_id
stringlengths
2
5
partition
stringclasses
2 values
text
stringlengths
5
289k
language
stringclasses
1 value
meta_information
dict
title
stringclasses
1 value
d634
train
n=int(input()) def do(): t=int(input()) x=[] for i in range(t): x.append(int(input())) print(max(x)) return for i in range(n): do()
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/UWCOI20A" }
d637
train
# cook your dish here from itertools import combinations a = list(map(int, input().split())) n = a[0] t = a[1] q = list(combinations(a[2:], 4)) total = 0 for i in q: if sum(i) == t: total += 1 print(total)
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/ZCOPRAC/problems/ZCO17001" }
d640
train
# cook your dish here t=int(input()) for _ in range(t): st=input() s=set(st) a=[] f1=f2=0 for i in s: a.append(st.count(i)) a.sort() if len(a)>=3: for i in range(2,len(a)): if a[i]!=a[i-1]+a[i-2]: f1=1 break x=a[0] a[0]=a[1] a[1]=x for i in range(2,len(a)): if a[i]!=a[i-1]+a[i-2]: f2=1 break if f1==1 and f2==1: print("Not") else: print("Dynamic") else: print("Dynamic")
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/CLFIBD" }
d643
train
# cook your dish here def isValid(mid): time = 0.0 for i in range(n): if time < c[i]: time = c[i] time += mid # cannon cooling elif time >= c[i] and time <= c[i] + d: time += mid # cannon cooling else: return False return True t = int(input()) while t != 0: n, d = list(map(int, input().split())) c = list(map(int, input().split()))[:n] ans = -1 c.sort() low, high = 0, 10 ** 10 while (high - low) > 0.000001: mid = (low + high) / 2 if isValid(mid): ans = mid low = mid else: high = mid print("{0:.6f}".format(ans)) t -= 1
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/ALIENIN" }
d646
train
t = int(input()) for _ in range(t): n = int(input()) k = int(input()) num = int(k/n) x = max(n*(1+num) - k, 0) diff = abs(x - (n-x)) if diff == 0: number = 2*x - 1 else: number = min(x, n-x)*2 print(number)
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/MMAX" }
d649
train
n,q=list(map(int,input().split())) final=[] height=list(map(int,input().split())) for k in range(0,q): b=input().split() if int(b[0])==1: step=int(b[1])-1 for k in range(0,int(b[2])): temp = 0 j=1 while j in range(1,101) and temp==0 and step+j<n: if height[step+j]>height[step]: step=step+j temp=1 j+=1 final.append(step+1) elif int(b[0])==2: for k in range(int(b[1])-1,int(b[2])): height[k]=height[k]+int(b[3]) for l in range(0,len(final)): print(final[l])
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/AUG17/problems/HILLJUMP" }
d652
train
# cook your dish here try: for i in range(int(input())): n=int(input()) l=[int(j) for j in input().split()][:n] d={} for j in l: d[j]=d.get(j,0)+1 a=len(d) c=0 for j in list(d.keys()): while(d[j]>=3): d[j]=(d[j]//3)+(d[j]%3) if(d[j]==2): c=c+1 if(c&1): s=0 for j in list(d.values()): s=s+j print(s-c-1) else: s=0 for j in list(d.values()): s=s+j print(s-c) except: pass
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/BTCH2020/problems/UNQCARD" }
d655
train
# cook your dish here x=int(input()) for i in range(x): s=list(map(int,input().split())) s.sort() print(s[1])
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/FLOW017" }
d658
train
def matrixScore(A): """ :type A: List[List[int]] :rtype: int """ m,n = len(A),len(A[0]) # 行变换 for i in range(m): if A[i][0] == 1: continue for j in range(n): A[i][j] = 1 - A[i][j] # 列变换 res = 0 for rows in zip(*A): # 始终使1的个数是更大的 cnt1 = max(rows.count(1), rows.count(0)) res += cnt1 * 2**(n-1) n -= 1 return res m, n = [int(s) for s in input().split(" ")] arr = [[int(s) for s in input().split(" ")] for i in range(m)] ans = matrixScore(arr) print(ans)
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/COFDEC20/problems/COFDQ2" }
d661
train
t = int(input()) for i in range(t): n = int(input()) if n == 1 or n == 2 or n == 145 or n == 40585: print(1) else: print(0)
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/PBK22020/problems/ITGUY26" }
d664
train
def least_rotation(S: str) -> int: """Booth's algorithm.""" f = [-1] * len(S) # Failure function k = 0 # Least rotation of string found so far for j in range(1, len(S)): sj = S[j] i = f[j - k - 1] while i != -1 and sj != S[k + i + 1]: if sj < S[k + i + 1]: k = j - i - 1 i = f[i] if sj != S[k + i + 1]: # if sj != S[k+i+1], then i == -1 if sj < S[k]: # k+i+1 = k k = j f[j - k] = -1 else: f[j - k] = i + 1 return k for _ in range(int(input())): l, s = input().split() if int(l) == 1: l = len(s) s += s k = least_rotation(s) print(s[k:k+l]) else: print(''.join(sorted(s)))
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/BIT32020/problems/BIT3B" }
d667
train
# cook your dish here t = int(input()) for _ in range(t): s = '' n = int(input()) if n==1: print(1) continue for i in range(1, n+1): s = s + str(i) print(s) p = 1 for i in range(n-1): s = '' for j in range(n): s = s + str(p + n) p = p+1 print(s)
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/PTRN2021/problems/ITGUY49" }
d670
train
T = int(input()) for _ in range(T): N, M, K = [int(x) for x in input().split()] UV = [[int(x) for x in input().split()] for _ in range(M)] Q = int(input()) AB = [[int(x) for x in input().split()] for _ in range(Q)] X = [[i] for i in range(N)] for u, v in UV: X[u - 1] += [v - 1] X[v - 1] += [u - 1] A = [[1 if i > 0 or j == 0 else 0 for j in range(N)] for i in range(K + 1)] for a, b in AB: A[b] = [1 if i == a - 1 else 0 for i in range(N)] if A[0][0] == 1: for k in range(K - 1, -1, -1): for i in range(N): if A[k][i] != 0: A[k][i] = sum(A[k + 1][j] for j in X[i]) print(A[0][0])
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/WNDR" }
d673
train
# cook your dish here from math import sqrt for i in range(int(input())): x1,y1,x2,y2=list(map(float,input().split())) m=(y2-y1)/(x2-x1) c=y2-m*x2 print('Test case : ',i+1) q=int(input()) for i in range(q): x3,y3=list(map(float,input().split())) if(y3-m*x3-c==0): print("YES") else: d=(abs(y3-m*x3-c))/sqrt(1+m*m) print("NO") print("%.6f" % d)
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/ABCC2020/problems/POINT" }
d676
train
import math def ispoweroftwo(y): return math.ceil(math.log(y,2))==math.floor(math.log(y,2)) t=int(input()) for i in range(t): n=int(input()) a=[] if(ispoweroftwo(n) and n!=1): print(-1,end=" ") if(n==1): print(1) if(n>=3 and not(ispoweroftwo(n))): a.append(2) a.append(3) a.append(1) if(n>3 and not ispoweroftwo(n)): i=4 while(i<=n): if(ispoweroftwo(i)): a.append(i+1) a.append(i) i+=2 else: a.append(i) i+=1 print(*a)
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/POSAND" }
d679
train
# cook your dish here test_case = int(input()) while test_case : n_people = int(input()) array = list(map(int, input().strip().split())) sums =[0 for i in range(n_people)] sums[0] = array[0] for i in range(1, n_people) : sums[i] = sums[i-1] + array[i] # print(sums) k = 1 count = 0 i = 0 while(k < n_people) : k = k + sums[i] # print(k) i = i + sums[i] count = count + 1 print(count) test_case -= 1 # 2 1 1 5 5 5 5 # [2, 3, 4, 9, 14, 19, 24] # 0 1 2 3 4 5 6
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/SPREAD2" }
d682
train
from math import ceil from bisect import bisect_right as b_r from bisect import bisect_left as b_l ar = list(map(int , input().split())) a = [int(ceil((ar[1]-int(x)+1)/ar[2])) for x in input().split()] s = sum(a) ar[1] = max(a) m = ar[1] - (s-ar[1])%2 mi = s%2 print(int( (m-mi)//2 +1)%(10**9+7))
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/RRGAME" }
d685
train
# cook your dish here import math # Function to find the Largest # Odd Divisor Game to check # which player wins def findWinner(n, k): cnt = 0; # Check if n == 1 then # player 2 will win if (n == 1): print("Grinch"); # Check if n == 2 or n is odd elif ((n & 1) or n == 2): print("Me"); else: tmp = n; val = 1; # While n is greater than k and # divisible by 2 keep # incrementing tha val while (tmp > k and tmp % 2 == 0): tmp //= 2; val *= 2; # Loop to find greatest # odd divisor for i in range(3, int(math.sqrt(tmp)) + 1): while (tmp % i == 0): cnt += 1; tmp //= i; if (tmp > 1): cnt += 1; # Check if n is a power of 2 if (val == n): print("Grinch"); elif (n / tmp == 2 and cnt == 1): print("Grinch"); # Check if cnt is not one # then player 1 wins else: print("Me"); # Driver code def __starting_point(): for i in range(int(input())): n=int(input()) findWinner(n, 1); __starting_point()
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/NQST2020/problems/WINALL" }
d688
train
from sys import stdin t = int(stdin.readline()) def count(n, arr): loc = 0 glob = 0 for i in range(n-1): if arr[i] > arr[i+1]: loc += 1 for i in range(n-1): for j in range(i+1, n): if glob > loc: return 0 if arr[i] > arr[j]: glob += 1; if glob == loc: return 1 return 0 for _ in range(t): n = int(stdin.readline()) arr = list(map(int, stdin.readline().split())) result = count(n, arr) if result: print("YES") else: print("NO")
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/COOK28/problems/LEPERMUT" }
d691
train
n,k,m = map(int,input().split()) ar = list(map(int,input().split())) fsum = [ar[0]] for i in range(1,n): fsum.append(fsum[i-1]+ar[i]) i = k #print(fsum) c = 0 while i <= n: if i == k: s = fsum[i-1] else: s = fsum[i-1]-fsum[i-k-1] if s == 0: c = -1 break if s < m: c += 1 if i<n: for j in range(i,i-k-1,-1): if ar[j-1] >0: j += k-1 i = j break if i<n: for j in range(i,i-k-1,-1): if ar[j-1] >0: j += k-1 i = j break i += 1 i = k while i <= n: if i==k: s = fsum[i-1] else: s = fsum[i-1] - fsum[i-k-1] if s == 0 : c = -1 break i += 1 print(c)
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/INTW2020/problems/MORALE99" }
d694
train
# cook your dish here x=int(input()) for i in range(x): s=int(input()) fact=1 for i in range(1,s+1): fact=fact*i print(fact)
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/FLOW018" }
d697
train
t=int(input()) for _ in range(t): n,m=list(map(int,input().split())) l=list(map(int,input().split())) k=[] for i in range(m): a,b=list(map(int,input().split())) k.append([a,b]) k.sort() c=[] flag=1 x=k[0][0] y=k[0][1] for i in k[1:]: if i[0]<=y: y=max(y,i[1]) else: c.append([x-1,y-1]) x=i[0] y=i[1] c.append([x-1,y-1]) m=[] j=0 for i in c: while j<i[0]: m.append(l[j]) j+=1 x=l[i[0]:i[1]+1] m+=sorted(x) j=i[1]+1 while j<n: m.append(l[j]) j+=1 if m==sorted(l): print('Possible') else: print('Impossible')
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/PERMSUFF" }
d700
train
for T in range(int (eval(input()))): N,K,D=list(map(int,input().split())) A=list(map(int,input().split())) P=sum(A)//K print(min(P,D))
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/DIVTHREE" }
d703
train
for i in range(int(input())): m,tc,th=map(int,input().split()) x=(th-tc) if x%3!=0: print("Yes") else: if (x//3)<=m: print("No") else: print("Yes")
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/COCA2020/problems/HOTNCOLD" }
d706
train
ar = [] ar.append(1) for i in range(1, 31): ar.append(ar[i-1]*(4*i-2)/(i+1)) t = int(input()) while(t>0): n = int(input()) if(n==0): print(0) else: print(ar[n]*2) t=t-1
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/ALGT2013/problems/TNMALG02" }
d712
train
def convertToParitys(s): """ This converts the string s to an int, which is a bitMap of the parity of each letter odd ? = first bit set odd a = second bit set odd b = third bit set etc """ keys = '?abcdefghijklmnopqrstuvwxyz' paritys = {c:0 for c in keys} for c in s: paritys[c] += 1 for c, v in paritys.items(): paritys[c] = v%2 out = 0 bitValue = 1 for c in keys: if paritys[c]: out += bitValue bitValue *= 2 return out def getSolutionBitMaps(s): """ these are the 27 valid bitmaps that a substring can have even ? and the parities the same 26 cases of odd ? and one bit different in the parity compared to s """ out = [] sP = convertToParitys(s) if sP%2: sP -= 1 # to remove the '?' parity #even case - out.append(sP) #odd cases - need to xor sP with 1 + 2**n n = 1 to 26 inc to flip ? bit and each of the others for n in range(1,27): out.append(sP^(1+2**n)) return out def getLeadingSubStringBitMapCounts(s): """ This calculates the bit map of each of the len(s) substrings starting with the first character and stores as a dictionary. Getting TLE calculating each individually, so calculating with a single pass """ out = {} bM = 0 keys = '?abcdefghijklmnopqrstuvwxyz' paritys = {c:0 for c in keys} values = {c:2**i for i,c in enumerate(keys)} out[bM] = out.setdefault(bM, 0) + 1 #add the null substring bMis = [] i = 0 bMis = [0] for c in s: i += 1 if paritys[c]: paritys[c] = 0 bM -= values[c] else: paritys[c] = 1 bM += values[c] out[bM] = out.setdefault(bM, 0) + 1 bMis.append(bM) return out,bMis def solve(s): out = 0 bMjCounts,bMis = getLeadingSubStringBitMapCounts(s) #print('bMjCounts') #print(bMjCounts) solutions = getSolutionBitMaps(s) #print('solutions') #print(solutions) for bMi in bMis: for bMs in solutions: if bMs^bMi in bMjCounts: out += bMjCounts[bMs^bMi] #print(i,bMi,bMs,bMs^bMi,bMjCounts[bMs^bMi]) if 0 in solutions: out -= len(s) #remove all null substrings out //= 2 # since j may be less that i each substring is counted twice return out T = int(input()) for tc in range(T): s = input() print(solve(s))
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/SEDPASS" }
d715
train
# cook your dish here import math for t in range(int(input())): n=int(input()) a=[int(i) for i in input().split()] div=sum(a)/n div=math.ceil(div) count=div*n-sum(a) for i in a: if i>div: count+=i-div print(count)
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/WNTR2020/problems/WC07" }
d718
train
for i in range(int(input())): print(2*(sum(list(map(int, input().split())))-1))
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/HECS2020/problems/CC001" }
d721
train
t = int(input()) for _ in range(t): s = input() pref = [0]*len(s) if s[0]=="1": pref[0]+=1 for i in range(1,len(s)): if s[i]=="1": pref[i]+=1 pref[i]=pref[i]+pref[i-1] k=1 cnt=0 while (k+k*k)<=len(s): r = k+k*k i=r-1 while i<len(s): if (i-r)>=0: if pref[i]-pref[i-r]==k: cnt+=1 i+=1 else: i+=abs(k-(pref[i]-pref[i-r])) else: if pref[i]==k: cnt+=1 i+=1 else: i+=abs(k-(pref[i])) k+=1 print(cnt)
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/BDGFT" }
d724
train
def ans(l): s = "" i = 0 while (i < len(l)): temp = l[i] k = temp[1] if (k != 0): s += str(temp[0]) + "x^" + str(k) else: s += str(temp[0]) i += 1 if (i < len(l)): s += " + " if (len(s) > 0): return s else: return "0" test = int(input()) while (test != 0): test -= 1 N = int(input()) l = [] while (N != 0): n,m = list(map(int,input().split())) if (m > 0): l += [[n*m,m-1]] N -= 1 print(ans(l))
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/LOCFEB16/problems/POLYDIFR" }
d727
train
# cook your dish here t=int(input()) while t>0: n=int(input()) li=[] c,o,d,e,h,f=0,0,0,0,0,0 for i in range(0,n): s=input() for i in range(len(s)): if s[i]=='c': c=c+1 elif s[i]=='o': o=o+1 elif s[i]=='d': d=d+1 elif s[i]=='e': e=e+1 elif s[i]=='h': h=h+1 elif s[i]=='f': f=f+1 e=e//2 c=c//2 print(min(c,o,d,e,h,f)) t-=1
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/CFMM" }
d730
train
t=int(input()) for _ in range(t): n,m=map(int,input().split()) d={} e={} l=[] for i in range(n): d[i]=0 for i in range(m): e[i]=0 for i in range(n): l.append(input()) for i in range(n): for j in range(m): if l[i][j]=='1': d[i]=1 e[j]=1 #ans=[] if sum(d.values())+sum(e.values())==0: k=[-1]*m for i in range(n): print(*k) else: ans=[] for i in range(n): ans.append([0]*m) for i in range(n): for j in range(m): if l[i][j]=='1': ans[i][j]=0 else: if (d[i] or e[j]): ans[i][j]=1 else: ans[i][j]=2 for i in range(n): for j in range(m): print(ans[i][j],end=" ") print()
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/ORMATRIX" }
d733
train
# cook your dish here for tc in range(int(input())): n = int(input()) li1 = list(map(int,input().split(' '))) li2 = list(map(int,input().split(' '))) walk = 0 sum1 = 0 sum2 = 0 for i in range(n): if li1[i] == li2[i] and sum1 == sum2: walk += li1[i] sum1 += li1[i] sum2 += li2[i] print(walk)
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/WWALK" }
d736
train
for _ in range(eval(input())): n=eval(input()) if n%2: print('NO') else: print('YES')
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/LOCMAY16/problems/MDOSA" }
d739
train
# cook your dish here # cook your dish here #powerful numbers n = int(input()) plist = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313] power = 1 for i in range(2,n+1,1): pdiv = [] count = 0 for p in plist: if i>=p and i%p==0: pdiv.append(p) for pd in pdiv: if i%(pd**2)==0: count+=1 if count==len(pdiv) and count!=0: power+=1 print(power)
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/FULU2020/problems/ARMY1N" }
d742
train
import random import os yash=(2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997) def fix(m): for ai in yash: if m%ai==0: return ai return m def rabin_miller(a,i,n): if i==0: return 1 x=rabin_miller(a,i/2,n) if x==0: return 0 y=(x*x)%n if (y==1)and(x!=1)and(x!=n-1): return 0 if i%2!=0: y=(a*y)%n return y def gcd(x,y): if y==0: return x return gcd(y,x%y) def brent_rho(n): if (n<=3)or(rabin_miller(random.randint(2,n-2),n-1,n)==1): return n y,r,q,m=1,1,1,203 while 1: x=y for i in range(1,r+1): y=(y*y+1)%n k=0 while 1: ys=y for i in range(1,min(m,r-k)+1): y=(y*y+1)%n q=(q*abs(x-y))%n g=gcd(q,n) k+=m if (k>=r)or(g>1): break r*=2 if g>1: break if g==n: while 1: ys=(ys*ys+1)%n g=gcd(abs(x-ys),n) if g>1: break if g==n: return n return brent_rho(g) def divsum2(n): if n==1: return 0 d=brent_rho(n) d=fix(d) assert (d<=3)or(rabin_miller(random.randint(2,d-2),d-1,d)==1) f,m=0,n while m%d==0: m/=d f = f + 1; return (f*d)+(divsum2(m)) try: while(1): z=eval(input()) print(divsum2(z)) except: os.sys.exit(0);
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/ALGOTH10/problems/FACTSUM" }
d745
train
t=int(input()) for _ in range(t): n=int(input()) l1=[] if n==1: print('*') elif n==3: print('*') print('**') print('*') else: s1="" n1=n//2 n1+=1 for i in range(1,n1+1): s1="" if i==1: s1+='*' elif i==2: s1+='**' else: s1+='*' for j in range(2,i): s1+=' ' s1+='*' l1.append(s1) for i in l1: print(i) l1.reverse() for i in range(1,len(l1)): print(l1[i])
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/PEND2020/problems/ANITGUY6" }
d748
train
for _ in range(int(input())): n = int(input()) arr= list(map(int,input().split())) arr.sort() d={} for i in arr: if i not in d: d[i]=1 else: d[i]+=1 flag = True for i in d: if d[i]>2: flag=False break if arr.count(max(arr))!=1: flag=False if flag==True: arr1=[] arr2=[] for i in d: if d[i]<=2: if d[i]==2: arr2.append(i) arr1.append(i) arr2.reverse() rearr= arr1+arr2 print("YES") print(*rearr) else: print("NO") # cook your dish here
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/INCRDEC" }
d751
train
def invper(ar): ar1=[0]*(len(ar)) for i in range(len(ar)): ar1[ar[i]-1]=i+1 return ar1 t=int(input()) while(t!=0): ar=list(map(int,input().split())) ar1=invper(ar) if(ar==ar1): print("ambiguous") else: print("not ambiguous") t = int(input())
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/PERMUT2" }
d754
train
for t in range(int(input())): l1=list(map(int,input().split())) l2=list(map(int,input().split())) l3=list(map(int,input().split())) max=0 g=l1[0]+l2[0]+l3[0] y=l1[1]+l2[1]+l3[1] r=l1[2]+l2[2]+l3[2] if g%2==0: g-=1 if y%2==0: y-=1 if r%2==0: r-=1 if max<g: max=g if max<r: max=r if max<y: max=y m=l1[0]+l1[1]+l1[2] o=l2[0]+l2[1]+l2[2] p=l3[0]+l3[1]+l3[2] if m%2==0: m-=1 if o%2==0: o-=1 if p%2==0: p-=1 if max<m: max=m if max<o: max=o if max<p: max=p print(max)
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/BOUQUET" }
d757
train
# cook your dish here import math try: def prime(n): for i in range(2, int(math.sqrt(n)) + 1): if n % i == 0: return False return True for t in range(int(input())): x, y = list(map(int, input().split())) s = x + y i = s while(1): if prime(s + 1): ans = s + 1 break else: s += 1 print(ans - i) except: pass
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/POTATOES" }
d760
train
# cook your dish here store=[0]*(10**5+1) def sieve(): for i in range(2,10**5+1): if(store[i]==0): store[i]=1 for j in range(i,10**5+1,i): store[j]=i sieve() # print(store) for _ in range(int(input())): n=int(input()) li=[int(x) for x in input().split()] dp=[0]*(10**5+1) for i in li: dp[store[i]]+=1 max_re=0 res=0 for i in li: if(dp[store[i]]==max_re): if(store[i]>res): res=store[i] elif(dp[store[i]]>max_re): max_re=dp[store[i]] res=store[i] print(res)
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/HECS2020/problems/CC005" }
d763
train
t=int(input()) while(t): n=int(input()) cnt=1; for i in range(n): s="" for j in range(n): s=s+str(bin(cnt))[2:][: : -1]+" " cnt=cnt+1 print(s) t=t-1
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/PSTR2020/problems/ITGUY60" }
d766
train
n=int(input()) a=list(map(int,input().split())) q=int(input()) while q>0: i=1 tot=a[0] b=list(map(int,input().split())) if b[0]==1: #p,f=map(int,raw_input().split()) a[b[1]-1]=b[2] else: #r=int(raw_input()) tot=a[0] while 1+i*b[1]<=n: tot=tot*a[i*b[1]] i=i+1 m=(str)(tot) tot=tot%1000000007 print((int)(m[0]),tot) q=q-1
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/JUNE16/problems/FRJUMP" }
d769
train
# cook your dish here # cook your dish here from math import log2; import sys; sys.setrecursionlimit(10 ** 7) from collections import defaultdict inf = float("inf") def find_height(node): nodes[node]=1 for i in graph[node]: nodes[node]+=find_height(i) return nodes[node] def find_sum(node): suma=nodes[node] maxa=0 for i in graph[node]: maxa=max(find_sum(i),maxa) return maxa+suma for i in range(int(input())): n=int(input()) l=list(map(int,input().split())) graph=defaultdict(set) for i in range(len(l)): graph[l[i]].add(i+2) nodes=defaultdict(int) find_height(1) ans=find_sum(1) print(ans)
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/SUBMEXS" }
d772
train
from operator import itemgetter t=int(input()) for i in range(t): n=int(input()) m,f=list(map(int,input().split())) x=list(map(int,input().split())) my,fy=0,0 check=[0]*n #print check for j in range(n): if x[j]>0 and x[j]%m==0 and check[j]==0: check[j]=1 my+=1 #print check for j in range(n): if x[j]>0 and x[j]%f==0 and check[j]==0: check[j]=1 fy+=1 if ((((my+fy)*1.0)/n)*100)>=70: print("Yes") if my>fy: print("Multan") elif fy>my: print("Fultan") else: print("Both") else: print("No") #print check
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/CDGO2016/problems/CDGO1602" }
d775
train
# cook your dish here n, k, p = [int(i) for i in input().split()] n_sep = list(map(int, input().split())) count = 0 sep_sort = sorted(n_sep) hashing = {sep_sort[0]: 0} for j in range(1, n): if (abs(sep_sort[j] - sep_sort[j - 1]) > k): count += 1 hashing[sep_sort[j]] = count #print(hashing) for i in range(p): pair = list(map(int, input().split())) if hashing[n_sep[pair[1] - 1]] == hashing[n_sep[pair[0] - 1]]: print("Yes") else: print("No")
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/FROGV" }
d778
train
import math t=eval(input()) while t: t=t-1 r1,h1,r2,h2=list(map(float,input().split())) vol1=(math.pi*r1*r1*h1)/3 + (2*math.pi*r1*r1*r1)/3 vol2=math.pi*r2*r2*h2 print("%.8f %.8f" % (vol1,vol2))
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/LOCFEB16/problems/ICECREAM" }
d781
train
import sys user_input = sys.stdin.readline().split() T = int(user_input[0]) for j in range(T) : var = sys.stdin.readline().split() N = int(var[0]) M = int(var[1]) if (N%M)%2 : print("ODD") else : print("EVEN")
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/LOCMAY18/problems/REMAIN" }
d784
train
# cook your dish here epi=10**-2 def vision(t): a1=x0+(dx*t)-x1 a2=y0+(dy*t)-y1 a3=z0+(dz*t)-z1 b=4*((a1*d1)+(a2*d2)+(a3*d3))*((a1*d1)+(a2*d2)+(a3*d3)) a=4*((a1*a1)+(a2*a2)+(a3*a3)) value=(b-(a*c)) return value xrange=range for _ in range(int(input())): x1,y1,z1,x0,y0,z0,dx,dy,dz,cx,cy,cz,r=list(map(int,input().split())) d1=x1-cx d2=y1-cy d3=z1-cz c=(d1*d1)+(d2*d2)+(d3*d3)-(r*r) low=0 high=10**9+1 while low<(high-10**-6): mid=low+(high-low)*1.0/2; value=vision(mid); if abs(value)<=epi: break; elif value>0: low=mid; else: high=mid; print(mid)
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/VSN" }
d787
train
from sys import stdin, stdout #from math import gcd as g #a,b = map(int, stdin.readline().split()) #l1 = list(map(int, stdin.readline().split())) l = [1,6,7] c = 1 for x in range(3,100001): if x%2==1: a = l[c]*6 l.append(a) else: l.append(a+1) c+=1 n = int(stdin.readline()) for _ in range(n): s = int(stdin.readline()) print(l[s-1])
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/PBK22020/problems/ITGUY23" }
d790
train
tc=int(input()) for case in range(tc): m,r=list(map(int,input().split())) n=m**(r-1) a=[i**n for i in range(1,2*n+1)] tmp=2*n-1 for i in range(n): for j in range(tmp-i): a[j]=a[j+1]-a[j] print((a[n-1]/m)%1000000007)
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/CDST2016/problems/CDS2" }
d793
train
# cook your dish here t = int(input()) for _ in range(t): n,s = input().split() N = int(n) r = N - len(s) count = 0 if N>len(s): count = pow(26, r-1,(10**9+7)) count*= (26+25*len(s)) count = count%(10**9 + 7) print(count)
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/ICL1904" }
d796
train
t=int(input()) for i in range(t): n,k,l=map(int,input().split()) if k*l<n: print(-1) elif (k==1 and n>1): print(-1) else: for j in range(n): print((j%k)+1,end=' ') print()
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/BOWLERS" }
d799
train
# cook your dish here import sys def dist(a,b): return abs(a[0]-b[0])+abs(a[1]-b[1]) n, m = map(int, input().split()) matrix=[] id_matrix=[[0 for i in range(n)] for i in range(n)] for _ in range(n): matrix.append(list(map(int, input().split()))) charms=[] for _ in range(m): x,y,lungh = map(int, input().split()) x-=1 y-=1 charms.append([x,y,lungh]) if m<=10: for i in range(n): for j in range(n): flag=0 for charm in charms: if dist([i,j],charm[:2])<=charm[2]: flag=1 break if flag==0: matrix[i][j]=-float('Inf') for i in range(1,n): matrix[0][i]+=matrix[0][i-1] matrix[i][0]+=matrix[i-1][0] for i in range(1,n): for j in range(1,n): matrix[i][j]+=max(matrix[i-1][j], matrix[i][j-1]) else: for charm in charms: for i in range(-charm[2],charm[2]+1): appo=charm[2]-abs(i) for j in range(-appo, appo+1): x=i+charm[0] y=j+charm[1] if x>=0 and x<n and y>=0 and y<n: id_matrix[x][y]=1 if id_matrix[0][0]==0: matrix[0][0]=-float('Inf') for i in range(1,n): if id_matrix[0][i]==0: matrix[0][i]=-float('Inf') else: matrix[0][i]+=matrix[0][i-1] if id_matrix[i][0]==0: matrix[i][0]=-float('Inf') else: matrix[i][0]+=matrix[i-1][0] for i in range(1,n): for j in range(1,n): if id_matrix[i][j]==0: matrix[i][j]=-float('Inf') else: matrix[i][j]+=max(matrix[i-1][j], matrix[i][j-1]) if matrix[n-1][n-1]<-10**(10): print('NO') else: print('YES') print(matrix[n-1][n-1])
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/ZCOPRAC/problems/ZCO13002" }
d802
train
from collections import Counter tc=int(input()) for k in range(tc): n=int(input()) a=list(map(int, input().rstrip().split())) b= list(map(int, input().rstrip().split())) cc=sorted(a+b) #print('cc = ',cc) p=[] q=[] #print('len(cc) = ',len(cc)) #print('len = ',(2*n)) #rx=0 for i in range(0,(2*n),2): p.append(cc[i]) #rx+=1 for i in range(1,(2*n)+1,2): q.append(cc[i]) if(p!=q): print('-1') continue a.sort() b.sort() #print(p) #print(q) if(a==b): print('0') continue xx = list((Counter(a) - Counter(p)).elements()) yy = list((Counter(b) - Counter(p)).elements()) #print('xx = ',xx) #print('yy = ',yy) iu=len(xx) gb=sorted(xx+yy) #print(iu) uu=xx[0] vv=yy[0] #print('uu = ',uu) #print('vv = ',vv) zz=min(cc[0],uu,vv) #print('zz = ',zz) ans=0 for i in range(iu): if(gb[i]<=(zz*2)): ans+=gb[i] else: ans+=(zz*2) print(ans) #a = [1, 1, 1, 2, 3, 3] #b = [1, 1, 2, 2, 3, 4] '''c = [] i, j = 0, 0 while i < len(a) and j < len(b): if a[i] == b[j]: c.append(a[i]) i += 1 j += 1 elif a[i] > b[j]: j += 1 else: i += 1''' #print(c)
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/CHFNSWPS" }
d808
train
# cook your dish here for _ in range(int(input())): n,q=map(int,input().split()) l=[int(i) for i in input().split()] qry=[int(input()) for i in range(q)] def cmp(sub1,sub2): for i in range(len(sub1)): if sub1[i]>sub2[i]: return 1 if sub1[i]<sub2[i]: return 2 return 1 maxl=[] for i in range(n): for j in range(i,n): maxl.append(max(l[i:j+1])) maxl.sort(reverse=True) for i in qry: print(maxl[i-1])
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/KTHMAX" }
d811
train
# cook your dish here from bisect import bisect_left def BinarySearch(a, x): i = bisect_left(a, x) if i != len(a) and a[i] == x: return i else: return -1 for _t in range(int(input())): _n, q = list(map(int, input().split())) mounts = list(map(int, input().split())) for _q in range(q): query = list(map(int, input().split())) if query[0] == 0: mounts[query[1]] = query[2] else: curr = query[1] prev = set(mounts[:curr+1]) for m in mounts[curr+1:]: if m > mounts[curr] and m not in prev: print(m) break else: print(-1)
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/STR2020/problems/CHFMNT" }
d814
train
#dt = {} for i in x: dt[i] = dt.get(i,0)+1 import sys;input = sys.stdin.readline inp,ip = lambda :int(input()),lambda :[int(w) for w in input().split()] n,k = ip() x = ip() x.sort() if k == 1: a = x[n//2] b = x[n//2-1] else: s = sum(x) a = s//n b = a + 1 sa = sum([abs((a-i)**k) for i in x]) sb = sum([abs((b-i)**k) for i in x]) if sa < sb: print(a) else: print(b)
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/COJK2020/problems/CKOJ20B" }
d817
train
def bookList(): numBooks=int(input()) bookNum=[int(x) for x in input().split()] takenBooks=int(input()) for i in range(takenBooks): takenBookPos=(int(input())) a=bookNum[takenBookPos-1] print(a) bookNum.remove(a) bookList()
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/IARCSJUD/problems/BOOKLIST" }
d820
train
T=int(input()) while T: x,y=map(int,input().split()) while(y): x, y = y, x % y if x==1: print("YES") else: print("NO") T-=1
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/CCOD2020/problems/NITGOC" }
d823
train
def main(): while True: [n, m] = [int(i) for i in input().split()] if n == m and n == 0: break cache = {} for i in range(n): dna = input().rstrip('\n') if dna in cache: cache[dna] = 1 + cache[dna] else: cache[dna] = 1 c = [0 for i in range(n + 1)] for dna in cache: c[cache[dna]] = 1 + c[cache[dna]] for i in range(1, n + 1): print(c[i]) def __starting_point(): main() __starting_point()
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/PRFT2012/problems/PD11" }
d826
train
testcase = int(input()) for case in range(testcase): n = int(input()) print(2**(n-2)+1) print('\n')
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/AGTK2012/problems/ALGBBQ" }
d829
train
for i in range(int(input())): a=int(input()) b=input().split() if '0' in b: print(100*(a-b.index('0'))+b.count('0')*1000) else: print(0)
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/CHEFAPAR" }
d832
train
for _ in range(int(input())): n,m=input().split() n,m=int(n),int(m) x=y=c=0 l=list(map(int,input().split())) for i in range(n): for j in range(i,n): x=x+l[j] if (x%m)>y: y=x%m c=1 elif y==(x%m): c+=1 x = 0 print(y,c)
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/BEARSEG" }
d835
train
a=int(input()) for _ in range(a): c,d=list(map(int,input().split())) crr=[[[0,0] for i in range(c+1)] for j in range(c+1)] trr=[] for i in range(c): kk=list(input().split()) trr.append(kk) for i in range(1,c+1): for j in range(1,c+1): if(trr[i-1][j-1]=='a'): crr[i][j][0]=max(crr[i-1][j][0],crr[i][j-1][0])+1 if(j==1): crr[i][j][1]=crr[i-1][j][1]+1 elif(i==1): crr[i][j][1]=crr[i][j-1][1]+1 elif(crr[i-1][j][0]>crr[i][j-1][0]): crr[i][j][1]=crr[i-1][j][1]+1 else: crr[i][j][1]=crr[i][j-1][1]+1 else: crr[i][j][0]=max(crr[i-1][j][0],crr[i][j-1][0]) if(j==1): crr[i][j][1]=crr[i-1][j][1]+1 elif(i==1): crr[i][j][1]=crr[i][j-1][1]+1 elif(crr[i-1][j][0]>crr[i][j-1][0]): crr[i][j][1]=crr[i-1][j][1]+1 else: crr[i][j][1]=crr[i][j-1][1]+1 for i in range(d): m,n=list(map(int,input().split())) print(crr[m][n][1]-crr[m][n][0])
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/AARA2018/problems/ARMBH5" }
d838
train
for t in range(eval(input())): n=eval(input()) n-=n%10 n/=10 print(n*(n+1)/2*10)
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/KQPM2015/problems/SUMMATH" }
d841
train
def func(num): for i in range(num): if i < num//2 + 1: print(' '*i, end='') print('*') else: print(' '*(num-i-1), end='') print('*') for _ in range(int(input())): num = int(input()) func(num)
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/PSTR2020/problems/ITGUY45" }
d844
train
t=int(input()) for _ in range(t): n=int(input()) grid=[] for _ in range(n): temp=[] temp=list(map(int,input().strip().split())) temp.sort() grid.append(temp) curr=max(grid[n-1]) total=curr for i in range(n-2,0-1,-1): flag=0 for j in range(n-1,0-1,-1): if grid[i][j]<curr: flag=1 curr=grid[i][j] total+=curr break if flag==0: total=-1 break print(total)
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/MAXSC" }
d847
train
K,A,B = map(int,input().split()) if A + 2 > B: print(K + 1) return start = A - 1 K -= start ans = K//2 * (B-A) + K%2 + start + 1 print(ans)
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/SCAT2020/problems/SC_04" }
d850
train
n=eval(input()) a=list(map(int,input().split())) c=m=0 maxi=max(a) for i in range(n): if a[i]==maxi: c+=1 m=max(c,m) else: c=0 print(m)
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/BYTE2016/problems/BYTES11" }
d853
train
t=int(input()) for t in range(t): n=int(input()) for i in range(0,n): for j in range(0,n): if i%2==0: if j%2==0: print(0,end="") else: print(1,end="") else: if j%2==0: print(1,end="") else: print(0,end="") print()
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/PTRN2021/problems/ITGUY56" }
d856
train
oo = int(input()) for i in range(oo): val = input() print(val[::-1])
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/SPNT2020/problems/AODLS002" }
d859
train
# cook your dish here t=int(input()) while t>0: n=int(input()) if n==1: print(1) else: c,num=1,2 while num<n: num*=2 if num==n: print(num) else: print(num//2) t-=1
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/PBK02020/problems/ITGUY11" }
d862
train
#!/usr/bin/env python F = [1,1] def fibo(): for i in range(500): F.append(F[-2] + F[-1]) def main(): fibo() #print len(str(F[-1])) #print len(str(10**100)) while True: try: A, B = list(map(int, input().strip().split()[:2])) if A == 0 and B == 0: break print(len([x for x in F if x >= A and x <= B])) except: break main()
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/PRFT2012/problems/PD32" }
d865
train
testCases = int(input()) for c in range(testCases): n, k = list(map(int, input().split())) sum = 0 i = 0 power = 1 while i <= n: if k**power == i: power += 1 else: sum += i i +=1 answer = "Case #" + str(c + 1) + ": " + str(sum) print(answer)
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/GSTS1601/problems/BUG2K16E" }
d868
train
T = int(input()) for _ in range(T): W = list(map(int, input().strip().split())) S = W[0] W = W[1:] W = W[::-1] i = 0 c = 0 flag = 0 while (len(W) != 0 or flag != 1) and i<len(W): k = i su = 0 while su <= S and k<len(W)-1: su += W[k] k += 1 if su-W[k-1]<=S: c += 1 else: flag = 1 i += 1 print(c-1)
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/JLUG2020/problems/BRKTBRK" }
d871
train
# cook your dish here import math; from math import gcd,sqrt,floor,factorial,ceil from bisect import bisect_left,bisect_right import bisect; import sys; from sys import stdin,stdout import os sys.setrecursionlimit(pow(10,7)) import collections from collections import defaultdict,Counter from statistics import median # input=stdin.readline # print=stdout.write from queue import Queue inf = float("inf") from operator import neg; mod=pow(10,9)+7 def fun(l): m=[[l[0]]] for i in range(1,n): if m[-1][-1]==l[i]: m[-1]+=[l[i]] else: m.append([l[i]]) count=[] for i in range(len(m)): count.append(len(m[i])) return count; def function(l1,index,prev,count): tuple=(index,prev,count) if tuple in dict: return dict[tuple] n=len(l1) if index==n: return 0; if count>=3: if index%2==prev: dict[tuple]=function(l1,index+1,prev,count) return function(l1,index+1,prev,count) else: dict[tuple]=l1[index]+function(l1,index+1,prev,count); return dict[tuple] if prev==None: skip=l1[index]+function(l1,index+1,prev,count) not_skip=function(l1,index+1,index%2,count+1) maxa=min(skip,not_skip) dict[tuple]=maxa return maxa; if index%2==prev: dict[tuple]=function(l1,index+1,index%2,count) return dict[tuple] if index%2!=prev: skip=l1[index]+function(l1,index+1,prev,count) not_skip=function(l1,index+1,index%2,1+count) maxa = min(skip, not_skip) dict[tuple]=maxa return maxa; t=int(input()) for i in range(t): s=input() l=list(s) n=len(l) l=[int(i) for i in l] l1=fun(l) dict=defaultdict(int) theta=function(l1,0,None,0) print(theta)
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/PRFYIT" }
d874
train
let_to_num = {'A':[0,5], 'B':[1,6], 'C':[2,7], 'D':[3,8], 'E':[4,9]} num_to_let = {0:'A', 1:'B', 2:'C', 3:'D', 4:'E', 5:'A', 6:'B', 7:'C', 8:'D', 9:'E'} connections = {0:(1,4,5), 1:(0,2,6), 2:(1,3,7), 3:(2,4,8), 4:(0,3,9), 5:(0,7,8), 6:(1,8,9), 7:(2,5,9), 8:(3,5,6), 9:(4,6,7)} T = int(input()) for i in range(T): s = input() out_1, out_2= [],[] flag1, flag2 = True, True for c in range(len(s)): #print out_1, out_2, flag1, flag2 if c == 0: out_1.append(let_to_num[s[c]][0]) out_2.append(let_to_num[s[c]][1]) #print out_1, out_2, '\n' else: if flag1: conn_1 = set(connections[out_1[-1]]) to_conn_1 = set(let_to_num[s[c]]) if len(conn_1.intersection(to_conn_1))==0: flag1 = False else: out_1.extend(list(conn_1.intersection(to_conn_1))) #print 'out1',conn_1, to_conn_1, flag1, conn_1.intersection(to_conn_1) if flag2: conn_2 = set(connections[out_2[-1]]) to_conn_2 = set(let_to_num[s[c]]) if len(conn_2.intersection(to_conn_2))==0: flag2 = False else: out_2.extend(list(conn_2.intersection(to_conn_2))) #print 'out2', conn_2, to_conn_2, flag2, conn_2.intersection(to_conn_2) #print out_1, out_2, flag1, flag2, '\n' if (not flag1) and (not flag2): break if (not flag1) and (not flag2): print(-1) continue elif flag1 and (not flag2): print(''.join(str(k) for k in out_1)) continue elif flag2 and (not flag1): print(''.join(str(k) for k in out_2)) continue else: print(min(''.join(str(k) for k in out_1), ''.join(str(k) for k in out_2))) continue
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/COOK52/problems/PETERSEN" }
d877
train
t=int(input()) for t1 in range(t): n,x=map(int,input().split()) a=list(map(int,input().split())) mx=max(a) mn=min(a) if (mx-mn<x): print("YES") else: print("NO")
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/ENDE2020/problems/ENCDEC01" }
d880
train
for _ in range(int(input())): x, y = map(int, input().split()) ans = 0 for i in range(y, x+1, y): if i%y == 0: ans += i%10 print(ans)
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/ENDE2020/problems/ENCDEC04" }
d883
train
from collections import Counter def solve(A,B): a = Counter(A) b = Counter(B) ans = 0 for i in a: if i in b: ans += min(a[i],b[i]) return ans t = int(input()) for _ in range(t): A = input() B = input() print(solve(A,B))
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/LCPESY" }
d886
train
from sys import stdin, stdout input = stdin.readline from collections import defaultdict as dd import math def geti(): return list(map(int, input().strip().split())) def getl(): return list(map(int, input().strip().split())) def gets(): return input() def geta(): return int(input()) def print_s(s): stdout.write(s+'\n') def solve(): for _ in range(geta()): n=geta() n=bin(n).split('b')[1] print(n.count('0')) def __starting_point(): solve() __starting_point()
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/PBK32020/problems/ITGUY31" }
d889
train
def search(arr, lenl, val): s = 0 l = lenl - 1 total = 0 while (s <= l): m = int((s + l) / 2) if (arr[m] <= val): total = m + 1 s = m + 1 else: l = m - 1 return total def kmpsearch(string, lps): lis = [] lens = len(string) lensh = lens // 2 l = 0 i = 0 while i < lens: if string[i] == pat[l]: l += 1 i += 1 elif l > 0: l = lps[l - 1] else: i += 1 if l == lenp: if i - l < lensh: lis.append(i - l) l = lps[l - 1] return lis def kmp(pat, lenp): lps = [0]*(lenp) l = 0 i = 1 while i < lenp: if pat[i] == pat[l]: l += 1 lps[i] = l i += 1 elif l > 0: l = lps[l-1] else: lps[i] = 0 i += 1 return lps keyword = input() pat = input() q = int(input()) lenk = len(keyword) lenp = len(pat) k = keyword * 2 lis = kmpsearch(k, kmp(pat, lenp)) lenl = len(lis) for _ in range(q): n = int(input()) count = 0 q = n // lenk r = n % lenk count += search(lis, lenl, r - lenp) if q >= 1: count += search(lis, lenl, lenk + r - lenp) if q >= 2: count += (q - 1)*lenl print(count)
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/CENS20C" }
d892
train
# cook your dish here import math; from math import gcd,sqrt,floor,factorial,ceil from bisect import bisect_left,bisect_right import bisect; import sys; from sys import stdin,stdout import os sys.setrecursionlimit(pow(10,7)) import collections from collections import defaultdict,Counter from statistics import median # input=stdin.readline # print=stdout.write from queue import Queue inf = float("inf") from operator import neg; n,m=map(int,input().split()) for i in range(m): k=int(input()) print(max(0,min(k-n-1,3*n+1-k)))
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/RRSUM" }
d895
train
import random t=int(input()) for testCase in range(t): n=int(input()) array1=[] array2=[] array=[] for i in range(n) : array1.append(list(map(int,input().split()))) for i in range(n) : array2.append(list(map(int,input().split()))) for i in range(n) : array.append(i) # print array2," ",array1 for i in range(n) : print(array[i]+1, end=' ') print() k=0 max=0 answer=[] temp=[] while k < (1<<5) : k+=1 for i in range(n) : rand=random.randint(0,len(array)-1) temp.append(array[rand]) array.pop(rand) array = temp count=0 for i in range(n) : for j in range(n) : if(array1[i][j] and array2[array[i]][array[j]]) : count+=1 if(count > max): answer=array max=count #print max,count for x in answer : print(x+1, end=' ') print()
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/APRIL12/problems/SIMGRAPH" }
d898
train
# cook your dish here # cook your dish here MOD = 10 ** 9 + 7 for t in range(int(input())): N, M, K = map(int, input().split()) A = list(map(int, input().split())) I, D = [0] * (N + 2), [0] * (N + 2) for i in range(M): x, L, R = input().split() L, R = int(L), int(R) if x == 'I': I[L] += 1 I[R] -= 1 else: D[L] += 1 D[R] -= 1 impossibru = mx = mn = 0 ans = 1 for i in range(N): I[i] += I[i - 1] D[i] += D[i - 1] if I[i] and D[i]: impossibru = 1 break if not I[i] and not D[i]: ans = ans * (mx - mn + 1) % MOD mn, mx = 1, K elif I[i]: mx = min(mx + 1, K) mn += 1 elif D[i]: mn = max(1, mn - 1) mx -= 1 if mn > mx: impossibru = 1 break if A[i] != -1: if not mn <= A[i] <= mx: impossibru = 1 break mn = mx = A[i] ans = ans * (mx - mn + 1) % MOD print(0 if impossibru else ans)
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/CO92REST" }
d901
train
import math t=int(input()) for i in range(t): k=int(input()) res=((pow(2,k,1000000007))*5)%1000000007 print(res)
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/RSIGNS" }
d904
train
# cook your dish here try: t = int(input()) for _ in range(t): p = [int(x) for x in input().split()] q = [int(x) for x in input().split()] q[1] *= -1 m = (q[1]-p[1])/(q[0]-p[0]) c = p[1] - m*p[0] print("{:.2f}".format(-c/m)) except: pass
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/HECS2020/problems/CC000" }
d907
train
# cook your dish here # Author: Dancing Monkey | Created: 09.DEC.2018 import bisect for _ in range(int(input())): n = int(input()) x1 , x2, x3 = [], [], [] for i in range(n): x, y = list(map(int, input().split())) if x == 1: x1.append(y) if x == 2: x2.append(y) if x == 3: x3.append(y) x1.sort() x2.sort() x3.sort() y1, y2, y3 = len(x1), len(x2), len(x3) area = 0 for i in range(y1): for j in range(i+1, y1): area += abs(x1[i] - x1[j])*(y2 + (2*y3)) for i in range(y3): for j in range(i+1, y3): area += abs(x3[i] - x3[j])*(y2 + (2*y1)) for i in range(y2): for j in range(i+1, y2): area += abs(x2[i] - x2[j])*(y1 + y3) area /= 2 s1 = [0] for i in range(y2): s1.append(s1[-1] + x2[i]) # print(s1) s2 = [0] for i in range(y2):s2.append(s2[-1] + x2[y2 - 1 - i]) # print(s2) for i in x1: for j in x3: p1 = (i + j) / 2 p = bisect.bisect_left(x2, p1) # print('p', p) l = p h = y2 - l # print(l, h) area += p1*(l) - s1[l] # print('dfg', area) area += s2[h] - p1*(h) print(format(area, 'f')) # print()
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/MAKETRI" }
d910
train
for u in range(int(input())): n=int(input()) l=list(map(int,input().split())) d=list(map(int,input().split())) ka=[] k=[] l.sort() d.sort() for i in range(n): ka.append(d[i]) ka.append(l[i]) for i in range(n): k.append(l[i]) k.append(d[i]) if(ka==sorted(ka)): print("YES") elif(k==sorted(k)): print("YES") else: print("NO")
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/SCAT2020/problems/SC_02" }
d913
train
#dt = {} for i in x: dt[i] = dt.get(i,0)+1 import sys;input = sys.stdin.readline inp,ip = lambda :int(input()),lambda :[int(w) for w in input().split()] def check(mid): pos = x[0] ct = 1 for i in range(1,n): if x[i]-pos >= mid: pos = x[i] ct += 1 if ct == k: return True return False for _ in range(inp()): n,k = ip() x = ip() x.sort() ans = -1 l,r = 1,x[-1] while l < r: mid = (l+r)//2 if check(mid): ans = max(ans,mid) l = mid +1 else: r = mid print(ans)
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/CHLG2020/problems/KIDEE1" }
d916
train
# cook your dish here test = int(input()) for _ in range(0,test): n = int(input()) lister = set(map(int,input().split())) print(len(lister))
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/CFRTEST" }
d919
train
# cook your dish here mod=8589934592 list1=[] for i in range(int(input())): x=int(input()) ans=(pow(2,x,mod)-1)%mod list1.append((i+1,ans)) for i in list1: print(f'Case {i[0]}: {i[1]}')
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/KOL16H" }
d922
train
def f(a,n): l,r,s1,s2 = [0]*n, [0]*n, [], [] for i in range(n): count = 1 while(len(s1)>0 and a[i]<s1[-1][0]): count += s1[-1][1] s1.pop() s1.append((a[i],count)) l[i] = count for i in range(n-1,-1,-1): count = 1 while(len(s2)>0 and a[i]<=s2[-1][0]): count += s2[-1][1] s2.pop() s2.append((a[i],count)) r[i] = count count = 0 for i in range(n): count += a[i]*l[i]*r[i] return count t = int(input())
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/RICY" }
d925
train
# cook your dish here # cook your dish here import math def distinctPrimeFactors(num) : primes,sqrt = set(),int(math.sqrt(num)) if (num == 2) :primes.add(num) for j in range(2, sqrt + 1) : if (num % j == 0) : primes.add(j) while (num % j == 0) :num //= j if (num > 2) :primes.add(num) return (primes) res,c,lst,primes,rangeData = [],0,{},{},{};k, q = map(int, input().split());primes[k] = distinctPrimeFactors(k) for tc in range(q) : query = input() if (query[0] == '!') : cmd, l, r, x = query.split();l,r,x = int(l),int(r),int(x);start,end,startflag = l,r,False for i in sorted(rangeData) : rangeVal = i if (start > rangeVal[1]) :continue if (end < rangeVal[0]) :break startRange,endRange = start,end if (start >= rangeVal[0] and start <= rangeVal[1]) :start = rangeVal[1] + 1;continue if (end >= rangeVal[0]) :endRange = rangeVal[0] - 1 if (startRange <= endRange) : rangeData[(startRange, endRange)] = x;start = max(endRange + 1, rangeVal[1] + 1) if (start <= end) :rangeData[(start,end)] = x elif (query[0] == '?') : cmd, l, r = query.split();l,r,count = int(l),int(r),0 for primenum in primes[k] : for currRange in rangeData : if (not (r < currRange[0] or l > currRange[1])) : if (rangeData[currRange] % primenum == 0) :count += 1;break c += 1;res.append(count) for i in range(c):print(res[i])
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/PRMRANGE" }
d928
train
n, m = map(int, input().split()) l = n f = 1 s = ((n)*(n+1))//2 - l - f for _ in range(m): k = int(input()) if 2 <= k <= n-1 or k in [f, l]: l, f = f, l else: l = k print(s+l+f)
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/CGRL2020/problems/CGMN1" }
d934
train
#!/usr/bin/env python2 def gc(c): return 'a' <= c <= 'h' def gd(c): return '1' <= c <= '8' t = int(input()) for i in range(t): line = input() if len(line) != 5: print("Error") continue if line[2] != '-': print("Error") continue x1 = line[0] y1 = line[1] x2 = line[3] y2 = line[4] if gc(x1) and gd(y1) and gc(x2) and gd(y2): d1 = abs(ord(x1) - ord(x2)) d2 = abs(ord(y1) - ord(y2)) if d1 > d2: d1,d2 = d2, d1 if (d1 == 1) and (d2 == 2): print("Yes") else: print("No") else: print("Error")
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/COOK11/problems/KNIGHTMV" }
d937
train
for _ in range(int(input())): n=int(input()) a=[] l=0 for i in range(n): a.append(list(map(int,input().split()))) for i in range(n-1,0,-1): r=a[i][i-1]+1 if a[i][i]!=r: l+=1 n=i+1 for j in range(n): for k in range(j,n): a[j][k],a[k][j]=a[k][j],a[j][k] print(l)
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/ADAMAT" }
d940
train
lucky = {4, 774, 7, 744, 777, 74, 747, 44, 77, 47, 474, 444, 477, 447} from functools import lru_cache import sys sys.setrecursionlimit(10 ** 6) mod = 10 ** 9 + 7 fact = [1] for i in range(1, 1001): fact.append(fact[-1] * i % mod) inv = [pow(i, mod-2, mod) for i in fact] C = lambda k, n: fact[n] * inv[n-k] * inv[k] % mod def f(n): n = [int(x) for x in n] @lru_cache(None) def dp(pos, cnt, free): if cnt > 777: return 0 diff = len(n) - pos ans = 0 if free: for i in lucky: i -= cnt if 0 <= i <= diff: ans += C(i, diff) * pow(2, i, mod) * pow(8, diff - i, mod) ans %= mod return ans if pos == len(n): return int(cnt in lucky) for i in range(10 if free else n[pos]+1): ans += dp(pos+1, cnt + int(i == 4 or i == 7), free or i < n[pos]) ans %= mod return ans return dp(0, 0, 0) t = int(input()) for _ in range(t): l, r = input().split() l = str(int(l) -1) print((f(r) - f(l)) % mod)
PYTHON
{ "starter_code": "", "url": "https://www.codechef.com/problems/LUCKY2" }