source stringclasses 4
values | task_type stringclasses 1
value | in_source_id stringlengths 0 138 | problem_statement stringlengths 219 13.2k | gold_standard_solution stringlengths 0 413k | problem_id stringlengths 5 10 | metadata dict | verification_info dict |
|---|---|---|---|---|---|---|---|
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))
``` | vfc_4386 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/ANUTHM",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n2 2\n1 6\n",
"output": "3.000000\n6.000000\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 1387 | Solve the following coding problem using the programming language python:
-----Problem Statement-----
Chef studies combinatorics. He tries to group objects by their rang (a positive integer associated with each object). He also gives the formula for calculating the number of different objects with rang N as following:... | ```python
# cook your dish here
import sys
mod_val = 1000000007
rang = [0]*101
pow_cache = [0]*102
multisets = {}
def mod_pow(base, pow):
result = 1
while pow:
if pow&1:
result = (result*base) % mod_val
base = (base*base) % mod_val
pow = pow>>1
return result
def precalculate():
for i in range(1, 102)... | vfc_4390 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/GERALD05",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1 0 0 0\n1\n1 0 0 0\n3\n0 1 0 0\n2\n2 3 1 4\n10\n",
"output": "1\n3\n3\n213986343\n",
"type": "stdin_stdout"
}
]
} |
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... | vfc_4394 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/SLAB",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n600000\n250000\n",
"output": "577500\n250000\n",
"type": "stdin_stdout"
}
]
} |
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
... | vfc_4398 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/IARCSJUD/problems/IAREVERS",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"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 Th... |
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))
``` | vfc_4402 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/RANDID",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n2 2\n",
"output": "3.3333333333\n",
"type": "stdin_stdout"
}
]
} |
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... | vfc_4406 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/FGFS",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"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"
}
]
} |
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)
``` | vfc_4410 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/SPTC2020/problems/CPCEJC4",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6 70\n",
"output": "76\n",
"type": "stdin_stdout"
}
]
} |
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)
``` | vfc_4414 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/CARVANS",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"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 (... |
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/... | vfc_4418 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/PCJ18G",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n4\n10000000000\n",
"output": "23\n227374950\n",
"type": "stdin_stdout"
}
]
} |
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)
``` | vfc_4422 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/EXAMCHT",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n2 6\n",
"output": "3\n",
"type": "stdin_stdout"
}
]
} |
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")... | vfc_4426 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/CHEFADV",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"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"
}
]
} |
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... | vfc_4430 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/RC122020/problems/RECNDROT",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n2\n2 1\n2\n1 2\n5\n1 3 2 1 2\n",
"output": "2\n1\n2\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 1398 | Solve the following coding problem using the programming language python:
You have initially a string of N characters, denoted by A1,A2...AN. You have to print the size of the largest subsequence of string A such that all the characters in that subsequence are distinct ie. no two characters in that subsequence should ... | ```python
def solve(S):
a = set(S)
return len(a)
t = int(input())
for _ in range(t):
s = input()
print(solve(s))
``` | vfc_4434 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/DISCHAR",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\nabc\naba\n",
"output": "3\n2\n",
"type": "stdin_stdout"
}
]
} |
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, ... | vfc_4438 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/HXR",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n3 2\n1 2 3\n1 2\n2 3\n1 3\n",
"output": "3 1 0\n",
"type": "stdin_stdout"
}
]
} |
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))
``` | vfc_4442 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/ENNO2020/problems/ENCNOV",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n4 2 2\n5 1 5\n",
"output": "5 7\n5 31\n",
"type": "stdin_stdout"
}
]
} |
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)
``` | vfc_4446 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/COM12020/problems/CODE_01",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7 50\n1 12 5 111 200 1000 10\n",
"output": "4\n",
"type": "stdin_stdout"
}
]
} |
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)))
``` | vfc_4450 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/BINADD",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n100010\n0\n0\n100010\n11100\n1010\n",
"output": "0\n1\n3\n",
"type": "stdin_stdout"
}
]
} |
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... | vfc_4454 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/CEFT2020/problems/INTER",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n12\n226\n",
"output": "2\n3\n",
"type": "stdin_stdout"
}
]
} |
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... | vfc_4458 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/APRIL16/problems/CHBLLNS",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n3 3 3\n1\n3 3 3\n2\n",
"output": "1\n4\n",
"type": "stdin_stdout"
}
]
} |
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... | vfc_4462 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/RC152020/problems/REC15B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n6\n",
"output": "0\n",
"type": "stdin_stdout"
}
]
} |
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(... | vfc_4466 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/ENGXOR",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n6 1\n4 2 15 9 8 8\n3\n",
"output": "2 4\n",
"type": "stdin_stdout"
}
]
} |
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... | vfc_4470 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/DIFNEIGH",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n1 1\n2 3\n",
"output": "1\n1\n3\n1 1 2\n2 3 3\n",
"type": "stdin_stdout"
}
]
} |
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 ... | vfc_4474 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/CHEFTWOS",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n1111\n2211\n222\n111\n",
"output": "8\n0\n",
"type": "stdin_stdout"
}
]
} |
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"))
``` | vfc_4478 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/PBK22020/problems/ITGUY25",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n2\n5\n",
"output": "1\n2\n",
"type": "stdin_stdout"
}
]
} |
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... | vfc_4482 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/FTRIP",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"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"
}
]
} |
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... | vfc_4486 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/SMTC2020/problems/RROUNDS",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n3 10 2 5\n2 20 5 10\n",
"output": "1\n0\n",
"type": "stdin_stdout"
}
]
} |
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]] ... | vfc_4490 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/FORGETPW",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"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"
}
]
} |
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... | vfc_4494 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/ROLLBAR",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"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"
}
]
} |
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... | vfc_4498 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/CDVA16/problems/CDVA1605",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 3 3\nMMF\nMMM\nFFM\nFFM\n2 F\n3 M\n1 M\n",
"output": "yes\nno\nyes\n",
"type": "stdin_stdout"
}
]
} |
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")
``` | vfc_4502 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/PRPALN",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\naaa\nabc\nabdbca\nabba\n",
"output": "YES\nNO\nYES\nYES\n",
"type": "stdin_stdout"
}
]
} |
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 ... | vfc_4506 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/SOPC2015/problems/SOPC1504",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7\n1 2 3 4 5 6 7\n",
"output": "1 2 4 7\n3 5 6\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 1417 | Solve the following coding problem using the programming language python:
Raj loves to listen to songs in his free time. It’s his birthday tomorrow and his friend Neelansh wants his gift to be the most unique. Being great at making music, he decides to produce a song for him. However, Raj likes songs according to thei... | ```python
for _ in range(int(input())):
n = int(input())
ar = list(map(int,input().split()))
d = {}
for ele in ar:
if ele in d:
d[ele] += 1
else:
d[ele] = 1
m = 99999
count = 0
for ele in d:
count+=1
if m>d[ele]:
... | vfc_4510 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/CSPR2020/problems/OCTAVE",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n8\n1 2 3 4 5 6 7 8\n16\n1 2 1 2 3 3 4 4 5 5 6 6 7 8 7 8\n",
"output": "1\n2\n",
"type": "stdin_stdout"
}
]
} |
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])
``` | vfc_4514 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/SFRV",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n4\n2 1 4 3\n4\n7 6 3 2\n",
"output": "30\n39\n",
"type": "stdin_stdout"
}
]
} |
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 + ... | vfc_4518 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/DIGITSEP",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n3\n474\n2 1 1\n34\n6311861109697810998905373107116111\n10 4 25\n",
"output": "2\n1\n",
"type": "stdin_stdout"
}
]
} |
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)... | vfc_4522 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/ZCOPRAC/problems/ZCO20002",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"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"
}
]
} |
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 ... | vfc_4526 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/CCOD2020/problems/PALL9",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n1\n2\n",
"output": "9\n99\n",
"type": "stdin_stdout"
}
]
} |
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)
``` | vfc_4530 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/AUG12/problems/LEBOMBS",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n3\n010\n5\n10001\n7\n0000000\n",
"output": "0\n1\n7\n",
"type": "stdin_stdout"
}
]
} |
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)
``` | vfc_4534 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/JOHNY",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"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"
}
]
} |
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)
``` | vfc_4538 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/COTH2020/problems/SUBALGO",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1001 2\nSample Input 2\n5 2\n",
"output": "100\nSample Output 2\n3\n",
"type": "stdin_stdout"
}
]
} |
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])
``` | vfc_4542 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/FENWITER",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"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"
}
]
} |
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 ... | vfc_4546 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/SLUSH",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"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"
}
]
} |
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... | vfc_4550 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/PPCTS",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 3\n1 2\n0 1\nRDL\n",
"output": "4\n6\n6\n",
"type": "stdin_stdout"
}
]
} |
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+... | vfc_4554 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/PEWDSVTS",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"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"
}
]
} |
apps | verifiable_code | 1429 | Solve the following coding problem using the programming language python:
Monisha likes to paint. She has painted $N$ paintings (numbered $1$ through $N$) and wants to choose some subset of these paintings for an exhibition. For each valid $i$, the $i$-th painting has beauty $b_i$ and the probability that it will be d... | ```python
# cook your dish here
t=int(input())
while(t>0):
n=int(input())
b=[int(x) for x in input().split()]
p=[float(x) for x in input().split()]
s=[0]*(10)
yet=2
mx=0
for i in range(n):
st=bin(b[i])
rng=len(st)-2
if(rng+2>yet):
for ml in range(rng+2-yet):
s.append(0)
if(rng>mx):
mx=rng
for... | vfc_4558 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/EXPXOR",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n3\n5 6 2\n1.0 0.0 0.5\n4\n2 2 2 2\n0.5 0.5 0.5 0.5\n",
"output": "6.000000000000000\n1.000000000000000\n",
"type": "stdin_stdout"
}
]
} |
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)
``` | vfc_4562 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/AGPR2020/problems/ALPR2000",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n2 1\n",
"output": "3\n",
"type": "stdin_stdout"
}
]
} |
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 ... | vfc_4566 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/COW42020/problems/COW3F",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n5\n2\n",
"output": "200000002\n0\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 1432 | Solve the following coding problem using the programming language python:
Bandwidth of a matrix A is defined as the smallest non-negative integer K such that A(i, j) = 0 for |i - j| > K.
For example, a matrix with all zeros will have its bandwith equal to zero. Similarly bandwith of diagonal matrix will also be zero.
... | ```python
t = int(input())
for i in range(t):
n = int(input())
A = []
for i in range(0, n):
A.append([int(i) for i in input().split()])
ones = sum([sum(i) for i in A])
compare = n
ans = 0
for i in range(0, n):
if ones <= compare:
ans = i
br... | vfc_4570 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/BANDMATR",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n2\n0 0\n0 0\n2\n1 0\n0 1\n2\n1 0\n1 0\n2\n1 0\n1 1\n3\n1 0 0\n0 1 1\n1 1 0\n4\n1 1 1 1\n1 1 1 1\n1 1 1 1\n1 1 1 1\n\n\n",
"output": "0\n0\n0\n1\n1\n3\n",
"type": "stdin_stdout"
}
]
} |
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 ... | vfc_4574 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/OCT12/problems/LUCKY10",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n4\n7\n435\n479\n7\n8\n1675475\n9756417\n\n\n",
"output": "7\n74\n\n777744\n",
"type": "stdin_stdout"
}
]
} |
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] ... | vfc_4578 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/DEMTREE",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"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"
}
]
} |
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]... | vfc_4582 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/IARCSJUD/problems/EXPT",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"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"
}
]
} |
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)
``` | vfc_4586 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/HHAL",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\nabbabaab\n\n\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} |
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 = ... | vfc_4590 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/BRBG2020/problems/FTNUM",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n2\n2 3\n2\n4 2\n3\n12 3 2\n",
"output": "6\n8\n-1\n",
"type": "stdin_stdout"
}
]
} |
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... | vfc_4594 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/PRMDIV",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n5\n2 30 2 4 3\n",
"output": "6\n",
"type": "stdin_stdout"
}
]
} |
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... | vfc_4598 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/CHEFYODA",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n2 3 2 3\n2 2 5 5\n",
"output": "0.500000\n1.000000\n",
"type": "stdin_stdout"
}
]
} |
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))
``` | vfc_4602 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/EXUNA",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n2\n7 12\n",
"output": "7\n",
"type": "stdin_stdout"
}
]
} |
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... | vfc_4606 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/CLGAME",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n3 2\n5 7 1\n1 2\n",
"output": "Chef\n",
"type": "stdin_stdout"
}
]
} |
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)
``` | vfc_4610 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/ECPG2020/problems/ECPC10C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n2\n",
"output": "3\n",
"type": "stdin_stdout"
}
]
} |
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)
``` | vfc_4614 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/LCOLLIS",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n4 3\n111\n100\n110\n000\n2 2\n10\n01\n",
"output": "4\n0\n",
"type": "stdin_stdout"
}
]
} |
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]
... | vfc_4618 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/CHEFSOC",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"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"
}
]
} |
apps | verifiable_code | 1445 | Solve the following coding problem using the programming language python:
There are N islands in the sea, enumerated from 1 to N. Each of them is so small that we can consider them as points on a plane. You are given the Cartesian coordinates of all islands. X-axis is directed towards East and Y-axis is directed towar... | ```python
t= int(input())
for _ in range(t):
n = int(input())
ar = []
y = []
for i in range(n):
ar.append( list(map(int,input().split())) )
y.append(ar[-1][1])
ar[-1].append(i)
y.sort()
mny = y[0]
mxy = y[-1]
ar.sort()
ssx,ssy,ssi = ar[0]
bbx,bby,bbi = ar[-1]
sbx,sby,sbi = ar[0]
bsx,bsy,bsi = ar[-... | vfc_4622 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/LIGHTHSE",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n5\n0 0\n1 0\n2 0\n0 -1\n0 -2\n4\n5 0\n-5 0\n0 5\n0 -5\n",
"output": "1\n3 SW\n2\n4 NE\n2 NE\n",
"type": "stdin_stdout"
}
]
} |
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... | vfc_4626 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/XORNUBER",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n3\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} |
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:
... | vfc_4630 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/CHEFRECP",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"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"
}
]
} |
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)
``` | vfc_4634 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/CFUS2020/problems/CFS2001",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n1 4 3 8 2\n",
"output": "43\n",
"type": "stdin_stdout"
}
]
} |
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)
``` | vfc_4638 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/COOK22/problems/LUCKYBAL",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n47\n74\n477\n4747477\n\n\n",
"output": "2\n2\n3\n23\n",
"type": "stdin_stdout"
}
]
} |
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)
``` | vfc_4642 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/PBK32020/problems/ITGUY30",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"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"
}
]
} |
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].... | vfc_4646 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/EDGEDIR",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"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"
}
]
} |
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
... | vfc_4650 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/NOV15/problems/EGRCAKE",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n2 0\n2 1\n4 2\n",
"output": "No 1\nYes\nNo 2\n",
"type": "stdin_stdout"
}
]
} |
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] ... | vfc_4654 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/HMAPPY1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 5 3\n1 1 0 1 1\n?!?!?\n",
"output": "2\n3\n3\n",
"type": "stdin_stdout"
}
]
} |
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]... | vfc_4658 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/SIC2016/problems/SANTA",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"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_std... |
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)
``` | vfc_4662 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/LTIME29/problems/STDPRGS",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"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"
}
]
} |
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... | vfc_4666 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/XORIT",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1 10\n3 6\n4 10\n10 17\n100 159\n",
"output": "28\n9\n28\n79\n7485\n",
"type": "stdin_stdout"
}
]
} |
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... | vfc_4670 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/INTEST",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7 3\n1\n51\n966369\n7\n9\n999996\n11\n",
"output": "4\n",
"type": "stdin_stdout"
}
]
} |
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)
``` | vfc_4674 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/PCJ18B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n3\n8\n",
"output": "10\n120\n",
"type": "stdin_stdout"
}
]
} |
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... | vfc_4678 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/PCJ18F",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 1\n 0 1\n 0 -1\n 1 0\n -1 0\n\n",
"output": "5.656854249492380\n",
"type": "stdin_stdout"
}
]
} |
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... | vfc_4682 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/TAWY2020/problems/TAWY002",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "9 17 5\n1 3 2 4 5 6 1 2 2\n",
"output": "NO\n",
"type": "stdin_stdout"
}
]
} |
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:... | vfc_4686 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/QTST2020/problems/NEGBFRAC",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"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"
}
]
} |
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... | vfc_4690 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/COMT2020/problems/BHPORSRP",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\nGovernment clg Berhampore\nSeRaMporE textile college\nGirls college Kolkata\n",
"output": "GCETTB\nGCETTS\nOthers\n",
"type": "stdin_stdout"
}
]
} |
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... | vfc_4694 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/UNITGCD",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n5\n\n",
"output": "2\n3 1 2 5\n2 3 4\n",
"type": "stdin_stdout"
}
]
} |
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:
... | vfc_4698 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/MEDIC",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n2019:03:31\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} |
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... | vfc_4702 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/MARCH16/problems/PARITREE",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"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"
}
]
} |
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)])
``` | vfc_4706 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/NBONACCI",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 4\n0 1 2\n7\n2\n5\n1000000000\n",
"output": "3\n1\n0\n0\n",
"type": "stdin_stdout"
}
]
} |
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... | vfc_4710 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/A3",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"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"
}
]
} |
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)
``` | vfc_4714 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/JLUG2020/problems/HXTDC",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\nA\n1A23\n2C2A\n",
"output": "10\n6691\n11306\n",
"type": "stdin_stdout"
}
]
} |
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
`... | vfc_4718 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/PTRN2021/problems/ITGUY53",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1\n2\n3\n4\n",
"output": "2\n23\n34\n234\n345\n456\n2345\n3456\n4567\n5678\n",
"type": "stdin_stdout"
}
]
} |
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)
``` | vfc_4722 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/CK87GSUB",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\na\nabba\n",
"output": "0\n2\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 1471 | Solve the following coding problem using the programming language python:
In Chefland, there is a monthly robots competition. In the competition, a grid table of N rows and M columns will be used to place robots. A cell at row i and column j in the table is called cell (i, j). To join this competition, each player wil... | ```python
import sys
def spaces(a,n,m,k,visit1,visit2,dist,position):
queue = [position]
lastedit = []
dist[position[0]][position[1]] = 0
while queue!=[]:
point = queue[0]
i = point[0]
j = point[1]
#print 'point',i,j
if visit1[i][j]==False:
visit1[i][j] = True
startx = max(i-k,0)
endx = min(i+k... | vfc_4726 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/JULY16/problems/CHEFARC",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n4 4 1 1\n0 1 1 0\n0 1 1 0\n0 1 1 0\n0 0 0 0\n4 4 1 1\n0 1 1 0\n0 1 1 0\n0 1 1 0\n1 0 0 1\n",
"output": "5\n-1\n",
"type": "stdin_stdout"
}
]
} |
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))
``` | vfc_4730 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/CZEN2020/problems/NHSPN",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n",
"output": "1 20\n",
"type": "stdin_stdout"
}
]
} |
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... | vfc_4734 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/SNCKEL16/problems/VCAKE",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"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"
}
]
} |
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))
``` | vfc_4738 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/CFSN2015/problems/LINNUM",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n5\n345 1323 165 98 456\n3\n5\n335 876 98 1323 349\n3\n",
"output": "1323\n335\n",
"type": "stdin_stdout"
}
]
} |
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)
``` | vfc_4742 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/ITRA2016/problems/ITRA10",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "cat is the act of tac\ncat\n",
"output": "The antidote is found in 46.\n",
"type": "stdin_stdout"
}
]
} |
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))
``` | vfc_4746 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/WCOUNT",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"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",
... |
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)
``` | vfc_4750 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/DIVGOLD",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n4\nDCBA\n7\nXYZZYZZ\n",
"output": "ADCB\nXYYZZZZ\n",
"type": "stdin_stdout"
}
]
} |
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... | vfc_4754 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/PERIODIC",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"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"
}
]
} |
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))
``` | vfc_4758 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/WATSCORE",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n5\n2 45\n9 100\n8 0\n2 15\n8 90\n1\n11 1\n",
"output": "135\n0\n",
"type": "stdin_stdout"
}
]
} |
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... | vfc_4762 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/SIC2016/problems/NEAR",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"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"
}
]
} |
apps | verifiable_code | 1481 | Solve the following coding problem using the programming language python:
A binary string is called a self-destructing string if it can reduced to an empty string by performing the following operation some number of times (possibly zero): Choose a valid integer $i$ such that the $i$-th character of the current string ... | ```python
t=int(input())
for i in range(t):
s=input()
zeroes=s.count('0')
ones=s.count('1')
if (len(s)%2==1 or zeroes==0 or ones==0):
ans= -1
else:
ans=abs(zeroes-ones)//2
print(ans)
``` | vfc_4766 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/SDSTRING",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n001101\n1101\n110\n",
"output": "0\n1\n-1\n",
"type": "stdin_stdout"
}
]
} |
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)
``` | vfc_4770 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/PINS",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n1\n",
"output": "1 1\n",
"type": "stdin_stdout"
}
]
} |
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'):
... | vfc_4774 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/IARCSJUD/problems/LEAFEAT",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"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 appro... |
apps | verifiable_code | 1484 | Solve the following coding problem using the programming language python:
Young Sheldon is given the task to teach Chemistry to his brother Georgie. After teaching him how to find total atomic weight, Sheldon gives him some formulas which consist of $x$, $y$ and $z$ atoms as an assignment.
You already know that Georg... | ```python
for _ in range(int(input())):
s = list(input().strip())
i = 0
while i < len(s) - 1:
if s[i].isalpha() or s[i] == ')':
if s[i + 1].isdigit():
if i + 2 >= len(s) or s[i + 2] == ')':
s = s[:i+1] + ['*', s[i+1]] + s[i+2:]
else:
s = s[:i+1] + ['*', s[i+1], '+'] + s[i+2:]
i += 1
e... | vfc_4778 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/CORS2020/problems/PENEVAL",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n(xy)2\nx(x2y)3(z)2\n",
"output": "12\n46\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 1485 | Solve the following coding problem using the programming language python:
Chef has a pepperoni pizza in the shape of a $N \times N$ grid; both its rows and columns are numbered $1$ through $N$. Some cells of this grid have pepperoni on them, while some do not. Chef wants to cut the pizza vertically in half and give th... | ```python
# cook your dish here
for _ in range(int(input())):
n=int(input())
l1=[]
l2=[]
for i in range(n):
s=input()
a=s[ :n//2].count('1')
b=s[n//2: ].count('1')
if a>b:
l1.append(a-b)
elif a<b:
l2.append(b-a)
p=sum(l1)
q=sum(l2)
if p==q:
print(0)
elif p>q:
diff=p-q
flag=0... | vfc_4782 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/PEPPERON",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n6\n100000\n100000\n100000\n100000\n010010\n001100\n4\n0011\n1100\n1110\n0001\n",
"output": "2\n0\n",
"type": "stdin_stdout"
}
]
} |
Subsets and Splits
Random Hard Python Problems
Retrieves a random sample of 10 hard difficulty questions along with their answers and problem IDs, providing basic filtering but limited analytical value.