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/1516/B
Solve the following coding problem using the programming language python: Baby Ehab is known for his love for a certain operation. He has an array $a$ of length $n$, and he decided to keep doing the following operation on it: he picks $2$ adjacent elements; he then removes them and places a single integer in their pl...
```python import sys input = lambda : sys.stdin.readline().rstrip() for _ in range(int(input())): n = int(input()) A = list(map(int, input().split())) Result = [0] for a in A: Result.append(Result[-1] ^ a) r = Result[-1] if not r: b = 0 else: idx = Result.index(r) if idx < n: S = set(Result[idx + 1:])...
vfc_132888
{ "difficulty": "medium", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1516/B", "time_limit": "1 second" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n3\n0 2 2\n4\n2 3 1 10\n", "output": "YES\nNO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "15\n2\n660632533 660632533\n2\n774306959 774306959\n2\n971739496 784083784\n2\n775353256 672...
taco
verifiable_code
https://codeforces.com/problemset/problem/1473/A
Solve the following coding problem using the programming language python: You have an array $a_1, a_2, \dots, a_n$. All $a_i$ are positive integers. In one step you can choose three distinct indices $i$, $j$, and $k$ ($i \neq j$; $i \neq k$; $j \neq k$) and assign the sum of $a_j$ and $a_k$ to $a_i$, i. e. make $a_i ...
```python t = int(input()) for i in range(t): (a, d) = map(int, input().split()) s = input().split(' ') s = [int(x) for x in s] s.sort() if s[0] + s[1] <= d or s[-1] <= d: print('YES') else: print('NO') ```
vfc_132892
{ "difficulty": "easy", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1473/A", "time_limit": "2 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n5 3\n2 3 2 5 4\n3 4\n2 4 4\n5 4\n2 1 5 3 6\n", "output": "NO\nYES\nYES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "12\n3 1\n1 1 1\n3 1\n1 1 1\n3 1\n1 1 1\n3 1\n1 1 1\n3 1\n1 1 1\n3 ...
taco
verifiable_code
Solve the following coding problem using the programming language python: problem Do you know Just Odd Inventions? The business of this company is to "just odd inventions". Here we call it JOI for short. JOI has two offices, each of which has square rooms of the same size arranged in a grid pattern. All the rooms th...
```python from heapq import heappop as pop from heapq import heappush as push INF = 1000000000000 def bfs(lst, used, que, w, h): (v, y, x) = pop(que) if y > 0 and (not used[y - 1][x]): push(que, (lst[y - 1][x], y - 1, x)) used[y - 1][x] = True if h > y + 1 and (not used[y + 1][x]): push(que, (lst[y + 1][x], y...
vfc_132896
{ "difficulty": "unknown_difficulty", "memory_limit": "134.217728 megabytes", "memory_limit_bytes": null, "problem_url": null, "time_limit": "1.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n2 2 1 2\n9 5\n1 17\n3 2 2 1\n6 1 20\n8 18 3\n8\n5 4 1 3\n5 5 4 5 5\n8 2 1 9 7\n1 1 3 5 1\n7 2 7 1 3\n6 5 6 2\n2 3 5 8 2 7\n1 6 9 4 5 1\n2 5 5 4 2 2\n5 4 2 5 3 3\n7 1 5 1 5 6\n6\n3 3 2 2\n2 9 2\n9 1 9\n2 9 2\n2 2 1 1\n1 3\n5 7\n0...
taco
verifiable_code
Solve the following coding problem using the programming language python: There is data of up to 100 characters per line, consisting of half-width alphabetic character strings. Some lines are symmetric (same whether read from the left edge or the right edge). Create a program that reads this data and outputs the numbe...
```python n = 0 while True: try: t = str(input()) if t == t[::-1]: n += 1 except EOFError: break print(n) ```
vfc_132901
{ "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": "abcba\nsx\nabcddcba\nrstrd", "output": "2\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/MERGEDLIS
Solve the following coding problem using the programming language python: You have two arrays A and B of size N and M respectively. You have to merge both the arrays to form a new array C of size N + M (the relative order of elements in the original arrays A and B should not change in the array C). For e.g. if A = [{...
```python from bisect import bisect_right def lis(arr): sub = [] for (i, x) in enumerate(arr): if len(sub) == 0 or sub[-1] <= x: sub.append(x) else: idx = bisect_right(sub, x) sub[idx] = x return len(sub) for _ in range(int(input())): (N, M) = input().split(' ') N = int(N) M = int(M) A = list(map(i...
vfc_132905
{ "difficulty": "medium_hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/MERGEDLIS", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n3 2\n6 4 5\n1 3\n2 3\n1 3\n2 2 4\n", "output": "4\n5\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/615/E
Solve the following coding problem using the programming language python: Ayrat is looking for the perfect code. He decided to start his search from an infinite field tiled by hexagons. For convenience the coordinate system is introduced, take a look at the picture to see how the coordinates of hexagon are defined: ...
```python import math def main(m): if m == 0: print('0 0') else: x = math.floor(1 / 6 * ((12 * m - 3) ** 0.5 + 3)) while True: d = m - (x ** 3 - (x - 1) ** 3) if d < 0: x -= 1 elif d > x * 6 + 6: x += 1 else: break (s, r) = divmod(d, x) if s == 0: print('{} {}'.format(2 * x - r -...
vfc_132910
{ "difficulty": "hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/615/E", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n", "output": "-2 0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "7\n", "output": "3 2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "39\n",...
taco
verifiable_code
https://codeforces.com/problemset/problem/255/B
Solve the following coding problem using the programming language python: Little Vitaly loves different algorithms. Today he has invented a new algorithm just for you. Vitaly's algorithm works with string s, consisting of characters "x" and "y", and uses two following operations at runtime: Find two consecutive chara...
```python def solve(s): n = len(s) if n == 1: return s s = list(s) memo = {'x': s.count('x'), 'y': s.count('y')} if memo['x'] > memo['y']: return 'x' * (memo['x'] - memo['y']) else: return 'y' * (memo['y'] - memo['x']) s = input() result = solve(s) print(result) ```
vfc_132914
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/255/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "x\n", "output": "x\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "yxyxy\n", "output": "y\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "xxxxxy\...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/equal-sums4801/1
Solve the following coding problem using the programming language python: Given an array A of positive integers, find the smallest non-negative integer (i.e. greater than or equal to zero) that can be placed between any two elements of the array such that the sum of elements in the subarray occurring before it, is eq...
```python class Solution: def EqualSum(self, a, n): summa = sum(a) diff = float('inf') index = 0 pos = 1 for (i, item) in enumerate(a): summa -= item * 2 if abs(summa) < diff: diff = abs(summa) index = i + 2 if summa >= 0: pos = 1 else: pos = 2 return (diff, index, pos) ``...
vfc_132918
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/equal-sums4801/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "Arr[] = {3, 2, 1, 5, 7, 8}", "output": "4 5 1", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/APO12020/problems/APOC2_04
Solve the following coding problem using the programming language python: ----- CHEF N TIMINGS ----- One day chef was working with some random numbers. Then he found something interesting. He observed that no 240, 567, 9999 and 122 and called these numbers nice as the digits in numbers are in increasing order. Also h...
```python for _ in range(int(input())): n = input().rstrip() n = [ele for ele in n] l = len(n) m = 10 ** 18 + 8 ini = 1 for i in range(l - 1, -1, -1): if int(n[i]) <= m: if ini == 1: m = int(n[i]) else: m = max(m, n[i]) else: m = int(n[i]) - 1 n[i] = str(m) for j in range(l - 1, i, -1):...
vfc_132919
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/APO12020/problems/APOC2_04", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n132\n", "output": "129\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/implement-queue-using-linked-list/1
Solve the following coding problem using the programming language python: Implement a Queue using Linked List. A Query Q is of 2 Types (i) 1 x (a query of this type means pushing 'x' into the queue) (ii) 2 (a query of this type means to pop an element from the queue and print the poped element) Example 1: Inpu...
```python class Node: def __init__(self, data): self.data = data self.next = None class MyQueue: def __init__(self): self.front = None self.rear = None def push(self, item): node = Node(item) if self.front is None: self.front = self.rear = node else: self.rear.next = node self.rear = node ...
vfc_132923
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/implement-queue-using-linked-list/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "Q = 5\nQueries = 1 2 1 3 2 1 4 2", "output": "2 3", "type": "stdin_stdout" }, { "fn_name": null, "input": "Q = 4\nQueries = 1 2 2 2 1 3", "output": "2 -1", "type": "stdin_stdout" } ...
taco
verifiable_code
Solve the following coding problem using the programming language python: Anshu's father is a billionaire but he wants Anshu to learn the value of money. So, his father gives him his pocket money in a different manner. He gives 1Rs. on first day, 2 Rs. on second, 3 Rs. on third and so on. So, Anshu gets n Rs. on any ...
```python ''' # Read input from stdin and provide input before running code name = raw_input('What is your name?\n') print 'Hi, %s.' % name ''' t = input() t = int(t) while t: n = input() n = int(n) print(n*(n+1)/2) t-=1 ```
vfc_132924
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n2233453433234\n214356547566785435\n2143647368364618767318673624764324343325486", "output": "50005000\n1035\n1\n0\n311655", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n10000\n45\n1\n0...
taco
verifiable_code
Solve the following coding problem using the programming language python: A palindrome is a string that is the same whether it is read from left to right or from right to left. Chota Bheem likes palindromes a lot. As a birthday gift he received two strings A and B. Now he is curious if there is a way to insert string ...
```python def pla(h): return h == h[::-1] def insert(original, new, pos): return original[:pos] + new + original[pos:] for _ in range(eval(input())): s = input() m = input() count = 0 for i in range(0, len(s)+1): k = insert(s, m, i) if pla(k): count += 1 print(count) ```
vfc_132928
{ "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\naaaa\na\nab\nb\naaa\nab\naba\nc\nbcba\na\naaaaaaaaaa\na\ntttt\nss\nab\na\naaaabbbbaaaa\nacbadabca\nabc\ncba\naaba\na", "output": "0\n0\n0\n0\n0\n0\n0\n0", "type": "stdin_stdout" }, { "fn_name": null, ...
taco
verifiable_code
https://codeforces.com/problemset/problem/831/C
Solve the following coding problem using the programming language python: Polycarp watched TV-show where k jury members one by one rated a participant by adding him a certain number of points (may be negative, i. e. points were subtracted). Initially the participant had some score, and each the marks were one by one a...
```python def solve(): (k, n) = get([int]) A = get([int]) B = get([int]) Bset = set(B) s = list(itertools.accumulate(A)) valid = set() count = 0 for (judge, current) in itertools.product(B[:1], s): score = judge - current s2 = set((score + i for i in s)) if Bset <= s2: valid.add(score) return len(vali...
vfc_132932
{ "difficulty": "medium_hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/831/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 1\n-5 5 0 20\n10\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 2\n-2000 -2000\n3998000 4000000\n", "output": "1\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/MLIS
Solve the following coding problem using the programming language python: Chef received an array A of N integers as a valentine's day present. He wants to maximize the length of the longest strictly increasing subsequence by choosing a subarray and adding a fixed integer X to all its elements. More formally, Chef wan...
```python def lis_right_dp(nums): n = len(nums) maxv = [0] * (n + 1) (pr, maxv[1]) = (1, nums[-1]) dp = [0] * n dp[-1] = 1 for j in range(n - 2, -1, -1): (l, r) = (1, pr) while r - l > 2: m = (r + l) // 2 if nums[j] >= maxv[m]: r = m - 1 else: l = m x = 1 for p in range(r, l - 1, -1): ...
vfc_132940
{ "difficulty": "hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/MLIS", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n3\n1 2 1\n5\n1 5 8 6 9\n4\n1 2 2 1\n", "output": "3\n5\n3\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: For given two sides of a triangle a and b and the angle C between them, calculate the following properties: * S: Area of the triangle * L: The length of the circumference of the triangle * h: The height of the triangle with side a as a bottom e...
```python import math pi = math.pi (a, b, si) = map(float, input().split()) S = 1 / 2 * a * b * math.sin(math.radians(si)) c2 = a * a + b * b - 2 * a * b * math.cos(math.radians(si)) L = a + b + math.sqrt(c2) h = 2 * S / a print(S) print(L) print(h) ```
vfc_132944
{ "difficulty": "unknown_difficulty", "memory_limit": "134.217728 megabytes", "memory_limit_bytes": null, "problem_url": null, "time_limit": "1.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 3 130", "output": "4.59626665871\n13.3582153654\n2.29813332936\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 3 11", "output": "1.14485397226\n8.20039476726\n0.57242698613\n", ...
taco
verifiable_code
https://codeforces.com/problemset/problem/1054/D
Solve the following coding problem using the programming language python: At a break Vanya came to the class and saw an array of $n$ $k$-bit integers $a_1, a_2, \ldots, a_n$ on the board. An integer $x$ is called a $k$-bit integer if $0 \leq x \leq 2^k - 1$. Of course, Vanya was not able to resist and started changi...
```python (n, k) = map(int, input().split()) a = list(map(int, input().split())) p = [0] * (n + 1) base = (1 << k) - 1 def kC2(k): return (k - 1) * k // 2 d = {} for i in range(1, n + 1): p[i] = p[i - 1] ^ a[i - 1] p[i] = min(p[i], p[i] ^ base) if p[i] not in d: d[p[i]] = 0 d[p[i]] += 1 if 0 not in d: d[0] = 0...
vfc_132948
{ "difficulty": "hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1054/D", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 2\n1 3 0\n", "output": "5", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 3\n1 4 4 7 3 4\n", "output": "19", "type": "stdin_stdout" }, { "fn_name": null, ...
taco
verifiable_code
https://www.codechef.com/problems/ANDEQ
Solve the following coding problem using the programming language python: You are given an array A = [A_{1}, A_{2}, \ldots, A_{N}], consisting of N integers. In one move, you can take two adjacent numbers A_{i} and A_{i+1}, delete them, and then insert the number A_{i} \land A_{i+1} at the deleted position. Here, \lan...
```python for _ in range(int(input())): n = int(input()) arr = list(map(int, input().split())) res = arr[0] for i in arr: res &= i p = 0 curr = arr[0] for i in range(1, n): if curr == res: p += 1 curr = arr[i] else: curr &= arr[i] if curr == res: p += 1 print(n - p) ```
vfc_132953
{ "difficulty": "medium_hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/ANDEQ", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n4\n0 0 0 1\n2\n1 1\n6\n1 2 3 4 5 6\n4\n2 28 3 22\n", "output": "1\n0\n4\n3\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1202/C
Solve the following coding problem using the programming language python: You have a string $s$ — a sequence of commands for your toy robot. The robot is placed in some cell of a rectangular grid. He can perform four commands: 'W' — move one cell up; 'S' — move one cell down; 'A' — move one cell left; 'D' — move o...
```python for i in range(int(input())): s = input() (lm, rm, um, dm) = (0, 0, 0, 0) (xp, yp) = (0, 0) for ch in s: if ch == 'W': yp += 1 elif ch == 'A': xp -= 1 elif ch == 'S': yp -= 1 else: xp += 1 lm = min(lm, xp) rm = max(rm, xp) um = max(um, yp) dm = min(dm, yp) (xp, yp) = (0, 0) (...
vfc_132961
{ "difficulty": "hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1202/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\nDSAWWAW\nD\nWA\n", "output": "8\n2\n4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\nDSAWWAW\nD\nAW\n", "output": "8\n2\n4\n", "type": "stdin_stdout" }, { ...
taco
verifiable_code
https://codeforces.com/problemset/problem/750/B
Solve the following coding problem using the programming language python: In this problem we assume the Earth to be a completely round ball and its surface a perfect sphere. The length of the equator and any meridian is considered to be exactly 40 000 kilometers. Thus, travelling from North Pole to South Pole or vice ...
```python n = int(input()) d = 40000 y = 0 cor = True for i in range(n): (t, s) = input().split() t = int(t) if y == 0 and s[0] != 'S': cor = False break if y == 20000 and s[0] != 'N': cor = False break if s[0] == 'N': y -= t if y < 0: cor = False break elif s[0] == 'S': y += t if y > 20000:...
vfc_132969
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/750/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n7500 South\n10000 East\n3500 North\n4444 West\n4000 North\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n15000 South\n4000 East\n", "output": "NO\n", ...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/matching-pair5320/1
Solve the following coding problem using the programming language python: Given a set of numbers from 1 to N, each number is exactly present twice so there are N pairs. In the worst-case scenario, how many numbers X should be picked and removed from the set until we find a matching pair? Example 1: Input: N = 1 Output...
```python class Solution: def find(self, N): return N + 1 ```
vfc_132974
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/matching-pair5320/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 1", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "N = 2", "output": "3", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/add-binary-strings3805/1
Solve the following coding problem using the programming language python: Given two binary strings A and B consisting of only 0s and 1s. Find the resultant string after adding the two Binary Strings. Note: The input strings may contain leading zeros but the output string should not have any leading zeros. Example 1: I...
```python class Solution: def addBinary(self, A, B): sum = bin(int(a, 2) + int(b, 2)) return sum[2:] ```
vfc_132977
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/add-binary-strings3805/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "A = \"1101\", B = \"111\"", "output": "10100", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/990/B
Solve the following coding problem using the programming language python: You have a Petri dish with bacteria and you are preparing to dive into the harsh micro-world. But, unfortunately, you don't have any microscope nearby, so you can't watch them. You know that you have $n$ bacteria in the Petri dish and size of t...
```python [n, K] = map(int, input().strip().split()) ais = list(map(int, input().strip().split())) ais.sort() res = 0 cnt = 1 for i in range(n - 1): if ais[i + 1] == ais[i]: cnt += 1 else: if ais[i + 1] > ais[i] + K: res += cnt cnt = 1 res += cnt print(res) ```
vfc_132986
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/990/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7 1\n101 53 42 102 101 55 54\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 5\n20 15 10 15 20 25\n", "output": "1\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/THREEBOX
Solve the following coding problem using the programming language python: Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef has 3 boxes of sizes A, B, and C respectively. He puts the boxes in bags of size D (A ≤ B ≤ C ≤ D). Find the minimum number of bags Chef needs s...
```python for _ in range(int(input())): (a, b, c, d) = map(int, input().split()) if a + b + c <= d: print(1) elif a + b <= d or b + c <= d or a + c <= d: print(2) else: print(3) ```
vfc_132990
{ "difficulty": "easy", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/THREEBOX", "time_limit": "0.5 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n2 3 5 10\n1 2 3 5\n3 3 4 4\n", "output": "1\n2\n3\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/DOMINANT2
Solve the following coding problem using the programming language python: You are given an array A of length N. An element X is said to be *dominant* if the frequency of X in A is strictly greater than the frequency of any other element in the A. For example, if A = [2, 1, 4, 4, 4] then 4 is a dominant element since ...
```python for test_cases in range(int(input())): length = int(input()) list_a = list(map(int, input().split())) dict_a = dict() for i in list_a: if i not in dict_a: dict_a[i] = 1 else: dict_a[i] += 1 list_b = sorted(dict_a.values()) if len(list_b) == 1 or list_b[-1] != list_b[-2]: print('YES') else: ...
vfc_132996
{ "difficulty": "easy", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/DOMINANT2", "time_limit": "0.5 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n5\n2 2 2 2 2\n4\n1 2 3 4\n4\n3 3 2 1\n6\n1 1 2 2 3 4\n", "output": "YES\nNO\nYES\nNO\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1207/C
Solve the following coding problem using the programming language python: You are responsible for installing a gas pipeline along a road. Let's consider the road (for simplicity) as a segment $[0, n]$ on $OX$ axis. The road can have several crossroads, but for simplicity, we'll denote each crossroad as an interval $(x...
```python from sys import stdin item = lambda : stdin.readline().split() it = lambda : stdin.readline()[:-1] for _ in range(int(stdin.readline())): (n, a, b) = map(int, item()) s = it() x = s.find('1') if x == -1: print(n * (a + b) + b) continue res = (n + 1) * (a + b) + b for y in range(x + 1, n): if s[y] ...
vfc_133000
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1207/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n8 2 5\n00110010\n8 1 1\n00110010\n9 100000000 100000000\n010101010\n2 5 1\n00\n", "output": "94\n25\n2900000000\n13\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n2 3 5\n00\n12 4 7\...
taco
verifiable_code
https://www.codechef.com/ZCOPRAC/problems/ZCO15003
Solve the following coding problem using the programming language python: Zonal Computing Olympiad 2015, 29 Nov 2014 An interval is a pair of positive integers [a, b] with a ≤ b. It is meant to denote the set of integers that lie between the values a and b. For example [3,5] denotes the set {3,4,5} while the interval...
```python import operator no_seq = int(input().strip()) seqs = [] for idx in range(no_seq): input_now = input().strip().split(' ') seqs.append([int(input_now[0]), int(input_now[1])]) seqs.sort(key=operator.itemgetter(0)) curr = seqs[0] answer = 1 for i in range(1, no_seq): if curr[1] < seqs[i][0]: answer += 1 cu...
vfc_133004
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/ZCOPRAC/problems/ZCO15003", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n3 5\n3 3\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n6 9\n3 5\n4 8\n", "output": "2\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1334/A
Solve the following coding problem using the programming language python: Polycarp has recently created a new level in this cool new game Berlio Maker 85 and uploaded it online. Now players from all over the world can try his level. All levels in this game have two stats to them: the number of plays and the number of...
```python from __future__ import division, print_function import os import sys from io import BytesIO, IOBase import bisect, collections, heapq if sys.version_info[0] < 3: from __builtin__ import xrange as range from future_builtins import ascii, filter, hex, map, oct, zip def solution(): n = int(input().strip()) ...
vfc_133013
{ "difficulty": "easy", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1334/A", "time_limit": "2 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n3\n0 0\n1 1\n1 2\n2\n1 0\n1000 3\n4\n10 1\n15 2\n10 2\n15 2\n1\n765 432\n2\n4 4\n4 3\n5\n0 0\n1 0\n1 0\n1 0\n1 0\n", "output": "NO\nYES\nNO\nYES\nNO\nYES\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/847/A
Solve the following coding problem using the programming language python: Doubly linked list is one of the fundamental data structures. A doubly linked list is a sequence of elements, each containing information about the previous and the next elements of the list. In this problem all lists have linear structure. I.e....
```python import os import sys import math from io import BytesIO, IOBase from fractions import Fraction from collections import defaultdict BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = 'x' in file.mode or 'r' not ...
vfc_133017
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/847/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7\n4 7\n5 0\n0 0\n6 1\n0 2\n0 4\n1 0\n", "output": "4 7\n5 6\n0 5\n6 1\n3 2\n2 4\n1 0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n2 0\n0 1\n", "output": "2 0\n0 1\n", "t...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/cube-root-of-a-number0915/1
Solve the following coding problem using the programming language python: Given a number N, find the cube root of N. Note: We need to print the floor value of the result. Example 1: Input: N = 3 Output: 1 Explanation: Cube root of 3 is 1.442 = 1 Example 2: Input: N = 8 Output: 2 Explanation: Cube root of 8 is 2 Yo...
```python import math class Solution: def cubeRoot(self, N): return math.floor(N ** (1 / 3)) ```
vfc_133021
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/cube-root-of-a-number0915/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 3", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "N = 8", "output": "2", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1059/C
Solve the following coding problem using the programming language python: Let's call the following process a transformation of a sequence of length $n$. If the sequence is empty, the process ends. Otherwise, append the greatest common divisor (GCD) of all the elements of the sequence to the result and remove one arbi...
```python from math import ceil for _ in range(1): n = int(input()) if n <= 3: for i in range(n): if i == n - 1: print(i + 1) break print(1, end=' ') continue count = 1 while 2 ** count <= n: count += 1 count -= 1 curr = 2 ** count total = 0 add = 0 ans = [] while curr > 0: add = n // cu...
vfc_133022
{ "difficulty": "medium_hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1059/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n", "output": "1 1 3 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n", "output": "1 2 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n", ...
taco
verifiable_code
https://codeforces.com/problemset/problem/1401/A
Solve the following coding problem using the programming language python: We have a point $A$ with coordinate $x = n$ on $OX$-axis. We'd like to find an integer point $B$ (also on $OX$-axis), such that the absolute difference between the distance from $O$ to $B$ and the distance from $A$ to $B$ is equal to $k$. [Image...
```python from sys import stdin, stdout input = stdin.buffer.readline for _ in range(int(input())): (n, k) = map(int, input().split()) if n < k: print(k - n) else: print(k + n & 1) ```
vfc_133026
{ "difficulty": "easy", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1401/A", "time_limit": "1 second" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n4 0\n5 8\n0 1000000\n0 0\n1 0\n1000000 1000000\n", "output": "0\n3\n1000000\n0\n1\n0\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: problem The IOI country consists of N towns from town 1 to town N, and the towns are connected by roads. The IOI country has K roads, all of which connect two different towns. Cars can move freely in both directions on the road, but they cannot...
```python from heapq import heappop as pop from heapq import heappush as push def main(): (n, k) = map(int, input().split()) clst = [] rlst = [] for i in range(n): (c, r) = map(int, input().split()) clst.append(c) rlst.append(r) edges = [[] * n for i in range(n)] for i in range(k): (a, b) = map(int, inpu...
vfc_133030
{ "difficulty": "unknown_difficulty", "memory_limit": "268.435456 megabytes", "memory_limit_bytes": null, "problem_url": null, "time_limit": "8.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "enoN", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "eooN", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "Nooe", ...
taco
verifiable_code
https://codeforces.com/problemset/problem/1264/C
Solve the following coding problem using the programming language python: Creatnx has $n$ mirrors, numbered from $1$ to $n$. Every day, Creatnx asks exactly one mirror "Am I beautiful?". The $i$-th mirror will tell Creatnx that he is beautiful with probability $\frac{p_i}{100}$ for all $1 \le i \le n$. Some mirrors a...
```python def main(): m = 998244353 n = int(input()) pp = map(int, input().split()) probb = 100 num = 0 for (i, p) in enumerate(pp, 1): probu = (100 - p) * probb % m probb = p * probb % m num = (num * 100 + i * probu) % m num = (num + n * probb) % m print(num * pow(probb, m - 2, m) % m) main() ```
vfc_133034
{ "difficulty": "very_hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1264/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 2\n50 50\n2\n2\n", "output": "4\n6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 5\n10 20 30 40 50\n2\n3\n4\n5\n3\n", "output": "117\n665496274\n332748143\n831870317\n499122211...
taco
verifiable_code
https://www.codechef.com/NQST2020/problems/XMASGIFT
Solve the following coding problem using the programming language python: Its Christmas time and Santa has started his ride to deliver gifts to children waiting for him in a 1-dimentional city. All houses in this city are on a number line numbered as 1, 2, 3… and so on. Santa wants to deliver to houses from n to m, bu...
```python from math import gcd from math import ceil from itertools import combinations as c t = int(input()) for _ in range(t): (n, m, a, d) = list(map(int, input().split())) l = [] for i in range(5): l.append(a + i * d) ans = m - n + 1 for i in range(1, 6): x = list(c(l, i)) for j in x: e = j[0] for ...
vfc_133038
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/NQST2020/problems/XMASGIFT", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n2 20 2 1\n", "output": "5\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: G: Working Kou decided to do the same number of jobs every day for the next $ N $. $ A_i $ jobs are added on the $ i $ day of the $ N $ day. Mr. Kou has no work to do now, and he doesn't have to finish all the work by the $ N $ day. How many...
```python from itertools import accumulate n = int(input()) a = list(accumulate(map(int, input().split()))) for i in range(100, 0, -1): for j in range(n): if i * (j + 1) > a[j]: break else: print(i) break ```
vfc_133046
{ "difficulty": "unknown_difficulty", "memory_limit": "268.435456 megabytes", "memory_limit_bytes": null, "problem_url": null, "time_limit": "1.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n4 2 5 3 0", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n14 3 0 1 -1", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/at-least-two-greater-elements4625/1
Solve the following coding problem using the programming language python: Given an array of N distinct elements, the task is to find all elements in array except two greatest elements in sorted order. Example 1: Input : a[] = {2, 8, 7, 1, 5} Output : 1 2 5 Explanation : The output three elements have two or more gre...
```python class Solution: def findElements(self, a, n): a.sort() return a[:n - 2] ```
vfc_133050
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/at-least-two-greater-elements4625/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "a[] = {2, 8, 7, 1, 5}", "output": "1 2 5", "type": "stdin_stdout" }, { "fn_name": null, "input": "a[] = {7, -2, 3, 4, 9, -1}", "output": "-2 -1 3 4", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/number-of-root-to-leaf-paths/1
Solve the following coding problem using the programming language python: Given a binary tree, you need to find the number of all root to leaf paths along with their path lengths. Example 1: Input: 3 / \ 2 4 Output: 2 2 $ Explanation : There are 2 roots to leaf paths of length 2(3 -> 2 and 3 -> 4) E...
```python def pathCounts(root): has = {} def fun(root, row): if root is None: return if root.left == None and root.right == None: if row in has: has[row] += 1 else: has[row] = 1 return fun(root.left, row + 1) fun(root.right, row + 1) fun(root, 1) for (key, value) in has.items(): print...
vfc_133052
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/number-of-root-to-leaf-paths/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\r\n / \\\r\n 2 4", "output": "2 2 $", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\r\n / \\\r\n 20 30\r\n / \\ \r\n 40 60", "output": "2 1 $3 2 $", ...
taco
verifiable_code
https://codeforces.com/problemset/problem/19/A
Solve the following coding problem using the programming language python: Everyone knows that 2010 FIFA World Cup is being held in South Africa now. By the decision of BFA (Berland's Football Association) next World Cup will be held in Berland. BFA took the decision to change some World Cup regulations: * the final...
```python import sys import logging logging.root.setLevel(level=logging.INFO) team_size = int(sys.stdin.readline()) teams = {} for _ in range(team_size): name = sys.stdin.readline().strip() teams[name] = {'point': 0, 'delta': 0, 'score': 0} contest_size = team_size * (team_size - 1) // 2 logging.info(teams) for _ in ...
vfc_133053
{ "difficulty": "medium", "memory_limit": "64.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/19/A", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\nEULEUbCmfrmqxtzvg\nuHGRmKUhDcxcfqyruwzen\nuHGRmKUhDcxcfqyruwzen-EULEUbCmfrmqxtzvg 13:92\n", "output": "EULEUbCmfrmqxtzvg\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\nTeMnHVvWKpwlp...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/find-nth-element-of-spiral-matrix/1
Solve the following coding problem using the programming language python: Given a matrix with n rows and m columns. Your task is to find the kth element which is obtained while traversing the matrix spirally. You need to complete the method findK which takes four arguments the first argument is the matrix A and the ne...
```python def findK(arr, m, n, k): seen = [[0 for i in range(n)] for j in range(m)] dr = [0, 1, 0, -1] dc = [1, 0, -1, 0] x = 0 y = 0 di = 0 b = 1 for i in range(m * n): if b == k: return matrix[x][y] seen[x][y] = True cr = x + dr[di] cc = y + dc[di] if 0 <= cr and cr < m and (0 <= cc) and (cc < n)...
vfc_133061
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/find-nth-element-of-spiral-matrix/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "n = 4, m = 4, k = 10\nA[][] = {{1 2 3 4},\n {5 6 7 8},\n {9 10 11 12},\r\n {13 14 15 16}}", "output": "13", "type": "stdin_stdout" }, { "fn_name": null, "input": "n = 3...
taco
verifiable_code
https://www.codechef.com/problems/KNGTOR
Solve the following coding problem using the programming language python: King loves to go on tours with his friends. King has N cars that can seat 5 people each and M cars that can seat 7 people each. Determine the maximum number of people that can travel together in these cars. ------ Input Format ------ - The f...
```python t = int(input()) for i in range(t): (n, m) = map(int, input().split()) a = n * 5 b = m * 7 print(a + b) ```
vfc_133062
{ "difficulty": "easy", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/KNGTOR", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n4 8\n2 13\n14 5\n8 8", "output": "76\n101\n105\n96", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.hackerrank.com/challenges/matrix-tree/problem
Solve the following coding problem using the programming language python: Sevenkplus has a rooted tree with $N$ vertices. The vertices are labeled from $1$ to $N$. $1$ is the root of the tree. Each vertex $v$ has a weight $W_v$. He forms a $N\times N$ matrix ${M}$ from the tree. ${M}$ is defined by $M(x,y)=W_{lca(...
```python import collections, sys MOD = 1000000007 def dfs_compute(tree, weights, root): visited = set() stack = [(-1, root)] product = 1 while stack: (parent, node) = stack.pop() if node not in visited: visited.add(node) product *= weights[node - 1] - (weights[parent - 1] if parent > -1 else 0) produ...
vfc_133071
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.hackerrank.com/challenges/matrix-tree/problem", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1 2 3\n1 2\n1 3\n", "output": "2\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/328/B
Solve the following coding problem using the programming language python: Do you remember how Kai constructed the word "eternity" using pieces of ice as components? Little Sheldon plays with pieces of ice, each piece has exactly one digit between 0 and 9. He wants to construct his favourite number t. He realized that...
```python t = input() s = input() s = list(s) n = len(s) copies = 0 x = t.count('6') + t.count('9') y = s.count('6') + s.count('9') a = t.count('2') + t.count('5') b = s.count('2') + s.count('5') if x == 0 and a == 0: copies = 100 elif x == 0: copies = b // a elif a == 0: copies = y // x else: copies = min(y // x, ...
vfc_133075
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/328/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "42\n23454\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "169\n12118999\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "...
taco
verifiable_code
https://codeforces.com/problemset/problem/1196/A
Solve the following coding problem using the programming language python: Alice and Bob have received three big piles of candies as a gift. Now they want to divide these candies as fair as possible. To do this, Alice takes one pile of candies, then Bob takes one of the other two piles. The last pile is split between A...
```python def f1(a, b, c): d1 = abs(a - b) d2 = min(c, d1) if a < b: a += d2 else: b += d2 c = (c - d2) // 2 a += c b += c return min(a, b) def f2(s): (a, b, c) = map(int, s.split()) return max(f1(a, b, c), f1(b, c, a), f1(c, a, b)) q = int(input()) lines = [''] * q for i in range(q): lines[i] = input()...
vfc_133079
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1196/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n1 3 4\n1 10 100\n10000000000000000 10000000000000000 10000000000000000\n23 34 45\n", "output": "4\n55\n15000000000000000\n51\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n111 2 3\n...
taco
verifiable_code
https://codeforces.com/problemset/problem/276/D
Solve the following coding problem using the programming language python: A little girl loves problems on bitwise operations very much. Here's one of them. You are given two integers l and r. Let's consider the values of $a \oplus b$ for all pairs of integers a and b (l ≤ a ≤ b ≤ r). Your task is to find the maximum ...
```python import math def maxor(bawah, atas): if bawah == atas: return 0 xor = bawah ^ atas pangkat2 = math.log(xor, 2) return 2 ** int(math.floor(pangkat2) + 1) - 1 a = input().split() print(maxor(int(a[0]), int(a[1]))) ```
vfc_133085
{ "difficulty": "medium_hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/276/D", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 2\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "8 16\n", "output": "31\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1\n...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/ishaans-sum-problem0934/1
Solve the following coding problem using the programming language python: Ishaan is curious about numbers. He takes any 2 random numbers A and B. He wants to find out that whether A can be written as a sum of B distinct positive integers.Help him find out whether it is possible or not. Example 1: Input: A = 5, B = 2 O...
```python class Solution: def kthDistinct(self, A, B): if A >= B * (B + 1) // 2: return 1 return 0 ```
vfc_133089
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/ishaans-sum-problem0934/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "A = 5, B = 2", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "A = 6, B = 2", "output": "1", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/geek-and-coffee-shop5721/1
Solve the following coding problem using the programming language python: Given two values N and M. Give the value when N is halved M-1 times. Example 1: Input: N = 100, M = 4 Output: 12 Explaination: The sequence of numbers is 100, 50, 25, 12. Example 2: Input: N = 10, M = 5 Output: 0 Explaination: The sequence is 1...
```python import math class Solution: def mthHalf(self, N, M): return math.trunc(N / 2 ** (M - 1)) ```
vfc_133095
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/geek-and-coffee-shop5721/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 100, M = 4", "output": "12", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/351/E
Solve the following coding problem using the programming language python: Jeff's friends know full well that the boy likes to get sequences and arrays for his birthday. Thus, Jeff got sequence p_1, p_2, ..., p_{n} for his birthday. Jeff hates inversions in sequences. An inversion in sequence a_1, a_2, ..., a_{n} is a...
```python n = int(input()) inp = input() seq = inp.split(' ') seq = [abs(int(x)) for x in seq] Max = max(seq) nxt = [0] * n cnt = [0] * n pos = [n] * (Max + 1) for i in range(n - 1, -1, -1): nxt[i] = pos[seq[i]] pos[seq[i]] = i for i in range(0, Max + 1): j = pos[i] while j < n: front = sum(cnt[0:j]) back = sum...
vfc_133096
{ "difficulty": "hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/351/E", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n2 1\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "9\n-2 0 -1 0 -1 2 1 0 -1\n", "output": "6\n", "type": "stdin_stdout" }, { "fn_name": null,...
taco
verifiable_code
https://codeforces.com/problemset/problem/327/D
Solve the following coding problem using the programming language python: After too much playing on paper, Iahub has switched to computer games. The game he plays is called "Block Towers". It is played in a rectangular grid with n rows and m columns (it contains n × m cells). The goal of the game is to build your own ...
```python import sys from collections import deque sys.setrecursionlimit(501 * 501) (n, m) = [int(i) for i in input().split()] a = [[0 for i in range(m)] for i in range(n)] d = [(0, 1), (0, -1), (1, 0), (-1, 0)] q = deque() def main(): global a ans = [] first = [] q = deque() for i in range(n): line = input() ...
vfc_133101
{ "difficulty": "hard", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/327/D", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 1\n#\n", "output": "0\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/check-if-an-array-is-sorted0701/1
Solve the following coding problem using the programming language python: Given an array arr[] of size N, check if it is sorted in non-decreasing order or not. Example 1: Input: N = 5 arr[] = {10, 20, 30, 40, 50} Output: 1 Explanation: The given array is sorted. Example 2: Input: N = 6 arr[] = {90, 80, 100, 70, 40, 3...
```python class Solution: def arraySortedOrNot(self, arr, n): check = False for j in range(1, len(arr)): if arr[j] < arr[j - 1]: check = True return 0 if check == False: return 1 ```
vfc_133106
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/check-if-an-array-is-sorted0701/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 5\r\narr[] = {10, 20, 30, 40, 50}", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "N = 6\r\narr[] = {90, 80, 100, 70, 40, 30}", "output": "0", "type": "stdin_st...
taco
verifiable_code
https://codeforces.com/problemset/problem/848/A
Solve the following coding problem using the programming language python: From beginning till end, this message has been waiting to be conveyed. For a given unordered multiset of n lowercase English letters ("multi" means that a letter may appear more than once), we treat all letters as strings of length 1, and repea...
```python k = int(input()) for i in range(26): tt = 1 while tt * (tt + 1) // 2 <= k: tt += 1 k -= tt * (tt - 1) // 2 print(chr(97 + i) * tt, end='') print('') ```
vfc_133107
{ "difficulty": "medium_hard", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/848/A", "time_limit": "1.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "99681\n", "output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
taco
verifiable_code
Solve the following coding problem using the programming language python: Arrow is getting paranoid about Malcom merlyn, his arch-enemy. All his efforts to subdue Merlyn have been in vain. These days Arrow is working on a problem with John Diggle. Diggle mentioned that the Felicity has been facing weird problem with t...
```python t=eval(input()) for i in range(0,t): n=eval(input()) if(n%3==0): s="5"*n print(s) else: if((n-5)%3==0 and (n-5)>=0): s="5"*(n-5) s=s+"3"*5 print(s) else: k=5 cnt=1 f=0 while(((n-k)%3)!=0): cnt=cnt+1 k=5*cnt if(k<=n): f=1 else: f=0 if(f==0): prin...
vfc_133111
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "20\n69327\n24854\n34614\n35760\n98079\n10791\n13721\n31914\n33209\n80402\n10820\n73710\n82528\n98124\n20644\n11684\n85579\n39020\n68833\n2915", "output": "-1\n555\n33333\n55555533333", "type": "stdin_stdout" }, ...
taco
verifiable_code
https://www.codechef.com/problems/PALL01
Solve the following coding problem using the programming language python: The citizens of Byteland regularly play a game. They have blocks each denoting some integer from 0 to 9. These are arranged together in a random manner without seeing to form different numbers keeping in mind that the first block is never a 0. O...
```python n = int(input()) for i in range(n): p = int(input()) print('wins') if p == int(''.join(reversed(list(str(p))))) else print('loses') ```
vfc_133119
{ "difficulty": "easy", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/PALL01", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n331\n666\n343", "output": "loses\nwins\nwins", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n331\n699\n343", "output": "losses\nlosses\nwins\n", "type": "stdin_stdout" ...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/word-break-part-23249/1
Solve the following coding problem using the programming language python: Given a string s and a dictionary of words dict of length n, add spaces in s to construct a sentence where each word is a valid dictionary word. Each dictionary word can be used more than once. Return all such possible sentences. Follow examples...
```python class Solution: def search(self, word, dict): if word in dict: return True return False def solve(self, start, end, s, word_map, words, ans): if start > end: ans.append(words[:]) return for i in range(start, end + 1): if word_map.get(s[start:i + 1]): words.append(s[start:i + 1]) ...
vfc_133124
{ "difficulty": "medium_hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/word-break-part-23249/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "s = \"catsanddog\", n = 5 \r\ndict = {\"cats\", \"cat\", \"and\", \"sand\", \"dog\"}", "output": "(cats and dog)(cat sand dog)", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/14/A
Solve the following coding problem using the programming language python: A boy Bob likes to draw. Not long ago he bought a rectangular graph (checked) sheet with n rows and m columns. Bob shaded some of the squares on the sheet. Having seen his masterpiece, he decided to share it with his elder brother, who lives in ...
```python (n, m) = map(int, input().split()) data = [] for i in range(n): data.append(list(input())) boundary = [-1, -1, -1, -1] for i in range(n): for j in range(m): if data[i][j] == '*': if boundary[0] > j or boundary[0] == -1: boundary[0] = j if boundary[1] < j or boundary[1] == -1: boundary[1] = j...
vfc_133125
{ "difficulty": "easy", "memory_limit": "64.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/14/A", "time_limit": "1.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 6\n*****.\n", "output": "*****\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 1\n*\n.\n", "output": "*\n", "type": "stdin_stdout" }, { "fn_name": null, ...
taco
verifiable_code
https://codeforces.com/problemset/problem/199/C
Solve the following coding problem using the programming language python: Qwerty the Ranger took up a government job and arrived on planet Mars. He should stay in the secret lab and conduct some experiments on bacteria that have funny and abnormal properties. The job isn't difficult, but the salary is high. At the be...
```python import os import sys from math import * from collections import * from fractions import * from bisect import * from heapq import * from io import BytesIO, IOBase def vsInput(): sys.stdin = open('input.txt', 'r') sys.stdout = open('output.txt', 'w') BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def ...
vfc_133129
{ "difficulty": "medium_hard", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/199/C", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 5 2 10\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1000000 1000000 1 1\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, ...
taco
verifiable_code
Solve the following coding problem using the programming language python: Given a set S. Generate T, a set that contains all subsets of S minus the null set and calculate A, XOR sum of the set T. S={1,2,3} T={{1},{2},{3},{1,2},{1,3},{2,3} ,{1,2,3}} A=XORiana of T . XORiana of a set is defined as XOR of all the elem...
```python ''' # Read input from stdin and provide input before running code name = raw_input('What is your name?\n') print 'Hi, %s.' % name ''' T = int(input()) for t in range(T): n = int(input()) arr = input() print(0 if n!=1 else int(arr)) ```
vfc_133133
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "100\n100\n41 67 134 100 169 124 78 158 162 64 105 145 81 27 161 91 195 142 27 36 191 4 102 153 92 182 21 116 118 95 47 126 171 138 69 112 67 99 35 94 103 11 122 133 73 64 141 111 53 68 147 44 62 157 37 59 123 141 129 178 116 35 190...
taco
verifiable_code
https://www.hackerrank.com/challenges/the-grid-search/problem
Solve the following coding problem using the programming language python: Given an array of strings of digits, try to find the occurrence of a given pattern of digits. In the grid and pattern arrays, each string represents a row in the grid. For example, consider the following grid: 1234567890 0987654321 11111...
```python def pattern_here(G, row_i, g): i = G[row_i].find(g[0]) while i != -1: found = True for j in range(1, len(g)): if G[row_i + j][i:i + len(g[j])] != g[j]: found = False if found: return True i = G[row_i].find(g[0], i + 1) return False tests = int(input()) for _ in range(tests): (R, C) = lis...
vfc_133137
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.hackerrank.com/challenges/the-grid-search/problem", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n10 10\n7283455864\n6731158619\n8988242643\n3830589324\n2229505813\n5633845374\n6473530293\n7053106601\n0834282956\n4607924137\n3 4\n9505\n3845\n3530\n15 15\n400453592126560\n114213133098692\n474386082879648\n522356951189169\n887...
taco
verifiable_code
https://www.hackerrank.com/challenges/matrix-script/problem
Solve the following coding problem using the programming language python: Neo has a complex matrix script. The matrix script is a $N$ X $\mbox{M}$ grid of strings. It consists of alphanumeric characters, spaces and symbols (!,@,#,$,%,&). To decode the script, Neo needs to read each column and select only the alphanu...
```python import re (m, n) = list(map(int, input().split())) pattern = '([A-Za-z0-9]){1}[^A-Za-z0-9]{1,}([A-Za-z0-9]){1}' a = list() for row in range(m): a.append(input()) message = [] for col in range(n): for row in range(m): message.append(a[row][col]) mystring = ''.join(message) mystring2 = re.sub(pattern, '\\g<...
vfc_133145
{ "difficulty": "medium_hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.hackerrank.com/challenges/matrix-script/problem", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7 3\nTsi\nh%x\ni #\nsM \n$a \n#t%\nir!\n", "output": "This is Matrix# %!\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1184/A2
Solve the following coding problem using the programming language python: After learning about polynomial hashing, Heidi decided to learn about shift-xor hashing. In particular, she came across this interesting problem. Given a bitstring $y \in \{0,1\}^n$ find out the number of different $k$ ($0 \leq k < n$) such tha...
```python from math import gcd def canHash(n, ln): if n == '0' * ln: return ln ans = 0 yes = [] for i in range(1, ln): if ln % i == 0: token = 1 for k in range(i): a = sum([int(b) for b in n[k::i]]) if a % 2 != 0: token = 0 if token == 1: yes.append(i) ans += 1 elif gcd(ln, i) i...
vfc_133149
{ "difficulty": "hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1184/A2", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n1010\n", "output": "3\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/MANAPTS
Solve the following coding problem using the programming language python: Chef is playing a mobile game. In the game, Chef's character *Chefario* can perform special attacks. However, one special attack costs X mana points to Chefario. If Chefario currently has Y mana points, determine the maximum number of special ...
```python t = int(input()) for _ in range(t): (x, y) = map(int, input().split()) print(y // x) ```
vfc_133153
{ "difficulty": "easy", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/MANAPTS", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n10 30\n6 41\n50 2\n", "output": "3\n6\n0\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/STRP
Solve the following coding problem using the programming language python: An input string S of length N is transferred through the network using a special protocol. The protocol can send the string through a series of operations. In one operation, we can choose a lowercase english alphabet C and do one of the followin...
```python t = int(input()) for bunny in range(t): n = int(input()) s = input() count = 0 i = 0 while i < n: if i + 1 < n and s[i] == s[i + 1]: count += 1 i += 2 else: count += 1 i += 1 print(count) ```
vfc_133157
{ "difficulty": "easy", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/STRP", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n5\ncbcdc\n6\naabeee\n", "output": "5\n4\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/69/B
Solve the following coding problem using the programming language python: In Chelyabinsk lives a much respected businessman Nikita with a strange nickname "Boss". Once Nikita decided to go with his friend Alex to the Summer Biathlon World Cup. Nikita, as a very important person, received a token which allows to place ...
```python import os import sys from io import BytesIO, IOBase from types import GeneratorType from bisect import * from collections import defaultdict, deque, Counter import math import string from heapq import * from operator import add from itertools import accumulate BUFSIZE = 8192 sys.setrecursionlimit(10 ** 5) cl...
vfc_133161
{ "difficulty": "easy", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/69/B", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "20 30\n5 10 38 50\n17 18 86 42\n4 13 91 90\n20 20 45 31\n3 3 16 11\n16 16 80 66\n19 19 96 26\n15 20 7 84\n9 18 45 36\n5 19 89 6\n9 9 4 58\n9 14 97 31\n6 12 74 90\n4 5 84 2\n12 19 92 48\n16 16 92 55\n9 15 88 38\n6 14 8 66\n14 17 71 ...
taco
verifiable_code
https://codeforces.com/problemset/problem/1736/C1
Solve the following coding problem using the programming language python: This is the easy version of this problem. In this version, we do not have queries. Note that we have multiple test cases in this version. You can make hacks only if both versions of the problem are solved. An array $b$ of length $m$ is good if ...
```python n = int(input()) h = [] for i in range(n): k = int(input()) a = list(map(int, input().split())) j = 1 l = 0 l2 = 0 ll = 0 ll2 = 0 for i in range(k): if a[i] >= j: l = l + 1 else: j = a[i] if l % 2 == 0: ll = ll + (l + 1) * (l // 2) else: ll = ll + ((l + 1) * (l // 2) + l // 2 +...
vfc_133165
{ "difficulty": "easy", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1736/C1", "time_limit": "1 second" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n3\n1 2 3\n3\n1 1 1\n4\n2 1 4 3\n", "output": "6\n3\n7\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/41/C
Solve the following coding problem using the programming language python: Sometimes one has to spell email addresses over the phone. Then one usually pronounces a dot as dot, an at sign as at. As a result, we get something like vasyaatgmaildotcom. Your task is to transform it into a proper email address (vasya@gmail.c...
```python a = input() b = '' if a[0] + a[1] + a[2] == 'dot': b += 'dot' i = 3 elif a[0] + a[1] == 'at': b += 'at' i = 2 else: i = 0 at = 0 while i < len(a) - 3: if a[i] == 'd' and a[i + 1] == 'o' and (a[i + 2] == 't'): b += '.' i += 3 elif a[i] == 'a' and a[i + 1] == 't' and (at == 0): b += '@' at = 1 ...
vfc_133174
{ "difficulty": "easy", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/41/C", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "dotdotdotdotdotdotdotdotdotdotdotdoatdotdotdotdotdotdotdotdotdotdotdotdotdotdotdotdotdotdotdotdotdot\n", "output": "dot..........do@....................dot\n", "type": "stdin_stdout" }, { "fn_name": null, ...
taco
verifiable_code
Solve the following coding problem using the programming language python: Problem statement AOR Ika-chan is in a bad mood lately. Apparently, I don't like the ratio of the number of followers to the number of followers of "Ikatta". Currently, AOR Ika-chan has $ A $ followers, $ B $ followers, and a ratio of $ A: B $....
```python (a, b, n) = map(int, input().split()) score = abs(a - b) for x in range(1, n + 1): for y in range(1, n + 1): if b * x % y == 0: new_a = b * x // y score = min(score, abs(a - new_a)) print(score) ```
vfc_133180
{ "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": "19 28 3", "output": "5\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "19 51 3", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "19 ...
taco
verifiable_code
https://codeforces.com/problemset/problem/1559/D2
Solve the following coding problem using the programming language python: This is the hard version of the problem. The only difference between the two versions is the constraint on n. You can make hacks only if all versions of the problem are solved. A forest is an undirected graph without cycles (not necessarily con...
```python import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = 'x' in file.mode or 'r' not in file.mode self.write = self.buffer.write if self.writable else None def ...
vfc_133188
{ "difficulty": "very_hard", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1559/D2", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "100 10 9\n34 53\n72 57\n66 76\n24 2\n80 2\n80 63\n70 34\n71 48\n91 9\n73 3\n32 29\n73 38\n87 66\n19 28\n19 86\n77 5\n14 83\n67 26\n93 30\n", "output": "89\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\...
taco
verifiable_code
https://codeforces.com/problemset/problem/1108/E1
Solve the following coding problem using the programming language python: The only difference between easy and hard versions is a number of elements in the array. You are given an array $a$ consisting of $n$ integers. The value of the $i$-th element of the array is $a_i$. You are also given a set of $m$ segments. Th...
```python (n, m) = [int(i) for i in input().split()] A = [int(i) for i in input().split()] queries = [] for i in range(m): (l, r) = [int(x) for x in input().split()] queries.append([l, r]) if True: B = A[:] bestans = 0 bestq = [] for mnind in range(n): qans = [] B = A[:] for i in range(m): if queries[i][...
vfc_133196
{ "difficulty": "medium_hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1108/E1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 4\n2 -2 3 1 2\n1 3\n4 5\n2 5\n1 3\n", "output": "6\n2\n4 1 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 4\n2 -2 3 1 4\n3 5\n3 4\n2 4\n2 5\n", "output": "7\n2\n2 3 \n", ...
taco
verifiable_code
https://www.codechef.com/problems/RPDRDNG
Solve the following coding problem using the programming language python: You are given an array B of length 2N . You have an unknown array A which is sorted and contains *distinct* elements. You need to find out the array A. B contains all the medians of each prefix and suffix of the array A. A median is the middle ...
```python for i in range(int(input())): n = int(input()) B = [int(k) for k in input().split()] B.sort() d = dict() for k in range(2 * n): if B[k] not in d: d[B[k]] = 1 else: d[B[k]] += 1 c = list(set(B)) c.sort() if n == 1: if B[0] == B[1]: print(B[0]) else: print(-1) continue for k in ra...
vfc_133200
{ "difficulty": "medium_hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/RPDRDNG", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n3\n6 5 5 7 6 6\n3\n1 2 1 4 2 4", "output": "5 6 7\n-1", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/510/B
Solve the following coding problem using the programming language python: Fox Ciel is playing a mobile puzzle game called "Two Dots". The basic levels are played on a board of size n × m cells, like this: [Image] Each cell contains a dot that has some color. We will use different uppercase Latin characters to expres...
```python __author__ = 'artyom' (n, m) = map(int, input().split()) graph = [] for _ in range(n): graph.append(input()) def neighbours(vertex, colour): (x, y) = vertex res = [] if x > 0 and graph[x - 1][y] == colour: res.append((x - 1, y)) if y > 0 and graph[x][y - 1] == colour: res.append((x, y - 1)) if x < ...
vfc_133204
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/510/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 4\nAAAA\nABCA\nAAAA\n", "output": "Yes\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 4\nAAAA\nABCA\nAADA\n", "output": "No\n", "type": "stdin_stdout" }, { "...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/implement-two-stacks-in-an-array/1
Solve the following coding problem using the programming language python: Your task is to implement 2 stacks in one array efficiently. You need to implement 4 methods. push1 : pushes element into first stack. push2 : pushes element into second stack. pop1 : pops element from first stack and returns the popped element...
```python def push1(a, x): a.insert(0, x) def push2(a, x): a.insert(len(a), x) def pop1(a): if a: return a.pop(0) return -1 def pop2(a): if a: return a.pop(len(a) - 1) return -1 ```
vfc_133208
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/implement-two-stacks-in-an-array/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "push1(2)\npush1(3)\npush2(4)\npop1()\npop2()\npop2()", "output": "3 4 -1", "type": "stdin_stdout" }, { "fn_name": null, "input": "push1(1)\npush2(2)\r\npop1()\npush1(3)\npop1()\npop1()", "outpu...
taco
verifiable_code
Solve the following coding problem using the programming language python: Darshit is planning to celebrate the birthday of his friend, Diksha. There are two types of gifts that Diksha wants from Darshit: one is black and the other is white. To make her happy, Darshit has to buy B number of black gifts and W number of ...
```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!' t=eval(input()) while t>0: t-=1 b,w=list(map(int,input().split())) x,y,z=list(map(int,input().split())) b1=b*x b2=b*y+b*z w1=w*y w2=w*x+z*w print...
vfc_133209
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n10 10\n1 1 1\n5 9\n2 3 4\n3 6\n9 1 1\n7 7\n4 2 1\n3 3\n1 9 2", "output": "20\n37\n12\n35\n12", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: You're about to play a simplified "battleship" game with your little brother. The board for this game is a rectangular grid with R rows and C columns. At the start of the game, you will close your eyes, and you will keep them closed until the en...
```python import math t = int(eval(input())) k = 1 while(k<=t): lst = input() lst = lst.split() lst = list(map(int,lst)) r = lst[0] c = lst[1] w = lst[2] s = 0 if (w is 1): s = r*c print(("Case #"+str(k)+": "+str( r * (c/w + w -1)))) k = k+1 ```
vfc_133217
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n1 4 2\n1 7 7", "output": "Case #1: 3\nCase #2: 7\nCase #3: 10", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n1 4 2\n1 7 7\n2 5 1", "output": "Case #1: 3\nCase #2: 7", "typ...
taco
verifiable_code
https://codeforces.com/problemset/problem/139/A
Solve the following coding problem using the programming language python: One Sunday Petr went to a bookshop and bought a new book on sports programming. The book had exactly n pages. Petr decided to start reading it starting from the next day, that is, from Monday. Petr's got a very tight schedule and for each day o...
```python n = int(input()) l = list(map(int, input().split())) i = 0 while n > 0: if i == 7: i = 0 n -= l[i] if n > 0: i += 1 print(i + 1) ```
vfc_133225
{ "difficulty": "easy", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/139/A", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n1 0 1 0 1 0 1\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "7\n2 1 1 1 1 1 0\n", "output": "6\n", "type": "stdin_stdout" }, { "fn_name": nul...
taco
verifiable_code
https://www.codechef.com/PEND2020/problems/ITGUY03
Solve the following coding problem using the programming language python: Chef has a number N, Cheffina challenges the chef to check the divisibility of all the permutation of N by 2. If any of the permutations is divisible by 2 then print 1 else print 0. -----Input:----- - First-line will contain $T$, the number of ...
```python for i in range(int(input())): n = int(input()) flag = 0 while n > 0: if n % 10 % 2 == 0: flag = 1 break n = n // 10 if flag == 0: print(0) else: print(1) ```
vfc_133229
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/PEND2020/problems/ITGUY03", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n19\n385\n", "output": "0\n1\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: She is an apprentice wizard. She first learned the magic of manipulating time. And she decided to open a liquor store to earn a living. It has to do with the fact that all the inhabitants of the country where she lives love alcohol. Residents es...
```python while True: (n, m) = map(int, input().split()) if n == 0: break p = list(map(int, input().split())) if 1 in p: n = 0 print(n / 2) ```
vfc_133234
{ "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": "12 3\n2 3 6\n13 4\n1 2 3 6\n0 0", "output": "6.0\n0.0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "12 3\n2 3 6\n12 4\n2 2 3 6\n0 0", "output": "6.0\n6.0\n", "type": "stdin_s...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/median-of-bst/1
Solve the following coding problem using the programming language python: Given a Binary Search Tree of size N, find the Median of its Node values. Example 1: Input: 6 / \ 3 8 / \ / \ 1 4 7 9 Output: 6 Explanation: Inorder of Given BST will be: 1, 3, 4, 6, 7, 8, 9. So, here median...
```python def count_nodes(root): cnt = 0 temp = root while temp: if temp.left is None: cnt += 1 temp = temp.right else: pred = temp.left while pred.right and pred.right != temp: pred = pred.right if pred.right is None: pred.right = temp temp = temp.left else: pred.right = None ...
vfc_133242
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/median-of-bst/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": "findMedian", "input": "6\n / \\\n 3 8 \n / \\ / \\\n1 4 7 9", "output": "6", "type": "function_call" }, { "fn_name": "findMedian", "input": "6\n / \\\n 3 8 \n / \\ / ...
taco
verifiable_code
https://codeforces.com/problemset/problem/1561/C
Solve the following coding problem using the programming language python: In a certain video game, the player controls a hero characterized by a single integer value: power. The hero will have to beat monsters that are also characterized by a single integer value: armor. On the current level, the hero is facing $n$ c...
```python t = int(input()) results = [None] * t for l in range(t): n = int(input()) caves = [[int(x) for x in input().split()][1:] for _ in range(n)] min_levels = [(max((x - i + 1 for (i, x) in enumerate(cave))), len(cave)) for cave in caves] min_levels.sort(key=lambda x: x[0]) sub = 0 for (i, x) in enumerate(min...
vfc_133243
{ "difficulty": "easy", "memory_limit": "512 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1561/C", "time_limit": "2 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n1\n1 42\n2\n3 10 15 8\n2 12 11\n", "output": "43\n13\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/find-pair-given-difference1559/1
Solve the following coding problem using the programming language python: Given an array Arr[] of size L and a number N, you need to write a program to find if there exists a pair of elements in the array whose difference is N. Example 1: Input: L = 6, N = 78 arr[] = {5, 20, 3, 2, 5, 80} Output: 1 Explanation: (2, 80)...
```python class Solution: def findPair(self, arr, L, N): s = set() s.add(arr[0]) for i in range(1, len(arr)): if arr[i] - N in s or arr[i] + N in s: return True else: s.add(arr[i]) return False ```
vfc_133247
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/find-pair-given-difference1559/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "L = 6, N = 78\r\narr[] = {5, 20, 3, 2, 5, 80}", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "L = 5, N = 45\r\narr[] = {90, 70, 20, 80, 50}", "output": "-1", "type...
taco
verifiable_code
https://codeforces.com/problemset/problem/1552/E
Solve the following coding problem using the programming language python: The numbers $1, \, 2, \, \dots, \, n \cdot k$ are colored with $n$ colors. These colors are indexed by $1, \, 2, \, \dots, \, n$. For each $1 \le i \le n$, there are exactly $k$ numbers colored with color $i$. Let $[a, \, b]$ denote the interva...
```python def solve(): (n, k) = map(int, input().split()) arr = list(map(lambda x: int(x) - 1, input().split())) t = [[] for i in range(n)] for i in range(n * k): t[arr[i]].append(i) used = [0] * n c1 = [0] ans = [0] * n q = n // (k - 1) r = n % (k - 1) for i in range(k - 1): c1.append(c1[-1] + q + (i <= ...
vfc_133248
{ "difficulty": "hard", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1552/E", "time_limit": "1 second" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 3\n2 4 3 1 1 4 2 3 2 1 3 4\n", "output": "4 5\n7 9\n8 11\n2 6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 2\n1 1\n", "output": "1 2\n", "type": "stdin_stdout" }, ...
taco
verifiable_code
https://www.codechef.com/problems/SPLITMAX
Solve the following coding problem using the programming language python: Let f be a function, such that, for an array A of size M, f(A) is defined as f(A) = \sum_{i=1}^{M}\sum_{j=1, j \ne i}^{j=M} (A_{i}\cdot A_{j}) You are given an array C of size N. In one operation on the array, you can: Choose an index i (1≤ i ...
```python for i in range(int(input())): n = int(input()) l = list(map(int, input().split())) s = 0 for i in range(n): s = s + l[i] s = s % 998244353 s = s * (s - 1) s = s % 998244353 print(s) ```
vfc_133252
{ "difficulty": "easy", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/SPLITMAX", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n2\n1 2\n2\n1 3\n", "output": "6\n12\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/MAXMINK
Solve the following coding problem using the programming language python: You are given two arrays A and B, both of length N. You would like to choose exactly K distinct indices i_{1},i_{2}, \ldots, i_{K} such that \min(A_{i_{1}}+A_{i_{2}}+ \ldots + A_{i_{K}}, B_{i_{1}}+B_{i_{2}}+\ldots + B_{i_{K}}) is maximized. Fin...
```python def dp(n, k, a, b): dp = [[-1 for _ in range(1601)] for __ in range(k + 1)] dp[0][0] = 0 for i in range(n): for j in range(k - 1, -1, -1): for s in range(1601): if dp[j][s] != -1: dp[j + 1][s + a[i]] = max(dp[j][s] + b[i], dp[j + 1][s + a[i]]) ans = 0 for s in range(0, 1601): ans = max(an...
vfc_133256
{ "difficulty": "very_hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/MAXMINK", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n5 3\n4 2 3 1 4\n3 2 5 5 1\n4 2\n1 2 3 4\n4 3 2 1\n6 3\n8 10 3 6 7 2\n4 8 4 1 1 6\n", "output": "9\n5\n18\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: Given a character C, print the ASCII value of that character. Input: First and only line in input contains a character C. Output: Print the ASCII value of the character C. Constraints: C ∈ ASCII characters SAMPLE INPUT b SAMPLE OUTPUT 98...
```python x=input() print(ord(x)) ```
vfc_133260
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "z", "output": "81", "type": "stdin_stdout" }, { "fn_name": null, "input": "4", "output": "52", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: You are given an array S of N strings numbered from 0 to N-1. You build string sequence Ti by the following rules: T0 = S0 Ti = Ti-1 + reverse(Ti-1) + Si Now please answer M queries: by non-negative integer x output x-th character of the TN-1 ...
```python def getch(i,z): if (i==0): return s[0][z] else: if (z < lu[i-1]): return getch(i-1,z) z-=lu[i-1] if (z < lu[i-1]): return getch(i-1,lu[i-1]-1-z) z-=lu[i-1] return s[i][z] t=eval(input()) while t: t-=1 n,m=list(map(int,input().split())) b="" s=[] l=[] lu=[] for x in range(n): ...
vfc_133265
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "100\n2 1000\nqghumeaylnlfdxfircvscxggbwkfnqduxwfnfozvsrtkjprepggxrpnrvystmwcysyyc\npevikeffmznimkkasvwsrenzkycxfxtlsgypsfadpooefxz\n108\n61\n151\n148\n142\n14\n164\n45\n28\n111\n176\n130\n136\n173\n63\n154\n69\n176\n9\n112\n182\n93...
taco
verifiable_code
https://codeforces.com/problemset/problem/250/A
Solve the following coding problem using the programming language python: Polycarpus has been working in the analytic department of the "F.R.A.U.D." company for as much as n days. Right now his task is to make a series of reports about the company's performance for the last n days. We know that the main information in...
```python n = int(input()) s = [int(i) for i in input().split()] d = [] (l, r) = (0, 0) cnt = 0 while r < n: if cnt == 2 and s[r] < 0: d.append(s[l:r]) cnt = 1 l = r r += 1 else: if s[r] < 0: cnt += 1 r += 1 if cnt < 3: d.append(s[l:r]) print(len(d)) s = [len(i) for i in d] print(*s) ```
vfc_133273
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/250/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "11\n1 2 3 -4 -5 -6 5 -5 -6 -7 6\n", "output": "3\n5 3 3 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n0 -1 100 -1 0\n", "output": "1\n5 ", "type": "stdin_stdout" } ] ...
taco
verifiable_code
https://codeforces.com/problemset/problem/1005/E1
Solve the following coding problem using the programming language python: You are given a permutation $p_1, p_2, \dots, p_n$. A permutation of length $n$ is a sequence such that each integer between $1$ and $n$ occurs exactly once in the sequence. Find the number of pairs of indices $(l, r)$ ($1 \le l \le r \le n$) s...
```python import sys (n, m) = map(int, input().split()) s = list(map(int, input().split())) try: ind = s.index(m) except: print(0) sys.exit() dp = [0 for i in range(n)] for i in range(ind + 1, n): if s[i] < m: dp[i] = dp[i - 1] - 1 elif s[i] > m: dp[i] = dp[i - 1] + 1 for i in range(ind - 1, -1, -1): if s[i] ...
vfc_133277
{ "difficulty": "medium_hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1005/E1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 4\n2 4 5 3 1\n", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 5\n1 2 3 4 5\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, ...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/rearrange-a-linked-list/1
Solve the following coding problem using the programming language python: Given a singly linked list, the task is to rearrange it in a way that all odd position nodes are together and all even positions node are together. Assume the first element to be at position 1 followed by second element at position 2 and so on. ...
```python class Solution: def rearrangeEvenOdd(self, head): i = 0 even = [] odd = [] a = [] temp1 = head temp2 = head while temp1: i += 1 if i % 2 == 0: even.append(temp1.data) else: odd.append(temp1.data) temp1 = temp1.next a = odd + even for item in a: temp2.data = item t...
vfc_133281
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/rearrange-a-linked-list/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "LinkedList:1->2->3->4", "output": "1 3 2 4", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1575/K
Solve the following coding problem using the programming language python: Mr. Chanek wants to knit a batik, a traditional cloth from Indonesia. The cloth forms a grid a with size n × m. There are k colors, and each cell in the grid can be one of the k colors. Define a sub-rectangle as an ordered pair of two cells ((x...
```python (n, m, k, r, c) = map(int, input().split()) (ax, ay, bx, by) = map(int, input().split()) p = n * m if ax != bx or ay != by: p -= r * c print(pow(k, p, 1000000007)) ```
vfc_133282
{ "difficulty": "hard", "memory_limit": "512.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1575/K", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "997824195 298198038 671030405 831526 973640\n694897941 219757278 695597597 220039071\n", "output": "885735196\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "78 15 967084213 68 15\n6 1 9 1...
taco
verifiable_code
https://codeforces.com/problemset/problem/1104/A
Solve the following coding problem using the programming language python: Vasya has his favourite number $n$. He wants to split it to some non-zero digits. It means, that he wants to choose some digits $d_1, d_2, \ldots, d_k$, such that $1 \leq d_i \leq 9$ for all $i$ and $d_1 + d_2 + \ldots + d_k = n$. Vasya likes b...
```python a = int(input()) if a % 9 == 0: print(a // 9) for i in range(a // 9): print(9, end=' ') elif a % 8 == 0: print(a // 8) for i in range(a // 8): print(8, end=' ') elif a % 7 == 0: print(a // 7) for i in range(a // 7): print(7, end=' ') elif a % 6 == 0: print(a // 6) for i in range(a // 6): print...
vfc_133286
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1104/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n", "output": "1\n1 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n", "output": "4\n1 1 1 1 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "2...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/recursively-find-sum-of-digits3558/1
Solve the following coding problem using the programming language python: Given two numbers A and B, the task is to find f(A^{B}). f(n) which takes a positive integer n as input and does the following: f(n): if n < 10 return n else return f( sum_of_digits(n) ) Example 1: Input: A = 6, B = 6 Output: 9 Explanati...
```python class Solution: def SumofDigits(self, a, b): k = 1 while b: if b & 1: k = k * a % 9 a = a * a % 9 b = b >> 1 if k == 0: return 9 return k ```
vfc_133290
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/recursively-find-sum-of-digits3558/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "A = 6, B = 6", "output": "9", "type": "stdin_stdout" }, { "fn_name": null, "input": "A = 7, B = 3", "output": "1", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/134/B
Solve the following coding problem using the programming language python: Let's assume that we have a pair of numbers (a, b). We can get a new pair (a + b, b) or (a, a + b) from the given pair in a single step. Let the initial pair of numbers be (1,1). Your task is to find number k, that is, the least number of steps...
```python import sys def solve(): n = int(input()) if n == 1: return 0 res = 1000000 for other in range(n - 1, 0, -1): pair = [n, other] temp = 0 while (pair[0] > 1 or pair[1] > 1) and (pair[0] > 0 and pair[1] > 0): pair.sort() multiples = (pair[1] - 1) // pair[0] if multiples == 0: break p...
vfc_133291
{ "difficulty": "hard", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/134/B", "time_limit": "1.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "999998\n", "output": "30\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "12345...
taco
verifiable_code
https://codeforces.com/problemset/problem/182/D
Solve the following coding problem using the programming language python: Vasya has recently learned at school what a number's divisor is and decided to determine a string's divisor. Here is what he came up with. String a is the divisor of string b if and only if there exists a positive integer x such that if we writ...
```python s1 = input() s2 = input() n = len(s1) m = len(s2) cnt = 0 from math import gcd g = gcd(n, m) for i in range(g): if n % (i + 1) == 0 and m % (i + 1) == 0: if s1[:i + 1] * (n // (i + 1)) == s1 and s1[:i + 1] * (m // (i + 1)) == s2: cnt += 1 print(cnt) ```
vfc_133300
{ "difficulty": "medium", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/182/D", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "aba\nabaaba\n", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "ab\nab\n", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "...
taco
verifiable_code
https://www.codechef.com/COZL2012/problems/RBX12R01
Solve the following coding problem using the programming language python: Mr. X stays in a mansion whose door opens in the North. He travels every morning to meet his friend Ms. Y walking a predefined path. To cut the distance short, one day he decides to construct a skywalk from his place to his friend’s place. Help...
```python from math import sqrt def process(S): P = [0, 0, 'S'] for i in S: if i == 'L': if P[-1] == 'N': P[-1] = 'W' elif P[-1] == 'S': P[-1] = 'E' elif P[-1] == 'E': P[-1] = 'N' elif P[-1] == 'W': P[-1] = 'S' elif i == 'R': if P[-1] == 'N': P[-1] = 'E' elif P[-1] == 'S': ...
vfc_133304
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/COZL2012/problems/RBX12R01", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n2 L 2 R 2 L 1\n", "output": "5.0NW\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/shortest-path-in-undirected-graph/1
Solve the following coding problem using the programming language python: Given a Directed Acyclic Graph of N vertices from 0 to N-1 and a 2D Integer array(or vector) edges[ ][ ] of length M, where there is a directed edge from edge[i][0] to edge[i][1] with a distance of edge[i][2] for all i, 0<=i Find the shortest pa...
```python from typing import List import math class Solution1: def shortestPath(self, n: int, m: int, edges: List[List[int]]) -> List[int]: distance = [100000] * n distance[0] = 0 for i in range(n - 1): for edge in edges: u = edge[0] v = edge[1] w = edge[2] if distance[u] + w < distance[v]: ...
vfc_133312
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/shortest-path-in-undirected-graph/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 4, M = 2\nedge = [[0,1,2],[0,2,1]", "output": "0 2 1 -1", "type": "stdin_stdout" }, { "fn_name": null, "input": "N = 6, M = 7\nedge = [[0,1,2],[0,4,1],[4,5,4],[4,2,2],[1,2,3],[2,3,6],[5,3,1]]", ...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/93c977e771fc0d82e87ba570702732edb2226ad7/1
Solve the following coding problem using the programming language python: Given two arrays that represent Preorder traversals of a Full binary tree preOrder[] and its mirror tree preOrderMirror[], your task is to complete the function constructBinaryTree(), that constructs the full binary tree using these two Preorder...
```python class Node: def __init__(self, value): self.data = value self.left = None self.right = None class Solution: def constructBinaryTree(self, pre, preM, n): self.i = 0 return self.util(pre, preM, n) def util(self, pre, preM, n): if self.i == n: return None j = 0 while j < n: if preM[j...
vfc_133317
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/93c977e771fc0d82e87ba570702732edb2226ad7/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "preOrder[] = {0,1,2}\npreOrderMirror[] = {0,2,1}", "output": "0\n / \\\n 1 2", "type": "stdin_stdout" }, { "fn_name": null, "input": "preOrder[] = {1,2,4,5,3,6,7}\npreO...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/largest-value-in-each-level/1
Solve the following coding problem using the programming language python: Given a binary tree, find the largest value in each level. Example 1: Input : 1 / \ 2 3 Output : 1 3 Explanation : There are two levels in the tree : 1. {1}, max = 1 2. {2, 3}, max = 3 Example 2: Input : 4 ...
```python class Solution: def largestValues(self, root): if not root: return [] ans = [] current = [root] while current: new_curr = [] maxx = -999999999 for node in current: maxx = max(maxx, node.data) if node.left: new_curr.append(node.left) if node.right: new_curr.append(no...
vfc_133318
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/largest-value-in-each-level/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n / \\\n 2 3", "output": "1 3", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n / \\\n 9 2\n / \\ \\\n 3 5 7", "output": "4 9 7", "type...
taco
verifiable_code
Solve the following coding problem using the programming language python: In this problem your goal is to guess some secret permutation A of integers from 1 to 16. There are 17 tests in this problem. Test number i for 1 ≤ i ≤ 16 will have the following form: the first line of the input contains string "ELEMENT" (wit...
```python x = input() if x == "PERMUTATION": print("13 15 1 6 14 4 5 7 2 16 9 11 10 12 8 3") else: a, b = list(map(int, input().split(' '))) if (a == 1): print((13)) elif a == 2: print((15)) elif a == 3: print((1)) elif a == 4: print((6)) elif a == 5: print((14)) elif a == 6: print((4)) elif a == 7...
vfc_133319
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "ELEMENT\n3 1", "output": "8", "type": "stdin_stdout" }, { "fn_name": null, "input": "ELEMENT\n8 7", "output": "14", "type": "stdin_stdout" }, { "fn_name": null, "input...
taco
verifiable_code
https://codeforces.com/problemset/problem/566/A
Solve the following coding problem using the programming language python: Teachers of one programming summer school decided to make a surprise for the students by giving them names in the style of the "Hobbit" movie. Each student must get a pseudonym maximally similar to his own name. The pseudonym must be a name of s...
```python import sys class Node: def __init__(self, d): global nodes self.ch = {} self.a = [[], []] self.d = d nodes += [self] nodes = [] pairs = [] res = 0 N = int(sys.stdin.readline()) _input = sys.stdin.readlines() _input = [s[:-1] for s in _input] A = [_input[:N], _input[N:]] T = Node(0) for (i, l) in ...
vfc_133327
{ "difficulty": "hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/566/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\ngennady\ngalya\nboris\nbill\ntoshik\nbilbo\ntorin\ngendalf\nsmaug\ngaladriel\n", "output": "11\n4 1\n2 5\n1 3\n5 2\n3 4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\na\na\n", ...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/first-repeating-element4018/1
Solve the following coding problem using the programming language python: Given an array arr[] of size n, find the first repeating element. The element should occur more than once and the index of its first occurrence should be the smallest. Note:- The position you return should be according to 1-based indexing. Exam...
```python class Solution: def firstRepeated(self, arr, n): d = {} for i in arr: if i not in d: d[i] = 1 else: d[i] += 1 for i in range(len(arr)): if d[arr[i]] > 1: return i + 1 return -1 ```
vfc_133331
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/first-repeating-element4018/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "n = 7\r\narr[] = {1, 5, 3, 4, 3, 5, 6}", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "n = 4\r\narr[] = {1, 2, 3, 4}", "output": "-1", "type": "stdin_stdout" }...
taco
verifiable_code
https://codeforces.com/problemset/problem/304/C
Solve the following coding problem using the programming language python: Bike is interested in permutations. A permutation of length n is an integer sequence such that each integer from 0 to (n - 1) appears exactly once in it. For example, [0, 2, 1] is a permutation of length 3 while both [0, 2, 2] and [1, 2, 3] is n...
```python r = int(input()) if r % 2 == 0: print(-1) elif r == 1: print(0) print(0) print(0) else: for i in range(r): print(i, end=' ') print() i = r - 1 while i >= 0: print(i, end=' ') i -= 2 i = r - 2 while i >= 0: print(i, end=' ') i -= 2 print() for i in range(r - 1, -1, -1): print(i, end=' '...
vfc_133332
{ "difficulty": "easy", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/304/C", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "11805\n", "output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 7...
taco
verifiable_code
Solve the following coding problem using the programming language python: On the way to Dandi March, Gandhijee carried a mirror with himself. When he reached Dandi, he decided to play a game with the tired people to give them some strength. At each turn of the game he pointed out a person and told him to say a number ...
```python t = int(input()) for x in range(t): num = input() flag = 0 for i in num: if int(i) == 1 or int(i) == 0 or int(i) == 8: flag = 0 else: flag = 1 break if flag == 1: print("NO") else: if num == num[::-1]: print("YES") else: print("NO") ```
vfc_133336
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "100\n1811810018881018180000801108888080018110808008018118108008080118100808888011080000818101888100181181\n1810018011188001181180801800080801081881008181800880081818001881801080800081080811811008811108100181\n1810000880888100800010...