source stringclasses 1
value | task_type stringclasses 1
value | in_source_id stringlengths 1 4 | problem stringlengths 488 6.07k | gold_standard_solution stringlengths 19 30.1k | verification_info dict | metadata dict | problem_id stringlengths 5 9 |
|---|---|---|---|---|---|---|---|
apps | verifiable_code | 616 | Solve the following coding problem using the programming language python:
There are $M$ levels for a building numbered from $1$ to $M$ from top to bottom, each level having $N$ parking spots numbered from $1$ to $N$ from left to right. Some spots might have a car while other may be empty, the information of which is g... | ```python
from sys import stdin
for _ in range(int(stdin.readline())):
m, n = list(map(int, stdin.readline().split()))
final = []
arr = []
val = 0
extra = 0
for j in range(m):
ans = list(map(str, stdin.readline().split()))
if ans.count('N') == n:
val += 1
else:
if val%2 == 0:
arr.append(ans)
... | {
"language": "python",
"test_cases": [
{
"input": "2\n4 5\nN P N N P\nN N P N N\nN P N N N\nP N N N N\n3 3\nN P P\nP P P\nP P N\n",
"output": "10\n6\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/CHPTRS01/problems/CARLOT"
} | vfc_1306 |
apps | verifiable_code | 617 | Solve the following coding problem using the programming language python:
We all know that Share market is place where drastic change occurs within moments. So we have one Stockholder, Isabella, who wants to maximize her profit by selling her shares. She has $N$ shares of a Doofenshmirtz Corporation which is represent... | ```python
def CeilIndex(A, l, r, key):
while (r - l > 1):
m = l + (r - l)//2
if (A[m] >= key):
r = m
else:
l = m
return r
def LongestIncreasingSubsequenceLength(A, size):
# Add boundary case,
# when array size is one
tail... | {
"language": "python",
"test_cases": [
{
"input": "1\n4\n1 2\n4 3\n3 5\n2 4\n",
"output": "3\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/CACD2020/problems/STOCKMAX"
} | vfc_1310 |
apps | verifiable_code | 618 | Solve the following coding problem using the programming language python:
Dexter, being irritated by DD, gave her a lucrative game to play to keep her busy.
There are $N$ bags numbered $1$ to $N$. The $i_{th}$ bag contains $A_i$ coins. The bags are placed in a circular order such that the $N_{th}$ bag is adjacent to t... | ```python
t=int(input())
for i in range(t):
n,k=list(map(int,input().split(" ")))
arr=list(map(int,input().strip().split(" ")))[:n]
def maxCircularSum(arr, n, k):
if (n < k):
print("Invalid");
return;
sum = 0;
start = 0;
end = k - 1;
for i in... | {
"language": "python",
"test_cases": [
{
"input": "1\n5 3\n8 6 9 4 10\n",
"output": "24\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/ENCD2020/problems/ECAPR206"
} | vfc_1314 |
apps | verifiable_code | 619 | Solve the following coding problem using the programming language python:
In a regular table tennis match, the player who serves changes every time after 2 points are scored, regardless of which players scored them.
Chef and Cook are playing a different match — they decided that the player who serves would change ever... | ```python
n=int(input())
for i in range(n):
l=list(map(int,input().split()))
k=l[0]+l[1]
k=k%(2*l[2])
if k>=0 and k<l[2]:
print("CHEF")
else:
print("COOK")
``` | {
"language": "python",
"test_cases": [
{
"input": "3\n1 3 2\n0 3 2\n34 55 2\n",
"output": "CHEF\nCOOK\nCHEF\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/CHSERVE"
} | vfc_1318 |
apps | verifiable_code | 620 | Solve the following coding problem using the programming language python:
Find the length of the longest contiguous segment in an array, in which if a given element $K$ is inserted, $K$ becomes the second largest element of that subarray.
-----Input:-----
- The first line will contain $T$, number of test cases. Then ... | ```python
for _ in range(int(input())):
n,k=list(map(int,input().split()))
a=list(map(int,input().split()))
def check(mid):
d,left={},0
for i in range(mid):
if a[i]>k:
if a[i] not in d:
d[a[i]]=1
else:
d[a[i]]+=1
if len(d)==1:
return True
for i in range(mid,n):
if a[left]>k:
... | {
"language": "python",
"test_cases": [
{
"input": "2\n5 3\n2 4 2 4 2\n8 5\n9 3 5 7 8 11 17 2\n",
"output": "5\n3\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/SLAEL"
} | vfc_1322 |
apps | verifiable_code | 621 | Solve the following coding problem using the programming language python:
Given n words w[1..n], which originate from the same stem (e.g. grace, graceful, disgraceful, gracefully), we are interested in the original stem. To simplify the problem, we define the stem as the longest consecutive substring that occurs in al... | ```python
t = eval(input())
for _ in range(t):
n = eval(input())
a = input().strip().split()
cb, cs = 0, ""
for i in range(len(a[0])):
for j in range(i+1,len(a[0])+1):
al = True
s = a[0][i:j]
for k in a[1:]:
if s not in k:
al = False
break
if al:
if j-i>=cb:
cb = max(cb, j-i)
... | {
"language": "python",
"test_cases": [
{
"input": "1\n4\ngrace graceful disgraceful gracefully\n",
"output": "grace\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/COOK63/problems/STEM"
} | vfc_1326 |
apps | verifiable_code | 623 | Solve the following coding problem using the programming language python:
Given the list of numbers, you are to sort them in non decreasing order.
-----Input-----
t – the number of numbers in list, then t lines follow [t <= 10^6].
Each line contains one integer: N [0 <= N <= 10^6]
-----Output-----
Output given num... | ```python
t = int(input())
list_to_tri = []
for i in range(t):
list_to_tri.append(int(input()))
list_to_tri.sort()
for i in list_to_tri:
print(i)
``` | {
"language": "python",
"test_cases": [
{
"input": "5\n5\n3\n6\n7\n1\n",
"output": "1\n3\n5\n6\n7\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/TSORT"
} | vfc_1334 |
apps | verifiable_code | 624 | Solve the following coding problem using the programming language python:
Once, a genius guy Cristo visited NASA where he met many scientists. A young intern Mark at NASA asked Cristo to observe the strange behaviour of two
independent particles (say Alpha and Beta) moving in the free space.Cristo was astonished to s... | ```python
for _ in range(eval(input())):
n=eval(input())
mod=1000000007
f1,f2=[0]*101000,[0]*101000
f1[1]=0
f1[2]=2
f1[3]=3
f2[1]=1
f2[2]=1
f2[3]=2;
for i in range(4,100001):
f1[i]=f1[i-1]%mod+f1[i-2]%mod+f1[i-3]%mod
f2[i]=f2[i-1]%mod+f2[i-2]%mod+f2[i-3]%mod
print(f1[n]%mod,f2[n]%mod)
``` | {
"language": "python",
"test_cases": [
{
"input": "2\n1\n2\n",
"output": "0 1\n2 1\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/ICOD2016/problems/ICODE16C"
} | vfc_1338 |
apps | verifiable_code | 625 | Solve the following coding problem using the programming language python:
Shaun is very much interested in Subarrays. Shaun wants to count the number of subarrays in his chosen array with sum being a multiple of $10^9$. Since, Shaun is interested in huge numbers.He chose his array such that it contains only $10^8$ and... | ```python
def subCount(arr, n, k):
mod = []
for i in range(k + 1):
mod.append(0)
cumSum = 0
for i in range(n):
cumSum = cumSum + arr[i]
# as the sum can be negative,
# taking modulo twice
mod[((cumSum % k) + k) % k] = mod[((cumSum % k) + k) % k] +... | {
"language": "python",
"test_cases": [
{
"input": "2\n3\n100000000 900000000 100000000\n1\n900000000\n",
"output": "2\n0\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/COCA2020/problems/COCA2001"
} | vfc_1342 |
apps | verifiable_code | 626 | Solve the following coding problem using the programming language python:
The Chef has prepared the appetizers in the shapes of letters to spell a special message for the guests. There are n appetizers numbered from 0 to n-1 such that if the appetizers are arrayed in this order, they will display the message. The Chef... | ```python
t=int(input())
def reversebinary(bits,n):
bStr=''
for i in range(bits):
if n>0:
bStr=bStr+str(n%2)
else:
bStr=bStr+'0'
n=n>>1
return int(bStr,2)
for i in range(t):
k,msg=input().split()
k=int(k)
newmsg=[]
for j in msg:
... | {
"language": "python",
"test_cases": [
{
"input": "2\n2 chef\n4 enjoyourapplepie\n\n\n",
"output": "cehf\neayejpuinpopolre\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/COOK02/problems/ARRANGE"
} | vfc_1346 |
apps | verifiable_code | 627 | Solve the following coding problem using the programming language python:
Bharat was given a problem to solve, by his brother, Lord Ram. The problem was like, given integers, $N$ and $K$, Bharat has to find the number (possibilities) of non-increasing arrays of length $K$, where each element of the array is between $1... | ```python
import math
p=7+10**9
n,k=list(map(int,input().split()))
c=math.factorial(n+k-1)//((math.factorial(k))*(math.factorial(n-1)))
print(c%p)
``` | {
"language": "python",
"test_cases": [
{
"input": "2 5\n",
"output": "6\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/PCR12020/problems/BHARAT"
} | vfc_1350 |
apps | verifiable_code | 628 | Solve the following coding problem using the programming language python:
Chef and his best friend Aleksa are into mathematical games these days. Today, they have some ( ≥ 0 ) black cells represented as B, and a white cell represented as W, lying randomly in a straight line.
They have decided to play with these cells.... | ```python
t =int(input()) #no. of test cases
while t>0:
t=t-1
str=input()
size=len(str)
pos=str.find('W')
left=pos
right=size-pos-1
arr = [[0 for i in range(right+1)] for j in range(left+1)]
#arr[i,j] = 1 if with i black cells on left and j on right 1st player can win, 0 otherwise.
#Recursion: arr[i][j... | {
"language": "python",
"test_cases": [
{
"input": "3\nW\nBW\nBWBB\n",
"output": "Chef\nAleksa\nAleksa\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/BWCELL"
} | vfc_1354 |
apps | verifiable_code | 629 | Solve the following coding problem using the programming language python:
Naturally, the magical girl is very good at performing magic. She recently met her master wizard Devu, who gifted her R potions of red liquid,
B potions of blue liquid, and G potions of green liquid.
-
The red liquid potions have liquid amoun... | ```python
import sys
import math
import heapq
def half(n):
return n//2
def main(arr,m):
a,b,c=arr
while m!=0:
s=max(a,b,c)
if s==a:
a=half(a)
elif s==b:
b=half(b)
else:
c=half(c)
m-=1
return max(a,b,c)
for i in range(int(input())):
r,g,b,m=list(map(int,input().split())... | {
"language": "python",
"test_cases": [
{
"input": "3\n1 1 1 1\n1\n2\n3\n1 1 1 1\n2\n4\n6\n3 2 2 2\n1 2 3\n2 4\n6 8\n",
"output": "2\n4\n4\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/PRPOTION"
} | vfc_1358 |
apps | verifiable_code | 631 | Solve the following coding problem using the programming language python:
In Ciel's restaurant, a waiter is training.
Since the waiter isn't good at arithmetic, sometimes he gives guests wrong change.
Ciel gives him a simple problem.
What is A-B (A minus B) ?
Surprisingly, his answer is wrong.
To be more precise, his... | ```python
a, b = [int(x) for x in input().split()]
r = list(str(a-b))
if r[0] == "1":
r[0] = "2"
else:
r[0]="1"
print("".join(r))
``` | {
"language": "python",
"test_cases": [
{
"input": "5858 1234\n",
"output": "1624\nOutput details\nThe correct answer of 5858-1234 is 4624.\nSo, for instance, 2624, 4324, 4623, 4604 and 4629 will be accepted, but 0624, 624, 5858, 4624 and 04624 will be rejected.\nNotes\nThe problem setter is also no... | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/COOK17/problems/CIELAB"
} | vfc_1366 |
apps | verifiable_code | 632 | Solve the following coding problem using the programming language python:
Sheldon is a little geek living in Texas. While his friends like to play outside, little Sheldon likes to play around with ICs and lasers in his house. He decides to build N clap activated toggle machines each with one power inlet and one outlet... | ```python
n=int(input())
while n>0:
i=1
a,b=(int(i) for i in input().split())
if (b+1)%(i<<a)==0:
print("ON")
else:
print("OFF")
n=n-1
``` | {
"language": "python",
"test_cases": [
{
"input": "4\n4 0\n4 47\n1 0\n1 1\n",
"output": "OFF\nON\nOFF\nON\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/BTCD2012/problems/T05"
} | vfc_1370 |
apps | verifiable_code | 633 | Solve the following coding problem using the programming language python:
Well known investigative reporter Kim "Sherlock'' Bumjun needs your help! Today, his mission is to sabotage the operations of the evil JSA. If the JSA is allowed to succeed, they will use the combined power of the WQS binary search and the UFDS ... | ```python
n=int(input())
def do():
t=int(input())
x=[]
for i in range(t):
x.append(int(input()))
print(max(x))
return
for i in range(n):
do()
``` | {
"language": "python",
"test_cases": [
{
"input": "1\n5\n4\n7\n6\n3\n1\n",
"output": "7\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/UWCOI20A"
} | vfc_1374 |
apps | verifiable_code | 634 | Solve the following coding problem using the programming language python:
Lyra Belacqua is a very gifted girl. She is one of a very small set of people capable of reading an alethiometer, more commonly known as The Golden Compass. It has one specific use: to tell the truth. The name in fact, is derived from "Aletheia"... | ```python
string=input()
max_no=0
for i in range(len(string)):
var_occur=0
check_no=str()
j=i
while(j<len(string) and var_occur<2 ):
if(string[j].isalpha()):
if(var_occur==0):
check_no+='9'
var_occur+=1
else:
var_occur+=1
else:
check_no+=string[j]
j+=1
#print(check_no)
max_no=max(max_no... | {
"language": "python",
"test_cases": [
{
"input": "06454\nInput2:\nC0D3C43F\n",
"output": "6454\nOutput2:\n3943\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/ALETHIO"
} | vfc_1378 |
apps | verifiable_code | 635 | Solve the following coding problem using the programming language python:
Chef is given a sequence of prime numbers $A_1, A_2, \ldots, A_N$. This sequence has exactly $2^N$ subsequences. A subsequence of $A$ is good if it does not contain any two identical numbers; in particular, the empty sequence is good.
Chef has t... | ```python
# cook your dish here
from collections import Counter
def solve(arr, n, k):
ans = 0
dict1 = {}
mod = 1000000007
for i in range(n):
if arr[i] in dict1:
dict1[arr[i]] += 1
else:
dict1[arr[i]] = 1
l1 = [0]+list(dict1.keys())
v = min(k, len(l1))
dp = [[0 for _ in range(v+1)]for _ in range(len(... | {
"language": "python",
"test_cases": [
{
"input": "5 3\n2 2 3 3 5\n",
"output": "18\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/GDSUB"
} | vfc_1382 |
apps | verifiable_code | 636 | Solve the following coding problem using the programming language python:
In this problem you are given a sequence of $N$ positive integers $S[1],S[2],\dots,S[N]$. In addition you are given an integer $T$, and your aim is to find the number of quadruples $(i,j,k,l)$, such that $1 \le i < j < k < l \le N$, and $S[i] +... | ```python
# cook your dish here
from itertools import combinations
a = list(map(int, input().split()))
n = a[0]
t = a[1]
q = list(combinations(a[2:], 4))
total = 0
for i in q:
if sum(i) == t:
total += 1
print(total)
``` | {
"language": "python",
"test_cases": [
{
"input": "6 20 3 1 1 2 5 10\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/ZCOPRAC/problems/ZCO17001"
} | vfc_1386 |
apps | verifiable_code | 637 | Solve the following coding problem using the programming language python:
A balanced parenthesis string is defined as follows:
- The empty string is balanced
- If P is balanced, (P) is also
- If P and Q are balanced, PQ is also balanced
You are given two even integers n$n$ and k$k$. Find any balanced paranthesis stri... | ```python
import sys
def input():
return sys.stdin.readline().strip()
for i in range(int(input())):
n, k = map(int, input().split())
arr = []
if k == 2 or k == 4 or n % 2 != 0 or n == k:
arr.append('-1')
elif k % 2 != 0:
for i in range(int(n / 2)):
arr.append('(')
... | {
"language": "python",
"test_cases": [
{
"input": "2\n4 2\n8 6\n",
"output": "-1\n(())(())\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/UNBAL"
} | vfc_1390 |
apps | verifiable_code | 638 | Solve the following coding problem using the programming language python:
You will be given m strings. For each of those strings, you need to count the total number of appearances of that string as substrings in all possible strings of length n containing only lower case English letters.
A string may appear in a str... | ```python
for _ in range(int(input())):
n,m=map(int,input().split())
print("Case "+str(_+1)+":")
for i in range(m):
s=input()
ls=len(s)
if ls>n:
print("0")
else:
k=(n-ls+1)
print((k*pow(26,n-ls,1000000007))%1000000007)
``` | {
"language": "python",
"test_cases": [
{
"input": "3\n2 1\naa\n2 1\nd\n12 3\ncdmn\nqweewef\nqs\n\n\n",
"output": "Case 1:\n1\nCase 2:\n52\nCase 3:\n443568031\n71288256\n41317270\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/ZUBAPCNT"
} | vfc_1394 |
apps | verifiable_code | 639 | Solve the following coding problem using the programming language python:
For a string $S$ let the unique set of characters that occur in it one or more times be $C$. Consider a permutation of the elements of $C$ as $(c_1, c_2, c_3 ... )$. Let $f(c)$ be the number of times $c$ occurs in $S$.
If any such permutation of... | ```python
# cook your dish here
t=int(input())
for _ in range(t):
st=input()
s=set(st)
a=[]
f1=f2=0
for i in s:
a.append(st.count(i))
a.sort()
if len(a)>=3:
for i in range(2,len(a)):
if a[i]!=a[i-1]+a[i-2]:
f1=1
break
x=a[0]
a[0]=a[1]
a[1]=x
for i in range(2,len(a)):
if a[i]!=a[i-1]+a[i... | {
"language": "python",
"test_cases": [
{
"input": "3\naaaabccc\naabbcc\nppppmmnnoooopp\n",
"output": "Dynamic\nNot\nDynamic\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/CLFIBD"
} | vfc_1398 |
apps | verifiable_code | 640 | Solve the following coding problem using the programming language python:
Chef made two laddus with sweetness X and Y respectively. Cheffina comes and sees the chef created two laddus with different sweetness (might be same). Cheffina has the magical power to make the sweetness of laddus equal. Cheffina requires 1 uni... | ```python
def gcd(a,b):
if b==0:return a
else:return gcd(b,a%b)
def lcm(a,b):
m=a*b
g=gcd(a,b)
return int(m/g)
for _ in range(int(input())):
x,y=[int(x) for x in input().split()]
l=lcm(x,y)
s=int(l/x)
t=int(l/y)
print(s+t-2)
``` | {
"language": "python",
"test_cases": [
{
"input": "2\n2 2\n4 6\n",
"output": "0\n3\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/PBK22020/problems/ITGUY22"
} | vfc_1402 |
apps | verifiable_code | 641 | Solve the following coding problem using the programming language python:
A key feature of the Siruseri railway network is that it has exactly one route between any pair of stations.
The government has chosen three contractors to run the canteens at the stations on the railway network. To ensure that there are no disp... | ```python
n=int(input())
cost=[]
d={}
val_desc=[0]*n
visited=set()
visited.add(0)
dfstack=[]
desc = [[False for i in range(n)] for i in range(n)]
for i in range(n):
cost.append(int(input()))
d[i]=[]
for i in range(n-1):
j,k=list(map(int,input().split()))
d[j-1].append(k-1)
d[k-1].append(j-1)
def... | {
"language": "python",
"test_cases": [
{
"input": "6\n10\n20\n25\n40\n30\n30\n4 5\n1 3\n3 4\n2 3\n6 4\n",
"output": "70\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/IARCSJUD/problems/SPLIT3"
} | vfc_1406 |
apps | verifiable_code | 643 | Solve the following coding problem using the programming language python:
Ted$Ted$ loves prime numbers. One day he is playing a game called legendary$legendary$ with his girlfriend Robin$Robin$. Ted$Ted$ writes a number N$N$ on a table and the number is in the form of :
N = P1A1 * P2A2 * ……….. * PnAn
Ted$Ted$ asks Ro... | ```python
d = 10**9 + 7
t = int(input())
while t:
t-=1
n =int(input())
p =list(map(int, input().strip().split()))
a =list(map(int, input().strip().split()))
b =list(map(int, input().strip().split()))
ans = 1
for i in range(n):
c = a[i] - b[i] + 1
tmp = (( pow... | {
"language": "python",
"test_cases": [
{
"input": "1\n3\n2 3 5\n2 1 2\n1 1 1\n",
"output": "540\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/AARA2018/problems/ARMBH4"
} | vfc_1414 |
apps | verifiable_code | 644 | Solve the following coding problem using the programming language python:
There are $N$ friends in a group. Each of them have $A_{i}$ candies.
Can they share all of these candies among themselves such that each one of them have equal no. of candies.
-----Input:-----
- First line will contain $T$, number of testcases.... | ```python
# cook your dish here
for _ in range(int(input())):
friends = int(input())
candies = list(map(int,input().split()))
if (sum(candies) % friends == 0):
print("Yes")
else:
print("No")
``` | {
"language": "python",
"test_cases": [
{
"input": "1\n3\n1 2 3\n",
"output": "Yes\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/ENJU2020/problems/ECJN202"
} | vfc_1418 |
apps | verifiable_code | 645 | Solve the following coding problem using the programming language python:
Chef has $K$ chocolates and he wants to distribute them to $N$ people (numbered $1$ through $N$). These people are standing in a line in such a way that for each $i$ ($1 \le i \le N-1$), person $i$ and person $i+1$ are adjacent.
First, consider ... | ```python
t = int(input())
for _ in range(t):
n = int(input())
k = int(input())
num = int(k/n)
x = max(n*(1+num) - k, 0)
diff = abs(x - (n-x))
if diff == 0:
number = 2*x - 1
else:
number = min(x, n-x)*2
print(number)
``` | {
"language": "python",
"test_cases": [
{
"input": "1\n3\n2\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/MMAX"
} | vfc_1422 |
apps | verifiable_code | 646 | Solve the following coding problem using the programming language python:
Given a string $s$.
You can perform the following operation on given string any number of time.
Delete two successive elements of the string if they are same.
After performing the above operation you have to return the least possible length of t... | ```python
from sys import stdin,stdout
import math,bisect
from datetime import date
from collections import Counter,deque,defaultdict
L=lambda:list(map(int, stdin.readline().strip().split()))
M=lambda:list(map(int, stdin.readline().strip().split()))
I=lambda:int(stdin.readline().strip())
S=lambda:stdin.readline().strip... | {
"language": "python",
"test_cases": [
{
"input": "3\nabccd\nabbac\naaaa\n",
"output": "3\n1\n0\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/CDGO2021/problems/MINLEN"
} | vfc_1426 |
apps | verifiable_code | 647 | Solve the following coding problem using the programming language python:
Ashley wrote a random number generator code.
Due to some reasons, the code only generates random positive integers which are not evenly divisible by 10. She gives $N$ and $S$ as input to the random number generator. The code generates a random n... | ```python
"""
Author : thekushalghosh
Team : CodeDiggers
"""
import sys,math
input = sys.stdin.readline
############ ---- USER DEFINED INPUT FUNCTIONS ---- ############
def inp():
return(int(input()))
def inlt():
return(list(map(int,input().split())))
def insr():
s = input()
return(s[:len(s) -... | {
"language": "python",
"test_cases": [
{
"input": "2\n1 5\n2 2\n",
"output": "5\n1\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/NCC2020/problems/NCC005"
} | vfc_1430 |
apps | verifiable_code | 648 | Solve the following coding problem using the programming language python:
Chef is going to organize a hill jumping competition and he is going to be one of the judges in it. In this competition there are N hills in a row, and the initial height of i-th hill is Ai. Participants are required to demonstrate their jumping... | ```python
n,q=list(map(int,input().split()))
final=[]
height=list(map(int,input().split()))
for k in range(0,q):
b=input().split()
if int(b[0])==1:
step=int(b[1])-1
for k in range(0,int(b[2])):
temp = 0
j=1
while j in range(1,101) and temp==0 and step+j<n:
if height[step+j]>height[step]:
step=st... | {
"language": "python",
"test_cases": [
{
"input": "5 3\n1 2 3 4 5\n1 1 2\n2 3 4 -1\n1 1 2\n",
"output": "3\n4\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/AUG17/problems/HILLJUMP"
} | vfc_1434 |
apps | verifiable_code | 649 | Solve the following coding problem using the programming language python:
Mandarin chinese
, Russian and Vietnamese as well.
You are given a grid with $n$ rows and $m$ columns. Each cell of this grid can either be empty or it contains one particle. It can never contain more than one particle. Let's denote the cell in ... | ```python
def main():
for _ in range(int(input())):
rows,column = map(int,input().split())
arr = []
for i in range(rows):
arr.append(list(input()))
string = input()
last = string[-1]
operation = Find(string,last)
for i in string[0]+operation:
if i == "L":
arr = Left(arr)
if i == "R":
arr... | {
"language": "python",
"test_cases": [
{
"input": "3\n4 4\n1010\n0010\n1001\n0100\nLRDU\n4 3\n000\n010\n001\n101\nLRL\n3 2\n01\n10\n00\nD\n",
"output": "0011\n0011\n0001\n0001\n000\n100\n100\n110\n00\n00\n11\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/FRCPRT"
} | vfc_1438 |
apps | verifiable_code | 650 | Solve the following coding problem using the programming language python:
Chef is the event manager of his college. He has been assigned the task to manage the upcoming tech fest. There are $K$ rooms where the event can take place, and at a particular time only one event can be organized in a room for a particular tim... | ```python
import sys
# import math
from math import gcd
# import re
# from heapq import *
# from collections import defaultdict as dd
# from collections import OrderedDict as odict
# from collections import Counter as cc
# from collections import deque
# sys.setrecursionlimit(10**5)#thsis is must
# mod = 10**... | {
"language": "python",
"test_cases": [
{
"input": "1\n4 2\n1 10 1\n10 20 2\n15 50 2\n20 30 2\n",
"output": "3\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/ENNO2020/problems/ENCNOV4"
} | vfc_1442 |
apps | verifiable_code | 651 | Solve the following coding problem using the programming language python:
In these quarantine days, Chef and Chefina are getting bored. So, Chef came up with a game for her. He gets a pack of cards with numbers written on them. Chef then asks her to remove cards from the pack in the following manner: Chefina can choos... | ```python
# cook your dish here
try:
for i in range(int(input())):
n=int(input())
l=[int(j) for j in input().split()][:n]
d={}
for j in l:
d[j]=d.get(j,0)+1
a=len(d)
c=0
for j in list(d.keys()):
while(d[j]>=3):
d[j]=(d[j]//3)+(d[j]%3)
if(d[j]==2):
c=c+1
if(c&1):
s=0
for j in list... | {
"language": "python",
"test_cases": [
{
"input": "2\n5\n1 2 2 3 5\n9\n1 2 2 3 3 5 8 8 9\n",
"output": "3\n5\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/BTCH2020/problems/UNQCARD"
} | vfc_1446 |
apps | verifiable_code | 652 | Solve the following coding problem using the programming language python:
Shubham recently learned the lexicographical order in strings.
Now, he has two strings s1 and s2 of the equal size and Shubham wants to compare those two strings lexicographically.
Help Shubham with the strings comparison.
Note:
Letters a... | ```python
t=eval(input())
while t:
t=t-1
s1=input().lower()
s2=input().lower()
res="equal"
for i in range(len(s1)):
if(s1[i]!=s2[i]):
res="first" if s1[i]<s2[i] else "second"
break
print(res)
``` | {
"language": "python",
"test_cases": [
{
"input": "2\nabc\nacb\nAB\nba\n",
"output": "first\nfirst\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/CDFXOQ16/problems/CDFX01"
} | vfc_1450 |
apps | verifiable_code | 653 | Solve the following coding problem using the programming language python:
You have a laser with P amount of energy in it. You are playing a game where you have to use the laser to destroy some crystals, each with some health of their own. Initially, you have 0 points.
Each crystal has an associated health. The health ... | ```python
def game(n,l,p):
if(len(l)==0):
return 0
l.sort()
if(len(l)>=1 and p<l[0]):
return 0
l.sort()
c=0
ma=set()
ma.add(0)
while(len(l)):
if(p>=l[0]):
p-=l[0]
c+=1
ma.add(c)
l=l[1:]
... | {
"language": "python",
"test_cases": [
{
"input": "1\n200\n100\n",
"output": "0\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/COFJ2020/problems/JUN1"
} | vfc_1454 |
apps | verifiable_code | 654 | Solve the following coding problem using the programming language python:
Three numbers A, B and C are the inputs. Write a program to find second largest among them.
-----Input-----
The first line contains an integer T, the total number of testcases. Then T lines follow, each line contains three integers A, B and C... | ```python
# cook your dish here
x=int(input())
for i in range(x):
s=list(map(int,input().split()))
s.sort()
print(s[1])
``` | {
"language": "python",
"test_cases": [
{
"input": "3\n120 11 400\n10213 312 10\n10 3 450\n",
"output": "120\n312\n10\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/FLOW017"
} | vfc_1458 |
apps | verifiable_code | 655 | Solve the following coding problem using the programming language python:
Chef had a sequence of positive integers with length $N + K$. He managed to calculate the arithmetic average of all elements of this sequence (let's denote it by $V$), but then, his little brother deleted $K$ elements from it. All deleted elemen... | ```python
def __starting_point():
t=int(input())
for _ in range(t):
n,k,v=map(int,input().split())
li=list(map(int,input().split()))
sumn=0
for i in range(n):
sumn=sumn+li[i]
sumk=v*(n+k)-sumn
e=int(sumk/k)
r=sumk%k
if e<=0:
print(-1)
elif r!=0:
print(-1)
else:
print(e)
__starting_poin... | {
"language": "python",
"test_cases": [
{
"input": "3\n3 3 4\n2 7 3\n3 1 4\n7 6 5\n3 3 4\n2 8 3\n",
"output": "4\n-1\n-1\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/AVG"
} | vfc_1462 |
apps | verifiable_code | 656 | Solve the following coding problem using the programming language python:
Write a program to obtain a number $N$ and increment its value by 1 if the number is divisible by 4 $otherwise$ decrement its value by 1.
-----Input:-----
- First line will contain a number $N$.
-----Output:-----
Output a single line, the new ... | ```python
# cook your dish here
n = int(input())
if(n%4==0):
print(n+1)
else:
print(n-1)
``` | {
"language": "python",
"test_cases": [
{
"input": "5\n",
"output": "4\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/DECINC"
} | vfc_1466 |
apps | verifiable_code | 657 | Solve the following coding problem using the programming language python:
You will be given a two-dimensional array with row consisting values 0 or 1.
A move consists of choosing any column or row, and toggling all the 0’s as 1’s and 1’s as 0’s.
After making the required moves, every row represents a binary number... | ```python
def matrixScore(A):
"""
:type A: List[List[int]]
:rtype: int
"""
m,n = len(A),len(A[0])
# 行变换
for i in range(m):
if A[i][0] == 1: continue
for j in range(n):
A[i][j] = 1 - A[i][j]
# 列变换
... | {
"language": "python",
"test_cases": [
{
"input": "3 4\n0 0 1 1\n1 0 1 0\n1 1 0 0\n",
"output": "39\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/COFDEC20/problems/COFDQ2"
} | vfc_1470 |
apps | verifiable_code | 658 | Solve the following coding problem using the programming language python:
A sequence of integers ($a_1, a_2, \ldots, a_k$) is said to be UpDown, if these inequalities hold true:
- $a_1 \le a_2$
- $a_2 \ge a_3$
- $a_3 \le a_4$
and so on.
That is, every even-indexed element should be at least as large as its adjacent el... | ```python
# cook your dish here
t=int(input())
for _ in range(t):
n=int(input())
array=list(map(int, input().split()))
list_sub=[]
idx=0
counter=0
for i in range(n-1):
if counter%2==0 and array[i]<=array[i+1]:
counter+=1
elif counter%2==1 and array[i]>=array[i+1]:
... | {
"language": "python",
"test_cases": [
{
"input": "2\n7\n100 1 10 3 20 25 24\n5\n3 3 2 4 1\n",
"output": "7\n6\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/ZCOPRAC/problems/UPDOWSEQ"
} | vfc_1474 |
apps | verifiable_code | 659 | Solve the following coding problem using the programming language python:
Binod is a youtuber and he is busy in the fame of social media so he asked you to help him solve a problem.
You have been given an array of $positive$ $integers$ $a_{1},a_{2},a_{3},...,a_{i},...,a_{n}$ of size n.You have to find the smallest len... | ```python
#binarr
def binarr(a, k, s):
a.sort(reverse=True)
arr = [0]*k
for i in range(k):
arr[i] = a[i]
if sum(arr) <= s:
return binarr(a, k+1, s)
return len(arr)
try:
n, k, s = list(map(int, input().split()))
a = list(map(int, input().split()))
print(binar... | {
"language": "python",
"test_cases": [
{
"input": "1:\n5 1 5\n1 2 3 4 5\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/COVO2020/problems/BINARR"
} | vfc_1478 |
apps | verifiable_code | 660 | Solve the following coding problem using the programming language python:
The chef was busy in solving algebra, he found some interesting results, that there are many numbers which can be formed by the sum of the factorial of the digits, he wrote all those interesting numbers in the diary(in increasing order) and went... | ```python
t = int(input())
for i in range(t):
n = int(input())
if n == 1 or n == 2 or n == 145 or n == 40585:
print(1)
else:
print(0)
``` | {
"language": "python",
"test_cases": [
{
"input": "2\n2\n10\n",
"output": "1\n0\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/PBK22020/problems/ITGUY26"
} | vfc_1482 |
apps | verifiable_code | 661 | Solve the following coding problem using the programming language python:
Raju has created a program to find the square root of a number. But his program can store only integers. Being a newbie, he didn't know about rounding the numbers. Hence his program returns the absolute value of the result if possible. For examp... | ```python
try:
from math import sqrt
t,x=list(map(int,input().split()))
for _ in range(t):
n=int(input())
if(n<0):
print("no")
else:
diff=(x/100)*n
ans=int(sqrt(n))
ans1=ans**2
if(n-ans1<=diff):
print("yes")
else:
print("no")
except:
pass
``` | {
"language": "python",
"test_cases": [
{
"input": "2 20\n5\n3\n",
"output": "yes\nno\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/COMT2020/problems/ROOTSQR"
} | vfc_1486 |
apps | verifiable_code | 662 | Solve the following coding problem using the programming language python:
Kabir wants to impress Tara by showing her his problem solving skills. He has decided to give the correct answer to the next question which will be asked by his Algorithms teacher.
The question asked is:
Find the sum of alternate consecutive d$d... | ```python
# cook your dish here
for t in range(int(input().strip())):
d = int(input().strip())
L, R = map(int, input().strip().split(" "))
if L % 2 == 0:
L += 1
sum = (((((R - L + 2)//2)//d)+1)//2) - 1
sum = (sum * 2 * d * (sum + 1) * d) + (sum+1) *d * (L + d -1)
print(sum%1000000007)
``... | {
"language": "python",
"test_cases": [
{
"input": "1\n3\n10 33\n",
"output": "114\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/HECS2020/problems/CC002"
} | vfc_1490 |
apps | verifiable_code | 663 | Solve the following coding problem using the programming language python:
You are given a string $S$ and an integer $L$. A operation is described as :- "You are allowed to pick any substring from first $L$ charcaters of $S$, and place it at the end of the string $S$.
A string $A$ is a substring of an string $B$ if $A... | ```python
def least_rotation(S: str) -> int:
"""Booth's algorithm."""
f = [-1] * len(S) # Failure function
k = 0 # Least rotation of string found so far
for j in range(1, len(S)):
sj = S[j]
i = f[j - k - 1]
while i != -1 and sj != S[k + i + 1]:
if sj < S[k +... | {
"language": "python",
"test_cases": [
{
"input": "2\n1 rga\n2 cab\n",
"output": "arg\nabc\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/BIT32020/problems/BIT3B"
} | vfc_1494 |
apps | verifiable_code | 664 | Solve the following coding problem using the programming language python:
This year $p$ footballers and $q$ cricketers have been invited to participate in IPL (Indian Programming League) as guests. You have to accommodate them in $r$ rooms such that-
- No room may remain empty.
- A room may contain either only footbal... | ```python
# cook your dish here
MOD = 998244353
fball = [ [0]*101 for _ in range(101) ]
cric = [ [0]*101 for _ in range(101) ]
def calSNum(n, r):
if n == r or r == 1:
fball[r][n] = 1
return
if n > 0 and r > 0 and n > r:
fball[r][n] = (fball[r-1][n-1]%MOD + (r*fball[r][n-1])%MOD )%MOD
return
fball[r][n]... | {
"language": "python",
"test_cases": [
{
"input": "4\n2 1 4\n2 4 4\n2 5 4\n2 8 4\n",
"output": "0\n3\n10\n609\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/FCIPL"
} | vfc_1498 |
apps | verifiable_code | 665 | Solve the following coding problem using the programming language python:
Chef organised a chess tournament, which spanned over $M$ months. There were $N$ players, and player $i$ was rated $R_i$ before the start of the tournament. To see the progress of the players, he noted their rating changes at the end of each mon... | ```python
# cook your dish here
t=int(input())
for _ in range(t):
n,m=list(map(int,input().split()))
r=list(map(int,input().split()))
rating=[[r[i]]*(m) for i in range(n)]
ranking=[[0]*m for i in range(n)]
for i in range(n):
diff=list(map(int,input().split()))
for j in range(m):
rating[i][j]+=diff[j]
if ... | {
"language": "python",
"test_cases": [
{
"input": "2\n3 3\n2500 2500 2520\n10 -5 -20\n10 15 20\n-15 17 13\n2 3\n2125 2098\n-20 10 -10\n10 10 -20\n",
"output": "2\n2\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/ELOMAX"
} | vfc_1502 |
apps | verifiable_code | 666 | Solve the following coding problem using the programming language python:
The chef is trying to solve some pattern problems, Chef wants your help to code it. Chef has one number K to form a new pattern. Help the chef to code this pattern problem.
-----Input:-----
- First-line will contain $T$, the number of test case... | ```python
# cook your dish here
t = int(input())
for _ in range(t):
s = ''
n = int(input())
if n==1:
print(1)
continue
for i in range(1, n+1):
s = s + str(i)
print(s)
p = 1
for i in range(n-1):
s = ''
for j in range(n):
s = s + str(p... | {
"language": "python",
"test_cases": [
{
"input": "4\n1\n2\n3\n4\n",
"output": "1\n12\n34\n123\n456\n789\n1234\n5678\n9101112\n13141516\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/PTRN2021/problems/ITGUY49"
} | vfc_1506 |
apps | verifiable_code | 667 | Solve the following coding problem using the programming language python:
Diana is planning to make a very long journey. Her journey consists of $N$ bus routes, numbered from $1 to N$ in the order she must take them. The buses themselves are very fast but do not run often. The $i-th$ bus route only runs every $Xi$ day... | ```python
t = int(input())
for _ in range(t):
nd = list(map(int, input().split()))
n = nd[0]
d = nd[1]
cutOff = []
x = d
buses = list(map(int, input().split()))
for i in range(len(buses)-1,-1,-1):
x = x - x%buses[i]
print(x)
``` | {
"language": "python",
"test_cases": [
{
"input": "3\n3 10\n3 7 2\n4 100\n11 10 5 50\n1 1\n1\n",
"output": "6\n99\n1\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/COX22020/problems/CCODEX2"
} | vfc_1510 |
apps | verifiable_code | 668 | Solve the following coding problem using the programming language python:
You are given an array A with size N (indexed from 0) and an integer K. Let's define another array B with size N · K as the array that's formed by concatenating K copies of array A.
For example, if A = {1, 2} and K = 3, then B = {1, 2, 1, 2, 1, ... | ```python
def max_sum(arr):
# Finds the maximum sum of sub-arrays of arr
max_till_now = -1000000 #minimum possible number
current_sum = 0
for i in range(len(arr)):
if current_sum < 0:
# If sum of previous elements is negative, then ignore them. Start fresh
# with `curren... | {
"language": "python",
"test_cases": [
{
"input": "2\n2 3\n1 2\n3 2\n1 -2 1\n\n\n",
"output": "9\n2\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/KCON"
} | vfc_1514 |
apps | verifiable_code | 669 | Solve the following coding problem using the programming language python:
Nadaca is a country with N$N$ cities. These cities are numbered 1$1$ through N$N$ and connected by M$M$ bidirectional roads. Each city can be reached from every other city using these roads.
Initially, Ryan is in city 1$1$. At each of the follow... | ```python
T = int(input())
for _ in range(T):
N, M, K = [int(x) for x in input().split()]
UV = [[int(x) for x in input().split()] for _ in range(M)]
Q = int(input())
AB = [[int(x) for x in input().split()] for _ in range(Q)]
X = [[i] for i in range(N)]
for u, v in UV:
X[u - 1] += [v - 1]
... | {
"language": "python",
"test_cases": [
{
"input": "3\n4 3 3\n1 2\n1 3\n1 4\n0\n4 3 3\n1 2\n1 3\n1 4\n1\n2 2\n4 3 3\n1 2\n1 3\n1 4\n1\n2 1\n",
"output": "28\n4\n6\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/WNDR"
} | vfc_1518 |
apps | verifiable_code | 670 | Solve the following coding problem using the programming language python:
Sereja has an array A of N positive integers : A[1], A[2], A[3], ... , A[N].
In a single operation on the array, he performs the following two steps :
- Pick two indices i, j s.t. A[i] > A[j]
- A[i] -= A[j]
Sereja can apply these operation... | ```python
def gcd(a,b):
if b==0:
return a
else:
return gcd(b,a%b)
def main():
t=int(input())
while t!=0:
t=t-1
n=int(input())
if n==1:
print(input())
else:
a=list(map(int,input().split(" ")))
p=a[0]
for i in range(1,n):
p=gcd(p,a[i])
if p==1:
break
print(n*p)
def __starting... | {
"language": "python",
"test_cases": [
{
"input": "2\n1\n1\n3\n2 4 6\n",
"output": "1\n6\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/COOK64/problems/SEAARASU"
} | vfc_1522 |
apps | verifiable_code | 671 | Solve the following coding problem using the programming language python:
Chef is going to start playing Fantasy Football League (FFL) this season. In FFL, each team consists of exactly $15$ players: $2$ goalkeepers, $5$ defenders, $5$ midfielders and $3$ forwards. Chef has already bought $13$ players; he is only miss... | ```python
for i in range(int(input())):
n,s =map(int,input().split())
l1=list(map(int,input().split()))
l2=list(map(int,input().split()))
m=[]
n=[]
for i in range(len(l1)):
if l2[i]==0:
m.append(l1[i])
else:
n.append(l1[i])
if len(m)>0 and len(n)>0:
if 100-s>=(min(m)+min(n)):
print("yes")
else:
... | {
"language": "python",
"test_cases": [
{
"input": "2\n4 90\n3 8 6 5\n0 1 1 0\n4 90\n5 7 6 5\n0 1 1 0\n",
"output": "yes\nno\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/FFL"
} | vfc_1526 |
apps | verifiable_code | 672 | Solve the following coding problem using the programming language python:
In my town ,there live a coder named Chef . He is a cool programmer . One day , he participate in a programming contest ,the contest give him only one problem . If he can’t solve the problem ,the problem setter will kill him . But the round allo... | ```python
# cook your dish here
from math import sqrt
for i in range(int(input())):
x1,y1,x2,y2=list(map(float,input().split()))
m=(y2-y1)/(x2-x1)
c=y2-m*x2
print('Test case : ',i+1)
q=int(input())
for i in range(q):
x3,y3=list(map(float,input().split()))
if(y3-m*x3-c==0):
print("YES")
else:
d=(abs(y3... | {
"language": "python",
"test_cases": [
{
"input": "2\n3 5 6 5\n2\n4 5\n6 8\n3 4 7 10\n1\n7 4\n",
"output": "Test case : 1\nYES\nNO\n3.000000\nTest case : 2\nNO\n3.328201\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/ABCC2020/problems/POINT"
} | vfc_1530 |
apps | verifiable_code | 673 | Solve the following coding problem using the programming language python:
Its Christmas time and Santa has started his ride to deliver gifts to children waiting for him in a 1-dimentional city. All houses in this city are on a number line numbered as 1, 2, 3… and so on. Santa wants to deliver to houses from n to m, bu... | ```python
from math import gcd
from math import ceil
from itertools import combinations as c
t=int(input())
for _ in range(t):
n,m,a,d=list(map(int,input().split()))
l=[]
for i in range(5):
l.append(a+i*d)
ans=m-n+1
for i in range(1,6):
x=list(c(l,i))
for j ... | {
"language": "python",
"test_cases": [
{
"input": "1\n2 20 2 1\n",
"output": "5\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/NQST2020/problems/XMASGIFT"
} | vfc_1534 |
apps | verifiable_code | 674 | Solve the following coding problem using the programming language python:
Chef bought an electronic board and pen. He wants to use them to record his clients' signatures.
The board is a grid with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$) of pixels. Initially, all pixels are white. ... | ```python
import numpy as np
for _ in range(int(input())):
ans = np.float('inf')
n, m = (int(x) for x in input().split())
sig = np.zeros((n,m))
img = np.zeros((3*n,3*m))
for row in range(n):
sig[row,:] = np.array([int(x) for x in input()])
for row in range(n):
img[row+n,m:2*m] = np.array([int(x) for x in inpu... | {
"language": "python",
"test_cases": [
{
"input": "5\n3 3\n100\n010\n000\n000\n010\n001\n4 4\n0000\n0110\n0000\n0011\n1100\n0000\n1100\n0000\n3 3\n100\n000\n001\n000\n010\n000\n3 3\n000\n010\n000\n100\n000\n001\n3 3\n111\n000\n000\n001\n001\n001\n",
"output": "0\n2\n1\n0\n2\n",
"type": "stdin... | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/SIGNTURE"
} | vfc_1538 |
apps | verifiable_code | 676 | Solve the following coding problem using the programming language python:
There is an event in DUCS where boys get a chance to show off their skills to impress girls. The boy who impresses the maximum number of girls will be honoured with the title “Charming Boy of the year”.
There are $N$ girls in the department. Eac... | ```python
from collections import Counter
for _ in range(int(input())):
n=int(input())
l=[i for i in input().split()]
ll=[]
c=Counter(l)
cc=[]
m=0
for l,count in c.most_common(len(l)-1):
if m==0:
ll.append(l)
cc.append(count)
... | {
"language": "python",
"test_cases": [
{
"input": "2\n10\njohn berry berry thomas thomas john john berry thomas john\n4\nramesh suresh suresh ramesh\n",
"output": "john\nramesh\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/DCC2020/problems/DCC202"
} | vfc_1546 |
apps | verifiable_code | 677 | Solve the following coding problem using the programming language python:
Computation of the date either previous or forthcoming dates is quiet easy. But it is quiet difficult to calculate the day from a particular given date.
You are required to find a day from a particular date given to you.
-----Input-----
It con... | ```python
import sys
import datetime
a,b,c = list(map(int,sys.stdin.readline().split()))
d = datetime.date(c,b,a)
print(d.strftime("%A"))
``` | {
"language": "python",
"test_cases": [
{
"input": "14 3 2012\n",
"output": "Wednesday\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/TCTR2012/problems/NOPC10"
} | vfc_1550 |
apps | verifiable_code | 678 | Solve the following coding problem using the programming language python:
Snackdown 2019 is coming! People have started to spread the word and tell other people about the contest.
There are $N$ people numbered $1$ through $N$. Initially, only person $1$ knows about Snackdown. On each day, everyone who already knows ab... | ```python
# cook your dish here
test_case = int(input())
while test_case :
n_people = int(input())
array = list(map(int, input().strip().split()))
sums =[0 for i in range(n_people)]
sums[0] = array[0]
for i in range(1, n_people) :
sums[i] = sums[i-1] + array[i]
# print(sums)
k = 1
count = 0
i = 0
... | {
"language": "python",
"test_cases": [
{
"input": "2\n7\n2 1 1 5 5 5 5\n5\n5 1 3 2 1\n",
"output": "2\n1\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/SPREAD2"
} | vfc_1554 |
apps | verifiable_code | 679 | Solve the following coding problem using the programming language python:
Harry is a bright student. To prepare thoroughly for exams, he completes all the exercises in his book! Now that the exams are approaching fast, he is doing book exercises day and night. He writes down and keeps updating the remaining number of ... | ```python
t=eval(input())
a=[]
b=[]
top=-1
for __ in range(0,t):
x=input().split()
if(x[0]!="-1" and x[0]!="0"):
add=int(x[0])
if top!=-1 and add>a[top][0] :
b[top]+=1
else:
a.append((add,x[1]))
b.append(0)
top+=1
elif (x[0]=="-1"):
#print("%s %s" %(b[t... | {
"language": "python",
"test_cases": [
{
"input": "6\n9 english\n6 mathematics\n8 geography\n-1\n3 graphics\n-1\n",
"output": "1 mathematics\n0 graphics\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/DEC12/problems/BEX"
} | vfc_1558 |
apps | verifiable_code | 680 | Solve the following coding problem using the programming language python:
You are given two integer sequences $A_1, A_2, \ldots, A_N$ and $B_1, B_2, \ldots, B_M$. For any two sequences $U_1, U_2, \ldots, U_p$ and $V_1, V_2, \ldots, V_q$, we define
Score(U,V)=∑i=1p∑j=1qUi⋅Vj.Score(U,V)=∑i=1p∑j=1qUi⋅Vj.Score(U, V) = \su... | ```python
t = int(input())
l,r,x = 0,0,0
ans = []
for i in range(t):
(n,m) = tuple(map(int,input().split()))
a = list(map(int,input().split()))
b = list(map(int,input().split()))
suma = sum(a)
sumb = sum(b)
q = int(input())
for j in range(q):
l1 = list(map(int,input().split()))
if l1[0] == 1:
l = l1[1]
... | {
"language": "python",
"test_cases": [
{
"input": "1\n3 4\n2 -1 5\n3 3 2 4\n6\n3\n1 2 3 -2\n3\n1 1 3 1\n2 2 4 2\n3\n",
"output": "72\n24\n90\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/ARRQRY"
} | vfc_1562 |
apps | verifiable_code | 681 | Solve the following coding problem using the programming language python:
You are playing following game: given an array A of N natural numbers. All numbers in the array A are at most M. On every turn you may pick any two different elements Ai and Aj (i≠j), such that Ai, Aj ≤ M, and add K to both. The game ends when y... | ```python
from math import ceil
from bisect import bisect_right as b_r
from bisect import bisect_left as b_l
ar = list(map(int , input().split()))
a = [int(ceil((ar[1]-int(x)+1)/ar[2])) for x in input().split()]
s = sum(a)
ar[1] = max(a)
m = ar[1] - (s-ar[1])%2
mi = s%2
print(int( (m-mi)//2 +1)%(10**9+7))
``` | {
"language": "python",
"test_cases": [
{
"input": "3 3 2\n1 2 3\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/RRGAME"
} | vfc_1566 |
apps | verifiable_code | 682 | Solve the following coding problem using the programming language python:
Rohit collects coins: he has exactly one coin for every year from 1 to n. Naturally, Rohit keeps all the coins in his collection in the order in which they were released. Once Rohit's younger brother made a change — he took all the coins whose r... | ```python
n=int(input())
a=list(map(int,input().split()))
l,r=-1,-1
for i in range(n):
if a[i]!=i+1:
l=i
break
for i in range(n-1,-1,-1):
if a[i]!=i+1:
r=i
break
j=r+1
for i in range(l,r+1):
if a[i]==j:
j-=1
continue
else:
print(0,0)
re... | {
"language": "python",
"test_cases": [
{
"input": "8\n1 6 5 4 3 2 7 8\n",
"output": "2 6\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/BRBG2020/problems/PRMA"
} | vfc_1570 |
apps | verifiable_code | 683 | Solve the following coding problem using the programming language python:
-----Problem Statement-----
Write a program that accepts a number, n, and outputs the same.
-----Input-----
The only line contains a single integer.
-----Output-----
Output the answer in a single line.
-----Constraints-----
- 0 ≤ n ≤ 105
--... | ```python
# cook your dish here
a = int(input())
print(a)
``` | {
"language": "python",
"test_cases": [
{
"input": "123\n",
"output": "123\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/START01"
} | vfc_1574 |
apps | verifiable_code | 684 | Solve the following coding problem using the programming language python:
Congratulations !!! You have successfully completed the heist by looting all the gifts in Santa's locker. Now it's time to decide who gets to take all the gifts, you or the Grinch, there will be no splitting. So you and Grinch decide to play a g... | ```python
# cook your dish here
import math
# Function to find the Largest
# Odd Divisor Game to check
# which player wins
def findWinner(n, k):
cnt = 0;
# Check if n == 1 then
# player 2 will win
if (n == 1):
print("Grinch");
# Check if n == 2 or n is odd ... | {
"language": "python",
"test_cases": [
{
"input": "7\n1\n2\n3\n4\n5\n6\n12\n",
"output": "Grinch\nMe\nMe\nGrinch\nMe\nGrinch\nMe\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/NQST2020/problems/WINALL"
} | vfc_1578 |
apps | verifiable_code | 685 | Solve the following coding problem using the programming language python:
You are given an axis-aligned rectangle in a 2D Cartesian plane. The bottom left corner of this rectangle has coordinates (0,0)$(0, 0)$ and the top right corner has coordinates (N−1,N−1)$(N-1, N-1)$. You are also given K$K$ light sources; each l... | ```python
# https://www.codechef.com/problems/RECTLIT
def assess(sq,points):
EWct = 0
NSct = 0
for a,b in points:
EW = (a == 0 or a == sq)
NS = (b == 0 or b == sq)
if EW and NS:
return 'yes'
EWct += EW
NSct += NS
if NSct + EWct == 0 or len... | {
"language": "python",
"test_cases": [
{
"input": "2\n2 10\n0 0\n1 0\n2 10\n1 2\n1 1\n",
"output": "yes\nno\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/RECTLIT"
} | vfc_1582 |
apps | verifiable_code | 686 | Solve the following coding problem using the programming language python:
Chef has been working in a restaurant which has N floors. He wants to minimize the time it takes him to go from the N-th floor to ground floor. He can either take the elevator or the stairs.
The stairs are at an angle of 45 degrees and Chef's... | ```python
n=int(input())
l=[]
for i in range(0,n):
a,b,c=map(int,input().split())
n1=(2**0.5)*(a/b)
n2=2*(a/c)
if n1>n2:
l.append("Elevator")
else:
l.append("Stairs")
for i in l:
print(i)
``` | {
"language": "python",
"test_cases": [
{
"input": "3\n5 10 15\n2 10 14\n7 14 10\n",
"output": "Elevator\nStairs\nStairs\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/ELEVSTRS"
} | vfc_1586 |
apps | verifiable_code | 687 | Solve the following coding problem using the programming language python:
The Little Elephant likes permutations. This time he has a permutation A[1], A[2], ..., A[N] of numbers 1, 2, ..., N.
He calls a permutation A good, if the number of its inversions is equal to the number of its local inversions. The number of i... | ```python
from sys import stdin
t = int(stdin.readline())
def count(n, arr):
loc = 0
glob = 0
for i in range(n-1):
if arr[i] > arr[i+1]:
loc += 1
for i in range(n-1):
for j in range(i+1, n):
if glob > loc:
return 0
if arr[i] > arr[j]:
glob += 1;
if glob == loc:
return 1
return 0
for _ in ... | {
"language": "python",
"test_cases": [
{
"input": "4\n1\n1\n2\n2 1\n3\n3 2 1\n4\n1 3 2 4\n",
"output": "YES\nYES\nNO\nYES\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/COOK28/problems/LEPERMUT"
} | vfc_1590 |
apps | verifiable_code | 689 | Solve the following coding problem using the programming language python:
In africa jungle , there were zebra's who liked to spit.
There owner watched them for whole day and noted in his sheet where each zebra spitted.
Now he's in a confusion and wants to know if in the jungle there are two zebra's which spitted at ea... | ```python
# cook your dish here
t=int(input())
i=0
a=0
d=dict()
while i<t:
l=input().split()
d[int(l[0])]=int(l[0])+int(l[1])
i+=1
for k in d:
if d[k] in d:
if d[d[k]]==k:
a=1
break
if a==1:
print("YES")
else:
print("NO")
``` | {
"language": "python",
"test_cases": [
{
"input": "2\n0 1\n1 -1\n",
"output": "YES\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/CMR12121/problems/ZBJNG"
} | vfc_1598 |
apps | verifiable_code | 690 | Solve the following coding problem using the programming language python:
You are a king and you are at war. If the enemy breaks through your frontline you lose.
Enemy can break the line only if the sum of morale of any $K$ continuous soldiers is strictly less than $M$. So, you being a motivational orator decides to b... | ```python
n,k,m = map(int,input().split())
ar = list(map(int,input().split()))
fsum = [ar[0]]
for i in range(1,n):
fsum.append(fsum[i-1]+ar[i])
i = k
#print(fsum)
c = 0
while i <= n:
if i == k:
s = fsum[i-1]
else:
s = fsum[i-1]-fsum[i-k-1]
if s == 0:
c = -1
break
if s... | {
"language": "python",
"test_cases": [
{
"input": "6 2 5\n1 1 1 1 1 1\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/INTW2020/problems/MORALE99"
} | vfc_1602 |
apps | verifiable_code | 691 | Solve the following coding problem using the programming language python:
You are given a sequence $A_1, A_2, \ldots, A_N$. For each valid $i$, the star value of the element $A_i$ is the number of valid indices $j < i$ such that $A_j$ is divisible by $A_i$.
Chef is a curious person, so he wants to know the maximum sta... | ```python
T = int(input())
for _ in range(T):
n = int(input())
arr = list(map(int, input().split()))
a = [0 for _ in range(max(arr)+1)]
star_val = []
for i in range(len(arr)):
j = 1
val = 0
while j*arr[i] <= len(a):
val += a[j*arr[i]-1]
j += 1
star_val.append(val)
a[arr[i]-1] += 1
print(max(star_v... | {
"language": "python",
"test_cases": [
{
"input": "1\n7\n8 1 28 4 2 6 7\n",
"output": "3\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/MSV"
} | vfc_1606 |
apps | verifiable_code | 692 | Solve the following coding problem using the programming language python:
There is crazy man named P29892P. He always tries to do crazy things as he thinks. One day he invented a machine and named it as ANGEN. The ANGEN is used to perform range operations. The range operation means performing operations on range value... | ```python
VQ = "UAMmSs"
n = int(input())
a = list(map(int, input().split()))
for _ in range(int(input())):
q, x, y = input().split()
if q not in VQ:
print("!!!")
continue
if q == "U":
a[int(x) - 1] = int(y)
continue
l = int(x) - 1
r = int(y)
if q == "A":
print(sum(a[l:r]))
continue
if q == "M":
pri... | {
"language": "python",
"test_cases": [
{
"input": "6\n1 2 5 3 10 6\n6\nA 1 5\nM 1 3\nm 5 6\ns 3 6\nU 1 7\nS 1 2\n",
"output": "21\n5\n6\n5\n2\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/CRES2016/problems/CRES104"
} | vfc_1610 |
apps | verifiable_code | 693 | Solve the following coding problem using the programming language python:
Write a program to find the factorial value of any number entered by the user.
-----Input-----
The first line contains an integer T, the total number of testcases. Then T lines follow, each line contains an integer N.
-----Output-----
For ea... | ```python
# cook your dish here
x=int(input())
for i in range(x):
s=int(input())
fact=1
for i in range(1,s+1):
fact=fact*i
print(fact)
``` | {
"language": "python",
"test_cases": [
{
"input": "3\n3\n4\n5\n",
"output": "6\n24\n120\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/FLOW018"
} | vfc_1614 |
apps | verifiable_code | 694 | Solve the following coding problem using the programming language python:
The MarkiT online virtual market startup wants to organize its grand opening in NIT Patna.
but they want maximum crowd for their inauguration. So the manager told this to Praveen a student in NITP who suggested them:
The first-year students co... | ```python
import math
def fun(num1,num2):
if num1>num2:
a=num1
b=num2
else:
a=num2
b=num1
rem=a%b
while(rem!=0):
a=b
b=rem
rem=a%b
gcd=b
return (int((num1*num2)/gcd))
for _ in range (int(input())):
hours=int(input())*24
x,y,z=list(map(int,input().split()))
lcm=x
lcm=fun(x,y)
lcm=fun(lcm,z)
... | {
"language": "python",
"test_cases": [
{
"input": "1\n10\n8 10 6\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/STRT2020/problems/CRWDCN"
} | vfc_1618 |
apps | verifiable_code | 695 | Solve the following coding problem using the programming language python:
You are given three non-negative integers $X$, $Y$ and $N$. Find the number of integers $Z$ such that $0 \le Z \le N$ and $(X \oplus Z) < (Y \oplus Z)$, where $\oplus$ denotes the bitwise XOR operation.
-----Input-----
- The first line of the i... | ```python
# cook your dish here
tc=int(input())
for j in range(tc):
ip=list(map(int,input().rstrip().split()))
x=ip[0]
y=ip[1]
n=ip[2]
cnt=0
if(x==y):
print('0')
continue
ln=bin(x).replace("0b", "")
rn=bin(y).replace("0b", "")
ll=len(ln)
rl=len(rn)
#print(ln)
#print(rn)
if(ll==len(rn)):
for i in ra... | {
"language": "python",
"test_cases": [
{
"input": "3\n1 2 10\n2 1 10\n0 0 7\n",
"output": "6\n5\n0\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/XORCOMP"
} | vfc_1622 |
apps | verifiable_code | 696 | Solve the following coding problem using the programming language python:
You are given a permutation of natural integers from 1 to N, inclusive. Initially, the permutation is 1, 2, 3, ..., N.
You are also given M pairs of integers, where the i-th is (Li Ri). In a single turn you can choose any of these pairs (let's s... | ```python
t=int(input())
for _ in range(t):
n,m=list(map(int,input().split()))
l=list(map(int,input().split()))
k=[]
for i in range(m):
a,b=list(map(int,input().split()))
k.append([a,b])
k.sort()
c=[]
flag=1
x=k[0][0]
y=k[0][1]
for i in k[1:]:
if i[0]<=y:
y=max(y,i[1])
else:
c.append([x-1,y-1]... | {
"language": "python",
"test_cases": [
{
"input": "2\n7 4\n3 1 2 4 5 7 6\n1 2\n4 4\n6 7\n2 3\n4 2\n2 1 3 4\n2 4\n2 3\n",
"output": "Possible\nImpossible\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/PERMSUFF"
} | vfc_1626 |
apps | verifiable_code | 698 | Solve the following coding problem using the programming language python:
For years you have been working hard in Santa's factory to manufacture gifts for kids in substandard work environments with no pay. You have finally managed to escape the factory and now you seek revenge. You are planning a heist with the Grinch... | ```python
import math
t = int(input())
def phi(n):
res = n
i = 2
while i*i<=n:
if n%i==0:
res/=i
res*=(i-1)
while n%i==0:
n/=i
i+=1
if n>1:
res/=n
res*=(n-1)
return int(res)
while t:
a,m = list(map(int,input().split()))
g = math.gcd(a,m)
print(phi(m//g))
t-=1
``` | {
"language": "python",
"test_cases": [
{
"input": "3\n4 9\n5 10\n42 9999999967\n",
"output": "6\n1\n9999999966\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/NQST2020/problems/HEIST101"
} | vfc_1634 |
apps | verifiable_code | 699 | Solve the following coding problem using the programming language python:
Chef wants to host some Division-3 contests. Chef has $N$ setters who are busy creating new problems for him. The $i^{th}$ setter has made $A_i$ problems where $1 \leq i \leq N$.
A Division-3 contest should have exactly $K$ problems. Chef wa... | ```python
for T in range(int (eval(input()))):
N,K,D=list(map(int,input().split()))
A=list(map(int,input().split()))
P=sum(A)//K
print(min(P,D))
``` | {
"language": "python",
"test_cases": [
{
"input": "5\n1 5 31\n4\n1 10 3\n23\n2 5 7\n20 36\n2 5 10\n19 2\n3 3 300\n1 1 1\n",
"output": "0\n2\n7\n4\n1\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/DIVTHREE"
} | vfc_1638 |
apps | verifiable_code | 700 | Solve the following coding problem using the programming language python:
Now-a-days, Manish is becoming famous for bank robbery in the country because of his cleverness, he never robs own his own.He has four workers A , B, C, and D , all working under him.All of the four take some amount for that. There are total N ... | ```python
for t in range(int(input())):
n = int(input())
l = []
m = []
x = list(map(int,input().split()))
l.append(x)
m.append(list(x))
for i in range(1,n):
x = list(map(int,input().split()))
l.append(x)
temp = []
for i in range(4):
temp.append (x[i]+min(m[-1][:i]+m[-1][i+1:]))
m.append(temp)
print... | {
"language": "python",
"test_cases": [
{
"input": "1\n3\n4 7 2 9\n5 6 4 7\n2 6 4 3\n",
"output": "10\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/ICOD2016/problems/ICODE16D"
} | vfc_1642 |
apps | verifiable_code | 701 | Solve the following coding problem using the programming language python:
You are given a sequence of N$N$ powers of an integer k$k$; let's denote the i$i$-th of these powers by kAi$k^{A_i}$. You should partition this sequence into two non-empty contiguous subsequences; each element of the original sequence should app... | ```python
# cook your dish here
def main():
for _ in range(int(input())):
N, k = [int(x) for x in input().split()]
Powers = [k ** int(x) for x in input().split()]
s1, s2 = 0, sum(Powers)
ans = (0, None)
i = 0
while i < N - 1:
s1 += Powers[i]
s2 -= Powers[i]
... | {
"language": "python",
"test_cases": [
{
"input": "1\n5 2\n1 1 3 3 5\n",
"output": "4\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/MXM"
} | vfc_1646 |
apps | verifiable_code | 702 | Solve the following coding problem using the programming language python:
This is a peculiar functioning setup.
Two Tanks are separated from each other by a wall .There is a pipe in the wall which connects both tanks which allows flow of water between them . Due to this ,there is change in temperature of both tanks ... | ```python
for i in range(int(input())):
m,tc,th=map(int,input().split())
x=(th-tc)
if x%3!=0:
print("Yes")
else:
if (x//3)<=m:
print("No")
else:
print("Yes")
``` | {
"language": "python",
"test_cases": [
{
"input": "2\n4 5 10\n2 2 5\n",
"output": "Yes\nNo\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/COCA2020/problems/HOTNCOLD"
} | vfc_1650 |
apps | verifiable_code | 703 | Solve the following coding problem using the programming language python:
Chef gives an integer $K$ in the input. If the given number is beautiful binary number, print it, Else find its previous beautiful binary number. A beautiful binary number is a number whose binary representation does not contain any consecutive... | ```python
pref = []
for i in range(10 ** 5 + 10):
b = bin(i)[2:]
if not any(b[j] == b[j+1] == '1' for j in range(len(b) - 1)):
pref.append(i)
else:
pref.append(pref[-1])
for i in range(int(input())):
print(pref[int(input())])
``` | {
"language": "python",
"test_cases": [
{
"input": "3\n3\n6\n8\n",
"output": "2\n5\n8\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/PBK02020/problems/ITGUY10"
} | vfc_1654 |
apps | verifiable_code | 704 | Solve the following coding problem using the programming language python:
Eugene has to do his homework. But today, he is feeling very lazy and wants to you do his homework. His homework has the following given maths problem.
You are given three integers: A, N, M. You write the number A appended to itself N times in a... | ```python
# cook your dish here
for _ in range(int(input())):
a,n,m = map(int,input().split(' '))
s = len(str(a))
#print(s)
c = 10**s - 1
w = c*m
b = pow(10,n*s,w)-1
d = b//c
ans = (d%m)*(a%m)
print(ans%m)
``` | {
"language": "python",
"test_cases": [
{
"input": "2\n12 2 17\n523 3 11\n\n\n",
"output": "5\n6\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/KBIGNUMB"
} | vfc_1658 |
apps | verifiable_code | 705 | Solve the following coding problem using the programming language python:
A city of dimension N x N is constructed with grid of lanes. These lanes are fenced by government so that no one can cross any grid diagonally. Although a train
line runs diagonally from (0,0) to (N,N).
Our chef has a weird kind of phobia and i... | ```python
ar = []
ar.append(1)
for i in range(1, 31):
ar.append(ar[i-1]*(4*i-2)/(i+1))
t = int(input())
while(t>0):
n = int(input())
if(n==0):
print(0)
else:
print(ar[n]*2)
t=t-1
``` | {
"language": "python",
"test_cases": [
{
"input": "2\n2\n5\n",
"output": "4\n84\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/ALGT2013/problems/TNMALG02"
} | vfc_1662 |
apps | verifiable_code | 706 | Solve the following coding problem using the programming language python:
Chef has $N$ small boxes arranged on a line from $1$ to $N$. For each valid $i$, the weight of the $i$-th box is $W_i$. Chef wants to bring them to his home, which is at the position $0$. He can hold any number of boxes at the same time; however... | ```python
t=int(input())
for i in range(t):
x,y=0,0
n,m=list(map(int,input().split()))
l=list(map(int,input().split()))
if(max(l)>m):
print(-1)
else:
for i in range(len(l)):
y+=l[i]
if(y>m):
y=l[i]
x+=1
if(y>0):
x+=1
print(x)
``` | {
"language": "python",
"test_cases": [
{
"input": "4\n1 1\n2\n2 4\n1 1\n3 6\n3 4 2\n3 6\n3 4 3\n",
"output": "-1\n1\n2\n3\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/CHEFNWRK"
} | vfc_1666 |
apps | verifiable_code | 708 | Solve the following coding problem using the programming language python:
You are given a square matrix $M$ with $N$ rows (numbered $1$ through $N$) and $N$ columns (numbered $1$ through $N$). Initially, all the elements of this matrix are equal to $A$. The matrix is broken down in $N$ steps (numbered $1$ through $N$)... | ```python
# cook your dish here
for _ in range(int(input())):
n,k = list(map(int,input().split()))
mod = 10**9+7
s=0
for i in range(1,n+1):
p = pow(k,(2*i)-1,mod)
# print(p)
s=(s+p)%mod
# print(k)
k = (p*k)%mod
print(s)
``` | {
"language": "python",
"test_cases": [
{
"input": "1\n3 2\n",
"output": "511620149\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/MATBREAK"
} | vfc_1674 |
apps | verifiable_code | 709 | Solve the following coding problem using the programming language python:
$Gogi$, $Tapu$ and $Sonu$ are the elite members of $Tapu$ $Sena$. $Gogi$ is always stoned and asks absurd questions, But this time he asked a question which seems to be very serious and interesting. $Tapu$ wants to solve this question to impress... | ```python
# cook your dish here
try:
t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
gcd = max(a[0], a[-1])
print(gcd)
except EOFError:pass
``` | {
"language": "python",
"test_cases": [
{
"input": "1\n1\n2\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/CORE2020/problems/CORE2002"
} | vfc_1678 |
apps | verifiable_code | 710 | Solve the following coding problem using the programming language python:
Blob is a computer science student. He recently got an internship from Chef's enterprise. Along with the programming he has various other skills too like graphic designing, digital marketing and social media management. Looking at his skills Che... | ```python
def maxval(arr):
fn = [float('-inf')]*(len(arr)+1)
sn = [float('-inf')]*len(arr)
tn = [float('-inf')]*(len(arr)-1)
fon = [float('-inf')]*(len(arr)-2)
for i in reversed(list(range(len(arr)))):
fn[i] = max(fn[i + 1], arr[i])
for i in reversed(list(range(len(arr) - 1))):
s... | {
"language": "python",
"test_cases": [
{
"input": "6\n3 9 10 1 30 40\n",
"output": "46\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/WNTR2020/problems/WC04"
} | vfc_1682 |
apps | verifiable_code | 711 | Solve the following coding problem using the programming language python:
The notorious hacker group "Sed" managed to obtain a string $S$ from their secret sources. The string contains only lowercase English letters along with the character '?'.
A substring of $S$ is a contiguous subsequence of that string. For exampl... | ```python
def convertToParitys(s):
"""
This converts the string s to an int, which is a bitMap of the parity of each letter
odd ? = first bit set
odd a = second bit set
odd b = third bit set
etc
"""
keys = '?abcdefghijklmnopqrstuvwxyz'
paritys = {c:0 for c in keys}
for... | {
"language": "python",
"test_cases": [
{
"input": "5\naa?\na???\n????\nasfhaslskfak\naf??avvnfed?fav?faf????\n\n",
"output": "2\n6\n4\n2\n27\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/SEDPASS"
} | vfc_1686 |
apps | verifiable_code | 712 | Solve the following coding problem using the programming language python:
Chef got into a fight with the evil Dr Doof. Dr Doof has decided to destroy all even numbers from the universe using his Evil-Destroy-inator. Chef has $N$ integers with him. To stop Doof, Chef has to find an odd number which is an integer multip... | ```python
def gcd(a,b):
if b==0: return a
return gcd(b,a%b)
for _ in range(int(input())):
n = int(input())
arr = list(map(int,input().split()))
value = arr[0]
if n!=1:
for i in arr[1:]:
value = value*i//gcd(value, i)
if value%2==0:
print("NO")
else:
print("YES")
``` | {
"language": "python",
"test_cases": [
{
"input": "2\n5\n1 2 5 4 3\n1\n7\n",
"output": "NO\nYES\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/COLE2020/problems/CLLCM"
} | vfc_1690 |
apps | verifiable_code | 715 | Solve the following coding problem using the programming language python:
Recently Rocky had participated in coding competition and he is sharing one of the problem with you which he was unable to solve. Help Rocky in solving the problem.
Suppose the alphabets are arranged in a row starting with index 0$0$ from AtoZ$A... | ```python
# cook your dish here
s = input().strip()
start_w = 27
w_dict = {}
words = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]
for word in words:
w_dict[word] = start_w
start_w = start_w - 1
total_wt = 0
for c in s:
to... | {
"language": "python",
"test_cases": [
{
"input": "A\nAND\n",
"output": "27\n65\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/CFUN2020/problems/CODSTAN6"
} | vfc_1702 |
apps | verifiable_code | 716 | Solve the following coding problem using the programming language python:
Chef has created a special dividing machine that supports the below given operations on an array of positive integers.
There are two operations that Chef implemented on the machine.
Type 0 Operation
Update(L,R):
for i = L to R:
a[i] = a[i] /... | ```python
import math
n=1001
a=[True]*n
l=[]
for i in range(2,33):
if(a[i]):
for j in range(i*i,n,i):
a[j]=False
for pr in range(2,1001):
if(a[pr]):
l.append(pr)
t=int(input())
for j in range(t):
n,m=list(map(int,input().strip().split()))
arr=[int(num) for num in input().strip().split()]
Matrix =[]
index=[... | {
"language": "python",
"test_cases": [
{
"input": "2\n6 7\n2 5 8 10 3 44\n1 2 6\n0 2 3\n1 2 6\n0 4 6\n1 1 6\n0 1 6\n1 4 6\n2 2\n1 3\n0 2 2\n1 1 2\n",
"output": "5 3 5 11\n1\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/SEPT16/problems/DIVMAC"
} | vfc_1706 |
apps | verifiable_code | 717 | Solve the following coding problem using the programming language python:
Today is rose day, batch mates of Kabir and Tara decided to celebrate this day by exchanging roses with each other.
Note:$Note:$ exchanging means both the boy and the girl will give rose to each other.
In the class there are B$B$ boys and G$G$... | ```python
for i in range(int(input())):
print(2*(sum(list(map(int, input().split())))-1))
``` | {
"language": "python",
"test_cases": [
{
"input": "1\n2 3\n",
"output": "8\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/HECS2020/problems/CC001"
} | vfc_1710 |
apps | verifiable_code | 719 | Solve the following coding problem using the programming language python:
-----Problem-----
Suppose there is a circle. There are N Juice shops on that circle. Juice shops are numbered 0 to N-1 (both inclusive). You have two pieces of information corresponding to each of the juice shop:
(1) the amount of Juice that a ... | ```python
import re,sys
def isCirlePossible(juices,distances):
if juices == [] or distances == []:
return -1;
total_juice_consumed = 0
juice_consumed = 0
start=0
for i in range(0,len(juices)):
diff = juices[i] - distances[i]
if juice_consumed >= 0:
juice_consumed += diff
else:
juice_consumed = diff
... | {
"language": "python",
"test_cases": [
{
"input": "3\n1 5\n10 3\n3 4\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/COMN2016/problems/SUMTOUR"
} | vfc_1718 |
apps | verifiable_code | 720 | Solve the following coding problem using the programming language python:
All strings in Chefland are beautiful because they are binary strings (a binary string contains only characters '0' and '1'). The beauty of a binary string $S$ is defined as the number of pairs $(i, j)$ ($1 \le i \le j \le |S|$) such that the su... | ```python
t = int(input())
for _ in range(t):
s = input()
pref = [0]*len(s)
if s[0]=="1":
pref[0]+=1
for i in range(1,len(s)):
if s[i]=="1":
pref[i]+=1
pref[i]=pref[i]+pref[i-1]
k=1
cnt=0
while (k+k*k)<=len(s):
r = k+k*k
i=r-1
while i<len(s):
if (i-r)>=0:
if pref[i]-pref[i-r]==k:
cnt+=... | {
"language": "python",
"test_cases": [
{
"input": "2\n010001\n10\n",
"output": "4\n1\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/BDGFT"
} | vfc_1722 |
apps | verifiable_code | 722 | Solve the following coding problem using the programming language python:
The kingdom of the snakes is an NxN grid. Their most-valued possession is a huge collection of poison, which is stored in the central KxK grid. It is guaranteed that both N and K are odd. What we mean by 'central' is this: suppose in the NxN gri... | ```python
'''input
2
7 3 5
5 2 5 2
2 4 2 6
6 2 6 4
5 6 5 7
7 1 7 4
7 3 7
1 1 6 1
1 2 3 2
5 2 5 2
2 6 2 6
6 2 6 4
5 6 5 7
7 1 7 4
'''
for _ in range(int(input())):
n, k, m = list(map(int, input().split()))
row_s = []
col_s = []
for _ in range(m):
h_x, h_y, t_x, t_y = list(map(int, input().split()))
if h_x == t_... | {
"language": "python",
"test_cases": [
{
"input": "2\n7 3 7\n1 1 6 1\n1 2 3 2\n5 2 5 2\n2 4 2 6\n6 2 6 4\n5 6 5 7\n7 1 7 4\n7 3 7\n1 1 6 1\n1 2 3 2\n5 2 5 2\n2 6 2 6\n6 2 6 4\n5 6 5 7\n7 1 7 4\n",
"output": "3\n-1\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/PROTEPOI"
} | vfc_1730 |
apps | verifiable_code | 723 | Solve the following coding problem using the programming language python:
In this problem, you will be given a polynomial, you have to print what it becomes after differentiation.
Following are the rules for differentiation:
- For a polynomial f(x), its differentiation is defined as f'(x).
- If a is a constant, then ... | ```python
def ans(l):
s = ""
i = 0
while (i < len(l)):
temp = l[i]
k = temp[1]
if (k != 0):
s += str(temp[0]) + "x^" + str(k)
else:
s += str(temp[0])
i += 1
if (i < len(l)):
s += " + "
if (len(s) > 0):
return s
else:
return "0"
test = int(input())
while (test != 0):
test -= 1
N = int(i... | {
"language": "python",
"test_cases": [
{
"input": "2\n1\n1 2\n3\n1 3\n1 1\n1 0\n",
"output": "2x^1\n3x^2 + 1\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/LOCFEB16/problems/POLYDIFR"
} | vfc_1734 |
apps | verifiable_code | 724 | Solve the following coding problem using the programming language python:
Petya is preparing a problem for a local contest in his school. The problem is to find a longest increasing subsequence in a given permutation. A permutation of size n$n$ is a sequence of n$n$ numbers a1,…,an$a_1, \ldots, a_n$ such that every nu... | ```python
# cook your dish here
for _ in range(int(input())):
n,k = [int(c) for c in input().split()]
a = [int(c) for c in input().split()]
ls = a
if n==1:
print("YES")
print(1)
continue
if k==1:
print("NO")
continue
if k==2 and n>2:
if ls[0]!... | {
"language": "python",
"test_cases": [
{
"input": "2\n3 2\n1 2\n2 1\n1\n",
"output": "YES\n2 3 1\nNO\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/INVLIS"
} | vfc_1738 |
apps | verifiable_code | 725 | Solve the following coding problem using the programming language python:
The Little Elephant and his friends from the Zoo of Lviv were returning from the party. But suddenly they were stopped by the policeman Big Hippo, who wanted to make an alcohol test for elephants.
There were N elephants ordered from the left to ... | ```python
def magic():
def check(art,k,m):
n=len(art)
for i in range(n-k+1):
maxi=0
maxi=max(art[i:i+k])
total=0
total=art[i:i+k].count(maxi)
if total>=m:
return False
return True
for _ in range(eval(input())):
n,k,m=list(map(int,input().split()))
arr=list(map(int,input().split())... | {
"language": "python",
"test_cases": [
{
"input": "4\n5 3 2\n1 3 1 2 1\n5 3 3\n7 7 7 7 7\n5 3 3\n7 7 7 8 8\n4 3 1\n1 3 1 2\n",
"output": "0\n1\n1\n-1\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/LEALCO"
} | vfc_1742 |
apps | verifiable_code | 726 | Solve the following coding problem using the programming language python:
Today, Chef decided to cook some delicious meals from the ingredients in his kitchen. There are $N$ ingredients, represented by strings $S_1, S_2, \ldots, S_N$. Chef took all the ingredients, put them into a cauldron and mixed them up.
In the ca... | ```python
# cook your dish here
t=int(input())
while t>0:
n=int(input())
li=[]
c,o,d,e,h,f=0,0,0,0,0,0
for i in range(0,n):
s=input()
for i in range(len(s)):
if s[i]=='c':
c=c+1
elif s[i]=='o':
o=o+1
elif s[i]=='d':
d=d+1
elif s[i]=='e':
e=e+1
elif s[i]=='h':
h=h+1
elif ... | {
"language": "python",
"test_cases": [
{
"input": "3\n6\ncplusplus\noscar\ndeck\nfee\nhat\nnear\n5\ncode\nhacker\nchef\nchaby\ndumbofe\n5\ncodechef\nchefcode\nfehcedoc\ncceeohfd\ncodechef\n",
"output": "1\n2\n5\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/CFMM"
} | vfc_1746 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.