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://practice.geeksforgeeks.org/problems/sum-of-distinct-elements4801/1
Solve the following coding problem using the programming language python: You are given an array Arr of size N. Find the sum of distinct elements in an array. Example 1: Input: N = 5 Arr[] = {1, 2, 3, 4, 5} Output: 15 Explanation: Distinct elements are 1, 2, 3 4, 5. So sum is 15. Example 2: Input: N = 5 Arr[] = {5, 5,...
```python class Solution: def findSum(self, arr, n): s = set(arr) a = list(s) return sum(a) ```
vfc_142332
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/sum-of-distinct-elements4801/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 5\nArr[] = {1, 2, 3, 4, 5}", "output": "15", "type": "stdin_stdout" }, { "fn_name": null, "input": "N = 5\nArr[] = {5, 5, 5, 5, 5}", "output": "5", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: As many of you know, we have two major calendar systems used in Japan today. One of them is Gregorian calendar which is widely used across the world. It is also known as “Western calendar” in Japan. The other calendar system is era-based calend...
```python while True: Name = [] first = [] final = [] (N, Q) = map(int, input().split()) if N == Q == 0: break else: for n in range(N): (eraname, erabasedyear, westernyear) = input().split() Name.append(eraname) era_first = int(westernyear) - int(erabasedyear) + 1 first.append(int(era_first)) f...
vfc_142333
{ "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 3\nmeiji 10 1877\ntaisho 6 1917\nshowa 62 1987\nheisei 22 2010\n2046\n1917\n1988\n1 1\nuniversalcentury 123 2168\n2010\n0 0", "output": "Unknown\ntaisho 6\nUnknown\nUnknown\n", "type": "stdin_stdout" }, { ...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/mr-modulo-and-pairs5610/1
Solve the following coding problem using the programming language python: Mr. Modulo comes up with another problem related to modulo and this time he is interested in finding all the possible pairs a and b in the array arr[] such that a % b = k where k is a given integer. The array given will have distinct elements. Y...
```python class Solution: def divisors(self, val): ans = [] for i in range(1, int(val ** 0.5) + 1): if val % i == 0: if val // i == i: ans.append(i) else: ans.append(i) ans.append(val // i) return ans def printPairs(self, a, n, h): a.sort() count = 0 _set = set(a) k = h for...
vfc_142338
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/mr-modulo-and-pairs5610/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N=5, K=3\narr[] = {2, 3, 5, 4, 7}", "output": "4", "type": "stdin_stdout" }, { "fn_name": null, "input": "N=2, K=3\narr[] = {1, 2}", "output": "0", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.hackerrank.com/challenges/liars/problem
Solve the following coding problem using the programming language python: You have N soldiers numbered from 1 to N. Each of your soldiers is either a liar or a truthful person. You have M sets of information about them. Each set of information tells you the number of liars among a certain range of your soldiers. Let L...
```python def floyd_warshall(N, edges): from math import inf paths = [[inf] * (N + 1) for _ in range(N + 1)] for (i, j, c) in edges: paths[i][j] = min(paths[i][j], c) for k in range(N + 1): for n1 in range(N + 1): for n2 in range(N + 1): paths[n1][n2] = min(paths[n1][n2], paths[n1][k] + paths[k][n2]) re...
vfc_142339
{ "difficulty": "hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.hackerrank.com/challenges/liars/problem", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 2\n1 2 1\n2 3 1\n", "output": "1 2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "20 11\n3 8 4\n1 9 6\n1 13 9\n5 11 5\n4 19 12\n8 13 5\n4 8 4\n7 9 2\n10 13 3\n7 16 7\n14 19 4\n", ...
taco
verifiable_code
https://codeforces.com/problemset/problem/1216/C
Solve the following coding problem using the programming language python: There is a white sheet of paper lying on a rectangle table. The sheet is a rectangle with its sides parallel to the sides of the table. If you will take a look from above and assume that the bottom left corner of the table has coordinates $(0, 0...
```python W = list(map(int, input().split())) B1 = list(map(int, input().split())) B2 = list(map(int, input().split())) def f(A, B): return (max(A[0], B[0]), max(A[1], B[1]), min(A[2], B[2]), min(A[3], B[3])) def area(A): return max(A[2] - A[0], 0) * max(A[3] - A[1], 0) if area(f(W, B1)) + area(f(W, B2)) - area(f(W...
vfc_142343
{ "difficulty": "medium_hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1216/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 2 4 4\n1 1 3 5\n3 1 5 5\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 3 7 5\n0 0 4 6\n0 0 7 4\n", "output": "YES\n", "type": "stdin_stdout" }, {...
taco
verifiable_code
https://codeforces.com/problemset/problem/1695/B
Solve the following coding problem using the programming language python: Mike and Joe are playing a game with some stones. Specifically, they have $n$ piles of stones of sizes $a_1, a_2, \ldots, a_n$. These piles are arranged in a circle. The game goes as follows. Players take turns removing some positive number of ...
```python def circle_game(): for _ in range(int(input())): a = int(input()) b = list(map(int, input().split())) if a % 2 != 0: print('Mike') elif b.index(min(b)) % 2 == 0: print('Joe') else: print('Mike') circle_game() ```
vfc_142347
{ "difficulty": "easy", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1695/B", "time_limit": "1 second" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n1\n37\n2\n100 100\n", "output": "Mike\nJoe\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n1\n1\n", "output": "Mike\n", "type": "stdin_stdout" }, { "fn_name...
taco
verifiable_code
https://www.codechef.com/problems/DPAIRS
Solve the following coding problem using the programming language python: Chef has two integer sequences $A_1, A_2, \ldots, A_N$ and $B_1, B_2, \ldots, B_M$. You should choose $N+M-1$ pairs, each in the form $(A_x, B_y)$, such that the sums $A_x + B_y$ are all pairwise distinct. It is guaranteed that under the given c...
```python (n, m) = map(int, input().split()) arr1 = list(map(int, input().split())) arr2 = list(map(int, input().split())) max1 = arr1.index(max(arr1)) min2 = arr2.index(min(arr2)) arr = [] for i in range(m): arr.append([max1, i]) for i in range(n): if i != max1: arr.append([i, min2]) for i in arr: print(*i) ```
vfc_142351
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/DPAIRS", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 2\n10 1 100\n4 3\n\n", "output": "2 1\n0 0\n1 0\n0 1\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1492/C
Solve the following coding problem using the programming language python: Your classmate, whom you do not like because he is boring, but whom you respect for his intellect, has two strings: $s$ of length $n$ and $t$ of length $m$. A sequence $p_1, p_2, \ldots, p_m$, where $1 \leq p_1 < p_2 < \ldots < p_m \leq n$, is ...
```python (n, m) = map(int, input().split()) s = input() t = input() fast_substring = [0] * m last_substring = [0] * m j = 0 for i in range(n): if s[i] == t[j]: fast_substring[j] = i j += 1 if j == m: break j = m - 1 for i in range(n - 1, -1, -1): if s[i] == t[j]: last_substring[j] = i j -= 1 if j < 0: ...
vfc_142359
{ "difficulty": "medium", "memory_limit": "512 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1492/C", "time_limit": "2 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 3\nabbbc\nabc\n", "output": "3\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1263/A
Solve the following coding problem using the programming language python: You have three piles of candies: red, green and blue candies: the first pile contains only red candies and there are $r$ candies in it, the second pile contains only green candies and there are $g$ candies in it, the third pile contains only ...
```python for _ in range(int(input())): a = sorted(list(map(int, input().split()))) if a[2] - a[0] >= a[1]: print(a[1] + a[0]) else: print(int(a[1] + (a[0] - (a[1] - (a[2] - a[0])) / 2))) ```
vfc_142363
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1263/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n1 1 1\n1 2 1\n4 1 1\n7 4 10\n8 1 4\n8 2 8\n", "output": "1\n2\n2\n10\n5\n9\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n1 1 1\n1 2 1\n4 1 1\n7 7 10\n8 1 4\n8 2 8\n", "output...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/pairs-which-are-divisible-by-41920/1
Solve the following coding problem using the programming language python: Given an array, if ‘n’ positive integers, count the number of pairs of integers in the array that have the sum divisible by 4. Example 1: Input : Arr[] = {2, 2, 1, 7, 5} Output : 3 Explanation: (2,2), (1,7) and(7,5) are the 3 pairs. Example 2: ...
```python class Solution: def count4Divisibiles(self, arr, n): arr.sort() rem = [0] * 4 for index in range(n): rem[arr[index] % 4] += 1 ans = 0 ans += rem[0] * (rem[0] - 1) // 2 ans += rem[2] * (rem[2] - 1) // 2 ans += rem[1] * rem[3] return ans ```
vfc_142367
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/pairs-which-are-divisible-by-41920/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "Arr[] = {2, 2, 1, 7, 5}", "output": "3", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: N: Mail order Mr. Komozawa bought building blocks toys from Makai mail order. The building blocks are in the shape of a cube with a side length of 1, and are stacked on squares divided into $ H $ pieces vertically and $ W $ pieces horizontally...
```python from bisect import bisect_left as bl from itertools import accumulate (h, w) = map(int, input().split()) aList = sorted(map(int, input().split())) bList = list(map(int, input().split())) acc = [0] + list(accumulate(aList)) aList.insert(0, -1) ans = 0 for b in bList: index = bl(aList, b) ans += acc[index - 1...
vfc_142368
{ "difficulty": "unknown_difficulty", "memory_limit": "268.435456 megabytes", "memory_limit_bytes": null, "problem_url": null, "time_limit": "1.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 2\n0 5\n1 5", "output": "6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 2\n0 2\n1 5", "output": "3\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/CHEFFFUNC
Solve the following coding problem using the programming language python: Chef's new friend hErd gave him two functions f and g. The function f is defined over x (x≥ 1) as: f(x) = \begin{cases} 0, & \text{if } x = 1 \\ f( \frac{x}{2} ) + 1, & \text{if } x \text{ is even} \\ f( \lfloor \frac{x}{2} \rfloor ), & \tex...
```python def base_2(x): return bin(x)[2:] def f_plus_g(x): b = base_2(x) k = len(b) - 1 c = b.count('0') return c + 2 ** (k + 1) + 2 ** k - 1 - x for _ in range(int(input())): (l, r) = [int(x) for x in input().split()] assert l >= 1 and l <= r k = len(base_2(r)) - 1 if 2 ** k >= l: print(k + 2 ** (k + 1) -...
vfc_142372
{ "difficulty": "very_hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/CHEFFFUNC", "time_limit": "3 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1 1\n1 2\n1 20", "output": "1\n4\n35", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/maximum-product-of-two-numbers2730/1
Solve the following coding problem using the programming language python: Given an array Arr of size N with all elements greater than or equal to zero. Return the maximum product of two numbers possible. Example 1: Input: N = 6 Arr[] = {1, 4, 3, 6, 7, 0} Output: 42 Example 2: Input: N = 5 Arr = {1, 100, 42, 4, 23}...
```python class Solution: def maxProduct(self, arr, n): arr.sort() return arr[n - 1] * arr[n - 2] ```
vfc_142376
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/maximum-product-of-two-numbers2730/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 6\nArr[] = {1, 4, 3, 6, 7, 0}", "output": "42", "type": "stdin_stdout" }, { "fn_name": null, "input": "N = 5\nArr = {1, 100, 42, 4, 23}", "output": "4200", "type": "stdin_stdout" ...
taco
verifiable_code
https://www.hackerrank.com/challenges/xoring-ninja/problem
Solve the following coding problem using the programming language python: An XOR operation on a list is defined here as the xor ($\oplus$) of all its elements (e.g.: $XOR(\{A,B,C\})=A\oplus B\oplus C$). The $\textit{XorSum}$ of set $\textbf{arr}$ is defined here as the sum of the $XOR$s of all non-empty subsets of $...
```python import sys def poweroftwo(n): val = 1 yield val for i in range(n): val *= 2 yield val r = sys.stdin.readline text = r() t = int(text) for i in range(t): text = r() n = int(text) text = r() tmp = 0 for num in map(int, text.split()): tmp |= num for i in range(n - 1): tmp *= 2 if i % 20 == 0:...
vfc_142377
{ "difficulty": "medium_hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.hackerrank.com/challenges/xoring-ninja/problem", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n3\n1 2 3\n", "output": "12\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n4\n1 2 4 8\n5\n1 2 3 5 100\n", "output": "120\n1648\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: Ikshu and his machine gun To celebrate his new year Ikshu went to play "beyond to beyond" (abbreviated as BOB) with his friends. BOB can be described as follows : It consists of Infinite boxes arranged one over another, Lowest box being 1. Give...
```python s=int(input()) list=[int(i) for i in input().split()] list.sort() for i in range(s): print((list[i]-i), end=' ') print(""); ```
vfc_142381
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "62979\n47002 56795 62986 63048 51206 50283 59370 4792 68263 63431 78791 47826 51402 3700 21285 65012 63282 13506 61628 75066 51915 72566 48469 27761 36470 36168 64585 58069 6364 6914 18834 27017 16577 19015 2214 23683 49144 23089 3...
taco
verifiable_code
Solve the following coding problem using the programming language python: Problem Given a natural number N less than or equal to 12, find the smallest natural number such that the number of divisors is exactly N. Constraints * 1 ≤ N ≤ 12 Input One natural number N is given in one line. Output Output the smalles...
```python def solve(n): for i in range(1, 10000): cnt = 0 for j in range(1, i + 1): if i % j == 0: cnt += 1 if cnt == n: return i while True: try: n = int(input()) print(solve(n)) except EOFError: break ```
vfc_142386
{ "difficulty": "unknown_difficulty", "memory_limit": "267.38688 megabytes", "memory_limit_bytes": null, "problem_url": null, "time_limit": "1.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5", "output": "16\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4", "output": "6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6", "out...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/replace-the-bit3212/1
Solve the following coding problem using the programming language python: Given two numbers N and K, change the Kth (1-based indexing) bit from the left of the binary representation of the number N to '0' if it is '1', else return the number N itself. Example 1: Input: N = 13, K = 2 Output: 9 Explanation: Binary repr...
```python class Solution: def replaceBit(self, N, K): n = list(bin(N)[2:]) if len(n) >= K: ind = K - 1 if n[ind] == '1': n[ind] = '0' return int(''.join(n), 2) else: return N else: return N ```
vfc_142390
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/replace-the-bit3212/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 13, K = 2", "output": "9", "type": "stdin_stdout" }, { "fn_name": null, "input": "N = 13, K = 6", "output": "13", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/playing-with-mobile-numbers0732/1
Solve the following coding problem using the programming language python: Given a number in form of a string s. The task is to find whether the number is valid indian mobile number or not. Rules for valid :-indian mobile number The number should contain 10 or 11 or 12 digits. If it contains 10 digits, then first di...
```python import re class Solution: def is_valid(self, s): if len(s) >= 10 and len(s) <= 12: if len(s) == 10: ans = re.search('^[7-9]', s) if ans: return 1 else: return 0 if len(s) == 11: ans = re.search('^0[7-9]', s) if ans: return 1 else: return 0 if len(s) ==...
vfc_142391
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/playing-with-mobile-numbers0732/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "s = \"912345678999\"", "output": "0", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.hackerrank.com/challenges/short-palindrome/problem
Solve the following coding problem using the programming language python: Consider a string, $S$, of $n$ lowercase English letters where each character, $s_i$ ($0\leq i<n)$, denotes the letter at index $\boldsymbol{i}$ in $S$. We define an $(a,b,c,d)$ palindromic tuple of $S$ to be a sequence of indices in $S$ satisfy...
```python mod = 10 ** 9 + 7 def sum_multi(A, B): return A[0] * B[0] + A[1] * B[1] + A[2] * B[2] + A[3] * B[3] + A[4] * B[4] + A[5] * B[5] + A[6] * B[6] + A[7] * B[7] + A[8] * B[8] + A[9] * B[9] + A[10] * B[10] + A[11] * B[11] + A[12] * B[12] + A[13] * B[13] + A[14] * B[14] + A[15] * B[15] + A[16] * B[16] + A[17] * B[...
vfc_142392
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.hackerrank.com/challenges/short-palindrome/problem", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "kkkkkkz\n", "output": "15\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "ghhggh\n", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": ...
taco
verifiable_code
https://codeforces.com/problemset/problem/876/A
Solve the following coding problem using the programming language python: Winnie-the-Pooh likes honey very much! That is why he decided to visit his friends. Winnie has got three best friends: Rabbit, Owl and Eeyore, each of them lives in his own house. There are winding paths between each pair of houses. The length o...
```python n = int(input()) a = int(input()) b = int(input()) c = int(input()) if n == 1: print(0) return x = min(a, b, c) if x in [a, b]: print((n - 1) * x) else: print(min(a, b) + (n - 2) * c) ```
vfc_142400
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/876/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n2\n3\n1\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n2\n3\n5\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "in...
taco
verifiable_code
Solve the following coding problem using the programming language python: Panda is fond of numbers. Given a number, he subtracts it with squares of any one particular digit of that number to get new numbers. This operation can be applied any number of times (possibly zero) till he obtains a pandatic number. If he is a...
```python get_input = int(input()) while(get_input): num = int(input()) if num == 90 or num == 91: print("No") elif num < 13: if num == 1 or num == 4: print("Yes") else: print("No") else: print("Yes") get_input -= 1 ```
vfc_142404
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "100000\n700001\n700002\n700003\n700004\n700005\n700006\n700007\n700008\n700009\n700010\n700011\n700012\n700013\n700014\n700015\n700016\n700017\n700018\n700019\n700020\n700021\n700022\n700023\n700024\n700025\n700026\n700027\n700028\...
taco
verifiable_code
Solve the following coding problem using the programming language python: A rabbit is playing a role-playing game. Just before entering the castle, he was ambushed by an enemy! It was a battle between one hero operated by a rabbit and n enemies. Each character has four stats, health hi, attack power ai, defense power...
```python import sys readline = sys.stdin.readline write = sys.stdout.write def solve(): N = int(readline()) (ha, aa, da, sa) = map(int, readline().split()) ans = 0 S = [] for i in range(N): (hi, ai, di, si) = map(int, readline().split()) m0 = max(ai - da, 0) if si > sa: ans += m0 m1 = max(aa - di, 0) ...
vfc_142408
{ "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": "1\n1 0 1 1\n10000 10000 10000 10000", "output": "-1\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/821/A
Solve the following coding problem using the programming language python: Okabe needs to renovate the Future Gadget Laboratory after he tried doing some crazy experiments! The lab is represented as an n by n square grid of integers. A good lab is defined as a lab in which every number not equal to 1 can be expressed a...
```python from itertools import * n = int(input()) f = [list(map(int, input().split())) for _ in range(n)] for (i, j) in product(list(range(n)), list(range(n))): x = f[i][j] if x == 1: continue if not any((a + b == x for (a, b) in product(chain(f[i][:j], f[i][j + 1:]), (f[k][j] for k in chain(list(range(i)), list(...
vfc_142412
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/821/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1 1 2\n2 3 1\n6 4 1\n", "output": "Yes\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n1 5 2\n1 1 1\n1 2 3\n", "output": "No\n", "type": "stdin_stdout" }, { ...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/santa-banta2814/1
Solve the following coding problem using the programming language python: Santa is still not married. He approaches a marriage bureau and asks them to hurry the process. The bureau checks the list of eligible girls of size N and hands it over to Santa. Santa being conscious about his marriage is determined to find a g...
```python def precompute(): pass def helpSanta(n, m, g): if m == 0: return -1 parent = list(range(n)) rank = [1] * n def find(n): if parent[n] != n: parent[n] = find(parent[n]) return parent[n] def union(a, b): (x, y) = (find(a), find(b)) if x == y: return False if rank[x] > rank[y]: paren...
vfc_142416
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/santa-banta2814/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 10\r\nM = 6\r\ng[] = {{1,2},{2,3},{3,4},{4,5},{6,7},{9,10}}", "output": "11", "type": "stdin_stdout" }, { "fn_name": null, "input": "N = 2\r\nM = 1\r\ng[] = {{1, 2}}", "output": "3", ...
taco
verifiable_code
Solve the following coding problem using the programming language python: The professor is conducting a course on Discrete Mathematics to a class of N students. He is angry at the lack of their discipline, and he decides to cancel the class if there are fewer than K students present after the class starts. Given the ...
```python for _ in range(eval(input())): n,k=list(map(int,input().split())) a=list(map(int,input().split())) a=[x for x in a if x<=0] print("YES" if len(a)<k else "NO") ```
vfc_142417
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n4 3\n-1 -3 4 2\n4 2\n0 -1 2 1", "output": "YES\nNO", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n10 4\n-93 -86 49 -62 -90 -63 40 72 11 67\n10 10\n23 -35 -2 58 -67 -56 -42 -73 -19 37...
taco
verifiable_code
Solve the following coding problem using the programming language python: There is a rectangular maze with square squares lined up vertically and horizontally. In this maze, while moving to the adjacent squares in the north, south, east and west, the starting square S departs and the goal square G is aimed at. There a...
```python from collections import deque while True: (x, y) = map(int, input().split()) if x == 0: break mp = [list('#' * (x + 2))] + [list('#' + input() + '#') for _ in range(y)] + [list('#' * (x + 2))] ice_cnt = 0 ice_dic = [] vec = ((1, 0), (0, -1), (-1, 0), (0, 1)) def ice_search(x, y, ice_cnt): for (dx,...
vfc_142421
{ "difficulty": "unknown_difficulty", "memory_limit": "134.217728 megabytes", "memory_limit_bytes": null, "problem_url": null, "time_limit": "1.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 5\n.X.S.\n.X#..\n.XX##\n.#XG.\n..X..\n7 3\nSXX.XXG\nX.#.#X.\nXXX.XX#\n4 4\nS...\nX.X.\nGX..\n...X\n10 10\n..XXXXX.XX\n.X.#.#X.XX\nSX.#X.X..X\n#X.##.X.XX\n..XXXX#.XX\n##.##.##XX\n....X.YX#X\n.##X..#X#X\n....XX#..X\n...#XXG..X\n0 0...
taco
verifiable_code
Solve the following coding problem using the programming language python: A young boy John is playing with eight triangular panels. These panels are all regular triangles of the same size, each painted in a single color; John is forming various octahedra with them. While he enjoys his playing, his father is wondering...
```python import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools sys.setrecursionlimit(10 ** 7) inf = 10 ** 20 eps = 1.0 / 10 ** 13 mod = 10 ** 9 + 7 dd = [(-1, 0), (0, 1), (1, 0), (0, -1)] ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (...
vfc_142433
{ "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": "blue blue blue blue bluf blue blue blue\nred blue blue blue blue blue blue blue\nred red blue blue blue blue blue blue", "output": "1\n1\n3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "...
taco
verifiable_code
https://www.codechef.com/COFI2016/problems/CF212
Solve the following coding problem using the programming language python: Given a square matrix of size N×N, calculate the absolute difference between the sums of its diagonals. -----Input----- The first line contains a single integer N. The next N lines denote the matrix's rows, with each line containing N space-se...
```python def diagonal_difference(matrix): l = sum((matrix[i][i] for i in range(N))) r = sum((matrix[i][N - i - 1] for i in range(N))) return abs(l - r) matrix = [] N = eval(input()) for _ in range(N): matrix.append(list(map(int, input().split()))) print(diagonal_difference(matrix)) ```
vfc_142441
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/COFI2016/problems/CF212", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n11 2 4\n4 5 6\n10 8 -12\n", "output": "15\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/CY302020/problems/CODEY302
Solve the following coding problem using the programming language python: The chef is very expert in coding, so to keep his password safe from the hackers. He always enters a decoded code of his password. You are a hacker and your work is to find the maximum number of possible ways to unlock his password in encoded fo...
```python t = int(input()) while t > 0: s = input().strip() if not s: print('NO') dp = [0 for x in range(len(s) + 1)] dp[0] = 1 dp[1] = 1 if 0 < int(s[0]) <= 9 else 0 for i in range(2, len(s) + 1): if 0 < int(s[i - 1:i]) <= 9: dp[i] += dp[i - 1] if s[i - 2:i][0] != '0' and int(s[i - 2:i]) <= 26: dp[i]...
vfc_142454
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/CY302020/problems/CODEY302", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n12\n223\n", "output": "YES\nNO\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/844b4fdcd988ac5461324d62d43f7892749a113c/1
Solve the following coding problem using the programming language python: There is a row of N houses, each house can be painted with one of the three colors: red, blue or green. The cost of painting each house with a certain color is different. You have to paint all the houses such that no two adjacent houses have the...
```python class Solution: def distinctColoring(self, N, r, g, b): dp = [[0] * 3 for _ in range(N)] dp[0][0] = r[0] dp[0][1] = g[0] dp[0][2] = b[0] for i in range(1, N): dp[i][0] = min(dp[i - 1][1], dp[i - 1][2]) + r[i] dp[i][1] = min(dp[i - 1][0], dp[i - 1][2]) + g[i] dp[i][2] = min(dp[i - 1][0], d...
vfc_142458
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/844b4fdcd988ac5461324d62d43f7892749a113c/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 3\r\nr[] = {1, 1, 1}\r\ng[] = {2, 2, 2}\r\nb[] = {3, 3, 3}", "output": "4", "type": "stdin_stdout" }, { "fn_name": null, "input": "N = 3\r\nr[] = {2, 1, 3}\r\ng[] = {3, 2, 1}\r\nb[] = {1, 3, 2}",...
taco
verifiable_code
Solve the following coding problem using the programming language python: Subodh is celebrating its annual Techno-Cultural Fest. The IT student Kejal has agreed to supply candies for this festive season. The Kejal has prepared N boxes of candies, numbered 1 to N (Each number occurring exactly once ). The Kejal is ver...
```python for _ in range(eval(input())): try:n=eval(input()) except:n=eval(input()) if n==0: print(0) continue # print n try:arr=input().split() except:arr=input().split() try:seq=input().split() except:seq=input().split() if n==1: print(0) continue #print n count=0 flag=False while len(arr)>0: x=...
vfc_142459
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n\n3\n1 2 3\n3 2 1", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n\n3\n1 2 3\n3 1 2\n\n3\n1 2 3\n3 2 1\n\n5\n3 4 5 2 1 \n4 1 5 2 3 \n\n4\n1 2 3 4\n2 3 4 1", "outpu...
taco
verifiable_code
https://codeforces.com/problemset/problem/934/A
Solve the following coding problem using the programming language python: Nian is a monster which lives deep in the oceans. Once a year, it shows up on the land, devouring livestock and even people. In order to keep the monster away, people fill their villages with red colour, light, and cracking noise, all of which f...
```python (n, m) = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) rec = [[] for i in range(n)] INF = float('inf') for i in range(n): for j in range(m): rec[i].append(a[i] * b[j]) rec[i] = sorted(rec[i], reverse=True) ma = [-INF] * n ind = 0 for i in range(n): if m...
vfc_142463
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/934/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 2\n20 18\n2 14\n", "output": "252\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 3\n-1 0 1 2 3\n-1 0 1\n", "output": "2\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/STONES
Solve the following coding problem using the programming language python: Soma is a fashionable girl. She absolutely loves shiny stones that she can put on as jewellery accessories. She has been collecting stones since her childhood - now she has become really good with identifying which ones are fake and which ones a...
```python for i in range(int(input())): s1 = input() s2 = input() c = 0 for i in s2: if i in s1: c = c + 1 print(c) ```
vfc_142467
{ "difficulty": "easy", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/STONES", "time_limit": "0.363636 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\nabc\nabcdef\naA\nabAZ\naaa\na\nwhat\nnone", "output": "3\n2\n1\n0", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\nacb\nabcdef\naA\nabAZ\naaa\na\nwhat\nnone", "output": "3\n2\n1\n...
taco
verifiable_code
Solve the following coding problem using the programming language python: Deepak like strings which are in flip flop in nature. For example, he likes XYXYX, while he doesn't like XXYX. Now he want to convert every string into a string which he likes. for this, he only delete the character in the string. Now find the ...
```python for _ in range(eval(input())): ins = input().strip() print(sum([a==b for a, b in zip(ins, ins[1:])])) ```
vfc_142471
{ "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\nXXXX\nYYYYY\nXYXYXYXY\nYXYXYX\nXXXYYY", "output": "49790\n49682\n49764\n49923\n49869\n49906\n49630\n49797\n49932\n50316", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/GROUPS
Solve the following coding problem using the programming language python: Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. There are $N$ seats in a row. You are given a string $S$ with length $N$; for each valid $i$, the $i$-th character of $S$ is '0' if the $i$-th seat i...
```python for _ in range(int(input())): s = input() p = s.split('0') print(len(p) - p.count('')) ```
vfc_142480
{ "difficulty": "easy", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/GROUPS", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n000\n010\n101\n01011011011110", "output": "0\n1\n2\n4", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/CFSN2015/problems/PUNBAN
Solve the following coding problem using the programming language python: Like all minions Dave also like to eat bananas. So as to his obsession, he is eating banana, but this time in different way. There are N bananas in dish. Dave wants to eat all of them. He starts eating at speed 1 banana/second. He can increase o...
```python t = int(input()) while t: k = 1 j = 0 n = int(input()) while n > 0: if n <= k: j += 1 n = 0 elif n > 2 * k: j += 2 n = n - 2 * k k += 1 else: j += 2 n = 0 print(j) t -= 1 ```
vfc_142484
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/CFSN2015/problems/PUNBAN", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n2\n4\n", "output": "2\n3\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/648/A
Solve the following coding problem using the programming language python: Профиль горного хребта схематично задан в виде прямоугольной таблицы из символов «.» (пустое пространство) и «*» (часть горы). Каждый столбец таблицы содержит хотя бы одну «звёздочку». Гарантируется, что любой из символов «*» либо находится в ни...
```python def main(): (n, m) = [int(i) for i in input().split()] d = [list(input()) for i in range(n)] a = [0] * m for i in range(m): for j in range(n): if d[j][i] == '*': a[i] += 1 x = y = 0 for i in range(1, m): if a[i] > a[i - 1]: x = max(x, a[i] - a[i - 1]) else: y = max(y, a[i - 1] - a[i])...
vfc_142488
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/648/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6 11\n...........\n.........*.\n.*.......*.\n**.......*.\n**..*...**.\n***********\n", "output": "3 4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 5\n....*\n...**\n..***\n.****\n*****...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/subtraction-and-two-numbers0816/1
Solve the following coding problem using the programming language python: Given two integers A and B.Find out the number of steps required to repeatedly subtract the smaller of the two from the larger until one of them becomes 0. Example 1: Input: A=5,B=13 Output: 6 Explanation: The steps are as follows: (5,13)->(5,8)...
```python class Solution: def repeatedSubtraction(self, A, B): a = 0 while A != 0 and B != 0: if A > B: A = A - B a = a + 1 else: B = B - A a = a + 1 return a ```
vfc_142492
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/subtraction-and-two-numbers0816/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "A=5,B=13", "output": "6", "type": "stdin_stdout" }, { "fn_name": null, "input": "A=5,B=15", "output": "3", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/463/B
Solve the following coding problem using the programming language python: Caisa solved the problem with the sugar and now he is on the way back to home. Caisa is playing a mobile game during his path. There are (n + 1) pylons numbered from 0 to n in this game. The pylon with number 0 has zero height, the pylon with ...
```python n = int(input()) x = 0 r = 0 ph = 0 for h in map(int, input().split()): d = h - ph if d > x: r += d - x x = 0 else: x -= d ph = h print(r) ```
vfc_142502
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/463/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n3 4 3 2 4\n", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n4 4 4\n", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "in...
taco
verifiable_code
https://codeforces.com/problemset/problem/1355/A
Solve the following coding problem using the programming language python: Let's define the following recurrence: $$a_{n+1} = a_{n} + minDigit(a_{n}) \cdot maxDigit(a_{n}).$$ Here $minDigit(x)$ and $maxDigit(x)$ are the minimal and maximal digits in the decimal representation of $x$ without leading zeroes. For example...
```python for _ in range(int(input())): (n, k) = map(int, input().split()) e = [n] while True: a = list(str(n)) if int(min(a)) == 0: break else: n += int(max(a)) * int(min(a)) e.append(n) r = len(e) print(e[r - 1]) if k > r else print(e[k - 1]) ```
vfc_142506
{ "difficulty": "easy", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1355/A", "time_limit": "1 second" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "8\n1 4\n487 1\n487 2\n487 3\n487 4\n487 5\n487 6\n487 7\n", "output": "42\n487\n519\n528\n544\n564\n588\n628\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/682/C
Solve the following coding problem using the programming language python: Alyona decided to go on a diet and went to the forest to get some apples. There she unexpectedly found a magic rooted tree with root in the vertex 1, every vertex and every edge of which has a number written on. The girl noticed that some of th...
```python nn = int(input()) a = [0] + list(map(int, input().split())) E = [[] for _ in range(nn + 1)] for i in range(nn - 1): (p, c) = list(map(int, input().split())) E[i + 2] += [(p, c)] E[p] += [(i + 2, c)] ans = 0 ch = [(1, 0, 0)] while ch: (nom, pre, l) = ch.pop() if l > a[nom]: continue ans += 1 for (x, c...
vfc_142510
{ "difficulty": "medium_hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/682/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "9\n88 22 83 14 95 91 98 53 11\n3 24\n7 -8\n1 67\n1 64\n9 65\n5 12\n6 -80\n3 8\n", "output": "5\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n53 82 15 77 71 23\n5 -77\n6 -73\n2 0\n1 26...
taco
verifiable_code
https://codeforces.com/problemset/problem/913/E
Solve the following coding problem using the programming language python: You are given a boolean function of three variables which is defined by its truth table. You need to find an expression of minimum length that equals to this function. The expression may consist of: Operation AND ('&', ASCII code 38) Operatio...
```python val = '!x&x\nx&y&z\n!z&x&y\nx&y\n!y&x&z\nx&z\n!y&x&z|!z&x&y\n(y|z)&x\n!y&!z&x\n!y&!z&x|x&y&z\n!z&x\n!z&x|x&y\n!y&x\n!y&x|x&z\n!(y&z)&x\nx\n!x&y&z\ny&z\n!x&y&z|!z&x&y\n(x|z)&y\n!x&y&z|!y&x&z\n(x|y)&z\n!x&y&z|!y&x&z|!z&x&y\n(x|y)&z|x&y\n!x&y&z|!y&!z&x\n!y&!z&x|y&z\n!x&y&z|!z&x\n!z&x|y&z\n!x&y&z|!y&x\n!y&x|y&z\n...
vfc_142514
{ "difficulty": "very_hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/913/E", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n00110011\n00000111\n11110000\n00011111\n", "output": "y\n(y|z)&x\n!x\nx|y&z\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n11001110\n", "output": "!y|!z&x\n", "type": "s...
taco
verifiable_code
https://codeforces.com/problemset/problem/219/B
Solve the following coding problem using the programming language python: Polycarpus is an amateur businessman. Recently he was surprised to find out that the market for paper scissors is completely free! Without further ado, Polycarpus decided to start producing and selling such scissors. Polycaprus calculated that ...
```python (p, d) = input().split() p = int(p) d = int(d) ans = p = p + 1 i = 10 while i <= 1000000000000000000: if p % i <= d: ans = p - p % i i *= 10 print(ans - 1) ```
vfc_142518
{ "difficulty": "medium", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/219/B", "time_limit": "1.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "393776794010351632 4138311260892\n", "output": "393775999999999999\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "559198116944738707 0\n", "output": "559198116944738707\n", "t...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/decode-the-pattern1138/1
Solve the following coding problem using the programming language python: Given an integer n. Return the nth row of the following look-and-say pattern. 1 11 21 1211 111221 Look-and-Say Pattern: To generate a member of the sequence from the previous member, read off the digits of the previous member, counting the numbe...
```python class Solution: def lookandsay(self, n): if n == 1: return 1 val = '11' for i in range(n - 2): s = '' c = 1 val = str(val) for i in range(len(val) - 1): if val[i] == val[i + 1]: c += 1 else: s += str(c) + val[i] c = 1 s += str(c) + val[i + 1] val = s retur...
vfc_142523
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/decode-the-pattern1138/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "n = 5", "output": "111221", "type": "stdin_stdout" }, { "fn_name": null, "input": "n = 3", "output": "21", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1607/G
Solve the following coding problem using the programming language python: A known chef has prepared $n$ dishes: the $i$-th dish consists of $a_i$ grams of fish and $b_i$ grams of meat. The banquet organizers estimate the balance of $n$ dishes as follows. The balance is equal to the absolute value of the difference be...
```python for _ in range(int(input())): input() (n, m) = map(int, input().split()) a = [] b = [] for i in range(n): (ai, bi) = map(int, input().split()) a.append(ai) b.append(bi) suma = sum(a) sumb = sum(b) diff = suma - sumb ms = [m] * n ansa = [0] * n ansb = [0] * n for i in range(n): ma = m - b[i...
vfc_142524
{ "difficulty": "hard", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1607/G", "time_limit": "2 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "8\n\n1 5\n3 4\n\n1 6\n3 4\n\n2 2\n1 3\n4 2\n\n2 4\n1 3\n1 7\n\n3 6\n1 7\n1 8\n1 9\n\n3 6\n1 8\n1 9\n30 10\n\n3 4\n3 1\n3 2\n4 1\n\n5 4\n0 7\n6 4\n0 8\n4 1\n5 3\n", "output": "0\n2 3\n1\n3 3\n0\n1 1\n1 1\n2\n1 3\n0 4\n3\n0 6\n...
taco
verifiable_code
Solve the following coding problem using the programming language python: PandeyG, a brilliant tennis player, decided to start a tournament in his colony. Now, since PandeyG is overly optimistic and ambitious - he tries to lure in as many people as he can from his colony for them to participate in his very own knockou...
```python import sys fline = 0 for line in sys.stdin: if fline == 0: fline = 1 continue player = line if player.startswith('0'): print(0) elif len(player) == 1 and player.startswith('1'): print(0) else: player = int(player) - 1 print(player) ```
vfc_142528
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n1\n0\n", "output": "999999\n999998\n55554\n4443\n332\n21\n10\n99998\n9\n12\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n0\n1\n2\n3\n4\n5\n", "output": "222221\n12151514\n2\n...
taco
verifiable_code
https://codeforces.com/problemset/problem/1779/G
Solve the following coding problem using the programming language python: The time has finally come, MKnez and Baltic are to host The Game of the Century. For that purpose, they built a village to lodge its participants. The village has the shape of an equilateral triangle delimited by three roads of length $n$. It i...
```python t = int(input('')) for _ in range(t): n = int(input('')) a = (input(''), input(''), input('')) if a[0][n - 1] == a[1][n - 1] and a[0][n - 1] == a[2][n - 1]: print(0) continue big = [0, 0, 0] for i in (0, 1, 2): for j in range(n - 2, -1, -1): if a[i][j] != a[i][n - 1]: big[i] = j + 1 brea...
vfc_142532
{ "difficulty": "very_hard", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1779/G", "time_limit": "2 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n3\n001\n001\n010\n1\n0\n0\n0\n3\n111\n011\n100\n", "output": "2\n0\n3\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.hackerrank.com/challenges/solve-me-first/problem
Solve the following coding problem using the programming language python: Complete the function solveMeFirst to compute the sum of two integers. Example $a=7$ $b=3$ Return $10$. Function Description Complete the solveMeFirst function in the editor below. solveMeFirst has the following parameters: int a...
```python def solveMeFirst(a, b): return a + b num1 = int(input()) num2 = int(input()) res = solveMeFirst(num1, num2) print(res) ```
vfc_142540
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.hackerrank.com/challenges/solve-me-first/problem", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n3\n", "output": "5\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/strongly-connected-components-kosarajus-algo/1
Solve the following coding problem using the programming language python: Given a Directed Graph with V vertices (Numbered from 0 to V-1) and E edges, Find the number of strongly connected components in the graph. Example 1: Input: Output: 3 Explanation: We can clearly see that there are 3 Strongly Connected Compone...
```python class Solution: def kosaraju(self, V, adj): def time(G): n = len(G) visited = [False for _ in range(n)] time_tab = [0 for _ in range(n)] t = n - 1 def dfsVisit(G, u): nonlocal visited, time_tab, t visited[u] = True for v in G[u]: if not visited[v]: dfsVisit(G, v) ...
vfc_142544
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/strongly-connected-components-kosarajus-algo/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "", "output": "1", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.hackerrank.com/challenges/strange-advertising/problem
Solve the following coding problem using the programming language python: HackerLand Enterprise is adopting a new viral advertising strategy. When they launch a new product, they advertise it to exactly $5$ people on social media. On the first day, half of those $5$ people (i.e., $floor(\frac{5}{2})=2$) like the adv...
```python people = 5 total = 0 n = int(input()) for i in range(n): receive = int(people / 2) total += receive people = receive * 3 print(total) ```
vfc_142545
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.hackerrank.com/challenges/strange-advertising/problem", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n", "output": "9\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/8a644e94faaa94968d8665ba9e0a80d1ae3e0a2d/1
Solve the following coding problem using the programming language python: Given a collection of Intervals, the task is to merge all of the overlapping Intervals. Example 1: Input: Intervals = {{1,3},{2,4},{6,8},{9,10}} Output: {{1, 4}, {6, 8}, {9, 10}} Explanation: Given intervals: [1,3],[2,4] [6,8],[9,10], we have on...
```python class Solution: def overlappedInterval(self, Intervals): i = 0 Intervals.sort() ans = [] while i < len(Intervals): first = Intervals[i][0] last = Intervals[i][1] while i < len(Intervals) - 1 and Intervals[i + 1][0] <= last: last = max(last, Intervals[i + 1][1]) i += 1 ans.append(...
vfc_142558
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/8a644e94faaa94968d8665ba9e0a80d1ae3e0a2d/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "Intervals = {{1,3},{2,4},{6,8},{9,10}}", "output": "{{1, 4}, {6, 8}, {9, 10}}", "type": "stdin_stdout" }, { "fn_name": null, "input": "Intervals = {{6,8},{1,9},{2,4},{4,7}}", "output": "{{1, 9}...
taco
verifiable_code
https://codeforces.com/problemset/problem/1248/A
Solve the following coding problem using the programming language python: DLS and JLS are bored with a Math lesson. In order to entertain themselves, DLS took a sheet of paper and drew $n$ distinct lines, given by equations $y = x + p_i$ for some distinct $p_1, p_2, \ldots, p_n$. Then JLS drew on the same paper sheet...
```python t = int(input()) while t > 0: t -= 1 n = int(input()) p = [int(x) for x in input().split()] m = int(input()) q = [int(x) for x in input().split()] p_o = 0 p_e = 0 for x in p: if x % 2 == 0: p_e += 1 else: p_o += 1 q_o = 0 q_e = 0 for x in q: if x % 2 == 0: q_e += 1 else: q_o += ...
vfc_142568
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1248/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n3\n1 3 2\n2\n0 3\n1\n1\n1\n1\n1\n2\n1\n1\n", "output": "3\n1\n0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "7\n2\n1000000000 0\n2\n1000000000 0\n2\n1 0\n2\n1000000000 0\n2\n1 0\n2\n...
taco
verifiable_code
https://codeforces.com/problemset/problem/476/A
Solve the following coding problem using the programming language python: Dreamoon wants to climb up a stair of n steps. He can climb 1 or 2 steps at each move. Dreamoon wants the number of moves to be a multiple of an integer m. What is the minimal number of moves making him climb to the top of the stairs that sati...
```python (n, m) = input().split(' ') n = int(n) m = int(m) def how_many_moves(n, m): for i in range(n): if m * 2 * i >= n: return m * i total_moves = how_many_moves(n, m) if n >= m: print(total_moves) else: print(-1) ```
vfc_142572
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/476/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10 2\n", "output": "6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 5\n", "output": "-1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "29 7\...
taco
verifiable_code
https://www.codechef.com/problems/CHFSPL
Solve the following coding problem using the programming language python: Read problem statements in [Mandarin], [Bengali], [Russian], and [Vietnamese] as well. Chef has three spells. Their powers are A, B, and C respectively. Initially, Chef has 0 hit points, and if he uses a spell with power P, then his number of h...
```python t = int(input()) for i in range(t): (a, b, c) = map(int, input().split()) print(max(a + b, b + c, a + c)) ```
vfc_142580
{ "difficulty": "easy", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/CHFSPL", "time_limit": "0.5 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n4 2 8\n10 14 18", "output": "12\n32", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/queue-using-stack/1
Solve the following coding problem using the programming language python: Implement a Queue using two stack s1 and s2. Example 1: Input: enqueue(2) enqueue(3) dequeue() enqueue(4) dequeue() Output: 2 3 Explanation: enqueue(2) the queue will be {2} enqueue(3) the queue will be {3 2} dequeue() the poped element will be ...
```python class Queue: def __init__(self): self.s1 = [] self.s2 = [] def enqueue(self, X): self.s1.append(X) def dequeue(self): if len(self.s2) != 0: return self.s2.pop() while len(self.s1) != 0: self.s2.append(self.s1.pop()) return self.s2.pop() ```
vfc_142589
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/queue-using-stack/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "enqueue(2)\nenqueue(3)\ndequeue()\nenqueue(4)\ndequeue()", "output": "2 3", "type": "stdin_stdout" }, { "fn_name": null, "input": "enqueue(2)\ndequeue()\ndequeue()", "output": "2 -1", "ty...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/matrix-exponentiation2711/1
Solve the following coding problem using the programming language python: Given an equation of the form f(n) = f(n-1) + f(n-2) where f(0) = 1, f(1) = 1 , the task is to find the n^{th} term of this sequence. Example 1: Input: n = 3 Output: 3 Explanation: f(3) = f(2) + f(1) = 3 Example 2: Input: n = 2 Output: 2 Expla...
```python class Solution: def multiply(self, a, b): mul = [[0 for x in range(3)] for y in range(3)] for i in range(3): for j in range(3): mul[i][j] = 0 for k in range(3): mul[i][j] += a[i][k] * b[k][j] for i in range(3): for j in range(3): a[i][j] = mul[i][j] % int(1000000000.0 + 7) ret...
vfc_142590
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/matrix-exponentiation2711/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "n = 3", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "n = 2", "output": "2", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/transform-to-prime4635/1
Solve the following coding problem using the programming language python: Given an array of n integers. Find the minimum positive number to be inserted in array, so that sum of all elements of array becomes prime. If sum is already prime, then return 0. Example 1: Input: N=5 arr[] = { 2, 4, 6, 8, 12 } Output: 5 Exp...
```python def isprime(n): if n == 1: return False for i in range(2, int(n ** 0.5) + 1): if n % i == 0: return False return True def minNumber(arr, N): a = sum(arr) i = 0 while True: if isprime(a + i): return i break i += 1 ```
vfc_142591
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/transform-to-prime4635/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": "minNumber", "input": "N=5\narr[] = { 2, 4, 6, 8, 12 }", "output": "5", "type": "function_call" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/102/C
Solve the following coding problem using the programming language python: Once when Gerald studied in the first year at school, his teacher gave the class the following homework. She offered the students a string consisting of n small Latin letters; the task was to learn the way the letters that the string contains ar...
```python import itertools import math import time def timer(f): def tmp(*args, **kwargs): t = time.time() res = f(*args, **kwargs) print('Время выполнения функции: %f' % (time.time() - t)) return res return tmp s = input() n = int(input()) array = [[0, chr(i + ord('a'))] for i in range(26)] for i in range(...
vfc_142592
{ "difficulty": "easy", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/102/C", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "halasouqgfxfcrwhqgllaqiphaxekljz\n87\n", "output": "0\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1462/B
Solve the following coding problem using the programming language python: Polycarp has a string $s[1 \dots n]$ of length $n$ consisting of decimal digits. Polycarp performs the following operation with the string $s$ no more than once (i.e. he can perform operation $0$ or $1$ time): Polycarp selects two numbers $i$ a...
```python a = int(input()) for i in range(a): b = int(input()) c = input() if c[0:4] == '2020': print('YES') elif c[0:3] == '202' and c[b - 1] == '0': print('YES') elif c[0:2] == '20' and c[b - 2:b] == '20': print('YES') elif c[0] == '2' and c[b - 3:b] == '020': print('YES') elif c[b - 4:b] == '2020': ...
vfc_142596
{ "difficulty": "easy", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1462/B", "time_limit": "2 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n8\n20192020\n8\n22019020\n4\n2020\n5\n20002\n6\n729040\n6\n200200\n", "output": "YES\nYES\nYES\nNO\nNO\nNO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n4\n2021\n", "output":...
taco
verifiable_code
https://codeforces.com/problemset/problem/145/C
Solve the following coding problem using the programming language python: Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya has sequence a co...
```python import sys input = sys.stdin.readline def solve(): (n, k) = map(int, input().split()) a = [4, 7] d = dict() idx = 0 for p in range(1, 10): for m in range(1 << p): v = 0 for i in range(p): v = v * 10 + a[m >> i & 1] d[v] = idx idx += 1 c = [0] * idx b = 0 for v in map(int, input().sp...
vfc_142600
{ "difficulty": "hard", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/145/C", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7 4\n1 2 3 4 5 6 7\n", "output": "35\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10 1\n1 2 3 4 5 6 7 8 9 10\n", "output": "10\n", "type": "stdin_stdout" }, { ...
taco
verifiable_code
https://codeforces.com/problemset/problem/569/D
Solve the following coding problem using the programming language python: Little Johnny has recently learned about set theory. Now he is studying binary relations. You've probably heard the term "equivalence relation". These relations are very important in many areas of mathematics. For example, the equality of the tw...
```python def main(): mod = 10 ** 9 + 7 n = int(input()) a = [[0] * (n + 1) for i in range(n + 1)] a[0][0] = 1 for i in range(1, n + 1): a[i][0] = a[i - 1][i - 1] for j in range(1, i + 1): a[i][j] = (a[i][j - 1] + a[i - 1][j - 1]) % mod print(a[n][n - 1]) main() ```
vfc_142612
{ "difficulty": "hard", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/569/D", "time_limit": "1.5 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n", "output": "37\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n", "output": "151\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4000\n",...
taco
verifiable_code
https://codeforces.com/problemset/problem/556/B
Solve the following coding problem using the programming language python: Andrewid the Android is a galaxy-famous detective. He is now investigating a case of frauds who make fake copies of the famous Stolp's gears, puzzles that are as famous as the Rubik's cube once was. Its most important components are a button an...
```python n = int(input()) arr = list(map(int, input().split())) r = n - arr[0] p = 1 c = -1 for i in range(n): if p == 1: t = (arr[i] + r) % n else: t = (n - (r - arr[i])) % n p = -p if t > c: c = t else: print('No') break else: print('Yes') ```
vfc_142624
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/556/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1 0 0\n", "output": "Yes\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n4 2 1 4 3\n", "output": "Yes\n", "type": "stdin_stdout" }, { "fn_name": null, ...
taco
verifiable_code
https://codeforces.com/problemset/problem/334/B
Solve the following coding problem using the programming language python: Gerald is very particular to eight point sets. He thinks that any decent eight point set must consist of all pairwise intersections of three distinct integer vertical straight lines and three distinct integer horizontal straight lines, except fo...
```python s = set() w = set() d = dict() for _ in range(8): l = list(map(int, input().split())) s.add(l[0]) w.add(l[1]) if l[0] in d: d[l[0]].append(l[1]) d[l[0]].sort() else: d[l[0]] = list() d[l[0]].append(l[1]) if len(d) > 3: print('ugly') exit() if len(s) < 3 or len(w) < 3 or len(s) > 3 or (len(w)...
vfc_142628
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/334/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "0 0\n0 1\n0 2\n1 0\n1 2\n2 0\n2 1\n2 2\n", "output": "respectable\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "0 0\n1 0\n2 0\n3 0\n4 0\n5 0\n6 0\n7 0\n", "output": "ugly\n", ...
taco
verifiable_code
https://www.codechef.com/CFUN2020/problems/CODSTAN6
Solve the following coding problem using the programming language python: Recently Rocky had participated in coding competition and he is sharing one of the problem with you which he was unable to solve. Help Rocky in solving the problem. Suppose the alphabets are arranged in a row starting with index 0$0$ from AtoZ$A...
```python s = input().strip() start_w = 27 w_dict = {} words = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'] for word in words: w_dict[word] = start_w start_w = start_w - 1 total_wt = 0 for c in s: total_wt = total_wt + w_dict[c] pr...
vfc_142633
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/CFUN2020/problems/CODSTAN6", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "A\nAND\n", "output": "27\n65\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/NUMCOMP1
Solve the following coding problem using the programming language python: Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. You are given all $N - 1$ integers in the range $[2, N]$. In each step, you choose $2$ distinct integers and if they share a common factor greater th...
```python from bisect import bisect_right def Sieve(n): prime = [True for i in range(n + 1)] p = 2 while p * p <= n: if prime[p] == True: for i in range(p * p, n + 1, p): prime[i] = False p += 1 prime[2] = False lst = [] for p in range(2, n + 1): if prime[p]: lst.append(p) return lst m = 10 ** ...
vfc_142641
{ "difficulty": "medium_hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/NUMCOMP1", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n2\n4\n8", "output": "1\n2\n3", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/202/C
Solve the following coding problem using the programming language python: Consider some square matrix A with side n consisting of zeros and ones. There are n rows numbered from 1 to n from top to bottom and n columns numbered from 1 to n from left to right in this matrix. We'll denote the element of the matrix which i...
```python from sys import stdin import math def make_dp(): dp = [0] * 1001 dp[1] = 1 dp[3] = 5 for i in range(5, 100, 2): dp[i] = dp[i - 2] + i + i - 2 return dp x = int(stdin.readline().strip()) if x == 3: print(5) exit() dp = make_dp() for i in range(1, len(dp)): if x <= dp[i]: print(i) break ```
vfc_142645
{ "difficulty": "medium_hard", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/202/C", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "61\n", "output": "11", "type": "stdin_stdout" }, { "fn_name": null, "input": "13\n", "output": "5", "type": "stdin_stdout" }, { "fn_name": null, "input": "38\n", ...
taco
verifiable_code
https://codeforces.com/problemset/problem/1107/D
Solve the following coding problem using the programming language python: You are given a binary matrix $A$ of size $n \times n$. Let's denote an $x$-compression of the given matrix as a matrix $B$ of size $\frac{n}{x} \times \frac{n}{x}$ such that for every $i \in [1, n], j \in [1, n]$ the condition $A[i][j] = B[\lce...
```python import sys hex2bin = [''] * 256 hex2bin[ord('0')] = '0000' hex2bin[ord('1')] = '0001' hex2bin[ord('2')] = '0010' hex2bin[ord('3')] = '0011' hex2bin[ord('4')] = '0010' hex2bin[ord('5')] = '0010' hex2bin[ord('6')] = '0110' hex2bin[ord('7')] = '0111' hex2bin[ord('8')] = '1000' hex2bin[ord('9')] = '1001' hex2bin[...
vfc_142649
{ "difficulty": "medium_hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1107/D", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "8\nE7\nE7\nE7\n00\n00\nE7\nE7\nE7\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n7\nF\nF\nF\n", "output": "1\n", "type": "stdin_stdout" }, { ...
taco
verifiable_code
https://www.codechef.com/problems/CHEFQUER
Solve the following coding problem using the programming language python: Read problem statements in [Mandarin Chinese], [Russian], and [Vietnamese] as well. You are given a sequence $A_{1}, A_{2}, \ldots, A_{N}$. Chef wants you to handle $Q$ queries. There are two types of queries: 1 L R X: for each $i$ ($L ≤ i ≤ R$...
```python class Ftree: def __init__(self, N): self.st = [0] * (N + 1) self.n = N def Update(self, l, r, diff): while l <= self.n: self.st[l] += diff l += l & -l r += 1 while r <= self.n: self.st[r] -= diff r += r & -r def Query(self, i): sum = 0 while i > 0: sum += self.st[i] i -= ...
vfc_142654
{ "difficulty": "medium_hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/CHEFQUER", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 4\n1 10 3 6 5\n1 1 3 5\n2 3\n1 4 5 7\n2 5", "output": "52\n69", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1475/E
Solve the following coding problem using the programming language python: Masha works in an advertising agency. In order to promote the new brand, she wants to conclude contracts with some bloggers. In total, Masha has connections of $n$ different bloggers. Blogger numbered $i$ has $a_i$ followers. Since Masha has a ...
```python import sys import math def fn(n, k, a): h = [] a.sort(reverse=True) for i in range(k): h.append(a[i]) h1 = h.count(min(h)) h2 = a.count(min(h)) p = 1 for i in range(h1): p = p * (h2 - i) for i in range(h1): p = p // (h1 - i) return p % 1000000007 input = sys.stdin.read() data = list(map(int, i...
vfc_142658
{ "difficulty": "medium_hard", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1475/E", "time_limit": "2 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n4 3\n1 3 1 2\n4 2\n1 1 1 1\n2 1\n1 2\n", "output": "2\n6\n1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n4 3\n1 3 1 2\n4 2\n1 2 1 1\n2 1\n1 2\n", "output": "2\n3\n1\n", ...
taco
verifiable_code
https://www.codechef.com/LOCAPR16/problems/ACDEMY
Solve the following coding problem using the programming language python: Sherlock Holmes has decided to start a new academy to some of the young lads. He has conducted several tests and finally selected N equally brilliant students.Now he don't know whether to train all the N students or not. Now since Holmes was in...
```python t = eval(input()) for i in range(t): n = eval(input()) a = list(map(int, input().split())) cnt = 2 cnt1 = 2 ll = len(a) if ll < 3: cnt1 = ll else: for j in range(2, ll): if a[j - 1] + a[j - 2] == a[j]: cnt += 1 cnt1 = max(cnt1, cnt) else: cnt1 = max(cnt1, cnt) cnt = 2 print(c...
vfc_142662
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/LOCAPR16/problems/ACDEMY", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n5\n2 3 5 1 2\n3\n1 2 3\n", "output": "3\n3\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/smaller-on-left20360700/1
Solve the following coding problem using the programming language python: Given an array arr[ ] of N positive integers, the task is to find the greatest element on the left of every element in the array which is strictly smaller than itself, if this element does not exist for an index print "-1". Example 1: Input: N =...
```python def Smallestonleft(arr, n): ans = [] s = [] from bisect import bisect_left def BinarySearch(a, x): i = bisect_left(a, x) if i: return i - 1 else: return -1 res = [-1] * (n + 1) lst = [] lst.append(arr[0]) for i in range(1, n): idx = BinarySearch(lst, arr[i]) if idx != -1: res[i] = ...
vfc_142666
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/smaller-on-left20360700/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": "Smallestonleft", "input": "N = 5\r\narr[] = {2, 3, 4, 5, 1}", "output": "-1 2 3 4 -1", "type": "function_call" }, { "fn_name": "Smallestonleft", "input": "N = 3\r\narr[] = {1, 2, 3}", "output": "-1 1 2", ...
taco
verifiable_code
https://www.hackerrank.com/challenges/binary-search-tree-insertion/problem
Solve the following coding problem using the programming language python: You are given a pointer to the root of a binary search tree and values to be inserted into the tree. Insert the values into their appropriate position in the binary search tree and return the root of the updated binary tree. You just have to com...
```python class Node: def __init__(self, info): self.info = info self.left = None self.right = None self.level = None def __str__(self): return str(self.info) def preOrder(a): if a == None: return print(a.info, end=' ') try: preOrder(a.left.root) except AttributeError: print('', end='') try: ...
vfc_142667
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.hackerrank.com/challenges/binary-search-tree-insertion/problem", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": " 4\n / \\n 2 7\n / \\n 1 3\n", "output": " 4\n / \\n 2 7\n / /\n 1 3 6\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/577/C
Solve the following coding problem using the programming language python: Vasya and Petya are playing a simple game. Vasya thought of number x between 1 and n, and Petya tries to guess the number. Petya can ask questions like: "Is the unknown number divisible by number y?". The game is played by the following rules:...
```python def get_primes(n): numbers = set(range(n, 1, -1)) primes = [] while numbers: p = numbers.pop() primes.append(p) numbers.difference_update(set(range(p * 2, n + 1, p))) return primes n = int(input()) l = get_primes(n + 1) ans = [] for x in l: p = x while p <= n: ans.append(p) p *= x print(len(an...
vfc_142677
{ "difficulty": "medium", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/577/C", "time_limit": "1.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "784\n", "output": "160\n2 4 8 16 32 64 128 256 512 3 9 27 81 243 729 5 25 125 625 7 49 343 11 121 13 169 17 289 19 361 23 529 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163...
taco
verifiable_code
https://codeforces.com/problemset/problem/38/C
Solve the following coding problem using the programming language python: The blinds are known to consist of opaque horizontal stripes that can be rotated thus regulating the amount of light flowing in the room. There are n blind stripes with the width of 1 in the factory warehouse for blind production. The problem is...
```python (m, l) = map(int, input().split()) a = list(map(int, input().split())) print(max((i * sum((ai // i for ai in a)) for i in range(l, 101)))) ```
vfc_142681
{ "difficulty": "medium", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/38/C", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "93 10\n6 47 6 89 21 91 51 72 32 48 54 89 36 12 25 38 58 62 54 16 5 52 52 85 67 33 81 72 6 42 91 16 29 78 56 62 75 48 69 12 89 34 27 15 7 80 14 57 29 6 80 46 64 94 83 96 1 42 11 41 15 26 17 36 44 11 68 73 93 45 73 35 91 14 84 48 7 8...
taco
verifiable_code
https://www.codechef.com/BYTE2016/problems/BYTES11
Solve the following coding problem using the programming language python: We all know how great ABD aka AB-DE-VILLIERS is. However his team mates were jealous of him and posed a problem for him to solve.The problem description is as follows : Given an array of integers,find the length of the largest subarray(contiguo...
```python n = eval(input()) a = list(map(int, input().split())) c = m = 0 maxi = max(a) for i in range(n): if a[i] == maxi: c += 1 m = max(c, m) else: c = 0 print(m) ```
vfc_142687
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/BYTE2016/problems/BYTES11", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n2 4 8 3\n", "output": "1\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/return-two-prime-numbers2509/1
Solve the following coding problem using the programming language python: Given an even number N (greater than 2), return two prime numbers whose sum will be equal to given number. There are several combinations possible. Print only the pair whose minimum value is the smallest among all the minimum values of pairs and...
```python class Solution: def primeDivision(self, N): def check_prime(n): for i in range(2, int(n ** 0.5) + 1): if n % i == 0: return False return True for i in range(N - 2, 1, -1): if check_prime(i) and check_prime(N - i): return (N - i, i) break ```
vfc_142695
{ "difficulty": "medium_hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/return-two-prime-numbers2509/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 74", "output": "12", "type": "stdin_stdout" }, { "fn_name": null, "input": "4", "output": "19", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/FREQARRRET
Solve the following coding problem using the programming language python: Consider an array A consisting of N positive elements. The *frequency array* of A is the array B of size N such that B_{i} = *frequency* of element A_{i} in A. For example, if A = [4, 7, 4, 11, 2, 7, 7], the *frequency array* B = [2, 3, 2, 1, 1...
```python import numpy as np def inp(): return int(input()) def st(): return input().rstrip('\n') def lis(): return list(map(int, input().split())) def ma(): return map(int, input().split()) def lexsmall(freqarr): for j in np.unique(freqarr): if freqarr.count(j) % j != 0: print(-1) return num = 1 di...
vfc_142696
{ "difficulty": "medium_hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/FREQARRRET", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n5\n2 3 3 3 2\n5\n1 1 1 1 1\n5\n5 5 5 5 5\n3\n1 2 4\n8\n1 3 2 3 2 2 2 3", "output": "1 2 2 2 1\n1 2 3 4 5\n1 1 1 1 1\n-1\n1 2 3 2 3 4 4 2\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/front-back-transformation1659/1
Solve the following coding problem using the programming language python: Given a string S, consisting only of english alphabets, replace all the alphabets with the alphabets occuring at the same position when counted in reverse order of alphabets. For example, 'a' would be replaced by 'z', 'b' by 'y', 'c' by 'x' and ...
```python class Solution: def convert(self, s): ans = '' for i in s: if ord('a') <= ord(i) and ord(i) <= ord('z'): i = chr(ord('z') - (ord(i) - ord('a'))) elif ord('A') <= ord(i) and ord(i) <= ord('Z'): i = chr(ord('Z') - (ord(i) - ord('A'))) ans += i return ans ```
vfc_142700
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/front-back-transformation1659/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "S = \"Hello\"", "output": "Svool", "type": "stdin_stdout" }, { "fn_name": null, "input": "S = \"GfG\"", "output": "TuT", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/print-table0303/1
Solve the following coding problem using the programming language python: Create the multiplication table of a given number N and return the table as an array. Example 1: Input: N = 9 Output: 9 18 27 36 45 54 63 72 81 90 Explanation: The table of 9 is the output whose 1st term is 9 and the 10th term is 90. Example 2:...
```python class Solution: def getTable(self, N): tables = [] for i in range(1, 11): tables.append(N * i) return tables ```
vfc_142701
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/print-table0303/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 9", "output": "9 18 27 36 45 54 63 72 81 90", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: Solve the mystery. Input: String which consists of words(all the characters of any word are lower case letters) and punctuation marks(consists of {'.' , ',' , '?' , '!'}). Also every input string consists of one '*' in it. It is guaranteed tha...
```python T=eval(input()) while T>0: l = input() st="" for char in l: if char.isalnum() or char=='*': st=st+char le = len(st) for i in range(0,le/2): if(st[i]=='*' or st[le-1-i]=='*'): if(st[i]=='*'): print(st[le-1-i]) else: print(st[i]) T=T-1 ```
vfc_142702
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "981\nr.o,k.y!?y!k o!*\nr!m w!r ,w?m!*\ne s!r b.n?.n,b!r.*?e\nl r?l?n,p p!f k o,k!c?q,n,n u!w?swun*qckokfppnlrl\nb q.l,j?v!w!d?q.?q d w v.j l?*!b\np.n!n?w,q.j,a a?r w o,s.c ,s.o?w?r?*.a j,q wnnp\nq,a e !*,a?q\nm?n?z,k!q?x.j!k,t,y?ac...
taco
verifiable_code
Solve the following coding problem using the programming language python: Write a program which reads a rectangle and a circle, and determines whether the circle is arranged inside the rectangle. As shown in the following figures, the upper right coordinate $(W, H)$ of the rectangle and the central coordinate $(x, y)$...
```python (a, b, x, y, r) = map(int, input().split()) if r <= y and y <= b - r and (r <= x) and (x <= a - r): print('Yes') else: print('No') ```
vfc_142706
{ "difficulty": "unknown_difficulty", "memory_limit": "134.217728 megabytes", "memory_limit_bytes": null, "problem_url": null, "time_limit": "1.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 4 2 2 1", "output": "No\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 8 2 0 0", "output": "Yes\n", "type": "stdin_stdout" }, { "fn_name": null, "input...
taco
verifiable_code
https://codeforces.com/problemset/problem/181/D
Solve the following coding problem using the programming language python: Let's consider one interesting word game. In this game you should transform one word into another through special operations. Let's say we have word w, let's split this word into two non-empty parts x and y so, that w = xy. A split operation i...
```python MOD = int(1000000000.0) + 7 a = input() b = input() k = int(input()) if len(a) != len(b): print(0) exit() a = a + a x = 0 y = 0 for i in range(len(a) // 2): flag = 1 for j in range(len(b)): if a[j + i] != b[j]: flag = 0 break if flag == 1: x += 1 else: y += 1 flag = 0 for i in range(len(b)):...
vfc_142710
{ "difficulty": "medium_hard", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/181/D", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "aaeddddadbcacbdccaeeeddecadbecbbcebdcdbcddcadcadccecccecdbabd\nadbecbbcebdcdbcddcadcadccecccecdbabdaaeddddadbcacbdccaeeeddec\n55400\n", "output": "471327413\n", "type": "stdin_stdout" }, { "fn_name": null,...
taco
verifiable_code
Solve the following coding problem using the programming language python: Please find the greatest common divisor of two natural numbers. A clue is: The Euclid's algorithm is a way to resolve this task. Input The input file consists of several lines with pairs of two natural numbers in each line. The numbers do no...
```python import sys def gcd(a, b): if b: return gcd(b, a % b) else: return a List = [] for i in sys.stdin: List.append(i) for data in List: print(gcd(int(data.split()[0]), int(data.split()[1]))) ```
vfc_142715
{ "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": "57 38\n19 84", "output": "19\n1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "57 38\n6 84", "output": "19\n6\n", "type": "stdin_stdout" }, { "fn_name": null, ...
taco
verifiable_code
https://codeforces.com/problemset/problem/1559/C
Solve the following coding problem using the programming language python: The city where Mocha lives in is called Zhijiang. There are $n+1$ villages and $2n-1$ directed roads in this city. There are two kinds of roads: $n-1$ roads are from village $i$ to village $i+1$, for all $1\leq i \leq n-1$. $n$ roads can be d...
```python N = int(input()) for _ in range(N): n = int(input()) nums = [0] + list(map(int, input().strip().split())) + [1] for (i, (cur_r, next_r)) in enumerate(zip(nums[:], nums[1:])): if cur_r == 0 and next_r == 1: break out_nums = list(range(1, i + 1)) + [n + 1] + list(range(i + 1, n + 1)) print(' '.join(ma...
vfc_142719
{ "difficulty": "easy", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1559/C", "time_limit": "1 second" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n3\n0 1 0\n3\n1 1 0\n", "output": "1 4 2 3 \n4 1 2 3 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1\n1\n1\n0\n", "output": "2 1 \n1 2 \n", "type": "stdin_stdout" }...
taco
verifiable_code
Solve the following coding problem using the programming language python: The huge maze The Squares has been newly completed in the famous theme park. Evacuation drills must be conducted under the guidance of the fire department, but the time required for the drills cannot be predicted due to the huge maze. Therefore,...
```python from sys import stdin def main(): head = [[8, 1, 2, 4], [1, 2, 4, 8], [2, 4, 8, 1], [4, 8, 1, 2]] while True: (W, H) = map(int, stdin.readline().split()) m = [[0] * W for _ in range(H)] ps = [] if not (W or H): break for h in range(H): s = stdin.readline() for w in range(W): if s[w] ...
vfc_142723
{ "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 3\n##########\n#E.......X\n##########\n4 4\n####\n#N.#\n#..X\n####\n5 5\n#####\n#N..#\n###.X\n#S..#\n#####\n6 6\n######\n#..#X#\n#.EE.#\n####N#\n#....#\n######\n8 8\n##X#####\n#....E.#\n#####.##\n#.#...##\n#.W.#..#\n#-#.N#.X\n#X...
taco
verifiable_code
https://www.hackerrank.com/challenges/degree-of-an-algebraic-number/problem
Solve the following coding problem using the programming language python: A number is algebraic if it is a root of some nonzero polynomial with integer coefficients. A number is transcendental if it is not algebraic. For example, ${11}$, ${i}$, $\sqrt[3]{2}$ and $\phi$ (golden ratio) are algebraic, because they are r...
```python MAXA = 10 ** 7 def main(): ncases = int(input()) for _ in range(ncases): n = int(input()) a = [int(f) for f in input().split()] assert n == len(a) print(mindegree(a)) def mindegree(a): factors = [set(factoroddpow(item)) for item in a] adjoins = 0 for (i, factor) in enumerate(factors): if len(...
vfc_142727
{ "difficulty": "hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.hackerrank.com/challenges/degree-of-an-algebraic-number/problem", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1\n4\n3\n2 4 4\n4\n1 2 3 5\n", "output": "1\n2\n8\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: Jal Mahal Lake is famous tourist place in Jaipur. The lake has floating planks in a straight line. The planks are currently not attached to each other, and there may be gaps between some of them. You have to push them all together and connect th...
```python t=eval(input()) for i in range(0,t): n=eval(input()) pos=input() leng=input() pos=pos.split() leng=leng.split() pos=list(map(int,pos)) leng=list(map(int,leng)) diff=[] adiff=[] for j in range(0,n): diff.append([pos[j],leng[j]]) diff.sort() #print diff for j in range(0,n-1): #print diff[j+1][0...
vfc_142731
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n4\n1 3 10 20\n2 2 5 3\n3\n100 50 1\n10 2 1\n5\n4 10 100 13 80\n5 3 42 40 9\n10\n5606451 63581020 81615191 190991272 352848147 413795385 468408016 615921162 760622952 791438427\n42643329 9909484 58137134 99547272 39849232 1514670...
taco
verifiable_code
https://www.codechef.com/problems/HXOR
Solve the following coding problem using the programming language python: Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. You are given a sequence $A_{1}, A_{2}, \ldots, A_{N}$ and you have to perform the following operation exactly $X$ times: Choose two integer...
```python for _ in range(int(input())): (n, x) = map(int, input().split()) arr = list(map(int, input().split())) rem = 0 for i in range(n - 1): a = arr[i] d = a & rem (a, rem) = (a ^ d, rem ^ d) b = bin(a).count('1') if b <= x: x -= b rem ^= a a = 0 elif x > 0: d = 0 for j in range(31, -1...
vfc_142735
{ "difficulty": "medium_hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/HXOR", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n3 3\n2 2 3", "output": "0 0 3", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1521/B
Solve the following coding problem using the programming language python: Nastia has received an array of $n$ positive integers as a gift. She calls such an array $a$ good that for all $i$ ($2 \le i \le n$) takes place $gcd(a_{i - 1}, a_{i}) = 1$, where $gcd(u, v)$ denotes the greatest common divisor (GCD) of integer...
```python from math import gcd for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) print(n - 1) (val, idx) = min(((val, idx) for (idx, val) in enumerate(a))) counter = 1 for i in range(idx + 1, n): a[i] = val + counter counter += 1 print(idx + 1, i + 1, val, a[i]) counter = 1...
vfc_142739
{ "difficulty": "easy", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1521/B", "time_limit": "2 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n5\n9 6 3 11 15\n3\n7 5 13\n", "output": "4\n3 1 3 5\n3 2 3 4\n3 4 3 4\n3 5 3 5\n2\n2 1 5 6\n2 3 5 6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n5\n9 6 3 11 15\n3\n7 5 13\n", ...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/matrix-game-20508/1
Solve the following coding problem using the programming language python: Given a string S which contains only small letters. The task is to make a square matrix from string S. Then perform the following operations. 1. In each column delete the characters which occur more than one. 2. Column-wise sort the remaining ch...
```python class Solution: def matrixGame(self, S): if len(S) == 1: return S elif len(S) < 5: return 0 l = len(S) import math k = int(math.sqrt(l)) M = [] for i in range(0, len(S), k): M.append(S[i:i + k]) W = [] for i in range(k): b = '' for j in range(k): b += M[j][i] g = '' ...
vfc_142744
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/matrix-game-20508/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "S = \"adgkbdhlceilcfjm\"", "output": "abefgjhikm", "type": "stdin_stdout" }, { "fn_name": null, "input": "S = \"abcabcabc\"", "output": "0", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/847/L
Solve the following coding problem using the programming language python: In the computer network of the Berland State University there are n routers numbered from 1 to n. Some pairs of routers are connected by patch cords. Information can be transmitted over patch cords in both direction. The network is arranged in s...
```python import math import sys read = sys.stdin.readline n = int(read()) sub = [[] for _ in range(n)] for i in range(n): data = read().strip() for j in data.split('-'): tree = list(map(int, j.split(':')[1].split(','))) for k in range(len(tree)): tree[k] -= 1 sub[i].append(sorted(tree)) sub[i].sort() dp = ...
vfc_142745
{ "difficulty": "very_hard", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/847/L", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n2:2,3-1:4\n3:4,3,1\n3:2,4,1\n1:2-2:1,3\n", "output": "-1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n2:7,4-2:5,8-1:3-1:6-1:2-2:10,9\n9:6,7,3,4,10,8,9,5,1\n9:2,1,7,6,9,4,8,10,5\n...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/arrange-balls0052/1
Solve the following coding problem using the programming language python: There are p balls of type P, q balls of type Q and r balls of type R. Using the balls we want to create a straight line such that no two balls of same type are adjacent. Example 1: Input: p = 2, q = 2, r = 2 Output: 30 Explanation: There are 3...
```python MAX = 101 dp = [[[[-1] * 4 for i in range(MAX)] for j in range(MAX)] for k in range(MAX)] def countWayss(p, q, r, last): if p < 0 or q < 0 or r < 0: return 0 if p == 1 and q == 0 and (r == 0) and (last == 0): return 1 if p == 0 and q == 1 and (r == 0) and (last == 1): return 1 if p == 0 and q == 0 ...
vfc_142749
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/arrange-balls0052/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "p = 2, q = 2, r = 2", "output": "30", "type": "stdin_stdout" }, { "fn_name": null, "input": "p = 1, q = 1, r = 1", "output": "6", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/minimum-swaps/1
Solve the following coding problem using the programming language python: Given an array of n distinct elements. Find the minimum number of swaps required to sort the array in strictly increasing order. Example 1: Input: nums = {2, 8, 5, 4} Output: 1 Explaination: swap 8 with 4. Example 2: Input: nums = {10, 19, 6, 3,...
```python from collections import OrderedDict class Solution: def minSwaps(self, nums): dic = OrderedDict() for i in range(len(nums)): dic[nums[i]] = i sorted_dic = OrderedDict(sorted(dic.items())) swaps = 0 for (i, v) in enumerate(sorted_dic.values()): if i != v: (nums[i], nums[v]) = (nums[v], n...
vfc_142750
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/minimum-swaps/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "nums = {2, 8, 5, 4}", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "nums = {10, 19, 6, 3, 5}", "output": "2", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: On Unix computers, data is stored in directories. There is one root directory, and this might have several directories contained inside of it, each with different names. These directories might have even more directories contained inside of them...
```python for it in range(eval(input())): n, m = list(map(int, input().split())) ans = 0 f = {'':[]} for i in range(n): k=input().split('/') while len(k)>1: l=k.pop() s='/'.join(k) if s not in f: f[s] = [] if l not in f[s]: f[s].append(l) for i in range(m): k=input().split('/') while le...
vfc_142751
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n0 2\n/home/gcj/finals\n/home/gcj/quals\n2 1\n/chicken\n/chicken/egg\n/chicken\n1 3\n/a\n/a/b\n/a/c\n/b/b", "output": "Case #1: 4\nCase #2: 0", "type": "stdin_stdout" }, { "fn_name": null, "input":...
taco
verifiable_code
https://www.hackerrank.com/challenges/triangle-numbers/problem
Solve the following coding problem using the programming language python: Given a triangle of numbers where each number is equal to the sum of the three numbers on top of it, find the first even number in a row. Explanatory Note: The vertex of the triangle (at the top) is 1. The structure of the triangle is shown b...
```python def number(n): if n == 1 or n == 2: return -1 elif n % 2 == 1: return 2 elif n % 4 == 0: return 3 else: return 4 n = int(input()) row_num = [] for i in range(n): row_num.append(int(input())) for j in range(n): print(number(row_num[j])) ```
vfc_142755
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.hackerrank.com/challenges/triangle-numbers/problem", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n3\n4\n", "output": "2\n3\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.hackerrank.com/challenges/wet-shark-and-42/problem
Solve the following coding problem using the programming language python: As punishment for attacking Sunland, Wet Shark is now forced to walk on a line of numbered squares, starting from $\mbox{1}$ and going to infinity. Wet Shark initially has a strength of $\mbox{S}$. To make the experience harder for Wet Shark, ea...
```python def calc(x): MOD = 10 ** 9 + 7 twenties = x // 20 rem = x % 20 if rem == 0: return (42 * twenties - 2) % MOD else: return (42 * twenties + 2 * rem) % MOD tcs = int(input()) for i in range(tcs): print(calc(int(input()))) ```
vfc_142760
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.hackerrank.com/challenges/wet-shark-and-42/problem", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n3\n4\n", "output": "6 \n8\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/XORK
Solve the following coding problem using the programming language python: Given an array A having N elements, a subarray S of A is called good if XOR(S) ≥ K, where XOR(S) denotes the [bitwise XOR] of all the elements of the subarray S. Find the length of the smallest subarray S which is good. If there is no good suba...
```python T = int(input()) for _ in range(T): (N, K) = map(int, input().split()) A = list(map(int, input().split())) def length(getMask, ignoreMask): assert getMask & ignoreMask == 0 C = [0] D = {0: 0} res = float('inf') for (i, elt) in enumerate(A): presum = C[-1] ^ elt & ~ignoreMask C.append(presu...
vfc_142764
{ "difficulty": "very_hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/XORK", "time_limit": "2 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n5 15\n1 4 2 8 1\n5 7\n1 4 2 8 1\n5 20\n1 4 2 8 1", "output": "4\n1\n-1", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/711/C
Solve the following coding problem using the programming language python: ZS the Coder and Chris the Baboon has arrived at Udayland! They walked in the park where n trees grow. They decided to be naughty and color the trees in the park. The trees are numbered with integers from 1 to n from left to right. Initially, t...
```python INF = 10 ** 18 MX_SZ = 112 dp = [[[INF for k in range(MX_SZ)] for j in range(MX_SZ)] for i in range(MX_SZ)] best = [[[(INF, INF) for k in range(MX_SZ)] for j in range(MX_SZ)] for i in range(MX_SZ)] def read(): return [int(x) for x in input().split()] (n, m, k_res) = read() arr = read() cost = [] for i in ra...
vfc_142768
{ "difficulty": "medium_hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/711/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 2 2\n0 0 0\n1 2\n3 4\n5 6\n", "output": "10", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 2 2\n2 1 2\n1 3\n2 4\n3 5\n", "output": "-1", "type": "stdin_stdout" }, { ...
taco
verifiable_code
https://codeforces.com/problemset/problem/415/A
Solve the following coding problem using the programming language python: Mashmokh works in a factory. At the end of each day he must turn off all of the lights. The lights on the factory are indexed from 1 to n. There are n buttons in Mashmokh's room indexed from 1 to n as well. If Mashmokh pushes button with index...
```python from array import * from itertools import * (n, m) = list(map(int, input().split())) bs = map(int, input().split()) a = array('i', repeat(0, n)) for b in bs: for i in range(b - 1, n): if a[i] != 0: break a[i] = b for i in a: print(i, end=' ') ```
vfc_142772
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/415/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 4\n4 3 1 2\n", "output": "1 1 3 4 4 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 5\n5 4 3 2 1\n", "output": "1 2 3 4 5 \n", "type": "stdin_stdout" }, { "f...
taco
verifiable_code
https://codeforces.com/problemset/problem/727/B
Solve the following coding problem using the programming language python: Vasily exited from a store and now he wants to recheck the total price of all purchases in his bill. The bill is a string in which the names of the purchases and their prices are printed in a row without any spaces. Check has the format "name_1p...
```python s = input() a = 0 r = '' l = [] for i in s: if 48 <= ord(i) <= 57 or ord(i) == 46: r += i elif len(r) > 0: if len(r) > 3 and r[-3] == '.': a += float(''.join(r[:-3].split('.')) + r[-3:]) else: a += float(''.join(r.split('.')) + '.00') r = '' if len(r) > 0: if len(r) > 3 and r[-3] == '.': a ...
vfc_142776
{ "difficulty": "medium_hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/727/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "chipsy48.32televizor12.390\n", "output": "12.438.32\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "a1b2c3.38\n", "output": "6.38\n", "type": "stdin_stdout" }, { ...