solution
stringlengths
10
159k
difficulty
int64
0
3.5k
language
stringclasses
2 values
#include <bits/stdc++.h> using namespace std; const long long N = 1e6 + 50; const long long MOD = 998244353; long long n, x[N], y[N], l[N], r[N], Fac[N << 1], cnt; char s[N]; void Exgcd(long long a, long long b, long long &x, long long &y) { if (b == 0) { x = 1, y = 0; return; } Exgcd(b, a % b, x, y); long long tmpx = y, tmpy = x - a / b * y; x = tmpx, y = tmpy; } long long Inv(long long t) { long long x = 0, y = 0; Exgcd(t, MOD, x, y); return (x + MOD) % MOD; } long long C(long long n, long long m) { if (n - m < 0 || n < 0 || m < 0) return 0; return Fac[n] * Inv(Fac[m]) % MOD * Inv(Fac[n - m]) % MOD; } void Calc() { Fac[0] = 1; for (long long i = 1; i <= n * 2; i++) Fac[i] = Fac[i - 1] * i, Fac[i] %= MOD; } signed main() { scanf("%s", s + 1); n = strlen(s + 1); for (long long i = 1; i <= n; i++) { x[i] = x[i - 1], l[i] = l[i - 1]; if (s[i] == '?') x[i]++; if (s[i] == '(') l[i]++; } for (long long i = n; i >= 1; i--) { r[i] = r[i + 1], y[i] = y[i + 1]; if (s[i] == ')') r[i]++; if (s[i] == '?') y[i]++; } Calc(); long long ans = 0; for (long long i = 1; i <= n; i++) { ans += (l[i] * C(x[i] + y[i + 1], y[i + 1] + r[i + 1] - l[i]) % MOD + x[i] * C(x[i] + y[i + 1] - 1, y[i + 1] + r[i + 1] - l[i] - 1) % MOD) % MOD; ans %= MOD; } printf("%lld\n", ans); return 0; }
2,900
CPP
#include <bits/stdc++.h> using namespace std; int main() { int n, m, x, sum = 0, maxi = -1, max = -101; cin >> n >> m; vector<int> ar(n + 1, 0); for (int i = 1; i <= n; i++) { cin >> ar[i]; if (ar[i] % m == 0) { ar[i]--; } if (max <= (ar[i] / m)) { maxi = i; max = ar[i] / m; } } cout << maxi; }
1,000
CPP
test_cases = int(input()) for z in range(test_cases): n,x=list(map(int,input().split())) a=list(map(int,input().split())) count=0 sum=0 index=[] for i in range(len(a)): sum+=a[i] if a[i]%x==0: count+=1 else: index.append(i+1) if sum%x!=0: print(n) elif count==n: print(-1) else: d=min(index[0],n-index[-1]+1) print(n-d)
1,200
PYTHON3
#include <bits/stdc++.h> const int N = 5 + 1e5; int a[N], b[N], n, m; using namespace std; long long calcA(int v) { long long s = 0; int i; for (i = 0; i < n; ++i) if (a[i] < v) s += v - a[i]; return s; } long long calcB(int v) { long long s = 0; int i; for (i = 0; i < m; ++i) if (b[i] > v) s += b[i] - v; return s; } int main() { ios::sync_with_stdio(0); int i; long long n1 = 0, m1 = 0, n2, m2; cin >> n >> m; for (i = 0; i < n; ++i) cin >> a[i]; for (i = 0; i < m; ++i) cin >> b[i]; sort(a, a + n); sort(b, b + m); if (a[0] >= b[m - 1]) { cout << 0; return 0; } int l = a[0], r = b[m - 1], mid; while (l < r) { mid = (l + r) / 2; n1 = calcA(mid); m1 = calcB(mid); n2 = calcA(mid + 1); m2 = calcB(mid + 1); if (n1 + m1 < n2 + m2) r = mid; else l = mid + 1; } n1 = calcA(l); m1 = calcB(l); n2 = calcA(r); m2 = calcB(r); cout << min(n1 + m1, n2 + m2); }
1,700
CPP
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); void c_p_c() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } double pi = 3.141592653589; void solve() { long long n; cin >> n; long long a[n]; for (long long &i : a) cin >> i; if (a[0] + a[1] <= a[n - 1]) { cout << 1 << " " << 2 << " " << n << "\n"; return; } cout << -1 << "\n"; } int32_t main() { long long x; cin >> x; while (x--) solve(); return 0; }
800
CPP
n, t = map(int, input().split()) A = [] for i in range(n): s, d = map(int, input().split()) if s >= t: A.append(s - t) else: A.append((d - (t - s) % d) % d) print(A.index(min(A)) + 1)
1,000
PYTHON3
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); struct P { double first, second; P() {} P(double first, double second) : first(first), second(second) {} bool operator<(const P &p) const { return ((first) < (p.first) - 1e-9) || ((fabs(first - p.first) < 1e-9) && ((second) < (p.second) - 1e-9)); } double operator^(const P &p) const { return first * p.second - second * p.first; } P operator-(const P &p) const { return P(first - p.first, second - p.second); } P operator+(const P &p) const { return P(first + p.first, second + p.second); } P operator*(double u) const { return P(first * u, second * u); } double operator*(const P &p) const { return first * p.first + second * p.second; } double len() { return sqrt(((first) * (first)) + ((second) * (second))); } void eat() { scanf("%lf%lf", &first, &second); } P nor() { if ((fabs(len() - 0) < 1e-9)) return *this; return *this * (1. / len()); } P rot(double the) { return P(first * cos(the) - second * sin(the), first * sin(the) + second * cos(the)); } }; P a, b, w1, w2, m1, m2; P ra, rb, rw1, rw2; P reflect(P p) { P ret; double first = ((m2 - m1) ^ (p - m1)) / (m2 - m1).len(); if (first == 0) return p; p = p - m1; P n = (m2 - m1).nor(); if ((((n ^ p)) < (0) - 1e-9)) { n = n.rot(pi / 2); } else n = n.rot(-(pi / 2)); n = n * (2 * fabs(first)); return ret = p + n + m1; } bool inter(P a, P b, P c, P d) { double s, t; P ab = b - a, cd = d - c; if ((fabs(0 - (ab ^ cd)) < 1e-9)) { if ((fabs((c - a).len() + ((b - c).len()) - (b - a).len()) < 1e-9)) return true; return false; } s = ((cd ^ c) - (cd ^ a)) / (cd ^ ab); t = ((ab ^ a) - (ab ^ c)) / (ab ^ cd); if (((s) > (0) - 1e-9) && ((s) < (1) + 1e-9) && ((t) > (0) - 1e-9) && ((t) < (1) + 1e-9)) return 1; return 0; } int main() { a.eat(); b.eat(); w1.eat(); w2.eat(); m1.eat(), m2.eat(); ra = reflect(a); rb = reflect(b); rw1 = reflect(w1); rw2 = reflect(w2); if (!inter(a, b, m1, m2) && !inter(a, b, w1, w2)) { printf("YES\n"); return 0; } if (inter(a, rb, m1, m2) && !inter(a, rb, rw1, rw2) && inter(b, ra, m1, m2) && !(inter(b, ra, rw1, rw2))) { printf("YES\n"); return 0; } printf("NO\n"); return 0; }
2,400
CPP
#include <bits/stdc++.h> using namespace std; vector<int> cc[200005]; bool vis[200005]; vector<int> gr[200005]; void dfs(int x, int i) { vis[x] = true; cc[i].push_back(x); for (auto ed : gr[x]) { if (vis[ed] == false) dfs(ed, i); } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int n, m, a, b; cin >> n >> m; for (long long int i = 0; i < m; i++) { cin >> a >> b; gr[a].push_back(b); gr[b].push_back(a); } memset(vis, false, sizeof(vis)); int cnt = 0; for (int i = 1; i <= n; i++) { if (vis[i] == false) { dfs(i, cnt); cnt++; } } int ans = 0; for (int i = 0; i <= n; i++) { int f = 1; for (int j = 0; j < cc[i].size(); j++) { if (gr[cc[i][j]].size() != 2) { f = 0; break; } } if (cc[i].size() >= 3 && f == 1) ans++; } cout << ans; }
1,500
CPP
#include <bits/stdc++.h> using namespace std; struct node { int x, y, st; node(int a = 0, int b = 0, int c = 0) : x(a), y(b), st(c) {} } S; char mp[21][21]; int V[8][2], cnt; int number[8], value[8]; int f[21][21][1 << 8], step[4][2] = {1, 0, -1, 0, 0, 1, 0, -1}; int n, m; bool valid(int x, int y) { return 0 <= x && x < n && 0 <= y && y < m && (mp[x][y] == '.' || mp[x][y] == 'S'); } int get(int x, int y, int nowy, int ST) { for (int i = 0; i < cnt; i++) if (x > V[i][0] && ((y == V[i][1] && nowy == V[i][1] + 1) || (nowy == V[i][1] && y == V[i][1] + 1))) ST ^= 1 << i; return ST; } int BFS() { memset(f, -1, sizeof(f)); queue<node> q; q.push(S); f[S.x][S.y][0] = 0; while (!q.empty()) { node u = q.front(); q.pop(); for (int i = 0; i < 4; i++) { node v = u; v.x += step[i][0], v.y += step[i][1]; if (!valid(v.x, v.y)) continue; v.st = get(v.x, v.y, u.y, u.st); if (f[v.x][v.y][v.st] != -1) continue; f[v.x][v.y][v.st] = f[u.x][u.y][u.st] + 1; q.push(v); } } int ans = 0; for (int i = 0; i < (1 << cnt); i++) if (f[S.x][S.y][i] != -1) { bool bomb = false; int sum = 0; for (int j = 0; j < cnt; j++) if (i & (1 << j)) { if (number[j] == -1) { bomb = true; break; } sum += value[number[j]]; } if (bomb) continue; ans = max(ans, sum - f[S.x][S.y][i]); } return ans; } void init() { cnt = 0; memset(number, -1, sizeof(number)); for (int i = 0; i < n; i++) { scanf("%s", mp[i]); for (int j = 0; j < m; j++) if (mp[i][j] == 'B') { V[cnt][0] = i; V[cnt++][1] = j; } else if ('1' <= mp[i][j] && mp[i][j] <= '8') { V[cnt][0] = i; V[cnt][1] = j; number[cnt++] = mp[i][j] - '1'; } else if (mp[i][j] == 'S') { S.x = i, S.y = j; S.st = 0; } } for (int i = 0; i < cnt; i++) scanf("%d", &value[i]); } int main() { int i, j; while (~scanf("%d %d", &n, &m)) { init(); printf("%d\n", BFS()); } return 0; }
2,600
CPP
#include <bits/stdc++.h> using namespace std; long long a, b, c, d; map<long long, long long> m, m2; queue<long long> q; vector<long long> ans[10000]; long long disp(long long x, long long st) { long long y = x, tmp = a * b; long long cnt2, cnt3, cnt2x, cnt3x; cnt2 = 0; cnt3 = 0; cnt2x = 0; cnt3x = 0; while (tmp % 2 == 0) { tmp /= 2; cnt2++; } while (tmp % 3 == 0) { tmp /= 3; cnt3++; } while (x % 2 == 0) { x /= 2; cnt2x++; } while (x % 3 == 0) { x /= 3; cnt3x++; } x = cnt3 - cnt3x; y = m[y] - x; long long i; for (i = 1; i <= x; i++) { if (a % 3 == 0) { a /= 3; a *= 2; } else { b /= 3; b *= 2; } } for (i = 1; i <= y; i++) { if (a % 2 == 0) { a /= 2; } else { b /= 2; } } cout << a << " " << b << endl; } long long disp2(long long x, long long st) { swap(a, c); swap(b, d); long long y = x, tmp = a * b; long long cnt2, cnt3, cnt2x, cnt3x; cnt2 = 0; cnt3 = 0; cnt2x = 0; cnt3x = 0; while (tmp % 2 == 0) { tmp /= 2; cnt2++; } while (tmp % 3 == 0) { tmp /= 3; cnt3++; } while (x % 2 == 0) { x /= 2; cnt2x++; } while (x % 3 == 0) { x /= 3; cnt3x++; } x = cnt3 - cnt3x; y = m2[y] - x; long long i; for (i = 1; i <= x; i++) { if (a % 3 == 0) { a /= 3; a *= 2; } else { b /= 3; b *= 2; } } for (i = 1; i <= y; i++) { if (a % 2 == 0) { a /= 2; } else { b /= 2; } } cout << a << " " << b << endl; } long long solve() { cin >> a >> b >> c >> d; long long x; x = a * b; m[x] = 0; q.push(x); while (!q.empty()) { x = q.front(); if (x % 2 == 0 && m.find(x / 2) == m.end()) { m[x / 2] = m[x] + 1; q.push(x / 2); } if (x % 3 == 0 && m.find((x / 3) * 2) == m.end()) { m[(x / 3) * 2] = m[x] + 1; q.push((x / 3) * 2); } q.pop(); } x = c * d; m2[x] = 0; q.push(x); while (!q.empty()) { x = q.front(); if (x % 2 == 0 && m2.find(x / 2) == m2.end()) { q.push((x / 2)); m2[x / 2] = m2[x] + 1; } if (x % 3 == 0 && m2.find((x / 3) * 2) == m2.end()) { m2[(x / 3) * 2] = m2[x] + 1; q.push((x / 3) * 2); } if (m.find(x) != m.end()) { ans[m[x] + m2[x]].push_back(x); } q.pop(); } long long i; for (i = 0; i <= 1800; i++) { if (ans[i].size() > 0) { cout << i << endl; disp(ans[i][0], i); disp2(ans[i][0], i); return 0; } } cout << -1 << endl; return 0; } int main() { long long t = 1; while (t--) { solve(); } }
1,900
CPP
a, b, r = [int(i) for i in input().split()] print('First' if a >= 2 * r and b >= 2 * r else 'Second')
1,600
PYTHON3
#include <bits/stdc++.h> using namespace std; long long t; int T, n, m, d, p[210000]; int ok(int d) { long long tt = 0, k = 0; int mm = 0; for (int i = 1; i <= n; i++) { if (p[i] > d) continue; mm++; tt += p[i]; if (mm == m + 1) { mm = 1; tt += k; k = 0; } k += p[i]; if (tt > t) return 0; } return 1; } int calc(int d) { long long tt = 0, k = 0; int mm = 0, ret = 0; for (int i = 1; i <= n; i++) { if (p[i] > d) continue; mm++; tt += p[i]; ret++; if (mm == m + 1) { mm = 1; tt += k; k = 0; } k += p[i]; if (tt > t) return ret - 1; } return ret; } int main() { scanf("%d", &T); while (T--) { scanf("%d%d%lld", &n, &m, &t); for (int i = 1; i <= n; i++) scanf("%d", &p[i]); int l = 1, r = min(t, 1ll * 200000); while (l != r) { int mid = (l + r + 1) / 2; if (ok(mid)) l = mid; else r = mid - 1; } int u = calc(l), v = calc(l + 1); if (l + 1 > t) v = -1; if (u > v) printf("%d %d\n", u, l); else printf("%d %d\n", v, l + 1); } return 0; }
2,100
CPP
#include <bits/stdc++.h> using namespace std; int arr[11111]; int out[11111]; int temp[11111]; int main() { int n, k; scanf("%d %d", &n, &k); for (int i = (1); i < (n); ++i) arr[i] = 1; arr[n] = 0; int qtd = 0; int ct = 5; while (arr[1] != n - 1) { memcpy(temp, arr, sizeof arr); out[qtd++] = n; int j = n - 1; int qt = 0; while (j >= 1 && arr[j] == n - j) { j--; qt++; out[qtd++] = n; } int act = qt; while (j >= 1 && qt) { arr[j] += temp[j + act]; out[qtd++] = j + act; j--; qt--; } while (j >= 1) { arr[j] += temp[j + 1]; out[qtd++] = j + 1; j--; } for (int i = qtd - 1; i >= 0; --i) printf("%d ", out[i]); printf("\n"); k--; qtd = 0; ct--; } while (k--) { for (int i = (0); i < (n); ++i) printf("%d ", n); printf("\n"); } return 0; }
1,600
CPP
#include <bits/stdc++.h> using namespace std; long long cat[100005]; long long dp[2][100005]; long long d[100005]; long long sum[100005]; long long s[100005]; int main() { int n, m, p; while (scanf("%d %d %d", &n, &m, &p) != EOF) { d[1] = 0; int u; for (int i = 2; i <= n; i++) { scanf("%d", &u); d[i] = d[i - 1] + u; } long long tmp2; int tmp; sum[0] = 0; for (int i = 1; i <= m; i++) { scanf("%d %I64d", &tmp, &tmp2); cat[i] = tmp2 - d[tmp]; sum[i] = sum[i - 1] + cat[i]; } cat[0] = 0; sort(cat + 1, cat + m + 1); for (int i = 0; i <= m; i++) dp[1][i] = cat[i] * i - sum[i]; int now, pre; int top; for (int i = 0; i < p - 1; i++) { top = 0; if ((i & 1) == 0) { now = 0; pre = 1; } else { now = 1; pre = 0; } s[++top] = 1; s[++top] = 2; int j = 3; while (j <= m) { while (top > 1 && ((sum[j] + dp[pre][j]) - (sum[s[top]] + dp[pre][s[top]])) * (s[top] - s[top - 1]) < ((sum[s[top]] + dp[pre][s[top]]) - (sum[s[top - 1]] + dp[pre][s[top - 1]])) * (j - s[top])) top--; s[++top] = j; j++; } dp[now][1] = 0; int ptr = 1; for (j = 2; j <= m; j++) { while (ptr < top && ((sum[s[ptr + 1]] + dp[pre][s[ptr + 1]]) - (sum[s[ptr]] + dp[pre][s[ptr]])) < cat[j] * (s[ptr + 1] - s[ptr])) ptr++; dp[now][j] = dp[pre][s[ptr]] + cat[j] * (j - s[ptr]) - (sum[j] - sum[s[ptr]]); } } if (p % 2 == 1) now = 1; else now = 0; printf("%I64d\n", dp[now][m]); } return 0; }
2,400
CPP
#include <bits/stdc++.h> using namespace std; int read() { int s = 0, w = 1; char c; while (c = getchar(), c > '9' || c < '0') if (c == '-') w = -1; while (c >= '0' && c <= '9') s = s * 10 + c - '0', c = getchar(); return w * s; } const int N = 2e5 + 7; struct edge { int t, next; } e[N << 1]; int n, m, q, cnt, num; int head[N], u[N], v[N]; void add(int u, int t) { e[cnt].t = t; e[cnt].next = head[u]; head[u] = cnt++; e[cnt].t = u; e[cnt].next = head[t]; head[t] = cnt++; } int tp, t, now; int low[N], dfn[N], st[N], ins[N], vis[N], bl[N], kin[N]; void Tarjan(int u, int fa) { low[u] = dfn[u] = ++t; st[++tp] = u; for (int i = head[u]; i != -1; i = e[i].next) { int v = e[i].t; if ((i ^ 1) == fa) continue; if (!dfn[v]) { Tarjan(v, i); low[u] = min(low[u], low[v]); } else if (!bl[v]) low[u] = min(low[u], dfn[v]); } if (low[u] == dfn[u]) { now++; kin[now] = num; int v; do { v = st[tp--]; bl[v] = now; } while (v != u); } } int dee[N], fa[N][25], up[N], down[N]; void dfs(int u, int f) { ins[u] = 1; fa[u][0] = f; dee[u] = dee[f] + 1; for (int i = head[u]; i != -1; i = e[i].next) { int v = e[i].t; if (!ins[v]) dfs(v, u); } } void findfa() { for (int i = 1; i <= 20; i++) for (int j = 1; j <= now; j++) fa[j][i] = fa[fa[j][i - 1]][i - 1]; } int lca(int a, int b) { if (dee[b] < dee[a]) swap(a, b); for (int i = 20; i >= 0; i--) if (dee[fa[b][i]] >= dee[a]) b = fa[b][i]; if (a == b) return a; for (int i = 20; i >= 0; i--) { if (fa[a][i] != fa[b][i]) a = fa[a][i], b = fa[b][i]; } return fa[a][0]; } void dfs1(int u) { ins[u] = 1; for (int i = head[u]; i != -1; i = e[i].next) { int v = e[i].t; if (!ins[v]) { dfs1(v); up[u] += up[v]; down[u] += down[v]; } } } int main() { memset(head, -1, sizeof head); n = read(); m = read(); q = read(); for (int i = 1; i <= m; i++) { u[i] = read(); v[i] = read(); add(u[i], v[i]); } for (int i = 1; i <= n; i++) if (!dfn[i]) num++, Tarjan(i, -1); memset(head, -1, sizeof head); cnt = 0; for (int i = 1; i <= m; i++) if (bl[u[i]] != bl[v[i]]) add(bl[u[i]], bl[v[i]]); for (int i = 1; i <= now; i++) if (!ins[i]) dfs(i, 0); findfa(); for (int i = 1, a, b; i <= q; i++) { a = bl[read()], b = bl[read()]; if (kin[a] != kin[b]) return puts("No"), 0; if (a == b) continue; int c = lca(a, b); up[c]--; down[c]--; up[a]++; down[b]++; } memset(ins, 0, sizeof ins); for (int i = 1; i <= now; i++) if (!ins[i]) dfs1(i); for (int i = 1; i <= now; i++) if (up[i] && down[i]) return puts("No"), 0; return puts("Yes"), 0; }
2,800
CPP
num = int(input()) res = 0 for i in range(num): q = input().split(' ') z = 0 for j in q: if j == '0': z += 1 if z < 2: res += 1 print(res)
800
PYTHON3
#include <bits/stdc++.h> using namespace std; void test_case() { int n, m; cin >> n >> m; int pety = min(n, m); int vasy = n + m - 1 - pety; cout << vasy << " " << pety; } int32_t main() { std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); int T = 1; while (T-- > 0) { test_case(); } return 0; }
1,300
CPP
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { if (b) { return gcd(b, a % b); } return a; } long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } struct RangeTree { private: vector<long long> b; int kk; public: RangeTree(const vector<int>& v) { int n = int(v.size()); kk = 1; while (kk < n) { kk *= 2; } b.resize(2 * kk + 10, 1); for (int i = 0; i < n; ++i) { b[i + kk] = v[i]; } for (int i = kk - 1; i >= 1; --i) { b[i] = lcm(b[2 * i], b[2 * i + 1]); } } long long getLCM(int L, int R) { ; L += kk; R += kk; long long res = 1; while (L <= R) { if (L % 2 == 1) { res = lcm(res, b[L++]); } if (R % 2 == 0) { res = lcm(res, b[R--]); } L /= 2, R /= 2; }; return res; } }; long long sum(long long x, long long y, long long MOD) { if ((x += y) >= MOD) { x -= MOD; } return x; } long long product(long long x, long long y, long long MOD) { long long res = 0; while (y) { if (y & 1) { res = sum(res, x, MOD); } x = sum(x, x, MOD); y /= 2; } return res; } long long inverse(long long x, long long MOD) { long long a = x; long long b = MOD; long long p = 1, q = 0; long long r = 0, s = 1; while (a && b) { if (a >= b) { long long k = a / b; a %= b; p -= r * k; q -= s * k; } else { long long k = b / a; b %= a; r -= p * k; s -= q * k; } } long long res; if (a) { assert(a == 1); res = p; } else { assert(b == 1); res = r; } res %= MOD; if (res < 0) { res += MOD; }; assert(product(res, x, MOD) == 1); return res; } bool canExpand(long long& totMod, long long& totRem, long long newMod, long long newRem) { ; long long D = gcd(totMod, newMod); if (totRem % D != newRem % D) { ; return false; } long long mod1 = totMod; long long rem1 = totRem; long long mod2 = newMod; long long rem2 = newRem; if (mod1 == D) { totMod = mod2; totRem = rem2; } else if (mod2 == D) { totMod = mod1; totRem = rem1; } else { long long b = mod1 / D; long long c = mod2 / D; long long r = ((rem2 - rem1) / D) % c; if (r < 0) { r += c; } long long k = product(inverse(b, c), r, c); totRem = k * mod1 + rem1; totMod = b * c * D; } return true; } int main() { int n, m; scanf("%d%d", &n, &m); vector<vector<pair<int, int> > > pos(m); vector<int> k(n); for (int i = 0; i < n; ++i) { scanf("%d", &k[i]); for (int j = 0; j < k[i]; ++j) { int a; scanf("%d", &a); --a; pos[a].push_back(pair<int, int>(i, j)); } } RangeTree tree(k); vector<int> res(m, 0); for (int i = 0; i < m; ++i) { int L = -2, R = -2; long long totMod = 1, totRem = 0; for (int j = 0; j < (int)pos[i].size(); ++j) { int curPos = pos[i][j].first; long long curRem = pos[i][j].second; long long curMod = k[curPos]; if (R + 1 < pos[i][j].first) { L = R = curPos; totMod = curMod; totRem = curRem; } else { while (!canExpand(totMod, totRem, curMod, curRem)) { ++L; totMod = tree.getLCM(L, R); totRem %= totMod; } ++R; } res[i] = max(res[i], R - L + 1); } } for (int i = 0; i < m; ++i) { printf("%d\n", res[i]); } return 0; }
2,800
CPP
n,h = map(int,input().split()) a = [int(s) for s in input().split()] count = n for i in a: if i > h: count += 1 print(count)
800
PYTHON3
#include <bits/stdc++.h> using namespace std; const int N = 4e5 + 5, M = 1 << 15; const double pi = acos(-1); template <class o> inline void qr(o &x) { char c = getchar(); int f = 1; x = 0; while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); } while (c >= '0' && c <= '9') { x = x * 10 + (c ^ 48); c = getchar(); } x *= f; } template <class o> inline void qw(o x) { if (x < 0) x = -x, putchar('-'); if (x / 10) qw(x / 10); putchar(x % 10 + 48); } struct cp { double x, y; cp(double x = 0.0, double y = 0.0) : x(x), y(y) {} inline cp operator+(const cp &a) const { return cp(x + a.x, y + a.y); } inline cp operator-(const cp &a) const { return cp(x - a.x, y - a.y); } inline cp operator*(const cp &a) const { return cp(x * a.x - y * a.y, a.x * y + x * a.y); } inline cp operator+(const double &a) const { return cp(x + a, y + a); } inline cp operator-(const double &a) const { return cp(x - a, y - a); } inline cp operator*(const double &a) const { return cp(x * a, y * a); } inline cp operator/(const double &a) const { return cp(x / a, y / a); } } w[N << 1]; int tr[N << 1], cnt, mod; inline void rev(int n) { if (cnt == n) return; cnt = n; for (int i = 0; i < n; i++) tr[i] = (tr[i >> 1] >> 1 | ((i & 1) ? n >> 1 : 0)); } inline void Init(int n) { for (int i = 1; i < n; i <<= 1) { w[i] = cp(1, 0); for (int j = 1; j < i; j++) w[i + j] = (((j & 31) == 1) ? cp(cos(pi * j / i), sin(pi * j / i)) : w[i + j - 1] * w[i + 1]); } } void dft(cp *g, bool op, int n) { rev(n); static cp f[N << 1], t; for (int i = 0; i < n; i++) f[i] = g[tr[i]]; for (int p = 2, l = 1; p <= n; l = p, p <<= 1) for (int i = 0; i < n; i += p) for (int j = 0; j < l; j++) t = w[j | l] * f[i | j | l], f[i | j | l] = f[i | j] - t, f[i | j] = f[i | j] + t; if (op) for (int i = 0; i < n; i++) g[i] = f[i] / n; else for (int i = 0; i < n; i++) g[i] = f[i]; } inline void px(cp *f, cp *g, int n) { for (int i = 0; i < n; i++) f[i] = f[i] * g[i]; } inline long long num(double x) { return x < 0 ? (long long)(x - 0.49) % mod : (long long)(x + 0.49) % mod; } cp p[N << 1], q[N << 1]; void mtt(int *f, int *g, int m) { int n = 1; for (; n < (m << 1); n <<= 1) ; for (int i = 0; i < m; i++) p[i] = cp(f[i], 0), q[i] = cp(g[i], 0); for (int i = m; i < n; i++) p[i] = q[i] = cp(0, 0); dft(p, 0, n); dft(q, 0, n); px(p, q, n); reverse(p + 1, p + n); dft(p, 1, n); for (int i = 0; i < m; i++) f[i] = (num(p[i].x) + mod) % mod; } int f[2][N << 1]; void add(int p, int m) { for (int i = m; i; i--) f[p][i] = (f[p][i] + f[0][i - 1] + f[1][i - 1]) % mod; f[p][1] = (f[p][1] + 1) % mod; } int g[2][N << 1], n; void mul(int p, int m) { for (int i = 0; i < 2; i++) for (int j = 1; j < m; j++) g[i][j] = (f[0][j] + f[1][j]) % mod; g[0][0] = g[1][0] = 1; mtt(g[0], f[p], m); mtt(g[1], f[p ^ 1], m); for (int i = 0; i < 2; i++) for (int j = 1; j < m; j++) f[i][j] = (g[i][j] + f[i][j]) % mod; memset(g[0], 0, sizeof(int) * (n)), memset(g[1], 0, sizeof(int) * (n)); } int main() { int mx, lg = 0, j = 0; qr(n), qr(mx); qr(mod); mx /= 2; if (mx) lg = log2(mx); long long ans = 0; int m = n + 1; for (n = 1; n < (m << 1); n <<= 1) ; Init(n); for (int i = lg; ~i; i--) { mul(j & 1, m); j <<= 1; if (mx & (1 << i)) add((j | 1) & 1, m), j |= 1; for (int k = 1; k < m; k++) if (k & 1) ans += f[1][k]; ans %= mod; } qw(ans); puts(""); return 0; }
3,400
CPP
#include <bits/stdc++.h> using namespace std; multiset<long long> g; int const N = 100005; long long a[N * 2], b[N * 2]; long long sa[N * 2], sb[N * 2]; bool vis[N]; void calc(int n, int flag) { int nn = n + n; for (int i = 1; i <= nn; i++) { sa[i] = a[i] + sa[i - 1]; sb[i] = b[i] + sb[i - 1]; } g.clear(); g.insert(0); for (int i = 2; i <= n; i++) { g.insert(sa[i - 1] - sb[i - 1]); } if ((*(g.begin())) >= 0) { if (flag == 0) vis[1] = true; else vis[n] = true; } long long sum = 0; for (int i = 2; i <= n; i++) { g.erase(g.find(a[i - 1] - b[i - 1] - sum)); sum -= (a[i - 1] - b[i - 1]); g.insert(-sum); if ((*(g.begin())) + sum >= 0) { if (flag == 0) vis[i] = true; else vis[n - i + 1] = true; } } } int main() { int n; while (~scanf("%d", &n)) { for (int i = 1; i <= n; i++) { vis[i] = false; } for (int i = 1; i <= n; i++) { scanf("%I64d", &a[i]); a[i + n] = a[i]; } for (int i = 1; i <= n; i++) { scanf("%I64d", &b[i]); b[n + i] = b[i]; } calc(n, 0); reverse(a + 1, a + n + 1); reverse(b + 1, b + n); for (int i = 1; i <= n; i++) a[n + i] = a[i]; for (int i = 1; i <= n; i++) b[n + i] = b[i]; calc(n, 1); int ans = 0; for (int i = 1; i <= n; i++) if (vis[i]) ans++; printf("%d\n", ans); for (int i = 1; i <= n; i++) if (vis[i]) printf("%d ", i); } }
2,000
CPP
#include <bits/stdc++.h> using namespace std; long long deg(long long n) { long long c = 0; while (n) { c += n % 10; n /= 10; } return c; } int main() { long long n; cin >> n; for (int i = 1; i < 100; i++) { long long m = i * i + 4 * n; long long y = sqrt(m); if (y * y == m) { long long x1 = (-i + y) / 2, x2 = (-i - y) / 2; if (x1 > 0) { if (i == deg(x1)) { cout << x1; return 0; } } if (x2 > 0) { if (i == deg(x2)) { cout << x2; return 0; } } } } cout << -1; return 0; }
1,400
CPP
#include <bits/stdc++.h> using namespace std; struct edge { int to, next; } e[1000004]; int h[300004], ne = 0, cnt = 0; int n, r, p, a[300004], belong[300004], low[300004], dfn[300004], SCC; int val[300004]; bool inq[300004]; stack<int> ST; long long temp = 0; long long ans = 1; void insert(int u, int v) { e[++ne].to = v; e[ne].next = h[u]; h[u] = ne; } void tarjan(int x) { inq[x] = 1; dfn[x] = low[x] = ++cnt; ST.push(x); for (int i = h[x]; i; i = e[i].next) { if (!dfn[e[i].to]) { tarjan(e[i].to); low[x] = min(low[x], low[e[i].to]); } else if (inq[e[i].to]) low[x] = min(low[x], dfn[e[i].to]); } if (low[x] == dfn[x]) { SCC++; int now = -1; while (now != x) { now = ST.top(); ST.pop(); belong[now] = SCC; inq[now] = 0; val[SCC]++; } } } int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { int x; scanf("%d", &x); insert(i, x); } for (int i = 1; i <= n; i++) if (!dfn[i]) tarjan(i); int rest = n; for (int i = 1; i <= SCC; i++) { if (val[i] == 1) continue; rest -= val[i]; temp = 1; for (int k = 1; k <= val[i]; k++) temp = (temp + temp) % 1000000007LL; temp = (temp - 2LL + 1000000007LL) % 1000000007LL; ans = (ans * temp) % 1000000007LL; } temp = 1; for (int k = 1; k <= rest; k++) temp = (temp + temp) % 1000000007LL; ans = (ans * temp) % 1000000007LL; printf("%I64d\n", ans); return 0; }
1,900
CPP
s=input().split("+") s.sort() for i in range(len(s)): if i+1!=len(s): print(s[i]+"+",sep="",end="") else: print(s[i],sep="",end="")
800
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a(n); vector<pair<int, int>> ps(n); for (int i = 0; i < n; i++) { cin >> a[i]; ps[i] = make_pair(a[i], i); } sort(ps.begin(), ps.end(), [](pair<int, int>& a, pair<int, int>& b) { if (a.first == b.first) { return a.second < b.second; } return a.first > b.first; }); int m; cin >> m; for (int query = 0; query < m; query++) { int k, pos; cin >> k >> pos; priority_queue<int> q; for (int i = 0; i < k; i++) { q.push(ps[i].second); if (i >= pos) { q.pop(); } } cout << a[q.top()] << endl; } return 0; }
1,600
CPP
n = int(input()) inp = input() d = {'z': 0, 'n': 0} for i in inp: if (i in ('z', 'n')): d[i] += 1 res = '1' * d['n'] + '0' * d['z'] for i in res: print(i, end=' ')
800
PYTHON3
for t in range(int(input())): n,k=list(map(int,input().split())) prk=(k//(n-1)) mrk=(prk*n) if (mrk-prk)==k: print(mrk-1) else: print(mrk+(k%(n-1)))
1,200
PYTHON3
pada_malo=int(input())-1 while pada_malo>4: pada_malo=(pada_malo-5)//2 print(["Sheldon","Leonard","Penny","Rajesh","Howard"][pada_malo])
1,100
PYTHON3
#include <bits/stdc++.h> using namespace std; const int mod = 1000 * 1000 * 1000 + 7; const int INF = 1000 * 1000 * 1000; const long long LINF = (long long)INF * INF; int n, k, a, b, q; int fen1[200100], fen2[200100]; void add(int *fen, int i, int x) { for (i++; i <= n; i += i & -i) { fen[i] += x; } } long long sum(int *fen, int r) { long long res = 0; for (r++; r > 0; r -= r & -r) { res += fen[r]; } return res; } long long sum(int *fen, int l, int r) { return sum(fen, r) - sum(fen, l - 1); } int32_t main(void) { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; cin >> n >> k >> a >> b >> q; while (q--) { int op; cin >> op; if (op == 1) { int di, ai; cin >> di >> ai; di--; long long x1 = sum(fen1, di, di); long long x2 = sum(fen2, di, di); if (x1 + ai > a) { add(fen1, di, a - x1); } else { add(fen1, di, ai); } if (x2 + ai > b) { add(fen2, di, b - x2); } else { add(fen2, di, ai); } } else { int pi; cin >> pi; pi--; cout << sum(fen2, 0, pi - 1) + sum(fen1, pi + k, n - 1) << '\n'; } } return 0; }
1,700
CPP
#include <bits/stdc++.h> using namespace std; string s; int T; int main() { cin >> T; while (T--) { cin >> s; int flag1, flag2, flag3; flag1 = flag2 = flag3 = 0; for (int i = 0; i < s.length(); i++) { if (s[i] >= 'a' && s[i] <= 'z') flag1++; if (s[i] >= 'A' && s[i] <= 'Z') flag2++; if (s[i] >= '0' && s[i] <= '9') flag3++; } if (flag1 != 0 && flag2 != 0 && flag3 != 0) { cout << s << endl; continue; } else if (flag1 == 0 && flag2 && flag3) { if (flag2 > 1) { for (int i = 0; i < s.length(); i++) if (s[i] >= 'A' && s[i] <= 'Z') { s[i] = 'a'; break; } } else { for (int i = 0; i < s.length(); i++) if (s[i] >= '0' && s[i] <= '9') { s[i] = 'a'; break; } } } else if (flag1 && flag2 == 0 && flag3) { if (flag1 > 1) { for (int i = 0; i < s.length(); i++) if (s[i] >= 'a' && s[i] <= 'z') { s[i] = 'A'; break; } } else { for (int i = 0; i < s.length(); i++) if (s[i] >= '0' && s[i] <= '9') { s[i] = 'A'; break; } } } else if (flag1 && flag2 && flag3 == 0) { if (flag1 > 1) { for (int i = 0; i < s.length(); i++) if (s[i] >= 'a' && s[i] <= 'z') { s[i] = '1'; break; } } else { for (int i = 0; i < s.length(); i++) if (s[i] >= 'A' && s[i] <= 'Z') { s[i] = '1'; break; } } } else if (flag1 == 0 && flag2 == 0 && flag3) { s[0] = 'a'; s[1] = 'A'; } else if (flag1 && flag2 == 0 && flag3 == 0) { s[0] = 'A'; s[1] = '1'; } else if (flag1 == 0 && flag2 && flag3 == 0) { s[0] = 'a'; s[1] = '1'; } cout << s << endl; } return 0; }
1,200
CPP
a,b,c = map(int, input().split()) k = 0 if a>=c or b>=c: print(0) exit() if a<=0 and b<=0: print(-1) exit() if a+b < 0: s = max(a,b) - min(a,b) k += abs(s//min(abs(min(a,b)),abs(max(a,b)))) if a<b: a+=k*min(abs(a),abs(b)) else: b+=k*min(abs(a),abs(b)) while a<c and b<c: if a<b: a=b+a else: b=b+a k+=1 print(k)
1,600
PYTHON3
from collections import deque for _ in range(int(input())): n, k = map(int, input().split()) x = sorted(input()) base = x[:k] x = x[k:] if len(set(base)) > 1 or len(x) <= 0: print(max(base)) continue if len(set(x)) == 1: print(base[0] + (len(x) // k + (1 if len(x) % k > 0 else 0)) * x[0]) else: print(base[0] + ''.join(x))
1,600
PYTHON3
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; const int MAXN = 100005; const int M = 1000; int n, m, timer, tp, a, b, c, q; int t_in[MAXN], t_out[MAXN], vall[MAXN], arr[MAXN]; bitset<M> t[4 * MAXN]; bitset<M> bt, pr; int lazy[4 * MAXN] = {0}; vector<vector<int> > g(MAXN); void DFS(int, int); void build(int, int, int); void update(int, int, int, int, int, int); void push(int); void get_prime(); bitset<M> get(int, int, int, int, int); int main() { cin >> n >> m; for (int i = 1; i <= n; i++) cin >> vall[i], vall[i] % m; for (int i = 1; i < n; i++) { cin >> a >> b; g[a].push_back(b); g[b].push_back(a); } DFS(1, 0); get_prime(); build(1, 1, n); cin >> q; while (q--) { cin >> tp; if (tp == 1) { cin >> a >> b; b %= m; update(1, 1, n, t_in[a], t_out[a], b); } else { cin >> a; bt = get(1, 1, n, t_in[a], t_out[a]); bt = bt & pr; cout << bt.count() << endl; } } return 0; } void DFS(int f, int p) { t_in[f] = ++timer; arr[timer] = f; for (int i = 0; i < g[f].size(); i++) { if (g[f][i] != p) DFS(g[f][i], f); } t_out[f] = timer; } void build(int f, int tl, int tr) { if (tl == tr) { t[f].set(vall[arr[tl]] % m, 1); return; } int tm = (tl + tr) / 2; build(f * 2, tl, tm); build(f * 2 + 1, tm + 1, tr); t[f] = t[f * 2] | t[f * 2 + 1]; } void make_shift(int f, int s_val) { t[f] = (t[f] >> (m - s_val)) | ((t[f] << (M - m + s_val)) >> (M - m)); } void push(int f) { if (lazy[f] == 0) return; lazy[f] %= m; lazy[f * 2] += lazy[f]; lazy[f * 2] %= m; lazy[f * 2 + 1] += lazy[f]; lazy[f * 2 + 1] %= m; make_shift(2 * f, lazy[f]); make_shift(2 * f + 1, lazy[f]); lazy[f] = 0; } void update(int f, int tl, int tr, int l, int r, int x) { if (l > r) return; if (tl == l && tr == r) { lazy[f] += x; lazy[f] %= m; make_shift(f, x); return; } push(f); int tm = (tl + tr) / 2; update(f * 2, tl, tm, l, min(tm, r), x); update(f * 2 + 1, tm + 1, tr, max(tm + 1, l), r, x); t[f] = t[f * 2] | t[f * 2 + 1]; } bitset<M> k; bitset<M> get(int f, int tl, int tr, int l, int r) { if (l > r) return k; if (tl == l && tr == r) return t[f]; int tm = (tl + tr) / 2; push(f); return get(f * 2, tl, tm, l, min(r, tm)) | get(f * 2 + 1, tm + 1, tr, max(l, tm + 1), r); } void get_prime() { bitset<M> tt; for (int i = 2; i < M; i++) { if (tt[i]) continue; pr[i] = 1; for (int j = i * i; j < M; j += i) tt[j] = 1; } }
2,800
CPP
#include <bits/stdc++.h> using namespace std; int tSum; int found = false; int n, Num; int a[30][30], A[170], vis[107]; int CurSum[44]; int TSUM[44]; int lim; void dfs(int x, int y) { if (y == 1) if ((x > 1) && (CurSum[x - 1] != lim)) return; if (x == n && y > 1) { if (TSUM[y - 1] != lim) return; } if ((x > n)) { int sum[9]; memset(sum, 0, sizeof(sum)); for (int i = 1; i <= n; ++i) sum[1] += a[i][i]; for (int i = 1; i <= n; ++i) sum[2] += a[i][n + 1 - i]; if (sum[2] != sum[1] || (sum[1] != lim)) return; found = true; tSum = sum[1]; return; } for (int i = 1; i <= Num; ++i) if (vis[i]) { a[x][y] = A[i]; int tx = x, ty = y; if (y == n) { ++x; y = 1; } else ++y; --vis[i]; CurSum[tx] += A[i]; TSUM[ty] += A[i]; dfs(x, y); if (found) return; ++vis[i]; CurSum[tx] -= A[i]; TSUM[ty] -= A[i]; x = tx; y = ty; } } int TS(0); int main() { cin >> n; memset(vis, 0, sizeof(vis)); Num = n * n; for (int i = 1; i <= n * n; ++i) { cin >> A[i]; bool fl = false; TS += A[i]; for (int j = 1; j <= i - 1; ++j) if (A[i] == A[j]) { fl = true; ++vis[j]; break; } if (fl) continue; ++vis[i]; } for (int i = 1; i <= Num; ++i) { if (vis[i] == 0) { for (int j = i + 1; j <= Num; ++j) if (vis[j]) { vis[i] = vis[j]; vis[j] = 0; A[i] = A[j]; break; } if (vis[i] == 0) { Num = i - 1; break; } } } lim = TS / n; dfs(1, 1); cout << tSum << endl; for (int i = 1; i <= n; ++i) { for (int j = 1; j <= n; ++j) cout << a[i][j] << ' '; cout << endl; } return 0; }
1,900
CPP
b,d,s=map(int,input().split()) if b==max(b,d,s): if b==d: if d==s: print(0) else: print(abs(d-1-s)) else: if b==s: print(abs(b-1-d)) else: print(abs(b-1-s)+abs(b-1-d)) elif d==max(b,d,s): if d==s: print(d-1-b) else: print(abs(d-1-b)+abs(d-1-s)) else: if s==d: if d==b: print(0) else: print(abs(d-1-b)) else: if b==s: print(abs(s-1-d)) else: print(abs(s-1-b)+abs(s-1-d))
1,200
PYTHON3
n, s, ans = int(input()), input(), '' for c in s: if n % 2 == 0: ans = (c + ans if len(ans) % 2 == 0 else ans + c) else: ans = (ans + c if len(ans) % 2 == 0 else c + ans) print(ans)
900
PYTHON3
r, c = map(int, input().split()) rows = [] for i in range(r): s = input() rows.append(s) res = "Yes" for i in range(r): for j in range(c): if i < r - 1 and (rows[i][j] + rows[i + 1][j]) == "SW": res = "No" break if i < r - 1 and (rows[i][j] + rows[i + 1][j]) == "WS": res = "No" break if j < c - 1 and (rows[i][j] + rows[i][j + 1]) == "SW": res = "No" break if j < c - 1 and (rows[i][j] + rows[i][j + 1]) == "WS": res = "No" break if res == "No": break print(res) if res != "No": for i in range(len(rows)): s = "" for j in rows[i]: if j == ".": s += "D" else: s += j print(s)
900
PYTHON3
#include <bits/stdc++.h> using namespace std; int k, m, i; set<int> S; void search(int x, int v) { if (!x) { int y = abs(k - v); if (y < 10000) { S.insert(i * 10000 + y); S.insert(y * 10000 + i); } y = abs(k + v); if (y < 10000) { S.insert(i * 10000 + y); S.insert(y * 10000 + i); } if (S.size() >= m) { for (set<int>::iterator it = S.begin(); it != S.end() && m; ++it, --m) printf("%08d\n", *it); exit(0); } return; } int t = x % 10; search(x / 10, v + t); search(x / 10, v - t); search(x / 10, v * t); } int main() { scanf("%d %d", &k, &m); for (i = 0; i < 10000; i++) search(i / 10, i % 10); return 0; }
2,700
CPP
#include <bits/stdc++.h> char _; using namespace std; void PRINT(int x, int y) { for (int i = y - 1; i >= 0; i--) { cout << ((0u == (x & (1 << i))) ? 0u : 1u); } cout << endl; } vector<string> vec_splitter(string s) { s += ','; vector<string> res; while (!s.empty()) { res.push_back(s.substr(0, s.find(','))); s = s.substr(s.find(',') + 1); } return res; } void debug_out(vector<string> __attribute__((unused)) args, __attribute__((unused)) int idx, __attribute__((unused)) int LINE_NUM) { cerr << endl; } template <typename Head, typename... Tail> void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) { if (idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") "; stringstream ss; ss << H; cerr << args[idx] << " = " << ss.str(); debug_out(args, idx + 1, LINE_NUM, T...); } int main() { cin.sync_with_stdio(0); cin.tie(0); int t; cin >> t; while (t--) { int n, k; cin >> n >> k; string s; cin >> s; int lbPre = n / 2 - k + 1; string ans = ""; for (int x = 0; x < lbPre; x++) { ans += '('; } for (int x = 0; x < lbPre; x++) { ans += ')'; } for (int x = 0; x < n / 2 - lbPre; x++) { ans += "()"; } int tot = 0; vector<pair<int, int> > moves; for (int x = 0; x < n; x++) { if (ans[x] != s[x]) { for (int i = x + 1; i < n; i++) { if (s[x] != s[i]) { char front = s[i]; for (int j = x + 1; j <= i; j++) { s[j] = s[j - 1]; } s[x] = front; tot++; moves.push_back(make_pair(x, i)); break; } } } } 42; cout << tot << "\n"; for (int x = 0; x < moves.size(); x++) { cout << moves[x].first + 1 << " " << moves[x].second + 1 << "\n"; } } return 0; }
1,700
CPP
s=input() u=0 l=0 for i in s: if ord(i)>=65 and ord(i)<=90: u=u+1 else: l=l+1 if l>=u: s=s.lower() print(s) else: s=s.upper() print(s)
800
PYTHON3
# ------------------- fast io -------------------- 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") # ------------------- fast io -------------------- import math testcases=int(input()) for j in range(testcases): #just try every b in the range 1,10**2 +1 a,b,c=map(int,input().split()) moves=4*10**4 ans=[a,b,c] for s in range(1,10**4 +10**3): b1=s minb=10**4+1 rem1=abs(b-s) if rem1<=minb: minb=rem1 #find the factors of b1 mina=10**4+1 a1=a for k in range(1,math.ceil(math.sqrt(b1))+1): if s%k==0: second=s//k rem1=abs(a-k) if rem1<mina: mina=rem1 a1=k rem2=abs(a-second) if rem2<mina: mina=rem2 a1=second minc=10**4 +1 c1=c if c>=s: rem1=c%s rem2=(-c)%s if rem1<minc: minc=rem1 c1=c-rem1 if rem2<minc: minc=rem2 c1=c+rem2 else: #c<s rem2=(-c)%s if rem2<minc: minc=rem2 c1=c+rem2 if mina+minb+minc<moves: moves=mina+minb+minc ans=[a1,b1,c1] print(moves) print(*ans)
2,000
PYTHON3
n=int(input()) if n%10==0: print(n) else: if n%10>5: n+=(10-n%10) else: n-=n%10 print(n)
800
PYTHON3
n,b,a = map(int,input().split()) A = list(map(int, input().split())) m = a ans = 0 for i in range(n): if A[i] == 1: if b > 0 and a < m: b -= 1 a += 1 elif a > 0: a -= 1 elif b > 0: b -= 1 else: break else: if a > 0: a -= 1 elif b > 0: b -= 1 else: break ans = i+1 print(ans)
1,500
PYTHON3
n = int(input()) for i in range(n): inpString = input() length = len(inpString) if length > 10: outString = inpString[0] + str(length - 2) + inpString[length-1] else: outString = inpString print(outString)
800
PYTHON3
n,m,k = list(map(int,input().split(' '))) if n <= m and n <= k : print ("YES") else :print ("NO")
800
PYTHON3
n,k=map(int,input().split()) s=list(map(int,input().split())) c=k if s[k-1]==0: c=0 for i in range(k-1,0,-1): if s[i-1]!=s[k-1]: c=i break elif n==k: c=k else: for i in range(k,n): if s[i]==s[k-1]: c=c+1 else: break print(c)
800
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; long long int arr[n]; int rows = sqrt(n); queue<pair<long long int, long long int> > q[2]; int ii = 0; for (int i = 0; i < rows; i++) { for (int j = 0; j < rows; j++) { cin >> arr[ii]; q[i % 2].push({arr[ii], arr[ii]}); ii++; } } int count = 0; int temp_row = rows; sort(arr, arr + n); long long r = 0; for (int i = 1; i <= n; i *= 4) for (int j = n - i; j < n; ++j) r += arr[j]; cout << r << endl; ; int kkk = 0; while (kkk) { auto temp1 = q[0].front(); q[0].pop(); auto temp2 = q[0].front(); q[0].pop(); auto temp3 = q[1].front(); q[1].pop(); auto temp4 = q[1].front(); q[1].pop(); count += 2; int dalna; if (count <= temp_row) { dalna = 0; } else if (count >= temp_row) { dalna = 1; if (count == 2 * temp_row) { count = 0; temp_row /= 2; } } long long int sum = temp1.first + temp2.first + temp3.first + temp4.first; long long int maxi = max(temp1.second, max(temp2.second, max(temp3.second, temp4.second))); sum += maxi; q[dalna].push({sum, maxi}); if (q[0].size() == 1) { cout << q[0].front().first << endl; return 0; } } return 0; }
1,400
CPP
#include <bits/stdc++.h> using namespace std; const int N = (1 << 20) + 100, LOG = 19, inf = 1e9, mod = 998244353; const long long INF = 1e18; int n, m, k, ex; long long p[N], base[N]; int a[N], b[N], c[N], A[LOG][N], B[N], ans[N]; bool was[N]; long long first(long long x) { long long res = 0; for (int i = 0; i < m; i++) { if (was[i]) continue; res = ((res << 1) | ((x >> i) & 1)); } return res; } int sum(int a, int b) { a += b; if (a >= mod) a -= mod; return a; } int sub(int a, int b) { a -= b; if (a < 0) a += mod; return a; } void add(long long x) { for (int i = 0; i < k; i++) if ((x >> p[i]) & 1) x ^= base[i]; if (x == 0) { ex++; return; } for (int i = 0; i < m; i++) if ((x >> i) & 1) { p[k] = i; base[k] = x; k++; break; } } int main() { scanf("%d%d", &n, &m); for (int i = 0; i < n; i++) { long long x; scanf("%lld", &x); add(x); } if (k <= 20) { for (int i = 0; i < (1 << k); i++) { long long x = 0; for (int j = 0; j < k; j++) if ((i >> j) & 1) x ^= base[j]; ans[__builtin_popcountll(x)]++; } } else { for (int i = 0; i < min(m / 2, k); i++) was[p[i]] = 1; for (int i = 0; i < (1 << min(m / 2, k)); i++) { long long x = 0, cnt = 0; for (int j = 0; j < min(m / 2, k); j++) if ((i >> j) & 1) x ^= base[j]; for (int j = 0; j < min(m / 2, k); j++) if ((x >> p[j]) & 1) cnt++, x ^= (1ll << p[j]); A[cnt][first(x)]++; } for (int i = 0; i < (1 << (k - min(m / 2, k))); i++) { long long x = 0; for (int j = 0; j < k - min(m / 2, k); j++) if ((i >> j) & 1) x ^= base[j + min(m / 2, k)]; B[first(x)]++; } long long inv = 1; for (int i = 0; i < LOG; i++) { if (inv & 1) inv += mod; inv >>= 1; } for (int i = 0; i < LOG; i++) { for (int j = 0; j < (1 << LOG); j++) a[j] = A[i][j], b[j] = B[j]; for (int j = 0; j < LOG; j++) for (int q = 0; q < (1 << LOG); q++) if ((q >> j) & 1) { { int x = a[q ^ (1 << j)]; int y = a[q]; a[q ^ (1 << j)] = sum(x, y); a[q] = sub(x, y); } { int x = b[q ^ (1 << j)]; int y = b[q]; b[q ^ (1 << j)] = sum(x, y); b[q] = sub(x, y); } } for (int j = 0; j < (1 << LOG); j++) c[j] = 1ll * a[j] * b[j] % mod; for (int j = 0; j < LOG; j++) for (int q = 0; q < (1 << LOG); q++) if ((q >> j) & 1) { int x = c[q ^ (1 << j)]; int y = c[q]; c[q ^ (1 << j)] = sum(x, y); c[q] = sub(x, y); } for (int j = 0; j < (1 << LOG); j++) { c[j] = c[j] * inv % mod; ans[i + __builtin_popcountll(j)] = sum(ans[i + __builtin_popcountll(j)], c[j]); } } } long long x = 1; while (ex--) { x = x + x; if (x >= mod) x -= mod; } for (int i = 0; i <= m; i++) printf("%lld ", 1ll * ans[i] * x % mod); }
2,700
CPP
#include <bits/stdc++.h> using namespace std; int prime[20000050], cnt, output; bitset<300000050> b; void Init(int l, int r) { for (int i = 2; i <= r; i++) { if (!b[i]) { prime[++cnt] = i; if (l <= i && r >= i && (i == 2 || i % 4 == 1)) output++; } for (int j = 1; j <= cnt && i * prime[j] <= r; j++) { b[i * prime[j]] = 1; if (i % prime[j] == 0) break; } } } int main() { int l, r; scanf("%d %d", &l, &r); Init(l, r); printf("%d", output); }
2,200
CPP
img=[['OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'IN', 'OUT', 'IN', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'IN', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT'], ['OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'IN', 'OUT', 'IN', 'IN', 'IN', 'OUT', 'IN', 'OUT', 'IN', 'OUT', 'IN', 'OUT', 'OUT', 'IN', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT'], ['OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'OUT', 'IN', 'OUT', 'OUT', 'OUT', 'IN', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'OUT', 'IN', 'OUT', 'OUT', 'OUT', 'OUT', 'IN', 'OUT', 'OUT', 'IN', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT'], ['OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'OUT', 'IN', 'OUT', 'IN', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'OUT', 'IN', 'OUT', 'IN', 'IN', 'IN', 'OUT', 'IN', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT'], ['OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'IN', 'OUT', 'IN', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'OUT', 'IN', 'OUT', 'IN', 'OUT', 'IN', 'OUT', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT'], ['OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'IN', 'OUT', 'OUT', 'IN', 'IN', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'IN', 'IN', 'IN', 'OUT', 'IN', 'IN', 'IN', 'OUT', 'IN', 'OUT', 'OUT', 'IN', 'OUT', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'IN', 'OUT', 'OUT', 'IN', 'OUT', 'IN', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT'], ['OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'IN', 'OUT', 'OUT', 'IN', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'IN', 'OUT', 'IN', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'IN', 'IN', 'OUT', 'IN', 'IN', 'OUT', 'IN', 'IN', 'OUT', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT'], ['OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'IN', 'IN', 'OUT', 'IN', 'IN', 'OUT', 'IN', 'IN', 'IN', 'OUT', 'IN', 'IN', 'IN', 'OUT', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'OUT', 'OUT', 'IN', 'OUT', 'OUT', 'IN', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT'], ['OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'OUT', 'IN', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'IN', 'OUT', 'OUT', 'OUT', 'IN', 'OUT', 'IN', 'IN', 'OUT', 'OUT', 'IN', 'IN', 'OUT', 'IN', 'IN', 'OUT', 'IN', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT'], ['OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT'], ['OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT'], ['OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT'], ['OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT'], ['OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT'], ['OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT'], ['OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT'], ['OUT', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'OUT'], ['OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'OUT'], ['OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'OUT'], ['OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'IN', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'IN', 'OUT', 'IN', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT'], ['OUT', 'OUT', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'IN', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'IN', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT'], ['OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'OUT', 'IN', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'IN', 'IN', 'OUT', 'IN', 'IN', 'OUT', 'OUT', 'IN', 'OUT', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'OUT', 'OUT'], ['OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'IN', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'IN', 'OUT', 'OUT', 'IN', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT'], ['OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'IN', 'OUT', 'OUT', 'IN', 'OUT', 'OUT', 'IN', 'IN', 'OUT', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'IN', 'IN', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'IN', 'OUT', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT'], ['OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'IN', 'IN', 'OUT', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'IN', 'OUT', 'OUT', 'IN', 'OUT', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT'], ['OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'IN', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'OUT', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'IN', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'IN', 'OUT', 'OUT', 'OUT', 'IN', 'OUT', 'OUT', 'IN', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT'], ['IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'IN', 'IN', 'IN', 'OUT', 'IN', 'OUT', 'OUT', 'IN', 'OUT', 'OUT', 'IN', 'OUT', 'OUT', 'OUT', 'IN', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'IN', 'OUT', 'OUT', 'IN', 'OUT', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'OUT', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN'], ['IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'IN', 'OUT', 'OUT', 'IN', 'OUT', 'IN', 'IN', 'OUT', 'IN', 'IN', 'IN', 'OUT', 'IN', 'IN', 'IN', 'OUT', 'IN', 'IN', 'IN', 'IN', 'OUT', 'IN', 'OUT', 'IN', 'IN', 'IN', 'OUT', 'IN', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'IN', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN'], ['IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'IN', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'OUT', 'IN', 'OUT', 'OUT', 'IN', 'OUT', 'IN', 'OUT', 'OUT', 'OUT', 'OUT', 'IN', 'OUT', 'IN', 'OUT', 'OUT', 'IN', 'OUT', 'IN', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN'], ['IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'IN', 'OUT', 'OUT', 'IN', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'OUT', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'IN', 'OUT', 'IN', 'OUT', 'IN', 'IN', 'OUT', 'IN', 'IN', 'OUT', 'IN', 'OUT', 'OUT', 'IN', 'OUT', 'OUT', 'OUT', 'IN', 'OUT', 'OUT', 'IN', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN'], ['IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'IN', 'IN', 'OUT', 'IN', 'IN', 'IN', 'IN', 'OUT', 'IN', 'IN', 'OUT', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'IN', 'OUT', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'OUT', 'IN', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN'], ['IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'IN', 'OUT', 'OUT', 'IN', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'OUT', 'IN', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'OUT', 'IN', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'IN', 'OUT', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'IN', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN'], ['IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'OUT', 'IN', 'IN', 'IN', 'OUT', 'IN', 'IN', 'OUT', 'IN', 'IN', 'IN', 'OUT', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'IN', 'OUT', 'OUT', 'IN', 'IN', 'OUT', 'IN', 'IN', 'OUT', 'OUT', 'IN', 'OUT', 'OUT', 'OUT', 'IN', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN'], ['IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'IN', 'IN', 'OUT', 'IN', 'OUT', 'OUT', 'OUT', 'OUT', 'IN', 'OUT', 'IN', 'OUT', 'OUT', 'OUT', 'OUT', 'IN', 'OUT', 'IN', 'OUT', 'OUT', 'IN', 'OUT', 'IN', 'OUT', 'IN', 'IN', 'OUT', 'IN', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'OUT', 'IN', 'IN', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN'], ['IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'OUT', 'IN', 'OUT', 'IN', 'OUT', 'IN', 'OUT', 'IN', 'OUT', 'IN', 'IN', 'IN', 'IN', 'OUT', 'IN', 'IN', 'OUT', 'IN', 'OUT', 'OUT', 'IN', 'OUT', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN'], ['IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'IN', 'OUT', 'OUT', 'IN', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'IN', 'OUT', 'OUT', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'OUT', 'IN', 'OUT', 'OUT', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN'], ['IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'IN', 'OUT', 'IN', 'IN', 'OUT', 'IN', 'IN', 'OUT', 'IN', 'IN', 'OUT', 'IN', 'IN', 'OUT', 'OUT', 'IN', 'OUT', 'IN', 'IN', 'IN', 'OUT', 'IN', 'OUT', 'OUT', 'IN', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN'], ['IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'IN', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'IN', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN'], ['OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'IN', 'OUT', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'IN', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'IN', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT'], ['OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT'], ['OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'IN', 'OUT', 'OUT', 'IN', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT'], ['OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'IN', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT'], ['OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'IN', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'OUT'], ['OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'OUT'], ['OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'IN', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'OUT'], ['OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'IN', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'IN', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'IN', 'OUT', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'OUT'], ['OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'IN', 'OUT', 'IN', 'OUT', 'IN', 'OUT', 'OUT', 'IN', 'OUT', 'IN', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'OUT', 'IN', 'OUT', 'IN', 'IN', 'OUT', 'OUT', 'IN', 'OUT', 'IN', 'OUT', 'OUT', 'IN', 'OUT', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'IN', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'OUT'], ['OUT', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'IN', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'IN', 'OUT', 'IN', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'OUT'], ['OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'IN', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'OUT', 'IN', 'IN', 'IN', 'IN', 'OUT', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'IN', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT'], ['OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'IN', 'OUT', 'OUT', 'IN', 'OUT', 'OUT', 'IN', 'OUT', 'OUT', 'OUT', 'IN', 'OUT', 'IN', 'IN', 'IN', 'IN', 'OUT', 'IN', 'IN', 'IN', 'OUT', 'IN', 'IN', 'OUT', 'IN', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'IN', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT'], ['OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'OUT', 'IN', 'IN', 'OUT', 'IN', 'OUT', 'OUT', 'OUT', 'OUT', 'IN', 'OUT', 'OUT', 'OUT', 'IN', 'OUT', 'IN', 'OUT', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'OUT', 'IN', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT'], ['OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'IN', 'IN', 'OUT', 'IN', 'OUT', 'IN', 'OUT', 'OUT', 'OUT', 'IN', 'OUT', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT'], ['OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'IN', 'OUT', 'IN', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'IN', 'OUT', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'IN', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT'], ['OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'OUT', 'IN', 'IN', 'OUT', 'IN', 'IN', 'IN', 'IN', 'OUT', 'IN', 'IN', 'IN', 'IN', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT'], ['OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'OUT', 'IN', 'OUT', 'IN', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'IN', 'OUT', 'OUT', 'OUT', 'OUT', 'IN', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT'], ['OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'IN', 'OUT', 'IN', 'IN', 'IN', 'IN', 'OUT', 'IN', 'IN', 'OUT', 'IN', 'IN', 'OUT', 'IN', 'OUT', 'IN', 'IN', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT'], ['OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'OUT', 'IN', 'OUT', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT'], ['OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT'], ['OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT'], ['OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT'], ['OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT'], ['OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT'], ['OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT'], ['OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'IN', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT', 'OUT']] data=input() row=int(data.strip().split(' ')[0]) col=int(data.strip().split(' ')[1]) print(img[row][col])
0
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, m, a, b, u = 1; string s; cin >> n >> m; vector<pair<int, pair<int, string>>> vk; for (int i = 0; i < n; i++) { cin >> s >> a >> b; vk.push_back(make_pair(a, make_pair(b, s))); } sort(vk.begin(), vk.end()); vk.push_back(make_pair(20000, make_pair(900, s))); for (int i = 1; i <= n; i++) { if (vk[i].first == vk[i - 1].first) u++; else { if (u <= 2 || vk[i - 2].second.first != vk[i - 3].second.first) cout << vk[i - 1].second.second << " " << vk[i - 2].second.second << endl; else cout << '?' << endl; u = 1; } } return 0; }
1,300
CPP
#include <bits/stdc++.h> using namespace std; int main() { int t, a[200005], n, k, prom, res, m; scanf("%d", &t); while (t--) { scanf("%d%d", &n, &k); for (int i = 0; i < n; i++) scanf("%d", a + i); sort(a, a + n); if (n == 1) { cout << a[0] << endl; continue; } int mini = INT_MAX; for (int i = 0; i < n - k; i++) { prom = (a[k + i] + a[i]) / 2; m = max(a[k + i] - prom, prom - a[i]); if (m < mini) { res = prom; mini = m; } prom++; m = max(a[k + i] - prom, prom - a[i]); if (m < mini) { res = prom; mini = m; } } cout << res << endl; } return 0; }
1,600
CPP
s = list(map(int, input().split())) def linesq(xf1,yf1,xf2,yf2): return (yf1-yf2)**2+(xf1-xf2)**2 def sdch(arr): a, b, c, d, e, f = arr sides = [] sides.append(linesq(a,b,e,f)) sides.append(linesq(a,b,c,d)) sides.append(linesq(c,d,e,f)) sides = sorted(sides) #if AB + BC > CA and CA + AB > BC and BC + CA > AB: if (sides[0]**0.5 + sides[1]**0.5 > sides[2]**0.5) and (sides[1]**0.5 + sides[2]**0.5 > sides[0]**0.5) and (sides[0]**0.5 + sides[2]**0.5 > sides[1]**0.5): if sides[0] + sides[1] == sides[2]: return True if sdch(s): print('RIGHT') exit() for i in range(6): s[i] += 1 if sdch(s): print('ALMOST') exit() s[i] -= 2 if sdch(s): print('ALMOST') exit() s[i] += 1 print('NEITHER')
1,500
PYTHON3
# http://codeforces.com/problemset/problem/733/A vowel = ["A", "I", "U", "E", "O", "Y"] s = str(input()) ans = 0 temp = -1 if any(x in s for x in vowel): for i in range(len(s)): if s[i] in vowel: ans = max(ans, abs(temp-i)) temp = i ans = max(ans, abs(len(s)-temp)) print(ans) else: print(len(s)+1)
1,000
PYTHON3
xa, ya = map(int, input().split()) xb, yb = map(int, input().split()) xc, yc = map(int, input().split()) xs = [xa, xb, xc] xs.sort() ys = [ya, yb, yc] ys.sort() mx, my = xs[1], ys[1] field = [[False]*1001 for _ in range(1001)] for sx, sy in [(xa, ya), (xb, yb), (xc, yc)]: for x in range(min(sx, mx), max(sx, mx)+1): field[x][sy] = True for y in range(min(sy, my), max(sy, my)+1): field[mx][y] = True ans = [] for x in range(1001): for y in range(1001): if field[x][y]: ans.append((x, y)) print(len(ans)) for x, y in ans: print(x, y)
1,600
PYTHON3
n, w = map(int, input().split()) a = sorted(list(map(int, input().split()))) print(min(3 * n * a[0], 1.5 * n * a[n], w))
1,500
PYTHON3
mod = 1000000007 ii = lambda : int(input()) si = lambda : input() dgl = lambda : list(map(int, input())) f = lambda : map(int, input().split()) il = lambda : list(map(int, input().split())) ls = lambda : list(input()) n,m=f() x=(((n//m+1)*(n//m))//2)*(n%m)+((n//m)*(n//m-1))//2*(m-n%m) y=((n-m+1)*(n-m))//2 print(x,y)
1,300
PYTHON3
n, m, k = map(int, input().split()) b = [[0 for x in range(m + 2)] for y in range(n + 2)] def makes_square(i, j): # st sus if b[i - 1][j - 1] + b[i - 1][j] + b[i][j - 1] == 3: return 1 # st jos if b[i][j - 1] + b[i + 1][j] + b[i + 1][j - 1] == 3: return 1 # dr jos if b[i + 1][j] + b[i + 1][j + 1] + b[i][j + 1] == 3: return 1 # dr sus if b[i - 1][j] + b[i - 1][j + 1] + b[i][j + 1] == 3: return 1 return 0 loss = 0 for z in range(k): i, j = map(int, input().split()) b[i][j] = 1 if makes_square(i, j) == 1: loss = z + 1 break print(loss)
1,100
PYTHON3
import sys a = [char for char in sys.stdin.readline()] b = [char for char in sys.stdin.readline()] i = 0 while len(a)-i-1 >= 0 and len(b)-i-1 >=0 and a[len(a)-i-1] == b[len(b)-i-1]: i+=1 print((len(a)-i) + (len(b)-i))
900
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { long long int t; cin >> t; for (long long int z = 0; z < t; z++) { long long int n, r; cin >> n >> r; long long int ans; if (n > r) { cout << (r * (r + 1)) / 2 << "\n"; } else { cout << ((n - 1) * (n)) / 2 + 1 << "\n"; } } return 0; }
1,200
CPP
def Input(): tem = input().split() ans = [] for it in tem: ans.append(int(it)) return ans from collections import Counter x_0,y_0,a,c,b,d = Input() x_s,y_s,t=Input() lis = [[0,0],[abs(x_s-x_0)+abs(y_s-y_0),0]] x,y=x_0,y_0 x_n, y_n = x_0*a+b,y_0*c+d for i in range(300): lis.append([abs(x_s-x_n)+abs(y_s-y_n),abs(x_n-x)+abs(y_n-y)+lis[-1][1]]) x,y=x_n,y_n x_n,y_n=x_n*a+b,y_n*c+d m = len(lis) ans = 0 for i in range(1,m): if lis[i][0]<=t: ans+=1 break for i in range(2,m): for j in range(1,i): MIN = min(lis[i][0],lis[j][0]) if MIN+lis[i][1]-lis[j][1]<=t: ans=max(ans,i-j+1) print(ans)
1,700
PYTHON3
n, k = [int(i) for i in input().split()] a = [int(i) for i in input().split()] b = 0 for i in range(n): if a[i] >= a[k-1] and a[i] > 0: b += 1 print(b)
800
PYTHON3
#include <bits/stdc++.h> using namespace std; int n, a[100100], q, k, x; int gt(int x) { int ct = 41; for (int i = 1; i <= k; ++i) { for (int j = 1; j <= n; ++j) { if (i * a[j] == x) { ct = min(ct, i); continue; }; for (int g = 1; g <= k - i; ++g) { if ((x - i * a[j]) % g != 0) continue; int ans = (x - i * a[j]) / g; int L = 1; int R = j; while (L + 1 < R) { int mid = (L + R) / 2; if (a[mid] <= ans) { L = mid; } else { R = mid; } } if (a[L] == ans) ct = min(ct, i + g); } } } if (ct > 20) return -1; return ct; } int main() { scanf("%d%d", &n, &k); for (int i = 1; i <= n; ++i) { scanf("%d", &a[i]); } scanf("%d", &q); for (int i = 0; i < q; ++i) { scanf("%d", &x); printf("%d\n", gt(x)); } return 0; }
1,900
CPP
a=[int(x) for x in input().split()] su= sum(a)/2 flag=0 for i in range(4): for j in range(i+1,5): for k in range(j+1,6): sum1=a[i]+a[j]+a[k] if sum1==su: # print(a[i],a[j],a[k]) print("YES") flag=1 exit() if flag==0: print("NO")
1,000
PYTHON3
#include <bits/stdc++.h> using namespace std; inline int gi() { char c; int num = 0, flg = 1; while ((c = getchar()) < '0' || c > '9') if (c == '-') flg = -1; while (c >= '0' && c <= '9') { num = num * 10 + c - 48; c = getchar(); } return num * flg; } long long all; namespace LCT { int fa[400005], ch[400005][2], siz[400005], vsz[400005]; long long sum[400005]; long long val(int x) { return 1ll * siz[x] * siz[x]; } bool pdc(int x) { return ch[fa[x]][1] == x; } bool nrt(int x) { return ch[fa[x]][0] == x || ch[fa[x]][1] == x; } void pushup(int x) { siz[x] = siz[ch[x][0]] + siz[ch[x][1]] + 1 + vsz[x]; } void rot(int x) { int y = fa[x], z = fa[y]; bool flg = pdc(x); if (nrt(y)) ch[z][pdc(y)] = x; if (ch[y][flg] = ch[x][flg ^ 1]) fa[ch[y][flg]] = y; ch[x][flg ^ 1] = y; fa[y] = x; fa[x] = z; pushup(y); pushup(x); } void splay(int x) { for (; nrt(x); rot(x)) if (nrt(fa[x])) rot(pdc(x) == pdc(fa[x]) ? fa[x] : x); } void Access(int x) { for (int i = 0; x; i = x, x = fa[x]) { splay(x); vsz[x] -= siz[i]; vsz[x] += siz[ch[x][1]]; sum[x] -= val(i); sum[x] += val(ch[x][1]); ch[x][1] = i; pushup(x); } } int findroot(int x) { Access(x); splay(x); while (ch[x][0]) x = ch[x][0]; splay(x); return x; } void link(int x, int y) { splay(x); all -= sum[x] + val(ch[x][1]); int z = findroot(y); Access(x); splay(z); all -= val(ch[z][1]); splay(y); fa[x] = y; vsz[y] += siz[x]; sum[y] += val(x); pushup(y); Access(x); splay(z); all += val(ch[z][1]); } void cut(int x, int y) { Access(x); all += sum[x]; int z = findroot(y); Access(x); splay(z); all -= val(ch[z][1]); splay(x); ch[x][0] = fa[ch[x][0]] = 0; pushup(x); splay(z); all += val(ch[z][1]); } } // namespace LCT int fir[400005], to[2 * 400005], nxt[2 * 400005], cnt; void adde(int a, int b) { to[++cnt] = b; nxt[cnt] = fir[a]; fir[a] = cnt; to[++cnt] = a; nxt[cnt] = fir[b]; fir[b] = cnt; } int fa[400005]; void dfs(int u, int ff) { fa[u] = ff; for (int p = fir[u]; p; p = nxt[p]) if (to[p] != ff) dfs(to[p], u); } vector<pair<int, int> > tmp[400005]; int col[400005]; bool oft[400005]; long long ans[400005]; int main() { int n, m, i, j, u, v, t; n = gi(); m = gi(); for (i = 1; i <= n; i++) { col[i] = gi(); tmp[col[i]].push_back(make_pair(0, i)); } for (i = 1; i < n; i++) { u = gi(); v = gi(); adde(u, v); } dfs(1, n + 1); for (i = 1; i <= m; i++) { u = gi(); v = gi(); tmp[col[u]].push_back(make_pair(i, u)); col[u] = v; tmp[col[u]].push_back(make_pair(i, u)); } for (i = 1; i <= n; i++) LCT::link(i, fa[i]); for (i = 1; i <= n; i++) { long long pre = 0; for (j = 0; j < int(tmp[i].size()); j++) { t = tmp[i][j].first; u = tmp[i][j].second; if (!oft[u]) LCT::cut(u, fa[u]); else LCT::link(u, fa[u]); oft[u] ^= 1; ans[t] += 1ll * n * n - all - pre; pre = 1ll * n * n - all; } for (j = 0; j < int(tmp[i].size()); j++) if (oft[u = tmp[i][j].second]) LCT::link(u, fa[u]), oft[u] = 0; } for (i = 1; i <= m; i++) ans[i] += ans[i - 1]; for (i = 0; i <= m; i++) printf("%lld\n", ans[i]); }
3,300
CPP
n2, x, y = [int(i) for i in input().split()] middle = n2//2 if (x == middle+1 or x == middle) and (y == middle+1 or y == middle): print("NO") else: print("YES")
1,200
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; double S = .0; int cnt = 0; double A[100]; for (int i = 0; i < 2 * n; ++i) { double v; cin >> v; A[i] = v; double x = v - floor(v); if (x > 0.0001) { cnt++; S += x; } } double best2 = 1e9; int zeros = 2 * n - cnt; for (int i = max(0, n - zeros); i <= n && i <= cnt; ++i) { double v = fabs(S - i); if (v < best2) best2 = v; } cout << std::fixed << std::setprecision(3) << best2 << endl; return 0; }
1,800
CPP
#include <bits/stdc++.h> using namespace std; long long int binpow(long long x, long long p) { if (p == 0) { return 1; } else if (p == 1) return x; else { if (p % 2 == 0) return binpow(x * x, p / 2); else return x * binpow(x * x, p / 2); } } int gcd(int a, int b) { if (!a || !b) return a | b; unsigned shift = __builtin_ctz(a | b); a >>= __builtin_ctz(a); do { b >>= __builtin_ctz(b); if (a > b) swap(a, b); b -= a; } while (b); return a << shift; } int main() { long long n, m; cin >> n >> m; long long arr[n]; set<int> s; map<long long, long long> mp; for (long long(i) = (0); (i) < (1e5 + 5); (i)++) { mp[i] = 0; } for (long long(i) = (0); (i) < (n); (i)++) { cin >> arr[i]; s.insert(arr[i]); mp[arr[i]]++; } long long i = 1; long long ans[n]; ans[0] = s.size(); mp[arr[0]]--; long long cnt = s.size(); if (mp[arr[0]] == 0) { cnt -= 1; } for (long long(i) = (1); (i) < (n); (i)++) { if (mp[arr[i]] < 1) { cnt -= 1; ans[i] = cnt; } else { mp[arr[i]] -= 1; ans[i] = cnt; if (mp[arr[i]] == 0) cnt -= 1; } } for (long long(i) = (0); (i) < (m); (i)++) { long long k; cin >> k; cout << ans[k - 1] << "\n"; } return 0; }
1,100
CPP
from math import ceil t=int(input()) for _ in range(t): n,m=map(int,input().split()) l=list(map(int,input().split())) l.sort() dp=[0]*(n+1) for i in range(n-1,-1,-1): c=ceil(m/l[i]) if c+i>n: dp[i]=dp[i+1] else: dp[i]=max(dp[i+1],1+dp[i+c]) print(dp[0])
1,400
PYTHON3
#include <bits/stdc++.h> using namespace std; int n, v[5 * 100001], freq[100001], val; int main(void) { scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &val); freq[val]++; } int idx = 0; for (int i = 0; i < 100001; i++) { for (int j = 0; j < freq[i]; j++) { v[idx++] = i; } } int ans = 0; int mid = n >> 1; int l = 0, r = (n >> 1); while (l < mid && r < n) { if (2 * v[l] <= v[r]) { l++; r++; ans++; } else { r++; } } printf("%d\n", n - ans); return 0; }
1,600
CPP
#include <bits/stdc++.h> using namespace std; void adskiy_razgon() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } const int mxN = 1e+9 + 7; const long long INF = 1e+18 + 7; long long nod(long long a, long long b) { if (b > a) { swap(a, b); } while (b > 0) { a %= b; swap(a, b); } return a; } long long nok(long long a, long long b) { return a * b / nod(a, b); } void sp(long long a, double b) { cout << fixed << setprecision(a) << b; } long long binpow(long long a, long long n) { if (n == 0) { return 1; } if (n % 2 == 1) { return binpow(a, n - 1) * a; } else { long long b = binpow(a, n / 2); return b * b; } } void solve() { long long a, b, c; cin >> a >> b >> c; long long ans = 0; while (a <= c && c >= b) { if (a > b) { b += a; } else { a += b; } ans++; } cout << ans << "\n"; } int main() { adskiy_razgon(); long long t = 1; cin >> t; for (int i = 1; i <= t; ++i) { solve(); } return 0; }
800
CPP
n = int(input()) t = 1 k = 0 while t<n: t =k*(k+1)//2 k+=1 if t==n: print("YES") else: print("NO")
800
PYTHON3
#include <bits/stdc++.h> using namespace std; long long power(long long a, long long b, long long m) { long long ret = 1; while (b) { if (b % 2) ret = ((ret % m) * (a % m)) % m; a = ((a % m) * (a % m)) % m; b /= 2; } return ret; } void ya() { cout << "YES"; exit(0); } void no() { cout << "NO"; exit(0); } int main() { int n; cin >> n; map<char, int> m[n]; int len[n]; for (int i = 0; i < n; i++) { string s; cin >> s; len[i] = s.size(); for (int j = 0; j < s.size(); j++) m[i][s[j]]++; } int ans = -1; for (int i = 'a'; i <= 'z'; i++) { for (int j = i + 1; j <= 'z'; j++) { int temp = 0; for (int k = 0; k < n; k++) { int flag = 0; for (auto it = m[k].begin(); it != m[k].end(); it++) { char ch = it->first; if (ch != i && ch != j) { flag = 1; break; } } if (!flag) temp += len[k]; } ans = max(ans, temp); } } cout << ans; return 0; }
1,200
CPP
from sys import stdin, stdout input = stdin.readline for _ in range(int(input())): n = int(input()) d = {} r = [[0, 0] for i in range(n + 1)] for i in range(n): a, b = map(int, input().split()) d[a] = d.get(a, 0) + 1 r[a][b] += 1 b = [] for i in d.keys(): b.append([r[i][1], i]) b.sort(reverse=True) ans = 0 s = set() x = 0 for i in range(len(b)): while d[b[i][1]] > 0 and d[b[i][1]] in s: d[b[i][1]] -= 1 x += min(r[b[i][1]][1], d[b[i][1]]) ans += d[b[i][1]] s.add(d[b[i][1]]) stdout.write(f'{ans} {x}\n')
1,400
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { long long n, mx = 0; cin >> n; vector<long long> v(n), v2(n); if (n == 1) { cout << 0; return 0; } for (int i = 0; i < n; i++) { cin >> v[i]; } mx = v[n - 1]; v2.push_back(0); for (int i = n - 2; i >= 0; i--) { if (v[i] - mx == 0) { v2.push_back(1); } else if (v[i] - mx < 0) { v2.push_back(abs(v[i] - mx) + 1); } else v2.push_back(0); if (v[i] > mx) mx = v[i]; } reverse(v2.begin(), v2.end()); for (int i = 0; i < n; i++) cout << v2[i] << " "; return 0; }
1,100
CPP
#include <bits/stdc++.h> using namespace std; int a[1000006]; int n, m; long long sol; inline long long Solve(const int p) { long long sol = 0; int j = 0; for (int i = 1; i <= n && a[i] < p; i++) { ++j; if (j == m + 1) j = 1; if (j == 1) sol += 1LL * 2 * (p - a[i]); } j = 0; for (int i = n; i && a[i] > p; i--) { ++j; if (j == m + 1) j = 1; if (j == 1) sol += 1LL * 2 * (a[i] - p); } return sol; } int main() { cin.sync_with_stdio(false); cin >> n >> m; long long sum = 0; for (int i = 1; i <= n; ++i) { cin >> a[i]; sum += a[i]; } sort(a + 1, a + n + 1); long long p = sum / n; sol = Solve(p); sol = min(sol, Solve(p - 1)); sol = min(sol, Solve(p + 1)); p = a[n / 2]; sol = min(sol, Solve(p)); p = a[n / 2 + 1]; sol = min(sol, Solve(p)); cout << sol << "\n"; return 0; }
2,000
CPP
#include <bits/stdc++.h> using namespace std; int n, cnt = 1, sum = 1, q, id[400005][3]; bool mp[400005]; char x[400005]; int main() { scanf("%d %d\n%s", &n, &q, x + 1); for (int i = 1; i <= n; i++) mp[i] = (x[i] == '.'); scanf("%s", x + 1); for (int i = 1; i <= n; i++) mp[(n + 1) + i] = (x[i] == '.'); for (int i = 1; i <= n; i++) { if (!mp[i] && !mp[i + (n + 1)]) continue; else if (mp[i] && mp[i + (n + 1)]) { if (!mp[i - 1] && !mp[i + (n + 1) - 1]) { id[i][0] = ++cnt; id[i][1] = ++sum; id[i + (n + 1)][0] = cnt; id[i + (n + 1)][1] = sum; id[i][2] = 1; id[i + (n + 1)][2] = 1; continue; } if (mp[i - 1] && mp[i + (n + 1) - 1]) { id[i][2] = id[i - 1][2] + 1; id[i + (n + 1)][2] = id[i + (n + 1) - 1][2] + 1; } else { sum++; if (mp[i - 1]) { id[i][2] = id[i - 1][2] + 1; id[i + (n + 1)][2] = id[i][2] + 1; } else { id[i + (n + 1)][2] = id[i + (n + 1) - 1][2] + 1; id[i][2] = id[i + (n + 1)][2] + 1; } } id[i][0] = cnt; id[i][1] = sum; id[i + (n + 1)][0] = cnt; id[i + (n + 1)][1] = sum; } else { if (mp[i]) { if (!mp[i - 1]) { id[i][0] = ++cnt; id[i][2] = 1; } else { id[i][0] = cnt; id[i][2] = id[i - 1][2] + 1; int j = i + (n + 1) - 1; while (mp[j]) { if (!mp[j - (n + 1)]) goto xx; j--; } while (j != i + (n + 1)) id[++j][2] = 0; } } else { if (!mp[i + (n + 1) - 1]) { id[i + (n + 1)][0] = ++cnt; id[i + (n + 1)][2] = 1; } else { id[i + (n + 1)][0] = cnt; id[i + (n + 1)][2] = id[i + (n + 1) - 1][2] + 1; int j = i - 1; while (mp[j]) { if (!mp[j + (n + 1)]) goto xx; j--; } while (j != i) id[++j][2] = 0; } } } xx:; } int a, b; for (int i = 1; i <= q; i++) { scanf("%d%d", &a, &b); a += (a > n); b += (b > n); if (!mp[a] || !mp[b]) printf("-1\n"); else if (a == b) printf("0\n"); else if (id[a][0] != id[b][0]) printf("-1\n"); else if (id[a][1] == id[b][1] && id[a][1]) { int ans = ((a > (n + 1)) ^ (b > (n + 1))) + abs((a - 1) % (n + 1) - (b - 1) % (n + 1)); printf("%d\n", ans); } else { int ans = abs((id[a][2] ? id[a][2] : id[((a + (n + 1) - 1) % (2 * (n + 1)) + 1)][2]) - (id[b][2] ? id[b][2] : id[((b + (n + 1) - 1) % (2 * (n + 1)) + 1)][2])) + (!id[a][2]) + (!id[b][2]); printf("%d\n", ans); } } return 0; }
2,200
CPP
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,m,k = mapi() a = list(mapi()) b = list(mapi()) c = list(mapi()) a.sort() b.sort() c.sort() dis = lambda x,y,z:(x-y)*(x-y)+(x-z)*(x-z)+(y-z)*(y-z) res = dis(a[0],b[0],c[0]) l1,l2,l3 = 0,0,0 while l1<n-1 or l2<m-1 or l3<k-1: tmp= float("inf") tmp2 =float("inf") tmp3 = float("inf") #if l1<n-1 and l2<m and l3<k: if l1<n-1: tmp = dis(a[l1+1],b[l2],c[l3]) #if l2<m-1 and l1<n and l3<k: if l2<m-1: tmp2 = dis(a[l1],b[l2+1],c[l3]) #if l3<k-1 and l2<m and l1<n: if l3<k-1: tmp3 = dis(a[l1],b[l2],c[l3+1]) if tmp<=tmp2 and tmp<=tmp3: res = min(res,tmp) l1+=1 elif tmp2<=tmp and tmp2<=tmp3: res = min(res,tmp2) l2+=1 else: res = min(res,tmp3) l3+=1 print(min(res,dis(a[n-1],b[m-1],c[k-1])))
1,700
PYTHON3
#include <bits/stdc++.h> using namespace std; const int maxn = 12; int R, B; struct Point { int x, y; void read() { scanf("%d%d", &x, &y); } Point operator-(const Point &o) const { return (Point){x - o.x, y - o.y}; } int operator*(const Point &o) const { return x * o.y - y * o.x; } } RP[maxn], BP[maxn]; bool intersect(const Point &a, const Point &b, const Point &c, const Point &d) { if (((c - b) * (d - b)) * ((c - a) * (d - a)) > 0) return false; if (((a - c) * (b - c)) * ((a - d) * (b - d)) > 0) return false; return true; } int M[maxn]; bool used[maxn]; bool check(int p) { for (int i = 0; i < p; ++i) if (intersect(RP[i], BP[M[i]], RP[p], BP[M[p]])) return false; return true; } void dfs(int p) { if (p >= R) { throw 1; } for (int i = 0; i < R; ++i) if (!used[i]) { M[p] = i; used[i] = true; if (check(p)) { dfs(p + 1); } used[i] = false; } } int main() { scanf("%d%d", &R, &B); for (int i = 0; i < R; ++i) RP[i].read(); for (int i = 0; i < B; ++i) BP[i].read(); if (R != B) { printf("No\n"); return 0; } try { dfs(0); } catch (int) { printf("Yes\n"); return 0; } printf("No\n"); }
1,600
CPP
for _ in[0]*int(input()):n=input();l=len(n);print(9*l-9+int(n[0])-(n<n[0]*l))
1,000
PYTHON3
#include <bits/stdc++.h> using namespace std; int cnt[2][6]; int main() { int n; cin >> n; for (int i = 0; i < n; ++i) { int x; cin >> x; cnt[0][x]++; } for (int i = 0; i < n; ++i) { int x; cin >> x; cnt[1][x]++; } int ans = 0; for (int x = 1; x <= 5; ++x) { if (abs(cnt[0][x] - cnt[1][x]) & 1) { puts("-1"); return 0; } ans += abs(cnt[0][x] - cnt[1][x]) / 2; } cout << ans / 2 << endl; }
1,000
CPP
#include <bits/stdc++.h> using namespace std; int n, m; vector<int> g[100]; int ord[3003]; bool vis[100]; int pos[100] = {}; int deg[100] = {}; int getHash(int u, int v) { return (min(u, v) << 7) | max(u, v); } void dfs(int v, int p) { vis[v] = true; for (int to : g[v]) if (to != p && !vis[to]) { dfs(to, v); } } void eraseEdge(int x, int y) { g[x].erase(find(g[x].begin(), g[x].end(), y)); g[y].erase(find(g[y].begin(), g[y].end(), x)); } int main() { scanf("%d%d", &n, &m); for (int i = 0; i < (int)(m + 1); ++i) scanf("%d", ord + i), --ord[i]; for (int i = m - 1; i >= 0; --i) { int from = ord[i]; int to = ord[i + 1]; g[from].push_back(to); g[to].push_back(from); int p = -1; if (i) p = ord[i - 1]; sort(g[from].begin(), g[from].end()); for (int x : g[from]) if (x > to && x != p) { for (int j = 0; j < (int)(n); ++j) vis[j] = g[j].empty(); dfs(x, from); bool ok = true; vis[from] = true; for (int j = 0; j < (int)(n); ++j) if (!vis[j]) { ok = false; break; } if (!ok) continue; ord[i + 1] = x; eraseEdge(from, x); for (int j = 0; j < (int)(n); ++j) sort(g[j].begin(), g[j].end()); for (int j = 0; j < (int)(n); ++j) deg[j] = (int)g[j].size(); for (int j = i + 2; j <= m; ++j) ord[j] = -2; for (i += 2; i <= m; ++i) { for (int y : g[x]) { for (int j = 0; j < (int)(n); ++j) vis[j] = deg[j] == 0; dfs(y, x); vis[x] = true; bool ok = true; for (int j = 0; j < (int)(n); ++j) if (!vis[j]) { ok = false; break; } if (!ok) continue; eraseEdge(x, y); --deg[x]; --deg[y]; ord[i] = x = y; break; } } for (int j = 0; j < (int)(m + 1); ++j) printf("%d ", ord[j] + 1); printf("\n"); return 0; } } printf("No solution\n"); return 0; }
2,300
CPP
a =int(input()) b=int(input()) c=int(input()) x=a//1 y=b//2 z=c//4 d=min(x,y,z) res=(d*1)+(d*2)+(d*4) print(res)
800
PYTHON3
n = int(input()) if n % 2 == 0: ans = [2]*int(n/2) print(len(ans)) print(*ans) else: ans = [2]*int((n/2)-1)+[3] print(len(ans)) print(*ans)
800
PYTHON3
input() data = sorted(list(map(int, input().split(' ')))) temp = [] res = 0 front = '0' flag = False for i in data: if front == i: temp.append(front) else: j = 1 if len(temp) != 0: flag = True while flag and j < i - front: temp_data = temp.pop() res += front + j - temp_data if len(temp) == 0: flag = False j += 1 front = i j = 1 for index in temp: res += data[-1] + j - index j += 1 print(res)
1,200
PYTHON3
try: n=int(input()) space=[] for i in range(n,-1,-1): space.append(i) k=space[:n] k=k[::-1] space=space+k num=[] for i in range(n+1): num.append(i) k=[] for i in range(n+2): k.append(num[:i]) k=k[1:] r=k[:n] r=r[::-1] k+=r for i in range(1,len(k)-1): z=k[i] z=z[:-1] z=z[::-1] k[i]=k[i]+z for i in range(len(k)): for j in range(space[i]): print(" ",end=" ") print(*k[i]) except: pass
1,000
PYTHON3
info = input() a = info.split() total = int(a[0]) * int(a[-1]) * (int(a[-1])+1)//2 payment = total - int(a[1]) if payment >= 0: print (payment) else: print (0)
800
PYTHON3
#include <bits/stdc++.h> using namespace std; int n, m, len, A[45], B[45]; struct Mat { int d[45][45]; Mat() { memset(d, 0, sizeof(d)); } void init() { for (int i = 0; i < 45; ++i) for (int j = 0; j < 45; ++j) d[i][j] = (0x7fffffff - 100); } friend Mat operator*(Mat a, Mat b) { Mat res; for (int i = 0; i < len; ++i) { for (int j = 0; j < len; ++j) { res.d[i][j] = (0x7fffffff - 100); for (int k = 0; k < len; ++k) res.d[i][j] = min((long long)res.d[i][j], (long long)a.d[i][k] + b.d[k][j]); } } return res; } friend Mat operator^(Mat a, int k) { Mat res; res.init(); for (int i = 0; i < len; ++i) res.d[i][i] = 0; for (int i = k; i; i >>= 1, a = a * a) if (i & 1) res = res * a; return res; } }; int f[45][45], g[45][45]; int main() { scanf("%d%d", &n, &m); len = 2 * n + 1; for (int i = 1; i <= n; ++i) scanf("%d", &A[i]); for (int i = 1; i <= n; ++i) scanf("%d", &B[i]); for (int i = 0; i < 45; ++i) for (int j = 0; j < 45; ++j) f[i][j] = g[i][j] = (0x7fffffff - 100); Mat a; a.init(); for (int lim = 0; lim < len; ++lim) { for (int i = 0; i < 45; ++i) for (int j = 0; j < 45; ++j) g[i][j] = (0x7fffffff - 100); g[0][0] = 0; for (int i = 1; i <= n; ++i) { for (int j = 0; j <= i; ++j) if (i - j - j <= lim) { if (j - 1 >= 0) g[i][j] = min(g[i][j], g[i - 1][j - 1] + A[i]); g[i][j] = min(g[i][j], g[i - 1][j] + B[i]); } } for (int j = 0; j < len && abs(j - lim) <= n; ++j) if ((n + j - lim) % 2 == 0) { a.d[lim][j] = g[n][(n + j - lim) / 2]; } } a = a ^ m; printf("%d\n", a.d[0][0]); return 0; }
2,500
CPP
#include <bits/stdc++.h> using namespace std; using LD = double; LD k, d, t; int main() { scanf("%lf%lf%lf", &k, &d, &t); LD not_cook = 0; if (d < k) { long long pom = k / d; if (pom * d != k) pom = pom + (long long)1; not_cook = pom * d - k; } else not_cook = d - k; LD dod = (LD)2 * k + not_cook; t *= (LD)2; long long pel = t / dod; t -= pel * dod; LD czas = (k + not_cook) * pel; if (t == (LD)0) { printf("%.10lf", czas); return 0; } if (t <= (LD)2 * k) { czas += t / (LD)2; printf("%.10lf", czas); return 0; } czas += k; t -= (LD)2 * k; czas += t; printf("%.10lf", czas); }
1,700
CPP
m = input().split('+') m.sort() print('+'.join(m))
800
PYTHON3
for _ in range(int(input())): a,m = map(int,input().split()) print(a*(len(str(m))-1+(len(str(m))==str(m).count('9'))))
1,100
PYTHON3
#include <bits/stdc++.h> using namespace std; const long long N = 3100; long long r, c, n, k, pos[N], sz[N], sum[N], pre[N], suc[N], len[N]; long long t[N], all, ans; vector<long long> p[N]; inline long long read() { long long f = 1, x = 0; char s = getchar(); while (s < '0' || s > '9') { if (s == '-') f = -1; s = getchar(); } while (s >= '0' && s <= '9') { x = x * 10 + s - '0'; s = getchar(); } return x * f; } inline void del(long long x) { suc[pre[x]] = suc[x]; pre[suc[x]] = pre[x]; } inline long long cal(long long x) { if (x == c + 1) return len[x] * (len[x] - 1) / 2; long long r = (pos[x] == c + 1) ? c : (suc[pos[x]] - 1); return (2 * (r - x) + len[x] + 1) * len[x] / 2; } inline void upd(long long x) { sz[x]--; long long now = x; if (pos[x] >= x && pos[x] != c + 1) { sum[x]--; all -= cal(x); if (sz[suc[pos[x]]] + sum[x] < k) pos[x] = suc[pos[x]], sum[x] += sz[pos[x]]; all += cal(x); } else if (pos[x] < x && sz[x] < k) all -= cal(x), pos[x] = x, sum[x] = sz[x], all += cal(x); if (!sz[x]) { all -= cal(x) + cal(suc[x]); len[suc[x]] += len[x]; all += cal(suc[x]); } x = pre[x]; while (x) { if (pos[x] >= now) { if (pos[x] != c + 1) { sum[x]--; all -= cal(x); if (sz[suc[pos[x]]] + sum[x] < k) pos[x] = suc[pos[x]], sum[x] += sz[pos[x]]; all += cal(x); if (pos[x] == now && !sz[now]) pos[x] = pre[now]; } } else if (pos[x] == pre[now] && sum[x] + sz[now] < k) { all -= cal(x); pos[x] = now, sum[x] += sz[now]; all += cal(x); if (!sz[now]) pos[x] = pre[now]; } else break; x = pre[x]; } if (!sz[now]) del(now); } signed main() { r = read(); c = read(); n = read(); k = read(); for (long long i = 1; i <= n; i++) { long long x = read(), y = read(); p[x].push_back(y); t[y]++; } t[c + 1] = 1; for (long long i = 1; i <= r; i++) { long long last = 0; for (long long j = 1; j <= c + 1; j++) if (t[j]) { pre[j] = last; suc[last] = j; len[j] = j - last; sz[j] = t[j]; last = j; } if (pre[c + 1] == 0) { ans += (r - i + 1) * c * (c + 1) / 2; continue; } sz[c + 1] = 0; pos[c + 1] = c + 1; sum[c + 1] = 0; all = len[c + 1] * (len[c + 1] - 1) / 2; for (long long j = pre[c + 1]; j; j = pre[j]) { pos[j] = pos[suc[j]]; sum[j] = sum[suc[j]] + sz[j]; while (sum[j] >= k) sum[j] -= sz[pos[j]], pos[j] = pre[pos[j]]; all += cal(j); } ans += all; for (long long j = r; j > i; j--) { for (long long x : p[j]) upd(x); ans += all; } for (long long x : p[i]) t[x]--; } long long tmp = 0; for (long long i = 1; i <= r; i++) for (long long j = 1; j <= c; j++) tmp += (r - i + 1) * (c - j + 1); ans = tmp - ans; printf("%lld\n", ans); }
3,000
CPP
t=int(input()) while t>0: t-=1 a,b=[int(i) for i in input().split(" ")] print((b-(a-b)%b)%b)
1,500
PYTHON3
#include <bits/stdc++.h> using namespace std; map<int, int> ma; long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } int main() { int n, a[110], i; long long tar[110]; while (scanf("%d", &n) != EOF) { for (i = 1; i <= n; i++) scanf("%d", &a[i]); int flag = 1; for (i = 1; i <= n; i++) { int pos = i, t = i, j; for (j = 1; j < n + 1; j++) { pos = a[pos]; if (pos == t) { if (j % 2 == 0) { tar[i] = j / 2; } else { tar[i] = j; } break; } } if (j == n + 1) { flag = 0; break; } } if (flag == 0) printf("-1\n"); else { long long ans = 1; for (i = 1; i <= n; i++) { if (ans > tar[i]) ans = ans * tar[i] / gcd(ans, tar[i]); else ans = ans * tar[i] / gcd(tar[i], ans); } printf("%lld\n", ans); } } return 0; }
1,600
CPP
n, k = map(int, input().strip().split()) row = [k] + [0]*(n-1) for _ in range(n): row.append(row.pop(0)) print(*row)
800
PYTHON3
#include <bits/stdc++.h> using namespace std; string nr = ""; int pPos = 0, nrz; char c; bool notz = 0; int main() { cin >> c; while (!cin.eof()) { if (c == '.') { pPos *= -1; } else if (c == 'e') { cin >> nrz; } else { nr += c; pPos += (pPos >= 0); } cin >> c; } int x = nr.size() - 1; while (nr[x] == '0') { --x; } nr = nr.substr(0, x + 1); pPos *= -1; pPos += nrz; if (pPos == nr.size()) pPos = -1; for (int i = 0; i < nr.size(); ++i) { if (notz) cout << nr[i]; else if (nr[i] != '0') { notz = 1; cout << nr[i]; } if (i == pPos - 1) { if (!notz) { cout << '0'; notz = 1; } cout << '.'; } } if (pPos > nr.size()) for (int i = nr.size(); i < pPos; ++i) cout << '0'; }
1,400
CPP
s = input() v = ["A", "O", "Y", "E", "U", "I", "a", "o", "y", "e", "u", "i"] for e in v: s = s.replace(e, "") r='' for i in range(len(s)): r += '.'+s[i] r = r.lower() print(r)
1,000
PYTHON3
#include <bits/stdc++.h> using namespace std; int n, c; int dp[8]; char s[3]; int main() { scanf("%d", &n); for (int i = 1; i < 8; ++i) dp[i] = 1e9; for (int k = 1; k <= n; ++k) { scanf("%d%s", &c, s); int status = 0; int len = strlen(s); for (int i = 0; i < len; ++i) status |= 1 << (s[i] - 'A'); for (int i = 0; i < 8; ++i) dp[i | status] = min(dp[i | status], dp[i] + c); } printf("%d\n", dp[7] == 1e9 ? -1 : dp[7]); return 0; }
1,200
CPP
#include <bits/stdc++.h> using namespace std; const int N = 100005; const int inf = 1000000009; int rd() { char c = getchar(); int t = 0, f = 1; while (!isdigit(c)) f = (c == '-') ? -1 : 1, c = getchar(); while (isdigit(c)) t = t * 10 + c - 48, c = getchar(); return t * f; } void wt(int x) { if (x < 0) putchar('-'), wt(-x); else { if (x > 9) wt(x / 10); putchar(x % 10 + 48); } } long long s[N], Ans[N]; vector<pair<int, int> > vec[N]; int n, m, A[N], l, r, mid, x, id, top, Res, stk[N]; double slope(int j, int k) { return 1.0 * ((s[k] - 1ll * A[k] * k) - (s[j] - 1ll * A[j] * j)) / (A[k] - A[j]); } int main() { n = rd(); for (int i = ((int)1); i <= ((int)n); i++) A[i] = rd(), s[i] = s[i - 1] + A[i]; m = rd(); for (int i = ((int)1); i <= ((int)m); i++) { l = rd(), r = rd(); vec[r].push_back(make_pair(l, i)); } for (int i = ((int)1); i <= ((int)n); i++) { while (top > 0 && A[i] <= A[stk[top]]) top--; while (top > 1 && slope(i, stk[top]) >= slope(stk[top], stk[top - 1])) top--; stk[++top] = i; for (int j = ((int)0); j <= ((int)vec[i].size() - 1); j++) { x = vec[i][j].first, id = vec[i][j].second; l = lower_bound(stk + 1, stk + top + 1, i - x + 1) - stk; r = top - 1, Res = i; while (l <= r) { mid = l + r >> 1; if (slope(stk[mid + 1], stk[mid]) <= x - i) r = mid - 1, Res = stk[mid]; else l = mid + 1; } Ans[id] = (s[i] - s[Res]) + 1ll * A[Res] * (x - i + Res); } } for (int i = ((int)1); i <= ((int)m); i++) printf("%I64d\n", Ans[i]); return 0; }
2,900
CPP
#include <bits/stdc++.h> using namespace std; struct person { long long k, a, b; person(int x = 0, int y = 0, int z = 0) : k(x), a(y), b(z) {} }; bool comp(person x, person y) { return abs(x.a - x.b) < abs(y.a - y.b); } int n; long long s; vector<person> p; long long get_ans1(long long ans, long long d) { int i = 0; while ((d > 0) && (i < n)) { if (p[i].a <= p[i].b) { i++; continue; } ans -= min(d, p[i].k) * p[i].a; ans += min(d, p[i].k) * p[i].b; d -= min(d, p[i].k); i++; } return ans; } long long get_ans2(long long ans, long long d) { int i = 0; while ((d > 0) && (i < n)) { if (p[i].b < p[i].a) { i++; continue; } ans -= min(d, p[i].k) * p[i].b; ans += min(d, p[i].k) * p[i].a; d -= min(d, p[i].k); i++; } return ans; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> s; p.resize(n); for (int i = 0; i < n; i++) cin >> p[i].k >> p[i].a >> p[i].b; sort(p.begin(), p.end(), comp); long long cur1 = 0, cur2 = 0, ans = 0, all = 0; for (int i = 0; i < n; i++) { if (p[i].a > p[i].b) cur1 += p[i].k, ans += p[i].k * p[i].a; else cur2 += p[i].k, ans += p[i].k * p[i].b; all += p[i].k; } long long k0 = (all - 1) / s + 1; long long k1 = (cur1 - 1) / s + 1; long long k2 = (cur2 - 1) / s + 1; if (k0 == k1 + k2) { cout << ans << "\n"; return 0; } long long d1 = cur1 - (cur1 / s) * s, d2 = cur2 - (cur2 / s) * s; cout << max(get_ans1(ans, d1), get_ans2(ans, d2)); return 0; }
1,900
CPP