solution
stringlengths
10
983k
difficulty
int64
0
25
language
stringclasses
2 values
#include <bits/stdc++.h> using namespace std; int main() { int n, m, a, b, x, y, z; cin >> n >> m >> a >> b; if (a > (b / m)) { x = n / m; y = n % m; z = x * b; if ((y * a) > b) cout << z + b; else { cout << z + (y * a); } } else { cout << a * n; } }
7
CPP
#include <bits/stdc++.h> using namespace std; double dis[100005]; double f[100005]; int main() { double r; long long m; long long tmp; double s; while (scanf("%I64d%lf", &m, &r) != EOF) { f[1] = 0; double ans = 0; long long day = m * m; double s = sqrt(2 * r * r); dis[1] = 2 * r; dis[2] = 2 * r + s; dis[3] = 2 * r + 2 * s; for (int i = 4; i <= m; i++) { dis[i] = dis[i - 1] + 2 * r; } for (int i = 1; i <= m; i++) { f[1] += dis[i]; } for (int i = 2; i <= m / 2; i++) { f[i] = f[i - 1] - dis[m - i + 2] + dis[i]; } if (m & 1) { for (int i = 2; i <= (m + 1) / 2; i++) ans += dis[i]; ans *= 2; ans += dis[1]; } for (int i = 1; i <= m / 2; i++) { ans += f[i] * 2; } printf("%.10lf\n", ans / day); } return 0; }
8
CPP
string = input() vowel = {'a', 'o', 'y', 'e', 'u', 'i'} for x in string.strip(): if x.lower() in vowel: print('', end='') else: print('.' + x.lower(), end='')
7
PYTHON3
#include <iostream> #include <map> #include <vector> using namespace std; void solve() { int N; while(cin >> N, N) { vector<int> Vec(N); for(int i = 0; i < N; ++i) { cin >> Vec[i]; } int count = 0; bool Flag = true; while(Flag) { ++count; map<int, int> Map; Flag = false; for(int i = 0; i < N; ++i) { ++Map[Vec[i]]; } vector<int> VecBuf(N); for(int i = 0; i < N; ++i) { VecBuf[i] = Map[Vec[i]]; } for(int i = 0; i < N; ++i) { if(Vec[i] != VecBuf[i]) { Flag = true; for(int j = 0; j < N; ++j) { Vec[j] = VecBuf[j]; } goto NEXT; } } NEXT: ; } cout << --count << endl; for(int i = 0; i < N - 1; ++i) { cout << Vec[i] << " "; } cout << Vec[N - 1] << endl; } } int main() { solve(); return(0); }
0
CPP
a,b,xx,yy=[int(i) for i in input().split()] x,y=[int(i) for i in input().split()] xx-=a yy-=b if xx%(2*x)==0 and yy%(2*y)==0 or (xx+x)%(2*x)==0 and (y+yy)%(2*y)==0: print("YES") else: print("NO")
7
PYTHON3
# Anuneet Anand T = int(input()) Y = [] while T: n,x = map(int,input().split()) A = list(map(int,input().split())) A.sort() S = sum(A) f = 0 for i in range(n): if S/(n-i)>=x and f==0: Y.append(n-i) f = 1 break S = S - A[i] if f == 0: Y.append(0) T = T - 1 for i in Y: print(i)
8
PYTHON3
#include <bits/stdc++.h> #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops") #pragma GCC optimize("no-stack-protector,fast-math") using namespace std; const long long N = 3e5 + 100, OO = 1e9 + 7, T = 10, M = 1e9 + 7, P = 6151, SQ = 300, lg = 30; long long fac[N], inv[N]; long long pw(long long x, long long y) { if (y == 0) return 1; long long cnt = pw(x, y / 2); cnt = (cnt * cnt) % M; cnt = (cnt * (y % 2 == 1 ? x : 1)) % M; return cnt; } void prepro() { fac[0] = 1; for (long long i = 1; i <= N - lg; i++) fac[i] = (fac[i - 1] * i) % M; inv[N - lg] = pw(fac[N - lg], M - 2); for (long long i = N - lg - 1; i > -1; i--) inv[i] = (inv[i + 1] * (i + 1)) % M; } long long c(long long x, long long y) { return ((fac[x] * inv[y] % M) * inv[x - y]) % M; } long long get(long long n, long long k) { if (n < k) return 0; long long cnt = inv[k], sum = 0; for (long long i = 0; i <= k; i++) { if (i % 2 == 0) sum = (sum + c(k, i) * pw(k - i, n)) % M; else sum = (sum - c(k, i) * pw(k - i, n)) % M; } sum = (sum + M) % M; cnt = (cnt * sum) % M; return cnt; } int32_t main() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); prepro(); long long n, k; cin >> n >> k; long long sum = 0; for (long long i = 0; i < n; i++) { long long x; cin >> x; sum = (sum + x) % M; } long long ans = (get(n, k) + ((n - 1) * get(n - 1, k)) % M) % M; ans = (ans * sum) % M; cout << ans << endl; return 0; }
13
CPP
a=int(input()) b=[[i,i]for i in range(a)] for i in range(a): c=input().split() b[i][0]=int(c[0]) b[i][1]=int(c[1]) s=0 for i in range(a): for j in range(a): if b[i][0]==b[j][1] and i!=j: s+=1 print(s)
7
PYTHON3
#include<iostream> #include<cstdio> #include<algorithm> #include<map> #include<vector> #include<cstring> #include<cmath> using namespace std; inline int read(){ int 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(int a){ if(a>=10)write(a/10); putchar('0'+a%10); } inline void writeln(int a){ write(a); puts(""); } const int N=200005; int sum,n,a[N],dp[N][2],b[N],c[N]; int main(){ n=read(); for(int i=1;i<=n;i++){ a[i]=read(); int t=log(a[i])/log(2); if((1<<t)==a[i]){ dp[i][0]=dp[i][1]=max(dp[i-1][0]+min(b[i-1],t),dp[i-1][1]+min(c[i-1],t)); b[i]=c[i]=t; sum+=t; }else{b[i]=t+1; c[i]=t; dp[i][0]=max(dp[i-1][0]+min(b[i-1],t),dp[i-1][1]+min(c[i-1],t)); dp[i][1]=max(dp[i-1][0]+min(b[i-1],t+1),dp[i-1][1]+min(c[i-1],t+1)); sum+=t+1; } } writeln(sum-max(dp[n][0],dp[n][1])); }
0
CPP
#include <iostream> using namespace std; const int kMaxN = 2002; int a[kMaxN * 3]; int f[kMaxN * 3][kMaxN * 3], p[kMaxN][kMaxN]; int n, ans; void T0(int i, int j, int g) { // 用gη»„ηš„ε‘ζ›Ώζ’i g *= 3; f[j][g] = max(f[j][g], f[i][j] + (a[i] == a[g + 1] && a[i] == a[g + 2])); f[j][g + 1] = max(f[j][g + 1], f[i][j] + (a[i] == a[g] && a[i] == a[g + 2])); f[j][g + 2] = max(f[j][g + 2], f[i][j] + (a[i] == a[g] && a[i] == a[g + 1])); } void T1(int i, int j, int g) { // 用gη»„ηš„η‰Œζ›Ώζ’j g *= 3; f[i][g] = max(f[i][g], f[i][j] + (a[j] == a[g + 1] && a[j] == a[g + 2])); f[i][g + 1] = max(f[i][g + 1], f[i][j] + (a[j] == a[g] && a[j] == a[g + 2])); f[i][g + 2] = max(f[i][g + 2], f[i][j] + (a[j] == a[g] && a[j] == a[g + 1])); } void T2(int i, int j, int g) { // 用gη»„ηš„η‰Œζ›Ώζ’iε’Œj g *= 3; f[g][g + 1] = max(f[g][g + 1], f[i][j] + (a[i] == a[j] && a[i] == a[g + 2])); f[g][g + 2] = max(f[g][g + 2], f[i][j] + (a[i] == a[j] && a[i] == a[g + 1])); f[g + 1][g + 2] = max(f[g + 1][g + 2], f[i][j] + (a[i] == a[j] && a[i] == a[g])); } void P() { // 钄倄理 int m = 2; for (int i = 3; i < 3 * n; i += 3) { // ζžšδΈΎη»„ if (a[i] == a[i + 1] && a[i] == a[i + 2]) { // ζœ‰δΈ€η»„η›ΈεŒη›΄ζŽ₯ζΆˆι™€ ans++; } else { a[++m] = a[i], a[++m] = a[i + 1], a[++m] = a[i + 2]; } } a[++m] = a[3 * n]; // ζœ€εŽδΈ€η»„ n = m / 3; for (int i = n; i >= 1; i--) { // ι’„ε€„η†ζ―η»„δΉ‹εŽζ―η§ζ•°ε­—η¬¬δΈ€ζ¬‘ε‡ΊηŽ°ηš„η»„ for (int j = 1; j <= n; j++) { p[i][j] = p[i + 1][j]; } p[i][a[i * 3]] = p[i][a[i * 3 + 1]] = p[i][a[i * 3 + 2]] = i; } } int main() { cin >> n; for (int i = 1; i <= 3 * n; i++) { cin >> a[i]; } P(); for (int j = 1; j < 3 * n; j++) { for (int i = 1; i < j; i++) { int g = j / 3 + 1; T0(i, j, g); T1(i, j, g); T2(i, j, g); if (p[g + 1][a[i]]) { T0(i, j, p[g][a[i]]); T2(i, j, p[g][a[i]]); } if (p[g + 1][a[j]]) { T1(i, j, p[g][a[j]]); T2(i, j, p[g][a[j]]); } } } cout << ans + f[3 * n + 1][3 * n + 2]; return 0; }
0
CPP
#include <bits/stdc++.h> using namespace std; int n; int a[105]; int main() { int i; while (scanf("%d", &n) != EOF) { for (i = 1; i <= n; i++) scanf("%d", &a[i]); if (n % 2 == 0) printf("No\n"); else if ((a[1] % 2) && (a[n] % 2)) printf("Yes\n"); else printf("No\n"); } return 0; }
7
CPP
# -*- coding: utf-8 -*- import sys def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def Yes(): print('Yes') def No(): print('No') def YES(): print('YES') def NO(): print('NO') sys.setrecursionlimit(10 ** 9) INF = 10 ** 18 MOD = 10 ** 9 + 7 R1, R2 = MAP() ans = 1 / (1/R1 + 1/R2) print(ans)
0
PYTHON3
A,B,C=input().split() f=A[-1]==B[0] and B[-1]==C[0] print('YES' if f else 'NO')
0
PYTHON3
#include<iostream> #include<algorithm> #include<vector> #include<map> using namespace std; #define x first #define y second typedef pair< int , int > Pt; int main(){ int m; while(cin >> m , m){ vector< Pt > a(m); for(int i = 0 ; i < m ; i++ ) cin >> a[i].x >> a[i].y; int n; cin >> n; vector< Pt > all(n); for(int i = 0 ; i < n ; i++ ) cin >> all[i].x >> all[i].y; sort(a.begin(),a.end()); sort(all.begin(),all.end()); for(int i = 0 ; i < n ; i++ ){ int xx = all[i].x - a[0].x, yy = all[i].y - a[0].y, j; for(j = 0 ; j < m ; j++ ){ if(!binary_search(all.begin(),all.end(),Pt(a[j].x+xx,a[j].y+yy))){ break; } } if(j == m){ cout << all[i].x - a[0].x << " " << all[i].y - a[0].y << endl; break; } } } }
0
CPP
""" Accomplished using the EduTools plugin by JetBrains https://plugins.jetbrains.com/plugin/10081-edutools """ from typing import List, Tuple # Linear regression: https://dataaspirant.com/simple-linear-regression-python-without-any-machine-learning-libraries/ def mean(readings: List[int]) -> float: return sum(readings) / float(len(readings)) def variance(readings: List[int]) -> float: Β΅ = mean(readings) diffSq = [pow((reading - Β΅), 2) for reading in readings] return sum(diffSq) / float(len(readings) - 1) def covariance(l1: List[int], l2: List[int]) -> float: Β΅ = [mean(l1), mean(l2)] cov = 0.0 for i in range(0, len(l1)): cov += (l1[i] - Β΅[0]) * (l2[i] - Β΅[1]) return cov / float(len(l1) - 1) def linearReg(lx: List[int], ly: List[int]) -> Tuple[float, float]: m = covariance(lx, ly) / float(variance(lx)) b = mean(ly) - (m * mean(lx)) return b, m # Program if __name__ == "__main__": # Parse input length = int(input()) ls = [int(s) for s in input().strip().split(' ')] # Compute def compute() -> int: # Definitely is arithmetic sequence if length <= 2: return 0 # Compute regression b, m = linearReg(list(range(0, length)), ls) # print(b, m) diff = round(m) # Loop through possible starting values minChanges = 1e10 for start in range(ls[0] - 1, ls[0] + 2): changes = 0 # Count changes for i in range(0, length): dist = ls[i] - (start + diff * i) # No change required if dist == 0: continue # One modification required if abs(dist) <= 1: changes += 1 continue # Two or more modifications required, that means this is invalid changes = 1e10 break # Add to min changes if changes < minChanges: minChanges = changes # Solution found if minChanges != 1e10: return minChanges # No solutions found return -1 # Write your solution here print(compute())
10
PYTHON3
def plus(a, b): c = "" i = len(a)-1 arg = 0 while i >= 0: k = (arg + ord(a[i]) + ord(b[i]) - 194) arg = 1 if k < 26: arg = 0 i -= 1 c = chr(k % 26) + c c = chr(1) * arg + c return c def minus(a): c = "" i = 0 arg = 0 while i < len(a): c += chr((arg * 26 + ord(a[i]))//2) arg = ord(a[i]) % 2 i += 1 if arg: c = c[:len(c)-1] + chr(ord(c[len(c)-1])+1) return c n = int(input()) a = input() b = input() a1 = "" b1 = "" i = 0 while i < n: a1 += a[i] b1 += b[i] i += 1 c = plus(a,b) c = minus(c) c1 = "" for q in c: c1 += chr(ord(q) + ord('a')) print(c1[len(c1)-n:])
11
PYTHON3
num = int(input()) dic = dict() for i in range(num): inp = input() if dic.get(inp) is not None: dic[inp] = dic[inp] + 1 else: dic[inp] = 1 max_value = max(dic.values()) max_keys = [k for k, v in dic.items() if v == max_value] print(max_keys[0])
7
PYTHON3
#include <bits/stdc++.h> using namespace std; bool comp(pair<long long, long long> &a, pair<long long, long long> &b) { return (a.second > b.second); } void show_vec(vector<pair<long long, long long> > v) { for (int i = 0; i < v.size(); i++) cout << v[i].first << " " << v[i].second << "\n"; ; cout << "\n"; } long long gcd(long long a, long long b) { if (a == 0) return b; return gcd(b % a, a); } long long lcm(long long a, long long b) { return ((a * b) / gcd(a, b)); } long long fact(long long n) { if (n == 0) return 1; return n * fact(n - 1); } bool check_prime(int n) { if (n <= 1) return false; if (n < 4) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (int i = 5; i * i <= n; i += 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } void solve() { long long n, i, j, k = 0, m; string s, t = "", t1 = ""; cin >> n >> s; i = n, j = 0; m = n; if (m % 2) m--; i = m / 2; while (i > 0) { t = s.substr(0, i); t1 = s.substr(i, i); if (t == t1) k = max(k, (long long)t.length()); i--; } if (k == 0) k++; cout << n - k + 1 << "\n"; } int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); int t = 1; while (t--) { solve(); } return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; string S; set<string> ans; int N; bool u[10001][2]; void dfs(int n, string prev, int p) { if (u[n][p]) return; if (n + 1 - 2 > 4) { string t = S.substr(n - 1, 2); if (t != prev) { ans.insert(t); dfs(n - 2, t, 2); } } if (n + 1 - 3 > 4) { string t = S.substr(n - 2, 3); if (t != prev) { ans.insert(t); dfs(n - 3, t, 3); } } u[n][p] = 1; } int main() { cin >> S; N = S.length(); memset(u, 0, sizeof(u)); dfs(S.length() - 1, "", 0); cout << ans.size() << endl; for (__typeof((ans).begin()) i = (ans).begin(); i != (ans).end(); i++) cout << *i << endl; return 0; }
7
CPP
#include <bits/stdc++.h> using namespace std; unsigned long long n, k, ans = 1; unsigned long long go(unsigned long long i) { return log2(i); } signed main() { cin >> n >> k; if (k == 1) { cout << n; return 0; } while (n) { n >>= 1; ans <<= 1; } cout << ans - 1; return 0; }
8
CPP
s = input() a = s.lower() b = s.upper() cnt1, cnt2 = 0, 0 for i in range(len(s)): if s[i] != a[i]: cnt1 -= -1 if s[i] != b[i]: cnt2 -= -1 if cnt1 > cnt2: print(b) else: print(a)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; template <class T> inline bool uin(T& a, T b) { return a > b ? (a = b, true) : false; } template <class T> inline bool uax(T& a, T b) { return a < b ? (a = b, true) : false; } int main() { ios::sync_with_stdio(false); cin.tie(0); long long N, K; cin >> N >> K; if (K == 1) { cout << N << '\n'; return 0; } string be, en; cin >> be >> en; long long ans = 0, cur = 1; for (int i = 0; i < N; ++i) { cur *= 2LL; if (be[i] == 'b') --cur; if (en[i] == 'a') --cur; uin(cur, K); ans += cur; } cout << ans << '\n'; }
8
CPP
#include <bits/stdc++.h> using namespace std; long long pre[20]; long long deal(char x[]) { long long cur = 0; int len = strlen(x + 1); for (int i = 1; i < len; i++) { if (i - 2 < 0) cur += 9; else cur += 1ll * 9 * pre[i - 2]; } if (len - 2 >= 0) cur += (x[1] - '1') * 1ll * pre[len - 2]; else cur += (x[1] - '1'); long long mm = 0; for (int i = 2; i < len; i++) mm = mm * 10 + (x[i] - '0'); if (x[1] > x[len]) mm--; cur += mm + 1; return cur; } int main() { char n[30], m[30]; long long nn; pre[0] = 1; for (int i = 1; i <= 18; i++) pre[i] = pre[i - 1] * 10; scanf("%I64d", &nn); scanf("%s", m + 1); nn--; if (nn == 0) n[1] = '0', n[2] = '\0'; else { int len = 0, j = 1; char tp[30]; while (nn) { tp[len++] = nn % 10 + '0'; nn /= 10; } len--; while (len >= 0) n[j++] = tp[len--]; n[j] = '\0'; } long long ans = deal(m) - deal(n); printf("%I64d\n", ans); return 0; }
7
CPP
#include <bits/stdc++.h> using namespace std; long long n, i, ta, tb, has, t, X[202020], Y[202020], a[202020], b[202020], x[202020]; pair<pair<long long, long long>, long long> A[202020], B[202020]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> t; while (t--) { cin >> n; for (i = 1; i <= n; i++) { x[i] = 2; cin >> a[i] >> b[i]; A[i] = make_pair(make_pair(a[i], b[i]), i); } has = -1; long long ma = -1e18; sort(A + 1, A + 1 + n); for (i = 1; i <= n; i++) { x[A[i].second] = 1; ma = max(ma, A[i].first.second); if (i < n && A[i + 1].first.first > ma) { has = 1; break; } } if (has == -1) cout << -1 << "\n"; else { for (i = 1; i <= n; i++) if (i < n) cout << x[i] << " "; else cout << x[i] << "\n"; } } }
9
CPP
#include <bits/stdc++.h> using namespace std; int m, x, y; map<pair<int, int>, int> itb; map<int, pair<int, int> > bti; set<int> blocks; set<int> q; vector<int> result; bool ex_g(int xx, int yy) { if (itb.find(make_pair(xx, yy)) != itb.end()) return (blocks.find(itb[make_pair(xx, yy)]) != blocks.end()); else return false; } bool can_pull(int idx) { int xx = bti[idx].first; int yy = bti[idx].second; if (ex_g(xx, yy + 1) and !ex_g(xx - 1, yy) and !ex_g(xx + 1, yy)) { return false; } if (ex_g(xx - 1, yy + 1) and !ex_g(xx - 1, yy) and !ex_g(xx - 2, yy)) { return false; } if (ex_g(xx + 1, yy + 1) and !ex_g(xx + 1, yy) and !ex_g(xx + 2, yy)) { return false; } return true; } bool can_pull(int xx, int yy) { return ex_g(xx, yy) && can_pull(itb[make_pair(xx, yy)]); } void remove_el(bool turn) { int r = (turn ? *q.rbegin() : *q.begin()); if (!can_pull(r)) { q.erase(r); remove_el(turn); return; } result.push_back(r); q.erase(r); blocks.erase(r); int xx = bti[r].first; int yy = bti[r].second; if (can_pull(xx, yy - 1)) { q.insert(itb[make_pair(xx, yy - 1)]); } if (can_pull(xx - 1, yy - 1)) { q.insert(itb[make_pair(xx - 1, yy - 1)]); } if (can_pull(xx + 1, yy - 1)) { q.insert(itb[make_pair(xx + 1, yy - 1)]); } } int main() { cin >> m; for (int i = 0; i < m; i++) { cin >> x >> y; itb[make_pair(x, y)] = i; bti[i] = make_pair(x, y); blocks.insert(i); } for (int i = 0; i < m; i++) if (can_pull(i)) { q.insert(i); } bool t = true; for (int i = 0; i < m; i++) { if (t) remove_el(true); else remove_el(false); t = !t; } long long int sum = 0; long long int c = (1000 * 1000 * 1000) + 9; for (int i = 0; i < result.size(); i++) { sum *= m; sum %= c; sum += result[i]; sum %= c; } cout << sum << endl; return 0; }
10
CPP
//24 #include<iostream> #include<cmath> using namespace std; int main(){ for(int n;cin>>n,n;){ int mi; double mb=1<<30; while(n--){ int i; double h,w; cin>>i>>h>>w; double mbid=fabs(w*10000/h/h-22); if(mbid<mb||mbid==mb&&i<mi){ mi=i; mb=mbid; } } cout<<mi<<endl; } return 0; }
0
CPP
exit = [] enter = [] people = enter n = int(input()) for i in range(n): a, b = list(map(int, input().split())) exit.append(a) enter.append(b) for i in range(len(people)): people[0] = enter[0] people[i] = people[i - 1] - exit[i] + enter[i] people.sort() print(people[-1])
7
PYTHON3
#include <bits/stdc++.h> using namespace std; typedef long long LL; LL iabs(LL x) { return x >= 0 ? x : -x; } int main() { int n, m; scanf("%d%d", &n, &m); printf("%lld\n", iabs(1LL * (n - 2) * (m - 2))); return 0; }
0
CPP
#include<bits/stdc++.h> using namespace std; void solve() { int n,m,i; cin>>n>>m; if(n&1) for(i=1;i<=m;i++) cout<<i<<" "<<n-i<<endl; else for(i=0;i<m;i++) if(i<(m+1)/2) cout<<i+1<<" "<<n-i<<endl; else cout<<i+1<<" "<<n-i-1<<endl; } int32_t main() { ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL); int t=1;//cin>>t; while(t--) solve(); return 0; }
0
CPP
#include <bits/stdc++.h> using namespace std; stack<int> s; int main() { int n, mx = 0; scanf("%d", &n); for (int i = 0; i < n; i++) { int x; scanf("%d", &x); mx = max(mx, x); if (s.size() == 0 || s.top() > x) s.push(x); else if (s.top() == x) s.pop(); else if (s.top() < x) { printf("NO\n"); return 0; } } if (s.size() > 1 || (s.size() == 1 && s.top() != mx)) printf("NO\n"); else printf("YES\n"); }
10
CPP
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while (t--) { int n; cin >> n; set<int> vec; for (int i = 0; i < n; i++) { int d; cin >> d; vec.insert(d); } cout << vec.size() << "\n"; } }
8
CPP
#include <bits/stdc++.h> using namespace std; struct pairHash { int operator()(const pair<string, int> p) const { int i; int res = 7; for (i = 0; i < p.first.size(); i++) { res = (long long)(res * 257 + p.first[i]) % 1000000007; } res = (long long)(res * 257 + p.second) % 1000000007; return res; } }; unordered_map<pair<string, int>, string, pairHash> Map; int sum[1001][2]; int main() { int n, m, i, j; string s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11; int b, b2; ios::sync_with_stdio(false); cin.tie(NULL); cin >> n >> m; for (i = 0; i < n; i++) { cin >> s1 >> s2 >> s3; s6.clear(); s7.clear(); if (s3[0] == '0' || s3[0] == '1') { for (j = 0; j < m; j++) { b = (int)s3[j] - '0'; s6 += (char)b; s7 += (char)b; } } else { cin >> s4 >> s5; if (s3 == "?" && s5 == "?") { if (s4 == "XOR") { for (j = 0; j < m; j++) { s6 += (char)0; s7 += (char)0; } } else { for (j = 0; j < m; j++) { s6 += (char)0; s7 += (char)1; } } } else { if (s3 == "?") swap(s3, s5); s8 = Map[make_pair(s3, 0)]; s9 = Map[make_pair(s3, 1)]; s10 = Map[make_pair(s5, 0)]; s11 = Map[make_pair(s5, 1)]; if (s5 == "?") { if (s4 == "XOR") { for (j = 0; j < m; j++) { s6 += (int)0 ^ s8[j]; s7 += (int)1 ^ s9[j]; } } else { if (s4 == "OR") { for (j = 0; j < m; j++) { s6 += (int)0 | s8[j]; s7 += (int)1 | s9[j]; } } else { for (j = 0; j < m; j++) { s6 += (int)0 & s8[j]; s7 += (int)1 & s9[j]; } } } } else { if (s4 == "XOR") { for (j = 0; j < m; j++) { s6 += (int)s10[j] ^ s8[j]; s7 += (int)s11[j] ^ s9[j]; } } else { if (s4 == "OR") { for (j = 0; j < m; j++) { s6 += (int)s10[j] | s8[j]; s7 += (int)s11[j] | s9[j]; } } else { for (j = 0; j < m; j++) { s6 += (int)s10[j] & s8[j]; s7 += (int)s11[j] & s9[j]; } } } } } } for (j = 0; j < m; j++) { sum[j][0] += s6[j]; sum[j][1] += s7[j]; } Map[make_pair(s1, 0)] = s6; Map[make_pair(s1, 1)] = s7; } for (i = 0; i < m; i++) { if (sum[i][0] <= sum[i][1]) cout << "0"; else cout << "1"; } cout << "\n"; for (i = 0; i < m; i++) { if (sum[i][0] >= sum[i][1]) cout << "0"; else cout << "1"; } cout << "\n"; return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; long long mem[101][10010], t[101][10010]; long long n, a[101], b[101], total; long long dp(long long cur, long long ob) { if (ob == 0) { t[cur][ob] = 0; return 0; } if (n == cur) { t[cur][ob] = 999999; return 200; } long long &ret = mem[cur][ob]; if (ret != -1) return ret; long long cob, x; if (ob < b[cur]) { x = ob - a[cur]; cob = 0; } else { cob = ob - b[cur]; x = b[cur] - a[cur]; } ret = 1 + dp(cur + 1, cob); t[cur][ob] = x + t[cur + 1][cob]; if (ret == dp(cur + 1, ob)) { t[cur][ob] = min(t[cur][ob], t[cur + 1][ob]); } else if (ret > dp(cur + 1, ob)) { ret = dp(cur + 1, ob); t[cur][ob] = t[cur + 1][ob]; } return ret; } int main() { long long total = 0; memset(mem, -1, sizeof(mem)); scanf("%lld", &n); for (long long i = 0; i < n; i++) { scanf("%lld", a + i); total += a[i]; } for (long long i = 0; i < n; i++) scanf("%lld", b + i); cout << dp(0, total); printf(" "); cout << t[0][total] << endl; return 0; }
16
CPP
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; for (auto i = 0; i < t; i++) { int n; cin >> n; vector<pair<int, int> > p; vector<int> time(n); int k = 1; int max = 0; for (auto j = 0; j < n; j++) { int a, b; cin >> a >> b; p.push_back(make_pair(a, b)); if (max < p[j].first) max = p[j].first; if (p[j].first == 1 && b >= k) { time[j] = k; k++; } else { time[j] = 0; } } for (auto f = 2; f <= max; f++) { if (k < f) { k = f; } for (auto j = 0; j < n; j++) { if (p[j].first == f && p[j].second >= k) { time[j] = k; k++; } else if (time[j] == 0) { time[j] = 0; } } } for (auto j = 0; j < n; j++) { cout << time[j] << " "; } cout << "\n"; } }
8
CPP
import sys #sys.stdin = open("input.txt", "r") for t in range(int(input())): n = int(input()) print((n -1) // 2)
7
PYTHON3
def useElevator(x, y, z, t1, t2, t3): timeUsingStairs = abs(x - y) * t1 timeUsingElevator = 3 * t3 + (abs(x - y) + abs(x - z)) * t2 return timeUsingElevator <= timeUsingStairs x, y, z, t1, t2, t3 = map(int, input().split()) print("YES" if useElevator(x, y, z, t1, t2, t3) else "NO")
7
PYTHON3
import sys from os import path if(path.exists('input.txt')): sys.stdin = open("input.txt","r") sys.stdout = open("output.txt","w") n, m = input().split() n = int(n) m = int(m) arr = list(map(int, input().split())) start = 1 ans = 0 for i in arr: if i > start : ans += i - start start = i elif i == start: continue else: ans += n - start + i start = i print(ans)
8
PYTHON3
h,w=map(int,input().split()) if h%3==0 or w%3==0: print(0) else: ans=float('inf') for i in range(1,h): c=max(i*(w//2),i*(w-w//2),(h-i)*w)-min(i*(w//2),i*(w-w//2),(h-i)*w) if ans>c: ans=c #print(ans) for i in range(1,w): d=max(i*(h//2),i*(h-h//2),(w-i)*h)-min(i*(h//2),i*(h-h//2),(w-i)*h) if ans>d: ans=d #print(ans) print(min(ans,h,w))
0
PYTHON3
t=int(input()) while(t!=0): n=int(input()) a=list(map(int,input().split())) a.reverse() print(*a) t-=1
7
PYTHON3
#include <bits/stdc++.h> using namespace std; const unsigned int MOD = 1000000007; void grid(int N, int M, char** mat) { long long** sumsDown = new long long*[N]; long long** sumsRight = new long long*[N]; long long** pathsLeftDown = new long long*[N]; long long** pathsUpDown = new long long*[N]; long long** pathsLeftRight = new long long*[N]; long long** pathsUpRight = new long long*[N]; int** num_pushes_down = new int*[N]; int** num_pushes_right = new int*[N]; int** y = new int*[N]; int** x = new int*[N]; int i, j; for (i = 0; i < N; i++) { sumsDown[i] = new long long[M](); sumsRight[i] = new long long[M](); y[i] = new int[M]; x[i] = new int[M]; pathsLeftDown[i] = new long long[M](); pathsUpDown[i] = new long long[M](); pathsLeftRight[i] = new long long[M](); pathsUpRight[i] = new long long[M](); num_pushes_down[i] = new int[M](); num_pushes_right[i] = new int[M](); } int num; for (i = N - 2; i >= 0; i--) { for (int j = 0; j < M; j++) { num = num_pushes_down[i + 1][j]; if (mat[i + 1][j] == '.') { ++num; } num_pushes_down[i][j] = num; } } for (j = M - 2; j >= 0; j--) { for (int i = 0; i < N; i++) { y[i][j] = -1; x[i][j] = -1; num = num_pushes_right[i][j + 1]; if (mat[i][j + 1] == '.') { ++num; } num_pushes_right[i][j] = num; } } for (i = 0; i < N; i++) { y[i][M - 1] = -1; x[i][M - 1] = -1; } for (j = 0; j < M; j++) { int lastComputed = 0; for (int i = 0; i < N; i++) { num = num_pushes_down[i][j]; int k; for (k = lastComputed + 1; k >= i && k < i + num && k < N; k++) { y[k][j] = i; } lastComputed = k - 1; } } for (i = 0; i < N; i++) { int lastComputed = 0; for (int j = 0; j < M; j++) { num = num_pushes_right[i][j]; int k; for (k = lastComputed + 1; k >= j && k < j + num && k < M; k++) { x[i][k] = j; } lastComputed = k - 1; } } if (num_pushes_right[0][0] > 0) { pathsLeftRight[0][0] = 1; for (int j = 1; j < M; j++) { if (x[0][j] == 0) { pathsLeftRight[0][j] = 1; } else { pathsLeftRight[0][j] = 0; } } } if (num_pushes_down[0][0] > 0) { pathsUpDown[0][0] = 1; for (int i = 1; i < N; i++) { if (y[i][0] == 0) { pathsUpDown[i][0] = 1; } else { pathsUpDown[i][0] = 0; } } } for (j = 1; j < M; j++) { pathsLeftDown[0][j] = (num_pushes_down[0][j] > 0) ? pathsLeftRight[0][j - 1] : 0; sumsDown[0][j] = pathsLeftDown[0][j]; sumsRight[0][j] = pathsLeftRight[0][j]; } for (i = 1; i < N; i++) { sumsDown[i][0] = pathsUpDown[i][0]; pathsUpRight[i][0] = (num_pushes_right[i][0] > 0) ? pathsUpDown[i - 1][0] : 0; sumsRight[i][0] = pathsUpRight[i][0]; } for (i = 1; i < N; i++) { for (int j = 1; j < M; j++) { if (num_pushes_down[i][j] > 0) { pathsLeftDown[i][j] = (pathsLeftRight[i][j - 1] % MOD + pathsUpRight[i][j - 1] % MOD) % MOD; } else { pathsLeftDown[i][j] = 0; } long long sum; if (y[i][j] != -1 && y[i][j] != i) { if (y[i][j] > 0) { sum = sumsDown[i - 1][j] - sumsDown[y[i][j] - 1][j]; if (sum < 0) { sum += MOD; } } else { sum = sumsDown[i - 1][j]; } } else { sum = 0; } pathsUpDown[i][j] = sum % MOD; sumsDown[i][j] = (sumsDown[i - 1][j] % MOD + pathsLeftDown[i][j] % MOD) % MOD; if (num_pushes_right[i][j] > 0) { pathsUpRight[i][j] = (pathsLeftDown[i - 1][j] % MOD + pathsUpDown[i - 1][j] % MOD) % MOD; } else { pathsUpRight[i][j] = 0; } if (x[i][j] != -1 && x[i][j] != j) { if (x[i][j] > 0) { sum = sumsRight[i][j - 1] - sumsRight[i][x[i][j] - 1]; if (sum < 0) { sum += MOD; } } else { sum = sumsRight[i][j - 1]; } } else { sum = 0; } pathsLeftRight[i][j] = sum % MOD; sumsRight[i][j] = (sumsRight[i][j - 1] % MOD + pathsUpRight[i][j] % MOD) % MOD; } } i = N - 1; j = M - 1; long long total = 0; if (i > 0) { total += (pathsLeftDown[i - 1][j] % MOD + pathsUpDown[i - 1][j] % MOD) % MOD; } if (j > 0) { total += (pathsLeftRight[i][j - 1] % MOD + pathsUpRight[i][j - 1] % MOD) % MOD; } if (i == 0 && j == 0) { total = 1; } cout << total % MOD << endl; } int main() { int N, M; cin >> N >> M; char** mat = new char*[N]; for (int i = 0; i < N; i++) { mat[i] = new char[M]; } for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { cin >> mat[i][j]; } } grid(N, M, mat); }
11
CPP
from sys import stdin word = stdin.readline().rstrip() first_letter = word[0] other_letters = word[1:] def correctCaps(firstLetter, otherLetters): if firstLetter.isupper() and otherLetters.isupper(): return firstLetter.lower() + otherLetters.lower() elif firstLetter.islower() and otherLetters.isupper(): return firstLetter.upper() + otherLetters.lower() elif firstLetter.islower() and not otherLetters: return firstLetter.upper() elif firstLetter.isupper() and not otherLetters: return firstLetter.lower() else: return firstLetter + otherLetters print(correctCaps(first_letter, other_letters))
7
PYTHON3
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #pragma GCC optimize("unroll-loops") using namespace std; const int MAXN = 100005; const int LMAXN = 20; inline int64_t gilbertOrder(int x, int y, int pow, int rotate) { if (pow == 0) { return 0; } int hpow = 1 << (pow - 1); int seg = (x < hpow) ? ((y < hpow) ? 0 : 3) : ((y < hpow) ? 1 : 2); seg = (seg + rotate) & 3; const int rotateDelta[4] = {3, 0, 0, 1}; int nx = x & (x ^ hpow), ny = y & (y ^ hpow); int nrot = (rotate + rotateDelta[seg]) & 3; int64_t subSquareSize = int64_t(1) << (2 * pow - 2); int64_t ans = seg * subSquareSize; int64_t add = gilbertOrder(nx, ny, pow - 1, nrot); ans += (seg == 1 || seg == 2) ? add : (subSquareSize - add - 1); return ans; } struct Query { int l, r, ind; int64_t ord; inline void calcOrder() { ord = gilbertOrder(l, r, LMAXN, 0); } }; inline bool operator<(const Query &a, const Query &b) { return a.ord < b.ord; } int n, m, a[MAXN], vx, ret[MAXN]; int ans[MAXN]; int curr, cc[MAXN]; vector<Query> q; map<int, int> ma; set<int> ss; inline void add(int x) { cc[x]++; if (cc[x] == ret[x]) curr++; else if (cc[x] == ret[x] + 1) curr--; } inline void remove(int x) { if (cc[x] == ret[x]) curr--; if (cc[x] == ret[x] + 1) curr++; cc[x]--; } int main() { std::ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> m; for (int i = 0; i < n; i++) cin >> a[i], ss.insert(a[i]); for (auto it : ss) ma[it] = vx++; for (int i = 0; i < n; i++) ret[ma[a[i]]] = a[i], a[i] = ma[a[i]]; q.resize(m); for (int i = 0; i < m; i++) { int l, r; cin >> l >> r; q[i].l = l - 1; q[i].r = r - 1; q[i].ind = i; q[i].calcOrder(); } sort(q.begin(), q.end()); int mo_left = 0, mo_right = -1; for (int i = 0; i < m; i++) { int left = q[i].l; int right = q[i].r; while (mo_right < right) add(a[++mo_right]); while (mo_right > right) remove(a[mo_right--]); while (mo_left < left) remove(a[mo_left++]); while (mo_left > left) add(a[--mo_left]); ans[q[i].ind] = curr; } for (int i = 0; i < m; i++) cout << ans[i] << "\n"; return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; double pr[1000]; int vis[1000]; int main() { int n, k, i, j, x, q; scanf("%d %d", &n, &k); for (i = 0; i < n; i++) scanf("%lf", &pr[i]); scanf("%d", &q); int q_n = n / k; vector<double> v; while (q--) { double sum = 0; for (i = 0; i < q_n; i++) { scanf("%d", &x); x--; vis[x] = 1; sum += pr[x]; } sum /= (double)q_n; v.push_back(sum); } double sum; vector<double> now; for (i = 0; i < n; i++) { if (!vis[i]) { now.push_back(pr[i]); } } sort(now.begin(), now.end()); int cn = n - now.size(); cn /= (n / k); if (cn < k) { sum = 0; for (i = 0; i < q_n; i++) { sum += now[i]; } sum /= (double)q_n; v.push_back(sum); sum = 0; int cnt = 0; for (i = (int)(now.size()) - 1; i >= 0; i--) { if (cnt >= q_n) break; sum += now[i]; cnt++; } sum /= (double)q_n; v.push_back(sum); } sort(v.begin(), v.end()); printf("%.15lf %.15lf\n", v[0], v[v.size() - 1]); return 0; }
8
CPP
q = int(input()) for _ in range(q): n = int(input()) a = list(map(int, input().split())) print(((sum(a)-1)//n+1))
7
PYTHON3
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll I, O, T, J, L, S, Z; ll mx; int main() { cin >> I >> O >> T >> J >> L >> S >> Z; mx = I / 2 * 2 + J / 2 * 2 + L / 2 * 2; if (I >= 1 && J >= 1 && L >= 1) mx = max(mx, (I - 1) / 2 * 2 + (J - 1) / 2 * 2 + (L - 1) / 2 * 2 + 3); mx += O; cout << mx << endl; return 0; }
0
CPP
#include <bits/stdc++.h> using namespace std; int s[1000 * 100 + 5], k[1000 * 1000 + 5]; int main() { int n; cin >> n; int a[n]; stack<int> v; v.push(0); s[0] = 0; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 1; i < n; i++) { while (a[v.top()] < a[i]) { v.pop(); if (v.empty()) { break; } } if (v.empty()) { v.push(i); } else { while (s[v.top()] <= k[v.top()] and s[v.top()] != 0) { v.pop(); } k[v.top()]++; s[i] = k[v.top()]; v.push(i); } } cout << *max_element(s, s + n); }
8
CPP
#include <bits/stdc++.h> const int MAXN = 410; typedef long long LL; int pow(int a, int b, int res = 1) { for (; b; b >>= 1, a *= a) if (b & 1) res *= a; return res; } int C[MAXN][4], n; LL hash(int * a) { return a[0] | a[1] << 16 | (LL) a[2] << 32 | (LL) a[3] << 48; } void dehash(int * a, LL t) { static const int mask = (1 << 16) - 1; a[0] = t & mask, t >>= 16; a[1] = t & mask, t >>= 16; a[2] = t & mask, t >>= 16; a[3] = t & mask; } void mk(int * t, int a, int b, int c, int d) { t[0] = a, t[1] = b, t[2] = c, t[3] = d; } void rotate(int * a) { static int t; t = a[3], a[3] = a[2], a[2] = a[1], a[1] = a[0], a[0] = t; } int rtteq(int * a) { LL hs = hash(a); int res = 0; for (int i = 0; i != 4; ++i) res += hash(a) == hs, rotate(a); return res; } void mins(int * a) { LL h[4]; for (int i = 0; i != 4; ++i) h[i] = hash(a), rotate(a); int at = std::min_element(h, h + 4) - h; for (int i = 0; i != at; ++i) rotate(a); } LL down(int a, int b) { LL res = 1; for (int i = a; i > a - b; --i) res *= i; return res; } std::map<LL, int> hav, pt; void ins(int * a, int v) { hav[hash(a)] += v; } int main() { std::ios_base::sync_with_stdio(false), std::cin.tie(0); std::cin >> n; for (int i = 1; i <= n; ++i) { for (int j = 0; j < 4; ++j) std::cin >> C[i][j]; mins(C[i]); ins(C[i], 1); } LL ans = 0; for (int i = 1; i <= n; ++i) for (int j = i + 1; j <= n; ++j) { ins(C[i], -1), ins(C[j], -1); for (int T = 0; T != 4; ++T) { int t[4]; mk(t, C[i][3], C[i][2], C[j][3], C[j][2]); mins(t); ++pt[hash(t)]; mk(t, C[i][2], C[i][1], C[j][0], C[j][3]); mins(t); ++pt[hash(t)]; mk(t, C[i][1], C[i][0], C[j][1], C[j][0]); mins(t); ++pt[hash(t)]; mk(t, C[i][0], C[i][3], C[j][2], C[j][1]); mins(t); ++pt[hash(t)]; LL r = 1; for (auto x : pt) { r *= down(hav[x.first], x.second); dehash(t, x.first); r *= pow(rtteq(t), x.second); } ans += r; pt.clear(); rotate(C[j]); } ins(C[i], 1), ins(C[j], 1); } std::cout << ans / 3 << std::endl; return 0; }
0
CPP
#include <bits/stdc++.h> using namespace std; struct student { int score, id; } n[1024]; bool operator<(const student &s1, const student &s2) { if (s1.score != s2.score) return s1.score > s2.score; else return s1.id < s2.id; } int main() { int N, A, B, C, D, i; cin >> N; for (i = 1; i <= N; i++) { cin >> A >> B >> C >> D; n[i].score = A + B + C + D; n[i].id = i; } sort(n + 1, n + 1 + N); for (i = 1; i <= N; i++) if (n[i].id == 1) break; cout << i << endl; return 0; }
7
CPP
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3fLL; const double EPS = 1e-8; const int MOD = 1000000007; const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1}; struct IOSetup { IOSetup() { cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(20); cerr << fixed << setprecision(10); } } iosetup; int query(const string &s) { assert(!s.empty() && s.length() <= 300); cout << s << endl; int dist; cin >> dist; assert(dist != -1); if (dist == 0) exit(0); return dist; } int main() { string a_str = "", b_str = ""; for (int _ = (0); _ < (300); ++_) a_str += 'a'; for (int _ = (0); _ < (300); ++_) b_str += 'b'; int a = 300 - query(a_str), b = 300 - query(b_str); string spell = ""; for (int _ = (0); _ < (a); ++_) spell += 'a'; int dist = b; for (int i = (0); i < (spell.length()); ++i) { if ((i - 1 < 0 || spell[i - 1] == 'a') && spell[i] == 'a') { while (b > 0) { string cp = spell; cp.insert(cp.begin() + i, 'b'); int now = query(cp); if (now >= dist) break; --dist; --b; spell.insert(spell.begin() + i, 'b'); } } } while (b--) spell += 'b'; query(spell); assert(false); }
10
CPP
import sys n = int(sys.stdin.readline()) first_p = (sys.stdin.readline()).split() count = 1 vmax = 0 for i in range(n - 1): second_p = (sys.stdin.readline()).split() if(first_p[0] == second_p[0] and first_p[1] == second_p[1]): count += 1 else: if(count > vmax): vmax = count count = 1 first_p = second_p; if(count > vmax): vmax = count print(vmax)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; template <class T> void max_swap(T& a, const T& b) { a = max(a, b); } template <class T> void min_swap(T& a, const T& b) { a = min(a, b); } template <class T> void uniq(vector<T>& c) { sort(c.begin(), c.end()); c.erase(unique(c.begin(), c.end()), c.end()); } template <class T> string to_s(const T& a) { ostringstream os; os << a; return os.str(); } template <class T> T to_T(const string& s) { istringstream is(s); T res; is >> res; return res; } template <class T, class U> ostream& operator<<(ostream& os, pair<T, U>& p) { os << "( " << p.first << ", " << p.second << " )"; return os; } template <class T> void print(T a, int n, const string& deli = " ", int br = 1) { for (int i = 0; i < n; ++i) { cout << a[i]; if (i + 1 != n) cout << deli; } while (br--) cout << endl; } template <class T> void print(const T& c, const string& deli = " ", int br = 1) { for (__typeof__((c).begin()) it = (c).begin(); it != (c).end(); ++it) { cout << *it; if (++it != c.end()) cout << deli; --it; } while (br--) cout << endl; } template <class T> void print2d(T a, int w, int h, int width = -1, int br = 1) { for (int i = 0; i < h; ++i) { for (int j = 0; j < w; ++j) { if (width != -1) cout.width(width); cout << a[i][j] << ' '; } cout << endl; } while (br--) cout << endl; } template <class T> void input(T& a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; } template <class T> void input(T* a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; } void fix_precision(int n) { cout.setf(ios::fixed, ios::floatfield); cout.precision(10); } void fast_io() { cin.tie(0); ios::sync_with_stdio(false); } bool valid(int x, int y, int w, int h) { return 0 <= x && x < w && 0 <= y && y < h; } const int dx[] = {0, 1, 0, -1}; const int dy[] = {1, 0, -1, 0}; const double PI = acos(-1.0); const int mod = ((long long)(1e9)) + 7; long long lower(long long n) { long long t = pow(n, 1.0 / 4); for (long long i = max(0LL, t - 2);; ++i) if (i * i * i * i >= n) return i; exit(1); } long long upper(long long n) { long long t = sqrt(n); for (long long i = t + 2;; --i) if (i * i <= n) return i; exit(1); } int sum[((long long)(1e6)) + 100][5]; int not_contain(int l, int r) { for (int i = 0; i < (int)(5); ++i) if (sum[r + 1][i] - sum[l][i] == 0) return i; exit(1); } int grundy(long long n) { int l = lower(n), r = upper(n); if (n <= 1 || l > r) return 0; return not_contain(l, r); } int main() { for (int i = 0; i < (int)(((long long)(1e6))); ++i) { for (int j = 0; j < (int)(5); ++j) sum[i + 1][j] = sum[i][j]; ++sum[i + 1][grundy(i)]; } int n; cin >> n; int g = 0; while (n--) { long long a; cin >> a; g ^= grundy(a); } cout << (g ? "Furlo" : "Rublo") << endl; }
9
CPP
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; int mx = -1; for (int i = 0; i < n; i++) { int x; cin >> x; mx = max(mx, x); } cout << max(0, mx - 25) << endl; return 0; }
7
CPP
n = int(input()) arr = list(map(int, input().split())) it = n - 1 while(arr[it] == arr[n - 1]): it -= 1 print(it + 1)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; vector<pair<int, bool>> g[2005]; int a = 0, cnt = 0; bool vs[2004]; vector<set<int>> h; void dfs(int u, set<int> &s) { vs[u] = 1; s.insert(u); for (pair<int, bool> v : g[u]) { if (v.second == 1) { if (!vs[v.first]) { dfs(v.first, s); } } } } int main() { int n; cin >> n; int m; cin >> m; int u, v; for (int i = 0; i < m; i++) { cin >> u >> v; g[u].push_back({v, 1}); g[v].push_back({u, 1}); } cin >> m; for (int i = 0; i < m; i++) { cin >> u >> v; g[u].push_back({v, 0}); g[v].push_back({u, 0}); } for (int i = 1; i <= n; i++) { if (!vs[i]) { set<int> s; dfs(i, s); h.push_back(s); } } for (int i = 0; i < h.size(); i++) { set<int> r = h[i]; bool f = 1; for (int el : r) { for (pair<int, bool> u : g[el]) { if (u.second == 0) { if (r.find(u.first) != r.end()) f = 0; } } } int l = r.size(); if (f) a = max(a, l); } cout << a << endl; return 0; }
9
CPP
a=input() b=a.replace('WUB',' ') print(b)
7
PYTHON3
a,b = map(int, input().split()) res = 0 a, b = sorted([a,b]) while a > 0 and b > 1: t = (b - 1) // 2 res += t a += t b -= 2 * t a, b = sorted([a,b]) if b == 2: res += 1 break print(res)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int n; struct node { int v, next; } edge[500005 << 2]; int adj[500005], adj2[500005], pos, fa[500005], fa2[500005]; int fi_fa[500005], cnt, out[500005][4]; void add(int adj[], int u, int v) { ++pos; edge[pos].v = v, edge[pos].next = adj[u]; adj[u] = pos; } void dfs(int adj[], int u, int fa[]) { for (int p = adj[u], v; p; p = edge[p].next) if ((v = edge[p].v) != fa[u]) { fa[v] = u; dfs(adj, v, fa); } } int root(int u) { if (fi_fa[u] == u) return u; return fi_fa[u] = root(fi_fa[u]); } bool check(int x, int y) { if (!x || !y) return 0; if (fa[x] == y || fa[y] == x) return 1; return 0; } void solve(int u, int f) { for (int p = adj[u], v, t; p; p = edge[p].next) if ((v = edge[p].v) != f) { solve(v, u); if (fa2[u] != v && fa2[v] != u) { t = root(v); ++cnt; out[cnt][0] = u, out[cnt][1] = v, out[cnt][2] = t, out[cnt][3] = fa2[t]; } } } int main() { scanf("%d", &n); int u, v; for (int i = 1; i < n; ++i) { scanf("%d%d", &u, &v); add(adj, u, v), add(adj, v, u); } for (int i = 1; i < n; ++i) { scanf("%d%d", &u, &v); add(adj2, u, v), add(adj2, v, u); } dfs(adj, 1, fa); dfs(adj2, 1, fa2); for (int i = 1; i <= n; ++i) fi_fa[i] = check(i, fa2[i]) ? fa2[i] : i; solve(1, 0); printf("%d\n", cnt); for (int i = 1; i <= cnt; ++i) printf("%d %d %d %d\n", out[i][0], out[i][1], out[i][2], out[i][3]); return 0; }
11
CPP
n = int(input()) if n%2==0: print("NO") else: a = [-1 for i in range(n*2)] num = 1 i = 0 while num <= 2*n: a[i] = num num += 1 i = (i+n)%(2*n) a[i] = num if a[(i+1)%(2*n)] == -1: i += 1 else: i -= 1 num += 1 print("YES") print(*a)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int n, k, best = 2147483647; bool has[200010]; vector<int> near[200010]; int root1, root2; long long res = 0; int dfs1(int now, int prev) { int cnt = has[now]; for (auto x : near[now]) { if (x - prev) cnt += dfs1(x, now); } if (cnt >= k && cnt < best) { root2 = now; best = cnt; } res = res + min(cnt, 2 * k - cnt); return cnt; } void dfs2(int now, int prev, int d) { if (has[now]) res += 1ll * d; for (auto x : near[now]) if (x - prev) dfs2(x, now, d + 1); } int main() { cin >> n >> k; for (int i = 0; i < 2 * k; i++) { int v; cin >> v; has[v] = 1; } for (int i = 0; i < n - 1; i++) { int u, v; cin >> u >> v; near[u].push_back(v); near[v].push_back(u); } for (int i = 0; i < n; i++) { if (near[i].size() == 1) { root1 = i; break; } } dfs1(root1, -1); cout << res << endl; return 0; }
11
CPP
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; for (int i = n; i > 0; i--) { if (n % i == 0) { n = i; cout << i << " "; } } cout << endl; return 0; }
8
CPP
#include <bits/stdc++.h> const int MAXN = 5 * 100000 + 10; const int MOD = 1000000000 + 7; const int INF = 0x7fffffff; using namespace std; vector<int> G[MAXN]; vector<int> S[MAXN]; vector<int> Lay[MAXN]; int n, m, Ans = 0; int vis[MAXN], col[MAXN]; void dfs(int fa, int x) { int pos = 1; priority_queue<int> Q; while (!Q.empty()) Q.pop(); for (int i = 0; i < S[x].size(); i++) if (col[S[x][i]] != 0) Q.push(-col[S[x][i]]); for (int i = 0; i < S[x].size(); i++) { if (col[S[x][i]] != 0) continue; while (!Q.empty() && (pos == (-Q.top()))) { pos++; Q.pop(); } col[S[x][i]] = pos; pos++; } for (int i = 0; i < G[x].size(); i++) { int v = G[x][i]; if (v == fa) continue; dfs(x, v); } } int main() { memset(col, 0, sizeof(col)); scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) S[i].clear(); for (int i = 1; i <= m; i++) Lay[i].clear(); for (int i = 1; i <= n; i++) { int s, x; scanf("%d", &s); Ans = max(Ans, s); for (int j = 1; j <= s; j++) { scanf("%d", &x); S[i].push_back(x); } } for (int i = 1; i < n; i++) { int u, v; scanf("%d%d", &u, &v); G[u].push_back(v); G[v].push_back(u); } dfs(0, 1); if (Ans == 0) Ans = 1; printf("%d\n", Ans); for (int i = 1; i <= m; i++) { if (col[i] == 0) printf("1 "); else printf("%d ", col[i]); } return 0; }
9
CPP
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 20; const int MAX = 10000007; inline long long read() { char c = getchar(); long long x = 0, f = 1; while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); } while (c >= '0' && c <= '9') { x = x * 10 + c - '0', c = getchar(); } return x * f; } inline void out(int x) { if (x > 9) out(x / 10); putchar(x % 10 + '0'); } int k; int main() { k = read(); for (int i = (1); i <= (k - 1); ++i) { for (int j = (1); j <= (k - 1); ++j) { int t = i * j; int kep = t; string s; while (kep) { s += kep % k + '0'; kep /= k; } reverse(s.begin(), s.end()); cout << s << " "; } cout << "\n"; } return 0; }
14
CPP
def no(): print('NO') exit(0) S = input() if ''.join(sorted(S)) != S: no() a = S.count('a') b = S.count('b') c = S.count('c') if a+b+c != len(S): no() if a == 0 or b == 0: no() if c != a and c != b: no() print('YES')
7
PYTHON3
n,k=map(int,input().split()) a=list(map(int,input())) ans=[-1]*n upper=False lower=False for i in range(k): ans[i]=a[i] for i in range(k,n): ans[i]=ans[i-k] if ans[i]==a[i]: pass elif ans[i]>a[i]: if lower==False and upper==False: upper=True else: if lower==False and upper==False: lower=True for j in range(k-1,-1,-1): if ans[j]!=9: break for l in range(i+1): if l%k==j: ans[l]+=1 elif l%k>j: ans[l]=0 print(n) print("".join(map(str,ans)))
9
PYTHON3
#include<bits/stdc++.h> using namespace std; #define LL long long #define ULL unsigned long long #define mp make_pair #define pb push_back #define pii pair<int,int> #define pll pair<LL,LL> #define x first #define y second #define pi acosl(-1) #define sqr(x) ((x)*(x)) #define pdd pair<double,double> #define MEMS(x) memset(x,-1,sizeof(x)) #define MEM(x) memset(x,0,sizeof(x)) #define less Less #define EPS 1e-4 #define arg ARG #define cpdd const pdd #define rank Rank #define MXN 200005 int main(){ int p[200005]; int n; scanf("%d",&n); if(n==1){ printf("0\n"); return 0; } for(int i=0;i<n;i++){ int x; scanf("%d",&x); p[x]=i; } int ans=0; int last=0; if(p[n-1]>p[n])ans++,last=n; else last=n-1; for(int i=n-2;i>=1;i--){ if(ans==0){ if(p[i]>p[i+1])ans++,last=i+1; } else if(p[i]<p[i+1]&&(p[last]<p[i]||p[last]>p[i+1])){ // if(p[last]>p[i+1]) // last=i; } else if(p[i]>p[i+1]&&(p[i]>p[last]&&p[last]>p[i+1])){ //last=i+1; } else{ ans++; last=i+1; } } printf("%d\n",ans); } /**/
0
CPP
#include <bits/stdc++.h> using namespace std; int sum(int n); int main() { int t; cin >> t; while (t--) { int n; cin >> n; if (n % 10 == 9) { cout << ((n - 9) / 10) + 1 << endl; } else cout << (n / 10) << endl; } }
7
CPP
#include <bits/stdc++.h> using namespace std; int main() { int t; long long int n, x; cin >> n; long long int b[n]; map<long long int, long long int> mp; for (int i = 0; i < n; i++) { cin >> b[i]; } for (int i = 0; i < n; i++) { mp[(i - b[i])] += b[i]; } long long int maxv = 0; for (auto x : mp) { maxv = max(maxv, x.second); } cout << maxv << endl; return 0; }
7
CPP
#include <bits/stdc++.h> using namespace std; const int mn = 2e5 + 10; vector<int> g[mn]; long long dp[mn][2]; void dfs(int x, int p) { long long sum = 0, dif1 = 0x3f3f3f3f, dif2 = 0x3f3f3f3f; for (int y : g[x]) { if (y == p) continue; dfs(y, x); sum += dp[y][0]; long long dif = dp[y][1] - dp[y][0]; if (dif < dif1) dif2 = dif1, dif1 = dif; else if (dif < dif2) dif2 = dif; } dp[x][0] = sum + min(1LL, dif1 + dif2 - 1); dp[x][1] = sum + min(1LL, dif1); dp[x][0] = min(dp[x][0], dp[x][1]); } int main() { int n, i; long long xx, yy; scanf("%d%lld%lld", &n, &xx, &yy); for (i = 0; i < n - 1; i++) { int a, b; scanf("%d%d", &a, &b); g[a].push_back(b); g[b].push_back(a); } if (yy <= xx) { for (i = 1; i <= n; i++) { if (g[i].size() == n - 1) { printf("%lld", xx + yy * (n - 2)); return 0; } } printf("%lld", yy * (n - 1)); return 0; } dfs(1, 0); long long num = dp[1][0] - 1; printf("%lld", num * yy + (n - 1 - num) * xx); }
10
CPP
N,X,T = map(int,input().split()) cnt = -(-N//X) print(cnt * T)
0
PYTHON3
for _ in range(int(input())): a,b=map(int,input().split()) if a>b: diff=a-b else: diff=b-a if diff%10==0: r=diff/10 else: r=int(diff/10)+1 print(int(r))
7
PYTHON3
''' ___ ___ ___ ___ ___ ___ /\__\ /\ \ _____ /\ \ /\ \ /\ \ /\__\ /:/ _/_ \:\ \ /::\ \ \:\ \ ___ /::\ \ |::\ \ ___ /:/ _/_ /:/ /\ \ \:\ \ /:/\:\ \ \:\ \ /\__\ /:/\:\__\ |:|:\ \ /\__\ /:/ /\ \ /:/ /::\ \ ___ \:\ \ /:/ \:\__\ ___ /::\ \ /:/__/ /:/ /:/ / __|:|\:\ \ /:/ / /:/ /::\ \ /:/_/:/\:\__\ /\ \ \:\__\ /:/__/ \:|__| /\ /:/\:\__\ /::\ \ /:/_/:/__/___ /::::|_\:\__\ /:/__/ /:/_/:/\:\__\ \:\/:/ /:/ / \:\ \ /:/ / \:\ \ /:/ / \:\/:/ \/__/ \/\:\ \__ \:\/:::::/ / \:\~~\ \/__/ /::\ \ \:\/:/ /:/ / \::/ /:/ / \:\ /:/ / \:\ /:/ / \::/__/ ~~\:\/\__\ \::/~~/~~~~ \:\ \ /:/\:\ \ \::/ /:/ / \/_/:/ / \:\/:/ / \:\/:/ / \:\ \ \::/ / \:\~~\ \:\ \ \/__\:\ \ \/_/:/ / /:/ / \::/ / \::/ / \:\__\ /:/ / \:\__\ \:\__\ \:\__\ /:/ / \/__/ \/__/ \/__/ \/__/ \/__/ \/__/ \/__/ \/__/ \/__/ ''' """ β–‘β–‘β–ˆβ–ˆβ–„β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–„β–ˆβ–ˆ β–‘β–„β–€β–‘β–ˆβ–„β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–„β–ˆβ–‘β–‘β–ˆβ–‘ β–‘β–ˆβ–‘β–„β–‘β–ˆβ–„β–‘β–‘β–‘β–‘β–‘β–‘β–„β–ˆβ–‘β–„β–‘β–ˆβ–‘ β–‘β–ˆβ–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–„β–ˆβ–‘ β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–€β–€β–ˆβ–ˆβ–ˆβ–ˆβ–€β–€β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–‘ β–„β–ˆβ–€β–ˆβ–€β–‘β–‘β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–‘β–‘β–‘β–€β–€β–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–‘β–‘β–€β–ˆβ–ˆβ–ˆβ–ˆβ–€β–€β–ˆβ–ˆβ–ˆβ–ˆβ–€β–‘β–‘β–ˆβ–ˆ β–ˆβ–ˆβ–‘β–‘β–‘β–‘β–ˆβ–€β–‘β–‘β–‘β–‘β–€β–ˆβ–‘β–‘β–‘β–‘β–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–„β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–„β–ˆβ–ˆβ–ˆ β–‘β–€β–ˆβ–ˆβ–ˆβ–„β–‘β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–‘β–‘β–„β–ˆβ–ˆβ–ˆβ–€β–‘ β–‘β–‘β–‘β–€β–ˆβ–ˆβ–„β–‘β–€β–ˆβ–ˆβ–€β–‘β–„β–ˆβ–ˆβ–€β–‘β–‘β–‘ β–‘β–‘β–‘β–‘β–‘β–‘β–€β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–€β–‘β–‘β–‘β–‘β–‘β–‘ β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘ """ import sys import math import collections import operator as op from collections import deque from math import gcd, inf, sqrt, pi, cos, sin, ceil, log2 from bisect import bisect_right, bisect_left # sys.stdin = open('input.txt', 'r') # sys.stdout = open('output.txt', 'w') from functools import reduce from sys import stdin, stdout, setrecursionlimit setrecursionlimit(2**20) def ncr(n, r): r = min(r, n - r) numer = reduce(op.mul, range(n, n - r, -1), 1) denom = reduce(op.mul, range(1, r + 1), 1) return numer // denom # or / in Python 2 def prime_factors(n): i = 2 factors = [] while i * i <= n: if n % i: i += 1 else: n //= i factors.append(i) if n > 1: factors.append(n) return (list(factors)) def sumDigits(no): return 0 if no == 0 else int(no % 10) + sumDigits(int(no / 10)) MOD = 1000000007 PMOD = 998244353 N = 10**9 + 7 T = 1 T = int(stdin.readline()) for _ in range(T): # n, p = list(map(int, stdin.readline().rstrip().split())) n = int(stdin.readline()) a = list(map(int, stdin.readline().rstrip().split())) # l = list(map(int, stdin.readline().rstrip().split())) # s = list(stdin.readline().strip('\n')) # t = str(stdin.readline().strip('\n')) # m = int(stdin.readline()) # s = list(map(int, stdin.readline().rstrip().split()) cnt = 0 for i in range(1, n): if a[i] < a[i - 1]: cnt += 1 # print(cnt) if cnt < n - 1: print('YES') else: print('NO')
7
PYTHON3
from math import sqrt n=int(input()) s=0 for i in range(1,n+1): for j in range(i+1,n+1): c=sqrt(i*i+j*j) cc=int(c) if(c==cc): if(c>n): break else: s=s+1 print(s)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { string s; for (int i = 0; i < 10; i++) { cout << i << endl; getline(cin, s); if (s != "no") { if (s == "great" || s == "cool" || s == "don't think so" || s == "not bad" || s == "don't touch me") cout << "normal" << endl; else cout << "grumpy" << endl; } } return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; int main() { string a1, a2, a, b, b1, b2, s; cin >> a1 >> a2 >> b1 >> b2; swap(a2[0], a2[1]); swap(b2[0], b2[1]); a += a1 + a2; b += b1 + b2; a.erase(a.find('X'), 1); b.erase(b.find('X'), 1); s += a + a; if (s.find(b) != string::npos) { printf("YES\n"); } else { printf("NO\n"); } }
7
CPP
#include <bits/stdc++.h> using namespace std; const int MAXN = 1000005; long long a[MAXN], Sum[MAXN], onLine[MAXN], residue[MAXN]; int main() { int N, Q; scanf("%d%d", &N, &Q); Sum[0] = 0; for (int i = 1; i <= N; i++) { scanf("%I64d", &a[i]); Sum[i] = Sum[i - 1] + a[i]; } for (int t = 1; t <= Q; t++) { long long b; scanf("%I64d", &b); onLine[N + 1] = 0; onLine[N] = 1; residue[N] = a[N]; int r = N; int l = N; while (l > 1) { l--; while (Sum[r] - Sum[l - 1] > b) r--; onLine[l] = onLine[r + 1] + 1; if (r == N) residue[l] = Sum[N] - Sum[l - 1]; else residue[l] = residue[r + 1]; } long long ans; if (Sum[N] > b) { ans = onLine[1]; int i = 2; while (Sum[i - 1] < b) { long long res = onLine[i]; if (residue[i] + Sum[i - 1] <= b) ans = min(ans, res); i++; } } else { ans = 1; } printf("%I64d\n", ans); } return 0; }
11
CPP
#include<bits/stdc++.h> using namespace std; int main() { long double a, b, c; cin >> a >> b >> c; if ((a + (2 * sqrtl(a * b)) + b) < c)cout << "Yes" << endl; else cout << "No" << endl; }
0
CPP
#include <bits/stdc++.h> using namespace std; int main() { int t, l; cin >> t; for (l = 0; l < t; l++) { int n, i, j; cin >> n; int a[n], g = 0, s = 0, b = 0; for (i = 0; i < n; i++) cin >> a[i]; g = 1; for (i = 1; i < n; i++) if (a[i] != a[0]) break; else g++; s = 1; for (j = i + 1; j < n; j++) { s++; if (s == g + 1) { while (j + 1 < n && a[j + 1] == a[j]) { s++; j++; } break; } } for (i = j + 1; i < n; i++) { b++; if (b == g + 1) { while (i + 1 < n && a[i + 1] == a[i]) { b++; i++; } break; } } if (g + s + b > n / 2) { cout << "0 0 0" << endl; continue; } else if (g + s + b == n / 2) cout << g << " " << s << " " << b << endl; else { int z = 1; for (j = i + 1; j + 1 < n; j++) { if (a[j] == a[j + 1]) z++; else { if (g + s + b + z > n / 2) break; else { b = b + z; z = 1; } } } cout << g << " " << s << " " << b << endl; } } }
9
CPP
#!/usr/bin/env python3.9 from math import ceil # ceil(W / 2) <= C <= W # Output: m - nmb of items # j1, ..., jm - item's indicies for _ in range(int(input())): n, W = list(map(int, input().split(' '))) w = list(enumerate(map(int, input().split(' ')), 1)) ''' 3 groups: (0): wi < W/2 (1): ceil(W/2) <= wi <= W (2): W < wi yes_cond: any(1) or sum(0) > W/2 ''' w.sort(key=lambda x: x[1]) indicies = [] small_sum = 0 for i, wi in reversed(w): if wi > W: continue elif ceil(W/2) <= wi <= W: small_sum += wi indicies.append(i) break elif wi < ceil(W/2): indicies.append(i) small_sum += wi if small_sum >= ceil(W/2): break if indicies and small_sum >= ceil(W/2): print(len(indicies)) print(*indicies) else: print(-1)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; long long t1, t2, x1, x2, t0; const double eps = 1e-9; inline bool eq(double a, double b) { return abs(a - b) < eps; } inline bool ls(double a, double b) { return a <= b - eps; } inline bool gt(double a, double b) { return a >= b + eps; } inline bool le(double a, double b) { return a < b + eps; } inline bool ge(double a, double b) { return a > b - eps; } inline bool zr(double lhs) { return fabs(lhs) < eps; } inline bool nz(double lhs) { return fabs(lhs) >= eps; } inline bool ps(double lhs) { return lhs >= eps; } inline bool nn(double lhs) { return lhs >= -eps; } inline bool ng(double lhs) { return lhs < -eps; } inline bool np(double lhs) { return lhs < eps; } bool check(long long y1, long long y2) { return t1 * y1 + t2 * y2 >= t0 * (y1 + y2); } double cal(long long y1, long long y2) { return double(t1 * y1 + t2 * y2) / (y1 + y2); } int main() { scanf("%lld%lld%lld%lld%lld", &t1, &t2, &x1, &x2, &t0); double ans = DBL_MAX; long long ay1, ay2; for (long long y1 = 0; y1 <= x1; y1++) { long long tmp1 = t2 * y1 - t1 * y1; if (tmp1 == 0) { bool ok = check(y1, x2); if (ok) { double tmp2 = cal(y1, x2); if (ls(tmp2, ans)) { ans = tmp2, ay1 = y1, ay2 = x2; } else if (eq(tmp2, ans)) { if (y1 + x2 > ay1 + ay2) { ay1 = y1, ay2 = x2; } } } } else if (tmp1 > 0) { long long l = 0, r = x2; while (l < r) { long long mid = (l + r) / 2; bool ok = check(y1, mid); if (ok) r = mid; else l = mid + 1; } if (check(y1, l)) { double tmp2 = cal(y1, l); if (ls(tmp2, ans)) { ans = tmp2, ay1 = y1, ay2 = l; } else if (eq(tmp2, ans)) { if (y1 + l > ay1 + ay2) { ay1 = y1, ay2 = l; } } } } else { long long l = 0, r = x2; while (l < r) { long long mid = (l + r + 1) / 2; bool ok = check(y1, mid); if (ok) l = mid; else r = mid - 1; } if (check(y1, l)) { double tmp2 = cal(y1, l); if (ls(tmp2, ans)) { ans = tmp2, ay1 = y1, ay2 = l; } else if (eq(tmp2, ans)) { if (y1 + l > ay1 + ay2) { ay1 = y1, ay2 = l; } } } } } printf("%lld %lld\n", ay1, ay2); return 0; }
7
CPP
s = input() s = list(s) l = len(s) r = l//20 if r*20!=l: r = r + 1 c = l//r if c*r!=l: c = c + 1 q = r*c - l t = 0 print(("%i %i") %(r,c)) i = 0 a = 0 while i<r: j = 0 m = 0 while j<c: if t<q and m==0: print('*', end="") t = t + 1 m = 1 else: print(s[a], end="") a = a + 1 j = j + 1 i = i + 1 print()
8
PYTHON3
A, B = map(int, input().split()) A -= 1 print ((B - 1 + A - 1)// A)
0
PYTHON3
t = int(input()) for i in range(t): l, r, m = [int(i) for i in input().split()] for x in range(l, r+1): if m<x: a=x b=l c=l-m+x break elif l-r<=m%x-x<=r-l: a=x b=r+m%x-x c=r break elif l-r<=m%x<=r-l: a=x b=r c=r-m%x break print(a,b,c)
8
PYTHON3
R = lambda:map(int,input().split()) n, d = R() arr = list(R()) ans = 2 for i in range(n-1): if arr[i]+d < arr[i+1]-d: ans += 2 if arr[i]+d == arr[i+1]-d: ans += 1 print(ans)
7
PYTHON3
#import<iostream> int main(){int n,v,i,c=0;std::cin>>n;for(i=n;i--;){std::cin>>v;if(v&1&&c++);}std::cout<<(c&1?"NO":"YES");}
0
CPP
#include <iostream> #include <cstdio> using namespace std; int main(){ int n; double w,h; while(scanf("%d,%lf,%lf", &n, &w, &h) != -1){ double bmi = w/h/h; if(bmi >= 25) cout << n << endl; } }
0
CPP
#include <bits/stdc++.h> #define all(c) (c).begin(),(c).end() using namespace std; const double R=6378.10; const double PI=3.1415926535; const double EPS=1e-10; const double toRad=180.0/PI; int main(void){ double a,b,c,d; while(cin >> a >> b >> c >> d){ if(a<0 && b<0 && c<0 && d<0)break; a/=toRad,b/=toRad,c/=toRad,d/=toRad; double ax=cos(b)*cos(a),ay=sin(b)*cos(a),az=sin(a); double bx=cos(d)*cos(c),by=sin(d)*cos(c),bz=sin(c); double D=sqrt(pow(ax-bx,2)+pow(ay-by,2)+pow(az-bz,2)); double rad=acos(1-D*D/2); printf("%.0f",round(R*rad)); cout << endl; } return 0; }
0
CPP
n=input() print("Bad" if n[0]==n[1] or n[1]==n[2] or n[2]==n[3] else "Good")
0
PYTHON3
n = int(input()) A = list(map(int, input().split())) A.sort() used = [False] * n v = n i = 0 j = 0 while i < n: while j < n - 1: j += 1 if A[i] < A[j] and used[j] == False: used[j] = True v -= 1 break i += 1 print(v)
9
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int n; while (cin >> n) { if (n & 1) cout << -1 << endl; else { for (int i = 1; i <= n; i++) { if (i & 1) cout << (i + 1); else cout << (i - 1); if (i != n) cout << ' '; } cout << endl; } } return 0; }
7
CPP
n=int(input()) arr=list(map(int,input().split())) arr.sort() flag=[0]*n flag[0]=1 valid=True ct=1 for i in range(1,len(arr)): if arr[i]!=arr[i-1]: flag[i]=1 ct+=1 for i in range(1,len(arr)): if flag[i]==0 and flag[i]==flag[i-1]: valid=False break if valid: print("YES") print(ct) for i in range(len(arr)): if flag[i]==1: print(arr[i],end=" ") print() print(n-ct) for i in range(len(arr)-1,-1,-1): if flag[i]!=1: print(arr[i],end=" ") print() else: print("NO")
9
PYTHON3
n = int(input()) grid = [] for i in range(n): grid.append(input()) diag = grid[0][0] other = grid[0][1] good = True for i in range(n): for j in range(n): if i == j or i+j == n-1: if grid[i][j] != diag: good = False elif grid[i][j] != other: good = False if diag != other and good: print("YES") else: print("NO")
7
PYTHON3
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const int mod = 1e9 + 7; const double eps = 1e-6; int main() { int n; while (cin >> n) { long long ans = 0; priority_queue<long long, vector<long long>, greater<long long> > q; q.push(INF); while (n--) { long long x; cin >> x; long long tmp = q.top(); if (tmp > x) q.push(x); else { ans += x - tmp; q.pop(); q.push(x), q.push(x); } } cout << ans << endl; } return 0; }
11
CPP
#include <bits/stdc++.h> using namespace std; const int oo = (int)1e9; const double eps = 1e-7; const int MAXN = 1e5 + 10; int dx[] = {1, 0, 0, -1, -1, -1, 1, 1}; int dy[] = {0, 1, -1, 0, 1, -1, 1, -1}; int d; int cost[2002]; int start; vector<int> adj[2002]; long long dfs(int node, int par) { long long ans = 1; for (int i = 0; i < ((int)((adj[node]).size())); i++) { int child = adj[node][i]; if (child == par || cost[child] < cost[start] || cost[child] - cost[start] > d || (cost[start] == cost[child] && start > child)) continue; ans *= dfs(child, node) + 1; ans %= 1000000007; } return ans; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, a, b; cin >> d >> n; for (int i = 0; i < n; i++) cin >> cost[i]; for (int i = 0; i < n - 1; i++) { cin >> a >> b; a--, b--; adj[a].push_back(b); adj[b].push_back(a); } long long ans = 0; for (int i = 0; i < n; i++) { start = i; ans += dfs(i, -1); ans %= 1000000007; } cout << ans << endl; }
10
CPP
# #----------------useful pkgs(&)func-----------------------# # from math import floor,comb,ceil,factorial,gcd,perm,exp,log,sqrt,pi as PI,e as E,inf as INF # from itertools import permutations,combinations,combinations_with_replacement # def john(l,x):return x.join(l) # def most(l):return(max(set(l), key=l.count)) # def is_anagram(s1,s2):return sorted(s1)==sorted(s2) # #permutation(l,k) Notes:- l->(list),k->(number of values in each tuple) # def binary_search(arr, x): #arr:-list to search,x:-element to search # low,high,mid=0,len(arr)-1,0 # while low <= high: # mid=(high+low)//2 # if arr[mid]<x:low = mid + 1 # elif arr[mid]>x:high=mid-1 # else:return mid # return -1 # #----------------------------------------------------------# def solve(): n = int(input()) if(n%4==0):print("YES") else:print("NO") #----------------------------------------------------------# t=1 t=int(input()) for _ in range(t):solve() '''--------------------cheat Sheet-------------------------# 1). l=list(map(int,input().split())) 2). x=lambda a,b,c:a+b+c+10 ---->usg---->x(a,b,c) 3). list1.extend(list2) 4). list1.append(list2) #---------------------------------------------------------'''
7
PYTHON3
#dt = {} for i in x: dt[i] = dt.get(i,0)+1 #dt = {k:v for k,v in sorted(x.items(), key=lambda i: i[1])} ipnl = lambda n: [int(input()) for _ in range(n)] inp = lambda :int(input()) ip = lambda :[int(w) for w in input().split()] mp = lambda :map(int,input().split()) for _ in range(int(input())): a,b = mp() c,d = mp() if (a == c and b+d == a) or (a==d and b+c == a): print("YES") elif (b == c and a+d == b) or (b==d and a+c == b): print("YES") else: print("NO")
8
PYTHON3
##n = int(input()) ##a = list(map(int, input().split())) ##print(" ".join(map(str, res))) n = int(input()) A = 1234567 B = 123456 C = 1234 for a in range(int(n/A)+1): for b in range(int(n/B)+1): r = n-a*A-b*B if r >= 0 and r%C == 0: print("YES") exit(0) print("NO")
8
PYTHON3
n = input() n = int(n) res = 0 z = [100,20,10,5,1] for x in z: res += n//x n %= x print(res)
7
PYTHON3
#include<iostream> #include<cmath> #include<cstdio> using namespace std; #define rep(i, n) for(int i = 0; i < n; ++i) int x[100], y[100]; int main() { int n; for (int ii = 1;; ++ii) { cin >> n; if (n == 0) break; double res = 0; rep (i, n) cin >> x[i] >> y[i]; rep (i, n) res += x[i] * y[(i + 1) % n] - y[i] * x[(i + 1) % n]; printf("%d %.1lf\n", ii, abs(res / 2)); } }
0
CPP
#include<iostream> #include<string> #include<algorithm> #include<cmath> #include<map> #include<vector> #include<math.h> #include<stdio.h> #define int long long int test[100000], uiop[100000]; using namespace std; signed main() { int n, a, b, c = 0, d = 0, e = 0; cin >> n >> a >> b; c = a, d = b; for (int h = 1; h <= 1000000; h++) { if (h % 2 == 1) { a = a - b; } else { b = a + b; } if (a == c && b == d) { e = h; break; } test[h] = a; uiop[h] = b; } if (n % e == 0) { cout << a << ' ' << b << endl; } else { cout << test[n % e] << ' ' << uiop[n % e] << endl; } }
0
CPP
t = int(input()) while(t): t -= 1 n, x = list(map(int, input().split())) a = input() total = a.count('0') - a.count('1') count = [0, 0] if(total == 0): ans = 0 for i in range(n): count[int(a[i])] += 1 if(x == count[0] - count[1]): ans += 1 if(ans): print(-1) else: print(0) continue ans = int(x % total == 0 and x // total >= 0) for i in range(n-1): count[int(a[i])] += 1 temp = (x - (count[0] - count[1])) if(temp % total == 0 and temp // total >= 0): ans += 1 print(ans)
8
PYTHON3