source stringclasses 1
value | task_type stringclasses 1
value | in_source_id stringlengths 1 4 | problem stringlengths 488 6.07k | gold_standard_solution stringlengths 19 30.1k | verification_info dict | metadata dict | problem_id stringlengths 5 9 |
|---|---|---|---|---|---|---|---|
apps | verifiable_code | 1054 | Solve the following coding problem using the programming language python:
Chef likes strings a lot but he likes palindromic strings even more. Today he found an old string s in his garage. The string is so old that some of its characters have faded and are unidentifiable now. Faded characters in the string are represe... | ```python
test=int(input())
for i in range(test):
s=input()
b=len(s)
list1=[]
for j in range(len(s)):
if s[j]=='.':
list1.append(j)
for i in list1:
if b-i-1 in list1 :
if i!=b-i-1 and ((s[i] and s[b-i-1]) != 'a' ):
s=s[:i]+'a'+s[i+1:b-i-1]+'a'+... | {
"language": "python",
"test_cases": [
{
"input": "3\na.ba\ncb.bc\na.b\n",
"output": "abba\ncbabc\n-1\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/LEXOPAL"
} | vfc_3058 |
apps | verifiable_code | 1055 | Solve the following coding problem using the programming language python:
Chef is planning a huge party for all of you and has ordered M pizzas. He wants to invite as many people to the party. However, he knows that everyone will have exactly one slice of a pizza (regardless of the size) and he wants to make sure that... | ```python
# cook your dish here
m,n=[int(i) for i in input().split()]
arr=list(map(int,input().split()))
arr=sorted(arr,reverse=True)
ans=0
w=0
q=m
for m in range(q):
if(arr[m]>n):
w=1
break
ans+=1+(arr[m]*(arr[m]+1))//2
n-=arr[m]
if(n==0):
print(ans)
else:
if(w==1... | {
"language": "python",
"test_cases": [
{
"input": "5 10\n1 2 3 4 5\n\n",
"output": "31\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/PIZPAR"
} | vfc_3062 |
apps | verifiable_code | 1056 | Solve the following coding problem using the programming language python:
Write a program to check whether a triangle is valid or not, when the three angles of the triangle are the inputs. A triangle is valid if the sum of all the three angles is equal to 180 degrees.
-----Input-----
The first line contains an integ... | ```python
n=int(input())
for i in range(n):
a,b,c=map(int,input().split())
if a>0 and b>0 and c>0 and a+b+c==180:
print("YES")
else:
print("NO")
``` | {
"language": "python",
"test_cases": [
{
"input": "3 \n40 40 100\n45 45 90\n180 1 1\n\n",
"output": "YES\nYES\nNO\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/FLOW013"
} | vfc_3066 |
apps | verifiable_code | 1057 | Solve the following coding problem using the programming language python:
Alice is a very brilliant student. He considers '4' and '7' as Magic numbers. The numbers containing only magic numbers are also magical. Given a magic number N ,he wants to know what could be the next magical number greater than the given numbe... | ```python
import math
def magic(a,digits):
m=a%10
if(m==4):
return a+3
elif(m==7):
p=list(str(a))
#print p
for i in range(digits-1,-1,-1):
#print p[i]
if (p[i]=='4'):
#print 'four'
p[i]='7'
p = ''.join(s... | {
"language": "python",
"test_cases": [
{
"input": "2\n4\n47\n\n\n",
"output": "7\n74\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/ALKH2012/problems/NMAGIC"
} | vfc_3070 |
apps | verifiable_code | 1058 | Solve the following coding problem using the programming language python:
There is a popular apps named “Exbook” like “Facebook”. To sign up in this app , You have to make a strong password with more than 3 digits and less than 10 digits . But I am a pro hacker and so I make a Exbook hacking site . You need to login i... | ```python
# cook your dish here
t=int(input())
for i in range(0,t):
p=input()
l=list(p)
for j in range(0,len(l)):
l[j]=int(l[j])
l[j]=l[j]-2
for j in range(0,len(l)):
l[j]=str(l[j])
q=''.join(l)
print(q)
``` | {
"language": "python",
"test_cases": [
{
"input": "2\n3527\n47269\n",
"output": "1305\n25047\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/ABCC2020/problems/PASSHACK"
} | vfc_3074 |
apps | verifiable_code | 1059 | Solve the following coding problem using the programming language python:
You have an array A of size N containing only positive numbers. You have to output the maximum possible value of A[i]%A[j] where 1<=i,j<=N.
-----Input-----
The first line of each test case contains a single integer N denoting the size of the a... | ```python
n = int(input())
a = []
for i in range(n):
a.append(int(input()))
m1 = 0
m2 = 0
for e in a:
if (e > m1):
m2 = m1
m1 = e
elif (e > m2 and e != m1):
m2 = e
ans = 0
for e in a:
temp = m1%e
if (temp>ans):
ans = temp
print(max(m2%m1,ans))
``` | {
"language": "python",
"test_cases": [
{
"input": "2\n1\n2\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/LOCMAR16/problems/MOD"
} | vfc_3078 |
apps | verifiable_code | 1060 | Solve the following coding problem using the programming language python:
Chef and Abhishek both are fighting for the post of Chairperson to be part of ACE committee and are trying their best. To select only one student their teacher gave them a binary string (string consisting of only 0's and 1's) and asked them to f... | ```python
def countSubstr(str, n, x, y):
tot_count = 0
count_x = 0
for i in range(n):
if str[i] == x:
count_x += 1
if str[i] == y:
tot_count += count_x
return tot_count
t=int(input())
for _ in range(t):
n=int(input())
str... | {
"language": "python",
"test_cases": [
{
"input": "1\n4\n1010\n",
"output": "4\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/CEFT2020/problems/QFUN"
} | vfc_3082 |
apps | verifiable_code | 1061 | Solve the following coding problem using the programming language python:
Chef is playing with an expression which consists of integer operands and the following binary
Bitwise operators - AND, OR and XOR. He is trying to figure out that what could be the Maximum possible answer of the expression, given that he can p... | ```python
# cook your dish here
def value(a, b, c):
if(c == '&'):
return a&b
elif(c == '^'):
return a^b
elif(c == '|'):
return a|b
def break_rules(n, operator):
if(len(n) == 1):
return n
elif(len(n) == 2):
return [value(n[0], n[1], operator[0])]
else:
... | {
"language": "python",
"test_cases": [
{
"input": "2\n3^40|10^2\n92^95|56&2&3\n",
"output": "43\n95\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/BIT2C"
} | vfc_3086 |
apps | verifiable_code | 1063 | Solve the following coding problem using the programming language python:
Write a program to find the remainder when an integer A is divided by an integer B.
-----Input-----
The first line contains an integer T, the total number of test cases. Then T lines follow, each line contains two Integers A and B.
-----Outp... | ```python
number = int(input())
for i in range(number):
x = list(map(int, input().split(' ')))
print(x[0]%x[1])
``` | {
"language": "python",
"test_cases": [
{
"input": "3\n1 2\n100 200\n40 15\n",
"output": "1\n100\n10\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/FLOW002"
} | vfc_3094 |
apps | verifiable_code | 1064 | Solve the following coding problem using the programming language python:
Chef Ciel wants to put a fancy neon signboard over the entrance of her restaurant. She has not enough money to buy the new one so she bought some old neon signboard through the internet. Ciel was quite disappointed when she received her order - ... | ```python
from math import gcd
import sys
input=lambda : sys.stdin.readline().strip()
c=lambda x: 10**9 if(x=="?") else int(x)
def main():
for _ in range(int(input())):
s=list(input())[::-1]
l=['F','E','H','C']
i=0
while(i<len(s)):
if(i+3<len(s)):
f=True
for j in range(i,i+4):
if(l[j-i]==s[j] o... | {
"language": "python",
"test_cases": [
{
"input": "5\n????CIELIS???E?\n????CIELISOUR???F\nT?KEITE?SY\n????????\n???C???\n",
"output": "CHEFCIELISACHEF\nCHEFCIELISOURCHEF\nTAKEITEASY\nCHEFCHEF\nAAACHEF\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/MANYCHEF"
} | vfc_3098 |
apps | verifiable_code | 1065 | Solve the following coding problem using the programming language python:
Chefland is a grid with N$N$ rows and M$M$ columns. Each cell of this grid is either empty or contains a house. The distance between a pair of houses is the Manhattan distance between the cells containing them.
For each d$d$ between 1$1$ and N+M... | ```python
# cook your dish here
for a in range(int(input())):
N,M=map(int,input().split())
b=[]
for o in range(N):
b.append(input())
c=[]
for d in b:
f=[]
for e in range(len(d)):
if d[e]=='1':
f.append(e)
c.append(f)
i=[]
for g in range(len(c)):
for h in... | {
"language": "python",
"test_cases": [
{
"input": "1\n3 4\n0011\n0000\n0100\n",
"output": "1 0 1 1 0\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/AVGMAT"
} | vfc_3102 |
apps | verifiable_code | 1066 | Solve the following coding problem using the programming language python:
-----
CHEF N TIMINGS
-----
One day chef was working with some random numbers. Then he found something
interesting. He observed that no 240, 567, 9999 and 122 and called these numbers
nice as the digits in numbers are in increasing order. Also h... | ```python
for _ in range(int(input())):
n=input().rstrip()
n=[ele for ele in n]
l=len(n)
m=10**18+8
ini=1
for i in range(l-1,-1,-1):
if int(n[i])<=m:
if ini==1:
m=int(n[i])
else:
m=max(m,n[i])
else:
m=int(n[i])-1
n[i]=str(m)
for j in range(l-1,i,-1):
n[j]='9'
i=0
while n[i]=='... | {
"language": "python",
"test_cases": [
{
"input": "1\n132\n",
"output": "129\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/APO12020/problems/APOC2_04"
} | vfc_3106 |
apps | verifiable_code | 1067 | Solve the following coding problem using the programming language python:
Chef has a strip of length $N$ units and he wants to tile it using $4$ kind of tiles
-A Red tile of $2$ unit length
-A Red tile of $1$ unit length
-A Blue tile of $2$ unit length
-A Blue tile of $1$ unit length
Chef is having an infinite ... | ```python
# Fibonacci Series using
# Optimized Method
# function that returns nth
# Fibonacci number
MOD = 1000000007
def fib(n):
F = [[2, 2],
[1, 0]]
power(F, n - 1)
ans = [6, 2]
return (F[0][0] * 6 + F[0][1] * 2) % MOD
# return F[0][0]
def multiply(F, M):
x = (F[... | {
"language": "python",
"test_cases": [
{
"input": "1\n2\n",
"output": "6\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/COG2020/problems/COG2004"
} | vfc_3110 |
apps | verifiable_code | 1068 | Solve the following coding problem using the programming language python:
Ada's classroom contains $N \cdot M$ tables distributed in a grid with $N$ rows and $M$ columns. Each table is occupied by exactly one student.
Before starting the class, the teacher decided to shuffle the students a bit. After the shuffling, ea... | ```python
# cook your dish here
t=int(input())
for _ in range(t):
N, M=map(int,input().split())
if(N%2==0 or M%2==0):
print("YES")
else:
print("NO")
``` | {
"language": "python",
"test_cases": [
{
"input": "2\n3 3\n4 4\n",
"output": "NO\nYES\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/ADASCOOL"
} | vfc_3114 |
apps | verifiable_code | 1069 | Solve the following coding problem using the programming language python:
Shivam is the youngest programmer in the world, he is just 12 years old. Shivam is learning programming and today he is writing his first program.
Program is very simple, Given two integers A and B, write a program to add these two numbers.
-... | ```python
#Note that it's python3 Code. Here, we are using input() instead of raw_input().
#You can check on your local machine the version of python by typing "python --version" in the terminal.
#Read the number of test cases.
T = int(input())
for tc in range(T):
# Read integers a and b.
(a, b) = list(map(int, inpu... | {
"language": "python",
"test_cases": [
{
"input": "3\n1 2\n100 200\n10 40\n",
"output": "3\n300\n50\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/FLOW001"
} | vfc_3118 |
apps | verifiable_code | 1071 | Solve the following coding problem using the programming language python:
Bob just learned about bitwise operators. Since Alice is an expert, she decided to play a game, she will give a number $x$ to Bob and will ask some questions:
There will be 4 different kinds of queries:-
-
Alice gives an integer $i$ and Bob has... | ```python
# cook your dish here
t=int(input())
while t>0:
n,q=list(map(int,input().split()))
blst=[0]
for i in range(1,65):
blst.append(0)
i=1
while n>0:
if n%2:
blst[i]=1
n//=2
i+=1
while q>0:
n=int(input())
if n==1:
p=int(... | {
"language": "python",
"test_cases": [
{
"input": "1\n2 2\n2\n1\n1\n1\n",
"output": "ON\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/ENDE2020/problems/ENCDEC03"
} | vfc_3126 |
apps | verifiable_code | 1072 | Solve the following coding problem using the programming language python:
Problem description.
Winston and Royce love sharing memes with each other. They express the amount of seconds they laughed ar a meme as the number of ‘XD’ subsequences in their messages. Being optimization freaks, they wanted to find the string ... | ```python
t=int(input())
for i in range(t):
n=int(input())
r=int(n**(.5))
d=n-r*r
m=d%r
print('X'*m+'D'*(m>0)+'X'*(r-m)+'D'*(r+d//r))
``` | {
"language": "python",
"test_cases": [
{
"input": "1\n9\n",
"output": "XXXDDD\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/XDS"
} | vfc_3130 |
apps | verifiable_code | 1073 | Solve the following coding problem using the programming language python:
You are given two integers $N$ and $M$. Find the number of sequences $A_1, A_2, \ldots, A_N$, where each element is an integer between $1$ and $M$ (inclusive) and no three consecutive elements are equal. Since this number could be very large, co... | ```python
import sys
def fin(): return sys.stdin.readline().strip()
def fout(s, end="\n"): sys.stdout.write(str(s)+end)
MOD = pow(10, 9)+7
t = int(input())
while t>0:
t -= 1
n, m = list(map(int, fin().split()))
if n == 1:
print(m%MOD)
continue
dp1 = m*(m-1)
dp2 = m
for i in range(3, n+1):
temp = dp2
dp2 ... | {
"language": "python",
"test_cases": [
{
"input": "2\n2 2\n3 4\n",
"output": "4\n60\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/CARR"
} | vfc_3134 |
apps | verifiable_code | 1074 | Solve the following coding problem using the programming language python:
Chef is making Window frames for his new office, for this he has n wooden Logs whose lengths are l1, l2, … ln respectively. Chef Doesn’t want to break any logs or Stick 2 or more logs together.
To make a h × w Window Frame, he needs two Logs w... | ```python
# cook your dish here
t=int(input())
j=0
while j<t:
n=int(input())
lst=list(map(int,input().split()))
s=set()
d=list()
for i in lst:
if i in s:
s.remove(i)
d.append(i)
else:
s.add(i)
x=len(d)
if x%2==0:
print(x//2)
els... | {
"language": "python",
"test_cases": [
{
"input": "2\n4\n1 2 1 2\n8\n1 2 1 3 4 1 5 6\n",
"output": "1\n0\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/NITJ2021/problems/CIN005"
} | vfc_3138 |
apps | verifiable_code | 1075 | Solve the following coding problem using the programming language python:
Henry and Derek are waiting on a room, eager to join the Snackdown 2016 Qualifier Round. They decide to pass the time by playing a game.
In this game's setup, they write N positive integers on a blackboard. Then the players take turns, startin... | ```python
gb = [0, 1, 2, 2, 3, 3]
ga = [0 for x in range(70)]
gag = [0 for x in range(70)]
ga[0] = 1
gag[0] = 0
for i in range(1, 70):
if i % 4 == 0:
ga[i] = 1.5 * ga[i-1]
gag[i] = 0
else:
ga[i] = 2 * ga[i-1]
gag[i] = gag[i-1] + 1
def g(n):
if n < 6:
return gb[n]
else:
x = n / 6
a = 0
for i, k in... | {
"language": "python",
"test_cases": [
{
"input": "2\n2\n3 4\n3\n1 3 5\n",
"output": "Henry\nDerek\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/SNCKQL16/problems/FDIVGAME"
} | vfc_3142 |
apps | verifiable_code | 1077 | Solve the following coding problem using the programming language python:
Chef recently printed directions from his home to a hot new restaurant across the town, but forgot to print the directions to get back home. Help Chef to transform the directions to get home from the restaurant.
A set of directions consists of s... | ```python
t = int(input())
for i in range(t):
n = int(input())
dir = []
for j in range(n):
dir.append(input().strip().split())
for j in range(n-1):
if dir[j+1][0] == 'Right':
dir[j][0] = 'Left'
else:
dir[j][0] = 'Right'
dir[n-1][0] = 'Begin'
... | {
"language": "python",
"test_cases": [
{
"input": "2\n4\nBegin on Road A\nRight on Road B\nRight on Road C\nLeft on Road D\n6\nBegin on Old Madras Road\nLeft on Domlur Flyover\nLeft on 100 Feet Road\nRight on Sarjapur Road\nRight on Hosur Road\nRight on Ganapathi Temple Road\n\n",
"output": "Begin ... | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/COOK29/problems/DIRECTI"
} | vfc_3150 |
apps | verifiable_code | 1078 | Solve the following coding problem using the programming language python:
For her next karate demonstration, Ada will break some bricks.
Ada stacked three bricks on top of each other. Initially, their widths (from top to bottom) are $W_1, W_2, W_3$.
Ada's strength is $S$. Whenever she hits a stack of bricks, consider ... | ```python
t=int(input())
for i in range(t):
n,w1,w2,w3=map(int,input().split())
if n>=w1+w2+w3:
print(1)
elif n>=w1+w2 or n>=w2+w3:
print(2)
else:
print(3)
``` | {
"language": "python",
"test_cases": [
{
"input": "3\n3 1 2 2\n2 1 1 1\n3 2 2 1\n",
"output": "2\n2\n2\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/BRKBKS"
} | vfc_3154 |
apps | verifiable_code | 1079 | Solve the following coding problem using the programming language python:
Kostya likes the number 4 much. Of course! This number has such a lot of properties, like:
- Four is the smallest composite number;
- It is also the smallest Smith number;
- The smallest non-cyclic group has four elements;
- Four is the maximal... | ```python
# cook your dish here
x=int(input())
for i in range(x):
h=input()
print(h.count('4'))
``` | {
"language": "python",
"test_cases": [
{
"input": "5\n447474\n228\n6664\n40\n81\n",
"output": "4\n0\n1\n1\n0\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/LUCKFOUR"
} | vfc_3158 |
apps | verifiable_code | 1080 | Solve the following coding problem using the programming language python:
Every day, Mike goes to his job by a bus, where he buys a ticket. On the ticket, there is a letter-code that can be represented as a string of upper-case Latin letters.
Mike believes that the day will be successful in case exactly two different ... | ```python
def res(s):
if len(s) == 2:
if s[0] == s[1]:
print("NO")
else:
print("YES")
elif s[0] != s[1]:
counte = 0
for i in range(2, len(s)):
if i % 2 == 0:
if s[i] != s[0]:
counte = 1
break
else:
if s[i] != s[1]:
counte = 1
break
if counte == 0:
print("YES")
... | {
"language": "python",
"test_cases": [
{
"input": "2\nABABAB\nABC\n",
"output": "YES\nNO\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/TICKETS5"
} | vfc_3162 |
apps | verifiable_code | 1081 | Solve the following coding problem using the programming language python:
A spy needs your help to encrypt a 5 letter message.
To encrypt the message the following steps are need to be done:
1)Each letter of the message will be converted to it's equivalent number (i.e A=0, B=1,..Z=25)
2)98, 57, 31, 45, 46 are the 5 ... | ```python
# cook your dish here
import string
from collections import OrderedDict
from itertools import zip_longest
dic = OrderedDict(zip(string.ascii_uppercase, range(0, 26)))
keys = [98, 57, 31, 45, 46]
t = int(input()) # number of test cases
s1 = []
for i in range(t):
s = input()
for i in s:
if i in dic.key... | {
"language": "python",
"test_cases": [
{
"input": "2\nHELLO\nHELL\n",
"output": "BJQEI\nBJQE\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/STRG2020/problems/ENCYP"
} | vfc_3166 |
apps | verifiable_code | 1082 | Solve the following coding problem using the programming language python:
$Jaggu$ monkey a friend of $Choota$ $Bheem$ a great warrior of $Dholakpur$. He gets everything he wants. Being a friend of $Choota$ $Bheem$ he never has to struggle for anything, because of this he is in a great debt of $Choota$ $Bheem$, he real... | ```python
counter = -1
def flattree(node):
nonlocal counter
if visited[node]==1:
return
else:
visited[node]=1
counter += 1
i_c[node] = counter
flat_tree[counter] = swt[node]
for i in graph[node]:
if visited[i]==0:
fl... | {
"language": "python",
"test_cases": [
{
"input": "10\n10 12 6 8 1 19 0 5 13 17\n1 2\n1 3\n1 4\n3 10\n4 8\n8 9\n4 5\n5 7\n5 6\n3\n1 1\n2 3 20\n1 8\n",
"output": "10\n23\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/COFY2020/problems/GKSMNHM"
} | vfc_3170 |
apps | verifiable_code | 1083 | Solve the following coding problem using the programming language python:
Probably everyone has experienced an awkward situation due to shared armrests between seats in cinemas. A highly accomplished cinema manager named "Chef" decided to solve this problem.
When a customer wants to buy a ticket, the clerk at the tic... | ```python
for i in range(eval(input())):
n,m,z,l,r,b = list(map(int, input().split()))
rows=n
columns=m
hand_rest=n*(m+1)
if(m%2==0):
hand_rest -=max(0,n-l-r)
if(l+r+(2*b)<=hand_rest):
# print "kanu"
print(min(n*m,l+r+z+b))
else:
temp=l+r+(hand_rest-l-r)/2
# print "parth"
print(min(n*m,temp+z))
``` | {
"language": "python",
"test_cases": [
{
"input": "2\n2 2 3 2 1 1\n3 3 1 2 0 9\n",
"output": "4\n8\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/DEC15/problems/CHCINEMA"
} | vfc_3174 |
apps | verifiable_code | 1084 | Solve the following coding problem using the programming language python:
You are given a binary string S. You need to transform this string into another string of equal length consisting only of zeros, with the minimum number of operations.
A single operation consists of taking some prefix of the string S and flippin... | ```python
# cook your dish here
s=input()
s1=s[::-1]
arr=[]
cnt=0
for i in range(len(s1)):
arr.append(s1[i])
for i in range(len(arr)):
if(arr[i]=="1"):
for j in range(i,len(arr)):
if(arr[j]=="1"):
arr[j]="0"
else:
arr[j]="1"
cnt+=1
print(cnt)
``` | {
"language": "python",
"test_cases": [
{
"input": "01001001\n",
"output": "6\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/PREFINVS"
} | vfc_3178 |
apps | verifiable_code | 1086 | Solve the following coding problem using the programming language python:
Let's define the niceness of a sequence of positive integers X1,X2,…,XN$X_1, X_2, \dots, X_N$ as the sum of greatest common divisors of all pairs of its elements, i.e.
N∑i=1N∑j=i+1gcd(Xi,Xj).∑i=1N∑j=i+1Ngcd(Xi,Xj).\sum_{i=1}^N \sum_{j=i+1}^N \ma... | ```python
# cook your dish here
mod = 10**9 + 7
from math import gcd
def fac50():
f = [0]*51
f[0] ,f[1] = 1,1
for i in range(1,51):f[i] = (f[i-1]*i)%mod
return f
def gcd110():
gc = [[0]*111 for i in range(111)]
for i in range(111):
for j in range(111):gc[i][j] = gcd(i,j)
return gc
fa... | {
"language": "python",
"test_cases": [
{
"input": "3\n3 3\n1 1 -1\n4 8\n1 -1 -1 3\n3 10\n-1 -1 -1\n\n",
"output": "3\n23\n150\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/NICARRAY"
} | vfc_3186 |
apps | verifiable_code | 1087 | Solve the following coding problem using the programming language python:
You are given an unweighted, undirected graph. Write a program to check if it's a tree topology.
-----Input-----
The first line of the input file contains two integers N and M --- number of nodes and number of edges in the graph (0 < N <= 1000... | ```python
#!/usr/bin/env python
def iscycle(E, v, EXPLORED_NODES, EXPLORED_EDGES):
EXPLORED_NODES.add(v)
r = False
for e in [x for x in E if v in x]:
if e in EXPLORED_EDGES: continue
if e[0] == v: w = e[1]
else: w = e[0]
if w in EXPLORED_NODES:
return True
else:
EXPLORED_EDGES.add(e)
r = ... | {
"language": "python",
"test_cases": [
{
"input": "3 2\n1 2\n2 3\n",
"output": "YES\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/PRFT2012/problems/PD31"
} | vfc_3190 |
apps | verifiable_code | 1088 | Solve the following coding problem using the programming language python:
Two cheeky thieves (Chef being one of them, the more talented one of course) have came across each other in the underground vault of the State Bank of Churuland. They are shocked! Indeed, neither expect to meet a colleague in such a place with t... | ```python
t=int(input())
while(t):
s=input().split()
m=int(s[0])
p=float(s[1])
if(m%2==0):
r=(1-p**m)/(p+1)
else:
r=(1+p**m)/(p+1)
print(1000000000*r,1000000000*(1-r))
t-=1
``` | {
"language": "python",
"test_cases": [
{
"input": "2\n1 0.5\n2 0.5\n",
"output": "1000000000.0 0.0\n500000000.0 500000000.0\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/BANROB"
} | vfc_3194 |
apps | verifiable_code | 1089 | Solve the following coding problem using the programming language python:
The garden has a tree with too many leaves on it and gardner wants to cut the unwanted leaves. This is a rooted tree, where a node $v$ is called parent of another node $u$, if there exists a directed edge from $v$ to $u$. Leaf node is a node wit... | ```python
def dfs(node):
nonlocal adj,leaf
val=0
flag=0
for i in adj[node]:
x= dfs(i)
val+=x
if x==0:
flag=1
leaf+=val-val%3
if val%3==0 and flag==0:
return 1
else:
return 0
for _ in range(int(input())):
n=int(input())
adj=[[] for i in range(n+2)]
arr=[int(i) for i in input().split()]
leaf=0
#p... | {
"language": "python",
"test_cases": [
{
"input": "1\n13\n1 1 1 1 1 4 3 4 4 3 4 3\n",
"output": "4\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/ECPG2020/problems/ECPC10D"
} | vfc_3198 |
apps | verifiable_code | 1090 | Solve the following coding problem using the programming language python:
You are given a sequence of n integers a1, a2, ..., an and an integer d.
Find the length of the shortest non-empty contiguous subsequence with sum of elements at least d. Formally, you should find the smallest positive integer k with the followi... | ```python
# cook your dish here
import collections
def shortestSubarray(A, K):
N = len(A)
P = [0]
for x in A:
P.append(P[-1] + x)
#Want smallest y-x with Py - Px >= K
ans = N+1 # N+1 is impossible
monoq = collections.deque() #opt(y) candidates, represented as indices of P
for y, P... | {
"language": "python",
"test_cases": [
{
"input": "2\n5 5\n1 2 3 1 -5\n5 1\n1 2 3 1 -5\n",
"output": "2\n1\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/MINSUBAR"
} | vfc_3202 |
apps | verifiable_code | 1091 | Solve the following coding problem using the programming language python:
Rupsa really loves triangles. One day she came across an equilateral triangle having length of each side as an integer N. She started wondering if it was possible to transform the triangle keeping two sides fixed and alter the third side such th... | ```python
# cook your dish here
import math
def isPos(num):
if num%2==0:
for i in range(num,2*num,1):
if ((num**2)-((i/2)**2))**(1/2)==int(((num**2)-((i/2)**2))**(1/2)):
return 'YES'
return 'NO'
else:
for i in range(num+1,2*num,1):
if ((num**2)-((i/2)**2))**(1/2)==int(((num**2)-((i/2)**2))**(1/2)):
... | {
"language": "python",
"test_cases": [
{
"input": "2\n5\n3\n",
"output": "YES\nNO\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/ADTRI"
} | vfc_3206 |
apps | verifiable_code | 1092 | Solve the following coding problem using the programming language python:
The faculty of application management and consulting services (FAMCS) of the Berland State University (BSU) has always been popular among Berland's enrollees. This year, N students attended the entrance exams, but no more than K will enter the u... | ```python
# cook your dish here
t=int(input())
for i in range(t):
(n,k,e,m)=tuple(map(int,input().split()))
scores=[]
for j in range(n-1):
scores.append(sum(list(map(int,input().split()))))
scores.sort(reverse=True);
bsc=scores[k-1];
msc=sum(list(map(int,input().split())))
mini=bsc-msc+1
if(mini<0):
print(0... | {
"language": "python",
"test_cases": [
{
"input": "1\n4 2 3 10\n7 7 7\n4 6 10\n7 10 9\n9 9\n",
"output": "4\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/ENTEXAM"
} | vfc_3210 |
apps | verifiable_code | 1093 | Solve the following coding problem using the programming language python:
Chef likes toys. His favourite toy is an array of length N. This array contains only integers. He plays with this array every day. His favourite game with this array is Segment Multiplication. In this game, the second player tells the left and r... | ```python
# # # # n = int(input())
# # # # arr = list(map(int , input().split()))
# # # # for _ in range(int(input())):
# # # # l,r,mod = map(int , input().split())
# # # # pro = 1
# # # # for i in range(l - 1,r):
# # # # pro *= arr[i]
# # # # print(pro % mod) #sample testcases passed #TLE
# # # import nu... | {
"language": "python",
"test_cases": [
{
"input": "5\n1 2 3 4 5\n4\n1 2 3\n2 3 4\n1 1 1\n1 5 1000000000\n",
"output": "2\n2\n0\n120\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/CHMOD"
} | vfc_3214 |
apps | verifiable_code | 1094 | Solve the following coding problem using the programming language python:
Two words rhyme if their last 3 letters are a match. Given N words, print the test case number (of the format Case : num) followed by the rhyming words in separate line adjacent to each other.
The output can be in anyorder.
-----Input-----
Fir... | ```python
t = int(input())
for i in range(t):
n = int(input())
suffixes = {}
xx = input().split()
for x in range(n):
try:
a = suffixes[xx[x][-3:]]
except Exception as e:
a = []
a.append(xx[x])
suffixes.update({xx[x][-3:]: a})
print("Case : %d" % (i + 1))
for a in sorted(suffixes):
print("".join(... | {
"language": "python",
"test_cases": [
{
"input": "3\n3\nnope qwerty hope\n5\nbrain drain request grain nest\n4\nthese words dont rhyme\n",
"output": "Case : 1\nhope nope\nqwerty\nCase : 2\nbrain drain grain\nnest request\nCase : 3\nthese\ndont\nwords\nrhyme\n",
"type": "stdin_stdout"
}
... | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/COWA2016/problems/CWAM1502"
} | vfc_3218 |
apps | verifiable_code | 1095 | Solve the following coding problem using the programming language python:
Indraneel has to sort the books in his library. His library has one long shelf. His books are numbered $1$ through $N$ and he wants to rearrange the books so that they appear in the sequence $1,2, ..., N$.
He intends to do this by a sequence of ... | ```python
n=int(input())
arr=[int(x) for x in input().split()]
l=[1]*n
if sorted(arr)==arr:
print('0')
else:
for i in range(0,len(arr)):
for j in range(i):
if arr[i]>=arr[j] and l[i]<l[j]+1:
l[i]=l[j]+1
print(n-max(l))
``` | {
"language": "python",
"test_cases": [
{
"input": "5\n2 1 4 5 3\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/IARCSJUD/problems/BOOKSORT"
} | vfc_3222 |
apps | verifiable_code | 1096 | Solve the following coding problem using the programming language python:
Zonal Computing Olympiad 2012, 26 Nov 2011
The year is 2102 and today is the day of ZCO. This year there are N contests and the starting and ending times of each contest is known to you. You have to participate in exactly one of these contests.... | ```python
import sys
n, x, y = input().split(' ')
n = int(n)
x = int(x)
y = int(y)
contests = {}
for i in range(n):
s, e = input().split(' ')
s = int(s)
e = int(e)
contests[(s, e)] = abs(s-e)
v_time = input().split(' ')
w_time = input().split(' ')
v_time, w_time = list(map(int, v_time)), list(map(int, w_time))
v... | {
"language": "python",
"test_cases": [
{
"input": "3 4 2\n15 21\n5 10\n7 25\n4 14 25 2\n13 21\n",
"output": "8\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/ZCOPRAC/problems/ZCO12002"
} | vfc_3226 |
apps | verifiable_code | 1097 | Solve the following coding problem using the programming language python:
Sinchan and his friends loves to eat. They have a 2D rectangular cake which they want to share. Sinchan is very kind and offers his friends to eat the cake first, all friends goes one by one to eat the cake. Each friend will cut cake into two pa... | ```python
testcases=int(input())
results=[]
for i in range(0,testcases):
friends=int(input())
l,b=list(map(int,input().split()))
over=False
if b>l:
temp=b
b=l
l=temp
for counter in range(0,friends):
if l==b:
over=True
break
elif l>b:
l=l-b
if b>l:
temp=b
b=l
l=temp
if over:
... | {
"language": "python",
"test_cases": [
{
"input": "3\n2\n5 3\n4\n4 8\n1\n1 2\n",
"output": "Yes 2\nNo\nYes 1\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/CDGO2016/problems/CDGO1601"
} | vfc_3230 |
apps | verifiable_code | 1098 | Solve the following coding problem using the programming language python:
Chef and Roma are playing a game. Rules of the game are quite simple.
Initially there are N piles of stones on the table.
In each turn, a player can choose one pile and remove it from the table.
Each player want to maximize the total number of s... | ```python
# cook your dish here
for i in range(int(input())):
n = int(input())
l = list(map(int,input().split()))
s = 0
l.sort(reverse = True)
for i in range(0,n,2):
s = s+l[i]
print(s)
``` | {
"language": "python",
"test_cases": [
{
"input": "2\n3\n1 2 3\n3\n1 2 1\n",
"output": "4\n3\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/CHEFA"
} | vfc_3234 |
apps | verifiable_code | 1099 | Solve the following coding problem using the programming language python:
Did you know that there are over 40,000 varieties of Rice in the world ? There are so many dishes that can be prepared with Rice too. A famous chef from Mumbai, Tid Gusto prepared a new dish and named it 'Tid Rice'. He posted the recipe in his n... | ```python
import sys
def f(p):
votes = {}
for x in range(p):
str = sys.stdin.readline()
t = str.split()
votes[t[0]] = t[1]
ans = 0
for per in votes:
if votes[per] == "+":
ans= ans+1
else:
ans = ans-1
return ans
x = sys.stdin.readline()
for t in range(int(x)):
p = sys.stdi... | {
"language": "python",
"test_cases": [
{
"input": "3\n4\ntilak +\ntilak +\ntilak -\ntilak +\n3\nratna +\nshashi -\nratna -\n3\nbhavani -\nbhavani +\nbhavani -\n",
"output": "1\n-2\n-1\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/COOK10/problems/TIDRICE"
} | vfc_3238 |
apps | verifiable_code | 1100 | Solve the following coding problem using the programming language python:
This question is similar to the $"Operation$ $on$ $a$ $Tuple"$ problem in this month's Long Challenge but with a slight variation.
Consider the following operations on a triple of integers. In one operation, you should:
- Choose a positive int... | ```python
# cook your dish here
"""
Input:
The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains three space-separated integers p, q and r.
The second line contains three space-separated integers a, b... | {
"language": "python",
"test_cases": [
{
"input": "1\n2 2 1\n3 3 2\n",
"output": "3\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/ENJU2020/problems/ECJN201"
} | vfc_3242 |
apps | verifiable_code | 1101 | Solve the following coding problem using the programming language python:
After failing to clear his school mathematics examination, infinitepro decided to prepare very hard for his upcoming re-exam, starting with the topic he is weakest at ― computational geometry.
Being an artist, infinitepro has C$C$ pencils (numbe... | ```python
from collections import Counter
from math import factorial
def nc3(n):
a=factorial(n)
b=factorial(n-3)
return ((a)/(b*6))
def rem(s,k):
t=-1
x=-1
for i in range(len(s)):
if s[i][0]>2 and s[i][1]<=k:
if s[i][0]>3:
ch=(nc3(s[i][0])-nc3(s[i]... | {
"language": "python",
"test_cases": [
{
"input": "2\n7 2 13\n1 10 1\n1 14 2\n6 4 1\n2 2 1\n0 12 2\n2 11 2\n0 6 1\n8 10\n6 1 20\n1 5 1\n2 11 1\n4 0 1\n6 8 1\n0 11 1\n3 3 1\n9\n",
"output": "2\n4\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/ACCBIP"
} | vfc_3246 |
apps | verifiable_code | 1102 | Solve the following coding problem using the programming language python:
On Miu's smart phone, there is a search feature which lets her search for a contact name by typing digits on the keypad where each digit may correspond to any of the characters given below it. For example, to search for TOM, she can type 866 and... | ```python
for _ in range(int(input())):
n=int(input())
n1=0
ans=1
while(n>0):
d=int(n % 10)
if(d!=0):
if(d!=9 and d!=7 and d!=1):
n1=3
elif(d==1):
n1=1
else:
n1=4
ans=(int(ans)*int(n1))% (1000000007)
n/=10
else:
n/=10
if(ans==1):
print("0")
else:
print(ans %(1000000007))
`... | {
"language": "python",
"test_cases": [
{
"input": "2\n5\n72\n",
"output": "3\n12\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/TCFL2020/problems/TCFL20C"
} | vfc_3250 |
apps | verifiable_code | 1103 | Solve the following coding problem using the programming language python:
Leha is a bright mathematician. Today he is investigating whether an integer is divisible by some square number or not.
He has a positive integer X represented as a product of N integers a1, a2, .... aN. He has somehow figured out that there exi... | ```python
import sys
import math
r=int(input())
for v in range (0,r):
n = int(input())
x=1
arr=list(map(int,input().strip().split(" ")))
for i in range (0,n):
x=x*arr[i]
for i in range (2,100000000):
if(x%(pow(i,2))==0):
ans1=i
break
print(ans1)
``` | {
"language": "python",
"test_cases": [
{
"input": "1\n3\n21 11 6\n",
"output": "3\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/LTIME37/problems/SQNUMBF"
} | vfc_3254 |
apps | verifiable_code | 1104 | Solve the following coding problem using the programming language python:
Kabir Singh is playing a game on the non-negative side of x-axis. It takes him $1 second$ to reach from Pth position to (P−1)th position or (P+1)th position.
Kabir never goes to the negative side and also doesn't stop at any moment of time.
Th... | ```python
# cook your dish here
T=int(input())
MOD=int(1e9+7)
for t in range(T):
N,K=[int(a) for a in input().split()]
M=K//2
# ans= ((K%2)?( (N+M)*(N+M) + M ):( (N+M)*(N+M) - M) )
ans=(N+M)*(N+M) -M
if(K%2):
ans+=2*M
if(N==0):
ans=K*(K-1)
print(ans%MOD)
``` | {
"language": "python",
"test_cases": [
{
"input": "4\n0 1\n1 1\n1 3\n4 6\n",
"output": "0\n1\n5\n46\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/LDT42020/problems/WALKREC"
} | vfc_3258 |
apps | verifiable_code | 1105 | Solve the following coding problem using the programming language python:
Chef Ada is preparing $N$ dishes (numbered $1$ through $N$). For each valid $i$, it takes $C_i$ minutes to prepare the $i$-th dish. The dishes can be prepared in any order.
Ada has a kitchen with two identical burners. For each valid $i$, to pre... | ```python
for i in range(int(input())):
n=int(input())
c=[int(z) for z in input().split()]
c.sort()
c.reverse()
b1,b2=0,0
for i in range(n):
if b1<b2:
b1+=c[i]
elif b2<b1:
b2+=c[i]
else:
b1+=c[i]
print(max(b1,b2))
``` | {
"language": "python",
"test_cases": [
{
"input": "3\n3\n2 2 2\n3\n1 2 3\n4\n2 3 4 5\n",
"output": "4\n3\n7\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/ADADISH"
} | vfc_3262 |
apps | verifiable_code | 1106 | Solve the following coding problem using the programming language python:
A long way back I have taken $5000 from Golu when I used to live in Jodhpur. Now, time has passed and I am out of Jodhpur. While Golu still in Jodhpur, one day called me and asked about his money.
I thought of giving Golu a chance. I told him th... | ```python
'''Well I found the bug, but I don't understand why it was doing that. I mean, as
far as I can tell, it shouldn't be a bug!
Note to self: deleting from (supposedly) local lists through recursion is dangerous!'''
class Group(object):
def __init__(self,size,start,end,value):
self.size = size
... | {
"language": "python",
"test_cases": [
{
"input": "2\n5 5 4\n2 1 5 50\n1 2 4 20\n2 3 4 40\n2 4 5 50\n3 4 5 80\n10 10 5\n2 5 10 17300\n2 1 8 31300\n5 4 10 27600\n4 8 10 7000\n5 9 10 95900\n2 7 10 14000\n3 6 10 63800\n1 7 10 19300\n3 8 10 21400\n2 2 10 7000\n",
"output": "140\n127200\nBy:\nChintan, A... | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/IGNS2012/problems/IG02"
} | vfc_3266 |
apps | verifiable_code | 1107 | Solve the following coding problem using the programming language python:
Polo, the Penguin, likes numbers. He says that the goodness of a number is itself multiplied by the number of digits in it's decimal representation. For example, the goodness of the integer 474 is 474*3 = 1422.
Help him to count the sum of goodn... | ```python
# cook your dish here
from sys import stdin
from math import sqrt,ceil,log10
def get_sum(a,b,digits):
sum=((b+a)*(b-a+1))//2
return sum*digits
def solve():
mod=10**9+7
thehighlimiter={i: 10 ** i - 1 for i in range(12)}
thelowlimiter={i: 10**i for i in range(12)}
for _ in range(int(inp... | {
"language": "python",
"test_cases": [
{
"input": "1\n9 12\n\n\n",
"output": "75\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/PPNUM"
} | vfc_3270 |
apps | verifiable_code | 1108 | Solve the following coding problem using the programming language python:
There were $N$ students (numbered $1$ through $N$) participating in the Indian Programming Camp (IPC) and they watched a total of $K$ lectures (numbered $1$ through $K$). For each student $i$ and each lecture $j$, the $i$-th student watched the ... | ```python
N,M,K=map(int,input().split())
c=0
for i in range(N):
T=list(map(int,input().split()))
Q=T[-1]
T.pop(-1)
if Q<=10 and sum(T)>=M:
c+=1
print(c)
``` | {
"language": "python",
"test_cases": [
{
"input": "4 8 4\n1 2 1 2 5\n3 5 1 3 4\n1 2 4 5 11\n1 1 1 3 12\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/IPCCERT"
} | vfc_3274 |
apps | verifiable_code | 1109 | Solve the following coding problem using the programming language python:
Sumit and Dhiraj are roommates in a hostel of NIT Jamshedpur,One day after completing there boring assignments of Artificial Intelligence, they decided to play a game as it was dhiraj,s idea to play a game so he started explaining the rules of t... | ```python
import math
for t in range(int(input())):
n = int(input())
temp = math.sqrt(n)
if (temp == int(temp)):
print("YES")
else:
print("NO")
``` | {
"language": "python",
"test_cases": [
{
"input": "2\n4\n5\n",
"output": "YES\nNO\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/COYA2016/problems/CDYPA01"
} | vfc_3278 |
apps | verifiable_code | 1110 | Solve the following coding problem using the programming language python:
You are given an array of integers [A1,A2,…,AN]$[A_1, A_2, \ldots, A_N]$. Let's call adding an element to this array at any position (including the beginning and the end) or removing an arbitrary element from it a modification. It is not allowed... | ```python
# cook your dish here
for _ in range(int(input())):
n=int(input());li=list(map(int,input().split()));dli=dict();modi=0
for i in li:
if i not in dli:dli[i]=1
else:dli[i]+=1
op=sorted(list(dli))
if(len(dli)!=0):
while 1:
tmp=[]
for i in op:
if dli[i]==0:continue... | {
"language": "python",
"test_cases": [
{
"input": "2\n5\n1 4 1 2 2\n4\n2 3 2 3\n",
"output": "1\n2\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/PERMPART"
} | vfc_3282 |
apps | verifiable_code | 1111 | Solve the following coding problem using the programming language python:
Using his tip-top physique, Kim has now climbed up the mountain where the base is located. Kim has found the door to the (supposedly) super secret base. Well, it is super secret, but obviously no match for Kim's talents.
The door is guarded by ... | ```python
# cook your dish here
for _ in range(int(input())):
n=int(input())
a=list(map(int,input().split()))
even=[]
odd=[]
for i in a:
if(i & 1):
even.append(i)
else:
odd.append(i)
print(len(even)*len(odd))
``` | {
"language": "python",
"test_cases": [
{
"input": "3\n4\n3 5 3 4\n2\n5 7\n1\n4\n",
"output": "3\n0\n0\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/UWCOI20B"
} | vfc_3286 |
apps | verifiable_code | 1112 | Solve the following coding problem using the programming language python:
The chef is trying to decode some pattern problems, Chef wants your help to code it. Chef has one number K to form a new pattern. Help the chef to code this pattern problem.
-----Input:-----
- First-line will contain $T$, the number of test cas... | ```python
# cook your dish here
for _ in range(int(input())):
n = int(input())
m = n
x= 1
for i in range(n):
for j in range(m):
print(x, end = '')
x += 1
print()
m -= 1
``` | {
"language": "python",
"test_cases": [
{
"input": "4\n1\n2\n3\n4\n",
"output": "1\n12\n3\n123\n45\n6\n1234\n567\n89\n10\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/PSTR2020/problems/ITGUY58"
} | vfc_3290 |
apps | verifiable_code | 1113 | Solve the following coding problem using the programming language python:
Given an array A of length N, your task is to find the element which repeats in A maximum number of times as well as the corresponding count. In case of ties, choose the smaller element first.
-----Input-----
First line of input contains an int... | ```python
t = input();
a = [0 for i in range(10001)]
i = 0;
while i < int(t):
n = input();
k = input();
assert(len(k.split(' ')) == int(n));
for each in k.split(' '):
a[int(each)] += 1;
V = 0;
C = a[V];
for j in range(10001):
if C < a[j]:
V = j;
C = a[V];
a[j] = 0;
i += 1;
print(V... | {
"language": "python",
"test_cases": [
{
"input": "2\n5\n1 2 3 2 5\n6\n1 2 2 1 1 2\n\n\n",
"output": "2 2\n1 3\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/FEB12/problems/MAXCOUNT"
} | vfc_3294 |
apps | verifiable_code | 1114 | Solve the following coding problem using the programming language python:
Chefu is Chef's little brother, he is 12 years old and he is new to competitive programming.
Chefu is practicing very hard to become a very skilled competitive programmer and win gold medal in IOI.
Now Chefu is participating in a contest and the... | ```python
T=int(input())
for i in range(T):
N=int(input())
A=list(map(int,input().split()))[:N]
l=[]
for j in range(len(A)):
for k in range(j+1,len(A)):
l.append(A[j]+A[k])
print(l.count(max(l))/((N*(N-1))/2))
``` | {
"language": "python",
"test_cases": [
{
"input": "3\n4\n3 3 3 3\n6\n1 1 1 2 2 2\n4\n1 2 2 3\n",
"output": "1.00000000\n0.20000000\n0.33333333\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/RNDPAIR"
} | vfc_3298 |
apps | verifiable_code | 1116 | Solve the following coding problem using the programming language python:
-----Problem Statement-----
We have an integer sequence $A$, whose length is $N$.
Find the number of the non-empty contiguous subsequences of $A$ whose sum is $0$. Note that we are counting the ways to take out subsequences. That is, even if the... | ```python
from collections import defaultdict
def findSubarraySum(arr, n, Sum):
# Dictionary to store number of subarrays
# starting from index zero having
# particular value of sum.
prevSum = defaultdict(lambda : 0)
res = 0
# Sum of elements so far.
currsum = 0
for i in range(0, n):
... | {
"language": "python",
"test_cases": [
{
"input": "6\n1 3 -4 2 2 -2\n",
"output": "3\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/SCAT2020/problems/SC_01"
} | vfc_3306 |
apps | verifiable_code | 1117 | Solve the following coding problem using the programming language python:
It is the end of 2019 — the 17th of November, the Cooking Challenge day.
There are N$N$ players participating in this competition, numbered 1$1$ through N$N$. Initially, the skill level of each player is zero. There are also M$M$ challenges (num... | ```python
import numpy as np
def sort_it(array):
new_list = []
for i in range(len(array)):
start = 0
value = array[i][0]
last = len(new_list)
while start != last:
mid = (start + last) // 2
if new_list[mid][0] > value:
last = mid
... | {
"language": "python",
"test_cases": [
{
"input": "1\n5 3 4\n1 1 3\n1 2 -4\n4 5 2\n1 2\n1 3\n1 1\n2 3\n",
"output": "3 0 0 4 4\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/CHADAY"
} | vfc_3310 |
apps | verifiable_code | 1118 | Solve the following coding problem using the programming language python:
Chef is playing a game which contains a binary string.
He can perform one operation only:
- Toggle the i_th bit of the string (0 to 1 or 1 to 0)
By performing operations on the string (can be zero times), you have to convert the string with no ... | ```python
'''
Name : Jaymeet Mehta
codechef id :mj_13
Problem : Avenir Strings
'''
from sys import stdin,stdout
test=int(stdin.readline())
for _ in range(test):
N=int(stdin.readline())
seq=list(input())
fp,fp1,fl,fl1=0,0,0,1
for i in range(N):
if fl!=int(seq[i])-0:
fp+=1
fl=1-fl
for i in range(N):
if fl1!... | {
"language": "python",
"test_cases": [
{
"input": "1\n4\n1011\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/ENFE2020/problems/ECFEB205"
} | vfc_3314 |
apps | verifiable_code | 1119 | Solve the following coding problem using the programming language python:
It's Diwali time and you are on a tour of Codepur, a city consisting of buildings of equal length and breadth because they were designed by a computer architect with a bit of OCD.
The ruling party of Codepur wants to have a blockbuster Diwali ce... | ```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 kadane(arr, start, finish, n):
Sum = 0
maxSum = float('-inf')
i = None
finish[0] = -1
local_start = 0
for i in range(n... | {
"language": "python",
"test_cases": [
{
"input": "6 5\n0 -2 -7 0 -1\n9 2 -6 2 0\n-4 1 -4 1 0\n-1 8 0 -2 1\n-10 1 1 -5 6\n-15 -1 1 5 -4\n",
"output": "9 2\n-4 1\n-1 8\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/CHLG2020/problems/CCFUND"
} | vfc_3318 |
apps | verifiable_code | 1121 | Solve the following coding problem using the programming language python:
Chef is stuck on the minute hand of a giant clock. To escape from this clock he needs to get onto the hour hand which has an exit door.
Since the minute hand and and hour hand are not connected at any point, chef will surely need to make a jump... | ```python
# cook your dish here
t=int(input())
while t>0:
a=input().split(":")
a1=int(a[0])
a2=int(a[1])
b1=a1%12
if a2%5!=0:
b2=(a2//5)*5+5
else:
b2=a2
c1=b1*30
extra=0.5*b2
c1+=extra
c1%=360
d1=(b2//5)*30
d1%=360
if c1>d1:
ans1=c1-d1
ans2=360-ans1
else:
ans1=d1-c1
ans2=360-ans1
... | {
"language": "python",
"test_cases": [
{
"input": "3\n14:20\n02:10\n09:30\n",
"output": "50 degree\n5 degree\n105 degree\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/PAHC2020/problems/CHEFJUMP"
} | vfc_3326 |
apps | verifiable_code | 1122 | Solve the following coding problem using the programming language python:
Ravi is very good student in mathematics and he also like Even numbers very much .
On the other hand his friend Jhon like Odd numbers . Both of them are preparing for IIT JEE Advance .One day they are solving a question together the question w... | ```python
# cook your dish here
while True:
try:
m=int(input())
n=int(m/2)
a=m-n
sum_even= int(2*(2*n*(n+1)*(2*n+1))/3)
sum_odd= int(((4*a*a*a)-a)/3)
result=sum_odd+sum_even
if result%2==0:
print('Ravi')
else:
print('Jhon')
except:
break;
``` | {
"language": "python",
"test_cases": [
{
"input": "2\n3\n",
"output": "Jhon\nRavi\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/CFUN2020/problems/CODSTAN7"
} | vfc_3330 |
apps | verifiable_code | 1123 | Solve the following coding problem using the programming language python:
Chef has decided to start home delivery from his restaurant. He hopes that he will get a lot of orders for delivery, however there is a concern. He doesn't have enough work forces for all the deliveries. For this he has came up with an idea - h... | ```python
# cook your dish here
from sys import stdin, stdout
from math import ceil
def solve():
for _ in range(int(input())):
n, m = map(int, stdin.readline().split())
par = [i for i in range(n)]
for i in range(m):
ta, tb = map(int, stdin.readline().strip().split())
... | {
"language": "python",
"test_cases": [
{
"input": "1\n4 2\n0 1\n1 2\n3\n0 2\n0 3\n2 1\n\n\n",
"output": "YO\nNO\nYO\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/HDELIVER"
} | vfc_3334 |
apps | verifiable_code | 1124 | Solve the following coding problem using the programming language python:
Lumpy is a bus driver. Today, the conductor is absent so Lumpy has to do the conductor's job as well. There are N creatures in the bus. Sometimes the creatures don't carry change and can't pay the exact amount of the fare. Each creature in the b... | ```python
# cook your dish here
# cook your dish here
t=int(input())
for _ in range(t):
n,p,q=list(map(int,input().split(" ")))
l=list(map(int,input().split(" ")))
l.sort()
s=sum(l)
a=p+2*q
b=0
for i in l:
if(p==0):
if(i%2==0 and a>=i):
a=a-i
b=b+1
elif(q==0):
if(a>=i):
a=a-i
b=b+1
el... | {
"language": "python",
"test_cases": [
{
"input": "3\n3 3 0\n1 2 2\n3 2 1\n1 2 1\n4 5 4\n2 3 4 5\n",
"output": "2\n3\n3\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/LUMPYBUS"
} | vfc_3338 |
apps | verifiable_code | 1125 | Solve the following coding problem using the programming language python:
You are the principal of the Cake school in chefland and today is your birthday. You want to treat each of the children with a small cupcake which is made by you. But there is a problem, You don't know how many students are present today.
The st... | ```python
# cook your dish here
for _ in range(int(input())):
n=list(map(int,input().split()))
print(n[0]*n[1])
``` | {
"language": "python",
"test_cases": [
{
"input": "1\n5 10\n",
"output": "50\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/ENDE2020/problems/ENCDEC2"
} | vfc_3342 |
apps | verifiable_code | 1126 | Solve the following coding problem using the programming language python:
"How did you get the deal,how did he agree?"
"Its's simple Tom I just made him an offer he couldn't refuse"
Ayush is the owner of a big construction company and a close aide of Don Vito The Godfather, recently with the help of the Godfather his... | ```python
for _ in range(int(input())):
n=int(input())
print((2*(pow(n,2)))-n+1)
``` | {
"language": "python",
"test_cases": [
{
"input": "2\n1\n2\n",
"output": "2\n7\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/CFW32020/problems/AYUSCRT"
} | vfc_3346 |
apps | verifiable_code | 1127 | Solve the following coding problem using the programming language python:
Nitika was once reading a history book and wanted to analyze it. So she asked her brother to create a list of names of the various famous personalities in the book. Her brother gave Nitika the list. Nitika was furious when she saw the list. The ... | ```python
# cook your dish here
x= int(input())
for i in range(x):
y = list(map(str, input().split()))
j= 0
while j<len(y)-1:
print((y[j][0]).capitalize()+".", end=' ')
j+= 1
print(y[len(y)-1].capitalize())
``` | {
"language": "python",
"test_cases": [
{
"input": "3\ngandhi\nmahatma gandhI\nMohndas KaramChand gandhi\n\n\n",
"output": "Gandhi \nM. Gandhi \nM. K. Gandhi \n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/NITIKA"
} | vfc_3350 |
apps | verifiable_code | 1128 | Solve the following coding problem using the programming language python:
The Chef is given an array of numbers and asked to find the first balance point of an array. A balance point is an index in the array N where the sum of the integers to the left of N is equal to the sum of the integers to the right of N. If ther... | ```python
import sys
t = eval(input())
for j in range(t):
n = eval(input())
a = list(map(int, input().split()))
ch = 0
sm = 0 ; x = sum(a)
s1 = [0] * n ; s2 = [0] * n
for i in range(n):
sm += a[i]
s1[i] = sm
s2[i] = x
x -= a[i]
if(sum(a) - a[0] == 0):
print(0)
elif(sum(a) - a[n - 1] == 0):
print(n ... | {
"language": "python",
"test_cases": [
{
"input": "2\n7\n7 8 9 1 9 8 7\n6\n1 100 50 -51 1 1\n",
"output": "3\n1\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/TSCO2017/problems/TSECJ101"
} | vfc_3354 |
apps | verifiable_code | 1129 | Solve the following coding problem using the programming language python:
Chef’s girlfriend is angry with him because he forgot her birthday. Chef decided to please her by gifting her a Love Graph.
Chef has $N$ vertices: $V_1, V_2, \dots, V_N$. Love Graph is an undirected multigraph with no self-loops and can be cons... | ```python
def fastpow(base, power):
result = 1
while power > 0:
if power % 2 == 0:
power = power // 2
base = base * base
else:
power = power - 1
result = result * base
power = power // 2
base = base * base
return result
t=int(input())
for i in range(t):
a=list(map(int,input().split()))
n,r=... | {
"language": "python",
"test_cases": [
{
"input": "1\n2 1\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/DCC2020/problems/DCC201"
} | vfc_3358 |
apps | verifiable_code | 1130 | Solve the following coding problem using the programming language python:
Finally, a COVID vaccine is out on the market and the Chefland government has asked you to form a plan to distribute it to the public as soon as possible. There are a total of $N$ people with ages $a_1, a_2, \ldots, a_N$.
There is only one hospi... | ```python
for _ in range(int(input())):
f,d=list(map(int,input().split()))
arr=list(map(int,input().split()))
risk=0
days_risk=0
days_norm=0
if d==1:
print(f)
else:
for a in arr:
if a>=80 or a<=9:
risk+=1
norm=f-risk
if risk%d==0:
days_risk=risk//d
else:
days_risk=(risk//d)+1
if norm%d==... | {
"language": "python",
"test_cases": [
{
"input": "2\n10 1\n10 20 30 40 50 60 90 80 100 1\n5 2\n9 80 27 72 79\n",
"output": "10\n3\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/VACCINE2"
} | vfc_3362 |
apps | verifiable_code | 1131 | Solve the following coding problem using the programming language python:
Chef has an array of N natural numbers most of them are repeated. Cheffina challenges chef to find all numbers(in ascending order) whose frequency is strictly more than K.
-----Input:-----
- First-line will contain $T$, the number of test cases... | ```python
for _ in range(int(input())):
n,k=[int(x) for x in input().split()]
a=list(map(int,input().split()))
dp=[0]*(max(a)+1)
for _ in range(n):
dp[a[_]]+=1
for _ in range(1,len(dp)):
if dp[_]>k:
print(_,end=" ")
print()
``` | {
"language": "python",
"test_cases": [
{
"input": "1\n5 1\n5 2 1 2 5\n",
"output": "2 5\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/PEND2020/problems/ANITGUY8"
} | vfc_3366 |
apps | verifiable_code | 1133 | Solve the following coding problem using the programming language python:
Shivam is working on electric circuits. He requires some connecting wires. He needs to make a total of N connections and he has mentioned his wire length requirements for each connection in an integer sequence A. For buying wires, he need to dec... | ```python
from sys import stdin,stdout
from math import gcd
nmbr=lambda:int(stdin.readline())
lst=lambda:list(map(int, stdin.readline().split()))
for _ in range(nmbr()):
n=nmbr()
a=lst()
g=a[0]
ans=0
for v in a[1:]:
g=gcd(v,g)
for i in a:
ans+=i//g
print(g,ans)
``` | {
"language": "python",
"test_cases": [
{
"input": "1\n3\n2 4 8\n",
"output": "2 7\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/CSTR2020/problems/ELECTRIC"
} | vfc_3374 |
apps | verifiable_code | 1134 | Solve the following coding problem using the programming language python:
Daenerys Targaryen has been suggested by her counselors to leave the Meereen and start conquering other parts of the world. But she knows giving up on the people of Meereen means victory of slavery. Her plan is to start conquering rest of the wo... | ```python
t=int(input())
for i in range(t):
n,m=list(map(int,input().split()))
a=list(map(int,input().split()))
army=0
if n>m:
for i in range(0,m):
army+=a[i]
for j in range(m,n):
army=army-(a[j]/2)
if army<0:
print('DEFEAT')
break
else:
continue
else:
print('VICTORY')
... | {
"language": "python",
"test_cases": [
{
"input": "3\n5 3\n1 2 3 4 5\n6 2\n4 4 4 4 4 4\n7 4\n10 10 10 10 50 60 70\n",
"output": "VICTORY\nVICTORY\nDEFEAT\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/KOKT2015/problems/KOKT03"
} | vfc_3378 |
apps | verifiable_code | 1135 | Solve the following coding problem using the programming language python:
Chef Ada is the FootBall coach of the Dinosaurs Institute of Technology.
There are $N$ dinosaurs (enumerated $1$ through $N$) placed in a line. The i-th dinosaur has a height of $i$ meters.
Ada is training The dinosaurs in the following tactic:
... | ```python
# cook your dish here
t=int(input())
while t!=0:
n,k=map(int,input().split())
lst=[]
for i in range(1,n+1):
lst.append(i)
lst[k],lst[n-1]=lst[n-1],lst[k]
for item in lst:
print(item,end=' ')
t-=1
``` | {
"language": "python",
"test_cases": [
{
"input": "1\n5 2\n",
"output": "2 3 1 5 4\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/MXCH"
} | vfc_3382 |
apps | verifiable_code | 1136 | Solve the following coding problem using the programming language python:
Chef has N laddus of K sweetness each. Chef wants to eat all laddus, but Chef is restricted with the given condition that he must not eat two adjacent laddus. Chef starts calculating the maximum sweetness that he will get from the laddus. Find t... | ```python
t = int(input())
for _ in range(t):
n,m = map(int,input().split())
if n==1:
print(m)
else:
if n%2==0:
print((n//2)*m)
else:
print(((n//2)+1)*m)
``` | {
"language": "python",
"test_cases": [
{
"input": "2\n1 2\n4 3\n",
"output": "2\n6\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/PBK12020/problems/ITGUY17"
} | vfc_3386 |
apps | verifiable_code | 1137 | Solve the following coding problem using the programming language python:
Vishal Wants to buy 2 gifts for his best friend whose name is Annabelle(her age is 20), So they both went for shopping in a store. But Annabelle gave, Vishal a condition that she will accept this gifts only when the total price of the gifts is t... | ```python
test = int(input())
ANS = list()
for i in range(test):
n = int(input())
items = sorted(list(map(int, input().split())))
c = 1
for j in range(len(items)):
if items[j] < 2000:
t = 2000 - items[j]
if t in items[j+1:]:
ANS.append("Accepted")
c = 2
break
else:
pass
else:
break
... | {
"language": "python",
"test_cases": [
{
"input": "1\n5\n10 2 1000 50 1000\n",
"output": "Accepted\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/ARYS2020/problems/BDYGFT"
} | vfc_3390 |
apps | verifiable_code | 1138 | Solve the following coding problem using the programming language python:
Sereja is hosting his birthday dinner. He invited his N close friends. Let us number the people from 1 to N according to the order in which they arrive at the event. The dinner is being held in long straight corridor in which people sit in a way... | ```python
a=eval(input())
while(a):
x=eval(input())
b=list(map(int,input().split()))
z=[0]*100
k=1
j=0
c=0
for i in b:
if i==0:
z.insert(i,k)
else:
if z[z.index(i)+1]==0:
z.insert(j,k)
else:
m=z.index(i)
n=m+1
p=(len(z)-z.count(0))-n
c=c+min(n,p)
z.i... | {
"language": "python",
"test_cases": [
{
"input": "3\n1\n0\n3\n0 0 0\n5\n0 1 2 1 4\n",
"output": "0\n0\n3\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/COOK64/problems/SEALINE"
} | vfc_3394 |
apps | verifiable_code | 1139 | Solve the following coding problem using the programming language python:
The chef is very expert in coding, so to keep his password safe from the hackers. He always enters a decoded code of his password. You are a hacker and your work is to find the maximum number of possible ways to unlock his password in encoded fo... | ```python
t = int(input())
while t>0:
s = input().strip()
if not s:
print('NO')
dp = [0 for x in range(len(s) + 1)]
dp[0] = 1
dp[1] = 1 if 0 < int(s[0]) <= 9 else 0
for i in range(2, len(s) + 1):
if 0 < int(s[i-1:i]) <= 9:
dp[i] += dp[i - 1]
if s[i-2:i][0] != '0' and int(s[i-2:i]) <= 26:
dp[i] += dp... | {
"language": "python",
"test_cases": [
{
"input": "2\n12\n223\n",
"output": "YES\nNO\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/CY302020/problems/CODEY302"
} | vfc_3398 |
apps | verifiable_code | 1140 | Solve the following coding problem using the programming language python:
Consider the following algorithm
order(arr, i) {
if length(arr) <= 1 {
return arr
}
l = []
r = []
n = length(arr) - 1
for j in 0, 1, ..., n {
if ( (arr[j] modulo power(2,i+1)) < power(2,i) ) {
append arr[j] to l
}else{
append arr[j] to r
}
}
... | ```python
for _ in range(int(input())):
p, idx = map(int, input().split())
b = bin(idx)[2:]
b = ('0' * (p - len(b)) + b)[::-1]
print(int(b, 2))
``` | {
"language": "python",
"test_cases": [
{
"input": "2\n3 3\n3 7\n",
"output": "6\n7\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/ZCOPRAC/problems/ZCO20001"
} | vfc_3402 |
apps | verifiable_code | 1141 | Solve the following coding problem using the programming language python:
A tourist is visiting Byteland. The tourist knows English very well. The language of Byteland is rather different from English. To be exact it differs in following points:
- Bytelandian alphabet has the same letters as English one, but possibly... | ```python
try:
t,m=input().split()
t=int(t)
m=list(m)
letters=list("abcdefghijklmnopqrstuvwxyz")
trans={}
for i in range(len(letters)):
trans[letters[i]]=m[i]
for i in range(t):
x=list(input())
y=""
for j in x:
if(j.isalpha()==True):
if(j.isupper()==True):
y+=trans[j.lower()].upper()
else... | {
"language": "python",
"test_cases": [
{
"input": "and its\n",
"output": "",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/TOTR"
} | vfc_3406 |
apps | verifiable_code | 1142 | Solve the following coding problem using the programming language python:
This is one more story about our old friend, the Despotic King. Once every year, it was customary for the king to give audience to the rich merchants of his country in a large hall. On that day, the merchants were ushered in to meet the king one... | ```python
arr=[]
n=int(input())
for i in range(n):
a=int(input())
arr.append(a)
arr.sort()
p=arr.index(a)
print((i-p)+1)
``` | {
"language": "python",
"test_cases": [
{
"input": "6\n78\n24\n68\n40\n39\n89\n",
"output": "1\n2\n2\n3\n4\n1\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/IARCSJUD/problems/IARANK"
} | vfc_3410 |
apps | verifiable_code | 1143 | Solve the following coding problem using the programming language python:
Yash likes playing with numbers. He has a challenge for you. Yash gives
you a number that he made by multiplying two numbers. He claims that the
possible sum of the two numbers he multiplied is as minimum as possible. He
challenges you to find t... | ```python
# cook your dish here
def isPrime(n) :
# Corner cases
if (n <= 1) :
return False
if (n <= 3) :
return True
# This is checked so that we can skip
# middle five numbers in below loop
if (n % 2 == 0 or n % 3 == 0) :
return False
i = 5
while... | {
"language": "python",
"test_cases": [
{
"input": "1\n852140\n",
"output": "1929\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/CHLG2020/problems/MINI2"
} | vfc_3414 |
apps | verifiable_code | 1144 | Solve the following coding problem using the programming language python:
Devu loves to play with binary strings a lot. One day he borrowed a binary string s of size n from his friend Churu. Before starting to play with it, he wants to make sure that string does not contain more than k consecutive equal characters. F... | ```python
T= int(input());
for i in range(T):
n,k = list(map(int,input().split()));
s=list(map(int,input()));
if k==1:
s_0 ={};
s_1={};
c0=0;
c1=0;
for j in range(n):
if(j%2==0):
s_1[j]=1;
s_0[j]=0;
else:
s_1[j]=0;
s_0[j]=1;
for j in range(n):
if(s_0[j]-s[j]!=0):
c0+=1;
... | {
"language": "python",
"test_cases": [
{
"input": "3\n2 1\n11\n2 2\n11\n4 1\n1001\n",
"output": "1\n10\n0\n11\n2\n1010\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/DEVSTR"
} | vfc_3418 |
apps | verifiable_code | 1145 | Solve the following coding problem using the programming language python:
In a bizarre game of chess ,knight was so drunk, that instead of his usual move he started walking straight. In every move Knight jumps on 2n steps forward (n is number of block that he had travelled so far from starting) but after that he has t... | ```python
from math import log,pow
n=int(input())
a=[]
for i in range(n):
no=int(input())
if(no%2==0):
a.append("0")
elif(no==1):
a.append("1")
elif(no==3):
a.append("3")
else:
s="2"
lv=int(log(no,2))
clv=1
cno=3
while(cno!=no):
if(no<cno*pow(2,lv-clv)):
s=s+"1"
clv=clv+1
cno=(2*cno)... | {
"language": "python",
"test_cases": [
{
"input": "2\n17\n10\n",
"output": "2111\n0\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/ALGT2013/problems/TNMALG07"
} | vfc_3422 |
apps | verifiable_code | 1146 | Solve the following coding problem using the programming language python:
[Chopsticks (singular: chopstick) are short, frequently tapered sticks used in pairs of equal length, which are used as the traditional eating utensils of China, Japan, Korea and Vietnam. Originated in ancient China, they can also be found in so... | ```python
# cook your dish here
a,b=list(map(int,input().split()))
ls=[]
for i in range(a):
ls.append(int(input()))
ls.sort()
c=0;i=0
while i<(a-1):
if ls[i+1]-ls[i]<=b:
c=c+1
i=i+1
i=i+1
print(c)
``` | {
"language": "python",
"test_cases": [
{
"input": "5 2\n1\n3\n3\n9\n4\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/TACHSTCK"
} | vfc_3426 |
apps | verifiable_code | 1147 | Solve the following coding problem using the programming language python:
You are given a string S containing only lowercase characters.
You can rearrange the string and you have to print minimum number of characters needed(can be 0) to make it palindrome.
-----Input:-----
- First line contain an interger T denoting... | ```python
# cooking dish here
from sys import stdin
from collections import Counter
read = stdin.readline
for testcase in range(int(read())):
length = int(read())
string = read().strip()
counts = Counter(string)
odd_counts = 0
for count in list(counts.values()):
# print(coun... | {
"language": "python",
"test_cases": [
{
"input": "3\n1\na\n9\nabbbcbddd\n6\nabcdef\n",
"output": "0\n2\n5\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/CDGO2021/problems/PALINDRO"
} | vfc_3430 |
apps | verifiable_code | 1148 | Solve the following coding problem using the programming language python:
In ACM-ICPC contests, there are usually three people in a team. For each person in the team, you know their scores in three skills - hard work, intelligence and persistence.
You want to check whether it is possible to order these people (assign ... | ```python
def g(x,y):
d = x[0]>=y[0] and x[1]>=y[1] and x[2]>=y[2]
e= x[0]>y[0] or x[1]>y[1] or x[2]>y[2]
return d and e
t=int(input())
for _ in range(t):
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
if g(a,b) and g(b,c):
print('yes')
elif g(a,c) and g(c,... | {
"language": "python",
"test_cases": [
{
"input": "3\n1 2 3\n2 3 4\n2 3 5\n1 2 3\n2 3 4\n2 3 4\n5 6 5\n1 2 3\n2 3 4\n",
"output": "yes\nno\nyes\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/ORDTEAMS"
} | vfc_3434 |
apps | verifiable_code | 1149 | Solve the following coding problem using the programming language python:
Chef had an interesting dream last night. He dreamed of a new revolutionary chicken recipe. When he woke up today he tried very hard to reconstruct the ingredient list. But, he could only remember certain ingredients. To simplify the problem, th... | ```python
# cook your dish here
t=int(input())
for _ in range(t):
l = input()
n= len(l)
prod = 1
for k in range(n//2):
i = l[k]
j = l[n-k-1]
if ((i!=j) and (i!='?' and j!="?") ):
prod=0
break
elif ((i==j) and (i=='?')):
prod*=26
prod = prod%10000009
if n%2!=0:
if l[n//2]=="?":
prod*=26... | {
"language": "python",
"test_cases": [
{
"input": "5\n?\n??\nab?\na?c\naba\n",
"output": "26\n26\n1\n0\n1\nConstraints\n1 ≤ T ≤ 20\n1 ≤ sum of length of all input strings ≤ 1,000,000\nEach input string contains only lowercase roman letters ('a' - 'z') or question marks.\n",
"type": "stdin_std... | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/RRECIPE"
} | vfc_3438 |
apps | verifiable_code | 1150 | Solve the following coding problem using the programming language python:
In the 2-D world of Flatland, the Circles were having their sports day and wanted to end it with a nice formation. So, they called upon Mr. Sphere from Spaceland for help. Mr Sphere decides to arrange the Circles in square formations. He starts ... | ```python
# cook your dish here
import math
for _ in range(int(input())):
n=int(input())
c=0
while(n>0):
i=int(math.sqrt(n))
c+=1
n=n-i**2
print(c)
``` | {
"language": "python",
"test_cases": [
{
"input": "2\n85\n114\n",
"output": "2\n4\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/ICL1902"
} | vfc_3442 |
apps | verifiable_code | 1151 | Solve the following coding problem using the programming language python:
There is a city with $N$ numbered $0 - N-1$ shops. A market is a place where we can reach from one shop to another using some road. There are $M$ roads in this city connecting each connecting any two shops.
Find the number of markets in the cit... | ```python
from sys import stdin
from math import ceil, gcd
# Input data
#stdin = open("input", "r")
def dfs(src, visit):
visit[src] = 1
for nbr in d[src]:
if visit[nbr] == 0:
dfs(nbr, visit)
for _ in range(int(stdin.readline())):
n, m = list(map(int, stdin.readline().sp... | {
"language": "python",
"test_cases": [
{
"input": "1\n5 3\n0 1\n2 3\n3 4\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/ENAU2020/problems/ECAUG206"
} | vfc_3446 |
apps | verifiable_code | 1152 | Solve the following coding problem using the programming language python:
Chef Jessie has a lot of recipes with her (N). She often remembered the starting few characters of the recipe and forgot the rest. As all the great chefs do, Jessie also numbered the recipes depending on the priority. So, given the list of recip... | ```python
nr=int(input())
d={}
for r in range(nr):
s,v=list(map(str,input().split()))
d[int(v)]=s
q=int(input())
lis=[]
for i in range(q):
lis.append(input())
l=list(d.keys())
l.sort(reverse=True)
ans='NO'
for j in lis:
ans='NO'
for k in l:
if len(j)<=len(d[k]):
a=d[k]
if j==a[0:len(j)]:
ans=a
br... | {
"language": "python",
"test_cases": [
{
"input": "4\nflour-with-eggs 100\nchicken-ham -10\nflour-without-eggs 200\nfish-with-pepper 1100\n6\nf\nflour-with\nflour-with-\nc\nfl\nchik\n",
"output": "fish-with-pepper\nflour-without-eggs\nflour-with-eggs\nchicken-ham\nflour-without-eggs\nNO\n",
"... | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/TWSTR"
} | vfc_3450 |
apps | verifiable_code | 1154 | Solve the following coding problem using the programming language python:
Chef and his friends are playing the game AMONG US. They all have chosen their names as numbers. There are N people in Chef’s group including him, and each swears that he is not the imposter. However, it turns out there were N+1 people in the ga... | ```python
try:
n=int(input())
x=[*list(map(int, input().split()))]
y=[*list(map(int, input().split()))]
for i in y:
d=x.count(i)-y.count(i)
if d!=0:
print(i)
break
except: pass
``` | {
"language": "python",
"test_cases": [
{
"input": "3\n4 2 5\n4 2 3 5\n",
"output": "3\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/CSTR2020/problems/AMONGUS"
} | vfc_3458 |
apps | verifiable_code | 1155 | Solve the following coding problem using the programming language python:
Autobots are instructed by Optimus Prime to mobilize in the form of a rectangular shape with each Autobot on each vertex of the rectangle region on a -”deployment area” (which may consist of one or more regions). This is done so as to take care ... | ```python
print
``` | {
"language": "python",
"test_cases": [
{
"input": "1\n4\n0 4 0 4\n1 3 1 2\n2 3 1 3\n3 4 1 3\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/TCTR2012/problems/NOPC2"
} | vfc_3462 |
apps | verifiable_code | 1156 | Solve the following coding problem using the programming language python:
Write a program, which takes an integer N and if the number is less than 10 then display "Thanks for helping Chef!" otherwise print "-1".
-----Input-----
The first line contains an integer T, total number of testcases. Then follow T lines, eac... | ```python
# cook your dish here
for i in range(int(input())):
x=int(input())
if x<10:
print("Thanks for helping Chef!")
else:
print("-1")
``` | {
"language": "python",
"test_cases": [
{
"input": "3\n1\n12\n-5\n",
"output": "Thanks for helping Chef!\n-1\nThanks for helping Chef!\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/FLOW008"
} | vfc_3466 |
apps | verifiable_code | 1157 | Solve the following coding problem using the programming language python:
Today is the planned day tor Thik and Ayvak's wedding. Kark is infatuated with Ayvak. He offers to play a game with Thik. Whosoever wins, will get to marry Ayvak. Ayvak, who values games of chance over all the other things in life, agrees to thi... | ```python
# cook your dish here
# cook your dish here
for i in range(int(input())):
n,m,k=map(int,input().split())
l,ans = list(map(int,input().split())),0
for i in l:
r=i//m + 1;c=i%m
if(c==0):c=m;r-=1
ans+=r*(n+1-r)*c*(m+1-c)
ans/=((n+1)*(m+1)*n*m)//4
print(ans)
``` | {
"language": "python",
"test_cases": [
{
"input": "1\n2 2 2\n1 2\n\n\n",
"output": "0.8888888888888888\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/RECTLOVE"
} | vfc_3470 |
apps | verifiable_code | 1158 | Solve the following coding problem using the programming language python:
Recently, chef Ciel often hears about 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.... | ```python
#!/usr/bin/env python
def main():
N = int(input())
C = 0
for n in range(N):
S = input().strip()
Pi = S.split()[-1]
L = [Pi.count(k) for k in map(str, list(range(10)))]
if L[8] >= L[5] and L[5] >= L[3] and \
L[0] == 0 and L[1] == 0 and \
L[2] == 0 and L[4] == 0 and \
L[6] == 0 and L[7] == ... | {
"language": "python",
"test_cases": [
{
"input": "6\nmilk 58\nCiel's Drink 80\nThe curry 2nd edition 888888\nrice omelet 85855\nunagi 1\nThe first and last letters can be a space 358\n",
"output": "3\nOutput details\n58 and 888888 and 358 are Ciel numbers.\n80 and 85855 and 1 are not Ciel nu... | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/COOK20/problems/CIELNUM2"
} | vfc_3474 |
apps | verifiable_code | 1159 | Solve the following coding problem using the programming language python:
Abhi and his friends (Shanky,Anku and Pandey) love to play with strings. Abhi invented a simple game. He will give a string S to his friends. Shanky and Anku will play the game while Pandey is just a spectator. Shanky will traverse the string fr... | ```python
t = int(input())
for e in range(t):
str = input()
dict = {}
for x in range(len(str)):
if str[x] in dict:
dict[str[x]] = -1
else:
dict[str[x]] = x
shankyIndex = len(str)
ankuIndex = -1
for x in dict:
if dict[x] != -1:
if dict[x] < shankyIndex:
shankyIndex = dict[x]
if dict[x] >... | {
"language": "python",
"test_cases": [
{
"input": "3\ngoogle\nbreakraekb\naman\n",
"output": "SHANKY\nPANDEY\nANKU\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/RECJ1601/problems/ABHSTR"
} | vfc_3478 |
apps | verifiable_code | 1160 | Solve the following coding problem using the programming language python:
Chef is an advocate for Go Green Initiative. Today he had n trees planted in a row outside his his restaurant. Today, the height of i-th tree is hi feet. The trees grow at a rate of mi feet per day.
Chef knows that trees will look beautiful if t... | ```python
def get(l,n):
l1,l2 = [],[]
i = 1
h1,m1 = l[0]
while (i < len(l)):
h2,m2 = l[i]
if (h1>h2):
if (m1 >= m2):
l1 += [(0,10**20)]
l2 += [(-1,-1)]
else:
d = (h1-h2)//(m2-m1)
if (((h1-h2)%(m2-m1)) == 0):
l1 += [(0,d-1)]
l2 += [(d+1,10**20)]
else:
l1 += [(0,d)]
l... | {
"language": "python",
"test_cases": [
{
"input": "3\n3\n0 1\n2 2\n0 3\n2\n2 1\n1 2\n3\n1 1\n2 2\n3 3\n",
"output": "1\n0 1\n2\n0 0\n2 Inf\n0\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/AUG16/problems/CHAHG"
} | vfc_3482 |
apps | verifiable_code | 1161 | Solve the following coding problem using the programming language python:
In Snakeland, there are some snakes and mongooses. They are lined up in a row. The information about how exactly they are lined up it is provided to you by a string of length n. If the i-th character of this string is 's', then it means that the... | ```python
for i in range(int(input())):
a=input()
c=a.count('m')
d=a.count('s')
t=0
while t<len(a)-1:
if (a[t]=='m' and a[t+1]=='s') or (a[t]=='s' and a[t+1]=='m'):
d=d-1
t=t+2
else:
t=t+1
if c>d:
print('mongooses')
elif d>c:
print('snakes')
else:
print('tie')
``` | {
"language": "python",
"test_cases": [
{
"input": "4\nsm\nssm\nsms\nssmmmssss\n",
"output": "mongooses\ntie\ntie\nsnakes\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/SNELECT"
} | vfc_3486 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.