_id
stringlengths 2
5
| partition
stringclasses 2
values | text
stringlengths 5
289k
| language
stringclasses 1
value | meta_information
dict | title
stringclasses 1
value |
---|---|---|---|---|---|
d801 | train | n=int(input())
a=list(map(int,input().split()))
a.sort()
print(a[-1],a[0])
| PYTHON | {
"starter_code": "",
"url": "https://www.codechef.com/SPTC2020/problems/CPCEJC2"
} | |
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"
} | |
d803 | train | import math
def csb(n):
count = 0
while (n):
n &= (n-1)
count+= 1
return count
def f(ca,cb,i,cf,C,n,dp):
if ca<0 or cb<0:
return 0
if i==n:
if ca==0 and cb==0 and cf==0:
return 1
return 0
st=str(ca)+" "+str(cb)+" "+str(cf)+" "+str(i)
if dp.get(st)!=None:
return dp[st]
x=0
if (C&(1<<i))>0:
x=1
if x==1:
#we will have odd num of set bits
if cf==1:
dp[st]=f(ca,cb,i+1,0,C,n,dp)+f(ca-1,cb-1,i+1,1,C,n,dp)
else:
dp[st]=f(ca-1,cb,i+1,0,C,n,dp)+f(ca,cb-1,i+1,0,C,n,dp)
else:
if cf==1:
dp[st]=f(ca-1,cb,i+1,1,C,n,dp)+f(ca,cb-1,i+1,1,C,n,dp)
else:
dp[st]=f(ca,cb,i+1,0,C,n,dp)+f(ca-1,cb-1,i+1,1,C,n,dp)
return dp[st]
def ip():
for _ in range(int(input())):
a,b,c=list(map(int,input().split()))
n=int(math.log(c,2))+1
dp={}
print(f(csb(a),csb(b),0,0,c,n,dp))
ip()
| PYTHON | {
"starter_code": "",
"url": "https://www.codechef.com/problems/CHEFADD"
} | |
d804 | train | cards = ['A','2','3','4','5','6','7','8','9','T','J','Q','K']
def royal_flush(arr):
nonlocal ans, confirm
rf_set = 'TJQKA'
rf = 1
for char in arr:
if char[0] not in rf_set:
rf = 0
break
if rf :
if len(set(suit)) == 1:
ans = 'royal flush'
confirm = 1
def straight_flush(arr): # and 'straight'
nonlocal ans,confirm
sf = 1
for i in range(1,5):
if arr[i] - arr[i-1] != 1:
sf = 0
break
if sf:
if len(set(suit)) == 1 :
ans = 'straight flush'
confirm = 1
else:
ans = 'straight'
confirm = 1
def four(arr):
nonlocal ans, confirm
f = 0
for char in arr:
if arr.count(char) == 4:
f = 1
break
if f:
confirm = 1
ans = 'four of a kind'
def full_house(arr): # and three
nonlocal ans, confirm
fh = 0
three = 0
two = 0
for char in arr:
if arr.count(char) == 3:
three = 1
elif arr.count(char) == 2:
two = 1
if three and two:
confirm = 1
ans = 'full house'
elif three:
confirm = 1
ans = 'three of a kind'
def two_pairs(arr):
nonlocal ans, confirm
temp = []
for char in arr:
if arr.count(char) == 2:
if char not in temp:
temp.append(char)
if len(temp) == 2:
confirm = 1
ans = 'two pairs'
elif len(temp) == 1:
confirm = 1
ans = 'pair'
def idex(char_x):
return cards.index(char_x)
for _ in range(int(input())):
onhand = list(input().split())
cards_set = [[],[]]
suit = []
confirm = 0
ans = ''
for c in onhand:
num = idex(c[0])
cards_set[0].append(num)
if num == 0:
cards_set[1].append(13)
else:
cards_set[1].append(num)
suit.append(c[1])
royal_flush(onhand)
if not confirm:
cards_set[0] = sorted(cards_set[0])
cards_set[1] = sorted(cards_set[1])
straight_flush(cards_set[0])
straight_flush(cards_set[1])
if not confirm:
four(cards_set[0])
four(cards_set[1])
if not confirm:
full_house(cards_set[0])
full_house(cards_set[1])
if not confirm:
if len(set(suit)) == 1:
confirm = 1
ans = 'flush'
if not confirm:
two_pairs(cards_set[0])
two_pairs(cards_set[1])
print(ans if confirm else 'high card') | PYTHON | {
"starter_code": "",
"url": "https://www.codechef.com/problems/POKER"
} | |
d805 | train | import numpy as np
for _ in range(int(input())):
n = int(input())-1;soldiers = [int(j) for j in input().split()]
force = int(input());attacks = np.zeros(2*n,dtype=int);attacks[:n] = np.array(soldiers);attacks[n:2*n] = attacks[:n];shield = [0 for _ in range(n)];pow_of_2 = 1
while n // pow_of_2 > 0: pow_of_2 *= 2
soldier_of_attack = (2 * n - pow_of_2) % n;pow_of_2 = attacks[soldier_of_attack] > force
for i in range(n):
if attacks[i] > force: shield[i] = 10 ** 11
elif n == 1: shield[i] = force
elif pow_of_2:
shield[i] = force; num_of_survivors = n; soldiers = list(attacks[i:i+n]); starting_soldier = (n - i) % n
if (num_of_survivors - starting_soldier) % 2 == 1: shield[i] += soldiers[-1]
soldiers = [soldiers[i] for i in range(num_of_survivors) if i < starting_soldier or (i - starting_soldier) % 2 == 0];num_of_survivors = starting_soldier + (num_of_survivors - starting_soldier - 1) // 2
if num_of_survivors > 1:
pow_2 = 1
while True:
attacker = num_of_survivors - (num_of_survivors % pow_2); pow_2 *= 2
if attacker == 0: break
if attacker % pow_2 == 0: shield[i] += soldiers[attacker]
elif i == soldier_of_attack: shield[i] = force
else: shield[i] = force + 1
shield_needed = min(shield)
if shield_needed == 10 ** 11: print("impossible")
else:
print("possible")
for i in range(n):
if shield[i] == shield_needed:print(str(i+1) + " " + str(shield_needed));break | PYTHON | {
"starter_code": "",
"url": "https://www.codechef.com/problems/CHFWAR"
} | |
d806 | train | t=int(input())
while(t):
n=int(input())
l=[]
for i in range(n):
l.append(list(map(int,input().split())));
m=[]
for i in l:
m.append((i[1]//(i[0]+1))*i[2])
res=max(m)
print(res)
t=t-1 | PYTHON | {
"starter_code": "",
"url": "https://www.codechef.com/problems/STFOOD"
} | |
d807 | train | # Why do we fall ? So we can learn to pick ourselves up.
t = int(input())
for _ in range(0,t):
n = int(input())
abc = [int(i) for i in input().split()]
i = 0
lst = [n]
for _ in range(0,100):
k = str(lst[-1]/abc[i%3]).split('.')
if int(k[1][0]) > 0:
lst.append(int(k[1][0]))
else:
lst.append(int(k[0][0]))
i += 1
pattern = []
ind = 0
while len(pattern) == 0:
for i in range(ind, len(lst) - 1):
check = lst[ind: i + 1] * 50
check = check[:len(lst) - ind]
if lst[ind:] == check:
pattern = check
break
if len(pattern):
break
ind += 1
final_pattern = []
for i in range(0, len(pattern)):
couldbe = pattern[:i + 1]
check = pattern[:i + 1] * 100
check = check[:len(pattern)]
if check == pattern:
final_pattern = couldbe
break
lp = len(final_pattern)
q = int(input())
for _ in range(0, q):
qq = int(input())
if qq < ind:
print(lst[qq])
else:
qq -= ind
kk = qq % lp
print(final_pattern[kk])
"""
1
56
3 5 7
4
0
1
2
3
""" | PYTHON | {
"starter_code": "",
"url": "https://www.codechef.com/PROC2020/problems/WLIST"
} | |
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"
} | |
d809 | train | from fractions import gcd
for testCases in range(eval(input())):
n = eval(input())
if n == 1:
print('1')
elif n == 2:
print('2')
elif n == 3:
print('6')
else:
c = n*(n-1)
k = n - 2
while True:
if gcd(k,n-1) == 1 and gcd(k,n) == 1:
break
k -= 1
d = (n-1)*(n - 2)
k1 = n - 3
while True:
if gcd(k1,n-1) == 1 and gcd(k1,n-2) == 1:
break
k1 -= 1
print(max(c*k,d*k1)) | PYTHON | {
"starter_code": "",
"url": "https://www.codechef.com/CDX2015/problems/CDXLRG"
} | |
d810 | train | #from itertools import combinations as c
n=int(input());l=list(map(int,input().split()))
l1=[]
if(n<3):
print("NO")
else:
l.sort()
for i in range(n-2):
if(l[i]+l[i+1]>l[i+2]):
l1.append([l[i+2],l[i+1],l[i]])
if(len(l1)!=0):
print("YES")
print(*max(l1))
else:
print("NO") | PYTHON | {
"starter_code": "",
"url": "https://www.codechef.com/COJK2020/problems/CKOJ20A"
} | |
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"
} | |
d812 | train | try:
n, k=map(int, input().split())
arr=list(map(int, input().split()))
forward = [0]*(n+1)
backward= [0]*(n+1)
backward[0]=arr[0]
backward[1]=arr[0]+arr[1]
for i in range(k, n):
forward[i]=arr[i] +max(forward[i-1],forward[i-2])
for i in range(2, n):
backward[i]=arr[i]+max(backward[i-1],backward[i-2])
ans=-float("Inf")
for i in range(k-1, n):
ans=max(ans, forward[i]+backward[i]-arr[i])
print(ans)
except Exception:
pass | PYTHON | {
"starter_code": "",
"url": "https://www.codechef.com/INOIPRAC/problems/INOI1301"
} | |
d813 | train | # cook your dish here
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
curr = 0
ans = 0
for x in a:
curr += x
ans += abs(curr)
print(ans) | PYTHON | {
"starter_code": "",
"url": "https://www.codechef.com/problems/PRLADDU"
} | |
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"
} | |
d815 | train | for _ in range(int(input())):
n=int(input())
def maxConsequtiveOnes(lst):
_max = 0
_ones = [0]
for i in lst:
if i == 0:
_max += 1
if i == 1:
_max = 0
_ones.append(_max)
return max(_ones)
a = list(map(int, input().split()))
b = maxConsequtiveOnes(a)
if (b % 2 == 0):
print("No")
else:
print("Yes")
| PYTHON | {
"starter_code": "",
"url": "https://www.codechef.com/problems/ARRGAME"
} | |
d816 | train | # cook your dish here
from collections import deque
primes = {2,3,5,7,11,13,17}
edges = [(0,3),(0,1),(1,2),(1,4),(2,5),(3,4),(3,6),(4,5),(4,7),(5,8),(6,7),(7,8)]
x = [1,2,3,4,5,6,7,8,9]
avail = {tuple(x):0}
q = deque([x])
while q:
curr = q.popleft();
for e in edges:
if curr[e[0]]+curr[e[1]] in primes:
nxt = curr[0:]
nxt[e[0]],nxt[e[1]] = nxt[e[1]], nxt[e[0]]
nxtt = tuple(nxt)
if nxtt not in avail:
avail[nxtt] = avail[tuple(curr)]+1
q.append(nxt)
t = int(input())
while t:
inp = input()
grid = []
for i in range(3):
inp = input()
for j in inp.strip().split(" "):
grid.append(int(j))
gridt = tuple(grid)
if gridt in avail: print(avail[gridt])
else: print(-1);
t-= 1 | PYTHON | {
"starter_code": "",
"url": "https://www.codechef.com/problems/H1"
} | |
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"
} | |
d818 | train | for _ in range(int(input())):
n=int(input())
l=list(map(int,input().split()))
su=l[0]
for i in range(1,n):
su^=l[i]
print(su) | PYTHON | {
"starter_code": "",
"url": "https://www.codechef.com/INDC2021/problems/DATEGIFT"
} | |
d819 | train | # cook your dish here
for _ in range(int(input())):
n=int(input())
a=[int(x) for x in input().split()]
sum=0
for i in range(n):
if a[i]%2==0:
sum+=1
a[i]=sum
q=int(input())
while q:
l,r=map(int,input().split())
if l!=1:
c=a[r-1]-a[l-2]
else:
c=a[r-1]
if c==0:
print("ODD")
else:
print("EVEN")
q-=1 | PYTHON | {
"starter_code": "",
"url": "https://www.codechef.com/problems/MINIAND"
} | |
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"
} | |
d821 | train | # cook your dish here
for _ in range(int(input())):
n,m = list(map(int,input().split()))
colors = [0]*41; cost = [0]*41
color = 0
for i in range(n):
cc,pp = list(map(int,input().split()))
colors[cc] += 1
cost[cc] += pp
for i in colors:
if i>0: color += 1
dp2 = [[0]*41 for i in range(color+1)]
dp2[0] = [1]*41
for i in range(1,color+1):
for j in range(1,41):
dp2[i][j] = dp2[i][j-1]+dp2[i-1][j-1]*(2**colors[j]-1)
dp1 = [[0]*41 for i in range(color+1)]
for i in range(1,color+1):
for j in range(1,41):
dp1[i][j] = dp1[i][j-1]+dp1[i-1][j-1]*(2**colors[j]-1)+dp2[i-1][j-1]*cost[j]*(2**(colors[j]-1))
num=den=0
for i in range(m,color+1):
num += dp1[i][40]
den += dp2[i][40]
print(num/den) | PYTHON | {
"starter_code": "",
"url": "https://www.codechef.com/problems/LEBALONS"
} | |
d822 | train | for _ in range(int(input())):
n = int(input())
ls = []
rs = []
lrs = []
for i in range(n):
l, r = map(int, input().split())
ls.append(l)
rs.append(r)
lrs.append((l, r, i))
lrs.sort()
c = 0
maxi = -1
res = [-1] * n
for l, r, i in lrs:
if ls[i] > maxi:
maxi = rs[i]
res[i] = c
elif rs[i] <= maxi:
res[i] = 1^c
else:
maxi = rs[i]
c ^= 1
res[i] = c
print(*res, sep='') | PYTHON | {
"starter_code": "",
"url": "https://www.codechef.com/problems/COLINT"
} | |
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"
} | |
d824 | train | # cook your dish here
# cook your dish here
t = int(input())
while t:
t-=1
c=0
ar=[int(i) for i in input().strip().split()]
for i in range(1,16):
b=bin(i)[2:].zfill(4)
s=0
for i in range(4):
if b[i]=='1':
s+=ar[i]
if(s==0):
c=1
break
print("Yes" if c==1 else "No")
| PYTHON | {
"starter_code": "",
"url": "https://www.codechef.com/problems/CHEFSETC"
} | |
d825 | train | from sys import stdin,stdout
input=stdin.readline
n=int(input())
a=[[] for i in range(n)]
for i in range(n-1):
u,v=map(int,input().split())
a[u-1].append(v-1)
a[v-1].append(u-1)
b=[0]*n
vis=[0]*n
st=[(0,0)]
vis[0]=1
pa=[0]*n
while st:
x,y=st.pop()
b[x]=y
for i in a[x]:
if vis[i]==0:
pa[i]=x
vis[i]=1
if x==0:
st.append((i,y+len(a[x])-1))
else:
st.append((i,y+len(a[x])-2))
c=[]
for i in range(1,n):
if len(a[i])==1:
c.append((b[i],i))
c.sort()
ans=0
while c:
x,y=c.pop()
m=y
p=0
while y!=0 and pa[y]!=-1:
y=pa[y]
if pa[y]==-1:
break
if y!=0:
p+=(len(a[y])-2)
else:
p+=(len(a[y])-1)
if p>=1:
p=0
while m!=0 and pa[m]!=-1:
x=m
if pa[m]==-1:
break
m=pa[m]
pa[x]=-1
if m!=0:
p+=(len(a[m])-2)
else:
p+=(len(a[m])-1)
if y==0:
pa[0]=-1
for i in range(n):
if pa[i]!=-1:
st=[i]
pa[i]=-1
while st:
x=st.pop()
for j in a[x]:
if pa[j]!=-1:
pa[j]=-1
st.append(j)
ans+=1
print(ans) | PYTHON | {
"starter_code": "",
"url": "https://www.codechef.com/problems/MINIKILL"
} | |
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"
} | |
d827 | train | # This is not my code, it's Snehasish Karmakar's. Refer to http://www.codechef .com/viewsolution/7153774
# for original version.
# Submitting it to try and work out if it can be sped up.
def compute_nCr(n,r) :
C[0][0]=1
for i in range(1,n+1) :
# print "i",i
C[i][0]=1
for j in range(1,min(i,r)+1) :
if i!=j :
C[i][j]=(C[i-1][j-1]+C[i-1][j])%MOD
else :
C[i][j]=1
def solve(n,m) :
store=[C[m+i-1][i] for i in range(m+1)]
for i in range(1,n+1) :
s=1
for j in range(1,m+1) :
s=(s+store[j])%MOD
store[j]=(s*C[m+j-1][j])%MOD
# print "a[%d][%d]=%d"%(i,j,s)
return s
MOD=1000000000
LIMIT=2000
C=[[0] * (LIMIT + 1) for _ in range(2*LIMIT+1)]
compute_nCr(2*LIMIT,LIMIT)
t=int(input())
while t :
n,m=list(map(int,input().split()))
print(solve(n,m))
t-=1 | PYTHON | {
"starter_code": "",
"url": "https://www.codechef.com/problems/STDYTAB"
} | |
d828 | train | try:
t=int(input())
for i in range(t):
n,k=map(int,input().split())
s=input()
l=[-1]*len(s)
numb=s.count('b')
x=numb
for j in range(len(s)):
if(s[j]=='a'):
l[j]=numb
if(s[j]=='b'):
numb=numb-1
#print(l)
count1=0
for j in range(len(l)):
if(l[j]>0):
count1=count1+(k*(2*l[j]+(k-1)*x))//2
elif(l[j]==0):
count1=count1+(k*(2*0+(k-1)*x))//2
print(count1)
except:
pass
| PYTHON | {
"starter_code": "",
"url": "https://www.codechef.com/problems/ABREPEAT"
} | |
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"
} | |
d830 | train | # cook your dish here
# cook your dish here
from itertools import combinations
n = int(input())
t = list(combinations(list(map(int, input().split())), 2))
ar = 0
for i in t:
ar += abs(i[0] - i[1])
print(ar) | PYTHON | {
"starter_code": "",
"url": "https://www.codechef.com/ZCOPRAC/problems/ZCO13001"
} | |
d831 | train | for _ in range(int(input())):
n=int(input())
a=input()
b=input()
l=[]
flag=0
for i in range(n):
if b[i]!=a[i]:
if b[i] in a and b[i]<a[i]:
l.append(b[i])
else:
flag=1
break
if flag==1:
print(-1)
else:
if l==[]:
print(0)
else:
l = sorted(list(set(l)), reverse = True)
print(len(l))
for i in range(len(l)):
q=[]
r=[]
for j in range(len(a)):
if l[i]==b[j]:
q.append(j)
r.append(a[j])
if l[i] not in r:
for k in range(len(a)):
if a[k]==l[i]:
q.append(k)
print(len(q),*q)
| PYTHON | {
"starter_code": "",
"url": "https://www.codechef.com/problems/CONVSTR"
} | |
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"
} | |
d833 | train | def fact(n):
if n<2:
return 1
return n * fact(n-1)
def ncr(n, r):
return fact(n)// (fact(r)*fact(n-r))
t=int(input())
for _ in range(t):
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
count_z = a.count(a[k-1])
count_z_seq = a[:k].count(a[k-1])
print(ncr(count_z, count_z_seq))
| PYTHON | {
"starter_code": "",
"url": "https://www.codechef.com/problems/CHEFINSQ"
} | |
d834 | train | import sys
def main():
s=sys.stdin.readline
n, m = list(map(int, s().split()))
nums={}
for i in range(1, n+1):
nums[i]=list(map(int, s().split()))
cases=int(s())
for case in range(cases):
px, py, qx, qy = list(map(int, s().split()))
ans=[]
for i in range(px, qx+1):
for j in range(py-1, qy):
ans.append(nums[i][j])
print(sum(ans))
def __starting_point():
main()
__starting_point() | PYTHON | {
"starter_code": "",
"url": "https://www.codechef.com/DMNT2012/problems/COUNTSTR"
} | |
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"
} | |
d836 | train | t = eval(input())
for _ in range(t):
n, m = list(map(int, input().split()))
if n*m == 2:
print('Yes')
elif (n*m)%2 == 0 and m != 1 and n != 1:
print('Yes')
else:
print('No') | PYTHON | {
"starter_code": "",
"url": "https://www.codechef.com/APRIL16/problems/CHEFPATH"
} | |
d837 | train | def bestMovie():
tests=int(input())
for t in range(tests):
n = int(input())
L = list(map(int, input().split()))
R = list(map(int, input().split()))
maxIndex = -1
maxValue = 0
for i in range(n):
prod = L[i]*R[i]
if maxValue < prod:
maxValue = prod
maxIndex = i
elif maxValue == prod:
if R[maxIndex] < R[i]:
maxIndex = i
print(maxIndex+1)
bestMovie() | PYTHON | {
"starter_code": "",
"url": "https://www.codechef.com/COOK69/problems/MOVIEWKN"
} | |
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"
} | |
d839 | train | T = int(input())
for i in range(T):
x = int(input())
l= [int(x) for x in input().split()]
t=[]
for i in range(len(l)):
t.append(l[i]+i)
print(max(t)) | PYTHON | {
"starter_code": "",
"url": "https://www.codechef.com/problems/WALK"
} | |
d840 | train | def isSubsetSum(arr, n, sum):
subset = [ [False for j in range(sum + 1)] for i in range(3) ]
for i in range(n + 1):
for j in range(sum + 1):
if (j == 0):subset[i % 2][j] = True
elif (i == 0):subset[i % 2][j] = False
elif (arr[i - 1] <= j):subset[i % 2][j] = subset[(i + 1) % 2][j - arr[i - 1]] or subset[(i + 1)% 2][j]
else:subset[i % 2][j] = subset[(i + 1) % 2][j]
return subset[n % 2][sum]
for _ in range(int(input())):
k,n,a = int(input()),int(input()),list(map(int,input().split()))
if sum(a) < k or k < min(a):print(0);continue
print(1) if isSubsetSum(a, n, k) else print(0) | PYTHON | {
"starter_code": "",
"url": "https://www.codechef.com/COFY2020/problems/GKSMNLC"
} | |
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"
} | |
d842 | train | M = 10 ** 9 + 7
for _ in range(int(input())):
s,p,m,r = list(map(int, input())),0,1,0
for d in reversed(s):
p += d * m
m = m * 10 % M
for d in s:
r = (r * m + p) % M
p = (p * 10 - (m - 1) * d) % M
print(r) | PYTHON | {
"starter_code": "",
"url": "https://www.codechef.com/problems/YVNUM"
} | |
d843 | train | t=int(input())
for _ in range(t):
n=int(input())
b=1
if n%2:
c=n-2
for j in range(n//2):
print(" "*j+str(b) +" "*c+ str(b))
b+=1
c-=2
print(" "*(n//2)+str(b)+" "*(n//2))
b+=1
c=1
for j in range(n//2):
print(" "*(n//2-j-1)+str(b)+" "*c+ str(b))
b+=1
c+=2
else:
c=n-2
for j in range(n//2):
print(" "*j+str(b)+" "*c+str(b))
b+=1
c-=2
c=0
for j in range(n//2):
print(" "*(n//2-j-1)+str(b) +" "*c+ str(b))
b+=1
c+=2
| PYTHON | {
"starter_code": "",
"url": "https://www.codechef.com/PTRN2020/problems/ITGUY41"
} | |
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"
} | |
d845 | train | def getInput():
N_k = input().split()
N =int(N_k[0])
k =int(N_k[1])
list = []
output = []
count = 0
for i in range(0,k):
val = input()
if(val!="CLOSEALL"):
val=val.split()
val = int (val[1])
if val not in list:
count= count +1
list.append(val)
else:
list.remove(val)
count= count -1
else:
count =0
while len(list) > 0:
list.pop()
output.append(count)
for each in output:
print(each)
getInput() | PYTHON | {
"starter_code": "",
"url": "https://www.codechef.com/COOK23/problems/TWTCLOSE"
} | |
d846 | train | def __gcd(a, b):
# Everything divides 0
if (a == 0 or b == 0):
return 0;
# base case
if (a == b):
return a;
# a is greater
if (a > b):
return __gcd(a - b, b);
return __gcd(a, b - a);
# Function to find
# number of squares
def NumberOfSquares(x, y):
# Here in built PHP
# gcd function is used
s = __gcd(x, y);
ans = (x * y) / (s * s);
return int(ans);
n=int(input())
while n:
n=n-1
c,d=map(int,input().split())
print(NumberOfSquares(c, d)) | PYTHON | {
"starter_code": "",
"url": "https://www.codechef.com/COM12020/problems/CODE_00"
} | |
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"
} | |
d848 | train | a= [0, 0, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 0, 5, 2, 2, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 2, 7, 4, 0, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 2, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 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| PYTHON | {
"starter_code": "",
"url": "https://www.codechef.com/problems/BIGPIZA"
} | |
d849 | train | # cook your dish here
#Moony and ICPC team
T = int(input())
for i in range(T):
N,data = int(input()),list(map(int,input().split()))
if(N==3):
print(sum(data))
else:
best = data[0]+data[1]+data[2]
overall = best
k=len(data)
for i in range(1,k-2):
overall=overall - data[i-1] + data[i+2]
if(overall>best):
best = overall
j=max(data[1],data[-2])
l= data[-1]+data[0]+j
if(best < l):
best = l
print(best) | PYTHON | {
"starter_code": "",
"url": "https://www.codechef.com/COG2020/problems/COG2002"
} | |
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"
} | |
d851 | train | from math import gcd
__author__ = 'Prateek'
def test():
n = int(input())
a = list(map(int, input().split()))
a = list(set(a))
n = len(a)
if len(a) == 1:
print(2 * a[0])
return
g1 = [0 for i in range(n)]
g2 = [0 for i in range(n)]
g1[0] = a[0]
g2[n - 1] = a[n - 1]
for i in range(1, n):
g1[i] = gcd(g1[i - 1], a[i])
for i in range(n - 2, -1, -1):
g2[i] = gcd(g2[i + 1], a[i])
ans = 0
for i in range(n):
if i == 0:
ans = max(ans, g2[i + 1] + a[i])
elif i == n - 1:
ans = max(ans, g1[i - 1] + a[i])
else:
ans = max(ans, gcd(g1[i - 1], g2[i + 1]) + a[i])
print(ans)
if __author__ == 'Prateek':
t = int(input())
for _ in range(t):
test()
| PYTHON | {
"starter_code": "",
"url": "https://www.codechef.com/problems/SUMAGCD"
} | |
d852 | train | for _ in range(int(input())):
n,k=map(int,input().split())
print(((2*n*(k-1))+2)/k) | PYTHON | {
"starter_code": "",
"url": "https://www.codechef.com/problems/COMPEXP"
} | |
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"
} | |
d854 | train | # cook your dish here
t=int(input())
for i in range(t):
n=int(input())
if n<101:
l1=[]
l2=[]
d=dict()
for i in range(1,2*n+1):
if i%2==0:
l1.append(int(input()))
else:
l2.append(str(input()))
r1=[]
for i in l1:
r1.append(i)
l1.sort()
ind=[]
for i in l1:
a=r1.index(i)
ind.append(a)
for i in ind:
print(l2[i])
else:
print(0)
break
| PYTHON | {
"starter_code": "",
"url": "https://www.codechef.com/TCFL2020/problems/TCFL20B"
} | |
d855 | train | # cook your dish here
for _ in range(int(input())):
n = int(input())
arr = list(map(int,input().split()))
l = []
for i in range(0, len(arr)):
for j in range(i+1, len(arr)):
if(arr[i] == arr[j]):
l.append(arr[j])
if (len(l) ==0):
print("prekrasnyy")
else:
print("ne krasivo") | PYTHON | {
"starter_code": "",
"url": "https://www.codechef.com/ARYS2020/problems/FREQARRY"
} | |
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"
} | |
d857 | train | t = int(input())
for _ in range(t):
n = int(input())
a = {}
for i in range(n):
l = input()
if l not in a:
a[l] = 1
else:
a[l] += 1
done = []
ans = 0
for i in a:
if a[i] != 0:
temp = [x for x in i.split()]
v = temp[0]
v0 = v + " 0"
v1 = v + " 1"
if(v0 in a and v1 in a):
if a[v0] > a[v1]:
ans += a[v0]
else:
ans += a[v1]
a[v0] = a[v1] = 0
elif(v0 in a):
ans += a[v0]
a[v0] = 0
elif(v1 in a):
ans += a[v1]
a[v1] = 0
print(ans) | PYTHON | {
"starter_code": "",
"url": "https://www.codechef.com/problems/TRAINSET"
} | |
d858 | train | testcases = int(input())
for i in range(testcases):
n = int(input())
my = list(map(int,input().split()))
opp = list(map(int,input().split()))
my.sort(reverse = True)
opp.sort(reverse = True)
j = 0
k = 0
while(k < n):
if(my[j] > opp[k]):
j += 1
k += 1
print(j) | PYTHON | {
"starter_code": "",
"url": "https://www.codechef.com/EXCT2015/problems/RACEWARS"
} | |
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"
} | |
d860 | train | import math
import os
import random
import re
import sys
r = 100000
prev = 1
s = set()
for i in range(1, r+1):
now = i ^ prev
s.add(now)
prev = now
s = list(s)
t = int(input())
while t > 0:
t -= 1
n, k = list(map(int, input().split()))
if n > 3:
if n % 2 == 0:
size = (n//2) + 2
else:
size = ((n-1)//2) + 2
else:
size = n
if size - k >= 0:
print(s[size-k])
else:
print(-1)
| PYTHON | {
"starter_code": "",
"url": "https://www.codechef.com/CMYC2020/problems/BTENG"
} | |
d861 | train | # cook your dish here
import math
T = int(input())
for _ in range(T):
N, H = map(int, input().split())
A = list(map(int, input().split()))
low, high = 1, max(A)
while low != high:
time = 0
mid = (low + high) // 2
for i in range(N):
time += math.ceil(A[i] / mid)
if time <= H :
high = mid
else:
low = mid + 1
print(high) | PYTHON | {
"starter_code": "",
"url": "https://www.codechef.com/problems/MINEAT"
} | |
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"
} | |
d863 | train | cases = int(input())
for case in range(cases):
N, M, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
jad = 0
P = M*K
for milk in A:
if(milk>P):
jad += milk-P
else:
jad += milk%K
print(jad%1000000007)
| PYTHON | {
"starter_code": "",
"url": "https://www.codechef.com/BITC2016/problems/DMILK"
} | |
d864 | train | n=int(input())
l=[]
dp=[]
d={}
for i in range(n):
l.append(int(input()))
d[i]=[]
dp.append([0,0])
for i in range(n-1):
a,b=list(map(int,input().split()))
d[a-1].append(b-1)
d[b-1].append(a-1)
#print(l)
#print(d)
def dfs(ch,pa,visited):
dp[ch][1]=l[ch]
#print(dp[ch],ch+1)
for i in range(len(d[ch])):
if d[ch][i] not in visited:
visited.add(d[ch][i])
dfs(d[ch][i],ch,visited)
dp[ch][0]+=max(dp[d[ch][i]][0],dp[d[ch][i]][1])
dp[ch][1]+=dp[d[ch][i]][0]
#print(ch+1,dp[ch])
v=set()
v.add(0)
dfs(0,-1,v)
#print(dp)
print(max(dp[0][0],dp[0][1]))
| PYTHON | {
"starter_code": "",
"url": "https://www.codechef.com/IARCSJUD/problems/CATERCON"
} | |
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"
} | |
d866 | train | try:
for _ in range(int(input())):
n = int(input())
print(0) if(n==1) else print(pow(2,n-1,10**9+7)-2)
except EOFError:
pass
| PYTHON | {
"starter_code": "",
"url": "https://www.codechef.com/problems/CPERM"
} | |
d867 | train | t=int(input())
for _ in range(t):
n=int(input())
l=list(map(int,input().split()))
if sum(l)!=n or max(l)==n:
print('-1')
else:
d=dict()
ans=[-1]*n
for i in range(0,n):
d[i]=1
for i in range(n):
if l[i]!=0:
count=l[i]
for k,v in list(d.items()):
if count>0 and v==1 and i!=k:
d[k]=0
ans[k]=i+1
count-=1
ind=-1
for i in range(0,len(ans)):
if ans[i]==-1:
ind=i
if ind==-1:
print(*ans)
else:
for i in range(len(ans)):
if ans[i]!=ind+1:
ans[ind]=ans[i]
ans[i]=ind+1
break
print(*ans)
| PYTHON | {
"starter_code": "",
"url": "https://www.codechef.com/problems/CHEFVOTE"
} | |
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"
} | |
d869 | train | from bisect import insort
from math import ceil
for _ in range(int(input())):
n,k=list(map(int,input().split( )))
array=list(map(int,input().split( )))
ans=0
index=[]
for i in range(1,n+1):
index.append(ceil(k/(ceil(k/i))))
for i in range(n):
count=[0]*(2001)
temp=[]
for j in range(i,n):
count[array[j]]+=1
insort(temp,array[j])
#m=ceil(k/(j-i+1)) precalculate thes values in index array
#t=ceil(k/m)
x=temp[index[j-i]-1]
f=count[x]
if count[f]:
ans+=1
print(ans)
| PYTHON | {
"starter_code": "",
"url": "https://www.codechef.com/problems/SUBPRNJL"
} | |
d870 | train | x = input()
y = input()
z = x.find(y)
if z == -1 :
print('N')
else :
print('Y') | PYTHON | {
"starter_code": "",
"url": "https://www.codechef.com/TCTR2012/problems/NOPC1"
} | |
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"
} | |
d872 | train | import sys
t = int(input())
# print(t)
for _ in range(t):
n,m = map(int,input().split());
s = [];
for i in range(n):
s.append(input())
ans = []
for i in range(n):
ans.append([])
for j in range(m):
ans[i].append([])
for i in range(n):
for j in range(m):
c = 0
if s[i][j] == 'U':
for k in range(i,-1,-1):
if s[k][j] == '#':
break
ans[k][j].append(c)
c+=1
elif s[i][j] == 'D':
for k in range(i,n):
if s[k][j] == '#':
break
ans[k][j].append(c)
c+=1
elif s[i][j] == 'L':
for k in range(j,-1,-1):
if s[i][k] == '#':
break
ans[i][k].append(c)
c+=1
elif s[i][j] == 'R':
for k in range(j,m):
if s[i][k] == '#':
break
ans[i][k].append(c)
c+=1
for i in range(n):
for j in range(m):
ans[i][j].sort()
res = []
for i in range(n):
for j in range(m):
c= 1
# print(ans[i][j])
for k in range(1,len(ans[i][j])):
# print(ans[i][j][k])
if ans[i][j][k] == ans[i][j][k-1]:
c+=1
else :
if c!=1:
res.append(c)
c = 1
if k==len(ans[i][j])-1:
if c!=1:
res.append(c)
pairs = 0
# print(res)
for i in range(len(res)):
pairs += ((res[i]*(res[i]-1))//2)
print(pairs) | PYTHON | {
"starter_code": "",
"url": "https://www.codechef.com/problems/ANTEATER"
} | |
d873 | train | for t in range(int(input())):
n, a , b , k = map(int,input().split())
solvedbychef = 0
solvedbyappy = 0
for i in range(n+1):
if i % a == 0 and i % b == 0 :
continue
elif i%a == 0 :
solvedbyappy+=1
elif i%b == 0:
solvedbychef+=1
totalsolved = solvedbychef + solvedbyappy
if totalsolved>=k:
print("Win")
else :
print("Lose") | PYTHON | {
"starter_code": "",
"url": "https://www.codechef.com/problems/HMAPPY2"
} | |
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"
} | |
d875 | train | import math
T=int(input())
for i in range(T):
N,M,S=input().split()
N=int(N)
M=int(M)
S=int(S)
ls=list(map(int,input().split()))
maxx=max(ls)
if S<17 and maxx<=50:
ls.sort()
total_sum = M * S
count = 0
sum = 0
for i in ls:
if i / S > 2:
continue
else:
sum = sum + math.ceil(i / S) * S
if sum <= total_sum:
count = count + 1
print(count)
# cook your dish here
| PYTHON | {
"starter_code": "",
"url": "https://www.codechef.com/problems/ZCOPREP"
} | |
d876 | train | import sys
from collections import defaultdict as dd
from collections import deque
from fractions import Fraction as f
from copy import *
from bisect import *
from heapq import *
from math import *
from itertools import permutations
def eprint(*args):
print(*args, file=sys.stderr)
zz=1
#sys.setrecursionlimit(10**6)
if zz:
input=sys.stdin.readline
else:
sys.stdin=open('input.txt', 'r')
sys.stdout=open('all.txt','w')
def li():
return [int(xx) for xx in input().split()]
def fli():
return [float(x) for x in input().split()]
def comp(a,b):
if(a>b):
return 2
return 2 if a==b else 0
def gi():
return [xx for x in input().split()]
def fi():
return int(input())
def swap(a,i,j):
a[i],a[j]=a[j],a[i]
def si():
return list(input().rstrip())
def mi():
return map(int,input().split())
def gh():
sys.stdout.flush()
def graph(n,m):
for i in range(m):
x,y=mi()
a[x].append(y)
a[y].append(x)
def bo(i):
return ord(i)-ord('a')
t=fi()
while t>0:
t-=1
n,z1,z2=mi()
d={}
a=li()
flag=0
for i in a:
d[i]=1
d[-i]=1
if i==z1 or i==z2 or i==-z1 or i==-z2:
flag=1
break
if flag:
print(1)
continue
for i in d:
p=[i-z1,i-z2]
c=1
for j in p:
if j in d:
c*=0
flag|=c
print(0 if flag else 2) | PYTHON | {
"starter_code": "",
"url": "https://www.codechef.com/problems/JAGAM"
} | |
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"
} | |
d878 | train | t = int(input())
for _ in range(t):
x, y, k, n = [int(x) for x in input().split()]
k = k*2
temp = abs(x-y)
if(temp%k == 0):
print("Yes")
else:
print("No")
| PYTHON | {
"starter_code": "",
"url": "https://www.codechef.com/problems/CATHIEF"
} | |
d879 | train | # cook your dish here
import numpy as np
def minstairs(n,k):
stairsHeight=[]
stairs=0
current = 0
stairsHeight=list(map(int, input().split()))
stairsHeight=np.array(stairsHeight)
curr=0
for i in range(n):
if stairsHeight[i]-curr<=k:
curr=stairsHeight[i]
else:
if (stairsHeight[i]-curr)%k==0:
stairs+=((stairsHeight[i]-curr)//k)-1
else:
stairs+=(stairsHeight[i]-curr)//k
curr=stairsHeight[i]
return stairs
T=int(input())
for i in range(T):
n,k =list(map(int,input().split()))
print(minstairs(n,k))
| PYTHON | {
"starter_code": "",
"url": "https://www.codechef.com/problems/ADASTAIR"
} | |
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"
} | |
d881 | train | oo = int(input())
for i in range(oo):
val = int(input())
print((val**2)*3.14) | PYTHON | {
"starter_code": "",
"url": "https://www.codechef.com/SPNT2020/problems/AODLS001"
} | |
d882 | train | # cook your dish here
t=int(input())
for i in range(t):
n=int(input())
ar=list(map(int,input().split()))
tot=0
st=0
for j in range(1,n):
if(ar[j-1]>ar[j]):
si=j-st
c=(si*(si+1))//2
tot+=c
st=j
si=n-st
c=(si*(si+1))//2
tot+=c
print(tot)
| PYTHON | {
"starter_code": "",
"url": "https://www.codechef.com/problems/SUBINC"
} | |
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"
} | |
d884 | train | for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
s = set(a)
if n == 1 or len(s) > 2:
print(-1)
continue
if len(s) == 1:
x = s.pop()
if x == 0:
print(n)
elif x == n-1:
print(0)
else:
print(-1)
continue
x, y = sorted(s)
xc, yc = a.count(x), a.count(y)
if xc == y and xc == x + 1:
print(yc)
else:
print(-1)
| PYTHON | {
"starter_code": "",
"url": "https://www.codechef.com/problems/CNTFAIL"
} | |
d885 | train | try:
for _ in range(int(input())):
s,s1=0,0
x,k=[int(i) for i in input().split()]
for i in range(2,x+1):
if(x%i==0):
s=s+i**k
for i in range(2,k+1):
if(k%i==0):
s1+=i*x
print(s,s1)
except EOFError as e:
pass | PYTHON | {
"starter_code": "",
"url": "https://www.codechef.com/SITC2020/problems/FACPOW"
} | |
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"
} | |
d887 | train | for _ in range(int(input())):
n=int(input())
a=list(map(int,input().split()))
x=int(input())
for _ in range(1,n,2):
a[_],a[_-1]=a[_-1],a[_]
for _ in range(n):
a[_]+=(a[_]%3)
# a=a[::-1]
# a.sort()
# if x>a[-1]:
# print(-1)
# continue
l,h=-1,9999999999
for _ in range(n):
# if a[_]>=x:
# if _==n-1:
# print(-1)
# break
# elif _==0:
# print(-1)
# break
# else:
# print(a[_-1],a[_])
# break
if a[_]>l and a[_]<x :
l=a[_]
if a[_]<h and a[_]>x :
h=a[_]
print(l,end=" ")
if h==9999999999:
print(-1)
else:
print(h)
| PYTHON | {
"starter_code": "",
"url": "https://www.codechef.com/ENDE2020/problems/ENCDEC5"
} | |
d888 | train | # cook your dish here
# cook your dish here
for _ in range(int(input())):
n=int(input())
a=list(map(int, input().split()))
b=list(map(int, input().split()))
if a[0]!=0 or b[-1]!=0 or a[-1]!=b[0]:
print('No')
else:
ab=b[0]
flag=0
for i in range(1, n-1):
if a[i]==0 or b[i]==0:
print('No')
flag=1
break
elif a[i]+b[i]<ab:
print('No')
flag=1
break
elif a[i]>ab+b[i] or b[i]>ab+a[i]:
print('No')
flag=1
break
if flag==0:
print('Yes') | PYTHON | {
"starter_code": "",
"url": "https://www.codechef.com/problems/DIS"
} | |
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"
} | |
d890 | train | # cook your dish here
def ceil(num):
if num%1==0:
return int(num//1)
else:
return int((num//1)+1)
for _ in range(int(input())):
n=int(input())
s=input()
p=0
a=[]
for i in range(n):
if s[i]=="P":
p=p+1
req=ceil(0.75*n)
requirement=req-p
for i in range(2,n-2):
if s[i]=="A":
if (s[i-1]=="P" or s[i-2]=="P") and (s[i+1]=="P" or s[i+2]=="P"):
a.append(i)
if requirement>len(a):
print(-1)
else:
print(max(requirement,0)) | PYTHON | {
"starter_code": "",
"url": "https://www.codechef.com/problems/PROXYC"
} | |
d891 | train | # cook your dish here
t=int(input())
while t:
n=int(input())
r1=input()
r2=input()
r1count=0
r2count=0
count=0
for i in range(n):
if(r1[i]=="*"):
r1count+=1
if(r2[i]=="*"):
r2count+=1
if(r1count>0) and (r2count>0):
count=1
r1count=0
r2count=0
i=0
while(i<n):
if(r1[i]=="*"):
r1count+=1
if(r2[i]=="*"):
r2count+=1
if(r1count>1) or (r2count>1):
count+=1
r1count=0
r2count=0
i-=1
i+=1
elif(r1count==0 and r2count>0) or (r2count==0 and r1count>0):
count=max(r1count,r2count)-1
else:
count=0
print(count)
t-=1 | PYTHON | {
"starter_code": "",
"url": "https://www.codechef.com/problems/SNCOUP"
} | |
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"
} | |
d893 | train | from sys import setrecursionlimit
setrecursionlimit(10 * 9)
def solve(i):
if i + k >= n:
return 1
if i in dp:
return dp[i]
mini = float('inf')
for j in range(i+1, min(n, i+k+1)):
if i == -1 or a[i] == a[j]:
mini = min(mini, solve(j) + 1)
dp[i] = mini
return dp[i]
for _ in range(int(input())):
n, k = map(int, input().split())
a = list(map(lambda x: int(x) % 2, input().split()))
le = lo = -1
se = so = -1
for i in range(n-k, n):
if a[i] == 0:
le = i
break
for i in range(n-k, n):
if a[i] == 1:
lo = i
break
m1 = float('inf')
if le != -1:
m1 = 0
while True:
lle = -1
for i in range(se + 1, se + k + 1):
if i == le:
m1 += 2
break
if a[i] == 0:
lle = i
else:
if lle == -1:
m1 = float('inf')
break
se = lle
m1 += 1
continue
break
m2 = float('inf')
if lo != -1:
m2 = 0
while True:
llo = -1
for i in range(so + 1, so + k + 1):
if i == lo:
m2 += 2
break
if a[i] == 1:
llo = i
else:
if llo == -1:
m2 = float('inf')
break
so = llo
m2 += 1
continue
break
if min(m1, m2) != float('inf'):
print(min(m1, m2))
else:
print(-1) | PYTHON | {
"starter_code": "",
"url": "https://www.codechef.com/BIT32020/problems/BIT3D"
} | |
d894 | train | # cook your dish here
from math import floor, sqrt
try:long
except NameError:long = int
def fac(n):
step,maxq,d = lambda x: 1 + (x<<2) - ((x>>1)<<1),long(floor(sqrt(n))),1
q = n % 2 == 0 and 2 or 3
while q <= maxq and n % q != 0:
q = step(d)
d += 1
return q <= maxq and [q] + fac(n//q) or [n]
n,k,s = map(int,input().split())
a,di,l,m,ans,su =list(map(int,input().split())),{},[],0,0,0
for i in a:
bb,su = list(set(fac(i))),su+i
for j in bb:
try:di[j]+=1
except KeyError:m,di[j] = m+1,1
l.append(su*(k-m*s))
if su*(k-m*s) <0:m,di,su = 0,{},0
print(max(l)) | PYTHON | {
"starter_code": "",
"url": "https://www.codechef.com/problems/MAXSPSUM"
} | |
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"
} | |
d896 | train | n=int(input())
ar=list(map(int,input().split()))
dp=[0]*n
dp[0]=ar[0]
dp[1]=ar[1]
for i in range(2,n):
dp[i]=min(dp[i-2],dp[i-1])+ar[i]
ar.reverse()
#print(ar)
dp1=[0]*n
dp1[0]=ar[0]
dp1[1]=ar[1]
for i in range(2,n):
dp1[i]=min(dp1[i-2],dp1[i-1])+ar[i]
print(min(dp[-1],dp1[-1])) | PYTHON | {
"starter_code": "",
"url": "https://www.codechef.com/ZCOPRAC/problems/ZCO12004"
} | |
d897 | train | for tc in range(int(input())):
N = int(input())
a, b = list(map(int, input().split()))
pr = []
# 'L' is lexicographically lower than 'R'.
# so, we should first try to apply L+ or L-
# if we can't then only we'll try to apply R+ or R-
for i in range(N - 1):
l, r = list(map(int, input().split()))
#continue the following process until a == l and b == r
while a != l or b != r:
# trying to apply L-
if a > l:
a -= 1
pr.append('L-')
# now, trying to apply L+ (if a < b)
elif a + 1 < b and a < l:
a += 1
pr.append('L+')
# ok, so far, so good... now, let's try to apply R+
elif b < r:
b += 1
pr.append('R+')
# finally, lastly, trying to apply R- (if a < b)
elif b - 1 > a and b > r:
b -= 1
pr.append('R-')
print(len(pr))
print(''.join(pr)) | PYTHON | {
"starter_code": "",
"url": "https://www.codechef.com/problems/GERALD03"
} | |
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"
} | |
d899 | train | # cook your dish here
from math import pow
t = int(input())
for _ in range(t):
m,n = map(int,input().rstrip().split())
cnt = len(str(n))
x = pow(10,cnt)
if n == x-1:
print(m*cnt,m)
else:
print(m*(cnt-1),m) | PYTHON | {
"starter_code": "",
"url": "https://www.codechef.com/PCO12020/problems/LOTR1"
} | |
d900 | train | from math import ceil
for _ in range(int(input())):
n = int(input())
arr = [int(x) for x in input().split()]
sarr = sum(arr)
mavg = sarr/n
while n>1:
sarr -= arr.pop()
n-=1
mavg = max(mavg, sarr/n)
print(int(ceil(mavg))) | PYTHON | {
"starter_code": "",
"url": "https://www.codechef.com/CROS2020/problems/COCR106"
} |