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://www.codechef.com/problems/PRITREE
Solve the following coding problem using the programming language python: Read problems statements [Hindi] , [Vietnamese] , [Mandarin Chinese] , [Russian] and [Bengali] as well. Chef loves prime numbers and trees. One day, Chef received $N$ nodes (numbered $1$ through $N$) as a gift. There are no edges between them ...
```python def union(parent, size, a, b): x = find(parent, a) y = find(parent, b) if x != y: if size[x] < size[y]: parent[x] = y size[y] = size[x] + size[y] else: parent[y] = x size[x] = size[x] + size[y] return (parent, size) def find(parent, a): while a != parent[a]: parent[a] = parent[parent[a...
vfc_132416
{ "difficulty": "very_hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/PRITREE", "time_limit": "2 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n1 5 2 3\n", "output": "1 3\n3 2\n3 4\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.hackerrank.com/challenges/bday-gift/problem
Solve the following coding problem using the programming language python: Isaac has to buy a new HackerPhone for his girlfriend Amy. He is exploring the shops in the town to compare the prices whereupon he finds a shop located on the first floor of a building, that has a unique pricing policy. There are N steps leadin...
```python import sys N = int(sys.stdin.readline()) balls = [int(sys.stdin.readline()) for _ in range(N)] print('%.1f' % (sum(balls) / 2)) ```
vfc_132420
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.hackerrank.com/challenges/bday-gift/problem", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1 \n1\n2\n", "output": "2.0\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/solve-the-sudoku-1587115621/1
Solve the following coding problem using the programming language python: Given an incomplete Sudoku configuration in terms of a 9 x 9 2-D square matrix (grid[][]), the task to find a solved Sudoku. For simplicity, you may assume that there will be only one unique solution. A sudoku solution must satisfy all of the f...
```python class Solution: def isSafe(self, grid, r, c, val): for i in range(9): if grid[r][i] == val: return False if grid[i][c] == val: return False if grid[3 * (r // 3) + i // 3][3 * (c // 3) + i % 3] == val: return False return True def SolveSudoku(self, grid): for i in range(9): fo...
vfc_132424
{ "difficulty": "medium_hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/solve-the-sudoku-1587115621/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "grid[][] = \n[[3 0 6 5 0 8 4 0 0],\n[5 2 0 0 0 0 0 0 0],\n[0 8 7 0 0 0 0 3 1 ],\n[0 0 3 0 1 0 0 8 0],\n[9 0 0 8 6 3 0 0 5],\n[0 5 0 0 9 0 6 0 0],\n[1 3 0 0 0 0 2 5 0],\n[0 0 0 0 0 0 0 7 4],\n[0 0 5 2 0 6 3 0 0]]", "output": "...
taco
verifiable_code
https://www.codechef.com/OCT12/problems/LUCKY10
Solve the following coding problem using the programming language python: The Little Elephant loves lucky strings. Everybody knows that the lucky string is a string of digits that contains only the lucky digits 4 and 7. For example, strings "47", "744", "4" are lucky while "5", "17", "467" are not. The Little Elephan...
```python t = int(input()) for i in range(0, t): a = input() b = input() agts = bgts = afour = bfour = aseven = bseven = altf = bltf = afts = bfts = 0 for j in a: if j >= '7': if j > '7': agts += 1 else: aseven += 1 elif j >= '4': if j > '4': afts += 1 else: afour += 1 else: alt...
vfc_132429
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/OCT12/problems/LUCKY10", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n4\n7\n435\n479\n7\n8\n1675475\n9756417\n\n\n", "output": "7\n74\n\n777744\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/579/A
Solve the following coding problem using the programming language python: You are a lover of bacteria. You want to raise some bacteria in a box. Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split into two bacteria. You hop...
```python x = int(input()) s = 0 while x: s += x % 2 x //= 2 print(s) ```
vfc_132433
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/579/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "8\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "536870911\n...
taco
verifiable_code
Solve the following coding problem using the programming language python: <image> There is a container that is bifurcated as shown in the figure. Drop 10 balls numbered from 1 to 10 through the opening A of the container and place the balls in the left cylinder B or the right cylinder C. Since plate D can rotate lef...
```python n = int(input()) i = 1 while i <= n: ball = list(map(int, input().split())) left = [0] right = [0] m = 0 while True: if m == 10: print('YES') break if ball[m] < left[len(left) - 1] and ball[m] < right[len(right) - 1]: print('NO') break if ball[m] > left[len(left) - 1] and ball[m] > righ...
vfc_132437
{ "difficulty": "unknown_difficulty", "memory_limit": "134.217728 megabytes", "memory_limit_bytes": null, "problem_url": null, "time_limit": "1.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n3 1 4 2 5 6 7 8 9 10\n11 9 8 7 6 5 4 3 2 1", "output": "YES\nNO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n3 1 4 2 5 6 7 8 1 10\n11 9 8 7 6 5 4 3 2 1", "output": "NO\nNO\n...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/maximum-weight-transformation-of-a-given-string3551/1
Solve the following coding problem using the programming language python: Given string s consisting of only A’s and B’s. You can transform the given string to another string by toggling any character. Thus many transformations of the given string are possible. The task is to find the Weight of the maximum weight trans...
```python class Solution: def getMaxWeight(self, s): n = len(s) dp = [0] * (n + 1) dp[1] = 1 for i in range(2, n + 1): if s[i - 1] == s[i - 2]: dp[i] = max(dp[i - 2] + 3, dp[i - 1] + 1) else: dp[i] = dp[i - 2] + 4 return dp[n] ```
vfc_132441
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/maximum-weight-transformation-of-a-given-string3551/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "s = \"AA\"", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "s = \"ABB\"", "output": "5", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1159/D
Solve the following coding problem using the programming language python: Let s be some string consisting of symbols "0" or "1". Let's call a string t a substring of string s, if there exists such number 1 ≤ l ≤ |s| - |t| + 1 that t = s_l s_{l+1} … s_{l + |t| - 1}. Let's call a substring t of string s unique, if there...
```python (n, k) = map(int, input().split()) strr = '' while len(strr) < n: strr += '0' * ((n - k) // 2) + '1' strr = strr[:n] print(strr) ```
vfc_132442
{ "difficulty": "hard", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1159/D", "time_limit": "1.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "100000 33334\n", "output": "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
taco
verifiable_code
https://codeforces.com/problemset/problem/894/A
Solve the following coding problem using the programming language python: "QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth. Now Diamond has given Bort a string consisting of only uppercase English letters of length n. There is a great number of "QAQ" in the string (...
```python import sys import math import bisect def main(): s = input() n = len(s) ans = 0 for i in range(n): for j in range(i + 1, n): for k in range(j + 1, n): if s[i] + s[j] + s[k] == 'QAQ': ans += 1 print(ans) main() ```
vfc_132447
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/894/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "QAQAQYSYIOIWIN\n", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "QAQQQZZYNOIWIN\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, ...
taco
verifiable_code
Solve the following coding problem using the programming language python: Xenny had a list of N strings of equal length. He wanted to sort them by the first M characters only. That means, while sorting the list of strings, he only wanted to consider the first M characters of each string. Help Xenny to find out the K^t...
```python for t in range(eval(input())): n,k,m = list(map(int,input().split())) ary = [input() for i in range(n)] ary2 = list(enumerate([i[:m] for i in ary])) ary2.sort(key=lambda x:x[1]) ary3 = [i[m:] for i in ary] print(ary2[k-1][1]+ary3[ary2[k-1][0]]) ```
vfc_132451
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n5 5 10\nvjrfndbprs\nfasidbjtnr\nmsdlpklqsc\nsfqfcebvfe\ncqtuiliqag\n6 2 10\ngrydfiyhde\nyibnrsompe\nsezxcdrotm\nflebazeeus\nzvuqelenaj\naudnepqvhs\n7 4 10\ngbygfvdmcn\nhumquwkfqw\ncrtfosgcyj\nadoypofjmi\nzqfefxvnzd\ntzxnzdgnio\n...
taco
verifiable_code
https://codeforces.com/problemset/problem/755/A
Solve the following coding problem using the programming language python: PolandBall is a young, clever Ball. He is interested in prime numbers. He has stated a following hypothesis: "There exists such a positive integer n that for each positive integer m number n·m + 1 is a prime number". Unfortunately, PolandBall i...
```python def is_prime(adad): if adad == 2: return True else: saquare = int(adad ** 0.5) + 1 counter = 2 while counter < saquare: if adad % counter != 0: counter += 1 else: return False return True vurudi_asli = int(input()) prime_check = True zarib = 1 while prime_check: vurudi = vurudi_asli...
vfc_132455
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/755/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n", "output": "2", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: Problem Statement: Dom and Brian were trying to evade the truck drivers of Verone's gang. They were too fast, too furious for them, and could get away from the truck drivers easily. They decided to race with each other, and divided the city int...
```python import math for i in range(int(input())): try: dom=input().split(' ') except (EOFError): break try: brian=input().split(' ') except (EOFError): break mdom=0 mbrian=0 n=len(dom) for i in range(n-1): k=math.fabs(int(dom[i+1])-int(dom[i])) if k>mdom: mdom=k l=math.fabs(int(brian[i+1])-in...
vfc_132459
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n-829 -501 -266 -40\n795 -962 182 352\n", "output": "Dom\n1991655\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "393\n221 -269 137 -126 -759 -852 -950 885 -507 -656 -681 760 74 -174 -43...
taco
verifiable_code
Solve the following coding problem using the programming language python: The nth triangular number is defined as the sum of the first n positive integers. The nth tetrahedral number is defined as the sum of the first n triangular numbers. It is easy to show that the nth tetrahedral number is equal to n(n+1)(n+2) ⁄ 6....
```python def main(): INIT = 100 query = [] ans = [] while True: q = int(input()) if q == 0: break query.append(q) MAX = max(query) table = [INIT] * (MAX + 1) table[0] = 0 all_item = [i * (i + 1) * (i + 2) // 6 for i in range(1, 181)] odd_item = [i for i in all_item if i % 2] eve_item = [i for i in a...
vfc_132463
{ "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": "40\n14\n5\n165\n120\n133\n106\n139\n0", "output": "2 6\n2 14\n2 5\n1 1\n1 18\n4 31\n4 4\n3 37\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/903/B
Solve the following coding problem using the programming language python: Vova is again playing some computer game, now an RPG. In the game Vova's character received a quest: to slay the fearsome monster called Modcrab. After two hours of playing the game Vova has tracked the monster and analyzed its tactics. The Mod...
```python (h1, a1, c1) = [int(j) for j in input().split()] (h2, a2) = [int(j) for j in input().split()] att = 0 if h2 % a1 == 0: att = int(h2 / a1) else: att = int(h2 // a1 + 1) i = 0 moves = 0 h11 = h1 while i < att: if i == att - 1: i += 1 moves += 1 h11 -= a2 elif h11 <= a2: h11 += c1 - a2 moves += 1 ...
vfc_132467
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/903/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10 6 100\n17 5\n", "output": "4\nSTRIKE\nHEAL\nSTRIKE\nSTRIKE\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "11 6 100\n12 5\n", "output": "2\nSTRIKE\nSTRIKE\n", "type": "stdin...
taco
verifiable_code
https://codeforces.com/problemset/problem/1437/F
Solve the following coding problem using the programming language python: $n$ fishermen have just returned from a fishing vacation. The $i$-th fisherman has caught a fish of weight $a_i$. Fishermen are going to show off the fish they caught to each other. To do so, they firstly choose an order in which they show thei...
```python M = 998244353 n = int(input()) l = sorted(map(int, input().split()))[::-1] out = [0] * n big = 0 if l[0] >= 2 * l[1]: out[1] = 1 big = 1 for i in range(2, n): new = [0] * n bigN = 0 for j in range(i): if l[j] >= 2 * l[i]: big += out[j] else: new[j] += out[j] * (i - 1) new[j] %= M new[i] = b...
vfc_132475
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1437/F", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n1 1 4 9\n", "output": "20\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1294/A
Solve the following coding problem using the programming language python: Polycarp has three sisters: Alice, Barbara, and Cerene. They're collecting coins. Currently, Alice has $a$ coins, Barbara has $b$ coins and Cerene has $c$ coins. Recently Polycarp has returned from the trip around the world and brought $n$ coins...
```python t = int(input()) for i in range(t): (a, b, c, n) = map(int, input().split()) maximum = max(a, b, c) temp = maximum - a + (maximum - b) + (maximum - c) n = n - temp if n >= 0 and (n / 3).is_integer(): print('YES') else: print('NO') ```
vfc_132479
{ "difficulty": "easy", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1294/A", "time_limit": "2 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n5 3 2 8\n100 101 102 105\n3 2 1 100000000\n10 20 15 14\n101 101 101 3\n", "output": "YES\nYES\nNO\nNO\nYES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n1 1 1 1111\n", "outpu...
taco
verifiable_code
https://codeforces.com/problemset/problem/1260/D
Solve the following coding problem using the programming language python: You are playing a computer game, where you lead a party of $m$ soldiers. Each soldier is characterised by his agility $a_i$. The level you are trying to get through can be represented as a straight line segment from point $0$ (where you and you...
```python import sys input = sys.stdin.readline (M, N, K, T) = map(int, input().split()) A = list(map(int, input().split())) LRD = [list(map(int, input().split())) for _ in range(K)] A.append(10 ** 15) A.sort(reverse=True) l = 0 r = M + 1 while r - l > 1: m = (r + l) // 2 D_limit = A[m] P = [0] * (N + 2) for (L, R,...
vfc_132484
{ "difficulty": "hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1260/D", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 6 4 14\n1 2 3 4 5\n1 5 2\n1 2 5\n2 3 5\n3 5 3\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 2 5 3\n5 2 10\n1 2 3\n1 1 9\n1 1 2\n2 2 4\n1 2 9\n", "output": "1\n...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/distributing-balls1659/1
Solve the following coding problem using the programming language python: Geek wants to distribute M balls among N children. His nemesis Keeg wants to disrupt his plan and removes P balls from Geek's bag. The minimum number of balls required to make each child happy are given in an array arr[]. Find the number of ways...
```python class Solution: def countWays(self, m, n, p, arr): m = m - p if sum(arr) > m: return -1 mod = int(1000000000.0 + 7) dp = [[0 for i in range(m + 1)] for j in range(n)] for i in range(1, m + 1): dp[0][i] = 1 if i >= arr[0] else 0 for i in range(1, n): for j in range(m + 1): if j >= ar...
vfc_132490
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/distributing-balls1659/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "m = 13, n = 4, p = 5\r\narr = {2, 3, 1, 3}", "output": "-1", "type": "stdin_stdout" }, { "fn_name": null, "input": "m = 30, n = 10, p = 14\r\narr = {2, 2, 1, 1, 1, 2, 2, 3, 1, 1}", "output": "1...
taco
verifiable_code
https://www.codechef.com/problems/ROBOTG
Solve the following coding problem using the programming language python: There is a rectangular grid of cells consisting of n rows and m columns. You will place a robot on one of the grid cells and provide it with a command string s, consisting of characters ‘L’, ‘R’, ‘U’, ‘D’. After being placed, the robot will foll...
```python test = int(input()) for _ in range(test): b = list(map(int, str(input()).split(' '))) c = str(input()) li1 = [0] li2 = [0] for i1 in range(len(c)): if c[i1] == 'R': li1.append(li1[len(li1) - 1] + 1) elif c[i1] == 'L': li1.append(li1[len(li1) - 1] - 1) elif c[i1] == 'U': li2.append(li2[len(...
vfc_132491
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/ROBOTG", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n1 1\nR\n2 3\nLLRU\n3 2\nLLRU\n4 3\nULURUDRDLD\n3 6\nRURUR\n", "output": "unsafe\nsafe\nunsafe\nsafe\nsafe\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/978/C
Solve the following coding problem using the programming language python: There are $n$ dormitories in Berland State University, they are numbered with integers from $1$ to $n$. Each dormitory consists of rooms, there are $a_i$ rooms in $i$-th dormitory. The rooms in $i$-th dormitory are numbered from $1$ to $a_i$. A...
```python (n, m) = [int(x) for x in input().split()] dorms = [int(x) for x in input().split()] letters = [int(x) for x in input().split()] sm = 0 idx = 1 for i in range(len(letters)): room = letters[i] while sm + dorms[idx - 1] < room: sm += dorms[idx - 1] idx += 1 print(idx, room - sm) ```
vfc_132496
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/978/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 6\n10 15 12\n1 9 12 23 26 37\n", "output": "1 1\n1 9\n2 2\n2 13\n3 1\n3 12\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 3\n5 10000000000\n5 6 9999999999\n", "output": "1 5\n2 ...
taco
verifiable_code
https://codeforces.com/problemset/problem/991/E
Solve the following coding problem using the programming language python: This night wasn't easy on Vasya. His favorite team lost, and he didn't find himself victorious either — although he played perfectly, his teammates let him down every time. He had to win at least one more time, but the losestreak only grew longe...
```python from collections import Counter from itertools import product s = input() ds = Counter(s) fac = [1 for i in range(100)] for i in range(1, 100): fac[i] = fac[i - 1] * i res = 0 for possib in product(*[zip([k] * n, range(1, n + 1)) for (k, n) in ds.items()]): possib = list(possib) non_zero_sum = sum((v for (...
vfc_132500
{ "difficulty": "medium_hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/991/E", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "97\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2028\n", "output": "13\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/975/D
Solve the following coding problem using the programming language python: Ghosts live in harmony and peace, they travel the space without any purpose other than scare whoever stands in their way. There are $n$ ghosts in the universe, they move in the $OXY$ plane, each one of them has its own velocity that does not ch...
```python from collections import Counter from sys import stdin (n, a, b) = map(int, stdin.readline().split()) s = Counter() ans = 0 for i in range(n): (x, vx, vy) = map(int, stdin.readline().split()) tmp = vy - a * vx ans += s[tmp] - s[vx, vy] s[tmp] += 1 s[vx, vy] += 1 print(ans * 2) ```
vfc_132513
{ "difficulty": "hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/975/D", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 1 1\n1 -1 -1\n2 1 1\n3 1 1\n4 -1 -1\n", "output": "8\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: Russian Translation Available You have a graph with N vertices and M edges. Someone has chosen N-1 edges of these M and claims that they form a spanning tree. Just check whether it's true or not. Input The first line contains one integer T de...
```python t=int(input()) while t!=0: n,m=list(map(int,input().split())) flag=[False]*(n+1) q=[] for _ in range(m): x,y=list(map(int,input().split())) q.append((x,y)) u=list(map(int,input().split())) #print u[n-1] for i in range(0,n-1): flag[q[u[i]-1][0]]=True flag[q[u[i]-1][1]]=True g=True ...
vfc_132517
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "20\n46 1035\n6 19\n10 43\n12 15\n16 23\n7 21\n1 18\n22 35\n19 30\n16 19\n29 35\n16 35\n5 34\n2 27\n5 39\n16 31\n4 10\n15 31\n13 34\n29 40\n8 45\n27 37\n10 41\n18 30\n23 29\n20 46\n8 26\n3 28\n1 14\n14 44\n42 44\n17 44\n4 15\n5 20\n...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/coin-change2448/1
Solve the following coding problem using the programming language python: Given an integer array coins[ ] of size N representing different denominations of currency and an integer sum, find the number of ways you can make sum by using different combinations from coins[ ]. Note: Assume that you have an infinite suppl...
```python class Solution: def count(self, coins, N, Sum): table = [0 for k in range(sum + 1)] table[0] = 1 for i in range(0, N): for j in range(coins[i], sum + 1): table[j] += table[j - coins[i]] return table[Sum] ```
vfc_132522
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/coin-change2448/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 3, sum = 4\ncoins = {1,2,3}", "output": "4", "type": "stdin_stdout" }, { "fn_name": null, "input": "N = 4, Sum = 10\ncoins = {2,5,3,6}", "output": "5", "type": "stdin_stdout" } ...
taco
verifiable_code
Solve the following coding problem using the programming language python: "Balloons should be captured efficiently", the game designer says. He is designing an oldfashioned game with two dimensional graphics. In the game, balloons fall onto the ground one after another, and the player manipulates a robot vehicle on th...
```python import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools sys.setrecursionlimit(10 ** 7) inf = 10 ** 20 eps = 1.0 / 10 ** 10 mod = 10 ** 9 + 7 dd = [(0, -1), (1, 0), (0, 1), (-1, 0)] ddn = [(0, -1), (1, -1), (1, 0), (1, 1), (0, 1), (-1, -1), (-1, 0), ...
vfc_132523
{ "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\n10 100\n100 270\n2\n10 100\n100 280\n3\n100 150\n10 360\n40 450\n3\n100 150\n9 360\n40 440\n2\n100 10\n50 200\n2\n100 100\n50 110\n1\n15 10\n4\n1 10\n2 20\n3 100\n90 200\n0", "output": "OK 220\nOK 200\nOK 260\nOK 280\nNG 1...
taco
verifiable_code
https://codeforces.com/problemset/problem/1373/B
Solve the following coding problem using the programming language python: Alica and Bob are playing a game. Initially they have a binary string $s$ consisting of only characters 0 and 1. Alice and Bob make alternating moves: Alice makes the first move, Bob makes the second move, Alice makes the third one, and so on....
```python def solve(): a = input() ones = 0 zero = 0 for i in a: if i == '0': zero += 1 else: ones += 1 minor = min(zero, ones) if minor % 2: print('DA') else: print('NET') t = int(input()) for test in range(t): solve() ```
vfc_132531
{ "difficulty": "easy", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1373/B", "time_limit": "1 second" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n01\n1111\n0011\n", "output": "DA\nNET\nNET\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: Hope you still have not forgotten about pig Benny. She is asking for help again. This time you have to answer some queries that Benny will give you. All actions happen in the Universe where each planet has its own id starting from 0. There ...
```python N,Q=list(map(int, input().split())) arrD=list(map(int, input().split())) if N==1: for iCase in range(Q): print("YES" if int(input())%arrD[0]==0 else "NO") else: gcd=arrD[0] for i in range(1,N): b=arrD[i] while b: gcd,b=b,gcd%b if gcd>1: for i in range(N): arrD[i]/=gcd MAX=1000000001 min...
vfc_132535
{ "difficulty": "medium_hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1000 100000\n329840658 976629293 990996624 944560277 818418687 323075146 878280978 258769540 485256799 715596328 912023268 429754762 900763267 515983960 396410906 776785920 680829099 694757449 712818376 320140591 156360396 22215341...
taco
verifiable_code
Solve the following coding problem using the programming language python: Chandu is weak in maths. His teacher gave him homework to find maximum possible pair XOR in a matrix of size N x M with some conditions. Condition imposed is that, the pair can be formed between sum of elements in a column and sum of elements in...
```python n,m = list(map(int, input().split())) arr = [] check = n row, col = [0]*n, [0]*m while check>0: arr.append([int(x) for x in input().split()]) check -= 1 for i in range(n): for j in range(m): row[i] += arr[i][j] col[j] += arr[i][j] result = 0 for i in range(n): for j in range(m): result = max(result,...
vfc_132539
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "9 2\n16 17 \n7 20 \n9 18 \n12 10 \n2 17 \n6 16 \n7 11 \n17 9 \n18 9 \n", "output": "3145725\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 1\n9 \n16 \n16 \n", "output": "57\n", ...
taco
verifiable_code
Solve the following coding problem using the programming language python: problem To the west of the Australian continent is the wide Indian Ocean. Marine researcher JOI is studying the properties of N species of fish in the Indian Ocean. For each type of fish, a rectangular parallelepiped habitat range is determine...
```python (n, k) = map(int, input().split()) plst = [] xlst = [] ylst = [] dlst = [] for _ in range(n): (x1, y1, d1, x2, y2, d2) = map(int, input().split()) plst.append((x1, y1, d1, x2, y2, d2)) xlst.append(x1) xlst.append(x2) ylst.append(y1) ylst.append(y2) dlst.append(d1) dlst.append(d2) xlst = list(set(xlst)...
vfc_132544
{ "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": "3 2\n10 50 0 50 70 100\n10 20 20 70 90 60\n40 60 20 90 90 70", "output": "65000\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 2\n10 50 0 50 70 100\n10 20 20 70 90 60\n40 60 20 90 90 98...
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 def cp(sa): n=len(sa) st="" for i in range(n-1,-1,-1): st+=sa[i] return st==sa t=eval(input()) for c in range(0,t): s=input() n=len(s) if(cp(s)): print(n) continue mlength=2*n for i in range(n,mlength): st=s+s[i-n::-1] #print st if(cp(st)): print(len(st)) break ```
vfc_132548
{ "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://practice.geeksforgeeks.org/problems/prime-number2314/1
Solve the following coding problem using the programming language python: For a given number N check if it is prime or not. A prime number is a number which is only divisible by 1 and itself. Example 1: Input: N = 5 Output: 1 Explanation: 5 has 2 factors 1 and 5 only. Example 2: Input: N = 25 Output: 0 Explanation: ...
```python class Solution: def isPrime(self, N): if N < 2: return 0 i = 2 while i <= N ** 0.5: if N % i == 0: return 0 i = i + 1 return 1 ```
vfc_132564
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/prime-number2314/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 5", "output": "1", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/maximum-sum-of-non-adjacent-nodes/1
Solve the following coding problem using the programming language python: Given a binary tree with a value associated with each node, we need to choose a subset of these nodes such that sum of chosen nodes is maximum under a constraint that no two chosen node in subset should be directly connected that is, if we have ...
```python class Solution: def sol(self, root): if root is None: return [0, 0] leftAns = self.sol(root.left) rightAns = self.sol(root.right) a = root.data + leftAns[1] + rightAns[1] b = max(leftAns[0], leftAns[1]) + max(rightAns[0], rightAns[1]) return [a, b] def getMaxSum(self, root): ans = self.so...
vfc_132565
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/maximum-sum-of-non-adjacent-nodes/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "11\n / \\\n 1 2", "output": "11", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n / \\\n 2 3\n / / \\\n 4 5 6", "output": "16", "type":...
taco
verifiable_code
https://codeforces.com/problemset/problem/988/B
Solve the following coding problem using the programming language python: You are given $n$ strings. Each string consists of lowercase English letters. Rearrange (reorder) the given strings in such a way that for every string, all strings that are placed before it are its substrings. String $a$ is a substring of stri...
```python n = int(input()) t = [input() for i in range(n)] for i in range(n - 1): for j in range(i + 1, n): if len(t[j]) < len(t[i]): (t[i], t[j]) = (t[j], t[i]) h = True for i in range(n - 1): if not t[i] in t[i + 1]: h = False if h == True: print('YES') for i in range(n): print(t[i]) else: print('NO') ...
vfc_132566
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/988/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\na\naba\nabacaba\nba\naba\n", "output": "YES\na\nba\naba\naba\nabacaba\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\na\nabacaba\nba\naba\nabab\n", "output": "NO\n", "typ...
taco
verifiable_code
https://codeforces.com/problemset/problem/1316/C
Solve the following coding problem using the programming language python: It is Professor R's last class of his teaching career. Every time Professor R taught a class, he gave a special problem for the students to solve. You being his favourite student, put your heart into solving it one last time. You are given two ...
```python import os import sys from atexit import register from io import BytesIO input = BytesIO(os.read(0, os.fstat(0).st_size)).readline (n, m, p) = list(map(int, input().split())) As = list(map(int, input().split())) Bs = list(map(int, input().split())) k = 0 for a in As: if a % p: break k += 1 l = 0 for b in B...
vfc_132576
{ "difficulty": "medium_hard", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1316/C", "time_limit": "1.5 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 2 2\n1 1 2\n2 1\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 2 999999937\n2 1\n3 1\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_na...
taco
verifiable_code
Solve the following coding problem using the programming language python: Xenny has 2 positive integers A and B. He wants to find the prime factorization of the integer A^B. Input format: Each line contains 2 space-separated integers A and B. Output format: Consider A^B to have N prime factors. Print N lines. For ...
```python import math primelist=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199] skiplist=[1,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,...
vfc_132580
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "695749246376 801", "output": "2 639\n3 1917\n5 639\n7 1917\n13 639\n19 639\n103 639\n313 639", "type": "stdin_stdout" }, { "fn_name": null, "input": "974803270780 76", "output": "2 167\n71 167"...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/smallest-number-with-sum-of-digits-as-n-and-divisible-by-10n4032/1
Solve the following coding problem using the programming language python: Find the smallest number such that the sum of its digits is N and it is divisible by 10^{N}. Example 1: Input: N = 5 Outptut: 500000 Explanation: Sum of digits of 500000 is 5 and divisible by 10^{5}. Example 2: Input: N = 20 Output: 299000000000...
```python class Solution: def digitsNum(self, N): sum = N l1 = '' while sum > 0: if sum > 9: l1 += '9' else: l1 += str(sum) sum -= 9 l2 = l1[::-1] for i in range(N): l2 += '0' return l2 ```
vfc_132584
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/smallest-number-with-sum-of-digits-as-n-and-divisible-by-10n4032/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 20", "output": "29900000000000000000000", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1243/C
Solve the following coding problem using the programming language python: Ujan has been lazy lately, but now has decided to bring his yard to good shape. First, he decided to paint the path from his house to the gate. The path consists of n consecutive tiles, numbered from 1 to n. Ujan will paint each tile in some co...
```python def prime_factor(n): ass = [] for i in range(2, int(n ** 0.5) + 1): while n % i == 0: ass.append(i) n = n // i if n != 1: ass.append(n) return ass n = int(input()) p = list(set(prime_factor(n))) if len(p) == 1: print(p[0]) else: print(1) ```
vfc_132594
{ "difficulty": "medium", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1243/C", "time_limit": "1.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n", "output": "2\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/FPE
Solve the following coding problem using the programming language python: There is a rooted tree of N vertices rooted at vertex 1. Each vertex v has a value A_{v} associated with it. You choose a vertex v (possibly the root) from the tree and remove all vertices on the path from the root to the vertex v, also includi...
```python import sys import math def get_ints(): return list(map(int, sys.stdin.readline().strip().split())) def docase(): [n] = get_ints() aa = get_ints() ee = [list() for _ in range(0, n)] for _ in range(1, n): [u, v] = get_ints() if v != 1: ee[u - 1].append(v) if u != 1: ee[v - 1].append(u) stack...
vfc_132598
{ "difficulty": "hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/FPE", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n10\n15 30 15 5 3 15 3 3 5 5\n1 2\n1 5\n2 3\n2 4\n5 6\n5 7\n5 8\n7 9\n7 10", "output": "33", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/CDGO2016/problems/CDGO1601
Solve the following coding problem using the programming language python: Sinchan and his friends loves to eat. They have a 2D rectangular cake which they want to share. Sinchan is very kind and offers his friends to eat the cake first, all friends goes one by one to eat the cake. Each friend will cut cake into two pa...
```python testcases = int(input()) results = [] for i in range(0, testcases): friends = int(input()) (l, b) = list(map(int, input().split())) over = False if b > l: temp = b b = l l = temp for counter in range(0, friends): if l == b: over = True break elif l > b: l = l - b if b > l: temp ...
vfc_132602
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/CDGO2016/problems/CDGO1601", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n2\n5 3\n4\n4 8\n1\n1 2\n", "output": "Yes 2\nNo\nYes 1\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.hackerrank.com/challenges/triangle-quest-2/problem
Solve the following coding problem using the programming language python: You are given a positive integer $N$. Your task is to print a palindromic triangle of size $N$. For example, a palindromic triangle of size $5$ is: 1 121 12321 1234321 123454321 You can't take more than two lines. The first line (a for-...
```python for i in range(1, int(input()) + 1): print({1: 1, 2: 121, 3: 12321, 4: 1234321, 5: 123454321, 6: 12345654321, 7: 1234567654321, 8: 123456787654321, 9: 12345678987654321}[i]) ```
vfc_132606
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.hackerrank.com/challenges/triangle-quest-2/problem", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n", "output": "1\n121\n12321\n1234321\n123454321\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/COMN2016/problems/SUMTOUR
Solve the following coding problem using the programming language python: -----Problem----- Suppose there is a circle. There are N Juice shops on that circle. Juice shops are numbered 0 to N-1 (both inclusive). You have two pieces of information corresponding to each of the juice shop: (1) the amount of Juice that a ...
```python import re, sys def isCirlePossible(juices, distances): if juices == [] or distances == []: return -1 total_juice_consumed = 0 juice_consumed = 0 start = 0 for i in range(0, len(juices)): diff = juices[i] - distances[i] if juice_consumed >= 0: juice_consumed += diff else: juice_consumed = d...
vfc_132614
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/COMN2016/problems/SUMTOUR", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1 5\n10 3\n3 4\n", "output": "1\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/60/A
Solve the following coding problem using the programming language python: <image> One morning the Cereal Guy found out that all his cereal flakes were gone. He found a note instead of them. It turned out that his smart roommate hid the flakes in one of n boxes. The boxes stand in one row, they are numbered from 1 to ...
```python (n, m) = input().split(' ') n = int(n) m = int(m) hints = {} max_right = None min_left = None if m > 0: for i in range(m): do_nothing = False line = input().split(' ') hint_position = int(line[4]) - 1 if line[2] == 'left': hint_box = hint_position - 1 if min_left is None or hint_box < min_left:...
vfc_132618
{ "difficulty": "easy", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/60/A", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 0\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1\nTo the right of 1\n", "output": "-1\n", "type": "stdin_stdout" }, { "fn_name": null, ...
taco
verifiable_code
https://www.codechef.com/problems/FLOW018
Solve the following coding problem using the programming language python: Write a program to find the factorial value of any number entered by the user. -----Input----- The first line contains an integer T, the total number of testcases. Then T lines follow, each line contains an integer N. -----Output----- For ea...
```python for i in range(int(input())): n = int(input()) p = 1 for i in range(1, n + 1): p = p * i print(p) ```
vfc_132622
{ "difficulty": "easy", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/FLOW018", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n3\n4\n5\n", "output": "6\n24\n120\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/minimum-distinct-ids3251/1
Solve the following coding problem using the programming language python: Given an array of items, the i'th index element denotes the item id’s and given a number m, the task is to remove m elements such that there should be minimum distinct id’s left. Print the number of distinct id’s. Example 1 - Input: n = 6 arr[] ...
```python from collections import defaultdict class Solution: def distinctIds(self, arr: list, n: int, m: int): mp = defaultdict(int) count = 0 for i in arr: mp[i] += 1 a = list() for (key, value) in mp.items(): a.append(value) a.sort() sz = len(a) for i in a: if i <= m: m -= i count...
vfc_132626
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/minimum-distinct-ids3251/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "n = 6\narr[] = {2, 2, 1, 3, 3, 3}\nm = 3", "output": "1", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/number-following-a-pattern3126/1
Solve the following coding problem using the programming language python: Given a pattern containing only I's and D's. I for increasing and D for decreasing. Devise an algorithm to print the minimum number following that pattern. Digits from 1-9 and digits can't repeat. Example 1: Input: D Output: 21 Explanation: D ...
```python class Solution: def printMinNumberForPattern(ob, S): start = 0 prev = S[0] result = '' S = S + '#' for x in range(1, len(S)): if prev == S[x]: continue elif prev == 'I': tmp = x + 1 if S[x] == '#' else x start += 1 if start != 0 else 0 while start < tmp: start += 1 ...
vfc_132627
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/number-following-a-pattern3126/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "D", "output": "21", "type": "stdin_stdout" }, { "fn_name": null, "input": "IIDDD", "output": "126543", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1791/A
Solve the following coding problem using the programming language python: Given a lowercase Latin character (letter), check if it appears in the string ${codeforces}$. -----Input----- The first line of the input contains an integer $t$ ($1 \leq t \leq 26$) — the number of test cases. The only line of each test cas...
```python import math def im(): return map(int, input().split()) def il(): return list(map(int, input().split())) def ii(): return int(input()) same = lambda s: s.count(s[0]) == len(s) def solve(): a = il() t = ii() for _ in range(t): c = input() if c in 'codeforces': print('YES') else: print('NO') ```
vfc_132629
{ "difficulty": "easy", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1791/A", "time_limit": "1 second" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10\na\nb\nc\nd\ne\nf\ng\nh\ni\nj\n", "output": "NO\nNO\nYES\nYES\nYES\nYES\nNO\nNO\nNO\nNO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "26\nq\na\nz\nw\ns\nx\ne\nd\nc\nr\nf\nv\nt\ng\nb\n...
taco
verifiable_code
https://www.codechef.com/problems/PERMSUFF
Solve the following coding problem using the programming language python: You are given a permutation of natural integers from 1 to N, inclusive. Initially, the permutation is 1, 2, 3, ..., N. You are also given M pairs of integers, where the i-th is (Li Ri). In a single turn you can choose any of these pairs (let's s...
```python t = int(input()) for i in range(t): (n, m) = map(int, input().split()) l = list(map(int, input().split())) d = [] for j in range(m): (a, b) = map(int, input().split()) d.append([a, b]) d.sort() c = [] f = 1 x = d[0][0] y = d[0][1] for j in d[1:]: if j[0] <= y: y = max(y, j[1]) else: c....
vfc_132633
{ "difficulty": "medium_hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/PERMSUFF", "time_limit": "2 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n7 4\n3 1 2 4 5 7 6\n1 2\n4 4\n6 7\n2 3\n4 2\n2 1 3 4\n2 4\n2 3\n", "output": "Possible\nImpossible\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/282/B
Solve the following coding problem using the programming language python: The Bitlandians are quite weird people. They have very peculiar customs. As is customary, Uncle J. wants to have n eggs painted for Bitruz (an ancient Bitland festival). He has asked G. and A. to do the work. The kids are excited because just ...
```python from sys import * input = stdin.readline n = int(input()) r = [] (x, y) = (0, 0) l = [] for i in range(n): l.append(list(map(int, input().split()))) for i in range(n): if abs(x + l[i][0] - y) <= 500: r.append('A') x += l[i][0] else: y += l[i][1] r.append('G') if abs(x - y) <= 500: print(''.join(r)...
vfc_132641
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/282/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n1 999\n999 1\n", "output": "AG\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n400 600\n400 600\n400 600\n", "output": "AGA\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/CHEFDETE
Solve the following coding problem using the programming language python: Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Chef is a private detective. He was asked to investigate a case of murder in the city of Frangton. Chef arrived in Frangton to find out that the mafia was involved i...
```python n = int(input()) m = list(map(int, input().split())) m = set(m) p = set(range(n + 1)) a = p - m for i in a: print(i, end=' ') ```
vfc_132645
{ "difficulty": "easy", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/CHEFDETE", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n0 1 1 2 2 3", "output": "4 5 6", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/two-water-jug-problem3402/1
Solve the following coding problem using the programming language python: You are at the side of a river. You are given a m litre jug and a n litre jug . Both the jugs are initially empty. The jugs dont have markings to allow measuring smaller quantities. You have to use the jugs to measure d litres of water . Determi...
```python class Solution: def gcd(self, a, b): if b == 0: return a return self.gcd(b, a % b) def solve(self, to, frmJug, target): st = frmJug toJug = 0 count = 1 while st != target and toJug != target: temp = min(st, to - toJug) toJug += temp st -= temp count += 1 if st == target or to...
vfc_132650
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/two-water-jug-problem3402/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "m = 3, n = 5, d = 4", "output": "6", "type": "stdin_stdout" }, { "fn_name": null, "input": "m = 8, n = 56, d = 46", "output": "-1", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/b64485d3994958cca8748991bb58668204b3e4c0/1
Solve the following coding problem using the programming language python: Given a maze with N cells. Each cell may have multiple entry points but not more than one exit (i.e entry/exit points are unidirectional doors like valves). You are given an array Edge[] of N integers, where Edge[i] contains the cell index that ...
```python class Solution: def maxWeightCell(self, N, Edge): adj = [0 for i in range(N + 1)] for (ind, val) in enumerate(Edge): if val != -1: adj[val] += ind maxi = max(adj) for i in range(N - 1, -1, -1): if adj[i] == maxi: return i return 0 ```
vfc_132651
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/b64485d3994958cca8748991bb58668204b3e4c0/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 4\r\nEdge[] = {2, 0, -1, 2}", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "N = 1\r\nEdge[] = {-1}", "output": "0", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.hackerrank.com/challenges/palindrome-index/problem
Solve the following coding problem using the programming language python: Given a string of lowercase letters in the range ascii[a-z], determine the index of a character that can be removed to make the string a palindrome. There may be more than one solution, but any will do. If the word is already a palindrome or t...
```python import sys T = int(input()) def check(s, idx): s = s[0:idx] + s[idx + 1:len(s)] (i, j) = (0, len(s) - 1) while i < j: if s[i] != s[j]: return False (i, j) = (i + 1, j - 1) return True for _ in range(T): s = sys.stdin.readline().strip() n = len(s) (i, j) = (0, n - 1) while i < j: if s[i] != s...
vfc_132657
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.hackerrank.com/challenges/palindrome-index/problem", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 \naaab \nbaa \naaa \n", "output": "3\n0\n-1\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/find-the-remainder1439/1
Solve the following coding problem using the programming language python: Given a number N in the form of string, your task is to find the remainder when the number is divided by 7. Note: The given number is very large and so the Input is taken as a String. Example 1: Input: N = "98" Output: 0 Explanation: 98 when d...
```python class Solution: def findRemainder(self, N): return int(N) % 7 ```
vfc_132661
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/find-the-remainder1439/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = \"98\"", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "N = \"13\"", "output": "6", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/POPGATES
Solve the following coding problem using the programming language python: You are Dastan, the great Prince of Persia! After searching long for the mysterious 'Sands of Time', you have finally arrived at the gates of the city that hosts the ancient temple of the gods. However, the gate is locked and it can only be open...
```python try: def check(s, a): if s == 'H' and a % 2 == 0: return 1 if s == 'T' and a % 2 == 0: return 0 if s == 'H' and a % 2 != 0: return 0 return 1 for _ in range(int(input())): (n, k) = map(int, input().split()) l = list(map(str, input().split())) flip = 0 while k: if check(l[-1], fl...
vfc_132662
{ "difficulty": "easy", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/POPGATES", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n5 3\nH T T H T\n7 4\nH H T T T H H\n6 1\nT H T H T T\n", "output": "1\n2\n2\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: Rahul is assigned a task by his fellow mates.He has to take a string from somewhere and first of all he has to calculate the weight of that string.The weight of string is calculated by adding the ASCII values of each characters in that string an...
```python import collections s=input() num=sum(bytearray(s))//len(s) if num%2==0: print((s[::-1])) else: print(((collections.Counter(s).most_common(1)[0])[0])) ```
vfc_132671
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "Worldd", "output": "d", "type": "stdin_stdout" }, { "fn_name": null, "input": "Hello", "output": "olleH", "type": "stdin_stdout" }, { "fn_name": null, "input": "Hello ...
taco
verifiable_code
https://codeforces.com/problemset/problem/1009/D
Solve the following coding problem using the programming language python: Let's call an undirected graph $G = (V, E)$ relatively prime if and only if for each edge $(v, u) \in E$  $GCD(v, u) = 1$ (the greatest common divisor of $v$ and $u$ is $1$). If there is no edge between some pair of vertices $v$ and $u$ then the...
```python from math import gcd (n, m) = list(map(int, input().split())) edges = [] p = m for i in range(1, n + 1): for j in range(i + 1, n + 1): if gcd(i, j) == 1: m -= 1 edges.append([i, j]) if m == 0: break if m == 0: break if len(edges) >= p and p >= n - 1: print('Possible') for i in range(len(e...
vfc_132675
{ "difficulty": "medium_hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1009/D", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 6\n", "output": "Possible\n1 2\n2 3\n3 4\n4 5\n1 3\n1 4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 12\n", "output": "Impossible\n", "type": "stdin_stdout" }, {...
taco
verifiable_code
https://codeforces.com/problemset/problem/1380/A
Solve the following coding problem using the programming language python: You are given a permutation $p_1, p_2, \dots, p_n$. Recall that sequence of $n$ integers is called a permutation if it contains all integers from $1$ to $n$ exactly once. Find three indices $i$, $j$ and $k$ such that: $1 \le i < j < k \le n$;...
```python for _ in range(int(input())): n = int(input()) p = list(map(int, input().split())) a = [] f = 0 for i in range(len(p) - 2): if p[i] < p[i + 1] and p[i + 1] > p[i + 2]: a.append([p.index(p[i]) + 1, p.index(p[i + 1]) + 1, p.index(p[i + 2]) + 1]) f = 1 break if f == 0: print('NO') else: pri...
vfc_132679
{ "difficulty": "easy", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1380/A", "time_limit": "2 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n4\n2 1 4 3\n6\n4 6 1 2 5 3\n5\n5 3 1 2 4\n", "output": "YES\n2 3 4\nYES\n1 2 3\nNO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n4\n2 1 4 3\n6\n4 6 1 2 5 3\n5\n5 3 1 2 4\n", ...
taco
verifiable_code
https://www.codechef.com/problems/ANTSCHEF
Solve the following coding problem using the programming language python: Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef has been researching ant colonies for many years and finally discovered all their secrets. An ant colony consists of $N$ distinct line...
```python import sys def getInput(): return sys.stdin.readline().strip() def getInt(): return int(getInput()) def getInts(): return map(int, getInput().split()) def getArray(): return list(getInts()) tc = getInt() for _ in range(tc): n = getInt() lines = [] for __ in range(n): lines.append(getArray()[1:]) ...
vfc_132683
{ "difficulty": "hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/ANTSCHEF", "time_limit": "2 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n2\n2 -2 1\n1 2", "output": "2", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1463/E
Solve the following coding problem using the programming language python: Ivan is a programming teacher. During the academic year, he plans to give $n$ lectures on $n$ different topics. Each topic should be used in exactly one lecture. Ivan wants to choose which topic will he explain during the $1$-st, $2$-nd, ..., $n...
```python class Node: def __init__(self, value): self.value = value self.next = None self.prev = None def __repr__(self): if not self: return '{}()'.format(self.__class__.__name__) return '{}({})'.format(self.__class__.__name__, self.value) class LL: def __init__(self, iterable=None): self.sentine...
vfc_132687
{ "difficulty": "very_hard", "memory_limit": "512 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1463/E", "time_limit": "2 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 2\n2 3 0 5 3\n1 5\n5 4\n", "output": "3 2 1 5 4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 2\n2 3 0 5 3\n1 5\n5 1\n", "output": "0\n", "type": "stdin_stdout" }, ...
taco
verifiable_code
Solve the following coding problem using the programming language python: Hint * One grid may be filled more than once * Even if it can be represented by one line segment such as '1', it may be represented by two or more line segments. Sample Input 1 Formula for Sample Input 1. Sample Input 2 Sample Input 2 formu...
```python dic = {((0, 0), (0, 1), (0, 2), (0, 3), (0, 4), (1, 0), (1, 4), (2, 0), (2, 1), (2, 2), (2, 3), (2, 4)): '0', ((0, 0), (0, 1), (0, 2), (0, 3), (0, 4)): '1', ((0, 0), (0, 2), (0, 3), (0, 4), (1, 0), (1, 2), (1, 4), (2, 0), (2, 1), (2, 2), (2, 4)): '2', ((0, 0), (0, 2), (0, 4), (1, 0), (1, 2), (1, 4), (2, 0), (...
vfc_132696
{ "difficulty": "unknown_difficulty", "memory_limit": "268.435456 megabytes", "memory_limit_bytes": null, "problem_url": null, "time_limit": "1.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "23\n1 1 3 1\n3 1 3 3\n3 3 1 3\n1 3 1 5\n1 5 3 5\n5 2 7 2\n7 2 7 4\n7 4 5 4\n5 4 5 6\n5 6 7 6\n11 4 13 4\n13 0 15 0\n15 0 15 4\n18 2 18 2\n21 5 23 5\n21 5 21 7\n21 7 23 7\n23 7 23 8\n23 9 21 9\n24 0 26 0\n24 0 24 4\n24 4 26 4\n26 0 ...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/b0cc054e97350ba5d7081b76cf67821d8990e259/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: Input...
```python class Solution: def leaders(self, A, N): a = [] m = A[-1] for i in range(N - 1, -1, -1): if A[i] >= m: m = A[i] a.append(A[i]) return a[::-1] ```
vfc_132700
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/b0cc054e97350ba5d7081b76cf67821d8990e259/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/1659/B
Solve the following coding problem using the programming language python: You are given a binary string of length $n$. You have exactly $k$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($0$ becomes $1$, $1$ becomes $0$). You need to output the lexicographical...
```python import sys def solve(): inp = sys.stdin.readline (n, k) = map(int, inp().split()) s = list(inp()) s.pop() r = [0] * n k_bak = k if k % 2 == 0: for i in range(0, n - 1): if s[i] == '0' and k > 0: s[i] = '1' r[i] = 1 k -= 1 r[-1] = k if (k_bak - k) % 2: s[-1] = str(int(s[-1]) ^ 1...
vfc_132705
{ "difficulty": "easy", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1659/B", "time_limit": "1 second" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n6 3\n100001\n6 4\n100011\n6 0\n000000\n6 1\n111001\n6 11\n101100\n6 12\n001110\n", "output": "111110\n1 0 0 0 0 2 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 0 1 1 0 8 \n111110\n1 1 0 0 0 ...
taco
verifiable_code
https://codeforces.com/problemset/problem/1316/A
Solve the following coding problem using the programming language python: $n$ students are taking an exam. The highest possible score at this exam is $m$. Let $a_{i}$ be the score of the $i$-th student. You have access to the school database which stores the results of all students. You can change each student's scor...
```python for _ in range(int(input())): (n, m) = input().split() n = int(n) m = int(m) l = [int(x) for x in input().split()] if sum(l) >= m: print(m) else: print(sum(l)) ```
vfc_132709
{ "difficulty": "easy", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1316/A", "time_limit": "1 second" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n4 10\n1 2 3 4\n4 5\n1 2 3 4\n", "output": "10\n5\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "27\n1 1\n0\n1 2\n0\n1 5\n0\n1 10\n0\n1 50\n0\n1 100\n0\n1 500\n0\n1 1000\n0\n1 5000\n0\n...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/magnet-array-problem3743/1
Solve the following coding problem using the programming language python: Given N Magnets which are placed linearly, with each magnet to be considered as of point object. Each magnet suffers force from its left sided magnets such that they repel it to the right and vice versa. All forces are repulsive. The force being...
```python class Solution: def nullPoints(self, n, a, getAnswer): z = 0 for i in range(n - 1): start = a[i] end = a[i + 1] while True: mid = (start + end) / 2 eq = self.equilibrium(a, mid) if eq > 0: start = mid elif eq < 0: end = mid else: getAnswer[i] = mid break ...
vfc_132714
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/magnet-array-problem3743/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 2\r\nM[] = {1, 2}", "output": "1.50", "type": "stdin_stdout" }, { "fn_name": null, "input": "N = 4\r\nM[] = {0, 10, 20, 30}", "output": "3.82, 15.00, 26.18", "type": "stdin_stdout" ...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/6d3e72175b15d41f0842b1969300d7f969132efc/1
Solve the following coding problem using the programming language python: Given an array of integers of size N. For each ith element in the array, calculate the absolute difference between the count of numbers that are to the left of i and are strictly greater than ith element, and the count of numbers that are to the...
```python from bisect import bisect, bisect_left class Solution: def greaterLesser(self, A, N): output = [] left = [] for item in A: i = bisect(left, item) output.append(len(left) - i) left.insert(i, item) right = [] for (i, item) in enumerate(A[::-1]): j = bisect_left(right, item) right.ins...
vfc_132715
{ "difficulty": "medium_hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/6d3e72175b15d41f0842b1969300d7f969132efc/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 5\r\nA[] = {5, 4, 3, 2, 1}", "output": "4 2 0 2 4", "type": "stdin_stdout" }, { "fn_name": null, "input": "N = 5\r\nA[] = {1, 2, 3, 4, 5}", "output": "0 0 0 0 0", "type": "stdin_stdou...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/shortest-path-from-1-to-n0156/1
Solve the following coding problem using the programming language python: Consider a directed graph whose vertices are numbered from 1 to n. There is an edge from a vertex i to a vertex j iff either j = i + 1 or j = 3 * i. The task is to find the minimum number of edges in a path in G from vertex 1 to vertex n. Exampl...
```python class Solution: def minStep(self, n): c = 0 while n != 1: if n % 3 == 0: n = n // 3 c += 1 elif n % 3 != 0: n = n - 1 c += 1 return c ```
vfc_132716
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/shortest-path-from-1-to-n0156/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 9", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "N = 4", "output": "2", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1678/A
Solve the following coding problem using the programming language python: Tokitsukaze has a sequence $a$ of length $n$. For each operation, she selects two numbers $a_i$ and $a_j$ ($i \ne j$; $1 \leq i,j \leq n$). If $a_i = a_j$, change one of them to $0$. Otherwise change both of them to $\min(a_i, a_j)$. Tokitsuk...
```python for s in [*open(0)][2::2]: n = len((a := s.split())) m = a.count('0') print(n - m if m else n if len({*a}) < n else n + 1) ```
vfc_132722
{ "difficulty": "easy", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1678/A", "time_limit": "1 second" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0\n", "output": "4\n3\n2\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/94/A
Solve the following coding problem using the programming language python: Igor K. always used to trust his favorite Kashpirovsky Antivirus. That is why he didn't hesitate to download the link one of his groupmates sent him via QIP Infinium. The link was said to contain "some real funny stuff about swine influenza". Th...
```python s = input() a = [] for i in range(10): a.append(input()) p = 0 while p < 80: for i in range(10): if a[i] == s[p:p + 10]: print(i, end='') p += 10 break ```
vfc_132726
{ "difficulty": "easy", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/94/A", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "01111101111100101010001001011110111001110111110111011111011110110111111011011111\n1111110111\n0010000101\n0110000100\n0111111011\n1011100111\n1100101010\n1011011111\n1100010001\n0111110111\n0010010111\n", "output": "85948866"...
taco
verifiable_code
https://codeforces.com/problemset/problem/946/A
Solve the following coding problem using the programming language python: You are given a sequence a consisting of n integers. You may partition this sequence into two sequences b and c in such a way that every element belongs exactly to one of these sequences. Let B be the sum of elements belonging to b, and C be t...
```python def main_function(): n = int(input()) a = [int(i) for i in input().split(' ')] sum_positive = 0 sum_negative = 0 for i in a: if i > 0: sum_positive += i else: sum_negative += i return sum_positive - sum_negative print(main_function()) ```
vfc_132734
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/946/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1 -2 0\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n16 23 16 15 42 8\n", "output": "120\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/28/C
Solve the following coding problem using the programming language python: There are n students living in the campus. Every morning all students wake up at the same time and go to wash. There are m rooms with wash basins. The i-th of these rooms contains ai wash basins. Every student independently select one the rooms ...
```python import sys MAX_N = 55 line = list(map(int, sys.stdin.readline().split(' '))) studc = line[0] roomc = line[1] arr = list(map(int, sys.stdin.readline().split(' '))) ncr = [[0 for i in range(MAX_N)] for j in range(MAX_N)] ncr[0][0] = 1 for i in range(1, MAX_N): ncr[i][0] = 1 for j in range(1, MAX_N): ncr[i][...
vfc_132738
{ "difficulty": "hard", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/28/C", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "35 40\n12 1 4 8 1 9 1 11 1 1 8 8 16 1 6 5 3 1 6 4 6 2 4 6 2 1 1 16 2 2 3 1 1 2 2 3 8 12 1 4\n", "output": "2.659784922284758\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "7 4\n1 2 3 4\n"...
taco
verifiable_code
https://www.codechef.com/PTRN2021/problems/ITGUY51
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 n = int(input()) l = [0] * n for x in range(n): l[x] = int(input()) for i in range(n): z = 1 for j in range(1, l[i] + 1): for k in range(1, l[i] + 1): print(z, end='') z += 2 print() ```
vfc_132747
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/PTRN2021/problems/ITGUY51", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n1\n2\n3\n4\n", "output": "1\n13\n57\n135\n7911\n131517\n1357\n9111315\n17192123\n25272931\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: Do the following for a four-digit number N consisting of numbers 0-9. 1. Let L be the number obtained as a result of arranging the numerical values ​​of each of the N digits in descending order. 2. Let S be the number obtained as a result of ar...
```python while True: number = int(input()) if number == 0: break trial = 0 while True: if number == 6174: print(trial) break box = [] for i in range(4): a = number % 10 number = int(number / 10) box.append(a) if box[0] == box[1] and box[2] == box[3] and (box[1] == box[2]): print('NA') ...
vfc_132751
{ "difficulty": "unknown_difficulty", "memory_limit": "134.217728 megabytes", "memory_limit_bytes": null, "problem_url": null, "time_limit": "1.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6174\n3985\n3333\n0000", "output": "0\n3\nNA\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6174\n1779\n3333\n0000", "output": "0\n6\nNA\n", "type": "stdin_stdout" }, ...
taco
verifiable_code
https://codeforces.com/problemset/problem/256/A
Solve the following coding problem using the programming language python: Gena loves sequences of numbers. Recently, he has discovered a new type of sequences which he called an almost arithmetical progression. A sequence is an almost arithmetical progression, if its elements can be represented as: * a1 = p, where ...
```python R = lambda : map(int, input().split()) n = int(input()) arr = list(R()) dp = [[0] * (n + 1) for i in range(n + 1)] for i in range(n): p = -1 for j in range(i): dp[i][j] = max(dp[i][j], dp[j][p] + 1) p = j if arr[j] == arr[i] else p print(max((max(dp[i]) for i in range(n))) + 1) ```
vfc_132756
{ "difficulty": "medium", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/256/A", "time_limit": "5.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "8\n2 2 5 3 4 3 3 2\n", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n4 4 3 5 1\n", "output": "2", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/unusual-string-sort0405/1
Solve the following coding problem using the programming language python: Given a string composed of both lowercase and uppercase letters. Sort it in such a manner such that the uppercase and lowercase letter comes in an alternate manner but in sorted way. Example 1: Input: S = bAwutndekWEdkd Output: AbEdWddekkntuw Ex...
```python class Solution: def stringSort(self, s): upper = '' lower = '' res = '' for i in s: if i.isupper(): upper += i else: lower += i upper = sorted(upper) lower = sorted(lower) if len(upper) < len(lower): for j in range(len(upper)): res += upper[j] + lower[j] for j in range(...
vfc_132760
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/unusual-string-sort0405/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "S = bAwutndekWEdkd", "output": "AbEdWddekkntuw", "type": "stdin_stdout" }, { "fn_name": null, "input": "S = AiBFR", "output": "AiBFR", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/count-number-of-hops-1587115620/1
Solve the following coding problem using the programming language python: A frog jumps either 1, 2, or 3 steps to go to the top. In how many ways can it reach the top. As the answer will be large find the answer modulo 1000000007. Example 1: Input: N = 1 Output: 1 Example 2: Input: N = 4 Output: 7 Explanation:Below ar...
```python class Solution: def countWays(self, n): s1 = 1 s2 = 2 s3 = 4 if n == 1: return 1 elif n == 2: return 2 elif n == 3: return 4 else: for i in range(4, n + 1): ways = (s1 + s2 + s3) % 1000000007 s1 = s2 s2 = s3 s3 = ways return ways ```
vfc_132761
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/count-number-of-hops-1587115620/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 1", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "N = 4", "output": "7", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/MEDMAXMATCH
Solve the following coding problem using the programming language python: N boys and N girls attend a dance class, where N is odd. For today's practice session, they need to form N boy-girl pairs. The i-th boy has a happiness value of A_{i} and the i-th girl has a happiness value of B_{i}. A pair consisting of the i-...
```python for _ in range(int(input())): n = int(input()) ali = list(map(int, input().split())) bli = list(map(int, input().split())) ali.sort() bli.sort() k = n // 2 ali = ali[k:] bli = bli[k:] lst = list() ln = len(ali) for i in range(ln): a = ali[i] + bli[ln - i - 1] lst.append(a) lst.sort() print(ls...
vfc_132763
{ "difficulty": "medium_hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/MEDMAXMATCH", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1\n10\n25\n3\n1 6 6\n2 2 7\n5\n10 4 93 5 16\n4 34 62 6 26\n", "output": "35\n8\n50\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/PBK12020/problems/ITGUY16
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 cases...
```python try: for _ in range(int(input())): k = int(input()) for i in range(1, k + 1): print(' ' * (k - i), end='') if i % 2 == 1: for j in range(0, i): print(chr(65 + j), end='') else: for j in range(0, i): print(j + 1, end='') print() except: pass ```
vfc_132775
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/PBK12020/problems/ITGUY16", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n2\n4\n", "output": "A\n12\nA\n12\nABC\n1234\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: Everyone who is involved with HackerEarth in what so ever form knows who Little Kuldeep is. He's not so little, but he's called that. (No one knows why!) He's pretty efficient at organizing, mentoring, managing various hiring challenges, contest...
```python arr=[] art=[0]*1440 flag=0 for _ in range(eval(input())): a,b=list(map(str,input().split('-'))) ah,am=a.split(':') bh,bm=b.split(':') final1=int(ah)*60+int(am) final2=int(bh)*60+int(bm) for item in range(final1,final2): if art[item]==0: art[item]=1 elif art[item]!=0: print("Will need a moderat...
vfc_132779
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n10:00-11:00\n09:00-12:00", "output": "Who needs a moderator?\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n09:00-09:50\n13:00-17:00\n09:50-10:30", "output": "Who needs a mode...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/rotate-by-90-degree0356/1
Solve the following coding problem using the programming language python: Given a square matrix[][] of size N x N. The task is to rotate it by 90 degrees in an anti-clockwise direction without using any extra space. Example 1: Input: N = 3 matrix[][] = [[1 2 3], [4 5 6], [7 8 9]] Output: 3 ...
```python def rotate(matrix): l = [] for i in range(-1, -(len(matrix) + 1), -1): k = [] for j in range(len(matrix)): k.append(matrix[j][i]) l.append(k) for i in range(len(matrix)): matrix[i] = l[i] ```
vfc_132783
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/rotate-by-90-degree0356/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": "rotate", "input": "N = 3\nmatrix[][] = [[1 2 3],\n [4 5 6],\n [7 8 9]]", "output": "3 6 9 \n2 5 8 \n1 4 7", "type": "function_call" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: You have a part to play in the Wars to Come. As everyone knows, Lord Stannis Baratheon (First of His Name, King of the Andals and the First Men, Lord of the Seven Kingdoms and Protector of the Realm) is one true king. Now, he wants to conquer t...
```python count = int(input()) strenghts = input().strip().split(" ") istrenghts = [] requiredStrength = int(input()) for s in strenghts: istrenghts.append(int(s)) istrenghts = sorted(istrenghts, reverse=True) start = 0 count = 0 su = 0 while(start < len(istrenghts) and su < requiredStrength): su += istrenghts...
vfc_132790
{ "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\n84 87 78 16 94 36 87 93 50 22 63 28 91 60 64 27 41 27 73 37 12 69 68 30 83 31 63 24 68 36 30 3 23 59 70 68 94 57 12 43 30 74 22 20 85 38 99 25 16 71 14 27 92 81 57 74 63 71 97 82 6 26 85 28 37 6 47 30 14 58 25 96 83 46 15 68 3...
taco
verifiable_code
Solve the following coding problem using the programming language python: In the International System of Units (SI), various physical quantities are expressed in the form of "numerical value + prefix + unit" using prefixes such as kilo, mega, and giga. For example, "3.5 kilometers", "5.1 milligrams", and so on. On th...
```python m = {'yotta': 24, 'zetta': 21, 'exa': 18, 'peta': 15, 'tera': 12, 'giga': 9, 'mega': 6, 'kilo': 3, 'hecto': 2, 'deca': 1, 'deci': -1, 'centi': -2, 'milli': -3, 'micro': -6, 'nano': -9, 'pico': -12, 'femto': -15, 'ato': -18, 'zepto': -21, 'yocto': -24} for _ in range(int(input())): (v, *b) = input().split() ...
vfc_132794
{ "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": "7\n12.3 kilo meters\n0.45 mega watts\n0.000000000000000000000001 yotta grams\n1000000000000000000000000 yocto seconds\n42 amperes\n0.951642419825234 joules\n1234.56789012345678901234567890 hecto pascals", "output": "1.23 * 10...
taco
verifiable_code
https://codeforces.com/problemset/problem/1411/B
Solve the following coding problem using the programming language python: We call a positive integer number fair if it is divisible by each of its nonzero digits. For example, $102$ is fair (because it is divisible by $1$ and $2$), but $282$ is not, because it isn't divisible by $8$. Given a positive integer $n$. Find...
```python import math def lcm(lista): k = 1 for i in lista: if i != 0: k = k * i // math.gcd(k, i) return k def lyans(): a = input() listn = [] for i in a: listn.append(int(i)) n = len(listn) for i in range(len(a)): l = lcm(listn[:n - i - 1]) nb = int(a[n - i - 1:]) if i == len(a) - 1: star = ...
vfc_132798
{ "difficulty": "easy", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1411/B", "time_limit": "2 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n1\n282\n1234567890\n1000000000000000000\n", "output": "1\n288\n1234568040\n1000000000000000000\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1337/C
Solve the following coding problem using the programming language python: Writing light novels is the most important thing in Linova's life. Last night, Linova dreamed about a fantastic kingdom. She began to write a light novel for the kingdom as soon as she woke up, and of course, she is the queen of it. <image> Th...
```python from sys import * input = stdin.readline (n, k) = map(int, input().split()) graph = [set([]) for _ in range(n + 1)] for _ in range(n - 1): (x, y) = map(int, input().split()) graph[x].add(y) graph[y].add(x) (dep, par, cn) = ([0] * (n + 1), [0] * (n + 1), 0) (q, p) = ([1], []) vis = [0] * (n + 1) vis[1] = 1 ...
vfc_132802
{ "difficulty": "medium_hard", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1337/C", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 2\n1 2\n1 3\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 1\n1 2\n2 3\n", "output": "2\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/MINCOINSREQ
Solve the following coding problem using the programming language python: There are only 2 type of denominations in Chefland: Coins worth 1 rupee each Notes worth 10 rupees each Chef wants to pay his friend exactly X rupees. What is the minimum number of coins Chef needs to pay exactly X rupees? ------ Input Forma...
```python t = int(input()) for i in range(t): x = int(input()) print(x % 10) ```
vfc_132806
{ "difficulty": "easy", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/MINCOINSREQ", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n53\n100\n9\n11\n", "output": "3\n0\n9\n1\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/SKMP
Solve the following coding problem using the programming language python: Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef has a string $S$. He also has another string $P$, called *pattern*. He wants to find the pattern in $S$, but that might be impossible. ...
```python for _ in range(int(input())): a = input() b = input() a_small = '' a_big = '' a_small1 = '' a_big1 = '' a = list(a) b = list(b) for i in range(len(b)): a.remove(b[i]) a = ''.join(a) b = ''.join(b) for i in range(len(a)): if ord(a[i]) <= ord(b[0]): a_small += a[i] elif a[i]: a_big += a[...
vfc_132810
{ "difficulty": "medium", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/SKMP", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\nakramkeeanany\naka\nsupahotboy\nbohoty\ndaehabshatorawy\nbadawy", "output": "aaakaeekmnnry\nabohotypsu\naabadawyehhorst", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/CHEFPDIG
Solve the following coding problem using the programming language python: Chef likes to play with big numbers. Today, he has a big positive integer N. He can select any two digits from this number (the digits can be same but their positions should be different) and orders them in any one of the two possible ways. For ...
```python al = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'] t = input() for c in range(0, int(t)): num = int(input()) lst = [int(x) for x in str(num)] for i in al: n = ord(i) t1 = n % 10 t2 = n // 10 c1 = lst.count(t1) c2...
vfc_132814
{ "difficulty": "medium", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/CHEFPDIG", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n65\n566\n11\n1623455078\n", "output": "A\nAB\nACDFGHIJKLNPQRSTUVW\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: Codex is about to start and Ram has not done dinner yet. So, he quickly goes to hostel mess and finds a long queue in front of food counter. But somehow he manages to take the food plate and reaches in front of the queue. The plates are divided...
```python T = int(input()) fib = [0 for i in range(123)] fib[0] = 2 fib[1] = 3 for i in range(2,123): fib[i] = fib[i-1] + fib[i-2] for _ in range(T): N = int(input()) print(fib[N - 1] ** 2) ```
vfc_132818
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "19\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19", "output": "4\n9\n25\n64\n169\n441\n1156\n3025\n7921\n20736\n54289\n142129\n372100\n974169\n2550409\n6677056\n17480761\n45765225\n119814916", "type"...
taco
verifiable_code
https://codeforces.com/problemset/problem/342/A
Solve the following coding problem using the programming language python: Xenia the mathematician has a sequence consisting of n (n is divisible by 3) positive integers, each of them is at most 7. She wants to split the sequence into groups of three so that for each group of three a, b, c the following conditions held...
```python a = int(input()) list = input().split() list2 = [] for elements in list: elements = int(elements) list2.append(elements) count1 = int(list2.count(1)) count2 = int(list2.count(2)) count3 = int(list2.count(3)) count4 = int(list2.count(4)) count6 = int(list2.count(6)) if 5 in list2 or 7 in list2: print(-1) el...
vfc_132822
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/342/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n1 1 1 2 2 2\n", "output": "-1\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/CAARRAY
Solve the following coding problem using the programming language python: Given an integer N, construct an array A of length N such that: 1 ≤ A_{i} ≤ 10^{18} for all (1 ≤ i ≤ N); There exists a [subsequence] of length greater than 1 such that the [gcd] of all elements of the subsequence is i, for all 1 ≤ i ≤ N. More...
```python from math import inf from collections import * import math, os, sys, heapq, bisect, random, threading from functools import lru_cache from itertools import * def inp(): return sys.stdin.readline().rstrip('\r\n') def out(var): sys.stdout.write(str(var)) def inpu(): return int(inp()) def lis(): return l...
vfc_132830
{ "difficulty": "very_hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/CAARRAY", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n3\n4\n", "output": "2 3 6\n4 24 10 15", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1419/E
Solve the following coding problem using the programming language python: An agent called Cypher is decrypting a message, that contains a composite number $n$. All divisors of $n$, which are greater than $1$, are placed in a circle. Cypher can choose the initial order of numbers in the circle. In one move Cypher can ...
```python import random from math import gcd, sqrt, floor, ceil def solve_1(n): d = divisors(n) order = [0] * len(d) moves = [999999999] * 1 mark = [False] * len(d) permutation(d, [0] * len(d), 0, moves, mark, order) if gcd(order[0], order[-1]) == 1: moves[0] += 1 return (order, moves[0]) def permutation(d, ...
vfc_132842
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1419/E", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n6\n4\n30\n", "output": "2 3 6 \n1\n2 4 \n0\n2 30 6 3 15 5 10 \n0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n18\n", "output": "2 6 3 9 18\n0\n", "type": "stdin_stdout...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/maximum-of-minimum-for-every-window-size3453/1
Solve the following coding problem using the programming language python: Given an integer array. The task is to find the maximum of the minimum of every window size in the array. Note: Window size varies from 1 to the size of the Array. Example 1: Input: N = 7 arr[] = {10,20,30,50,10,70,30} Output: 70 30 20 10 10 10 ...
```python class Solution: def maxOfMin(self, arr, n): stack = [] left = [-1] * n right = [n] * n for i in range(n): while stack and arr[stack[-1]] >= arr[i]: stack.pop() if stack: left[i] = stack[-1] stack.append(i) stack.clear() for i in range(n - 1, -1, -1): while stack and arr[stack...
vfc_132846
{ "difficulty": "medium_hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/maximum-of-minimum-for-every-window-size3453/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 7\narr[] = {10,20,30,50,10,70,30}", "output": "70 30 20 10 10 10 10", "type": "stdin_stdout" }, { "fn_name": null, "input": "N = 3\narr[] = {10,20,30}", "output": "30 20 10", "type": ...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/check-if-array-contains-contiguous-integers-with-duplicates-allowed2046/1
Solve the following coding problem using the programming language python: Given an array of n integers(duplicates allowed). Print “Yes” if it is a set of contiguous integers else print “No”. Example 1: ​Input : arr[ ] = {5, 2, 3, 6, 4, 4, 6, 6} Output : Yes Explanation: The elements of array form a contiguous ...
```python class Solution: def areElementsContiguous(self, arr, n): num_set = set(arr) minimum = min(num_set) maximum = max(num_set) expected_count = maximum - minimum + 1 if len(num_set) == expected_count: return True else: return False ```
vfc_132847
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/check-if-array-contains-contiguous-integers-with-duplicates-allowed2046/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "arr[ ] = {5, 2, 3, 6, 4, 4, 6, 6}", "output": "Yes", "type": "stdin_stdout" }, { "fn_name": null, "input": "arr[ ] = {10, 14, 10, 12, 12, \n 13, 15}", "output": "No...
taco
verifiable_code
https://codeforces.com/problemset/problem/350/A
Solve the following coding problem using the programming language python: Valera wanted to prepare a Codesecrof round. He's already got one problem and he wants to set a time limit (TL) on it. Valera has written n correct solutions. For each correct solution, he knows its running time (in seconds). Valera has also wr...
```python def solve(a, b): if max(min(a) * 2, max(a)) < min(b): return max(min(a) * 2, max(a)) else: return -1 (n, m) = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) print(solve(a, b)) ```
vfc_132852
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/350/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 6\n4 5 2\n8 9 6 10 7 11\n", "output": "5", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 1\n3 4 5\n6\n", "output": "-1\n", "type": "stdin_stdout" }, { "fn_name"...
taco
verifiable_code
Solve the following coding problem using the programming language python: problem Information I want to paint a rectangular veneer board to make a signboard for the promotion of the Olympic Games. Some rectangular masking tapes are pre-attached to the veneer board where I do not want to paint. We decided to paint eac...
```python from typing import Union, List import io, sys import bisect from collections import deque def main(): (w, h) = list(map(int, sys.stdin.readline().split())) if w == h == 0: return 'END' n = int(sys.stdin.readline()) x1y1x2y2_list = [list(map(int, sys.stdin.readline().split())) for _ in range(n)] (X1, Y...
vfc_132856
{ "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": "15 6\n10\n1 4 5 6\n2 1 4 5\n1 0 5 1\n6 1 7 5\n7 5 3 6\n7 0 9 2\n9 1 10 5\n11 0 14 1\n12 1 13 5\n11 5 14 6\n0 0", "output": "3\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/488/D
Solve the following coding problem using the programming language python: Alexandra has a paper strip with n numbers on it. Let's call them a_{i} from left to right. Now Alexandra wants to split it into some pieces (possibly 1). For each piece of strip, it must satisfy: Each piece should contain at least l number...
```python def split(a, n, s, l): pieces = [] i = 1 tmpmin = a[0] tmpmax = a[0] tmppc = [a[0]] while i < n: if abs(a[i] - tmpmin) <= s and abs(a[i] - tmpmax) <= s: tmppc.append(a[i]) if a[i] < tmpmin: tmpmin = a[i] elif a[i] > tmpmax: tmpmax = a[i] else: pieces.append(tmppc) tmppc = [a[i...
vfc_132861
{ "difficulty": "hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/488/D", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7 2 2\n1 3 1 2 4 1 2\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "7 2 2\n1 100 1 100 1 100 1\n", "output": "-1\n", "type": "stdin_stdout" }, { ...
taco
verifiable_code
Solve the following coding problem using the programming language python: You have obtained the Izua Japanese dictionary, which is the official language of Izua, and the Izua alphabet (list of letters). There are N types of letters in the Izua alphabet. The order of the words that appear in the Izua Japanese dictionar...
```python def solve(): from sys import stdin m = 1000000007 f_i = stdin while True: N = int(f_i.readline()) if N == 0: break w = list(range(N)) R = int(f_i.readline()) for i in range(R): (s, t) = map(int, f_i.readline().split()) s -= 1 t -= 1 (w[s], w[t]) = (w[t], w[s]) s = [(i, c) for (i...
vfc_132865
{ "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": "3\n2\n1 2\n2 1\n4\n2\n2 3\n2 4\n0", "output": "0\n4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n2\n1 2\n2 1\n4\n2\n2 2\n2 4\n0", "output": "0\n5\n", "type": "stdin_stdou...
taco
verifiable_code
https://www.codechef.com/problems/FLOW004
Solve the following coding problem using the programming language python: If Give an integer N . Write a program to obtain the sum of the first and last digits of this number. -----Input----- The first line contains an integer T, the total number of test cases. Then follow T lines, each line contains an integer N. ...
```python for i in range(int(input())): s = int(input()) m = [] while s > 0: rem = s % 10 m.append(rem) s = s // 10 print(m[0] + m[len(m) - 1]) ```
vfc_132870
{ "difficulty": "easy", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/FLOW004", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1234\n124894\n242323\n", "output": "5\n5\n5\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/922/C
Solve the following coding problem using the programming language python: Imp is watching a documentary about cave painting. [Image] Some numbers, carved in chaotic order, immediately attracted his attention. Imp rapidly proposed a guess that they are the remainders of division of a number n by all integers i from 1...
```python from math import sqrt, pow, ceil from decimal import * l1 = input().split() l1 = [int(i) for i in l1] x = l1[0] y = l1[1] for i in range(1, y + 1): if x % i != i - 1: print('No') exit() print('Yes') ```
vfc_132875
{ "difficulty": "medium_hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/922/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 4\n", "output": "No\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 3\n", "output": "Yes\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/919/D
Solve the following coding problem using the programming language python: You are given a graph with $n$ nodes and $m$ directed edges. One lowercase letter is assigned to each node. We define a path's value as the number of the most frequently occurring letter. For example, if letters on a path are "abaca", then the v...
```python from collections import defaultdict, deque import sys input = sys.stdin.readline (n, m) = map(int, input().split()) l = list(input()) deg = [0 for i in range(n)] graph = defaultdict(list) for i in range(m): (a, b) = map(int, input().split()) a -= 1 b -= 1 graph[a].append(b) deg[b] += 1 q = deque() for i ...
vfc_132879
{ "difficulty": "medium_hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/919/D", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 4\nabaca\n1 2\n1 3\n3 4\n4 5\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 6\nxzyabc\n1 2\n3 1\n2 3\n5 4\n4 3\n6 4\n", "output": "-1\n", "type": "stdin_s...
taco
verifiable_code
https://codeforces.com/problemset/problem/1556/E
Solve the following coding problem using the programming language python: William has two arrays $a$ and $b$, each consisting of $n$ items. For some segments $l..r$ of these arrays William wants to know if it is possible to equalize the values of items in these segments using a balancing operation. Formally, the valu...
```python import sys input = sys.stdin.readline class SegTree: def __init__(self, n, e, ope, lst=[]): self.N0 = 2 ** (n - 1).bit_length() self.e = e self.ope = ope self.data = [e] * (2 * self.N0) if lst: for i in range(n): self.data[self.N0 + i] = lst[i] for i in range(self.N0 - 1, 0, -1): se...
vfc_132883
{ "difficulty": "hard", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1556/E", "time_limit": "2 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "8 5\n0 1 2 9 3 2 7 5\n2 2 1 9 4 1 5 8\n2 6\n1 7\n2 4\n7 8\n5 8\n", "output": "1\n3\n1\n-1\n-1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10 5\n146321077 449813547 308647993 833095737 ...