_id
stringlengths
2
5
partition
stringclasses
2 values
text
stringlengths
5
289k
language
stringclasses
1 value
meta_information
dict
title
stringclasses
1 value
d8101
test
n = int(input()) dn = list(map(int, input().split())) dn.sort() a = dn[n // 2 - 1] b = dn[n // 2] print((b-a))
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc132/tasks/abc132_c" }
d8102
test
def main(): import sys input = sys.stdin.readline N, H, L, R = list(map(int, input().split())) A = list(map(int, input().split())) dp = [[-1] * H for _ in range(N+1)] dp[0][0] = 0 for i, a in enumerate(A): for t in range(H): if dp[i][t] >= 0: dp[i+1][(t+a)%H] = max(dp[i+1][(t+a)%H], dp[i][t] + int(L <= (t+a)%H <= R)) dp[i + 1][(t + a-1) % H] = max(dp[i + 1][(t + a-1) % H], dp[i][t] + int(L <= (t + a-1) % H <= R)) print(max(dp[-1])) def __starting_point(): main() __starting_point()
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/1324/E" }
d8103
test
n = int(input()) a = list(map(int, input().split())) ans = [1] t = 1 for i in range(n - 1): if a[i + 1] / a[i] <= 2: t += 1 else: t = 1 ans.append(t) print(max(ans))
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/1029/B" }
d8104
test
import math from collections import defaultdict import sys input = sys.stdin.readline def main(): n = int(input()) a = list(map(int, input().split())) MAX = 10**7 + 1 res = MAX * MAX #MAX_P = int(math.sqrt(MAX)) MAX_P = 3163 primes = [] p = 2 sieve = [True] * (MAX_P+1) while p < MAX_P: if sieve[p]: primes.append(p) k = 2 while k * p < MAX_P: sieve[k * p] = False k += 1 p += 1 np = len(primes) cand1 = {} cand2 = {} ind1 = {} ind2 = {} res = MAX * MAX for index in range(n): val = a[index] if val >= res: continue divisors = [1] p = 0 while val > 0 and p < np: while val % primes[p] == 0: divisors += [d * primes[p] for d in divisors] val //= primes[p] p += 1 if val > 1: divisors += [d * val for d in divisors] for d in set(divisors): if d not in cand1: cand1[d] = a[index] ind1[d] = index else: if d not in cand2: if a[index] < cand1[d]: cand2[d] = cand1[d] ind2[d] = ind1[d] cand1[d] = a[index] ind1[d] = index else: cand2[d] = a[index] ind2[d] = index else: if a[index] < cand1[d]: cand2[d] = cand1[d] ind2[d] = ind1[d] cand1[d] = a[index] ind1[d] = index elif a[index] < cand2[d]: cand2[d] = a[index] ind2[d] = index else: continue if res > cand1[d] // d * cand2[d]: x, y = ind1[d], ind2[d] res = cand1[d] // d * cand2[d] print(min(x+1, y+1), max(x+1, y+1)) def __starting_point(): main() __starting_point()
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/1154/G" }
d8105
test
from sys import stdin, stdout from math import sin, tan, cos, pi, atan2, sqrt, acos, atan, factorial from random import randint n = int(stdin.readline()) s = list(stdin.readline().strip()) a, b, c = s.count('0'), s.count('1'), s.count('2') d = n // 3 for i in range(len(s)): if s[i] == '2' and c > d: if a < d: s[i] = '0' a += 1 c -= 1 else: s[i] = '1' b += 1 c -= 1 elif s[i] == '1' and b > d: if a < d: s[i] = '0' a += 1 b -= 1 for i in range(len(s) - 1, -1, -1): if s[i] == '1' and b > d: if c < d: s[i] = '2' b -= 1 c += 1 elif s[i] == '0' and a > d: if c < d: s[i] = '2' a -= 1 c += 1 elif b < d: s[i] = '1' a -= 1 b += 1 stdout.write(''.join(s))
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/1102/D" }
d8106
test
import sys N, M = list(map(int, input().split())) a = [False]*(N+1) for i in range(M): a[int(input())] = True b = [0]*(N+1) if N < 2: print((1)) return b[-1] = 1 for i in reversed(list(range(0, N))): if a[i]: b[i] = 0 continue if i == N-1: b[i] = b[i+1] else: b[i] = (b[i+1] + b[i+2])%(10**9+7) print((b[0]))
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc129/tasks/abc129_c" }
d8107
test
x, k, d = map(int, input().split()) if x < 0: x *= -1 cnt = min(k, x//d+1) x -= cnt * d if abs(x) < x+d: x += d cnt -= 1 x -= d * ((k-cnt)%2) else: x += d * ((k-cnt)%2) print(abs(x))
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc175/tasks/abc175_c" }
d8108
test
TASK = "stars" # FIN = open(TASK + ".in") # FOUT = open(TASK + ".out", "w") a = [1, 0, 0, 0, 1, 0, 1, 0, 2, 1, 1, 2, 0, 1, 0, 0] ans = 0 n = int(input()) if n == 0: print(1) return while (n > 0): tmp = n % 16 ans += a[tmp] n //= 16 print(ans) # FIN.close() # FOUT.close()
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/784/B" }
d8109
test
a = [ 4, 22, 27, 58, 85, 94, 121, 166, 202, 265, 274, 319, 346, 355, 378, 382, 391, 438, 454, 483, 517, 526, 535, 562, 576, 588, 627, 634, 636, 645] print(a[int(input()) - 1])
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/784/A" }
d8110
test
x = int(input()) print(x%2)
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/952/A" }
d8111
test
n = int(input()) a = list(map(int, input().split())) print(max(a) ^ a[-1])
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/784/C" }
d8112
test
def read_int(): return int(input()) def read_ints(): return list(map(int, input().split(' '))) t = read_int() for case_num in range(t): n, k = read_ints() i = 1 largest = 1 while i * i <= n: if n % i == 0: if i <= k: largest = max(largest, i) if n // i <= k: largest = max(largest, n // i) i += 1 print(n // largest)
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/1360/D" }
d8113
test
n,m = map(int,input().split()) s = [list(map(int,input().split())) for i in range(m)] p = list(map(int,input().split())) ans = 0 for i in range(2 ** n): t = ['off'] * n x = i j = 0 while x > 0: if x % 2 != 0: t[j] = 'on' x = x // 2 j += 1 flg = True for j in range(m): z = 0 for k in range(1,s[j][0]+1): if t[s[j][k]-1] == 'on': z += 1 if z % 2 != p[j]: flg = False break if flg: ans += 1 print(ans)
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc128/tasks/abc128_c" }
d8114
test
import math A,B,H,M = map(int,input().split()) if H >= 12: H -= 12 choperminute = 360/60 ##ไธ€ๅˆ†ใง้•ท้‡ใŒไฝ•ๅบฆๅ‹•ใใ‹ tanperminute = 30/60 ##ไธ€ๅˆ†ใง็Ÿญ้‡ใŒไฝ•ๅบฆๅ‹•ใใ‹ tankaku = H*30 + tanperminute*M chokaku = choperminute*M if chokaku >= tankaku: angle = chokaku -tankaku else: angle = tankaku - chokaku if angle > 180: angle = 360 -angle ansjyou = (A**2) + (B**2) - (2*A*B*math.cos(math.radians(angle))) print(ansjyou**0.5)
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc168/tasks/abc168_c" }
d8115
test
MAXN = 200001 def less_sum(s, m): n = len(s) a = 0 b = 0 res = 0 last = 0 count = [0 for i in range(-MAXN, MAXN+1)] count[0] = 1 x = 0 last = 1 for i in range(n): if s[i] > m: b += 1 else: a += 1 x = a-b #print(x) #print(count[-2], count[-1], count[0], count[1], count[2]) if s[i] > m: last -= count[x+1] else: last += count[x] #print(x, last) res += last count[x] += 1 last += 1 #print(res) return res n, m = map(int, input().split(' ')) s = list(map(int, input().split(' ')))[0:n] #print(m, s) print(less_sum(s, m) - less_sum(s, m-1))
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/1005/E2" }
d8116
test
from copy import deepcopy n,m = map(int,input().split()) a = list(map(int,input().split())) b = [list(map(int,input().split())) for i in range(m)] best1 = -1 best2 = -1 best3 = [] for i in range(n): tmp = 0 tmp2 = 0 tmp3 = [] c = deepcopy(a) for j in range(m): x,y = b[j] x-=1;y-=1 if x<= i and i <= y: continue for k in range(x,y+1): c[k] -= 1 tmp3.append(j+1) tmp2 += 1 kon = max(c)-min(c) if best1 < kon: best1 = kon best2 = tmp2 best3 = tmp3 print(best1) print(best2) print(*best3)
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/1108/E1" }
d8117
test
n = int(input()) for i in range(n): s = input() if len(s) == len(set(s)) and abs(ord(min(s)) - ord(max(s))) == len(s) - 1: print('Yes') else: print('No')
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/1144/A" }
d8118
test
import sys # a very nice implementation of a minimum segment tree with # some inspiration taken from https://codeforces.com/blog/entry/18051 # this implementation should be able to be modified to do pretty # much anything one would want to do with segment trees apart from # persistance. # note that especially in python this implementation is much much better # than most other approches because how slow python can be with function # calls. # currently it allows for two operations, both running in o(log n), # 'add(l,r,value)' adds value to [l,r) # 'find_min(l,r)' finds the index with the smallest value class super_seg: def __init__(self,data): n = len(data) m = 1 while m<n: m *= 2 self.n = n self.m = m self.data = [0]*(2*m) for i in range(n): self.data[i+m] = data[i] for i in reversed(range(m)): self.data[i] = min(self.data[2*i], self.data[2*i+1]) self.query = [0]*(2*m) # push the query on seg_ind to its children def push(self,seg_ind): # let the children know of the queries q = self.query[seg_ind] self.query[2*seg_ind] += q self.query[2*seg_ind+1] += q self.data[2*seg_ind] += q self.data[2*seg_ind+1] += q # remove queries from seg_ind self.data[seg_ind] = min(self.data[2*seg_ind],self.data[2*seg_ind+1]) self.query[seg_ind] = 0 # updates the node seg_ind to know of all queries # applied to it via its ancestors def update(self,seg_ind): # find all indecies to be updated seg_ind //= 2 inds = [] while seg_ind>0: inds.append(seg_ind) seg_ind//=2 # push the queries down the segment tree for ind in reversed(inds): self.push(ind) # make the changes to seg_ind be known to its ancestors def build(self,seg_ind): seg_ind//=2 while seg_ind>0: self.data[seg_ind] = min(self.data[2*seg_ind], self.data[2*seg_ind+1]) + self.query[seg_ind] seg_ind //= 2 # lazily add value to [l,r) def add(self,l,r,value): l += self.m r += self.m l0 = l r0 = r while l<r: if l%2==1: self.query[l]+= value self.data[l] += value l+=1 if r%2==1: r-=1 self.query[r]+= value self.data[r] += value l//=2 r//=2 # tell all nodes above of the updated # area of the updates self.build(l0) self.build(r0-1) # min of data[l,r) def min(self,l,r): l += self.m r += self.m # apply all the lazily stored queries self.update(l) self.update(r-1) segs = [] while l<r: if l%2==1: segs.append(l) l+=1 if r%2==1: r-=1 segs.append(r) l//=2 r//=2 return min(self.data[ind] for ind in segs) # find index of smallest value in data[l,r) def find_min(self,l,r): l += self.m r += self.m # apply all the lazily stored queries self.update(l) self.update(r-1) segs = [] while l<r: if l%2==1: segs.append(l) l+=1 if r%2==1: r-=1 segs.append(r) l//=2 r//=2 ind = min(segs, key=lambda i:self.data[i]) mini = self.data[ind] # dig down in search of mini while ind<self.m: self.push(ind) if self.data[2*ind]==mini: ind *= 2 else: ind = 2*ind+1 return ind-self.m,mini n,m = [int(x) for x in input().split()] A = [int(x) for x in input().split()] inter = [] inter2 = [] for _ in range(m): l,r = [int(x) for x in input().split()] l -= 1 inter.append((l,r)) inter2.append((r,l)) inter_copy = inter[:] inter.sort() inter2.sort() Aneg = super_seg([-a for a in A]) besta = -1 besta_ind = -1 j1 = 0 j2 = 0 for i in range(n): # Only segments containing i should be active # Activate while j1<m and inter[j1][0]<=i: l,r = inter[j1] Aneg.add(l,r,1) j1 += 1 # Deactivate while j2<m and inter2[j2][0]<=i: r,l = inter2[j2] Aneg.add(l,r,-1) j2 += 1 Amax = -Aneg.min(0,n) Ai = -Aneg.min(i,i+1) if Amax-Ai>besta: besta = Amax-Ai besta_ind = i ints = [j for j in range(m) if inter_copy[j][0]<=besta_ind<inter_copy[j][1]] print(besta) print(len(ints)) print(*[x+1 for x in ints])
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/1108/E2" }
d8119
test
x=int(input()) a=list(map(int,input().strip().split())) y=[] c=0 f1=1 f2=1 l=0 r=x-1 op=[] while(f1 or f2): if(l>r): break if(a[l]<c): f1=0 if(a[r]<c): f2=0 if(f1 and f2): if(a[l]<=a[r]): c=a[l] l=l+1 op.append('L') else: c=a[r] r=r-1 op.append('R') elif(f1): c=a[l] l=l+1 op.append('L') elif(f2): c=a[r] r=r-1 op.append('R') print(len(op)) print("".join(op))
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/1157/C1" }
d8120
test
n = int(input()) mass = list(map(int, input().split())) left = [1] * n right = [1] * n for i in range(1, n): if mass[i] > mass[i - 1]: left[i] = left[i - 1] + 1 for i in range(n - 2, -1, -1): if mass[i] < mass[i + 1]: right[i] = right[i + 1] + 1 mx = 1 for i in range(n): if i == 0: mx = max(right[0], mx) elif i == n - 1: mx = max(mx, left[n - 1]) elif mass[i + 1] > mass[i - 1]: mx = max(mx, left[i - 1] + right[i + 1]) mx = max(mx, left[i]) mx = max(mx, right[i]) print(mx)
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/1272/D" }
d8121
test
# TAIWAN NUMBER ONE!!!!!!!!!!!!!!!!!!! # TAIWAN NUMBER ONE!!!!!!!!!!!!!!!!!!! # TAIWAN NUMBER ONE!!!!!!!!!!!!!!!!!!! from sys import stdin, stdout from collections import defaultdict from collections import deque import math import copy #T = int(input()) #N = int(input()) #s1 = input() #s2 = input() N,K = [int(x) for x in stdin.readline().split()] arr = [int(x) for x in stdin.readline().split()] arr.sort() freq = {} for i in range(N): num = arr[i] if num not in freq: freq[num] = [] round = 0 freq[num].append(0) while num!=0: round += 1 num = num//2 if num not in freq: freq[num] = [] freq[num].append(round) res = 999999999999 for key in freq: if len(freq[key])<K: continue else: s = sum(freq[key][:K]) res = min(res,s) print(res)
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/1213/D1" }
d8122
test
#-*-coding:utf-8-*- import sys input=sys.stdin.readline def main(): n,a,b = map(int,input().split()) a_count=0 d,r=divmod(n,a+b) a_count+=a*d if r > a: a_count+=a else: a_count+=r print(a_count) def __starting_point(): main() __starting_point()
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc158/tasks/abc158_b" }
d8123
test
for q in range(int(input())): n = int(input()) D = list(map(int, input().split())) D.sort() z = D[0] * D[-1] if z == -1: print(-1) else: Dz = set() for i in range(2, int(z ** 0.5) + 1): if z % i == 0: Dz.add(i) Dz.add(z // i) if Dz == set(D): print(z) else: print(-1)
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/1165/D" }
d8124
test
n=int(input()) ar=list(map(int,input().split())) s=set() a=[] for x in ar[::-1]: if x not in s: a.append(x) s.add(x) print(len(a)) print(*a[::-1])
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/978/A" }
d8125
test
def f(n): a=0 while(n>0): a+=n%10 n//=10 return a n=int(input()) while f(n)%4!=0: n+=1 print(n)
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/1183/A" }
d8126
test
import sys input = sys.stdin.readline t=int(input()) for tests in range(t): S=input().strip() m=int(input()) B=list(map(int,input().split())) LIST=[0]*26 for s in S: LIST[ord(s)-97]+=1 ANS=[0]*m ind=25 while max(B)>=0: L=[] for i in range(m): if B[i]==0: L.append(i) B[i]=-1 LEN=len(L) while LIST[ind]<LEN: ind-=1 for l in L: ANS[l]=ind ind-=1 for l in L: for i in range(m): B[i]-=abs(i-l) #print(ANS) print("".join([chr(a+97) for a in ANS]))
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/1367/D" }
d8127
test
N = int(input()) al = [chr(ord('a') + i) for i in range(26)] ans = '' while N>0: N -=1 ans += al[N%26] N //= 26 print(ans[::-1])
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc171/tasks/abc171_c" }
d8128
test
n = int(input()) arr = input() final = len(arr) arr = arr.split() lens = [0 for x in range(n)] visit = [0 for x in range(n)] cnt = 0 ans = 0 for i in range(n): if visit[i]: continue lens[cnt] = len(arr[i]) for j in range(i+1,n): if arr[j]==arr[i]: arr[j] = cnt visit[j] = 1 arr[i] = cnt cnt += 1 for i in range(n): for j in range(i,n): temp = arr[i:j+1] ind = 1 found = 0 len2 = j-i+1 cur = 0 kmp = [0 for x in range(len2)] while ind < len2: if temp[ind] == temp[cur]: cur += 1 kmp[ind] = cur ind += 1 else: if cur != 0: cur -= 1 else: kmp[ind] = 0 ind += 1 ind = 0 cur = 0 while ind < n: if arr[ind] == temp[cur]: ind += 1 cur += 1 if cur == len2: found += 1 cur = 0 elif ind < n and temp[cur] != arr[ind]: if cur != 0: cur = kmp[cur-1] else: ind += 1 if found>1: res = 0 for k in temp: res += (lens[k]-1)*(found) res += (len(temp)-1)*(found) ans = max(ans,res) print(final-ans)
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/1003/F" }
d8129
test
def mi(): return map(int, input().split()) n, k = mi() a = list(mi()) for i in range(n): a[i] = [a[i],i] a.sort(reverse= True) a = a[:k] s = 0 ind = [] for i in a: s+=i[0] ind.append(i[1]) ind.sort() for i in range(k): ind[i]+=1 ind1 = ind.copy() for i in range(1,len(ind)): ind[i]-=ind1[i-1] ind[-1] = n-sum(ind[:k-1]) print (s) for i in ind: print (i, end = ' ')
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/1006/B" }
d8130
test
from sys import stdin tt = 1 for loop in range(tt): dic = {} dic[0] = 1 n = int(stdin.readline()) a = list(map(int,stdin.readline().split())) now = 0 ans = 0 for i in a: now += i if now in dic: ans += 1 dic = {} dic[0] = 1 now = i dic[now] = 1 print (ans)
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/1426/D" }
d8131
test
import sys input = sys.stdin.readline rInt = lambda: int(input()) mInt = lambda: list(map(int, input().split())) rLis = lambda: list(map(int, input().split())) t = int(input()) for _ in range(t): n, m = mInt() if n == 1: print(0) elif n == 2: print(m) else: print(2 * m)
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/1353/A" }
d8132
test
K = int(input()) a = [7] * (K + 1) a[0] %= K for i in range(1, K+1): a[i] = (10*a[i-1] + 7) % K ans = [i+1 for i, ai in enumerate(a) if ai == 0] if len(ans) > 0: print((ans[0])) else: print((-1))
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc174/tasks/abc174_c" }
d8133
test
def main(): n, m = map(int, input().split()) def intCompare(x): if int(x) == m: return 0 if int(x) < m: return -1 return 1 p = list(map(intCompare, input().split())) ret = 0 ind = p.index(0) tem = 0 ret0 = [0] * 400001 ret1 = [0] * 400001 set0 = set() for i in range(ind, -1, -1): tem += p[i] ret0[tem] += 1 set0.add(tem) tem = 0 for i in range(ind, n): tem += p[i] ret1[tem] += 1 for i in set0: ret += ret0[i] * (ret1[-i] + ret1[1-i]) print(ret) return 0 main()
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/1005/E1" }
d8134
test
n, m = [int(x) for x in input().split()] a = [int(x) for x in input().split()] a.sort(reverse=True) def check(d): s=0 for i in range(len(a)): s+=max(0,a[i]-i//d) return s>=m if sum(a)<m: print(-1) else: l, r = 1,n mid = l+r>>1 while l<r: if check(mid): r=mid else: l=mid+1 mid=l+r>>1 print(l)
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/1118/D1" }
d8135
test
n = int(input()) T = input().split(' ') for i in range(n): T[i] = int(T[i]) m = n+1 if n == 1: print(0) else: for a in range(-1, 2): for b in range(-1, 2): c = True p = (T[1]+b) - (T[0]+a) tot = 0 if a!=0: tot+=1 if b!=0: tot+=1 el = T[1]+b for j in range(2, n): if abs((T[j] - el) - p) <= 1: el += p if T[j] != el: tot+=1 else: c = False if c: m = min(m, tot) if m <= n: print(m) else: print(-1)
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/978/D" }
d8136
test
import bisect n,k=list(map(int,input().split())) A=list(map(int,input().split())) A.sort() DP=[[0]*(k+1) for i in range(n)] for i in range(n): x=bisect.bisect_right(A,A[i]+5)-1 #print(i,x) for j in range(k-1,-1,-1): DP[i][j]=max(DP[i][j],DP[i-1][j]) DP[x][j+1]=max(DP[i-1][j]+x-i+1,DP[x][j+1]) print(max([DP[i][-1] for i in range(n)]))
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/1133/E" }
d8137
test
N, K, M = map(int,input().split()) A = list(map(int,input().split())) def score(): max_aim = M*N last_score = max_aim - sum(A) if last_score <=0: return 0 elif 0 < last_score <= K: return last_score elif K < last_score: return -1 print(score())
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc151/tasks/abc151_b" }
d8138
test
n,k,q = [int(x) for x in input().split()] a = [] for i in range(q): a.append(int(input())) res = [0] * n for i in range(q): res[a[i]-1] += 1 b = q - k #print(res) for i in range(n): if res[i] > b: print("Yes") else: print("No")
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc141/tasks/abc141_c" }
d8139
test
import sys input = sys.stdin.readline n,m=list(map(int,input().split())) A=[list(map(int,input().split())) for i in range(n)] for i in range(m): #ไธ€่กŒ็›ฎใ‚’i-1ใพใง0ใซใ™ใ‚‹ ANSR=[0]*n ANSC=[0]*m for j in range(i): if A[0][j]==1: ANSC[j]=1 for j in range(i,m): if A[0][j]==0: ANSC[j]=1 for r in range(1,n): B=set() for c in range(m): if ANSC[c]==0: B.add(A[r][c]) else: B.add(1-A[r][c]) if len(B)>=2: break if max(B)==0: ANSR[r]=1 else: print("YES") print("".join(map(str,ANSR))) print("".join(map(str,ANSC))) return ANSR=[0]*n ANSC=[0]*m for j in range(m): if A[0][j]==1: ANSC[j]=1 flag=0 for r in range(1,n): if flag==0: B=[] for c in range(m): if ANSC[c]==0: B.append(A[r][c]) else: B.append(1-A[r][c]) if max(B)==0: continue elif min(B)==1: ANSR[r]=1 continue else: OI=B.index(1) if min(B[OI:])==1: flag=1 continue OO=B.index(0) if max(B[OO:])==0: flag=1 ANSR[r]=1 continue else: print("NO") return else: B=set() for c in range(m): if ANSC[c]==0: B.add(A[r][c]) else: B.add(1-A[r][c]) if len(B)>=2: break if max(B)==0: ANSR[r]=1 else: print("YES") print("".join(map(str,ANSR))) print("".join(map(str,ANSC))) return print("NO")
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/1157/G" }
d8140
test
import sys import time for line in sys.stdin: ll = len(line) - 1 fail = 0 for i in range(ll): if i == ll - 1 - i: if int(line[i]) not in [3, 7]: fail = 1 continue x = int(line[i]) y = int(line[ll - 1 - i]) if (x, y) not in [(3, 3), (4, 6), (6, 4), (7, 7), (8, 0), (0, 8), (5, 9), (9, 5)]: fail = 1 if fail: print("No") if not fail: print("Yes")
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/784/D" }
d8141
test
n, b, a = map(int, input().split()) A = list(map(int, input().split())) a0 = a ans = 0 for elem in A: if a + b == 0: break if elem == 0: if a > 0: a -= 1 ans += 1 else: b -= 1 ans += 1 else: if a == a0: a -= 1 ans += 1 elif b > 0: b -= 1 a += 1 ans += 1 else: a -= 1 ans += 1 print(ans)
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/1154/D" }
d8142
test
res = 0 val = 0 sub = False for c in input()+'+': if c == '+' or c == '-': if sub: val *= -1 res += val val = 0 sub = (c == '-') val *= 10 val += ord(c) - ord('0') print(res)
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/952/F" }
d8143
test
n, k = list(map(int, input().split())) if n > k*(k-1): print("NO") else: print("YES") cnt = 0 for delta in range(k): for c in range(1, k+1): if cnt < n: cnt +=1 print(c, 1+(c+delta)%k) else: break
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/1118/E" }
d8144
test
import sys from math import * def minp(): return sys.stdin.readline().strip() def mint(): return int(minp()) def mints(): return map(int, minp().split()) n, k, x = mints() a = list(mints()) d = [None]*(n+1) p = [None]*(n+1) for i in range(0,k): d[i] = a[i] for xx in range(2,x+1): d,p = p,d for nn in range(n): m = None for i in range(max(0,nn-k),nn): if p[i] != None: if m == None: m = p[i] else: m = max(m, p[i]) if m != None: d[nn] = m + a[nn] else: d[nn] = None m = -1 for i in range(n-k,n): if d[i] != None: m = max(m, d[i]) print(m)
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/1077/F1" }
d8145
test
import heapq n, k = list(map(int, input().split())) s = input() mostRecent = n best = [] for room in range(n-1, -1, -1): if s[room] == '1': mostRecent = room best.append(mostRecent) best = best[::-1] dp = [0] vals = [(0,0)] for room in range(1, n + 1): new = dp[-1] + room if room - k - 1 >= 0: bestRout = best[room - k - 1] if bestRout <= (room - 1): covered = bestRout - k if covered >= 0: try: while len(vals) > 0 and vals[0][1] < covered: heapq.heappop(vals) if len(vals) > 0: add = vals[0][0] new2 = (bestRout + 1) + add new = min(new2, new) except Exception: pass else: new2 = (bestRout + 1) new = min(new2, new) dp.append(new) heapq.heappush(vals, (new, room)) print(new)
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/1216/F" }
d8146
test
S = input() T = input() s = [[] for i in range(26)] t = [[] for i in range(26)] for i in range(len(S)): s[ord(S[i])-97].append(i) t[ord(T[i])-97].append(i) s = sorted(s) t = sorted(t) if s == t: print("Yes") else: print("No")
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc110/tasks/abc110_c" }
d8147
test
N, M, X = list(map(int, input().split())) A = [0]*N for i in range(N): A[i] = list(map(int, input().split())) min_sump = -1 for i in range(2**(N+1)): sump = 0 sume = [0]*M for j in range(N): ns = "0" + str(N) +"b" bi = format(i,ns) if bi[-1-j] == "1": sump += A[j][0] sume = list(map(sum, zip(sume, A[j][1:]))) if all([i >= X for i in sume]): if min_sump == -1: min_sump = sump else: min_sump = min(min_sump,sump) print(min_sump)
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc167/tasks/abc167_c" }
d8148
test
import sys sys.setrecursionlimit(10 ** 6) D,G=map(int,input().split()) p=[] c=[] for i in range(D): a,b=map(int,input().split()) p += [a] c += [b] def solve(bit): if bit >= (1<<D): return 1000 p_sum=0 num=0 for i in range(D): if bit & (1<<i): p_sum += c[i] + p[i] * 100*(i+1) num += p[i] if p_sum >= G: return min(num,solve(bit+1)) else: for i in reversed(range(D)): if bit & 1<<i: continue for j in range(p[i]): if p_sum >= G: break p_sum += 100*(i+1) num += 1 else: return solve(bit+1) return min(num,solve(bit+1)) print(solve(0))
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc104/tasks/abc104_c" }
d8149
test
n=int(input()) arr=list(map(int,input().split())) arr1=[] arr2=[] count1=0 count2=0 for i in range(n): if(i%2==0): count1+=arr[i] else: count2+=arr[i] ans=0 temp1=0 temp2=0 for i in range(n): if(i%2==0): val1=temp1+count2-temp2 val2=temp2+count1-temp1-arr[i] if(val1==val2): ans+=1 temp1+=arr[i] else: val1=temp1+count2-temp2-arr[i] val2=temp2+count1-temp1 if(val1==val2): ans+=1 temp2+=arr[i] print(ans)
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/1118/B" }
d8150
test
n, k, x = list(map(int, input().split())) a = [None] + list(map(int, input().split())) lo, hi = 0, 10 ** 9 * 5000 q = [None] * (n + 1) def get(mid): f, r = 0, 0 q[0] = 0, 0, 0 for i in range(1, n + 1): if q[r][2] == i - k - 1: r += 1 cur = q[r][0] + a[i] - mid, q[r][1] + 1, i while r <= f and q[f] <= cur: f -= 1 f += 1 q[f] = cur if q[r][2] == n - k: r += 1 return q[r] while lo < hi: mid = (lo + hi + 1) >> 1 _, cnt, _ = get(mid) if cnt >= x: lo = mid else: hi = mid - 1 sm, _, _ = get(lo) ans = max(-1, sm + x * lo) print(ans)
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/1077/F2" }
d8151
test
N=int(input()) ans ="No" for i in range(N//4+1): for j in range(N//7+1): if 4*i + 7*j == N: ans = "Yes" print(ans)
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc105/tasks/abc105_b" }
d8152
test
import sys # import math # import bisect # import numpy as np # from decimal import Decimal # from numba import njit, i8, u1, b1 #JIT compiler # from itertools import combinations, product # from collections import Counter, deque, defaultdict # sys.setrecursionlimit(10 ** 6) MOD = 10 ** 9 + 7 INF = 10 ** 9 PI = 3.14159265358979323846 def read_str(): return sys.stdin.readline().strip() def read_int(): return int(sys.stdin.readline().strip()) def read_ints(): return map(int, sys.stdin.readline().strip().split()) def read_ints2(x): return map(lambda num: int(num) - x, sys.stdin.readline().strip().split()) def read_str_list(): return list(sys.stdin.readline().strip().split()) def read_int_list(): return list(map(int, sys.stdin.readline().strip().split())) def GCD(a: int, b: int) -> int: return b if a%b==0 else GCD(b, a%b) def LCM(a: int, b: int) -> int: return (a * b) // GCD(a, b) def solve(info): for Cx in range(101): for Cy in range(101): height = abs(Cx - info[0][0]) + abs(Cy - info[0][1]) + info[0][2] flag = True for x,y,h in info[1:]: val = max(height - abs(Cx - x) - abs(Cy - y), 0) if h == val: continue else: flag = False break if flag: return Cx, Cy, height def Main(): n = read_int() info = [tuple(read_ints()) for _ in range(n)] info.sort(key=lambda x: x[2], reverse=True) print(*solve(info)) def __starting_point(): Main() __starting_point()
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc112/tasks/abc112_c" }
d8153
test
s=input();n=len(s)-1;print(sum(s[i]!=s[n-i]for i in range(n+1))//2)
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc147/tasks/abc147_b" }
d8154
test
import sys n = int(input()) for a in range(1,10): if n % a == 0 and n // a <= 9: print("Yes") return print("No")
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc144/tasks/abc144_b" }
d8155
test
n = int(input()) l = list(map(int,input().split())) cnt = 0 for i in range(0,n-2): for j in range(i+1,n-1): for k in range(j+1,n): x = [l[i],l[j],l[k]] ma = sorted(x)[2] _ma = sorted(x)[0] + sorted(x)[1] if l[i] != l[j] and l[i] != l[k] and l[j] != l[k] and ma < _ma: cnt += 1 print(cnt)
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc175/tasks/abc175_b" }
d8156
test
a,b = map(int,input().split()) print(a*b if a < 10 and b < 10 else -1)
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc144/tasks/abc144_a" }
d8157
test
# -*- coding: utf-8 -*- def main(): n, m = list(map(int, input().split())) x = sorted(list(map(int, input().split()))) diff = list() for i, j in zip(x, x[1:]): diff.append(abs(i - j)) diff = sorted(diff, reverse=True) print((sum(diff) - sum(diff[:n - 1]))) def __starting_point(): main() __starting_point()
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc117/tasks/abc117_c" }
d8158
test
import sys import os class Path(): def __init__(self, idx, s, d): self.idx = idx self.s = s self.d = d def __eq__(self, rhs): return self.s == rhs.s and self.d == rhs.d def __hash__(self): return self.s * 100000 + self.d def shortestPath(n, k, paths): ps = dict() for p in paths: if p.s not in ps: ps[p.s] = [p] else: ps[p.s].append(p) if p.d not in ps: ps[p.d] = [p] else: ps[p.d].append(p) d = set() open = set() d.add(1) for e in paths: if e.s == 1 or e.d == 1: open.add(e) general_edges = [] general_choices = [] while len(d) < n: newd = set() choices = dict() for e in open: oe = e.s if e.s in d: oe = e.d newd.add(oe) if oe not in choices: choices[oe] = [e.idx] else: choices[oe].append(e.idx) d.update(newd) for oe, p in choices.items(): if len(p) > 1: general_choices.append(p) else: general_edges.append(p[0]) open = set() for node in newd: for p in ps[node]: if (p.s in d) != (p.d in d): open.add(p) maxk = 1 for choice in general_choices: maxk *= len(choice) k = min(k, maxk) print(k) output = ['0'] * len(paths) for e in general_edges: output[e] = '1' for e in general_choices: output[e[0]] = '1' for i in range(k): print(''.join(output)) for choice in general_choices: done = False for i in range(len(choice) - 1): if output[choice[i]] == '1': output[choice[i]] = '0' output[choice[i + 1]] = '1' done = True break if done: break output[choice[len(choice) - 1]] = '0' output[choice[0]] = '1' def main(): n, m, k = (int(x) for x in input().split()) paths = [] for i in range(m): path = [int(x) for x in input().split()] paths.append(Path(i, path[0], path[1])) shortestPath(n, k, paths) def __starting_point(): main() __starting_point()
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/1005/F" }
d8159
test
n = int(input()) a = list(map(int, input().split())) q = (10 ** 6) * [-1] pnt = -1 ans = "YES" for i in range(n): if pnt == -1: pnt += 1 q[pnt] = a[i] else : if q[pnt] == a[i] or abs(q[pnt] - a[i]) % 2 == 0: q[pnt] = -1 pnt -= 1 else: pnt += 1 q[pnt] = a[i] if pnt > 0 : ans = "NO" print(ans)
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/1092/D1" }
d8160
test
H, n = list(map(int, input().split())) d = list(map(int, input().split())) t = 0 miPt = H for a in d: t += 1 H += a miPt = min(miPt, H) if H <= 0: print(t) return if sum(d) >= 0: print(-1) return jump = max(0, miPt // -sum(d) - 2) H -= jump * -sum(d) t += n * jump for i in range(100000000000000000): t += 1 H += d[i % n] if H <= 0: print(t) return
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/1141/E" }
d8161
test
n = int(input()) s = input() a = [[0] * 26 for _ in range(26)] for i in range(n -1): a[ord(s[i]) - ord('A')][ord(s[i + 1]) - ord('A')] += 1 mx = -1 for i in range(26): for j in range(26): if a[i][j] > mx: mx = a[i][j] ans = chr(i + ord('A')) + chr(j + ord('A')) print(ans)
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/977/B" }
d8162
test
s = input()[::-1] t = input()[::-1] i = 0 while i < min(len(s),len(t)) and s[i] == t[i]: i += 1 print(len(s) - i + len(t) - i)
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/1005/B" }
d8163
test
from fractions import gcd from functools import reduce n, x = list(map(int, input().split())) c = list(map(int, input().split())) print((reduce(gcd, [abs(i-x) for i in c])))
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc109/tasks/abc109_c" }
d8164
test
s = input() def is_palinedrome(st): for i in range(len(st)//2): if st[i] != st[-(i+1)]: return False return True s_pali = is_palinedrome(s) sub_pali_left = is_palinedrome(s[:len(s)//2]) sub_pali_right = is_palinedrome(s[len(s)//2+1:]) if s_pali and sub_pali_left and sub_pali_right: print('Yes') else: print('No')
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc159/tasks/abc159_b" }
d8165
test
a, b = input().split() a = int(a) b1, b2 = b.split('.') b3 = int(b1)*100 + int(b2) print((a*b3//100))
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc169/tasks/abc169_c" }
d8166
test
t = int(input()) for i in range(t): n = int(input()) print((n-1)//2)
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/1335/A" }
d8167
test
from queue import Queue from random import shuffle import sys import math import os.path sys.setrecursionlimit(100000) # LOG def log(*args, **kwargs): print(*args, file=sys.stderr, **kwargs) # INPUT def ni(): return map(int, input().split()) def nio(offset): return map(lambda x: int(x) + offset, input().split()) def nia(): return list(map(int, input().split())) # CONVERT def toString(aList, sep=" "): return sep.join(str(x) for x in aList) def toMapInvertIndex(aList): return {k: v for v, k in enumerate(aList)} # SORT def sortId(arr): return sorted(range(len(arr)), key=lambda k: arr[k]) # MAIN n,m,s = ni() s -= 1 adj = [[] for _ in range(n)] for i in range(m): u,v = nio(-1) if (v != s): adj[u].append(v) stack = [] visited= [False]*n def dfs(x): nonlocal visited nonlocal stack visited[x] = True for y in adj[x]: if not visited[y]: dfs(y) stack.append(x) for i in range(n): if not visited[i]: dfs(i) # log(adj) # log(visited) # log(stack) count = -1 def loang(x): nonlocal visited visited[x] = False for y in adj[x]: if visited[y]: loang(y) for x in stack[::-1]: if visited[x]: count += 1 loang(x) print(count)
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/999/E" }
d8168
test
n=int(input()) arr=list(map(int,input().split())) arr=sorted(arr) s=set() for val in arr: if val!=1 and val-1 not in s: s.add(val-1) elif val not in s: s.add(val) elif val+1 not in s: s.add(val+1) print(len(s))
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/1203/E" }
d8169
test
import bisect n,m = map(int,input().split()) Q = [] P = [[] for _ in range(n)] for i in range(m): p,y = map(int,input().split()) Q.append([p,y]) P[p-1].append(y) P_1 = [sorted(l) for l in P] for p,y in Q: a = str(p).zfill(6) b = str(bisect.bisect(P_1[p-1], y)).zfill(6) print(a+b)
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc113/tasks/abc113_c" }
d8170
test
N = int(input()) A = list(map(int,input().split())) A_list = [float('inf')] * N ans = min(A) while max(A_list) > 0: mi = ans for i,a in enumerate(A): amari = a % mi A_list[i] = amari if amari != 0: ans = min(ans,amari) print(ans)
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc118/tasks/abc118_c" }
d8171
test
""" Codeforces April Fools Contest 2014 Problem I Author : chaotic_iak Language: Python 3.3.4 """ class InputHandlerObject(object): inputs = [] def getInput(self, n = 0): res = "" inputs = self.inputs if not inputs: inputs.extend(input().split(" ")) if n == 0: res = inputs[:] inputs[:] = [] while n > len(inputs): inputs.extend(input().split(" ")) if n > 0: res = inputs[:n] inputs[:n] = [] return res InputHandler = InputHandlerObject() g = InputHandler.getInput ############################## SOLUTION ############################## # ?(_/____+_______*__-_____*______-___):-__<___,___<____,____<_____,_____<______,______<_______. golorp = input().split(":-") golorp[0] = golorp[0][2:] ct = 0 jaws = [] for x in range(len(golorp[0])): if golorp[0][x] == "_": ct += 1 else: jaws.append(ct) ct = 0 ct = 0 conditionsraw = [] for x in range(len(golorp[1])): if golorp[1][x] == "_": ct += 1 else: conditionsraw.append(ct) conditionsraw.append(golorp[1][x]) ct = 0 conditions = [] for x in range(0, len(conditionsraw)//4): if conditionsraw[4*x+1] == ">": conditions.append((conditionsraw[4*x+2], conditionsraw[4*x])) else: conditions.append((conditionsraw[4*x], conditionsraw[4*x+2])) inedges = [[-1]] * (max(jaws) + 1) outedges = [[-1]] * (max(jaws) + 1) val = [-1] * (max(jaws) + 1) processed = [False] * (max(jaws) + 1) for x in jaws: inedges[x] = [] outedges[x] = [] for x, y in conditions: inedges[y].append(x) outedges[x].append(y) for i in range(10): for x in jaws: if not inedges[x] and not processed[x]: val[x] += 1 processed[x] = True for y in outedges[x]: val[y] = max(val[y], val[x]) inedges[y].remove(x) failure = False for x in jaws: if not processed[x] or val[x] > 9: failure = True break if failure: print("false") else: s = "" for x in jaws: s += str(val[x]) print(s)
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/409/I" }
d8172
test
from collections import* n, m, k = map(int, input().split()) b = [[int(v) for v in input().split()] for _ in range(n)] if m < n: a = [[b[j][i] for j in range(n)] for i in range(m)] b = a m, n = n, m cntrs = [Counter() for _ in range(n)] d = (n + m-1) // 2 for i in range(1<<d): ones = bin(i).count('1') z = d - ones if ones >= n or z >= m: continue xor = b[0][0] x, y = 0, 0 for j in range(d): if i&(1<<j): x += 1 else: y += 1 xor ^= b[x][y] cntrs[x][xor] += 1 sm = 0 sleft = n + m - 2 - d for i in range(1<<sleft): ones = bin(i).count('1') z = sleft - ones if ones >= n or z >= m: continue xor = b[n-1][m-1] x, y = n-1, m-1 for j in range(sleft): if i&(1<<j): x -= 1 else: y -= 1 xor ^= b[x][y] xor ^= b[x][y] ^ k sm += cntrs[x][xor] print(sm)
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/1006/F" }
d8173
test
n = int(input()) s = input() for d in range(1, n+1): if n%d == 0: t1 = s[:d] t2 = s[d:] s = t1[::-1] + t2 print(s)
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/999/B" }
d8174
test
a, b = map(int,input().split()) print(a+b)
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/409/H" }
d8175
test
import re s = input() ops = re.split('([+-])', s) assert len(ops) % 2 == 1 ops = ['+'] + ops total = 0 for i in range(0, len(ops), 2): if ops[i] == '+': total += int(ops[i+1]) elif ops[i] == '-': total -= int(ops[i+1]) else: assert False for b in bytes(str(total), 'ascii'): print('+' * b + '.>')
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/784/G" }
d8176
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/E2" }
d8177
test
def readinput(): n=int(input()) return n def main(n): stock=[] for _ in range(10): stock.append([]) stock[0].append('') for m in range(1,10): for i in range(len(stock[m-1])): stock[m].append(stock[m-1][i]+'3') stock[m].append(stock[m-1][i]+'5') stock[m].append(stock[m-1][i]+'7') #print(stock) count=0 for m in range(3,10): for i in range(len(stock[m])): if int(stock[m][i]) <= n and '3' in stock[m][i] and '5' in stock[m][i] and '7' in stock[m][i]: count+=1 #print(stock[m][i]) return count def __starting_point(): n=readinput() ans=main(n) print(ans) __starting_point()
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc114/tasks/abc114_c" }
d8178
test
s = list(input()) ans = 0 for i in range(1, len(s)): if s[i] == s[i-1]: ans += 1 if s[i] == '1': s[i] = '0' else: s[i] = '1' print(ans)
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc124/tasks/abc124_c" }
d8179
test
n = int(input()) a = [int(x) for x in input().split()] flag = True for x in a: if x % 2 == 0: if x % 3 and x % 5: flag = False if flag: print('APPROVED') else: print('DENIED')
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc155/tasks/abc155_b" }
d8180
test
# ้ซ˜ๆฉ‹ๅ›ใฏใ‚ฟใƒƒใƒ—ใƒ€ใƒณใ‚นใ‚’ใ™ใ‚‹ใ“ใจใซใ—ใพใ—ใŸใ€‚ใ‚ฟใƒƒใƒ—ใƒ€ใƒณใ‚นใฎๅ‹•ใใฏๆ–‡ๅญ—ๅˆ— S ใง่กจใ•ใ‚Œใ€ S ใฎๅ„ๆ–‡ๅญ—ใฏ L, R, U, D ใฎใ„ใšใ‚Œใ‹ใงใ™ใ€‚ # ๅ„ๆ–‡ๅญ—ใฏ่ถณใ‚’็ฝฎใไฝ็ฝฎใ‚’่กจใ—ใฆใŠใ‚Šใ€ 1 ๆ–‡ๅญ—็›ฎใ‹ใ‚‰้ †็•ชใซ่ธใ‚“ใงใ„ใใพใ™ใ€‚ S ใŒไปฅไธ‹ใฎ 2 ๆกไปถใ‚’ๆบ€ใŸใ™ใจใใ€ใพใŸใใฎๆ™‚ใซ้™ใ‚Šใ€ S ใ‚’ใ€Œ่ธใฟใ‚„ใ™ใ„ใ€ๆ–‡ๅญ—ๅˆ—ใจใ„ใ„ใพใ™ใ€‚ # ๅฅ‡ๆ•ฐๆ–‡ๅญ—็›ฎใŒใ™ในใฆ R, U, D ใฎใ„ใšใ‚Œใ‹ใ€‚ ๅถๆ•ฐๆ–‡ๅญ—็›ฎใŒใ™ในใฆ L, U, D ใฎใ„ใšใ‚Œใ‹ใ€‚ S ใŒใ€Œ่ธใฟใ‚„ใ™ใ„ใ€ๆ–‡ๅญ—ๅˆ—ใชใ‚‰ Yes ใ‚’ใ€ใใ†ใงใชใ‘ใ‚Œใฐ No ใ‚’ๅ‡บๅŠ›ใ—ใฆใใ ใ•ใ„ใ€‚ S = str(input()) if 'L' in S[0::2] or 'R' in S[1::2]: print('No') else: print('Yes')
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc141/tasks/abc141_b" }
d8181
test
#70 C - Five Transportations N = int(input()) lis = [int(input()) for _ in range(5)] mini = min(lis) group = (N+mini-1)//mini ans = 5 + group - 1 print(ans)
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc123/tasks/abc123_c" }
d8182
test
n = int(input()) mod = 10**9 + 7 all09 = ((2 * 10**n) % mod - (2 * 9**n) % mod) % mod of09 = ((10**n) % mod - 8**n % mod) % mod print((all09-of09)%mod)
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc178/tasks/abc178_c" }
d8183
test
#!/usr/bin/env python3 import sys from itertools import chain import numpy as np def solve(X: int): if X <= 2: return 2 flags = np.array([True for i in range(3, X + 112, 2)]) for i in range(len(flags)): if flags[i]: prime = i * 2 + 3 flags[i::prime] = False if prime >= X: return prime def main(): X = int(input()) # type: int answer = solve(X) print(answer) def __starting_point(): main() __starting_point()
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc149/tasks/abc149_c" }
d8184
test
n = int(input()) v = list(map(int, input().split())) odd = [0] * (10 ** 5 + 5) even = [0] * (10 ** 5 + 5) for i in range(n): if i % 2 == 0: even[v[i]] += 1 else: odd[v[i]] += 1 sum_odd = sum(odd) sum_even = sum(even) ans = sum_odd + sum_even max_odd = max(odd) max_even = max(even) if odd.index(max_odd) != even.index(max_even): print(sum_odd + sum_even - max_even - max_odd) else: odd.sort() even.sort() if odd[-1] - odd[-2] > even[-1] - even[-2]: ans -= odd[-1] + even[-2] else: ans -= odd[-2] + even[-1] print(ans)
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc111/tasks/arc103_a" }
d8185
test
N,A,B,C = map(int,input().split()) l = [int(input()) for _ in range(N)] ans = float("inf") for i in range(4**N): a,b,c = [],[],[] cost = 0 for j in range(N): r = (i//(4**j)) % 4 if r == 1: a.append(l[j]) elif r == 2: b.append(l[j]) elif r == 3: c.append(l[j]) if a and b and c: cost += sum(max((len(x)-1), 0)*10 for x in [a,b,c]) a = sum(a) b = sum(b) c = sum(c) cost += sum(abs(x-y) for x,y in [(a,A),(b,B),(c,C)]) ans = min(ans, cost) print(ans)
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc119/tasks/abc119_c" }
d8186
test
n = int(input()) s = list(input()) for a in range(len(s)): s[a] = chr(ord(s[a]) + n) if ord(s[a])>90: s[a] = chr(ord(s[a])-26) c=s[0] for b in range(len(s)-1): c = c + s[b+1] print(c)
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc146/tasks/abc146_b" }
d8187
test
#!/usr/bin/env python from collections import Counter from math import sqrt m = 2750131 + 100 f = list(range(m)) for d in range(2, int(sqrt(m)) + 10): if f[d] == d: i, k = 2, d << 1 while k < m: if f[k] == k: f[k] = i k += d i += 1 np = list(range(m)) c = 1 for i in range(2, m): if f[i] == i: np[i] = c c += 1 n = int(input()) b = sorted(list(map(int, input().split())), reverse=True) d = Counter(b) a = [] i, la = 0, 0 while la < n: if d[b[i]] > 0: la += 1 if f[b[i]] == b[i]: a.append(np[b[i]]) d[b[i]] -= 1 d[np[b[i]]] -= 1 else: a.append(b[i]) d[b[i]] -= 1 d[f[b[i]]] -= 1 i += 1 print(*a)
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/1176/D" }
d8188
test
IN = input rint = lambda: int(IN()) rmint = lambda: map(int, IN().split()) rlist = lambda: list(rmint()) n, k = rmint() pr = [i for i in range(-1, n - 1)] nx = [i for i in range(+1, n + 1)] ans = [0] * n p = [0] * n i = 0 for g in rlist(): p[n-(g-1)-1] = i i += 1 def dl(x, t): ans[x] = t if nx[x] < n: pr[nx[x]] = pr[x] if pr[x] >= 0: nx[pr[x]] = nx[x] t = 1 for c in p: #print(ans) #print(pr) #print(nx) if ans[c]: continue dl(c, t) j = pr[c] for i in range(k): if j < 0: break dl(j, t) j = pr[j] j = nx[c] for i in range(k): if j >= n: break dl(j, t) j = nx[j] t = 3 - t for o in ans: print(o, end='')
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/1154/E" }
d8189
test
mod = 998244353 n = int(input()) a = list(map(int, input().split())) d = {} for i in range(n): if a[i] not in d: d[a[i]] = (i, i) else: d[a[i]] = (d[a[i]][0], i) d2 = {} for k, v in list(d.items()): if v[0] != v[1]: d2[k] = v active, ans = 0, 1 for i in range(n - 1): if a[i] in d2: if i == d2[a[i]][0]: active += 1 if i == d2[a[i]][1]: active -= 1 if active == 0: ans = (ans * 2) % mod print(ans)
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/1102/E" }
d8190
test
from collections import defaultdict maxn = 2000000000 mk = [] bs = 1 while bs <= maxn: mk.append(bs) bs *= 2 n = int(input()) ls = [int(i) for i in input().split()] dic = defaultdict(int) for i in ls: dic[i] += 1 cnt = 0 for i in ls: dic[i] -= 1 flag = False for j in mk: if dic[j - i] > 0: flag = True break if not flag: cnt += 1 dic[i] += 1 print(cnt)
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/1005/C" }
d8191
test
s =input() from collections import Counter count = Counter(s) c0 = count["0"] c1 = count["1"] print(min(c0,c1)*2)
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc120/tasks/abc120_c" }
d8192
test
n,m = map(int,input().split()) min_i = 1 max_i = n for i in range(m): l,r = map(int,input().split()) min_i = max(min_i,l) max_i = min(max_i,r) if max_i-min_i>=0: print(max_i-min_i+1) else: print(0)
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc127/tasks/abc127_c" }
d8193
test
n = int(input()) h = list(map(int, input().split())) res = 0 while True: if sum(h) == 0: break i = 0 while i < n: if h[i] == 0: i += 1 else: res += 1 while i < n and h[i] > 0: h[i] -= 1 i += 1 print(res)
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc116/tasks/abc116_c" }
d8194
test
stops, cap = map(int,input().split()) a = list(map(int,input().split())) start_max = cap start_min = 0 current = 0 for x in a: current += x start_max = min(cap-current, start_max) start_min = max(start_min,-current) if abs(current) > cap: print (0) break else: if start_max<start_min: print (0) else: print (start_max-start_min + 1)
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/978/E" }
d8195
test
def powof3(x): ans=0 while(x%3==0): x=x//3 ans+=1 return ans n=int(input()) a=list(map(int,input().split())) for i in range(n): a[i]=[-1*powof3(a[i]),a[i]] a.sort() for i in range(n): a[i]=a[i][1] print(*a)
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/977/D" }
d8196
test
n = int(input()) points = set(int(x) for x in input().strip().split()) powers = [2**i for i in range(31)] for point in points: for power in powers: if point + power in points and point + power + power in points: print(3) print(point, point + power, point + power + power) return for point in points: for power in powers: if point + power in points: print(2) print(point, point + power) return print(1) print(points.pop())
PYTHON
{ "starter_code": "", "url": "https://codeforces.com/problemset/problem/988/D" }
d8197
test
A,B,K = map(int,input().split()) if A >= K: print(A-K,B) elif K-A<B: print(0,B-(K-A)) else: print(0,0)
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc149/tasks/abc149_b" }
d8198
test
X = int(input()) deposit = 100 y_later = 0 while deposit < X: y_later += 1 deposit += deposit // 100 print(y_later)
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc165/tasks/abc165_b" }
d8199
test
import math K = int(input()) rst = 0 for i in range(1, K + 1): for j in range(1, K + 1): tmp = math.gcd(i, j) for k in range(1, K + 1): rst += math.gcd(tmp, k) print(rst)
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc162/tasks/abc162_c" }
d8200
test
N = int(input()) a = list(map(int,input().split())) aa = [] for i in a: aa.append(i-1) print(sum(aa))
PYTHON
{ "starter_code": "", "url": "https://atcoder.jp/contests/abc103/tasks/abc103_c" }