source
stringclasses
4 values
task_type
stringclasses
1 value
in_source_id
stringlengths
0
138
problem_statement
stringlengths
219
13.2k
gold_standard_solution
stringlengths
0
413k
problem_id
stringlengths
5
10
metadata
dict
verification_info
dict
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/maximum-gcd-of-siblings-of-a-binary-tree/1
Solve the following coding problem using the programming language python: Given a 2d list that represents the nodes of a Binary tree with N nodes, the task is to find the maximum GCD of the siblings of this tree without actually constructing it. Note: If there are no pairs of siblings in the given tree, print 0. Also,...
```python import math class Solution: def maxBinTreeGCD(self, arr, N): possible_pairs = [] arr.sort() ans = 0 for i in range(len(arr) - 1): if arr[i][0] == arr[i + 1][0]: ans = max(ans, math.gcd(arr[i][1], arr[i + 1][1])) i += 1 else: continue return ans ```
vfc_143303
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/maximum-gcd-of-siblings-of-a-binary-tree/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 7\narr = {{4, 5}, {4, 2}, {2, 3}, {2, 1}, {3, 6}, {3, 12}}", "output": "6", "type": "stdin_stdout" }, { "fn_name": null, "input": "N = 3\narr[] = {{1,2}, {1,4}}", "output": "2", "type...
taco
verifiable_code
Solve the following coding problem using the programming language python: Nate U. Smith runs a railroad company in a metropolitan area. In addition to his railroad company, there are rival railroad companies in this metropolitan area. The two companies are in a competitive relationship with each other. In this metrop...
```python m = int(input()) while m: m -= 1 (ax, ay, bx, by) = map(int, input().split()) n = int(input()) (dx, dy) = (bx - ax, by - ay) intersections = set() while n: n -= 1 (sx, sy, tx, ty, o, l) = map(int, input().split()) (tdx, tdy) = (tx - sx, ty - sy) (asx, asy) = (sx - ax, sy - ay) denom = dx * tdy...
vfc_143304
{ "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\n-10 1 10 1\n4\n-6 2 -2 -2 0 1\n-6 -2 -2 2 1 0\n6 2 2 -2 0 0\n6 -2 2 2 1 1\n8 12 -7 -3\n8\n4 -5 4 -2 1 1\n4 -2 4 9 1 0\n6 9 6 14 1 1\n-5 6 7 6 0 0\n1 0 1 10 0 0\n-5 0 -5 10 0 1\n-7 0 7 0 0 1\n-1 0 -1 -5 0 1", "output": "1\n...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/remove-duplicates3034/1
Solve the following coding problem using the programming language python: Given a string without spaces, the task is to remove duplicates from it. Note: The original order of characters must be kept the same. Example 1: Input: S = "zvvo" Output: "zvo" Explanation: Only keep the first occurrence Example 2: Input: S =...
```python class Solution: def removeDups(self, string): p = '' for char in string: if char not in p: p = p + char return p ```
vfc_143308
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/remove-duplicates3034/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "S = \"zvvo\"", "output": "\"zvo\"", "type": "stdin_stdout" }, { "fn_name": null, "input": "S = \"gfg\"", "output": "gf", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: There is Kannon-do in the mountain behind Ichiro's house. There are 30 steps from the foot to this Kannon-do, and Ichiro goes to Kannon-do almost every day. Ichiro can go up the stairs up to 3 steps with one foot. While playing, I noticed that t...
```python import sys n = 30 f = [1, 1, 2, 4] while len(f) <= n: f.append(f[-1] + f[-2] + f[-3]) while True: n = int(input()) if n == 0: sys.exit() day = f[n] if day % 3650 == 0: print(int(day / 3650)) else: print(int(day / 3650) + 1) ```
vfc_143309
{ "difficulty": "unknown_difficulty", "memory_limit": "134.217728 megabytes", "memory_limit_bytes": null, "problem_url": null, "time_limit": "1.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n10\n14\n25\n0", "output": "1\n1\n1\n701\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n10\n14\n23\n0", "output": "1\n1\n1\n207\n", "type": "stdin_stdout" }, { ...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/length-of-last-word5721/1
Solve the following coding problem using the programming language python: Given a string S consisting of upper/lower-case alphabets and empty space characters ‘ ‘. The string may contain spaces at the end. You will have return the length of last word which consists of alphabets only. Example 1: Input: S = "Geeks for G...
```python class Solution: def findLength(self, s): n = len(s) count = 0 for i in range(n - 1, -1, -1): if s[i] == ' ' and count > 0: return count elif s[i] != ' ': count += 1 return count ```
vfc_143313
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/length-of-last-word5721/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "S = \"Geeks for Geeks\"", "output": "5", "type": "stdin_stdout" }, { "fn_name": null, "input": "S = \"Start Coding Here \"", "output": "4", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1430/G
Solve the following coding problem using the programming language python: You are given a directed acyclic graph (a directed graph that does not contain cycles) of n vertices and m arcs. The i-th arc leads from the vertex x_i to the vertex y_i and has the weight w_i. Your task is to select an integer a_v for each ver...
```python from heapq import heappush, heappop class MinCostFlow: INF = 10 ** 18 def __init__(self, N): self.N = N self.G = [[] for i in range(N)] def add_edge(self, fr, to, cap, cost): forward = [to, cap, cost, None] backward = forward[3] = [fr, 0, -cost, forward] self.G[fr].append(forward) self.G[to]...
vfc_143314
{ "difficulty": "very_hard", "memory_limit": "1024.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1430/G", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "18 27\n3 16 55467\n17 11 829\n5 12 15831\n14 6 24056\n5 2 63216\n15 6 38762\n2 6 10654\n12 6 51472\n11 9 79384\n1 6 67109\n5 13 86794\n7 6 74116\n10 3 44030\n5 7 71499\n16 17 33019\n5 14 54625\n9 6 10151\n5 10 3514\n5 1 92436\n13 6...
taco
verifiable_code
Solve the following coding problem using the programming language python: Problem There is a grid of $ R \ times C $ squares with $ (0, 0) $ in the upper left and $ (R-1, C-1) $ in the lower right. When you are in a square ($ e $, $ f $), from there $ (e + 1, f) $, $ (e-1, f) $, $ (e, f + 1) $, $ (e) , f-1) $, $ (e, ...
```python from collections import deque (R, C, ay, ax, by, bx) = map(int, input().split()) MOD = INF = 10 ** 9 + 7 dists = [[INF] * C for i in range(R)] dists[ay][ax] = 0 ptns = [[0] * C for i in range(R)] ptns[ay][ax] = 1 q = deque([(0, ax, ay)]) dxs = [1, 0, -1, 0] dys = [0, 1, 0, -1] ans_d = None while q: (d, x, y)...
vfc_143318
{ "difficulty": "unknown_difficulty", "memory_limit": "536.870912 megabytes", "memory_limit_bytes": null, "problem_url": null, "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 2 0 0 0 1", "output": "1 2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "421 435 196 169 388 5", "output": "39 3262623\n", "type": "stdin_stdout" }, { "fn_nam...
taco
verifiable_code
https://codeforces.com/problemset/problem/918/B
Solve the following coding problem using the programming language python: As the guys fried the radio station facilities, the school principal gave them tasks as a punishment. Dustin's task was to add comments to nginx configuration for school's website. The school has n servers. Each server has a name and an ip (name...
```python (n, m) = map(int, input().split()) a = [] b = [] ans = [] p = [] for i in range(n): (c, d) = map(str, input().split()) d += ';' a.append(c) a.append(d) for i in range(m): b.append(list(map(str, input().split()))) for i in range(m): p.append(b[i][0]) p.append(b[i][1]) p.append('#' + a[a.index(b[i][1]) ...
vfc_143322
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/918/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 2\nmain 192.168.0.2\nreplica 192.168.0.1\nblock 192.168.0.1;\nproxy 192.168.0.2;\n", "output": "block 192.168.0.1; #replica\nproxy 192.168.0.2; #main\n", "type": "stdin_stdout" }, { "fn_name": null, ...
taco
verifiable_code
https://www.hackerrank.com/challenges/mehta-and-his-laziness/problem
Solve the following coding problem using the programming language python: Mehta is a very lazy boy. He always sleeps in Maths class. One day his teacher catches him sleeping and tells him that she would mark him absent for the whole semester. While she pretends to be strict, she is actually very kind-hearted. So she w...
```python import fractions def primes(n): primfac = {} d = 2 while d * d <= n: while n % d == 0: if d in primfac: primfac[d] += 1 else: primfac[d] = 1 n /= d d += 1 if n > 1: if n in primfac: primfac[n] += 1 else: primfac[n] = 1 return primfac def numf(n): prod = 1 dictx = primes...
vfc_143327
{ "difficulty": "medium_hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.hackerrank.com/challenges/mehta-and-his-laziness/problem", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n2\n8\n36\n900\n", "output": "0\n1/3\n1/8\n3/26\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/ELEVATR
Solve the following coding problem using the programming language python: Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef's apartment consists of $M$ floors (numbered $1$ through $M$), and there's an elevator that is used to move between different floors. T...
```python T = int(input()) for _ in range(T): (n, m) = map(int, input().split()) v = list(map(int, input().split())) ans = 2000000000.0 xx = 2 for pp in range(2): lpoz = -1 sw = 0 prev = v[0] dir = True if prev == -1: prev = 1 else: lpoz = 0 for i in range(1, n): if v[i] != -1: j = lpoz ...
vfc_143331
{ "difficulty": "very_hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/ELEVATR", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n4 5\n2 3 4 3\n4 5\n2 -1 4 3\n4 5\n1 -1 -1 5\n5 4\n-1 -1 3 -1 -1\n5 5\n-1 -1 3 -1 -1\n", "output": "1\n1\n-1\n1\n0\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1560/B
Solve the following coding problem using the programming language python: Some number of people (this number is even) have stood in a circle. The people stand in the circle evenly. They are numbered clockwise starting from a person with the number $1$. Each person is looking through the circle's center at the opposite...
```python for _ in range(int(input())): (a, b, c) = map(int, input().split()) maxi = abs(a - b) * 2 if maxi >= a and maxi >= b and (maxi >= c) and (abs(a - b) > 1): if c > abs(a - b): print(abs(c - abs(a - b))) else: print(c + abs(a - b)) else: print(-1) ```
vfc_143336
{ "difficulty": "easy", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1560/B", "time_limit": "1 second" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7\n6 2 4\n2 3 1\n2 4 10\n5 3 4\n1 3 2\n2 5 4\n4 3 2\n", "output": "8\n-1\n-1\n-1\n4\n1\n-1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n6666777 3 4\n", "output": "6666778\n", ...
taco
verifiable_code
https://codeforces.com/problemset/problem/717/B
Solve the following coding problem using the programming language python: R3D3 spent some time on an internship in MDCS. After earning enough money, he decided to go on a holiday somewhere far, far away. He enjoyed suntanning, drinking alcohol-free cocktails and going to concerts of popular local bands. While listenin...
```python import sys, heapq input = sys.stdin.readline (n, a, b) = map(int, input().split()) if a < b: (a, b) = (b, a) if b == 0: print((n - 1) * a) else: pascal = [[1] * 20005] for i in range(20004): newrow = [1] for j in range(1, 20005): newrow.append(newrow[-1] + pascal[-1][j]) if newrow[-1] > n: b...
vfc_143340
{ "difficulty": "very_hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/717/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 1 2\n", "output": "12\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 1 5\n", "output": "6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 ...
taco
verifiable_code
https://codeforces.com/problemset/problem/1144/E
Solve the following coding problem using the programming language python: You are given two strings $s$ and $t$, both consisting of exactly $k$ lowercase Latin letters, $s$ is lexicographically less than $t$. Let's consider list of all strings consisting of exactly $k$ lowercase Latin letters, lexicographically not l...
```python def plus(a, b): c = '' i = len(a) - 1 arg = 0 while i >= 0: k = arg + ord(a[i]) + ord(b[i]) - 194 arg = 1 if k < 26: arg = 0 i -= 1 c = chr(k % 26) + c c = chr(1) * arg + c return c def minus(a): c = '' i = 0 arg = 0 while i < len(a): c += chr((arg * 26 + ord(a[i])) // 2) arg = ord...
vfc_143344
{ "difficulty": "hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1144/E", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\naz\nbf\n", "output": "bc\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\nafogk\nasdji\n", "output": "alvuw\n", "type": "stdin_stdout" }, { "fn_name": null, ...
taco
verifiable_code
https://www.hackerrank.com/challenges/tutzki-and-lcs/problem
Solve the following coding problem using the programming language python: Given two strings, $a$ and $\boldsymbol{b}$, find and print the total number of ways to insert a character at any position in string $\class{ML__boldsymbol}{\boldsymbol{a}}$ such that the length of the Longest Common Subsequence of characters in...
```python import string def lcs(s1, s2): n = len(s1) m = len(s2) dp = [[0 for _ in range(m + 1)] for _ in range(n + 1)] for i in range(n): for j in range(m): if s1[i] == s2[j]: dp[i + 1][j + 1] = dp[i][j] + 1 else: dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]) return dp def alpIndexes(s, alp...
vfc_143348
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.hackerrank.com/challenges/tutzki-and-lcs/problem", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "aa\nbaaa\n", "output": "4\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/b6b3297ccfb1ad5f66a9c2b92979170417adf114/1
Solve the following coding problem using the programming language python: Professor McGonagall teaches transfiguration at Hogwarts. She has given Harry the task of changing himself into a cat. She explains that the trick is to analyze your own DNA and change it into the DNA of a cat. The transfigure spell can be used ...
```python class Solution: def transfigure(self, A, B): m = {} n = len(A) for i in range(n): if A[i] in m: m[A[i]] += 1 else: m[A[i]] = 1 for i in range(n): if B[i] in m: m[B[i]] -= 1 for key in m: if m[key] != 0: return -1 (i, j) = (n - 1, n - 1) res = 0 while i >= 0 and j ...
vfc_143352
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/b6b3297ccfb1ad5f66a9c2b92979170417adf114/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "A = \"GEEKSFORGEEKS\" \nB = \"FORGEEKSGEEKS\"", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "A = \"ABC\" \nB = \"BCA\"", "output": "2", "type": "stdin_stdout" ...
taco
verifiable_code
Solve the following coding problem using the programming language python: PCK, which recycles Aizu's precious metal, Aizunium, has a network all over the country and collects Aizunium with many collection vehicles. This company standardizes the unit of weight and number of lumps for efficient processing. A unit calle...
```python n = int(input()) size = 200100 total = [0 for _ in range(size)] for _ in range(n): s = sum(map(int, input().split())) total[s] += 1 for i in range(size - 1): if total[i] % 2: print(i, 0) total[i + 1] += total[i] // 2 ```
vfc_143354
{ "difficulty": "unknown_difficulty", "memory_limit": "268.435456 megabytes", "memory_limit_bytes": null, "problem_url": null, "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n100010 2", "output": "100012 0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n2 1\n1 3\n2 0", "output": "2 0\n3 0\n4 0\n", "type": "stdin_stdout" }, { "fn_...
taco
verifiable_code
https://www.hackerrank.com/challenges/sherlock-and-minimax/problem
Solve the following coding problem using the programming language python: Watson gives Sherlock an array of integers. Given the endpoints of an integer range, for all $M$ in that inclusive range, determine the minimum( abs(arr[i]-M) for all $1\leq i\leq|arr|$) ). Once that has been determined for all integers in the...
```python N = int(input()) A = [int(c) for c in input().split()[:N]] (P, Q) = [int(c) for c in input().split()[:2]] a = sorted(A) max_point = P max_distance = min((abs(i - P) for i in a)) for i in range(len(a) - 1): if a[i] > Q or a[i + 1] < P: continue m = int((a[i] + a[i + 1]) / 2) if m < P: point = P distan...
vfc_143358
{ "difficulty": "medium_hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.hackerrank.com/challenges/sherlock-and-minimax/problem", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n5 8 14\n4 9\n", "output": "4\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: Problem Find the angle between the two given angles θ1 and θ2. Here, the angle between them is defined as "θ1 & plus; t'when t'is the one with the smallest absolute value among the t satisfying θ1 & plus; t = θ2 − t" as shown in the figure belo...
```python s1 = int(input()) s2 = int(input()) a = min(s1, s2) b = max(s1, s2) if b - a > 180: print((b + (360 - b + a) / 2) % 360) else: print((a + b) / 2) ```
vfc_143362
{ "difficulty": "unknown_difficulty", "memory_limit": "267.38688 megabytes", "memory_limit_bytes": null, "problem_url": null, "time_limit": "1.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "20\n594", "output": "127.0000000000\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n26", "output": "18.0000000000\n", "type": "stdin_stdout" }, { "fn_name": n...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/remove-every-kth-node/1
Solve the following coding problem using the programming language python: Given a singly linked list, your task is to remove every k^{th} node from the linked list. Input: The first line of input contains number of test cases T. Then T test cases follow. Every test case contains 3 lines. First line of every test case ...
```python def deleteK(head, k): n = head s = 1 if k == 1: return None while n != None: s = s + 1 while n.next != None and s == k: n.next = n.next.next s = 1 n = n.next return head ```
vfc_143366
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/remove-every-kth-node/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": "deleteK", "input": "2\r\n\r\n8\r\n\r\n1 2 3 4 5 6 7 8\r\n\r\n3\r\n\r\n4\r\n\r\n1 2 3 4\r\n\r\n2", "output": "1 2 4 5 7 8\r\n\r\n1 3", "type": "function_call" } ] }
taco
verifiable_code
https://atcoder.jp/contests/abc144/tasks/abc144_d
Solve the following coding problem using the programming language python: Takahashi has a water bottle with the shape of a rectangular prism whose base is a square of side a~\mathrm{cm} and whose height is b~\mathrm{cm}. (The thickness of the bottle can be ignored.) We will pour x~\mathrm{cm}^3 of water into the bottl...
```python import math (a, b, x) = map(int, input().split()) print(math.degrees(math.atan(2 / a / a / a * (a * a * b - x) if a * a * b <= x * 2 else a * b * b / 2 / x))) ```
vfc_143367
{ "difficulty": "medium_hard", "memory_limit": "1024.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://atcoder.jp/contests/abc144/tasks/abc144_d", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 2 4\n", "output": "45.0000000000\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "12 21 10\n", "output": "89.7834636934\n", "type": "stdin_stdout" }, { "fn_name"...
taco
verifiable_code
https://codeforces.com/problemset/problem/1550/D
Solve the following coding problem using the programming language python: Let's call an integer array $a_1, a_2, \dots, a_n$ good if $a_i \neq i$ for each $i$. Let $F(a)$ be the number of pairs $(i, j)$ ($1 \le i < j \le n$) such that $a_i + a_j = i + j$. Let's say that an array $a_1, a_2, \dots, a_n$ is excellent i...
```python import io, os input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline M = 10 ** 9 + 7 MAX = 10 ** 6 + 1 factor = [1] * MAX for i in range(1, MAX): factor[i] = factor[i - 1] * i % M def fastfrac(a, b, M): numb = pow(b, M - 2, M) return a % M * (numb % M) % M def comb(m, n): if n < 0 or m < 0: retu...
vfc_143371
{ "difficulty": "hard", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1550/D", "time_limit": "2 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n3 0 3\n4 -3 5\n42 -33 55\n69 -42 146\n", "output": "4\n10\n143922563\n698570404\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n20000 -431912570 597469643\n20000 -13928452 414987414...
taco
verifiable_code
https://www.codechef.com/problems/CERSOL
Solve the following coding problem using the programming language python: Cersei wants to be the queen of seven kingdoms. For this to happen, she needs to address the soldiers in her army. There are n$n$ soldiers in her army (numbered 1$1$ through n$n$). Cersei passes on the message to the first soldier (soldier 1). ...
```python (dt, a) = (None, None) def dfs(z): r = [{}, {}] ln = len(dt[z]) if ln == 0: r[0][0] = 0 r[1][1 << a[z]] = 1 elif ln == 1: l = dfs(dt[z][0]) r[0] = l[1] for m in l[0]: r[1][1 << a[z] | m] = min(r[1][1 << a[z] | m], l[0][m] + 1) if 1 << a[z] | m in r[1] else l[0][m] + 1 for m in l[1]: r[1...
vfc_143375
{ "difficulty": "very_hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/CERSOL", "time_limit": "2 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n5 4 3\n1 1 2 2 3\n1 2\n1 3\n2 4\n2 5\n", "output": "3\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/CRES2016/problems/CRES104
Solve the following coding problem using the programming language python: There is crazy man named P29892P. He always tries to do crazy things as he thinks. One day he invented a machine and named it as ANGEN. The ANGEN is used to perform range operations. The range operation means performing operations on range value...
```python VQ = 'UAMmSs' n = int(input()) a = list(map(int, input().split())) for _ in range(int(input())): (q, x, y) = input().split() if q not in VQ: print('!!!') continue if q == 'U': a[int(x) - 1] = int(y) continue l = int(x) - 1 r = int(y) if q == 'A': print(sum(a[l:r])) continue if q == 'M': p...
vfc_143379
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/CRES2016/problems/CRES104", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n1 2 5 3 10 6\n6\nA 1 5\nM 1 3\nm 5 6\ns 3 6\nU 1 7\nS 1 2\n", "output": "21\n5\n6\n5\n2\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: Rajesh has been challenge by his friend to find the number which have properties like, Here take no 12 such that square of 12(12*12)=144 and 21 which is reverse of 12 have square(21*21)= 441 whose reverse is equal to 144 and now Rajesh is no...
```python t=eval(input()) for i in range(t): n=input() a=int(n) #print a b=n[::-1] #print b c=int(b) #print c if n!=b: d=a**2 #print d e=c**2 #print e f=str(d) g=str(e) h=g[::-1] #print h if f==h: print(b) else: print("No") else: print("No") ```
vfc_143383
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "25\n102\n211\n221\n301\n311\n115\n12\n31\n201\n211\n221\n1003\n1012\n1013\n99\n8888\n10000\n3111\n2111\n0000\n19\n20\n333\n545\n1112", "output": "221\n311\n2001\n1101\n1201\n1301\nNo\n2022\nNo\nNo\nNo\n301\n13\n311\n1122\n100...
taco
verifiable_code
https://www.hackerrank.com/challenges/two-two/problem
Solve the following coding problem using the programming language python: Prof. Twotwo as the name suggests is very fond powers of 2. Moreover he also has special affinity to number 800. He is known for carrying quirky experiments on powers of 2. One day he played a game in his class. He brought some number plates on...
```python tree = [False, {}] def add(word): current = tree for c in word: try: current = current[1][c] except KeyError: current[1][c] = [False, {}] current = current[1][c] current[0] = True def count(word): count = 0 for start in range(len(word)): (current, index) = (tree, start) while True: ...
vfc_143387
{ "difficulty": "hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.hackerrank.com/challenges/two-two/problem", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n2222222\n24256\n65536\n023223\n33579\n", "output": "7\n4\n1\n4\n0\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/PYRAMIDMOVES
Solve the following coding problem using the programming language python: You are given a pyramid of the following form with an infinite number of rows: 1 2\ 3 4\ 5\ 6 7\ 8\ 9\ 10 ........... From a cell, you can move to either the bottom-left cell or the bottom-right cell directly in contact with the current one (...
```python import math MOD7 = pow(10, 9) + 7 MAXF = pow(10, 5) my_list = [0] * (MAXF + 1) def last(l): return (l + 1) * l / 2 def get_level_and_index(n): idx = -1 line = -1 if n == 1: return (1, 1) left = 2 right = 1 + math.floor(math.sqrt(2 * n)) while left <= right: line = int((left + right) / 2) if las...
vfc_143391
{ "difficulty": "hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/PYRAMIDMOVES", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n2 7\n1 5\n5 3", "output": "1\n2\n0", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/722/B
Solve the following coding problem using the programming language python: You are given a text consisting of n lines. Each line contains some space-separated words, consisting of lowercase English letters. We define a syllable as a string that contains exactly one vowel and any arbitrary number (possibly none) of con...
```python from collections import Counter input() for p in map(int, input().split()): C = Counter(input()) if sum((C[v] for v in 'aeiouy')) != p: print('NO') break else: print('YES') ```
vfc_143395
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/722/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n2 2 3\nintel\ncode\nch allenge\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n1 2 3 1\na\nbcdefghi\njklmnopqrstu\nvwxyz\n", "output": "NO\n", "type": ...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/check-if-a-number-is-power-of-another-number5442/1
Solve the following coding problem using the programming language python: Given two positive numbers X and Y, check if Y is a power of X or not. Example 1: Input: X = 2, Y = 8 Output: 1 Explanation: 2^{3} is equal to 8. Example 2: Input: X = 1, Y = 8 Output: 0 Explanation: Any power of 1 is not equal to 8. Your...
```python from math import pow, log class Solution: def isPowerOfAnother(ob, X, Y): if X == 0 or X == 1: return 0 else: m = log(Y, X) m = round(m) if X ** m == Y: return 1 return 0 ```
vfc_143399
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/check-if-a-number-is-power-of-another-number5442/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "X = 2, Y = 8", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "X = 1, Y = 8", "output": "0", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.hackerrank.com/challenges/py-set-discard-remove-pop/problem
Solve the following coding problem using the programming language python: .remove(x) This operation removes element $\boldsymbol{x}$ from the set. If element $\boldsymbol{x}$ does not exist, it raises a KeyError. The .remove(x) operation returns None. Example >>> s = set([1, 2, 3, 4, 5, 6, 7, 8, 9]) >>> s.remo...
```python cmds = {'pop': lambda x: s.pop(), 'remove': lambda x: s.remove(int(x[1])), 'discard': lambda x: s.discard(int(x[1]))} input() s = set(map(int, input().split())) n = int(input()) for i in range(n): args = input().split() cmds[args[0]](args) print(sum(s)) ```
vfc_143400
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.hackerrank.com/challenges/py-set-discard-remove-pop/problem", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "9\n1 2 3 4 5 6 7 8 9\n10\npop\nremove 9\ndiscard 9\ndiscard 8\nremove 7\npop \ndiscard 6\nremove 5\npop \ndiscard 5\n", "output": "4\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/MAXAGRY
Solve the following coding problem using the programming language python: Alice and Bob were playing a game yet again but this time, Bob already lost the game. Now he wants to take revenge. Bob saw a jigsaw puzzle which was solved by Alice and decided to jumble the puzzle pieces again. There are N puzzle pieces in a ...
```python for _ in range(int(input())): (n, k) = map(int, input().split()) total = 0 if k >= n // 2: print(n * (n - 1) // 2) continue else: total += n * (n - 1) // 2 total -= (n - k) * (n - k - 1) // 2 total += (n - 2 * k) * k total += k * (k - 1) // 2 print(total) ```
vfc_143404
{ "difficulty": "medium", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/MAXAGRY", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n7 3\n1 4\n8 2\n5 3\n", "output": "21\n0\n22\n10\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: Do you know the famous series of children's books named "Where's Wally"? Each of the books contains a variety of pictures of hundreds of people. Readers are challenged to find a person called Wally in the crowd. We can consider "Where's Wally" ...
```python import string import sys S = string.ascii_uppercase + string.ascii_lowercase + string.digits + '+/' mod = 10 ** 9 + 9 p = 13 q = 19 L = 1000 p_table = [1] * (L + 1) q_table = [1] * (L + 1) for i in range(L): p_table[i + 1] = p_table[i] * p % mod q_table[i + 1] = q_table[i] * q % mod readline = sys.stdin.rea...
vfc_143408
{ "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": "48 3 3\ngAY4I4wA\ngIIgIIgg\nw4IAYAg4\ng\ng\nw\n153 3 3\nkkkkkkkkkkkkkkkkkkkkkkkkkg\nSSSSSSSSSSSSSSSSSSSSSSSSSQ\nJJJJJJJJJJJJJJJJJJJJJJJJJI\ng\nQ\nJ\n1 1 2\nA\nA\nA\n384 3 2\nABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/12-hour-clock-subtraction1708/1
Solve the following coding problem using the programming language python: Given two positive integers num1 and num2, subtract num2 from num1 on a 12 hour clock rather than a number line. Note: Assume the Clock starts from 0 hour to 11 hours. Example 1: Input: num1 = 7, num2 = 5 Output: 2 Explanation: 7-5 = 2. The ti...
```python class Solution: def subClock(self, num1, num2): return (num1 - num2) % 12 ```
vfc_143412
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/12-hour-clock-subtraction1708/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "num1 = 7, num2 = 5", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "num1 = 5, num2 = 7", "output": "10", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://atcoder.jp/contests/abc131/tasks/abc131_b
Solve the following coding problem using the programming language python: You have N apples, called Apple 1, Apple 2, Apple 3, ..., Apple N. The flavor of Apple i is L+i-1, which can be negative. You can make an apple pie using one or more of the apples. The flavor of the apple pie will be the sum of the flavors of th...
```python (n, l) = map(int, input().split()) r = l + n - 1 m = r if r < 0 else l s = (l + r) * n // 2 print(s if l * r <= 0 else s - m) ```
vfc_143413
{ "difficulty": "easy", "memory_limit": "1024.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://atcoder.jp/contests/abc131/tasks/abc131_b", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 2\n", "output": "18\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 -1\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "30 -5...
taco
verifiable_code
https://www.codechef.com/COMT2020/problems/ROOTSQR
Solve the following coding problem using the programming language python: Raju has created a program to find the square root of a number. But his program can store only integers. Being a newbie, he didn't know about rounding the numbers. Hence his program returns the absolute value of the result if possible. For examp...
```python try: from math import sqrt (t, x) = list(map(int, input().split())) for _ in range(t): n = int(input()) if n < 0: print('no') else: diff = x / 100 * n ans = int(sqrt(n)) ans1 = ans ** 2 if n - ans1 <= diff: print('yes') else: print('no') except: pass ```
vfc_143418
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/COMT2020/problems/ROOTSQR", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 20\n5\n3\n", "output": "yes\nno\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/SEAPERM
Solve the following coding problem using the programming language python: Read problems statements in Mandarin Chinese and Russian. Sereja have array A' that contain N integers. Now Sereja want to permute elements of the array, he want to use some permutation p, such that A[i] = A'[p[i]], where A - new array.   Le...
```python import sys for j in range(int(sys.stdin.readline())): (n, k, s) = map(int, sys.stdin.readline().split()) m = list(map(int, sys.stdin.readline().split())) if n == 3 and k == 2 and (s == 4): print(2, 1, 3) continue if n == 4 and k == 4 and (s == 1): print(4, 3, 2, 1) continue [print(i[0] + 1, end='...
vfc_143423
{ "difficulty": "very_hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/SEAPERM", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n3 2 4\n3 4 1\n4 4 1\n1 1 1 1", "output": "2 1 3\n4 3 2 1", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/smallest-power-of-2-greater-than-or-equal-to-n2630/1
Solve the following coding problem using the programming language python: Given a number N.Find the nearest number which is a power of 2 and greater than or equal to N. Example 1: Input: N = 1 Output: 1 Explanation: The nearest power of 2 greater than or equal to 1 is 2^0=1. Example 2: Input: N = 5 Output: 8 Explanat...
```python class Solution: def nearestPowerOf2(self, N): count = 0 n = N if n & n - 1 == 0: return N while n != 0: count += 1 n >>= 1 return 1 << count ```
vfc_143427
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/smallest-power-of-2-greater-than-or-equal-to-n2630/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 1", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "N = 5", "output": "8", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/595/B
Solve the following coding problem using the programming language python: Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consists of exactly n digits. Also Pasha has a number k and two sequences of length n / k (n is divisible by k) a_1, a_2, ..., a...
```python import sys (n, k) = sys.stdin.readline().split() n = int(n) k = int(k) a = [int(x) for x in sys.stdin.readline().split()] b = [int(x) for x in sys.stdin.readline().split()] MOD = 10 ** 9 + 7 res = 1 for i in range(0, n // k): lo = b[i] * 10 ** (k - 1) - 1 up = (b[i] + 1) * 10 ** (k - 1) - 1 tmp = (10 ** k ...
vfc_143429
{ "difficulty": "medium_hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/595/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6 2\n38 56 49\n7 3 4\n", "output": "8\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "8 2\n1 22 3 44\n5 4 3 2\n", "output": "32400\n", "type": "stdin_stdout" }, { ...
taco
verifiable_code
Solve the following coding problem using the programming language python: Imagine a game played on a line. Initially, the player is located at position 0 with N candies in his possession, and the exit is at position E. There are also N bears in the game. The i-th bear is located at x_i. The maximum moving speed of the...
```python import sys readline = sys.stdin.readline class Segtree: def __init__(self, A, intv, initialize=True, segf=max): self.N = len(A) self.N0 = 2 ** (self.N - 1).bit_length() self.intv = intv self.segf = segf if initialize: self.data = [intv] * self.N0 + A + [intv] * (self.N0 - self.N) for i in r...
vfc_143433
{ "difficulty": "unknown_difficulty", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": null, "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 9 1\n2 3 8", "output": "12\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 1000000000 1000000000\n1 199586132", "output": "2000000000\n", "type": "stdin_stdout" }, ...
taco
verifiable_code
https://codeforces.com/problemset/problem/909/F
Solve the following coding problem using the programming language python: Given an integer N, find two permutations: Permutation p of numbers from 1 to N such that p_{i} ≠ i and p_{i} & i = 0 for all i = 1, 2, ..., N. Permutation q of numbers from 1 to N such that q_{i} ≠ i and q_{i} & i ≠ 0 for all i = 1, 2, ..., N...
```python def test(x, i): i = list(i) ok = True for j in range(x): if i[j] == j + 1 or i[j] & j + 1 != 0: ok = False if ok: print(i) def comp(n): return 2 ** len(bin(n)[2:]) - 1 - n n = int(input()) nn = n if n % 2 == 0: x = [] while n != 0: for i in range(comp(n), n + 1): x.append(i) n = comp(n) ...
vfc_143438
{ "difficulty": "very_hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/909/F", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n", "output": "NO\nNO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n", "output": "YES\n6 5 4 3 2 1 \nYES\n3 6 2 5 1 4\n", "type": "stdin_stdout" }, { "fn_n...
taco
verifiable_code
Solve the following coding problem using the programming language python: In this problem, a date is written as Y-M-D. For example, 2019-11-30 means November 30, 2019. Integers M_1, D_1, M_2, and D_2 will be given as input. It is known that the date 2019-M_2-D_2 follows 2019-M_1-D_1. Determine whether the date 2019-M...
```python input() (_, d) = input().split() print('1' if d == '1' else '0') ```
vfc_143442
{ "difficulty": "unknown_difficulty", "memory_limit": "1024.0 megabytes", "memory_limit_bytes": null, "problem_url": null, "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "11 30\n6 1", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "11 17\n11 17", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "inpu...
taco
verifiable_code
https://codeforces.com/problemset/problem/1203/A
Solve the following coding problem using the programming language python: There are $n$ students standing in a circle in some order. The index of the $i$-th student is $p_i$. It is guaranteed that all indices of students are distinct integers from $1$ to $n$ (i. e. they form a permutation). Students want to start a r...
```python import sys def solve(n, pn): if n == 1: return 'YES' count = 0 if pn[0] > pn[n - 1]: count = 1 for i in range(1, n): if pn[i] > pn[i - 1]: count += 1 if count == 1 or count == n - 1: return 'YES' else: return 'NO' q = int(input()) for _ in range(q): n = int(input()) pn = list(map(int, sy...
vfc_143446
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1203/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n4\n1 2 3 4\n3\n1 3 2\n5\n1 2 3 5 4\n1\n1\n5\n3 2 1 5 4\n", "output": "YES\nYES\nNO\nYES\nYES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n12\n12 3 4 5 6 7 8 9 10 11 1 2\n", ...
taco
verifiable_code
https://www.codechef.com/MAY12/problems/CHEFLUCK
Solve the following coding problem using the programming language python: Every great chef knows that lucky numbers are positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Our chef has recently returned from the Luc...
```python import sys import os def __starting_point(): start = 0 for line in sys.stdin: if start == 0: start = 1 continue else: try: n = int(line.strip()) q = n / 7 rem = n % 7 if rem == 0: res = n elif rem == 1: res = (q - 1) * 7 elif rem == 2: res = (q - 2) * 7 ...
vfc_143450
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/MAY12/problems/CHEFLUCK", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n7\n4\n11\n1\n15\n\n\n", "output": "7\n0\n7\n-1\n7\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/712/B
Solve the following coding problem using the programming language python: Memory is performing a walk on the two-dimensional plane, starting at the origin. He is given a string s with his directions for motion: An 'L' indicates he should move one unit left. An 'R' indicates he should move one unit right. A 'U' indic...
```python s = input() if len(s) % 2 == 1: print(-1) else: hor = 0 ver = 0 for direction in s: if direction == 'R': hor += 1 elif direction == 'L': hor -= 1 elif direction == 'U': ver += 1 else: ver -= 1 print((abs(hor) + abs(ver)) // 2) ```
vfc_143454
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/712/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "RRU\n", "output": "-1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "UDUR\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "RUUR\...
taco
verifiable_code
Solve the following coding problem using the programming language python: Arjit, Protector of The Realm, has an important task at hand. M new subjects are soon going to become a part of The Realm. The Realm, though, already has N subjects who are well skilled in the ways of The Realm. He wants the new subjects too to ...
```python from collections import defaultdict import heapq t = int(input()) ans = [] while t: t = t - 1 m,n = list(map(int, input().split())) st = defaultdict(list) pr = defaultdict(list) while m: m = m - 1 u,v = list(map(int, input().split())) heapq.heappush(st[u], v) while n: n = n - 1 u,v = list(ma...
vfc_143458
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10\n87 45\n20 17\n17 50\n22 21\n22 80\n94 67\n69 78\n90 22\n92 85\n76 82\n47 17\n63 19\n97 14\n72 15\n75 36\n94 61\n81 65\n30 49\n67 51\n21 40\n31 15\n6 51\n44 96\n24 35\n32 51\n17 78\n19 79\n48 67\n44 19\n81 19\n55 27\n31 87\n43 6...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/sum-equals-to-sum4006/1
Solve the following coding problem using the programming language python: Given an array A of N integers. The task is to find if there are two pairs (a, b) and (c, d) such that a+b = c+d. Example 1: Input:N=7 A[] = {3, 4, 7, 1, 2, 9, 8} Output: 1Explanation:(3, 7) and (9, 1) are the pairs whosesum are equal. Example...
```python class Solution: def findPairs(self, arr, n): l = [] for i in range(len(arr)): for j in range(i + 1, len(arr)): sum = arr[i] + arr[j] if sum in l: return 1 else: l.append(sum) else: return 0 ```
vfc_143463
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/sum-equals-to-sum4006/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N=7 A[] = {3, 4, 7, 1, 2, 9, 8}", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "N=7 A[] = {65, 30, 7, 90, 1, 9, 8}", "output": "0", "type": "stdin_stdout" } ...
taco
verifiable_code
https://codeforces.com/problemset/problem/349/B
Solve the following coding problem using the programming language python: Igor has fallen in love with Tanya. Now Igor wants to show his feelings and write a number on the fence opposite to Tanya's house. Igor thinks that the larger the number is, the more chance to win Tanya's heart he has. Unfortunately, Igor coul...
```python n = int(input()) ar = [int(x) for x in input().split()] mi = -1 mc = 10 ** 18 for i in range(len(ar)): if ar[i] <= mc: mc = ar[i] mi = i digits = n // mc if digits == 0: print(-1) exit(0) n -= mc * digits ar = ar[::-1] ans = [str(mi + 1)] * digits index = 0 while index < digits: for i in range(len(ar)...
vfc_143464
{ "difficulty": "medium_hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/349/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n5 4 3 2 1 2 3 4 5\n", "output": "55555\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n9 11 1 12 5 8 9 10 6\n", "output": "33\n", "type": "stdin_stdout" }, { ...
taco
verifiable_code
Solve the following coding problem using the programming language python: I have a lot of friends. Every friend is very small. I often go out with my friends. Put some friends in your backpack and go out together. Every morning I decide which friends to go out with that day. Put friends one by one in an empty backpack...
```python import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools sys.setrecursionlimit(10 ** 7) inf = 10 ** 20 eps = 1.0 / 10 ** 13 mod = 10 ** 9 + 7 dd = [(-1, 0), (0, 1), (1, 0), (0, -1)] ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (...
vfc_143468
{ "difficulty": "unknown_difficulty", "memory_limit": "134.217728 megabytes", "memory_limit_bytes": null, "problem_url": null, "time_limit": "8.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6 37\n5\n9\n24\n18\n26\n33", "output": "6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 1\n1\n2\n7\n9", "output": "1\n", "type": "stdin_stdout" }, { "fn_name"...
taco
verifiable_code
https://codeforces.com/problemset/problem/1725/B
Solve the following coding problem using the programming language python: A basketball competition is held where the number of players in a team does not have a maximum or minimum limit (not necessarily $5$ players in one team for each match). There are $N$ candidate players in the competition that will be trained by ...
```python def solve(): (n, d) = map(int, input().split()) a = sorted([*map(int, input().split())])[::-1] (i, j, r) = (0, len(a), 0) while i < j: x = a[i] while x <= d: j -= 1 if i < j: x += a[i] else: return r else: r += 1 i += 1 return r print(solve()) ```
vfc_143472
{ "difficulty": "easy", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1725/B", "time_limit": "1 second" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6 180\n90 80 70 60 50 100\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 4\n1 2\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": nu...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/check-for-three-consecutive-numbers5729/1
Solve the following coding problem using the programming language python: Given an integer n, the task is to find whether n can be written as sum of three consecutive integer. Example 1: Input: n = 6 Output: 1 2 3 Explanation: 6 = 1+2+3 Hence 6 can be written as sum of three consecutive integer. Example 2: Input: n ...
```python class Solution: def consecutiveSum(self, n): if n % 3 != 0: return [-1] a = n // 3 return [a - 1, a, a + 1] ```
vfc_143476
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/check-for-three-consecutive-numbers5729/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "n = 6", "output": "1 2 3", "type": "stdin_stdout" }, { "fn_name": null, "input": "n = 7", "output": "-1", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: Chef and Jhool went to a party, and both decided to play a game. The game is simple, both Chef and Jhool will eat the dishes served at the party till they are full, and the one who eats maximum number of dishes is the winner. However, both of...
```python t=int(input()) for I in range(t): x,y,n=list(map(int,input().split())) ar=list(map(int,input().split())) ar=sorted(ar) sumx=0 sumy=0 cx=0 cy=0 for I in ar: if sumx<=x and sumx+I<=x: sumx=sumx+I cx=cx+1 for I in ar: if sumy<=y and sumy+I<=y: sumy=sumy+I cy=cy+1 #print cx,cy ...
vfc_143477
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "100\n99999 97599 1000\n96 100 91 96 92 92 98 96 95 95 99 93 99 99 95 98 93 94 99 96 98 97 98 98 99 94 92 95 93 94 99 92 91 98 93 91 95 96 97 99 98 97 97 96 99 99 97 92 93 96 98 93 93 91 97 99 91 92 94 95 100 98 92 94 100 98 96 92 9...
taco
verifiable_code
https://www.codechef.com/problems/SUBPRNJL
Solve the following coding problem using the programming language python: "It does not matter how slowly you go as long as you do not stop." - Confucius You are given an array $A_1, A_2, \ldots, A_N$ and an integer $K$. For each subarray $S = [A_l, A_{l+1}, \ldots, A_r]$ ($1 \le l \le r \le N$): - Let's define an arra...
```python import bisect import math t = int(input()) while t > 0: fp = 0 (n, k) = map(int, input().split()) a = [int(o) for o in input().split()] for i in range(n): left = [] arr = [0] * 2050 for j in range(i, n): right = a[j] bisect.insort(left, right) arr[a[j]] += 1 uhoy = math.ceil(k / (j - i +...
vfc_143481
{ "difficulty": "hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/SUBPRNJL", "time_limit": "2 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n3 3\n1 2 3\n", "output": "3\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/expression-add-operators/1
Solve the following coding problem using the programming language python: Given a string S that contains only digits (0-9) and an integer target, return all possible strings to insert the binary operator ' + ', ' - ', or ' * ' between the digits of S so that the resultant expression evaluates to the target value. Note...
```python class Solution: def solve(self, ind, S, target, evalu, ans, res, mul): if ind == len(S): if evalu == target: res.append(ans) return for i in range(ind, len(S)): if ind != i and S[ind] == '0': break cur = int(S[ind:i + 1]) if ind == 0: self.solve(i + 1, S, target, cur, ans + st...
vfc_143485
{ "difficulty": "medium_hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/expression-add-operators/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "S = \"123\"\r\ntarget = 6", "output": "{ \"1*2*3\", \"1+2+3\"}", "type": "stdin_stdout" }, { "fn_name": null, "input": "S = \"3456237490\"\r\ntarget = 9191", "output": "{ }", "type": "std...
taco
verifiable_code
https://www.codechef.com/problems/HOLES
Solve the following coding problem using the programming language python: Chef wrote some text on a piece of paper and now he wants to know how many holes are in the text. What is a hole? If you think of the paper as the plane and a letter as a curve on the plane, then each letter divides the plane into regions. For e...
```python for i in range(int(input())): x = input() h1 = 'ADOPQR' h0 = 'CEFGHIJKLMNSTUVWXYZ' h2 = 'B' h = 0 for i in x: if i in h1: h += 1 elif i in h2: h += 2 print(h) ```
vfc_143486
{ "difficulty": "easy", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/HOLES", "time_limit": "0.71 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\nCODECHEF\nDRINKEATCODE", "output": "2\n5", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\nFEHCEDOC\nDRINKEATCODE", "output": "2\n5\n", "type": "stdin_stdout" }, { ...
taco
verifiable_code
https://codeforces.com/problemset/problem/337/A
Solve the following coding problem using the programming language python: The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her n students and give each of them a jigsaw puzzle (which, as wikipedia states, ...
```python (n, m) = list((int(a) for a in input().split())) p = list((int(a) for a in input().split())) p.sort() mn = p[n - 1] - p[0] for i in range(1, m - n + 1): t = p[n + i - 1] - p[i] if t < mn: mn = t print(mn) ```
vfc_143490
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/337/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 6\n10 12 10 7 5 22\n", "output": "5\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 2\n4 4\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, ...
taco
verifiable_code
Solve the following coding problem using the programming language python: In the year 2xxx, an expedition team landing on a planet found strange objects made by an ancient species living on that planet. They are transparent boxes containing opaque solid spheres (Figure 1). There are also many lithographs which seem to...
```python from collections import defaultdict, deque import sys readline = sys.stdin.readline write = sys.stdout.write def solve(): N = int(readline()) if N == 0: return False C0 = [list(map(int, readline().split())) for i in range(N)] U = [1] * N D = defaultdict(list) for i in range(N): (xi, yi, zi, ri) = C...
vfc_143494
{ "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\n95 20 180 18\n125 20 185 18\n40 27 195 10\n1\n5 5 5 4\n2\n5 5 5 4\n5 5 5 3\n2\n5 5 5 4\n5 7 5 3\n16\n2338 3465 29034 710\n1571 14389 25019 842\n1706 8015 11324 1155\n1899 4359 33815 888\n2160 10364 20511 1264\n2048 8835 23706 19...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/all-numbers-with-specific-difference3558/1
Solve the following coding problem using the programming language python: Given a positive number N and a number D. Find the count of positive numbers smaller or equal to N such that the difference between the number and sum of its digits is greater than or equal to given specific value D. Example 1: Input: N = 13 ,...
```python class Solution: def getCount(self, N, D): if D == 0: return N def sumOfDigit(N): c = 0 n = N while n != 0: c += n % 10 n = n // 10 return c low = 1 high = N while low <= high: mid = int((low + high) / 2) if mid - sumOfDigit(mid) < D: low = mid + 1 else: hig...
vfc_143498
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/all-numbers-with-specific-difference3558/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 13 , D = 2", "output": "4", "type": "stdin_stdout" }, { "fn_name": null, "input": "N = 14 , D = 3", "output": "5", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/998/B
Solve the following coding problem using the programming language python: There are a lot of things which could be cut — trees, paper, "the rope". In this problem you are going to cut a sequence of integers. There is a sequence of integers, which contains the equal number of even and odd numbers. Given a limited budg...
```python from sys import * from math import * from bisect import * (n, k) = map(int, stdin.readline().split()) a = list(map(int, stdin.readline().split())) od = ev = 0 c = [] for i in range(n): if a[i] % 2 == 0: ev += 1 else: od += 1 if ev == od and i != n - 1: c.append(abs(a[i] - a[i + 1])) c.sort() ans = 0 ...
vfc_143499
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/998/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6 4\n1 2 5 10 15 20\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 10\n1 3 2 4\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": nul...
taco
verifiable_code
https://codeforces.com/problemset/problem/1291/B
Solve the following coding problem using the programming language python: You're given an array $a_1, \ldots, a_n$ of $n$ non-negative integers. Let's call it sharpened if and only if there exists an integer $1 \le k \le n$ such that $a_1 < a_2 < \ldots < a_k$ and $a_k > a_{k+1} > \ldots > a_n$. In particular, any st...
```python t = int(input()) for _ in range(0, t): n = int(input()) A = list(map(int, input().split())) c = 1 p = -1 s = n for i in range(0, n): if A[i] < i: break p = i for i in range(n - 1, -1, -1): if A[i] < n - 1 - i: break s = i if s <= p: print('Yes') else: print('No') ```
vfc_143503
{ "difficulty": "easy", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1291/B", "time_limit": "1 second" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10\n1\n248618\n3\n12 10 8\n6\n100 11 15 9 7 8\n4\n0 1 1 0\n2\n0 0\n2\n0 1\n2\n1 0\n2\n1 1\n3\n0 1 0\n3\n1 0 1\n", "output": "Yes\nYes\nYes\nNo\nNo\nYes\nYes\nYes\nYes\nNo\n", "type": "stdin_stdout" }, { "f...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/print-diagonally1623/1
Solve the following coding problem using the programming language python: Give a N*N square matrix, return an array of its anti-diagonals. Look at the example for more details. Example 1: Input: N = 2 matrix[][] = {{1,2}, {3,4}} Output: 1 2 3 4 Explanation: Matrix is as below: 1 2 3 4 Printing it in anti...
```python class Solution: def antiDiagonalPattern(self, m): e = [] for i in range(len(m[0])): a = i for j in range(len(m)): if a >= 0: e += [m[j][a]] a -= 1 for i in range(len(m[0])): b = len(m[0]) - 1 for j in range(i + 1, len(m)): if b >= 0: e += [m[j][b]] b -= 1 return...
vfc_143507
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/print-diagonally1623/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 2\r\nmatrix[][] = {{1,2},\r\n {3,4}}", "output": "1 2 3 4", "type": "stdin_stdout" }, { "fn_name": null, "input": "N = 3\r\nmatrix[][] = {{1,2,3},\r\n\r\n {4,5,6},\r\n\r...
taco
verifiable_code
https://codeforces.com/problemset/problem/897/A
Solve the following coding problem using the programming language python: Are you going to Scarborough Fair? Parsley, sage, rosemary and thyme. Remember me to one who lives there. He once was the true love of mine. Willem is taking the girl to the highest building in island No.28, however, neither of them knows ho...
```python (n, m) = list(map(int, input().split())) s = input() for i in range(m): (l, r, c, c2) = input().split() (l, r) = (int(l), int(r)) for j in range(l - 1, r): if s[j] == c: s = s[:j] + c2 + s[j + 1:] print(s) ```
vfc_143512
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/897/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 1\nioi\n1 1 i n\n", "output": "noi", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g\n", "output": "gaaak", "type": "stdin_stdout" }, ...
taco
verifiable_code
https://www.codechef.com/problems/CHAIRS_
Solve the following coding problem using the programming language python: Chef's coding class is very famous in Chefland. This year X students joined his class and each student will require one chair to sit on. Chef already has Y chairs in his class. Determine the minimum number of new chairs Chef must buy so that e...
```python t = int(input()) for i in range(t): (x, y) = map(int, input().split()) if x <= y: print('0') else: print(x - y) ```
vfc_143516
{ "difficulty": "easy", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/CHAIRS_", "time_limit": "0.5 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n20 14\n41 41\n35 0\n50 100\n", "output": "6\n0\n35\n0\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/the-light-problem4217/1
Solve the following coding problem using the programming language python: There are N office cubicles placed in a straight line, each with a bright bulb. Each light bulb can brighten K rooms on either side of it (also the one in which the light bulb itself is), but all the cubicles don't have a bulb. You are given an ...
```python class Solution: def isBrightened(self, N, K, A): if K == 0: return int(not 0 in A) if not 1 in A[-K - 1:]: return 0 while len(A) > K: flag = True for _ in range(2 * K + 1): if A.pop(): flag = False break if not A: break if flag: return 0 return 1 ```
vfc_143520
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/the-light-problem4217/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 4, K = 3\nA = {0, 1, 0, 1}", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "N = 7, K = 2\nA = {1, 0, 0, 0, 0, 0, 1}", "output": "0", "type": "stdin_stdout" ...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/is-sudoku-valid4820/1
Solve the following coding problem using the programming language python: Given an incomplete Sudoku configuration in terms of a 9x9 2-D square matrix(mat[][]) the task to check if the current configuration is valid or not where a 0 represents an empty block. Note: Current valid configuration does not ensure validity...
```python import collections class Solution: def isValid(self, mat): rows = collections.defaultdict(set) cols = collections.defaultdict(set) squares = collections.defaultdict(set) for r in range(9): for c in range(9): if mat[r][c] == 0: continue if mat[r][c] in rows[r] or mat[r][c] in cols[c]...
vfc_143521
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/is-sudoku-valid4820/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "mat[][] = [\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,...
taco
verifiable_code
https://www.codechef.com/problems/RANKLISTPAGE
Solve the following coding problem using the programming language python: Chef participated in a contest and got a rank X. Chef is trying to find his name in the ranklist but there are too many pages. Each page consists of 25 participants. Chef wants to find the exact page number which contains his name. Help Chef...
```python for i in range(int(input())): a = int(input()) if a % 25 == 0: print(int(a / 25)) else: print(int(a / 25 + 1)) ```
vfc_143522
{ "difficulty": "easy", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/RANKLISTPAGE", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n1\n34\n150\n74\n", "output": "1\n2\n6\n3\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://atcoder.jp/contests/abc138/tasks/abc138_a
Solve the following coding problem using the programming language python: You will be given an integer a and a string s consisting of lowercase English letters as input. Write a program that prints s if a is not less than 3200 and prints red if a is less than 3200. -----Constraints----- - 2800 \leq a < 5000 - s is ...
```python N = int(input()) s = input() if N < 3200: s = 'red' print(s) ```
vfc_143526
{ "difficulty": "easy", "memory_limit": "1024.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://atcoder.jp/contests/abc138/tasks/abc138_a", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3200\npink\n", "output": "pink\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3199\npink\n", "output": "red\n", "type": "stdin_stdout" }, { "fn_name": null, ...
taco
verifiable_code
Solve the following coding problem using the programming language python: The secret organization AiZu AnalyticS has launched a top-secret investigation. There are N people targeted, with identification numbers from 1 to N. As an AZAS Information Strategy Investigator, you have decided to determine the number of peopl...
```python N = int(input()) U = set([i + 1 for i in range(N)]) A = set([int(x) for x in input().split()[1:]]) B = set([int(x) for x in input().split()[1:]]) C = set([int(x) for x in input().split()[1:]]) result = U - A & C | B & C print(len(result)) ```
vfc_143531
{ "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": "5\n3 1 2 3\n2 4 5\n2 2 4", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n3 1 2 1\n2 4 5\n2 3 4", "output": "2\n", "type": "stdin_stdout" }, { "f...
taco
verifiable_code
Solve the following coding problem using the programming language python: rakesh loves to play number games. when He was surfing on google he found one of the game. The theme of the game is to find the shortest way that he can make the number equal to 1. He can only perform only three operations they are -1, /2, /3. A...
```python for t in range(eval(input())): number=int(input()) count=0 while number!=1: if number%3==0: number=number/3 elif number%2==0: number=number/2 else: number=number-1 count=count+1 print(count) ```
vfc_143535
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "20\n23847221\n237483758\n212343535\n231452323\n123124135\n231231345\n128374857\n857392819\n429843209\n235986284\n123984135\n218457538\n485928749\n999999999\n757384756\n3847586\n328935794\n239847249\n249874268\n239857927", "ou...
taco
verifiable_code
Solve the following coding problem using the programming language python: Write a program which manipulates a sequence A = {a1, a2, . . . , an} with the following operations: * add(i, x): add x to ai. * getSum(s, t): print the sum of as, as+1,...,at. Note that the initial values of ai (i = 1, 2, . . . , n) are 0. ...
```python from array import array import bisect import collections import heapq import itertools import operator import sys class BIT: def __init__(self, n): self.n = n self.arr = array('l', [0] * (n + 1)) def __str__(self): return str(self.arr.tolist()) def add(self, i, x): while i <= self.n: self.ar...
vfc_143539
{ "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": "4 5\n0 1 1\n0 2 2\n0 3 3\n1 1 2\n1 2 2", "output": "3\n2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 5\n0 1 1\n0 2 2\n0 1 5\n1 1 2\n1 2 2", "output": "8\n2\n", "type": "s...
taco
verifiable_code
https://www.codechef.com/problems/POOK
Solve the following coding problem using the programming language python: We have found a new chess character — pook. It has the qualities of both a rook and a pawn. Specifically, treating the chessboard to be an N\times N grid where (i, j) denotes the intersection of the i-th row and the j-th column, a pook placed at...
```python for _ in range(int(input())): n = int(input()) print(n if n > 3 else n - 1 if n > 1 else 1) ```
vfc_143543
{ "difficulty": "easy", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/POOK", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1\n2\n3", "output": "1\n1\n2", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/carmichael-numbers3703/1
Solve the following coding problem using the programming language python: A number n is said to be a Carmichael number if it satisfies the following modular arithmetic condition: power(b, n-1) MOD n = 1, for all b ranging from 1 to n such that b and n are relatively prime, i.e, gcd(b, n) = 1 Given a positive ...
```python import math class Solution: def binpow(self, a, b, n): ans = 1 while b: if b & 1: ans = ans * a % n a = a * a % n b >>= 1 return ans def isCarmichael(self, n): for b in range(1, n + 1): if math.gcd(b, n) == 1 and self.binpow(b, n - 1, n) != 1: return 0 return 1 ```
vfc_143547
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/carmichael-numbers3703/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "n = 8", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "n = 3", "output": "1", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/number-of-ways2552/1
Solve the following coding problem using the programming language python: Given a value N. In how many ways you can construct a grid of size N x 4 using tiles of size 1 x 4. Example 1: Input: N = 1 Output: 1 Explaination: We can arrange the tiles horizontally and this is the only way. Example 2: Input: N = 4 Output: ...
```python class Solution: def arrangeTiles(self, N): dp = [1] * (N + 1) for i in range(4, N + 1): dp[i] = dp[i - 1] + dp[i - 4] return dp[N] ```
vfc_143548
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/number-of-ways2552/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": "2", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/SURCHESS
Solve the following coding problem using the programming language python: Chef loves to play chess, so he bought a new chessboard with width M$M$ and height N$N$ recently. Chef considers a chessboard correct if its width (number of columns) is equal to its height (number of rows) and each cell has no side-adjacent cel...
```python import sys from collections import defaultdict dp = defaultdict(int) sys.setrecursionlimit(10 ** 9) (a, b) = [int(j) for j in input().split()] board = [] for i in range(a): l = [int(j) for j in input()] board.append(l) b2 = [[0 for i in range(b)] for j in range(a)] for i in range(a): for j in range(b): i...
vfc_143550
{ "difficulty": "hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/SURCHESS", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "8 8\n00101010\n00010101\n10101010\n01010101\n10101010\n01010101\n10101010\n01010101\n4\n1 2 0 1001\n", "output": "7\n8\n6\n8\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/maximum-average-subarray5859/1
Solve the following coding problem using the programming language python: Given an array Arr of size N and a positive integer K, find the sub-array of length K with the maximum average. Example 1: Input: K = 4, N = 6 Arr[] = {1, 12, -5, -6, 50, 3} Output: 12 -5 -6 50 Explanation: Maximum average is (12 - 5 - 6 + 50)...
```python class Solution: def findMaxAverage(self, arr, n, k): st = 0 ed = k - 1 cur = 0 for i in range(k): cur += arr[i] ma = cur for i in range(k, n): cur += arr[i] cur -= arr[i - k] if ma < cur: ma = cur st = i - k + 1 ed = i return st ```
vfc_143555
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/maximum-average-subarray5859/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "K = 4, N = 6\r\nArr[] = {1, 12, -5, -6, 50, 3}", "output": "12 -5 -6 50", "type": "stdin_stdout" }, { "fn_name": null, "input": "K = 3, N = 7\r\nArr[] = {3, -435, 335, 10, -50, 100, 20}", "outp...
taco
verifiable_code
https://codeforces.com/problemset/problem/1239/B
Solve the following coding problem using the programming language python: This is a harder version of the problem. In this version, n ≤ 300 000. Vasya is an experienced developer of programming competitions' problems. As all great minds at some time, Vasya faced a creative crisis. To improve the situation, Petya gift...
```python def get_bal(): bal = [0] * n bal[0] = u[0] for i in range(1, n): bal[i] = bal[i - 1] + u[i] min_b = min(bal) ans = 0 for i in range(n): if bal[i] == min_b: ans += 1 return ans n = int(input()) u = list(input()) for i in range(n): if u[i] == '(': u[i] = 1 else: u[i] = -1 if sum(u) != 0: pr...
vfc_143560
{ "difficulty": "very_hard", "memory_limit": "512.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1239/B", "time_limit": "1.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "100\n((()()))(()()))(())))((()((()()))(()))())((()(())(((())())((()))())))((()(())((())(())())))(()((())(\n", "output": "8\n23 38", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n(\n", ...
taco
verifiable_code
https://codeforces.com/problemset/problem/568/B
Solve the following coding problem using the programming language python: Little Johnny has recently learned about set theory. Now he is studying binary relations. You've probably heard the term "equivalence relation". These relations are very important in many areas of mathematics. For example, the equality of the tw...
```python def main(): mod = 10 ** 9 + 7 n = int(input()) a = [[0] * (n + 1) for i in range(n + 1)] a[0][0] = 1 for i in range(1, n + 1): a[i][0] = a[i - 1][i - 1] for j in range(1, i + 1): a[i][j] = (a[i][j - 1] + a[i - 1][j - 1]) % mod print(a[n][n - 1]) main() ```
vfc_143564
{ "difficulty": "hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/568/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n", ...
taco
verifiable_code
https://codeforces.com/problemset/problem/1709/B
Solve the following coding problem using the programming language python: You are beta testing the new secret Terraria update. This update will add quests to the game! Simply, the world map can be represented as an array of length $n$, where the $i$-th column of the world has height $a_i$. There are $m$ quests you h...
```python import sys, math, itertools, functools, collections input = sys.stdin.readline def solve(): (n, m) = map(int, input().split(' ')) a = list(map(int, input().split(' '))) right = [0] * n left = [0] * n x = 0 for i in range(1, n): if a[i - 1] > a[i]: x += a[i - 1] - a[i] right[i] = x x = 0 for i ...
vfc_143568
{ "difficulty": "easy", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1709/B", "time_limit": "2 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7 6\n10 8 9 6 8 12 7\n1 2\n1 7\n4 6\n7 1\n3 5\n4 2\n", "output": "2\n10\n0\n7\n3\n1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "8 6\n1 2 3 4 5 6 7 8\n1 8\n7 1\n1 2\n2 3\n4 5\n4 5\n", ...
taco
verifiable_code
https://codeforces.com/problemset/problem/1512/B
Solve the following coding problem using the programming language python: There is a square field of size $n \times n$ in which two cells are marked. These cells can be in the same row or column. You are to mark two more cells so that they are the corners of a rectangle with sides parallel to the coordinate axes. Fo...
```python t = int(input()) for inh in range(0, t): n = int(input()) (row, column, c) = ([], [], 0) for inhg in range(0, n): s = input() if '*' in s and c < 2: for i in range(0, n): if s[i] == '*': row.append(inhg) column.append(i) c += 1 if row[0] == row[1]: if row[0] == 0: row.append...
vfc_143572
{ "difficulty": "easy", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1512/B", "time_limit": "2 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n4\n..*.\n....\n*...\n....\n2\n*.\n.*\n2\n.*\n.*\n3\n*.*\n...\n...\n5\n.....\n..*..\n.....\n.*...\n.....\n4\n....\n....\n*...\n*...\n", "output": "*.*.\n....\n*.*.\n....\n**\n**\n**\n**\n*.*\n*.*\n...\n.....\n.**..\n.....\n...
taco
verifiable_code
https://www.hackerrank.com/challenges/permutation-equation/problem
Solve the following coding problem using the programming language python: Given a sequence of $n$ integers, $p(1),p(2),...,p(n)$ where each element is distinct and satisfies $1\leq p(x)\leq n$. For each $\boldsymbol{x}$ where $1\leq x\leq n$, that is $\boldsymbol{x}$ increments from $\mbox{1}$ to $n$, find any integer...
```python n = int(input()) ps = [int(x) for x in input().split()] for x in range(1, n + 1): for y in range(n): if ps[ps[y] - 1] == x: print(y + 1) break ```
vfc_143576
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.hackerrank.com/challenges/permutation-equation/problem", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n2 3 1\n", "output": "2\n3\n1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n4 3 5 1 2\n", "output": "1\n3\n5\n4\n2\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/32/C
Solve the following coding problem using the programming language python: It is known that fleas in Berland can jump only vertically and horizontally, and the length of the jump is always equal to s centimeters. A flea has found herself at the center of some cell of the checked board of the size n × m centimeters (eac...
```python (n, m, s) = map(int, input().split()) r = -(-n // s) * (s if n % s == 0 else n % s) c = -(-m // s) * (s if m % s == 0 else m % s) print(r * c) ```
vfc_143580
{ "difficulty": "medium_hard", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/32/C", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "694117 431924 737\n", "output": "13934440800", "type": "stdin_stdout" }, { "fn_name": null, "input": "1000000 1000000 12345\n", "output": "20340100", "type": "stdin_stdout" }, { ...
taco
verifiable_code
Solve the following coding problem using the programming language python: Little Jhool is still out of his mind - exploring all his happy childhood memories. And one of his favorite memory is when he found a magical ghost, who promised to fulfill one of Little Jhool's wish. Now, Little Jhool was a kid back then, and...
```python tc = int(input()) while (tc>0): tc = tc - 1 a = input() r, u, b, y = a.count('r'), a.count('u'), a.count('b'), a.count('y') print(min(r, min(u, (min(b, y))))) ```
vfc_143584
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10\nxndttmdfrootikifokpfybngthjtsnimvmunukcnqumvnceqzvoufkeokspjtanjpvcmxdvya\njyohyidkifxmxxxdpwhqxixppuifaamqaajrhcizsznmkuoamjfhrpegjplrdkbqgnqqvxjjp\nwlffsgpehqhxlgejtukggjddklaasynluivoyxsskahoyzlehrbankvbgbkdqvcrbopvwaxoo\nnu...
taco
verifiable_code
Solve the following coding problem using the programming language python: Anchored Balloon A balloon placed on the ground is connected to one or more anchors on the ground with ropes. Each rope is long enough to connect the balloon and the anchor. No two ropes cross each other. Figure E-1 shows such a situation. <im...
```python import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools sys.setrecursionlimit(10 ** 7) inf = 10 ** 20 eps = 1.0 / 10 ** 13 mod = 10 ** 9 + 7 dd = [(-1, 0), (0, 1), (1, 0), (0, -1)] ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (...
vfc_143588
{ "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\n10 10 20\n10 -10 20\n-10 10 120\n1\n10 10 16\n2\n10 10 20\n10 -10 20\n2\n100 0 101\n-90 0 91\n2\n0 0 53\n30 40 102\n3\n10 10 20\n10 -10 20\n-10 -10 20\n3\n1 5 13\n5 -3 13\n-3 -2 13\n3\n98 97 168\n-82 -80 193\n-99 -96 211\n4\n90 ...
taco
verifiable_code
https://www.codechef.com/problems/XYTREE
Solve the following coding problem using the programming language python: Chef has a tree consisting of N nodes, rooted at node 1. Every node of this tree can be assigned a binary value (0 or 1). Initially, every node is assigned 0. We define AND-value of a set of nodes as the [bitwise AND] of all the values of the n...
```python import random import math from collections import defaultdict, Counter, deque, OrderedDict from functools import lru_cache import bisect import heapq import sys input = lambda : sys.stdin.readline().strip() class SegmentTree: def __init__(self, arr, func=lambda x, y: x + y, defaultvalue=0): self.n = len(...
vfc_143592
{ "difficulty": "hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/XYTREE", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n5\n1 2\n1 3\n2 4\n2 5\n5\n1 1\n1 3\n2\n1 5\n2\n", "output": "3\n2", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/630/C
Solve the following coding problem using the programming language python: The numbers of all offices in the new building of the Tax Office of IT City will have lucky numbers. Lucky number is a number that consists of digits 7 and 8 only. Find the maximum number of offices in the new building of the Tax Office given t...
```python n = int(input()) res = pow(2, n + 1) res = res - 2 print(res) ```
vfc_143596
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/630/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n", "output": "6", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n", "ou...
taco
verifiable_code
Solve the following coding problem using the programming language python: Given is a string S. Let T be the concatenation of K copies of S. We can repeatedly perform the following operation: choose a character in T and replace it with a different character. Find the minimum number of operations required to satisfy the...
```python s = input() k = int(input()) m = 0 j = 0 if len(set(list(s))) == 1: print(len(s) * k // 2) exit() for i in range(len(s)): if len(s) <= j + 1: a = m * k if s[0] == s[-1] == s[len(s) // 3]: print(a + k - 1) else: print(a) break if s[j] == s[j + 1]: m += 1 j += 1 j += 1 ```
vfc_143600
{ "difficulty": "unknown_difficulty", "memory_limit": "1024.0 megabytes", "memory_limit_bytes": null, "problem_url": null, "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "cooooooooonteeeeeeeedest\n999993333", "output": "7999946664\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "issih\n2", "output": "2\n", "type": "stdin_stdout" }, { ...
taco
verifiable_code
https://codeforces.com/problemset/problem/1505/B
Solve the following coding problem using the programming language python: Many people are aware of DMCA – Digital Millennium Copyright Act. But another recently proposed DMCA – Digital Millennium Calculation Act – is much less known. In this problem you need to find a root of a number according to this new DMCA law. ...
```python n = int(input()) sumo = n while n >= 10: sumo = 0 while n != 0: sumo += n % 10 n //= 10 n = sumo print(sumo) ```
vfc_143604
{ "difficulty": "medium_hard", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1505/B", "time_limit": "1.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "81\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "98\n", "output": "8\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "29\n", ...
taco
verifiable_code
https://www.codechef.com/INOIPRAC/problems/INOI1402
Solve the following coding problem using the programming language python: -----Indian National Olympiad in Informatics 2014----- Nikhil’s slogan has won the contest conducted by Drongo Airlines and he is entitled to a free ticket between any two destinations served by the airline. All cities served by Drongo Airlines ...
```python (c, f) = list(map(int, input().split())) l = [[1000001 for i in range(c)] for j in range(c)] while f: (x, y, cost) = list(map(int, input().split())) l[x - 1][y - 1] = cost l[y - 1][x - 1] = cost f -= 1 for i in range(c): l[i][i] = 0 for k in range(c): for x in range(c): for y in range(c): if x == k...
vfc_143608
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/INOIPRAC/problems/INOI1402", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 5\n1 2 10\n1 3 24\n2 3 2\n2 4 15\n3 4 7\n", "output": "19\nNote : Your program should not print anything other than what is specified in the output format. Please remove all diagnostic print statements before making your fi...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/number-series3015/1
Solve the following coding problem using the programming language python: Find the Nth term of the following series : N Nth term 1 0 2 1 3 0 4 2 5 0 6 1 7 0 8 3 9 0 10 1 and so on....... Example 1: Input: N = 8 Output: 3 Explanation: According to the series for N = 8 Nth term is 3. Ex...
```python class Solution: def findNth(ob, n): ans = 0 while n: if n & 1: return ans else: ans += 1 n >>= 1 return -1 ```
vfc_143612
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/number-series3015/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 8", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "N = 5", "output": "0", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1385/C
Solve the following coding problem using the programming language python: You are given an array $a$ consisting of $n$ integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from $a$ to make it a good array. Recall that the prefix of the array $a=[a_1, a_2, \dots, a_n]$ i...
```python from math import * sInt = lambda : int(input()) mInt = lambda : map(int, input().split()) lInt = lambda : list(map(int, input().split())) t = sInt() for _ in range(t): n = sInt() a = lInt() x = n - 1 while a[x - 1] >= a[x] and x > 0: x -= 1 while a[x - 1] <= a[x] and x > 0: x -= 1 print(x) ```
vfc_143613
{ "difficulty": "easy", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1385/C", "time_limit": "1 second" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n4\n1 2 3 4\n7\n4 3 3 8 4 5 2\n3\n1 1 1\n7\n1 3 1 4 5 3 2\n5\n5 4 3 2 3\n", "output": "0\n4\n0\n2\n3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n4\n1 2 3 4\n7\n4 3 3 8 4 5 2\n3\n1...
taco
verifiable_code
https://www.codechef.com/problems/BIBOARD
Solve the following coding problem using the programming language python: Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef loves single-colored squares, so he got a rectangular board with size $N \times M$ consisting only of black cells and white cells. He calculates the *cost* of...
```python import collections class Dinic: def __init__(self, n): self.n = n self.g = [[] for i in range(n)] def add_edge(self, fr, to, cap): self.g[fr].append([to, cap, len(self.g[to])]) self.g[to].append([fr, 0, len(self.g[fr]) - 1]) def add_multi_edge(self, v1, v2, cap1, cap2): self.g[v1].append([v2,...
vfc_143617
{ "difficulty": "very_hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/BIBOARD", "time_limit": "3 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n3 3\n10?\n01?\n???\n1 1 1\n2 2 2", "output": "18", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/flatten-binary-tree-to-linked-list/1
Solve the following coding problem using the programming language python: Given the root of a binary tree, flatten the tree into a "linked list": The "linked list" should use the same Node class where the right child pointer points to the next node in the list and the left child pointer is always null. The "linked...
```python class Solution: def flatten(self, root): stack = [(root, False)] dummy = Node(-1) curr = dummy while stack: (node, visited) = stack.pop() if visited: curr.right = node node.left = None curr = node elif node: stack.append((node.right, False)) stack.append((node.left, Fals...
vfc_143622
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/flatten-binary-tree-to-linked-list/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\r\n / \\\r\n 2 5\r\n / \\ \\\r\n 3 4 6", "output": "1 2 3 4 5 6", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\r\n / \\\r\n 3 4\r\n ...
taco
verifiable_code
https://codeforces.com/problemset/problem/1420/C2
Solve the following coding problem using the programming language python: This is the hard version of the problem. The difference between the versions is that the easy version has no swap operations. You can make hacks only if all versions of the problem are solved. Pikachu is a cute and friendly pokémon living in th...
```python input = __import__('sys').stdin.readline def check(*inds): global localmax, localmin, maxs, mins for ind in inds: if not ok(ind): continue if localmax[ind] == 0 and s[ind - 1] < s[ind] > s[ind + 1]: localmax[ind] = 1 maxs += s[ind] if localmin[ind] == 0 and s[ind - 1] > s[ind] < s[ind + 1]: ...
vfc_143624
{ "difficulty": "hard", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1420/C2", "time_limit": "2 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n3 1\n1 3 2\n1 2\n2 2\n1 2\n1 2\n1 2\n7 5\n1 2 5 4 3 6 7\n1 2\n6 7\n3 4\n1 2\n2 3\n", "output": "3\n4\n2\n2\n2\n9\n10\n10\n10\n9\n11\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n2 ...
taco
verifiable_code
https://www.codechef.com/IARCSJUD/problems/TIMBER
Solve the following coding problem using the programming language python: The GoC Timber Mafia is notorious for its deforestation activities in the forests near Siruseri. These activities have increased multifold after the death of the bandit who used to lord over these jungles. Having lost the battle to prevent the ...
```python from sys import stdin (n, m) = map(int, stdin.readline().split()) forest = [] matrix = [] for _ in range(n): forest.append(list(map(int, stdin.readline().split()))) matrix.append([0] * m) matrix[0][0] = forest[0][0] for j in range(1, m): matrix[0][j] = matrix[0][j - 1] + forest[0][j] for i in range(1, n): ...
vfc_143628
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/IARCSJUD/problems/TIMBER", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 4\n3 4 15 23\n14 20 12 9\n3 8 12 15\n12 20 7 5\n2\n2 2 3 4\n4 2 4 2\n", "output": "76\n20\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: G --Derangement / Derangement Story Person D is doing research on permutations. At one point, D found a permutation class called "Derangement". "It's cool to have a perfect permutation !!! And it starts with D !!!", the person of D who had a c...
```python import sys def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] def ...
vfc_143632
{ "difficulty": "unknown_difficulty", "memory_limit": "536.870912 megabytes", "memory_limit_bytes": null, "problem_url": null, "time_limit": "1.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n2 1 3 5 4", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n2 1 0 5 4", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "in...
taco
verifiable_code
Solve the following coding problem using the programming language python: Snuke received a triangle as a birthday present. The coordinates of the three vertices were (x_1, y_1), (x_2, y_2), and (x_3, y_3). He wants to draw two circles with the same radius inside the triangle such that the two circles do not overlap (...
```python from math import hypot (x1, y1, x2, y2, x3, y3) = map(int, open(0).read().split()) a = hypot(x1 - x2, y1 - y2) b = hypot(x2 - x3, y2 - y3) c = hypot(x3 - x1, y3 - y1) R = abs((x2 - x1) * (y3 - y1) - (x3 - x1) * (y2 - y1)) / (a + b + c) m = max(a, b, c) r = m / (2 + m / R) print('{:.12f}'.format(r)) ```
vfc_143637
{ "difficulty": "unknown_difficulty", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": null, "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 1\n1 5\n1 9", "output": "0.428755972649\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "0 -1\n1 1\n2 0", "output": "0.350073412538\n", "type": "stdin_stdout" }, { ...
taco
verifiable_code
Solve the following coding problem using the programming language python: D: Indecision-Indecision- problem Ebi-chan has been addicted to gal games lately, and her goal now is to capture two heroines at the same time. Ebi-chan can use several events to increase her liking from the heroine, but only one heroine can ...
```python (N, C) = map(int, input().split()) events = [] for i in range(N): events.append(list(map(int, input().split()))) def solve(): L = 250 dp = [[-10 ** 18] * (L + 1) for i in range(C + 1)] for j in range(C + 1): dp[j][0] = 0 for (a, b, c) in events: for j in range(C - c, -1, -1): for k in range(L + 1...
vfc_143641
{ "difficulty": "unknown_difficulty", "memory_limit": "268.435456 megabytes", "memory_limit_bytes": null, "problem_url": null, "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 4\n4 2 2\n2 1 1\n2 1 1", "output": "6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 4\n4 2 2\n2 1 1\n3 2 1", "output": "7\n", "type": "stdin_stdout" }, { "f...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/jumbled-strings0431/1
Solve the following coding problem using the programming language python: You are provided an input string S and the string “GEEKS” . Find the number of ways in which the subsequence “GEEKS” can be formed from the string S. Example 1: Input : S = "GEEKS" Output: 1 Explanation: "GEEKS" occurs in S only once. Example...
```python class Solution: def TotalWays(self, s1): mod = int(1000000000.0 + 7) s2 = 'GEEKS' dp = [[0 for i in range(len(s2) + 1)] for j in range(len(s1) + 1)] dp[0][0] = 1 for i in range(1, len(s1) + 1): dp[i][0] = 1 for i in range(1, len(s1) + 1): for j in range(1, len(s2) + 1): if s1[i - 1] ==...
vfc_143645
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/jumbled-strings0431/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "S = \"GEEKS\"", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "S = \"AGEEKKSB\"", "output": "2", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: You are given an integer n find its next greater or equal number whose binary representation must not contain consecutive ones. For eg. given n=6 whose binary is 110 and the next number with no consecutive ones is 8 whose binary is 1000. INPU...
```python test = int(input()) a = [0 for i in range(test)] for i in range(test): a[i] = int(input()) for i in range(test): n = a[i] b = str(bin(n)) while '11' in b: n+=1 b = str(bin(n)) print(n) ```
vfc_143646
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "40\n41\n1191\n164\n586\n659\n916\n372\n976\n1048\n1018\n769\n997\n1069\n785\n89\n491\n527\n836\n1125\n500\n307\n1030\n200\n153\n292\n42\n145\n206\n1208\n151\n511\n748\n1197\n432\n635\n168\n987\n385\n993\n22", "output": "72\n8...
taco
verifiable_code
https://codeforces.com/problemset/problem/1761/B
Solve the following coding problem using the programming language python: Define a cyclic sequence of size $n$ as an array $s$ of length $n$, in which $s_n$ is adjacent to $s_1$. Muxii has a ring represented by a cyclic sequence $a$ of size $n$. However, the ring itself hates equal adjacent elements. So if two adjac...
```python t = int(input()) while t: n = int(input()) a = [int(x) for x in input().split()] s = set(a) sum = 0 if len(s) > 2: print(n) elif len(s) == 1: print(1) else: print(2 + (n - 2) // 2) t -= 1 ```
vfc_143650
{ "difficulty": "easy", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1761/B", "time_limit": "1 second" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n4\n1 2 3 2\n4\n1 2 1 2\n1\n1\n", "output": "4\n3\n1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n100\n60 76 89 77 41 81 42 49 39 37 48 56 26 38 85 50 40 13 20 24 79 21 22 9 92 11 ...
taco
verifiable_code
Solve the following coding problem using the programming language python: Find the number, modulo 998244353, of sequences of length N consisting of 0, 1 and 2 such that none of their contiguous subsequences totals to X. Constraints * 1 \leq N \leq 3000 * 1 \leq X \leq 2N * N and X are integers. Input Input is give...
```python def modfac(n, MOD): f = 1 factorials = [1] for m in range(1, n + 1): f *= m f %= MOD factorials.append(f) inv = pow(f, MOD - 2, MOD) invs = [1] * (n + 1) invs[n] = inv for m in range(n, 1, -1): inv *= m inv %= MOD invs[m - 1] = inv return (factorials, invs) def modnCr(n, r, mod, fac, inv)...
vfc_143654
{ "difficulty": "unknown_difficulty", "memory_limit": "1024.0 megabytes", "memory_limit_bytes": null, "problem_url": null, "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 3", "output": "47\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 6", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "13 13", ...
taco
verifiable_code
Solve the following coding problem using the programming language python: We have a pyramid with N steps, built with blocks. The steps are numbered 1 through N from top to bottom. For each 1≤i≤N, step i consists of 2i-1 blocks aligned horizontally. The pyramid is built so that the blocks at the centers of the steps ar...
```python import sys sys.setrecursionlimit(10 ** 8) ini = lambda : int(sys.stdin.readline()) inm = lambda : map(int, sys.stdin.readline().split()) inl = lambda : list(inm()) ins = lambda : sys.stdin.readline().rstrip() debug = lambda *a, **kw: print('\x1b[33m', *a, '\x1b[0m', **dict(file=sys.stderr, **kw)) (n, x) = inm...
vfc_143658
{ "difficulty": "unknown_difficulty", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": null, "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 1", "output": "No\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 2", "output": "Yes\n1\n2\n3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": ...