Dataset Viewer
Auto-converted to Parquet Duplicate
difficulty
stringclasses
4 values
tags
stringlengths
2
164
skill_types
stringclasses
114 values
fn_mode
stringclasses
2 values
fn_name
stringlengths
0
32
test_cases
stringlengths
31
29.8M
system
stringclasses
1 value
user
stringlengths
546
14.5k
answer
stringlengths
32
413k
source_dataset
stringclasses
1 value
task
stringclasses
1 value
HARD
['Dynamic programming']
['Dynamic programming']
auto
{"input": ["5 3 10\n1 2 3 4 5\nRGBRR\n", "2 1 15\n5 6\nRG\n", "6 1 21\n4 2 3 5 1 6\nRGBGRB\n", "6 1 21\n6 5 4 3 2 1\nRGBRGB\n", "1 1 10\n10\nR\n", "2 1 10\n5 5\nRG\n", "2 1 10\n5 6\nRR\n", "5 3 10\n1 2 3 4 5\nRGBRG\n", "9 1 6\n1 1 1 3 3 3 2 2 2\nRGGBRRGBB\n", "50 39 2000\n48 43 26 24 46 37 15 30 39 34 4 14 29 34 8 18 4...
You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
You will be given a competitive programming problem. Generate an executable Python function generated from the given prompt. Please reason step by step about your solution approach, then provide a complete implementation in Python 3 that is thoroughly optimized for both speed and memory usage. Put your final solution ...
```python INF = 10000000000.0 max_n = 50 max_k = 2000 def main(): (n, s, k) = map(int, input().split()) s -= 1 buf = [''] * (max_n + 1) dp = [[0 for i in range(max_n + 1)] for j in range(max_k + 1)] r = list(map(int, input().split())) c = input() answer = INF for i in range(len(c)): buf[i] = c[i] for i in r...
TACO-verified
code_generation
EASY
['Data structures', 'Mathematics', 'Greedy algorithms']
['Data structures', 'Greedy algorithms']
auto
{"input": ["4\n4\n1 2 3 4\n5\n1 5 2 4 3\n6\n4 2 5 3 6 1\n1\n1\n", "4\n4\n2 1 3 4\n5\n1 5 2 4 3\n6\n4 2 5 3 6 1\n1\n1\n", "4\n4\n2 1 3 4\n5\n1 5 2 4 3\n6\n2 4 5 3 6 1\n1\n1\n", "4\n4\n1 2 3 4\n5\n1 5 2 4 3\n6\n4 2 5 3 6 1\n1\n1\n"], "output": ["4 3 2 1\n5 2 4 3 1\n6 1 5 3 4 2\n1\n", "4 3 2 1\n5 2 4 3 1\n6 1 5 3 4 2\n1\n...
You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
You will be given a competitive programming problem. Generate an executable Python function generated from the given prompt. Please reason step by step about your solution approach, then provide a complete implementation in Python 3 that is thoroughly optimized for both speed and memory usage. Put your final solution ...
```python import heapq from math import sqrt import operator import sys inf_var = 0 if inf_var == 1: inf = open('input.txt', 'r') else: inf = sys.stdin input = inf.readline def read_one_int(): return int(input().rstrip('\n')) def read_list_of_ints(): res = [int(val) for val in input().rstrip('\n').split(' ')] re...
TACO-verified
code_generation
EASY
['String algorithms', 'Fundamentals']
[]
call_based
is_anagram
{"input": [["foefet", "toffee"], ["Buckethead", "DeathCubeK"], ["Twoo", "WooT"], ["dumble", "bumble"], ["ound", "round"], ["apple", "pale"]], "output": [[true], [true], [true], [false], [false], [false]]}
You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
You will be given a competitive programming problem. Generate an executable Python function generated from the given prompt. Please reason step by step about your solution approach, then provide a complete implementation in Python 3 that is thoroughly optimized for both speed and memory usage. Put your final solution ...
```python def is_anagram(test, original): return sorted(original.lower()) == sorted(test.lower()) ```
TACO-verified
code_generation
MEDIUM_HARD
['Dynamic programming', 'Data structures', 'Greedy algorithms']
['Dynamic programming', 'Data structures', 'Greedy algorithms']
auto
{"input": ["3\n0 1 1\n", "4\n0 0 1 2\n", "2\n0 0\n", "4\n0 1 1 0\n", "3\n0 1 0\n", "2\n0 1\n", "8\n0 0 2 0 3 0 3 2\n", "3\n0 1 2\n", "10\n0 0 2 2 3 2 3 3 1 3\n", "6\n0 0 0 2 0 1\n"], "output": ["0\n", "0\n", "0\n", "1\n", "1\n", "0\n", "7\n", "0\n", "4\n", "4\n"]}
You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
You will be given a competitive programming problem. Generate an executable Python function generated from the given prompt. Please reason step by step about your solution approach, then provide a complete implementation in Python 3 that is thoroughly optimized for both speed and memory usage. Put your final solution ...
```python n = int(input()) above = list(map(int, input().split())) total = [x + 1 for x in above] for i in range(0, n - 1)[::-1]: total[i] = max(total[i], total[i + 1] - 1) for i in range(1, n): total[i] = max(total[i], total[i - 1]) below = [t - a - 1 for (t, a) in zip(total, above)] print(sum(below)) ```
TACO-verified
code_generation
EASY
['Greedy algorithms']
['Greedy algorithms']
auto
{"input": ["3\n2\n10\n3\n001\n4\n0100"], "output": ["YES\nNO\nYES"]}
You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
You will be given a competitive programming problem. Generate an executable Python function generated from the given prompt. Please reason step by step about your solution approach, then provide a complete implementation in Python 3 that is thoroughly optimized for both speed and memory usage. Put your final solution ...
```python for i in range(0, int(input())): n = int(input()) l = list(input()) t = 0 a = 0 b = 0 for j in range(0, n): t = t + 1 if l[j] == '0': a = a + 1 else: b = b + 1 if b >= t / 2: print('YES') break elif j == n - 1 and b < t / 2: print('NO') else: continue ```
TACO-verified
code_generation
HARD
['Sorting', 'Constructive algorithms']
['Sorting']
auto
{"input": ["3\n3\n1 1 2\n4\n19 39 19 84\n6\n1 2 3 1 2 3"], "output": ["NO\nYES\n19 19 39 84 \n39 84 19 19 \nYES\n1 1 2 2 3 3 \n2 3 3 1 1 2 "]}
You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
You will be given a competitive programming problem. Generate an executable Python function generated from the given prompt. Please reason step by step about your solution approach, then provide a complete implementation in Python 3 that is thoroughly optimized for both speed and memory usage. Put your final solution ...
```python t = int(input()) for _ in range(t): n = int(input()) l = list(map(int, input().split())) d = {} for i in l: d[i] = d.get(i, 0) + 1 mx = 0 for i in d.values(): if i >= mx: mx = i if len(d) == 2: print('NO') elif n % 2 == 0: if mx <= n // 2: print('YES') l.sort() for i in range(n): ...
TACO-verified
code_generation
HARD
['Dynamic programming', 'Greedy algorithms']
['Dynamic programming', 'Greedy algorithms']
auto
{"input": ["5\n4 3 2 2 3\n", "7\n3 3 4 4 4 3 3\n", "3\n1 3 5\n", "1\n1000\n", "15\n67 67 65 65 66 66 66 68 67 67 67 65 65 66 70\n", "15\n17 17 18 17 16 16 17 17 15 15 13 12 12 14 15\n", "20\n10 6 25 38 8 4 22 40 28 45 23 33 18 39 28 26 40 4 14 47\n", "20\n6 5 5 7 12 12 12 12 7 41 35 28 28 28 28 13 12 12 7 6\n", "20\n6 ...
You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
You will be given a competitive programming problem. Generate an executable Python function generated from the given prompt. Please reason step by step about your solution approach, then provide a complete implementation in Python 3 that is thoroughly optimized for both speed and memory usage. Put your final solution ...
```python from collections import defaultdict, deque from heapq import heappush, heappop from bisect import bisect_left, bisect_right import sys, itertools, math sys.setrecursionlimit(10 ** 5) input = sys.stdin.readline sqrt = math.sqrt def LI(): return list(map(int, input().split())) def LF(): return list(map(floa...
TACO-verified
code_generation
MEDIUM_HARD
['Data structures']
['Data structures']
call_based
findPoisonedDuration
{"input": [[[1, 4], 2]], "output": [4]}
You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
You will be given a competitive programming problem. Generate an executable Python function generated from the given prompt. Please reason step by step about your solution approach, then provide a complete implementation in Python 3 that is thoroughly optimized for both speed and memory usage. Put your final solution ...
```python class Solution: def findPoisonedDuration(self, timeSeries, duration): if not timeSeries: return 0 prev = timeSeries[0] ret = 0 count = 0 for t in timeSeries[1:]: diff = t - prev if diff > duration: count += 1 else: ret += diff prev = t ret += (count + 1) * duration retur...
TACO-verified
code_generation
EASY
[]
[]
call_based
make_acronym
{"input": [["My aunt sally"], ["Please excuse my dear aunt Sally"], ["How much wood would a woodchuck chuck if a woodchuck could chuck wood"], ["Unique New York"], ["a42"], ["1111"], [64], [[]], [{}], [""]], "output": [["MAS"], ["PEMDAS"], ["HMWWAWCIAWCCW"], ["UNY"], ["Not letters"], ["Not letters"], ["Not a string"], ...
You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
You will be given a competitive programming problem. Generate an executable Python function generated from the given prompt. Please reason step by step about your solution approach, then provide a complete implementation in Python 3 that is thoroughly optimized for both speed and memory usage. Put your final solution ...
```python def make_acronym(phrase): try: return ''.join((word[0].upper() if word.isalpha() else 0 for word in phrase.split())) except AttributeError: return 'Not a string' except TypeError: return 'Not letters' ```
TACO-verified
code_generation
EASY
[]
[]
auto
{"input": ["5\nWEEWW\n", "12\nWEWEWEEEWWWE\n", "8\nWWWWWEEE\n"], "output": ["1\n", "4\n", "3\n"]}
You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
You will be given a competitive programming problem. Generate an executable Python function generated from the given prompt. Please reason step by step about your solution approach, then provide a complete implementation in Python 3 that is thoroughly optimized for both speed and memory usage. Put your final solution ...
```python n = int(input()) s = input() cnt = s[1:].count('E') ans = cnt for i in range(1, n): if s[i - 1] == 'W': cnt += 1 if s[i] == 'E': cnt -= 1 ans = min(ans, cnt) print(ans) ```
TACO-verified
code_generation
MEDIUM_HARD
['String algorithms', 'Dynamic programming']
['Dynamic programming']
call_based
minFlipsMonoIncr
{"input": [["\"00110\""]], "output": [2]}
You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
You will be given a competitive programming problem. Generate an executable Python function generated from the given prompt. Please reason step by step about your solution approach, then provide a complete implementation in Python 3 that is thoroughly optimized for both speed and memory usage. Put your final solution ...
```python class Solution: def minFlipsMonoIncr(self, S: str) -> int: onesSoFar = 0 partial = 0 for n in S: if n == '0': partial = min(onesSoFar, partial + 1) else: onesSoFar += 1 return partial ```
TACO-verified
code_generation
MEDIUM
['Bit manipulation', 'Graph algorithms', 'Complete search']
['Bit manipulation', 'Complete search']
auto
{"input": ["7 6\nAlena\nOlya\nVanya\nBrus\nJohn\nAlice\nMariana\nAlena John\nAlena Alice\nOlya John\nOlya Alice\nVanya John\nVanya Alice\n", "7 6\nj\nZ\nPZNeTyY\nm\na\nUj\nsuaaSiKcK\nUj PZNeTyY\na j\nPZNeTyY Z\nPZNeTyY j\nm PZNeTyY\nm j\n", "15 3\na\nYclKFJoaIA\nhalYcB\nbLOlPzAeQ\ntckjt\noDFijpx\nb\npz\nVDLb\nlCEHPibt\...
You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
You will be given a competitive programming problem. Generate an executable Python function generated from the given prompt. Please reason step by step about your solution approach, then provide a complete implementation in Python 3 that is thoroughly optimized for both speed and memory usage. Put your final solution ...
```python tmp = input().split(' ') N_ppl = int(tmp[0]) N_cstrt = int(tmp[1]) ppl_to_id = {} id_ppl = [0] * N_ppl cstrt = [0] * N_ppl for i in range(N_ppl): tmp = input() id_ppl[i] = tmp ppl_to_id[tmp] = i cstrt[i] = [] for i in range(N_cstrt): tmp = input().split() cstrt[ppl_to_id[tmp[0]]].append(ppl_to_id[tmp[1]...
TACO-verified
code_generation
EASY
['Fundamentals', 'Data structures', 'Mathematics']
['Data structures']
call_based
total
{"input": [[[1, 2, 3, 4, 5]], [[1, 2, 3, 4]], [[1, 2, 3]], [[4, 4, 52, 23, 32, 1, -1]], [[4, 4, 5, -1]], [[-1, -1, -1]], [[-1, -1, -10, 42, 92, 1, 23, 6, -3]], [[-1, 1, -1, 1]], [[42]]], "output": [[48], [20], [8], [1753], [30], [-4], [9248], [0], [42]]}
You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
You will be given a competitive programming problem. Generate an executable Python function generated from the given prompt. Please reason step by step about your solution approach, then provide a complete implementation in Python 3 that is thoroughly optimized for both speed and memory usage. Put your final solution ...
```python def total(arr): while len(arr) > 1: arr = [x + y for (x, y) in zip(arr, arr[1:])] return arr[0] ```
TACO-verified
code_generation
EASY
['Fundamentals', 'Data structures']
['Data structures']
call_based
faro_cycles
{"input": [[2], [52], [542], [1250], [1954]], "output": [[1], [8], [540], [156], [30]]}
You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
You will be given a competitive programming problem. Generate an executable Python function generated from the given prompt. Please reason step by step about your solution approach, then provide a complete implementation in Python 3 that is thoroughly optimized for both speed and memory usage. Put your final solution ...
```python def faro_cycles(n): (x, cnt) = (2, 1) while x != 1 and n > 3: cnt += 1 x = x * 2 % (n - 1) return cnt ```
TACO-verified
code_generation
EASY
['String algorithms', 'Fundamentals', 'Data structures']
['Data structures']
call_based
word_search
{"input": [["ab", ["za", "ab", "abc", "zab", "zbc"]], ["aB", ["za", "ab", "abc", "zab", "zbc"]], ["ab", ["za", "aB", "Abc", "zAB", "zbc"]], ["abcd", ["za", "aB", "Abc", "zAB", "zbc"]]], "output": [[["ab", "abc", "zab"]], [["ab", "abc", "zab"]], [["aB", "Abc", "zAB"]], [["None"]]]}
You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
You will be given a competitive programming problem. Generate an executable Python function generated from the given prompt. Please reason step by step about your solution approach, then provide a complete implementation in Python 3 that is thoroughly optimized for both speed and memory usage. Put your final solution ...
```python def word_search(query, seq): return [x for x in seq if query.lower() in x.lower()] or ['None'] ```
TACO-verified
code_generation
MEDIUM
[]
[]
auto
{"input": ["3 2\n", "3 200\n", "100000 100000\n", "2 1000\n", "2 100000\n", "2 1\n", "100000 1\n", "100000 2\n", "99991 99989\n", "36 99291\n"], "output": ["9\n", "10813692\n", "742202979\n", "4449880\n", "434344400\n", "1\n", "1\n", "607723521\n", "215961669\n", "172687341\n"]}
You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
You will be given a competitive programming problem. Generate an executable Python function generated from the given prompt. Please reason step by step about your solution approach, then provide a complete implementation in Python 3 that is thoroughly optimized for both speed and memory usage. Put your final solution ...
```python (N, K) = map(int, input().split()) D = [0] * (K + 1) D[K] = 1 mod = 10 ** 9 + 7 for i in range(K, 0, -1): D[i] = pow(K // i, N, mod) for j in range(2 * i, K + 1, i): D[i] = (D[i] - D[j]) % mod c = 0 for i in range(len(D)): c += D[i] * i print(c % mod) ```
TACO-verified
code_generation
EASY
['Greedy algorithms']
['Greedy algorithms']
auto
{"input": ["2\n3 10\n2 1 3\n7 8 9\n4 5\n1 2 2 1\n3 3 3 4\n"], "output": ["YES\nNO\n"]}
You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
You will be given a competitive programming problem. Generate an executable Python function generated from the given prompt. Please reason step by step about your solution approach, then provide a complete implementation in Python 3 that is thoroughly optimized for both speed and memory usage. Put your final solution ...
```python def isGood(listA, listB, k): n = len(listA) listA.sort() listB.sort(reverse=True) for i in range(n): if listA[i] + listB[i] < k: return False return True T = int(input().strip()) for i in range(T): [n, k] = [int(x) for x in input().strip().split()] listA = [int(x) for x in input().strip().split()]...
TACO-verified
code_generation
MEDIUM_HARD
[]
[]
auto
{"input": ["3\n1 2\n1 3\n", "2\n1 2\n", "5\n1 2\n2 3\n3 4\n3 5\n", "8\n1 2\n2 3\n3 4\n3 5\n3 6\n6 7\n6 8\n", "5\n1 2\n1 3\n3 4\n3 5", "5\n1 2\n1 4\n3 4\n3 5", "5\n1 2\n1 4\n5 4\n3 5", "3\n2 3\n1 3", "5\n1 2\n2 3\n2 4\n3 5", "5\n1 2\n1 5\n3 4\n3 5"], "output": ["2\n1\n1\n", "1\n1\n", "2\n8\n12\n3\n3\n", "40\n280\n840\n1...
You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
You will be given a competitive programming problem. Generate an executable Python function generated from the given prompt. Please reason step by step about your solution approach, then provide a complete implementation in Python 3 that is thoroughly optimized for both speed and memory usage. Put your final solution ...
```python import sys input = sys.stdin.readline from collections import deque nn = 200200 mod = 10 ** 9 + 7 fa = [1] * (nn + 1) fainv = [1] * (nn + 1) inv = [1] * (nn + 1) for i in range(nn): fa[i + 1] = fa[i] * (i + 1) % mod fainv[-1] = pow(fa[-1], mod - 2, mod) for i in range(nn)[::-1]: fainv[i] = fainv[i + 1] * (i...
TACO-verified
code_generation
EASY
['Fundamentals']
[]
call_based
calculate_grade
{"input": [[[92, 94, 99]], [[50, 60, 70, 80, 90]], [[50, 55]]], "output": [["A"], ["C"], ["F"]]}
You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
You will be given a competitive programming problem. Generate an executable Python function generated from the given prompt. Please reason step by step about your solution approach, then provide a complete implementation in Python 3 that is thoroughly optimized for both speed and memory usage. Put your final solution ...
```python from bisect import bisect from statistics import mean def calculate_grade(scores): return 'FDCBA'[bisect([60, 70, 80, 90], mean(scores))] ```
TACO-verified
code_generation
EASY
['Implementation']
[]
auto
{"input": ["5\n3 4 5 6 7\n", "7\n12 13 14 15 14 13 12\n", "1\n8\n", "44\n7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10\n", "92\n3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 ...
You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
You will be given a competitive programming problem. Generate an executable Python function generated from the given prompt. Please reason step by step about your solution approach, then provide a complete implementation in Python 3 that is thoroughly optimized for both speed and memory usage. Put your final solution ...
```python n = int(input()) s = list(map(int, input().split()))[:n] k = -1 if s[n - 1] == 0: print('UP') elif s[n - 1] == 15 or s[n - 2] > s[n - 1]: print('DOWN') elif n == 1: print(k) else: print('UP') ```
TACO-verified
code_generation
EASY
['Implementation']
[]
auto
{"input": ["5 5 5 5 5 5\n", "4 4 4 4 2 2\n", "1 1 2 2 3 4\n", "1 3 3 3 4 5\n", "4 4 5 6 7 8\n", "4 4 4 4 4 5\n", "5 5 5 6 6 6\n", "4 4 2 2 2 2\n", "1 1 3 3 3 5\n", "1 8 9 1 1 1\n"], "output": ["Elephant\n", "Elephant\n", "Alien\n", "Alien\n", "Alien\n", "Bear\n", "Alien\n", "Elephant\n", "Alien\n", "Bear\n"]}
You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
You will be given a competitive programming problem. Generate an executable Python function generated from the given prompt. Please reason step by step about your solution approach, then provide a complete implementation in Python 3 that is thoroughly optimized for both speed and memory usage. Put your final solution ...
```python a = list(map(int, input().split())) for i in range(6): if a.count(a[i]) >= 4: v = a[i] break else: print('Alien') exit() for i in range(4): a.remove(v) a.sort() if a[0] < a[1]: print('Bear') elif a[0] == a[1]: print('Elephant') else: print('Alien') ```
TACO-verified
code_generation
EASY
['String algorithms', 'Fundamentals']
[]
call_based
likes
{"input": [[[]], [["Peter"]], [["Jacob", "Alex"]], [["Max", "John", "Mark"]], [["Alex", "Jacob", "Mark", "Max"]]], "output": [["no one likes this"], ["Peter likes this"], ["Jacob and Alex like this"], ["Max, John and Mark like this"], ["Alex, Jacob and 2 others like this"]]}
You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
You will be given a competitive programming problem. Generate an executable Python function generated from the given prompt. Please reason step by step about your solution approach, then provide a complete implementation in Python 3 that is thoroughly optimized for both speed and memory usage. Put your final solution ...
```python def likes(names): n = len(names) return {0: 'no one likes this', 1: '{} likes this', 2: '{} and {} like this', 3: '{}, {} and {} like this', 4: '{}, {} and {others} others like this'}[min(4, n)].format(*names[:3], others=n - 2) ```
TACO-verified
code_generation
MEDIUM_HARD
['Implementation']
[]
auto
{"input": ["2\n0 0\n0 1\n0 2\n1 0\n1 1\n1 2\n2 0\n2 1\n2 2\n", "2\n0 0\n0 1\n0 2\n0 3\n1 0\n1 2\n2 0\n2 1\n2 2\n", "2\n5 14\n5 17\n25 43\n26 43\n32 41\n33 0\n38 0\n48 17\n48 30\n", "2\n17 44\n19 14\n19 25\n24 27\n32 1\n34 27\n38 1\n45 5\n45 12\n", "2\n1 2\n1 27\n1 45\n10 45\n28 48\n38 1\n44 1\n45 7\n45 26\n", "2\n2 27\...
You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
You will be given a competitive programming problem. Generate an executable Python function generated from the given prompt. Please reason step by step about your solution approach, then provide a complete implementation in Python 3 that is thoroughly optimized for both speed and memory usage. Put your final solution ...
```python from sys import stdin, stdout def rsingle_int(): return int(stdin.readline().rstrip()) def rmult_int(): return [int(x) for x in stdin.readline().rstrip().split()] def r_str(): return stdin.readline().rstrip() def rsingle_char(): return stdin.read(1) def main(): n = rsingle_int() num_p = 4 * n + 1 ...
TACO-verified
code_generation
MEDIUM_HARD
['Graph algorithms']
[]
auto
{"input": ["1\n4 4\n1 2 24\n1 4 20\n3 1 3\n4 3 12\n1\n"], "output": ["24 3 15\n"]}
You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
You will be given a competitive programming problem. Generate an executable Python function generated from the given prompt. Please reason step by step about your solution approach, then provide a complete implementation in Python 3 that is thoroughly optimized for both speed and memory usage. Put your final solution ...
```python import heapq def find(V, N, S): dist = [-1 for x in range(N)] visited = [False for x in range(N)] Q = [(0, S)] dist[S] = 0 while Q: (mindist, minv) = heapq.heappop(Q) if not visited[minv]: for x in V[minv]: if dist[x] == -1: dist[x] = mindist + V[minv][x] else: dist[x] = min(dis...
TACO-verified
code_generation
EASY
['Number theory']
[]
auto
{"input": ["2\n3\n1 2 3\n3\n5 10 5\n"], "output": ["1 2 6 3\n5 10 10 5\n"]}
You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
You will be given a competitive programming problem. Generate an executable Python function generated from the given prompt. Please reason step by step about your solution approach, then provide a complete implementation in Python 3 that is thoroughly optimized for both speed and memory usage. Put your final solution ...
```python def lcm(a, b): return a * b // gcd(a, b) def gcd(a, b): if a == 0: return b return gcd(b % a, a) T = int(input()) for t in range(T): N = int(input()) A = list(map(int, input().split())) B = [A[0]] for i in range(N - 1): B.append(lcm(A[i], A[i + 1])) B.append(A[N - 1]) print(' '.join(map(str, B))...
TACO-verified
code_generation
MEDIUM
['String algorithms']
[]
auto
{"input": ["8 \nGAAATAAA\n"], "output": ["5\n"]}
You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
You will be given a competitive programming problem. Generate an executable Python function generated from the given prompt. Please reason step by step about your solution approach, then provide a complete implementation in Python 3 that is thoroughly optimized for both speed and memory usage. Put your final solution ...
```python def solve(S, n): count = {} for c in S: count[c] = count.get(c, 0) + 1 for c in count: if count[c] > n // 4: count[c] = count[c] - n // 4 else: count[c] = 0 if sum((count[c] for c in count)) == 0: return 0 count2 = {} (i, j, best) = (0, 0, n) while j < n: while j < n and any((count2.get...
TACO-verified
code_generation
EASY
['String algorithms', 'Mathematics']
[]
auto
{"input": ["6\nABACAB\nABBA\nAC\nABC\nCABCBB\nBCBCBCBCBCBCBCBC\n", "6\nABACAB\nABBA\nAC\nABC\nCABCBB\nCBCBCBCBCBCBCBCB\n", "6\nABACAB\nABBA\nAC\nABC\nCABCBB\nBCBCBCBCBCACBCBC\n", "6\nABACAB\nABBA\nBC\nABB\nCABCBB\nCBCBCBCBCBCBCBCB\n", "6\nABBCAB\nABBA\nAC\nABC\nCABCBB\nBCBCBCBCBCACBCBC\n", "6\nABACAC\nABBA\nAC\nACB\nCA...
You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
You will be given a competitive programming problem. Generate an executable Python function generated from the given prompt. Please reason step by step about your solution approach, then provide a complete implementation in Python 3 that is thoroughly optimized for both speed and memory usage. Put your final solution ...
```python def solve(s): return s.count('B') == s.count('A') + s.count('C') n = int(input()) for i in range(n): s = input() if solve(s): print('YES') else: print('NO') ```
TACO-verified
code_generation
HARD
['Bit manipulation', 'Mathematics']
['Bit manipulation']
auto
{"input": ["1\n5\n3 1 2 4 5\n2 4 5 1 3"], "output": ["3 1 2 4 5"]}
You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
You will be given a competitive programming problem. Generate an executable Python function generated from the given prompt. Please reason step by step about your solution approach, then provide a complete implementation in Python 3 that is thoroughly optimized for both speed and memory usage. Put your final solution ...
```python import itertools t = int(input()) for _ in range(t): N = int(input()) A = list(map(int, input().split(' '))) B = list(map(int, input().split(' '))) ultimate_sum = 0 for i in range(20): mask = 1 << i count_a = 0 count_b = 0 for (a, b) in zip(A, B): if a & mask > 0: count_a += 1 if b & ma...
TACO-verified
code_generation
HARD
['Number theory', 'Data structures', 'Mathematics']
['Data structures']
auto
{"input": ["5\n1 5 2 4 2\n4\n1 5\n2 5\n3 5\n4 5\n", "5\n1 3 4 4 2\n4\n1 5\n2 5\n3 5\n4 5\n", "5\n1 3 4 4 2\n4\n1 5\n2 5\n3 5\n2 5\n", "5\n1 3 4 4 2\n4\n1 5\n2 5\n1 5\n4 5\n", "5\n1 3 4 4 2\n4\n1 5\n2 5\n1 5\n3 5\n", "5\n1 3 4 4 2\n4\n1 3\n2 5\n1 5\n3 5\n", "5\n1 3 4 2 2\n4\n1 5\n2 5\n3 5\n2 5\n", "5\n1 3 4 4 2\n4\n1 5\...
You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
You will be given a competitive programming problem. Generate an executable Python function generated from the given prompt. Please reason step by step about your solution approach, then provide a complete implementation in Python 3 that is thoroughly optimized for both speed and memory usage. Put your final solution ...
```python from math import gcd class SegTree: def __init__(self, arr=None, length=None): if arr is not None: self.n = len(arr) self.t = [1 for _ in range(2 * self.n)] self.ct = [0] * self.n + [1] * self.n self.construct(arr) else: assert False self.n = length self.t = [1 for _ in range(2 * s...
TACO-verified
code_generation
MEDIUM
['Complete search', 'Constructive algorithms', 'Data structures', 'Ad-hoc']
['Data structures', 'Complete search']
auto
{"input": [["5", "4 1 2 3 4", "4", "3", "4", "6", "1", "", ""], "5\n4 0 2 3 4\n4\n3\n4\n6\n1", "5\n4 0 2 3 4\n4\n5\n4\n6\n1", "5\n4 1 2 3 4\n4\n5\n4\n6\n1", "5\n4 1 2 6 4\n4\n5\n4\n6\n1", "5\n4 1 2 3 4\n4\n3\n7\n6\n1", "5\n4 0 2 3 4\n1\n3\n4\n6\n1", "5\n4 0 2 3 0\n4\n5\n4\n6\n1", "5\n4 1 2 3 4\n3\n5\n4\n6\n1", "5\n4 1 ...
You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
You will be given a competitive programming problem. Generate an executable Python function generated from the given prompt. Please reason step by step about your solution approach, then provide a complete implementation in Python 3 that is thoroughly optimized for both speed and memory usage. Put your final solution ...
```python n = int(input()) a = list(map(int, input().split())) cnt = {} for i in range(n): mn = a[i] for j in range(i, n): mn = min(mn, a[j]) if mn in cnt: cnt[mn] += 1 else: cnt[mn] = 1 q = int(input()) for i in range(q): k = int(input()) if k in cnt: print(cnt[k]) else: print(0) ```
TACO-verified
code_generation
EASY
['String algorithms', 'Greedy algorithms']
['Greedy algorithms']
auto
{"input": ["2\n10057\n90\n"], "output": ["10012\n9\n"]}
You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
You will be given a competitive programming problem. Generate an executable Python function generated from the given prompt. Please reason step by step about your solution approach, then provide a complete implementation in Python 3 that is thoroughly optimized for both speed and memory usage. Put your final solution ...
```python import sys, collections equal = {'19', '28', '29', '37', '38', '39', '46', '47', '48', '49', '55', '56', '57', '58', '59', '64', '65', '66', '67', '68', '69', '73', '74', '75', '76', '77', '78', '79', '82', '83', '84', '85', '86', '87', '88', '89', '91', '92', '93', '94', '95', '96', '97', '98', '99'} def so...
TACO-verified
code_generation
MEDIUM
[]
[]
auto
{"input": ["3 3 2\n1 2\n5 4\n9 2\n", "9 4 1\n1 5\n2 4\n3 3\n4 2\n5 1\n6 2\n7 3\n8 4\n9 5\n", "3 0 1\n300000000 1000000000\n100000000 1000000000\n200000000 1000000000\n", "9 4 1\n1 5\n2 4\n3 3\n4 2\n5 1\n6 2\n7 3\n8 4\n9 0", "3 3 2\n1 4\n5 4\n9 2", "3 0 1\n77888184 1000000000\n100000000 1000000000\n200000000 1000000000"...
You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
You will be given a competitive programming problem. Generate an executable Python function generated from the given prompt. Please reason step by step about your solution approach, then provide a complete implementation in Python 3 that is thoroughly optimized for both speed and memory usage. Put your final solution ...
```python (n, d, a) = map(int, input().split()) xh = [list(map(int, input().split())) for _ in range(n)] xh.sort(key=lambda x: x[0]) from collections import deque minusd = deque() nowd = 0 ans = 0 for (x, h) in xh: while minusd and minusd[0][1] <= x: (d_, _) = minusd.popleft() nowd -= d_ tmp = max(0, (h - nowd + ...
TACO-verified
code_generation
HARD
['Tree algorithms', 'Combinatorics', 'Graph traversal', 'Dynamic programming']
['Dynamic programming']
auto
{"input": ["8\n4 5\n1 2\n6 3\n2 3\n2 8\n4 7\n2 4\n", "7\n2 7\n2 6\n4 7\n7 3\n7 5\n1 7\n", "3\n1 2\n3 2\n", "2\n2 1\n", "10\n5 4\n5 2\n3 7\n9 3\n3 2\n3 1\n3 8\n9 10\n1 6\n", "6\n2 1\n3 2\n4 1\n5 4\n1 6\n", "5\n3 5\n4 3\n2 4\n1 2\n", "6\n4 6\n1 5\n5 4\n5 3\n2 4\n", "9\n5 6\n1 3\n2 3\n7 6\n4 1\n3 6\n8 1\n1 9\n", "8\n4 5\n...
You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
You will be given a competitive programming problem. Generate an executable Python function generated from the given prompt. Please reason step by step about your solution approach, then provide a complete implementation in Python 3 that is thoroughly optimized for both speed and memory usage. Put your final solution ...
```python import sys n = int(sys.stdin.readline().strip()) D = [0] * n p = 998244353 for i in range(0, n - 1): (u, v) = list(map(int, sys.stdin.readline().strip().split())) D[u - 1] = D[u - 1] + 1 D[v - 1] = D[v - 1] + 1 ans = n for i in range(0, n): for j in range(0, D[i]): ans = ans * (j + 1) % p print(ans) ```
TACO-verified
code_generation
MEDIUM_HARD
['Implementation', 'Greedy algorithms']
['Greedy algorithms']
auto
{"input": ["5 328 249\n62 265\n32 271\n72 237\n28 99\n22 364\n", "4 337 873\n62 81\n87 481\n39 1189\n45 450\n", "2 1000 1\n100 1\n100 1\n", "5 351 183\n16 337\n19 221\n81 359\n87 253\n5 240\n", "3 100 5\n100 1\n100 1\n100 1\n", "10 1000 8\n100 1\n100 1\n100 1\n100 1\n100 1\n100 1\n100 1\n100 1\n100 1\n100 1\n", "11 2 1...
You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
You will be given a competitive programming problem. Generate an executable Python function generated from the given prompt. Please reason step by step about your solution approach, then provide a complete implementation in Python 3 that is thoroughly optimized for both speed and memory usage. Put your final solution ...
```python class Scroll: def __init__(self, id, power, damage): self.id = id self.power = power self.damage = damage self.active = False (num_scrolls, boss_max, regenerate) = map(int, input().split()) scrolls = [Scroll(i + 1, *map(int, input().split())) for i in range(num_scrolls)] scrolls.sort(key=lambda scro...
TACO-verified
code_generation
EASY
['Implementation', 'Complete search']
['Complete search']
auto
{"input": ["2\n4\n1 0 0 1 0\n0 1 0 0 1\n0 0 0 1 0\n0 1 0 1 0\n2\n0 0 0 1 0\n0 0 0 1 0\n", "2\n4\n1 0 0 1 0\n0 1 0 0 1\n0 0 0 1 0\n0 1 0 1 0\n2\n0 0 0 0 0\n0 0 0 1 0\n", "2\n4\n1 0 0 1 0\n1 1 0 0 1\n0 0 0 0 0\n0 1 0 1 0\n2\n0 0 0 0 0\n0 0 0 1 1\n", "2\n4\n1 0 0 1 0\n0 1 0 0 1\n0 0 0 1 0\n0 1 0 1 0\n2\n0 0 0 1 1\n0 0 0 1...
You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
You will be given a competitive programming problem. Generate an executable Python function generated from the given prompt. Please reason step by step about your solution approach, then provide a complete implementation in Python 3 that is thoroughly optimized for both speed and memory usage. Put your final solution ...
```python from itertools import combinations def solve(test_case): n = int(input()) mat = [] for i in range(n): mat.append([int(x) for x in input().split()]) sets = [] for j in range(5): temp = set() for i in range(n): if mat[i][j] == 1: temp.add(i) if len(temp) >= n / 2: sets.append(temp) if l...
TACO-verified
code_generation
MEDIUM
['Combinatorics']
[]
auto
{"input": ["3\n1 1\n1 2\n2 2\n"], "output": ["3\n18\n160\n"]}
You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
You will be given a competitive programming problem. Generate an executable Python function generated from the given prompt. Please reason step by step about your solution approach, then provide a complete implementation in Python 3 that is thoroughly optimized for both speed and memory usage. Put your final solution ...
```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('...
TACO-verified
code_generation
EASY
['Mathematics', 'Constructive algorithms']
[]
auto
{"input": ["578 3\n", "20 2\n", "1000 1\n", "4 1\n", "10 1\n", "843 152\n", "1 1\n", "3 10\n", "1 1000\n", "9 1\n"], "output": ["11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...
You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
You will be given a competitive programming problem. Generate an executable Python function generated from the given prompt. Please reason step by step about your solution approach, then provide a complete implementation in Python 3 that is thoroughly optimized for both speed and memory usage. Put your final solution ...
```python (n, m) = map(int, input().split()) print(n * '1') print((n - 1) * '8' + '9') ```
TACO-verified
code_generation
EASY
['Mathematics']
[]
auto
{"input": ["4\n5 1\n5 2\n5 3\n3 10\n"], "output": ["Chocolate\nEither\nCandy\nCandy\n"]}
You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
You will be given a competitive programming problem. Generate an executable Python function generated from the given prompt. Please reason step by step about your solution approach, then provide a complete implementation in Python 3 that is thoroughly optimized for both speed and memory usage. Put your final solution ...
```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') ```
TACO-verified
code_generation
EASY
['Fundamentals', 'Data structures']
['Data structures']
call_based
binary_cleaner
{"input": [[[0, 1, 2, 1, 0, 2, 1, 1, 1, 0, 4, 5, 6, 2, 1, 1, 0]], [[0, 1, 1, 2, 0]], [[2, 2, 0]], [[0, 1, 2, 1, 0, 2, 1, 1]], [[1]], [[3, 0, 7, 0, 2, 0]]], "output": [[[[0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0], [2, 5, 10, 11, 12, 13]]], [[[0, 1, 1, 0], [3]]], [[[0], [0, 1]]], [[[0, 1, 1, 0, 1, 1], [2, 5]]], [[[1], []]], [[[0,...
You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
You will be given a competitive programming problem. Generate an executable Python function generated from the given prompt. Please reason step by step about your solution approach, then provide a complete implementation in Python 3 that is thoroughly optimized for both speed and memory usage. Put your final solution ...
```python def binary_cleaner(seq): res = ([], []) for (i, x) in enumerate(seq): if x < 2: res[0].append(x) else: res[1].append(i) return res ```
TACO-verified
code_generation
HARD
['Sorting', 'Constructive algorithms', 'Data structures', 'Ad-hoc']
['Sorting', 'Data structures']
auto
{"input": [" 2\n 5\n 1 2 3 4 5\n 5\n 1 3 2 5 4"], "output": [" 0\n 3"]}
You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
You will be given a competitive programming problem. Generate an executable Python function generated from the given prompt. Please reason step by step about your solution approach, then provide a complete implementation in Python 3 that is thoroughly optimized for both speed and memory usage. Put your final solution ...
```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) ```
TACO-verified
code_generation
EASY
[]
[]
auto
{"input": ["4\n6 3 1\n2 2 2\n4 3 2\n5 1 2\n"], "output": ["YES\nNO\nNO\nYES\n"]}
You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
You will be given a competitive programming problem. Generate an executable Python function generated from the given prompt. Please reason step by step about your solution approach, then provide a complete implementation in Python 3 that is thoroughly optimized for both speed and memory usage. Put your final solution ...
```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') ```
TACO-verified
code_generation
MEDIUM_HARD
['Number theory', 'Mathematics']
[]
auto
{"input": ["3\n4\n4 2 3 1\n5\n1 4 3 2 5\n2\n2 1\n"], "output": ["3\n2\n1\n"]}
You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
You will be given a competitive programming problem. Generate an executable Python function generated from the given prompt. Please reason step by step about your solution approach, then provide a complete implementation in Python 3 that is thoroughly optimized for both speed and memory usage. Put your final solution ...
```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) ```
TACO-verified
code_generation
EASY
['Greedy algorithms']
['Greedy algorithms']
auto
{"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"]}
You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
You will be given a competitive programming problem. Generate an executable Python function generated from the given prompt. Please reason step by step about your solution approach, then provide a complete implementation in Python 3 that is thoroughly optimized for both speed and memory usage. Put your final solution ...
```python import sys input = sys.stdin.readline for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) if 0 not in a: print(1) else: check = 0 block = 0 for i in range(len(a)): if a[i] != 0: if check == 0: block += 1 check = 1 if block == 2: break e...
TACO-verified
code_generation
HARD
['Dynamic programming', 'Sorting', 'Implementation', 'Greedy algorithms']
['Dynamic programming', 'Sorting', 'Greedy algorithms']
auto
{"input": ["3 3 3 2\n1 1\n2 1\n3 1\n2 3\n", "3 5 3 2\n1 2\n2 3\n3 1\n1 5\n", "3 6 3 2\n1 6\n2 2\n3 4\n1 6\n", "2 2 2 2\n1 1\n1 2\n1 2\n", "5 5 10 3\n3 1\n3 2\n3 5\n1 5\n2 1\n2 5\n1 2\n1 4\n3 3\n2 4\n2 1 5\n", "5 3 10 3\n5 3\n1 1\n2 2\n1 3\n3 2\n5 2\n2 3\n2 1\n3 1\n5 1\n1 2 3\n", "3 3 8 2\n2 2\n1 2\n2 1\n2 3\n3 2\n1 3\n...
You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
You will be given a competitive programming problem. Generate an executable Python function generated from the given prompt. Please reason step by step about your solution approach, then provide a complete implementation in Python 3 that is thoroughly optimized for both speed and memory usage. Put your final solution ...
```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...
TACO-verified
code_generation
EASY
[]
[]
call_based
palindrome
{"input": [[1221], [110011], [1456009006541], [123322], [1], [152], [9999], ["ACCDDCCA"], ["@14AbC"], ["1221"]], "output": [[true], [true], [true], [false], [true], [false], [true], ["Not valid"], ["Not valid"], ["Not valid"]]}
You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
You will be given a competitive programming problem. Generate an executable Python function generated from the given prompt. Please reason step by step about your solution approach, then provide a complete implementation in Python 3 that is thoroughly optimized for both speed and memory usage. Put your final solution ...
```python def palindrome(num): if type(num) is not int or num < 1: return 'Not valid' return num == int(str(num)[::-1]) ```
TACO-verified
code_generation
HARD
['Mathematics', 'Greedy algorithms', 'Implementation', 'Constructive algorithms']
['Greedy algorithms']
auto
{"input": ["1\nIAO'113098\n", "1\nIAO'021113099\n", "1\nIAO'10005000\n", "1\nIAO'111111111\n", "1\nIAO'11378\n", "1\nIAO'111110\n", "1\nIAO'001\n", "1\nIAO'000000000\n", "1\nIAO'2015\n", "2\nIAO'0\nIAO'00\n"], "output": ["1113098\n", "1021113099\n", "110005000\n", "1111111111\n", "111378\n", "1111110\n", "3001\n", "100...
You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
You will be given a competitive programming problem. Generate an executable Python function generated from the given prompt. Please reason step by step about your solution approach, then provide a complete implementation in Python 3 that is thoroughly optimized for both speed and memory usage. Put your final solution ...
```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...
TACO-verified
code_generation
EASY
['Implementation']
[]
auto
{"input": ["7\n", "21\n", "1\n", "2\n", "3\n", "4\n", "5\n", "6\n", "8\n", "9\n"], "output": ["7\n", "5\n", "1\n", "2\n", "3\n", "4\n", "5\n", "6\n", "8\n", "9\n"]}
You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
You will be given a competitive programming problem. Generate an executable Python function generated from the given prompt. Please reason step by step about your solution approach, then provide a complete implementation in Python 3 that is thoroughly optimized for both speed and memory usage. Put your final solution ...
```python n = int(input()) step = 9 count = 0 digit = 1 while count + digit * step < n: count += digit * step step *= 10 digit += 1 i = n - count k = int((i + (digit - 1)) / digit) num = 10 ** (digit - 1) + (k - 1) j = digit - (i + digit - 1) % digit - 1 while j > 0: num = int(num / 10) j -= 1 print(num % 10) ```
TACO-verified
code_generation
MEDIUM
['Greedy algorithms']
['Greedy algorithms']
auto
{"input": ["6 2 \n0 1 1 1 1 0 \n"], "output": ["2\n"]}
You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
You will be given a competitive programming problem. Generate an executable Python function generated from the given prompt. Please reason step by step about your solution approach, then provide a complete implementation in Python 3 that is thoroughly optimized for both speed and memory usage. Put your final solution ...
```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) ```
TACO-verified
code_generation
EASY
['Greedy algorithms', 'Complete search', 'Mathematics', 'Constructive algorithms']
['Complete search', 'Greedy algorithms']
auto
{"input": ["3\n3 4\n1 2\n120 150\n", "1\n500000000 1000000000\n", "1\n100000001 200000002\n", "1\n1000000000 1000000000\n", "1\n100000000 199999999\n", "5\n500000000 1000000000\n500000000 999999999\n499999998 999999996\n499999998 999999995\n499999998 999999997\n", "4\n50000000 100000000\n50000001 100000000\n50000000 99...
You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
You will be given a competitive programming problem. Generate an executable Python function generated from the given prompt. Please reason step by step about your solution approach, then provide a complete implementation in Python 3 that is thoroughly optimized for both speed and memory usage. Put your final solution ...
```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]) > ...
TACO-verified
code_generation
HARD
['Sorting', 'Data structures', 'Implementation', 'Complete search']
['Sorting', 'Data structures', 'Complete search']
auto
{"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", "1\n104\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 102 6504 5000...
You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
You will be given a competitive programming problem. Generate an executable Python function generated from the given prompt. Please reason step by step about your solution approach, then provide a complete implementation in Python 3 that is thoroughly optimized for both speed and memory usage. Put your final solution ...
```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...
TACO-verified
code_generation
MEDIUM
['Number theory']
[]
auto
{"input": ["3\n4\n5\n80\n"], "output": ["2\n3\n4\n"]}
You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
You will be given a competitive programming problem. Generate an executable Python function generated from the given prompt. Please reason step by step about your solution approach, then provide a complete implementation in Python 3 that is thoroughly optimized for both speed and memory usage. Put your final solution ...
```python from math import log10 def caldigit(p): c = int(log10(p)) + 1 a = int('1' * c) % p while a: a = (a * 10 + 1) % p c += 1 return c for _ in range(int(input())): n = int(input()) twos = 0 while not n & 1: n >>= 1 twos += 1 fives = 0 while not n % 5: n //= 5 fives += 1 print(2 * caldigit(n)...
TACO-verified
code_generation
EASY
['Greedy algorithms', 'Complete search', 'Mathematics', 'Constructive algorithms']
['Complete search', 'Greedy algorithms']
auto
{"input": ["14\n", "2\n", "1\n", "3\n", "4\n", "5\n", "6\n", "7\n", "8\n", "9\n"], "output": ["4 4\n", "0 2\n", "0 1\n", "0 2\n", "0 2\n", "0 2\n", "1 2\n", "2 2\n", "2 3\n", "2 4\n"]}
You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
You will be given a competitive programming problem. Generate an executable Python function generated from the given prompt. Please reason step by step about your solution approach, then provide a complete implementation in Python 3 that is thoroughly optimized for both speed and memory usage. Put your final solution ...
```python n = int(input()) print(2 * (n // 7) + n % 7 // 6, 2 * ((n + 5) // 7) + (n + 5) % 7 // 6) ```
TACO-verified
code_generation
EASY
['Game theory', 'Implementation', 'Greedy algorithms']
['Greedy algorithms']
auto
{"input": ["3\n4 5 7\n", "2\n1 1\n", "10\n38282 53699 38282 38282 38282 38282 38282 38282 38282 38282\n", "10\n50165 50165 50165 50165 50165 50165 50165 50165 50165 50165\n", "10\n83176 83176 83176 23495 83176 8196 83176 23495 83176 83176\n", "10\n32093 36846 32093 32093 36846 36846 36846 36846 36846 36846\n", "3\n1 2 ...
You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
You will be given a competitive programming problem. Generate an executable Python function generated from the given prompt. Please reason step by step about your solution approach, then provide a complete implementation in Python 3 that is thoroughly optimized for both speed and memory usage. Put your final solution ...
```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') ```
TACO-verified
code_generation
EASY
['Mathematics']
[]
auto
{"input": ["6\n2\n2 3\n1\n2\n5\n1 6 2 4 3\n4\n2 2 2 1\n3\n1 1000000000 999999999\n1\n1\n", "1\n3\n1 2 12212221\n", "1\n1\n100000\n"], "output": ["YES\nNO\nNO\nYES\nYES\nYES\n", "NO\n", "NO\n"]}
You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
You will be given a competitive programming problem. Generate an executable Python function generated from the given prompt. Please reason step by step about your solution approach, then provide a complete implementation in Python 3 that is thoroughly optimized for both speed and memory usage. Put your final solution ...
```python import sys def main(): t = int(sys.stdin.readline()) for _ in range(t): n = int(sys.stdin.readline()) arr = list(map(int, sys.stdin.readline().split())) val = sum(arr) / n if n == 1: if arr[0] > 1: print('NO') else: print('YES') else: mx1 = mx2 = -sys.maxsize for i in arr: ...
TACO-verified
code_generation
MEDIUM_HARD
['Game theory', 'Mathematics', 'Greedy algorithms']
['Greedy algorithms']
auto
{"input": ["4\n0523\n", "2\n??\n", "8\n?054??0?\n", "6\n???00?\n", "80\n????66??8?0?????0??8?45?328??0?6???121038??????4?17??12847??3??65??6?????2????62\n", "8\n923?5???\n", "4\n1928\n", "8\n????????\n", "6\n??????\n", "12\n?3??????3???\n"], "output": ["Bicarp\n", "Bicarp\n", "Bicarp\n", "Monocarp\n", "Monocarp\n", "Bi...
You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
You will be given a competitive programming problem. Generate an executable Python function generated from the given prompt. Please reason step by step about your solution approach, then provide a complete implementation in Python 3 that is thoroughly optimized for both speed and memory usage. Put your final solution ...
```python n = int(input()) s = input() nuq1 = 0 nuq2 = 0 sum1 = 0 sum2 = 0 for i in range(n): if s[i] == '?' and i < n // 2: nuq1 += 1 elif s[i] == '?' and i >= n // 2: nuq2 += 1 elif i < n // 2: sum1 += int(s[i]) else: sum2 += int(s[i]) if sum1 - sum2 == 9 * ((nuq2 - nuq1) // 2): print('Bicarp') else: pr...
TACO-verified
code_generation
End of preview. Expand in Data Studio
README.md exists but content is empty.
Downloads last month
125