source stringclasses 4
values | task_type stringclasses 1
value | in_source_id stringlengths 0 138 | problem stringlengths 219 13.2k | gold_standard_solution stringlengths 0 413k | problem_id stringlengths 5 10 | metadata dict | verification_info dict |
|---|---|---|---|---|---|---|---|
taco | verifiable_code | https://codeforces.com/problemset/problem/743/B | Solve the following coding problem using the programming language python:
Chloe, the same as Vladik, is a competitive programmer. She didn't have any problems to get to the olympiad like Vladik, but she was confused by the task proposed on the olympiad.
Let's consider the following algorithm of generating a sequence ... | ```python
(n, k) = [int(x) for x in input().split()]
tmp = n + 1
lan = 2 ** (n + 1) - 1
while lan > 1:
if k <= lan // 2:
lan = lan // 2
tmp = tmp - 1
elif k >= lan // 2 + 2:
k = lan // 2 - lan + k
lan = lan // 2
tmp = tmp - 1
if k == lan // 2 + 1:
break
print(tmp)
``` | vfc_138264 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/743/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 2\n",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 8\n",
"output": "4",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 27\n",
... |
taco | verifiable_code | https://www.hackerrank.com/challenges/sherlock-and-permutations/problem | Solve the following coding problem using the programming language python:
Watson asks Sherlock:
Given a string S of N 0's and M 1's, how many unique permutations of this string start with 1?
Help Sherlock by printing the answer modulo (10^{9}+7).
Input Format
First line contains T, the number of test cases... | ```python
MOD = 1000000007
t = int(input())
def f(c0, c1):
c1 -= 1
res = 1
for i in range(c0 + 1, c0 + c1 + 1):
res = res * i // (i - c0)
return res % MOD
for _ in range(t):
(c0, c1) = map(int, input().split())
print(f(c0, c1))
``` | vfc_138268 | {
"difficulty": "medium_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.hackerrank.com/challenges/sherlock-and-permutations/problem",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n1 1\n2 3\n",
"output": "1\n6\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/quick-sort-on-linked-list/1 | Solve the following coding problem using the programming language python:
Sort the given Linked List using quicksort. which takes O(n^2) time in worst case and O(nLogn) in average and best cases, otherwise you may get TLE.
Input:
In this problem, method takes 1 argument: address of the head of the linked list. The fun... | ```python
class Node:
def __init__(self, data):
self.data = data
self.next = None
def quickSort(head):
if head is None or head.next is None:
return head
pivot = head
current = head.next
less_than_pivot = None
greater_than_pivot = None
while current is not None:
next_node = current.next
if current.dat... | vfc_138277 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/quick-sort-on-linked-list/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": "quickSort",
"input": "2\r\n\n3\r\n\n1 6 2\r\n\n4\r\n\n1 9 3 8",
"output": "1 2 6\r\n\n1 3 8 9",
"type": "function_call"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Several drivers had lined up for the Drag Racing Competition at the Tokyo Drift Street. Dom had organized the competition, but he was not available during all the races and hence he did not know their results. In the drag race match, 2 drivers r... | ```python
map = {}
details = []
nTestCases = int(input())
for i in range(0,(2**nTestCases)-1):
matches = input()
details.append(matches)
racer1,racer2 = ''.join(matches.split(" ")[0]),''.join(matches.split(" ")[1])
if racer1 in map:
if map[racer1] == "false":
map[racer1],map[racer2] = "false","false"
else:
... | vfc_138279 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "9\nznejwgwpok wohkjjwlwn\nuwdszgerob pxutblrgio\ntnvpozvuib rmkroequbu\nxozaulqdsc wneolwstpl\ntnvpozvuib evrtybebba\nrfsijiyzzn ehbrqxwqft\nrphpmhvjxw luohdaqoyr\nrsdfhgmges chjthfleee\nqrjdszcwxt abzorlrlsh\ntgszjlyyra cdvenegwyc... | |
taco | verifiable_code | https://codeforces.com/problemset/problem/818/F | Solve the following coding problem using the programming language python:
Ivan is developing his own computer game. Now he tries to create some levels for his game. But firstly for each level he needs to draw a graph representing the structure of the level.
Ivan decided that there should be exactly n_{i} vertices in ... | ```python
def newest_approach(n):
from math import floor, ceil, sqrt
quad_solv = sqrt(2 * n + 1 / 4) - 1 / 2
x = floor(quad_solv)
y = ceil(quad_solv)
xed = int(x * (x - 1) / 2 + n - x)
xbr = n - x
ybr = n - y
yed = 2 * ybr
if xed > yed:
print(xed)
else:
print(yed)
return
def main():
import sys
data = ... | vfc_138283 | {
"difficulty": "hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/818/F",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n3\n4\n6\n",
"output": "2\n3\n6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n",
"output": "0\n1\n2\n3\n4\n6\n7\n8\n10\n12\n",
"type": "s... |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/distance-from-the-source-bellman-ford-algorithm/1 | Solve the following coding problem using the programming language python:
Given a weighted, directed and connected graph of V vertices and E edges, Find the shortest distance of all the vertex's from the source vertex S.
Note: If the Graph contains a negative cycle then return an array consisting of only -1.
Example 1... | ```python
import math
class Solution:
def bellman_ford(self, V, edges, S):
dis = [100000000 for i in range(V)]
dis[S] = 0
for i in range(V - 1):
for (m, n, o) in edges:
if dis[m] != 100000000 and dis[m] + o < dis[n]:
dis[n] = dis[m] + o
for (m, n, o) in edges:
if dis[m] != 100000000 and dis[m]... | vfc_138287 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/distance-from-the-source-bellman-ford-algorithm/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "E = [[0,1,9]]\nS = 0",
"output": "0 9",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "E = [[0,1,5],[1,0,3],[1,2,-1],[2,0,1]]\nS = 2",
"output": "1 6 0",
"type": "stdin_stdout"
... |
taco | verifiable_code | https://codeforces.com/problemset/problem/281/D | Solve the following coding problem using the programming language python:
Bike loves looking for the second maximum element in the sequence. The second maximum element in the sequence of distinct numbers x1, x2, ..., xk (k > 1) is such maximum element xj, that the following inequality holds: <image>.
The lucky number... | ```python
def empty(l):
return len(l) == 0
def lucky_number(arr):
st = []
l = 0
for d in arr:
while not empty(st) and st[-1] < d:
l = max(l, st.pop() ^ d)
if not empty(st):
l = max(l, st[-1] ^ d)
st.append(d)
d = 0
if not empty(st):
d = st.pop()
while not empty(st):
l = max(l, d ^ st[-1])
d = ... | vfc_138288 | {
"difficulty": "medium_hard",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/281/D",
"time_limit": "1.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10\n4547989 39261040 94929326 38131456 26174500 7152864 71295827 77784626 89898294 68006331\n",
"output": "134189790",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/HMAPPY2 | Solve the following coding problem using the programming language python:
Appy and Chef are participating in a contest. There are $N$ problems in this contest; each problem has a unique problem code between $1$ and $N$ inclusive. Appy and Chef decided to split the problems to solve between them ― Appy should solve the... | ```python
import math
for i in range(int(input())):
(z, a, b, k) = list(map(int, input().split()))
n = 0
x1 = z // a
x2 = z // b
x3 = a * b // math.gcd(a, b)
p1 = x1 - z // x3
p2 = x2 - z // x3
if p1 + p2 >= k:
print('Win')
else:
print('Lose')
``` | vfc_138292 | {
"difficulty": "easy",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/HMAPPY2",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n6 2 3 3\n",
"output": "Win\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1669/C | Solve the following coding problem using the programming language python:
Given an array $a=[a_1,a_2,\dots,a_n]$ of $n$ positive integers, you can do operations of two types on it:
Add $1$ to every element with an odd index. In other words change the array as follows: $a_1 := a_1 +1, a_3 := a_3 + 1, a_5 := a_5+1, \do... | ```python
t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
poss = True
par = a[0] % 2
for i in range(2, n, 2):
pari = a[i] % 2
if par != pari:
poss = False
par = a[1] % 2
for i in range(1, n, 2):
pari = a[i] % 2
if par != pari:
poss = False
if poss:
print(... | vfc_138296 | {
"difficulty": "easy",
"memory_limit": "256 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1669/C",
"time_limit": "1 second"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n3\n1 2 1\n4\n2 2 2 3\n4\n2 2 2 2\n5\n1000 1 1000 1 1000\n",
"output": "YES\nNO\nYES\nYES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n2\n514 514\n",
"output": "YES\n",
... |
taco | verifiable_code | https://www.codechef.com/ZCOPRAC/problems/ZCO17001 | Solve the following coding problem using the programming language python:
In this problem you are given a sequence of $N$ positive integers $S[1],S[2],\dots,S[N]$. In addition you are given an integer $T$, and your aim is to find the number of quadruples $(i,j,k,l)$, such that $1 \le i < j < k < l \le N$, and $S[i] +... | ```python
from itertools import combinations
a = list(map(int, input().split()))
n = a[0]
t = a[1]
q = list(combinations(a[2:], 4))
total = 0
for i in q:
if sum(i) == t:
total += 1
print(total)
``` | vfc_138300 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/ZCOPRAC/problems/ZCO17001",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6 20 3 1 1 2 5 10\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Wind Corridor is a covered passageway where strong wind is always blowing. It is a long corridor of width W, and there are several pillars in it. Each pillar is a right prism and its face is a polygon (not necessarily convex).
In this problem, ... | ```python
def solve():
from itertools import combinations
from heapq import heappush, heappop
def dot(c1, c2):
return c1.real * c2.real + c1.imag * c2.imag
def cross(c1, c2):
return c1.real * c2.imag - c1.imag * c2.real
def d_sp(sp1, sp2, p):
a = sp2 - sp1
b = p - sp1
if dot(a, b) < 0:
return abs(b... | vfc_138304 | {
"difficulty": "unknown_difficulty",
"memory_limit": "134.217728 megabytes",
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "8.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 2\n4\n1 1\n1 2\n2 4\n2 1\n4\n3 3\n3 4\n4 4\n4 3\n0 0",
"output": "3.00000000000000000000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 2\n4\n1 1\n2 2\n2 4\n2 1\n4\n3 3\n3 4\n0 4\n4 3... | |
taco | verifiable_code | https://www.codechef.com/problems/SNELECT | 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('... | vfc_138308 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/SNELECT",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\nsm\nssm\nsms\nssmmmssss\n",
"output": "mongooses\ntie\ntie\nsnakes\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/count-pairs-in-array-divisible-by-k/1 | Solve the following coding problem using the programming language python:
Given an array A[] and positive integer K, the task is to count total number of pairs in the array whose sum is divisible by K.
Example 1:
Input :
A[] = {2, 2, 1, 7, 5, 3}, K = 4
Output : 5
Explanation :
There are five pairs possible whose sum... | ```python
class Solution:
def countKdivPairs(self, arr, n, k):
ax = [0] * k
for i in arr:
ax[i % k] += 1
res = 0
for i in range(k // 2 + 1):
if 2 * i == k or i == 0:
res += ax[i] * (ax[i] - 1) // 2
else:
res += ax[i] * ax[k - i]
return res
``` | vfc_138312 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/count-pairs-in-array-divisible-by-k/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "A[] = {2, 2, 1, 7, 5, 3}, K = 4",
"output": "5",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "A[] = {5, 9, 36, 74, 52, 31, 42}, K = 3",
"output": "7",
"type": "stdin_stdout"
... |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Times Square in the capital city of NY has a rectangular shape with the size n × m meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size a × a.
... | ```python
import math
n,m,a = list(map(eval, input().split()))
lcount = 0
rcount = 0
while(n>0):
n-=a
lcount+=1
while(m>0):
m-=a
rcount+=1
print(lcount*rcount)
``` | vfc_138313 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1001 1000 10",
"output": "3015",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "222 332 5",
"output": "10100",
"type": "stdin_stdout"
}
]
} | |
taco | verifiable_code | https://www.codechef.com/AARA2018/problems/ARMBH1 | Solve the following coding problem using the programming language python:
Richik$Richik$ has just completed his engineering and has got a job in one of the firms at Sabrina$Sabrina$ which is ranked among the top seven islands in the world in terms of the pay scale.
Since Richik$Richik$ has to travel a lot to reach th... | ```python
t = int(input())
for i in range(t):
(x, n) = [int(g) for g in input().split()]
sal = 0
day = x
while day < n:
sal = sal + day
day += x
print(sal)
``` | vfc_138318 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/AARA2018/problems/ARMBH1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n3 10\n",
"output": "18\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/EMAILREM | Solve the following coding problem using the programming language python:
MoEngage helps the Chef send email reminders about rated contests to the participants.
There are a total of N participants on Chef’s platform, and U of them have told Chef not to send emails to them.
If so, how many participants should MoEngag... | ```python
(n, u) = map(int, input().split())
print(n - u)
``` | vfc_138322 | {
"difficulty": "easy",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/EMAILREM",
"time_limit": "0.5 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "100 7",
"output": "93",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4456 342",
"output": "4114",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.hackerrank.com/challenges/and-product/problem | Solve the following coding problem using the programming language python:
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\... | ```python
T = int(input())
for _ in range(T):
(A, B) = (int(_) for _ in input().split())
(i, C) = (-1, A ^ B)
while C > 0:
C >>= 1
i += 1
print(A & 2 ** 32 - 2 ** i)
``` | vfc_138326 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.hackerrank.com/challenges/and-product/problem",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n12 15\n2 3\n8 13\n",
"output": "12\n2\n8\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n17 23\n11 15\n",
"output": "16\n8\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/CHEFYODA | Solve the following coding problem using the programming language python:
Chef has arrived in Dagobah to meet with Yoda to study cooking. Yoda is a very busy cook and he doesn't want to spend time with losers. So he challenges the Chef to a series of games, and agrees to teach the Chef if Chef can win at least P of th... | ```python
import math
dp = []
dp.append(0)
for i in range(1, 1000005):
dp.append(math.log(i) + dp[i - 1])
t = int(input())
for i in range(t):
(n, m, p, k) = input().split()
n = int(n)
m = int(m)
p = int(p)
k = int(k)
if p == 0 or (n % 2 == 0 and m % 2 == 0):
ans = 1.0
print(ans)
elif n % 2 == 1 and m % 2 ==... | vfc_138330 | {
"difficulty": "hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/CHEFYODA",
"time_limit": "1.5 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n2 3 2 3\n2 2 5 5\n",
"output": "0.500000\n1.000000\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1281/A | Solve the following coding problem using the programming language python:
We just discovered a new data structure in our research group: a suffix three!
It's very useful for natural language processing. Given three languages and three suffixes, a suffix three can determine which language a sentence is written in.
It... | ```python
import sys
t = int(input())
for i in range(t):
a = sys.stdin.readline().strip()
if a[-2:] == 'po':
print('FILIPINO')
elif a[-4:] in ['desu', 'masu']:
print('JAPANESE')
else:
print('KOREAN')
``` | vfc_138335 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1281/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "8\nkamusta_po\ngenki_desu\nohayou_gozaimasu\nannyeong_hashimnida\nhajime_no_ippo\nbensamu_no_sentou_houhou_ga_okama_kenpo\nang_halaman_doon_ay_sarisari_singkamasu\nsi_roy_mustang_ay_namamasu\n",
"output": "FILIPINO\nJAPANESE\... |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Dark with his love for the prime numbers wanted to do some arithmetic so he decided to do some additions.
He wants to generate all prime numbers between two given numbers and add them up and decide whether that addition of numbers is a prime nu... | ```python
import bisect,math
l =[]
def primes_upto(limit):
is_prime = [False] * 2 + [True] * (limit - 1)
for n in range(int(limit**0.5 + 1.5)): # stop at ``sqrt(limit)``
if is_prime[n]:
for i in range(n*n, limit+1, n):
is_prime[i] = False
return [i for i, prime in enumerate(is_prime) if prime]
def ipri... | vfc_138339 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10\n1 1000000\n1 1000000\n1 1000000\n1 1000000\n1 1000000\n1 1000000\n1 1000000\n1 1000000\n1 1000000\n1 1000000",
"output": "YES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES",
"type": "stdin_stdout"
},
{
... | |
taco | verifiable_code | https://codeforces.com/problemset/problem/725/C | Solve the following coding problem using the programming language python:
Let’s define a grid to be a set of tiles with 2 rows and 13 columns. Each tile has an English letter written in it. The letters don't have to be unique: there might be two or more tiles with the same letter written on them. Here is an example of... | ```python
3
s = input()
n = len(s)
(a, b) = (0, 0)
d = dict()
for i in range(len(s)):
if s[i] in d:
a = d[s[i]]
b = i
d[s[i]] = i
if a == b - 1:
print('Impossible')
else:
ans = [[' '] * 13 for i in range(2)]
if (b - a) % 2 == 1:
for i in range((b - a) // 2):
ans[0][-(b - a) // 2 + i + 1] = s[a + i + 1]
... | vfc_138347 | {
"difficulty": "medium_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/725/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "ABCDEFGHIJKLMNOPQRSGTUVWXYZ\n",
"output": "YXWVUTGHIJKLM\nZABCDEFSRQPON\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "BUVTYZFQSNRIWOXXGJLKACPEMDH\n",
"output": "Impossible\n",
... |
taco | verifiable_code | https://codeforces.com/problemset/problem/908/B | Solve the following coding problem using the programming language python:
Bob programmed a robot to navigate through a 2d maze.
The maze has some obstacles. Empty cells are denoted by the character '.', where obstacles are denoted by '#'.
There is a single robot in the maze. Its start position is denoted with the ch... | ```python
from itertools import permutations
dirs = ((1, 0), (-1, 0), (0, 1), (0, -1))
per = permutations(dirs)
(r, c) = map(int, input().split())
grid = [input() for _ in range(r)]
path = input()
pos_start = [i for (i, x) in enumerate(grid) if 'S' in x][0]
start = (pos_start, grid[pos_start].index('S'))
pos_end = [i f... | vfc_138353 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/908/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 6\n.....#\nS....#\n.#....\n.#....\n...E..\n333300012\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 6\n......\n......\n..SE..\n......\n......\n......\n012321232123021... |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Roman loved diamonds. Monica decided to give him a beautiful gift on Valentine's Day. Her idea of diamonds was different though. She lit up all the windows of her rectangular building with N floors and M windows on each floor, with 2 shapes - / ... | ```python
'''
# Read input from stdin and provide input before running code
name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
#print 'Hello World!'
test_cases=input()
#print test_cases
for _ in range(int(test_cases)):
m,n=list(map(int,input().split(" ")))
#print m,n
diamonds=[]
for i in range(m... | vfc_138357 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n10 5\n/ / \\ / \\\n\\ / / / \\\n/ / / / \\\n/ \\ / / /\n\\ / \\ \\ /\n/ \\ / \\ \\\n\\ \\ / \\ /\n/ \\ \\ \\ /\n/ / \\ / \\\n\\ / / / /\n9 3\n/ \\ /\n/ \\ /\n\\ / /\n/ \\ /\n\\ / \\\n\\ \\ /\n/ / \\\n/ \\ \\\n/ / \\\n9 8\n\\ \\ ... | |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/min-distance-between-two-given-nodes-of-a-binary-tree/1 | Solve the following coding problem using the programming language python:
Given a binary tree and two node values your task is to find the minimum distance between them.
The given two nodes are guaranteed to be in the binary tree and nodes are numbered from 1 to N.
Please Note that a and b are not always leaf node.
Ex... | ```python
class Solution:
def findDist(self, root, a, b):
def LCA(root, path, tar):
if root == None:
return
if root.data == tar:
self.ans.append(path + [root.data])
LCA(root.left, path + [root.data], tar)
LCA(root.right, path + [root.data], tar)
self.ans = []
LCA(root, [], a)
ans1 = self.... | vfc_138361 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/min-distance-between-two-given-nodes-of-a-binary-tree/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\r\n / \\\r\n 2 3\r\na = 2, b = 3",
"output": "2",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/TADELIVE | Solve the following coding problem using the programming language python:
Read problems statements in Mandarin Chinese and Russian.
Andy and Bob are the only two delivery men of Pizza-chef store. Today, the store received N orders.
It's known that the amount of tips may be different when handled by different deliv... | ```python
(n, x, y) = [int(j) for j in input().split()]
a = [int(j) for j in input().split()]
b = [int(j) for j in input().split()]
c = [(abs(i - j), i, j) for (i, j) in zip(a, b)]
c.sort(reverse=1)
ans = 0
for (i, j, k) in c:
if x > 0 and y > 0:
if j < k:
ans += k
y -= 1
else:
ans += j
x -= 1
elif x ... | vfc_138362 | {
"difficulty": "medium_hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/TADELIVE",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 3 3\n1 2 3 4 5\n5 4 3 2 1",
"output": "21",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 3 3\n1 2 3 4 5\n5 4 3 0 1",
"output": "21\n",
"type": "stdin_stdout"
},
{
... |
taco | verifiable_code | Solve the following coding problem using the programming language python:
You are given three numbers. Is there a way to replace variables A, B and C with these numbers so the equality A + B = C is correct?
Input:
There are three numbers X1, X2 and X3 (1 ≤ Xi ≤ 10^100), each on a separate line of input.
Output:
Ou... | ```python
a=int(input())
b=int(input())
c=int(input())
l=[a,b,c]
def ckh(x,y,z):
flag=0
if((x+y)==z):
flag=1
return(flag)
p=1
while(p):
if(l[0]==2*l[2] or l[0]==2*l[1] or l[2]==2*l[1] or l[2]==2*l[0] or l[1]==2*l[2] or l[1]==2*l[0] ):
print('YES')
p=0
else:
if(ckh(l[0],l[1],l[2])):
print('YES')
p=0
... | vfc_138367 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1000000000000000000000000000000000000000000000000000000000000000000000000000\n2000000000000000000000000000000000000000000000000000000000000000000000000000\n400000000000000000000000000000000000000000000000000000000000000000000000000... | |
taco | verifiable_code | Solve the following coding problem using the programming language python:
C: Mod! Mod!
story
That's right! I'm looking for eyewitness testimony! A phantom thief has appeared in Aizu! Everyone's horse stick was stolen! Who is the culprit! ?? Unravel! Mod! Mod!
Problem statement
"Eyes" ... it's a miracle bud that sw... | ```python
n = int(input())
a = list(map(int, input().split()))
c = [0] * 3
for i in a:
c[i % 3] += 1
if c[1] | c[2] == 0:
ans = 1
else:
(ans, n) = (c[0], n - c[0])
if n <= 3:
ans += n
else:
t = max(-3, min(3, c[1] - c[2]))
if t > 0:
ans += 2 * c[2] + t
else:
ans += 2 * c[1] - t
print(ans)
``` | vfc_138373 | {
"difficulty": "unknown_difficulty",
"memory_limit": "268.435456 megabytes",
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n2 5 2 6 2 1",
"output": "6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n1 25 1 10 1 3",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... | |
taco | verifiable_code | https://www.hackerrank.com/challenges/helix/problem | Solve the following coding problem using the programming language python:
Natural numbers from 1 to N have been placed in an increasing order over some helix ( a circular structure ). When the helix starts rotating, it is easy to find out
The position of a given number
The number located at a given position.
The h... | ```python
from collections import defaultdict
from dataclasses import dataclass
from random import random
def print_tree(tree, pfx=''):
if tree is None:
return
print_tree(tree.left, pfx + ' ')
print(f'{pfx}{tree.value}: {count(tree)}')
print_tree(tree.right, pfx + ' ')
@dataclass
class Node:
value: int
count:... | vfc_138378 | {
"difficulty": "hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.hackerrank.com/challenges/helix/problem",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 10\n1 1 3\n2 3\n3 3\n1 3 5\n1 2 4\n3 1\n3 5\n2 4\n1 5 5\n2 2\n",
"output": "element 3 is at position 1\nelement at position 3 is 1\nelement at position 1 is 3\nelement at position 5 is 1\nelement 4 is at position 2\nelement... |
taco | verifiable_code | https://codeforces.com/problemset/problem/394/B | Solve the following coding problem using the programming language python:
Teacher thinks that we make a lot of progress. Now we are even allowed to use decimal notation instead of counting sticks. After the test the teacher promised to show us a "very beautiful number". But the problem is, he's left his paper with the... | ```python
(p, k) = map(int, input().split())
u = 10 * k - 1
v = pow(10, p - 1, u) - k
for y in range(k, 10):
if y * v % u == 0:
q = d = 9 * y
while q % u:
q = 10 * q + d
q = str(q // u)
print(q * (p // len(q)))
break
else:
print('Impossible')
``` | vfc_138383 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/394/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6 5\n",
"output": "142857",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 2\n",
"output": "Impossible\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"inpu... |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Create a program that inputs the vertex information of two polygons inscribed in one circle and outputs the magnitude relationship of their areas.
Assume that each vertex of the X-side is numbered counterclockwise from 1 to X (the figure shows ... | ```python
import math
M = 0.008726646259971648
EPS = 1e-08
a = [0] * 2
s = [0.0] * 2
while True:
eof = False
for i in range(2):
s[i] = a[i] = 0
n = int(input())
if n == 0:
eof = True
break
for j in range(1, n):
v = int(input())
a[i] += v
s[i] += math.sin(M * v) * math.cos(M * v)
v = 360 - a[i... | vfc_138387 | {
"difficulty": "unknown_difficulty",
"memory_limit": "134.217728 megabytes",
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "1.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n30\n125\n75\n4\n30\n125\n75\n5\n30\n125\n75\n65\n4\n30\n125\n75\n4\n30\n125\n75\n6\n30\n50\n50\n29\n75\n0",
"output": "0\n1\n2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n30\n125... | |
taco | verifiable_code | Solve the following coding problem using the programming language python:
problem
Create a program that counts the number of consecutive JOI or IOI characters in a given character string. The character string consists only of uppercase letters of the alphabet. For example, the character string "JOIOIOI" in the figure... | ```python
while True:
try:
j = input()
p = 0
q = 0
for i in range(len(j) - 2):
if j[i:i + 3] == 'JOI':
p += 1
elif j[i:i + 3] == 'IOI':
q += 1
else:
pass
print(p)
print(q)
except EOFError:
break
``` | vfc_138391 | {
"difficulty": "unknown_difficulty",
"memory_limit": "134.217728 megabytes",
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "1.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "JOIJOI\nJOIOIOIOI\nJOIOIOIJXNXNIOJIOIOJ",
"output": "2\n0\n1\n3\n1\n3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "eonN",
"output": "0\n0\n",
"type": "stdin_stdout"
},
... | |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/cd4b48615a30999443b728a72de6cd5addbd0501/1 | Solve the following coding problem using the programming language python:
IPL 2021 knockouts are over, teams MI, CSK, DC, and RCB are qualified for the semis.
Today is matchday 6 and it is between Delhi Capitals and Royal Challengers Banglore. Glenn Maxwell of RCB playing flawlessly. Rishabh Pant, the new captain of ... | ```python
class Solution:
def fillarray(self, s, a):
a[0] = 0
for i in range(1, len(s)):
series = a[i - 1]
while series:
if s[series] == s[i]:
a[i] = series + 1
break
series = a[series - 1]
if series == 0:
a[i] = int(s[i] == s[0])
return a
def compress(self, s):
a = [0] * len(... | vfc_138401 | {
"difficulty": "medium_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/cd4b48615a30999443b728a72de6cd5addbd0501/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "s = \"ababcababcd\"",
"output": "ab*c*d",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "s = \"zzzzzzz\"",
"output": "z*z*z",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/big-numbers-series1913/1 | Solve the following coding problem using the programming language python:
Given a series of numbers 0 1 4 18 96 600 4320 …., and series starting from zeroth term. Given n, find the nth value of the series.
Example 1:
Input: n = 4
Output: 96
Example 2:
Input: n = 2
Output: 4
Your Task:
You don't need to read ... | ```python
class Solution:
def solve(self, n):
ans = 1
for i in range(1, n + 1):
ans = ans * i
return ans
def NthTerm(self, n):
a = self.solve(n)
return n * a % (10 ** 9 + 7)
``` | vfc_138402 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/big-numbers-series1913/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "n = 4",
"output": "96",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "n = 2",
"output": "4",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1463/B | Solve the following coding problem using the programming language python:
You are given an array $[a_1, a_2, \dots, a_n]$ such that $1 \le a_i \le 10^9$. Let $S$ be the sum of all elements of the array $a$.
Let's call an array $b$ of $n$ integers beautiful if:
$1 \le b_i \le 10^9$ for each $i$ from $1$ to $n$;
for ... | ```python
def func(n, arr):
s = sum(arr)
odds = [1 if i & 1 else arr[i] for i in range(n)]
if sum(map(lambda i: abs(odds[i] - arr[i]), range(n))) << 1 <= s:
return odds
return [1 if i & 1 == 0 else arr[i] for i in range(n)]
for _ in range(int(input())):
print(*func(int(input()), list(map(int, input().split()))))... | vfc_138403 | {
"difficulty": "medium",
"memory_limit": "256 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1463/B",
"time_limit": "2 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n5\n1 2 3 4 5\n2\n4 6\n2\n1 1000000000\n6\n3 4 8 1 2 3\n",
"output": "1 2 1 4 1\n1 6\n1 1000000000\n1 4 1 1 1 3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n2\n1 1\n",
"outpu... |
taco | verifiable_code | https://codeforces.com/problemset/problem/950/C | Solve the following coding problem using the programming language python:
Oleg writes down the history of the days he lived. For each day he decides if it was good or bad. Oleg calls a non-empty sequence of days a zebra, if it starts with a bad day, ends with a bad day, and good and bad days are alternating in it. Let... | ```python
s = input()
(arr, zero, one) = ([], [], [])
for i in range(len(s)):
if s[i] == '0':
if one:
idx = one.pop()
arr[idx].append(i + 1)
zero.append(idx)
else:
zero.append(len(arr))
arr.append([i + 1])
else:
if not zero:
break
idx = zero.pop()
one.append(idx)
arr[idx].append(i + 1)
i... | vfc_138408 | {
"difficulty": "medium_hard",
"memory_limit": "512.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/950/C",
"time_limit": "1.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "0010101100\n",
"output": "2\n3 1 8 9\n7 2 3 4 5 6 7 10\n",
"type": "stdin_stdout"
},
{
"fn_nam... |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/the-celebrity-problem/1 | Solve the following coding problem using the programming language python:
A celebrity is a person who is known to all but does not know anyone at a party. If you go to a party of N people, find if there is a celebrity in the party or not.
A square NxN matrix M[][] is used to represent people at the party such that if ... | ```python
class Solution:
def celebrity(self, M, n):
i = 0
j = n - 1
while i < j:
if M[i][j] == 1:
i += 1
else:
j -= 1
count = 0
count2 = 0
for j in range(n):
if i != j:
count += M[j][i]
count2 += M[i][j]
if count2 == 0 and count == n - 1:
return i
return -1
``` | vfc_138412 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/the-celebrity-problem/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N = 3\r\nM[][] = {{0 1 0},\r\n {0 0 0}, \r\n {0 1 0}}",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "N = 2\r\nM[][] = {{0 1},\r\n {1 0}}",
"outp... |
taco | verifiable_code | https://codeforces.com/problemset/problem/778/B | Solve the following coding problem using the programming language python:
Bob recently read about bitwise operations used in computers: AND, OR and XOR. He have studied their properties and invented a new game.
Initially, Bob chooses integer m, bit depth of the game, which means that all numbers in the game will cons... | ```python
def OP(i, j, op):
if op == 'AND':
return i & j
if op == 'OR':
return i | j
if op == 'XOR':
return i ^ j
return 0
def totbit(i, test):
ans = 0
for j in range(0, len(ops)):
a = ops[j][0]
b = ops[j][1]
op = ops[j][2]
if a == '?':
x = test
elif a in M:
x = int(M[a][i])
else:
x = ... | vfc_138413 | {
"difficulty": "medium_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/778/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 3\na := 101\nb := 011\nc := ? XOR b\n",
"output": "011\n100\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 1\na := 1\nbb := 0\ncx := ? OR a\nd := ? XOR ?\ne := d AND bb\n",
"out... |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/product-is-even-or-odd3020/1 | Solve the following coding problem using the programming language python:
You are given two long numbers N1 and N2 in a string. You need to find out if the product of these numbers generate an even number or an odd number, If it is an even number print 1 else print 0.
Example 1:
Input:
N1 = "12"
N2 = "15"
Output: 1
E... | ```python
class Solution:
def EvenOdd(self, n1, n2):
a = int(n1)
b = int(n2)
if a * b % 2 == 0:
return 1
else:
return 0
``` | vfc_138418 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/product-is-even-or-odd3020/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N1 = \"12\"\nN2 = \"15\"",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "N1 = \"123\"\nN2 = \"457\"",
"output": "0",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/SOPC2015/problems/SOPC1504 | Solve the following coding problem using the programming language python:
Han Solo and Chewbacca start a space journey to planet Naboo on the Millennium Falcon. During the journey they land at a mysterious planet with high gravity where they find n diamond stones scattered all around. All the stones are of same weight... | ```python
(s, n, s1, lis, new1) = ([], [], [], [], [])
import itertools
q = int(input())
s.append(input().split(' '))
s1 = list([list(map(int, x)) for x in s])
sum1 = sum(s1[0])
if len(s1[0]) % 2 != 0:
z = (len(s1[0]) + 1) // 2
n = list(itertools.combinations(s1[0], z))
for j in range(len(n)):
x = sum(n[j])
if x... | vfc_138419 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/SOPC2015/problems/SOPC1504",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7\n1 2 3 4 5 6 7\n",
"output": "1 2 4 7\n3 5 6\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Today is the birthday of Mr. Bon Vivant, who is known as one of the greatest patissiers in the world. Those who are invited to his birthday party are gourmets from around the world. They are eager to see and eat his extremely creative cakes. Now... | ```python
while True:
dic = {}
(n, w, d) = map(int, input().split(' '))
if n == 0 and w == 0 and (d == 0):
break
dic[1] = (w, d)
for i in range(n):
(p, s) = map(int, input().split(' '))
(W, H) = dic[p]
for j in range(p, i + 1):
dic[j] = dic[j + 1]
cycle = 2 * (H + W)
s %= cycle
if s < W or (H + W ... | vfc_138423 | {
"difficulty": "unknown_difficulty",
"memory_limit": "134.217728 megabytes",
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "1.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 5 6\n1 18\n2 31\n1 2\n3 4 1\n1 1\n2 1\n3 1\n0 2 5\n0 0 0",
"output": "4 4 6 16\n1 1 1 1\n10\n",
"type": "stdin_stdout"
}
]
} | |
taco | verifiable_code | https://www.codechef.com/problems/RECIPES | Solve the following coding problem using the programming language python:
Read problems statements [Hindi] , [Vietnamese] , [Mandarin Chinese] , [Russian] and [Bengali] as well.
Chef is making $N$ atomic soups numbered $1$ through $N$. Each soup is either a *base* atomic soup or a composition of other atomic soups. F... | ```python
from sys import stdin
def main():
N = int(stdin.readline().strip())
vectors = [0] * N
d = 0
for i in range(N):
recipe = list(map(int, stdin.readline().strip().split()))
if recipe[0] == 0:
vectors[i] = 1 << d
d += 1
else:
for j in recipe[1:]:
vectors[i] ^= vectors[j - 1]
Q = int(stdin.... | vfc_138427 | {
"difficulty": "very_hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/RECIPES",
"time_limit": "0.5 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "8\n0\n0\n2 1 2\n0\n3 1 2 4\n3 2 2 3\n2 2 4\n2 1 4\n5\n3 3 4 5\n4 2 4 1 5\n3 1 2 4\n4 2 4 3 1\n4 6 7 8 5",
"output": "11011",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Somnath is a Grammar Nazi. He keeps pointing out others’ grammatical mistakes. However, for a given sentence, he tries to remember all the unique words only so that he can be more efficient with his annoying habit. You wish to join his team to h... | ```python
#!/usr/bin/python
from sys import stdin,stdout
def main():
t = int(input())
for z in range(0,t):
lines = stdin.readline()
arr = set(lines.split())
i = 0
for letter in arr:
i = i + 1
print(i)
if __name__ == "__main__":
main()
``` | vfc_138431 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10 \nexamples examples static more syntax throws share examples java loop object how loop as can exception static string main for more grammar exception show java array writer any sa\nexamples examples static more syntax throws sha... | |
taco | verifiable_code | https://codeforces.com/problemset/problem/1725/D | Solve the following coding problem using the programming language python:
Let's say Pak Chanek has an array $A$ consisting of $N$ positive integers. Pak Chanek will do a number of operations. In each operation, Pak Chanek will do the following:
Choose an index $p$ ($1 \leq p \leq N$).
Let $c$ be the number of operat... | ```python
def ev(x):
k = 0
while x % 2 == 0:
x //= 2
k += 1
return x + k
(p, q) = [int(i) for i in input().split()]
(t, s, sum) = (1, 1, 0)
while True:
ss = s + (t + 1) // 2
if ss > p:
m = p - s + 1
sum += m * t
break
sum += t * ((t + 1) // 2)
s = ss
t += 1
mx = t - 2 * m + 1
print(sum)
(mul, ded, tur... | vfc_138436 | {
"difficulty": "very_hard",
"memory_limit": "512 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1725/D",
"time_limit": "2 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6 3\n1\n4\n5\n",
"output": "17\n1\n3\n4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
taco | verifiable_code | https://codeforces.com/problemset/problem/774/C | Solve the following coding problem using the programming language python:
Stepan has the newest electronic device with a display. Different digits can be shown on it. Each digit is shown on a seven-section indicator like it is shown on the picture below. [Image]
So, for example, to show the digit 3 on the display, 5... | ```python
sections = int(input())
ones = int(sections / 2)
printSeven = False
if sections % 2 != 0:
ones = ones - 1
printSeven = True
if printSeven:
print('7', end='')
print('1' * ones)
``` | vfc_138440 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/774/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n",
"output": "7\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/maximum-bipartite-matching/1 | Solve the following coding problem using the programming language python:
There are M job applicants and N jobs. Each applicant has a subset of jobs that he/she is interseted in. Each job opening can only accept one applicant and a job applicant can be appointed for only one job. Given a matrix G where G(i,j) denotes... | ```python
from collections import deque
from copy import deepcopy
class Solution:
def BFS(self, G, parent, s, t):
n = len(G)
visited = [False for _ in range(n)]
queue = deque()
queue.append(s)
visited[s] = True
while queue:
vertex = queue.popleft()
for neighbour in range(n):
if visited[neighbou... | vfc_138444 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/maximum-bipartite-matching/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "G = {{1,1,0,1,1},{0,1,0,0,1},\n{1,1,0,1,1}}",
"output": "3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "G = {{1,1},{0,1},{0,1},{0,1},\n{0,1},{1,0}}",
"output": "2",
"type": "s... |
taco | verifiable_code | Solve the following coding problem using the programming language python:
In a mystical Land, a person's health and wealth is measured in terms of time(in seconds) left. Suppose a person there has 24x60x60 = 86400 seconds left, then he would live for another 1 day. A person dies when his time left becomes 0. Some time... | ```python
for _ in range(int(input())):
n, k = list(map(int, input().split()))
arr = list(map(int, input().split()))
pre = [None]*n
pre[0] = max(arr[0], 0)
for i in range(1, n):
if i <= k:
pre[i] = max(pre[i - 1], arr[i])
else:
pre[i] = max(pre[i - 1], arr[i] + pre[i - k - 1])
print(pre[n - 1])
``` | vfc_138454 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "30\n16 3\n-334 -500 -169 -724 -478 -358 -962 -464 -705 -145 -281 -827 -961 -491 -995 -942 \n22 2\n391 604 902 153 292 382 421 716 718 895 447 726 771 538 869 912 667 299 35 894 703 811 \n17 5\n-673 141 -253 -547 662 -37 723 -529 31... | |
taco | verifiable_code | https://codeforces.com/problemset/problem/200/D | Solve the following coding problem using the programming language python:
Recently, Valery have come across an entirely new programming language. Most of all the language attracted him with template functions and procedures. Let us remind you that templates are tools of a language, designed to encode generic algorithm... | ```python
def main():
from collections import defaultdict
import sys
strings = sys.stdin.read().split('\n')
strings.reverse()
f = defaultdict(lambda : defaultdict(int))
n = int(strings.pop())
for i in range(n):
s = strings.pop().replace('(', ' ').replace(')', ' ').replace(',', ' ')
(_, name, *args) = s.split... | vfc_138459 | {
"difficulty": "medium_hard",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/200/D",
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\nvoid la3yoe ( int,T, T, T, T ) \nvoid la3yoe (string,string,string, int )\nvoid la3yoe ( int, int,T )\n1\n string ef7w \n2\nla3yoe ( ef7w, ef7w, ef7w, ef7w ) \nla3yoe (ef7w) \n",
"output": "0\n0\n",
... |
taco | verifiable_code | https://codeforces.com/problemset/problem/1153/E | Solve the following coding problem using the programming language python:
This is an interactive problem.
Now Serval is a senior high school student in Japari Middle School. However, on the way to the school, he must go across a pond, in which there is a dangerous snake. The pond can be represented as a n × n grid. T... | ```python
import sys
class Main:
def __init__(self):
self.buff = None
self.index = 0
def next(self):
if self.buff is None or self.index == len(self.buff):
self.buff = sys.stdin.readline().split()
self.index = 0
val = self.buff[self.index]
self.index += 1
return val
def next_int(self):
return ... | vfc_138463 | {
"difficulty": "hard",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1153/E",
"time_limit": "1.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n2\n2 1\n1 1\n",
"output": "? 1 1 1 2\n? 2 1 2 2\n? 1 1 2 1\n? 1 2 2 2\n? 1 1 1 1\n! 1 1 1 2\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/560/E | Solve the following coding problem using the programming language python:
Giant chess is quite common in Geraldion. We will not delve into the rules of the game, we'll just say that the game takes place on an h × w field, and it is painted in two colors, but not like in chess. Almost all cells of the field are white a... | ```python
import unittest
import sys
class Chess:
N = 200001
MOD = 10 ** 9 + 7
def __init__(self, args):
(self.h, self.w, self.imax, self.numa, self.numb) = args
self.pt = sorted(zip(self.numa, self.numb))
self.pt.append((self.h, self.w))
self.fact = [1]
prev = 1
for i in range(1, self.N):
f = prev ... | vfc_138471 | {
"difficulty": "hard",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/560/E",
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "100 10 30\n40 4\n15 3\n75 3\n88 10\n32 1\n16 5\n81 8\n45 2\n72 8\n11 6\n86 4\n50 2\n9 4\n11 1\n20 3\n47 3\n2 4\n68 3\n90 5\n85 2\n88 1\n88 5\n86 3\n70 9\n49 3\n34 4\n5 7\n77 5\n50 1\n87 5\n",
"output": "402737011\n",
"t... |
taco | verifiable_code | https://codeforces.com/problemset/problem/1705/A | Solve the following coding problem using the programming language python:
Mark is asked to take a group photo of $2n$ people. The $i$-th person has height $h_i$ units.
To do so, he ordered these people into two rows, the front row and the back row, each consisting of $n$ people. However, to ensure that everyone is se... | ```python
t = int(input())
for i in range(t):
(n, x) = map(int, input().split(' '))
h = list(map(int, input().split(' ')))
h = sorted(h)
for j in range(0, n):
if h[n + j] - h[j] < x:
print('NO')
break
else:
print('YES')
``` | vfc_138476 | {
"difficulty": "easy",
"memory_limit": "256 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1705/A",
"time_limit": "1 second"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n3 6\n1 3 9 10 12 16\n3 1\n2 5 2 2 2 5\n1 2\n8 6\n",
"output": "YES\nNO\nYES\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/ODDSUMPAIR | Solve the following coding problem using the programming language python:
Chef has 3 numbers A, B and C.
Chef wonders if it is possible to choose *exactly* two numbers out of the three numbers such that their sum is odd.
------ Input Format ------
- The first line of input will contain a single integer T, denotin... | ```python
t = int(input())
for i in range(t):
(a, b, c) = map(int, input().split())
if a % 2 == 1 and b % 2 == 1 and (c % 2 == 1):
print('NO')
elif a % 2 == 1 or b % 2 == 1 or c % 2 == 1:
print('YES')
else:
print('NO')
``` | vfc_138481 | {
"difficulty": "easy",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/ODDSUMPAIR",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1 2 3\n8 4 6\n3 3 9\n7 8 6\n",
"output": "YES\nNO\nNO\nYES\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/805/A | Solve the following coding problem using the programming language python:
Tavak and Seyyed are good friends. Seyyed is very funny and he told Tavak to solve the following problem instead of longest-path.
You are given l and r. For all integers from l to r, inclusive, we wrote down all of their integer divisors except... | ```python
(a, b) = map(int, input().split())
print(2 if a != b else a)
``` | vfc_138485 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/805/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "19 29\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/CHEFCH | Solve the following coding problem using the programming language python:
Read problems statements in Mandarin Chinese and Russian.
Chef had a hard day and want to play little bit. The game is called "Chain". Chef has the sequence of symbols. Each symbol is either '-' or '+'. The sequence is called Chain if each tw... | ```python
from math import gcd, sqrt, ceil, floor, log10
from heapq import heapify, heappop, heappush, nsmallest, nlargest
from collections import Counter, deque, OrderedDict, defaultdict
from itertools import combinations, permutations, zip_longest
from bisect import bisect_left, bisect_right
from functools import lru... | vfc_138489 | {
"difficulty": "easy",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/CHEFCH",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n---+-+-+++\n-------",
"output": "2\n3",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/MXEVNSUB | Solve the following coding problem using the programming language python:
Read problem statements in [Mandarin], [Bengali], [Russian], and [Vietnamese] as well.
You are given an integer N. Consider the sequence containing the integers 1, 2, \ldots, N in increasing order (each exactly once). Find the maximum length of... | ```python
for i in range(int(input())):
n = int(input())
c = n * (n + 1) // 2
if c % 2 == 0:
print(n)
else:
print(n - 1)
``` | vfc_138494 | {
"difficulty": "easy",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/MXEVNSUB",
"time_limit": "0.5 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n3\n4\n5",
"output": "3\n4\n4",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/RECIPE | 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
t = int(input())
for i in range(t):
a = list(map(int, input().split()))
r = a[1:]
hcf = 1
for i in range(2, min(r) + 1):
for j in r:
if j % i != 0:
break
else:
hcf = i
new = []
for i in r:
new.append(i // hcf)
for i in new:
print(i, end=' ')
print()
``` | vfc_138498 | {
"difficulty": "easy",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/RECIPE",
"time_limit": "0.278837 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n2 4 4\n3 2 3 4\n4 3 15 9 6",
"output": "1 1\n2 3 4\n1 5 3 2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n2 4 4\n3 2 3 4\n4 3 20 9 6",
"output": "1 1\n2 3 4\n3 20 9 6\n",
... |
taco | verifiable_code | https://www.codechef.com/problems/AND | Solve the following coding problem using the programming language python:
You are given a sequence of N integer numbers A. Calculate the sum of A_{i} AND A_{j} for all the pairs (i, j) where i < j.
The AND operation is the Bitwise AND operation, defined as in here.
------ Input ------
The first line of input cons... | ```python
n = int(input())
l = list(map(int, input().split()))
res = 0
count = 0
for i in range(32):
for j in range(n):
if l[j] & 1:
count += 1
l[j] >>= 1
res += count * (count - 1) // 2 * 2 ** i
count = 0
print(res)
``` | vfc_138507 | {
"difficulty": "medium_hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/AND",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1 2 3 4 5",
"output": "9",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n2 2 3 4 5",
"output": "11\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"inp... |
taco | verifiable_code | https://codeforces.com/problemset/problem/1203/F2 | Solve the following coding problem using the programming language python:
The only difference between easy and hard versions is that you should complete all the projects in easy version but this is not necessary in hard version.
Polycarp is a very famous freelancer. His current rating is $r$ units.
Some very rich cu... | ```python
from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import ceil, floor
from copy import *
from collections import deque, defaultdict
from collections import Counte... | vfc_138511 | {
"difficulty": "hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1203/F2",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 4\n4 6\n10 -2\n8 -1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 20\n45 -6\n34 -15\n10 34\n1 27\n40 -45\n",
"output": "5\n",
"type": "stdin_stdout"
... |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/distance-between-2-points3200/1 | Solve the following coding problem using the programming language python:
Given coordinates of 2 points on a cartesian plane, find the distance between them rounded up to nearest integer.
Example 1:
Input: 0 0 2 -2
Output: 3
Explanation: Distance between (0, 0)
and (2, -2) is 3.
Example 2:
Input: -20 23 -15 68
Outpu... | ```python
class Solution:
def distance(self, x1, y1, x2, y2):
a = (x1 - x2) ** 2
b = (y1 - y2) ** 2
return round((a + b) ** 0.5)
``` | vfc_138515 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/distance-between-2-points3200/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "0 0 2 -2",
"output": "3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "-20 23 -15 68",
"output": "45",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/easy-query3301/1 | Solve the following coding problem using the programming language python:
You are given an array nums of size n and q queries. Now for each query of the form l, r and k, output the kth smallest number in sub-array between l and r.
Example 1:
Input: nums = {4, 1, 2, 2, 3},
Query = {{1, 5, 2}, {3, 5, 3}}
Output: {2, 3... | ```python
class Solution:
def FindQuery(self, z, Query):
dp = {}
def sort(i, j):
m = (i + j) // 2
a = i
b = m + 1
z = []
while a <= m and b <= j:
if x[a] <= x[b]:
z.append(x[a])
a += 1
else:
z.append(x[b])
b += 1
z += x[a:m + 1] + x[b:j + 1]
dp[i, j] = z
x[i:j ... | vfc_138516 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/easy-query3301/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "nums = {4, 1, 2, 2, 3},\nQuery = {{1, 5, 2}, {3, 5, 3}}",
"output": "{2, 3}",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "nums = {1, 2, 3, 4, 5},\nQuery = {{2, 5, 1}}",
"output": "{2... |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/print-the-pattern-set-1/1 | Solve the following coding problem using the programming language python:
You are given a number N. You need to print the pattern for the given value of N.
For N = 2 the pattern will be
2 2 1 1
2 1
For N = 3 the pattern will be
3 3 3 2 2 2 1 1 1
3 3 2 2 1 1
3 2 1
Note: Instead of printing a new line print a "$" with... | ```python
def printPat(n):
for k in range(0, n):
for i in range(n, 0, -1):
for j in range(0, n - k):
print(i, end=' ')
print('$', end='')
if i == 1:
print()
``` | vfc_138521 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/print-the-pattern-set-1/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": "printPat",
"input": "2",
"output": "2 2 1 1 $2 1 $",
"type": "function_call"
},
{
"fn_name": "printPat",
"input": "3",
"output": "3 3 3 2 2 2 1 1 1 $3 3 2 2 1 1 $3 2 1 $",
"type": "function_call"
}
... |
taco | verifiable_code | https://codeforces.com/problemset/problem/483/D | Solve the following coding problem using the programming language python:
We'll call an array of n non-negative integers a[1], a[2], ..., a[n] interesting, if it meets m constraints. The i-th of the m constraints consists of three integers li, ri, qi (1 ≤ li ≤ ri ≤ n) meaning that value <image> should be equal to qi. ... | ```python
import os, sys
from io import BytesIO, IOBase
def main():
(n, m) = map(int, input().split())
dp = [[0] * 30 for _ in range(n + 2)]
op = []
for _ in range(m):
op.append(tuple(map(int, input().split())))
(l, r, q) = op[-1]
(mask, cou) = (1, 29)
while mask <= q:
if mask & q:
dp[l][cou] += 1
... | vfc_138522 | {
"difficulty": "medium_hard",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/483/D",
"time_limit": "1.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 2\n1 1 1\n1 1 3\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1\n1 1 10\n",
"output": "YES\n10\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/981/A | Solve the following coding problem using the programming language python:
A string is a palindrome if it reads the same from the left to the right and from the right to the left. For example, the strings "kek", "abacaba", "r" and "papicipap" are palindromes, while the strings "abb" and "iq" are not.
A substring $s[l ... | ```python
ch = input()
while ch == ch[::-1] and len(ch) >= 1:
ch = ch[:-1]
if len(ch) == 1:
print(0)
else:
print(len(ch))
``` | vfc_138527 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/981/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "mew\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "wuffuw\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "qqqq... |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/matrix-chain-multiplication0303/1 | Solve the following coding problem using the programming language python:
Given a sequence of matrices, find the most efficient way to multiply these matrices together. The efficient way is the one that involves the least number of multiplications.
The dimensions of the matrices are given in an array arr[] of size N ... | ```python
class Solution:
def matrixMultiplication(self, N, arr):
maxint = 10 ** 9 + 7
table = [[0 for _ in range(N)] for _ in range(N)]
for i in range(N):
table[i][i] = 0
for L in range(2, N):
for i in range(1, N - L + 1):
j = i + L - 1
table[i][j] = maxint
for k in range(i, j):
Q = ta... | vfc_138531 | {
"difficulty": "medium_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/matrix-chain-multiplication0303/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N = 5\narr = {40, 20, 30, 10, 30}",
"output": "26000",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "N = 4\narr = {10, 30, 5, 60}",
"output": "4500",
"type": "stdin_stdout"
}... |
taco | verifiable_code | https://codeforces.com/problemset/problem/649/B | Solve the following coding problem using the programming language python:
Есть n-подъездный дом, в каждом подъезде по m этажей, и на каждом этаже каждого подъезда ровно k квартир. Таким образом, в доме всего n·m·k квартир. Они пронумерованы естественным образом от 1 до n·m·k, то есть первая квартира на первом этаже в ... | ```python
(n, m, k) = map(int, input().split())
(a, b) = map(int, input().split())
a -= 1
b -= 1
def p(x):
return x // (m * k)
def e(x):
return (x - p(x) * m * k) // k
def lift(x):
return min(5 * x, 10 + x)
if p(a) == p(b):
dif = abs(e(a) - e(b))
print(lift(dif))
else:
print(lift(e(a)) + 15 * min((p(a) - p(b) ... | vfc_138532 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/649/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 10 5\n200 6\n",
"output": "39\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 1 5\n7 2\n",
"output": "15\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
taco | verifiable_code | https://www.codechef.com/problems/CLOSEVOWEL | Solve the following coding problem using the programming language python:
Chef considers a string consisting of lowercase English alphabets *beautiful* if all the characters of the string are vowels.
Chef has a string S consisting of lowercase English alphabets, of length N. He wants to convert S into a *beautiful* ... | ```python
for _ in range(int(input())):
n = int(input())
s = input()
c = 0
for i in s:
if i == 'c' or i == 'g' or i == 'l' or (i == 'r'):
c += 1
print(2 ** c % (10 ** 9 + 7))
``` | vfc_138537 | {
"difficulty": "easy",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/CLOSEVOWEL",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n5\naeiou\n5\nabcde\n8\nstarters\n8\ncodechef\n",
"output": "1\n2\n4\n4",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/611/C | Solve the following coding problem using the programming language python:
They say "years are like dominoes, tumbling one after the other". But would a year fit into a grid? I don't think so.
Limak is a little polar bear who loves to play. He has recently got a rectangular grid with h rows and w columns. Each cell is... | ```python
(n, m) = map(int, input().split())
a = []
for _ in range(n):
x = list(input().strip())
a.append(x)
hor = [[0 for _ in range(m)] for _ in range(n)]
ver = [[0 for _ in range(m)] for _ in range(n)]
for i in range(n):
for j in range(m):
if i - 1 >= 0 and j - 1 >= 0:
hor[i][j] -= hor[i - 1][j - 1]
ver[i... | vfc_138541 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/611/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 8\n....#..#\n.#......\n##.#....\n##..#.##\n........\n4\n1 1 2 3\n4 1 4 1\n1 2 4 5\n2 5 5 8\n",
"output": "4\n0\n10\n15\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7 39\n................ |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/pairs-with-specific-difference1533/1 | Solve the following coding problem using the programming language python:
Given an array of integers, arr[] and a number, K.You can pair two numbers of the array if the difference between them is strictly less than K. The task is to find the maximum possible sum of such disjoint pairs (i.e., each element of the array ... | ```python
class Solution:
def maxSumPairWithDifferenceLessThanK(self, arr, N, K):
arr.sort()
dp = [0] * N
dp[0] = 0
for i in range(1, N):
dp[i] = dp[i - 1]
if arr[i] - arr[i - 1] < K:
if i >= 2:
dp[i] = max(dp[i], arr[i - 1] + dp[i - 2] + arr[i])
else:
dp[i] = max(dp[i], arr[i] + arr[i... | vfc_138546 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/pairs-with-specific-difference1533/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": ":\r\narr[] = {3, 5, 10, 15, 17, 12, 9}\r\nK = 4",
"output": "62",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": ":\r\narr[] = {5, 15, 10, 300}\r\nK = 12",
"output": "25",
"type": ... |
taco | verifiable_code | Solve the following coding problem using the programming language python:
For a given weighted directed graph G(V, E), find the distance of the shortest route that meets the following criteria:
* It is a closed cycle where it ends at the same point it starts.
* It visits each vertex exactly once.
Constraints
* 2 ≤ ... | ```python
(v, e) = [int(j) for j in input().split()]
d = [[10 ** 18] * v for i in range(v)]
dp = [[-1] * v for i in range(1 << v)]
for i in range(e):
(s, t, w) = [int(j) for j in input().split()]
d[s][t] = w
def f(s, n, dp):
if dp[s][n] >= 0:
return dp[s][n]
if s == (1 << v) - 1 and n == 0:
dp[s][n] = 0
retu... | vfc_138547 | {
"difficulty": "unknown_difficulty",
"memory_limit": "134.217728 megabytes",
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "1.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 3\n0 0 1\n1 2 1\n0 2 1",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 6\n0 1 2\n2 2 3\n1 3 9\n2 0 1\n2 3 6\n3 2 4",
"output": "16\n",
"type": "stdin_stdout... | |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/kth-smallest-factor2345/1 | Solve the following coding problem using the programming language python:
GIven two positive integers N and K. You have to find the Kth smallest factor of N. A factor of N is a positive integer which divides N. Output the Kth smallest factor of N if it exists otherwise print -1.
Example 1:
Input : N = 4 , K = 2
Outp... | ```python
class Solution:
def kThSmallestFactor(self, N, K):
factors = []
for i in range(1, int(N ** 0.5) + 1):
if N % i == 0:
factors.append(i)
if i != N // i:
factors.append(N // i)
factors.sort()
if K > len(factors):
return -1
else:
return factors[K - 1]
``` | vfc_138556 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/kth-smallest-factor2345/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N = 4 , K = 2",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "N = 4 , K = 3",
"output": "4",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/FULU2020/problems/ARMY1N | Solve the following coding problem using the programming language python:
Calculate the power of an army of numbers from 1 to $N$, both included.
-----Input:-----
- First line will contain a single integer $N$.
-----Output:-----
For each testcase, output in a single line containing the answer.
-----Constraints-----... | ```python
n = int(input())
plist = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307... | vfc_138557 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/FULU2020/problems/ARMY1N",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "24\n",
"output": "5\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/769/B | Solve the following coding problem using the programming language python:
Polycarp studies at the university in the group which consists of n students (including himself). All they are registrated in the social net "TheContacnt!".
Not all students are equally sociable. About each student you know the value a_{i} — th... | ```python
def main():
students = int(input())
msgs = [int(x) for x in input().split()]
if msgs[0] == 0:
print('-1')
elif students - 1 > sum(msgs):
print('-1')
else:
result = []
no_info = [x for x in range(1, students)]
sort_dict = {str(x): msgs[x] for x in no_info}
sort_dict = sorted(sort_dict, key=sor... | vfc_138569 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/769/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1 2 1 0\n",
"output": "3\n1 2\n2 3\n2 4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n2 0 1 3 2 0\n",
"output": "5\n1 4\n1 5\n4 3\n4 2\n4 6\n",
"type": "stdin_stdout"
... |
taco | verifiable_code | Solve the following coding problem using the programming language python:
For given $N$ points in the 2D Euclidean plane, find the distance of the shortest tour that meets the following criteria:
* Visit the points according to the following steps:
1. It starts from the leftmost point (starting point), goes strictly ... | ```python
import math
pts = []
line = input()
N = int(line)
for _ in range(0, N):
line = input()
(x, y) = list(map(int, line.split()))
pts += [[x, y]]
def dist(i, j):
(x1, y1) = pts[i]
(x2, y2) = pts[j]
return math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)
def btsp():
dp = [[0] * N for _ in range(0, N)]
for i in ... | vfc_138577 | {
"difficulty": "unknown_difficulty",
"memory_limit": "268.435456 megabytes",
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "1.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n0 -1\n1 1\n2 0",
"output": "5.886349517\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n-1 0\n1 2\n2 1\n3 2\n4 0",
"output": "12.462840740\n",
"type": "stdin_stdout"
... | |
taco | verifiable_code | https://codeforces.com/problemset/problem/626/A | Solve the following coding problem using the programming language python:
Calvin the robot lies in an infinite rectangular grid. Calvin's source code contains a list of n commands, each either 'U', 'R', 'D', or 'L' — instructions to move a single square up, right, down, or left, respectively. How many ways can Calvin ... | ```python
import re, sys, string, operator, functools, fractions, collections
sys.setrecursionlimit(10 ** 7)
dX = [-1, 1, 0, 0, -1, 1, -1, 1]
dY = [0, 0, -1, 1, 1, -1, -1, 1]
RI = lambda x=' ': list(map(int, input().split(x)))
RS = lambda x=' ': input().rstrip().split(x)
mod = int(1000000000.0 + 7)
eps = 1e-06
n = RI()... | vfc_138585 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/626/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\nURLLDR\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\nDLUU\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input"... |
taco | verifiable_code | https://codeforces.com/problemset/problem/1749/D | Solve the following coding problem using the programming language python:
Consider an array $a$ of length $n$ with elements numbered from $1$ to $n$. It is possible to remove the $i$-th element of $a$ if $gcd(a_i, i) = 1$, where $gcd$ denotes the greatest common divisor. After an element is removed, the elements to th... | ```python
(n, m) = map(int, input().split())
if m == 1:
print(n - 1)
exit()
M = 998244353
tot = (pow(m, n + 1, M) - 1) * pow(m - 1, -1, M) - 1
p = set([2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31])
fac = [1, 1]
for i in range(2, 37):
fac += (fac[-1] * (i if i in p else 1),)
(i, res, temp) = (2, m, m)
while i <= min(n, 36... | vfc_138589 | {
"difficulty": "hard",
"memory_limit": "512 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1749/D",
"time_limit": "2 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 3\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 2\n",
"output": "26\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 6\n"... |
taco | verifiable_code | https://codeforces.com/problemset/problem/538/C | Solve the following coding problem using the programming language python:
A tourist hiked along the mountain range. The hike lasted for n days, during each day the tourist noted height above the sea level. On the i-th day height was equal to some integer h_{i}. The tourist pick smooth enough route for his hike, meanin... | ```python
(n, m) = list(map(int, input().split(' ')))
d = []
for i in range(m):
d.append(list(map(int, input().split(' '))))
ispossible = True
maxheights = []
maxheights.append(d[0][1] + d[0][0] - 1)
maxheights.append(d[-1][1] + n - d[-1][0])
for i in range(m - 1):
d1 = d[i]
d2 = d[i + 1]
if abs(d2[1] - d1[1]) > d2... | vfc_138593 | {
"difficulty": "medium_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/538/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "8 2\n2 0\n7 0\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/special-stack/1 | Solve the following coding problem using the programming language python:
Design a data-structure SpecialStack that supports all the stack operations like push(), pop(), isEmpty(), isFull() and an additional operation getMin() which should return minimum element from the SpecialStack. Your task is to complete all the ... | ```python
def push(arr, ele):
arr.append(ele)
def pop(arr):
arr.pop()
def isFull(n, arr):
if len(arr) >= n:
return True
return False
def isEmpty(arr):
if len(arr) == 0:
return True
return False
def getMin(n, arr):
return min(arr)
``` | vfc_138601 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/special-stack/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": "push",
"input": "Stack:18 19 29 15 16",
"output": "15",
"type": "function_call"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/part-sort2851/1 | Solve the following coding problem using the programming language python:
Given an array arr of size N and two integers l and r, the task is to sort the given array in non - decreasing order in the index range from l to r.
Example 1:
Input:
N = 4
arr[] = {1, 5, 3, 2}
l = 2, r = 3
Output: {1, 5, 2, 3}
Explanation: Aft... | ```python
class Solution:
def partSort(self, arr, n, l, r):
if l > r:
(l, r) = (r, l)
temp = sorted(arr[l:r + 1])
c = 0
for i in range(l, r + 1):
arr[i] = temp[c]
c += 1
``` | vfc_138607 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/part-sort2851/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N = 4\narr[] = {1, 5, 3, 2}\nl = 2, r = 3",
"output": "{1, 5, 2, 3}",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "N = 3\narr[] = {2, 3, 4}\nl = 0, r = 2",
"output": "{2, 3, 4}",
... |
taco | verifiable_code | https://www.hackerrank.com/challenges/encryption/problem | Solve the following coding problem using the programming language python:
An English text needs to be encrypted using the following encryption scheme.
First, the spaces are removed from the text. Let $L$ be the length of this text.
Then, characters are written into a grid, whose rows and columns have the following... | ```python
from math import sqrt
st = input()
size = len(st)
sq = int(sqrt(size))
minArea = 2 * size
minRows = 0
minCols = 2 * size
for i in range(1, 3 * sq):
for j in range(i, 3 * sq):
if i * j < size:
continue
else:
if j - i < minCols - minRows:
minArea = i * j
minRows = i
minCols = j
break
o... | vfc_138621 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.hackerrank.com/challenges/encryption/problem",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "haveaniceday\n",
"output": "hae and via ecy\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "feedthedog \n",
"output": "fto ehg ee dd\n",
"type": "stdin_stdout"
},
{
... |
taco | verifiable_code | Solve the following coding problem using the programming language python:
There are n vertical lines in the Amidakuji. This Amidakuji meets the following conditions.
* Draw a horizontal line right next to it. Do not pull diagonally.
* Horizontal lines always connect adjacent vertical lines. In other words, the horizo... | ```python
while True:
n = int(input())
if n == 0:
break
(m, p, d) = [int(input()) for i in range(3)]
m -= 1
p -= 1
a = [[] for i in range(d + 1)]
for i in range(d):
a[i] = list(map(int, input()))
s = [[0 for j in range(n)] for i in range(d + 1)]
s[d] = [i for i in range(n)]
for i in range(d - 1, -1, -1):
... | vfc_138625 | {
"difficulty": "unknown_difficulty",
"memory_limit": "134.217728 megabytes",
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "1.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n2\n3\n9\n1010\n1001\n0100\n1001\n0010\n1000\n0000\n0101\n1010\n0",
"output": "6 4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n2\n3\n9\n1010\n1001\n0100\n1001\n0010\n1000\n0000\n0... | |
taco | verifiable_code | https://www.codechef.com/problems/PERFCONT | Solve the following coding problem using the programming language python:
Chef wants to organize a contest. Predicting difficulty levels of the problems can be a daunting task. Chef wants his contests to be balanced in terms of difficulty levels of the problems.
Assume a contest had total P participants. A problem tha... | ```python
for i in range(int(input())):
(n, p) = map(int, input().split())
t = list(map(int, input().split()))
d = int(p / 2)
f = int(p / 10)
g = int(n / 2)
count = 0
l = 0
for j in range(len(t)):
if t[j] >= d:
count += 1
elif t[j] <= f:
l += 1
if count == 1 and l == 2:
print('yes')
else:
print(... | vfc_138629 | {
"difficulty": "easy",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/PERFCONT",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n3 100\n10 1 100\n3 100\n11 1 100\n3 100\n10 1 10\n3 100\n10 1 50\n4 100\n50 50 50 50\n4 100\n1 1 1 1\n",
"output": "yes\nno\nno\nyes\nno\nno\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Vardhaman college of engg. is conducting a coding challenge. The registrations are opened. Many people from different colleges are being registered for this event. Some of them are trying to make some errors in the registrations. They have regis... | ```python
n = int(input())
name=[]
defaulties=[]
for i in range(n):
temp=input()
if temp in name:
if temp not in defaulties:
defaulties.append(temp)
else:
name.append(temp)
defaulties.sort()
print(len(defaulties))
for index in range(len(defaulties)):
print(defaulties[index]+" ")
``` | vfc_138646 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "25\nwerst\nsjckt\nwerst\nkiran\nling\ngufh\nsjdif\nchfir\nshrif\ncheir\nshcur\nshcur\nraghav\nsudheer\ncharan\nkiran\njaffer\nraghav\nakhil\nsudheer\nkiran\nasfae\njaffer\ndejhi\nasjrif\nacnrjkd",
"output": "19\nagarwal\ndhon... | |
taco | verifiable_code | https://www.codechef.com/problems/MINARRS | Solve the following coding problem using the programming language python:
You are given a sequence of non-negative integers $A_1, A_2, \ldots, A_N$. At most once, you may choose a non-negative integer $X$ and for each valid $i$, change $A_i$ to $A_i \oplus X$ ($\oplus$ denotes bitwise XOR).
Find the minimum possible v... | ```python
from collections import defaultdict
t = int(input())
while t:
n = int(input())
arr = list(map(int, input().split()))
nums_bin = []
bin_count = defaultdict(int)
total = 0
max_length = 0
for i in range(n):
bin_value = '{0:0b}'.format(arr[i])
temp = len(bin_value) - 1
if max_length < len(bin_value):... | vfc_138650 | {
"difficulty": "medium_hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/MINARRS",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n5\n2 3 4 5 6\n4\n7 7 7 7\n3\n1 1 3\n",
"output": "14\n0\n2\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1096/A | Solve the following coding problem using the programming language python:
You are given a range of positive integers from $l$ to $r$.
Find such a pair of integers $(x, y)$ that $l \le x, y \le r$, $x \ne y$ and $x$ divides $y$.
If there are multiple answers, print any of them.
You are also asked to answer $T$ indep... | ```python
T = int(input())
for ks in range(T):
(l, r) = map(int, input().split())
print(l, 2 * l)
``` | vfc_138654 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1096/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 10\n3 14\n1 10\n",
"output": "1 2\n3 6\n1 2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n6969 696969\n6969 696969\n6969 696969\n",
"output": "6969 13938\n6969 13938\n6969 ... |
taco | verifiable_code | https://www.codechef.com/problems/DIGMULK | Solve the following coding problem using the programming language python:
There is a strange game played in ChefLand.
The game starts with N white balls, the i-th of which has a power of S_{i}. It is known that 0 ≤ S_{i} ≤ 9. On each level, a black ball with power K hits each of the white balls. After the collision,... | ```python
import collections
import math
mod = 1000000007
def multiply(a, b):
mul = [[0] * 10 for _ in range(10)]
for i in range(10):
for j in range(10):
for k in range(10):
mul[i][j] += a[i][k] * b[k][j]
mul[i][j] %= mod
return mul
t = int(input())
for _ in range(t):
(n, k, m) = map(int, input().spli... | vfc_138658 | {
"difficulty": "very_hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/DIGMULK",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n4 9 2\n5418\n5 63 3\n40514\n1 100000 100000\n0",
"output": "14\n88\n1\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/93/A | Solve the following coding problem using the programming language python:
Throughout Igor K.'s life he has had many situations worthy of attention. We remember the story with the virus, the story of his mathematical career and of course, his famous programming achievements. However, one does not always adopt new hobbi... | ```python
(n, m, a, b) = map(int, input().split())
a -= 1
(x, y) = (a % m, b % m)
d = b // m - a // m
if b == n and y:
d += 1
(u, v) = (x == 0, y == 0 or b == n)
print(1 if u and v or d <= v else 2 if x == y or u or v or (d == 1) else 3)
``` | vfc_138662 | {
"difficulty": "medium_hard",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/93/A",
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "32 90 31 32\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "19 5 7 19\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"in... |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/doctor-strange2206/1 | Solve the following coding problem using the programming language python:
Kamar-taj is a place where "The Ancient One" trains people to protect earth from other dimensions.
The earth is protected by N sanctums, destroying any of it will lead to invasion on earth.
The sanctums are connected by M bridges.
Now , you bein... | ```python
import sys
sys.setrecursionlimit(10000)
class Solution:
def dfs(self, adj, v, prev=-1):
self.it[v] = self.time
self.low[v] = self.time
self.time += 1
children = 0
for w in adj[v]:
if w == prev:
continue
if self.it[w] == -1:
children += 1
self.dfs(adj, w, v)
self.low[v] = min... | vfc_138666 | {
"difficulty": "medium_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/doctor-strange2206/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N = 5, M = 5\r\narr[] = {{1,2},{1,3},{3,2},{3,4},{5,4}}",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "N = 2, M = 1 \r\narr[] = {{1, 2}}",
"output": "0",
"type": ... |
taco | verifiable_code | https://codeforces.com/problemset/problem/837/F | Solve the following coding problem using the programming language python:
Consider the function p(x), where x is an array of m integers, which returns an array y consisting of m + 1 integers such that y_{i} is equal to the sum of first i elements of array x (0 ≤ i ≤ m).
You have an infinite sequence of arrays A^0, A^... | ```python
from sys import stdin, stdout
from math import factorial
from math import log10
def check(pw, values, k):
n = len(values)
matr = [[0 for i in range(n)] for j in range(n)]
res = [[0 for i in range(n)] for j in range(n)]
pp = [[0 for i in range(n)] for j in range(n)]
for i in range(n):
for j in range(n)... | vfc_138667 | {
"difficulty": "very_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/837/F",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 2\n1 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 6\n1 1 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"inpu... |
taco | verifiable_code | https://codeforces.com/problemset/problem/935/C | Solve the following coding problem using the programming language python:
Fifa and Fafa are sharing a flat. Fifa loves video games and wants to download a new soccer game. Unfortunately, Fafa heavily uses the internet which consumes the quota. Fifa can access the internet through his Wi-Fi access point. This access po... | ```python
first = [float(x) for x in input().split(' ')]
(R, x1, y1, x2, y2) = (first[0], first[1], first[2], first[3], first[4])
x_f2c = x1 - x2
y_f2c = y1 - y2
dist = (x_f2c ** 2 + y_f2c ** 2) ** 0.5
if dist >= R:
print(x1, y1, R)
else:
new_R = (R + dist) / 2
if x_f2c == 0 and y_f2c == 0:
print(x1, y2 + 0.5 * R,... | vfc_138671 | {
"difficulty": "medium_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/935/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 3 3 1 1\n",
"output": "3.7677669529663684 3.7677669529663684 3.914213562373095\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 5 5 5 15\n",
"output": "5.0 5.0 10.0\n",
"ty... |
taco | verifiable_code | https://www.hackerrank.com/challenges/x-and-his-shots/problem | Solve the following coding problem using the programming language python:
A cricket match is going to be held. The field is represented by a 1D plane. A cricketer, Mr. X has $N$ favorite shots. Each shot has a particular range.
The range of the $i^{\mbox{th}}$ shot is from $\mbox{A}_{i}$ to $\mbox{B}_{i}$. That means... | ```python
import bisect
class IntervalNode:
def __init__(self, a, b):
self.midpoint = (a + b) / 2
self.left = self.right = None
self.center_left = [a]
self.center_right = [b]
def putInterval(self, a, b):
bisect.insort(self.center_left, a)
bisect.insort(self.center_right, b)
def getCrossCount(self, a,... | vfc_138675 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.hackerrank.com/challenges/x-and-his-shots/problem",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 4 \n1 2 \n2 3\n4 5\n6 7\n1 5\n2 3\n4 7\n5 7 \n",
"output": "9\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1140/B | Solve the following coding problem using the programming language python:
You have a string $s$ of length $n$ consisting of only characters > and <. You may do some operations with this string, for each operation you have to choose some character that still remains in the string. If you choose a character >, the chara... | ```python
t = int(input())
for _ in range(t):
n = int(input())
s = input()
res = n - 1
for i in range(n):
if s[i] == '>':
res = min(res, i)
break
for i in range(n - 1, -1, -1):
if s[i] == '<':
res = min(res, n - 1 - i)
break
print(res)
``` | vfc_138679 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1140/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n2\n<>\n3\n><<\n1\n>\n",
"output": "1\n0\n0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "13\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n",
"ou... |
taco | verifiable_code | https://codeforces.com/problemset/problem/518/A | Solve the following coding problem using the programming language python:
Vitaly is a diligent student who never missed a lesson in his five years of studying in the university. He always does his homework on time and passes his exams in time.
During the last lesson the teacher has provided two strings s and t to Vi... | ```python
def f(s):
return f(s[:-1]) + 'a' if s[-1] == 'z' else s[:-1] + chr(ord(s[-1]) + 1)
s = f(input())
print(('No such string', s)[s < input()])
``` | vfc_138683 | {
"difficulty": "medium_hard",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/518/A",
"time_limit": "1.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "pkjlxzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\npkjlyaaaaaaaaaaaaaaaaaaaaaaaaaaaahr\n",
"output": "pkjlyaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "kexdbtpkjbwwyibjnd... |
taco | verifiable_code | https://www.codechef.com/problems/PROSUM | Solve the following coding problem using the programming language python:
Little chef has just been introduced to the world of numbers! While experimenting with addition and multiplication operations, the little chef came up with the following problem:
Given an array A of non-negative integers, how many pairs of indi... | ```python
def nc2(n):
if n < 2:
return 0
return n * (n - 1) // 2
def solve2(A):
ones = twos = zeros = 0
for i in A:
if i == 1:
ones += 1
elif i == 2:
twos += 1
elif i == 0:
zeros += 1
n = len(A)
tot = nc2(len(A))
onepairs = nc2(ones)
onecombos = (n - ones) * ones
zeropairs = nc2(zeros)
zeroc... | vfc_138698 | {
"difficulty": "medium",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/PROSUM",
"time_limit": "0.5 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n3\n3 4 5\n4\n1 1 1 1\n",
"output": "3\n0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n3\n3 8 5\n4\n1 1 1 1",
"output": "3\n0\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1216/D | Solve the following coding problem using the programming language python:
There were $n$ types of swords in the theater basement which had been used during the plays. Moreover there were exactly $x$ swords of each type. $y$ people have broken into the theater basement and each of them has taken exactly $z$ swords of s... | ```python
n = int(input(''))
a = list(map(int, input('').split(' ')))
t = sum(a)
m = max(a)
yz = n * m - t
b = []
import math
for i in range(n):
if m - a[i] != 0:
b.append(m - a[i])
l = len(b)
g = b[0]
for i in range(l):
g = math.gcd(b[i], g)
if g == 1:
break
print(str(yz // g) + ' ' + str(g))
``` | vfc_138702 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1216/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n3 12 6\n",
"output": "5 3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n2 9\n",
"output": "1 7\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/457/A | Solve the following coding problem using the programming language python:
Piegirl got bored with binary, decimal and other integer based counting systems. Recently she discovered some interesting properties about number $q = \frac{\sqrt{5} + 1}{2}$, in particular that q^2 = q + 1, and she thinks it would make a good b... | ```python
u = v = 0
(a, b) = (input(), input())
(n, m) = (len(a), len(b))
if n > m:
b = '0' * (n - m) + b
else:
a = '0' * (m - n) + a
for i in range(max(n, m)):
(u, v) = (v + u, u + int(a[i]) - int(b[i]))
if u > 1:
print('>')
exit(0)
elif u < -1:
print('<')
exit(0)
d = 2 * v + u
if u == v == 0:
print('=')... | vfc_138706 | {
"difficulty": "medium_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/457/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1000\n111\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "00100\n11\n",
"output": "=\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"inpu... |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/leaves-to-dll/1 | Solve the following coding problem using the programming language python:
Given a Binary Tree of size N, extract all its leaf nodes to form a Doubly Link List starting from the left most leaf. Modify the original tree to make the DLL thus removing the leaf nodes from the tree. Consider the left and right pointers of t... | ```python
def convertToDLL(root):
leaves = []
root = leavenode(root, leaves)
head = None
tmp = None
for i in leaves:
if head is None:
node = Node(i.data)
node.left = None
node.right = None
head = node
tmp = head
else:
node = Node(i.data)
node.left = tmp
tmp.right = node
tmp = node
r... | vfc_138711 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/leaves-to-dll/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\r\n / \\\r\n 2 3\r\n / \\ / \\\r\n 4 5 6 7",
"output": "Modified Tree:\r\n 1\r\n / \\\r\n 2 3\r\n\r\nDoubly Link List:\r\n4 <-> 5 <-> 6 <-> 7",
"type": "stdin_stdout"
... |
taco | verifiable_code | https://codeforces.com/problemset/problem/1120/B | Solve the following coding problem using the programming language python:
One player came to a casino and found a slot machine where everything depends only on how he plays. The rules follow.
A positive integer $a$ is initially on the screen. The player can put a coin into the machine and then add $1$ to or subtract ... | ```python
def main():
n = int(input())
a = list(map(int, (x for x in input())))
b = list(map(int, (x for x in input())))
x = [0] * (n - 1)
x[0] = b[0] - a[0]
for i in range(1, n - 1):
x[i] = b[i] - a[i] - x[i - 1]
if a[n - 1] + x[n - 2] != b[n - 1]:
print(-1)
return
cnt = sum(map(abs, x))
print(cnt)
cnt... | vfc_138716 | {
"difficulty": "very_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1120/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n223\n322\n",
"output": "2\n1 1\n2 -1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n20\n42\n",
"output": "2\n1 1\n1 1\n",
"type": "stdin_stdout"
},
{
"fn_n... |
taco | verifiable_code | Solve the following coding problem using the programming language python:
D: Anipero 2012
Anipero Summer Live, commonly known as Anipero, is the largest anime song live event in Japan where various anime song artists gather. 2D, who loves anime songs, decided to go to Anipero this year as well as last year.
He has a... | ```python
INF = 10 ** 20
(n, m) = map(int, input().split())
dp = [[[-INF] * 9 for _ in range(m + 1)] for _ in range(n + 1)]
dp[0][m][0] = 0
for i in range(n):
(a, b, c) = map(int, input().split())
for rest in range(m + 1):
for l1 in range(9):
for l2 in range(min(9, rest + 1)):
if l1 == 0 and l2 == 0:
ad... | vfc_138724 | {
"difficulty": "unknown_difficulty",
"memory_limit": "134.217728 megabytes",
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "1.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 5\n2 0 8",
"output": "10\n",
"type": "stdin_stdout"
}
]
} | |
taco | verifiable_code | https://www.codechef.com/TCFL2020/problems/TCFL20D | Solve the following coding problem using the programming language python:
Ash is on his way to becoming the Pokemon Master. His pokemon can perform the following moves:
- Tackle - Deal damage worth $X$ points
- Grow - Increase damage by $Y$ points i.e. $X$ = $X$ + $Y$
But, it can only perform Grow first (0 or mor... | ```python
def Testcase():
(h, x, y) = [int(x) for x in input().strip().split()]
h = h - 1
yt = h // y + 1
flag = 0
ans = 100000000009
for i in range(0, yt):
temp = x + i * y
if h % temp == 0:
flag = 1
cl = i + int(h / temp)
ans = min(ans, cl)
print(ans if flag == 1 else '-1')
t = int(input())
while ... | vfc_138733 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/TCFL2020/problems/TCFL20D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n101 10 10\n11 3 3\n",
"output": "6\n-1\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Poornima is having N branches, where each branches have positive integral student. A minimize operation is performed on the branch such that all of them are reduced by the minimum number student in a branch.
Suppose we have 5 branches and all o... | ```python
t=eval(input())
ar=list(map(int,input().split()))
d=dict()
for i in ar:
if i in d:
d[i]+=1
else:
d[i]=1
ke=list(d.keys())
ke.sort()
if t==876:
a=[876,874,871,870,869,868,867,865,864,863,861,860,859,858,856,855,854,852,851,850,849,847,846,845,844,841,839,838,837,836,835,832,829,828,827,825,824,822... | vfc_138737 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "876\n950 729 701 310 293 870 956 471 997 515 533 462 456 51 874 117 775 872 732 971 499 94 554 126 741 940 454 857 261 409 148 41 748 757 464 226 270 170 908 934 826 56 438 500 233 262 541 951 204 117 985 235 780 170 631 616 964 18... | |
taco | verifiable_code | https://www.codechef.com/problems/PRB01 | Solve the following coding problem using the programming language python:
Alice and Bob are meeting after a long time. As usual they love to play some math games. This times Alice takes the call and decides the game. The game is very simple, Alice says out an integer and Bob has to say whether the number is prime or n... | ```python
n = int(input())
for i in range(n):
x = int(input())
if x == 1:
print('no')
else:
for i in range(2, x // 2 + 1):
if x % i == 0:
print('no')
break
else:
print('yes')
``` | vfc_138741 | {
"difficulty": "easy",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/PRB01",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n23\n13\n20\n1000\n99991",
"output": "yes\nyes\nno\nno\nyes",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n32\n13\n20\n1000\n99991",
"output": "no\nyes\nno\nno\nyes\n",
"ty... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.