_id
stringlengths
2
5
partition
stringclasses
2 values
text
stringlengths
5
289k
language
stringclasses
1 value
meta_information
dict
title
stringclasses
1 value
d8301
test
a = input() atcg =["A","T","C","G"] result =[] res= 0 for i in a: if i in atcg: res +=1 else: res = 0 result.append(res) print(max(result))
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc122/tasks/abc122_b" }
d8302
test
n=input() count=0 for i in range(1,int(n)+1): l=len(str(i)) if l%2!=0: count+=1 print(count)
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc136/tasks/abc136_b" }
d8303
test
S = input() T = input() tigau = 0 for i in range(len(S)): if S[i] != T[i]: tigau += 1 print(tigau)
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc172/tasks/abc172_b" }
d8304
test
K, X = map(int, input().split()) lists = [X] for i in range(1, K): if X + i <= 1000000: lists.append(X + i) if X - i >= -1000000: lists.append(X - i) lists.sort() print(*lists)
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc137/tasks/abc137_b" }
d8305
test
X = int(input()) if X >= 30: print("Yes") else: print("No")
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc174/tasks/abc174_a" }
d8306
test
import math n , d = list(map(int, input().split())) x = [list(map(int, input().split())) for _ in range(n)] cnt = 0 sum_tmp = 0 for i in range(n): for j in range(i+1, n): for h in range(d): sum_tmp += (x[i][h] - x[j][h]) ** 2 if math.sqrt(sum_tmp).is_integer(): cnt += 1 sum_tmp = 0 print(cnt)
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc133/tasks/abc133_b" }
d8307
test
s = input('') # Sが入力しづらければBad,そうでなければGood if s[0] == s[1] or s[1] == s[2] or s[2] == s[3]: print('Bad') else: print('Good')
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc131/tasks/abc131_a" }
d8308
test
N = int(input()) v = sorted(map(int, input().split())) tmp = v[0] for i in range(1,N): tmp = (tmp+v[i])/2.0 print(tmp)
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc138/tasks/abc138_c" }
d8309
test
N = int(input()) A = [int(i) for i in input().split()] B = [int(i) for i in input().split()] C = [int(i) for i in input().split()] ans = 0 for i in range(N): ans += B[A[i]-1] if(A[i] == A[i-1]+1 and i != 0): ans += C[A[i]-2] print(ans)
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc140/tasks/abc140_b" }
d8310
test
_ = input() S = input() print((S.count("ABC")))
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc150/tasks/abc150_b" }
d8311
test
#!/usr/bin/env python3 import itertools n = int(input()) data = [[] for i in range(5)] # print(data) for i in range(n): tmp = str(input()) if tmp[0] == "M": data[0].append(tmp) elif tmp[0] == "A": data[1].append(tmp) elif tmp[0] == "R": data[2].append(tmp) elif tmp[0] == "C": data[3].append(tmp) elif tmp[0] == "H": data[4].append(tmp) ans = 0 for i, j, k in itertools.combinations([0, 1, 2, 3, 4], 3): ans += len(data[i])*len(data[j])*len(data[k]) print(ans)
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc089/tasks/abc089_c" }
d8312
test
n,m=map(int,input().split()) if n==m: print("Yes") else: print("No")
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc152/tasks/abc152_a" }
d8313
test
S=input() if S[2]==S[3] and S[4]==S[5]: print("Yes") else: print("No")
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc160/tasks/abc160_a" }
d8314
test
n, t = map(int, input().split()) a = [list(map(int, input().split())) for i in range(n)] l = [] flag = False for i in range(n): if a[i][1] <= t: l.append(a[i][0]) flag = True if flag: print(min(l)) else: print('TLE')
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc112/tasks/abc112_b" }
d8315
test
n,a,b = map(int,input().split()) print(n*a if n*a < b else b)
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc133/tasks/abc133_a" }
d8316
test
from collections import defaultdict n = int(input()) s_dict = defaultdict(int) for i in range(n): s_int = [0] * 26 s = list(input()) for si in s: s_int[ord(si) - ord('a')] += 1 cnt = 0 for s_int_i in s_int: cnt *= 10 cnt += s_int_i s_dict[cnt] += 1 ans = 0 for key in s_dict: ans += s_dict[key] * (s_dict[key] - 1) / 2 print(int(ans))
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc137/tasks/abc137_c" }
d8317
test
l = [0] def count(size): nums = (10**size - 10**(size - 1)) small = l[size-1] + size large = l[size-1] + nums * size if len(l) <= size: l.append(large) return (nums * (small + large))//2 def test(minSize, size, val): out = minSize * val + size * ((val + 1) * val)//2 return out q = int(input()) for _ in range(q): want = int(input()) size = 1 while want > count(size): want -= count(size) size += 1 minSize = l[size - 1] lo = 0 #Impossible hi = (10**size - 10**(size - 1)) #Possible while hi - lo > 1: testV = (lo + hi) // 2 out = test(minSize, size, testV) if out < want: lo = testV else: hi = testV want -= test(minSize, size, lo) newS = 1 while 9 * (10**(newS - 1)) * newS < want: want -= 9 * (10**(newS - 1)) * newS newS += 1 want -= 1 more = want//newS dig = want % newS value = 10**(newS - 1) + more print(str(value)[dig])
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/1216/E1" }
d8318
test
import sys input = sys.stdin.readline n,k=list(map(int,input().split())) R=[list(map(int,input().split())) for i in range(n-1)] RDICT={tuple(sorted([R[i][0],R[i][1]])):i for i in range(n-1)} C=[[] for i in range(n+1)] for x,y in R: C[x].append(y) C[y].append(x) CLEN=[] for i in range(1,n+1): CLEN.append(len(C[i])) from collections import Counter counter=Counter(CLEN) CV=sorted(list(counter.keys()),reverse=True) cvsum=0 cities=1 for cv in CV: cvsum+=counter[cv] if cvsum>k: cities=cv break print(cities) ANS=[0]*(n-1) from collections import deque QUE = deque() QUE.append([1,1]) VISITED=[0]*(n+1) while QUE: city,roadnum=QUE.pop() VISITED[city]=1 for to in C[city]: if VISITED[to]==0: ANS[RDICT[tuple(sorted([city,to]))]]=roadnum roadnum=roadnum%cities+1 QUE.append([to,roadnum]) print(*ANS)
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/1141/G" }
d8319
test
n=int(input()) a=list(map(int,input().split())) a.sort() prev=-2 c=0 for i in a: dif=i-prev if dif > 1: prev=i+1 c+=1 ac=0 lc=-2 for i in a: if lc < i-1: lc=i-1 ac+=1 elif lc == i-1: lc=i ac+=1 elif lc == i: lc=i+1 ac+=1 print(c,ac)
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/1283/E" }
d8320
test
n = int(input()) A = [-1] ans = [1] for i in range(n): A.append(tuple(map(int, input().split()))) a = A[1][0] b = A[1][1] c = A[a][0] d = A[a][1] if b == c or b == d: ans.append(a) ans.append(b) else: ans.append(b) ans.append(a) while len(ans) != n: p = A[ans[-2]] if p[0] == ans[-1]: ans.append(p[1]) else: ans.append(p[0]) for i in ans: print(i, end=' ')
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/1095/D" }
d8321
test
n = int(input()) A = list(map(int, input().split())) A.sort() i = 0 j = 0 ans = 0 while j < len(A): ans = max(ans, j - i) if i == j or A[j] - A[i] <= 5: j += 1 else: i += 1 print(max(ans, j - i))
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/1133/C" }
d8322
test
q = int(input()) for query in range(q): k, n, a, b = list(map(int,input().split())) if n * b > k: print(-1) else: print(min(n, (k-n*b-1)//(a-b)))
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/1183/C" }
d8323
test
def num(s): ans1 = [0]*n for q in range(n): ans1[q] = s[q] == 'a' sum1 = 0 for q in range(n): w = sum1*(s[q] == 'b') sum1 += ans1[q] ans1[q] = w sum1 = 0 for q in range(n): w = sum1*(s[q] == 'c') sum1 += ans1[q] ans1[q] = w sum1 = 0 for q in range(n): sum1 += ans1[q] return sum1 % C n = int(input()) s = list(input()) C, k = 10**9+7, 0 ans, ans1, deg = [0]*n, [0]*n, [1] for q in range(n): deg.append(deg[-1]*3 % C) k += s[q] == '?' if k == 0: print(num(s)) elif k == 1: ans = 0 for q in range(n): if s[q] == '?': for q1 in ['a', 'b', 'c']: s[q] = q1 ans += num(s) break print(ans % C) elif k == 2: ans = 0 ind1 = ind2 = -1 for q in range(n): if s[q] == '?' and ind1 == -1: ind1 = q elif s[q] == '?': ind2 = q for q in ['aa', 'ab', 'ac', 'ba', 'bb', 'bc', 'ca', 'cb', 'cc']: s[ind1], s[ind2] = q[0], q[1] ans += num(s) print(ans % C) else: ans = 0 for q1 in ['???', '??c', '?b?', '?bc', 'a??', 'a?c', 'ab?', 'abc']: t = q1.count('?') ans1 = [0] * n for q in range(n): ans1[q] = (s[q] == q1[0])*deg[k-t] sum1 = 0 for q in range(n): w = sum1 * (s[q] == q1[1]) sum1 += ans1[q] ans1[q] = w % C sum1 = 0 for q in range(n): w = sum1 * (s[q] == q1[2]) sum1 += ans1[q] ans1[q] = w % C sum1 = 0 for q in range(n): sum1 += ans1[q] ans += sum1 print(ans % C)
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/1426/F" }
d8324
test
import sys input = sys.stdin.readline n,m=list(map(int,input().split())) A=list(map(int,input().split())) SP=[list(map(int,input().split())) for i in range(m)] MIN=min(A) x=A.index(MIN) EDGE_x=[[x+1,i+1,A[x]+A[i]] for i in range(n) if x!=i] EDGE=EDGE_x+SP EDGE.sort(key=lambda x:x[2]) #UnionFind Group=[i for i in range(n+1)] def find(x): while Group[x] != x: x=Group[x] return x def Union(x,y): if find(x) != find(y): Group[find(y)]=Group[find(x)]=min(find(y),find(x)) ANS=0 for i,j,x in EDGE: if find(i)!=find(j): ANS+=x Union(i,j) print(ANS)
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/1095/F" }
d8325
test
import sys a,m,n=list(map(int,input().split())) aux=[0]*(a+1) inf=10**15 dp=[aux.copy() for i in range(n+1)] m1=10**12 m2=10**12 for i in range(m): l,r=list(map(int,input().split())) if l<m1: m1=l for j in range(l,r): dp[0][j+1]=inf s=[] for i in range(1,n+1): x,w=list(map(int,input().split())) s.append(tuple([x,w])) if x<m2: m2=x if m2>m1: print(-1) return s.sort() for i in range(1,n+1): x=s[i-1][0] w=s[i-1][1] for j in range(x+1): dp[i][j]=dp[i-1][j] for j in range(x+1,a+1): if i!=1: dp[i][j]=min(dp[0][j]+dp[i][j-1],dp[i-1][j],w*(j-x)+dp[i][x]) else: dp[i][j]=min(dp[0][j]+dp[i][j-1],w*(j-x)+dp[i][x]) ans=dp[-1][-1] if ans>=inf: print(-1) else: print(ans)
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/988/F" }
d8326
test
from collections import Counter c=Counter(list(map(int,input().split()))) if len(c)==2:print('Yes') else:print('No')
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc155/tasks/abc155_a" }
d8327
test
N = int(input()) T, A = map(int, input().split()) H = list(map(int, input().split())) high = [] abso = [] for i in range(N): high.append(T - (H[i] * 0.006)) n = 0 while n <= N - 1: abso.append(abs(A - high[n])) n += 1 answer = abso.index(min(abso)) + 1 print(answer)
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc113/tasks/abc113_b" }
d8328
test
x,y = list(map(int,input().split())) print((int((x * (x-1)) / 2 + (y * (y - 1))/2)))
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc159/tasks/abc159_a" }
d8329
test
def main(): N, Q = map(int,input().split()) S = str(input()) sum_array = [0] * 100000 i = 0 while i < len(S): if S[i] == 'A' and ((i + 1) < len(S)) and S[i + 1] == 'C': sum_array[i] = 1 i += 2 else: i += 1 sum = 0 for i in range(N): sum += sum_array[i] sum_array[i] = sum #print("") #print(sum_array) ans_array = [0] * Q for q in range(Q): l, r = map(int,input().split()) l_sum = sum_array[l-1] if l == 1: l_sum = 0 elif sum_array[l-2] != l_sum: l_sum = sum_array[l-2] r_sum = sum_array[r-1] if sum_array[r-2] != r_sum: r_sum = sum_array[r-2] ans_array[q] = r_sum - l_sum for ans in ans_array: print(ans) def __starting_point(): main() __starting_point()
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc122/tasks/abc122_c" }
d8330
test
n = [ int(i) for i in input().split() ] p = [ int(i) for i in input().split() ] p = sorted(p) val = sum( p[:n[1]] ) print(val)
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc171/tasks/abc171_b" }
d8331
test
print((sum(sorted(list(map(int,input().split())))[0:2])))
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc129/tasks/abc129_a" }
d8332
test
x,a = map(int,input().split()) print(0 if x < a else 10)
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc130/tasks/abc130_a" }
d8333
test
n,k=map(int,input().split()) print(min(n%k,k-n%k))
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc161/tasks/abc161_c" }
d8334
test
a, b, c = map(int, input().split()) if a+b+c >= 22: print('bust') else: print('win')
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc147/tasks/abc147_a" }
d8335
test
n = int(input()) print((n if n%2==0 else n*2))
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc102/tasks/abc102_a" }
d8336
test
N,D=list(map(int,input().split())) print(((N-1)//(2*D+1)+1))
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc134/tasks/abc134_b" }
d8337
test
n=int(input())%10 if n==2 or n==4 or n==5 or n==7 or n==9: print("hon") if n==0 or n==1 or n==6 or n==8: print("pon") if n==3: print("bon")
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc168/tasks/abc168_a" }
d8338
test
import itertools n = int(input()) Tako = list(map(int, input().split())) ans = 0 for x,y in itertools.combinations(Tako,2): ans += x*y print(ans)
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc143/tasks/abc143_b" }
d8339
test
import copy n = int(input()) a = [] for i in range(n): s = int(input()) a.append(s) b = copy.copy(a) a.sort(reverse=True) c = b.index(a[0]) for j in b: if j == b[c]: print(a[1]) else: print(a[0])
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc134/tasks/abc134_c" }
d8340
test
a, b = map(int, input().split()) print(max(a+a-1, a+b, b+b-1))
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc124/tasks/abc124_a" }
d8341
test
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 MOD = 1000000007 def main(): N, K, *X = list(map(int, read().split())) A = [abs(x - X[0]) for x in X] ans = INF for i in range(N - K + 1): if ans > min(abs(X[i]), abs(X[i + K - 1])) + A[i + K - 1] - A[i]: ans = min(abs(X[i]), abs(X[i + K - 1])) + A[i + K - 1] - A[i] print(ans) return def __starting_point(): main() __starting_point()
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc107/tasks/arc101_a" }
d8342
test
a,b = map(int, input().split()) print((((b-a)**2)-(a+b))//2)
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc099/tasks/abc099_b" }
d8343
test
import math H,A = list(map(int,input().split())) print((math.ceil(H/A)))
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc153/tasks/abc153_a" }
d8344
test
a, b, c, d = list(map(int, input().split())) s = max(a, c) e = min(b, d) print((e - s if e-s > 0 else 0))
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc070/tasks/abc070_b" }
d8345
test
N = int(input()) if N >= 105: if N >= 135: if N >= 165: if N >= 189: if N >= 195: print((5)) else: print((4)) else: print((3)) else: print((2)) else: print((1)) else: print((0))
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc106/tasks/abc106_b" }
d8346
test
n, k = map(int, input().split()) print(int(n % k != 0))
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc105/tasks/abc105_a" }
d8347
test
N = int(input()) list_ = [111,222,333,444,555,666,777,888,999] for i in list_: if i >= N: print(i) return
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc111/tasks/abc111_b" }
d8348
test
A=list(map(int,input().split())) A.sort(reverse=True) print((A[0]-A[2]))
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc103/tasks/abc103_a" }
d8349
test
from collections import defaultdict d = defaultdict(bool) n = int(input()) for i in range(1000000): if d[n]: print((i + 1)) return d[n] = True if n & 1: n = n * 3 + 1 else: n >>= 1
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc116/tasks/abc116_b" }
d8350
test
A,B,C,D=map(int,input().split());print("YNeos"[(A+D-1)//D<(C+B-1)//B::2])
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc164/tasks/abc164_b" }
d8351
test
n = int(input()) vlst = list(map(int, input().split())) clst = list(map(int, input().split())) ans = 0 for v, c in zip(vlst, clst): ans += max(0, v - c) print(ans)
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc125/tasks/abc125_b" }
d8352
test
h,w = map(int, input().split()) cell = [] for i in range(h): row = list(input()) if row != ["."]*w: cell.append(row) counter = [] for i in range(w): flag = 0 for j in range(len(cell)): if cell[j][i] == "#": flag = 1 break if flag == 1: counter.append(i) for a in cell: ans = '' for i in counter: ans = ans + a[i] print(ans)
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc107/tasks/abc107_b" }
d8353
test
R=int(input()) print(R*2*3.141592)
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc163/tasks/abc163_a" }
d8354
test
s = input() if len(set(s)) == 2 and s.count(s[0]) == 2 : print('Yes') else : print('No')
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc132/tasks/abc132_a" }
d8355
test
A,B=map(int,input().split()) print(max(A+B,A-B,A*B))
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc137/tasks/abc137_a" }
d8356
test
N = int(input()) H = list(map(int,input().split())) top = H[0] cnt = 1 for i in range(1,N): if top <= H[i]: cnt += 1 top = H[i] print(cnt)
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc124/tasks/abc124_b" }
d8357
test
n = int(input()) a = list(map(int, input().split())) o = [] cur = 0 for x in a: if x == 1: if cur > 0: o.append(cur) cur = 1 else: cur += 1 o.append(cur) print(len(o)) print(' '.join(str(x) for x in o))
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/1005/A" }
d8358
test
from math import * test = int(input()) for test_case in range(test): n = int(input()) ct = 3 p = 2 while(1): if(n%ct == 0): print(n//ct) break p *= 2 ct += p
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/1343/A" }
d8359
test
n, k = list(map(int, input().split())) for i in range(k): if n%10==0: n //= 10 else: n -= 1 print(n)
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/977/A" }
d8360
test
# AC import sys class Main: def __init__(self): self.buff = None self.index = 0 def __next__(self): if self.buff is None or self.index == len(self.buff): self.buff = self.next_line() self.index = 0 val = self.buff[self.index] self.index += 1 return val def next_line(self, _map=str): return list(map(_map, sys.stdin.readline().split())) def next_int(self): return int(next(self)) def solve(self): n = self.next_int() x = sorted([self.next_int() for _ in range(0, n)]) ml = -1 _i = 0 _j = 0 j = 0 for i in range(0, n): j = max(j, i) while j + 1 < n and x[j + 1] == x[i]: j += 1 while j + 2 < n and x[j + 2] == x[j] + 1: j += 2 while j + 1 < n and x[j + 1] == x[j]: j += 1 jj = j if j + 1 < n and x[j + 1] == x[j] + 1: jj += 1 if jj - i > ml: ml = jj - i _i = i _j = jj a = [] b = [] i = _i while i <= _j: a.append(x[i]) i += 1 while i <= _j and x[i] == a[-1]: b.append(x[i]) i += 1 print(ml + 1) print(' '.join([str(x) for x in (a + b[::-1])])) def __starting_point(): Main().solve() __starting_point()
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/1157/F" }
d8361
test
# import collections, atexit, math, sys from functools import cmp_to_key #key=cmp_to_key(lambda x,y: 1 if x not in y else -1 ) sys.setrecursionlimit(1000000) def getIntList(): return list(map(int, input().split())) import bisect try : #raise ModuleNotFoundError import numpy def dprint(*args, **kwargs): print(*args, **kwargs, file=sys.stderr) dprint('debug mode') except ModuleNotFoundError: def dprint(*args, **kwargs): pass def memo(func): cache={} def wrap(*args): if args not in cache: cache[args]=func(*args) return cache[args] return wrap @memo def comb (n,k): if k==0: return 1 if n==k: return 1 return comb(n-1,k-1) + comb(n-1,k) inId = 0 outId = 0 if inId>0: dprint('use input', inId) sys.stdin = open('input'+ str(inId) + '.txt', 'r') #标准输出重定向至文件 if outId>0: dprint('use output', outId) sys.stdout = open('stdout'+ str(outId) + '.txt', 'w') #标准输出重定向至文件 atexit.register(lambda :sys.stdout.close()) #idle 中不会执行 atexit N, M = getIntList() total = 0 zz = [0 for i in range(N)] for i in range(N): a,b = getIntList() total+=a zz[i] = a-b zz.sort(reverse = True) if total <= M: print(0) return for i in range(N): total -= zz[i] if total <= M: print(i+1) return print(-1)
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/1015/C" }
d8362
test
TC = int(input()) while TC > 0: n, a, b = list(map(int, input().split())) ans = "" for i in range(b): ans += chr(ord('a') + i) ans = ans * n print(ans[:n]) TC -= 1
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/1335/B" }
d8363
test
n, x, t = list(map(int, input().split())) ans = 0 while n > 0: ans += t n -= x print(ans)
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc176/tasks/abc176_a" }
d8364
test
#!/usr/bin/env python3 n = int(input()) print((n//3))
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc089/tasks/abc089_a" }
d8365
test
a,p = map(int,input().split()) A = a*3 + p print(A//2)
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc128/tasks/abc128_a" }
d8366
test
a,b = map(int, input().split()) print(a+b if b%a==0 else b-a)
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc118/tasks/abc118_a" }
d8367
test
print('YNeos'[input()+(T:=input())[-1]!=T::2])
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc167/tasks/abc167_a" }
d8368
test
A, B = map(int, input().split()) if (A+B) %2 == 0: print((A+B) // 2) else: print('IMPOSSIBLE')
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc135/tasks/abc135_a" }
d8369
test
N=int(input()) X=N%10 y=N//10 Y=y%10 Z=N//100 if X==7 or Y==7 or Z==7: print("Yes") else: print("No")
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc162/tasks/abc162_a" }
d8370
test
def S(n): c = 0 for i in range(len(n)): c += int(n[i]) return c N = input() if int(N) % S(N) == 0: print('Yes') else: print('No')
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc101/tasks/abc101_b" }
d8371
test
x1, y1, x2, y2 = map(int, input().split()) print(x2-(y2-y1), y2+(x2-x1), x1-(y2-y1), y1+(x2-x1))
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc108/tasks/abc108_b" }
d8372
test
s,t = input().split() a,b = map(int,input().split()) u = input() if u == s : print(a-1,b) else : print(a,b-1)
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc154/tasks/abc154_a" }
d8373
test
n = int(input()) s = list(input()) m = n//2 if n%2 != 0: ans = "No" else: for i in range(m): if s[i] != s[m+i]: ans = "No" break ans = "Yes" print(ans)
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc145/tasks/abc145_b" }
d8374
test
# -*- coding: utf-8 -*- """ Created on Sat Sep 12 11:04:24 2020 @author: liang """ W, H, x, y = map(int, input().split()) ans = [0] * 2 ans[0] = H*W/2 if x == W/2 and y == H/2: ans[1] = 1 else: ans[1] = 0 print(" ".join(map(str, ans)))
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc130/tasks/abc130_c" }
d8375
test
import collections n = int(input()) li = list(input().split()) c = collections.Counter(li) if len(c) == 3: print('Three') else: print('Four')
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc089/tasks/abc089_b" }
d8376
test
from sys import stdin, stdout from math import sin, tan, cos, pi, atan2, sqrt, acos, atan, factorial from random import randint n, x, y = map(int, stdin.readline().split()) values = list(map(int, stdin.readline().split())) if x > y: stdout.write(str(n)) else: v = sum(map(lambda v: int(v <= x), values)) stdout.write(str(v // 2 + (v & 1)))
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/1102/C" }
d8377
test
def main(): import sys from bisect import bisect_left input = sys.stdin.readline N = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) C = [a-b for a, b in zip(A, B)] C.sort() ans = 0 for i, c in enumerate(C): j = bisect_left(C, -c+1) ans += N-j if c > 0: ans -= 1 print(ans // 2) def __starting_point(): main() __starting_point()
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/1324/D" }
d8378
test
n = int(input()) a = [int(x) for x in input().split()] print(*[x - ((x ^ 1) & 1) for x in a])
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/1006/A" }
d8379
test
def connected_components(neighbors): seen = set() def component(node): nodes = set([node]) while nodes: node = nodes.pop() seen.add(node) nodes |= neighbors[node] - seen yield node for node in neighbors: if node not in seen: yield component(node) from collections import defaultdict graph = defaultdict(set) n,m = map(int,input().split()) for _ in range(m): u,v = map(int,input().split()) graph[u].add(v) graph[v].add(u) total = 0 for component in connected_components(graph): nodes = list(component) size = len(nodes) seen = set() current = nodes[0] while len(seen) < size: choice = list(graph[current]) if len(choice) != 2:break seen.add(current) possible = [c for c in choice if c not in seen] if not possible: break current = possible[0] if len(seen) == size: total+=1 print (total)
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/977/E" }
d8380
test
import sys n = int(input()) a = [int(t) for t in input().split(' ')] mx = [[] for _ in range(n)] lines = sys.stdin.readlines() for i in range(n-1): v1, v2 = (int(t) - 1 for t in lines[i].split(' ')) mx[v1].append(v2) mx[v2].append(v1) count = [[0, 0] for _ in range(n)] total = [a.count(1), a.count(2)] answer = 0 OBSERVE = 0 CHECK = 1 stack = [(OBSERVE, 0, -1)] while len(stack): state, v, from_ = stack.pop() if state == OBSERVE: stack.append((CHECK, v, from_)) for nv in mx[v]: if nv != from_: stack.append((OBSERVE, nv, v)) else: for nv in mx[v]: if nv != from_: if count[nv][0] == total[0] and count[nv][1] == 0 or count[nv][1] == total[1] and count[nv][0] == 0: answer += 1 count[v][0] += count[nv][0] count[v][1] += count[nv][1] if a[v] != 0: count[v][a[v]-1] += 1 print(answer)
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/1118/F1" }
d8381
test
k = int(input()) a = reversed(input()) b = reversed(input()) aa = [0] * (k + 1) bb = [0] * (k + 1) for i, x in enumerate(a): aa[i] = ord(x) - 97 for i, x in enumerate(b): bb[i] = ord(x) - 97 carry = 0 cc = [0] * (k + 1) for i in range(k + 1): cc[i] = aa[i] + bb[i] + carry if cc[i] >= 26: carry = 1 cc[i] -= 26 else: carry = 0 carry = 0 for i in reversed(list(range(k+1))): value = carry * 26 + cc[i] carry = value % 2 cc[i] = value // 2 answer = "" for x in reversed(cc[:-1]): answer += chr(x + 97) print(answer)
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/1144/E" }
d8382
test
n, k = list(map(int, input().split())) a = list(map(int, input().split())) uniq = [] seen = set() for i, x in enumerate(a): if x not in seen: seen.add(x) uniq.append((i + 1, x)) if len(uniq) < k: print('NO') else: print('YES') b = [str(i) for i, _ in uniq[:k]] print(' '.join(b))
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/988/A" }
d8383
test
n = int(input()) a = list(map(int, input().split())) inf = 10 ** 6 inc = [inf for i in range(0, n + 1)] dec = [-inf for i in range(0, n + 1)] trinc = [-1 for i in range(0, n + 1)] trdec = [-1 for i in range(0, n + 1)] inc[0] = -inf dec[0] = inf #inc means last dec was in i and we want minimize last inc for i in range(0, n - 1): if a[i + 1] < a[i]: if inc[i + 1] > inc[i]: inc[i + 1] = inc[i] trinc[i + 1] = 1 if a[i + 1] > a[i]: if dec[i + 1] < dec[i]: dec[i + 1] = dec[i] trdec[i + 1] = 1 if a[i + 1] > inc[i]: if dec[i + 1] < a[i]: dec[i + 1] = a[i] trdec[i + 1] = 0 if a[i + 1] < dec[i]: if inc[i + 1] > a[i]: inc[i + 1] = a[i] trinc[i + 1] = 0 if inc[n - 1] == inf and dec[n - 1] == -inf: print("NO") return now_inc = False ans = [0 for i in range(0, n)] if inc[n - 1] != inf: now_inc = True for i in range(n - 1, -1, -1): if now_inc: ans[i] = 1 if trinc[i] == 0: now_inc = False else: ans[i] = 0 if trdec[i] == 0: now_inc = True print("YES") print(" ".join(str(x) for x in ans))
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/1144/G" }
d8384
test
t = int(input()) for i in range(t): d,v,l,r = list(map(int, input().split())) ans = d // v ans -= r//v - (l-1)//v print(ans)
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/1066/A" }
d8385
test
from math import * n = int(input()) print(factorial(n) // (factorial(n // 2) ** 2) * factorial(n//2-1) ** 2 // 2)
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/1433/E" }
d8386
test
from collections import Counter, defaultdict from string import ascii_lowercase as al n, k = list(map(int, input().split())) s = list(input()) C = defaultdict(int, Counter(s)) C_ = defaultdict(int) k_ = k for char in al: temp = min(C[char], k_) C_[char] += temp k_ -= temp for i, el in enumerate(s): if C_[el] > 0: s[i] = '' C_[el] -= 1 print(''.join(s))
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/999/C" }
d8387
test
import collections def main(): from sys import stdin, stdout def read(): return stdin.readline().rstrip('\n') def read_array(sep=None, maxsplit=-1): return read().split(sep, maxsplit) def read_int(): return int(read()) def read_int_array(sep=None, maxsplit=-1): return [int(a) for a in read_array(sep, maxsplit)] def write(*args, **kwargs): sep = kwargs.get('sep', ' ') end = kwargs.get('end', '\n') stdout.write(sep.join(str(a) for a in args) + end) def write_array(array, **kwargs): sep = kwargs.get('sep', ' ') end = kwargs.get('end', '\n') stdout.write(sep.join(str(a) for a in array) + end) def enough(days): bought = [] # (type, amount) bought_total = 0 used_from = days for d in range(days, 0, -1): used_from = min(d, used_from) for t in offers.get(d, []): if K[t] > 0: x = min(K[t], used_from) K[t] -= x bought.append((t, x)) bought_total += x used_from -= x if not used_from: break remaining_money = days - bought_total ans = (total_transaction - bought_total) * 2 <= remaining_money for t, a in bought: K[t] += a return ans n, m = read_int_array() K = read_int_array() total_transaction = sum(K) offers = collections.defaultdict(list) for _ in range(m): d, t = read_int_array() offers[d].append(t-1) low = total_transaction high = low * 2 ans = high while low <= high: mid = (low + high) // 2 if enough(mid): ans = mid high = mid - 1 else: low = mid + 1 write(ans) main()
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/1165/F2" }
d8388
test
n,m=map(int,input().split()) g=[[*input()] for _ in range(n)] c=[[0 for _ in range(m)] for _ in range(n)] for i in range(n): v=0 for j in range(m): v=(v+1)*(g[i][j]=='*') c[i][j]=v v=0 for j in range(m-1,-1,-1): v=(v+1)*(g[i][j]=='*') c[i][j]=min(c[i][j],v) for j in range(m): v=0 for i in range(n): v=(v+1)*(g[i][j]=='*') c[i][j]=min(c[i][j],v) v=0 for i in range(n-1,-1,-1): v=(v+1)*(g[i][j]=='*') c[i][j]=min(c[i][j],v) for i in range(n): for j in range(m): if c[i][j]==1: c[i][j]=0 for i in range(n): v=0 for j in range(m): v=max(v-1,c[i][j]) if v:g[i][j]='.' v=0 for j in range(m-1,-1,-1): v=max(v-1,c[i][j]) if v:g[i][j]='.' for j in range(m): v=0 for i in range(n): v=max(v-1,c[i][j]) if v:g[i][j]='.' for i in range(n-1,-1,-1): v=max(v-1,c[i][j]) if v:g[i][j]='.' if all(g[i][j]=='.' for i in range(n) for j in range(m)): r=[(i+1,j+1,c[i][j]-1) for i in range(n) for j in range(m) if c[i][j]] print(len(r)) for t in r: print(*t) else: print(-1)
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/1015/E2" }
d8389
test
A,B,C=map(int,input()) if A==C: print('Yes') else: print('No')
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc070/tasks/abc070_a" }
d8390
test
a,b = map(int, input().split()) if a == b: print("Draw") elif a == 1 or (a > b and b != 1): print("Alice") else: print("Bob")
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc054/tasks/abc054_a" }
d8391
test
print(' '.join(input().split(',')))
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc051/tasks/abc051_a" }
d8392
test
n,m=list(map(int,input().split())) ab=[[int(x) for x in input().split()] for _ in range(n)] cd=[[int(x) for x in input().split()] for _ in range(m)] for a,b in ab: ans=list() for c,d in cd: ans.append(abs(a-c)+abs(b-d)) print((ans.index(min(ans))+1))
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc057/tasks/abc057_b" }
d8393
test
a = int(input()) ans = a + a**2 + a**3 print(ans)
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc172/tasks/abc172_a" }
d8394
test
n, m = map(int, input().split()) a = ["" for _ in range(n)] b = ["" for _ in range(m)] for i in range(n): a[i] = str(input()) for i in range(m): b[i] = str(input()) def check(ini_x, ini_y): nonlocal n, m, a, b for x in range(m): for y in range(m): if a[ini_x + x][ini_y + y] != b[x][y]: return False return True for i in range(n - m + 1): for j in range(n - m + 1): if check(i, j): print("Yes") return print("No")
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc054/tasks/abc054_b" }
d8395
test
a=input().split() a.sort(reverse=True) if len(set(a))==1: print(12*int(a[0])) else: ans=int(a[0]+a[1])+int(a[2]) print(ans)
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc110/tasks/abc110_a" }
d8396
test
def main(): p = [] sum_cost = 0 n = int(input()) for i in range(n): p.append(int(input())) max_p = max(p) p[p.index(max_p)] = max_p / 2 print((int(sum(p)))) def __starting_point(): main() __starting_point()
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc115/tasks/abc115_b" }
d8397
test
import math a = [] for i in range(5): a.append(int(input())) sum = 0 r =10 for i in range(5): if a[i] % 10 ==0: sum+=a[i] elif a[i] % 10 !=0: r = min(r,a[i]%10) sum+= (10*math.ceil(a[i]/10)) print(sum-10+r)
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc123/tasks/abc123_b" }
d8398
test
n=int(input()) a=list(map(lambda x:1/int(x),input().split())) print(1/sum(a))
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc138/tasks/abc138_b" }
d8399
test
n,k = map(int,input().split()) L = sorted(list(int(input()) for _ in range(n))) m = 10**9 for i in range(n-k+1): m = min(m, L[i+k-1]-L[i]) print(m)
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc115/tasks/abc115_c" }
d8400
test
S = input() ans = 'A' if S.islower(): ans = 'a' print(ans)
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc171/tasks/abc171_a" }