_id
stringlengths
2
5
partition
stringclasses
2 values
text
stringlengths
5
289k
language
stringclasses
1 value
meta_information
dict
title
stringclasses
1 value
d1201
train
def checkValidity(s): count = 0 previous = "" for x in s: if count == 0: previous = x count += 1 elif count == 1: count = 0 if previous == x: return "no" return "yes" t = int(input()) for _ in range(t): s = input() print(checkValidity(s))
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/PLAYPIAN" }
d1202
train
# cook your dish here def solve(l,r,c,row,col,po): count=0 visited=set() stack=set() stack.add((l[row][col],row,col)) while stack: ele=stack.pop() visited.add((ele[1],ele[2])) if ele[0]<po: count+=1 if ele[1]-1>=0 and (ele[1]-1,ele[2]) not in visited: if l[ele[1]-1][ele[2]]<po: stack.add((l[ele[1]-1][ele[2]],ele[1]-1,ele[2])) if ele[1]+1<r and (ele[1]+1,ele[2]) not in visited: if l[ele[1]+1][ele[2]]<po: stack.add((l[ele[1]+1][ele[2]],ele[1]+1,ele[2])) if ele[2]-1>=0 and (ele[1],ele[2]-1) not in visited: if l[ele[1]][ele[2]-1]<po: stack.add((l[ele[1]][ele[2]-1],ele[1],ele[2]-1)) if ele[2]+1<c and (ele[1],ele[2]+1) not in visited: if l[ele[1]][ele[2]+1]<po: stack.add((l[ele[1]][ele[2]+1],ele[1],ele[2]+1)) return count for _ in range(int(input())): r,c,q=map(int,input().split()) l=[] for i in range(r): a=list(map(int,input().split())) l.append(a) for i in range(q): row,col,po=map(int,input().split()) print(solve(l,r,c,row-1,col-1,po))
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/UWCOI20C" }
d1203
train
# cook your dish here d = { 'D': 238, 'T': 244, 'M': 138, 'B': 279, 'C': 186 } s = list(input()) totalCal = 0 for i in range(len(s)): if s[i] == 'D': totalCal += d['D'] if s[i] == 'T': totalCal += d['T'] if s[i] == 'M': totalCal += d['M'] if s[i] == 'B': totalCal += d['B'] if s[i] == 'C': totalCal += d['C'] R = totalCal // 50 Rm = totalCal % 50 C = Rm // 5 Cm = Rm % 5 x = totalCal - (R * 50 + C * 5) # print(totalCal - R * 50 + C * 5) W = int(x * 4 * 0.5) # print(R * 50 + C * 5 + W * 0.5) print(R) print(C) print(W)
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/RTCG2020/problems/RTCG002" }
d1204
train
import math f = math.factorial for u in range(eval(input())): n, q = list(map(int, input().split())) for j in range(q): i,k = list(map(int, input().split())) if k>i: c=0 print(c) else: a=2**(n-i) b=1 d=int(i-1) e=1 h=1 g=1 #b=f(i-1)/f(k-1)/f(i-k) if(k-1>i-k): for z in range(i-k): b=b*d d=d-1 e=e*h h=h+1 b=b/e else: for z in range(k-1): b=b*d d=d-1 e=e*g g=g+1 b=b/e c=a*b c=c%1000000007 print(c)
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/CDVA16/problems/CDVA1607" }
d1205
train
for t in range(int(input())): s = input() r = input() diff = list() index = list() cnt = 0 for i in range(len(s)): if s[i] != r[i]: cnt += 1 index.append(i) for i in range(1, len(index)): diff.append(index[i] - index[i - 1] - 1) diff.sort() fmin = cnt ** 2 oper = cnt ; moves = cnt for i in diff: moves += i oper -= 1 fmin = min(fmin, moves * oper) print(fmin)
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/MINOPS" }
d1206
train
for _ in range(int(input())): s=input() n=len(s) t=0 ans=0 for i in range(n-1): if(s[i]==s[i+1]): t=t+1 x=t for i in range(n): t=x if(i!=0): if(s[i]==s[i-1]): t=t-1 else: t=t+1 y=t for j in range(i,n): t=y try: if(s[j]==s[j+1]): t=t-1 else: t=t+1 except: pass ans=ans+t print(ans)
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/EVIPRO" }
d1207
train
from sys import stdout, stdin n,m,o = list(map(int, stdin.readline().split())) n= n+m+o l=[] a=[] for i in range(n): b= int(stdin.readline()) if(b in l and b not in a): l.append(b) a.append(b) elif(b not in l): l.append(b) a.sort() stdout.write(str(len(a)) + '\n') stdout.write(''.join([str(id) + '\n' for id in a]))
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/IARCSJUD/problems/VOTERSDI" }
d1208
train
t=int(input()) for _ in range(t): n=int(input()) a=list(map(int,input().split())) a.sort() s=sum(a) if a[0]*(s-a[0])<=a[n-1]*(s-a[n-1]): print(a[0]*(s-a[0])) else: print(a[n-1]*(s-a[n-1]))
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/KINGSHIP" }
d1209
train
T=int(input()) t=[] for _ in range(T): N=int(input()) t.append(N) N=max(t)+1 l=[0 for i in range(N)] p=1 a=1 for i in range(1,N): a=(a*i)%1000000007 p=p*a%1000000007 l[i]=p for i in t: print(l[i])
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/MATHL" }
d1210
train
# cook your dish here try: for i in range(int(input())): v1,t1,v2,t2,v3,t3=map(int,input().split()) ok = 0 if t1 <= t3 <= t2: x, y = t2 - t3, t3 - t1 ok = x * v3 <= (x + y) * v1 and y * v3 <= (x + y) * v2 print('YES' if ok else 'NO') except: pass
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/CLBATH" }
d1211
train
t=int(input()) while t: t=t-1 n,x=input().split() n=int(n) x=int(x) d,l=input().split() if d=='L': p=x elif d=='R': p=(n-x)+1 if p%2==1: if l=='H': lang='H' else: lang='E' elif p%2==0: if l=='H': lang='E' else: lang='H' print(p,lang)
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/COPT2020/problems/GRDAY1" }
d1212
train
# cook your dish here for _ in range(int(input())): s=input() while(s.count("abc")!=0): s=s.replace("abc","") print(s)
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/PBK12020/problems/ITGUY15" }
d1213
train
from sys import stdin from collections import Counter def func(arr,n,l): count=0 k=l//n if n<len(arr): for ele in arr[0:n]: count+=max(0,k-ele) else: for ele in arr: count+=max(0,ele-k) return count for _ in range(int(stdin.readline())): s=stdin.readline().strip() d=Counter(s) arr=sorted(list(d.values()),reverse=True) l=len(s) val=[1] for i in range(2,27): if l%i==0: val.append(i) ans = float('inf') for ele in val: x = func(arr,ele,l) if x < ans: ans = x print(ans)
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/ARTBALAN" }
d1214
train
# cook your dish here for t in range(int(input())): x1,x2,x3,v1,v2=[int(x)for x in input().rstrip().split()] t1=abs(x3-x1)/v1 t2=abs(x3-x2)/v2 if t1<t2: print("Chef") elif t1>t2: print("Kefa") elif t1==t2: print("Draw") else: pass
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/CHEFRUN" }
d1215
train
try: t=int(input()) for i in range(t): print("Case {}:".format(i+1), end=" ") m, n = map(int,input().split()) x, y = map(int,input().split()) l = int(input()) a=input() destx = a.count("R")-a.count("L") desty = a.count("U")-a.count("D") #print(destx, desty) if (destx<0 or destx>m) or (desty<0 or desty>n): result = "DANGER" elif destx == x and desty == y: result = "REACHED" else: result = "SOMEWHERE" print(result) except: pass
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/ZUBREACH" }
d1216
train
def isSolvable( W, R): LW, LR, F, ML, AW, V, LMap = len(W), len(R), set([w[0] for w in W+[R]]), max(map(len, W+[R])), W+[R], set(), {} if LR < ML: return False def dfs(d,i,c): if d == ML: return c == 0 if i == len(W) + 1: s = sum(LMap[w[-d-1]] if d < len(w) else 0 for w in W) + c return dfs(d+1,0,s//10) if s % 10 == LMap[R[-d-1]] else False if i < LW and d >= len(W[i]): return dfs(d,i+1,c) ch = AW[i][-d-1] if ch in LMap: return dfs(d,i+1,c) for x in range((ch in F), 10): if x not in V: LMap[ch], _ = x, V.add(x) if dfs(d,i+1,c): return True V.remove(LMap.pop(ch)) return dfs(0,0,0) n=int(input()) W=[] for i in range(n): W.append(str(input())) R=input() a=(isSolvable(W,R)) if a==True: print("true") else: print("false")
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/CHLG2020/problems/MATH88" }
d1217
train
t=int(input()) for i in range(t): n,k=map(int,input().split()) m=list(map(int,input().split())) a=0 for i in m: if i>=k: a=1 break if a==1: print('YES') else: print('NO')
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/PCJ18A" }
d1218
train
def fun(a,cur,n,cnt): if cur>=n-1: return for i in range(cur,n-1): if i<n-2: if a[i]>0 and a[i+1]>0: a[i]-=1 a[i+1]-=1 a[i+2]+=1 cnt[0]=(cnt[0]+1)%1000000007 fun(a,i,n,cnt) a[i]+=1 a[i+1]+=1 a[i+2]-=1 else: if a[i]>0 and a[i+1]>0: a[i]-=1 a[i+1]-=1 a.append(1) cnt[0]=(cnt[0]+1)%1000000007 fun(a,i,n+1,cnt) a[i]+=1 a[i+1]+=1 a.pop() tc=int(input()) for case in range(tc): n=int(input()) a=list(map(int,input().split())) cnt=[1] fun(a,0,n,cnt) print(cnt[0]%1000000007)
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/AUG17/problems/CHEFFA" }
d1219
train
t=int(input()) for i in range(t): x,n=[int(g) for g in input().split()] sal=0 day=x while day<n: sal=sal+day day+=x print(sal)
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/AARA2018/problems/ARMBH1" }
d1220
train
t = int(input()) while t != 0: M = 1000000007 n, m = list(map(int, input().split())) ans = 1 tt = n//2 tt = tt * (tt + 1) ans = pow(m, tt, M) print(ans) t -= 1
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/INRO2021/problems/JEWELMIN" }
d1221
train
import sys from collections import defaultdict from copy import copy R = lambda t = int: t(eval(input())) RL = lambda t = int: [t(x) for x in input().split()] RLL = lambda n, t = int: [RL(t) for _ in range(n)] def solve(): N, Q = RL() P = RL() B = RL() phones = sorted(zip(P, B)) S = defaultdict(lambda : []) for p, b in phones: for i in range(2**7): if (i>>b) & 1: S[i] += [p] B = set(B) I = [0] * len(B) for _ in range(Q): b, K = RL() s = RL() x = 0 for b in s: x += 1<<b if len(S[x]) < K: print(-1) else: print(S[x][-K]) T = 1#R() for t in range(1, T + 1): solve()
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/ENJU2020/problems/ECJN209" }
d1222
train
from math import sqrt T = int(input()) ans = [] for _ in range(T): X = int(input()) count = 0 x = 0 y = 0 while(x<=X): p = int(sqrt(y)) count += 1 if(p*p>y): x = p y += p**2 else: x = p+1 y += (p+1)**2 if(x<=X): ans.append(count) else: ans.append(count-1) for i in ans: print(i)
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/TWOVRIBL" }
d1223
train
def sort_str(s): o = [] for c in s: o.append(c) o.sort() return "".join(o) def find_ana(s): if len(s) <= 1: return 0 h = {} c = 0 for i in range(len(s)): for j in range(i+1, len(s)+1): t = sort_str(s[i:j]) if t in h: c += h[t] h[t] += 1 else: h[t] = 1 return c t = int(input()) for _ in range(t): print(find_ana(input()))
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/COCU2016/problems/CURR2" }
d1224
train
t=int(input()) def vsense(val,a,l): sense=0 ctr=a for c in range(n): if val[c]<=ctr: sense+=-1 else: sense+=1 ctr+=l return sense while t: n,l,a,b=list(map(int,input().split())) val=list(map(int,input().split())) val.sort() sense=0 if b==a+n*l or vsense(val,a,l)<=0: loc=a else: st=a end=b-n*l while st<=end: m=(st+end)/2 chk=vsense(val,m,l) if chk==0: loc=m break elif chk<0: end=m-1 else: loc=m st=m+1 ans=0 st=loc for c in range(n): ans+=abs(st-val[c]) st+=l print(ans) t-=1
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/CONSESNK" }
d1225
train
import fractions import sys f = sys.stdin if len(sys.argv) > 1: f = open(sys.argv[1], "rt") sum_cache = {} def sum_func(x): if x < 10: return x r = sum_cache.get(x) if r is not None: return r xx = 0 while x > 0: xx += x % 10 x /= 10 r = sum_func(xx) sum_cache[x] = r return r def test(): for n in range(1): print(n, sum_func(n)) print(sum_func(int(10**18 - 1))) #~ test() #~ sys.exit(1) cycle_table = [ # Cycle len, markers # D_kfunc [9, [1, 1, 1, 1, 1, 1, 1, 1, 1]], # 1 [9, [1, 1, 1, 1, 1, 1, 1, 1, 1]], # 2 [3, [1, 0, 0, 1, 0, 0, 1, 0, 0]], # 3 [9, [1, 1, 1, 1, 1, 1, 1, 1, 1]], # 4 [9, [1, 1, 1, 1, 1, 1, 1, 1, 1]], # 5 [3, [1, 0, 0, 1, 0, 0, 1, 0, 0]], # 6 [9, [1, 1, 1, 1, 1, 1, 1, 1, 1]], # 7 [9, [1, 1, 1, 1, 1, 1, 1, 1, 1]], # 8 [1, [1, 0, 0, 0, 0, 0, 0, 0, 0]], # 9 ] NUMBER = 9 def calc(A_1, D, L, R): #~ print('calc ===', A_1, D, L, R) A_L = A_1 + D * (L - 1) A_L_kfunc = sum_func(A_L) D_kfunc = sum_func(D) #~ print(A_L, A_L_kfunc, D_kfunc) n = R - L + 1 if D == 0: return n * A_L_kfunc cycle_len = cycle_table[D_kfunc - 1][0] cycle_markers = list(cycle_table[D_kfunc - 1][1]) # copy #~ print('cycle_len', cycle_len) whole_part = n // cycle_len remainder = n % cycle_len #~ print('whole_part, remainder = ', whole_part, remainder) counts = [whole_part * x for x in cycle_markers] #~ print(counts) pos = 0 for i in range(remainder): counts[pos] += 1 pos = (pos + D_kfunc) % NUMBER #~ print(counts) r = 0 for i, x in enumerate(counts): value = (A_L_kfunc - 1 + i) % NUMBER + 1 r += value * x return r def calc_dumb(A_1, D, L, R): #~ print('dumb ===', A_1, D, L, R) a = A_1 + D * (L - 1) n = R - L + 1 r = 0 for i in range(n): value = sum_func(a) #~ print(a, value) r += value a += D return r def test1(): a1 = 1 L = 1 R = 1000 for d in range(100): r1 = calc_dumb(a1, d, L, R) r2 = calc(a1, d, L, R) if r1 != r2: print(a1, d, L, R, ":", r1, r2) def test2(): a1 = 1 d = 9 L = 1 R = 9 r1 = calc_dumb(a1, d, L, R) r2 = calc(a1, d, L, R) print(r1, r2) #~ test1() #~ sys.exit(1) T = int(f.readline().strip()) for case_id in range(1, T+1): A_1, D, L, R = list(map(int, f.readline().strip().split())) r = calc(A_1, D, L, R) print(r)
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/NOV15/problems/KFUNC" }
d1226
train
t=eval(input()) def func(k,n,x,dist,graph): if k==n: x+=[dist[n]] return for i in range(1,n+1): if graph[k][i]!=0 and dist[i]==-1: dist[i]=dist[k]+graph[k][i] func(i,n,x,dist,graph) dist[i]=-1 while t: graph=[[0 for i in range(11)]for j in range(11)] v,e=list(map(int,input().split())) for i in range(e): x,y,w=list(map(int,input().split())) graph[x][y]=w graph[y][x]=w x=[] dist=[-1]*(v+1) dist[1]=0 func(1,v,x,dist,graph) x.sort() val=x[0] ans=0 for i in range(len(x)): if val==x[i]: ans+=1 print(ans) t-=1
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/CIELTOMY" }
d1227
train
from collections import defaultdict from itertools import product def solve(mouse,n,m): # shadow matrix will contains the count of mice which affect (i,j) position # if there is a mice at position (i,j) then in shadow matrix it will affect         all four adjacent blocks shadow=[[0 for i in range(m)]for j in range(n)] for i,j in product(list(range(n)),list(range(m))): if mouse[i][j]==1: if i>0: shadow[i-1][j]+=1 if j>0: shadow[i][j-1]+=1 if i<n-1: shadow[i+1][j]+=1 if j<m-1: shadow[i][j+1]+=1 # dp is a dictionary which contains a tuple of 3 values (i,j,0)=>we are         coming at destination (i,j) from left side # (i,j,1)=> we are coming at destination (i,j) from top dp=defaultdict(int) # dp[(0,0,0)]=dp[(0,0,1)]=shadow[0][0]-mouse[0][0] # fill only first row # in first row we can only reach at (0,j) from (0,j-1,0) as we can't come         from top. # so here we will assign count of mices which will affect current cell        (shadow[0][i]) + previous result i.e,(0,j-1,0) and # if mouse is in the current cell than we have to subtract it bcoz we have         add it twice i.e, when we enter at this block # and when we leave this block for i in range(1,m): dp[(0,i,0)]=dp[(0,i,1)]=shadow[0][i]-mouse[0][i]+dp[(0,i-1,0)] # same goes for first column # we can only come at (i,0) from (i-1,0) i.e top for i in range(1,n): dp[(i,0,0)]=dp[(i,0,1)]=shadow[i][0]-mouse[i][0]+dp[(i-1,0,1)] # for rest of the blocks # for a block (i,j) we have to add shadow[i][j] and subtract mouse[i][j]         from it for double counting # now for each block we have two choices, either take its previous block         with same direction or take previous block with different # direction and subtract corner double counted mouse. We have to take min of         both to find optimal answer for i,j in product(list(range(1,n)),list(range(1,m))): a=shadow[i][j]-mouse[i][j] b=a a+=min(dp[(i,j-1,0)],dp[(i,j-1,1)]-mouse[i-1][j]) b+=min(dp[(i-1,j,1)],dp[(i-1,j,0)]-mouse[i][j-1]) dp[(i,j,0)]=a dp[(i,j,1)]=b # what if [0][0] and [n-1][m-1] have mice, so we have to add them as we         haven't counted them yet. return min(dp[(n-1,m-1,0)],dp[(n-1,m-1,1)])+mouse[0][0]+mouse[n-1][m-1] for _ in range(int(input())): n,m=list(map(int,input().split( ))) mouse=[] for i in range(n): x=input() mouse.append(list(map(int,x))) print(solve(mouse,n,m))
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/LEMOUSE" }
d1228
train
for _ in range(int(input())): l=list(map(str,input().split())) a=[(1,3,5),(1,3,6),(1,4,5),(1,4,6),(2,3,5),(2,3,6),(2,4,5),(2,4,6)] c=0 for i in a: if len(set([l[i[0]-1],l[i[1]-1],l[i[2]-1]]))==1: c=1 break if c==1: print("YES") else: print("NO")
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/CHCUBE" }
d1229
train
for _ in range(int(input())): n=int(input()) a=[] b=[] for i in range(4*n-1): c,d=list(map(int,input().split())) a.append(c) b.append(d) c1=0 c2=0 for i in a: c1^=i for i in b: c2^=i print(c1,c2)
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/PTMSSNG" }
d1230
train
for _ in range(int(input())): n, k = map(int, input().split()) arr= list(map(int, input().split())) motu, tomu = [], [] for i in range(n): if i%2 == 0: motu.append(arr[i]) else: tomu.append((arr[i])) motu.sort(reverse=True) tomu.sort() for i in range(len(motu)): if len(tomu)-1<i: break if k==0: break if tomu[i]<motu[i]: tomu[i], motu[i] = motu[i], tomu[i] k-=1 if sum(tomu) > sum(motu): print("YES") else: print("NO")
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/MTYFRI" }
d1231
train
dic = {} #num = "1" #def tonum(num): # res=0 # for i in range(len(num)): # res = 2*res + int(num[i]) # return res #for i in range(64): # number = tonum(num) # dic[num] = [] # num = num+"0" n = int(input()) flag=0 if n >= 68: inp = input() print("Yes") else: inp = [int(x) for x in input().split()] for i in range(len(inp)-1): for j in range(i+1,len(inp)): xor = inp[i]^inp[j] if xor in list(dic.keys()): for pair in dic[xor]: (x,y) = pair if x != i and y!=j and x!=j and y!=i: flag = 1 break dic[xor].append((i,j)) else: dic[xor] = [] dic[xor].append((i,j)) if flag is 1: break if flag is 1: break if flag is 1: print("Yes") else: print("No")
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/JULY12/problems/GRAYSC" }
d1232
train
from operator import add from functools import reduce choices=[] for x in range(1800): num_str = list(map (int, str (2**x))) suma = reduce (add, num_str) choices.append(suma) N=int(input()) for x in range(N): t=int(input()) print(choices[t])
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/AGTK2012/problems/ALG2N" }
d1233
train
# cook your dish here class node: def __init__(self,a,b=0,c=0): self.val=a self.a=b self.b=c arr=[] def finder(node,val): if(arr[node].val==0): return val else: a=finder(arr[node].a,val) b=finder(arr[node].b,val) if(arr[node].val==1): return a+b-a*b else: return a*b t=int(input()) while(t>0): x=input() n=int(input()) arr.append(node(0)) for i in range(0,n): vals=input().split() sz=len(vals) for i in range(0,sz): vals[i]=int(vals[i]) if(vals[0]==0): next=node(0) arr.append(next) else: next=node(vals[0],vals[1],vals[2]) arr.append(next) lower=0.0 higher=1.0 eps=1e-9 while((higher-lower)>eps): mid=(higher+lower)/2.0 if(finder(n,mid)>0.5): higher=mid else: lower=mid print("%.5f" %(higher)) arr=[] # print(higher) t-=1
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/CIRCUITS" }
d1234
train
import sys def GRIG(L): LENT = len(L) MINT = 1 GOT = 0 DY = [ [{x: 0 for x in range(0, 10)}, 0, 0] ] for i in L: DY.append([{x: 0 for x in range(0, 10)}, 0, 0]) GOT += 1 for j in range(0, GOT): if DY[j][0][i] == 1: DY[j][0][i] = 0 DY[j][1] -= 1 else: DY[j][0][i] = 1 DY[j][1] += 1 DY[j][2] += 1 if DY[j][1] <= 1 and DY[j][2] > MINT: MINT = DY[j][2] return MINT TESTCASES = int(input().strip()) for i in range(0, TESTCASES): L = [int(x) for x in list(input().strip())] print(GRIG(L))
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/COVO2020/problems/GRIG" }
d1235
train
divisors = [1 , 2 , 3 , 4 , 6 , 8 , 9 , 10 , 12 , 16 , 18 , 20 , 24 , 30 , 32 , 36 , 40 , 48 , 60 , 64 , 72 , 80 , 84 , 90 , 96 , 100 , 108 , 120 , 128 , 144 , 160 , 168 , 180 , 192 , 200 , 216 , 224 , 240 , 256 , 288 , 320 , 336 , 360 , 384 , 400 , 432 , 448 , 480 , 504 , 512 , 576 , 600 , 640 , 672 , 720 , 768 , 800 , 864 , 896 , 960 , 1008 , 1024 , 1152 , 1200 , 1280 , 1344 , 1440 , 1536 , 1600 , 1680 , 1728 , 1792 , 1920 , 2016 , 2048 , 2304 , 2400 , 2688 , 2880 , 3072 , 3360 , 3456 , 3584 , 3600 , 3840 , 4032 , 4096 , 4320 , 4608 , 4800 , 5040 , 5376 , 5760 , 6144 , 6720 , 6912 , 7168 , 7200 , 7680 , 8064 , 8192 , 8640 , 9216 , 10080 , 10368 , 10752 , 11520 , 12288 , 12960 , 13440 , 13824 , 14336 , 14400 , 15360 , 16128 , 16384 , 17280 , 18432 , 20160 , 20736 , 21504 , 23040 , 24576 , 25920 , 26880 , 27648 , 28672 , 28800 , 30720 , 32256 , 32768 , 34560 , 36864 , 40320 , 41472 , 43008 , 46080 , 48384 , 49152 , 51840 , 53760 , 55296 , 57600 , 61440 , 62208 , 64512 , 65536 , 69120 , 73728 , 80640 , 82944 , 86016 , 92160 , 96768 , 98304 , 103680 , 107520 , 110592 , 115200 , 122880 , 124416 , 129024 , 131072 , 138240 , 147456 , 153600 , 161280 , 165888 , 172032 , 184320 , 193536 , 196608 , 207360 , 215040 , 221184 , 230400 , 245760] numbers = [1 , 2 , 4 , 6 , 12 , 24 , 36 , 48 , 60 , 120 , 180 , 240 , 360 , 720 , 840 , 1260 , 1680 , 2520 , 5040 , 7560 , 10080 , 15120 , 20160 , 25200 , 27720 , 45360 , 50400 , 55440 , 83160 , 110880 , 166320 , 221760 , 277200 , 332640 , 498960 , 554400 , 665280 , 720720 , 1081080 , 1441440 , 2162160 , 2882880 , 3603600 , 4324320 , 6486480 , 7207200 , 8648640 , 10810800 , 14414400 , 17297280 , 21621600 , 32432400 , 36756720 , 43243200 , 61261200 , 73513440 , 110270160 , 122522400 , 147026880 , 183783600 , 245044800 , 294053760 , 367567200 , 551350800 , 698377680 , 735134400 , 1102701600 , 1396755360 , 2095133040 , 2205403200 , 2327925600 , 2793510720 , 3491888400 , 4655851200 , 5587021440 , 6983776800 , 10475665200 , 13967553600 , 20951330400 , 27935107200 , 41902660800 , 48886437600 , 64250746560 , 73329656400 , 80313433200 , 97772875200 , 128501493120 , 146659312800 , 160626866400 , 240940299600 , 293318625600 , 321253732800 , 481880599200 , 642507465600 , 963761198400 , 1124388064800 , 1606268664000 , 1686582097200 , 1927522396800 , 2248776129600 , 3212537328000 , 3373164194400 , 4497552259200 , 6746328388800 , 8995104518400 , 9316358251200 , 13492656777600 , 18632716502400 , 26985313555200 , 27949074753600 , 32607253879200 , 46581791256000 , 48910880818800 , 55898149507200 , 65214507758400 , 93163582512000 , 97821761637600 , 130429015516800 , 195643523275200 , 260858031033600 , 288807105787200 , 391287046550400 , 577614211574400 , 782574093100800 , 866421317361600 , 1010824870255200 , 1444035528936000 , 1516237305382800 , 1732842634723200 , 2021649740510400 , 2888071057872000 , 3032474610765600 , 4043299481020800 , 6064949221531200 , 8086598962041600 , 10108248702552000 , 12129898443062400 , 18194847664593600 , 20216497405104000 , 24259796886124800 , 30324746107656000 , 36389695329187200 , 48519593772249600 , 60649492215312000 , 72779390658374400 , 74801040398884800 , 106858629141264000 , 112201560598327200 , 149602080797769600 , 224403121196654400 , 299204161595539200 , 374005201994424000 , 448806242393308800 , 673209363589963200 , 748010403988848000 , 897612484786617600 , 1122015605983272000 , 1346418727179926400 , 1795224969573235200 , 2244031211966544000 , 2692837454359852800 , 3066842656354276800 , 4381203794791824000 , 4488062423933088000 , 6133685312708553600 , 8976124847866176000 , 9200527969062830400] t = int(input()) for x in range(0, t): a = int(input()) i = 0 for y in divisors: if y > a: print("win", numbers[i]) break i = i+1 else: print("lose")
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/IOPC2012/problems/IOPC1211" }
d1236
train
print(25)
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/CMR12121/problems/DGLST" }
d1237
train
t = int(input()) for _ in range(t): n = int(input()) a = input().strip() prev = a[0] ans = -1 for i in a: if prev == i: ans += 1 prev = i print(ans)
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/CDGO2021/problems/DIFFPENS" }
d1238
train
# cook your dish here for _ in range(int(input())): a,b,c=list(map(int, input().split())) p=a*100+b mx=p ans, cnt = 0, 0 while True: cnt+=1 if p<c or cnt==10000: break else: p-=c a=p//100 b=p%100 p=b*100+a if p>mx: mx=p ans=cnt print(ans)
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/MONTRANS" }
d1239
train
test=int(input()) for i in range(test): N=input() X=[] list2=[] for x in N: X.append(x) list1=[] list1=list(set(X)) output='' for x in list1: for y in X: if int(x)>=6: n=int(x)*10+int(y) list2.append(n) for j in list1: if int(j)>=6: m=int(j)*10+int(j) list2.remove(m) list2.sort() if len(list2)==0: print(" ") else: list2.sort() for k in list2: if chr(k) not in output and 64<k<91: output+=chr(k) print(output)
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/CHEFPDIG" }
d1240
train
# cook your dish here t=int(input()) for _ in range(t): n = int(input()) for i in range(n+1): b = n for space in range(n-i): print(" ",end="") for j in range(i+1): print(b,end="") b-=1 print() for l in range(n): a = n for j1 in range(0,l+1): print(" ",end="") for k in range(n-l): print(a,end="") a-=1 print()
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/PBK32020/problems/ITGUY28" }
d1241
train
# cook your dish here t = int(input()) while t: x = int(input()) arr = [int(i) for i in input().split()] total = 0 for i in arr: if i % 6 == 0: total += 6 else: total += (i % 6) print(total) t -= 1
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/PEND2020/problems/ITGUY00" }
d1242
train
n=int(input()) for i in range(n): k,x=map(int,input().split()) l=list(map(int,input().split())) f,e,o=0,0,0 for i in l: if(i%2==0): e+=1 else: o+=1 if(o<=x//2): f=1 elif(e<=x//2): if((k-x)%2!=0): f=0 else: f=1 else: if(x%2==0): f=1 else: f=0 if(f==1): print('Jesse') else: print('Walter')
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/GMSTN" }
d1243
train
from math import * for t in range(int(input())): n = int(input()) numberlist = list(map(int,input().split())) numberlist.sort() print(numberlist[0]* ( len(numberlist) -1))
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/MNMX" }
d1244
train
a = int(input()) for i in range(a): b = input() if '5' in b or '0' in b: print(1) continue print(0)
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/PSTR2020/problems/ITGUY06" }
d1245
train
c=0 for i in range (int(input ())): a, b=map(int, input().split()) c+=abs(a-b)+1 print(c%((10**9) +7))
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/COW42020/problems/COW3C" }
d1246
train
n = int(input()) l = [0] * n for x in range(n): l[x] = int(input()) for i in range(n): z = 1 for j in range(1,l[i]+1): for k in range(1,l[i]+1): print(z,end='') z += 2 print()
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/PTRN2021/problems/ITGUY51" }
d1247
train
# cook your dish here l1=int(input()) for i in range(l1): x=int(input()) y=list(map(int,input().split())) z=list(map(int,input().split())) if max(z)!=max(y): print('YES') else: print('NO')
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/CHPTRS01/problems/FUNRUN" }
d1248
train
import sys sys.setrecursionlimit(10000000) def mergeSortInversions(arr): if len(arr) == 1: return arr, 0 larr=len(arr) a = arr[:larr//2] b = arr[larr//2:] a, ai = mergeSortInversions(a) b, bi = mergeSortInversions(b) c = [] i = 0 j = 0 inversions = 0 + ai + bi la=len(a) while i < la and j < len(b): if a[i] <= b[j]: c.append(a[i]) i += 1 else: c.append(b[j]) j += 1 inversions += (la-i) c += a[i:] c += b[j:] return c, inversions for _ in range(int(input())): n,d=list(map(int,input().split())) p=[int(o) for o in input().split()] array=[[] for i in range(d)] flag=0 for i in range(n): array[i%d].append(p[i]) if p[i]%((i%d)+1)!=0: flag=1 ans=0 dumarr=[0]*n for i in range(d): array[i],v=mergeSortInversions(array[i]) for j in range(len(array[i])): dumarr[i+j*d]=array[i][j] ans+=v p=sorted(p) # print(dumarr) if dumarr==p: print(ans) else: print(-1)
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/DPERM" }
d1249
train
# cook your dish here def finder(n): cnt=0 for i in range(2,n+1): a=n while a!=0: r=a%i a=a//i if r==1: cnt+=1 return cnt t=int(input()) for _ in range(t): n=int(input()) if n==0: print(0) elif n==1: print('INFINITY') else: print(finder(n))
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/BASE" }
d1250
train
# cook your dish here for i in range(int(input())): n,k=[int(i) for i in input().split()] if(n%2==0): if(k<(n*(n+1))//2 - 1 or k>3*((n//2)**2) - 1):print(-1) elif(k==(n*(n+1))//2 - 1): for i in range(1,n+1):print(i,'',end='') print() else: k,count,p,l,x = k-(n*(n+1))//2 + 1,0,0,[0 for i in range(n)],1 while(k>0):p+=2 ;k,count = k-n+p ,count+1 for i in range(n,n-count+1,-1):l[x]=i ;x+=2 k=-k ;l[2*count - 1 +k],p = n-count+1 ,1 for i in range(n): if(l[i]==0):l[i]=p ; p+=1 for i in l:print(i,'',end='') print() else: if(n==1):print(1) if(k==0) else print(-1) elif(k<(n*(n+1))//2 - 1 or k>3*(n//2)*(n//2 + 1)):print(-1) elif(k==(n*(n+1))//2 - 1): for i in range(1,n+1):print(i,'',end='') print() else: k,count,p,l,x = k-(n*(n+1))//2 + 1,0,0,[0 for i in range(n)],1 while(k>0): p+=2 ; k,count = k-n+p ,count+1
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/GENPERM" }
d1251
train
t=int(input()) for _ in range(t): n=int(input()) p=10**9+7 a=(pow(3,n+1,p)-1) b=(pow(2,n+1,p)-1) print((((3*a)//2)%p-(2*(b))%p+p)%p)
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/ALQU2018/problems/GDP" }
d1252
train
import sys def _r(*conv) : r = [conv[i](x) for i, x in enumerate(input().strip().split(' '))] return r[0] if len(r) == 1 else r def _ra(conv) : return list(map(conv, input().strip().split(' '))) def _rl() : return list(input().strip()) def _rs() : return input().strip() def _a(k, *v) : return all(x == k for x in v) def _i(conv) : for line in sys.stdin : yield conv(line) ################################################################## n = _r(int) lookup = dict([(x, i) for i, x in enumerate(_ra(str))]) g = [(set(), dict()) for _ in range(n)] m = _r(int) for _ in range(m) : c1, c2, d = _r(str, str, int) i1 = lookup[c1] g[i1][0].add(c2) g[i1][1][c2] = d t = _r(int) for _ in range(t) : k = _ra(str)[1:] failed = False if len(set(k)) != len(k) : failed = True if not failed : if k[0] not in lookup : failed = True else : r = 0 v = g[lookup[k[0]]] for i in range(1, len(k)) : if k[i] not in v[0] : failed = True break r += v[1][k[i]] v = g[lookup[k[i]]] if not failed : print(r) if failed : print('ERROR')
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/TRAVELER" }
d1253
train
# cook your dish here import math N = 10**6 sum_arr = [0] * (N + 1) def lprime(): arr = [0] * (N + 1) arr[0] = 1 arr[1] = 1 for i in range(2, math.ceil(math.sqrt(N) + 1)): if arr[i] == 0: for j in range(i * i, N + 1, i): arr[j] = 1 curr_prime_sum = 0 for i in range(1, N + 1): if arr[i] == 0: curr_prime_sum += i sum_arr[i] = curr_prime_sum n=int(input()) lprime() for _ in range(n): x=int(input()) print(sum_arr[x]%10)
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/CSEP2020/problems/IRVS" }
d1254
train
# cook your dish here T = int(input()) for i in range(T): N,data,D,People = int(input()),list(map(int,list(input()))),int(input()),list(map(int,input().split())) data.insert(0,"|"),data.append("|") infected = [] for i in range(1,N+1): if(data[i]==1): infected.append(i) i = 0 while(i<D): boundary = People[i] + i data.insert(boundary,"|") times = len(infected) for p in range(times): index = infected[p] if(index>=boundary): index+=1 infected[p]+=1 if(data[index]==1): if(data[index+1]==0): data[index+1] = 1 infected.append(index+1) if(data[index-1]==0): data[index-1] = 1 infected.append(index-1) else: infected.remove(index) times-=1 i+=1 infected.sort() print(data.count(1))
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/CHPTRS01/problems/WASHHAND" }
d1255
train
t = int(input()) for z in range(t) : n,p = [int(x) for x in input().split()] a = [int(x) for x in input().split()] c = [x for x in a if x >= p//2] h = [x for x in a if x <= p//10] if len(c)==1 and len(h)==2 : print("yes") else: print("no")
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/PERFCONT" }
d1256
train
for _ in range(int(input())): s,k=map(str,input().split()) k=int(k) n="NOPE" al=[0]*26 for ele in s: al[ord(ele)-ord('a')]=1 l=len(s) ans=[] # print(al) for i in range(26): if len(ans)==l: break elif al[i]==1 and k>0: k-=1 ans.append(chr(i+ord('a'))) elif al[i]==0: ans.append(chr(i+ord('a'))) if len(ans)!=l: print(n) else: print("".join(ans))
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/SDIFFSTR" }
d1257
train
# cook your dish here t = int(input()) res = [] for i in range(t): n = int(input()) arr = [int(i) for i in input().split()] num_2 = 0 num = 0 for j in range(len(arr)): if arr[j] == 2: num_2 += 1 if arr[j] > 2: num += 1 res.append(num_2 * num + (num * (num - 1)) // 2) for z in res: print(z)
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/PROSUM" }
d1258
train
factorials=[1] for x in range(1,201): factorials.append(factorials[x-1]*x) x=int(input()) for x in range(x): n=int(input()) print(factorials[n])
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/AGTK2012/problems/ALGFACT" }
d1259
train
s=int(input()) while(s>0): s-=1 a=input() c=0 for x in a: c+=int(x) if(c<9 and len(a)!=1): print(9-c%9) else: print(min(9-c%9,c%9))
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/DIVNINE" }
d1260
train
# cook your dish here t=int(input()) for _ in range(t): n,m = map(int,input().split()) count=0 for i in range(n,m+1): p=str(i) if p[-1]=='2' or p[-1]=='3' or p[-1]=='9': count+=1 print(count)
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/NUM239" }
d1261
train
def merge(intervals,start,mid,end): al = mid-start+1 bl = end-mid A = intervals[start:mid+1] B = intervals[mid+1:end+1] p=0;q=0;k=start; while(p<al and q<bl): if(A[p]<B[q]): intervals[k] = A[p] k+=1;p+=1; else: intervals[k] = B[q] k+=1;q+=1; while(p<al): intervals[k] = A[p] k+=1;p+=1; while(q<bl): intervals[k] = B[q] k+=1;q+=1; def mergesort(intervals, start, end): if(start<end): mid = int((start+end)/2) mergesort(intervals,start,mid) mergesort(intervals,mid+1,end) merge(intervals,start,mid,end) t = int(input()) for _ in range(t): n,m,k = map(int, input().split()) cities = [[0,[]] for i in range(n)] for i in range(m): a,b = map(int, input().split()) cities[a-1][1].append(b-1) cities[b-1][1].append(a-1) li = list(map(int, input().split())) def specialfunction(): mergesort(li,0,n-1) if(k>len(li)): print(-1) else: sum = 0 front = 0 rear = len(li)-1 for i in range(k): if(i%2==0): sum += li[rear] rear -= 1 else: sum += li[front] front += 1 print(sum) if(m == 0): specialfunction() continue for i in range(n): cities[i][0] = li[i] visited = [-1 for i in range(n)] count = 0 museummonths = [] def searchUnvisited(): for i in range(n): if(visited[i] == -1): return i return -1 def bfs(ind,count): museumcount = 0 queue = [] queue.append(ind) visited[ind] = 1 museumcount += cities[ind][0] count += 1 front = 0 rear = 0 while(front<=rear): noe = len(cities[ind][1]) for i in range(noe): if(visited[cities[ind][1][i]] == -1): queue.append(cities[ind][1][i]) rear += 1 count += 1 museumcount += cities[cities[ind][1][i]][0] visited[cities[ind][1][i]] = 1 front += 1 try: ind = queue[front] except: break museummonths.append(museumcount) return count while(count<n): for i in range(n): if(visited[i] == -1): count = bfs(i,count) mergesort(museummonths,0,len(museummonths)-1) #print(museummonths) if(k>len(museummonths)): print(-1) else: sum = 0 front = 0 rear = len(museummonths)-1 for i in range(k): if(i%2==0): sum += museummonths[rear] rear -= 1 else: sum += museummonths[front] front += 1 print(sum)
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/INOIPRAC/problems/ROADTRIP" }
d1262
train
import fractions import sys f = sys.stdin if len(sys.argv) > 1: f = open(sys.argv[1], "rt") def calc(N, M): if M != N: return [(-1, -1)] r = [(i+1, ((i+1) % N)+1) for i in range(N)] return r T = int(f.readline().strip()) for case_id in range(1, T+1): N, M = list(map(int, f.readline().strip().split())) rr = calc(N, M) for a, b in rr: print(a, b)
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/LTIME31/problems/EXNETWRK" }
d1263
train
t=int(input()) for _ in range(t): n,m=[int(x) for x in input().split()] mat=[] ans=[] for i in range(n+2): l=[] p=[] for j in range(m+2): l.append(0) p.append(1000000000) mat.append(l) ans.append(p) y=int(input()) for i in range(y): a,b=[int(x) for x in input().split()] mat[a][b]=1 ans[a][b]=0 y=int(input()) for i in range(y): a,b=[int(x) for x in input().split()] mat[a][b]=1000000000 ans[a][b]=1000000000 for i in range(1,n+1): for j in range(1,m+1): if mat[i][j]==1 or mat[i][j]==1000000000: continue else: ans[i][j]=min(ans[i][j],ans[i][j-1]+1,ans[i-1][j]+1) for i in range(n,0,-1): for j in range(m,0,-1): if mat[i][j] == 1 or mat[i][j] == 1000000000: continue else: ans[i][j]=min(ans[i][j],ans[i+1][j]+1,ans[i][j+1]+1) for i in range(1,n+1): for j in range(m, 0, -1): if mat[i][j] == 1 or mat[i][j] == 1000000000: continue else: ans[i][j] = min(ans[i][j], ans[i - 1][j] + 1, ans[i][j + 1] + 1) for i in range(n, 0, -1): for j in range(1,m+1): if mat[i][j] == 1 or mat[i][j] == 1000000000: continue else: ans[i][j] = min(ans[i][j], ans[i + 1][j] + 1, ans[i][j - 1] + 1) for i in range(1,n+1): for j in range(1,m+1): if mat[i][j]==1 or mat[i][j]==1000000000: continue else: ans[i][j]=min(ans[i][j],ans[i][j-1]+1,ans[i-1][j]+1) for i in range(n,0,-1): for j in range(m,0,-1): if mat[i][j] == 1 or mat[i][j] == 1000000000: continue else: ans[i][j]=min(ans[i][j],ans[i+1][j]+1,ans[i][j+1]+1) for i in range(1,n+1): for j in range(m, 0, -1): if mat[i][j] == 1 or mat[i][j] == 1000000000: continue else: ans[i][j] = min(ans[i][j], ans[i - 1][j] + 1, ans[i][j + 1] + 1) for i in range(n, 0, -1): for j in range(1,m+1): if mat[i][j] == 1 or mat[i][j] == 1000000000: continue else: ans[i][j] = min(ans[i][j], ans[i + 1][j] + 1, ans[i][j - 1] + 1) for i in range(1,n+1): for j in range(1,m+1): if mat[i][j]==1000000000: print('X',end=" ") elif ans[i][j]>=1000000000: print('-1',end=" ") else: print(ans[i][j],end=" ") print()
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/CACD2020/problems/AJP" }
d1264
train
for _ in range(int(input())): x,n = map(int,input().split()) reach = [0]*(x+1) reach[0] = 1 i=1 while i**n<=x: j = 1 while j+i**n<=x: j+=1 j-=1 while j>=0: if reach[j]>0: reach[j+i**n]+=reach[j] j-=1 i+=1 #print(reach) print(reach[-1])
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/PBK22020/problems/ITGUY24" }
d1265
train
r=[0,1,1,2,1,4,2,6,1,8,4] n,m=[int(x) for x in input().split()] if m==1: while n%2!=1: n=n/2 if n==1: print(1) else: print(n-1) elif (n+1)/2<m: print(m) else: print(n-m)
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/CDVA16/problems/CDVA1610" }
d1266
train
def base5(n): if n == 0: return for x in base5(n // 5): yield x yield n % 5 def seq(n): return int(''.join(str(2 * x) for x in base5(n)) or '0') for i in range(eval(input())): k=eval(input()) while(i<k): i=i+1 print(seq(i-1))
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/JUNE16/problems/CHEARMY" }
d1267
train
res="" for _ in range(int(input())): ans=0 c=int(input()) for i in range(c): n,m=list(map(int,input().split( ))) ans^=(n+m-2)%3 if ans: res+="MasterChef\n" else: res+="Football\n" print(res)
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/CHEFBRO" }
d1268
train
def dfs(ind,m,n,k): if(ind == m): return [""] else: temp = dfs(ind+1,m,n,k) ans = [] if(len(temp)<k): for i in temp: for j in range(97,97+n): ans += [chr(j)+i] else: for i in temp: ans += ["z"+i] return ans n,m,k = list(map(int,input().split())) p = [] mr= [] for _ in range(m): inp = [int(x) for x in input().split()] mc = inp[0] mi = 0 for j in range(1,n): if(mc<inp[j]): mc = inp[j] mi = j p += [inp] mr += [mi] ans = dfs(0,m,n,k) w = [] for i in ans: cst = 0 s = "" for j in range(m): if(i[j]!="z"): s+=i[j] cst += p[j][ord(i[j])-97] else: s += chr(mr[j]+97) w += [(-cst,s)] w.sort() print(w[k-1][1])
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/LTIME40/problems/LTM40EF" }
d1269
train
while(True): n, m, x = map(int, input().split()) if(n==0 and m==0 and x==0): break money=0 for i in range(n): money=money + (x+m*i)//n print(money)
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/READCOST" }
d1270
train
for _ in range(int(input())): n=int(input()) a=list(map(int,input().split())) b=list(map(int,input().split())) a.sort() b.sort() s=0 for i in range(n): s+=min(a[i],b[i]) print(s)
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/SNUG_FIT" }
d1271
train
import sys sys.setrecursionlimit(100000) memo = {} def recurse(arr, T1, T2, k, i): if T1 >= k and T2 >= k: return i if i >= len(arr): return float('inf') if (T1, T2) in memo: return memo[(T1, T2)] t1 = recurse(arr, T1 + arr[i], T2, k, i+1) t2 = recurse(arr, T1, T2 + arr[i], k, i+1) memo[(T1, T2)] = min(t1, t2) return memo[(T1, T2)] for _ in range(int(input())): n, k = list(map(int, input().split())) lst = list(map(int, input().split())) lst.sort(reverse = True) memo = {} res = recurse(lst, 0, 0, k, 0) if res == float('inf'): print(-1) else: print(res)
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/WIPL" }
d1272
train
# fast io import sys def fop(s): sys.stdout.write(str(s)+'\n') def fip(): return sys.stdin.readline() fintinp = lambda : int(fip()) def flistinp(func= int): return list(map(func,fip().split())) def fnsepline(n,func=str): return [func(fip()) for _ in range(n)] #-------------------code------------------------ def even(x): x = bin(x).count('1') return x%2==0 for _ in range(fintinp()): q =fintinp() o = e =0 nums = set() for qn in range(q): qn = fintinp() if qn not in nums: if even(qn): e+=1 else: o+=1 for n in set(nums): x = n^qn if x not in nums: if even(x): e+=1 else: o+=1 nums.add(x) nums.add(qn) print(e,o)
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/PRTAGN" }
d1273
train
# cook your dish here n=int(input()) for _ in range(n): a=int(input()) if(a%2==0): f=(a//2)-1 s=a-f else: f=(a//2) s=a-f print(f,s)
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/ANDOR" }
d1274
train
import math t = int(input().strip()) for _ in range(t): n, m = list(map(int, input().strip().split())) a = [] v = [-1] * 4 for i in range(n): a.append(input().strip()) for i, ai in enumerate(a): if ai.find('*') > -1: v[2] = i break if v[2] == -1: print(0) else: for i, ai in reversed(list(enumerate(a))): if ai.find('*') > -1: v[3] = i break for i in range(m): x = [ai[i] for ai in a] if '*' in x: v[0] = i break for i in reversed(range(m)): x = [ai[i] for ai in a] if '*' in x: v[1] = i break if v.count(v[0]) == len(v): print(1) else: print(int(math.ceil(max(v[3] - v[2], v[1] - v[0]) / 2.0)) + 1)
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/JAN16/problems/DEVPERF" }
d1275
train
for _ in range(int(input().strip())): n = int(input().strip()) lst = [] for i in range(n): lst.append(i+1) lst.append(1) #print(lst) for i in range(n): print(''.join(str(e) for e in lst)) for x in range(n): lst[x * 2 + 1] += 1
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/PTRN2020/problems/ITGUY35" }
d1276
train
test = int(input()) for _ in range(test): n, m = map(int, input().split()) indexArray = list(map(int, input().split())) mini = min(indexArray) maxi = max(indexArray) result = n*[0] for i in range(n): result[i] = max(maxi - i, i - mini) print(result[i], end=" ") print()
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/ANUARM" }
d1277
train
from bisect import * for x in range(eval(input())): n,k = list(map(int,input().split())) arr = list(map(int,input().split())) arr.sort() t = 1 result = 0 y = 0 while y < n: if arr[y]<t: y += 1 elif arr[y]==t: t = t*2 y += 1 else: result += 1 t = t*2 while t < 2**(k): result += 1 t = t*2 print(result)
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/COOK86/problems/LIKECS03" }
d1278
train
for i in range(int(input())): n=int(input()) s=0 for i in range(n): a,b,c=map(int,input().split()) d=(c/100)*a e=a+d f=e-((c/100)*e) g=a-f h=b*g s=s+h print(s)
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/BIGSALE" }
d1279
train
# cook your dish here from sys import stdin,stdout,setrecursionlimit from math import ceil mod = 1000000007 t = int(stdin.readline()) for _ in range(t): m,n = list(map(int,input().split())) if m < n: m,n = n,m y = n-1 s1 = ((y*(y+1)) //2)%mod s2 = ((y*(y+1)*(2*y+1)) //6)%mod s3 = ((y*y*(y+1)*(y+1)) //4)%mod ans = (m*n*s1 - (m+n)*s2+s3)%mod # ans = (m*(m+1)*(2*m*n + 4*n + 2 - m*m - m)//12) print(ans)
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/COX22020/problems/DCODEX2" }
d1280
train
# cook your dish here for _ in range(int(input())): d=dict() ls=[] for i in range(int(input())): ls=list(map(int,input().split())) if ls[0] in d: d[ls[0]]=max(ls[1],d[ls[0]]) else: d[ls[0]]=ls[1] # print(d) if len(d)<3: print(0) else: kd=list(d.values()) kd.sort() # print(kd) print(kd[-1]+kd[-2]+kd[-3])
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/OPTCODE" }
d1281
train
t=int(input()) for _ in range(t): xyz = input().strip() string = 0 for i in range(len(xyz)//2): string = string + (abs(ord(xyz[i])-ord(xyz[len(xyz)-i-1]))) print(string)
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/RTCG2020/problems/RTCG004" }
d1282
train
t=int(input()) x=[1,2,3,4,5,6,7] for i in range(t): N=int(input()) a=list(map(int,input().split())) rev=a[::-1] dup=set(a) if rev== a and list(dup) ==x: print("yes") else: print("no")
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/RAINBOWA" }
d1283
train
l= [] for i in range(62): l.append(2**i) T = int(input()) flag = 0 for t in range(T): L,R = [int(i) for i in input().split()] bL = bin(L) lL = len(bL)-2 index = 1 ans = 0 temp = 0 while(index<=lL): temp = L%l[index] if temp>=l[index-1]: if(l[index]-temp<=R-L+1): ans= (ans +(l[index-1])*(l[index]-temp))%1000000007 else : ans=(ans+(l[index-1])*(R-L+1))%1000000007 index+=1 print(ans) # 4378578345 584758454958 # 18091037982636824985 8589934592 4429185025 4294967296
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/RGAND" }
d1284
train
# cook your dish here import sys n = 201 v = [0 for i in range(n + 1)] def gen(): for i in range(1, n + 1): v[i] = i countDivision = [0 for i in range(n + 1)] for i in range(n + 1): countDivision[i] = 2 for i in range(2, n + 1, 1): if (v[i] == i and countDivision[i] == 2): for j in range(2 * i, n + 1, i): if (countDivision[j] > 0): v[j] = int(v[j] / i) countDivision[j] -= 1 try: t=int(sys.stdin.readline()) for _ in range(t): gen() x=int(sys.stdin.readline()) flag=0 for i in range(2,x//2+1): if v[i]==1 and v[x-i]==1: flag=1 #print(i,x-i) if flag==1: print("YES") else: print("NO") except: pass
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/CHEFPRMS" }
d1285
train
# cook your dish here for _ in range(int(input())): n = int(input()) k = n//4 # a,b,c = map(int,input().split()) a = sorted(map(int,input().split())) a60 = (a[k-1],a[k]) a75 = (a[2*k-1],a[2*k]) a90 = (a[3*k-1],a[3*k]) if a60[0]==a60[1] or a75[0]==a75[1] or a90[0]==a90[1] : print(-1) else : print(a60[1],a75[1],a90[1])
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/HIT" }
d1286
train
# cook your dish here T=int(input()) for k in range(0,T): N=int(input()) matrix=[] for i in range(0,N): a=list(map(int, input().split())) matrix.append(a) max_trace = [] for i in range(0,N): trace1=0 trace2=0 for j in range(0,i+1): trace1+=matrix[j][N+j-i-1] trace2+=matrix[N+j-i-1][j] max_trace.append(trace1) max_trace.append(trace2) print(max(max_trace))
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/TRACE" }
d1287
train
import math def main(): #print("enter i, k, s") IN = '11 6 5' z = IN.split() z = input().split() i = int(z[0]) k = int(z[1]) s = int(z[2]) #print("enter a_i and b_i") IN = '4 5' z = IN.split() z = input().split() a_i = int(z[0]) b_i = int(z[1]) #print( "i = %d k = %d s = %d " % (i, k, s) ) #print( "a_i = %d b_i = %d" % (a_i, b_i) ) x = math.sqrt(2) y = math.sqrt(3) #print(x,y) # Obtaining the k-th element when k >= i if(i<=k): diff = k-i #if both k and i are odd or even if(k-i)%2==0: #print("#1") ans = (a_i + b_i) * math.pow(2,2*(k-i)-s) #diff = int(diff/2) #ans = (a_i + b_i) * math.pow(2,4*diff-s) #if i and k are of different parities then obtaining first # a_(i+1) and b_(i+1) else: #print("#2") ans = (2*x*a_i + 2*x*y*b_i) * math.pow(2,2*(k-(i+1))-s ) diff = int(diff/2) ans = (2*x*a_i + 2*x*y*b_i) * math.pow(2,4*diff - s) #print("1: ", (2*x*a_i + 2*x*y*b_i)) #print("2: ", math.pow(2,4*diff - 2- s)) #print("2 sol: ", math.pow(2,4*int(diff)-s)) #print("diff: ",diff) # Obtaining the k_th element when k < i else: diff = i-k #if both k and i are odd or even if(i-k)%2==0: #print("#3") ans = (a_i + b_i) / math.pow(2,2*(i-k)+s) #diff = int(diff/2) #ans = (a_i + b_i) / math.pow(2,4*diff+s) #if i and k are of different parities then obtaining first # a_(i+1) and b_(i+1) else: #print("#4") ans = (2*x*a_i + 2*x*y*b_i) / math.pow(2,2*(i+1-k)+s) diff = int(diff/2) ans = (2*x*a_i + 2*x*y*b_i) / math.pow(2,4*diff + 4 + s) print(ans) main()
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/CODECRCK" }
d1288
train
t=int(input()) MOD=(10**9)+7 l=['a','e','i','o','u'] for i in range(t): s=input() k=[] for j in s: if j in l: k.append(1) else: k.append(0) r=bin(int(''.join(map(str, k)), 2) << 1) print((int(r,2)//2)%MOD)
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/CBEN2020/problems/STRNM" }
d1289
train
t=int(input()) for _ in range(t): n,m=map(int,input().split()) mat=[0 for i in range(n)] #mat=[[0 for i in range(n)] for j in range(n)] for i in range(m): u,v=map(int,input().split()) u,v=(u-1),(v-1) mat[u]|=(1<<v) mat[v]|=(1<<u) for i in range(n): mat[i]|=(1<<i) goal=(2**n)-1 ans=n for i in range(1,goal+1): mvs=0 loc=0 for j in range(n): if(i&(1<<j)): loc|=mat[j] mvs+=1 if(loc==goal): ans=min(mvs,ans) print(ans)
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/CHSHIFU" }
d1290
train
t = int(input()) while(t>0): n=int(input()) if(n<=0): print(0) fact=1 start=1 for i in range(1,n+1): fact*=start start+=2 print(fact) t=t-1
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/AGTK2012/problems/ALGPAN" }
d1291
train
# cook your dish here x=input () y=len (x) if y==1: print('1') elif y==2: print('2') elif y==3: print('3') elif y>3: print('More than 3 digits')
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/HOWMANY" }
d1292
train
#-*- coding:utf-8 -*- import sys # class Point: # def __init__(self, x, y): # self.x = x # self.y = y # def mul(self, k): # return Point(k * self.x, k * self.y) # def __add__(self, other): # return Point(self.x + other.x, self.y + other.y) # def __sub__(self, other): # return self + (-other) # def __neg__(self): # return Point(-self.x, -self.y) # def __eq__(self, other): # return self.x == other.x and self.y == other.y # def __getitem__(self, index): # return (self.x, self.y)[index] # def __str__(self): # return "(%d;%d)" % (self.x, self.y) DIRS = dict( U=(0, 1), D=(0, -1), R=(1, 0), L=(-1, 0) ) KOEF = 0.2 def div(a, b): return round(float(a) / b, 1) # class Moving: # def __init__(self, x, y, dir): # self.p = Point(x, y) # self.dir = Point(*DIRS[dir.upper()]) # def collide(self, other): # times = [] # for coord in range(2): # d = abs(self.p[coord] - other.p[coord]) # d2 = abs((self.p + self.dir.mul(KOEF) - other.p)[coord]) # d3 = abs((other.p + other.dir.mul(KOEF) - self.p)[coord]) # d_next = abs((self.p + self.dir.mul(KOEF) - (other.p + other.dir    .mul(KOEF)))[coord]) # if d2 > d or d3 > d: # return None # speed = abs(d_next - d) # if speed == 0: # if self.p[coord] != other.p[coord]: # return None # continue # times.append( div(d, speed / KOEF) ) # if len(times) == 2 and times[0] != times[1]: # return # return times[0] def collide_coord(ex, edx, x, dx): d = abs(ex - x) d2 = abs(ex + edx - x) d3 = abs(ex - x - dx) if d2 > d or d3 > d: return False d_next = abs(ex + edx * KOEF - x - dx * KOEF) speed = abs(d_next - d) if speed == 0: if ex != x: return return "all" # all else: return div(d, speed / KOEF) def main(): t = int(input()) for _ in range(t): ex, ey, dir = sys.stdin.readline().strip().split() ex = int(ex) ey = int(ey) edx, edy = DIRS[dir] n = int(sys.stdin.readline()) min_time = float("+inf") for _ in range(n): x, y, dir = sys.stdin.readline().strip().split() x = int(x) y = int(y) dx, dy = DIRS[dir] tx = collide_coord(ex, edx, x, dx) if tx is False: continue ty = collide_coord(ey, edy, y, dy) if ty is False: continue if tx == "all": min_time = min(min_time, ty) elif ty == "all": min_time = min(min_time, tx) elif tx == ty: min_time = min(min_time, tx) print(min_time if min_time < 1000000 else "SAFE") def __starting_point(): main() __starting_point()
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/COLLIDE" }
d1293
train
# cook your dish here from operator import itemgetter inp=list(map(int, input().split())) n, m, w, b = inp[:4] stops=[] for i in range(w): stops.append((inp[4+2*i]-1,inp[5+2*i]-1,'w')) for i in range(b): stops.append((inp[4+2*w+2*i]-1,inp[5+2*w+2*i]-1,'b')) stops.sort(key=itemgetter(1)) stops.sort(key=itemgetter(0)) counter=0 stop_rows=[[] for _ in range(n)] for stop in stops: stop_rows[stop[0]].append(stop[1:]) for row in stop_rows: idx=0 for i in range(len(row)): if idx==row[i][0]: idx+=1 else: if row[i][1]=='w': if i<len(row)-1: num=row[i+1][0]-idx+1 counter+=((num*(num+1))>>1)-1 idx=row[i][0]+1 num=row[i+1][0]-row[i][0]+1 counter-=((num*(num+1))>>1)-1 else: num=m-idx counter+=((num*(num+1))>>1)-1 idx=row[i][0]+1 num=m-row[i][0] counter-=((num*(num+1))>>1)-1 else: num=row[i][0]-idx+1 counter+=((num*(num+1))>>1)-1 idx=row[i][0]+1 num=m-idx counter+=(num*(num+1))>>1 print(counter)
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/ZCOPRAC/problems/ZCO17002" }
d1294
train
def update_B(B, query): p, R = query for i in range(len(R)): B[p][i] = R[i] B[i][p] = R[i] def get_A(B): N = len(B) A = [0] * N i = 0 for j in range(N): if B[0][j] != 0: i = j A[i] = -B[0][i] break for j in range(i + 1, N): if abs(A[i] - B[0][j]) == B[i][j]: A[j] = B[0][j] else: A[j] = -B[0][j] return A def print_list(A): print(' '.join([str(a) for a in get_A(B)])) N, Q = [int(x) for x in input().rstrip().split()] B = [] for i in range(N): B += [[int(x) for x in input().rstrip().split()]] queries = [] for i in range(Q): p = int(input()) - 1 arr = input().rstrip().split() queries += [(p, [int(x) for x in arr])] print_list(get_A(B)) for q in queries: update_B(B, q) print_list(' '.join([str(a) for a in get_A(B)]))
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/MTRXMOD" }
d1295
train
# cook your dish here import sys,collections input=sys.stdin.readline def main(): T=int(input()) for _ in range(T): N,K=map(int,input().split()) Tree={} for j in range(N): Tree[j]=[] for i in range(N-1): u,v=map(int,input().split()) Tree[u-1].append(v-1) Tree[v-1].append(u-1) A=list(map(int,input().split())) vis=[0 for i in range(N)] #to mark visited vertices 0 for visited and             1 for not visited maxval=[[0,0] for i in range(N)] #Nx2 list where each i stores max             value till now and its count minval=[0 for i in range(N)] #Nx2 list where each i stores min value             till now lfnode=[] #list to store leaf nodes #Appending node 1 vis[0]=1 Q=collections.deque([0]) maxval[0][0],maxval[0][1]=A[0],1 minval[0]=A[0] while(len(Q)!=0): a=Q.pop() mv1=maxval[a][0] mv2=minval[a] flag=0 #to check leaf node for i in Tree[a]: if (vis[i]==0): vis[i]=1 flag=1 #not a leaf node v=A[i] Q.append(i) #Comparing maximum value of parent node if (mv1<v): maxval[i][0],maxval[i][1]=v,1 elif(mv1==v): maxval[i][0],maxval[i][1]=mv1,maxval[a][1]+1 else: maxval[i][0],maxval[i][1]=maxval[a][0],maxval[a][1] #Comparing minimum value of parent node if (mv2>v): minval[i]=v elif(v==mv2): minval[i]=mv2 else: minval[i]=minval[a] if (flag==0): lfnode.append(a) flag=0 #For answer if 0 then NO else YES K1=len(bin(K))-2 #length of K #print(lfnode,val) for i in lfnode: v1,v2=maxval[i][0],maxval[i][1] if (v1>K1 and v2%2==0): flag=1 elif(v1==K1 and v2%2==1): flag=1 v11=minval[i] if (v11>K1 and v11!=v1): flag=1 elif(v11==K1): flag=1 if(flag==1): break if (flag==1): print("YES") else: print("NO") main()
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/KTREE" }
d1296
train
mod=10**9+7 def fibonacci(n): if n < 0: raise ValueError("Negative arguments not implemented") return (_fib(n)[0]%mod + mod)%mod; def _fib(n): if n == 0: return (0, 1) else: a, b = _fib(n // 2) c = (a * (b * 2 - a))%mod d = (a * a + b * b)%mod if n % 2 == 0: return (c, d) else: return (d, c + d) def inv(n): return pow(n,mod-2,mod) def brute(n,k): ret = 0 for i in range(0,n+1): ret+=fibonacci(i)*pow(k,i,mod) return ret%mod def ans(n,k): k%=mod a = pow(k,n+1,mod) b=(a*k)%mod x = a*(fibonacci(n+1))+b*fibonacci(n)-k y = inv((k*k+k-1)%mod) return ((x*y)%mod+mod)%mod for t in range(0,eval(input())): n,k = list(map(int,input().split())) print(ans(n,k))
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/IPC15P3B/problems/FIBEQN" }
d1297
train
import sys sys.setrecursionlimit(10**8) MOD = 10**9+7 fac = [0]*(10**5+1) def pre() : fac[0] = 1 for i in range(1,10**5+1) : fac[i] = fac[i-1]*i fac[i] = fac[i]%MOD def dfs(gp , vertex , visited , deg , ans) : visited[vertex] = 1 stack = [] stack.append(vertex) while len(stack)>0 : vertex = stack.pop() ans = ans%MOD * fac[deg[vertex]]%MOD ans %= MOD for i in gp[vertex] : if not visited[i] : visited[i] = 1 if vertex in gp[i] : deg[i] -= 1 stack.append(i) return ans%MOD pre() for __ in range(eval(input())) : n = eval(input()) deg = [0]*(n+1) st = [[] for __ in range(n+1)] for _ in range(n-1) : a , b = list(map(int,sys.stdin.readline().split())) st[a].append(b) st[b].append(a) deg[a] += 1 deg[b] += 1 k = eval(input()) visited = [0]*(n+1) print(dfs(st ,k,visited,deg , 1)%MOD)
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/LOCAPR16/problems/BLTOUR" }
d1298
train
# cook your dish here for _ in range(int(input())): x, y= map(int, input().split()) if x<y: print('<') elif x>y: print('>') else: print('=')
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/CHOPRT" }
d1299
train
t = int(input()) while(t): n = int(input()) ar = list(map(int,input().strip().split(" "))) print(len([x for x in ar[1:len(ar)] if ar[0]<x])) t-=1
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/COLE2016/problems/CLBMUP" }
d1300
train
t=int(input()) f=0 y=0 for _ in range(t): n=int(input()) seq=[int(x) for x in input().split()] prev=seq[0] for i in range(1,len(seq)): if prev==seq[i]: seq[i]=0 prev=seq[i] ans=0 anss=0 for el in seq: if el!=0: c=seq.count(el) if ans<c: ans=c anss=el elif ans==c: if el<anss: anss=el else: anss=anss print(anss)
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/RC122020/problems/RECNDNOS" }