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/deletion-and-reverse-in-linked-list/1
Solve the following coding problem using the programming language python: Given a Circular Linked List of size N. The task is to delete the given node (excluding the first and last node) in the circular linked list and then print the reverse of the circular linked list. Example 1: Input: 5 2 5 7 8 10 8 Output: 10 7 ...
```python def deleteNode(head, key): temp = head while True: if temp.next.data == key: temp.next = temp.next.next break else: temp = temp.next def reverse(head): last = head curr = head while last.next != head: last = last.next prev = last while curr != last: tmp = curr.next curr.next = prev ...
vfc_144435
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/deletion-and-reverse-in-linked-list/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n2 5 7 8 10\n8", "output": "10 7 5 2", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n1 7 8 10\n8", "output": "10 7 1", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1165/B
Solve the following coding problem using the programming language python: Polycarp wants to train before another programming competition. During the first day of his training he should solve exactly $1$ problem, during the second day — exactly $2$ problems, during the third day — exactly $3$ problems, and so on. Durin...
```python def get_num(): return int(input()) def print_arr(arr: list): for val in arr: print(val) def read_num_list(k): num_str = input() return [int(v) for v in num_str.split(' ')] n = get_num() problems = read_num_list(n) problems = sorted(problems) i = 1 j = 0 while True: if j >= len(problems): break if ...
vfc_144436
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1165/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n3 1 4 1\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n1 1 1\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "inpu...
taco
verifiable_code
https://codeforces.com/problemset/problem/1462/E2
Solve the following coding problem using the programming language python: This is the hard version of this problem. The only difference between the easy and hard versions is the constraints on $k$ and $m$. In this version of the problem, you need to output the answer by modulo $10^9+7$. You are given a sequence $a$ o...
```python MOD = 10 ** 9 + 7 N = 200001 fact = [1] for i in range(1, N + 1): fact.append(fact[-1] * i % MOD) def nCr(n, r): if n <= r: return n == r a = fact[n] b = fact[n - r] * fact[r] % MOD b = pow(b, MOD - 2, MOD) return a * b % MOD import math import bisect for i in range(int(input())): (n, m, k) = map(in...
vfc_144440
{ "difficulty": "medium_hard", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1462/E2", "time_limit": "4 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n4 3 2\n1 2 4 3\n4 2 1\n1 1 1 1\n1 1 1\n1\n10 4 3\n5 6 1 3 2 9 8 1 2 4\n", "output": "2\n6\n1\n20\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n1 1 1\n1\n1 1 1\n1\n1 1 1\n1\n", ...
taco
verifiable_code
https://atcoder.jp/contests/abc168/tasks/abc168_b
Solve the following coding problem using the programming language python: We have a string S consisting of lowercase English letters. If the length of S is at most K, print S without change. If the length of S exceeds K, extract the first K characters in S, append ... to the end of them, and print the result. -----Co...
```python K = int(input()) S = str(input()) if K >= len(S): print(S) else: print(S[0:K] + '...') ```
vfc_144444
{ "difficulty": "easy", "memory_limit": "1024.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://atcoder.jp/contests/abc168/tasks/abc168_b", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7\nnikoandsolstice\n", "output": "nikoand...\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "40\nferelibenterhominesidquodvoluntcredunt\n", "output": "ferelibenterhominesidquodvolunt...
taco
verifiable_code
https://codeforces.com/problemset/problem/1469/C
Solve the following coding problem using the programming language python: You want to build a fence that will consist of $n$ equal sections. All sections have a width equal to $1$ and height equal to $k$. You will place all sections in one line side by side. Unfortunately, the ground beneath the fence is not flat. Fo...
```python for _ in range(int(input())): (n, h) = map(int, input().split()) a = list(map(int, input().split())) mi = a[0] ma = a[0] a = a[1:] s = 1 for x in a: mi = max(x, mi - h + 1) ma = min(x + h - 1, ma + h - 1) if ma < mi: s = 0 if mi != a[-1]: s = 0 print('YES') if s == 1 else print('NO') ```
vfc_144449
{ "difficulty": "medium_hard", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1469/C", "time_limit": "2 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n6 3\n0 0 2 5 1 1\n2 3\n0 2\n3 2\n3 0 2\n", "output": "YES\nYES\nNO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n2 2\n2 8\n", "output": "NO\n", "type": "stdin_stdout" ...
taco
verifiable_code
https://www.codechef.com/PBK12020/problems/ITGUY20
Solve the following coding problem using the programming language python: Finally, the pandemic is over in ChefLand, and the chef is visiting the school again. Chef likes to climb the stairs of his school's floor by skipping one step, sometimes chef climbs the stairs one by one. Simply, the chef can take one or 2 step...
```python for _ in range(int(input())): N = int(input()) if N % 2 == 0: print(N // 2 + 1) else: print((N - 1) // 2 + 1) ```
vfc_144453
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/PBK12020/problems/ITGUY20", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n3\n", "output": "2\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/PRFYIT
Solve the following coding problem using the programming language python: We say that a binary string (a string containing only characters '0' and '1') is pure if it does not contain either of the strings "0101" or "1010" as a subsequence. Recall that string T is a subsequence of string S if we can delete some of the ...
```python for _ in range(int(input())): bi = input().strip() dp = [0 if i < 2 else len(bi) for i in range(6)] for c in bi: if c == '1': dp[3] = min(dp[3], dp[0]) dp[0] += 1 dp[5] = min(dp[5], dp[2]) dp[2] += 1 dp[4] += 1 else: dp[2] = min(dp[2], dp[1]) dp[1] += 1 dp[4] = min(dp[4], dp[3])...
vfc_144462
{ "difficulty": "very_hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/PRFYIT", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n010111101\n1011100001011101\n0110\n111111\n", "output": "2\n3\n0\n0\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1528/B
Solve the following coding problem using the programming language python: Kavi has 2n points lying on the OX axis, i-th of which is located at x = i. Kavi considers all ways to split these 2n points into n pairs. Among those, he is interested in good pairings, which are defined as follows: Consider n segments with e...
```python import sys, math import io, os def data(): return sys.stdin.buffer.readline().strip() def mdata(): return list(map(int, data().split())) def outl(var): sys.stdout.write(' '.join(map(str, var)) + '\n') def out(var): sys.stdout.write(str(var) + '\n') mod = 998244353 n = int(data()) l = [1] * (n + 1) for...
vfc_144466
{ "difficulty": "medium_hard", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1528/B", "time_limit": "1.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "333625\n", "output": "668510586", "type": "stdin_stdout" }, { "fn_name": null, "input": "693549\n", "output": "721751076", "type": "stdin_stdout" }, { "fn_name": null, ...
taco
verifiable_code
https://codeforces.com/problemset/problem/1007/A
Solve the following coding problem using the programming language python: You are given an array of integers. Vasya can permute (change order) its integers. He wants to do it so that as many as possible integers will become on a place where a smaller integer used to stand. Help Vasya find the maximal number of such in...
```python from collections import Counter as co x = int(input()) y = list(map(int, input().split())) print(x - max(co(y).values())) ```
vfc_144470
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1007/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7\n10 1 1 1 5 5 3\n", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n1 1 1 1 1\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, ...
taco
verifiable_code
https://www.codechef.com/problems/DIVISIBLEBY
Solve the following coding problem using the programming language python: You are given an array A consisting of N positive integers. Suppose F(B,X) gives the minimum positive integer Y such that: X divides Y \cdot B_{i} for all (1 ≤ i ≤ |B|). Find the value of F(A,A_{i}) for all (1 ≤ i ≤ N). ------ Input Format -...
```python import math as m t = int(input()) for _ in range(t): n = int(input()) A = list(map(int, input().split())) gcd = A[0] for j in A: gcd = m.gcd(j, gcd) for j in A: print(j // gcd, end=' ') print() ```
vfc_144474
{ "difficulty": "medium", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/DIVISIBLEBY", "time_limit": "2 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n2\n1 2\n3\n2 2 2\n", "output": "1 2\n1 1 1\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/77/E
Solve the following coding problem using the programming language python: Have you ever tasted Martian food? Well, you should. Their signature dish is served on a completely black plate with the radius of R, flat as a pancake. First, they put a perfectly circular portion of the Golden Honduras on the plate. It has t...
```python def solve(R, r, k): r = r / R n = k answer = (1 - r) * r / (2 * (n ** 2 * (1 - r) ** 2 + r)) answer = 2 * R * answer print('%.10f' % answer) t = int(input()) for i in range(t): (R, r, k) = map(int, input().split()) solve(R, r, k) ```
vfc_144478
{ "difficulty": "very_hard", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/77/E", "time_limit": "1.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n4 2 2\n", "output": "0.6666666667\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n1000 999 1\n", "output": "0.9999989990\n", "type": "stdin_stdout" }, { "fn...
taco
verifiable_code
https://codeforces.com/problemset/problem/461/B
Solve the following coding problem using the programming language python: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≤ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tree,...
```python MOD = 1000000007 n = int(input()) p = [int(x) for x in input().split()] x = [int(x) for x in input().split()] children = [[] for x in range(n)] for i in range(1, n): children[p[i - 1]].append(i) count = [(0, 0) for i in range(n)] for i in reversed(range(n)): prod = 1 for ch in children[i]: prod *= count[...
vfc_144482
{ "difficulty": "hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/461/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n0 0\n0 1 1\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n0 1 1 0 4\n1 1 0 0 1 0\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name...
taco
verifiable_code
https://codeforces.com/problemset/problem/1486/D
Solve the following coding problem using the programming language python: You are a given an array $a$ of length $n$. Find a subarray $a[l..r]$ with length at least $k$ with the largest median. A median in an array of length $n$ is an element which occupies position number $\lfloor \frac{n + 1}{2} \rfloor$ after we s...
```python import sys (n, k) = map(int, input().split()) a = list(map(int, input().split())) l = 0 r = n while l < r: if l + 1 == r: try1 = r flag = 0 tmp = 0 grid = [0] for i in range(n): if a[i] >= try1: tmp += 1 else: tmp -= 1 grid.append(tmp) lowestprev = 0 for i in range(k, n + 1): ...
vfc_144486
{ "difficulty": "hard", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1486/D", "time_limit": "2 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 3\n1 2 3 2 1\n", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 2\n1 2 3 4\n", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "...
taco
verifiable_code
https://atcoder.jp/contests/abc071/tasks/abc071_a
Solve the following coding problem using the programming language python: Snuke lives at position x on a number line. On this line, there are two stores A and B, respectively at position a and b, that offer food for delivery. Snuke decided to get food delivery from the closer of stores A and B. Find out which store is...
```python (x, a, b) = map(int, input().split()) print('A' if abs(x - a) < abs(x - b) else 'B') ```
vfc_144490
{ "difficulty": "easy", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://atcoder.jp/contests/abc071/tasks/abc071_a", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 2 7\n", "output": "B\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 999 1000\n", "output": "A\n", "type": "stdin_stdout" }, { "fn_name": null, "input":...
taco
verifiable_code
https://codeforces.com/problemset/problem/1600/J
Solve the following coding problem using the programming language python: You have received data from a Bubble bot. You know your task is to make factory facilities, but before you even start, you need to know how big the factory is and how many rooms it has. When you look at the data you see that you have the dimensi...
```python directions = [(-1, 0), (0, 1), (1, 0), (0, -1)] i_cant_do_bitwise_operations = {0: (False, False, False, False), 1: (False, False, False, True), 2: (False, False, True, False), 3: (False, False, True, True), 4: (False, True, False, False), 5: (False, True, False, True), 6: (False, True, True, False), 7: (Fals...
vfc_144497
{ "difficulty": "medium", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1600/J", "time_limit": "1.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6 1\n13\n5\n7\n15\n13\n7\n", "output": "3 2 1 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 5\n9 14 9 12 13\n5 15 11 6 7\n5 9 14 9 14\n3 2 14 3 14\n", "output": "9 4 4 2 1 \n", ...
taco
verifiable_code
https://www.codechef.com/CDGO2021/problems/STRNCHAR
Solve the following coding problem using the programming language python: Your are given a string $S$ containing only lowercase letter and a array of character $arr$. Find whether the given string only contains characters from the given character array. Print $1$ if the string contains characters from the given array...
```python t = int(input()) for _ in range(t): S = set(input().strip()) n = int(input().strip()) a = set(input().strip().split(' ')) g = True for i in S: if i not in a: g = False if g: print(1) else: print(0) ```
vfc_144501
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/CDGO2021/problems/STRNCHAR", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\nabcd\n4\na b c d\naabbbcccdddd\n4\na b c d\nacd\n3\na b d\n", "output": "1\n1\n0\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: It is lunch time at the Vibrant Gujarat Summit and all the investors are called for the executive lunch. When Bruce reached the lunch area, he found that the waiter was taking out bowls from a big box containing some amount of golden bowls and o...
```python v = eval(input()) print(int((v*(v-1)/2)**.5)+1) ```
vfc_144505
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4684660", "output": "756872327473", "type": "stdin_stdout" }, { "fn_name": null, "input": "120", "output": "85", "type": "stdin_stdout" }, { "fn_name": null, "input": ...
taco
verifiable_code
Solve the following coding problem using the programming language python: Example Input 2 2 2 1 0 0 0 Output 24 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools sys.setrecursionlimit(10 ** 7) inf = 10 ** 20 eps = 1.0 / 10 ** 10 mod = 10 ** 9 + 7 dd = [(-1, 0), (0, 1), (1, 0), (0, -1)] ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (...
vfc_144509
{ "difficulty": "unknown_difficulty", "memory_limit": "268.435456 megabytes", "memory_limit_bytes": null, "problem_url": null, "time_limit": "5.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 2 2 0\n0 0 0", "output": "24\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 1 2 0\n-1 -1 0", "output": "16\n", "type": "stdin_stdout" }, { "fn_name": null, ...
taco
verifiable_code
https://codeforces.com/problemset/problem/1343/A
Solve the following coding problem using the programming language python: Recently Vova found $n$ candy wrappers. He remembers that he bought $x$ candies during the first day, $2x$ candies during the second day, $4x$ candies during the third day, $\dots$, $2^{k-1} x$ candies during the $k$-th day. But there is an issu...
```python t = int(input()) for i in range(t): n = int(input()) k = 2 j = 0 while True: j = 2 ** k if n % (j - 1) == 0: break k = k + 1 print(n // (j - 1)) ```
vfc_144513
{ "difficulty": "easy", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1343/A", "time_limit": "1 second" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7\n3\n6\n7\n21\n28\n999999999\n999999984\n", "output": "1\n2\n1\n7\n4\n333333333\n333333328\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n6\n", "output": "2\n", "type": "s...
taco
verifiable_code
Solve the following coding problem using the programming language python: You are given a string of length N. Calculate the number of distinct substrings of S. Constraints * 1 \leq N \leq 500,000 * S consists of lowercase English letters. Input Input is given from Standard Input in the following format: S Outp...
```python class StrAlg: @staticmethod def sa_naive(s): n = len(s) sa = list(range(n)) sa.sort(key=lambda x: s[x:]) return sa @staticmethod def sa_doubling(s): n = len(s) sa = list(range(n)) rnk = s tmp = [0] * n k = 1 while k < n: sa.sort(key=lambda x: (rnk[x], rnk[x + k]) if x + k < n else...
vfc_144517
{ "difficulty": "unknown_difficulty", "memory_limit": "1024.0 megabytes", "memory_limit_bytes": null, "problem_url": null, "time_limit": "5.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "abcacbb", "output": "24\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "baaaa", "output": "9\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "aaab...
taco
verifiable_code
Solve the following coding problem using the programming language python: Snuke has decided to use a robot to clean his room. There are N pieces of trash on a number line. The i-th piece from the left is at position x_i. We would like to put all of them in a trash bin at position 0. For the positions of the pieces o...
```python def E(i, y): if i == 1: return 5 * y else: return (2 * i + 1) * y def ceil(a, b): return -(-a // b) (N, X) = map(int, input().split()) x = [int(i) for i in input().split()] a = [0] for i in range(N): a.append(a[-1] + x[i]) ans = 10 ** 50 for k in range(1, N + 1): tmp = (N + k) * X for i in range(N ...
vfc_144521
{ "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 1\n1 1856513539 999999998 999999999 1000000000", "output": "24282567693\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "16 10\n1 7 12 27 52 75 731 13856 395504 534840 1276551 903860 9384...
taco
verifiable_code
https://www.codechef.com/problems/LGSEG
Solve the following coding problem using the programming language python: Read problem statements in [Mandarin], [Bengali], [Russian], and [Vietnamese] as well. Chef has a sequence A_{1}, A_{2}, \ldots, A_{N}. Let's call a contiguous subsequence of A a *segment*. A segment is *good* if it can be divided into at most...
```python def build(N, start_index): up = [[None] * N for _ in range(20)] up[0] = start_index for i in range(1, 20): for j in range(N): p = up[i - 1][j] if p == -1: up[i][j] = -1 else: up[i][j] = up[i - 1][p] return up def call(up, node, K): (last, jump) = (node, 1) for i in range(19): if no...
vfc_144525
{ "difficulty": "very_hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/LGSEG", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n5 2 5\n1 3 2 1 5\n5 3 5\n5 1 5 1 1", "output": "4\n4", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/2/A
Solve the following coding problem using the programming language python: The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more diffic...
```python n = int(input()) d = {} l = [] for _ in range(n): (name, score) = input().split() score = int(score) l.append((name, score)) d[name] = d.get(name, 0) + score m = max([x for x in d.values()]) ties = [x for (x, y) in d.items() if y == m] if len(ties) == 1: print(ties[0]) exit() else: d.clear() for row i...
vfc_144530
{ "difficulty": "medium", "memory_limit": "64.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/2/A", "time_limit": "1.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "15\naawtvezfntstrcpgbzjbf 681\nzhahpvqiptvksnbjkdvmknb -74\naawtvezfntstrcpgbzjbf 661\njpdwmyke 474\naawtvezfntstrcpgbzjbf -547\naawtvezfntstrcpgbzjbf 600\nzhahpvqiptvksnbjkdvmknb -11\njpdwmyke 711\nbjmj 652\naawtvezfntstrcpgbzjbf ...
taco
verifiable_code
https://www.codechef.com/problems/COOK82A
Solve the following coding problem using the programming language python: Read problems statements in mandarin chinese, russian and vietnamese as well. Today is the final round of La Liga, the most popular professional football league in the world. Real Madrid is playing against Malaga and Barcelona is playing again...
```python T = int(input()) for i in range(T): scores = dict() for j in range(4): (team, score) = map(str, input().split(' ')) score = int(score) scores[team] = score if scores['RealMadrid'] < scores['Malaga'] and scores['Barcelona'] > scores['Eibar']: print('Barcelona') else: print('RealMadrid') ```
vfc_144534
{ "difficulty": "easy", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/COOK82A", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\nBarcelona 2\nMalaga 1\nRealMadrid 1\nEibar 0\nMalaga 3\nRealMadrid 2\nBarcelona 8\nEibar 6", "output": "RealMadrid\nBarcelona", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: Problem statement 2D, who is good at cooking, is trying to make lunch. Cooking requires all N ingredients a_ {0}, a_ {1},…, a_ {N−1}. Now, 2D's refrigerator doesn't contain any ingredients, so I have to go to the supermarket to buy it. At the ...
```python n = int(input()) dic = {} price = [] for i in range(n): (a, x) = input().split() dic[a] = i price.append(int(x)) parent = [i for i in range(n)] def find(x): if parent[x] == x: return x parent[x] = find(parent[x]) return parent[x] m = int(input()) for _ in range(m): (s, t) = input().split() (si, ti)...
vfc_144538
{ "difficulty": "unknown_difficulty", "memory_limit": "134.217728 megabytes", "memory_limit_bytes": null, "problem_url": null, "time_limit": "1.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\ntako 2\nyaki 1\n0\ntako yaki", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\ntako 3\nyaji 1\n-1\noakt yaki", "output": "4\n", "type": "stdin_stdout" },...
taco
verifiable_code
https://atcoder.jp/contests/abc128/tasks/abc128_d
Solve the following coding problem using the programming language python: Your friend gave you a dequeue D as a birthday present. D is a horizontal cylinder that contains a row of N jewels. The values of the jewels are V_1, V_2, ..., V_N from left to right. There may be jewels with negative values. In the beginning, y...
```python (n, k) = map(int, input().split()) v = [int(i) for i in input().split()] r = min(n, k) ans = 0 for a in range(r + 1): for b in range(r - a + 1): if b >= 1: q = v[:a] + v[-b:] else: q = v[:a] t = k - a - b m = 0 for i in sorted(q): if i < 0 and t > 0: m += abs(i) t -= 1 ans = max(...
vfc_144543
{ "difficulty": "medium", "memory_limit": "1024.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://atcoder.jp/contests/abc128/tasks/abc128_d", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6 4\n-10 8 2 1 2 6\n", "output": "14\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 4\n-6 -100 50 -2 -5 -3\n", "output": "44\n", "type": "stdin_stdout" }, { "f...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/largest-power-of-prime4416/1
Solve the following coding problem using the programming language python: Given a positive integer N and a prime p, the task is to print the largest power of prime p that divides N!. Here N! means the factorial of N = 1 x 2 x 3 . . (N-1) x N. Note that the largest power may be 0 too. Example 1: Input: N = 5 , p = 2 ...
```python class Solution: def largestPowerOfPrime(self, N, p): sum = 0 while N: N //= p sum += N return sum ```
vfc_144547
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/largest-power-of-prime4416/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 5 , p = 2", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "N = 3 , p = 5", "output": "0", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.hackerrank.com/challenges/two-strings/problem
Solve the following coding problem using the programming language python: Given two strings, determine if they share a common substring. A substring may be as small as one character. Example $s1=\text{'and'}$ $s2=\text{'art'}$ These share the common substring $\class{ML__boldsymbol}{\boldsymbol{a}}$. $\t...
```python a = int(input()) for i in range(a): i = input() j = input() setx = set([a for a in i]) sety = set([y for y in j]) if setx.intersection(sety) == set(): print('NO') else: print('YES') ```
vfc_144548
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.hackerrank.com/challenges/two-strings/problem", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\nhello\nworld\nhi\nworld\n", "output": "YES\nNO\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.hackerrank.com/challenges/possible-path/problem
Solve the following coding problem using the programming language python: Adam is standing at point $(a,b)$ in an infinite 2D grid. He wants to know if he can reach point $(x,y)$ or not. The only operation he can do is to move to point $(a+b,b),(a,a+b),(a-b,b),\text{or}(a,b-a)$ from some point $(a,b)$. It is given tha...
```python t = int(input()) def gcd(a, b): if b == 0: return a return gcd(b, a % b) for i in range(t): (a, b, x, y) = map(int, input().split()) if gcd(a, b) == gcd(x, y): print('YES') else: print('NO') ```
vfc_144552
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.hackerrank.com/challenges/possible-path/problem", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1 1 2 3\n2 1 2 3\n3 3 1 1\n", "output": "YES\nYES\nNO\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/888/D
Solve the following coding problem using the programming language python: A permutation p of size n is an array such that every integer from 1 to n occurs exactly once in this array. Let's call a permutation an almost identity permutation iff there exist at least n - k indices i (1 ≤ i ≤ n) such that p_{i} = i. Your...
```python import math def calculate_derangement(fac, n): ans = fac[n] for i in range(1, n + 1): if i % 2 == 1: ans -= fac[n] // fac[i] else: ans += fac[n] // fac[i] return ans (n, k) = map(int, input().split()) fac = [1] for i in range(1, n + 1): fac.append(fac[i - 1] * i) ans = 0 for i in range(0, k + 1...
vfc_144556
{ "difficulty": "medium_hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/888/D", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 1\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 2\n", "output": "7\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 3\n",...
taco
verifiable_code
https://www.codechef.com/problems/COOLCHEF
Solve the following coding problem using the programming language python: Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef is experimenting in his kitchen. He has $N$ spices (numbered $0$ through $N-1$) with types $S_{0}, S_{1}, \ldots, S_{N-1}$. You should...
```python def exponent(a, y, m): if y == 0: return 1 ss = y // 2 an = exponent(a, ss, m) an = an * an % m if y % 2 == 0: return an else: return a * an % m import bisect (n, q) = map(int, input().split()) it = list(map(int, input().split())) a = [1] x = 10 ** 9 + 7 for i in range(1, n + 1): a.append(a[-1] *...
vfc_144560
{ "difficulty": "very_hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/COOLCHEF", "time_limit": "5 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 3\n1 2 3 7 10\n1 1 1 1\n2 1 3 4\n0 0 0 4", "output": "1\n2\n120", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: problem You are a traveler traveling on the JOI Highway. The JOI Highway is a road that extends straight from east to west, and there are n post towns on the JOI Highway. Numbered. The westernmost post town on the JOI highway is post town 1, an...
```python (n, m) = map(int, input().split()) accums = [0] for i in range(n - 1): accums.append(accums[-1] + int(input())) result = 0 k = 0 for i in range(m): a = int(input()) result = (result + abs(accums[k + a] - accums[k])) % 100000 k += a print(result) ```
vfc_144564
{ "difficulty": "unknown_difficulty", "memory_limit": "134.217728 megabytes", "memory_limit_bytes": null, "problem_url": null, "time_limit": "8.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7 5\n2\n1\n2\n3\n2\n1\n2\n-1\n3\n2\n-3", "output": "19\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "7 5\n2\n0\n2\n3\n2\n1\n2\n-1\n3\n2\n-3", "output": "16\n", "type": "stdin...
taco
verifiable_code
https://codeforces.com/problemset/problem/146/B
Solve the following coding problem using the programming language python: Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya calls a mask of a...
```python s = input() (a, b) = (s.split()[0], s.split()[1]) dif = len(a) - len(b) mask = '' tmp = int(a) tmp += 1 t = str(tmp) while 1: for i in t: if i in ['4', '7']: mask += i if mask == b: break else: tmp += 1 t = str(tmp) mask = '' print(tmp) ```
vfc_144568
{ "difficulty": "easy", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/146/B", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "39999 4774\n", "output": "40774\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "40007 74\n", "output": "50074\n", "type": "stdin_stdout" }, { "fn_name": null, ...
taco
verifiable_code
https://codeforces.com/problemset/problem/1263/B
Solve the following coding problem using the programming language python: A PIN code is a string that consists of exactly $4$ digits. Examples of possible PIN codes: 7013, 0000 and 0990. Please note that the PIN code can begin with any digit, even with 0. Polycarp has $n$ ($2 \le n \le 10$) bank cards, the PIN code o...
```python try: n = int(input()) for i in range(n): count = 0 sub = 0 u = int(input()) b = [] for j in range(u): o = str(input()) b.append(o) d = set(b) for r in d: sub = sub + (b.count(r) - 1) count = count + sub print(count) for (er, gh) in enumerate(b): if b.count(gh) == 1: conti...
vfc_144572
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1263/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n2\n1234\n0600\n2\n1337\n1337\n4\n3139\n3139\n3139\n3139\n", "output": "0\n1234\n0600\n1\n1337\n0337\n3\n3139\n0139\n1139\n2139\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n10\n000...
taco
verifiable_code
https://www.hackerrank.com/challenges/compare-the-triplets/problem
Solve the following coding problem using the programming language python: Alice and Bob each created one problem for HackerRank. A reviewer rates the two challenges, awarding points on a scale from 1 to 100 for three categories: problem clarity, originality, and difficulty. The rating for Alice's challenge is the tr...
```python import sys (a0, a1, a2) = input().strip().split(' ') (a0, a1, a2) = [int(a0), int(a1), int(a2)] (b0, b1, b2) = input().strip().split(' ') (b0, b1, b2) = [int(b0), int(b1), int(b2)] A = (a0 > b0) + (a1 > b1) + (a2 > b2) B = (a0 < b0) + (a1 < b1) + (a2 < b2) print(A, B) ```
vfc_144577
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.hackerrank.com/challenges/compare-the-triplets/problem", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 6 7\n3 6 10\n", "output": "1 1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "17 28 30\n99 16 8\n", "output": "2 1\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/BENCHP
Solve the following coding problem using the programming language python: In the gym, Chef prefers to lift at least $W$ grams during a bench press and if that's impossible, Chef considers his workout to be incomplete and feels bad. The rod weighs $W_{r}$ grams and there are $N$ other weights lying on the floor that w...
```python from collections import Counter tc = int(input()) for _ in range(tc): (n, w, wr) = map(int, input().split()) a = Counter(list(map(int, input().split()))) if wr >= w: print('YES') else: d = 0 for i in a: d += a[i] // 2 * i * 2 if wr + d >= w: print('YES') break else: print('NO') `...
vfc_144581
{ "difficulty": "medium_hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/BENCHP", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n2 5 10 \n2 2\n7 100 50\n100 10 10 10 10 10 90 \n6 100 40 \n10 10 10 10 10 10", "output": "YES\nNO\nYES", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters. A string X is called a good string when the following conditions are all met: * Let L be the length of X. L is divisible...
```python gcd = lambda a, b: a if b == 0 else gcd(b, a % b) (n, m) = map(int, input().split()) s = input() t = input() d = gcd(n, m) if s[::n // d] == t[::m // d]: print(n * m // d) else: print(-1) ```
vfc_144585
{ "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": "3 2\nacq\nae", "output": "6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 3\nabcdef\nabc", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, ...
taco
verifiable_code
https://codeforces.com/problemset/problem/1105/D
Solve the following coding problem using the programming language python: Kilani is playing a game with his friends. This game can be represented as a grid of size $n \times m$, where each cell is either empty or blocked, and every player has one or more castles in some cells (there are no two castles in one cell). T...
```python import sys from collections import deque as dq (h, w, P) = [int(x) for x in input().split()] S = [int(x) for x in input().split()] board = [] for b in sys.stdin.read(): for c in b: if c == '.': board.append(-1) elif 0 <= ord(c) - 49 <= 9: board.append(ord(c) - 49) elif c == '#': board.append(-...
vfc_144591
{ "difficulty": "hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1105/D", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 3 2\n1 1\n1..\n...\n..2\n", "output": "6 3 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 4 4\n1 1 1 1\n....\n#...\n1234\n", "output": "1 4 3 3 \n", "type": "stdin_stdout...
taco
verifiable_code
https://codeforces.com/problemset/problem/1609/C
Solve the following coding problem using the programming language python: While performing complex market analysis William encountered the following problem: For a given array $a$ of size $n$ and a natural number $e$, calculate the number of pairs of natural numbers $(i, k)$ which satisfy the following conditions: $...
```python import sys isPrime = [True] * int(1000000.0 + 2) def solve(): inp = sys.stdin.readline (n, e) = map(int, inp().split()) a = list(map(int, inp().split())) w = [True] * n r = 0 for i in range(n): if w[i]: j = 0 z = i last = -1 last1 = -1 p = False while z < n: w[z] = False v =...
vfc_144595
{ "difficulty": "medium", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1609/C", "time_limit": "2 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n7 3\n10 2 1 3 1 19 3\n3 2\n1 13 1\n9 3\n2 4 2 1 1 1 1 4 2\n3 1\n1 1 1\n4 1\n1 2 1 1\n2 2\n1 2\n", "output": "2\n0\n4\n0\n5\n0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n10 3\n1...
taco
verifiable_code
Solve the following coding problem using the programming language python: Our master carpenter is designing a condominium called Bange Hills Mansion. The condominium is constructed by stacking up floors of the same height. The height of each floor is designed so that the total height of the stacked floors coincides wi...
```python (H, A, B) = map(int, input().split()) ans = 0 for k in range(A, B + 1): if H % k == 0: ans += 1 print(ans) ```
vfc_144599
{ "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": "101 2 5", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "100 2 5", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "111...
taco
verifiable_code
https://www.codechef.com/ICOD2016/problems/ICODE16D
Solve the following coding problem using the programming language python: Now-a-days, Manish is becoming famous for bank robbery in the country because of his cleverness, he never robs own his own.He has four workers A , B, C, and D , all working under him.All of the four take some amount for that. There are total N ...
```python for t in range(int(input())): n = int(input()) l = [] m = [] x = list(map(int, input().split())) l.append(x) m.append(list(x)) for i in range(1, n): x = list(map(int, input().split())) l.append(x) temp = [] for i in range(4): temp.append(x[i] + min(m[-1][:i] + m[-1][i + 1:])) m.append(temp...
vfc_144604
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/ICOD2016/problems/ICODE16D", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n3\n4 7 2 9\n5 6 4 7\n2 6 4 3\n", "output": "10\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/interesting-queries4742/1
Solve the following coding problem using the programming language python: Given an array nums of n elements and q queries . Each query consists of two integers l and r . You task is to find the number of elements of nums[] in range [l,r] which occur atleast k times. Example 1: Input: nums = {1,1,2,1,3}, Queries = {{...
```python import math class Solution: def solveQueries(self, nums, Queries, k): answers = [0] * len(Queries) count = {} n = int(math.sqrt(len(nums))) + 1 q = list(enumerate(Queries)) q.sort(key=lambda a: [int(a[1][0] / n), -a[1][1]]) currentL = 0 currentR = -1 ans = 0 for i in q: left = i[1][0] ...
vfc_144608
{ "difficulty": "medium_hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/interesting-queries4742/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "nums = {1,1,2,1,3}, Queries = {{1,5},\r\n{2,4}}, k = 1", "output": "{3,2}", "type": "stdin_stdout" }, { "fn_name": null, "input": "nums = {1,2,3,1}, Queries = {{1,4},\r\n{2,4},{4,4}, k = 2", "o...
taco
verifiable_code
https://codeforces.com/problemset/problem/811/C
Solve the following coding problem using the programming language python: Vladik often travels by trains. He remembered some of his trips especially well and I would like to tell you about one of these trips: Vladik is at initial train station, and now n people (including Vladik) want to get on the train. They are al...
```python import sys inf = 1 << 30 def solve(): n = int(input()) a = [0] + [int(i) for i in input().split()] maxi = max(a) f = [-1] * (maxi + 1) for i in range(1, n + 1): if f[a[i]] == -1: f[a[i]] = i l = [-1] * (maxi + 1) for i in range(n, 0, -1): if l[a[i]] == -1: l[a[i]] = i dp = [0] * (n + 1) fo...
vfc_144609
{ "difficulty": "hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/811/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n4 4 2 5 2 3\n", "output": "14\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "9\n5 1 3 1 5 2 4 2 5\n", "output": "9\n", "type": "stdin_stdout" }, { "fn_name": ...
taco
verifiable_code
https://codeforces.com/problemset/problem/177/B1
Solve the following coding problem using the programming language python: The Smart Beaver from ABBYY decided to have a day off. But doing nothing the whole day turned out to be too boring, and he decided to play a game with pebbles. Initially, the Beaver has n pebbles. He arranges them in a equal rows, each row has b...
```python n = int(input()) r = n + 1 i = 2 s = n ** 0.5 while i <= s: if n % i == 0: r += n // i n //= i s = n ** 0.5 i = 1 i += 1 print(r) ```
vfc_144613
{ "difficulty": "easy", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/177/B1", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "999161856\n", "output": "1998319610\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "999999937\n", "output": "999999938\n", "type": "stdin_stdout" }, { "fn_name": ...
taco
verifiable_code
https://www.codechef.com/PCR12020/problems/BHARAT
Solve the following coding problem using the programming language python: Bharat was given a problem to solve, by his brother, Lord Ram. The problem was like, given integers, $N$ and $K$, Bharat has to find the number (possibilities) of non-increasing arrays of length $K$, where each element of the array is between $1...
```python import math p = 7 + 10 ** 9 (n, k) = list(map(int, input().split())) c = math.factorial(n + k - 1) // (math.factorial(k) * math.factorial(n - 1)) print(c % p) ```
vfc_144617
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/PCR12020/problems/BHARAT", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 5\n", "output": "6\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/xor-of-all-elements0736/1
Solve the following coding problem using the programming language python: Given a list A having N positive elements. The task to create another list such as i^{th} element is XOR of all elements of A except A[i]. Example 1: Input: A = [2, 1, 5, 9] Output: 13 14 10 6 Explanation: At first position 1^5^9 = 13 At second...
```python class Solution: def getXor(self, A, N): xor = 0 for i in A: xor ^= i for i in range(N): A[i] ^= xor return A ```
vfc_144621
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/xor-of-all-elements0736/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "A = [2, 1, 5, 9]", "output": "13 14 10 6", "type": "stdin_stdout" }, { "fn_name": null, "input": "A = [2, 1]", "output": "1 2", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/modular-exponentiation-for-large-numbers5537/1
Solve the following coding problem using the programming language python: Implement pow(x, n) % M. In other words, given x, n and M, find (x^{n}) % M. Example 1: Input: x = 3, n = 2, m = 4 Output: 1 Explanation: 3^{2} = 9. 9 % 4 = 1. Example 2: Input: x = 2, n = 6, m = 10 Output: 4 Explanation: 2^{6} = 64. 64 % 10 =...
```python class Solution: def PowMod(self, x, n, m): res = 1 while n > 0: if n & 1 != 0: res = res * x % m % m x = x % m * x % m % m n = n >> 1 return res ```
vfc_144622
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/modular-exponentiation-for-large-numbers5537/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "x = 3, n = 2, m = 4", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "x = 2, n = 6, m = 10", "output": "4", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/ROOKPATH
Solve the following coding problem using the programming language python: Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. There is a chessboard with $N$ rows (numbered $1$ through $N$) and $N$ columns (numbered $1$ through $N$). $M$ squares on this chessboard (n...
```python import sys from collections import deque def eulerian_path(root, adj): path = [] stack = [root] while stack: u = stack[-1] if len(adj[u]) == 0: path.append(u) stack.pop() else: v = adj[u][-1] adj[u].pop() adj[v] = [w for w in adj[v] if w != u] stack.append(v) return path def main...
vfc_144623
{ "difficulty": "very_hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/ROOKPATH", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n2 4\n1 1\n1 2\n2 1\n2 2\n1 1\n1 1\n", "output": "1 3 4 2\n1\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://atcoder.jp/contests/abc110/tasks/abc110_b
Solve the following coding problem using the programming language python: Our world is one-dimensional, and ruled by two empires called Empire A and Empire B. The capital of Empire A is located at coordinate X, and that of Empire B is located at coordinate Y. One day, Empire A becomes inclined to put the cities at coo...
```python (n, m, x, y) = map(int, input().split()) xm = list(map(int, input().split())) ym = list(map(int, input().split())) print('No War' if max([x] + xm) < min([y] + ym) else 'War') ```
vfc_144627
{ "difficulty": "easy", "memory_limit": "1024.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://atcoder.jp/contests/abc110/tasks/abc110_b", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 2 10 20\n8 15 13\n16 22\n", "output": "No War\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 2 -48 -1\n-20 -35 -91 -23\n-22 66\n", "output": "War\n", "type": "stdin_stdout...
taco
verifiable_code
https://codeforces.com/problemset/problem/1256/C
Solve the following coding problem using the programming language python: There is a river of width $n$. The left bank of the river is cell $0$ and the right bank is cell $n + 1$ (more formally, the river can be represented as a sequence of $n + 2$ cells numbered from $0$ to $n + 1$). There are also $m$ wooden platfor...
```python import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = 'x' in file.mode or 'r' not in file.mode self.write = self.buffer.write if self.writable else None def ...
vfc_144631
{ "difficulty": "medium_hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1256/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7 3 2\n1 2 1\n", "output": "YES\n0 1 0 2 2 0 3 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10 1 11\n1\n", "output": "YES\n0 0 0 0 0 0 0 0 0 1 \n", "type": "stdin_stdout" ...
taco
verifiable_code
Solve the following coding problem using the programming language python: Consider placing N flags on a line. Flags are numbered through 1 to N. Flag i can be placed on the coordinate X_i or Y_i. For any two different flags, the distance between them should be at least D. Decide whether it is possible to place all N...
```python class Two_SAT: def __init__(self, variable=[]): self.variable = set(variable) self.clause_number = 0 self.variable_number = len(variable) self.adjacent_out = {(v, b): set() for v in variable for b in [True, False]} self.adjacent_in = {(v, b): set() for v in variable for b in [True, False]} def a...
vfc_144635
{ "difficulty": "unknown_difficulty", "memory_limit": "1024.0 megabytes", "memory_limit_bytes": null, "problem_url": null, "time_limit": "5.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 3\n1 4\n2 5\n0 10", "output": "Yes\n1\n5\n10\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 2\n1 5\n2 5\n0 6", "output": "Yes\n5\n2\n0\n", "type": "stdin_stdout" }, ...
taco
verifiable_code
https://codeforces.com/problemset/problem/1089/G
Solve the following coding problem using the programming language python: Berland State University invites people from all over the world as guest students. You can come to the capital of Berland and study with the best teachers in the country. Berland State University works every day of the week, but classes for gue...
```python def solve(k, a): w = sum(a) ans = float('inf') if k <= w: for start in range(7): for end in range(start, 8): if sum(a[start:end]) >= k: ans = min(ans, end - start) for start in range(7): for end in range(7): x = sum(a[start:]) y = sum(a[:end + 1]) z = k - x - y if z >= 0 and z ...
vfc_144639
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1089/G", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n2\n0 1 0 0 0 0 0\n100000000\n1 0 0 0 1 0 1\n1\n1 0 0 0 0 0 0\n", "output": "8\n233333332\n1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n13131313\n1 0 1 0 1 1 1\n", "output"...
taco
verifiable_code
https://codeforces.com/problemset/problem/1550/A
Solve the following coding problem using the programming language python: Let's call an array $a$ consisting of $n$ positive (greater than $0$) integers beautiful if the following condition is held for every $i$ from $1$ to $n$: either $a_i = 1$, or at least one of the numbers $a_i - 1$ and $a_i - 2$ exists in the arr...
```python import math for _ in range(int(input())): n = int(input()) if n == 1: print(1) else: x = int(math.sqrt(n)) if x ** 2 == n: print(x) else: print(x + 1) ```
vfc_144643
{ "difficulty": "easy", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1550/A", "time_limit": "1 second" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n1\n8\n7\n42\n", "output": "1\n3\n3\n7\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n1\n12\n7\n42\n", "output": "1\n4\n3\n7\n", "type": "stdin_stdout" }, { ...
taco
verifiable_code
https://codeforces.com/problemset/problem/1227/B
Solve the following coding problem using the programming language python: Permutation $p$ is a sequence of integers $p=[p_1, p_2, \dots, p_n]$, consisting of $n$ distinct (unique) positive integers between $1$ and $n$, inclusive. For example, the following sequences are permutations: $[3, 4, 1, 2]$, $[1]$, $[1, 2]$. T...
```python def test(a): se = set() se.add(a[0]) ans = [a[0]] l = 1 for i in range(1, len(a)): if a[i] == a[i - 1]: while l in se: l += 1 ans.append(l) se.add(l) else: ans.append(a[i]) se.add(a[i]) if ans[i] > a[i]: print(-1) return f = False if len(set(ans)) == n: print(' '.join(m...
vfc_144647
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1227/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n5\n1 3 4 5 5\n4\n1 1 3 4\n2\n2 2\n1\n1\n", "output": "1 3 4 5 2 \n-1\n2 1 \n1 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n5\n2 3 4 5 5\n4\n1 1 3 4\n2\n2 2\n1\n1\n", "outpu...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/set-the-rightmost-unset-bit4436/1
Solve the following coding problem using the programming language python: Given a non-negative number N. The problem is to set the rightmost unset bit in the binary representation of N. If there are no unset bits, then just leave the number as it is. Example 1: Input: N = 6 Output: 7 Explanation: The binary representa...
```python class Solution: def setBit(self, N): if N & N + 1: return N | N + 1 return N ```
vfc_144651
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/set-the-rightmost-unset-bit4436/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 6", "output": "7", "type": "stdin_stdout" }, { "fn_name": null, "input": "N = 15", "output": "15", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: Given an array A. Delete an single element from the array such that sum of the differences of adjacent elements should be minimum. For more clarification Sum for an array A having N element is defined as : abs( A[0] - A[1] ) + abs( A[1] - ...
```python for tc in range(eval(input())): n = eval(input()) a = list(map(int,input().split())) k=ans=0 if n < 3: ans=0 else: t=abs(a[0]-a[1]) k=t for i in range(1,n-1): t = abs(abs(a[i-1]-a[i]) + abs(a[i]-a[i+1]) - abs(a[i-1]-a[i+1])) if t>k: k=t ans = i if n > 2 and abs(a[n-1]-a[n-2]) > k: ...
vfc_144652
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n1\n100\n2\n100 1\n2\n1 2\n3\n1 100 2\n3\n1 2 3\n3\n1 5 6\n3\n1 7 8\n3\n8 7 1\n3\n7 8 1\n3\n7 1 8", "output": "0\n0\n0\n1\n0", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n4\n10 20 80 ...
taco
verifiable_code
https://www.codechef.com/problems/SEATSTR2
Solve the following coding problem using the programming language python: Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Sereja has a string A consisting of n lower case English letters. Sereja calls two strings X and Y each of length n similar if they can be made equal by applying t...
```python md = 10 ** 9 + 7 fact = [] prod = 1 for x in range(1, 100002): fact.append(prod) prod *= x prod %= md for _ in range(int(input())): s = input() counts = [s.count(x) for x in set(s)] sym4 = 0 sym3 = 0 sym2 = 0 sym1 = 0 sym1choose2 = 0 sym2choose2 = 0 sym1cchoose2 = 0 sym1c2choose2 = 0 choose_all ...
vfc_144656
{ "difficulty": "hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/SEATSTR2", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\nz\nabcd", "output": "0\n144", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\nz\nabcd", "output": "0\n144", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/UWCOI20C
Solve the following coding problem using the programming language python: Kim has broken in to the base, but after walking in circles, perplexed by the unintelligible base design of the JSA, he has found himself in a large, empty, and pure white, room. The room is a grid with H∗W$H*W$ cells, divided into H$H$ rows an...
```python def solve(l, r, c, row, col, po): count = 0 visited = set() stack = set() stack.add((l[row][col], row, col)) while stack: ele = stack.pop() visited.add((ele[1], ele[2])) if ele[0] < po: count += 1 if ele[1] - 1 >= 0 and (ele[1] - 1, ele[2]) not in visited: if l[ele[1] - 1][ele[2]] < po: ...
vfc_144660
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/UWCOI20C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n5 5 3\n4 3 9 7 2\n8 6 5 2 8\n1 7 3 4 3\n2 2 4 5 6\n9 9 9 9 9\n3 4 6\n3 2 5\n1 4 9\n", "output": "10\n0\n19\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: It’s well know fact among kitties that digits 4 and 7 are lucky digits. Today, N boxes of fish bites arrived. Each box has a unique integer label on it, ranged between 1 and N, inclusive. The boxes are going to be given away to the kitties in in...
```python k = eval(input()) n = eval(input()) i=1 a=0 b=0 cnt=0 while(i<=n): a+=str(i).count('4') b+=str(i).count('7') if(a+b>k): cnt+=1 a=0 b=0 i+=1 print(cnt) ```
vfc_144664
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n7331173", "output": "2305411", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n49503", "output": "6684", "type": "stdin_stdout" }, { "fn_name": null, "inp...
taco
verifiable_code
https://codeforces.com/problemset/problem/1367/A
Solve the following coding problem using the programming language python: Alice guesses the strings that Bob made for her. At first, Bob came up with the secret string $a$ consisting of lowercase English letters. The string $a$ has a length of $2$ or more characters. Then, from string $a$ he builds a new string $b$ a...
```python for _ in range(int(input())): b = list(input()) a = [b[0]] n = len(b) i = 1 while i < n: a.append(b[i]) i += 2 print(*a, sep='') ```
vfc_144669
{ "difficulty": "easy", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1367/A", "time_limit": "2 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\nabbaac\nac\nbccddaaf\nzzzzzzzzzz\n", "output": "abac\nac\nbcdaf\nzzzzzz\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\nassaad\n", "output": "asad\n", "type": "stdin_stdo...
taco
verifiable_code
Solve the following coding problem using the programming language python: Captain Jack loves tables. He wants to know whether you love tables or not. So he asks you to solve the following problem: Given an array A and element m, you have to find the value up to which table of m is present in the array. (example - if t...
```python ''' # Read input from stdin and provide input before running code name = raw_input('What is your name?\n') print 'Hi, %s.' % name ''' #print 'Hello World!' n,m=list(map(int,input().split())) l=[int(i) for i in input().split()] c=0 t=m for i in range(1,len(l)+1): #print i if m in l: c=m #print c m=i*t...
vfc_144673
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "8 3\n2 1 4 5 7 10 11 13", "output": "10", "type": "stdin_stdout" }, { "fn_name": null, "input": "1000 2\n489 428 166 36 252 484 281 341 72 136 111 40 361 251 477 448 179 460 284 303 258 392 279 481 1...
taco
verifiable_code
https://www.codechef.com/problems/TREE3
Solve the following coding problem using the programming language python: Kefaa has developed a novel decomposition of a tree. He claims that this decomposition solves many difficult problems related to trees. However, he doesn't know how to find it quickly, so he asks you to help him. You are given a tree with $N$ ve...
```python def dfs(u, p): l = [u] for v in g[u]: if v != p: r = dfs(v, u) if r == 2: return 2 if r == 1: l.append(v) if len(l) == 4: out.append(l) l = [u] if len(l) == 3: out.append(l + [p]) return len(l) t = int(input()) for _ in range(t): n = int(input()) g = [[] for _ in range...
vfc_144677
{ "difficulty": "very_hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/TREE3", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n4\n1 2\n1 3\n1 4\n7\n1 2\n2 3\n1 4\n4 5\n1 6\n6 7\n", "output": "YES\n1 2 3 4\nNO\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/676/A
Solve the following coding problem using the programming language python: Nicholas has an array a that contains n distinct integers from 1 to n. In other words, Nicholas has a permutation of size n. Nicholas want the minimum element (integer 1) and the maximum element (integer n) to be as far as possible from each ot...
```python N = int(input('')) Line2 = input('') Array = list(map(int, Line2.split(' '))) min_elem_index = Array.index(min(Array)) max_elem_index = Array.index(max(Array)) min_index = 0 max_index = N - 1 L_inv1 = abs(min_elem_index - min_index) R_inv1 = abs(max_index - min_elem_index) ans1 = 0 if L_inv1 >= R_inv1: ans1 ...
vfc_144681
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/676/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n4 5 1 3 2\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "7\n1 6 5 3 4 7 2\n", "output": "6\n", "type": "stdin_stdout" }, { "fn_name": null, ...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/reverse-level-order-traversal/1
Solve the following coding problem using the programming language python: Given a binary tree of size N, find its reverse level order traversal. ie- the traversal must begin from the last level. Example 1: Input : 1 / \ 3 2 Output: 3 2 1 Explanation: Traversing level 1 : 3 2 Traversing level ...
```python def reverseLevelOrder(root): temp1 = [root] result = [] while temp1: temp2 = [] temp3 = [] for i in temp1: temp3.append(i.data) if i.left: temp2.append(i.left) if i.right: temp2.append(i.right) temp1 = temp2 if temp3: result = temp3 + result return result ```
vfc_144685
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/reverse-level-order-traversal/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\r\n / \\\r\n 3 2", "output": "3 2 1", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\r\n / \\\r\n 20 30\r\n / \\ \r\n 40 60", "output": "40 60 20 3...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/sum-triangle-for-given-array1159/1
Solve the following coding problem using the programming language python: Given a array, write a program to construct a triangle where last row contains elements of given array, every element of second last row contains sum of below two elements and so on. Example 1: Input: A[] = {4, 7, 3, 6, 7}; Output: 81 40 41 21 1...
```python def getTriangle(arr, n): s = [[0 for i in range(n)] for j in range(n)] for i in range(n): s[n - 1][i] = arr[i] j = 1 while j < n: k = j for i in range(k, n, 1): s[n - 1 - j][i] = s[n - j][i] + s[n - j][i - 1] j += 1 a = [] i = n - 1 while i > -1: for j in range(i, n, 1): a.append(s[n - ...
vfc_144686
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/sum-triangle-for-given-array1159/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": "getTriangle", "input": "A[] = {4, 7, 3, 6, 7};", "output": "81 40 41 21 19 22 11 10 9 13 4 7 3 6 7", "type": "function_call" }, { "fn_name": "getTriangle", "input": "A[] = {5, 8, 1, 2, 4, 3, 14}", "output": "...
taco
verifiable_code
https://codeforces.com/problemset/problem/1300/C
Solve the following coding problem using the programming language python: Anu has created her own function $f$: $f(x, y) = (x | y) - y$ where $|$ denotes the bitwise OR operation. For example, $f(11, 6) = (11|6) - 6 = 15 - 6 = 9$. It can be proved that for any nonnegative numbers $x$ and $y$ value of $f(x, y)$ is also...
```python n = int(input()) l = list(map(int, input().split())) p = [0] * n temp = ~l[0] for i in range(1, n): p[i] = temp temp &= ~l[i] temp = ~l[-1] ans = [-1, -float('inf')] for i in range(n - 2, -1, -1): if i != 0: p[i] &= temp temp &= ~l[i] p[i] &= l[i] if ans[1] < p[i]: ans[0] = i ans[1] = p[i] e...
vfc_144687
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1300/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n4 0 11 6\n", "output": "11 6 4 0 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n13\n", "output": "13 ", "type": "stdin_stdout" }, { "fn_name": null, "...
taco
verifiable_code
https://codeforces.com/problemset/problem/415/D
Solve the following coding problem using the programming language python: Mashmokh's boss, Bimokh, didn't like Mashmokh. So he fired him. Mashmokh decided to go to university and participate in ACM instead of finding a new job. He wants to become a member of Bamokh's team. In order to join he was given some programmin...
```python import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools sys.setrecursionlimit(10 ** 7) inf = 10 ** 20 eps = 1.0 / 10 ** 10 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), (-1, -1)] def ...
vfc_144691
{ "difficulty": "medium", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/415/D", "time_limit": "1.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2000 2000\n", "output": "585712681", "type": "stdin_stdout" }, { "fn_name": null, "input": "1544 1794\n", "output": "933285446", "type": "stdin_stdout" }, { "fn_name": null,...
taco
verifiable_code
Solve the following coding problem using the programming language python: Have you ever had an infinite loop when you ran a hard-working program? It would be convenient to be able to determine in advance whether a program will stop executing without having to execute it. Unfortunately, it is not possible to make such...
```python def solve(): from sys import stdin f_i = stdin N = int(f_i.readline()) from string import ascii_lowercase next_line = {} S = {} V = {} line = 0 for i in range(N): stmt = f_i.readline().split() next_line[line] = stmt[0] line = stmt[0] op = stmt[1] if op == 'ADD' or op == 'SUB': (v1, v2, v...
vfc_144695
{ "difficulty": "unknown_difficulty", "memory_limit": "268.435456 megabytes", "memory_limit_bytes": null, "problem_url": null, "time_limit": "5.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n111 SET c 1\n12 SUB c c 4\n777 SET a 4", "output": "a=0\nc=1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n10 SET c 1\n193 IF c 10\n20 HALT", "output": "inf\n", "type":...
taco
verifiable_code
https://codeforces.com/problemset/problem/1624/A
Solve the following coding problem using the programming language python: Polycarp got an array of integers $a[1 \dots n]$ as a gift. Now he wants to perform a certain number of operations (possibly zero) so that all elements of the array become the same (that is, to become $a_1=a_2=\dots=a_n$). In one operation, he ...
```python from collections import Counter from math import ceil, floor, log, gcd import bisect as bs import sys input = sys.stdin.readline inp_lis = lambda : list(map(int, input().split())) inp_multi = lambda : map(int, input().split()) inp_int = lambda : int(input().strip()) for _ in range(int(input().strip())): n = ...
vfc_144699
{ "difficulty": "easy", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1624/A", "time_limit": "2 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n6\n3 4 2 4 1 2\n3\n1000 1002 998\n2\n12 11\n", "output": "3\n4\n1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n31\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n"...
taco
verifiable_code
https://codeforces.com/problemset/problem/1331/B
Solve the following coding problem using the programming language python: There was once young lass called Mary, Whose jokes were occasionally scary. On this April's Fool Fixed limerick rules Allowed her to trip the unwary. Can she fill all the lines To work at all times? On juggling the words Right ...
```python z = int(input()) a = 2 while z / a != z // a: a += 1 stri = '' if a < z // a: stri += f'{a}' stri += f'{z // a}' else: stri += f'{z // a}' stri += f'{a}' print(stri) ```
vfc_144703
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1331/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "35\n", "output": "", "type": "stdin_stdout" }, { "fn_name": null, "input": "57\n", "output": "", "type": "stdin_stdout" }, { "fn_name": null, "input": "391\n", "...
taco
verifiable_code
https://codeforces.com/problemset/problem/1195/C
Solve the following coding problem using the programming language python: Finally, a basketball court has been opened in SIS, so Demid has decided to hold a basketball exercise session. $2 \cdot n$ students have come to Demid's exercise session, and he lined up them into two rows of the same size (there are exactly $n...
```python n = int(input()) L1 = list(map(int, input().split())) L2 = list(map(int, input().split())) (a0, b0) = (0, 0) (a1, b1) = (L1[-1], L2[-1]) for k in range(2, n + 1): a = L1[-k] + max(b0, b1) b = L2[-k] + max(a0, a1) (a1, a0) = (a, a1) (b1, b0) = (b, b1) print(max(a1, b1)) ```
vfc_144707
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1195/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n9 3 5 7 3\n5 8 1 4 5\n", "output": "29\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n1 2 9\n10 1 1\n", "output": "19\n", "type": "stdin_stdout" }, { "fn_n...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/brothers-from-different-root/1
Solve the following coding problem using the programming language python: Given two BSTs containing N1 and N2 distinct nodes respectively and given a value x. Your task is to complete the function countPairs(), that returns the count of all pairs from both the BSTs whose sum is equal to x. Example 1: Input: BST1: ...
```python class Solution: def inorder(self, root): ans = [] curr = root while curr: if curr.left is None: ans.append(curr.data) curr = curr.right else: pred = curr.left while pred.right and pred.right != curr: pred = pred.right if pred.right is None: pred.right = curr cu...
vfc_144711
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/brothers-from-different-root/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "BST1:\n 5\n / \\\n 3 7\n / \\ / \\\n 2 4 6 8\n\nBST2:\n 10\n / \\\n 6 15\n / \\ / \\\n 3 8 11 18\n\nx = 16", "output": "3", "type": "stdin_stdout" }, ...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/sort-in-specific-order2422/1
Solve the following coding problem using the programming language python: Given an array A of positive integers. Your task is to sort them in such a way that the first part of the array contains odd numbers sorted in descending order, rest portion contains even numbers sorted in ascending order. Example 1: Input: N ...
```python class Solution: def sortIt(self, arr, n): list1 = list() list2 = list() for i in arr: if i % 2 == 0: list1.append(i) else: list2.append(i) list2.sort(reverse=True) list1.sort() arr[:] = list2 + list1 return arr ```
vfc_144712
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/sort-in-specific-order2422/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 7\r\nArr = {1, 2, 3, 5, 4, 7, 10}", "output": "7 5 3 1 2 4 10", "type": "stdin_stdout" }, { "fn_name": null, "input": "N = 7\r\nArr = {0, 4, 5, 3, 7, 2, 1}", "output": "7 5 3 1 0 2 4", ...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/pasha-and-primes0438/1
Solve the following coding problem using the programming language python: Given an array of N integers and another array R containing Q queries(of l and r). Answer all Q queries asking the number of primes in the subarray ranging from l to r (both inclusive). Note: A is 0-based but the queries will be 1-based. Example...
```python class Solution: def primeRange(self, N, Q, A, R): n = max(A) sieve = [True] * (n + 1) sieve[0] = sieve[1] = False for i in range(2, int(n ** 0.5) + 1): if sieve[i]: for j in range(i * i, n + 1, i): sieve[j] = False tree = [0] * (n + 1) def add(pos, val): while pos <= n: tree[...
vfc_144713
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/pasha-and-primes0438/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N=5,Q=3\nA={2,5,6,7,8}\nR={{1,3},{2,5},{3,3}}", "output": "2 2 0", "type": "stdin_stdout" }, { "fn_name": null, "input": "N=5,Q=3\nA={1,2,3,4,5}\nR={{1,4},{2,5},{2,3}}", "output": "2 3 2", ...
taco
verifiable_code
https://codeforces.com/problemset/problem/1790/C
Solve the following coding problem using the programming language python: A sequence of $n$ numbers is called permutation if it contains all integers from $1$ to $n$ exactly once. For example, the sequences [$3, 1, 4, 2$], [$1$] and [$2,1$] are permutations, but [$1,2,1$], [$0,1$] and [$1,3,4$] — are not. Kristina ha...
```python from sys import stdin input = stdin.readline t = int(input()) for _ in range(t): n = int(input()) perms = [] for _ in range(n): perms.append(list(input().split())) start = None if perms[0][0] == perms[1][0] or perms[0][0] == perms[2][0]: start = perms[0][0] else: start = perms[1][0] for perm in p...
vfc_144714
{ "difficulty": "easy", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1790/C", "time_limit": "3 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n4\n4 2 1\n4 2 3\n2 1 3\n4 1 3\n3\n2 3\n1 3\n1 2\n5\n4 2 1 3\n2 1 3 5\n4 2 3 5\n4 1 3 5\n4 2 1 5\n4\n2 3 4\n1 3 4\n1 2 3\n1 2 4\n3\n2 1\n1 3\n2 3\n", "output": "4 2 1 3 \n1 2 3 \n4 2 1 3 5 \n1 2 3 4 \n2 1 3 \n", "type...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/longest-substring-containing-1/1
Solve the following coding problem using the programming language python: Given a function that takes a binary string. The task is to return the longest size of contiguous substring containing only ‘1’. Input: The first line of input contains an integer T denoting the no of test cases.Then T test cases follow. Each te...
```python def maxlength(s): c = 0 l = [] for i in s: if i == '1': c += 1 else: l.append(c) c = 0 l.append(c) return max(l) ```
vfc_144718
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/longest-substring-containing-1/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": "maxlength", "input": "2\r\n\r\n110\r\n\r\n11101110", "output": "2\r\n3", "type": "function_call" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/924/A
Solve the following coding problem using the programming language python: There is a rectangular grid of n rows of m initially-white cells each. Arkady performed a certain number (possibly zero) of operations on it. In the i-th operation, a non-empty subset of rows R_{i} and a non-empty subset of columns C_{i} are ch...
```python def main(): (n, m) = list(map(int, input().split())) (aa, bb) = ([{i for (i, c) in enumerate(input()) if c == '#'} for _ in range(n)], []) for a in aa: if a: for b in bb: c = a & b if c and a != b: print('No') return bb.append(a) print('Yes') def __starting_point(): main() __st...
vfc_144719
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/924/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 8\n.#.#..#.\n.....#..\n.#.#..#.\n#.#....#\n.....#..\n", "output": "Yes\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 5\n..#..\n..#..\n#####\n..#..\n..#..\n", "output": "No\n", ...
taco
verifiable_code
Solve the following coding problem using the programming language python: Takahashi is standing on a two-dimensional plane, facing north. Find the minimum positive integer K such that Takahashi will be at the starting position again after he does the following action K times: * Go one meter in the direction he is fac...
```python from math import gcd X = int(input()) g = gcd(X, 360) print(360 // g) ```
vfc_144723
{ "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": "155", "output": "72\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2", "output": "180\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "297", ...
taco
verifiable_code
https://codeforces.com/problemset/problem/1159/E
Solve the following coding problem using the programming language python: Vasya has written some permutation p_1, p_2, …, p_n of integers from 1 to n, so for all 1 ≤ i ≤ n it is true that 1 ≤ p_i ≤ n and all p_1, p_2, …, p_n are different. After that he wrote n numbers next_1, next_2, …, next_n. The number next_i is e...
```python import sys from array import array from typing import List, Tuple, TypeVar, Generic, Sequence, Union def input(): return sys.stdin.buffer.readline().decode('utf-8') def main(): t = int(input()) ans = ['-1'] * t for ti in range(t): n = int(input()) a = [0] + list(map(int, input().split())) p = [0] ...
vfc_144728
{ "difficulty": "hard", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1159/E", "time_limit": "1.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n3\n2 3 4\n2\n3 3\n3\n-1 -1 -1\n3\n3 4 -1\n1\n2\n4\n4 -1 4 5\n", "output": "1 2 3\n2 1\n1 2 3\n-1\n1\n3 1 2 4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n4\n2 4 4 5\n4\n2 -1 4 -1...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/are-you-perfect4926/1
Solve the following coding problem using the programming language python: Given a number N. Find out the nearest number which is a perfect square and also the absolute difference between them. Example 1: Input: N = 25 Output: 25 0 Explanation: Since 25 is a perfect square, it is the closest perfect square to itself a...
```python class Solution: def nearestPerfectSquare(self, N): import math b = int(math.sqrt(N)) s1 = b ** 2 s2 = (b + 1) ** 2 d1 = N - s1 d2 = s2 - N if d1 < d2: return (s1, d1) return (s2, d2) ```
vfc_144733
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/are-you-perfect4926/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 25", "output": "25 0", "type": "stdin_stdout" }, { "fn_name": null, "input": "N = 1500", "output": "1521 21", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: Number of tanka Wishing to die in the spring under the flowers This is one of the famous tanka poems that Saigyo Hoshi wrote. Tanka is a type of waka poem that has been popular in Japan for a long time, and most of it consists of five phrases ...
```python def solve(N): k = 0 rng = 0 for i in range(54): if cl[i] < N <= cl[i + 1]: k = i + 2 rng2 = cl[i] rng = cl[i + 1] - cl[i] posrng = (N - rng2) % (rng // 9) perrng = (N - rng2) // (rng // 9) + 1 if posrng == 0: posrng = rng // 9 perrng -= 1 ans = [perrng] for i in range(k - 1): if i == ...
vfc_144734
{ "difficulty": "unknown_difficulty", "memory_limit": "268.435456 megabytes", "memory_limit_bytes": null, "problem_url": null, "time_limit": "8.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n2\n3\n390\n216\n1546\n314159265358979323\n0", "output": "10\n12\n13\n2020\n599\n57577\n7744444777744474777777774774744777747477444774744744\n", "type": "stdin_stdout" }, { "fn_name": null, "input"...
taco
verifiable_code
https://codeforces.com/problemset/problem/337/D
Solve the following coding problem using the programming language python: Paladin Manao caught the trail of the ancient Book of Evil in a swampy area. This area contains n settlements numbered from 1 to n. Moving through the swamp is very difficult, so people tramped exactly n - 1 paths. Each of these paths connects s...
```python import collections class Graph: def __init__(self, n, dir): self.node_cnt = n self.__directed = dir self.__adjList = [] for i in range(n): self.__adjList.append([]) def addEdge(self, u, v): self.__adjList[u].append(v) if not self.__directed: self.__adjList[v].append(u) def getDistance...
vfc_144739
{ "difficulty": "hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/337/D", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6 2 3\n1 2\n1 5\n2 3\n3 4\n4 5\n5 6\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 2 1\n2 1\n1 2\n", "output": "2\n", "type": "stdin_stdout" }, { ...
taco
verifiable_code
https://codeforces.com/problemset/problem/1560/C
Solve the following coding problem using the programming language python: Polycarp has found a table having an infinite number of rows and columns. The rows are numbered from $1$, starting from the topmost one. The columns are numbered from $1$, starting from the leftmost one. Initially, the table hasn't been filled ...
```python from __future__ import division, print_function import os import sys from io import BytesIO, IOBase import itertools if sys.version_info[0] < 3: input = raw_input range = xrange filter = itertools.ifilter map = itertools.imap zip = itertools.izip BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def ...
vfc_144743
{ "difficulty": "easy", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1560/C", "time_limit": "1 second" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7\n11\n14\n5\n4\n1\n2\n1000000000\n", "output": "2 4\n4 3\n1 3\n2 1\n1 1\n1 2\n31623 14130\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n77777\n", "output": "279 65\n", "t...
taco
verifiable_code
https://www.hackerrank.com/challenges/countingsort2/problem
Solve the following coding problem using the programming language python: Often, when a list is sorted, the elements being sorted are just keys to other values. For example, if you are sorting files by their size, the sizes need to stay connected to their respective files. You cannot just take the size numbers and out...
```python n = int(input()) ar = [int(x) for x in input().strip().split(' ')] c = [0] * 100 for a in ar: c[a] += 1 s = '' for x in range(0, 100): for i in range(0, c[x]): s += ' ' + str(x) print(s[1:]) ```
vfc_144747
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.hackerrank.com/challenges/countingsort2/problem", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "100\n63 25 73 1 98 73 56 84 86 57 16 83 8 25 81 56 9 53 98 67 99 12 83 89 80 91 39 86 76 85 74 39 25 90 59 10 94 32 44 3 89 30 27 79 46 96 27 32 18 21 92 69 81 40 40 34 68 78 24 87 42 69 23 41 78 22 6 90 99 89 50 30 20 1 43 3 70 95...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/save-knights2718/1
Solve the following coding problem using the programming language python: How many non-attacking knights K(n) can be placed on an n x n chessboard. Recall that a knight can attack another knight if their vertical distance on the chessboard is 2 and their horizontal distance is 1, or if their vertical distance is 1 an...
```python import math class Solution: def saveKnights(self, n): if n == 2: return 4 elif n % 2 == 0: return int(math.pow(n, 2) / 2) else: return int((math.pow(n, 2) + 1) / 2) ```
vfc_144752
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/save-knights2718/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "n = 3", "output": "5", "type": "stdin_stdout" }, { "fn_name": null, "input": "n = 1", "output": "1", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/259/A
Solve the following coding problem using the programming language python: The Little Elephant loves chess very much. One day the Little Elephant and his friend decided to play chess. They've got the chess pieces but the board is a problem. They've got an 8 × 8 checkered board, each square is painted either black or ...
```python n = 8 s = '' for i in range(n): s += input() + ',' if s.count('WBWBWBWB') + s.count('BWBWBWBW') != 8: print('NO') else: print('YES') ```
vfc_144753
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/259/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "WBWBWBWB\nBWBWBWBW\nBWBWBWBW\nBWBWBWBW\nWBWBWBWB\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "WBWBWBWB\nWBWBWBWB\nBBWBWWWB\nBWBWBWBW\nBW...
taco
verifiable_code
https://codeforces.com/problemset/problem/610/C
Solve the following coding problem using the programming language python: The semester is already ending, so Danil made an effort and decided to visit a lesson on harmony analysis to know how does the professor look like, at least. Danil was very bored on this lesson until the teacher gave the group a simple task: fin...
```python a = [1, -1] b = [1, 1] X = [a, b] cur = 1 k = int(input()) def pr(X): for v in X: print(''.join(['*' if x == -1 else '+' for x in v])) def get_xor(v): return [-1 * x for x in v] def build(X): ans = [] n = len(X) for i in range(0, n, 2): ans.extend([X[i] + X[i + 1], X[i + 1] + X[i], get_xor(X[i]) +...
vfc_144757
{ "difficulty": "medium_hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/610/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n", "output": "++++\n+*+*\n++**\n+**+\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n", "output": "++\n+*\n", "type": "stdin_stdout" }, { "fn_name": null, ...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/longest-common-prefix-in-an-array5129/1
Solve the following coding problem using the programming language python: Given an array of N strings, find the longest common prefix among all strings present in the array. Example 1: Input: N = 4 arr[] = {geeksforgeeks, geeks, geek, geezer} Output: gee Explanation: "gee" is the longest common prefix in all ...
```python class Solution: def longestCommonPrefix(self, arr, n): arr.sort() min_len = min(len(arr[0]), len(arr[n - 1])) ans = '' for i in range(min_len): if arr[0][i] == arr[n - 1][i]: ans += arr[0][i] else: break return ans if len(ans) > 0 else -1 ```
vfc_144762
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/longest-common-prefix-in-an-array5129/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 4\narr[] = {geeksforgeeks, geeks, geek,\n geezer}", "output": "gee", "type": "stdin_stdout" }, { "fn_name": null, "input": "N = 2\narr[] = {hello, world}", "output": "-1", "ty...
taco
verifiable_code
Solve the following coding problem using the programming language python: Little Jhool always wanted to have some psychic powers so that he could showoff his skills, and magic to people and impress them. (Specially, his girlfriend Big Jhool!) But, in spite all his efforts, hardwork, dedication, Googling, watching yout...
```python n=input() c=0 for i in range (1,len(n)): if n[i]==n[i-1]: c=c+1 else: c=0 if c==5: break if c==5: print("Sorry, sorry!") else: print("Good luck!") ```
vfc_144763
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "11111111111111\n", "output": "Sorry, sorry!\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "0\n", "output": "Sorry, sorry!\n", "type": "stdin_stdout" }, { "fn_nam...
taco
verifiable_code
https://codeforces.com/problemset/problem/750/C
Solve the following coding problem using the programming language python: Every Codeforces user has rating, described with one integer, possibly negative or zero. Users are divided into two divisions. The first division is for users with rating 1900 or higher. Those with rating 1899 or lower belong to the second divis...
```python s = 0 a = b = '' for i in range(int(input())): (c, d) = map(int, input().split()) if d == 1: a = min(a, s) if a != '' else s else: b = max(b, s) if b != '' else s s += c print('Infinity' if b == '' else 'Impossible' if a != '' and a - b < 1 else 1899 - b + s) ```
vfc_144767
{ "difficulty": "medium_hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/750/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n-7 1\n5 2\n8 2\n", "output": "1907\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n57 1\n22 2\n", "output": "Impossible\n", "type": "stdin_stdout" }, { "fn_...
taco
verifiable_code
https://codeforces.com/problemset/problem/16/C
Solve the following coding problem using the programming language python: Reca company makes monitors, the most popular of their models is AB999 with the screen size a × b centimeters. Because of some production peculiarities a screen parameters are integer numbers. Recently the screen sides ratio x: y became popular ...
```python import os import sys from math import * from collections import * from bisect import * from io import BytesIO, IOBase def vsInput(): sys.stdin = open('input.txt', 'r') sys.stdout = open('output.txt', 'w') BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.file...
vfc_144771
{ "difficulty": "medium_hard", "memory_limit": "64.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/16/C", "time_limit": "0.5 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2000000000 2000000000 1999999998 1999999999\n", "output": "1999999998 1999999999", "type": "stdin_stdout" }, { "fn_name": null, "input": "721746595 799202881 143676564 380427290\n", "output": "...
taco
verifiable_code
https://codeforces.com/problemset/problem/1284/C
Solve the following coding problem using the programming language python: Recall that the permutation is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $[2,3,1,5,4]$ is a permutation, but $[1,2,2]$ is not a permutation ($2$ appears twice in the array) and $[1,3,4]$ is als...
```python (n, m) = map(int, input().split()) fac = [1] for i in range(1, n + 1): fac.append(i * fac[i - 1] % m) ans = 0 for i in range(1, n + 1): ans += (n - i + 1) * fac[i] * fac[n - i + 1] ans %= m print(ans) ```
vfc_144775
{ "difficulty": "medium_hard", "memory_limit": "1024 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1284/C", "time_limit": "1 second" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 993244853\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 993244853\n", "output": "6\n", "type": "stdin_stdout" }, { "fn_name": null, "...
taco
verifiable_code
https://codeforces.com/problemset/problem/1184/C2
Solve the following coding problem using the programming language python: The Cybermen solved that first test much quicker than the Daleks. Luckily for us, the Daleks were angry (shocking!) and they destroyed some of the Cybermen. After the fighting stopped, Heidi gave them another task to waste their time on. There...
```python import sys NORM = 2000000 LIMIT = NORM * 2 + 1 class segmentTree: def __init__(self, n): self.n = n self.t = [0] * (n * 2) self.lazy = [0] * n def apply(self, p, value): self.t[p] += value if p < self.n: self.lazy[p] += value def build(self, p): while p > 1: p >>= 1 self.t[p] = max...
vfc_144779
{ "difficulty": "hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1184/C2", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 1\n1 1\n1 -1\n-1 1\n-1 -1\n2 0\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 2\n1 1\n1 -1\n-1 1\n-1 -1\n2 0\n", "output": "5\n", "type": "stdin_stdout" ...
taco
verifiable_code
https://codeforces.com/problemset/problem/69/E
Solve the following coding problem using the programming language python: Programmer Sasha has recently begun to study data structures. His coach Stas told him to solve the problem of finding a minimum on the segment of the array in <image>, which Sasha coped with. For Sasha not to think that he had learned all, Stas ...
```python from typing import TypeVar, Generic, Callable, List import sys from array import array from collections import Counter def input(): return sys.stdin.buffer.readline().decode('utf-8') minf = -10 ** 9 - 100 T = TypeVar('T') class SegmentTree(Generic[T]): __slots__ = ['size', 'tree', 'identity', 'op', 'updat...
vfc_144783
{ "difficulty": "medium_hard", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/69/E", "time_limit": "1.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10 3\n-55\n-35\n-80\n91\n-96\n-93\n-39\n-77\n4\n29\n", "output": "-35\n91\n91\n91\n-39\n-39\n4\n29\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10 3\n-6\n2\n79\n-49\n86\n13\n-31\n-71\n5...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/elements-before-which-no-element-is-bigger0602/1
Solve the following coding problem using the programming language python: You are given an array A of size N. The task is to find count of elements before which all the elements are smaller. First element is always counted as there is no other element before it. Example 1: Input : arr[] = {10, 40, 23, 35, 50, 7} O...
```python class Solution: def countElements(self, arr, n): cnt = 1 m = arr[0] for i in range(1, n): if m < arr[i]: m = arr[i] cnt += 1 return cnt ```
vfc_144788
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/elements-before-which-no-element-is-bigger0602/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "arr[] = {10, 40, 23, 35, 50, 7}", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "arr[] = {5, 4, 1}", "output": "1", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: Implement the recursive function given by the following rules and print the last 3 digits: F(x, y) = { y + 1 when x = 0, F(x - 1, 1) when x > 0 and y = 0, F(x - 1, F(x, y - 1)) when x > 0 and y > 0 } Input Format A single line containi...
```python def solve(x, y): if x == 0: return (y + 1) % 1000 if x == 1: return (y + 2) % 1000 if x == 2: return (2 * y + 3) % 1000 if x == 3: r = 5 add = 8 for i in range(y): r = (add + r) % 1000 add = (add * 2) % 1000 return r if x == 4 and y == 0: return 13 if (x == 4 and y == 1) or (x == 5...
vfc_144789
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 2", "output": "533", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 100", "output": "003", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 1", ...
taco
verifiable_code
Solve the following coding problem using the programming language python: Division of Big Integers Given two integers $A$ and $B$, compute the quotient, $\frac{A}{B}$. Round down to the nearest decimal. Input Two integers $A$ and $B$ separated by a space character are given in a line. Output Print the quotient in...
```python (a, b) = map(int, input().split()) if a * b < 0: print(abs(a) // abs(b) * -1) else: print(abs(a) // abs(b)) ```
vfc_144793
{ "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 16", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "9 6", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "18 6", ...
taco
verifiable_code
https://codeforces.com/problemset/problem/355/C
Solve the following coding problem using the programming language python: Vasya has n items lying in a line. The items are consecutively numbered by numbers from 1 to n in such a way that the leftmost item has number 1, the rightmost item has number n. Each item has a weight, the i-th item weights wi kilograms. Vasya...
```python path = list(map(int, input().split())) (n, L, R, QL, QR) = (path[0], path[1], path[2], path[3], path[4]) w = list(map(int, input().split())) sumpref = [0] for i in range(1, n + 1): sumpref.append(w[i - 1] + sumpref[i - 1]) answer = QR * (n - 1) + sumpref[n] * R for i in range(1, n + 1): energy = L * sumpref...
vfc_144797
{ "difficulty": "medium", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/355/C", "time_limit": "1.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 1 100 10000 1\n1 2 3 4 5\n", "output": "906\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 78 94 369 10000\n93\n", "output": "7254\n", "type": "stdin_stdout" }, { ...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/filling-bucket0529/1
Solve the following coding problem using the programming language python: Given a Bucket having a capacity of N litres and the task is to determine that by how many ways you can fill it using two bottles of capacity of 1 Litre and 2 Litre only. Find the answer modulo 10^{8}. Example 1: Input: 3 Output: 3 Explanation:...
```python class Solution: def fillingBucket(self, N): a = 1 b = 2 if N <= 2: return N for i in range(3, N + 1): c = a + b % 10 ** 8 a = b b = c return c % 10 ** 8 ```
vfc_144802
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/filling-bucket0529/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "4", "output": "5", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: Rng is going to a festival. The name of the festival is given to you as a string S, which ends with `FESTIVAL`, from input. Answer the question: "Rng is going to a festival of what?" Output the answer. Here, assume that the name of "a festival...
```python S = input() s_len = len(S) ans = S[:s_len - 8] print(ans) ```
vfc_144804
{ "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": "YAKINIJUFESTIVAL", "output": "YAKINIJU\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "CODEFESTIVALFERTIVAL", "output": "CODEFESTIVAL\n", "type": "stdin_stdout" }, { ...