source
stringclasses
4 values
task_type
stringclasses
1 value
in_source_id
stringlengths
0
138
problem_statement
stringlengths
219
13.2k
gold_standard_solution
stringlengths
0
413k
problem_id
stringlengths
5
10
metadata
dict
verification_info
dict
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/juggler-sequence3930/1
Solve the following coding problem using the programming language python: Juggler Sequence is a series of integers in which the first term starts with a positive integer number a and the remaining terms are generated from the immediate previous term using the below recurrence relation: Given a number N, find the Juggl...
```python import math class Solution: def jugglerSequence(self, N): if N == 1: return [1] seq = [N] if N % 2 == 0: seq.extend(self.jugglerSequence(int(N ** 0.5))) else: seq.extend(self.jugglerSequence(int(N ** 1.5))) return seq ```
vfc_145173
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/juggler-sequence3930/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 9", "output": "9 27 140 11 36 6 2 1", "type": "stdin_stdout" }, { "fn_name": null, "input": "N = 6", "output": " 6 2 1", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/DISHOWN
Solve the following coding problem using the programming language python: Read problems statements in Mandarin Chinese and Russian. This summer, there is a worldwide competition being held in Chef Town and some of the best chefs of the world are participating. The rules of this competition are quite simple. Each ...
```python def find(child): new_parent = child while new_parent != parents[new_parent]: new_parent = parents[new_parent] while child != parents[child]: temp = parents[child] parents[child] = new_parent child = temp return new_parent def union(root1, root2): (real_root1, real_root2) = (find(root1), find(roo...
vfc_145174
{ "difficulty": "medium_hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/DISHOWN", "time_limit": "0.5 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n2\n1 2\n2\n0 1 2\n1 1", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n2\n1 3\n2\n0 1 2\n1 1", "output": "2\n", "type": "stdin_stdout" }, { "fn_...
taco
verifiable_code
https://codeforces.com/problemset/problem/507/C
Solve the following coding problem using the programming language python: Amr bought a new video game "Guess Your Way Out!". The goal of the game is to find an exit from the maze that looks like a perfect binary tree of height h. The player is initially standing at the root of the tree and the exit from the tree is lo...
```python import sys import math MAXNUM = math.inf MINNUM = -1 * math.inf ASCIILOWER = 97 ASCIIUPPER = 65 def getInt(): return int(sys.stdin.readline().rstrip()) def getInts(): return map(int, sys.stdin.readline().rstrip().split(' ')) def getString(): return sys.stdin.readline().rstrip() def printOutput(ans): s...
vfc_145178
{ "difficulty": "medium_hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/507/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 2\n", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 3\n", "output": "5", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 6\n", ...
taco
verifiable_code
https://codeforces.com/problemset/problem/1176/F
Solve the following coding problem using the programming language python: You are playing a computer card game called Splay the Sire. Currently you are struggling to defeat the final boss of the game. The boss battle consists of $n$ turns. During each turn, you will get several cards. Each card has two parameters: it...
```python from sys import stdin, stdout, exit n = int(input()) inf = 10 ** 18 dp = [[-inf] * 10 for i in range(n + 1)] dp[0][0] = 0 for i in range(n): k = int(stdin.readline()) cards = [] for j in range(k): (c, d) = map(int, stdin.readline().split()) cards.append((c, d)) cards.sort(reverse=True) cards_by_cost ...
vfc_145182
{ "difficulty": "hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1176/F", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n3\n1 6\n1 7\n1 5\n2\n1 4\n1 3\n3\n1 10\n3 5\n2 3\n3\n1 15\n2 4\n1 10\n1\n1 100\n", "output": "263\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n3\n1 1\n1 1\n1 1\n3\n1 1\n1 1\n1 1\n...
taco
verifiable_code
https://www.codechef.com/PTRN2021/problems/ITGUY52
Solve the following coding problem using the programming language python: The chef is trying to solve some pattern problems, Chef wants your help to code it. Chef has one number K to form a new pattern. Help the chef to code this pattern problem. -----Input:----- - First-line will contain $T$, the number of test case...
```python t = int(input()) for _ in range(t): k = int(input()) count = 1 for _ in range(k): output = [] for index in range(1, k + 1): output.append(bin(count).replace('0b', '')) count += 1 print(*output) ```
vfc_145186
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/PTRN2021/problems/ITGUY52", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n1\n2\n3\n4\n", "output": "1\n1 10\n11 100\n1 10 11\n100 101 110\n111 1000 1001\n1 10 11 100\n101 110 111 1000\n1001 1010 1011 1100\n1101 1110 1111 10000\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: There is a tree with N vertices, numbered 1 through N. The i-th edge in this tree connects Vertices A_i and B_i and has a length of C_i. Joisino created a complete graph with N vertices. The length of the edge connecting Vertices u and v in thi...
```python import sys input = sys.stdin.readline from collections import defaultdict n = int(input()) abd = [list(map(int, input().split())) for i in range(n - 1)] if n == 2: print(abd[0][2]) exit() graph = [[] for i in range(n + 1)] deg = [0 for i in range(n + 1)] for (a, b, d) in abd: graph[a].append((b, d)) graph...
vfc_145190
{ "difficulty": "unknown_difficulty", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": null, "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "8\n2 8 8\n1 5 1\n4 8 2\n2 5 4\n3 8 5\n6 8 9\n2 7 12", "output": "130\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n1 2 5\n3 4 10\n2 3 3\n2 5 2", "output": "44\n", "type": ...
taco
verifiable_code
https://codeforces.com/problemset/problem/401/B
Solve the following coding problem using the programming language python: Sereja is a coder and he likes to take part in Codesorfes rounds. However, Uzhland doesn't have good internet connection, so Sereja sometimes skips rounds. Codesorfes has rounds of two types: Div1 (for advanced coders) and Div2 (for beginner co...
```python (X, n) = list(map(int, input().split())) Taken = [True] * (X + 1) for i in range(n): x = list(map(int, input().split())) if x[0] == 1: Taken[x[1]] = False Taken[x[2]] = False else: Taken[x[1]] = False cnt = 0 minn = 0 maxx = 0 ans = 0 for i in range(1, X): if Taken[i]: cnt += 1 maxx += 1 else: ...
vfc_145196
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/401/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 2\n2 1\n2 2\n", "output": "0 0", "type": "stdin_stdout" }, { "fn_name": null, "input": "9 3\n1 2 3\n2 8\n1 4 5\n", "output": "2 3", "type": "stdin_stdout" }, { "fn_name": ...
taco
verifiable_code
https://www.codechef.com/problems/CHEFAPAR
Solve the following coding problem using the programming language python: Chef lives in a big apartment in Chefland. The apartment charges maintenance fees that he is supposed to pay monthly on time. But Chef is a lazy person and sometimes misses the deadlines. The apartment charges 1000 Rs per month as maintenance fe...
```python for i in range(int(input())): n = int(input()) p = list(map(int, input().split())) amount = p.count(0) * 1000 if p.count(0) != 0: q = p.index(0) print(100 * (n - q) + amount) else: print(amount) ```
vfc_145200
{ "difficulty": "easy", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/CHEFAPAR", "time_limit": "2 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n2\n1 1\n2\n0 0\n3\n0 1 0\n2\n0 1\n\n\n", "output": "0\n2200\n2300\n1200\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1243/B1
Solve the following coding problem using the programming language python: This problem is different from the hard version. In this version Ujan makes exactly one exchange. You can hack this problem only if you solve both problems. After struggling and failing many times, Ujan decided to try to clean up his house agai...
```python t = int(input()) for x in range(t): n = int(input()) s = input() t = input() i = c = 0 a = b = '' while c < 4 and i < n: if s[i] != t[i]: c += 1 a += s[i] b += t[i] i += 1 if c == 2 and len(set(a)) == len(set(b)) == 1: print('Yes') else: print('No') ```
vfc_145204
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1243/B1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n5\nsouse\nhouhe\n3\ncat\ndog\n2\naa\naz\n3\nabc\nbca\n", "output": "Yes\nNo\nNo\nNo\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n11\nartiovnldnp\nartiovsldsp\n2\naa\nzz\n2\naa\nx...
taco
verifiable_code
https://codeforces.com/problemset/problem/1326/C
Solve the following coding problem using the programming language python: You are given a permutation $p_1, p_2, \ldots, p_n$ of integers from $1$ to $n$ and an integer $k$, such that $1 \leq k \leq n$. A permutation means that every number from $1$ to $n$ is contained in $p$ exactly once. Let's consider all partitio...
```python (n, k) = [int(el) for el in input().split()] per = [int(el) for el in input().split()] sp = sorted(per, reverse=True) sp.append(0) mod = 998244353 result = 1 prev = 0 for (i, p) in enumerate(per, 1): if p > sp[k]: if not prev: prev = i else: result *= i - prev result %= mod prev = i print(sum...
vfc_145208
{ "difficulty": "easy", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1326/C", "time_limit": "1 second" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 2\n2 1 3\n", "output": "5 2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 5\n2 1 5 3 4\n", "output": "15 1\n", "type": "stdin_stdout" }, { "fn_name": null, ...
taco
verifiable_code
https://www.hackerrank.com/challenges/points-on-rectangle/problem
Solve the following coding problem using the programming language python: You are given $\textit{q}$ queries where each query consists of a set of $n$ points on a two-dimensional plane (i.e., $(x,y)$). For each set of points, print YES on a new line if all the points fall on the edges (i.e., sides and/or corners) of a...
```python def main(): for i in range(int(input())): p = [list(map(int, input().split())) for j in range(int(input()))] (px, py) = zip(*p) x0 = min(px) x1 = max(px) y0 = min(py) y1 = max(py) result = all((x in (x0, x1) or y in (y0, y1) for (x, y) in p)) print('YES' if result else 'NO') main() ```
vfc_145212
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.hackerrank.com/challenges/points-on-rectangle/problem", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n3\n0 0\n0 1\n1 0\n4\n0 0\n0 2\n2 0\n1 1\n", "output": "YES\nNO\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/EZSPEAK
Solve the following coding problem using the programming language python: *Words that contain many consecutive consonants, like "schtschurowskia", are generally considered somewhat hard to pronounce.* We say that a word is *hard to pronounce* if it contains 4 or more consonants in a row; otherwise it is *easy to pron...
```python for _ in range(int(input())): n = int(input()) s = input() if n <= 3: print('YES') else: for i in range(n - 3): string = s[i:i + 4] vow1 = 'a' in string or 'e' in string or 'i' in string vow2 = 'o' in string or 'u' in string if not vow1 and (not vow2): print('NO') break else: ...
vfc_145216
{ "difficulty": "easy", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/EZSPEAK", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n5\napple\n15\nschtschurowskia\n6\npolish\n5\ntryst\n3\ncry", "output": "YES\nNO\nYES\nNO\nYES\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: Singh is getting bored at work. He has a lot of ideas (N) to work on (as side projects) but is unable to choose one. He chooses a random number (R) and lines up his ideas in a circle. He starts counting from first and removes the R^th idea in t...
```python N, R = [int(i) for i in input().split()] r = 0 for i in range(1, N+1): r = (r+R)%i print(r+1) ```
vfc_145220
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "23 9000001", "output": "6", "type": "stdin_stdout" }, { "fn_name": null, "input": "23 9000000", "output": "4", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/358/A
Solve the following coding problem using the programming language python: Dima and Seryozha live in an ordinary dormitory room for two. One day Dima had a date with his girl and he asked Seryozha to leave the room. As a compensation, Seryozha made Dima do his homework. The teacher gave Seryozha the coordinates of n d...
```python length = int(input()) sequence = list(map(int, input().split())) if length <= 3: print('no') else: for i in range(length - 1): (w, x) = sorted([sequence[i], sequence[i + 1]]) for j in range(length - 1): (y, z) = sorted([sequence[j], sequence[j + 1]]) if w < y < x < z or y < w < z < x: print('y...
vfc_145224
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/358/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n0 10 5 15\n", "output": "yes\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n0 15 5 10\n", "output": "no\n", "type": "stdin_stdout" }, { "fn_name": null, ...
taco
verifiable_code
https://codeforces.com/problemset/problem/846/F
Solve the following coding problem using the programming language python: You are given an array a consisting of n positive integers. You pick two integer numbers l and r from 1 to n, inclusive (numbers are picked randomly, equiprobably and independently). If l > r, then you swap values of l and r. You have to calcula...
```python n = int(input()) arr = [0] arr = arr + list(map(int, input().split(' '))) def getCounts(arr): last = {} ans = 0.0 prev = 0.0 res = 0.0 for i in range(1, len(arr)): if arr[i] not in last: ans = prev + i else: ans = prev + i - last[arr[i]] prev = ans res += ans last[arr[i]] = i return res...
vfc_145228
{ "difficulty": "medium_hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/846/F", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n1 2\n", "output": "1.500000\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n2 2\n", "output": "1.000000\n", "type": "stdin_stdout" }, { "fn_name": null, ...
taco
verifiable_code
Solve the following coding problem using the programming language python: Rachel, being an awesome android programmer, just finished an App that will let us draw a triangle by selecting three points on the touch-plane.Now She asks her friend Bruce to draw a Right-Angled Triangle (we'll call it RAT) by selecting 3 inte...
```python def dist(x1,y1,x2,y2): return (x1-x2)*(x1-x2)+(y1-y2)*(y1-y2) def is_RAT(a): ab = dist(a[0],a[1],a[2],a[3]) bc = dist(a[4],a[5],a[2],a[3]) ca = dist(a[0],a[1],a[4],a[5]) if ab == bc+ca or ca == bc+ab or bc == ab+ca: return True return False def samepoint(a): if a[0]==a[2] and a[1] == a[3]: return...
vfc_145232
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "20\n0 0 1 0 4 1\n0 0 1 0 100 1\n60 4 90 -53 32 -12\n52 -34 -37 -63 23 54\n39 22 95 25 42 -33\n-10 -11 62 6 -12 -3\n22 -15 -24 77 -69 -60\n99 85 90 87 64 -20\n-50 -37 -93 -6 -80 -80\n4 -13 4 -49 -24 -13\n0 -3 -3 -10 4 -7\n-45 -87 -3...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/implementation-of-priority-queue-using-binary-heap/1
Solve the following coding problem using the programming language python: Given a binary heap implementation of Priority Queue. Extract the maximum element from the queue i.e. remove it from the Queue and return it's value. Example 1: Input: 4 2 8 16 24 2 6 5 Output: 24 Priority Queue after extracting maximum: 16 8...
```python class Solution: def extractMax(self): global s ans = H[0] H[0] = H[s] s -= 1 shiftDown(0) return ans ```
vfc_145236
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/implementation-of-priority-queue-using-binary-heap/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 2 8 16 24 2 6 5", "output": "24", "type": "stdin_stdout" }, { "fn_name": null, "input": "64 12 8 48 5", "output": "64", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1204/E
Solve the following coding problem using the programming language python: Natasha's favourite numbers are $n$ and $1$, and Sasha's favourite numbers are $m$ and $-1$. One day Natasha and Sasha met and wrote down every possible array of length $n+m$ such that some $n$ of its elements are equal to $1$ and another $m$ el...
```python P = 998244853 N = 4000 (f, fi) = ([0] * (N + 1), [0] * (N + 1)) f[0] = 1 for i in range(N): f[i + 1] = f[i] * (i + 1) % P fi[-1] = pow(f[-1], P - 2, P) for i in reversed(range(N)): fi[i] = fi[i + 1] * (i + 1) % P def C(n, r): c = 1 while n or r: (a, b) = (n % P, r % P) if a < b: return 0 c = c *...
vfc_145237
{ "difficulty": "hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1204/E", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "0 2\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 0\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 2\n",...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/find-difference-between-sum-of-diagonals1554/1
Solve the following coding problem using the programming language python: Given a matrix Grid[][] of size NxN. Calculate the absolute difference between the sums of its diagonals. Example 1: Input: N=3 Grid=[[1,2,3],[4,5,6],[7,8,9]] Output: 0 Explanation: Sum of primary diagonal = 1+5+9 = 15. Sum of secondary diagona...
```python class Solution: def diagonalSumDifference(self, N, Grid): (Grid1, Grid2) = (0, 0) for i in range(N): for j in range(N): if i == j: Grid1 += Grid[i][j] if i + j == N - 1: Grid2 += Grid[i][j] return abs(Grid1 - Grid2) ```
vfc_145241
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/find-difference-between-sum-of-diagonals1554/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N=3\nGrid=[[1,2,3],[4,5,6],[7,8,9]]", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "N=3\nGrid=[[1,1,1],[1,1,1],[1,1,1]]", "output": "0", "type": "stdin_stdout" ...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/leaders-in-an-array-1587115620/1
Solve the following coding problem using the programming language python: Given an array A of positive integers. Your task is to find the leaders in the array. An element of array is leader if it is greater than or equal to all the elements to its right side. The rightmost element is always a leader. Example 1: Inp...
```python class Solution: def leaders(self, A, N): leaders = [] max_right = A[N - 1] leaders.append(max_right) for i in range(N - 2, -1, -1): if A[i] >= max_right: leaders.append(A[i]) max_right = A[i] leaders.reverse() return leaders ```
vfc_145242
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/leaders-in-an-array-1587115620/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "n = 6\r\nA[] = {16,17,4,3,5,2}", "output": "17 5 2", "type": "stdin_stdout" }, { "fn_name": null, "input": "n = 5\r\nA[] = {1,2,3,4,0}", "output": "4 0", "type": "stdin_stdout" } ] ...
taco
verifiable_code
https://codeforces.com/problemset/problem/1012/C
Solve the following coding problem using the programming language python: Welcome to Innopolis city. Throughout the whole year, Innopolis citizens suffer from everlasting city construction. From the window in your room, you see the sequence of n hills, where i-th of them has height a_{i}. The Innopolis administratio...
```python from sys import stdin from math import ceil n = int(stdin.readline().strip()) s = tuple([0] + list(map(int, stdin.readline().strip().split())) + [0]) lim = ceil(n / 2) + 1 dp = [[2000000002 for i in range(n + 1)] for j in range(lim)] vis = [[False for i in range(n + 1)] for j in range(lim)] for i in range(n +...
vfc_145244
{ "difficulty": "hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1012/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n1 1 1 1 1\n", "output": "1 2 2 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n1 2 3\n", "output": "0 2 \n", "type": "stdin_stdout" }, { "fn_name": null, ...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/addition-of-two-numbers0812/1
Solve the following coding problem using the programming language python: Given two numbers A and B. Your task is to return the sum of A and B. Example 1: Input: A = 1, B = 2 Output: 3 Explanation: Addition of 1 and 2 is 3. Example 2: Input: A = 10, B = 20 Output: 30 Explanation: Addition os 10 and 20 is 30. You...
```python class Solution: def addition(ob, A, B): return A + B ```
vfc_145248
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/addition-of-two-numbers0812/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "A = 1, B = 2", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "A = 10, B = 20", "output": "30", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.hackerrank.com/challenges/twins/problem
Solve the following coding problem using the programming language python: Lia is fascinated by anything she considers to be a twin. She calls a pairs of positive integers, $\boldsymbol{i}$ and $j$, twins if: They are both prime. A prime number is an integer greater than $\mbox{1}$ that has no positive divisors other ...
```python limit = 1000000 (beg, end) = map(int, input().strip().split(' ')) is_prime = [False] * (limit + 1) prime = [] for x in range(1, int(limit ** 0.5) + 1): for y in range(1, int(limit ** 0.5) + 1): n = 4 * x ** 2 + y ** 2 if n <= limit and (n % 12 == 1 or n % 12 == 5): is_prime[n] = not is_prime[n] n = ...
vfc_145249
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.hackerrank.com/challenges/twins/problem", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 13\n", "output": "3\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/remove-bst-keys-outside-given-range/1
Solve the following coding problem using the programming language python: Given a Binary Search Tree (BST) and a range [min, max], remove all keys which are outside the given range. The modified tree should also be BST. Example 1: Input: Range = [-10, 13] Output: -8 6 7 13 Explanation: Nodes with values -13, 14 and 15...
```python class Solution: def removekeys(self, root, l, r): if root is None: return root root.left = self.removekeys(root.left, l, r) root.right = self.removekeys(root.right, l, r) if root.data > r: return root.left if root.data < l: return root.right return root ```
vfc_145253
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/remove-bst-keys-outside-given-range/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "Range = [-10, 13]", "output": "-8 6 7 13", "type": "stdin_stdout" }, { "fn_name": null, "input": "Range = [2, 6]\r\n 14\r\n / \\\r\n 4 16\r\n / \\ /\r\n 2 8 15\r\...
taco
verifiable_code
https://codeforces.com/problemset/problem/1740/D
Solve the following coding problem using the programming language python: Pak Chanek, a renowned scholar, invented a card puzzle using his knowledge. In the puzzle, you are given a board with $n$ rows and $m$ columns. Let $(r, c)$ represent the cell in the $r$-th row and the $c$-th column. Initially, there are $k$ ca...
```python import sys input = sys.stdin.readline def readList(): return list(map(int, input().split())) def readInt(): return int(input()) def readInts(): return map(int, input().split()) def readStr(): return input().strip() def solve(): (n, m, k) = readInts() arr = readList() isPresent = [False] * (k + 1) ...
vfc_145255
{ "difficulty": "medium", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1740/D", "time_limit": "1 second" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n3 3 6\n3 6 4 1 2 5\n3 3 10\n1 2 3 4 5 6 7 8 9 10\n5 4 4\n2 1 3 4\n3 4 10\n10 4 9 3 5 6 8 2 7 1\n", "output": "YA\nTIDAK\nYA\nYA\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: You are given two string S and T. Find the maximal length of some prefix of the string S which occurs in strings T as subsequence. Input The first line contains string S. The second line contains string T. Both strings consist of lowecase Latin...
```python from collections import deque, defaultdict, Counter from math import factorial from fractions import gcd from sys import stdin, exit from itertools import * import heapq import string import re def prase(T): if T == 1: return list(map(int, testcase.next().strip().split())) return testcase.next().strip(...
vfc_145259
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "informatika\ninformatikainformatikainformatika\n", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "qwertyuiopasdfghjklzxcvbnm\nmnbvcxzlkjhgfdsapoiuytrewq\n", "output": "11...
taco
verifiable_code
https://codeforces.com/problemset/problem/451/D
Solve the following coding problem using the programming language python: We call a string good, if after merging all the consecutive equal characters, the resulting string is palindrome. For example, "aabba" is good, because after the merging step it will become "aba". Given a string, you have to find two values: t...
```python def R(): return map(int, input().split()) def I(): return int(input()) def S(): return str(input()) def L(): return list(R()) from collections import Counter import math import sys from itertools import permutations import bisect mod = 10 ** 9 + 7 s = S() l = len(s) A = [0] * 2 B = [0] * 2 for i in ran...
vfc_145263
{ "difficulty": "hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/451/D", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "bb\n", "output": "1 2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "baab\n", "output": "2 4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "bab...
taco
verifiable_code
https://codeforces.com/problemset/problem/707/C
Solve the following coding problem using the programming language python: Katya studies in a fifth grade. Recently her class studied right triangles and the Pythagorean theorem. It appeared, that there are triples of positive integers such that you can construct a right triangle with segments of lengths corresponding ...
```python import sys, os, io def rs(): return sys.stdin.readline().rstrip() def ri(): return int(sys.stdin.readline()) def ria(): return list(map(int, sys.stdin.readline().split())) def ws(s): sys.stdout.write(s + '\n') def wi(n): sys.stdout.write(str(n) + '\n') def wia(a): sys.stdout.write(' '.join([str(x)...
vfc_145267
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/707/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n", "output": "4 5", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n", "output": "8 10", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n", ...
taco
verifiable_code
https://codeforces.com/problemset/problem/344/B
Solve the following coding problem using the programming language python: Mad scientist Mike is busy carrying out experiments in chemistry. Today he will attempt to join three atoms into one molecule. A molecule consists of atoms, with some pairs of atoms connected by atomic bonds. Each atom has a valence number — th...
```python a = list(map(int, input().split())) if sum(a) % 2 == 1 or max(a) > sum(a) - max(a): print('Impossible') elif len(set(a)) == 1: print(a[0] // 2, a[0] // 2, a[0] // 2) elif a.count(min(a)) == 2: pos = a.index(max(a)) ans = [0] * 3 ans[pos] = ans[pos - 1] = max(a) // 2 ans[pos - 2] = (min(a) * 2 - max(a)) ...
vfc_145271
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/344/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 1 2\n", "output": "0 1 1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 4 5\n", "output": "1 3 2\n", "type": "stdin_stdout" }, { "fn_name": null, "inpu...
taco
verifiable_code
https://www.codechef.com/ENAU2020/problems/ECAUG202
Solve the following coding problem using the programming language python: One day, Delta, the dog, got very angry. He has $N$ items with different values, and he decided to destroy a few of them. However, Delta loves his hooman as well. So he only destroyed those items whose Least Significant Bit in binary representat...
```python for test in range(int(input())): n = int(input()) ar = list(map(int, input().split())) count = 0 for item in ar: if bin(item)[-1] == '0': count += item print(count) ```
vfc_145275
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/ENAU2020/problems/ECAUG202", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n5\n1 2 3 4 5\n", "output": "6\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/CLASSES
Solve the following coding problem using the programming language python: Chef's college is starting next week. There are $S$ subjects in total, and he needs to choose $K$ of them to attend each day, to fulfill the required number of credits to pass the semester. There are $N + 1$ buildings. His hostel is in building ...
```python from collections import deque def BFS(bldg, s): queue = deque() queue.append(s) cost = [-1 for i in range(n + 1)] cost[s] = 0 while queue: s = queue.popleft() for i in bldg[s]: if cost[i] == -1: queue.append(i) cost[i] = cost[s] + 1 return cost for _ in range(int(input())): (n, m, s, k)...
vfc_145279
{ "difficulty": "very_hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/CLASSES", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n2 3 2 2\n0 1\n1 2\n2 0\n1 2\n2 2 2 2\n0 1\n1 2\n1 2\n6 7 5 3\n0 1\n0 2\n0 4\n1 3\n1 4\n2 5\n2 6\n1 2 3 5 6", "output": "4\n6\n8", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/maximum-number-of-partitions-that-can-be-sorted-individually-to-make-sorted2926/1
Solve the following coding problem using the programming language python: Given an array arr[ ] of size n such that elements of arr[ ] in range [0, 1, ..n-1]. Our task is to divide the array into the maximum number of partitions that can be sorted individually, then concatenated to make the whole array sorted. Exampl...
```python def maxPartitions(arr, n): a = arr[0] c = 0 for i in range(n): if a < arr[i]: a = arr[i] if a == i: c += 1 return c ```
vfc_145283
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/maximum-number-of-partitions-that-can-be-sorted-individually-to-make-sorted2926/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": "maxPartitions", "input": "arr[ ] = {2, 1, 0, 3}", "output": "2", "type": "function_call" }, { "fn_name": "maxPartitions", "input": "arr[ ] = {2, 1, 0, 3, 4, 5}", "output": "4", "type": "function_call" ...
taco
verifiable_code
https://codeforces.com/problemset/problem/634/A
Solve the following coding problem using the programming language python: A remote island chain contains n islands, labeled 1 through n. Bidirectional bridges connect the islands to form a simple cycle — a bridge connects islands 1 and 2, islands 2 and 3, and so on, and additionally a bridge connects islands n and 1. ...
```python input() l1 = [int(x) for x in input().split() if x != '0'] l2 = [int(x) for x in input().split() if x != '0'] m = len(l1) x = l1.index(l2[0]) b = True for i in range(len(l1)): b &= l2[i] == l1[(x + i) % m] print('YES' if b else 'NO') ```
vfc_145284
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/634/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1 0 2\n2 0 1\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1 0\n0 1\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": null,...
taco
verifiable_code
https://www.hackerrank.com/challenges/python-string-formatting/problem
Solve the following coding problem using the programming language python: Given an integer, $n$, print the following values for each integer $\boldsymbol{i}$ from $\mbox{1}$ to $n$: Decimal Octal Hexadecimal (capitalized) Binary Function Description Complete the print_formatted function in the editor below. ...
```python N = int(input()) width = len(str(bin(N))) - 2 for n in range(1, N + 1): for base in 'doXb': print('{0:{width}{base}}'.format(n, base=base, width=width), end=' ') print() ```
vfc_145288
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.hackerrank.com/challenges/python-string-formatting/problem", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "17\n", "output": " 1 1 1 1\n 2 2 2 10\n 3 3 3 11\n 4 4 4 100\n 5 5 5 101\n 6 6 6 110\n 7 7 7 111\n 8 10 8 1000\n 9 ...
taco
verifiable_code
https://codeforces.com/problemset/problem/163/A
Solve the following coding problem using the programming language python: One day Polycarpus got hold of two non-empty strings s and t, consisting of lowercase Latin letters. Polycarpus is quite good with strings, so he immediately wondered, how many different pairs of "x y" are there, such that x is a substring of st...
```python from sys import stdin s = [ord(i) - 97 for i in stdin.readline().strip()] s1 = [ord(i) - 97 for i in stdin.readline().strip()] n = len(s) m = len(s1) mod = 1000000007 dp = [[0 for i in range(n)] for j in range(26)] for i in range(m): arr = [0 for j in range(n)] for j in range(n): if s1[i] == s[j]: arr[...
vfc_145293
{ "difficulty": "medium_hard", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/163/A", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "bbabb\nbababbbbab\n", "output": "222\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "ab\nbbbba\n", "output": "5\n", "type": "stdin_stdout" }, { "fn_name": null, ...