solution
stringlengths
10
159k
difficulty
int64
0
3.5k
language
stringclasses
2 values
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 10; const int INF = 0x3f3f3f3f; int a[110], b[110]; set<int> st[110]; set<int>::iterator it; int main() { int n, m, k; cin >> n >> m >> k; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= n; i++) { int x; cin >> x; b[...
1,100
CPP
#include <bits/stdc++.h> using namespace std; const int maxn = 200 + 5; int n, m; int he[maxn]; bool cur[maxn]; int main() { scanf("%d%d", &m, &n); memset(cur, false, 103 * sizeof(bool)); for (int i = 1; i <= m; i++) { int k, kk; scanf("%d", &k); for (int j = 1; j <= k; j++) { scanf("%d", &kk); ...
800
CPP
n = int(input()) sum = 0 while n > 0: sum = sum + (n % 2) n = n // 2 print(sum)
1,000
PYTHON3
l=int(input()) s=input() a=[] for i in range(0,l-1): a.append(s[i]+s[i+1]) a.sort() fs="" m,c=0,1 #print(a) for i in range(len(a)): count = a.count(a[i]) if count>m: m=count fs=a[i] """for i in range(1,len(a)): if a[i] == a[i-1]: c+=1 if c>=m: m=c ...
900
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { long long i, t, s = 0, c = 0; cin >> t; int ar[t]; for (i = 0; i < t; i++) cin >> ar[i]; sort(ar, ar + t); for (i = 0; i < t; i++) { if (s <= ar[i]) { c++; s = s + ar[i]; } } cout << c; }
1,300
CPP
a = [-1] * 16 a[0] = 0 for i in range(1,16): for j in [4, 6, 9]: if i >= j and a[i - j] != -1: a[i] = max(a[i], a[i - j] + 1) for _ in range(int(input())): n = int(input()) if n < 16: print(a[n]) else: t = (n - 16) // 4 + 1 print(a[n - t * 4] + t)
1,300
PYTHON3
n,m=map(int,input().split()) CAN0=n-m CAN1=max(1,m) print(min(CAN0,CAN1))
900
PYTHON3
a,b=[],[] for _ in range(int(input())): x,y=map(int,input().split()) a.append((x,y)) a.sort() ans=a[0][1] for i in range(1,len(a)): x,y=a[i] if y>=ans:ans=y else:ans=x print(ans)
1,400
PYTHON3
#include <bits/stdc++.h> using namespace std; template <int MOD> struct Modular { int value; Modular(const Modular& k) : value(k.value) {} template <typename V> Modular(const V& v) : value(v % MOD) { if (value < 0) { value += MOD; } } Modular() : Modular(0) {} Modular& operator+=(Modular con...
2,600
CPP
#include <bits/stdc++.h> using namespace std; const long long MOD = 998244353; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; long long k; cin >> n >> k; vector<vector<vector<long long>>> dp( n, vector<vector<long long>>(2, vector<long long>(2 * n + 1, 0))); vector<int> cor(n); for (...
2,200
CPP
n = int(input()) j = 0 temp = 0 for i in range(n): k, t = map(int, input().split()) j += t - k temp = max(temp, j) print(temp)
800
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { char str[][10] = {"vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon"}; vector<string> s; string ans; int n, flag = 0, i, j; char c[10]; for (i = 0; i < 8; i++) s.push_back(str[i]); cin >> n ...
1,000
CPP
y = int(input()) + 1 while not len(set(list(str(y)))) == len(list(str(y))): y += 1 print(y)
800
PYTHON3
#include <bits/stdc++.h> using namespace std; map<string, vector<string>> mymap; map<string, bool> vis; int dfs(string v) { vis[v] = true; int m = 0; for (auto i : mymap[v]) { if (!vis[i]) { m = max(m, dfs(i)); } } return m + 1; } int main() { int n; cin >> n; for (int i = 0; i < n; i++) {...
1,200
CPP
#include <bits/stdc++.h> const int md = 1e9 + 7; const long long inf = 4e18; const int OO = 0; const int OOO = 1; using namespace std; const int M = 5050505; int sieve[M] = {}; void prep() { for (int i = 2; i * i <= M; i++) { if (!sieve[i]) { sieve[i] = i; for (int j = i * i; j < M; j += i) sieve[j] =...
2,900
CPP
number, count = input().split(' ') count = int(count) for _ in range(count): figure = int(number[-1]) if figure == 0: number = number[:len(number)-1] else: number = number[:len(number)-1] + str(figure-1) print(number)
800
PYTHON3
import re import math n=int(input()) for i in range(n): r=input() s=re.findall(r'[0-9]+|[A-Z]+', r) if len(s) == 2: c = [] t = len(s[0]) for i in range(t): c.append(ord(s[0][i])-64) column = 0 for i in range(t): column += c[i] * 26**(t - i - 1)...
1,600
PYTHON3
num = int(input()) n = input() l = map(int,n.split()) main = list(l) maxi= main[0] mini = main[0] amazing = 0 for i in main: if i > maxi: maxi = i amazing += 1 elif i < mini: mini = i amazing += 1 print(amazing)
800
PYTHON3
n, k = map(int, input().split()) s = list(map(int, input().split())) print((len([x for x in s if x + k <= 5])) // 3)
800
PYTHON3
#include <bits/stdc++.h> using namespace std; int N; int Triangle[305]; bool Use[305]; struct Element { int nodes[5], cnt; } Sol[900005], Sol2[900005]; int K; bool E[900005]; void Erase(int pos) { swap(Sol[pos], Sol[K]); --K; } void Insert(int pos, int v[], int cnt) { for (int i = 1; i <= cnt; i++) Sol[pos].nod...
2,800
CPP
import sys input = sys.stdin.readline for _ in range(int(input())): n=int(input()) L=list(map(int,input().split())) if L[0]<L[-1]: print('YES') else: print('NO')
1,400
PYTHON3
#include <bits/stdc++.h> using namespace std; const int N = 1010; const int M = 33; const int K = 670000; const int LIT = 2500; const int INF = 1 << 28; const int base = 137; const double eps = 1e-10; const int dir[5][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}}; const int dir2[10][2] = {{-1, 0}, {1, 0}, {0, 1}, {0, -1}, ...
1,300
CPP
#include <bits/stdc++.h> using namespace std; using ll = long long; template <int maxn> class Seg { private: struct Node { ll maxi, sum; }; Node join(Node const& a, Node const& b) { return {max(a.maxi, b.maxi), a.sum + b.sum}; } int n; Node tree[maxn * 4]; void build(vector<int> const& v, int no,...
2,500
CPP
#include <bits/stdc++.h> inline long long Max(long long x, long long y) { return x > y ? x : y; } inline long long Min(long long x, long long y) { return x < y ? x : y; } inline long long Abs(long long x) { return x < 0 ? ~x + 1 : x; } inline long long read() { long long r = 0; bool w = 0; char ch = getchar(); ...
800
CPP
#include <bits/stdc++.h> using namespace std; template <typename tp> tp read() { char c = getchar(); tp x = 0; bool sgn = 0; while ((c < '0' || c > '9') && c != '-') c = getchar(); if (c == '-') sgn = 1, c = getchar(); while (c >= '0' && c <= '9') x = (x << 3) + (x << 1) + c - '0', c = getchar(); return s...
2,500
CPP
#include <bits/stdc++.h> using namespace std; pair<int, int> a[100007]; int val[100007], n, k; map<int, int> id; set<int> S; vector<int> adj[100007]; bool d[100007]; void dfs(int u) { cout << val[u] << " "; d[u] = 1; for (auto v : adj[u]) if (!d[v]) dfs(v); } int main() { cin >> n; for (int i = 1; i <= n;...
1,700
CPP
t=int(input()) for i in range(t): n, m = map(int, input().split()) sp=list(map(int, input().split())) print(min(m, sum(sp)))
800
PYTHON3
#include <bits/stdc++.h> using namespace std; const long long maxn = 2e6 + 9; long long p[maxn]; long long sz[maxn]; long long lst[maxn]; pair<long long, long long> q[maxn]; long long n; long long find_p(long long i) { if (p[i] != i) p[i] = find_p(p[i]); return p[i]; } void merg(long long i, long long e) { i = fi...
2,500
CPP
s=input( ) a=0 for i in range(len(s)): if s[i] is 'h' and a==0: a=1 continue if s[i] is 'e' and a==1: a=2 continue if s[i] is 'l' and a==2: a=3 continue if s[i] is 'l' and a==3: a=4 continue if s[i] is 'o' and a==4: a=5 ...
1,000
PYTHON3
#include <bits/stdc++.h> using namespace std; void _print(bool t) { cerr << t; } void _print(long long t) { cerr << t; } void _print(string t) { cerr << t; } void _print(char t) { cerr << t; } void _print(double t) { cerr << t; } template <class T> void _print(vector<T> v) { cerr << "[ "; for (T i : v) { _prin...
1,900
CPP
#include <bits/stdc++.h> using namespace std; int main() { long long int tc, i, j; cin >> tc; while (tc--) { long long int n, s = 0, b; cin >> n; for (i = 0; i < n; i++) { cin >> b; if (b <= 2048) s += b; } s >= 2048 ? cout << "YES\n" : cout << "NO\n"; } }
1,000
CPP
n = int(input()) d = dict() for each_n in range(n): s = input() if s in d: print(s + str(d[s])) d[s] += 1 else: print("OK") d[s] = 1
1,300
PYTHON3
n,s,t = list(map(int,input().split())) p = list(map(int,input().split())) path = [s] path_d={s:0} while(True): # print(path_d) # print(p[path[-1]-1]) try: check = path_d[p[path[-1]-1]]==0 break except: pass path_d[p[path[-1]-1]]=0 path.append(p[path[-1]-1]) if p...
1,200
PYTHON3
import itertools import math import sys import heapq from collections import Counter from collections import deque from fractions import gcd from functools import reduce sys.setrecursionlimit(4100000) INF = 1 << 60 #ここから書き始める n = int(input()) s = input() cnt1 = s.count("A") cnt2 = n - cnt1 if cnt1 > cnt2: print("A...
800
PYTHON3
import math a,b=(int(n) for n in input().split()) ans=1 for i in range (1,min(a,b)+1): ans*=i print(ans)
800
PYTHON3
def solve(): from math import gcd r, y, k = map(int, input().split()) b = max(r, y) a = min(r, y) c = b - gcd(a, b) - 1 x = 1 + c // a if x >= k: print('REBEL') else: print('OBEY') t = eval(input()) for i in range(t): solve()
1,700
PYTHON3
#include <bits/stdc++.h> using namespace std; vector<pair<int, pair<long long, int> > > g[303030]; vector<int> gg[303030]; int used[303030]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m, k; cin >> n >> m >> k; for (int i = 0; i < m; i++) { int a, b, c; cin >> a >> b >> c; g[a].p...
1,800
CPP
n = input() leng = len(n) for i in range(leng): if(i is 0 and n[i] is '9' ): continue elif(n[i]>'4'): n = n.replace(n[i],str(9-int(n[i]))) n = [i for i in n] if n[0] is '0': n[0] = '9' print(''.join(n))
1,200
PYTHON3
#include <bits/stdc++.h> using namespace std; using namespace std; using namespace std; signed main() { long long n; cin >> n; vector<long long> v1(n); vector<long long> v2(n); for (long long i = 0; i < (long long)(n); ++i) { cin >> v1[i] >> v2[i]; } long long c = 0; for (long long i = 0; i < (long ...
800
CPP
n = int(input()) str = input() a=[] for v in str: if v not in a: a.append(v) print(n-len(a) if n < 27 else -1)
1,000
PYTHON3
#include <bits/stdc++.h> using namespace std; long long p[1000010], a[1000010], b[1000010]; int main() { int n, m; scanf("%d%d", &n, &m); p[0] = 1; for (int i = 1; i <= n; ++i) p[i] = p[i - 1] * 999983; for (int i = 0; i < m; ++i) { int u, v; scanf("%d%d", &u, &v); a[u] += p[v], a[v] += p[u]; } ...
2,300
CPP
#include <bits/stdc++.h> using namespace std; int n, a, i = 1, j, b; int main() { scanf("%d", &n); while (i < 1100000000) { n++; b = n; while (b != 0) { a = b % 10; if (a == 8 || a == -8) { printf("%d\n", i); return 0; } b /= 10; } i++; } return 0; }
1,100
CPP
#include <bits/stdc++.h> using namespace std; int main() { int x, y; vector<pair<int, int> > v, ve; set<int> setx, sety; for (int i = 0; i < 3; i++) { cin >> x >> y; v.push_back(make_pair(x, y)); setx.insert(x); sety.insert(y); } if (setx.size() == 1 || sety.size() == 1) { cout << "1" <<...
1,700
CPP
#include <bits/stdc++.h> using namespace std; int main() { int s = 1; char c; cin >> c; while (cin >> c) s += (c - 49 ? c - 48 : 10); cout << s; }
1,900
CPP
n, m = map(int, input().split()) ans = n while n // m > 0: ans += n // m n = n % m + n // m print(ans)
900
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long int n; cin >> n; long long int i; long long int a[n]; for (long long int i = 0; i < n; i++) cin >> a[i]; vector<char> v; long long int ma = 0; long long int j = n - 1; i = 0; ...
1,300
CPP
#include <bits/stdc++.h> using namespace std; int DV(char c) { int z; if (c == '0') z = 0; else if (c == '1') z = 1; else if (c == '2') z = 2; else if (c == '3') z = 3; else if (c == '4') z = 4; else if (c == '5') z = 5; else if (c == '6') z = 6; else if (c == '7') z = ...
1,000
CPP
d,t=map(int,input().split()) a = [list(map(int, input().split())) for i in range(d)] b = list(zip(*a)) mn = sum(b[0]) zx = sum(b[1]) if mn<=t<=zx: print('YES') x = t - mn for i, j in a: y = min(j - i, x) x -= y print(i + max(0, y), end=' ') else: print('NO')
1,200
PYTHON3
n, x = map(int, input().split()) a = 0 b = 1000 for i in range(n): c, d = map(int, input().split()) a = max(a, min(c, d)) b = min(b, max(c, d)) if a > b: print(-1) exit(0) if a <= x <= b: print(0) else: print(min(abs(a - x), abs(b - x)))
1,000
PYTHON3
n = int(input()) step = 0 while n != 0: if n >= 5: n -= 5 step += 1 elif n >= 4: n -= 4 step += 1 elif n >= 3: n -= 3 step += 1 elif n >= 2: n -= 2 step += 1 elif n >= 1: n -= 1 step += 1 print(step)
800
PYTHON3
#include <bits/stdc++.h> using namespace std; const long long seed = 233; const long long mod = 998244353; const long long P = 1e9 + 7; char s[2][2010], w[2010]; int n, m; int dp[2][2010][2010], ans; long long Pow[2010]; struct node { long long h[2010]; void make(int n, char* s) { for (int i = 1; i <= n; i++) {...
3,200
CPP
angka=input() x=len(angka) total=0 for i in range(x): if angka[i]=="4" or angka[i]=="7": total+=1 if total==4 or total==7 or total==47 or total==744: print("YES") else: print("NO")
800
PYTHON3
ins = map(int, input().split()) n, m = next(ins), next(ins) cnt = [0] * 20010 cancel = False for _ in range(m): line = list(map(int, input().split())) done = False for i in range(1, len(line)): if line[i] > 0: cnt[line[i] + 10000] = 1 if cnt[line[i]] == 1: don...
1,300
PYTHON3
""" ~~ Author : Bhaskar ~~ Dated : 08~06~2020 """ import sys from bisect import * from math import floor,sqrt,ceil,factorial as F,gcd,pi from itertools import chain,combinations,permutations,accumulate from collections import Counter,defaultdict,OrderedDict,deque from array import array INT_MAX = sys.maxsize INT_MIN =...
1,000
PYTHON3
#include <bits/stdc++.h> using namespace std; long long mod = 1e9 + 7; long long gcdll(long long a, long long b) { if (!b) return a; return gcdll(b, a % b); } void seive(int n) { vector<bool> is_prime(n + 1, true); is_prime[0] = is_prime[1] = false; for (int i = 2; i * i <= n; i++) { if (is_prime[i]) { ...
1,800
CPP
#include <bits/stdc++.h> int MAX_DIST = 200000000; struct node_s { int id; int dist; bool visited; }; struct edge_s { int length; bool visited; }; struct edge_lst { int node; edge_s* edge; edge_lst* nxt; }; bool compare_nodes(node_s* n1, node_s* n2) { if (n1->dist == n2->dist) return n1->id < n2->...
1,900
CPP
#include <bits/stdc++.h> using namespace std; int memo[30010][1600]; int n, d; int p[30010]; int base; int dfs(int cur, int pre) { if (cur > 30000) return 0; if (memo[cur][pre + base] != -1) return memo[cur][pre + base]; int ret = p[cur]; int plus = 0; for (int i = -1; i <= 1; i++) { int npre = pre + i; ...
1,900
CPP
#include <bits/stdc++.h> using namespace std; const int mod = 1000 * 1000 * 1000 + 7; const int dx[4] = {1, -1, 0, 0}; const int dy[4] = {0, 0, 1, -1}; const int sum[4] = {3, -3, 1, -1}; int n, m, i, j; string s[1005]; bool b[1005][1005]; vector<int> a; int p[300][300]; int v[300], g[300]; int dp[300][300][2][2]; int r...
2,300
CPP
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:64000000") using namespace std; void __never(int a) { printf("\nOPS %d", a); } int dx[] = {-1, 0, 1, 0, -1, 1}; int dy[] = {0, -1, 0, 1, -1, 1}; bool bad[5][5]; int nums[5][5]; int Code(vector<vector<int> > m) { int mask = 0, cc = 0; for (int(i) = (0); (i) <=...
2,000
CPP
s = input() c = 'aeiou' ans = "@" cn = 0 sm = 1 for i in s: if(i in c): cn = 0 sm = 1 elif(i == ans[-1]): sm += 1 cn += 1 elif(i != ans[-1]): cn += 1 if(cn == sm or cn <3): ans += i elif(cn>2): ans += " " ans += i cn = 1...
1,500
PYTHON3
import math mac=10**9+7 def comb(a,b): return math.factorial(a)//(math.factorial(b)*math.factorial(a-b)) n,m=map(int,input().split()) print(comb(2*m+n-1,2*m)%mac)
1,600
PYTHON3
class Solution: # @param A : tuple of strings # @return a list of list of integers def __init__(self): self.travelled_city = dict() def twobrackets(self , st): p_stack = [] q_stack = [] count = 0 for e in st: if e == '[': p_st...
800
PYTHON3
input_l = input() input_var = input_l.split() input_ = int(input_var[0]) iter = int(input_var[1]) while(iter > 0): last = input_ % 10 if(last == 0): input_ = input_ // 10 else: input_ = input_ - 1 iter -= 1 print(input_)
800
PYTHON3
#include <bits/stdc++.h> typedef long long ll; using namespace std; vector<vector<int>> matrix; vector<int> arr; pair<int, int> comb[6]={{0, 1}, {0, 2}, {0, 3}, {1, 2}, {1, 3}, {2, 3}}; pair<int, int> comb2[6]={{0, 1}, {0, 2}, {1, 0}, {1, 2}, {2, 0}, {2, 1}}; int n, m; int chk(bool flag){ int ret=0, mx=0; for...
2,500
CPP
n,b=map(int,input().split()) lis=[-1] for i in range((n+1)//2,n+1): if i%b==0: lis.append(i) break print(max(lis))
1,000
PYTHON3
l,m=map(int,input().split()) dic1=input().split() dic2=input().split() a=[] for i in range(int(input())): inp=int(input()) j=inp%l;r=inp%m if j==0: j=len(dic1) if r==0: r=len(dic2) a.append(dic1[j-1]+dic2[r-1]) for i in a: print(i)
800
PYTHON3
#include <bits/stdc++.h> using namespace std; const int maxn = 100000; int n; struct poly { unsigned long long p[10]; poly() { memset(p, 0, sizeof(p)); } poly operator*(poly b) { poly ret; for (int o = 0; o < 10; o++) ret.p[o] = 0; for (int i = 0; i < 10; i++) for (int j = 0; j < 10; j++) ...
3,400
CPP
#include <bits/stdc++.h> using namespace std; typedef struct item* pitem; vector<int> x[100001]; int used[100001][2], p[100001][2], v = -1; bool loop = false; void DFS(int u, int m) { used[u][m] = 1; if (x[u].size() == 0 && m == 1) v = u; for (int i = 0; i < x[u].size(); i++) { if (!used[x[u][i]][m ^ 1]) { ...
2,100
CPP
#include <bits/stdc++.h> using namespace std; const int MAX = 100005; const int INF = 1e9 + 7; const long long LINF = 1e18 + 7; vector<int> adj[MAX]; int vis[MAX] = {}; int cnt[MAX] = {}; int dfs(int u) { vis[u] = 1; if (adj[u].size() == 1 && u != 1) cnt[u] += 1; for (int i = 0; i < adj[u].size(); i++) { int ...
1,600
CPP
#include <bits/stdc++.h> using namespace std; char ans[110000], str[110000]; int P[2][110000]; int main() { int Len, i, j, t, K, now, then; while (scanf("%s", str + 1) != EOF) { str[0] = '$'; Len = strlen(str); str[Len] = '$'; P[0][0] = P[1][0] = 0; for (i = 0; i < Len - 1; i++) P[0][++P[0][0]] ...
2,100
CPP
t = int(input()) for _ in range(t): n = int(input()) D = {} DC = {} DS = {} A = list(map(int, input().split())) for i in range(n): if A[i] in D: D[A[i]].append(i) DS[A[i]][i] = 1 DC[A[i]] += 1 else: D[A[i]] = [i] DS[A[i]...
1,100
PYTHON3
#include <bits/stdc++.h> using namespace std; double get(double x1, double x2, double y1, double y2) { double p = (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1); return sqrt(p); } int main() { int n; double k; cin >> n >> k; double a, b; pair<double, double> p[n]; for (int i = 0; i < n; i++) { cin >>...
900
CPP
import math def get_primes(prime_supr): is_prime = [0]*2 + [1]*prime_supr for i in range(2,int(math.sqrt(prime_supr)) + 1): if is_prime[i]: for j in range(i * i, prime_supr + 1, i): is_prime[j] = 0 return is_prime get_int = lambda: map(int, input().split()) r, c = ...
800
PYTHON3
n = int(input()) a = list(map(int,input().split())) s = {} #dic d = {} #dic p = set() #set mx = - 10**15 mi = -mx ans = 2 for i in range(n) : if a[i] in s : s[a[i]] += 1 else : s[a[i]] = 1 mx = max(mx,a[i]) mi = min(mi,a[i]) if 0 in s : ans = max(ans,s[0]) for i in range(n) : for j in range(n) : if (j==...
2,000
PYTHON3
n = int(input()) if(n&1 or n==2): print('NO') else: print('YES')
800
PYTHON3
import sys import math import itertools import functools import collections import operator import fileinput import copy from collections import * ORDA = 97 # a def ii(): return int(input()) def mi(): return map(int, input().split()) def li(): return [int(i) for i in input().split()] def lcm(a, b): return abs(a * b)...
1,200
PYTHON3
a=input().split() nos=int(a[0]) tot=int(a[1]) l=[] b=input().split() for i in range(nos): l.append(int(b[i])) p=sum(l) m=p+(nos-1)*10 if m>tot: print(-1) else: n=(tot-p)//5 print(n)
900
PYTHON3
#include <bits/stdc++.h> class DSU { public: void reset(int n) { v.clear(); v.resize(n); for (int i = 0; i < n; ++i) v[i] = i; } void merge(int a, int b) { a = get(a), b = get(b); v[a] = b; } int get(int a) { return v[a] == a ? a : v[a] = get(v[a]); } private: std::vector<int> v; }; s...
2,200
CPP
n = int(input()) s = '8'*(n//2)+'4'*(n%2) if len(s)>18: print(-1) else: print(s)
1,200
PYTHON3
import sys input = sys.stdin.readline from math import gcd t=int(input()) for tests in range(t): n=int(input()) A=list(map(int,input().split())) NOW=0 ANS=[] while A: MAX=-1 NEXT=-1 NEXTIND=-1 for i in range(len(A)): a=A[i] if gcd(NOW,a)>MAX...
1,300
PYTHON3
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int maxn = 2e5 + 5; const int inf = 0x3f3f3f3f; int d[maxn << 1], p[maxn]; int main() { int T, n, k; scanf("%d", &T); while (T--) { memset(d, 0, sizeof(d)); scanf("%d%d", &n, &k); for (int i = 1; i <= n; i++) scanf("%d", &p[i...
800
CPP
n=int(input()) l=list(map(int,input().split())) if len(l)==1: print(1) else: l.sort() l=l[::-1] for i in range(1,n): a=sum(l[:i]) b=sum(l[i:]) if a>b: i=i-1 break print(i+1)
900
PYTHON3
#include <bits/stdc++.h> using namespace std; void solve() { long long int n; cin >> n; vector<long long int> arr(n, 0); for (long long int i = 0; i < n; i++) { cin >> arr[i]; } map<long long int, vector<long long int>> ans; for (long long int i = 0; i < n; i++) { long long int x = arr[i], c = 0; ...
1,900
CPP
#include <bits/stdc++.h> using namespace std; int n, ans; string inp[100005]; struct Node { int cnt, scnt, cap; vector<pair<char, int> > son; map<char, int> mmp; multiset<int, greater<int> > mts; } a[100005]; int tot = 1; bool mk[100005]; void Insert(string s, int len) { int cur = 1; for (int i = 1; i <= le...
2,200
CPP
#include <bits/stdc++.h> using namespace std; long long n; int c[12] = {4, 10, 20, 35, 56, 83, 116, 155, 198, 244, 292}; int main() { cin >> n; if (n >= 12) cout << (n - 11) * 49 + 292; else cout << c[n - 1]; return 0; }
2,000
CPP
#include <bits/stdc++.h> using namespace std; char next_char(char c) { const int mod = 'z' - 'a' + 1; return 'a' + (c - 'a' + 1) % mod; } int main() { int n, t; scanf("%d %d", &n, &t); vector<char> s1(n + 1, ' '), s2(n + 1, ' '), s3(n + 1, ' '); scanf("%s", s1.data()); scanf("%s", s2.data()); int same =...
1,700
CPP
n,m=map(int,input().split()) if m==0: print("1") else: print(min(m,n-m))
900
PYTHON3
n = int(input()) s = input() t1 = s.count('L') t2 = s.count('R') print(t1+t2+1)
800
PYTHON3
t=int(input()) a=[] b=[] for i in range(0,t): n,m=map(int,input().split()) a.append(n) b.append(m) c=list(a) c.sort() c=c[::-1] p=0 for i in range(0,len(a)): if a[i]!=b[i]: p=1 break if p==1: print("rated") else: if c==a: print("maybe") else: print("unrat...
900
PYTHON3
#include <bits/stdc++.h> #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math") using namespace std; const int N = 1e6 + 10; int nxt[N]; pair<int, int> seg[N * 4]; int mp[N]; void upd(int nod, int l, int r, int id, int val) { if (r - l == 1) { seg[nod] = {mp[l], val}; return; } int mid = ...
2,400
CPP
#include <bits/stdc++.h> using namespace std; string inttostr(long x) { string tmp = ""; while (x > 0) { char ch = (x % 10) + 48; tmp = ch + tmp; x /= 10; } return tmp; } int main() { long n; string m; cin >> n >> m; long a[11]; memset(a, 0, sizeof(a)); long s = 0; while (n > 0) { ...
1,100
CPP
n,h,m=map(int,input().split()) ans=[-1]*(n+1) while m: l,r,x=map(int,input().split()) for i in range(l,r+1): if ans[i]==-1: ans[i]=x**2 else: if ans[i]>x**2: ans[i]=x**2 m-=1 for i in range(1,n+1): if ans[i]==-1: ans[i]=h**2 ...
800
PYTHON3
import sys def main(): nums = [int(i) for i in sys.stdin.readline().split("+")] print("+".join([str(n) for n in sorted(nums)])) if __name__ == '__main__': main()
800
PYTHON3
#include <bits/stdc++.h> using namespace std; using ll = long long; namespace _buff { const size_t buff_size = 1e5; char buff[buff_size], *begin = buff, *end = buff; char getc() { if (begin == end) { end = (begin = buff) + fread(buff, 1, buff_size, stdin); } return begin == end ? -1 : *begin++; } } // namesp...
2,600
CPP
data = list(map(int, input().split())) ndigits = data[0] d_sum = data[1] if d_sum == 0: if ndigits > 1: print("-1 -1") else: print("0 0") elif 9 * ndigits < d_sum: print("-1 -1") else: to_minimal = d_sum minimal = "" for x in range(ndigits-1): for number in range(9,-1,-1)...
1,400
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int vladik; int valera; int num = 1; bool flag = true; scanf("%d %d", &vladik, &valera); while (true) { if (flag) { vladik -= num; num++; flag = false; if (vladik < 0) { printf("Vladik\n"); break; } ...
800
CPP
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e6 + 10; const int INF = 1e9; int t, n, m, cpm, cnt, degout[MAXN], tp[MAXN], num[MAXN], low[MAXN]; vector<int> E[MAXN], r1, r2; stack<int> s; void reset() { cpm = 0; cnt = 0; for (long long i = 1; i <= n; i++) { E[i].clear(); num[i] = 0; ...
2,400
CPP
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #pragma comment(linker, "/stack:200000000") using namespace std; long long spf[301]; long long fac[301]; void sieve() { spf[1] = 1; for (long long...
2,100
CPP
import sys mod = 1000000007 def get_array(): return list(map(int, sys.stdin.readline().split())) def get_ints(): return map(int, sys.stdin.readline().split()) def input(): return sys.stdin.readline() def print_array(a): print(" ".join(map(str, a))) def main(): for _ in range(int(input())): n, a, b = get_int...
1,500
PYTHON3
#include <bits/stdc++.h> using namespace std; vector<int> tr[100001]; int dp[100001][11][3], k, x, n, m, tmp[11][3], md = 1e9 + 7; inline void ad(int &x, int y) { if ((x += y) >= md) x -= md; } void go(int v = 1, int p = 0) { dp[v][0][0] = k - 1; dp[v][1][1] = 1; dp[v][0][2] = m - k; int(*z)[3] = dp[v]; for...
2,000
CPP