source
stringclasses
4 values
task_type
stringclasses
1 value
in_source_id
stringlengths
0
138
problem
stringlengths
219
13.2k
gold_standard_solution
stringlengths
0
413k
problem_id
stringlengths
5
10
metadata
dict
verification_info
dict
taco
verifiable_code
https://codeforces.com/problemset/problem/1141/G
Solve the following coding problem using the programming language python: Treeland consists of $n$ cities and $n-1$ roads. Each road is bidirectional and connects two distinct cities. From any city you can get to any other city by roads. Yes, you are right — the country's topology is an undirected tree. There are som...
```python (n, k) = map(int, input().split(' ')) deg = [0] * n neighbors = [[] for i in range(n)] edges = [] for i in range(n - 1): (a, b) = map(int, input().split(' ')) neighbors[a - 1].append(b - 1) neighbors[b - 1].append(a - 1) deg[a - 1] += 1 deg[b - 1] += 1 edges.append((a - 1, b - 1)) deg = list(sorted(deg)...
vfc_139657
{ "difficulty": "hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1141/G", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6 2\n1 4\n4 3\n3 5\n3 6\n5 2\n", "output": "2\n1 2 1 1 2 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 2\n3 1\n1 4\n1 2\n", "output": "1\n1 1 1 ", "type": "stdin_stdout" ...
taco
verifiable_code
https://codeforces.com/problemset/problem/1282/A
Solve the following coding problem using the programming language python: Polycarp lives on the coordinate axis $Ox$ and travels from the point $x=a$ to $x=b$. It moves uniformly rectilinearly at a speed of one unit of distance per minute. On the axis $Ox$ at the point $x=c$ the base station of the mobile operator is...
```python T = int(input()) for test in range(T): (a, b, c, r) = map(int, input().split()) if a > b: (a, b) = (b, a) if c - r > b or c + r < a: print(b - a) else: bottom = max(min(c - r, b) - a, 0) upper = max(b - max(c + r, a), 0) time = bottom + upper print(time) ```
vfc_139662
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1282/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "9\n1 10 7 1\n3 3 3 0\n8 2 10 4\n8 2 10 100\n-10 20 -17 2\n-3 2 2 0\n-3 1 2 0\n2 3 2 3\n-1 3 -2 2\n", "output": "7\n0\n4\n0\n30\n5\n4\n0\n3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "9...
taco
verifiable_code
Solve the following coding problem using the programming language python: In the Mathematical world of Dr. Ramanujam, every new student must have to pass a exam to take the classes of Advance mathematics from Dr. Ramanujam. One day Ram wants to have classes of Advance mathematics, so he arrived at class of Dr. Ramanuj...
```python T=int(input()) for t in range(T): exp=input() exp+="+" val=0; for i in range(1,len(exp)): if(exp[-i]=="+"): val+=int(exp[-i-1]) elif(exp[-i]=="-"): val-=int(exp[-i-1]) elif(exp[-i]=="*"): val*=int(exp[-i-1]) print(val) ```
vfc_139666
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "42\n7-0*4+8-4*5\n1+1*5*7+1+2\n3-2+6*5*6*8\n9-7-5+3+2+3\n4+1*8*4-7+9\n3+9-6*0+8-0\n2-8*5*9-0+1\n3*9*4-6*6*1\n8+9*3*8*2+1\n3*9+4+7*3+1\n5*2+9*3+2-0\n1+5*5-1-0-1\n4-0+1-7-7+3\n5*9*1+2-6-3\n8+1+5-9+7*3\n5+2*1*4-6+8\n9+4-4*9+8+8\n7*8-8-...
taco
verifiable_code
Solve the following coding problem using the programming language python: HackerMan loves playing Age of Empire. A few days ago, he discovered a variant of that game which is equally adventurous. Here, he has to capture a castle before his enemy. The map consists of several interconnected paths in a grid pattern. He ...
```python #!/usr/bin/env python import sys def trymove(movegrid, x, y, num, grid): if x < 0 or y < 0 or x >= rows or y >= cols: return False timeleft = num - grid[x][y] if timeleft > movegrid[x][y]: movegrid[x][y] = timeleft return True #print movegrid, x, y, num def rescue(movegrid, grid): progress = Fa...
vfc_139674
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10\n50 26\n2 3 2 1 2 4 8 9 10 3 3 5 5 3 5 8 3 1 7 10 9 1 10 2 4 5\n6 10 1 2 6 9 7 1 7 1 4 1 3 8 3 7 10 7 10 3 3 8 6 2 2 10\n2 6 2 6 2 1 10 7 3 2 2 7 9 9 4 1 2 4 5 8 6 6 1 4 3 9\n10 2 8 2 1 2 10 4 4 1 2 4 4 5 6 10 5 8 1 4 9 1 5 8 2 ...
taco
verifiable_code
Solve the following coding problem using the programming language python: Taro Aizu's company has a boss who hates being indivisible. When Taro goes out to eat with his boss, he pays by splitting the bill, but when the payment amount is not divisible by the number of participants, his boss always pays for it. One day...
```python def solve(price, ps, is_prime): dp = [0] * ((price >> 5) + 1) for i in range(0, price + 1, ps[0]): dp[i >> 5] |= 1 << (i & 31) dp[0] = 1 for i in range(1, len(ps)): cur_p = ps[i] r = cur_p & 31 rest = 0 if cur_p >= 32: for p in range(cur_p, price + 1, 32): i1 = p - cur_p >> 5 i2 = p >...
vfc_139678
{ "difficulty": "unknown_difficulty", "memory_limit": "134.217728 megabytes", "memory_limit_bytes": null, "problem_url": null, "time_limit": "5.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 15000\n305\n260\n129\n500\n3 400\n10\n20\n30\n3 337371\n5\n9\n12\n0 0", "output": "14983\nNA\n337369\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 15000\n305\n124\n129\n500\n3 400\n1...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/print-elements-of-array4910/1
Solve the following coding problem using the programming language python: Given an array Arr of size N, print all its elements. Example 1: Input: N = 5 Arr[] = {1, 2, 3, 4, 5} Output: 1 2 3 4 5 Example 2: Input: N = 4 Arr[] = {2, 3, 5, 5} Output: 2 3 5 5 Your Task: Complete the function printArray() which takes an arr...
```python class Solution: def printArray(self, arr, n): for i in arr: print(i, end=' ') ```
vfc_139682
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/print-elements-of-array4910/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 5\r\nArr[] = {1, 2, 3, 4, 5}", "output": "1 2 3 4 5", "type": "stdin_stdout" }, { "fn_name": null, "input": "N = 4\r\nArr[] = {2, 3, 5, 5}", "output": "2 3 5 5", "type": "stdin_stdout...
taco
verifiable_code
https://codeforces.com/problemset/problem/1625/C
Solve the following coding problem using the programming language python: The Government of Mars is not only interested in optimizing space flights, but also wants to improve the road system of the planet. One of the most important highways of Mars connects Olymp City and Kstolop, the capital of Cydonia. In this prob...
```python import functools import sys input = sys.stdin.readline MAX = sys.maxsize sys.setrecursionlimit(10 ** 9) def read(): return list(map(int, input().strip().split())) def solve(l, k, d, a): d.append(l) @functools.lru_cache(maxsize=None) def solve_rec(position, drops, speed): if position >= len(a): ret...
vfc_139683
{ "difficulty": "medium_hard", "memory_limit": "128 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1625/C", "time_limit": "3 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 10 0\n0 3 4 8\n5 8 3 6\n", "output": "47\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 10 2\n0 3 4 8\n5 8 3 6\n", "output": "38\n", "type": "stdin_stdout" }, { ...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/broken-blocks0022/1
Solve the following coding problem using the programming language python: In the game of Broken Blocks, the player is allowed to move on m x n blocks i.e. m levels and n stone blocks on each level such that one level is vertically above the previous level (as in a staircase), with some of its stone blocks replaced by ...
```python class Solution: def MaxGold(self, matrix): l = len(matrix) o = len(matrix[0]) if l == 1: r = max(matrix[0]) if r == -1: return 0 return r if o == 1: p = matrix[0][0] if matrix[0][0] == -1: return 0 for h in range(1, l): if matrix[h][0] == -1: return p matrix[h]...
vfc_139691
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/broken-blocks0022/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "matrix = {{2,5,6},{-1,3,2},{4,-1,5}}", "output": "14", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: A great king of a certain country suddenly decided to visit the land of a friendly country. The country is famous for trains, and the king visits various stations. There are 52 train stations, each with a single uppercase or lowercase alphabeti...
```python def horizontal_input(T=str): return list(map(T, input().split())) def vertical_input(n, T=str, sep=False, septype=tuple): data = [] if sep: for i in range(n): data.append(septype(map(T, input().split()))) else: for i in range(n): data.append(T(input())) return data d = 'abcdefghijklmnopqrstuvw...
vfc_139692
{ "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": "2\n1 2\nbdd\n3\n3 2 1\nDDDA\n5\n3 1 4 5 2\ndcdkIlkP\n0", "output": "abc\nABCx\nabZfGijL\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1 2\nbdd\n3\n3 2 2\nDDDA\n5\n3 1 4 5 2\ndcdkIlkP\...
taco
verifiable_code
https://www.codechef.com/problems/VALENTINE
Solve the following coding problem using the programming language python: Valentine's Day is approaching and thus Chef wants to buy some chocolates for someone special. Chef has a total of X rupees and one chocolate costs Y rupees. What is the maximum number of chocolates Chef can buy? ------ Input Format ------ ...
```python t = int(input()) for i in range(t): (x, y) = map(int, input().split(' ')) print(x // y) ```
vfc_139696
{ "difficulty": "easy", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/VALENTINE", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n5 10\n16 5\n35 7\n100 1\n", "output": "0\n3\n5\n100\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/620/A
Solve the following coding problem using the programming language python: Professor GukiZ makes a new robot. The robot are in the point with coordinates (x_1, y_1) and should go to the point (x_2, y_2). In a single step the robot can change any of its coordinates (maybe both of them) by one (decrease or increase). So ...
```python l = list(map(int, input().split())) (x1, y1) = (l[0], l[1]) l = list(map(int, input().split())) (x2, y2) = (l[0], l[1]) dx = abs(x2 - x1) dy = abs(y2 - y1) if dx > dy: print(dx) else: print(dy) ```
vfc_139700
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/620/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "0 0\n4 5\n", "output": "5\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 4\n6 1\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input"...
taco
verifiable_code
https://codeforces.com/problemset/problem/1775/A1
Solve the following coding problem using the programming language python: This is an easy version of the problem. The difference between the versions is that the string can be longer than in the easy version. You can only do hacks if both versions of the problem are passed. Kazimir Kazimirovich is a Martian gardener....
```python for _ in range(int(input())): s = input() ans = ':(' n = len(s) x = 1 ans1 = [] for i in range(len(s)): l = [] if x + 1 < n: a = s[0:x] b = s[x:x + 1] c = s[x + 1:] l.append(a) l.append(b) l.append(c) x = x + 1 ans1.append(l) flag = 1 for i in ans1: a = i[0] b = i[1] ...
vfc_139705
{ "difficulty": "easy", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1775/A1", "time_limit": "1 second" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\nbbba\naba\naaa\nabba\nabbb\n", "output": "b b ba\na b a\na a a\nab b a\nab b b\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/print-bracket-number4058/1
Solve the following coding problem using the programming language python: Given a string S, the task is to find the bracket numbers. Example 1: Input: S = "(aa(bdc))p(dee)" Output: 1 2 2 1 3 3 Explanation: The highlighted brackets in the given string (aa(bdc))p(dee) has been assigned the numbers as: 1 2 2 1 3 3. Ex...
```python class Solution: def bracketNumbers(self, S): ans = [] stack = [] (x, y) = (0, 0) for c in S: if c == '(': x += 1 stack.append(x) ans.append(x) elif c == ')': ans.append(stack.pop()) return ans ```
vfc_139709
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/print-bracket-number4058/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "S = \"(aa(bdc))p(dee)\"", "output": "1 2 2 1 3 3", "type": "stdin_stdout" }, { "fn_name": null, "input": "S = \"(((()(\"", "output": "1 2 3 4 4 5", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/ARREQU
Solve the following coding problem using the programming language python: Chef has an array of N integers. Chef can rearrange this array in any manner. Chef doesn’t like the array if any two adjacent elements are equal. Determine whether there exists a rearrangement of the array that Chef likes. ------ Input Format...
```python from collections import Counter for _ in range(int(input())): n = int(input()) counter_arr = Counter(map(int, input().split())) if max(counter_arr.values()) > round(n / 2): print('No') else: print('Yes') ```
vfc_139717
{ "difficulty": "easy", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/ARREQU", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n5\n1 1 1 1 1\n3\n3 3 4\n", "output": "No\nYes\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1030/D
Solve the following coding problem using the programming language python: Vasya has got three integers $n$, $m$ and $k$. He'd like to find three integer points $(x_1, y_1)$, $(x_2, y_2)$, $(x_3, y_3)$, such that $0 \le x_1, x_2, x_3 \le n$, $0 \le y_1, y_2, y_3 \le m$ and the area of the triangle formed by these point...
```python import math import time from collections import defaultdict, deque, Counter from sys import stdin, stdout from bisect import bisect_left, bisect_right from queue import PriorityQueue import sys def gcd(a, b): if b == 0: return a return gcd(b, a % b) (n, m, k) = map(int, stdin.readline().split()) N = n M ...
vfc_139722
{ "difficulty": "medium_hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1030/D", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 3 3\n", "output": "YES\n0 0\n0 2\n4 0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 4 7\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, ...
taco
verifiable_code
https://codeforces.com/problemset/problem/877/B
Solve the following coding problem using the programming language python: One day Nikita found the string containing letters "a" and "b" only. Nikita thinks that string is beautiful if it can be cut into 3 strings (possibly empty) without changing the order of the letters, where the 1-st and the 3-rd one contain onl...
```python s = input() n = len(s) ca = [0] * (n + 1) cb = [0] * (n + 1) for i in range(n): if s[i] == 'a': ca[i + 1] += 1 else: cb[i + 1] += 1 for i in range(n): ca[i + 1] += ca[i] cb[i + 1] += cb[i] ans = min(ca[-1], cb[-1]) for l in range(1, n + 1): ans = min(ans, ca[l] + (cb[-1] - cb[l])) ans = min(ans, cb[...
vfc_139726
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/877/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "abba\n", "output": "4", "type": "stdin_stdout" }, { "fn_name": null, "input": "bab\n", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "bbabbbaabb...
taco
verifiable_code
https://www.codechef.com/problems/WSC
Solve the following coding problem using the programming language python: Read problems statements in Mandarin Chinese and Russian. The following is an easy game that the setter of this problem played when he was 8: A boatman, a wolf, a sheep, and a cabbage are on the bank of a river. They have a small boat that i...
```python testcases = int(input()) for _ in range(testcases): (n, m) = map(int, input().split()) l = [] if m > 2: print('NO') for i in range(m): input() elif m == 0: print('YES') elif m == 1: print('YES') input() else: for i in range(m): (x, y) = map(int, input().split()) if x not in l: l...
vfc_139730
{ "difficulty": "medium_hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/WSC", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n3 2\n1 2\n2 3\n3 3\n1 2\n2 3\n1 3", "output": "YES\nNO", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n3 2\n1 2\n2 3\n3 3\n1 2\n2 3\n2 3", "output": "YES\nNO\n", "type": "s...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/count-digits-in-a-factorial3957/1
Solve the following coding problem using the programming language python: Given an integer N. You have to find the number of digits that appear in its factorial, where factorial is defined as, factorial(N) = 1*2*3*4..*N and factorial(0) = 1. Example 1: Input: N = 5 Output: 3 Explanation: 5! is 120 so there are 3 dig...
```python import math class Solution: def facDigits(self, N): return len(str(math.factorial(N))) ```
vfc_139734
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/count-digits-in-a-factorial3957/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 5", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "N = 10", "output": "7", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/950/B
Solve the following coding problem using the programming language python: Hacker Zhorik wants to decipher two secret messages he intercepted yesterday. Yeah message is a sequence of encrypted blocks, each of them consists of several bytes of information. Zhorik knows that each of the messages is an archive containing...
```python (n, m) = [int(x) for x in input().split()] q1 = [int(x) for x in input().split()] q2 = [int(x) for x in input().split()] a1 = a2 = 0 it1 = it2 = -1 ans = 0 while it1 < n - 1 or it2 < m - 1: if a1 <= a2: it1 += 1 a1 += q1[it1] else: it2 += 1 a2 += q2[it2] if a1 == a2: a1 = a2 = 0 ans += 1 print(...
vfc_139735
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/950/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7 6\n2 5 3 1 11 4 4\n7 8 2 4 1 8\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 3\n1 10 100\n1 100 10\n", "output": "2\n", "type": "stdin_stdout" }, ...
taco
verifiable_code
Solve the following coding problem using the programming language python: Panda has a thing for palindromes. Hence he was a given a problem by his master. The master will give Panda an array of strings S having N strings. Now Panda has to select the Palin Pairs from the given strings . A Palin Pair is defined as...
```python noc = eval(input()) ans = {} temp = [] while noc: noc-=1 s1 = input() if s1 in ans: ans[s1]+=1 else: ans[s1] = 1 temp.append(s1) palins = 0 for x in temp: x1 = list(x) x1r = x1[::-1] x1rs="".join(x1r) if x1rs in ans: palins+=ans[x1rs] print(palins / 2) ```
vfc_139743
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1000\nSNTahGEzzg\nHoUwwCwYcL\nqmxqGFJXOe\nWXKLICrbar\nbpojEyGlYa\naYlGyEjopb\ngzzEGhaTNS\nhVvonTueII\ngNCRZRBKnm\nbpojEyGlYa\nrwpeUtNlaf\nLcYwCwwUoH\nGowhGtFUgX\nngBSLguLsW\npcdgGHzGCA\neOXJFGqxmq\nbpojEyGlYa\nGXHsiEAACE\nyAnaZMHcv...
taco
verifiable_code
https://codeforces.com/problemset/problem/363/B
Solve the following coding problem using the programming language python: There is a fence in front of Polycarpus's home. The fence consists of n planks of the same width which go one after another from left to right. The height of the i-th plank is h_{i} meters, distinct planks can have distinct heights. [Image] Fenc...
```python (n, k) = map(int, input().split()) h = list(map(int, input().split())) j = 0 m = 0 sum = 0 s = float('inf') if n == k: print(1) else: for i in range(n): sum += h[i] m += 1 if m == k: a = s s = min(s, sum) sum -= h[j] j += 1 m -= 1 if a != s: index = j else: continue print(i...
vfc_139751
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/363/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7 3\n1 2 6 1 1 7 1\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1\n100\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, ...
taco
verifiable_code
https://codeforces.com/problemset/problem/1187/D
Solve the following coding problem using the programming language python: You are given an array a_1, a_2, ..., a_n and an array b_1, b_2, ..., b_n. For one operation you can sort in non-decreasing order any subarray a[l ... r] of the array a. For example, if a = [4, 2, 2, 1, 3, 1] and you choose subbarray a[2 ... 5...
```python from sys import stdin, stdout from collections import defaultdict t = int(stdin.readline()) inf = 10 ** 6 def merge_sort(order, a): if len(order) == 1: return (order, a) mid = (len(order) + 1) // 2 (left_o, left_a) = merge_sort(order[:mid], a[:mid]) (right_o, right_a) = merge_sort(order[mid:], a[mid:])...
vfc_139755
{ "difficulty": "very_hard", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1187/D", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n5\n4 4 4 4 4\n5 5 5 5 5\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n8\n7 8 6 4 6 4 2 3\n2 4 7 6 4 8 3 6\n", "output": "YES\n", "type": "stdin_stdout...
taco
verifiable_code
https://www.hackerrank.com/challenges/superman-celebrates-diwali/problem
Solve the following coding problem using the programming language python: While switching buildings, he loses height $\boldsymbol{I}$ while jumping. The second restriction is explained below with an example. Assume $I=2$. Now Superman is in the 2^{nd} building 5^{th} floor ($B=2$, $F=5$). If he wants to switch to th...
```python (n, h, drop) = map(int, input().split()) a = [[0] * (h + 1) for _ in range(n)] for i in range(n): tmp = list(map(int, input().split()))[1:] for j in tmp: a[i][j] += 1 dp = [[0] * (h + 1) for _ in range(n)] opt = [0] * (h + 1) for i in range(1, h + 1): for j in range(n): dp[j][i] = dp[j][i - 1] + a[j][i...
vfc_139759
{ "difficulty": "medium_hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.hackerrank.com/challenges/superman-celebrates-diwali/problem", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 15 2 \n5 1 1 1 4 10\n8 9 5 7 7 3 9 8 8\n5 9 5 6 4 3\n0 \n", "output": "12\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/CHEFCODE
Solve the following coding problem using the programming language python: Read problems statements in mandarin chinese, russian and vietnamese as well. Though our Head Chef retired from sport programming long back, but that did not affect his passion to contribute to the programming community. He still remains engag...
```python import bisect def create_subsets(arr, k): subset = [] l = len(arr) val = 2 ** l for i in range(val): s = 1 for j in range(l): if i & 1 << j: s *= arr[j] if s <= k: subset.append(s) subset.sort() return subset (n, k) = [int(c) for c in input().split()] arr = [int(c) for c in input().spli...
vfc_139763
{ "difficulty": "hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/CHEFCODE", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 4\n1 2 3", "output": "5", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/984/A
Solve the following coding problem using the programming language python: Two players play a game. Initially there are $n$ integers $a_1, a_2, \ldots, a_n$ written on the board. Each turn a player selects one number and erases it from the board. This continues until there is only one number left on the board, i. e. $...
```python N = int(input()) A = list(map(int, input().split())) A.sort() if N % 2 == 0: print(A[N // 2 - 1]) else: print(A[N // 2]) ```
vfc_139767
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/984/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n2 1 3\n", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n2 2 2\n", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "9...
taco
verifiable_code
https://codeforces.com/problemset/problem/666/A
Solve the following coding problem using the programming language python: First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, whic...
```python s = input() n = len(s) x = set() a = [[0 for i in range(2)] for j in range(n + 3)] b = [0 for i in range(n + 3)] b[n] = 1 a[n][0] = 1 a[n][1] = 1 for i in range(n - 1, 4, -1): if b[i + 2]: if a[i + 2][0] and s[i:i + 2] != s[i + 2:i + 4]: b[i] = 1 a[i][0] = 1 if a[i + 2][1]: b[i] = 1 a[i][0] =...
vfc_139771
{ "difficulty": "medium_hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/666/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "abacabaca\n", "output": "3\naca\nba\nca\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "abaca\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, ...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/red-or-green5711/1
Solve the following coding problem using the programming language python: Given a string of length N, made up of only uppercase characters 'R' and 'G', where 'R' stands for Red and 'G' stands for Green.Find out the minimum number of characters you need to change to make the whole string of the same colour. Example 1: ...
```python class Solution: def RedOrGreen(self, N, S): d = {} for i in S: if i not in d: d[i] = 1 else: d[i] += 1 k = min(d.values()) if k == N: return 0 return k ```
vfc_139779
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/red-or-green5711/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N=5\nS=\"RGRGR\"", "output": "2", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/find-a-pair-with-given-target-in-bst/1
Solve the following coding problem using the programming language python: Given a Binary Search Tree and a target sum. Check whether there's a pair of Nodes in the BST with value summing up to the target sum. Example 1: Input: 2 / \ 1 3 sum = 5 Output: 1 Explanation: Nodes with value 2 and ...
```python class Solution: def isPairPresent(self, root, target): def inorder(root): if root == None: return inorder(root.left) ino.append(root.data) inorder(root.right) ino = [] inorder(root) l = 0 r = len(ino) - 1 while l < r: if ino[l] + ino[r] == target: return 1 elif ino[l] ...
vfc_139780
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/find-a-pair-with-given-target-in-bst/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\r\n / \\\r\n 1 3\r\nsum = 5", "output": "1", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1552/F
Solve the following coding problem using the programming language python: An ant moves on the real line with constant speed of $1$ unit per second. It starts at $0$ and always moves to the right (so its position increases by $1$ each second). There are $n$ portals, the $i$-th of which is located at position $x_i$ and...
```python n = 0 m = 200005 r = [0] * m l = [0] * m s = [0] * m dp = [0] * m sum = [0] * m mod = 998244353 def lower_bound(v): l = 1 ri = n ans = 0 while ri >= l: mid = l + ri >> 1 if r[mid] >= v: ri = mid - 1 ans = mid else: l = mid + 1 return ans n = int(input()) for i in range(1, n + 1): (r[i], ...
vfc_139781
{ "difficulty": "hard", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1552/F", "time_limit": "2 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n3 2 0\n6 5 1\n7 4 0\n8 1 1\n", "output": "23\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n454971987 406874902 1\n", "output": "503069073\n", "type": "stdin_stdout" ...
taco
verifiable_code
https://codeforces.com/problemset/problem/299/A
Solve the following coding problem using the programming language python: Ksusha is a beginner coder. Today she starts studying arrays. She has array a_1, a_2, ..., a_{n}, consisting of n positive integers. Her university teacher gave her a task. Find such number in the array, that all array elements are divisible by...
```python def main(): n = int(input()) L = list(map(int, input().split())) setL = set(L) rep = -1 for i in setL: for j in setL: if j % i != 0: rep = -1 break else: rep = i if rep != -1: break print(rep) main() ```
vfc_139789
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/299/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n2 2 4\n", "output": "2\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/LOG_EQN
Solve the following coding problem using the programming language python: Chef has a sequence of N$N$ integers A1,A2,...,AN$A_1, A_2, ..., A_N$. Chef thinks that a triplet of integers (i,j,k)$(i,j,k)$ is good if 1≤i<j<k≤N$1 \leq i < j < k \leq N$ and P$P$ in the following expression contains an odd number of ones in ...
```python from math import * t = int(input()) for _ in range(t): n = int(input()) a = [int(d) for d in input().split()] (odd, even) = (0, 0) for i in range(n): if bin(a[i]).count('1') % 2 == 1: odd += 1 else: even += 1 total = 0 if odd >= 3 and even >= 2: total += odd * (odd - 1) * (odd - 2) // 6 to...
vfc_139793
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/LOG_EQN", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n4\n1 1 2 3\n", "output": "1\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/find-index4752/1
Solve the following coding problem using the programming language python: Given an unsorted array Arr[] of N integers and a Key which is present in this array. You need to write a program to find the start index( index where the element is first found from left in the array ) and end index( index where the element is ...
```python class Solution: def findIndex(self, a, N, key): res = [] for i in range(0, n): if a[i] == key: res.append(i) if len(res) >= 1: return [res[0], res[-1]] else: return [-1, -1] ```
vfc_139797
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/find-index4752/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 6\r\narr[] = { 1, 2, 3, 4, 5, 5 }\r\nKey = 5", "output": "4 5", "type": "stdin_stdout" }, { "fn_name": null, "input": "N=6\r\narr[] = { 6, 5, 4, 3, 1, 2 }\r\nKey = 4", "output": "2 2", ...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/smallest-number5829/1
Solve the following coding problem using the programming language python: The task is to find the smallest number with given sum of digits as S and number of digits as D. Example 1: Input: S = 9 D = 2 Output: 18 Explanation: 18 is the smallest number possible with sum = 9 and total digits = 2. Example 2: Input: S...
```python class Solution: def smallestNumber(self, S, D): if S > 9 * D: return '-1' S = S - 1 i = D - 1 res = [''] * D while i >= 0: if S >= 10: res[i] = str(9) i -= 1 S -= 9 elif i != 0: res[i] = str(S) i -= 1 S = 0 else: res[i] = str(S + 1) break return ''.joi...
vfc_139798
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/smallest-number5829/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "S = 9 \nD = 2", "output": "18", "type": "stdin_stdout" }, { "fn_name": null, "input": "S = 20\nD = 3", "output": "299", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/maximum-sum-difference2545/1
Solve the following coding problem using the programming language python: Given a number N. We have to find maximum sum of all permutations of numbers from 1 to N. The maximum sum will be sum of absolute difference of adjacent elements in array. Example 1: Input: N = 2 Output: 1 Explaination: Permutations of 2 are: {...
```python class Solution: def maxSum(self, N): if N == 1: return 1 return N * (N - 1) // 2 + N // 2 - 1 ```
vfc_139799
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/maximum-sum-difference2545/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 2", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "N = 3", "output": "3", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1404/C
Solve the following coding problem using the programming language python: Let $a_1, \ldots, a_n$ be an array of $n$ positive integers. In one operation, you can choose an index $i$ such that $a_i = i$, and remove $a_i$ from the array (after the removal, the remaining parts are concatenated). The weight of $a$ is defi...
```python import sys sys.setrecursionlimit(10 ** 5) int1 = lambda x: int(x) - 1 p2D = lambda x: print(*x, sep='\n') def II(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def LI1(): return list(map(int1, sy...
vfc_139800
{ "difficulty": "hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1404/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "13 5\n2 2 3 9 5 4 6 5 7 8 3 11 13\n3 1\n0 0\n2 4\n5 0\n0 12\n", "output": "5\n11\n6\n1\n0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 2\n1 4 1 2 4\n0 0\n1 0\n", "output": "2\n0...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/three-great-candidates0515/1
Solve the following coding problem using the programming language python: The hiring team aims to find 3 candidates who are great collectively. Each candidate has his or her ability expressed as an integer. 3 candidates are great collectively if product of their abilities is maximum. Given abilities of N candidates in...
```python class Solution: def maxProduct(self, arr, n): arr.sort() return max(arr[-1] * arr[-2] * arr[-3], arr[0] * arr[1] * arr[-1]) ```
vfc_139805
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/three-great-candidates0515/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 5\r\nArr[] = {10, 3, 5, 6, 20}", "output": "1200", "type": "stdin_stdout" }, { "fn_name": null, "input": "N = 5\r\nArr[] = {-10, -3, -5, -6, -20}", "output": "-90", "type": "stdin_std...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/c-input-output2432/1
Solve the following coding problem using the programming language python: Given two integers A and B. Your task is to return their product. Example 1: Input: A = 1, B = 2 Output: 2 Explanation: Multiplication of 1 and 2 is 2. Example 2: Input: A = 8, B = 7 Output: 56 Explanation: Multiplication of 8 and 7 is 56. ...
```python class Solution: def multiplication(ob, A, B): return A * B ```
vfc_139806
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/c-input-output2432/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "A = 1, B = 2", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "A = 8, B = 7", "output": "56", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: All Indian Robotic Challenge (AIRC) is going to be held in NIT Raipur.Ajeet a student of nitrr want to participate in it and win it. In airc person whose robots will reach faster to end point will win .speed of bot is 20meters/Min.Ajeet want to ...
```python t=eval(input()) for x in range(t): d=eval(input()) print((d*60/20)) ```
vfc_139807
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10\n15\n25\n30\n35\n45\n15\n25\n30\n35\n45", "output": "45\n75\n90\n105\n135\n45\n75\n90\n105\n135", "type": "stdin_stdout" }, { "fn_name": null, "input": "14\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\...
taco
verifiable_code
https://codeforces.com/problemset/problem/682/B
Solve the following coding problem using the programming language python: Someone gave Alyona an array containing n positive integers a_1, a_2, ..., a_{n}. In one operation, Alyona can choose any element of the array and decrease it, i.e. replace with any positive integer that is smaller than the current one. Alyona c...
```python le = int(input()) n = sorted(map(int, input().split())) n.sort() n[0] = 1 for x in range(1, le): if n[x] > n[x - 1] + 1: n[x] = n[x - 1] + 1 print(n[-1] + 1) ```
vfc_139811
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/682/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n1 3 3 3 6\n", "output": "5\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n2 1\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "inpu...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/geek-fight/1
Solve the following coding problem using the programming language python: Geek is playing a video game that contains N monsters having varying power denoted by power[i]. Geek will play total Q rounds and for each round, the power of Geek is Q[i]. He can kill all monsters having power <= Q[i]. All the monsters which we...
```python from typing import List from typing import List class Solution: def win(self, n: int, power: List[int], q: int, Q: List[int]) -> List[List[int]]: def binary(arr, ele): (lo, hi) = (0, len(arr) - 1) ans = -1 while lo <= hi: mid = (lo + hi) // 2 if arr[mid] <= ele: ans = mid lo =...
vfc_139820
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/geek-fight/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 7\r\npowers[] = {1, 2, 3, 4, 5, 6, 7}\r\nQ[] = {3, 10, 2}", "output": "{{3, 6}, {7, 28}, {2, 3}}", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.hackerrank.com/challenges/matrix/problem
Solve the following coding problem using the programming language python: The kingdom of Zion has cities connected by bidirectional roads. There is a unique path between any pair of cities. Morpheus has found out that the machines are planning to destroy the whole kingdom. If two machines can join forces, they will ...
```python def leader(x): if P[x] == x: return P[x] if P[x] == x + 10 ** 5: return P[x] P[x] = leader(P[x]) return P[x] def same(x, y): return leader(x) == leader(y) def canJoin(x, y): return not (leader(x) >= 10 ** 5 and leader(y) >= 10 ** 5) def union(x, y): a = leader(x) b = leader(y) if a > b: (a, ...
vfc_139821
{ "difficulty": "medium_hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.hackerrank.com/challenges/matrix/problem", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 3\n2 1 8\n1 0 5\n2 4 5\n1 3 4\n2\n4\n0\n", "output": "10\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/e2d156755ca4e0a9b9abf5680191d4b06e52b1a8/1
Solve the following coding problem using the programming language python: Geek is in a geekland which have a river and some stones in it. Initially geek can step on any stone. Each stone has a number on it representing the value of exact step geek can move. If the number is +ve then geeks can move right and if the num...
```python def fun(i, n, arr, visit): if i < 0 or i >= n: return 2 if visit[i] == 1: return visit[i] visit[i] = 1 visit[i] = fun(i + arr[i], n, arr, visit) return visit[i] class Solution: def goodStones(self, n, arr) -> int: visit = [0] * n ans = 0 for i in range(n): if visit[i] == 0: visit[i] =...
vfc_139825
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/e2d156755ca4e0a9b9abf5680191d4b06e52b1a8/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "[2, 3, -1, 2, -2, 4, 1]", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "[1, 0, -3, 0, -5, 0]", "output": "2", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/MYPROBLEM
Solve the following coding problem using the programming language python: Chef loves problems about digits and he came up with an interesting one. Chef has given you two integers N and K. You should find the minimum non-negative integer X, such that N + X has at most K distinct digits in its decimal representation. ...
```python from sys import stdin, stdout input = stdin.readline r_int = lambda : int(input()) m_int = lambda : map(int, input().split()) l_int = lambda : list(map(int, input().split())) def solve(): (n_int, k) = m_int() n = list(map(int, str(n_int))) if len(set(n)) <= k: print(0) return for (i, d) in enumerate(...
vfc_139826
{ "difficulty": "very_hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/MYPROBLEM", "time_limit": "2 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "9\n30 1\n56 4\n364 2\n125 3\n37662730 3\n41872528 4\n73170084 8\n90032975 1\n7487471 3", "output": "3\n0\n2\n0\n603\n1583\n0\n9967024\n3", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/792/C
Solve the following coding problem using the programming language python: A positive integer number n is written on a blackboard. It consists of not more than 105 digits. You have to transform it into a beautiful number by erasing some of the digits, and you want to erase as few digits as possible. The number is call...
```python a = input() if len(a) == 1: if int(a) % 3 == 0: print(a) else: print(-1) exit(0) one = [] two = [] sum = 0 (zs, zf) = (0, 0) for i in range(len(a)): q = int(a[i]) sum += q if q == 0: if zs == 0: zs = i elif zs != 0 and zf == 0: zf = i if q % 3 == 1: if len(one) <= 4: one.append(i) eli...
vfc_139830
{ "difficulty": "hard", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/792/C", "time_limit": "1.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "100020001\n", "output": "10002000\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "100000000000000000222\n", "output": "1000000000000000002\n", "type": "stdin_stdout" }, ...
taco
verifiable_code
Solve the following coding problem using the programming language python: Frustrated from Mandark's challenges, Dexter plans an invasion in Mandark's lab. He knows that the underground entrance is the best way to get inside. But still, he needs to defuse the bombs hidden under the tiles of the floor. Dexter knows tha...
```python def solve(w, h): return (w * h + 1) / 2 def answer(w, h): return solve(w/2, h/2) + solve((w+1)/2, h/2) + solve((w+1)/2, (h+1)/2) + solve(w/2, (h+1)/2) for _ in range(eval(input())): w, h = list(map(int, input().split())) print(answer(w, h)) ```
vfc_139834
{ "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\n530 701\n11 6\n25 25\n1 100\n1 1", "output": "8\n497005\n497504\n468\n97836", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n4 4\n997 997\n998 997\n1 934\n744 263", "output": "185...
taco
verifiable_code
https://www.codechef.com/problems/GDSUB
Solve the following coding problem using the programming language python: Chef is given a sequence of prime numbers $A_1, A_2, \ldots, A_N$. This sequence has exactly $2^N$ subsequences. A subsequence of $A$ is good if it does not contain any two identical numbers; in particular, the empty sequence is good. Chef has t...
```python from collections import Counter from itertools import accumulate (n, k) = map(int, input().split()) a = list(map(int, input().split())) ctr = Counter(a) st = list(set(a)) l = len(st) k = min(k, l) m = list(accumulate([ctr[i] for i in st])) ans = 0 for i in range(2, k + 1): temp = [] for j in range(l): if ...
vfc_139845
{ "difficulty": "medium_hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/GDSUB", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 3\n2 2 3 3 5\n", "output": "18\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.hackerrank.com/challenges/equations/problem
Solve the following coding problem using the programming language python: Find the number of positive integral solutions for the equations $\dfrac{1}{x}+\dfrac{1}{y}=\dfrac{1}{N!}$ Input Format An integer N  Output Format The number of positive integral solutions for the above equation modulo 1000007 Const...
```python primes = [] a = range(2, 1000001) while len(a) > 0: if a[0] < 1000: primes.append(a[0]) a = [i for i in a if i % a[0] != 0] else: break primes = primes + a n = int(input()) m = 1 for p in primes: b = 0 nn = n // p while nn > 0: b += nn nn //= p m *= 1 + 2 * b m %= 1000007 print(m) ```
vfc_139849
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.hackerrank.com/challenges/equations/problem", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 \n", "output": "1\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/CMYC2020/problems/BTENG
Solve the following coding problem using the programming language python: Voritex a big data scientist collected huge amount of big data having structure of two rows and n columns. Voritex is storing all the valid data for manipulations and pressing invalid command when data not satisfying the constraints. Voritex lik...
```python import math import os import random import re import sys r = 100000 prev = 1 s = set() for i in range(1, r + 1): now = i ^ prev s.add(now) prev = now s = list(s) t = int(input()) while t > 0: t -= 1 (n, k) = list(map(int, input().split())) if n > 3: if n % 2 == 0: size = n // 2 + 2 else: size ...
vfc_139853
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/CMYC2020/problems/BTENG", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n4 2\n5 5\n", "output": "2\n0\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1180/A
Solve the following coding problem using the programming language python: While playing with geometric figures Alex has accidentally invented a concept of a $n$-th order rhombus in a cell grid. A $1$-st order rhombus is just a square $1 \times 1$ (i.e just a cell). A $n$-th order rhombus for all $n \geq 2$ one obtai...
```python n = int(input()) c = 1 m = 0 if n == 1: print(1) elif n == 2: print(5) else: c = c + (n - 1) * 4 n = n - 2 c = c + 4 * n * (n + 1) // 2 print(c) ```
vfc_139857
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1180/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n", "output": "5", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n", "ou...
taco
verifiable_code
https://codeforces.com/problemset/problem/1313/A
Solve the following coding problem using the programming language python: Tired of boring office work, Denis decided to open a fast food restaurant. On the first day he made $a$ portions of dumplings, $b$ portions of cranberry juice and $c$ pancakes with condensed milk. The peculiarity of Denis's restaurant is the p...
```python t = int(input()) for you in range(t): l = input().split() a = int(l[0]) b = int(l[1]) c = int(l[2]) poss = [1, 2, 3, 4, 5, 6, 7] count = [0] for i in range(2 ** 7): l = [] for j in range(7): if i & 1 << j: l.append(poss[j]) x = 0 y = 0 z = 0 for i in l: for k in range(3): if 1...
vfc_139861
{ "difficulty": "easy", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1313/A", "time_limit": "1 second" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7\n1 2 1\n0 0 0\n9 1 7\n2 2 3\n2 3 2\n3 2 2\n4 4 4\n", "output": "3\n0\n4\n5\n5\n5\n7\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n2 2 8\n3 2 2\n", "output": "5\n5\n", "t...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/jump-game/1
Solve the following coding problem using the programming language python: Given an positive integer N and a list of N integers A[]. Each element in the array denotes the maximum length of jump you can cover. Find out if you can make it to the last index if you start at the first index of the list. Example 1: Input: N ...
```python class Solution: def canReach(self, A, N): if N == 1: return 1 maxReach = A[0] for i in range(1, N): maxReach = max(maxReach, A[i] + i) if maxReach >= N - 1: return 1 if i == N - 1: return 1 if maxReach <= i: return 0 return 1 ```
vfc_139865
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/jump-game/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 6\nA[] = {1, 2, 0, 3, 0, 0}", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "N = 3\nA[] = {1, 0, 2}", "output": "0", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/7-segment-display0752/1
Solve the following coding problem using the programming language python: Using seven segment display, you can write down any digit from 0 to 9 using at most seven segments. Given a positive number N and then a string S representing a number of N digits. You have to rearrange the segments in this N digit number to get...
```python class Solution: def sevenSegments(self, S, N): segs = [6, 2, 5, 5, 4, 5, 6, 3, 7, 5] total = sum((segs[int(S[i])] for i in range(N))) ans = ['0'] * N for i in range(N): if total == 2 * (N - i): ans[i] = '1' total -= 2 elif total == 7 * (N - i): ans[i] = '8' total -= 7 elif t...
vfc_139866
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/7-segment-display0752/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 6\r\nS = \"234567\"", "output": "000011", "type": "stdin_stdout" }, { "fn_name": null, "input": "N = 3\r\nS = \"011\"", "output": "011", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: CodeswarBala found various ornaments in Btyeland. Each ornament is made up of various items, and each item is represented by a letter from 'a' to 'z'. An item can be present multiple times in a ornament . An item is called special item if it o...
```python ''' # Read input from stdin and provide input before running code name = raw_input('What is your name?\n') print 'Hi, %s.' % name ''' def zerolistmaker(n): listofzeros = [0] * n return listofzeros n=eval(input()) l=zerolistmaker(101) m=n while n: x=input() a=set(x) for i in a: l[ord(str(i))-96]+=1...
vfc_139875
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "100\nayayrnhxvfbxzodsycpjqlrbwbmrmoaeunllzjrtdcmdbcmbdefglycboqxkagyderwkpdpewsjgkqdhcsixxhsrolrfnbkilw\nwgfvoecyrmvjefplndcdrozkpkoxnigzpcgzzeitwddxtqrhfqsukchfxqycacmoiknbiwhxxmbpljqhkahjt\nrbharxcldxthzuqrmofxcomdvjewxvwpsyhdnya...
taco
verifiable_code
Solve the following coding problem using the programming language python: Scientists, researchers, mathematicians and thinkers propose theories for a number of things. For explaining a single thing, a number of theories are proposed. A number of theories are rendered invalid after a new and more relevant theory surf...
```python def comp(p1,p2): if p1[0]==p2[0]: return p2[1]-p1[1] else: return p1[0]-p2[0] t=eval(input()) while t: A=[] B=[] n=eval(input()) for i in range(n): (a,b)=list(map(int,input().split())) A.append((a,b)) B.append((a,0)) B.append((b,1)) i+=1 B=sorted(B,cmp=comp) C=[0]*len(B) C[0]=1 maxx=-f...
vfc_139879
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10\n1000\n24000 49105\n2729 25508\n23500 23742\n21228 34303\n17351 28299\n8818 9601\n14790 45516\n12829 34331\n21215 49856\n32191 42162\n6294 31301\n816 15326\n24728 55379\n30622 49686\n19628 46067\n26405 55668\n1766 26810\n29343 4...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/frequency-of-each-element-in-an-unsorted-array0759/1
Solve the following coding problem using the programming language python: Given an array of elements. The task is to calculate the cumulative frequency of each element of the array. Note :- Cumulative frequency should be taken according to the sorted order of elements. Example 1: Input : Arr[] = {1, 2, 2, 1, 3, 4} Out...
```python class Solution: def countFreq(self, a, n): a.sort() arr = [] count = 1 for i in range(1, n): if a[i] != a[i - 1]: arr.append(count) count += 1 arr.append(count) return arr ```
vfc_139883
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/frequency-of-each-element-in-an-unsorted-array0759/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "Arr[] = {1, 2, 2, 1, 3, 4}", "output": "2 4 5 6", "type": "stdin_stdout" }, { "fn_name": null, "input": "Arr[] = {1, 2, 1, 2, 1, 2}", "output": "3 6", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/find-the-number-which-contain-the-digit-d4144/1
Solve the following coding problem using the programming language python: Given two integer number n and d. The task is to find the number between 0 to n which contain the specific digit d. Example 1 - Input n = 20 d = 5 Output 5 15 Explanation: For number till 20, 5 appears in 5 itself and 15. Example 2 - Input n = ...
```python class Solution: def solve(self, n, d): l = [] d = str(d) for i in range(n + 1): if d in str(i): l.append(int(i)) if len(l) == 0: return [-1] return l ```
vfc_139884
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/find-the-number-which-contain-the-digit-d4144/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "n = 20\r\nd = 5", "output": "5 15", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: Shell Sort Shell Sort is a generalization of Insertion Sort to arrange a list of $n$ elements $A$. 1 insertionSort(A, n, g) 2 for i = g to n-1 3 v = A[i] 4 j = i - g 5 while j >= 0 && A[j] > v 6 A...
```python def insertionSort(a, n, g): global cnt for i in range(g, n): v = a[i] j = i - g while j >= 0 and a[j] > v: a[j + g] = a[j] j = j - g cnt = cnt + 1 a[j + g] = v def shellSort(a, n): global cnt global G global m cnt = 0 G = [1] while 3 * G[0] + 1 <= n: G = [3 * G[0] + 1] + G m = len...
vfc_139885
{ "difficulty": "unknown_difficulty", "memory_limit": "134.217728 megabytes", "memory_limit_bytes": null, "problem_url": null, "time_limit": "6.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n5\n1\n4\n5\n2", "output": "2\n4 1\n2\n1\n2\n4\n5\n5\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/smallest-greater-elements-in-whole-array2751/1
Solve the following coding problem using the programming language python: Given an array A of N length. We need to calculate the next smallest greater element for each element in a given array. If the next greater element is not available in a given array then we need to fill -10000000 at that index place. Example 1: ...
```python import bisect def greaterElement(arr, n): arr_sorted = sorted(arr) output = [] for val in arr: idx = bisect.bisect_right(arr_sorted, val) smallest_greater = arr_sorted[idx] if idx <= n - 1 else -10000000 output.append(smallest_greater) return output ```
vfc_139889
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/smallest-greater-elements-in-whole-array2751/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": "greaterElement", "input": "arr[] = {13, 6, 7, 12}", "output": "_ 7 12 13", "type": "function_call" }, { "fn_name": "greaterElement", "input": "arr[] = {6, 3, 9, 8, 10, 2, 1, 15, 7}", "output": "7 6 10 9 15 3 ...
taco
verifiable_code
https://www.codechef.com/problems/CHFPARTY
Solve the following coding problem using the programming language python: Tonight, Chef would like to hold a party for his $N$ friends. All friends are invited and they arrive at the party one by one in an arbitrary order. However, they have certain conditions — for each valid $i$, when the $i$-th friend arrives at th...
```python for _ in range(int(input())): n = int(input()) li = list(map(int, input().split())) li.sort() p = 0 for i in li: if p >= i: p = p + 1 print(p) ```
vfc_139890
{ "difficulty": "easy", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/CHFPARTY", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n2\n0 0\n6\n3 1 0 0 5 5\n3\n1 2 3\n", "output": "2\n4\n0\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/5c2734730cb1e98e3877a0b91f7d680d0efc8acf/1
Solve the following coding problem using the programming language python: The task is to find the second smallest number with a given sum of digits as S and the number of digits as D. Example 1: Input: S = 9 D = 2 Output: 27 Explanation: 18 is the smallest number possible with sum = 9 and total digits = 2, Whereas th...
```python class Solution: def secondSmallest(self, S, D): if S <= 9 and D == 1: return S if S >= 9 * D: return -1 ret = [] while S: if S >= 9: ret.append(9) S -= 9 else: ret.append(S) S = 0 if len(ret) < D: ret[-1] -= 1 while len(ret) < D: ret.append(0) ret[-1] += 1 ...
vfc_139895
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/5c2734730cb1e98e3877a0b91f7d680d0efc8acf/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "S = 9 \r\nD = 2", "output": "27", "type": "stdin_stdout" }, { "fn_name": null, "input": "S = 16\r\nD = 3", "output": "178", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/CARRANGE
Solve the following coding problem using the programming language python: The *fuel economy* of a car is the distance which it can travel on one litre of fuel. The base fuel economy (i.e, its fuel economy when there is only one person - the driver - in the car) of a certain car is M kilometres per litre. It was also ...
```python t = int(input()) for i in range(t): (p, m, v) = map(int, input().split()) print(abs(p - m - 1) * v) ```
vfc_139900
{ "difficulty": "easy", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/CARRANGE", "time_limit": "0.5 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n5 10 20\n1 6 10\n4 6 1", "output": "120\n60\n3", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/402/B
Solve the following coding problem using the programming language python: The Queen of England has n trees growing in a row in her garden. At that, the i-th (1 ≤ i ≤ n) tree from the left has height a_{i} meters. Today the Queen decided to update the scenery of her garden. She wants the trees' heights to meet the cond...
```python import math def main(): (n, k) = [int(i) for i in input().split()] l = [int(i) for i in input().split()] l2 = [l[i] - i * k for i in range(len(l))] d = dict() m = 0 mn = 0 for i in l2: if i > 0: try: d[i] += 1 except: d[i] = 1 if d[i] > m: m = d[i] mn = i count = 0 ans = [...
vfc_139904
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/402/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 1\n1 2 1 5\n", "output": "2\n+ 3 2\n- 4 1\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/find-first-and-last-occurrence-of-x0849/1
Solve the following coding problem using the programming language python: Given a sorted array with possibly duplicate elements. The task is to find indexes of first and last occurrences of an element X in the given array. Note: If the element is not present in the array return {-1,-1} as pair. Example 1: Input: N =...
```python class Solution: def indexes(self, v, x): res = [] for i in range(len(v)): if v[i] == x: res.append(i) if len(res) == 0: return [-1, -1] else: return (res[0], res[-1]) ```
vfc_139908
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/find-first-and-last-occurrence-of-x0849/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 9\nv[] = {1, 3, 5, 5, 5, 5, 67, 123, 125}\nX = 5", "output": "2 5", "type": "stdin_stdout" }, { "fn_name": null, "input": "N = 9\nv[] = {1, 3, 5, 5, 5, 5, 7, 123, 125}\nX = 7", "output": "6...
taco
verifiable_code
https://codeforces.com/problemset/problem/1315/D
Solve the following coding problem using the programming language python: VK news recommendation system daily selects interesting publications of one of n disjoint categories for each user. Each publication belongs to exactly one category. For each category i batch algorithm selects a_i publications. The latest A/B t...
```python import sys from heapq import heappush, heappop def main(): n = int(sys.stdin.readline()) h = sorted(list(zip([int(i) for i in sys.stdin.readline().split()], [int(i) for i in sys.stdin.readline().split()]))) (z, w, o, res) = ([], 0, 0, 0) while o < n: t = h[o][0] w += h[o][1] heappush(z, -1 * h[o][1...
vfc_139909
{ "difficulty": "medium_hard", "memory_limit": "512.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1315/D", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n1000000000 1000000000 1000000000 1000000000 1000000000\n100000 100000 100000 100000 100000\n", "output": "1000000\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n14 31 50 67 42 44 8...
taco
verifiable_code
Solve the following coding problem using the programming language python: Xenny was a teacher and his class consisted of N boys and N girls. He took all his students to the playground and asked them to stand in a straight line. The boys and the girls formed a perfect line, but Xenny seemed unhappy. He wanted them to f...
```python for _ in range(eval(input())): n=eval(input()) b=input() s1=['G']*(2*n) s2=['G']*(2*n) j=count1=count2=0 for i in range(1,2*n,2): s1[i]='B' s2[j]='B' j=j+2 for i in range(2*n): if b[i]!=s1[i]: count1+=1 if b[i]!=s2[i]: count2+=1 print(min(count1/2,count2/2)) ```
vfc_139922
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n465\nGGBGBGBGGGBGBBGGGGGBGBGGBBGBBGGGGBGGBBGBGGBBGBGGBGBGBGBBGGBGGGGBGGGGBGBBGBBBBBBBBBBBBGGBGBGBGGGGGBBGBBGGGBGBBGGBBGBGGGBBGBBBGGBBGGBGBGGBGGGBBGGGBBBGBGGBGGGGGGGBGBBGGGBBBBGBGBGBGBBBGBGBGBGGBBBBBBBGGGGBGBBGGBBBBBGGBGGGBBGBGGB...
taco
verifiable_code
https://www.codechef.com/problems/GMEDIAN
Solve the following coding problem using the programming language python: Read problems statements [Hindi] , [Vietnamese] , [Mandarin Chinese] , [Russian] and [Bengali] as well. Raja only participates in contests and does not upsolve, but he claims that he has been upsolving. Chef wants to test if he is really improv...
```python def main(): (mod, m) = (int(1000000000.0 + 7), 1005) (Fact, iFact) = ([1] * m, [1] * m) for i in range(2, m): Fact[i] = Fact[i - 1] * i % mod iFact[m - 1] = pow(Fact[m - 1], mod - 2, mod) for i in range(m - 2, 0, -1): iFact[i] = iFact[i + 1] * (i + 1) % mod t = int(input()) for _ in range(t): n ...
vfc_139926
{ "difficulty": "hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/GMEDIAN", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n3\n2 3 2", "output": "5", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/find-the-closest-number5513/1
Solve the following coding problem using the programming language python: Given an array of sorted integers. The task is to find the closest value to the given number in array. Array may contain duplicate values. Note: If the difference is same for two values print the value which is greater than the given number. Exa...
```python class Solution: def findClosest(self, arr, n, target): h_a = [0] * n for i in range(n): h_a[i] = abs(arr[i] - target) m = min(h_a) for i in range(-1, n * -1, -1): if h_a[i] == m: return arr[i] return arr[0] ```
vfc_139930
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/find-the-closest-number5513/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "Arr[] = {1, 3, 6, 7} and K = 4", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "Arr[] = {1, 2, 3, 5, 6, 8, 9}, K = 4", "output": "5", "type": "stdin_stdout" } ...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/tywins-war-strategy0527/1
Solve the following coding problem using the programming language python: Tywin Lannister is facing a war. He has N troops of soldiers. Each troop has a certain number of soldiers denoted by an array A. Tywin thinks that a troop is lucky if it has a number of soldiers as a multiple of K. He doesn't want to lose any so...
```python def min_soldiers(arr, n, K): count = 0 a = [] i = 0 while i < n: if arr[i] % K == 0: count += 1 i = i + 1 i = 0 while i < n: d = K - arr[i] while d < 0: d = d + K a.append(d) i = i + 1 a.sort() r = [] m = 0 if n % 2 == 0 and count < n // 2: l = n // 2 - count h = 0 while h < ...
vfc_139932
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/tywins-war-strategy0527/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": "min_soldiers", "input": "arr[ ] = {5, 6, 3, 2, 1} and K = 2", "output": "1", "type": "function_call" }, { "fn_name": "min_soldiers", "input": "arr[ ] = {2, 3, 4, 9, 8, 7} and K = 4", "output": "1", "typ...
taco
verifiable_code
https://codeforces.com/problemset/problem/391/C2
Solve the following coding problem using the programming language python: This problem consists of three subproblems: for solving subproblem C1 you will receive 4 points, for solving subproblem C2 you will receive 4 points, and for solving subproblem C3 you will receive 8 points. Manao decided to pursue a fighter's c...
```python m = 301000 ns = [0] * m es = [0] * m c = [0] * m b = [0] * m t = [0] * m P = 0 def add(b, k): k = t[k] while k: e = es[k] if b[-1] > e: b[-1] = e b[e] += 1 k = ns[k] def delete(b): for i in range(b[m - 1], m + 1): if b[i]: b[i] -= 1 b[-1] = i return i def calc(k): global b q = 0 ...
vfc_139933
{ "difficulty": "unknown_difficulty", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/391/C2", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6 4\n1 159371\n1 73897\n1 181693\n4 187816\n3 154227\n1 188146\n", "output": "387495", "type": "stdin_stdout" }, { "fn_name": null, "input": "15 1\n8 79548\n2 109344\n1 40450\n5 65400\n10 93553\n10 8...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/exit-point-in-a-matrix0905/1
Solve the following coding problem using the programming language python: Given a matrix of size n x m with 0’s and 1’s , you enter the matrix at cell (0,0) in left to right direction. whenever you encounter a 0 you retain in same direction , if you encounter a 1’s you have to change direction to right of current dire...
```python class Solution: def FindExitPoint(self, matrix): i = 0 j = 0 dir = 0 while True: dir = (dir + matrix[i][j]) % 4 if matrix[i][j] == 1: matrix[i][j] = 0 if dir == 0: j += 1 elif dir == 1: i += 1 elif dir == 2: j -= 1 elif dir == 3: i -= 1 if i < 0: i += 1 ...
vfc_139937
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/exit-point-in-a-matrix0905/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "matrix = {{0, 1, 0},\n{0, 1, 1}, {0, 0, 0}}", "output": "1 0", "type": "stdin_stdout" }, { "fn_name": null, "input": "matrix = {{0, 0}}", "output": "0 1", "type": "stdin_stdout" } ]...
taco
verifiable_code
https://www.codechef.com/problems/RESQ
Solve the following coding problem using the programming language python: Our Chef is catering for a big corporate office party and is busy preparing different mouth watering dishes. The host has insisted that he serves his delicious cupcakes for dessert. On the day of the party, the Chef was over-seeing all the foo...
```python t = int(input()) for i in range(t): n = int(input()) f = False d = n - 1 for j in range(int(n ** 0.5), 0, -1): if n % j == 0: if d > abs(j - n / j): d = abs(j - n / j) print(int(d)) ```
vfc_139940
{ "difficulty": "easy", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/RESQ", "time_limit": "2 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n20\n13\n8\n4", "output": "1\n12\n2\n0", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n38\n13\n8\n4", "output": "17\n12\n2\n0\n", "type": "stdin_stdout" }, { "...
taco
verifiable_code
Solve the following coding problem using the programming language python: You are given N number of trophies. All trophies look similar. However, one of them is defective. All trophies except the defective one have same weight. The defective one has less weight compared to others. You are given a weighing balance. As ...
```python i=int(input()) k=[] for j in range(i): m=int(input()) k.append(m) for s in k: if s!=1 and s!=0: a=0 l=s/3 while l>1: a=a+1 l=l/3 a=a+1 print(a) else: a=0 print(a) ```
vfc_139947
{ "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\n2\n4\n8\n16", "output": "1\n2\n2\n3\n4\n5\n3\n6\n6\n7", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n2\n4\n8\n16\n52\n100\n27\n728\n729\n730", "output": "1\n2\n2\n3", "ty...
taco
verifiable_code
Solve the following coding problem using the programming language python: Our code monk, high on excitement after solving the rest of the problems , goes on a trek in the mountains . On his way, he encounters Janemba, the evil magician! Janemba takes our monk to a poison field and plays a game with him described as ...
```python import heapq def solve(xss, n, k): ''' use two heaps to select the cheapest k row / col in O(k.log(n)) select the cheapeast combination of "i rows" + "k-i cols" + i ''' # total, count_rows, count_cols = 0, 0, 0 rows = [sum(xs) for xs in xss] cols = [sum(xs) for xs in zip(*xss)] heapq.heapify(rows) h...
vfc_139951
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n2 3\n4 10\n2 9\n2 1\n4 5\n5 2", "output": "24\n7\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "100\n2 5\n4 1\n8 5\n2 2\n3 4\n1 7\n2 5\n8 3\n8 9\n2 2\n6 6\n4 1\n2 5\n7 5\n1 6\n2 4\n6 7...
taco
verifiable_code
https://codeforces.com/problemset/problem/109/C
Solve the following coding problem using the programming language python: Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya encountered...
```python import os import sys from io import BytesIO, IOBase from types import GeneratorType from collections import defaultdict BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = 'x' in file.mode or 'r' not in file.mod...
vfc_139955
{ "difficulty": "hard", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/109/C", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n2 1 1000000000\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1 2 7\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, ...
taco
verifiable_code
Solve the following coding problem using the programming language python: The time has arrived when the world is going to end. But don't worry, because the new world yuga will start soon. Manu (carrier of mankind) has been assigned the job to carry all the necessary elements of current yuga to the upcoming yuga. Ther...
```python stone= [0] * 10000000 def check(jump,n,k): i=ans=0 j=0 j1=0 flag=0 for i in range(n): while(j<n and stone[j]-stone[j1]<=jump): j+=1 ans+=1 j1=j-1; if(j==n): flag=1 break if(ans<=k and flag==1): return 1 return 0 if __name__ == "__main__": testcases = eval(input()) for...
vfc_139959
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n5915 3724\n33756 51456 52248 56810 66300 71810 76398 84024 88740 94734 99792 142060 160480 232650 291165 303597 307746 318541 378882 379104 410210 427424 430576 436738 443312 443548 446715 471744 475500 507600 537189 578391 5914...
taco
verifiable_code
https://codeforces.com/problemset/problem/275/A
Solve the following coding problem using the programming language python: Lenny is playing a game on a 3 × 3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the lights off. We consider...
```python def do(sh): return 1 - sh a = [[1 for _ in range(5)] for __ in range(5)] for i in range(1, 4): b = list(map(int, input().split())) for j in range(1, 4): if b[j - 1] % 2 == 1: a[i][j] = 1 - a[i][j] a[i + 1][j] = 1 - a[i + 1][j] a[i - 1][j] = 1 - a[i - 1][j] a[i][j + 1] = 1 - a[i][j + 1] a[i...
vfc_139963
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/275/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 0 0\n0 0 0\n0 0 1\n", "output": "001\n010\n100\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 0 1\n8 8 8\n2 0 3\n", "output": "010\n011\n100\n", "type": "stdin_stdout" ...
taco
verifiable_code
Solve the following coding problem using the programming language python: problem The island where JOI lives has been invaded by zombies. JOI decided to escape to the shelter, which is set as the safest shelter on the island. The island where JOI lives consists of N towns from town 1 to town N, and the towns are con...
```python from collections import deque from heapq import heappop, heappush inf = float('INF') dq = [] (n, m, k, s) = map(int, input().split()) (p, q) = map(int, input().split()) c = [0] * k z_dist = [inf] * n for i in range(k): c[i] = int(input()) - 1 z_dist[c[i]] = 0 heappush(dq, (0, c[i])) g = [[] for i in range(...
vfc_139967
{ "difficulty": "unknown_difficulty", "memory_limit": "268.435456 megabytes", "memory_limit_bytes": null, "problem_url": null, "time_limit": "8.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "13 21 1 1\n1000 6000\n7\n1 2\n3 7\n2 4\n5 8\n8 9\n2 5\n3 4\n6 7\n9 10\n10 11\n5 9\n7 12\n3 6\n4 5\n1 3\n11 12\n6 7\n8 11\n6 13\n7 8\n12 13", "output": "11000\n", "type": "stdin_stdout" }, { "fn_name": null...
taco
verifiable_code
https://codeforces.com/problemset/problem/1660/A
Solve the following coding problem using the programming language python: Vasya decided to go to the grocery store. He found in his wallet $a$ coins of $1$ burle and $b$ coins of $2$ burles. He does not yet know the total cost of all goods, so help him find out $s$ ($s > 0$): the minimum positive integer amount of mon...
```python def solve(): if n == 0: return 1 return n + 2 * m + 1 from sys import stdin input = stdin.readline for _ in range(int(input())): (n, m) = [int(x) for x in input().split()] print(solve()) ```
vfc_139975
{ "difficulty": "easy", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1660/A", "time_limit": "1 second" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n1 1\n4 0\n0 2\n0 0\n2314 2374\n", "output": "4\n5\n1\n1\n7063\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/CHEFRP
Solve the following coding problem using the programming language python: Read problems statements in Mandarin Chinese and Russian. Rupsa recently started to intern under Chef. He gave her N type of ingredients of varying quantity A_{1}, A_{2}, ..., A_{N} respectively to store it. But as she is lazy to arrange the...
```python T = int(input()) for i in range(T): N = int(input()) A = [int(n) for n in input().split()] if 1 in A: print(-1) continue A_sorted = sorted(A) print(sum(A_sorted) + 2 - A_sorted[0]) ```
vfc_139991
{ "difficulty": "easy", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/CHEFRP", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n2\n2 2\n1\n6", "output": "4\n2", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n2\n2 1\n1\n6", "output": "-1\n2\n", "type": "stdin_stdout" }, { "fn_name": null...
taco
verifiable_code
https://codeforces.com/problemset/problem/16/A
Solve the following coding problem using the programming language python: According to a new ISO standard, a flag of every country should have a chequered field n × m, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of the same colour...
```python _ = list(map(int, input().split())) __ = True ____ = 'WTF' for _i_ in range(_[0]): ___ = input() if ___.count(___[0]) != _[1] or ___[0] == ____: __ = False ____ = ___[0] print('YES' if __ else 'NO') ```
vfc_139999
{ "difficulty": "easy", "memory_limit": "64.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/16/A", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10 10\n2222222222\n5555555555\n0000000000\n4444444444\n1111111111\n3333333393\n3333333333\n5555555555\n0000000000\n8888888888\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, "input...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/minimum-depth-of-a-binary-tree/1
Solve the following coding problem using the programming language python: Given a binary tree, find its minimum depth. Example 1: Input: 1 / \ 3 2 / 4 Output: 2 Explanation: Minimum depth is between nodes 1 and 2 since minimum depth is defined as the numb...
```python class Solution: def minDepth(self, root): if root == None: return 0 if not root.left and (not root.right): return 1 if not root.right: return self.minDepth(root.left) + 1 if not root.left: return self.minDepth(root.right) + 1 rightDepth = self.minDepth(root.right) leftDepth = self.mi...
vfc_140003
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/minimum-depth-of-a-binary-tree/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n / \\\n 3 2\n /\n 4", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n / \\\n 20 30\n \\ \\ ...
taco
verifiable_code
https://www.codechef.com/problems/EOSUBSEQ
Solve the following coding problem using the programming language python: You are given an array $a$ of length $n$. A subsequence of this array is valid, if it satisfies these two conditions: - There shouldn't be any two even numbers within a distance of $K$, both which have been chosen in the subsequence. i.e. there ...
```python import sys import math def main(arr, k): x = [] y = [] for e in arr: if e % 2 == 0: x.append(e) y.append(0) else: x.append(0) y.append(e) a = [0] * n b = [0] * n a[0] = x[0] b[0] = y[0] for i in range(1, n): if i < k: a[i] = max(x[i], a[i - 1]) b[i] = max(y[i], b[i - 1]) els...
vfc_140004
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/EOSUBSEQ", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1 1\n3\n2 1\n2 2\n5 2\n1 2 3 4 6\n", "output": "3\n2\n11\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/deee0e8cf9910e7219f663c18d6d640ea0b87f87/1
Solve the following coding problem using the programming language python: Due to the rise of covid-19 cases in India, this year BCCI decided to organize knock-out matches in IPL rather than a league. Today is matchday 2 and it is between the most loved team Chennai Super Kings and the most underrated team - Punjab Ki...
```python class Solution: def max_of_subarrays(self, arr, n, k): ans = [] d = deque() for x in range(n): while d and arr[d[-1]] <= arr[x]: d.pop() d.append(x) if d[0] == x - k: d.popleft() if x >= k - 1: ans.append(arr[d[0]]) return ans ```
vfc_140009
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/deee0e8cf9910e7219f663c18d6d640ea0b87f87/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 9, K = 3\r\narr[] = 1 2 3 1 4 5 2 3 6", "output": "3 3 4 5 5 5 6", "type": "stdin_stdout" }, { "fn_name": null, "input": "N = 10, K = 4\r\narr[] = 8 5 10 7 9 4 15 12 90 13", "output": "10 1...
taco
verifiable_code
https://codeforces.com/problemset/problem/682/A
Solve the following coding problem using the programming language python: After finishing eating her bun, Alyona came up with two integers n and m. She decided to write down two columns of integers — the first column containing integers from 1 to n and the second containing integers from 1 to m. Now the girl wants to ...
```python (n, k) = map(int, input().rstrip().split(' ')) m = max(n, k) n = min(n, k) total = m * (n // 5) z = n % 5 + m % 5 f = 0 if z > 5: f = z % 5 else: f = 0 total = total + n % 5 * (m // 5) + z // 5 + f print(total) ```
vfc_140010
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/682/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6 12\n", "output": "14\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "11 14\n", "output": "31\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1549/C
Solve the following coding problem using the programming language python: When you play the game of thrones, you win, or you die. There is no middle ground. Cersei Lannister, A Game of Thrones by George R. R. Martin There are n nobles, numbered from 1 to n. Noble i has a power of i. There are also m "friendships". A...
```python import sys input = sys.stdin.readline (n, m) = list(map(int, input().split())) a = [0] * (n + 1) ans = n for i in range(m): (u, v) = list(map(int, input().split())) u = min(u, v) if a[u] == 0: ans -= 1 a[u] += 1 q = int(input()) for i in range(q): b = list(map(int, input().split())) if b[0] == 1: b[...
vfc_140014
{ "difficulty": "medium", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1549/C", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 0\n2\n1 2 1\n3\n", "output": "2\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1617/A
Solve the following coding problem using the programming language python: You are given strings $S$ and $T$, consisting of lowercase English letters. It is guaranteed that $T$ is a permutation of the string abc. Find string $S'$, the lexicographically smallest permutation of $S$ such that $T$ is not a subsequence of ...
```python for _ in range(int(input())): s = input() t = input() ans = '' l = [0] * 26 a = s.count('a') b = s.count('b') c = s.count('c') for i in s: l[ord(i) - 97] += 1 if t[0] == 'a' and t[1] == 'b' and l[0]: for i in range(a): ans += 'a' for i in range(c): ans += 'c' for i in range(b): ans +...
vfc_140018
{ "difficulty": "easy", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1617/A", "time_limit": "1 second" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7\nabacaba\nabc\ncccba\nacb\ndbsic\nbac\nabracadabra\nabc\ndddddddddddd\ncba\nbbc\nabc\nac\nabc\n", "output": "aaaacbb\nabccc\nbcdis\naaaaacbbdrr\ndddddddddddd\nbbc\nac\n", "type": "stdin_stdout" }, { "fn_...
taco
verifiable_code
Solve the following coding problem using the programming language python: Today is external viva of computer science subject and Bosky is not at all prepared for it. Adding to his problems, he hasn't reached college yet. Luckily the external examiner was late too. Bosky somehow managed to reach the college before the ...
```python t=int(input()) def factors(n): count=[] for i in range(1,(int(n**.5))+1): if n%i==0: count.append(i) count.append(n/i) return len(set(count)) def gcd(a,b): if a%b==0: return b return gcd(b,a%b) def findTotal(n,r): return n-factors(r-1) for asfsd in range(t): n,r=(int(e) for e in input...
vfc_140022
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10\n981756253 222214880\n657750962 441987370\n420253542 134811149\n383766767 285392712\n860925640 57251957\n280092191 192232945\n326601984 158670005\n904352022 417098579\n511597444 208285363\n844871521 635543166", "output": "...
taco
verifiable_code
Solve the following coding problem using the programming language python: A palindrome is a word that reads the same forward and backward. Given a string s, you need to make it a palindrome by adding 0 or more characters to the end of s, and remember, we want the palindrome to be as short as possible. INPUT First li...
```python tc=int(input()) for case in range(tc): s=list(map(str,input())) l=len(s) for i in range(l): a=s[i:] b=a[::-1] if a==b: break print(l+i) ```
vfc_140030
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\nabdfhdyrbdbsdfghjkllkjhgfds\nzazazazazazazazazazazazazazazazazazazazazazazazaza\nbacba\na\nadwuaaxcnleegluqvsczaguujoppchwecusmevz\nkoikijiikmmkmonkiinnjlijmiimnniokikimikkkkjkmiinii", "output": "38\n51\n9\n1\n77\n95", ...
taco
verifiable_code
https://www.codechef.com/problems/XORTRV
Solve the following coding problem using the programming language python: There are K travellers who want to travel through a country one after the other. The country is in the form of a 2-d grid and is divided into N rows and M columns, such that each cell of the grid can be considered to be a city. Each city is in...
```python t = int(input()) for _ in range(t): (N, M, k) = map(int, input().split()) a = [] for _ in range(N): a.append(input()) dp = [0] * N for i in range(N): dp[i] = [0] * M dp[0][0] = k - 1 for i in range(1, N): if a[i - 1][0] == '1': dp[i][0] = (dp[i - 1][0] + 1) // 2 else: dp[i][0] = dp[i - 1]...
vfc_140044
{ "difficulty": "very_hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/XORTRV", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n2 2 1\n10\n01\n2 2 1\n10\n10\n2 2 2\n11\n10\n", "output": "2 2\n2 1\n2 2\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/min-coin5549/1
Solve the following coding problem using the programming language python: Given a list of coins of distinct denominations and total amount of money. Find the minimum number of coins required to make up that amount. Output -1 if that money cannot be made up using given coins. You may assume that there are infinite numb...
```python class Solution: def MinCoin(self, nums, W): import sys sys.setrecursionlimit(10 ** 9 + 7) n = len(nums) prev = [sys.maxsize for j in range(W + 1)] curr = [sys.maxsize for j in range(W + 1)] for j in range(W + 1): if j % nums[0] == 0: prev[j] = j // nums[0] for i in range(1, n): for j...
vfc_140048
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/min-coin5549/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "arr = [1, 2, 5], amount = 11", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "arr = [2, 6], amount = 7", "output": "-1", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/ISHVALA
Solve the following coding problem using the programming language python: Years after the Ishval Civil War, the Ishvalan refugees have now found a safe place for themselves which is a rectangular piece of land, surrounded by fences. The land can be thought of as a 2d grid which extends $N$ units vertically and $M$ un...
```python t = int(input()) for _ in range(t): (n, m) = map(int, input().split()) (x, y, s) = map(int, input().split()) if x > 0: xs = list(map(int, input().split())) xs = [0] + xs + [n + 1] else: xs = [0, n + 1] if y > 0: ys = list(map(int, input().split())) ys = [0] + ys + [m + 1] else: ys = [0, m + ...
vfc_140049
{ "difficulty": "medium_hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/ISHVALA", "time_limit": "0.5 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n7 8\n1 2 2\n5\n4 8\n6 5\n2 0 1\n1 4", "output": "6\n20", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: You are given N positive integers A1, A2, ... AN. Find the number of ways to distribute them in 2 groups in such a way that sum of numbers in each group is greater or equal K. The answer can be large so output it modulo 10^9 + 7. Input The firs...
```python MOD=1000000007 N,K=list(map(int,input().split())) A=list(map(int,input().split())) found=[0]*K found[0]=1 Kplus=0 if sum(A)<2*K: print(0) exit() for a in A: Kplus=Kplus*2 for j in range(max(0,K-a),K): Kplus+=found[j] Kplus%=MOD for j in range(K-1,a-1,-1): found[j]=(found[j]+found[j-a])%MOD print((...
vfc_140055
{ "difficulty": "medium_hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "100 99119\n81217 231120056 54419882 88760834 2112 65540576 35693123 62543 81795 239497212 79119636 239871505 111502084 67846 148754274 10370 141253092 233586721 56189 62785 88546 97503097 81049874 69624 28820 187253338 98897023 181...
taco
verifiable_code
https://codeforces.com/problemset/problem/1140/A
Solve the following coding problem using the programming language python: Ivan recently bought a detective book. The book is so interesting that each page of this book introduces some sort of a mystery, which will be explained later. The $i$-th page contains some mystery that will be explained on page $a_i$ ($a_i \ge ...
```python pages = int(input()) mysts = list(map(int, input().split())) days = 0 read_up_till = 0 for (i, ai) in enumerate(mysts): if ai >= read_up_till: read_up_till = ai if i == read_up_till - 1: days += 1 print(days) ```
vfc_140059
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1140/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "9\n1 3 3 6 7 6 8 8 9\n", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n1\n", "output": "1\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: Xavier challenges one of his friend to perform some crazy string functions by giving him some words and each word basically denotes a type of string function which his friend has to perform. WORDS WITH THEIR MEANING:- Wordrev n->To arrange eac...
```python def sort_words(seq, n): res = [] for x in range(n): cur = min(seq) seq.remove(cur) res.append(cur) for x in seq: res.append(x) return res s = input().strip().split() noc = eval(input()) while noc: noc-=1 ins = input().split() com = ins[0] ndx = int(ins[1]) res = [] if com == "Word...
vfc_140063
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "honesty is the best policy\n2\nWordrev 2\nsortword 3", "output": "madam", "type": "stdin_stdout" }, { "fn_name": null, "input": "my name is xavier\n2\nWordrev 3\nsortword 2", "output": "ym eman...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/primes-sum5827/1
Solve the following coding problem using the programming language python: Given a number N. Find if it can be expressed as sum of two prime numbers. Example 1: Input: N = 34 Output: "Yes" Explanation: 34 can be expressed as sum of two prime numbers. Example 2: Input: N = 23 Output: "No" Explanation: 23 cannnot be ex...
```python class Solution: def isSumOfTwo(self, N): if N & 1 == 0: return 'Yes' N = N - 2 for i in range(2, N): if N % i == 0: return 'No' else: return 'Yes' ```
vfc_140067
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/primes-sum5827/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 34", "output": "\"Yes\"", "type": "stdin_stdout" }, { "fn_name": null, "input": "N = 23", "output": "\"No\"", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1244/A
Solve the following coding problem using the programming language python: Tomorrow is a difficult day for Polycarp: he has to attend $a$ lectures and $b$ practical classes at the university! Since Polycarp is a diligent student, he is going to attend all of them. While preparing for the university, Polycarp wonders w...
```python from math import ceil for _ in range(int(input())): (a, b, c, d, k) = map(int, input().split()) (na, nb) = (ceil(a / c), ceil(b / d)) if na + nb > k: print(-1) else: print(na, nb) ```
vfc_140073
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1244/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n7 5 4 5 8\n7 5 4 5 2\n20 53 45 26 4\n", "output": "7 1\n-1\n1 3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "8\n80 72 20 12 10\n81 72 20 12 11\n80 73 20 12 11\n81 73 20 12 12\n80 73 ...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/preorder-traversal-iterative/1
Solve the following coding problem using the programming language python: Given a binary tree. Find the preorder traversal of the tree without using recursion. Example 1: Input: 1 / \ 2 3 / \ 4 5 Output: 1 2 4 5 3 Explanation: Preorder traversal (Root->Left->Right) of ...
```python class Solution: def preOrder(self, root): if not root: return None st = [] ans = [] st.append(root) while st: ans.append(st[-1].data) node = st.pop() if node.right: st.append(node.right) if node.left: st.append(node.left) return ans ```
vfc_140077
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/preorder-traversal-iterative/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\r\n / \\\r\n 2 3\r\n / \\\r\n 4 5", "output": "1 2 4 5 3", "type": "stdin_stdout" }, { "fn_name": null, "input": "8\r\n / \\\r\n 1 5\r\n ...
taco
verifiable_code
Solve the following coding problem using the programming language python: problem There is one bar-shaped candy with a length of N mm (where N is an even number). Two JOI officials decided to cut this candy into multiple pieces and divide them into a total of N / 2 mm. did. For unknown reasons, this candy has differ...
```python n = int(input()) dp = [float('inf')] * (n + 1) dp[0] = 0 cost = [int(input()) for _ in range(n - 1)] for i in range(1, n): for j in range(i): if dp[i - j] + cost[i - 1] < dp[j]: dp[j] = dp[i - j] + cost[i - 1] if dp[j] + cost[i - 1] < dp[i - j]: dp[i - j] = dp[j] + cost[i - 1] print(dp[n // 2]) ``...
vfc_140078
{ "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": "6\n1\n4\n12\n6\n2", "output": "6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n1\n7\n12\n6\n2", "output": "7\n", "type": "stdin_stdout" }, { "fn_name": null,...
taco
verifiable_code
https://codeforces.com/problemset/problem/1426/D
Solve the following coding problem using the programming language python: Kolya got an integer array $a_1, a_2, \dots, a_n$. The array can contain both positive and negative integers, but Kolya doesn't like $0$, so the array doesn't contain any zeros. Kolya doesn't like that the sum of some subsegments of his array c...
```python import sys, string from collections import deque, defaultdict from math import sqrt, factorial, gcd, ceil, atan, pi, log2 def input(): return sys.stdin.buffer.readline().decode('utf-8') from bisect import bisect_left, bisect_right from operator import add MOD = int(1000000000.0) + 7 INF = float('inf') def ...
vfc_140083
{ "difficulty": "medium", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1426/D", "time_limit": "2 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n1 -5 3 2\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n4 -2 3 -9 2\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, ...
taco
verifiable_code
https://www.codechef.com/problems/CHEFADD
Solve the following coding problem using the programming language python: Chef likes to solve difficult tasks. This time, he tried to solve the Big Famous Unsolvable $A+B=C$. One of his friends played a prank on Chef and randomly shuffled the bits in $A$ and $B$ (independently in each number). However, the funny thing...
```python import math def csb(n): count = 0 while n: n &= n - 1 count += 1 return count def f(ca, cb, i, cf, C, n, dp): if ca < 0 or cb < 0: return 0 if i == n: if ca == 0 and cb == 0 and (cf == 0): return 1 return 0 st = str(ca) + ' ' + str(cb) + ' ' + str(cf) + ' ' + str(i) if dp.get(st) != None...
vfc_140091
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/CHEFADD", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n1 2 3\n369 428 797\n", "output": "2\n56\n", "type": "stdin_stdout" } ] }