solution
stringlengths
10
159k
difficulty
int64
0
3.5k
language
stringclasses
2 values
q, t = map(int, input().split(' ')) m = t c = 0 for i in range(1, q + 1): m += 5 * i c += 1 if m > 240: m -= 5 * i c -= 1 print(c)
800
PYTHON3
import itertools g=input() h=input() p=input() guesthost=sorted(g+h) pile=sorted(p) check=[True if i==j else False for i,j in itertools.zip_longest(guesthost,pile)] if all(check)==True: print('YES') else: print('NO')
800
PYTHON3
#include <bits/stdc++.h> using namespace std; inline char gc() { static char buf[100000], *p1 = buf, *p2 = buf; return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1++; } inline long long read() { long long x = 0; char ch = getchar(); bool positive = 1; for (; !isdigit(ch); ch = getchar()) if (ch == '-') positive = 0; for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0'; return positive ? x : -x; } inline void write(long long a) { if (a >= 10) write(a / 10); putchar('0' + a % 10); } inline void writeln(long long a) { if (a < 0) { a = -a; putchar('-'); } write(a); puts(""); } const long long N = 200005; long long n, T, tot, sum; pair<long long, long long> a[N]; signed main() { n = read(); T = read(); for (long long i = 1; i <= n; i++) a[i].second = read(); for (long long i = 1; i <= n; i++) a[i].first = read(); for (long long i = 1; i <= n; i++) { tot += a[i].second * a[i].first; sum += a[i].second; } if (tot == T * sum) writeln(sum); else { if (tot < T * sum) { sort(&a[1], &a[n + 1]); for (long long i = 1; i <= n; i++) { if (tot - a[i].second * a[i].first >= T * (sum - a[i].second)) { double t = (double)(tot - T * sum) / (a[i].first - T); printf("%.10lf\n", sum - t); return 0; } else { tot -= a[i].second * a[i].first; sum -= a[i].second; } } } else { sort(&a[1], &a[n + 1]); for (long long i = n; i; i--) { if (tot - a[i].second * a[i].first <= T * (sum - a[i].second)) { double t = (double)(tot - T * sum) / (a[i].first - T); printf("%.10lf\n", sum - t); return 0; } else { tot -= a[i].second * a[i].first; sum -= a[i].second; } } } puts("0"); } }
2,000
CPP
X = 0 n = int(input()) for _ in range(n): a = input() if a == 'X++' or a == '++X': X = eval('X + 1') else: X = eval('X - 1') print(X)
800
PYTHON3
t=int(input()) for query in range(t): r = int(input()) f = [int(x) for x in input().split()] pos=True for i in range(r//2): if f[i]<i: pos=False if f[r-i-1]<i: pos=False if r%2==0: if max(f[r//2],f[r//2-1])<r//2: pos=False else: if f[r//2]<r//2: pos=False if pos==True: print("YES") else: print("NO")
1,300
PYTHON3
x,y=map(int,input().split()) a=1 k=-1 x=x-1 while(x): a=a*10 x=x-1 for i in range(a,a*10): if(i%y==0): k=1 print(i) break if(k!=1): print("-1")
1,000
PYTHON3
n = int(input()) found = False data = "" for i in range(n): row = input().split("|") if not found: if row[0] == "OO": row[0] = "++" found = True elif row[1] == "OO": row[1] = "++" found = True data += "|".join(row) + "\n" if found: print("YES") print(data) else: print("NO")
800
PYTHON3
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e3 + 2; int n, m; struct Ans { int sx, sy, tx, ty; } ans[MAXN]; int R[MAXN], C[MAXN]; int main() { scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%d", &R[i]); for (int i = 1; i <= n; ++i) scanf("%d", &C[i]); for (int i = 1; i <= n; ++i) { int x = -1, y = -1; for (x = i; x <= n; ++x) if (R[x] == i) break; for (y = i; y <= n; ++y) if (C[y] == i) break; if (x == i && y == i) continue; ans[++m] = (Ans){x, i, i, y}; R[x] = R[i]; C[y] = C[i]; } printf("%d\n", m); for (int i = 1; i <= m; ++i) printf("%d %d %d %d\n", ans[i].sx, ans[i].sy, ans[i].tx, ans[i].ty); return 0; }
2,900
CPP
#include <bits/stdc++.h> std::vector<int> a[222222]; std::vector<int> b[222222]; int d[222222]; int v[222222]; int r[222222]; int main() { std::priority_queue<std::pair<int, int> > PQ; int i, j, k, n, m; scanf("%d%d", &n, &m); for (i = 0; i < n; i++) { scanf("%d", &j); d[i] = j; while (j--) { scanf("%d", &k); a[i].push_back(k); b[std::abs(k)].push_back(i); } } for (i = 0; i < n; i++) PQ.push(std::make_pair(-d[i], i)); while (!PQ.empty()) { std::pair<int, int> p = PQ.top(); PQ.pop(); if (v[p.second]) continue; for (i = 0; i < a[p.second].size(); i++) if (r[std::abs(a[p.second][i])] && r[std::abs(a[p.second][i])] * a[p.second][i] > 0) break; if (i < a[p.second].size()) continue; if (p.first == 0) { puts("NO"); return 0; } for (i = 0; i < a[p.second].size(); i++) if (!r[std::abs(a[p.second][i])]) break; k = a[p.second][i]; r[std::abs(k)] = k / std::abs(k); for (i = 0; i < b[std::abs(k)].size(); i++) if (b[std::abs(k)][i] != p.second) { d[b[std::abs(k)][i]]--; PQ.push(std::make_pair(-d[b[std::abs(k)][i]], b[std::abs(k)][i])); } } puts("YES"); for (i = 1; i <= m; i++) putchar(r[i] > 0 ? '1' : '0'); }
2,500
CPP
#include <bits/stdc++.h> using namespace std; int n, m; char ans[20][20], now[20][20]; char figure[4][4][4] = {{"AAA", ".A.", ".A."}, {".A.", ".A.", "AAA"}, {"A..", "AAA", "A.."}, {"..A", "AAA", "..A"}}; char best; void paint(char color, int type, int a, int b) { for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) if (figure[type][i][j] == 'A') now[a + i][b + j] = color; } void wash(int type, int a, int b) { for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) if (figure[type][i][j] == 'A') now[a + i][b + j] = '.'; } bool clr(int type, int a, int b) { for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) if (figure[type][i][j] == 'A') if (now[a + i][b + j] != '.') return false; return true; } char maxim[20][20]; void dfs(int a, int b, char curr) { if (a >= n - 2) { if (curr > best) { best = curr; for (int i = 0; i < n; i++) strcpy(ans[i], now[i]); } return; } if (b >= m - 2) { dfs(a + 1, 0, curr); return; } if (curr + 1 < maxim[a][b]) return; maxim[a][b] = max(maxim[a][b], curr); dfs(a, b + 1, curr); for (int i = 0; i < 4; i++) { if (clr(i, a, b)) { paint(curr, i, a, b); dfs(a, b + 1, curr + 1); wash(i, a, b); } } return; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> m; for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) ans[i][j] = now[i][j] = '.'; dfs(0, 0, 'A'); cout << best - 'A' << endl; for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) cout << ans[i][j]; cout << endl; } return 0; }
2,300
CPP
a=int(input());s=0 for i in sorted(map(int,input().split()),reverse=True):s+=abs(a-i);a-=1; print(s)
1,200
PYTHON3
a = input().strip() print("{}{}".format(a, a[::-1]))
800
PYTHON3
import math n=int(input()) if(n%2==0): print(math.ceil(n/2)) else: print("-"+str(math.ceil(n/2)))
800
PYTHON3
#include <bits/stdc++.h> using namespace std; int main(void) { int a, x, y; scanf("%d%d%d", &a, &x, &y); if (y % a == 0) { puts("-1"); return 0; } int k = y / a; if (k == 0 || k % 2) { if (x <= (a - 1) / 2 && x >= -((a - 1) / 2)) printf("%d\n", k == 0 ? 1 : 3 * ((k - 1) / 2) + 2); else puts("-1"); return 0; } else { if (x < 0 && x > -a) printf("%d\n", 3 * ((k - 2) / 2) + 2 + 1); else if (x > 0 && x < a) printf("%d\n", 3 * ((k - 2) / 2) + 2 + 2); else puts("-1"); } return 0; }
1,400
CPP
showels = 1 mul = 1 n,k = map(int,input().split()) n = num = n%10 while(not (n%10==0 or (n-k)%10==0)): mul+=1 n = num*mul showels+=1 print(showels)
800
PYTHON3
def ans(a, n): d = {} for i in a: for j in i: if j not in d: d[j]=1 else: d[j]+=1 lis = list(d.values()) for i in lis: if i%n!=0: return('NO') return('YES') m = int(input()) for i in range(m): n = int(input()) arr = [] for i in range(n): x = input() arr.append(x) print(ans(arr,n))
800
PYTHON3
#include <bits/stdc++.h> using namespace std; ifstream fin("in.in"); ofstream fout("out.out"); const int N = 1e5 + 10; int n, m, k[N]; vector<int> a[N]; long long res; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> m >> n; for (int i = 0; i < n; i++) { cin >> k[i]; int pos = -1; for (int j = 0; j < k[i]; j++) { int x; cin >> x; a[i].push_back(x); if (x == 1) pos = j; } res += k[i] - 1; if (pos > -1) { for (int j = pos + 1; j < k[i]; j++) if (a[i][j] == a[i][j - 1] + 1) res--; else break; } } cout << res + n + res - 1 << endl; return 0; }
1,500
CPP
#include <bits/stdc++.h> const long long mod = 1e9 + 7; const int x = 1; using namespace std; long long qpow(long long a, long long b) { long long res = 1; while (b) { if (b & 1) res *= a, res %= mod; a *= a; a %= mod; b >>= 1; } return res; } long long isprime(long long n) { int i; if (n == 2) return 1; if (n % 2 == 0) return 0; for (i = 3; i <= sqrt(n); i += 2) if (n % i == 0) return 0; return 1; } int main() { long long n; cin >> n; vector<int> v(n); vector<int> g(n); for (int i = 0; i < n; i++) { cin >> v[i]; g[i] = v[i]; } int l, r; sort((g).begin(), (g).end()); bool tf = 0; for (int i = 0; i < n; i++) { tf |= (v[i] != g[i]); } if (tf == 0) { cout << "yes" << endl << "1 1"; return 0; } for (int i = 0; i < n; i++) { if (v[i] != g[i]) { l = i; for (int j = l + 1; j < n; j++) { if (v[j] == g[l]) { r = j; goto k; } } } } r = n + 1; k: reverse(v.begin() + l, v.begin() + r + 1); for (int i = 0; i < n; i++) { if (v[i] != g[i]) { cout << "no"; return 0; } } cout << "yes" << endl << l + 1 << ' ' << r + 1 << endl; return 0; }
1,300
CPP
n=int(input()) l=list(map(int,input().split())) p=list(map(int,input().split())) l=l[1:];p=p[1:] l=l+p l=set(l); if len(l)==n: print("I become the guy.") else: print("Oh, my keyboard!")
800
PYTHON3
inp = input().split(' ') change = {} for x in range(int(inp[1])): a = input().split() if len(a[1])<len(a[0]): change[a[0]] = a[1] else: change[a[0]] = a[0] b = input().split(' ') out = "" c = b.pop(0) out = out + change[c] for y in b: out = out + ' ' + change[y] print(out)
1,000
PYTHON3
#include <bits/stdc++.h> using namespace std; const int N = 30005; const long long INF = 1e18; int t, n, m, k, l; char word[200005]; int dp[N]; int cnt[30]; void test() { scanf("%d %d %d", &n, &m, &k); scanf("%s", &word[1]); for (int i = 0; i < 26; i++) { cnt[i] = 0; } l = strlen(word + 1); for (int i = 1; i <= l; i++) { cnt[word[i] - 'A']++; } long long ans = INF; for (int i = 0; i < 26; i++) { for (int j = 0; j < n; j++) { dp[j] = 0; } dp[0] = 1; for (int j = 0; j < 26; j++) { if (j == i) continue; for (int k = n - 1; k >= 0; k--) { if (dp[k] == 1 && k + cnt[j] < n) { dp[k + cnt[j]] = 1; } } for (int k = 0; k < n; k++) { if (dp[k] == 0 || k + cnt[i] < n) continue; int used = n - k; if (l - (k + cnt[i]) >= m) { ans = 0; break; } else { int remaining = m - (l - (k + cnt[i])); ans = min(ans, (long long)used * remaining); } } } } printf("%lld\n", ans); } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); scanf("%d", &t); while (t--) { test(); } }
2,300
CPP
#include <bits/stdc++.h> using namespace std; struct cww { cww() { if (1) { ios::sync_with_stdio(false); cin.tie(0); } } } star; template <typename T> inline bool chmin(T &l, T r) { bool a = l > r; if (a) l = r; return a; } template <typename T> inline bool chmax(T &l, T r) { bool a = l < r; if (a) l = r; return a; } template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &it : v) is >> it; return is; } class range { private: struct I { int x; int operator*() { return x; } bool operator!=(I &lhs) { return x < lhs.x; } void operator++() { ++x; } }; I i, n; public: range(int n) : i({0}), n({n}) {} range(int i, int n) : i({i}), n({n}) {} I &begin() { return i; } I &end() { return n; } }; int n, m; int a[1123456]; int b[1123456]; int k; int c[1123456]; void latte() { scanf("%d%d", &n, &m); for (int i : range(m)) { scanf("%d%d", a + i, b + i); a[i]--; b[i]--; } } void malta() { string sp(k, ' '); sp.back() = '\n'; printf("%d\n", k); for (int i : range(k)) { printf("%d%c", c[i] + 1, sp[i]); } } using V = vector<int>; using VV = vector<V>; VV g; V vis, ord, in, itr, stk; void sort() { itr = V(n, -1); for (int i : range(n)) { if (itr[i] == -1) { if (in[i] == 0) continue; itr[i]++; stk.push_back(i); while (stk.size()) { const int v = stk.back(); if (itr[v] == g[v].size()) { stk.pop_back(); ord.push_back(v); } else { const int u = g[v][itr[v]]; if (itr[u] == -1 && in[u]) { itr[u]++; stk.push_back(u); } itr[v]++; } } } } reverse((ord).begin(), (ord).end()); } int main() { latte(); g = VV(n); for (int i : range(m)) g[a[i]].push_back(b[i]); vis = V(n, 0); in = V(n, 0); for (int v : range(n)) { if (vis[v]) continue; vis[v] = 1; in[v] = 1; for (int u : g[v]) vis[u] = 1; } sort(); vis = V(n, 0); k = 0; for (int v : ord) { if (vis[v]) continue; for (int u : g[v]) { vis[u] = 1; } c[k++] = v; } sort(c, c + k); malta(); return 0; }
3,000
CPP
query=int(input()) ball=1; throw=1 for i in range(query-1): ball+=throw ball=ball%query if ball==0: print(query,end=" ") else: print(ball,end=" ") throw+=1
800
PYTHON3
t=int(input()) for _ in range(t): b=input() if (len(b)-1)%2==0: s="" for i in range(len(b)): if i%2==0: s=s+b[i] print(s) else: s="" for i in range(len(b)): if i%2==0: s=s+b[i] s=s+b[len(b)-1] print(s)
800
PYTHON3
#include <bits/stdc++.h> using namespace std; int const N = 111; int t1, t2, l1, l2; string s1, s2; int dp[N], ans; int32_t main() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); cin >> t1 >> t2 >> s1 >> s2; l1 = s1.size(), l2 = s2.size(); for (int i = 0; i < l2; i++) { int p = 0; for (int j = 0; j < l1; j++) if (s1[j] == s2[p]) dp[i]++, p = (p + 1) % l2; s2 = s2.substr(1) + s2[0]; } int r = 0; for (int i = 0; i < t1; i++) { ans += dp[r]; r = (r + dp[r]) % l2; } cout << (ans / t2) / l2; }
2,000
CPP
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int m, n, k, t; int a[N]; struct nd { int l, r, d; nd(int _l = 0, int _r = 0, int _d = 0) { l = _l; r = _r; d = _d; } friend bool operator<(nd a, nd b) { return a.l < b.l || (a.l == b.l && a.r < b.r); } } b[N]; int can(int val) { int Rlast = 0, L = 0, ret = 0; for (int i = 1; i <= k; ++i) if (b[i].d > val) { if (!Rlast || b[i].l > Rlast) { if (Rlast) ret += (Rlast - L + 1) * 2; L = b[i].l; Rlast = b[i].r; } else Rlast = max(Rlast, b[i].r); } if (Rlast) ret += (Rlast - L + 1) * 2; return ret; } int main() { scanf("%d%d%d%d", &m, &n, &k, &t); t -= n + 1; for (int i = 1; i <= m; ++i) scanf("%d", &a[i]); sort(a + 1, a + m + 1); for (int i = 1, l, r, d; i <= k; ++i) { scanf("%d%d%d", &l, &r, &d); b[i] = nd(l, r, d); } sort(b + 1, b + k + 1); int l = 0, r = m; while (l != r) { int mid = l + r + 1 >> 1; if (can(a[m - mid + 1]) <= t) l = mid; else r = mid - 1; } printf("%d\n", l); }
1,900
CPP
#########################################################################################################\ ######################################################################################################### ###################################The_Apurv_Rathore##################################################### ######################################################################################################### ######################################################################################################### import sys,os,io from sys import stdin from math import log, gcd, ceil from collections import defaultdict, deque, Counter from heapq import heappush, heappop import math if(os.path.exists('input.txt')): sys.stdin = open("input.txt","r") ; sys.stdout = open("output.txt","w") def ncr(n, r, p): num = den = 1 for i in range(r): num = (num * (n - i)) % p den = (den * (i + 1)) % p return (num * pow(den, p - 2, p)) % p def primeFactors(n): l = [] while n % 2 == 0: l.append(2) n = n / 2 for i in range(3,int(math.sqrt(n))+1,2): while n % i== 0: l.append(int(i)) n = n / i if n > 2: l.append(n) return list(set(l)) def power(x, y, p) : res = 1 x = x % p if (x == 0) : return 0 while (y > 0) : if ((y & 1) == 1) : res = (res * x) % p y = y >> 1 # y = y/2 x = (x * x) % p return res def SieveOfEratosthenes(n): prime = [True for i in range(n+1)] p = 2 while (p * p <= n): if (prime[p] == True): for i in range(p * p, n+1, p): prime[i] = False p += 1 return prime def countdig(n): c = 0 while (n > 0): n //= 10 c += 1 return c def si(): return input() def prefix_sum(arr): r = [0] * (len(arr)+1) for i, el in enumerate(arr): r[i+1] = r[i] + el return r def divideCeil(n,x): if (n%x==0): return n//x return n//x+1 def ii(): return int(input()) def li(): return list(map(int,input().split())) def ws(s): sys.stdout.write(s + '\n') def wi(n): sys.stdout.write(str(n) + '\n') def wia(a): sys.stdout.write(' '.join([str(x) for x in a]) + '\n') #__________________________TEMPLATE__________________OVER_______________________________________________________ # input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline t = 1 # t = int(input()) for _ in range(t): l,r,x,y = li() z = y//x ans = 0 if (y%x==0): for i in range(1,z+1): if (i*i>z): break if (z%i==0): if (gcd(z//i,i)==1): if (l/x<=i<=r/x and l/x<=z//i<=r/x): if (z//i!=i): ans+=2 else: ans+=1 print(ans)
1,600
PYTHON3
import sys import math n, a, b = [int(x) for x in (sys.stdin.readline()).split()] ff = [''] * (n + 1) for i in (sys.stdin.readline()).split(): ff[int(i)] = "1" for i in (sys.stdin.readline()).split(): ff[int(i)] = "2" print(" ".join(ff[1:]))
800
PYTHON3
#include <bits/stdc++.h> using namespace std; const int iinf = 1e9 + 7; const long long linf = 1ll << 60; const double dinf = 1e10; inline long long read() { bool f = 0; long long x = 0; char c = getchar(); while ((c < '0' || c > '9') && c != '-') c = getchar(); if (c == '-') { f = 1; c = getchar(); } while (c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = getchar(); } if (f) x = -x; return x; } inline void scf(int &x) { bool f = 0; x = 0; char c = getchar(); while ((c < '0' || c > '9') && c != '-') c = getchar(); if (c == '-') { f = 1; c = getchar(); } while (c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = getchar(); } if (f) x = -x; return; } void scf(int &x, int &y) { scf(x); return scf(y); } void scf(int &x, int &y, int &z) { scf(x); scf(y); return scf(z); } const int N = 2e5 + 100; int n, c; int lst[N]; int cnt[N]; inline int LAST(int i, int v) { int ret = lst[i]; if (v > i) v = 0; return ret < v ? v : ret; } inline bool check(int v) { int tmp = c, mx = tmp; for (;;) { int p = LAST(tmp < mx ? tmp : mx, v); if (!p) break; int need = tmp / p; if (need >= cnt[p]) tmp -= cnt[p] * p; else tmp %= p; mx = p - 1; } return tmp; } int main() { scf(c, n); for (int i = 0; i < (n); i++) { int x; scf(x); cnt[x]++; } for (int i = (1); i <= (c); i++) lst[i] = cnt[i] ? i : lst[i - 1]; for (int ans = (1); ans <= (c); ans++) { cnt[ans]++; if (check(ans)) { printf("%d\n", ans); return 0; } cnt[ans]--; } puts("Greed is good"); return 0; }
2,600
CPP
#include <bits/stdc++.h> using namespace std; void solve() { int N; cin >> N; long A[N]; for (int i = 0; i < N; cin >> A[i++]) { } for (int i = 0; i < N; ++i) { if (A[i] == 0) cout << "0 "; else if (i & 1) { if (A[i] < 0) cout << A[i] << ' '; else cout << '-' << A[i] << ' '; } else cout << abs(A[i]) << ' '; } cout << '\n'; } int main(void) { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int T; cin >> T; while (T--) { solve(); } exit(0); }
1,100
CPP
#include <bits/stdc++.h> using namespace std; int a[4001], b[4001], sum[4], Sum[4], Q, n, N, i, j, k, l, Ls, tot; int ans[4002]; char S[4001], T[4001]; void swap(int &x, int &y) { int z = x; x = y; y = z; } int turn(char a, char b) { if (a == b) { return (a == '0') ? 2 : 3; } if (a == '0') return 0; return 1; } void rev(int *a, int t) { int i; for (i = t / 2; i >= 1; i--) swap(a[i], a[t - i + 1]); for (i = 1; i <= t; i++) if (a[i] <= 1) a[i] ^= 1; } int main() { scanf("%d", &Q); for (; Q; --Q) { scanf("%s", S + 1), scanf("%s", T + 1); n = strlen(S + 1), tot = 0, N = n / 2; memset(sum, 0, sizeof(sum)); memset(Sum, 0, sizeof(Sum)); for (i = 1; i <= N; i++) a[i] = turn(S[i * 2 - 1], S[i * 2]), ++sum[a[i]]; for (i = 1; i <= N; i++) b[i] = turn(T[i * 2 - 1], T[i * 2]), ++Sum[b[i]]; if (sum[0] + sum[1] != sum[0] + sum[1] || sum[2] != Sum[2] || sum[3] != Sum[3]) { printf("-1\n"); continue; } Ls = -1, tot = 0; if (sum[0] != Sum[0]) { if (((sum[0] - sum[1]) > 0 ? (sum[0] - sum[1]) : -(sum[0] - sum[1])) > ((Sum[0] - Sum[1]) > 0 ? (Sum[0] - Sum[1]) : -(Sum[0] - Sum[1]))) { for (i = 1; i <= N; i++) if (a[i] <= 1) { --sum[a[i]], ++sum[a[i] ^ 1]; if (sum[0] == Sum[0]) { rev(a, i); ans[++tot] = i; break; } } } else { for (i = 1; i <= N; i++) if (b[i] <= 1) { --Sum[b[i]], ++Sum[b[i] ^ 1]; if (sum[0] == Sum[0]) { rev(b, i); Ls = i; break; } } } } for (i = 1; i <= N - 1; i++) { for (j = i; j <= N; j++) if (a[j] == b[i]) { if (j > 1) rev(a, j - 1), ans[++tot] = j - 1; rev(a, j), ans[++tot] = j; break; } } if (N > 1) rev(a, N - 1), ans[++tot] = N - 1; if (Ls > -1) ans[++tot] = Ls; printf("%d\n", tot); for (i = 1; i <= tot; i++) printf("%d ", ans[i] * 2); printf("\n"); } }
3,300
CPP
#include <bits/stdc++.h> using namespace std; const int N = 200005; vector<vector<int> > G(N); vector<pair<int, int> > e; vector<bool> vis(N), vis2(N); vector<int> col(N, 0); vector<int> d(N, 1), d2(N, 1); bool flg = true; bool flg2 = true; void dfs1(int root, int u) { vis[root] = true; for (int i = 0; i < G[root].size(); i++) { int v = G[root][i]; if (!vis[v]) { if (col[v] != col[root]) d[root]++; dfs1(v, u); } } if (root != u && d[root] > 1) flg = false; } void dfs2(int root, int u) { vis2[root] = true; for (int i = 0; i < G[root].size(); i++) { int v = G[root][i]; if (!vis2[v]) { if (col[v] != col[root]) d2[root]++; dfs2(v, u); } } if (root != u && d2[root] > 1) flg2 = false; } int main() { int n; cin >> n; for (int i = 0; i < n - 1; i++) { int u, v; cin >> u >> v; G[u].push_back(v); G[v].push_back(u); e.push_back(make_pair(u, v)); } for (int i = 1; i <= n; i++) cin >> col[i]; int x = -1, y = -1; for (int i = 0; i < e.size(); i++) { if (col[e[i].first] == col[e[i].second]) continue; x = e[i].first, y = e[i].second; break; } if (x == -1) { cout << "YES" << '\n' << 1 << '\n'; return 0; } dfs1(x, x); dfs2(y, y); if (flg) cout << "YES" << '\n' << x << '\n'; else if (flg2) cout << "YES" << '\n' << y << '\n'; else cout << "NO" << '\n'; return 0; }
1,600
CPP
q = int(input()) for i in range(q): a, b, c = map(int, input().split()) s = a + b + c print(s // 2)
800
PYTHON3
#include <bits/stdc++.h> using namespace std; void dfs(vector<vector<char>> &arr, int i, int j, int n, int &p) { if (p == 1) return; if (i < 0 || j < 0 || i > n - 1 | j > n - 1) return; if (arr[i][j] == '2' || arr[i][j] == '0') return; if ((arr[i][j] == '1') && (i == n - 1 || j == n - 1)) { p = 1; arr[i][j] = '2'; return; } if (arr[i][j] == '1') { arr[i][j] = '2'; } dfs(arr, i + 1, j, n, p); dfs(arr, i, j + 1, n, p); } int fin(int i, int j, int k) { int len = j - i + 1; int ans = (len + k) / (k + 1); if (ans < 2) return 0; else { return ans - 2; } } void fac(int x, int y, int i, int n) { if (n == i) { cout << x << "\n"; return; } fac(((y - x) + 1000000007) % 1000000007, y, i + 1, n); } long long fac(long long n) { if (n == 0) { return 1; } return n * fac(n - 1); } void solve() { long long n; cin >> n; long long f = fac(n); cout << (f / ((n) * (n / 2))); } int main() { ios_base::sync_with_stdio(false); int t = 1; while (t--) { solve(); } }
1,300
CPP
def le2(num): s = str(num) ans = '' for i in s: ans += i + '0' ans = ans[:-1] return int(ans) def m1(num,less): sn = str(num) sr = '' for i in range(less): sr+='0'+sn[-1] sn = sn[:-1] sr = sn+sr[::-1] return int(sr) def m2(num,less): sn = str(num) sr = '' for i in range(less): sr+=sn[-1]+'0' sn = sn[:-1] sr = sn+sr[::-1] return int(sr) mod = 998244353 ans = 0 n = int(input()) d = [[]for i in range(11)] a = list(map(int,input().split())) for i in a: d[len(str(i))].append(i) prev = 0 for i in range(1,11): curlen = len(d[i]) #less for lessnum in d[i-1]: prev = (prev + le2(lessnum)) % mod ans = (ans+prev*curlen)%mod for lessdigits in range(1,i): downsum = 0 for curnum in d[i]: downsum = (downsum+m1(curnum,lessdigits))%mod ans = (ans + downsum*len(d[lessdigits])) #equal cursuml1 = 0 for enum in d[i]: res = le2(enum) ans = (ans + curlen * 11 * res) % mod cursuml1 = (cursuml1+10*res)%mod #more for moredigits in range(i+1,11): ans = (ans+cursuml1*len(d[moredigits]))%mod moresum = 0 for morenum in d[moredigits]: moresum = (moresum+m2(morenum,i))%mod ans = (ans+moresum*curlen)%mod print(ans)
1,500
PYTHON3
l=list(map(int,input().split())) k,n,w=l[0],l[1],l[2] c=(k*((w*(w+1))//2)) if(c>n): print(c-n) else: print(0)
800
PYTHON3
a=[] for i in range(5): a.append(list(map(int,input().split()))) for i in range(5): if 1 in a[i]: j=a[i].index(1) break print(abs(2-i)+abs(2-j))
800
PYTHON3
#include <bits/stdc++.h> using namespace std; int N; int P[202020]; int A[202020], B[202020]; int M; int C[202020]; set<int> X[4]; set<int> did; void solve() { int i, j, k, l, r, x, y; string s; cin >> N; for (i = 0; i < (N); i++) cin >> P[i]; for (i = 0; i < (N); i++) cin >> A[i], X[A[i]].insert(P[i]); for (i = 0; i < (N); i++) cin >> B[i], X[B[i]].insert(P[i]); cin >> M; for (i = 0; i < (M); i++) { cin >> x; while (X[x].size()) { if (did.count(*X[x].begin()) == 0) break; X[x].erase(X[x].begin()); } if (X[x].empty()) (void)printf("-1"); else { y = *X[x].begin(); did.insert(y); X[x].erase(y); (void)printf("%d", y); } (void)printf("%c", (i == M - 1) ? '\n' : ' '); } } int main(int argc, char** argv) { string s; int i; if (argc == 1) ios::sync_with_stdio(false), cin.tie(0); for (i = 0; i < (argc - 1); i++) s += argv[i + 1], s += '\n'; for (i = 0; i < (s.size()); i++) ungetc(s[s.size() - 1 - i], stdin); solve(); return 0; }
1,400
CPP
import sys from math import pi, sin def I(): return sys.stdin.readline().rstrip() def h(n): m = n // 2 - 1 a = 1 return a * sin(pi * m / n) / sin(pi / n) def main(): for tc in range(1, 1+int(I())): n = int(I()) n *= 2 print(h(n)) main()
1,400
PYTHON3
lst = [0] for _ in range(int(input())): a,e = list(map(int,input().split())) lst.append(lst[-1]-a+e) print(max(lst))
800
PYTHON3
t=int(input()) a=[] for i in range(t): p,q=[int(i) for i in input().split()] a.append((p,q)) a.sort() c=0 c=a[0][1]#3 p=a[0][1]#3 #print(a,c,p) for i in range(1,t): if p>a[i][1]: c=c+a[i][0]-p p=a[i][0] else: c=c+a[i][1]-p p=a[i][1] print(c)
1,400
PYTHON3
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; string s; bool has[30][30]; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> s; int k; cin >> k; for (int i = 0; i < k; i++) { char x, y; cin >> x >> y; has[x - 'a'][y - 'a'] = has[y - 'a'][x - 'a'] = true; } int i = 0; int ans = 0; while (i < s.size()) { int j = i; while ((j < s.size()) && (s[j] == s[i] || has[s[j] - 'a'][s[i] - 'a'])) j++; j--; int f0 = 0, f1 = 0; for (int t = i; t <= j; t++) { if (s[t] == s[i]) f0++; else f1++; } ans += min(f0, f1); i = j + 1; } cout << ans; return 0; }
1,600
CPP
#include <bits/stdc++.h> using namespace std; int main() { long long int n, m, i, j, c = 0, s = 0, f = 0, a, b; cin >> n >> m; vector<pair<long long int, long long int> > arr; for (i = 0; i < m; i++) { cin >> a >> b; arr.push_back(make_pair(b, a)); } sort(arr.rbegin(), arr.rend()); for (i = 0; i < m; i++) { if (n <= 0) { break; } c = min(arr[i].second, n); n -= c; s += arr[i].first * c; } cout << s << endl; return 0; }
900
CPP
#include <bits/stdc++.h> using namespace std; int a[11][111], b[11][111], c[11][111]; char str[111]; struct node { int n, v; node(int _n, int _v) { n = _n, v = _v; } node() {} friend bool operator<(node a, node b) { return a.v > b.v; } } p[111]; int main() { int n, m, cc; while (~scanf("%d%d%d", &n, &m, &cc)) { for (int i = 0; i < n; i++) { scanf(" %*s", str); for (int j = 0; j < m; j++) { scanf("%d %d %d", &a[i][j], &b[i][j], &c[i][j]); } } int res = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (i == j) continue; int t = 0, cnt = 0, q = cc; for (int k = 0; k < m; k++) { if (b[j][k] > a[i][k]) p[cnt++] = node(c[i][k], (b[j][k] - a[i][k])); } sort(p, p + cnt); for (int k = 0; k < cnt; k++) { if (q <= p[k].n) { t += q * p[k].v; break; } else { t += p[k].n * p[k].v; q -= p[k].n; } } res = max(res, t); } } printf("%d\n", res); } return 0; }
1,200
CPP
#include <bits/stdc++.h> using namespace std; int main() { int n, m, k; cin >> n >> m >> k; char grid[n][m]; bool flag1 = 0, flag2 = 0; int cnt[100] = {}; for (int i = 0; i < n; i++) { string s; cin >> s; if (s.find('-') < 0 || s.find('-') >= s.size()) continue; int x = s.find('G'); int y = s.find('R'); if (y == -1 && x == -1) continue; if (y >= s.size() || y < 0) flag1 = 1; if (x >= s.size() || x < 0) flag2 = 1; if (x < s.size() && x >= 0 && y < s.size() && y >= 0) { int tmp = abs(x - y) - 1; int cur = 0; while (tmp) { cnt[cur] += tmp % 2; tmp /= 2; cur++; } } } if (flag1 & flag2) puts("Draw"); else if (flag1) puts("First"); else if (flag2) puts("Second"); else { int ans = 0; for (int i = 0; i < 100; i++) if (cnt[i] % (k + 1)) { puts("First"); return 0; } puts("Second"); } return 0; }
2,600
CPP
#include <bits/stdc++.h> using namespace std; template <class T> inline int countbit(T n) { return (n == 0) ? 0 : (1 + countbit(n & (n - 1))); } template <class T> inline T gcd(T a, T b) { return b ? gcd(b, a % b) : a; } const double EPS = 1e-9; const double PI = acos(-1.0); int get(int desired, vector<int> szs) { for (int i = 0; i < 5; i++) { if (desired + i < 5 && szs[desired + i] != 0) return desired + i; if (desired - i >= 0 && szs[desired - i] != 0) return desired - i; } return -1; } int main() { int k; vector<int> szs(5, 0); cin >> szs[0] >> szs[1] >> szs[2] >> szs[3] >> szs[4]; cin >> k; for (int i = 0; i < int(k); i++) { string pref; int desired = 0; cin >> pref; if (pref == "S") desired = 0; if (pref == "M") desired = 1; if (pref == "L") desired = 2; if (pref == "XL") desired = 3; if (pref == "XXL") desired = 4; int got = get(desired, szs); switch (got) { case 0: cout << "S" << endl; break; case 1: cout << "M" << endl; break; case 2: cout << "L" << endl; break; case 3: cout << "XL" << endl; break; case 4: cout << "XXL" << endl; break; default: cout << "shit" << endl; break; } szs[got]--; } return 0; }
1,100
CPP
#include <bits/stdc++.h> const long long INF = 10000000000000; const long long mod = 1e9 + 7; using namespace std; void add(int& a, int b) { a += b; if (a >= mod) a -= mod; } long long mul(long long a, long long b) { return (a * b) % mod; } long long Pow(long long a, long long b) { if (b == 0) return 1; long long c = Pow(a, b / 2); if (b % 2) return c * c * a; return c * c; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; cout.precision(30); int n, k; cin >> n >> k; std::vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; sort(a.begin(), a.end()); map<long long, bool> maap; int nb = 0; for (int i = n; i >= 0; i--) { for (int j = 0; j < i && nb < k; j++, nb++) { cout << n - i + 1 << " "; for (int m = n - 1; m >= i; m--) cout << a[m] << " "; cout << a[j] << "\n"; } } return 0; }
1,600
CPP
#include <bits/stdc++.h> #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace std; long long power(long long a, long long b, long long modi) { a %= modi; long long res = 1; while (b) { if (b % 2) { res = (res * a) % modi; } b /= 2; a = (a * a) % modi; } return res; } int rub[2000001]; int pi[2000001]; bool isprime[2000001]; void seive() { for (int i = 4; i <= 2000000; i += 2) isprime[i] = 1; for (int i = 3; i * i <= 2000000; i += 2) { if (!isprime[i]) { for (int j = i * i; j <= 2000000; j += i) isprime[j] = 1; } } for (int i = 2; i <= 2000000; i++) { if (!isprime[i]) pi[i] = pi[i - 1] + 1; else pi[i] = pi[i - 1]; } } bool ispali(int n) { int no = n; int rev = 0; while (no > 0) { int ld = no % 10; no /= 10; rev = rev * 10 + ld; } if (n == rev) return true; else return false; } void np() { for (int i = 1; i <= 2000000; i++) { if (ispali(i)) rub[i] = rub[i - 1] + 1; else rub[i] = rub[i - 1]; } } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int p, q; cin >> p >> q; seive(); np(); int ans = 0; for (int i = 1; i <= 2000000; i++) { int c = (p * rub[i]) / q; if (pi[i] <= c && i > ans) ans = i; } cout << ans; return 0; }
1,600
CPP
n,k = map(int,input().split()) count = 0 for _ in range(n): s = list(map(int,input())) for i in range(k+1): if i not in s: break else: count+=1 print(count)
1,100
PYTHON3
n,c=map(int,input().split()) l=list(map(int,input().split())) med=0 for i in range(n-1): if l[i]-l[i+1]>med:med=l[i]-l[i+1] print(max(med-c,0))
1,000
PYTHON3
n,a,b=map(int,input().split()) x=input() if x[a-1]==x[b-1]: print(0) else: print(1)
1,200
PYTHON3
n = int(input()) k = int(input()) for i in range(n): a, b = map(int, input().split()) if (a == k or a == 7-k or b == k or b == 7-k): print('NO') exit() print('YES')
1,100
PYTHON3
#include <bits/stdc++.h> using namespace std; const int MAXN = 100100; const int MAXLG = 20; int n; long long key[MAXN]; int lcp[MAXN], p[MAXN], c[MAXN]; struct Cmp { bool operator()(int i, int j) const { return key[i] < key[j]; } }; void build_sa(string &text) { n = text.size(); for (int i = 0; i < n; i++) { p[i] = i; key[i] = text[i]; } sort(p, p + n, Cmp()); for (int k = 1;; k *= 2) { for (int i = 0; i < n; i++) { c[p[i]] = (i > 0 && key[p[i]] == key[p[i - 1]]) ? c[p[i - 1]] : i; } if (k >= n) { break; } for (int i = 0; i < n; i++) { key[i] = (long long)c[i] * (long long)(n + 111) + (long long)(i + k < n ? c[i + k] + 1 : 0); } sort(p, p + n, Cmp()); } for (int i = 0, k = 0; i < n; i++) { if (k > 0) { k--; } if (c[i] == n - 1) { lcp[c[i]] = 0; continue; } int j = p[c[i] + 1]; while (max(i, j) + k < n && text[i + k] != '{' && text[i + k] == text[j + k]) { k++; } lcp[c[i]] = k; } } int lg[MAXN]; int mn[MAXN][MAXLG]; void build_st() { for (int i = 0; i <= n; i++) { mn[i][0] = lcp[i]; if (i > 0) { lg[i] = lg[i - 1]; } if ((1 << (lg[i] + 1)) == i) { lg[i]++; } } for (int j = 1; (1 << j) <= n; j++) { for (int i = 0; i + (1 << j) <= n; i++) { mn[i][j] = min(mn[i][j - 1], mn[i + (1 << (j - 1))][j - 1]); } } } int getLCP(int i, int j) { i = c[i]; j = c[j]; if (i == j) { return n - p[i]; } j--; if (i > j) { swap(i, j); } int log = lg[j - i + 1]; return min(mn[i][log], mn[j - (1 << log) + 1][log]); } int getL(int i, int len) { int L = i; int l = 0, r = i - 1; while (l <= r) { int mid = (l + r) / 2; if (getLCP(p[mid], p[i]) >= len) { L = mid; r = mid - 1; } else { l = mid + 1; } } return L; } int getR(int i, int len) { int R = i; int l = i + 1, r = n - 1; while (l <= r) { int mid = (l + r) / 2; if (getLCP(p[i], p[mid]) >= len) { R = mid; l = mid + 1; } else { r = mid - 1; } } return R; } int cont[MAXN]; int getSolL(int i, int rq) { int solL = n - p[i] + 1; int l = 1, r = n - p[i]; while (l <= r) { int mid = (l + r) / 2; int getl = getL(i, mid); int cnt = cont[getR(i, mid)]; if (getl > 0) { cnt -= cont[getl - 1]; } if (cnt <= rq) { solL = mid; r = mid - 1; } else { l = mid + 1; } } return solL; } int getSolR(int i, int lq) { int solR = 0; int l = 1; int r = n - p[i]; while (l <= r) { int mid = (l + r) / 2; int getl = getL(i, mid); int cnt = cont[getR(i, mid)]; if (getl > 0) { cnt -= cont[getl - 1]; } if (cnt >= lq) { solR = mid; l = mid + 1; } else { r = mid - 1; } } return solR; } int L[MAXN], R[MAXN]; int main() { ios::sync_with_stdio(0); cin.tie(0); string s; cin >> s; int q; cin >> q; int sz_s = s.size(); build_sa(s); long long tot = n - p[0]; for (int i = 0; i < n; i++) { L[p[i]] = 1; R[p[i]] = n - p[i]; if (i > 0) { tot += n - p[i] - lcp[i - 1]; L[p[i]] = lcp[i - 1] + 1; } } if (q == 0) { cout << tot << '\n'; return 0; } while (q--) { int lq, rq; string qs; cin >> qs >> lq >> rq; string text = s + '{' + qs; build_sa(text); n--; build_st(); int sz_qs = qs.size(); for (int i = 0; i < n; i++) { cont[i] = 0; if (i > 0) { cont[i] = cont[i - 1]; } if (p[i] > sz_s) { cont[i]++; } } for (int i = 0; i < n; i++) { if (p[i] < sz_s) { L[p[i]] = max(L[p[i]], getSolL(i, rq)); R[p[i]] = min(R[p[i]], getSolR(i, lq)); } } } long long sol = 0ll; for (int i = 0; i < sz_s; i++) { if (L[i] <= R[i]) { sol += (long long)(R[i] - L[i] + 1); } } cout << sol << '\n'; }
2,400
CPP
#include <bits/stdc++.h> using namespace std; int f[101][101]; int gg[101] = {}; int n, ans; int main() { cin >> n; for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) cin >> f[i][j]; for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) { if (f[i][j] == 1) gg[i] = 1; if (f[i][j] == 2) gg[j] = 1; if (f[i][j] == 3) gg[i] = gg[j] = 1; } ans = 0; for (int i = 1; i <= n; i++) if (gg[i] == 0) ans++; cout << ans << endl; if (ans != 0) { for (int i = 1; i <= n; i++) if (gg[i] == 0) cout << i << " "; cout << endl; } return 0; }
900
CPP
#include <bits/stdc++.h> using namespace std; const int MAXN = 1 << 16; struct node { int d, s; } p[MAXN + 5]; vector<pair<int, int> > ans; void bfs(int st) { queue<int> q; q.push(st); while (!q.empty()) { int u = q.front(); p[u].d--; q.pop(); int v = p[u].s; ans.push_back(make_pair(u, v)); p[v].d--; p[v].s ^= u; if (p[v].d == 1) q.push(v); } } int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d%d", &p[i].d, &p[i].s); for (int i = 0; i < n; i++) if (p[i].d == 1) bfs(i); printf("%d\n", ans.size()); for (int i = 0; i < ans.size(); i++) printf("%d %d\n", ans[i].first, ans[i].second); return 0; }
1,500
CPP
n, k = map(int, input().split()) ess = list(map(int, input().split())) dp = [-1] * 101 for i in range(n): b = ess[i] if dp[b] == -1: dp[b] = 0 dp[b] += 1 ma = max(dp) c = ma // k if ma % k != 0: c += 1 ans = 0 for i in range(101): if dp[i] != -1: ans += c * k - dp[i] print(ans)
900
PYTHON3
n, m = map(int, input().split()) i = 1 while m >= i: m -= i i += 1 if i == n+1: i = 1 print(m)
800
PYTHON3
import sys n = int(input()) arr = list(map(int, input().split())) f = 0 l = n - 1 while (f < l): temp = arr[f] arr[f] = arr[l] arr[l] = temp f += 2 l -= 2 print (*arr,sep=' ')
900
PYTHON3
#https://codeforces.com/problemset/problem/1146/A #xaxxxxa #aaabaa cadena = input() longitud = len(cadena) totalA = 0 totalOtros = 0 #print(cadena) #print(longitud) for i in range(0, longitud): if(cadena[i] == "a"): #print("posicion", i, "=", cadena[i]) totalA+= 1 else: totalOtros+= 1 while(totalOtros >= totalA): totalOtros-= 1 nuevaLongitud = totalA + totalOtros print(nuevaLongitud) #print("Numero de A's:", totalA) #print("Numero de Caracteres distintos a A:", totalOtros) #print("Suma de A con Otros:", totalA + totalOtros) #print("Longitud de la cadena:", longitud)
800
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int T; cin >> T; cin.ignore(); for (int t = 0; t < T; ++t) { int a, b, c; cin >> a >> b >> c; cin.ignore(); int ct = 0; if (a > 0) { ++ct; --a; } if (b > 0) { ++ct; --b; } if (c > 0) { ++ct; --c; } vector<int> v{a, b, c}; sort(v.begin(), v.end()); if (v[0] == 0) { ct += min(v[1], 1); } else if (v[0] == 1) { ct += min(v[2], 2); } else if (v[0] == 2) { ct += 3; } else { ct += 4; } cout << ct << endl; } }
900
CPP
a, b = map(int, input().split()) while True: if not a or not b: break newa = a - (a // (2 * b)) * 2 * b newb = b - (b // (2 * a)) * 2 * a if newa == a and newb == b: break else: a = newa; b = newb print(a, b)
1,100
PYTHON3
n=int(input()) a=list(map(int,input().split())) b=list(map(int,input().split())) m1=max(b) t=0 c=[] for i in range(n): if b[i]==m1: t=i break else: c.append(b[i]) for j in range(t+1,n): c.append(b[j]) m2=max(c) if sum(a)>m1+m2: print("NO") else: print("YES")
900
PYTHON3
# # ------------------------------------------------ # ____ _ Generatered using # / ___| | | # | | __ _ __| | ___ _ __ ______ _ # | | / _` |/ _` |/ _ \ '_ \|_ / _` | # | |__| (_| | (_| | __/ | | |/ / (_| | # \____\____|\____|\___|_| |_/___\____| # # GNU Affero General Public License v3.0 # ------------------------------------------------ # Author : prophet # Created : 2020-08-12 11:06:11.213692 # UUID : TP4GAI9PVycl6MzC # ------------------------------------------------ # production = True import sys, math, collections, bisect, itertools, heapq, decimal, random, copy, re def input(f = 0, m = 0): if m > 0: return [input(f) for i in range(m)] else: l = sys.stdin.readline()[:-1] if f >= 10: u = False f = int(str(f)[-1]) else: u = True if f == 0: p = [l] elif f == 1: p = list(map(int, l.split())) elif f == 2: p = list(map(float, l.split())) elif f == 3: p = list(l) elif f == 4: p = list(map(int, list(l))) elif f == 5: p = l.split() return p if u else p[0] def out(l, f = 0, n = True): if f == 0: p = str(l) elif f == 1: p = " ".join(map(str, l)) elif f == 2: p = "\n".join(map(str, l)) elif f == 3: p = "".join(map(str, l)) print(p, end = "\n" if n else "") def log(*args): if not production: print("$$$", end = "") print(*args) enu = enumerate ter = lambda a, b, c: b if a else c ceil = lambda a, b: -(-a // b) def mapl(i, f = 0): if f == 0: return list(map(int, i)) elif f == 1: return list(map(str, i)) elif f == 2: return list(map(list, i)) # # >>>>>>>>>>>>>>> START OF SOLUTION <<<<<<<<<<<<<< # def col(n, x, s): out([x, s], 1) f = 0 for i in range(1, n + 1): if i == s: continue f = i out([x, i], 1) return f def solve(): n, m, x, y = input(1) s = col(m, x, y) for i in range(1, n + 1): if i == x: continue s = col(m, i, s) log() return solve() # # >>>>>>>>>>>>>>>> END OF SOLUTION <<<<<<<<<<<<<<< #
1,100
PYTHON3
n = int(input()) entrada = list(map(int, input().split())) contratados = 0 crimes = 0 for i in entrada: if i == -1: if contratados > 0: contratados -= 1 else: crimes += 1 else: contratados += i print(crimes)
800
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { long h = 0, t = 0; cin >> h >> t; bool isLost = false; while (1) { if (h >= 2 and t >= 2) { h -= 2; t -= 2; } else if (h >= 1 and t >= 12) { h -= 1; t -= 12; } else if (t >= 22) t -= 22; else { isLost = true; break; } if (t >= 22) t -= 22; else if (t >= 12 and h >= 1) { h -= 1; t -= 12; } else if (t >= 2 and h >= 2) { h -= 2; t -= 2; } else { isLost = false; break; } } cout << ((isLost) ? ("Hanako") : ("Ciel")); return 0; }
1,200
CPP
n = int(input()) ls = list(map(int, input().split())) ls.sort(reverse=True) for i in range(0, n + 1): if sum(ls[:i]) > sum(ls[i:]): print(i) break;
900
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int n, k, i, sum = 0, c = 0; vector<int> ind; cin >> n >> k; int a[n], b[n]; for (i = 0; i < n; i++) { cin >> a[i]; b[i] = a[i]; } sort(a, a + n); for (i = 0; i < n; i++) { if (sum + a[i] <= k) { sum += a[i]; c++; ind.push_back(a[i]); } } cout << c << endl; if (!c) return 0; for (i = 0; i < n; i++) for (int j = 0; j < n; j++) { if (b[i] == ind[j]) { cout << i + 1 << " "; ind[j] = -1; break; } } return 0; }
1,000
CPP
if __name__ == '__main__': nums = input().split() n = int(nums[0]) v = int(nums[1]) if n < v+2: print(n - 1) else: print(int(v-1 + (n-v)*(n-v+1)/2))
900
PYTHON3
n = int(input()) a = [int(x) for x in str(n)] l, f=0, 0 for i in a: if i==4 or i==7: l+=1 k = [int(i) for i in str(l)] for j in k: if j!=4: if j!=7: f=1 print("YES" if f==0 else "NO")
800
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { long long int n, i, k, j = 0; cin >> n; long long int a[n], b[n]; for (i = 0; i <= n - 1; i++) { cin >> a[i]; } sort(a, a + n); for (i = 0; i <= n - 1; i++) { if (a[i] == a[i + 1] && ((i + 1) <= (n - 1))) { b[j] = a[i]; j++; while (a[i] == a[i + 1] && ((i + 1) <= (n - 1))) i++; } } if (a[n - 2] != a[n - 1]) { for (i = n - 1; i >= 0; i--) { b[j] = a[i]; j++; while (a[i] == a[i - 1] && (i - 1) >= 0) { i--; } } } else { i = n - 1; while (a[i] == a[i - 1]) i--; i--; for (; i >= 0; i--) { b[j] = a[i]; j++; while (a[i] == a[i - 1] && (i - 1) >= 0) { i--; } } } cout << j << endl; for (k = 0; k <= j - 1; k++) cout << b[k] << " "; return 0; }
1,100
CPP
n = int(input()) s = list(str(input())) #print(s) t = list(reversed(s)) #print(t) X = [[] for _ in range(26)] Y = [[] for _ in range(26)] for i, c in enumerate(s): j = ord(c)-ord('a') X[j].append(i) for i, c in enumerate(t): j = ord(c)-ord('a') Y[j].append(i) #print(X) #print(Y) A = [-1]*n for i in range(26): for j, k in zip(X[i], Y[i]): A[j] = k #print(A) class BIT: def __init__(self, n): self.n = n self.bit = [0]*(self.n+1) # 1-indexed def init(self, init_val): for i, v in enumerate(init_val): self.add(i, v) def add(self, i, x): # i: 0-indexed i += 1 # to 1-indexed while i <= self.n: self.bit[i] += x i += (i & -i) def sum(self, i, j): # return sum of [i, j) # i, j: 0-indexed return self._sum(j) - self._sum(i) def _sum(self, i): # return sum of [0, i) # i: 0-indexed res = 0 while i > 0: res += self.bit[i] i -= i & (-i) return res def lower_bound(self, x): s = 0 pos = 0 depth = self.n.bit_length() v = 1 << depth for i in range(depth, -1, -1): k = pos + v if k <= self.n and s + self.bit[k] < x: s += self.bit[k] pos += v v >>= 1 return pos bit = BIT(max(A)+1) # 0-max(A) ans = 0 for a in A: ans += bit.sum(a+1, bit.n) bit.add(a, 1) print(ans)
1,900
PYTHON3
#include <bits/stdc++.h> using namespace std; const int N = 1e3 + 5; int n, m, S, T, a, b, vis[2][N], dis[2][N], e[N][N], res; set<int> g[N]; set<pair<int, int>> edges; void bfs(int v, int t) { queue<int> Q; Q.push(v); vis[t][v] = 1; while (!Q.empty()) { int u = Q.front(); Q.pop(); for (auto i : g[u]) { if (vis[t][i]) continue; vis[t][i] = 1; dis[t][i] = dis[t][u] + 1; Q.push(i); } } } int main() { cin >> n >> m >> S >> T; for (int i = 0; i < m; i++) { cin >> a >> b; g[a].insert(b); g[b].insert(a); e[a][b] = e[b][a] = 1; } bfs(S, 0); bfs(T, 1); for (int i = 1; i < n; i++) for (int j = i + 1; j <= n; j++) if (!e[i][j] && dis[0][i] + dis[1][j] + 1 >= dis[0][T] && dis[0][j] + dis[1][i] + 1 >= dis[0][T]) res++; cout << res; }
1,600
CPP
import math from sys import stdin from collections import Counter,defaultdict,deque input=stdin.readline mod=pow(10,9)+7 def solve(): n=int(input()) l1=list(map(int,input().split())) l2=list(map(int,input().split())) d1=dict() d2=dict() g=defaultdict(int) for i in range(n): d1[l1[i]]=i d2[l2[i]]=i for i in range(n): v=d1[l1[i]]-d2[l1[i]] if(v<0): v=v+n g[v]+=1 x=max(g.values()) print(x) solve()
1,400
PYTHON3
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; int m; cin >> m; int a; vector<pair<int, int> > diag(n + m - 1); for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { cin >> a; if (a == 0) { diag[i + j].first += 1; } else { diag[i + j].second += 1; } } } int i = 0, j = n + m - 2; int ans = 0; while (i < j) { int tot = diag[i].first + diag[i].second + diag[j].first + diag[j].second; int changes = tot - max(diag[i].first + diag[j].first, diag[i].second + diag[j].second); ans += changes; i++; j--; } cout << ans << "\n"; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while (t--) solve(); return 0; }
1,500
CPP
n, m, k = map(int, input().split()) h = list(map(int, input().split())) check = [0] * (n+1) for i in h: check[i] = 1 bone = 1 for _ in range(k): if check[bone]: break u, v = map(int, input().split()) if bone == u: bone = v elif bone == v: bone = u print(bone)
1,300
PYTHON3
a = input().lower() d = "a", "o", "y", "e", "u", "i" for i in a: if i not in d: print('.' + i, end='')
1,000
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { long long n, t, ans = 0, i, a, b, m, x, y; cin >> t; while (t > 0) { cin >> n; vector<int> res; long long es = 0, os = 0; if ((n / 2) % 2 == 0) { cout << "YES" << endl; for (i = 0; i < n / 2; i++) { res.push_back(2 * (i + 1)); es += 2 * (i + 1); } for (i = 0; i < n / 2; i++) { res.push_back(2 * (i + 1) - 1); os += 2 * (i + 1) - 1; } res[n - 1] += es - os; for (i = 0; i < n; i++) cout << res[i] << " "; cout << endl; } else cout << "NO" << endl; t--; } }
800
CPP
#include <bits/stdc++.h> using namespace std; const int INF = 0x3fffffff; const int SINF = 0x7fffffff; const long long LINF = 0x3fffffffffffffff; const long long SLINF = 0x7fffffffffffffff; const int MAXN = 200007; struct pT { int x, y, z; } pt[MAXN], pm[MAXN], que[MAXN]; struct aT { void setd(int _tp, int _id, int _x, int _y, int _z) { tp = _tp, id = _id, x = _x, y = _y, z = _z; } bool operator<(const aT &a) const { return (x ^ a.x) ? (x < a.x) : (tp < a.tp); } int tp, id, x, y, z; } ar[8][MAXN]; int ka[8]; class ftT { public: void clear() { memset(data, 0x3f3f3f3f, sizeof(data)); } void upd(int p, int x) { for (; p < MAXN; p += p & -p) data[p] = (((data[p]) < (x)) ? (data[p]) : (x)); } int query(int p) { int ans = INF; for (; p; p ^= p & -p) ans = (((ans) < (data[p])) ? (ans) : (data[p])); return ans; } private: int data[MAXN]; } ft; int n, m, q, X, Y, Z; int XL, XR, YL, YR, ZL, ZR; int ans[MAXN]; void init(); void input(); void work(); int gettp(const pT &p); void add(const pT pt[], int n, int ntp); void check(aT ar[], int n, int st); int main() { init(); input(); work(); } void init() { ios::sync_with_stdio(false); } void input() { scanf("%d%d%d%d%d%d", &X, &Y, &Z, &m, &n, &q); for (int i = 1; i <= m; ++i) scanf("%d%d%d", &pm[i].x, &pm[i].y, &pm[i].z); for (int i = 1; i <= n; ++i) scanf("%d%d%d", &pt[i].x, &pt[i].y, &pt[i].z); for (int i = 1; i <= q; ++i) scanf("%d%d%d", &que[i].x, &que[i].y, &que[i].z); } void work() { ++X, ++Y, ++Z; XL = YL = ZL = INF, XR = YR = ZR = 0; for (int i = 1; i <= m; ++i) { XL = (((XL) < (pm[i].x)) ? (XL) : (pm[i].x)); XR = (((XR) > (pm[i].x)) ? (XR) : (pm[i].x)); YL = (((YL) < (pm[i].y)) ? (YL) : (pm[i].y)); YR = (((YR) > (pm[i].y)) ? (YR) : (pm[i].y)); ZL = (((ZL) < (pm[i].z)) ? (ZL) : (pm[i].z)); ZR = (((ZR) > (pm[i].z)) ? (ZR) : (pm[i].z)); } add(pt, n, 0); add(que, q, 1); for (int i = 0; i < 8; ++i) check(ar[i], ka[i], i); printf("CORRECT\n"); for (int i = 1; i <= q; ++i) printf(ans[i] == 0 ? "UNKNOWN\n" : ans[i] == 1 ? "CLOSED\n" : "OPEN\n"); } int gettp(const pT &pt) { auto cmp = [](const int x, int l, int r) { return (x > r) ? 0 : (x < l) ? 1 : 2; }; return cmp(pt.x, XL, XR) * 9 + cmp(pt.y, YL, YR) * 3 + cmp(pt.z, ZL, ZR); } void add(const pT pt[], int n, int ntp) { int nt, nx, ny, nz; for (int i = 1; i <= n; ++i) { nt = gettp(pt[i]); nz = nt % 3, ny = nt / 3 % 3, nx = nt / 9; if (nx == 2 && ny == 2 && nz == 2) { if (!ntp) { printf("INCORRECT\n"); exit(0); } else { ans[i] = 2; continue; } } for (int cx = 0; cx < 2; ++cx) { for (int cy = 0; cy < 2; ++cy) { for (int cz = 0; cz < 2; ++cz) { if (((cx + 1) & (nx + 1)) && ((cy + 1) & (ny + 1)) && ((cz + 1) & (nz + 1))) { ar[(cx << 2) | (cy << 1) | cz][++ka[(cx << 2) | (cy << 1) | cz]] .setd(ntp, i, pt[i].x, pt[i].y, pt[i].z); } } } } } } void check(aT ar[], int n, int st) { if (st & 4) for (int i = 1; i <= n; ++i) ar[i].x = X - ar[i].x; if (st & 2) for (int i = 1; i <= n; ++i) ar[i].y = Y - ar[i].y; if (st & 1) for (int i = 1; i <= n; ++i) ar[i].z = Z - ar[i].z; sort(ar + 1, ar + 1 + n); ft.clear(); for (int i = 1; i <= n; ++i) { if (!ar[i].tp) ft.upd(ar[i].y, ar[i].z); else if (ft.query(ar[i].y) <= ar[i].z) ans[ar[i].id] = 1; } }
2,700
CPP
a = input() print(a[0].capitalize()+a[1:len(a)])
800
PYTHON3
#include <bits/stdc++.h> using namespace std; int n, cnt, maxx, x, y; int k[200005], d[200005], a[200005], dep[200005], v[200005]; int vet[400005], nxt[400005], head[200005]; vector<int> p[200005]; void add(int x, int y) { vet[++cnt] = y; nxt[cnt] = head[x]; head[x] = cnt; } void dfs(int u, int pre) { dep[u] = dep[pre] + 1; int res = 0; for (int i = 0; i < p[d[u]].size(); i++) { int t = p[d[u]][i]; v[t]++; if (v[t] == dep[u] - 1) res = max(res, t); if (v[t] == dep[u]) k[u] = max(k[u], t); } res = max(res, max(k[u], k[pre])); a[u] = res; for (int e = head[u]; e; e = nxt[e]) if (vet[e] != pre) dfs(vet[e], u); for (int i = 0; i < p[d[u]].size(); i++) v[p[d[u]][i]]--; } int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &d[i]), maxx = max(maxx, d[i]); ; for (int i = 1; i < n; i++) { scanf("%d%d", &x, &y); add(x, y), add(y, x); } for (int i = 1; i <= maxx; i++) for (int j = i; j <= maxx; j += i) p[j].push_back(i); dfs(1, 0); for (int i = 1; i <= n; i++) printf("%d ", a[i]); puts(""); return 0; }
2,000
CPP
#include <bits/stdc++.h> using namespace std; const int N = 2e3 + 3; long long a, b, T; int main() { ios_base::sync_with_stdio(0), cin.tie(0); cin >> T; while (T--) { cin >> a >> b; cout << (a ^ b ? (abs(a - b) - 1) / 10 + 1 : 0) << endl; } }
800
CPP
#include <bits/stdc++.h> using namespace std; const int mo = 1000000007; const int N = 205; const int dx[] = {-2, -2, -1, -1, 1, 1, 2, 2}; const int dy[] = {-1, 1, -2, 2, -2, 2, -1, 1}; int vis[N][N], n; int dis[N][N], cnt[N]; pair<int, int> q[N * N]; long long T; int main() { scanf("%lld%d", &T, &n); for (int i = (int)(1); i <= (int)(n); i++) { int x, y; scanf("%d%d", &x, &y); vis[x + 100][y + 100] = 1; } int h = 0, t = 1; cnt[1] = 1; q[1] = pair<int, int>(100, 100); vis[100][100] = 1; while (h != t) { int x = q[++h].first, y = q[h].second; if (dis[x][y] == min(40ll, T)) continue; for (int d = (int)(0); d <= (int)(7); d++) { int nx = x + dx[d], ny = y + dy[d]; if (vis[nx][ny]) continue; vis[nx][ny] = 1; dis[nx][ny] = dis[x][y] + 1; ++cnt[dis[nx][ny]]; q[++t] = pair<int, int>(nx, ny); } } int ans = t; if (T > 40) { int delta = cnt[40] - cnt[39]; ans = (ans + 1ll * (cnt[40] + cnt[40] + 1ll * (T - 39) % mo * delta % mo) * ((T - 40) % mo) % mo * (mo + 1) / 2 % mo) % mo; } printf("%d\n", ans); }
3,000
CPP
T = int(input()) result = [] for _ in range(T): val = input() s = 0 flag = False total = 0 for i in range(len(val)): if val[i] == '1' and flag: total += s s = 0 flag = False if val[i] == '0' and flag: s += 1 if val[i] == '1' and flag == False: flag = True result.append(total) for el in result: print(el)
800
PYTHON3
print(input() * 0 + str((lambda a: sum([a[i] * (i + 2) for i in range(len(a))]) - a[-1])(sorted(tuple(map(int, input().split()))))))
1,200
PYTHON3
#include <bits/stdc++.h> using namespace std; long long s, x; int main() { cin >> s >> x; s -= x; if (s < 0 || s % 2 != 0) { cout << 0 << endl; return 0; } s /= 2; if (s & x) { cout << 0 << endl; return 0; } long long bit = 0, result = 0; if (!s) result -= 2; while (x > 0) { bit += x & 1; x >>= 1; } result += 1LL << bit; cout << result << endl; return 0; }
1,700
CPP
#include <bits/stdc++.h> using namespace std; template <class T> inline T bigmod(T p, T e, T M) { long long ret = 1LL; for (; e > 0; e >>= 1) { if (e & 1) ret = (ret * p) % M; p = (p * p) % M; } return (T)ret; } template <class T> inline T bpow(T p, T e) { long long ret = 1LL; for (; e > 0; e >>= 1) { if (e & 1) ret = (ret * p); p = p * p; } return (T)ret; } template <class T> inline T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); } template <class T> inline T modinverse(T a, T M) { return bigmod(a, M - 2, M); } int ts, kk = 1; char s[100005]; stack<pair<int, int> > st; char ls[] = {"()[]"}; int p[100005]; int q[100005]; int fr[100005]; int main() { int t, i, j, k; scanf("%s", s); int rs = 0, id; int cnt = 0; for (i = 0; s[i] != '\0'; i++) { p[i] = 0; q[i] = i + 1; for (k = 0; k < 4; k++) if (s[i] == ls[k]) break; if (k & 1) { if (!st.empty() && st.top().first == k - 1) { j = st.top().second; st.pop(); if (k == 3) cnt++; q[i] = ((j > 0) ? q[j - 1] : j); j = q[i]; p[i] = cnt - ((j > 0) ? fr[j - 1] : 0); } else { while (!st.empty()) st.pop(); } } else { st.push(pair<int, int>(k, i)); } fr[i] = cnt; if (p[i] > rs) { rs = p[i]; id = i; } } printf("%d\n", rs); if (rs) { s[id + 1] = 0; printf("%s\n", s + q[id]); } return 0; }
1,700
CPP
#include <bits/stdc++.h> const int N = 1e5 + 7; using namespace std; long long a[N]; int main() { int i, j, k, n, flag = 0, zero = 0, x; long long sum = 0; scanf("%d", &n); for (i = 0; i < n; i++) scanf("%lld", &a[i]), sum += a[i]; sort(a, a + n); for (i = 0; i < n; i++) { if (a[i] == 0) zero++; if (i > 0 && a[i] == a[i - 1]) flag++, x = a[i]; } if (zero > 1 || flag > 1) { printf("cslnb"); } else { if (flag == 0) { long long dx = sum - (0 + n - 1) * n / 2; if (dx % 2 == 0) printf("cslnb"); else printf("sjfnb"); } else { int pan = 0; for (i = 0; i < n; i++) if (a[i] == x - 1) pan = 1; long long dx = sum - (0 + n - 1) * n / 2; if (pan == 0) { if (dx % 2 == 0) printf("cslnb"); else printf("sjfnb"); } else { printf("cslnb"); } } } }
1,800
CPP
#include <bits/stdc++.h> using namespace std; const int MaxN = 1 << 18; int N, M; double A, B, Y1[MaxN], Y2[MaxN], L[MaxN]; inline double FindDist(double X1, double Y1, double X2, double Y2) { return sqrt((X2 - X1) * (X2 - X1) + (Y2 - Y1) * (Y2 - Y1)); } inline double Dist(int idx, int idy) { return FindDist(0, 0, A, Y1[idx]) + FindDist(A, Y1[idx], B, Y2[idy]) + L[idy]; } int main(void) { cin.sync_with_stdio(0); cin >> N >> M >> A >> B; for (int i = 0; i < N; i++) cin >> Y1[i]; for (int i = 0; i < M; i++) cin >> Y2[i]; for (int i = 0; i < M; i++) cin >> L[i]; int idxA = 0, idxB = 0; for (int i = 0; i < M; i++) { int L = 0, R = N - 1; while (R - L > 2) { int M1 = (2 * L + R) / 3, M2 = (L + 2 * R) / 3; double Dist1 = Dist(M1, i), Dist2 = Dist(M2, i); if (Dist1 < Dist2) R = M2; else L = M1; } for (int j = L; j <= R; j++) if (Dist(j, i) < Dist(idxA, idxB)) { idxA = j; idxB = i; } } cout << idxA + 1 << " " << idxB + 1 << endl; return 0; }
1,900
CPP
#include <bits/stdc++.h> using namespace std; struct Node { Node() {} Node(int a, char b) { to = a; c = b; } int to; char c; }; vector<Node> v[100005]; int n, m; int vis[100005]; vector<int> ans1, ans2; vector<int> p[3]; bool dfs(int i, int k, char c) { if (vis[i]) { return vis[i] == k; } vis[i] = k; p[k].push_back(i); for (int j = 0; j < v[i].size(); j++) { if (dfs(v[i][j].to, v[i][j].c == c ? k : k ^ 3, c) == false) return false; } return true; } int solve(char ch, vector<int> &ans) { memset(vis, 0, sizeof(vis)); for (int i = 1; i <= n; i++) { if (vis[i] == 0) { p[1].clear(); p[2].clear(); if (dfs(i, 1, ch) == false) { return 0; } if (p[1].size() < p[2].size()) ans.insert(ans.end(), p[1].begin(), p[1].end()); else ans.insert(ans.end(), p[2].begin(), p[2].end()); } } return 1; } void print(vector<int> &p) { cout << p.size() << endl; if (p.size()) printf("%d", p[0]); for (int i = 1; i < p.size(); i++) printf(" %d", p[i]); } int main() { while (cin >> n >> m) { int a, b; char c; ans1.clear(); ans2.clear(); for (int i = 1; i <= n; i++) v[i].clear(); for (int i = 1; i <= m; i++) { scanf("%d %d %c", &a, &b, &c); v[a].push_back(Node(b, c)); v[b].push_back(Node(a, c)); } int k1 = n, k2 = n; if (solve('B', ans1)) k1 = ans1.size(); if (solve('R', ans2)) k2 = ans2.size(); if (k2 < k1) { print(ans2); } else if (k1 != n && k1 <= k2) { print(ans1); } else cout << -1 << endl; } return 0; }
2,200
CPP
n=int(input()) a=list(map(int,input().split(" "))) a.sort() i=0 count=0 while(i<n): if a[i]<0: d=abs(a[i]+1) # print(d) if i==n-1: count+=d+2 elif a[i+1]<0: e=abs(a[i+1]+1) # print(e) count+=(d+e) elif a[i+1]>=0: e=abs(a[i+1]+1) count+=(d+e) # print(count) i+=2 elif a[i]>=0: e=abs(a[i]-1) count+=e # print(count) i+=1 print(count)
900
PYTHON3
#include <bits/stdc++.h> using namespace std; long long vis[100004]; int main() { long long t; cin >> t; { while (t--) { int n, m; cin >> n >> m; vector<int> op; int i; for (i = 0; i < n; i++) { int x; cin >> x; if (!vis[x]) op.push_back(x); vis[x] = 1; } sort(op.begin(), op.end()); long long ans = 0; long long how = 0; for (i = op.size() - 1; i >= 0; i--) { vis[op[i]] = 0; if (op[i] - how <= 0) continue; ans++; how += m; } cout << ans << endl; } } return 0; }
1,300
CPP
def getDivisors(n) : divisor=[] i = 1 while i <= n : if (n % i==0) : divisor.append(i), i = i + 1 return divisor n = int(input()) divisors= input().split(" ") for i in range(n): divisors[i]=int(divisors[i]) divisors.sort() y = max(divisors) ydiv = getDivisors(y) for i in ydiv: divisors.remove(i) x = max(divisors) print(x, y)
1,100
PYTHON3
# -*- coding: utf-8 -*- """ Created on Fri May 8 10:09:02 2020 @author: Harshal """ n,k=map(int,input().split()) arr=list(map(int,input().split())) arr.sort(reverse=True) kthscore=arr[k-1] ans=0 for i in arr: if i>=kthscore and i>0: ans+=1 print(ans)
800
PYTHON3
T = int(input()) for i in range(T): n = int(input()) ans = 0 for i in range(1, n//2+1): ans += 8*i*i print(ans)
1,000
PYTHON3
#include <bits/stdc++.h> using namespace std; long long t, n, k, d1, d2; bool solve(long long t1, long long t2, long long t3) { long long sum = t1 + t2 + t3; if (k < sum || (k - sum) % 3) return false; long long t = n - k - (3 * max(max(t1, t2), t3) - sum); if (t < 0 || t % 3) return false; return true; } int main() { ios_base::sync_with_stdio(0); cin >> t; while (t--) { cin >> n >> k >> d1 >> d2; bool res = false; long long mx = max(d1, d2); res = res || solve(d1, 0, d2); res = res || solve(d1 + d2, d2, 0); res = res || solve(0, d1, d1 + d2); res = res || solve(mx - d1, mx, mx - d2); if (res) cout << "yes\n"; else cout << "no\n"; } return 0; }
1,700
CPP
def stringmaker(k,d,n): a='' for i in d: d[i]=d[i]//n a+=i*d[i] return a def main(): d=dict() n=int(input()) st=input() if len(st)%n!=0: print(-1) return 0 else: k= len(st)//n for i in st: d[i]= d.get(i,0)+1 for i in d: if d[i]%n!=0: print(-1) return 0 print(stringmaker(k,d,n)*n) return 0 if __name__ == '__main__': main()
1,000
PYTHON3
#include <bits/stdc++.h> using namespace std; int x[5010], a[5010], b[5010], c[5010], d[5010]; int nex[5010]; long long dis(int i, int j) { if (i > j) return (long long)abs(x[i] - x[j]) + c[i] + b[j]; else return (long long)abs(x[i] - x[j]) + d[i] + a[j]; } int main() { int n, s, t; while (~scanf("%d%d%d", &n, &s, &t)) { memset(nex, -1, sizeof(nex)); for (int i = 1; i <= n; i++) scanf("%d", &x[i]); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); for (int i = 1; i <= n; i++) scanf("%d", &b[i]); for (int i = 1; i <= n; i++) scanf("%d", &c[i]); for (int i = 1; i <= n; i++) scanf("%d", &d[i]); nex[s] = t; for (int i = 1; i <= n; i++) { if (i == s || i == t) continue; long long maxx = (long long)1e18; int k; for (int j = s; nex[j] + 1; j = nex[j]) { long long tmp = dis(j, i) + dis(i, nex[j]) - dis(j, nex[j]); if (tmp < maxx) { maxx = tmp; k = j; } } nex[i] = nex[k]; nex[k] = i; } long long ans = 0; for (int i = s; nex[i] + 1; i = nex[i]) ans += dis(i, nex[i]); printf("%I64d\n", ans); } return 0; }
2,500
CPP
a,b=input().split() b=int(b) s=input() while b: s=s.replace('BG','GB') b-=1 print(s)
800
PYTHON3
a, m = list(map(int, input().split())) for i in range(30): if (a * (2 ** i) % m == 0): print("Yes") exit(0) print("No")
1,400
PYTHON3
#include <bits/stdc++.h> using namespace std; void flash() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } void solve() { long long n; cin >> n; long long a[n + 10]; for (long long i = 0; i < n; i++) { cin >> a[i]; } long long ans = 0; sort(a, a + n); long long j = n - 1; long long i = 0; cout << (n - 1) / 2 << "\n"; for (long long k = 0; k < n; k++) { if (k % 2) { cout << a[i++] << " "; } else { cout << a[j--] << " "; } } } int32_t main() { flash(); long long t; t = 1; while (t--) { solve(); } return 0; }
1,000
CPP