solution
stringlengths
10
159k
difficulty
int64
0
3.5k
language
stringclasses
2 values
t = int(input().strip()) for i in range(t): _ = input().strip().split(' ') n, k = int(_[0]), int(_[1]) ans = 0 while n != 0: ans += n%k + 1 n = n//k print(ans-1)
900
PYTHON3
from bisect import * s, n = [0], input() for i in map(int, input().split()): if i > s[-1]: s.append(i) else: s[bisect_right(s, i)] = i print(len(s) - 1)
1,500
PYTHON3
lr=input() s=input() l1=['q','w','e','r','t','y','u','i','o','p'] l2=['a','s','d','f','g','h','j','k','l',';'] l3=list("zxcvbnm,./") #print(l1) #print(l2) #print(l3) if lr=='R': for i in list(s): if i in l1: print(l1[(l1.index(i))-1],end="") elif i in l2: print(l2[(l2.index(i))-1],end="") else: print(l3[(l3.index(i))-1],end="") else: for i in list(s): if i in l1: print(l1[(l1.index(i))+1],end="") elif i in l2: print(l2[(l2.index(i))+1],end="") else: print(l3[(l3.index(i))+1],end="")
900
PYTHON3
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; int n, m, x, y, vx, vy, revx, revy; int Exgcd(int a, int b, long long &x, long long &y) { if (b == 0) { x = 1; y = 0; return a; } long long g = Exgcd(b, a % b, y, x); y -= (a / b) * x; return g; } int main() { scanf("%d%d%d%d%d%d", &n, &m, &x, &y, &vx, &vy); if (vx == 0) { if (x == 0 || x == n) { if (vy == 1) printf("%d %d\n", x, m); else printf("%d %d\n", x, 0); } else printf("-1\n"); return 0; } if (vy == 0) { if (y == 0 || y == m) { if (vx == 1) printf("%d %d\n", n, y); else printf("%d %d\n", 0, y); } else printf("-1\n"); return 0; } if (vx == -1) { revx = 1; x = n - x; } if (vy == -1) { revy = 1; y = m - y; } long long a, b, g; g = Exgcd(n, m, a, b); if ((x - y) % g != 0) { printf("-1\n"); return 0; } long long t = (x - y) / g; a *= t; b *= t; int mm = m / g; long long minA = (a % mm + mm + mm - 1) % mm + 1; long long minB = -((x - y) - minA * n) / m; int ansX = n, ansY = m; if (minA % 2 == 0) ansX = n - ansX; if (minB % 2 == 0) ansY = m - ansY; if (revx) ansX = n - ansX; if (revy) ansY = m - ansY; printf("%d %d\n", ansX, ansY); return 0; }
2,600
CPP
# python 3 n_val, k_val = list(map(int, input().split())) joy_list = list() for idx in range(n_val): f_val, t_val = list(map(int, input().split())) if t_val > k_val: joy = f_val - (t_val - k_val) else: joy = f_val joy_list.append(joy) print(max(joy_list))
900
PYTHON3
import sys import string import math import bisect as bi from collections import defaultdict as dd input=sys.stdin.readline def cin(): return map(int,sin().split()) def ain(): return list(map(int,sin().split())) def sin(): return input() def inin(): return int(input()) def pref(a,n): pre=[0]*n pre[0]=a[0] for i in range(1,n): pre[i]=a[i]+pre[i-1] return pre ##dp1=[1]*100 ##dp1[0]=2 ##for i in range(1,100): ## dp1[i]=dp1[i-1]*2 for i in range(inin()): n=inin() a=ain() b=ain() x=sorted(a) one=b.count(1) zer=n-one if((one==0 or zer==0 )and a!=x): print("No") else: print('Yes') ## d=sorted(d.items(),key=lambda a:a[1],reverse=True) ## print(d)
1,300
PYTHON3
def abbr(x): if len(x)>10: x = x[0] + str(len(x) - 2) + x[len(x)-1] return x n = int(input()) for i in range(n): s = input() print(abbr(s))
800
PYTHON3
n1 = input() # "1101" n2 = input() # "1111" answer = "" for i in range(len(n1)): if n1[i] == n2[i]: answer = answer + "0" else: answer = answer + "1" print(answer)
800
PYTHON3
for nt in range(int(input())): n = int(input()) a = [0] for i in range(1,int(n**0.5)+1): a.append(n//i) a.append(i) a = sorted(list(set(a))) print (len(a)) print (*a)
1,400
PYTHON3
#include <bits/stdc++.h> using namespace std; char a[5000][5000]; long long int dp[5000][5000]; int main() { int n, m; cin >> n >> m; for (int i = 0; i < n; i++) { scanf("%s", a[i]); } for (int i = n - 1; i >= 0; i--) { for (int j = m - 1; j >= 0; j--) { dp[i][j] = dp[i + 1][j] + dp[i][j + 1] - dp[i + 1][j + 1] + (a[i][j] - '0'); } } long long int cnt = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (a[i][j] == '1') cnt++; } } long long int fians = INT_MAX; ; for (int k = 2; k <= max(n, m); k++) { if (k * k >= (n * m)) { fians = min(fians, min(cnt, k * k - cnt)); continue; } long long int ans = 0; for (int i = 0; i < n + n % k; i = i + k) { for (int j = 0; j < m + m % k; j = j + k) { ans += min( k * k - (dp[i][j] - dp[i + k][j] - dp[i][j + k] + dp[i + k][j + k]), dp[i][j] - dp[i + k][j] - dp[i][j + k] + dp[i + k][j + k]); } } fians = min(fians, ans); } cout << fians << "\n"; }
1,400
CPP
#include <bits/stdc++.h> using namespace std; int main() { srand(time(NULL)); puts("Black"); return 0; }
1,800
CPP
#include <bits/stdc++.h> using namespace std; template <class c> struct rge { c b, e; }; template <class c> rge<c> range(c i, c j) { return rge<c>{i, j}; } template <class c> auto dud(c *x) -> decltype(cerr << *x, 0); template <class c> char dud(...); struct debug { template <class c> debug &operator<<(const c &) { return *this; } }; template <typename T> T set_bit(T N, T pos) { return N = N | (1 << pos); } template <typename T> T reset_bit(T N, T pos) { return N = N & ~(1 << pos); } template <typename T> bool check_bit(T N, T pos) { return (bool)(N & (1 << pos)); } template <typename T> void bin_print(T N) { bitset<25> bit(N); cerr << bit.to_string() << "\n"; } template <typename T> void max_self(T &a, T b) { a = max(a, b); } template <typename T> void min_self(T &a, T b) { a = min(a, b); } template <typename T> void add_self(T &a, T b) { a += b; } template <typename T> void ara_read(T &v, long long int n) { long long int temp; for (long long int i = 0; i < n; i++) { scanf("%lld", &temp); v.emplace_back(temp); } } template <typename T> void ara_print(T &v) { for (long long int x : v) printf("%lld ", x); puts(""); } const long long int INF = 2e18 + 99; ; int main() { ios_base::sync_with_stdio(0); ; int n; cin >> n; map<int, int> m; for (int i = 0; i < n; i++) { int temp; cin >> temp; if (temp) m[temp]++; } int ans = (int)m.size(); cout << ans << '\n'; return 0; }
800
CPP
#include <bits/stdc++.h> using namespace std; template <class T> void printArray(vector<T> arr) { for (T a : arr) cout << a << " "; cout << '\n'; } void printVerdict(bool verdict) { cout << (verdict ? "YES" : "NO") << '\n'; } int main() { std::ios_base::sync_with_stdio(false); cin.tie(0); map<string, int> position; int _ = 1; for (string s : {"C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "B", "H"}) { position[s] = _; _++; } vector<string> triad(3); bool major = false, minor = false; for (int i = 0; i < 3; i++) cin >> triad[i]; sort(triad.begin(), triad.end()); int semitone1 = position[triad[1]] - position[triad[0]], semitone2 = position[triad[2]] - position[triad[1]]; if (semitone1 < 0) semitone1 += 12; if (semitone2 < 0) semitone2 += 12; if (semitone1 == 4 && semitone2 == 3) major = true; else if (semitone1 == 3 && semitone2 == 4) minor = true; while (!major && !minor && next_permutation(triad.begin(), triad.begin() + 3)) { semitone1 = position[triad[1]] - position[triad[0]], semitone2 = position[triad[2]] - position[triad[1]]; if (semitone1 < 0) semitone1 += 12; if (semitone2 < 0) semitone2 += 12; if (semitone1 == 4 && semitone2 == 3) major = true; else if (semitone1 == 3 && semitone2 == 4) minor = true; } if (major) cout << "major" << '\n'; else if (minor) cout << "minor" << '\n'; else cout << "strange" << '\n'; }
1,200
CPP
n, m, k = list(map(int, input().split())) if n <= m and n <= k: print('Yes') else: print('No')
800
PYTHON3
# 279B >> accepted # chu giai giai thuat: 2 vong lap i,j chay song song, nen tinh ra chi co 1 vong lap, # cho i chay tu 0>>n, cong dan time, den khi (time+a[i])>t thi dung i lai, update max_book. # bien j chay theo bien i, khi (time+a[i])>t thi j+=1 de tim bo sach phu hop tiep theo. def main(): n, t = map(int, input().split()) a = list(map(int, input().split())) max_book = 0 j, i = 0, 0 time = 0 # tong thoi gian doc sach while (i < n): temp = time + a[i] if temp <= t: time += a[i] i += 1 # print ('time=',time) # print ('i=',i) else: max_book = max(max_book, i - j) j += 1 time -= a[j - 1] if j >= n: break # print ('max_book=',max_book) # print ('time1=',time) # print ('j=',j) max_book = max(max_book, i - j) print(max_book) if __name__ == '__main__': main()
1,400
PYTHON3
#include <bits/stdc++.h> using namespace std; int nf, ne, nz, rf, re, rz, df, de; double f, e, z, ans; int a[100], N; double d[40][30][30]; void dp() { memset(d, 0, sizeof(d)); int i, j, k; double fire, elec; for (j = 0; j <= nf; j++) { for (k = 0; k <= ne; k++) { double &x = d[0][j][k]; if (a[0] < 2) { fire = f * df; elec = e * de; for (int ii = 0; ii <= N; ii++) { double rng = (min(double(ii + z * 1.0 / 2), double(f * 1.0 / 2)) - max(double(ii - z * 1.0 / 2), double(-f * 1.0 / 2))); if (rng < 0) { rng = 0; } fire += double(a[ii] * df * rng); rng = (min(double(ii + z * 1.0 / 2), double(e * 1.0 / 2)) - max(double(ii - z * 1.0 / 2), double(-e * 1.0 / 2))); if (rng < 0) { rng = 0; } elec += double(a[ii] * de * rng); } if (j > 0) { x = max(x, fire); } if (k > 0) { x = max(x, elec); } if (a[0] == 0) { if (j > 1) { x = max(x, 2 * fire); } if (j > 0 && k > 0) { x = max(x, fire + elec); } if (k > 1) { x = max(x, 2 * elec); } } } } } for (i = 1; i <= N; i++) { for (j = 0; j <= nf; j++) { for (k = 0; k <= ne; k++) { double &x = d[i][j][k]; x = d[i - 1][j][k]; if (a[i] < 2) { fire = f * df; elec = e * de; for (int ii = 0; ii <= N; ii++) { double rng = (min(double(ii + z * 1.0 / 2), double(i + f * 1.0 / 2)) - max(double(ii - z * 1.0 / 2), double(i - f * 1.0 / 2))); if (rng < 0) { rng = 0; } fire += double(a[ii] * df * rng); rng = (min(double(ii + z * 1.0 / 2), double(i + e * 1.0 / 2)) - max(double(ii - z * 1.0 / 2), double(i - e * 1.0 / 2))); if (rng < 0) { rng = 0; } elec += double(a[ii] * de * rng); } if (j > 0) { x = max(x, d[i - 1][j - 1][k] + fire); } if (k > 0) { x = max(x, (d[i - 1][j][k - 1] + elec)); } if (a[i] == 0) { if (j > 1) { x = max(x, d[i - 1][j - 2][k] + 2 * fire); } if (j > 0 && k > 0) { x = max(x, d[i - 1][j - 1][k - 1] + fire + elec); } if (k > 1) { x = max(x, d[i - 1][j][k - 2] + 2 * elec); } } } } } } ans = max(ans, d[N][nf][ne]); } int dfs(int pos, int x) { if (pos == N) { if (x == 0) dp(); return 0; } if (x < 0) { return 0; } a[pos] = 0; dfs(pos + 1, x); a[pos] = 1; dfs(pos + 1, x - 1); a[pos] = 2; dfs(pos + 1, x - 2); return 0; } int main() { int i, j, k, n, m; scanf("%d%d%d", &nf, &ne, &nz); scanf("%d%d%d", &rf, &re, &rz); scanf("%d%d", &df, &de); N = (nf + ne + nz + 1) / 2; memset(a, 0, sizeof(a)); ans = 0; f = 2 * sqrt(rf * rf - 1); e = 2 * sqrt(re * re - 1); z = 2 * sqrt(rz * rz - 1); dfs(0, nz); printf("%lf", ans); return 0; }
2,600
CPP
N = input() team = False counter = 0 for i in N: if i == '0' and team == False: counter += 1 elif i == '0' and team == True: counter = 1 team = False elif i == '1' and team == True: counter += 1 elif i == '1' and team == False: counter = 1 team = True if counter >= 7: print('YES') break else: print('NO')
900
PYTHON3
for _ in range(int(input())): n=int(input()) c=0 l=[] while n>0: if n%10!=0: l.append((n%10)*(10**c)) c+=1 n=n//10 print(len(l)) print(*l)
800
PYTHON3
#include <bits/stdc++.h> using namespace std; template <class T> inline T GCD(T a, T b) { return b ? GCD(b, a % b) : a; } template <class T> inline T LCM(T a, T b) { if (a < 0) return LCM(-a, b); if (b < 0) return LCM(a, -b); return a * (b / GCD(a, b)); } template <class T> inline T POW1(T a, T b, T m) { long long x = 1, y = a; while (b > 0) { if (b % 2 == 1) { x = (x * y); if (x > m) x %= m; } y = (y * y); if (y > m) y %= m; b /= 2; } return x; } template <class T> inline T INV(T n, T m) { return POW1(n, m - 2, m); } template <class T> inline T SUB(T a, T b, T m) { return (a % m - b % m + m) % m; } template <class T> inline T ADD(T a, T b, T m) { return (a % m + b % m) % m; } template <class T> inline T MUL(T a, T b, T m) { return (a % m * b % m) % m; } template <class T> inline T DIV(T a, T b, T m) { return (a % m * (INV(b, m)) % m) % m; } int main() { long long int w, m, k; cin >> w >> m >> k; long long int tm = m; long long int d1 = 0; while (tm != 0) { tm /= 10; d1++; } long long int sum = 0, prev = 0; long long int ans = 0; long long int nxt = 1, temp = d1; for (long long int i = 0; i < d1; i++) { nxt *= 10; } long long int num = m, prev_n; while (sum <= w) { prev = sum; prev_n = nxt - num; ans += prev_n; if ((log(prev_n) + log(k) + log(d1)) / log(10) > 16) { d1++; break; } sum += prev_n * d1 * k; d1++; num = nxt; nxt *= 10; } d1--; ans -= prev_n; ans += (w - prev) / (d1 * k); cout << ans << endl; return 0; }
1,600
CPP
#include <bits/stdc++.h> using namespace std; int n; vector<int> v; long long int dp[5012]; long long int ppow(long long int i, long long int j) { long long int res = 1; while (j) { if (j & 1LL) { res *= i; res %= 998244353; } i *= i; if (i >= 998244353) i %= 998244353; j >>= 1LL; } return res; } vector<int> C; long long int A[5012]; int main() { for (int i = 1; i < 5012; i++) { A[i] = ppow(i, 998244353 - 2); } cin >> n; for (int i = 0; i < n; i++) { int a; scanf("%d", &a); v.push_back(a); } sort(v.begin(), v.end()); reverse(v.begin(), v.end()); int las = -1; int cont = 0; for (int i = 0; i < n; i++) { if (las != v[i]) { las = v[i]; cont = 0; } cont++; C.push_back(cont); } for (int j = 0; j < n; j++) { if (j == n - 1 || (j + 1 < n && v[j] != v[j + 1])) { dp[j] = C[j]; dp[j] *= ppow(n, 998244353 - 2); dp[j] %= 998244353; } } long long int win = 0; for (int i = 2; i <= n; i++) { long long int sm = 0; for (int k = v.size() - 1; k >= 0; k--) { if (k && v[k] == v[k - 1]) { long long int U = dp[k] * C[k - 1]; U %= 998244353; U *= A[n - (i - 1)]; U %= 998244353; win += U; win %= 998244353; } long long int fa = sm; sm += dp[k]; dp[k] = 0; sm %= 998244353; if (k == v.size() - 1 || v[k] != v[k + 1]) { if (C[k] <= n - (i - 1)) { dp[k] = fa * C[k]; dp[k] %= 998244353; dp[k] *= A[n - (i - 1)]; dp[k] %= 998244353; } } } } printf("%lld\n", win); return 0; }
2,300
CPP
for _t in range(int(input())): n, r = list(map(int, input().split())) if n > r: v = r * (r+1) v = v//2 print(v) else: v = (n * (n+1))//2 print(v-n+1)
1,200
PYTHON3
def prime(x): for i in range(2,x): if x%i != 0: #It will give us all the prime numbers a = True else: a = False break return a n = int(input()) for i in range(n): a = 4+i b = n-a if (prime(a) == False) and (prime(b) == False): print(a,b) break
800
PYTHON3
#include <bits/stdc++.h> using namespace std; inline int getint() { int c, l = 0, x; for (; !isdigit(c = getchar()); l = c) if (c == EOF) return 1 << 31; for (x = c - '0'; isdigit(c = getchar()); x = x * 10 + c - '0') if (c == EOF) break; return l == '-' ? -x : x; } const int N = 1200; char B[N][N], A[N]; int ll, T, dp[2][N], sa[N], n, sa2[N], stl, f[12], g[12], c[32], len[N]; int main() { scanf("%s%d", A, &n); stl = strlen(A); ll = strlen(A); if (A[0] == '?') A[0] = '!'; for (int j = 0; ll - j - 1 > j; j++) swap(A[j], A[ll - j - 1]); for (int i = 1; i <= n; i++) { scanf("%s", B[i]); int x = strlen(B[i]); ll = max(ll, x); len[i] = x; for (int j = 0; x - j - 1 > j; j++) swap(B[i][j], B[i][x - j - 1]); } for (int i = 0; i <= ll; i++) if (!A[i]) A[i] = '0'; for (int i = 0; i <= ll; i++) { for (int j = 1; j <= n; j++) if (!B[j][i]) B[j][i] = '0'; } for (int i = 0; i <= 9; i++) scanf("%d", c + i); for (int i = 10; i < 30; i++) c[i] = c[i - 10]; for (int i = 1; i <= n; i++) sa[i] = i; memset(dp, 0x88, sizeof(dp)); int *x = sa, *y = sa2; dp[0][0] = 0; ll++; for (int i = 0; i < ll; i++) { T ^= 1; memset(dp[T], 0x88, sizeof(dp[T])); memset(f, 0, sizeof(f)); for (int j = 1; j <= n; j++) f[B[j][i] - '0']++; for (int j = 1; j < 10; j++) f[j] += f[j - 1]; for (int j = n; j >= 1; j--) y[f[B[x[j]][i] - '0']--] = x[j]; memset(f, 0, sizeof(f)); memset(g, 0, sizeof(g)); int gg = 0; for (int j = 1; j <= n; j++) f[B[j][i] - '0']++; for (int j = 1; j <= n; j++) if (len[j] <= i) gg++; for (int j = 0; j <= n; j++) { int ak = 0; if (A[i] == '?' || A[i] == '!') for (int k = 0; k < 10; k++) { ak += f[10 - k]; if (A[i] == '!' && k == 0) continue; int ans = 0; for (int l = 0; l < 10; l++) ans += c[k + l] * (f[l] - g[l]) + c[k + l + 1] * g[l]; dp[T][ak + g[9 - k]] = max(dp[T][ak + g[9 - k]], dp[!T][j] + ans); } else { for (int k = 0; k < A[i] - '0'; k++) ak += f[10 - k]; int k = A[i] - '0'; ak += f[10 - k]; int ans = 0; for (int l = 0; l < 10; l++) if (i >= stl && l == 0) ans += c[k + l] * (f[l] - g[l] - gg) + c[k + l + 1] * g[l]; else ans += c[k + l] * (f[l] - g[l]) + c[k + l + 1] * g[l]; dp[T][ak + g[9 - k]] = max(dp[T][ak + g[9 - k]], dp[!T][j] + ans); } g[B[x[n - j]][i] - '0']++; if (len[x[n - j]] <= i) gg--; } swap(x, y); } int ans = 0; for (int i = 0; i <= n; i++) ans = max(ans, dp[T][i]); cout << ans; return 0; }
3,000
CPP
input() s = sum(map(int, input().split())) print('HARD' if s else 'EASY')
800
PYTHON3
a, b, s = [abs(int(x)) for x in input().strip().split()] diff = s - a - b print("Yes" if diff >= 0 and diff % 2 == 0 else "No")
1,000
PYTHON3
#include <bits/stdc++.h> using namespace std; const char fi[] = "vd.inp"; const char fo[] = "vd.out"; long n, m, x, y, a, b; long u, v; long xa, ya, xb, yb; long ucln(long a, long b) { long r = a % b; while (r) { a = b; b = r; r = a % b; } return (b); } int main() { scanf("%ld%ld%ld%ld%ld%ld", &n, &m, &x, &y, &a, &b); long tg = ucln(a, b); a /= tg; b /= tg; tg = min(n / a, m / b); u = tg * a; v = tg * b; if (u % 2 == 0) xa = x - u / 2; else xa = x - u / 2 - 1; xb = xa + u; if (xa < 0) { xa = 0; xb = xa + u; } if (xb > n) { xb = n; xa = xb - u; } if (v % 2 == 0) ya = y - v / 2; else ya = y - v / 2 - 1; yb = ya + v; if (ya < 0) { ya = 0; yb = ya + v; } if (yb > m) { yb = m; ya = yb - v; } printf("%ld %ld %ld %ld", xa, ya, xb, yb); }
1,700
CPP
#!/usr/bin/python3 def main(): t, s, x = map(int, input().split()) if x == t: print("YES") return x -= t + s if (x >= 0 and x % s == 0) or (x >= 1 and (x - 1) % s == 0): print("YES") else: print("NO") main()
900
PYTHON3
# import sys # input=sys.stdin.readline def fu(a,x): for i in range(x): a[i]=str((int(a[i])+1)%2) a[:x]=a[:x][::-1] t=int(input()) for _ in range(t): n=int(input()) a=list(input()) b=list(input()) c=[] for i in range(n): if a[n-i-1]!=b[n-i-1]: if a[0]==b[n-i-1]: c.append(n-i) fu(a,n-i) c.append(1) fu(a,1) c.append(n-i) fu(a,n-i) else: c.append(n-i) fu(a,n-i) print(len(c),*c)
1,300
PYTHON3
#include <bits/stdc++.h> using namespace std; long long MOD = 1000000007; const double pi = 3.141592653589793; int main() { int T; cin >> T; for (int i = 0; i < T; i++) { double n; cin >> n; cout << setprecision(20) << cos(pi / (4 * n)) / sin(pi / (2 * n)) << '\n'; } }
1,400
CPP
#include <bits/stdc++.h> using namespace std; const int N = 55, M = 10101; int d, n; int a[N]; bool f[N * M]; int main() { while (~scanf("%d%d", &n, &d)) { memset(f, 0, sizeof(f)); for (int i = (1); i < (n + 1); i++) scanf("%d", a + i); f[0] = 1; for (int i = (1); i < (n + 1); i++) { for (int j = N * M - 1; j >= a[i]; --j) if (f[j - a[i]]) f[j] = 1; } int r1 = 0, r2 = 0; for (;;) { int pre = r1; r1 += d; for (int i = (0); i < (d + 1); i++) { if (f[r1 - i]) { r1 -= i; break; } } if (r1 == pre) break; ++r2; } printf("%d %d\n", r1, r2); } return 0; }
2,200
CPP
#include <bits/stdc++.h> using namespace std; const int MAX = 1e5 + 9; int n, nxt[MAX], a[MAX]; int main() { cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; int ans = 0; for (int l = 0; l < n; l++) { for (int i = n - 2, j = n - 1; i >= 0; i--) { while (i < j - a[j]) j--; nxt[i] = j; } for (int i = 0; i < n - 1; i = nxt[i]) ans++; rotate(a, a + n - 1, a + n); } cout << ans; }
1,900
CPP
a,b=list(map(int,input().split())) c=0 f=True while f: a=a*3 b=b*2 c+=1 if a>b: f=False print(c)
800
PYTHON3
#include <bits/stdc++.h> using namespace std; const int maxn = 1100; int n, m; int v[maxn], mark[maxn]; vector<int> g[maxn]; long long J; int main() { cin >> n >> m; for (int i = 0; i < n; i++) cin >> v[i]; for (int i = 0; i < m; i++) { int x, y; cin >> x >> y; x--; y--; g[x].push_back(y); g[y].push_back(x); } v[n] = -1; for (int i = 0; i < n; i++) { int r = n; for (int j = 0; j < n; j++) if (v[r] < v[j] && !mark[j]) r = j; for (int j = 0; j < g[r].size(); j++) if (!mark[g[r][j]]) J += v[g[r][j]]; mark[r] = 1; } cout << J << endl; }
1,400
CPP
n = int(input()) l = list(map(int,input().split())) l1 = [] l2 = [] l3 = [] for f in range(n) : if l[f] == 1 : l1.append(f+1) if l[f] == 2 : l2.append(f+1) if l[f] == 3 : l3.append(f+1) print(min(len(l1),len(l2),len(l3))) for f in range(min(len(l1),len(l2),len(l3))) : print(l1[f],l2[f],l3[f])
800
PYTHON3
#from bisect import bisect_left as bl #c++ lowerbound bl(array,element) #from bisect import bisect_right as br #c++ upperbound br(array,element) #from __future__ import print_function, division #while using python2 def modinv(n,p): return pow(n,p-2,p) def get_moves(a, n): moves = [] i = 0 while True: if a[i] == 0: while i+1 < n and a[i+1] == 0: i += 1 i += 1 moves.append(i) if i >= n: break if a[i] == 1: while i+1 < n and a[i+1] == 1: i += 1 i += 1 moves.append(i) if i >= n: break if a[n-1] == 0: moves.pop(-1) return moves def main(): #sys.stdin = open('input.txt', 'r') #sys.stdout = open('output.txt', 'w') for case in range(int(input())): n = int(input()) a = [int(x) for x in input()] b = [int(x) for x in input()] # string a to all zero moves_a = get_moves(a, n) # string b to all zero moves_b = get_moves(b, n) moves_b.reverse() print(len(moves_a) + len(moves_b), *moves_a, *moves_b) #------------------ Python 2 and 3 footer by Pajenegod and c1729----------------------------------------- py2 = round(0.5) if py2: from future_builtins import ascii, filter, hex, map, oct, zip range = xrange import os, sys from io import IOBase, BytesIO 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): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable if py2: 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) input = lambda: sys.stdin.readline().rstrip('\r\n') if __name__ == '__main__': main()
1,300
PYTHON3
#include <bits/stdc++.h> const int mod = 1e9 + 7; const int MAXS = 5005, MAXT = 5005, MAXSIZ = 205, MAXL = MAXS + MAXT, MAXLOG = 16; template <typename _T> void read(_T &x) { x = 0; char s = getchar(); int f = 1; while (s > '9' || s < '0') { if (s == '-') f = -1; s = getchar(); } while (s >= '0' && s <= '9') { x = (x << 3) + (x << 1) + (s - '0'), s = getchar(); } x *= f; } template <typename _T> void write(_T x) { if (x < 0) { putchar('-'); x = (~x) + 1; } if (9 < x) { write(x / 10); } putchar(x % 10 + '0'); } template <typename _T> _T MAX(const _T a, const _T b) { return a > b ? a : b; } template <typename _T> _T MIN(const _T a, const _T b) { return a < b ? a : b; } long long DP[MAXS][MAXT]; int a[MAXS], b[MAXT]; char s[MAXS], t[MAXT]; int N, M; int main() { scanf("%s%s", s + 1, t + 1); N = strlen(s + 1), M = strlen(t + 1); for (int i = 1; i <= N; i++) a[i] = s[i]; for (int i = 1; i <= M; i++) b[i] = t[i]; long long res = 0; for (int i = 1; i <= N; i++) { for (int j = 1; j <= M; j++) { DP[i][j] = DP[i][j - 1]; if (a[i] == b[j]) { DP[i][j] = (DP[i][j] + DP[i - 1][j - 1] + 1) % mod; } } res = (res + DP[i][M]) % mod; } write(res), putchar('\n'); return 0; }
1,700
CPP
#include <bits/stdc++.h> using namespace std; int main() { cin.sync_with_stdio(false); cin.tie(0); long long int n, m, x, i, j, ans = 0, i1, l, s = 0; string t; cin >> n >> m >> x; vector<vector<char>> k(n, vector<char>(m)); vector<pair<long long int, long long int>> pairs; unordered_map<char, bool> keys; for (i = 0; i <= n - 1; ++i) for (j = 0; j <= m - 1; ++j) { cin >> k[i][j]; if (!(keys.find(k[i][j]) != keys.end())) keys.insert(make_pair(k[i][j], true)); if (k[i][j] == 'S') { ++s; pairs.push_back(make_pair(i, j)); } } cin >> l >> t; vector<double> ch(26, INT_MAX); for (i = 0; i <= n - 1; ++i) { for (j = 0; j <= m - 1; ++j) { double d = 0, md = INT_MAX; for (i1 = 0; i1 <= s - 1; ++i1) { d = (pairs[i1].first - i) * (pairs[i1].first - i) + (pairs[i1].second - j) * (pairs[i1].second - j); md = min(md, d); } ch[k[i][j] - 'a'] = min(sqrt(md), ch[k[i][j] - 'a']); } } bool possible = true; for (i = 0; i <= l - 1; ++i) { char c = t[i]; if (isupper(t[i])) c = t[i] + 32; if ((isupper(t[i]) and !s) or !(keys.find(c) != keys.end())) { possible = false; break; } if (isupper(t[i]) and ch[c - 'a'] > x) ++ans; } if (!possible) cout << "-1\n"; else cout << ans << '\n'; return 0; }
1,500
CPP
def gcd(x,y): if(y==0): return x else: return gcd(y,x%y) t=int(input()) for _ in range(t): u,v=map(int,input().split()) if(u>v): if(u%v==0): print("YES") else: print("NO") else: if(v%u==0): print("YES") else: print("NO")
800
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int a[7]; for (int i = 0; i < 6; i++) cin >> a[i]; sort(a, a + 6); do { if (a[0] + a[1] + a[2] == a[3] + a[4] + a[5]) { cout << "YES"; return 0; } } while (next_permutation(a, a + 6)); cout << "NO"; }
1,000
CPP
#include <bits/stdc++.h> using namespace std; int n, fi[60], res = INT_MAX; string a[60], t, ta; int aa[200], bb[200]; int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; int x = a[1].length() - 1; for (int i = 0; i <= x; i++) aa[a[1][i]]++; for (int i = 2; i <= n; i++) { memset(bb, 0, sizeof(bb)); for (int j = 0; j <= x; j++) bb[a[i][j]]++; for (int j = 'a'; j <= 'z'; j++) if (aa[j] != bb[j]) { cout << -1; return 0; } } for (int i = 1; i <= n; i++) { fi[i] = 0; for (int j = 1; j <= n; j++) { if (i == j) continue; t = a[j]; if (t == a[i]) continue; for (int k = 0; k < a[j].length(); k++) { fi[i]++; char x = t[0]; t.erase(0, 1); t += x; if (t == a[i]) break; } if (t != a[i]) fi[i] = INT_MAX; } } for (int i = 1; i <= n; i++) res = min(res, fi[i]); if (res == INT_MAX) cout << -1; else cout << res; }
1,300
CPP
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int d[n]; for (int i(0); i < n; i++) cin >> d[i]; for (int i(n - 1); i > 0; i--) if (abs(d[i] - d[i - 1]) >= 2) { cout << "NO"; return 0; } cout << "YES"; return 0; }
1,600
CPP
#include <bits/stdc++.h> using namespace std; template <class L, class R> ostream &operator<<(ostream &os, pair<L, R> P) { return os << "(" << P.first << "," << P.second << ")"; } template <class T> ostream &operator<<(ostream &os, set<T> V) { os << "["; for (auto vv : V) os << vv << ","; return os << "]"; } template <class T> ostream &operator<<(ostream &os, vector<T> V) { os << "["; for (auto vv : V) os << vv << ","; return os << "]"; } template <class K, class X> ostream &operator<<(ostream &os, map<K, X> V) { os << "["; for (auto vv : V) os << vv << ","; return os << "]"; } void debug_out() { cerr << '\n'; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...); } using ii = pair<long long, long long>; using vb = vector<bool>; using vi = vector<long long>; using vii = vector<ii>; using vvi = vector<vi>; using vvii = vector<vii>; template <long long dim = 20> class gauss { public: std::array<long long, dim> basis; std::array<long long, dim> index; gauss() { basis.fill(0); index.fill(-1); } void add(long long idx, long long x) { for (long long i = dim - 1; i >= 0 && x; i--) { long long mask = (1 << i); if ((x & mask) && (basis[i] == 0 or idx > index[i])) { swap(x, basis[i]); swap(idx, index[i]); } x = std::min(x, x ^ basis[i]); } } long long querymax(long long idx) { long long best = 0; for (long long i = dim - 1; i >= 0; i--) { if (index[i] >= idx) { best = std::max(best, best ^ basis[i]); } } return best; } }; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n; cin >> n; vi c(n); vector<gauss<20>> gv(n); for (long long i = 0; i < n; i++) { cin >> c[i]; if (i > 0) { gv[i] = gv[i - 1]; } gv[i].add(i, c[i]); } long long m; cin >> m; for (long long i = 0; i < m; i++) { long long ll, rr; cin >> ll >> rr; ll--; rr--; cout << gv[rr].querymax(ll) << '\n'; } }
2,500
CPP
#include <bits/stdc++.h> using namespace std; int main() { string x; int n; cin >> x >> n; int alpha[26]; int max = 0; for (int i = 0; i < 26; i++) { cin >> alpha[i]; if (max < alpha[i]) max = alpha[i]; } int total = 0; for (int i = 0; i < x.length(); i++) { int temp = x[i] - 97; total += alpha[temp] * (i + 1); } int temp = x.length() + 1; while (n > 0) { total += temp * max; temp++; n--; } cout << total; return 0; }
1,000
CPP
T = int(input()) for t in range(T): n = int(input()) A = [int(i) for i in input().split()] # if at most half is 1, remove all the 1 # if odd number of 1 one_count = 0 for i in A: if i == 1: one_count += 1 if one_count <= n//2: # remove all 1 ans = [0] * (n-one_count) else: # remove all the zero if one_count % 2: ans = [1] * (one_count - 1) else: ans = [1] * one_count print(len(ans)) print(*ans)
1,100
PYTHON3
s = input().split(":") fir = int(s[0]) sec = int(s[1]) def ispal(a,b): if len(a)==1:a = "0"+a if len(b)==1:b = "0"+b if a[::-1]==b:return True ans = 0 while not ispal(str(fir),str(sec)): ans += 1 sec += 1 if sec == 60: sec = 0 fir += 1 if fir == 24: fir = 0 sec = 0 print(ans)
1,000
PYTHON3
#include <bits/stdc++.h> using namespace std; int n, k, a[105], b[105], w[105], dp1[20010], dp2[20010]; int main() { while (scanf("%d%d", &n, &k) != EOF) { for (int i = 1; i <= n; i++) scanf("%d", &a[i]); for (int j = 1; j <= n; j++) scanf("%d", &b[j]); for (int i = 0; i <= 20000; i++) dp1[i] = dp2[i] = -1 << 30; dp1[0] = 0, dp2[0] = 0; for (int i = 1; i <= n; i++) { w[i] = a[i] - k * b[i]; if (w[i] > 0) { for (int j = 20000; j >= w[i]; j--) { dp1[j] = max(dp1[j - w[i]] + a[i], dp1[j]); } } else { w[i] = -w[i]; for (int j = 20000; j >= w[i]; j--) { dp2[j] = max(dp2[j - w[i]] + a[i], dp2[j]); } } } int maxx = -1; for (int i = 0; i <= 20000; i++) { maxx = max(maxx, dp1[i] + dp2[i]); } if (maxx == 0) printf("-1\n"); else printf("%d\n", maxx); } return 0; }
1,900
CPP
import sys t = int(sys.stdin.readline()) for _ in range(t): n = int(sys.stdin.readline()) xn = list(map(int, sys.stdin.readline().split())) m=int(sys.stdin.readline()) xm=list(map(int, sys.stdin.readline().split())) no=0 ne=0 for i in xn: if i % 2 == 0: no += 1 else: ne += 1 mo=0 me=0 for i in xm: if i % 2 == 0: mo += 1 else: me += 1 print(mo*no+me*ne)
1,000
PYTHON3
#include <bits/stdc++.h> using namespace std; template <class T> void read(T& num) { char CH; bool F = false; for (CH = getchar(); CH < '0' || CH > '9'; F = CH == '-', CH = getchar()) ; for (num = 0; CH >= '0' && CH <= '9'; num = num * 10 + CH - '0', CH = getchar()) ; F && (num = -num); } long long ax, ay, bx, by, cx, cy; int solve(long long x, long long y) { x = bx - x; y = by - y; if (cx == 0 && cy == 0) { if (x == 0 && y == 0) return 1; return 0; } else if (cx == 0) { long long g = x / cy, h = y / cy; if (g * cy == x && h * cy == y) return 1; return 0; } else if (cy == 0) { long long g = x / cx, h = y / cx; if (g * cx == x && h * cx == y) return 1; return 0; } else { long long tx = x * cy, ty = y * cx; long long b = (tx - ty) / (cy * cy + cx * cx); if (b * (cx * cx + cy * cy) != (tx - ty)) return 0; else { long long a = (x - b * cy) / cx; if (a * cx + b * cy == x) return 1; return 0; } } } int main() { read(ax); read(ay); read(bx); read(by); read(cx); read(cy); int f = 0; if (solve(ax, ay)) f = 1; if (solve(-ax, -ay)) f = 1; if (solve(ay, -ax)) f = 1; if (solve(-ay, ax)) f = 1; if (f) cout << "YES\n"; else cout << "NO\n"; return 0; }
2,000
CPP
t=int(input()) for i in range(t): n=int(input()) a=n//2 b=n%2 if(b==1): a=a-1 b=b+2 if(b==3): print(7,end="") for i in range(a): print(1,end="") print()
900
PYTHON3
for _ in range(int(input())): nn=input() l1=[int(i) for i in input().split()] cc=input() l2=[int(k) for k in input().split()] max1=max2=0 s1=s2=0 for i in range(len(l1)): s1+=l1[i] max1=max(max1,s1) for j in range(len(l2)): s2+=l2[j] max2=max(max2,s2) #print(max1,max2) print(max1+max2)
1,000
PYTHON3
n, k = map(int, input().split()) l = list(map(int, input().split())) mx = -1000000001 if k == 1: print(min(l)) elif k >= 3: print(max(l)) else: temp_mn = 1000000001 for i in range(n - 1): temp_mn = min(temp_mn, l[i]) mx = max(temp_mn, mx) temp_mn = 1000000001 for i in range(n - 1, 0, -1): temp_mn = min(temp_mn, l[i]) mx = max(temp_mn, mx) print(mx)
1,200
PYTHON3
k,n,w=(int (x) for x in input() .split()) price =0 for i in range(1,w+1): price+=k*i print(max(0,price-n))
800
PYTHON3
#include <bits/stdc++.h> using namespace std; const int mod = (int)1e9 + 7; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << std::endl; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; stack<int> st; cin >> n; int top = 0, ans = 0; int cnt = 1; for (int i = 0; i < 2 * n; i++) { string s; int t = 0; cin >> s; if (s == "add") { cin >> t; st.push(t); } else { if (!st.empty()) { if (st.top() == cnt) st.pop(); else { ans++; while (!st.empty()) st.pop(); } } cnt++; } } cout << ans << endl; }
1,500
CPP
for _ in range(int(input())): n, k = list(map(int,input().split())) if n%k == 0 and n>=k: print("YES") l=[n//k] * (k) print(*l) elif n<k : print("NO") else: k -=1 if (n-k) % 2 != 0 and (n-k)>0 : l = [1] * k + [n-k] print("YES") print(*l) elif (n-2*k)%2 ==0 and (n-2*k)>0: l = [2] * k + [n-2*k] print("YES") print(*l) else: print("NO")
1,200
PYTHON3
t = int(input()) array = [] for i in range(0, t): n = int(input()) array = input().split(" ") result = [] for j in range(0, n, 2): a, b = int(array[j]), int(array[j + 1]) if a > 0 and b > 0 or a < 0 and b < 0: result += [-b, a] else: result += abs(b), abs(a) print(*result)
800
PYTHON3
for _ in range(int(input())): n,m=map(int,input().split()) s=[input() for _ in range(n)] for i in range(m): v=0 for l in range(26): p=s[0][:i]+chr(97+l)+s[0][i+1:] t=0 for u in s: r=0 for h in range(m): if u[h]!=p[h]: if r: t=1 break else: r=1 if t: break else: print(p);v=1;break if v: break else: print(-1)
1,700
PYTHON3
if __name__ == '__main__': n = int(input()) print((n - 1) // 2)
1,000
PYTHON3
import math n=input() a=list(map(lambda x:int(x),input().split())) a_min=min(a) a_max=max(a) isFind=False ans=math.inf for i in range(a_min,a_max+1): diff=0 flag=True for j in a: if j-i==0: continue else: if diff==0: diff=abs(i-j) elif abs(j-i)!=diff: flag=False break if flag: ans=min(ans,diff) isFind=True if not isFind: print(-1) else: print(ans)
1,200
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { long long int n, m, ans, ans1, x; cin >> n; m = n; ans = 0; ans1 = 0; while (n--) { cin >> x; ans |= x; } while (m--) { cin >> x; ans1 |= x; } cout << ans + ans1; return 0; }
900
CPP
n = int(input()) s = input() for i in range(101): for j in range(n): if s[j] == '-': i -= 1 else: i += 1 if i < 0: break if i >= 0 and j == n - 1: print(i) break
800
PYTHON3
a=input() a=int(a) b=input() c=0 for i in range (a): try: if(b[i+1]<b[i]): for j in range(i+1,a): print(b[j],end="") break else: print(b[i],end="") except: pass
1,200
PYTHON3
#include <bits/stdc++.h> using namespace std; const int maxn = 2005; typedef long long ll; struct Node{ int x,y; int cmp(){ return y<0 || y==0 && x<0; } }a[maxn]; Node operator -(const Node a,const Node b){ return Node{a.x-b.x,a.y-b.y}; } ll operator *(const Node a,const Node b){ return 1ll*a.x*b.y-1ll*a.y*b.x; } int p[maxn],cyc[maxn],cyctot; vector<int>lis[maxn],g; int main(){ int n; scanf("%d",&n); for(int i=1;i<=n;++i)scanf("%d%d%d",&a[i].x,&a[i].y,&p[i]); int ori=0; for(int i=1;i<=n;++i){ if(cyc[i] || i==p[i])continue; int u=i;++cyctot; while(!cyc[u]){ cyc[u]=cyctot; lis[cyctot].push_back(u); u=p[u]; if(!ori || a[ori].y>a[i].y)ori=i; } } if(!ori)return printf("0\n"),0; for(int i=1;i<=n;++i){ if(!cyc[i] || i==ori)continue; g.push_back(i); } sort(g.begin(),g.end(),[&](int c,int d){ Node e=a[c]-a[ori],f=a[d]-a[ori]; if(e.cmp()!=f.cmp()){ return e.cmp()<f.cmp(); } return e*f>0; }); vector<array<int,2>>ans; for(int i=0;i+1<g.size();++i){ int u=g[i],v=g[i+1],cu=cyc[u],cv=cyc[v]; if(cu!=cv){ ans.push_back({u,v}); swap(p[u],p[v]); for(auto c:lis[cv]){ cyc[c]=cu; lis[cu].push_back(c); } lis[cv].clear(); } } while(ori!=p[ori]){ int u=p[ori]; ans.push_back({ori,u}); swap(p[u],p[ori]); } printf("%d\n",(int)ans.size()); for(auto [u,v]:ans)printf("%d %d\n",u,v);puts(""); }
3,000
CPP
n = int(input()) l=[n] while n!=1: for i in range(2,n+1): if n%i==0: n=n//i l.append(n) break for i in l: print(i,end=" ")
1,300
PYTHON3
from math import gcd from collections import Counter def printYes(): print("YES") def printNo(): print("NO") t = int(input()) for i in range(t): a,b,c= map(int,input().split()) while b!=0 and a>20: a=a//2 + 10 b=b-1 if a -c*10<=0: printYes() else: printNo()
900
PYTHON3
#include <bits/stdc++.h> using namespace std; int alpbt[26], flag[26], a[26]; int cmp(int x, int y) { return a[x] < a[y]; } int main() { string s; int k; int m = 0; cin >> s >> k; if (k >= s.size()) printf("0\n"); else { for (int i = 0; i < s.size(); i++) a[s[i] - 'a']++; for (int i = 0; i < 26; i++) alpbt[i] = i; sort(alpbt, alpbt + 26, cmp); for (int i = 0; i < 26; i++) { if (k < a[alpbt[i]]) break; k -= a[alpbt[i]]; flag[alpbt[i]] = 1; } for (int i = 0; i < 26; i++) { if (!flag[i]) m++; } printf("%d\n", m); for (int i = 0; i < s.size(); i++) if (!flag[s[i] - 'a']) cout << s[i]; } return 0; }
1,200
CPP
#include <bits/stdc++.h> using namespace std; int main() { int n; int sum = 0; int temp; cin >> n; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> temp; if ((i == (n) / 2) | (j == (n) / 2) | (i == j) | (i == n - 1 - j)) sum += temp; } } cout << sum; return 0; }
800
CPP
n = int(input()) a = [["."] * (2*n+3) for i in range(5)] for i in range(2*n+3): a[2][i] = "A" for i in range(n): a[1][i * 2 + 2] = "B" a[3][i * 2 + 2] = "C" a[0][0] = "D" a[0][1] = "E" a[1][0] = "F" a[0][2] = "Z" for i in range(n): if i % 2 == 0: a[4][i * 2 + 2] = "G" a[4][i * 2 + 3] = "H" a[4][i * 2 + 4] = "I" else: a[0][i * 2 + 2] = "J" a[0][i * 2 + 3] = "K" a[0][i * 2 + 4] = "L" if n % 2 == 0: a[0][2*n] = "M" a[0][2*n + 1] = "N" a[0][2*n + 2] = "O" a[1][2*n + 2] = "P" else: a[4][2*n] = "Q" a[4][2*n + 1] = "R" a[4][2*n + 2] = "S" a[3][2*n + 2] = "T" """ for x in a: print(*x, sep="") allcnt = 0 for i in range(len(a)): for j in range(len(a[i])): if a[i][j] != ".": cnt = 0 for x in [[-1, 0], [1, 0], [0, -1], [0, 1]]: ni = i + x[0] nj = j + x[1] if ni >= 0 and ni < len(a) and nj >= 0 and nj < len(a[ni]) and a[ni][nj] != ".": cnt += 1 if cnt % 2 != 0: print("Error! ", i, j, a[i][j], cnt) if cnt == 4: allcnt += 1 if allcnt != n: print("Error! allcnt ", allcnt) """ cnt = 0 for i in range(len(a)): for j in range(len(a[i])): if a[i][j] != ".": cnt += 1 print(cnt) for i in range(len(a)): for j in range(len(a[i])): if a[i][j] != ".": print(i, j)
1,500
PYTHON3
#include <bits/stdc++.h> using namespace std; long long a; int main() { while (~scanf("%I64d", &a)) { int ans = 0; long long temp; long long weishu = 0; long long shabi = 1; while (shabi * 10 <= a) { shabi *= 10; weishu++; } temp = a - shabi + 1; a = shabi - 1; while (a) { int fok = a % 10; a /= 10; ans += fok; } while (temp) { int op = temp % 10; temp /= 10; ans += op; } cout << ans << endl; } }
1,100
CPP
n,k=map(int,input().split()) B=[] for i in range(n): B.append(int(input())) A=[0]*k for i in range(n): A[B[i]-1]+=1 res=0 for i in range(len(A)): if A[i]>1: res+=(A[i]//2)*2 A[i]=A[i]%2 res+=(sum(A)+1)//2 print(res)
1,000
PYTHON3
n = int(input()) increment = 2 d_cnt = 1 for i in range(1, n+1): s_cnt = (n-d_cnt)//2 print('*'*s_cnt, end='') print('D'*d_cnt, end='') print('*'*s_cnt) d_cnt += increment if d_cnt == n: increment *= -1
800
PYTHON3
n, t = map(int, input().split()) a = list(map(int, input().split())) res = 0 for i in range(n): res += 86400 - a[i] if res >= t: print(i + 1) exit()
800
PYTHON3
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 2; long long st[N], zb[N], k, b, cd, y; int tp, m, c, x; inline void read(int &x) { c = getchar(); while ((c < 48) || (c > 57)) c = getchar(); x = c ^ 48; c = getchar(); while ((c >= 48) && (c <= 57)) { x = x * 10 + (c ^ 48); c = getchar(); } } int main() { read(x); cd = x; tp = 1; read(m); zb[1] = 1; for (; m--; printf("%lld %lld\n", zb[tp], st[tp] + zb[tp] * k + b)) { read(x); if (x == 1) { read(x); cd += x; tp = 1; k = b = 0; continue; } if (x == 2) { read(x); y = -k * (cd + 1) - b; if (st[tp] == -k * zb[tp] - b) { cd += x; continue; } while ((tp > 1) && ((long double)(st[tp] - y) * (zb[tp] - zb[tp - 1]) >= (long double)(st[tp - 1] - st[tp]) * (cd + 1 - zb[tp]))) --tp; zb[++tp] = cd + 1; st[tp] = y; cd += x; continue; } read(x); b += x; read(x); k += x; b -= x; while ((tp > 1) && ((st[tp - 1] - st[tp]) <= (long double)(zb[tp] - zb[tp - 1]) * k)) --tp; } }
2,700
CPP
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) if(n==1): print("First") else: count = 0 for i in range(n-1): if(a[i] == 1): count += 1 else: break if(count%2 == 0): print("First") else: print("Second")
1,100
PYTHON3
test_cases = int(input()) for _ in range(test_cases): n = int(input()) a = list(map(int, input().split())) zeros = [1 if x == 0 else 0 for x in a] find_zeros = sum(zeros) sum_a = sum(a) if find_zeros > 0: sum_a += find_zeros if sum_a == 0: print(1 + find_zeros) else: print(find_zeros) else: if sum_a == 0: print(1) else: print(0)
800
PYTHON3
#include <iostream> #include <cstring> #include <vector> #include <stack> #include <queue> #include <set> #ifdef ONLINE_JUDGE #define cerr if(0)cerr #endif using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<int, pii> edg; const int maxn = 210; const int maxm = 2012; edg G_edges[maxm]; edg H_edges[maxm]; vector<int> G[maxn]; vector<int> H[maxn]; int dist[maxn][maxn]; // in H bool vis[maxn]; bool color[maxn]; int edcnt_H = 0; int n, m; inline int get_other(int i, int v, edg arr[]) { if(arr[i].second.first == v) return arr[i].second.second; return arr[i].second.first; } inline void add_edge_H(int x, int y, int w) { H_edges[edcnt_H] = {w, {x, y}}; H[x].push_back(edcnt_H); dist[x][y] = w; edcnt_H++; cerr << "adding " << x << " " << y << " " << w << endl; } inline void fill_H() { for(int i = 0; i < m; i++) { int x = G_edges[i].second.first; int y = G_edges[i].second.second; if(G_edges[i].first == 1) { add_edge_H(x, y, 1); add_edge_H(y, x, -1); } else { add_edge_H(x, y, 1); add_edge_H(y, x, 1); } } } inline bool check_bipar() { stack<int> ds; ds.push(0); vis[0] = true; color[0] = 0; while(!ds.empty()) { int t = ds.top(); ds.pop(); for(int i: G[t]) { int u = get_other(i, t, G_edges); if(vis[u]) { if(color[u] == color[t]) return false; continue; } ds.push(u); vis[u] = true; color[u] = !color[t]; } } return true; } inline void floyd_warshall() { for(int i = 0; i < n; i++) dist[i][i] = 0; for(int k = 0; k < n; k++) for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) dist[i][j] = min(dist[i][j], dist[i][k]+dist[k][j]); } inline void die() { cout << "NO" << endl; exit(0); } int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n >> m; memset(dist, 63, sizeof dist); for(int i = 0; i < m; i++) { int x, y, b; cin >> x >> y >> b; x--; y--; G_edges[i] = {b, {x, y}}; G[x].push_back(i); G[y].push_back(i); } bool bip = check_bipar(); cerr << "bipar: " << bip << endl; if(!bip) die(); fill_H(); for(int i = 0; i < n; i++) { cerr << i+1 << ": "; for(int j: H[i]) { int u = get_other(j, i, H_edges); int w = H_edges[i].first; cerr << u+1 << "," << w << " "; } cerr << endl; } floyd_warshall(); cerr << endl; for(int i = 0; i < n; i++) { cerr << i << ": "; for(int j = 0; j < n; j++) cerr << dist[i][j] << " "; cerr << endl; } int max_dist = 0; int source = 0; int destin = 0; for(int i = 0; i < n; i++) { if(dist[i][i] < 0) die(); for(int j = 0; j < n; j++) { if(dist[i][j] > max_dist) { max_dist = dist[i][j]; source = i; destin = j; } } } cout << "YES" << endl; cout << max_dist << endl; for(int i = 0; i < n; i++) { cout << dist[source][i] << " "; } cout << endl; return 0; }
2,700
CPP
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n, i, j; cin >> n; map<long long, long long> m; pair<long long, long long> a[4 * n + 1]; vector<long long> v[51], s[51]; for (i = 0; i < 4 * n + 1; i++) { long long x, y; cin >> x >> y; a[i].first = x; a[i].second = y; v[x].push_back(y); s[y].push_back(x); } long long mnx = -1, mny = -1, mxx = -1, mxy = -1; for (i = 0; i < 51; i++) { if (v[i].size() >= n) { if (mnx == -1) { mnx = i; } else { mxx = i; } } if (s[i].size() >= n) { if (mny == -1) { mny = i; } else { mxy = i; } } } for (i = 0; i < 4 * n + 1; i++) { if ((a[i].first == mnx || a[i].first == mxx) && a[i].second <= mxy && a[i].second >= mny) continue; if ((a[i].second == mny || a[i].second == mxy) && a[i].first <= mxx && a[i].first >= mnx) continue; cout << a[i].first << " " << a[i].second; return 0; } }
1,600
CPP
n = int(input()) sr = input() o = 0 z= 0 for x in sr: if(x=='n'): o+=1 if(x=='z'): z+=1 while(o!=0): print("1", end = " ") o-=1 while(z!=0): print("0", end = " ") z-=1
800
PYTHON3
#include <bits/stdc++.h> using namespace std; int N, P, u, v, _w; int Q[1024][3], nQ = 0; int nxt[1024], w[1024]; bool pre[1024]; void calc(int u) { int maxf = 0x7fffffff; Q[nQ][0] = u; while (nxt[u] != -1) { maxf = min(maxf, w[u]); u = nxt[u]; } Q[nQ][1] = u; Q[nQ++][2] = maxf; } int main() { scanf("%d %d", &N, &P); memset(pre, 0, sizeof(pre)); memset(nxt, -1, sizeof(nxt)); for (int i = 0; i < P; ++i) { scanf("%d %d %d", &u, &v, &_w); pre[v] = 1, nxt[u] = v, w[u] = _w; } for (int i = 1; i <= N; ++i) if (!pre[i] && nxt[i] != -1) calc(i); printf("%d\n", nQ); for (int i = 0; i < nQ; ++i) printf("%d %d %d\n", Q[i][0], Q[i][1], Q[i][2]); return 0; }
1,400
CPP
# n=int(input()) # if(n%2==0): # print("YES") # else: # print("NO") # for _ in range(int(input())): # n=(input()) # if(len(n)<=10): # print(n) # else: # print(n[0]+str(len(n)-2)+n[len(n)-1]) # a=0 # for _ in range(int(input())): # n=list(map(int,input().split())) # count=0 # for i in range(len(n)): # if(n[i]==1): # count+=1 # else: # count-=1 # if(count>0): # a+=1 # print(a) # n,m=map(int,input().split()) # a=list(map(int,input().split())) # count=0 # for i in range(len(a)): # if(a[i]>=a[m-1] and a[i]>0): # count+=1 # print(count) # n,m=map(int,input().split()) # # if((n*m)%2!=0): # print((n*m)//2) # # else: # # print((n*m)//2)\ # x=0 # for _ in range(int(input())): # n=input() # if(n=="X++" or n=="++X"): # x=x+1 # else: # x=x-1 # print(x) # n = input() # m = input() # n = n.lower() # m = m.lower() # if n == m: # print("0") # elif n > m: # print('1') # elif n <m: # print('-1') # matrix=[] # min=[] # one_line=0 # one_column=0 # for l in range(0,5): # m=input().split() # for col,ele in enumerate() # a = list(map(int,input().split('+'))) # a.sort() # print('+'.join([str(c) for c in a])) # n=list(input()) # # if(n[0].islower()): # n[0]=n[0].upper() # else: # pass # print("".join(str(x)for x in n)) # n=list(input()) # s=input() # count=0 # for i in range(1,len(s)): # if(s[i]==s[i-1]): # count+=1 # print(count) # v=["A","O","Y","E","U","I","a","i","e","o","u","y"] # n=list(input()) # x=[] # for i in range(len(n)): # if n[i] not in v: # x.append(n[i]) # print("."+".".join(str(y.lower())for y in x)) # a=[] # b=[] # c=[] # for _ in range(int(input())): # x,y,z=map(int,input().split()) # a.append(x) # b.append(y) # c.append(z) # print("YES" if sum(a)==sum(b)==sum(c)== 0 else "NO") # m = "hello" # n=input() # j=0 # flag=0 # for i in range(len(n)): # if(n[i]==m[j]): # j=j+1 # if(j==5): # flag=1 # break # if(flag==1): # print("YES") # else: # print("NO") # a=set(list(input())) # print("CHAT WITH HER!" if len(set(list(input())))%2==0 else "IGNORE HIM!") # k,n,w=map(int,input().split()) # sum=0 # a=[] # for i in range(w+1): # sum+=k*i # print((sum-n) if sum>n else 0) # m,n = 0,0 # for i in range(5): # a = map(int,input().split()) # for j in range(5): # if a[j]!=0: # m = i # n = j # break # print(abs(m-2)+abs(n-2)) # l,b=map(int,input().split()) # c=0 # while(l<=b): # l=l*3 # b=b*2 # c=c+1 # print(c) # from math import ceil # n,m,a=map(int,input().split()) # # print(ceil(n/a),ceil(m/a)) # c=ceil(n/a)*ceil(m/a) # print(c) # n=int(input()) # if(n%4==0 or n%7==0 or n%44==0 or n%47==0 or n%74==0 or n%444==0 or n%447==0 or n%474==0 or n%477==0): # print("YES") # else: # print("NO") # def tramCapacity(): # n = int(input().strip()) # pout, pin = map(int, input().strip().split()) # sm = pin # mx = pin # for i in range(n-1): # pout, pin = map(int, input().strip().split()) # sm = sm - pout + pin # if sm > mx: # mx = sm # return mx # print(tramCapacity()) # n,k=map(int,input().split()) # for i in range(k): # if(str(n)[-1]=="0"): # n=n//10 # else: # n=n-1 # print(n) # n=int(input()) # n=int(input()) # if(n%5==0): # print(n//5) # else: # print((n//5)+1) # n=int(input()) # if(n%2==0): # print(n//2) # else: # print("-"+str(n-((n-1)//2))) # n=int(input()) # arr=list(map(int,input().split())) # sum=sum(arr) # deno=len(arr)*100 # print(format(((sum/deno)*100),'.12f')) # k=int(input()) # l=int(input()) # m=int(input()) # n=int(input()) # d=int(input()) # count=0 # # if(d%k==0): # # print(d) # # elif(d%l==0): # # print(d//l) # # elif(d%m==0): # # print(d//m) # # elif(d%n==0): # # print(d//n) # # else: # for i in range(1,d+1): # if(i%k==0 or i%l==0 or i%m==0 or i%n==0): # count+=1 # print(count) # a,b=map(int,input().split()) # # if(n%m==0): # # print(0) # # else: # # for i in range(m): # # n=n+i # # if(n%m==0): # # print(i-1) # # break # # else: # # continue # x=((a+b)-1)/b # print((b*x)-1) # for _ in range(int(input())): # a, b = map(int,input().split(" ")) # x=(a + b - 1) // b # # print(x) # print((b * x) - a) # for _ in range(int(input())): # n=int(input()) # print((n-1)//2) # n=int(input()) # # n = int(input()) # if n%2 == 0: # print(8, n-8) # else: # print(9, n-9) # n=int(input()) # a=[] # for i in range(len(n)): # x=int(n)-int(n)%(10**i) # a.append(x) # print(a) # # b=max(a) # print(a[-1]) # for i in range(len(a)): # a[i]=a[i]-a[-1] # print(a) # for _ in range(int(input())): # n=int(input()) # p=1 # rl=[] # x=[] # while(n>0): # dig=n%10 # r=dig*p # rl.append(r) # p*=10 # n=n//10 # for i in rl: # if i !=0: # x.append(i) # print(len(x)) # print(" ".join(str(x)for x in x)) # n,m=map(int,input().split()) # print(str(min(n,m))+" "+str((max(n,m)-min(n,m))//2)) # arr=sorted(list(map(int,input().split()))) # s=max(arr) # ac=arr[0] # ab=arr[1] # bc=arr[2] # a=s-bc # b=ab-a # c=bc-b # print(a,b,c) # x=0 # q,t=map(int,input().split()) # for i in range(1,q+1): # x=x+5*i # if(x>240-t): # print(i-1) # break # if(x<=240-t): # print(q) # # print(q) # print(z) # print(x) # l=(240-t)-x # print(l) # if(((240-t)-x)>=0): # print(q) # else: # print(q-1) # n, L = map(int, input().split()) # arr = [int(x) for x in input().split()] # arr.sort() # x = arr[0] - 0 # y = L - arr[-1] # r = max(x, y) * 2 # for i in range(1, n): # r = max(r, arr[i] - arr[i-1]) # print(format(r/2,'.12f')) # n,m=map(int,input().split()) # print(((m-n)*2)-1) # for _ in range(int(input())): # n=int(input()) # x=360/(180-n) # # print(x) # if(n==60 or n==90 or n==120 or n==108 or n==128.57 or n==135 or n==140 or n==144 or n==162 or n==180): # print("YES") # elif(x==round(x)): # print("YES") # else: # print("NO") # n,m=map(int,input().split()) # if(n<2 and m==10): # print(-1) # else: # x=10**(n-1) # print(x+(m-(x%m))) # for _ in range(int(input())): # n,k=map(int,input().split()) # a=list(map(int,input().split())) # a.sort() # c=0 # for i in range(1,n): # c = (k-a[i])//a[0] # # print(c) # for _ in range(int(input())): # x,y=map(int,input().split()) # a,b=map(int,input().split()) # q=a*(x+y) # p=b*(min(x,y))+a*(abs(x-y)) # print(min(p,q)) # n,k=map(int,input().split()) # a=n//2+n%2 # print(a) # if(k<=a): # print(2*k-1) # else: # print(2*(k-a)) # a,b=map(int,input().split()) # count=0 # if(a>=b): # print(a-b) # else: # while(b>a): # if(b%2==0): # b=int(b/2) # count+=1 # else: # b+=1 # count+=1 # print(count+(a-b)) # n=int(input()) # while n>5: # n = n - 4 # n=(n-((n-4)%2))/2 # # print(n) # if n==1: # print('Sheldon') # if n==2: # print('Leonard') # if n==3: # print('Penny') # if n==4: # print('Rajesh') # if n==5: # print('Howard') # n, m = (int(x) for x in input().split()) # if(n<m): # print(-1) # else: # print((int((n-0.5)/(2*m))+1)*m) # for _ in range(int(input())): # n,k=map(int,input().split()) # print(k//n) # print(k%n) # if((k+(k//n))%n==0): # print(k+(k//n)+1) # else: # print(k+(k//n)) # for i in range(int(input())): # n,k=map(int,input().split()) # print((k-1)//(n-1) +k) # for _ in range(int(input())): # n,k = map(int,input().split()) # if (n >= k*k and n % 2 == k % 2): # print("YES") # else: # print("NO") # for _ in range(int(input())): # n,x=map(int,input().split()) # a=list(map(int,input().split())) # arr=[] # # s=sum([i%2 for i in a]) # for i in a: # j=i%2 # arr.append(j) # s=sum(arr) # # print(s) # if s==0 or (n==x and s%2==0) or (s==n and x%2==0): # print("No") # else: # print("Yes") # a=int(input()) # print(a*(a*a+5)//6) # n,m=map(int,input().split()) # a=[] # k='YES' # for i in range(m): # a.append(list(map(int,input().split()))) # a.sort() # for i in a: # if i[0]<n: # n=n+i[1] # else: # k='NO' # break # print(k) # a=input() # if('1'*7 in a or '0'*7 in a): # print("YES") # else: # print("NO") # s=int(input()) # for i in range(s): # n=int(input()) # if (n//2)%2==1: # print('NO') # else: # print('YES') # for j in range(n//2): # print(2*(j+1)) # for j in range(n//2-1): # print(2*(j+1)-1) # print(n-1+n//2) # k,r=map(int,input().split()) # i=1 # while((k*i)%10)!=0 and ((k*i)%10)!=r: # i=i+1 # print(i) # for _ in range(int(input())): # n,m=map(int,input().split()) # if(abs(n-m)==0): # print(0) # else: # if(abs(n-m)%10==0): # print((abs(n-m)//10)) # else: # print((abs(n-m)//10)+1) # a,b,c=map(int,input().split()) # print(max(a,b,c)-min(a,b,c)) # a=int(input()) # arr=list(map(int,input().split())) # print(a*max(arr)-sum(arr)) # for _ in range(int(input())): # a, b = map(int, input().split()) # if a==b: # print((a+b)**2) # elif max(a,b)%min(a,b)==0: # print(max(a,b)**2) # else: # ans=max(max(a,b),2*min(a,b)) # print(ans**2) # import math # # for _ in range(int(input())): # x=int(input()) # a=list(map(int,input().split())) # for j in range(len(a)): # n=math.sqrt(a[j]) # flag=0 # if(a[j]==1): # print("NO") # elif(n==math.floor(n)): # for i in range(int(n)): # if((6*i)-1==n or ((6*i)+1==n) or n==2 or n==3 or n!=1): # # print("YES") # flag=1 # break # else: # flag=0 # print("YES" if flag==1 else "NO") # else: # print("NO") # print(12339-12345) # for _ in range(int(input())): # x,y,n=map(int,input().split()) # # for i in range((n-x),n): # # # if(i%x==y): # # print(i) # print(n-(n-y)%x) # n=int(input()) # for _ in range(int(input())): # n= int(input()) # print(int(2**(n//2+1)-2)) # for _ in range(int(input())): # n=int(input()) # arr=list(map(int,input().split())) # countod=0 # countev=0 # for i in range(n): # if i%2==0 and arr[i]%2!=0: # countev+=1 # elif i%2!=0 and arr[i]%2==0: # countod+=1 # if countod!=countev: # print(-1) # else: # print(countev) # n,m=map(int,input().split()) # x=m/(n//2) # print(x) # print(int(x*(n-1))) # for _ in range(int(input())): # n,m = map(int,input().split()) # print(m*min(2,n-1)) # n=int(input()) # if(n%2==0): # print(n//2) # print('2 '*(n//2)) # else: # print(((n-2)//2)+1) # print('2 '*(((n-2)//2)) + "3") # for _ in range(int(input())): # n=int(input()) # for i in range(2,30): # if(n%(2**i - 1)==0): # print(n//(2**i - 1)) # break # a,b=map(int,input().split()) # print((a-1)//(b-1)+a) # for _ in range(int(input())): # n=int(input()) # print(n//2) # for _ in range(int(input())): # n=int(input()) # if(n%2==0): # print(n//2) # else: # print((n//2)+1) # for _ in range(int(input())): # a,b = map(int, input().split()) # count = 0 # while(min(a,b) != 0): # x=max(a,b) # y = min(a,b) # a = y # b=x # count += b//a # b = b % a # print(count) # n,k=map(int,input().split()) # a=list(map(int,input().split())) # m=min(a) # c=0 # for i in a: # if (i-m)%k!=0: # print(-1) # break # c+=(i-m)//k # else: # print(c) # a,b = map(int,input().split()) # l = b-(2*a) # if l < a: # print(a-l) # else: # print(0) # for _ in range(int(input())): # n = int(input()) # n2 = 0 # n3 = 0 # while n % 2 == 0: # n2 += 1 # n //= 2 # while n % 3 == 0: # n3 += 1 # n //= 3 # if n != 1 or n2 > n3: # print(-1) # else: # print(2 * n3 - n2) # t=int(input()) # for _ in range(t): # x,n,m=map(int,input().split()) # while x>20 and n>0: # x=x//2+10 # n-=1 # while m>0: # x=x-10 # m-=1 # if x<=0: # print("YES") # else: # print("NO") # for _ in range(int(input())): # print(int(input())) # t=int(input()) # for i in range(t): # n,a,b,c,d=map(int,input().split()) # if (a-b)*n<=c+d and c-d<=(a+b)*n: # print('YES') # else: # print('NO') # for t in range(int(input())): # x, y = map(int, input().split()) # print((x*y+1)//2) # t = int(input()) # for _ in range(t): # a,b=list(map(int,input().split())) # if b==a: # print(0) # if b>a: # print((2-(b-a)%2)) # if b<a: # print((1+(a-b)%2)) # t = int(input()) # for _ in range(t): # a, b, c, n = map(int, input().split()) # # if (a+b+c+n) % 3 == 0 and (((a+b+c+n) // 3) >= max(a, b, c)): # # print("YES") # # else: # # print("NO") # m = max(a,b,c) # d = n-(sum([abs(m-a),abs(b-m),abs(c-m)])) # print("YES" if(d>=0 and d%3==0) else "NO") # for _ in range ( int(input()) ): # x,y,z = sorted (map(int,input().split())) # # print(x,y,z) # if y == z : # print("YES") # print (x,1,z) # else: # print("NO") # n=int(input()) # a=list(map(int,input().split())) # x=sum(a) # y=0 # count=0 # while(y<=x): # y+=max(a) # x=x-max(a) # a.remove(max(a)) # count+=1 # print(count) # s = input() # flag=0 # for x in 'HQ9': # if x in s: # flag=1 # print("YES" if flag==1 else "NO") # import math # n=int(input()) # a=list(map(int,input().split())) # s=sum(a) # print(math.floor(s//4)+1) # from math import ceil # n=int(input()) # s=list(map(int,input().split())) # a=s.count(4) # b=s.count(3) # c=s.count(2) # d=s.count(1) # p=a+b # if d<=b: # p=p+ceil(c/2) # else : # p=p+ceil((d-b+2*c)/4) # print(p) # s=input() # uc=lc=0 # for i in s: # if i.isupper(): # uc+=1 # else: # lc+=1 # # print(uc,lc) # if(lc>=uc): # s=s.lower() # else: # s=s.upper() # print(s) # s=input() # m=input(), # print("YES" if s[::-1]==m else "NO") # a=input() # n=input() # dc=ac=0 # for i in n: # if i=='D': # dc+=1 # else: # ac+=1 # if dc>ac: # print("Danik") # elif(ac>dc): # print("Anton") # else: # print("Friendship") # n=input() # if len(n)==1: # print(n.swapcase()) # else: # if n.isupper(): # print(n.lower()) # else: # if n[1:].isupper(): # print(n.capitalize()) # else: # print(n) # print(*input().split('WUB')) # s={"Tetrahedron":4,"Cube":6,"Octahedron":8,"Dodecahedron":12,"Icosahedron":20} # c=0 # for i in range(int(input())): # c+=s[input()] # print(c) # a=input() # print("YES" if len(set(input().lower())) == 26 else "NO") # for _ in range(int(input())): # n=int(input()) # s=input() # while '()' in s: # s=s.replace('()','') # # print(s) # print(len(s)//2) # m = "hello" # n=input() # j=0 # flag=0 # for i in range(len(n)): # if(n[i]==m[j]): # j=j+1 # if(j==5): # flag=1 # break # if(flag==1): # print("YES") # else: # print("NO") # s=input() # ab=s.count('AB') # ba=s.count('BA') # aba=s.count('ABA') # bab=s.count('BAB') # # print(ab,ba,aba,bab) # if ab+ba-aba-bab>=2 and ab>0 and ba>0: # print('YES') # else: # print('NO') # n,m=map(int,input().split()) # d={} # for i in range(m): # a,b=input().split() # d[a]=b # for x in input().split(): # # print(d[x]) # if len(x)<=len(d[x]) : # print(x,end=" ") # else: # print(d[x],end=" ") # n=int(input()) # List=[] # for i in range(n): # List.append(input()) # List.sort() # print(List[n//2]) # for _ in range(int(input())): # s = input() # if s.count('0') == len(s) or s.count('0') == 0: # print(s) # else : # print("10" * len(s)) # for i in range(int(input())): # S=input() # print("".join(set(S))*len(S)) # t = int(input()) # for _ in range(t): # n = int(input()) # a=list(map(int,input().split())) # for _ in range(int(input())): # n=int(input()) # l=list(map(int,input().split())) # flag=0 # for i in range(n): # if i+2<n: # if l[i] in l[i+2:]: # flag=1 # break # if flag==1: # print('YES') # else: # print('NO') # n=int(input()) # print("codeforces"+"s"*(n-1)) # g=(input()) # h=(input()) # c=(input()) # print("YES" if sorted(g+h)==sorted(c) else "NO") # a,b=map(int,input().split()) # a,b=map(int,input().split()) # i=int(input()) # print((a^i)+(b^i)) # for _ in range(int(input())): # a,b=map(int,input().split()) # print(a^b) # for _ in range(int(input())): # n=input() # count=0 # for i in n: # if(i=="B" and count!=0): # count=count-1 # else: # count=count+1 # print(count) # n=list(input()) # count=0 # for i in range(len(n)): # # print(n[i]) # if(n[i]=='4' or n[i]=='7'): # count+=1 # m=count # # print(m) # if(m==4 or m==7): # print("YES") # else: # print("NO") # count=0 # for _ in range(int(input())): # n,m=map(int,input().split()) # if(abs(n-m)>=2): # count+=1 # print(count) # n,m=map(int,input().split()) # a=map(int,input().split()) # q=0 # p=1 # for i in a: # q+=(i-p)%n;p=i # print(q) # input() # d=[0]*100001 # for x in map(int,input().split()): # d[x]+=x # a=b=0 # for i in d: # a,b=max(a,i+b),a # print(a) # def hanoisum(n): # s=0 # for i in range(1,n+1): # s+= 2**(i-1) # return s # n=int(input()) # print(hanoisum(n)) # def hanoisum(n): # if n==1: # return 1 # return n + hanoisum(2**(n-1)) # x=int(input()) # print(hanoisum(x)) # def hanoi(x,a,b,c): # if(x==1): # print("move 1 from " + a +"to"+c) # return # hanoi(x-1,a,c,b) # print("move" + x + " from "+ a + "to" +c) # hanoi(n-1,b,a,c) # n=int(input()) # print(hanoi(n,A,B,C)) # for i in range(int(input())): # n,k=map(int,input().split()) # a=list(map(int,input().split())) # b=list(map(int,input().split())) # a.sort() # b.sort(reverse=True) # for j in range(k): # if b[j]>a[j]: # a[j],b[j]=b[j],a[j] # print(sum(a)) # n, s = map(int, input().split()) # if(n==1 and s==0): # print('0 0') # elif(9*n < s or s == 0): # print('-1 -1') # else: # x1 = 10**(n-1) # for i in range(s-1): # x1 += 10**(i//9) # x2 = 0 # for i in range(s): # x2 += 10**(n-1-i//9) # print(x1, x2) # n=int(input()) # s=n+1 # while len(set(str(s)))<4: # s+=1 # print(s) # t=int(input()) # for i in range(t): # n=int(input()) # c=list(map(int,input().split())) # o=list(map(int,input().split())) # minc=min(c) # mino=min(o) # ans=0 # for j in range(n): # ans+=max(abs(minc-c[j]),abs(mino-o[j])) # print(ans) # for t in range(int(input())): # n = int(input()) # l = sorted(list(map(int,input().split()))) # a=[] # for i in range(n-1): # x=l[i+1]-l[i] # a.append(x) # print(min(a)) # b=int(input()) # boys=list(map(int,input().split())) # boys.sort() # g=int(input()) # girls=list(map(int,input().split())) # girls.sort() # count=0 # for boy in boys: # for i in range(g): # if abs(boy-girls[i])<=1: # count+=1 # girls[i]=-2 # break # print(count) # for _ in range(int(input())): # a=int(input()) # l=list(map(int,input().split())) # s=[] # for i in l: # if i not in s: # s.append(i) # print(" ".join(str(x)for x in s)) # n,x=map(int,input().split()) # s=input() # for i in range(x): # s=s.replace("BG","GB") # print(s) # n, m = map(int,input().split()) # a = sorted(map(int,input().split())) # x=[] # for i in range(m-n+1): # x.append((a[i+n-1]-a[i])) # print(min(x)) # for i in range(int(input())): # x=int(input()) # print(2) # print(x,x-1) # for i in range(x-2): # print(x,x-2) # x=x-1 # mc=0 # cc=0 # t=int(input()) # for i in range(t): # m,c=map(int,input().split()) # if(m>c): # mc+=1 # elif(m<c): # cc+=1 # if(mc>cc): # print("Mishka") # elif(cc>mc): # print("Chris") # else: # print("Friendship is magic!^^") # n,a,b,c = map(int,input().split()) # a,b,c = sorted([a,b,c])[::-1] # ans = 0 # for i in range(n//a+1): # for j in range(n//b+1): # k = (n-i*a-j*b)//c # if i*a+b*j+k*c==n and k>=0: # ans = max(ans,i+j+k) # break # print(ans) # n=int(input()) # b=input().split() # for i in range(n): # print(b.index(str(i+1))+1,end=" ") # import math # x=int(input()) # next = math.floor(math.log(x)/math.log(2)) # print(next) # y= pow(2,math.ceil(math.log(x)/math.log(2))) # print(next-(x-y)) # n=int(input()) # count=0 # while(n!=0): # if(n%2==1): # count+=1 # n=n//2 # print(count) # t=int(input()) # for _ in range(t): # a,b=map(int,input().split()) # if(a!=0)and(b!=0): # res=(a+b)//3 # else: # res=0 # print(min(res,a,b)) # n=int(input()) # ar=list(map(int,input().split())) # for i in range(0,n): # a=ar[i]%2 # b=ar[(i+1)%n]%2 # c=ar[(i-1)%n]%2 # if(a!=b) and a!=c: # print(i+1) # break # n=int(input()) # arr=list(map(int,input().split())) # arr.sort() # print(*arr) # n,h=map(int,input().split()) # a=list(map(int,input().split())) # count=0 # for i in a: # if i>h: # count+=2 # else: # count+=1 # print(count) # int(input()) # count=1 # cc=1 # a=list(map(int,input().split())) # for i in range(len(a)-1): # if(a[i+1]>=a[i]): # count+=1 # else: # count=1 # cc=max(cc,count) # print(cc) # t=int(input()) # s="" # while t: # s+=input() # t-=1 # one=s.count("11") # zero=s.count("00") # print((one+zero)+1) # n=input() # m=input() # x=[] # for i in range(len(n)) : # if n[i]!=m[i]: # x.append(1) # else: # x.append(0) # print("".join(str(x)for x in x)) # int(input()) # print("HARD" if 1 in list(map(int,input().split())) else "EASY") n = int(input()) print('I hate' + ' that I love that I hate' * ((n-1)// 2)*(n > 2) + ' that I love' * ((n + 1) % 2) +' it')
800
PYTHON3
#include <bits/stdc++.h> using namespace std; const double eps = 1e-14; const int maxn = 2020; int n; long double x[maxn], y[maxn], a[maxn], b[maxn]; int main() { scanf("%d\n", &n); for (int i = 1; i <= n; i++) { double a, b, c; scanf("%lf%lf%lf", &a, &b, &c); double q = a * a + b * b; x[i] = a * c / q; y[i] = b * c / q; } long long ans = 0; for (int i = 1; i <= n; i++) { int m = 0; for (int j = i + 1; j <= n; j++) a[++m] = x[j] - x[i], b[m] = y[j] - y[i]; for (int j = 1; j < m; j++) for (int k = j + 1; k <= m; k++) if (fabs(b[j] * a[k] - a[j] * b[k]) < eps) ans++; } printf("%I64d\n", ans); return 0; }
2,900
CPP
n, k = map(int, input().split()) print(*list(reversed(range(1, k + 2))) + list(range(k + 2, n + 1)))
1,100
PYTHON3
#include <bits/stdc++.h> using namespace std; long long n, x, y, k; vector<long long> V; long long sol[300010]; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> x; V.push_back(x); } for (int i = 0; i < n - 2; i++) { x = max(min(V[i], V[i + 2]), V[i + 1]); k = abs(n - (3 + i * 2)); k = abs(k - 1); sol[k] = max(sol[k], x); } for (int i = 0; i < n - 1; i++) { x = min(V[i], V[i + 1]); k = abs(n - (2 + i * 2)); k = abs(k - 1); sol[k] = max(sol[k], x); } for (int i = 2; i < n; i++) { sol[i] = max(sol[i], sol[i - 2]); } sort(V.begin(), V.end()); for (int i = 0; i < n - 2; i++) { cout << sol[i] << " "; } cout << V.back(); if (n > 1) cout << " " << V.back() << "\n"; }
2,800
CPP
for t in range(int(input())): n=input() l=len(n) n=int(n) s=[] for i in range(l): p=(n%10)*(10**i) n//=10 if p!=0:s.append(p) print(len(s)) print(*s)
800
PYTHON3
def function(a): a1 = a a1 += 1 while a1 % 10 == 0: a1 //= 10 return a1 n = int(input()) array = [n] while True: n = function(n) if not array.count(n): array.append(n) else: break print(len(array))
1,100
PYTHON3
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 5; int h[N], A, R, M, n; long long sum[N], ans = 1e18; long long calc(long long i) { int p = lower_bound(h + 1, h + n + 1, i) - h - 1; long long Sum = i * n, res = 0; if (Sum > sum[n]) { long long w = 1ll * i * p - sum[p] - (Sum - sum[n]); res = w * M + A * (Sum - sum[n]); } else { long long w = (sum[n] - sum[p]) - 1ll * i * (n - p) - (sum[n] - Sum); res = w * M + R * (sum[n] - Sum); } ans = min(ans, res); return res; } int main() { scanf("%d%d%d%d", &n, &A, &R, &M); M = min(M, A + R); for (int i = 1; i <= n; i++) scanf("%d", h + i); sort(h + 1, h + n + 1); for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + h[i]; long long lx = 0, rx = 2e9; for (int i = 1; i <= 1000; i++) { long long x1 = lx + (rx - lx) / 3, x2 = rx - (rx - lx) / 3; if (calc(x1) > calc(x2)) lx = x1; else rx = x2; } printf("%lld\n", ans); return 0; }
2,100
CPP
str= input() querrys= int(input()) lis=[] cont=0 for i in range(0,len(str)-1): if str[i] == str[i+1]: cont+=1 lis.append(cont) lis.insert(0,0) for i in range(querrys): q=(input().split()) l=int(q[0]) r=int(q[1]) print(lis[r-1]-lis[l-1])
1,100
PYTHON3
n, k = map(int, input().split()) def f(val): res = val p = 1 while val // (k ** p) > 0: res += val // (k ** p) p += 1 return res left, right = -1, 10 ** 9 + 1 while left + 1 < right: mid = (left + right) >> 1 if f(mid) >= n: right = mid else: left = mid print(right)
1,500
PYTHON3
s, n = [int(x) for x in input().split()] passable = True dragon_list = [] for i in range(n): dra_str, bonus = [int(x) for x in input().split()] dragon = [dra_str,bonus] dragon_list.append(dragon) dragon_list = sorted(dragon_list, key=lambda dra:dra[0]) #print(dragon_list) for i in dragon_list: if s > int(i[0]): s += int(i[1]) else: passable = False if passable == True: print("YES") else: print("NO")
1,000
PYTHON3
n = int(input()) c = 0 t = -1 for i in range(n): x = int(input()) if t != x: c =c+ 1 t = x print(c)
800
PYTHON3
from collections import defaultdict import math n = int(input().lstrip()) numbers = [] for _ in range(n): numbers.append(list(map(int, input().lstrip().split()))) def gcd(a, b): if not a: return b return gcd(b % a, a) slope_map = defaultdict(set) total = 0 res = 0 for i in range(n): for j in range(i + 1, n): x1, y1 = numbers[i] x2, y2 = numbers[j] a = y1 - y2 b = x1 - x2 d = gcd(a, b) a //= d b //= d if a < 0 or (not a and b < 0): a *= -1 b *= -1 slope = (a, b) c = a * x1 - b * y1 if c not in slope_map[slope]: total += 1 slope_map[slope].add(c) res += total - len(slope_map[slope]) print(res)
1,900
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); string s; cin >> s; string t; cin >> t; reverse(s.begin(), s.end()); if (s == t) { cout << "YES" << endl; } else { cout << "NO" << endl; } return 0; }
800
CPP
from math import gcd t = int(input()) for i in range(t): r,b,k = map(int,input().split()) if r > b: r,b = b,r g = gcd(r,b) r /= g b /= g if (b-2)//r >= k-1: print("REBEL") else: print("OBEY")
1,700
PYTHON3
a,b=map(int,input().split()) c,d=map(int,input().split()) if b==d: print(b) else: if b<d: b+=((d-b)//a)*a for i in range(200): if (b+i*a-d)%c==0: print(b+i*a) break else: print(-1)
1,200
PYTHON3
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() n,a,b,k = Ri() s = ri() cnt = 0 totans = 0; ans = [] for i in range(len(s)): if s[i] == '0': cnt+=1 else: cnt= 0 if cnt == b: if a > 1: a-=1 else: ans.append(i+1) totans+=1 cnt = 0 print(totans) print(*ans)
1,700
PYTHON3
from fractions import gcd a,b,x,y = map(int, input().split()) g = gcd(x, y) x //= g y //= g a = min(a, b * x // y) b = min(b, a * y // x) print(b // y)
1,000
PYTHON3
#include <bits/stdc++.h> using namespace std; int a[100001]; int main() { int n; scanf("%d", &n); string s; cin >> s; int m = s.size(); if (m == 1) { cout << "Yes" << endl; return 0; } for (int i = 0; i < m; i++) { a[s[i]]++; } for (int i = 0; i < 200; i++) { if (a[i] >= 2) { cout << "Yes" << endl; return 0; } } cout << "No" << endl; return 0; }
900
CPP
#include <bits/stdc++.h> using namespace std; int p[105], c[105]; int main() { ios::sync_with_stdio(false); int t; cin >> t; while (t--) { int n; cin >> n; for (int i = 1; i <= n; i++) cin >> p[i] >> c[i]; int f = 1; for (int i = 1; i <= n; i++) { if (c[i] > p[i]) f = 0; if (p[i] < p[i - 1] || c[i] < c[i - 1]) f = 0; if (p[i] - p[i - 1] < c[i] - c[i - 1]) f = 0; } if (f) puts("YES"); else puts("NO"); } return 0; }
1,200
CPP
#include <bits/stdc++.h> const int MAXN = 1e2 + 19; int n, k, a[MAXN]; int main() { int T; std::scanf("%d", &T); while (T--) { std::scanf("%d%d", &n, &k); std::scanf("%d", a + 1); int num = 0; for (int i = 2; i <= n; ++i) { std::scanf("%d", a + i); if (a[i] != a[i - 1]) ++num; } --k; if (num == 0) { std::puts("1"); continue; } if (k == 0) { std::puts("-1"); continue; } std::printf("%d\n", (num + k - 1) / k); } }
1,400
CPP
#include <bits/stdc++.h> int X[3010], Y[3010]; struct SJd { int z, y, i; SJd() {} SJd(int Z, int Y, int I) { z = Z; y = Y; i = I; } }; SJd px[3010]; int cmp(const void* A, const void* B) { SJd a = *(SJd*)A, b = *(SJd*)B; if (a.z != b.z) return b.z - a.z; return b.y - a.y; } int ss[3010], zl[3010][12], zr[3010][12], r, c, ne[3010], la[3010]; void del(int x) { if (la[x] != -1) ne[la[x]] = ne[x]; if (ne[x] != -1) la[ne[x]] = la[x]; } void build() { for (int i = 1; i <= c + 1; i++) la[i] = (ss[i - 1] ? i - 1 : la[i - 1]); for (int i = c; i >= 0; i--) ne[i] = (ss[i + 1] ? i + 1 : ne[i + 1]); la[0] = ne[c + 1] = -1; } int main() { int n, k; long long ans = 0; scanf("%d%d%d%d", &r, &c, &n, &k); for (int i = 0; i < n; i++) scanf("%d%d", &X[i], &Y[i]); ss[0] = ss[c + 1] = 1; for (int l = 1; l <= r; l++) { for (int i = 1; i <= c; i++) ss[i] = 0; int m = 0; for (int i = 0; i < n; i++) { if (X[i] >= l) { px[m] = SJd(X[i], Y[i], m); ss[Y[i]] += 1; m += 1; } } build(); qsort(px, m, sizeof(SJd), cmp); for (int i = 0; i < m; i++) { for (int j = 0; j <= k; j++) zl[i][j] = zr[i][j] = -1; } for (int i = 0; i < m; i++) { int x = px[i].y, h = 0; while (x != -1 && h + ss[x] <= k + 1) { h += ss[x]; int t = x; x = la[x]; if (x != -1) zl[i][h] = t - x; } x = ne[px[i].y]; h = 0; zr[i][h] = x - px[i].y; while (x != -1 && h + ss[x] <= k + 1) { h += ss[x]; int t = x; x = ne[x]; if (x != -1) zr[i][h] = x - t; } ss[x = px[i].y] -= 1; if (ss[x] == 0) del(x); } for (int i = 0; i < m; i++) { int t = r - px[i].z + 1; for (int a = 0; a <= k; a++) { if (zl[i][a] != -1 && zr[i][k - a] != -1) ans += 1ll * t * zl[i][a] * zr[i][k - a]; } } } printf("%lld", ans); return 0; }
3,000
CPP
#include <bits/stdc++.h> #pragma warning(disable : 4996) using namespace std; const int N = 1e7 + 5; int a[N], sum = 0; int x, y; void io() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); } bool jud(int w) { if (w % y == 0) return 1; return 0; } int main() { io(); int T; cin >> T; while (T--) { memset(a, 0, sizeof(a)); sum = 0; cin >> x >> y; int suc = 0; for (int i = 1; i <= x; i++) { cin >> a[i]; sum += a[i]; if (a[i] % y != 0) { suc = 1; } } int l = 1, r = x; if (sum % y != 0) cout << x << endl; else if (!suc) cout << -1 << endl; else { for (int i = 1; i <= x; i++) { if (a[i] % y != 0) { l = i; break; } } for (int i = x; i >= 1; i--) { if (a[i] % y != 0) { r = i; break; } } cout << max(x - l, r - 1) << endl; } } return 0; }
1,200
CPP