source stringclasses 4
values | task_type stringclasses 1
value | in_source_id stringlengths 0 138 | problem stringlengths 219 13.2k | gold_standard_solution stringlengths 0 413k | problem_id stringlengths 5 10 | metadata dict | verification_info dict |
|---|---|---|---|---|---|---|---|
taco | verifiable_code | https://codeforces.com/problemset/problem/463/D | Solve the following coding problem using the programming language python:
Gargari got bored to play with the bishops and now, after solving the problem about them, he is trying to do math homework. In a math book he have found k permutations. Each of them consists of numbers 1, 2, ..., n in some order. Now he should f... | ```python
import os
import sys
from io import BytesIO, IOBase
def main():
(n, k) = map(int, input().split())
a = [list(map(lambda x: int(x) - 1, input().split())) for _ in range(k)]
b = [[0] * n for _ in range(k)]
for i in range(k):
for j in range(n):
b[i][a[i][j]] = j
dp = [[0] * n for _ in range(k)]
for i... | vfc_140095 | {
"difficulty": "hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/463/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 3\n1 4 2 3\n4 1 2 3\n1 2 4 3\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 3\n2 5 1 4 6 3\n5 1 4 3 2 6\n5 4 2 6 3 1\n",
"output": "3\n",
"type": "stdin_s... |
taco | verifiable_code | https://codeforces.com/problemset/problem/10/B | Solve the following coding problem using the programming language python:
All cinema halls in Berland are rectangles with K rows of K seats each, and K is an odd number. Rows and seats are numbered from 1 to K. For safety reasons people, who come to the box office to buy tickets, are not allowed to choose seats themse... | ```python
__author__ = 'Darren'
def solve():
(n, k) = map(int, input().split())
group = map(int, input().split())
available = [[k, 1][:] for _ in range(k + 1)]
center = (k + 1) // 2
for m in group:
(closest, best_row, best_col) = (10000, -1, -1)
for row in range(1, k + 1):
col = 0
if available[row][0] <... | vfc_140099 | {
"difficulty": "medium",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/10/B",
"time_limit": "1.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 3\n3 3\n",
"output": "2 1 3\n1 1 3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "80 29\n19 15 15 27 2 25 2 5 29 11 6 4 20 11 27 16 6 6 10 2 5 12 8 23 11 7 11 13 19 29 8 4 9 13 14 22 16... |
taco | verifiable_code | https://codeforces.com/problemset/problem/832/B | Solve the following coding problem using the programming language python:
It's hard times now. Today Petya needs to score 100 points on Informatics exam. The tasks seem easy to Petya, but he thinks he lacks time to finish them all, so he asks you to help with one..
There is a glob pattern in the statements (a string ... | ```python
def do(cur) -> str:
if len(cur) < len(pt) - 1:
return 'NO'
i = j = 0
while j < len(cur):
if pt[i] == '?':
if cur[j] not in good:
return 'NO'
elif pt[i] == '*':
b = len(cur) - len(pt) + 1
for x in cur[j:j + b]:
if x in good:
return 'NO'
i += 1
j += b
continue
elif pt[i... | vfc_140107 | {
"difficulty": "medium_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/832/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "ab\na?a\n2\naaa\naab\n",
"output": "YES\nNO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "abc\na?a?a*\n4\nabacaba\nabaca\napapa\naaaaax\n",
"output": "NO\nYES\nNO\nYES\n",
"t... |
taco | verifiable_code | https://codeforces.com/problemset/problem/6/C | Solve the following coding problem using the programming language python:
Alice and Bob like games. And now they are ready to start a new game. They have placed n chocolate bars in a line. Alice starts to eat chocolate bars one by one from left to right, and Bob — from right to left. For each chocololate bar the time,... | ```python
n = int(input())
(*l,) = map(int, input().split())
a = b = i = 0
j = n - 1
while i <= j:
if a <= b:
a += l[i]
i += 1
else:
b += l[j]
j -= 1
print(i, n - i)
``` | vfc_140111 | {
"difficulty": "easy",
"memory_limit": "64.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/6/C",
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n1 1\n",
"output": "1 1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n1 1 1 1\n",
"output": "2 2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"in... |
taco | verifiable_code | https://codeforces.com/problemset/problem/1145/D | Solve the following coding problem using the programming language python:
From "ftying rats" to urban saniwation workers - can synthetic biology tronsform how we think of pigeons?
The upiquitous pigeon has long been viewed as vermin - spleading disease, scavenging through trush, and defecating in populous urban spas... | ```python
n = int(input())
a = list(map(int, input().split()))
print((min(a) ^ a[2]) + 2)
``` | vfc_140116 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1145/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1 2 3 4 5\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n6 12 3 15 9 18\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
taco | verifiable_code | Solve the following coding problem using the programming language python:
After solving Reese's first problem Harold thought he had proven himself. But Reese wasn't convinced so he gave Harold another query. He told Harold to find the nth term of the sequence given by the equation.
a[n]=( f[n] + g[n] ) % n
where, f... | ```python
arr = [0]*100005
f = [0]*100005
ans = [0]*100005
def mark(a):
i = 2
while i*a<=100002:
num = i*a
if arr[num]==0:
arr[num] += a
i += 1
def sieve():
for i in range(2,100002):
if arr[i]==0:
arr[i] = arr[i-1]+i
mark(i)
else:
arr[i] += arr[i-1]
sieve()
for i in range(1,100002//2+1):
for ... | vfc_140124 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "300\n44\n18470\n6337\n26503\n19172\n15727\n11481\n29361\n26965\n24467\n5708\n28148\n23284\n16830\n9964\n494\n2998\n11945\n4830\n5439\n32394\n14607\n3905\n156\n295\n12385\n17424\n18719\n19721\n19898\n5450\n21729\n14774\n11541\n1872\... | |
taco | verifiable_code | https://codeforces.com/problemset/problem/819/E | Solve the following coding problem using the programming language python:
In order to fly to the Moon Mister B just needs to solve the following problem.
There is a complete indirected graph with n vertices. You need to cover it with several simple cycles of length 3 and 4 so that each edge is in exactly 2 cycles.
W... | ```python
f = lambda n: [(1, 2, 3)] * 2 if n == 3 else [(1, 2, 3, 4), (1, 2, 4, 3), (1, 4, 2, 3)] if n == 4 else f(n - 2) + [(n, n - 1, 1), (n, n - 1, n - 2)] + [(n, i, n - 1, i + 1) for i in range(1, n - 2)]
ans = f(int(input()))
print(len(ans))
[print(len(i), *i) for i in ans]
``` | vfc_140128 | {
"difficulty": "very_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/819/E",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n",
"output": "2\n3 1 2 3\n3 1 2 3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n",
"output": "6\n3 1 2 3\n3 2 3 4\n3 3 4 5\n3 4 5 1\n4 2 1 3 5\n4 5 1 4 2\n",
"type": "s... |
taco | verifiable_code | https://codeforces.com/problemset/problem/793/A | Solve the following coding problem using the programming language python:
Oleg the bank client checks share prices every day. There are n share prices he is interested in. Today he observed that each second exactly one of these prices decreases by k rubles (note that each second exactly one price changes, but at diffe... | ```python
(n, k) = map(int, input().split())
l = list(map(int, input().split()))
K = min(l)
for i in range(n):
if (l[i] - K) % k != 0:
print(-1)
exit()
Sum = sum(l)
K = K * n
Sum = Sum - K
print(Sum // k)
``` | vfc_140132 | {
"difficulty": "easy",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/793/A",
"time_limit": "1.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 3\n1 3 5\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 2\n2 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\n",
... |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/distinct-palindromic-substrings5141/1 | Solve the following coding problem using the programming language python:
Given a string str of lowercase ASCII characters, Count the number of distinct continuous palindromic sub-strings which are present in the string str.
Example 1:
Input:
str = "abaaa"
Output:
5
Explanation : These are included in answer:
"a","aa"... | ```python
class Solution:
def palindromeSubStrs(self, s):
m = dict()
n = len(s)
R = [[0 for x in range(n + 1)] for x in range(2)]
s = '@' + s + '#'
for j in range(2):
rp = 0
R[j][0] = 0
i = 1
while i <= n:
while s[i - rp - 1] == s[i + j + rp]:
rp += 1
R[j][i] = rp
k = 1
whil... | vfc_140136 | {
"difficulty": "medium_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/distinct-palindromic-substrings5141/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "str = \"abaaa\"",
"output": "5",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "str = \"geek\"",
"output": "4",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/CTOUR | Solve the following coding problem using the programming language python:
Ishank lives in a country in which there are N$N$ cities and N−1$N-1$ roads. All the cities are connected via these roads. Each city has been assigned a unique number from 1 to N$N$. The country can be assumed as a tree, with nodes representing ... | ```python
try:
X = list(map(int, input().split()))
except:
X = [0, 0]
ch = []
chnew = []
par = {}
par[1] = 0
for i in range(X[0] + 1):
ch.append([])
chnew.append([])
for i in range(X[0] - 1):
Y = list(map(int, input().split()))
ch[Y[0]].append([Y[1], Y[2]])
ch[Y[1]].append([Y[0], Y[2]])
tre = [1]
while len(tre):... | vfc_140137 | {
"difficulty": "very_hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/CTOUR",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "9 5\n1 2 8\n1 3 -9\n2 4 1\n2 5 -6\n3 6 7\n3 7 6\n6 8 3\n6 9 4\n1 2\n2 7\n4 3\n3 2\n8 9\n",
"output": "10\n5\n0\n-1\n21\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/SHKSTR | Solve the following coding problem using the programming language python:
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Sheokand loves strings. Chef has $N$ strings $S_{1}, S_{2}, \dots, S_{N}$ which he wants to give to Sheokand; however, he doesn't want to give them away for free, so... | ```python
from collections import defaultdict
TrieNode = lambda : defaultdict(TrieNode)
trie = TrieNode()
words = []
trie['idx'] = 0
def insert(w, cur, idx):
for c in w:
if c not in cur:
cur = cur[c]
cur['idx'] = idx
else:
cur = cur[c]
cur['isWord'] = True
if '$' not in cur:
cur['$'] = idx
def searc... | vfc_140141 | {
"difficulty": "medium_hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/SHKSTR",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\nabcd\nabce\nabcdex\nabcde\n3\n3 abcy\n3 abcde\n4 abcde",
"output": "abcd\nabcdex\nabcde",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1213/D2 | Solve the following coding problem using the programming language python:
The only difference between easy and hard versions is the number of elements in the array.
You are given an array $a$ consisting of $n$ integers. In one move you can choose any $a_i$ and divide it by $2$ rounding down (in other words, in one mo... | ```python
import sys
from collections import Counter
def solve():
(n, k) = list(map(int, sys.stdin.readline().split()))
a = sorted(list(map(int, sys.stdin.readline().split())))
cnt = Counter(a)
opr = cnt.copy()
opr.clear()
result = 10 ** 7
for val in a:
cur_opr = 0
while val > 0:
if cnt[val] >= k:
re... | vfc_140145 | {
"difficulty": "medium_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1213/D2",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 3\n1 2 2 4 5\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 3\n1 2 3 4 5\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Valentina is looking for a new game to play with her friends.
She asks her mom Marcia for an idea.
After a moment Marcia described to girls the following simple game.
Girls are divided into n teams, indexed 1 through n.
Each girl chooses a lowe... | ```python
for i in range(int(input())):
a = [0] * 26
x, y = list(map(str, input().split(' ')))
x = int(x)
for j in y:
a[ord(j)-ord('a')]+=1
maxx = -1
ind = -1
sz = -1
for j in range(x):
k = input()
tot=0
for l in k:
tot+=a[ord(l)-ord('a')]
if tot > maxx:
maxx = tot
ind = j+1
sz = len(k)
... | vfc_140149 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10\n3 xizardnpdntlncxyogfdmvqatzfvbvioqundfclvpytkhlvkkl\nqmjobrrjqs\nqmjobrrjq\nqmjobrrjq\n20 eedbadbdcbcecbdbeaaeccbcadcdccdacecedabcdeabcbabec\nyg\ngriolisi\nkjhtoft\njqn\nfggnohh\nxlnni\nuuftgfxtj\nm\nnqiioy\nvsvypjnu\nrlp\nmm\... | |
taco | verifiable_code | Solve the following coding problem using the programming language python:
The courier charges for a courier company are set according to size and weight as shown in the table below.
A size | B size | C size | D size | E size | F size
--- | --- | --- | --- | --- | --- | ---
Size | 60 cm or less | 80 cm or less | 100 c... | ```python
S = [60, 80, 100, 120, 140, 160]
W = [2, 5, 10, 15, 20, 25]
P = [600, 800, 1000, 1200, 1400, 1600]
while 1:
n = int(input())
if n == 0:
break
r = 0
for i in range(n):
(x, y, h, w) = map(int, input().split())
s = x + y + h
for j in range(6):
if s <= S[j] and w <= W[j]:
r += P[j]
break
p... | vfc_140153 | {
"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\n50 25 5 5\n80 60 10 30\n3\n10 7 25 24\n5 8 12 5\n30 30 30 18\n0",
"output": "800\n3800\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n50 25 5 5\n80 60 10 30\n3\n10 7 25 24\n5 8 12 5... | |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/shortest-un-ordered-subarray3634/1 | Solve the following coding problem using the programming language python:
Given an array of n distinct elements. Find the length of shortest unordered (neither increasing nor decreasing) sub array in given array.
Example 1:
Input:
n = 5
a[] = {7, 9, 10, 8, 11}
Output:
3
Explanation:
Shortest unsorted subarray is 9, ... | ```python
class Solution:
def shortestUnorderedSubarray(self, a, n):
a = [int(x) for x in a]
for index in range(n - 2):
if a[index] < a[index + 1] > a[index + 2] or a[index] > a[index + 1] < a[index + 2]:
return 3
return 0
``` | vfc_140157 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/shortest-un-ordered-subarray3634/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "n = 5\na[] = {7, 9, 10, 8, 11}",
"output": "3",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/ANUARM | Solve the following coding problem using the programming language python:
N Soldiers are lined up for a memory test. They are numbered from 0 to N-1 from left to right.
In the test, there are M rounds. In each round, Captain selects one position. Soldier at that position will be numbered 0. All the soldiers to the r... | ```python
import sys
input = sys.stdin.readline
for i in range(int(input())):
(n, m) = (int(i) for i in input().split())
li = [int(i) for i in input().split()]
(ma, mi) = (max(li), min(li))
for i in range(n):
print(max(ma - i, i - mi), end=' ')
print()
``` | vfc_140158 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/ANUARM",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n4 1\n1\n6 2\n2 3\n",
"output": "1 0 1 2\n3 2 1 1 2 3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n4 1\n1\n11 2\n2 3",
"output": "1 0 1 2 3 2 1 1 2 3 4 5 6 7 8\n",
"typ... |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/stuffs-division5735/1 | Solve the following coding problem using the programming language python:
Your are given N students with some goodies to be distrubuted among them such that student at i^{th} index gets exactly i amount of goodies (considering no wastage). The goodies has already been distributed by some other. Your task is to check i... | ```python
class Solution:
def possible(self, arr, n):
total = 0
for i in range(n):
total += i + 1
return True if total == sum(arr) else False
``` | vfc_140162 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/stuffs-division5735/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N = 5\r\nArr = {7, 4, 1, 1, 2}",
"output": "YES",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "N = 5\r\nArr = {1, 1, 1, 1, 1}",
"output": "NO",
"type": "stdin_stdout"
}
]
... |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/make-zeroes4042/1 | Solve the following coding problem using the programming language python:
Given a matrix of size n x m. Your task is to make Zeroes, that means in whole matrix when you find a zero, convert its upper, lower, left, and right value to zero and make that element the sum of the upper, lower, left and right value. Do the ... | ```python
import copy
class Solution:
def MakeZeros(self, matrix):
zeroCoordinates = []
hashMap = {}
(m, n) = (len(matrix), len(matrix[0]))
newMatrix = copy.deepcopy(matrix)
for i in range(len(matrix)):
for j in range(len(matrix[0])):
if matrix[i][j] == 0:
zeroCoordinates.append((i, j))
has... | vfc_140163 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/make-zeroes4042/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "matrix = {{1, 2, 3, 4},\r\n {5, 6, 0, 7}, \r\n {8, 9, 4, 6},\r\n {8, 4, 5, 2}}",
"output": "{{1, 2, 0, 4}, \r\n {5, 0, 20, 0},\r\n {8, 9, 0, 6}, \r\n {8,... |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Carving the cake 2 (Cake 2)
JOI-kun and IOI-chan are twin brothers and sisters. JOI has been enthusiastic about making sweets lately, and JOI tried to bake a cake and eat it today, but when it was baked, IOI who smelled it came, so we decided t... | ```python
import sys
sys.setrecursionlimit(100000)
(N, *A) = map(int, open(0).read().split())
memo = [[-1] * N for i in range(N)]
for i in range(N):
memo[i][i] = A[i] if N % 2 else 0
def dfs(p, q, t):
if memo[p][q] != -1:
return memo[p][q]
if t:
memo[p][q] = r = max(A[p] + dfs((p + 1) % N, q, 0), A[q] + dfs(p, ... | vfc_140164 | {
"difficulty": "unknown_difficulty",
"memory_limit": "268.435456 megabytes",
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "8.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n2\n8\n1\n10\n12",
"output": "21\n",
"type": "stdin_stdout"
}
]
} | |
taco | verifiable_code | https://www.codechef.com/problems/XORPRO | Solve the following coding problem using the programming language python:
The enmity between Logan and Donald Pierce never ceases to exist.
However, once Logan and Donald came face to face. Donald got agitated and asked Logan to prove his true mettle by solving a puzzle.
Logan is provided an array Arr[] of N i... | ```python
t = int(input())
for _ in range(t):
n = int(input())
L = list(map(int, input().split()))
xor = 0
for i in range(n):
xor = xor ^ L[i]
ans = 10 ** 18 + 7
for i in range(n):
a = L[i]
b = a ^ xor
ans = min(abs(a - b), ans)
print(ans)
``` | vfc_140168 | {
"difficulty": "medium_hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/XORPRO",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n4\n1 1 1 1",
"output": "0",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/886/B | Solve the following coding problem using the programming language python:
Vlad likes to eat in cafes very much. During his life, he has visited cafes n times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research.
First of all, Vlad assig... | ```python
n = int(input())
lst = list(map(int, input().split()))
lst1 = []
s = {}
for i in range(n):
s[lst[i]] = i + 1
k = list(s.keys())
i = list(s.values())
print(k[i.index(min(i))])
``` | vfc_140173 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/886/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1 3 2 1 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n2 1 2 2 4 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
taco | verifiable_code | https://www.codechef.com/problems/CHFINVNT | Solve the following coding problem using the programming language python:
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef is trying to invent the light bulb that can run at room temperature without electricity. So he has N gases numbered from 0 to N - 1 that he can ... | ```python
import math
for _ in range(int(input())):
(n, p, k) = map(int, input().split())
if n % k == 0:
x = p % k
y = n // k
print(x * y + math.ceil((p + 1) / k))
elif n % k >= p % k + 1:
x = p % k
y = math.ceil(n / k)
print(x * y + math.ceil((p + 1) / k))
else:
x = p % k
y = math.ceil(n / k) - 1
... | vfc_140177 | {
"difficulty": "medium_hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/CHFINVNT",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n10 5 5\n10 6 5\n10 4 5\n10 8 5",
"output": "2\n4\n9\n8",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/reaching-the-heights1921/1 | Solve the following coding problem using the programming language python:
The teacher gives a mental ability question to Raju. The question is as follows:-
Raju is in an elevator. Given by his teacher is an array of size N which denotes the number of floors and has a 1 based indexing. The elevator starts from the grou... | ```python
def reaching_height(n, arr):
arr.sort()
lst = []
if arr.count(arr[0]) == n and n > 1:
return [-1]
else:
for i in range(0, n // 2):
x = i + 1
lst.extend([arr[-x], arr[i]])
if n % 2 != 0:
lst.append(arr[n // 2])
return lst
``` | vfc_140181 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/reaching-the-heights1921/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": "reaching_height",
"input": "arr[ ] = {2, 3, 4, 5}",
"output": "5 2 4 3",
"type": "function_call"
},
{
"fn_name": "reaching_height",
"input": "arr[ ] = {1, 1}",
"output": "Not Possible",
"type": "functio... |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/number-of-triangles/1 | Solve the following coding problem using the programming language python:
Given a 2D matrix g contains only 1 and 0, count the number of triangles in it.
Take 3 index i,j,k (0<=i,j,k<n). {i,j}, {j,k}, {k,i} will form a triangle if i!=j and i!=k and j!=k and g[i][j]=1 and g[j][k]=1 and g[k][i]=1.
Example 1:
Input:
N=4
... | ```python
from typing import List
class Solution:
def numberOfTriangles(self, n: int, g: List[List[int]]) -> int:
cnt = 0
for i in range(n):
for j in range(n):
for k in range(n):
if (i != j and j != k and (i != k)) and g[i][j] == 1 and (g[j][k] == 1) and (g[k][i] == 1):
cnt += 1
return cnt //... | vfc_140182 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/number-of-triangles/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N=4\r\ngraph[][]={{0, 0, 1, 0}, \r\n {1, 0, 0, 1},\r\n {0, 1, 0, 0}, \r\n {0, 0, 1, 0}}",
"output": "2",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Serena is interested in only red and yellow roses. She is arranging flowers in some fashion to be presented at her friend's birthday. Her friend loves only red and yellow roses(but mostly red ones). The flowers can be arranged only in the follow... | ```python
t=eval(input())
while t:
s=input()
le=len(s)
if s[0]=='R' and s.count("Y")+s.count("R")==le and s.count("YYY")==0:
print("YES")
else:
print("NO")
t-=1
``` | vfc_140183 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "47\nRRYRRY\nRRRR\nYYRWBR\nR\nRY\nRRY\nW\nYRY\nRGGGGGGGGG\nRYYRYYRYY\nRYYY\nRR\nRYRYRYRYR\nRRRRGRRR\nRRYRRYRYY\nYYY\nBBBB\nRRRYYY\nRRRRY\nYRRRR\nRRYYRYYYR\nRYYYRYYYR\nRYYBYYRYY\nRRRRRRRRR\nRYYYYYYYY\nYYYYYYYYY\nRYRYYRYYR\nYYR\nRP\nR... | |
taco | verifiable_code | https://codeforces.com/problemset/problem/1545/A | Solve the following coding problem using the programming language python:
AquaMoon has $n$ friends. They stand in a row from left to right, and the $i$-th friend from the left wears a T-shirt with a number $a_i$ written on it. Each friend has a direction (left or right). In the beginning, the direction of each friend ... | ```python
t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
b = sorted(a)
eleToOddIndices = {}
eleToEvenIndices = {}
for (index, ele) in enumerate(a):
if ele != b[index]:
if index % 2:
if ele not in eleToEvenIndices:
eleToEvenIndices[ele] = 0
eleToEvenIndic... | vfc_140187 | {
"difficulty": "medium",
"memory_limit": "256 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1545/A",
"time_limit": "1 second"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n4\n4 3 2 5\n4\n3 3 2 2\n5\n1 2 3 5 4\n",
"output": "YES\nYES\nNO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n10\n6 2 1 1 1 10 10 2 10 5\n8\n1 3 1 1 4 5 4 4\n9\n9 6 9 9 2 8 7 2 2... |
taco | verifiable_code | https://codeforces.com/problemset/problem/1732/D1 | Solve the following coding problem using the programming language python:
This is the easy version of the problem. The only difference is that in this version there are no "remove" queries.
Initially you have a set containing one element — $0$. You need to handle $q$ queries of the following types:
+ $x$ — add the i... | ```python
import sys
import math
def solve():
inp = sys.stdin.readline
q = int(inp())
s = {0}
d = {}
for i in range(q):
(t, x) = inp().split()
if t == '+':
s.add(int(x))
elif t == '?':
x = int(x)
v = d.get(x, 0)
while v in s:
v += x
d[x] = v
print(v)
else:
raise Exception('wut')
... | vfc_140192 | {
"difficulty": "medium",
"memory_limit": "256 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1732/D1",
"time_limit": "3 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "15\n+ 1\n+ 2\n? 1\n+ 4\n? 2\n+ 6\n? 3\n+ 7\n+ 8\n? 1\n? 2\n+ 5\n? 1\n+ 1000000000000000000\n? 1000000000000000000\n",
"output": "3\n6\n3\n3\n10\n3\n2000000000000000000\n",
"type": "stdin_stdout"
},
{
"fn_n... |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/permutations-in-array1747/1 | Solve the following coding problem using the programming language python:
Given two arrays of equal size N and an integer K. The task is to check if after permuting both arrays, we get sum of their corresponding element greater than or equal to k i.e A_{i} + B_{i} >= K for all i (from 0 to N-1). Return true if possibl... | ```python
class Solution:
def isPossible(self, a, b, n, k):
a.sort()
b.sort(reverse=True)
for i in range(n):
if a[i] + b[i] < k:
return False
return True
``` | vfc_140197 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/permutations-in-array1747/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "a[] = {2, 1, 3}, \r\nb[] = { 7, 8, 9 }, \r\nk = 10.",
"output": "True",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "a[] = {1, 2, 2, 1}, b[] = { 3, 3, 3, 4 }, k = 5.",
"output": "Fals... |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/next-greater-even-number0828/1 | Solve the following coding problem using the programming language python:
Given a positive integer X. The task is to find the smallest even number E such that
E > X and all digits in X and E are the same.
Note: All the digits in X should be same with digits in E.
Example 1:
Input:
X = 34722641
Output:
34724126
Expla... | ```python
class Solution:
def getNextEven(self, x):
(s, p, flag, r) = ([], 0, 0, int(x))
for i in x:
p += int(i)
if int(i) % 2 == 0:
flag = 1
s.append(i)
if flag == 0:
return -1
(n, x) = (len(s), int(x))
while r % 2 != 0 or r <= x:
(l, k) = (-1, -1)
for i in range(n - 2, -1, -1):
i... | vfc_140198 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/next-greater-even-number0828/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "X = 34722641",
"output": "34724126",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/161/A | Solve the following coding problem using the programming language python:
The Two-dimensional kingdom is going through hard times... This morning the Three-Dimensional kingdom declared war on the Two-dimensional one. This (possibly armed) conflict will determine the ultimate owner of the straight line.
The Two-dimens... | ```python
(n, m, x, y) = map(int, input().split())
a_n = [i for i in map(int, input().split())]
b_m = [i for i in map(int, input().split())]
count = 0
result = []
i = 0
j = 0
while j < m and i < n:
if b_m[j] > a_n[i] + y:
i += 1
elif b_m[j] < a_n[i] - x:
j += 1
else:
count += 1
result.append((i + 1, j + 1))
... | vfc_140199 | {
"difficulty": "easy",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/161/A",
"time_limit": "3.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "33 23 17 2\n1 1 1 1 1 1 1 2 2 2 2 2 2 2 3 3 3 3 3 3 4 4 4 4 4 4 4 5 5 5 5 5 5\n10 10 10 10 10 10 10 11 11 11 11 11 11 11 12 12 12 12 12 12 13 13 13\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name... |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Monk's birthday is coming this weekend! He wants to plan a Birthday party and is preparing an invite list with his friend Puchi. He asks Puchi to tell him names to add to the list.
Puchi is a random guy and keeps coming up with names of people ... | ```python
for _ in range(eval(input())):
n=eval(input())
a=[]
while n:
n-=1
s=input()
a.append(s)
s=set(a)
a=sorted(s)
#print a
for i in a:
print(i)
``` | vfc_140204 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n10\nabc\ndef\nghi\njkl\nmno\npqr\nstu\nvwx\nabc\nghi\n10\nbb\nab\nba\nab\nba\nba\nab\nba\nba\nba\n10\naa\nba\nba\nba\nbb\nab\nab\naa\nbb\nbb\n10\nab\nab\nbb\nbb\nab\nba\naa\nba\nab\naa\n10\nba\nbb\nbb\nbb\naa\nba\nba\nba\nbb\nbb... | |
taco | verifiable_code | https://www.codechef.com/problems/NSA | Solve the following coding problem using the programming language python:
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
You are given a string $S$ of lowercase English letters with length $N$. You are allowed to (but don't have to) choose one index in this string and change the letter... | ```python
letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
indices = {letter: letters.index(letter) for letter in letters}
for _ in range(int(input())):
count = [0 for i in range(26)]
ans = 0
arr = list(input())
for let in a... | vfc_140208 | {
"difficulty": "medium_hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/NSA",
"time_limit": "1.5 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\nabcd\ndbca\ndcba",
"output": "6\n1\n0",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
For a number X, let its "Coolness" be defined as the number of "101"s occurring in its binary representation. For example, the number 21 has Coolness 2, since its binary representation is 101012, and the string "101" occurs twice in this represe... | ```python
'''
# Read input from stdin and provide input before running code
name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
tc = int(input())
c = {}
rk = {}
while tc:
tc-=1
r, k = list(map(int, input().strip().split(" ")))
ans = 0
if rk.get((r,k), None):
print(rk[(r, k)])
elif r == 10000... | vfc_140216 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "100\n30547 1\n29957 7\n31132 18\n22387 8\n20812 3\n10812 4\n6599 12\n28161 4\n13242 3\n15610 17\n24657 20\n24530 2\n7339 5\n9400 13\n20875 5\n11443 14\n11088 8\n9013 1\n11815 16\n5108 19\n23167 19\n21237 2\n30141 17\n10985 16\n1924... | |
taco | verifiable_code | https://codeforces.com/problemset/problem/1154/E | Solve the following coding problem using the programming language python:
There are $n$ students standing in a row. Two coaches are forming two teams — the first coach chooses the first team and the second coach chooses the second team.
The $i$-th student has integer programming skill $a_i$. All programming skills ar... | ```python
(n, k) = map(int, input().split())
list1 = list(map(int, input().split()))
dict1 = {i: a for (a, i) in enumerate(list1)}
right = {i: i + 1 for i in range(n)}
left = {i: i - 1 for i in range(n)}
ans = [0] * n
t = 1
for i in range(n, 0, -1):
idx = dict1.get(i)
if ans[idx] == 0:
ans[idx] = t
(r, l) = (righ... | vfc_140224 | {
"difficulty": "medium_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1154/E",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 2\n2 4 5 3 1\n",
"output": "11111\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 1\n2 1 3 5 4\n",
"output": "22111\n",
"type": "stdin_stdout"
},
{
"fn_name":... |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/minimum-number-of-swaps-needed2136/1 | Solve the following coding problem using the programming language python:
Given an array arr[] of size N of non negative integers. We can perform a swap operation on any two adjacent elements in the array. The task is to find the minimum number of swaps needed to sort the array in non - decreasing order.
Example 1:... | ```python
class Solution:
def merge(self, arr, mid, l, r):
n1 = mid - l + 1
n2 = r - mid
left = []
right = []
for i in range(n1):
left.append(arr[l + i])
for i in range(n2):
right.append(arr[mid + 1 + i])
count = 0
i = 0
k = l
j = 0
while i < n1 and j < n2:
if left[i] <= right[j]:
a... | vfc_140233 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/minimum-number-of-swaps-needed2136/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N = 4\narr[] = {4, 1, 2, 3}",
"output": "3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "N = 4\narr[] = {4, 4, 2, 3}",
"output": "4",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/first-and-last-bit2357/1 | Solve the following coding problem using the programming language python:
Given a positive integer n. The problem is to check whether only the first and last bits are set in the binary representation of n. The answer is 1 if the first and last bit is set else 0.
Example 1:
Input: N = 9
Output: 1
Explanation: (9)_{10} ... | ```python
class Solution:
def onlyFirstAndLastAreSet(self, n):
b = str(bin(n).replace('0b', ''))
if b[0] == '1' and b[-1] == '1' and (b.count('1') == 2):
return 1
return 0
``` | vfc_140238 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/first-and-last-bit2357/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N = 9",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "N = 15",
"output": "0",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/LTIME34/problems/ARRAYSUM | Solve the following coding problem using the programming language python:
You are given an array A, consisting of N integers and an array B, consisting of M integers.
The subsequence of A is the array that can be obtained by picking the elements at the arbitrary sorted set of positions from A.
Your task is to count th... | ```python
mod = 10 ** 9 + 7
(n, m) = list(map(int, input().split()))
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
dp = []
for i in range(n):
dp += [[0] * m]
dp[-1][-1] = 1
for i in range(n - 2, -1, -1):
dp[i][-1] = 1
for j in range(m - 1):
x = a[i] + b[j] - b[j + 1]
temp = 0
for ... | vfc_140240 | {
"difficulty": "hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/LTIME34/problems/ARRAYSUM",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 3\n1 5 2 4 7\n7 9 6\n\n\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 2\n7 7 7 7\n3 4\n\n\n",
"output": "6\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Aniruddha and Andrew are playing a Game on Christmas Eve named "Christmas-Gamecon". In this they are given a list of numbers.
In each turn alternatively one will select any one number from the list and decrease it by 1,2,3 or 4.
The last person ... | ```python
for _ in range(eval(input())):
n = eval(input())
a = list(map(int, input().split()))
answer = 0
for x in a:
answer ^= x % 5
print('Andrew' if answer == 0 else 'Aniruddha')
``` | vfc_140244 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "8\n200\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77... | |
taco | verifiable_code | https://www.codechef.com/problems/LIKECS04 | Solve the following coding problem using the programming language python:
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Chef Dobby loves playing games, especially games related to numbers. So, today Bhuvan gave him a new game. The description of the game goes as follows :
Consider a... | ```python
def solve0(x):
lr = (max(x) + 1) * len(x) + 1
ret = [0] * lr
ret[0] = 1
for y in x:
ret0 = [0] * lr
for (i, z) in enumerate(ret):
if z == 0:
continue
for j in range(i, i + y + 1):
ret0[j] += z
ret = ret0
q = 0
for i in range(100):
j = 1 << i
if j >= len(ret):
break
q += ret[... | vfc_140248 | {
"difficulty": "very_hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/LIKECS04",
"time_limit": "2 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n2 0 1",
"output": "4",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/959/D | Solve the following coding problem using the programming language python:
Mahmoud has an array a consisting of n integers. He asked Ehab to find another array b of the same length such that:
b is lexicographically greater than or equal to a. b_{i} ≥ 2. b is pairwise coprime: for every 1 ≤ i < j ≤ n, b_{i} and b_{... | ```python
MAX_NUM = 2000000
prime_str = '2 3 5 7 11 13 17 19 23 29 ' + '31 37 41 43 47 53 59 61 67 71 ' + '73 79 83 89 97 101 103 107 109 113 ' + '127 131 137 139 149 151 157 163 167 173 ... | vfc_140256 | {
"difficulty": "hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/959/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n2 3 5 4 13\n",
"output": "2 3 5 7 11 ",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Rani and Nandu decide to play a number game. Both play alternately, Rani playing the first move.
In each of their moves, they can subtract a maximum of k and a minimum of 1 from n i.e. each of them must subtract from n, any natural number les... | ```python
for i in range(eval(input())):
N,k = list(map(int, input().split()))
if (N)%(k+1)==1:
print("Nandu")
else:
print("Rani")
``` | vfc_140260 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "151\n329 257\n705 487\n768 697\n217 104\n969 371\n430 316\n588 276\n609 496\n9 5\n290 222\n333 100\n741 626\n817 489\n235 7\n623 179\n490 253\n623 456\n841 344\n861 786\n984 656\n441 46\n734 237\n501 249\n609 19\n745 41\n905 459\n5... | |
taco | verifiable_code | https://codeforces.com/problemset/problem/1695/D1 | Solve the following coding problem using the programming language python:
The only difference between this problem and D2 is the bound on the size of the tree.
You are given an unrooted tree with $n$ vertices. There is some hidden vertex $x$ in that tree that you are trying to find.
To do this, you may ask $k$ queri... | ```python
from collections import deque
K = input
def f(x, pre):
q = deque([(x, pre)])
dp = [0] * (n + 1)
R = []
while q:
(u, p) = q.popleft()
R.append(u)
for v in g[u]:
if v != p:
g[v].remove(u)
q.append((v, u))
for u in R[::-1]:
z = c = 0
for v in g[u]:
z += dp[v]
if dp[v] == 0:
c... | vfc_140266 | {
"difficulty": "hard",
"memory_limit": "256 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1695/D1",
"time_limit": "2 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1\n2\n1 2\n10\n2 4\n2 1\n5 7\n3 10\n8 6\n6 1\n1 3\n4 7\n9 6\n",
"output": "0\n1\n2\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/multiple-of-x-closest-to-n1719/1 | Solve the following coding problem using the programming language python:
Given two numbers X and N, find the smallest value of (N*K) which is closest to X. Where K is any positive number greater than zero. If in case there are two numbers closer to N, then return the larger number.
Example 1:
Input: X = 9, N = 2
Ou... | ```python
class Solution:
def closestNo(self, x, n):
rem = x % n
a = x - rem
b = a + n
if x - a < b - x and a != 0:
return a
else:
return b
``` | vfc_140270 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/multiple-of-x-closest-to-n1719/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "X = 9, N = 2",
"output": "10",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1330/D | Solve the following coding problem using the programming language python:
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS:
You are given two integers d, m, find the number of arrays a, satisfying the following constraints:
* The length of a is n, n ≥ 1
... | ```python
t = int(input())
for _ in range(t):
(d, m) = map(int, input().split())
a = []
i = 0
while d > (1 << i + 1) - 1:
a.append(1 << i)
i += 1
a.append((1 << i) - (1 << i + 1) + d + 1)
ans = 1
for x in a:
ans *= x + 1
ans %= m
print((ans - 1) % m)
``` | vfc_140271 | {
"difficulty": "medium_hard",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1330/D",
"time_limit": "1.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10\n1 1000000000\n2 999999999\n3 99999998\n4 9999997\n5 999996\n10 99995\n7 9994\n8 993\n9 92\n10 1\n",
"output": "1\n3\n5\n11\n17\n119\n29\n59\n89\n0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Welcome to PC Koshien, players. Physical condition management is important to participate in the event. It is said that at the turn of the season when the temperature fluctuates greatly, it puts a strain on the body and it is easy to catch a col... | ```python
c = 0
while c <= 6:
(a, b) = map(int, input().split())
c = c + 1
print(a - b)
``` | vfc_140275 | {
"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": "30 19\n39 20\n19 18\n4 20\n22 21\n23 10\n10 -10",
"output": "11\n19\n1\n-16\n1\n13\n20\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "30 19\n39 20\n19 18\n4 20\n22 21\n23 10\n15 -10",
... | |
taco | verifiable_code | Solve the following coding problem using the programming language python:
King Kala the Fighter has an army of N soldiers. Each soldier is either a BanVeer or a TalwarBaaz. There are M soldiers in the army who are TalwarBaaz. The King forms a strategy. For each battle, he doesn’t have the resources to send his army in... | ```python
fact = [0]*200005
inv = [0]*200005
MOD = 1000000009
def invMod (n):
return pow(n, MOD-2, MOD)
def solve (n, r):
if r < 0 or r > n:
return 0
x = ( fact[n] * ( inv[r]%MOD * inv[n-r]%MOD)%MOD)%MOD
return x
def main():
fact[0] = 1
inv[0] = 1
for i in range(1,200003):
fact[i] = (fact[i-1]*i)%MOD
in... | vfc_140279 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "100\n22 7 426\n445 77 81\n447 141 497\n202 59 325\n482 8 417\n156 120 402\n228 33 357\n239 38 211\n179 6 340\n68 48 16\n440 423 93\n449 218 310\n355 48 431\n80 77 218\n434 44 176\n355 131 80\n422 121 11\n67 60 174\n191 155 335\n34 ... | |
taco | verifiable_code | Solve the following coding problem using the programming language python:
A calculator scholar has discovered a strange life form called an electronic fly that lives in electronic space. While observing the behavior of the electronic flies, the electronic flies at the (x, y, z) point in this space then move to (x', y'... | ```python
def gcd(m, n):
while n:
(m, n) = (n, m % n)
return m
def lcm(m, n):
return m // gcd(m, n) * n
def f(a, m):
x = a
cnt = 1
while x != 1:
x = x * a % m
cnt += 1
return cnt
while 1:
(a1, m1, a2, m2, a3, m3) = map(int, input().split())
if a1 == 0:
break
t1 = f(a1, m1)
t2 = f(a2, m2)
t3 = f(a3... | vfc_140287 | {
"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 5 5 7 6 13\n517 1024 746 6561 4303 3125\n0 0 0 0 0 0",
"output": "12\n116640000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 5 5 7 6 13\n517 1334 746 6561 4303 3125\n0 0 0 0 0 0",
... | |
taco | verifiable_code | https://codeforces.com/problemset/problem/1553/D | Solve the following coding problem using the programming language python:
You are given two strings $s$ and $t$, both consisting of lowercase English letters. You are going to type the string $s$ character by character, from the first character to the last one.
When typing a character, instead of pressing the button ... | ```python
n = int(input())
for i in range(n):
(s, t) = (input()[::-1], input()[::-1])
i = j = 0
while i < len(s) and j < len(t):
if s[i] == t[j]:
i += 1
j += 1
else:
i += 2
print('YES' if j == len(t) else 'NO')
``` | vfc_140295 | {
"difficulty": "medium",
"memory_limit": "256 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1553/D",
"time_limit": "2 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\nababa\nba\nababa\nbb\naaa\naaaa\naababa\nababa\n",
"output": "YES\nNO\nNO\nYES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\naababa\nababa\n",
"output": "YES\n",
"type"... |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Monk visits Biksy, the largest trading market in the land. Biksy has traders from all over the world.
There are a total of N items indexed from 1 to N, that are traded in the market by a total of M dealers. Each trader is characterized by three ... | ```python
from collections import defaultdict
import sys
T = int(input())
inf = sys.maxsize
for test in range(T):
N,M = [int(x) for x in input().split()]
D = [[inf]*(N+1) for x in range(N+1) ]
dicti = defaultdict(lambda :-1*inf)
for l in range(M):
i,j,c = [int(x) for x in input().split()]
if dicti[(i,j)] < c:... | vfc_140305 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n1 1\n1 1 4\n4 6\n1 3 -3\n2 3 1\n4 2 -5\n2 4 4\n1 3 -3\n1 2 1\n",
"output": "Yes\nNo",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n6 22\n1 4 -446\n2 6 -930\n3 4 -499\n4 1 -979\n5 3 -... | |
taco | verifiable_code | https://codeforces.com/problemset/problem/1213/D1 | Solve the following coding problem using the programming language python:
The only difference between easy and hard versions is the number of elements in the array.
You are given an array $a$ consisting of $n$ integers. In one move you can choose any $a_i$ and divide it by $2$ rounding down (in other words, in one mo... | ```python
l = input().split()
n = int(l[0])
k = int(l[1])
hashi = dict()
l = input().split()
li = [int(i) for i in l]
z = 0
for i in li:
z = i
count = 0
while z > 0:
if z not in hashi:
hashi[z] = [count]
else:
hashi[z].append(count)
z = z // 2
count += 1
if 0 not in hashi:
hashi[0] = [count]
else:
... | vfc_140309 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1213/D1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 3\n1 2 2 4 5\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 3\n1 2 3 4 5\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
taco | verifiable_code | https://codeforces.com/problemset/problem/264/B | Solve the following coding problem using the programming language python:
Squirrel Liss is interested in sequences. She also has preferences of integers. She thinks n integers a_1, a_2, ..., a_{n} are good.
Now she is interested in good sequences. A sequence x_1, x_2, ..., x_{k} is called good if it satisfies the fol... | ```python
def main():
input()
d = {}
for a in map(int, input().split()):
(z, l) = (0, [])
for p in (2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 22... | vfc_140314 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/264/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n2 3 4 6 9\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "9\n1 2 3 5 6 7 8 9 10\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": nu... |
taco | verifiable_code | https://codeforces.com/problemset/problem/1398/A | Solve the following coding problem using the programming language python:
You are given an array $a_1, a_2, \dots , a_n$, which is sorted in non-decreasing order ($a_i \le a_{i + 1})$.
Find three indices $i$, $j$, $k$ such that $1 \le i < j < k \le n$ and it is impossible to construct a non-degenerate triangle (a tr... | ```python
for t in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
if a[0] + a[1] > a[-1]:
print(-1)
else:
print(1, 2, n)
``` | vfc_140319 | {
"difficulty": "easy",
"memory_limit": "256 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1398/A",
"time_limit": "1 second"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n",
"output": "1 2 7\n-1\n1 2 3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n3\n78788 78788 100000\n",
"output": "-1... |
taco | verifiable_code | https://codeforces.com/problemset/problem/1227/D2 | Solve the following coding problem using the programming language python:
This is the harder version of the problem. In this version, $1 \le n, m \le 2\cdot10^5$. You can hack this problem if you locked it. But you can hack the previous problem only if you locked both problems.
You are given a sequence of integers $a... | ```python
WIDTH = 10
def index_tree(n):
levels = [[1] * n]
size = WIDTH
while size < n:
(m, r) = (n // size, n % size)
levels.append([size] * m + ([r] if r > 0 else []))
size *= WIDTH
return levels
def dec_index(levels, i):
for level in levels:
level[i] -= 1
i //= WIDTH
def find_pos(levels, pos):
(i,... | vfc_140323 | {
"difficulty": "medium_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1227/D2",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n10 20 10\n6\n1 1\n2 1\n2 2\n3 1\n3 2\n3 3\n",
"output": "20\n10\n20\n10\n20\n10\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/282/C | Solve the following coding problem using the programming language python:
The Bitlandians are quite weird people. They do everything differently. They have a different alphabet so they have a different definition for a string.
A Bitlandish string is a string made only of characters "0" and "1".
BitHaval (the mayor o... | ```python
a = input()
b = input()
if len(a) != len(b):
print('NO')
elif a.count('1') == 0 and b.count('1') > 0:
print('NO')
elif a.count('1') > 0 and b.count('1') == 0:
print('NO')
else:
print('YES')
``` | vfc_140328 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/282/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "11\n10\n",
"output": "YES\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/55dbfdc246f3f62d6a7bcee7664cacf6be345527/1 | Solve the following coding problem using the programming language python:
Given a string str, find the minimum characters to be added at front of the string to make it a palindrome.
Example 1:
Input:
str = ABCD
Output: 3
Explanation: The resultant string
after adding 3 characters is DCBABCD.
The minimum possible answ... | ```python
class Solution:
def addMinChar(self, str1):
size = len(str1)
ans = 0
i = 0
j = size - 1
while i <= j:
if str1[i] == str1[j]:
i += 1
j -= 1
else:
ans += 1
i = 0
j = size - 1 - ans
return ans
``` | vfc_140336 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/55dbfdc246f3f62d6a7bcee7664cacf6be345527/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "str = ABCD",
"output": "3",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
The customer telephone support center of the computer sales company called JAG is now in- credibly confused. There are too many customers who request the support, and they call the support center all the time. So, the company wants to figure out... | ```python
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def check(N, C, T, x):
used = [0] * N
S = [0] * (T + 1)
cap = x
f = 0
for t in range(T):
cap += S[t]
if cap == 0:
continue
for i in range(f, N):
if used[i]:
continue
(m, l, k) = C[i]
if t + m > T:
break
if t %... | vfc_140337 | {
"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 300\n100 46 150\n100 50 150\n100 50 150\n3 300\n100 50 150\n100 50 150\n200 50 150\n9 18\n3 1 1\n3 1 1\n3 1 1\n4 100 1\n5 100 1\n5 100 1\n10 5 3\n10 5 3\n1 7 1000\n10 18\n1 2 3\n2 3 4\n3 4 5\n4 5 6\n5 6 7\n6 7 8\n7 8 9\n8 9 10\n9... | |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/occurence-of-an-integer-in-a-linked-list/1 | Solve the following coding problem using the programming language python:
Given a singly linked list and a key, count the number of occurrences of given key in the linked list.
Example 1:
Input:
N = 7
Link List = 1->2->1->2->1->3->1
search_for = 1
Output: 4
Explanation:1 appears 4 times.
Example 2:
Input:
N = 5
Link L... | ```python
class Solution:
def count(self, head, search_for):
if head is None:
return 0
cnt = 0
while head.next:
if head.data == search_for:
cnt += 1
head = head.next
if head.data == search_for:
return cnt + 1
return cnt
``` | vfc_140341 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/occurence-of-an-integer-in-a-linked-list/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N = 7\nLink List = 1->2->1->2->1->3->1\nsearch_for = 1",
"output": "4",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "N = 5\nLink List = 1->2->1->2->1\nsearch_for = 3",
"output": "0",
... |
taco | verifiable_code | https://www.codechef.com/problems/REMOVECARDS | Solve the following coding problem using the programming language python:
You have N cards placed in front of you on the table. The i^{th} card has the number A_{i} written on it.
In one move, you can remove any one card from the remaining cards on the table.
Find the minimum number of moves required so that all t... | ```python
from collections import Counter
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
d = Counter(a)
maximum = 0
for i in d:
if maximum < d[i]:
maximum = d[i]
print(n - maximum)
``` | vfc_140342 | {
"difficulty": "easy",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/REMOVECARDS",
"time_limit": "0.5 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n5\n1 1 2 2 3\n4\n8 8 8 8\n6\n5 6 7 8 9 10\n",
"output": "3\n0\n5\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/pattern-for-reverse-character-bridge5738/1 | Solve the following coding problem using the programming language python:
For a given value N, denoting the number of Characters starting from the A, print reverse character bridge pattern.
Example 1:
Input:
N = 5
Output:
ABCDEDCBA
ABCD DCBA
ABC CBA
AB BA
A A
Example 2:
Input:
N = 4
Output:
ABCDCBA
ABC C... | ```python
class Solution:
def revCharBridge(self, N):
l = []
co = 0
c = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
for i in range(N, 0, -1):
start = c[:i]
if i == N - 1:
co = 1
else:
co += 2
center = ' ' * co
end = start[::-1]
if i == N:
l.append(start + end[1:])
else:
l.append(start + ... | vfc_140347 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/pattern-for-reverse-character-bridge5738/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N = 5",
"output": "ABCDEDCBA\r\nABCD DCBA\r\nABC CBA\r\nAB BA\r\nA A",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "N = 4",
"output": "ABCDCBA\r\nABC CBA\r\nAB BA\r\nA ... |
taco | verifiable_code | https://codeforces.com/problemset/problem/847/D | Solve the following coding problem using the programming language python:
A new dog show on TV is starting next week. On the show dogs are required to demonstrate bottomless stomach, strategic thinking and self-preservation instinct. You and your dog are invited to compete with other participants and naturally you wan... | ```python
from heapq import heappush, heappop
(bowels, Time) = list(map(int, input().split()))
myLine = [-int(b) for b in input().split()]
gulp = []
eat = 0
for i in range(1, min(bowels + 1, Time)):
while gulp and -gulp[0] >= Time - i:
heappop(gulp)
if -myLine[i - 1] < Time:
heappush(gulp, myLine[i - 1] + i)
eat... | vfc_140348 | {
"difficulty": "hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/847/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 5\n1 5 3\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 2\n1\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
K: Relief (Angel Relief)
Tenma, an angel, decides to save a city.
The city has a rectangular shape divided into north-south $ H $ parcels x east-west $ W $ parcels, with houses in each parcel.
The $ X $ th section from the north and the $ Y $... | ```python
def f():
return map(int, input().split())
(h, w) = f()
print(sum([sum([(x + 1) * (w - x) * v for (x, v) in enumerate(f())]) * (y + 1) * (h - y) for y in range(h)]))
``` | vfc_140352 | {
"difficulty": "unknown_difficulty",
"memory_limit": "268.435456 megabytes",
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "1.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 2\n1 2\n0 8",
"output": "44\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 2\n1 2\n-1 8",
"output": "40\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... | |
taco | verifiable_code | https://codeforces.com/problemset/problem/1353/A | Solve the following coding problem using the programming language python:
You are given two integers $n$ and $m$. You have to construct the array $a$ of length $n$ consisting of non-negative integers (i.e. integers greater than or equal to zero) such that the sum of elements of this array is exactly $m$ and the value ... | ```python
test = int(input())
for t in range(test):
(a, b) = map(int, input().split())
if a == 1:
print(0)
elif a == 2:
print(b)
else:
print(2 * b)
``` | vfc_140356 | {
"difficulty": "easy",
"memory_limit": "256 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1353/A",
"time_limit": "1 second"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1 100\n2 2\n5 5\n2 1000000000\n1000000000 1000000000\n",
"output": "0\n2\n10\n1000000000\n2000000000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n54 33\n",
"output": "66\n",... |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/sorting-all-array-elements-except-one4653/1 | Solve the following coding problem using the programming language python:
Given an array A of positive integers, sort the array in ascending order such that element at index K in unsorted array stays unmoved and all other elements are sorted.
Example 1:
ââ¬â¹Input : arr[ ] = {10, 4, 11, 7, 6, 20}
and K =... | ```python
def sortExceptK(arr, n, k):
result = arr[k]
arr.sort()
arr.remove(result)
arr.insert(k, result)
lst = list(map(str, arr))
join = ' '.join(lst)
return join
``` | vfc_140364 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/sorting-all-array-elements-except-one4653/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": "sortExceptK",
"input": "arr[ ] = {10, 4, 11, 7, 6, 20} \r\n and K = 2",
"output": "4 6 11 7 10 20",
"type": "function_call"
},
{
"fn_name": "sortExceptK",
"input": "arr[ ] = {30, 20, 10} and K = 0",
"o... |
taco | verifiable_code | https://codeforces.com/problemset/problem/909/A | Solve the following coding problem using the programming language python:
The preferred way to generate user login in Polygon is to concatenate a prefix of the user's first name and a prefix of their last name, in that order. Each prefix must be non-empty, and any of the prefixes can be the full name. Typically there ... | ```python
(first, last) = map(str, input().split())
string = first[0]
for i in first[1:]:
if i < last[0]:
string += i
else:
break
print(string + last[0])
``` | vfc_140365 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/909/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "harry potter\n",
"output": "hap\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "tom riddle\n",
"output": "tomr\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
taco | verifiable_code | https://codeforces.com/problemset/problem/883/G | Solve the following coding problem using the programming language python:
Vasya has a graph containing both directed (oriented) and undirected (non-oriented) edges. There can be multiple edges between a pair of vertices.
Vasya has picked a vertex s from the graph. Now Vasya wants to create two separate plans:
to o... | ```python
import sys
input = sys.stdin.readline
def put():
return map(int, input().split())
def dfs(x, flag=1):
(s, vis, ans) = ([x], [0] * n, ['+'] * m)
vis[x] = 1
while s:
i = s.pop()
for (j, k) in graph[i]:
if vis[j] == 0:
if k * flag < 0:
ans[abs(k) - 1] = '-'
elif k * flag > 0:
ans[a... | vfc_140369 | {
"difficulty": "hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/883/G",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 2 1\n1 1 2\n2 2 1\n",
"output": "2\n-\n2\n+\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/ROWSOLD | Solve the following coding problem using the programming language python:
Limak is a little polar bear.
He is playing a video game and he needs your help.
There is a row with N cells, each either empty or occupied by a soldier, denoted by '0' and '1' respectively.
The goal of the game is to move all soldiers to the ri... | ```python
t = int(input())
for _ in range(t):
time = 0
s = list(map(int, input().lstrip('0')))
ones = 0
zeroes = 0
i = 0
while i < len(s):
if i < len(s):
while s[i] == 1:
i += 1
ones += 1
if i >= len(s):
break
if i < len(s):
while s[i] == 0:
i += 1
zeroes += 1
if i >= len(s)... | vfc_140378 | {
"difficulty": "medium_hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/ROWSOLD",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n10100\n1100001\n000000000111\n001110100011010\n",
"output": "8\n10\n0\n48\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/count-of-palindromic-substrings-in-an-index-range3752/1 | Solve the following coding problem using the programming language python:
Given a string S of lowercase english alphabetic characters and a substring range starting from q1 and ending at q2, the task is to find out the count of palindromic substrings in the given substring range.
Example 1:
Input:
N = 7
S = "xyaabax"... | ```python
def countPalinInRange(n, A, q1, q2):
res = 0
if q1 > q2:
(q1, q2) = (q2, q1)
for i in range(q1, q2 + 1):
j = i - 1
k = i + 1
res += 1
while j >= q1 and k <= q2:
if A[j] == A[k]:
res += 1
else:
break
j -= 1
k += 1
if i < n - 1 and A[i] == A[i + 1]:
j = i
k = i + 1
wh... | vfc_140382 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/count-of-palindromic-substrings-in-an-index-range3752/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": "countPalinInRange",
"input": "N = 7 \nS = \"xyaabax\"\nq1 = 3\nq2 = 5",
"output": "4",
"type": "function_call"
},
{
"fn_name": "countPalinInRange",
"input": "N = 7\nS = \"xyaabax\" \nq1 = 2 \nq2 = 3.",
"outpu... |
taco | verifiable_code | https://www.codechef.com/problems/PRACLIST | Solve the following coding problem using the programming language python:
*CodeChef recently revamped its [practice page] to make it easier for users to identify the next problems they should solve by introducing some new features:*
*Recent Contest Problems - contains only problems from the last 2 contests*
*Separate... | ```python
(X, Y) = map(int, input().split())
print(X - Y)
``` | vfc_140383 | {
"difficulty": "easy",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/PRACLIST",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10 4",
"output": "6",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1706/D1 | Solve the following coding problem using the programming language python:
This is the easy version of the problem. The only difference between the versions is the constraints on $n$, $k$, $a_i$, and the sum of $n$ over all test cases. You can make hacks only if both versions of the problem are solved.
Note the unusua... | ```python
for _ in range(int(input())):
(N, K) = map(int, input().split())
a = [*map(int, input().split())]
ps = [0] * (10 ** 5 + 10)
for i in range(N):
(pv, j) = (10 ** 9, 1)
while j <= min(a[i], K):
nv = a[i] // j
ps[nv + 1] = max(ps[nv + 1], pv)
pv = nv
j = a[i] // (a[i] // j) + 1
ps[0] = max(p... | vfc_140387 | {
"difficulty": "medium_hard",
"memory_limit": "64 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1706/D1",
"time_limit": "4 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7\n5 2\n4 5 6 8 11\n5 12\n4 5 6 8 11\n3 1\n2 9 15\n7 3\n2 3 5 5 6 9 10\n6 56\n54 286 527 1436 2450 2681\n3 95\n16 340 2241\n2 2\n1 3\n",
"output": "2\n0\n13\n1\n4\n7\n0\n",
"type": "stdin_stdout"
},
{
"fn_... |
taco | verifiable_code | https://www.codechef.com/COOK75/problems/UGLYF | Solve the following coding problem using the programming language python:
Watson gives to Sherlock two strings S1 and S2 consisting of uppercase English alphabets. Next he wants Sherlock to build a flower in the following way:
He puts both strings perpendicular to each other in such a way that they overlap at the sam... | ```python
for _ in range(eval(input())):
S1 = input()
m1 = len(S1) / 2
S2 = input()
m2 = len(S2) / 2
d1 = {}
d2 = {}
for i in range(len(S1)):
c = S1[i]
v = abs(m1 - i)
if c in d1:
if v < d1[c][0]:
d1[c] = [v, i]
else:
d1[c] = [v, i]
for i in range(len(S2)):
c = S2[i]
v = abs(m2 - i)
if c... | vfc_140394 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/COOK75/problems/UGLYF",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\nABCDE\nXXBCZQ\nBBB\nBBBBBB\n\n\n",
"output": "2\n6\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/607/B | Solve the following coding problem using the programming language python:
Genos recently installed the game Zuma on his phone. In Zuma there exists a line of n gemstones, the i-th of which has color c_{i}. The goal of the game is to destroy all the gemstones in the line as quickly as possible.
In one second, Genos is... | ```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_140415 | {
"difficulty": "hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/607/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 2 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 2 3\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input"... |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Mehta is a forever alone and desperate guy. He has a crush on N girls of his society. He wants to impress them all and so he needs to do their task collectively.All the girls give him a number which he stores in an array named A of size N. To do... | ```python
combinations = [0]*100005
def combi():
combinations[3]=1
temp = 1
for i in range(4,100000):
temp = (temp*i)/(i-3)
combinations[i] = temp
combi()
n = eval(input())
a = [0]*100005
count = [0]*16
for i in range (0,n):
a[i] = eval(input())
ac = a[i]
c = 0
while(ac>0):
if(ac%10==2):
c = c... | vfc_140423 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "20105\n6051640186872\n627261416550056\n35381765486\n881327430\n70\n331660044\n3162565\n0\n278303\n775746307000\n68\n722000325415\n15\n66\n5\n677\n67518600103\n21850\n34624348521\n83222787581\n486630457775\n624363\n62\n5407687372806... | |
taco | verifiable_code | https://codeforces.com/problemset/problem/12/C | Solve the following coding problem using the programming language python:
The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includ... | ```python
(n, m) = input().split(' ')
n = int(n)
m = int(m)
priceList = []
res = []
least = 0
most = 0
fruitCount = 0
seq = input().split(' ')
for i in seq:
priceList.append(int(i))
item = []
count = []
for i in range(m):
inp = input()
if inp in item:
count[item.index(inp)] += 1
else:
item.append(inp)
count.a... | vfc_140427 | {
"difficulty": "easy",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/12/C",
"time_limit": "1.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 1\n14 26 22\naag\n",
"output": "14 26\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 3\n4 2 3\nwivujdxzjm\nawagljmtc\nwivujdxzjm\n",
"output": "7 11\n",
"type": "stdin_std... |
taco | verifiable_code | https://codeforces.com/problemset/problem/267/B | Solve the following coding problem using the programming language python:
You have a set of dominoes. Each domino is a rectangular tile with a line dividing its face into two square ends. Can you put all dominoes in a line one by one from left to right so that any two dominoes touched with the sides that had the same ... | ```python
def euler(start):
s = [(start, 0)]
ans = []
while s:
(i, e) = s[-1]
if i in mark:
mark.remove(i)
if degree[i] == 0:
ans.append(e)
s.pop()
else:
for (j, e) in graph[i]:
if vis[abs(e)] == 0:
degree[i] -= 1
degree[j] -= 1
vis[abs(e)] = 1
s.append((j, e))
break
... | vfc_140435 | {
"difficulty": "hard",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/267/B",
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "100\n5 0\n6 4\n1 6\n2 2\n4 0\n0 4\n4 4\n4 0\n6 6\n0 2\n3 2\n0 4\n0 4\n2 0\n4 4\n0 4\n2 6\n4 2\n1 4\n2 5\n2 0\n3 2\n1 4\n5 4\n4 2\n2 4\n4 0\n0 1\n6 4\n2 1\n5 4\n4 0\n5 6\n4 1\n2 4\n6 1\n6 4\n2 5\n2 4\n3 3\n5 4\n6 4\n2 2\n2 5\n4 4\n5... |
taco | verifiable_code | https://codeforces.com/problemset/problem/645/A | Solve the following coding problem using the programming language python:
Bessie the cow and her best friend Elsie each received a sliding puzzle on Pi Day. Their puzzles consist of a 2 × 2 grid and three tiles labeled 'A', 'B', and 'C'. The three tiles sit on top of the grid, leaving one grid cell empty. To make a mo... | ```python
a1 = input()
a2 = input()
b1 = input()
b2 = input()
first = list(a1 + a2[::-1])
second = list(b1 + b2[::-1])
first.remove('X')
second.remove('X')
ans = 'NO'
for i in range(3):
if first == second:
ans = 'YES'
break
second = second[1:] + [second[0]]
print(ans)
``` | vfc_140439 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/645/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "AB\nXC\nXB\nAC\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "AB\nXC\nAC\nBX\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null... |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/search-a-node-in-bst/1 | Solve the following coding problem using the programming language python:
Given a Binary Search Tree and a node value X, find if the node with value X is present in the BST or not.
Example 1:
Input: 2
\
81
/ \
42 87
\ \... | ```python
class BST:
def search(self, node, x):
if node is None:
return False
if node.data == x:
return True
elif x < node.data:
return self.search(node.left, x)
else:
return self.search(node.right, x)
``` | vfc_140443 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/search-a-node-in-bst/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\r\n \\\r\n 81 \r\n / \\ \r\n 42 87 \r\n \\ \\ \r\n 66 90 \r\n / \r\n 45\r\nX = 87",
"output": "1... |
taco | verifiable_code | https://www.codechef.com/problems/MY1STCONTEST | Solve the following coding problem using the programming language python:
*Each contest - there are approximately 1500 - 2000 users who participate for the 1st time and get rated.*
*The Chef wanted to tell new users some tricks for their 1st contest:*
*Before the contest - you don’t have any rating. So even if you ma... | ```python
(t, s, u) = map(int, input().split())
print(t - s, t - s - u)
``` | vfc_140445 | {
"difficulty": "easy",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/MY1STCONTEST",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10 3 2\n",
"output": "7 5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 4 1\n",
"output": "6 5\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/491/B | Solve the following coding problem using the programming language python:
Think of New York as a rectangular grid consisting of N vertical avenues numerated from 1 to N and M horizontal streets numerated 1 to M. C friends are staying at C hotels located at some street-avenue crossings. They are going to celebrate birt... | ```python
(n, m) = map(int, input().split())
minx = miny = n + m
maxx = maxy = -minx
dist = n + m + 1
c = int(input())
for _ in range(c):
(x, y) = map(int, input().split())
minx = min(minx, x - y)
miny = min(miny, x + y)
maxx = max(maxx, x - y)
maxy = max(maxy, x + y)
h = int(input())
for i in range(h):
(a, b) = ... | vfc_140449 | {
"difficulty": "hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/491/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10 10\n2\n1 1\n3 3\n2\n1 10\n4 4\n",
"output": "6\n2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "100 100\n10\n53 20\n97 6\n12 74\n48 92\n97 13\n47 96\n75 32\n69 21\n95 75\n1 54\n10\n36... |
taco | verifiable_code | https://www.codechef.com/problems/CO92REST | Solve the following coding problem using the programming language python:
Chef had an array A with length N, but some of its elements got lost. Now, each element of this array is either unknown (denoted by -1) or a positive integer not exceeding K.
Chef decided to restore the array A by replacing each unknown element ... | ```python
mod = 10 ** 9 + 7
for t in range(int(input())):
(N, M, K) = map(int, input().split())
A = list(map(int, input().split()))
(I, D) = ([0] * (N + 2), [0] * (N + 2))
for i in range(M):
(x, L, R) = input().split()
(L, R) = (int(L), int(R))
if x == 'I':
I[L] += 1
I[R] -= 1
else:
D[L] += 1
D[... | vfc_140453 | {
"difficulty": "very_hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/CO92REST",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n4 2 10\n2 3 5 4\nI 1 2\nD 3 4\n5 2 10\n-1 -1 -1 -1 -1\nI 1 3\nD 3 5\n6 2 2\n-1 -1 -1 -1 -1 -1\nI 1 4\nD 4 6\n",
"output": "1\n8\n0\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
The professor is conducting a course on Discrete Mathematics to a class of N students. He is angry at the lack of their discipline, and he decides to cancel the class if there are fewer than K students present after the class starts.
Given the ... | ```python
test_cases=int(input())
for i in range(test_cases):
students,required=input().split()
students=int(students)
required=int(required)
a=[0]*students
a=input().split()
count=0
for i in range(students):
a[i]=int(a[i])
if a[i]<=0:
count+=1
if count>=required:
print("NO")
else:
print("YES")
``` | vfc_140457 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n4 3\n-1 -3 4 2\n4 2\n0 -1 2 1",
"output": "YES\nNO",
"type": "stdin_stdout"
}
]
} | |
taco | verifiable_code | https://codeforces.com/problemset/problem/41/D | Solve the following coding problem using the programming language python:
On some square in the lowest row of a chessboard a stands a pawn. It has only two variants of moving: upwards and leftwards or upwards and rightwards. The pawn can choose from which square of the lowest row it can start its journey. On each squa... | ```python
import sys
from array import array
def input():
return sys.stdin.buffer.readline().decode('utf-8')
(n, m, k) = map(int, input().split())
k += 1
a = [tuple(map(int, input().rstrip())) for _ in range(n)]
empty = -1
dp = [[[empty] * k for _ in range(m)] for _ in range(n)]
prev = [[[(-1, -1, '*')] * k for _ in ... | vfc_140462 | {
"difficulty": "hard",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/41/D",
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "100 2 8\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00\n00... |
taco | verifiable_code | https://codeforces.com/problemset/problem/239/C | Solve the following coding problem using the programming language python:
A sequence of non-negative integers a1, a2, ..., an of length n is called a wool sequence if and only if there exists two integers l and r (1 ≤ l ≤ r ≤ n) such that <image>. In other words each wool sequence contains a subsequence of consecutive... | ```python
(n, m) = map(int, input().split())
MOD = 10 ** 9 + 9
ans = pow(2, m, MOD) - 1
step = pow(2, m, MOD) - 2
for i in range(n - 1):
ans = ans * step % MOD
step -= 1
while ans < 0:
ans += MOD
while ans >= MOD:
ans -= MOD
print(ans)
``` | vfc_140474 | {
"difficulty": "easy",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/239/C",
"time_limit": "1.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "86232 41348\n",
"output": "77566161\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 2\n",
"output": "6\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1092/D2 | Solve the following coding problem using the programming language python:
Vova's family is building the Great Vova Wall (named by Vova himself). Vova's parents, grandparents, grand-grandparents contributed to it. Now it's totally up to Vova to put the finishing touches.
The current state of the wall can be respresent... | ```python
def f():
b = [a[0]]
for e in a[1:]:
if b != []:
if e > b[-1]:
print('NO')
return
elif e == b[-1]:
b.pop()
else:
b.append(e)
else:
b.append(e)
if len(b) == 0:
print('YES')
elif len(set(b)) == 1 and b[0] == max(a):
print('YES')
else:
print('NO')
n = int(input())
a = [i... | vfc_140478 | {
"difficulty": "hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1092/D2",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n2 1 1 2 5\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n4 5 3\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
taco | verifiable_code | https://codeforces.com/problemset/problem/1380/C | Solve the following coding problem using the programming language python:
There are $n$ programmers that you want to split into several non-empty teams. The skill of the $i$-th programmer is $a_i$. You want to assemble the maximum number of teams from them. There is a restriction for each team: the number of programme... | ```python
for _ in range(int(input())):
(n, x) = map(int, input().split())
l = list(map(int, input().split()))
l.sort(reverse=True)
size = 1
team = 0
for i in range(n):
if l[i] * size >= x:
team += 1
size = 1
else:
size += 1
print(team)
``` | vfc_140482 | {
"difficulty": "medium",
"memory_limit": "256 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1380/C",
"time_limit": "2 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n5 10\n7 11 2 9 5\n4 8\n2 4 2 3\n4 11\n1 3 3 7\n",
"output": "2\n1\n0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n5 10\n7 11 2 9 1\n4 8\n2 4 2 3\n4 11\n1 3 3 7\n",
"output":... |
taco | verifiable_code | https://codeforces.com/problemset/problem/1144/A | Solve the following coding problem using the programming language python:
A string is called diverse if it contains consecutive (adjacent) letters of the Latin alphabet and each letter occurs exactly once. For example, the following strings are diverse: "fced", "xyz", "r" and "dabcef". The following string are not div... | ```python
t = int(input())
while t:
s = input()
s = sorted(list(s))
flag = 0
for i in range(len(s) - 1):
if s.count(s[i]) > 1:
flag = 1
break
if chr(ord(s[i]) + 1) not in s:
flag = 1
break
if flag == 0 or len(s) == 1:
print('Yes')
else:
print('No')
t = t - 1
``` | vfc_140486 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1144/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "8\nfced\nxyz\nr\ndabcef\naz\naa\nbad\nbabc\n",
"output": "Yes\nYes\nYes\nYes\nNo\nNo\nNo\nNo\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "44\nops\ntest\nyes\nno\nac\nbc\ncb\nz\na\nq\nr\... |
taco | verifiable_code | Solve the following coding problem using the programming language python:
We have decided to introduce an automatic ticket gate to the railway network of a certain country. One of the difficult issues to implement is determining whether a given ticket can move between designated stations. Each ticket has a boarding st... | ```python
from heapq import heappush, heappop
(s, r) = map(int, input().split())
edges = [[] for _ in range(s)]
for _ in range(r):
(u, v, w) = map(int, input().split())
u -= 1
v -= 1
edges[u].append((v, w))
edges[v].append((u, w))
(a, b, q) = map(int, input().split())
a -= 1
b -= 1
def dijkstra(start):
INF = 10 ... | vfc_140490 | {
"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 3\n1 2 3\n1 4 1\n2 3 5\n4 3 1\n3 6 2\n4 5 2\n5 6 1\n1 6 6\n1 6\n4 3\n4 6\n5 6\n2 6\n2 5",
"output": "No\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 3\n1 2 3\n1 4 1\n2 3 5\n4 3 2\n3... | |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/earthquake-and-the-paint-shop4518/1 | Solve the following coding problem using the programming language python:
Geek's Paint Shop is one of the famous shop in Geekland, but 2014 Earthquake caused disarrangement of the items in his shop. Each item in his shop is a 40-digit alpha numeric code .
Now Chunky wants to retain the reputation of his shop, for that... | ```python
from collections import defaultdict
class alphanumeric:
def __init__(self, name, count):
self.name = name
self.count = count
class Solution:
def sortedStrings(self, N, A):
store = defaultdict(lambda : 0)
for item in A:
store[item] += 1
output = []
items = sorted(store.keys())
for item i... | vfc_140494 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/earthquake-and-the-paint-shop4518/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N = 3\r\nA[] =\r\n[\"2234597891 zmxvvxbcij 8800654113 jihgfedcba\",\r\n\"1234567891 abcdefghij 9876543219 jihgfedcba\",\r\n\"2234597891 zmxvvxbcij 8800654113 jihgfedcba\"]",
"output": "1234567891 abcdefghij 9876543219 jihgfed... |
taco | verifiable_code | https://codeforces.com/problemset/problem/1296/F | Solve the following coding problem using the programming language python:
There are n railway stations in Berland. They are connected to each other by n-1 railway sections. The railway network is connected, i.e. can be represented as an undirected tree.
You have a map of that network, so for each railway section you ... | ```python
import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
from collections import deque
n = int(input())
G = [[] for i in range(n)]
edges = []
for i in range(n - 1):
(a, b) = map(int, input().split())
(a, b) = (a - 1, b - 1)
G[a].append(b)
G[b].append(a)
edges.append((a, b))
dep = [0] *... | vfc_140495 | {
"difficulty": "hard",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1296/F",
"time_limit": "3.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "9\n9 4\n7 5\n4 1\n6 5\n5 2\n3 1\n2 1\n8 3\n3\n9 7 2\n1 6 4\n8 4 1\n",
"output": "2 2 2 4 4 1 4 1 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7\n3 4\n2 3\n6 5\n2 7\n5 2\n1 2\n6\n5 6 2\... |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/compete-the-skills5807/1 | Solve the following coding problem using the programming language python:
A and B are good friend and programmers. They are always in a healthy competition with each other. They decide to judge the best among them by competing. They do so by comparing their three skills as per their values. Please help them doing so a... | ```python
class Solution:
def scores(self, a, b, cc):
for i in range(len(a)):
if a[i] > b[i]:
cc[0] += 1
elif a[i] < b[i]:
cc[1] += 1
return (cc[0], cc[1])
``` | vfc_140500 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/compete-the-skills5807/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "A = {4, 2, 7}\nB = {5, 6, 3}",
"output": "1 2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "A = {4, 2, 7}\nB = {5, 2, 8}",
"output": "0 2",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Prateek wants to give a party to his N friends on his birthday, where each friend is numbered from 1 to N. His friends are asking for a gift to come to the party, instead of giving him one. The cost of the gifts are given in the array Value whe... | ```python
t=int(input())
for c in range(t):
N,X=list(map(int,input().split()))
a=[]
flag=0
start=0
s=0
for j in range(N):
a.append(int(input()))
for k in range(N):
while(s>X):
s-=a[start]
start+=1
if(s==X):
flag=1
break
s+=a[k]
while(s>X):
s-=a[start]
start+=1
if(s==X):
flag=1
if(fla... | vfc_140502 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n5 12\n1\n3\n4\n5\n2\n",
"output": "YES\nNO\nYES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n5 25\n25\n1\n2\n3\n4\n6 21\n41\n56\n23\n45\n67\n89\n1 20\n20\n5 7\n1\n1\n2\n2\n2\n5 80... | |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/insert-in-a-sorted-list/1 | Solve the following coding problem using the programming language python:
Given a linked list sorted in ascending order and an integer called data, insert data in the linked list such that the list remains sorted.
Example 1:
Input:
LinkedList: 25->36->47->58->69->80
data: 19
Output: 19 25 36 47 58 69 80
Example 2:
Inp... | ```python
class Solution:
def sortedInsert(self, head1, key):
newNode = Node(key)
if head1 == None:
return newNode
if head1.data > key:
newNode.next = head1
head1 = newNode
return head1
current = head1
while current.next:
if current.next.data > key:
newNode.next = current.next
current... | vfc_140506 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/insert-in-a-sorted-list/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "LinkedList:25->36->47->58->69->80\r\ndata:19",
"output": "19 25 36 47 58 69 80",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "LinkedList:50->100\r\ndata:75",
"output": "50 75 100",
... |
taco | verifiable_code | https://www.hackerrank.com/challenges/sherlock-and-divisors/problem | Solve the following coding problem using the programming language python:
Watson gives an integer $N$ to Sherlock and asks him: What is the number of divisors of $N$ that are divisible by 2?.
Input Format
First line contains $\mathbf{T}$, the number of testcases. This is followed by $\mathbf{T}$ lines each cont... | ```python
even = lambda x: x & 1 == 0
def f(x):
div = 1
ret = 0
while div * div < x:
if x % div == 0:
if even(div):
ret += 1
if even(x // div):
ret += 1
div += 1
if div * div == x and even(div):
ret += 1
return ret
t = int(input())
for _ in range(t):
print(f(int(input())))
``` | vfc_140507 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.hackerrank.com/challenges/sherlock-and-divisors/problem",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n9\n8\n",
"output": "0\n3\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Find the edit distance between given two words s1 and s2.
The disntace is the minimum number of single-character edits required to change one word into the other. The edits including the following operations:
* insertion: Insert a character at... | ```python
s1 = input()
s2 = input()
dist = [[0 for i in range(len(s1) + 1)] for j in range(len(s2) + 1)]
for i in range(len(s1) + 1):
dist[0][i] = i
for i in range(len(s2) + 1):
dist[i][0] = i
for i in range(1, len(s2) + 1):
for j in range(1, len(s1) + 1):
k = 1
if s1[j - 1] == s2[i - 1]:
k = 0
dist[i][j] =... | vfc_140511 | {
"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": "icpc\nipcc",
"output": "2\n",
"type": "stdin_stdout"
}
]
} | |
taco | verifiable_code | https://www.codechef.com/IARCSJUD/problems/IARANK | Solve the following coding problem using the programming language python:
This is one more story about our old friend, the Despotic King. Once every year, it was customary for the king to give audience to the rich merchants of his country in a large hall. On that day, the merchants were ushered in to meet the king one... | ```python
arr = []
n = int(input())
for i in range(n):
a = int(input())
arr.append(a)
arr.sort()
p = arr.index(a)
print(i - p + 1)
``` | vfc_140520 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/IARCSJUD/problems/IARANK",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n78\n24\n68\n40\n39\n89\n",
"output": "1\n2\n2\n3\n4\n1\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/SCHTEST | Solve the following coding problem using the programming language python:
The ZCO scholarship contest offers scholarships to first time ZCO participants. You are participating in it for the first time. So you want to know the number of participants who'll get the scholarship.
You know that the maximum number of schola... | ```python
for _ in range(int(input())):
(n, r, x, y) = map(int, input().split())
if x > 0:
a = list(map(int, input().split()))
if y > 0:
b = list(map(int, input().split()))
if x > 0 and y > 0:
a = a + b
c = n - len(list(set(a)))
else:
l = x + y
c = n - l
x = min(c, r)
print(x)
``` | vfc_140524 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/SCHTEST",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n5 3 0 1\n4\n10 2 4 6\n3 1 7 6\n4 3 1 5 9 7\n10 4 4 6\n3 1 7 6\n4 3 1 5 9 7\n",
"output": "3\n2\n3\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/COPAR | Solve the following coding problem using the programming language python:
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef wants to give a gift to Chefina to celebrate their anniversary. Of course, he has a sequence $a_{1}, a_{2}, \ldots, a_{N}$ ready for th... | ```python
N = 100000
prime = [-1 for i in range(N + 1)]
i = 2
while i <= N:
if prime[i] == -1:
prime[i] = i
for j in range(2 * i, N + 1, i):
if prime[j] == -1:
prime[j] = i
i += 1
from math import gcd
for _ in range(int(input())):
n = int(input())
arr = list(map(int, input().split()))
range_p = [[-1, -1... | vfc_140536 | {
"difficulty": "hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/COPAR",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n4\n2 3 4 5",
"output": "3",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/NMNMX | Solve the following coding problem using the programming language python:
Maheshmati and Sangu are playing a game. First, Maheshmati gives Sangu a sequence of $N$ distinct integers $a_1, a_2, \dots, a_N$ (not necessarily sorted) and an integer $K$. Sangu has to create all subsequences of this sequence with length $K$.... | ```python
import math
def power(x, y, p):
res = 1
x = x % p
while y > 0:
if y & 1:
res = res * x % p
y = y >> 1
x = x * x % p
return res
def modInverse(n, p):
return power(n, p - 2, p)
def Combi(n, r, p):
if r == 0:
return 1
if r > n:
return 0
return f[n] * modInverse(f[r], p) % p * modInverse(f... | vfc_140540 | {
"difficulty": "medium_hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/NMNMX",
"time_limit": "2 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n4 3\n1 2 3 4\n",
"output": "36\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/PUSH7PA | Solve the following coding problem using the programming language python:
Pushpa has entered Chefland and wants to establish Pushpa-Raj here too.
Chefland has N towers where the height of the i^{th} tower is H_{i}. To establish Pushpa-Raj, Pushpa does the following:
Initially, Pushpa chooses any tower i (1≤ i ≤ N) a... | ```python
def maxHeight(List):
return max(set(List), key=List.count)
t = int(input())
for i in range(0, t):
n = int(input())
a = list(map(int, input().split()))
x = maxHeight(a) + a.count(maxHeight(a)) - 1
y = max(a) + a.count(max(a)) - 1
print(x if x > y else y)
``` | vfc_140544 | {
"difficulty": "easy",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/PUSH7PA",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n4\n1 2 1 3\n1\n2",
"output": "3\n2",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Have you ever been a part of the exciting game Passing the Parcel ? Sid is on a school picnic with his classmates. The teacher decides to make the whole class play the game of Passing the Parcel. Since the
winner of the game gets lots of chocol... | ```python
import itertools
N = eval(input())
S = input()
players = list(range(N))
pos = 0
for c in itertools.cycle(S):
# print pos
# print players
# print c
# print '---------'
if len(players) == 1: break
if c == 'b':
players.remove(players[pos])
else:
pos += 1
if pos >= len(players): pos = 0 ... | vfc_140548 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1000\nbaaabbaaabbbbbabbabbababbbaabbabbbbbbaaaabbbbabbbbbaaaababaaabbaaaaaaabaaababababaaabbbaababbbbaababbbaabbabbbabaaabaaaaabbbaabbababaabbbbaaabbbaabaaabaaaaaaabbbbabababbbbbbbbbaabaaaababaaaaaabbababbaababababbaabaababaaabbaab... | |
taco | verifiable_code | https://www.codechef.com/problems/PRETNUM | Solve the following coding problem using the programming language python:
Read problems statements in Mandarin Chinese and Russian.
Chef doesn't love math anymore. He loves Sasha. Sashen'ka is cute.
Chef goes on a date with her. Flowers are boring, while numbers are not. He knows that most of all this girl loves ... | ```python
from bisect import bisect
from math import sqrt, floor
prime = []
isprime = [True] * (10 ** 6 + 2)
isprime[0] = False
isprime[1] = False
for x in range(2, 10 ** 6 + 2):
if isprime[x]:
prime.append(x)
for i in range(2 * x, 10 ** 6 + 2, x):
isprime[i] = False
for _ in range(int(input())):
(a, b) = map(... | vfc_140561 | {
"difficulty": "medium_hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/PRETNUM",
"time_limit": "1 - 2 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n1 10",
"output": "6",
"type": "stdin_stdout"
}
]
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.