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 | contaminated_aime_2024 bool 1
class | contaminated_aime_2025 bool 1
class | contaminated_math_500 bool 1
class | contaminated_gpqa bool 1
class | contaminated_lcb bool 2
classes |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
apps | verifiable_code | 100 | Solve the following coding problem using the programming language python:
You have three piles of candies: red, green and blue candies: the first pile contains only red candies and there are $r$ candies in it, the second pile contains only green candies and there are $g$ candies in it, the third pile contains only ... | ```python
n = int(input())
for _ in range(n):
a, b, c = list(map(int, input().split()))
print(min((a+b+c)//2, a+b, a+c, b+c))
``` | {
"language": "python",
"test_cases": [
{
"input": "6\n1 1 1\n1 2 1\n4 1 1\n7 4 10\n8 1 4\n8 2 8\n",
"output": "1\n2\n2\n10\n5\n9\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/1263/A"
} | vfc_400 | false | false | false | false | false |
apps | verifiable_code | 101 | Solve the following coding problem using the programming language python:
Polycarp lives on the coordinate axis $Ox$ and travels from the point $x=a$ to $x=b$. It moves uniformly rectilinearly at a speed of one unit of distance per minute.
On the axis $Ox$ at the point $x=c$ the base station of the mobile operator is... | ```python
import os
from io import BytesIO
# input = BytesIO(os.read(0, os.fstat(0).st_size)).readline
for i in range(int(input())):
a, b, c, r = list(map(int, input().split()))
a, b = min(a, b), max(a, b)
left = max(c - r, a)
right = min(c + r, b)
if right >= a and left <= right:
print(b -... | {
"language": "python",
"test_cases": [
{
"input": "9\n1 10 7 1\n3 3 3 0\n8 2 10 4\n8 2 10 100\n-10 20 -17 2\n-3 2 2 0\n-3 1 2 0\n2 3 2 3\n-1 3 -2 2\n",
"output": "7\n0\n4\n0\n30\n5\n4\n0\n3\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/1282/A"
} | vfc_404 | false | false | false | false | false |
apps | verifiable_code | 102 | Solve the following coding problem using the programming language python:
Hooray! Polycarp turned $n$ years old! The Technocup Team sincerely congratulates Polycarp!
Polycarp celebrated all of his $n$ birthdays: from the $1$-th to the $n$-th. At the moment, he is wondering: how many times he turned beautiful number o... | ```python
s = []
for i in range(1, 10):
k = 0
for l in range(1, 10):
k *= 10
k += i
s.append(k)
s.sort()
q = int(input())
while q:
n = int(input())
l = 0
r = len(s)
while l + 1 < r:
m = (l + r) // 2
if s[m] <= n:
l = m
else:
... | {
"language": "python",
"test_cases": [
{
"input": "6\n18\n1\n9\n100500\n33\n1000000000\n",
"output": "10\n1\n9\n45\n12\n81\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/1259/A"
} | vfc_408 | false | false | false | false | false |
apps | verifiable_code | 103 | Solve the following coding problem using the programming language python:
Ashish and Vivek play a game on a matrix consisting of $n$ rows and $m$ columns, where they take turns claiming cells. Unclaimed cells are represented by $0$, while claimed cells are represented by $1$. The initial state of the matrix is given. ... | ```python
t = int(input())
for _ in range(t):
n, m = [int(x) for x in input().split()]
grid = [[int(x) for x in input().split()] for _ in range(n)]
rows = sum(1 for x in grid if all(y == 0 for y in x))
cols = sum(1 for j in range(m) if all(grid[i][j] == 0 for i in range(n)))
res = min(rows, cols)... | {
"language": "python",
"test_cases": [
{
"input": "4\n2 2\n0 0\n0 0\n2 2\n0 0\n0 1\n2 3\n1 0 1\n1 1 0\n3 3\n1 0 0\n0 0 0\n1 0 0\n",
"output": "Vivek\nAshish\nVivek\nAshish\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/1365/A"
} | vfc_412 | false | false | false | false | false |
apps | verifiable_code | 104 | Solve the following coding problem using the programming language python:
You are given a colored permutation $p_1, p_2, \dots, p_n$. The $i$-th element of the permutation has color $c_i$.
Let's define an infinite path as infinite sequence $i, p[i], p[p[i]], p[p[p[i]]] \dots$ where all elements have same color ($c[i]... | ```python
from sys import stdin
input = stdin.readline
q = int(input())
for rwerew in range(q):
n = int(input())
p = list(map(int,input().split()))
c = list(map(int,input().split()))
for i in range(n):
p[i] -= 1
przyn = [0] * n
grupa = []
i = 0
while i < n:
if przyn[i] == 1:
i += 1
else:
nowa_grupa ... | {
"language": "python",
"test_cases": [
{
"input": "3\n4\n1 3 4 2\n1 2 2 3\n5\n2 3 4 5 1\n1 2 3 4 5\n8\n7 4 5 6 1 8 3 2\n5 3 6 4 7 5 8 4\n",
"output": "1\n5\n2\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/1327/D"
} | vfc_416 | false | false | false | false | false |
apps | verifiable_code | 105 | Solve the following coding problem using the programming language python:
— Hey folks, how do you like this problem?
— That'll do it.
BThero is a powerful magician. He has got $n$ piles of candies, the $i$-th pile initially contains $a_i$ candies. BThero can cast a copy-paste spell as follows: He chooses two pile... | ```python
import math
t = int(input())
for test in range(t):
n,k = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
ans = 0
for i in range(1,n):
if(A[i]>k):
ans = 0
break
rem = k-A[i]
ans+=rem//A[0]
print(ans)
``` | {
"language": "python",
"test_cases": [
{
"input": "3\n2 2\n1 1\n3 5\n1 2 3\n3 7\n3 2 2\n",
"output": "1\n5\n4\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/1417/A"
} | vfc_420 | false | false | false | false | false |
apps | verifiable_code | 106 | Solve the following coding problem using the programming language python:
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossib... | ```python
t = int(input())
for ti in range(t):
n = int(input())
lri = [None for _ in range(n)]
for _ in range(n):
li, ri = list(map(int, input().split()))
lri[_] = (li, ri, _)
lri.sort()
t = [None for _ in range(n)]
ct, t[lri[0][2]], eg = 1, 1, lri[0][1]
for i in range(1, n):
if lri[i][0] <= eg:
... | {
"language": "python",
"test_cases": [
{
"input": "3\n2\n5 5\n2 3\n3\n3 5\n2 3\n2 3\n3\n3 3\n4 4\n5 5\n",
"output": "2 1 \n-1\n1 1 2 \n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/1101/C"
} | vfc_424 | false | false | false | false | false |
apps | verifiable_code | 107 | Solve the following coding problem using the programming language python:
Chaneka has a hobby of playing with animal toys. Every toy has a different fun value, a real number. Chaneka has four boxes to store the toys with specification: The first box stores toys with fun values in range of $(-\infty,-1]$. The second... | ```python
t = int(input())
for _ in range(t):
a, b, c, d = [int(i) for i in input().split(" ")]
sgn = (a+b)%2
small = False
large = False
if a == 0 and d == 0:
small = True
if b == 0 and c == 0:
large = True
okay = [True] * 4
if sgn == 0:
okay[0] = False
okay[1] = False
else:
okay[... | {
"language": "python",
"test_cases": [
{
"input": "2\n1 2 0 1\n0 1 0 0\n",
"output": "Ya Ya Tidak Tidak\nTidak Ya Tidak Tidak\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/1425/H"
} | vfc_428 | false | false | false | false | false |
apps | verifiable_code | 108 | Solve the following coding problem using the programming language python:
You're given an array $a_1, \ldots, a_n$ of $n$ non-negative integers.
Let's call it sharpened if and only if there exists an integer $1 \le k \le n$ such that $a_1 < a_2 < \ldots < a_k$ and $a_k > a_{k+1} > \ldots > a_n$. In particular, any st... | ```python
for _ in range(int(input())):
n=int(input())
li=list(map(int,input().split()))
ans=0
for i in range(n):
if li[i]>=i:
ans+=1
else:
break
for i in range(n):
if li[n-1-i]>=i:
ans+=1
else:
break
if ans>n:
... | {
"language": "python",
"test_cases": [
{
"input": "10\n1\n248618\n3\n12 10 8\n6\n100 11 15 9 7 8\n4\n0 1 1 0\n2\n0 0\n2\n0 1\n2\n1 0\n2\n1 1\n3\n0 1 0\n3\n1 0 1\n",
"output": "Yes\nYes\nYes\nNo\nNo\nYes\nYes\nYes\nYes\nNo\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/1291/B"
} | vfc_432 | false | false | false | false | true |
apps | verifiable_code | 109 | Solve the following coding problem using the programming language python:
You have a bag of size $n$. Also you have $m$ boxes. The size of $i$-th box is $a_i$, where each $a_i$ is an integer non-negative power of two.
You can divide boxes into two parts of equal size. Your goal is to fill the bag completely.
For exa... | ```python
import sys
import math
from collections import defaultdict
from collections import deque
from itertools import combinations
from itertools import permutations
input = lambda : sys.stdin.readline().rstrip()
read = lambda : list(map(int, input().split()))
go = lambda : 1/0
def write(*args, sep="\n"):
for i in... | {
"language": "python",
"test_cases": [
{
"input": "3\n10 3\n1 32 1\n23 4\n16 1 4 1\n20 5\n2 1 16 1 8\n",
"output": "2\n-1\n0\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/1303/D"
} | vfc_436 | false | false | false | false | false |
apps | verifiable_code | 110 | Solve the following coding problem using the programming language python:
On February 14 Denis decided to give Valentine to Nastya and did not come up with anything better than to draw a huge red heart on the door of the length $k$ ($k \ge 3$). Nastya was very confused by this present, so she decided to break the door... | ```python
for _ in range(int(input())):
n, k = tuple(map(int, input().split()))
arr = list(map(int, input().split()))
peaks = [0 for i in range(n)]
for i in range(1, n - 1):
if arr[i] > arr[i - 1] and arr[i] > arr[i + 1]:
peaks[i] = 1
cnt = 0
max_peaks = 0
answer = 0
... | {
"language": "python",
"test_cases": [
{
"input": "5\n8 6\n1 2 4 1 2 4 1 2\n5 3\n3 2 3 2 1\n10 4\n4 3 4 3 2 3 2 1 0 1\n15 7\n3 7 4 8 2 3 4 5 21 2 3 4 2 1 3\n7 5\n1 2 3 4 5 6 1\n",
"output": "3 2\n2 2\n2 1\n3 1\n2 3\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/1341/B"
} | vfc_440 | false | false | false | false | false |
apps | verifiable_code | 111 | Solve the following coding problem using the programming language python:
You are given an image, that can be represented with a 2-d n by m grid of pixels. Each pixel of the image is either on or off, denoted by the characters "0" or "1", respectively. You would like to compress this image. You want to choose an integ... | ```python
#!/usr/bin/env python
# coding:utf-8
# Copyright (C) dirlt
from sys import stdin
def run(n, m, pixels):
ans = 1 << 30
acc = [[0] * (m + 1) for _ in range(n + 1)]
for i in range(n):
for j in range(m):
acc[i + 1][j + 1] = acc[i + 1][j] + int(pixels[i][j])
for j in ran... | {
"language": "python",
"test_cases": [
{
"input": "3 5\n00100\n10110\n11001\n",
"output": "5\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/838/A"
} | vfc_444 | false | false | false | false | false |
apps | verifiable_code | 112 | Solve the following coding problem using the programming language python:
Now that Heidi has made sure her Zombie Contamination level checker works, it's time to strike! This time, the zombie lair is a strictly convex polygon on the lattice. Each vertex of the polygon occupies a point on the lattice. For each cell of ... | ```python
import math
def lexComp(a, b):
if a[0] != b[0]:
return -1 if a[0] < b[0] else 1
if a[1] != b[1]:
return -1 if a[1] < b[1] else 1
return 0
def turn(a, b, c):
return (b[0] - a[0]) * (c[1] - b[1]) - (b[1] - a[1]) * (c[0] - b[0])
def dist2(a, b):
return (a[0] - b[0]) ** ... | {
"language": "python",
"test_cases": [
{
"input": "8\n00000000\n00000110\n00012210\n01234200\n02444200\n01223200\n00001100\n00000000\n5\n00000\n01210\n02420\n01210\n00000\n7\n0000000\n0122100\n0134200\n0013200\n0002200\n0001100\n0000000\n0\n",
"output": "4\n2 3\n2 4\n6 6\n5 2\n4\n2 2\n2 3\n3 3\n3 2... | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/690/B2"
} | vfc_448 | false | false | false | false | false |
apps | verifiable_code | 113 | Solve the following coding problem using the programming language python:
Bob watches TV every day. He always sets the volume of his TV to $b$. However, today he is angry to find out someone has changed the volume to $a$. Of course, Bob has a remote control that can change the volume.
There are six buttons ($-5, -2, ... | ```python
import math
from decimal import Decimal
import heapq
from collections import deque
def na():
n = int(input())
b = [int(x) for x in input().split()]
return n,b
def nab():
n = int(input())
b = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]
return n,b,c
def dv():
n, m = l... | {
"language": "python",
"test_cases": [
{
"input": "3\n4 0\n5 14\n3 9\n",
"output": "2\n3\n2\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/1255/A"
} | vfc_452 | false | false | false | false | false |
apps | verifiable_code | 114 | Solve the following coding problem using the programming language python:
You play a computer game. In this game, you lead a party of $m$ heroes, and you have to clear a dungeon with $n$ monsters. Each monster is characterized by its power $a_i$. Each hero is characterized by his power $p_i$ and endurance $s_i$.
The ... | ```python
import sys
input = sys.stdin.readline
import bisect
t=int(input())
for testcases in range(t):
n=int(input())
A=list(map(int,input().split()))
m=int(input())
PS=[tuple(map(int,input().split())) for i in range(m)]
PS.sort()
K=[PS[-1]]
for a,b in PS[::-1][1:]:
if b<=K[-1][... | {
"language": "python",
"test_cases": [
{
"input": "2\n6\n2 3 11 14 1 8\n2\n3 2\n100 1\n5\n3 5 100 2 3\n2\n30 5\n90 1\n",
"output": "5\n-1\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/1257/D"
} | vfc_456 | false | false | false | false | false |
apps | verifiable_code | 115 | Solve the following coding problem using the programming language python:
Polycarp plays a computer game (yet again). In this game, he fights monsters using magic spells.
There are two types of spells: fire spell of power $x$ deals $x$ damage to the monster, and lightning spell of power $y$ deals $y$ damage to the mo... | ```python
class BIT():
def __init__(self,n):
self.BIT=[0]*(n+1)
self.num=n
def query(self,idx):
res_sum = 0
while idx > 0:
res_sum += self.BIT[idx]
idx -= idx&(-idx)
return res_sum
#Ai += x O(logN)
def update(self,idx,x):
while id... | {
"language": "python",
"test_cases": [
{
"input": "6\n1 5\n0 10\n1 -5\n0 5\n1 11\n0 -10\n",
"output": "5\n25\n10\n15\n36\n21\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/1398/E"
} | vfc_460 | false | false | false | false | false |
apps | verifiable_code | 116 | Solve the following coding problem using the programming language python:
Let's call an array $a_1, a_2, \dots, a_m$ of nonnegative integer numbers good if $a_1 + a_2 + \dots + a_m = 2\cdot(a_1 \oplus a_2 \oplus \dots \oplus a_m)$, where $\oplus$ denotes the bitwise XOR operation.
For example, array $[1, 2, 3, 6]$ is... | ```python
for nt in range(int(input())):
n=int(input())
l=list(map(int,input().split()))
s=sum(l)
e=l[0]
for i in range(1,n):
e=e^l[i]
if s==2*e:
print(0)
print ()
else:
print(2)
print(e,s+e)
``` | {
"language": "python",
"test_cases": [
{
"input": "3\n4\n1 2 3 6\n1\n8\n2\n1 1\n",
"output": "0\n\n2\n4 4\n3\n2 2 6\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/1270/C"
} | vfc_464 | false | false | false | false | false |
apps | verifiable_code | 117 | Solve the following coding problem using the programming language python:
All techniques in the ninja world consist of hand seals. At the moment Naruto is learning a new technique, which consists of $n\cdot m$ different seals, denoted by distinct numbers. All of them were written in an $n\times m$ table.
The table is... | ```python
from sys import stdin
input = stdin.readline
tests = int(input())
for test in range(tests):
n, m = list(map(int, input().split()))
a = [[0] * m for _ in range(n)]
r = [[int(i) for i in input().split()] for _ in range(n)]
c = [[int(i) for i in input().split()] for _ in range(m)]
z = [[-1, ... | {
"language": "python",
"test_cases": [
{
"input": "2\n2 3\n6 5 4\n1 2 3\n1 6\n2 5\n3 4\n3 1\n2\n3\n1\n3 1 2\n",
"output": "1 2 3 \n6 5 4 \n3 \n1 \n2 \n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/1413/B"
} | vfc_468 | false | false | false | false | false |
apps | verifiable_code | 118 | Solve the following coding problem using the programming language python:
There are $n$ programmers that you want to split into several non-empty teams. The skill of the $i$-th programmer is $a_i$. You want to assemble the maximum number of teams from them. There is a restriction for each team: the number of programme... | ```python
__MULTITEST = True
## solve
def solve():
n, x = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
group = 0
ptr = n-1
members = 0
currentMin = int(1e10)
while ptr > -1:
currentMin = min(currentMin, a[ptr])
members += 1
if current... | {
"language": "python",
"test_cases": [
{
"input": "3\n5 10\n7 11 2 9 5\n4 8\n2 4 2 3\n4 11\n1 3 3 7\n",
"output": "2\n1\n0\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/1380/C"
} | vfc_472 | false | false | false | false | false |
apps | verifiable_code | 119 | Solve the following coding problem using the programming language python:
Assume that you have $k$ one-dimensional segments $s_1, s_2, \dots s_k$ (each segment is denoted by two integers — its endpoints). Then you can build the following graph on these segments. The graph consists of $k$ vertexes, and there is an edge... | ```python
import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
n = int(input())
ab = [list(map(int,input().split())) for i in range(n-1)]
graph = [[] for i in range(n+1)]
deg = [0]*(n+1)
for a,b in ab:
graph[a].append(b)
graph[b].append(a)
deg[a] += 1
deg[b] += 1
pnt = [... | {
"language": "python",
"test_cases": [
{
"input": "1\n10\n1 2\n1 3\n1 4\n2 5\n2 6\n3 7\n3 8\n4 9\n4 10\n",
"output": "8\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/1238/F"
} | vfc_476 | false | false | false | false | false |
apps | verifiable_code | 120 | Solve the following coding problem using the programming language python:
Ayoub thinks that he is a very smart person, so he created a function $f(s)$, where $s$ is a binary string (a string which contains only symbols "0" and "1"). The function $f(s)$ is equal to the number of substrings in the string $s$ that contai... | ```python
import sys
input = sys.stdin.readline
t=int(input())
def calc(x):
return x*(x+1)//2
for test in range(t):
n,m=list(map(int,input().split()))
ANS=calc(n)
k=n-m
q,mod=divmod(k,m+1)
ANS-=calc(q+1)*mod+calc(q)*(m+1-mod)
print(ANS)
``` | {
"language": "python",
"test_cases": [
{
"input": "5\n3 1\n3 2\n3 3\n4 0\n5 2\n",
"output": "4\n5\n6\n0\n12\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/1301/C"
} | vfc_480 | false | false | false | false | false |
apps | verifiable_code | 121 | Solve the following coding problem using the programming language python:
Reminder: the median of the array $[a_1, a_2, \dots, a_{2k+1}]$ of odd number of elements is defined as follows: let $[b_1, b_2, \dots, b_{2k+1}]$ be the elements of the array in the sorted order. Then median of this array is equal to $b_{k+1}$.... | ```python
for _ in range(int(input())):
n = int(input())
ar = list(map(int, input().split()))
ar.sort()
print(abs(ar[n] - ar[n - 1]))
``` | {
"language": "python",
"test_cases": [
{
"input": "3\n1\n1 1\n3\n6 5 4 1 2 3\n5\n13 4 20 13 2 5 8 3 17 16\n",
"output": "0\n1\n5\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/1300/B"
} | vfc_484 | false | false | false | false | false |
apps | verifiable_code | 508 | Solve the following coding problem using the programming language python:
There is an infinitely long street that runs west to east, which we consider as a number line.
There are N roadworks scheduled on this street.
The i-th roadwork blocks the point at coordinate X_i from time S_i - 0.5 to time T_i - 0.5.
Q people a... | ```python
from heapq import heapify, heappush, heappop
import sys
input = sys.stdin.readline
def solve():
N, Q = list(map(int, input().split()))
events = []
for i in range(N):
S, T, X = list(map(int, input().split()))
events.append((S-X-0.5, 1, X))
events.append((T-X-0.5, 0, X))
... | {
"language": "python",
"test_cases": [
{
"input": "4 6\n1 3 2\n7 13 10\n18 20 13\n3 4 2\n0\n1\n2\n3\n5\n8\n",
"output": "2\n2\n10\n-1\n13\n-1\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://atcoder.jp/contests/abc128/tasks/abc128_e"
} | vfc_874 | false | false | false | false | true |
apps | verifiable_code | 509 | Solve the following coding problem using the programming language python:
Given is an undirected connected graph with N vertices numbered 1 to N, and M edges numbered 1 to M.
The given graph may contain multi-edges but not self loops.
Each edge has an integer label between 1 and N (inclusive).
Edge i has a label c_i, ... | ```python
import sys
sys.setrecursionlimit(10**6)
class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.... | {
"language": "python",
"test_cases": [
{
"input": "3 4\n1 2 1\n2 3 2\n3 1 3\n1 3 1\n",
"output": "1\n2\n1\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://atcoder.jp/contests/arc108/tasks/arc108_c"
} | vfc_878 | false | false | false | false | true |
apps | verifiable_code | 510 | Solve the following coding problem using the programming language python:
You are given a string S of length N consisting of lowercase English letters.
Process Q queries of the following two types:
- Type 1: change the i_q-th character of S to c_q. (Do nothing if the i_q-th character is already c_q.)
- Type 2: answe... | ```python
n = int(input())
s = list(input())
s = [ord(i)-97 for i in s]
dic = {}
for i in range(26):
dic[i] = []
for i in range(n):
dic[s[i]].append(i)
for i in range(26):
dic[i].append(float('inf'))
from bisect import bisect_left
q = int(input())
for i in range(q):
x, y, z = input().split()
if ... | {
"language": "python",
"test_cases": [
{
"input": "7\nabcdbbd\n6\n2 3 6\n1 5 z\n2 1 1\n1 4 a\n1 7 d\n2 1 7\n",
"output": "3\n1\n5\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://atcoder.jp/contests/abc157/tasks/abc157_e"
} | vfc_882 | false | false | false | false | true |
apps | verifiable_code | 511 | Solve the following coding problem using the programming language python:
There are N Snuke Cats numbered 1, 2, \ldots, N, where N is even.
Each Snuke Cat wears a red scarf, on which his favorite non-negative integer is written.
Recently, they learned the operation called xor (exclusive OR).What is xor?
For n non-neg... | ```python
n=int(input())
a=list(map(int,input().split()))
X=[]
b=a[0]
for i in range(1,n) :
b^=a[i]
for i in range(n) :
x=b^a[i]
X.append(x)
for i in X :
print(i,end=" ")
``` | {
"language": "python",
"test_cases": [
{
"input": "4\n20 11 9 24\n",
"output": "26 5 7 22\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://atcoder.jp/contests/abc171/tasks/abc171_e"
} | vfc_886 | false | false | false | false | true |
apps | verifiable_code | 512 | Solve the following coding problem using the programming language python:
There is a tree with N vertices numbered 1 to N.
The i-th edge in this tree connects Vertex a_i and Vertex b_i, and the color and length of that edge are c_i and d_i, respectively.
Here the color of each edge is represented by an integer between... | ```python
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**5)
N, Q = map(int, input().split())
path = [[] for _ in range(N)]
for _ in range(N-1) :
a, b, c, d = (int(i) for i in input().split())
path[a-1].append((b-1, c-1, d))
path[b-1].append((a-1, c-1, d))
# doublingに必要なKを求める
for K in ra... | {
"language": "python",
"test_cases": [
{
"input": "5 3\n1 2 1 10\n1 3 2 20\n2 4 4 30\n5 2 1 40\n1 100 1 4\n1 100 1 5\n3 1000 3 4\n",
"output": "130\n200\n60\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://atcoder.jp/contests/abc133/tasks/abc133_f"
} | vfc_890 | false | false | false | false | true |
apps | verifiable_code | 513 | Solve the following coding problem using the programming language python:
We have a tree with N vertices, whose i-th edge connects Vertex u_i and Vertex v_i.
Vertex i has an integer a_i written on it.
For every integer k from 1 through N, solve the following problem:
- We will make a sequence by lining up the integer... | ```python
import bisect
import sys
sys.setrecursionlimit(10**7)
def dfs(v):
pos=bisect.bisect_left(dp,arr[v])
changes.append((pos,dp[pos]))
dp[pos]=arr[v]
ans[v]=bisect.bisect_left(dp,10**18)
for u in g[v]:
if checked[u]==0:
checked[u]=1
dfs(u)
pos,val=changes.po... | {
"language": "python",
"test_cases": [
{
"input": "10\n1 2 5 3 4 6 7 3 2 4\n1 2\n2 3\n3 4\n4 5\n3 6\n6 7\n1 8\n8 9\n9 10\n",
"output": "1\n2\n3\n3\n4\n4\n5\n2\n2\n3\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://atcoder.jp/contests/abc165/tasks/abc165_f"
} | vfc_894 | false | false | false | false | true |
apps | verifiable_code | 514 | Solve the following coding problem using the programming language python:
Write a program to take two numbers as input and print their difference if the first number is greater than the second number otherwise$otherwise$ print their sum.
-----Input:-----
- First line will contain the first number (N1$N1$)
- Second li... | ```python
m = int(input())
n = int(input())
print(m-n) if m>n else print(m+n)
``` | {
"language": "python",
"test_cases": [
{
"input": "82\n28\n",
"output": "54\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/DIFFSUM"
} | vfc_898 | false | false | false | false | false |
apps | verifiable_code | 515 | Solve the following coding problem using the programming language python:
Witua is a little student from the University of Lviv. He enjoys studying math. Witua knows a lot of famous mathematicians like Eratosthenes, Pythagoras, Fermat, Diophantus, Furko, Gauss and so on. However, his favorite one is Euler. The only th... | ```python
# cook your dish here
def modular_pow(base, exponent, modulus):
result = 1
while exponent > 0:
if(exponent %2 == 1):
result = (result * base) % modulus
exponent = exponent//2
base = (base * base)%modulus
return result
def passesMillerRabinTest(n, a):
s = 0
d = n-1
while(d%2 == 0):
s += 1
d ... | {
"language": "python",
"test_cases": [
{
"input": "3\n2\n3\n4\n",
"output": "2\n3\n3\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/WITMATH"
} | vfc_902 | false | false | false | false | false |
apps | verifiable_code | 516 | Solve the following coding problem using the programming language python:
Almir had a small sequence $A_1, A_2, \ldots, A_N$. He decided to make $K$ copies of this sequence and concatenate them, forming a sequence $X_1, X_2, \ldots, X_{NK}$; for each valid $i$ and $j$ ($0 \le j < K$), $X_{j \cdot N + i} = A_i$.
For ex... | ```python
# cook your dish here
def count(k,n,m):
sum1=(m*(m+1))//2
sum2=(m*(m-1))//2
ct=0
for i in range(n):
for j in range(n):
if i<j and k[i]>k[j]:
ct+=sum1
elif j<i and k[i]>k[j]:
ct+=sum2
return ct
test=int(input())
for _ in range... | {
"language": "python",
"test_cases": [
{
"input": "2\n3 3\n2 1 3\n4 100\n99 2 1000 24\n\n",
"output": "12\n30000\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/INVYCNT"
} | vfc_906 | false | false | false | false | false |
apps | verifiable_code | 517 | Solve the following coding problem using the programming language python:
Indian National Olympiad in Informatics 2015
A string is any nonempty sequence of 0s and 1s. Examples of strings are 00, 101, 111000, 1, 0, 01. The length of a string is the number of symbols in it. For example, the length of 111000 is 6. If u a... | ```python
# cook your dish here
def offset(l, flag):
x = 0
# print(l)
for i in range(1, len(l)):
temp = []
for j in range(i):
v = getbig(l[i], l[j], fs)
if v > 1:
temp.append(v)
if flag:
x += 2**v - 2
... | {
"language": "python",
"test_cases": [
{
"input": "3 176\n",
"output": "6\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/INOIPRAC/problems/INOI1502"
} | vfc_910 | false | false | false | false | false |
apps | verifiable_code | 518 | Solve the following coding problem using the programming language python:
Finally, the pandemic is over in ChefLand, and the chef is visiting the school again. Chef likes to climb the stairs of his school's floor by skipping one step, sometimes chef climbs the stairs one by one. Simply, the chef can take one or 2 step... | ```python
for _ in range(int(input())):
N=int(input())
if N%2==0:
print(N//2+1)
else:
print((N-1)//2+1)
``` | {
"language": "python",
"test_cases": [
{
"input": "1\n3\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/PBK12020/problems/ITGUY20"
} | vfc_914 | false | false | false | false | false |
apps | verifiable_code | 519 | Solve the following coding problem using the programming language python:
Indian National Olympiad in Informatics 2016
There are k types of brackets each with its own opening bracket and closing bracket. We assume that the first pair is denoted by the numbers 1 and k+1, the second by 2 and k+2 and so on. Thus the ope... | ```python
# cook your dish here
import bisect
n, k1, *l = map(int, input().split())
v_l, b_l = l[:n], l[n:]
b_inv = {key:[] for key in range(2*k1)}
for i in range(n):
b_l[i] -= 1
b_inv[b_l[i]].append(i)
dp = [[0 for _ in range(n)] for _ in range(n)]
for k in range(1, n):
for j in range(n-2, -1... | {
"language": "python",
"test_cases": [
{
"input": "6 3 4 5 -2 1 1 6 1 3 4 2 5 6\n",
"output": "13\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/INOIPRAC/problems/INOI1602"
} | vfc_918 | false | false | false | false | false |
apps | verifiable_code | 520 | Solve the following coding problem using the programming language python:
Write a program that takes in a letterclass ID of a ship and display the equivalent string class description of the given ID. Use the table below.
Class ID Ship ClassB or bBattleShipC or cCruiserD or dDestroyerF or fFrigate
-----Input-----
Th... | ```python
# cook your dish here
t=int(input())
for i in range(t):
n=input()
if(n=='b' or n=='B'):
print('BattleShip')
elif(n=='c' or n=='C'):
print('Cruiser')
elif(n=='d' or n=='D'):
print('Destroyer')
else:
print('Frigate')
``` | {
"language": "python",
"test_cases": [
{
"input": "3\nB\nc\nD\n",
"output": "BattleShip\nCruiser\nDestroyer\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/FLOW010"
} | vfc_922 | false | false | false | false | false |
apps | verifiable_code | 521 | Solve the following coding problem using the programming language python:
Nature photographing may be fun for tourists, but it is one of the most complicated things for photographers. To capture all the facets of a bird, you might need more than one cameras. You recently encountered such a situation.
There are $n$ pho... | ```python
from math import *
from collections import *
import sys
input=sys.stdin.readline
t=int(input())
while(t):
t-=1
n=int(input())
a=list(map(int,input().split()))
p,q=map(int,input().split())
s=0
a.sort()
for i in range(n//2):
x=a[i]
x1=a[n-i-1]
i... | {
"language": "python",
"test_cases": [
{
"input": "2\n2\n0 1\n0 1\n2\n0 1\n100 1\n\n",
"output": "0.785398163397\n0.000100999899\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/CAPTBIRD"
} | vfc_926 | false | false | false | false | false |
apps | verifiable_code | 522 | Solve the following coding problem using the programming language python:
Three Best Friends $AMAN$ , $AKBAR$ , $ANTHONY$ are planning to go to “GOA” , but just like every other goa trip plan there is a problem to their plan too.
Their parents will only give permission if they can solve this problem for them
They are... | ```python
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 sys
sys.setrecursionlimit(10**9)
from math import sqrt,ceil,floor
n=int(input())
... | {
"language": "python",
"test_cases": [
{
"input": "3\n",
"output": "3\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/SPRT2020/problems/GOATRIP"
} | vfc_930 | false | false | false | false | false |
apps | verifiable_code | 523 | Solve the following coding problem using the programming language python:
Maheshmati and Sangu are playing a game. First, Maheshmati gives Sangu a sequence of $N$ distinct integers $a_1, a_2, \dots, a_N$ (not necessarily sorted) and an integer $K$. Sangu has to create all subsequences of this sequence with length $K$.... | ```python
f = 5003*[0]
modn = 1000000007
def qPow(a, b):
nonlocal modn
res = 1
while b > 0:
if (b & 1) == 1:
res = res * a % modn
a = a * a % modn
b = b >> 1
return res
def getF():
nonlocal f
f[0] = 1
for i in range(1, 5001):
f[i] = f[i-1] * i
def __starting_point():
getF()
T = int(input())
w... | {
"language": "python",
"test_cases": [
{
"input": "1\n4 3\n1 2 3 4\n",
"output": "36\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/NMNMX"
} | vfc_934 | false | false | false | false | false |
apps | verifiable_code | 524 | Solve the following coding problem using the programming language python:
There are total $N$ cars in a sequence with $ith$ car being assigned with an alphabet equivalent to the $ith$ alphabet of string $S$ . Chef has been assigned a task to calculate the total number of cars with alphabet having a unique even value i... | ```python
arr = list(input())
n = len(arr)
ans = list()
#for i in arr:
#ans.append(ord(i)-96)
li = ['b','d','f','h','j','l','n','p','r','t','v','x','z']
s = set(arr)
temp = s.intersection(li)
for _ in range(int(input())):
x,y = list(map(int,input().split()))
li = list(temp)
#s = set()
c=... | {
"language": "python",
"test_cases": [
{
"input": "bbccdd\n5\n1 2\n3 4\n5 6\n1 6\n2 5\n",
"output": "1\n0\n1\n2\n2\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/STRG2020/problems/TOTCARS"
} | vfc_938 | false | false | false | false | false |
apps | verifiable_code | 525 | Solve the following coding problem using the programming language python:
You are given three numbers $a$, $b$, $c$ . Write a program to determine the largest number that is less than or equal to $c$ and leaves a remainder $b$ when divided by $a$.
-----Input:-----
- First line will contain $T$, number of testcases. T... | ```python
# cook your dish here
for t in range(int(input())):
a,b,c=map(int,input().split())
p=(c//a)*a+b
if p<=c:
print(p)
else:
print(((c//a)-1)*a+b)
``` | {
"language": "python",
"test_cases": [
{
"input": "1\n7 2 10\n",
"output": "9\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/CCOD2020/problems/MOTU001"
} | vfc_942 | false | false | false | false | false |
apps | verifiable_code | 526 | Solve the following coding problem using the programming language python:
Aureole the Techno-cultural fest of JEC thought of conducting a workshop on big data, as the topic is hot everyone wants to take part but due to limited seats in the Jashan Auditorium there is a selection criteria, a problem is given.
the proble... | ```python
#include<sdg.h>
for _ in range(int(input())):
s=input()
n=len(s)
if n==1:
if s[0].isalpha(): print("-32")
else: print(0)
else:
num,ch=0,0
p,q=0,0
c=1
x=s[0]
ans=""
for i in range(1,n):
if s[i-1]==s[i]:
... | {
"language": "python",
"test_cases": [
{
"input": "1\naaabb\n",
"output": "-40\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/COPT2020/problems/AUREOLE"
} | vfc_946 | false | false | false | false | false |
apps | verifiable_code | 527 | Solve the following coding problem using the programming language python:
Given an Array of length $N$ containing elements $Ai$ ( i = 1 to n ) . You have to handle $Q$ queries on this array . Each Query is of two types k=(1 or 2).
Type 1:- $k$ $l$ $r$ in which you have to tell whether the product of numbers in rang... | ```python
def update(index, value, bi_tree):
while index < len(bi_tree):
bi_tree[index] += value
index += index & -index
def get_sum(index, bi_tree):
ans = 0
while index > 0:
ans += bi_tree[index]
index -= index & -index
return ans
def get_range_sum(left, right, bi_tree):
ans = get_sum(right, bi_tree)... | {
"language": "python",
"test_cases": [
{
"input": "4\n2 2 3 4\n4\n1 1 2\n1 3 4\n2 3 3\n1 1 4\n",
"output": "YES\nNO\nYES\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/STRT2020/problems/RANPRO"
} | vfc_950 | false | false | false | false | false |
apps | verifiable_code | 528 | Solve the following coding problem using the programming language python:
Recently in JEC ants have become huge, the Principal is on a journey to snipe them !!
Principal has limited $N$ practice Bullets to practice so that he can be sure to kill ants.
- The Practice ground has max length $L$.
- There is a Limit X such... | ```python
# cook your dish here
from sys import stdin,stdout
from collections import deque,defaultdict
from math import ceil,floor,inf,sqrt,factorial,gcd,log
from copy import deepcopy
ii1=lambda:int(stdin.readline().strip())
is1=lambda:stdin.readline().strip()
iia=lambda:list(map(int,stdin.readline().strip().split()))... | {
"language": "python",
"test_cases": [
{
"input": "2\n1 10\n2 10\n",
"output": "10\n4\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/COPT2020/problems/ANTHUNT"
} | vfc_954 | false | false | false | false | false |
apps | verifiable_code | 529 | Solve the following coding problem using the programming language python:
Given an integer N. Integers A and B are chosen randomly in the range [1..N]. Calculate the probability that the Greatest Common Divisor(GCD) of A and B equals to B.
-----Input-----
The first line of the input contains an integer T denoting the... | ```python
import math
for _ in range(int(input())):
n=int(input())
s=int(math.sqrt(n))
ans=0
for i in range(1,s+1):
ans+=(n//i)
ans=ans*2-(s*s)
g=math.gcd(n*n,ans)
print(str(ans//g)+"/"+str(n*n//g))
``` | {
"language": "python",
"test_cases": [
{
"input": "3\n1\n2\n3\n",
"output": "1/1\n3/4\n5/9\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/COOLGUYS"
} | vfc_958 | false | false | false | false | false |
apps | verifiable_code | 530 | Solve the following coding problem using the programming language python:
The median of a sequence is the element in the middle of the sequence after it is sorted. For a sequence with even size, the median is the average of the two middle elements of the sequence after sorting. For example, for a sequence $A = [1, 3, ... | ```python
# cook your dish here
# cook your dish here
import numpy as np
import sys
def findSeq(n, s, k, m, M):
midInd = n // 2
seqs = []
for ind in range(midInd + 2, midInd - 3, -1):
if ind >= n or ind < 0:
continue
seq = genBestSeq(n, ind, m, M, s)
if seq is not -... | {
"language": "python",
"test_cases": [
{
"input": "2\n3 6 1 1 5\n4 4 2 1 3\n\n",
"output": "1 1 4\n-1\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/HACKFU"
} | vfc_962 | false | false | false | false | false |
apps | verifiable_code | 531 | Solve the following coding problem using the programming language python:
Shashank is playing a game with his friends.
There are n sticks located in a row at points $a_1,a_2, ...,a_n$. Each stick has a height- $h_i$. A person can chop a stick down, after which it takes over one of the regions [$a_i$ - $h_i$, $a_i$] or... | ```python
# cook your dish here
n=int(input())
counts=dict()
z=0
upper=None
for i in range(0,n):
a,h= [int(num) for num in input().split()]
counts[a]=h
for key,count in counts.items():
c=0
x=key-count
y=key+count
c1=0
c2=0
for j in counts.keys():
if j==key:
continue
else:
if x<=j<=key:
c1=0
br... | {
"language": "python",
"test_cases": [
{
"input": "5\n1 2\n2 1\n5 10\n10 9\n19 1\nSample Input 2:\n5\n1 2\n2 1\n5 10\n10 9\n20 1\n",
"output": "3\nSample Output 2:\n4\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/COTH2020/problems/STKGAME"
} | vfc_966 | false | false | false | false | false |
apps | verifiable_code | 532 | Solve the following coding problem using the programming language python:
To help Lavanya learn all about binary numbers and binary sequences, her father has bought her a collection of square tiles, each of which has either a 0 or a 1 written on it. Her brother Nikhil has played a rather nasty prank. He has glued toge... | ```python
n=int(input())
modulo=15746
num=[1,1]
for i in range(2,n+1):
num.append((num[i-1]+num[i-2])%modulo)
print(num[n])
``` | {
"language": "python",
"test_cases": [
{
"input": "4\n",
"output": "5\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/IARCSJUD/problems/TILES01"
} | vfc_970 | false | false | false | false | false |
apps | verifiable_code | 533 | Solve the following coding problem using the programming language python:
The chef is playing a game of long distance. Chef has a number K and he wants to find the longest distance between the index of the first and the last occurrence of K in a given array of N numbers.
-----Input:-----
- First-line will contain $T$... | ```python
# cook your dish here
for _ in range(int(input())):
m,n=list(map(int,input().split()))
a=[int(i) for i in input().split()]
l=-1
for i in range(n-1,-1,-1):
if a[i]==m:
l=i
break
f=-1
for i in range(0,n):
if a[i]==m:
f=i
bre... | {
"language": "python",
"test_cases": [
{
"input": "2\n2 6\n2 3 4 2 1 6\n4 6\n2 3 4 2 1 6\n",
"output": "3\n0\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/PBK32020/problems/ITGUY33"
} | vfc_974 | false | false | false | false | false |
apps | verifiable_code | 534 | Solve the following coding problem using the programming language python:
Vasya's older brother, Petya, attends an algorithm course in his school. Today he learned about matchings in graphs. Formally, a set of edges in a graph is called a matching if no pair of distinct edges in the set shares a common endpoint.
Petya... | ```python
def detect_triangle(adj):
for x in range(len(adj)):
for y in adj[x]:
if not set(adj[x]).isdisjoint(adj[y]):
return True
for _ in range(int(input())):
n,m=list(map(int,input().split()))
graph=[[] for i in range(n)]
for i in range(m):
u,v=list(map(int,input().split()))... | {
"language": "python",
"test_cases": [
{
"input": "3\n3 3\n1 2\n1 3\n2 3\n4 2\n1 2\n3 4\n5 0\n",
"output": "3\n1\n0\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/ANTMAT"
} | vfc_978 | false | false | false | false | true |
apps | verifiable_code | 535 | Solve the following coding problem using the programming language python:
Chef got in the trouble! He is the king of Chefland and Chessland. There is one queen in Chefland and one queen in Chessland and they both want a relationship with him. Chef is standing before a difficult choice…
Chessland may be considered a ch... | ```python
def C(n):
return n*(n-1)//2
def sol():
equal, mini = False, min(N,M)
total_ways = 2*C(N * M)
if N==M:
equal = True
ways = 0
if not equal:
ways = (N*C(M)+M*C(N))
diag = 0
for i in range(2, mini+1):
diag += 2*C(i)
for i in range(mini+1,max(N,M)):
diag += C(mini)
diag *= 2
ways += dia... | {
"language": "python",
"test_cases": [
{
"input": "2\n3 3 2 2\n4 4 2 3\n",
"output": "24\n94\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/CHQUEENS"
} | vfc_982 | false | false | false | false | false |
apps | verifiable_code | 536 | Solve the following coding problem using the programming language python:
2021 was approaching and the world was about to end. So 2 gods Saurabhx and Saurabhy (from Celesta) created the Cyberverse. But this time disappointed with humans both the gods decided not to have humans in this world. So they created a world of... | ```python
# cook your dish here
t=int(input())
for i in range(t):
(n,k)=tuple(map(int,input().split()))
print(k//n)
``` | {
"language": "python",
"test_cases": [
{
"input": "1\n5 8\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/CYBV"
} | vfc_986 | false | false | false | false | false |
apps | verifiable_code | 537 | Solve the following coding problem using the programming language python:
Zonal Computing Olympiad 2015, 29 Nov 2014
We say that two integers x and y have a variation of at least K, if |x − y| ≥ K (the absolute value of their difference is at least K). Given a sequence of N integers a1,a2,...,aN and K, the total vari... | ```python
n,k=[int(x) for x in input().split()]
a=[int(x) for x in input().split()]
ans=0
for i in range(n-1):
for j in range(i+1,n):
if(abs(a[i]-a[j])>=k):
ans+=1
print(ans)
``` | {
"language": "python",
"test_cases": [
{
"input": "3 1\n3 1 3\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/ZCOPRAC/problems/ZCO15002"
} | vfc_990 | false | false | false | false | false |
apps | verifiable_code | 538 | Solve the following coding problem using the programming language python:
Sebi goes to school daily with his father. They cross a big highway in the car to reach to the school. Sebi sits in front seat beside his father at driving seat. To kill boredom, they play a game of guessing speed of other cars on the highway. S... | ```python
# cook your dish here
n=int(input())
for i in range(n):
S, SG, FG, D, T = map(int, input().split())
speed = (D*180)/T + S
if abs(SG-speed) == abs(FG-speed):
print('DRAW')
elif abs(SG-speed) > abs(FG-speed):
print('FATHER')
else:
print('SEBI')
``` | {
"language": "python",
"test_cases": [
{
"input": "2\n100 180 200 20 60\n130 131 132 1 72\n\n\n",
"output": "SEBI\nFATHER\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/SEBIHWY"
} | vfc_994 | false | false | false | false | false |
apps | verifiable_code | 539 | Solve the following coding problem using the programming language python:
Bob has got some injury in his leg and due to this he can take exactly M steps in one move.
Bob enters a square field of size NxN. The field is only having one gate(for both entrance and exit) at its one of the corners. Bob started walking alon... | ```python
# By Prathmesh Maurya
t=eval(input())
while(t!=0):
t-=1
n=eval(input())
if n%2 == 0:
print(n*4)
elif n%4==3:
print(n)
else:
print(n*2)
``` | {
"language": "python",
"test_cases": [
{
"input": "2\n1\n2\n",
"output": "2\n8\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/LOCAUG16/problems/BSQUARE"
} | vfc_998 | false | false | false | false | false |
apps | verifiable_code | 540 | Solve the following coding problem using the programming language python:
Chef has a sequence of positive integers $A_1, A_2, \ldots, A_N$. He wants to choose some elements of this sequence (possibly none or all of them) and compute their MEX, i.e. the smallest positive integer which does not occur among the chosen el... | ```python
for __ in range(int(input())):
n,m=map(int,input().split())
arr=list(map(int,input().split()))
s=set(arr)
mex=-1
ele=1
for i in range(1,n+1):
if i not in s:
mex = i
break
if m>mex:
print(-1)
elif m==mex:
print(n... | {
"language": "python",
"test_cases": [
{
"input": "1\n3 3\n1 2 4\n\n",
"output": "3\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/MAXMEX"
} | vfc_1002 | false | false | false | false | false |
apps | verifiable_code | 541 | Solve the following coding problem using the programming language python:
"Humankind cannot gain anything without first giving something in return. To obtain, something of equal value must be lost. That is alchemy's first law of Equivalent Exchange. In those days, we really believed that to be the world's one, and onl... | ```python
for i in range(int(input())):
n = int(input())
c = list(map(int, input().split()))
d = {}
d[0] = -1
parity = 0
ans = 0
for i in range(n):
parity ^= 1 << (c[i]-1)
for t in range(30):
x = parity^(1<<t)
if(x in d.keys()):
ans = max(ans, i - d[x])
if p... | {
"language": "python",
"test_cases": [
{
"input": "4\n14\n5 4 2 2 3 2 1 3 2 7 4 9 9 9\n3\n1 2 1\n3\n1 1 1\n5\n1 2 3 4 1\n",
"output": "3\n1\n1\n0\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/LEQEX"
} | vfc_1006 | false | false | false | false | false |
apps | verifiable_code | 542 | Solve the following coding problem using the programming language python:
Chef has just finished the construction of his new garden. He has sown the garden with patches of the most beautiful carpet grass he could find. He has filled it with patches of different color and now he wants to evaluate how elegant his garden... | ```python
# cook your dish here
import sys
import math
def main(grid):
ans=0
for i in range(len(grid)):
for j in range(len(grid[0])):
first_point=grid[i][j]
for k in range(j+1,len(grid[0])):
second_point=grid[i][k]
if first_point==second_point:
... | {
"language": "python",
"test_cases": [
{
"input": "3\n2 2\naa\naA\n3 3\naba\nbab\naba\n4 4\naabb\naabb\nbbaa\nbbaa\n\n\n",
"output": "0\n1\n4\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/GARDENSQ"
} | vfc_1010 | false | false | false | false | false |
apps | verifiable_code | 543 | Solve the following coding problem using the programming language python:
Ram and Shyam are playing a game of Truth and Dare. In this game, Shyam will ask Ram to perform tasks of two types:
- Truth task: Ram has to truthfully answer a question.
- Dare task: Ram has to perform a given task.
Each task is described by an... | ```python
# cook your dish here
for _ in range(int(input())):
tr=int(input())
trl=list(map(int,input().split()))
dr = int(input())
drl = list(map(int, input().split()))
ts = int(input())
tsl = list(map(int, input().split()))
ds = int(input())
dsl = list(map(int, input().split()))
for... | {
"language": "python",
"test_cases": [
{
"input": "4\n2\n1 2\n3\n1 3 2\n1\n2\n2\n3 2\n2\n1 2\n3\n1 3 2\n1\n2\n3\n3 2 4\n3\n3 2 5\n2\n2 100\n1\n2\n1\n100\n2\n1 2\n3\n1 3 2\n1\n2\n3\n3 2 2\n\n",
"output": "yes\nno\nyes\nyes\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/TRUEDARE"
} | vfc_1014 | false | false | false | false | true |
apps | verifiable_code | 544 | Solve the following coding problem using the programming language python:
An encoder encodes the first $16$ lowercase English letters using $4$ bits each. The first bit (from the left) of the code is $0$ if the letter lies among the first $8$ letters, else it is $1$, signifying that it lies among the last $8$ letters.... | ```python
# cook your dish here
def decode(L,S):
str_2=""
lst=[]
for i in range(L//4):
str_1 = "abcdefghijklmnop"
S_1=S[(i*4):(4*(i+1))]
for j in range(4):
if(S_1[j]=="1"):
str_1=str_1[len(str_1)//2:len(str_1)]
else:
str_1 = str_1[0:len(str_1) // 2]
str_2=str_2+str_1
print(str_2)
T=int(input(... | {
"language": "python",
"test_cases": [
{
"input": "3\n4\n0000\n8\n00001111\n4\n1001\n",
"output": "a\nap\nj\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/DECODEIT"
} | vfc_1018 | false | false | false | false | false |
apps | verifiable_code | 545 | Solve the following coding problem using the programming language python:
Chef wants to serve mankind by making people immortal by preparing a dish, a dish of life - a dish with the best taste in the universe, one with the smell and splash of fresh water flowing down the springs of the mountain, one with the smell of ... | ```python
for _ in range(int(input())):
n,k = list(map(int,input().split()))
array = []
tot = []
for _ in range(n):
temp = list(map(int,input().split()))
aa = temp[0]
del(temp[0])
temp.sort()
temp.insert(0,aa)
array.append(temp)
dic = {}
array.sort(reverse=True)
for i in array:
del(i[0])
for i in ... | {
"language": "python",
"test_cases": [
{
"input": "3\n3 4\n3 1 2 3\n2 1 3\n2 1 2\n2 3\n3 1 2 3\n2 1 3\n2 3\n2 1 2\n2 1 3\n",
"output": "sad\nsome\nall\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/DISHLIFE"
} | vfc_1022 | false | false | false | false | false |
apps | verifiable_code | 546 | Solve the following coding problem using the programming language python:
Motu and Patlu are playing with a Magical Ball. Patlu find some interesting pattern in the motion of the ball that ball always bounce back from the ground after travelling a linear distance whose value is some power of $2$. Patlu gave Motu total... | ```python
# cook your dish here
test=int(input())
for _ in range(test):
n=int(input())
n=list(bin(n))
ans=n.count('1')
print(ans-1)
``` | {
"language": "python",
"test_cases": [
{
"input": "1\n13\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/SMTC2020/problems/BBALLS"
} | vfc_1026 | false | false | false | false | false |
apps | verifiable_code | 547 | Solve the following coding problem using the programming language python:
Two players are playing a game. The game is played on a sequence of positive integer pairs. The players make their moves alternatively. During his move the player chooses a pair and decreases the larger integer in the pair by a positive multiple... | ```python
import sys
t = int(input())
def g(a,b):
if (a > b):
tmp = a
a = b
b = tmp
if (b == a):
return 0
if (b % a == 0):
return int(b/a)-1
r = g(b%a,a)
q = int(b/a)
if (r >= q):
return q-1
else:
return q
def mex(x):
n = len(list(x.keys()))
for i in range(n):
if (i not in x):
return i
r... | {
"language": "python",
"test_cases": [
{
"input": "3\n1\n2 3\n2\n4 5\n5 6\n2\n2 3\n3 5\n",
"output": "NO\nNO\nYES\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/GAMEAAM"
} | vfc_1030 | false | false | false | false | false |
apps | verifiable_code | 548 | Solve the following coding problem using the programming language python:
The chef is trying to solve some pattern problems, Chef wants your help to code it. Chef has one number K to form a new pattern. Help the chef to code this pattern problem.
-----Input:-----
- First-line will contain $T$, the number of test case... | ```python
# cook your dish here
for i in range(int(input())):
n=int(input())
p=1
l=n-1
for j in range(n):
for k in range(l):
print(" ",end='')
for k in range(p):
print("*",end='')
print()
for k in range(l):
print(" ",end='')
for... | {
"language": "python",
"test_cases": [
{
"input": "4\n1\n2\n3\n4\n",
"output": "*\n*\n*\n*\n***\n***\n*\n*\n***\n***\n*****\n*****\n*\n*\n***\n***\n*****\n*****\n*******\n*******\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/PTRN2020/problems/ITGUY42"
} | vfc_1034 | false | false | false | false | false |
apps | verifiable_code | 549 | Solve the following coding problem using the programming language python:
In a fictitious city of CODASLAM there were many skyscrapers. The mayor of the city decided to make the city beautiful and for this he decided to arrange the skyscrapers in descending order of their height, and the order must be strictly decreas... | ```python
import sys
num=int(sys.stdin.readline())
s=sys.stdin.readline().split()
sky=list(map(int,s))
sky.reverse()
cuts=0
change=0
t=False
i=1
while i<len(sky):
if sky[i]<=sky[i-1]:
for j in range(i-1,-1,-1):
if sky[j]<=sky[i]-(i-j):
break
else:
change+=sky[j]-(sky[i]-(i-j))
if change... | {
"language": "python",
"test_cases": [
{
"input": "5\n1 2 3 4 5\n",
"output": "8\nBy:\nChintan,Asad,Ashayam,Akanksha\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/IGNS2012/problems/IG04"
} | vfc_1038 | false | false | false | false | false |
apps | verifiable_code | 550 | Solve the following coding problem using the programming language python:
There is Chef and Chef’s Crush who are playing a game of numbers.
Chef’s crush has a number $A$ and Chef has a number $B$.
Now, Chef wants Chef’s crush to win the game always, since she is his crush. The game ends when the greatest value of A^... | ```python
def main():
t = int(input())
while (t):
m, n = map(int, input().split())
a , b= bin(m)[2:],bin(n)[2:]
#print(a,b)
max = m^n
if len(a)>len(b):
diff =len(a)-len(b)
b= ("0"*diff)+b
#print(b)
elif len(a)<len(b):
diff =len(b)-len(a)
a= ("0"*diff)+a
#print(a)
ll = len(b)
count= ... | {
"language": "python",
"test_cases": [
{
"input": "1\n4 5\n",
"output": "2 7\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/CHPTRS01/problems/GAMENUM"
} | vfc_1042 | false | false | false | false | false |
apps | verifiable_code | 551 | Solve the following coding problem using the programming language python:
Chef Tobby is playing a rapid fire with Bhuvan. He gives Bhuvan a string S and each time, Bhuvan has to guess whether there exists 2 equal subsequences in the string or not.
Bhuvan got a perfect score in the game with Chef Tobby. However, Chef T... | ```python
t = int(input())
for _ in range(t):
s = [x for x in input()]
freq = {}
for i in s:
if i in freq:
freq[i] += 1
else:
freq[i] = 1
flag = 0
for keys, values in freq.items():
if(values >= 2):
flag = 1
break
if(flag == 0):
print("no")
else:
print("yes")
``` | {
"language": "python",
"test_cases": [
{
"input": "4\nlikecs\nvenivedivici\nbhuvan\ncodechef\n",
"output": "no\nyes\nno\nyes\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/LIKECS01"
} | vfc_1046 | false | false | false | false | false |
apps | verifiable_code | 552 | Solve the following coding problem using the programming language python:
Chef has gone shopping with his 5-year old son. They have bought N items so far. The items are numbered from 1 to N, and the item i weighs Wi grams.
Chef's son insists on helping his father in carrying the items. He wants his dad to give him a ... | ```python
def main():
T = int(input())
for t in range(T):
N,K = map(int, input().split())
W = list(map(int, input().split()))
W.sort()
if 2*K > N:
K = N - K
kid = sum(W[:K])
dad = sum(W[K:])
diff = dad - kid
print(diff)
def __starting_point():
main()
__starting_point()
``` | {
"language": "python",
"test_cases": [
{
"input": "2\n5 2\n8 4 5 2 10\n8 3\n1 1 1 1 1 1 1 1\n",
"output": "17\n2\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/MAXDIFF"
} | vfc_1050 | false | false | false | false | true |
apps | verifiable_code | 553 | Solve the following coding problem using the programming language python:
Consider the following operations on a triple of integers. In one operation, you should:
- Choose an integer $d$ and an arithmetic operation ― either addition or multiplication.
- Choose a subset of elements of the triple.
- Apply the arithmetic... | ```python
def eq_solve(v0, v1, u0, u1):
den = u0 - v0
num = u1 - v1
if den != 0:
return num / den
return 1
def solve(p, q, r, a, b, c, rs):
if p == a and q == b and r == c:
return rs
if rs >= 2:
return 3
res = 3
adds = [a - p, b - q, c - r]
mul... | {
"language": "python",
"test_cases": [
{
"input": "2\n3 5 7\n6 5 10\n8 6 3\n9 7 8\n\n",
"output": "1\n2\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/TTUPLE"
} | vfc_1054 | false | false | false | false | false |
apps | verifiable_code | 554 | Solve the following coding problem using the programming language python:
Johnny was asked by his math teacher to compute nn (n to the power of n, where n is an integer), and has to read his answer out loud. This is a bit of a tiring task, since the result is probably an extremely large number, and would certainly kee... | ```python
from math import log10
from decimal import Decimal
def solve(n,k):
mod=10**k
x=Decimal(n)
y=x*(x.log10())%1
p=str(pow(10,y))
c=0
first=''
for v in p:
if c==k:
break
if v==".":
continue
first+=v
c+=1
last=str(pow(n,n,mod)).zfill(k)
return (first,last)
queries=[]
for _ in range(int(inpu... | {
"language": "python",
"test_cases": [
{
"input": "2\n4 2\n9 3\n",
"output": "25 56\n387 489\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/A4"
} | vfc_1058 | false | false | false | false | false |
apps | verifiable_code | 555 | Solve the following coding problem using the programming language python:
Sherlock Holmes has decided to start a new academy to some of the young lads. He has conducted several tests and finally selected N equally brilliant
students.Now he don't know whether to train all the N students or not. Now since Holmes was in... | ```python
t = eval(input())
for i in range(t):
n = eval(input())
a = list(map(int, input().split()))
cnt = 2
cnt1 = 2
ll = len(a)
if ll < 3:
cnt1 = ll
else:
for j in range(2,ll):
if a[j-1] + a[j-2] == a[j]:
cnt += 1
cnt1 = max(cnt1, cnt)
else:
cnt1 = max(cnt1, cnt)
cnt = 2
print(cnt1)... | {
"language": "python",
"test_cases": [
{
"input": "2\n5\n2 3 5 1 2\n3\n1 2 3\n",
"output": "3\n3\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/LOCAPR16/problems/ACDEMY"
} | vfc_1062 | false | false | false | false | false |
apps | verifiable_code | 556 | Solve the following coding problem using the programming language python:
A robot is initially at $(0,0)$ on the cartesian plane. It can move in 4 directions - up, down, left, right denoted by letter u, d, l, r respectively. More formally:
- if the position of robot is $(x,y)$ then u makes it $(x,y+1)$
- if the positi... | ```python
z = int(input())
i = 0
while i < z:
n = int(input())
p = int(n**(0.5))
if p*(p+1) < n:
p += 1
# print("P", p)
x, y = 0, 0
q = 0
flag = True
if p*(p+1) == n:
# print("Even steps, nice")
q = p
else:
# remaining steps
q = p-1
flag = False
if q%2 :... | {
"language": "python",
"test_cases": [
{
"input": "5\n1\n2\n3\n50\n12233443\n",
"output": "0 1\n-1 1\n-1 0\n2 4\n-1749 812\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/DECO2020/problems/DECOSNKE"
} | vfc_1066 | false | false | false | false | false |
apps | verifiable_code | 557 | Solve the following coding problem using the programming language python:
Prof. Sergio Marquina is a mathematics teacher at the University of Spain. Whenever he comes across any good question(with complexity k), he gives that question to students within roll number range i and j.
At the start of the semester he assign... | ```python
# cook your dish here
for t in range(int(input())):
n,m=[int(x)for x in input().rstrip().split()]
s=[]
for p in range(n):
s.append(10)
for c in range(m):
i,j,k=[int(x)for x in input().rstrip().split()]
for q in range(i-1,j):
s[q]=s[q]*k
print(sum(s)//n)
``` | {
"language": "python",
"test_cases": [
{
"input": "1\n5 3\n1 3 5\n2 5 2\n3 4 7\n",
"output": "202\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/CMR12121/problems/ELPF"
} | vfc_1070 | false | false | false | false | false |
apps | verifiable_code | 558 | Solve the following coding problem using the programming language python:
The city of Siruseri is impeccably planned. The city is divided into a rectangular array of cells with $M$ rows and $N$ columns. Each cell has a metro station. There is one train running left to right and back along each row, and one running top... | ```python
from queue import PriorityQueue
m,n=list(map(int,input().split()))
rr=[]
cc=[]
speed={'S':3,'O':2,'F':1}
visited=set()
dp=[]
def qwerty(cur,x,y,f):
if f==0:
gg=rr[x][1]+y*rr[x][0]
while gg<cur:
gg+=(2*(n-1))*rr[x][0]
return gg-cur+rr[x][0]
elif f==1:
gg=rr[x][1]+(2*(n-1)-y)*rr[x][... | {
"language": "python",
"test_cases": [
{
"input": "3 4\nF 3\nS 2\nO 2\nS 1\nF 2\nO 2\nF 4\n2 3 8 1 1\n",
"output": "15\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/IARCSJUD/problems/METRO"
} | vfc_1074 | false | false | false | false | false |
apps | verifiable_code | 559 | Solve the following coding problem using the programming language python:
Taxis of Kharagpur are famous for making sharp turns. You are given the coordinates where a particular taxi was on a 2-D planes at N different moments: (x1, y1), (x2, y2), ..., (xN, yN). In between these coordinates, the taxi moves on a straight... | ```python
import math
import copy
try:
import psyco
psyco.full()
except ImportError:
pass
def isSharp(ang):
return ang > math.pi/4 + 0.00001
def unitVector(p2, p1):
d0 = p2[0] - p1[0]
d1 = p2[1] - p1[1]
d = math.sqrt(d0*d0 + d1*d1)
if d != 0:
return [d0/d, d1/d]
return [0, 0]
def compVectors(P):
V = [... | {
"language": "python",
"test_cases": [
{
"input": "5\n3\n0 0\n1 1\n2 1\n3\n0 0\n1 0\n6 1\n3\n0 0\n1 0\n1 1\n4\n0 0\n1 0\n1 1\n6 1\n6\n0 0\n1 0\n1 1\n2 1\n2 2\n3 2\n",
"output": "yes yes\nyes yes\nno yes\nno yes\nno no\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/TAXITURN"
} | vfc_1078 | false | false | false | false | false |
apps | verifiable_code | 560 | Solve the following coding problem using the programming language python:
Chef is the judge of a competition. There are two players participating in this competition — Alice and Bob.
The competition consists of N races. For each i (1 ≤ i ≤ N), Alice finished the i-th race in Ai minutes, while Bob finished it in Bi min... | ```python
# cook your dish here
for i in range(int(input())):
N=int(input())
ALICE=list(map(int,input().split()))
BOB=list(map(int,input().split()))
ALICE[ALICE.index(max(ALICE))]=0
BOB[BOB.index(max(BOB))]=0
if sum(ALICE)<sum(BOB):
print("Alice")
elif sum(BOB)<sum(ALICE):
print("Bob")
else:
print("Draw")... | {
"language": "python",
"test_cases": [
{
"input": "3\n5\n3 1 3 3 4\n1 6 2 5 3\n5\n1 6 2 5 3\n3 1 3 3 4\n3\n4 1 3\n2 2 7\n",
"output": "Alice\nBob\nDraw\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/CO92JUDG"
} | vfc_1082 | false | false | false | false | false |
apps | verifiable_code | 561 | Solve the following coding problem using the programming language python:
This time minions are celebrating Diwali Festival. There are N minions in total. Each of them owns a house. On this Festival, Each of them wants to decorate their house. But none of them have enough money to do that. One of the minion, Kevin, re... | ```python
def find_combinations(list, sum):
if not list:
if sum == 0:
return [[]]
return []
return find_combinations(list[1:], sum) + \
[[list[0]] + tail for tail in
find_combinations(list[1:], sum - list[0])]
for tc in range(int(input())):
n,k=list(map(int,input().split()))
a=list(map(int,input().split... | {
"language": "python",
"test_cases": [
{
"input": "2\n4 9\n5 2 2 4\n4 9\n5 2 18 3\n",
"output": "YES\nNO\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/CFSN2015/problems/LINSUB"
} | vfc_1086 | false | false | false | false | false |
apps | verifiable_code | 562 | Solve the following coding problem using the programming language python:
Chef loves to play chess, so he bought a new chessboard with width M$M$ and height N$N$ recently.
Chef considers a chessboard correct if its width (number of columns) is equal to its height (number of rows) and each cell has no side-adjacent cel... | ```python
# cook your dish here
n,m=map(int,input().split())
L=[]
for i in range(n):
s=input()
L.append(s)
cost=[]
h2=[0]*(m+1)
cost.append(h2)
for i in range(n):
h=[0]
for j in range(m):
if(L[i][j]=='0' and (i+j)%2!=0):
h.append(1)
elif(L[i][j]=='1' and (i+j)%2==0):
... | {
"language": "python",
"test_cases": [
{
"input": "8 8\n00101010\n00010101\n10101010\n01010101\n10101010\n01010101\n10101010\n01010101\n4\n1 2 0 1001\n",
"output": "7\n8\n6\n8\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/SURCHESS"
} | vfc_1090 | false | false | false | false | false |
apps | verifiable_code | 563 | Solve the following coding problem using the programming language python:
The land of Programmers Army is surrounded by many islands. A unique number is associated with each island. The king of the islands is a very generous person, he donates a certain amount of gold coins to travelers for visiting each island that t... | ```python
# cook your dish here
for i in range(int(input())):
N = int(input())
l = list(map(int, input().split()))
for j in range(int(input())):
q1, q2 = map(int, input().split())
temp = l[q1 - 1 : q2]
print(sum(temp))
``` | {
"language": "python",
"test_cases": [
{
"input": "1\n4\n10 2 5 50\n2\n1 3\n2 4\n",
"output": "17\n57\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/ARYS2020/problems/GOLDTRIP"
} | vfc_1094 | false | false | false | false | false |
apps | verifiable_code | 564 | Solve the following coding problem using the programming language python:
-----Coal Company -----
The Tunisian Coal Mining company uses a train to ferry out coal blocks from its coal mines. The train has N containers numbered from 1 to N which need to
be filled with blocks of coal. Assume there are infinite coal blo... | ```python
for _ in range(int(input())):
n,k=list(map(int,input().split()))
c=list(map(int,input().split()))
count=1
for i in range(n):
if i+1<n:
if c[i]-c[i+1]>=k or c[i+1]-c[i]>=k:
continue
else:
count+=1
c[i],c[i+1]=c[i+1],c[i]
print(count)
``` | {
"language": "python",
"test_cases": [
{
"input": "2\n3 2\n5 4 7\n5 1\n5 3 4 5 6\n",
"output": "2\n1\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/COMS1501/problems/CM1503"
} | vfc_1098 | false | false | false | false | false |
apps | verifiable_code | 565 | Solve the following coding problem using the programming language python:
"If you didn't copy assignments during your engineering course, did you even do engineering?"
There are $Q$ students in Chef's class. Chef's teacher has given the students a simple assignment:
Write a function that takes as arguments an array $A... | ```python
def f(a,y,index,sorted_pos):
#print(a,y,index,sorted_pos)
n=len(a)
low=0
high=n-1
L,R=0,0
l,r=0,0
while(low<=high):
mid=(low+high)//2
#print(low,high,mid)
if(a[mid]== y):
break
elif(mid > index[y]):
high=mid-1
L+=1
#print("L")
if(a[mid] <y):
l+=1
#print(" l ")
else:
... | {
"language": "python",
"test_cases": [
{
"input": "1\n7 7\n3 1 6 7 2 5 4\n1\n2\n3\n4\n5\n6\n7\n",
"output": "0\n1\n1\n2\n1\n0\n0\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/FAKEBS"
} | vfc_1102 | false | false | false | false | true |
apps | verifiable_code | 566 | Solve the following coding problem using the programming language python:
Chef likes strings a lot but he likes palindromic strings more. Today, Chef has two strings A and B, each consisting of lower case alphabets.
Chef is eager to know whether it is possible to choose some non empty strings s1 and s2 where s1 is a ... | ```python
t=int(input())
for _ in range (t):
str1=input()
str2=input()
res='No'
for i in str1:
if i in str2:
res='Yes'
break
print(res)
``` | {
"language": "python",
"test_cases": [
{
"input": "3\nabc\nabc\na\nb\nabba\nbaab\n",
"output": "Yes\nNo\nYes\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/STRPALIN"
} | vfc_1106 | false | false | false | false | false |
apps | verifiable_code | 567 | Solve the following coding problem using the programming language python:
Chef's new hobby is painting, but he learned the fact that it's not easy to paint 2D pictures in a hard way, after wasting a lot of canvas paper, paint and of course time. From now on, he decided to paint 1D pictures only.
Chef's canvas is N mil... | ```python
# cook your dish here
import sys
import math
def main(arr):
for i in range(1,len(arr)-1):
if arr[i]==arr[i-1] and arr[i]==arr[i+1]:
return "Yes"
return "No"
test=int(input())
for _ in range(test):
b=int(input())
arr=list(map(int,input().split()))
print(main(arr))
... | {
"language": "python",
"test_cases": [
{
"input": "3\n4\n1 5 5 5\n4\n1 1 1 5\n3\n5 5 2\n\n",
"output": "Yes\nYes\nNo\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/MAKEART"
} | vfc_1110 | false | false | false | false | false |
apps | verifiable_code | 568 | Solve the following coding problem using the programming language python:
Kefaa has developed a novel decomposition of a tree. He claims that this decomposition solves many difficult problems related to trees. However, he doesn't know how to find it quickly, so he asks you to help him.
You are given a tree with $N$ ve... | ```python
test=int(input())
for t in range(test):
n= int(input())
adj=[[] for i in range(n+1)]
for _ in range(n-1):
a,b=list(map(int,input().split()))
adj[a].append(b)
adj[b].append(a)
#print(adj)
root=1
q,s=[root],set([root])
for x in q:
adj[x]= [p for p in adj[x] if p not in s]
q.extend(adj[x]... | {
"language": "python",
"test_cases": [
{
"input": "2\n4\n1 2\n1 3\n1 4\n7\n1 2\n2 3\n1 4\n4 5\n1 6\n6 7\n",
"output": "YES\n1 2 3 4\nNO\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/TREE3"
} | vfc_1114 | false | false | false | false | false |
apps | verifiable_code | 569 | Solve the following coding problem using the programming language python:
Sandu, a teacher in Chefland introduced his students to a new sequence i.e.
0,1,0,1,2,0,1,2,3,0,1,2,3,4........
The Sequence starts from 0 and increases by one till $i$(initially i equals to 1), then repeat itself with $i$ changed to $i+1$
Stude... | ```python
from math import sqrt
for _ in range(int(input())):
n = int(input())
x = int(sqrt(2 * n))
while x * (x+1) // 2 <= n:
x += 1
while x * (x+1) // 2 > n:
x -= 1
n -= x * (x+1) // 2
print(n)
``` | {
"language": "python",
"test_cases": [
{
"input": "5\n8\n9\n20\n32\n109\n",
"output": "2\n3\n5\n4\n4\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/ENCD2020/problems/ECAPR203"
} | vfc_1118 | false | false | false | false | false |
apps | verifiable_code | 570 | Solve the following coding problem using the programming language python:
Ayu loves distinct letter sequences ,a distinct letter sequence is defined by a sequence of small case english alphabets such that no character appears more then once.
But however there are two phrases that she doesn't like these phrases are "ka... | ```python
# cook your dish here
from collections import deque, defaultdict
from math import sqrt, ceil,factorial
import sys
import copy
def get_array(): return list(map(int, sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.... | {
"language": "python",
"test_cases": [
{
"input": "2\nkarp\nabcd\n",
"output": "22\n24\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/INDC2021/problems/AYUKAR"
} | vfc_1122 | false | false | false | false | false |
apps | verifiable_code | 571 | Solve the following coding problem using the programming language python:
The chef has a recipe he wishes to use for his guests,
but the recipe will make far more food than he can serve to the guests.
The chef therefore would like to make a reduced version of the recipe which has the same ratios of ingredients, but ma... | ```python
#! /usr/bin/env python
from sys import stdin
from functools import reduce
def gcd(a,b):
while b!=0:
a,b=b,a%b
return a
def gcdl(l):
return reduce(gcd, l[1:],l[0])
def __starting_point():
T=int(stdin.readline())
for case in range(T):
numbers=list(map(int, stdin.readline().split()[1:]))
g=gcdl(n... | {
"language": "python",
"test_cases": [
{
"input": "3\n2 4 4\n3 2 3 4\n4 3 15 9 6\n\n",
"output": "1 1\n2 3 4\n1 5 3 2\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/COOK04/problems/RECIPE"
} | vfc_1126 | false | false | false | false | false |
apps | verifiable_code | 572 | Solve the following coding problem using the programming language python:
Today is Chef's birthday. His mom has surprised him with truly fruity gifts: 2 fruit baskets. The first basket contains N apples, and the second one contains M oranges. Chef likes apples and oranges very much but he likes them equally, and there... | ```python
for _ in range(int(input())):
a,o,g=map(int,input().split())
while g>0:
if a<o:
a+=1
g-=1
elif o<a:
o+=1
g-=1
else:
break
print(abs(a-o))
``` | {
"language": "python",
"test_cases": [
{
"input": "3\n3 4 1\n5 2 1\n3 4 3\n",
"output": "0\n2\n0\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/FRUITS"
} | vfc_1130 | false | false | false | false | false |
apps | verifiable_code | 573 | Solve the following coding problem using the programming language python:
After acquiring an extraordinary amount of knowledge through programming contests, Malvika decided to harness her expertise to train the next generation of Indian programmers. So, she decided to hold a programming camp. In the camp, she held a d... | ```python
for _ in range(int(input())):
n,m=map(int, input().split())
if n==1:
print(0)
elif n==2:
print(m)
else:
print(m*2+n-3)
``` | {
"language": "python",
"test_cases": [
{
"input": "2\n2 1\n3 2\n",
"output": "1\n4\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/CHN05"
} | vfc_1134 | false | false | false | false | false |
apps | verifiable_code | 574 | Solve the following coding problem using the programming language python:
Find out the maximum sub-array of non negative numbers from an array.
The sub-array should be continuous. That is, a sub-array created by choosing the second and fourth element and skipping the third element is invalid.
Maximum sub-array is d... | ```python
for t in range(int(input())):
n=int(input())
a=list(map(int,input().split()))
s=0
l=[]
for i in range(n):
if (a[i]<0):
e=i
ss=sum(a[s:e])
l.append((ss,e-s,n-s))
s=i+1
e=n
ss=sum(a[s:e])
l.append((ss,e-s,n-s))
x=max(l)
s=n-x[2]
e=x[1]+s
for i in range(s,e):
print(a[i], end=' ')
pri... | {
"language": "python",
"test_cases": [
{
"input": "1\n6\n1 2 5 -7 2 3\n",
"output": "1 2 5\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/CDBU2015/problems/CDBSTR06"
} | vfc_1138 | false | false | false | false | false |
apps | verifiable_code | 575 | Solve the following coding problem using the programming language python:
Chef found a strange string yesterday - a string of signs s, where each sign is either a '<', '=' or a '>'. Let N be the length of this string. Chef wants to insert N + 1 positive integers into this sequence and make it valid. A valid sequence i... | ```python
for _ in range(int(input())):
st=input().replace("=","")
if not len(st):print(1)
else:
cu=mx=1
for j in range(1,len(st)):
if st[j]==st[j-1]:cu+=1
else:mx=max(mx,cu);cu=1
print(max(mx+1,cu+1))
``` | {
"language": "python",
"test_cases": [
{
"input": "4\n<<<\n<><\n<=>\n<=<\n",
"output": "4\n2\n2\n3\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/CHEFSIGN"
} | vfc_1142 | false | false | false | false | false |
apps | verifiable_code | 576 | Solve the following coding problem using the programming language python:
You came across this story while reading a book. Long a ago when the modern entertainment systems did not exist people used to go to watch plays in theaters, where people would perform live in front of an audience. There was a beautiful actress ... | ```python
for _ in range(int(input())):
S = input()
n = len(S)
a = n - S.count('a')
print(2 ** n - 2 ** a)
``` | {
"language": "python",
"test_cases": [
{
"input": "2\nabc\naba\n",
"output": "4\n6\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/CFW32020/problems/OMGO"
} | vfc_1146 | false | false | false | false | true |
apps | verifiable_code | 577 | Solve the following coding problem using the programming language python:
Not everyone probably knows that Chef has younder brother Jeff. Currently Jeff learns to read.
He knows some subset of the letter of Latin alphabet. In order to help Jeff to study, Chef gave him a book with the text consisting of N words. Jeff c... | ```python
knows=input()
n=eval(input())
while n!=0:
n=n-1
word=input()
for x in word:
ctr=0
for y in knows:
if x==y:ctr=ctr+1;break
if ctr==0:print('No');break
else: print('Yes')
``` | {
"language": "python",
"test_cases": [
{
"input": "act\n2\ncat\ndog\n",
"output": "Yes\nNo\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/LTIME39/problems/ALPHABET"
} | vfc_1150 | false | false | false | false | false |
apps | verifiable_code | 578 | Solve the following coding problem using the programming language python:
Chef has a calculator which has two screens and two buttons. Initially, each screen shows the number zero. Pressing the first button increments the number on the first screen by 1, and each click of the first button consumes 1 unit of energy.
Pr... | ```python
# cook your dish here
for i in range(int(input())):
n,b=map(int,input().split())
ans=round(n/(2*b))*(n-b*round((n/(2*b))));
print(ans)
``` | {
"language": "python",
"test_cases": [
{
"input": "3\n10 2\n8 5\n6 1\n",
"output": "12\n3\n9\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/CALC"
} | vfc_1154 | false | false | false | false | false |
apps | verifiable_code | 579 | Solve the following coding problem using the programming language python:
Chef has a circular sequence $A$ of $N$ non-negative integers $A_1, A_2, \ldots, A_N$ where $A_i$ and $A_{i+1}$ are considered adjacent, and elements $A_1$ and $A_N$ are considered adjacent.
An operation on position $p$ in array $A$ is defined a... | ```python
t=int(input())
def check():
pref = [0]*n
pref[0]=a[0]
suff = [0]*n
suff[-1]=a[-1]
for i in range (1,n):
pref[i] = pref[i-1]|a[i]
suff[n-i-1] = suff[n-i]|a[n-i-1]
if suff[1]==k:
return 0
elif pref[n-2]==k:
return n-1
else:
for i in range (... | {
"language": "python",
"test_cases": [
{
"input": "5\n3 6\n2 1 6\n3 6\n2 1 5\n3 7\n2 4 6\n3 7\n1 2 4\n3 7\n1 2 6\n",
"output": "2 1 3\n-1\n-1\n-1\n2 3 1\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/RECNDORO"
} | vfc_1158 | false | false | false | false | false |
apps | verifiable_code | 580 | 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(odd) to form a new pattern. Help the chef to code this pattern problem.
-----Input:-----
- First-line will contain $T$, the number of tes... | ```python
from sys import stdin, stdout
from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque
from heapq import merge, heapify, heappop, heappush, nsmallest
from bisect import bisect_left as bl, bisect_right as br, bisect
mod = pow(10, 9) + 7
mod2 = 99824435... | {
"language": "python",
"test_cases": [
{
"input": "4\n1\n3\n5\n7\n",
"output": "1\n111\n111\n111\n11111\n11 11\n1 1 1\n11 11\n11111\n1111111\n11 11\n1 1 1 1\n1 1 1\n1 1 1 1\n11 11\n1111111\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/PTRN2021/problems/ITGUY54"
} | vfc_1162 | false | false | false | false | true |
apps | verifiable_code | 581 | Solve the following coding problem using the programming language python:
Humpy, the little elephant, has his birthday coming up. He invited all his cousins but doesn’t know how many of them are really coming as some of them are having exams coming up. He will only get to know how many of them are coming on the day of... | ```python
# your code goes here
from sys import stdin, stdout
n = int(stdin.readline())
while n:
n -= 1
k, l, e = map(int, stdin.readline().strip().split(' '))
a = map(int, stdin.readline().strip().split(' '))
x = float(l) / float(e + sum(a))
if x - int(x):
stdout.write("NO\n")
else:
stdout.write("YES\n")
``` | {
"language": "python",
"test_cases": [
{
"input": "2\n4 10 2\n2 2 3 1\n4 12 3\n6 5 7 3\n",
"output": "YES\nNO\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/IC32016/problems/HBB"
} | vfc_1166 | false | false | false | false | false |
apps | verifiable_code | 582 | Solve the following coding problem using the programming language python:
You may have tried your level best to help Chef but Dr Doof has managed to come up with his masterplan in the meantime. Sadly, you have to help Chef once again. Dr Doof has designed a parenthesis-inator. It throws a stream of $N$ brackets at the... | ```python
import sys
import bisect as bi
import math
from collections import defaultdict as dd
input=sys.stdin.readline
##sys.setrecursionlimit(10**7)
def cin():
return list(map(int,sin().split()))
def ain():
return list(map(int,sin().split()))
def sin():
return input()
def inin():
return in... | {
"language": "python",
"test_cases": [
{
"input": "1\n)())((()\n3\n1 7 6\n",
"output": "3\n8\n-1\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/COLE2020/problems/CLBRKT"
} | vfc_1170 | false | false | false | false | false |
apps | verifiable_code | 583 | Solve the following coding problem using the programming language python:
Let's call a sequence good if the sum of all its elements is $0$.
You have a sequence of integers $A_1, A_2, \ldots, A_N$. You may perform any number of operations on this sequence (including zero). In one operation, you should choose a valid in... | ```python
n=int(input())
for i in range(n):
t=int(input())
m=list(map(int,input().split()))
p,q=0,0
if t==1:
if m[0]>=0:
print('YES')
else:
print('NO')
else:
for i in m:
if i<0:
q+=i
else:
p+=i
if p>=abs(q):
print('YES')
else:
print('NO')
``` | {
"language": "python",
"test_cases": [
{
"input": "2\n1\n-1\n2\n1 2\n",
"output": "NO\nYES\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/WATMELON"
} | vfc_1174 | false | false | false | false | false |
apps | verifiable_code | 584 | Solve the following coding problem using the programming language python:
Given a binary string $S$ consisting of only 1’s and 0’s where 1 represents a Square and 0 represents a Circle. The diameter of the circle and the side of the square must be any integer (obviously > 0) . You will have to perfectly inscribe (as s... | ```python
for z in range(int(input())):
s = input()
n = len(s)
i = 0
while i<n and s[i]=='1':
i+=1
if i==0:
print(0)
else:
k = 0
while i<n and s[i]=='0':
i+=1
k+=1
print(k)
``` | {
"language": "python",
"test_cases": [
{
"input": "3\n1110\n0010\n1001000\n",
"output": "1\n0\n2\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/CHIL2020/problems/BININSC"
} | vfc_1178 | false | false | false | false | false |
apps | verifiable_code | 585 | Solve the following coding problem using the programming language python:
You are an evil sorcerer at a round table with $N$ sorcerers (including yourself). You can cast $M$ spells which have distinct powers $p_1, p_2, \ldots, p_M$.
You may perform the following operation any number of times (possibly zero):
- Assign ... | ```python
import functools
def gcd(x,y):
if(y == 0):
return x
return gcd(y, x%y)
for _ in range(int(input())):
n, m= map(int, input().split())
p = list(map(int, input().split()))
ans = functools.reduce(lambda x,y: gcd(x, y), p)
if(ans <= n):
print(n-ans)
else:
f = [1]
for k in range(ans//2, 1, -1):... | {
"language": "python",
"test_cases": [
{
"input": "5\n4 1\n5\n6 2\n2 4\n1 4\n7 16 8 29\n1000000000 1\n998244353\n1 1\n20201220\n",
"output": "3\n4\n0\n1755647\n0\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://www.codechef.com/problems/CIRCHAOS"
} | vfc_1182 | false | false | false | false | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.