solution
stringlengths
10
983k
difficulty
int64
0
25
language
stringclasses
2 values
a=int(input()) b=int(input()) c=int(input()) q=a+b+c w=a*b*c e=(a+b)*c r=(a*b)+c t=a*(b+c) y=a+(b*c) m=max(q,w,e,r,t,y) print(m)
7
PYTHON3
n = input() l = 0 q = len(n) sogl = ['q', 'w', 'r', 't', 'y', 'p', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'z', 'x', 'c', 'v', 'b', 'n', 'm'] for i in range(1, len(n) - 1): if (((n[i - 1] != n[i + 1]) or ((n[i] != n[i - 1]) and (n[i-1] == n[i + 1]))) and (n[i - 1] in sogl) and (n[i] in sogl) and (n[i + 1] in sogl)): print (n[l:i + 1:1], end=" ") l = i + 1 n = n[0:i] + 'a' + n[i + 1:q] print (n[l:len(n):1])
7
PYTHON3
#include <bits/stdc++.h> using namespace std; struct MCMF { struct Edge { int to, cap, cost, rev; Edge(int to, int cap, int cost) : to(to), cap(cap), cost(cost) {} }; vector<Edge> G[3000]; int N, src, sink, work[3000], dist[3000]; bool chk[3000]; MCMF(int N, int src, int sink) : N(N), src(src), sink(sink) {} void add_edge(int f, int t, int cap, int cost) { G[f].emplace_back(t, cap, cost); G[t].emplace_back(f, 0, -cost); G[f].back().rev = G[t].size() - 1; G[t].back().rev = G[f].size() - 1; } void add_edge_from_source(int t, int cap, int cost) { add_edge(src, t, cap, cost); } void add_edge_to_sink(int f, int cap, int cost) { add_edge(f, sink, cap, cost); } void prep() { int temp; queue<int> Q; priority_queue<pair<int, int>> PQ; memset(dist, 0x7f, sizeof(dist)); memset(chk, 0, sizeof(chk)); dist[src] = 0; Q.push(src); while (!Q.empty()) { int c = Q.front(); Q.pop(); chk[c] = false; for (auto &e : G[c]) if (e.cap > 0 && dist[e.to] > dist[c] + e.cost) { dist[e.to] = dist[c] + e.cost; if (!chk[e.to]) { chk[e.to] = true; Q.push(e.to); } } } temp = dist[sink] - dist[src]; for (int i = 0; i < N; i++) for (auto &e : G[i]) e.cost += dist[i] - dist[e.to]; memset(dist, 0x7f, sizeof(dist)); dist[src] = 0; PQ.emplace(0, src); while (!PQ.empty()) { auto [t, c] = PQ.top(); PQ.pop(); if (-t != dist[c]) continue; for (auto &e : G[c]) if (e.cap > 0 && dist[e.to] > dist[c] + e.cost) { dist[e.to] = dist[c] + e.cost; PQ.emplace(-dist[e.to], e.to); } } for (int i = 0; i < N; i++) dist[i] += temp; } int dfs(int c, int MF = 0x7fffffff) { int flow; chk[c] = true; if (c == sink) return MF; for (int &i = work[c]; i < G[c].size(); i++) { auto &e = G[c][i]; if (!chk[e.to] && e.cap > 0 && dist[e.to] == dist[c] + e.cost && (flow = dfs(e.to, min(e.cap, MF)))) { e.cap -= flow; G[e.to][e.rev].cap += flow; return flow; } } return 0; } int flow() { int ret = 0; for (prep(); memset(work, 0, sizeof(work)); memset(chk, 0, sizeof(chk))) { int M = 0x7fffffff; while (int temp = dfs(src)) { ret += dist[sink] * temp; memset(chk, 0, sizeof(chk)); } for (int i = 0; i < N; i++) if (chk[i]) for (auto &e : G[i]) if (e.cap > 0 && !chk[e.to]) M = min(M, dist[i] + e.cost - dist[e.to]); if (M == 0x7fffffff) break; for (int i = 0; i < N; i++) if (!chk[i]) dist[i] += M; } return ret; } }; int ans[50][50], P[50][50], V[50][50]; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ((void)0); ((void)0); ((void)0); int N, M, T, cnt = 0; cin >> N >> M; T = N * (N - 1) / 2; MCMF mf(T + N + 2, T + N, T + N + 1); memset(P, -1, sizeof(P)); for (int i = 0; i < N; i++) { for (int j = 0; j < i; j++) mf.add_edge_from_source(V[j][i] = cnt++, 1, 0); for (int j = 1; j < N; j++) mf.add_edge_to_sink(T + i, 1, 2 * j - 1); } while (M--) { int a, b; cin >> a >> b; --a; --b; mf.add_edge(V[min(a, b)][max(a, b)], T + a, 1, 0); ans[a][b] = 1; } for (int i = 0; i < N; i++) for (int j = 0; j < i; j++) if (mf.G[V[j][i]].size() == 1) { P[j][i] = mf.G[T + j].size(); mf.add_edge(V[j][i], T + j, 1, 0); P[i][j] = mf.G[T + i].size(); mf.add_edge(V[j][i], T + i, 1, 0); } mf.flow(); for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { if (P[i][j] == -1) cout << ans[i][j]; else cout << mf.G[T + i][P[i][j]].cap; } cout << '\n'; } return 0; }
11
CPP
#include <bits/stdc++.h> using namespace std; inline int Get() { int res = 0, q = 1; char ch = getchar(); while ((ch < '0' || ch > '9') && ch != '-') ch = getchar(); if (ch == '-') q = -1, ch = getchar(); while (ch >= '0' && ch <= '9') res = res * 10 + ch - '0', ch = getchar(); return res * q; } const double eps = 1e-12, pi = M_PI; const int oo = (int)2e9, mod = (int)1e9 + 7; const long long INF = (long long)1e17; const int N = (int)3e3; typedef int arr[N + 10]; typedef int arre[2 * N + 10]; int n, m, tot = 1, j, k, sc; arr g, ft; arre pt, nt, e; bool v[N + 10], ic[N + 10]; double ans; void Link(int x, int y) { pt[++tot] = y, nt[tot] = g[x], g[x] = tot; pt[++tot] = x, nt[tot] = g[y], g[y] = tot; } void Find(int x, int fa) { v[x] = 1; for (int i = g[x]; i; i = nt[i]) if (pt[i] != fa) { if (v[pt[i]]) j = x, k = pt[i], e[i] = e[i ^ 1] = 1; else Find(pt[i], x); } } void Dfs(int x, int fa) { ft[x] = fa; for (int i = g[x]; i; i = nt[i]) if (pt[i] != fa && !e[i]) Dfs(pt[i], x); } void Dp(int x, int fa, int dp, int ds) { if (ds <= 1) ans += 1. / dp; else ans += 1. / dp + 1. / (dp - ds + sc - ds + 2) - 1. / (dp - ds + sc); for (int i = g[x]; i; i = nt[i]) if (pt[i] != fa && !e[i]) Dp(pt[i], x, dp + 1, ds + ic[pt[i]]); } int main() { scanf( "%d" "\n", &n); for (int i = (1), end = (n); i <= end; ++i) scanf( "%d" "%d" "\n", &j, &k), ++j, ++k, Link(j, k); Find(1, 0); Dfs(j, 0); for (int now = k; now != j; now = ft[now]) ++sc, ic[now] = 1; ++sc, ic[j] = 1; for (int i = (1), end = (n); i <= end; ++i) Dp(i, 0, 1, ic[i]); printf( "%.10lf" "\n", ans); return 0; }
10
CPP
n=int(input()) l=list(map(int,input().split())) e=0 o=0 for i in l: if(i%2==0): e+=1 else: o+=1 print(min(e,o))
7
PYTHON3
t = int(input()) for t1 in range(t): s = input() s = list(s) rem = list() for data in range(len(s)): if(data == 0 or data %2 == 1): rem.append(s[data]) rem = "".join(rem) print(rem)
7
PYTHON3
n = int(input()) if (n < 4) or (n % 2 == 1): print(0) else: x = n / 2 if (x % 2 == 1): print(int(x//2)) else: print(int(x//2 - 1))
7
PYTHON3
#!/usr/bin/env python3 import sys if __name__ == "__main__": n = int(sys.stdin.readline()) ais = list(map(int, sys.stdin.readline().split())) if sum(ais)%n == 0: print(n) else: print(n-1)
8
PYTHON3
a = input() b = a.lower() c = ['a','o','y','e','u','i'] for i in b: if i in c: b = b.replace(i,'') b = list(b) b = '.'.join(b) print('.'+str(b))
7
PYTHON3
import math n = int(input()) m = int(input()) if n > 30: print(m) else: print(m%(2**n))
7
PYTHON3
s = input().split('.') if s[0][-1] == '9': print('GOTO Vasilisa.') else: if s[1][0] < '5': print(s[0]) else: print(int(s[0])+1)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; const int inf = 1000000000; int D, n, m, Q; struct data { int p[3], mn[3], mx[3], ch[2], sum; bool operator<(data a) const { if (p[D] == a.p[D] && p[(D + 1) % 3] == a.p[(D + 1) % 3]) return p[(D + 2) % 3] < a.p[(D + 2) % 3]; else if (p[D] == a.p[D]) return p[(D + 1) % 3] < a.p[(D + 1) % 3]; else return p[D] < a.p[D]; } } s[500009]; struct REC { int mn[3], mx[3]; } q; void init() { for (int i = 0; i < 3; ++i) { s[0].mn[i] = inf, s[0].mx[i] = -inf; } } void pushup(int x) { int l = s[x].ch[0], r = s[x].ch[1]; for (int i = 0; i < 3; ++i) { s[x].mn[i] = min(s[x].p[i], min(s[l].mn[i], s[r].mn[i])); s[x].mx[i] = max(s[x].p[i], max(s[l].mx[i], s[r].mx[i])); } s[x].sum = s[l].sum + s[r].sum + 1; } int build(int l, int r, int now) { int mid = (l + r) >> 1; D = now, nth_element(s + l, s + mid, s + 1 + r); if (mid > l) s[mid].ch[0] = build(l, mid - 1, (now + 1) % 3); if (r > mid) s[mid].ch[1] = build(mid + 1, r, (now + 1) % 3); pushup(mid); return mid; } int judge(int k) { if (!k) return 0; for (int i = 0; i < 3; ++i) { if (q.mn[i] > s[k].mx[i] || q.mx[i] < s[k].mn[i]) return 0; } int flag = 0; for (int i = 0; i < 3; ++i) { if (s[k].mn[i] >= q.mn[i] && s[k].mx[i] <= q.mx[i]) ++flag; } return flag == 3 ? 1 : -1; } int query(int x) { int p = judge(x), flag = 0; if (p == 0) return 0; if (p == 1) return s[x].sum; for (int i = 0; i < 3; ++i) { flag += (s[x].p[i] >= q.mn[i] && s[x].p[i] <= q.mx[i]); } if (flag == 3) return 1; if (query(s[x].ch[0])) return 1; if (query(s[x].ch[1])) return 1; return 0; } int main() { init(); int mn[3], mx[3]; mx[0] = mx[1] = mx[2] = 1; scanf("%d%d%d%d%d%d", &mn[0], &mn[1], &mn[2], &n, &m, &Q); for (int i = 1; i <= n; ++i) { int x, y, z; scanf("%d%d%d", &x, &y, &z); mx[0] = max(mx[0], x), mx[1] = max(mx[1], y), mx[2] = max(mx[2], z); mn[0] = min(mn[0], x), mn[1] = min(mn[1], y), mn[2] = min(mn[2], z); } for (int i = 1; i <= m; ++i) { int x, y, z; scanf("%d%d%d", &x, &y, &z); if (x >= mn[0] && x <= mx[0] && y >= mn[1] && y <= mx[1] && z >= mn[2] && z <= mx[2]) { printf("INCORRECT\n"); return 0; } s[i].p[0] = x, s[i].p[1] = y, s[i].p[2] = z; } printf("CORRECT\n"); int root = build(1, m, 0); for (int i = 1; i <= Q; ++i) { int x, y, z; scanf("%d%d%d", &x, &y, &z); if (x >= mn[0] && x <= mx[0] && y >= mn[1] && y <= mx[1] && z >= mn[2] && z <= mx[2]) { printf("OPEN\n"); } else { q.mn[0] = min(mn[0], x), q.mn[1] = min(mn[1], y), q.mn[2] = min(mn[2], z); q.mx[0] = max(mx[0], x), q.mx[1] = max(mx[1], y), q.mx[2] = max(mx[2], z); if (!query(root)) printf("UNKNOWN\n"); else printf("CLOSED\n"); } } return 0; }
11
CPP
#include <bits/stdc++.h> using namespace std; const long long N = 3e5 + 10; long long n, a[N], cnt[2]; int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; reverse(a, a + n); for (int i = 0; i < n; i++) { cnt[i % 2] += (a[i] + 1) / 2, cnt[(i & 1) ^ 1] += a[i] / 2; } cout << min(cnt[0], cnt[1]) << endl; }
8
CPP
#include <bits/stdc++.h> using namespace std; void solve() { int n, k; string str; cin >> n >> k >> str; bool ans = true; for (int i = k; i < n; i++) if (str[i] != '?' && str[i % k] == '?') str[i % k] = str[i]; for (int i = k; i < n; i++) if (str[i] != '?' && str[i % k] != '?' && str[i] != str[i % k]) { ans = false; break; } int q0 = 0, q1 = 0; for (int i = 0; i < k && ans; i++) q0 += (str[i] == '0'), q1 += (str[i] == '1'); if (!ans) printf("NO\n"); else if (q0 <= k / 2 && q1 <= k / 2) printf("YES\n"); else printf("NO\n"); } int main() { int t; scanf(" %d", &t); while (t--) solve(); return 0; }
7
CPP
#include <bits/stdc++.h> using namespace std; map<char, int> mm; char str[105][105]; int mark[105][105]; int go[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}}; int n, m; bool can(int x, int y) { if (x < 0 || y < 0) return false; if (x >= n || y >= m) return false; return true; } int main() { int i, j, k; char co[2]; while (scanf("%d%d%s", &n, &m, co) != EOF) { mm.clear(); mm['.'] = 1; mm[co[0]] = 1; for (i = 0; i < n; i++) scanf("%s", str[i]); for (i = 0; i < n; i++) { for (j = 0; j < m; j++) { if (str[i][j] == co[0]) { for (k = 0; k < 4; k++) { if (can(i + go[k][0], j + go[k][1])) { mm[str[i + go[k][0]][j + go[k][1]]] = 1; } } } } } printf("%d\n", mm.size() - 2); } return 0; }
8
CPP
#include <bits/stdc++.h> int main() { int n; scanf("%d", &n); int i; int total[1000 + 1]; for (i = 0; i < 1000 + 1; i++) { total[i] = 0; } for (i = 0; i < n; i++) { int a; scanf("%d", &a); total[a]++; } int count = 0; while (1) { int remain = 0; for (i = 1; i < 1000 + 1; i++) { if (total[i] > 0) { remain++; } if (remain >= 2) break; } if (remain <= 1) break; int start; int find = 0; for (i = 1; i < 1000 + 1; i++) { if (total[i] > 0) { start = i; find = 1; break; } } if (!find) break; int first = 1; for (i = start + 1; i < 1000 + 1; i++) { if (total[i] > 0) { count++; if (first) { total[start]--; first = 0; } total[i]--; } } } printf("%d\n", count); return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; const int MAX = 2e5 + 5; const long long INF = 1e18; int n, cnt; long long x, y; vector<int> g[MAX]; int dfs(int u, int p = -1) { if (g[u].size() == 1 && p != -1) return 1; int s = 0; for (int v : g[u]) if (v != p) s += dfs(v, u); if (s == 0) return 1; if (s == 1) { cnt++; return 1; } cnt += 2; return 0; } int main() { scanf("%d%I64d%I64d", &n, &x, &y); for (int i = 1; i < n; i++) { int a, b; scanf("%d%d", &a, &b); g[a].push_back(b); g[b].push_back(a); } int st = 0; for (int i = 1; i <= n; i++) if ((int)g[i].size() == n - 1) st = 1; if (y < x) { long long ans = x + (n - 2) * y; if (!st) { ans -= x; ans += y; } printf("%I64d\n", ans); return 0; } dfs(1); long long ans = cnt * x + (n - 1 - cnt) * y; printf("%I64d\n", ans); return 0; }
10
CPP
numtest = int(input()) result = [] for i in range(numtest): numplank = int(input()) lengths = list(map(lambda num: int(num), input().split())) lengths.sort(reverse=True) result.append(str(min(lengths[1] - 1, numplank - 2))) print('\n'.join(result))
7
PYTHON3
#include <iostream> #include <cstdio> #define ll long long using namespace std; inline int read() { int x = 0, f = 1; char ch = getchar(); while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();} while(ch >= '0' && ch <= '9') {x = (x << 3) + (x << 1) + (ch ^ 48); ch = getchar();} return x * f; } const int N = 410,mod = 998244353; int n,sa,sb; int a[N],b[N]; int f[N][N][N],fac[N],inv[N]; int ksm(int x,int y) { int res = 1; for(;y;y >>= 1,x = 1ll * x * x % mod) if(y & 1) res = 1ll * res * x % mod; return res; } void add(int &x,int y){x = x + y; if(x >= mod) x -= mod;} int main() { n = read(); for(int i = 1;i <= n;i ++) a[i] = read(),b[i] = read(),sa += a[i],sb += b[i]; fac[0] = 1; for(int i = 1;i <= 400;i ++) fac[i] = 1ll * fac[i - 1] * i % mod; inv[400] = ksm(fac[400],mod - 2); for(int i = 399;i >= 0;i --) inv[i] = 1ll * inv[i + 1] * (i + 1) % mod; f[0][0][0] = mod - 1; for(int i = 1;i <= n;i ++) for(int j = 0;j <= sa;j ++) for(int k = 0;k <= sb;k ++) { if(!f[i - 1][j][k]) continue; add(f[i][j][k],f[i - 1][j][k]); int x = 1; for(int l = 0;l < b[i];l ++,x = 1ll * x * a[i] % mod) add(f[i][j + a[i]][k + l],mod - 1ll * x * inv[l] % mod * f[i - 1][j][k] % mod); } int ans = 0; for(int i = 1,x,invi;i <= sa;i ++) { invi = ksm(i,mod - 2); x = 1ll * sa * invi % mod; for(int j = 0;j <= sb;j ++,x = 1ll * x * invi % mod) add(ans,1ll * x * fac[j] % mod * f[n][i][j] % mod); } cout << ans << "\n"; }
0
CPP
#include <bits/stdc++.h> using namespace std; const int MAX = 500004; long long p, pos1, pos2, q, x, l, ans = 0, r, y, z, k, n, m, t, d, c = 0, sum = 0; long long int mn = 0x3f3f3f3f, len, cnt = 1, mx = -1000; std::vector<int> v[MAX]; int a[105]; string s[10004], s1, s2; map<string, string> mp; vector<int> goal[100015]; void precomp() { for (int i = 1; i < 100010; i++) for (int j = i; j < 100010; j += i) goal[j].push_back(i); } int main() { cin >> n; precomp(); int recent[100005]; memset(recent, (0), sizeof(recent)); for (long long int i = (1); i <= (n); i++) { cin >> x >> y; if (y == 0) { cout << goal[x].size() << endl; for (int k : goal[x]) recent[k] = i; } else { c = 0; for (int k : goal[x]) { c += (recent[k] < i - y); recent[k] = i; } cout << c << endl; } } return 0; }
8
CPP
import sys import math readline = sys.stdin.readline read = sys.stdin.read ns = lambda: readline().rstrip() ni = lambda: int(readline().rstrip()) nm = lambda: map(int, readline().split()) nl = lambda: list(map(int, readline().split())) prn = lambda x: print(*x, sep='\n') def solve(): n = ni() print(math.cos(math.pi / (4 * n)) / math.sin(math.pi / (2 * n))) return # solve() T = ni() for _ in range(T): solve()
9
PYTHON3
#include <bits/stdc++.h> using namespace std; long long solve(string s, long long k) { long long n = s.size(); if (count(s.begin(), s.end(), s[0]) == n) return (n * k) / 2; if (k == 1) { long long ans = 0; for(int i = 1; i < n; i++) { if (s[i] == s[i - 1]) ans++, i++; } return ans; } if (s[0] != s[n - 1]) return solve(s, 1) * k; int pref = 0; while (s[pref] == s[0]) pref++; string inside = s.substr(pref, n - pref) + s.substr(0, pref); return solve(s, 1) + solve(inside, k - 1); } int main() { string s; long long k; cin >> s >> k; cout << solve(s, k); }
0
CPP
# import sys # sys.stdin=open('input.txt','r') # sys.stdout=open('output.txt','w') import copy # snippets gcd lcm snippet ............................................................. def gcd(x, y): while (y): x, y = y, x % y return x def lcm(x,y): return x*y//gcd(x,y) # for alphagoai def gcd(a, b): while (b): a, b = b, a % b return a def lcm(a,b): return a*b//gcd(a,b) # to check number is prime or not in n**.5//6 complexity def is_prime(n): if (n <= 1): return False if (n <= 3): return True if (n % 2 == 0 or n % 3 == 0): return False i = 5 while (i * i <= n): if (n % i == 0 or n % (i + 2) == 0): return False i = i + 6 return True # kmp search snippet ........................................................... def LSPtable(pattern): n=len(pattern) l=[0]*n j=0 for i in range(1,n): while j>0 and pattern[i]!=pattern[j]: j=l[j-1] if pattern[i]==pattern[j]: l[i]=j+1 j+=1 else: l[i]=0 return l def KMPsearch(pattern,string): lsp=LSPtable(pattern) j=0 for i in range(len(string)): while j>0 and string[i]!=pattern[j]: j=lsp[j-1] if string[i]==pattern[j]: j+=1 if j== len(pattern): return i-j+1 return -1 # Binary Exponentiation # takes logarithmic time complex for calculatation of a power of some watch erritcho video if forgot # below is iterative implementation of binary exponentiation as iterative's are faster than recurssive def power(a,b): res=1 while b>0: if b%2:res*=a a*=a b=b//2 return res # mod inverse function...................... # if m is prime ....... fermats's little theorem def modInverse(a, m): g = gcd(a, m) if (g != 1): print("Inverse doesn't exist") else: print("Modular multiplicative inverse is ", power(a, m - 2, m)) def power(x, y, m): if (y == 0): return 1 p = power(x, y // 2, m) % m p = (p * p) % m if (y % 2 == 0): return p else: return ((x * p) % m) def gcd(a, b): if (a==0): return b return gcd(b % a, a) # fenwick tree snippet ......................................................... def getsum(BITTree,i): s=0 while i>0: s+=BITTree[i] i-=i&(-i) return s def updatebit(BITTree,n,i,v): i=i+1 while i<=n: BITTree[i]+=v i+=i&(-i) def constructor(arr, n): BITTree =[0]*(n+1) for i in range(n): updatebit(BITTree,n,i,arr[i]) return BITTree def arrIn(): return list(map(int,input().split())) def mapIn(): return map(int,input().split()) # import sys # sys.stdin=open('input.txt','r') # sys.stdout=open('output.txt','w') for i in range(int(input())): n=int(input()) if n%2==0: x=1 y=2 for i in range(n): if i%2: print(x,end=" ") x+=2 else: print(y,end=" ") y+=2 print() else: x=1 y=2 for i in range(n-3): if i%2: print(x,end=" ") x+=2 else: print(y,end=" ") y+=2 print(n,n-2,n-1)
7
PYTHON3
name = input() name = name[0:3] print(name)
0
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int n; char c[100005]; long a[100005]; cin >> n; cin >> c; for (int i = 0; i < n; i++) scanf("%ld", &a[i]); int i = 0; int s = 0, cn = 1; n = n - 1; while (1) { if (c[s] == '>') s += a[s]; else s -= a[s]; if (s < 0 or s > n) { cn = 0; break; } else cn++; if (cn == n + 10000000) break; } if (cn == 0) cout << "FINITE" << endl; else cout << "INFINITE" << endl; return 0; }
8
CPP
n = int(input()) s = list(input()) answer = [] for i in range(len(s)): if len(answer) == 0: answer.append(s[i]) if answer[-1] != s[i] and len(answer) % 2 == 1: answer.append(s[i]) elif len(answer) % 2 == 0: answer.append(s[i]) if len(answer) % 2 == 1: answer = answer[:-1] print(len(s) - len(answer)) print("".join(answer))
9
PYTHON3
#include <bits/stdc++.h> using namespace std; const int INF = 1000 * 1000 * 1000; const long long LINF = 1LL * INF * INF; const long double PI = acos(-1.); const double EPS = 1e-6; long long mod = INF + 7; const int maxn = 1000; long long d[maxn][maxn]; int main() { int n, m, k; cin >> n >> m >> k; if (false) { for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) d[i][j] = LINF; d[i][i] = 0; } for (int i = 0; i < m; ++i) { long long a, b, c; cin >> a >> b >> c; a--; b--; d[a][b] = c; d[b][a] = c; } for (int k = 0; k < n; ++k) for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) if (d[i][k] < LINF && d[k][j] < LINF) d[i][j] = min(d[i][j], d[i][k] + d[k][j]); vector<long long> arr; for (int i = 0; i < n; ++i) { for (int j = i + 1; j < n; ++j) arr.push_back(d[i][j]); } sort(arr.begin(), arr.end()); cout << arr[k - 1]; } else { vector<pair<int, pair<int, int> > > arr1; for (int i = 0; i < m; ++i) { long long a, b, c; cin >> a >> b >> c; a--; b--; arr1.push_back(make_pair(c, make_pair(a, b))); } sort(arr1.begin(), arr1.end()); while ((int)arr1.size() > k) arr1.pop_back(); set<int> v; for (int i = 0; i < (int)arr1.size(); ++i) { v.insert(arr1[i].second.second); v.insert(arr1[i].second.first); } map<int, int> ind; int cnt = 0; for (auto it : v) { ind[it] = cnt++; } n = cnt; for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) d[i][j] = LINF; d[i][i] = 0; } for (int i = 0; i < (int)arr1.size(); ++i) { long long a = ind[arr1[i].second.second]; long long b = ind[arr1[i].second.first]; long long c = arr1[i].first; d[a][b] = c; d[b][a] = c; } for (int k = 0; k < n; ++k) for (int i = 0; i < n; ++i) if (d[i][k] < LINF) for (int j = 0; j < n; ++j) if (d[i][k] < LINF && d[k][j] < LINF) d[i][j] = min(d[i][j], d[i][k] + d[k][j]); vector<long long> arr; for (int i = 0; i < n; ++i) { for (int j = i + 1; j < n; ++j) arr.push_back(d[i][j]); } sort(arr.begin(), arr.end()); cout << arr[k - 1]; } return 0; }
12
CPP
x=int(input()) y=x+1 c=1 while(c!=0): c=0 r=str(y) r=list(r) for i in range(0,len(r)): for j in range(i+1,len(r)): if(r[i]==r[j]): c+=1 y=y+1 print(y-1)
7
PYTHON3
from collections import deque import sys input = sys.stdin.readline def bfs(s): q = deque() q.append(s) visit = [0] * (n + 1) visit[s] = 1 parent = [-1] * (n + 1) p = [] while q: i = q.popleft() p.append(i) for j in G[i]: if not visit[j]: q.append(j) visit[j] = 1 parent[j] = i return parent, p n = int(input()) a = list(map(int, input().split())) cnt = [0] * 3 for i in a: cnt[i] += 1 G = [[] for _ in range(n + 1)] for _ in range(n - 1): u, v = map(int, input().split()) G[u].append(v) G[v].append(u) parent, p = bfs(1) dpr, dpb = [0] * (n + 1), [0] * (n + 1) ans = 0 for _ in range(n - 1): i = p.pop() j = parent[i] if a[i - 1] == 1: dpr[i] += 1 elif a[i - 1] == 2: dpb[i] += 1 if (not dpr[i] and dpb[i] == cnt[2]) or (not dpb[i] and dpr[i] == cnt[1]): ans += 1 dpr[j] += dpr[i] dpb[j] += dpb[i] print(ans)
12
PYTHON3
n,m = map(int,input().split()) ans = max(n*2, m*3) while ans//2 + ans//3 - ans//6 < n+m: ans += 1 print(ans)
9
PYTHON3
#include <bits/stdc++.h> using namespace std; void _fill_int(int* p, int val, int rep) { int i; for (i = 0; i < rep; i++) p[i] = val; } signed long long N, K; vector<string> S; class Trie { public: vector<vector<int> > V; int find(string s) { int cur = 0; for (__typeof(s.begin()) it = s.begin(); it != s.end(); it++) if ((cur = V[cur][*it]) == 0) return -1; return cur; } void create(vector<string> S) { V.clear(); V.push_back(vector<int>(256)); sort(S.begin(), S.end()); for (__typeof(S.begin()) it = S.begin(); it != S.end(); it++) { int cur = 0; for (__typeof((*it).begin()) c = (*it).begin(); c != (*it).end(); c++) { if (V[cur][*c] == 0) V.push_back(vector<int>(256)), V[cur][*c] = V.size() - 1; cur = V[cur][*c]; } } } }; Trie t; bool winwin(int cur) { int i; for (i = 0; i < 256; i++) if (t.V[cur][i] != 0) { if (winwin(t.V[cur][i]) == false) return true; } return false; } bool loselose(int cur) { int i, num = 0; for (i = 0; i < 256; i++) if (t.V[cur][i] != 0) { if (loselose(t.V[cur][i]) == false) return true; if (loselose(t.V[cur][i]) == true) num++; } if (num) return false; return true; } void solve() { int f, i, j, k, l, x, y; cin >> N >> K; for (i = 0; i < N; i++) { string s; cin >> s; S.push_back(s); } t.create(S); bool b1 = winwin(0); bool b2 = loselose(0); if (!b1) { cout << "Second" << endl; } else { if (b2) { cout << "First" << endl; } else { if (K % 2) cout << "First" << endl; else cout << "Second" << endl; } } } int main(int argc, char** argv) { string s; if (argc == 1) ios::sync_with_stdio(false); for (int i = 1; i < argc; i++) s += argv[i], s += '\n'; for (int i = s.size() - 1; i >= 0; i--) ungetc(s[i], stdin); solve(); return 0; }
8
CPP
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:16000000") using namespace std; const int Maxn = 200005; const int Maxm = 2 * Maxn; const int Maxs = 1048576; int n, q; int a[Maxm], b[Maxm], c[Maxm]; vector<int> neigh[Maxn]; int my[Maxn]; int cur, lef[Maxn], rig[Maxn]; long long BIT[Maxn]; long long mn[Maxs], flag[Maxs]; void downOn(int v, long long fl) { mn[v] += fl; flag[v] += fl; } void Down(int v) { if (flag[v]) { downOn(2 * v, flag[v]); downOn(2 * v + 1, flag[v]); flag[v] = 0; } } void Union(int v) { mn[v] = min(mn[2 * v], mn[2 * v + 1]); } void Update(int v, int l, int r, int a, int b, long long val) { if (l == a && r == b) downOn(v, val); else { Down(v); int m = l + r >> 1; if (a <= m) Update(2 * v, l, m, a, min(m, b), val); if (m + 1 <= b) Update(2 * v + 1, m + 1, r, max(m + 1, a), b, val); Union(v); } } void Change(int v, int l, int r, int x, long long val) { if (l == r) { mn[v] = val; flag[v] = 0; } else { Down(v); int m = l + r >> 1; if (x <= m) Change(2 * v, l, m, x, val); else Change(2 * v + 1, m + 1, r, x, val); Union(v); } } long long Get(int v, int l, int r, int a, int b) { if (l == a && r == b) return mn[v]; else { Down(v); int m = l + r >> 1; if (b <= m) return Get(2 * v, l, m, a, b); if (m + 1 <= a) return Get(2 * v + 1, m + 1, r, a, b); return min(Get(2 * v, l, m, a, m), Get(2 * v + 1, m + 1, r, m + 1, b)); } } void Traverse(int v) { lef[v] = ++cur; for (int i = 0; i < neigh[v].size(); i++) Traverse(neigh[v][i]); rig[v] = cur; } void Add(int x, long long val) { for (int i = x; i <= n; i += i & -i) BIT[i] += val; } long long Get(int x) { long long res = 0; for (int i = x; i > 0; i -= i & -i) res += BIT[i]; return res; } int main() { scanf("%d %d", &n, &q); for (int i = 1; i <= 2 * n - 2; i++) { scanf("%d %d %d", &a[i], &b[i], &c[i]); if (i <= n - 1) neigh[a[i]].push_back(b[i]); else my[a[i]] = c[i]; } Traverse(1); for (int i = 1; i <= n - 1; i++) { int v = b[i]; Add(lef[v], c[i]); Add(rig[v] + 1, -c[i]); } for (int i = n; i <= 2 * n - 2; i++) Change(1, 1, n, lef[a[i]], Get(lef[a[i]]) + my[a[i]]); while (q--) { int typ, u, v; scanf("%d %d %d", &typ, &u, &v); if (typ == 1) if (u <= n - 1) { int mod = v - c[u]; c[u] = v; Add(lef[b[u]], mod); Add(rig[b[u]] + 1, -mod); Update(1, 1, n, lef[b[u]], rig[b[u]], mod); } else { my[a[u]] = v; Change(1, 1, n, lef[a[u]], Get(lef[a[u]]) + my[a[u]]); } else if (lef[u] <= lef[v] && lef[v] <= rig[u]) printf("%I64d\n", Get(lef[v]) - Get(lef[u])); else printf("%I64d\n", Get(1, 1, n, lef[u], rig[u]) - Get(lef[u]) + Get(lef[v])); } return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; int got, n; char s[101], a[101], b[101], c[101], ans[101] = {"Unhandled Exception"}; bool check() { int thr = 0; while (~scanf("%*[^a-z]%[a-z]", s), s[1] != 'a') { if (s[1] == 'r') thr |= check(); if (s[1] == 'h') scanf("%*[^a-zA-Z]%[a-zA-Z]", a), thr = 1; } scanf("%*[^a-zA-Z]%[a-zA-z]%*[^\"]\"%[^\"]", b, c); if (thr && !got && !strcmp(a, b)) got = 1, strcpy(ans, c); return thr; } int main() { scanf("%d", &n); while (~scanf("%*[^a-z]%[a-z]", s), s[1] == 'r') check(); printf("%s", ans); }
9
CPP
#include <bits/stdc++.h> using namespace std; const int maxn = 5005; int arr[maxn]; int dp[maxn][maxn]; int max_value[maxn][maxn]; inline int max(int a, int b) { return a > b ? a : b; } int main() { int n, q; scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &dp[1][i]); for (int i = 1; i <= n; i++) { for (int j = i; j <= n; j++) { if (i == 1) { max_value[i][j] = dp[i][j]; continue; } int x = dp[i - 1][j - 1] ^ dp[i - 1][j]; dp[i][j] = x; max_value[i][j] = max(max_value[i - 1][j - 1], max_value[i - 1][j]); max_value[i][j] = max(max_value[i][j], x); } } scanf("%d", &q); int l, r; for (int i = 1; i <= q; i++) { scanf("%d %d", &l, &r); printf("%d\n", max_value[r - l + 1][r]); } return 0; }
10
CPP
#include <bits/stdc++.h> using namespace std; int n, d, h; void solve() { if (n == 2) { if (d != h) cout << -1 << '\n'; else cout << 1 << ' ' << 2 << '\n'; return; } if (d > 2 * h || d == 1) { cout << -1 << '\n'; return; } int cnt = 1; while (cnt - 1 < h) { cout << cnt << ' '; cnt++; cout << cnt << '\n'; } if (cnt - 1 < d) { cout << 1 << ' '; cnt++; cout << cnt << '\n'; } while (cnt - 1 < d) { cout << cnt << ' '; cnt++; cout << cnt << '\n'; } while (cnt < n) cout << (d == h) + 1 << ' ' << cnt + 1 << '\n', cnt++; return; } void inp() { cin >> n >> d >> h; return; } int main() { clock_t beg = clock(); { cin.tie(0); ios_base::sync_with_stdio(false); }; inp(); solve(); clock_t end = clock(); fprintf(stderr, "%.3f sec\n", (double)(end - beg) / CLOCKS_PER_SEC); return 0; }
8
CPP
q = int(input()) for _ in range(q): l1,r1,l2,r2 = [int(x) for x in input().split()] if l1 <= l2: print(l1,r2) else: print(r1,l2)
7
PYTHON3
tot_count = 0 for i in range(0, int(input())): prbms = [int(i) for i in input().split()] count = 0 for prb in prbms: if prb == 1: count += 1 if count >= 2: tot_count += 1 print(tot_count)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int n, arr[120]; cin >> n; for (int i = 0; i < n; i++) cin >> arr[i]; int maxi = -1; for (int i = 0; i < n; i++) { int x = arr[i]; maxi = max(maxi, arr[i]); for (int j = i + 1; j < n; j++) { x ^= arr[j]; maxi = max(maxi, x); } } cout << maxi; return 0; }
7
CPP
#include <bits/stdc++.h> using namespace std; long long a; long long b; int main() { ios_base::sync_with_stdio(false); cin >> a >> b; long long res = LLONG_MAX; for (int t = 1; t <= 2; t++) { vector<long long> c; for (long long i = 1; i * i <= b; i++) { if (b % i == 0) c.push_back(i); } int l = 0; int n = (int)c.size(); long long x = a + b; for (long long i = 1; i * i <= x; i++) { if (x % i == 0) { while (l + 1 < n && c[l + 1] <= i) l++; if (b / c[l] <= x / i) { res = min(res, (i + x / i) * 2); } } } swap(a, b); } cout << res << "\n"; }
12
CPP
# 731 A [string], count, ch = map(str, input().split()), 0, 'a' for i in string: count += min(abs(ord(i)-ord(ch)), 26-abs(ord(i)-ord(ch)));ch = i print(count)
7
PYTHON3
n = int(input()) m=list(map(int,input().split())) k=0 s=0 for i in range(n): s+=max(0,k-m[i]) k=max(k,m[i]) print(s)
0
PYTHON3
#include <bits/stdc++.h> using namespace std; const long long INF = 1e6; const int N = 100005; int s, k, v; vector<int> x, y, z; void operate(int id, vector<int>& a, int& tt) { swap(a[id], a[id + 2]); swap(a[id + 1], a[id + 2]); if (tt == id) { tt += 2; return; } if (tt == id + 1) { tt += 1; return; } if (tt == id + 2) { tt -= 2; return; } } int main() { auto make = [](vector<int>& a, int pos) { swap(a[pos + 1], a[pos + 2]); swap(a[pos], a[pos + 1]); }; int t; cin >> t; while (t--) { int n; cin >> n; vector<int> a(n); int sig = 0; vector<pair<int, int>> res(n), secure(n); for (int i = 0; i < n; ++i) { cin >> a[i]; res[i] = {a[i], i}; secure[i] = {a[i], i}; } if (res[0].first == 249) sig = 1; sort(res.begin(), res.end()); for (int i = 0; i < n; ++i) { a[res[i].second] = i; } int cnt = 0; if (sig) for (int i = 0; i < n; ++i) for (int j = i + 1; j < n; ++j) if (a[i] > a[j] && secure[i].first == secure[j].first) cout << "WRONG HERE AT i, secure[i]=" << i << " " << secure[i].first << "\n"; for (int i = 0; i < n; ++i) { for (int j = i + 1; j < n; ++j) { cnt += a[j] < a[i]; } } if (cnt & 1) { for (int i = 0; i < n - 1; ++i) { if (res[i].first == res[i + 1].first) { swap(a[res[i].second], a[res[i + 1].second]); break; } } } vector<int> ans; for (int i = 0; i < n - 2; ++i) { int pos = min_element(a.begin() + i, a.end()) - a.begin(); while (pos > i + 1) { make(a, pos - 2); ans.push_back(pos - 2); pos -= 2; } if (pos != i) { make(a, i); make(a, i); ans.push_back(i); ans.push_back(i); pos = i; } } for (int i = 0; i < 2; ++i) { if (is_sorted(a.begin(), a.end())) { break; } make(a, n - 3); ans.push_back(n - 3); } if (!is_sorted(a.begin(), a.end())) { cout << -1 << endl; } else { cout << ans.size() << endl; for (auto it : ans) cout << it + 1 << " "; cout << endl; } } return 0; }
10
CPP
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 7; int n, a, b; int d[MAXN]; char c; int main() { scanf("%d%d%d", &n, &a, &b); for (int i = 1; i <= n; ++i) { cin >> c; if (c == '1') d[i] = 1; } if (d[a] == d[b]) cout << 0; else cout << 1; return 0; }
7
CPP
# https://codeforces.com/problemset/problem/1304/A # Objective: if not same place -1, else number steps # Status: t = int(input()) for i in range(1, t+1): arr = input() l = list(map(int,arr.split(' '))) if (l[1]-l[0]) % (l[2]+l[3]) != 0: print(-1) else: print(int((l[1]-l[0]) / (l[2]+l[3])))
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int inv; bool query(int x, int y) { cout << x << " " << y << endl; string res; cin >> res; return (res[0] == 'b') ^ inv; } int main() { int n; cin >> n; inv = query(0, 1); if (n == 1) { cout << "1 0 1 1" << endl; return 0; } int ans = 0; for (int k = 1 << (n - 2); k != 0; k /= 2) { int res = query(ans + k, 1); if (res == 0) ans += k; } cout << ans + 1 << " " << 2 << " " << ans << " " << 0 << endl; }
9
CPP
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 10; const int INF = 2e9; int a[N], l[N], r[N]; int main() { int T, n; cin >> T; while (T--) { cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; } for (int i = 1; i <= n; i++) { l[i] = INF; r[i] = -1; } for (int i = 1; i <= n; i++) { l[a[i]] = min(l[a[i]], i); r[a[i]] = max(r[a[i]], i); } vector<pair<int, int> > v; for (int i = 1; i <= n; i++) { if (l[i] > r[i]) continue; v.push_back(pair<int, int>(l[i], r[i])); } int cnt = 0, res = 0; for (int i = 0; i < v.size(); i++) { if (i == 0 || v[i].first < v[i - 1].second) cnt = 1; else cnt++; res = max(res, cnt); } int ans = v.size() - res; cout << ans << "\n"; } return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; int a[100]; int main() { int n, m; scanf("%d%d", &n, &m); int l = 0, r = n - 1; --m; for (int i = 1; i < n; ++i) { int t = n - i - 1; if ((m >> t) & 1) a[r--] = i; else a[l++] = i; } a[r] = n; for (int i = 0; i < n; ++i) printf("%d%c", a[i], i + 1 == n ? '\n' : ' '); }
8
CPP
#include <bits/stdc++.h> using namespace std; long long f(long long n, long long k, long long h, long long d) { long long cnt = 0, siz = 0; while (siz + d <= n) { cnt += d * h; siz += d; d *= k; h++; } return cnt + (n - siz) * h; } long long n, s, k, freq[100005], nodes, curs; void solve() { cin >> n >> s; if (2 * s > n * (n + 1) or s < 2 * n - 1) { cout << "No" << '\n'; return; } if (2 * s == n * (n + 1)) { cout << "Yes" << '\n'; for (long long i = 2; i < n + 1; i++) cout << i - 1 << " "; return; } for (long long i = 1; i < n; i++) { if (f(n, i, 1, 1) <= s) { k = i; break; } } freq[1] = 1; nodes++; curs++; for (long long i = 2; i < n + 1; i++) { if (nodes == n) break; long long lo = 0, hi = min(n - nodes, freq[i - 1] * k); while (hi - lo > 1) { long long mid = (lo + hi) / 2; if (curs + f(n - nodes, k, i, mid) <= s) hi = mid; else lo = mid; } long long l = hi; freq[i] = l; nodes += l; curs += i * l; } cout << "Yes" << '\n'; long long node = 1; for (long long i = 2; i < n + 1; i++) { long long cur = node; for (long long j = 1; j < freq[i] + 1; j++) { cout << cur << " "; if (j % k == 0) cur--; } node += freq[i]; } } signed main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long t = 1; while (t--) { solve(); } return 0; }
9
CPP
import math health = [] power1 = [] power2 = [] test_cases = int(input()) for i in range(test_cases): data_set = list(input().split()) health.append(int(data_set[0])) power1.append(int(data_set[1])) power2.append(int(data_set[2])) for i in range(len(health)): for j in range(power1[i]): if health[i] > 20: health[i] = math.floor(health[i] / 2) + 10 if health[i] <= 20: break for k in range(power2[i]): if health[i] > 0: health[i] -= 10 if health[i] <= 0: break print("YES" if health[i] <= 0 else "NO")
8
PYTHON3
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:32000000") using namespace std; inline bool read(int& val) { return scanf("%d", &val) != -1; } inline bool read(long long& val) { return scanf("%I64d", &val) != -1; } inline bool read(double& val) { return scanf("%lf", &val) != -1; } inline bool read(char* val) { return scanf("%s", val) != -1; } template <class T1, class T2> inline bool read(T1& a, T2& b) { return read(a) && read(b); } template <class T1, class T2, class T3> inline bool read(T1& a, T2& b, T3& c) { return read(a) && read(b) && read(c); } template <class T1, class T2, class T3, class T4> inline bool read(T1& a, T2& b, T3& c, T4& d) { return read(a) && read(b) && read(c) && read(d); } template <class T1, class T2, class T3, class T4, class T5> inline bool read(T1& a, T2& b, T3& c, T4& d, T5& e) { return read(a) && read(b) && read(c) && read(d) && read(e); } const int N = 1111111; const long long mod = 1000000007; int A[N]; int cnt[N]; bool vis[N]; bitset<N> dp; int main() { int n, k; read(n, k); for (int i = 1, _ = (n); i <= _; ++i) read(A[i]); int odd = 0; for (int i = 1, _ = (n); i <= _; ++i) { int len = 0; for (int j = i; !vis[j]; j = A[j]) len += (vis[j] = true); cnt[len]++; odd += len % 2; } for (int i = 1, _ = (n); i <= _; ++i) while (cnt[i] > 2) { cnt[i * ((cnt[i] + 1) / 2)]++; cnt[i] /= 2; } dp[0] = 1; for (int i = 1, _ = (n); i <= _; ++i) for (int j = 0, _ = (cnt[i]); j < _; ++j) dp |= dp << i; cout << (dp[k] ? k : k + 1) << ' '; if (k * 2 <= n - odd) cout << k * 2 << endl; else cout << min(n, k + (n - odd) / 2) << endl; return 0; }
12
CPP
#include <bits/stdc++.h> using namespace std; int ar[55], DP[55][2005]; int N, S, K; int main() { cin >> N >> S >> K; for (int i = 0; i < N; i++) cin >> ar[i]; string str; cin >> str; int ans = 2000000009; for (int i = 0; i < 55; i++) { for (int j = 0; j < 2005; j++) { DP[i][j] = 2000000009; } } for (int i = 0; i < N; i++) DP[i][ar[i]] = abs(S - 1 - i); for (int j = 0; j < 2005; j++) { for (int i = 0; i < N; i++) { for (int k = 0; k < N; k++) { if (ar[k] > ar[i] && str[k] != str[i]) { DP[k][j + ar[k]] = min(DP[k][j + ar[k]], DP[i][j] + abs(k - i)); } } } } for (int i = 0; i < 55; i++) for (int j = K; j < 2005; j++) ans = min(ans, DP[i][j]); cout << (ans == 2000000009 ? -1 : ans) << endl; return (0); }
9
CPP
#include <bits/stdc++.h> using namespace std; inline long long read() { long long x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } long long T, n, a[3000], x, y; bool flag; void doit(int x) { for (int i = 1; i <= x / 2; i++) swap(a[i], a[x - i + 1]); } int main() { T = read(); while (T--) { n = read(); flag = true; for (int i = 1; i <= n; i++) { a[i] = read(); if (a[i] % 2 != i % 2) flag = false; } if (!flag) { cout << -1 << endl; continue; } cout << (n - 1) * 5 / 2 << endl; for (int i = n / 2; i >= 1; i--) { for (int j = 1; j <= n; j++) { if (a[j] == i * 2 + 1) { x = j; break; } } for (int j = 1; j <= n; j++) { if (a[j] == i * 2) { y = j; break; } } cout << x << " "; doit(x); if (y < x) y = x - y + 1; cout << y - 1 << " "; doit(y - 1); cout << y + 1 << " "; doit(y + 1); cout << 3 << " "; doit(3); cout << i * 2 + 1 << " "; doit(i * 2 + 1); } cout << endl; } return 0; }
9
CPP
#include <bits/stdc++.h> using namespace std; int A[200016], n, p, f; int tp[9]; int ni(int x) { int res = 0; for (int i = 8; i > 0; --i) if (x / tp[i]) printf("%d+", (x / tp[i]) % 10), res += (x / tp[i]) % 10; printf("%d\n", x % 10), res += x % 10; return res; } int main() { tp[0] = 1; for (int i = 1; i < 9; ++i) tp[i] = tp[i - 1] * 10; cin >> n; for (int i = 1; i <= n; ++i) scanf("%1d", &A[i]), f += A[i]; if (f < 289) { for (int i = 1; i < n; ++i) printf("%d+", A[i]); printf("%d\n", A[n]); if (f == 199) puts("1+99"), puts("1+00"); else ni(ni(f)); } else { int X = 0, Y = 0, Z = 0, mx; for (int i = 1; i <= n; i += 3) if (i + 2 <= n) X += A[i] * 100 + A[i + 1] * 10 + A[i + 2]; else { for (int t = n; t >= i; --t) X += A[t]; i = n; } for (int i = 2; i <= n; i += 3) if (i + 2 <= n) Y += A[i] * 100 + A[i + 1] * 10 + A[i + 2]; else { for (int t = n; t >= i; --t) Y += A[t]; i = n; } for (int i = 3; i <= n; i += 3) if (i + 2 <= n) Z += A[i] * 100 + A[i + 1] * 10 + A[i + 2]; else { for (int t = n; t >= i; --t) Z += A[t]; i = n; } mx = max(X, max(Y, Z)); if (X == mx) { int tmp = f, tt = (int)log10(f) + 1, i; for (i = 1; i <= n; i += 3) if ((tmp + A[i] * 99 + A[i + 1] * 9) / tp[tt]) break; else { printf("%d%d%d+", A[i], A[i + 1], A[i + 2]), tmp += A[i] * 99 + A[i + 1] * 9; } for (; i <= n; i += 3) if ((tmp + A[i] * 9) / tp[tt]) break; else { printf("%d%d+%d+", A[i], A[i + 1], A[i + 2]), tmp += A[i] * 9; } printf("%d%d+", A[i], A[i + 1]); tmp += A[i] * 9; for (int j = i + 2; j < n; ++j) printf("%d+", A[j]); printf("%d\n", A[n]); ni(ni(tmp)); } else if (Y == mx) { int tmp = f, tt = (int)log10(f) + 1, i; printf("%d+", A[1]); for (i = 2; i <= n; i += 3) if ((tmp + A[i] * 99 + A[i + 1] * 9) / tp[tt]) break; else tmp += A[i] * 99 + A[i + 1] * 9, printf("%d%d%d+", A[i], A[i + 1], A[i + 2]); for (; i <= n; i += 3) if ((tmp + A[i] * 9) / tp[tt]) break; else tmp += A[i] * 9, printf("%d%d+%d+", A[i], A[i + 1], A[i + 2]); tmp += A[i] * 9; printf("%d%d+", A[i], A[i + 1]); for (int j = i + 2; j < n; ++j) printf("%d+", A[j]); printf("%d\n", A[n]); ni(ni(tmp)); } else if (Z == mx) { int tmp = f, tt = (int)log10(f) + 1, i; printf("%d+%d+", A[1], A[2]); for (i = 3; i <= n; i += 3) if ((tmp + A[i] * 99 + A[i + 1] * 9) / tp[tt]) break; else tmp += A[i] * 99 + A[i + 1] * 9, printf("%d%d%d+", A[i], A[i + 1], A[i + 2]); for (; i <= n; i += 3) if ((tmp + A[i] * 9) / tp[tt]) break; else tmp += A[i] * 9, printf("%d%d+%d+", A[i], A[i + 1], A[i + 2]); tmp += A[i] * 9; printf("%d%d+", A[i], A[i + 1]); for (int j = i + 2; j < n; ++j) printf("%d+", A[j]); printf("%d\n", A[n]); ni(ni(tmp)); } } }
7
CPP
#(38)ICP得点集計ソフトウェア while True: n=int(input()) if n==0: break s=[int(input()) for i in range(n)] a=max(s) b=min(s) c=sum(s) y=(c-a-b)//(n-2) print(y)
0
PYTHON3
#include <bits/stdc++.h> using namespace std; vector<int> fact[110]; void start() { for (int i = 2; i <= 100; ++i) { for (int j = i; j <= 100; j += i) fact[j].push_back(i); } } void print() { for (int i = 1; i <= 10; ++i) { for (auto it : fact[i]) { cout << it << " "; } cout << '\n'; } } int main() { int n; cin >> n; vector<int> a(n); int sum = 0; for (int i = 0; i < n; ++i) { cin >> a[i]; sum += a[i]; } sort(a.begin(), a.end()); set<int> ns; int prevs = sum; for (int x = 2; x <= 100; ++x) { int tmp = sum; for (int i = 0; i < n; ++i) { if (a[i] % x == 0) { ns.insert(sum - a[0] - a[i] + a[0] * x + a[i] / x); } } } ns.insert(sum); cout << *ns.begin() << '\n'; }
8
CPP
n,k = map(int,input().split()) print((n-1+(k-2))//(k-1))
0
PYTHON3
h, m, s, t1, t2 = list(map(int, input().split())) h %= 12 t1 %= 12 t2 %= 12 t1, t2 = sorted([t1, t2]) m += s/60 h += m/60 s = s/60*12 m = m /60*12 if (t1 < s < t2 and t1 < m < t2 and t1 < h < t2) or (not(t1 < s < t2) and not(t1 < m < t2) and not(t1 < h < t2)): print('YES') else: print('NO')
8
PYTHON3
import sys sys.setrecursionlimit(10 ** 7) input = sys.stdin.readline from bisect import bisect_left N = int(input()) XD = [[int(i) for i in input().split()] for _ in range(N)] XD.sort() MOD = 998244353 def make(): edge = [[] for _ in range(N)] parent = [-1] * N MAXIDX = N sorted_X = [X for X,_ in XD] for i in range(N-1, -1, -1): idx = bisect_left(sorted_X, XD[i][0] + XD[i][1]) for j in range(i+1, min(idx, MAXIDX)): if parent[j] < 0: parent[j] = i if idx >= MAXIDX: MAXIDX = i + 1 for i,par in enumerate(parent): if par < 0: continue edge[par].append(i) return parent, edge parent, edge = make() def cnt(node): if not edge[node]: return 2 res = 1 for v in edge[node]: res = (res * cnt(v)) % MOD res += 1 return res % MOD def main(): ans = 1 for i,par in enumerate(parent): if par < 0: ans = (ans * cnt(i)) % MOD print(ans) if __name__ == "__main__": main()
0
PYTHON3
#include <iostream> #include <string> #include <algorithm> using namespace std; const int size = 3; bool check ( char hyo[size][size], char mark ) { for (int y = 0; y < size; ++y) for (int x = 0; x < size; ++x) { if (x+2 < size && hyo[y][x] == mark && hyo[y][x+1] == mark && hyo[y][x+2] == mark) { return true; } if (y+2 < size && hyo[y][x] == mark && hyo[y+1][x] == mark && hyo[y+2][x] == mark) { return true; } if (x+2 < size && y+2 < size && hyo[y][x] == mark && hyo[y+1][x+1] == mark && hyo[y+2][x+2] == mark) { return true; } if (x-2 >= 0 && y+2 < size && hyo[y][x] == mark && hyo[y+1][x-1] == mark && hyo[y+2][x-2] == mark) { return true; } } return false; } int main ( void ) { string str; while (cin >> str) { char hyo[size][size]; for (int y = 0; y < size; ++y) for (int x = 0; x < size; ++x) hyo[y][x] = str[y*size + x]; char judge = 'd'; char mark[] = { 'o', 'x' }; for (int i = 0; i < 2; ++i) { if (check(hyo, mark[i])) { judge = mark[i]; } } cout << judge << endl; } return 0; }
0
CPP
from collections import Counter print(len([1 for i in Counter([int(input()) for i in range(int(input()))]).values() if i%2!=0]))
0
PYTHON3
n = int(input()) L = [] for j in range(n): T = [int(x) for x in input().split()] for i in T: if i == 3 or i == 1: break else: L.append(j) print(len(L)) for i in L: print(i+1, end = ' ')
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int o[1002][1002], v[1002][1002], tmp[1002][1002]; int acc[1002][1002]; int op[1002], cl[1002], rw[1002]; int ans[1002]; int n, m, q; void rotate() { for (int j = 1; j <= m; ++j) for (int i = n; i >= 1; --i) tmp[j][n + 1 - i] = o[i][j]; for (int i = 0; i < q; ++i) { int pr = rw[i], pc = cl[i]; rw[i] = pc; cl[i] = n + 1 - pr; } swap(n, m); memcpy(o, tmp, sizeof tmp); } void solve() { for (int i = 1; i <= n; ++i) for (int j = 1; j <= m; ++j) acc[i][j] = v[i][j] + acc[i][j - 1]; for (int i = 0; i < q; ++i) { int qr = rw[i], qc = cl[i]; if (op[i] == 1) { v[qr][qc] ^= 1; for (int j = 1; j <= m; ++j) acc[qr][j] = v[qr][j] + acc[qr][j - 1]; } else { if (v[qr][qc] == 0) { int lo = qc, hi = qc; while (lo - 1 >= 1 && v[qr][lo - 1] == 0) --lo; while (hi + 1 <= m && v[qr][hi + 1] == 0) ++hi; for (int j = qr; j <= n && v[j][qc] == 0; ++j) { while (acc[j][qc] - acc[j][lo - 1]) ++lo; while (acc[j][hi] - acc[j][qc - 1]) --hi; ans[i] = max(ans[i], (hi - lo + 1) * (j - qr + 1)); } } } } } int main() { scanf("%d%d%d", &n, &m, &q); for (int i = 1; i <= n; ++i) for (int j = 1; j <= m; ++j) scanf("%d", o[i] + j), o[i][j] ^= 1; for (int i = 0; i < q; ++i) scanf("%d%d%d", op + i, rw + i, cl + i); for (int i = 0; i < 4; ++i) { memcpy(v, o, sizeof o); solve(); rotate(); } for (int i = 0; i < q; ++i) if (op[i] == 2) printf("%d\n", ans[i]); return 0; }
8
CPP
a=int(input()) list1=list(map(int,input().split())) b=int(input()) list2=list(map(int,input().split())) list3=[(i+1,list2[i]) for i in range(b)] list3.sort(key=lambda x:x[1]) dic1={} output=[] for i in range(a): dic1[i+1]=(dic1[i][1]+1,dic1[i][1]+list1[i])if i!=0 else (1,list1[0]) count=0 j=1 while 1: flag=1 if list3[count][1] <=dic1[j][1] and list3[count][1] >=dic1[j][0]: output.append((list3[count][0],j)) count+=1 else: j+=1 if count+1>b: break output.sort(key=lambda x:x[0]) for i in range(0,b): print(output[i][1])
8
PYTHON3
# # # author : samars_diary # # 15-09-2020 │ 11:04:55 # # # import sys, os.path #if(os.path.exists('input.txt')): #sys.stdin = open('input.txt',"r") #sys.stdout = open('output.txt',"w") sys.setrecursionlimit(10 ** 5) def mod(): return 10**9+7 def i(): return sys.stdin.readline().strip() def ii(): return int(sys.stdin.readline()) def li(): return list(sys.stdin.readline().strip()) def mii(): return map(int, sys.stdin.readline().split()) def lii(): return list(map(int, sys.stdin.readline().strip().split())) #print=sys.stdout.write def solve(): a,b=mii() if min(a,b)%2==0: print('Malvika') else: print('Akshat') for _ in range(1): solve()
7
PYTHON3
#include <bits/stdc++.h> int kx[8] = {+2, +2, -2, -2, +1, +1, -1, -1}; int ky[8] = {+1, -1, +1, -1, +2, -2, +2, -2}; int d9x[9] = {+1, +1, +1, +0, +0, +0, -1, -1, -1}; int d9y[9] = {+1, +0, -1, +1, +0, -1, +1, +0, -1}; int dx4[4] = {+0, +0, +1, -1}; int dy4[4] = {+1, -1, +0, +0}; long long int gcd(unsigned long long int a, unsigned long long int b) { return (a == 0) ? b : gcd(b % a, a); } long long int lcm(unsigned long long int a, unsigned long long int b) { return a * (b / gcd(a, b)); } const long long INF = 1e18; const long long ALPH_SIZE = 256; using namespace std; inline void modulo(long long int& x) { if (x >= 1000000007) { x %= 1000000007; } return; } int n, m, k, l; bool to_head; bool path[201]; int conpos[201]; void fill_conpos() { int pos = k; int t = 0; while (t <= l) { if (pos == n - 1) { to_head = true; } else if (pos == 0) { to_head = false; } conpos[t] = pos; ++t; if (to_head) { --pos; } else { ++pos; } } return; } long long int dp[51 + 1][201]; long long int best[201]; int main() { cin >> n >> m >> k; --m; --k; string tmp; cin >> tmp >> tmp; to_head = (tmp == "head"); cin >> tmp; l = tmp.size(); for (int i = 0; i < l; ++i) { path[i] = (tmp[i] == '1'); } fill_conpos(); for (int t = l - 1; ~t; --t) { for (int p = 0; p < n; ++p) { if (conpos[t] == p) { dp[p][t] = t; best[t] = max(best[t], dp[p][t]); continue; } if (t == l - 1) { dp[p][t] = INF; best[t] = max(best[t], dp[p][t]); continue; } if (path[t]) { dp[p][t] = best[t + 1]; } else { long long int a; if (p > 0) { if (conpos[t] == p - 1) { a = t; } else { a = dp[p - 1][t + 1]; } } else { a = 0; } long long int b; if (p < n - 1) { if (conpos[t] == p + 1) { b = t; } else { b = dp[p + 1][t + 1]; } } else { b = 0; } long long int c; c = dp[p][t + 1]; dp[p][t] = max(a, max(b, c)); } best[t] = max(best[t], dp[p][t]); } } if (dp[m][0] == INF) { cout << "Stowaway\n"; } else { cout << "Controller " << dp[m][0] << endl; } }
8
CPP
#include <bits/stdc++.h> using namespace std; const long long Inf = 4e18; const long long K = 62; void add_self(long long& x, long long y) { x = min(x + y, Inf); } long long mul(long long x, long long y) { if (!x || !y) return 0; if (Inf / x < y) return Inf; return x * y; } vector<vector<long long> > Zero(long long n, long long m) { return vector<vector<long long> >(n, vector<long long>(m, 0)); } vector<vector<long long> > Ident(long long n) { vector<vector<long long> > Res = Zero(n, n); for (long long i = 0; i < n; i++) Res[i][i] = 1; return Res; } vector<vector<long long> > Multy(const vector<vector<long long> >& A, const vector<vector<long long> >& B) { assert(A[0].size() == B.size()); vector<vector<long long> > Res = Zero(A.size(), B[0].size()); for (long long i = 0; i < Res.size(); i++) for (long long j = 0; j < Res[0].size(); j++) for (long long k = 0; k < A[0].size(); k++) add_self(Res[i][j], mul(A[i][k], B[k][j])); return Res; } vector<vector<long long> > Power(const vector<vector<long long> >& A, long long k) { if (!k) return Ident(A.size()); if (k & 1) return Multy(A, Power(A, k - 1)); return Power(Multy(A, A), k >> 1); } const long long N = 200200; long long a[N]; int main() { long long n, k; cin >> n >> k; for (long long i = 0; i < n; i++) scanf("%I64d", a + i); reverse(a, a + n); while (!a[n - 1]) n--; reverse(a, a + n); for (long long i = 0; i < n; i++) if (a[i] >= k) return cout << "0", 0; if (n > 3) { for (long long rep = 0;; rep++) { for (long long i = 0; i < n; i++) if (a[i] >= k) return cout << rep, 0; for (long long i = 1; i < n; i++) add_self(a[i], a[i - 1]); } } vector<vector<long long> > Base = Zero(1, n); vector<vector<long long> > Trans[K]; for (long long i = 0; i < n; i++) Base[0][i] = a[i]; Trans[0] = Zero(n, n); for (long long i = 0; i < n; i++) for (long long j = i; j < n; j++) Trans[0][i][j] = 1; for (long long r = 1; r < K; ++r) Trans[r] = Multy(Trans[r - 1], Trans[r - 1]); long long Ans = 0; for (long long jump = K - 1; ~jump; jump--) { vector<vector<long long> > Cur = Multy(Base, Trans[jump]); bool ok = false; for (long long i = 0; i < n; i++) if (Cur[0][i] >= k) { ok = true; break; } if (ok) continue; Ans += 1LL << jump; Base = Cur; } cout << Ans + 1; }
12
CPP
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int lst = -1; int n = s.size(); for (char c = 'z'; c >= 'a'; c--) { for (int i = lst + 1; i < n; i++) { if (s[i] == c) { cout << c; lst = i; } } } return 0; }
9
CPP
for _ in range(int(input())) : v, c, t1, t2 = map(int, input().split()) if (v+c) >= (t1+t2) : if min(v, c) >= t2 : print('Yes') else : print('No') else : print('No')
9
PYTHON3
#include <bits/stdc++.h> using namespace std; const int Maxn = 100005, Maxk = 205, p = 1e9 + 7; int n, k, cnt, siz[Maxn], head[Maxn]; long long result, tmp[Maxk], ans[Maxk], S[Maxk][Maxk], f[Maxn][Maxk]; struct edg { int nxt, to; } edge[2 * Maxn]; void add(int x, int y) { edge[++cnt] = (edg){head[x], y}; head[x] = cnt; } void dfs(int u, int fa) { siz[u] = 1; f[u][0] = 2; for (int i = head[u]; i; i = edge[i].nxt) { int to = edge[i].to; if (to != fa) { dfs(to, u); memset(tmp, 0, sizeof(long long[k + 1])); for (int a = 0; a <= k && a <= siz[u]; a++) for (int b = 0; a + b <= k && b <= siz[to]; b++) (tmp[a + b] += f[u][a] * f[to][b]) %= p; for (int a = 0; a <= k; a++) f[u][a] = tmp[a], (ans[a] += p - f[to][a]) %= p; siz[u] += siz[to]; } } for (int i = 0; i <= k; i++) (ans[i] += f[u][i]) %= p; for (int i = k; i >= 1; i--) (f[u][i] += f[u][i - 1]) %= p; f[u][1]--; } int main() { scanf("%d%d", &n, &k); S[0][0] = 1; for (int i = 1; i <= k; i++) for (int j = 1; j <= k; j++) S[i][j] = (j * S[i - 1][j] + S[i - 1][j - 1]) % p; for (int i = 1; i < n; i++) { int x, y; scanf("%d%d", &x, &y); add(x, y), add(y, x); } dfs(1, 0); long long now = 1; for (int i = 0; i <= k; i++) (result += S[k][i] * now % p * ans[i]) %= p, (now *= i + 1) %= p; printf("%lld", result); return 0; }
13
CPP
#include <bits/stdc++.h> using namespace std; const int maxn = 20; const long long mod = 1000000000 + 7; long long n, c, f[10]; struct matrix { long long a[maxn][maxn], n; matrix(long long f, long long size) { n = size; memset(a, 0, sizeof(a)); if (f == 0) return; for (int i = 1; i <= n; i++) a[i][i] = 1; } matrix operator*(const matrix &fun) const { matrix ans(0, n); for (int i = 1; i <= 5; i++) { for (int k = 1; k <= 5; k++) { if (a[i][k]) for (int j = 1; j <= 5; j++) ans.a[i][j] = (ans.a[i][j] + a[i][k] * fun.a[k][j] % (mod - 1)) % (mod - 1); } } return ans; } matrix qpow(long long x) const { matrix ans(1, n); matrix tmp = (*this); while (x) { if (x & 1) ans = ans * tmp; tmp = tmp * tmp; x >>= 1; } return ans; } }; long long quick_pow(long long a, long long n) { long long ans = 1; while (n) { if (n & 1) ans = (ans * a) % (mod); a = (a * a) % (mod); n >>= 1; } return ans; } int main() { scanf("%lld %lld %lld %lld %lld", &n, &f[1], &f[2], &f[3], &c); matrix x(0, 5), y(0, 5), z(0, 5), w(0, 5); int a_x[] = {0, 0, 0, 1, 0, 0}; int a_y[] = {0, 0, 1, 0, 0, 0}; int a_z[] = {0, 1, 0, 0, 0, 0}; int a_w[] = {0, 0, 0, 0, 0, 2}; x.a[1][1] = y.a[1][1] = z.a[1][1] = 1; x.a[1][2] = y.a[1][2] = z.a[1][2] = 1; x.a[1][3] = y.a[1][3] = z.a[1][3] = 1; x.a[2][1] = y.a[2][1] = z.a[2][1] = 1; x.a[3][2] = y.a[3][2] = z.a[3][2] = 1; w.a[1][1] = w.a[1][2] = w.a[1][3] = w.a[1][4] = w.a[1][5] = 1; w.a[2][1] = w.a[3][2] = 1; w.a[4][4] = w.a[4][5] = w.a[5][5] = 1; matrix tmp_x = x.qpow(n - 3); matrix tmp_y = y.qpow(n - 3); matrix tmp_z = z.qpow(n - 3); matrix tmp_w = w.qpow(n - 3); long long mul_x = 0, mul_y = 0, mul_z = 0, mul_w = 0; for (int i = 1; i <= 5; i++) { mul_x = (mul_x + a_x[i] * tmp_x.a[1][i] % (mod - 1)) % (mod - 1); mul_y = (mul_y + a_y[i] * tmp_y.a[1][i] % (mod - 1)) % (mod - 1); mul_z = (mul_z + a_z[i] * tmp_z.a[1][i] % (mod - 1)) % (mod - 1); mul_w = (mul_w + a_w[i] * tmp_w.a[1][i] % (mod - 1)) % (mod - 1); } long long ans = ((quick_pow(f[1], mul_x) * quick_pow(f[2], mul_y) % (mod)) * (quick_pow(f[3], mul_z) * quick_pow(c, mul_w) % (mod))) % (mod); printf("%lld\n", ans); return 0; }
11
CPP
#include <bits/stdc++.h> using namespace std; const int md = 1000000007; void Add(int &x, int y) { x += y; if (x >= md) x -= md; } int Fac[100005], Inv[100005]; int n, K; int Fast(int x, int k) { int res = 1; while (k) { if (k & 1) res = 1ll * res * x % md; k >>= 1; x = 1ll * x * x % md; } return res; } void Init() { Fac[0] = Inv[0] = 1; for (int i = (1), i_END_ = (n); i <= i_END_; ++i) { Fac[i] = 1ll * Fac[i - 1] * i % md; Inv[i] = Fast(Fac[i], md - 2); } } int C(int x, int y) { if (x < y) return 0; return 1ll * Fac[x] * Inv[x - y] % md * Inv[y] % md; } int dp[100005]; char str[100005]; int main() { scanf("%d%d", &n, &K); scanf("%s", str + 1); if (!K) { int res = 0; for (int i = (1), i_END_ = (n); i <= i_END_; ++i) res = (1ll * res * 10 % md + str[i] - '0') % md; printf("%d\n", res); return 0; } Init(); int base = 1; for (int i = (1), i_END_ = (n); i <= i_END_; ++i) { dp[i] = 1ll * base * C(n - 1 - i, K - 1) % md; Add(dp[i], dp[i - 1]); base = 1ll * base * 10 % md; } int ans = 0; base = 1; for (int i = (n), i_END_ = (1); i >= i_END_; --i) { int k = str[i] - '0'; Add(ans, 1ll * k * dp[n - i] % md); Add(ans, 1ll * k * base % md * C(i - 1, K) % md); base = 1ll * base * 10 % md; } printf("%d\n", ans); return 0; }
9
CPP
n = int(input()) for i in range(0, n): str1 = input() condition1 = False condition2 = False start = 0 end = 0 col = 0 for j in range(0, len(str1)-1): sub = str1[j+1] if str1[j] == "R" and ord(sub)>=48 and ord(sub)<=57: condition1 = True start = j+1 if str1[j] == "C" and ord(sub)>=48 and ord(sub)<=57: condition2 = True end = j if condition1 == True and condition2 == True: for j in range(0, len(str1)): if str1[j] == "C": col = int(str1[j+1:]) break ans = [] while col > 0: digit = col % 26 col = col // 26 if digit == 0: digit = 26 col -= 1 digit = int(digit) ans.append(chr(64+digit)) for j in range(1, len(ans)+1): print(ans[len(ans)-j], end="") print(str1[start:end]) else: convert = [] start = 0 for j in range(0, len(str1)): if ord(str1[j]) > 57: convert.append(int(ord(str1[j]) - 64)) else: start = j break value = 0 for k in range(0, len(convert)): value = (value * 26) + convert[k] req = str1[start:] print("R" + str(req) + "C" + str(value))
8
PYTHON3
mod = 1000000007 s = input() n = len(s) ans = 1 fib = [0] * 100001 fib[2] = 2 fib[3] = 3 for i in range(4, 100001): fib[i] = (fib[i-1] % mod + fib[i-2] % mod) % mod i = 0 mm = s.count('m') ww = s.count('w') while i < n: j = i+1 c = s[i] count = 1 if c == 'n' or c == 'u': while j < n and s[j] == s[j-1]: count += 1 j += 1 if count > 1: ans = (ans % mod * fib[count] % mod) % mod i = j if mm > 0 or ww > 0: print(0) else: print(ans)
9
PYTHON3
#include <bits/stdc++.h> using namespace std; vector<int> out[250]; int done[250][250]; void construct(int k) { int q = 1; for (; q <= k * (k - 1) / 2; q++) { bool c = 0; for (int i = 0; i < k && !c; i++) { if (out[i].size() < k - 1) { out[i].push_back(q); for (int j = 0; j < (k); j++) if (!done[i][j] && i != j) { done[i][j] = done[j][i] = 1; out[j].push_back(q); c = 1; break; } } } } } int f(long long k) { return k * (k - 1) / 2; } int main() { int n; scanf("%d", &n); int s = 3, e = n; while (s < e) { int m = s + (e - s + 1) / 2; if (f(m) <= n) s = m; else e = m - 1; } printf("%d\n", s); construct(s); for (int i = 0; i < (s); i++) { for (int j = 0; j < (s - 1); j++) printf("%d%s", out[i][j], (j == s - 2) ? "\n" : " "); } return 0; }
9
CPP
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:128000000") using namespace std; char s[10000000] = {0}; int main() { int t, i, r1, j, v, n, l, m, to, len, p, r, k, x, y, z, fl; fl = 0; while (cin.getline(s, 10000000)) { k = 0; n = strlen(s); for (i = 0; i < n; i++) if (s[i] != ' ') { if (s[i] == '#') k = 1; break; } if (k) { if (fl) printf("\n"); printf("%s\n", s); fl = 0; continue; } for (i = 0; i < n; i++) if (s[i] != ' ') printf("%c", s[i]); fl = 1; } if (fl) printf("\n"); return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; inline long long read() { char ch = getchar(); long long f = 1; while (ch < '0' || ch > '9') { if (ch == '-') f = -f; ch = getchar(); } long long x = 0; while (ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + ch - '0', ch = getchar(); return x * f; } const int MAXN = 1e5 + 10; string f[MAXN] = { "0\n.\n", "0\n..\n", "0\n...\n", "0\n....\n", "0\n.....\n", "0\n......\n", "0\n.......\n", "0\n........\n", "0\n.........\n", "0\n.\n.\n", "0\n..\n..\n", "0\n...\n...\n", "0\n....\n....\n", "0\n.....\n.....\n", "0\n......\n......\n", "0\n.......\n.......\n", "0\n........\n........\n", "0\n.........\n.........\n", "0\n.\n.\n.\n", "0\n..\n..\n..\n", "1\nAAA\n.A.\n.A.\n", "1\nAAA.\n.A..\n.A..\n", "2\nAAA.B\n.ABBB\n.A..B\n", "2\nAAABBB\n.A..B.\n.A..B.\n", "3\nAAACBBB\n.A.C.B.\n.ACCCB.\n", "3\nAAABBB.C\n.A..BCCC\n.A..B..C\n", "4\nAAADBBB.C\n.A.D.BCCC\n.ADDDB..C\n", "0\n.\n.\n.\n.\n", "0\n..\n..\n..\n..\n", "1\nAAA\n.A.\n.A.\n...\n", "2\nAAA.\n.AB.\n.AB.\n.BBB\n", "2\nAAA..\n.ABBB\n.A.B.\n...B.\n", "3\nAAABBB\n.AC.B.\n.AC.B.\n.CCC..\n", "4\nAAABBB.\n.AC.BD.\n.AC.BD.\n.CCCDDD\n", "4\nAAABBB..\n.AD.BCCC\n.AD.B.C.\n.DDD..C.\n", "5\nAAABBBCCC\n.AD.BE.C.\n.AD.BE.C.\n.DDDEEE..\n", "0\n.\n.\n.\n.\n.\n", "0\n..\n..\n..\n..\n..\n", "2\nAAA\n.A.\nBA.\nBBB\nB..\n", "2\nAAA.\n.A..\nBA..\nBBB.\nB...\n", "4\nAAA.B\n.ABBB\nCA.DB\nCCCD.\nC.DDD\n", "4\nAAABBB\n.A..B.\nCA.DB.\nCCCDDD\nC..D..\n", "5\nAAABBB.\n.A..BD.\nCA.EBD.\nCCCEDDD\nC.EEE..\n", "6\nAAABBB.C\n.A..BCCC\nDA.EB.FC\nDDDEEEF.\nD..E.FFF\n", "7\nAAA.BBB.D\n.ACCCBDDD\nEA.CFB.GD\nEEECFFFG.\nE...F.GGG\n", "0\n.\n.\n.\n.\n.\n.\n", "0\n..\n..\n..\n..\n..\n..\n", "2\nAAA\n.A.\nBA.\nBBB\nB..\n...\n", "3\nAAA.\n.A..\nBA..\nBBBC\nBCCC\n...C\n", "4\nAAA..\n.ABBB\nCA.B.\nCCCBD\nC.DDD\n....D\n", "5\nAAABBB\n.A..B.\n.AC.B.\n.ECCCD\n.ECDDD\nEEE..D\n", "6\nAAA.BBB\n.AC..B.\n.ACCCB.\nE.CFDDD\nEEEF.D.\nE.FFFD.\n", "7\nAAABBB..\n.AD.BCCC\n.AD.B.C.\nEDDDG.CF\nEEE.GFFF\nE..GGG.F\n", "8\nAAABBBCCC\n.AD.B..C.\n.AD.BE.C.\nFDDDHEEEG\nFFF.HEGGG\nF..HHH..G\n", "0\n.\n.\n.\n.\n.\n.\n.\n", "0\n..\n..\n..\n..\n..\n..\n..\n", "3\nAAA\n.A.\nBA.\nBBB\nB.C\nCCC\n..C\n", "4\nAAA.\n.AB.\n.AB.\nCBBB\nCCCD\nCDDD\n...D\n", "5\nAAA..\n.ABBB\nCA.B.\nCCCB.\nCEDDD\n.E.D.\nEEED.\n", "6\nAAABBB\n.A..B.\nCA.DB.\nCCCDDD\nCE.DF.\n.EEEF.\n.E.FFF\n", "8\nAAAC..B\n.A.CBBB\nDACCCEB\nDDDEEE.\nDHFFFEG\n.H.FGGG\nHHHF..G\n", "9\nAAA.BBB.\n.ACCCBE.\n.ADC.BE.\nDDDCFEEE\nG.DIFFFH\nGGGIFHHH\nG.III..H\n", "10\nAAA.BBB..\n.ACCCBDDD\n.AECFB.D.\nEEECFFFDG\nH.EJFIGGG\nHHHJ.IIIG\nH." "JJJI...\n", "0\n.\n.\n.\n.\n.\n.\n.\n.\n", "0\n..\n..\n..\n..\n..\n..\n..\n..\n", "3\nAAA\n.A.\nBA.\nBBB\nB..\nCCC\n.C.\n.C.\n", "4\nAAA.\n.A..\nBA..\nBBB.\nBCCC\n.DC.\n.DC.\nDDD.\n", "6\nAAA..\n.ABBB\nCA.B.\nCCCBD\nC.DDD\nEEEFD\n.E.F.\n.EFFF\n", "7\nAAABBB\n.A..B.\nCA.DB.\nCCCDDD\nC.ED..\n.GEEEF\n.GEFFF\nGGG..F\n", "9\nAAA.BBB\n.ACCCB.\nDA.CEB.\nDDDCEEE\nDFFFE.G\n.IFHGGG\n.IFHHHG\nIIIH..." "\n", "10\nAAABBB.C\n.A..BCCC\nDA.EB.FC\nDDDEEEF.\nD..EHFFF\nGGGJHHHI\n.G." "JHIII\n.GJJJ..I\n", "12\nAAA.BBB.D\n.ACCCBDDD\nEA.CFB.GD\nEEECFFFG.\nE.." "HFIGGG\nJHHHLIIIK\nJJJHLIKKK\nJ..LLL..K\n", "0\n.\n.\n.\n.\n.\n.\n.\n.\n.\n", "0\n..\n..\n..\n..\n..\n..\n..\n..\n..\n", "4\nAAA\n.A.\nBA.\nBBB\nB.C\nCCC\nD.C\nDDD\nD..\n", "5\nAAA.\n.A..\nBA..\nBBBC\nBCCC\nD..C\nDDDE\nDEEE\n...E\n", "7\nAAA..\n.ABBB\nCA.B.\nCCCBD\nCEDDD\n.EEED\nGEFFF\nGGGF.\nG..F.\n", "8\nAAABBB\n.A..B.\nCA.DB.\nCCCDDD\nC.ED..\nEEEFFF\nG.EHF.\nGGGHF.\nG.HHH." "\n", "10\nAAABBB.\n.A..BD.\nCA.EBD.\nCCCEDDD\nCFEEE.G\n.FFFGGG\nIFHHHJG\nIIIH.J." "\nI..HJJJ\n", "12\nAAAC.BBB\n.ADCCCB.\n.ADCE.B.\nFDDDEEEG\nFFFHEGGG\nFHHHIIIG\nJJJHKIL." "\n.JKKKIL.\n.J..KLLL\n", "13\nAAABBB..C\n.A..BDCCC\nEA.GBDDDC\nEEEG.DFFF\nEHGGG.IF.\n.HHHIIIF." "\nKHJJJMI.L\nKKKJ.MLLL\nK..JMMM.L\n"}; int main() { long long n = read(), m = read(), ans = (n - 1) * 9 + (m - 1); cout << f[ans]; return 0; }
9
CPP
#include <bits/stdc++.h> using namespace std; int main() { int h,n,sum=0,t; cin>>h>>n; for(int i=0;i<n;++i) { cin>>t; sum+=t; } if(sum>=h) cout<<"Yes\n"; else cout<<"No\n"; return 0; }
0
CPP
a, b = map(int, input().split()) for i in range(1, 11): if i * a % 10 in [0, b]: print(i) break
7
PYTHON3
#Pye from sys import stdin, stdout from os import path if path.exists('inp.txt'): stdin = open("inp.txt", "r") s = [None for i in range(105)] q = []; p = []; r = [] n, m = map(int, stdin.readline().split()) for i in range(n): k = stdin.readline().split() s[i] = k[0] for i in range(n): if s[i] != None: t = s[i][::-1] for id in range(n): if id != i and t == s[id]: q.append(s[i]) r.append(t) s[i] = s[id] = None break if s[i] == t: p.append(s[i]) s[i] = None print(m * len(q) * 2 + m if len(p) > 0 else m * len(q) * 2) for v in q: print(v, end='') if len(p) > 0: print(p[0], end='') r.reverse() for v in r: print(v, end='')
8
PYTHON3
#include<iostream> #include<cstdio> #include<algorithm> #include<cstring> using namespace std; const int N=2e5+10; int cnt[N],f[N],a[N]; int main() { int T;scanf("%d",&T); while(T--) { memset(f,0,sizeof(f)); memset(cnt,0,sizeof(cnt)); int n;scanf("%d",&n);int m=n; for(int i=1;i<=n;i++)scanf("%d",&a[i]),cnt[a[i]]++; sort(a+1,a+n+1);n=unique(a+1,a+n+1)-a-1; for(int i=1;i<=n;i++) { for(int j=1;j*j<=a[i];j++) { if(a[i]%j)continue; f[a[i]]=max(f[a[i]],max(f[j],f[a[i]/j])); } f[a[i]]+=cnt[a[i]]; } int ans=0; for(int i=1;i<=2e5;i++)ans=max(ans,f[i]); printf("%d\n",m-ans); } }
13
CPP
#Code by Sounak, IIESTS #------------------------------warmup---------------------------- import os import sys import math from io import BytesIO, IOBase from fractions import Fraction import collections from itertools import permutations from collections import defaultdict from collections import deque import threading #sys.setrecursionlimit(300000) #threading.stack_size(10**8) BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") #------------------------------------------------------------------------- #mod = 9223372036854775807 class SegmentTree: def __init__(self, data, default=0, func=lambda a, b: a+b): """initialize the segment tree with data""" self._default = default self._func = func self._len = len(data) self._size = _size = 1 << (self._len - 1).bit_length() self.data = [default] * (2 * _size) self.data[_size:_size + self._len] = data for i in reversed(range(_size)): self.data[i] = func(self.data[i + i], self.data[i + i + 1]) def __delitem__(self, idx): self[idx] = self._default def __getitem__(self, idx): return self.data[idx + self._size] def __setitem__(self, idx, value): idx += self._size self.data[idx] = value idx >>= 1 while idx: self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1]) idx >>= 1 def __len__(self): return self._len def query(self, start, stop): if start == stop: return self.__getitem__(start) stop += 1 start += self._size stop += self._size res = self._default while start < stop: if start & 1: res = self._func(res, self.data[start]) start += 1 if stop & 1: stop -= 1 res = self._func(res, self.data[stop]) start >>= 1 stop >>= 1 return res def __repr__(self): return "SegmentTree({0})".format(self.data) class SegmentTree1: def __init__(self, data, default=10**6, func=lambda a, b: min(a,b)): """initialize the segment tree with data""" self._default = default self._func = func self._len = len(data) self._size = _size = 1 << (self._len - 1).bit_length() self.data = [default] * (2 * _size) self.data[_size:_size + self._len] = data for i in reversed(range(_size)): self.data[i] = func(self.data[i + i], self.data[i + i + 1]) def __delitem__(self, idx): self[idx] = self._default def __getitem__(self, idx): return self.data[idx + self._size] def __setitem__(self, idx, value): idx += self._size self.data[idx] = value idx >>= 1 while idx: self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1]) idx >>= 1 def __len__(self): return self._len def query(self, start, stop): if start == stop: return self.__getitem__(start) stop += 1 start += self._size stop += self._size res = self._default while start < stop: if start & 1: res = self._func(res, self.data[start]) start += 1 if stop & 1: stop -= 1 res = self._func(res, self.data[stop]) start >>= 1 stop >>= 1 return res def __repr__(self): return "SegmentTree({0})".format(self.data) MOD=10**9+7 class Factorial: def __init__(self, MOD): self.MOD = MOD self.factorials = [1, 1] self.invModulos = [0, 1] self.invFactorial_ = [1, 1] def calc(self, n): if n <= -1: print("Invalid argument to calculate n!") print("n must be non-negative value. But the argument was " + str(n)) exit() if n < len(self.factorials): return self.factorials[n] nextArr = [0] * (n + 1 - len(self.factorials)) initialI = len(self.factorials) prev = self.factorials[-1] m = self.MOD for i in range(initialI, n + 1): prev = nextArr[i - initialI] = prev * i % m self.factorials += nextArr return self.factorials[n] def inv(self, n): if n <= -1: print("Invalid argument to calculate n^(-1)") print("n must be non-negative value. But the argument was " + str(n)) exit() p = self.MOD pi = n % p if pi < len(self.invModulos): return self.invModulos[pi] nextArr = [0] * (n + 1 - len(self.invModulos)) initialI = len(self.invModulos) for i in range(initialI, min(p, n + 1)): next = -self.invModulos[p % i] * (p // i) % p self.invModulos.append(next) return self.invModulos[pi] def invFactorial(self, n): if n <= -1: print("Invalid argument to calculate (n^(-1))!") print("n must be non-negative value. But the argument was " + str(n)) exit() if n < len(self.invFactorial_): return self.invFactorial_[n] self.inv(n) # To make sure already calculated n^-1 nextArr = [0] * (n + 1 - len(self.invFactorial_)) initialI = len(self.invFactorial_) prev = self.invFactorial_[-1] p = self.MOD for i in range(initialI, n + 1): prev = nextArr[i - initialI] = (prev * self.invModulos[i % p]) % p self.invFactorial_ += nextArr return self.invFactorial_[n] class Combination: def __init__(self, MOD): self.MOD = MOD self.factorial = Factorial(MOD) def ncr(self, n, k): if k < 0 or n < k: return 0 k = min(k, n - k) f = self.factorial return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD mod=10**9+7 omod=998244353 #------------------------------------------------------------------------- prime = [True for i in range(10)] pp=[0]*10 def SieveOfEratosthenes(n=10): p = 2 c=0 while (p * p <= n): if (prime[p] == True): c+=1 for i in range(p, n+1, p): pp[i]+=1 prime[i] = False p += 1 #---------------------------------Binary Search------------------------------------------ def binarySearch(arr, n, key): left = 0 right = n-1 mid = 0 res=arr[n-1] while (left <= right): mid = (right + left)//2 if (arr[mid] >= key): res=arr[mid] right = mid-1 else: left = mid + 1 return res def binarySearch1(arr, n, key): left = 0 right = n-1 mid = 0 res=arr[0] while (left <= right): mid = (right + left)//2 if (arr[mid] > key): right = mid-1 else: res=arr[mid] left = mid + 1 return res #---------------------------------running code------------------------------------------ n=int(input()) a=list(map(int,input().split())) m=min(a) if a.count(m)<=n//2: print("Alice") else: print("Bob")
9
PYTHON3
import sys sys.setrecursionlimit(10 ** 6) int1 = lambda x: int(x) - 1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] # 左の箱(パターンにあたる)と右の箱(対象)が連動して動く # 文字が同じ限り右に広げて、lcpを記録しながら左に縮めていく感じ # 縮められなくなったら、topを右の箱の左端にして、左の箱を0までずらす # 箱ができていない(幅が0)のときは、右の箱を1つ右に def ZAlgorithm(aa): target = aa # s = input() len_t = len(target) lcp = [-1] * len_t top = 1 # 右の箱において、左の箱の0に対応する点 left = 0 # 左の箱の左端(本当はここでので宣言は不要だけど理解の為) right = 0 # 左の箱の右端 lcp[0] = 0 while top < len_t: # 箱を右に広げていく while top + right < len_t and target[right] == target[top + right]: right += 1 # 右の箱左端のlcpを記録 lcp[top] = right left = 1 # 箱の幅が0だったらtopを動かして、このターン終了 if right == 0: top += 1 continue # lcpを記録しながら箱を左に縮めていく(最初の条件重要) while left + lcp[left] < right and left < right: lcp[top + left] = lcp[left] left += 1 # topを右の箱の左端にして、左の箱を0まで戻す top += left right -= left left = 0 # これも本当は不要 return lcp def main(): # 「aを左にシフト」=「bを右にシフト」 # 左にシフトは面倒なのでbを右に動かす # 動かした(下記は2つシフトしたとき)結果 # a0 a1 a2 a3 a4 # xor xor xor xor xor # x x x x x # = = = = = # b3 b4 b0 b1 b2 # と、なっていればよい。ここで、xorをただの足し算に置き換えて考える # a0 a1 a2 a3 a4 # + + + + + # x x x x x # = = = = = # b3 b4 b0 b1 b2 # 具体例で # 4 6 3 7 2 # + + + + + # 1 1 1 1 1 # = = = = = # 5 7 4 8 3 # このとき、aの増減とbの増減は一致する # aの増減・・・末尾から(+2) 4 (+2) 6 (-3) 3 (+4) 7 (-5) 2 # bの増減・・・末尾から(+2) 5 (+2) 7 (-3) 4 (+4) 8 (-5) 3 # これはxorでも同様のことがいえる # よって、a,bそれぞれの隣接xorのリストを作る # aを2つ並べて(ループするから)、bを右にシフトしながら一致する位置を探す # 一致する位置を探すのはZ-Algorithmを使った # シフト量が分かれば、対応する1組のa,bからxも分かる # らしいが、こんなの思いつかんわ!! inf = pow(2, 31) n = II() aa = LI() bb = LI() ax = [aa[i - 1] ^ aa[i] for i in range(n)] bx = [bb[i - 1] ^ bb[i] for i in range(n)] # print(ax) # print(bx) ll = ZAlgorithm(bx + [inf] + ax + ax[:-1]) # lcp・・・length common prefixみたいな? for shift, lcp in enumerate(ll[n + 1:]): if lcp == n: print(shift, aa[shift] ^ bb[0]) main()
0
PYTHON3
y, b, r = list(map(int, input().split())) ye, bl, re = r - 2, r - 1, r while re > r or ye > y or bl > b: re, ye, bl = re - 1, ye - 1, bl - 1 print(re + ye + bl)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { (ios_base::sync_with_stdio(false), cin.tie(NULL)); ; string s; int arr[26]; memset(arr, 0, sizeof(arr)); cin >> s; for (int i{0}; i < s.length(); i++) { arr[s[i] - 'a']++; } bool isPalindrome{true}; if (s.length() & 1) { bool flag{false}; for (int i = 0; i < 26; i++) { if (arr[i] & 1) { if (flag) { isPalindrome = false; break; } flag = true; } } } else { for (int i = 0; i < 26; i++) { if (arr[i] & 1) { isPalindrome = false; break; } } } if (isPalindrome) { cout << "First\n"; } else { if (s.length() & 1) { cout << "First\n"; } else { cout << "Second\n"; } } return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; int main() { long long int n, k, x, sum = 0, ans = 0; cin >> n >> k; long long int arr[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; sum = sum + arr[i]; } for (int i = 0; i < k; i++) { cin >> x; sum = sum - arr[x - 1]; ans = ans + (sum) * (arr[x - 1]); arr[x - 1] = 0; } for (int i = 0; i <= n - 2; i++) { ans = ans + arr[i] * arr[i + 1]; } ans = ans + arr[0] * arr[n - 1]; cout << ans << "\n"; return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; map<int, int> m; int main() { int k, b, n, x, zro; long long sum0 = 0, sum = 0, mod = 0; scanf("%d %d %d", &k, &b, &n); m[0] = 1; for (int i = 1; i <= n; ++i) { scanf("%d", &x); if (x) zro = 0; else { ++zro; sum0 += zro; } mod = (mod + x) % (k - 1); sum += m[(mod - b + k - 1) % (k - 1)]; ++m[mod]; } if (b == 0) printf("%I64d\n", sum0); else if (b == k - 1) printf("%I64d\n", sum - sum0); else printf("%I64d\n", sum); }
11
CPP
#include<iostream> #include<vector> #include<algorithm> #include<climits> using namespace std; const int V_MAX=100000; vector<int> G[V_MAX]; vector<bool> check(V_MAX,false); vector<int> pre(V_MAX,INT_MAX); vector<int> low(V_MAX,INT_MAX); vector<bool> articulation(V_MAX,false); int order; void dfs(int s,int p){ int counter=0; if(check[s]==true){return;} check[s]=true; pre[s]=order; low[s]=order; order++; for (int i=0;i<G[s].size();i++){ if(G[s][i]!=p && pre[G[s][i]]<low[s]){ low[s]=pre[G[s][i]]; } if(check[G[s][i]]==false){ dfs(G[s][i],s); counter++; if(s!=0 && G[s][i]!=p && pre[s]<=low[G[s][i]]){ articulation[s]=true; } } } if(s==0 && counter>1){ articulation[0]=true; } if(low[p]>low[s]){ low[p]=low[s]; } } int main(){ int V,E,s,t; cin>> V >> E; for (int i=0;i<E;i++){ cin >> s >> t; G[s].push_back(t); G[t].push_back(s); } order=0; dfs(0,0); for(int i=0;i<V;i++){ if(articulation[i]==true){ cout << i << endl; } } /* for(int i=0;i<V;i++){ cout << pre[i] << " "; } cout << endl; for(int i=0;i<V;i++){ cout << low[i] << " "; } */ return 0; }
0
CPP
n, h = list(map(int, input().split())) result = 0 heights = list(map(int, input().split())) for i in heights: if i > h: result += 2 else: result += 1 print(result)
7
PYTHON3
str="31 28 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31 31 29 31 30 31 30 31 31 30 31 30 31 " str+=str n=int(input()) s=input() if s in str : print("YES") else: print("NO")
8
PYTHON3
n=int(input()) text=input() mydict={} for i in range(1,n): tg=text[i-1]+text[i] if tg not in mydict: mydict[tg]=1 else: mydict[tg]+=1 keys=list(mydict.keys()) values=list(mydict.values()) print(keys[values.index(max(values))])
8
PYTHON3
MODINT = 10**9 + 7 N, K = map(int, input().split()) ans = 0 q = [0] * (K + 1) for i in range(K, 0, -1): q[i] = pow(K//i, N, MODINT) for j in range(i*2, K+1, i): q[i] -= q[j] ans += (q[i]*i) % MODINT print(ans % MODINT)
0
PYTHON3
#include <bits/stdc++.h> using namespace std; class node { public: node(char v, int p) { val = v, pos = p; } char val; int pos; }; int main(void) { char c; unsigned long long cnt[26] = {0}; int i = 0, j = 0; bool found; list<node> h; int dis = 0; while ((c = getchar()) != '\n') { cnt[0]++; found = false; j = 0; for (list<node>::iterator it = h.begin(); it != h.end(); j++) { list<node>::iterator next = it; next++; if (next == h.end()) dis = it->pos + 1; else dis = it->pos - next->pos; if (found) cnt[j] += dis; else if (it->val != c) cnt[j + 1] += dis; else { found = true; cnt[j] += dis; it = h.erase(it); h.push_front(node(c, i)); continue; } it++; } if (!found) { h.push_front(node(c, i)); } i++; } int hl = h.size(); printf("%d\n", hl); for (int i = 0; i < hl; i++) cout << cnt[i] << endl; ; return 0; }
9
CPP
#include <bits/stdc++.h> using namespace std; int n; int x[10005]; set<int> h; int main() { int n, k; scanf("%d%d", &n, &k); for (int i = 0; i < n; i++) scanf("%d", &x[i]), h.insert(x[i]); int q; scanf("%d", &q); while (q--) { int a; scanf("%d", &a); int ans = k + 1; for (int i = n - 1; i >= 0; i--) { for (int j = 1; j <= k; j++) { int tem = a - j * x[i]; if (tem == 0) ans = min(ans, j); if (tem <= 0) break; for (int p = 1; p <= k - j; p++) { if (tem % p != 0) continue; tem /= p; if (h.find(tem) != h.end()) ans = min(ans, j + p); tem *= p; } } } if (ans == k + 1) printf("%d\n", -1); else printf("%d\n", ans); } }
11
CPP
import sys; u = sys.stdin.readline n = int(u()) a = list(map(int, u().split())) ind = -1 for i in range(40, -1, -1): # print(i); for j in range(n): if a[j] & (1 << i): if ind == -1: ind = j; else: ind = -1; break; if ind != -1: print(a[ind], end=' '); break; for i in range(n): if i != ind: print(a[i], end=' ');
7
PYTHON3
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1); const int MX = 10005; struct Point { double x, y; } pts[2 * MX]; Point operator-(Point a, Point b) { a.x -= b.x; a.y -= b.y; return a; } Point operator+(Point a, Point b) { a.x += b.x; a.y += b.y; return a; } Point operator*(Point a, double k) { a.x *= k; a.y *= k; return a; } double cp(Point a, Point b) { return a.x * b.y - a.y * b.x; } Point intersection(Point p, Point v, Point q, Point u) { double T = (cp(p, v) - cp(q, v)) / cp(u, v); return q + u * T; } double S[2 * MX]; int n; double calc(Point pivot, double alpha) { Point v = {cos(alpha), sin(alpha)}; auto getDist = [&](Point p) { return cp(v, p - pivot); }; int lo = 0, hi = 0; { int L = 0, R = n - 2; while (L <= R) { int M = (L + R) / 2; bool ok; if (getDist(pts[0]) > getDist(pts[n - 1])) { ok = getDist(pts[M + 1]) <= getDist(pts[M]) || getDist(pts[M]) >= getDist(pts[0]); } else { ok = getDist(pts[M + 1]) <= getDist(pts[M]) && getDist(pts[M]) <= getDist(pts[0]); } if (ok) { lo = M + 1; L = M + 1; } else { R = M - 1; } } } { int L = 0, R = n - 2; while (L <= R) { int M = (L + R) / 2; bool ok; if (getDist(pts[0]) < getDist(pts[n - 1])) { ok = getDist(pts[M + 1]) >= getDist(pts[M]) || getDist(pts[M]) <= getDist(pts[0]); } else { ok = getDist(pts[M + 1]) >= getDist(pts[M]) && getDist(pts[M]) >= getDist(pts[0]); } if (ok) { hi = M + 1; L = M + 1; } else { R = M - 1; } } } int a = 0, b = 0; { int L = lo, R = hi; if (R <= L) R += n; R--; while (L <= R) { int M = (L + R) / 2; if (getDist(pts[M]) < 0) { a = M; L = M + 1; } else { R = M - 1; } } } { int L = hi, R = lo; if (R <= L) R += n; R--; while (L <= R) { int M = (L + R) / 2; if (getDist(pts[M]) > 0) { b = M; L = M + 1; } else { R = M - 1; } } } if (a >= n) a -= n; if (b >= n) b -= n; if (a > b) b += n; Point p1 = intersection(pivot, v, pts[a], pts[a + 1] - pts[a]); Point p2 = intersection(pivot, v, pts[b], pts[b + 1] - pts[b]); return S[b] - S[a + 1] + cp(pts[a + 1], p1) + cp(p1, p2) + cp(p2, pts[b]); } int main() { int q; ignore = scanf("%d %d", &n, &q); for (int i = 0; i < n; i++) { ignore = scanf("%lf %lf", &pts[i].x, &pts[i].y); } reverse(pts, pts + n); for (int i = 0; i < n; i++) { pts[i + n] = pts[i]; } for (int i = 1; i < 2 * n; i++) { S[i] = S[i - 1] + cp(pts[i], pts[i - 1]); } double total = S[n]; while (q--) { Point p; ignore = scanf("%lf %lf", &p.x, &p.y); double L = 0, R = PI; bool sgn = (2.0 * calc(p, 0) - total) >= 0.0; for (int rep = 0; rep < 50; rep++) { double M = (L + R) / 2; double tmp = 2.0 * calc(p, M) - total; if ((tmp >= 0) == sgn) { L = M; } else { R = M; } } printf("%.15lf\n", (L + R) / 2); } }
13
CPP
#include <bits/stdc++.h> using namespace std; const int maxn = 1 << 19; const double eps = 1e-2; const double PI = acos((double)-1); struct pnt { double first, second; pnt() {} pnt(double first, double second) : first(first), second(second) {} inline pnt operator*(const pnt& a) { return pnt(first * a.first - second * a.second, first * a.second + second * a.first); } inline pnt operator+(const pnt& a) { return pnt(first + a.first, second + a.second); } inline void operator+=(const pnt& a) { first += a.first, second += a.second; } inline pnt operator-(const pnt& a) { return pnt(first - a.first, second - a.second); } inline pnt operator!() { return pnt(first, -second); } inline pnt operator*(double c) { return pnt(first * c, second * c); } inline pnt operator/(double c) { return pnt(first / c, second / c); } }; pnt a[maxn]; pnt c[maxn]; pnt pp[maxn]; int p[maxn]; void fft_forv(int n, pnt* a, int dr) { int nn = 1; while (nn < n) { pnt w = pp[nn]; if (dr == -1) w = !w; pnt tk = pnt(1, 0); for (int j = 0; j < nn; j++) { for (int i = j; i < n; i += 2 * nn) { a[i + nn] = a[i + nn] * tk; a[i] += a[i + nn]; a[i + nn] = a[i] - a[i + nn] * 2; } tk = tk * w; } nn *= 2; } } void fft_smesh(int n, pnt* a, int dr) { if (n == 1) return; if (n <= 1 << 1) { fft_forv(n, a, dr); return; } n /= 2; fft_smesh(n, a, dr); fft_smesh(n, a + n, dr); pnt w = pp[n]; if (dr == -1) w = !w; pnt tk = pnt(1, 0); for (int i = 0; i < n; i++) { a[i + n] = a[i + n] * tk; a[i] += a[i + n]; a[i + n] = a[i] - a[i + n] * 2; tk = tk * w; } } void calcbit(int n) { int tk = 1, ff; int lg = 0; while (tk < n) { tk *= 2; lg++; } p[0] = 0; tk = 0; for (int i = 1; i < n; i++) { ff = lg; do { ff--; tk ^= 1 << ff; } while (((tk >> ff) & 1) == 0); p[i] = tk; } } void revbit(int& n, pnt* a) { for (int i = 0; i < n; i++) { if (p[i] > i) swap(a[i], a[p[i]]); } } void mul(int& an, pnt* a, int& cn, pnt* c) { cn = an; fft_smesh(cn, a, 1); a[cn] = a[0]; for (int i = 0; i < cn; i++) { c[i] = c[i] + ((a[i] + !a[cn - i]) / 2) * ((a[i] - !a[cn - i]) / 2) * pnt(0, -1); } } void mul(int* a0, int* b0, int cn, int* c0) { for (int i = 0; i < cn; i++) { a[p[i]].first = a0[i]; a[p[i]].second = b0[i]; } mul(cn, a, cn, c); revbit(cn, c); fft_smesh(cn, c, -1); for (int i = 0; i < cn; i++) c[i] = c[i] / cn; for (int i = 0; i < cn; i++) { c0[i] = c[i].first > 0.5; } } string s0 = "ACGT"; int sum[maxn]; int poly1[maxn]; int poly2[maxn]; int res[maxn]; int bad[maxn]; char s1[maxn]; char s2[maxn]; int main() { int n, m, k; scanf("%d %d %d\n", &n, &m, &k); for (int i = 0; (1 << i) < maxn; i++) { pp[1 << i] = pnt(cos(PI / (1 << i)), sin(PI / (1 << i))); } int cn = 1; while (cn < n + m) { cn *= 2; } calcbit(cn); scanf("%s\n%s\n", s1, s2); for (int j = 0; j < 4; j++) { for (int i = 0; i < n; i++) { sum[i] = 0; } for (int i = 0; i < n; i++) if (s1[i] == s0[j]) { sum[max(0, i - k)]++; sum[min(n, i + k + 1)]--; } int cur = 0; for (int i = 0; i < n; i++) { cur += sum[i]; if (cur == 0) { poly1[i] = 1; } else { poly1[i] = 0; } } for (int i = 0; i < m; i++) { if (s2[i] == s0[j]) { poly2[m - 1 - i] = 1; } else { poly2[m - 1 - i] = 0; } } mul(poly1, poly2, cn, res); for (int i = m - 1; i < n + m; i++) { if (res[i] > 0) { bad[i - (m - 1)] = 1; } } } int ans = 0; for (int i = 0; i <= n - m; i++) if (bad[i] == 0) { ans++; } cout << ans << endl; cerr << clock() * 1. / CLOCKS_PER_SEC << endl; return 0; }
10
CPP
from collections import deque def solveOne(): nVertices, nEdges, v1, v2 = map(int, input().split()) v1 -= 1 v2 -= 1 g = [[] for _ in range(nVertices)] for _ in range(nEdges): u, v = map(lambda x: int(x) - 1, input().split()) g[u].append(v) g[v].append(u) def bfs(start, restricted): visited = {start} q = deque([start]) while q: v = q.pop() for to in g[v]: if to != restricted and to not in visited: visited.add(to) q.appendleft(to) return visited - {start} set1 = bfs(v1, v2) set2 = bfs(v2, v1) return len(set1 - set2) * len(set2 - set1) for _ in range(int(input())): print(solveOne())
8
PYTHON3
T=int(input()) for t in range(T): n=int(input()) l=[int(k) for k in input().split()] c=0 for i in range(1,n): if(l[i]<l[i-1]): c+=l[i-1]-l[i] print(c)
9
PYTHON3
from collections import defaultdict import math def SieveOfEratosthenes(n): # Create a boolean array "prime[0..n]" and initialize # all entries it as true. A value in prime[i] will # finally be false if i is Not a prime, else true. prime = [True for i in range(n + 1)] p = 2 while (p * p <= n): # If prime[p] is not changed, then it is a prime if (prime[p] == True): # Update all multiples of p for i in range(p * 2, n + 1, p): prime[i] = False p += 1 prime[0]= False prime[1]= False ans = [] # Print all prime numbers for p in range(n + 1): if prime[p]: ans.append(p) return ans n = int(input()) arr = list(map(int, input().split(' '))) factors = defaultdict(list) primes = SieveOfEratosthenes(450) for num in arr: sqrt = int(math.sqrt(num)) x = num lst = defaultdict(int) for i in primes: if x%i != 0: continue if i > x: break while x > 1 and x%i == 0: lst[i] += 1 x /= i x = int(x) i = x while x > 1 and x%i == 0: lst[i] += 1 x /= i x = int(x) for i in lst.keys(): factors[i].append(lst[i]) ans = 1 for i in factors.keys(): lst = factors[i] lst = sorted(lst) if len(lst) == n: ans *= i ** (lst[1]) if len(lst) == n-1: ans *= i ** (lst[0]) print(ans)
7
PYTHON3
n = int(input()) diff = -100000000000 minv = int(input()) for i in range(1,n): a = int(input()) diff = max(diff,a-minv) minv = min(a,minv) print(diff)
0
PYTHON3