anchor
stringlengths
10
14.3k
positive
stringlengths
10
14.9k
# ARC058D - いろはちゃんとマス目 / Iroha and a Grid (ABC042D) def get_fact(lim): # compute a toble of factorials (1-idx) fact = [1] * (lim + 1) x = 1 for i in range(1, lim + 1): x = (x * i) % MOD fact[i] = x return fact def get_inv(lim): # compute a toble of inverse factorials (1-idx) ...
import java.util.Scanner; public class Main { public static class Combination { long[] factorial; int maxN; long Module; public Combination(final int maxN, final long Module) { this.maxN = maxN; factorial = new long[maxN]; this.Module = Module...
import java.io.*; import java.util.*; public class cf1428_Div1Div2_c { public static void main(String[] args) throws IOException { FastScanner in = new FastScanner(); int tc = in.nextInt(); for ( ; tc > 0; tc--) { char[] line = in.next().toCharArray(); int n = line.length; ...
#include <bits/stdc++.h> using namespace std; signed main() { ios::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while (t--) { string s; cin >> s; int A = 0, B = 0; int ans = 0, del = 0, cnt = 0; for (char x : s) { if (x == 'A') cnt++, A++; else { if (cnt) { ...
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); long n = sc.nextLong(); StringBuilder sb = new StringBuilder(); int i = 1; while (i <= 11) { if (n > Math.pow(26, i)) { n ...
#include<bits/stdc++.h> using namespace std; int main(){ string ans=""; long long int n; cin>>n; n=n-1; while(n>-1){ ans=ans+char('a'+(n%26)); n=n/26-1; } reverse(ans.begin(),ans.end()); cout<<ans; return 0; }
#include <bits/stdc++.h> using namespace std; template <typename T> T pow(T a, T e, T mod) { if (!e) return 1; T x = pow(a, e / 2, mod); x = x * x % mod; return (e & 1) ? x * a % mod : x; } template <typename T, typename exp_t, T (*multiply)(T, T)> T pow(T a, exp_t e) { if (!e) return 1; T x = pow<T, exp_t,...
import static java.lang.Integer.parseInt; import static java.lang.Long.parseLong; import static java.lang.System.exit; import static java.util.Arrays.fill; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.math.BigInteger; import java.u...
import java.util.ArrayList; import java.util.Arrays; import java.util.Scanner; public class Main { Scanner sc = new Scanner(System.in); int[] memo; ArrayList<Integer> lh, lr; void run() { for (;;) { int n = sc.nextInt(); if (n == 0) return; lh = new ArrayList<Integer>(); lr = new ArrayList<Integer>(...
#include <iostream> #include <fstream> #include <vector> #include <string> #include <map> #include <sstream> #include <queue> #include <cstdlib> #include <algorithm> #include <iterator> #include <stack> #include <list> using namespace std; #define INF 100000000 typedef long long int lli; typedef pair<int,int> P; bool ...
#include <bits/stdc++.h> using namespace std; const int N = 100010; struct Ques { int l, r, id; }; int n, bl, m, all, cnt; int a[N]; Ques q[N]; deque<int> w[N]; deque<int> s[N]; int v[N], ans[N], ok[N]; int cmp(Ques a, Ques b) { return a.l / bl < b.l / bl || (a.l / bl == b.l / bl && a.r < b.r); } int main() { sca...
import java.io.*; import java.util.*; import java.math.BigInteger.*; import static java.lang.Math.*; import static java.math.BigInteger.*; import static java.util.Arrays.*; import java.util.Collections.*; // https://netbeans.org/kb/73/java/editor-codereference_ru.html#display //<editor-fold defaultstate="collapsed" de...
#include <bits/stdc++.h> using namespace std; string memo[51][51]; string max(string const& a, string const& b) { if(a == "invalid") { return b; } if(a.size() > b.size()) { return a; } else if(a.size() < b.size()) { return b; } else { return (a < b ? b : a); } }...
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**13 mod = 10**9+7 dd = [(-1,0),(0,1),(1,0),(0,-1)] ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] def LI(): return [int(x) for x in sys.stdin....
def main(): while True: n, c = map(int, input().split()) if n == 0:break music = [] for _ in range(n): line = list(map(int, input().split())) add_panel = sum([2 ** i * line[i] for i in range(16)]) music.append(add_panel) hand = [] for _ in range(c): line = list(map...
import java.util.Arrays; import java.util.Scanner; //Beat Panel public class Main{ void run(){ Scanner sc = new Scanner(System.in); int[][] dp = new int[2][1<<16]; for(;;){ int n = sc.nextInt(), c = sc.nextInt(); if(n+c==0)break; int[] a = new int[n], b = new int[c]; for(int i=0;i<n;i++)for(int j=0...
val = 3337867500 n,a,d = map(int, input().split()) print(val * a, val * d)
#include <bits/stdc++.h> const int ntf = 1e9; const unsigned long long ft = 368131125ll; const unsigned long long vl = 12000000000ll; int n, a, d; int main() { scanf(" %d %d %d", &n, &a, &d); printf("%llu %llu\n", ft * a % ntf * vl + 1, ft * d % ntf * vl); return 0; }
#include <cstdio> int main() { int prev = 0; int curr; int sum = 0; int n; scanf("%d", &n); int i; for (i = 0; i < n; i++) { scanf("%d", &curr); if (curr - prev > 0) sum += curr - prev; prev = curr; } printf("%d\n", sum); return 0; }
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int N = in.nextInt(); int[] h = new int[N]; for (int i = 0; i < N; i++) { h[i] = in.nextInt(); } int ans = 0; while (true) { int left = -1; for (int i = 0; i < N; i++) { ...
import java.io.*; import java.util.*; public class CF99A { private static BufferedReader br; private static StringTokenizer st; private static PrintWriter pw; // private static Timer t = new Timer(); public CF99A() throws IOException { br = new BufferedReader(new InputStreamReader(System.in)); pw = new Pri...
#include <bits/stdc++.h> using namespace std; template <typename a> void SWAP(a &b, a &c) { a d = b; b = c; c = d; } long long power(long long a, long long b) { long long result = 1; while (b) { if (b & 1) result = a * result; a *= a; b >>= 1; } return result; } long long gcd(long long a, long...
#include <bits/stdc++.h> using namespace std; const int maxn = (1 << 22) + 5; int n, m, a[maxn]; bool vis[maxn], f[maxn]; void dfs(int x) { if (vis[x]) return; vis[x] = 1; if (f[x]) dfs(x ^ ((1 << n) - 1)); for (int i = 0; i < n; i++) if (x & (1 << i)) dfs(x ^ (1 << i)); } int main() { scanf("%d%d", &n, &...
import java.util.* ; import java.io.* ; public class F { static int mod = (int) (1e9+7); static InputReader in; static PrintWriter out; static boolean[] vis; static boolean[] arr; static void dfs(int i, int n, int mask){ vis[i] = true; for(int j = 0; j < n; j++){ ...
#include <bits/stdc++.h> long long int array[300010], power[300030]; int cmp(const void *a, const void *b) { return (*(long long int *)a) - (*(long long int *)b); } int main() { long long int i, j, ans, mod, val, val2, n; mod = 1000000007; ans = 0; power[0] = 1; scanf("%lld", &n); for (i = 0; i < n; i++) ...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import java.util.Random; import java.util.StringTokenizer; import java.util.concurrent.ThreadLocalRandom; public class Main3 { static long mod = 1000000007L; public static void main(String[] ...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; public class E630 { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); PrintWriter pw = new PrintWriter(Syst...
x1, y1, x2, y2 = map(int, input().split()) x2 -= x1 y2 -= y1 x1 = 0 y1 = 0 odd_x = (x2 - x1) // 2 + 1 - (1 if x1 % 2 == 0 and x2 % 2 == 0 else 0) odd_y = (y2 - y1) // 2 + 1 - (1 if y1 % 2 == 0 and y2 % 2 == 0 else 0) even_x = (x2 - x1) // 2 + 1 - (1 if x1 % 2 == 1 and x2 % 2 == 1 else 0) even_y = (y2 - y1) // 2 + 1 - ...
import java.util.*; import java.io.*; public class a { public static void main(String[] args) throws IOException { input.init(System.in); int n = input.nextInt(); int[] nums = {110,50,80,170,20,200}; if(n<=2) System.out.println(-1); else if(n==3) System.out.println(210); else ...
n = input() if n < 3: print -1 else: print 10 ** (n-1) + (-1*10 ** (n-1))%210
/* Author: Greg Zborovsky User: angeredgecko Date/Time: 2021-02-27 18:58:04.698474 */ #include <bits/stdc++.h> using namespace std; template <class T> void debug(vector<T> vec, ostream &fout = cout) { fout << "["; for (auto const &val : vec) { fout << val << " "; } fout << "]"; } template...
T = int(input()) while T >= 1: n = int(input()) arr = list(map(int,input().split())) check = True ; pis = 0 for i in range(n): pis += arr[i] if pis < i*(i+1)//2: check = False break if check == True: print("YES") else: print("NO") T -= 1
#include <bits/stdc++.h> using namespace std; const int N = 100010; int k[3], t[3]; int n; long long c[N], tm[N], d[N]; int main() { for (int i = 0; i < 3; i++) scanf("%d", &k[i]); for (int i = 0; i < 3; i++) scanf("%d", &t[i]); scanf("%d", &n); long long ret = 0; for (int i = 0; i < n; i++) scanf("%I64d", &c...
k1,k2,k3 = [int(x) for x in raw_input().split()] t1,t2,t3 = [int(x) for x in raw_input().split()] n = int(raw_input()) q1 = [int(x) for x in raw_input().split()] q2 = [] i = 0 for x in q1: if i < k1: q2.append(x+t1) else: q2.append(max(x, q2[i-k1])+t1) i += 1 q3 = [] i = 0 for x in q2: if i < k2: q3.append(x...
#include <bits/stdc++.h> using namespace std; template <class T, class T1> int chkmin(T &x, const T1 &y) { return x > y ? x = y, 1 : 0; } template <class T, class T1> int chkmax(T &x, const T1 &y) { return x < y ? x = y, 1 : 0; } const int MAXN = 3042; const int mod = 998244353; string s, t; void read() { cin >> s ...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.io.BufferedWriter; import java.io.Writer; import java.io.OutputStreamWriter; import java.util.InputMismatchException; import java.io.IOException; import java.io.Input...
while 1: n, m = map(int, raw_input().split()) if n == m == 0: break S = map(int, raw_input().split()) left = 0; right = sum(S)+2 def check(mid): if 1+mid <= S[0]: return 10**9 cnt = 0; l = 1 target = S[n-1] - mid for i in xrange(n-1): w...
#include <iostream> #include <string> #include <cstdlib> #include <cmath> #include <algorithm> #include <vector> #include <stack> #include <set> #include <queue> #include <map> #include <utility> using namespace std; #define sz size() #define rep(i, a, n) for(int i = (a);i < (n);i++) #define lep(i, a, n) for(int i = (...
f = [0, 4, 8, -1, 16, -10, 4, -12, -48, 26, -44, 15, -16, -4, -4, -1] jly = 998244353 t = 0 x = [0, 0, 0, 24, 4, 240, 204, 1316, 2988, 6720, 26200, 50248, 174280, 436904, 1140888, 3436404] n = int(input()) for i in range(16, n + 1): t = 0 for j in range(0, 16): t = (t + f[(i - j - 1) & 15] * x[j]) % jly...
#include <bits/stdc++.h> constexpr int P = 998244353; constexpr int A[16] = {0, 0, 0, 24, 4, 240, 204, 1316, 2988, 6720, 26200, 50248, 174280, 436904, 1140888, 3436404}; constexpr int F[16] = {P - 1, P - 4, P - 4, P - 16, 15, P - 44, 2...
n = int(input()) a = [] for _ in range(n): xy = list(map(int, input().split())) a.append(xy) midpoint = {} for i in range(n): for j in range(i + 1, n): x1, y1 = a[i][0], a[i][1] x2, y2 = a[j][0], a[j][1] dx = x2 + x1 dy = y2 + y1 midpoint[(dx / 2, dy / 2)] = midpoint....
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const long long INF = 0x3f3f3f3f3f3f3f3fll; const int maxn = 2005; pair<long long, long long> poi[maxn]; map<pair<long long, long long>, int> M; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) cin >> poi[i].first >> poi[i].second...
if __name__ == "__main__": n = int(input()) a = set(map(lambda x: int(x), input().split())) m = int(input()) b = set(map(lambda x: int(x), input().split())) for elem in sorted(a.intersection(b)): print(elem)
#include "bits/stdc++.h" using namespace std; using ll = long long; using P = pair<int, int>; #define PI acos(-1) #define Mod (int)1000000007 #define INFTY (int)INT_MAX #define Rep(i, n) for (int i = 0; i < (int)(n); i++) #define BitRep(i, n) for (int i = 0; i < (int)(1 << n); i++) #define All(vec) vec.begin(), vec.end...
#include <bits/stdc++.h> using namespace std; int n, x; long long smn, smx = 0; set<pair<int, int> > mset; pair<int, int> g; void summin(pair<int, int> a[]) { mset.insert(pair<int, int>(n - 1, 0)); for (int i = 0; i < n; ++i) { g = *mset.lower_bound(pair<int, int>(a[i].second, 0)); mset.erase(g); smn +=...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.io.BufferedWriter; import java.io.Writer; import java.io.OutputStreamWriter; import java.util.InputMismatchException; import java.io.IOException; import java.io.Input...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10, skc = 998244353; vector<int> v[N], edge[N]; void add(int x, int y, int z) { v[x].push_back(y); edge[x].push_back(z); } void upd(int &x, int y) { x = (x + y) % skc; } int f[N][3], n; struct node { int id, vl; friend bool operator<(node A, node...
import java.util.*; import java.io.*; public class Main { public static void main(String args[]) {new Main().run();} FastReader in = new FastReader(); PrintWriter out = new PrintWriter(System.out); void run(){ work(); out.flush(); } long mod=998244353; long gcd(long a,long b) { return b==0?a:gcd(b,a%b); ...
//package Working_with_Ranges.Segment_Tree.Chef_Force; import java.util.Scanner; public class Cleaning { static long[][] st, lazy; static long INF = 1000_000_000_000L; public static void main(String[] args) { Scanner scan = new Scanner(System.in); int T = scan.nextInt(); while (T--...
#include <bits/stdc++.h> #define fir first #define sec second using namespace std; typedef long long ll; typedef pair<int,int> P; typedef pair<P,P> Q; const int inf1 = 1e9+9; const ll inf2 = 1e16+9; const int maxx = 1e9+9; const int maxn = 1e6+9; int n,ar[maxn]; int l[maxn],r[maxn],t[maxn]; bool judge(int p) { ...
import java.io.*; import java.util.Arrays; import java.util.StringTokenizer; public class TaskE { StringTokenizer st; BufferedReader in; PrintWriter out; long res00, res01, res10, res11; public static void main(String[] args) throws IOException { TaskE taskA = new TaskE(); taskA.op...
#include <bits/stdc++.h> using namespace std; long long getll() { long long x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch <= '9' && ch >= '0') { x = x * 10 + ch - '0'; ch = getchar(); } return f * x; } struct Mat { lo...
i=int(input()) l=set(map(int,input().split())) print('YES' if i == len(l) else 'NO')
#include <bits/stdc++.h> using namespace std; using ll = long long; int main(){ set<int> S; int N;cin>>N; int buf; for(int i=0; i<N; i++){ cin>>buf; S.insert(buf); } cout<<(S.size()==N? "YES\n": "NO\n"); }
# # # author : samars_diary # # 12-09-2020 │ 19:22:08 # # # import sys, os.path if(os.path.exists('input.txt')): sys.stdin = open('input.txt',"r") #sys.stdout = open('output.txt',"w") sys.setrecursionlimit(10 ** 5) def i(): return sys.stdin...
import java.util.ArrayList; import java.util.Collections; import java.util.Scanner; public class codeforces670div2 { public static void main(String[] args) { // TODO Auto-generated method stub Scanner s=new Scanner(System.in); int t=s.nextInt(); while(t-->0) { int n=s.nextInt(); int a[]=new int[n]; ...
import java.util.*; public class MyClass { public static void main(String args[]) { Scanner sc = new Scanner(System.in); int t=sc.nextInt(); while(t--!=0) { int n=sc.nextInt(),o=0,e=0; boolean f=false; for(int i=0;i<n;i++) ...
#include <bits/stdc++.h> using namespace std; void tetris(int k) { int odd = 0; int even = 0; for (int i = 1; i <= k; i++) { int j; cin >> j; if (j & 1) { odd++; } else { even++; } } if (odd == k || even == k) { cout << "YES" << '\n'; } else { cout << "NO" << '\n'; ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; int i = 1; if (n % 2) { cout << 1 << ' '; i++; } for (; i <= n; i += 2) { cout << i + 1 << ' ' << i << ' '; } return 0; }
import java.io.*; import java.util.*; import static java.lang.Math.*; public class ProblemC_46 { final boolean ONLINE_JUDGE=System.getProperty("ONLINE_JUDGE")!=null; BufferedReader in; PrintWriter out; StringTokenizer tok=new StringTokenizer(""); void init() throws FileNotFoundException{ if (ONLINE_JUDGE)...
#include<bits/stdc++.h> using namespace std; signed main(){ int x,n,a; int p[1000]={}; cin>>x>>n; for(int i=0;i<n;i++){ cin>>a; p[a]=1; } int num=0,ab=x; for(int i=-10000;i<=10000;i++){ if(ab>abs(x-i)&&p[i]==0){ ab=abs(x-i); num=i; } } cout<<num<<"\n"; }
x,n=map(int,input().split()) p=list(map(int,input().split())) ans=0 for i in range(1,102): if i not in p: if abs(x-i)<abs(x-ans): ans=i print(ans)
//package round76; import java.io.PrintWriter; import java.util.Arrays; import java.util.Scanner; public class D { Scanner in; String INPUT = "5 6"; PrintWriter out; static int MOD = 1000000007; void solve() { int L = ni(); int R = ni(); String[] t = {" ", " B", " R", " W", " Y", "BW", "BY", "RW", "RY...
#include <bits/stdc++.h> using namespace std; long long iMatrixMultiply(long long multiplicant1, long long multiplicant2, long long ivalue = (long long)1023123123 * (long long)1023123123) { return (multiplicant1 * multiplicant2) % ivalue; } long l...
import java.util.Scanner; public class Move_Brackets { public static void main(String [] args) { Scanner sc=new Scanner (System.in); int t=sc.nextInt(); for(int j=0;j<t;j++) { int n=sc.nextInt(); String s=sc.next(); int b=0; int res=0; int min=0; for(int i=0;i<n;i++) { if(s.charAt(i)=='(...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int tc; cin >> tc; while (tc--) { string s; int n, x = 0, y = 0; bool vis[55]; memset(vis, false, sizeof(vis)); vector<int> f; cin >> n >> s; for (int i = 0; i < n; i++) { if (s[i]...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; public class Main { public static void main(String[] args) { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); try { ArrayList<Date> date=new A...
#include <iostream> #include <vector> #include <string> #include <algorithm> #include <utility> #include <numeric> #include <array> #include <cmath> #include <memory> using namespace std; //変数デバッグ #define DEB(variable) cout << #variable << '=' << variable << endl //for簡易表記(引数ミス防止) #define FOR(LoopVariable,numberOFbegi...
#include <bits/stdc++.h> #ifdef LOCAL #include "lib.cpp" #endif #define fio ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0); #define TC long long T_;cin>>T_;while(T_--) #define rar(a,n) int n;cin >> n;int a[n];for(int i_=0;i_<n;i_++)cin >> a[i_]; #define rark(a,n,k) int n,k;cin >> n >> k;int a[n];for(int i_=0;i_<...
import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStream; import java.io.OutputStreamWriter; import java.util.InputMismatchException; public class D1{ private static Reader sc = new Reader(); private static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));...
#include <set> #include <map> #include <list> #include <cmath> #include <queue> #include <stack> #include <cstdio> #include <string> #include <vector> #include <cstdlib> #include <cstring> #include <sstream> #include <iomanip> #include <iostream> #include <algorithm> #include <fstream> #include <ctime> #include <deque>...
#!usr/bin/env python3 from collections import defaultdict from collections import deque from heapq import heappush, heappop import sys import math import bisect import random def LI(): return list(map(int, sys.stdin.readline().split())) def I(): return int(sys.stdin.readline()) def LS():return list(map(list, sys.stdin....
#include <bits/stdc++.h> using namespace std; const int maxn = 400005; char str[maxn]; int n, odd, even, buf[256]; vector<char> odd_list, cur_list; int main() { scanf("%d", &n); scanf("%s", str + 1); for (int i = 1; i <= n; i++) ++buf[str[i]]; for (int i = 0; i < 256; i++) { if (buf[i] & 1) odd_list.push_ba...
import java.io.*; import java.util.*; import java.math.BigInteger; import java.util.Map.Entry; import static java.lang.Math.*; public class Main extends PrintWriter { List<String> solve(final int n, final int m, final int k, int[] cnt) { int odd = 0; for (int c = 0; c < k; c++) { if ...
import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Scanner; //Color the Map public class Main{ class R{ List<L> l; boolean u; int color, id; public R(int id) { this.id = id; l = new ArrayList<L>(); u = false; ...
def main(): while 1: N = int(input()) if N == 0: break D = {} G = [set() for i in range(N)] cur = 0 K = [] PS = [] for i in range(N): ps = [] s = input() if s in D: k = D[s] el...
#include <iostream> using namespace std; int main() { int m; cin >> m; for (int prob = 0; prob < m; prob++) { int depo; cin >> depo; int year; cin >> year; int n; cin >> n; int ans = 0; for (int method = 0; method < n; method++) { int hukuri; double nennri; int tesuu; cin >> huku...
def c(a): global y,r,d for _ in range(y):a+=int(a*r)-d return a def s(a): global y,r,d b=0 for _ in range(y): b+=int(a*r) a-=d return a+b for _ in range(int(input())): m=0 a=int(input());y=int(input()) for _ in range(int(input())): b,r,d=map(float,input(...
#include <bits/stdc++.h> using namespace std; int n, a[100005], b[100005], cnt[100005], i, tmp, in[100005], go[100005]; vector<int> v[100005]; int main() { cin >> n; for (i = 1; i <= n; i++) { cnt[i] = 0; in[i] = 0; go[i] = 0; cin >> a[i]; } for (i = 1; i <= n; i++) { cin >> b[i]; if (b[...
import java.io.*; public class two { public static void main(String[] args) throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String line = br.readLine(); int N = Integer.parseInt(line); int[] objectsType = new int[N+1]; int[]...
import java.io.*; import java.util.*; public class CF { class Pers { int id, left, right, v; Pers(int id, int left, int v, int right) { this.id = id; this.left = left; this.right = right; this.v = v; } } int MAX = (int) (3 * 1e5 + 11); class SegTree { int n; int[] sum; int[] maxPref; ...
import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = 'x' in file.mode or 'r' not in file.mode self.write = self.buffer.write if self.wri...
import java.util.*; import java.lang.*; import java.io.*; public class GFG { public static void main (String[] args) throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringBuffer sb = new StringBuffer(); int Q = Integer.parseInt(br.readLine()); for(int q = 0; q < Q...
#include <bits/stdc++.h> #pragma GCC optimize "O3" using namespace std; const int inf = 0x3f3f3f3f; const long long INF = 0x3f3f3f3f3f3f3f3f; const int N = 4000; int huh[N + 5]; int ile[N + 5], pt; void solve() { memset(ile, 0, sizeof(ile)); int n; cin >> n; pt = N; while (n) { ile[pt] += n / huh[pt]; ...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.Arrays; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.UncheckedIOException; import java.util.Objects; import java.nio.charset.C...
#include <bits/stdc++.h> using namespace std; #define int long long #define REP(i, n) for (long long i = 0, max_i = (n); i < max_i; i++) #define REPI(i, a, b) for (long long i = (a), max_i = (b); i < max_i; i++) #define ALL(obj) begin(obj), end(obj) #define RALL(obj) rbegin(obj), rend(obj) #define fi first #define se s...
import java.util.*; public class Main { Scanner in = new Scanner(System.in); public static void main(String[] args) { new Main(); } public Main() { new Problem_B(); } class Problem_B{ int h,w,ph,pw; int[][] a; boolean[][] b; boolean[][] c; int sum(int start_x,int start_y){ int result = 0; f...
#ifndef _WIN32 #include<iostream> #endif #include<cmath> #include<iomanip> #include<algorithm> #include<vector> #include<string> using namespace std; typedef long long LL; #define FOR(i,bg,ed) for(int (i)=(bg);(i)<(ed);(i)++) #define REP(i,n) FOR(i,0,n) struct cww { cww() { ios::sync_with_stdio(false); cin.tie(0);...
n = int(raw_input()) a = map(int, raw_input().split()) m = int(raw_input()) b = map(int, raw_input().split()) if sum(a) != sum(b): print -1 else: sum_a, sum_b, i, j = 0, 0, 0, 0 output = 0 while i < n: output += 1 sum_a += a[i] sum_b += b[j] i += 1 j += 1 while sum_a != sum_b: if sum_a < sum_b: ...
import java.util.*; import java.io.*; public class Forces{ public static void main(String ...arg) { Read cin = new Read(); long sum1 = 0,sum2=0; int n = cin.nextInt(); Long[] a = new Long[n]; for(int i=0;i<n;i++) { a[i] = cin.nextLong(); sum1 += a[i]; } int m = cin.nextInt(); Long[] b = ...
#include <bits/stdc++.h> using namespace std; int main() { int n, arr[200000], arr1[200000] = {}, counter = 1, counter2 = 0, index; cin >> n; for (int i = 0; i < n; i++) { cin >> arr[i]; if (counter2 == 0 && arr[i] == 0) { index = i; counter2++; arr1[i] = 0; } } for (int i = inde...
import math #t=int(input()) #for i in range(t): #n,a,b = map(int, input().strip().split(' ')) n=int(input()) lst = list(map(int, input().strip().split(' '))) p=[] for j in range(n): if lst[j]==0: p.append(j) l=len(p) #print(p) if l==1: for j in range(n): print(abs(p[0]-j),end=" ") else: i1=0...
import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintStream; import java.util.Arrays; import java.util.Comparator; import java.util.StringTokenizer; /* public class _480D { } */ public cla...
#include <bits/stdc++.h> using namespace std; int MAX_N = 500; int MAX_DURABILITY = 1000; int N, S; vector<int> in, out, weight, durability, value; vector<vector<int> > start; vector<vector<int> > finish; vector<int> temp; vector<vector<int> > cache; int solve(int part, int D) { int &result = cache[part][D]; if (re...
import java.util.Scanner; public class Main { private static Scanner sc = new Scanner(System.in); public static void main(String[] args) { int n = sc.nextInt(), k = sc.nextInt(); System.out.println((n + 1) / 2 >= k ? "YES" : "NO"); } }
n, k = map(int, input().split()) if n >= k*2-1: print('YES') else: print('NO')
def aaa(): n=int(input()) a=list(map(int,input().split())) b=list(map(int,input())) b=[0]+b+[0] for ii in range(n): aa=a[ii] bl=b[ii] br=b[ii+1] if bl==0: lo=hi=aa l1=ii+1 else: lo=min(lo,aa) hi=max(hi,aa) if br==0: r1=ii+1 if lo!=l1 or hi!=r1: return 1 aaa=aaa() print("NO" if aaa...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.InputMismatchException; import java.io.IOException; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author Pranay2516 */ public class...
from fractions import gcd n=input() nums=map(int,raw_input().split()) mx=max(nums);nums.sort() difMax=map(lambda x:mx-x,nums) y=reduce(gcd,difMax) z=sum(difMax)/y print z,y
import java.util.Scanner; public class cf { static long maxx(long a,long b){ if(a > b)return a; else return b; } static long Quick_GCD(long a,long b) { if(a==0) return b; if(b==0) return a; if(!(a%2==1)&&!(b%2==1)) { return Quick_GCD(a>>1,b>>1)<<1; } else if(!(b%2==1)) ...
n = int(input()) a = [int(x) for x in input().strip().split()] a = sorted(a) d = [] for i in range(len(a) - 1): d.append(a[i + 1] - a[i]) def gcd(a, b): if(b == 0): return a else: return gcd(b, a % b) g = d[0] for e in d: g = gcd(g, e) cnt = len(a) print( int( ( a[len(a) - 1] -...
import java.util.*; public class Solution { public static void main(String[] args) { Scanner in=new Scanner(System.in); int n=in.nextInt(); Long[] arr=new Long[n]; for(int i=0;i<n;i++) { arr[i]=in.nextLong(); } Arrays.sort(arr); long s...
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:16777216") const double PI(acos(-1.0)); using namespace std; long double dp[55][55][55], cnk[55][55]; int v[55]; int main() { cout.precision(2); srand(unsigned(time(nullptr))); int n, m; scanf("%d%d", &n, &m); for (int i = 0; i < m; ++i) scanf("%d", &v[...
import java.io.*; import java.util.*; import java.math.*; public class c { int stud, room; int[] wash; double[][][] prob; long[][] c; void solve() throws Exception { stud = nextInt(); room = nextInt(); wash = new int[room]; for (int i = 0; i < room; ++i) wash[i] = nextInt(); c = new long[51][51]; ...
#include <cstdio> #include <cstring> #include <algorithm> #include <string> #include <cmath> #include <stack> #include <vector> #include <map> #include <set> #include <queue> #include <list> #include <iostream> #include <climits> #include <cfloat> using namespace std; double distance(double x1, double y1, double x2,...
import java.util.LinkedList; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (true) { final int n = sc.nextInt(); if(n == 0){ break; } Point2D[] input = new Point2D[n]; for(int i = 0; i < n; i++){ S...
N, K = map(int, input().split(" ")) print(N - K if K >= 2 else 0)
#include <iostream> using namespace std; int main(){ int n, k; cin >> n >> k; if( k != 1) cout << n - k; else cout << 0; return 0; }
#include <bits/stdc++.h> using namespace std; int gcd(int x, int y) { if (y == 0) return x; return gcd(y, x % y); } int arr[107]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) cin >> arr[i]; int cnt = arr[0]; for (int i = 1; i < n; i++) { int curr = arr[i]; if (cnt > curr) swap(cnt, cu...
n = int(input()) x = list(map(int, input().split())) ##greatest common divisor def gcd(a , b): while b > 0: (a, b) = (b, a % b) return a res = x[0] for i in x[1:]: res = gcd(res, i) print(res*len(x))
#include <bits/stdc++.h> inline int getint() { int x = 0, p = 1; char c = getchar(); while (c <= 32) c = getchar(); if (c == 45) p = -p, c = getchar(); while (c > 32) x = x * 10 + c - 48, c = getchar(); return x * p; } using namespace std; const int N = 1e5 + 5; int n, m, k, p, a[N], h[N]; pair<long long, i...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.util.Arrays; import java.io.BufferedWriter; import java.io.Writer; import java.io.OutputStreamWriter; import java.util.InputMismatchException; import java.io.IOExcept...
#include <bits/stdc++.h> using namespace std; const int MAXN = 300000; int n, m; vector<int> v[MAXN]; bool u[MAXN]; pair<long long, long long> dfs(int x) { u[x] = true; pair<long long, long long> res{1, 0}; for (int y : v[x]) { if (!u[y]) { pair<long long, long long> cur = dfs(y); res.first += cur...
//package Graphs; import java.io.PrintWriter; import java.util.ArrayList; import java.util.LinkedList; import java.util.Scanner; public class M771A { public static Scanner enter = new Scanner(System.in); public static PrintWriter out = new PrintWriter(System.out); public static void main(String[] args) { ...
#include <bits/stdc++.h> using namespace std; template <class t> inline t read(t &x) { char c = getchar(); bool f = 0; x = 0; while (!isdigit(c)) f |= c == '-', c = getchar(); while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar(); if (f) x = -x; return x; } template <class t> inline void wr...
import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.InputMismatchException; public class A5 { InputStream is; PrintWriter out; String INPUT = ""; final int mod = 1000000007; public static int[][] enu...
#include <bits/stdc++.h> using namespace std; int main() { int n, m = 0, k, p, a, i, e = 0, b, c, d, cou = 0; cin >> n >> k; for (i = 0; i < n; i++) { cin >> a; if (a <= k) m++; else { p = a / k; b = a % k; if (p % 2 == 1 && b != 0) { p++; cou = cou + (p / 2); ...
n, k = map(int, input().split()) w = list(map(int, input().split())) q=0 t=0 for i in range(n): a=w[i]//k w[i]%=k q+=(a//2) t+=(a%2) # print(a, w[i], t, q) if t==2: t=0 q+=1 if w[i]>0: if t==1: t=0 w[i]=0 q+=1 else: w[i]=0 t+=1 if t>0: q+=1 print(q)
#define _CRT_SECURE_NO_WARNINGS #include "stdio.h" #include <vector> #include "memory.h" #include "string.h" #include "math.h" #include <set> #include <map> #include <iostream> #include <algorithm> #include <functional> #include <queue> using namespace std; vector<vector<int> > C; vector<vector<int> > N; vector<int...
import sys from heapq import heapify, heappop, _heapify_max, heappush, _heappop_max f = sys.stdin def line(): return f.readline().strip().split() class UnionFind: def __init__(self, n): self.link = [-1]*n self.rank = [0]*n def add_link(self,node,parent): self.link[node] = parent ...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.IOException; import java.util.ArrayList; import java.io.UncheckedIOException; import java.util.List; import java.io.Closeable; import java.io.Writer; import java.io.OutputStreamWriter; import...
#include <bits/stdc++.h> using namespace std; const int inf = 1e9; const int MOD = 1e9 + 7; const int N = 1e5 + 10; int n, k, m, x, y, g[N], lv[N], depth; vector<int> v[N]; queue<int> q; bool check(int M) { long long sum = 0, cost = 1LL * M * depth; for (int R = depth, L = depth + 1; R > 0; R--) { while (L > 1 ...
#include <iostream> #include <algorithm> #include <string> #include <vector> #include <set> using namespace std; int dx[] = {-1, -1, 0, 1, 1, 0}; int dy[] = {-1, 0, 1, 1, 0, -1}; vector<pair<int, int>> make_set(string &s, int i){ vector<pair<int, int>> ret; auto pos = make_pair(0, 0); ret.push_back(pos); for (a...
import java.util.*; import java.util.Scanner; import static java.lang.Math.*; public class Main { final Scanner sc=new Scanner(System.in); final int INF=Integer.MAX_VALUE/4; public static void main(String[] args) { new Main().doIt(); } void doIt(){ new AOJ1228(); } class AOJ1228{ final int[] vx={0,1,1,0,...
from __future__ import print_function from sys import stdin inp = [int(x) for x in stdin.read().split()] n, m = inp[0], inp[1] in_idx = 2 n += 1 adj = [[] for _ in range(n)] edge_index = [[] for _ in range(n)] for i in range(m): a = inp[in_idx] in_idx += 1 b = inp[in_idx] in_idx += 1 adj[a].append(b) edge_inde...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 7; int n, m; set<int> adj[N]; set<pair<int, int> > edges; void input() { scanf("%d %d", &n, &m); int u, v; for (int i = (0); i < (m); i++) { scanf("%d %d", &u, &v); adj[u].insert(v); adj[v].insert(u); if (u > v) { swap(u, v); ...
from sys import stdin,stdout,setrecursionlimit,maxint,exit #setrecursionlimit(2*10**5) def listInput(): return map(long,stdin.readline().split()) def printBS(li): for i in xrange(len(li)-1): stdout.write("%d "%li[i]) stdout.write("%d\n"%li[-1]) def sin(): return stdin.readline().rstrip() n,k=listInput() li=listIn...
#include <bits/stdc++.h> using namespace std; long long i, j, n, m, a[110000], k, num, ans, p; long long s[110000]; long long search(long long l, long long r, long long j) { long long c; if (l == r) return l; if (l == r - 1) { if ((j - l) * a[j] <= s[j - 1] - s[l - 1] + k) return l; return r; } c = (l...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; int p = m; vector<int> ans; int cnt = 0; for (int i = 0; i < n; i++) { cnt = 0; if (a[i] <= p) { p -= a[i]; if (p == 0) { cnt++; p = ...
n, m = map(int, raw_input().split()) a_l = map(int, raw_input().split()) oc = 0 for a in a_l: first = min(a, m - oc) if a + oc < m: oc += first print 0, elif a + oc == m: oc = 0 print 1, else: ans = 1 a -= first ans += a / m oc = a % m print ans,
import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.StringTokenizer; public class Main { int mod = 1000000007; ...
T = int(input()) for t in range(T): n = int(input()) A = [int(i) for i in input().split()] print(*A[::-1])
#include <bits/stdc++.h> using namespace std; int main () { int N, M; cin >> N >> M; int C = N + 1; vector<int> T(N); for (int i = 0; i < N; i++) T[i] = i + 1; for (int i = 0; i < M; i++) { int x, y; cin >> x >> y; x = T[x-1], y = T[y-1]; for (auto &j : T) { if ...
n, m = map(int, input().split()) q = [] for _ in range(m): a, b = map(int, input().split()) i, j = -1, -1 for k in range(len(q)): if i == -1: if a in q[k]: i = k if j == -1: if b in q[k]: j = k if i >= 0 and j >= 0: ...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.util.stream.IntStream; import java.util.PriorityQueue; import java.util.AbstractQueue; import java.util.Random; import java.util.ArrayList; import java.io.OutputStreamWriter; import java.io.OutputStream; import java.util.Co...
#include <bits/stdc++.h> using namespace std; const int N = 1e8; const int Maxn = 10010; int ansx[Maxn], xl, ansy[Maxn], yl; int main() { srand(233); int i, j, k; int t = rand() % N + 1; while (1) { cout << "0 " << t << " " << t << endl; int dis; cin >> dis; if (dis != 0) break; t = rand() %...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.concurrent.ThreadLocalRandom; import java.util.InputMismatchException; import java.io.IOException; import java.io.InputStream; /** * Built using CHelper plug-in *...
#include <bits/stdc++.h> using namespace std; long long n, m, ans, u, v, sum; long long a[100005], s[100005]; long long gcd(long long xx, long long yy) { long long r = xx % yy; if (r == 0) return yy; else return gcd(yy, r); } void solve() { long long i, j, g; u = 0; s[1] = 0; for (i = 2; i <= n; i...
//package round180; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.Comparator; import java.util.InputMismatchException; public class E { InputStream is; PrintWriter out; String INPUT = ""; void sol...
#include <bits/stdc++.h> using namespace std; const int MAXN(101); const int MAXE(5000010); const int MAXK(100010); const int MAXC(2); const int INF((INT_MAX - 1) / 2); const int BASE(20); const double LIM(1e50); const double EPS(1e-5); const double PER(0.02); const double MUL(3.5); int IT; template <typename T> inline...
import sys f = lambda s: int(s)-1 n = int(input()) b = [0]*(n+1) def update(bit,idx,val): idx += 1 while idx < n+1: bit[idx] += val idx += idx&(-idx) def getSum(bit,idx): idx += 1 ans = 0 while idx > 0: ans += bit[idx] idx -= idx&(-idx) return ans a = list(map(f...
#include <bits/stdc++.h> using namespace std; const int N = 1000010; const int M = 200010; const long long inf = 0x7fffffff; inline long long read() { long long x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { ...
#include <bits/stdc++.h> using namespace std; const long long inf = LONG_MAX; const long long arr = 1000000; bool comp(pair<long long, long long> a, pair<long long, long long> b) { if (a.first == b.first) return a.second < b.second; else return a.first < b.first; } int main(void) { long long n; cin >> n...
import java.util.Scanner; /** * Created by soumen.porel on 02/07/17. */ public class InfiniteSequence { public static void main(String[] atgs){ Scanner scanner = new Scanner(System.in); long num = scanner.nextLong(); long n = num; long j=1; for (int i=1; n > 0;i++){ ...
import java.util.Scanner; public class C54 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); double[]p = new double[n+1]; for (int i = 1; i <= n; i++) { long L = sc.nextLong(); long R = sc.nextLong(); ...
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0), eps = 1e-8; const int inf = ~0U >> 2; int mod = 1e9 + 7; int Pow(int x, long long t) { int r = 1; for (; t; t >>= 1, x = (long long)x * x % mod) if (t & 1) r = (long long)r * x % mod; return r; } const int N = 1010; int n; long long l...
from bisect import bisect import sys readline = sys.stdin.readline write = sys.stdout.write def construct(N, S, base, MOD): L = 26 root = [0, 0, N-1, [None]*L] nds = [root] for i, s in enumerate(S): node = root for c in s: h, a, b, nt = node if nt[c] is None: ...
#include <bits/stdc++.h> using namespace std; using psi = pair<string, int>; template <typename T> class merge_tree { const int n; vector<vector<T>> data; int size(int x) { int res; for (res = 1; res < x; res <<= 1); return res; } int query(int node, T val) { return lower_bound(data[node].begin(), data[no...
import java.util.*; import static java.lang.System.*; public class Main { Scanner sc = new Scanner(in); void run() { int m; int money, year, n; m = sc.nextInt(); for (int i = 0; i < m; i++) { money = sc.nextInt(); year = sc.nextInt(); n = sc.nextInt(); int max = 0; for (int j = 0; j < n; j+...
import sys n = int(raw_input()) for i in xrange(n): im = int(raw_input()) y = int(raw_input()) n = int(raw_input()) fm = 0 for j in xrange(n): w, ir, c = raw_input().split() w, ir, c = int(w), float(ir), int(c) if w == 1: ...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class LittlePigsAndWolves { public static void main(String[] args)throws IOException { littlePigsAndWolves(); } public static void littlePigsAndWolves() throws IOException { BufferedReader re...
#include <bits/stdc++.h> using namespace std; int n, m, cnt, next_x, next_y; char maze[15][15]; int dx[] = {-1, 1, 0, 0}; int dy[] = {0, 0, -1, 1}; map<pair<int, int>, int> w; map<int, pair<int, int> > w_rev; map<pair<int, int>, int> taken; bool valid(int x, int y) { return (x >= 0 && x < n && y >= 0 && y < m); } int m...
#include <bits/stdc++.h> #define rep(i,n)for(int i=0;i<(n);i++) using namespace std; typedef long long ll; typedef pair<ll,ll>P; int n; ll x; ll b[200000],l[200000],u[200000]; P s[200000]; int id[200000]; ll sum=0; bool C(ll t){ ll m=t/x; if(m>=n)return true; ll S=0; rep(i,m)S+=s[i].first; ll r=t%x; ll Max=0; r...
import math def main(): buf = input() buflist = buf.split() N = int(buflist[0]) X = int(buflist[1]) iblu = [] for i in range(N): buf = input() buflist = buf.split() iblu.append((i, int(buflist[0]), int(buflist[1]), int(buflist[2]))) aoki_score = 0 takahashi_score...
def extgcd(a, b, d=0): """solve ax + by = gcd(a, b) return x, y, gcd(a, b) unproved """ g = a if b == 0: x, y = 1, 0 else: x, y, g = extgcd(b, a % b) x, y = y, x - a // b * y return x, y, g a, b = map(int, input().split()) print(*extgcd(a, b)[:2])
#include<cstdio> #include<cstring> #include<iostream> using namespace std; int a,b,c,x,y; int exgcd(int a,int b){ if(!b){ x=1; y=0; return a; } int e=exgcd(b,a%b); int kkz=x; x=y; y=kkz-a/b*y; return e; } int main() { scanf("%d%d",&a,&b); ...
import java.util.*; public class Main { Scanner sc = new Scanner(System.in); public static void main(String[] args) { new Main(); } public Main() { new B().doIt(); } class B{ void doIt(){ int n = sc.nextInt(); String str = sc.next(); char ctr[] =...
n = int(input()) x = input() d = int(input()) swap = {} for i in range(n): if d == 0:break if x[i] == "0": swap[i] = True d -= 1 for i in range(n - 1, -1, -1): if d == 0:break if x[i] == "1": swap[i] = True d -= 1 print("".join([x[i] if i not in swap else ("0" if x[i] == "1" else "1") for i in ra...
import java.util.Arrays; import java.util.Scanner; public class CF453B { public static void main(String[] args) throws Exception { new CF453B().solve(); } static final int[] primes = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53 }; static class ElmWithIndex implem...
#include <bits/stdc++.h> using namespace std; int n, a[107], F[107], optEl[107][(1LL << (18))], dp[107][(1LL << (18))]; int primes[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59}; vector<int> rst; void factorise() { for (int x = 1; x <= 60; ++x) { for (int i = 0; i < 17; ++i) { if ((x %...
n = int(raw_input()) m = int(raw_input()) a = map(int,raw_input().split()) b = map(int,raw_input().split()) arr = [] for i in range(n): arr.append(b[-i]) arr.append(a[-1-i]) x = m ans = 0 flag = 0 for i in range(2*n): if arr[i] - 1 <=0: flag =1 break ans = x*1.0/(arr[i]-1) x += ans ans = x-m if flag ==1: ans ...
import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.List; import java.util.StringTokenizer; ...
#include <bits/stdc++.h> using namespace std; void solve() { int n, k; cin >> n >> k; vector<int> a(n), b(n); for (int i = 0; i < n; ++i) cin >> a[i]; for (int i = 0; i < n; ++i) cin >> b[i]; long long ans = 0; for (int i = 0; i < n; ++i) if (b[i] == 1) { ans += a[i]; a[i] = 0; } lon...
n,k = map(int, raw_input().split()) tab_th = map(int, raw_input().split()) tab_sl = map(int, raw_input().split()) wyn_1 = 0 wyn_2 = 0 for x in range(0, len(tab_sl), +1): if tab_sl[x] == 1: wyn_1 += tab_th[x] else: if x < k: wyn_2 += tab_th[x] temp_wyn = wyn_1+wyn_2 wyn = temp_wyn for...
import java.awt.*; import java.io.PrintWriter; import java.util.*; public class Main { static LinkedList<Integer> adj[]; static boolean vis[];static int dp[],inDeg[],dist[]; public static void main(String args[]) { Scanner sc = new Scanner(System.in); int n=sc.nextInt(),m=sc.nextInt(); ...
#include <bits/stdc++.h> using namespace std; int dis[100005]; vector<int>v[100005]; int n, m; int dfs(int x){ if(dis[x] != -1)return dis[x]; int ret = 0; for(int i = 0; i < v[x].size(); i++){ ret = max(ret, dfs(v[x][i]) + 1); } return dis[x] = ret; } int main(){ cin >> n >> m; for(int i = 0; i <= n; i++)dis[i...
def increase_difference(to_start, diff): res = 1 for i in to_start: if i + diff < 10: break if i + diff > 9: diff = diff - (9 - i) res += 1 return res def decrease_difference(to_start, diff): res = 1 for i in to_start: if i - diff > -1: ...
#include <bits/stdc++.h> using namespace std; string in; int ans = INT_MAX, cnt; vector<string> v; void solve(string str) { if (str.length() == 6) { int ltemp[3], rtemp[3], lsum = 0, rsum = 0; for (int i = 0; i < 3; i++) { ltemp[i] = str[i] - '0'; lsum += ltemp[i]; } for (int i = 3; i < 6;...
def main(): from itertools import chain n, m = map(int, input().split()) b1, b2, b3, b4 = ([0] * m for _ in range(4)) it = iter(range(1, m + 1)) try: for i in range(n): b1[i] = next(it) b4[i] = next(it) for i in range(n): b2[i] = next(it) ...
import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; public class Edu11B { public static void main(String[] args) throws NumberFormatException, IOException {...
#include <bits/stdc++.h> using namespace std; inline void pisz(int n) { printf("%d\n", n); } const int fx[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}}; const int fxx[8][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}, {1, 1}, {1, -1}, {-1, 1}, {-1, -1}}; template <typename T, typename TT> ostream& operator...
//package compete; import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.lang.reflect.Array; import java.security.acl.LastOwnerException; import java.util.*; import java.util.ArrayDeque; import java.util....
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.StringTokenizer; public class ProgressBar { public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int k = sc...
#include <bits/stdc++.h> using namespace std; int main() { int n, k, t, s; cin >> n >> k >> t; s = n * k * t / 100; for (int i = 0; i < n; i++) { if (s >= k) { cout << k << " "; s -= k; } else if (s > 0) { cout << s << " "; s = 0; } else cout << "0 "; } return 0; }
import java.lang.*; import java.math.*; import java.util.*; import java.io.*; public class Main { void solve() { int n=ni(),m=ni(); int a[][]=new int[m+1][]; for(int i=1;i<=m;i++){ int sz=ni(); a[i]=new int[sz]; for(int j=0;j<sz;j++){ a[i]...
def use_fast_io(): import sys class InputStorage: def __init__(self, lines): lines.reverse() self.lines = lines def input_func(self): if self.lines: return self.lines.pop() else: return "" input_storage_obj = I...
import java.io.*; import java.util.*; public class Main { private void solve() { int n = sc.nextInt(); int k = sc.nextInt(); int[] a = new int[n]; int[] b = new int[n]; long total = 0; for (int i = 0; i < n; i++) { a[i] = sc.nextInt(); b[i] ...
import copy shroud = [] aBerrySum = 0 bBerrySum = 0 n,k = map(int,input().split()) isAllRemainderCovered = False remainderCovered = [False for _ in range(k)] remainderCovered[0] = True for _ in range(n): a,b = map(int,input().split()) shroud.append([a,b]) aBerrySum += a bBerrySum += b if a >= k an...
import collections def doit(): N = int(input()) graph = dict() for n in range(N) : graph[n] = list() for n in range(N - 1): a, b = map(int, input().split()) graph[a-1].append(b-1) graph[b-1].append(a-1) msize = 0 for k in graph: msize = max(msize, len(gr...
//package cf780; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; import java.util.ArrayList; import java.util.Arrays; import java.ut...
#include <bits/stdc++.h> using namespace std; int main() { long long int i, count = 0, n; string s; cin >> s; n = s.size(); stack<char> st; for (i = 0; i < n; i++) { if (st.empty()) { st.push(s[i]); } else { if (st.top() == s[i]) { count++; st.pop(); } else { ...
//var input = readline() var str = readline() var ans = []; var cnt = 0; for (var j=0; j<str.length; j++) { if (ans[ans.length-1] == str[j]) { //while(s[j] == s[j+1] && s.length > 0) { ans.pop(); //print('pop = '+ ans.join('')); cnt ++; }...
n,a=map(int,raw_input().split()) x=map(int,raw_input().split()) x=sorted(x) if n==1: print 0 exit(0) else: print min(x[-2]-x[0]+abs(a-x[0]),x[-1]-x[1]+abs(x[1]-a), x[-2]-x[0]+abs(a-x[-2]),x[-1]-x[1]+abs(x[-1]-a))
import java.util.Arrays; import java.util.Scanner; public class Main { Scanner cin = new Scanner(System.in); public Main() { while (cin.hasNext()) { int n = cin.nextInt(), a = cin.nextInt(); int[] array = new int[n]; for (int i = 0; i < n; i++) array[i] = cin.nextInt(); if (n == 1) { System.ou...
mp = {"ani":"square1001","otouto":"e869120"} s = input() print(mp[s])
import java.util.*; public class Main { public static void main (String[] args) { Scanner sc = new Scanner(System.in); String s = sc.next(); if (s.equals("ani")) { System.out.println("square1001"); } else { System.out.println("e869120"); } } }
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**10 mod = 998244353 dd = [(0,-1),(1,0),(0,1),(-1,0)] ddn = [(0,-1),(1,-1),(1,0),(1,1),(0,1),(-1,-1),(-1,0),(-1,1)] def LI(): return [int(x) for x in sys.stdi...
#include<bits/stdc++.h> #define range(i,a,b) for(int i = (a); i < (b); i++) #define rep(i,b) for(int i = 0; i < (b); i++) #define all(a) (a).begin(), (a).end() #define debug(x) cout << "debug " << x << endl; const int INF = 100000000; using namespace std; int main(){ int h, w; cin >> w >> h; char m[100][1...
#include <iostream> #include <list> #include <iterator> #include <vector> void dump(std::list<int> L) { if (L.empty()) { std::cout << std::endl; return; } auto it = L.begin(); std::cout << *it; it++; for (; it != L.end(); it++) { std::cout << ' ' << *it; } ...
import sys from collections import deque sys.setrecursionlimit(10**9) n,q = map(int, input().split()) l = [deque() for _ in range(n)] for _ in range(q): query = input().split() if query[0] == "0": # insert idx = int(query[1]) l[idx].append(query[2]) elif query[0] == "1": # dump idx = int(query[1]) print(" ...
import sys def read(): return int(input()) def reads(): return [int(x) for x in input().split()] N,M=reads() table=[reads() for i in range(N)] A=[[0]*N for i in range(N)] B=[[0]*N for i in range(N)] for i in range(N): for j in range(N): res=10**9+7 for k in range(M): res=min(res,...
#include <bits/stdc++.h> using namespace std; struct str { int x, y; bool operator<(const str& A) const { return x < A.x; } }; int n, m, k, anscnt; int arr[20][30001]; int pre[20][20], qre[20][20]; int dp[20][20][1 << 16], first; map<int, int> mp; int cal(int cur, int val) { if (val == (1 << n) - 1) return qre[fi...
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 200200; char buffer[N]; string read() { scanf("%s", buffer); return buffer; } string solve(string a, string b, char c) { a += c; b += c; string result = ""; for (int i = 0, j = 0; i < a.size() || j < b.size()...
//package binaryliterature; import java.util.*; import java.io.*; public class binaryliterature { public static void main(String[] args) throws IOException { BufferedReader fin = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(fin.readLine()); StringBuilder fout = new StringBuild...
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws IOException { Reader in = new Reader(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out)); int n = in.nextInt(); int m = in.n...
#include <bits/stdc++.h> using namespace std; const int INF = 1000000000; const int MOD = 1000000007; signed main() { cin.tie(0), cout.tie(0); ios::sync_with_stdio(0); int n, k; cin >> n >> k; int a, b, c, d; cin >> a >> b >> c >> d; if (k < n + 1 || n <= 4) cout << -1 << '\n', exit(0); else { c...
#include <bits/stdc++.h> using namespace std; long long Abs(long long x) { if (x < 0) return -x; return x; } int Solve0(long long x0, long long y0, long long x1, long long y1, long long a) { x0 += y0; x1 += y1; if (x0 > x1) swap(x0, x1); if (x0 < 0) { long long tmp = ((-x0) / (2 * a) + 1) * 2...
import java.util.*; import java.io.*; import java.text.*; public class D124 { static long INF = (long) 1e9; static long a, b; public static long find1(long x1, long y1) { long lo = -INF; long hi = INF; long k = -INF; while (lo <= hi) { long mid = lo + hi >> 1; if (2 * a * mid - x1 < y1) { k = mi...
#include <bits/stdc++.h> using namespace std; using ll=long long; #define int ll #define rng(i,a,b) for(int i=int(a);i<int(b);i++) #define rep(i,b) rng(i,0,b) #define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--) #define per(i,b) gnr(i,0,b) #define pb push_back #define eb emplace_back #define a first #define b second ...
""" #If FastIO not needed, use this and don't forget to strip #import sys, math #input = sys.stdin.readline """ import os import sys from io import BytesIO, IOBase import heapq as h from bisect import bisect_left, bisect_right import time from types import GeneratorType BUFSIZE = 8192 class FastIO(IOBase): newl...