solution
stringlengths
10
159k
difficulty
int64
0
3.5k
language
stringclasses
2 values
n,m = map(int,input().split(' ')) bulb = [False]*m for i in range(n): temp = list(map(int,input().split(' ')))[1::] for each in temp: bulb[each-1] = True print('YES' if not (False in bulb) else 'NO')
800
PYTHON3
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { int t; while (b != 0) { t = b; b = a % b; a = t; } return a; } int main() { int n; cin >> n; int a[200]; for (int i = 0; i < n; i++) cin >> a[i]; if (n == 1) { cout << a[0]; return 0; } int ans = n; int i = 0; while (i < n && !a[i]) { ans--; i++; } int j = n - 1; while (j >= i && !a[j]) { ans--; j--; } int k = i; for (; k < j + 1;) { if (!a[k]) { int x = k; while (k < j + 1 && !a[k]) k++; if (k - x >= 2) { ans -= k - x; } } else { k++; } } cout << ans; }
900
CPP
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long LLINF = 1e18; const int maxN = 1e6 + 10; const long long MOD = 1000000007; long long A[maxN]; long long n, p; long long pw(long long x) { if (x == 0) return 1; if (x == 1) return p; if (x & 1) return (((pw(x / 2) * pw(x / 2)) % MOD) * p) % MOD; else return (pw(x / 2) * pw(x / 2)) % MOD; } long long pw2(long long x) { if (x == 0) return 1; if (x == 1) return p; if (x & 1) return min(1000000LL, pw2(x / 2) * pw2(x / 2) * p); else return min(1000000LL, pw2(x / 2) * pw2(x / 2)); } long long calc_need(long long old, long long dif) { old = min(1000009LL, old * pw2(dif)); return old; } int main() { int t; scanf("%d", &t); while (t--) { scanf("%lld %lld", &n, &p); for (int i = 0; i < n; i++) { scanf("%lld", &A[i]); } sort(A, A + n), reverse(A, A + n); long long ans = 0; long long cnt_need = 0, exp_need = 0; for (int i = 0; i < n; i++) { if (cnt_need == 0) { cnt_need++; exp_need = A[i]; ans = (ans + pw(A[i])) % MOD; } else { cnt_need = min(calc_need(cnt_need, exp_need - A[i]), 1000009LL); exp_need = A[i]; cnt_need--; ans = (ans + MOD - pw(A[i])) % MOD; } } printf("%lld\n", ans); } return 0; }
1,900
CPP
#include <bits/stdc++.h> #pragma GCC optimize("Ofast", "inline", "-ffast-math") #pragma GCC target("avx,sse2,sse3,sse4,mmx") #pragma GCC target("arch=corei7-avx") using namespace std; struct P { int x, y; } p[2020]; P le = (P){-int(1e9 + 7), -1}; inline P operator-(const P &a, const P &b) { return (P){a.x - b.x, a.y - b.y}; } inline long long ddd(const P &a, const P &b) { return (long long)a.x * b.x + (long long)a.y * b.y; } inline long long xxx(const P &a, const P &b) { return (long long)a.x * b.y - (long long)b.x * a.y; } struct OPT { P p; double ang; int fl; } opt[4040]; bool cmp(const OPT &a, const OPT &b) { return abs(a.ang - b.ang) > (1e-8) ? a.ang < b.ang : xxx(a.p, b.p) > 0; } int n, m, cnt; long long ans; long long C2(long long x) { return x * (x - 1) / 2; } int main() { cin >> n; for (int i = 1; i <= n; ++i) cin >> p[i].x >> p[i].y; for (int i = 1; i <= n; ++i) { m = cnt = 0; for (int j = 1; j <= n; ++j) if (j != i) { P v = p[j] - p[i]; cnt += xxx(le, v) > 0; opt[++m] = (OPT){v, atan2(v.y, v.x), -1}; v = p[i] - p[j]; opt[++m] = (OPT){v, atan2(v.y, v.x), 1}; } sort(opt + 1, opt + m + 1, cmp); for (int j = 1; j <= m; ++j) { cnt += opt[j].fl; if (opt[j].fl == -1) ans += C2(cnt) * C2(n - 2 - cnt); } } cout << ans / 2 << endl; }
2,700
CPP
#include <bits/stdc++.h> using namespace std; long long n; long long e[100005]; long long dp[100005][2]; int main() { cin >> n; for (int i = 1; i <= n; i++) { cin >> e[i]; } dp[1][0] = abs(e[1] + 1); dp[1][1] = abs(e[1] - 1); for (int i = 2; i <= n; i++) { dp[i][0] = min(dp[i - 1][0] + abs(e[i] - 1), dp[i - 1][1] + abs(e[i] + 1)); dp[i][1] = min(dp[i - 1][0] + abs(e[i] + 1), dp[i - 1][1] + abs(e[i] - 1)); } cout << dp[n][1] << endl; return 0; }
900
CPP
#include <bits/stdc++.h> using namespace std; const int mod = 998244353; const int maxn = 3e5 + 5; vector<int> adj[maxn]; int two[maxn], color[maxn], cnt[2]; bool vis[maxn], flag; inline int add(const int& a, const int& b) { return a + b < mod ? a + b : a + b - mod; } inline int mul(const int& a, const int& b) { return 1LL * a * b % mod; } void dfs(int u, int c = 0) { vis[u] = true; ++cnt[color[u] = c]; for (auto v : adj[u]) { if (vis[v]) flag &= (color[u] ^ color[v]); else dfs(v, !c); } } int main() { two[0] = 1; for (int i = 1; i ^ maxn; ++i) two[i] = add(two[i - 1], two[i - 1]); int t; cin >> t; while (t--) { int n, m; cin >> n >> m; for (int i = 1; i <= n; ++i) adj[i].clear(); while (m--) { int u, v; cin >> u >> v; adj[u].push_back(v); adj[v].push_back(u); } memset(vis + 1, 0, n * sizeof(bool)); flag = true; int res = 1; for (int i = 1; i <= n; ++i) if (!vis[i]) { cnt[0] = cnt[1] = 0; dfs(i); if (flag) res = mul(res, add(two[cnt[0]], two[cnt[1]])); else break; } cout << (flag ? res : 0) << endl; } }
1,700
CPP
#include <bits/stdc++.h> using namespace std; int main() { int t, n, i, j = 0, g, c = 0, d = 0, arr[4], x = 1; cin >> t; for (i = 0; i < t; i++) { c = j = d = 0; x = 1; cin >> n; g = n; for (int i = 0; g != 0; i++) { if (g % 10 != 0) { c++; arr[j++] = (g % 10) * x; g = g / 10; } else g = g / 10; d++; x = x * 10; } cout << c << endl; for (int i = c - 1; i >= 0; i--) { cout << arr[i] << " "; } cout << endl; } return 0; }
800
CPP
#include <bits/stdc++.h> using namespace std; const int MAXN = 100005; int N, M; int F[MAXN]; map<pair<int, int>, int> H; int A[MAXN]; int B[MAXN]; void rev(int st, int en) { if (st > en) return; vector<int> lol; for (int i = st; i <= en; ++i) lol.push_back(A[i]); reverse(lol.begin(), lol.end()); int cnt = 0; for (int i = st; i <= en; ++i) A[i] = B[i] = lol[cnt++]; return; } int main() { cin >> N >> M; if (N == 1) { cout << "NO\n"; return 0; } for (int i = 1; i <= N; ++i) A[i] = B[i] = i; for (int i = 1; i <= M; ++i) { int u, v; cin >> u >> v; F[u]++; F[v]++; H[make_pair(min(u, v), max(u, v))] = 1; } int yes = 0; int idx = -1; for (int i = 1; i <= N; ++i) { if (F[i] != (N - 1)) { yes = 1; idx = i; break; } } if (yes) { int ind = -1; for (int i = 1; i <= N; ++i) { if (i != idx && H.find(make_pair(min(i, idx), max(i, idx))) == H.end()) { ind = i; break; } } cout << "YES\n"; rev(idx + 1, ind); B[ind] = B[idx]; for (int i = 1; i <= N; ++i) cout << A[i] << " "; cout << endl; for (int i = 1; i <= N; ++i) cout << B[i] << " "; cout << endl; } else { cout << "NO\n"; } return 0; }
1,800
CPP
n=int(input()) m=int(input()) l=[] for i in range(n): l.append(int(input())) l.sort(reverse=True) s=0 c=0 for i in l: s=s+i c=c+1 if(s>=m): print(c) break
800
PYTHON3
# cook your dish here n=int(input()) c=0 for i in range(n): a=[int(x) for x in input().split()] k=0 for j in a: if j==1: k=k+1 if k>=2: c=c+1 print(c)
800
PYTHON3
#include <bits/stdc++.h> using namespace std; int n, m; pair<int, int> red[2005], blue[2005]; pair<int, int> rred[2005][2], rblue[2005][2]; int vis[2005][2005]; vector<pair<pair<int, int>, pair<int, int> > > re, bl; int check1(pair<pair<int, int>, pair<int, int> > x, pair<pair<int, int>, pair<int, int> > y) { if (y.first.second >= x.first.second && y.first.second <= x.second.second && x.first.first >= y.first.first && x.first.first <= y.second.first) return 1; return 0; } bool check(int t) { int pre = 0; re.clear(); bl.clear(); for (int i = 0; i < n; i++) { rblue[i][0] = make_pair(blue[i].first, blue[i].second - 2 * t); rblue[i][1] = make_pair(blue[i].first, blue[i].second + 2 * t); if (i == 0) continue; if (blue[i].first == blue[pre].first && rblue[i][0] <= rblue[pre][1]) { rblue[pre][1] = rblue[i][1]; } else { bl.push_back(make_pair(rblue[pre][0], rblue[pre][1])); pre = i; } } bl.push_back(make_pair(rblue[pre][0], rblue[pre][1])); pre = 0; for (int i = 0; i < m; i++) { rred[i][0] = make_pair(red[i].first - t * 2, red[i].second); rred[i][1] = make_pair(red[i].first + t * 2, red[i].second); if (!i) continue; if (red[i].second == red[pre].second && rred[i][0] <= rred[pre][1]) { rred[pre][1] = rred[i][1]; } else { re.push_back(make_pair(rred[pre][0], rred[pre][1])); pre = i; } } re.push_back(make_pair(rred[pre][0], rred[pre][1])); memset(vis, 0, sizeof(vis)); int lenr = re.size(); int lenb = bl.size(); for (int i = 0; i < lenb; i++) { for (int j = 0; j < lenr; j++) { if (check1(bl[i], re[j])) { for (int k = j + 1; k < lenr; k++) { if (check1(bl[i], re[k])) { if (vis[j][k]) return true; vis[j][k]++; } } } } } return false; } int main() { scanf("%d%d", &n, &m); for (int i = 0; i < n; i++) { int x, y; scanf("%d%d", &x, &y); blue[i] = make_pair(x + y, x - y); } for (int i = 0; i < m; i++) { int x, y; scanf("%d%d", &x, &y); red[i] = make_pair(x + y, x - y); } sort(blue, blue + n); for (int i = 0; i < m; i++) swap(red[i].first, red[i].second); sort(red, red + m); for (int i = 0; i < m; i++) swap(red[i].first, red[i].second); if (blue[0].first == blue[n - 1].first || red[0].second == red[m - 1].second) { puts("Poor Sereja!"); return 0; } int L = 0, R = 0x7fffffff, ans = 0; while (L <= R) { int mid = (L + R) >> 1; if (check(mid)) { R = mid - 1; ans = mid; } else L = mid + 1; } cout << ans << endl; return 0; }
2,600
CPP
#include <bits/stdc++.h> #define ull unsigned long long #define ll long long #define endl '\n' #define line cout<<"--------------------------"<<endl #define dd(x) cout<<#x<<" = "<<x<<' ' #define sz(v) (ll)v.size() #define srt(v) sort(v.begin(),v.end()) #define rsrt(v) sort(v.rbegin(),v.rend()) #define all(v) v.begin(),v.end() #define pb push_back #define mp make_pair #define mod 1000000007 #define fast ios_base::sync_with_stdio(false); cin.tie(NULL) #define filein freopen("input.txt","r",stdin) #define fileout freopen("output.txt","w",stdout) using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const ll mx=200009; void yes() {cout<<"Yes"<<endl; } void no() {cout<<"No"<<endl; } ll ara[mx],n,d; ll nisi[mx][11]; double dp[mx][11]; bool vis[mx][11]; double call(ll ind, ll last) { if(ind==n) { if(last==d) return 1; return -10000008; } double &ret=dp[ind][last]; if(vis[ind][last]) return ret; vis[ind][last]=1; ret=-100000098.0; ll aa=last; if(last==10) aa=1; double a=log2(ara[ind])+(double)call(ind+1,(ara[ind]*aa)%10); double b=call(ind+1,last); if(a>b and a>0) { ret=a; nisi[ind][last]=1; //cout<<ind<<' '<<last<<endl;; } else ret=b; //cout<<ind<<' '<<a<<' '<<b<<' '<<last<<endl; return ret; } int main() { fast; cin>>n>>d; for(ll i=0;i<n;i++) cin>>ara[i]; double d=call(0,10); if(d<=0) cout<<-1<<endl; else { vector<ll> ans; ll ind=0,last=10; while(ind<n) { if(nisi[ind][last]) { if(last==10) last=1; ans.pb(ara[ind]); last=(last*ara[ind])%10; } //cout<<ind<<' '<<last<<endl; ind++; } cout<<sz(ans)<<endl; for(auto x: ans) cout<<x<<' '; cout<<endl; } }
2,100
CPP
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; int arr[n]; int cnt = 0; for (int i = 0; i < n; i++) { cin >> arr[i]; if (arr[i] == 1) cnt++; } if (cnt == 1) { cout << -1 << endl; return 0; } vector<int> factor; for (int i = 2; i <= cnt; i++) { if (cnt % i == 0) { factor.push_back(i); } } long long fans = 1e17; for (int j = 0; j < factor.size(); j++) { long long ans = 0; int num = factor[j]; vector<int> v; int c = 0; for (int i = 0; i < n; i++) { if (arr[i] == 1) c++; if (c == num / 2 + 1 && arr[i] == 1) { v.push_back(i); } if (c == num) c = 0; } int p = 0; int k = 0; int l = v.size(); while (p < l) { int cn = 0; while (cn < num) { if (arr[k] == 1) { cn++; ans += abs(v[p] - k); } k++; } p++; } fans = min(fans, ans); } cout << fans << endl; return 0; }
1,800
CPP
#include <bits/stdc++.h> using namespace std; struct node { int a, b; node() {} node(int x, int y) { a = x; b = y; } bool operator<(const node &no) const { return a < no.a || (a == no.a && b > no.b); } }; int p[5001], ret[5001], num[5001]; int main() { int n, i, k; scanf("%d", &n); for (i = 1; i <= n; i++) scanf("%d", p + i); for (i = 1; i <= n; i++) { priority_queue<node> qe; memset(num, 0, sizeof(num)); for (k = i; k <= n; k++) { num[p[k]]++; qe.push(node(num[p[k]], p[k])); ret[qe.top().b]++; } } for (i = 1; i <= n; i++) { if (i > 1) printf(" "); printf("%d", ret[i]); } return 0; }
1,500
CPP
#include <bits/stdc++.h> using namespace std; int n; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n; long long a[n]; for (int i = 0; i < n; i++) cin >> a[i]; cout << 1 << " " << 1 << '\n'; cout << -a[0] << '\n'; a[0] = 0; if (n == 1) { for (int i = 0; i < 2; i++) cout << 1 << " " << 1 << '\n' << 0 << '\n'; return 0; } cout << 2 << " " << n << '\n'; for (int i = 1; i < n; i++) { long long add = (a[i] % n) * (n - 1); a[i] += add; cout << add << " "; } cout << '\n' << 1 << " " << n << '\n'; for (int i = 0; i < n; i++) cout << -a[i] << " "; }
1,600
CPP
n, k = tuple([int(i) for i in input().split()]) letters = {} for letter in input(): letters[letter] = letters.get(letter, 0) + 1 if len(letters.keys()) == k: print(min(letters.values()) * k) else: print(0)
800
PYTHON3
#include <bits/stdc++.h> using namespace std; const int N = 2010; const int M = 100010; int lowbit(int x) { return x & (-x); } long long a[4][N][N]; int n; void Add(int x, int y, long long val) { if (!x || !y) return; for (int i = x; i <= n; i += lowbit(i)) { for (int j = y; j <= n; j += lowbit(j)) { a[0][i][j] ^= val; if (x % 2 == 1) a[1][i][j] ^= val; if (y % 2 == 1) a[2][i][j] ^= val; if (x % 2 && y % 2) a[3][i][j] ^= val; } } } long long Get(int x, int y, int op) { long long ans = 0; for (int i = x; i > 0; i -= lowbit(i)) { for (int j = y; j > 0; j -= lowbit(j)) { ans ^= a[op][i][j]; } } return ans; } long long Get(int x1, int y1, int x2, int y2, int op) { long long ans = 0; ans = Get(x2, y2, op) ^ Get(x1 - 1, y1 - 1, op) ^ Get(x2, y1 - 1, op) ^ Get(x1 - 1, y2, op); return ans; } long long Solve(int x, int y) { long long ans = 0; ans = Get(x, y, 3); if (y % 2) ans ^= Get(1, y + 1, x, n, 1); if (x % 2) ans ^= Get(x + 1, 1, n, y, 2); if (x % 2 && y % 2) ans ^= Get(x + 1, y + 1, n, n, 0); return ans; } int main(void) { int m, op, x1, y1, x2, y2; long long val; scanf("%d%d", &n, &m); memset(a, 0, sizeof(a)); for (int i = 1; i <= m; ++i) { scanf("%d", &op); scanf("%d %d %d %d", &x1, &y1, &x2, &y2); if (op == 2) { cin >> val; Add(x2, y2, val); Add(x1 - 1, y2, val); Add(x2, y1 - 1, val); Add(x1 - 1, y1 - 1, val); } else { long long ans = Solve(x2, y2) ^ Solve(x1 - 1, y1 - 1) ^ Solve(x1 - 1, y2) ^ Solve(x2, y1 - 1); cout << ans << endl; } } return 0; }
2,500
CPP
#include <bits/stdc++.h> using namespace std; long long int dp[3][100111], ans = -9000000000000000007, a[100111], m[100111]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long int p, q, r, n; cin >> n >> p >> q >> r; for (int i = 0; i < 3; i++) { for (int j = 0; j < 100111; j++) { dp[i][j] = -9000000000000000007; } } for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = n - 1; i >= 0; i--) { dp[2][i] = max(dp[2][i + 1], r * a[i]); } for (int i = 0; i < n; i++) { m[i] = q * a[i] + dp[2][i]; } for (int i = n - 1; i >= 0; i--) { dp[0][i] = max(dp[0][i + 1], m[i]); } for (int i = 0; i < n; i++) { ans = max(ans, p * a[i] + dp[0][i]); } cout << ans; return 0; }
1,500
CPP
#include <bits/stdc++.h> long long q_pow(long long x, long long n, long long mod) { long long ret = 1; while (n) { if (n & 1) ret = x * ret % mod; x = x * x % mod; n >>= 1; } return ret; } long long __gcd(long long x, long long y) { if (!y) return x; return __gcd(y, x % y); } int dx[] = {-1, 1, 0, 0}; int dy[] = {0, 0, -1, 1}; using namespace std; const long long INF = 0x3f3f3f3f3f3f3f3f; const int mod = 1e9 + 7; const int maxn = 400000 + 50; long long sum[maxn][20], fa[maxn][20], w[maxn]; int cnt = 1; void insert(int val, int father) { w[++cnt] = val; if (w[cnt] <= w[father]) { fa[cnt][0] = father; } else { int tmp = father; for (int i = 19; i >= 0; i--) { if (w[fa[tmp][i]] < w[cnt]) tmp = fa[tmp][i]; } fa[cnt][0] = fa[tmp][0]; } if (fa[cnt][0] == 0) sum[cnt][0] = INF; else sum[cnt][0] = w[fa[cnt][0]]; for (int i = 1; i <= 19; i++) { fa[cnt][i] = fa[fa[cnt][i - 1]][i - 1]; if (fa[cnt][i] == 0 || sum[cnt][i - 1] == INF) sum[cnt][i] = INF; else sum[cnt][i] = sum[cnt][i - 1] + sum[fa[cnt][i - 1]][i - 1]; } } long long query(int pos, long long val) { long long ans = 0; if (val < w[pos]) return 0; val -= w[pos], ans++; for (int i = 19; i >= 0; i--) { if (sum[pos][i] <= val) { val -= sum[pos][i]; ans += (1LL << i); pos = fa[pos][i]; } } return ans; } signed main(int argc, char *argv[]) { if (argc == 2 && strcmp("-debug", argv[1]) == 0) { freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); } int n; cin >> n; long long last = 0; memset((sum[1]), (0x3f), sizeof(sum[1])); w[0] = INF, w[1] = 0; long long opt, x, y; for (int i = 1; i <= n; i++) { scanf("%lld%lld%lld", &opt, &x, &y); x ^= last, y ^= last; if (opt == 1) { insert(y, x); } else { last = query(x, y); printf("%lld\n", last); } } return 0; }
2,200
CPP
from collections import deque n, q = [int(i) for i in input().split()] a = [int(i) for i in input().split()] a = deque(a) mx = max(a) const = [] while a[0] != mx: const.append([a[0], a[1]]) if a[0] > a[1]: k = a.popleft() a.append(a.popleft()) a.appendleft(k) else: a.append(a.popleft()) for z in range(q): m = int(input()) if m <= len(const): print(' '.join(list(map(str, const[m - 1])))) else: m -= len(const) if m % (len(a) - 1) == 0: print(mx, a[len(a) - 1]) else: print(mx, a[m % (len(a) - 1)])
1,500
PYTHON3
#include <bits/stdc++.h> using namespace std; long long fast_pow(long long x, long long k) { long long ans = 1; while (k) { if (k & 1) ans = ans * x % 998244353; x = x * x % 998244353; k >>= 1; } return ans; } long long inv(long long x) { return fast_pow(x, 998244353 - 2); } int n; long long sum = 0; int a[300000 + 5]; long long f[300000 + 5], g[300000 + 5]; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); sum += a[i]; } g[0] = n - 1; for (long long i = 1; i < sum; ++i) g[i] = (sum * (n - 1) % 998244353 + i * (n - 1) % 998244353 * g[i - 1] % 998244353) * inv(sum - i) % 998244353; for (int i = sum; i >= 0; i--) f[i] = (f[i + 1] + g[i]) % 998244353; long long ans = 0; for (int i = 1; i <= n; ++i) ans = (ans + f[a[i]]) % 998244353; ans = (ans - f[0] * (n - 1) % 998244353 + 998244353) * inv(n) % 998244353; printf("%lld\n", ans); }
3,200
CPP
import re str = input() regex = r"([aeiuyoAEIUOY])" substr = "" result = re.sub(regex, substr, str) #print(result) regex = r"(\w)" answer = re.sub(regex, lambda m : "." + m.group(0).lower() , result, 0, re.MULTILINE) print(answer)
1,000
PYTHON3
#include <bits/stdc++.h> using namespace std; const long long N = 1e6 + 10; const long long INF = 1e9 + 10; const long long MOD = 1e9 + 7; bool setBit(long long n, long long k) { return n & (1LL << k); } void solve() { long long n; cin >> n; vector<long long> a(n + 1), b(n + 1); map<long long, long long> mp; for (long long i = 1; i <= n; i++) { cin >> a[i]; mp[a[i]]++; } for (long long i = 1; i <= n; i++) cin >> b[i]; long long ans = 0; vector<long long> v; for (long long i = 1; i <= n; i++) { if (mp[a[i]] > 1) ans += b[i]; } for (auto u : mp) { if (u.second > 1) v.push_back(u.first); } if ((long long)v.size() == 0) { cout << "0\n"; return; } for (long long i = 1; i <= n; i++) { if (mp[a[i]] == 1) { for (auto u : v) { long long flg = 1; for (long long j = 0; j < 60; j++) { if (setBit(u, j) == 0 && setBit(a[i], j) == 1) flg = 0; } if (flg) { ans += b[i]; break; } } } } cout << ans; } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); long long t = 1; while (t--) { solve(); } }
1,700
CPP
#include <bits/stdc++.h> using namespace std; int32_t main() { long long n, x; cin >> n >> x; long long count = 0; if (x == 1) { cout << "1"; } else { set<long long> s; for (long long i = 1; i <= n; i++) { s.insert(i); } for (long long i = 1; i <= n; i++) { if (x % i == 0) { if (s.count(x / i)) { count++; } } } cout << count; } return 0; }
1,000
CPP
MOD = 1000000007 ii = lambda : int(input()) si = lambda : input() dgl = lambda : list(map(int, input())) f = lambda : map(int, input().split()) il = lambda : list(map(int, input().split())) ls = lambda : list(input()) from math import * t=[4,7,47,44,77,74,444,744,474,447,477,747,774,777] p=len(t) a=[] n=ii() for i in range(0,p): if(n%t[i]==0): a.append(1) if(a.count(1)>=1): print("YES") else: print("NO")
1,000
PYTHON3
a=input() b=input() c=[] for i in range(len(a)): if a[i]==b[i]: c.append('0') else: c.append('1') dot='' print(dot.join(c))
800
PYTHON3
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimization("unroll-loops") using namespace std; mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); int64_t happy[] = {4, 7, 44, 47, 74, 77, 444, 447, 474, 477, 744, 747, 774, 777, 4444, 4447, 4474, 4477, 4744, 4747, 4774, 4777, 7444, 7447, 7474, 7477, 7744, 7747, 7774, 7777, 1234567890}; struct node { int64_t _min; int64_t _minc; int64_t d; int64_t _happy; }; node t[567890]; void upd(node &v, node &vl, node &vr) { v._min = min(vl._min, vr._min); v._minc = (vl._min == v._min ? vl._minc : 0) + (vr._min == v._min ? vr._minc : 0); } void build(int64_t v, int64_t tl, int64_t tr) { if (tl == tr) { t[v]._minc = 1; return; } int64_t tm = (tl + tr) / 2; build(v * 2, tl, tm); build(v * 2 + 1, tm + 1, tr); } int64_t _count(int64_t v, int64_t tl, int64_t tr, int64_t l, int64_t r, int64_t sub) { t[v].d += sub; t[v]._min -= sub; if (l > r) return 0; if (tl == l && tr == r) { return (t[v]._min == 0 ? t[v]._minc : 0); } sub = t[v].d; t[v].d = 0; int64_t tm = (tl + tr) / 2; return _count(v * 2, tl, tm, l, min(r, tm), sub) + _count(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r, sub); } void add(int64_t v, int64_t tl, int64_t tr, int64_t l, int64_t r, int64_t val, int64_t sub) { t[v].d += sub; t[v]._min -= sub; if (l > r) return; if (tl == l && tr == r) { t[v].d += val; t[v]._min -= val; return; } sub = t[v].d; t[v].d = 0; int64_t tm = (tl + tr) / 2; add(v * 2, tl, tm, l, min(r, tm), val, sub); add(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r, val, sub); upd(t[v], t[v * 2], t[v * 2 + 1]); } void inc(int64_t v, int64_t tl, int64_t tr, int64_t sub) { t[v].d += sub; t[v]._min -= sub; if (t[v]._min >= 0) return; if (tl == tr) { while (t[v]._min < 0) { t[v]._min = happy[t[v]._happy++] - t[v].d; } return; } sub = t[v].d; t[v].d = 0; int64_t tm = (tl + tr) / 2; inc(v * 2, tl, tm, sub); inc(v * 2 + 1, tm + 1, tr, sub); upd(t[v], t[v * 2], t[v * 2 + 1]); } int32_t main() { ios_base ::sync_with_stdio(0); cin.tie(0); cout.tie(0); int64_t n, m; cin >> n >> m; build(1, 0, n - 1); for (int64_t i = 0; i < n; i++) { int64_t x; cin >> x; add(1, 0, n - 1, i, i, x, 0); } while (m--) { string type; cin >> type; if (type == "add") { int64_t l, r, d; cin >> l >> r >> d; l--; r--; add(1, 0, n - 1, l, r, d, 0); } else { int64_t l, r; cin >> l >> r; l--; r--; inc(1, 0, n - 1, 0); cout << _count(1, 0, n - 1, l, r, 0) << "\n"; } } }
2,400
CPP
t = int(input()) rs= [] import math def nCr(n, r): ts = 1 f = math.factorial ms = f(r) for i in range(n - r + 1, n + 1): ts *= i return int(ts/ms) for i in range(t): _ = int(input()) arr = input() a = [int(item) for item in arr.split(' ')] a = list(sorted(a)) c = 0 end = 0 for i in range(len(a)): if a[i] == a[i-1] and i>0: continue j = i while True: if j < len(a) -1: if a[j+1] - a[i] <=2: j +=1 else: break if j == len(a) -1: break x = j - i + 1 if x>=3: # print(nCr(x, 3)) c += nCr(x, 3) if end > i: x = end - i + 1 if x >= 3: c -= nCr(x, 3) end = j rs.append(c) for i in rs: print(int(i))
1,500
PYTHON3
#include <bits/stdc++.h> using namespace std; pair<long long int, long long int> ans; long long int qube(long long int x) { return x * x * x; } void fun(long long int m, long long int cnt = 0, long long int vol = 0) { if (m == 0) { ans = max(ans, make_pair(cnt, vol)); return; } long long int a = 1; while (qube(a + 1) <= m) a++; fun(m - qube(a), cnt + 1, vol + qube(a)); fun(qube(a) - 1 - qube(a - 1), cnt + 1, vol + qube(a - 1)); } int main() { long long int m; cin >> m; fun(m); cout << ans.first << " " << ans.second; return 0; }
2,200
CPP
#include <bits/stdc++.h> using namespace std; int main() { int n, loc = 1; cin >> n; string s; cin >> s; for (int i = 0; i <= n - 1; i++) { if (s[i] > s[i + 1]) { loc = i; break; } if (i == n - 1) loc = i; } s.erase(s.begin() + loc); cout << s; }
1,200
CPP
#include <bits/stdc++.h> using namespace std; using ll = int64_t; auto& errStream = cerr; class CerrDummy { } cerrDummy; template <class T> CerrDummy& operator<<(CerrDummy& cd, const T&) { return cd; } using charTDummy = char; using traitsDummy = char_traits<charTDummy>; CerrDummy& operator<<(CerrDummy& cd, basic_ostream<charTDummy, traitsDummy>&( basic_ostream<charTDummy, traitsDummy>&)) { return cd; } using pi = pair<ll, ll>; using vi = vector<ll>; using ld = long double; template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p) { os << "(" << p.first << "," << p.second << ")"; return os; } template <class T> ostream& operator<<(ostream& os, const vector<T>& v) { os << "{"; for (ll i = ll(0); i < ll((ll)v.size()); i++) { if (i) os << ","; os << v[i]; } os << "}"; return os; } ll read() { ll i; scanf("%" SCNd64, &i); return i; } void printSpace() { printf(" "); } void printEoln() { printf("\n"); } void print(ll x, ll suc = 1) { printf("%" PRId64, x); if (suc == 1) printEoln(); if (suc == 2) printSpace(); } string readString() { static char buf[3341000]; scanf("%s", buf); return string(buf); } char* readCharArray() { static char buf[3341000]; static ll bufUsed = 0; char* ret = buf + bufUsed; scanf("%s", ret); bufUsed += strlen(ret) + 1; return ret; } template <class T, class U> void chmax(T& a, U b) { if (a < b) a = b; } template <class T, class U> void chmin(T& a, U b) { if (b < a) a = b; } template <class T> T Sq(const T& t) { return t * t; } void Yes(bool ex = true) { cout << "YES" << endl; if (ex) exit(0); } void No(bool ex = true) { cout << "NO" << endl; if (ex) exit(0); } const ll infLL = LLONG_MAX / 3; const ll inf = infLL; vector<string> flip(vector<string> x) { ll n = x.size(), m = x[0].size(); vector<string> res(m, string(n, '.')); for (ll i = ll(0); i < ll(m); i++) for (ll j = ll(0); j < ll(n); j++) res[i][j] = x[j][i]; return res; } pair<ll, vector<string>> Solve(vector<string> x) { ll n = x.size(), m = x[0].size(); string waf = "ACGT"; sort(waf.begin(), waf.end()); pair<ll, string> ans(inf, ""); do { if (waf[0] < waf[1] && waf[2] < waf[3]) { ll sum = 0; for (ll i = ll(0); i < ll(n); i++) { ll k = (i % 2) * 2; ll mn = inf; for (ll _ = ll(0); _ < ll(2); _++) { ll cnt = 0; for (ll j = ll(0); j < ll(m); j++) if (x[i][j] != waf[k + j % 2]) cnt++; chmin(mn, cnt); swap(waf[k], waf[k + 1]); } sum += mn; } chmin(ans, make_pair(sum, waf)); } } while (next_permutation(waf.begin(), waf.end())); waf = ans.second; vector<string> res(n, string(m, '.')); for (ll i = ll(0); i < ll(n); i++) { ll k = (i % 2) * 2; pi mn(inf, -1); for (ll _ = ll(0); _ < ll(2); _++) { ll cnt = 0; for (ll j = ll(0); j < ll(m); j++) if (x[i][j] != waf[k + j % 2]) cnt++; chmin(mn, pi(cnt, _)); swap(waf[k], waf[k + 1]); } if (mn.second) swap(waf[k], waf[k + 1]); for (ll j = ll(0); j < ll(m); j++) res[i][j] = waf[k + j % 2]; } return make_pair(ans.first, res); } signed main() { ll n = read(), m = read(); vector<string> x(n); for (ll i = ll(0); i < ll(n); i++) { x[i] = readString(); } auto ans1 = Solve(x); auto ans2 = Solve(flip(x)); ans2.second = flip(ans2.second); auto ans = min(ans1, ans2); { ll dif = 0; for (ll i = ll(0); i < ll(n); i++) for (ll j = ll(0); j < ll(m); j++) if (x[i][j] != ans.second[i][j]) dif++; assert(dif == ans.first); cerrDummy << dif << endl; } for (ll i = ll(0); i < ll(n); i++) printf("%s\n", ans.second[i].c_str()); }
2,100
CPP
#include <bits/stdc++.h> using namespace std; int n; char S[1000]; int main() { cin >> n; scanf("%s", S); int p = 0; while (p < n) { if (S[p] == 'o') { if (p + 2 < n && S[p + 1] == 'g' && S[p + 2] == 'o') { while (p + 2 < n && S[p + 1] == 'g' && S[p + 2] == 'o') p += 2; printf("***"); p++; continue; } } printf("%c", S[p]); p++; } return 0; }
900
CPP
#include <bits/stdc++.h> using namespace std; vector<long long> a, b, o, felulrol, felulrol2, alulrol, alulrol2; int n; int main() { ios_base::sync_with_stdio(0); cin >> n; a.resize(n + 1); b.resize(n + 1); o.resize(n + 1); felulrol.resize(n + 1); felulrol2.resize(n + 1); alulrol.resize(n + 1); alulrol2.resize(n + 1); for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n; i++) { cin >> b[i]; } for (int k = n - 1; k >= 0; k--) { o[k] = o[k + 1] + a[k] + b[k]; } long long m = 0; for (int k = n - 1; k >= 0; k--) { felulrol[k] = (2 * m + 1) * b[k] + felulrol[k + 1] + o[k + 1]; m++; } for (int k = 0; k < n; k++) { felulrol2[k] = felulrol[k] + 2 * k * o[k]; } m = 0; for (int k = n - 1; k >= 0; k--) { alulrol[k] = (2 * m + 1) * a[k] + alulrol[k + 1] + o[k + 1]; m++; } for (int k = 0; k < n; k++) { alulrol2[k] = alulrol[k] + 2 * k * o[k]; } vector<long long> bo(n); for (int k = 0; k < n; k++) { if (k != 0) { if (k % 2 == 0) { bo[k] = bo[k - 1] + a[k] * (2 * k) + b[k] * (2 * k + 1); } else { bo[k] = bo[k - 1] + a[k] * (2 * k + 1) + b[k] * (2 * k); } } else { bo[0] = b[0]; } } long long maximum = 0; for (int k = 0; k < n - 1; k++) { if (k % 2 == 0) { maximum = max((long long)bo[k] + alulrol2[k + 1], maximum); } else { maximum = max((long long)bo[k] + felulrol2[k + 1], maximum); } } cout << max(maximum, (long long)felulrol2[0]); return 0; }
1,800
CPP
#include <bits/stdc++.h> using namespace std; template <typename T> void chmax(T &a, T b) { a = max(a, b); } template <typename T> void chmin(T &a, T b) { a = min(a, b); } template <typename T> void chadd(T &a, T b) { a = a + b; } long long int dx[] = {0, 0, 1, -1}; long long int dy[] = {1, -1, 0, 0}; constexpr long long INF = 1001001001001001LL; constexpr long long MOD = 1000000007LL; signed main() { long long int N, K; cin >> N >> K; string s; cin >> s; long long int cnt[30] = {}; for (long long int(i) = (0); (i) < (s.length()); (i)++) { cnt[s[i] - 'a']++; } bool ok = true; for (long long int(i) = (0); (i) < (26); (i)++) if (cnt[i] > K) ok = false; cout << (ok ? "YES" : "NO") << endl; return 0; }
900
CPP
#include <bits/stdc++.h> using namespace std; const int INF = 1000 * 1000 * 1000; const long long INF64 = 1000LL * 1000LL * 1000LL * 1000LL * 1000LL * 1000LL; int n; map<string, int> mp; int r[10][10]; int a[3]; void Load() { int m = 1; cin >> n; string x, y; int t1, t2; for (int i = 1; i <= n; i++) { cin >> x >> y >> y; if (mp[x] == 0) mp[x] = m++; t1 = mp[x]; if (mp[y] == 0) mp[y] = m++; t2 = mp[y]; r[t1][t2] = 1; } cin >> a[0] >> a[1] >> a[2]; } void Solve() { int ans = INF; int sim = INF; int k, s1, s2, s3, sum, delt; vector<int> v; for (int i = 1; i <= 7; i++) v.push_back(i); do { for (int i = 1; i <= 5; i++) for (int j = 1; j <= 7 - i - 1; j++) { k = 7 - i - j; s1 = a[0] / i; s2 = a[1] / j; s3 = a[2] / k; sum = 0; for (int t1 = 0; t1 < i; t1++) for (int t2 = 0; t2 < i; t2++) sum += r[v[t1]][v[t2]]; for (int t1 = i; t1 < i + j; t1++) for (int t2 = i; t2 < i + j; t2++) sum += r[v[t1]][v[t2]]; for (int t1 = i + j; t1 < 7; t1++) for (int t2 = i + j; t2 < 7; t2++) sum += r[v[t1]][v[t2]]; delt = abs(s1 - s2); delt = max(delt, abs(s1 - s3)); delt = max(delt, abs(s2 - s3)); if (delt < ans) { ans = delt; sim = sum; } if (delt == ans) { if (sim < sum) sim = sum; } } } while (next_permutation(v.begin(), v.end())); cout << ans << " " << sim; } int main() { Load(); Solve(); return 0; }
1,400
CPP
a = [] for i in range(4): s = input() for elem in s: a.append(elem) def c(q, w, e): q -= 1 w -= 1 e -= 1 q = a[q] w = a[w] e = a[e] kr = 0 ps = 0 if (q == 'o') or (w == 'o') or (e == 'o'): return False if (q == 'x'): kr += 1 if (w == 'x'): kr += 1 if (e == 'x'): kr += 1 if (kr == 2): print("YES") exit() return True else: return False c(1, 2, 3) c(2, 3, 4) c(5, 6, 7) c(6, 7, 8) c(9, 10, 11) c(10, 11, 12) c(13, 14, 15) c(14, 15, 16) c(1, 5, 9) c(5, 9, 13) c(2, 6, 10) c(6, 10, 14) c(3, 7, 11) c(7, 11, 15) c(4, 8, 12) c(8, 12, 16) c(1, 6, 11) c(5, 10, 15) c(2, 7, 12) c(6, 11, 16) c(3, 6, 9) c(7, 10, 13) c(4, 7, 10) c(8, 11, 14) print("NO")
1,100
PYTHON3
for _ in range(int(input())): n,k = [int(x) for x in input().split()] a = [int(x) for x in input().split()] ds = {} for j in range(n): e = a[j] if e%k !=0: ele = k - e%k if ele not in ds.keys(): ds[ele]=1 else: ds[ele]+=1 mi = -1 mv = -1 # print(ds) for j in ds.keys(): if ds[j]>mv or (ds[j]==mv and mi<j): mi = j mv = ds[j] if mi == -1: print(0) else: print((mv-1)*k+mi+1)
1,400
PYTHON3
#include <bits/stdc++.h> using namespace std; const int maxx = 1e6 + 19; long long a, b, c, d, ans, jvb, minn = 99999999999, maxn = -999999999999, arr[maxx], n, m, x, y; vector<int> v; string s; void Input() { cin >> x >> y >> c >> d; } void Solve() { d *= (x % y); c *= y - (x % y); ans = min(c, d); cout << ans << endl; } int main() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); Input(), Solve(); return 0; }
1,000
CPP
from collections import Counter for _ in range(int(input())): n, k = list(map(int, input().split())) # n = int(input()) arr = list(map(int, input().split())) ans = [] temp = Counter(arr) if len(temp) > k: print(-1) continue else: for i in temp: ans.append(i) if len(ans) < k: temp2 = [1] * (k - len(ans)) ans += temp2 print(len(ans)*n) print(*(ans * n))
1,400
PYTHON3
#include <bits/stdc++.h> using namespace std; int n; char a[100010]; vector<int> points[10]; int dis[100010][10]; int dch[10][10]; int cnt[10][300]; int mask[100010]; int ans; long long ans2; void update(int x, int tot) { if (x == ans) ans2 += tot; if (x > ans) { ans = x; ans2 = tot; } } void bfs(int ch) { queue<int> q; for (vector<int>::iterator i = points[ch].begin(); i != points[ch].end(); i++) q.push(*i); for (int i = 1; i <= n; i++) if (a[i] == ch + 96) dis[i][ch] = 0; else dis[i][ch] = 0x3f3f3f3f; while (!q.empty()) { int x = q.front(); q.pop(); if (dis[x - 1][ch] == 0x3f3f3f3f) { dis[x - 1][ch] = dis[x][ch] + 1; q.push(x - 1); } if (dis[x + 1][ch] == 0x3f3f3f3f) { dis[x + 1][ch] = dis[x][ch] + 1; q.push(x + 1); } } } void add(int pos) { cnt[a[pos] - 96][mask[pos]]++; } int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf(" %c", &a[i]); points[a[i] - 96].push_back(i); } for (int ch = 1; ch <= 8; ch++) bfs(ch); memset(dch, 0x3f, sizeof(dch)); for (int i = 1; i <= 8; i++) dch[i][i] = 0; for (int k = 1; k <= n; k++) for (int i = 1; i <= 8; i++) for (int j = 1; j <= 8; j++) dch[i][j] = min(dch[i][j], dis[k][i] + dis[k][j]); for (int k = 1; k <= 8; k++) for (int i = 1; i <= 8; i++) for (int j = 1; j <= 8; j++) dch[i][j] = min(dch[i][j], dch[i][k] + dch[k][j] + 1); for (int i = 1; i <= n; i++) for (int j = 1; j <= 8; j++) for (int ch = 1; ch <= 8; ch++) dis[i][ch] = min(dis[i][ch], dis[i][j] + dch[j][ch] + 1); for (int i = 1; i <= n; i++) for (int ch = 1; ch <= 8; ch++) mask[i] |= (dis[i][ch] - dch[a[i] - 96][ch]) << (ch - 1); for (int r = 1; r <= n; r++) for (int l = max(1, r - 15); l < r; l++) { int minf = r - l; for (int ch = 1; ch <= 8; ch++) minf = min(minf, dis[l][ch] + dis[r][ch] + 1); update(minf, 1); } for (int i = 17, j = 1; i <= n; i++, j++) { add(j); for (int ch = 1; ch <= 8; ch++) for (int st = 0; st <= 255; st++) { if (cnt[ch][st]) { int fuck = 0x3f3f3f3f; for (int sb = 1; sb <= 8; sb++) fuck = min(fuck, dch[ch][sb] + dis[i][sb] + (((st) >> (sb - 1)) & 1) + 1); update(fuck, cnt[ch][st]); } } } printf("%d %lld\n", ans, ans2); return 0; }
3,300
CPP
n = int(input()) s = input() z = s.count('z') o = s.count('n') print("1 "*o + "0 "*z)
800
PYTHON3
n = int(input()) seq = list(map(int, input().split())) sum_=0 neg = 0 zero = 0 for num in seq: if num < 0: neg += 1 if num == 0: sum_ += 1 zero += 1 continue sum_+= abs(num) -1 if neg%2 == 0 or zero > 0: print(sum_) else: print(sum_ +2)
900
PYTHON3
#include <bits/stdc++.h> using namespace std; string s[1010]; int n, m, visited[1010][1010], dist[1010][1010]; void bfs(int x1, int y1) { queue<pair<int, int> > myq; myq.push(pair<int, int>(x1, y1)); visited[x1][y1] = 1; dist[x1][y1] = 0; while (!myq.empty()) { int x = myq.front().first; int y = myq.front().second; myq.pop(); if (x > 0 and dist[x - 1][y] > dist[x][y] + 1 and s[x - 1][y] != 'T') myq.push(pair<int, int>(x - 1, y)), dist[x - 1][y] = dist[x][y] + 1; if (x < n - 1 and dist[x + 1][y] > dist[x][y] + 1 and s[x + 1][y] != 'T') myq.push(pair<int, int>(x + 1, y)), dist[x + 1][y] = dist[x][y] + 1; if (y > 0 and dist[x][y - 1] > dist[x][y] + 1 and s[x][y - 1] != 'T') myq.push(pair<int, int>(x, y - 1)), dist[x][y - 1] = dist[x][y] + 1; if (y < m - 1 and dist[x][y + 1] > dist[x][y] + 1 and s[x][y + 1] != 'T') myq.push(pair<int, int>(x, y + 1)), dist[x][y + 1] = dist[x][y] + 1; } } int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); int i, j, sx, sy, ex, ey; cin >> n >> m; for (i = 0; i < n; i++) cin >> s[i]; for (i = 0; i < 1010; i++) for (j = 0; j < 1010; j++) dist[i][j] = 1000000007; for (i = 0; i < n; i++) for (j = 0; j < m; j++) { if (s[i][j] == 'S') sx = i, sy = j; else if (s[i][j] == 'E') ex = i, ey = j; } bfs(ex, ey); int ans = 0; for (i = 0; i < n; i++) { for (j = 0; j < m; j++) { if (s[i][j] > '0' and s[i][j] <= '9' and dist[i][j] <= dist[sx][sy]) ans += s[i][j] - '0'; } } cout << ans; return 0; }
1,500
CPP
#include <bits/stdc++.h> const int MAX_N = 500 + 10; std::bitset<MAX_N> f[2][64][MAX_N], g, temp; int n, m; int main() { scanf("%d %d", &n, &m); for (int i = 0; i < m; ++i) { int x, y, t; scanf("%d %d %d", &x, &y, &t); f[t][0][x][y] = 1; } for (int i = 1; i <= 60; ++i) for (int j = 1; j <= n; ++j) for (int k = 1; k <= n; ++k) for (int t = 0; t < 2; ++t) if (f[t][i - 1][j][k]) f[t][i][j] |= f[t ^ 1][i - 1][k]; int flg = 0; long long ans = 0, INF = 1e18; g[1] = 1; for (int i = 60; i >= 0; --i) { temp = 0; for (int j = 1; j <= n; ++j) if (g[j]) temp |= f[flg][i][j]; if (temp.count()) { ans += ((long long)1 << i); g = temp; flg ^= 1; } } if (ans > INF) printf("-1\n"); else printf("%I64d\n", ans); return 0; }
2,400
CPP
a = int(input()) check = 0 if a%2==0: if (a/2)%2==0: print(0) check = 1 elif (a+1)%2==0: if ((a+1)/2)%2==0: print(0) check = 1 if (check==0): print (1)
800
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; if (n == 3) { cout << "1" << endl; } else { cout << (n - 3 + 1) * (n - 1) - (n - 2) << endl; } return 0; }
1,100
CPP
#include <bits/stdc++.h> using namespace std; bool desc(long long int a, long long int b) { return (a > b); } bool pairone(pair<long long int, long long int> &a, pair<long long int, long long int> &b) { return (a.first < b.first); } void show(vector<int> vec) { for (auto x : vec) cout << x << " "; cout << endl; ; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ; int n; cin >> n; vector<int> a(n), b(n); vector<int> perm_a(n + 1), perm_b(n + 1); long long int i; for (i = 0; i < n; i++) { cin >> a[i]; perm_a[a[i]] = i; } for (i = 0; i < n; i++) { cin >> b[i]; perm_b[b[i]] = i; } map<int, int> shifts2match; int j, shift, maxi = 0; for (i = 0; i < n; i++) { i = perm_b[b[i]]; j = perm_a[b[i]]; shift = (j - i >= 0 ? j - i : n + j - i); shifts2match[shift]++; maxi = max(maxi, shifts2match[shift]); } cout << maxi; }
1,400
CPP
#include <bits/stdc++.h> using namespace std; const int N = 100005; const int mod = 1e9 + 7; int f[N], n, ans, num, now, m; vector<int> a[N]; bool ok; bool check() { if (n <= 2 && m <= 3) return 0; return 1; } int main() { cin >> n >> m; if (n == 1 && m == 1) { cout << "YES\n1"; return 0; } if (n <= m) for (int i = (1); i < (n + 1); i++) for (int j = (1); j < (m + 1); j++) a[i].push_back((i - 1) * m + j); else { ok = 1; swap(n, m); for (int j = (1); j < (m + 1); j++) for (int i = (1); i < (n + 1); i++) a[i].push_back((j - 1) * n + i); } if (check()) cout << "YES" << endl; else { cout << "NO"; return 0; } if (m == 4) { for (int i = (1); i < (n + 1); i++) { if (i & 1) { swap(a[i][0], a[i][2]); swap(a[i][0], a[i][1]); swap(a[i][1], a[i][3]); } else { swap(a[i][0], a[i][1]); swap(a[i][0], a[i][2]); swap(a[i][2], a[i][3]); } } if (!ok) { for (int i = (1); i < (n + 1); i++) for (int j = (0); j < (m); j++) cout << a[i][j] << (j == m - 1 ? "\n" : " "); } else { for (int j = (0); j < (m); j++) for (int i = (1); i < (n + 1); i++) cout << a[i][j] << (i == n ? "\n" : " "); } } else if (n == 3 && m == 3) { cout << "6 1 8\n7 5 3\n2 9 4"; } else { for (int i = (1); i < (n + 1); i++) { vector<int> tmp; if (i & 1) { for (int j = 1; j < (int)a[i].size(); j += 2) tmp.push_back(a[i][j]); for (int j = 0; j < (int)a[i].size(); j += 2) tmp.push_back(a[i][j]); a[i] = tmp; } else { for (int j = 0; j < (int)a[i].size(); j += 2) tmp.push_back(a[i][j]); for (int j = 1; j < (int)a[i].size(); j += 2) tmp.push_back(a[i][j]); a[i] = tmp; } } if (!ok) { for (int i = (1); i < (n + 1); i++) for (int j = (0); j < (m); j++) cout << a[i][j] << (j == m - 1 ? "\n" : " "); } else { for (int j = (0); j < (m); j++) for (int i = (1); i < (n + 1); i++) cout << a[i][j] << (i == n ? "\n" : " "); } } return 0; }
2,200
CPP
# Problem: B # Date: February 11 2020 # Author: OBJECT.705X t=int(input()) while t: n=int(input()) a=[int(x) for x in input().split()] a=sorted(a) print(a[n]-a[n-1]) t-=1
1,000
PYTHON3
k, n = map(int,input().split()) temp = input().split() data = [] i = 1 for item in temp: data.append([int(item),i]) i += 1 data.sort() cost = 0 answer = [] for item in data: if (item[0]+cost)<=n: cost += item[0] answer.append(item[1]) else: break print(len(answer)) if(len(answer) != 0): for i in range(len(answer)-1): print(answer[i],end=' ') print(answer[-1])
1,000
PYTHON3
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); string x; cin >> x; if (x.length() < 26) { cout << -1 << endl; return 0; } string to = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; int n = x.length(); for (int i = 0; i < n - 25; i++) { string det = x.substr(i, 26); int a = 0; int arr[27]{}; for (int i = 0; i < det.length(); i++) { if (det[i] == '?') { a++; } else { arr[det[i] - 'A']++; } } bool sin = 1; int mis = 0; for (int i = 0; i < 26; i++) { if (arr[i] > 1) { sin = 0; break; } else if (arr[i] == 0) mis++; } if (sin && mis <= a) { for (int j = i; j < i + 26; j++) { if (x[j] == '?') { for (int k = 0; k < 26; k++) { if (arr[k] == 0) { arr[k] = 1; char t = 'A' + k; x[j] = t; break; } } } } for (int j = 0; j < x.length(); j++) { if (x[j] == '?') x[j] = 'A'; } cout << x << endl; return 0; } } cout << -1 << endl; return 0; }
1,300
CPP
w = str(input()) x = w.split("1") y = w.split("0") if any([len(t1) >= 7 for t1 in x]) or any([len(t2) >= 7 for t2 in y]): print("YES") else: print("NO")
900
PYTHON3
from collections import defaultdict, deque, Counter, OrderedDict from bisect import insort, bisect_right, bisect_left import threading, sys def main(): n, k = map(int, input().split()) s = [int(i) for i in input().split()] n = n - (2*k - n) if n <= 0: print(s[-1]) else: ans = s[-1] for i in range(0,n//2): ans = max(ans,s[i]+s[n-1-i]) print(ans) if __name__ == "__main__": """sys.setrecursionlimit(400000) threading.stack_size(40960000)""" thread = threading.Thread(target=main) thread.start()
1,400
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { long long n, res = 0, t1, t2, t3; cin >> n; while (n--) { cin >> t1 >> t2 >> t3; if (t1 == 1 && t2 == 1 && t3 == 1) ++res; else if (t1 == 1 && t2 == 1 && t3 == 0) ++res; else if (t1 == 1 && t2 == 0 && t3 == 1) ++res; else if (t1 == 0 && t2 == 1 && t3 == 1) ++res; } cout << res << endl; return 0; }
800
CPP
#include <bits/stdc++.h> using namespace std; inline int read() { int sum = 0; char c = getchar(); bool f = 0; while (c < '0' || c > '9') { if (c == '-') f = 1; c = getchar(); } while (c >= '0' && c <= '9') { sum = sum * 10 + c - '0'; c = getchar(); } if (f) return -sum; return sum; } const int N = 600000; const int INF = 2000000000; int n, m, cnt, A[N], B[N]; namespace LCT { int f[N], son[N][2], mn[N], v[N], sz[N]; bool rev[N]; inline void in(int x) { v[x] = INF; sz[x] = (x <= n); mn[x] = x; } inline bool RT(int x) { return son[f[x]][0] != x && son[f[x]][1] != x; } inline void up(int &x, int y) { if (y && v[x] > v[y]) x = y; } inline void up(int x) { sz[x] = sz[son[x][0]] + sz[son[x][1]] + (x <= n); mn[x] = x; up(mn[x], mn[son[x][0]]); up(mn[x], mn[son[x][1]]); } inline void down(int x) { if (rev[x]) rev[x] = 0, swap(son[x][0], son[x][1]), rev[son[x][0]] ^= 1, rev[son[x][1]] ^= 1; } inline void dn(int x) { if (!RT(x)) dn(f[x]); down(x); } inline void R(int x) { int p = f[x], g = f[p]; bool a = son[p][1] == x, b = !a; son[p][a] = son[x][b]; f[son[x][b]] = p; if (!RT(p)) son[g][son[g][1] == p] = x; f[x] = g; son[x][b] = p; f[p] = x; up(p); up(x); } inline void splay(int x) { dn(x); int p; while (!RT(x)) { if (RT(p = f[x])) { R(x); break; } ((son[f[p]][0] == p) ^ (son[p][0] == x)) ? R(x) : R(p); R(x); } } inline void access(int x) { for (int y = 0; x; y = x, x = f[x]) splay(x), son[x][1] = y, up(x); } inline void mroot(int x) { access(x); splay(x); rev[x] ^= 1; } inline int find(int x) { access(x); splay(x); while (son[x][0]) x = son[x][0]; return x; } inline void link(int x, int y) { mroot(x); f[x] = y; } inline void cut(int x, int y) { mroot(x); access(y); splay(y); son[y][0] = 0; f[x] = 0; up(y); } bool ind[N], cir[N]; int em; inline void link(int x, int y, int k) { int a = find(x), b = find(y); if (a != b) { link(x, k); link(y, k); ind[k] = 1; return; } mroot(x); access(y); splay(y); b = sz[y]; if (v[k] > v[a = mn[y]]) cut(A[a], a), cut(B[a], a), link(x, k), link(y, k), ind[a] = 0, ind[k] = 1; if (b & 1) { v[k] > v[a] ? cir[a] = 1 : cir[k] = 1; em++; } } } // namespace LCT using namespace LCT; map<pair<int, int>, int> H; int X[N], Y[N], id[N]; bool tp[N]; int main() { int i, j, x, y; pair<int, int> o; cnt = n = read(); m = read(); for (i = 1; i <= n; i++) in(i); for (i = 1; i <= m; i++) { X[i] = x = read(); Y[i] = y = read(); o = make_pair(x, y); if (!H[o]) id[i] = ++cnt, in(cnt), H[o] = cnt, tp[i] = 1, A[cnt] = X[i], B[cnt] = Y[i]; else v[x = H[o]] = i, id[i] = x, H[o] = 0; } for (i = 1; i <= m; i++) { if (tp[i]) link(X[i], Y[i], id[i]); else if (ind[id[i]]) cut(X[i], id[i]), cut(Y[i], id[i]); else if (cir[id[i]]) cir[id[i]] = 0, em--; puts(em ? "NO" : "YES"); } return 0; }
2,500
CPP
import os import sys from io import BytesIO, IOBase import math from decimal import Decimal from decimal import * from collections import defaultdict, deque import heapq from decimal import Decimal getcontext().prec = 25 abcd='abcdefghijklmnopqrstuvwxyz' ABCD='ABCDEFGHIJKLMNOPQRSTUVWXYZ' months = {1:31, 2:28,3:31, 4:30, 5:31, 6:30, 7:31, 8:31, 9:30, 10:31, 11:30, 12:31} MOD = 1000000007 BUFSIZE = 8192 from bisect import bisect_left, bisect_right 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") # for _ in range(int(input())): # map(int, input().split(" ")) # list(map(int, input().split(" "))) n, m = map(int, input().split(" ")) p = list(map(int, input().split(" "))) t = list(map(int, input().split(" "))) t1 = t2 = 0 ans1 =ans2 = 0 for i in range(n): t1+=t[i] t2+=t[n-i-1] ans1 += max(0, p[i]-m*(t1)) ans2 += max(0, p[n-1-i]-m*(t2)) if ans1>ans2: print("Limak") elif ans2>ans1: print("Radewoosh") else: print("Tie")
800
PYTHON3
t = int(input()) for f in range(t): x, y, a, b = map(int, input().split()) if (y - x) % (a + b) == 0: print((y - x) // (a + b)) else: print(-1)
800
PYTHON3
t = int(input()) for _ in range(t): n, m = map(int, input().split()) l = [] for i in range(n): l.append(input()) count = 0 trees = dict() for i in range(n-1,-1,-1): for j in range(0,m): if l[i][j] == "*": x = 0 if i != n-1 and j >= 1 and j <= m-2: if (i+1,j-1) in trees and (i+1,j) in trees and (i+1,j+1) in trees: x = min(trees[(i+1,j-1)],trees[(i+1,j)],trees[(i+1,j+1)]) count += x+1 trees[(i,j)] = 1+x print(count)
1,400
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, m; cin >> n >> m; vector<int> A(n, 0), B(m, 0); for (int i = 0; i < n; i++) cin >> A[i]; for (int i = 0; i < m; i++) cin >> B[i]; int times = n; if (n <= 1) { cout << "YES" << endl; continue; } while (times--) { int flag = 0; for (int p = 0; p < m; p++) { int i = B[p] - 1; if (A[i] > A[i + 1]) { swap(A[i], A[i + 1]); flag = 1; } } if (flag == 0) break; } int flag = 0; for (int i = 1; i < n; i++) { if (A[i] >= A[i - 1]) continue; else { flag = 1; break; } } if (flag == 1) { cout << "NO" << endl; } else cout << "YES" << endl; } return 0; }
1,200
CPP
#include <bits/stdc++.h> const double EPS = 0.00000001; const long long mod = 1000000000 + 7; using namespace std; int n; pair<pair<long long, long long>, int> a[100100]; int main() { ios::sync_with_stdio(0); cin >> n; for (int i = 0; i < n; i++) { cin >> a[i].first.first >> a[i].first.second; a[i].second = i; } sort(a, a + n); for (int i = 0; i < n; i++) { long long ax = a[i].first.first, ay = a[i].first.second, bx = a[i + 1].first.first, by = a[i + 1].first.second, cx = a[i + 2].first.first, cy = a[i + 2].first.second; long long d = ax * (by - cy) + bx * (cy - ay) + cx * (ay - by); if (d == 0) continue; else { cout << a[i].second + 1 << " " << a[i + 1].second + 1 << " " << a[i + 2].second + 1; break; } } int ____________; cin >> ____________; return 0; }
1,600
CPP
for _ in range(int(input())): n,k=map(int,input().split()) arr=list(map(int,input().split())) arr.append(0) val=0 flag=True;mmin=0 if n==1: print(arr[0]) else: for i in range(0,n): if flag: if arr[i]>arr[i+1]: val+=arr[i] flag=False else: if arr[i]<arr[i+1]: val-=arr[i] mmin=arr[i] flag=True if flag==True: val+=mmin print(val)
1,300
PYTHON3
#include <bits/stdc++.h> const int N = 1e6 + 10; const int mod = 1e9 + 7; const int INF = 0x3f3f3f3f; using namespace std; int n, k; int x; map<int, int> mp; vector<int> res; bool check(int x) { int cnt = 0; for (auto w : mp) { cnt += w.second / x; } if (cnt >= k) return true; return false; } int main() { scanf("%d %d", &n, &k); mp.clear(); res.clear(); for (int i = 1; i <= n; ++i) { scanf("%d", &x); mp[x]++; } int l = 1, r = n; while (l < r) { int mid = (l + r + 1) >> 1; if (check(mid)) { l = mid; } else r = mid - 1; } int cnt = 0; for (auto w : mp) { int t = w.second / l; if (t > 0) { for (int i = 1; i <= t; ++i) { res.push_back(w.first); cnt++; if (cnt == k) { for (auto it : res) { printf("%d ", it); } return 0; } } } } return 0; }
1,600
CPP
#include <bits/stdc++.h> using namespace std; int t, n; int main() { cin >> t; while (t--) { cin >> n; cout << n << "\n"; } }
900
CPP
#include <bits/stdc++.h> using namespace std; struct node { int x, y, mx, mn; }; int N; vector<int> v; node a[1000008]; void initialize(int ind, int start, int end) { if (start == end) { a[ind].x = a[ind].y = start; a[ind].mx = v[start]; a[ind].mn = 0; } else { int mid = (start + end) / 2; initialize(ind * 2, start, mid); initialize(ind * 2 + 1, mid + 1, end); a[ind].mx = max(a[ind * 2].mx, a[ind * 2 + 1].mx); if (a[ind].mx == a[ind * 2].mx) { a[ind].mn = max(a[ind * 2].mn, a[ind * 2 + 1].mx); a[ind].x = a[ind * 2].x; if (a[ind].mn == a[ind * 2].mn) a[ind].y = a[ind * 2].y; else a[ind].y = a[ind * 2 + 1].x; } else { a[ind].mn = max(a[ind * 2 + 1].mn, a[ind * 2].mx); a[ind].x = a[ind * 2 + 1].x; if (a[ind].mn == a[ind * 2].mx) a[ind].y = a[ind * 2].x; else a[ind].y = a[ind * 2 + 1].y; } } } node query(int ind, int i, int j, int start, int end) { if (i <= start && j >= end) return a[ind]; int mid = (start + end) / 2; if (j <= mid) return query(ind * 2, i, j, start, mid); else if (i > mid) return query(ind * 2 + 1, i, j, mid + 1, end); else { node p1, p2, p3; p1 = query(ind * 2, i, j, start, mid); p2 = query(ind * 2 + 1, i, j, mid + 1, end); p3.mx = max(p1.mx, p2.mx); if (p3.mx == p1.mx) { p3.mn = max(p1.mn, p2.mx); p3.x = p1.x; if (p3.mn == p1.mn) p3.y = p1.y; else p3.y = p2.x; } else { p3.mn = max(p2.mn, p1.mx); p3.x = p2.x; if (p3.mn == p1.mx) p3.y = p1.x; else p3.y = p2.y; } return p3; } } map<map<int, int>, int> dp; int ans(int i, int j) { if (i >= j) return 0; map<int, int> mp; mp[i] = j; if (dp.count(mp) > 0) return dp[mp]; node p = query(1, i - 1, j - 1, 0, N - 1); int as = p.mx ^ p.mn; as = max(as, max(ans(i, max(p.x, p.y)), ans(min(p.x, p.y) + 2, j))); as = max(as, ans(min(p.x, p.y) + 2, max(p.x, p.y))); dp[mp] = as; return as; } int main() { int n; cin >> n; N = n; v.resize(n); for (int i = 0; i < n; i++) scanf("%d", &v[i]); initialize(1, 0, n - 1); cout << ans(1, n) << "\n"; return 0; }
1,800
CPP
#732A-Buy a Shovel k,r=map(int,input().split(' ')) for i in range(1,10): c=k*i if (c-10*int(c/10) == 0) or (c-10*int(c/10) == r): print(i) break
800
PYTHON3
from math import * # from sys import stdin,stdout def binarySearch(arr,x): l=0 r=len(arr)-1 while l <= r: mid = (l + r)//2; if arr[mid] == x: return mid elif arr[mid] < x: l = mid + 1 else: r = mid - 1 return -1 def js(arr,x): l=0 r=len(arr)-1 ans=-1 while(l<=r): m=(l+r)//2 if(arr[m]<=x): ans=m l=m+1 else: r=m-1 return ans def jg(arr,x): l=0 r=len(arr)-1 ans=-1 while(l<=r): m=(l+r)//2 if(arr[m]>=x): ans=m r=m-1 else: l=m+1 return ans def ceil(a,b): if a%b == 0: return int(a/b) else: return (a//b + 1) for i in range(int(input())): x,y,a,b=map(int,input().split()) if((y-x)%(a+b)==0): print((y-x)//(a+b)) else: print(-1)
800
PYTHON3
s = str(input()) if 65 <= ord((s[0])) <= 90: print(s) else: print(s[0].upper()+s[1:])
800
PYTHON3
n,m=map(int,input().split()) if n%2==0: if m>=n/2: print(0,end=" ") else: print(n-2*m,end=" ") else: if m>n/2: print(0,end=" ") else: print(n-2*m,end=" ") t=1 num=0 if(m==0): print(n) else: i=1 while(i<=m): i+=t t+=1 if(i!=1): print(n-t) else: print(n-2)
1,300
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); string inp, s = "><+-.,[]"; cin >> inp; int k = 0; for (int i = 0; i < inp.length(); i++) { k *= 16; k += (8 + s.find(inp[i])); k %= 1000003; } cout << k; return 0; }
1,200
CPP
#include <bits/stdc++.h> using namespace std; int static const N = 1234567; long long n, br; map<int, int> mapa; long long niz[N]; int main() { cin >> n; int m = sqrt(n); for (int i = 1; i <= m + 3; i++) { if (n % i == 0) { int t = n / i; niz[br++] = (long long)t + (long long)n * ((long long)t - 1) / 2; t = i; niz[br++] = (long long)t + (long long)n * ((long long)t - 1) / 2; } } sort(niz, niz + br); for (int i = 0; i < br; i++) if (i == 0 || niz[i] != niz[i - 1]) cout << niz[i] << " "; printf("\n"); return 0; }
1,400
CPP
#include <bits/stdc++.h> using namespace std; const int maxn = 10000 + 10; long long d[2][20001], a[maxn]; const int mod = 1e9 + 7; int abss(int fd) { if (fd < 0) fd *= -1; return fd; } int main() { int n, m, f, g, c; cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; d[0][a[0]] = 1; long long ans = 0; ans += d[0][0]; for (int i = 1; i < n; i++) for (int j = 0; j < maxn; j++) { int it = i % 2; d[it][j] = d[it ^ 1][abss(a[i] - j)] + d[it ^ 1][abss(a[i] + j)]; d[it][j] %= mod; if (j == a[i]) d[it][j]++; d[it][j] %= mod; if (j == 0) ans += d[it][j], ans %= mod; } cout << ans; }
2,300
CPP
R = input().split("WUB") R = [x for x in R if x != ''] print(' '.join(R))
900
PYTHON3
s=0 n=int(input()) for i in range(n): k=input() if(k=="Tetrahedron"): s+=4 elif(k=="Cube"): s+=6 elif(k=="Octahedron"): s+=8 elif(k=="Dodecahedron"): s+=12 elif(k=="Icosahedron"): s+=20 print(s) #
800
PYTHON3
a=['su','mo','tu','we','th','fr','sa'] b=a.index(input()[:2]) c=a.index(input()[:2]) if (c-b)%7 in [0,2,3]:print('YES') else:print('NO')
1,000
PYTHON3
import sys import math import bisect from sys import stdin, stdout from math import gcd, floor, sqrt, log2, ceil from collections import defaultdict from bisect import bisect_left as bl, bisect_right as br from collections import Counter ip = lambda : int(stdin.readline()) inp = lambda: map(int,stdin.readline().split()) ips = lambda: stdin.readline().rstrip() t = ip() for _ in range(t): n = ip() a = list(inp()) b = list(inp()) dic = defaultdict(bool) flag = True for i in range(n): if i == 0: if a[i] == b[i]: dic[a[i]] = True else: flag = False break else: if a[i]<b[i]: if dic[1]: pass else: flag = False break elif a[i] == b[i]: pass else: if dic[-1]: pass else: flag = False break dic[a[i]] = True if flag: print("YES") else: print("NO")
1,100
PYTHON3
t = int(input()) for _ in range(t): n = int(input()) xgt = [] ygt = [] xlt = [] ylt = [] xmax = 10**5+1 xmin = 10**5+1 ymax = 10**5+1 ymin = 10**5+1 flag = True for i in range(n): a = list(map(int,list(input().split()))) if not a[2]: xgt.append(a[0]) if not a[3]: ylt.append(a[1]) if not a[4]: xlt.append(a[0]) if not a[5]: ygt.append(a[1]) if len(xgt): xmin = max(xgt) if len(xlt): xmax = min(xlt) if len(ylt): ymax = min(ylt) if len(ygt): ymin = max(ygt) if xmax >10**5: xmax =10**5 if ymax >10**5: ymax =10**5 if xmin >10**5: xmin =-10**5 if ymin >10**5: ymin =-10**5 if xmax < xmin: print('0') flag = False else: x = xmax if ymax < ymin: if flag: print('0') flag = False else: y = ymax if flag: print(1,x,y)
1,500
PYTHON3
#include <bits/stdc++.h> using namespace std; void fastio() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); } void one(); int main() { fastio(); int t = 1; for (int i = 0; i < t; ++i) { one(); } return 0; } int f(vector<long long> &v, int i) { if (i < 0) { return v.size(); } long long bit = 1LL << i; vector<long long> a, b; for (auto x : v) { if (x & bit) { a.push_back(x); } else { b.push_back(x); } } if (a.empty() || b.empty()) { return f(v, i - 1); } if (a.size() > 1 || b.size() > 1) { return 1 + max(f(a, i - 1), f(b, i - 1)); } else { return f(v, i - 1); } } void one() { int n; cin >> n; vector<long long> a(n); for (int i = 0; i < n; ++i) cin >> a[i]; cout << n - f(a, 31) << "\n"; }
2,100
CPP
n=int(input()) cantidad=0 numeros = list(map(int,input().split())) for i in numeros: if i >=1: cantidad +=1 if cantidad >=1: print("HARD") else: print("EASY")
800
PYTHON3
from sys import stdin,stdout #input=stdin.readline from math import ceil for _ in range(int(input())): n=int(input()) x=ceil(n**0.5) y=ceil(n/x) print(x-1+y-1)
1,100
PYTHON3
#include <bits/stdc++.h> using namespace std; const int N = 55; int n, r1, c1, r2, c2; char g[N][N]; vector<pair<int, int>> aAcc; vector<pair<int, int>> bAcc; bool mark[N][N]; int power(int x, int y) { int s = 1; for (int i = 0; i < y; i++) { s *= x; } return s; } void dfs(int x, int y, int c) { mark[x][y] = true; for (int i = -1; i <= 1; i++) { if (i == 0) { continue; } if (x + i >= 0 && x + i < n && !mark[x + i][y] && g[x + i][y] == '0') { if (c == 1) { aAcc.push_back({x + i, y}); } else { bAcc.push_back({x + i, y}); } dfs(x + i, y, c); } if (y + i >= 0 && y + i < n && !mark[x][y + i] && g[x][y + i] == '0') { if (c == 1) { aAcc.push_back({x, y + i}); } else { bAcc.push_back({x, y + i}); } dfs(x, y + i, c); } } } void solve() { aAcc.push_back({r1, c1}); bAcc.push_back({r2, c2}); dfs(r1, c1, 1); dfs(r2, c2, 2); int mini = INT_MAX; if (aAcc == bAcc) { cout << 0; } else { for (int i = 0; i < aAcc.size(); i++) { for (int j = 0; j < bAcc.size(); j++) { int tmp = power(abs(aAcc[i].first - bAcc[j].first), 2) + power(abs(aAcc[i].second - bAcc[j].second), 2); mini = min(mini, tmp); } } cout << mini; } } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; cin >> r1 >> c1; cin >> r2 >> c2; r1--; r2--; c1--; c2--; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> g[i][j]; } } solve(); }
1,400
CPP
#include <bits/stdc++.h> using namespace std; bool visit[200]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); string s; long long x, d = 1; cin >> s >> x; for (int i = 0; i < x; i++) d *= 10; if (s == "0") { cout << 0 << endl; return 0; } int f = 0; while (1) { string a, b; for (int i = 0; i < s.size(); i++) { if (!visit[i]) a += s[i]; } b = a; long long m; stringstream ss; ss << a; ss >> m; if (m % d == 0) { if (m == 0) { cout << s.size() - 1 << endl; return 0; } long long c = 0; for (int i = 0; i < s.size(); i++) { if (visit[i] == 1) c++; } cout << c << endl; return 0; } for (int i = s.size() - 1; i >= 0; i--) { if (visit[i] == 0 && s[i] != '0') { visit[i] = 1; break; } } } return 0; }
1,100
CPP
def process(): n, x, y = list(map(int, input().split())) days = list(map(int, input().split())) for i in range(n): m = min(i + y + 1, n) m1 = max(0, i - x) if sum(days[j] > days[i] for j in range(m1, m)) == m - m1 -1: print(i+1) return process()
1,000
PYTHON3
def calculate_minimal_refueling(obj_pos, fuel_capacity, gas_station_pos, trip_required): # current_fuel = fuel_capacity - gas_station_pos # if current_fuel < 0 or \ # fuel_capacity - 2 * (obj_pos - gas_station_pos) < 0 or \ # fuel_capacity - 2 * gas_station_pos < 0: # if trip_required == 0: # return 0 # elif trip_required == 1: # if fuel_capacity >= gas_station_pos: # return 0 # elif fuel_capacity - gas_station_pos < 0 or fuel_capacity - (obj_pos - gas_station_pos) < 0: # return -1 # else: # return 1 # return -1 # refueling_count = 0 # print("gas on start:", current_fuel) # for _ in range(trip_required // 2): # # direct direction # print("gf<->o,", current_fuel, '->', current_fuel - 2 * (obj_pos - gas_station_pos)) # current_fuel -= 2 * (obj_pos - gas_station_pos) # if current_fuel < 0: # refueling_count += 1 # current_fuel = fuel_capacity - 2 * (obj_pos - gas_station_pos) # print("refueled,", current_fuel) # # backward direction # print("home<->gf,", current_fuel, '->', current_fuel - 2 * gas_station_pos) # current_fuel -= 2 * gas_station_pos # if current_fuel < 0: # refueling_count += 1 # current_fuel = fuel_capacity - 2 * gas_station_pos # print("refueled,", current_fuel) # if trip_required % 2 != 0 and current_fuel - (obj_pos - gas_station_pos) - obj_pos < 0: # refueling_count += 1 # print("refueled at the end") # return refueling_count direction = True current_gas = fuel_capacity refuel_count = 0 for trip in range(trip_required): if direction: current_gas -= gas_station_pos if current_gas < 0: return -1 elif (trip + 1 != trip_required and current_gas < 2 * (obj_pos - gas_station_pos)) or \ current_gas < obj_pos - gas_station_pos: current_gas = fuel_capacity refuel_count += 1 current_gas -= obj_pos - gas_station_pos if current_gas < 0: return -1 direction = False else: current_gas -= obj_pos - gas_station_pos if current_gas < 0: return -1 elif (trip + 1 != trip_required and current_gas < 2 * gas_station_pos) or \ current_gas < gas_station_pos: current_gas = fuel_capacity refuel_count += 1 current_gas -= gas_station_pos if current_gas < 0: return -1 direction = True return refuel_count def main(): a, b, f, k = map(int, input().split()) print(calculate_minimal_refueling(a, b, f, k)) if __name__ == '__main__': main()
1,500
PYTHON3
a=[] for i in range(5): a=input() if(a.find('1') != -1): j = a.find('1') // 2 o=i print(abs(2-o)+abs(2-j))
800
PYTHON3
#include <bits/stdc++.h> using namespace std; vector<int> adj[int(1e5 * 2)]; bool vis[int(1e5 * 2)] = {0}; long long int e, v; void dfs(int a) { vis[a] = 1; v++; for (int i = 0; i < adj[a].size(); i++) { e++; if (vis[adj[a][i]]) continue; dfs(adj[a][i]); } } int main() { int n, m, a, b; cin >> n >> m; while (m--) { cin >> a >> b; adj[a].push_back(b); adj[b].push_back(a); } for (int i = 0; i < n; i++) { if (vis[i + 1]) continue; e = 0; v = 0; dfs(i + 1); if (v * v - v != e) { cout << "NO"; return 0; } } cout << "YES"; return 0; }
1,500
CPP
#include <bits/stdc++.h> using namespace std; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); long long no_of_vertex, max_edge; long long input; cin >> no_of_vertex >> max_edge; vector<long long> adj[100005]; for (long long i = 1; i <= no_of_vertex; i++) { cin >> input; adj[input].push_back(i); } if (adj[0].size() != 1) { cout << -1; return 0; } vector<pair<long long, long long> > ans; for (long long i = 1; i < 100005; i++) { if (adj[i - 1].size() * (max_edge - (i - 1 != 0)) < adj[i].size()) { cout << -1; return 0; } reverse(adj[i - 1].begin(), adj[i - 1].end()); long long pos = 0; for (long long j = 0; j < adj[i].size(); j++) { if (pos < adj[i - 1].size()) { ans.push_back({adj[i - 1][pos], adj[i][j]}); pos++; } else { j--; pos = 0; } } } cout << ans.size() << "\n"; for (auto k : ans) { cout << k.first << " " << k.second << "\n"; } }
1,800
CPP
str1 = input() str2 = input() continue_checking = True i = 0 while continue_checking: if str1[i].lower() > str2[i].lower(): print("1") continue_checking = False elif str1[i].lower() < str2[i].lower(): print("-1") continue_checking = False elif i == len(str1)-1: print("0") continue_checking = False i += 1
800
PYTHON3
a=int(input()) b=int(input()) c=a+b a=str(a) b=str(b) c=str(c) a=list(a) b=list(b) while(a.count('0')>0): a.remove('0') c=list(c) while(c.count('0')>0): c.remove('0') while(b.count('0')>0): b.remove('0') a="".join(a) a=int(a) b="".join(b) b=int(b) c="".join(c) c=int(c) if(a+b==c): print("YES") else: print("NO")
1,000
PYTHON3
for _ in range(int(input())): n = int(input()) a = list(map(int,input().split())) a.sort() b = [] c = 0 for i in range(n-1): b.append(a[i]-a[i-1]) for j in range(len(b)): if b[j]%2 != 0 : c=1 break if c == 0 : print("YES") else: print("NO")
900
PYTHON3
t=int(input()) a=list(map(int,input().strip().split(" ")))[:t] c=0 for i in range(len(a)): c+=a[i] avg=c/2 c1=0 for j in range(len(a)): c1+=a[j] if c1>=avg: print(j+1) break
1,300
PYTHON3
from sys import stdin,stdout;t=stdin.readline;f=stdout.writelines for _ in range(int(t())): n,a,b = map(int,t().split()) for i in range(n): f("{}".format(chr(97 + i % b))) f("{}\n".format('')) ''' 7 5 3 abcabcab '''
900
PYTHON3
import sys n,a,b = list(map(int, input().split())) if a>1 and b>1: print('NO') sys.exit(0) if n==3 and a==1 and b==1: print('NO') sys.exit(0) if n==2 and a==1 and b==1: print('NO') sys.exit(0) t = [[0 for i in range(n)] for j in range(n)] comp = max(a,b) for i in range(comp-1, n-1): t[i][i+1] = 1 t[i+1][i] = 1 if b>1: for i in range(n): for j in range(n): if i!=j: t[i][j] = 1-t[i][j] print('YES') for i in range(n): print("".join(map(str, t[i])))
1,700
PYTHON3
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007LL; int n, m, comp; vector<pair<int, int> > G[100010]; int vis[100010]; bool flag; void dfs(int i) { for (typeof(G[i].begin()) it = G[i].begin(); it != G[i].end(); ++it) if (vis[it->first] != -1) { if (vis[it->first] != (vis[i] ^ it->second)) flag = false; } else { vis[it->first] = vis[i] ^ it->second; dfs(it->first); } } int main() { while (cin >> n >> m) { for (int i = (0); i < (m); i++) { int a, b, c; cin >> a >> b >> c; a--; b--; G[a].push_back(pair<int, int>(b, !c)); G[b].push_back(pair<int, int>(a, !c)); } memset(vis, -1, sizeof(vis)); flag = true; comp = 0; for (int i = (0); i < (n); i++) if (vis[i] == -1) { vis[i] = 0; dfs(i); comp++; } long long p = 1; for (int _ = (0); _ < (comp - 1); _++) p = (p * 2) % mod; cout << p * flag << endl; } return 0; }
2,200
CPP
for i in range(int(input())): a,b,n,s=map(int,input().split()) if a*n+b>=s and s%n<=b: print('YES') else: print('NO')
1,000
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int t, n; long long int i = 0, j = 0; cin >> n; long long int arr[n]; for (i = 0; i < n; i++) cin >> arr[i]; stack<long long int> s; long long int ans = 0; for (int i = 0; i < n; i++) { while (s.size() && s.top() < arr[i]) { ans = max(ans, arr[i] ^ s.top()); s.pop(); } if (s.size()) { ans = max(ans, arr[i] ^ s.top()); } s.push(arr[i]); } cout << ans; return 0; }
1,800
CPP
#include <bits/stdc++.h> using namespace std; int N, M, R, C; int mxdis, mxnode, sp[2][100005]; vector<int> V[100005]; bool E[100005]; void dfs(int node, int ata, int dis) { if (dis > mxdis && E[node]) { mxdis = dis; mxnode = node; } for (typeof(V[node].begin()) it = V[node].begin(); it != V[node].end(); it++) if (*it != ata) dfs(*it, node, dis + 1); } void dfs4(int node, int ata, int dis, bool w) { sp[w][node] = dis; for (typeof(V[node].begin()) it = V[node].begin(); it != V[node].end(); it++) if (*it != ata) dfs4(*it, node, dis + 1, w); } int main() { int u1, u2, x, y, d; scanf("%d %d %d", &N, &M, &d); for (int i = 1; i <= M; i++) { cin >> x; E[x] = 1; } for (int i = 1; i <= N - 1; i++) { cin >> x >> y; V[x].push_back(y); V[y].push_back(x); } int r = 1; dfs(1, -1, 0); u1 = mxnode; mxdis = 0; dfs(mxnode, -1, 0); u2 = mxnode; dfs4(u1, -1, 0, 0); dfs4(u2, -1, 0, 1); int res = 0; for (int i = 1; i <= N; i++) { if (sp[0][i] <= d && sp[1][i] <= d) ++res; } cout << res << endl; cerr << "\nTime: " << (double)clock() / CLOCKS_PER_SEC << " seconds." << endl; return 0; }
2,000
CPP
# -*- coding: utf-8 -*- import math import collections import bisect import heapq import time import random import itertools import sys from typing import List """ created by shhuan at 2020/1/9 21:29 """ def solve(S, T): N, M = len(S), len(T) left = [-1 for _ in range(N)] si, ti = 0, 0 while si < N: if ti >= M: left[si] = left[si-1] si += 1 continue if S[si] == T[ti]: left[si] = ti ti += 1 else: left[si] = left[si-1] if si > 0 else -1 si += 1 right = [M for _ in range(N)] si, ti = N-1, M-1 while si >= 0: if ti < 0: right[si] = right[si+1] si -= 1 continue if S[si] == T[ti]: right[si] = ti ti -= 1 else: right[si] = right[si+1] if si+1 < N else M si -= 1 ans = 0 for i in range(N): if left[i] >= M-1: ans = max(ans, N-i-1) break j = bisect.bisect_right(right, left[i] + 1) ans = max(ans, j-i-(2 if left[i] >= 0 else 1)) print(ans) S = input() T = input() solve(S, T)
1,600
PYTHON3
n = int(input()) print(int((24 * (4 ** (n - 3))) + ((n - 3) * 36 * (4 ** (n - 4)))))
1,700
PYTHON3
R = lambda:map(int, input().split()) n = int(input()) L = list(R()) f = [0]*(max(L)+1) for i in L: f[i] += 1 ma = max(f) ind = f.index(ma) A = [0]*(n) for i in range(n): if L[i] == ind: A[i] = 1 res = n-ma print(res) j = L.index(ind) #print(j) while j >= 0: if A[j] == 0: A[j] = 1 if L[j] > ind:print(2,j+1,j+2) else:print(1,j+1,j+2) j -= 1 j = L.index(ind) while j < n: if A[j] == 0: A[j] = 1 if L[j] > ind:print(2,j+1,j) else:print(1,j+1,j) j += 1
1,400
PYTHON3
import math n=(int)(input()) for i in range(n): a,b=map(int, input().split(" ")) print((int)(math.ceil(a*b/2)))
800
PYTHON3