solution
stringlengths
10
983k
difficulty
int64
0
25
language
stringclasses
2 values
#include <bits/stdc++.h> using namespace std; int T, n, m, p, k, a[8010], sum[8010]; bool can[8010]; int main() { scanf("%d", &T); while (T--) { int ans = 0; scanf("%d", &n); for (int i = 1; i <= n; i++) { can[i] = 0; scanf("%d", &a[i]); sum[i] = sum[i - 1] + a[i]; } for (int i = 1; i <= n; i++) for (int j = i + 1; j <= n; j++) if (sum[j] - sum[i - 1] <= n) can[sum[j] - sum[i - 1]] = true; for (int i = 1; i <= n; i++) if (can[a[i]]) ans++; printf("%d\n", ans); } }
11
CPP
#include <bits/stdc++.h> using namespace std; int n, b; int a[111111]; int main(void) { scanf("%d %d", &n, &b); int tot = 0; int max = 0; for (int i = 0; i < n; i++) { scanf("%d", &a[i]); tot += a[i]; if (max < a[i]) { max = a[i]; } } if (tot + b < max * n) { printf("-1\n"); return 48 - 48; } double mid = (1.0 * tot + b) / n; for (int i = 0; i < n; i++) { printf("%.6f\n", mid - a[i]); } return 48 - 48; }
7
CPP
#include <bits/stdc++.h> using namespace std; string _reset = "\u001b[0m", _yellow = "\u001b[33m", _bold = "\u001b[1m"; void DBG() { cerr << "]" << _reset << endl; } template <class H, class... T> void DBG(H h, T... t) { cerr << to_string(h); if (sizeof...(t)) cerr << ", "; DBG(t...); } const int INF = 1e9 + 7, N = 2002, M = 1e9 + 7; void add(int& a, int b) { a += b; if (a >= M) a -= M; } void solve() { int n; string s, t; cin >> n >> s >> t; for (int i = 0; i < n; i += 2) { if (s[i] != '?') s[i] ^= 1; if (t[i] != '?') t[i] ^= 1; } vector<pair<int, int> > dp(2 * n + 1); dp[n] = {1, 0}; for (int i = 0; i < n; i++) { vector<pair<int, int> > ndp(2 * n + 1); for (int j = 0; j < 2 * n + 1; j++) if (dp[j].first) { for (int x = 0; x < 2; x++) if (s[i] != ('1' ^ x)) { for (int y = 0; y < 2; y++) if (t[i] != ('1' ^ y)) { int nj = j + x - y, cost = 0; if (!(j == n && x == 1 && y == 1)) { if (x) { if (j >= n) add(cost, M - i); else add(cost, i); } if (y) { if (j <= n) add(cost, M - i); else add(cost, i); } } add(ndp[nj].first, dp[j].first); add(ndp[nj].second, dp[j].second); add(ndp[nj].second, int(1LL * dp[j].first * cost % M)); } } } swap(dp, ndp); } cout << dp[n].second << '\n'; } signed main() { std::ios::sync_with_stdio(0); std::cin.tie(0); ; int t; cin >> t; while (t--) solve(); }
12
CPP
#include <bits/stdc++.h> using namespace std; const int N = (int)1e6 + 15; const int inf = 0x3f3f3f3f; int apow[N], invApow[N], inv[N], mp[N]; bool used[N]; int main() { int a, b, p; long long x; while (~scanf("%d%d%d%lld", &a, &b, &p, &x)) { memset(mp, 0x3f, sizeof(mp)); memset(used, false, sizeof(used)); inv[1] = 1; for (int i = 2; i < p; i++) { inv[i] = (((long long)-p / i * inv[p % i]) % p + p) % p; } apow[0] = invApow[0] = 1; mp[1] = 0; int y = p - 1; for (int i = 1; i < p - 1; i++) { apow[i] = (long long)apow[i - 1] * a % p; invApow[i] = inv[apow[i]]; mp[invApow[i]] = min(i, mp[invApow[i]]); y = (!y && apow[i] == 1 ? i : y); } long long ans = 0; for (int n = 0; n < p - 1; n++) { int k = ((n - (long long)b * invApow[n]) % p + p) % p; if (n + (long long)k * (p - 1) > x) { continue; } ans += ((x - n) - (long long)(p - 1) * k) / (p - 1) / p + 1; } printf("%lld\n", ans); } }
11
CPP
print('YES' if (input() + ''.join(reversed(input()))).replace('X', '') \ in (input() + ''.join(reversed(input()))).replace('X', '') * 2 else 'NO')
7
PYTHON3
#include <bits/stdc++.h> #pragma GCC optimize(2) #pragma warning(disable : 4996) using namespace std; const int INF = 0x3f3f3f3f; const long long int INFLL = 0x3f3f3f3f3f3f3f3f; const int maxn = 200010; int a[maxn]; int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); int T; cin >> T; while (T--) { int n, m; cin >> n >> m; int ans = 0; ans += n / 2 * m; if (n & 1) { if (m & 1) { ans += m / 2 + 1; } else ans += m / 2; } cout << ans << endl; } }
7
CPP
d=int(input().split()[1]) h=input().split() for i in range(len(h)): h[i]=int(h[i]) wy=2 for i in range(len(h)-1): if h[i+1]-h[i]==d*2: wy+=1 elif h[i+1]-h[i]>d*2: wy+=2 print(wy)
7
PYTHON3
# Bob quer quebrar a barra de chocolate de modo que cada pedaço tenha uma noz def main(): n = int(input()) barra = input().split() barra = [int(x) for x in barra] i = 0 while i<n and barra[i] == 0: i += 1 f = n-1 while f>=0 and barra[f] == 0: f -= 1 barra = barra[i:f+1] if barra == []: print(0) return soma = [1] for i in range(1,len(barra)): soma.append(soma[-1]+barra[i]) freq = {} for i in range(1,soma[-1]+1): freq[i] = 0 for num in soma: freq[num] += 1 total = 1 for f in freq.values(): total = total*f if soma == []: total = 0 print(total) main()
8
PYTHON3
#define _USE_MATH_DEFINES #include <iostream> #include <sstream> #include <cmath> #include <algorithm> #include <queue> #include <stack> #include <limits> #include <map> #include <string> #include <cstring> #include <set> #include <deque> using namespace std; typedef long long ll; int main(){ string str; map<string,string> encode; map<string,string> decode; encode[" "] = "101"; encode["'"] = "000000"; encode[","] = "000011"; encode["-"] = "10010001"; encode["."] = "010001"; encode["?"] = "000001"; encode["A"] = "100101"; encode["B"] = "10011010"; encode["C"] = "0101"; encode["D"] = "0001"; encode["E"] = "110"; encode["F"] = "01001"; encode["G"] = "10011011"; encode["H"] = "010000"; encode["I"] = "0111"; encode["J"] = "10011000"; encode["K"] = "0110"; encode["L"] = "00100"; encode["M"] = "10011001"; encode["N"] = "10011110"; encode["O"] = "00101"; encode["P"] = "111"; encode["Q"] = "10011111"; encode["R"] = "1000"; encode["S"] = "00110"; encode["T"] = "00111"; encode["U"] = "10011100"; encode["V"] = "10011101"; encode["W"] = "000010"; encode["X"] = "10010010"; encode["Y"] = "10010011"; encode["Z"] = "10010000"; decode["00000"] = "A"; decode["00001"] = "B"; decode["00010"] = "C"; decode["00011"] = "D"; decode["00100"] = "E"; decode["00101"] = "F"; decode["00110"] = "G"; decode["00111"] = "H"; decode["01000"] = "I"; decode["01001"] = "J"; decode["01010"] = "K"; decode["01011"] = "L"; decode["01100"] = "M"; decode["01101"] = "N"; decode["01110"] = "O"; decode["01111"] = "P"; decode["10000"] = "Q"; decode["10001"] = "R"; decode["10010"] = "S"; decode["10011"] = "T"; decode["10100"] = "U"; decode["10101"] = "V"; decode["10110"] = "W"; decode["10111"] = "X"; decode["11000"] = "Y"; decode["11001"] = "Z"; decode["11010"] = " "; decode["11011"] = "."; decode["11100"] = ","; decode["11101"] = "-"; decode["11110"] = "'"; decode["11111"] = "?"; while(getline(cin,str)){ string enc=""; for(int i=0;i<str.size();i++){ enc+=encode[str.substr(i,1)]; } enc+="0000"; string dec=""; for(int i=0;i+5<=enc.size();i+=5){ dec+=decode[enc.substr(i,5)]; } cout << dec << endl; } }
0
CPP
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const long long LL_INF = 0x3f3f3f3f3f3f3f3f; const int INF = 0x3f3f3f3f; inline void cmin(int &x, int y) { if (y < x) x = y; } inline void cmax(int &x, int y) { if (y > x) x = y; } const int MAXN = 100005; int n; long long s[MAXN], difs[MAXN], pdifs[MAXN]; int main() { scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%I64d", &s[i]); sort(s, s + n); for (int i = 0; i < n - 1; i++) difs[i] = s[i + 1] - s[i]; sort(difs, difs + n - 1); for (int i = 0; i < n - 1; i++) pdifs[i] = pdifs[i - 1] + difs[i]; int q; scanf("%d", &q); long long l, r, ans; while (q--) { scanf("%I64d %I64d", &l, &r); long long dif = r - l + 1; int m = lower_bound(difs, difs + n - 1, dif) - difs; --m; ans = pdifs[m] + dif * (n - m - 1); printf("%I64d ", ans); } return 0; }
10
CPP
#include <bits/stdc++.h> using namespace std; int in() { int a; scanf("%d", &a); return a; } int main() { int t, test = 0; cin >> t; while (t--) { string a, b, c; cin >> a >> b >> c; int cheak = 1; for (int i = 0; i < a.length(); i++) { if (a[i] == c[i] || b[i] == c[i]) continue; else { cheak = 0; break; } } if (cheak) cout << "YES\n"; else cout << "NO\n"; } return 0; }
7
CPP
s=input() k=int(input()) if len(set(list(s)))==1:print((len(s)*k)//2);exit() t=[1] for i in range(1,len(s)): if s[i-1]==s[i]:t[-1]+=1 else:t.append(1) a=0 for i in t:a+=(i//2)*k if s[0]==s[-1]: if t[0]%2==t[-1]%2==1:a+=k-1 print(a)
0
PYTHON3
#include <iostream> #include <stdio.h> using namespace std; int main(void) { int n, *A, sousa, num, len = 0; cin >> n; A = new int[n]; for (int i = 0; i < n; i++) { cin >> sousa; if (sousa == 1 || sousa == 0) cin >> num; if (sousa == 0) A[len++] = num; else if (sousa == 1) cout << A[num] << endl; else A[--len] == NULL; } return 0; }
0
CPP
for _ in range(int(input())): x, y = map(int, input().split()) c = list(map(int, input().split())) for i in range(6): c[i] = min(c[i], c[(i + 1) % 6] + c[(i - 1) % 6]) if x >= 0: if y >= x: print(x * c[0] + (y - x) * c[1]) elif y <= 0: print(x * c[5] + abs(y) * c[4]) else: print((x - y) * c[5] + y * c[0]) else: if y <= x: print((x - y) * c[4] + abs(x) * c[3]) elif y >= 0: print(abs(x) * c[2] + y * c[1]) else: print(abs(y) * c[3] + (y - x) * c[2]) # path1=abs(x)*c[0 if x>=0 else 3]+abs(y-x)*c[1 if y-x>=0 else 4] # path2=abs(y)*c[0 if y>=0 else 3]+abs(x-y)*c[5 if x-y>=0 else 2] # path3=abs(y)*c[1 if y>=0 else 4]+abs(x)*c[5 if x>=0 else 2] # print(min(path1,path2,path3))
10
PYTHON3
#include <bits/stdc++.h> using namespace std; int n, u, v; long long sum, V[100010], C[100010]; vector<vector<int> > node, node2; long long getGcd(long long a, long long b) { long long x = a, y = b, z = a % b; while (z) { x = y; y = z; z = x % y; } return y; } long long dfs(int parent, int here) { if (V[here]) { return 1LL; } vector<long long> child; for (int i = 0; i < node[here].size(); ++i) { int there = node[here][i]; if (parent != there) { node2[here].push_back(there); child.push_back(dfs(here, there)); } } if (child.empty()) { printf("%lld\n", sum); exit(0); } long long lcm = child[0]; for (int i = 1; i < (int)child.size(); ++i) { long long gcd = getGcd(lcm, child[i]); lcm = lcm * child[i] / gcd; if (lcm > sum) { printf("%lld\n", sum); exit(0); } } lcm = lcm * (long long)child.size(); if (lcm > sum) { printf("%lld\n", sum); exit(0); } return lcm; } void calc(int here, long long cur) { if (node2[here].empty()) { C[here] = cur; return; } long long left = cur / (long long)node2[here].size(); for (int i = 0; i < node2[here].size(); ++i) { int there = node2[here][i]; calc(there, left); } } bool isPossible() { for (int i = 1; i <= n; ++i) { if (C[i] && C[i] > V[i]) { return false; } } return true; } int main() { scanf("%d", &n); node.resize(n + 1); node2.resize(n + 1); for (int i = 1; i <= n; ++i) { scanf("%lld", &V[i]); sum += V[i]; } for (int i = 0; i < n - 1; ++i) { scanf("%d%d", &u, &v); node[u].push_back(v); node[v].push_back(u); } long long mul = dfs(1, 1); calc(1, mul); long long mmin = 9876543212345LL; for (int i = 1; i <= n; ++i) { if (C[i]) { mmin = min(mmin, V[i] / C[i]); } } long long sol = 0; for (int i = 1; i <= n; ++i) { if (C[i]) { sol += V[i] - C[i] * mmin; } } printf("%lld\n", sol); }
8
CPP
from math import ceil for _ in range(int(input())): divisor = int(input()) # print(ceil(sum(input()))/divisor) sumi = sum(list(map(int,input().split()))) print(ceil((sumi/divisor)))
7
PYTHON3
#include <bits/stdc++.h> using namespace std; const int MAXN = 100000; struct Q { pair<int, int> p; int num; bool operator<(const Q &q) const { return (p < q.p); } }; int ans[MAXN]; vector<Q> hor[MAXN]; vector<Q> ver[MAXN]; vector<Q> dia1[2 * MAXN]; vector<Q> dia2[2 * MAXN]; void doIt(vector<Q> &v) { if (v.size() < 2) return; sort(v.begin(), v.end()); for (int i = 0; i < v.size(); i++) { ans[v[i].num] += 2; if (!i || v.size() - 1 == i) ans[v[i].num]--; } } int main() { int n, m; cin >> n >> m; for (int i = 0; i < m; i++) { Q q; int x, y; cin >> x >> y; x--; y--; q.p.first = x; q.p.second = y; q.num = i; hor[x].push_back(q); ver[y].push_back(q); dia1[(n - 1) + (y - x)].push_back(q); dia2[2 * (n - 1) - (x + y)].push_back(q); } for (int i = 0; i < n; i++) { doIt(hor[i]); doIt(ver[i]); } for (int i = 0; i < 2 * (n - 1); i++) { doIt(dia1[i]); doIt(dia2[i]); } int c[9]; memset(c, 0, sizeof c); for (int i = 0; i < m; i++) c[ans[i]]++; for (int i = 0; i < 8; i++) cout << c[i] << ' '; cout << c[8] << endl; return 0; }
11
CPP
#include <bits/stdc++.h> using namespace std; int k, n; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; long long i = 0; do { i += 5; for (long long j = i; !(j % 5); j /= 5) k++; } while (k < n); if (k == n) cout << 5 << endl << i << " " << i + 1 << " " << i + 2 << " " << i + 3 << " " << i + 4 << endl; else cout << 0 << endl; return 0; }
8
CPP
#include <stdio.h> int main(void) { int N, A; double res = 0; scanf("%d", &N); for (int n = 0; n < N; ++n) { scanf("%d", &A); res += 1.0/A; } printf("%.10f\n", 1.0/res); }
0
CPP
#include <bits/stdc++.h> using namespace std; const int maxA = 100000; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; int trees[n]; for (int i = 0; i < n; i++) cin >> trees[i]; int dp[maxA + 1]; memset(dp, 0, sizeof(dp)); int offset[n]; for (int i = 0; i < n / 2; i++) offset[i] = i; for (int i = n / 2; i < n; i++) offset[i] = n - i - 1; for (int i = 0; i < n; i++) { int firstElem = trees[i] - offset[i]; if (firstElem > 0) { dp[firstElem]++; } } int maxGoodTrees = 1; for (int i = 0; i < maxA + 1; i++) { maxGoodTrees = max(maxGoodTrees, dp[i]); } cout << (n - maxGoodTrees) << '\n'; return 0; }
9
CPP
st = input() s1 = st.upper() s2 = st.lower() k1 = 0 k2 = 0 for i in range(len(st)): if s1[i] != st[i]: k1 += 1 if s2[i] != st[i]: k2 += 1 if (k1 >= k2): print(s2) else: print(s1)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int size[55], father[55]; int findroot(int x) { int root; for (root = x; father[root] != -1; root = father[root]) ; int i; for (; father[x] != -1;) { i = father[x]; father[x] = root; x = i; } return root; } void u(int x, int y) { int xx = findroot(x); int yy = findroot(y); if (xx == yy) return; if (size[xx] > size[yy]) swap(xx, yy); father[xx] = yy; size[yy] += size[xx]; } vector<int> v[48]; int main() { int n, m; scanf("%d%d", &n, &m); int i; for (i = 0; i < n; i++) { size[i] = 1; father[i] = -1; } int x, y; for (i = 0; i < m; i++) { scanf("%d%d", &x, &y); x--; y--; u(x, y); } int x1 = 0, x2 = 0, x3 = 0; for (i = 0; i < n; i++) { if (father[i] != -1) continue; if (size[i] > 3) { printf("-1\n"); return 0; } else if (size[i] == 1) x1++; else if (size[i] == 2) x2++; else if (size[i] == 3) x3++; } if (x2 > x1) { printf("-1\n"); return 0; } for (i = 0; i < n; i++) { v[findroot(i)].push_back(i + 1); if (father[i] != -1) { size[i] = 0; } } for (i = 0; i < n; i++) { if (father[i] != -1) continue; if (size[i] == 3) { printf("%d %d %d\n", v[i][0], v[i][1], v[i][2]); size[i] = 0; } else if (size[i] == 2) { int j; for (j = 0; j < n; j++) { if (size[j] == 1) { size[j] = 0; size[i] = 0; printf("%d %d %d\n", v[j][0], v[i][0], v[i][1]); break; } } } } for (i = 0; i < n; i++) { if (size[i] == 1) { int j, k; for (j = 0; j < n; j++) { if ((size[j] == 1) && (j != i)) { for (k = 0; k < n; k++) { if ((size[k] == 1) && (j != k) && (k != i)) { size[i] = 0; size[j] = 0; size[k] = 0; printf("%d %d %d\n", v[i][0], v[j][0], v[k][0]); break; } } if (size[i] == 0) break; } } } } return 0; }
8
CPP
#include <iostream> using namespace std; int main() { string x,y; cin>>x>>y; if(x[0]==y[2]&&x[1]==y[1]&&x[2]==y[0]) { cout<<"YES"; } else { cout<<"NO"; } return 0; }
0
CPP
#include <bits/stdc++.h> using namespace std; int main(){ long N;cin>>N; cout<<((N-1)*N)/2<<endl; }
0
CPP
def polyhedrons(inputs): my_dict = {"Tetrahedron" : 4, "Cube" : 6, "Octahedron" : 8, "Dodecahedron" : 12, "Icosahedron" : 20} return sum([my_dict[i] for i in inputs]) if __name__ == "__main__": n = int(input()) print(polyhedrons([str(input()) for i in range(n)]))
7
PYTHON3
#include <bits/stdc++.h> using namespace std; const int Maxn = 500, Maxm = 500; int n, m, x[Maxn], y[Maxn], seq[Maxm]; bool canGet(int from) { bool taken[Maxm] = {}; vector<int> ans; for (int i = 0; i < n; i++) if ((i - from) % 2) ans.push_back(-1); else { int prv = (i - 1 + n) % n; int nxt = (i + 1) % n; int need = 0; if (x[prv] == x[i]) need += abs(y[prv] - y[i]); else need += abs(x[prv] - x[i]); if (x[i] == x[nxt]) need += abs(y[i] - y[nxt]); else need += abs(x[i] - x[nxt]); int j; for (j = 0; j < m; j++) if (!taken[j] && seq[j] == need) break; if (j == m) return false; ans.push_back(j + 1); taken[j] = true; } cout << "YES\n"; for (int i = 0; i < ans.size(); i++) { if (i) cout << " "; cout << ans[i]; } cout << endl; return true; } int main() { cin >> n >> m; for (int i = 0; i < n; i++) cin >> x[i] >> y[i]; for (int i = 0; i < m; i++) cin >> seq[i]; if (!canGet(0)) if (!canGet(1)) cout << "NO\n"; return 0; }
7
CPP
n=int(input()) l=[4,7,47,74,447,474,477,774,747,744] f=0 for i in range(10): if n%l[i]==0 or n==l[i]: print("YES") f=1 break if f==0: print("NO")
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { long long int n; cin >> n; cout << 2 * n - 1 << " " << "2" << endl; cout << "1" << " " << "2" << endl; }
7
CPP
dig = int(input()) if(dig%2==0 and dig!=2): print('YES') else: print('NO')
7
PYTHON3
#include <bits/stdc++.h> using namespace std; bool compare(const pair<int long long, int long long> &a, const pair<int long long, int long long> &b) { return a.second <= b.second; } int long long inline power(int long long a, int long long b, int long long p) { a %= p; int long long ans = 1; while (b > 0) { if (b & 1) ans = (ans * a) % p; a = (a * a) % p; b >>= 1; } return ans; } int long long inv(int long long n, int long long p) { return power(n, p - 2, p); } bool inline isPrime(int long long n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (int long long i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } int long long gcd(int long long a, int long long b) { if (b == 0) return a; return gcd(b, a % b); } const int long long SZ = 4e5 + 5; const int long long b1 = 1e4 + 7; const int long long b2 = 1e9 + 87; const int long long mod2 = 1e9 + 9; struct custom_hash { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; int long long pw1[SZ], pw2[SZ]; int long long h1[3][SZ], h2[3][SZ]; int long long szs[3]; unordered_map<int long long, bool, custom_hash> m1; void cal_pwr() { pw1[0] = pw2[0] = 1; for (int long long i = 1; i < SZ; i++) { pw1[i] = (pw1[i - 1] * b1) % 998244353; pw2[i] = (pw2[i - 1] * b2) % mod2; } } void build_hash(string s, int long long id) { int long long i, sz = s.size(); szs[id] = sz; h1[id][0] = h2[id][0] = 0; for (i = 0; i < sz; i++) { h1[id][i + 1] = ((h1[id][i] * b1) + s[i]) % 998244353; h2[id][i + 1] = ((h2[id][i] * b2) + s[i]) % mod2; } } pair<int long long, int long long> get_hash(int long long l, int long long r, int long long id) { int long long v1 = (h1[id][r] - (h1[id][l - 1] * pw1[r - l + 1])) % 998244353; if (v1 < 0) v1 += 998244353; int long long v2 = (h2[id][r] - (h2[id][l - 1] * pw2[r - l + 1])) % mod2; if (v2 < 0) v2 += mod2; return make_pair(v1, v2); } void solve() { int long long n, m, i, j, k, l, r; cal_pwr(); string s, s1, s2; cin >> s >> s1 >> s2; n = s.size(); int long long n1 = s1.size(); int long long n2 = s2.size(); if (n < max(n1, n2)) { cout << "0\n"; return; } build_hash(s, 0); build_hash(s1, 1); build_hash(s2, 2); for (i = 0; i + max(n1, n2) - 1 < n; i++) { for (j = i + max(n1, n2) - 1; j < n; j++) { pair<int long long, int long long> p1 = get_hash(i + 1, i + n1, 0); pair<int long long, int long long> p2 = get_hash(j + 1 - n2 + 1, j + 1, 0); if (p1.first == h1[1][n1] && p1.second == h2[1][n1] && p2.first == h1[2][n2] && p2.second == h2[2][n2]) { pair<int long long, int long long> p3 = get_hash(i + 1, j + 1, 0); int long long x = ((p3.first << 32LL) | p3.second); m1[x] = 1; } } } cout << m1.size() << "\n"; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int long long t = 1; int long long w = 1; while (t--) { solve(); w++; } }
8
CPP
k=int(input()) print((k//2)*(k//2+k%2))
0
PYTHON3
n = int(input()) x = [i for i in map(int, input().split())] print(sum(x)/len(x))
8
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; int count = 0; for (int i = 0; i < n; i++) { if (s[i] == s[i + 1]) { ++count; } } cout << count; return 0; }
7
CPP
#pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimization("unroll-loops") #include <iostream> //#include <bits/stdc++.h> using namespace std; #include <string.h> #include <utility> #include <algorithm> #include <vector> #include <stack> #include <map> #include <unordered_map> #include <queue> #include <set> #include <math.h> #define ll long long ll max(ll a, ll b) { if (a < b) return b; return a; } ll min(ll a, ll b) { if (a < b) return a; return b; } #define INPUT_OUTPUT freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout) #define all(v) v.begin(), v.end() #define lli unsigned long long int #define f(i, a, b) for (int i = a; i < b; i++) #define here cout << "here\n" #define pp pair<ll, ll> #define vpp vector<pp> #define vii vector<ll> #define ss second #define ff first #define pb push_back #define mp make_pair #define mod 1000000007 #define endl "\n" #define inside ll, vector<ll>, greater<ll> #define Minpq priority_queue<inside> #define Maxpq priority_queue<ll> #define unm unordered_map<ll, ll> #define MAX (1LL << 60) - 1 #define MIN -((1LL << 60) - 1) ll X[] = {-1, 1, 0, 0}; // 4 ll Y[] = {0, 0, -1, 1}; // 4 ll XX[] = {-1, 1, 0, 0, -1, 1, -1, 1}; // 8 ll YY[] = {0, 0, -1, 1, -1, 1, 1, -1}; // 8 ll HX[] = {1, -1, 2, -2, 1, -1, -2, 2}; ll HY[] = {2, -2, 1, -1, -2, 2, 1, -1}; #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) // class req // { // public: // ll len, l, r; // // req(ll a, ll b, ll c) // : len(a), l(b), r(c) {} // }; // make sure that b's value is the desired top values, write priority_queue<req> if spent is max and if spent is equal than ascending by ind // bool operator<(const req &a, const req &b) // { // if (a.len != b.len) // return a.len < b.len; // returns true if descending sort of spent is req // // return a.l > b.l; // return true if ascending sort of ind is req // } ll fpow(ll x, ll n) { ll res = 1; while (n) { if (n & 1) { res = res * x % mod; } x = x * x % mod; n >>= 1; } return (res % mod); } ll binomialCoeff(ll n, ll k) { ll C[n + 1][k + 1]; ll i, j; C[0][0] = 1; for (i = 1; i <= n; i++) { for (j = 0; j <= min(i, k); j++) { // Base Cases if (j == 0 || j == i) C[i][j] = 1; else C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % mod; } } return C[n][k]; } ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); } // Max and min distribute over each other like gcd and lcm, max of min of all pair having A as common is min of A and max of rest, max(min(A,B), min(A,C)) = min(A, max(B,C)) // Neutral element for AND = -1 ( all ones ) , SUM = 0, MULTI = 1, OR = 0 (all zeros ) // advice - always check constraints // 1. brute force // 2. trick , think about: this - (combinations), i & i+k, n^2 to n // 3. gcd/hcf // 4. reverse array, find max, find min, sorting, heap, tree // 5. graph, bfs, dfs //https://cp-algorithms.com //https://oeis.org //vector<vector<ll>> v(n, vector<ll>(m, 0)) // ll **arr = new ll*[n]; f(i,0,n){ arr[i] = new ll [m]}; /* 1. segmentTree, SQRT decomposition, BIT 2. User Comparator, PriorityQueue, Stack, Queue, Deque 3. Sorting, Recursion 4. If a+b=n then if either of them is greater than n/2 other is less than n/2 for sure 5. For less than 1e12, use normal to find prime factor, else 902076349729 = 949777*949777, 916517107801 = 957349*957349, 506623120463 = 47^(x), 34359738368 = 2^(x), 912943012301/974059904437/930881829259 = prime 6. There is prime between n and 3n/2 for n<=1000. WOH ! 7. Prime gap of numbers less than 1e9 doesn't exceed 300 8. Combinotrics- if you have n identical object and r different object number of ways of arrangement is (n+r-1) C (r-1) or (n+r-1) C (n) */ ll getAnswer(vii &v, ll x) { ll ans = 0; for (int i = 0; i < v.size(); i++) { if (v[i] < x) { ans += v[i]; } else ans += v[i] - x; } return ans; } void solve() { ll n; cin >> n; ll arr[n]; f(i, 0, n) cin >> arr[i]; sort(arr, arr + n); vii v; for (int i = 0; i < n;) { int j = i; while (j < n && arr[i] == arr[j]) j++; v.pb(j - i); i = j; } n = v.size(); sort(all(v)); // f(i, 0, v.size()) cout << v[i] << " "; // cout << "\n"; ll sum = 0; f(i, 0, n) sum += v[i]; ll cursum = 0; ll fans = MAX; for (int i = 0; i < n; i++) { ll remsum = sum - cursum; ll ans = cursum + remsum - (n - i) * v[i]; cursum += v[i]; fans = min(ans, fans); } cout << fans << "\n"; } int32_t main() { IOS; ll test = 0; cin >> test; while (test--) solve(); }
12
CPP
# ---------------------------iye ha aam zindegi--------------------------------------------- import math import random import heapq,bisect import sys from collections import deque, defaultdict from fractions import Fraction import sys import threading from collections import defaultdict threading.stack_size(10**8) mod = 10 ** 9 + 7 mod1 = 998244353 # ------------------------------warmup---------------------------- import os import sys from io import BytesIO, IOBase sys.setrecursionlimit(300000) BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") # -------------------game starts now----------------------------------------------------import math class TreeNode: def __init__(self, k, v): self.key = k self.value = v self.left = None self.right = None self.parent = None self.height = 1 self.num_left = 1 self.num_total = 1 class AvlTree: def __init__(self): self._tree = None def add(self, k, v): if not self._tree: self._tree = TreeNode(k, v) return node = self._add(k, v) if node: self._rebalance(node) def _add(self, k, v): node = self._tree while node: if k < node.key: if node.left: node = node.left else: node.left = TreeNode(k, v) node.left.parent = node return node.left elif node.key < k: if node.right: node = node.right else: node.right = TreeNode(k, v) node.right.parent = node return node.right else: node.value = v return @staticmethod def get_height(x): return x.height if x else 0 @staticmethod def get_num_total(x): return x.num_total if x else 0 def _rebalance(self, node): n = node while n: lh = self.get_height(n.left) rh = self.get_height(n.right) n.height = max(lh, rh) + 1 balance_factor = lh - rh n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right) n.num_left = 1 + self.get_num_total(n.left) if balance_factor > 1: if self.get_height(n.left.left) < self.get_height(n.left.right): self._rotate_left(n.left) self._rotate_right(n) elif balance_factor < -1: if self.get_height(n.right.right) < self.get_height(n.right.left): self._rotate_right(n.right) self._rotate_left(n) else: n = n.parent def _remove_one(self, node): """ Side effect!!! Changes node. Node should have exactly one child """ replacement = node.left or node.right if node.parent: if AvlTree._is_left(node): node.parent.left = replacement else: node.parent.right = replacement replacement.parent = node.parent node.parent = None else: self._tree = replacement replacement.parent = None node.left = None node.right = None node.parent = None self._rebalance(replacement) def _remove_leaf(self, node): if node.parent: if AvlTree._is_left(node): node.parent.left = None else: node.parent.right = None self._rebalance(node.parent) else: self._tree = None node.parent = None node.left = None node.right = None def remove(self, k): node = self._get_node(k) if not node: return if AvlTree._is_leaf(node): self._remove_leaf(node) return if node.left and node.right: nxt = AvlTree._get_next(node) node.key = nxt.key node.value = nxt.value if self._is_leaf(nxt): self._remove_leaf(nxt) else: self._remove_one(nxt) self._rebalance(node) else: self._remove_one(node) def get(self, k): node = self._get_node(k) return node.value if node else -1 def _get_node(self, k): if not self._tree: return None node = self._tree while node: if k < node.key: node = node.left elif node.key < k: node = node.right else: return node return None def get_at(self, pos): x = pos + 1 node = self._tree while node: if x < node.num_left: node = node.left elif node.num_left < x: x -= node.num_left node = node.right else: return (node.key, node.value) raise IndexError("Out of ranges") @staticmethod def _is_left(node): return node.parent.left and node.parent.left == node @staticmethod def _is_leaf(node): return node.left is None and node.right is None def _rotate_right(self, node): if not node.parent: self._tree = node.left node.left.parent = None elif AvlTree._is_left(node): node.parent.left = node.left node.left.parent = node.parent else: node.parent.right = node.left node.left.parent = node.parent bk = node.left.right node.left.right = node node.parent = node.left node.left = bk if bk: bk.parent = node node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1 node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right) node.num_left = 1 + self.get_num_total(node.left) def _rotate_left(self, node): if not node.parent: self._tree = node.right node.right.parent = None elif AvlTree._is_left(node): node.parent.left = node.right node.right.parent = node.parent else: node.parent.right = node.right node.right.parent = node.parent bk = node.right.left node.right.left = node node.parent = node.right node.right = bk if bk: bk.parent = node node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1 node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right) node.num_left = 1 + self.get_num_total(node.left) @staticmethod def _get_next(node): if not node.right: return node.parent n = node.right while n.left: n = n.left return n # -----------------------------------------------binary seacrh tree--------------------------------------- class SegmentTree1: def __init__(self, data, default=2*10**9, func=lambda a, b: min(a,b)): """initialize the segment tree with data""" self._default = default self._func = func self._len = len(data) self._size = _size = 1 << (self._len - 1).bit_length() self.data = [default] * (2 * _size) self.data[_size:_size + self._len] = data for i in reversed(range(_size)): self.data[i] = func(self.data[i + i], self.data[i + i + 1]) def __delitem__(self, idx): self[idx] = self._default def __getitem__(self, idx): return self.data[idx + self._size] def __setitem__(self, idx, value): idx += self._size self.data[idx] = value idx >>= 1 while idx: self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1]) idx >>= 1 def __len__(self): return self._len def query(self, start, stop): if start == stop: return self.__getitem__(start) stop += 1 start += self._size stop += self._size res = self._default while start < stop: if start & 1: res = self._func(res, self.data[start]) start += 1 if stop & 1: stop -= 1 res = self._func(res, self.data[stop]) start >>= 1 stop >>= 1 return res def __repr__(self): return "SegmentTree({0})".format(self.data) # -------------------game starts now----------------------------------------------------import math class SegmentTree: def __init__(self, data, default=0, func=lambda a, b: max(a,b)): """initialize the segment tree with data""" self._default = default self._func = func self._len = len(data) self._size = _size = 1 << (self._len - 1).bit_length() self.data = [default] * (2 * _size) self.data[_size:_size + self._len] = data for i in reversed(range(_size)): self.data[i] = func(self.data[i + i], self.data[i + i + 1]) def __delitem__(self, idx): self[idx] = self._default def __getitem__(self, idx): return self.data[idx + self._size] def __setitem__(self, idx, value): idx += self._size self.data[idx] = value idx >>= 1 while idx: self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1]) idx >>= 1 def __len__(self): return self._len def query(self, start, stop): if start == stop: return self.__getitem__(start) stop += 1 start += self._size stop += self._size res = self._default while start < stop: if start & 1: res = self._func(res, self.data[start]) start += 1 if stop & 1: stop -= 1 res = self._func(res, self.data[stop]) start >>= 1 stop >>= 1 return res def __repr__(self): return "SegmentTree({0})".format(self.data) # -------------------------------iye ha chutiya zindegi------------------------------------- class Factorial: def __init__(self, MOD): self.MOD = MOD self.factorials = [1, 1] self.invModulos = [0, 1] self.invFactorial_ = [1, 1] def calc(self, n): if n <= -1: print("Invalid argument to calculate n!") print("n must be non-negative value. But the argument was " + str(n)) exit() if n < len(self.factorials): return self.factorials[n] nextArr = [0] * (n + 1 - len(self.factorials)) initialI = len(self.factorials) prev = self.factorials[-1] m = self.MOD for i in range(initialI, n + 1): prev = nextArr[i - initialI] = prev * i % m self.factorials += nextArr return self.factorials[n] def inv(self, n): if n <= -1: print("Invalid argument to calculate n^(-1)") print("n must be non-negative value. But the argument was " + str(n)) exit() p = self.MOD pi = n % p if pi < len(self.invModulos): return self.invModulos[pi] nextArr = [0] * (n + 1 - len(self.invModulos)) initialI = len(self.invModulos) for i in range(initialI, min(p, n + 1)): next = -self.invModulos[p % i] * (p // i) % p self.invModulos.append(next) return self.invModulos[pi] def invFactorial(self, n): if n <= -1: print("Invalid argument to calculate (n^(-1))!") print("n must be non-negative value. But the argument was " + str(n)) exit() if n < len(self.invFactorial_): return self.invFactorial_[n] self.inv(n) # To make sure already calculated n^-1 nextArr = [0] * (n + 1 - len(self.invFactorial_)) initialI = len(self.invFactorial_) prev = self.invFactorial_[-1] p = self.MOD for i in range(initialI, n + 1): prev = nextArr[i - initialI] = (prev * self.invModulos[i % p]) % p self.invFactorial_ += nextArr return self.invFactorial_[n] class Combination: def __init__(self, MOD): self.MOD = MOD self.factorial = Factorial(MOD) def ncr(self, n, k): if k < 0 or n < k: return 0 k = min(k, n - k) f = self.factorial return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD # --------------------------------------iye ha combinations ka zindegi--------------------------------- def powm(a, n, m): if a == 1 or n == 0: return 1 if n % 2 == 0: s = powm(a, n // 2, m) return s * s % m else: return a * powm(a, n - 1, m) % m # --------------------------------------iye ha power ka zindegi--------------------------------- def sort_list(list1, list2): zipped_pairs = zip(list2, list1) z = [x for _, x in sorted(zipped_pairs)] return z # --------------------------------------------------product---------------------------------------- def product(l): por = 1 for i in range(len(l)): por *= l[i] return por # --------------------------------------------------binary---------------------------------------- def binarySearchCount(arr, n, key): left = 0 right = n - 1 count = 0 while (left <= right): mid = int((right + left) / 2) # Check if middle element is # less than or equal to key if (arr[mid] < key): count = mid + 1 left = mid + 1 # If key is smaller, ignore right half else: right = mid - 1 return count # --------------------------------------------------binary---------------------------------------- def countdig(n): c = 0 while (n > 0): n //= 10 c += 1 return c def binary(x, length): y = bin(x)[2:] return y if len(y) >= length else "0" * (length - len(y)) + y def countGreater(arr, n, k): l = 0 r = n - 1 # Stores the index of the left most element # from the array which is greater than k leftGreater = n # Finds number of elements greater than k while (l <= r): m = int(l + (r - l) / 2) if (arr[m] >= k): leftGreater = m r = m - 1 # If mid element is less than # or equal to k update l else: l = m + 1 # Return the count of elements # greater than k return (n - leftGreater) class TrieNode: def __init__(self): self.children = [None] * 26 self.isEndOfWord = False class Trie: def __init__(self): self.root = self.getNode() def getNode(self): return TrieNode() def _charToIndex(self, ch): return ord(ch) - ord('a') def insert(self, key): pCrawl = self.root length = len(key) for level in range(length): index = self._charToIndex(key[level]) if not pCrawl.children[index]: pCrawl.children[index] = self.getNode() pCrawl = pCrawl.children[index] pCrawl.isEndOfWord = True def search(self, key): pCrawl = self.root length = len(key) for level in range(length): index = self._charToIndex(key[level]) if not pCrawl.children[index]: return False pCrawl = pCrawl.children[index] return pCrawl != None and pCrawl.isEndOfWord #-----------------------------------------trie--------------------------------- class Node: def __init__(self, data): self.data = data self.count=0 self.left = None # left node for 0 self.right = None # right node for 1 class BinaryTrie: def __init__(self): self.root = Node(0) def insert(self, pre_xor): self.temp = self.root for i in range(31, -1, -1): val = pre_xor & (1 << i) if val: if not self.temp.right: self.temp.right = Node(0) self.temp = self.temp.right self.temp.count+=1 if not val: if not self.temp.left: self.temp.left = Node(0) self.temp = self.temp.left self.temp.count += 1 self.temp.data = pre_xor def query(self, xor): self.temp = self.root for i in range(31, -1, -1): val = xor & (1 << i) if not val: if self.temp.left and self.temp.left.count>0: self.temp = self.temp.left elif self.temp.right: self.temp = self.temp.right else: if self.temp.right and self.temp.right.count>0: self.temp = self.temp.right elif self.temp.left: self.temp = self.temp.left self.temp.count-=1 return xor ^ self.temp.data # --------------------------------------------------binary----------------------------------- for ik in range(int(input())): n=int(input()) l=list(map(int,input().split())) s=sorted(set(l+[])) ind=defaultdict(int) for i in range(len(s)): ind[s[i]]=i ma=0 for i in range(n): l[i]=ind[l[i]] ma=max(i,ma) e=[n]*(ma+1) e1=[n] * (ma + 1) e2=[n]*(ma+1) s = SegmentTree1(e) s1=SegmentTree1(e1) s2 = SegmentTree1(e2) nextg=[n]*(n+1) nexts=[n]*(n+1) ind = [n] * (n + 1) ind1 = [n] * (n + 1) for i in range(n-1,-1,-1): nextg[i]=s.query(l[i],ma) nexts[i]=s.query(0,l[i]) s.__setitem__(l[i],i) ind[i]=s1.query(0,l[i]) ind1[i]=s2.query(l[i],ma) s1.__setitem__(l[i],nexts[i]) s2.__setitem__(l[i],nextg[i]) e[l[i]]=i end=[0]*n for i in range(n): end[i]=min(ind[i],ind1[i])-1 ans=1 for i in range(n-2,-1,-1): end[i]=min(end[i],end[i+1]) ans+=end[i]-i+1 print(ans)
9
PYTHON3
n, m = map(int, input().split()) mat1 = [] mat2 = [] for i in range(n): mat1.append(list(map(int, input().split()))) for i in range(n): mat2.append(list(map(int, input().split()))) flag = 1 # Along row for i in range(n): s1 = sum(mat1[i]) s2 = sum(mat2[i]) if s1 % 2 != s2 % 2: flag = 0 break for i in range(m): s1 = 0 s2 = 0 for j in range(n): s1 += mat1[j][i] s2 += mat2[j][i] if s1 % 2 != s2 % 2: flag = 0 break if flag: print("Yes") else: print("No")
9
PYTHON3
#include <bits/stdc++.h> using namespace std; double a, b, l; double pi = acos((double)-1); inline double solve() { if (a > b) swap(a, b); if (l <= a) return l; else if (l <= b) return a; else { double th = atan(cbrt(a / b)); double maxl = b / cos(th) + a / sin(th); if (l > maxl + 1e-7) return -1000; double ll = 0, rr = pi / 2; for (int k = 0; k < 50; k++) { double mm = (ll + rr) / 2; double d = -a * sin(mm) + b * cos(mm) - l * cos(2 * mm); if (d < 0) ll = mm; else rr = mm; } return a * cos(ll) + b * sin(ll) - l * sin(2 * ll) / 2; } } int main() { scanf("%lf%lf%lf", &a, &b, &l); double t = solve(); if (t >= 0) printf("%.7lf\n", solve()); else puts("My poor head =("); }
11
CPP
nRooms=int(input()) n=0 for i in range(nRooms): actual=str(input()).split(' ') if (int(actual[1])-int(actual[0])>=2): n+=1 print(n)
7
PYTHON3
z=int(input("")) x=list() for i in range(0,z): a=input("") x.append(a) for j in range(0,z): a=len(x[j]) if a<=10: print(x[j]) else: print(x[j][0]+str(a-2)+x[j][a-1])
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, x, ans = 1, y; map<int, int> m; map<int, int>::iterator p; vector<int> v, t; cin >> n; for (int(q) = 0; (q) < (n); (q)++) { cin >> x; v.push_back(x); } for (int(q) = 0; (q) < (n); (q)++) { for (int i = q + 1; i < n; i++) { y = v[q] + v[i]; p = m.find(y); if (p != m.end()) { p->second++; ans = max(p->second, ans); } else m.insert(pair<int, int>(y, 1)); } } cout << ans << endl; }
8
CPP
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } vector<vector<int> > v; pair<int, int> f(int a, int b) { int ri = a, rj = b; int t = v[a][b]; for (int i = a; i < v.size(); ++i) { for (int j = (i == a ? b : 0); j < v[i].size(); ++j) { if (v[i][j] < t) { ri = i; rj = j; t = v[i][j]; } } } return make_pair(ri, rj); } struct A { int a, b, c, d; A(int a = 0, int b = 0, int c = 0, int d = 0) : a(a), b(b), c(c), d(d) {} }; int main() { int n; cin >> n; v.resize(n); vector<int> c(n); for (int i = 0; i < n; ++i) { cin >> c[i]; v[i].resize(c[i]); } for (int i = 0; i < n; ++i) for (int j = 0; j < v[i].size(); ++j) cin >> v[i][j]; vector<A> rz; for (int i = 0; i < n; ++i) { for (int j = 0; j < v[i].size(); ++j) { pair<int, int> t = f(i, j); if (t.first != i || t.second != j) { swap(v[i][j], v[t.first][t.second]); rz.push_back(A(i, j, t.first, t.second)); } } } cout << rz.size() << endl; for (int i = 0; i < rz.size(); ++i) { printf("%d %d %d %d\n", rz[i].a + 1, rz[i].b + 1, rz[i].c + 1, rz[i].d + 1); } return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; const long long int MAX = 1e6 + 5; const int N = 2e5 + 5; const long long int mod = 1e9 + 7; const long long int mx = 1e16; bool comp(const int a, const int b) { return a > b; } const double PI = 2 * acos(0.0); long long int fac[N]; void pre() { fac[0] = 1LL; for (long long int i = 1; i < N; i++) { fac[i] = 1LL * i * fac[i - 1]; if (fac[i] >= mod) fac[i] %= mod; } } long long int power(long long int a, long long int b) { long long int x = 1; while (b) { if (b & 1) { x *= a; if (x >= mod) x %= mod; } a *= a; if (a >= mod) a %= mod; b >>= 1; } return x; } long long int inv(long long int k) { return power(k, mod - 2); } int main() { vector<int> v1, v2; int x, t, a, b, da, db; cin >> x >> t >> a >> b >> da >> db; int t1 = t; int t2 = t; int x1 = x; int x2 = x; if (x == 0) { printf("YES\n"); return 0; } for (long long int i = 0; i < t; i++) { if (a - i * da == x || b - i * db == x) { printf("YES\n"); return 0; } } for (long long int i = 0; i < t; i++) { for (long long int j = 0; j < t; j++) { int res = a - i * da + b - j * db; if (res == x) { printf("YES\n"); return 0; } } } printf("NO\n"); }
7
CPP
n = int(input()) s = input() f = [n + 1] * (n + 1) cur, total, ans = 0, 0, 0 for i in range(n - 1, -1, -1): if s[i] == '1': cur += 1 total += f[cur] - i - 1 else: while cur: f[cur] = i + 1 + cur cur -= 1 ans += total print(ans)
12
PYTHON3
from sys import stdout,stdin,maxsize from collections import defaultdict,deque t=int(stdin.readline()) for _ in range(t): n=int(stdin.readline()) #n,m=map(int,stdin.readline().split()) l=list(map(int,stdin.readline().split())) m=max(l)*(n-1) s=sum(l) ans=0 if m>=s: print(m-s) else: if s%(n-1)==0: print(0) else: print((n-1)-s%(n-1))
8
PYTHON3
a = int(input()) b = int(input()) c = int(input()) if a<1 or b<2 or c<4: print(0) else: m = min(a,b//2,c//4) print(m*7)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; template <typename F, typename S> ostream& operator<<(ostream& os, const pair<F, S>& p) { return os << "(" << p.first << ", " << p.second << ")"; } template <class T> ostream& operator<<(ostream& os, vector<T> const& x) { os << "{ "; for (auto& y : x) os << y << " "; return os << "}"; } template <class T> ostream& operator<<(ostream& os, set<T> const& x) { os << "{ "; for (auto& y : x) os << y << " "; return os << "}"; } template <typename T> ostream& operator<<(ostream& os, const multiset<T>& v) { os << "["; typename multiset<T>::const_iterator it; for (it = v.begin(); it != v.end(); it++) { if (it != v.begin()) os << ", "; os << *it; } return os << "]"; } template <typename F, typename S> ostream& operator<<(ostream& os, const map<F, S>& v) { os << "["; typename map<F, S>::const_iterator it; for (it = v.begin(); it != v.end(); it++) { if (it != v.begin()) os << ", "; os << it->first << " = " << it->second; } return os << "]"; } string s[200]; vector<pair<int, int> > ans; void cng(int x1, int y1, int x2, int y2, int x3, int y3) { s[x1][y1] = s[x1][y1] == '1' ? '0' : '1'; s[x2][y2] = s[x2][y2] == '1' ? '0' : '1'; s[x3][y3] = s[x3][y3] == '1' ? '0' : '1'; ans.push_back({x1, y1}); ans.push_back({x2, y2}); ans.push_back({x3, y3}); } void _main_main() { int n, m; cin >> n >> m; for (int i = 0; i < n; i++) cin >> s[i]; ans.clear(); for (int i = 0; i < n - 2; i++) { for (int j = 0; j < m - 1; j++) { if (s[i][j] == '1') cng(i, j, i, j + 1, i + 1, j); } if (s[i][m - 1] == '1') cng(i, m - 1, i + 1, m - 1, i + 1, m - 2); } for (int j = 0; j < m - 2; j++) { if (s[n - 2][j] == '1') cng(n - 2, j, n - 2, j + 1, n - 1, j + 1); if (s[n - 1][j] == '1') cng(n - 1, j, n - 2, j + 1, n - 1, j + 1); } int j = m - 2; while (1) { int cnt = 0; if (s[n - 2][j] == '1') cnt++; if (s[n - 2][j + 1] == '1') cnt++; if (s[n - 1][j] == '1') cnt++; if (s[n - 1][j + 1] == '1') cnt++; if (cnt == 0) break; else if (cnt == 1) { if (s[n - 2][j] == '1') cng(n - 2, j, n - 2, j + 1, n - 1, j); else if (s[n - 2][j + 1] == '1') cng(n - 2, j, n - 2, j + 1, n - 1, j); else if (s[n - 1][j] == '1') cng(n - 2, j, n - 2, j + 1, n - 1, j); else if (s[n - 1][j + 1] == '1') cng(n - 1, j + 1, n - 2, j + 1, n - 1, j); } else if (cnt == 2) { if (s[n - 2][j] == '1') cng(n - 1, j + 1, n - 2, j + 1, n - 1, j); else if (s[n - 2][j + 1] == '1') cng(n - 2, j, n - 1, j + 1, n - 1, j); else if (s[n - 1][j] == '1') cng(n - 2, j, n - 2, j + 1, n - 1, j + 1); else if (s[n - 1][j + 1] == '1') cng(n - 2, j, n - 2, j + 1, n - 1, j); } else if (cnt == 3) { if (s[n - 2][j] == '0') cng(n - 1, j + 1, n - 2, j + 1, n - 1, j); else if (s[n - 2][j + 1] == '0') cng(n - 2, j, n - 1, j + 1, n - 1, j); else if (s[n - 1][j] == '0') cng(n - 2, j, n - 2, j + 1, n - 1, j + 1); else if (s[n - 1][j + 1] == '0') cng(n - 2, j, n - 2, j + 1, n - 1, j); } else { cng(n - 2, j, n - 2, j + 1, n - 1, j); } } cout << ans.size() / 3 << endl; int cnt = 0; for (auto i : ans) { cnt++; cout << i.first + 1 << " " << i.second + 1 << " "; if (cnt == 3) { cnt = 0; cout << endl; } } } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int testCase = 1; cin >> testCase; for (int i = 0; i < testCase; i++) { _main_main(); } }
7
CPP
n=int(input()) a=[] fin=[] for i in range(n): b=input() v=[0]*len(b) a.append(b) fin.append(v) for i in range(n): for j in range(n): if(a[i][j]=='#'): fin[i][j]=1 for i in range(1,n-1): for j in range(1,len(a[i])-1): if(a[i][j]=='.' and a[i-1][j]=='.' and a[i][j+1]=='.' and a[i][j-1]=='.' and a[i+1][j]=='.' and fin[i][j]==0 and fin[i-1][j]==0 and fin[i][j+1]==0 and fin[i][j-1]==0 and fin[i+1][j]==0): fin[i][j]=fin[i-1][j]=fin[i][j+1]=fin[i][j-1]=fin[i+1][j]=1 poss=0 for i in range(n): for j in range(n): if(fin[i][j]==0): poss=1 break if(poss): print('NO') else: print('YES')
8
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf("%d", &n); int arr[n]; int mn = 100000, idx; for (int i = 0; i < n; i++) { scanf("%d", &arr[i]); if (arr[i] < mn) { mn = arr[i]; idx = i + 1; } } if (n == 1) { printf("-1"); return 0; } else if ((n == 2) && (arr[0] == arr[1])) { printf("-1"); return 0; } printf("1\n"); printf("%d\n", idx); return 0; }
7
CPP
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; long long ppow(long x, long s) { if (!s) return 1; if (!(s - 1)) return x % mod; if (s % 2) return (x * ppow(x, s - 1)) % mod; long long b = ppow(x, s / 2); return (b * b) % mod; } int main() { long long n, k, i, m, divisioni = 0; cin >> n >> k; while ((n % 5 == 0) && (divisioni < k)) { n = n / 5; divisioni++; } divisioni = 0; while ((n % 2 == 0) && (divisioni < k)) { n = n / 2; divisioni++; } cout << n * ppow(10, k); return 0; }
7
CPP
def isPrime(n) : if (n <= 1) : return False if (n <= 3) : return True if (n % 2 == 0 or n % 3 == 0) : return False i = 5 while(i * i <= n) : if (n % i == 0 or n % (i + 2) == 0) : return False i = i + 6 return True n,m=map(int,input().split()) if(isPrime(m) != True): print("NO") else: flag=0 n+=1 while(flag==0): if(isPrime(n)): nex=n break else: n+=1 if(nex==m): print("YES") else: print("NO")
7
PYTHON3
n=int(input()) s=input() print(max([len(set(s[:i])&set(s[i:])) for i in range(1,n)]))
0
PYTHON3
#include <bits/stdc++.h> using namespace std; vector<int> st; vector<int> p; const int INF = 2e7; void update(int v, int tl, int tr, int pos) { if (tl == tr) { st[v] = INF; return; } int m = (tl + tr) >> 1; int vl = v * 2 + 1; int vr = v * 2 + 2; if (pos <= m) { update(vl, tl, m, pos); } else { update(vr, m + 1, tr, pos); } st[v] = min(st[vl], st[vr]); } pair<int, int> getBorders(int v, int tl, int tr, int pos, int val) { if (st[v] >= val) { return make_pair(tl, tr); } if (tl == tr) { return make_pair(tl + 1, tr - 1); } int m = (tl + tr) >> 1; int vl = v * 2 + 1; int vr = v * 2 + 2; if (pos <= m) { pair<int, int> lBorders = getBorders(vl, tl, m, pos, val); if (lBorders.second == m) { pair<int, int> rBorders = getBorders(vr, m + 1, tr, pos, val); if (rBorders.first == m + 1) { return make_pair(lBorders.first, rBorders.second); } } return lBorders; } else { pair<int, int> rBorders = getBorders(vr, m + 1, tr, pos, val); if (rBorders.first == m + 1) { pair<int, int> lBorders = getBorders(vl, tl, m, pos, val); if (lBorders.second == m) { return make_pair(lBorders.first, rBorders.second); } } return rBorders; } } void build(int v, int tl, int tr) { if (tl == tr) { st[v] = p[tl]; return; } int m = (tl + tr) >> 1; int vl = v * 2 + 1; int vr = v * 2 + 2; build(vl, tl, m); build(vr, m + 1, tr); st[v] = min(st[vl], st[vr]); } class Fenwick { private: vector<int> a; int sum(int r) { int sum = 0; while (r >= 0) { sum += a[r]; r &= r + 1; --r; } return sum; } public: Fenwick(int size) { a.resize(size); } int sum(int l, int r) { return sum(r) - sum(l - 1); } void update(int pos) { while (pos < a.size()) { a[pos] += 1; pos |= pos + 1; } } }; int main() { ios::sync_with_stdio(false); int n, k; cin >> n >> k; st.resize(4 * n); p.resize(n); vector<int> positions(n + 1); for (int i = 0; i < n; ++i) { cin >> p[i]; positions[p[i]] = i; } vector<bool> isDel(n + 1, true); for (int i = 0; i < k; ++i) { int b; cin >> b; isDel[b] = false; } build(0, 0, n - 1); Fenwick f(n); long long ans = 0; for (int val = 1; val < n + 1; ++val) { if (!isDel[val]) { continue; } int pos = positions[val]; pair<int, int> borders = getBorders(0, 0, n - 1, pos, val); int spaces = f.sum(borders.first, borders.second); update(0, 0, n - 1, pos); f.update(pos); ans += (borders.second - borders.first + 1) - spaces; } cout << ans << '\n'; return 0; }
11
CPP
nn=int(input(),2) a=0 while pow(4,a)<nn: a+=1 print(a)
7
PYTHON3
# E import collections N = int(input()) A = list(map(int, input().split())) d = dict(collections.Counter([i + A[i] for i in range(N)])) ans = sum([d.get(i - A[i], 0) for i in range(N)]) print(ans)
0
PYTHON3
#!/usr/bin/env pypy """ Created on Mon Dec 14 13:18:46 2020 @author: yash """ """ _ _ ____ _ ____ | | __ _(_) / ___|| |__ _ __ ___ ___ | _ \ __ _ _ __ ___ _ | |/ _` | | \___ \| '_ \| '__/ _ \/ _ \ | |_) / _` | '_ ` _ \ | |_| | (_| | | ___) | | | | | | __/ __/ | _ < (_| | | | | | | \___/ \__,_|_| |____/|_| |_|_| \___|\___| |_| \_\__,_|_| |_| |_| """ """ """ """ ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░████████░░░░░░░░░░░░░░░░░░░░ ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████████░░░░░░░░░░░░░░░░░▌░░░ ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░◐◐◐█████████▀▀▀▀▀▀🔥░░░░░░░░███ ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████████░░░░░░░░░░░░░░░░░░░░▌░░░ ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████████░░░░░░░░░░░░░░░░░░░░█▌░░░ ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░▄▄▀█████████████████████████████████████████████████ ░░░░░░░░░░░░░░░░░░░░░░░░░░▄▄▄████▄████████ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ████ ░░░░░░░░░░░░░░░░░░░░░░░░░░░▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀█████████▀▀▀▀▀▀▀▀▀ ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████████░░░░░░░░░░░░░░░░░░░░░░ ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░◐◐◐█████████▀▀▀▀▀▀🔥░░░░░░░░░░ ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████████░░░░░░░░░░░░░░░░░░░░ ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████████░░░░░░░░░░░░░░░░░░░ ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░████████░░░░░░░░░░░░░░░░░░ ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░███████░░░░░░░░░░░░░░░░░ ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░██████░░░░░░░░░░░░░░░░ ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████░░░░░░░░░░░░░░░ """ """ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#@#@@#@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@##@M@M # #@@@M@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#@@@@#@@ @@@@@@M@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#@@### #@@B@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#@@B@@#@@@@@#M@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#@##@@M@#@@##@##@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#@@#M@@@@@##@M@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@##@@@@@@#@##@#@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#@@# @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@M@@ # @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#@@#@@#@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @# @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @# @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#@@#@@#@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@M@@ # @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#@@# @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ @@#@@#@@@@@@@@@@@@@@@@@#@@#@#@@@@@@@@@@@@@@@@@@@@@#@#@@@@@@@@@@@@@@@@@@@@@@@@@ @ #@@@@@@@@@@@@@@@@@@@@#@@@@@@#@@@@@@@@@@@@@@@@@#@#@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ @@#@#@@@@@@@@@@@@@@@@@@#@####@@@@@@@@@@@@@@@@@M@#@@#@#@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@#@#M@@@M@@@@@@@@@@@@@@@@@@@M@@@@@@@@@@@@@@@@@@@@@@@@@@@@ #@M@#@#@@@@@@@@@@@@@@@@@@#@@@@@@@@@@@@@@@@@@@@@@@@M@@M@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@#@@#@@@@@@@@@@@@@@@@@@@@M@M@#@@@@@@@@@@@@@@@@@@@@@@@#@@@@@@@@@@@@@@@@@@@@@@@@ @@#@@#@@@@@@@@@@@@@@@@@@@@@@@M@ @M@@#@@@@@@@@@@@@@@@@@@@@@@@@@ @#@@@@@#@@@@@@@@@@@@@@@@@@@#@@ @@@@M@@@@@@@@@@@@@@@@@@@@@@@@ @@@#@@@##@@@#@@@@@#@@@@@##@@@@ #@#@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@####@@####@@@@#@@@@M@@@#@@# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @#@ @#@@#@@@ #@ @ #@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @# @@#@@ #@@#@@@@@@@@@@@@@@@@@@@@@@@@@ ##@#@@ #M @# @@ @@M @@@@@@@@@@@@@@@@@@@@@@@@ @#@@@M #@ #@ # @@ @@@@@@@@@@@@@@@@@@@@@@@@ @@ @@#@@ ## @##@@ @@@@@@@@@@@@@@@@@@@@@@@@ @# @@M@ @@ @@@@@@@@@@@@@@@@@@@@@@@@ @@@##@@@ @@@@ @@@ @@ #@#@@#@@@@@@@@@@@@@@@@@ @@@@###@@###@@@@#@#@@@@#@@@ M@ #@ @ B @@@#@@@@@@@@@@@@@@@@@@@ @M@@@@@MM@@@@@M@@#@##@@@#@@M@B @# M@ @# #@ #@@#@@@@@@@@@@@@@@@@@@@ @#@#@@M@@M@@#@#@#@#@@#@#@#@@@@ @# @@ # @M @#@@@@@@@@@@@@@@@@@@@@@ @@@ @@@@#@##@ #@# @M # @ @ @@@@@#@@@@@@@@@@@@@@@@@ @@ @@ @#@@#@@#M #@@@@#@@@@@@@@@@@@@@@@@ M@# #@ @@@@##@@ @M@#M@@@#@@@@@@@@@@@@@@@@ @@@@ @@ @@@#@@@#@#@@@@@@@@@@@@@@@@ @# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @M@H@@ @# @#@@@@#@@@#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@#@#@##@M@@@M@ @M#@@@@@#@@#@@#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ #M@@@##@@@@@@@@M@@@@#@@#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@#@@@@@M@#@M@@B#M@@M@###@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ###@@@@@@@@@# @#@@@@@@@#@@@#@##@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@#@@M@@@#@@#@#@@@@@@#@@@#@#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#@M@#@# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@M@@@@# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#@@@@@#@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@M@@## @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#@@#@M @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@###@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#@@@@@#@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@# #@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@# #@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ """ """ / \ //\ |\___/| / \// \\ /0 0 \__ / // | \ \ / / \/_/ // | \ \ @_^_@'/ \/_ // | \ \ //_^_/ \/_ // | \ \ ( //) | \/// | \ \ ( / /) _|_ / ) // | \ _\ ( // /) '/,_ _ _/ ( ; -. | _ _\.-~ .-~~~^-. (( / / )) ,-{ _ `-.|.-~-. .~ `. (( // / )) '/\ / ~-. _ .-~ .-~^-. \ (( /// )) `. { } / \ \ (( / )) .----~-.\ \-' .~ \ `. \^-. ///.----..> \ _ -~ `. ^-` ^-_ ///-._ _ _ _ _ _ _}^ - - - - ~ ~-- ,.-~ /.-~ """ """ ____ _ _____ / ___|___ __| | ___| ___|__ _ __ ___ ___ ___ | | / _ \ / _` |/ _ \ |_ / _ \| '__/ __/ _ \/ __| | |__| (_) | (_| | __/ _| (_) | | | (_| __/\__ \ \____\___/ \__,_|\___|_| \___/|_| \___\___||___/ """ """ ░░██▄░░░░░░░░░░░▄██ ░▄▀░█▄░░░░░░░░▄█░░█░ ░█░▄░█▄░░░░░░▄█░▄░█░ ░█░██████████████▄█░ ░█████▀▀████▀▀█████░ ▄█▀█▀░░░████░░░▀▀███ ██░░▀████▀▀████▀░░██ ██░░░░█▀░░░░▀█░░░░██ ███▄░░░░░░░░░░░░▄███ ░▀███▄░░████░░▄███▀░ ░░░▀██▄░▀██▀░▄██▀░░░ ░░░░░░▀██████▀░░░░░░ ░░░░░░░░░░░░░░░░░░░░ """ """░░██▄░░░░░░░░░░░▄██ ░▄▀░█▄░░░░░░░░▄█░░█░ ░█░▄░█▄░░░░░░▄█░▄░█░ ░█░██████████████▄█░ ░█████▀▀████▀▀█████░ ▄█▀█▀░░░████░░░▀▀███ ██░░▀████▀▀████▀░░██ ██░░░░█▀░░░░▀█░░░░██ ███▄░░░░░░░░░░░░▄███ ░▀███▄░░████░░▄███▀░ ░░░▀██▄░▀██▀░▄██▀░░░ ░░░░░░▀██████▀░░░░░░ ░░░░░░░░░░░░░░░░░░░░ """ """ # Codeforces Round #186 (Div. 2), problem: (A) Ilya and Bank Account n = int(input()) if n > 0: print(n) else: s = str(n) if s[len(s)-1] < s[len(s)-2] and s[len(s)-2] != '0': print(int(s[:len(s)-2] + s[len(s)-1:])) elif s[len(s)-1] > s[len(s)-2] and s[len(s)-1] != '0': print(int(s[:len(s)-1])) else: print(int(s[:len(s)-1])) """ """ # Codeforces Round #261 (Div. 2), problem: (A) Pashmak and Garden, x1, y1, x2, y2=map(int,input().split()) l=abs(x1-x2) m=abs(y1-y2) if x1==x2: print(x1+m,y1,x2+m,y2) elif y1==y2: print(x1,y1+l,x2,y2+l) elif l!=m: print(-1) else: print(x1,y2,x2,y1) """ """ # Codeforces Round #142 (Div. 2), problem: (A) Dragons def solve(): s, n = map(int, input().split()) sets = [] for _ in range(n): ith, bonus = map(int, input().split()) sets.append([ith, bonus]) sets.sort(key=lambda x: x[0]) for i in sets: if i[0] < s: s += i[1] else: return "NO" return "YES" print(solve()) """ """ # Codeforces Round #690 (Div. 3) # (A) Favorite Sequence- for _ in range(int(input())): n = int(input()) l = list(map(int, input().split())) ans = [] k = n//2 start = 0 end = len(l)-1 while start <= end: if start != end: ans.append(l[start]) ans.append(l[end]) else: ans.append(l[end]) start += 1 end -= 1 for i in ans: print(i, end=" ") print() # B) Last Year's Substring- for _ in range(int(input())): n = int(input()) s = input() if s[0]+s[1] == '20' and s[-2]+s[-1] == '20': print("YES") elif s[0] == '2' and s[-3]+s[-2]+s[-1] == '020': print("YES") elif s[0]+s[1]+s[2] == '202' and s[-1] == '0': print("YES") elif s[0]+s[1]+s[2]+s[3] == '2020': print("YES") elif s[-4]+s[-3]+s[-2]+s[-1] == '2020': print("YES") else: print("NO") """ """ # Codeforces Round #251 (Div. 2) n, d = map(int, input().split()) l = list(map(int, input().split())) if (sum(l) + (n-1)*10) > d: print(-1) else: print((d-sum(l))//5) """ """ # Codeforces Round #290 (Div. 2) n,m=map(int,input().split()) for i in range(n): if i % 4 == 0: print('#'*m) elif i % 4 == 1: print('.'*(m-1)+'#') elif i % 4 == 2: print('#'*m) else: print('#'+'.'*(m-1)) n,m=map(int,input().split()) for i in range(n): print(['#'*m,'.'*(m-1)+'#','#'*m,'#'+'.'*(m-1)][i%4]) """ """ # Educational Codeforces Round 100 (Rated for Div. 2) # problem: (A) Dungeon def solve(a, b, c): s = a+b+c k = s//9 if s % 9 == 0 and a >= k and b >=k and c >= k: return "YES" else: return "NO" for _ in range(int(input())): a, b, c = map(int, input().split()) print(solve(a, b, c)) # problem: (B) Find The Array for _ in range(int(input())): n = int(input()) l = list(map(int, input().split())) even = 0 odd = 0 for i in range(len(l)): if i % 2 == 0: even += l[i] else: odd += l[i] if even < odd: for i in range(len(l)): if i % 2 == 0: l[i] = 1 print(l[i], end=" ") else: print(l[i], end=" ") else: for i in range(len(l)): if i % 2 == 0: print(l[i], end=" ") else: l[i] = 1 print(l[i], end=" ") """ """ # Codeforces Beta Round #25 (Div. 2 Only), problem: (A) IQ test n = int(input()) nums = list(map(int, input().split())) even = 0 odd = 0 counter1 = 0 counter2 = 0 for i in range(len(nums)): if nums[i]%2 == 0: counter1+=1 even = i+1 else: counter2+=1 odd = i+1 if counter1 == 1: print(even) else: print(odd) """ """ # Codeforces Round #246 (Div. 2), problem: (A) Choosing Teams n, k = map(int, input().split()) l = list(map(int, input().split())) counter = 0 for i in range(len(l)): if (5-l[i]) >= k: counter += 1 print(counter//3) """ """ # Codeforces Round #192 (Div. 2), problem: (A) r, c = map(int, input().split()) a = set() b = set() for i in range(r): d = input() for j in range(len(d)): if d[j] == 'S': a.add(j) b.add(i) print(r*c - len(a)*len(b)) """ # n, m = map(int, input().split()) # b = [] # for i in range(n): # if min(list(map(int, input().split()))[1:]) < m: # b.append(i + 1) # print(len(b), '\n', *b) """ # Codeforces Round #691 (Div. 2), problem: (A) Red-Blue Shuffle, for i in range(int(input())): n = int(input()) a = input() b = input() counter_a = 0 counter_b = 0 for j in range(len(a)): if a[j] > b[j]: counter_a += 1 elif a[j] < b[j]: counter_b += 1 if counter_a > counter_b: print("RED") elif counter_a < counter_b: print("BLUE") else: print("EQUAL") """ """ # Codeforces Round #263 (Div. 2), problem: (A) Appleman and Easy Task x = '' for _ in range(int(input())): x += input() if x == x[::-1]: print("YES") else: print("NO") """ """ # Codeforces Round #226 (Div. 2), problem: (A) Bear and Raspberry n, c = map(int, input().split()) l = list(map(int, input().split())) ans = l[0] - l[1] for i in range(1, len(l)-1): ans = max(ans, l[i] - l[i+1]) if ans - c < 0: print(0) else: print(ans-c) """ # n, k = map(int, input().split()) # joy = float("-inf") # for _ in range(n): # f, t = map(int, input().split()) # if t >= k: # joy = max(joy, f - (t - k)) # else: # joy = max(joy, f) # print(joy) """ # Codeforces Round #260 (Div. 2), problem: (A) Laptops, for _ in range(int(input())): a,b=input().split() if a!=b: print('Happy Alex') exit() print('Poor Alex') """ """ # Technocup 2021 - Elimination Round 3: problem: (A) In-game Chat for _ in range(int(input())): n = int(input()) s = input() j = len(s)-1 count = 0 while j >= 0: if s[j] != ')': break count += 1 j -= 1 if count > len(s)-count: print("YES") else: print("NO") """ # def solve(x): # for i in str(x): # if i != '0' and x % int(i) != 0: # return False # return True # t = int(input()) # for _ in range(t): # n = int(input()) # while not solve(n): # n += 1 # print(n) """ # Codeforces Round #222 (Div. 2), problem: (A) Playing with Dice a, b = map(int, input().split()) a_w = 0 b_w = 0 draw = 0 for i in range(1, 7): if abs(i-a) < abs(i-b): a_w += 1 elif abs(i-a) > abs(i-b): b_w += 1 else: draw += 1 print(a_w, draw, b_w) """ """ # Codeforces Round #283 (Div. 2), problem: (A) Minimum Difficulty n=int(input()) l=list(map(int,input().split())) x=max([l[i+1]-l[i] for i in range(n-1)]) y=min([l[i+2]-l[i] for i in range(n-2)]) print(max(x,y)) """ """ # Codeforces Round #156 (Div. 2), problem: (A) Greg's Workout n = int(input()) arr = list(map(int, input().split())) chest_count = 0 biceps_count = 0 back_count = 0 for i in range(len(arr)): if i%3 == 0: chest_count += arr[i] elif i%3 == 1: biceps_count += arr[i] elif i%3 == 2: back_count += arr[i] ans = max(chest_count, biceps_count, back_count) if chest_count == ans: print("chest") elif biceps_count == ans: print("biceps") else: print("back") OR input() arr = [int(i) for i in input().split()] b = [sum(arr[::3]), sum(arr[1::3]), sum(arr[2::3])] c = ['chest', 'biceps', 'back'] print(c[b.index(max(b))]) """ """ # Codeforces Round #275 (Div. 2), problem: (A) Counterexample l, r = map(int, input().split()) if r - l + 1 < 3: print(-1) exit() if l % 2 == 0: print(l, l+1, l+2) exit() if r - l + 1 > 3: print(l+1, l+2, l+3) exit() print(-1) """ """ # Codeforces Round #237 (Div. 2), problem: (A) Valera and X s = '' n = int(input()) for i in range(n): s += input() if s == s[::-1] and s.count(s[0]) == (2*n-1): print("YES") else: print("NO") OR n = int(input()) x, y = set(), set() for i in range(n): line = input() for j in range(n): if i == j or i == n - j - 1: x.add(line[j]) else: y.add(line[j]) if len(x) == 1 and len(y) == 1and x != y: print("YES") else: print("NO") """ """ # Codeforces Round #144 (Div. 2), problem: (A) Perfect Permutation n = int(input()) startIdx = 1 secondIdx = 2 l = [int(i) for i in range(n, 0, -1)] if n%2 == 0: while secondIdx <= n: l.append(secondIdx) l.append(startIdx) startIdx += 2 secondIdx += 2 else: print(-1) OR n=int(input()) if n%2: print(-1) else: print(*range(n,0,-1)) """ """ # Codeforces Round #284 (Div. 2), problem: (A) Watching a movie n, x = map(int, input().split()) minute = 1 for _ in range(n): l, r = map(int, input().split()) difference = l - minute minute = minute + difference%x minute = minute + (r-l+1) print(minute-1) """ """ # Codeforces Round #112 (Div. 2), problem: (A) Supercentral Point, n = int(input()) l = [] for _ in range(n): x, y = map(int, input().split()) l.append([x, y]) ans = 0 for i in range(n): left=right=upper=down = 0 for j in range(n): if l[i][0] > l[j][0] and l[i][1] == l[j][1]: right += 1 if l[i][0] < l[j][0] and l[i][1] == l[j][1]: left += 1 if l[i][0] == l[j][0] and l[i][1] > l[j][1]: upper+= 1 if l[i][0] == l[j][0] and l[i][1] < l[j][1]: down += 1 if (right and left and upper and down): ans += 1 print(ans) OR n = int(input()) l = [] for _ in range(n): x, y = map(int, input().split()) l.append([x, y]) ans = 0 for i in range(n): left=right=upper=down = 0 for j in range(n): if l[i][0] > l[j][0] and l[i][1] == l[j][1]: right = 1 elif l[i][0] < l[j][0] and l[i][1] == l[j][1]: left = 1 elif l[i][0] == l[j][0] and l[i][1] > l[j][1]: upper= 1 elif l[i][0] == l[j][0] and l[i][1] < l[j][1]: down = 1 if right==left==upper==down==1: ans += 1 print(ans) """ """ # Codeforces Round #160 (Div. 2), problem: (A) Roma and Lucky Numbers n, k = map(int, input().split()) arr = list(map(int, input().split())) count = 0 for i in arr: if ((str(i).count('4'))+(str(i).count('7')) <= k): count += 1 print(count) """ """ # A. Contest - Codeforces Round #285 (Div. 2) a, b, t1, t2 = map(int, input().split()) mishra = max((3*a)/10, a - (a/250) * t1) vasya = max((3*b)/10, b - (b/250) * t2) if int(mishra) > int(vasya): print("Misha") elif int(mishra) < int(vasya): print("Vasya") else: print("Tie") """ """ # Codeforces Round #203 (Div. 2), problem: (A) n, m = map(int, input().split()) a = list(map(int, input().split()[:n])) b = list(map(int, input().split()[:m])) v = min(a)*2 p = min(b) c = max(a) if v < p and c < p: print(max(v, c)) else: print(-1) """ """ # Codeforces Round #205 (Div. 2), problem: (A) Domino a = 0 b = 0 check = 0 for _ in range(int(input())): p, q = map(int, input().split()) a += p b += q if (a % 2 == 1 and b % 2 == 0) or (a % 2 == 0 and b % 2 == 1): check += 1 if a % 2 == b % 2 == 0: print(0) elif a % 2 == b % 2 == 1 and check > 0: print(1) else: print(-1) """ """ # Codeforces Beta Round #86 (Div. 2 Only), problem: (A) Cifera k = int(input()) l = int(input()) i = 0 while k**i < l: i += 1 if l == k**i: print("YES") print(i-1) else: print("NO") """ """ # Codeforces Round #181 (Div. 2), problem: (A) Array, n = int(input()) count_negative = 0 l = list(map(int, input().split())) set_A = [] set_B = [] set_C = [] for i in range(n): if l[i] < 0: set_A.append(l[i]) elif l[i] > 0: set_B.append(l[i]) else: set_C.append(l[i]) if len(set_B) == 0: for i in range(2): set_B.append(set_A.pop()) if len(set_A) % 2 == 0: set_C.append(set_A.pop()) print(len(set_A), *set_A) print(len(set_B), *set_B) print(len(set_C), *set_C) """ """ n = int(input()) l = sorted(map(int, input().split())) while len(set(l)) != 1: l[-1] -= l[0] l.sort() print(sum(l)) """ # Codeforces Round #278 (Div. 2), problem: (A) Giga Tower def solve(x): for i in str(x): if i == '8': return True return False t = int(input()) t += 1 s = str(t) count = 1 while not solve(t): count += 1 t += 1 print(count) # if '8' in s: # t += 1 # count = 1 # while not solve(t): # count += 1 # t += 1 # print(count) # else: # s = input() # t = input() # count = 0 # i = 0 # while i < len(t): # if t[i] == s[count]: # count += 1 # i +=1 # print(count+1) # def Sorted(l, key=None): # new_list = list(l) # new_list.sort(key=key) # return new_list # l = [2,1,3,10,3] # print(Sorted(l)) # print(l) #Problem - A # for i in range(int(input())): # arr = list(map(int, input().split())) # arr.sort() # print(arr[0]*arr[2]) #problem - N # for i in range(int(input())): # c1, c2, c3 = map(int, input().split()) # a1, a2, a3, a4, a5 = map(int, input().split()) # if c1 >= a1 and c2 >= a2 and c3 >= a3 and c1+c3 >= a1+a3+a4 and c2+c3 >= a2+a3+a5 and (c1+c2+c3) >= (a1+a2+a3+a4+a5): # print("YES") # else: # print("NO")
7
PYTHON3
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 2e5 + 7; char s[N]; const int MOD = 1e9 + 9; int A, invA; int pw[N]; int add(int a, int b) { a += b; if (a < 0) a += MOD; a %= MOD; return a; } int mul(int a, int b) { return (long long)a * b % MOD; } int bin_mul(int a, int b) { a %= MOD; int res = 1; while (b > 0) { if (b & 1) res = mul(res, a); a = mul(a, a); b >>= 1; } return res; } struct Node { bool first, last; int len, hsh; bool operator==(const Node& other) const { return len == other.len && hsh == other.hsh; } }; Node t[N << 2]; Node combine(Node lhs, Node rhs) { if (lhs.len == 0) return rhs; if (rhs.len == 0) return lhs; if (lhs.last && rhs.first) { lhs.len--; rhs.len--; lhs.hsh = mul(add(lhs.hsh, -1), invA); rhs.hsh = add(rhs.hsh, -pw[rhs.len]); if (lhs.len == 0) lhs.first = false; if (rhs.len == 0) rhs.last = false; } auto new_hsh = add(mul(lhs.hsh, pw[rhs.len]), rhs.hsh); return {lhs.first, rhs.last, lhs.len + rhs.len, new_hsh}; } void build(int v, int l, int r) { if (l == r) { if (s[l] == '0') { t[v] = {false, false, 1, 0}; } else { t[v] = {true, true, 1, 1}; } return; } int mid = (l + r) >> 1; build(v << 1, l, mid); build(v << 1 | 1, mid + 1, r); t[v] = combine(t[v << 1], t[v << 1 | 1]); } Node get(int v, int l, int r, int x, int y) { if (l > y || r < x) return {false, false, 0, 0}; if (l >= x && r <= y) return t[v]; int mid = (l + r) >> 1; return combine(get(v << 1, l, mid, x, y), get(v << 1 | 1, mid + 1, r, x, y)); } int main() { ios::sync_with_stdio(false); cin.tie(0); clock_t ttt = clock(); mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count()); A = rng() % MOD; invA = bin_mul(A, MOD - 2); int n; cin >> n; pw[0] = 1; for (int i = 1; i <= n; ++i) pw[i] = mul(pw[i - 1], A); cin >> (s + 1); int q; cin >> q; build(1, 1, n); while (q--) { int l1, l2, l; cin >> l1 >> l2 >> l; l--; if (get(1, 1, n, l1, l1 + l) == get(1, 1, n, l2, l2 + l)) { cout << "Yes\n"; } else { cout << "No\n"; } } cerr << "Time taken " << (double)(clock() - ttt) / CLOCKS_PER_SEC << " seconds\n"; return 0; }
12
CPP
#include <bits/stdc++.h> using namespace std; bool check(string s, string t) { if (s == "") return true; int tt = 0, sz = s.size(), tz = t.size(); for (int i = 0; i < sz; i++, tt++) { while (tt < tz && t[tt] != s[i]) tt++; if (tt == tz) break; if (i == sz - 1) return true; } return false; } int main(void) { string s, t; cin >> s >> t; int sz = s.size(); bool yes = false; string p = "", q = ""; for (int i = 0; i < sz; i++) { if (i & 1) q += s[i]; else p += s[i]; } yes |= check(p, t) || check(q, t); cout << (yes ? "Yes" : "No") << endl; return 0; }
0
CPP
#include<cstdio> #include<cstring> #include<queue> #include<algorithm> #include<vector> #include<utility> #include<functional> using namespace std; const int INF=1e9; const int ADD=1200; typedef pair<int,int> P; struct edge { int to,cap,cost,rev; }; int V; vector<edge> G[505]; int h[505]; int dist[505]; int prevv[505],preve[505]; void add_edge(int from,int to,int cap,int cost) { edge tmp; tmp.to=to,tmp.cap=cap,tmp.cost=cost,tmp.rev=G[to].size(); G[from].push_back(tmp); tmp.to=from,tmp.cap=0,tmp.cost=-cost,tmp.rev=G[from].size()-1; G[to].push_back(tmp); } int min_cost_flow(int s,int t,int f) { int res=0; fill(h,h+V,0); while(f>0) { priority_queue<P,vector<P>,greater<P>> que; fill(dist,dist+V,INF); dist[s]=0; que.push(P(0,s)); while(!que.empty()) { P p=que.top(); que.pop(); int v=p.second; if(dist[v]<p.first) { continue; } for(int i=0;i<G[v].size();++i) { edge &e=G[v][i]; if(e.cap>0&&dist[e.to]>dist[v]+e.cost+h[v]-h[e.to]) { dist[e.to]=dist[v]+e.cost+h[v]-h[e.to]; prevv[e.to]=v; preve[e.to]=i; que.push(P(dist[e.to],e.to)); } } } if(dist[t]==INF) { return -1; } for(int v=0;v<V;++v) { h[v]+=dist[v]; } int d=f; for(int v=t;v!=s;v=prevv[v]) { d=min(d,G[prevv[v]][preve[v]].cap); } f-=d; res+=d*h[t]; for(int v=t;v!=s;v=prevv[v]) { edge &e=G[prevv[v]][preve[v]]; e.cap-=d; G[v][e.rev].cap+=d; } } return res; } int N,M,s,t; int indree[520],outdree[520]; int main() { scanf("%d%d",&N,&M); V=N+2; t=N+1; int total=0; for(int i=1;i<=M;++i) { int x,y,z; scanf("%d%d%d",&x,&y,&z); ++x,++y; add_edge(x,y,INF,-z); outdree[x]++,indree[y]++; total+=z; } int max_f=0; for(int i=1;i<=N;++i) { if(indree[i]>outdree[i]) { add_edge(s,i,indree[i]-outdree[i],0); max_f+=indree[i]-outdree[i]; } else { add_edge(i,t,outdree[i]-indree[i],0); } } min_cost_flow(1,N,1); add_edge(N,1,INF,-dist[N]); int ans=min_cost_flow(s,t,max_f); printf("%d\n",ans-total); return 0; }
0
CPP
from sys import stdin,stdout input = stdin.readline n,m = map(int,input().split()) s = [False] + [c == '.' for c in list(input())] + [False] res = sum(x&y for (x,y) in zip(s[1:], s[:-1])) res_list = list() for i in range(m): x,c = input().split() x = int(x) nc = c == '.' if s[x] != nc: diff = s[x-1] + s[x+1] res += (-diff,diff) [nc] s[x] = nc res_list.append(res) stdout.write('\n'.join(map(str,res_list)))
9
PYTHON3
a, b, c = tuple(map(int, input().split())) if c == 0: if a == b: print("YES") else: print("NO") else: n = (b - a) // c if n >= 0 and a + n * c == b: print("YES") else: print("NO")
7
PYTHON3
#include <bits/stdc++.h> using namespace std; const long long MAXN = 2e5 + 10; const long long INF = 0x3f3f3f3f; const long long MOD = 1e9 + 7; const long double eps = 1e-9; const long double PI = acos(-1.0); long long n, m; inline long long read() { long long s = 0, w = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') w = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar(); return s * w; } struct qNode { long long v; long long c; qNode(long long _v = 0, long long _c = 0) : v(_v), c(_c) {} bool operator<(const qNode &r) const { return c > r.c; } }; struct Edge { long long v; long long cost; Edge(long long _v = 0, long long _cost = 0) : v(_v), cost(_cost) {} }; vector<Edge> E[MAXN]; bool vis[MAXN]; long long dist[MAXN]; void Dijkstra(long long n, long long start) { memset(vis, false, sizeof(vis)); memset(dist, 0x3f, sizeof(dist)); priority_queue<qNode> que; while (!que.empty()) { que.pop(); } dist[start] = 0; que.push(qNode(start, 0)); qNode tmp; while (!que.empty()) { tmp = que.top(); que.pop(); long long u = tmp.v; if (vis[u]) { continue; } vis[u] = true; for (long long i = 0; i < E[u].size(); i++) { long long v = E[tmp.v][i].v; long long cost = E[u][i].cost; if (!vis[v] && dist[v] > dist[u] + cost) { dist[v] = dist[u] + cost; que.push(qNode(v, dist[v])); } } } } void addEdge(long long u, long long v, long long w) { E[u].push_back(Edge(v, w)); } long long path[MAXN]; long long line[MAXN][2]; long long num[MAXN]; signed main() { cin >> n >> m; for (long long i = 0; i <= n; i++) { E[i].clear(); } for (long long i = 0; i < m; i++) { long long u, v; cin >> u >> v; addEdge(v, u, 1); line[i][0] = u, line[i][1] = v; } long long k; cin >> k; for (long long i = 0; i < k; i++) { path[i] = read(); } Dijkstra(n, path[k - 1]); for (long long i = 0; i < m; i++) { long long u = line[i][0], v = line[i][1]; if (dist[u] - dist[v] == 1) num[u]++; } long long ans1 = 0, ans2 = 0; for (long long i = 1; i < k; i++) { if (dist[path[i - 1]] - dist[path[i]] == 1) { if (num[path[i - 1]] > 1) { ans2++; } } else { ans1++; ans2++; } } cout << ans1 << " " << ans2 << endl; return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; } int visv[300007], ans[300007], us[300007], n, m, d[300007]; vector<pair<int, int> > edge[300007]; int dfs(int nd) { int ret = 0; for (int k = 0; k < edge[nd].size(); k++) { int v = edge[nd][k].first; if (visv[v]) continue; visv[v] = 1; int p = dfs(v); int e = edge[nd][k].second; if (p) ans[e] = 1; ret += p; us[nd] |= us[v]; } ret %= 2; if (d[nd] == -1 || ret == d[nd]) return 0; return 1; } void dfs2(int nd) { if (d[nd] == -1) return; for (int k = 0; k < edge[nd].size(); k++) { int v = edge[nd][k].first; if (visv[v]) continue; visv[v] = 1; if (us[v] == 0) continue; dfs2(v); ans[edge[nd][k].second] ^= 1; return; } } int main() { int i, u, v; scanf("%d %d", &n, &m); for (i = 1; i <= n; i++) { scanf("%d", &d[i]); us[i] = (d[i] == -1); ; } for (i = 1; i <= m; i++) { scanf("%d %d", &u, &v); edge[u].push_back({v, i}); edge[v].push_back({u, i}); } visv[1] = 1; int p = dfs(1); memset(visv, 0, sizeof visv); visv[1] = 1; if (p) { if (!us[1]) return printf("-1\n") & 0; else dfs2(1); } int tot = 0; for (i = 1; i <= m; i++) tot += ans[i]; printf("%d\n", tot); for (i = 1; i <= m; i++) if (ans[i]) printf("%d\n", i); return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; const int MAXN = 35005; const int MAXK = 55; int n, m; int a[MAXN]; int dp[MAXK][MAXN]; int tran[MAXK][MAXN]; int last[MAXN]; int val[MAXN]; int updated[MAXN]; void get_last() { int rec[MAXN]; memset(rec, 0, sizeof(int) * n + 5); for (int i = 1; i <= n; i++) { last[i] = rec[a[i]]; rec[a[i]] = i; } } int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); get_last(); for (int i = 1; i <= n; i++) { for (int k = min(i, m); k >= 1; k--) { int l = max(tran[k][i - 1], k - 1); int r = (tran[k + 1][i] == 0 ? i - 1 : tran[k + 1][i]); for (int j = l; j <= r; j++) { if (updated[j + 1] != i) { updated[j + 1] = i; val[j + 1] += (last[i] < j + 1); } if (dp[k][i] < dp[k - 1][j] + val[j + 1]) { dp[k][i] = dp[k - 1][j] + val[j + 1]; tran[k][i] = j; } } } } printf("%d", dp[m][n]); return 0; }
10
CPP
import sys sys.setrecursionlimit(2147483647) INF=float("inf") MOD=10**9+7 input=lambda:sys.stdin.readline().rstrip() def resolve(): n=int(input()) A=list(map(int,input().split())) N=n*(n+1)//2 if(sum(A)%N): print("NO") return k=sum(A)//N for i in range(n): q,r=divmod(k-(A[(i+1)%n]-A[i]),n) if(q<0 or r): print("NO") return print("YES") resolve()
0
PYTHON3
for _ in range(int(input())): a,b=map(int,input().split()) if(a%b==0): print(0) else: n=a//b m=(a//b)*b+b-a print(m)
10
PYTHON3
n,k=map(int,input().split()) for i in range(k): if n%10!=0: n-=1 else: n=n//10 print(n)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; inline long long read() { register long long x = 0, f = 1; register char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = -1; for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48); return x * f; } void write(long long x) { if (x < 0) x = -x, putchar('-'); if (x >= 10) write(x / 10); putchar(x % 10 + '0'); } void writeln(long long x) { write(x); puts(""); } const int BASE = 32; int n, P, a[50005]; bitset<BASE> f[BASE + 1][50005]; int b[233]; int main() { n = read(), P = read(); for (register int i = (1); i <= int(n); ++i) { a[i] = read(); } int m = n; n = 0; for (register int i = (1); i <= int(m); ++i) if (a[i] < BASE) b[++n] = i; f[0][0].set(0); for (register int i = (0); i < int(n); ++i) { f[i + 1][a[b[i + 1]] % P].set(a[b[i + 1]]); for (register int j = (0); j < int(P); ++j) { for (register int k = (0); k < int(BASE); ++k) if (f[i][j][k]) { f[i + 1][(1ll * j * (a[b[i + 1]] >= 10 ? 100 : 10) + a[b[i + 1]]) % P] .set(k ^ a[b[i + 1]]); f[i + 1][j].set(k); } } } int Xor = 0, Rem = 0; vector<int> ans; ans.clear(); for (register int i = (n); i >= int(1); --i) { bool flag = false; for (int x = 0; x < P && (!flag); ++x) { for (int y = 0; y < BASE && (!flag); ++y) { if (f[i - 1][x][y] && (1ll * x * (a[b[i]] >= 10 ? 100 : 10) + a[b[i]]) % P == Rem && (y ^ a[b[i]]) == Xor) { ans.push_back(b[i]); Rem = x; Xor = y; flag = true; break; } } } if (flag && Rem == 0 && Xor == 0) break; } if (ans.size()) { reverse(ans.begin(), ans.end()); puts("Yes"); writeln(ans.size()); for (unsigned i = 0; i < ans.size(); ++i) write(ans[i]), putchar(' '); } else puts("No"); return 0; }
10
CPP
import sys,math,collections from collections import defaultdict #from itertools import permutations,combinations def file(): sys.stdin = open('input.py', 'r') sys.stdout = open('output.py', 'w') def get_array(): l=list(map(int, input().split())) return l def get_2_ints(): a,b=map(int, input().split()) return a,b def get_3_ints(): a,b,c=map(int, input().split()) return a,b,c def sod(n): n,c=str(n),0 for i in n: c+=int(i) return c def isPrime(n): if (n <= 1): return False if (n <= 3): return True if (n % 2 == 0 or n % 3 == 0): return False i = 5 while(i * i <= n): if (n % i == 0 or n % (i + 2) == 0): return False i = i + 6 return True def getFloor(A, x): (left, right) = (0, len(A) - 1) floor = -1 while left <= right: mid = (left + right) // 2 if A[mid] == x: return A[mid] elif x < A[mid]: right = mid - 1 else: floor = A[mid] left = mid + 1 return floor def chk(l,n): s=0 o=0 for i in range(len(l)): s+=l[i] if(s>n): return 0 if(s==n): ind=i o=1 break if(o): return(sum(l[ind+1:])==n) #file() def main(): for tt in range(int(input())): n=int(input()) l=get_array() t=[0]*n '''t[-1]=l[-1] for i in range(n-2,-1,-1): t[i]=l[i]+t[i+1] print(t)''' c=0 p=0 for i in range(n-1,-1,-1): if(l[i]<0): c+=l[i] t[i]=0 else: t[i]=c #print(t) for i in range(n-1,-1,-1): if(l[i]>0): t[i]+=p if(l[i]>abs(t[i])): p+=abs(t[i]) l[i]=l[i]+t[i] else: p+=abs(l[i]) l[i]=0 #print(l) c=0 for i in l: if(i>0): c+=i print(c) if __name__ == '__main__': main()
8
PYTHON3
#include <bits/stdc++.h> using namespace std; map<int, int> M; vector<int> l, p; vector<int> Z; void DodajFU() { int nowy = Z.size(); Z.push_back(nowy); } int Find(int a) { if (Z[a] == a) return a; int fa = Find(Z[a]); Z[a] = fa; return fa; } void Union(int a, int b) { int fa = Find(a); int fb = Find(b); if (a != b) Z[fb] = fa; } vector<vector<int> > T; int lisc, size; void Stworz(int n) { int p = 1; while (p < n) p *= 2; lisc = p; size = 2 * p - 1; vector<int> pusty; for (int i = 0; i <= size; ++i) T.push_back(pusty); } void DodajST(int a, int b, int x) { a += lisc; b += lisc; T[a].push_back(x); if (a != b) T[b].push_back(x); while (a / 2 != b / 2) { if (a % 2 == 0) T[a + 1].push_back(x); if (b % 2 == 1) T[b - 1].push_back(x); a /= 2; b /= 2; } } void Merge(int a, int b) { a = Find(a); b = Find(b); l[a] = min(l[a], l[b]); p[a] = max(p[a], p[b]); Union(a, b); } void Polacz(int start, int k) { int a = start + lisc; while (a != 0) { vector<int> zb; bool jest = false; for (int i = 0; i < T[a].size(); ++i) { if (M[l[Find(T[a][i])]] == start || M[p[Find(T[a][i])]] == start) zb.push_back(T[a][i]); else { Merge(T[a][i], k); jest = true; } } if (jest) zb.push_back(Find(k)); T[a] = zb; a /= 2; } } int main() { ios_base::sync_with_stdio(0); int n; cin >> n; vector<int> w; vector<vector<int> > oper(n, vector<int>(3)); for (int i = 0; i < n; ++i) { cin >> oper[i][0] >> oper[i][1] >> oper[i][2]; if (oper[i][0] == 1) { w.push_back(oper[i][1]); w.push_back(oper[i][2]); } else { --oper[i][1]; --oper[i][2]; } } sort(w.begin(), w.end()); int nr = -1; for (int i = 0; i < w.size(); ++i) { if (i == 0 || w[i] != w[i - 1]) ++nr; M[w[i]] = nr; } Stworz(nr + 1); for (int i = 0; i < n; ++i) { int a = oper[i][1], b = oper[i][2]; if (oper[i][0] == 1) { l.push_back(a); p.push_back(b); DodajFU(); DodajST(M[a], M[b], Z.size() - 1); Polacz(M[a], Z.size() - 1); Polacz(M[b], Z.size() - 1); } else { int fa = Find(a), fb = Find(b); if (fa == fb || (l[fa] >= l[fb] && p[fa] <= p[fb])) cout << "YES" << endl; else cout << "NO" << endl; } } return 0; }
11
CPP
def three_indices(ind): for i in range(1, len(ind) - 1): if ind[i] > ind[i - 1] and ind[i] > ind[i + 1]: print("YES") print(f"{i} {i + 1} {i + 2}") return print("NO") t = int(input()) for i in range(t): n = int(input()) ind = list(map(int, input().split())) three_indices(ind)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; long long a[1000000]; long long t[4000000]; long long get_pos[1000000]; long long mas[1000000]; long long dd[1000000]; void built(long long v, long long tl, long long tr) { if (tl == tr) { t[v] = dd[tl]; return; } long long tm = (tl + tr) / 2; built(v * 2, tl, tm); built(v * 2 + 1, tm + 1, tr); t[v] = t[v * 2] + t[v * 2 + 1]; } long long get_sum(long long v, long long tl, long long tr, long long l, long long r) { if (l > tr || tl > r) { return 0; } if (tl >= l && tr <= r) { return t[v]; } long long tm = (tl + tr) / 2; return get_sum(v * 2, tl, tm, l, r) + get_sum(v * 2 + 1, tm + 1, tr, l, r); } void obnova(long long v, long long tl, long long tr, long long pos, long long x) { if (tl == tr) { t[v] = x; return; } long long tm = (tl + tr) / 2; if (pos <= tm) { obnova(v * 2, tl, tm, pos, x); } else { obnova(v * 2 + 1, tm + 1, tr, pos, x); } t[v] = t[v * 2] + t[v * 2 + 1]; } long long ans; signed main() { ios_base::sync_with_stdio(0); long long n, k; cin >> n >> k; for (long long i = 1; i <= n; ++i) { cin >> a[i]; get_pos[a[i]] = i; dd[i] = 1; } built(1, 1, n); for (long long i = 1; i <= k; ++i) { long long kk; cin >> kk; mas[kk] = 1; } set<long long> ss; ss.insert(0); ss.insert(n + 1); for (long long i = 1; i <= n; ++i) { if (mas[i]) { ss.insert(get_pos[i]); } else { auto r = ss.upper_bound(get_pos[i]); long long rr = *r; auto l = --r; long long ll = *l; ans += get_sum(1, 1, n, ll + 1, rr - 1); obnova(1, 1, n, get_pos[i], 0); } } cout << ans << endl; }
11
CPP
n,t=list(map(int,input().split())) s=input() for i in range(t): a=[] for i in range(len(s)-1): if(s[i]=="B" and s[i+1]=="G"): a.append(i) for i in a: s=s[:i]+"GB"+s[i+2:] print(s)
8
PYTHON3
n,h,l,r=map(int,input().split()) dp=[[-10**9 for i in range(h+1)] for j in range(n+1)] li=[int(x) for x in input().split()] dp[0][0]=0 mx=0 for i in range(1,n+1): for j in range(0,h+1): c=0 new=(j+li[i-1]-1)%h if new>=l and new<=r: c=1 dp[i][new]=max(dp[i][new],dp[i-1][j]+c) c=0 new=(j+li[i-1])%h if new>=l and new<=r: c=1 dp[i][new]=max(dp[i][new],dp[i-1][j]+c) print(max(dp[n]))
11
PYTHON3
n = int(input()) s = input() c = 0 for i in range(len(s)-1): if s[i+1]==s[i]: c = c +1 print(c)
7
PYTHON3
#!/usr/bin/env python3 import sys from math import * from collections import defaultdict from queue import deque # Queues from heapq import heappush, heappop # Priority Queues # parse lines = [line.strip() for line in sys.stdin.readlines()] T = int(lines[0]) cur = 1 for t in range(T): n, x, m = map(int, lines[cur].split()) ops = [list(map(int, line.split())) for line in lines[cur+1:cur+1+m]] cur += 1 + m lb, ub = x, x for a, b in ops: if lb <= b: lb = min(lb, a) if ub >= a: ub = max(ub, b) print(ub - lb + 1)
8
PYTHON3
if __name__ == '__main__': n = int(input()) points = [] for _ in range(n): tmp = list(map(int, input().split())) points.append(tmp) ans = [] for i in range(n): point_i = points[i] for j in range(n): if j == i: continue point_j = points[j] k_break = False vector_ij = [point_j[idx] - point_i[idx] for idx in range(5)] for k in range(j + 1, n): if k == i: continue point_k = points[k] vector_ik = [point_k[idx] - point_i[idx] for idx in range(5)] inner_product = 0 num_i_mo = 0 num_j_mo = 0 for idx in range(5): inner_product += vector_ij[idx] * vector_ik[idx] if inner_product > 0: k_break = True break if k_break: break else: ans.append(point_i) if len(points) <= 2: print(len(points)) for i in range(len(points)): print(i+1) else: print(len(ans)) for single in ans: print(points.index(single) + 1)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; cout << (n%2 != 0 ? n*2 : n) << endl; }
0
CPP
K=map n=int e=input P=print h=len y=list i=str a,b=K(n,e().split()) x=[b] def U(): global a,b while b//2>=a: if b%10==1: b=b//10 elif b%2==0: b=b//2 else: P("NO") return x.append(b) x.reverse() if x[0]!=a: P("NO") return P("YES") P(h(x)) P(" ".join(y(K(i,x)))) U()
7
PYTHON3
#include <bits/stdc++.h> using namespace std; const long long MAXN = 500 + 21, inf = 1e14 + 21; int n; long long q, r; long long a[MAXN]; long long ans = inf; int main() { ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; int x = a[0]; for (int i = 1; i * i <= x; i++) { int b[] = {i, i + 1, x / i, (x / i) + 1}; for (int j = 0; j < 4; j++) { long long tmp = 0; for (int k = 0; k < n; k++) { q = (a[k] + b[j] - 1) / b[j]; r = a[k] % b[j]; tmp += (!r || q >= b[j] - r ? q : inf); } ans = min(ans, tmp); } } cout << ans; return 0; }
11
CPP
#include <bits/stdc++.h> using namespace std; int main() { int n, arr[9], len = 0, minn; string str; cin >> n; for (int i = 0; i < 9; i++) { cin >> arr[i]; if (n / arr[i] > len) { len = n / arr[i]; minn = arr[i]; } } if (len == 0) { cout << "-1" << endl; return 0; } while (len > 0) { len--; for (int i = 8; i >= 0; i--) { int leen = (n - arr[i]) / minn; if (leen == len && n >= arr[i]) { str += (i + 1 + '0'); n -= arr[i]; } } } cout << str << endl; return 0; }
8
CPP
s=input() print(s.count('+')*1-s.count('-'))
0
PYTHON3
a = input() s = input() ans = 0 k = 1 for i in s: if int(i)%2 == 0: ans += k k += 1 print(ans)
7
PYTHON3
N = int(input()) a = list(map(int, input().split())) bl = True amount = N * (N + 1) // 2 # 一回の操作で除去される石の量 q1, r1 = divmod(sum(a), amount) # q: 操作の回数 if r1 != 0: bl = False else: d = [a[(i + 1) % N] - a[i] for i in range(N)] d = list(map(lambda x: x - q1, d)) cnt = 0 for dd in d: if dd > 0: bl = False break else: q2, r2 = divmod(-dd, N) if r2 > 0: bl = False break else: cnt += q2 bl &= (cnt == q1) print('YES' if bl else 'NO')
0
PYTHON3
N = int(input()) S = [] T = [] for i in range(N): s,t = input().split() S.append(s) T.append(int(t)) X = str(input()) ind = int(S.index(X)) print(sum(T[ind+1:]))
0
PYTHON3
N=int(input()) A=input().split() l=len(set(A)) print('YES' if N==l else 'NO')
0
PYTHON3
t=int(input()) for i in range(t): n=int(input()) a=list(map(int,input().split())) a.sort() f=0 for j in range(n-1): if abs(a[j]-a[j+1])>1: print("NO") f=1 break if f==0: print("YES")
7
PYTHON3
#include <bits/stdc++.h> int diru[] = {-1, -1, -1, 0, 0, 1, 1, 1}; int dirv[] = {-1, 0, 1, -1, 1, -1, 0, 1}; using namespace std; template <class T> T sq(T n) { return n * n; } template <class T> T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a % b) : a); } template <class T> T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); } template <class T> bool inside(T a, T b, T c) { return a <= b && b <= c; } template <class T> void setmax(T &a, T b) { if (a < b) a = b; } template <class T> void setmin(T &a, T b) { if (b < a) a = b; } template <class T> T power(T N, T P) { return (P == 0) ? 1 : N * power(N, P - 1); } char in[100100]; char tmp[100100]; bool p[1010][1010]; int main() { int n, T, t = 1, m, i, j, k; scanf("%s", in); n = strlen(in); scanf("%d", &k); for (i = 0; i < k; i++) { scanf("%s", tmp); p[tmp[0]][tmp[1]] = 1; p[tmp[1]][tmp[0]] = 1; } int ans = 0; int x = 0; int y = 0; bool f = 0; for (i = 0; i < n; i++) { if (i && in[i] == in[i - 1]) { if (f == 0) x++; else y++; } else if (i && p[in[i]][in[i - 1]]) { f = !f; if (f == 0) x++; else y++; } else { if (x && y) ans += min(x, y); x = 1; y = 0; f = 0; } } if (x && y) ans += min(x, y); printf("%d\n", ans); return 0; }
7
CPP
#include <iostream> #include <cmath> #include <cstdio> using namespace std; int main(){ const double pi =M_PI; double err,diff; int bunbo,bunsi; while (1){ cin >> err; if (err==0) break; bunbo=1; bunsi=3; while (1){ diff=(pi-((double)bunsi/bunbo)); //cout << bunsi << "/" << bunbo <<" "<<diff<<" " << endl; if (diff>err)bunsi++; else if ((pi-((double)bunsi/bunbo))<-err)bunbo++; else break; } cout << bunsi << "/" << bunbo << endl; } return 0; }
0
CPP
#include <bits/stdc++.h> using namespace std; bool ok(vector<int> &a, vector<int> &b) { int n = a.size(); for (int bt = 1; bt < (1 << n) - 1; bt++) { long long diff = 0; for (int i = 0; i < n; i++) if (bt & (1 << i)) diff += a[i] - b[i]; if (!diff) return false; } return true; } int rnd(int x) { return rand() % x; } vector<int> rotate(vector<int> a) { int n = a.size(); vector<int> ret(n); for (int i = 0; i < n; i++) ret[i] = a[(i + 1) % n]; return ret; } int main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; vector<int> a_sorted = a; sort(a_sorted.begin(), a_sorted.end()); vector<int> b = a_sorted; for (int i = 0; i < n; i++) { b = rotate(b); if (ok(a_sorted, b)) { map<int, int> mp; for (int i = 0; i < n; i++) mp[a_sorted[i]] = b[i]; for (auto x : a) cout << mp[x] << " "; cout << endl; return 0; } } cout << -1 << endl; return 0; }
8
CPP
#include<iostream> using namespace std; int main() { int N,A,B,C,X,Y,y,f; while(cin>>N>>A>>B>>C>>X,N||A||B||C||X){ f=0; y=-1; while(N-->0){ cin>>Y; if(Y==y){X=(A*X+B)%C;f++;} while(X!=Y&&f<10001){ X=(A*X+B)%C; f++; } y=Y; } if(f>10000)f=-1; cout<<f<<endl; } }
0
CPP
#include <bits/stdc++.h> using namespace std; long long MOD = 1000000007; string yes = "YES\n"; string no = "NO\n"; long long n, m, k, t; long long l, r, d; long long x, y; vector<long long> a; long long pref[100005], sum[100005]; long long pref_times[100005]; struct oper { long long l, r, d; }; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m >> k; for (long long i = 0; i < n; i++) cin >> t, a.push_back(t); vector<oper> op; while (m--) { cin >> l >> r >> d; oper temp; temp.l = l; temp.r = r; temp.d = d; op.push_back(temp); } while (k--) { long long x, y; cin >> x >> y; pref_times[x - 1] += 1; pref_times[y] -= 1; } for (long long i = 1; i < 100005; i++) { pref_times[i] += pref_times[i - 1]; } long long idx = 0; for (auto i : op) { pref[i.l - 1] += pref_times[idx] * i.d; pref[i.r] -= pref_times[idx++] * i.d; } for (long long i = 1; i < 100005; i++) { pref[i] += pref[i - 1]; } for (long long i = 0; i < n; i++) { a[i] += pref[i]; sum[i + 1] = sum[i] + a[i]; cout << a[i] << " "; } cout << "\n"; return 0; }
9
CPP
#In the name of GOD! n = int(input()) a = list(map(int, input().split())) a.sort() print(a[n // 2 - (1 - n % 2)])
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int a, ans[17] = {0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 0, 1, 0, 1, 0}; int main() { cin >> a; cout << ans[a]; return 0; }
10
CPP
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using vb = vector<bool>; using pii = pair<int, int>; using vii = vector<pii>; using vs = vector<string>; const ll MOD = 1e9 + 7; const ll INF = 1e9; const double PI = 3.14159265359; int main() { ios::sync_with_stdio(false), cin.tie(nullptr); int t; cin >> t; while (t--) { int n, x; cin >> n >> x; vi a(n), b(n); for (int i = 0; i < n; ++i) { cin >> a[i]; } for (int i = 0; i < n; ++i) { cin >> b[i]; } sort(a.begin(), a.end()); sort(b.rbegin(), b.rend()); bool yes = true; for (int i = 0; i < n; ++i) { if (a[i] + b[i] > x) { yes = false; break; } } cout << (yes ? "Yes" : "No") << endl; } }
7
CPP
def main(): (str1, str2) = (input(), input()) n = len(str1) str3 = [''] * n impossible = False for i in range(n): if str2[i] > str1[i]: impossible = True break str3[i] = str2[i] print(-1 if impossible else ''.join(str3)) if __name__ == '__main__': main()
8
PYTHON3
def s(n): ret = 0 while n > 0: ret += n % 10 n //= 10 return ret numbers = [999999999999999999] while numbers[-1] > 1: for d in range(0, 100): n = numbers[-1] m = n - 10 ** d if n * s(m) >= m * s(n): numbers.append(m) break numbers = list(reversed(numbers)) n = int(input()) for i in range(n): print(numbers[i])
0
PYTHON3
#include <iostream> using namespace std; int main() { int N; cin >> N; typedef long long ll; ll T, A; cin >> T >> A; ll t = T, a = A; for (int i = 1; i < N; ++i) { cin >> T >> A; ll m = t/T + ((0 == t%T) ? 0 : 1); ll n = a/A + ((0 == a%A) ? 0 : 1); ll j = ((m < n) ? n : m); t = j*T; a = j*A; } cout << t + a; return 0; }
0
CPP
#include <bits/stdc++.h> using namespace std; int main() { int n, m, k; cin >> n >> m >> k; vector<pair<int, int> > a; for (int i = 0; i < n; i++) { if (i & 1) { for (int j = m - 1; j >= 0; j--) { a.push_back(make_pair(i + 1, j + 1)); } } else { for (int j = 0; j < m; j++) { a.push_back(make_pair(i + 1, j + 1)); } } } int x = 0; int part = int(a.size()) / k; for (int i = 0; i < k - 1; i++) { cout << part << ' '; for (int j = 0; j < part; j++) { cout << a[x].first << " " << a[x].second << " "; x++; } cout << endl; } cout << int(a.size() - x) << ' '; while (x < a.size()) { cout << a[x].first << ' ' << a[x].second << " "; x++; } cout << endl; return 0; }
9
CPP
t=int(input()) for _ in range(t): k=[len(x) for x in input().split("R")] print(max(k)+1)
9
PYTHON3
t=int(input()) for _ in range(t): n,m=map(int,input().split()) q=[] for i in range(n): q.append(list(map(int,input().split()))) c=0 for i in range(n): for j in range(m): f=0 for k in range(m): if q[i][k]==1: f=1 break; if f==0: g=0 for k in range(n): if q[k][j]==1: g=1 break; if g==0: q[i][j]=1 c=c+1 #print(c) if c%2==0: print('Vivek') else: print('Ashish')
7
PYTHON3