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://practice.geeksforgeeks.org/problems/min-sum-formed-by-digits3551/1 | Solve the following coding problem using the programming language python:
Given an array of digits (values are from 0 to 9), find the minimum possible sum of two numbers formed from digits of the array. All digits of the given array must be used to form the two numbers.
Any combination of digits may be used to form th... | ```python
import heapq as h
class Solution:
def minSum(self, arr, n):
num1 = '0'
num2 = '0'
heap = []
for i in range(0, n):
h.heappush(heap, arr[i])
while heap:
if heap:
num1 = num1 + str(h.heappop(heap))
if heap:
num2 = num2 + str(h.heappop(heap))
return int(num1) + int(num2)
``` | vfc_143249 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/min-sum-formed-by-digits3551/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N = 6\narr[] = {6, 8, 4, 5, 2, 3}",
"output": "604",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "N = 5\narr[] = {5, 3, 0, 7, 4}",
"output": "82",
"type": "stdin_stdout"
}
... |
taco | verifiable_code | https://codeforces.com/problemset/problem/618/C | Solve the following coding problem using the programming language python:
Cat Noku has obtained a map of the night sky. On this map, he found a constellation with n stars numbered from 1 to n. For each i, the i-th star is located at coordinates (xi, yi). No two stars are located at the same position.
In the evening N... | ```python
f = lambda : list(map(int, input().split()))
d = lambda x, y: (x[0] - y[0]) ** 2 + (x[1] - y[1]) ** 2
r = lambda x, y, z: (x[0] - y[0]) * (x[1] - z[1]) == (x[1] - y[1]) * (x[0] - z[0])
n = int(input())
t = [f() for i in range(n)]
j = k = -1
b = c = 0
x = t.pop()
for i in range(n - 1):
a = d(x, t[i])
if j < ... | vfc_143250 | {
"difficulty": "medium_hard",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/618/C",
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n0 0\n131072 0\n131072 131072\n200000 0\n",
"output": "1 2 3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n999999999 1\n999999998 1\n999999997 1\n1000000000 1\n999999996 1\n9999999... |
taco | verifiable_code | https://www.codechef.com/problems/DISTNEIGH | Solve the following coding problem using the programming language python:
You are given three positive integers N, x, and y.
Count the number of arrays P of length N such that:
P_{1} = P_{N} = 1
There are exactly x indices i such that P_{i}=1
There are exactly y indices i such that P_{i}=2
There are exactly N-x-y ind... | ```python
mod = 998244353
fact = [1]
for i in range(1, 2 * 10 ** 6 + 1):
fact.append(fact[-1] * i % mod)
def binom(a, b):
if a < b or b < 0:
return 0
num = fact[a]
den = fact[b] * fact[a - b] % mod
return num * pow(den, -1, mod) % mod
(n, one, two) = map(int, input().split())
three = n - one - two
ans = 0
for t... | vfc_143258 | {
"difficulty": "very_hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/DISTNEIGH",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 3 1\n",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 4 3\n",
"output": "44",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/117/A | Solve the following coding problem using the programming language python:
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first t... | ```python
(n, m) = map(int, input().split())
k = 2 * (m - 1)
for i in range(n):
(s, f, t) = map(int, input().split())
d = t % k
if s < f:
print(k * (s <= d) + f - 1 + t - d)
elif f < s:
print(k * (d + s > k + 1) + k + 1 - f + t - d)
else:
print(t)
``` | vfc_143262 | {
"difficulty": "easy",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/117/A",
"time_limit": "1.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 4\n2 4 7\n3 3 1\n2 2 9\n",
"output": "9\n1\n9\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8 5\n2 2 91\n5 1 97\n5 1 36\n5 4 19\n2 5 50\n4 2 1\n1 4 9\n3 2 32\n",
"output": "91\n1... |
taco | verifiable_code | https://www.codechef.com/problems/KINGSHIP | Solve the following coding problem using the programming language python:
Chef is the new king of the country Chefland. As first and most important responsibility he wants to reconstruct the road system of Chefland. There are N (1 to N) cities in the country and each city i has a population Pi. Chef wants to build som... | ```python
n = int(input())
for i in range(n):
l = []
t1 = int(input())
t2 = str(input()).split()
for item in t2:
l.append(int(item))
l.sort()
sum = 0
for i in range(1, len(l)):
sum = sum + l[0] * l[i]
print(sum)
``` | vfc_143266 | {
"difficulty": "easy",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/KINGSHIP",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n2\n5 10\n4\n15 10 7 13\n",
"output": "50\n266\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n2\n5 5\n4\n15 10 7 13",
"output": "25\n266\n",
"type": "stdin_stdout"
},... |
taco | verifiable_code | https://codeforces.com/problemset/problem/363/C | Solve the following coding problem using the programming language python:
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume t... | ```python
s = input().rstrip()
n = len(s)
stack = []
for ch in s:
if len(stack) <= 1 or not stack[-1] == stack[-2] == ch:
stack.append(ch)
s = ''.join(stack)
stack = []
for ch in s:
if len(stack) <= 2 or not (stack[-3] == stack[-2] and stack[-1] == ch):
stack.append(ch)
print(''.join(stack))
``` | vfc_143270 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/363/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "helloo\n",
"output": "hello\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "woooooow\n",
"output": "woow\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"i... |
taco | verifiable_code | Solve the following coding problem using the programming language python:
A fashion show rates participants according to their level of hotness. Two different fashion shows were organized, one for men and the other for women. A date for the third is yet to be decided ;) .
Now the results of both fashion shows are out... | ```python
t = eval(input())
for i in range(t):
n = eval(input())
men = list(map(int, list(input().strip().split(' '))))
women = list(map(int, list(input().strip().split(' '))))
men = sorted(men)
women = sorted(women)
p = 0
for i in range(len(men)):
p += men[i]*women[i]
print(p)
``` | vfc_143274 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "30\n647\n6 1 7 5 10 6 4 6 6 9 8 4 9 2 4 10 3 9 1 6 4 4 7 0 0 6 1 2 9 10 8 1 0 1 3 5 1 4 6 4 3 8 5 2 2 6 10 4 7 3 1 0 4 4 7 0 4 1 10 0 8 1 0 0 9 8 10 4 9 6 9 5 4 8 1 6 1 10 3 1 1 1 9 1 1 3 8 8 7 7 6 10 2 5 0 7 2 8 10 7 7 6 8 6 2 10 ... | |
taco | verifiable_code | Solve the following coding problem using the programming language python:
After the death of Meghnad and Kumbhakaran, Raavan got scared. He used his mind and presented a proposal of a war of numbers instead of Bow and arrows to Ram.
According to him, Laxman will select a number N, Raavan has to subtract a number whic... | ```python
t = eval(input())
for i in range(t):
x = list(map(int,input().split()))
p,k = (x[0],x[1])
ans = k + 1
for j in range(1,p+1):
print(ans*(j), end=' ')
print()
``` | vfc_143278 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n50 5000\n25 1\n25 10000",
"output": "5001 10002 15003 20004 25005 30006 35007 40008 45009 50010 55011 60012 65013 70014 75015 80016 85017 90018 95019 100020 105021 110022 115023 120024 125025",
"type": "stdin_stdout"... | |
taco | verifiable_code | https://codeforces.com/problemset/problem/832/D | Solve the following coding problem using the programming language python:
Misha and Grisha are funny boys, so they like to use new underground. The underground has n stations connected with n - 1 routes so that each route connects two stations, and it is possible to reach every station from any other.
The boys decide... | ```python
import os
import sys
from io import BytesIO, IOBase
from types import GeneratorType
from collections import defaultdict
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = 'x' in file.mode or 'r' not in file.mod... | vfc_143283 | {
"difficulty": "hard",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/832/D",
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 20\n5 5 1 4\n1 4 3\n2 4 1\n1 5 5\n5 1 4\n5 1 5\n1 5 5\n5 4 4\n2 3 3\n4 4 1\n1 4 1\n4 5 4\n1 4 5\n4 1 5\n2 4 2\n4 3 3\n2 5 5\n1 5 4\n3 3 4\n5 5 1\n3 4 1\n",
"output": "3\n3\n3\n2\n3\n3\n2\n3\n2\n2\n2\n2\n2\n3\n3\n2\n2\n3\n3\... |
taco | verifiable_code | Solve the following coding problem using the programming language python:
D --Invisible
Problem Statement
You are trying to play a card game called "Invisible" with your friends. This card game uses two types of cards, a "scoring card" and a "jamming card". A positive value is written on each score card. The rules o... | ```python
(n, m) = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
memo = dict()
def calc(A, i):
if A[i] != -1:
return 0
point = 0
for j in range(i - 1, -1, -1):
if A[j] == -1:
break
point += A[j]
return point
def dfs(a, b, skip, turn, a_stack... | vfc_143291 | {
"difficulty": "unknown_difficulty",
"memory_limit": "536.870912 megabytes",
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "8.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 2\n100 -1\n200 62",
"output": "38\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 2\n110 -1\n200 62",
"output": "48\n",
"type": "stdin_stdout"
},
{
"fn_name":... | |
taco | verifiable_code | Solve the following coding problem using the programming language python:
In 20XX, the Aizu Chuo Road, which has a total distance of 58km and 6 sections from Atsushiokanomachi, Kitakata City to Minamiaizucho, is scheduled to be completed and opened.
For half a year after opening, the toll will be halved for vehicles ... | ```python
import sys, math, os, bisect
PYDEV = os.environ.get('PYDEV')
if PYDEV == 'True':
sys.stdin = open('sample-input.txt', 'rt')
M = [[0, 300, 500, 600, 700, 1350, 1650], [6, 0, 350, 450, 600, 1150, 1500], [13, 7, 0, 250, 400, 1000, 1350], [18, 12, 5, 0, 250, 850, 1300], [23, 17, 10, 5, 0, 600, 1150], [43, 37, 30... | vfc_143299 | {
"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": "2\n17 25\n4\n17 45\n4\n17 25\n7\n1 35\n0",
"output": "250\n1300\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n19 25\n4\n17 37\n4\n17 47\n7\n0 63\n0",
"output": "250\n650\n",
... | |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/maximum-gcd-of-siblings-of-a-binary-tree/1 | Solve the following coding problem using the programming language python:
Given a 2d list that represents the nodes of a Binary tree with N nodes, the task is to find the maximum GCD of the siblings of this tree without actually constructing it.
Note: If there are no pairs of siblings in the given tree, print 0. Also,... | ```python
import math
class Solution:
def maxBinTreeGCD(self, arr, N):
possible_pairs = []
arr.sort()
ans = 0
for i in range(len(arr) - 1):
if arr[i][0] == arr[i + 1][0]:
ans = max(ans, math.gcd(arr[i][1], arr[i + 1][1]))
i += 1
else:
continue
return ans
``` | vfc_143303 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/maximum-gcd-of-siblings-of-a-binary-tree/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N = 7\narr = {{4, 5}, {4, 2}, {2, 3}, {2, 1}, {3, 6}, {3, 12}}",
"output": "6",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Nate U. Smith runs a railroad company in a metropolitan area. In addition to his railroad company, there are rival railroad companies in this metropolitan area. The two companies are in a competitive relationship with each other.
In this metrop... | ```python
m = int(input())
while m:
m -= 1
(ax, ay, bx, by) = map(int, input().split())
n = int(input())
(dx, dy) = (bx - ax, by - ay)
intersections = set()
while n:
n -= 1
(sx, sy, tx, ty, o, l) = map(int, input().split())
(tdx, tdy) = (tx - sx, ty - sy)
(asx, asy) = (sx - ax, sy - ay)
denom = dx * tdy... | vfc_143304 | {
"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": "2\n-10 1 10 1\n4\n-6 2 -2 -2 0 1\n-6 -2 -2 2 1 0\n6 2 2 -2 0 0\n6 -2 2 2 1 1\n8 12 -7 -3\n8\n4 -5 4 -2 1 1\n4 -2 4 9 1 0\n6 9 6 14 1 1\n-5 6 7 6 0 0\n1 0 1 10 0 0\n-5 0 -5 10 0 1\n-7 0 7 0 0 1\n-1 0 -1 -5 0 1",
"output": "1\n... | |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/remove-duplicates3034/1 | Solve the following coding problem using the programming language python:
Given a string without spaces, the task is to remove duplicates from it.
Note: The original order of characters must be kept the same.
Example 1:
Input: S = "zvvo"
Output: "zvo"
Explanation: Only keep the first
occurrence
Example 2:
Input: S =... | ```python
class Solution:
def removeDups(self, string):
p = ''
for char in string:
if char not in p:
p = p + char
return p
``` | vfc_143308 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/remove-duplicates3034/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "S = \"zvvo\"",
"output": "\"zvo\"",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
There is Kannon-do in the mountain behind Ichiro's house. There are 30 steps from the foot to this Kannon-do, and Ichiro goes to Kannon-do almost every day. Ichiro can go up the stairs up to 3 steps with one foot. While playing, I noticed that t... | ```python
import sys
n = 30
f = [1, 1, 2, 4]
while len(f) <= n:
f.append(f[-1] + f[-2] + f[-3])
while True:
n = int(input())
if n == 0:
sys.exit()
day = f[n]
if day % 3650 == 0:
print(int(day / 3650))
else:
print(int(day / 3650) + 1)
``` | vfc_143309 | {
"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\n10\n14\n25\n0",
"output": "1\n1\n1\n701\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n10\n14\n23\n0",
"output": "1\n1\n1\n207\n",
"type": "stdin_stdout"
}
]
} | |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/length-of-last-word5721/1 | Solve the following coding problem using the programming language python:
Given a string S consisting of upper/lower-case alphabets and empty space characters ‘ ‘. The string may contain spaces at the end. You will have return the length of last word which consists of alphabets only.
Example 1:
Input:
S = "Geeks for G... | ```python
class Solution:
def findLength(self, s):
n = len(s)
count = 0
for i in range(n - 1, -1, -1):
if s[i] == ' ' and count > 0:
return count
elif s[i] != ' ':
count += 1
return count
``` | vfc_143313 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/length-of-last-word5721/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "S = \"Geeks for Geeks\"",
"output": "5",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "S = \"Start Coding Here \"",
"output": "4",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1430/G | Solve the following coding problem using the programming language python:
You are given a directed acyclic graph (a directed graph that does not contain cycles) of n vertices and m arcs. The i-th arc leads from the vertex x_i to the vertex y_i and has the weight w_i.
Your task is to select an integer a_v for each ver... | ```python
from heapq import heappush, heappop
class MinCostFlow:
INF = 10 ** 18
def __init__(self, N):
self.N = N
self.G = [[] for i in range(N)]
def add_edge(self, fr, to, cap, cost):
forward = [to, cap, cost, None]
backward = forward[3] = [fr, 0, -cost, forward]
self.G[fr].append(forward)
self.G[to]... | vfc_143314 | {
"difficulty": "very_hard",
"memory_limit": "1024.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1430/G",
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "18 27\n3 16 55467\n17 11 829\n5 12 15831\n14 6 24056\n5 2 63216\n15 6 38762\n2 6 10654\n12 6 51472\n11 9 79384\n1 6 67109\n5 13 86794\n7 6 74116\n10 3 44030\n5 7 71499\n16 17 33019\n5 14 54625\n9 6 10151\n5 10 3514\n5 1 92436\n13 6... |
taco | verifiable_code | https://codeforces.com/problemset/problem/918/B | Solve the following coding problem using the programming language python:
As the guys fried the radio station facilities, the school principal gave them tasks as a punishment. Dustin's task was to add comments to nginx configuration for school's website. The school has n servers. Each server has a name and an ip (name... | ```python
(n, m) = map(int, input().split())
a = []
b = []
ans = []
p = []
for i in range(n):
(c, d) = map(str, input().split())
d += ';'
a.append(c)
a.append(d)
for i in range(m):
b.append(list(map(str, input().split())))
for i in range(m):
p.append(b[i][0])
p.append(b[i][1])
p.append('#' + a[a.index(b[i][1]) ... | vfc_143322 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/918/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 2\nmain 192.168.0.2\nreplica 192.168.0.1\nblock 192.168.0.1;\nproxy 192.168.0.2;\n",
"output": "block 192.168.0.1; #replica\nproxy 192.168.0.2; #main\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
taco | verifiable_code | https://www.hackerrank.com/challenges/mehta-and-his-laziness/problem | Solve the following coding problem using the programming language python:
Mehta is a very lazy boy. He always sleeps in Maths class. One day his teacher catches him sleeping and tells him that she would mark him absent for the whole semester. While she pretends to be strict, she is actually very kind-hearted. So she w... | ```python
import fractions
def primes(n):
primfac = {}
d = 2
while d * d <= n:
while n % d == 0:
if d in primfac:
primfac[d] += 1
else:
primfac[d] = 1
n /= d
d += 1
if n > 1:
if n in primfac:
primfac[n] += 1
else:
primfac[n] = 1
return primfac
def numf(n):
prod = 1
dictx = primes... | vfc_143327 | {
"difficulty": "medium_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.hackerrank.com/challenges/mehta-and-his-laziness/problem",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n2\n8\n36\n900\n",
"output": "0\n1/3\n1/8\n3/26\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/ELEVATR | Solve the following coding problem using the programming language python:
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef's apartment consists of $M$ floors (numbered $1$ through $M$), and there's an elevator that is used to move between different floors. T... | ```python
T = int(input())
for _ in range(T):
(n, m) = map(int, input().split())
v = list(map(int, input().split()))
ans = 2000000000.0
xx = 2
for pp in range(2):
lpoz = -1
sw = 0
prev = v[0]
dir = True
if prev == -1:
prev = 1
else:
lpoz = 0
for i in range(1, n):
if v[i] != -1:
j = lpoz
... | vfc_143331 | {
"difficulty": "very_hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/ELEVATR",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n4 5\n2 3 4 3\n4 5\n2 -1 4 3\n4 5\n1 -1 -1 5\n5 4\n-1 -1 3 -1 -1\n5 5\n-1 -1 3 -1 -1\n",
"output": "1\n1\n-1\n1\n0\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1560/B | Solve the following coding problem using the programming language python:
Some number of people (this number is even) have stood in a circle. The people stand in the circle evenly. They are numbered clockwise starting from a person with the number $1$. Each person is looking through the circle's center at the opposite... | ```python
for _ in range(int(input())):
(a, b, c) = map(int, input().split())
maxi = abs(a - b) * 2
if maxi >= a and maxi >= b and (maxi >= c) and (abs(a - b) > 1):
if c > abs(a - b):
print(abs(c - abs(a - b)))
else:
print(c + abs(a - b))
else:
print(-1)
``` | vfc_143336 | {
"difficulty": "easy",
"memory_limit": "256 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1560/B",
"time_limit": "1 second"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7\n6 2 4\n2 3 1\n2 4 10\n5 3 4\n1 3 2\n2 5 4\n4 3 2\n",
"output": "8\n-1\n-1\n-1\n4\n1\n-1\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/717/B | Solve the following coding problem using the programming language python:
R3D3 spent some time on an internship in MDCS. After earning enough money, he decided to go on a holiday somewhere far, far away. He enjoyed suntanning, drinking alcohol-free cocktails and going to concerts of popular local bands. While listenin... | ```python
import sys, heapq
input = sys.stdin.readline
(n, a, b) = map(int, input().split())
if a < b:
(a, b) = (b, a)
if b == 0:
print((n - 1) * a)
else:
pascal = [[1] * 20005]
for i in range(20004):
newrow = [1]
for j in range(1, 20005):
newrow.append(newrow[-1] + pascal[-1][j])
if newrow[-1] > n:
b... | vfc_143340 | {
"difficulty": "very_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/717/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 1 2\n",
"output": "12\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1144/E | Solve the following coding problem using the programming language python:
You are given two strings $s$ and $t$, both consisting of exactly $k$ lowercase Latin letters, $s$ is lexicographically less than $t$.
Let's consider list of all strings consisting of exactly $k$ lowercase Latin letters, lexicographically not l... | ```python
def plus(a, b):
c = ''
i = len(a) - 1
arg = 0
while i >= 0:
k = arg + ord(a[i]) + ord(b[i]) - 194
arg = 1
if k < 26:
arg = 0
i -= 1
c = chr(k % 26) + c
c = chr(1) * arg + c
return c
def minus(a):
c = ''
i = 0
arg = 0
while i < len(a):
c += chr((arg * 26 + ord(a[i])) // 2)
arg = ord... | vfc_143344 | {
"difficulty": "hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1144/E",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\naz\nbf\n",
"output": "bc\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\nafogk\nasdji\n",
"output": "alvuw\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.hackerrank.com/challenges/tutzki-and-lcs/problem | Solve the following coding problem using the programming language python:
Given two strings, $a$ and $\boldsymbol{b}$, find and print the total number of ways to insert a character at any position in string $\class{ML__boldsymbol}{\boldsymbol{a}}$ such that the length of the Longest Common Subsequence of characters in... | ```python
import string
def lcs(s1, s2):
n = len(s1)
m = len(s2)
dp = [[0 for _ in range(m + 1)] for _ in range(n + 1)]
for i in range(n):
for j in range(m):
if s1[i] == s2[j]:
dp[i + 1][j + 1] = dp[i][j] + 1
else:
dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j])
return dp
def alpIndexes(s, alp... | vfc_143348 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.hackerrank.com/challenges/tutzki-and-lcs/problem",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "aa\nbaaa\n",
"output": "4\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/b6b3297ccfb1ad5f66a9c2b92979170417adf114/1 | Solve the following coding problem using the programming language python:
Professor McGonagall teaches transfiguration at Hogwarts. She has given Harry the task of changing himself into a cat. She explains that the trick is to analyze your own DNA and change it into the DNA of a cat. The transfigure spell can be used ... | ```python
class Solution:
def transfigure(self, A, B):
m = {}
n = len(A)
for i in range(n):
if A[i] in m:
m[A[i]] += 1
else:
m[A[i]] = 1
for i in range(n):
if B[i] in m:
m[B[i]] -= 1
for key in m:
if m[key] != 0:
return -1
(i, j) = (n - 1, n - 1)
res = 0
while i >= 0 and j ... | vfc_143352 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/b6b3297ccfb1ad5f66a9c2b92979170417adf114/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "A = \"GEEKSFORGEEKS\" \nB = \"FORGEEKSGEEKS\"",
"output": "3",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.hackerrank.com/challenges/sherlock-and-minimax/problem | Solve the following coding problem using the programming language python:
Watson gives Sherlock an array of integers. Given the endpoints of an integer range, for all $M$ in that inclusive range, determine the minimum( abs(arr[i]-M) for all $1\leq i\leq|arr|$) ). Once that has been determined for all integers in the... | ```python
N = int(input())
A = [int(c) for c in input().split()[:N]]
(P, Q) = [int(c) for c in input().split()[:2]]
a = sorted(A)
max_point = P
max_distance = min((abs(i - P) for i in a))
for i in range(len(a) - 1):
if a[i] > Q or a[i + 1] < P:
continue
m = int((a[i] + a[i + 1]) / 2)
if m < P:
point = P
distan... | vfc_143358 | {
"difficulty": "medium_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.hackerrank.com/challenges/sherlock-and-minimax/problem",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n5 8 14\n4 9\n",
"output": "4\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1550/D | Solve the following coding problem using the programming language python:
Let's call an integer array $a_1, a_2, \dots, a_n$ good if $a_i \neq i$ for each $i$.
Let $F(a)$ be the number of pairs $(i, j)$ ($1 \le i < j \le n$) such that $a_i + a_j = i + j$.
Let's say that an array $a_1, a_2, \dots, a_n$ is excellent i... | ```python
import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
M = 10 ** 9 + 7
MAX = 10 ** 6 + 1
factor = [1] * MAX
for i in range(1, MAX):
factor[i] = factor[i - 1] * i % M
def fastfrac(a, b, M):
numb = pow(b, M - 2, M)
return a % M * (numb % M) % M
def comb(m, n):
if n < 0 or m < 0:
retu... | vfc_143371 | {
"difficulty": "hard",
"memory_limit": "256 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1550/D",
"time_limit": "2 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n3 0 3\n4 -3 5\n42 -33 55\n69 -42 146\n",
"output": "4\n10\n143922563\n698570404\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n20000 -431912570 597469643\n20000 -13928452 414987414... |
taco | verifiable_code | https://www.codechef.com/CRES2016/problems/CRES104 | Solve the following coding problem using the programming language python:
There is crazy man named P29892P. He always tries to do crazy things as he thinks. One day he invented a machine and named it as ANGEN. The ANGEN is used to perform range operations. The range operation means performing operations on range value... | ```python
VQ = 'UAMmSs'
n = int(input())
a = list(map(int, input().split()))
for _ in range(int(input())):
(q, x, y) = input().split()
if q not in VQ:
print('!!!')
continue
if q == 'U':
a[int(x) - 1] = int(y)
continue
l = int(x) - 1
r = int(y)
if q == 'A':
print(sum(a[l:r]))
continue
if q == 'M':
p... | vfc_143379 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/CRES2016/problems/CRES104",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n1 2 5 3 10 6\n6\nA 1 5\nM 1 3\nm 5 6\ns 3 6\nU 1 7\nS 1 2\n",
"output": "21\n5\n6\n5\n2\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Rajesh has been challenge by his friend to find the number which have properties like,
Here take no 12 such that
square of 12(12*12)=144
and 21 which is reverse of 12 have square(21*21)= 441 whose reverse is equal to 144
and now Rajesh is no... | ```python
t=eval(input())
for i in range(t):
n=input()
a=int(n)
#print a
b=n[::-1]
#print b
c=int(b)
#print c
if n!=b:
d=a**2
#print d
e=c**2
#print e
f=str(d)
g=str(e)
h=g[::-1]
#print h
if f==h:
print(b)
else:
print("No")
else:
print("No")
``` | vfc_143383 | {
"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\n102\n211\n221\n301\n311\n115\n12\n31\n201\n211\n221\n1003\n1012\n1013\n99\n8888\n10000\n3111\n2111\n0000\n19\n20\n333\n545\n1112",
"output": "221\n311\n2001\n1101\n1201\n1301\nNo\n2022\nNo\nNo\nNo\n301\n13\n311\n1122\n100... | |
taco | verifiable_code | https://www.hackerrank.com/challenges/two-two/problem | Solve the following coding problem using the programming language python:
Prof. Twotwo as the name suggests is very fond powers of 2. Moreover he also has special affinity to number 800. He is known for carrying quirky experiments on powers of 2.
One day he played a game in his class. He brought some number plates on... | ```python
tree = [False, {}]
def add(word):
current = tree
for c in word:
try:
current = current[1][c]
except KeyError:
current[1][c] = [False, {}]
current = current[1][c]
current[0] = True
def count(word):
count = 0
for start in range(len(word)):
(current, index) = (tree, start)
while True:
... | vfc_143387 | {
"difficulty": "hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.hackerrank.com/challenges/two-two/problem",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n2222222\n24256\n65536\n023223\n33579\n",
"output": "7\n4\n1\n4\n0\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/PYRAMIDMOVES | Solve the following coding problem using the programming language python:
You are given a pyramid of the following form with an infinite number of rows:
1
2\ 3
4\ 5\ 6
7\ 8\ 9\ 10
...........
From a cell, you can move to either the bottom-left cell or the bottom-right cell directly in contact with the current one (... | ```python
import math
MOD7 = pow(10, 9) + 7
MAXF = pow(10, 5)
my_list = [0] * (MAXF + 1)
def last(l):
return (l + 1) * l / 2
def get_level_and_index(n):
idx = -1
line = -1
if n == 1:
return (1, 1)
left = 2
right = 1 + math.floor(math.sqrt(2 * n))
while left <= right:
line = int((left + right) / 2)
if las... | vfc_143391 | {
"difficulty": "hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/PYRAMIDMOVES",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n2 7\n1 5\n5 3",
"output": "1\n2\n0",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/722/B | Solve the following coding problem using the programming language python:
You are given a text consisting of n lines. Each line contains some space-separated words, consisting of lowercase English letters.
We define a syllable as a string that contains exactly one vowel and any arbitrary number (possibly none) of con... | ```python
from collections import Counter
input()
for p in map(int, input().split()):
C = Counter(input())
if sum((C[v] for v in 'aeiouy')) != p:
print('NO')
break
else:
print('YES')
``` | vfc_143395 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/722/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n2 2 3\nintel\ncode\nch allenge\n",
"output": "YES\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/check-if-a-number-is-power-of-another-number5442/1 | Solve the following coding problem using the programming language python:
Given two positive numbers X and Y, check if Y is a power of X or not.
Example 1:
Input:
X = 2, Y = 8
Output:
1
Explanation:
2^{3} is equal to 8.
Example 2:
Input:
X = 1, Y = 8
Output:
0
Explanation:
Any power of 1 is not
equal to 8.
Your... | ```python
from math import pow, log
class Solution:
def isPowerOfAnother(ob, X, Y):
if X == 0 or X == 1:
return 0
else:
m = log(Y, X)
m = round(m)
if X ** m == Y:
return 1
return 0
``` | vfc_143399 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/check-if-a-number-is-power-of-another-number5442/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "X = 2, Y = 8",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "X = 1, Y = 8",
"output": "0",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/MAXAGRY | Solve the following coding problem using the programming language python:
Alice and Bob were playing a game yet again but this time, Bob already lost the game. Now he wants to take revenge.
Bob saw a jigsaw puzzle which was solved by Alice and decided to jumble the puzzle pieces again. There are N puzzle pieces in a ... | ```python
for _ in range(int(input())):
(n, k) = map(int, input().split())
total = 0
if k >= n // 2:
print(n * (n - 1) // 2)
continue
else:
total += n * (n - 1) // 2
total -= (n - k) * (n - k - 1) // 2
total += (n - 2 * k) * k
total += k * (k - 1) // 2
print(total)
``` | vfc_143404 | {
"difficulty": "medium",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/MAXAGRY",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n7 3\n1 4\n8 2\n5 3\n",
"output": "21\n0\n22\n10\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Do you know the famous series of children's books named "Where's Wally"? Each of the books contains a variety of pictures of hundreds of people. Readers are challenged to find a person called Wally in the crowd.
We can consider "Where's Wally" ... | ```python
import string
import sys
S = string.ascii_uppercase + string.ascii_lowercase + string.digits + '+/'
mod = 10 ** 9 + 9
p = 13
q = 19
L = 1000
p_table = [1] * (L + 1)
q_table = [1] * (L + 1)
for i in range(L):
p_table[i + 1] = p_table[i] * p % mod
q_table[i + 1] = q_table[i] * q % mod
readline = sys.stdin.rea... | vfc_143408 | {
"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": "48 3 3\ngAY4I4wA\ngIIgIIgg\nw4IAYAg4\ng\ng\nw\n153 3 3\nkkkkkkkkkkkkkkkkkkkkkkkkkg\nSSSSSSSSSSSSSSSSSSSSSSSSSQ\nJJJJJJJJJJJJJJJJJJJJJJJJJI\ng\nQ\nJ\n1 1 2\nA\nA\nA\n384 3 2\nABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234... | |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/12-hour-clock-subtraction1708/1 | Solve the following coding problem using the programming language python:
Given two positive integers num1 and num2, subtract num2 from num1 on a 12 hour clock rather than a number line.
Note: Assume the Clock starts from 0 hour to 11 hours.
Example 1:
Input:
num1 = 7, num2 = 5
Output:
2
Explanation:
7-5 = 2. The ti... | ```python
class Solution:
def subClock(self, num1, num2):
return (num1 - num2) % 12
``` | vfc_143412 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/12-hour-clock-subtraction1708/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "num1 = 7, num2 = 5",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "num1 = 5, num2 = 7",
"output": "10",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/COMT2020/problems/ROOTSQR | Solve the following coding problem using the programming language python:
Raju has created a program to find the square root of a number. But his program can store only integers. Being a newbie, he didn't know about rounding the numbers. Hence his program returns the absolute value of the result if possible. For examp... | ```python
try:
from math import sqrt
(t, x) = list(map(int, input().split()))
for _ in range(t):
n = int(input())
if n < 0:
print('no')
else:
diff = x / 100 * n
ans = int(sqrt(n))
ans1 = ans ** 2
if n - ans1 <= diff:
print('yes')
else:
print('no')
except:
pass
``` | vfc_143418 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/COMT2020/problems/ROOTSQR",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 20\n5\n3\n",
"output": "yes\nno\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/SEAPERM | Solve the following coding problem using the programming language python:
Read problems statements in Mandarin Chinese and Russian.
Sereja have array A' that contain N integers. Now Sereja want to permute elements of the array, he want to use some permutation p, such that A[i] = A'[p[i]], where A - new array.
Le... | ```python
import sys
for j in range(int(sys.stdin.readline())):
(n, k, s) = map(int, sys.stdin.readline().split())
m = list(map(int, sys.stdin.readline().split()))
if n == 3 and k == 2 and (s == 4):
print(2, 1, 3)
continue
if n == 4 and k == 4 and (s == 1):
print(4, 3, 2, 1)
continue
[print(i[0] + 1, end='... | vfc_143423 | {
"difficulty": "very_hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/SEAPERM",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n3 2 4\n3 4 1\n4 4 1\n1 1 1 1",
"output": "2 1 3\n4 3 2 1",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/smallest-power-of-2-greater-than-or-equal-to-n2630/1 | Solve the following coding problem using the programming language python:
Given a number N.Find the nearest number which is a power of 2 and greater than or equal to N.
Example 1:
Input:
N = 1
Output:
1
Explanation:
The nearest power of 2 greater than or
equal to 1 is 2^0=1.
Example 2:
Input:
N = 5
Output:
8
Explanat... | ```python
class Solution:
def nearestPowerOf2(self, N):
count = 0
n = N
if n & n - 1 == 0:
return N
while n != 0:
count += 1
n >>= 1
return 1 << count
``` | vfc_143427 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/smallest-power-of-2-greater-than-or-equal-to-n2630/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N = 1",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "N = 5",
"output": "8",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/595/B | Solve the following coding problem using the programming language python:
Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consists of exactly n digits.
Also Pasha has a number k and two sequences of length n / k (n is divisible by k) a_1, a_2, ..., a... | ```python
import sys
(n, k) = sys.stdin.readline().split()
n = int(n)
k = int(k)
a = [int(x) for x in sys.stdin.readline().split()]
b = [int(x) for x in sys.stdin.readline().split()]
MOD = 10 ** 9 + 7
res = 1
for i in range(0, n // k):
lo = b[i] * 10 ** (k - 1) - 1
up = (b[i] + 1) * 10 ** (k - 1) - 1
tmp = (10 ** k ... | vfc_143429 | {
"difficulty": "medium_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/595/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6 2\n38 56 49\n7 3 4\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8 2\n1 22 3 44\n5 4 3 2\n",
"output": "32400\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/909/F | Solve the following coding problem using the programming language python:
Given an integer N, find two permutations: Permutation p of numbers from 1 to N such that p_{i} ≠ i and p_{i} & i = 0 for all i = 1, 2, ..., N. Permutation q of numbers from 1 to N such that q_{i} ≠ i and q_{i} & i ≠ 0 for all i = 1, 2, ..., N... | ```python
def test(x, i):
i = list(i)
ok = True
for j in range(x):
if i[j] == j + 1 or i[j] & j + 1 != 0:
ok = False
if ok:
print(i)
def comp(n):
return 2 ** len(bin(n)[2:]) - 1 - n
n = int(input())
nn = n
if n % 2 == 0:
x = []
while n != 0:
for i in range(comp(n), n + 1):
x.append(i)
n = comp(n) ... | vfc_143438 | {
"difficulty": "very_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/909/F",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n",
"output": "NO\nNO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n",
"output": "YES\n6 5 4 3 2 1 \nYES\n3 6 2 5 1 4\n",
"type": "stdin_stdout"
},
{
"fn_n... |
taco | verifiable_code | https://codeforces.com/problemset/problem/1203/A | Solve the following coding problem using the programming language python:
There are $n$ students standing in a circle in some order. The index of the $i$-th student is $p_i$. It is guaranteed that all indices of students are distinct integers from $1$ to $n$ (i. e. they form a permutation).
Students want to start a r... | ```python
import sys
def solve(n, pn):
if n == 1:
return 'YES'
count = 0
if pn[0] > pn[n - 1]:
count = 1
for i in range(1, n):
if pn[i] > pn[i - 1]:
count += 1
if count == 1 or count == n - 1:
return 'YES'
else:
return 'NO'
q = int(input())
for _ in range(q):
n = int(input())
pn = list(map(int, sy... | vfc_143446 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1203/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n4\n1 2 3 4\n3\n1 3 2\n5\n1 2 3 5 4\n1\n1\n5\n3 2 1 5 4\n",
"output": "YES\nYES\nNO\nYES\nYES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n12\n12 3 4 5 6 7 8 9 10 11 1 2\n",
... |
taco | verifiable_code | https://www.codechef.com/MAY12/problems/CHEFLUCK | Solve the following coding problem using the programming language python:
Every great chef knows that lucky numbers are positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Our chef has recently returned from the Luc... | ```python
import sys
import os
def __starting_point():
start = 0
for line in sys.stdin:
if start == 0:
start = 1
continue
else:
try:
n = int(line.strip())
q = n / 7
rem = n % 7
if rem == 0:
res = n
elif rem == 1:
res = (q - 1) * 7
elif rem == 2:
res = (q - 2) * 7
... | vfc_143450 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/MAY12/problems/CHEFLUCK",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n7\n4\n11\n1\n15\n\n\n",
"output": "7\n0\n7\n-1\n7\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/712/B | Solve the following coding problem using the programming language python:
Memory is performing a walk on the two-dimensional plane, starting at the origin. He is given a string s with his directions for motion: An 'L' indicates he should move one unit left. An 'R' indicates he should move one unit right. A 'U' indic... | ```python
s = input()
if len(s) % 2 == 1:
print(-1)
else:
hor = 0
ver = 0
for direction in s:
if direction == 'R':
hor += 1
elif direction == 'L':
hor -= 1
elif direction == 'U':
ver += 1
else:
ver -= 1
print((abs(hor) + abs(ver)) // 2)
``` | vfc_143454 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/712/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "RRU\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "UDUR\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Arjit, Protector of The Realm, has an important task at hand. M new subjects are soon going to become a part of The Realm. The Realm, though, already has N subjects who are well skilled in the ways of The Realm. He wants the new subjects too to ... | ```python
from collections import defaultdict
import heapq
t = int(input())
ans = []
while t:
t = t - 1
m,n = list(map(int, input().split()))
st = defaultdict(list)
pr = defaultdict(list)
while m:
m = m - 1
u,v = list(map(int, input().split()))
heapq.heappush(st[u], v)
while n:
n = n - 1
u,v = list(ma... | vfc_143458 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10\n87 45\n20 17\n17 50\n22 21\n22 80\n94 67\n69 78\n90 22\n92 85\n76 82\n47 17\n63 19\n97 14\n72 15\n75 36\n94 61\n81 65\n30 49\n67 51\n21 40\n31 15\n6 51\n44 96\n24 35\n32 51\n17 78\n19 79\n48 67\n44 19\n81 19\n55 27\n31 87\n43 6... | |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/sum-equals-to-sum4006/1 | Solve the following coding problem using the programming language python:
Given an array A of N integers. The task is to find if there are two pairs (a, b) and (c, d) such that a+b = c+d.
Example 1:
Input:N=7 A[] = {3, 4, 7, 1, 2, 9, 8} Output: 1Explanation:(3, 7) and (9, 1) are the pairs whosesum are equal.
Example... | ```python
class Solution:
def findPairs(self, arr, n):
l = []
for i in range(len(arr)):
for j in range(i + 1, len(arr)):
sum = arr[i] + arr[j]
if sum in l:
return 1
else:
l.append(sum)
else:
return 0
``` | vfc_143463 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/sum-equals-to-sum4006/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N=7 A[] = {3, 4, 7, 1, 2, 9, 8}",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "N=7 A[] = {65, 30, 7, 90, 1, 9, 8}",
"output": "0",
"type": "stdin_stdout"
}
... |
taco | verifiable_code | Solve the following coding problem using the programming language python:
I have a lot of friends. Every friend is very small.
I often go out with my friends. Put some friends in your backpack and go out together.
Every morning I decide which friends to go out with that day. Put friends one by one in an empty backpack... | ```python
import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 13
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (... | vfc_143468 | {
"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": "6 37\n5\n9\n24\n18\n26\n33",
"output": "6\n",
"type": "stdin_stdout"
}
]
} | |
taco | verifiable_code | https://codeforces.com/problemset/problem/1725/B | Solve the following coding problem using the programming language python:
A basketball competition is held where the number of players in a team does not have a maximum or minimum limit (not necessarily $5$ players in one team for each match). There are $N$ candidate players in the competition that will be trained by ... | ```python
def solve():
(n, d) = map(int, input().split())
a = sorted([*map(int, input().split())])[::-1]
(i, j, r) = (0, len(a), 0)
while i < j:
x = a[i]
while x <= d:
j -= 1
if i < j:
x += a[i]
else:
return r
else:
r += 1
i += 1
return r
print(solve())
``` | vfc_143472 | {
"difficulty": "easy",
"memory_limit": "256 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1725/B",
"time_limit": "1 second"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6 180\n90 80 70 60 50 100\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 4\n1 2\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": nu... |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/check-for-three-consecutive-numbers5729/1 | Solve the following coding problem using the programming language python:
Given an integer n, the task is to find whether n can be written as sum of three consecutive integer.
Example 1:
Input: n = 6
Output: 1 2 3
Explanation: 6 = 1+2+3
Hence 6 can be written as sum of
three consecutive integer.
Example 2:
Input: n ... | ```python
class Solution:
def consecutiveSum(self, n):
if n % 3 != 0:
return [-1]
a = n // 3
return [a - 1, a, a + 1]
``` | vfc_143476 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/check-for-three-consecutive-numbers5729/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "n = 6",
"output": "1 2 3",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Chef and Jhool went to a party, and both decided to play a game. The game is simple, both Chef and Jhool will eat the dishes served at the party till they are full, and the one who eats maximum number of dishes is the winner. However, both of... | ```python
t=int(input())
for I in range(t):
x,y,n=list(map(int,input().split()))
ar=list(map(int,input().split()))
ar=sorted(ar)
sumx=0
sumy=0
cx=0
cy=0
for I in ar:
if sumx<=x and sumx+I<=x:
sumx=sumx+I
cx=cx+1
for I in ar:
if sumy<=y and sumy+I<=y:
sumy=sumy+I
cy=cy+1
#print cx,cy ... | vfc_143477 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "100\n99999 97599 1000\n96 100 91 96 92 92 98 96 95 95 99 93 99 99 95 98 93 94 99 96 98 97 98 98 99 94 92 95 93 94 99 92 91 98 93 91 95 96 97 99 98 97 97 96 99 99 97 92 93 96 98 93 93 91 97 99 91 92 94 95 100 98 92 94 100 98 96 92 9... | |
taco | verifiable_code | https://www.codechef.com/problems/SUBPRNJL | Solve the following coding problem using the programming language python:
"It does not matter how slowly you go as long as you do not stop." - Confucius
You are given an array $A_1, A_2, \ldots, A_N$ and an integer $K$. For each subarray $S = [A_l, A_{l+1}, \ldots, A_r]$ ($1 \le l \le r \le N$):
- Let's define an arra... | ```python
import bisect
import math
t = int(input())
while t > 0:
fp = 0
(n, k) = map(int, input().split())
a = [int(o) for o in input().split()]
for i in range(n):
left = []
arr = [0] * 2050
for j in range(i, n):
right = a[j]
bisect.insort(left, right)
arr[a[j]] += 1
uhoy = math.ceil(k / (j - i +... | vfc_143481 | {
"difficulty": "hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/SUBPRNJL",
"time_limit": "2 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n3 3\n1 2 3\n",
"output": "3\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/expression-add-operators/1 | Solve the following coding problem using the programming language python:
Given a string S that contains only digits (0-9) and an integer target, return all possible strings to insert the binary operator ' + ', ' - ', or ' * ' between the digits of S so that the resultant expression evaluates to the target value.
Note... | ```python
class Solution:
def solve(self, ind, S, target, evalu, ans, res, mul):
if ind == len(S):
if evalu == target:
res.append(ans)
return
for i in range(ind, len(S)):
if ind != i and S[ind] == '0':
break
cur = int(S[ind:i + 1])
if ind == 0:
self.solve(i + 1, S, target, cur, ans + st... | vfc_143485 | {
"difficulty": "medium_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/expression-add-operators/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "S = \"123\"\r\ntarget = 6",
"output": "{ \"1*2*3\", \"1+2+3\"}",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/HOLES | Solve the following coding problem using the programming language python:
Chef wrote some text on a piece of paper and now he wants to know how many holes are in the text. What is a hole? If you think of the paper as the plane and a letter as a curve on the plane, then each letter divides the plane into regions. For e... | ```python
for i in range(int(input())):
x = input()
h1 = 'ADOPQR'
h0 = 'CEFGHIJKLMNSTUVWXYZ'
h2 = 'B'
h = 0
for i in x:
if i in h1:
h += 1
elif i in h2:
h += 2
print(h)
``` | vfc_143486 | {
"difficulty": "easy",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/HOLES",
"time_limit": "0.71 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\nCODECHEF\nDRINKEATCODE",
"output": "2\n5",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\nFEHCEDOC\nDRINKEATCODE",
"output": "2\n5\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/337/A | Solve the following coding problem using the programming language python:
The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her n students and give each of them a jigsaw puzzle (which, as wikipedia states, ... | ```python
(n, m) = list((int(a) for a in input().split()))
p = list((int(a) for a in input().split()))
p.sort()
mn = p[n - 1] - p[0]
for i in range(1, m - n + 1):
t = p[n + i - 1] - p[i]
if t < mn:
mn = t
print(mn)
``` | vfc_143490 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/337/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 6\n10 12 10 7 5 22\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 2\n4 4\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
taco | verifiable_code | Solve the following coding problem using the programming language python:
In the year 2xxx, an expedition team landing on a planet found strange objects made by an ancient species living on that planet. They are transparent boxes containing opaque solid spheres (Figure 1). There are also many lithographs which seem to... | ```python
from collections import defaultdict, deque
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
N = int(readline())
if N == 0:
return False
C0 = [list(map(int, readline().split())) for i in range(N)]
U = [1] * N
D = defaultdict(list)
for i in range(N):
(xi, yi, zi, ri) = C... | vfc_143494 | {
"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": "3\n95 20 180 18\n125 20 185 18\n40 27 195 10\n1\n5 5 5 4\n2\n5 5 5 4\n5 5 5 3\n2\n5 5 5 4\n5 7 5 3\n16\n2338 3465 29034 710\n1571 14389 25019 842\n1706 8015 11324 1155\n1899 4359 33815 888\n2160 10364 20511 1264\n2048 8835 23706 19... | |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/all-numbers-with-specific-difference3558/1 | Solve the following coding problem using the programming language python:
Given a positive number N and a number D. Find the count of positive numbers smaller or equal to N such that the difference between the number and sum of its digits is greater than or equal to given specific value D.
Example 1:
Input:
N = 13 ,... | ```python
class Solution:
def getCount(self, N, D):
if D == 0:
return N
def sumOfDigit(N):
c = 0
n = N
while n != 0:
c += n % 10
n = n // 10
return c
low = 1
high = N
while low <= high:
mid = int((low + high) / 2)
if mid - sumOfDigit(mid) < D:
low = mid + 1
else:
hig... | vfc_143498 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/all-numbers-with-specific-difference3558/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N = 13 , D = 2",
"output": "4",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "N = 14 , D = 3",
"output": "5",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/998/B | Solve the following coding problem using the programming language python:
There are a lot of things which could be cut — trees, paper, "the rope". In this problem you are going to cut a sequence of integers.
There is a sequence of integers, which contains the equal number of even and odd numbers. Given a limited budg... | ```python
from sys import *
from math import *
from bisect import *
(n, k) = map(int, stdin.readline().split())
a = list(map(int, stdin.readline().split()))
od = ev = 0
c = []
for i in range(n):
if a[i] % 2 == 0:
ev += 1
else:
od += 1
if ev == od and i != n - 1:
c.append(abs(a[i] - a[i + 1]))
c.sort()
ans = 0
... | vfc_143499 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/998/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6 4\n1 2 5 10 15 20\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 10\n1 3 2 4\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": nul... |
taco | verifiable_code | https://codeforces.com/problemset/problem/897/A | Solve the following coding problem using the programming language python:
Are you going to Scarborough Fair?
Parsley, sage, rosemary and thyme.
Remember me to one who lives there.
He once was the true love of mine.
Willem is taking the girl to the highest building in island No.28, however, neither of them knows ho... | ```python
(n, m) = list(map(int, input().split()))
s = input()
for i in range(m):
(l, r, c, c2) = input().split()
(l, r) = (int(l), int(r))
for j in range(l - 1, r):
if s[j] == c:
s = s[:j] + c2 + s[j + 1:]
print(s)
``` | vfc_143512 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/897/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 1\nioi\n1 1 i n\n",
"output": "noi",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g\n",
"output": "gaaak",
"type": "stdin_stdout"
},
... |
taco | verifiable_code | https://www.codechef.com/problems/CHAIRS_ | Solve the following coding problem using the programming language python:
Chef's coding class is very famous in Chefland.
This year X students joined his class and each student will require one chair to sit on. Chef already has Y chairs in his class. Determine the minimum number of new chairs Chef must buy so that e... | ```python
t = int(input())
for i in range(t):
(x, y) = map(int, input().split())
if x <= y:
print('0')
else:
print(x - y)
``` | vfc_143516 | {
"difficulty": "easy",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/CHAIRS_",
"time_limit": "0.5 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n20 14\n41 41\n35 0\n50 100\n",
"output": "6\n0\n35\n0\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/the-light-problem4217/1 | Solve the following coding problem using the programming language python:
There are N office cubicles placed in a straight line, each with a bright bulb. Each light bulb can brighten K rooms on either side of it (also the one in which the light bulb itself is), but all the cubicles don't have a bulb. You are given an ... | ```python
class Solution:
def isBrightened(self, N, K, A):
if K == 0:
return int(not 0 in A)
if not 1 in A[-K - 1:]:
return 0
while len(A) > K:
flag = True
for _ in range(2 * K + 1):
if A.pop():
flag = False
break
if not A:
break
if flag:
return 0
return 1
``` | vfc_143520 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/the-light-problem4217/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N = 4, K = 3\nA = {0, 1, 0, 1}",
"output": "1",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/is-sudoku-valid4820/1 | Solve the following coding problem using the programming language python:
Given an incomplete Sudoku configuration in terms of a 9x9 2-D square matrix(mat[][]) the task to check if the current configuration is valid or not where a 0 represents an empty block.
Note: Current valid configuration does not ensure validity... | ```python
import collections
class Solution:
def isValid(self, mat):
rows = collections.defaultdict(set)
cols = collections.defaultdict(set)
squares = collections.defaultdict(set)
for r in range(9):
for c in range(9):
if mat[r][c] == 0:
continue
if mat[r][c] in rows[r] or mat[r][c] in cols[c]... | vfc_143521 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/is-sudoku-valid4820/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "mat[][] = [\n[3, 0, 6, 5, 0, 8, 4, 0, 0]\n[5, 2, 0, 0, 0, 0, 0, 0, 0]\n[0, 8, 7, 0, 0, 0, 0, 3, 1]\n[0, 0, 3, 0, 1, 0, 0, 8, 0]\n[9, 0, 0, 8, 6, 3, 0, 0, 5]\n[0, 5, 0, 0, 9, 0, 6, 0, 0]\n[1, 3, 0, 0, 0, 0, 2, 5, 0]\n[0, 0, 0, 0, 0,... |
taco | verifiable_code | https://www.codechef.com/problems/RANKLISTPAGE | Solve the following coding problem using the programming language python:
Chef participated in a contest and got a rank X.
Chef is trying to find his name in the ranklist but there are too many pages.
Each page consists of 25 participants. Chef wants to find the exact page number which contains his name.
Help Chef... | ```python
for i in range(int(input())):
a = int(input())
if a % 25 == 0:
print(int(a / 25))
else:
print(int(a / 25 + 1))
``` | vfc_143522 | {
"difficulty": "easy",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/RANKLISTPAGE",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1\n34\n150\n74\n",
"output": "1\n2\n6\n3\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
rakesh loves to play number games. when He was surfing on google he found one of the game. The theme of the game is to find the shortest way that he can make the number equal to 1. He can only perform only three operations they are -1, /2, /3. A... | ```python
for t in range(eval(input())):
number=int(input())
count=0
while number!=1:
if number%3==0:
number=number/3
elif number%2==0:
number=number/2
else:
number=number-1
count=count+1
print(count)
``` | vfc_143535 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "20\n23847221\n237483758\n212343535\n231452323\n123124135\n231231345\n128374857\n857392819\n429843209\n235986284\n123984135\n218457538\n485928749\n999999999\n757384756\n3847586\n328935794\n239847249\n249874268\n239857927",
"ou... | |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Write a program which manipulates a sequence A = {a1, a2, . . . , an} with the following operations:
* add(i, x): add x to ai.
* getSum(s, t): print the sum of as, as+1,...,at.
Note that the initial values of ai (i = 1, 2, . . . , n) are 0.
... | ```python
from array import array
import bisect
import collections
import heapq
import itertools
import operator
import sys
class BIT:
def __init__(self, n):
self.n = n
self.arr = array('l', [0] * (n + 1))
def __str__(self):
return str(self.arr.tolist())
def add(self, i, x):
while i <= self.n:
self.ar... | vfc_143539 | {
"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 5\n0 1 1\n0 2 2\n0 3 3\n1 1 2\n1 2 2",
"output": "3\n2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 5\n0 1 1\n0 2 2\n0 1 5\n1 1 2\n1 2 2",
"output": "8\n2\n",
"type": "s... | |
taco | verifiable_code | https://www.codechef.com/problems/POOK | Solve the following coding problem using the programming language python:
We have found a new chess character — pook. It has the qualities of both a rook and a pawn. Specifically, treating the chessboard to be an N\times N grid where (i, j) denotes the intersection of the i-th row and the j-th column, a pook placed at... | ```python
for _ in range(int(input())):
n = int(input())
print(n if n > 3 else n - 1 if n > 1 else 1)
``` | vfc_143543 | {
"difficulty": "easy",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/POOK",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1\n2\n3",
"output": "1\n1\n2",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/carmichael-numbers3703/1 | Solve the following coding problem using the programming language python:
A number n is said to be a Carmichael number if it satisfies the following modular arithmetic condition:
power(b, n-1) MOD n = 1,
for all b ranging from 1 to n such that b and
n are relatively prime, i.e, gcd(b, n) = 1
Given a positive ... | ```python
import math
class Solution:
def binpow(self, a, b, n):
ans = 1
while b:
if b & 1:
ans = ans * a % n
a = a * a % n
b >>= 1
return ans
def isCarmichael(self, n):
for b in range(1, n + 1):
if math.gcd(b, n) == 1 and self.binpow(b, n - 1, n) != 1:
return 0
return 1
``` | vfc_143547 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/carmichael-numbers3703/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "n = 8",
"output": "0",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "n = 3",
"output": "1",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/number-of-ways2552/1 | Solve the following coding problem using the programming language python:
Given a value N. In how many ways you can construct a grid of size N x 4 using tiles of size 1 x 4.
Example 1:
Input: N = 1
Output: 1
Explaination: We can arrange the tiles horizontally
and this is the only way.
Example 2:
Input: N = 4
Output: ... | ```python
class Solution:
def arrangeTiles(self, N):
dp = [1] * (N + 1)
for i in range(4, N + 1):
dp[i] = dp[i - 1] + dp[i - 4]
return dp[N]
``` | vfc_143548 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/number-of-ways2552/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N = 1",
"output": "1",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/SURCHESS | Solve the following coding problem using the programming language python:
Chef loves to play chess, so he bought a new chessboard with width M$M$ and height N$N$ recently.
Chef considers a chessboard correct if its width (number of columns) is equal to its height (number of rows) and each cell has no side-adjacent cel... | ```python
import sys
from collections import defaultdict
dp = defaultdict(int)
sys.setrecursionlimit(10 ** 9)
(a, b) = [int(j) for j in input().split()]
board = []
for i in range(a):
l = [int(j) for j in input()]
board.append(l)
b2 = [[0 for i in range(b)] for j in range(a)]
for i in range(a):
for j in range(b):
i... | vfc_143550 | {
"difficulty": "hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/SURCHESS",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "8 8\n00101010\n00010101\n10101010\n01010101\n10101010\n01010101\n10101010\n01010101\n4\n1 2 0 1001\n",
"output": "7\n8\n6\n8\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/maximum-average-subarray5859/1 | Solve the following coding problem using the programming language python:
Given an array Arr of size N and a positive integer K, find the sub-array of length K with the maximum average.
Example 1:
Input:
K = 4, N = 6
Arr[] = {1, 12, -5, -6, 50, 3}
Output: 12 -5 -6 50
Explanation: Maximum average is
(12 - 5 - 6 + 50)... | ```python
class Solution:
def findMaxAverage(self, arr, n, k):
st = 0
ed = k - 1
cur = 0
for i in range(k):
cur += arr[i]
ma = cur
for i in range(k, n):
cur += arr[i]
cur -= arr[i - k]
if ma < cur:
ma = cur
st = i - k + 1
ed = i
return st
``` | vfc_143555 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/maximum-average-subarray5859/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "K = 4, N = 6\r\nArr[] = {1, 12, -5, -6, 50, 3}",
"output": "12 -5 -6 50",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "K = 3, N = 7\r\nArr[] = {3, -435, 335, 10, -50, 100, 20}",
"outp... |
taco | verifiable_code | https://codeforces.com/problemset/problem/1239/B | Solve the following coding problem using the programming language python:
This is a harder version of the problem. In this version, n ≤ 300 000.
Vasya is an experienced developer of programming competitions' problems. As all great minds at some time, Vasya faced a creative crisis. To improve the situation, Petya gift... | ```python
def get_bal():
bal = [0] * n
bal[0] = u[0]
for i in range(1, n):
bal[i] = bal[i - 1] + u[i]
min_b = min(bal)
ans = 0
for i in range(n):
if bal[i] == min_b:
ans += 1
return ans
n = int(input())
u = list(input())
for i in range(n):
if u[i] == '(':
u[i] = 1
else:
u[i] = -1
if sum(u) != 0:
pr... | vfc_143560 | {
"difficulty": "very_hard",
"memory_limit": "512.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1239/B",
"time_limit": "1.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "100\n((()()))(()()))(())))((()((()()))(()))())((()(())(((())())((()))())))((()(())((())(())())))(()((())(\n",
"output": "8\n23 38",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/568/B | Solve the following coding problem using the programming language python:
Little Johnny has recently learned about set theory. Now he is studying binary relations. You've probably heard the term "equivalence relation". These relations are very important in many areas of mathematics. For example, the equality of the tw... | ```python
def main():
mod = 10 ** 9 + 7
n = int(input())
a = [[0] * (n + 1) for i in range(n + 1)]
a[0][0] = 1
for i in range(1, n + 1):
a[i][0] = a[i - 1][i - 1]
for j in range(1, i + 1):
a[i][j] = (a[i][j - 1] + a[i - 1][j - 1]) % mod
print(a[n][n - 1])
main()
``` | vfc_143564 | {
"difficulty": "hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/568/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n",
... |
taco | verifiable_code | https://codeforces.com/problemset/problem/1709/B | Solve the following coding problem using the programming language python:
You are beta testing the new secret Terraria update. This update will add quests to the game!
Simply, the world map can be represented as an array of length $n$, where the $i$-th column of the world has height $a_i$.
There are $m$ quests you h... | ```python
import sys, math, itertools, functools, collections
input = sys.stdin.readline
def solve():
(n, m) = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
right = [0] * n
left = [0] * n
x = 0
for i in range(1, n):
if a[i - 1] > a[i]:
x += a[i - 1] - a[i]
right[i] = x
x = 0
for i ... | vfc_143568 | {
"difficulty": "easy",
"memory_limit": "256 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1709/B",
"time_limit": "2 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7 6\n10 8 9 6 8 12 7\n1 2\n1 7\n4 6\n7 1\n3 5\n4 2\n",
"output": "2\n10\n0\n7\n3\n1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8 6\n1 2 3 4 5 6 7 8\n1 8\n7 1\n1 2\n2 3\n4 5\n4 5\n",
... |
taco | verifiable_code | https://codeforces.com/problemset/problem/1512/B | Solve the following coding problem using the programming language python:
There is a square field of size $n \times n$ in which two cells are marked. These cells can be in the same row or column.
You are to mark two more cells so that they are the corners of a rectangle with sides parallel to the coordinate axes.
Fo... | ```python
t = int(input())
for inh in range(0, t):
n = int(input())
(row, column, c) = ([], [], 0)
for inhg in range(0, n):
s = input()
if '*' in s and c < 2:
for i in range(0, n):
if s[i] == '*':
row.append(inhg)
column.append(i)
c += 1
if row[0] == row[1]:
if row[0] == 0:
row.append... | vfc_143572 | {
"difficulty": "easy",
"memory_limit": "256 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1512/B",
"time_limit": "2 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n4\n..*.\n....\n*...\n....\n2\n*.\n.*\n2\n.*\n.*\n3\n*.*\n...\n...\n5\n.....\n..*..\n.....\n.*...\n.....\n4\n....\n....\n*...\n*...\n",
"output": "*.*.\n....\n*.*.\n....\n**\n**\n**\n**\n*.*\n*.*\n...\n.....\n.**..\n.....\n... |
taco | verifiable_code | https://www.hackerrank.com/challenges/permutation-equation/problem | Solve the following coding problem using the programming language python:
Given a sequence of $n$ integers, $p(1),p(2),...,p(n)$ where each element is distinct and satisfies $1\leq p(x)\leq n$. For each $\boldsymbol{x}$ where $1\leq x\leq n$, that is $\boldsymbol{x}$ increments from $\mbox{1}$ to $n$, find any integer... | ```python
n = int(input())
ps = [int(x) for x in input().split()]
for x in range(1, n + 1):
for y in range(n):
if ps[ps[y] - 1] == x:
print(y + 1)
break
``` | vfc_143576 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.hackerrank.com/challenges/permutation-equation/problem",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n2 3 1\n",
"output": "2\n3\n1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n4 3 5 1 2\n",
"output": "1\n3\n5\n4\n2\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Little Jhool is still out of his mind - exploring all his happy childhood memories. And one of his favorite memory is when he found a magical ghost, who promised to fulfill one of Little Jhool's wish.
Now, Little Jhool was a kid back then, and... | ```python
tc = int(input())
while (tc>0):
tc = tc - 1
a = input()
r, u, b, y = a.count('r'), a.count('u'), a.count('b'), a.count('y')
print(min(r, min(u, (min(b, y)))))
``` | vfc_143584 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10\nxndttmdfrootikifokpfybngthjtsnimvmunukcnqumvnceqzvoufkeokspjtanjpvcmxdvya\njyohyidkifxmxxxdpwhqxixppuifaamqaajrhcizsznmkuoamjfhrpegjplrdkbqgnqqvxjjp\nwlffsgpehqhxlgejtukggjddklaasynluivoyxsskahoyzlehrbankvbgbkdqvcrbopvwaxoo\nnu... | |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Anchored Balloon
A balloon placed on the ground is connected to one or more anchors on the ground with ropes. Each rope is long enough to connect the balloon and the anchor. No two ropes cross each other. Figure E-1 shows such a situation.
<im... | ```python
import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 13
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (... | vfc_143588 | {
"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": "3\n10 10 20\n10 -10 20\n-10 10 120\n1\n10 10 16\n2\n10 10 20\n10 -10 20\n2\n100 0 101\n-90 0 91\n2\n0 0 53\n30 40 102\n3\n10 10 20\n10 -10 20\n-10 -10 20\n3\n1 5 13\n5 -3 13\n-3 -2 13\n3\n98 97 168\n-82 -80 193\n-99 -96 211\n4\n90 ... | |
taco | verifiable_code | https://codeforces.com/problemset/problem/630/C | Solve the following coding problem using the programming language python:
The numbers of all offices in the new building of the Tax Office of IT City will have lucky numbers.
Lucky number is a number that consists of digits 7 and 8 only. Find the maximum number of offices in the new building of the Tax Office given t... | ```python
n = int(input())
res = pow(2, n + 1)
res = res - 2
print(res)
``` | vfc_143596 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/630/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n",
"output": "6",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n",
"output": "2",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1505/B | Solve the following coding problem using the programming language python:
Many people are aware of DMCA – Digital Millennium Copyright Act. But another recently proposed DMCA – Digital Millennium Calculation Act – is much less known.
In this problem you need to find a root of a number according to this new DMCA law.
... | ```python
n = int(input())
sumo = n
while n >= 10:
sumo = 0
while n != 0:
sumo += n % 10
n //= 10
n = sumo
print(sumo)
``` | vfc_143604 | {
"difficulty": "medium_hard",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1505/B",
"time_limit": "1.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "81\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "98\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "29\n",
... |
taco | verifiable_code | https://www.codechef.com/INOIPRAC/problems/INOI1402 | Solve the following coding problem using the programming language python:
-----Indian National Olympiad in Informatics 2014-----
Nikhil’s slogan has won the contest conducted by Drongo Airlines and he is entitled to a free ticket between any two destinations served by the airline. All cities served by Drongo Airlines ... | ```python
(c, f) = list(map(int, input().split()))
l = [[1000001 for i in range(c)] for j in range(c)]
while f:
(x, y, cost) = list(map(int, input().split()))
l[x - 1][y - 1] = cost
l[y - 1][x - 1] = cost
f -= 1
for i in range(c):
l[i][i] = 0
for k in range(c):
for x in range(c):
for y in range(c):
if x == k... | vfc_143608 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/INOIPRAC/problems/INOI1402",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 5\n1 2 10\n1 3 24\n2 3 2\n2 4 15\n3 4 7\n",
"output": "19\nNote : Your program should not print anything other than what is specified in the output format. Please remove all diagnostic print statements before making your fi... |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/number-series3015/1 | Solve the following coding problem using the programming language python:
Find the Nth term of the following series :
N Nth term
1 0
2 1
3 0
4 2
5 0
6 1
7 0
8 3
9 0
10 1
and so on.......
Example 1:
Input: N = 8
Output: 3
Explanation: According to the series
for N = 8 Nth term is 3.
Ex... | ```python
class Solution:
def findNth(ob, n):
ans = 0
while n:
if n & 1:
return ans
else:
ans += 1
n >>= 1
return -1
``` | vfc_143612 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/number-series3015/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N = 8",
"output": "3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "N = 5",
"output": "0",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1385/C | Solve the following coding problem using the programming language python:
You are given an array $a$ consisting of $n$ integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from $a$ to make it a good array. Recall that the prefix of the array $a=[a_1, a_2, \dots, a_n]$ i... | ```python
from math import *
sInt = lambda : int(input())
mInt = lambda : map(int, input().split())
lInt = lambda : list(map(int, input().split()))
t = sInt()
for _ in range(t):
n = sInt()
a = lInt()
x = n - 1
while a[x - 1] >= a[x] and x > 0:
x -= 1
while a[x - 1] <= a[x] and x > 0:
x -= 1
print(x)
``` | vfc_143613 | {
"difficulty": "easy",
"memory_limit": "256 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1385/C",
"time_limit": "1 second"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n4\n1 2 3 4\n7\n4 3 3 8 4 5 2\n3\n1 1 1\n7\n1 3 1 4 5 3 2\n5\n5 4 3 2 3\n",
"output": "0\n4\n0\n2\n3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n4\n1 2 3 4\n7\n4 3 3 8 4 5 2\n3\n1... |
taco | verifiable_code | https://www.codechef.com/problems/BIBOARD | Solve the following coding problem using the programming language python:
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Chef loves single-colored squares, so he got a rectangular board with size $N \times M$ consisting only of black cells and white cells. He calculates the *cost* of... | ```python
import collections
class Dinic:
def __init__(self, n):
self.n = n
self.g = [[] for i in range(n)]
def add_edge(self, fr, to, cap):
self.g[fr].append([to, cap, len(self.g[to])])
self.g[to].append([fr, 0, len(self.g[fr]) - 1])
def add_multi_edge(self, v1, v2, cap1, cap2):
self.g[v1].append([v2,... | vfc_143617 | {
"difficulty": "very_hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/BIBOARD",
"time_limit": "3 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n3 3\n10?\n01?\n???\n1 1 1\n2 2 2",
"output": "18",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/flatten-binary-tree-to-linked-list/1 | Solve the following coding problem using the programming language python:
Given the root of a binary tree, flatten the tree into a "linked list":
The "linked list" should use the same Node class where the right child pointer points to the next node in the list and the left child pointer is always null.
The "linked... | ```python
class Solution:
def flatten(self, root):
stack = [(root, False)]
dummy = Node(-1)
curr = dummy
while stack:
(node, visited) = stack.pop()
if visited:
curr.right = node
node.left = None
curr = node
elif node:
stack.append((node.right, False))
stack.append((node.left, Fals... | vfc_143622 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/flatten-binary-tree-to-linked-list/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\r\n / \\\r\n 2 5\r\n / \\ \\\r\n 3 4 6",
"output": "1 2 3 4 5 6",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1420/C2 | Solve the following coding problem using the programming language python:
This is the hard version of the problem. The difference between the versions is that the easy version has no swap operations. You can make hacks only if all versions of the problem are solved.
Pikachu is a cute and friendly pokémon living in th... | ```python
input = __import__('sys').stdin.readline
def check(*inds):
global localmax, localmin, maxs, mins
for ind in inds:
if not ok(ind):
continue
if localmax[ind] == 0 and s[ind - 1] < s[ind] > s[ind + 1]:
localmax[ind] = 1
maxs += s[ind]
if localmin[ind] == 0 and s[ind - 1] > s[ind] < s[ind + 1]:
... | vfc_143624 | {
"difficulty": "hard",
"memory_limit": "256 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1420/C2",
"time_limit": "2 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n3 1\n1 3 2\n1 2\n2 2\n1 2\n1 2\n1 2\n7 5\n1 2 5 4 3 6 7\n1 2\n6 7\n3 4\n1 2\n2 3\n",
"output": "3\n4\n2\n2\n2\n9\n10\n10\n10\n9\n11\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n2 ... |
taco | verifiable_code | https://www.codechef.com/IARCSJUD/problems/TIMBER | Solve the following coding problem using the programming language python:
The GoC Timber Mafia is notorious for its deforestation
activities in the forests near Siruseri. These activities have
increased multifold after the death of the bandit who used to
lord over these jungles. Having lost the battle to prevent the
... | ```python
from sys import stdin
(n, m) = map(int, stdin.readline().split())
forest = []
matrix = []
for _ in range(n):
forest.append(list(map(int, stdin.readline().split())))
matrix.append([0] * m)
matrix[0][0] = forest[0][0]
for j in range(1, m):
matrix[0][j] = matrix[0][j - 1] + forest[0][j]
for i in range(1, n):
... | vfc_143628 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/IARCSJUD/problems/TIMBER",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 4\n3 4 15 23\n14 20 12 9\n3 8 12 15\n12 20 7 5\n2\n2 2 3 4\n4 2 4 2\n",
"output": "76\n20\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
G --Derangement / Derangement
Story
Person D is doing research on permutations. At one point, D found a permutation class called "Derangement". "It's cool to have a perfect permutation !!! And it starts with D !!!", the person of D who had a c... | ```python
import sys
def input():
return sys.stdin.readline().strip()
def list2d(a, b, c):
return [[c] * b for i in range(a)]
def list3d(a, b, c, d):
return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e):
return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ... | vfc_143632 | {
"difficulty": "unknown_difficulty",
"memory_limit": "536.870912 megabytes",
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "1.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n2 1 3 5 4",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n2 1 0 5 4",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"in... | |
taco | verifiable_code | Solve the following coding problem using the programming language python:
D: Indecision-Indecision-
problem
Ebi-chan has been addicted to gal games lately, and her goal now is to capture two heroines at the same time.
Ebi-chan can use several events to increase her liking from the heroine, but only one heroine can ... | ```python
(N, C) = map(int, input().split())
events = []
for i in range(N):
events.append(list(map(int, input().split())))
def solve():
L = 250
dp = [[-10 ** 18] * (L + 1) for i in range(C + 1)]
for j in range(C + 1):
dp[j][0] = 0
for (a, b, c) in events:
for j in range(C - c, -1, -1):
for k in range(L + 1... | vfc_143641 | {
"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": "3 4\n4 2 2\n2 1 1\n2 1 1",
"output": "6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 4\n4 2 2\n2 1 1\n3 2 1",
"output": "7\n",
"type": "stdin_stdout"
},
{
"f... | |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/jumbled-strings0431/1 | Solve the following coding problem using the programming language python:
You are provided an input string S and the string “GEEKS” . Find the number of ways in which the subsequence “GEEKS” can be formed from the string S.
Example 1:
Input : S = "GEEKS"
Output: 1
Explanation:
"GEEKS" occurs in S only once.
Example... | ```python
class Solution:
def TotalWays(self, s1):
mod = int(1000000000.0 + 7)
s2 = 'GEEKS'
dp = [[0 for i in range(len(s2) + 1)] for j in range(len(s1) + 1)]
dp[0][0] = 1
for i in range(1, len(s1) + 1):
dp[i][0] = 1
for i in range(1, len(s1) + 1):
for j in range(1, len(s2) + 1):
if s1[i - 1] ==... | vfc_143645 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/jumbled-strings0431/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "S = \"GEEKS\"",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "S = \"AGEEKKSB\"",
"output": "2",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
You are given an integer n find its next greater or equal number whose binary representation must not contain consecutive ones.
For eg. given n=6 whose binary is 110 and the next number with no consecutive ones is 8 whose binary is 1000.
INPU... | ```python
test = int(input())
a = [0 for i in range(test)]
for i in range(test):
a[i] = int(input())
for i in range(test):
n = a[i]
b = str(bin(n))
while '11' in b:
n+=1
b = str(bin(n))
print(n)
``` | vfc_143646 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "40\n41\n1191\n164\n586\n659\n916\n372\n976\n1048\n1018\n769\n997\n1069\n785\n89\n491\n527\n836\n1125\n500\n307\n1030\n200\n153\n292\n42\n145\n206\n1208\n151\n511\n748\n1197\n432\n635\n168\n987\n385\n993\n22",
"output": "72\n8... | |
taco | verifiable_code | https://codeforces.com/problemset/problem/1761/B | Solve the following coding problem using the programming language python:
Define a cyclic sequence of size $n$ as an array $s$ of length $n$, in which $s_n$ is adjacent to $s_1$.
Muxii has a ring represented by a cyclic sequence $a$ of size $n$.
However, the ring itself hates equal adjacent elements. So if two adjac... | ```python
t = int(input())
while t:
n = int(input())
a = [int(x) for x in input().split()]
s = set(a)
sum = 0
if len(s) > 2:
print(n)
elif len(s) == 1:
print(1)
else:
print(2 + (n - 2) // 2)
t -= 1
``` | vfc_143650 | {
"difficulty": "easy",
"memory_limit": "256 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1761/B",
"time_limit": "1 second"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n4\n1 2 3 2\n4\n1 2 1 2\n1\n1\n",
"output": "4\n3\n1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n100\n60 76 89 77 41 81 42 49 39 37 48 56 26 38 85 50 40 13 20 24 79 21 22 9 92 11 ... |
taco | verifiable_code | https://codeforces.com/problemset/problem/408/B | Solve the following coding problem using the programming language python:
Once little Vasya read an article in a magazine on how to make beautiful handmade garland from colored paper. Vasya immediately went to the store and bought n colored sheets of paper, the area of each sheet is 1 square meter.
The garland must c... | ```python
str1 = input()
str2 = input()
cnt1 = dict()
cnt2 = dict()
for x in str1:
if x not in cnt1.keys():
cnt1[x] = 0
cnt1[x] += 1
for x in str2:
if x not in cnt2.keys():
cnt2[x] = 0
cnt2[x] += 1
s = 0
for x in cnt2.keys():
if x not in cnt1.keys():
print(-1)
exit(0)
s += min(cnt1[x], cnt2[x])
print(s)
... | vfc_143662 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/408/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "aaabbac\naabbccac\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "a\nz\n",
"output": "-1",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/check-if-a-number-can-be-expressed-as-xy1606/1 | Solve the following coding problem using the programming language python:
Given a positive integer N, find if it can be expressed as x^{y} where y > 1 and x > 0 and x and y both are both integers.
Example 1:
Input:
N = 8
Output:
1
Explanation:
8 can be expressed
as 2^{3}.
Example 2:
Input:
N = 7
Output:
0
Explan... | ```python
class Solution:
def checkPower(ob, N):
if N <= 1:
return 1
n = 2
while n <= 125 ** 0.5:
t = n * n
while t <= N:
if t == N:
return 1
t = t * n
n += 1
return 0
``` | vfc_143666 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/check-if-a-number-can-be-expressed-as-xy1606/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N = 8",
"output": "1",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
problem
One day, Sosusa, who loves prime numbers, was playing with the pair $ (p, q) $, where $ p + q $ is a prime number. Suddenly, Sosusa wondered how many of these pairs were prime numbers with $ p $ and $ q $ both less than or equal to $ N ... | ```python
import math
N = int(input())
P = [True for x in range(N + 3)]
P[0] = False
P[1] = False
for i in range(2, int(math.sqrt(N + 3)) + 1):
if P[i]:
for j in range(i * 2, N + 3, i):
P[j] = False
count = 0
for q in range(3, N + 1):
if P[q] and P[2 + q]:
count += 2
print(count)
``` | vfc_143667 | {
"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": "5",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4",
"outp... | |
taco | verifiable_code | https://www.codechef.com/RC122020/problems/RECNDROT | Solve the following coding problem using the programming language python:
Chef has a sequence $A_1, A_2, \ldots, A_N$. For a positive integer $M$, sequence $B$ is defined as $B = A*M$ that is, appending $A$ exactly $M$ times. For example, If $A = [1, 2]$ and $M = 3$, then $B = A*M = [1, 2, 1, 2, 1, 2]$
You have to hel... | ```python
def mForMaxSeq(arr, n):
eim = dict()
for i in range(n):
if arr[i] in eim:
eim[arr[i]].append(i)
else:
eim[arr[i]] = [i]
keys = sorted(eim.keys())
connected = False
count = 0
pI = -1
nKeys = len(keys)
for i in range(nKeys - 1):
if not connected:
pI = eim[keys[i]][0]
for idx in eim[key... | vfc_143671 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/RC122020/problems/RECNDROT",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n2\n2 1\n2\n1 2\n5\n1 3 2 1 2\n",
"output": "2\n1\n2\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1675/A | Solve the following coding problem using the programming language python:
In the pet store on sale there are:
$a$ packs of dog food;
$b$ packs of cat food;
$c$ packs of universal food (such food is suitable for both dogs and cats).
Polycarp has $x$ dogs and $y$ cats. Is it possible that he will be able to buy food... | ```python
import sys
input = sys.stdin.readline
def inp():
return int(input())
def inlt():
return list(map(int, input().split()))
def insr():
s = input()
return list(s[:len(s) - 1])
def invr():
return map(int, input().split())
t = inp()
for _ in range(t):
(a, b, c, x, y) = inlt()
x -= a
y -= b
if x > 0 and... | vfc_143675 | {
"difficulty": "easy",
"memory_limit": "256 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1675/A",
"time_limit": "1 second"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7\n1 1 4 2 3\n0 0 0 0 0\n5 5 0 4 6\n1 1 1 1 1\n50000000 50000000 100000000 100000000 100000000\n0 0 0 100000000 100000000\n1 3 2 2 5\n",
"output": "YES\nYES\nNO\nYES\nYES\nNO\nNO\n",
"type": "stdin_stdout"
},
{
... |
taco | verifiable_code | https://codeforces.com/problemset/problem/630/B | Solve the following coding problem using the programming language python:
The city administration of IT City decided to fix up a symbol of scientific and technical progress in the city's main square, namely an indicator board that shows the effect of Moore's law in real time.
Moore's law is the observation that the n... | ```python
(a, b) = map(int, input().split())
y = b // (60 * 60 * 24 * 30 * 24)
print(a * pow(1.000000011, b))
``` | vfc_143679 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/630/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1000 1000000\n",
"output": "1011.060722383550382782399454922040\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1000 0\n",
"output": "1000\n",
"type": "stdin_stdout"
},
... |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Golu loves prime numbers . He wants to do something new with prime numbers. So Molu gives him a number and asks him to minmum number of prime numbers required such that their sum is equal to given number. This task is very diffcult for Golu so h... | ```python
import math
primes = []
def primeSieve(sieveSize):
sieve = [True] * sieveSize
sieve[0] = False
sieve[1] = False
for i in range(2, int(math.sqrt(sieveSize)) + 1):
pointer = i * 2
while pointer < sieveSize:
sieve[pointer] = False
pointer += i
for i in range(sieveSize):
if sieve[i] == True:
... | vfc_143683 | {
"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\n43\n469\n336\n502\n171\n726\n480\n360\n964\n466",
"output": "1\n2\n2\n1\n1\n2\n2\n2\n2\n2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n43\n5541\n6336\n646\n6243\n2798\n5016\n3504\... | |
taco | verifiable_code | https://www.codechef.com/LTIME29/problems/FSTSQ | Solve the following coding problem using the programming language python:
A squarer is a simple and convenient device. You give it some positive integer X and it calculates its square.
Leha is implementing a module of this device which is responsible for squaring the numbers consisting of multiple repetitions of one d... | ```python
val = 10 ** 9 + 7
def MOD(a, b):
aans = a
ans = 1
while b > 0:
ans = ans * aans % val
aans = aans * aans % val
b /= 2
return ans % val
for i in range(eval(input())):
(n, d) = list(map(int, input().split()))
a = int(str(d) * n)
sqr = str(a * a)
ans = 0
count = 0
for ii in sqr:
ans = ans + in... | vfc_143687 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/LTIME29/problems/FSTSQ",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 4\n3 6\n3 5\n",
"output": "139\n40079781\n32745632\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/988/D | Solve the following coding problem using the programming language python:
There are $n$ distinct points on a coordinate line, the coordinate of $i$-th point equals to $x_i$. Choose a subset of the given set of points such that the distance between each pair of points in a subset is an integral power of two. It is nece... | ```python
n = int(input())
l = list(map(int, input().split()))
s = set(l)
ans = [l[0]]
for i in l:
j = 1
while j < int(2000000000.0):
if i + j in s and i + 2 * j in s:
print('3')
print(i, i + j, i + 2 * j)
quit()
elif i + j in s:
ans = [i, i + j]
j *= 2
print(len(ans))
for i in ans:
print(i, end=' ... | vfc_143691 | {
"difficulty": "medium_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/988/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n3 5 4 7 10 12\n",
"output": "3\n3 4 5 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n-1 2 5 8 11\n",
"output": "1\n-1 \n",
"type": "stdin_stdout"
},
{
"fn... |
taco | verifiable_code | https://codeforces.com/problemset/problem/24/D | Solve the following coding problem using the programming language python:
You received as a gift a very clever robot walking on a rectangular board. Unfortunately, you understood that it is broken and behaves rather strangely (randomly). The board consists of N rows and M columns of cells. The robot is initially at so... | ```python
(n, m) = (int(s) for s in input().split())
(i, j) = (int(s) for s in input().split())
def find(n, m, i, j):
if i == n:
return 0
if m == 1:
return 2 * (n - i)
(e, a, b) = ([0.0] * m, [0] * m, [0] * m)
for l in range(n - 1, 0, -1):
(a[0], b[0]) = (0.5, 0.5 * (3 + e[0]))
for k in range(1, m - 1):
... | vfc_143695 | {
"difficulty": "very_hard",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/24/D",
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1000 1\n777 1\n",
"output": "446.0000000000",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "126 125\n115 22\n",
"output": "43.9999127943",
"type": "stdin_stdout"
},
{
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.