solution
stringlengths
10
159k
difficulty
int64
0
3.5k
language
stringclasses
2 values
a=int(input()) for i in range(a): b=input() s=b i=2 while i<len(b): s=s[:i]+s[i+1:] i=i+1 print(s)
800
PYTHON3
# -*- coding: utf-8 -*- """ Created on Tue Feb 27 20:06:06 2018 @author: hp """ #read the input start = input() end = input() x1 = ord(start[0]) - ord('a') + 1 y1 = eval(start[1]) x2 = ord(end[0]) - ord('a') + 1 y2 = eval(end[1]) #number of steps steps = max(abs(x1 - x2),abs(y1 - y2)) print(steps) #find the way while (x1 != x2 or y1 != y2): if x1 < x2: print('R',end = '') x1 += 1 elif x1 > x2: print('L',end = '') x1 -= 1 if y1 < y2: print('U') y1 += 1 elif y1 > y2: print('D') y1 -= 1 elif y1 == y2: print()
1,000
PYTHON3
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int vis[N]; vector<int> adj[N]; int n, m; bool cycle = false; void dfs(int x, int par) { vis[x] = 1; for (auto w : adj[x]) { if (!vis[w]) dfs(w, x); else if (vis[w] && w != par) cycle = true; } } void solve() { cin >> n >> m; int u, v; for (int i = 0; i < m; i++) { cin >> u >> v; adj[u].push_back(v); adj[v].push_back(u); } int ans = 0; for (int i = 1; i < n + 1; i++) { if (!vis[i]) { ans++; dfs(i, 0); if (cycle) ans--; } cycle = false; } cout << ans; return; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; while (t--) solve(); return 0; }
1,600
CPP
#include <bits/stdc++.h> using namespace std; vector<vector<int>> adj(1005); vector<int> vis(1005, 0); void dfs(int root) { vis[root]++; for (long long int i = 0; i < adj[root].size(); i++) { if (!vis[adj[root][i]]) { dfs(adj[root][i]); } } return; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, m, a, b; cin >> n >> m; for (long long int i = 0; i < m; i++) { cin >> a >> b; adj[a].push_back(b); adj[b].push_back(a); } dfs(1); if (m != n - 1) { cout << "no\n"; return 0; } for (long long int i = 1; i < n + 1; i++) { if (!vis[i]) { cout << "no\n"; return 0; } } cout << "yes\n"; return 0; }
1,300
CPP
from collections import Counter from collections import defaultdict from collections import deque import math import heapq import sys import io, os input = sys.stdin.readline # input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline from bisect import * rs = lambda: input().strip() ri = lambda: int(input()) rl = lambda: list(map(int, input().strip().split())) rls = lambda: list(map(str, input().split())) t=int(input()) for _ in range(0,t): n=int(input()) if(n%4==0): print("YES") else: print("NO")
800
PYTHON3
n=int(input()) a=list(map(int,input().split())) b=[] c=[] for i in range(1,n): b.append(a[i]-a[i-1]) fd=max(b) for j in range(2,n): c.append(a[j]-a[j-2]) ad=min(c) #print(fd,ad) if(fd>ad): print(fd) else: print(ad)
900
PYTHON3
#include <bits/stdc++.h> using namespace std; struct node { long long int r, len, c; friend bool operator<(node a, node b) { return a.r > b.r; } }; struct cd { long long int l, r, c; }; long long int mi[200005]; const long long int inf = 3000000000; vector<cd> v; bool cmp(cd a, cd b) { if (a.l == b.l) return a.r < b.r; return a.l < b.l; } int main() { long long int n, x; while (cin >> n >> x) { long long int a, b, c; long long int ans = inf; v.clear(); fill(mi, mi + 200000, inf); priority_queue<node> upt; for (long long int i = 0; i < n; i++) { cin >> a >> b >> c; v.push_back((cd){a, b, c}); } sort(v.begin(), v.end(), cmp); for (int i = 0; i < v.size(); i++) { while (!upt.empty()) { node check = upt.top(); if (v[i].l <= check.r) break; upt.pop(); if (mi[check.len] > check.c) mi[check.len] = check.c; } cd now = v[i]; long long int len = now.r - now.l + 1; long long int f = x - len; upt.push((node){now.r, len, now.c}); if (f <= 0) continue; if (now.c + mi[f] < ans) ans = now.c + mi[f]; } if (ans != inf) cout << ans << endl; else cout << -1 << endl; } return 0; }
1,600
CPP
#include <bits/stdc++.h> using namespace std; const long long int INF = 1e18; const int N = 1e5 + 7; const int MOD = 1e9 + 7; inline long long int Max(const long long int &x, const long long int &y) { return x > y ? x : y; } inline long long int Min(const long long int &x, const long long int &y) { return x > y ? y : x; } inline int read() { char ch = getchar(); int x = 0, f = 1; while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while ('0' <= ch && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } inline long long int readl() { char ch = getchar(); long long int x = 0, f = 1; while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while ('0' <= ch && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } long long int dp[33][2][2][2][2]; int limit[33][2]; long long int dfs(int len, bool l1, bool l2, bool r1, bool r2) { if (len == 0) return 1; long long int &res = dp[len][l1][l2][r1][r2]; if (res >= 0) return res; int d1 = (l1 ? limit[len][0] : 0), u1 = (r1 ? limit[len][1] : 1); int d2 = (l2 ? limit[len][0] : 0), u2 = (r2 ? limit[len][1] : 1); res = 0; for (int i = d1; i <= u1; i++) { for (int j = d2; j <= u2; j++) { if (i == 0 || j == 0) { res += dfs(len - 1, l1 & (i == d1), l2 & (j == d2), r1 & (i == u1), r2 & (j == u2)); } } } return res; } long long int cal(int l, int r) { int lenl = 0, lenr = 0; while (r) { limit[++lenr][1] = r % 2; r /= 2; } while (l) { limit[++lenl][0] = l % 2; l /= 2; } for (int i = lenl + 1; i <= lenr; i++) limit[i][0] = 0; return dfs(lenr, 1, 1, 1, 1); } int main() { int T = read(); while (T--) { memset(dp, -1, sizeof dp); int l = read(), r = readl(); cout << cal(l, r) << endl; } return 0; }
2,300
CPP
#include <bits/stdc++.h> using namespace std; const int MAXN = 1 << 18; int N; int p[MAXN]; int data[MAXN]; int find(int u) { return (data[u] < 0) ? u : data[u] = find(data[u]); } void join(int u, int v) { u = find(u); v = find(v); if (u != v) { data[u] += data[v]; data[v] = u; } } int main() { ios_base::sync_with_stdio(0); memset(data, -1, sizeof data); cin >> N; for (int i = 0; i < N; ++i) { cin >> p[i]; p[i]--; } string S; cin >> S; for (int i = 0; i < (int)S.size(); ++i) { if (S[i] == '1') join(i, i + 1); } for (int i = 0; i < N; ++i) { if (find(p[i]) != find(i)) { cout << "NO\n"; return 0; } } cout << "YES\n"; return 0; }
1,400
CPP
#include <bits/stdc++.h> using namespace std; const string s = "`1234567890-=qwertyuiop[]\\asdfghjkl;'zxcvbnm,./"; char dir, ch; char nxt(char ch, int sh) { for (int i = 0; i < s.size(); ++i) { if (s[i] == ch) return s[i + sh]; } } int main() { cin >> dir; cin.ignore(); while (cin >> ch) { if (dir == 'R') printf("%c", nxt(ch, -1)); else printf("%c", nxt(ch, +1)); } }
900
CPP
n=int(input()) a=input() print(sum(a[i]==a[i+1] for i in range(0,n-1)))
800
PYTHON3
#include <bits/stdc++.h> int main() { int a[10], count = 0; int i, j, k; for (i = 1; i < 5; i++) { scanf("%d", &a[i]); } for (;;) { if (a[1] == 1) { break; } if (a[1] % 2 == 0) { if (a[2] % 2 == 1) { a[2] += 1; a[3] += 1; printf("+2\n"); count++; } if (a[2] % 2 == 0) { a[1] /= 2; a[2] /= 2; printf("/1\n"); count++; } } else { a[1] += 1; a[2] += 1; printf("+1\n"); count++; } } for (;;) { if (a[2] == 1) { break; } if (a[2] % 2 == 0) { if (a[3] % 2 == 1) { a[3] += 1; a[4] += 1; printf("+3\n"); count++; } if (a[3] % 2 == 0) { a[2] /= 2; a[3] /= 2; printf("/2\n"); count++; } } else { a[2] += 1; a[3] += 1; printf("+2\n"); count++; } } for (;;) { if (a[3] == 1) { break; } while (a[3] % 2 == 1) { if (a[3] == 1) break; a[2] += 1; a[3] += 1; printf("+2\n"); count++; a[2] /= 2; a[3] /= 2; printf("/2\n"); count++; } while (a[4] % 2 == 1) { if (a[4] == 1) break; a[4] += 1; a[1] += 1; printf("+4\n"); count++; a[4] /= 2; a[1] /= 2; printf("/4\n"); count++; } if (a[3] == 1) ; else if (a[4] == 1) { for (;;) { if (a[3] == 1) { break; } if (a[3] == 2) { a[2] += 1; a[3] += 1; printf("+2\n"); count++; a[3] += 1; a[4] += 1; printf("+3\n"); count++; a[2] /= 2; a[3] /= 2; printf("/2\n"); count++; a[3] /= 2; a[4] /= 2; printf("/3\n"); count++; } if (a[3] % 2 == 1) { a[2] += 1; a[3] += 1; printf("+2\n"); count++; a[2] /= 2; a[3] /= 2; printf("/2\n"); count++; } if (a[3] % 2 == 0) { a[2] += 1; a[3] += 1; printf("+2\n"); count++; a[1] += 1; a[2] += 1; printf("+1\n"); count++; a[2] += 1; a[3] += 1; printf("+2\n"); count++; a[1] /= 2; a[2] /= 2; printf("/1\n"); count++; a[2] /= 2; a[3] /= 2; printf("/2\n"); count++; } } } else { a[3] /= 2; a[4] /= 2; printf("/3\n"); count++; } } for (;;) { if (a[4] == 1) { break; } if (a[4] == 2) { a[3] += 1; a[4] += 1; printf("+3\n"); count++; a[4] += 1; a[1] += 1; printf("+4\n"); count++; a[3] /= 2; a[4] /= 2; printf("/3\n"); count++; a[4] /= 2; a[1] /= 2; printf("/4\n"); count++; } if (a[4] % 2 == 1) { a[3] += 1; a[4] += 1; printf("+3\n"); count++; a[3] /= 2; a[4] /= 2; printf("/3\n"); count++; } if (a[4] % 2 == 0) { a[3] += 1; a[4] += 1; printf("+3\n"); count++; a[2] += 1; a[3] += 1; printf("+2\n"); count++; a[3] += 1; a[4] += 1; printf("+3\n"); count++; a[2] /= 2; a[3] /= 2; printf("/2\n"); count++; a[3] /= 2; a[4] /= 2; printf("/3\n"); count++; } } return 0; }
2,200
CPP
for i in range(int(input())): a,b,n=input().split() a=int(a) b=int(b) n=int(n) if(n%3==0): print(a) elif(n%3==1): print(b) elif(n%3==2): print(a^b)
900
PYTHON3
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 10; const int mx = 999999; int n, k, q; long long f[6], dp[N]; int main() { scanf("%d", &k); for (int i = 0; i < 6; ++i) scanf("%d", &f[i]); for (int i = 1; i <= mx; ++i) { int tmp = i, ct = 0; while (tmp) { int x = tmp % 10; if (x % 3 == 0) dp[i] += f[ct] * (x / 3); ct++; tmp /= 10; } } for (int i = 0, x = 3; i < 6; ++i, x = x * 10) { int tmp = min(3 * (k - 1), mx / x); for (int j = 1; j <= tmp; tmp -= j, j <<= 1) for (int w = mx; w >= j * x; --w) dp[w] = max(dp[w], dp[w - j * x] + j * f[i]); if (tmp) { for (int w = mx; w >= tmp * x; --w) dp[w] = max(dp[w], dp[w - tmp * x] + tmp * f[i]); } } scanf("%d", &q); while (q--) { int x; scanf("%d", &x); printf("%lld\n", dp[x]); } return 0; }
2,900
CPP
#include <bits/stdc++.h> using namespace std; const double g = 10.0, eps = 1e-12; const int N = 100000 + 10, maxn = 100000 + 10, inf = 0x3f3f3f3f, INF = 0x3f3f3f3f3f3f3f3f; int main() { long long n, m; scanf("%lld%lld", &n, &m); while (n && m) { if (n >= 2 * m) n %= 2 * m; else if (m >= 2 * n) m %= 2 * n; else break; } printf("%lld %lld\n", n, m); return 0; }
1,100
CPP
def main(a, b, c, d): if b >= a: return b if c <= d: return -1 else: x = int(abs(a - b)/abs(d - c)) if (abs(a - b) % abs(d - c)) != 0: x = x + 1 return b + (x*c) if __name__ == '__main__': t = int(input()) for t_itr in range(t): abcd = list(map(int, input().rstrip().split())) a = abcd[0] b = abcd[1] c = abcd[2] d = abcd[3] res = main(a, b, c, d) print(res)
900
PYTHON3
#include <bits/stdc++.h> using namespace std; const int maxn = 100010; int n, m, h, t, maxv; int e[maxn][2]; set<int> mp[maxn]; vector<int> g[maxn]; vector<int> xv, yv; set<int> comm; bool check(int x, int y, vector<int> &xv, vector<int> &yv, set<int> &comm) { int lx = max(0, (int)(h - xv.size())); int ly = max(0, (int)(t - yv.size())); if (comm.size() >= lx + ly) { printf("YES\n"); printf("%d %d\n", x, y); set<int>::iterator it = comm.begin(); int mx = min((int)xv.size(), h); for (int i = 0; i < mx; i++) printf("%d ", xv[i]); for (int i = 0; i < lx; i++) { printf("%d ", *it); it++; } printf("\n"); int my = min((int)yv.size(), t); for (int i = 0; i < my; i++) printf("%d ", yv[i]); for (int i = 0; i < ly; i++) { printf("%d ", *it); it++; } printf("\n"); return true; } return false; } bool solve(int x, int y) { if (mp[x].size() <= h || mp[y].size() <= t) return false; int cnt = mp[x].size() - 1; for (int i = 0; i < g[y].size() && cnt < h + t; i++) { int tx = g[y][i]; if (tx == x) continue; if (mp[x].count(tx) == 0) cnt++; } if (cnt < h + t) return false; xv.clear(); yv.clear(); comm.clear(); for (set<int>::iterator it = mp[x].begin(); it != mp[x].end() && xv.size() <= h && comm.size() <= maxv; it++) { int ty = *it; if (ty == y) continue; if (mp[y].find(ty) != mp[y].end()) comm.insert(ty); else xv.push_back(ty); } for (set<int>::iterator it = mp[y].begin(); it != mp[y].end() && yv.size() <= t && comm.size() <= maxv; it++) { int tx = *it; if (tx == x) continue; if (mp[x].find(tx) != mp[x].end()) comm.insert(tx); else yv.push_back(tx); } if (check(x, y, xv, yv, comm)) return true; return false; } int main() { scanf("%d%d%d%d", &n, &m, &h, &t); maxv = h + t; for (int i = 1; i <= n; i++) mp[i].clear(); for (int i = 0; i < m; i++) { int tx, ty; scanf("%d%d", &tx, &ty); mp[tx].insert(ty); mp[ty].insert(tx); g[tx].push_back(ty); g[ty].push_back(tx); } int flags = false; for (int i = 1; i <= n; i++) if (flags == false) for (int j = 0; j < g[i].size(); j++) { if (solve(i, g[i][j])) { flags = true; break; } } if (!flags) printf("NO\n"); return 0; }
2,000
CPP
k = int(input()) num = 10 mas = [6200101, 6200110, 6200200, 6201001, 6201010, 6201100, 6202000, 6210001, 6210010, 6210100, 6211000, 6220000, 6300001, 6300010, 6300100, 6301000, 6310000, 6400000, 7000003, 7000012, 7000021, 7000030, 7000102, 7000111, 7000120, 7000201, 7000210, 7000300, 7001002, 7001011, 7001020, 7001101, 7001110, 7001200, 7002001, 7002010, 7002100, 7003000, 7010002, 7010011, 7010020, 7010101, 7010110, 7010200, 7011001, 7011010, 7011100, 7012000, 7020001, 7020010, 7020100, 7021000, 7030000, 7100002, 7100011, 7100020, 7100101, 7100110, 7100200, 7101001, 7101010, 7101100, 7102000, 7110001, 7110010, 7110100, 7111000, 7120000, 7200001, 7200010, 7200100, 7201000, 7210000, 7300000, 8000002, 8000011, 8000020, 8000101, 8000110, 8000200, 8001001, 8001010, 8001100, 8002000, 8010001, 8010010, 8010100, 8011000, 8020000, 8100001, 8100010, 8100100, 8101000, 8110000, 8200000, 9000001, 9000010, 9000100, 9001000, 9010000, 9100000, 10000009, 10000018, 10000027, 10000036, 10000045, 10000054, 10000063, 10000072, 10000081, 10000090, 10000108, 10000117, 10000126, 10000135, 10000144, 10000153, 10000162, 10000171, 10000180, 10000207, 10000216, 10000225, 10000234, 10000243, 10000252, 10000261, 10000270, 10000306, 10000315, 10000324, 10000333, 10000342, 10000351, 10000360, 10000405, 10000414, 10000423, 10000432, 10000441, 10000450, 10000504, 10000513, 10000522, 10000531, 10000540, 10000603, 10000612, 10000621, 10000630, 10000702, 10000711, 10000720, 10000801, 10000810, 10000900, 10001008, 10001017, 10001026, 10001035, 10001044, 10001053, 10001062, 10001071, 10001080, 10001107, 10001116, 10001125, 10001134, 10001143, 10001152, 10001161, 10001170, 10001206, 10001215, 10001224, 10001233, 10001242, 10001251, 10001260, 10001305, 10001314, 10001323, 10001332, 10001341, 10001350, 10001404, 10001413, 10001422, 10001431, 10001440, 10001503, 10001512, 10001521, 10001530, 10001602, 10001611, 10001620, 10001701, 10001710, 10001800, 10002007, 10002016, 10002025, 10002034, 10002043, 10002052, 10002061, 10002070, 10002106, 10002115, 10002124, 10002133, 10002142, 10002151, 10002160, 10002205, 10002214, 10002223, 10002232, 10002241, 10002250, 10002304, 10002313, 10002322, 10002331, 10002340, 10002403, 10002412, 10002421, 10002430, 10002502, 10002511, 10002520, 10002601, 10002610, 10002700, 10003006, 10003015, 10003024, 10003033, 10003042, 10003051, 10003060, 10003105, 10003114, 10003123, 10003132, 10003141, 10003150, 10003204, 10003213, 10003222, 10003231, 10003240, 10003303, 10003312, 10003321, 10003330, 10003402, 10003411, 10003420, 10003501, 10003510, 10003600, 10004005, 10004014, 10004023, 10004032, 10004041, 10004050, 10004104, 10004113, 10004122, 10004131, 10004140, 10004203, 10004212, 10004221, 10004230, 10004302, 10004311, 10004320, 10004401, 10004410, 10004500, 10005004, 10005013, 10005022, 10005031, 10005040, 10005103, 10005112, 10005121, 10005130, 10005202, 10005211, 10005220, 10005301, 10005310, 10005400, 10006003, 10006012, 10006021, 10006030, 10006102, 10006111, 10006120, 10006201, 10006210, 10006300, 10007002, 10007011, 10007020, 10007101, 10007110, 10007200, 10008001, 10008010, 10008100, 10009000, 10010008, 10010017, 10010026, 10010035, 10010044, 10010053, 10010062, 10010071, 10010080, 10010107, 10010116, 10010125, 10010134, 10010143, 10010152, 10010161, 10010170, 10010206, 10010215, 10010224, 10010233, 10010242, 10010251, 10010260, 10010305, 10010314, 10010323, 10010332, 10010341, 10010350, 10010404, 10010413, 10010422, 10010431, 10010440, 10010503, 10010512, 10010521, 10010530, 10010602, 10010611, 10010620, 10010701, 10010710, 10010800, 10011007, 10011016, 10011025, 10011034, 10011043, 10011052, 10011061, 10011070, 10011106, 10011115, 10011124, 10011133, 10011142, 10011151, 10011160, 10011205, 10011214, 10011223, 10011232, 10011241, 10011250, 10011304, 10011313, 10011322, 10011331, 10011340, 10011403, 10011412, 10011421, 10011430, 10011502, 10011511, 10011520, 10011601, 10011610, 10011700, 10012006, 10012015, 10012024, 10012033, 10012042, 10012051, 10012060, 10012105, 10012114, 10012123, 10012132, 10012141, 10012150, 10012204, 10012213, 10012222, 10012231, 10012240, 10012303, 10012312, 10012321, 10012330, 10012402, 10012411, 10012420, 10012501, 10012510, 10012600, 10013005, 10013014, 10013023, 10013032, 10013041, 10013050, 10013104, 10013113, 10013122, 10013131, 10013140, 10013203, 10013212, 10013221, 10013230, 10013302, 10013311, 10013320, 10013401, 10013410, 10013500, 10014004, 10014013, 10014022, 10014031, 10014040, 10014103, 10014112, 10014121, 10014130, 10014202, 10014211, 10014220, 10014301, 10014310, 10014400, 10015003, 10015012, 10015021, 10015030, 10015102, 10015111, 10015120, 10015201, 10015210, 10015300, 10016002, 10016011, 10016020, 10016101, 10016110, 10016200, 10017001, 10017010, 10017100, 10018000, 10020007, 10020016, 10020025, 10020034, 10020043, 10020052, 10020061, 10020070, 10020106, 10020115, 10020124, 10020133, 10020142, 10020151, 10020160, 10020205, 10020214, 10020223, 10020232, 10020241, 10020250, 10020304, 10020313, 10020322, 10020331, 10020340, 10020403, 10020412, 10020421, 10020430, 10020502, 10020511, 10020520, 10020601, 10020610, 10020700, 10021006, 10021015, 10021024, 10021033, 10021042, 10021051, 10021060, 10021105, 10021114, 10021123, 10021132, 10021141, 10021150, 10021204, 10021213, 10021222, 10021231, 10021240, 10021303, 10021312, 10021321, 10021330, 10021402, 10021411, 10021420, 10021501, 10021510, 10021600, 10022005, 10022014, 10022023, 10022032, 10022041, 10022050, 10022104, 10022113, 10022122, 10022131, 10022140, 10022203, 10022212, 10022221, 10022230, 10022302, 10022311, 10022320, 10022401, 10022410, 10022500, 10023004, 10023013, 10023022, 10023031, 10023040, 10023103, 10023112, 10023121, 10023130, 10023202, 10023211, 10023220, 10023301, 10023310, 10023400, 10024003, 10024012, 10024021, 10024030, 10024102, 10024111, 10024120, 10024201, 10024210, 10024300, 10025002, 10025011, 10025020, 10025101, 10025110, 10025200, 10026001, 10026010, 10026100, 10027000, 10030006, 10030015, 10030024, 10030033, 10030042, 10030051, 10030060, 10030105, 10030114, 10030123, 10030132, 10030141, 10030150, 10030204, 10030213, 10030222, 10030231, 10030240, 10030303, 10030312, 10030321, 10030330, 10030402, 10030411, 10030420, 10030501, 10030510, 10030600, 10031005, 10031014, 10031023, 10031032, 10031041, 10031050, 10031104, 10031113, 10031122, 10031131, 10031140, 10031203, 10031212, 10031221, 10031230, 10031302, 10031311, 10031320, 10031401, 10031410, 10031500, 10032004, 10032013, 10032022, 10032031, 10032040, 10032103, 10032112, 10032121, 10032130, 10032202, 10032211, 10032220, 10032301, 10032310, 10032400, 10033003, 10033012, 10033021, 10033030, 10033102, 10033111, 10033120, 10033201, 10033210, 10033300, 10034002, 10034011, 10034020, 10034101, 10034110, 10034200, 10035001, 10035010, 10035100, 10036000, 10040005, 10040014, 10040023, 10040032, 10040041, 10040050, 10040104, 10040113, 10040122, 10040131, 10040140, 10040203, 10040212, 10040221, 10040230, 10040302, 10040311, 10040320, 10040401, 10040410, 10040500, 10041004, 10041013, 10041022, 10041031, 10041040, 10041103, 10041112, 10041121, 10041130, 10041202, 10041211, 10041220, 10041301, 10041310, 10041400, 10042003, 10042012, 10042021, 10042030, 10042102, 10042111, 10042120, 10042201, 10042210, 10042300, 10043002, 10043011, 10043020, 10043101, 10043110, 10043200, 10044001, 10044010, 10044100, 10045000, 10050004, 10050013, 10050022, 10050031, 10050040, 10050103, 10050112, 10050121, 10050130, 10050202, 10050211, 10050220, 10050301, 10050310, 10050400, 10051003, 10051012, 10051021, 10051030, 10051102, 10051111, 10051120, 10051201, 10051210, 10051300, 10052002, 10052011, 10052020, 10052101, 10052110, 10052200, 10053001, 10053010, 10053100, 10054000, 10060003, 10060012, 10060021, 10060030, 10060102, 10060111, 10060120, 10060201, 10060210, 10060300, 10061002, 10061011, 10061020, 10061101, 10061110, 10061200, 10062001, 10062010, 10062100, 10063000, 10070002, 10070011, 10070020, 10070101, 10070110, 10070200, 10071001, 10071010, 10071100, 10072000, 10080001, 10080010, 10080100, 10081000, 10090000, 10100008, 10100017, 10100026, 10100035, 10100044, 10100053, 10100062, 10100071, 10100080, 10100107, 10100116, 10100125, 10100134, 10100143, 10100152, 10100161, 10100170, 10100206, 10100215, 10100224, 10100233, 10100242, 10100251, 10100260, 10100305, 10100314, 10100323, 10100332, 10100341, 10100350, 10100404, 10100413, 10100422, 10100431, 10100440, 10100503, 10100512, 10100521, 10100530, 10100602, 10100611, 10100620, 10100701, 10100710, 10100800, 10101007, 10101016, 10101025, 10101034, 10101043, 10101052, 10101061, 10101070, 10101106, 10101115, 10101124, 10101133, 10101142, 10101151, 10101160, 10101205, 10101214, 10101223, 10101232, 10101241, 10101250, 10101304, 10101313, 10101322, 10101331, 10101340, 10101403, 10101412, 10101421, 10101430, 10101502, 10101511, 10101520, 10101601, 10101610, 10101700, 10102006, 10102015, 10102024, 10102033, 10102042, 10102051, 10102060, 10102105, 10102114, 10102123, 10102132, 10102141, 10102150, 10102204, 10102213, 10102222, 10102231, 10102240, 10102303, 10102312, 10102321, 10102330, 10102402, 10102411, 10102420, 10102501, 10102510, 10102600, 10103005, 10103014, 10103023, 10103032, 10103041, 10103050, 10103104, 10103113, 10103122, 10103131, 10103140, 10103203, 10103212, 10103221, 10103230, 10103302, 10103311, 10103320, 10103401, 10103410, 10103500, 10104004, 10104013, 10104022, 10104031, 10104040, 10104103, 10104112, 10104121, 10104130, 10104202, 10104211, 10104220, 10104301, 10104310, 10104400, 10105003, 10105012, 10105021, 10105030, 10105102, 10105111, 10105120, 10105201, 10105210, 10105300, 10106002, 10106011, 10106020, 10106101, 10106110, 10106200, 10107001, 10107010, 10107100, 10108000, 10110007, 10110016, 10110025, 10110034, 10110043, 10110052, 10110061, 10110070, 10110106, 10110115, 10110124, 10110133, 10110142, 10110151, 10110160, 10110205, 10110214, 10110223, 10110232, 10110241, 10110250, 10110304, 10110313, 10110322, 10110331, 10110340, 10110403, 10110412, 10110421, 10110430, 10110502, 10110511, 10110520, 10110601, 10110610, 10110700, 10111006, 10111015, 10111024, 10111033, 10111042, 10111051, 10111060, 10111105, 10111114, 10111123, 10111132, 10111141, 10111150, 10111204, 10111213, 10111222, 10111231, 10111240, 10111303, 10111312, 10111321, 10111330, 10111402, 10111411, 10111420, 10111501, 10111510, 10111600, 10112005, 10112014, 10112023, 10112032, 10112041, 10112050, 10112104, 10112113, 10112122, 10112131, 10112140, 10112203, 10112212, 10112221, 10112230, 10112302, 10112311, 10112320, 10112401, 10112410, 10112500, 10113004, 10113013, 10113022, 10113031, 10113040, 10113103, 10113112, 10113121, 10113130, 10113202, 10113211, 10113220, 10113301, 10113310, 10113400, 10114003, 10114012, 10114021, 10114030, 10114102, 10114111, 10114120, 10114201, 10114210, 10114300, 10115002, 10115011, 10115020, 10115101, 10115110, 10115200, 10116001, 10116010, 10116100, 10117000, 10120006, 10120015, 10120024, 10120033, 10120042, 10120051, 10120060, 10120105, 10120114, 10120123, 10120132, 10120141, 10120150, 10120204, 10120213, 10120222, 10120231, 10120240, 10120303, 10120312, 10120321, 10120330, 10120402, 10120411, 10120420, 10120501, 10120510, 10120600, 10121005, 10121014, 10121023, 10121032, 10121041, 10121050, 10121104, 10121113, 10121122, 10121131, 10121140, 10121203, 10121212, 10121221, 10121230, 10121302, 10121311, 10121320, 10121401, 10121410, 10121500, 10122004, 10122013, 10122022, 10122031, 10122040, 10122103, 10122112, 10122121, 10122130, 10122202, 10122211, 10122220, 10122301, 10122310, 10122400, 10123003, 10123012, 10123021, 10123030, 10123102, 10123111, 10123120, 10123201, 10123210, 10123300, 10124002, 10124011, 10124020, 10124101, 10124110, 10124200, 10125001, 10125010, 10125100, 10126000, 10130005, 10130014, 10130023, 10130032, 10130041, 10130050, 10130104, 10130113, 10130122, 10130131, 10130140, 10130203, 10130212, 10130221, 10130230, 10130302, 10130311, 10130320, 10130401, 10130410, 10130500, 10131004, 10131013, 10131022, 10131031, 10131040, 10131103, 10131112, 10131121, 10131130, 10131202, 10131211, 10131220, 10131301, 10131310, 10131400, 10132003, 10132012, 10132021, 10132030, 10132102, 10132111, 10132120, 10132201, 10132210, 10132300, 10133002, 10133011, 10133020, 10133101, 10133110, 10133200, 10134001, 10134010, 10134100, 10135000, 10140004, 10140013, 10140022, 10140031, 10140040, 10140103, 10140112, 10140121, 10140130, 10140202, 10140211, 10140220, 10140301, 10140310, 10140400, 10141003, 10141012, 10141021, 10141030, 10141102, 10141111, 10141120, 10141201, 10141210, 10141300, 10142002, 10142011, 10142020, 10142101, 10142110, 10142200, 10143001, 10143010, 10143100, 10144000, 10150003, 10150012, 10150021, 10150030, 10150102, 10150111, 10150120, 10150201, 10150210, 10150300, 10151002, 10151011, 10151020, 10151101, 10151110, 10151200, 10152001, 10152010, 10152100, 10153000, 10160002, 10160011, 10160020, 10160101, 10160110, 10160200, 10161001, 10161010, 10161100, 10162000, 10170001, 10170010, 10170100, 10171000, 10180000, 10200007, 10200016, 10200025, 10200034, 10200043, 10200052, 10200061, 10200070, 10200106, 10200115, 10200124, 10200133, 10200142, 10200151, 10200160, 10200205, 10200214, 10200223, 10200232, 10200241, 10200250, 10200304, 10200313, 10200322, 10200331, 10200340, 10200403, 10200412, 10200421, 10200430, 10200502, 10200511, 10200520, 10200601, 10200610, 10200700, 10201006, 10201015, 10201024, 10201033, 10201042, 10201051, 10201060, 10201105, 10201114, 10201123, 10201132, 10201141, 10201150, 10201204, 10201213, 10201222, 10201231, 10201240, 10201303, 10201312, 10201321, 10201330, 10201402, 10201411, 10201420, 10201501, 10201510, 10201600, 10202005, 10202014, 10202023, 10202032, 10202041, 10202050, 10202104, 10202113, 10202122, 10202131, 10202140, 10202203, 10202212, 10202221, 10202230, 10202302, 10202311, 10202320, 10202401, 10202410, 10202500, 10203004, 10203013, 10203022, 10203031, 10203040, 10203103, 10203112, 10203121, 10203130, 10203202, 10203211, 10203220, 10203301, 10203310, 10203400, 10204003, 10204012, 10204021, 10204030, 10204102, 10204111, 10204120, 10204201, 10204210, 10204300, 10205002, 10205011, 10205020, 10205101, 10205110, 10205200, 10206001, 10206010, 10206100, 10207000, 10210006, 10210015, 10210024, 10210033, 10210042, 10210051, 10210060, 10210105, 10210114, 10210123, 10210132, 10210141, 10210150, 10210204, 10210213, 10210222, 10210231, 10210240, 10210303, 10210312, 10210321, 10210330, 10210402, 10210411, 10210420, 10210501, 10210510, 10210600, 10211005, 10211014, 10211023, 10211032, 10211041, 10211050, 10211104, 10211113, 10211122, 10211131, 10211140, 10211203, 10211212, 10211221, 10211230, 10211302, 10211311, 10211320, 10211401, 10211410, 10211500, 10212004, 10212013, 10212022, 10212031, 10212040, 10212103, 10212112, 10212121, 10212130, 10212202, 10212211, 10212220, 10212301, 10212310, 10212400, 10213003, 10213012, 10213021, 10213030, 10213102, 10213111, 10213120, 10213201, 10213210, 10213300, 10214002, 10214011, 10214020, 10214101, 10214110, 10214200, 10215001, 10215010, 10215100, 10216000, 10220005, 10220014, 10220023, 10220032, 10220041, 10220050, 10220104, 10220113, 10220122, 10220131, 10220140, 10220203, 10220212, 10220221, 10220230, 10220302, 10220311, 10220320, 10220401, 10220410, 10220500, 10221004, 10221013, 10221022, 10221031, 10221040, 10221103, 10221112, 10221121, 10221130, 10221202, 10221211, 10221220, 10221301, 10221310, 10221400, 10222003, 10222012, 10222021, 10222030, 10222102, 10222111, 10222120, 10222201, 10222210, 10222300, 10223002, 10223011, 10223020, 10223101, 10223110, 10223200, 10224001, 10224010, 10224100, 10225000, 10230004, 10230013, 10230022, 10230031, 10230040, 10230103, 10230112, 10230121, 10230130, 10230202, 10230211, 10230220, 10230301, 10230310, 10230400, 10231003, 10231012, 10231021, 10231030, 10231102, 10231111, 10231120, 10231201, 10231210, 10231300, 10232002, 10232011, 10232020, 10232101, 10232110, 10232200, 10233001, 10233010, 10233100, 10234000, 10240003, 10240012, 10240021, 10240030, 10240102, 10240111, 10240120, 10240201, 10240210, 10240300, 10241002, 10241011, 10241020, 10241101, 10241110, 10241200, 10242001, 10242010, 10242100, 10243000, 10250002, 10250011, 10250020, 10250101, 10250110, 10250200, 10251001, 10251010, 10251100, 10252000, 10260001, 10260010, 10260100, 10261000, 10270000, 10300006, 10300015, 10300024, 10300033, 10300042, 10300051, 10300060, 10300105, 10300114, 10300123, 10300132, 10300141, 10300150, 10300204, 10300213, 10300222, 10300231, 10300240, 10300303, 10300312, 10300321, 10300330, 10300402, 10300411, 10300420, 10300501, 10300510, 10300600, 10301005, 10301014, 10301023, 10301032, 10301041, 10301050, 10301104, 10301113, 10301122, 10301131, 10301140, 10301203, 10301212, 10301221, 10301230, 10301302, 10301311, 10301320, 10301401, 10301410, 10301500, 10302004, 10302013, 10302022, 10302031, 10302040, 10302103, 10302112, 10302121, 10302130, 10302202, 10302211, 10302220, 10302301, 10302310, 10302400, 10303003, 10303012, 10303021, 10303030, 10303102, 10303111, 10303120, 10303201, 10303210, 10303300, 10304002, 10304011, 10304020, 10304101, 10304110, 10304200, 10305001, 10305010, 10305100, 10306000, 10310005, 10310014, 10310023, 10310032, 10310041, 10310050, 10310104, 10310113, 10310122, 10310131, 10310140, 10310203, 10310212, 10310221, 10310230, 10310302, 10310311, 10310320, 10310401, 10310410, 10310500, 10311004, 10311013, 10311022, 10311031, 10311040, 10311103, 10311112, 10311121, 10311130, 10311202, 10311211, 10311220, 10311301, 10311310, 10311400, 10312003, 10312012, 10312021, 10312030, 10312102, 10312111, 10312120, 10312201, 10312210, 10312300, 10313002, 10313011, 10313020, 10313101, 10313110, 10313200, 10314001, 10314010, 10314100, 10315000, 10320004, 10320013, 10320022, 10320031, 10320040, 10320103, 10320112, 10320121, 10320130, 10320202, 10320211, 10320220, 10320301, 10320310, 10320400, 10321003, 10321012, 10321021, 10321030, 10321102, 10321111, 10321120, 10321201, 10321210, 10321300, 10322002, 10322011, 10322020, 10322101, 10322110, 10322200, 10323001, 10323010, 10323100, 10324000, 10330003, 10330012, 10330021, 10330030, 10330102, 10330111, 10330120, 10330201, 10330210, 10330300, 10331002, 10331011, 10331020, 10331101, 10331110, 10331200, 10332001, 10332010, 10332100, 10333000, 10340002, 10340011, 10340020, 10340101, 10340110, 10340200, 10341001, 10341010, 10341100, 10342000, 10350001, 10350010, 10350100, 10351000, 10360000, 10400005, 10400014, 10400023, 10400032, 10400041, 10400050, 10400104, 10400113, 10400122, 10400131, 10400140, 10400203, 10400212, 10400221, 10400230, 10400302, 10400311, 10400320, 10400401, 10400410, 10400500, 10401004, 10401013, 10401022, 10401031, 10401040, 10401103, 10401112, 10401121, 10401130, 10401202, 10401211, 10401220, 10401301, 10401310, 10401400, 10402003, 10402012, 10402021, 10402030, 10402102, 10402111, 10402120, 10402201, 10402210, 10402300, 10403002, 10403011, 10403020, 10403101, 10403110, 10403200, 10404001, 10404010, 10404100, 10405000, 10410004, 10410013, 10410022, 10410031, 10410040, 10410103, 10410112, 10410121, 10410130, 10410202, 10410211, 10410220, 10410301, 10410310, 10410400, 10411003, 10411012, 10411021, 10411030, 10411102, 10411111, 10411120, 10411201, 10411210, 10411300, 10412002, 10412011, 10412020, 10412101, 10412110, 10412200, 10413001, 10413010, 10413100, 10414000, 10420003, 10420012, 10420021, 10420030, 10420102, 10420111, 10420120, 10420201, 10420210, 10420300, 10421002, 10421011, 10421020, 10421101, 10421110, 10421200, 10422001, 10422010, 10422100, 10423000, 10430002, 10430011, 10430020, 10430101, 10430110, 10430200, 10431001, 10431010, 10431100, 10432000, 10440001, 10440010, 10440100, 10441000, 10450000, 10500004, 10500013, 10500022, 10500031, 10500040, 10500103, 10500112, 10500121, 10500130, 10500202, 10500211, 10500220, 10500301, 10500310, 10500400, 10501003, 10501012, 10501021, 10501030, 10501102, 10501111, 10501120, 10501201, 10501210, 10501300, 10502002, 10502011, 10502020, 10502101, 10502110, 10502200, 10503001, 10503010, 10503100, 10504000, 10510003, 10510012, 10510021, 10510030, 10510102, 10510111, 10510120, 10510201, 10510210, 10510300, 10511002, 10511011, 10511020, 10511101, 10511110, 10511200, 10512001, 10512010, 10512100, 10513000, 10520002, 10520011, 10520020, 10520101, 10520110, 10520200, 10521001, 10521010, 10521100, 10522000, 10530001, 10530010, 10530100, 10531000, 10540000, 10600003, 10600012, 10600021, 10600030, 10600102, 10600111, 10600120, 10600201, 10600210, 10600300, 10601002, 10601011, 10601020, 10601101, 10601110, 10601200, 10602001, 10602010, 10602100, 10603000, 10610002, 10610011, 10610020, 10610101, 10610110, 10610200, 10611001, 10611010, 10611100, 10612000, 10620001, 10620010, 10620100, 10621000, 10630000, 10700002, 10700011, 10700020, 10700101, 10700110, 10700200, 10701001, 10701010, 10701100, 10702000, 10710001, 10710010, 10710100, 10711000, 10720000, 10800001, 10800010, 10800100] if k <= 7900: for i in range(k): num += 9 if sum(map(int, str(num))) != 10: while sum(map(int, str(num))) != 10: num += 9 print(num) else: print(mas[k - 7901])
1,100
PYTHON3
#include <bits/stdc++.h> using namespace std; template <class T> inline T gcd(T a, T b) { if (a < 0) return gcd(-a, b); if (b < 0) return gcd(a, -b); return (b == 0) ? a : gcd(b, a % b); } template <class T> inline T lcm(T a, T b) { if (a < 0) return lcm(-a, b); if (b < 0) return lcm(a, -b); return a * (b / gcd(a, b)); } template <class T> inline T sqr(T x) { return x * x; } template <class T> T power(T N, T P) { return (P == 0) ? 1 : N * power(N, P - 1); } long long toInt64(string s) { long long r = 0; istringstream sin(s); sin >> r; return r; } double LOG(long long N, long long B) { return (log10l(N)) / (log10l(B)); } string itoa(long long a) { if (a == 0) return "0"; string ret; for (long long i = a; i > 0; i = i / 10) ret.push_back((i % 10) + 48); reverse(ret.begin(), ret.end()); return ret; } vector<string> token(string a, string b) { const char *q = a.c_str(); while (count(b.begin(), b.end(), *q)) q++; vector<string> oot; while (*q) { const char *e = q; while (*e && !count(b.begin(), b.end(), *e)) e++; oot.push_back(string(q, e)); q = e; while (count(b.begin(), b.end(), *q)) q++; } return oot; } int Set(int N, int pos) { return N = N | (1 << pos); } int Reset(int N, int pos) { return N = N & ~(1 << pos); } int check(int N, int pos) { return (N & (1 << pos)); } int toggle(int N, int pos) { if (check(N, pos)) return N = Reset(N, pos); return N = Set(N, pos); } void PBIT(int N) { printf("("); for (int i = 10; i >= 0; i--) { bool x = check(N, i); cout << x; } puts(")"); } int dp2[102][155][4]; string s; int n; int call2(int i, int c, int d) { if (i == n) { if (c == 0) return 0; return (1 << 28); } if (dp2[i][c][d] != -1) return dp2[i][c][d]; int ret = 10000, get; if (s[i] == 'F') { if (d == 0) get = 1 + call2(i + 1, c, d); else get = -1 + call2(i + 1, c, d); ret = min(ret, get); } if (s[i] == 'T') { get = call2(i + 1, c, !d); ret = min(ret, get); } for (int ch = 1; ch <= c; ch++) { char m = s[i]; if (ch % 2 == 1) { if (s[i] == 'T') m = 'F'; else m = 'T'; } if (m == 'F') { if (d == 0) get = 1 + call2(i + 1, c - ch, d); else get = -1 + call2(i + 1, c - ch, d); ret = min(ret, get); } if (m == 'T') { get = call2(i + 1, c - ch, !d); ret = min(ret, get); } } return dp2[i][c][d] = ret; } int dp[102][155][4]; int call(int i, int c, int d) { if (i == n) { if (c == 0) return 0; return -(1 << 28); } if (dp[i][c][d] != -1) return dp[i][c][d]; int ret = -10000, get; if (s[i] == 'F') { if (d == 0) get = 1 + call(i + 1, c, d); else get = -1 + call(i + 1, c, d); ret = max(ret, get); } if (s[i] == 'T') { get = call(i + 1, c, !d); ret = max(ret, get); } for (int ch = 1; ch <= c; ch++) { char m = s[i]; if (ch % 2 == 1) { if (s[i] == 'T') m = 'F'; else m = 'T'; } if (m == 'F') { if (d == 0) get = 1 + call(i + 1, c - ch, d); else get = -1 + call(i + 1, c - ch, d); ret = max(ret, get); } if (m == 'T') { get = call(i + 1, c - ch, !d); ret = max(ret, get); } } return dp[i][c][d] = ret; } int main() { memset(dp, -1, sizeof(dp)); ; memset(dp2, -1, sizeof(dp2)); ; int k; cin >> s >> k; n = s.size(); int ret1 = call(0, k, 0); int ret2 = call2(0, k, 0); int ans = max(abs(ret1), abs(ret2)); cout << ans << endl; return 0; }
1,800
CPP
n=int(input()) a=[int(x) for x in input().split()] if(n<2): if(a[0]==15): print("DOWN") exit() if(a[0]==0): print("UP") exit() else: print("-1") exit() if(a[-1]==15): d=a[-1]-a[-2] if(d>0): print("DOWN") exit() else: print("UP") exit() if(a[-1]==15 or a[-1]==0): d=a[-1]-a[-2] if(d>0): print("DOWN") exit() else: print("UP") exit() else: d=a[-1]-a[-2] if(d>0): print("UP") else: print("DOWN")
1,100
PYTHON3
s=input() print("" +s[0].upper()+s[1:])
800
PYTHON3
#include <bits/stdc++.h> using namespace std; struct bigint { long long a = 0; void initiate() { cout << 'i' << endl; } void update() { cout << 'u' << endl; } void update(long long b) { a += b; } long long query() { return a; } }; template <typename elem_t, typename coord_t, coord_t n_inf, typename ret_t> class BIT { vector<coord_t> positions; vector<elem_t> elems; bool initiated = false; public: BIT() { positions.push_back(n_inf); } void initiate() { if (initiated) { for (elem_t &c_elem : elems) { c_elem.initiate(); } } else { initiated = true; sort(positions.begin(), positions.end()); positions.resize(unique(positions.begin(), positions.end()) - positions.begin()); elems.resize(positions.size()); } } template <typename... loc_form> void update(coord_t cord, loc_form... args) { if (initiated) { int pos = lower_bound(positions.begin(), positions.end(), cord) - positions.begin(); for (; pos < positions.size(); pos += pos & -pos) { elems[pos].update(args...); } } else { positions.push_back(cord); } } template <typename... loc_form> ret_t query(coord_t cord, loc_form... args) { ret_t res = 0; int pos = lower_bound(positions.begin(), positions.end(), cord) - positions.begin(); for (; pos > 0; pos -= pos & -pos) { res += elems[pos].query(args...); } return res; } }; struct q { int x1, x2, y1, y2; int v; int type; }; int n, m, w; int nr, mr; q todo[100111]; long long total; int main() { scanf("%d %d %d", &n, &m, &w); for (int i = 0; i < w; ++i) { scanf("%d %d %d %d %d", &todo[i].type, &todo[i].x1, &todo[i].y1, &todo[i].x2, &todo[i].y2); if (!todo[i].type) { ++todo[i].x2; ++todo[i].y2; scanf("%d", &todo[i].v); } else { --todo[i].x1; --todo[i].y1; } } BIT<bigint, int, INT_MIN, long long> x, xc, y, yc; for (int j = 0; j < w; ++j) { x.update(todo[j].x1); x.update(todo[j].x2); y.update(todo[j].y1); y.update(todo[j].y2); xc.update(todo[j].x1); xc.update(todo[j].x2); yc.update(todo[j].y1); yc.update(todo[j].y2); } x.initiate(); y.initiate(); xc.initiate(); yc.initiate(); for (int i = 0; i < w; ++i) { int x1 = todo[i].x1, x2 = todo[i].x2, y1 = todo[i].y1, y2 = todo[i].y2; long long v = todo[i].v; long long x1r = x1, x2r = x2, y1r = y1, y2r = y2; if (todo[i].type) { long long res = 0; res += xc.query(x2); res -= xc.query(x1); res += x.query(x2) * x2r; res -= x.query(x1) * x1r; res += yc.query(y2); res -= yc.query(y1); res += y.query(y2) * y2r; res -= y.query(y1) * y1r; res -= total; printf("%lld\n", res); } else { --x1r; --x2r; --y1r; --y2r; total += (x2r - x1r) * (y2r - y1r) * v; x.update(x1, v * (y2r - y1r)); x.update(x2, -v * (y2r - y1r)); xc.update(x1, -v * (y2r - y1r) * x1r); xc.update(x2, v * (y2r - y1r) * x2r); y.update(y1, v * (x2r - x1r)); y.update(y2, -v * (x2r - x1r)); yc.update(y1, -v * (x2r - x1r) * y1r); yc.update(y2, v * (x2r - x1r) * y2r); } } return 0; }
0
CPP
R=lambda:map(int, input().split()) n ,m = R() a=n-n//2 print([a+(-a)%m,-1][n<m])
1,000
PYTHON3
#include <bits/stdc++.h> using namespace std; void sober() { long long int n, x = 0, a = 0, b = 0, y = 0, sum = 0, k = 0, m = 0; cin >> n; set<long long int> sett; map<long long int, long long int> mp; vector<long long int> v(n); for (long long int i = 0; i < n; i++) cin >> v[i], sett.insert(v[i]), mp[v[i]] = i; if ((sett.size() == 1 and n == 2) or n == 1) { cout << "-1\n"; return; } cout << 1 << '\n'; cout << mp[*min_element(begin(v), end(v))] + 1; return; } signed main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long int t = 1; while (t--) { sober(); } }
1,000
CPP
N = int(input()) for n in range(N): numCol = int(input()) cols = [int(i) for i in input().split()] # print(cols) foundEven = False foundOdd = False for c in cols: if c % 2 == 1: foundOdd = True else: foundEven = True if foundOdd and foundEven: print("NO") break if not (foundOdd and foundEven): print("YES")
900
PYTHON3
#include <bits/stdc++.h> using namespace std; const int MOD = (int)1e9 + 7; const int INF = (int)1e9; const long long LINF = (long long)1e18; const long double PI = acos((long double)-1); const long double EPS = 1e-9; long long gcd(long long a, long long b) { long long r; while (b) { r = a % b; a = b; b = r; } return a; } long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } long long fpow(long long n, long long k, int p = MOD) { long long r = 1; for (; k; k >>= 1) { if (k & 1) r = r * n % p; n = n * n % p; } return r; } void addmod(int& a, int val, int p = MOD) { if ((a = (a + val)) >= p) a -= p; } void submod(int& a, int val, int p = MOD) { if ((a = (a - val)) < 0) a += p; } int mult(int a, int b, int p = MOD) { return (long long)a * b % p; } int inv(int a, int p = MOD) { return fpow(a, p - 2, p); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; string s; cin >> n >> s; int a[26] = {0}; for (int i = 0; i < n; i++) { if (s[i] != '*') a[s[i] - 'a'] = 1; } int m; cin >> m; vector<string> v; for (int i = 0; i < m; i++) { string s1; cin >> s1; int f = 0; for (int j = 0; j < n; j++) { if (s[j] == '*' && a[s1[j] - 'a'] == 1) { f = 1; break; } else if (s[j] != '*' && s[j] != s1[j]) { f = 1; break; } } if (!f) v.push_back(s1); } m = v.size(); int b[1001][26]; int ans = 0; for (int i = 0; i < m; i++) { for (int j = 0; j < 26; j++) b[i][j] = 0; for (int j = 0; j < n; j++) { if (s[j] == '*') b[i][v[i][j] - 'a']++; } } if (m == 0) { cout << 0; return 0; } for (int i = 0; i < 26; i++) { if (a[i] == 0) { int c = 0; for (int j = 0; j < m; j++) { if (b[j][i] > 0) c++; } if (c == m) ans++; } } cout << ans; return 0; }
1,500
CPP
# https://codeforces.com/contest/1335/problem/A from string import ascii_lowercase def solve(): n, a, b = map(int, input().split()) ans = None base = '' i = 0 while len(base) < a: if i < b: base += ascii_lowercase[i] i += 1 else: base += 'a' for i in range(a, n): base += base[i % a] print(base) if __name__ == '__main__': t = int(input()) while t > 0: solve() t -= 1
900
PYTHON3
#include <bits/stdc++.h> using namespace std; long long power(long long x, long long y, long long md = 1000000007) { long long res = 1; x %= md; while (y > 0) { if (y & 1) res = (res * x) % md; x = (x * x) % md; y = y >> 1; } return res % md; } long long max1(long long a, long long b, long long c = -1000000000000000000LL, long long d = -1000000000000000000LL) { long long mx1 = (a > b) ? a : b, mx2 = (c > d) ? c : d; return ((mx1 > mx2) ? mx1 : mx2); } long long fen[200005]; long long query(long long index) { index++; long long ans = 0; while (index > 0) { ans += fen[index]; index -= (index) & (-index); } return ans; } void update(long long index, long long val) { index++; while (index < 200005) { fen[index] += val; index += (index) & (-index); } } signed main() { long long n, k; cin >> n >> k; vector<pair<pair<long long, long long>, long long> > vv; for (long long i = 0; i < n; i++) { long long l, r; cin >> l >> r; vv.push_back({{l, r}, i}); update(l, 1); update(r + 1, -1); } sort(vv.begin(), vv.end()); long long p = 0; set<pair<long long, long long> > st; std::vector<long long> ans; for (long long i = 1; i <= 200000; i++) { while (p < n && vv[p].first.first == i) { st.insert({vv[p].first.second, vv[p].second}); p++; } long long q = query(i); if (q <= k) continue; long long del = q - k; for (long long j = 0; j < del; j++) { assert(st.size()); auto it = std::prev(st.end()); update(i, -1); update((*it).first + 1, 1); ans.push_back((*it).second); st.erase(it); } } cout << ans.size() << endl; for (long long i = 0; i < ans.size(); i++) cout << ans[i] + 1 << " "; }
1,800
CPP
#include <bits/stdc++.h> using namespace std; int cnt_s[33]; int cnt_t[33]; string s, t; int ls, lt, fl; int need_tree() { int i, j, k, l; for (i = 1; i <= 26; i++) { if (cnt_s[i] < cnt_t[i]) return 1; } return 0; } int isAutomation() { int i, j, k, l; i = 0; j = 0; while (i < ls) { if (j < lt && s[i] == t[j]) j++; i++; } if (j == lt) return 1; return 0; } int main() { cin >> s >> t; ls = (int)s.size(); lt = (int)t.size(); int x, i; for (i = 0; i < ls; i++) { x = s[i] - 'a' + 1; cnt_s[x]++; } for (i = 0; i < lt; i++) { x = t[i] - 'a' + 1; cnt_t[x]++; } if (need_tree() == 1) cout << "need tree\n"; else if (isAutomation() == 1) cout << "automaton\n"; else if (ls == lt) cout << "array\n"; else cout << "both\n"; return 0; }
1,400
CPP
n=int(input()) a=[0 for i in range(10**5+1)] l=list(map(int,input().split())) for i in l: a[i]+=1 so=0 se=0 dp=[0 for i in range(10**5+1)] dp[1]=a[1] for i in range(2,10**5+1): dp[i]=max(dp[i-1],dp[i-2]+a[i]*i) print(dp[10**5])
1,500
PYTHON3
#!/usr/bin/python3 n, m, k = input().split() if(int(m) >= int(n) and int(k) >= int(n)): print("Yes") else: print("No")
800
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int n, p; cin >> n >> p; string s; cin >> s; int count = 0; for (int i = 0; i < n - p; i++) { if ((s[i] == s[i + p]) && (s[i] != '.')) count++; else if (s[i] == '.') { if (s[i + p] == '.') { s[i] = '0'; s[i + p] = '1'; } else s[i] = (s[i + p] == '0') ? '1' : '0'; } else if (s[i + p] == '.') { if (s[i] == '.') { s[i] = '0'; s[i + p] = '1'; } else s[i + p] = (s[i] == '0') ? '1' : '0'; } } if (count == n - p) cout << "No" << endl; else { for (int i = n - p; i < n; i++) { if (s[i] == '.') s[i] = '1'; } cout << s << endl; } return 0; }
1,200
CPP
a, b, c = map(int, input().split()) ans = 0 x = min(a, b, c) a -= x b -= x c -= x ans = max(ans, x + a // 3 + b // 3 + c // 3) if x >= 1: ans = max(ans, x - 1 + (a + 1) // 3 + (b + 1) // 3 + (c + 1) // 3) if x >= 2: ans = max(ans, x - 2 + (a + 2) // 3 + (b + 2) // 3 + (c + 2) // 3) print(ans)
1,600
PYTHON3
#include <bits/stdc++.h> using namespace std; vector<long long> a; struct SegTree { struct Node { long long left, right, mid, size; }; Node combine(const Node& A, const Node& B, long long m) { Node C; if (A.left < A.size) { C.left = A.left; } else { if ((a[m - 1] > 0) <= (a[m] > 0)) { C.left = A.size + B.left; } else { C.left = A.size; } } if (B.right < B.size) { C.right = B.right; } else { if ((a[m - 1] > 0) <= (a[m] > 0)) { C.right = B.size + A.right; } else { C.right = B.size; } } C.mid = max(A.mid, B.mid); if ((a[m - 1] > 0) <= (a[m] > 0)) { C.mid = max(C.mid, A.right + B.left); } C.size = A.size + B.size; return C; } long long size; vector<Node> t; void init(long long n) { size = n; t.resize(4 * size); } void build(long long x, long long lx, long long rx) { if (lx + 1 == rx) { if (a[lx] == 0) { t[x] = {0, 0, 0, 1}; } else { t[x] = {1, 1, 1, 1}; } } else { long long m = (lx + rx) / 2; build(2 * x + 1, lx, m); build(2 * x + 2, m, rx); t[x] = combine(t[2 * x + 1], t[2 * x + 2], m); } } void build(long long n) { init(n); build(0, 0, size); } void set(long long v, long long x, long long lx, long long rx) { if (lx + 1 == rx) { if (a[lx] == 0) { t[x] = {0, 0, 0, 1}; } else { t[x] = {1, 1, 1, 1}; } } else { long long m = (lx + rx) / 2; if (v < m) { set(v, 2 * x + 1, lx, m); } else { set(v, 2 * x + 2, m, rx); } t[x] = combine(t[2 * x + 1], t[2 * x + 2], m); } } void set(long long v) { set(v, 0, 0, size); } }; void solve() { long long Q; Q = 1; while (Q--) { long long n; cin >> n; vector<long long> b(n); for (long long i = 0; i < n; ++i) cin >> b[i]; ; a.resize(n - 1); for (long long i = 0; i < n - 1; ++i) { a[i] = b[i] - b[i + 1]; } SegTree tree; if (a.size() != 0) { tree.build(a.size()); } long long m; cin >> m; while (m--) { long long l, r, d; cin >> l >> r >> d; --l, --r; if (a.size() == 0) { cout << 1 << " "; continue; } if (l > 0) { a[l - 1] -= d; tree.set(l - 1); } if (r < a.size()) { a[r] += d; tree.set(r); } cout << tree.t[0].mid + 1 << " "; } } } signed main(signed argc, char** argv) { ios_base::sync_with_stdio(false); cin.tie(nullptr); if (argc > 1 && (string)argv[1] == "local") { freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); solve(); while (cin.peek() != EOF) { if (isspace(cin.peek())) cin.get(); else { cout << '\n'; solve(); } } } else { solve(); } }
2,500
CPP
#include <bits/stdc++.h> using namespace std; int ans[507]; int a[507][507], f[507][507]; int main() { int n, m, k; scanf("%d%d%d", &n, &m, &k); for (int i = (1); i <= (n); ++i) { string s; cin >> s; s = '#' + s; for (int j = (1); j <= (m); ++j) a[i][j] = a[i][j - 1] + (s[j] - '0'); } for (int i = (0); i <= (n); ++i) { for (int j = (0); j <= (k); ++j) f[i][j] = 1000000007; } f[0][0] = 0; for (int i = (1); i <= (n); ++i) { for (int j = (0); j <= (m); ++j) ans[j] = 1000000007; ans[0] = 0; for (int j = (1); j <= (m); ++j) { for (int j_ = (j); j_ <= (m); ++j_) { int sz = a[i][j_] - a[i][j - 1]; ans[sz] = min(ans[sz], j_ - j + 1); } } for (int j = (0); j <= (k); ++j) { for (int j_ = (0); j_ <= (j); ++j_) { int len = a[i][m] - (j - j_); f[i][j] = min(f[i][j], f[i - 1][j_] + ans[len]); } } } int res = 1000000007; for (int j = (0); j <= (k); ++j) res = min(res, f[n][j]); cout << res << endl; return 0; }
1,800
CPP
#include <bits/stdc++.h> using namespace std; int N, T, Z, i, DH[1000005], A[1000005][3], L, R, X, Y; char C[1000005]; pair<int, int> F; priority_queue<pair<int, int> > PQ; void udt(int X) { PQ.push(pair<int, int>(-A[X][0], X)); } void gabung() { if (X == L && Y == R) { R = L; return; } if (X == L) { L = A[Y][2]; A[L][0] += A[L][0] - 2 * T; udt(L); return; } if (Y == R) { R = A[X][1]; A[R][0] += A[R][0] - 2 * T; udt(R); return; } X = A[X][1]; Y = A[Y][2]; if (C[X] != C[Y]) { A[X][2] = Y; A[Y][1] = X; return; } if (X == L && Y == R) { L = R; return; } if (Y == R) { A[X][0] += A[X][0] + A[Y][0] - 4 * T; R = X; } else { A[X][2] = A[Y][2]; A[A[Y][2]][1] = X; A[X][0] += A[Y][0] - 2 * T; if (X == L) { A[X][0] += A[Y][0] - 2 * T; } } A[Y][0] = 0; udt(X); } void wait() { string S; getline(cin, S); } void print() { int j; for (i = L; i != R; i = A[i][2]) { cout << C[i] << ' ' << i << ' ' << A[i][0] - 2 * T << ' '; } cout << C[R] << ' ' << R << ' ' << A[R][0] - 2 * T; cout << '\n'; wait(); } int main() { cin >> C; N = strlen(C); A[0][0] = 1; for (i = 1; i < N; i++) { if (C[i] == C[R]) { A[R][0]++; } else { R++; C[R] = C[i]; A[R][0] = 1; } } A[0][2] = 1; A[0][0] *= 2; PQ.push(pair<int, int>(-A[0][0], 0)); for (i = 1; i < R; i++) { A[i][1] = i - 1; A[i][2] = i + 1; PQ.push(pair<int, int>(-A[i][0], i)); } if (R) { A[R][1] = R - 1; A[R][0] *= 2; PQ.push(pair<int, int>(-A[R][0], R)); } for (T = 1; L < R; T++) { Z = 0; while (!PQ.empty() && (PQ.top().first >= -2 * T)) { F = PQ.top(); PQ.pop(); if (A[F.second][0] == -F.first) { DH[Z] = F.second; Z++; } } if (Z) { sort(DH, DH + Z); X = Y = DH[0]; for (i = 1; i < Z; i++) { if (A[Y][2] == DH[i]) { Y = DH[i]; } else { gabung(); X = Y = DH[i]; } } gabung(); } } cout << T - 1 << '\n'; }
2,100
CPP
#include <bits/stdc++.h> using namespace std; const long long oo = 0x3f3f3f3f3f3f3f3f; const double eps = 1e-9; vector<long long> have, need; vector<long long> p, k; vector<vector<long long> > ch; void fail() { cout << "NO" << endl; exit(0); } long long dfs(long long i) { long long total = have[i] - need[i]; for (long long j : ch[i]) { long long cur = dfs(j); if (cur < 0) { if (abs(cur * 1.0 * k[j]) > 2e17) fail(); cur *= k[j]; } total += cur; if (abs(total) > 2e17) fail(); } return total; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n; cin >> n; have.resize(n), need.resize(n); for (long long i = (0); i < (n); i++) cin >> have[i]; for (long long i = (0); i < (n); i++) cin >> need[i]; p.resize(n), k.resize(n); ch.resize(n); for (long long i = (1); i < (n); i++) { cin >> p[i] >> k[i]; p[i]--; ch[p[i]].push_back(i); } cout << (dfs(0) >= 0 ? "YES" : "NO") << endl; }
2,300
CPP
def calc_dist(t1, t2): x1, y1 = t1 x2, y2 = t2 return ((((x2 - x1)**2) + ((y2-y1)**2))**0.5) h, w = [int(x) for x in input().split()] arr = [["0"]*w]*h locations = [] for i in range(h): line = [x for x in input()] for j in range(w): if line[j] == "*": locations.append([i, j]) arr[i][j] = line[j] locations.append([h, w]) count = 0 curr = [0, 0] closest = [h, w] dist = 99999999999999999999999999999999999999999999 if curr in locations: count += 1 while curr != [h, w]: dist = 99999999999999999999999999999999999999999999 for location in locations: if location[0] < curr[0] or location[1] < curr[1] or location == curr: continue if(calc_dist(curr, location) < dist): dist = calc_dist(curr, location) closest = location curr = closest if curr != [h, w]: count += 1 print(count)
1,800
PYTHON3
#include <bits/stdc++.h> using namespace std; const int maxn = 10 * 1000 * 100 + 5; const int mod = 998244353; int n, a[maxn], mark[maxn], m[maxn], k = 1; vector<int> ans; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; mark[a[i]] = 1; } for (int i = 1; i <= n; i++) { if (m[a[i]] != 1) { if (mark[(int)1e6 + 1 - a[i]] == 0) { ans.push_back((int)1e6 + 1 - a[i]); m[a[i]] = 1; mark[(int)1e6 + 1 - a[i]] = 1; } else { while (mark[k] == 1 || mark[(int)1e6 + 1 - k] == 1) k++; ans.push_back(k); ans.push_back((int)1e6 + 1 - k); mark[k] = 1; mark[(int)1e6 + 1 - k] = 1; m[a[i]] = 1; m[(int)1e6 + 1 - a[i]] = 1; } } } cout << ans.size() << endl; for (int i = 0; i < ans.size(); i++) cout << ans[i] << " "; }
1,700
CPP
from math import * n=int(input()) a=list(map(int,input().split())) k=max(a)-min(a) x=a.count(max(a)) y=a.count(min(a)) if(max(a)!=min(a)): print(str(k)+' '+str(x*y)) else: print(str(0)+' '+str(n*(n-1)//2))
1,300
PYTHON3
#include <bits/stdc++.h> using namespace std; const int xt[4] = {1, 1, -1, -1}; const int yt[4] = {1, -1, -1, 1}; struct rec { int x, y, k; } v; int n, m, ans, p1[110000], p2[110000], p3[110000], p4[110000]; long long sum = 0; int f1() { char str[5]; scanf("%s", str); if (str[0] == 'D' && str[1] == 'L') return 1; if (str[0] == 'D' && str[1] == 'R') return 0; if (str[0] == 'U' && str[1] == 'L') return 2; return 3; } rec change(rec v) { if (v.k == 0) { int t = min(n - v.x, m - v.y); v.x += t, v.y += t; sum += t; return v; } if (v.k == 1) { int t = min(n - v.x, v.y - 1); v.x += t; v.y -= t; sum += t; return v; } if (v.k == 2) { int t = min(v.x - 1, v.y - 1); v.x -= t; v.y -= t; sum += t; return v; } int t = min(v.x - 1, m - v.y); v.x -= t; v.y += t; sum += t; return v; } bool work(rec &v) { if (v.x == 1) { p1[v.y]++; if (p1[v.y] == 1) ans--; v.k = 3 - v.k; if (p1[v.y] > 3) return 1; } if (v.x == n) { p2[v.y]++; if (p2[v.y] == 1) ans--; v.k = 3 - v.k; if (p2[v.y] > 3) return 1; } if (v.y == 1) { p3[v.x]++; if (p3[v.x] == 1) ans--; v.k ^= 1; if (p3[v.x] > 3) return 1; } if (v.y == m) { p4[v.x]++; if (p4[v.x] == 1) ans--; v.k ^= 1; if (p4[v.x] > 3) return 1; } return 0; } int main() { scanf("%d%d", &n, &m); scanf("%d%d", &v.x, &v.y); v.k = f1(); if (v.x == 1 && v.y == 1) v.k = 0; if (v.x == n && v.y == 1) v.k = 3; if (v.x == 1 && v.y == m) v.k = 1; if (v.x == n && v.y == m) v.k = 2; for (int i = 1; i <= m; i++) { if ((v.x + v.y) % 2 == (1 + i) % 2) ans++; if ((v.x + v.y) % 2 == (n + i) % 2) ans++; } for (int i = 1; i <= n; i++) { if ((v.x + v.y) % 2 == (1 + i) % 2) ans++; if ((v.x + v.y) % 2 == (m + i) % 2) ans++; } if (v.x == 1) p1[v.y]++, ans--; if (v.x == n) p2[v.y]++, ans--; if (v.y == 1) p3[v.x]++, ans--; if (v.y == m) p4[v.x]++, ans--; while (1) { v = change(v); if (work(v)) break; if (!ans) { cout << sum + 1 << endl; return 0; } } printf("-1\n"); return 0; }
2,500
CPP
from sys import stdin, stdout def find(arr,N): if len(set(arr))==1: return N return 1 def main(): for _ in range(int(stdin.readline())): N=int(stdin.readline()) arr=list(map(int, stdin.readline().split())) print(find(arr,N)) main()
800
PYTHON3
#include <bits/stdc++.h> int diru[] = {-1, -1, -1, 0, 0, 1, 1, 1}; int dirv[] = {-1, 0, 1, -1, 1, -1, 0, 1}; using namespace std; template <class T> T sq(T n) { return n * n; } template <class T> T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a % b) : a); } template <class T> T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); } template <class T> bool inside(T a, T b, T c) { return a <= b && b <= c; } template <class T> void setmax(T &a, T b) { if (a < b) a = b; } template <class T> void setmin(T &a, T b) { if (b < a) a = b; } template <class T> T power(T N, T P) { return (P == 0) ? 1 : N * power(N, P - 1); } long long int in[100100]; int main() { int n, T, t = 1, m, i, j, k; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d", &m); in[i] = m; } long long int ans = 0; for (i = 0; i < n - 1; i++) { j = 1; for (;;) { if (i + j >= n) break; j <<= 1; } j >>= 1; in[i + j] += in[i]; ans += in[i]; cout << ans << endl; } return 0; }
1,000
CPP
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; stack<int> a; int c = 0; for (int i = 0; i < s.size(); i++) { if (s[i] == ')' && !a.empty()) { a.pop(); c += 2; } else if (s[i] == '(') a.push(1); } cout << c; }
1,400
CPP
n,m= list(map(int,input().split())) a = list(map(int,input().split())) b = list(map(int,input().split())) if max(2*min(a),max(a))<min(b): print(max(2*min(a),max(a))) else: print("-1")
1,200
PYTHON3
#include<cstdio> #include<cstring> #include<algorithm> #include<cstdlib> #include<ctime> using namespace std; int t,n,p[100005],a[100005],c[100005],q[100005],tans[100005]; #ifndef DEBUG int query(int x,int y,int z) { x=p[x],y=p[y],z=p[z]; printf("? %d %d %d\n",x,y,z); fflush(stdout); int ans; scanf("%d",&ans); return ans; } #else int b[100005]; inline int F(int x) { return x>=0?x:-x; } int query(int x,int y,int z) { x=p[x],y=p[y],z=p[z]; int v[3]; v[0]=F(b[x]-b[y]),v[1]=F(b[y]-b[z]),v[2]=F(b[z]-b[x]); sort(v,v+3); // printf("query:x=%d,y=%d,z=%d,v=%d\n",x,y,z,v[1]); return v[1]; } #endif int main() { #ifdef DEBUG freopen("CF1526F.in","r",stdin); freopen("CF1526F.out","w",stdout); #endif srand(time(0)); scanf("%d",&t); while(t--) { scanf("%d",&n); #ifdef DEBUG for(int i=1;i<=n;i++) scanf("%d",&b[i]); #endif for(int i=1;i<=n;i++) p[i]=i; while(1) { random_shuffle(p+1,p+n+1); for(int i=1;i<=n;i++) c[i]=0; int fl=1,qfl=0; for(int i=3;i<=n;i++) { q[i]=query(1,2,i); c[q[i]]++; if(c[q[i]]>=3) qfl=1; if(c[q[i]]>=3&&q[i]>=n/3-2) { fl=0; break; } if(i==30&&qfl==0) { int nw=0; for(int j=1;j<n/3-1;j++) if(c[j]) nw=1; if(!nw) { fl=0; break; } } } if(qfl==0) { int nw=0; for(int j=1;j<n/3-1;j++) if(c[j]) nw=1; if(!nw) fl=0; } if(fl) break; } int mx=-1,id=-1,id2=-1,id3=-1; for(int i=n;i;i--) if(c[i]) { mx=i; break; } for(int i=1;i<=n;i++) { if(q[i]==mx) id=i; if(q[i]==mx-1) { if(id2==-1) id2=i; else id3=i; } } /*#ifdef DEBUG printf("mx=%d,id=%d,id2=%d,id3=%d\n",mx,id,id2,id3); for(int i=1;i<=n;i++) printf("%d ",c[i]); printf("\n"); #endif */ if(id3!=-1) { int q2=query(1,id,id2),q3=query(1,id,id3); if(q2>q3) id2=id3; } a[id]=1,a[id2]=2; for(int i=1;i<=n;i++) { if(i==id||i==id2) continue; a[i]=query(id,id2,i)+2; } for(int i=1;i<=n;i++) tans[p[i]]=a[i]; if(tans[1]>tans[2]) { for(int i=1;i<=n;i++) tans[i]=n+1-tans[i]; } printf("! "); for(int i=1;i<=n;i++) printf("%d ",tans[i]); printf("\n"); fflush(stdout); int q; scanf("%d",&q); } return 0; }
3,000
CPP
suit=input('') c1,c2,c3,c4,c5=input( ).split(" ") if suit[0]==c1[0]or suit[1]==c1[1] or suit[0]==c1[1] or suit[1]== c1[0]: print("YES") elif suit[0] == c2[0] or suit[1] == c2[1] or suit[0]==c2[1] or suit[1]== c2[0]: print("YES") elif suit[0] == c3[0] or suit[1] == c3[1] or suit[0]==c3[1] or suit[1]== c3[0]: print("YES") elif suit[0] == c4[0] or suit[1] == c4[1] or suit[0]==c4[1] or suit[1]== c4[0]: print("YES") elif suit[0] == c5[0] or suit[1] == c5[1] or suit[0]==c5[1] or suit[1]== c5[0]: print("YES") else: print("NO")
800
PYTHON3
#------------------Important Modules------------------# from sys import stdin,stdout from bisect import bisect_left as bl from bisect import bisect_right as br from heapq import * input=stdin.readline prin=stdout.write from random import sample from collections import Counter,deque from math import sqrt,ceil,log2,gcd #dist=[0]*(n+1) mod=10**9+7 class DisjSet: def __init__(self, n): # Constructor to create and # initialize sets of n items self.rank = [1] * n self.parent = [i for i in range(n)] # Finds set of given item x def find(self, x): # Finds the representative of the set # that x is an element of if (self.parent[x] != x): # if x is not the parent of itself # Then x is not the representative of # its set, self.parent[x] = self.find(self.parent[x]) # so we recursively call Find on its parent # and move i's node directly under the # representative of this set return self.parent[x] # Do union of two sets represented # by x and y. def union(self, x, y): # Find current sets of x and y xset = self.find(x) yset = self.find(y) # If they are already in same set if xset == yset: return # Put smaller ranked item under # bigger ranked item if ranks are # different if self.rank[xset] < self.rank[yset]: self.parent[xset] = yset elif self.rank[xset] > self.rank[yset]: self.parent[yset] = xset # If ranks are same, then move y under # x (doesn't matter which one goes where) # and increment rank of x's tree else: self.parent[yset] = xset self.rank[xset] = self.rank[xset] + 1 # Driver code def f(arr,i,j,d,dist): if i==j: return nn=max(arr[i:j]) for tl in range(i,j): if arr[tl]==nn: dist[tl]=d #print(tl,dist[tl]) f(arr,i,tl,d+1,dist) f(arr,tl+1,j,d+1,dist) #return dist def ps(n): cp=0;lk=0;arr={} #print(n) while n%2==0: n=n//2 #arr.append(n);arr.append(2**(lk+1)) lk+=1 arr[2]=lk; for ps in range(3,ceil(sqrt(n))+1,2): lk=0 while n%ps==0: n=n//ps arr.append(n);arr.append(ps**(lk+1)) lk+=1 arr[ps]=lk; if n!=1: lk+=1 arr[n]=lk #return arr #print(arr) return arr #count=0 #dp=[[0 for i in range(m)] for j in range(n)] #[int(x) for x in input().strip().split()] def gcd(x, y): while(y): x, y = y, x % y return x # Driver Code def factorials(n,r): #This calculates ncr mod 10**9+7 slr=n;dpr=r qlr=1;qs=1 mod=10**9+7 for ip in range(n-r+1,n+1): qlr=(qlr*ip)%mod for ij in range(1,r+1): qs=(qs*ij)%mod #print(qlr,qs) ans=(qlr*modInverse(qs))%mod return ans def modInverse(b): qr=10**9+7 return pow(b, qr - 2,qr) #=============================================================================================== ### START ITERATE RECURSION ### from types import GeneratorType def iterative(f, stack=[]): def wrapped_func(*args, **kwargs): if stack: return f(*args, **kwargs) to = f(*args, **kwargs) while True: if type(to) is GeneratorType: stack.append(to) to = next(to) continue stack.pop() if not stack: break to = stack[-1].send(to) return to return wrapped_func def power(arr): listrep = arr subsets = [] for i in range(2**len(listrep)): subset = [] for k in range(len(listrep)): if i & 1<<k: subset.append(listrep[k]) subsets.append(subset) return subsets def dis(xa,ya,xb,yb): return sqrt((xa-xb)**2+(ya-yb)**2) #### END ITERATE RECURSION #### #=============================================================================================== #----------Input functions--------------------# def ii(): return int(input()) def ilist(): return [int(x) for x in input().strip().split()] def outstrlist(array:list)->str: array=[str(x) for x in array] return ' '.join(array); def islist(): return list(map(str,input().split().rstrip())) def outfast(arr:list)->str: ss='' for ip in arr: ss+=str(ip)+' ' return prin(ss); def pda(n) : list = [] # List to store half of the divisors for i in range(1, int(sqrt(n) + 1)) : if (n % i == 0) : # Check if divisors are equal if (n / i == i) : #print (i, end =" ") list.append(i) else : # Otherwise print both #print (i, end =" ") list.append(int(n / i));list.append(i) # The list will be printed in reverse return list ###-------------------------CODE STARTS HERE--------------------------------########### ######################################################################################### #t=int(input()) t=1 for jj in range(t): n,x,y=ilist() arr=ilist();arr.sort() if x>y: print(n) else: c=0 for i in range(n): if arr[i]<=x: c+=1 print(ceil(c/2))
1,200
PYTHON3
#include <bits/stdc++.h> using namespace std; const int maxn = 5e5 + 20; int a[maxn], b[maxn], c[maxn], d[maxn]; int main() { int n; cin >> n; cout << "YES" << endl; for (int i = 0; i < n; i++) { cin >> a[i] >> b[i] >> c[i] >> d[i]; if (a[i] < 0) { a[i] *= -1; } if (b[i] < 0) { b[i] *= -1; } cout << (a[i] % 2) * 2 + (b[i] % 2) + 1 << endl; } }
2,100
CPP
n = int(input()) for i in range(n): rgb = [int(i) for i in input().split()] rgb.sort() p, m, g = rgb if g >= p + m: dias = p + m else: dias = (p + m + g) // 2 print(dias)
1,100
PYTHON3
#include <bits/stdc++.h> using namespace std; const int N = 1000000; const int maxN = N + 7; const long long O = 1e9 + 7; template <class T> T rd() { bool f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = 0; T x = 0; for (; isdigit(c); c = getchar()) x = x * 10 + c - '0'; return f ? x : -x; } int n, sn; long long fac[maxN]; void init() { fac[0] = 1; for (int i = (1), _ = (N); i <= _; ++i) fac[i] = fac[i - 1] * i % O; } bool ls(int x) { return 1 < x && x <= sn; } namespace C { int A[maxN], B[maxN]; int go[maxN], fr[maxN]; int cnt[maxN], pp[maxN], las[maxN], occ[maxN]; long long res; void init() { for (int i = (1), _ = (n); i <= _; ++i) pp[i] = 1, cnt[i] = 0, las[i] = 0; cnt[1] = 1; las[1] = 1; occ[1] = 1; for (int i = (2), _ = (n); i <= _; ++i) if (cnt[i] == 0) { occ[i] = 0; for (int j = i; j <= n; j += i) { cnt[j]++; pp[j] *= i; las[j] = i; ++occ[i]; } } } void pre() { memset(A, 0, sizeof A); memset(B, 0, sizeof B); memset(go, 0, sizeof go); memset(fr, 0, sizeof fr); sn = sqrtl(n); for (int i = (1), _ = (n); i <= _; ++i) A[pp[i]]++; for (int i = (sn + 1), _ = (n); i <= _; ++i) B[occ[i]]++; ++B[1]; res = 1; } void gao(int x, int y) { if (y == 0) return; if (cnt[x] != cnt[y]) { res = 0; return; } A[pp[y]]--; x = las[x], y = las[y]; if ((ls(x) || ls(y)) && x != y) { res = 0; return; } else if (ls(x) && ls(y)) return; else if (occ[x] != occ[y]) { res = 0; return; } if (go[y] == x) return; if (go[y]) { res = 0; return; } if (fr[x]) { res = 0; return; } go[y] = x; fr[x] = y; B[occ[y]]--; } long long calc() { for (int i = (1), _ = (n); i <= _; ++i) res = res * fac[A[i]] % O; for (int i = (1), _ = (n); i <= _; ++i) res = res * fac[B[i]] % O; return res; } } // namespace C int main() { init(); n = rd<int>(); C::init(); C::pre(); for (int i = (1), _ = (n); i <= _; ++i) C::gao(i, rd<int>()); printf("%I64d\n", C::calc()); return 0; }
3,000
CPP
n, k = map(int, input().split()) for i in range(0, k): if n % 10 != 0: n -= 1 else: n //= 10 print(n)
800
PYTHON3
l=0;v=0 n=int(input()) s=str(input()) for i in s: if i=="D": l+=1 if i=="A": v+=1 if l>v: print("Danik") elif l<v: print ("Anton") else: print("Friendship")
800
PYTHON3
#include <bits/stdc++.h> using namespace std; int xx[5005][5005]; int last[5005][2]; int arr[5005]; int dp[5005], n; int fnc(int num) { if (num >= n) return 0; int ans, ans2, ans3; if (dp[num] != -1) return dp[num]; if (last[arr[num]][0] < num) ans = fnc(num + 1); else { ans2 = fnc(last[arr[num]][1] + 1); ans3 = fnc(num + 1); ans = max(ans2 ^ xx[num][last[arr[num]][1]], ans2 + xx[num][last[arr[num]][1]]); ans = max(ans, ans3); } dp[num] = ans; return ans; } int main() { int i, ans, j; cin >> n; memset(last, -1, sizeof(last)); memset(dp, -1, sizeof(dp)); for (i = 0; i < n; i++) { cin >> arr[i]; if (last[arr[i]][0] == -1) last[arr[i]][0] = i; last[arr[i]][1] = i; } int visited[5005]; int maxi, mini; for (i = 0; i < n; i++) { maxi = -1; mini = last[arr[last[arr[i]][1]]][0]; for (j = last[arr[i]][1]; j >= (last[arr[i]][0]); j--) { maxi = max(maxi, last[arr[j]][1]); mini = min(mini, last[arr[j]][0]); } last[arr[i]][1] = maxi; last[arr[i]][0] = mini; } for (i = 0; i < n; i++) { ans = 0; memset(visited, 0, sizeof(visited)); for (j = i; j < n; j++) { if (visited[arr[j]] == 0) { ans = ans ^ arr[j]; visited[arr[j]] = 1; } xx[i][j] = ans; } } ans = fnc(0); cout << ans << endl; }
1,900
CPP
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimization("unroll-loops") using namespace std; template <class T> inline T sqr(T x) { return x * x; } template <class T> inline T parse(const string &s) { T x; stringstream ss(s); ss >> x; return x; } const double EPS = 1e-12; const int INF = 1000 * 1000 * 1000; const long long LINF = INF * 1ll * INF; const double DINF = 1e200; const double PI = 3.1415926535897932384626433832795l; int gcd(int a, int b) { return a ? gcd(b % a, a) : b; } long long gcd(long long a, long long b) { return a ? gcd(b % a, a) : b; } long long gcdex(long long a, long long b, long long &x, long long &y) { if (!a) { x = 0, y = 1; return b; } long long k = b / a; long long g = gcdex(b - k * a, a, y, x); x -= k * y; return g; } long long inv(long long a, long long m) { assert(m > 1); long long x, y, g; g = gcdex(a, m, x, y); return (x % (m / g) + m / g) % m / g; } long long crt(long long a1, long long m1, long long a2, long long m2) { long long a = (a2 - a1 % m2 + m2) % m2; long long x, y, g; g = gcdex(m1, m2, x, y); if (a % g) return -1; long long m = m1 / g * m2; assert(x + m2 >= 0); x = a / g * (x + m2) % m2; long long r = (a1 + x * m1) % m; assert(r % m1 == a1 && r % m2 == a2); return r; } long long powmod(long long a, long long p, long long m) { assert(p >= 0); long long r = 1; while (p) { if (p & 1) r = r * a % m; p >>= 1; a = a * a % m; } return r; } bool isprime(long long a) { if (a <= 1) return false; for (long long i = 2; i * i <= a; ++i) { if (a % i == 0) return false; } return true; } long long sqrtup(long long a) { if (!a) return 0; long long x = max(0ll, (long long)sqrt((double)a)); while (x * x >= a) --x; while ((x + 1) * (x + 1) < a) ++x; return x + 1; } long long isqrt(long long a) { if (a <= 0) { assert(!a); return 0; } long long x = (long long)sqrt((double)a); while (sqr(x + 1) <= a) ++x; while (x * x > a) --x; return x; } long long sgn(long long x) { return x < 0 ? -1 : x > 0 ? 1 : 0; } double randf() { double m = RAND_MAX + 1.; return (((rand() + .5) / m + rand()) / m + rand()) / m; } template <class T> ostream &operator<<(ostream &s, const vector<T> &v); template <class A, class B> ostream &operator<<(ostream &s, const pair<A, B> &p); template <class K, class V> ostream &operator<<(ostream &s, const map<K, V> &m); template <class T> ostream &operator<<(ostream &s, const set<T> &m); template <class T, size_t N> ostream &operator<<(ostream &s, const array<T, N> &a); template <class... T> ostream &operator<<(ostream &s, const tuple<T...> &t); template <class T> ostream &operator<<(ostream &s, const vector<T> &v) { s << '['; for (int i = 0; i < (((int)(v).size())); ++i) { if (i) s << ','; s << v[i]; } s << ']'; return s; } template <class A, class B> ostream &operator<<(ostream &s, const pair<A, B> &p) { s << "(" << p.first << "," << p.second << ")"; return s; } template <class K, class V> ostream &operator<<(ostream &s, const map<K, V> &m) { s << "{"; bool f = false; for (const auto &it : m) { if (f) s << ","; f = true; s << it.first << ": " << it.second; } s << "}"; return s; } template <class T> ostream &operator<<(ostream &s, const set<T> &m) { s << "{"; bool f = false; for (const auto &it : m) { if (f) s << ","; f = true; s << it; } s << "}"; return s; } template <class T> ostream &operator<<(ostream &s, const multiset<T> &m) { s << "{"; bool f = false; for (const auto &it : m) { if (f) s << ","; f = true; s << it; } s << "}"; return s; } template <class T, class V, class C> ostream &operator<<(ostream &s, const priority_queue<T, V, C> &q) { auto a = q; s << "{"; bool f = false; while (!a.empty()) { if (f) s << ","; f = true; s << a.top(); a.pop(); } return s << "}"; } template <class T, size_t N> ostream &operator<<(ostream &s, const array<T, N> &a) { s << '['; for (int i = 0; i < (((int)(a).size())); ++i) { if (i) s << ','; s << a[i]; } s << ']'; return s; } template <class T> ostream &operator<<(ostream &s, const deque<T> &a) { s << '['; for (int i = 0; i < (((int)(a).size())); ++i) { if (i) s << ','; s << a[i]; } s << ']'; return s; } template <size_t n, class... T> struct put1 { static ostream &put(ostream &s, const tuple<T...> &t) { s << get<sizeof...(T) - n>(t); if (n > 1) s << ','; return put1<n - 1, T...>::put(s, t); } }; template <class... T> struct put1<0, T...> { static ostream &put(ostream &s, const tuple<T...> &t) { return s; } }; template <class... T> ostream &operator<<(ostream &s, const tuple<T...> &t) { s << "("; put1<sizeof...(T), T...>::put(s, t); s << ")"; return s; } ostream &put3(ostream &s, const char *, bool) { return s; } template <class U, class... T> ostream &put3(ostream &s, const char *f, bool fs, U &&u, T &&...t) { while (*f == ' ') ++f; if (!fs) s << ", "; auto nf = f; int d = 0; while (*nf && (*nf != ',' || d)) { if (*nf == '(') ++d; else if (*nf == ')') --d; ++nf; } auto nf2 = nf; while (nf2 > f && *(nf2 - 1) == ' ') --nf; fs = *f == '"'; if (!fs) { s.write(f, nf2 - f); s << "="; }; s << u; if (fs) s << ' '; if (*nf) ++nf; return put3(s, nf, fs, forward<T>(t)...); } int main(int argc, char **argv) { vector<long long> A(11); for (int i = 0; i < (11); ++i) cin >> A[i]; reverse((A).begin(), (A).end()); for (long long v : A) { double r = sqrt(1. * abs(v)) + v * v * v * 5; if (r <= 400) printf("f(%d) = %.2f\n", (int)v, r); else printf("f(%d) = MAGNA NIMIS!\n", (int)v); } return 0; }
0
CPP
import sys INF = 10**20 MOD = 10**9 + 7 I = lambda:list(map(int,input().split())) from math import gcd from math import ceil from collections import defaultdict as dd, Counter from bisect import bisect_left as bl, bisect_right as br """ Facts and Data representation """ n, k = I() a = I() lo, hi = 1, INF def check(x): global k, n cur = 0 cnt0, cnt1 = 0, 0 for i in range(n): if cur: cur ^= 1 cnt0 += 1 elif a[i] <= x: cnt0 += 1 cur ^= 1 cur = 1 for i in range(n): if cur: cur ^= 1 cnt1 += 1 elif a[i] <= x: cnt1 += 1 cur ^= 1 return max(cnt0, cnt1) >= k while lo < hi: mid = (lo + hi) // 2 if check(mid): hi = mid else: lo = mid + 1 print(lo)
2,000
PYTHON3
n,m = map(int,input().split()) count = 0 lst = [] d = {} for i in range(1,m+1): d[i] = 0 for _ in range(n): l,r = map(int,input().split()) for i in range(l,r+1): d[i] = 1 for i in d: if d[i] == 0: count+=1 lst.append(i) print(count) for i in lst: print(i,end=" ")
800
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int n, count = 0; cin >> n; string s1, s2; cin >> s1 >> s2; for (int i = 0; i < n; i++) { count += min(abs(s1[i] - s2[i]), 10 - abs(s1[i] - s2[i])); } cout << count; return 0; }
800
CPP
#include <bits/stdc++.h> using namespace std; #pragma warning(disable : 4996) int n, k; void solve() { int i, j, n1; double l, r, m, v1, v2, s, t, x, a, y; cin >> n >> s >> v1 >> v2 >> k; l = 0; r = 1e9 + 1; for (int yy = 0; yy < 100; yy++) { m = (l + r) / 2; n1 = n; t = 0; x = 0; y = 0; while (n1 > 0) { t += abs(x - y) / (v1 + v2); y = t * v1; n1 = max(0, n1 - k); a = (v1 * v2 * m - (s)*v2 + y * v2 - t * v1 * v2) / (v1 - v2); a = min(a, s); a = max((double)0, a); t += a / v2; x = a + y; y = t * v1; if (y >= s) n1 = 0; } if (t <= m) { r = m; } else { l = m; } } printf("%.10lf", r); } int main() { solve(); return 0; }
1,900
CPP
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; set<char> c(s.begin(), s.end()); int count = 0; for (int i = 0; i < c.size(); i++) count++; if (count % 2) cout << "IGNORE HIM!"; else cout << "CHAT WITH HER!"; }
800
CPP
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int N; cin >> N; vector<int> V(N); for (int &X : V) cin >> X; int Ans = min(V[0], V[N - 1]); int Cnt = 0; while (Cnt < N - 2) { if (V[Cnt + 1] > V[Cnt + 2]) { Ans = min(Ans, V[Cnt + 1]); Cnt++; } else { Ans = min(Ans, V[Cnt + 2]); Cnt += 2; } } cout << Ans << endl; return 0; }
1,100
CPP
#include <bits/stdc++.h> using namespace std; typedef const int& ci; struct node { int s, id; friend bool operator<(const node& x, const node& y) { return x.s < y.s; } }; node a[300000 + 1]; int t[300000 + 1]; struct oper { int i, j, d; oper() {} oper(ci _i, ci _j, ci _d) : i(_i), j(_j), d(_d) {} }; oper op[300000]; int main() { int n, m; long long sum = 0; scanf("%d", &n), m = 0; for (int i = 0; ++i <= n; a[i].id = i, sum += a[i].s) scanf("%d", &a[i].s); for (int i = 0; ++i <= n; sum -= t[i]) scanf("%d", t + i); if (sum) { puts("NO"); return 0; } stable_sort(a + 1, a + n + 1), stable_sort(t + 1, t + n + 1); for (int i = 0; ++i <= n; a[i].s -= t[i]) ; int j = 0; while (a[++j].s <= 0) ; for (int i = 0; ++i < n;) { if (a[i].s > 0) { puts("NO"); return 0; } while (a[i].s) { if (a[j].s + a[i].s > 0) { op[++m] = oper(a[i].id, a[j].id, -a[i].s); a[j].s += a[i].s; a[i].s = 0; break; } op[++m] = oper(a[i].id, a[j].id, a[j].s); a[i].s += a[j].s; a[j].s = 0; while (a[++j].s <= 0) ; } } puts("YES"); printf("%d\n", m); for (int i = 0; ++i <= m; printf("%d %d %d\n", op[i].i, op[i].j, op[i].d)) ; return 0; }
2,300
CPP
#include <bits/stdc++.h> using namespace std; const int maxn = 100000 + 10; int ans[maxn], n, t[maxn]; struct node { int x, id; bool operator<(const node& tt) const { return x < tt.x; } } a[maxn], b[maxn]; int main() { while (~scanf("%d", &n)) { for (int i = 0; i < n; i++) { scanf("%d", &a[i].x); a[i].id = i + 1; t[i] = a[i].x; } for (int i = 0; i < n; i++) { scanf("%d", &b[i].x); b[i].id = i + 1; } sort(a, a + n); sort(b, b + n); for (int i = 0; i < n; i++) { int x = a[i].id; int y = b[i].id; x--; y--; ans[x] = t[y]; } for (int i = 0; i < n; i++) printf("%d%c", ans[i], i == n - 1 ? '\n' : ' '); } return 0; }
1,200
CPP
#include <bits/stdc++.h> using namespace std; pair<long long int, long long int> mult(pair<long long int, long long int> x, pair<long long int, long long int> y) { return pair<long long int, long long int>( x.first * y.first - x.second * y.second, x.first * y.second + x.second * y.first); } pair<long long int, long long int> sub(pair<long long int, long long int> x, pair<long long int, long long int> y) { return pair<long long int, long long int>(x.first - y.first, x.second - y.second); } pair<long long int, long long int> conj(pair<long long int, long long int> x) { return pair<long long int, long long int>(x.first, -x.second); } long long int lenSqr(pair<long long int, long long int> x) { return x.first * x.first + x.second * x.second; } int main() { ios_base::sync_with_stdio(0); pair<long long int, long long int> A, B, C; cin >> A.first >> A.second >> B.first >> B.second >> C.first >> C.second; pair<long long int, long long int> iK(1, 0); bool good = false; for (int i = (0); i <= (3); ++i) { if (mult(A, iK) == B) good = true; pair<long long int, long long int> R = sub(B, mult(A, iK)); R = mult(R, conj(C)); long long int d = lenSqr(C); if (d && R.first % d == 0 && R.second % d == 0) good = true; iK = mult(iK, pair<long long int, long long int>(0, 1)); } if (good) cout << "YES"; else cout << "NO"; return 0; }
2,000
CPP
#include <bits/stdc++.h> using namespace std; int main() { int m, a[505]; int num1 = 0, num2 = 0, num3 = 0; while (scanf("%d", &m) != EOF) { for (int i = 0; i < m; i++) { scanf("%d", &a[i]); num3 += a[i]; if (a[i] % 2) num1++; else num2++; } if (num3 % 2) { printf("%d\n", num1); } else { printf("%d\n", num2); } } }
900
CPP
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; const int MAX = 300009; long long n, k, m, cnt, j; multiset<long long> ans; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> k; if (n == k) { cout << "YES"; cout << endl; for (int i = 0; i < n; i++) cout << 1 << " "; return 0; } m = n; while (m) { if (m % 2 == 1) ans.insert(pow(2, j)); j++; m /= 2; } if (ans.size() > k) { cout << "NO"; return 0; } if (ans.size() == k) { cout << "YES"; cout << endl; for (auto i : ans) cout << i << " "; return 0; } while (ans.size() != k) { auto t = ans.end(); t--; if (*t == 1) break; long long tt = *t; ans.erase(t); ans.insert((tt) / 2); ans.insert((tt) / 2); } if (ans.size() == k) { cout << "YES"; cout << endl; for (auto i : ans) cout << i << " "; return 0; } cout << "NO"; }
1,400
CPP
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); const double eps = 1e-6; const long long INF = 1e15 + 5; const int maxn = 1e3 + 5; int p[maxn][maxn]; int vis[maxn]; int main() { ios::sync_with_stdio(false); cin.tie(0); ; int n, m, gg = 0; cin >> n >> m; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) cin >> p[i][j]; } for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { if (p[i][j] != p[i][1]) { vis[i] = 1; gg = i; } } } if (!gg) { int ans = 0; for (int i = 1; i <= n; i++) ans ^= p[i][1]; if (ans == 0) cout << "NIE" << endl; else { cout << "TAK" << endl; for (int i = 1; i <= n; i++) cout << "1" << " "; cout << endl; } } else { int ans = 0, qq; for (int i = 1; i <= n; i++) { if (i != gg) { ans ^= p[i][1]; } } for (int i = 1; i <= m; i++) { if (ans != p[gg][i]) { cout << "TAK" << endl; qq = i; break; } } for (int i = 1; i <= n; i++) { if (i != gg) cout << "1" << " "; else cout << qq << " "; } } }
1,600
CPP
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; int n; pair<pair<int, int>, int> ab[maxn]; vector<int> P; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; for (int i = 0; i < n; ++i) cin >> ab[i].first.first; for (int i = 0; i < n; ++i) cin >> ab[i].first.second; for (int i = 0; i < n; ++i) ab[i].second = i + 1; sort(ab, ab + n); cerr << endl; for (int i = 0; i < n; ++i) cerr << ab[i].first.first << ' '; cerr << endl; for (int i = 0; i < n; ++i) cerr << ab[i].first.second << ' '; cerr << endl; for (int i = 0; i < n; ++i) cerr << ab[i].second << ' '; cerr << endl; for (int i = 0; i < n; i += 2) { if (i == n - 1) P.push_back(ab[i].second); else if (i == n - 2) P.push_back(ab[i].second), P.push_back(ab[i + 1].second); else P.push_back(ab[i].first.second > ab[i + 1].first.second ? ab[i].second : ab[i + 1].second); } cout << P.size() << '\n'; for (int i : P) cout << i << ' '; return 0; }
2,400
CPP
import sys input = sys.stdin.readline n,m=map(int,input().split()) A=list(map(int,input().split())) B=list(map(int,input().split())) A0=[a for a in A if a%2==0] A1=[a for a in A if a%2==1] B0=[a for a in B if a%2==0] B1=[a for a in B if a%2==1] print(min(len(A0),len(B1))+min(len(A1),len(B0)))
800
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long t; cin >> t; while (t--) { long long n; cin >> n; vector<long long> wt(n); for (long long i = 0; i < n; i++) { cin >> wt[i]; } long long ans = 0; sort(wt.begin(), wt.end()); for (long long i = 0; i < n - 1; i++) { for (long long j = i + 1; j < n; j++) { long long s = wt[i] + wt[j]; long long i1 = 0, j1 = n - 1; long long cnt = 1; while (i1 < j1) { if (i1 == i || i1 == j) { i1++; continue; } if (j1 == i || j1 == j) { j1--; continue; } if (wt[i1] + wt[j1] == s) { cnt++; i1++; j1--; } else if (wt[i1] + wt[j1] > s) { j1--; } else { i1++; } } ans = max(ans, cnt); } } cout << ans << endl; } return 0; }
1,200
CPP
#include <bits/stdc++.h> using namespace std; const int N = 100100; int a[N]; int main() { int n; cin >> n; int cn = 0; for (int i = 0; i < n; ++i) { cin >> a[i]; if (i == a[i]) ++cn; } if (cn == n || cn == n - 2) { cout << n; return 0; } bool has = false; for (int i = 0; i < n; ++i) { if (a[i] == i) continue; if (a[a[i]] == i) { cout << cn + 2; return 0; } } cout << cn + 1; return 0; }
1,100
CPP
#include <bits/stdc++.h> using namespace std; const int INF = std::numeric_limits<int>::max(); const char* IN_FILE = ".in"; const char* OUT_FILE = ".out"; const int NMAX = 1005; const int NUM_DIR = 8; long long a[NMAX][NMAX], trHor[2][NMAX], trVer[2][NMAX]; long long sum[NUM_DIR][NMAX][NMAX]; const int dx[] = {-1, -1, 0, 1, 1, 1, 0, -1}; const int dy[] = {0, -1, -1, -1, 0, 1, 1, 1}; int m, n, k; bool used[NMAX][NMAX]; bool inside(int x, int y) { return x >= 0 && y >= 0 && x < n && y < m; } long long calc_sum(int dir, int x, int y, int count) { long long ret = sum[dir][x][y]; x += dx[dir] * count; y += dy[dir] * count; if (inside(x, y)) ret -= sum[dir][x][y]; return ret; } void readData() { cin >> n >> m >> k; for (int i = 0; i < int(n); ++i) for (int j = 0; j < int(m); ++j) cin >> a[i][j]; } long long solveNaive() { long long ans = -1; int ansx = -1, ansy = -1; for (int x = k - 1; x <= n - k; ++x) { for (int y = k - 1; y <= m - k; ++y) { long long currentSum = 0; for (int i = 0; i < int(n); ++i) { for (int j = 0; j < int(m); ++j) { long long w = max(0, k - abs(i - x) - abs(j - y)); currentSum += w * a[i][j]; } } if (currentSum > ans) { ans = currentSum; ansx = x; ansy = y; } } } ++ansx, ++ansy; cout << "correct " << ansx << " " << ansy << " " << ans << endl; return ans; } long long solve() { for (int i = 0; i < int(NUM_DIR); ++i) { for (int u = 0; u < int(NMAX); ++u) for (int v = 0; v < int(NMAX); ++v) used[u][v] = false; for (int x = 0; x < int(n); ++x) { for (int y = 0; y < int(m); ++y) { if (used[x][y]) continue; int xx = x, yy = y; while (inside(xx, yy) && !used[xx][yy]) { xx += dx[i]; yy += dy[i]; } int rev = (i + 4) % NUM_DIR; xx += dx[rev]; yy += dy[rev]; while (inside(xx, yy)) { used[xx][yy] = true; sum[i][xx][yy] = a[xx][yy]; if (inside(xx + dx[i], yy + dy[i])) { sum[i][xx][yy] += sum[i][xx + dx[i]][yy + dy[i]]; } xx += dx[rev]; yy += dy[rev]; } } } } for (int i = 0; i < int(k); ++i) { trHor[0][k - 1] += calc_sum(4, k - 1 - i, i, 2 * (i + 1) - 1); trHor[1][k - 1] += calc_sum(4, i, k + i - 1, 2 * (k - i) - 1); } for (int i = k; i <= m - k; ++i) { trHor[0][i] = trHor[0][i - 1] + calc_sum(4, 0, i, 2 * k - 1); trHor[0][i] -= calc_sum(3, 0, i - 1, k - 1); trHor[0][i] -= calc_sum(1, 2 * k - 2, i - 1, k); trHor[1][i] = trHor[1][i - 1] - calc_sum(4, 0, i - 1, 2 * k - 1); trHor[1][i] += calc_sum(5, 0, i, k); trHor[1][i] += calc_sum(7, 2 * k - 2, i, k - 1); } long long firstSum = 0; for (int i = 0; i < int(n); ++i) { for (int j = 0; j < int(m); ++j) { long long w = max(0, k - abs(i - k + 1) - abs(j - k + 1)); firstSum += w * a[i][j]; } } int ansx = k - 1, ansy = k - 1; long long ans = firstSum; for (int y = k - 1; y <= m - k; ++y) { long long currentSum = firstSum; trVer[0][k - 1] = 0; trVer[1][k - 1] = 0; for (int i = 0; i < int(k); ++i) { trVer[0][k - 1] += calc_sum(6, i, y - i, 2 * i + 1); trVer[1][k - 1] += calc_sum(6, k - 1 + i, y - k + 1 + i, 2 * (k - i) - 1); } for (int x = k; x <= n - k; ++x) { trVer[0][x] = trVer[0][x - 1] + calc_sum(6, x, y - k + 1, 2 * k - 1); trVer[0][x] -= calc_sum(7, x - 1, y - k + 1, k); trVer[0][x] -= calc_sum(1, x - 1, y + k - 1, k - 1); trVer[1][x] = trVer[1][x - 1] - calc_sum(6, x - 1, y - k + 1, 2 * k - 1); trVer[1][x] += calc_sum(5, x, y - k + 1, k); trVer[1][x] += calc_sum(3, x, y + k - 1, k - 1); } for (int x = k - 1; x <= n - k; ++x) { if (currentSum > ans) { ans = currentSum; ansx = x; ansy = y; } currentSum -= trVer[0][x]; if (x + 1 <= n - k) { currentSum += trVer[1][x + 1]; } } firstSum -= trHor[0][y]; if (y + 1 <= m - k) { firstSum += trHor[1][y + 1]; } } cout << ansx + 1 << " " << ansy + 1 << " " << endl; return ans; } void init() { freopen(IN_FILE, "rt", stdin); freopen(OUT_FILE, "wt", stdout); } int main() { ios_base::sync_with_stdio(false); readData(); solve(); return 0; }
2,500
CPP
n, m = (int(x) for x in input().split()) for i in range(n): row = {c for c in input().split()} if row & {'C', 'M', 'Y'}: print('#Color') exit(0) print('#Black&White')
800
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int n, i, c = 0; cin >> n; int a[n]; for (i = 0; i < n; i++) cin >> a[i]; while (a[0] % 2 == 0) a[0] /= 2; while (a[0] % 3 == 0) a[0] /= 3; for (i = 1; i < n; i++) { while (a[i] % 2 == 0) a[i] /= 2; while (a[i] % 3 == 0) a[i] /= 3; if (a[0] == a[i]) c++; } if (c == n - 1) cout << "YES"; else cout << "NO"; }
1,300
CPP
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long n; cin >> n; long long a[n][n]; long ans[n]; for (long i = 0; i < n; i++) { for (long j = 0; j < n; j++) cin >> a[i][j]; } long long x = a[0][1] * a[0][2] / a[1][2]; ans[0] = sqrt(x); for (long i = 1; i < n; i++) { ans[i] = a[0][i] / ans[0]; } for (long i = 0; i < n; i++) cout << ans[i] << " "; return 0; }
1,300
CPP
n=int(input()) name=input() count=0 for i in range(n-1): if(name[i]==name[i+1]): count=count+1 pass pass print(count)
800
PYTHON3
#include <bits/stdc++.h> const long long MOD = 1e9 + 7; const int EPS = 1e-9; const long double PI = acos(-1.0); const int MAXX = 2e5 + 3; const int LOGMAXN = 30; using namespace std; vector<int> adj[MAXX], adj1[MAXX]; vector<vector<char> > res; vector<char> v; long long N, M, K, dist[MAXX]; map<pair<long long, long long>, long long> roads; bool flag, vis[MAXX]; void bfs(int s) { for (int i = 0; i <= N; ++i) { dist[i] = 1e12; } dist[s] = 0; queue<int> q; q.push(s); while (!q.empty()) { int cur = q.front(); q.pop(); for (int i = 0; i < adj[cur].size(); ++i) { int to = adj[cur][i]; if (dist[to] > dist[cur] + 1) { dist[to] = dist[cur] + 1; q.push(to); } if (dist[to] == dist[cur] + 1) { adj1[to].push_back(roads[{min(cur, to), max(cur, to)}]); } } } } void dfs(int node, int d) { if (flag) return; if (d == N - 1) { if (res.size() < K) { res.push_back(v); } else { flag = true; } return; } for (int i = 0; i < adj1[node].size(); ++i) { int to = adj1[node][i]; v[to] = '1'; dfs(node + 1, d + 1); v[to] = '0'; if (flag) return; } } int main() { ios_base::sync_with_stdio(0); cin >> N >> M >> K; for (int i = 0; i < M; ++i) { int u, v; cin >> u >> v; adj[u].push_back(v); adj[v].push_back(u); roads[{min(u, v), max(u, v)}] = i; } v.assign(M, '0'); bfs(1); dfs(2, 0); cout << res.size() << endl; for (int i = 0; i < res.size(); ++i) { for (int j = 0; j < res[i].size(); ++j) { cout << res[i][j]; } cout << endl; } return 0; }
2,100
CPP
# -*- coding: utf-8 -*- """ Created on Mon Oct 19 11:42:13 2020 @author: 章斯岚 """ string1=input() ab=string1.count('ABA') string=string1.replace('ABA','h') ab+=string.count('BAB') string=string.replace('BAB','h') a=string.count('AB') b=string.count('BA') if (ab>0 and ab+a+b>1) or (a>0 and b>0) or 'BABAB'in string1: print('YES') else: print('NO')
1,500
PYTHON3
#include <bits/stdc++.h> const int MAX_N = 310; int n; int pref[MAX_N][MAX_N]; int likes[MAX_N], solution[MAX_N]; int main() { scanf("%d ", &n); for (int i = 1; i <= n; ++i) { for (int j = 1; j <= n; ++j) { int x; scanf("%d ", &x); pref[i][x] = j; } } for (int i = 1; i <= n; ++i) { int x; scanf("%d ", &x); likes[x] = i; } for (int i = 1; i <= n; ++i) { int best = 0, sol = 0; for (int j = 1; j <= n; ++j) { if (j != i && (best == 0 || likes[j] < likes[best])) { best = j; } if (best != 0) { if (sol == 0 || pref[i][best] < pref[i][sol]) { sol = best; } } } solution[i] = sol; } for (int i = 1; i < n; ++i) { printf("%d ", solution[i]); } printf("%d\n", solution[n]); return 0; }
1,800
CPP
#include <bits/stdc++.h> using namespace std; const long long int inf = 1e18, M = 1e9 + 7; const long long int N = 1; void solve() { long long int m, n, k, t; cin >> m >> n >> k >> t; vector<long long int> val(m); for (long long int i = 0; i < m; ++i) cin >> val[i]; sort(val.begin(), val.end()); reverse(val.begin(), val.end()); vector<pair<long long int, pair<long long int, long long int>>> traps(k); long long int a, b, c; for (long long int i = 0; i < k; ++i) { cin >> a >> b >> c; traps.push_back({a, {b, c}}); } sort(traps.begin(), traps.end()); long long int beg = 1, en = m; long long int mid, ans = 0; long long int now, cur; while (beg <= en) { mid = (beg + en) / 2; now = 0; cur = n + 1; for (auto c : traps) { if (c.second.second > val[mid - 1] && now < c.second.first) { cur += 2 * (c.second.first - max(c.first - 1, now)); now = c.second.first; } } if (cur <= t) { ans = mid; beg = mid + 1; } else en = mid - 1; } cout << ans; } int32_t main() { long long int t = 1; while (t--) { solve(); } return 0; }
1,900
CPP
#include <bits/stdc++.h> using namespace std; int n, m, c[2001], col, num[2001], t1, t2, t3; vector<int> adj[2001]; int dfs(int v) { int s = 1; c[v] = col; for (int i = 0; i < adj[v].size(); i++) { if (c[adj[v][i]] == 0) { s += dfs(adj[v][i]); } } return s; } int main() { cin >> n; cin >> m; for (int i = 1; i <= m; i++) { cin >> t1 >> t2; adj[t1].push_back(t2); adj[t2].push_back(t1); } for (int i = 1; i <= n; i++) { if (c[i] == 0) { col++; t3 = dfs(i); num[col] = t3; } } cin >> m; for (int i = 1; i <= m; i++) { cin >> t1 >> t2; if (c[t1] == c[t2]) num[c[t1]] = 0; } int ma = 0; for (int i = 1; i <= col; i++) { if (ma < num[i]) ma = num[i]; } cout << ma << endl; cin.get(); cin.get(); return 0; }
1,500
CPP
#include <bits/stdc++.h> const int INF = 2e9; const int mod = 1e9 + 7; using namespace std; int p[200200], b[200200]; void solve() { int n; scanf("%d", &n); for (int i = 0; i < n; ++i) { scanf("%d", &p[i]); --p[i]; } for (int i = 0; i < n; ++i) scanf("%d", &b[i]); int cnt = 0, s = 0; for (int i = 0; i < n; ++i) { if (p[i] != -1) { ++cnt; int cur = p[i]; int t; p[i] = -1; while (cur != i) { t = cur; cur = p[cur]; p[t] = -1; } } s += b[i]; } cout << (cnt > 1 ? cnt : 0) + ((s + 1) % 2) << endl; } int main() { solve(); return 0; }
1,700
CPP
#include <bits/stdc++.h> using namespace std; #define pb push_back #define eb emplace_back #define x first #define y second #define FOR(i, m, n) for (ll i(m); i < n; i++) #define DWN(i, m, n) for (ll i(m); i >= n; i--) #define REP(i, n) FOR(i, 0, n) #define DW(i, n) DWN(i, n, 0) #define F(n) REP(i, n) #define FF(n) REP(j, n) #define D(n) DW(i, n) #define DD(n) DW(j, n) using ll = long long; using ld = long double; using pll = pair<ll, ll>; using tll = tuple<ll, ll, ll>; using vll = vector<ll>; using vpll = vector<pll>; using vtll = vector<tll>; using gr = vector<vll>; using wgr = vector<vpll>; void add_edge(gr&g,ll x, ll y){ g[x].pb(y);g[y].pb(x); } void add_edge(wgr&g,ll x, ll y, ll z){ g[x].eb(y,z);g[y].eb(x,z); } template<typename T,typename U> ostream& operator<<(ostream& os, const pair<T,U>& p) { cerr << ' ' << p.x << ',' << p.y; return os; } template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) { for(auto x: v) os << ' ' << x; return os; } template <typename T> ostream& operator<<(ostream& os, const set<T>& v) { for(auto x: v) os << ' ' << x; return os; } template<typename T,typename U> ostream& operator<<(ostream& os, const map<T,U>& v) { for(auto x: v) os << ' ' << x; return os; } struct d_ { template<typename T> d_& operator,(const T& x) { cerr << ' ' << x; return *this;} } d_t; #define dbg(args ...) { d_t,"|",__LINE__,"|",":",args,"\n"; } #define deb(X ...) dbg(#X, "=", X); #define EPS (1e-10) #define INF (1LL<<61) #define CL(A,I) (memset(A,I,sizeof(A))) #define all(x) (x).begin(),(x).end() #define rall(x) (x).rbegin(),(x).rend() ll n,m,k; int main(void) { ios_base::sync_with_stdio(false); cin >> n >> m >> k; map<string,ll> pid; F(n) { string x; cin >> x; pid[x]=i; } map<ll,vll> s2p; vll deg(n); bool ok = 1; gr ng(n); F(m) { string x; cin >> x; ll p; cin >> p; p--; bool cok = 0; FOR(msk,0,1ll<<k) { string c = x; FF(k) if((1ll<<j)&msk) c[j]='_'; if(!pid.count(c)) continue; ll pt = pid[c]; if(pt==p) cok=1; else { deg[pt]++; ng[p].eb(pt); } } ok &= cok; } queue<ll> q; F(n) if(!deg[i]) q.push(i); ll done = 0; vll ret; while(q.size()) { ll top = q.front(); q.pop(); ret.pb(top); for(auto j: ng[top]) { deg[j]--; if(!deg[j]) q.push(j); } done++; } if(ok && done==n) { cout << "YES" << endl; for(auto i:ret) cout << i+1 << ' '; cout << endl; } else cout << "NO" << endl; return 0; }
2,300
CPP
n, m = map(int, input().split()) s1 = set() for _ in range(n): s1.add(input()) s2 = set() for _ in range(m): s2.add(input()) nm = len(s1 & s2) if n + (nm % 2) > m: print('YES') else: print('NO')
1,100
PYTHON3
#include <bits/stdc++.h> using namespace std; int T, n, m, a[1005], b[1005], book[1005]; int main() { cin >> T; while (T--) { memset(book, 0, sizeof(book)); cin >> n >> m; for (register int i = 1; i <= n; i++) cin >> a[i], book[a[i]] = 1; ; for (register int i = 1; i <= m; i++) cin >> b[i]; int flag = 0; for (register int i = 1; i <= m; i++) { if (book[b[i]]) { flag = 1; puts("YES"); printf("1 %d\n", b[i]); break; } } if (!flag) puts("NO"); } return 0; }
800
CPP
for ik in range(int(input())): n,k=map(int,input().split()) ca,cw=map(int,input().split()) s,w1=map(int,input().split()) if s>w1: s,w1=w1,s ca,cw=cw,ca tot=0 lwe=[n,k,ca,cw,s,w1] for i in range(ca+1): ans=0 n,k,ca,cw,s,w1=lwe[0],lwe[1],lwe[2],lwe[3],lwe[4],lwe[5] w=n//s #print(w,i) if w<i: continue ans+=i n-=i*s ans+=min(cw,n//w1) cw-=min(cw,n//w1) ca-=i ans+=min(ca,k//s) k-=min(ca,k//s)*s ans+=min(cw,k//w1) tot=max(tot,ans) #print(ans) print(tot)
1,700
PYTHON3
#include <bits/stdc++.h> using namespace std; void read_file(bool outToFile = true) {} int n, m, d; const int nMax = 150000 + 9; int A[nMax], B[nMax], T[nMax]; long long dp[2][nMax]; int ptr; deque<pair<int, int> > dq; void insert(int k) { while (!dq.empty() && dp[!ptr][k] <= dq.back().first) dq.pop_back(); dq.push_back(make_pair(dp[!ptr][k], k)); } void remove(int k) { if (!dq.empty() && dq.front().second == k) dq.pop_front(); } void build_dp() { ptr = 0; for (int j = 0; j < n; j++) dp[ptr][j] = abs(j - A[0]); for (int i = 1; i < m; i++) { ptr = !ptr; int t = T[i] - T[i - 1]; dq.clear(); for (int k = 0; k <= min(n - 1 * 1LL, 1LL * d * t); k++) insert(k); for (int j = 0; j < n; j++) { dp[ptr][j] = abs(j - A[i]) + dq.front().first; if (j + 1LL * d * t + 1 <= n - 1) insert(j + 1LL * d * t + 1); if (j - 1LL * d * t >= 0) remove(j - 1LL * d * t); } } } int main() { read_file(); while (scanf("%d%d%d", &n, &m, &d) != EOF) { for (int i = 0; i < m; i++) scanf("%d%d%d", &A[i], &B[i], &T[i]), A[i]--; build_dp(); long long ans = LLONG_MAX; for (int j = 0; j < n; j++) ans = min(ans, dp[ptr][j]); ans = -ans; for (int i = 0; i < m; i++) ans += B[i]; printf("%lld\n", ans); } }
2,100
CPP
#Thanos Sort is a sorting algorithm which removes half of the list/array until it is perfectly balanced. def thanos_sort(y): for i in range(len(y) - 1): if int(y[i]) > int(y[i + 1]): # If the list is not sorted in decreasing order. if i < int(len(y)/2): del y[:int(len(y)/2)] # remove first "n" elements of the list else: del y[int(len(y) / 2):] # remove last "n" elements of the list return thanos_sort(y) return len(y) x = input() # Get the size of the array. y = input().split(" ") # Get the string and split it to make list(array). # Finally print the length of the array after thanos sorting. print(thanos_sort(y))
0
PYTHON3
count = 0 for _ in [0]*int(input()): if sum([int(i) for i in input().split()]) >= 2: count += 1 print(count)
800
PYTHON3
import math initCandies = int(input()) kmin = 1 kmax = initCandies def test(k): vasyaCandies = 0 totalCandies = initCandies while totalCandies > 0: if totalCandies < k: vasyaCandies += totalCandies totalCandies = 0 else: vasyaCandies += k totalCandies -= k totalCandies -= totalCandies // 10 return vasyaCandies * 2 >= initCandies def binarySearch(kmin, kmax): while abs(kmax - kmin) > 1: k = (kmin + kmax)//2 if test(k): kmax = k else: kmin = k+1 if test(kmin): return kmin else: return kmax print(binarySearch(1, initCandies))
1,500
PYTHON3
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; char s[100005]; long long a[100005]; long long Pow(long long a, long long b) { long long ans = 1; while (b) { if (b & 1) ans = (ans * a) % mod; a = (a * a) % mod; b >>= 1; } return ans % mod; } int dp[100005][2]; int main() { long long n; scanf("%lld", &n); for (long long i = 2; i * 2 <= n; i++) { for (long long j = 2; j * i <= n; j++) a[i * j] += i + j; } long long ans = 0; for (long long i = 4; i <= n; i++) ans += 2 * a[i]; printf("%lld\n", ans); }
1,800
CPP
n,m = map(int,input().split()) i=1 while(m>=0): z=m m -= i i+=1 if i>n: i=1 print(z)
800
PYTHON3
#include <bits/stdc++.h> using namespace std; int visited[101]; int p[101]; int flag; int totalVisited(0); void SCC(int parent, vector<vector<int> > &adjList) { visited[parent] = 1; totalVisited++; for (int i = 0; i < (int)adjList[parent].size(); i++) { int child = adjList[parent][i]; if (!visited[child]) { p[child] = parent; SCC(child, adjList); } else if (visited[child] && (child != p[parent])) { flag = 1; } } } int main() { int n, m; cin >> n >> m; if (n != m) { cout << "NO" << endl; return 0; } memset(visited, 0, sizeof(visited)); memset(p, 0, sizeof(p)); vector<vector<int> > adjList(n + 1); for (int i = 0; i < m; i++) { int node1, node2; cin >> node1 >> node2; adjList[node1].push_back(node2); adjList[node2].push_back(node1); } SCC(1, adjList); if (totalVisited < n) cout << "NO" << endl; else if (flag) cout << "FHTAGN!" << endl; else cout << "NO" << endl; return 0; }
1,500
CPP
# def gcd(lft, rght): # if lft < rght: # rght, lft = lft, rght # if rght == 0: # return lft # return gcd(rght, lft % rght) # # # def lcm(lft, rght): # return (lft * rght) / gcd(lft, rght) from collections import defaultdict guest_name = input() owner_name = input() letters_heap = input() wont_char_set = defaultdict(int) if sorted(list(guest_name) + list(owner_name)) == sorted(list(letters_heap)): print('YES') else: print('NO')
800
PYTHON3
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5; int cnt[maxn][26]; map<int, map<int, int>> mp; void init(int x) { for (int i = 0; i < x; i++) { for (int j = 0; j < 26; j++) { cnt[i][j] = 0; } } } int main() { ios::sync_with_stdio(false); cin.tie(0); int t; cin >> t; while (t--) { string s; int n, k; cin >> n >> k; cin >> s; int x = (k + 1) / 2; init(x); for (int i = 0; i < k; i++) { for (int j = 0; j < n;) { int g = abs(i - (k - 1)); if (i < x) { g = i; } cnt[g][s[i + j] - 'a']++; j += k; } } for (int i = 0; i < x; i++) { int max1 = 0; for (int j = 0; j < 26; j++) { if (cnt[i][j] > max1) { max1 = cnt[i][j]; for (int g = 0; g < 26; g++) { mp[i][g] = 0; } mp[i][j] = 1; } } } int ans = 0; for (int i = 0; i < k; i++) { for (int j = 0; j < n;) { int g = abs(i - (k - 1)); if (i < x) { g = i; } if (mp[g][s[i + j] - 'a'] == 0) ans++; j += k; } } cout << ans << '\n'; } }
1,500
CPP
x = input() s = input() i = 0 while i + 1 < len(s) and s[i] <= s[i + 1]: i += 1 print(s[:i] + s[i+1:])
1,200
PYTHON3
#include <bits/stdc++.h> using namespace std; const long long MAXN = 200005; const long long MAXLOG = log2(MAXN); const long long oo = 1000000005; const unsigned long long OO = 1000000000000000005; const double pi = acos(-1.0); const double EPS = 1e-4; const long long dr[4] = {-1, 0, 1, 0}; const long long dc[4] = {0, 1, 0, -1}; const long long dr8[8] = {-1, -1, 0, 1, 1, 1, 0, -1}; const long long drknight[8] = {-2, -1, 1, 2, 2, 1, -1, -2}; const long long dcknight[8] = {1, 2, 2, 1, -1, -2, -2, -1}; const long long MOD = 1000000007; const long long ALPHABET_SIZE = 52; const long long MAX = 1000005; long long n, m; long long a[MAXN], b[MAXN]; vector<pair<long long, long long> > g[MAXN]; pair<long long, long long> p[MAXN]; bool mk[MAXN]; bool ok; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> m; vector<long long> res; for (long long i = 1; i <= n; i++) { cin >> a[i]; } for (long long i = 0; i < m; i++) { cin >> p[i].first >> p[i].second; b[p[i].first]++; b[p[i].second]++; g[p[i].first].push_back({i, p[i].second}); g[p[i].second].push_back({i, p[i].first}); } queue<long long> q; for (long long i = 1; i <= n; i++) { if (a[i] >= b[i] and a[i] > 0) { ok = 1; q.push(i); } } if (!ok) { cout << "DEAD"; return 0; } while (!q.empty()) { long long u = q.front(); q.pop(); if (a[u] < b[u]) { cout << "DEAD"; return 0; } for (auto e : g[u]) { long long v = e.second, j = e.first; if (mk[j]) continue; mk[j] = 1; a[u]--; b[u]--; b[v]--; res.push_back(j); if (a[v] >= b[v]) q.push(v); } } for (long long i = 1; i <= n; i++) { if (a[i] < 0) ok = 0; } if (!ok or res.size() != m) { cout << "DEAD"; return 0; } cout << "ALIVE\n"; for (long long i = res.size() - 1; i >= 0; i--) { cout << res[i] + 1 << " "; } return 0; }
2,400
CPP
#include <bits/stdc++.h> using namespace std; const long long inf = 10000000000000000LL; long long f[4001], g[4001]; int t[2001], c[2001]; int main() { long long ans; int n, i, j; scanf("%d", &n); for (i = 1; i <= n; i++) scanf("%d%d", &t[i], &c[i]); for (i = 0; i <= 4000; i++) f[i] = inf; f[2000] = 0; for (i = 1; i <= n; i++) { for (j = 0; j <= 4000; j++) { g[j] = inf; if (j >= t[i] && f[j - t[i]] + c[i] < g[j]) g[j] = f[j - t[i]] + c[i]; if (j < 4000 && f[j + 1] < g[j]) g[j] = f[j + 1]; } memcpy(f, g, sizeof(g)); } for (ans = inf, i = 2000; i <= 4000; i++) if (f[i] < ans) ans = f[i]; printf("%I64d\n", ans); return 0; }
1,900
CPP
n = int(input()) lo = 0 hi = 10 ** 9 while lo <= hi: mid = (lo + hi) // 2 tmp = mid * (mid + 1) // 2 if n > tmp: lo = mid + 1 else: hi = mid - 1 # print(hi) mult = hi * (hi + 1) // 2 + 1 print(n - mult + 1)
1,000
PYTHON3
#include <bits/stdc++.h> using namespace std; void readFile() {} long long binpow(long long a, long long b) { if (b == 0) return 1; long long res = binpow(a, b / 2); if (b % 2) return res * res * a; else return res * res; } int main() { readFile(); ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; if (n % 2 == 0) cout << -1 << endl; else { for (int i = 0; i <= n - 1; i++) cout << i << " "; cout << endl; for (int i = 0; i <= n - 1; i++) cout << i << " "; cout << endl; for (int i = 0; i <= n - 1; i++) { cout << (2 * i) % n << " "; } cout << endl; } return 0; }
1,300
CPP