solution
stringlengths
10
159k
difficulty
int64
0
3.5k
language
stringclasses
2 values
s = list(input()) n = len(s) tmp = [0, 0, 0, 0] d = {'R': 0, 'B': 0, 'Y': 0, 'G': 0} for i in range(n): if s[i] == '!': tmp[i % 4] += 1 else: d[s[i]] = i % 4 ans = [0, 0, 0, 0] t = ['R', 'B', 'Y', 'G'] for i in range(4): ans[i] = tmp[d[t[i]]] print(*ans)
1,100
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b, p, q, k = 0, c[101] = {0}; cin >> n >> a >> b; for (int i = 1; i < n; i++) { cin >> p >> q; for (int j = p; j < q; j++) c[j] = 1; } for (int i = a; i < b; i++) if (c[i] == 0) k++; cout << k; }
0
CPP
#include <bits/stdc++.h> const long long INF = 1e18L + 1; const int IINF = 1e9 + 1; using namespace std; template <class TH> void _dbg(const char *sdbg, TH h) { cerr << sdbg << '=' << h << endl; } template <class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) { while (*sdbg != ',') cerr << *sdbg++; cerr << '=' << h << ','; _dbg(sdbg + 1, a...); } const long long lim = 1ll << 13; struct seg { vector<long long> tab; seg() : tab(2 * lim, -1ll) {} void ins(long long pos, long long val) { pos += lim; tab[pos] = val; pos >>= 1; while (pos >= 1) { tab[pos] = max(tab[pos << 1], tab[(pos << 1) + 1]); pos >>= 1; } } long long mx(long long st, long long fn) { st += lim; fn += lim; long long res = max(tab[st], tab[fn]); while (fn - st > 1) { if ((st & 1) == 0) { res = max(res, tab[st + 1]); } if ((fn & 1) == 1) { res = max(res, tab[fn - 1]); } st >>= 1; fn >>= 1; } return res; } }; int main() { ios_base::sync_with_stdio(0); cin.tie(0); long long n, k, x; cin >> n >> k >> x; seg prv, cur; vector<long long> a(n); for (long long i = (long long)0; i < (long long)n; i++) { cin >> a[i]; if (i < k) { cur.ins(i, a[i]); } } for (long long j = (long long)2; j < (long long)x + 1; j++) { swap(cur, prv); for (long long i = (long long)j - 1; i < (long long)n; i++) { auto prf = prv.mx(max(i - k, 0ll), i - 1); if (prf != -1) { cur.ins(i, prf + a[i]); } } } cout << cur.mx(max(n - k, 0ll), n - 1) << "\n"; return 0; }
1,900
CPP
#include <bits/stdc++.h> using namespace std; int main() { string s, t, p; cin >> s; cin >> t; for (int i = s.size() - 1; i >= 0; i--) { p += s[i]; } if (t == p) { cout << "YES"; } else { cout << "NO"; } return 0; }
800
CPP
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); long long n, k, c, ans = 1; cin >> n >> k; for (int i = 2; i <= k; i++) { c = 1; for (int j = 0; j < i; j++) { c *= n - j; } for (int j = 2; j <= i; j++) { c /= j; } if (i == 3) { c *= 2; } if (i == 4) { c *= 9; } ans += c; } cout << ans; return 0; }
1,600
CPP
#include <bits/stdc++.h> using namespace std; char primes[10000005] = {}; int useda[10000005] = {}; int usedb[10000005] = {}; int cut[10000005] = {}; vector<int> g; void init() { memset(primes, 1, sizeof(primes)); primes[0] = primes[1] = 0; for (int i = 2; i < 10000005; i++) { if (primes[i] == 0) continue; g.push_back(i); for (int j = i * 2; j < 10000005; j += i) { primes[j] = 0; } } } int main() { init(); int n, m; cin >> n >> m; vector<vector<int> > A(n), B(m); vector<int> ga(n), gb(m); for (int i = 0; i < n; i++) { int a; scanf("%d", &a); ga[i] = a; for (int j = 0; j < g.size(); j++) { if (primes[a]) { useda[a]++; A[i].push_back(a); break; } if (a < g[j] * g[j]) break; while (a % g[j] == 0) { useda[g[j]]++; A[i].push_back(g[j]); a /= g[j]; } } } for (int i = 0; i < m; i++) { int b; scanf("%d", &b); gb[i] = b; for (int j = 0; j < g.size(); j++) { if (primes[b]) { usedb[b]++; B[i].push_back(b); break; } if (b < g[j] * g[j]) break; while (b % g[j] == 0) { usedb[g[j]]++; B[i].push_back(g[j]); b /= g[j]; } } } cout << n << " " << m << endl; for (int i = 0; i < g.size(); i++) cut[g[i]] = min(useda[g[i]], usedb[g[i]]); for (int i = 0; i < n; i++) { if (i) printf(" "); int a = ga[i]; for (int j = 0; j < A[i].size(); j++) { if (cut[A[i][j]]) { cut[A[i][j]]--; a /= A[i][j]; } } printf("%d", a); } cout << endl; for (int i = 0; i < g.size(); i++) cut[g[i]] = min(useda[g[i]], usedb[g[i]]); for (int i = 0; i < m; i++) { if (i) printf(" "); int b = gb[i]; for (int j = 0; j < B[i].size(); j++) { if (cut[B[i][j]]) { cut[B[i][j]]--; b /= B[i][j]; } } printf("%d", b); } cout << endl; return 0; }
1,800
CPP
n=int(input()) divide=[4,7,44,47,74,77,444,447,474,477,744,747,774,777] for i in range(14): if n%divide[i]==0: print("YES") n=0 break if n!=0: print("NO")
1,000
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { long long x, y; cin >> x >> y; if (x == 1 && y > 1) { cout << "<"; return 0; } else if (y == 1 && x > 1) { cout << ">"; return 0; } if (x == 2 && y == 4 || y == 2 && x == 4) { cout << "="; return 0; } if (x == 2 && y == 3 || y == 2 && x == 3) { if (x > y) cout << ">"; else { cout << "<"; } return 0; } if (x > y) { cout << "<"; return 0; } if (x < y) { cout << ">"; return 0; } if (x == y) { cout << "="; return 0; } return 0; }
1,100
CPP
import bisect import decimal from decimal import Decimal import os from collections import Counter import bisect from collections import defaultdict import math import random import heapq from math import sqrt import sys from functools import reduce, cmp_to_key from collections import deque import threading from itertools import combinations from io import BytesIO, IOBase from itertools import accumulate # sys.setrecursionlimit(200000) # mod = 10**9+7 # mod = 998244353 decimal.getcontext().prec = 46 def primeFactors(n): prime = set() while n % 2 == 0: prime.add(2) n = n//2 for i in range(3,int(math.sqrt(n))+1,2): while n % i== 0: prime.add(i) n = n//i if n > 2: prime.add(n) return list(prime) def getFactors(n) : factors = [] i = 1 while i <= math.sqrt(n): if (n % i == 0) : if (n // i == i) : factors.append(i) else : factors.append(i) factors.append(n//i) i = i + 1 return factors def SieveOfEratosthenes(n): prime = [True for i in range(n+1)] p = 2 while (p * p <= n): if (prime[p] == True): for i in range(p * p, n+1, p): prime[i] = False p += 1 num = [] for p in range(2, n+1): if prime[p]: num.append(p) return num def lcm(a,b): return (a*b)//math.gcd(a,b) def sort_dict(key_value): return sorted(key_value.items(), key = lambda kv:(kv[1], kv[0])) def list_input(): return list(map(int,input().split())) def num_input(): return map(int,input().split()) def string_list(): return list(input()) def decimalToBinary(n): return bin(n).replace("0b", "") def binaryToDecimal(n): return int(n,2) def DFS(n,s,adj): visited = [False for i in range(n+1)] stack = [] stack.append(s) while (len(stack)): s = stack[-1] stack.pop() if (not visited[s]): visited[s] = True for node in adj[s]: if (not visited[node]): stack.append(node) def solve(): n,x = num_input() arr = list_input() summ = sum(arr) if summ%x != 0: print(n) else: first = -1 for i in range(n): if arr[i]%x != 0: first = i break if first == -1: print(-1) return first += 1 second = -1 for i in range(-1,-(n+1),-1): if arr[i]%x != 0: second = i break print(max(n-first,n+second)) t = int(input()) #t = 1 for _ in range(t): solve()
1,200
PYTHON3
p = input() s = input() h1, m1 = map(int, p.split(':')) h2, m2 = map(int, s.split(':')) h = (h1 - h2) % 24 m = (m1 - m2) % 60 if m1 < m2: h -= 1 h = h % 24 print('{:02d}:{:02d}'.format(h, m))
900
PYTHON3
n=int(input()) v=2 for i in range(n): s=i+1 g=i+2 p=(s*g*s*g-v)//s print(p) v=s*g
1,600
PYTHON3
#include <bits/stdc++.h> using namespace std; char s[2][100020]; int mi[200040]; bool used[200040]; bool fresh(int &x, int v) { if (x > v) { x = v; return 1; } return 0; } int main() { int i, j, k, n; bool flag = 0; scanf("%d%d", &n, &k); for (i = 0; i < 2; i++) scanf("%s", s[i]); for (i = 0; i < n * 2; i++) mi[i] = 1000000000; queue<int> qq; qq.push(0); mi[0] = 0; while (!qq.empty()) { int x = qq.front(); qq.pop(); used[x] = 0; if ((x >> 1) + k >= n) { flag = 1; break; } if (s[(x & 1) ^ 1][(x >> 1) + k] == '-' && fresh(mi[(x + k * 2) ^ 1], mi[x] + 1)) { if (!used[(x + k * 2) ^ 1]) { used[(x + k * 2) ^ 1] = 1; qq.push((x + k * 2) ^ 1); } } if (s[x & 1][(x >> 1) + 1] == '-' && fresh(mi[x + 2], mi[x] + 1)) { if (!used[x + 2]) { used[x + 2] = 1; qq.push(x + 2); } } if ((x >> 1) > 0 && s[x & 1][(x >> 1) - 1] == '-' && mi[x] + 1 <= (x >> 1) - 1 && fresh(mi[x - 2], mi[x] + 1)) { if (!used[x - 2]) { used[x - 2] = 1; qq.push(x - 2); } } } puts(flag ? "YES" : "NO"); return 0; }
1,400
CPP
n=int(input()) l=list(map(int,input().split())) b=True if n==2: if l[0]==l[1]: b=False if n>2: for i in range(n): count=0 for j in range(n): if l[i]==l[j]: count+=1 if n<(2*count-1): b=False if b: print("YES") else: print("NO")
1,100
PYTHON3
t= int(input()) for _ in range(t): n = int(input()) arr = list(map(int,input().strip().split()))[:n] my_hash = [0]*200 for i in arr: my_hash[i] += 1 #print(my_hash[:10]) a_mex = None b_mex = None for i in range(len(my_hash)): if my_hash[i] == 0: if a_mex is None: a_mex = i if b_mex is None: b_mex = i break elif my_hash[i] == 1: if a_mex is None: a_mex = i print(a_mex+b_mex)
900
PYTHON3
#include <bits/stdc++.h> using namespace std; const int MAXN = 3 * 100000 + 50; int N; std::vector<int> v, links[MAXN]; int main(int argc, char const *argv[]) { ios::sync_with_stdio(false); cin.tie(0); cin >> N; int max_val = -10e9; int biggest = 0, next_big = 0; for (int i = 0; i < N; i++) { int tmp; cin >> tmp; v.push_back(tmp); max_val = max(tmp, max_val); } for (int i = 0; i < N - 1; i++) { int a, b; cin >> a >> b; a--; b--; links[a].push_back(b); links[b].push_back(a); } biggest = count_if(v.begin(), v.end(), [max_val](int tmp) { return tmp == max_val; }); next_big = count_if(v.begin(), v.end(), [max_val](int tmp) { return tmp == max_val - 1; }); int res = max_val + 2; for (int i = 0; i < v.size(); i++) { int x = biggest, y = next_big; if (v[i] == max_val) { x--; } else if (v[i] == max_val - 1) { y--; } for (int j = 0; j < links[i].size(); j++) { int next = links[i][j]; if (v[next] == max_val) { x--; } else if (v[next] == max_val - 1) { y--; } } if (x == 0) { res = min(res, max_val + 1); if (y == 0) { if (v[i] == max_val && biggest == 1) { res = min(res, max_val); } else { res = min(res, max_val + 1); } } } } cout << res << endl; return 0; }
1,900
CPP
#include <bits/stdc++.h> using namespace std; string s; vector<int> razm; int Recurs(int pos) { int i = pos, counts = 0; while (i < s.length()) { if ((s[i] == '<') && (s[i + 1] == '/') && (s[i + 2] == 't') && (s[i + 3] == 'a') && (s[i + 4] == 'b') && (s[i + 5] == 'l') && (s[i + 6] == 'e') && (s[i + 7] == '>')) { razm.push_back(counts); return i + 8; } else if ((s[i] == '<') && (s[i + 1] == 't') && (s[i + 2] == 'a') && (s[i + 3] == 'b') && (s[i + 4] == 'l') && (s[i + 5] == 'e') && (s[i + 6] == '>')) i = Recurs(i + 7); else if ((s[i] == '<') && (s[i + 1] == 't') && (s[i + 2] == 'd') && (s[i + 3] == '>')) { counts++; i += 3; } else i++; } } int main() { string d; while (cin >> d) s += d; Recurs(8); sort(razm.begin(), razm.end()); for (int i = 0; i < razm.size(); i++) cout << razm[i] << ' '; cout << endl; return 0; }
1,700
CPP
import sys for _ in range(int(sys.stdin.readline().rstrip())): a, b = list(map(int, sys.stdin.readline().rstrip().split())) if a == b: print('0') elif a < b: if (b - a) % 2 == 1: print('1') else: print('2') else: if (a - b) % 2 == 1: print('2') else: print('1')
800
PYTHON3
n,m=[int(i) for i in input().split()] a=min(m,n) if a%2: print('Akshat') else: print('Malvika')
900
PYTHON3
from collections import Counter s = input() k = int(input()) d = Counter() for i in s: d[i] += 1 if len(s) < k: print('impossible') else: print(max(0, k - len(d)))
1,000
PYTHON3
#include <bits/stdc++.h> const int val = (2e5) + 5; const int INF = (1e9); using namespace std; long long a[val]; map<long long, vector<pair<int, int> > > g; int solve() { int k; cin >> k; for (int x = 1; x <= k; ++x) { int n; cin >> n; long long sum = 0; for (int i = 1; i <= n; ++i) { cin >> a[i]; sum += a[i]; } for (int i = 1; i <= n; ++i) { sum -= a[i]; int l = g[sum].size(); if (l > 0) { cout << "YES" << endl; cout << x << " " << i << endl; cout << g[sum][0].first << " " << g[sum][0].second << endl; return 0; } sum += a[i]; } for (int i = 1; i <= n; ++i) { sum -= a[i]; g[sum].push_back({x, i}); sum += a[i]; } } cout << "NO" << endl; } int main() { ios_base::sync_with_stdio(0); solve(); return 0; }
1,400
CPP
def check(pos,a,b): while a<=b: if b not in pos: return False b-=1 return True if __name__ == "__main__": kk = int(input()) for _ in range(kk): n,m = map(int,input().split()) arr = [int(x) for x in input().split()] pos = set([int(x)-1 for x in input().split()]) target = sorted(arr) d = dict() for i,v in enumerate(arr): if v not in d: d[v] = [i] else: d[v].append(i) for v in d.values(): v.sort(reverse=True) #print(d) yes = True for i,t in enumerate(target): p = d[t].pop() #print(t,p,i,p-1) if not check(pos,i,p-1): yes = False break print("YES" if yes else "NO")
1,200
PYTHON3
#include <bits/stdc++.h> using namespace std; const int p = 1000000007; string s; int n, m; int lt(int x, int y) { if (y == 0) return 1; int c = lt(x, y / 2); c = ((long long)c * c) % p; if (y % 2 == 1) c = (long long)c * x % p; return c; } int cal(int y) { if (y == 0) return 1; if (y % 2 == 0) return ((cal(y - 1) + lt(lt(2, y), m))); int c = cal(y / 2); c = (long long)c * (1 + lt(lt(2, y / 2 + 1), m)) % p; return c; } int main() { getline(cin, s); m = (int)s.size(); cin >> n; int res = 0; for (int i = 0; i <= m - 1; i++) if (s[i] == '5' || s[i] == '0') res = (res + lt(2, i)) % p; int k = cal(n - 1); res = ((long long)res * k) % p; cout << res; return 0; }
1,700
CPP
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; int root[maxn]; int tin[maxn]; int tout[maxn]; bool vis[maxn]; vector<int> kids[maxn]; pair<int, int> docs[maxn]; pair<int, int> queries[maxn]; int timer = 0; int get_root(int x) { if (x == root[x]) return x; return root[x] = get_root(root[x]); } void dfs(int v) { if (vis[v]) return; vis[v] = true; tin[v] = timer++; for (int u : kids[v]) dfs(u); tout[v] = timer++; } int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; for (int i = 0; i < n; i++) root[i] = i; int dcnt = 0; int qcnt = 0; while (m--) { int t; cin >> t; if (t == 1) { int x, y; cin >> x >> y; x--; y--; kids[y].push_back(x); root[x] = get_root(y); } else if (t == 2) { int x; cin >> x; x--; docs[dcnt++] = {x, get_root(x)}; } else { int x, i; cin >> x >> i; x--; i--; queries[qcnt++] = {x, i}; } } for (int i = 0; i < n; i++) dfs(get_root(i)); for (int q = 0; q < qcnt; q++) { int x = queries[q].first; int i = queries[q].second; int c = docs[i].first; int p = docs[i].second; if (tin[p] <= tin[x] and tin[x] <= tout[p] and tin[x] <= tin[c] and tin[c] <= tout[x]) cout << "YES" << endl; else cout << "NO" << endl; } return 0; }
2,100
CPP
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; vector<int> a(n); for (long long i = 0; i < (long long)n; i++) cin >> a[i]; int lst = 0; vector<int> h(n); h[0] = 0; for (int i = 1; i < n; i++) { if (i - 1 > 0 && a[i - 1] > a[i]) lst++; h[i] = h[lst] + 1; } cout << h[n - 1] << endl; } return 0; }
1,600
CPP
n, k = (int(x) for x in input().split()) odd = (n + 1) // 2 print(k * 2 - 1 if k <= odd else (k - odd) * 2)
900
PYTHON3
n = int(input()) years = list(map(int, input().split())) years.sort() print(years[n//2])
800
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); int x = a[n - 1] - a[0]; if (n > 2) cout << min(a[n - 2] - a[0], a[n - 1] - a[1]); else cout << 0; }
900
CPP
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); string s[100]; int a[26]; vector<int> v[26]; bool prefix(string a, string b) { if (a.size() > b.size()) return false; for (int i = 0; i < a.size(); i++) { if (a[i] != b[i]) return false; } return true; } int main() { int n; scanf("%d", &n); for (int(i) = 0; i < int(n); ++i) cin >> s[i]; vector<int> res; queue<int> q; for (int i = 0; i < n - 1; i++) { if (prefix(s[i + 1], s[i])) { puts("Impossible"); return 0; } else if (prefix(s[i], s[i + 1])) continue; int c = 0; while (s[i][c] == s[i + 1][c]) c++; a[s[i + 1][c] - 'a']++; v[s[i][c] - 'a'].push_back(s[i + 1][c] - 'a'); } for (int i = 0; i < 26; i++) if (!a[i]) { res.push_back(i); q.push(i); } while (!q.empty()) { int u = q.front(); q.pop(); for (int i = 0; i < v[u].size(); i++) { a[v[u][i]]--; if (!a[v[u][i]]) { res.push_back(v[u][i]); q.push(v[u][i]); } } } for (int i = 0; i < 26; i++) { if (a[i]) { puts("Impossible"); return 0; } } for (int i = 0; i < res.size(); i++) printf("%c", (res[i] + 'a')); return 0; }
1,600
CPP
#include <bits/stdc++.h> using namespace std; int main() { int i, n; char a[101]; scanf("%s", &a); n = strlen(a); for (i = 0; i < n; i++) if (a[i] < 97) a[i] = a[i] + 32; for (i = 0; i < n; i++) if (a[i] == 'e' || a[i] == 'a' || a[i] == 'y' || a[i] == 'u' || a[i] == 'o' || a[i] == 'i') ; else printf(".%c", a[i]); printf("\n"); }
1,000
CPP
A=input().split() B=input() Answ=[] for i in range(int(B)): Koor=input().split() if (int(Koor[1])<=int(Koor[0])+int(A[1])) and (int(Koor[1])>=int(Koor[0])-int(A[1])) and (int(Koor[1])>=-1*int(Koor[0])+int(A[1])) and (int(Koor[1])<=-1*int(Koor[0])+2*int(A[0])-int(A[1])): Answ.append('YES') else: Answ.append('NO') for i in range(int(B)): print(Answ[i])
1,100
PYTHON3
input() s = input().split() print(max([s.count(i) for i in set(s)]))
800
PYTHON3
#include <bits/stdc++.h> using namespace std; vector<int> minis; vector<int> maxis; vector<pair<int, bool> > ns; const int INF = 0x3f3f3f3f; int main() { int n; cin >> n; int r = 0; for (int i = 0; i < n; i++) { int m; scanf("%d", &m); int maxi = -INF; int mini = INF; bool flag = false; int a; for (int j = 0; j < m; j++) { scanf("%d", &a); maxi = max(maxi, a); mini = min(mini, a); if (a > mini) { flag = true; } } if (flag == true) { r++; } else { minis.push_back(mini); maxis.push_back(maxi); } ns.push_back({mini, flag}); } sort(minis.begin(), minis.end()); sort(maxis.begin(), maxis.end()); long long tot = 0; for (int i = 0; i < n; i++) { int mini = ns[i].first; bool flag = ns[i].second; if (flag) { tot += n; continue; } tot += r; auto iter = upper_bound(maxis.begin(), maxis.end(), mini); int d = distance(iter, maxis.end()); tot += d; } cout << tot << endl; return 0; }
1,400
CPP
import sys, random n = int(sys.stdin.readline()) lns = sorted([int(x) for x in sys.stdin.readline().split()]) for a in range(n-2): b = a + 1 c = b + 1 if lns[a]+lns[b] > lns[c] and lns[a]+lns[c] > lns[b] and lns[b]+lns[c] > lns[a]: print('YES') exit() print('NO')
1,000
PYTHON3
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 7; const int MAXN = 1e6 + 7; const double EPS = 1e-8; vector<vector<deque<char> > > a; vector<vector<string> > b; int n, m; int all = 0; struct Res { int x1, y1, x2, y2; }; vector<Res> res; void move(int x1, int y1, int x2, int y2) { all++; res.push_back({x1, y1, x2, y2}); assert(a[x1][y1].size()); assert(x1 * m + y1 != x2 * m + y2); a[x2][y2].push_front(a[x1][y1].back()); a[x1][y1].pop_back(); } void print() { for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (!a[i][j].size()) { cout << "#"; } for (int pos = 0; pos < (int)a[i][j].size(); pos++) { cout << a[i][j][pos]; } cout << " "; } cout << "\n"; } } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> m; a.resize(n, vector<deque<char> >(m)); b.resize(n, vector<string>(m)); vector<int> ar(n, 0), br(n, 0), ac(m, 0), bc(m, 0); int sum1 = 0; vector<vector<int> > need0(n, vector<int>(m, 0)), need1(n, vector<int>(m, 0)); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { string s; cin >> s; assert(s.size()); for (char c : s) { a[i][j].push_back(c); ar[i]++; ac[j]++; } } } vector<int> needrow(n, 0), needcol(m, 0); int sum0 = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> b[i][j]; assert(b[i][j].size()); for (char c : b[i][j]) { if (c == '1') { need1[i][j]++; } else { need0[i][j]++; } br[i]++, bc[j]++; } needrow[i] += need1[i][j]; needcol[j] += need0[i][j]; sum0 += need0[i][j]; sum1 += need1[i][j]; assert(need1[i][j] >= 0); } } int r = -1, c = -1; for (int i = 0; i < n; i++) { if (ar[i] >= br[i]) { r = i; break; } } for (int i = 0; i < m; i++) { if (ac[i] >= bc[i]) { c = i; break; } } assert(r != -1 && c != -1); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (i == r) continue; while (a[i][j].size()) { move(i, j, r, j); } } } for (int j = 0; j < m; j++) { if (j == c) continue; while (a[r][j].size()) { move(r, j, r, c); } } for (int i = 0; i < n; i++) { if (i == r) continue; while (a[i][c].size()) { move(i, c, r, c); } } for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (i != r || j != c) { assert(!a[i][j].size()); } } } for (char t : a[r][c]) { if (t == '1') { sum1--; } else { sum0--; } } assert(!sum0 && !sum1); int li = 0, lj = 0; if (li == r) li++; if (lj == c) lj++; bool fixi = false, fixj = false; while (!fixi && a[li][c].size() == needrow[li] - need1[li][c]) { li++; if (li == r) li++; if (li == n) { li--; if (li == r) li--; fixi = true; } } while (!fixj && a[r][lj].size() == needcol[lj] - need0[r][lj]) { lj++; if (lj == c) lj++; if (lj == m) { lj--; if (lj == c) lj--; fixj = true; } } while (a[r][c].size()) { if (a[r][c].back() == '1') { move(r, c, li, c); assert(need1[li][c] >= 0); while (!fixi && a[li][c].size() == needrow[li] - need1[li][c]) { li++; if (li == r) li++; if (li == n) { li--; if (li == r) li--; fixi = true; } } } else if (a[r][c].back() == '0') { move(r, c, r, lj); while (!fixj && a[r][lj].size() == needcol[lj] - need0[r][lj]) { lj++; if (lj == c) lj++; if (lj == m) { lj--; if (lj == c) lj--; fixj = true; } } } } assert(!a[r][c].size()); for (int i = 0; i < n; i++) { if (i != li && i != r) { if (a[i][c].size() != needrow[i] - need1[i][c]) { for (int k = i + 1; k < n; k++) { assert(a[k][c].size() < needrow[k] - need1[k][c]); } cout << i << " " << a[li][c].size() << " " << needrow[li] - need1[li][c] << " " << need1[i][c] << " " << fixi << " " << fixj << " " << li << " " << r << "\n"; exit(0); } } } for (int i = 0; i < m; i++) { if (i != lj && i != c) { assert(a[r][i].size() == needcol[i] - need0[r][i]); } } for (int j = 0; j < m; j++) { if (j == c) continue; string need = b[r][j]; reverse(need.begin(), need.end()); for (int pos = 0; pos < (int)need.size(); pos++) { if (need[pos] == '0') { move(r, lj, r, c); } else { move(li, c, r, c); } } for (int pos = 0; pos < (int)need.size(); pos++) { move(r, c, r, j); } assert(!a[r][c].size()); } for (int i = 0; i < n; i++) { if (i == r) continue; string need = b[i][c]; reverse(need.begin(), need.end()); for (int pos = 0; pos < (int)need.size(); pos++) { if (need[pos] == '0') { move(r, lj, r, c); } else { move(li, c, r, c); } } for (int pos = 0; pos < (int)need.size(); pos++) { move(r, c, i, c); } assert(!a[r][c].size()); } string need = b[r][c]; reverse(need.begin(), need.end()); for (int pos = 0; pos < (int)need.size(); pos++) { if (need[pos] == '0') { move(r, lj, r, c); } else { move(li, c, r, c); } } assert(a[li][c].size() == needrow[li] - need1[li][c] + b[li][c].size()); assert(a[r][lj].size() == needcol[lj] - need0[r][lj] + b[r][lj].size()); for (int i = 0; i < n; i++) { if (i == r) continue; for (int j = 0; j < m; j++) { if (j == c) continue; assert(!a[i][j].size()); string need = b[i][j]; reverse(need.begin(), need.end()); for (char e : need) { if (e == '0') { move(r, j, i, j); } else { move(i, c, i, j); } } } } cout << res.size() << "\n"; for (auto r : res) { cout << r.x1 + 1 << " " << r.y1 + 1 << " " << r.x2 + 1 << " " << r.y2 + 1 << "\n"; } }
2,400
CPP
#include <bits/stdc++.h> using namespace std; char s[1 << 20], t[1 << 20]; int n, nq, m, d; int f[1 << 20]; int g[20][1 << 20], w[20][1 << 20]; pair<int, int> doit(int x, int e) { int ww = 0; for (int k = 0, ThxDem = 20; k < ThxDem; ++k) if (e & (1 << k)) { int y = g[k][x]; if (y < 0) { ww += w[k][x]; x = y; break; } x = y; ww += 1 << k; } return make_pair(x, ww); } int main() { scanf("%s%d", s, &nq); n = strlen(s); while (nq--) { scanf("%d%d", &m, &d); int c = 0; for (int i = 0, ThxDem = d; i < ThxDem; ++i) for (int j = i; j < m; j += d) f[j] = c++; assert(c == m); for (int i = 0, ThxDem = m; i < ThxDem; ++i) g[0][i] = f[i] - 1, w[0][i] = g[0][i] < 0; for (int k = 1, ThxDem = 20; k < ThxDem; ++k) for (int i = 0, ThxDem = m; i < ThxDem; ++i) { if (g[k - 1][i] < 0) { g[k][i] = -1; w[k][i] = w[k - 1][i]; } else { g[k][i] = g[k - 1][g[k - 1][i]]; if (g[k][i] < 0) w[k][i] = (1 << (k - 1)) + w[k - 1][g[k - 1][i]]; } } for (int i = 0, ThxDem = n; i < ThxDem; ++i) { int r; if (i < m) { auto p = doit(i, n - m + 1); if (p.first >= 0) r = n - m + p.first + 1; else r = p.second - 1; } else { auto p = doit(m - 1, n - i); if (p.first >= 0) r = n - m + p.first + 1; else r = i - m + p.second; } t[r] = s[i]; } memcpy(s, t, n * sizeof(char)); puts(s); } return 0; }
2,600
CPP
def odd_sum(lst): k, m = 0, 10 ** 9 for elem in lst: if elem >= 0: k += elem if k % 2: return k for elem in lst: if elem % 2: m = min(m, abs(elem)) return k - m n = int(input()) a = [int(i) for i in input().split()] print(odd_sum(a))
1,400
PYTHON3
#include <bits/stdc++.h> using namespace std; vector<int> G[100001]; int n, m, match[100001], dist[100001]; bool bfs() { int i, u, v, len; queue<int> Q; for (i = 1; i <= n; i++) { if (match[i] == 0) { dist[i] = 0; Q.push(i); } else dist[i] = (1 << 28); } dist[0] = (1 << 28); while (!Q.empty()) { u = Q.front(); Q.pop(); if (u != 0) { len = G[u].size(); for (i = 0; i < len; i++) { v = G[u][i]; if (dist[match[v]] == (1 << 28)) { dist[match[v]] = dist[u] + 1; Q.push(match[v]); } } } } return (dist[0] != (1 << 28)); } bool dfs(int u) { int i, v, len; if (u != 0) { len = G[u].size(); for (i = 0; i < len; i++) { v = G[u][i]; if (dist[match[v]] == dist[u] + 1) { if (dfs(match[v])) { match[v] = u; match[u] = v; return true; } } } dist[u] = (1 << 28); return false; } return true; } int hopcroft_karp() { int matching = 0, i; while (bfs()) for (i = 1; i <= n; i++) if (match[i] == 0 && dfs(i)) matching++; return matching; } vector<int> prime(int n) { vector<int> ret; for (int i = 2; i * i <= n; i++) while (n % i == 0) ret.push_back(i), n /= i; if (n > 1) ret.push_back(n); return ret; } int a[100005]; pair<int, int> good[100005]; vector<pair<int, int>> grp[100005]; int main() { int v, q; cin >> v >> q; for (int i = 1; i <= v; i++) { cin >> a[i]; } n = 0, m = 0; for (int i = 1; i <= v; i++) { if (i % 2 == 1) { vector<int> tmp = prime(a[i]); for (int j = 0; j < tmp.size(); j++) { grp[i].push_back({tmp[j], ++n}); } } } for (int i = 1; i <= v; i++) { if (i % 2 == 0) { vector<int> tmp = prime(a[i]); for (int j = 0; j < tmp.size(); j++) { grp[i].push_back({tmp[j], ++m + n}); } } } int x, y; while (q--) { cin >> x >> y; for (auto i : grp[x]) { for (auto j : grp[y]) { if (i.first == j.first) { G[i.second].push_back(j.second); G[j.second].push_back(i.second); } } } } printf("%d\n", hopcroft_karp()); return 0; }
2,100
CPP
for _ in range(int(input())): n = int(input()) ls = [] for i in range(n): ls.append(list(map(int, input().split()))[1:]) pr = [True] * n mr = [False] * n c = 0 for i in range(n): k = ls[i] for j in k: if pr[j - 1]: pr[j - 1] = False mr[i] = True c += 1 break if c == n: print("OPTIMAL") else: a = 0 b = 0 for i in range(n): if not mr[i]: a = i + 1 break for i in range(n): if pr[i]: b = i + 1 break print("IMPROVE") print(a, b)
1,200
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b; cin >> n >> a >> b; if (n <= a && n <= b) cout << "Yes" << endl; else cout << "No" << endl; return 0; }
800
CPP
import sys input = sys.stdin.readline h = int(input()) a = list(map(int, input().split())) n = sum(a) par = [-1]*n cnt = 1 s, t = -1, -1 for i in range(1, h+1): for v in range(cnt, cnt+a[i]): par[v] = cnt-1 if a[i-1]>=2 and a[i]>=2: s = cnt t = cnt-a[i-1] cnt += a[i] if s==-1 and t==-1: print('perfect') else: print('ambiguous') print(*list(map(lambda x: x+1, par))) par[s] = t print(*list(map(lambda x: x+1, par)))
1,500
PYTHON3
n = int(input()) for i in range(n): k = int(input()) x = input() a = '' b = '' one = False for c in x: if one: a+='0' b+=c continue if c == '2': a+='1' b+='1' elif c=='0': a+='0' b+='0' else: one = True a+='1' b+='0' print(a) print(b)
1,200
PYTHON3
n = int(input()) print(n) for i in range(n): if i==n-1: print(1) else: print('1 ',end='')
800
PYTHON3
n = int(input()) bill = [1, 5, 10, 20, 100] res = 0 while n: while bill[-1] <= n: res += 1 n -= bill[-1] bill.pop() print(res)
800
PYTHON3
s=str(input()) x=0 y=0 for i in range(len(s)): if(s[i].isupper()): x=x+1 else: y=y+1 if(x>y): print(s.upper()) else: print(s.lower())
800
PYTHON3
n=int(input()) heights=list(map(int, input().split())) first_index=0 last_index=n-1 max_number=max(heights) max_index=heights.index(max_number) heights.pop(max_index) heights.insert(0, max_number) min_number=min(heights) for i in range(len(heights)-1, 0, -1): if heights[i]==min_number: min_index=i break result=max_index-first_index + last_index-min_index print(result)
800
PYTHON3
import sys inf = 1 << 30 def solve(): n = int(input()) a = [inf if ai != '0' else 0 for ai in input().split()] for i in range(n): if a[i] == 0: for j in range(i - 1, -1, -1): if a[j] > i - j: a[j] = i - j else: break for j in range(i + 1, n): if a[j] > j - i: a[j] = j - i else: break print(*a) if __name__ == '__main__': solve()
1,200
PYTHON3
x1,y1=map(int,input().split()) x2,y2=map(int,input().split()) x3,y3=map(int,input().split()) print(3) d1=[] d1.append((x3-(x1-x2),y3-(y1-y2))) d1.append((x3-(x2-x1),y3+(y1-y2))) d1.append((x2-(x1-x3),y2-(y1-y3))) d1.append((x2+(x1-x3),y2+(y1-y3))) d1.append((x1-(x2-x3),y1-(y2-y3))) d1.append((x1+(x2-x3),y1+(y2-y3))) d1=set(d1) for i in d1: print(i[0],i[1])
1,200
PYTHON3
izi = int(input()[1:]) print(izi % 2)
0
PYTHON3
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> inline void amin(T &x, U y) { if (y < x) x = y; } template <typename T, typename U> inline void amax(T &x, U y) { if (x < y) x = y; } signed main() { long long n; cin >> n; vector<long long> c; for (long long i = 0; i < n; i++) { long long rt; cin >> rt; c.push_back(rt); } map<long long, long long> nombres; n++; for (long long i = 0; i < 1e5; i++) { nombres[n] = 0; } for (long long i = 0; i < n; i++) { nombres[c[i]]++; } vector<long long> dp(2, 0); nombres[0] = 0; dp[0] = nombres[0]; dp[1] = nombres[1]; for (long long i = 2; i < 1e5 + 10; i++) { dp.push_back(max(dp[i - 2] + (long long)nombres[i] * i, dp[i - 1])); } cout << dp.back(); return 0; }
1,500
CPP
#include <bits/stdc++.h> int main() { long long int tes, i, b = 0, c = 0, d = 0; int a; scanf("%I64d", &tes); for (i = 0; i < tes; i++) { scanf("%d", &a); if (a == 1) b++; else if (a == 2) c++; else d++; } if (b >= c && b >= d) printf("%I64d\n", c + d); else if (c >= b && c >= d) printf("%I64d\n", b + d); else if (d >= b && d >= c) printf("%I64d\n", b + c); return 0; }
900
CPP
#include <bits/stdc++.h> using namespace std; struct triple { long long a; long long b; long long c; }; vector<triple> lemmings; bool compa(triple a, triple b) { if (a.a != b.a) return a.a < b.a; if (a.b != b.b) return a.b < b.b; return a.c < b.c; } int main() { long long n, k, h; cin >> n >> k >> h; lemmings.resize(n); for (int i = 0; i < (n); ++i) { cin >> lemmings[i].a; lemmings[i].c = i; } for (int i = 0; i < (n); ++i) cin >> lemmings[i].b; sort(lemmings.begin(), lemmings.end(), compa); double top = 20000000000.0, bot = 0.0, mid = (top + bot) / 2; for (int i = 0; i < (100); ++i) { double t = 1; for (int i = 0; i < (n); ++i) { double gas = lemmings[i].b; gas *= mid; if (t < gas) t += 1.0; } if (t + 0.5 > k + 1) top = mid; else bot = mid; mid = (top + bot) / 2; } int asd[k]; double t = 1; int wer = 0; for (int i = 0; i < (n); ++i) { double gas = lemmings[i].b; gas *= mid; if (t < gas + 0.0000000001 && wer < k) { t += 1.0; asd[wer] = lemmings[i].c; wer++; } } for (int i = 0; i < (k - 1); ++i) cout << asd[i] + 1 << " "; cout << asd[k - 1] + 1 << endl; }
2,000
CPP
#include <bits/stdc++.h> using namespace std; int main() { int T; scanf("%d", &T); for (int t = 0; t < T; ++t) { int N, M; scanf("%d %d", &N, &M); vector<bool> matched(3 * N + 1); vector<int> matching; for (int i = 1; i <= M; ++i) { int u, v; scanf("%d %d", &u, &v); if (!matched[u] && !matched[v]) { matching.push_back(i); matched[u] = true; matched[v] = true; } } if (matching.size() >= N) { printf("Matching\n"); for (int i = 0; i < N; ++i) { printf("%d", matching[i]); if (i == N - 1) printf("\n"); else printf(" "); } } else { printf("IndSet\n"); int n = 0; for (int i = 1; i <= 3 * N; ++i) { if (!matched[i]) { printf("%d", i); n++; if (n == N) { printf("\n"); break; } else { printf(" "); } } } } } return 0; }
2,000
CPP
from collections import* input() d=Counter(map(int,input().split())) m=max(d) for i in range(1,m+1): if m%i==0:d[i]-=1 print(m,max(d.elements()))
1,100
PYTHON3
t=int(input()) for _ in range(t): n,m = map(int,input().split()) Y=False for v in range(n): a,b = map(int,input().split()) c,d = map(int,input().split()) if b==c: Y=True if Y and not(m%2): print("YES") else: print("NO")
900
PYTHON3
x = int(input()) arr = [int(x) for x in input().split()] min = 101 min_index = -1 max = 0 max_index = -1 step = 0 for i in range(x): if(arr[i] <= min): min = arr[i] min_index = i if(arr[i] > max): max = arr[i] max_index = i step = max_index + (x - 1 - min_index) if(min_index < max_index): step -= 1 print(step)
800
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int arr[3]; cin >> arr[0] >> arr[1] >> arr[2]; sort(arr, arr + 3); cout << (arr[1] - arr[0]) + (arr[2] - arr[1]); return 0; }
800
CPP
#include <bits/stdc++.h> using namespace std; int n, m; double dp[1001][1001], a[5][5]; double mdfs(int x, int y) { if (x < 0 || y < 0) return 0; if (y == 0) return dp[x][y] = 1; if (x == 0) return dp[x][y] = 1.0 / (y + 1); if (dp[x][y] >= 0) return dp[x][y]; double na = (1 - mdfs(y - 1, x)), nb = mdfs(y, x - 1); double px = nb * 1.0 / (nb + 1.0 / (y + 1)); if ((y * na + 1) * 1.0 / (y + 1) < 1 - nb) px = 0; double py = (nb * (y + 1) + y * (na - 1)) * 1.0 / (nb * (y + 1) + 1); if (nb * (y + 1) + y * (na - 1) < 0) py = 0; dp[x][y] = px * py * (y * na * 1.0 / (y + 1)) + px * (1 - py) * ((y * na + 1) * 1.0 / (y + 1)) + (1 - px) * (1 - py) * (1 - nb) + (1 - px) * py; return dp[x][y]; } signed main() { cin >> n >> m; for (int i = 0; i <= max(n, m); i++) for (int j = 0; j <= max(n, m); j++) dp[i][j] = -1; dp[0][0] = 1; mdfs(n, m); printf("%.9f %.9f\n", dp[n][m], 1 - dp[n][m]); return 0; }
2,700
CPP
n=int(input()) for i in range(n): if(i+1==n): if(i%2==0): print("I hate it",end=" ") else: print("I love it",end=" ") else: if(i%2==0): print("I hate that",end=" ") else: print("I love that",end=" ")
800
PYTHON3
# %% from sys import stdin f = stdin # f = open("be.txt") # text = f.read().splitlines() t = int(f.readline()) # %% # %% def solve(n, p, a): # fathers = [i for i in range(n)] def getparent(a): if fathers[a] == a: return a father = getparent(fathers[a]) fathers[a] = father return father def sameset(a, b): return getparent(a) == getparent(b) def uniset(a, b): fathers[a] = b # paths = [(i, i+1, p) for i in range(n-1)] paths = [] for i in range(n): # vegigmegyunk az elemeken # kiterjesztjuk a szomszedsagokat az oszthatosagig if a[i] < p: # maskepp nincs ertelme # visszafele for bi in range(i-1, 0, -1): if a[bi] % a[i] !=0: break if a[bi] < a[i]: break else: paths.append((bi, i, a[i])) # elorefele for bi in range(i+1, n, +1): if a[bi] % a[i] !=0: break if a[bi] < a[i]: break else: paths.append((bi, i, a[i])) # sorted_paths = list(sorted(paths, key=lambda x: x[2])) # del paths paths.sort() sorted_paths = paths u = 0 we = 0 found = 0 for i in range(n-1): # n-1 kapcsolat if u >= len(sorted_paths): break while True: if u >= len(sorted_paths): break current_path = sorted_paths[u] if not sameset(current_path[0], current_path[1]): uniset(current_path[0], current_path[1]) we += current_path[2] found+=1 u += 1 break u += 1 # print('i', i) # print(we) we += p * (n-found-1) return we #%% def readlinesasint(n:int, file): buffer = [] nums = [] for i in range(n): char = file.read(1) while char not in '\r\n\t ': buffer.append(char) char = file.read(1) nums.append(int("".join(buffer))) buffer = [] return nums # %% def new_solve(n, p, a): sorted_a = sorted(enumerate(a), key=lambda x: x[1]) is_connected_to_neighbour = [False for i in range(n-1)] ret_val = 0 for index, value in sorted_a: if value >= p: break i = index - 1 while i >= 0: if a[i]%a[index] == 0: if is_connected_to_neighbour[i]: i-=1 break continue else: is_connected_to_neighbour[i] = True ret_val += a[index] else: break i -= 1 i = index + 1 while i < n: if a[i]%a[index] == 0: if is_connected_to_neighbour[i-1]: i += 1 break continue else: is_connected_to_neighbour[i-1] = True ret_val += a[index] else: break i += 1 for i in range(len(is_connected_to_neighbour)): if not is_connected_to_neighbour[i]: ret_val += p return ret_val # %% for i in range(t): # break # print(text[i:i+2]) n, p = (map(int, f.readline().split())) a = readlinesasint(n, f) # print("AAAAAAAA") print(new_solve(n, p, a)) # %%
2,000
PYTHON3
import sys input = sys.stdin.buffer.readline n = int(input()) ls = list(map(int, input().split())) m = max(ls) def get_max(ls): ma = [[0]*n for _ in range(m+1)] for i in range(1, m+1): mx = 0 for j, u in enumerate(ls): mx += u if mx <= 0 or u > i: mx = 0 ma[i][j] = mx return ma ml, mr = get_max(ls), get_max(list(reversed(ls))) mr = [list(reversed(u)) for u in mr] mx = 0 for i, u in enumerate(ls): if u <= 0: continue lv = ml[u][i-1] if i > 0 else 0 rv = mr[u][i+1] if i < n-1 else 0 mx = max(mx, lv+rv) print(mx)
2,000
PYTHON3
from sys import stdin,stdout from math import gcd,sqrt,factorial from collections import deque,defaultdict input=stdin.readline R=lambda:map(int,input().split()) I=lambda:int(input()) S=lambda:input().rstrip('\n') L=lambda:list(R()) P=lambda x:stdout.write(x) lcm=lambda x,y:(x*y)//gcd(x,y) hg=lambda x,y:((y+x-1)//x)*x pw=lambda x:0 if x==1 else 1+pw(x//2) chk=lambda x:chk(x//2) if not x%2 else True if x==1 else False sm=lambda x:(x**2+x)//2 N=10**9+7 for _ in range(I()): e=[] o=[] ln=0 for i in map(int,S()): if i&1:o+=i, else:e+=i, ln+=1 ans=[] e.reverse() o.reverse() for i in range(ln): if not e:ans=ans+o[::-1];break elif not o:ans=ans+e[::-1];break if e[-1]<o[-1]:ans+=e.pop(), else:ans+=o.pop(), print(*ans,sep='')
1,600
PYTHON3
#include <bits/stdc++.h> int main() { int n, w; std::cin >> n >> w; long long int *volumes = new long long int[2 * n]; for (int i = 0; i < 2 * n; ++i) { std::cin >> volumes[i]; } std::sort(volumes, volumes + 2 * n); double val1 = 3 * n * volumes[0], val2 = 1.5 * n * volumes[n]; std::cout << std::setprecision(10) << std::min(std::min(val1, val2), (double)w) << '\n'; }
1,500
CPP
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); vector<bool> is_prime(2800000, 0); vector<long long> vect, vect2, vect3; is_prime[0] = 1, is_prime[1] = 1; vect.push_back(0); for (int i = 2; i * i <= 2800000; i++) { if (is_prime[i] == 0) { for (int j = i * i; j <= 2800000; j += i) { is_prime[j] = 1; } } } map<long long, long long> map1, map2; for (int i = 2; i < 2800000; i++) { if (is_prime[i] == 0) { map1[i] = vect.size(); vect.push_back(i); } } long long n; cin >> n; for (int i = 0; i < 2 * n; i++) { long long a; cin >> a; vect2.push_back(a); map2[a]++; } sort(vect2.begin(), vect2.end()); for (int i = 2 * n - 1; i >= 0; i--) { if (map2[vect2[i]] > 0) { if (is_prime[vect2[i]] == 0) { vect3.push_back(map1[vect2[i]]); map2[vect2[i]]--; map2[map1[vect2[i]]]--; } else { long long j = 2; for (j = 2; j * j <= vect2[i]; j++) { if (vect2[i] % j == 0) break; } map2[vect2[i] / j]--; map2[vect2[i]]--; vect3.push_back(vect2[i]); } } } for (int i = 0; i < n; i++) cout << vect3[i] << " "; return 0; }
1,800
CPP
n=int(input()) str=input() count=0 for i in range(len(str)-1): if str[i]==str[i+1]: count+=1 print(count)
800
PYTHON3
n=int(input()) c=input() t=[0]*n for i in range(n): h=i//2 if i%2==0: t[n-1-h]=c[n-1-i] else: t[h]=c[n-1-i] r="".join(t) print(r)
900
PYTHON3
n = int(input()) i = 0 ct = 0 sm = 0 while sm <= n: i = i + 1 ct = ct + i sm = sm + ct print(i - 1)
800
PYTHON3
n=int(input()) if n>=0: print(n) else: if int(str(n)[:-1])>=int(str(n)[:-2]+str(n)[-1]): print(int(str(n)[:-1])) else: print(int(str(n)[:-2]+str(n)[-1]))
900
PYTHON3
#include <bits/stdc++.h> using namespace std; int32_t main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; long long n; cin >> n; long long ok = 0; long long x, y; for (long long i = 1; i * i <= n; i++) { if (n % i == 0) { x = i; y = n / i; if (x >= 5 && y >= 5) { ok = 1; break; } } } if (ok == 0) { cout << -1; return 0; } vector<string> arr; arr.push_back("aeiou"); arr.push_back("eioua"); arr.push_back("iouae"); arr.push_back("ouaei"); arr.push_back("uaeio"); char mat[x][y]; for (long long i = 0; i < x; i++) { for (long long j = 0; j < y; j++) { mat[i][j] = '0'; } } for (long long i = 0; i < x; i++) { long long l = 0; for (long long j = 0; j < 5; j++) { mat[i][j] = arr[i % 5][l++]; } } long long idx = -1; for (long long i = 0; i < x; i++) { for (long long j = 0; j < y; j++) { if (mat[i][j] == '0') { idx = j; break; } } } long long p = 0; if (idx != -1) { for (long long i = idx; i < y; i++) { long long u = 0; for (long long j = 0; j < 5; j++) { mat[j][i] = arr[p % 5][u++]; } } if (x > 5) { for (long long i = idx; i < y; i++) { for (long long j = 5; j < x; j++) { mat[j][i] = 'w'; } } } } string ans = ""; for (long long i = 0; i < x; i++) { for (long long j = 0; j < y; j++) { ans.push_back(mat[i][j]); } } cout << ans; return 0; }
1,100
CPP
#include <bits/stdc++.h> using namespace std; long long int MOD = 1000000007; long long int gcd(long long int a, long long int b) { if (b == 0) return a; else return gcd(b, a % b); } long long int lcm(long long int a, long long int b) { return a / gcd(a, b) * b; } long long int power(long long int a, long long int n) { if (n == 0) return 1; long long int p = power(a, n / 2); p = (p * p); if (n % 2) return (p * a); else return p; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int test = 1; cin >> test; while (test--) { string s; cin >> s; map<pair<pair<int, int>, pair<int, int>>, int> m; pair<int, int> prev = {0, 0}; pair<int, int> curr = {0, 0}; for (auto x : s) { if (x == 'N') { curr.second++; } else if (x == 'S') { curr.second--; } else if (x == 'W') { curr.first--; } else { curr.first++; } if (prev > curr) m[{curr, prev}]++; else m[{prev, curr}]++; prev = curr; } long long int ans = 0; for (auto x : m) { ans += (x.second - 1) + 5; } cout << ans << '\n'; } return 0; }
1,400
CPP
from collections import deque n = int(input()) serega = [] dima = [] cards = deque(map(int, input().split())) for i in range(n - 1): if i % 2 == 0: if len(cards) >= 2: a = cards.popleft() b = cards.pop() if a > b: serega.append(a) cards.append(b) else: serega.append(b) cards.appendleft(a) else: if len(cards) >= 2: a = cards.popleft() b = cards.pop() if a > b: dima.append(a) cards.append(b) else: dima.append(b) cards.appendleft(a) if n % 2 == 1: serega.append(cards.pop()) else: dima.append(cards.pop()) print(sum(serega), sum(dima))
800
PYTHON3
for _ in range(int(input())): s=input() ans="" ans+=(s[0]+s[1]) for i in range(3,len(s),2): ans+=s[i] print(ans)
800
PYTHON3
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") using namespace std; const int N = 1e3 + 10, M = 52; int dp[N][2][M][M]; int a[N]; int b[N]; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, p, k1; cin >> n >> p >> k1; if (k1 == 0) { cout << 0 << endl; return 0; } p = min(p, 2 * ((n + k1 - 1) / k1)); int t1; cin >> t1; for (int i = 0; i < t1; i++) { int x; cin >> x; a[x] = 1; } cin >> t1; for (int i = 0; i < t1; i++) { int x; cin >> x; b[x] = 1; } for (int i = 0; i < N; i++) { for (int j = 0; j < 2; j++) { for (int k = 0; k < M; k++) { for (int l = 0; l < M; l++) { dp[i][j][k][l] = -1e9; } } } } for (int j = 0; j <= n; j++) { dp[j][0][0][0] = 0; } for (int j = 0; j < n; j++) { for (int i = 0; i <= p; i++) { for (int k = 0; k <= k1; k++) { for (int l = 0; l <= k1; l++) { int x = k; if (x != 0) { x++; x %= k1 + 1; } int z = l; if (z != 0) { z++; z %= k1 + 1; } if (x > 0 && a[j + 1] == 1) { dp[i][1][x][z] = max(dp[i][1][x][z], dp[i][0][k][l] + 1); } if (z > 0 && b[j + 1]) { dp[i][1][x][z] = max(dp[i][1][x][z], dp[i][0][k][l] + 1); } dp[i][1][x][z] = max(dp[i][1][x][z], dp[i][0][k][l]); if (a[j + 1] > 0) { dp[i + 1][1][1][z] = max(dp[i + 1][1][1][z], dp[i][0][k][l] + 1); } if (b[j + 1] > 0) { dp[i + 1][1][x][1] = max(dp[i + 1][1][x][1], dp[i][0][k][l] + 1); } } } } for (int i = 0; i <= p; i++) { for (int k = 0; k <= k1; k++) { for (int l = 0; l <= k1; l++) { dp[i][0][k][l] = dp[i][1][k][l]; dp[i][1][k][l] = -1e9; } } } } int ans = 0; for (int y = 0; y <= p; y++) for (int i = 0; i <= k1; i++) { for (int j = 0; j <= k1; j++) { ans = max(ans, dp[y][0][i][j]); } } cout << ans; }
2,400
CPP
#include <bits/stdc++.h> using namespace std; long long a, b, c, i, j, k, v[1007][1007], x, y, p; int main() { cin >> a >> b >> c; for (i = 1; i <= c; i++) { cin >> x >> y; v[x][y] = 1; for (j = x - 1; j <= x && j <= a - 1; j++) for (k = y - 1; k <= y && k <= b - 1; k++) if (v[j][k] == 1 && v[j + 1][k] == 1 && v[j][k + 1] == 1 && v[j + 1][k + 1] == 1 && p == 0) p = i; } cout << p << endl; }
1,100
CPP
for _ in range(int(input())): s = input() s = s.strip('0') print(s.count('0'))
800
PYTHON3
a=input() b=a.lower() c=a.upper() if a==c or a==(b[0]+c[1:]): if a==(b[0]+c[1:]): print(c[0]+b[1:]) if a==c: print(b) else: print(a)
1,000
PYTHON3
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5, INF = 0x3f3f3f3f; int n, m; long long k; int he[N], ne[N << 1], to[N << 1], tot = 0; int u, v; int dis[N]; long long ans, num[N]; int sum, chose[N]; queue<int> q; vector<int> pr[N]; void add(int u, int v) { ne[++tot] = he[u]; to[tot] = v; he[u] = tot; } void dfs(int u) { if (u == n + 1) { for (int i = 1; i <= m; i++) printf("%d", chose[i]); printf("\n"); if (++sum == k) exit(0); return; } for (int i = 0; i < pr[u].size(); i++) { chose[(pr[u][i] + 1) / 2] = 1; dfs(u + 1); chose[(pr[u][i] + 1) / 2] = 0; } } int main() { ans = 1; scanf("%d%d%lld", &n, &m, &k); for (int i = 1; i <= m; i++) { scanf("%d%d", &u, &v); add(u, v), add(v, u); } memset(dis, 0x3f, sizeof(dis)); dis[1] = 0; q.push(1); while (q.size()) { u = q.front(), q.pop(); for (int i = he[u]; i; i = ne[i]) { v = to[i]; if (dis[v] == INF) { dis[v] = dis[u] + 1; num[v]++; q.push(v); pr[v].push_back(i); } else if (dis[v] == dis[u] + 1) { num[v]++; pr[v].push_back(i); } } } for (int i = 2; i <= n; i++) { if (ans * num[i] > k) { ans = k; break; } else { ans *= num[i]; } } printf("%lld\n", min(ans, k)); dfs(2); }
2,100
CPP
M = 998244353 n=input() p=list(map(int, input().split(' '))) num=0 denum=1 for i in p: num=(num+denum)*100%M denum=denum*i%M #print(num, denum) from math import gcd g=gcd(num,denum) num=num//g denum=denum//g denum=pow(denum,M-2,M) print(num*denum%M)
2,100
PYTHON3
import sys import math #to read string get_string = lambda: sys.stdin.readline().strip() #to read list of integers get_list = lambda: list( map(int,sys.stdin.readline().strip().split()) ) #to read non spaced string and elements are integers to list of int get_intList_from_str = lambda: list(map(int,list(sys.stdin.readline().strip()))) #to read non spaced string and elements are character to list of character get_strList_from_str = lambda: list(sys.stdin.readline().strip()) #to read integers get_int = lambda: int(sys.stdin.readline().strip()) #to print faster pt = lambda x: sys.stdout.write(str(x)) #--------------------------------WhiteHat010--------------------------------------# k,r = get_list() temp = k count = 1 while True: if temp%10 == 0: print(count) break elif (temp-r)%10 == 0: print(count) break elif temp == r: print(count) break else: temp = temp + k count += 1
800
PYTHON3
""" Accomplished using the EduTools plugin by JetBrains https://plugins.jetbrains.com/plugin/10081-edutools """ def f(ayes): n = len(ayes) cnt1 = len([a for a in ayes if a]) cnt0 = n - cnt1 if cnt1 <= n // 2: return [0 for _ in range(cnt0)] else: return [1 for _ in range(cnt1 - cnt1 % 2)] if __name__ == "__main__": # Write your solution here t = int(input()) for _ in range(t): _ = int(input()) result = f([int(a) for a in input().split()]) print(len(result)) print(' '.join([str(x) for x in result]))
1,100
PYTHON3
#include <bits/stdc++.h> template <typename T> inline void read(T &x) { x = 0; char c = getchar(); bool flag = false; while (!isdigit(c)) { if (c == '-') flag = true; c = getchar(); } while (isdigit(c)) x = x * 10 + (c ^ 48), c = getchar(); if (flag) x = -x; } using namespace std; int xorsum[1001000]; int n; inline void init() { for (int i = 1; i <= n; ++i) xorsum[i] = xorsum[i - 1] ^ i; } int main() { read(n); init(); int ans = 0; for (int i = 1; i <= n; ++i) { int x; read(x); ans ^= x; } for (int j = 1; j <= n; ++j) { int bei = n / j; if (bei & 1) ans ^= xorsum[j - 1]; int yu = n % j; ans ^= xorsum[yu]; } printf("%d\n", ans); return 0; }
1,600
CPP
t = int(input()) for _ in range(t): n = int(input()) s = input() ss = sorted(s) c = 0 for i in range(n): if s[i] != ss[i]: c += 1 print(c)
800
PYTHON3
import sys, os, io def rs(): return sys.stdin.readline().rstrip() def ri(): return int(sys.stdin.readline()) def ria(): return list(map(int, sys.stdin.readline().split())) def ws(s): sys.stdout.write(s + '\n') def wi(n): sys.stdout.write(str(n) + '\n') def wia(a): sys.stdout.write(' '.join([str(x) for x in a]) + '\n') import math,datetime,functools,itertools,operator,bisect,fractions,statistics from collections import deque,defaultdict,OrderedDict,Counter from fractions import Fraction from decimal import Decimal from sys import stdout def main(): starttime=datetime.datetime.now() if(os.path.exists('input.txt')): sys.stdin = open("input.txt","r") sys.stdout = open("output.txt","w") for _ in range(ri()): n,k=ria() s=rs() consgaps=[] currconsgaps=0 prevscore=0 for i in range(n): if s[i]=='W': if i-1>=0 and s[i-1]=='W': prevscore+=2 else: prevscore+=1 L,R=0,n-1 for i in range(n): if s[i]=='W': L=i break for i in range(n-1,-1,-1): if s[i]=='W': R=i break s=s[L:R+1] # print(s) if k==0: print(prevscore) elif prevscore==0: print(2*(min(n,k))-1) else: ngapsleftovers=(L+n-1-R) for i in range(len(s)): if s[i]=='W': if currconsgaps>0: consgaps.append(currconsgaps) currconsgaps=0 else: currconsgaps+=1 if currconsgaps>0: consgaps.append(currconsgaps) # print(consgaps) z=sorted(consgaps) # print(z) newscore=prevscore for i in z: if k-i<0: newscore+=2*k k=0 break else: newscore+=2*i+1 k-=i if k>0: newscore+=2*min(ngapsleftovers,k) print(newscore) #<--Solving Area Ends endtime=datetime.datetime.now() time=(endtime-starttime).total_seconds()*1000 if(os.path.exists('input.txt')): print("Time:",time,"ms") class FastReader(io.IOBase): newlines = 0 def __init__(self, fd, chunk_size=1024 * 8): self._fd = fd self._chunk_size = chunk_size self.buffer = io.BytesIO() def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size)) 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, size=-1): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size)) 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() class FastWriter(io.IOBase): def __init__(self, fd): self._fd = fd self.buffer = io.BytesIO() self.write = self.buffer.write def flush(self): os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class FastStdin(io.IOBase): def __init__(self, fd=0): self.buffer = FastReader(fd) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") class FastStdout(io.IOBase): def __init__(self, fd=1): self.buffer = FastWriter(fd) self.write = lambda s: self.buffer.write(s.encode("ascii")) self.flush = self.buffer.flush if __name__ == '__main__': sys.stdin = FastStdin() sys.stdout = FastStdout() main()
1,400
PYTHON3
import io, os input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline t=int(input()) for tests in range(t): n=int(input()) A=list(map(int,input().split())) COUNT=[[0]*201 for i in range(n)] for i in range(n): for j in range(1,201): COUNT[i][j]=COUNT[i-1][j] COUNT[i][A[i]]+=1 ANS=1 for i in range(1,201): bind=0 eind=n-1 score=0 while bind<eind: while bind<n and A[bind]!=i: bind+=1 while eind>=0 and A[eind]!=i: eind-=1 if bind<eind: score+=2 C=[0]*201 for j in range(201): C[j]=COUNT[eind-1][j]-COUNT[bind][j] ANS=max(ANS,score+max(C)) #print(ANS,i,bind,eind,score) bind+=1 eind-=1 print(ANS)
1,100
PYTHON3
# maa chudaaye duniya n = int(input()) arr = list(map(int, input().split())) init = [] curr_ptr = 0 last_element = arr[0] ctr = 0 while curr_ptr < n: if arr[curr_ptr] == last_element: ctr += 1 else: init.append(ctr) last_element = arr[curr_ptr] ctr = 1 curr_ptr += 1 init.append(ctr) ans = 0 for i in range(1, len(init)): ans = max(ans, min(init[i-1], init[i])) print(2*ans)
900
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); int t; cin >> t; for (int cs = 1; cs <= t; cs++) { long long n, k; cin >> n >> k; long long sum = (k - 1) * (k - 1); long long rem = n - sum; if (rem % 2 == 0 || rem <= ((k - 2) * 2 + 1)) { cout << "NO" << endl; } else { cout << "YES" << endl; } } }
1,100
CPP
#include <bits/stdc++.h> using namespace std; inline int read() { char ch; int w = 1; while (!isdigit(ch = getchar())) if (ch == '-') w = -1; int s = ch - '0'; while (isdigit(ch = getchar())) s = s * 10 + ch - '0'; return s * w; } const int N = 1e7 + 5; long long n, sum[N], maxn; int main() { n = read(); for (register int i = n; i >= 1; i--) { int x = read(); sum[x + i] += x; maxn = max(maxn, sum[x + i]); } printf("%lld", maxn); return 0; }
1,400
CPP
#include <bits/stdc++.h> using namespace std; map<string, int> record; int main() { int n, m; vector<int> digit; vector<int> num; scanf("%d", &n); for (int i = 0; i < n; i++) { int t = 0; scanf("%d", &m); while (m > 0) { t += m % 10; m /= 10; } if (t % 3 == 0) digit.push_back(t); else num.push_back(t); } int ans = digit.size() / 2; for (int i = 0; i < num.size(); i++) { for (int j = i + 1; j < num.size(); j++) { if ((num[i] + num[j]) % 3 == 0 && num[j] != 0) { ans++; num[j] = 0; break; } } } printf("%d\n", ans); return 0; }
1,300
CPP
#include<iostream> #include<stdio.h> #include<cstdio> #include<vector> #include<algorithm> #include<cstring> #include<cmath> #include<queue> #include<string> #include<stack> #include<set> #include<map> #include<bitset> #include<unordered_map> #include<time.h> #include<cstdlib> #include <chrono> #include <random> typedef long long ll; typedef unsigned long long ull; //#pragma comment(linker, "/STACK:1024000000,1024000000") //#pragma comment(linker, "/STACK:36777216") //hdu 扩栈 #define mm(a) memset(a,0,sizeof(a)) #define lr rt<<1 #define rr rt<<1|1 #define sync std::ios::sync_with_stdio(false);std::cin.tie(0); #define inf 0x3f3f3f3f #define eqs 1e-8 #define lb(x) (x&(-x)) #define ch(a) (int(a-'a')+1) #define rep(i, a, b) for(int i=a;i<=b;i++) #define mkp(a, b) make_pair(a,b) #define re register #define umap(a) (a).reserve(1024);(a).max_load_factor(0.25); using namespace std; typedef pair<int,ll> pii; typedef pair<ll,ll> pll; typedef pair<pii,int> piii; //const double pi=acos(-1); const int maxn=305; const ll Mod=1000000007; //const ll Mod=998244353; ll ksm(ll x,ll y) { ll res=1; while(y) { if(y&1) { res=res*x%Mod; } x=x*x%Mod; y/=2; } return res%Mod; } int n,root; int d[maxn],anc[maxn][20]; vector<int>g[maxn]; inline void dfs(int u,int dep,int fa) { d[u]=dep; anc[u][0]=fa; for(int i=0;i<g[u].size();i++) if(g[u][i]!= fa) dfs(g[u][i],dep+1,u); } inline int log2(int x) { int k=0; while(x>1) { x>>=1; k++; } return k; } inline void init() { dfs(root, 0, 0); int s = 10; for (int j = 1;j<= s;j++) for(int i = 1;i<=n;i++) { anc[i][j] = anc[anc[i][j - 1]][j - 1]; } } // 求x与y的LCA inline int query(int x,int y) { if(d[x]<d[y]) swap(x, y); int s = log2(d[x] - d[y]); while(d[x]>d[y]) { if(d[x]-(1<<s)>=d[y]) x=anc[x][s]; s--; } s=log2(d[x]); while(s>-1) { if (anc[x][s]!=anc[y][s]) { x=anc[x][s]; y=anc[y][s]; } s--; } return x==y?x:anc[x][0]; } ll p[maxn],inv[maxn]; ll C(int n,int m) { return p[n]*inv[m]%Mod*inv[n-m]%Mod; } ll dp[maxn][maxn]; int main() { p[0]=inv[0]=1ll; for(int i=1;i<=maxn-2;i++) { p[i]=p[i-1]*i%Mod; // inv[i]=ksm(p[i],Mod-2); } inv[maxn-2]=ksm(p[maxn-2],Mod-2); //阶乘的逆元 for(int i=maxn-3;i>=0;i--) inv[i]=inv[i+1]*(i+1)%Mod; cin>>n; int u,v; for(int i=1;i<n;i++) { cin>>u>>v; g[u].push_back(v); g[v].push_back(u); } for(int i=1;i<=n;i++) dp[0][i]=1ll; for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) { dp[i][j]=(dp[i-1][j]+dp[i][j-1])*inv[2]%Mod; } } ll ans=0ll; int ac; ll wu,wv; ll p,q; for(int k=1;k<=n;k++) { root=k; init(); // for(int i=1;i<=n;i++) // { // cout<<root<<' '<<i<<' '<<anc[i][0]<<' '<<anc[i][1]<<endl; // } for(u=1;u<=n;u++) { for(v=u+1;v<=n;v++) { ac=query(u,v); // cout<<root<<' '<<u<<' '<<v<<' '<<ac<<endl; if(ac==u) continue; if(ac==v) { ans=(ans+1ll)%Mod; continue; } wu=d[u]-d[ac]; wv=d[v]-d[ac]; ans=(1ll*ans+dp[wv][wu])%Mod; } } } ans=ans*ksm(n,Mod-2)%Mod; cout<<(ans%Mod+Mod)%Mod<<endl; return 0; }
2,300
CPP
t = int(input()) for _ in range(t): n = int(input()) p = 0 a = list(map(int,input().split())) for i in range(n): if a[i]%2==1: p+=1 if p==0: print("NO") else: if(p==n and n%2==0): print("NO") else: print("YES")
800
PYTHON3
n = int(input()) ans = [] vert = set() hor = set() for i in range(n*n): a,b = map(int,input().split()) if a not in vert and b not in hor: ans.append(i+1) vert.add(a) hor.add(b) print(*ans)
1,000
PYTHON3
def main(): n=int(input()) feel=['hate', 'love'] tmp=0 i=1 while i<n: print('I '+feel[tmp]+' that',end=' ') tmp=1-tmp i+=1 print('I '+feel[tmp]+' it') main()
800
PYTHON3
def cover(sx,sy): x,y = sx,sy while y!=1: y -= 1 ans.append((x,y)) if sy!=m: y = sy while y!=m: y += 1 ans.append((x,y)) return [x,y] n,m,sx,sy = map(int,input().split()) x,y = sx,sy ans = [] end = [sx+1,sy] while len(ans)<n*m: while end!=[1,1] and end!=[1,m]: end[0] -= 1 ans.append(end) end = cover(end[0],end[1]) # print (ans,end) end = [sx,end[1]] while end!=[n,1] and end!=[n,m]: end[0] += 1 ans.append(end) end = cover(end[0],end[1]) # print (ans,end) for i in ans: print (i[0],i[1])
1,100
PYTHON3
x, y = input().split() arr = input() l = list(map(int,arr.split(" "))) l.sort() a = 0 c = 0 for c in range(int(x)): if 5 - l[c] >= int(y): a += 1 c += 1 print(a//3)
800
PYTHON3
inp = lambda:map(int,input().split()) n,k = inp() k -= 1 arr = list(inp()) count = 0 for i in range (0, n): if ((arr[i] >= arr[k]) and (arr[i] > 0)): count +=1 print(count)
800
PYTHON3
s=input() l=[] for i in s: if i in 'hello': l.append(i) if 'h'in l and 'e'in l and'l'in l and 'o' in l and l.count('l')>1: del l[0:l.index('h')] l.remove('h') if 'e'in l and 'l' in l and 'o' in l and l.count('l')>1: del l[:l.index('e')] l.remove('e') if 'l'in l and 'o'in l and l.count('l')>1: del l[:l.index('l')+1] del l[:l.index('l')] if 'o'in l: print('YES') else: print('NO') else: print('NO') else: print('NO') else: print('NO')
1,000
PYTHON3
from math import sqrt,gcd n=int(input()) for i in range(round(sqrt(n))+1,0,-1): if n%i==0 and gcd(i,n//i)==1:print(i,n//i);break
1,400
PYTHON3
def solve(): n = int(input()) cards = [] cnt = {} for i in range(n): card = tuple(map(int, input().split(' '))) cards.append(card) cnt[card[0]] = [0, 0] cnt[card[1]] = [0, 0] for card in cards: if card[0] != card[1]: cnt[card[0]][0] += 1 cnt[card[1]][1] += 1 else: cnt[card[0]][0] += 1 border = (len(cards) + 1) // 2 best = float('inf') for num in cnt.keys(): count = cnt[num] if sum(count) >= border: # try to flip down -> top or vice versa needTop = max(0, border - count[0]) best = min(best, needTop) if best == float('inf'): print(-1) else: print(best) solve()
1,500
PYTHON3
for _ in range(int(input())): n=int(input()) A=[int(i)%3 for i in input().split()] count=A.count(0) x=A.count(1) y=A.count(2) count+=min(x,y) rest=max(x,y)-min(x,y) count+=rest//3 print(count)
1,100
PYTHON3
a=input() s=1 for i in range(len(a)-1): if a[i]==a[i+1]: s+=1 if s==7: print('YES') break else: s=1 if s<7: print('NO')
900
PYTHON3
i=input;i() c=o=s=0 for i in i().split(): i=int(i) c=c+1 if i>=s else 1 o=max(o,c) s=i print(o)
900
PYTHON3