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 | 886 | Solve the following coding problem using the programming language python:
Chef is playing a game with his childhood friend. He gave his friend a list of N numbers named $a_1, a_2 .... a_N$ (Note: All numbers are unique). Adjust the numbers in the following order:
$(i)$ swap every alternate number with it's succeeding... | ```python
for _ in range(int(input())):
n=int(input())
a=list(map(int,input().split()))
x=int(input())
for _ in range(1,n,2):
a[_],a[_-1]=a[_-1],a[_]
for _ in range(n):
a[_]+=(a[_]%3)
# a=a[::-1]
# a.sort()
# if x>a[-1]:
# print(-1)
# continue
l,h=-1,9... | vfc_2386 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/ENDE2020/problems/ENCDEC5",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n10\n5 15 1 66 55 32 40 22 34 11\n38\n",
"output": "35 41\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 887 | Solve the following coding problem using the programming language python:
Arya and Aryan live in a country called Nadaca. Nadaca consists of $N$ cities numbered $1$ through $N$, which are connected by some bidirectional roads. Each road has a positive (not necessarily integer) length. Arya lives in city $1$ and Aryan ... | ```python
# cook your dish here
# cook your dish here
for _ in range(int(input())):
n=int(input())
a=list(map(int, input().split()))
b=list(map(int, input().split()))
if a[0]!=0 or b[-1]!=0 or a[-1]!=b[0]:
print('No')
else:
ab=b[0]
flag=0
for i in range(1, n-1):
if a[i]==0 or b[i]==0:
print('No'... | vfc_2390 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/DIS",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n3\n0 1 1\n1 1 0\n3\n0 1 5\n5 1 0\n",
"output": "Yes\nNo\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 888 | Solve the following coding problem using the programming language python:
Cherry has a string S$S$ consisting of lowercase English letters. Using this string, he formed a pyramid of infinite length with certain rules:
- N$N$-th row of pyramid contains N$N$ characters.
- Each row of pyramid begins with the first charac... | ```python
def search(arr, lenl, val):
s = 0
l = lenl - 1
total = 0
while (s <= l):
m = int((s + l) / 2)
if (arr[m] <= val):
total = m + 1
s = m + 1
else:
l = m - 1
return total
def kmpsearch(string, lps):
lis ... | vfc_2394 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/CENS20C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "codechef\nchefcode\n3\n4\n12\n1455\n",
"output": "0\n1\n181\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 889 | Solve the following coding problem using the programming language python:
Chef is a brilliant university student that does not attend lectures because he believes that they are boring and coding is life! However, his university follows certain rules and regulations, and a student may only take an exam for a course if ... | ```python
# cook your dish here
def ceil(num):
if num%1==0:
return int(num//1)
else:
return int((num//1)+1)
for _ in range(int(input())):
n=int(input())
s=input()
p=0
a=[]
for i in range(n):
if s[i]=="P":
p=p+1
req=ceil(0.75*n)
requirement=req-p
for i in range(2,n-2):
if s[i]=="A":
if (s[i-1]=... | vfc_2398 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/PROXYC",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n9\nPAAPPAPPP\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 890 | Solve the following coding problem using the programming language python:
Snakeland is a well organised city. The houses of the city are organised in an orderly rectangular fashion with dimensions 2 * n, i.e. there are total two rows and n columns. The house in the i-th row and j-th column is also said to be the house... | ```python
# cook your dish here
t=int(input())
while t:
n=int(input())
r1=input()
r2=input()
r1count=0
r2count=0
count=0
for i in range(n):
if(r1[i]=="*"):
r1count+=1
if(r2[i]=="*"):
r2count+=1
if(r1count>0) and (r2count>0):
count=1
r1count=0
r2count=0
i=0
while(i<n):
if(r1[i]=="*"):
... | vfc_2402 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/SNCOUP",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n2\n**\n**\n3\n***\n*..\n3\n*..\n.*.\n",
"output": "2\n3\n1\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 891 | Solve the following coding problem using the programming language python:
Andrii is good in Math, but not in Programming. He is asking you to solve following problem: Given an integer number N and two sets of integer A and B. Let set A contain all numbers from 1 to N and set B contain all numbers from N + 1 to 2N. Mul... | ```python
# cook your dish here
import math;
from math import gcd,sqrt,floor,factorial,ceil
from bisect import bisect_left,bisect_right
import bisect;
import sys;
from sys import stdin,stdout
import os
sys.setrecursionlimit(pow(10,7))
import collections
from collections import defaultdict,Counter
from statistics import... | vfc_2406 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/RRSUM",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 5\n6\n2\n9\n7\n5\n\n",
"output": "2\n0\n1\n3\n1\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 892 | Solve the following coding problem using the programming language python:
There are $N$ cells numbered 1,2,….., N, and every cell has some positive value. you will be given an array $A_1$,$A_2$,…,$A_N$ where $A_i$ is the value of $ith$ cell and an integer $K$.
There is a monkey who wants to reach the $right$ side of t... | ```python
from sys import setrecursionlimit
setrecursionlimit(10 * 9)
def solve(i):
if i + k >= n:
return 1
if i in dp:
return dp[i]
mini = float('inf')
for j in range(i+1, min(n, i+k+1)):
if i == -1 or a[i] == a[j]:
mini = min(mini, solve(j) + 1)
... | vfc_2410 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/BIT32020/problems/BIT3D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n2 2\n3 4\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 893 | Solve the following coding problem using the programming language python:
Given an array of size N$N$ and two integers K$K$ and S$S$, the special sum of a subarray is defined as follows:
(Sum of all elements of the subarray) * (K$K$ - p$p$ * S$S$)
Where p$p$ = number of distinct prime factors of “product of all elem... | ```python
# cook your dish here
from math import floor, sqrt
try:long
except NameError:long = int
def fac(n):
step,maxq,d = lambda x: 1 + (x<<2) - ((x>>1)<<1),long(floor(sqrt(n))),1
q = n % 2 == 0 and 2 or 3
while q <= maxq and n % q != 0:
q = step(d)
d += 1
return q <= maxq and [q] + fac(n/... | vfc_2414 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/MAXSPSUM",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 10 2\n14 2 7 15\n",
"output": "138\nSample\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 894 | Solve the following coding problem using the programming language python:
Chef recently developed an affinity for undirected graphs.
He likes pairs of graphs that are similar in structure.
However, Chef discovered that when the vertices of a graph are reorganized, it's often the case that the resulting graph,
although... | ```python
import random
t=int(input())
for testCase in range(t):
n=int(input())
array1=[]
array2=[]
array=[]
for i in range(n) :
array1.append(list(map(int,input().split())))
for i in range(n) :
array2.append(list(map(int,input().split())))
for i in range(n) :
array.append(i)
# print array2," ",array1
... | vfc_2418 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/APRIL12/problems/SIMGRAPH",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n3\n0 1 0\n1 0 0\n0 0 0\n0 0 1\n0 0 1\n1 1 0\n4\n0 0 1 0\n0 0 0 0\n1 0 0 1\n0 0 1 0\n0 0 1 1\n0 0 0 0\n1 0 0 0\n1 0 0 0\n\n",
"output": "1 2 3\n1 2 3\n1 4 2 3\n2 4 1 3\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 895 | Solve the following coding problem using the programming language python:
Zonal Computing Olympiad 2012, 26 Nov 2011
It's dinner time in Castle Camelot, and the fearsome Knights of the Round Table are clamouring for dessert. You, the chef, are in a soup. There are N knights, including King Arthur, each with a differ... | ```python
n=int(input())
ar=list(map(int,input().split()))
dp=[0]*n
dp[0]=ar[0]
dp[1]=ar[1]
for i in range(2,n):
dp[i]=min(dp[i-2],dp[i-1])+ar[i]
ar.reverse()
#print(ar)
dp1=[0]*n
dp1[0]=ar[0]
dp1[1]=ar[1]
for i in range(2,n):
dp1[i]=min(dp1[i-2],dp1[i-1])+ar[i]
print(min(dp[-1],dp1[-1]))
... | vfc_2422 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/ZCOPRAC/problems/ZCO12004",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1 2 1 2 2\n",
"output": "4\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 896 | Solve the following coding problem using the programming language python:
-----Problem Statement-----
Chef has a sequence of N segments: [L1, R1], [L2, R2], ..., [LN, RN]. He wants to transform the first segment to the last one (with index N). His plan is to do this big deal with a number of transformations: firstly h... | ```python
for tc in range(int(input())):
N = int(input())
a, b = list(map(int, input().split()))
pr = []
# 'L' is lexicographically lower than 'R'.
# so, we should first try to apply L+ or L-
# if we can't then only we'll try to apply R+ or R-
for i in range(N - 1):
l, r = list(map(int, input().split()))
... | vfc_2426 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/GERALD03",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n3\n-1 0\n0 1\n3 5\n1\n0 1\n3\n-2 -1\n-2 -1\n-2 0\n4\n4 6\n3 5\n-1 1\n1 2\n",
"output": "9\nR+L+R+L+R+L+R+L+R+\n0\n1\nR+\n13\nL-R-L-L-L-L-R-R-R-R-L+R+L+\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 897 | Solve the following coding problem using the programming language python:
Chef had an array A with length N, but some of its elements got lost. Now, each element of this array is either unknown (denoted by -1) or a positive integer not exceeding K.
Chef decided to restore the array A by replacing each unknown element ... | ```python
# cook your dish here
# cook your dish here
MOD = 10 ** 9 + 7
for t in range(int(input())):
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
I, D = [0] * (N + 2), [0] * (N + 2)
for i in range(M):
x, L, R = input().split()
L, R = int(L), int(R)
i... | vfc_2430 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/CO92REST",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n4 2 10\n2 3 5 4\nI 1 2\nD 3 4\n5 2 10\n-1 -1 -1 -1 -1\nI 1 3\nD 3 5\n6 2 2\n-1 -1 -1 -1 -1 -1\nI 1 4\nD 4 6\n",
"output": "1\n8\n0\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 898 | Solve the following coding problem using the programming language python:
Note : This question carries $150$ $points$
There is an outcry in Middle Earth, as the greatest war between Orgs of Dark Lord Sauron and Frodo Baggins is about to begin. To end the war, Frodo decides to destroy the ring in the volcano of Mordor.... | ```python
# cook your dish here
from math import pow
t = int(input())
for _ in range(t):
m,n = map(int,input().rstrip().split())
cnt = len(str(n))
x = pow(10,cnt)
if n == x-1:
print(m*cnt,m)
else:
print(m*(cnt-1),m)
``` | vfc_2434 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/PCO12020/problems/LOTR1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n1 9\n",
"output": "1 1\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 899 | Solve the following coding problem using the programming language python:
Chef wants to teach a lesson of sharing to the students.
There are $N$ students (numbered from $1$ to $N$ from left to right) who are asked to stand in a row. Initially Chef gave $A$$i$ candies to the $i$$th$ child. In one operation any child ca... | ```python
from math import ceil
for _ in range(int(input())):
n = int(input())
arr = [int(x) for x in input().split()]
sarr = sum(arr)
mavg = sarr/n
while n>1:
sarr -= arr.pop()
n-=1
mavg = max(mavg, sarr/n)
print(int(ceil(mavg)))
``` | vfc_2438 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/CROS2020/problems/COCR106",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n5\n1 2 3 4 5\n5\n5 4 3 2 1\n",
"output": "3\n5\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 900 | Solve the following coding problem using the programming language python:
On her way to ChefLand, Marichka noticed $10^K$ road signs (numbered $0$ through $10^K - 1$). For each valid $i$, the sign with number $i$ had the integer $i$ written on one side and $10^K-i-1$ written on the other side.
Now, Marichka is wonderi... | ```python
import math
t=int(input())
for i in range(t):
k=int(input())
res=((pow(2,k,1000000007))*5)%1000000007
print(res)
``` | vfc_2442 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/RSIGNS",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n1\n\n",
"output": "10\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 901 | Solve the following coding problem using the programming language python:
Sereja have array A' that contain N integers. Now Sereja want to permute elements of the array, he want to use some permutation p, such that A[i] = A'[p[i]], where A - new array.
Lets function f(A,i) = S - A[i] - A[i +1] - ... - A[j], where j ... | ```python
# Md. Khairullah Gaurab
# SUST, CSE, 20th Batch
# [email protected]
test = int(input());
for i in range(test):
N, S, K = list(map(int,input().split()));
lis = list(map(int,input().split()));
ans = [i+1 for i in range(N)] ;
ans.sort(reverse=True);
for j in range(N):
prin... | vfc_2446 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/APRIL14/problems/SEAPERM",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n3 2 4\n3 4 1\n4 4 1\n1 1 1 1\n\n\n",
"output": "2 1 3\n4 3 2 1\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 902 | Solve the following coding problem using the programming language python:
Tweedle-Dee and Tweedle-Dum are playing a fierce match of binary Nim. This novel game is played with $N$ stacks, each of them containing only $1$-s and $0$-s.
Just like in normal Nim, Tweedle-Dee and Tweedle-Dum alternate turns; in their turn, a... | ```python
for u in range(int(input())):
p=input().split()
n=int(p[0])
s=p[1]
x,y=0,0
for i in range(n):
l=input()
if(l[0]=='1'):
y+=l.count('1')
else:
x+=l.count('0')
if(x<y):
print("Dum")
elif(y<x):
print("Dee")
else:
if(s=='Dee'):
print("Dum")
else:
print("Dee")
``` | vfc_2450 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/BINIM",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n2 Dee\n101\n010\n2 Dum\n101\n010\n",
"output": "Dum\nDee\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 903 | Solve the following coding problem using the programming language python:
Kabir likes Tara's smile and wants to look at her smile. They are sitting in the class and you are friends with Kabir. You have to place a mirror (point size) in the front wall of the class so that Kabir can have a glimpse of Tara's smile.
Cons... | ```python
# cook your dish here
try:
t = int(input())
for _ in range(t):
p = [int(x) for x in input().split()]
q = [int(x) for x in input().split()]
q[1] *= -1
m = (q[1]-p[1])/(q[0]-p[0])
c = p[1] - m*p[0]
print("{:.2f}".format(-c/m))
except:
... | vfc_2454 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/HECS2020/problems/CC000",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n1 1\n4 4\n",
"output": "1.60\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 904 | Solve the following coding problem using the programming language python:
The most dangerous cyborg Jenish is finally entrapped on a narrow bridge over a valley. The bridge is $N$ meters long. For convenience, position $i$ represents a portion of bridge between whose left border is at distance $i-1$ meters from left e... | ```python
# cook your dish here
import bisect
for _ in range(int(input())):
n,x=list(map(int,input().split()))
l=list(map(int,input().split()))
battery=[]
power=0
i=0
t=(n+1)//2
while power<x and i<t:
if i==n-i-1:
temp=[-1,l[i]]
else:
temp=sorted([ l[i], l[n-i-1] ])
power+=temp[1]
pos=b... | vfc_2458 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/BATTERY",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n4 8\n5 1 4 2\n3 4\n3 1 2\n2 7\n5 5\n",
"output": "YES\nYES\nNO\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 905 | Solve the following coding problem using the programming language python:
Once upon a time, a king and a few of his soldiers were caught by an enemy king in a war.
He puts them in a circle. The first man in the circle has to kill the second man, the third man has to kill the fourth, fifth man to kill the sixth and ... | ```python
n=int(input())
arr=[]
for i in range(1,n+1):
arr.append(i)
c=0
i=0
f=0;
while(c<n-1):
if(arr[i%n]!=-1 and f):
arr[i%n]=-1
c=c+1
f=0
if(arr[i%n]!=-1):
f=1
i=i+1
for i in range(0,n):
if(arr[i]!=-1):
ans=arr[i]
break;
print(ans)
``` | vfc_2462 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/EPNY2012/problems/EPI02",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "9\n",
"output": "3\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 906 | Solve the following coding problem using the programming language python:
Chef has come to a 2 dimensional garden in which there are N points. Each point has coordinates (x, y), where x can either be 1 or 2 or 3. Chef will now choose every triplet of these N points and make a triangle from it. You need to tell the sum... | ```python
# cook your dish here
# Author: Dancing Monkey | Created: 09.DEC.2018
import bisect
for _ in range(int(input())):
n = int(input())
x1 , x2, x3 = [], [], []
for i in range(n):
x, y = list(map(int, input().split()))
if x == 1: x1.append(y)
if x == 2: x2.append(y)
if x == 3: x3.append(y)
x1.sort(... | vfc_2466 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/MAKETRI",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n3\n1 1\n2 1\n3 3\n4\n1 1\n2 2\n2 1\n3 3\n",
"output": "1.0\n2.0\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 907 | Solve the following coding problem using the programming language python:
The annual snake festival is upon us, and all the snakes of the kingdom have gathered to participate in the procession. Chef has been tasked with reporting on the procession, and for this he decides to first keep track of all the snakes. When he... | ```python
# cook your dish here
t=int(input())
for i in range(t):
n=int(input())
s=input().strip()
c=0
for i in range(len(s)):
if s[i]=='.':
continue
if s[i]=='H':
c+=1
if s[i]=='T':
c-=1
if c>1:
break
if c<0:
break
if c==0:
print('Valid')
else:
print('Invalid')
``` | vfc_2470 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/SNAKPROC",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n18\n..H..T...HTH....T.\n3\n...\n10\nH..H..T..T\n2\nHT\n11\n.T...H..H.T\n7\nH..T..H\n",
"output": "Valid\nValid\nInvalid\nValid\nInvalid\nInvalid\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 908 | Solve the following coding problem using the programming language python:
Chef belongs to a very rich family which owns many gold mines. Today, he brought N gold coins and decided to form a triangle using these coins. Isn't it strange?
Chef has a unusual way of forming a triangle using gold coins, which is described a... | ```python
t = eval(input())
def moneda(m):
h = 1
triange = []
while m >= h:
triange.append(h)
m -= h
h += 1
return len(triange)
triangulo = []
for i in range(t):
n = eval(input())
triangulo.append(n)
for i in triangulo:
print(moneda(i))
``` | vfc_2474 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/LTIME35/problems/TRICOIN",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n3\n5\n7\n",
"output": "2\n2\n3\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 909 | Solve the following coding problem using the programming language python:
-----Problem Statement-----
A classroom has several students, half of whom are boys and half of whom are girls. You need to arrange all of them in a line for the morning assembly such that the following conditions are satisfied:
- The students m... | ```python
for u in range(int(input())):
n=int(input())
l=list(map(int,input().split()))
d=list(map(int,input().split()))
ka=[]
k=[]
l.sort()
d.sort()
for i in range(n):
ka.append(d[i])
ka.append(l[i])
for i in range(n):
k.append(l[i])
k.append(d[i])
... | vfc_2478 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/SCAT2020/problems/SC_02",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n2\n1 3\n2 4\n",
"output": "YES\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 910 | Solve the following coding problem using the programming language python:
Recently, Chef got obsessed with piano. He is a just a rookie in this stuff and can not move his fingers from one key to other fast enough. He discovered that the best way to train finger speed is to play scales.
There are different kinds of sc... | ```python
t =int(input())
for i in range(t):
C=[ord(x)-ord('R') for x in list(input())]
N=int(input())
L=sum(C)
r=1
c=0
while(r*L<N*12):
c+=N*12-r*L
r+=1
print(c)
``` | vfc_2482 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/PIANO1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 \nTTTT\n1\nTTSTTTS\n3\n\n\n",
"output": "4\n36\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 911 | Solve the following coding problem using the programming language python:
The Golomb sequence $G_1, G_2, \ldots$ is a non-decreasing integer sequence such that for each positive integer $n$, $G_n$ is the number of occurrences of $n$ in this sequence. The first few elements of $G$ are $[1, 2, 2, 3, 3, 4, 4, 4, 5, \ldot... | ```python
def find_upper_bound(arr,key):
low,high = 0,len(arr)-1
while low<=high:
mid = (low+high)//2
if arr[mid]==key:return mid
elif arr[mid]>key and mid-1>=0 and arr[mid-1]<key:return mid
elif arr[mid]>key:high = mid - 1
else:low = mid + 1
return mid
def get_query(l):
nonlocal prefix_storer,bin_st... | vfc_2486 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/GOLOMB",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 5\n2 4\n100 100\n",
"output": "27\n17\n441\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 912 | Solve the following coding problem using the programming language python:
k kids seem to have visited your home for the festival. It seems like the kids
had all been fighting with each other, so you decided to keep them as far as
possible from each other. You had placed n chairs on the positive number line,
each at po... | ```python
#dt = {} for i in x: dt[i] = dt.get(i,0)+1
import sys;input = sys.stdin.readline
inp,ip = lambda :int(input()),lambda :[int(w) for w in input().split()]
def check(mid):
pos = x[0]
ct = 1
for i in range(1,n):
if x[i]-pos >= mid:
pos = x[i]
ct += 1
... | vfc_2490 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/CHLG2020/problems/KIDEE1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n2 2\n1 2\n",
"output": "1\nConstraints\n2 ≤ n ≤ 100000\n0 ≤ xi ≤ 10 9\nk ≤ n\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 913 | Solve the following coding problem using the programming language python:
Salmon runs a fish delivery company in Fish City. Fish City has $N$ vertical roads numbered $1, 2, ..., N$ from left to right, each spaced 1 unit apart; similarly, there are $M$ horizontal roads numbered $1, 2, ..., M$ from bottom to top, each s... | ```python
n,m,k=map(int, input().split())
a = []
check = [0]*m
while k!= 0:
x1,y1,x2,y2 =map(int,input().split())
a.append([x1,y1,x2,y2])
check[y1-1] += 1
check[y2-1] += 1
k-= 1
maxi = check.index(max(check))+1
sum = 0
k = 0
for i in range(len(a)):
x1,y1,x2,y2 = a[i]
if (y1 > maxi and y2 > maxi) or (y1<maxi and ... | vfc_2494 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/UWCOI21D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 4 3\n2 3 4 1\n1 4 5 2\n3 3 5 3\n",
"output": "16\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 914 | Solve the following coding problem using the programming language python:
There is a building with $N$ floors (numbered $1$ through $N$ from bottom to top); on each floor, there are $M$ windows (numbered $1$ through $M$ from left to right). Let's denote the $j$-th window on the $i$-th floor by $(i, j)$.
All windows in... | ```python
try:
t = int(input())
while(t > 0):
t -= 1
n,m = list(map(int,input().split()))
a = [list(map(int,input().split())) for _ in range(n)]
dp = [[0 for _ in range(m)] for _ in range(n)]
ans = [['0' for _ in range(m)] for _ in range(n)]
for i in range... | vfc_2498 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/APARTS",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n3 4\n1 3 7 10\n9 2 4 11\n8 12 5 6 \n\n",
"output": "1111\n1001\n0100\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 915 | Solve the following coding problem using the programming language python:
Devu has n weird friends. Its his birthday today, so they thought that this is the best occasion for testing their friendship with him. They put up conditions before Devu that they will break the friendship unless he gives them a grand party on ... | ```python
# cook your dish here
test = int(input())
for _ in range(0,test):
n = int(input())
lister = set(map(int,input().split()))
print(len(lister))
``` | vfc_2502 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/CFRTEST",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n2\n3 2\n2\n1 1\n",
"output": "2\n1\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 916 | Solve the following coding problem using the programming language python:
Chef was bored staying at home in the lockdown. He wanted to go out for a change. Chef and Chefu are fond of eating Cakes,so they decided to go the Cake shop where cakes of all possible price are available .
They decided to purchase cakes of equ... | ```python
# cook your dish here
import math
T=int(input())
for i in range(T):
a=list(map(int,input().split()))
n=a[0]
m=a[1]
print(m*n//math.gcd(m,n))
``` | vfc_2506 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/ENAU2020/problems/ECAUG201",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n2 3\n",
"output": "6\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 917 | Solve the following coding problem using the programming language python:
You are given an array of N integers a1, a2, ..., aN and an integer K. Find the number of such unordered pairs {i, j} that
- i ≠ j
- |ai + aj - K| is minimal possible
Output the minimal possible value of |ai + aj - K| (where i ≠ j) and the n... | ```python
for _ in range(int(input())):
n,k=list(map(int, input().split()))
l=list(map(int, input().split()))
l.sort()
c=0
mn=abs(l[0]+l[1]-k)
for i in range(n-1):
for j in range(i+1, n):
temp=abs(l[i]+l[j]-k)
if temp==mn:
c+=1
elif temp<mn:
mn=temp
c=1
elif l[i]+l[j]-k>mn:... | vfc_2510 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/APPROX2",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n4 9\n4 4 2 6\n",
"output": "1 4\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 918 | Solve the following coding problem using the programming language python:
Mr. Wire Less is not that good at implementing circuit in a breadboard. In his Digital Logic Design course, he has to implement several boolean functions using the breadboard. In a breadboard, inputs are given through the switches and outputs ar... | ```python
# cook your dish here
mod=8589934592
list1=[]
for i in range(int(input())):
x=int(input())
ans=(pow(2,x,mod)-1)%mod
list1.append((i+1,ans))
for i in list1:
print(f'Case {i[0]}: {i[1]}')
``` | vfc_2514 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/KOL16H",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n1\n2\n\n\n",
"output": "Case 1: 1\nCase 2: 3\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 919 | Solve the following coding problem using the programming language python:
An even sequence has the following property: each maximal contiguous subsequence which contains only equal integers (i.e. the same integer repeated a number of times) has an even length. In particular, the empty sequence is even. A subsequence i... | ```python
'''Author- Akshit Monga'''
from sys import stdin, stdout
input = stdin.readline
t=int(input())
for _ in range(t):
n=int(input())
a=[int(x) for x in input().split()]
ans=0
dp=[-1 for i in range(0,n+1)]
for i in a:
var1=dp[i]
var2=ans
ans=max(ans,var1+1)
dp[i]=max(dp[i],var2+1)
print(n-ans)
``` | vfc_2518 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/EVSTR",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n4\n1 1 2 1\n11\n2 2 2 10 2 10 1 1 5 3 5\n",
"output": "2\n3\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 920 | Solve the following coding problem using the programming language python:
You are teaching a class of $N$ students. Today, during the morning prayer, all the students are standing in a line. You are given a string $s$ with length $N$; for each valid $i$, the $i$-th character of this string is 'b' if the $i$-th student... | ```python
from collections import Counter
for _ in range(int(input())):
s = input()
c = Counter(list(s))
if len(c) == 1:
print(0)
else:
m = min(c['b'], c['g'])
ma = max(c['b'], c['g'])
l = (ma - m + 1) // 2
r = (ma - m + 1) // 2 + (ma - m + 1) % 2
res = (l * (l + 1)) // 2
re = res
for i in range(1,... | vfc_2522 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/AWKMINI",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\ngb\nbgg\nbbgg\n",
"output": "1\n2\n6\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 921 | Solve the following coding problem using the programming language python:
Doctor Kunj installed new software on cyborg Shresth.
This software introduced Shresth to range minimum queries.
Cyborg Shresth thought of T$T$ different problems in each of which you will be given
an array A$A$ of length N$N$ and an array B$B$ ... | ```python
def f(a,n):
l,r,s1,s2 = [0]*n, [0]*n, [], []
for i in range(n):
count = 1
while(len(s1)>0 and a[i]<s1[-1][0]):
count += s1[-1][1]
s1.pop()
s1.append((a[i],count))
l[i] = count
for i in range(n-1,-1,-1):
count = 1
while(len(s2)>0 and a[i]<=s2[-1][0]):
... | vfc_2526 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/RICY",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n7 3\n10 3 7 9 1 19 2\n1 4 6\n",
"output": "43\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 922 | Solve the following coding problem using the programming language python:
Chef has three baskets and two of them have multiple balls(Natural numbers written on them). The first basket has N balls, the second basket has M balls and the third basket is empty. Chef starts choosing all the unique balls(only occurring once... | ```python
t = int(input())
for i in range(t):
n, m = map(int, input().split())
arr1 = list(map(int, input().split()))
arr2 = list(map(int, input().split()))
hmap = {}
for i in range(n):
if arr1[i] in hmap:
hmap[arr1[i]] += 1
else:
hmap[arr1[i]] = 1
fo... | vfc_2530 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/PEND2020/problems/ITGUY08",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n4 5\n1 2 3 4\n2 3 4 5 6\n",
"output": "1 5 6\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 923 | Solve the following coding problem using the programming language python:
Like all minions Dave also like to eat bananas. So as to his obsession, he is eating banana, but this time in different way. There are N bananas in dish. Dave wants to eat all of them. He starts eating at speed 1 banana/second. He can increase o... | ```python
t=int(input())
while(t):
k=1
j=0
n=int(input())
while(n>0):
if(n<=k):
j+=1
n=0
elif n>2*k:
j+=2
n=n-2*k
k+=1
else:
j+=2
n=0
print(j)
t-=1
``` | vfc_2534 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/CFSN2015/problems/PUNBAN",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n2\n4\n",
"output": "2\n3\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 924 | Solve the following coding problem using the programming language python:
Given an empty array A of infinite length and a positive integer K you have to process
Q queries of type:
- ! l r x: Fill the value x in all the empty places in the array from index l to r (both inclusive).
- ? l r: Print the number of pri... | ```python
# cook your dish here
# cook your dish here
import math
def distinctPrimeFactors(num) :
primes,sqrt = set(),int(math.sqrt(num))
if (num == 2) :primes.add(num)
for j in range(2, sqrt + 1) :
if (num % j == 0) :
primes.add(j)
while (num % j == 0) :num //= j
if (nu... | vfc_2538 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/PRMRANGE",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "20 5\n? 1 5\n! 3 5 4\n? 1 5\n! 1 4 15\n? 1 5\n",
"output": "0\n1\n2\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 925 | Solve the following coding problem using the programming language python:
Petr is organizing Petr Mitrichev Contest #11. The top N coders according to codechef ratings (excluding Petr himself) agreed to participate in the contest. The participants have been ranked from 0 to N-1 according to their ratings. Petr had ask... | ```python
import math
def comb(n,r):
f = math.factorial
return f(n) / f(r) / f(n-r)
t=int(input())
for i in range(1,t+1):
n=int(input())
arr = list(map(int, input().split()))
m=0
ans=0.0
for i in range(0,n):
if (arr[i]==-1):
m=m+1
for i in range(0,m):
ans=ans+((m-i)*comb(m-1,m-1-i))
ans=ans/pow(2,m-1)
... | vfc_2542 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/CHN15ROL/problems/CHN15B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n5\n-1 -1 1 2 1\n",
"output": "1.5\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 926 | Solve the following coding problem using the programming language python:
Today is Chocolate day and Kabir and Tara are visiting a Valentine fair. Upon arriving, they find a stall with an interesting game.
There are N$N$ jars having some chocolates in them. To win the game, one has to select the maximum number of cons... | ```python
# cook your dish here
for u in range(int(input())):
n,r=list(map(int,input().split()))
l=list(map(int,input().split()))
m=0
for i in range(n-1):
d=[]
d.append(l[i])
c=1
while(i+c<n):
d.append(l[i+c])
d.sort(reverse=True)
if(d[... | vfc_2546 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/HECS2020/problems/CC003",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n6 5\n1 3 3 1 1 5\n",
"output": "3\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 927 | Solve the following coding problem using the programming language python:
Mohit(Ex GenSec ) is the most active member of the roasting club who loves giving tasks to other members. One day he observed that none of the members were paying attention to the online classes, so he decided to have some fun and overcome the b... | ```python
n, m = map(int, input().split())
l = n
f = 1
s = ((n)*(n+1))//2 - l - f
for _ in range(m):
k = int(input())
if 2 <= k <= n-1 or k in [f, l]:
l, f = f, l
else:
l = k
print(s+l+f)
``` | vfc_2550 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/CGRL2020/problems/CGMN1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 4\n7\n12\n10\n1\n",
"output": "17\n22\n20\n20\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 928 | Solve the following coding problem using the programming language python:
Being a crewmate in the Among Us game, you will have to solve a task to win against the imposter.
The task : You are given a certain number of bulbs(Say n) which are initially in OFF position.
The bulbs are numbered from 1 to n. There will be ... | ```python
import math
def CountSquares(a, b):
return (math.floor(math.sqrt(b)) - math.ceil(math.sqrt(a)) + 1)
for _ in range(int(input())):
n=int(input())
val=CountSquares(1,n)
ans=val-val//3
print(ans)
``` | vfc_2554 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/ENNO2020/problems/ENCNOV11",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n2\n20\n",
"output": "1\n3\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 929 | Solve the following coding problem using the programming language python:
You are given a tree with $N$ vertices (numbered $1$ through $N$) and a bag with $N$ markers. There is an integer written on each marker; each of these integers is $0$, $1$ or $2$. You must assign exactly one marker to each vertex.
Let's define ... | ```python
# cook your dish here
import numpy as np
tests = int(input())
for _ in range(tests):
n = int(input())
weights = [int(j) for j in input().split()]
edges = [[0] for _ in range(n-1)]
for i in range(n-1):
edges[i] = [int(j)-1 for j in input().split()]
vertex_set = [[] for _ in range(n)]
fo... | vfc_2558 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/TREEUNAT",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n3\n0 1 1\n1 2\n1 3\n3\n0 1 2\n1 2\n1 3\n4\n2 2 2 2\n1 2\n1 3\n3 4\n",
"output": "1\n1\n0\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 930 | Solve the following coding problem using the programming language python:
Consider the following $4 \times 4$ pattern:
1 2 4 7
3 5 8 11
6 9 12 14
10 13 15 16
You are given an integer $N$. Print the $N \times N$ pattern of the same kind (containing integers $1$ through $N^2$).
-----Input-----
- The first line o... | ```python
for i in range(int(input())):
t=int(input())
n=0
for i in range(1,t+1):
n=n+i
x=[n]
y=n
for j in range(i,t+i-1):
if j<t:
z=y+j
else:
z=y+(2*t-j-1)
x.append(z)
y=z
print(*x)
``` | vfc_2562 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/PPATTERN",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n4\n",
"output": "1 2 4 7\n3 5 8 11\n6 9 12 14\n10 13 15 16\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 931 | Solve the following coding problem using the programming language python:
One day, Delta, the dog, got very angry. He has $N$ items with different values, and he decided to destroy a few of them. However, Delta loves his hooman as well. So he only destroyed those items whose Least Significant Bit in binary representat... | ```python
# cook your dish here
for test in range(int(input())):
n = int(input())
ar = list(map(int, input().split()))
count = 0
for item in ar:
if bin(item)[-1] == '0':
count += item
print(count)
``` | vfc_2566 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/ENAU2020/problems/ECAUG202",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n5\n1 2 3 4 5\n",
"output": "6\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 932 | Solve the following coding problem using the programming language python:
There are two friends Alice and Bob. They have a packet of $n$ candies. They want to split the candies between them, and to do so, they kept them all in a single line. The $i^{\text{th}}$ candy in the line has a sweetness value of $a_i$. They de... | ```python
from sys import setrecursionlimit
setrecursionlimit(10 ** 9)
def solve(i, j, c=0):
if i > j:
return 0
if (i, j) in dp:
return dp[i, j]
x0 = solve(i+1, j, c^1)
x1 = solve(i, j-1, c^1)
if c == 0:
y = 1 << (j - i)
x0 += a[i] * y
x1 += a[j] * y
dp[i, j] = x0 + x1
return dp[i, j]
for _ in ra... | vfc_2570 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/EXPCAN",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n2\n1 2\n3\n1 2 3\n",
"output": "1.500000000000000\n4.000000000000000\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 933 | Solve the following coding problem using the programming language python:
Chef develops his own computer program for playing chess. He is at the very beginning. At first he needs to write the module that will receive moves written by the players and analyze it. The module will receive a string and it should report at ... | ```python
#!/usr/bin/env python2
def gc(c):
return 'a' <= c <= 'h'
def gd(c):
return '1' <= c <= '8'
t = int(input())
for i in range(t):
line = input()
if len(line) != 5:
print("Error")
continue
if line[2] != '-':
print("Error")
continue
x1 = line[0]
y1 = line[1]
x2 = line[3]
y2 = ... | vfc_2574 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/COOK11/problems/KNIGHTMV",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\na1-b3\nd2-h8\na3 c4\nErrorError\n",
"output": "Yes\nNo\nError\nError\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 934 | Solve the following coding problem using the programming language python:
Given a triplet of integers (X , Y , Z), such that X ≤ Y and Y ≥ Z, we define f(X , Y , Z) to be (X + Y) * (Y + Z). If either X > Y or Y < Z, or both, then f(X , Y , Z) is defined to be 0.
You are provided three arrays A , B and C of any leng... | ```python
T=int(input()) # cook your dish here
for i in range(T):
n=list(map(int,input().split()))
a=n[0]
b=n[1]
c=n[2]
l=[]
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
for i in range(b):
for j in range(a):
f... | vfc_2578 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/SUMQ",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 \n3 1 3\n1 2 3\n5\n4 5 6\n\n\n",
"output": "399\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 935 | Solve the following coding problem using the programming language python:
Chef Two and Chef Ten are playing a game with a number $X$. In one turn, they can multiply $X$ by $2$. The goal of the game is to make $X$ divisible by $10$.
Help the Chefs find the smallest number of turns necessary to win the game (it may be p... | ```python
# cook your dish here
t=int(input())
for i in range(t):
x=int(input())
if x%10==0:
print(0)
elif x%5==0:
print(1)
else:
print(-1)
``` | vfc_2582 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/TWOVSTEN",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n10\n25\n1\n",
"output": "0\n1\n-1\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 936 | Solve the following coding problem using the programming language python:
Chef Ada has a matrix with $N$ rows (numbered $1$ through $N$ from top to bottom) and $N$ columns (numbered $1$ through $N$ from left to right) containing all integers between $1$ and $N^2$ inclusive. For each valid $i$ and $j$, let's denote the... | ```python
for _ in range(int(input())):
n=int(input())
a=[]
l=0
for i in range(n):
a.append(list(map(int,input().split())))
for i in range(n-1,0,-1):
r=a[i][i-1]+1
if a[i][i]!=r:
l+=1
n=i+1
for j in range(n):
for k in range(j,n):
a[j][k],a[k][j]=a[k][j],a[j][k]
print(l)
``` | vfc_2586 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/ADAMAT",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n4\n1 2 9 13\n5 6 10 14\n3 7 11 15\n4 8 12 16\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 937 | Solve the following coding problem using the programming language python:
Chef's daily routine is very simple. He starts his day with cooking food, then he eats the food and finally proceeds for sleeping thus ending his day. Chef carries a robot as his personal assistant whose job is to log the activities of Chef at v... | ```python
# cook your dish here
t=int(input())
for _ in range(t):
s=input()
k=len(s)
count=0
for i in range(k-1):
if(s[i]=="C"):
if(s[i+1]=='E'or s[i+1]=='S' or s[i+1]=="C"):
count+=1
elif(s[i]=="E"):
if(s[i+1]=="S"or s[i+1]=='E'):
count+=1
elif(s[i]=="S"):
if(s[i+1]=="S"):
count+=1
i... | vfc_2590 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/CHEFROUT",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\nCES\nCS\nCCC\nSC\nECCC\n",
"output": "yes\nyes\nyes\nno\nno\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 938 | Solve the following coding problem using the programming language python:
Chef has an array A consisting of N elements. He wants to find number of pairs of non-intersecting segments [a, b] and [c, d] (1 ≤ a ≤ b < c ≤ d ≤ N) such there is no number that occurs in the subarray {Aa, Aa+1, ... , Ab} and {Ac, Ac+1, ... ,... | ```python
t=int(input())
for q in range(t):
n=int(input())
x=list(map(int,input().split()))
dic={}
dic2={}
for i in range(n):
dic2[x[i]]=1
#print dic2
if len(dic2)==n:
n+=2
print((n*(n-1)*(n-2)*(n-3))/24)
continue
counter=0
for i in range(n-1):
if x[i] in dic:
dic[x[i]]+=1
else:
dic[x[i]]=1
... | vfc_2594 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/JULY16/problems/CHSGMNTS",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n3\n1 2 3\n4\n1 2 1 2\n",
"output": "5\n4\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 939 | Solve the following coding problem using the programming language python:
Chef loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Let F(X) equals to the num... | ```python
lucky = {4, 774, 7, 744, 777, 74, 747, 44, 77, 47, 474, 444, 477, 447}
from functools import lru_cache
import sys
sys.setrecursionlimit(10 ** 6)
mod = 10 ** 9 + 7
fact = [1]
for i in range(1, 1001):
fact.append(fact[-1] * i % mod)
inv = [pow(i, mod-2, mod) for i in fact]
C = lambda k, n: fact[n] * inv[n-... | vfc_2598 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/LUCKY2",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1 100\n1 10000\n1 100000\n4444 4447\n\n\n",
"output": "0\n16\n640\n2\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 940 | Solve the following coding problem using the programming language python:
Chef has a circular plot of land of radius $R$ on which he wants to construct a swimming pool.
He wants the swimming pool to be square in shape with maximum possible area,so that he along
with his friends can enjoy themselves during their summer... | ```python
T=int(input())
l=[]
for t in range(T):
R=int(input())
a=2*(R**2)
l.append(a)
for s in l:
print(s)
``` | vfc_2602 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/ENCD2020/problems/ECAPR202",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n5\n10\n",
"output": "50\n200\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 941 | Solve the following coding problem using the programming language python:
You are given two positive integers $A$ and $B$. Find the number of pairs of positive integers $(X, Y)$ such that $1 \le X \le A$, $1 \le Y \le B$ and $X + Y$ is even.
-----Input-----
- The first line of the input contains a single integer $T$ ... | ```python
try:
t=int(input())
while t>0:
[a,b]=[int(x) for x in input().split()]
if a==1 and b==1:
print(1)
continue
if a%2==0:
o1=a//2
e1=a//2
else:
o1=a//2+1
e1=a//2
if b%2==0:
o2=b//2
e2=b//2
else:
o2=b//2+1
e2=b//2
print(e1*e2+o1*o2)
t-=1
except:
pass
``` | vfc_2606 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/EVENPSUM",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1 1\n2 3\n4 6\n8 9\n",
"output": "1\n3\n12\n36\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 942 | Solve the following coding problem using the programming language python:
You are given $N$ integers in an array: $A[1], A[2], \ldots, A[N]$. You also have another integer $L$.
Consider a sequence of indices ($i_1, i_2, \ldots, i_k$). Note that a particular index can occur multiple times in the sequence, and there is ... | ```python
# cook your dish here
# from queue import PriorityQueue
# import bisect
def insort(l, v):
s = 0
e = len(l)
while True:
mid = (s+e)//2
if s == e or mid > len(l):
break
if l[mid][0] < v[0]:
s = mid+1
elif l[mid][0] > v[0]:
e = mid
... | vfc_2610 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/INOIPRAC/problems/INOI1902",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n6 3\n2 4 1 12 3 5\n",
"output": "3\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 943 | Solve the following coding problem using the programming language python:
Tejas has invited the Clash Team for a Dinner Party. He places V empty plates (numbered from 1 to V inclusive) in a straight line on a table. He has prepared 2 kinds of Delicious Dishes named dish A and dish B.
He has exactly V servings of Dish... | ```python
# cook your dish here
t=int(input())
for i in range(t):
v,w=list(map(int,input().strip().split(" ")))
if v==w:
print(v+1)
elif v<w:
print(v+1)
else:
print(w+1)
#s="a"
#s=s*v
#l=list(s)
#print(l)
ct=0
#for i in range(w):
`... | vfc_2614 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/CCWC2018/problems/BONAPP",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n3 3\n",
"output": "4\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 944 | Solve the following coding problem using the programming language python:
Given an array $A$ of length $N$.
We have to find the $maximum$ sum of elements of the subarray between $two$ nearest occurrences of $same$ elements (excluding both).
If both the elements are $even$ then the total number of $even$ elements in th... | ```python
# cook your dish here
from sys import stdin, stdout
from collections import defaultdict
for _ in range(int(stdin.readline())):
n=int(stdin.readline())
lst=list(map(int, stdin.readline().split()))
prefix_odd=[0]*n
prefix_even=[0]*n
odd_val=0
even_val=0
for i in range(n):
if ... | vfc_2618 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/CFUS2020/problems/CFS2002",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n10\n1 2 3 2 1 5 1 2 8 2\n",
"output": "7\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 945 | Solve the following coding problem using the programming language python:
Now that Chef has finished baking and frosting his cupcakes, it's time to package them. Chef has N cupcakes, and needs to decide how many cupcakes to place in each package. Each package must contain the same number of cupcakes. Chef will choose ... | ```python
for i in range(int(input())):
n=int(input())
print(n//2+1)
``` | vfc_2622 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/MUFFINS3",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n2\n5\n",
"output": "2\n3\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 946 | Solve the following coding problem using the programming language python:
There are $N$ buckets numbered $1$ through $N$. The buckets contain balls; each ball has a color between $1$ and $K$. Let's denote the number of balls with color $j$ that are initially in bucket $i$ by $a_{i, j}$.
For each $i$ from $1$ to $N-1$ ... | ```python
import sys
import math
def main(arr):
k=len(arr[0])
n=len(arr)
dp=[[0]*k for i in range(n+1)]
summation_arr=[]
for i in range(len(arr)):
a=1 if i!=0 else 0
summation_arr.append(sum(arr[i])+a)
for i in range(1,len(dp)):
for j in range(len(dp[0])):
dp[i][j]=(dp[i-1][j]+arr[i-1][j])/summati... | vfc_2626 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/BUCKETS",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 2\n0 1\n1 1\n",
"output": "0.333333 0.666667\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 947 | Solve the following coding problem using the programming language python:
In this problem we are concerned with words constructed using the lowercase letters of the English alphabet - that is, a,b,c,…,z. These words need not necessarily be meaningful: any sequence of letters forms a word. For example, abbca is a word.... | ```python
def codn1(s1,s2,p):
c=0
ind=0
for i in range(len(s1)):
if s1[i]!=s2[i]:
c+=1
ind=i
if c>1 or ind==len(s1)-1:
return 0
if s1[ind]>s2[ind] and s1[ind] in s2[ind+1:]:
p[0]=True
if s1[ind]<s2[ind] and s2[ind] in s1[ind+1:]:
p[1]=True
return 1
def codn2(s1,s2):
if len(s1)<le... | vfc_2630 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/IARCSJUD/problems/WORDHOP",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "11\nabacd\nbcdada\ndd\nabcd\nbcdd\nadcd\naddd\naa\nccd\nadd\nad\n",
"output": "7\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 948 | Solve the following coding problem using the programming language python:
Chang's new maths teacher is very enthusiastic about making sure that students understand the concept rather than remembering it. On her first day at teaching, she gives an assignment to all the students to test their potential. Chang wants to d... | ```python
from math import sqrt
a, b = map(int, input().split())
pairs = 0
for i in range(1, a+1):
for j in range(1, b+1):
root = sqrt(i**2 + j)
if not root - int(root):
pairs += 1
print(pairs)
``` | vfc_2634 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/CHNGFUNC",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 4\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 949 | Solve the following coding problem using the programming language python:
Fizza is a cute girl and she wants to be more beautiful.
So she approached a magician to increase her beauty magically. But the magician's
glasses accidently got locked inside the locker and he forgot the password. Without
glasses he can't help... | ```python
def check(l,n):
m = 0
for i in range(n-1):
x = l[i]
c = 0
j = i
while (j+2<n and l[j+2]==x) or (j+1<n and l[j+1] == x):
if l[j+1] == x:
j = j+1
else:
j+=2
c+=1
if m<c:
m = c
retu... | vfc_2638 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/LOGI2020/problems/FIZZA",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n8\n6 3 6 4 5 4 3 6\n9\n5 5 4 5 2 1 3 4 2\n6\n1 2 3 4 5 6\n",
"output": "1\n2\n0\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 950 | Solve the following coding problem using the programming language python:
A repetition-free number is one in which each digit $\{1,2,3,…,9\}$ appears at most once and the digit $0$ does not appear. A repetition-free number can have at most nine digits, but may also have fewer than nine digits. Some examples of repetit... | ```python
N = int(input())
i = N + 1
flag = 0
for i in range(N+1, 987654321):
a = str(i)
b = list(a)
c = set(a)
if '0' not in b:
if len(b) == len(c):
print(i)
flag += 1
break
if flag < 1:
print(0)
``` | vfc_2642 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/IARCSJUD/problems/REPFREE",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "99\nSample output\n123\n",
"output": "",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 951 | Solve the following coding problem using the programming language python:
IIST is thinking of acquiring some land nearby to build its new state of the art labs. The land it has chosen incidentaly has some abandoned college buildings which IIST wants to use. The administration decide the value of the building based on ... | ```python
import math
from itertools import permutations as p
def diff(li1, li2):
li_dif = [i for i in li1 if i not in li2]
return li_dif
def segments(b):
"""A sequence of (x,y) numeric coordinates pairs """
poly = [(i[0],i[1]) for i in b]
return zip(poly, poly[1:] + [poly[0]])... | vfc_2646 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/CUBE2020/problems/BDRYIIST",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n6\n0 0 8 3\n1 4 3 2\n2 1 7 1\n4 1 2 3\n3 5 4 6\n2 3 9 8\n3\n3 0 10 2\n5 5 20 25\n7 -3 30 32\n",
"output": "2 4 5\n3.16\n2\n15.00\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 952 | Solve the following coding problem using the programming language python:
Chef has a string of size $N$ which consists only lowercase English alphabet. The chef doesn't like the consonant alphabet at all. So he is thinking of changing every single consonant alphabet to any vowel alphabet. There is some cost for perfor... | ```python
# cook your dish here
str1=int(input())
for i in range(str1):
l1=[]
str2=input()
for i in str2:
l1.append(i)
count=0
d=dict()
d={'a':1,'b':2,'c':3,'d':4,'e':5,'f':6,'g':7,'h':8,'i':9,'j':10,'k':11,'l':12,'m':13,'n':14}
d1={'o':15,'p':16,'q':17,'r':18,'s':19,... | vfc_2650 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/BIT32020/problems/BIT3F",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\naeiou\ndbcc\n",
"output": "0\n6\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 953 | Solve the following coding problem using the programming language python:
Chef has $N$ doggo (dogs) , Lets number them $1$ to $N$.
Chef decided to build houses for each, but he soon realizes that keeping so many dogs at one place may be messy. So he decided to divide them into several groups called doggo communities... | ```python
# cook your dish here
import sys
def get_array(): return list(map(int , sys.stdin.readline().strip().split()))
def get_ints(): return list(map(int, sys.stdin.readline().strip().split()))
def input(): return sys.stdin.readline().strip()
import math
from collections import defaultdict
from itertools import comb... | vfc_2654 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/STR2020/problems/DOGGO",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n4\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 954 | Solve the following coding problem using the programming language python:
Chef has an old machine if the chef enters any natural number, the machine will display 1, 2, …n, n-1, n-2, n-3,…1 series and in next line prints sum of cubes of each number in the series. Chef wants to create a computer program which can replic... | ```python
t=int(input())
while(t!=0):
t=t-1
n=int(input())
ans=0
for i in range(1,n+1,1):
sum=0;
for j in range(1,i+1,1):
sum=sum+j
s=sum-i
sum=sum+s
if(i!=n):
ans=ans+2*sum*i
else:
ans=ans+sum*i
print... | vfc_2658 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/PEND2020/problems/ANITGUY4",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n1\n3\n",
"output": "1\n45\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 955 | Solve the following coding problem using the programming language python:
-----Problem Statement-----
Levy's conjecture, named after Hyman Levy, states that all odd integers greater than 5 can be represented as the sum of an odd prime number and an even semiprime. To put it algebraically, 2n + 1 = p + 2q always has a ... | ```python
isPrime=[1 for i in range(10001)]
cnt=[0 for i in range(10001)]
isPrime[0]=0
isPrime[1]=0
prime=[]
for i in range(2,10001):
if isPrime[i]:
prime.append(i)
for j in range(i*i,10001,i):
isPrime[j]=0
#print(prime)
for i in prime:
for j in prime:
if (i + 2*j)>10000:
break
else:
cnt[i + 2*j]+=1
... | vfc_2662 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/LEVY",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n2\n7\n11\n",
"output": "0\n1\n2\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 956 | Solve the following coding problem using the programming language python:
You are given a convex polygon $P$ with vertices $P_0, P_1, \ldots, P_{n-1}$, each having integer coordinates. On each edge $P_{i} P_{(i+1) \% n}$ of the polygon, choose a point $R_i$ uniformly at random. What is the expected area of the convex ... | ```python
# cook your dish here
n=int(input())
x=[]
y=[]
for _ in range(n):
s=input().split(' ')
x.append(int(s[0]))
y.append(int(s[1]))
q=x[0]
w=y[0]
for t in range(n-1):
x[t]=(x[t]+x[t+1])/2
y[t]=(y[t]+y[t+1])/2
x[n-1]=(x[n-1]+q)/2
y[n-1]=(y[n-1]+w)/2
i=0
a=0
while(i<n-1):
a+=(x[i]*y[i+1]-y[i]*x[i+1])/2
i+... | vfc_2666 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/EAREA",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n0 0\n1 0\n0 1\n",
"output": "0.1250000000\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 957 | Solve the following coding problem using the programming language python:
Tired of the overpopulated world, Miu - The introverted cat visits a new continent in search for a new house.
There are $N$ houses lying on the X-axis.
Their positions are given by $X$$i$ , where $i$ refers to the $i$th house. ( $1 <= i <= N$... | ```python
n = int(input())
for i in range(n) :
t = int(input())
li = sorted(list(map(int , input().split())))
ans = 1
dp = [li[1]-li[0]] + [0] * (t-2) + [li[t-1] - li[t-2]]
for i in range(1 , t-1) :
dp[i] = min(li[i] - li[i-1] , li[i+1] - li[i])
print(max(dp))
``` | vfc_2670 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/TCFL2020/problems/TCFL20A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n6\n7 -1 2 13 -5 15\n4\n6 10 3 12\n",
"output": "5\n3\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 958 | 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
from sys import stdin, stdout
from collections import Counter
n = int(stdin.readline())
#l = list(map(int, stdin.readline().split()))
#l = [int(stdin.readline()) for _ in range(n)]
#a, b = map(int, stdin.readline().split())
for _ in range(n):
n1 = int(stdin.readline())
if n1==1:
print... | vfc_2674 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/PEND2020/problems/ITGUY02",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1\n2\n3\n4\n5\n",
"output": "*\n*\n***\n*\n* *\n*****\n*\n* *\n* *\n*******\n*\n* *\n* *\n* *\n*********\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 959 | Solve the following coding problem using the programming language python:
You are given an array with $N$ integers: $A[1], A[2], \ldots, A[N]$ (where $N$ is even). You are allowed to permute the elements however you want. Say, after permuting the elements, you end up with the array $A'[1], A'[2], \ldots, A'[N]$. Your ... | ```python
for i in range(int(input())):
n=int(input())
m=list(map(int,input().split()))[:n]
m.sort()
t=0
for j in range(n//2):
t+=abs(m[j]-m[n-j-1])
print(t)
``` | vfc_2678 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/NOMATCH",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n4\n1 -3 2 -3\n",
"output": "9\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 960 | 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
t = int(input())
for _ in range(t):
k = int(input())
count = 1
for _ in range(k):
output = []
for index in range(1,k+1):
output.append(bin(count).replace("0b", ""))
count += 1
print(*output)
``` | vfc_2682 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/PTRN2021/problems/ITGUY52",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1\n2\n3\n4\n",
"output": "1\n1 10\n11 100\n1 10 11\n100 101 110\n111 1000 1001\n1 10 11 100\n101 110 111 1000\n1001 1010 1011 1100\n1101 1110 1111 10000\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 961 | Solve the following coding problem using the programming language python:
The chef has one array of N natural numbers (might be in sorted order). Cheffina challenges chef to find the total number of inversions in the array.
-----Input:-----
- First-line will contain $T$, the number of test cases. Then the test cases ... | ```python
# cook your dish here
def mergeSort(arr, n):
# A temp_arr is created to store
# sorted array in merge function
temp_arr = [0]*n
return _mergeSort(arr, temp_arr, 0, n-1)
# This Function will use MergeSort to count inversions
def _mergeSort(arr, temp_arr, left, right):
# A va... | vfc_2686 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/PSTR2020/problems/ANITGUY3",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n5\n5 4 1 3 2\n",
"output": "8\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 962 | 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
for _ in range(int(input())):
n = int(input())
s = ''
for i in range(1, n + 1): s += str(i)
for i in range(n, 0, -1):
if i % 2 == 0:
for j in range(i, 0, -1): print(j, end = '')
else:
for j in range(1, i + 1): print(j, end = '')
print()
``` | vfc_2690 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/PTRN2020/problems/ITGUY40",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n2\n3\n4\n",
"output": "21\n1\n123\n21\n1\n4321\n123\n21\n1\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 963 | Solve the following coding problem using the programming language python:
In ChefLand, there is a mountain range consisting of $N$ hills (numbered $1$ through $N$) in a straight line. Let's denote the height of the $i$-th hill from the left by $h_i$.
Ada is working on the water supply system of ChefLand. On some of th... | ```python
def solve(l):
m = l.index(max(l))
if m == 0 or m == len(l) - 1:
return 1
return 1 + min(solve(l[0:m]), solve(l[m+1:]))
tc = int(input())
for test in range(tc):
n = int(input())
l = list(map(int, input().split()))
print(solve(l))
``` | vfc_2694 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/PUMPWAT",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n6\n4 16 32 6 8 2\n\n",
"output": "2 \n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 964 | Solve the following coding problem using the programming language python:
-----Problem-----
There is an infinite one dimensional array ranging from (-infinity, infinity).A Zombie is currently at cell number 0. The zombie wants to reach cell number H. The Zombie moves in only two ways. The Zombie either
Makes U steps... | ```python
import fractions
for t in range(int(input())):
h,u,d = list(map(int,input().split()))
g = fractions.gcd(u,d)
if (h%g!=0):
print(-1)
else:
m = 0
n = 0
while (True):
n = (float(m)*u-h)/d
if (n>0 and int(n) == n):
break
m+=1
print(int(m+n))
``` | vfc_2698 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/COMN2016/problems/ZOMBIE",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n3 2 1\n3 2 2\n",
"output": "3\n-1\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 965 | Solve the following coding problem using the programming language python:
Cyael is a teacher at a very famous school in Byteland and she is known by her students for being very polite to them and also to encourage them to get good marks on their tests.
Then, if they get good marks she will reward them with candies :) ... | ```python
# cook your dish here
try:
t = int(input())
for _ in range(t):
n, k = map(int, input().split())
if k == 0:
print(0, n)
else:
print(n//k, n%k)
except:
pass
``` | vfc_2702 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/SPCANDY",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n10 2\n100 3\n",
"output": "5 0\n33 1\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 966 | Solve the following coding problem using the programming language python:
There are N hills in a row numbered 1 through N from left to right. Each hill has a height; for each valid i, the height of the i-th hill is Hi. Chef is initially on the leftmost hill (hill number 1). He can make an arbitrary number of jumps (in... | ```python
for _ in range(int(input())):
N,U,D=list(map(int,input().split()))
H=list(map(int,input().split()))
jumps=0
paracount=0
for i in range(len(H)-1):
if H[i+1]-H[i]<=U and H[i+1]>=H[i]:
jumps+=1
elif H[i]>=H[i+1] and H[i]-H[i+1]<=D:
jumps+=1
elif H[i]-H[i+1]>D and paracount==0:
jumps+=1
par... | vfc_2706 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/HILLS",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n5 3 2\n2 5 2 6 3\n5 2 3\n4 4 4 4 4\n5 2 7\n1 4 3 2 1\n",
"output": "3\n5\n1\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 967 | Solve the following coding problem using the programming language python:
Since due to COVID 19, India has undergone a complete 21 day lockdown. So Amol was attending an online lecture where his professor asked him to solve a question. Amol was unable to solve the question so he asked you to solve the question and giv... | ```python
try:
def countsubsetsum(S,arr,n):
k=[[0 for i in range(S+1)] for i in range(n+1)]
for i in range(n+1):
for j in range(S+1):
if(j==0):
k[i][j]=1
elif(i==0):
k[i][j]=0
elif(arr[i-1]<=j):
... | vfc_2710 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/CY302020/problems/CODY303",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n4\n16\n2 4 6 10\n4\n20\n2 8 12 10\n",
"output": "2\n2\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 968 | Solve the following coding problem using the programming language python:
You are given a rooted tree on N vertices. The nodes are numbered from 1 to N, and Node 1 is the root. Each node u has an associated value attached to it: Au.
For each vertex v, we consider the path going upwards from v to the root. Suppose that... | ```python
import sys
n = eval(input())
parents = [int(x)-1 for x in input().split(' ')]
values = list(map(int , input().split(' ')))
parents = [0]+parents
# print(parents)
# print(values)
def single_node_cost(i):
cost = 0
# print('started with ',i)
min_value = sys.maxsize
while i != 0:
min_value = min(min_value,v... | vfc_2714 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/POSTTREE",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "8\n1 1 1 1 5 8 6\n1 2 3 4 5 15 70 10\n",
"output": "1 3 4 5 6 21 96 26\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 969 | Solve the following coding problem using the programming language python:
You might have heard about our new goodie distribution program aka the "Laddu Accrual System". This problem is designed to give you a glimpse of its rules. You can read the page once before attempting the problem if you wish, nonetheless we will... | ```python
for i in range(int(input())):
n,k=input().split()
laddus=0
for j in range(int(n)):
t=input().split()
if t[0]=='CONTEST_WON':
if(int(t[1])<=20):
laddus+=300+20-int(t[1])
else:
laddus+=300
elif t[0]=='TOP_CONTRIBUTOR':
laddus+=300
elif t[0]=='BUG_FOUND':
laddus+=int(t[1])
elif t... | vfc_2718 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/LADDU",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n4 INDIAN\nCONTEST_WON 1\nTOP_CONTRIBUTOR\nBUG_FOUND 100\nCONTEST_HOSTED\n4 NON_INDIAN\nCONTEST_WON 1\nTOP_CONTRIBUTOR\nBUG_FOUND 100\nCONTEST_HOSTED\n",
"output": "3\n1\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 970 | Solve the following coding problem using the programming language python:
You may have helped Chef and prevented Doof from destroying the even numbers. But, it has only angered Dr Doof even further. However, for his next plan, he needs some time. Therefore, Doof has built $N$ walls to prevent Chef from interrupting hi... | ```python
def posSearch(arr, num):
l = 0
r = len(arr)
if num < arr[l]:
return 0
elif num > arr[r-1]:
return r
while l < r:
m = (l+r)//2
if arr[m] == num:
return -1
if arr[m] < num < arr[m+1]:
return m+1
if arr[m] > num:
r = m
elif arr[m] < num:
l = m+1
for _ in range(int(input())):
n ... | vfc_2722 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/CLPNT",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n2\n1 3\n5\n0 0\n2 0\n0 4\n1 1\n1 2\n",
"output": "0\n1\n2\n1\n-1\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 971 | Solve the following coding problem using the programming language python:
You are given a sequence $A_1, A_2, \ldots, A_N$. You want all the elements of the sequence to be equal. In order to achieve that, you may perform zero or more moves. In each move, you must choose an index $i$ ($1 \le i \le N$), then choose $j =... | ```python
for _ in range(int(input())):
n=int(input())
a=[int(z) for z in input().split()]
m=0
a1=list(set(a))
for i in range(len(a1)):
if a.count(a1[i])>m:
m=a.count(a1[i])
print(n-m)
``` | vfc_2726 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/CHNGIT",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n5\n1 1 1 1 1\n4\n9 8 1 8\n2\n1 9\n",
"output": "0\n2\n1\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 972 | Solve the following coding problem using the programming language python:
-----
HALLOWEEN EVE
-----
In some other world, today is Halloween Eve.There are N trees planted in Mr. Smith’s
garden. The height of the i-th tree (1≤i≤N) is h i meters.
He decides to choose K trees from these trees and decorate them with elect... | ```python
try:
a=list(map(int,input().split()))
n=a[0]
k=a[1]
hi=[]
for i in range(n):
hi.append(int(input()))
hi.sort()
diff=[]
for i in range(n-k+1):
diff.append(hi[i+k-1]-hi[i])
print(min(diff))
except:
pass
``` | vfc_2730 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/APO12020/problems/APOC2_03",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 3\n10\n15\n11\n14\n12\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 973 | Solve the following coding problem using the programming language python:
You are given an $array$ of size $N$ and an integer $K$ ( $N > 1 , K > 0$ ).
Each element in the array can be incremented by $K$ or decremented by $K$ $at$ $most$ $once$.
So there will be $3^n$ possible combinations of final array. (As there ar... | ```python
# cook your dish here
testcases=int(input())
for _ in range(testcases):
(N,K)=list(map(int,input().split()))
array=list(map(int,input().split()))
max=array[0]
min=array[0]
for i in array:
if i>max:
max=i
if i<min:
min=i
ma... | vfc_2734 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/FUSN2020/problems/CKWR08",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n4 3\n4 2 5 1\n3 5\n2 5 3\n",
"output": "10\n13\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 974 | Solve the following coding problem using the programming language python:
Mr. Pr and Ms. Ad are at $a$ and $b$ respectively on an infinite number line. Mr. Pr wants to meet Ms. Ad.
Mr. Pr can choose to move $c$ or $d$ units in 1 second. If Mr. Pr moves $c$ units then Ms. Ad will move $d$ units and vice versa. (Both o... | ```python
for _ in range(int(input())):
a,b,c,d=list(map(int,input().split()))
if(a==b):
print('YES')
elif(c==d):
print('NO')
else:
if(abs(a-b)%abs(c-d)==0):
print('YES')
else:
print('NO')
``` | vfc_2738 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/ICM2020/problems/ICM2008",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n3 4 1 2\n10 20 3 7\n",
"output": "YES\nNO\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 975 | Solve the following coding problem using the programming language python:
The ZCO scholarship contest offers scholarships to first time ZCO participants. You are participating in it for the first time. So you want to know the number of participants who'll get the scholarship.
You know that the maximum number of schola... | ```python
for _ in range(int(input())):
n,r,x,y=map(int,input().split())
if x>0:
a=list(map(int,input().split()))
if y>0:
b=list(map(int,input().split()))
if x>0 and y>0:
a=a+b
c=n-len(list(set(a)))
else:
l=x+y
c=n-l
x=min(c,r)
print(x)
``` | vfc_2742 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/SCHTEST",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n5 3 0 1\n4\n10 2 4 6\n3 1 7 6\n4 3 1 5 9 7\n10 4 4 6\n3 1 7 6\n4 3 1 5 9 7\n",
"output": "3\n2\n3\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 976 | Solve the following coding problem using the programming language python:
Zonal Computing Olympiad 2012, 26 Nov 2011
We consider sequences of opening and closing brackets with two types of brackets, () and []. A bracket sequence is well-bracketed if we can pair up each opening bracket with a matching closing bracket... | ```python
# cook your dish here
n=int(input())
stringa=list(map(int,input().split()))
counter=0
counter1=0
counter3=0
somma1=0
somma2=0
massimo=0
massimo1=0
massimo3=0
stack=[]
for par in stringa:
if par==1 or par==3:
if counter1==0 and par==1:
counter1=1
somma1=1
massim... | vfc_2746 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/ZCOPRAC/problems/ZCO12003",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "14\n1 1 3 4 2 2 3 3 3 1 2 4 4 4\n",
"output": "2 6 8\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 977 | Solve the following coding problem using the programming language python:
Chef recently graduated Computer Science in university, so he was looking for a job. He applied for several job offers, but he eventually settled for a software engineering job at ShareChat. Chef was very enthusiastic about his new job and the f... | ```python
# cook your dish here
try:
for _ in range(int(input())):
n = int(input())
li = [i for i in input()]
a = 0
while a+1<len(li):
li[a],li[a+1] = li[a+1],li[a]
a+=2
li2 = li.copy()
for i in li2:
fh = 109
sh = 110
li.remove(i)
if ord(i)>fh:
li.append(chr(fh-(ord(i)-sh)))
else:
... | vfc_2750 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/ENCMSG",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n9\nsharechat\n4\nchef\n",
"output": "shizxvzsg\nsxuv\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 978 | Solve the following coding problem using the programming language python:
Chuck Norris just created a universe. He has already started the space-time continuum. Now he needs to fill the universe with matter and antimatter for the avatar cycle to start.
He created $N$ distinct pairs of elementary matter and their corre... | ```python
for i in range(int(input())):
n=int(input())
if(n<=2 or n>1000000007):
print("0")
else:
prod=1
for i in range(2,n):
prod*=i
if(prod>1000000007):
prod=prod%1000000007
print(((prod)*(n*prod-2))%1000000007)
``` | vfc_2754 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/PROC2020/problems/VC711",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n3\nSample output :\n8\n",
"output": "",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 979 | Solve the following coding problem using the programming language python:
You are given a grid of size M x N, where each square is colored with some random color among K colors with each having equal probability.
A Good Rectangle is defined as one where all squares lying on the inner border are of the same color.
Wh... | ```python
def for1(M,k):
ret = 0.0
x = k*k+0.0
z=x
for m in range(1,M):
ret+=(M-m)/x
x*=z
return ret
def for2(M,k):
ret = 0.0
x = k+0.0
for m in range(1,M):
ret+=(M-m)/x
x*=k
return ret
def ans(M,N,K):
return int(round(M*N+M*for2(N,K)+N*for2(M,K)+K*for1(M,K)*for1(N,K),0))
M,N,K = list(map(... | vfc_2758 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/IPC15P1C/problems/GRECT",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 3 1\n",
"output": "6\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 980 | Solve the following coding problem using the programming language python:
Jem is famous for his laziness at school. He always leaves things to last minute. Now Jem has N problems in the assignment of "Advanced topics in algorithm" class to solved. The assignment is due tomorrow and as you may guess he hasn't touch any... | ```python
for t in range(int(input())):
n,b,m = list(map(int,input().split()))
ans = 0
while n>0:
ans+=b
half = (n+1)/2 if n%2 else n/2
ans+=m*half
m*=2
n=n-half
print(ans-b)
``` | vfc_2762 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/COOK74/problems/TALAZY",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n9 1 2\n123456 123456 123456\n",
"output": "45\n131351258112\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 981 | Solve the following coding problem using the programming language python:
Chef is very fond of horses. He enjoys watching them race. As expected, he has a stable full of horses. He, along with his friends, goes to his stable during the weekends to watch a few of these horses race. Chef wants his friends to enjoy the r... | ```python
t=eval(input())
for q in range(t):
l=eval(input())
a=input().split()
a=[int(x) for x in a]
a=sorted(a)
for i in range(l-1):
a[i]=(a[i+1]-a[i])
print(min(a[0:l-1]))
``` | vfc_2766 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/SEP12/problems/HORSES",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n5\n4 9 1 32 13\n",
"output": "3\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 982 | Solve the following coding problem using the programming language python:
Special Numbers
Mani has encountered a problem on Special numbers in Bytecode. A number S is called a special number if its digits are in an arithmetic progression modulo 10. He has an array consisting of all numbers from 1 to N and needs your ... | ```python
# cook your code here
n=input()
x=len(n)
no=list(map(int,n))
temp=[0]*x
if (x>2):
sum=99
for i in range(3,x):
sum=sum+90
sum=sum+10*(int(n[0])-1)
sum=sum+int(n[1])
f=int(n[0])%10
s=int(n[1])%10
cd=s-f
temp[0]=n[0]
temp[1]=n[1]
for i in range(2,x):
nxt=(s+cd)%10
temp[i]=(chr(nxt+48))
s=... | vfc_2770 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/BYCO2016/problems/BYCD1603",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "123\n",
"output": "102\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 983 | Solve the following coding problem using the programming language python:
Omy and Ish were learning the pattern printing. In order to learn they give themselves a task. In this task they are given a string and they have to form a pyramid with the pattern as follows:
RowNumber are one based indexed.
-
If (RowNumber % ... | ```python
import sys
n = int(sys.stdin.readline().strip())
s = sys.stdin.readline().strip()
alph = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
arr = [0]*26
pref = []
for i in range(len(s)):
for j in range(26):
if alph[j] == s[i]:
arr[j] += 1
break
pref += [arr[:]]
# for x in pref:
# print(x)
q = i... | vfc_2774 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/LICO2020/problems/PATTERNG",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\nCODING\n2\n1 C\n2 D\n",
"output": "1\n1\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 984 | Solve the following coding problem using the programming language python:
Given an array $A$ of size $N$ , count number of pairs of index $i,j$ such that $A_i$ is even, $A_j$ is odd and $i < j$
-----Input-----
- The first line of the input contains a single integer $T$ denoting the number of test cases.
- The firs... | ```python
t = int(input())
for i in range(t):
n = int(input())
l = list(map(int, input().split()))
counter = 0
even = 0
for num in l:
if num % 2 == 0:
even += 1
if num % 2 == 1:
counter += even
print(counter)
``` | vfc_2778 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/CPAIRS",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n4\n1 2 1 3\n5\n5 4 1 2 3\n",
"output": "2\n3\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 985 | Solve the following coding problem using the programming language python:
This problem is about sequences of positive integers $a_1,a_2,...,a_N$. A subsequence of a sequence is anything obtained by dropping some of the elements. For example, $3,7,11,3$ is a subsequence of $6,3,11,5,7,4,3,11,5,3$ , but $3,3,7$ is not a... | ```python
# coding: utf-8
# Your code here!
n=int(input())
a=[]
for i in range(n):
x=int(input())
a.append(x)
# print(a)
ans=0
m=[1]*n
for i in range(n):
for j in range(i):
if a[i]%a[j]==0:
m[i]=max(m[i],m[j]+1)
print(max(m))
``` | vfc_2782 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/IARCSJUD/problems/DIVSEQ",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "9\n2\n3\n7\n8\n14\n39\n145\n76\n320\nSample output 1:\n3\nSample input 2:\n14\n2\n11\n16\n12\n36\n60\n71\n17\n29\n144\n288\n129\n432\n993\nSample output 2:\n5\n",
"output": "",
"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.