source
stringclasses
1 value
task_type
stringclasses
1 value
in_source_id
stringlengths
1
4
problem
stringlengths
488
6.07k
gold_standard_solution
stringlengths
19
30.1k
verification_info
dict
metadata
dict
problem_id
stringlengths
5
9
apps
verifiable_code
1162
Solve the following coding problem using the programming language python: Every great chef knows that lucky numbers are positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Our chef has recently returned from the Luc...
```python import sys import os def __starting_point(): start = 0 for line in sys.stdin: if start == 0: start = 1 continue else: try: n = int(line.strip()) # print n q = ...
{ "language": "python", "test_cases": [ { "input": "5\n7\n4\n11\n1\n15\n\n\n", "output": "7\n0\n7\n-1\n7\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/MAY12/problems/CHEFLUCK" }
vfc_3490
apps
verifiable_code
1163
Solve the following coding problem using the programming language python: Who's interested in football? Rayne Wooney has been one of the top players for his football club for the last few years. But unfortunately, he got injured during a game a few months back and has been out of play ever since. He's got proper treat...
```python T = int(input()) for j in range(0,T): line1, line2 = input(), input() seq = line2.split() current_min = 1000001 current_max = 0 max_spread = 0 for i in range(0,len(seq)): current_value = int(seq[i]) if current_min > current_value: current_min = current_value current_max = current_value elif ...
{ "language": "python", "test_cases": [ { "input": "3\n6\n3 7 1 4 2 4\n5\n5 4 3 2 1\n5\n4 3 2 2 3\n", "output": "4\nUNFIT\n1\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/APRIL12/problems/PLAYFIT" }
vfc_3494
apps
verifiable_code
1164
Solve the following coding problem using the programming language python: Mandarin chinese , Russian and Vietnamese as well. Chef is organising a contest with $P$ problems (numbered $1$ through $P$). Each problem has $S$ subtasks (numbered $1$ through $S$). The difficulty of a problem can be calculated as follows: - L...
```python p,s = [int(i) for i in input().split()] scores = {} for j in range(1, p + 1): sc = [int(i) for i in input().split()] ns = [int(i) for i in input().split()] nsc = dict(list(zip(sc,ns))) ssc = sorted(sc) score = 0 for a,b in zip(ssc[:-1], ssc[1:]): if nsc[a] > nsc[b]: score += 1 if score in list(sc...
{ "language": "python", "test_cases": [ { "input": "3 3\n16 24 60\n498 861 589\n14 24 62\n72 557 819\n16 15 69\n435 779 232\n", "output": "2\n1\n3\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/PROBLEMS" }
vfc_3498
apps
verifiable_code
1165
Solve the following coding problem using the programming language python: Chef will not be able to attend the birthday of his best friend Rock. He promised Rock that this will not be the case on his half birthday. To keep his promise Chef must know Rock’s next half birthday accurately. Being busy, he is assigning this...
```python # cook your dish here d = {'january':31,'february':29,'march':31, 'april':30,'may':31,'june':30,'july':31, 'august':31,'september':30,'october':31, 'november':30,'december':31} #l=[[15,'january'],[31,'august'],[10,'october']] l2 = list(d.keys()) for _ in range(int(input())): l=input().split() l[0]=int(...
{ "language": "python", "test_cases": [ { "input": "3\n15 january\n31 august\n10 october\n", "output": "16 july\n1 march\n10 april\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/PAHC2020/problems/HALFBDAY" }
vfc_3502
apps
verifiable_code
1166
Solve the following coding problem using the programming language python: Little Elephant is playing a game with arrays. He is given an array A0, A1, ..., AN−1 of N integers. And then Q queries are given, each containing an integer K. He has to tell how many subarrays satisfy the condition: the function foo returns K ...
```python import sys import math def main(arr,k): ans=0 for i in range(len(arr)): curr_min=float('inf') for j in range(i,len(arr)): curr_min=min(curr_min,arr[j]) if curr_min==k: ans+=1 return ans n=int(input()) arr=list(ma...
{ "language": "python", "test_cases": [ { "input": "5\n4 1 2 3 4\n4\n3\n4\n6\n1\n\n\n", "output": "2\n2\n0\n8\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/SUBMIN" }
vfc_3506
apps
verifiable_code
1168
Solve the following coding problem using the programming language python: Abhishek is fond of playing cricket very much. One morning, he is playing cricket with his friends. Abhishek is a right-hand batsman .He has to face all types of balls either good or bad. There are total 26 balls in the game and each ball is...
```python import sys for _ in range(0,eval(input())): d,inp,mp,n,q=set(),list(map(ord,list(sys.stdin.readline().strip()))),[x=='b' for x in list(sys.stdin.readline().strip())],eval(input()),ord('a') inps = [inp[i:] for i in range(len(inp))] inps.sort() op,prev= 0,'' for ip in inps: i,ct=...
{ "language": "python", "test_cases": [ { "input": "2\nababab\nbgbbbbbbbbbbbbbbbbbbbbbbbb\n1\nacbacbacaa\nbbbbbbbbbbbbbbbbbbbbbbbbbb\n2\n", "output": "5\n8\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/ICOD2016/problems/ICODE16G" }
vfc_3514
apps
verifiable_code
1169
Solve the following coding problem using the programming language python: This is a simple game you must have played around with during your school days, calculating FLAMES of you and your crush! Given the names of two people, cancel out the common letters (repeated occurrence of a letter is treated separately, so 2A'...
```python import sys def joseph(k, n=6): if k==0: k = 1 x = 0 for i in range(2,n+1): x = (x+k)%i return x FLAMES = ['FRIENDS', 'LOVE', 'ADORE', 'MARRIAGE', 'ENEMIES', 'SISTER'] nCase = int(sys.stdin.readline()) for _ in range(nCase): a = ''.join(sys.stdin.readline().split()) b = ''.join(sys.stdin.readline(...
{ "language": "python", "test_cases": [ { "input": "2\nSHILPA\nAAMIR\nMATT\nDENISE\n\n\n\n", "output": "ENEMIES\nLOVE\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/IGNS2012/problems/IG01" }
vfc_3518
apps
verifiable_code
1170
Solve the following coding problem using the programming language python: In order to establish dominance amongst his friends, Chef has decided that he will only walk in large steps of length exactly $K$ feet. However, this has presented many problems in Chef’s life because there are certain distances that he cannot t...
```python t=int(input()) for i in range(0,t): n,k=map(int,input().split()) a1,*a=map(int,input().split()) a.insert(0,a1) j=0 while j<n: if a[j]%k==0: print(1,end="") else: print(0,end="") j+=1 print("") ```
{ "language": "python", "test_cases": [ { "input": "1\n5 3\n12 13 18 20 27216\n", "output": "10101\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/CHEFSTEP" }
vfc_3522
apps
verifiable_code
1171
Solve the following coding problem using the programming language python: Roger recently built a circular race track with length K$K$. After hosting a few races, he realised that people do not come there to see the race itself, they come to see racers crash into each other (what's wrong with our generation…). After th...
```python import numpy as np from numba import njit i8 = np.int64 @njit def solve(a, b, t, K, N): t1 = t // K d = t % K * 2 # b が a から a + d の位置にあれば衝突する x = 0 y = 0 ans = 0 for c in a: while b[x] < c: x += 1 while b[y] <= c + d: y +=...
{ "language": "python", "test_cases": [ { "input": "5 3 11\n1 3\n1 10\n2 4\n2 7\n2 0\n3\n8\n100\n", "output": "4\n10\n110\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/CRSHIT" }
vfc_3526
apps
verifiable_code
1172
Solve the following coding problem using the programming language python: Chef has the string s of length n consisted of digits 4 and 7. The string s is called balanced if there exits such integer x (1 ≤ x ≤ n) that the number of digits 4 in substring s[1; x) is equal to the number of digits 7 in substring s(x; n], wh...
```python from math import factorial def Ncr(n,r): if r<0:return 0 return factorial(n)/(factorial(n-r)*factorial(r)) def solve(m,n): modulo=10**9+7 if m==n: return (Ncr(2*n-1,n-1)+Ncr(2*n-2,n-2))%modulo elif m>n: return (Ncr(m+n,n)-Ncr(m+n-2,n-1))%modulo else: return (Ncr...
{ "language": "python", "test_cases": [ { "input": "2\n47\n4477\n\n\n", "output": "1\n4\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/NOV12/problems/LUCKY9" }
vfc_3530
apps
verifiable_code
1173
Solve the following coding problem using the programming language python: Guddu was participating in a programming contest. He only had one problem left when his mother called him for dinner. Guddu is well aware how angry his mother could get if he was late for dinner and he did not want to sleep on an empty stomach, ...
```python import itertools from collections import defaultdict as dfd def sumPairs(arr, n): s = 0 for i in range(n-1,-1,-1): s += i*arr[i]-(n-1-i)*arr[i] return s def subarrayXor(arr, n, m): ans = 0 xorArr =[0 for _ in range(n)] mp = dfd(list) xorArr[0] = arr[0] for i in range(1, n): xorArr[i] = xorArr[i...
{ "language": "python", "test_cases": [ { "input": "1\n3\n5 2 7\n", "output": "2\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/KS1" }
vfc_3534
apps
verifiable_code
1174
Solve the following coding problem using the programming language python: Chef has a sequence of N$N$ integers A1,A2,...,AN$A_1, A_2, ..., A_N$. Chef thinks that a triplet of integers (i,j,k)$(i,j,k)$ is good if 1≤i<j<k≤N$1 \leq i < j < k \leq N$ and P$P$ in the following expression contains an odd number of ones in ...
```python from math import * t = int(input()) for _ in range(t): n = int(input()) a = [int(d) for d in input().split()] odd,even = 0,0 for i in range(n): if bin(a[i]).count("1")%2 == 1: odd += 1 else: even +=1 total = 0 if odd >= 3 and even >= 2: total += (odd*(odd-1)*...
{ "language": "python", "test_cases": [ { "input": "1\n4\n1 1 2 3\n", "output": "1\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/LOG_EQN" }
vfc_3538
apps
verifiable_code
1175
Solve the following coding problem using the programming language python: Oliver and Nova are true lovers. Inspite of knowing that Nova will die Oliver married her at the lake where they met. But they had a conflict about even and odd numbers. Nova likes the odd numbers and Oliver prefers even. One day they went to a ...
```python import math def lcm(a, b): return (a*b)//gcd(a, b) def gcd(a, b): if b == 0: return a return gcd(b, a%b) for _ in range(int(input())): n = int(input()) na = math.ceil((2*n)/math.acos(-1)) nb = ((n+1)//2)**2 nlcm = lcm(na, nb) oa = math.ceil(n/2) ob = (...
{ "language": "python", "test_cases": [ { "input": "1\n111\n", "output": "YESS(sunglass emo)\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/NEWB2020/problems/CNFCT" }
vfc_3542
apps
verifiable_code
1176
Solve the following coding problem using the programming language python: There are $5$ cities in the country. The map of the country is given below. The tour starts from the red city. Each road is associated with a character. Initially, there is an empty string. Every time a road has been travelled the character ass...
```python for _ in range(int(input())): s=input() if len(s)<4: print("NO") else: if s[-4:]=="1000": print("YES") else: print("NO") ```
{ "language": "python", "test_cases": [ { "input": "1\n100\n", "output": "NO\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/ICM2006" }
vfc_3546
apps
verifiable_code
1177
Solve the following coding problem using the programming language python: Chef has N subordinates. In order to complete a very important order he will choose exactly K of them. He can't choose less than K since it will be not enough to complete the order in time. On the other hand if he chooses more than K subordinate...
```python def nCr(n,k): if(k>n):return 0 k=min(k,n-k) num,den=1,1 for i in range(k): num*=(n-i) den*=(i+1) return num/den def Main(): for cases in range(int(input())): a,b=[int(x) for x in input().split()] print(nCr(a,b)) Main() ```
{ "language": "python", "test_cases": [ { "input": "3\n2 1\n3 3\n10 5\n", "output": "2\n1\n252\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/COOK06/problems/CHEFTEAM" }
vfc_3550
apps
verifiable_code
1178
Solve the following coding problem using the programming language python: Tonight, Chef would like to hold a party for his $N$ friends. All friends are invited and they arrive at the party one by one in an arbitrary order. However, they have certain conditions — for each valid $i$, when the $i$-th friend arrives at th...
```python test=int(input()) for _ in range(test): n=int(input()) ls=list(map(int,input().split())) ls.sort() s=0 for i in range(n): if s>=ls[i]: s=s+1 else: break print(s) ```
{ "language": "python", "test_cases": [ { "input": "3\n2\n0 0\n6\n3 1 0 0 5 5\n3\n1 2 3\n", "output": "2\n4\n0\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/CHFPARTY" }
vfc_3554
apps
verifiable_code
1179
Solve the following coding problem using the programming language python: You are given a positive integer $N$. Consider the sequence $S = (1, 2, \ldots, N)$. You should choose two elements of this sequence and swap them. A swap is nice if there is an integer $M$ ($1 \le M < N$) such that the sum of the first $M$ elem...
```python # cook your dish here from math import sqrt for _ in range(int(input())): n=int(input()) sum=(n*(n+1))//2 #print(sum) if(sum%2!=0): print(0) continue m=(int((sqrt(1+4*(sum)))-1)//2) if(m*(m+1)//2==sum//2): print((((m-1)*m)//2)+n-m+((n-m-1)*(n-m))//2) else: print(n-m) ```
{ "language": "python", "test_cases": [ { "input": "5\n1\n2\n3\n4\n7\n", "output": "0\n0\n2\n2\n3\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/CHFNSWAP" }
vfc_3558
apps
verifiable_code
1180
Solve the following coding problem using the programming language python: You are playing a Billiards-like game on an $N \times N$ table, which has its four corners at the points $\{(0, 0), (0, N), (N, 0),$ and $(N, N)\}$. You start from a coordinate $(x,y)$, $(0 < x < N, 0 < y < N)$ and shoot the ball at an angle $...
```python # cook your dish here t=int(input()) for i in range(t): a=0 b=0 N,K,x,y=map(int,input().split()) if x==y: a=N b=N elif x>y: if K%4==1: a=N b=y-x+N elif K%4==2: a=y-x+N b=N elif K%4==3: a=0 b=x-y else: a=x-y b=0 else: if K%4==1: a=x-y+N b=N elif K%4==2: ...
{ "language": "python", "test_cases": [ { "input": "2\n5 5 4 4\n5 2 3 1\n", "output": "5 5\n3 5\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/BILLRD" }
vfc_3562
apps
verifiable_code
1181
Solve the following coding problem using the programming language python: Chef has a natural number N. Cheffina challenges chef to check whether the given number is divisible by the sum of its digits or not. If the given number is divisible then print "Yes" else "No". -----Input:----- - First-line will contain $T$, t...
```python import sys,io,os,math from math import ceil,log,gcd,inf from itertools import permutations mod=1000000007 mod1=998244353 def printlist(n): sys.stdout.write(" ".join(map(str,n)) + "\n") printf=lambda n:sys.stdout.write(str(n)+"\n") def printns(n): sys.stdout.write(str(n)) def intinp(): return in...
{ "language": "python", "test_cases": [ { "input": "2\n16\n27\n", "output": "No\nYes\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/PEND2020/problems/ANITGUY9" }
vfc_3566
apps
verifiable_code
1182
Solve the following coding problem using the programming language python: Gorodetskiy is a university student. He is really good at math and really likes solving engaging math problems. In the last exam, his professor gave him really hard math problems to solve, but Gorodetskiy could not solve them and failed the exam...
```python def interesting_nums(m): nums = [] for x in range(m + 1, 2 * m + 1): if x * m % (x - m) == 0: nums.append(x) return nums def main(): T = int(input()) for _ in range(T): num_list = interesting_nums(int(input())) print(len(num_list)) for num in num_list: print(num) main() ```
{ "language": "python", "test_cases": [ { "input": "2\n3\n6\n", "output": "2\n4\n6\n5\n7\n8\n9\n10\n12\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/DRMP" }
vfc_3570
apps
verifiable_code
1183
Solve the following coding problem using the programming language python: Problem description. This problem is simple and will introduce you to the Dynamic Programming. You will be given an array and a key value. You will have to find out the occurrences of the key value depending upon the query using Brute Force a...
```python for __ in range(eval(input())): x = eval(input()) a = list(map(int,input().split())) key = eval(input()) query = eval(input()) maxvisited = x #maximum visted value j = x-1 ans = [] val = 0 while j>=0: if a[j]==key: ans.append(val+1) val = val...
{ "language": "python", "test_cases": [ { "input": "1\n10\n1 2 3 1 2 3 1 2 3 1\n3\n5\n2\n4\n6\n8\n2\n\n", "output": "3 8 9\n2 6 1\n1 4 1\n1 2 1\n3 8 1\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/AIPC2015/problems/AN01" }
vfc_3574
apps
verifiable_code
1184
Solve the following coding problem using the programming language python: Chef's friend Alex runs a movie theatre. Due to the increasing number of platforms for watching movies online, his business is not running well. As a friend, Alex asked Chef to help him maximise his profits. Since Chef is a busy person, he needs...
```python from itertools import permutations C = list(permutations(['A','B','C','D'])) V = list(permutations([3,6,9,12])) P = list(permutations([25,50,75,100])) R = [] def test(): d = {} n = int(input()) for i in C[0]: for j in V[0]: d[i+str(j)] = 0 for i in range(n): x,y = input().split() d[x+y] += 1 an...
{ "language": "python", "test_cases": [ { "input": "5\n12\nA 3\nB 12\nC 6\nA 9\nB 12\nC 12\nD 3\nB 9\nD 3\nB 12\nB 9\nC 6\n7\nA 9\nA 9\nB 6\nC 3\nD 12\nA 9\nB 6\n2\nA 9\nB 6\n1\nD 12\n0\n", "output": "575\n525\n-25\n-200\n-400\n475\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/THEATRE" }
vfc_3578
apps
verifiable_code
1185
Solve the following coding problem using the programming language python: Taru likes reading. Every month he gets a copy of the magazine "BIT". The magazine contains information about the latest advancements in technology. Taru reads the book at night and writes the page number to which he has read on a piece of pa...
```python import sys rl=sys.stdin.readline T=int(rl()) for t in range(T): P=int(rl()) T=(P+1)//2 F=list(map(int,rl().split()))[1:] numtorn=int(rl()) t=sum(range(1,P+1))-sum(F) K=T-numtorn print('%.4f' % (t*K/float(T))) ```
{ "language": "python", "test_cases": [ { "input": "2\n10\n2 1 2\n2\n10\n1 8\n0\n", "output": "31.2000\n47.0000\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/SEPT11/problems/TRMAG" }
vfc_3582
apps
verifiable_code
1186
Solve the following coding problem using the programming language python: Bhallaladeva was an evil king who ruled the kingdom of Maahishmati. He wanted to erect a 100ft golden statue of himself and he looted gold from several places for this. He even looted his own people, by using the following unfair strategy: There...
```python import math n = int(input()) a = sorted(map(int,input().split())) l = [0]*n for i in range(n): l[i] = a[i] + l[i-1] for q in range(int(input())): print(l[int(math.ceil(float(n)/(int(input())+1)))-1]) ```
{ "language": "python", "test_cases": [ { "input": "4\n3 2 1 4\n2\n0\n2\n", "output": "10\n3\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/AMR15ROL/problems/AMR15D" }
vfc_3586
apps
verifiable_code
1187
Solve the following coding problem using the programming language python: Chef wants to select a subset $S$ of the set $\{1, 2, \ldots, N\}$ such that there are no two integers $x, y \in S$ which satisfy $\frac{x}{y} = M$. Help Chef find the maximum size of a subset $S$ he can choose and the number of ways in which he...
```python for _ in range(int(input())): N,M = list(map(int,input().split())) count,e,perm = 0,0,1 while(True): lim,start = N//(M**e),N//(M**(e + 1)) + 1 num = lim - start + 1 divs = num//M if((start + divs*M) <= lim): r = (start+divs*M)%M if(r == 0 or (r + (lim - (start + divs*M)) >= M)): divs += 1...
{ "language": "python", "test_cases": [ { "input": "3\n5 2\n10 2\n100 3\n", "output": "4 1\n6 12\n76 49152\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/BANQUNT" }
vfc_3590
apps
verifiable_code
1188
Solve the following coding problem using the programming language python: Chef is a private detective. He was asked to investigate a case of murder in the city of Frangton. Chef arrived in Frangton to find out that the mafia was involved in the case. Chef spent some time watching for people that belong to the clan and...
```python n = eval(input()) r = list(map(int, input().split())) tree = dict() i = 1 for j in r: c = tree.get(j) if c: tree[j].append(i) else: tree[j] = [i] if not tree.get(i): tree[i] = [] i += 1 s = [] for elem in tree: if not tree[elem]: s.append(str(elem)) print(' '.join(s)) ```
{ "language": "python", "test_cases": [ { "input": "6\n0 1 1 2 2 3\n", "output": "4 5 6\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/FEB16/problems/CHEFDETE" }
vfc_3594
apps
verifiable_code
1189
Solve the following coding problem using the programming language python: You are given a sequence $A_1, A_2, \ldots, A_N$. For each $k$ ($1 \le k \le N$), let's define a function $f(k)$ in the following way: - Consider a sequence $B_1, B_2, \ldots, B_N$, which is created by setting $A_k = 0$. Formally, $B_k = 0$ and ...
```python from sys import stdin def gt(num): if num: return num return 0 for __ in range(int(stdin.readline().split()[0])): n = int(stdin.readline().split()[0]) a = list(map(int, stdin.readline().split())) cnta = dict() cnta.setdefault(0) cntb = dict() cntb.setdefault(0) for i in a: cnta[i] = gt(cnta.get(i...
{ "language": "python", "test_cases": [ { "input": "2\n6\n1 2 1 1 3 1\n3\n4 1 4\n", "output": "6\n2\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/CFINASUM" }
vfc_3598
apps
verifiable_code
1190
Solve the following coding problem using the programming language python: Tomya is a girl. She loves Chef Ciel very much. Tomya like a positive integer p, and now she wants to get a receipt of Ciel's restaurant whose total price is exactly p. The current menus of Ciel's restaurant are shown the following table. Name ...
```python t= int(input()) while(t>0): n = int(input()) m=0 m=n//(2**11) n%=(2**11) while(n>0): num=n%2 m+=num n//=2 print(m) t-=1 ```
{ "language": "python", "test_cases": [ { "input": "4\n10\n256\n255\n4096\n", "output": "2\n1\n8\n2\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/CIELRCPT" }
vfc_3602
apps
verifiable_code
1191
Solve the following coding problem using the programming language python: Sandy is a professor at a very reputed institute. The institute mandates that all the lectures be communicated in English. As Sandy is not very good at English(or anything actually) the presentations he displays in class have a lot of spelling m...
```python # cook your dish here from difflib import get_close_matches import sys, os def closeMatches(patterns, word): return get_close_matches(word, patterns, 1, 0.9)[0] def get_string(): return sys.stdin.readline().strip() def get_ints(): return map(int, sys.stdin.readline().strip().split()) ans = [] test...
{ "language": "python", "test_cases": [ { "input": "1\n5 2\nszhbdvrngk\nqzhxibnuec\njfsalpwfkospl\nlevjehdkjy\nwdfhzgatuh\nszhbdvcngk\nqzhxbnuec\n", "output": "szhbdvrngk\nqzhxibnuec\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/PROC2020/problems/ENGRIS" }
vfc_3606
apps
verifiable_code
1192
Solve the following coding problem using the programming language python: You are given a sequence of integers $A_1, A_2, \ldots, A_N$. This sequence is circular ― for each valid $i$, the element $A_{i+1}$ follows after $A_i$, and the element $A_1$ follows after $A_N$. You may insert any positive integers at any posit...
```python from math import gcd from itertools import groupby def gcd_split(seq): gcds= [int(gcd(a,b)==1) for a,b in zip(seq[1:],seq[:-1])] gcds.append(int(gcd(seq[0],seq[-1])==1)) # print(gcds) if max(gcds)==0: return -1 else: splits=[len(list(x))+1 for num,x in groupby(gcds) if num==0] # print(splits) if...
{ "language": "python", "test_cases": [ { "input": "1\n5\n3 6 4 5 9\n", "output": "3 1 1 0\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/MININS" }
vfc_3610
apps
verifiable_code
1193
Solve the following coding problem using the programming language python: There are $N$ robots who work for $Y$ days and on each day they produce some toys .on some days a few robots are given rest. So depending on the availability of robots owner has made a time table which decides which robots will work on the par...
```python MAX = 100005 tree = [0] * MAX; lazy = [0] * MAX; def updateRangeUtil(si, ss, se, us, ue, diff) : if (lazy[si] != 0) : tree[si] += lazy[si]; if (ss != se) : lazy[si * 2 + 1] += lazy[si]; lazy[si * 2 + 2] += lazy[si]; lazy[si] = 0; if (ss > se or ss >...
{ "language": "python", "test_cases": [ { "input": "1\n5\n4\n0 3\n1 2\n4 4\n0 4\n", "output": "4\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/ENDE2020/problems/ENCDEC6" }
vfc_3614
apps
verifiable_code
1194
Solve the following coding problem using the programming language python: Toby has found a game to entertain himself.The game is like this: You are in a coordinate system initially at (0,0) and you are given a sequence of steps which lead to your destination.The steps are given in the form of directions: ’U’ ,’D’ , ’...
```python from collections import Counter try: for _ in range(int(input())): n=int(input()) s=input() d1=dict(Counter(s)) u,d,r,l=0,0,0,0 if 'U' in d1: u=d1['U'] else: u=0 if 'D' in d1: d=d1['D'] else: d=0 if 'R' in d1: r=d1['R'] else: r=0 if 'L' in d1: l=d1['L'] else: ...
{ "language": "python", "test_cases": [ { "input": "3\n7\nULUDLLU\n4\nRUUR\n4\nLRLR\n", "output": "2\n0\n4\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/CSEP2020/problems/TOBY" }
vfc_3618
apps
verifiable_code
1195
Solve the following coding problem using the programming language python: Chefland has all the cities on a straight line. There are $N$ cities in Chefland numbered $1$ to $N$. City $i$ is located at coordinate $x_i$ on the x-axis. Guru wants to travel from city $A$ to city $B$. He starts at time t=0. He has following ...
```python t=int(input()) for _ in range(t): n,a,b,c,d,p,q,y=list(map(int,input().split())) l=list(map(int,input().split())) ans = abs((l[b-1]-l[a-1]))*p x=abs(l[c-1]-l[a-1])*p if x<=y: x=y+abs(l[d-1]-l[c-1])*q+abs(l[b-1]-l[d-1])*p ans=min(ans,x) print(ans) ```
{ "language": "python", "test_cases": [ { "input": "1\n4 1 3 2 4 3 2 4\n1 2 3 4\n", "output": "6\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/WALKFAST" }
vfc_3622
apps
verifiable_code
1196
Solve the following coding problem using the programming language python: Every college has a stud−max$stud-max$ buoy. JGEC$JGEC$ has its own Atul$Atul$ who loves to impress everyone with his smile. A presentation is going on at the auditorium where there are N$N$ rows of M$M$ chairs with people sitting on it. Everyon...
```python t = int(input()) for i in range(t): q = input().split() n = int(q[0]) m = int(q[1]) k = int(q[2]) sumax = 0 b = [] for j in range(n): a = [int(k) for k in input().split()] b = b + [a] for j in range(n): su = 0 for x in range(k): ...
{ "language": "python", "test_cases": [ { "input": "1\n4 4 3\n1 4 5 7\n2 3 8 6\n1 4 8 9\n5 1 5 6\n", "output": "22\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/AARA2018/problems/ARMBH2" }
vfc_3626
apps
verifiable_code
1197
Solve the following coding problem using the programming language python: Chef loves saving money and he trusts none other bank than State Bank of Chefland. Unsurprisingly, the employees like giving a hard time to their customers. But instead of asking them to stand them in long queues, they have weird way of acceptin...
```python lst=[1, 2, 4, 8, 13, 21, 31, 45, 66, 81, 97, 123, 148, 182, 204, 252, 290, 361, 401, 475, 565, 593, 662, 775, 822, 916, 970, 1016, 1159, 1312, 1395, 1523, 1572, 1821, 1896, 2029, 2254, 2379, 2510, 2780, 2925, 3155, 3354, 3591, 3797, 3998, 4297, 4433, 4779, 4851, 5123, 5243, 5298, 5751, 5998, 6374, 6801, 6925,...
{ "language": "python", "test_cases": [ { "input": "4\n1\n2\n3\n4\n", "output": "1\n1\n1 2\n3\n1 2 4\n7\n1 2 4 8\n15\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/PROC2020/problems/CHFBANK" }
vfc_3630
apps
verifiable_code
1198
Solve the following coding problem using the programming language python: Chef recently took a course in linear algebra and learned about linear combinations of vectors. Therefore, in order to test his intelligence, Raj gave him a "fuzzy" problem to solve. A sequence of integers $B_1, B_2, \ldots, B_M$ generates an in...
```python import math import bisect from functools import reduce from collections import defaultdict # import sys # input = sys.stdin.readline def inn(): return int(input()) def inl(): return list(map(int, input().split())) MOD = 10**9+7 INF = inf = 10**18+5 n = inn() a = inl() k = [] for q in range(inn()): k.ap...
{ "language": "python", "test_cases": [ { "input": "2\n2 4\n3\n1\n2\n8\n", "output": "0\n2\n3\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/FUZZYLIN" }
vfc_3634
apps
verifiable_code
1199
Solve the following coding problem using the programming language python: In a country called Chef Land, there was a lot of monetary fraud, so Chefu, the head of the country, decided to choose new denominations of the local currency ― all even-valued coins up to an integer $N$ should exist. After a few days, a citizen...
```python for i in range(int(input())): n,k=list(map(int,input().split())) t=0 if n%2!=0: n-=1 t+=1 t+=(n//k) if n%k!=0: t+=1 print(t) ```
{ "language": "python", "test_cases": [ { "input": "4\n2 2\n1 14\n30 10\n31 4\n", "output": "1\n1\n3\n9\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/CHFMOT18" }
vfc_3638
apps
verifiable_code
1200
Solve the following coding problem using the programming language python: Two sisters, A and B, play the piano every day. During the day, they can play in any order. That is, A might play first and then B, or it could be B first and then A. But each one of them plays the piano exactly once per day. They maintain a com...
```python def checkValidity(s): count = 0 previous = "" for x in s: if count == 0: previous = x count += 1 elif count == 1: count = 0 if previous == x: return "no" return "yes" t = int(input()) for _ in range(t): s = input() print(checkValidity(s)) ```
{ "language": "python", "test_cases": [ { "input": "4\nAB\nABBA\nABAABB\nAA\n", "output": "yes\nyes\nno\nno\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/PLAYPIAN" }
vfc_3642
apps
verifiable_code
1201
Solve the following coding problem using the programming language python: Kim has broken in to the base, but after walking in circles, perplexed by the unintelligible base design of the JSA, he has found himself in a large, empty, and pure white, room. The room is a grid with H∗W$H*W$ cells, divided into H$H$ rows an...
```python # cook your dish here def solve(l,r,c,row,col,po): count=0 visited=set() stack=set() stack.add((l[row][col],row,col)) while stack: ele=stack.pop() visited.add((ele[1],ele[2])) if ele[0]<po: count+=1 if ele[1]-1>=0 and (ele[1]-1,ele[2]) not i...
{ "language": "python", "test_cases": [ { "input": "1\n5 5 3\n4 3 9 7 2\n8 6 5 2 8\n1 7 3 4 3\n2 2 4 5 6\n9 9 9 9 9\n3 4 6\n3 2 5\n1 4 9\n", "output": "10\n0\n19\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/UWCOI20C" }
vfc_3646
apps
verifiable_code
1202
Solve the following coding problem using the programming language python: Mark loves eating chocolates and also likes to be fit. Given the calorie count for every chocolate he eats, find what he has to do to burn the calories. The name of the chocolates along with its calorie count are given as follows: Calories per ...
```python # cook your dish here d = { 'D': 238, 'T': 244, 'M': 138, 'B': 279, 'C': 186 } s = list(input()) totalCal = 0 for i in range(len(s)): if s[i] == 'D': totalCal += d['D'] if s[i] == 'T': totalCal += d['T'] if s[i] == 'M': totalCal += d['M'] if s[i] == 'B': tota...
{ "language": "python", "test_cases": [ { "input": "DDTM\n", "output": "17\n1\n6\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/RTCG2020/problems/RTCG002" }
vfc_3650
apps
verifiable_code
1203
Solve the following coding problem using the programming language python: Given a set of N natural numbers 1,2,3........N and Q query.For each query you have to calculate the total number of subset in which Ith. number of set come at Kth postion.Elements of every subset should be in sorted order. The answer could ...
```python import math f = math.factorial for u in range(eval(input())): n, q = list(map(int, input().split())) for j in range(q): i,k = list(map(int, input().split())) if k>i: c=0 print(c) else: a=2**(n-i) b=1 d=int(i-1) e=1 h=1 g=1 #b=f(i-1)/f(k-1)/f(i-k) if(k-1>i-k): for z in...
{ "language": "python", "test_cases": [ { "input": "1\n3 3\n1 2\n2 1\n3 2\n", "output": "0\n2\n2\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/CDVA16/problems/CDVA1607" }
vfc_3654
apps
verifiable_code
1204
Solve the following coding problem using the programming language python: You are given two strings $S$ and $R$. Each of these strings has length $N$. We want to make $S$ equal to $R$ by performing the following operation some number of times (possibly zero): - Choose two integers $a$ and $b$ such that $1 \le a \le b ...
```python for t in range(int(input())): s = input() r = input() diff = list() index = list() cnt = 0 for i in range(len(s)): if s[i] != r[i]: cnt += 1 index.append(i) for i in range(1, len(index)): diff.append(index[i] - index[i - 1] - 1) diff.sort() fmin = cnt ** 2 oper = cnt ; moves = cnt for i i...
{ "language": "python", "test_cases": [ { "input": "1\nadefb\nbdefa\n", "output": "4\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/MINOPS" }
vfc_3658
apps
verifiable_code
1205
Solve the following coding problem using the programming language python: Do you know Professor Saeed? He is the algorithms professor at Damascus University. Yesterday, he gave his students hard homework (he is known for being so evil) - for a given binary string $S$, they should compute the sum of $F(S, L, R)$ over a...
```python for _ in range(int(input())): s=input() n=len(s) t=0 ans=0 for i in range(n-1): if(s[i]==s[i+1]): t=t+1 x=t for i in range(n): t=x if(i!=0): if(s[i]==s[i-1]): t=t-1 else: t=t+1 y=t for j in range(i,n): t=y try: if(s[j]==s[j+1]): t=t-1 else: t=t+1 ...
{ "language": "python", "test_cases": [ { "input": "1\n001\n", "output": "6\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/EVIPRO" }
vfc_3662
apps
verifiable_code
1206
Solve the following coding problem using the programming language python: As you might remember, the collector of Siruseri had ordered a complete revision of the Voters List. He knew that constructing the list of voters is a difficult task, prone to errors. Some voters may have been away on vacation, others may have m...
```python from sys import stdout, stdin n,m,o = list(map(int, stdin.readline().split())) n= n+m+o l=[] a=[] for i in range(n): b= int(stdin.readline()) if(b in l and b not in a): l.append(b) a.append(b) elif(b not in l): l.append(b) a.sort() stdout.write(str(len(a)) + '\n') stdout....
{ "language": "python", "test_cases": [ { "input": "5 6 5\n23\n30\n42\n57\n90\n21\n23\n35\n57\n90\n92\n21\n23\n30\n57\n90\nSample output:\n5\n21\n23\n30\n57\n90\n", "output": "", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/IARCSJUD/problems/VOTERSDI" }
vfc_3666
apps
verifiable_code
1207
Solve the following coding problem using the programming language python: Chef is the new king of the country Chefland. As first and most important responsibility he wants to reconstruct the road system of Chefland. There are N (1 to N) cities in the country and each city i has a population Pi. Chef wants to build som...
```python t=int(input()) for _ in range(t): n=int(input()) a=list(map(int,input().split())) a.sort() s=sum(a) if a[0]*(s-a[0])<=a[n-1]*(s-a[n-1]): print(a[0]*(s-a[0])) else: print(a[n-1]*(s-a[n-1])) ```
{ "language": "python", "test_cases": [ { "input": "2\n2\n5 10\n4\n15 10 7 13\n", "output": "50\n266\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/KINGSHIP" }
vfc_3670
apps
verifiable_code
1208
Solve the following coding problem using the programming language python: Chef is solving mathematics problems. He is preparing for Engineering Entrance exam. He's stuck in a problem. $f(n)=1^n*2^{n-1}*3^{n-2} * \ldots * n^{1} $ Help Chef to find the value of $f(n)$.Since this number could be very large, compute it m...
```python T=int(input()) t=[] for _ in range(T): N=int(input()) t.append(N) N=max(t)+1 l=[0 for i in range(N)] p=1 a=1 for i in range(1,N): a=(a*i)%1000000007 p=p*a%1000000007 l[i]=p for i in t: print(l[i]) ```
{ "language": "python", "test_cases": [ { "input": "1\n3\n", "output": "12\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/MATHL" }
vfc_3674
apps
verifiable_code
1209
Solve the following coding problem using the programming language python: It's winter and taking a bath is a delicate matter. Chef has two buckets of water. The first bucket has $v_1$ volume of cold water at temperature $t_1$. The second has $v_2$ volume of hot water at temperature $t_2$. Chef wants to take a bath wit...
```python # cook your dish here try: for i in range(int(input())): v1,t1,v2,t2,v3,t3=map(int,input().split()) ok = 0 if t1 <= t3 <= t2: x, y = t2 - t3, t3 - t1 ok = x * v3 <= (x + y) * v1 and y * v3 <= (x + y) * v2 print('YES' if ok else 'NO') except: pass ```
{ "language": "python", "test_cases": [ { "input": "3\n5 10 5 20 8 15\n5 10 5 20 1 30\n5 10 5 20 5 20\n", "output": "YES\nNO\nYES\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/CLBATH" }
vfc_3678
apps
verifiable_code
1210
Solve the following coding problem using the programming language python: -----Problem Statement----- One of the things JEC is known for is its GR (Group Recreation) where juniors and seniors do friendly interaction ;P As for the new session of 2020 seniors decided to have their first GR and give them some treat. Juni...
```python t=int(input()) while t: t=t-1 n,x=input().split() n=int(n) x=int(x) d,l=input().split() if d=='L': p=x elif d=='R': p=(n-x)+1 if p%2==1: if l=='H': lang='H' else: lang='E' elif p%2==0: if l=='H': lang='E' else: lang='H' print(p,lang) ```
{ "language": "python", "test_cases": [ { "input": "2\n15 5\nL H\n20 14\nR E\n*try to trim extra white spaces like new line during input in case of wrong answer\n", "output": "5 H\n7 E\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/COPT2020/problems/GRDAY1" }
vfc_3682
apps
verifiable_code
1211
Solve the following coding problem using the programming language python: The chef is having one string of English lower case alphabets only. The chef wants to remove all "abc" special pairs where a,b,c are occurring consecutively. After removing the pair, create a new string and again remove "abc" special pair from a...
```python # cook your dish here for _ in range(int(input())): s=input() while(s.count("abc")!=0): s=s.replace("abc","") print(s) ```
{ "language": "python", "test_cases": [ { "input": "2\naabcc\nbababccc\n", "output": "ac\nbc\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/PBK12020/problems/ITGUY15" }
vfc_3686
apps
verifiable_code
1213
Solve the following coding problem using the programming language python: Chef and his competitor Kefa own two restaurants located at a straight road. The position of Chef's restaurant is $X_1$, the position of Kefa's restaurant is $X_2$. Chef and Kefa found out at the same time that a bottle with a secret recipe is l...
```python # cook your dish here for t in range(int(input())): x1,x2,x3,v1,v2=[int(x)for x in input().rstrip().split()] t1=abs(x3-x1)/v1 t2=abs(x3-x2)/v2 if t1<t2: print("Chef") elif t1>t2: print("Kefa") elif t1==t2: print("Draw") else: pass ```
{ "language": "python", "test_cases": [ { "input": "3\n1 3 2 1 2\n1 5 2 1 2\n1 5 3 2 2\n", "output": "Kefa\nChef\nDraw\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/CHEFRUN" }
vfc_3694
apps
verifiable_code
1214
Solve the following coding problem using the programming language python: Everybody is worried about Rakesh as the boy does not have much knowledge about the real world. He can not go from one place to another on his own. It's high time he learned to explore the city. He is going to a relative's house situated on the ...
```python try: t=int(input()) for i in range(t): print("Case {}:".format(i+1), end=" ") m, n = map(int,input().split()) x, y = map(int,input().split()) l = int(input()) a=input() destx = a.count("R")-a.count("L") desty = a.count("U")-a.count("D") #print(destx, desty) if (destx<0 or destx>m) or (de...
{ "language": "python", "test_cases": [ { "input": "2\n20 20\n4 5\n13\nLLUUUUURRRRRR\n10 10\n3 4\n7\nUDUDDRR\n", "output": "Case 1: REACHED\nCase 2: DANGER\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/ZUBREACH" }
vfc_3698
apps
verifiable_code
1215
Solve the following coding problem using the programming language python: Two friends David and Rojer were preparing for their weekly class-test. The are preparing for the math test, but because of continuously adding big integers and solving equations they got exhausted. They decided to take break and play a game. Th...
```python def isSolvable( W, R): LW, LR, F, ML, AW, V, LMap = len(W), len(R), set([w[0] for w in W+[R]]), max(map(len, W+[R])), W+[R], set(), {} if LR < ML: return False def dfs(d,i,c): if d == ML: return c == 0 if i == len(W) + 1: s = sum(LMap[w[-d-...
{ "language": "python", "test_cases": [ { "input": "3\nTHIS\nIS\nTOO\nFUNNY\n", "output": "true\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/CHLG2020/problems/MATH88" }
vfc_3702
apps
verifiable_code
1216
Solve the following coding problem using the programming language python: Today Chef wants to evaluate the dishes of his $N$ students. He asks each one to cook a dish and present it to him. Chef loves his secret ingredient, and only likes dishes with at least $X$ grams of it. Given $N$, $X$ and the amount of secret in...
```python t=int(input()) for i in range(t): n,k=map(int,input().split()) m=list(map(int,input().split())) a=0 for i in m: if i>=k: a=1 break if a==1: print('YES') else: print('NO') ```
{ "language": "python", "test_cases": [ { "input": "3\n5 100\n11 22 33 44 55\n5 50\n10 20 30 40 50\n5 45\n12 24 36 48 60\n", "output": "NO\nYES\nYES\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/PCJ18A" }
vfc_3706
apps
verifiable_code
1218
Solve the following coding problem using the programming language python: Richik$Richik$ has just completed his engineering and has got a job in one of the firms at Sabrina$Sabrina$ which is ranked among the top seven islands in the world in terms of the pay scale. Since Richik$Richik$ has to travel a lot to reach th...
```python t=int(input()) for i in range(t): x,n=[int(g) for g in input().split()] sal=0 day=x while day<n: sal=sal+day day+=x print(sal) ```
{ "language": "python", "test_cases": [ { "input": "1\n3 10\n", "output": "18\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/AARA2018/problems/ARMBH1" }
vfc_3714
apps
verifiable_code
1219
Solve the following coding problem using the programming language python: You have found $M$ different types of jewels in a mine and each type of jewel is present in an infinite number. There are $N$ different boxes located at position $(1 ,2 ,3 ,...N)$. Each box can collect jewels up to a certain number ( box at posi...
```python t = int(input()) while t != 0: M = 1000000007 n, m = list(map(int, input().split())) ans = 1 tt = n//2 tt = tt * (tt + 1) ans = pow(m, tt, M) print(ans) t -= 1 ```
{ "language": "python", "test_cases": [ { "input": "2\n1 10\n5 2\n", "output": "1\n64\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/INRO2021/problems/JEWELMIN" }
vfc_3718
apps
verifiable_code
1220
Solve the following coding problem using the programming language python: Lets wish Horsbug98 on his birthday and jump right into the question. In Chefland, $6$ new mobile brands have appeared each providing a range of smartphones. For simplicity let the brands be represented by numbers $1$ to $6$. All phones are sold...
```python import sys from collections import defaultdict from copy import copy R = lambda t = int: t(eval(input())) RL = lambda t = int: [t(x) for x in input().split()] RLL = lambda n, t = int: [RL(t) for _ in range(n)] def solve(): N, Q = RL() P = RL() B = RL() phones = sorted(zip(P, B)) ...
{ "language": "python", "test_cases": [ { "input": "4 2\n4 5 6 7\n1 2 3 4\n3 3\n1 2 3\n3 4\n4 5 6\n", "output": "4\n-1\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/ENJU2020/problems/ECJN209" }
vfc_3722
apps
verifiable_code
1221
Solve the following coding problem using the programming language python: Chef played an interesting game yesterday. This game is played with two variables $X$ and $Y$; initially, $X = Y = 0$. Chef may make an arbitrary number of moves (including zero). In each move, he must perform the following process: - Choose any...
```python from math import sqrt T = int(input()) ans = [] for _ in range(T): X = int(input()) count = 0 x = 0 y = 0 while(x<=X): p = int(sqrt(y)) count += 1 if(p*p>y): x = p y += p**2 else: x = p+1 y += (p+1)**2 if(x<=X): ans.append(count) else: ans.append(count-1) for i in ans: prin...
{ "language": "python", "test_cases": [ { "input": "3\n3\n8\n9\n", "output": "3\n5\n6\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/TWOVRIBL" }
vfc_3726
apps
verifiable_code
1222
Solve the following coding problem using the programming language python: The EEE classes are so boring that the students play games rather than paying attention during the lectures. Harsha and Dubey are playing one such game. The game involves counting the number of anagramic pairs of a given string (you can read ab...
```python def sort_str(s): o = [] for c in s: o.append(c) o.sort() return "".join(o) def find_ana(s): if len(s) <= 1: return 0 h = {} c = 0 for i in range(len(s)): for j in range(i+1, len(s)+1): t = sort_str(s[i:j]) if t in h: c += h...
{ "language": "python", "test_cases": [ { "input": "3\nrama\nabba\nabcd\n", "output": "2\n4\n0\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/COCU2016/problems/CURR2" }
vfc_3730
apps
verifiable_code
1223
Solve the following coding problem using the programming language python: It's the annual military parade, and all the soldier snakes have arrived at the parade arena, But they aren't standing properly. The entire parade must be visible from the main podium, and all the snakes must be in a line. But the soldiers are l...
```python t=int(input()) def vsense(val,a,l): sense=0 ctr=a for c in range(n): if val[c]<=ctr: sense+=-1 else: sense+=1 ctr+=l return sense while t: n,l,a,b=list(map(int,input().split())) val=list(map(int,input().split())) val.sort() sense=0 if b==a+n*l or vsense(val,a,l)<=0: loc=a else: s...
{ "language": "python", "test_cases": [ { "input": "2\n3 4 11 23\n10 11 30\n3 4 11 40\n10 11 30\n", "output": "16\n16\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/CONSESNK" }
vfc_3734
apps
verifiable_code
1224
Solve the following coding problem using the programming language python: Eugene loves sequences, especially arithmetic progressions. One day he was asked to solve a difficult problem. If a sequence of numbers A1, A2, ... , AN form an arithmetic progression A, he was asked to calculate sum of F(Ai), for L ≤ i ≤ R. F(...
```python import fractions import sys f = sys.stdin if len(sys.argv) > 1: f = open(sys.argv[1], "rt") sum_cache = {} def sum_func(x): if x < 10: return x r = sum_cache.get(x) if r is not None: return r xx = 0 while x > 0: xx += x % 10 x /= 10 r = sum...
{ "language": "python", "test_cases": [ { "input": "2\n1 1 1 3\n14 7 2 4\n\n\n", "output": "6\n12\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/NOV15/problems/KFUNC" }
vfc_3738
apps
verifiable_code
1225
Solve the following coding problem using the programming language python: Tomya is a girl. She loves Chef Ciel very much. Today, too, Tomya is going to Ciel's restaurant. Of course, Tomya would like to go to Ciel's restaurant as soon as possible. Therefore Tomya uses one of the shortest paths from Tomya's house to Ci...
```python t=eval(input()) def func(k,n,x,dist,graph): if k==n: x+=[dist[n]] return for i in range(1,n+1): if graph[k][i]!=0 and dist[i]==-1: dist[i]=dist[k]+graph[k][i] func(i,n,x,dist,graph) dist[i]=-1 while t: graph=[[0 for i in range(11)]for j in range(11)] v,e=list(map(int,input().split())) ...
{ "language": "python", "test_cases": [ { "input": "2\n3 3\n1 2 3\n2 3 6\n1 3 7\n3 3\n1 2 3\n2 3 6\n1 3 9\n", "output": "1\n2\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/CIELTOMY" }
vfc_3742
apps
verifiable_code
1226
Solve the following coding problem using the programming language python: It is well-known that the elephants are afraid of mouses. The Little Elephant from the Zoo of Lviv is not an exception. The Little Elephant is on a board A of n rows and m columns (0-based numeration). At the beginning he is in cell with coordi...
```python from collections import defaultdict from itertools import product def solve(mouse,n,m): # shadow matrix will contains the count of mice which affect (i,j) position # if there is a mice at position (i,j) then in shadow matrix it will affect         all four adjacent blocks shadow=[[0 for i in range(m)]f...
{ "language": "python", "test_cases": [ { "input": "2\n3 9\n001000001\n111111010\n100100100\n7 9\n010101110\n110110111\n010011111\n100100000\n000010100\n011011000\n000100101\n", "output": "9\n10\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/LEMOUSE" }
vfc_3746
apps
verifiable_code
1227
Solve the following coding problem using the programming language python: One day, Chef found a cube which has each of its sides painted in some color out of black, blue, red, green, yellow and orange. Now he asks you to check if he can choose three sides such that they are pairwise adjacent and painted in the same co...
```python for _ in range(int(input())): l=list(map(str,input().split())) a=[(1,3,5),(1,3,6),(1,4,5),(1,4,6),(2,3,5),(2,3,6),(2,4,5),(2,4,6)] c=0 for i in a: if len(set([l[i[0]-1],l[i[1]-1],l[i[2]-1]]))==1: c=1 break if c==1: print("YES") else: print("NO") ```
{ "language": "python", "test_cases": [ { "input": "2\nblue yellow green orange black green\ngreen yellow green orange black green\n", "output": "NO\nYES\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/CHCUBE" }
vfc_3750
apps
verifiable_code
1228
Solve the following coding problem using the programming language python: Chef has $N$ axis-parallel rectangles in a 2D Cartesian coordinate system. These rectangles may intersect, but it is guaranteed that all their $4N$ vertices are pairwise distinct. Unfortunately, Chef lost one vertex, and up until now, none of hi...
```python for _ in range(int(input())): n=int(input()) a=[] b=[] for i in range(4*n-1): c,d=list(map(int,input().split())) a.append(c) b.append(d) c1=0 c2=0 for i in a: c1^=i for i in b: c2^=i print(c1,c2) ```
{ "language": "python", "test_cases": [ { "input": "1\n2\n1 1\n1 2\n4 6\n2 1\n9 6\n9 3\n4 3\n", "output": "2 2\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/PTMSSNG" }
vfc_3754
apps
verifiable_code
1229
Solve the following coding problem using the programming language python: Motu and Tomu are very good friends who are always looking for new games to play against each other and ways to win these games. One day, they decided to play a new type of game with the following rules: - The game is played on a sequence $A_0, ...
```python for _ in range(int(input())): n, k = map(int, input().split()) arr= list(map(int, input().split())) motu, tomu = [], [] for i in range(n): if i%2 == 0: motu.append(arr[i]) else: tomu.append((arr[i])) motu.sort(reverse=True) tomu.sort() for i in range(len(motu)): if len(tomu)-1<i: break ...
{ "language": "python", "test_cases": [ { "input": "2\n6 0\n1 1 1 1 1 1\n5 1\n2 4 6 3 4\n", "output": "NO\nYES\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/MTYFRI" }
vfc_3758
apps
verifiable_code
1230
Solve the following coding problem using the programming language python: The Gray code (see wikipedia for more details) is a well-known concept. One of its important properties is that every two adjacent numbers have exactly one different digit in their binary representation. In this problem, we will give you n non-...
```python dic = {} #num = "1" #def tonum(num): # res=0 # for i in range(len(num)): # res = 2*res + int(num[i]) # return res #for i in range(64): # number = tonum(num) # dic[num] = [] # num = num+"0" n = int(input()) flag=0 if n >= 68: inp = input() print("Yes") else: inp = [int(x) for x in input(...
{ "language": "python", "test_cases": [ { "input": "5\n1 0 2 3 7\n", "output": "Yes\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/JULY12/problems/GRAYSC" }
vfc_3762
apps
verifiable_code
1231
Solve the following coding problem using the programming language python: The chef won a duet singing award at Techsurge & Mridang 2012. From that time he is obsessed with the number 2. He just started calculating the powers of two. And adding the digits of the results. But he got puzzled after a few calculations. S...
```python from operator import add from functools import reduce choices=[] for x in range(1800): num_str = list(map (int, str (2**x))) suma = reduce (add, num_str) choices.append(suma) N=int(input()) for x in range(N): t=int(input()) print(choices[t]) ```
{ "language": "python", "test_cases": [ { "input": "3\n5\n10\n4\n", "output": "5\n7\n7\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/AGTK2012/problems/ALG2N" }
vfc_3766
apps
verifiable_code
1232
Solve the following coding problem using the programming language python: AND gates and OR gates are basic components used in building digital circuits. Both gates have two input lines and one output line. The output of an AND gate is 1 if both inputs are 1, otherwise the output is 0. The output of an OR gate is 1 if ...
```python # cook your dish here class node: def __init__(self,a,b=0,c=0): self.val=a self.a=b self.b=c arr=[] def finder(node,val): if(arr[node].val==0): return val else: a=finder(arr[node].a,val) b=finder(arr[node].b,val) if(arr[node].val==1): return a+b-a*b else: return a*b t=int(input()) ...
{ "language": "python", "test_cases": [ { "input": "4\n\n1\n0\n\n3\n0\n0\n1 1 2\n\n3\n0\n0\n2 1 2\n\n5\n0\n0\n0\n2 1 2\n1 3 4\n\n\n", "output": "0.50000\n0.29289\n0.70711\n0.40303\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/CIRCUITS" }
vfc_3770
apps
verifiable_code
1233
Solve the following coding problem using the programming language python: There are players standing in a row each player has a digit written on their T-Shirt (multiple players can have the same number written on their T-Shirt). You have to select a group of players, note that players in this group should be standi...
```python import sys def GRIG(L): LENT = len(L) MINT = 1 GOT = 0 DY = [ [{x: 0 for x in range(0, 10)}, 0, 0] ] for i in L: DY.append([{x: 0 for x in range(0, 10)}, 0, 0]) GOT += 1 for j in range(0, GOT): if DY[j][0][i] == 1: DY[j][0][i] = 0 ...
{ "language": "python", "test_cases": [ { "input": "1\n123343\n", "output": "3\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/COVO2020/problems/GRIG" }
vfc_3774
apps
verifiable_code
1234
Solve the following coding problem using the programming language python: There is a new prodigy in town and he has challenged people to a game. They have to give him an integer N and he will immediately respond with a number which has more than N factors. What the prodigy really does is to do some complex calculation...
```python divisors = [1 , 2 , 3 , 4 , 6 , 8 , 9 , 10 , 12 , 16 , 18 , 20 , 24 , 30 , 32 , 36 , 40 , 48 , 60 , 64 , 72 , 80 , 84 , 90 , 96 , 100 , 108 , 120 , 128 , 144 , 160 , 168 , 180 , 192 , 200 , 216 , 224 , 240 , 256 , 288 , 320 , 336 , 360 , 384 , 400 , 432 , 448 , 480 , 504 , 512 , 576 , 600 , 640 , 672 , 720 , ...
{ "language": "python", "test_cases": [ { "input": "3\n3\n5\n12345678\n", "output": "win 6\nwin 12\nlose\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/IOPC2012/problems/IOPC1211" }
vfc_3778
apps
verifiable_code
1235
Solve the following coding problem using the programming language python: Given a number n. Find the last two digits of 5 ^ n ( 5 to the power of n ). Remember that overflow can occur. -----Input:----- - N — the power in which you need to raise number 5. -----Output:----- Last two digits of 5^n. -----Constraints--...
```python print(25) ```
{ "language": "python", "test_cases": [ { "input": "2\n", "output": "25\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/CMR12121/problems/DGLST" }
vfc_3782
apps
verifiable_code
1236
Solve the following coding problem using the programming language python: You are given a set of n pens, each of them can be red, blue, green, orange, and violet in color. Count a minimum number of pens that should be taken out from the set so that any two neighboring pens have different colors. Pens are considered to...
```python t = int(input()) for _ in range(t): n = int(input()) a = input().strip() prev = a[0] ans = -1 for i in a: if prev == i: ans += 1 prev = i print(ans) ```
{ "language": "python", "test_cases": [ { "input": "2\n5\nRBBRG\n5\nRBGOV\n", "output": "1\n0\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/CDGO2021/problems/DIFFPENS" }
vfc_3786
apps
verifiable_code
1237
Solve the following coding problem using the programming language python: You are standing near a very strange machine. If you put C cents in the machine, the remaining money in your purse will transform in an unusual way. If you have A dollars and B cents remaining in your purse after depositing the C cents, then aft...
```python # cook your dish here for _ in range(int(input())): a,b,c=list(map(int, input().split())) p=a*100+b mx=p ans, cnt = 0, 0 while True: cnt+=1 if p<c or cnt==10000: break else: p-=c a=p//100 b=p%...
{ "language": "python", "test_cases": [ { "input": "2\n9 77 69\n98 99 69\n\n\n", "output": "4\n0\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/MONTRANS" }
vfc_3790
apps
verifiable_code
1238
Solve the following coding problem using the programming language python: Chef likes to play with big numbers. Today, he has a big positive integer N. He can select any two digits from this number (the digits can be same but their positions should be different) and orders them in any one of the two possible ways. For ...
```python test=int(input()) for i in range(test): N=input() X=[] list2=[] for x in N: X.append(x) list1=[] list1=list(set(X)) output='' for x in list1: for y in X: if int(x)>=6: n=int(x)*10+int(y) list2.append(n) for j in list1: if int(j)>=6: m=int(j)*10+int(j) list2.remove(m) list2.sor...
{ "language": "python", "test_cases": [ { "input": "4\n65\n566\n11\n1623455078\n", "output": "A\nAB\nACDFGHIJKLNPQRSTUVW\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/CHEFPDIG" }
vfc_3794
apps
verifiable_code
1239
Solve the following coding problem using the programming language python: The chef is trying to solve some pattern problems, Chef wants your help to code it. Chef has one number K to form a new pattern. Help the chef to code this pattern problem. -----Input:----- - First-line will contain $T$, the number of test case...
```python # cook your dish here t=int(input()) for _ in range(t): n = int(input()) for i in range(n+1): b = n for space in range(n-i): print(" ",end="") for j in range(i+1): print(b,end="") b-=1 print() for l in range(n): a = n ...
{ "language": "python", "test_cases": [ { "input": "2\n2\n4\n", "output": "2\n21\n210\n21\n2\n4\n43\n432\n4321\n43210\n4321\n432\n43\n4\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/PBK32020/problems/ITGUY28" }
vfc_3798
apps
verifiable_code
1240
Solve the following coding problem using the programming language python: The chef is having one array of natural numbers. Cheffina challenges chef that find the sum of weights all the natural numbers present in the array, but the main problem is that all numbers have not original weights. After every 6 natural number...
```python # cook your dish here t = int(input()) while t: x = int(input()) arr = [int(i) for i in input().split()] total = 0 for i in arr: if i % 6 == 0: total += 6 else: total += (i % 6) print(total) t -= 1 ```
{ "language": "python", "test_cases": [ { "input": "1\n6\n6 7 9 11 4 16\n", "output": "23\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/PEND2020/problems/ITGUY00" }
vfc_3802
apps
verifiable_code
1241
Solve the following coding problem using the programming language python: "Don't Drink and Drive, but when you do, Better Call Saul." Once Jesse and Walter were fighting over extra cash, and Saul decided to settle it with a game of stone piles whose winner gets the extra money. The game is described as follows : There...
```python n=int(input()) for i in range(n): k,x=map(int,input().split()) l=list(map(int,input().split())) f,e,o=0,0,0 for i in l: if(i%2==0): e+=1 else: o+=1 if(o<=x//2): f=1 elif(e<=x//2): if((k-x)%2!=0): f=0 else: f=1 else: if(x%2==0): ...
{ "language": "python", "test_cases": [ { "input": "2\n5 3\n4 4 4 3 4\n7 4\n3 3 1 1 1 2 4\n", "output": "Jesse\nWalter\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/GMSTN" }
vfc_3806
apps
verifiable_code
1242
Solve the following coding problem using the programming language python: Chef loves to play with arrays by himself. Today, he has an array A consisting of N distinct integers. He wants to perform the following operation on his array A. - Select a pair of adjacent integers and remove the larger one of these two. This...
```python from math import * for t in range(int(input())): n = int(input()) numberlist = list(map(int,input().split())) numberlist.sort() print(numberlist[0]* ( len(numberlist) -1)) ```
{ "language": "python", "test_cases": [ { "input": "2\n2\n3 4\n3\n4 2 5\n", "output": "3\n4\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/MNMX" }
vfc_3810
apps
verifiable_code
1243
Solve the following coding problem using the programming language python: Chef has a number N, Cheffina challenges the chef to check the divisibility of all the permutation of N by 5. If any of the permutations is divisible by 5 then print 1 else print 0. -----Input:----- - First-line will contain $T$, the number of ...
```python a = int(input()) for i in range(a): b = input() if '5' in b or '0' in b: print(1) continue print(0) ```
{ "language": "python", "test_cases": [ { "input": "2\n19\n385\n", "output": "0\n1\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/PSTR2020/problems/ITGUY06" }
vfc_3814
apps
verifiable_code
1244
Solve the following coding problem using the programming language python: A Train started its journey at x=-infinity is travelling on the x-Coordinate Axis. Given n passengers and the coordinates $b_i$ and $d_i$ for each of the $ith$ passenger at which they board and leave from the train respectively. Due to current C...
```python c=0 for i in range (int(input ())): a, b=map(int, input().split()) c+=abs(a-b)+1 print(c%((10**9) +7)) ```
{ "language": "python", "test_cases": [ { "input": "3\n0 2\n1 3\n-1 4\n", "output": "12\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/COW42020/problems/COW3C" }
vfc_3818
apps
verifiable_code
1245
Solve the following coding problem using the programming language python: The chef is trying to solve some pattern problems, Chef wants your help to code it. Chef has one number K to form a new pattern. Help the chef to code this pattern problem. -----Input:----- - First-line will contain $T$, the number of test case...
```python n = int(input()) l = [0] * n for x in range(n): l[x] = int(input()) for i in range(n): z = 1 for j in range(1,l[i]+1): for k in range(1,l[i]+1): print(z,end='') z += 2 print() ```
{ "language": "python", "test_cases": [ { "input": "4\n1\n2\n3\n4\n", "output": "1\n13\n57\n135\n7911\n131517\n1357\n9111315\n17192123\n25272931\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/PTRN2021/problems/ITGUY51" }
vfc_3822
apps
verifiable_code
1246
Solve the following coding problem using the programming language python: Walter White and Jesse Pinkman (a drug addict) both love to play with chemicals. One day they were playing with some chemicals to make an energy drink. Unknowingly they made a highly powerful drink. To test the drink on others also they called s...
```python # cook your dish here l1=int(input()) for i in range(l1): x=int(input()) y=list(map(int,input().split())) z=list(map(int,input().split())) if max(z)!=max(y): print('YES') else: print('NO') ```
{ "language": "python", "test_cases": [ { "input": "1\n5\n1 2 3 4 5\n2 7 8 9 9\n\n", "output": "YES\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/CHPTRS01/problems/FUNRUN" }
vfc_3826
apps
verifiable_code
1247
Solve the following coding problem using the programming language python: Chef received a permutation $P_1, P_2, \ldots, P_N$ and also an integer $D$ from his good friend Grux, because Grux was afraid he would forget them somewhere. However, since Grux was just playing with the permutation, it was all shuffled, and Ch...
```python import sys sys.setrecursionlimit(10000000) def mergeSortInversions(arr): if len(arr) == 1: return arr, 0 larr=len(arr) a = arr[:larr//2] b = arr[larr//2:] a, ai = mergeSortInversions(a) b, bi = mergeSortInversions(b) c = [] i = 0 j = 0 inversions = 0 + ai + bi la=len(a) while i < l...
{ "language": "python", "test_cases": [ { "input": "2\n5 2\n3 4 5 2 1\n5 2\n4 3 2 1 5\n", "output": "3\n-1\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/DPERM" }
vfc_3830
apps
verifiable_code
1248
Solve the following coding problem using the programming language python: Chef has recently learned about number bases and is becoming fascinated. Chef learned that for bases greater than ten, new digit symbols need to be introduced, and that the convention is to use the first few letters of the English alphabet. For ...
```python # cook your dish here def finder(n): cnt=0 for i in range(2,n+1): a=n while a!=0: r=a%i a=a//i if r==1: cnt+=1 return cnt t=int(input()) for _ in range(t): n=int(input()) if n==0: print(0) elif n==1: print('IN...
{ "language": "python", "test_cases": [ { "input": "4\n6\n9\n11\n24\n", "output": "4\n7\n8\n14\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/BASE" }
vfc_3834
apps
verifiable_code
1249
Solve the following coding problem using the programming language python: For a permutation P = (p1, p2, ..., pN) of numbers [1, 2, ..., N], we define the function f(P) = max(p1, p2) + max(p2, p3) + ... + max(pN-1, pN). You are given N and an integer K. Find and report a permutation P of [1, 2, ..., N] such that f(P) ...
```python # cook your dish here for i in range(int(input())): n,k=[int(i) for i in input().split()] if(n%2==0): if(k<(n*(n+1))//2 - 1 or k>3*((n//2)**2) - 1):print(-1) elif(k==(n*(n+1))//2 - 1): for i in range(1,n+1):print(i,'',end='') print() else: k,count,p,l,x = k-(n*(n+1))...
{ "language": "python", "test_cases": [ { "input": "3\n4 12\n2 2\n5 14\n", "output": "-1\n1 2\n5 4 3 2 1\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/GENPERM" }
vfc_3838
apps
verifiable_code
1250
Solve the following coding problem using the programming language python: Our chef has been assigned a task to make a necklace of length N, from gold, diamond and platinum.There is single kind of gold, two types of diamond and three types of platinum available. A necklace can be represented as strings of the form (G)∗...
```python t=int(input()) for _ in range(t): n=int(input()) p=10**9+7 a=(pow(3,n+1,p)-1) b=(pow(2,n+1,p)-1) print((((3*a)//2)%p-(2*(b))%p+p)%p) ```
{ "language": "python", "test_cases": [ { "input": "2\n1\n2\n", "output": "6\n25\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/ALQU2018/problems/GDP" }
vfc_3842
apps
verifiable_code
1251
Solve the following coding problem using the programming language python: Chef likes to travel very much. He plans some travel routes and wants to know their lengths. He hired you to make these calculations. But be careful, some of the routes are incorrect. There may be some misspelling in city names or there will be ...
```python import sys def _r(*conv) : r = [conv[i](x) for i, x in enumerate(input().strip().split(' '))] return r[0] if len(r) == 1 else r def _ra(conv) : return list(map(conv, input().strip().split(' '))) def _rl() : return list(input().strip()) def _rs() : return input().strip() def _a(k, *v) : return all(x...
{ "language": "python", "test_cases": [ { "input": "5\nDonetsk Kiev New-York Miami Hollywood\n9\nDonetsk Kiev 560\nKiev New-York 7507\nNew-York Miami 1764\nMiami Hollywood 28\nHollywood Miami 30\nMiami New-York 1764\nKiev Donetsk 550\nHollywood New-York 1736\nNew-York Hollywood 1738\n13\n5 Donetsk Kiev Ne...
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/TRAVELER" }
vfc_3846
apps
verifiable_code
1252
Solve the following coding problem using the programming language python: Given a number $n$, give the last digit of sum of all the prime numbers from 1 to $n$ inclusive. -----Input:----- - First line contains number of testcase $t$. - Each testcase contains of a single line of input, number $n$. -----Output:----- ...
```python # cook your dish here import math N = 10**6 sum_arr = [0] * (N + 1) def lprime(): arr = [0] * (N + 1) arr[0] = 1 arr[1] = 1 for i in range(2, math.ceil(math.sqrt(N) + 1)): if arr[i] == 0: for j in range(i * i, N + 1, i): arr[j] = 1 curr_prime...
{ "language": "python", "test_cases": [ { "input": "1\n10\n", "output": "7\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/CSEP2020/problems/IRVS" }
vfc_3850
apps
verifiable_code
1253
Solve the following coding problem using the programming language python: People in Karunanagar are infected with Coronavirus. To understand the spread of disease and help contain it as early as possible, Chef wants to analyze the situation in the town. Therefore, he does the following: - Chef represents the populatio...
```python # cook your dish here T = int(input()) for i in range(T): N,data,D,People = int(input()),list(map(int,list(input()))),int(input()),list(map(int,input().split())) data.insert(0,"|"),data.append("|") infected = [] for i in range(1,N+1): if(data[i]==1): infected.append(i...
{ "language": "python", "test_cases": [ { "input": "2\n9\n000010000\n3\n2 5 8\n5\n00001\n1\n5\n", "output": "6\n1\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/CHPTRS01/problems/WASHHAND" }
vfc_3854
apps
verifiable_code
1254
Solve the following coding problem using the programming language python: Chef wants to organize a contest. Predicting difficulty levels of the problems can be a daunting task. Chef wants his contests to be balanced in terms of difficulty levels of the problems. Assume a contest had total P participants. A problem tha...
```python t = int(input()) for z in range(t) : n,p = [int(x) for x in input().split()] a = [int(x) for x in input().split()] c = [x for x in a if x >= p//2] h = [x for x in a if x <= p//10] if len(c)==1 and len(h)==2 : print("yes") else: print("no") ```
{ "language": "python", "test_cases": [ { "input": "6\n3 100\n10 1 100\n3 100\n11 1 100\n3 100\n10 1 10\n3 100\n10 1 50\n4 100\n50 50 50 50\n4 100\n1 1 1 1\n", "output": "yes\nno\nno\nyes\nno\nno\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/PERFCONT" }
vfc_3858
apps
verifiable_code
1255
Solve the following coding problem using the programming language python: You are teaching students to generate strings consisting of unique lowercase latin characters (a-z). You give an example reference string $s$ to the students. You notice that your students just copy paste the reference string instead of creating...
```python for _ in range(int(input())): s,k=map(str,input().split()) k=int(k) n="NOPE" al=[0]*26 for ele in s: al[ord(ele)-ord('a')]=1 l=len(s) ans=[] # print(al) for i in range(26): if len(ans)==l: break elif al[i]==1 and k>0: k-=1 ans.append(chr(i+ord('a'))) elif al[i]==0: ans.append(chr(...
{ "language": "python", "test_cases": [ { "input": "4\nhelowrd 0\nbackground 0\nabcdefghijklmnopqrstuvwxyz 0\nb 1\n", "output": "abcfgij\nefhijlmpqs\nNOPE\na\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/SDIFFSTR" }
vfc_3862
apps
verifiable_code
1256
Solve the following coding problem using the programming language python: Little chef has just been introduced to the world of numbers! While experimenting with addition and multiplication operations, the little chef came up with the following problem: Given an array A of non-negative integers, how many pairs of indi...
```python # cook your dish here t = int(input()) res = [] for i in range(t): n = int(input()) arr = [int(i) for i in input().split()] num_2 = 0 num = 0 for j in range(len(arr)): if arr[j] == 2: num_2 += 1 if arr[j] > 2: num += 1 res.append(num_2 * num + (num * (num - 1)) // 2) for z in re...
{ "language": "python", "test_cases": [ { "input": "2\n3\n3 4 5\n4\n1 1 1 1\n", "output": "3\n0\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/PROSUM" }
vfc_3866
apps
verifiable_code
1257
Solve the following coding problem using the programming language python: The chef was chatting with his friend who was a mathematician. Chef said "Hi !". His friend replied that '!' is the symbol of factorial. Chef had never heard about it and he asked more about it. Then his friend taught him how to calculate the ...
```python factorials=[1] for x in range(1,201): factorials.append(factorials[x-1]*x) x=int(input()) for x in range(x): n=int(input()) print(factorials[n]) ```
{ "language": "python", "test_cases": [ { "input": "3\n5\n4\n6\n", "output": "120\n24\n720\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/AGTK2012/problems/ALGFACT" }
vfc_3870
apps
verifiable_code
1258
Solve the following coding problem using the programming language python: Chef Zidane likes the number 9. He has a number N, and he wants to turn it into a multiple of 9. He cannot add or remove digits, and he can only change one digit at a time. The only allowed operation is to increment or decrement a digit by one, ...
```python s=int(input()) while(s>0): s-=1 a=input() c=0 for x in a: c+=int(x) if(c<9 and len(a)!=1): print(9-c%9) else: print(min(9-c%9,c%9)) ```
{ "language": "python", "test_cases": [ { "input": "4\n1989\n86236\n90210\n99999999999999999999999999999999999999988\n", "output": "0\n2\n3\n2\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/DIVNINE" }
vfc_3874
apps
verifiable_code
1259
Solve the following coding problem using the programming language python: Vasya likes the number $239$. Therefore, he considers a number pretty if its last digit is $2$, $3$ or $9$. Vasya wants to watch the numbers between $L$ and $R$ (both inclusive), so he asked you to determine how many pretty numbers are in this ...
```python # cook your dish here t=int(input()) for _ in range(t): n,m = map(int,input().split()) count=0 for i in range(n,m+1): p=str(i) if p[-1]=='2' or p[-1]=='3' or p[-1]=='9': count+=1 print(count) ```
{ "language": "python", "test_cases": [ { "input": "2\n1 10\n11 33\n", "output": "3\n8\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/NUM239" }
vfc_3878
apps
verifiable_code
1260
Solve the following coding problem using the programming language python: Lavanya and Nikhil have K months of holidays ahead of them, and they want to go on exactly K road trips, one a month. They have a map of the various cities in the world with the roads that connect them. There are N cities, numbered from 1 to N. ...
```python def merge(intervals,start,mid,end): al = mid-start+1 bl = end-mid A = intervals[start:mid+1] B = intervals[mid+1:end+1] p=0;q=0;k=start; while(p<al and q<bl): if(A[p]<B[q]): intervals[k] = A[p] k+=1;p+=1; else: intervals[k] = B[q] k+=1;q+=1; while(p<al): intervals[k] = A[p] k+...
{ "language": "python", "test_cases": [ { "input": "3\n10 10 3\n1 3\n3 5\n5 1\n1 6\n6 2\n5 6\n2 5\n7 10\n4 7\n10 9\n20 0 15 20 25 30 30 150 35 20\n10 10 2\n1 3\n3 5\n5 1\n1 6\n6 2\n5 6\n2 5\n7 10\n4 7\n10 9\n20 0 15 20 25 30 30 150 35 20\n10 10 5\n1 3\n3 5\n5 1\n1 6\n6 2\n5 6\n2 5\n7 10\n4 7\n10 9\n20 0 1...
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/INOIPRAC/problems/ROADTRIP" }
vfc_3882
apps
verifiable_code
1262
Solve the following coding problem using the programming language python: An area named Renus, is divided into $(N \times M)$ cells. According to archaeological survey the area contains huge amount of treasure. Some cells out of $(N \times M)$ cells contain treasure. But problem is, you can't go to every cell as some ...
```python t=int(input()) for _ in range(t): n,m=[int(x) for x in input().split()] mat=[] ans=[] for i in range(n+2): l=[] p=[] for j in range(m+2): l.append(0) p.append(1000000000) mat.append(l) ans.append(p) y=int(input()) for i in range(y): a,b=[int(x) for x in input().split()] mat[a][b]=1 ...
{ "language": "python", "test_cases": [ { "input": "1\n3 3\n2\n1 1\n1 3\n2\n2 1\n2 2\n", "output": "0 1 0\nX X 1\n4 3 2\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/CACD2020/problems/AJP" }
vfc_3890
apps
verifiable_code
1263
Solve the following coding problem using the programming language python: The chef was playing with numbers and he found that natural number N can be obtained by sum various unique natural numbers, For challenging himself chef wrote one problem statement, which he decided to solve in future. Problem statement: N can b...
```python for _ in range(int(input())): x,n = map(int,input().split()) reach = [0]*(x+1) reach[0] = 1 i=1 while i**n<=x: j = 1 while j+i**n<=x: j+=1 j-=1 while j>=0: if reach[j]>0: reach[j+i**n]+=reach[j] j-=1 ...
{ "language": "python", "test_cases": [ { "input": "2\n4 1\n38 2\n", "output": "2\n1\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/PBK22020/problems/ITGUY24" }
vfc_3894
apps
verifiable_code
1264
Solve the following coding problem using the programming language python: Mohit's girlfriend is playing a game with Nicky. The description of the game is as follows: - Initially on a table Player 1 will put N gem-stones. - Players will play alternatively, turn by turn. - At each move a player can take at most M gem-st...
```python r=[0,1,1,2,1,4,2,6,1,8,4] n,m=[int(x) for x in input().split()] if m==1: while n%2!=1: n=n/2 if n==1: print(1) else: print(n-1) elif (n+1)/2<m: print(m) else: print(n-m) ```
{ "language": "python", "test_cases": [ { "input": "4 2\n", "output": "2\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/CDVA16/problems/CDVA1610" }
vfc_3898
apps
verifiable_code
1265
Solve the following coding problem using the programming language python: The Head Chef is receiving a lot of orders for cooking the best of the problems lately. For this, he organized an hiring event to hire some talented Chefs. He gave the following problem to test the skills of the participating Chefs. Can you solv...
```python def base5(n): if n == 0: return for x in base5(n // 5): yield x yield n % 5 def seq(n): return int(''.join(str(2 * x) for x in base5(n)) or '0') for i in range(eval(input())): k=eval(input()) while(i<k): i=i+1 print(seq(i-1)) ```
{ "language": "python", "test_cases": [ { "input": "2\n2\n5\n\n\n", "output": "2\n8\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/JUNE16/problems/CHEARMY" }
vfc_3902