solution
stringlengths
10
983k
difficulty
int64
0
25
language
stringclasses
2 values
#include <bits/stdc++.h> using namespace std; void solve() { long long int n; cin >> n; vector<long long int> a(n); for (auto &x : a) cin >> x; long long int p = -1, q = -1, r = -1; long long int big = a[n - 1]; bool ok = false; for (int i = n - 2; i >= 0; i--) { if (a[i] + a[i - 1] <= big && i - 1 >= 0) { p = i; q = i + 1; r = n; ok = true; } } if (ok == true) cout << p << " " << q << " " << r << endl; else cout << -1 << endl; } int main() { long long int t; cin >> t; while (t--) { solve(); } }
7
CPP
#!/usr/bin/env python import os import sys from io import BytesIO, IOBase #from bisect import bisect_left as bl #c++ lowerbound bl(array,element) #from bisect import bisect_right as br #c++ upperbound br(array,element) def main(): for _ in range(int(input())): x1,y1,x2,y2=map(int,input().split(" ")) if x1==x2 or y1==y2: print(abs(x2-x1)+abs(y2-y1)) else: print(abs(x2-x1)+abs(y2-y1)+2) #-----------------------------BOSS-------------------------------------! # region fastio 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.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") # endregion if __name__ == "__main__": main()
7
PYTHON3
n,k=input().split() x,y=int(n),int(k) if 3*x>y: print((3*x)-y) else: print(0)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } template <class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } int n; vector<pair<int, int> > v; long long DP[3001][3001]; long long solve(int idx, int lst) { if (idx == n) return 0; long long &ret = DP[idx][lst]; if (ret != -1) return ret; ret = (1LL << 59); ret = min(ret, solve(idx + 1, lst) + v[idx].first - v[lst].first); ret = min(ret, solve(idx + 1, idx) + v[idx].second); return ret; } int main() { scanf("%d", &n); int a, b; for (int i = 0; i < n; ++i) { scanf("%d %d", &a, &b); v.push_back(pair<int, int>(a, b)); } memset(DP, -1, sizeof(DP)); sort(v.begin(), v.end()); cout << solve(1, 0) + 1LL * v[0].second; }
11
CPP
mod = 1000000007 eps = 10**-9 def main(): import sys input = sys.stdin.readline for _ in range(int(input())): N = int(input()) A = list(map(int, input().split())) flg = 1 for i in range(31, -1, -1): cnt = 0 for a in A: if a >> i & 1: cnt += 1 if cnt & 1: flg = 0 if cnt % 4 == 1: print("WIN") else: if N & 1: print("LOSE") else: print("WIN") break if flg: print("DRAW") if __name__ == '__main__': main()
10
PYTHON3
#include <bits/stdc++.h> using namespace std; long long a[2]; int main() { int n; string s; cin >> n; cin >> s; for (int i = 0; i < s.size(); i++) { if (s[i] == 'n') { a[0]++; } if (s[i] == 'z') { a[1]++; } } for (int i = 0; i < 2; i++) { for (int y = 0; y < a[i]; y++) { cout << 1 - i << " "; } } return 0; }
7
CPP
a,t = map(str, input().split()) if a==t: print('H') else: print('D')
0
PYTHON3
# !/usr/bin/env python3 # encoding: UTF-8 # Modified: <05/Jul/2019 08:57:12 PM> # βœͺ H4WK3yEδΉ‘ # Mohd. Farhan Tahir # Indian Institute Of Information Technology (IIIT), Gwalior import sys import os from io import IOBase, BytesIO def main(): n = int(input()) arr = get_array() arr.sort() if arr[-1] >= arr[-2] + arr[0]: if n == 3: print('NO') return if arr[-3] + arr[-2] > arr[-1]: arr[-2], arr[-1] = arr[-1], arr[-2] else: print('NO') return print('YES') print(*arr) BUFSIZE = 8192 class FastIO(BytesIO): newlines = 0 def __init__(self, file): self._file = file self._fd = file.fileno() self.writable = "x" in file.mode or "w" in file.mode self.write = super(FastIO, self).write if self.writable else None def _fill(self): s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0]) return s def read(self): while self._fill(): pass return super(FastIO, self).read() def readline(self): while self.newlines == 0: s = self._fill() self.newlines = s.count(b"\n") + (not s) self.newlines -= 1 return super(FastIO, self).readline() def flush(self): if self.writable: os.write(self._fd, self.getvalue()) self.truncate(0), self.seek(0) class IOWrapper(IOBase): def __init__(self, file): py2 = round(0.5) self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable if py2 == 1: self.write = self.buffer.write self.read = self.buffer.read self.readline = self.buffer.readline else: self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) def get_array(): return list(map(int, sys.stdin.readline().split())) def get_ints(): return map(int, sys.stdin.readline().split()) def input(): return sys.stdin.readline().strip() if __name__ == "__main__": main()
8
PYTHON3
#include <bits/stdc++.h> using namespace std; int idx, c; string one, s, ten[10]; int main() { cin >> one; for (int i = 0; i < 10; i++) { cin >> ten[i]; } for (int i = 0; i < 8; i++) { s = ""; for (int j = idx; j < idx + 10; j++) { s += one[j]; } idx += 10; for (int x = 0; x < 10; x++) { if (s == ten[x]) { cout << x; break; } } } return 0; }
7
CPP
#include <bits/stdc++.h> using namespace std; int main() { string s, kq = ""; cin >> s; if (s[0] == '/') cout << '/'; char *t = strtok(&s[0], "/"); while (t != NULL) { kq = kq + t + "/"; t = strtok(NULL, "/"); } cout << kq.substr(0, kq.length() - 1); }
7
CPP
N = int(input()) P = [input().split()+[i+1] for i in range(N)] P.sort(key=lambda x: (x[0], -int(x[1]), x[2])) for _, _, i in P: print(i)
0
PYTHON3
s = input() s = s.split('WUB') first = True for i in s: if len(i) > 0: if not first: print(' ', end = '') first = False print(i, end = '') print()
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int read() { char ch = getchar(); int x = 0, pd = 0; while (ch < '0' || ch > '9') pd |= ch == '-', ch = getchar(); while ('0' <= ch && ch <= '9') x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar(); return pd ? -x : x; } const int maxn = 300005; int n, p[maxn], vis[maxn]; struct node { int val, cnt; bool operator<(const node x) const { return val < x.val; } } min1[maxn << 2], min2[maxn << 2]; int t[maxn << 2]; void _sort(node &a, node &b, node &c, node &d) { if (b < a) swap(a, b); if (c < a) swap(a, c); if (d < a) swap(a, d); if (c < b) swap(b, c); if (d < b) swap(b, d); if (d < c) swap(c, d); } void pushup(int rt) { node x = (rt << 1)[min1], y = (rt << 1)[min2], z = (rt << 1 | 1)[min1], w = (rt << 1 | 1)[min2]; _sort(x, y, z, w); rt[min1] = x; if (y.val == x.val) { rt[min1].cnt += y.cnt; rt[min2] = z; if (w.val == z.val) rt[min2].cnt += w.cnt; } else { rt[min2] = y; if (z.val == y.val) rt[min2].cnt += z.cnt; } } void pushdown(int rt) { int _t = rt[t]; (rt << 1)[min1].val += _t, (rt << 1)[min2].val += _t; (rt << 1 | 1)[min1].val += _t, (rt << 1 | 1)[min2].val += _t; (rt << 1)[t] += _t, (rt << 1 | 1)[t] += _t, rt[t] = 0; } void build(int rt, int l, int r) { if (l == r) { rt[min1].cnt = 1, rt[min2].val = 0x3f3f3f3f; return; } int mid = (l + r) >> 1; build((rt << 1), l, mid), build((rt << 1 | 1), mid + 1, r); } void update(int rt, int l, int r, int L, int R, int x) { if (L <= l && r <= R) { rt[min1].val += x, rt[min2].val += x; rt[t] += x; return; } if (rt[t]) pushdown(rt); int mid = (l + r) >> 1; if (L <= mid) update((rt << 1), l, mid, L, R, x); if (R > mid) update((rt << 1 | 1), mid + 1, r, L, R, x); pushup(rt); } long long ans; int query(int rt, int l, int r, int L, int R) { if (L <= l && r <= R) { if (rt[min2].val <= 2) return rt[min1].cnt + rt[min2].cnt; return rt[min1].val <= 2 ? rt[min1].cnt : 0; } if (rt[t]) pushdown(rt); int mid = (l + r) >> 1; if (R <= mid) return query((rt << 1), l, mid, L, R); if (L > mid) return query((rt << 1 | 1), mid + 1, r, L, R); return query((rt << 1), l, mid, L, R) + query((rt << 1 | 1), mid + 1, r, L, R); } int main() { n = read(); for (int i = 1; i <= n; i++) p[vis[i] = read()] = i; build(1, 1, n); for (int i = 1; i <= n; i++) { int x, y; if (p[i] == 1) { if (vis[2] > i) update(1, 1, n, 1, i, 1); else update(1, 1, n, vis[2] + 1, i, 1); } else if (p[i] == n) { if (vis[n - 1] > i) update(1, 1, n, 1, i, 1); else update(1, 1, n, vis[n - 1] + 1, i, 1); } else if (vis[p[i] - 1] > i && vis[p[i] + 1] > i) update(1, 1, n, 1, i, 1); else if ((vis[p[i] - 1] > i && vis[p[i] + 1] < i) || (vis[p[i] - 1] < i && vis[p[i] + 1] > i)) { if (p[i] == 1) x = vis[2]; else if (p[i] == n) x = vis[n - 1]; else x = min(vis[p[i] - 1], vis[p[i] + 1]); update(1, 1, n, x + 1, i, 1); } else { x = min(vis[p[i] - 1], vis[p[i] + 1]); y = vis[p[i] - 1] + vis[p[i] + 1] - x; update(1, 1, n, x + 1, i, 1), update(1, 1, n, 1, y, -1); } if (i > 1) ans += query(1, 1, n, 1, i - 1); } printf("%lld\n", ans); return 0; }
10
CPP
for _ in range(int(input())): input();s = input() print('NO' if s.find('8')==-1 or len(s[s.find('8'):])<11 else 'YES')
7
PYTHON3
i,p=input,print;n,b,q=int(i()),[int(x)&1 for x in i().split()],[];f=q.append;f(b[0]) for a in b[1:]:q.pop() if q and q[-1] == a else f(a) p('NO' if len(q)>1 else 'YES')
10
PYTHON3
#include<iostream> #include<cstring> using namespace std; char a[8000][8000]; int h, w, loop, cx, cy; int main() { while (true) { cin >> h >> w; if (!h) { break; } memset(a, ' ', sizeof(a)); for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { cin >> a[i][j]; } } cx = 0; cy = 0; loop = 0; while (true) { if (loop > 15000000) { cout << "LOOP" << endl; break; } if (a[cy][cx] == '.') { cout << cx << ' ' << cy << endl; break; } if (a[cy][cx] == '<') { cx--; } if (a[cy][cx] == '>') { cx++; } if (a[cy][cx] == '^') { cy--; } if (a[cy][cx] == 'v') { cy++; } loop++; } } }
0
CPP
#include <bits/stdc++.h> using namespace std; int dp[2010][2010]; string A, B; int sa, sb; int dif(int pa, int pb) { if (pa >= sa || pb >= sb) return 0; if (dp[pa][pb] != -1) return dp[pa][pb]; return dp[pa][pb] = (A[pa] != B[pb]) + dif(pa + 1, pb + 1); } int main() { memset(dp, -1, sizeof dp); cin >> A >> B; sa = A.size(); sb = B.size(); int ans = (int)1E9; for (int i = 0; i < sa; ++i) for (int j = 0; j < sb; ++j) { int get = min(sb - j, sa - i); ans = min(ans, sb - get + dif(i, j)); } cout << ans << '\n'; return 0; }
7
CPP
from math import ceil from fractions import Fraction t = int(input()) for i in range(t): x,y,k = map(int,input().split()) palki = k * (y + 1) print(ceil(Fraction(palki - 1,x - 1)) + k)
7
PYTHON3
from __future__ import division, print_function import sys if sys.version_info[0] < 3: from __builtin__ import xrange as range from future_builtins import ascii, filter, hex, map, oct, zip import os, sys, bisect, copy from collections import defaultdict, Counter, deque #from functools import lru_cache #use @lru_cache(None) if os.path.exists('in.txt'): sys.stdin=open('in.txt','r') if os.path.exists('out.txt'): sys.stdout=open('out.txt', 'w') # def input(): return sys.stdin.readline() def mapi(arg=0): return map(int if arg==0 else str,input().split()) #------------------------------------------------------------------ for _ in range(int(input())): n = int(input()) a = list(mapi()) b = list(mapi()) if n&1 and a[n//2]!=b[n//2]: print("No") continue f = 1 mp = defaultdict(int) for i in range(n//2): mp[(min(a[i],a[n-i-1]),max(a[i],a[n-i-1]))]+=1 for i in range(n//2): mp[(min(b[i],b[n-i-1]),max(b[i],b[n-i-1]))]-=1 if mp[(min(b[i],b[n-i-1]),max(b[i],b[n-i-1]))]<0: f = 0 break if f: print("Yes") else: print("No")
12
PYTHON3
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0; i<(n); i++) int n, ans, l[2005]; int main() { scanf("%d", &n); rep(i,n) scanf("%d", l+i); sort(l, l+n); rep(i,n) rep(j,i){ ans += (int)(lower_bound(l, l+n, l[i]+l[j]) - l) - i - 1; } printf("%d\n", ans); }
0
CPP
import sys input = sys.stdin.readline t=int(input()) for testcases in range(t): n=int(input()) S=input().strip() ANS=n if "1" in S: t=S.index("1") ANS=max(ANS,(n-t)*2) #print(t) t=S[::-1].index("1") ANS=max(ANS,(n-t)*2) #print(t) print(ANS)
8
PYTHON3
#include <bits/stdc++.h> using namespace std; const int BUF_SIZE = 30; char buf[BUF_SIZE], *buf_s = buf, *buf_t = buf + 1; const int maxn = 1010; const int maxs = 1000010; int n, s, z[maxn], y[maxs][2]; int check() { int cnt = 0; for (int a = 1; a <= n; a++) if (z[a]) cnt++; return cnt; } int main() { { while (*buf_s != '-' && !isdigit(*buf_s)) { buf_s++; if (buf_s == buf_t) { buf_s = buf; buf_t = buf + fread(buf, 1, BUF_SIZE, stdin); } }; bool register _nega_ = false; if (*buf_s == '-') { _nega_ = true; { buf_s++; if (buf_s == buf_t) { buf_s = buf; buf_t = buf + fread(buf, 1, BUF_SIZE, stdin); } }; } int register _x_ = 0; while (isdigit(*buf_s)) { _x_ = _x_ * 10 + *buf_s - '0'; { buf_s++; if (buf_s == buf_t) { buf_s = buf; buf_t = buf + fread(buf, 1, BUF_SIZE, stdin); } }; } if (_nega_) _x_ = -_x_; (n) = (_x_); }; for (int a = 1; a <= n; a++) { while (*buf_s != '-' && !isdigit(*buf_s)) { buf_s++; if (buf_s == buf_t) { buf_s = buf; buf_t = buf + fread(buf, 1, BUF_SIZE, stdin); } }; bool register _nega_ = false; if (*buf_s == '-') { _nega_ = true; { buf_s++; if (buf_s == buf_t) { buf_s = buf; buf_t = buf + fread(buf, 1, BUF_SIZE, stdin); } }; } int register _x_ = 0; while (isdigit(*buf_s)) { _x_ = _x_ * 10 + *buf_s - '0'; { buf_s++; if (buf_s == buf_t) { buf_s = buf; buf_t = buf + fread(buf, 1, BUF_SIZE, stdin); } }; } if (_nega_) _x_ = -_x_; (z[a]) = (_x_); }; int p1 = 0, p2 = 0, p3, x; for (int a = 1; a <= n; a++) { if (!z[p1]) p1 = a; else { if (!z[p2]) p2 = a; else { p3 = a; while (true) { if (z[p3] < z[p1]) swap(p1, p3); if (z[p2] < z[p1]) swap(p1, p2); if (z[p3] < z[p2]) swap(p2, p3); if (!z[p1]) break; x = z[p2] / z[p1]; while (x) { s++; y[s][0] = p1; if (x & 1) y[s][1] = p2, z[p2] -= z[p1]; else y[s][1] = p3, z[p3] -= z[p1]; z[p1] <<= 1; x >>= 1; } } p1 = p2; p2 = p3; } } } if (check() != 2) { printf("-1\n"); return 0; }; printf("%d\n", s); for (int a = 1; a <= s; a++) printf("%d %d\n", y[a][0], y[a][1]); return 0; }
11
CPP
#include <bits/stdc++.h> using namespace std; set<int> gSetka; int main() { int n; cin >> n; set<int> setka; setka.insert(0); for (int i = 0; i < n; ++i) { int cur; cin >> cur; set<int> newSetka; gSetka.insert(cur); newSetka.insert(cur); for (auto it = setka.begin(); it != setka.end(); ++it) { newSetka.insert(*it | cur); gSetka.insert(*it | cur); } swap(setka, newSetka); } cout << gSetka.size(); return 0; }
7
CPP
h1,m1,h2,m2,k = map(int,input().split()) t = h2*60+m2-h1*60-m1-k print(t)
0
PYTHON3
#include <bits/stdc++.h> using namespace std; int ds[10]; int main() { int n, k; scanf("%d%d", &n, &k); if (n == 0) { puts("0"); return 0; } int m = 0; for (; n > 0; n /= 10) ds[m++] = n % 10; int w = 0; for (int i = 0; i < m && k > 0; i++) { if (ds[i] == 0) k--; else w++; } if (k > 0) w = m - 1; printf("%d\n", w); return 0; }
8
CPP
x,y = map(int, input().split()) matriz = [[0 for i in range(y)] for i in range (x)] lista = [] if y <= 1: for c in range(x): z = int(input()) if c > 0: matriz[c][0] = matriz[c-1][0] + z else: matriz[c][0] = z else: for c in range(x): z = list(map(int, input().split())) lista.append(z) if c == 0: matriz[c][0] = z[0] else: matriz[c][0] = matriz[c-1][0] + z[0] for c in range(1, y): matriz[0][c] = lista[0][c] + matriz[0][c-1] msg = "" if y != 1: for i in range(1, x): for j in range(1, y): if matriz[i][j] != 0: pass else: if matriz[i-1][j] >= matriz[i][j-1]: matriz[i][j] = matriz[i-1][j] + lista[i][j] elif matriz[i-1][j] < matriz[i][j-1]: matriz[i][j] = matriz[i][j-1] + lista[i][j] for c in range(x): msg += str(matriz[c][-1]) + " " print(msg.strip())
8
PYTHON3
#include <iostream> #include <vector> #include <algorithm> using namespace std; int main( void ) { int n; while ( cin >> n ) { vector <int> T(n); for ( int i = 0; i < n; i++ ) cin >> T[i]; sort( T.begin(), T.end() ); int s = 0, t = 0; for ( int i = 0; i < n; i++ ) { s += T[i] + t; t += T[i]; } cout << s << endl; } return 0; }
0
CPP
#include <bits/stdc++.h> using namespace std; vector<int> primes; void buildSieve(int n) { vector<int> spf; spf.resize(n + 1, 0); spf[0] = spf[1] = 1; for (int i = 2; i <= n; ++i) { if (spf[i] == 0) { primes.push_back(i); spf[i] = i; } for (int j = 0; j < int(primes.size()) && primes[j] <= spf[i] && i * primes[j] <= n; ++j) { spf[i * primes[j]] = primes[j]; } } } int main() { buildSieve(500100); int n; cin >> n; int p = *lower_bound(primes.begin(), primes.end(), n); int d = p - n; assert(d <= n / 2); cout << p << endl; for (int i = 1; i < n; i++) { cout << i << ' ' << i + 1 << endl; } cout << n << ' ' << 1 << endl; int i = 1; while (d != 0) { if (d == 1) { break; } cout << i << ' ' << i + 2 << endl; cout << i + 1 << ' ' << i + 3 << endl; d -= 2; i += 4; } if (d == 1) { cout << i << ' ' << i + 2 << endl; } cin.ignore(2); return 0; }
10
CPP
import math def lcm(x,y): p=math.gcd(x,y) l=(x*y)/p return l tc=int(input()) for i in range(tc): a,b,c=map(int,input().split()) min1=123456789 x=a y=b z=c for i in range(1,10001): for j in range(i,100001,i): s=int(abs(i-a)+abs(j-b)) if s>min1: continue p=lcm(i,j) r=p-(c%p) if r==p: r=0 if c%p<r: s+=c%p r=-(c%p) else: s+=r if s<min1: min1=s x=i y=j z=c+r print(int(min1)) print(int(x),int(y),int(z),sep=" ")
10
PYTHON3
str1 = input("").lower() str2 = input("").lower() if (str1 > str2): print("1") elif (str1 == str2): print("0") else: print("-1")
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int a[1001], i, j, n, x, y; bool b; int main() { b = false; cin >> n; a[0] = 0; a[n + 1] = n + 1; for (i = 1; i <= n; i++) { cin >> a[i]; } for (i = 1; i <= n; i++) { if (a[i] == a[i - 1] + 1) continue; else { x = i; for (j = i + 1; j <= n + 1; j++) if (a[j] == a[j - 1] - 1) continue; else if (a[i] == a[j] - 1) { y = j - 1; break; break; } else { cout << "0 0"; return 0; } break; } } for (i = x; i <= (y + x) / 2; i++) swap(a[i], a[y - i + x]); for (i = 1; i <= n; i++) if (a[i] != a[i - 1] + 1) b = true; if (b == false) cout << x << " " << y; else cout << "0 0"; return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; string s; int t; inline bool all_same() { for (int i = 0, len = s.size(); i < len; i++) if (s[i] != s[0]) return 0; return 1; } int main() { cin >> t; while (t--) { cin >> s; if (all_same()) cout << s << '\n'; else { for (int i = 0, len = s.size(); i < len; i++) { cout << "10"; } cout << '\n'; } } }
8
CPP
n = int(input()) count = 0 for i in range(n): a = [int(x) for x in input().split()] if sum(a) >= 2: count += 1 print(count)
7
PYTHON3
from collections import defaultdict from sys import setrecursionlimit,stdin input=stdin.readline setrecursionlimit(100000) def dfs(r,g,b,rr,gg,bb): if (r==0 and b==0) or (r==0 and g==0) or (g==0 and b==0) : return 0 x=0 y=0 z=0 if dp[r][g][b]!=-1: return dp[r][g][b] if r!=0 and g!=0: x=rr[r-1]*gg[g-1]+dfs(r-1,g-1,b,rr,gg,bb) if r!=0 and b!=0: y=rr[r-1]*bb[b-1]+dfs(r-1,g,b-1,rr,gg,bb) if b!=0 and g!=0: z=bb[b-1]*gg[g-1]+dfs(r,g-1,b-1,rr,gg,bb) dp[r][g][b]=max(x,y,z) return max(x,y,z) r,g,b=map(int,input().split()) rr=list(map(int,input().split())) gg=list(map(int,input().split())) bb=list(map(int,input().split())) rr.sort() gg.sort() bb.sort() dp=[[[-1]*(b+1) for i in range(g+1)] for j in range(r+1)] print(dfs(r,g,b,rr,gg,bb))
10
PYTHON3
def checkhash(p,h): aux = False for i in range(0,(len(h)-len(p))+1): cont = 0 for j in range(len(p)): if(h[i:(len(p)+i)].count(p[j]) == p.count(p[j])): cont+=1 if(cont == len(p)): aux = True break if(aux): return "YES" return "NO" t = int(input()) for e in range(t): p = input() h = input() print(checkhash(p,h))
7
PYTHON3
w, h = map(int, input().split()) print((2**(w+h))%(998244353))
9
PYTHON3
#include <bits/stdc++.h> using namespace std; int a[100]; int main() { int n, d, m; while (cin >> n >> d) { int sum = 0; for (int i = 0; i < n; i++) { cin >> a[i]; sum += a[i]; } cin >> m; sort(a, a + n); if (n < m) cout << sum - (m - n) * d << endl; else { sum = 0; for (int i = 0; i < m; i++) sum += a[i]; cout << sum << endl; } } return 0; }
7
CPP
import os import sys from io import BytesIO, IOBase _str = str BUFSIZE = 8192 def str(x=b''): return x if type(x) is bytes else _str(x).encode() 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.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b'\n') + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode('ascii')) self.read = lambda: self.buffer.read().decode('ascii') self.readline = lambda: self.buffer.readline().decode('ascii') def inp(): return sys.stdin.readline().rstrip() def mpint(): return map(int, inp().split(' ')) def itg(): return int(inp()) # ############################## import from collections import Counter def gcd(x, y): """greatest common divisor of x and y""" while y: x, y = y, x % y return x def memodict(f): """memoization decorator for a function taking a single argument""" class memodict(dict): def __missing__(self, key): ret = self[key] = f(key) return ret return memodict().__getitem__ def pollard_rho(n): """returns a random factor of n""" if n & 1 == 0: return 2 if n % 3 == 0: return 3 s = ((n - 1) & (1 - n)).bit_length() - 1 d = n >> s for a in [2, 325, 9375, 28178, 450775, 9780504, 1795265022]: p = pow(a, d, n) if p == 1 or p == n - 1 or a % n == 0: continue for _ in range(s): prev = p p = (p * p) % n if p == 1: return gcd(prev - 1, n) if p == n - 1: break else: for i in range(2, n): x, y = i, (i * i + 1) % n f = gcd(abs(x - y), n) while f == 1: x, y = (x * x + 1) % n, (y * y + 1) % n y = (y * y + 1) % n f = gcd(abs(x - y), n) if f != n: return f return n @memodict def prime_factors(n): """returns a Counter of the prime factorization of n""" if n <= 1: return Counter() f = pollard_rho(n) return Counter([n]) if f == n else prime_factors(f) + prime_factors(n // f) # ############################## main def solve(): p, q = mpint() if p % q: return p qf = prime_factors(q).copy() pf = Counter() mx = 1 for f in qf: p //= f ** qf[f] pf[f] = qf[f] while not p % f: p //= f pf[f] += 1 qf[f] -= 1 mx *= f ** pf[f] ans = 1 for f, exp in qf.items(): ans = max(ans, mx // f ** (pf[f] - exp)) return ans * p def main(): # print("YES" if solve() else "NO") # print("yes" if solve() else "no") # solve() # print(solve()) for _ in range(itg()): print(solve()) DEBUG = 0 URL = 'https://codeforces.com/contest/1445/problem/C' if __name__ == '__main__': if DEBUG == 1: import requests # ImportError: cannot import name 'md5' from 'sys' (unknown location) from ACgenerator.Y_Test_Case_Runner import TestCaseRunner runner = TestCaseRunner(main, URL) inp = runner.input_stream print = runner.output_stream runner.checking() elif DEBUG == 2: main() else: sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) main() # Please check!
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } int lcm(int a, int b) { return ((a * b) / gcd(a, b)); } vector<long long int> v; map<long long int, int> A; int main() { int a, n, m, i; cin >> n >> m; for (i = 0; i < n; ++i) { cin >> a; A[a] = -1; } for (i = 1;; ++i) { if (A[i] != -1) { if (m - i >= 0) { m -= i; v.push_back(i); } else break; } else continue; } cout << v.size() << endl; for (i = 0; i < v.size(); ++i) cout << v[i] << " "; }
9
CPP
#include <bits/stdc++.h> using namespace std; template <typename T> void maxtt(T& t1, T t2) { t1 = max(t1, t2); } template <typename T> void mintt(T& t1, T t2) { t1 = min(t1, t2); } bool debug = 0; int n, m, k; int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; string direc = "RDLU"; long long ln, lk, lm; void etp(bool f = 0) { puts(f ? "YES" : "NO"); exit(0); } void addmod(int& x, int y, int mod = 998244353) { assert(y >= 0); x += y; if (x >= mod) x -= mod; assert(x >= 0 && x < mod); } void et(int x = -1) { printf("%d\n", x); exit(0); } long long fastPow(long long x, long long y, int mod = 998244353) { long long ans = 1; while (y > 0) { if (y & 1) ans = (x * ans) % mod; x = x * x % mod; y >>= 1; } return ans; } long long gcd1(long long x, long long y) { return y ? gcd1(y, x % y) : x; } struct Point { int x, y; Point() {} Point(int x, int y) : x(x), y(y) {} long double abs() const { return hypot(x, y); } long double arg() const { return atan2(y, x); } Point operator*(double o) const { return Point(x * o, y * o); } Point operator+(const Point& o) const { return Point(x + o.x, y + o.y); } Point operator-(const Point& o) const { return Point(x - o.x, y - o.y); } Point operator/(double o) const { return Point(x / o, y / o); } bool operator<(const Point& o) const { return x < o.x - 1e-9 || (x < o.x + 1e-9 && y < o.y - 1e-9); } friend bool operator==(const Point& r1, const Point& r2) { return r1.x == r2.x && r1.y == r2.y; } int cross(Point b) const { return x * b.y - b.x * y; } void readin() { scanf("%d%d", &x, &y); } void pp() { printf("%d %d\n", x, y); } } a[6135], b[6135]; int r[6135]; void cal(vector<int> A, vector<int> B) { if (A.size() == 1) { if (!debug) for (int z : B) printf("%d %d\n", z, A[0]); return; } if (B.size() == 1) { if (!debug) for (int z : A) printf("%d %d\n", B[0], z); return; } assert(A.size() > 1 && B.size() > 1); int mxR = 0, tar = -1; for (int z : B) if (mxR < r[z]) { tar = z; mxR = r[z]; } vector<pair<long double, int>> vp; for (int z : A) { vp.push_back({(a[z] - b[tar]).arg(), z + m}); } for (int z : B) if (z != tar) { vp.push_back({(b[z] - b[tar]).arg(), z}); } sort(vp.begin(), vp.end()); int N = vp.size(), S = 0; for (int i = 0, j = -1; i < N; i++) { j = max(i, j); if (i == j) { S += 1 - r[vp[i].second]; j++; } Point cur = vp[i].second <= m ? b[vp[i].second] : a[vp[i].second - m]; cur = cur - b[tar]; while (1) { int id = vp[j % N].second; Point tt = id <= m ? b[id] : a[id - m]; tt = tt - b[tar]; if (tt.cross(cur) < 0) { S += 1 - r[id]; j++; } else break; } if (S >= 1 && S <= mxR - 1) { r[tar] = S; vector<int> ta, tb; tb.push_back(tar); for (int z = i; z < j; z++) { int id = vp[z % N].second; if (id <= m) tb.push_back(id); else ta.push_back(id - m); } cal(ta, tb); r[tar] = mxR - S; ta.clear(); tb.clear(); tb.push_back(tar); for (int z = j;; z++) { if (z % N == i) break; int id = vp[z % N].second; if (id <= m) tb.push_back(id); else ta.push_back(id - m); } cal(ta, tb); break; } S -= 1 - r[vp[i].second]; } } void fmain(int tid) { scanf("%d%d", &n, &m); for (int(i) = 1; (i) <= (int)(m); (i)++) { scanf("%d", r + i); } for (int(i) = 1; (i) <= (int)(n); (i)++) r[m + i] = 0; for (int(i) = 1; (i) <= (int)(n); (i)++) a[i].readin(); for (int(j) = 1; (j) <= (int)(m); (j)++) b[j].readin(); vector<int> A, B; for (int(i) = 1; (i) <= (int)(n); (i)++) A.push_back(i); for (int(j) = 1; (j) <= (int)(m); (j)++) B.push_back(j); if (!debug) puts("YES"); cal(A, B); } int main() { int t = 1; scanf("%d", &t); for (int(i) = 1; (i) <= (int)(t); (i)++) { fmain(i); } return 0; }
20
CPP
n=int(input()) A=list(map(int,input().split())) B=[A[i] for i in range(0,n)] B.sort(reverse=True) ans=0 a=[];p=[0 for i in range(n+1)] for i in range(0,n): ans+=(B[i]*i+1) for j in range(n): if(B[i]==A[j] and p[j]==0): a.append(j+1) p[j]=1 break print(ans) print(*a)
8
PYTHON3
#include <bits/stdc++.h> int a[1005][1005]; int main() { int n, m; while (~scanf("%d%d", &n, &m)) { int s = 0; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) scanf("%d", &a[i][j]); } for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { if (a[i][j] == 1) { for (int k = i - 1; k >= 1; k--) { if (a[k][j] == 0) s++; else break; } for (int k = i + 1; k <= n; k++) { if (a[k][j] == 0) s++; else break; } for (int k = j - 1; k >= 1; k--) { if (a[i][k] == 0) s++; else break; } for (int k = j + 1; k <= m; k++) { if (a[i][k] == 0) s++; else break; } } } } printf("%d\n", s); } }
8
CPP
#include <bits/stdc++.h> using namespace std; int main() { vector<int> l; int n, a[103], far[1008] = {0}, cnt = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; if (far[a[i]] == 0) l.push_back(a[i]); far[a[i]]++; } int x = n; if (n % 2 == 1) x++; for (int i = 0; i < l.size(); i++) { int z = l[i]; if (z % 2 == 1) x++; if (far[z] > (x / 2)) { return puts("NO"); } } cout << "YES"; return 0; }
7
CPP
#include <bits/stdc++.h> using namespace std; int T; char s[1000]; map<vector<int>, int> M; void init() { for (int x = 1989; x <= 30000; x++) { vector<int> tmp; int y = x; tmp.push_back(y % 10); y /= 10; for (;;) { if (M.find(tmp) == M.end()) { M[tmp] = x; break; } if (y == 0) break; tmp.push_back(y % 10); y /= 10; } } } long long p10[20]; int f(long long x, int t) { x /= p10[t]; return x % 10; } int main() { p10[0] = 1; for (int i = 1; i < 20; i++) p10[i] = p10[i - 1] * 10; init(); cin >> T; while (T--) { scanf("%s", s); int len = strlen(s); vector<int> a, b; for (int i = len - 1; i > 3; i--) a.push_back(s[i] - '0'); b.push_back(s[len - 1] - '0'); long long last = M[b]; for (int i = 0; i < a.size(); i++) { if (i != 0) last += p10[i]; while (f(last, i) != a[i]) last += p10[i]; } cout << last << endl; } return 0; }
10
CPP
#include <bits/stdc++.h> using namespace std; const int INF = (-1u) / 2; const long long int INF2 = (-1ull) / 2; int a, b, i, d[1011000], j, k, n, m, timer = 0, l, r, x, y; int c[1011000], cnt = 0, fl = 0, a2, a3 = -1000000, ans = 0; int main() { ios_base::sync_with_stdio(0); cin >> n; j = 1; k = n + 1; a = 1; while (a < n) { if (a % 2 != 0) { c[j] = a; c[j + (n - a)] = a; j++; } else { c[k] = a; c[k + (n - a)] = a; k++; } a++; } for (i = 1; i <= n * 2; i++) { if (c[i] == 0) c[i] = n; cout << c[i] << " "; } return 0; }
10
CPP
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int x = 0; for (char c : s) { if (x == 0 && c == 'C') x = 1; else if (x == 1 && c == 'F') x = 2; } cout << (x == 2 ? "Yes" : "No") << endl; }
0
CPP
# cook your dish here import sys import math import bisect from sys import stdin, stdout from math import gcd, floor, sqrt, log2, ceil from collections import defaultdict as dd from bisect import bisect_left as bl, bisect_right as br from bisect import insort from collections import Counter from collections import deque from heapq import heappush,heappop,heapify from itertools import permutations,combinations from itertools import accumulate as ac mod = int(1e9)+7 #mod = 998244353 ip = lambda : int(stdin.readline()) inp = lambda: map(int,stdin.readline().split()) ips = lambda: stdin.readline().rstrip() out = lambda x : stdout.write(str(x)+"\n") t = ip() for _ in range(t): n = ip() arr = list(inp()) ans = sum(arr)/n ans = ceil(ans) print(ans)
7
PYTHON3
n,k=map(int, input().split()) x = [int(x) for x in input().split()] count=0 for i in range(0,n): if x[i]>=x[k-1] and x[i]>0: count=count+1 print(count)
7
PYTHON3
kl = int(input()) for l in range(kl): x1, y1, x2, y2 = map(int, input().split()) print(1 + (x2-x1)*(y2-y1))
9
PYTHON3
// AOJ 0212 (http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0212) #include<cstdio> #include<algorithm> #include<limits> #include<queue> #include<vector> #define rep(i,a) for(int i=0;i<(a);++i) typedef std::pair<int, int> P; const int MAX_N = 100, MAX_C = 10, INF = std::numeric_limits<int>::max()>>2; struct St { int v, dist, tick; St( int v, int dist, int tick ) : v(v), dist(dist), tick(tick) {} bool operator< ( const St &s ) const { return dist > s.dist; } }; int c, n, m, s, d; std::vector<P> G[MAX_N]; int dp[MAX_N][MAX_C]; int main() { while( scanf( "%d%d%d%d%d", &c, &n, &m, &s, &d ), c|n|m|s|d ) { rep( i, n ) G[i].clear(); --s; --d; rep( i, m ) { int a, b, f; scanf( "%d%d%d", &a, &b, &f ); --a; --b; G[a].push_back( P( b, f ) ); G[b].push_back( P( a, f ) ); } std::priority_queue<St> pque; pque.push( St( s, 0, c ) ); rep( i, n ) rep( j, c+1 ) dp[i][j] = INF; dp[s][c] = 0; while( !pque.empty() ) { St st = pque.top(); pque.pop(); int v = st.v, dist = st.dist, t = st.tick; if( dp[v][t] < dist ) continue; rep( i, G[v].size() ) { P &e = G[v][i]; if( dp[e.first][t] > dp[v][t]+e.second ) { dp[e.first][t] = dp[v][t]+e.second; pque.push( St( e.first, dp[v][t]+e.second, t ) ); } if( t && dp[e.first][t-1] > dp[v][t]+e.second/2 ) { dp[e.first][t-1] = dp[v][t]+e.second/2; pque.push( St( e.first, dp[v][t]+e.second/2, t-1 ) ); } } } printf( "%d\n", *std::min_element( dp[d], dp[d]+c+1 ) ); } return 0; }
0
CPP
#include <cstdio> #include <cstring> char s[1000000]; int n; long long ans; int main() { scanf("%s", s), n = strlen(s); for (int i = 0, j = 0; i < n; ++i) if (s[i] == 'W') ans += i - j, ++j; printf("%lld\n", ans); return 0; }
0
CPP
s=input() if('0' in s): i=s.index('0') print(s[:i]+s[i+1:]) else: print(s[0:-1])
7
PYTHON3
n, k = map(int, input().split()) t = '' for i in map(ord, input()): d = min(k, max(122 - i, i - 97)) t += chr(i + d if i + d < 123 else i - d) k -= d print(-1 if k else t) # Made By Mostafa_Khaled
9
PYTHON3
n = int(input()) l = list(map(int, input().split())) k0 = kb = km = 0 for x in l: if x == 0: k0 += 1 elif x > 0: kb += 1 else: km += 1 if k0 > (n + 1) // 2 or (km < (n + 1) // 2 and kb < (n + 1) // 2): print(0) else: print(1 if kb > km else -1)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int dir1[8][2] = {1, 2, 2, 1, 2, -1, 1, -2, -1, 2, -2, 1, -1, -2, -2, -1}; int dir2[4][2] = {1, 0, 0, 1, -1, 0, 0, -1}; int dir3[8][2] = {1, 0, 0, 1, -1, 0, 0, -1, 1, 1, 1, -1, -1, 1, -1, -1}; int gcd(int x, int y) { return y == 0 ? x : gcd(y, x % y); } bool isPrime(int x) { if (x == 1) return false; else if (x == 2) return true; for (int i = 2; i <= sqrt(x * 1.0); ++i) { if (x % i == 0) return false; } return true; } int sqr(int x) { return x * x; } int sum[200005], he[200005], h[200005]; int vis[1200]; int main() { int n; while (~scanf("%d%*c", &n)) { memset(sum, 0, sizeof(sum)); memset(he, 0, sizeof(he)); memset(vis, 0, sizeof(vis)); int x, y; int maxn = -1; for (int i = 1; i <= n; ++i) { scanf("%d %d", &x, &y); sum[i] = sum[i - 1] + x; he[i] = y; h[i] = he[i]; vis[y]++; maxn = max(maxn, y); } sort(h + 1, h + 1 + n); vector<int> vt; vt.clear(); for (int i = 1; i <= n; ++i) { int height; int width = sum[n] - sum[i] + sum[i - 1] - sum[0]; if (he[i] == maxn && vis[maxn] > 1 || he[i] < maxn) height = maxn; else height = h[n - 1]; int area = width * height; vt.push_back(area); } for (int i = 0; i < vt.size(); ++i) cout << vt[i] << " "; cout << endl; } return 0; }
8
CPP
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.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def Yes(): print('Yes') def No(): print('No') def YES(): print('YES') def NO(): print('NO') INF = 10 ** 18 MOD = 10**9+7 Ri = lambda : [int(x) for x in sys.stdin.readline().split()] ri = lambda : sys.stdin.readline().strip() # for _ in range(int(ri())): s = ri() k = int(ri()) se = set() dic = {} for i in s: dic[i] = dic.get(i, 0)+1 lis = [(i,dic[i]) for i in dic] lis.sort(key = lambda x : (x[1])) tot = 0 for i in range(len(lis)): if lis[i][1] <= k: k-=lis[i][1] se.add(lis[i][0]) tot+=1 else: # tot = len(lis) - i break ans = [] for i in range(len(s)): if s[i] not in se: ans.append(s[i]) print(len(dic) - len(se)) print("".join(ans))
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; map<char, vector<int>> m; map<pair<char, int>, int> l; map<char, int> p; for (int k = 0; k < s.length(); k++) { m[s[k]].push_back(k + 1); if (m[s[k]].size() > 0) { char c = s[k]; l[make_pair(c, m[s[k]].size())] = k + 1; } } int q; cin >> q; string x; while (q--) { cin >> x; for (int k = 0; k < x.length(); k++) { p[x[k]]++; } int mymax = INT_MIN; for (auto itr = p.begin(); itr != p.end(); itr++) { int a = itr->second; char x = itr->first; int k = l[make_pair(x, a)]; if (k > mymax) mymax = k; } cout << mymax << endl; p.clear(); } }
8
CPP
N,C,K=map(int,input().split()) T=[int(input()) for i in range(N)] T.sort() S=[[T[0]]] t=T[0] k=0 for i in range(1,N): if T[i]<=t+K and len(S[k])<C: S[k].append(T[i]) else: k+=1 S.append([T[i]]) t=T[i] print(len(S))
0
PYTHON3
from sys import stdin input() ans = 0 for line in stdin: if line.count('1') >= 2: ans += 1 print(ans)
7
PYTHON3
#include<iostream> #include<cmath> using namespace std; int N_MAX=101; int main() { int n,i,t,res=10000; int w[N_MAX]; cin >> n; w[0]=0; for(i=0;i<n;i++){ cin >> t; w[i+1]=w[i]+t; } for(i=1;i<n;i++){ t=abs(w[n]-2*w[i]); if(t<res) res=t; } cout << res << endl; return 0; }
0
CPP
n = int(input()) a = list(map(int,input().split())) new = [] for i in range(n): new.append([a[i],i]) new.sort(key = lambda x: x[0], reverse = True) newAns = n*[0] i = 0 s = new[i][0] rating = 1 + i newAns[new[i][1]] = rating for i in range(1, n): if new[i][0] == s: newAns[new[i][1]] = newAns[new[i-1][1]] else: s = new[i][0] newAns[new[i][1]] = 1 + i print(*newAns)
7
PYTHON3
import bisect n, m = map(int, input().split()) l1 = list(map(int, input().split())) l2 = list(map(int, input().split())) l1.sort() r = [] for x in l2: r.append(str(bisect.bisect(l1, x))) print(" ".join(r))
8
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int a, b; cin >> a >> b; int sum = a; int rem = 0; while (a >= b) { sum += a / b; rem = a % b; a /= b; a += rem; } cout << sum << endl; return 0; }
7
CPP
#include <bits/stdc++.h> using namespace std; const int Mod = (int)1e9 + 7; const int MX = 1073741822; const long long MXLL = 4e18; const int Sz = 1110111; inline void Read_rap() { ios_base ::sync_with_stdio(0); cin.tie(0); cout.tie(0); } inline void randomizer3000() { unsigned int seed; asm("rdtsc" : "=A"(seed)); srand(seed); } void files(string problem) { if (fopen((problem + ".in").c_str(), "r")) { freopen((problem + ".in").c_str(), "r", stdin); freopen((problem + ".out").c_str(), "w", stdout); } } void localInput(const char in[] = "s") { if (fopen(in, "r")) { freopen(in, "r", stdin); } else cerr << "Warning: Input file not found" << endl; } int n; const int N = 302; int pref[N][N]; int dp[N][N]; int a[N]; int plen[N], len[N]; int main() { Read_rap(); cin >> n; for (int i = 1; i <= n; i++) { static string s; cin >> s; static map<string, int> id; if (!id.count(s)) id[s] = (int)(id.size()); a[i] = id[s]; len[i] = (int)(s.size()); } for (int i = n; i >= 1; i--) for (int j = n; j >= 1; j--) if (a[i] == a[j]) pref[i][j] = pref[i + 1][j + 1] + 1; for (int i = 1; i <= n; i++) plen[i] = plen[i - 1] + len[i]; for (int i = 1; i <= n; i++) { for (int j = 1; j <= i; j++) { int len = i - j + 1; for (int p = len; p < j; p++) { int q = p - len + 1; if (pref[j][q] >= len) dp[i][j] = max(dp[i][j], dp[p][q] + 1); } } } int ans = 0; for (int i = 1; i <= n; i++) { for (int j = 1; j <= i; j++) { int len = i - j + 1; if (dp[i][j]) { int cost = len - 1 + plen[i] - plen[j - 1] - len; ans = max(ans, cost * (dp[i][j] + 1)); } } } int sum = accumulate(len + 1, len + n + 1, 0) + n - 1; cout << sum - ans; return 0; }
12
CPP
#include <bits/stdc++.h> using namespace std; const int N = 200200; const int M = 1e9 + 7; int n; int a[N]; int num[N], c[N], b[N]; int bp(int a, int b) { int r = 1; while (b > 0) { if (b % 2 == 1) r = 1LL * r * a % M; a = 1LL * a * a % M; b /= 2; } return r; } int main() { scanf("%d", &n); while (n--) { int x; scanf("%d", &x); ++a[x]; } int nums = 0; for (int i = 0; i < N; ++i) if (a[i] > 0) { num[i] = nums; c[nums] = i; ++nums; } for (int i = 0; i < N; ++i) b[i] = i; int r = 1; int k = 1; for (int i = 0; i < N; ++i) { int p = 1, pr = r; for (int j = 0; j < a[i]; ++j) { p = 1LL * p * i % M; r = 1LL * r * pr % M * bp(p, k) % M; } k = 1LL * k * (a[i] + 1) % (M - 1); } printf("%d\n", r); return 0; }
10
CPP
#include <iostream> #include <algorithm> #include <string> #include <sstream> #include <vector> #include <set> #include <cmath> #include <unordered_map> #include <queue> #include <map> #include <functional> #include <stack> #include <cmath> #include <cstring> #include <random> #include <chrono> #include <memory> #include <cassert> #include <numeric> #include <iomanip> #define int long long #define pic pair<int, char> #define x first #define y second #define ll long long #define pii pair<long long, long long> #define endl "\n" #define all(a) (a).begin(), (a).end() #pragma GCC optimize ("O3") #define PI 3.14159265 #define pdd pair<double, double> #define rect pair<pii, pii> using namespace std; const int N = 5e5 + 14; const int inf = (int)1e9; const int mod = 1e9 + 7; const double eps = 1e-6; mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count()); using namespace std; int q; int n; vector<rect> v; int disty[N]; int ysz; int t[N * 4]; int tag[N * 4]; void compress() { vector<int> ycords; for (auto &pp : v) { ycords.push_back(pp.x.y); ycords.push_back(pp.y.y); } sort(all(ycords)); ycords.resize(unique(all(ycords)) - ycords.begin()); ysz = ycords.size(); map<int, int> mp; for (int i = 0; i < ycords.size(); ++i) { mp[ycords[i]] = i; disty[i] = ycords[i] - ycords[0]; } for (auto &pp : v) { pp.x.y = mp[pp.x.y]; pp.y.y = mp[pp.y.y]; } } void add(int tl, int tr, int v, int l, int r, int dlt) { if (tl > r || tr < l) return; if (r < l) return; if (tl >= l && tr <= r) { tag[v] += dlt; if (tag[v]) t[v] = disty[tr + 1] - disty[tl]; else if (tl != tr) t[v] = t[v * 2] + t[v * 2 + 1]; else if (tl == tr) t[v] = 0; return; } int mid = (tl + tr) / 2; add(tl, mid, v * 2, l, r, dlt); add(mid + 1, tr, v * 2 + 1, l, r, dlt); t[v] = (tag[v] ? (disty[tr + 1] - disty[tl]) : (t[v * 2] + t[v * 2 + 1])); } int get() { return tag[1] ? (disty[ysz - 1] - disty[0]) : (t[2] + t[3]); } int solve() { vector<pii> odr; for (int i = 0; i < n; ++i) { odr.emplace_back(i, 0); odr.emplace_back(i, 1); } sort(all(odr), [](pii p1, pii p2) { int x1 = 0; int x2 = 0; if (!p1.y) x1 = v[p1.x].x.x; else x1 = v[p1.x].y.x; if (!p2.y) x2 = v[p2.x].x.x; else x2 = v[p2.x].y.x; if (x1 == x2) return p1.y < p2.y; return x1 < x2; }); int px = -1; ll ans = 0; for (auto &pr : odr) { int curx = 0; int up = v[pr.x].y.y; int down = v[pr.x].x.y; if (!pr.y) curx = v[pr.x].x.x; else curx = v[pr.x].y.x; ans += (ll)get() * (ll)(curx - px); px = curx; if (!pr.y) add(0, ysz - 2, 1, down, up - 1, 1); else add(0, ysz - 2, 1, down, up - 1, -1); } return ans; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout.precision(20); //cin >> q; q = 1; while (q--) { cin >> n; v.resize(n); for (int i = 0; i < n; ++i) cin >> v[i].x.x >> v[i].x.y >> v[i].y.x >> v[i].y.y; fill(t, t + n * 4 + 10, 0); fill(tag, tag + n * 4 + 10, 0); ysz = 0; fill(disty, disty + n + 10, 0); compress(); cout << solve() << endl; } }
0
CPP
s1 = input() s2 = input() ms1 = [0]*26 ms2 = [0]*26 ms3 = [0]*26 ms4 = [0]*26 m = 0 n = 0 for i in range (len(s1)): if ord(s1[i]) in range(ord('A'),ord('Z')+1): ms1[ord(s1[i])-ord('A')] += 1 else: ms2[ord(s1[i])-ord('a')] += 1 for i in range (len(s2)): if ord(s2[i]) in range(ord('A'),ord('Z')+1): ms3[ord(s2[i])-ord('A')] += 1 else: ms4[ord(s2[i])-ord('a')] += 1 for i in range(len(ms1)): if ms3[i] and ms1[i]: mn = min(ms3[i],ms1[i]) m += mn ms3[i] -= mn ms1[i] -= mn if ms2[i] and ms4[i]: mn = min(ms2[i],ms4[i]) m += mn ms2[i] -= mn ms4[i] -= mn for i in range (len(ms1)): if ms3[i] and ms2[i]: mn = min(ms2[i],ms3[i]) n += mn ms3[i] -= mn ms2[i] -= mn if ms1[i] and ms4[i]: mn = min(ms1[i],ms4[i]) n += mn ms1[i] -= mn ms4[i] -= mn print(m, n)
8
PYTHON3
t=int(input()) lst=list(map(int,input().split())) p=0 q=0 for t in range(t): if(p>0): if(lst[t]==-1): p-=1 else: p+=lst[t] else: if(lst[t]==-1): q+=1 else: p+=lst[t] print(q)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { long long n, m, d; cin >> n >> m >> d; set<long long> s; vector<long long> ans(n + 1); unordered_map<long long, long long> umap; for (long long i = 1; i <= n; i++) { long long a; cin >> a; s.insert(a); umap[a] = i; } long long curr = 0; long long day = 1; d++; while (s.size() != 0) { auto itr = s.lower_bound(curr); if (itr != s.end()) { long long val = *itr; s.erase(val); ans[umap[val]] = day; curr = val + d; if (curr > m) curr = 0, day++; } else { curr = 0; day++; auto itr = s.lower_bound(curr); long long val = *itr; s.erase(val); ans[umap[val]] = day; curr = val + d; if (curr > m) curr = 0, day++; } } long long out = 0; for (long long i = 1; i <= n; i++) out = max(out, ans[i]); cout << out << endl; for (long long i = 1; i <= n; i++) cout << ans[i] << " "; return 0; }
9
CPP
#include <bits/stdc++.h> using namespace std; using lint = long long; using pi = pair<int, int>; using frac = pair<lint, lint>; const int MAXN = 100005; int n; pi a[MAXN]; lint sum[MAXN]; bool cmp(frac a, frac b){ return (__int128)a.first * b.second < (__int128)b.first * a.second; } lint gcd(lint x, lint y){ return y ? gcd(y, x%y) : x; } int main(){ scanf("%d",&n); for(int i=0; i<n; i++) scanf("%d %d",&a[i].first,&a[i].second); sort(a, a + n, [&](const pi &p, const pi &q){ return max(p.first, p.second) > max(q.first, q.second); }); frac dap(n, 1); auto upd_val = [&](lint n, lint a, lint b){ // assert(a <= b); a += n * b; dap = min(dap, frac(a, b), cmp); }; lint sumA = 0; for(int i=1; i<=n; i++){ sumA += a[i-1].first; sum[i] = sum[i-1] + max(a[i-1].first, a[i-1].second); } for(int i=0; i<n; i++){ if(sum[i] >= sumA - a[i].second){ auto lb = lower_bound(sum, sum + i + 1, sumA - a[i].second) - sum; lint tmp = sumA - sum[lb]; if(tmp <= 0){ upd_val(lb, 0, 1); } else{ upd_val(lb, tmp, a[i].second); } } else{ lint newval = sumA + max(a[i].first, a[i].second); auto lb = lower_bound(sum + i + 1, sum + n + 1, newval - a[i].second) - sum; lint tmp = newval - sum[lb]; if(tmp <= 0) upd_val(lb - 1, 0, 1); else{ if(tmp <= a[i].second) upd_val(lb - 1, tmp, a[i].second); } } } dap.first = (n * dap.second - dap.first); dap.second *= n; { lint g = gcd(dap.first, dap.second); dap.first /= g; dap.second /= g; } printf("%lld %lld\n", dap.first, dap.second); }
0
CPP
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 5; void pairsort(long long a[], long long b[], long long n) { pair<long long, long long> pairt[n]; for (long long i = 0; i < n; i++) { pairt[i].first = a[i]; pairt[i].second = b[i]; } sort(pairt, pairt + n); for (long long i = 0; i < n; i++) { a[i] = pairt[i].first; b[i] = pairt[i].second; } } long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } long long isPrime(long long n) { if (n < 2) return 0; if (n < 4) return 1; if (n % 2 == 0 or n % 3 == 0) return 0; for (long long i = 5; i * i <= n; i += 6) if (n % i == 0 or n % (i + 2) == 0) return 0; return 1; } long long C(long long n, long long r) { if (r > n - r) r = n - r; long long ans = 1; for (long long i = 1; i <= r; i++) { ans *= n - r + i; ans /= i; } return ans; } long long mod = 1e9 + 7; long long modexpo(long long x, long long p) { long long res = 1; x = x % mod; while (p) { if (p % 2) res = res * x; p >>= 1; x = x * x % mod; res %= mod; } return res; } long long H, n, a[200005], b[200005], m, s, r, ans, ans1, H1; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; cin >> H >> n; for (long long i = 0; i < n; i++) cin >> a[i], s += a[i]; b[0] = a[0]; m = a[0]; for (long long i = 1; i < n; i++) { b[i] = b[i - 1] + a[i]; m = (m < b[i] ? m : b[i]); } H1 = H; for (long long i = 0; i < n && H1 > 0; i++) { ans1++; H1 += a[i]; if (H1 <= 0) { cout << ans1; return 0; } } if (s >= 0) { cout << -1; return 0; } s = -s; r = (0 > (H + m) / s - 1 ? 0 : (H + m) / s - 1); H -= r * s; ans = r * n; for (long long i = 0; i < n && H > 0; i++) { ans++; H += a[i]; if (H <= 0) break; } for (long long i = 0; i < n && H > 0; i++) { ans++; H += a[i]; if (H <= 0) break; } for (long long i = 0; i < n && H > 0; i++) { ans++; H += a[i]; if (H <= 0) break; } cout << ans; return 0; }
11
CPP
#include <bits/stdc++.h> using namespace std; const int N = 1 << 18; struct Tuple { int dp[5][5]; Tuple(char c) : Tuple() { if (c == '2') { dp[0][0] = 1; dp[0][1] = 0; } else if (c == '0') { dp[1][1] = 1; dp[1][2] = 0; } else if (c == '1') { dp[2][2] = 1; dp[2][3] = 0; } else if (c == '6') { dp[3][3] = 1; dp[4][4] = 1; } else if (c == '7') { dp[3][3] = 1; dp[3][4] = 0; } } Tuple() { for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { dp[i][j] = 1e7; } dp[i][i] = 0; } } }; Tuple dat[N * 2]; Tuple operator*(Tuple a, Tuple b) { Tuple ret; for (int i = 0; i < 5; i++) { ret.dp[i][i] = 1e7; } for (int i = 0; i < 5; i++) { for (int j = i; j < 5; j++) { for (int k = j; k < 5; k++) { ret.dp[i][k] = min(ret.dp[i][k], a.dp[i][j] + b.dp[j][k]); } } } return ret; } Tuple query(int l, int r) { Tuple vl, vr; l += N; r += N; for (; l < r; l /= 2, r /= 2) { if (l & 1) vl = vl * dat[l++]; if (r & 1) vr = dat[--r] * vr; } return vl * vr; } int main() { int n, q; cin >> n >> q; string s; cin >> s; for (int i = 0; i < n; i++) { dat[i + N] = Tuple(s[i]); } for (int i = N - 1; i >= 1; i--) { dat[i] = dat[i * 2] * dat[i * 2 + 1]; } for (int i = 0; i < q; i++) { int l, r; scanf("%d %d", &l, &r); Tuple ret = query(l - 1, r); int ans = ret.dp[0][4]; if (ans > n) ans = -1; printf("%d\n", ans); } }
11
CPP
import sys,collections p=[s.split()for s in sys.stdin] p=collections.deque([[s[0],int(s[1])]for s in p]) q=int(p.popleft()[1]) t=0 while len(p)>0: if p[0][1]>q: p[0][1]-=q p+=[p.popleft()] t+=q else: t+=p[0][1] print(p.popleft()[0],t)
0
PYTHON3
a = input() a = str(a) a = a.lower() a = a.replace('a','') a=a.replace('o','') a=a.replace('y','') a=a.replace('e','') a=a.replace('u','') a=a.replace('i','') a=a.replace('b','.b') a=a.replace('c','.c') a=a.replace('d','.d') a=a.replace('f','.f') a=a.replace('g','.g') a=a.replace('h','.h') a=a.replace('j','.j') a=a.replace('k','.k') a=a.replace('l','.l') a=a.replace('m','.m') a=a.replace('n','.n') a=a.replace('p','.p') a=a.replace('q','.q') a=a.replace('r','.r') a=a.replace('s','.s') a=a.replace('t','.t') a=a.replace('v','.v') a=a.replace('w','.w') a=a.replace('x','.x') a=a.replace('z','.z') print(a)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { long long x, n, k, a; cin >> n >> x >> k; vector<long long> all, all1, all2; for (long long i = 0; i < n; i++) { scanf("%I64d", &a); all1.push_back((a + x - 1 - (a + x - 1) % x) / x); all2.push_back((a - (a % x)) / x + 1); all.push_back(a); } sort(all.begin(), all.end()); sort(all1.begin(), all1.end()); sort(all2.begin(), all2.end()); if (k != 0) { long long ans = 0; long long i = 0, j = 0; while (j < n) { while (j < n && all2[j] - all1[i] < k) j++; if (j < n && all2[j] - all1[i] == k) { long long j2 = j; long long i2 = i; while (j2 < n && all2[j2] == all2[j]) j2++; while (i2 < n && all1[i2] == all1[i]) i2++; ans += (i2 - i) * (j2 - j); i = i2; j = j2; } else i++; } cout << ans << endl; } else { long long ans = 0; long long j = 0; long long i = 0; while (i < n) { while (j < n && all[j] == all[i]) j++; if (all[i] % x != 0) ans += (j - i) * (j - i + 1) / 2; i = j; } j = 0; i = 0; while (i < n) { while (j < n && all2[j] == all2[i] && all1[j] == all1[i]) j++; if (all[i] % x != 0) ans += (j - i) * (j - i - 1) / 2; i = j; } cout << ans << endl; } return 0; }
8
CPP
n = str(input()) if int(n) > 0: print(n) else: if n[-1] > n[-2]: print(n[:-1]) else: if n[:-2] == '-' and n[-1] == '0': print(n[-1]) else: print(n[:-2] + n[-1])
7
PYTHON3
a = [int(i) for i in input().split()] m = a[0] s = a[1] h = [0]*m x = 0 for d in range(m): for i in range(1,10): if x<s: h[d] = h[d] + 1 x = x + 1 x = 0 q = [0]*m q[0] = 1 x = 1 for d in range(m-1,-1,-1): for i in range(1,10): if x<s: q[d] = q[d] + 1 x = x + 1 if s>m*9: print('-1 -1') elif m == 1 and s==0: print('0 0') elif s == 0 or m == 0: print('-1 -1') else: num1= ''.join([str(f) for f in h]) num2= ''.join([str(f) for f in q]) print(num2 + ' ' + num1)
9
PYTHON3
a,b=map(int,input().split()) i=() for i in range(a): if(i%2==0): print("#"*b) elif(i%4==1): print("."*(b-1)+"#") elif(i%4==3): print("#"+"."*(b-1))
7
PYTHON3
a,b,c=map(int,input().split()) f=0 if(a==b): f=1 elif(c==0): f=0 elif(((b-a)<0 and c>0) or ((b-a)>0 and c<0)): f=0 elif((b-a)%c==0): f=1 if(f==1): print("YES") else: print("NO")
7
PYTHON3
a = list(map(int, input().split())) p = sum(a) if p % 5 == 0 and p > 0: print(p//5) else: print(-1)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int N, r, v, x, y; long double abss(long double x) { if (x < 0) return -x; return x; } int main() { long double eps = 1e-10; scanf("%d%d%d", &N, &r, &v); for (int i = 1; i <= N; ++i) { scanf("%d%d", &x, &y); long double z = 1.0 * (y - x) / r; long double st = 0.0, dr = z, ret = z; while (dr - st >= eps) { long double mij = (st + dr) / 2; long double a = abss(2 * sin(mij / 2)); if (a >= z - mij) { ret = mij; dr = mij - eps / 10; } else { st = mij + eps / 10; } } double meh = r * ret / v; printf("%.12lf\n", meh); } return 0; }
8
CPP
a = input() dan = 0 f = 0 for i in range(len(a)-1): if(a[i]==a[i+1]): dan+=1 if(dan>=6): print("YES") f = 1 break else: dan = 0 if(f==0): print("NO")
7
PYTHON3
t=int(input()) li=list(map(int,input().split())) if 1 in li: print(-1) else: print(1)
7
PYTHON3
m,mmax=1,1 n=int(input()) a=[int(i) for i in input().split()] for i in range(1,n): if a[i]>=a[i-1]: m+=1 else: m=1 if mmax<m: mmax=m print(mmax)
7
PYTHON3
s = input(); st = set(s) print("Yes" if st == set("WE") or st == set("NS") or st == set("SENW") else "No")
0
PYTHON3
nums = input().split() a = int(nums[0]) b = int(nums[1]) heights = input().split() for i in range(a): heights[i] = int(heights[i]) heights.sort() sum = 0 for i in range(a): for j in range (i+1, a): if ((int(heights[j])-int(heights[i]))<=b) : sum = sum +2 else: break print(sum)
7
PYTHON3
for _ in range(int(input())): n,k=map(int,input().split()) print(9*(n-1) +k)
8
PYTHON3
n = int(input()) k = int(input()) xn = map(int,input().split()) print(sum([min(x,k-x)*2 for x in xn]))
0
PYTHON3
#include <bits/stdc++.h> using namespace std; const long long int mod = 1e9 + 7; long long int t, n, m, a[1000005] = {0}; map<long long int, long long int> mp; long long int binexpo(long long int a, long long int b, long long int m) { a %= m; long long int res = 1; while (b > 0) { if (b & 1) res = (res * a) % m; a = (a * a) % m; b >>= 1; } return res; } int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); long long int i, j, k, x, y; cin >> n >> x; long long int ss = 0; for (i = 1; i <= n; i++) { cin >> a[i]; ss += a[i]; } for (i = 1; i <= n; i++) mp[ss - a[i]]++; while (1) { auto it = mp.begin(); y = it->first; long long int gg = (it->second) % x; if (gg) break; mp[1 + y] += ((it->second) / x); mp[y] -= ((it->second) / x) * x; if (mp[y] == 0) mp.erase(y); } auto it = mp.begin(); y = min(ss, it->first); y = binexpo(x, y, mod); cout << y; return 0; }
9
CPP
#include <iostream> #include <cstdio> #include <vector> #include <algorithm> #include <complex> #include <cstring> #include <cstdlib> #include <string> #include <cmath> #include <cassert> #include <queue> #include <set> #include <map> #include <valarray> #include <bitset> #include <stack> #include <iomanip> #include <fstream> using namespace std; #define REP(i,n) for(int i=0;i<(int)(n);++i) #define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i) #define ALL(c) (c).begin(), (c).end() #define chmax(a,b) (a<b?(a=b,1):0) #define chmin(a,b) (a>b?(a=b,1):0) #define valid(y,x,h,w) (0<=y&&y<h&&0<=x&&x<w) const int INF = 1<<29; const double EPS = 1e-8; const double PI = acos(-1); typedef long long ll; typedef pair<int,int> pii; typedef complex<double> P; P pIN() { double x,y; cin >> x >> y; return P(x,y); } namespace std { bool operator < (const P& a, const P& b) { // if (abs(a-b)<EPS) return 0; return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b); } bool operator==(const P &a, const P &b) { return abs(a-b)<EPS; } } double cross(const P& a, const P& b) { return imag(conj(a)*b); } double dot(const P& a, const P& b) { return real(conj(a)*b); } int ccw(P a, P b, P c) { b -= a; c -= a; if (cross(b, c) > EPS) return +1; // counter clockwise if (cross(b, c) < -EPS) return -1; // clockwise if (dot(b, c) < -EPS) return +2; // c--a--b on line if (EPS < norm(b) && norm(b) < norm(c)-EPS) return -2; // a--b--c on line return 0; } struct L : public vector<P> { L(const P &a, const P &b) { push_back(a); push_back(b); } L() { resize(2); } }; ostream &operator<<(ostream &os, const L &a) { os << a[0] << " -> " << a[1]; return os; } typedef vector<P> G; #define curr(g, i) g[i] #define next(g, i) g[(i+1)%g.size()] #define prev(g, i) g[(i+g.size()-1)%g.size()] L line(const G &g, int i) { return L(g[i],g[(i+1)%g.size()]); } struct C { P p; double r; C(const P &p, double r) : p(p), r(r) { } }; bool contain(const C &c1, const C &c2) { double d = abs(c1.p - c2.p); return d < c1.r - c2.r + EPS; } vector<L> tangentCP(const C &c, const P &p) { vector<L> ret; P vect = c.p - p; double d = abs(vect); double l = sqrt(d*d-c.r*c.r); if (::isnan(l)) { return ret; } P v1 = vect * P(l / d, c.r / d); P v2 = vect * P(l / d, -c.r / d); ret.push_back(L(p, p+v1)); if (l > EPS) ret.push_back(L(p, p+v2)); return ret; } vector<L> tangentCC(const C &c1, const C &c2) { vector<L> ret; if (abs(c1.p - c2.p) - (c1.r + c2.r) > -EPS) { P center = (c1.p * c2.r + c2.p * c1.r) / (c1.r + c2.r); ret = tangentCP(c1, center); } if (fabs(c1.r - c2.r) > EPS) { P out = (-c1.p * c2.r + c2.p * c1.r) / (c1.r - c2.r); vector<L> nret = tangentCP(c1, out); ret.insert(ret.end(), nret.begin(), nret.end()); } else { P vect = c2.p - c1.p; vect /= abs(vect); P q1 = c1.p + vect * P(0, 1) * c1.r; P q2 = c1.p + vect * P(0, -1) * c1.r; ret.push_back(L(q1, q1 + vect)); ret.push_back(L(q2, q2 + vect)); } return ret; } P projection(const L &l, const P &p) { double t = dot(p-l[0], l[0]-l[1]) / norm(l[0]-l[1]); return l[0] + t*(l[0]-l[1]); } P reflection(const L &l, const P &p) { return p + P(2,0) * (projection(l, p) - p); } vector<P> crosspointLC(const L &l, const C &c) { vector<P> ret; P center = projection(l, c.p); double d = abs(center - c.p); double t = sqrt(c.r * c.r - d * d); if (::isnan(t)) { return ret; } P vect = (l[1] - l[0]); vect /= abs(vect); ret.push_back(center - vect * t); if (t > EPS) { ret.push_back(center + vect * t); } return ret; } bool intersectSP(const L &s, const P &p) { return abs(s[0]-p)+abs(s[1]-p)-abs(s[1]-s[0]) < EPS; // triangle inequality } vector<P> crosspointSC(const L &s, const C &c) { vector<P> ret; vector<P> nret = crosspointLC(s, c); FOR(it, nret) if (intersectSP(s, *it)) ret.push_back(*it); return ret; } G g; double l,r; int N; struct Res { P ct; L s; double ang; Res(const P &ct, const L &s, double ang) : ct(ct),s(s),ang(ang) {} Res() {} }; bool win(const Res &a, const Res &b, const P &ct) { if (abs(a.ang-b.ang)>EPS) return a.ang > b.ang; return abs(a.ct-ct) < abs(b.ct-ct); } bool sameang(const P &a, const P &b) { return abs(cross(a,b))<EPS && dot(a,b)>0; } double angle(const P &a, const P &b) { double ret = arg(b)-arg(a); return (ret>=0) ? ret : ret + 2*PI; } // γƒ†γ€γƒ„Ξ΄ε‡–γ€γƒ„γ€γƒƒγƒ†γ€γƒ„Ξ΄ζš—γ€γƒ„Ξ΄γ‚©aテ」ツ?γ‚£γƒ†γ€γƒ„Ξ΄ε‡–γ€γƒ„γ€γƒƒγƒ†γ€γƒ„Ξ΄ζš—γ€γƒ„Ξ΄γ‚©bテ」ツ?ョテγ‚₯ツ鳴禿」ツ?ョティツゑツζ΄₯・ツコツヲ double angle2(const P &a, const P &b) { return min(angle(a,b), angle(b,a)); } double angle2_2(const P &a, const P &b) { double ret = abs(arg(b)-arg(a)); return ret>PI ? 2*PI-ret : ret; } // テヲツ卍γ₯γ‚£γƒ„γ‚£γƒ„ζš—γƒ»γƒ„ε΄’ζ¦²γ€γƒ„γ€η”˜γƒ»γƒ„?エテ」ツ?ッテ・ツ青ォテ」ツ?ソテ」ツ??γƒ»γƒ„ε‚΅η”˜γƒ²γƒ„εγ₯γ‚£γƒ„γ‚£γƒ„ζš—γƒ»γƒ„ε΄’ζ¦²γ€γƒ„γ€η”˜γƒ»γƒ„?エテ」ツ?ッテ・ツ青ォテ」ツ?セテ」ツ?ェテ」ツ?? int quadrant(const P &a) { if (a.real() > 0 && a.imag() >= 0) return 0; if (a.real() <= 0 && a.imag() > 0) return 1; if (a.real() < 0 && a.imag() <= 0) return 2; return 3; } // テ」ツδγƒ₯γƒ†γ€γƒ„Ξ΄ι™γ€γƒ„γ€γ‚±γƒ†γ€γƒ„Ξ΄ζš—γ€γƒ„?ェティツゑツζ΄₯・ツコツヲテヲツッツ氾ィツシツ? bool cmpAngle(const P &a, const P&b) { int q1 = quadrant(a); int q2 = quadrant(b); if (q1 != q2) return q1 < q2; return cross(a,b)>0; } // γƒ†γ€γƒ„Ξ΄ε‡–γ€γƒ„γ€γƒƒγƒ†γ€γƒ„Ξ΄ζš—γ€γƒ„Ξ΄γ‚©γƒ†γ€γƒ„?γƒ§γƒ†γƒ»γƒ„ε΄’ζ¦²γ‚£γƒ„γ‚΅γƒ„γ€Œ P rotate(P p, double ang) { return p * P(cos(ang), sin(ang)); } // γƒ†γƒ»γƒ„η― ζ·Œγ‚‘γƒ„γ€γ‚±γƒ†γƒ»γƒ„ε •γ‚£γƒ†γ€γƒ„γ€η”˜γ€γƒ„?ョテゑツ崒エテゑツキツ堙」ツ?γƒ§γƒ†γƒ»γƒ„ε΄’ζ¦²γ‚£γƒ„γ‚΅γƒ„γ€Œ L rotate(L l, double ang) { return L(rotate(l[0], ang),rotate(l[1], ang)); } double signedLength(const P &p1, const P &p2, const P &p) { P pc = projection(L(p1,p2),p); double res = abs(pc-p1); if (dot(pc-p1,p2-p1)>0) return res; else return -res; } Res find_next(const P &ct, const L& s) { Res res; res.ang = INF; // vertex REP(i,N) { if (ct==g[i]) continue; REP(j,2) { if (s[j]==ct) continue; if (abs(g[i]-ct)<abs(s[j]-ct)) { if (sameang(g[i]-ct,s[j]-ct)) { if (ccw(ct,s[j],next(g,i)) == -1 || ccw(ct,s[j],prev(g,i)) == -1) { // stuck Res t(g[i], s, 0); if (win(res,t,ct)) res = t; } } else { double ang = angle(g[i]-ct,s[j]-ct); Res t(g[i],L(ct+rotate(s[0]-ct,-ang),ct+rotate(s[1]-ct,-ang)),ang); if (win(res,t,ct)) res = t; } } } } // edge REP(i,N) { REP(j,2) { if (s[j]==ct) continue; vector<P> ps = crosspointSC(line(g,i),C(ct,abs(s[j]-ct))); FOR(it, ps) { if (sameang(*it-ct,s[j]-ct)) { P a = g[i]; P b = next(g,i); P c = prev(g,i); if (abs(signedLength(ct,s[j],a) - signedLength(ct,s[j],b)) < EPS) continue; if (signedLength(ct,s[j],a) > signedLength(ct,s[j],b)) { swap(a,b); c = g[(i+2)%g.size()]; } if (ccw(ct,*it,a) == 1) continue; if (ccw(ct,*it,a) != -1) { continue; if (ccw(ct,*it,c) == 1) continue; } // cout << ct << " " << s[j] << " " << a << " " << b << " :" << signedLength(ct,s[j],a) << " " << signedLength(ct,s[j],b) << endl; // cout << *it << endl; // cout << ccw(ct,*it,a) << endl; // cout << *it << endl; // stuck Res t(*it, s, 0); if (win(res,t,ct)) res = t; } else { // cout << *it << endl; double ang = angle(*it-ct,s[j]-ct); Res t(*it,L(ct+rotate(s[0]-ct,-ang),ct+rotate(s[1]-ct,-ang)),ang); // cout << res.ang << " " << ang << endl; if (win(res,t,ct)) res = t; } } } } return res; } FILE *fp; double scale = 10; P diff(300, 300); double WH = 500; void outputLine(const L &l) { if (!fp) return; P a = l[0]; P b = l[1]; a = a*P(scale,0)+diff; b = b*P(scale,0)+diff; fprintf(fp,"line(%f,%f,%f,%f);\n",a.real(),WH-a.imag(),b.real(),WH-b.imag()); } void outputCircle(C c) { if (!fp) return; c.p = c.p*P(scale,0) + diff; c.r *= scale; fprintf(fp, "circle(%f,%f,%f);\n", c.p.real(), WH-c.p.imag(), c.r); } int main() { fp = fopen("data.js","w"); while(cin>>l>>r>>N, l||r||N) { g.clear(); double tang = r*2*PI; REP(i,N) g.push_back(pIN()); REP(i,N) outputLine(line(g,i)); L s(P(0,0),P(0,l)); P ct(0,0); double ang = 0; outputLine(s); int counter = 0; REP(i,1000) { Res ret = find_next(ct,s); // cout << ang << " " << ret.ang << " " << tang << endl; if (ang+ret.ang>=tang) { double ag = tang-ang; s[0] = ct+rotate(s[0]-ct,-ag); s[1] = ct+rotate(s[1]-ct,-ag); outputLine(s); break; } if (ang == 0) { if (counter++ == 10) break; } else counter = 0; // cout << ang << " " << s << ":" << ret.ang << " " << ret.s<< " " << ret.ct << endl; outputLine(ret.s); outputCircle(C(ct,l)); ang += ret.ang; s = ret.s; ct = ret.ct; } printf("%.10f %.10f\n", s[0].real(), s[0].imag()); } }
0
CPP
n=int(input()) c=0 s=sorted(list(map(int,input().split()))) for j in range(n) : l=s s=[] x=len(l) for i in range(x): if(l[i]%l[0]!=0): s.append(l[i]) c+=1 if(len(s)==0): break print(c)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; void solve() { string s, t; cin >> s >> t; long long p = 0, n = 0; long long sl[26] = {0}, su[26] = {0}, tl[26] = {0}, tu[26] = {0}; for (long long i = 0; i < s.length(); i++) { if (islower(s[i])) sl[s[i] - 'a']++; else su[s[i] - 'A']++; } for (long long i = 0; i < t.length(); i++) { if (islower(t[i])) tl[t[i] - 'a']++; else tu[t[i] - 'A']++; } for (long long i = 0; i < 26; i++) { long long x = min(sl[i], tl[i]); p += x; sl[i] -= x; tl[i] -= x; x = min(su[i], tu[i]); p += x; su[i] -= x; tu[i] -= x; } for (long long i = 0; i < 26; i++) { long long x = min(sl[i], tu[i]); n += x; sl[i] -= x; tu[i] -= x; x = min(su[i], tl[i]); n += x; su[i] -= x; tl[i] -= x; } cout << p << " " << n; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); long long t = 1; while (t--) solve(); }
8
CPP
#include <bits/stdc++.h> using namespace std; int n, m, cn[15]; pair<int, int> a[15], b[15], c1[15], c2[15]; set<int> st; int main() { cin >> n >> m; for (int i = 0; i < n; i++) cin >> a[i].first >> a[i].second; for (int i = 0; i < m; i++) cin >> b[i].first >> b[i].second; bool cand = true; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { st.clear(); st.insert(a[i].first); st.insert(a[i].second); st.insert(b[j].first); st.insert(b[j].second); if (st.size() != 3) { continue; } else { if (a[i].first == b[j].first) { cn[a[i].first]++; c1[i].first++; c2[j].first++; } else if (a[i].first == b[j].second) { cn[a[i].first]++; c1[i].first++; c2[j].second++; } else if (a[i].second == b[j].first) { cn[a[i].second]++; c1[i].second++; c2[j].first++; } else { cn[a[i].second]++; c1[i].second++; c2[j].second++; } if (c1[i].first >= 1 && c1[i].second >= 1 || c2[j].first >= 1 && c2[j].second >= 1) { cout << -1; return 0; } } } } int nb = 0, p = 0; for (int i = 0; i < 10; i++) if (cn[i]) nb++, p = i; if (nb == 1) { cout << p << endl; return 0; } else { cout << 0; return 0; } }
10
CPP
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 7; const int mod = 998244353; int a[N], b[N]; int main() { int t; cin >> t; while (t--) { int n, m, ans = 0; cin >> n >> m; for (int i = 1, x; i <= n; i++) { cin >> x; ans += x; } if (ans == m) printf("YES\n"); else printf("NO\n"); } return 0; }
7
CPP
#include <bits/stdc++.h> using namespace std; #define int long long typedef pair <int, int> pii; const int N = 1e5 + 10; int n, cnt[N], par[N], sum[N], mark[N]; pii ar[N]; map <int, int> mp; vector <int> ch[N]; void dfs(int v) { mark[v] = 1; for (int i : ch[v]) { dfs(i); sum[v] += sum[i] + cnt[i]; } } int32_t main() { ios::sync_with_stdio(0); cin.tie(0); fill(cnt, cnt + N, 1); cin >> n; for (int i = 0; i < n; i++) { cin >> ar[i].first; ar[i].second = i; mp[ar[i].first] = i; } sort(ar, ar + n); for (int i = n - 1; i > 0; i--) { int v = ar[i].second; int nd = ar[i].first - n + 2 * cnt[v]; if (mp.find(nd) == mp.end() || 2 * cnt[v] > n) return cout << -1, 0; int p = mp[nd]; ch[p].push_back(v); par[v] = p; cnt[p] += cnt[v]; } dfs(ar[0].second); if (sum[ar[0].second] != ar[0].first) return cout << -1, 0; for (int i = 0; i < n; i++) if (!mark[i]) return cout << -1, 0; for (int i = 0; i < n; i++) if (i != ar[0].second) cout << i + 1 << " " << par[i] + 1 << '\n'; }
0
CPP
n = int(input()) for i in range(n): temp = input() print(temp[0] + temp[1:len(temp) - 1:2] + temp[len(temp)-1])
7
PYTHON3
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); ; int n; cin >> n; string s; cin >> s; int d = 0, u = 0, l = 0, r = 0; for (int i = 0; i < (n); i++) { if (s[i] == 'L') l++; else if (s[i] == 'R') r++; else if (s[i] == 'D') d++; else u++; } long long int ma = 0; ma = 2 * min(u, d) + 2 * min(l, r); cout << ma; return 0; }
8
CPP
//37 #include<iostream> #include<string> #include<algorithm> #include<cctype> using namespace std; int main(){ int n; cin>>n; while(n--){ string r,m; cin>>r>>m; for(int i=r.size()-1;i>=0;i--){ switch(r[i]){ case 'J': if(m.size()>1){ rotate(m.begin(),m.end()-1,m.end()); } break; case 'C': if(m.size()>1){ rotate(m.begin(),m.begin()+1,m.end()); } break; case 'E': { string n; n=m.substr((m.size()+1)/2); if(m.size()%2){ n+=m[m.size()/2]; } n+=m.substr(0,m.size()/2); m=n; } break; case 'A': reverse(m.begin(),m.end()); break; case 'P': case 'M': for(int j=0;j<m.size();j++){ if(isdigit(m[j])){ m[j]=(m[j]-'0'+(r[i]=='M')-(r[i]=='P')+10)%10+'0'; } } break; } } cout<<m<<endl; } return 0; }
0
CPP
n = int(input()) ans = 1 cur = -1 row = "" for _ in range(n): row += input() for x in range(len(row)-1): if row[x] == row[x+1]: ans += 1 print(ans)
7
PYTHON3
from math import * l=[int(x) for x in input().split()] r,x,y,x1,y1=l[0],l[1],l[2],l[3],l[4] z=sqrt(((x-x1)**2)+((y-y1)**2)) a=2*r if z%a==0: print(int(z//a)) else: print(1+int(z//a))
8
PYTHON3