solution
stringlengths
10
983k
difficulty
int64
0
25
language
stringclasses
2 values
ans = [] for _ in range(int(input())): s = list(input()) for i in range(1, len(s)): if s[i] != s[0]: break else: ans.append(''.join(s)) continue t = '01' * len(s) ans.append(t) print('\n'.join(map(str, ans)))
8
PYTHON3
#include <bits/stdc++.h> long long abc[4], xyz[4], min[4], max[4], min_[4], max_[4]; int valid() { double sum = (double)abc[1] + abc[2] + abc[3]; if (sum < 0) sum = -sum; return sum <= 8e18; } int solve(int par) { for (int i = 1; i < 4; i++) { abc[i] = min_[i]; if ((abc[i] % 2 != 0) != par) abc[i]++; ...
9
CPP
#include <bits/stdc++.h> using namespace std; const int INF = (int)1e9; const long long INF64 = (long long)1e18; #pragma comment(linker, "/STACK:16777216") #pragma warning(disable : 4786) int Set(int N, int pos) { return N = N | (1 << pos); } int Reset(int N, int pos) { return N = N & ~(1 << pos); } bool check(int N, i...
8
CPP
#include <bits/stdc++.h> using namespace std; void func(); int main() { func(); return 0; } void func() { int N; cin >> N; bool arif = true; vector<int> mass(N); for (int i = 0; i < N; ++i) cin >> mass[i]; int shift; if (mass[0] < mass[1]) { shift = mass[0] - mass[1]; for (int i = 0; i < N - 1...
20
CPP
from itertools import permutations numstr = input() size = len(numstr) if len(numstr) % 2 == 0 else len(numstr) + 1 halfsize = size//2 # if number <= 10**8 if size <= 8: # generate all permutations of happiest numbers with current degree premuts = [int(''.join(p)) for p in permutations(['4', '7'] * halfsize)] prem...
8
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int n, a[105][105], sum = 0; bool seen; cin >> n; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> a[i][j]; if (i == j || (i == n - j - 1) || (i == (n - 1) / 2) || (j == (n - 1) / 2)) sum += a[i][j]; ...
7
CPP
#include <bits/stdc++.h> using namespace std; int main() { cout << 3 << endl; }
10
CPP
#include <bits/stdc++.h> int main(){ int i,s,x; scanf("%d",&x); for(i=s=0;s<x;s+=++i); printf("%d\n",i); return 0; }
0
CPP
#include <bits/stdc++.h> using namespace std; void print_vector(vector<int> v) { for (int i = 0; i < v.size(); i++) { cout << v[i] << " "; } cout << "\n"; } void print_arr(int v[], int size) { for (int i = 0; i < size; i++) { cout << v[i] << " "; } cout << "\n"; } long long getSets(long long current...
8
CPP
#include<iostream> #include<algorithm> #include<bitset> #include<vector> using namespace std; int H, W, K; char town[51][51]; int ans = 0; int dp[52][52][4][5][5][1 << 10] = {}; int ac[5][5] = { { 10, 10, 10, 10, 10 }, { 10, 3, 6, 8, 9 }, { 10, 2, 5, 7, 10 }, { 10, 1, 4, 10, 10 }, { 10, 0, 10, 10, 10 } }; int solve() ...
0
CPP
#include <bits/stdc++.h> using namespace std; const int N = 105; int n; int a[N], b[N]; char s[N]; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n; cin >> s + 1; for (int i = 1; i <= n; i++) cin >> a[i] >> b[i]; int ans = 0; for (int i = 1; i <= n; i++) { if (s[i] == '1') ++ans; } f...
8
CPP
#include <iostream> #include <algorithm> #include <string> #include <cstdlib> #include <queue> using namespace std; typedef long long lli; const int MAXR = 102; const int MAXC = 12; const lli INF = 1LL<<60; int R, C; lli G[MAXR][MAXC]; int numR[MAXR], numC[MAXC]; int main() { bool first = true; while(cin >> R &...
0
CPP
#include<bits/stdc++.h> #define ll long long #define fornum(A,B,C) for(A=B;A<C;++A) #define pii pair<int,int> #define pll pair<ll,ll> using namespace std; ///////////////////////////////////////////////////// #define MOD (ll)(1e9+7) ll R1, C1, R2, C2; ll i,j,k; ll Fa[2020202]; ll moddiv(ll a,ll b){ a %= MOD; ...
0
CPP
import math for _ in range(int(input())): n=int(input()) if n%4!=0: print("NO") else: s1=0 print("YES") for i in range(1,n+1): if i%2==0: print(i,end=" ") s1+=i s=0 for i in range(1,n-1): if i%2!=0: ...
8
PYTHON3
#include <bits/stdc++.h> namespace lc { template <class WeightType> struct EdgeWithWeight { int to; WeightType weight; EdgeWithWeight(int to, const WeightType &weight) : to(to), weight(weight) {} }; } // namespace lc namespace lc { template <typename EdgeType> class AdjacencyList { public: private: std::vect...
13
CPP
from sys import stdin, stdout t = int(stdin.readline()) for _ in range(t): n = int(stdin.readline()) a = list(map(int,stdin.readline().split())) c = 0 for i in range(n): if a[i] == 0 : a[i] = 1 c += 1 if sum(a) == 0: c += 1 stdout.write(str(c) + "\n")
7
PYTHON3
import sys from collections import defaultdict as dd from collections import Counter as cc from queue import Queue import math import itertools try: sys.stdin = open('input.txt', 'r') sys.stdout = open('output.txt', 'w') except: pass input = lambda: sys.stdin.buffer.readline().rstrip() for _ in range(int(input()))...
7
PYTHON3
t = int(input()) while t > 0: t -= 1 n, x, a, b = [int(q) for q in input().split()] right_num = max(a, b) left_num = min(a, b) for i in range(x): if right_num < n: right_num += 1 elif left_num > 1: left_num -= 1 length = right_num - left_num print(leng...
7
PYTHON3
#include <bits/stdc++.h> using namespace std; const int mxN = 2e4; int n, k, a[mxN], dp[2][mxN + 1], qt, m[mxN], b[mxN], mx[mxN + 1]; void al(int mi, int bi, bool mo) { if (qt && mi == m[qt - 1]) { if (bi > b[qt - 1]) return; --qt; } while (qt > 1 && (bi - b[qt - 1]) / (m[qt - 1] - mi) < ...
13
CPP
#include <iostream> #include <string> #include <algorithm> using namespace std; int main(){ string data[] = {"SUN","MON","TUE","WED","THU","FRI","SAT"}; string s;cin >> s; for(int i=0;i<7;i++) if(data[i]==s) cout << 7-i << endl; }
0
CPP
n = int(input()) a = list(map(int,input().split())) ans = 0 d = 1 for i in range(n-1): if a[i] < a[i+1]: d += 1 else: ans = max(ans,d) d = 1 ans = max(ans,d) print(ans)
7
PYTHON3
n = int(input()) if (n < 6): print(-1) else: print(1, 2) print(1, 3) print(1, 4) for i in range(5, n + 1): print(2, i) for i in range(2, n + 1): print(1, i)
9
PYTHON3
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using pll = pair<ll, ll>; using pii = pair<int, int>; const int MOD = 998244353; const int MAX = 2e5 + 5; const ll INF = 1e18 + 1; int DP[1005][2005][4] = {0}; int inc[4][4] = {{0, 1, 1, 1}, {0, 0, 2, 0}, {0, 2, 0, 0}, {1, 1, 1,...
10
CPP
bor = [0]*51 for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) ans = 0; for ves in range(2, 2*n+1): for j in range(n+1): bor[j] = 0 temp = 0 for x in a: if x >= ves: ...
9
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; long long a[n]; long long e = 0; long long o = 0; vector<long long> v1; vector<long long> v2; for (long long i = 0; i < n; i++) { cin >> a[i]; if (a[i] % 2 == 0) { e++; v1.push_back(a[i]); } else { ...
8
CPP
#include <bits/stdc++.h> #pragma comment(linker, "/stack:200000000") #pragma GCC optimize("Ofast", "unroll-loops", "omit-frame-pointer", "inline") #pragma GCC option("arch=native", "tune=native", "no-zero-upper") #pragma GCC target( \ "sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native,avx2") const int max_n =...
12
CPP
#include <bits/stdc++.h> using namespace std; using LL = long long; using Pii = pair<int, int>; namespace fastIO { bool IOerror = 0; inline char nc() { static char buf[100000], *p1 = buf + 100000, *pend = buf + 100000; if (p1 == pend) { p1 = buf; pend = buf + fread(buf, 1, 100000, stdin); if (pend == p1...
17
CPP
S = input() T = input() print(sum([s!=t for s, t in zip(S,T)]))
0
PYTHON3
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) best = max(a) first = a.index(best) if len(set(a)) == 1: print(-1) else: for i in range(first, n): if i == 0: if a[i] != a[i + 1]: print(i + 1) ...
9
PYTHON3
n, d = map(int, input().split()) for i in range(int(input())): x, y = map(int, input().split()) print('YES' if x+y in range(d, n + n - d + 1) and x-y in range(-d, d + 1) else 'NO');
8
PYTHON3
n = int(input()) hah = 0 S = [int(i) for i in input().split()] for i in range(n): if(S[i]== max(S)): p = i break for i in range(n-1, -1, -1): if(S[i]==min(S)): p += (n-i-1) break if(i == p): hah = 1 print(p - hah)
7
PYTHON3
n = int(input()) y = 0 x = 0 for i in range(n): dice1, dice2 = map(int, input().split()) if dice1 > dice2: y += 1 elif dice1 < dice2: x += 1 else: x += 0 if x < y: print('Mishka') if x > y: print('Chris')###CF703A ##n = int(input()) ##a = 0 ##b = 0 ##for i in range(n): ...
7
PYTHON3
n=int(input()) mas=[int(x) for x in input().split()] mas.reverse() if (mas[0]==0): print(len(mas)-mas.index(1)) else: print(len(mas)-mas.index(0))
7
PYTHON3
n = int(input()) # максимальное количество комнат x = 0 for i in range(1, n + 1): # создаем цикл для нахождения количества комнат, которые подойдут под условие p, q = map(int, input().split()) if p < q and q - p >= 2: x += 1 print(x)
7
PYTHON3
from collections import Counter n=int(input()) c=Counter(list(map(int,input().split()))) if c[1]<c[2]: print(c[1]) else: print((c[1]-c[2])//3+c[2])
7
PYTHON3
from collections import defaultdict n = int(input()) N = 100010 arr = [int(i) for i in input().split()] Dict = defaultdict(int) for i in arr: Dict[i] += 1 dp = [0]*N for i in range(1, N): if i-2 < 0: dp[i] = i*Dict[i] else: dp[i] = (i*Dict[i])+dp[i-2] dp[i] = max(dp[i], dp[i-1]) print(d...
9
PYTHON3
#include <bits/stdc++.h> const int INF = 10000000; int main() { int n; while (scanf("%d", &n) != EOF) { int x1, y1, x2, y2; long long s = 0; int minx = INF, maxx = -INF, miny = INF, maxy = -INF; for (int i = 0; i < n; ++i) { scanf("%d%d%d%d", &x1, &y1, &x2, &y2); if (x1 < minx) minx = x1...
7
CPP
#include<cstdio> #include<vector> int n; std::vector <int> ve; std::vector <int> ret; int main(){ #ifdef Ezio freopen("input","r",stdin); #endif scanf("%d",&n); for(int i=0,x;i<n;i++){ scanf("%d",&x); ve.push_back(x); } while(n){ int i; for(i=n-1;~i;i--) if(ve[i]==i+1){ ve.erase(ve.begin()+i); ...
0
CPP
t=int(input()) for i in range(t): n,m,x,y=map(int,input().split()) ans=0 for i in range(n): ar=input() j = 0; fl = 0; while (j < m): if (x * 2 > y and j>0 and ar[j]=='.' and fl == 1 and ar[j]==ar[j-1]): fl = 0 ...
8
PYTHON3
#include <bits/stdc++.h> using namespace std; int n, m, a[200005], pos[200005], mx[200005][19], lg[200005]; long long ans; int query(int x, int y) { int t = lg[y - x + 1]; return max(mx[x][t], mx[y - (1 << t) + 1][t]); } void solve(long long l, long long r) { if (r - l < 2) return; long long t = query(l, r), p ...
11
CPP
#include<iostream> #include<vector> using namespace std; int main(){ string s,t; for(;;){ cin >> s; cin >> t; if(t=="X")break; vector<string> v; int pos=0; while(pos<s.size()){ string tmp; if('A' <= s[pos] && s[pos]<='Z'){ tmp += (char)(s[pos] + 32); pos++; } w...
0
CPP
while True: try: num = int(input()) count = 0 for a in range(10): for b in range(10): for c in range(10): for d in range(10): if a+b+c+d==num: count+=1 print(int(count)) except: break
0
PYTHON3
R=lambda:map(int,input().split()) n,A,B,C,T=R() print(sum(A+max(0,C-B)*(T-t)for t in R())) # Made By Mostafa_Khaled
8
PYTHON3
#include <bits/stdc++.h> using namespace std; const int maxx = 1e6 + 100; string s; int vis[maxx]; int main() { while (cin >> s) { int len = s.length(); memset(vis, 0, sizeof(vis)); int l = 0; int r = len - 1; while (l <= r) { if (l == r) { vis[l] = 1; break; } if...
11
CPP
n=int(input()) s=input().split(" ") person=0 crime=0 for i in range(n): person+=int(s[i]) if person<0: person+=1 crime+=1 print(crime)
7
PYTHON3
#include <stdio.h> #include <iostream> #include <algorithm> #include <memory.h> using namespace std; typedef long long LL; const int maxn = 10005; const int mod = 998244353; int x,y,n;char a[maxn],b[maxn]; int fac[maxn],inc[maxn]; int dp[maxn][maxn],ans; LL comb(int n,int m) { return (LL)fac[n]*inc[m]%mod*(LL)inc[n...
0
CPP
#include <bits/stdc++.h> using namespace std; long long n, m, x, p[10005], s[10005], ans = 1000000000000000005; long long npong(long long n, long long p) { long long ans = 0; while (n > 0) { n /= p; ans += n; } return ans; } signed main() { scanf("%lld%lld", &n, &m); for (long long i = 2; i * i <= m...
9
CPP
#include <bits/stdc++.h> using namespace std; int i; string second; int main() { getline(cin, second); for (i = 0; i < second.length(); i++) if (second[i] == '1') { if (i + 1 < second.length()) if (second[i + 1] == '4') { i++; if (i + 1 < second.length()) if (second...
7
CPP
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; const int MAXN = 2e5 + 4; bool was[MAXN]; int a; int cnt(int len) { return (len + 1) / (a + 1); } set<pair<int, int> > st; void solve() { int n, k, m; cin >> n >> k >> a >> m; int sum = cnt(n); st.insert(make_pair(1, n)); int x; st.insert(ma...
10
CPP
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:1000000000") using namespace std; const int maxn = 1010; vector<int> ed[maxn]; int lnk[maxn]; bool used[maxn]; bool us[maxn]; bool dfs(int v) { if (us[v]) { return false; } us[v] = true; for (int i = 0; i < (int)ed[v].size(); i++) { int u = ed[v][...
12
CPP
#include <bits/stdc++.h> using namespace std; const int MAX = 100005; struct Node { int l, r, del, s; } t[MAX * 8]; struct node { int v, next; } g[MAX * 2]; int adj[MAX], l[MAX], r[MAX], e, n, m, level[MAX], idx, deg[MAX]; int E[MAX][2], tr[MAX * 2], st, f[MAX], cnt, id[MAX], h[MAX]; void add(int u, int v) { g[e]...
10
CPP
def solve(a, n, x): a.sort(reverse = True) cnt = 0 l = 0 for v in a: need = (x + v - 1) // v - 1 if l >= need: l -= need cnt += 1 else: l += 1 return cnt tests = int(input()) for test in range(tests): n, x = map(int, input().split()) a = list(map(int, input().split())) print(solve(a, n, x))
9
PYTHON3
num=int(input()) dicts={"Power":"purple","Time":"green","Space":"blue","Soul":"orange","Reality":"red","Mind":"yellow"} leng=len(dicts) index=0 while index<num: x=input() for i in dicts: if dicts[i]==x: x=i dicts.pop(x) index+=1 print(leng-num) for i in dicts: print(i)
7
PYTHON3
n = int(input()) a = list(map(int, input().split())) a.sort() ans = "NO" for i in range(2, n): if a[i-2] + a[i-1] > a[i]: ans = "YES" print(ans)
8
PYTHON3
a=input() w=["Sunny","Cloudy","Rainy","Sunny"] print(w[int(w.index(a))+1])
0
PYTHON3
word = str(input()) word1 = str(input()) word = word.lower() word1 = word1.lower() if word<word1: print(-1) elif word>word1: print(1) else: print(0)
7
PYTHON3
# a simple parser for python. use get_number() and get_word() to read def parser(): while 1: data = list(input().split(' ')) for number in data: if len(number) > 0: yield(number) input_parser = parser() def get_word(): global input_parser return next(input_pa...
7
PYTHON3
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; using vi = vector<int>; using vl = vector<ll>; const int MAXN = 2e5 + 5; const int INF = 0x3f3f3f3f; const int MOD = 1e9 + 7; void solve() { int t; cin >> t; while (t--) { string ans = ""; int n; cin >> n; ...
7
CPP
n, h = map(int, input().split()) print(sum([2 if int(x) > h else 1 for x in input().split()]))
7
PYTHON3
#include<bits/stdc++.h> using namespace std; int main() { int n,a[300],s=0; cin>>n; for(int i=1;i<=2*n;i++) cin>>a[i]; sort(a+1,a+2*n+1); for(int i=1;i<=2*n;i++) if(i%2==1) s+=a[i]; cout<<s<<endl; return 0; }
0
CPP
#include <bits/stdc++.h> using namespace std; #define ALL(x) (x).begin(), (x).end() #define AND(x,y,z) #define DUMP(xs) for (auto x:xs) cout<<x<<' ';cout<<endl #define DUMPP(xs) for (auto x:xs) cout<<'('<<x.first<<','<<x.second<<')';cout<<endl #define FOR(i,a,b) for (ll i=(ll)(a);i<(ll)(b);++i) #define OUT(x) cout<<...
0
CPP
#include <iostream> #include <algorithm> using namespace std; int main() { int n; cin >> n; int a[n],b[n]; for(int i=0;i<n;i++){ cin >> a[i]; b[i] = a[i]; } sort(b,b+n); for(int i=0;i<n;i++){ if(a[i]==b[n-1]) cout << b[n-2] << endl; else cout << b[n-1] << endl; } return 0; }
0
CPP
t = int(input()) if t == 200000: for i in range(t): n = int(input()) print(n, end='\n') else: for i in range(t): n = int(input()) guys = [int(i) for i in input().split()] guys.sort() groups, count = 0, 0 for j in range(n): count += 1 ...
8
PYTHON3
k, x = map(int, input().split()) print(["No", "Yes"][k * 500 >= x])
0
PYTHON3
import math for i in range(int(input())): n = int(input()) ans = 0 if n == 1: print(0) continue if n % 3 != 0: print(-1) continue while True: while n % 6 == 0: n /= 6 ans += 1 if n == 1 or n % 3 != 0: break ...
8
PYTHON3
#include<cstdio> #include<functional> #include<algorithm> #include<cstring> using namespace std; int main(void) { int h,w,x,y,a,b; scanf("%d %d %d %d",&h,&w,&x,&y); a=h*w; b=x+y; if(a%2==1 && b%2==1) printf("No\n"); else printf("Yes\n"); return 0; }
0
CPP
#include <bits/stdc++.h> using namespace std; const int INF = 1 << 30; const long long int MAX = 1e9 + 7; void array_show(int *array, int array_n, char middle = ' ') { for (int i = 0; i < array_n; i++) printf("%d%c", array[i], (i != array_n - 1 ? middle : '\n')); } void array_show(long long int *array, int array_...
12
CPP
#include <bits/stdc++.h> using namespace std; long long N, M, K; long long _C[110][110]; void init() { for (int i = 0; i < 110; ++i) { _C[i][0] = _C[i][i] = 1; for (int j = 1; j < i; ++j) { _C[i][j] = _C[i - 1][j] + _C[i - 1][j - 1]; if (_C[i][j] >= 1000000007) _C[i][j] -= 1000000007; } } } ...
10
CPP
one=input() two=input() three=input() one =''.join(sorted(one)) two=''.join(sorted(two)) three=''.join(sorted(three)) s=one+two s=''.join(sorted(s)) if s==three: print("YES") else: print("NO")
7
PYTHON3
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:256000000") using namespace std; long long mulmod(long long a, long long b, long long MOD) { if (b == 0) return 0; long long res = mulmod(a, b >> 1, MOD); res += res; res %= MOD; return (b & 1) ? (a + res) % MOD : res; } int main() { ios::sync_with_st...
8
CPP
#include <bits/stdc++.h> using namespace std; int main() { int cases, contador, estado; string word1, word2; cin >> cases; for (int j = 0; j < cases; j++) { contador = 0; estado = 0; cin >> word1; cin >> word2; if (word2[0] == word1[0]) { estado = 1; contador++; } if (est...
8
CPP
#include <bits/stdc++.h> using namespace std; int primes[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53}; int n; long long int ans = 1e18; map<long long int, bool> mp; void maxdiv(int* exp, int plc, int pas, long long int num) { if (pas == plc) plc++; exp[pas]++; num *= primes[pas]; if (num < 0...
11
CPP
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; int n, a[N], res; map<pair<int, int>, int> mp; void solve1() { for (int i = 0; i < n - 2; i++) { int k; for (int j = 29; j >= 0; j--) { if ((1 << j) & a[i]) { k = j; break; } } k++; long long sum = a[i...
11
CPP
#include <bits/stdc++.h> using namespace std; struct cmp { bool operator()(const long long &a, const long long &b) { return a >= b; } }; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n, k; cin >> n >> k; long long first = 0, second = 0, ans = 0; long long temp1 = 0, temp2 = 0, te...
11
CPP
#include<bits/stdc++.h> using namespace std; int p[105]; int x,n,t; int main(){ cin>>x>>n; for(int i=0;i<n;++i) { cin>>t; p[t]=1; } int min=1005,ans=0; for(int i=0;i<=101;++i) { if((!p[i])&&abs(i-x)<min) { min=abs(i-x); ans=i; } } cout<<ans<<"\n"; }
0
CPP
import math n, a, b =map(int, input().split()) arr = list(map(int, input().split())) results = [] for x in arr: rem = (x*a) % b k = math.floor(rem/a) results.append(k) print(" ".join(str(x) for x in results))
8
PYTHON3
T = int(input()) for _ in range(T): n = int(input()) print((n-1)//2)
7
PYTHON3
a,b,c=input().split();print(c,a,b)
0
PYTHON3
#include <bits/stdc++.h> using namespace std; const int N = 5000; int n, m; vector<int> g[N]; long long bpick[N]; long long dist(int i, int j) { if (i <= j) return j - i; else return n - (i - j); } int main() { cin >> n >> m; for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; a--, b--; ...
7
CPP
""" Problem from: http://codeforces.com/contest/405/problem/A A. Gravity Flip time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output Little Chris is bored during his physics lessons (too easy), so he has built a toy box to keep himself occupied. The box is special, sin...
7
PYTHON3
n=int(input()) s=input() freq={} for i in s: freq[i]=freq.get(i,0)+1 if freq.get('A',0)>freq.get('D',0):print('Anton') elif freq.get('A',0)<freq.get('D',0):print('Danik') else:print('Friendship')
7
PYTHON3
#include <bits/stdc++.h> using namespace std; namespace DINIC { const int MAXN = 1222; struct edg { int pos, cap, rev; }; vector<edg> gph[MAXN]; void clear() { for (int i = 0; i < MAXN; i++) gph[i].clear(); } void add_edge(int s, int e, int x) { gph[s].push_back({e, x, (int)gph[e].size()}); gph[e].push_back({s,...
15
CPP
n = int(input()) chall = input() flag = 0 for i in chall: if(i == '1'): flag = 1 break if(flag): print('HARD') else: print('EASY')
7
PYTHON3
n=int(input()) a=list(map(int,input().split())) t=1 p=a[0] m=0 for i in a: if(p==i): continue if(m>0): if(i<p): t+=1 m=0 elif(m<0): if(i>p): t+=1 m=0 else: if(i>p): m=1 elif(i<p): m=-1 p=i print(t)
0
PYTHON3
#include <bits/stdc++.h> using namespace std; int const N = 1e6 + 1; int md = 1e9 + 7; int i, j, n, m, t, x, y, k, nom, ans; int a[N], b[N]; int main() { long long s = 0; scanf("%d%d", &n, &k); for (int i = 1; i <= n; i++) { scanf("%d%d", &a[i], &b[i]); s += a[i]; } if (s <= k) { printf("-1"); ...
7
CPP
#include <bits/stdc++.h> using namespace std; long long int ll_max(long long int a, long long int b, long long int c) { return max(a, max(b, c)); } int int_max(int a, int b, int c) { return max(a, max(b, c)); } long long int ll_min(long long int a, long long int b, long long int c) { return min(a, min(b, c)); } int...
10
CPP
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx,avx,tune=native") #pragma GCC optimize("Ofast") #include <bits/stdc++.h> using namespace std; using ll = long long; int main(){ ll A,B,X;cin >> A >> B >> X; ll ans= 1e9; for(int i = 0;i <= 10000;i++){ for(int j = 0;j <= 10000;j++){ ...
0
CPP
#include <bits/stdc++.h> using namespace std; string s; const int maxn = 20; int d[maxn], p[maxn], f[maxn]; int best = -1, bestd = -1; int cur; string a = "", b = ""; int main() { getline(cin, s); for (int i = 0; i < (int)(s.size()); i++) { d[s[i] - '0']++; } for (int i = 1; i <= 5; i++) { for (int j = ...
8
CPP
#include<bits/stdc++.h> using namespace std; long long n, i, j, a[1<<18], b, c, d; int main(){ cin >> n; for(i=1;i<=n;++i){ cin >> a[i]; b += a[i]; } c = b; for(i=1; i<=n;++i){ d += a[i]; c = min(c, abs(d-(b-d))); } cout <<c; }
0
CPP
from collections import deque n, k = map(int, input().split()) id_list = list(map(int, input().split())) active_set = set() screen_q = deque() for id in id_list: if id not in active_set: active_set.add(id) if len(screen_q) == k: id_out = screen_q[-1] active_set.remove(id_...
8
PYTHON3
#include <bits/stdc++.h> using namespace std; long long seed, vmax; long long rnd() { long long res = seed; seed = (seed * 7 + 13) % 1000000007; return res; } long long n, m; long long a[1000001]; struct node { long long l, r; mutable long long val; node(long long _l = 0, long long _r = -1, long long _v = 0...
9
CPP
#include <stdio.h> int main(){ int a,b; scanf("%d%d",&a,&b); if(a+b==15)printf("+\n"); else if(a*b==15)printf("*\n"); else printf("x\n"); }
0
CPP
#include <bits/stdc++.h> using namespace std; int main() { int arr[4][4]; memset(arr, 0, sizeof(arr)); string str; cin >> str; int len = str.length(); for (int i = 0; i < len; i++) { if (str[i] == '0') { if (arr[0][2] == 0) { arr[0][2] = 1; cout << "3 1" << endl; } else { ...
9
CPP
n=list(input()) for i in range(0,len(n)): if(n[i]=='H' or n[i]=='Q' or n[i]=="9"): print("YES") exit() print("NO")
7
PYTHON3
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; const int mod = 1e9 + 7; long long int power(long long int x, long long int y) { long long int t = 1; while (y > 0) { if (y % 2) y -= 1, t = t * x % mod; else y /= 2, x = x * x % mod; } return t; } int main() { long l...
7
CPP
a=int(input()) letters=[] for i in list(input()): if ord(i)<91: letters.append(chr(ord(i)+32)) else: letters.append(i) check = set(letters) if len(check)<26: print('NO') else: print('YES')
7
PYTHON3
import sys def solve(): mod = 1000 * 1000 * 1000 + 7 n, = rv() a, = rl(1) mem = [0] * n timesofar = 0 for i in range(n): ariveat = a[i] - 1 moresum = 0 for j in range(ariveat, i): moresum += mem[j] mem[i] = moresum + 2 timesofar += moresum + 2...
10
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { string a = "", aux; for (int i = 1; i <= 1001; i++) { stringstream ss; ss << i; ss >> aux; a += aux; } int n; cin >> n; n--; cout << a[n] << endl; return 0; }
7
CPP
#include <bits/stdc++.h> using namespace std; void printP(vector<int>& a) { reverse(a.begin(), a.end()); cout << (int)a.size() - 1 << "\n"; for (int o : a) cout << o << " "; cout << "\n"; } int main() { std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout << std::setprecision(9); int N; scanf(...
8
CPP
#include <bits/stdc++.h> using namespace std; const int maxn = 100000 + 5; int p[maxn], g[maxn], t[maxn]; int n, w, h; const int offset = 100000 + 5; vector<int> point[offset * 4]; set<int> Valid; bool cmp(int A, int B) { if (g[A] != g[B]) return g[A] == 2; else return g[A] == 2 ? p[A] > p[B] : p[A] < p[B];...
10
CPP