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/114/B
Solve the following coding problem using the programming language python: When little Petya grew up and entered the university, he started to take part in АСМ contests. Later he realized that he doesn't like how the АСМ contests are organised: the team could only have three members (and he couldn't take all his friend...
```python from sys import stdin, stdout from collections import deque import sys from copy import deepcopy import math import collections from itertools import combinations def check(temp): for i in range(len(temp)): for j in range(i + 1, len(temp)): if temp[i] in enemy: if temp[j] in enemy[temp[i]]: re...
vfc_85112
{ "difficulty": "medium", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/114/B", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7 6\nAlena\nOlya\nVanya\nBrus\nJohn\nAlice\nMariana\nAlena John\nAlena Alice\nOlya John\nOlya Alice\nVanya John\nVanya Alice\n", "output": "5\nAlena\nBrus\nMariana\nOlya\nVanya\n", "type": "stdin_stdout" }, { ...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/nikits-problem1028/1
Solve the following coding problem using the programming language python: Nikit has to give a short contest of duration "n" minutes. The contest is divided into 2 sections-Easy and Hard. x and y marks will be awarded per problem for Easy and Hard respectively. Assume that he will take p minutes to solve an Easy proble...
```python class Solution: def maximumScore(self, n, x, y, a, b, p, q): max = 0 lst = [0, 0] for i in range(0, a + 1): for j in range(0, b + 1): if i * x + j * y > max and i * p + j * q <= n: max = i * x + j * y lst[0] = i lst[1] = j elif i * x + j * y == max and i * p + j * q <= n and ...
vfc_85116
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/nikits-problem1028/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "n = 180, x = 2, y = 5, a = 4\r\nb = 6,p = 20, q = 40", "output": "1 4", "type": "stdin_stdout" }, { "fn_name": null, "input": "n = 50, x = 5, y = 10, a = 5 \r\nb = 3, p = 10, q = 20", "output":...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/max-min/1
Solve the following coding problem using the programming language python: Given an array A of size N of integers. Your task is to find the sum of minimum and maximum element in the array. Example 1: Input: N = 5 A[] = {-2, 1, -4, 5, 3} Output: 1 Explanation: min = -4, max = 5. Sum = -4 + 5 = 1 Example 2: Input: N =...
```python class Solution: def findSum(self, A, N): A.sort() return A[0] + A[len(A) - 1] ```
vfc_85120
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/max-min/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 5\r\nA[] = {-2, 1, -4, 5, 3}", "output": "1", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/sort-the-pile-of-cards3733/1
Solve the following coding problem using the programming language python: We have n cards with each card numbered from 1 to n. All cards are randomly shuffled. We are allowed only operation moveCard(n) which moves the card with value n to the top of the pile. You are required to find out the minimum number of moveCard...
```python def minOps(a, n): stack = [] a.reverse() for item in a: while stack and stack[-1] < item: stack.pop() stack.append(item) i = 1 while i < len(stack) and stack[i] + 1 == stack[i - 1]: i += 1 return n - i ```
vfc_85121
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/sort-the-pile-of-cards3733/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": "minOps", "input": "n = 5\r\na[] = {5, 1, 2, 3, 4}", "output": "4", "type": "function_call" }, { "fn_name": "minOps", "input": "n = 4\r\na[] = {3, 4, 2, 1}", "output": "2", "type": "function_call" }...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/get-min-at-pop/1
Solve the following coding problem using the programming language python: Now, we'll try to solve a famous stack problem. You are given an array A of size N. You need to first push the elements of the array into a stack and then print minimum in the stack at each pop until stack becomes empty. Example 1: Input: N = 5...
```python def _push(a, n): stack = [] for i in a: stack.append(i) return stack def _getMinAtPop(stack): for i in range(len(stack)): print(min(stack), end=' ') stack.pop() ```
vfc_85123
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/get-min-at-pop/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": "_push", "input": "N = 5\r\nA = {1 2 3 4 5}", "output": "1 1 1 1 1", "type": "function_call" } ] }
taco
verifiable_code
https://www.codechef.com/UWCOI21/problems/UWCOI21C
Solve the following coding problem using the programming language python: Salmon loves to be a tidy person. One day, when he looked at the mess that he made after playing with his rubber ducks, he felt awful. Now he wants to clean up his mess, by placing his ducks into boxes. Each rubber duck has a color. There are a ...
```python for _ in range(int(input())): (n, k) = map(int, input().split()) c = [int(i) for i in input().split()] i = 0 m = 0 if n == 2 and k == 5: c1 = c c.sort() d = dict() for i in range(len(c)): for j in range(len(c1)): if c[i] == c1[j]: d[i] = j c1[j] = -1 break while m < n: ...
vfc_85124
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/UWCOI21/problems/UWCOI21C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n2 4\n3 4 1\n", "output": "2 1 1 3\n1 1 0 3\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.hackerrank.com/challenges/two-arrays/problem
Solve the following coding problem using the programming language python: There are two $n$-element arrays of integers, $A$ and $B$. Permute them into some $A^{\prime}$ and $B^{\prime}$ such that the relation $A^{\prime}[i]+B^{\prime}[i]\ge k$ holds for all $i$ where $0\leq i<n$. There will be $q$ queries consisting...
```python def isGood(listA, listB, k): n = len(listA) listA.sort() listB.sort(reverse=True) for i in range(n): if listA[i] + listB[i] < k: return False return True T = int(input().strip()) for i in range(T): [n, k] = [int(x) for x in input().strip().split()] listA = [int(x) for x in input().strip().split()]...
vfc_85132
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.hackerrank.com/challenges/two-arrays/problem", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n3 10\n2 1 3\n7 8 9\n4 5\n1 2 2 1\n3 3 3 4\n", "output": "YES\nNO\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/PCJ18F
Solve the following coding problem using the programming language python: Today, Chef has a fencing job at hand and has to fence up a surface covering N$N$ points. To minimize his work, he started looking for an algorithm that had him fence the least amount of length. He came up with the Convex Hull algorithm, but s...
```python import math (n, m) = map(int, input().split()) hyp = math.sqrt(1 + m * m) cosx = 1 / hyp sinx = m / hyp ptsx = [] ptsy = [] for i in range(n): (px, py) = list(map(int, input().strip().split())) ptsx.append(cosx * px + sinx * py) ptsy.append(cosx * py - sinx * px) w = max(ptsx) - min(ptsx) l = max(ptsy) - m...
vfc_85141
{ "difficulty": "very_hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/PCJ18F", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 1\n 0 1\n 0 -1\n 1 0\n -1 0\n\n", "output": "5.656854249492380\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/union-of-two-arrays3538/1
Solve the following coding problem using the programming language python: Given two arrays a[] and b[] of size n and m respectively. The task is to find the number of elements in the union between these two arrays. Union of the two arrays can be defined as the set containing distinct elements from both the arrays. If...
```python class Solution: def doUnion(self, a, n, b, m): return len(set(a + b)) ```
vfc_85145
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/union-of-two-arrays3538/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 3\r\n1 2 3 4 5\r\n1 2 3", "output": "5", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 2 \r\n85 25 1 32 54 6\r\n85 2", "output": "7", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/471/A
Solve the following coding problem using the programming language python: Two polar bears Menshykov and Uslada from the St.Petersburg zoo and elephant Horace from the Kiev zoo got six sticks to play with and assess the animals' creativity. Menshykov, Uslada and Horace decided to make either an elephant or a bear from ...
```python a = list(map(int, input().split())) for i in range(6): if a.count(a[i]) >= 4: v = a[i] break else: print('Alien') exit() for i in range(4): a.remove(v) a.sort() if a[0] < a[1]: print('Bear') elif a[0] == a[1]: print('Elephant') else: print('Alien') ```
vfc_85150
{ "difficulty": "easy", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/471/A", "time_limit": "1.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 5 5 5 5 5\n", "output": "Elephant\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 4 4 4 2 2\n", "output": "Elephant\n", "type": "stdin_stdout" }, { "fn_name":...
taco
verifiable_code
https://codeforces.com/problemset/problem/1353/D
Solve the following coding problem using the programming language python: You are given an array $a$ of length $n$ consisting of zeros. You perform $n$ actions with this array: during the $i$-th action, the following sequence of operations appears: Choose the maximum by length subarray (continuous subsegment) consist...
```python def generate(l, n): if n <= 0: return if n == 1: d.append((l, 1, l)) return elif n % 2 == 1: d.append((l, n, l + (n - 1) // 2)) generate(l, (n - 1) // 2) generate(l + (n - 1) // 2 + 1, (n - 1) // 2) else: d.append((l, n, l + (n - 1) // 2)) generate(l, (n - 1) // 2) generate(l + n // 2, (...
vfc_85154
{ "difficulty": "medium_hard", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1353/D", "time_limit": "1 second" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n1\n2\n3\n4\n5\n6\n", "output": "1 \n1 2 \n2 1 3 \n3 1 2 4 \n2 4 1 3 5 \n3 4 1 5 2 6 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n1\n2\n3\n4\n4\n6\n", "output": "1\n1 2\n2 1...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/ncr-mod-m-part-10038/1
Solve the following coding problem using the programming language python: Given 2 integers n and r. You task is to calculate ^{n}Cr%1000003. Example 1: Input: n = 5, r = 2 Output: 10 Explanation: ^{5}C2 = 5! / (2! * 3!) = 10 Example 2: Input: n = 3, r = 2 Output: 3 Explanation: ^{3}C2 = 3! / (2! * 1!) = 3 Your Tas...
```python M = 1000003 class Solution: def __init__(self): self.f = [1] * M for i in range(1, M): self.f[i] = self.f[i - 1] * i % M def nCr(self, n, r): if r > n: return 0 if r == 0: return 1 if n < M and r < M: return self.f[n] * pow(self.f[r], M - 2, M) * pow(self.f[n - r], M - 2, M) % M r...
vfc_85158
{ "difficulty": "medium_hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/ncr-mod-m-part-10038/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "n = 5, r = 2", "output": "10", "type": "stdin_stdout" }, { "fn_name": null, "input": "n = 3, r = 2", "output": "3", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: Jerry is a little mouse. He is trying to survive from the cat Tom. Jerry is carrying a parallelepiped-like piece of cheese of size A × B × C. It is necessary to trail this cheese to the Jerry's house. There are several entrances in the Jerry's h...
```python while True: (d, w, h) = sorted(map(int, input().split())) if d == w == h == 0: break dw = d ** 2 + w ** 2 n = int(input()) for i in range(n): y = int(input()) if (2 * y) ** 2 > dw: print('OK') else: print('NA') ```
vfc_85165
{ "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": "10 6 8\n5\n4\n1\n6\n2\n5\n0 0 0", "output": "NA\nNA\nOK\nNA\nNA\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.hackerrank.com/challenges/dijkstrashortreach/problem
Solve the following coding problem using the programming language python: Given an undirected graph and a starting node, determine the lengths of the shortest paths from the starting node to all other nodes in the graph. If a node is unreachable, its distance is -1. Nodes will be numbered consecutively from $1$ to $...
```python import heapq def find(V, N, S): dist = [-1 for x in range(N)] visited = [False for x in range(N)] Q = [(0, S)] dist[S] = 0 while Q: (mindist, minv) = heapq.heappop(Q) if not visited[minv]: for x in V[minv]: if dist[x] == -1: dist[x] = mindist + V[minv][x] else: dist[x] = min(dis...
vfc_85169
{ "difficulty": "medium_hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.hackerrank.com/challenges/dijkstrashortreach/problem", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n4 4\n1 2 24\n1 4 20\n3 1 3\n4 3 12\n1\n", "output": "24 3 15\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.hackerrank.com/challenges/john-and-gcd-list/problem
Solve the following coding problem using the programming language python: John is new to Mathematics and does not know how to calculate GCD of numbers. So he wants you to help him in a few GCD calculations. John has a list A of numbers, indexed 1 to N. He wants to create another list B having N+1 numbers, indexed from...
```python def gcd(a, b): return a if b == 0 else gcd(b, a % b) def lcm(a, b): return a * b // gcd(a, b) for _ in range(int(input())): n = int(input()) (a, ret) = ([1] + list(map(int, input().split())) + [1], '') for i in range(1, n + 2): ret += str(lcm(a[i], a[i - 1])) + ' ' print(ret) ```
vfc_85173
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.hackerrank.com/challenges/john-and-gcd-list/problem", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n3\n1 2 3\n3\n5 10 5\n", "output": "1 2 6 3\n5 10 10 5\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1608/B
Solve the following coding problem using the programming language python: You are given three integers $n, a, b$. Determine if there exists a permutation $p_1, p_2, \ldots, p_n$ of integers from $1$ to $n$, such that: There are exactly $a$ integers $i$ with $2 \le i \le n-1$ such that $p_{i-1} < p_i > p_{i+1}$ (in ot...
```python for s in [*open(0)][1:]: (n, a, b) = map(int, s.split()) r = (-1,) if -2 < a - b < 2 and a + b < n - 1: (*r,) = range(1, n + 1) j = a >= b k = a > b for i in [*range(2 - j, a + b - k + j, 2)] + ([(n - 2) * k], [])[a == b]: r[i:i + 2] = (r[i + 1], r[i]) print(*r) ```
vfc_85177
{ "difficulty": "easy", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1608/B", "time_limit": "1 second" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n4 1 1\n6 1 2\n6 4 0\n", "output": "1 4 2 3\n6 5 1 4 2 3\n-1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n86854 80785 15912\n", "output": "-1\n", "type": "stdin_stdout"...
taco
verifiable_code
https://www.hackerrank.com/challenges/bear-and-steady-gene/problem
Solve the following coding problem using the programming language python: A gene is represented as a string of length $n$ (where $n$ is divisible by $4$), composed of the letters $\mbox{A}$, $\mbox{C}$, $\textbf{T}$, and $\mbox{G}$. It is considered to be steady if each of the four letters occurs exactly $\frac{n}{4}$...
```python def solve(S, n): count = {} for c in S: count[c] = count.get(c, 0) + 1 for c in count: if count[c] > n // 4: count[c] = count[c] - n // 4 else: count[c] = 0 if sum((count[c] for c in count)) == 0: return 0 count2 = {} (i, j, best) = (0, 0, n) while j < n: while j < n and any((count2.get...
vfc_85181
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.hackerrank.com/challenges/bear-and-steady-gene/problem", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "8 \nGAAATAAA\n", "output": "5\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1579/A
Solve the following coding problem using the programming language python: Casimir has a string $s$ which consists of capital Latin letters 'A', 'B', and 'C' only. Each turn he can choose to do one of the two following actions: he can either erase exactly one letter 'A' and exactly one letter 'B' from arbitrary places...
```python def solve(s): return s.count('B') == s.count('A') + s.count('C') n = int(input()) for i in range(n): s = input() if solve(s): print('YES') else: print('NO') ```
vfc_85185
{ "difficulty": "easy", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1579/A", "time_limit": "2 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\nABACAB\nABBA\nAC\nABC\nCABCBB\nBCBCBCBCBCBCBCBC\n", "output": "NO\nYES\nNO\nNO\nYES\nYES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\nABACAB\nABBA\nAC\nABC\nCABCBB\nCBCBCBCBCBCBCB...
taco
verifiable_code
https://www.codechef.com/problems/XORGM
Solve the following coding problem using the programming language python: Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. You are given an odd integer $N$ and two integer sequences $A_{1}, A_{2}, \ldots, A_{N}$ and $B_{1}, B_{2}, \ldots, B_{N}$. Your task is t...
```python import itertools t = int(input()) for _ in range(t): N = int(input()) A = list(map(int, input().split(' '))) B = list(map(int, input().split(' '))) ultimate_sum = 0 for i in range(20): mask = 1 << i count_a = 0 count_b = 0 for (a, b) in zip(A, B): if a & mask > 0: count_a += 1 if b & ma...
vfc_85194
{ "difficulty": "hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/XORGM", "time_limit": "2 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n5\n3 1 2 4 5\n2 4 5 1 3", "output": "3 1 2 4 5", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/474/F
Solve the following coding problem using the programming language python: Mole is hungry again. He found one ant colony, consisting of n ants, ordered in a row. Each ant i (1 ≤ i ≤ n) has a strength si. In order to make his dinner more interesting, Mole organizes a version of «Hunger Games» for the ants. He chooses t...
```python from math import gcd class SegTree: def __init__(self, arr=None, length=None): if arr is not None: self.n = len(arr) self.t = [1 for _ in range(2 * self.n)] self.ct = [0] * self.n + [1] * self.n self.construct(arr) else: assert False self.n = length self.t = [1 for _ in range(2 * s...
vfc_85198
{ "difficulty": "hard", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/474/F", "time_limit": "1.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n1 5 2 4 2\n4\n1 5\n2 5\n3 5\n4 5\n", "output": "4\n4\n1\n1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n1 3 4 4 2\n4\n1 5\n2 5\n3 5\n4 5\n", "output": "4\n4\n2\n1\n", ...
taco
verifiable_code
https://www.codechef.com/problems/SUBMIN
Solve the following coding problem using the programming language python: Little Elephant is playing a game with arrays. He is given an array A0, A1, ..., AN−1 of N integers. And then Q queries are given, each containing an integer K. He has to tell how many subarrays satisfy the condition: the function foo returns K ...
```python n = int(input()) a = list(map(int, input().split())) cnt = {} for i in range(n): mn = a[i] for j in range(i, n): mn = min(mn, a[j]) if mn in cnt: cnt[mn] += 1 else: cnt[mn] = 1 q = int(input()) for i in range(q): k = int(input()) if k in cnt: print(cnt[k]) else: print(0) ```
vfc_85202
{ "difficulty": "medium", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/SUBMIN", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n4 1 2 3 4\n4\n3\n4\n6\n1\n\n\n", "output": "2\n2\n0\n8\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n4 0 2 3 4\n4\n3\n4\n6\n1", "output": "2\n2\n0\n0\n", "type": "stdin...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/total-number-of-strings5726/1
Solve the following coding problem using the programming language python: Given 3 characters 'a', 'b', 'c'. Find the number of strings of length n that can be formed from these 3 characters. Given that : we can use ‘a’ as many times as we want, ‘b’ maximum once, and ‘c’ maximum twice. Example 1: Input: n = 2 Output:...
```python class Solution: def no_ofString(self, n): l = 10 ** 9 + 7 return (1 + n * 2 + n * (n * n - 1) // 2) % l ```
vfc_85206
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/total-number-of-strings5726/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "n = 2", "output": "8", "type": "stdin_stdout" }, { "fn_name": null, "input": "n = 3", "output": "19", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/pattern-jumping4855/1
Solve the following coding problem using the programming language python: A frog starts at the point 0. In his first turn, he can make a jump of 1 unit. Now for all consequent turns, if the frog is currently at a distance x (from the start), his jump will take him x units forward. Given a leaf at a distance N, you hav...
```python class Solution: def canJump(self, N): if N == 1: return True if N % 2 == 1: return False else: while N > 2: N = N / 2 if N % 2 == 1: return False break if N == 2: return True ```
vfc_85207
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/pattern-jumping4855/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 3", "output": "False", "type": "stdin_stdout" }, { "fn_name": null, "input": "N = 2", "output": "True", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: View Russian Translation Little pig Benny has just taken a shower. Now she is going to buy some gifts for her relatives. But the problem is that Benny doesn't know how to reach to the gift shop. Her friend Mike has created a special set of inst...
```python # Hacker Earth # Problem Statement # 'L' -- from (X, Y) moves to point (X, Y - 1) # 'R' -- from (X, Y) moves to point (X, Y + 1) # 'U' -- from (X, Y) moves to point (X - 1, Y) # 'D' -- from (X, Y) moves to point (X + 1, Y) # Import libraries import sys import pdb def findBennyFallCount(myCommand): # initia...
vfc_85209
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/longest-palindromic-substring-in-linear-time/1
Solve the following coding problem using the programming language python: Given a string, find the longest substring which is palindrome in Linear time O(N). Input: The first line of input contains an integer T denoting the no of test cases . Then T test cases follow. The only line of each test case contains a string....
```python def manacher_odd(s): n = len(s) s = '$' + s + '^' p = [0] * (n + 2) (l, r) = (1, 1) max_len = 0 pos = -1 for i in range(1, n + 1): p[i] = max(0, min(r - i, p[l + r - i])) while s[i - p[i]] == s[i + p[i]]: p[i] += 1 if p[i] > max_len: max_len = p[i] pos = i if i + p[i] > r: r = i + p...
vfc_85213
{ "difficulty": "medium_hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/longest-palindromic-substring-in-linear-time/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": "LongestPalindromeSubString", "input": "2\r\n\nbabcbabcbaccba\r\n\nforgeeksskeegfor", "output": "abcbabcba\r\ngeeksskeeg", "type": "function_call" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1626/B
Solve the following coding problem using the programming language python: You are given a decimal representation of an integer $x$ without leading zeros. You have to perform the following reduction on it exactly once: take two neighboring digits in $x$ and replace them with their sum without leading zeros (if the sum...
```python import sys, collections equal = {'19', '28', '29', '37', '38', '39', '46', '47', '48', '49', '55', '56', '57', '58', '59', '64', '65', '66', '67', '68', '69', '73', '74', '75', '76', '77', '78', '79', '82', '83', '84', '85', '86', '87', '88', '89', '91', '92', '93', '94', '95', '96', '97', '98', '99'} def so...
vfc_85214
{ "difficulty": "easy", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1626/B", "time_limit": "2 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n10057\n90\n", "output": "10012\n9\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/match-specific-pattern/1
Solve the following coding problem using the programming language python: Given a dictionary of words and a pattern. Every character in the pattern is uniquely mapped to a character in the dictionary. Find all such words in the dictionary that match the given pattern. Example 1: Input: N = 4 dict[] = {abb,abc,xyz,xyy...
```python def findSpecificPattern(Dict, pattern): ans = [] for i in Dict: dic = {} dic2 = {} if len(i) == len(pattern): flag = True for (j, k) in zip(i, pattern): if j not in dic and k not in dic2: dic[j] = k dic2[k] = j elif dic.get(j) != k or dic2.get(k) != j: flag = False if f...
vfc_85218
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/match-specific-pattern/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": "findSpecificPattern", "input": "N = 4\ndict[] = {abb,abc,xyz,xyy}\npattern = foo", "output": "abb xyy", "type": "function_call" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: One day Patrik met a magician.He asked magician for his magic pencil.So magician decided to give him magic pencil only if he correctely answers to his question. Magician gave him 3 numbers a, b and c and asked him to find the multiple of c whi...
```python T = int(input()) for i in range(T): inp = input().split(" ") a = int(inp[0]) b = int(inp[1]) c = int(inp[2]) p = a**b t = int((p)/c) r = p % c #print(t,r) if(r < c-r): print((int(p - r))) else: print((int(p+(c-r)))) ```
vfc_85223
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10\n540385427 0 7\n959 0 9\n861022531 0 10\n674 2 6\n635724059 0 3\n89021457 1 8\n653379374 1 3\n756899538 0 10\n1 -734575199 1\n1 973594325 1", "output": "193321855\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n892066602\n0\n0\n0\...
taco
verifiable_code
https://codeforces.com/problemset/problem/1173/D
Solve the following coding problem using the programming language python: Nauuo is a girl who loves drawing circles. One day she has drawn a circle and wanted to draw a tree on it. The tree is a connected undirected graph consisting of n nodes and n-1 edges. The nodes are numbered from 1 to n. Nauuo wants to draw a...
```python import sys n = int(sys.stdin.readline().strip()) D = [0] * n p = 998244353 for i in range(0, n - 1): (u, v) = list(map(int, sys.stdin.readline().strip().split())) D[u - 1] = D[u - 1] + 1 D[v - 1] = D[v - 1] + 1 ans = n for i in range(0, n): for j in range(0, D[i]): ans = ans * (j + 1) % p print(ans) ``...
vfc_85227
{ "difficulty": "hard", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1173/D", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "8\n4 5\n1 2\n6 3\n2 3\n2 8\n4 7\n2 4\n", "output": "2304\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "7\n2 7\n2 6\n4 7\n7 3\n7 5\n1 7\n", "output": "1680\n", "type": "stdin_...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/delete-middle-of-linked-list/1
Solve the following coding problem using the programming language python: Given a singly linked list, delete middle of the linked list. For example, if given linked list is 1->2->3->4->5 then linked list should be modified to 1->2->4->5. If there are even nodes, then there would be two middle nodes, we need to delete ...
```python def deleteMid(head): temp = head c = 0 while temp != None: c += 1 temp = temp.next mid = c // 2 - 1 i = 0 temp = head while i < mid: temp = temp.next i += 1 temp.next = temp.next.next return head ```
vfc_85231
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/delete-middle-of-linked-list/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "LinkedList:1->2->3->4->5", "output": "1 2 4 5", "type": "stdin_stdout" }, { "fn_name": null, "input": "LinkedList:2->4->6->7->5->1", "output": "2 4 6 5 1", "type": "stdin_stdout" } ...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/d4aeef538e6dd3280dda5f8ed7964727fdc7075f/1
Solve the following coding problem using the programming language python: You are given a sorted array a of length n. For each i(0<=i<=n-1), you have to make all the elements of the array from index 0 till i equal, using minimum number of operations. In one operation you either increase or decrease the array element b...
```python from typing import List class Solution: def optimalArray(self, n: int, a: List[int]) -> List[int]: res = [0 for _ in range(n)] ind = 1 for i in range(1, n): res[ind] = res[i - 1] + (a[i] - a[i // 2]) ind += 1 return res ```
vfc_85232
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/d4aeef538e6dd3280dda5f8ed7964727fdc7075f/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N=4\r\nA={1,6,9,12}", "output": "0 5 8 14", "type": "stdin_stdout" }, { "fn_name": null, "input": "N=7\r\nA={1,1,1,7,7,10,19}", "output": "0 0 0 6 12 21 33", "type": "stdin_stdout" } ...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/counting-number-of-sentences-and-words-in-text3226/1
Solve the following coding problem using the programming language python: Given a text, text. The task is to count the number of sentences and words in the text. Definition of a sentence :- Sentences are defined as contiguous space-separated strings of characters ending with a sentence punctuation (' . ', ' ! ' or '...
```python class Solution: def sentenceWord(self, text): sent = 1 word = 1 for i in range(len(text) - 1): if text[i] == ' ': word += 1 elif (text[i] == '?' or text[i] == '.' or text[i] == '!') and (text[i + 1] != '.' and text[i + 1] != '!' and (text[i + 1] != '?')): sent += 1 return (sent, word) ...
vfc_85233
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/counting-number-of-sentences-and-words-in-text3226/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "text = \"Sentences\"", "output": "1 1", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/37/B
Solve the following coding problem using the programming language python: Vasya’s elder brother Petya loves playing computer games. In one of his favourite computer games Petya reached the final level where a fight with the boss take place. While playing the game Petya found spell scrolls and now he is about to use t...
```python class Scroll: def __init__(self, id, power, damage): self.id = id self.power = power self.damage = damage self.active = False (num_scrolls, boss_max, regenerate) = map(int, input().split()) scrolls = [Scroll(i + 1, *map(int, input().split())) for i in range(num_scrolls)] scrolls.sort(key=lambda scro...
vfc_85234
{ "difficulty": "medium_hard", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/37/B", "time_limit": "1.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 328 249\n62 265\n32 271\n72 237\n28 99\n22 364\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 337 873\n62 81\n87 481\n39 1189\n45 450\n", "output": "NO\n", ...
taco
verifiable_code
https://www.codechef.com/PTRN2021/problems/ITGUY53
Solve the following coding problem using the programming language python: The chef is trying to decode some pattern problems, Chef wants your help to code it. Chef has one number K to form a new pattern. Help the chef to code this pattern problem. -----Input:----- - First-line will contain $T$, the number of test cas...
```python try: tc = int(input()) for _ in range(tc): n = int(input()) st = '' b = 1 for i in range(1, n + 1): b += 1 a = b for j in range(1, n + 1): print(a, end='') a += 1 print() except: pass ```
vfc_85238
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/PTRN2021/problems/ITGUY53", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n1\n2\n3\n4\n", "output": "2\n23\n34\n234\n345\n456\n2345\n3456\n4567\n5678\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: King Tle4Ever of Time Limit Exceeded is really fascinated about Tic Tac Toe. He organizes a national level contest for Tic Tac Toe every year in Time Limit Exceeded. (Though I agree you need to be really stupid to loose a game of Tic Tac Toe but...
```python #------------------------------------------------------------------------------- # Name: module1 # Purpose: # # Author: onkar shandilya # # Created: 08/11/2014 # Copyright: (c) onkar shandilya 2014 # Licence: <your licence> #---------------------------------------------------------------...
vfc_85242
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "100000\n798431\n176679\n406647\n580063\n91899\n430099\n359213\n373119\n255589\n412791\n816149\n160027\n633825\n73171\n958973\n745377\n133631\n639245\n367759\n165519\n947659\n821355\n722669\n464861\n619667\n241589\n754641\n652405\n6...
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 t = int(eval(input())) while(t>0): a = input() b = input() c = 0 for i in range(0,len(a)+1): k=a k = k[:i] + b + k[i:] if(k==k[::-1]): c+=1 else: continue print(c) t-=1 ```
vfc_85250
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "8\nabaa\naaaa\nypdtgyqrjdrjgkrmperucmenpqflppyukmiegqngqmrvatagqi\npmjeupqbxhovqaebuqziueetbxshglimlgqbnmcipdpvcrumdz\neylofwlnrxaoapsuajptrmcgsfkoynrpnfvuvvqimxjrnwdhdo\nqvladmcysshrsmfxgqiglqgxzafbnffcupcupnkngmdzdqywpf\nab\nbda\...
taco
verifiable_code
https://codeforces.com/problemset/problem/770/C
Solve the following coding problem using the programming language python: Now you can take online courses in the Berland State University! Polycarp needs to pass k main online courses of his specialty to get a diploma. In total n courses are availiable for the passage. The situation is complicated by the dependence o...
```python (n, k) = list(map(lambda x: int(x), input().split())) m = list(map(lambda x: int(x), input().split())) from types import GeneratorType def bootstrap(f, stack=[]): def wrappedfunc(*args, **kwargs): if stack: return f(*args, **kwargs) else: to = f(*args, **kwargs) while True: if type(to) is ...
vfc_85254
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/770/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6 2\n5 3\n0\n0\n0\n2 2 1\n1 4\n1 5\n", "output": "5\n1 2 3 4 5 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "9 3\n3 9 5\n0\n0\n3 9 4 5\n0\n0\n1 8\n1 6\n1 2\n2 1 2\n", "output": "6...
taco
verifiable_code
https://codeforces.com/problemset/problem/1788/B
Solve the following coding problem using the programming language python: The sum of digits of a non-negative integer $a$ is the result of summing up its digits together when written in the decimal system. For example, the sum of digits of $123$ is $6$ and the sum of digits of $10$ is $1$. In a formal way, the sum of ...
```python import sys, math, cmath, time from bisect import bisect_left start_time = time.time() def sod(n): n = str(n) s = 0 for i in n: s = s + int(i) return s def solve(t): n = inp() s = '' s1 = '' c = 1 while n > 0: d = n % 10 if d % 2 == 0: s = str(d // 2) + s s1 = str(d // 2) + s1 elif c =...
vfc_85259
{ "difficulty": "easy", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1788/B", "time_limit": "1 second" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n1\n161\n67\n1206\n19\n", "output": "0 1\n130 31\n33 34\n103 1103\n14 5\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/UASEQ
Solve the following coding problem using the programming language python: Read problems statements in Mandarin Chinese and Russian. You are given an array that consists of n integer numbers. You have to change at most K elements of this array, so that the resulting array will be a arithmetic progression. From all th...
```python from collections import defaultdict def eval(A, dictR, r): l = dictR[r] nbToChange = 0 newVal = A[l[-1]] for iR in range(l[-1], len(A) - 1): newVal += r if newVal != A[iR + 1]: nbToChange += 1 lastVal = newVal newVal = A[l[0]] for iR in range(l[0], 0, -1): newVal -= r if newVal != A[iR - 1]...
vfc_85263
{ "difficulty": "medium_hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/UASEQ", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 2\n1 2 1 4", "output": "-5 -2 1 4 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 2\n1 0 1 4", "output": "-5 -2 1 4\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/COFDEC20/problems/COFDQ2
Solve the following coding problem using the programming language python: You will be given a two-dimensional array with row consisting values 0 or 1. A move consists of choosing any column or row, and toggling all the 0’s as 1’s and 1’s as 0’s. After making the required moves, every row represents a binary number...
```python def matrixScore(A): (m, n) = (len(A), len(A[0])) for i in range(m): if A[i][0] == 1: continue for j in range(n): A[i][j] = 1 - A[i][j] res = 0 for rows in zip(*A): cnt1 = max(rows.count(1), rows.count(0)) res += cnt1 * 2 ** (n - 1) n -= 1 return res (m, n) = [int(s) for s in input().split...
vfc_85268
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/COFDEC20/problems/COFDQ2", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 4\n0 0 1 1\n1 0 1 0\n1 1 0 0\n", "output": "39\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/find-missing-and-repeating2512/1
Solve the following coding problem using the programming language python: Given an unsorted array Arr of size N of positive integers. One number 'A' from set {1, 2,....,N} is missing and one number 'B' occurs twice in array. Find these two numbers. Example 1: Input: N = 2 Arr[] = {2, 2} Output: 2 1 Explanation: Repeat...
```python class Solution: def findTwoElement(self, arr, n): unordered_map = {} rep = 0 miss = 0 for i in arr: if i not in unordered_map: unordered_map[i] = 1 else: rep = i for i in range(1, n + 1): if i not in unordered_map: miss = i return [rep, miss] ```
vfc_85273
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/find-missing-and-repeating2512/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 2\r\nArr[] = {2, 2}", "output": "2 1", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1765/N
Solve the following coding problem using the programming language python: You are given a positive integer $x$. You can apply the following operation to the number: remove one occurrence of any digit in such a way that the resulting number does not contain any leading zeroes and is still a positive integer. For examp...
```python from dataclasses import dataclass from time import time import math @dataclass class MyInput: t: int test_cases: list def get_input(): t = int(input()) test_cases = [] for _ in range(t): x = input() k = input() test_cases.append((x, k)) return MyInput(t=t, test_cases=test_cases) def get_sample_...
vfc_85274
{ "difficulty": "medium", "memory_limit": "512 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1765/N", "time_limit": "2 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n10000\n4\n1337\n0\n987654321\n6\n66837494128\n5\n7808652\n3\n", "output": "1\n1337\n321\n344128\n7052\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/3-divisors3942/1
Solve the following coding problem using the programming language python: You are given a list of q queries and for every query, you are given an integer N. The task is to find how many numbers(less than or equal to N) have number of divisors exactly equal to 3. Example 1: Input: q = 1 query[0] = 6 Output: 1 Explanat...
```python import math import bisect class Solution: def threeDivisors(self, query, q): maxn = max(query) ans = [] d = {} primes = [1] * int(math.sqrt(maxn) + 2) for i in range(2, len(primes)): if primes[i] == 1: j = 2 while j * i < len(primes): primes[j * i] = 0 j += 1 for _ in range...
vfc_85282
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/3-divisors3942/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "q = 1\r\nquery[0] = 6", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "q = 2\r\nquery[0] = 6\r\nquery[1] = 10", "output": "1\r\n2", "type": "stdin_stdout" } ]...
taco
verifiable_code
https://www.codechef.com/problems/BOWLERS
Solve the following coding problem using the programming language python: In a cricket game, an over is a set of six valid deliveries of balls performed by one player ― the bowler for this over. Consider a cricket game with a series of $N$ overs (numbered $1$ through $N$) played by $K$ players (numbered $1$ through $K...
```python t = int(input()) for i in range(t): (n, k, l) = map(int, input().split()) if k * l < n: print(-1) elif k == 1 and n > 1: print(-1) else: i = 0 for t in range(n): if i == k: i = 1 else: i = i + 1 print(i, end=' ') print('') ```
vfc_85283
{ "difficulty": "easy", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/BOWLERS", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n4 3 2\n5 4 1\n", "output": "1 2 3 2\n-1\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/338/A
Solve the following coding problem using the programming language python: Manao is taking part in a quiz. The quiz consists of n consecutive questions. A correct answer gives one point to the player. The game also has a counter of consecutive correct answers. When the player answers a question correctly, the number on...
```python def chk(x): d = (m - x) // (k - 1) * k if (m - x) % (k - 1): d += 1 + (m - x) % (k - 1) if d <= n - x: return True else: return False def calc(e): if e == 1: return 2 if e & 1: d = 2 else: d = 1 f = calc(e >> 1) d = d * f % D * f % D return d (n, m, k) = map(int, input().split()) D = 10...
vfc_85287
{ "difficulty": "medium_hard", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/338/A", "time_limit": "1.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "250000000 250000000 2\n", "output": " 1000000007", "type": "stdin_stdout" }, { "fn_name": null, "input": "1000000000 999998304 7355\n", "out...
taco
verifiable_code
https://codeforces.com/problemset/problem/1090/D
Solve the following coding problem using the programming language python: Vasya had an array of $n$ integers, each element of the array was from $1$ to $n$. He chose $m$ pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results...
```python (n, m) = map(int, input().split()) c = [[0, i, []] for i in range(n)] for i in range(m): (a, b) = map(int, input().split()) c[a - 1][0] += 1 c[a - 1][2].append(b - 1) c[b - 1][0] += 1 c[b - 1][2].append(a - 1) if n == 1: print('NO') else: ans = n * (n - 1) // 2 if m >= ans: print('NO') else: c.so...
vfc_85295
{ "difficulty": "medium_hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1090/D", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 0\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 1\n1 2\n", "output": "YES\n1 3 2 \n1 3 1 \n", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: C: Skewering problem One day, when Homura was playing with blocks, Tempura came. Homura decided to play with blocks with Tempura. There is a rectangular parallelepiped of A \ times B \ times C, which is made by stacking A \ times B \ times C ...
```python (A, B, C) = map(int, input().split()) ANS = 0 for i in [A, B, C]: if i % 2 == 1: ANS += 1 if ANS >= 2: print('Hom') else: print('Tem') ```
vfc_85299
{ "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": "2 1 10", "output": "Tem\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 1 1", "output": "Hom\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 ...
taco
verifiable_code
Solve the following coding problem using the programming language python: You are situated in an N dimensional grid at position (x1,x2,...,xN). The dimensions of the grid are (D1,D2,...DN). In one step, you can walk one step ahead or behind in any one of the N dimensions. (So there are always 2×N possible different mo...
```python def ways(di, offset, steps): global mem, dimensions if steps in mem[di] and offset in mem[di][steps]: return mem[di][steps][offset] val = 0 if steps == 0: val = 1 else: if offset - 1 >= 1: val += ways(di, offset - 1, steps - 1) if offset + 1 <= dimensions[di]: val += ways(di, offset + 1, st...
vfc_85303
{ "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\n1 287\n44\n78\n1 236\n25\n87\n1 122\n41\n63\n1 260\n7\n64\n1 127\n3\n73", "output": "38753340\n587915072\n644474045\n423479916\n320130104", "type": "stdin_stdout" }, { "fn_name": null, "input": "5...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/collection-of-pens1843/1
Solve the following coding problem using the programming language python: There are three piles of pens. A pens in the first pile and B pens in the second Pile.Find the minimum number of pens that should be there in the third pile so that sum of all three piles produces either a prime number or unity. Note: there sho...
```python class Solution: def isPrime(self, n): prime = 0 if n == 1: return 0 for i in range(2, int(n ** 0.5) + 1): if n % i == 0: prime = 1 break if prime: return 0 else: return 1 def minThirdPiles(self, A, B): i = 1 flag = True while flag: p = A + B + i if self.isPrime(p)...
vfc_85308
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/collection-of-pens1843/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "A = 1, B = 3", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "A = 4, B = 3", "output": "4", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1242/A
Solve the following coding problem using the programming language python: Ujan has been lazy lately, but now has decided to bring his yard to good shape. First, he decided to paint the path from his house to the gate. The path consists of $n$ consecutive tiles, numbered from $1$ to $n$. Ujan will paint each tile in s...
```python import sys input = sys.stdin.readline x = int(input()) if x == 1: print(1) sys.exit() import math L = int(math.sqrt(x)) FACT = dict() for i in range(2, L + 2): while x % i == 0: FACT[i] = FACT.get(i, 0) + 1 x = x // i if x != 1: FACT[x] = FACT.get(x, 0) + 1 if len(FACT) > 1: print(1) else: print(lis...
vfc_85309
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1242/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n", "output": "5\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/ERROR
Solve the following coding problem using the programming language python: Lots of geeky customers visit our chef's restaurant everyday. So, when asked to fill the feedback form, these customers represent the feedback using a binary string (i.e a string that contains only characters '0' and '1'. Now since chef is not...
```python T = int(input()) for i in range(0, T): S = input() if '101' in S or '010' in S: print('Good') else: print('Bad') ```
vfc_85313
{ "difficulty": "easy", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/ERROR", "time_limit": "0.5 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n11111110\n10101010101010\n", "output": "Bad\nGood\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n11101110\n10101010101010", "output": "Good\nGood\n", "type": "stdin_stdo...
taco
verifiable_code
Solve the following coding problem using the programming language python: At the end of last year, Santa Claus forgot to give Christmas presents to the children in JOI village. Therefore, I decided to deliver the chocolate cake to the children as an apology. The day to deliver is approaching tomorrow, so it's time to ...
```python from bisect import bisect_left as bl INF = 10 ** 20 def main(): (w, h) = map(int, input().split()) n = int(input()) xlst = [] ylst = [] appx = xlst.append appy = ylst.append for i in range(n): (x, y) = map(int, input().split()) appx(x) appy(y) sorted_xlst = sorted(xlst) sorted_ylst = sorted(yl...
vfc_85317
{ "difficulty": "unknown_difficulty", "memory_limit": "134.217728 megabytes", "memory_limit_bytes": null, "problem_url": null, "time_limit": "8.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 4\n3\n1 1\n3 4\n5 6", "output": "13\n3 4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 4\n3\n1 1\n1 4\n5 6", "output": "12\n1 4\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/SEBIHWY
Solve the following coding problem using the programming language python: Sebi goes to school daily with his father. They cross a big highway in the car to reach to the school. Sebi sits in front seat beside his father at driving seat. To kill boredom, they play a game of guessing speed of other cars on the highway. S...
```python t = int(input()) for _ in range(t): (s, sg, fg, d, t) = map(int, input().split(' ')) car_speed = s + d * 50 * 3.6 / t sebi = abs(car_speed - sg) fat = abs(car_speed - fg) if sebi < fat: print('SEBI') elif fat == sebi: print('DRAW') else: print('FATHER') ```
vfc_85321
{ "difficulty": "medium_hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/SEBIHWY", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n100 180 200 20 60\n130 131 132 1 72\n\n\n", "output": "SEBI\nFATHER\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/FCBARCA
Solve the following coding problem using the programming language python: As we all know, F.C. Barcelona is the best soccer team of our era! Their entangling and mesmerizing game style usually translates into very high ball possession, consecutive counter-attack plays and goals. Lots of goals, thanks to the natural ta...
```python t = int(input()) for i in range(t): (n, k) = map(int, input().split(' ')) sum = 0 z = 0 while n > 1: sum += k ** (n - 1) * (-1) ** z n -= 1 z += 1 print(sum % 1000000007) ```
vfc_85329
{ "difficulty": "medium_hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/FCBARCA", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n2 4\n4 2\n", "output": "4\n6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n3 4\n4 2", "output": "12\n6\n", "type": "stdin_stdout" }, { "fn_name": null, ...
taco
verifiable_code
https://codeforces.com/problemset/problem/653/A
Solve the following coding problem using the programming language python: Limak is a little polar bear. He has n balls, the i-th ball has size t_{i}. Limak wants to give one ball to each of his three friends. Giving gifts isn't easy — there are two rules Limak must obey to make friends happy: No two friends can get ...
```python n = int(input()) balls = list(map(int, input().split())) balls.sort() def answer(balls): a = 0 b = 1 while b < len(balls) - 1: while balls[b] == balls[a] and b < len(balls) - 2: b += 1 if balls[b] == balls[a] + 1: c = b + 1 while balls[c] == balls[b] and c < len(balls) - 1: c += 1 if b...
vfc_85333
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/653/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n18 55 16 17\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n40 41 43 44 44 44\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name"...
taco
verifiable_code
https://codeforces.com/problemset/problem/1713/A
Solve the following coding problem using the programming language python: You are living on an infinite plane with the Cartesian coordinate system on it. In one move you can go to any of the four adjacent points (left, right, up, down). More formally, if you are standing at the point $(x, y)$, you can: go left, and ...
```python import sys input = sys.stdin.readline t = int(input()) for _ in range(t): n = int(input()) Sum = 0 (A1, A2, A3, A4) = ([], [], [], []) for _ in range(n): (a, b) = map(int, input().split()) if a > 0: A1.append(a) elif a < 0: A2.append(-a) elif b > 0: A3.append(b) elif b < 0: A4.append...
vfc_85337
{ "difficulty": "easy", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1713/A", "time_limit": "1 second" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n4\n0 -2\n1 0\n-1 0\n0 2\n3\n0 2\n-3 0\n0 -1\n1\n0 0\n", "output": "12\n12\n0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n3\n-2 0\n0 -5\n0 -1\n3\n3 0\n-2 0\n0 1\n", "output"...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/scrambled-string/1
Solve the following coding problem using the programming language python: Given two strings S1 and S2 of equal length, the task is to determine if S2 is a scrambled form of S1. Scrambled string: Given string str, we can represent it as a binary tree by partitioning it into two non-empty substrings recursively. Below i...
```python from collections import Counter from functools import lru_cache class Solution: @lru_cache(None) def isScramble(self, s1: str, s2: str): if Counter(s1) != Counter(s2): return False if len(s1) == 1: return True for i in range(1, len(s1)): if self.isScramble(s1[:i], s2[:i]) and self.isScrambl...
vfc_85348
{ "difficulty": "medium_hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/scrambled-string/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "S1=\"coder\", S2=\"ocder\"", "output": "Yes", "type": "stdin_stdout" }, { "fn_name": null, "input": "S1=\"abcde\", S2=\"caebd\"", "output": "No", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/85781966a9db2a1ac17eaaed26a947eba5740d56/1
Solve the following coding problem using the programming language python: For a given 2D Matrix before, the corresponding cell (x, y) of the after matrix is calculated as follows: res = 0; for(i = 0; i <= x; i++){ for( j = 0; j <= y; j++){ res += before(i,j); } } after(x,y) = res; Give...
```python class Solution: def computeBeforeMatrix(self, N, M, after): ans = [[0 for _ in range(M)] for _ in range(N)] ans[0][0] = after[0][0] for i in range(1, M): ans[0][i] = after[0][i] - after[0][i - 1] for i in range(1, N): ans[i][0] = after[i][0] - after[i - 1][0] for i in range(1, N): for j i...
vfc_85349
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/85781966a9db2a1ac17eaaed26a947eba5740d56/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 2, M = 3\r\nafter[][] = {{1, 3, 6},\r\n {3, 7, 11}}", "output": "1 2 3\r\n2 2 1", "type": "stdin_stdout" }, { "fn_name": null, "input": "N = 1, M = 3\r\nafter[][] = {{1, 3, 5}}", ...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/asteroid-collision/1
Solve the following coding problem using the programming language python: We are given an integer array asteroids of size N representing asteroids in a row. For each asteroid, the absolute value represents its size, and the sign represents its direction (positive meaning right, negative meaning left). Each asteroid mo...
```python class Solution: def asteroidCollision(self, N, asteroids): st = [] for i in range(len(asteroids)): while st and asteroids[i] < 0 and (st[-1] > 0): if abs(asteroids[i]) > abs(st[-1]): st.pop() continue elif abs(asteroids[i]) == abs(st[-1]): st.pop() break else: st.app...
vfc_85350
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/asteroid-collision/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 3\r\n\r\nasteroids[ ] = {3, 5, -3}", "output": "{3, 5}", "type": "stdin_stdout" }, { "fn_name": null, "input": "N = 2\r\n\r\nasteroids[ ] = {10, -10}", "output": "{ }", "type": "stdin...
taco
verifiable_code
https://www.codechef.com/problems/SHUTTLE
Solve the following coding problem using the programming language python: Chef has decided to arrange the free shuttle service for his employees. City of Bhiwani has a strange layout - all of its N shuttle boarding points are arranged in a circle, numbered from 1 to N in clockwise direction. Chef's restaurant is at bo...
```python vec = [] def precal(): ne = 5000 is_prime = [True] * (ne + 1) is_prime[0] = is_prime[1] = False p = 2 while p * p <= ne: if is_prime[p]: for i in range(p * p, ne + 1, p): is_prime[i] = False p += 1 for i in range(2, ne + 1): if is_prime[i]: vec.append(i) precal() for i in range(int(inpu...
vfc_85351
{ "difficulty": "medium", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/SHUTTLE", "time_limit": "0.35122 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n2\n3\n4", "output": "1\n2\n2", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n2\n3\n1", "output": "1\n2\n1\n", "type": "stdin_stdout" }, { "fn_name": null, ...
taco
verifiable_code
Solve the following coding problem using the programming language python: Utkarsh being a very talkative child, was scolded by his teacher multiple times. One day, the teacher became very angry and decided to give him a very rigorous punishment. He made him stand on the school field which is X axis. Utkarsh initiall...
```python ''' # Read input from stdin and provide input before running code name = raw_input('What is your name?\n') print 'Hi, %s.' % name ''' N, P = list(map(int, input().split())) Prob = [] Prob.append(0) Prob.append(0) Prob.append(P/100) Prob.append(1 - Prob[2]) for i in range(4,N+1): Prob.append(Prob[i-2]*Prob...
vfc_85355
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "29210 37", "output": "1.000000", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/733/C
Solve the following coding problem using the programming language python: There was an epidemic in Monstropolis and all monsters became sick. To recover, all monsters lined up in queue for an appointment to the only doctor in the city. Soon, monsters became hungry and began to eat each other. One monster can eat ot...
```python na = int(input()) a = list(map(int, input().split())) nb = int(input()) b = list(map(int, input().split())) def judge(na, a, nb, b): ans = [] if sum(a) != sum(b): return (False, None) cur = 0 ind = -1 j = 0 for (i, x) in enumerate(a): cur += x if cur < b[j]: pass elif cur == b[j]: begin =...
vfc_85359
{ "difficulty": "medium_hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/733/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n1 2 2 2 1 2\n2\n5 5\n", "output": "YES\n2 L\n1 R\n4 L\n3 L\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n1 2 3 4 5\n1\n15\n", "output": "YES\n5 L\n4 L\n3 L\n2 L\n", "ty...
taco
verifiable_code
https://www.codechef.com/BRBG2020/problems/FTNUM
Solve the following coding problem using the programming language python: A prime number is number x which has only divisors as 1 and x itself. Harsh is playing a game with his friends, where his friends give him a few numbers claiming that they are divisors of some number x but divisor 1 and the number x itself are n...
```python import math def findnumber(l, n): l.sort() x = l[0] * l[-1] vec = [] i = 2 while i * i <= x: if x % i == 0: vec.append(i) if x // i != i: vec.append(x // i) i = i + 1 vec.sort() if len(vec) != n: return -1 else: j = 0 for it in range(n): if l[j] != vec[it]: return -1 els...
vfc_85363
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/BRBG2020/problems/FTNUM", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n2\n2 3\n2\n4 2\n3\n12 3 2\n", "output": "6\n8\n-1\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1555/D
Solve the following coding problem using the programming language python: Let's call the string beautiful if it does not contain a substring of length at least $2$, which is a palindrome. Recall that a palindrome is a string that reads the same way from the first character to the last and from the last character to th...
```python from itertools import permutations as perm import io import os input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline (n, m) = map(int, input().split()) s = input().decode('utf-8')[:n] pre = [[int(s[i] != pat[i % 3]) for i in range(n)] for pat in perm('abc')] for psum in pre: for i in range(1, n): ps...
vfc_85367
{ "difficulty": "medium_hard", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1555/D", "time_limit": "2 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 4\nbaacb\n1 3\n1 5\n4 5\n2 3\n", "output": "1\n2\n0\n1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1\na\n1 1\n", "output": "0\n", "type": "stdin_stdout" }, { ...
taco
verifiable_code
https://codeforces.com/problemset/problem/978/G
Solve the following coding problem using the programming language python: Petya studies at university. The current academic year finishes with $n$ special days. Petya needs to pass $m$ exams in those special days. The special days in this problem are numbered from $1$ to $n$. There are three values about each exam: ...
```python def sol(): (n, m) = list(map(int, input().split())) arr = [] for d in range(m): preArr = list(map(int, input().split())) preArr[0] -= 1 preArr[1] -= 1 arr.append(preArr) out = [m] * n for i in range(n): ind = 999999999999999 exm = False exmDate = 9999999999999 for g in range(m): if arr...
vfc_85376
{ "difficulty": "medium_hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/978/G", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 2\n1 3 1\n1 5 1\n", "output": "1 2 3 0 3 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 2\n1 3 1\n1 2 1\n", "output": "-1\n", "type": "stdin_stdout" }, { "f...
taco
verifiable_code
https://codeforces.com/problemset/problem/1791/G2
Solve the following coding problem using the programming language python: The only difference between the easy and hard versions are the locations you can teleport to. Consider the points $0,1,\dots,n+1$ on the number line. There is a teleporter located on each of the points $1,2,\dots,n$. At point $i$, you can do th...
```python import bisect def f(arr, c): n = len(arr) total = 0 start = [] for i in range(n): start.append(arr[i] + (i + 1)) arr[i] += min(i + 1, n - i) sorted_arr = sorted(arr) pref = [sorted_arr[0]] for i in range(1, n): pref.append(pref[-1] + sorted_arr[i]) for i in range(n): if c - start[i] >= 0: ...
vfc_85381
{ "difficulty": "hard", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1791/G2", "time_limit": "1 second" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10\n5 6\n1 1 1 1 1\n8 32\n100 52 13 6 9 4 100 35\n1 1\n5\n4 5\n4 3 2 1\n5 9\n2 3 1 4 1\n5 8\n2 3 1 4 1\n4 3\n2 3 4 1\n4 9\n5 4 3 3\n2 14\n7 5\n5 600000000\n500000000 400000000 300000000 200000000 100000000\n", "output": "2\n3...
taco
verifiable_code
Solve the following coding problem using the programming language python: Bawris, are wells or ponds in which the water may be reached by descending a set of steps. They may be covered and protected and are often of architectural significance. Rajasthan has a history of maintaining bawris, but now they are of archit...
```python for tc in range(eval(input())): px,py,bx,by=list(map(int,input().split())) if (px>=bx and py>=by) or (px>=by and py>=bx): print('Possible') else: print('Not Possible') ```
vfc_85385
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10000\n861 233 311 908\n603 699 539 329\n833 830 515 7\n198 271 837 532\n990 45 55 818\n527 569 32 580\n120 338 552 377\n391 537 590 315\n555 463 768 915\n793 941 642 787\n941 37 406 410\n641 884 834 936\n593 68 931 618\n648 167 99...
taco
verifiable_code
https://www.codechef.com/QTCC2020/problems/VIEW2004
Solve the following coding problem using the programming language python: -----General Statement:----- Read a number in scientific notation and output its equivalent decimal value. -----Input:----- All data is on a single line. The first integer indicates how many pairs of numbers follow. The first of each pair is A,...
```python import math x = input().split() n = int(x[0]) arr = [] i = 1 while i < len(x): arr.append(float(x[i])) i += 1 arr.append(int(x[i])) i += 1 i = 0 ans = [] while i < len(arr): x = arr[i] i += 1 y = arr[i] y = 10 ** y i += 1 ans.append(x * y) for i in range(len(ans)): print('{:.2f}'.format(ans[i])) `...
vfc_85397
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/QTCC2020/problems/VIEW2004", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 4.296 3 3.8 -2 1.8 2 2.8678 1\n", "output": "4296.00\n0.04\n180.00\n28.68\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: Min Element Given the sequence a_1, a_2, .., a_N. Find the minimum number in this sequence. If the minimum value is in more than one place, answer the one with the lowest number. input N a_1 a_2 ... a_N output Output the smallest i such...
```python N = int(input()) a = [int(x) for x in input().split()] print(a.index(min(a)) + 1) ```
vfc_85401
{ "difficulty": "unknown_difficulty", "memory_limit": "1073.741824 megabytes", "memory_limit_bytes": null, "problem_url": null, "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n8 6 9 0 2 1", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n8 6 9 1 2 0", "output": "6\n", "type": "stdin_stdout" }, { "fn_name": null, ...
taco
verifiable_code
https://codeforces.com/problemset/problem/1181/A
Solve the following coding problem using the programming language python: Soon after the Chunga-Changa island was discovered, it started to acquire some forms of civilization and even market economy. A new currency arose, colloquially called "chizhik". One has to pay in chizhiks to buy a coconut now. Sasha and Masha ...
```python (a, b, c) = map(int, input().split()) r1 = a % c r2 = b % c if r1 + r2 < c: print((a + b) // c, 0) else: print((a + b) // c, c - max(r1, r2)) ```
vfc_85405
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1181/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 4 3\n", "output": "3 1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 8 2\n", "output": "7 0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": ...
taco
verifiable_code
https://www.codechef.com/SPRT2020/problems/STCKSCAM
Solve the following coding problem using the programming language python: $Harshad$ $Mehta$ is planning a new scam with the stocks he is given a stock of integer price S and a number K . $harshad$ has got the power to change the number $S$ at most $K$ times In order to raise the price of stock and now cash it for hi...
```python (a, b) = [int(_) for _ in input().split()] if b == 0: print(a) else: l = [] a = str(a) for i in range(len(a)): l.append(a[i]) for i in range(len(l)): if b == 0: break if l[i] == '9': continue else: l[i] = '9' b -= 1 s = '' for i in l: s += i print(s) ```
vfc_85409
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/SPRT2020/problems/STCKSCAM", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4483 2\n", "output": "9983\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/number-of-pairs3422/1
Solve the following coding problem using the programming language python: Given two arrays X[] and Y[] of size M and N respectively. Find number of pairs such that x^{y} > y^{x} where x is an element from X[] and y is an element from Y[]. Example 1: Input: M = 3, N = 2 X[] = {2, 1, 6}, Y = {1, 5} Output: 3 Explanation...
```python class Solution: def countPairs(self, X, Y, m, n): for i in range(m): X[i] **= 1 / X[i] for i in range(n): Y[i] **= 1 / Y[i] X.sort() Y.sort() i = j = 0 ans = 0 while i < m: if j == n: ans += n else: while j < n and X[i] > Y[j]: j += 1 ans += j i += 1 return an...
vfc_85414
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/number-of-pairs3422/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "M = 3, N = 2\nX[] = {2, 1, 6}, Y = {1, 5}", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "M = 3, N = 3\nX[] = {10, 19, 18}, Y[] = {11, 15, 9}", "output": "2", "typ...
taco
verifiable_code
https://codeforces.com/problemset/problem/1351/B
Solve the following coding problem using the programming language python: Vasya claims that he had a paper square. He cut it into two rectangular parts using one vertical or horizontal cut. Then Vasya informed you the dimensions of these two rectangular parts. You need to check whether Vasya originally had a square. I...
```python t = int(input()) for i in range(t): sides1 = list(map(int, input().split())) sides2 = list(map(int, input().split())) sides1.sort() sides2.sort() if sides1[-1] == sides2[-1] and sides2[0] + sides1[0] == sides2[-1]: print('Yes') else: print('No') ```
vfc_85415
{ "difficulty": "easy", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1351/B", "time_limit": "1 second" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n2 3\n3 1\n3 2\n1 3\n3 3\n1 3\n", "output": "Yes\nYes\nNo\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n64 9\n41 36\n", "output": "No\n", "type": "stdin_stdout" }, ...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/count-pairs-in-an-array4145/1
Solve the following coding problem using the programming language python: Given an array of integers arr[0..n-1], count all pairs (arr[i], arr[j]) in it such that i*arr[i] > j*arr[j], and 0 ≤ i < j < n. Example 1: Input : arr[] = {5, 0, 10, 2, 4, 1, 6} Output : 5 Explanation : Pairs which hold condition i*arr[i] > j...
```python def merge(arr, temp, left, mid, right): inv_count = 0 i = left j = mid k = left while i <= mid - 1 and j <= right: if arr[i] <= arr[j]: temp[k] = arr[i] i += 1 k += 1 else: temp[k] = arr[j] k += 1 j += 1 inv_count = inv_count + (mid - i) while i <= mid - 1: temp[k] = arr[i] ...
vfc_85432
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/count-pairs-in-an-array4145/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "arr[] = {5, 0, 10, 2, 4, 1, 6}", "output": "5", "type": "stdin_stdout" }, { "fn_name": null, "input": "arr[] = {8, 4, 2, 1}", "output": "2", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1225/D
Solve the following coding problem using the programming language python: You are given $n$ positive integers $a_1, \ldots, a_n$, and an integer $k \geq 2$. Count the number of pairs $i, j$ such that $1 \leq i < j \leq n$, and there exists an integer $x$ such that $a_i \cdot a_j = x^k$. -----Input----- The first li...
```python from collections import defaultdict (n, k) = map(int, input().split()) a = list(map(int, input().split())) n = int(max(a) ** 0.5) mark = [True] * (n + 1) prime = [] for i in range(2, n + 1): if mark[i]: for j in range(i, n + 1, i): mark[j] = False prime.append(i) d = defaultdict(int) (ans, count) = (0...
vfc_85433
{ "difficulty": "medium_hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1225/D", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6 3\n1 3 9 8 24 1\n", "output": "5\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 2\n40 90\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, ...
taco
verifiable_code
https://codeforces.com/problemset/problem/1140/D
Solve the following coding problem using the programming language python: You are given a regular polygon with $n$ vertices labeled from $1$ to $n$ in counter-clockwise order. The triangulation of a given polygon is a set of triangles such that each vertex of each triangle is a vertex of the initial polygon, there is ...
```python n = int(input()) first = 2 * (n - 2) second = 3 * ((n - 2) * (n - 1) // 2) third = (n - 2) * (n - 1) * (2 * n - 3) // 6 print(first + second + third) ```
vfc_85437
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1140/D", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n", "output": "6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n", "output": "18\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1566/C
Solve the following coding problem using the programming language python: A binary string is a string that consists of characters $0$ and $1$. A bi-table is a table that has exactly two rows of equal length, each being a binary string. Let $\operatorname{MEX}$ of a bi-table be the smallest digit among $0$, $1$, or $2...
```python import sys import math import heapq from collections import defaultdict as dd from collections import OrderedDict as od from collections import deque from itertools import permutations as pp from itertools import combinations as cc from sys import stdin from functools import cmp_to_key as ctk from functools i...
vfc_85441
{ "difficulty": "easy", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1566/C", "time_limit": "1 second" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n7\n0101000\n1101100\n5\n01100\n10101\n2\n01\n01\n6\n000000\n111111\n", "output": "8\n8\n2\n12\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n7\n0101000\n1101100\n5\n01100\n10101\n2\...
taco
verifiable_code
https://codeforces.com/problemset/problem/1585/B
Solve the following coding problem using the programming language python: You are given an array $a$ of length $n$. Let's define the eversion operation. Let $x = a_n$. Then array $a$ is partitioned into two parts: left and right. The left part contains the elements of $a$ that are not greater than $x$ ($\le x$). The ...
```python import sys def _hy_anon_var_2(*_hyx_GXUffffX2): def solution(arr): max_elt = 0 steps = -1 for x in reversed(arr): if x > max_elt: steps += 1 max_elt = x _hy_anon_var_1 = None else: _hy_anon_var_1 = None return steps t = int(input()) for _ in range(t): n = int(input()) ar...
vfc_85445
{ "difficulty": "easy", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1585/B", "time_limit": "1 second" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n5\n2 4 1 5 3\n5\n5 3 2 4 1\n4\n1 1 1 1\n", "output": "1\n2\n0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1\n998244353\n4\n1 1 2 3\n", "output": "0\n0\n", "type": "st...
taco
verifiable_code
https://www.codechef.com/problems/FCTRL2
Solve the following coding problem using the programming language python: A tutorial for this problem is now available on our blog. Click here to read it. You are asked to calculate factorials of some small positive integers. ------ Input ------ An integer t, 1≤t≤100, denoting the number of testcases, followed b...
```python def factorial(n): if n == 0: return 1 elif n == 1: return 1 else: return n * factorial(n - 1) n = int(input()) for i in range(n): num = int(input()) print(factorial(num)) ```
vfc_85453
{ "difficulty": "easy", "memory_limit": "2000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/FCTRL2", "time_limit": "0.235294 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n1\n2\n5\n3", "output": "1\n2\n120\n6", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n2\n2\n5\n3", "output": "2\n2\n120\n6\n", "type": "stdin_stdout" }, { "fn_...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/diagonal-traversal-of-binary-tree/1
Solve the following coding problem using the programming language python: Given a Binary Tree, print the diagonal traversal of the binary tree. Consider lines of slope -1 passing between nodes. Given a Binary Tree, print all diagonal elements in a binary tree belonging to same line. If the diagonal element are present...
```python class Solution: def diagonal(self, root): if root is None: return out = [] node = root left_q = deque() while node: out.append(node.data) if node.left: left_q.appendleft(node.left) if node.right: node = node.right elif len(left_q) >= 1: node = left_q.pop() else: n...
vfc_85457
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/diagonal-traversal-of-binary-tree/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "8\r\n / \\\r\n 3 10\r\n / \\ \\\r\n 1 6 14\r\n / \\ /\r\n 4 7 13", "output": "8 10 14 3 6 7 13 1 4", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/INOIPRAC/problems/INOI1301
Solve the following coding problem using the programming language python: Indian National Olympiad in Informatics 2013 Calvin wakes up early one morning and finds that all his friends in the hostel are asleep. To amuse himself, he decides to play the following game : he draws a sequence of N squares on the ground, num...
```python try: (n, k) = map(int, input().split()) arr = list(map(int, input().split())) forward = [0] * (n + 1) backward = [0] * (n + 1) backward[0] = arr[0] backward[1] = arr[0] + arr[1] for i in range(k, n): forward[i] = arr[i] + max(forward[i - 1], forward[i - 2]) for i in range(2, n): backward[i] = arr[...
vfc_85458
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/INOIPRAC/problems/INOI1301", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "and output corresponding to the example above.\nSample input\n5 2\n5 3 -2 1 1\nSample output\n11\nNote : Your program should not print anything other than what is specified in the output format. Please remove all diagnostic print s...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/count-number-of-subtrees-having-given-sum/1
Solve the following coding problem using the programming language python: Given a binary tree and an integer X. Your task is to complete the function countSubtreesWithSumX() that returns the count of the number of subtress having total node’s data sum equal to the value X. Example: For the tree given below: ...
```python def countSubtreesWithSumX1(root, x): global count if root == None: return 0 l = countSubtreesWithSumX1(root.left, x) r = countSubtreesWithSumX1(root.right, x) if l + r + root.data == x: count += 1 return l + r + root.data def countSubtreesWithSumX(root, x): global count count = 0 countSubtreesWi...
vfc_85467
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/count-number-of-subtrees-having-given-sum/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n / \\\n -10 3\n / \\ / \\\n 9 8 -4 7\nX = 7", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n / \\\n 2 3\nX = 5", "output": "0", "ty...
taco
verifiable_code
Solve the following coding problem using the programming language python: Given an array a of N integers a1, a2, a3, ... aN you have to find the longest alternating sub-sequence of this array . An alternating sequence b1, b2 ... bk, k ≥ 1 is a sequence that has the 2 following properties: 1.|b1|<|b2|<|b3|<.....<|bk...
```python ''' # Read input from stdin and provide input before running code name = raw_input('What is your name?\n') print 'Hi, %s.' % name ''' import math n=int(input()) arr=list(map(int,input().split(' '))) matrix=[1]*(n) for j in range(n): for i in range(j): if (arr[j] > 0 and arr[i] <0) and abs(arr[j]) > abs(ar...
vfc_85468
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "99\n915256191 -846942591 -700108582 371499337 726371156 -292218005 -11614770 662981777 246247256 -548348143 -964445885 -520223206 17679568 -201690614 822262755 411154260 282828203 114723507 676902022 950390869 266235190 137949909 7...
taco
verifiable_code
https://codeforces.com/problemset/problem/1206/A
Solve the following coding problem using the programming language python: You are given an array $A$, consisting of $n$ positive integers $a_1, a_2, \dots, a_n$, and an array $B$, consisting of $m$ positive integers $b_1, b_2, \dots, b_m$. Choose some element $a$ of $A$ and some element $b$ of $B$ such that $a+b$ do...
```python n = int(input()) a = list(map(int, input().split())) m = int(input()) b = list(map(int, input().split())) c = a + b for i in range(len(a)): for j in range(len(b)): x = a[i] + b[j] if x not in c: print(a[i], b[j]) exit(0) ```
vfc_85472
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1206/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n20\n2\n10 20\n", "output": "20 20", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: Bangalore City, where peace prevails most of the time. Not everyone is a huge fan of peace, though. Certainly not Mr. XYZ, whose identity is not known to us - yet. Mr. XYZ has somehow managed to bring vampires and zombies to Bangalore City to at...
```python cases=int(input()) odd=[] even=[] a=list(map(int,input().split())) a.sort() for i in a: if i%2==0: even.append(i) else: odd.append(i) odd.append(sum(odd)) even.append(sum(even)) print(' '.join(map(str,even)) ,' '.join(map(str,odd))) ```
vfc_85485
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1000\n818 50 113 833 397 811 748 923 392 631 126 343 528 354 200 835 644 341 698 674 199 859 955 581 261 250 159 69 69 70 701 763 165 472 945 313 580 843 960 821 472 330 537 715 381 187 397 121 711 206 214 246 83 539 94 29 649 144 ...
taco
verifiable_code
https://www.codechef.com/problems/STSWAP
Solve the following coding problem using the programming language python: Chef has an array of N numbers and a magic function which can swap two array values if their distance is strictly greater than K units. Since his friend Pishty is obsessed with sorted array, Chef wants to make the lexicographically minimum array...
```python from sys import stdin input = stdin.readline (n, k) = [int(i) for i in input().split()] a = [int(i) for i in input().split()] if k < n // 2: print(*sorted(a)) exit() l = n - k - 1 r = n - (n - k - 1) rem = [] for i in range(n - k - 1): rem.append(a[i]) for i in range(r, n): rem.append(a[i]) rem.sort() ans...
vfc_85489
{ "difficulty": "medium_hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/STSWAP", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6 2\n4 6 3 2 5 1", "output": "1 2 3 4 5 6", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/FLIPPAL
Solve the following coding problem using the programming language python: Chef has a binary string S of length N. In one operation, Chef can: Select two indices i and j (1 ≤ i, j ≤ N, i \ne j) and flip S_{i} and S_{j}. (i.e. change 0 to 1 and 1 to 0) For example, if S = 10010 and chef applys operation on i = 1 and ...
```python for i in range(int(input())): n = int(input()) s = input() z = 0 o = 0 for i in s: if i == '0': z += 1 else: o += 1 if z % 2 != 0 and o % 2 != 0: print('NO') else: print('YES') ```
vfc_85495
{ "difficulty": "easy", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/FLIPPAL", "time_limit": "0.5 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n6\n101011\n2\n01\n7\n1110000\n", "output": "YES\nNO\nYES\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: During a voyage of the starship Hakodate-maru (see Problem A), researchers found strange synchronized movements of stars. Having heard these observations, Dr. Extreme proposed a theory of "super stars". Do not take this term as a description of ...
```python def distance(star, position): return sum([(a - b) ** 2 for (a, b) in zip(star, position)]) ** (1 / 2) def difference(star, position): return [a - b for (a, b) in zip(star, position)] while True: n = int(input()) if n == 0: break stars = [list(map(float, input().split())) for i in range(n)] position =...
vfc_85499
{ "difficulty": "unknown_difficulty", "memory_limit": "134.217728 megabytes", "memory_limit_bytes": null, "problem_url": null, "time_limit": "8.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n10.00000 10.00000 10.00000\n20.00000 10.00000 10.00000\n20.00000 20.00000 10.00000\n10.00000 20.00000 10.00000\n4\n10.00000 10.063097698119668 10.00000\n10.00000 50.00000 50.00000\n50.00000 10.00000 50.00000\n50.00000 50.00000 1...
taco
verifiable_code
https://www.codechef.com/problems/THREEPTS
Solve the following coding problem using the programming language python: Read problem statements in [Russian], [Mandarin Chinese], [Bengali], and [Vietnamese] as well. There are three distinct points - A, B, C in the X-Y plane. Initially, you are located at point A. You want to reach the point C satisfying the follo...
```python t = int(input()) for _ in range(t): (x1, y1) = map(int, input().split(' ')) (xb, yb) = map(int, input().split(' ')) (x3, y3) = map(int, input().split(' ')) xa = min(x1, x3) ya = min(y1, y3) xc = max(x1, x3) yc = max(y1, y3) if xb == xa and ya <= yb <= yc or (yb == yc and xa <= xb <= xc): print('YES'...
vfc_85503
{ "difficulty": "hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/THREEPTS", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n1 1\n1 3\n3 3\n0 0\n2 2\n3 4\n5 2\n3 2\n1 2\n1 1\n-1 1\n10000 10000\n", "output": "YES\nNO\nYES\nNO", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1159/A
Solve the following coding problem using the programming language python: Vasya has a pile, that consists of some number of stones. $n$ times he either took one stone from the pile or added one stone to the pile. The pile was non-empty before each operation of taking one stone from the pile. You are given $n$ operati...
```python n = int(input()) s = input() ans = 0 for i in s: if i == '+': ans += 1 else: ans = max(ans - 1, 0) print(ans) ```
vfc_85507
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1159/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n---\n", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n++++\n", "output": "4", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: You'll be given an array A of N integers as input. For each element of the array A[i], print A[i]-1. Input: There will be N+1 iines of input each consisting of a single integer. Integer in first line denotes N For the following N lines the int...
```python x = list() a = input() for i in range(int(a)): n = input() x.append(int(n)) i=0 x.insert(0,a) b = len(x) for i in range(1,b): x[i]= x[i] - 1 for i in range(1,b): print(x[i]) ```
vfc_85515
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "9\n1\n2\n3\n4\n5\n6\n7\n8\n9", "output": "0\n1\n2\n3\n4\n5\n6\n7\n8", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1189/D1
Solve the following coding problem using the programming language python: Note that this is the first problem of the two similar problems. You can hack this problem only if you solve both problems. You are given a tree with n nodes. In the beginning, 0 is written on all edges. In one operation, you can choose any 2 d...
```python m = int(input()) l = [0 for _ in range(m + 1)] for _ in range(m - 1): (a, b) = map(int, input().split()) l[a] += 1 l[b] += 1 if 2 in l: print('NO') else: print('YES') ```
vfc_85519
{ "difficulty": "medium_hard", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1189/D1", "time_limit": "1.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "50\n16 4\n17 9\n31 19\n22 10\n8 1\n40 30\n3 31\n20 29\n47 27\n22 25\n32 34\n12 15\n40 32\n10 33\n47 12\n6 24\n46 41\n14 23\n12 35\n31 42\n46 28\n31 20\n46 37\n1 39\n29 49\n37 47\n40 6\n42 36\n47 2\n24 46\n2 13\n8 45\n41 3\n32 17\n4...
taco
verifiable_code
https://codeforces.com/problemset/problem/999/A
Solve the following coding problem using the programming language python: Mishka started participating in a programming contest. There are $n$ problems in the contest. Mishka's problem-solving skill is equal to $k$. Mishka arranges all problems from the contest into a list. Because of his weird principles, Mishka onl...
```python (n, k) = map(int, input().split()) A = list(map(int, input().split())) ans = 0 for i in range(n): if A[i] > k: break else: ans += 1 if i != n - 1: for j in range(n - 1, -1, -1): if A[j] > k: break else: ans += 1 print(ans) ```
vfc_85525
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/999/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "8 4\n4 2 3 1 5 1 6 4\n", "output": "5\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 2\n3 1 2 1 3\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": n...
taco
verifiable_code
https://codeforces.com/problemset/problem/550/A
Solve the following coding problem using the programming language python: You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order). -----Input----- The only line of input contains a string s of length between 1...
```python s = input() a = s.find('AB') b = s.rfind('BA') c = s.find('BA') d = s.rfind('AB') if a == -1 or b == -1: print('NO') elif abs(a - b) <= 1 and abs(c - d) <= 1: print('NO') else: print('YES') ```
vfc_85529
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/550/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "ABA\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "BACFAB\n", "output": "YES\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/688/D
Solve the following coding problem using the programming language python: Today Pari and Arya are playing a game called Remainders. Pari chooses two positive integer x and k, and tells Arya k but not x. Arya have to find the value <image>. There are n ancient numbers c1, c2, ..., cn and Pari has to tell Arya <image> ...
```python from math import * (n, k) = map(int, input().split()) arr = list(map(int, input().split())) flag = 0 if k == 1: print('Yes') else: arr1 = [] temp = k for i in range(2, k + 1): if temp % i == 0: cnt = 0 while temp % i == 0: cnt += 1 temp = temp // i arr1.append(i ** cnt) mainflag = 0 f...
vfc_85533
{ "difficulty": "medium_hard", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/688/D", "time_limit": "1.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10 4\n2 2 2 2 2 2 2 2 2 2\n", "output": "No", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 125\n5\n", "output": "No", "type": "stdin_stdout" }, { "fn_name": null...
taco
verifiable_code
https://codeforces.com/problemset/problem/154/D
Solve the following coding problem using the programming language python: The King of Flatland will organize a knights' tournament! The winner will get half the kingdom and the favor of the princess of legendary beauty and wisdom. The final test of the applicants' courage and strength will be a fencing tournament. The...
```python (x1, x2, a, b) = map(int, input().split()) if a <= 0 <= b: if x1 < x2: if x2 - x1 <= b: print('FIRST') print(x2) else: print('DRAW') elif x1 - x2 <= -a: print('FIRST') print(x2) else: print('DRAW') else: reverse = False if a < 0: (x1, x2, a, b) = (-x1, -x2, -b, -a) reverse = True ...
vfc_85537
{ "difficulty": "very_hard", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/154/D", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "637107829 -403198378 -2 -2\n", "output": "DRAW\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "847094637 -152905363 -1000000000 -1000000000\n", "output": "FIRST\n-152905363\n", ...
taco
verifiable_code
https://www.codechef.com/problems/FAILURE
Solve the following coding problem using the programming language python: Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef has always dreamed of becoming an employee of the "Hack and Manipulate Group". Their work is simple ― attacking networks. They gave Che...
```python from collections import defaultdict class UndirectedGraph: def __init__(self, node_num): self.node_num = node_num self.graph = defaultdict(list) def add_edge(self, v, w): self.graph[v].append(w) self.graph[w].append(v) def _find(self, v, visited, deleted): stack = [v] parent = defaultdict(i...
vfc_85541
{ "difficulty": "very_hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/FAILURE", "time_limit": "2 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n5 5\n5 1\n5 2\n1 2\n2 3\n2 4\n5 6\n4 5\n4 1\n4 2\n4 3\n5 1\n5 2\n5 5\n3 4\n3 5\n3 1\n3 2\n4 2\n4 1\n3 4\n6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 4", "output": "1\n4\n2\n-1\n-1", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/578/B
Solve the following coding problem using the programming language python: You are given n numbers a_1, a_2, ..., a_{n}. You can perform at most k operations. For each operation you can multiply one of the numbers by x. We want to make [Image] as large as possible, where $1$ denotes the bitwise OR. Find the maximum p...
```python (n, k, p) = map(int, input().split()) numbers = list(map(int, input().split())) x = [0] * (n + 10) y = [0] * (n + 10) p = p ** k maxi = 0 for i in range(n): x[i + 1] = numbers[i] | x[i] for j in range(n, -1, -1): y[j - 2] = numbers[j - 1] | y[j - 1] for i in range(n): if maxi < x[i] | numbers[i] * p | y[i]...
vfc_85545
{ "difficulty": "medium_hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/578/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 1 2\n1 1 1\n", "output": "3\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/remove-all-duplicates-from-a-given-string4321/1
Solve the following coding problem using the programming language python: Given a string Str which may contains lowercase and uppercase chracters. The task is to remove all duplicate characters from the string and find the resultant string. The order of remaining characters in the output should be same as in the origi...
```python class Solution: def removeDuplicates(self, str): asci = [0] * 256 s = '' for i in range(len(str)): x = ord(str[i]) asci[x] += 1 for i in range(len(str)): x = ord(str[i]) if asci[x] > 0: s += str[i] asci[x] = 0 return s ```
vfc_85549
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/remove-all-duplicates-from-a-given-string4321/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "Str = geeksforgeeks", "output": "geksfor", "type": "stdin_stdout" }, { "fn_name": null, "input": "Str = HappyNewYear", "output": "HapyNewYr", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: Space Coconut Crab Space coconut crab English text is not available in this practice contest. Ken Marine Blue is a space hunter who travels through the entire galaxy in search of space coconut crabs. The space coconut crab is the largest crus...
```python import math def solve(e): k = 2 ** 32 for z in range(100, -1, -1): z3 = z * z * z if z3 > e: continue e2 = e - z3 ylm = int(math.sqrt(e2)) xzlm = 3 * z * z + 3 * z + 1 for y in range(ylm, -1, -1): y2 = y * y if e2 > (y + 1) * (y + 1): break e3 = e2 - y2 xylm = 2 * y + 1 x ...
vfc_85550
{ "difficulty": "unknown_difficulty", "memory_limit": "134.217728 megabytes", "memory_limit_bytes": null, "problem_url": null, "time_limit": "8.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n2\n4\n6\n300\n1250\n0", "output": "1\n2\n2\n4\n18\n44\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n2\n4\n2\n300\n1250\n0", "output": "1\n2\n2\n2\n18\n44\n", "type": "s...