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
1376
Solve the following coding problem using the programming language python: Salmon loves to be a tidy person. One day, when he looked at the mess that he made after playing with his rubber ducks, he felt awful. Now he wants to clean up his mess, by placing his ducks into boxes. Each rubber duck has a color. There are a ...
```python # cook your dish here for _ in range(int(input())): n,k=map(int,input().split()) c=[int(i) for i in input().split()] i=0 m=0 if(n==2 and k==5): c1=c c.sort() d=dict() for i in range(len(c)): for j in range(len(c1)): if(c[i]==c1[j]): d[i]=j c1[j]=-1 break while(m<n): ...
{ "language": "python", "test_cases": [ { "input": "1\n2 4\n3 4 1\n", "output": "2 1 1 3\n1 1 0 3\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/UWCOI21/problems/UWCOI21C" }
vfc_4346
apps
verifiable_code
1377
Solve the following coding problem using the programming language python: -----General Statement:----- Given the actual high and low temperatures for the day and the normal high and low temperatures for that day, calculate the average difference from normal. -----Input:----- The first line of the data set for this pr...
```python # cook your dish here for _ in range (int(input())): x1,y1,x2,y2=map(int,input().split()) av1=(x1+y1)/2 av2=(x2+y2)/2 if(av1>av2): print(av1-av2," DEGREE(S) ABOVE NORMAL") else: print(av2-av1," DEGREE(S) BELOW NORMAL") ```
{ "language": "python", "test_cases": [ { "input": "3\n75 45 78 40\n50 32 45 30\n56 48 62 45\n", "output": "1.0 DEGREE(S) ABOVE NORMAL\n3.5 DEGREE(S) ABOVE NORMAL\n1.5 DEGREE(S) BELOW NORMAL\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/QTCC2020/problems/VIEW2005" }
vfc_4350
apps
verifiable_code
1378
Solve the following coding problem using the programming language python: There are K nuclear reactor chambers labelled from 0 to K-1. Particles are bombarded onto chamber 0. The particles keep collecting in the chamber 0. However if at any time, there are more than N particles in a chamber, a reaction will cause 1 pa...
```python a,n,k = map(int,input().split()) for i in range(k): print(a%(n+1),end=' ') a=a//(n+1) ```
{ "language": "python", "test_cases": [ { "input": "3 1 3\n", "output": "1 1 0\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/NUKES" }
vfc_4354
apps
verifiable_code
1379
Solve the following coding problem using the programming language python: A simple string contains a large repetition of letters within it. This problem is related to string handling and manipulation. An original message is sent from planet Earth to planet Cybertron in form of a string. However, the letter position a...
```python import sys,math def main(filename): inputfile = open(filename,'rU') data = inputfile.readlines() T=data.pop(0) ans=[] ansstring=str() explored=[] for i in T: if i in explored: #print explored for j in range(len(ans)): if ans[j][0]==i: ans[j][1] += 1 else: ans.append([i,1]) exp...
{ "language": "python", "test_cases": [ { "input": "information\n", "output": "i2n2f1o2r1m1a1t1\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/TCTR2012/problems/NOPC9" }
vfc_4358
apps
verifiable_code
1380
Solve the following coding problem using the programming language python: The chef was searching for his pen in the garage but he found his old machine with a display and some numbers on it. If some numbers entered then some different output occurs on the display. Chef wants to crack the algorithm that the machine is ...
```python # cook your dish here T = int(input()) for t in range(T): N = int(input()) print(int(((N-1)*(N))/2)) ```
{ "language": "python", "test_cases": [ { "input": "1\n7\n", "output": "21\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/PBK32020/problems/ITGUY29" }
vfc_4362
apps
verifiable_code
1381
Solve the following coding problem using the programming language python: Chef works as a cook in a restaurant. Each morning, he has to drive down a straight road with length K$K$ to reach the restaurant from his home. Let's describe this road using a coordinate X$X$; the position of Chef's home is X=0$X = 0$ and the ...
```python # cook your dish here t = int(input()) for _ in range(t): n, k, d = list(map(int, input().split())) x = list(map(int, input().split())) l = list(map(int, input().split())) lane = 3 - l[0] switched = -float('inf') ans = k for i in range(n): if l[i] == lane: if switched + ...
{ "language": "python", "test_cases": [ { "input": "4\n2 10 20\n4 7\n1 2\n4 15 20\n4 6 9 13\n1 2 2 1\n5 10 1\n1 3 5 7 9\n1 2 1 2 1\n2 10 2\n4 5\n1 2\n", "output": "10\n13\n10\n5\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/TWOLANE" }
vfc_4366
apps
verifiable_code
1382
Solve the following coding problem using the programming language python: Chef has an array of N integers. He wants to play a special game. In this game he needs to make all the integers in the array greater than or equal to 0. Chef can use two types of operations. The first type is to increase all the integers of t...
```python n=int(input()) a=list(map(int,input().split())) x=int(input()) l=[] for i in a: if i<0: l.append(-i) l.sort() m=len(l) ans=0 if l: if x>n: ans=sum(l) else: ans=sum(l[m-x:]) print(ans) ```
{ "language": "python", "test_cases": [ { "input": "3\n-1 -2 -3\n2\n", "output": "5\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/INTEG" }
vfc_4370
apps
verifiable_code
1383
Solve the following coding problem using the programming language python: Due to COVID19 all employees of chemical factory are quarantined in home. So, company is organized by automated robots. There are $N$ Containers in company, which are labelled with $1$ to $N$ numbers. There are Total $N$ robots in Company, which...
```python T = int(input()) for _ in range(T): N, K1, K2 = list(map(int, input().split())) P1, P2, P3, P4 = list(map(int, input().split())) ans = 0 arr = [0] * (1005) length = len(arr) for i in range(1,N+1): j = 0 while j < length: arr[j] += 1 ...
{ "language": "python", "test_cases": [ { "input": "1\n4 1 4\n2 2 2 2\n", "output": "8\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/QFUN2020/problems/CHEMFACT" }
vfc_4374
apps
verifiable_code
1384
Solve the following coding problem using the programming language python: On each of the following $N$ days (numbered $1$ through $N$), Chef is planning to cook either pizza or broccoli. He wrote down a string $A$ with length $N$, where for each valid $i$, if the character $A_i$ is '1', then he will cook pizza on the ...
```python for _ in range(int(input())): n, k = map(int, input().split()) l = [*map(int, input())] count = [0] * (n + 1) for i in range(n - 1, -1, -1): if l[i] == 1: count[i] = count[i + 1] + 1 x,y = 0,0 for i in range(n): if l[i] == 1: x += 1 else: try: y = max(y, x + k + count[i + k]) ...
{ "language": "python", "test_cases": [ { "input": "2\n13 2\n0101110000101\n6 3\n100001\n", "output": "5\n4\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/PIBRO" }
vfc_4378
apps
verifiable_code
1385
Solve the following coding problem using the programming language python: Gru has a string $S$ of length $N$, consisting of only characters $a$ and $b$ for banana and $P$ points to spend. Now Gru wants to replace and/or re-arrange characters of this given string to get the lexicographically smallest string possible. F...
```python def __starting_point(): t=int(input()) for _ in range(t): n,p=input().split() n,p=int(n),int(p) s=input() a,b=0,0 arr=[0]*n for i in range(n): arr[i]=s[i] for c in s: if c=='a': a+=1 else: b+=1 swap=0 for i in range(a): if s[i]=='b': swap+=1 tmpp=p if p<=swap: ...
{ "language": "python", "test_cases": [ { "input": "1\n3 3\nbba\n", "output": "aab\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/BANSTR" }
vfc_4382
apps
verifiable_code
1386
Solve the following coding problem using the programming language python: -----Problem description----- As a holiday gift, Tojo received a probability problem. The problem read as follows Consider an N by M grid. Rows are numbered 1 to N, from top to bottom. Columns are numbered 1 to M, from left to right. You are ini...
```python from math import factorial for _ in range(int(input())): N,M=[int(a) for a in input().split()] print(float(N+M-1)) ```
{ "language": "python", "test_cases": [ { "input": "2\n2 2\n1 6\n", "output": "3.000000\n6.000000\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/ANUTHM" }
vfc_4386
apps
verifiable_code
1388
Solve the following coding problem using the programming language python: In India, every individual is charged with income tax on the total income each year. This tax is applied to specific ranges of income, which are called income tax slabs. The slabs of income tax keep changing from year to year. This fiscal year (...
```python arr = [0]*6 arr[1] = 250000*(0.05) arr[2] = 250000*(0.10) arr[3] = 250000*(0.15) arr[4] = 250000*(0.20) arr[5] = 250000*(0.25) for _ in range(int(input())): n = int(input()) tax = 0 if n<=250000: tax = 0 elif 250000<n<=500000: tax = sum(arr[:1]) rem = n - 250000 tax+= (rem)*(0.05) elif 50...
{ "language": "python", "test_cases": [ { "input": "2\n600000\n250000\n", "output": "577500\n250000\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/SLAB" }
vfc_4394
apps
verifiable_code
1389
Solve the following coding problem using the programming language python: In this problem the input will consist of a number of lines of English text consisting of the letters of the English alphabet, the punctuation marks ' (apostrophe), . (full stop), , (comma), ; (semicolon), :(colon) and white space characters (bl...
```python N = int(input()) l = [] for i in range(N): l.append(input()) for j in range(N-1,-1,-1): s = '` '+ l[j] n = len(s)-1 y = s[n] f = '' while y != '`': w = '' while y != ' ': if ord(y) in range(97,123) or ord(y) in range(65,91): w += y ...
{ "language": "python", "test_cases": [ { "input": "2\nThis is a sample piece of text to illustrate this \nproblem. If you are smart you will solve this right.\n\n", "output": "right this solve will you smart are you If problem\nthis illustrate to text of piece sample a is This\n", "type": "s...
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/IARCSJUD/problems/IAREVERS" }
vfc_4398
apps
verifiable_code
1390
Solve the following coding problem using the programming language python: Our Chef who was a renouned mathematician has recently got into diamonds' business. She has accidentally misplaced $Q$ diamonds into a jar which already had $N$ chocolates. She then started wondering about an interesting question as following. ...
```python # cook your dish here for h in range(int(input())): n,q=map(int,input().split()) print(q*(n+q+1)/(q+1)) ```
{ "language": "python", "test_cases": [ { "input": "1\n2 2\n", "output": "3.3333333333\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/RANDID" }
vfc_4402
apps
verifiable_code
1391
Solve the following coding problem using the programming language python: Our chef has recently opened a new restaurant with a unique style. The restaurant is divided into K compartments (numbered from 1 to K) and each compartment can be occupied by at most one customer. Each customer that visits the restaurant has a...
```python try: for _ in range(int(input())): N, K = map(int, input().split()) cell = [] count = 0 l = [] for __ in range(N): inserted = list(map(int, input().split())) cell.append(inserted) cell.sort(key=lambda x: x[1]) time = {} for number in cell: if number[2] not in time: tim...
{ "language": "python", "test_cases": [ { "input": "2\n3 3\n1 3 1\n4 6 2\n7 10 3\n4 2\n10 100 1\n100 200 2\n150 500 2\n200 300 2\n", "output": "3\n3\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/FGFS" }
vfc_4406
apps
verifiable_code
1392
Solve the following coding problem using the programming language python: Chef and Chefina are best friends. Chefina wants to test the Problem Solving skills of chef so she provides Chef 2 integer number $X$ and $Y$ The task of chef is to take the two numbers $X$ and $Y$ and return their SUM. Identify whether Chef c...
```python a,b=map(int,input().split()) print(a+b) ```
{ "language": "python", "test_cases": [ { "input": "6 70\n", "output": "76\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/SPTC2020/problems/CPCEJC4" }
vfc_4410
apps
verifiable_code
1393
Solve the following coding problem using the programming language python: Most problems on CodeChef highlight chef's love for food and cooking but little is known about his love for racing sports. He is an avid Formula 1 fan. He went to watch this year's Indian Grand Prix at New Delhi. He noticed that one segment of t...
```python for _ in range(int(input())): n = int(input()) l = list(map(int,input().split())) ans = 1 l1 = l[0] for i in range(1,n): if l[i] <= l1: l1 = l[i] ans = ans + 1 print(ans) ```
{ "language": "python", "test_cases": [ { "input": "3\n1\n10\n3\n8 3 6\n5\n4 5 1 2 3\n", "output": "1\n2\n2\nConstraints\n1 ≤ T ≤ 100\n1 ≤ N ≤ 10,000\nAll speeds are distinct positive integers that fit in a 32 bit signed integer.\nEach input file will not be larger than 4 MB (4,000,000,000 bytes) in...
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/CARVANS" }
vfc_4414
apps
verifiable_code
1394
Solve the following coding problem using the programming language python: Chef's pizza is the tastiest pizza to exist, and the reason for that is his special, juicy homegrown tomatoes. Tomatoes can be grown in rectangular patches of any side lengths. However, Chef only has a limited amount of land. Consider the enti...
```python from math import * def list_input(): return list(map(int,input().split())) def map_input(): return list(map(int,input().split())) def map_string(): return input().split() def g(n): return (n*(n+1)*(2*n+1))//6 def f(n): ans = 0 for i in range(1,floor(sqrt(n))+1): ans+=i*(i+floor(n/...
{ "language": "python", "test_cases": [ { "input": "2\n4\n10000000000\n", "output": "23\n227374950\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/PCJ18G" }
vfc_4418
apps
verifiable_code
1395
Solve the following coding problem using the programming language python: Ram and Shyam are sitting next to each other, hoping to cheat on an exam. However, the examination board has prepared $p$ different sets of questions (numbered $0$ through $p-1$), which will be distributed to the students in the following way: -...
```python # cook your dish here for test in range(0,int(input())): A,B = map(int,input().split()) diff = abs(A-B) count=0 if not(A^B): print(-1) else: for i in range(1,int(diff**(1/2))+1): if diff%i==0: if diff/i==i: count+=1 else: count+=2 print(count) ```
{ "language": "python", "test_cases": [ { "input": "1\n2 6\n", "output": "3\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/EXAMCHT" }
vfc_4422
apps
verifiable_code
1396
Solve the following coding problem using the programming language python: Mysterious Chefland… Recently, Chef realised that Discuss, the educational system of Chefland, is out of date. Therefore, he is trying to find ways to update the infrastructure in the country. One possible way is to move all materials from Discu...
```python t = input() t = int(t) for _ in range(t): n, m, x, y = input().split() n = int(n) m = int(m) x = int(x) y = int(y) n -= 1 m -= 1 flag = 0 if n % x == 0 and m % y == 0: flag = 1 n -= 1 m -= 1 if n >= 0 and m >= 0: if n % x == 0 and m % y == 0: flag = 1 if flag == 1: print("Chefirnemo")...
{ "language": "python", "test_cases": [ { "input": "5\n2 2 1 2\n11 10 5 9\n11 11 5 9\n12 11 5 9\n1 2 1 100\n", "output": "Chefirnemo\nChefirnemo\nPofik\nChefirnemo\nPofik\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/CHEFADV" }
vfc_4426
apps
verifiable_code
1397
Solve the following coding problem using the programming language python: Chef has a sequence $A_1, A_2, \ldots, A_N$. For a positive integer $M$, sequence $B$ is defined as $B = A*M$ that is, appending $A$ exactly $M$ times. For example, If $A = [1, 2]$ and $M = 3$, then $B = A*M = [1, 2, 1, 2, 1, 2]$ You have to hel...
```python def mForMaxSeq(arr, n): eim = dict() for i in range(n): if arr[i] in eim: eim[arr[i]].append(i) else: eim[arr[i]] = [i] keys = sorted(eim.keys()) # print(eim, keys) connected = False count = 0 pI = -1 nKeys = l...
{ "language": "python", "test_cases": [ { "input": "3\n2\n2 1\n2\n1 2\n5\n1 3 2 1 2\n", "output": "2\n1\n2\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/RC122020/problems/RECNDROT" }
vfc_4430
apps
verifiable_code
1399
Solve the following coding problem using the programming language python: Recently, Chef found a new formula for computing powers of a sequence: - You are given two sequences $A_1, A_2, \ldots, A_N$ and $(l_1, r_1), (l_2, r_2), \ldots, (l_N, r_N)$. - The $1$-st power of the sequence $A$ is $A^1 = A$. - For each $k > 1...
```python import numpy as np def solve(n,k,a,l,r): shape = (n,n) mat = np.zeros(shape, dtype=np.int64) for i in range(n): for j in range(l[i], r[i]): mat[i][j]=1 ans = np.eye(n,n, dtype=np.int64) while(k>0): if k%2 == 1: ans = np.matmul(mat, ...
{ "language": "python", "test_cases": [ { "input": "1\n3 2\n1 2 3\n1 2\n2 3\n1 3\n", "output": "3 1 0\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/HXR" }
vfc_4438
apps
verifiable_code
1400
Solve the following coding problem using the programming language python: Chandler has a list of non zero positive integers with him. He made a very interesting observation about the list. He noticed that the number of unique integers in an array of size $N$ is in the range $L$ to $R$ (both inclusive) and every elemen...
```python # cook your dish here for _ in range(int(input())): n,l,h=list(map(int,input().split())) print(n-l+1+2**(l)-2,1+2**(h)-2+2**(h-1)*(n-h)) ```
{ "language": "python", "test_cases": [ { "input": "2\n4 2 2\n5 1 5\n", "output": "5 7\n5 31\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/ENNO2020/problems/ENCNOV" }
vfc_4442
apps
verifiable_code
1401
Solve the following coding problem using the programming language python: Give me Chocolate Anushka wants to buy chocolates.there are many chocolates in front of her, tagged with their prices. Anushka has only a certain amount to spend, and she wants to maximize the number of chocolates she buys with this money. Gi...
```python n,k = map(int,input().split()) prices = list(map(int,input().split())) prices.sort() sum,cnt = 0, 0 for price in prices: sum += price if sum <= k: cnt += 1 else: break print(cnt) ```
{ "language": "python", "test_cases": [ { "input": "7 50\n1 12 5 111 200 1000 10\n", "output": "4\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/COM12020/problems/CODE_01" }
vfc_4446
apps
verifiable_code
1402
Solve the following coding problem using the programming language python: Recently, Chef studied the binary numeral system and noticed that it is extremely simple to perform bitwise operations like AND, XOR or bit shift on non-negative integers, while it is much more complicated to perform arithmetic operations (e.g. ...
```python def add(A, B): cnt = 0 while B > 0: U = A ^ B B = (A & B) * 2 A = U cnt += 1 return cnt for _ in range(int(input())): print(add(int(input(),2), int(input(), 2))) ```
{ "language": "python", "test_cases": [ { "input": "3\n100010\n0\n0\n100010\n11100\n1010\n", "output": "0\n1\n3\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/BINADD" }
vfc_4450
apps
verifiable_code
1403
Solve the following coding problem using the programming language python: Dhruvil has always been a studious person and will be completing his Engineering soon. He is always kneen about solving problems and is preparing hard for his next interview at Hackerrank. He has practiced lots of problems and now he came across...
```python # cook your dish here # cook your dish here def numDec(s): if not s: return 0 dp = [0 for _ in range(len(s) + 1)] dp[0] = 1 dp[1] = 0 if s[0] == '0' else 1 for i in range(2, len(dp)): if s[i-1] != '0': dp[i] += dp[i-1] two_digit = int(s[i-2 : i]) if two_digit >= 10 and two_digi...
{ "language": "python", "test_cases": [ { "input": "2\n12\n226\n", "output": "2\n3\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/CEFT2020/problems/INTER" }
vfc_4454
apps
verifiable_code
1404
Solve the following coding problem using the programming language python: Today a plane was hijacked by a maniac. All the passengers of the flight are taken as hostage. Chef is also one of them. He invited one of the passengers to play a game with him. If he loses the game, he will release all the passengers, otherwis...
```python import sys test_cases = int(input()) for i in range(0,test_cases): count = input().split() #print count count_r = int(count[0]) count_g = int(count[1]) count_b = int(count[2]) k = int(input()) if k is 1: total = 1 else: total = 1 if count_r < k: total = total + count_r else: total = t...
{ "language": "python", "test_cases": [ { "input": "2\n3 3 3\n1\n3 3 3\n2\n", "output": "1\n4\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/APRIL16/problems/CHBLLNS" }
vfc_4458
apps
verifiable_code
1405
Solve the following coding problem using the programming language python: There are $N$ sabotages available in the game Among Us, initially all at level $0$. $N$ imposters are allotted the task to upgrade the level of the sabotages. The $i^{th}$ imposter $(1 \leq i \leq N)$ increases the level of $x^{th}$ sabotage $...
```python from bisect import bisect n = 32000 def primeSeive(n): prime = [True for i in range(n + 1)] primes = [] p = 2 while (p * p <= n): if (prime[p] == True): for i in range(p * 2, n + 1, p): prime[i] = False p += 1 prime[0] = False prime[1] = Fals...
{ "language": "python", "test_cases": [ { "input": "1\n6\n", "output": "0\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/RC152020/problems/REC15B" }
vfc_4462
apps
verifiable_code
1406
Solve the following coding problem using the programming language python: A sophomore Computer Science student is frustrated with boring college lectures. Professor X agreed to give him some questions; if the student answers all questions correctly, then minimum attendance criteria will not apply to him. Professor X c...
```python # cook your dish here from sys import stdin, stdout for _ in range(int(stdin.readline())): n, q = list(map(int, stdin.readline().split())) arr = list(map(int, stdin.readline().split()))[:n] od = ev = 0 for i in arr: if bin(i).count('1')%2==0: ev += 1 else: od += 1 for _ in range(q): p = int(...
{ "language": "python", "test_cases": [ { "input": "1\n6 1\n4 2 15 9 8 8\n3\n", "output": "2 4\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/ENGXOR" }
vfc_4466
apps
verifiable_code
1407
Solve the following coding problem using the programming language python: You are given an empty grid with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). You should fill this grid with integers in a way that satisfies the following rules: - For any three cells $c_1$, $c_2$ and $c_3$ su...
```python # cook your dish here t = int(input()) for _ in range(t): m,n = [int(d) for d in input().split()] if m == 1: arr = [] if n%4 == 0: print(2) arr = [[1,1,2,2]*(n//4)] elif n%4 == 1: if n == 1: print(1) arr = [[1]] else: print(2) arr = [[1,1,2,2]*(n//4) + [1]] elif n%4 == 2...
{ "language": "python", "test_cases": [ { "input": "2\n1 1\n2 3\n", "output": "1\n1\n3\n1 1 2\n2 3 3\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/DIFNEIGH" }
vfc_4470
apps
verifiable_code
1408
Solve the following coding problem using the programming language python: Chef's loves his dog so much! Once his dog created two strings a and b each of length n consisting of digits 1 and 2, and even a problem about them! Chef's Dog will tell by barking if a string x (also containing only digits 1 and 2 and with leng...
```python mod = 10 ** 9 + 7 from collections import Counter choice = {'1' : ['11', '21', '22'], '2' : ['11', '12', '21']} def solve(a,b): n = len(a) if n == 1: return 2 dp = Counter([('11', '11')]) for i in range(n-1): new = Counter() for x,y in (a[i], b[i]), (b[i], a[i]): for p in choice[x]: for q in ...
{ "language": "python", "test_cases": [ { "input": "2\n1111\n2211\n222\n111\n", "output": "8\n0\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/CHEFTWOS" }
vfc_4474
apps
verifiable_code
1409
Solve the following coding problem using the programming language python: Chef solved so many hard questions, now he wants to solve some easy problems for refreshment. Chef asks Cheffina for the new question. Cheffina challanges the chef to print the total number of 1's in the binary representation of N(natural number...
```python for t in range(int(input())): n=int(input()) print(bin(n).count("1")) ```
{ "language": "python", "test_cases": [ { "input": "2\n2\n5\n", "output": "1\n2\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/PBK22020/problems/ITGUY25" }
vfc_4478
apps
verifiable_code
1410
Solve the following coding problem using the programming language python: Alice's school is planning to take some students from her class on a field trip. Alice is really excited about it. There are a total of S students in her class. But due to budget constraints, the school is planning to take only N students for th...
```python nCr = [[0 for x in range(1001)] for x in range(1001)] for i in range (0,1001): nCr[i][0]=1 nCr[i][i]=1 for i in range (1,1001): for j in range (1,1001): if i!=j: nCr[i][j] = nCr[i-1][j] + nCr[i-1][j-1] t=eval(input()) for rajarshisarkar in range(0,t): s,n,m,k=list(map(int,input().split(' '))) fo...
{ "language": "python", "test_cases": [ { "input": "3\n10 10 5 3\n10 4 6 4\n3 2 2 1\n", "output": "1.000000\n0.000000\n0.500000\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/FTRIP" }
vfc_4482
apps
verifiable_code
1411
Solve the following coding problem using the programming language python: Motu and Patlu are racing against each other on a circular track of radius $R$. Initially they are at the same point on the track and will run in same direction .The coach ordered them to run $X$ rounds of the circular field. Patlu wants to know...
```python # cook your dish here import math def swap(a,b): return b,a t = int(input()) while(t!=0): z = list(map(int,input().strip().split(" "))) x=z[0] r=z[1] a=z[2] b=z[3] #p = math.pi peri = 2*r tp = x*peri if(a<b): a,b=swap(a,b) t1 = tp/a d2 = t1* b dd = abs(tp-d2) if(dd%peri==0): print(int(d...
{ "language": "python", "test_cases": [ { "input": "2\n3 10 2 5\n2 20 5 10\n", "output": "1\n0\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/SMTC2020/problems/RROUNDS" }
vfc_4486
apps
verifiable_code
1412
Solve the following coding problem using the programming language python: Chef changed the password of his laptop a few days ago, but he can't remember it today. Luckily, he wrote the encrypted password on a piece of paper, along with the rules for decryption. The encrypted password is a string S consists of ASCII pri...
```python from decimal import Decimal T = int(input()) for _ in range(T): N = int(input()) data = dict() for __ in range(N): ci, pi = input().split() data[ci] = pi S = list(input()) for i in range(len(S)): if S[i] in data.keys(): S[i] = data[S[i]] ...
{ "language": "python", "test_cases": [ { "input": "4\n2\n5 3\n3 1\n5\n0\n01800.00\n0\n0.00100\n3\nx 0\nd 3\n# .\n0xd21#dd098x\n\n\n", "output": "3\n1800\n.001\n321.33098\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/FORGETPW" }
vfc_4490
apps
verifiable_code
1413
Solve the following coding problem using the programming language python: You are given a 1×1×2$1 \times 1 \times 2$ bar (a cuboid) and a grid A$A$ with N$N$ rows (numbered 1$1$ through N$N$) and M$M$ columns (numbered 1$1$ through M$M$). Let's denote the cell in row r$r$ and column c$c$ by (r,c)$(r, c)$. Some cells o...
```python def issafe(r,c,r1,c1,graph): if (graph[r][c] and graph[r1][c1]): return True return False t=int(input()) for mmmmmm in range(t): n,m=map(int,input().split()) x,y=map(int,input().split()) graph=[[False]*(m+2) for _ in range(n+2)] cost_graph=[[[-1,-1,-1...
{ "language": "python", "test_cases": [ { "input": "2\n2 4\n1 1\n1111\n0111\n2 4\n1 1\n1111\n0011\n\n", "output": "0 -1 -1 2\n-1 -1 -1 3\n0 -1 -1 2\n-1 -1 -1 -1\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/ROLLBAR" }
vfc_4494
apps
verifiable_code
1414
Solve the following coding problem using the programming language python: The auditorium of Stanford University is made up of L*R matrix (assume each coordinate has a chair). On the occasion of an event Chef was called as a chief guest. The auditorium was filled with males (M) and females (F), occupying one chair each...
```python def matrix(L,row,col,c): d={} dp=[] for i in range(row+1): temp=[] for i in range(col+1): temp.append([]) dp.append(temp) for i in range(row+1): dp[i][0]=0 for i in range(col+1): dp[0][i]=0 for i in range(1,row+1): for j in range(1,col+1): if L[i-1][j-1]==c: dp[i][j]=min(dp[i][j-1...
{ "language": "python", "test_cases": [ { "input": "4 3 3\nMMF\nMMM\nFFM\nFFM\n2 F\n3 M\n1 M\n", "output": "yes\nno\nyes\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/CDVA16/problems/CDVA1605" }
vfc_4498
apps
verifiable_code
1415
Solve the following coding problem using the programming language python: Given a string s. Can you make it a palindrome by deleting exactly one character? Note that size of the string after deletion would be one less than it was before. -----Input----- First line of the input contains a single integer T denoting nu...
```python for _ in range(int(input())): s=str(input()) n=len(s) k=s[::-1] a,b="","" for i in range(n): if s[i]!=k[i]: a+=s[i+1:] b+=k[i+1:] break else: a+=s[i] b+=k[i] #print(a,b) if a==a[::-1] or b==b[::-1]: print("YES") else: print("NO") ```
{ "language": "python", "test_cases": [ { "input": "4\naaa\nabc\nabdbca\nabba\n", "output": "YES\nNO\nYES\nYES\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/PRPALN" }
vfc_4502
apps
verifiable_code
1416
Solve the following coding problem using the programming language python: Han Solo and Chewbacca start a space journey to planet Naboo on the Millennium Falcon. During the journey they land at a mysterious planet with high gravity where they find n diamond stones scattered all around. All the stones are of same weight...
```python s,n,s1,lis,new1=[],[],[],[],[] import itertools q = int(input()) s.append(input().split(' ')) s1 = list([list(map(int,x)) for x in s]) sum1 = sum(s1[0]) if len(s1[0])%2!=0 : z = (len(s1[0])+1)//2 n = list(itertools.combinations(s1[0],z)) for j in range(len(n)) : x = sum(n[j]) if x==sum1//2 : lis ...
{ "language": "python", "test_cases": [ { "input": "7\n1 2 3 4 5 6 7\n", "output": "1 2 4 7\n3 5 6\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/SOPC2015/problems/SOPC1504" }
vfc_4506
apps
verifiable_code
1418
Solve the following coding problem using the programming language python: You are given a sequence $A_1, A_2, \ldots, A_N$. You may perform the following operation an arbitrary number of times (including zero): choose two adjacent elements of this sequence, i.e. $A_i$, $A_{i+1}$ for some valid $i$, and swap them. Howe...
```python # cook your dish here # cook your dish here for _ in range(int(input())): n=int(input()) l=list(map(int, input().split())) l.insert(0, 0) l1=[0]*(n+1) l1[1]=l[1] for i in range(2, n+1): l1[i]=max(l1[i-1]+l[i]*i, l1[i-2]+l[i-1]*i+l[i]*(i-1)) print(l1[-1]) ```
{ "language": "python", "test_cases": [ { "input": "2\n4\n2 1 4 3\n4\n7 6 3 2\n", "output": "30\n39\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/SFRV" }
vfc_4514
apps
verifiable_code
1419
Solve the following coding problem using the programming language python: Mr. Wilson was planning to record his new Progressive Rock music album called "Digits. Cannot. Separate". Xenny and PowerShell, popular pseudo-number-theoreticists from the Land of Lazarus were called by him to devise a strategy to ensure the su...
```python t = int(input()) def gcd (a, b): if (b == 0): return a return gcd (b, a % b) dp = {} def solve (p, k, g, s, m, x, y, n): if ((p, k, g) in dp): return dp[(p, k, g)]; ans = 0 if (p == n): if k >= x and k <= y: ans = g else: ans = 0 else: for i in range (p, n): if (i - p + ...
{ "language": "python", "test_cases": [ { "input": "2\n3\n474\n2 1 1\n34\n6311861109697810998905373107116111\n10 4 25\n", "output": "2\n1\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/DIGITSEP" }
vfc_4518
apps
verifiable_code
1420
Solve the following coding problem using the programming language python: In an array, a $block$ is a maximal sequence of identical elements. Since blocks are maximal, adjacent blocks have distinct elements, so the array breaks up into a series of blocks. For example, given the array $[3, 3, 2, 2, 2, 1, 5, 8, 4, 4]$,...
```python # cook your dish here # cook your dish here n=0;m=0; A=[];B=[]; anscount=0;k=0; def generate(n,m,l): nonlocal anscount if(len(l)==n+m): X=l i,j = 0,0 C=[0 for t in range(n+m)] while((i+j)<(n+m)): if(X[i+j] == 0): C[i+j] = A[i] i = i+1 else: C[i+j] = B[j] j = j+1 ans = len(C)...
{ "language": "python", "test_cases": [ { "input": "5\n2 2 4\n1 3\n3 4\n2 2 3\n1 3\n3 4\n2 2 2\n1 3\n3 4\n2 2 4\n4 7\n8 5\n2 2 2\n4 7\n8 5\n", "output": "4\n2\n0\n6\n0\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/ZCOPRAC/problems/ZCO20002" }
vfc_4522
apps
verifiable_code
1421
Solve the following coding problem using the programming language python: Patlu has recently got a new problem based on Pallindromes. A Pallindrome is a number that is same from front and back, example $121$ is pallindrome but $123$ is not . He wants to calculate sum of all $N$ digit number which are Pallindromic in n...
```python def getsum(N): if N==1: return 9 if N==2: return 99 s = "" for i in range(0,N): s = s+'5' s = int(s) if N%2==0: s = s*pow(9,N//2-1) else: s = s*pow(9,N//2) return s%(pow(10,9)+7) def main(): t = int(input()) for _ in range(0,t): N = int(input()) result = getsum(N) print(result) def ...
{ "language": "python", "test_cases": [ { "input": "2\n1\n2\n", "output": "9\n99\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/CCOD2020/problems/PALL9" }
vfc_4526
apps
verifiable_code
1422
Solve the following coding problem using the programming language python: The Little Elephant from the Zoo of Lviv currently is on the military mission. There are N enemy buildings placed in a row and numbered from left to right strating from 0. Each building i (except the first and the last) has exactly two adjacent ...
```python import sys T = int(sys.stdin.readline().strip()) for t in range(T): sys.stdin.readline().strip() st = '0'+sys.stdin.readline().strip()+'0' res = 0 for i in range(1,len(st)-1): if st[i] == st[i-1] == st[i+1] == '0': res+=1 print(res) ```
{ "language": "python", "test_cases": [ { "input": "3\n3\n010\n5\n10001\n7\n0000000\n", "output": "0\n1\n7\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/AUG12/problems/LEBOMBS" }
vfc_4530
apps
verifiable_code
1423
Solve the following coding problem using the programming language python: Vlad enjoys listening to music. He lives in Sam's Town. A few days ago he had a birthday, so his parents gave him a gift: MP3-player! Vlad was the happiest man in the world! Now he can listen his favorite songs whenever he wants! Vlad built up h...
```python # cook your dish here t=int(input()) for i in range(t): n=int(input()) nums=list(map(int,input().split())) k=int(input()) an=nums[k-1] cn=0 for i in range(n): if(nums[i]<an): cn+=1 print(cn+1) ```
{ "language": "python", "test_cases": [ { "input": "3\n4\n1 3 4 2\n2\n5\n1 2 3 9 4\n5\n5\n1 2 3 9 4 \n1\n\n\n", "output": "3\n4\n1\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/JOHNY" }
vfc_4534
apps
verifiable_code
1424
Solve the following coding problem using the programming language python: Little Praneet loves experimenting with algorithms and has devised a new algorithm. The algorithm is performed on an integer as follows: - if the rearmost digit is $0$, he will erase it. - else, he will replace the rearmost digit $d$ with $d-1$....
```python # cook your dish here n,a=map(int,input().split()) for i in range(a): if(n%10==0): n=n//10 else: n=n-1 print(n) ```
{ "language": "python", "test_cases": [ { "input": "1001 2\nSample Input 2\n5 2\n", "output": "100\nSample Output 2\n3\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/COTH2020/problems/SUBALGO" }
vfc_4538
apps
verifiable_code
1425
Solve the following coding problem using the programming language python: Chef has just learned a new data structure - Fenwick tree. This data structure holds information about array of N elements and can process two types of operations: - Add some value to ith element of the array - Calculate sum of all elements on ...
```python t=int(input()) count=[] for i in range(t) : s = input() a,b,c,n = s.split() n=int(n) d = int(a+b*n+c,2) count.append(0) while(d>0) : d=(d&(d+1))-1 count[i]+=1 for i in range(t) : print(count[i]) ```
{ "language": "python", "test_cases": [ { "input": "4\n001 100 011 4\n1000 1101 100 3\n1010 001 101 4\n010 101 000 4\n", "output": "6\n12\n8\n10\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/FENWITER" }
vfc_4542
apps
verifiable_code
1426
Solve the following coding problem using the programming language python: Chef is operating a slush machine. The machine produces slush drinks with $M$ flavors (numbered $1$ through $M$); for each valid $i$, the maximum number of drinks with flavour $i$ the machine can produce is $C_i$. Chef expects $N$ customers to c...
```python t=int(input()) for i in range(t): n,m=list(map(int,input().split())) l=[0]+list(map(int,input().split())) s=0 c=1 m1=[] for i in range(n): d,f,b=list(map(int,input().split())) if(l[d]>0): m1.append(d) s+=f l[d]-=1 else: m1.append(0) s+=b for i in range(n): if(m1[i]==0): for j ...
{ "language": "python", "test_cases": [ { "input": "1\n5 3\n1 2 3\n2 6 3\n2 10 7\n2 50 3\n1 10 5\n1 7 4\n", "output": "33\n2 2 3 1 3\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/SLUSH" }
vfc_4546
apps
verifiable_code
1427
Solve the following coding problem using the programming language python: Today, puppy Tuzik is going to a new dog cinema. He has already left his home and just realised that he forgot his dog-collar! This is a real problem because the city is filled with catchers looking for stray dogs. A city where Tuzik lives in ca...
```python # cook your dish here from sys import stdin,stdout a,b=list(map(int,stdin.readline().split())) left=[] top=[] for i in range(a): c,d=list(map(int,stdin.readline().split())) left.append(c) top.append(d) left.sort() top.sort() from bisect import bisect_right as br from bisect import bisect_left as bl row=0 c...
{ "language": "python", "test_cases": [ { "input": "2 3\n1 2\n0 1\nRDL\n", "output": "4\n6\n6\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/PPCTS" }
vfc_4550
apps
verifiable_code
1428
Solve the following coding problem using the programming language python: Pied Piper is a startup company trying to build a new Internet called Pipernet. Currently, they have $A$ users and they gain $X$ users everyday. There is also another company called Hooli, which has currently $B$ users and gains $Y$ users everyd...
```python # cook your dish here import heapq as hq from math import floor for _ in range(int(input())): n,a,b,x,y,z=map(int,input().split()) arr=[-int(i) for i in input().split()] days=((z-b-1)//y) ans=0 hq.heapify(arr) curr=a+days*x while curr<z : u=hq.heappop(arr) u=-u if u==0 : break else: curr+...
{ "language": "python", "test_cases": [ { "input": "3\n3 10 15 5 10 100\n12 15 18\n3 10 15 5 10 100\n5 5 10\n4 40 80 30 30 100\n100 100 100 100\n", "output": "4\nRIP\n1\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/PEWDSVTS" }
vfc_4554
apps
verifiable_code
1430
Solve the following coding problem using the programming language python: Chef wants you to distribute candies among $N$ kids who are sitting in a circle. However, he wants to make some kids jealous of others. Thus, he wants you to distribute candies in such a way that there is a difference of at least $K$ candies bet...
```python # cook your dish here for _ in range(int(input())): n,k = [int(v) for v in input().split()] ans = (n//2)*(k+2) if n%2 == 0: ans = ans else: ans += 1 + 2*k print(ans) ```
{ "language": "python", "test_cases": [ { "input": "1\n2 1\n", "output": "3\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/AGPR2020/problems/ALPR2000" }
vfc_4562
apps
verifiable_code
1431
Solve the following coding problem using the programming language python: After the hundred years of war started by the Fire Nation, its time for the Water Tribes to bring it to an end. Avatar asked Sokka to go to the Southern WarZone from The Northern WarZone and gave him some money in a bag for his journey. Sokka ha...
```python m=1000000007 def gcd(a, b): if (a == 0): return b return gcd(b % a, a) def modexp(x, n): if (n == 0) : return 1 elif (n % 2 == 0) : return modexp((x * x) % m, n // 2) else : return (x * modexp((x * x) % m, (n ...
{ "language": "python", "test_cases": [ { "input": "2\n5\n2\n", "output": "200000002\n0\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/COW42020/problems/COW3F" }
vfc_4566
apps
verifiable_code
1433
Solve the following coding problem using the programming language python: The Little Elephant loves lucky strings. Everybody knows that the lucky string is a string of digits that contains only the lucky digits 4 and 7. For example, strings "47", "744", "4" are lucky while "5", "17", "467" are not. The Little Elephan...
```python t = int(input()) for i in range(0,t): a = input() b = input() agts=bgts=afour=bfour=aseven=bseven=altf=bltf=afts=bfts=0; for j in a: if j >= '7': if j > '7': agts += 1 else: aseven += 1 elif j >= '4': if j > '4': afts += 1 else: afour += 1 else: altf += 1 for ...
{ "language": "python", "test_cases": [ { "input": "4\n4\n7\n435\n479\n7\n8\n1675475\n9756417\n\n\n", "output": "7\n74\n\n777744\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/OCT12/problems/LUCKY10" }
vfc_4574
apps
verifiable_code
1434
Solve the following coding problem using the programming language python: There's a tree and every one of its nodes has a cost associated with it. Some of these nodes are labelled special nodes. You are supposed to answer a few queries on this tree. In each query, a source and destination node (SNODE$SNODE$ and DNODE$...
```python # cook your dish here # cook your dish here import numpy as np n, s, q = [int(j) for j in input().split()] edges = [int(j)-1 for j in input().split()] costs = [int(j) for j in input().split()] special = [int(j)-1 for j in input().split()] queries = [[0] * 3 for _ in range(q)] for i in range(q): queries[i] ...
{ "language": "python", "test_cases": [ { "input": "7 1 5\n1 1 2 2 3 3\n3 5 4 2 7 9 1\n1\n2 3 100\n1 1 100\n2 1 100\n4 5 100\n4 7 100\n", "output": "6\n6\n6\n20\n16\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/DEMTREE" }
vfc_4578
apps
verifiable_code
1435
Solve the following coding problem using the programming language python: Indraneel's student has given him data from two sets of experiments that the student has performed. Indraneel wants to establish a correlation between the two sets of data. Each data set is a sequence of $N$ numbers. The two data sets do not mat...
```python import copy n=int(input()) a=[int(x) for x in input().split()] b=[int(x) for x in input().split()] c=[] d=[] lcs=[] def lcsfn(a,c,corda,cordb): for i in range(n+1): d.append([0]*(n+1)) lcs.append([0]*(n+1)) for i in range(1,n+1): for j in range(1,n+1): if a[i-1]==c[j-1]: lcs[i][j]...
{ "language": "python", "test_cases": [ { "input": "7\n3 8 4 23 9 11 28\n2 3 22 26 8 16 12\n", "output": "4\n3 4 23 9\n2 3 22 8\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/IARCSJUD/problems/EXPT" }
vfc_4582
apps
verifiable_code
1436
Solve the following coding problem using the programming language python: Harrenhal is the largest castle in the Seven Kingdoms and is the seat of House Whent in the Riverlands, on the north shore of the Gods Eye lake. Since the War of Conquest, however, it has become a dark and ruinous place. (c) A Wiki of Ice and Fi...
```python # cook your dish here for _ in range(int(input())): g=input() h=g[::-1] if h==g : print(1) else: print(2) ```
{ "language": "python", "test_cases": [ { "input": "1\nabbabaab\n\n\n", "output": "2\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/HHAL" }
vfc_4586
apps
verifiable_code
1437
Solve the following coding problem using the programming language python: A prime number is number x which has only divisors as 1 and x itself. Harsh is playing a game with his friends, where his friends give him a few numbers claiming that they are divisors of some number x but divisor 1 and the number x itself are n...
```python import math def findnumber(l,n): l.sort() x = l[0] * l[-1] vec = [] i = 2 while (i*i)<=x: if x%i==0: vec.append(i) if x//i !=i: vec.append(x//i) i = i + 1 vec.sort() if len(vec)!=n: return -1 else: j = ...
{ "language": "python", "test_cases": [ { "input": "3\n2\n2 3\n2\n4 2\n3\n12 3 2\n", "output": "6\n8\n-1\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/BRBG2020/problems/FTNUM" }
vfc_4590
apps
verifiable_code
1438
Solve the following coding problem using the programming language python: Mandarin chinese , Russian and Vietnamese as well. Let's denote $S(x)$ by the sum of prime numbers that divides $x$. You are given an array $a_1, a_2, \ldots, a_n$ of $n$ numbers, find the number of pairs $i, j$ such that $i \neq j$, $a_i$ divid...
```python # cook your dish here def prime_factors(n): i = 2 factors =set() while i * i <= n: if n % i: i += 1 else: n //= i factors.add(i) if n > 1: factors.add(n) return factors for _ in range(int(input())): n=int(input()) a=list(map(int,input().split())) ans=0 s=[] for i in range(n): s.appe...
{ "language": "python", "test_cases": [ { "input": "1\n5\n2 30 2 4 3\n", "output": "6\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/PRMDIV" }
vfc_4594
apps
verifiable_code
1439
Solve the following coding problem using the programming language python: Chef has arrived in Dagobah to meet with Yoda to study cooking. Yoda is a very busy cook and he doesn't want to spend time with losers. So he challenges the Chef to a series of games, and agrees to teach the Chef if Chef can win at least P of th...
```python import math dp = [] dp.append(0) for i in range(1,1000005): dp.append(math.log(i) + dp[i-1]) t = int(input()) for i in range(t): n,m,p,k = input().split() n = int(n) m = int(m) p = int(p) k = int(k) if p==0 or (n%2==0 and m%2==0): ans = 1.0 print(ans) elif n%2==1 and m%2==1: ans=0.0 print(a...
{ "language": "python", "test_cases": [ { "input": "2\n2 3 2 3\n2 2 5 5\n", "output": "0.500000\n1.000000\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/CHEFYODA" }
vfc_4598
apps
verifiable_code
1440
Solve the following coding problem using the programming language python: You are given an array $A$ of $N$ positive and pairwise distinct integers. You can permute the elements in any way you want. The cost of an ordering $(A_1, A_2, \ldots, A_N)$ is defined as $ (((A_1 \bmod A_2) \bmod A_3)......) \bmod A_N$ where...
```python # cook your dish here t=int(input()) for i in range(t): n=int(input()) a=list(map(int,input().split())) print(min(a)) ```
{ "language": "python", "test_cases": [ { "input": "1\n2\n7 12\n", "output": "7\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/EXUNA" }
vfc_4602
apps
verifiable_code
1441
Solve the following coding problem using the programming language python: Chef is again playing a game with his best friend Garry. As usual, the rules of this game are extremely strange and uncommon. First, they are given a stack of $N$ discs. Each disc has a distinct, non-negative integer written on it. The players e...
```python for _ in range(int(input())): n, k = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) a = [-1] + a[::-1] mx = a.index(max(a)) dp = [0] * (n + 1) for i in range(1, n + 1): for x in b: if i - x < 0: continue if i - x < mx <= i: dp[i] = 1 el...
{ "language": "python", "test_cases": [ { "input": "1\n3 2\n5 7 1\n1 2\n", "output": "Chef\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/CLGAME" }
vfc_4606
apps
verifiable_code
1442
Solve the following coding problem using the programming language python: Chef is baking a cake. While baking, in each minute the size of cake doubles as compared to its previous size. In this cake, baking of cake is directly proportional to its size. You are given $a$, the total time taken(in minutes) to bake the w...
```python # cook your dish here for _ in range(int(input())): a=int(input()) print(a/2+2) ```
{ "language": "python", "test_cases": [ { "input": "1\n2\n", "output": "3\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/ECPG2020/problems/ECPC10C" }
vfc_4610
apps
verifiable_code
1443
Solve the following coding problem using the programming language python: Once N boys and M girls attended a party. You are given a matrix A of N rows and M columns where Aij is 1 if the i-th boy likes the j-th girl, otherwise it will be 0. Note that it is not necessary that if a boy x likes girl y, then girl y should...
```python for i in range(int(input())): n,k=map(int,input().split()) m=[] for j in range(n): l=list(input()) m.append(l) a=0 for k in range(k): b=0 for p in range(n): if m[p][k]=='1': b+=1 if b>1: a+=((b*(b-1))//2) print(a) ```
{ "language": "python", "test_cases": [ { "input": "2\n4 3\n111\n100\n110\n000\n2 2\n10\n01\n", "output": "4\n0\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/LCOLLIS" }
vfc_4614
apps
verifiable_code
1444
Solve the following coding problem using the programming language python: Chef is a big fan of soccer! He loves soccer so much that he even invented soccer for dogs! Here are the rules of soccer for dogs: - N$N$ dogs (numbered 1$1$ through N$N$) stand in a line in such a way that for each valid i$i$, dogs i$i$ and i+1...
```python for _ in range(int(input())): num=int(input()) arr=list(map(int,input().split())) dp=[0]*num dp[0]=1 ans=1 j=0 for i in range(1,num): j=i+1 count=1 dp[i]=dp[i-1]%1000000007 if i-2>=0 and arr[i-2]==2: dp[i]+=dp[i-2]%1000000007 if i-3>=0 and arr[i-3]==2: dp[i]+=dp[i-3] ...
{ "language": "python", "test_cases": [ { "input": "3\n4\n1 1 1 1\n3\n2 2 2\n4\n1 2 1 1\n", "output": "4\n5\n6\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/CHEFSOC" }
vfc_4618
apps
verifiable_code
1446
Solve the following coding problem using the programming language python: Given an integer N, Chef wants to find the smallest positive integer M such that the bitwise XOR of M and M+1 is N. If no such M exists output -1. -----Input----- The first line of input contain an integer T denoting the number of test cases. E...
```python # from math import log2 # N = 10000 # for i in range(1,N): # # print(i) # for m in range(i): # if( (m^(m+1))==i ): # print(i) # print(m,m+1,bin(m)[2:]) # print() # break # # else: # # print(-1) # # print() T = int(input()) ans...
{ "language": "python", "test_cases": [ { "input": "1\n3\n", "output": "1\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/XORNUBER" }
vfc_4626
apps
verifiable_code
1447
Solve the following coding problem using the programming language python: In Chefland, types of ingredients are represented by integers and recipes are represented by sequences of ingredients that are used when cooking. One day, Chef found a recipe represented by a sequence $A_1, A_2, \ldots, A_N$ at his front door an...
```python # cook your dish here for __ in range(int(input())): n=int(input()) arr=list(map(int,input().split())) d={} s=set() flag=0 for i in range(n): if arr[i] in list(d.keys()): d[arr[i]]+=1 else: d[arr[i]]=1 curr_ele=arr[i] if (curr_ele in s) and arr[i-1]!=arr[i]: flag=1 break else: ...
{ "language": "python", "test_cases": [ { "input": "3\n6\n1 1 4 2 2 2\n8\n1 1 4 3 4 7 7 7\n8\n1 7 7 3 3 4 4 4\n", "output": "YES\nNO\nNO\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/CHEFRECP" }
vfc_4630
apps
verifiable_code
1448
Solve the following coding problem using the programming language python: Kshitij has recently started solving problems on codechef. As he is real problem solving enthusiast, he wants continuous growth in number of problems solved per day. He started with $a$ problems on first day. He solves $d$ problems more than p...
```python # cook your dish here t = int(input()) for _ in range(t): a,d,k,n,inc = map(int, input().strip().split()) res = a for i in range(1, n): if i%k == 0: d += inc res += d print(res) ```
{ "language": "python", "test_cases": [ { "input": "1\n1 4 3 8 2\n", "output": "43\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/CFUS2020/problems/CFS2001" }
vfc_4634
apps
verifiable_code
1449
Solve the following coding problem using the programming language python: A Little Elephant from the Zoo of Lviv likes lucky strings, i.e., the strings that consist only of the lucky digits 4 and 7. The Little Elephant calls some string T of the length M balanced if there exists at least one integer X (1 ≤ X ≤ M) such...
```python x=eval(input()) for x in range(0,x): ans=0 d=input() a=0 cont=0 for i in range(0,len(d)): a+=len(d)-i if d[i]=='7': ans+=1+cont cont+=1 else: cont=0 ans=a-ans print(ans) ```
{ "language": "python", "test_cases": [ { "input": "4\n47\n74\n477\n4747477\n\n\n", "output": "2\n2\n3\n23\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/COOK22/problems/LUCKYBAL" }
vfc_4638
apps
verifiable_code
1450
Solve the following coding problem using the programming language python: Cheffina challanges chef to rearrange the given array as arr[i] > arr[i+1] < arr[i+2] > arr[i+3].. and so on…, i.e. also arr[i] < arr[i+2] and arr[i+1] < arr[i+3] and arr[i] < arr[i+3] so on.. Chef accepts the challenge, chef starts coding but h...
```python # cook your dish here for _ in range(int(input())): n = int(input()) a = list(map(int,input().split())) a.sort() i=1 while(i<n): a[i-1],a[i] = a[i],a[i-1] i+=2 print(*a) ```
{ "language": "python", "test_cases": [ { "input": "2\n4\n4 1 6 3\n5\n4 5 1 6 3\n", "output": "3 1 6 4\n3 1 5 4 6\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/PBK32020/problems/ITGUY30" }
vfc_4642
apps
verifiable_code
1451
Solve the following coding problem using the programming language python: There is only little time left until the New Year! For that reason, Chef decided to make a present for his best friend. He made a connected and undirected simple graph with N$N$ vertices and M$M$ edges. Since Chef does not like odd numbers and h...
```python # cook your dish here for _ in range(int(input())): N, M = [int(x) for x in input().split()] edges = [0]*M dir = {} nodes = [[] for j in range(N+1)] ind = [0]*(N+1) graph = {} final_edges = [] for i in range(M): u, v = [int(x) for x in input().split()] nodes[u]....
{ "language": "python", "test_cases": [ { "input": "2\n4 4\n1 2\n1 3\n2 4\n3 4\n3 3\n1 2\n2 3\n1 3\n", "output": "0 0 1 1\n-1\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/EDGEDIR" }
vfc_4646
apps
verifiable_code
1452
Solve the following coding problem using the programming language python: Chef has bought N robots to transport cakes for a large community wedding. He has assigned unique indices, from 1 to N, to each of them. How it will happen? Chef arranges the N robots in a row, in the (increasing) order of their indices. Then, h...
```python #read input cases = int(input()) caselist = [] for i in range(0, cases): caselist.append(input()) #iterate each case for j in range(0, cases): #current case's parameters: current_input = caselist[j].split(' ') bots = int(current_input[0]) switch = int(current_input[1]) #generate botlist and cakelist ...
{ "language": "python", "test_cases": [ { "input": "3\n2 0\n2 1\n4 2\n", "output": "No 1\nYes\nNo 2\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/NOV15/problems/EGRCAKE" }
vfc_4650
apps
verifiable_code
1453
Solve the following coding problem using the programming language python: Chef has a sequence $A_1, A_2, \ldots, A_N$; each element of this sequence is either $0$ or $1$. Appy gave him a string $S$ with length $Q$ describing a sequence of queries. There are two types of queries: - '!': right-shift the sequence $A$, i....
```python n, q, k = map(int, input().split()) arr = list(map(int, input().split())) query = list(input()) q_ = len(query) c1 = query.count('?') c = arr.count(0) if c == n: for i in range(c1): print(0) else: for i in range(q_): if (i!=0) and (query[i] == '?' and query[i-1] == '?'): print(max_c) elif query[i] ...
{ "language": "python", "test_cases": [ { "input": "5 5 3\n1 1 0 1 1\n?!?!?\n", "output": "2\n3\n3\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/HMAPPY1" }
vfc_4654
apps
verifiable_code
1454
Solve the following coding problem using the programming language python: It's Christmas time and Santa is in town. There are N children each having a bag with a mission to fill in as many toffees as possible. They are accompanied by a teacher whose ulterior motive is to test their counting skills. The toffees are of ...
```python import numpy as np N=10**6+1 t=eval(input()) inp = () t1=ord('z') #bag=[[0 for _ in xrange(t1)] for _ in xrange(N+1)] bag=np.zeros((N+1,t1),dtype=np.int) #print bag while t: t-=1 inp=input().split() t2=ord(inp[3]) - ord('a') t3=int(inp[1]) t4=int(inp[2]) + 1 if inp[0]=="1": #print "enter" bag[t3]...
{ "language": "python", "test_cases": [ { "input": "5\n1 3 4 a\n1 5 8 a\n1 1 7 x\n2 1 6 a\n2 3 6 y\n", "output": "12\n0\nIn first case, there are two children between 3 and 5 between 0 - 6 having sum (4 + 8)\nThere's no toffee for y in given range\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/SIC2016/problems/SANTA" }
vfc_4658
apps
verifiable_code
1455
Solve the following coding problem using the programming language python: Leha is a usual student at 'The Usual University for Usual Students'. Sometimes he studies hard; at other times he plays truant and gets busy with other things besides academics. He has already studied at the university for N months. For the ith...
```python n=eval(input()) grades=list(map(int,input().split())) m=eval(input()) for df in range(m): x,y=list(map(int,input().split())) arr=[] arr=grades[x-1:y] arr.sort() sum=0 #arr.append(1000000) for nh in range(0,len(arr)-1,1): sum=sum+(arr[nh+1]-arr[nh])**2 #print sum,len(arr),nh+1,nh print(sum) ```
{ "language": "python", "test_cases": [ { "input": "5\n1 3 2 4 5\n5\n1 5\n1 4\n2 4\n3 3\n3 5\n", "output": "4\n3\n2\n0\n5\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/LTIME29/problems/STDPRGS" }
vfc_4662
apps
verifiable_code
1456
Solve the following coding problem using the programming language python: The XOR pair representation (XPR) of a positive integer $N$ is defined as a pair of integers $(A, B)$ such that: - $1 \le A \le B \le N$ - $A \oplus B = N$ - if there is no way to choose $A$ and $B$ satisfying the above conditions, $A = B = -1$ ...
```python import math def GLR(x): summation_N = (x*(x+1))//2 initial = x power = 0 sum_A = 0 while x>=1: count = (x+1)//2 sum_A += count * 2**power x = x - count power += 1 sum_B = summation_N - sum_A ans = sum_B - (int(math.log(initial,2))+1) return ans for _ in range(int(input())): l,r = list(map(i...
{ "language": "python", "test_cases": [ { "input": "5\n1 10\n3 6\n4 10\n10 17\n100 159\n", "output": "28\n9\n28\n79\n7485\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/XORIT" }
vfc_4666
apps
verifiable_code
1457
Solve the following coding problem using the programming language python: The purpose of this problem is to verify whether the method you are using to read input data is sufficiently fast to handle problems branded with the enormous Input/Output warning. You are expected to be able to process at least 2.5MB of input d...
```python #Note that it's python3 Code. Here, we are using input() instead of raw_input(). #You can check on your local machine the version of python by typing "python --version" in the terminal. (n, k) = list(map(int, input().split(' '))) ans = 0 for i in range(n): x = int(input()) if x % k == 0: ans += 1 prin...
{ "language": "python", "test_cases": [ { "input": "7 3\n1\n51\n966369\n7\n9\n999996\n11\n", "output": "4\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/INTEST" }
vfc_4670
apps
verifiable_code
1458
Solve the following coding problem using the programming language python: Chef has recently been playing a lot of chess in preparation for the ICCT (International Chef Chess Tournament). Since putting in long hours is not an easy task, Chef's mind wanders elsewhere. He starts counting the number of squares with odd si...
```python # cook your dish here t=int(input()) for i in range(t): a=0 n=int(input()) while(n>0): a += n*n n=n-2 print(a) ```
{ "language": "python", "test_cases": [ { "input": "2\n3\n8\n", "output": "10\n120\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/PCJ18B" }
vfc_4674
apps
verifiable_code
1459
Solve the following coding problem using the programming language python: Today, Chef has a fencing job at hand and has to fence up a surface covering N$N$ points. To minimize his work, he started looking for an algorithm that had him fence the least amount of length. He came up with the Convex Hull algorithm, but s...
```python import math n,m = map(int, input().split()) hyp = math.sqrt(1+m*m) cosx = 1/hyp sinx = m/hyp pts = [[], []] for i in range(n): p = input().split() px = int(p[0]) py = int(p[1]) pts[0].append(cosx*px+sinx*py) pts[1].append(cosx*py-sinx*px) w = max(pts[0])-min(pts[0]) l = max(pts[1])-min...
{ "language": "python", "test_cases": [ { "input": "4 1\n 0 1\n 0 -1\n 1 0\n -1 0\n\n", "output": "5.656854249492380\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/PCJ18F" }
vfc_4678
apps
verifiable_code
1460
Solve the following coding problem using the programming language python: Mia is working as a waitress at a breakfast diner. She can take up only one shift from 6 shifts a day i.e. from 10 am to 4 pm. She needs to save 300$ after completion of the month. She works only for $D$ days in the month. She estimates that she...
```python # cook your dish here l=[int(k) for k in input().split()] s=[int(k) for k in input().split()] x=l[1]*l[0] for i in range(l[0]): if(s[i]==1): x+=l[2] elif(s[i]==2): x+=(l[2]*98/100) elif(s[i]==3): x+=(l[2]*96/100) elif(s[i]==4): x+=(l[2]*94/100) elif(s[i]==5...
{ "language": "python", "test_cases": [ { "input": "9 17 5\n1 3 2 4 5 6 1 2 2\n", "output": "NO\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/TAWY2020/problems/TAWY002" }
vfc_4682
apps
verifiable_code
1461
Solve the following coding problem using the programming language python: Consider the fraction, $a/b$, where $a$ and $b$ are positive integers. If $a < b$ and $GCD(a,b) = 1$, it is called a reduced proper fraction. If we list the set of a reduced proper fraction for $d \leq 8$, (where $d$ is the denominator) in ascen...
```python from sys import stdin from fractions import Fraction input = stdin.readline for _ in range(int(input())): a, b, n = list(map(int, input().split())) ab = Fraction(a, b) p = set() for i in range(1, n+1): for j in range(n, 0, -1): x = Fraction(i, j) if x > ab:...
{ "language": "python", "test_cases": [ { "input": "5\n3 7 8\n3 5 8\n4 5 8\n6 7 8\n1 5 8\n", "output": "2 5\n4 7\n3 4\n5 6\n1 6\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/QTST2020/problems/NEGBFRAC" }
vfc_4686
apps
verifiable_code
1462
Solve the following coding problem using the programming language python: The name of our college is "Government College of Engineering and Textile Technology Berhampore". There is another college named "Government College of Engineering and Textile Technology Serampore". As the names are quite similar, those who are ...
```python # cook your dish here try: t=int(input()) for i in range(t): n=input() n=n.lower() a="berhampore" b="serampore" if a in n: if b in n: print("Both") else: print("GCETTB") elif b in n: i...
{ "language": "python", "test_cases": [ { "input": "3\nGovernment clg Berhampore\nSeRaMporE textile college\nGirls college Kolkata\n", "output": "GCETTB\nGCETTS\nOthers\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/COMT2020/problems/BHPORSRP" }
vfc_4690
apps
verifiable_code
1463
Solve the following coding problem using the programming language python: Chef has a recipe book. He wishes to read it completely as soon as possible so that he could try to cook the dishes mentioned in the book. The pages of the book are numbered $1$ through $N$. Over a series of days, Chef wants to read each page. O...
```python def ugcd(n): ans = [[1]] if(n==1): return ans elif(n%2==1): ans = [[1, 2, n]] else: ans = [[1, 2]] for k in range(1, int(n//2)): ans.append([k*2+1, k*2+2]) return ans t = int(input()) for i in range(t): n = int(input()) s = (ugcd(n)) print(len(s)) for j in r...
{ "language": "python", "test_cases": [ { "input": "1\n5\n\n", "output": "2\n3 1 2 5\n2 3 4\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/UNITGCD" }
vfc_4694
apps
verifiable_code
1464
Solve the following coding problem using the programming language python: You visit a doctor on a date given in the format $yyyy:mm:dd$. Your doctor suggests you to take pills every alternate day starting from that day. You being a forgetful person are pretty sure won’t be able to remember the last day you took the me...
```python t=int(input()) li1=[31,29,31,30,31,30,31,31,30,31,30,31] li2=[31,28,31,30,31,30,31,31,30,31,30,31] for z in range(t): y,m,d=list(map(int,input().split(':'))) if y%4 == 0: if y%100 == 0: if y%400 == 0: li=li1 else: li=li2 else: li=li1 else: li=li2 c=0 if d%2 == 0: while d%2 == 0: ...
{ "language": "python", "test_cases": [ { "input": "1\n2019:03:31\n", "output": "1\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/MEDIC" }
vfc_4698
apps
verifiable_code
1465
Solve the following coding problem using the programming language python: You are given a tree consisting of n nodes numbered from 1 to n. The weights of edges of the tree can be any binary integer satisfying following Q conditions. - Each condition is of form u, v, x where u, v are nodes of the tree and x is a bi...
```python import sys def powc(x,n,m): res = 1 xx=x while n: if n&1: res = (res*xx)%m xx=xx*xx%m n >>= 1 return res def circles(u): r = 0 S = [(u,-1,0)] Visited[u] = 0 for s in S: for e in V[s[0]]: if e[0] != s[1]: if Visited[e[0]]==-1: Visited[e[0]] = s[2...
{ "language": "python", "test_cases": [ { "input": "3\n3 2\n1 2\n1 3\n1 2 0\n1 3 0\n3 0\n1 2\n2 3\n3 1\n1 2\n2 3\n1 2 1\n", "output": "1\n4\n2\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/MARCH16/problems/PARITREE" }
vfc_4702
apps
verifiable_code
1466
Solve the following coding problem using the programming language python: Vietnamese and Bengali as well. An $N$-bonacci sequence is an infinite sequence $F_1, F_2, \ldots$ such that for each integer $i > N$, $F_i$ is calculated as $f(F_{i-1}, F_{i-2}, \ldots, F_{i-N})$, where $f$ is some function. A XOR $N$-bonacci s...
```python # cook your dish here n,q=map(int,input().split()) ls=[int(i) for i in input().split()] cur=0 s=[0] for i in ls: cur=cur^i s.append(cur) for i in range(q): k=int(input()) print(s[k%(n+1)]) ```
{ "language": "python", "test_cases": [ { "input": "3 4\n0 1 2\n7\n2\n5\n1000000000\n", "output": "3\n1\n0\n0\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/NBONACCI" }
vfc_4706
apps
verifiable_code
1467
Solve the following coding problem using the programming language python: Alice and Johnny are playing a simple guessing game. Johnny picks an arbitrary positive integer n (1<=n<=109) and gives Alice exactly k hints about the value of n. It is Alice's task to guess n, based on the received hints. Alice often has a s...
```python # cook your dish here def guessingGame (l): a = [] m = 1000000001 for i in range (len(l)): k=int(l[i][1]) if (l[i][0]=='<' and l[i][2]=='Yes'): a.append((1,1)) a.append((k,-1)) if (l[i][0]=='<' and l[i][2]=='No'): a.append((k,1)) a.append((m,-1)) if (l[i][0]=='=' and l[i][2]=='Y...
{ "language": "python", "test_cases": [ { "input": "3\n2\n< 100 No\n> 100 No\n3\n< 2 Yes\n> 4 Yes\n= 3 No\n6\n< 2 Yes\n> 1 Yes\n= 1 Yes\n= 1 Yes\n> 1 Yes\n= 1 Yes\n", "output": "0\n1\n2\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/A3" }
vfc_4710
apps
verifiable_code
1468
Solve the following coding problem using the programming language python: Ms. E.T. came from planet Hex. She has 8 fingers in each hand which makes her count in hexadecimal way. When she meets you, she tells you that she came from 7E light years from the planet Earth. You see she means that it is 126 light years far a...
```python # cook your dish here try: t=int(input()) for i in range(t): s=input() i=int(s,16) print(i) except EOFError as e: print(e) ```
{ "language": "python", "test_cases": [ { "input": "3\nA\n1A23\n2C2A\n", "output": "10\n6691\n11306\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/JLUG2020/problems/HXTDC" }
vfc_4714
apps
verifiable_code
1469
Solve the following coding problem using the programming language python: The chef is trying to decode 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 cas...
```python try: tc=int(input()) for _ in range(tc): n=int(input()) st="" b=1 for i in range(1,n+1): b+=1 a=b for j in range(1,n+1): print(a,end='') a+=1 print() except: pass `...
{ "language": "python", "test_cases": [ { "input": "4\n1\n2\n3\n4\n", "output": "2\n23\n34\n234\n345\n456\n2345\n3456\n4567\n5678\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/PTRN2021/problems/ITGUY53" }
vfc_4718
apps
verifiable_code
1470
Solve the following coding problem using the programming language python: Ahmed Gafer failed to pass the test, but he got the job because of his friendship with Said and Shahhoud. After working in the kitchen for a while, he blew it. The customers didn't like the food anymore and one day he even burned the kitchen. No...
```python # cook your dish here for _ in range(int(input())): s=input() count=0 i=0 while i<len(s)-1: ch=s[i] j=i+1 while j<len(s) and s[j]==ch: j+=1 l=j-i if i!=0 and j!=len(s) and s[i-1]==s[j] : count+=1 count+=l*(l-1)//2 #print(s[i:j],count) i=j print(count) ```
{ "language": "python", "test_cases": [ { "input": "2\na\nabba\n", "output": "0\n2\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/CK87GSUB" }
vfc_4722
apps
verifiable_code
1472
Solve the following coding problem using the programming language python: $Neha$ is given a number $N$. She always looks for special thing , this time she is looking for $Special$ $Number$ and $Partial$ $Special$ $Number$. A $Special$ $Number$ is a number whose product of its digits is equal to number itself i.e. $N ...
```python n=int(input()) a=[] b=[] for i in range(1,1000001): s = str(i) p=1 flag=0 for e in s: if e=='1': flag=1 p=p*int(e) if p==n: if flag!=1: a.append(i) else: b.append(i) print(len(a),len(b)) ```
{ "language": "python", "test_cases": [ { "input": "3\n", "output": "1 20\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/CZEN2020/problems/NHSPN" }
vfc_4730
apps
verifiable_code
1473
Solve the following coding problem using the programming language python: Many things in this first paragraph are references to some pretty famous YouTube stars, so be careful about rephrasing. Thanks! Michael, Kevin and Jake are sharing a cake, in celebration of their Webby award. They named it VCake. Unlike other c...
```python #!/usr/bin/python import sys def __starting_point(): t = int(input()) for iteration in range(t): r,c,m_inp,k_inp,j_inp = input().strip().split(" ") r=int(r) c=int(c) m_inp=int(m_inp) k_inp=int(k_inp) j_inp=int(j_inp) ans = "" if (r*c) != (m_inp+k_inp+j_inp): print("No") continue el...
{ "language": "python", "test_cases": [ { "input": "4\n4 5 10 4 6\n4 5 6 10 4\n4 5 4 6 10\n2 2 2 2 2\n", "output": "Yes\nYes\nYes\nNo\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/SNCKEL16/problems/VCAKE" }
vfc_4734
apps
verifiable_code
1474
Solve the following coding problem using the programming language python: Stuart is obsessed to numbers. He like all type of numbers in fact he is having a great collection of numbers in his room. His collection includes N different large numbers. But today he is searching for a number which is having maximum frequenc...
```python T = int(input()) def call_me(N,A,X): max = 0 ans = '' for i in A: if i.count(X) > max: max = i.count(X) ans = i return ans for i in range(T): N = int(input()) A = list(map(str,input().split())) X = input() print(call_me(N,A,X)) ```
{ "language": "python", "test_cases": [ { "input": "2\n5\n345 1323 165 98 456\n3\n5\n335 876 98 1323 349\n3\n", "output": "1323\n335\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/CFSN2015/problems/LINNUM" }
vfc_4738
apps
verifiable_code
1475
Solve the following coding problem using the programming language python: Abhiram needs to search for an antidote. He comes to know that clue for finding the antidote is carefully hidden by KrishnaMurthy in the form of a puzzle. The puzzle consists of a string S and a keywordK. Abhiram needs to find the string of pos...
```python x = input().split(" ") y = input() ans = '' l = 1 for i in x: if i!=y and sorted(i) == sorted(y): ans = ans + (str)(l) l=l+1 ans+='.' print("The antidote is found in",ans) ```
{ "language": "python", "test_cases": [ { "input": "cat is the act of tac\ncat\n", "output": "The antidote is found in 46.\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/ITRA2016/problems/ITRA10" }
vfc_4742
apps
verifiable_code
1476
Solve the following coding problem using the programming language python: Chef has decided to retire and settle near a peaceful beach. He had always been interested in literature & linguistics. Now when he has leisure time, he plans to read a lot of novels and understand structure of languages. Today he has decided to...
```python # cook your dish here from collections import Counter from math import factorial for _ in range(int(input())): s=input() c=Counter(s) k=factorial(len(s)) for value in c.values(): if value>1: k=k//factorial(value) print(k%(10**9+7)) ```
{ "language": "python", "test_cases": [ { "input": "4\nab\naa\naA\nAAbaz\n", "output": "2\n1\n2\n60\nDescription:\nIn first case \"ab\" & \"ba\" are two different words. In third case, note that A & a are different alphabets and hence \"Aa\" & \"aA\" are different words.\n", "type": "stdin_std...
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/WCOUNT" }
vfc_4746
apps
verifiable_code
1477
Solve the following coding problem using the programming language python: You have a string S consisting of N uppercase English letters. You are allowed to perform at most one operation of following kind: Choose any position in the string, remove the character at that position and insert it back to any other place in ...
```python for _1 in range(int(input())): n=int(input()) s=input().strip() answer=s for i in range(len(s)): c=s[i] string=s[:i]+s[i+1:] for j in range(len(string)+1): answer=min(answer, string[:j]+c+string[j:]) print(answer) ```
{ "language": "python", "test_cases": [ { "input": "2\n4\nDCBA\n7\nXYZZYZZ\n", "output": "ADCB\nXYYZZZZ\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/DIVGOLD" }
vfc_4750
apps
verifiable_code
1478
Solve the following coding problem using the programming language python: Let's define a periodic infinite sequence S$S$ (0$0$-indexed) with period K$K$ using the formula Si=(i%K)+1$S_i = (i \% K) + 1$. Chef has found a sequence of positive integers A$A$ with length N$N$ buried underground. He suspects that it is a co...
```python # cook your dish here from math import gcd for _ in range(int(input())): n,a,k,min_k,e = int(input()),[int(i) for i in input().split()],0,0,-1 for j in range(n): if(a[j] != -1):break for i in range(j,n): if min_k==0:min_k,e = a[i],a[i]+1 else: if min_k < a[i]:m...
{ "language": "python", "test_cases": [ { "input": "3\n3\n-1 -1 -1\n5\n1 -1 -1 4 1\n4\n4 6 7 -1\n", "output": "inf\n4\nimpossible\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/PERIODIC" }
vfc_4754
apps
verifiable_code
1479
Solve the following coding problem using the programming language python: You are participating in a contest which has $11$ problems (numbered $1$ through $11$). The first eight problems (i.e. problems $1, 2, \ldots, 8$) are scorable, while the last three problems ($9$, $10$ and $11$) are non-scorable ― this means tha...
```python # cook your dish here p=int(input()) for z in range(p): n=int(input()) a=[] for i in range(8): a.append(0) for i in range(n): x,y=list(map(int,input().split())) if x<=8 and y>a[x-1]: a[x-1]=y print(sum(a)) ```
{ "language": "python", "test_cases": [ { "input": "2\n5\n2 45\n9 100\n8 0\n2 15\n8 90\n1\n11 1\n", "output": "135\n0\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/WATSCORE" }
vfc_4758
apps
verifiable_code
1480
Solve the following coding problem using the programming language python: There are n cabs in a city numbered from 1 to n. The city has a rule that only one cab can run in the city at a time. Cab picks up the customer and drops him to his destination. Then the cab gets ready to pick next customer. There are m customer...
```python import math def dist(w,x,y,z): return math.hypot(y - w, z - x) t = int(input()) while (t>0): t = t -1 n, m = list(map(int,input().split())) a = [] for i in range(0,n): x,y = list(map(int,input().split())) a.append([x,y]) for j in range(0,m): p,q,r,s = list(map(int,input().split())) nearest = -1...
{ "language": "python", "test_cases": [ { "input": "1\n3 2\n1 3\n3 2\n3 5\n2 3 3 4\n5 3 4 1\n", "output": "1\n1\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/SIC2016/problems/NEAR" }
vfc_4762
apps
verifiable_code
1482
Solve the following coding problem using the programming language python: Chef's company wants to make ATM PINs for its users, so that they could use the PINs for withdrawing their hard-earned money. One of these users is Reziba, who lives in an area where a lot of robberies take place when people try to withdraw thei...
```python for i in range(int(input())): n = int(input()) q = "1"+"0"*(n//2) print(1,q) ```
{ "language": "python", "test_cases": [ { "input": "1\n1\n", "output": "1 1\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/PINS" }
vfc_4770
apps
verifiable_code
1483
Solve the following coding problem using the programming language python: As we all know caterpillars love to eat leaves. Usually, a caterpillar sits on leaf, eats as much of it as it can (or wants), then stretches out to its full length to reach a new leaf with its front end, and finally "hops" to it by contracting i...
```python from math import gcd n, k = list(map(int, input().split())) a = [] for i in range(k): try: a += list(map(int, input().split())) except: pass ans = n for i in range(1, 2**k): b = bin(i)[2:].rjust(k, "0") c = [] for j in range(k): if(b[j] == '1'): ...
{ "language": "python", "test_cases": [ { "input": "20 3\n3\n2\n5\n", "output": "6\nHint:\nYou may use 64 -bit integers ( long long in C/C++) to avoid errors while multiplying large integers. The maximum value you can store in a 32 -bit integer is 2 31 − 1 , which is approximately 2 ⋅ 10 9 . 6...
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/IARCSJUD/problems/LEAFEAT" }
vfc_4774