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/1149/D
Solve the following coding problem using the programming language python: Codefortia is a small island country located somewhere in the West Pacific. It consists of $n$ settlements connected by $m$ bidirectional gravel roads. Curiously enough, the beliefs of the inhabitants require the time needed to pass each road to...
```python import heapq (n, m, a, b) = map(int, input().split()) graph = {i: [] for i in range(n)} for i in range(m): (u, v, w) = map(int, input().split()) graph[u - 1].append((v - 1, w)) graph[v - 1].append((u - 1, w)) components = [-1] * n comp = -1 for i in range(n): if components[i] == -1: comp += 1 componen...
vfc_86025
{ "difficulty": "very_hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1149/D", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 5 20 25\n1 2 25\n2 3 25\n3 4 20\n4 5 20\n5 1 20\n", "output": "0 25 60 40 20\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 7 13 22\n1 2 13\n2 3 13\n1 4 22\n3 4 13\n4 5 13\n5 6 13\n6 ...
taco
verifiable_code
https://codeforces.com/problemset/problem/1426/F
Solve the following coding problem using the programming language python: You are given a string $s$ consisting of lowercase Latin letters "a", "b" and "c" and question marks "?". Let the number of question marks in the string $s$ be $k$. Let's replace each question mark with one of the letters "a", "b" and "c". Here...
```python def solve(s, n): a = 0 ab = 0 abc = 0 aTimes = 1 for i in range(s): if n[i] == 'a': a += aTimes a = a % mod elif n[i] == 'b': ab += a ab = ab % mod elif n[i] == 'c': abc += ab abc = abc % mod elif n[i] == '?': abc = (3 * abc + ab) % mod ab = (3 * ab + a) % mod a = (3 * ...
vfc_86029
{ "difficulty": "hard", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1426/F", "time_limit": "1 second" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\nac?b?c\n", "output": "24\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "7\n???????\n", "output": "2835\n", "type": "stdin_stdout" }, { "fn_name": null, ...
taco
verifiable_code
https://www.codechef.com/problems/HARDBET
Solve the following coding problem using the programming language python: There are 3 problems in a contest namely A, B, C respectively. Alice bets Bob that problem C is the hardest while Bob says that problem B will be the hardest. You are given three integers S_{A}, S_{B}, S_{C} which denotes the number of success...
```python for i in range(int(input())): (a, b, c) = map(int, input().split()) if c < b and c < a: print('Alice') elif b < c and b < a: print('Bob') else: print('Draw') ```
vfc_86033
{ "difficulty": "easy", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/HARDBET", "time_limit": "0.5 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1 4 2\n16 8 10\n14 15 9\n", "output": "Draw\nBob\nAlice\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/PROTEPOI
Solve the following coding problem using the programming language python: The kingdom of the snakes is an NxN grid. Their most-valued possession is a huge collection of poison, which is stored in the central KxK grid. It is guaranteed that both N and K are odd. What we mean by 'central' is this: suppose in the NxN gri...
```python for _ in range(int(input())): (n, k, m) = list(map(int, input().split())) row_s = [] col_s = [] for _ in range(m): (h_x, h_y, t_x, t_y) = list(map(int, input().split())) if h_x == t_x: if h_x < (n - k) // 2 + 1 or h_x > (n - k) // 2 + k: col_s.append([min(h_y, t_y), max(h_y, t_y)]) else: ...
vfc_86041
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/PROTEPOI", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n7 3 7\n1 1 6 1\n1 2 3 2\n5 2 5 2\n2 4 2 6\n6 2 6 4\n5 6 5 7\n7 1 7 4\n7 3 7\n1 1 6 1\n1 2 3 2\n5 2 5 2\n2 6 2 6\n6 2 6 4\n5 6 5 7\n7 1 7 4\n", "output": "3\n-1\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/ENJU2020/problems/ECJN209
Solve the following coding problem using the programming language python: Lets wish Horsbug98 on his birthday and jump right into the question. In Chefland, $6$ new mobile brands have appeared each providing a range of smartphones. For simplicity let the brands be represented by numbers $1$ to $6$. All phones are sold...
```python import sys from collections import defaultdict from copy import copy R = lambda t=int: t(eval(input())) RL = lambda t=int: [t(x) for x in input().split()] RLL = lambda n, t=int: [RL(t) for _ in range(n)] def solve(): (N, Q) = RL() P = RL() B = RL() phones = sorted(zip(P, B)) S = defaultdict(lambda : [])...
vfc_86049
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/ENJU2020/problems/ECJN209", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 2\n4 5 6 7\n1 2 3 4\n3 3\n1 2 3\n3 4\n4 5 6\n", "output": "4\n-1\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1042/B
Solve the following coding problem using the programming language python: Berland shop sells $n$ kinds of juices. Each juice has its price $c_i$. Each juice includes some set of vitamins in it. There are three types of vitamins: vitamin "A", vitamin "B" and vitamin "C". Each juice can contain one, two or all three typ...
```python def minv(a, b=0, c=0): if a | b | c != 7: return mins s = opts[a] + opts[b] + opts[c] return min(mins, s) opts = [1000000] * 8 opts[0] = 0 for _ in range(int(input())): (c, l) = input().split() (v, c) = (0, int(c)) if 'A' in l: v += 1 if 'B' in l: v += 2 if 'C' in l: v += 4 opts[v] = min(opts...
vfc_86059
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1042/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n5 C\n6 B\n16 BAC\n4 A\n", "output": "15\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n10 AB\n15 BA\n", "output": "-1\n", "type": "stdin_stdout" }, { "fn_n...
taco
verifiable_code
https://codeforces.com/problemset/problem/839/A
Solve the following coding problem using the programming language python: Bran and his older sister Arya are from the same house. Bran like candies so much, so Arya is going to give him some Candies. At first, Arya and Bran have 0 Candies. There are n days, at the i-th day, Arya finds a_{i} candies in a box, that is ...
```python (n, m) = map(int, input().split()) c = list(map(int, input().split())) i = 0 l = 0 for i in range(n): l += c[i] m -= min(l, 8) l -= min(l, 8) if m <= 0: print(i + 1) break else: print(-1) ```
vfc_86063
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/839/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 3\n1 2\n", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 17\n10 10 10\n", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "inpu...
taco
verifiable_code
https://codeforces.com/problemset/problem/876/C
Solve the following coding problem using the programming language python: Eighth-grader Vova is on duty today in the class. After classes, he went into the office to wash the board, and found on it the number n. He asked what is this number and the teacher of mathematics Inna Petrovna answered Vova that n is the answe...
```python import sys text = sys.stdin.read().strip() n = int(text) q = lambda x: sum([int(b) for b in str(x)]) e = [] for i in range(max(0, n - 81), n): if i + q(i) == n: e.append(i) print(len(e)) for z in e: print(z) ```
vfc_86067
{ "difficulty": "easy", "memory_limit": "512.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/876/C", "time_limit": "1.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10\n", "output": "1\n5 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "66\n", "output": "1\n60 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "39\n...
taco
verifiable_code
https://www.codechef.com/problems/RAINFALL1
Solve the following coding problem using the programming language python: In Chefland, precipitation is measured using a rain gauge in millimetre per hour. Chef categorises rainfall as: LIGHT, if rainfall is less than 3 millimetre per hour. MODERATE, if rainfall is greater than equal to 3 millimetre per hour and les...
```python t = int(input()) for i in range(t): x = int(input()) if x < 3: print('LIGHT') elif x >= 3 and x < 7: print('MODERATE') else: print('HEAVY') ```
vfc_86071
{ "difficulty": "easy", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/RAINFALL1", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n1\n20\n3\n7\n", "output": "LIGHT\nHEAVY\nMODERATE\nHEAVY", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1506/B
Solve the following coding problem using the programming language python: You are given a number $k$ and a string $s$ of length $n$, consisting of the characters '.' and '*'. You want to replace some of the '*' characters with 'x' characters so that the following conditions are met: The first character '*' in the ori...
```python for i in range(int(input())): (n, k) = map(int, input().split()) s = input() c = 1 f = s.find('*') while f < s.rfind('*'): f = s.rfind('*', f, f + k + 1) c += 1 print(c) ```
vfc_86080
{ "difficulty": "easy", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1506/B", "time_limit": "2 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n7 3\n.**.***\n5 1\n..*..\n5 2\n*.*.*\n3 2\n*.*\n1 1\n*\n", "output": "3\n1\n3\n2\n1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n7 3\n.**.***\n5 2\n..*..\n5 2\n*.*.*\n3 2\n*.*\n1 ...
taco
verifiable_code
https://codeforces.com/problemset/problem/1741/A
Solve the following coding problem using the programming language python: Two T-shirt sizes are given: $a$ and $b$. The T-shirt size is either a string M or a string consisting of several (possibly zero) characters X and one of the characters S or L. For example, strings M, XXL, S, XXXXXXXS could be the size of some ...
```python import sys input = sys.stdin.readline t = int(input()) for _ in range(t): (str1, str2) = map(str, input().rstrip().split()) if str1[-1] == 'S': l1 = -len(str1) elif str1[-1] == 'L': l1 = len(str1) else: l1 = 0 if str2[-1] == 'S': l2 = -len(str2) elif str2[-1] == 'L': l2 = len(str2) else: l2...
vfc_86084
{ "difficulty": "easy", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1741/A", "time_limit": "1 second" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\nXXXS XS\nXXXL XL\nXL M\nXXL XXL\nXXXXXS M\nL M\n", "output": "<\n>\n>\n=\n<\n>\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\nS L\nL S\nM L\nL M\nS M\nM S\n", "output": "<\n>\...
taco
verifiable_code
https://www.hackerrank.com/challenges/kittys-calculations-on-a-tree/problem
Solve the following coding problem using the programming language python: Kitty has a tree, $\mathbf{T}$, consisting of $n$ nodes where each node is uniquely labeled from $1$ to $n$. Her friend Alex gave her $\textit{q}$ sets, where each set contains $\boldsymbol{\mbox{k}}$ distinct nodes. Kitty needs to calculate the...
```python from collections import Counter, defaultdict MOD = 10 ** 9 + 7 def read_row(): return (int(x) for x in input().split()) def mul(x, y): return x * y % MOD def add(*args): return sum(args) % MOD def sub(x, y): return (x - y) % MOD (n, q) = read_row() adj_list = defaultdict(list) for _ in range(n - 1): ...
vfc_86088
{ "difficulty": "hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.hackerrank.com/challenges/kittys-calculations-on-a-tree/problem", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7 3\n1 2\n1 3\n1 4\n3 5\n3 6\n3 7\n2\n2 4\n1\n5\n3\n2 4 5\n", "output": "16\n0\n106\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/PLNTPATH
Solve the following coding problem using the programming language python: In order to expand its reach to the outer universe and ensure universal peace, the [MIB] has decided to expand its offices. Namely, it has established its office on N most important planets in the universe, with the base station on the planet S....
```python import heapq import math import collections (n, k, s) = map(int, input().split()) a = list(map(int, input().split())) alliance = [list(map(int, input().split())) for _ in range(n)] planet = collections.defaultdict(list) for i in range(1, k + 1): planet[i] = [] for (i, v) in enumerate(a): planet[v].append(i)...
vfc_86092
{ "difficulty": "very_hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/PLNTPATH", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 3 4\n1 3 1 2 2 \n0 5 -1 \n-1 4 0 \n0 3 -1 \n4 0 -1 \n4 0 3 \n", "output": "4 3 4 0 0 \n", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: Radhika 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 ...
```python for _ in range(int(input())): n, k = list(map(int, input().split())) print("Nandu" if n % (k + 1) == 1 else "Rani") ```
vfc_86101
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "998\n576 2\n207 9\n211 3\n621 9\n236 1\n345 10\n410 4\n641 5\n853 1\n189 10\n836 1\n301 1\n151 1\n591 7\n849 9\n711 3\n967 3\n168 1\n979 4\n504 3\n663 1\n559 5\n329 8\n528 5\n861 6\n255 5\n779 7\n34 1\n843 9\n329 7\n836 7\n286 5\n2...
taco
verifiable_code
https://codeforces.com/problemset/problem/1187/B
Solve the following coding problem using the programming language python: The letters shop showcase is a string s, consisting of n lowercase Latin letters. As the name tells, letters are sold in the shop. Letters are sold one by one from the leftmost to the rightmost. Any customer can only buy some prefix of letters ...
```python from collections import defaultdict n = int(input()) s = input() r = defaultdict(list) for (i, c) in enumerate(s): r[c].append(i) m = int(input()) for i in range(m): t = input() ans = 0 pos = defaultdict(int) for c in t: pos[c] += 1 ans = max(ans, r[c][pos[c] - 1]) print(ans + 1) ```
vfc_86105
{ "difficulty": "easy", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1187/B", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "100\nwjtwxtttttxjjwxtjtttwxjwjjwjxtwwxxwwwtwttwxjxxjxwxwjtjjwxxxxwwtwtxjxwtwtjjjxwjxjtwwwwtjtttjjtxtwtxjw\n10\nxwjxjwxtwwj\nwxjxxjxjx\nwtjxxxjxjxtwt\njwwxj\njtwjtxjxttxwtw\nwtwxjjjttjx\nwwwjtxw\ntjxjwtjwtw\ntjwtjjxtxjwt\nwxwtxtjw\n...
taco
verifiable_code
https://codeforces.com/problemset/problem/584/E
Solve the following coding problem using the programming language python: Anton loves transforming one permutation into another one by swapping elements for money, and Ira doesn't like paying for stupid games. Help them obtain the required permutation by paying as little money as possible. More formally, we have two ...
```python n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) c = {} for i in range(n): c[b[i]] = i b = [] for i in range(n): a[i] = c[a[i]] print(sum((abs(a[i] - i) for i in range(n))) >> 1) while True: for i in range(n): if a[i] < i: for j in range(a[i], i): if a[j] >=...
vfc_86110
{ "difficulty": "hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/584/E", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n4 2 1 3\n3 2 4 1\n", "output": "3\n2\n3 4\n1 3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n1\n1\n", "output": "0\n0\n", "type": "stdin_stdout" }, { "fn_...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/distinct-adjacent-element2121/1
Solve the following coding problem using the programming language python: Given an array arr[] of size N, the task is to check whether it is possible to obtain an array having distinct neighboring elements by swapping two neighboring array elements. Example 1: Input: N = 3, arr[] = {1, 1, 2} Output: YES Explanation: ...
```python from collections import Counter class Solution: def distinctAdjacentElement(self, arr, n): k = {} kis = [] for i in arr: if i not in k: k[i] = 1 else: k[i] += 1 for i in k: kis.append(k[i]) m = max(kis) if m <= (n + 1) // 2: return 'YES' ```
vfc_86115
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/distinct-adjacent-element2121/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 3, arr[] = {1, 1, 2}", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "N = 4, arr[] = {7, 7, 7, 7}", "output": " NO", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1405/E
Solve the following coding problem using the programming language python: Let a_1, …, a_n be an array of n positive integers. In one operation, you can choose an index i such that a_i = i, and remove a_i from the array (after the removal, the remaining parts are concatenated). The weight of a is defined as the maximu...
```python class Fenwick: def __init__(self, size): self.size = size self.tree = [0] * (size + 1) def add(self, idx, val): idx = int(idx) while idx <= self.size: self.tree[idx] += val idx += idx & -idx def sum(self, idx): ret = 0 idx = int(idx) while idx > 0: ret += self.tree[idx] idx -= ...
vfc_86116
{ "difficulty": "hard", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1405/E", "time_limit": "4.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 1\n1 1\n0 0\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1\n1\n0 0\n", "output": "1\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/check-if-a-integer-is-power-of-8-or-not2537/1
Solve the following coding problem using the programming language python: Given a positive integer N, The task is to find if it is a power of eight or not. Example 1: Input: 64 Output: Yes Explanation: 64 is power of 8. Example 2: Input: 75 Output: No Explanation: 75 is not a power of 8. Your Task: You don't need to ...
```python class Solution: def is_power_of_eight(self, n): (oc, zc) = (0, 0) while n != 0: if n & 1 == 0: zc += 1 else: oc += 1 n = n >> 1 if oc == 1 and zc % 3 == 0: return 'Yes' return 'No' ```
vfc_86120
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/check-if-a-integer-is-power-of-8-or-not2537/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "64", "output": "Yes", "type": "stdin_stdout" }, { "fn_name": null, "input": "75", "output": "No", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: Heading ##There are two integers A and B. You are required to compute the bitwise AND amongst all natural numbers lying between A and B, both inclusive. Input Format First line of the input contains T, the number of testcases to follow. Each te...
```python ''' # Read input from stdin and provide input before running code name = raw_input('What is your name?\n') print 'Hi, %s.' % name ''' #print 'Hello World!' import sys t = input() t = int(t) while (t > 0): t = t -1 input = input() n = int(input.split()[0]) m = int(input.split()[1]) ans = n print(str(ans...
vfc_86121
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "50\n170459136 170524671\n40173568 40239103\n105250816 105316351\n104267776 104333311\n125566976 125632511\n227934208 227999743\n235012096 235077631\n206700544 206766079\n655360 720895\n234094592 234160127\n27525120 27590655\n239140...
taco
verifiable_code
https://www.codechef.com/problems/WGHTS
Solve the following coding problem using the programming language python: Chef is playing with weights. He has an object weighing W units. He also has three weights each of X, Y, and Z units respectively. Help him determine whether he can measure the exact weight of the object with one or more of these weights. If it...
```python for _ in range(int(input())): (w, x, y, z) = map(int, input().split()) if w == x or w == y or w == z: print('YES') elif x + y + z == w or x + y == w or y + z == w or (x + z == w): print('YES') else: print('NO') ```
vfc_86125
{ "difficulty": "easy", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/WGHTS", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n5 2 1 6\n7 9 7 2\n20 8 10 12\n20 10 11 12\n", "output": "NO\nYES\nYES\nNO\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/429/C
Solve the following coding problem using the programming language python: Iahub and Iahubina went to a picnic in a forest full of trees. Less than 5 minutes passed before Iahub remembered of trees from programming. Moreover, he invented a new problem and Iahubina has to solve it, otherwise Iahub won't give her the foo...
```python def DFS(x): for i in range(x): if Seen[i][x]: continue if Rem[i] >= C[x]: if Rem[i] == C[x] and len(Children[i]) == 0: continue Rem[i] -= C[x] Parent[x] = i Children[i].append(x) return True for i in range(x): if Seen[i][x]: continue Y = [] for j in range(len(Children[i]))...
vfc_86129
{ "difficulty": "hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/429/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n1 1 1 4\n", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n1 1 5 2 1\n", "output": "NO", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/palindrome0746/1
Solve the following coding problem using the programming language python: Given an integer, check whether it is a palindrome or not. Example 1: Input: n = 555 Output: Yes Example 2: Input: n = 123 Output: No Your Task: You don't need to read or print anything. Your task is to complete the function is_palindrome() wh...
```python class Solution: def is_palindrome(self, n): self.n = n n = str(n) strait = n.strip() reverse = strait[::-1] n = int(n) if strait == reverse: return 'Yes' else: return 'No' ```
vfc_86133
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/palindrome0746/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "n = 555", "output": "Yes", "type": "stdin_stdout" }, { "fn_name": null, "input": "n = 123", "output": "No", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/multiply-two-linked-lists/1
Solve the following coding problem using the programming language python: Given elements as nodes of the two linked lists. The task is to multiply these two linked lists, say L_{1} and L_{2}. Note: The output could be large take modulo 10^{9}+7. Example: Input: 2 2 3 2 1 2 3 1 0 0 2 1 0 Output: 64 1000 Explanation: ...
```python MOD = 10 ** 9 + 7 def multiplyTwoList(head1, head2): no_1 = '' no_2 = '' i = head1 while i: no_1 += str(i.data) i = i.next j = head2 while j: no_2 += str(j.data) j = j.next ans = int(no_1) * int(no_2) ans = str(ans % (10 ** 9 + 7)) return ans ```
vfc_86134
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/multiply-two-linked-lists/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\r\n2\r\n3 2\r\n1\r\n2\r\n3\r\n1 0 0\r\n2\r\n1 0", "output": "64\r\n1000", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/PBK02020/problems/ITGUY11
Solve the following coding problem using the programming language python: For Diwali, Chef arranges all $K$ laddus in a row in his sweet shop. Whenever a customer comes to buy laddus, chef follows a rule that each customer must buy all laddus on odd position. After the selection of the laddu, a new row is formed, and ...
```python t = int(input()) while t > 0: n = int(input()) if n == 1: print(1) else: (c, num) = (1, 2) while num < n: num *= 2 if num == n: print(num) else: print(num // 2) t -= 1 ```
vfc_86136
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/PBK02020/problems/ITGUY11", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1\n5\n8\n", "output": "1\n4\n8\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/CMR12121/problems/DGLST
Solve the following coding problem using the programming language python: Given a number n. Find the last two digits of 5 ^ n ( 5 to the power of n ). Remember that overflow can occur. -----Input:----- - N — the power in which you need to raise number 5. -----Output:----- Last two digits of 5^n. -----Constraints--...
```python print(25) ```
vfc_86140
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/CMR12121/problems/DGLST", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n", "output": "25\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: Little chandu is very fond of playing games. Recently, He found a few straws each of length 1 inches in the store room. He took all of them and decided to mark a rectangular area on the floor with straws and warn rest of the family members to no...
```python a=int(input()) for i in range(a): n=int(input()) #print 'n is %d' % n flag='N' l=n/4 #print 'l is %d' % l x=(n-2)/4 b=x+1 #print 'x is %d ' % x #print 'printing %s' % (2*x+2*b) if 2*x+2*b <= n and x*b > l*l: flag='Y' #print 'flag is set' if flag =='Y': print(x*b) else: print(l*l) ```
vfc_86144
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "25000\n6202244\n200868\n26\n82646\n8840688\n266\n4\n8644\n884\n62\n6\n2482\n80\n6\n80\n2480\n2\n6844\n42\n80888\n228\n64462\n4\n2\n2068488\n2602\n466\n18060\n8600828\n6\n6\n66440\n248468\n3408\n926\n408\n18208\n42428\n424\n86\n4444...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/candy/1
Solve the following coding problem using the programming language python: There are N children standing in a line. Each child is assigned a rating value given in the integer array ratings. You are giving candies to these children subjected to the following requirements: Each child must have atleast one candy. Childr...
```python class Solution: def minCandy(self, N, ratings): L = [1] * len(ratings) R = [1] * len(ratings) for i in range(1, len(ratings)): if ratings[i] > ratings[i - 1]: L[i] += L[i - 1] for i in range(len(ratings) - 2, -1, -1): if ratings[i] > ratings[i + 1]: R[i] += R[i + 1] cnd = 0 for i i...
vfc_86148
{ "difficulty": "medium_hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/candy/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 3\r\n\r\nratings [ ] = {1, 0, 2}", "output": "5", "type": "stdin_stdout" }, { "fn_name": null, "input": "N = 3\r\n\r\nratings [ ] = {1, 2, 2}", "output": "4", "type": "stdin_stdout" ...
taco
verifiable_code
https://www.codechef.com/problems/ONP
Solve the following coding problem using the programming language python: Reverse Polish Notation (RPN) is a mathematical notation where every operator follows all of its operands. For instance, to add three and four, one would write "3 4 +" rather than "3 + 4". If there are multiple operations, the operator is given ...
```python def main(string): stack = [] s = '' for _ in string: if ord(_) in range(97, 123): s += _ elif _ == ')': if stack != []: s += stack[-1] del stack[-1] elif _ == '(': continue else: stack.append(_) print(s) for _ in range(int(input())): t = str(input()) main(t) ```
vfc_86149
{ "difficulty": "easy", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/ONP", "time_limit": "2.495 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n(a+(b*c))\n((a+b)*(z+x))\n((a+t)*((b+(a+c))^(c+d)))\n", "output": "abc*+\nab+zx+*\nat+bac++cd+^*\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/625/D
Solve the following coding problem using the programming language python: Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. L...
```python def digits(n): rd = [] while n: (n, d) = divmod(n, 10) rd.append(d) return list(reversed(rd)) def _ifs(dn, i, j, ci, cj, al, ar): while i < j: di = dn[i] + 10 * ci dj = dn[j] - cj for (ci, cj) in ((0, 0), (0, 1), (1, 0), (1, 1)): d = di - ci if d < 0 or d > 18: continue if dj + 10 ...
vfc_86153
{ "difficulty": "very_hard", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/625/D", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "110401\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1738464936\n", "output": "869281968", "type": "stdin_stdout" }, { "fn_name": null, "...
taco
verifiable_code
https://www.codechef.com/problems/CHCOINSG
Solve the following coding problem using the programming language python: Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Chef is playing a game with his friend Misha. They have a pile containg N coins. Players take alternate turns, removing some coins from the pile. On each turn, a pla...
```python for i in range(int(input())): t = int(input()) if t % 6 == 0: print('Misha') else: print('Chef') ```
vfc_86157
{ "difficulty": "medium", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/CHCOINSG", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n1\n8", "output": "Chef\nChef", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n0\n8", "output": "Misha\nChef\n", "type": "stdin_stdout" }, { "fn_name": null, ...
taco
verifiable_code
https://codeforces.com/problemset/problem/1213/C
Solve the following coding problem using the programming language python: Polycarp is reading a book consisting of $n$ pages numbered from $1$ to $n$. Every time he finishes the page with the number divisible by $m$, he writes down the last digit of this page number. For example, if $n=15$ and $m=5$, pages divisible b...
```python for i in range(int(input())): (n, m) = list(map(int, input().split())) l = [m % 10] for i in range(9): l.append((l[-1] + m % 10) % 10) a = n // m b = a // 10 ans = b * sum(l) for i in range(a % 10): ans += l[i] print(ans) ```
vfc_86161
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1213/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7\n1 1\n10 1\n100 3\n1024 14\n998244353 1337\n123 144\n1234312817382646 13\n", "output": "1\n45\n153\n294\n3359835\n0\n427262129093995\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "7\n1 ...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/poisioned-sweet2651/1
Solve the following coding problem using the programming language python: An enemy spy has poisoned one out of N sweets in a bakery. Even a bite of the poisoned sweet has potency to kill. However, the effects of the poison show only in 30 days. The managers asks the jailor to identify the poisoned sweet within 30 days...
```python class Solution: def numOfPrisoners(self, N): if N == 1: return 0 c = int(math.log2(N)) if 2 ** c < N: c += 1 return c ```
vfc_86165
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/poisioned-sweet2651/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 3", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "N = 2", "output": "1", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: In Manhattan, roads run where the x or y coordinate is an integer. Both Sunuke-kun's house and Sumeke-kun's house are on the road, and the straight line distance (Euclidean distance) is just d. Find the maximum value that can be considered as th...
```python d = float(input()) ans = max(2 ** 0.5 * d, int(d) + 1) print(ans) ```
vfc_86166
{ "difficulty": "unknown_difficulty", "memory_limit": "268.435456 megabytes", "memory_limit_bytes": null, "problem_url": null, "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1.6623460269048462", "output": "2.3509122966\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.hackerrank.com/challenges/surveillance/problem
Solve the following coding problem using the programming language python: The Academy is a school where each common area is laid out on an $m\times n$ grid and each cell in the grid is $\mbox{1}$ meter by $\mbox{1}$ meter. Danielle is their new head of security, and she wants to place a surveillance camera along every...
```python def modexp(b, e, m): rv = 1 bb = b ee = e while ee > 0: if ee & 1 == 1: rv = rv * bb % m bb = bb * bb % m ee >>= 1 return rv def count(n, m): n1 = (n + 2) // 3 n2 = (n + 1) // 3 n3 = (n + 0) // 3 m1 = (m + 2) // 3 m2 = (m + 1) // 3 m3 = (m + 0) // 3 q = 1000000007 e2_n1 = modexp(2, n1, ...
vfc_86170
{ "difficulty": "hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.hackerrank.com/challenges/surveillance/problem", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n3 3\n3 4\n", "output": "36\n78\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/378/B
Solve the following coding problem using the programming language python: Two semifinals have just been in the running tournament. Each semifinal had n participants. There are n participants advancing to the finals, they are chosen as follows: from each semifinal, we choose k people (0 ≤ 2k ≤ n) who showed the best re...
```python n = int(input()) a = [None] * n b = [None] * n for i in range(n): (a[i], b[i]) = map(int, input().split()) for i in range(n): if i < n // 2 or a[i] < b[n - i - 1]: print(1, end='') else: print(0, end='') print() for i in range(n): if i < n // 2 or b[i] < a[n - i - 1]: print(1, end='') else: print...
vfc_86174
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/378/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n9840 9920\n9860 9980\n9930 10020\n10040 10090\n", "output": "1110\n1100\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n9900 9850\n9940 9930\n10000 10020\n10060 10110\n", "outp...
taco
verifiable_code
https://codeforces.com/problemset/problem/31/D
Solve the following coding problem using the programming language python: Bob has a rectangular chocolate bar of the size W × H. He introduced a cartesian coordinate system so that the point (0, 0) corresponds to the lower-left corner of the bar, and the point (W, H) corresponds to the upper-right corner. Bob decided ...
```python (w, h, n) = list(map(int, input().split())) a = [[0 for i in range(2 * w - 1)] for j in range(2 * h - 1)] for i in range(1, 2 * h - 1, 2): for j in range(1, 2 * w - 1, 2): a[i][j] = ' ' for i in range(n): (x1, y1, x2, y2) = list(map(int, input().split())) if x1 == x2: if x1 != 0 and x1 != w: for j i...
vfc_86178
{ "difficulty": "hard", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/31/D", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10 10 4\n9 0 9 10\n4 0 4 10\n1 0 1 10\n1 4 4 4\n", "output": "10 10 12 18 50 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 5 3\n2 1 2 5\n0 1 5 1\n4 0 4 1\n", "output": "1 4 8 12...
taco
verifiable_code
https://codeforces.com/problemset/problem/1340/C
Solve the following coding problem using the programming language python: If the girl doesn't go to Denis, then Denis will go to the girl. Using this rule, the young man left home, bought flowers and went to Nastya. On the way from Denis's house to the girl's house is a road of n lines. This road can't be always cro...
```python import collections (n, m) = map(int, input().split()) arr = list(map(int, input().split())) arr = sorted(arr) (g, r) = map(int, input().split()) q = collections.deque() q.append((0, 0, 0)) checked = [[-1] * g for _ in range(m)] checked[0][0] = 0 while len(q) != 0: (v, t, cnt) = q.popleft() if v != m - 1: ...
vfc_86182
{ "difficulty": "very_hard", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1340/C", "time_limit": "1.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "15 5\n15 3 7 0 14\n11 11\n", "output": "45", "type": "stdin_stdout" }, { "fn_name": null, "input": "15 5\n15 14 7 3 0\n11 11\n", "output": "45", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/FINDSHOES
Solve the following coding problem using the programming language python: Chef has N friends. Chef promised that he would gift a pair of shoes (consisting of one left shoe and one right shoe) to each of his N friends. Chef was about to go to the marketplace to buy shoes, but he suddenly remembers that he already had M...
```python n = int(input()) for i in range(n): (a, b) = map(int, input().split()) x = a * 2 if b >= a: print(a) elif b == 0: print(x) else: print(x - b) ```
vfc_86186
{ "difficulty": "easy", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/FINDSHOES", "time_limit": "0.5 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n2 4\n6 0\n4 3\n", "output": "2\n12\n5\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1091/E
Solve the following coding problem using the programming language python: Bob is an active user of the social network Faithbug. On this network, people are able to engage in a mutual friendship. That is, if $a$ is a friend of $b$, then $b$ is also a friend of $a$. Each user thus has a non-negative amount of friends. ...
```python def main(): n = int(input()) a = list(map(int, input().split())) a.sort(reverse=True) mod = sum(a) % 2 counts = [0] * (n + 1) for guy in a: counts[guy] += 1 cumcounts = [0] * (n + 1) cumcounts[0] = counts[0] for i in range(n): cumcounts[i + 1] = cumcounts[i] + counts[i + 1] partialsums = [0] * (...
vfc_86190
{ "difficulty": "very_hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1091/E", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n3 3 3\n", "output": "3 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n1 1 1 1\n", "output": "0 2 4 \n", "type": "stdin_stdout" }, { "fn_name": null, ...
taco
verifiable_code
https://www.codechef.com/problems/LEMOUSE
Solve the following coding problem using the programming language python: It is well-known that the elephants are afraid of mouses. The Little Elephant from the Zoo of Lviv is not an exception. The Little Elephant is on a board A of n rows and m columns (0-based numeration). At the beginning he is in cell with coordi...
```python from collections import defaultdict from itertools import product def solve(mouse, n, m): shadow = [[0 for i in range(m)] for j in range(n)] for (i, j) in product(range(n), range(m)): if mouse[i][j] == 1: if i > 0: shadow[i - 1][j] += 1 if j > 0: shadow[i][j - 1] += 1 if i < n - 1: s...
vfc_86195
{ "difficulty": "medium_hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/LEMOUSE", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n3 9\n001000001\n111111010\n100100100\n7 9\n010101110\n110110111\n010011111\n100100000\n000010100\n011011000\n000100101\n", "output": "9\n10\n", "type": "stdin_stdout" }, { "fn_name": null, "input"...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/good-string5712/1
Solve the following coding problem using the programming language python: Given a string s of length N, you have to tell whether it is good or not. A good string is one where the distance between every two adjacent character is exactly 1. Here distance is defined by minimum distance between two character when alphabet...
```python class Solution: def isGoodString(self, s): for i in range(len(s) - 1): dist = abs(ord(s[i]) - ord(s[i + 1])) if dist != 1 and dist != 25: return 'NO' return 'YES' ```
vfc_86199
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/good-string5712/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "s = \"aaa\"", "output": "NO", "type": "stdin_stdout" }, { "fn_name": null, "input": "s = \"cbc\"", "output": "YES", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/COW42020/problems/COW3F
Solve the following coding problem using the programming language python: After the hundred years of war started by the Fire Nation, its time for the Water Tribes to bring it to an end. Avatar asked Sokka to go to the Southern WarZone from The Northern WarZone and gave him some money in a bag for his journey. Sokka ha...
```python m = 1000000007 def gcd(a, b): if a == 0: return b return gcd(b % a, a) def modexp(x, n): if n == 0: return 1 elif n % 2 == 0: return modexp(x * x % m, n // 2) else: return x * modexp(x * x % m, (n - 1) / 2) % m def getFractionModulo(a, b): c = gcd(a, b) a = a // c b = b // c d = modexp(b, ...
vfc_86200
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/COW42020/problems/COW3F", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n5\n2\n", "output": "200000002\n0\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: Rose loves to play games. This problem is about a game he recently played. In the game there are N locations, numbered 0 through N-1. Each location has one entrance and one exit. You are given an array aka A with N elements.For each i, A[i] desc...
```python ''' # Read input from stdin and provide input before running code name = raw_input('What is your name?\n') print 'Hi, %s.' % name ''' #print 'Hello World!' number_of_test_case = input() for i in range(int(number_of_test_case)): number_of_inputs = input() #data=[] #data = raw_input().split(" ") data = [i...
vfc_86204
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "11\n47\n16 38 18 8 24 32 42 45 2 10 30 26 23 -1 15 35 39 46 37 1 33 19 28 44 43 17 5 34 -1 11 40 41 3 13 6 4 7 31 36 21 27 25 29 20 9 14 22\n47\n30 9 24 10 8 36 4 46 2 -1 1 33 17 28 35 5 25 19 22 34 15 26 12 45 29 43 38 14 37 7 40 ...
taco
verifiable_code
https://www.hackerrank.com/challenges/div-and-span/problem
Solve the following coding problem using the programming language python: Maya is teaching Alex about HyperText Markup Language (HTML). Alex is confused about div and span tags, so Maya decides to reduce the concept to a simpler visual by representing div tags as square brackets and span tags as parentheses. In other ...
```python m = 10 ** 9 + 7 p_lim = 201 fact = [1] for i in range(1, 250000): fact.append(fact[-1] * i % m) def egcd(a, b): if a == 0: return (b, 0, 1) else: (g, y, x) = egcd(b % a, a) return (g, x - b // a * y, y) def modinv(a, m): while a < 0: a += m (g, x, y) = egcd(a, m) if g != 1: raise Exception('...
vfc_86208
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.hackerrank.com/challenges/div-and-span/problem", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1 1\n1 2\n2 2\n", "output": "3\n18\n160\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1028/B
Solve the following coding problem using the programming language python: Let s(x) be sum of digits in decimal representation of positive integer x. Given two integers n and m, find some positive integers a and b such that * s(a) ≥ n, * s(b) ≥ n, * s(a + b) ≤ m. Input The only line of input contain two in...
```python def sum_digit(n): c = 0 x = n while x > 0: c += x % 10 x = x // 10 return c (n, m) = map(int, input().split()) r = '5' su = 5 while su < n: r = '4' + r su += 4 r = r[0:len(r) - 1] r += '5' t1 = '' for i in range(len(r)): t1 += '5' print(int(t1)) print(int(r)) ```
vfc_86212
{ "difficulty": "easy", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1028/B", "time_limit": "1.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "578 3\n", "output": "111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/largest-odd-number-in-string/1
Solve the following coding problem using the programming language python: Given an string S, representing a large interger. Return the largest-valued odd integer (as a string) that is substring of the given string S. Note : A substring is a contiguous sequence of characters within a string. Null string ("") is also a ...
```python class Solution: def maxOdd(self, s): for i in range(len(s) - 1, -1, -1): if s[i] in {'1', '3', '5', '7', '9'}: return s[:i + 1] return '' ```
vfc_86217
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/largest-odd-number-in-string/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "s = \"504\"", "output": "\"5\"", "type": "stdin_stdout" }, { "fn_name": null, "input": "s = \"2042\"", "output": "\"\"", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/smallest-k-digit-number-divisible-by-x2351/1
Solve the following coding problem using the programming language python: Given two integers X and K. The task is to find smallest K-digit number divisible by X. Note: It is given that number of digits in X is always smaller or equal to K. Example 1: Input: X = 6, K = 1 Output: 6 Explanation: 6 is the smallest 1 di...
```python class Solution: def smallestKDigitNum(self, X, K): Min = pow(10, K - 1) if Min % X == 0: return Min else: return Min + X - (Min + X) % X ```
vfc_86218
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/smallest-k-digit-number-divisible-by-x2351/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "X = 6, K = 1", "output": "6", "type": "stdin_stdout" }, { "fn_name": null, "input": "X = 5, K = 2", "output": "10", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: The greatest common divisor is an indispensable element in mathematics handled on a computer. Using the greatest common divisor can make a big difference in the efficiency of the calculation. One of the algorithms to find the greatest common div...
```python def solve(): from sys import stdin f_i = stdin ans = '' while True: (a, b) = map(int, f_i.readline().split()) if a == 0 and b == 0: break if a < b: (a, b) = (b, a) cnt = 1 while a % b != 0: cnt += 1 (a, b) = (b, a % b) ans += f'{b} {cnt}\n' print(ans, end='') solve() ```
vfc_86219
{ "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": "1071 1029\n5 3\n0 0", "output": "21 3\n1 3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1251 1029\n5 3\n0 0", "output": "3 8\n1 3\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/MTRICK
Solve the following coding problem using the programming language python: Read problems statements in Mandarin Chinese and Russian. Vidhi went to a magic show last week where she was astounded by a magic trick performed by the great Mandwarf, the brown. His trick was as follows : Ask a volunteer from the audience t...
```python t = int(input().strip()) while t: n = int(input().strip()) l = [int(x) for x in input().strip().split()] (a, b, c) = (int(x) for x in input().strip().split()) S = input().strip() (s, e, i, x, y) = (0, n - 1, 1, 1, 0) for C in S: if C == 'R': (s, e, i) = (e, s, -i) elif C == 'A': y += a y %=...
vfc_86223
{ "difficulty": "medium_hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/MTRICK", "time_limit": "2 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n3\n1 1 1\n2 3 1000\nARM\n4\n1 2 3 4\n0 1 1000\nAMAM", "output": "3 3 9\n1 2 3 4", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n3\n1 1 1\n2 3 1000\nARM\n4\n1 2 3 4\n0 1 1010\nAMAM", ...
taco
verifiable_code
https://www.codechef.com/problems/TASTEDEC
Solve the following coding problem using the programming language python: Chef is buying sweet things to prepare for Halloween! The shop sells both chocolate and candy. Each bar of chocolate has a tastiness of X. Each piece of candy has a tastiness of Y. One packet of chocolate contains 2 bars, while one packet of c...
```python r = int(input()) for i in range(r): s = input() (m, n) = s.split() if 2 * int(m) > 5 * int(n): print('Chocolate') elif 2 * int(m) == 5 * int(n): print('Either') else: print('Candy') ```
vfc_86227
{ "difficulty": "easy", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/TASTEDEC", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n5 1\n5 2\n5 3\n3 10\n", "output": "Chocolate\nEither\nCandy\nCandy\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/PCJ18E
Solve the following coding problem using the programming language python: Chef loves sorting! Chef recently learnt about a new form of sorting, endsort! While performing endsort of an array $A$ of $N$ distinct elements, Chef can move any element to the end of the array. However, Chef fears that this will take too ...
```python t = int(input()) for i in range(t): n = int(input()) l = list(map(int, input().split())) c = [i for i in l] c.sort() j = 0 n = len(l) for i in range(len(l)): if l[i] == c[j]: j += 1 print(n - j) ```
vfc_86232
{ "difficulty": "hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/PCJ18E", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": " 2\n 5\n 1 2 3 4 5\n 5\n 1 3 2 5 4", "output": " 0\n 3", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/ENSPACE
Solve the following coding problem using the programming language python: Chef's computer has N GB of free space. He wants to save X files, each of size 1 GB and Y files, each of size 2 GB on his computer. Will he be able to do so? Chef can save all the files on his computer only if the total size of the files is le...
```python t = int(input()) for i in range(t): (n, x, y) = map(int, input().split()) a = x * 1 b = y * 2 if n < a + b: print('NO') else: print('YES') ```
vfc_86236
{ "difficulty": "easy", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/ENSPACE", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n6 3 1\n2 2 2\n4 3 2\n5 1 2\n", "output": "YES\nNO\nNO\nYES\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/ARRSORT
Solve the following coding problem using the programming language python: You are given an unsorted permutation P of size N. An operation is defined as: Swap P_{i} and P_{i+K} for any i in the range [1,N-K]. Find the maximum value of K, such that, the permutation P can be sorted by applying any finite number of oper...
```python import math t = int(input()) for i in range(t): n = int(input()) l = list(map(int, input().split())) for i in range(1, n + 1): l[i - 1] = abs(l[i - 1] - i) hcf = l[0] for j in range(1, n): hcf = math.gcd(hcf, l[j]) print(hcf) ```
vfc_86241
{ "difficulty": "medium_hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/ARRSORT", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n4\n4 2 3 1\n5\n1 4 3 2 5\n2\n2 1\n", "output": "3\n2\n1\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1696/B
Solve the following coding problem using the programming language python: For a collection of integers $S$, define $\operatorname{mex}(S)$ as the smallest non-negative integer that does not appear in $S$. NIT, the cleaver, decides to destroy the universe. He is not so powerful as Thanos, so he can only destroy the un...
```python for s in [*open(0)][2::2]: print(min(2, len(''.join((' *'[x > '0'] for x in s.split())).split()))) ```
vfc_86246
{ "difficulty": "easy", "memory_limit": "512 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1696/B", "time_limit": "2 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n4\n0 0 0 0\n5\n0 1 2 3 4\n7\n0 2 3 0 1 2 0\n1\n1000000000\n", "output": "0\n1\n2\n1\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: Rajat is a guy who always wants to live in a fantasy world. In his world, a deck consists of X cards, where X is a multiple of 4. There are four types of cards namely spade , heart , club and diamond with each type having values in range of [1,X...
```python T =int(input()) while T: input_list = input().split() output =1.0 /float(input_list[0]) print(format(output,'.10f')) T=T-1 ```
vfc_86250
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "98\n100026500 100010776 19170 diamond\n100024464 99996319 5706 heart\n100005436 99990832 32392 diamond\n100000292 99982871 12383 spade\n100019912 99993613 25668 club\n100004664 99996953 15142 heart\n100006868 99979224 25548 diamond...
taco
verifiable_code
https://codeforces.com/problemset/problem/1201/D
Solve the following coding problem using the programming language python: You are on the island which can be represented as a $n \times m$ table. The rows are numbered from $1$ to $n$ and the columns are numbered from $1$ to $m$. There are $k$ treasures on the island, the $i$-th of them is located at the position $(r_...
```python import bisect (n, m, k, q) = map(int, input().split()) vals = {} vals[1] = [1, 1] for i in range(k): (r, c) = map(int, input().split()) if r not in vals: vals[r] = [c, c] else: vals[r][0] = min(vals[r][0], c) vals[r][1] = max(vals[r][1], c) q = list(map(int, input().split())) q.sort() def find_short...
vfc_86254
{ "difficulty": "hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1201/D", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 3 3 2\n1 1\n2 1\n3 1\n2 3\n", "output": "6", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 5 3 2\n1 2\n2 3\n3 1\n1 5\n", "output": "8", "type": "stdin_stdout" }, { ...
taco
verifiable_code
https://codeforces.com/problemset/problem/980/A
Solve the following coding problem using the programming language python: A necklace can be described as a string of links ('-') and pearls ('o'), with the last link or pearl connected to the first one. $0$ You can remove a link or a pearl and insert it between two other existing links or pearls (or between a link a...
```python def ii(): return int(input()) def ai(): return map(int, input().split()) s = input() p = s.count('-') f = s.count('o') if f is 0: print('YES') return if p % f == 0: print('YES') else: print('NO') ```
vfc_86259
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/980/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "-o-o--\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "-o---\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": null, "input":...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/print-all-bitwise-subsets-of-a-number-n3301/1
Solve the following coding problem using the programming language python: Given a number N, print all the numbers which are a bitwise subset of the binary representation of N. Bitwise subset of a number N will be the numbers i in the range 0 ≤ i ≤ N which satisfy the below condition: N & i == i Example 1: Input: N = 5...
```python class Solution: def printSubsets(self, N): b = [] for i in range(N + 1): if N & i == i: b.append(i) return list(reversed(b)) ```
vfc_86263
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/print-all-bitwise-subsets-of-a-number-n3301/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 5", "output": "5 4 1 0", "type": "stdin_stdout" }, { "fn_name": null, "input": "N = 9", "output": "9 8 1 0", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/664/C
Solve the following coding problem using the programming language python: International Abbreviation Olympiad takes place annually starting from 1989. Each year the competition receives an abbreviation of form IAO'y, where y stands for some number of consequent last digits of the current year. Organizers always pick a...
```python from __future__ import print_function dic = {'9': '1989', '0': '1990', '1': '1991', '2': '1992', '3': '1993', '4': '1994', '5': '1995', '6': '1996', '7': '1997', '8': '1998'} def get_year(s): length = len(s) if len(s) == 1: return dic[s] pos = [s] pre = 1 if s[0] == '0' or len(s) < 4 or (len(s) == 4 a...
vfc_86264
{ "difficulty": "hard", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/664/C", "time_limit": "1.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\nIAO'113098\n", "output": "1113098\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\nIAO'021113099\n", "output": "1021113099\n", "type": "stdin_stdout" }, { "f...
taco
verifiable_code
https://codeforces.com/problemset/problem/54/C
Solve the following coding problem using the programming language python: In the probability theory the following paradox called Benford's law is known: "In many lists of random numbers taken from real sources, numbers starting with digit 1 occur much more often than numbers starting with any other digit" (that's the ...
```python def num_ones(a, b): if a == 0: if b == 0: return 0 ans = 0 b = str(b) for i in range(1, len(b)): ans += 10 ** (i - 1) if b[0] == '1': x = b[1:] if x == '': x = 0 else: x = int(x) ans += x + 1 else: ans += 10 ** (len(b) - 1) return ans return num_ones(0, b) - num_on...
vfc_86272
{ "difficulty": "hard", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/54/C", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n1 1000000000000000000\n50\n", "output": "0.111111111111111\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n1 1\n100\n", "output": "1.000000000000000\n", "type": "stdin_st...
taco
verifiable_code
https://codeforces.com/problemset/problem/1177/A
Solve the following coding problem using the programming language python: Let's write all the positive integer numbers one after another from $1$ without any delimiters (i.e. as a single string). It will be the infinite sequence starting with 123456789101112131415161718192021222324252627282930313233343536... Your tas...
```python def main(): req = ''.join((str(x) for x in range(1, 10001))) k = int(input()) print(int(req[k - 1])) main() ```
vfc_86277
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1177/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7\n", "output": "7\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "21\n", "output": "5\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n", ...
taco
verifiable_code
https://www.hackerrank.com/challenges/pylons/problem
Solve the following coding problem using the programming language python: Goodland is a country with a number of evenly spaced cities along a line. The distance between adjacent cities is $unrecognized$ unit. There is an energy infrastructure project planning meeting, and the government needs to know the fewest numb...
```python from sys import stderr ([n, k], c) = (map(int, input().split()), list(map(int, input().split()))) (ans, last) = (0, 0) while last < n: i = max([last - k] + [j for j in range(max(0, last - k + 1), min(n, last + k)) if c[j]]) if i == last - k: ans = -1 break ans += 1 last = i + k print(ans) ```
vfc_86285
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.hackerrank.com/challenges/pylons/problem", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6 2 \n0 1 1 1 1 0 \n", "output": "2\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1437/A
Solve the following coding problem using the programming language python: You got a job as a marketer in a pet shop, and your current task is to boost sales of cat food. One of the strategies is to sell cans of food in packs with discounts. Suppose you decided to sell packs with $a$ cans in a pack with a discount an...
```python def inp(): return int(input()) def inlt(): return list(map(int, input().split())) def insr(): s = input() return list(s[:len(s) - 1]) def invr(): return map(int, input().split()) test = inp() matrix = [] for i in range(test): t = inlt() matrix.append(t) for i in range(test): if int(matrix[i][0]) > ...
vfc_86289
{ "difficulty": "easy", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1437/A", "time_limit": "1 second" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n3 4\n1 2\n120 150\n", "output": "YES\nNO\nYES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n500000000 1000000000\n", "output": "NO\n", "type": "stdin_stdout" }, ...
taco
verifiable_code
Solve the following coding problem using the programming language python: Shivam is a genious, as you all know..:P Recently he discovered that every whole number in the universe can be represented as the sum of three numbers 1, 3 and 4. He was so much fascinated by the fact, that he began to write every number as sum ...
```python #see the editorial... x=[] x.append(0) x.append(1) x.extend([1,2,4]) m=10**7+7 for i in range(5,1000007): x.append((x[i-1]+x[i-3]+x[i-4])%m) for _ in range(eval(input())): print(x[eval(input())]) ```
vfc_86293
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10\n9\n6\n13\n3\n13\n12\n7\n3\n3\n2", "output": "6\n169\n4\n169\n6\n25\n9\n25\n4\n2", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n5\n12\n4\n12\n5\n8\n6\n8\n4\n3", "output": "40\n...
taco
verifiable_code
https://www.codechef.com/problems/INDEP
Solve the following coding problem using the programming language python: Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. You are given a graph $G$ with $N$ vertices (numbered $1$ through $N$) and $M$ edges. You should partition the vertices of $G$ into two sets $A$ and ...
```python lii = lambda x: list(map(x, input().split())) iip = lambda : int(input()) from fractions import Fraction from collections import defaultdict, deque def solve(): (n, m) = lii(int) graph = defaultdict(list) for i in range(m): (u, v) = lii(int) graph[u].append(v) graph[v].append(u) seta = defaultdict(...
vfc_86297
{ "difficulty": "very_hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/INDEP", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n5 7\n1 3\n1 4\n1 5\n2 3\n2 4\n2 5\n3 4", "output": "1\n11000", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1707/B
Solve the following coding problem using the programming language python: You are given an array $a$ consisting of $n$ non-negative integers. It is guaranteed that $a$ is sorted from small to large. For each operation, we generate a new array $b_i=a_{i+1}-a_{i}$ for $1 \le i < n$. Then we sort $b$ from small to large...
```python from collections import defaultdict, OrderedDict InputList = lambda Dtype: [Dtype(x) for x in input().split()] import bisect def solve(): N = int(input()) nums = InputList(int) n_zeros = bisect.bisect(nums, 0) nums = nums[n_zeros:] if not nums: return 0 for _ in range(N - 1): diff = [] if n_zeros...
vfc_86301
{ "difficulty": "hard", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1707/B", "time_limit": "1 second" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n3\n1 10 100\n4\n4 8 9 13\n5\n0 0 0 8 13\n6\n2 4 8 16 32 64\n7\n0 0 0 0 0 0 0\n", "output": "81\n3\n1\n2\n0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n104\n1 1 1 1 1 1 1 1 1 1 1 ...
taco
verifiable_code
Solve the following coding problem using the programming language python: Little Deepu and Little Kuldeep are the two best warriors in the realm of Westeros. But, their priorities and their loyalties are very much divided. Little Kuldeep fights for the right, just while Little Deepu fights for the wrong reasons, and s...
```python # Binomial coefficient with mod inverse of prime. Calculate binom (n, r) % p. MAXN = 2000005 MOD = 1000000007 f = [0] * MAXN def binom (n, r, p): # print binom (10 ** 18, 2545354543534, 9973) if n < 0 or r < 0 or n < r: return 0 # Precalculate factorial. if f [0] != 1: # Factorial already precalculated...
vfc_86305
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1000\n712336\n407965\n178170\n57817\n258862\n797700\n241152\n865167\n154689\n87726\n681719\n402872\n153826\n369021\n982749\n849277\n644029\n233735\n669348\n736216\n719060\n616122\n102632\n293092\n863134\n392404\n768184\n821631\n123...
taco
verifiable_code
Solve the following coding problem using the programming language python: Turtle Shi-ta and turtle Be-ko decided to divide a chocolate. The shape of the chocolate is rectangle. The corners of the chocolate are put on (0,0), (w,0), (w,h) and (0,h). The chocolate has lines for cutting. They cut the chocolate only along ...
```python from bisect import bisect_left while True: (n, m, w, h, S) = map(int, input().split()) if n == 0: break (m, wh2) = (m + 1, 2 * (w * h)) S = wh2 - 2 * S (tbl, s) = ([[0, 0, 0, 0]], [0]) for i in range(1, m): (l, r) = map(int, input().split()) tbl.append([l, r, 0, r - l]) s.append((l + r) * w) p ...
vfc_86310
{ "difficulty": "unknown_difficulty", "memory_limit": "134.217728 megabytes", "memory_limit_bytes": null, "problem_url": null, "time_limit": "4.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 3 10 10 50\n3 3\n6 6\n10 10\n4.0000000000 4.0000000000\n7.0000000000 7.0000000000\n2 3 10 10 70\n3 3\n6 6\n10 10\n4.0000000000 4.0000000000\n7.0000000000 7.0000000000\n2 3 10 10 30\n3 3\n6 6\n10 10\n4.0000000000 4.0000000000\n7.0...
taco
verifiable_code
https://www.hackerrank.com/challenges/easy-math/problem
Solve the following coding problem using the programming language python: Charlie and Johnny play a game. For every integer X Charlie gives, Johnny has to find the smallest positive integer Y, such that X * Y contains only 4's and 0's and starts with one or more 4's followed by zero or more 0's. (i.e.), 404 is an inva...
```python from fractions import gcd from collections import Counter testcases = int(input()) def factorization(n): facts = Counter() while not n % 2: facts.update({2: 1}) n //= 2 tryval = 3 while tryval ** 2 <= n: while not n % tryval: facts.update({tryval: 1}) n //= tryval tryval += 2 if n > 1: f...
vfc_86314
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.hackerrank.com/challenges/easy-math/problem", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n4\n5\n80\n", "output": "2\n3\n4\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/670/A
Solve the following coding problem using the programming language python: On the planet Mars a year lasts exactly n days (there are no leap years on Mars). But Martians have the same weeks as earthlings — 5 work days and then 2 days off. Your task is to determine the minimum possible and the maximum possible number of...
```python n = int(input()) print(2 * (n // 7) + n % 7 // 6, 2 * ((n + 5) // 7) + (n + 5) % 7 // 6) ```
vfc_86318
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/670/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "14\n", "output": "4 4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n", "output": "0 2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n", ...
taco
verifiable_code
https://codeforces.com/problemset/problem/914/B
Solve the following coding problem using the programming language python: Edogawa Conan got tired of solving cases, and invited his friend, Professor Agasa, over. They decided to play a game of cards. Conan has n cards, and the i-th card has a number a_{i} written on it. They take turns playing, starting with Conan. ...
```python n = int(input()) arr = [0] * 100001 inp = [i for i in map(int, input().split())] for i in range(0, n): arr[inp[i]] += 1 for i in range(100000, -1, -1): if arr[i] % 2 == 1: print('Conan') exit(0) print('Agasa') ```
vfc_86322
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/914/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n4 5 7\n", "output": "Conan\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1 1\n", "output": "Agasa\n", "type": "stdin_stdout" }, { "fn_name": null, "...
taco
verifiable_code
https://codeforces.com/problemset/problem/1767/D
Solve the following coding problem using the programming language python: $2^n$ teams participate in a playoff tournament. The tournament consists of $2^n - 1$ games. They are held as follows: in the first phase of the tournament, the teams are split into pairs: team $1$ plays against team $2$, team $3$ plays against ...
```python import sys import re import math from math import log2 from math import log from math import ceil from math import gcd from decimal import * from datetime import date from collections import deque import random import heapq import itertools import datetime const = 1000000007 ep = 1e-08 def get(): return lis...
vfc_86327
{ "difficulty": "medium", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1767/D", "time_limit": "2 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n101\n", "output": "4 5 6 7 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n1\n", "output": "2 ", "type": "stdin_stdout" }, { "fn_name": null, "input": ...
taco
verifiable_code
https://www.codechef.com/CACD2020/problems/PPPR
Solve the following coding problem using the programming language python: Pushkar is very good in Number Theory. He takes two numbers $A\ and\ B$ and declares them a Pushkar Pair. Pushkar Pair has a property that $A$ has a $Modular\ Inverse$ modulo $B$. He asks you to tell him the largest number $L$ that divides bot...
```python import math for i in range(int(input())): (a, b) = map(int, input().split()) print(math.gcd(a, b)) ```
vfc_86332
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/CACD2020/problems/PPPR", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n3 4\n", "output": "1\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/229/A
Solve the following coding problem using the programming language python: You are given a table consisting of n rows and m columns. Each cell of the table contains a number, 0 or 1. In one move we can choose some row of the table and cyclically shift its values either one cell to the left, or one cell to the right. T...
```python import sys (n, m) = map(int, input().split()) mp = ['' for i in range(n)] f = [[0 for j in range(m)] for i in range(n)] for i in range(n): mp[i] = input() if mp[i].find('1') == -1: print(-1) sys.exit() tmp = mp[i][::-1].find('1') + 1 for j in range(m): if mp[i][j] == '1': f[i][j] = 0 else: f...
vfc_86337
{ "difficulty": "medium", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/229/A", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 1\n0\n0\n0\n0\n0\n", "output": "-1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1\n0\n", "output": "-1\n", "type": "stdin_stdout" }, { "fn_name": null, ...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/shortest-uncommon-subsequence5746/1
Solve the following coding problem using the programming language python: Given two strings S and T, find length of the shortest subsequence in S which is not a subsequence in T. If no such subsequence is possible, return -1. A subsequence is a sequence that appears in the same relative order, but not necessarily cont...
```python class Solution: def __init__(self): self.indices = {} def shortestUnSub(self, S, T): m = len(S) n = len(T) dp = [[0] * (n + 1) for _ in range(m + 1)] for i in range(n + 1): dp[0][i] = 501 for i in range(1, m + 1): dp[i][0] = 1 for i in range(1, m + 1): for j in range(1, n + 1): ...
vfc_86341
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/shortest-uncommon-subsequence5746/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "S = \"babab\"\r\nT = \"babba\"", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "S = \"babhi\"\r\nT = \"babij\"", "output": "1", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/CUCRLINE
Solve the following coding problem using the programming language python: While playing in the plains, Chef found a point A with coordinates (X, Y). Chef is interested in finding the number of [straight lines] passing through the point A such that their [intercepts] on both axes are positive integers. ------ Input...
```python import math (x, y) = map(int, input().split()) n = x * y ans = 1 for i in range(2, int(math.sqrt(n)) + 2): if i > math.sqrt(n) + 1: break if n % i == 0: count = 0 while n % i == 0: n = n // i count += 1 ans *= count + 1 if n > 1: ans *= 2 print(ans) ```
vfc_86342
{ "difficulty": "very_hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/CUCRLINE", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 2", "output": "4", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: How many different ways can you make change for an amount, given a list of coins? In this problem, your code will need to efficiently compute the answer. Task Write a program that, given An amount N and types of infinite available coins M. A...
```python sl = input().split() N,M = (int(sl[0]),int(sl[1])) lis = [int(_) for _ in input().split()] arr = [[0]*M for _ in range(N+1)] for i in range(M): arr[0][i] = 1 for i in range(1,N+1): for j in range(M): #lis[M] has to be added x = arr[i-lis[j]][j] if i-lis[j] >=0 else 0 #lis[M] not to be added y = arr[...
vfc_86351
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 3\n1 2 3", "output": "4", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/664/A
Solve the following coding problem using the programming language python: Greatest common divisor GCD(a, b) of two positive integers a and b is equal to the biggest integer d such that both integers a and b are divisible by d. There are many efficient algorithms to find greatest common divisor GCD(a, b), for example, ...
```python def solution(l1): if l1[0] == l1[1]: return l1[0] else: return 1 def answer(): l1 = [int(x) for x in input().split()] print(solution(l1)) answer() ```
vfc_86361
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/664/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 2\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576\n", "output...
taco
verifiable_code
https://www.codechef.com/BGS12020/problems/BSPSTR
Solve the following coding problem using the programming language python: Teddy and Freddy are two friends. Teddy has a pile of strings of size $N$. Each string $Si$ in the pile has length less or equal to $100$ ($len(Si) \leq 100$). Teddy and Freddy like playing with strings. Teddy gives Freddy a string $B$ of size ...
```python n = int(input()) l = [] for i in range(n): l.append(input()) m = int(input()) s = input() c = 0 res = [s[i:j] for i in range(len(s)) for j in range(i + 1, len(s) + 1)] res = list(dict.fromkeys(res)) for i in res: if i in l: c = c + 1 print(c) ```
vfc_86365
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/BGS12020/problems/BSPSTR", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\na\nabc\nabcd\nabcde\n5\naaaaa\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\na\naa\naaa\naaaa\n5\naaaaa\n", "output": "4\n", "type": "stdin_stdout" ...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/n-divisors5123/1
Solve the following coding problem using the programming language python: Given three integers A, B, N. Your task is to print the number of numbers between A and B including them, which have N-divisors. A number is called N-divisor if it has total N divisors including 1 and itself. Example 1: Input: A = 1 B = 7 N = ...
```python class Solution: def count(self, A, B, N): ans = 0 for x in range(A, B + 1): count = 0 i = 1 while i * i <= x: if x % i == 0: count += 1 if x // i != i: count += 1 if count > N: break i += 1 if count == N: ans += 1 return ans ```
vfc_86369
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/n-divisors5123/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "A = 1\nB = 7\nN = 2", "output": "4", "type": "stdin_stdout" }, { "fn_name": null, "input": "A = 1\nB = 25\nN = 3", "output": "3", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/DESTCELL
Solve the following coding problem using the programming language python: Anas is playing an amazing game on a grid with $N$ rows and $M$ columns. The rows are numbered $1$ through $N$ from top to bottom and the columns are numbered $1$ through $M$ from left to right. Anas wants to destroy this grid. To do that, he wa...
```python for x in range(int(input())): (n, m) = map(int, input().split()) y = n * m l = [] for x in range(n * m): p = x + 1 if y % p == 0: ans = 2 * (y // p) else: ans = 2 * (y // p + 1) mu = 0 while mu < y: n1 = mu // m m1 = mu % m y2 = m1 * n + n1 if y2 % (x + 1) == 0: ans -= 1 ...
vfc_86370
{ "difficulty": "hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/DESTCELL", "time_limit": "2.5 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n2 3\n", "output": "6 4 3 3 2 1\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/624/C
Solve the following coding problem using the programming language python: One day student Vasya was sitting on a lecture and mentioned a string s1s2... sn, consisting of letters "a", "b" and "c" that was written on his desk. As the lecture was boring, Vasya decided to complete the picture by composing a graph G with t...
```python (n, m) = map(int, input().split()) s = [[0] * n for i in range(n)] for i in range(m): (a, b) = map(int, input().split()) s[a - 1][b - 1] = 1 s[b - 1][a - 1] = 1 for i in range(n): s[i][i] = 1 answer = [0] * n for i in range(n): flag = True for j in range(n): if s[i][j] == 0: flag = False if flag: ...
vfc_86378
{ "difficulty": "medium_hard", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/624/C", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 3\n1 3\n2 4\n3 4\n", "output": "No\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 4\n3 2\n1 3\n6 5\n4 6\n", "output": "No\n", "type": "stdin_stdout" }, { "fn...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/number-of-paths-in-a-matrix-with-k-coins2728/1
Solve the following coding problem using the programming language python: Given a N x N matrix such that each of its cells contains some coins. Count the number of ways to collect exactly K coins while moving from top left corner of the matrix to the bottom right. From a cell (i, j), you can only move to (i+1, j) or (...
```python class Solution: def util(self, a, i, j, n, m, k): global dp if i >= n or j >= m or k < 0: return 0 if i == n - 1 and j == m - 1: if k - a[i][j] == 0: return 1 return 0 if dp[i][j][k] != -1: return dp[i][j][k] dp[i][j][k] = self.util(a, i + 1, j, n, m, k - a[i][j]) + self.util(a, i,...
vfc_86382
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/number-of-paths-in-a-matrix-with-k-coins2728/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "K = 12, N = 3\r\narr[] = [[1, 2, 3], \r\n [4, 6, 5], \r\n [3, 2, 1]]", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "K = 16, N = 3\r\narr[] = [[1, 2, 3], \r\n ...
taco
verifiable_code
https://www.codechef.com/FEB16/problems/CHEFDETE
Solve the following coding problem using the programming language python: Chef is a private detective. He was asked to investigate a case of murder in the city of Frangton. Chef arrived in Frangton to find out that the mafia was involved in the case. Chef spent some time watching for people that belong to the clan and...
```python n = eval(input()) r = list(map(int, input().split())) tree = dict() i = 1 for j in r: c = tree.get(j) if c: tree[j].append(i) else: tree[j] = [i] if not tree.get(i): tree[i] = [] i += 1 s = [] for elem in tree: if not tree[elem]: s.append(str(elem)) print(' '.join(s)) ```
vfc_86383
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/FEB16/problems/CHEFDETE", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n0 1 1 2 2 3\n", "output": "4 5 6\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1043/A
Solve the following coding problem using the programming language python: Awruk is taking part in elections in his school. It is the final round. He has only one opponent — Elodreip. The are $n$ students in the school. Each student has exactly $k$ votes and is obligated to use all of them. So Awruk knows that if a per...
```python n = int(input()) a = list(map(int, input().split())) mayor = max(a) el = sum(a) while mayor > 0: total = 0 for i in range(len(a)): aux = a[i] aux = mayor - aux total = total + aux if total > el: print(mayor) break else: mayor = mayor + 1 ```
vfc_86387
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1043/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n1 1 1 5 1\n", "output": "5", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n2 2 3 2 2\n", "output": "5", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/josephus-problem/1
Solve the following coding problem using the programming language python: Given the total number of persons n and a number k which indicates that k-1 persons are skipped and kth person is killed in circle in a fixed direction. After each operation, the count will start from k+1th person. The task is to choose the safe...
```python class Solution: def josephus_(self, n, k): if n == 0: return 0 else: return (self.josephus_(n - 1, k) + k) % n def josephus(self, n, k): return self.josephus_(n, k) + 1 ```
vfc_86391
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/josephus-problem/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "n = 3 k = 2", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "n = 5 k = 3", "output": "4", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/NQST2020/problems/WINALL
Solve the following coding problem using the programming language python: Congratulations !!! You have successfully completed the heist by looting all the gifts in Santa's locker. Now it's time to decide who gets to take all the gifts, you or the Grinch, there will be no splitting. So you and Grinch decide to play a g...
```python import math def findWinner(n, k): cnt = 0 if n == 1: print('Grinch') elif n & 1 or n == 2: print('Me') else: tmp = n val = 1 while tmp > k and tmp % 2 == 0: tmp //= 2 val *= 2 for i in range(3, int(math.sqrt(tmp)) + 1): while tmp % i == 0: cnt += 1 tmp //= i if tmp > 1: ...
vfc_86394
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/NQST2020/problems/WINALL", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7\n1\n2\n3\n4\n5\n6\n12\n", "output": "Grinch\nMe\nMe\nGrinch\nMe\nGrinch\nMe\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1145/B
Solve the following coding problem using the programming language python: -----Input----- The input contains a single integer $a$ ($1 \le a \le 99$). -----Output----- Output "YES" or "NO". -----Examples----- Input 5 Output YES Input 13 Output NO Input 24 Output NO Input 46 Output YES The input will be st...
```python k = ['', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen'] n = ['', '', 'twenty', 'thirty', 'forty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninety'] a = int(input()) if a < 20: ...
vfc_86398
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1145/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "13\n", "output": "NO\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/cb02d40f50b0113c47cd9036e5f340bb51b32289/1
Solve the following coding problem using the programming language python: Given Preorder, Inorder and Postorder traversals of some tree of size N. The task is to check if they are all of the same tree or not. Example 1: Input: N = 5 preorder[] = {1, 2, 4, 5, 3} inorder[] = {4, 2, 5, 1, 3} postorder[] = {4, 5, 2, 3, 1}...
```python class Solution: def check(self, pre, l1, r1, ino, l2, r2, post, l3, r3): if l2 > r2: return True if pre[l1] != post[r3]: return False try: idx = ino.index(pre[l1]) except ValueError: return False return self.check(pre, l1 + 1, idx - l2 + l1, ino, l2, idx - 1, post, l3, l3 + idx - l2 - ...
vfc_86402
{ "difficulty": "medium_hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/cb02d40f50b0113c47cd9036e5f340bb51b32289/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 5\npreorder[] = {1, 2, 4, 5, 3}\ninorder[] = {4, 2, 5, 1, 3}\npostorder[] = {4, 5, 2, 3, 1}", "output": "Yes", "type": "stdin_stdout" }, { "fn_name": null, "input": "N = 5\npreorder[] = {1, 5, 4,...
taco
verifiable_code
Solve the following coding problem using the programming language python: Given a string of length n s = s1, s2,…, sn and m queries. Each query qk (1 ≤ k ≤ m) is one of four types, "L ++", "L-", "R ++", "R-", and l [for the kth query qk. k] and r [k] are defined below. * L ++: l [k] = l [k-1] + 1, r [k] = r [k-1] * ...
```python def main(): (n, m) = map(int, input().split()) s = input() mem = set() base = ord('a') - 1 mod1 = 1000000007 mod2 = 2147483647 h1 = [0] h2 = [0] for c in s: h1.append((h1[-1] * 27 + ord(c) - base) % mod1) h2.append((h2[-1] * 27 + ord(c) - base) % mod2) pow_mem1 = {0: 1} pow_mem2 = {0: 1} def ...
vfc_86403
{ "difficulty": "unknown_difficulty", "memory_limit": "134.217728 megabytes", "memory_limit_bytes": null, "problem_url": null, "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 6\nbaba\nR++\nL++\nR++\nL++\nR++\nL++", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 4\nabcde\nR++\nR++\nL++\nL--", "output": "3\n", "type": "stdin_stdout" ...
taco
verifiable_code
https://www.hackerrank.com/challenges/reverse-shuffle-merge/problem
Solve the following coding problem using the programming language python: Given a string, $\mbox{A}$, we define some operations on the string as follows: a. $reverse(A)$ denotes the string obtained by reversing string $\mbox{A}$. Example: $\text{reverse()abc''})=\text{"cba''}$ b. $shuffle(A)$ denotes any string tha...
```python from collections import Counter, defaultdict from bisect import bisect def solve(s): word = Counter(s) for (k, v) in word.items(): word[k] = v // 2 revleft = word.copy() (skipped, avail) = (Counter(), Counter()) locs = defaultdict(list) for (i, c) in enumerate(s): locs[c].append(i) ans = [] live ...
vfc_86407
{ "difficulty": "hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.hackerrank.com/challenges/reverse-shuffle-merge/problem", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "eggegg\n", "output": "egg\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "abcdefgabcdefg\n", "output": "agfedcb\n", "type": "stdin_stdout" }, { "fn_name": null, ...
taco
verifiable_code
Solve the following coding problem using the programming language python: Captain Jack Sparrow and Davy Jones are having a furious sword fight to gain the key to the chest containing Davy Jones' heart. Jack wants to kill Davy Jones and live forever as the captain of The Flying Dutchman. On the other hand, Davy Jones w...
```python def py_2(): t = eval(input()) for tt in range(t): freq = [0]*26 s = input() slen = len(s) for i in range(slen): #print ord(s[i])-97 freq[ord(s[i])-97] += 1 c = 0 for i in range(26): if freq[i]%2: c += 1 if c==0: print('JACK') elif c%2: print('JACK') else: print('DAVY ...
vfc_86411
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "100\nhqghumeaylnlfdxfircvscxggbwkfnqduxwfnfozvs\nddddddddddaaaaaaaaaa\nmznimkkasvwsrenzkycxfxtlsgypsfadpooefxzbcoejuvpvaboygpoeylfpbnpljvrvipyamyehwqnqrqpmxujjloovao\nuxwhmsncbxcoksfzkvatx\nknlyjyhfixjswnkkufnuxx\nrzbmnmgqooketlyhn...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/validate-an-ip-address-1587115621/1
Solve the following coding problem using the programming language python: Write a program to Validate an IPv4 Address. According to Wikipedia, IPv4 addresses are canonically represented in dot-decimal notation, which consists of four decimal numbers, each ranging from 0 to 255, separated by dots, e.g., 172.16.254.1 . ...
```python def has_leading_zero(n): if len(n) > 1: if n[0] == '0': return True else: return False def in_range(n): if n >= 0 and n <= 255: return True return False def isValid(s): newstr = s.split('.') flag = 1 if len(newstr) != 4: return 0 for ele in newstr: if len(ele) == 0: return 0 if h...
vfc_86415
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/validate-an-ip-address-1587115621/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": "isValid", "input": "IPv4 address = 222.111.111.111", "output": "1", "type": "function_call" }, { "fn_name": "isValid", "input": "IPv4 address = 5555..555", "output": "0", "type": "function_call" } ...
taco
verifiable_code
https://codeforces.com/problemset/problem/1635/A
Solve the following coding problem using the programming language python: You are given an array $a$ of size $n$. You can perform the following operation on the array: Choose two different integers $i, j$ $(1 \leq i < j \leq n$), replace $a_i$ with $x$ and $a_j$ with $y$. In order not to break the array, $a_i | a_j ...
```python for s in [*open(0)][2::2]: x = 0 print([(x := (x | int(i))) for i in s.split()][-1]) ```
vfc_86416
{ "difficulty": "easy", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1635/A", "time_limit": "1 second" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n3\n1 3 2\n5\n1 2 4 8 16\n2\n6 6\n3\n3 5 6\n", "output": "3\n31\n6\n7\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: Nantendo Co., Ltd. has released a game software called Packet Monster. This game was intended to catch, raise, and fight monsters, and was a very popular game all over the world. This game had features not found in traditional games. There are ...
```python while True: in1 = list(input()) if in1[0] == '-': break in2 = list(input()) out = list(input()) k = in2.pop(0) (ans, f) = ('', True) while len(in1) or len(in2): if len(out) and out[0] == k: k = in1.pop(0) del out[0] else: ans += k if len(in2): k = in2.pop(0) else: f = False...
vfc_86421
{ "difficulty": "unknown_difficulty", "memory_limit": "134.217728 megabytes", "memory_limit_bytes": null, "problem_url": null, "time_limit": "5.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "CBA\ncba\ncCa\nX\nYZ\nZ\n-", "output": "BbA\nYX\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: Chandan is a horrendous murderer and he wants to kill Arjit just because he's lazy. Chandan is following the trail of Arjit's shoes. The trail is in the form of a k-ary tree. Arjit is lazy, sure, but he's smart. So, he magically moves away from...
```python t=int(input()) def bfs(x): b=[False]*(n+1)# an array of false flags to keep track of vertices visited memo=["p"]*(n+1) l=0 c=0 q=[] q.append(x) memo[x]=0 while len(q)!=0: #t=s[-1] top=q.pop(0) #l=t b[top]=True #q.pop(0) for j in G[top]: #print j if memo[j[0]]=="p": q.append(j[0])...
vfc_86425
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n100\n49 40 86\n40 27 47\n27 26 8\n26 56 80\n56 1 74\n1 70 39\n70 23 49\n23 37 85\n37 11 6\n69 51 6\n51 76 56\n76 75 22\n75 65 88\n65 42 72\n42 55 27\n55 90 46\n90 66 7\n66 31 61\n33 95 43\n95 81 1\n81 4 87\n4 35 2\n35 8 95\n8 67...
taco
verifiable_code
https://codeforces.com/problemset/problem/6/E
Solve the following coding problem using the programming language python: There are several days left before the fiftieth birthday of a famous Berland's writer Berlbury. In this connection the local library decided to make an exposition of the works of this famous science-fiction writer. It was decided as well that it...
```python from collections import deque def mini_in_window(A, n, k): d = deque() res = [] for i in range(n): if i >= k and d[0] == i - k: d.popleft() while len(d) and A[d[-1]] >= A[i]: d.pop() d.append(i) if i >= k - 1: res.append(d[0]) return res def maxi_in_window(A, n, k): d = deque() res = ...
vfc_86430
{ "difficulty": "hard", "memory_limit": "64.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/6/E", "time_limit": "1.5 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 10\n35 45\n", "output": "2 1\n1 2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 0\n1000000 1000000 1000000\n", "output": "3 1\n1 3\n", "type": "stdin_stdout" }, {...
taco
verifiable_code
https://codeforces.com/problemset/problem/912/A
Solve the following coding problem using the programming language python: During the winter holidays, the demand for Christmas balls is exceptionally high. Since it's already 2018, the advances in alchemy allow easy and efficient ball creation by utilizing magic crystals. Grisha needs to obtain some yellow, green and...
```python (a, b) = map(int, input().split()) (x, y, z) = map(int, input().split()) s = 0 if 2 * x > a: s += 2 * x - a + y elif 2 * x + y > a: s += 2 * x + y - a if y > b: s += y - b + 3 * z elif y + 3 * z > b: s += y + 3 * z - b print(s) ```
vfc_86434
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/912/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 3\n2 1 1\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 9\n1 1 3\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "in...
taco
verifiable_code
https://www.codechef.com/problems/HDELIVER
Solve the following coding problem using the programming language python: Chef has decided to start home delivery from his restaurant. He hopes that he will get a lot of orders for delivery, however there is a concern. He doesn't have enough work forces for all the deliveries. For this he has came up with an idea - h...
```python def find(parent, i): if parent[i] == i: return i parent[i] = find(parent, parent[i]) return parent[i] def union(parent, rank, x, y): rootx = find(parent, x) rooty = find(parent, y) if rootx != rooty: if rank[rootx] < rank[rooty]: parent[rootx] = rooty elif rank[rootx] > rank[rooty]: parent[...
vfc_86438
{ "difficulty": "medium_hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/HDELIVER", "time_limit": "0.48995 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n4 2\n0 1\n1 2\n3\n0 2\n0 3\n2 1\n\n\n", "output": "YO\nNO\nYO\n", "type": "stdin_stdout" } ] }