source
stringclasses
4 values
task_type
stringclasses
1 value
in_source_id
stringlengths
0
138
problem
stringlengths
219
13.2k
gold_standard_solution
stringlengths
0
413k
problem_id
stringlengths
5
10
metadata
dict
verification_info
dict
taco
verifiable_code
https://www.hackerrank.com/challenges/sam-and-substrings/problem
Solve the following coding problem using the programming language python: Samantha and Sam are playing a numbers game. Given a number as a string, no leading zeros, determine the sum of all integer values of substrings of the string. Given an integer as a string, sum all of its substrings cast as integers. As th...
```python import operator MOD = 1000000007 s = input() n = len(s) a = [] p10 = 0 for i in range(n, 0, -1): p10 = (p10 * 10 + 1) % MOD a.append(p10 * i % MOD) b = [ord(c) - ord('0') for c in s] print(sum(map(operator.mul, reversed(a), b)) % MOD) ```
vfc_137827
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.hackerrank.com/challenges/sam-and-substrings/problem", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "16\n", "output": "23\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "123\n", "output": "164\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/XYPIZQ
Solve the following coding problem using the programming language python: Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. ChefX showed ChefY his new pizza slice design. The design is a planar figure that can be drawn in the following way: Draw a point $\mathsf{A...
```python import math t = int(input()) for i in range(t): a = [int(x) for x in input().split()] n = a[0] op = a[1] x = a[2] y = a[3] z = a[4] n1 = n * 2 + 1 if op == 1: if x < y and y < z: m = n1 - z elif x > y and y > z: m = n1 - z else: m = x elif op == 2: m = n1 - (z + x) elif op == 3: i...
vfc_137831
{ "difficulty": "hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/XYPIZQ", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n175456798 1 151163203 151163204 151163205", "output": "66583464 116971199", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/335/F
Solve the following coding problem using the programming language python: A nearby pie shop is having a special sale. For each pie you pay full price for, you may select one pie of a strictly lesser value to get for free. Given the prices of all the pies you wish to acquire, determine the minimum total amount you must...
```python h = [i for i in range(500001)] t = [i for i in range(500001)] ans = 0 len = 0 nw = 0 tot = 0 cnt = 0 a = [] def work(x): y = x >> 1 while y and h[y] > h[x]: tmp = h[x] h[x] = h[y] h[y] = tmp x = y y = x >> 1 def pop(): global len h[1] = h[len] len -= 1 x = 1 y = 2 if y < len and h[y + 1] <...
vfc_137835
{ "difficulty": "very_hard", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/335/F", "time_limit": "5.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "30\n3 6 3 8 6 4 4 2 4 10 8 5 9 6 7 7 9 4 7 4 10 1 9 10 4 7 7 4 2 3\n", "output": "96\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n1\n", "output": "1\n", "type": "stdin_st...
taco
verifiable_code
https://codeforces.com/problemset/problem/1213/E
Solve the following coding problem using the programming language python: You are given two strings $s$ and $t$ both of length $2$ and both consisting only of characters 'a', 'b' and 'c'. Possible examples of strings $s$ and $t$: "ab", "ca", "bb". You have to find a string $res$ consisting of $3n$ characters, $n$ ch...
```python n = int(input()) l = ['abc' * n, 'acb' * n, 'bca' * n, 'cab' * n, 'bca' * n, 'cba' * n, 'b' * n + 'c' * n + 'a' * n, 'a' * n + 'b' * n + 'c' * n, 'c' * n + 'a' * n + 'b' * n] a = input() b = input() print('YES') for i in l: if a not in i and b not in i: print(i) break ```
vfc_137839
{ "difficulty": "hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1213/E", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\nab\nbc\n", "output": "YES\nacbacb\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\naa\nbc\n", "output": "YES\nacbacbacb\n", "type": "stdin_stdout" }, { "fn_n...
taco
verifiable_code
https://codeforces.com/problemset/problem/384/A
Solve the following coding problem using the programming language python: Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (x, y), he can move to (or attack) positions (x...
```python n = int(input()) print(n % 2 + n * n // 2) for i in range(n): if i % 2: print(''.join(('C' if j % 2 else '.' for j in range(n)))) else: print(''.join(('.' if j % 2 else 'C' for j in range(n)))) ```
vfc_137844
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/384/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n", "output": "2\nC.\n.C\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/TWOTRAINS
Solve the following coding problem using the programming language python: There are 2 trains A and B and N stations in a line from 1 to N in order. There is also an array P of length N-1 such that P_{i} (1≤ i < N) denotes the amount of time any train takes to go from the i-th station to the (i+1)-th station. Initial...
```python for _ in range(int(input())): n = int(input()) p = list(map(int, input().split())) x = p[0] y = 2 * x for i in range(1, n - 1): x += p[i] if y < x: y += x - y + p[i] else: y += p[i] print(y) ```
vfc_137848
{ "difficulty": "easy", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/TWOTRAINS", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n2\n4\n3\n3 5\n4\n5 2 6\n", "output": "8\n13\n19\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1728/A
Solve the following coding problem using the programming language python: The title is a reference to the very first Educational Round from our writers team, Educational Round 18. There is a bag, containing colored balls. There are $n$ different colors of balls, numbered from $1$ to $n$. There are $\mathit{cnt}_i$ ba...
```python for _ in range(int(input())): x = int(input()) l = list(map(int, input().split())) ma = max(l) print(l.index(ma) + 1) ```
vfc_137856
{ "difficulty": "easy", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1728/A", "time_limit": "2 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n3\n1 1 1\n1\n9\n2\n4 7\n", "output": "1\n1\n2\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/find-the-frequency/1
Solve the following coding problem using the programming language python: Given a vector of N positive integers and an integer X. The task is to find the frequency of X in vector. Example 1: Input: N = 5 vector = {1, 1, 1, 1, 1} X = 1 Output: 5 Explanation: Frequency of 1 is 5. Your Task: Your task is to complete ...
```python def findFrequency(arr, n, x): c = 0 for i in arr: if i == x: c += 1 return c ```
vfc_137861
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/find-the-frequency/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": "findFrequency", "input": "N = 5\nvector = {1, 1, 1, 1, 1}\nX = 1", "output": "5", "type": "function_call" } ] }
taco
verifiable_code
https://www.codechef.com/problems/COST_MANIA
Solve the following coding problem using the programming language python: Kiteretsu goes to his Chemistry Lab to perform the perfect reaction. In his lab, he found N reagents numbered 1 to N. The i^{th} reagent has two properties - A_{i} and B_{i}. A reaction can be performed between the reagents i and j only if A_{i...
```python t = int(input()) for _ in range(t): (n, d) = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) mx_heat = None for i in range(n - 1, 0, -1): if mx_heat is not None and i * (i + 1) <= mx_heat: break for j in range(i - 1, -1, -1): if mx_heat is not N...
vfc_137866
{ "difficulty": "very_hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/COST_MANIA", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n5 2\n2 4 5 5 6\n1 3 2 2 5\n2 3\n2 3\n1 2\n", "output": "6\n-7\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1371/C
Solve the following coding problem using the programming language python: Anna is a girl so brave that she is loved by everyone in the city and citizens love her cookies. She is planning to hold a party with cookies. Now she has $a$ vanilla cookies and $b$ chocolate cookies for the party. She invited $n$ guests of th...
```python for _ in range(int(input())): (a, b, n, m) = list(map(int, input().split())) r = min(a, b) s = a + b if n + m > s: print('No') elif r < m: print('No') else: print('Yes') ```
vfc_137870
{ "difficulty": "easy", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1371/C", "time_limit": "1 second" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n2 2 1 2\n0 100 0 1\n12 13 25 1\n27 83 14 25\n0 0 1 0\n1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000\n", "output": "Yes\nNo\nNo\nYes\nNo\nYes\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/DEC15/problems/CHCINEMA
Solve the following coding problem using the programming language python: Probably everyone has experienced an awkward situation due to shared armrests between seats in cinemas. A highly accomplished cinema manager named "Chef" decided to solve this problem. When a customer wants to buy a ticket, the clerk at the tic...
```python for i in range(eval(input())): (n, m, z, l, r, b) = list(map(int, input().split())) rows = n columns = m hand_rest = n * (m + 1) if m % 2 == 0: hand_rest -= max(0, n - l - r) if l + r + 2 * b <= hand_rest: print(min(n * m, l + r + z + b)) else: temp = l + r + (hand_rest - l - r) / 2 print(min(n...
vfc_137874
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/DEC15/problems/CHCINEMA", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n2 2 3 2 1 1\n3 3 1 2 0 9\n", "output": "4\n8\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/667/C
Solve the following coding problem using the programming language python: First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, whic...
```python s = input()[5:][::-1] n = len(s) mu = set() can2 = [0] * (n + 1) can3 = [0] * (n + 1) if n >= 2: mu.add(s[0:2][::-1]) can2[2] = 1 if n >= 3: mu.add(s[0:3][::-1]) can3[3] = 1 if n >= 4 and s[0:2] != s[2:4]: mu.add(s[2:4][::-1]) can2[4] = 1 if n >= 5: mu.add(s[2:5][::-1]) mu.add(s[3:5][::-1]) can2[5] =...
vfc_137879
{ "difficulty": "medium_hard", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/667/C", "time_limit": "1.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "aaaaaxyxxxx\n", "output": "5\nxx\nxxx\nxyx\nyx\nyxx\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "aaaaaxxxxxx\n", "output": "2\nxx\nxxx\n", "type": "stdin_stdout" }, ...
taco
verifiable_code
https://codeforces.com/problemset/problem/1425/D
Solve the following coding problem using the programming language python: Mr. Chanek The Ninja is one day tasked with a mission to handle mad snakes that are attacking a site. Now, Mr. Chanek already arrived at the hills where the destination is right below these hills. The mission area can be divided into a grid of s...
```python import sys input = sys.stdin.readline sys.setrecursionlimit(10 ** 4) from sys import stdin, stdout from collections import defaultdict, Counter from functools import lru_cache M = 10 ** 9 + 7 fact = [1] * 2001 def fac(n): if n == 0 or n == 1: return 1 elif fact[n] != 1: return fact[n] fact[n] = fac(n ...
vfc_137883
{ "difficulty": "hard", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1425/D", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 1 0\n1 1 10\n1 999 30\n1 1000 40\n1 2 20\n", "output": "3000\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1 0\n1 1 10\n", "output": "100\n", "type": "stdin_stdout" }...
taco
verifiable_code
https://www.codechef.com/JUNE09/problems/D7
Solve the following coding problem using the programming language python: The Chef has been kidnapped by aliens ( they want to utilize his excellent cooking skills :P ) and has been transported to the alien planet "ZX532". Interestingly, "ZX532" uses a different time scale which has Y AlienHours on the face of a clock...
```python import decimal from decimal import * def solve(a, b, min1, min2, min3, min4, x, y): if a > b: return [] solMin1 = (a / y + b) / (y - 1 / y) solMin2 = (b / y + a) / (y - 1 / y) solMin1 *= x * y solMin2 *= x * y if solMin1 >= min1 and solMin1 <= min2 and (solMin2 >= min3) and (solMin2 <= min4): retur...
vfc_137887
{ "difficulty": "hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/JUNE09/problems/D7", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n5 12\n1 0 2 0 4 0 5 0\n5 12\n3 30 4 0 5 0 6 0\n5 12\n3 0 4 0 5 0 6 0\n\n\n", "output": "1:20.56\n-1\n3:26.43\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/991/D
Solve the following coding problem using the programming language python: Bishwock is a chess figure that consists of three squares resembling an "L-bar". This figure can be rotated by 90, 180 and 270 degrees so it can have four possible states: XX XX .X X. X. .X XX XX Bishwocks don't attack any s...
```python a = input() b = input() ct = 0 i = 0 while i < len(a): if i + 2 < len(a) and a[i] == '0' and (a[i + 1] == '0') and (a[i + 2] == '0') and (b[i] == '0') and (b[i + 1] == '0') and (b[i + 2] == '0'): ct += 2 i += 2 elif a[i:i + 2].count('0') + b[i:i + 2].count('0') >= 3: ct += 1 i += 1 i += 1 print(ct)...
vfc_137895
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/991/D", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "00\n00\n", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "00X00X0XXX0\n0XXX0X00X00\n", "output": "4", "type": "stdin_stdout" }, { "fn_name": null, ...
taco
verifiable_code
https://www.codechef.com/problems/GOODBINSTR
Solve the following coding problem using the programming language python: You are given a binary string S. A binary string is a string consisting of only 0's and 1's. A binary string is called *good* if it has an equal number of occurrences of \texttt{01} substrings and \texttt{10} substrings. Note that these substri...
```python tc = int(input()) for t in range(tc): b = input() if b[0] == b[-1]: print(len(b) - 2) else: print(2) ```
vfc_137899
{ "difficulty": "medium", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/GOODBINSTR", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n10100\n11111", "output": "2\n3", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/partition-a-number-into-two-divisible-parts3605/1
Solve the following coding problem using the programming language python: Given a number (as string) and two integers a and b, divide the string in two non-empty parts such that the first part is divisible by a and the second part is divisible by b. In case multiple answers exist, return the string such that the first...
```python class Solution: def stringPartition(ob, S, a, b): for i in range(len(S)): j = S[:i + 1] k = S[i + 1:] if len(j) >= 1 and len(k) >= 1: if int(j) % a == 0 and int(k) % b == 0: return j + ' ' + k return -1 ```
vfc_137904
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/partition-a-number-into-two-divisible-parts3605/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1200 4 3", "output": "12 00", "type": "stdin_stdout" }, { "fn_name": null, "input": "125 12 5", "output": "12 5", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1254/B2
Solve the following coding problem using the programming language python: This is the harder version of the problem. In this version, $1 \le n \le 10^6$ and $0 \leq a_i \leq 10^6$. You can hack this problem if you locked it. But you can hack the previous problem only if you locked both problems Christmas is coming, a...
```python def simple_div(x): if not x & 1: yield 2 while not x & 1: x >>= 1 i = 3 while i * i <= x: if x % i == 0: yield i while x % i == 0: x //= i i += 2 if x != 1: yield x def __main__(): n = int(input()) a = list(map(int, input().split())) sa = sum(a) a.pop() if sa == 1: print(-1)...
vfc_137905
{ "difficulty": "hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1254/B2", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n4 8 5\n", "output": "9\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: In this problem you will be given an integer array A of size N, your task is find whether given array is sorted or not (in ascending order) , if print "YES" else print "NO". Array a[n] is sorted if a[0] ≤ a[1] ≤ ... a[n - 1]. Input First li...
```python noc = eval(input()) while noc: noc -= 1 l = eval(input()) ins = list(map(int, input().split())) if sorted(ins) == ins: print("YES") else: print("NO") ```
vfc_137909
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n4\n1 2 3 4\n3\n7 66 10 \n2 \n1 0", "output": "YES\nYES\nNO\nNO\nYES", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/COOK72/problems/CHEFCBA
Solve the following coding problem using the programming language python: Chef recently learned about ratios and proportions. He wrote some positive integers a, b, c, d on a paper. Chef wants to know whether he can shuffle these numbers so as to make some proportion? Formally, four numbers x, y, z, w are said to make ...
```python def permutate(arr): if len(arr) == 1: yield arr for x in range(len(arr)): for perm in permutate(arr[:x] + arr[x + 1:]): yield ([arr[x]] + perm) vals = [int(x) for x in input().split()] founded = False for val in permutate(vals): if val[0] / float(val[1]) == val[2] / float(val[3]): print('Possible'...
vfc_137914
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/COOK72/problems/CHEFCBA", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 2 4 2\n", "output": "Possible\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/234/A
Solve the following coding problem using the programming language python: One fine October day a mathematics teacher Vasily Petrov went to a class and saw there n pupils who sat at the $\frac{n}{2}$ desks, two people at each desk. Vasily quickly realized that number n is even. Like all true mathematicians, Vasily has ...
```python def lefthanders_and_righthanders(n_int, student_list) -> list: sitting_order = [] for i in range(n_int // 2): if student_list[i] == 'R' and student_list[i + n_int // 2] == 'L': sitting_order.append((i + n_int // 2 + 1, i + 1)) print(i + n_int // 2 + 1, i + 1) else: sitting_order.append((i + 1, ...
vfc_137918
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/234/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\nLLRLLL\n", "output": "1 4\n2 5\n6 3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\nRRLL\n", "output": "3 1\n4 2\n", "type": "stdin_stdout" }, { "fn_name": ...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/drive-the-car2541/1
Solve the following coding problem using the programming language python: Suppose you are a car driver and you have to drive a car on a track divided into "N" number of sub-tracks. You are also given the value of "K" i.e. the total kilometers the car can drive on each sub-track. If the car can't cover a sub-track, you...
```python class Solution: def required(self, a, n, k): g = max(a) if g > k: return g - k return -1 ```
vfc_137926
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/drive-the-car2541/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 5, K = 7\narr[] = {2, 5, 4, 5, 2}", "output": "-1", "type": "stdin_stdout" }, { "fn_name": null, "input": "N = 5, K = 4\narr[] = {1, 6, 3, 5, 2}", "output": "2", "type": "stdin_stdout...
taco
verifiable_code
https://codeforces.com/problemset/problem/1614/A
Solve the following coding problem using the programming language python: Businessman Divan loves chocolate! Today he came to a store to buy some chocolate. Like all businessmen, Divan knows the value of money, so he will not buy too expensive chocolate. At the same time, too cheap chocolate tastes bad, so he will not...
```python for _ in range(int(input())): (n, l, r, k) = [int(i) for i in input().split()] a = sorted([int(i) for i in input().split()]) result = 0 c = 0 for i in range(n): if a[i] >= l and r >= a[i] and (c + a[i] <= k): c += a[i] result += 1 print(result) ```
vfc_137931
{ "difficulty": "easy", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1614/A", "time_limit": "1 second" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "8\n3 1 100 100\n50 100 50\n6 3 5 10\n1 2 3 4 5 6\n6 3 5 21\n1 2 3 4 5 6\n10 50 69 100\n20 30 40 77 1 1 12 4 70 10000\n3 50 80 30\n20 60 70\n10 2 7 100\n2 2 2 2 2 7 7 7 7 7\n4 1000000000 1000000000 1000000000\n1000000000 1000000000 ...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/cutting-binary-string1342/1
Solve the following coding problem using the programming language python: Given a string s containing 0's and 1's. You have to return the smallest positive integer C, such that the binary string can be cut into C pieces and each piece should be of the power of 5 with no leading zeros. Note: The string s is a binary s...
```python class Solution: def cuts(self, s): c = list(s) l = len(c) dp = [0] * (l + 1) dp[0] = 0 for i in range(1, l + 1): index = i - 1 if c[index] == '0': dp[i] = -1 else: dp[i] = -1 t = 1000 count = 0 for j in range(i): if c[index - j] == '1': count += Solution.num...
vfc_137940
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/cutting-binary-string1342/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "s = \"101101101\"", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "s = \"00000\"", "output": "-1", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: There are many caves deep in mountains found in the countryside. In legend, each cave has a treasure hidden within the farthest room from the cave's entrance. The Shogun has ordered his Samurais to explore these caves with Karakuri dolls (robots...
```python for _ in range(int(input())): m = dx = dy = 0 while 1: (x, y) = map(int, input().split()) if x == y == 0: break dx += x dy += y l = dx * dx + dy * dy if m == l and mx < dx or m < l: (m, mx, my) = (l, dx, dy) print(mx, my) ```
vfc_137942
{ "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": "3\n1 0\n0 1\n-1 0\n1 0\n0 5\n-1 0\n0 -1\n5 0\n0 1\n0 -1\n1 0\n0 -4\n-3 0\n0 3\n0 0\n0 -2\n-1 0\n0 1\n0 -1\n1 0\n0 2\n-2 0\n0 -3\n3 0\n0 4\n-4 0\n0 -5\n-2 0\n0 0\n1 0\n-1 0\n0 0\n2 0\n0 1\n-1 0\n0 1\n-1 0\n0 -2\n0 0", "output"...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/message-spreading4258/1
Solve the following coding problem using the programming language python: There are N students in a class, each in possession of a different funny story. They want to share funny stories with each other by sending electronic messages. Assume that a sender includes all the funny stories he or she knows at the time the...
```python class Solution: def minimumMessages(ob, N): if N == 1: return 0 if N == 2: return 2 if N > 2: i = 0 a = 2 while a <= N: a = a + 1 i = i + 2 return i ```
vfc_137946
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/message-spreading4258/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "1", "output": "0", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/PBK22020/problems/ITGUY23
Solve the following coding problem using the programming language python: The chef was not happy with the binary number system, so he designed a new machine which is having 6 different states, i.e. in binary there is a total of 2 states as 0 and 1. Now, the chef is confused about how to correlate this machine to get a...
```python from sys import stdin, stdout l = [1, 6, 7] c = 1 for x in range(3, 100001): if x % 2 == 1: a = l[c] * 6 l.append(a) else: l.append(a + 1) c += 1 n = int(stdin.readline()) for _ in range(n): s = int(stdin.readline()) print(l[s - 1]) ```
vfc_137947
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/PBK22020/problems/ITGUY23", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n3\n5\n", "output": "7\n37\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/withdrawing-money5323/1
Solve the following coding problem using the programming language python: Geek has N dollars in his bank account. He wants to withdraw all of it but the bank only allows withdrawal of an amount that is a divisor of the current amount in the bank and is less than the current amount. If Geek withdraws the maximum possib...
```python class Solution: def numberOfDays(self, N): ans = 0 while N > 0: check = 0 for i in range(2, int(N ** 0.5) + 1): if N % i == 0: N -= N / i ans += 1 check = 1 break if check == 0: N -= 1 ans += 1 return ans ```
vfc_137951
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/withdrawing-money5323/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 12", "output": "5", "type": "stdin_stdout" }, { "fn_name": null, "input": "N = 21", "output": "7", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/adjacents-are-not-allowed3528/1
Solve the following coding problem using the programming language python: You have a rectangular grid mat of dimension 2 x N. You need to find out the maximum sum such that no two chosen numbers are adjacent, vertically, diagonally or horizontally. Example 1: Input: N = 3 mat = {{1, 4, 5}, {2, 0, 0}} Output: 7...
```python class Solution: def maxSum(self, N, mat): dp = [-1] * N if N == 1: return max(mat[0][0], mat[1][0]) dp[0] = max(0, mat[0][0], mat[1][0]) dp[1] = max(dp[0], mat[0][1], mat[1][1]) for i in range(2, N): dp[i] = max(max(mat[0][i], mat[1][i]) + dp[i - 2], dp[i - 1]) return dp[N - 1] ```
vfc_137952
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/adjacents-are-not-allowed3528/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 3\nmat = {{1, 4, 5}, \n {2, 0, 0}}", "output": "7", "type": "stdin_stdout" }, { "fn_name": null, "input": "N = 2\nmat = {{1, 2}, \n {3, 4}}", "output": "4", "type": "stdin...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/find-the-sequence1346/1
Solve the following coding problem using the programming language python: Adobe is weak in the concepts of string. He is given a number N and has to find N terms of that series. The series is 1, 2, 5, 8,15. . . Example 1: Input: N = 8 Output: 1 2 5 8 15 28 51 94 Explanation: For N = 8, series comes out to be: 1 2 5 8...
```python class Solution: def printSeries(self, n): a = 1 b = 2 c = 5 arr = [] i = 0 while i < n: d = a + b + c arr.append(a) a = b b = c c = d i += 1 return arr ```
vfc_137957
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/find-the-sequence1346/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 8", "output": "1 2 5 8 15 28 51 94", "type": "stdin_stdout" }, { "fn_name": null, "input": "N = 3", "output": "1 2 5", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: The Antique Comedians of Malidinesia prefer comedies to tragedies. Unfortunately, most of the ancient plays are tragedies. Therefore the dramatic advisor of ACM has decided to transfigure some tragedies into comedies. Obviously, this work is ver...
```python t = eval(input()) def rev1(n, m): ns = str(n) ns = int(ns[::-1]) ms = str(m) ms = int(ms[::-1]) return ns + ms def rev(n): while(n%10 == 0): n /= 10 return int(str(n)[::-1]) for i in range(t): arr = list(map(int, list(input().strip().split(' ')))) a = arr[0] b = arr[1] print(rev(rev1(a,b))) `...
vfc_137958
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4256\n28268 24826\n22372 29718\n8093 21479\n8029 7468\n30615 20348\n10829 27274\n3894 10937\n20105 1857\n6928 26218\n28154 24742\n23035 29085\n30915 11872\n19664 4697\n803 16575\n7022 18061\n29341 2384\n19201 12615\n1623 4526\n1062...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/linked-list-insertion-1587115620/1
Solve the following coding problem using the programming language python: Create a link list of size N according to the given input literals. Each integer input is accompanied by an indicator which can either be 0 or 1. If it is 0, insert the integer in the beginning of the link list. If it is 1, insert the integer at...
```python class Solution: def insertAtBegining(self, head, x): if not head: return Node(x) temp = Node(x) temp.next = head return temp def insertAtEnd(self, head, x): if head is None: return Node(x) temp = head while temp.next: temp = temp.next temp.next = Node(x) return head ```
vfc_137962
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/linked-list-insertion-1587115620/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "LinkedList:9->0->5->1->6->1->2->0->5->0", "output": "5 2 9 5 6", "type": "stdin_stdout" }, { "fn_name": null, "input": "LinkedList:5->1->6->1->9->1", "output": "5 6 9", "type": "stdin_std...
taco
verifiable_code
https://codeforces.com/problemset/problem/1440/C2
Solve the following coding problem using the programming language python: This is the hard version of the problem. The difference between the versions is in the number of possible operations that can be made. You can make hacks if and only if you solved both versions of the problem. You are given a binary table of si...
```python import sys input = sys.stdin.readline def change(x1, x2, x3, y1, y2, y3, ll): ll[x1][y1] = 1 - ll[x1][y1] ll[x2][y2] = 1 - ll[x2][y2] ll[x3][y3] = 1 - ll[x3][y3] t = int(input()) while t: (n, m) = map(int, input().split()) ll = [] for i in range(n): l = list(map(int, input().strip())) ll.append(l) ...
vfc_137963
{ "difficulty": "hard", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1440/C2", "time_limit": "1.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n2 2\n10\n11\n3 3\n011\n101\n110\n4 4\n1111\n0110\n0110\n1111\n5 5\n01011\n11001\n00010\n11011\n10000\n2 3\n011\n101\n", "output": "1\n1 1 2 1 2 2 \n4\n1 2 1 3 2 2 \n2 1 3 1 2 2 \n2 2 3 2 3 3 \n2 2 2 3 3 3 \n8\n1 1 1 2 2 1 ...
taco
verifiable_code
https://codeforces.com/problemset/problem/617/C
Solve the following coding problem using the programming language python: A flowerbed has many flowers and two fountains. You can adjust the water pressure and set any values r_1(r_1 ≥ 0) and r_2(r_2 ≥ 0), giving the distances at which the water is spread from the first and second fountain respectively. You have to s...
```python import os import sys from math import * from collections import * from fractions import * from bisect import * from heapq 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 ...
vfc_137967
{ "difficulty": "medium_hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/617/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 -1 0 5 3\n0 2\n5 2\n", "output": "6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 0 0 5 0\n9 4\n8 3\n-1 0\n1 4\n", "output": "33\n", "type": "stdin_stdout" }, { ...
taco
verifiable_code
https://codeforces.com/problemset/problem/1534/E
Solve the following coding problem using the programming language python: This is an interactive problem. Note: the XOR-sum of an array a_1, a_2, …, a_n (1 ≤ a_i ≤ 10^9) is defined as a_1 ⊕ a_2 ⊕ … ⊕ a_n, where ⊕ denotes the [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR). Little Dormi r...
```python from sys import stdout def reverse(n, req): return [x for x in range(1, n + 1) if x not in req] def solve(): (n, k) = (int(x) for x in input().split()) if n % 2 == 1 and k % 2 == 0: print(-1) stdout.flush() return elif n % k == 0: xor = 0 curr_idx = 1 while curr_idx <= n: next_idx = curr_...
vfc_137971
{ "difficulty": "unknown_difficulty", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1534/E", "time_limit": "1.5 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 1\n949490681 476940754 49124973\n", "output": "3 639110214\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 2\n1 2 3\n", "output": "-1 -1\n", "type": "stdin_stdout" } ...
taco
verifiable_code
https://www.codechef.com/problems/EQPAIR
Solve the following coding problem using the programming language python: You are given an array A of length N. A pair (i, j) (1≤ i< j ≤ N) is said to be *good* if gcd(A_{i}, A_{j}) = lcm(A_{i}, A_{j}). Here gcd denotes the [greatest common divisor] and lcm denotes [least common multiple]. Find the total number of ...
```python for _ in range(int(input())): n = int(input()) lis = list(map(int, input().split())) lis.sort() ans = 0 cou = 1 for i in range(1, n): if lis[i] == lis[i - 1]: cou += 1 else: ans = ans + cou * (cou - 1) / 2 cou = 1 ans = ans + cou * (cou - 1) // 2 print(int(ans)) ```
vfc_137979
{ "difficulty": "easy", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/EQPAIR", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n2\n5 9\n5\n1 5 5 5 9\n8\n2 5 5 2 9 9 9 12\n4\n12 12 18 18\n5\n12 15 10 5 9\n", "output": "0\n3\n5\n2\n0", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/java-strings-set-15112/1
Solve the following coding problem using the programming language python: Given two strings S1 and S2 as input. Your task is to concatenate two strings and then reverse the string. Finally print the reversed string. Example 1: Input: S1 = "Geeks" , S2 = "forGeeks" Output: "skeeGrofskeeG" Explanation: Concatenating S1...
```python class Solution: def conRevstr(ob, S1, S2): addedString = S1 + S2 reversedString = addedString[::-1] return reversedString ```
vfc_137988
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/java-strings-set-15112/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "S1 = \"Geeks\" , S2 = \"forGeeks\"", "output": "\"skeeGrofskeeG\"", "type": "stdin_stdout" }, { "fn_name": null, "input": "S1 = \"Practice\" , S2 = \"Geeks\"", "output": "\"skeeGecitcarP\"", ...
taco
verifiable_code
https://www.codechef.com/problems/STICKS
Solve the following coding problem using the programming language python: Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Chef and his little brother are playing with sticks. They have total N sticks. Length of i-th stick is A_{i}. Chef asks his brother to choose any four sticks and to...
```python t = int(input()) for ni in range(t): n = int(input()) l = [int(i) for i in input().split()] s = list(set(l)) s = s[-1::-1] x = 0 s1 = list() for i in s: c = l.count(i) if c >= 2: x = x + c // 2 * 2 s1.append(i) if x >= 4: break if len(s1) == 0 or x < 4: print(-1) elif len(s1) == 1: ...
vfc_137989
{ "difficulty": "easy", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/STICKS", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n5\n1 2 3 1 2\n4\n1 2 2 3", "output": "2\n-1", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n5\n1 2 3 1 1\n4\n1 2 2 3", "output": "-1\n-1\n", "type": "stdin_stdout" }, ...
taco
verifiable_code
https://codeforces.com/problemset/problem/1096/F
Solve the following coding problem using the programming language python: A permutation of size $n$ is an array of size $n$ such that each integer from $1$ to $n$ occurs exactly once in this array. An inversion in a permutation $p$ is a pair of indices $(i, j)$ such that $i > j$ and $a_i < a_j$. For example, a permuta...
```python def divisors(M): d = [] i = 1 while M >= i ** 2: if M % i == 0: d.append(i) if i ** 2 != M: d.append(M // i) i = i + 1 return d def popcount(x): x = x - (x >> 1 & 1431655765) x = (x & 858993459) + (x >> 2 & 858993459) x = x + (x >> 4) & 252645135 x = x + (x >> 8) x = x + (x >> 16) ret...
vfc_137994
{ "difficulty": "hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1096/F", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n3 -1 -1\n", "output": "499122179\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1 2\n", "output": "0\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: Summer vacation ended at last and the second semester has begun. You, a Kyoto University student, came to university and heard a rumor that somebody will barricade the entrance of your classroom. The barricade will be built just before the start...
```python (N, A, B) = map(int, input().split()) t = [int(input()) for i in range(N)] ans = 0 for i in range(N): if A <= t[i] < B: continue else: ans += 1 print(ans) ```
vfc_137998
{ "difficulty": "unknown_difficulty", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": null, "time_limit": "1.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 1 6\n9\n6\n8\n1", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 1 2\n2\n2", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, ...
taco
verifiable_code
Solve the following coding problem using the programming language python: You are given N non-overlapping circles in xy-plane. The radius of each circle varies, but the radius of the largest circle is not double longer than that of the smallest. <image> Figure 1: The Sample Input The distance between two circles C1...
```python def _get_distance(c1, c2): return ((c1[1] - c2[1]) ** 2 + (c1[2] - c2[2]) ** 2) ** 0.5 - c1[0] - c2[0] from itertools import combinations def _get_min_distance(circles): min_d = float('inf') for (c1, c2) in combinations(circles, 2): min_d = min(min_d, _get_distance(c1, c2)) return min_d def closest_pa...
vfc_138006
{ "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": "4\n1.0 0.0 0.0\n1.5 0.0 3.0\n2.4193437752467455 4.0 0.0\n1.0 3.0 4.0\n0", "output": "0.500000000000\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n1.0 0.0 0.5226161732400485\n1.5 0.0 3...
taco
verifiable_code
https://codeforces.com/problemset/problem/1594/D
Solve the following coding problem using the programming language python: Theofanis started playing the new online game called "Among them". However, he always plays with Cypriot players, and they all have the same name: "Andreas" (the most common name in Cyprus). In each game, Theofanis plays with $n$ other players....
```python from sys import stdin, setrecursionlimit from collections import defaultdict from threading import Thread, stack_size input = stdin.readline def work(): def dfs(curr): nonlocal c1, c2, ok if color[curr] == 0: c1 += 1 else: c2 += 1 for node in graph[curr]: if color[node[0]] == -1: color...
vfc_138010
{ "difficulty": "medium_hard", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1594/D", "time_limit": "3 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n3 2\n1 2 imposter\n2 3 crewmate\n5 4\n1 3 crewmate\n2 5 crewmate\n2 4 imposter\n3 4 imposter\n2 2\n1 2 imposter\n2 1 crewmate\n3 5\n1 2 imposter\n1 2 imposter\n3 2 crewmate\n3 2 crewmate\n1 3 imposter\n5 0\n", "output": "2...
taco
verifiable_code
Solve the following coding problem using the programming language python: There are N temples in a straight line and K monks who want to spread their enlightening power to the entire road of temples. All the monks have an enlightenment value, which denotes the range of enlightenment which they can spread in both the ...
```python def is_enlightenment_possible(ar, n, k, dist): #Checks if all n temples in list ar is possible to be enlightened by k monks with range dist pos = ar[0] + dist for i in ar: if abs(pos - i) > dist: k = k - 1 pos = i + dist k = k - 1 if k >= 0: return True return False N, K = list(map(int, input(...
vfc_138014
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "100000 18\n3613051 6968776 8617651 5250945 2605599 4947993 6694873 2683281 1357358 5004417 4382640 7891512 7072189 6155695 8139750 8956961 6020969 2570586 8586683 3051843 3804421 6223742 857575 6081732 6800031 3601841 7021065 45493...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/the-modulo-task1736/1
Solve the following coding problem using the programming language python: Given an integer N. FInd an integer K for which N%K is the largest ( 1 <= K < N). Example 1: Input: N = 3 Output: 2 Explanation: 3%1 = 0 3%2 = 1 So, the modulo is highest for 2. Example 2: Input: N = 4 Output: 3 Explanation: 4%1 = 0 4%2 = 0 4%...
```python class Solution: def modTask(self, N): if N % 2 == 1: return (N + 1) // 2 else: return N // 2 + 1 ```
vfc_138018
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/the-modulo-task1736/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 3", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "N = 4", "output": "3", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/jumping-numbers3805/1
Solve the following coding problem using the programming language python: Given a positive number X. Find the largest Jumping Number which is smaller than or equal to X. Jumping Number: A number is called Jumping Number if all adjacent digits in it differ by only 1. All single-digit numbers are considered as Jumping ...
```python from collections import deque class Solution: def generate_all_jumping_nums(self, X, i): J = deque() J.append(i) while J: num = J.popleft() if num <= X: self.ans = max(self.ans, num) last_dig = num % 10 if last_dig != 9: J.append(num * 10 + last_dig + 1) if last_dig != 0: ...
vfc_138019
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/jumping-numbers3805/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "X = 10", "output": "10", "type": "stdin_stdout" }, { "fn_name": null, "input": "X = 50", "output": "45", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/GCDMOD
Solve the following coding problem using the programming language python: ------Read problems statements in Hindi, Mandarin chinese , Russian and Vietnamese as well. ------ At ShareChat, there are are plenty of interesting problems to solve. Here is one of them. Given integers $A$, $B$ and $N$, you should calculate...
```python import math def power(a, n, mod): res = 1 while n > 0: if n & 1 == 1: res = res % mod * a % mod % mod n -= 1 a = a % mod * a % mod % mod n = n // 2 return res def gcd(a, b, n, mod): if a == b: return (power(a, n, mod) + power(b, n, mod)) % mod possible = 1 total = a - b for i in range(1...
vfc_138020
{ "difficulty": "medium_hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/GCDMOD", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n10 1 1\n9 1 5", "output": "1\n2", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/PRIGAME
Solve the following coding problem using the programming language python: Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef and Divyam are playing a game with the following rules: First, an integer $X!$ is written on a board. Chef and Divyam alternate turns; ...
```python import sys def solve(x, y): if primes[x] > y: return 'Divyam' return 'Chef' def prime(n): primes = ['a' for i in range(n + 1)] primes[0] = 0 primes[1] = 0 for i in range(2, n + 1): if primes[i] == 'a': primes[i] = 1 + primes[i - 1] j = 2 while j * i < n: primes[j * i] = 0 j += 1 ...
vfc_138028
{ "difficulty": "medium_hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/PRIGAME", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1 2\n3 1\n2021 42", "output": "Chef\nDivyam \nDivyam", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/cousins-of-a-given-node/1
Solve the following coding problem using the programming language python: Given a binary tree and a node, print all cousins of given node in order of their appearance. Note that siblings should not be printed. Example 1: Input : 1 / \ 2 3 / \ / \ 4 5 6 ...
```python class Solution: def printCousins(self, root, node_to_find): q = [root] flag = 0 while len(q) > 0: l = len(q) for i in range(l): temp = q[0] q.pop(0) if temp.left != None and temp.left == node_to_find: flag = 1 continue elif temp.right != None and temp.right == node_to_f...
vfc_138032
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/cousins-of-a-given-node/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\r\n / \\\r\n 2 3\r\n / \\ / \\\r\n 4 5 6 7\r\n\r\nGiven node:5", "output": "6 7", "type": "stdin_stdout" }, { "fn_name": null, "input": "9\r\n ...
taco
verifiable_code
https://www.codechef.com/problems/CMPRSS
Solve the following coding problem using the programming language python: Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. You are given a strictly increasing sequence of integers $A_{1}, A_{2}, \ldots, A_{N}$. Your task is to compress this sequence. The *compressed form...
```python t = int(input()) for z in range(t): n = int(input()) l = list(map(int, input().split())) i = 0 s = str(l[0]) while i < n - 1: j = i + 1 c = 1 while j < n: if l[i] + j - i == l[j]: c += 1 j += 1 else: break if c >= 3: i = i + c if i < n: s = s + '...' + str(l[i - 1]) + ...
vfc_138033
{ "difficulty": "medium", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/CMPRSS", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n12\n1 2 3 5 6 8 9 10 11 12 15 17\n4\n4 5 7 8\n1\n4", "output": "1...3,5,6,8...12,15,17\n4,5,7,8\n4", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/TMSLT
Solve the following coding problem using the programming language python: Read problems statements in Mandarin Chinese and Russian. Chef wants to split a team of new chef into two teams to play a game. In order to make the split, he first designates two team captains who take alternate turns selecting players for th...
```python mdl = 1000000 for _ in range(int(input())): z = input().split() (n, a, b, c, d) = map(int, z[:5]) sqd = dict() sqd[d] = 0 r = d for e in range(1, n): r = ((a * r + b) * r + c) % mdl try: sqd[r] *= 1 break except KeyError: sqd[r] = e if len(sqd) == n: picks = list(sqd.keys()) else: i...
vfc_138041
{ "difficulty": "medium_hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/TMSLT", "time_limit": "5 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n1 1 1 1 1\n2 1 1 1 1\n3 1 2 3 4\n4 2 3 4 1", "output": "1\n2\n763\n74896", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/342/E
Solve the following coding problem using the programming language python: Xenia the programmer has a tree consisting of n nodes. We will consider the tree nodes indexed from 1 to n. We will also consider the first node to be initially painted red, and the other nodes — to be painted blue. The distance between two tre...
```python class CentroidDecomposition: def __init__(self, g): self.g = g self.n = len(g) self.parent = [-1] * self.n self.size = [1] * self.n self.cdparent = [-1] * self.n self.cddepth = [0] * self.n self.cdorder = [-1] * self.n self.cdused = [0] * self.n cnt = 0 stack = [0] while stack: v = ...
vfc_138049
{ "difficulty": "very_hard", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/342/E", "time_limit": "5.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 4\n1 2\n2 3\n2 4\n4 5\n2 1\n2 5\n1 2\n2 1\n", "output": "0\n3\n0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 4\n1 2\n2 3\n2 4\n4 5\n2 1\n2 1\n1 2\n2 1\n", "output": "0\n0\n0\...
taco
verifiable_code
https://www.codechef.com/problems/WORLDCUP
Solve the following coding problem using the programming language python: Read problems statements in Mandarin Chinese and Russian as well. Captain Dehatti from Bawanian village is making strategy to win the Fake Cricket World Cup organised in his village. He want his team to score runs only in 4's and 6's because...
```python def solve(r, b, l): if b == 0: if r == 0 and l >= 0: return 1 return 0 if l < 0 or r < 0: return 0 if arr[r][b][l] != -1: return arr[r][b][l] ans = 0 ans += solve(r - 0, b - 1, l) ans %= mod ans += solve(r - 0, b - 1, l - 1) ans %= mod ans += solve(r - 4, b - 1, l) ans %= mod ans += solv...
vfc_138053
{ "difficulty": "hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/WORLDCUP", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n10 2 9\n6 2 9\n6 1 9\n4 1 9\n5 1 9\n10 3 9", "output": "2\n4\n1\n1\n0\n12", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/760/A
Solve the following coding problem using the programming language python: Petr wants to make a calendar for current month. For this purpose he draws a table in which columns correspond to weeks (a week is seven consequent days from Monday to Sunday), rows correspond to weekdays, and cells contain dates. For example, a...
```python (x, y) = map(int, input().split()) z = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] k = (z[x - 1] - (abs(y - 7) + 1)) / 7 j = (z[x - 1] - (abs(y - 7) + 1)) % 7 if j == 0: print(int(k + 1)) else: print(int(k + 2)) ```
vfc_138070
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/760/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 7\n", "output": "6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1\n", "output": "5\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/340/A
Solve the following coding problem using the programming language python: Iahub and his friend Floyd have started painting a wall. Iahub is painting the wall red and Floyd is painting it pink. You can consider the wall being made of a very large number of bricks, numbered 1, 2, 3 and so on. Iahub has the following s...
```python def gcd(x, y): if y % x == 0: return x else: return gcd(y % x, x) inp = input() arr = inp.split(' ') x = int(arr[0]) y = int(arr[1]) a = int(arr[2]) b = int(arr[3]) g = gcd(min(x, y), max(x, y)) l = x * y // g i = 0 for i in range(a, a + l + 1): if i > b: break if i % l == 0: break ans = 0 if b >=...
vfc_138075
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/340/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 3 6 18\n", "output": "3", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: Naruto is a fan of numbers, he likes to play with them. This time he decided to multiply numbers and produce output. After every k elements he decides to find x^m, where x is the multiplication till k elements and m is a random number that narut...
```python def power1(x,n,MOD): if(n==0): return 1 ret=1 while(n): if(n&1): ret*=x ret%=MOD x*=x x%=MOD n>>=1 return ret T=eval(input()) while(T): T-=1 N,K,M,W=list(map(int,input().split())) L=list(map(int,input().split())) prod=1 for x in range(N): prod=prod*L[x]%W if((x+1)%K==0): prod=power1(...
vfc_138079
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n3 2 5 5\n8 4 9\n4 9 7 13\n9 4 77 85\n6 4 8 17\n5 98 74 23 65 45", "output": "1", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/c239059f6d110e6778cc2f2a1ab58ffd0a3d64ca/1
Solve the following coding problem using the programming language python: Given two integers N and K, the task is to count the number of ways to divide N into groups of positive integers. Such that each group shall have K elements and their sum is N. Also the number of elements in the groups follows a non-decreasing o...
```python import sys class Solution: def countWaystoDivide(self, N, K): dp = [[[0 for _ in range(K + 1)] for _ in range(N + 1)] for _ in range(N + 1)] for i in range(1, N + 1): dp[i][0][0] = 1 for max_value in range(1, N + 1): for remaining_sum in range(1, N + 1): for remaining_groups in range(1, K +...
vfc_138084
{ "difficulty": "medium_hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/c239059f6d110e6778cc2f2a1ab58ffd0a3d64ca/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 8\r\nK = 4", "output": "5", "type": "stdin_stdout" }, { "fn_name": null, "input": "N = 4\r\nK = 3", "output": "1", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/33af95e5935f1f2a0c3f5083c4b9d0db68e97bd4/1
Solve the following coding problem using the programming language python: Samwell laid out N bowls in a straight line and put a few marbles randomly in each bowl, i^{th} bowl has A[i] marbles. A bowl can never have more than 9 marbles at a time. A bowl can have zero marbles. Now Samwells friend adds one more marble to...
```python class Solution: def solve(self, n, a): for i in range(n - 1, 0, -1): if a[i] < 9: return i + 1 ```
vfc_138085
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/33af95e5935f1f2a0c3f5083c4b9d0db68e97bd4/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 3\r\nA[] = {1, 9, 9}", "output": "1", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/CLRL
Solve the following coding problem using the programming language python: Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef is at a Code Expo where many coders are present discussing, solving, sharing, and eavesdropping on solutions :P He recently learnt that a former HackerPlant em...
```python t = int(input()) for jhj in range(t): (n, r) = map(int, input().split()) a = list(map(int, input().split())) if n < 3: print('YES') continue b = a[0:n - 1] mini = min(b) maxi = max(b) ans = 'YES' for i in b: if i > r and i <= maxi: maxi = i elif i < r and i >= mini: mini = i else: a...
vfc_138086
{ "difficulty": "medium", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/CLRL", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n5 200\n600 300 100 350 200\n5 890\n5123 3300 783 1111 890\n", "output": "NO\nYES", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: You are situated in an N dimensional grid at position (x1,x2,...,xN). The dimensions of the grid are (D1,D2,...DN). In one step, you can walk one step ahead or behind in any one of the N dimensions. (So there are always 2×N possible different mo...
```python mod = 1000000007 def solve(x, d, n, m): mat = [[0 for i in range(n + 1)] for j in range(m + 1)] for i in range(n): mat1 = [[0 for j in range(m + 1)] for k in range(d[i] + 1)] D = d[i] for j in range(1, D + 1): mat1[j][0] = 1 for j in range(1, m + 1): for k in range(1, D + 1): mat1[k][j] = ...
vfc_138090
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n1 287\n44\n78\n1 236\n25\n87\n1 122\n41\n63\n1 260\n7\n64\n1 127\n3\n73", "output": "38753340\n587915072\n644474045\n423479916\n320130104", "type": "stdin_stdout" }, { "fn_name": null, "input": "5...
taco
verifiable_code
https://codeforces.com/problemset/problem/1043/E
Solve the following coding problem using the programming language python: Zibi is a competitive programming coach. There are $n$ competitors who want to be prepared well. The training contests are quite unusual – there are two people in a team, two problems, and each competitor will code exactly one of them. Of course...
```python from __future__ import division, print_function import io import os import sys if sys.version_info[0] < 3: from __builtin__ import xrange as range from cStringIO import StringIO from future_builtins import ascii, filter, hex, map, oct, zip else: from io import BytesIO as StringIO (sys.stdout, stream) = (i...
vfc_138094
{ "difficulty": "hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1043/E", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 2\n1 2\n2 3\n1 3\n1 2\n2 3\n", "output": "3 0 3 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 3\n1 2\n2 3\n1 3\n1 2\n2 3\n1 3\n", "output": "0 0 0 ", "type": "stdin_stdout...
taco
verifiable_code
https://codeforces.com/problemset/problem/316/E1
Solve the following coding problem using the programming language python: By the age of three Smart Beaver mastered all arithmetic operations and got this summer homework from the amazed teacher: You are given a sequence of integers a_1, a_2, ..., a_{n}. Your task is to perform on it m consecutive operations of the f...
```python (n, m) = list(map(int, input().split())) a = list(map(int, input().split())) for i in range(m): (t, l, r) = list(map(int, input().split())) if t == 1: a[l - 1] = r else: s = 0 fiba = fibb = 1 for i in range(l - 1, r): s += fiba * a[i] (fiba, fibb) = (fibb, fiba + fibb) print(s % 1000000000)...
vfc_138098
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/316/E1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 5\n1 3 1 2 4\n2 1 4\n2 1 5\n2 2 4\n1 3 10\n2 1 5\n", "output": "12\n32\n8\n50\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 3\n2\n2 1 1\n1 1 3\n2 1 1\n", "output": "2\n3\n", ...
taco
verifiable_code
Solve the following coding problem using the programming language python: Write a program that extracts n different numbers from the numbers 0 to 9 and outputs the number of combinations that add up to s. Each n number is from 0 to 9, and the same number cannot be used in one combination. For example, if n is 3 and s ...
```python def dfs(depth, prev, sum): if depth == n: return sum == s ret = 0 for i in range(prev + 1, 10): ret += dfs(depth + 1, i, sum + i) return ret while True: (n, s) = map(int, input().split()) if n == 0: break print(dfs(0, -1, 0)) ```
vfc_138102
{ "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": "3 5\n3 1\n0 0", "output": "2\n0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 0\n5 1\n0 0", "output": "0\n0\n", "type": "stdin_stdout" }, { "fn_name": null, ...
taco
verifiable_code
https://codeforces.com/problemset/problem/1130/D2
Solve the following coding problem using the programming language python: Alice received a set of Toy Train™ from Bob. It consists of one train and a connected railway network of n stations, enumerated from 1 through n. The train occupies one station at a time and travels around the network of stations in a circular m...
```python (n, m) = map(int, input().split()) def dist(a, b): return (n + b - a) % n def main(): inp1 = [0] * (n + 1) inp2 = [n] * (n + 1) for _ in range(m): (a, b) = map(int, input().split()) inp1[a] += 1 inp2[a] = min(inp2[a], dist(a, b)) inp = tuple(((r1 - 1) * n + r2 for (r1, r2) in zip(inp1, inp2))) l...
vfc_138106
{ "difficulty": "medium_hard", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1130/D2", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10 8\n5 2\n6 5\n3 8\n9 10\n4 3\n9 5\n2 6\n9 10\n", "output": "29 28 27 26 25 24 23 22 21 30 ", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/ZCOPREP
Solve the following coding problem using the programming language python: ZCO is approaching, and you want to be well prepared! There are $N$ topics to cover and the $i^{th}$ topic takes $H_i$ hours to prepare (where $1 \le i \le N$). You have only $M$ days left to prepare, and you want to utilise this time wisely. ...
```python import math T = int(input()) for i in range(T): (N, M, S) = input().split() N = int(N) M = int(M) S = int(S) ls = list(map(int, input().split())) maxx = max(ls) if S < 17 and maxx <= 50: ls.sort() total_sum = M * S count = 0 sum = 0 for i in ls: if i / S > 2: continue else: sum ...
vfc_138110
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/ZCOPREP", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n5 4 10\n10 24 30 19 40\n5 4 16\n7 16 35 10 15\n", "output": "2\n4\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/XORNUBER
Solve the following coding problem using the programming language python: Given an integer N, Chef wants to find the smallest positive integer M such that the bitwise XOR of M and M+1 is N. If no such M exists output -1. -----Input----- The first line of input contain an integer T denoting the number of test cases. E...
```python a = [2 ** x - 1 for x in range(1, 31)] for _ in range(int(input())): n = int(input()) if n == 1: print(2) elif n in a: print(n // 2) else: print('-1') ```
vfc_138115
{ "difficulty": "medium_hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/XORNUBER", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n3\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n1", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n2", ...
taco
verifiable_code
https://codeforces.com/problemset/problem/67/A
Solve the following coding problem using the programming language python: A teacher decides to give toffees to his students. He asks n students to stand in a queue. Since the teacher is very partial, he follows the following rule to distribute toffees. He looks at the first two students and gives more toffees to the ...
```python from collections import deque n = int(input()) s = input() ans = [1] * n for i in range(1, n): if s[i - 1] == 'R': ans[i] = ans[i - 1] + 1 elif s[i - 1] == '=': ans[i] = ans[i - 1] for i in range(n - 2, -1, -1): if s[i] == 'L': ans[i] = max(ans[i + 1] + 1, ans[i]) elif s[i] == '=': ans[i] = max(an...
vfc_138119
{ "difficulty": "medium_hard", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/67/A", "time_limit": "1.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "166\nR===RL=LRRR=RRRL=LRR=R=RR==L=R=R=RRR=RR=RLLRRL=LLRL==L=R==RLR==RL=RR=LR==R=R=LLRLRLR=RR=RLLRLR=RRLL==L=LR=RR=RRRL=RLLLR==L=RRLRLLLLLLLRL===LRLRLRLRRLL=LRLL===LRLRR==\n", "output": "1 2 2 2 2 3 2 2 1 2 3 4 4 5 6 7 2 2 1 2...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/create-your-own-calculator4308/1
Solve the following coding problem using the programming language python: Given the co-effecients of X,Y and Z in a system of simultaneous equations. Find the values of X,Y and Z. a1X + b1Y + c1Z = d1 a2X + b2Y + c2Z = d2 a3X + b3Y + c3Z = d3 Example 1: Input: Arr = {{5, 4, 2, 0}, {1, 4, 2, 0}, {4, 2...
```python import math class Solution: def delta(self, Arr, i, j, k): ans = Arr[0][i] * Arr[1][j] * Arr[2][k] ans += Arr[0][j] * Arr[1][k] * Arr[2][i] ans += Arr[0][k] * Arr[1][i] * Arr[2][j] ans -= Arr[0][i] * Arr[1][k] * Arr[2][j] ans -= Arr[0][j] * Arr[1][i] * Arr[2][k] ans -= Arr[0][k] * Arr[1][j] * A...
vfc_138124
{ "difficulty": "medium_hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/create-your-own-calculator4308/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "Arr = {{5, 4, 2, 0},\r\n {1, 4, 2, 0},\r\n {4, 2, 9, 0}}", "output": "{0, 0, 0}", "type": "stdin_stdout" }, { "fn_name": null, "input": "Arr = {{4.2, 6, 7, 10},\r\n {1, 2, 3, 12},\r...
taco
verifiable_code
https://www.codechef.com/problems/CLOST
Solve the following coding problem using the programming language python: Read problems statements in Mandarin Chinese , Russian and Vietnamese Churu is taking the course called “Introduction to Data Structures”. Yesterday, he learned how to use a stack to check is a given parentheses expression is balanced or not....
```python for _ in range(int(input())): (n, k) = map(int, input().split()) ans = '00' * (n // 2) + '0' * (n % 2) ans = list(ans) qry = [] for i in range(k): (x, y) = map(int, input().split()) qry.append([x, y]) qry.sort(key=lambda x: x[1] - x[0]) for i in range(k): x = qry[i][0] y = qry[i][1] mauka = 0...
vfc_138125
{ "difficulty": "hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/CLOST", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n4 1\n0 3\n4 2\n0 3\n1 2", "output": "()()\n(())", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/REIGN
Solve the following coding problem using the programming language python: Read problems statements in Mandarin Chinese and Russian. The Baratheons have been ruling in the Seven Kingdoms for many years. They have seen a lot: prosperity and hunger, tranquility and rebellions, live and death. But nevertheless, they sti...
```python def reign(arr, K): subarr1 = kadanesmax(arr) arr.reverse() subarr2 = kadanesmax(arr) subarr2.reverse() prosperity = arr[0] + arr[-1] for i in range(len(arr) - K - 1): year = subarr2[i + (K + 1)] + subarr1[i] prosperity = max(prosperity, year) return prosperity def kadanesmax(arr): maxend = arr[0]...
vfc_138133
{ "difficulty": "medium_hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/REIGN", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n5 3\n-1 1 2 3 -1\n8 3\n5 5 -1 -2 3 -1 2 -2\n6 0\n5 -1 5 0 -1 9", "output": "-2\n12\n18", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: Example Input crc 1 Output crc The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python from heapq import heappush, heappop def solve(): S = input() K = int(input()) L = len(S) INF = 10 ** 9 cost = [[INF] * (L + 1) for i in range(L + 1)] cost[0][L] = 0 ss = [] que = [(0, 0, L)] while que: (d, a, b) = heappop(que) if cost[a][b] < d: continue ss.append((a, b)) if a + 1 == b: ...
vfc_138137
{ "difficulty": "unknown_difficulty", "memory_limit": "268.435456 megabytes", "memory_limit_bytes": null, "problem_url": null, "time_limit": "3.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "crb\n1", "output": "bcrcb\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/MNMX
Solve the following coding problem using the programming language python: Chef loves to play with arrays by himself. Today, he has an array A consisting of N distinct integers. He wants to perform the following operation on his array A. - Select a pair of adjacent integers and remove the larger one of these two. This...
```python for _ in range(int(input())): n = int(input()) list_a = list(map(int, input().split())) if n == 2: print(min(list_a)) else: print(min(list_a) * (n - 1)) ```
vfc_138141
{ "difficulty": "easy", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/MNMX", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n2\n3 4\n3\n4 2 5\n", "output": "3\n4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n2\n3 4\n3\n4 2 9", "output": "3\n4\n", "type": "stdin_stdout" }, { "fn_...
taco
verifiable_code
https://codeforces.com/problemset/problem/249/B
Solve the following coding problem using the programming language python: For he knew every Who down in Whoville beneath, Was busy now, hanging a mistletoe wreath. "And they're hanging their stockings!" he snarled with a sneer, "Tomorrow is Christmas! It's practically here!" Dr. Suess, How The Grinch Stole Christmas ...
```python def check(n, casas): global T, N, street current = n time = T need = 0 last_house = 0 for (ind, i) in enumerate(street): time -= 1 if i == 'S': current += 1 elif i == 'H': need += 1 if need == 1: last_house = ind if need > 0 and current >= need: current -= need casas -= need ...
vfc_138145
{ "difficulty": "hard", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/249/B", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "336 400\nHSSHHSSHHS..S..SS..H.S.H..SSH.H.H.H.S.H.S.S.H.S..SS..H.SS.H.SS.SS..SS.H...H.H.H.HSS..H...SS..SS.H..H.S.S....S.H.SS..HS..S.S.S.H.H.S..S.H.SS.SS..SS.SS.HS.SS.HSSSSHSSSSSS.H.SS..HHH.H.H.S..H.SS.S.H..SS.HS.SS.S.H.H.H..H.SS.HS....
taco
verifiable_code
https://codeforces.com/problemset/problem/618/D
Solve the following coding problem using the programming language python: A group of n cities is connected by a network of roads. There is an undirected road between every pair of cities, so there are $\frac{n \cdot(n - 1)}{2}$ roads in total. It takes exactly y seconds to traverse any single road. A spanning tree is...
```python from collections import defaultdict from collections import deque from functools import reduce (n, x, y) = [int(x) for x in input().split()] E = defaultdict(set) for i in range(n - 1): (u, v) = [int(x) for x in input().split()] E[u].add(v) E[v].add(u) if x > y: for v in E: if len(E[v]) == n - 1: prin...
vfc_138149
{ "difficulty": "hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/618/D", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 2 3\n1 2\n1 3\n3 4\n5 3\n", "output": "9\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 3 2\n1 2\n1 3\n3 4\n5 3\n", "output": "8\n", "type": "stdin_stdout" }, { ...
taco
verifiable_code
https://codeforces.com/problemset/problem/1520/G
Solve the following coding problem using the programming language python: Dima overslept the alarm clock, which was supposed to raise him to school. Dima wonders if he will have time to come to the first lesson. To do this, he needs to know the minimum time it will take him to get from home to school. The city where...
```python import io import os from collections import deque from math import inf input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline M9 = 10 ** 9 + 7 (yes, no) = ('YES', 'NO') d4 = [(1, 0), (0, 1), (-1, 0), (0, -1)] MAXINT = inf def solve_(mrr, w, nrows, ncols): size = nrows * ncols def dfs(source, size): ...
vfc_138153
{ "difficulty": "hard", "memory_limit": "512.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1520/G", "time_limit": "3.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 3 1000000000\n0 0 0\n0 0 0\n", "output": "3000000000", "type": "stdin_stdout" }, { "fn_name": null, "input": "10 5 2\n0 3 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n-1 0 0 0 0\n0 0 0 6 0\n0 0 0 0 8\n0 0 5 6 0\n0...
taco
verifiable_code
https://www.codechef.com/problems/BREAKBAL
Solve the following coding problem using the programming language python: JJ found a balanced parenthesis sequence. He does not like balanced parentheses so he will make the parenthesis sequence unbalanced by swapping adjacent characters in the sequence. JJ is lazy and wants to know minimum number of adjacent swaps ...
```python from sys import stdin input = stdin.readline def answer(): ans = float('inf') (o, c, ind) = (0, 0, 0) for i in range(n): req = o - c + 1 while dist[-1] < i + 1: dist.pop() ind += 1 if n // 2 - ind < req: break cal = prefix[ind + req] - prefix[ind] - req * i - req * (req + 1) // 2 ans = ...
vfc_138157
{ "difficulty": "very_hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/BREAKBAL", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n()\n(())\n()()\n((()))(())\n", "output": "1\n2\n1\n2\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1354/D
Solve the following coding problem using the programming language python: Note that the memory limit is unusual. You are given a multiset consisting of n integers. You have to process queries of two types: * add integer k into the multiset; * find the k-th order statistics in the multiset and remove it. k-t...
```python from collections import Counter from collections import defaultdict from collections import deque import math import os import sys input = sys.stdin.readline ii = 0 _inp = b'' def getchar(): global ii, _inp if ii >= len(_inp): _inp = os.read(0, 4000) ii = 0 if not _inp: return b' '[0] ii += 1 retu...
vfc_138161
{ "difficulty": "hard", "memory_limit": "28.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1354/D", "time_limit": "1.5 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 8\n1 1 1 1 1\n2 3 4 -1 -1 -1 -1 -1\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 2\n1 1 1 2 3 4\n5 6\n", "output": "1\n", "type": "stdin_stdout" }, ...
taco
verifiable_code
https://codeforces.com/problemset/problem/1292/F
Solve the following coding problem using the programming language python: SIHanatsuka - EMber SIHanatsuka - ATONEMENT Back in time, the seven-year-old Nora used to play lots of games with her creation ROBO_Head-02, both to have fun and enhance his abilities. One day, Nora's adoptive father, Phoenix Wyle, brought Nor...
```python MOD = 1000000007 def isSubset(a, b): return a & b == a def isIntersect(a, b): return a & b != 0 def cntOrder(s, t): p = len(s) m = len(t) inMask = [0 for i in range(m)] for x in range(p): for i in range(m): if t[i] % s[x] == 0: inMask[i] |= 1 << x cnt = [0 for mask in range(1 << p)] for ma...
vfc_138169
{ "difficulty": "hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1292/F", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n2 6 8\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n2 3 4 9 12\n", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "i...
taco
verifiable_code
Solve the following coding problem using the programming language python: Given integer n, find length of n! (which is factorial of n) excluding trailing zeros. Input The first line of the standard input contains one integer t (t<10001) which is the number of test cases. In each of the next t lines there is number ...
```python from math import * def Trailing_Zeroes(x): fives = 0 i = 1 while 5**i <= x: fives+=x/(5**i) i+=1 return fives t = int(input()) while t: t-=1 n = int(input()) a = 0 #for i in xrange(1,n+1): # a+=log(i) print(int(ceil(lgamma(n+1)/log(10))) - Trailing_Zeroes(n)) ```
vfc_138173
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n105\n78\n123\n79", "output": "143\n378\n1426\n33149\n331869\n180622", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n104\n224\n665\n9996\n78787\n45457", "output": "144\n98\n178\n9...
taco
verifiable_code
https://www.hackerrank.com/challenges/stonegame/problem
Solve the following coding problem using the programming language python: Alice and Bob are playing the game of Nim with $n$ piles of stones with sizes $p_0,p_1,\ldots,p_{n-1}$. If Alice plays first, she loses if and only if the 'xor sum' (or 'Nim sum') of the piles is zero, i.e., $p_0\oplus p_1\oplus...\oplus p_{n-1}...
```python import operator as op import functools as ft from sys import stderr MOD = 1000000007 def readcase(): npiles = int(input()) piles = [int(fld) for fld in input().split()] assert npiles == len(piles) return piles def numsolns(piles): return (numunrestrictedsolns(piles) - numunrestrictedsolns([pile - 1 for...
vfc_138178
{ "difficulty": "medium_hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.hackerrank.com/challenges/stonegame/problem", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1 2 3\n", "output": "4\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/divisible-by-82732/1
Solve the following coding problem using the programming language python: Given a number S, you need to check whether any permutation of the number S divisible by 8 or not. Example 1: Input: S = "80" Output: "Divisible" Explanation: 80 is divisible by 8 Example 2 Input: S = "101" Output: "Not divisible" Your Task : C...
```python class Solution: def isDivisible8(self, S): if len(S) == 1: return int(not int(S) % 8) elif len(S) == 2: a = S[0] b = S[1] if int(a + b) % 8 == 0 or int(b + a) % 8 == 0: return 1 return 0 for i in range(len(S)): for j in range(i + 1, len(S)): for k in range(j + 1, len(S)): ...
vfc_138183
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/divisible-by-82732/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "S = \"80\"", "output": "\"Divisible\"", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/COVAXIN
Solve the following coding problem using the programming language python: Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. There are two types of vaccines available: Covaxin and Covishield. A black marketeer has X coins and wants to buy as many vaccines as possible. Due ...
```python import cmath def find_total(x, y): return B * x * x / 2 + j * x + D * y * y / 2 + k * y def find_root(a, b, c): dis = b ** 2 - 4 * a * c r1 = (-b - cmath.sqrt(dis)) / (2 * a) r2 = (-b + cmath.sqrt(dis)) / (2 * a) return max(r1.real, r2.real) q = int(input()) (X, A, B, C, D) = map(int, input().split()) ...
vfc_138184
{ "difficulty": "very_hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/COVAXIN", "time_limit": "1 - 3 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n20 2 3 4 1\n3 7 8 4 11 20\n", "output": "4\n1\n2\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/154/A
Solve the following coding problem using the programming language python: Sergey attends lessons of the N-ish language. Each lesson he receives a hometask. This time the task is to translate some sentence to the N-ish language. Sentences of the N-ish language can be represented as strings consisting of lowercase Latin...
```python ans = 0 t = [] x = input() y = int(input()) for i in range(y): z = input() t.append(z) pt = -1 ln = len(x) for i in t: a = i[0] b = i[1] pt = 0 for j in range(ln): ded1 = 0 ded2 = 0 if j >= pt: if x[j] in [a, b]: pt = j while pt < ln and x[pt] in [a, b]: if x[pt] == a: ded1 +...
vfc_138193
{ "difficulty": "medium_hard", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/154/A", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "vefneyamdzoytemupniw\n13\nve\nfg\noi\nan\nck\nwx\npq\nml\nbt\nud\nrz\nsj\nhy\n", "output": "1\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/license-key-formatting/1
Solve the following coding problem using the programming language python: Given a string S that consists of only alphanumeric characters and dashes. The string is separated into N + 1 groups by N dashes. Also given an integer K. We want to reformat the string S, such that each group contains exactly K characters, exc...
```python class Solution: def ReFormatString(self, S, K): c = K N = len(S) size = 0 ans = [] for j in range(N - 1, -1, -1): tmp = S[j] if tmp >= 'a' and tmp <= 'z': tmp = chr(65 + (ord(tmp) - 97)) if S[j] != '-' and c: ans.append(tmp) c -= 1 size += 1 elif c == 0: c = K a...
vfc_138197
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/license-key-formatting/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "S = \"5F3Z-2e-9-w\", K = 4", "output": "\"5F3Z-2E9W\"", "type": "stdin_stdout" }, { "fn_name": null, "input": "S = \"2-5g-3-J\", K = 2", "output": "\"2-5G-3J\"", "type": "stdin_stdout" ...
taco
verifiable_code
https://codeforces.com/problemset/problem/1694/B
Solve the following coding problem using the programming language python: Let's call a binary string $T$ of length $m$ indexed from $1$ to $m$ paranoid if we can obtain a string of length $1$ by performing the following two kinds of operations $m-1$ times in any order : Select any substring of $T$ that is equal to 01...
```python import sys input = sys.stdin.readline def solve(): n = int(input()) s = input().strip() ans = n for i in range(1, n): if s[i - 1] != s[i]: ans += i return ans for _ in range(int(input())): print(solve()) ```
vfc_138200
{ "difficulty": "easy", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1694/B", "time_limit": "1 second" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n1\n1\n2\n01\n3\n100\n4\n1001\n5\n11111\n", "output": "1\n3\n4\n8\n5\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/RC122020/problems/RECNDNUM
Solve the following coding problem using the programming language python: Chef is playing a game on the non-negative x-axis. It takes him $1$ second to reach from $i^{th}$ position to $(i-1)^{th}$ position or $(i+1)^{th}$ position. The chef never goes to the negative x-axis. Also, Chef doesn't stop at any moment of ti...
```python import sys from random import choice, randint inp = sys.stdin.readline out = sys.stdout.write flsh = sys.stdout.flush sys.setrecursionlimit(10 ** 9) 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_138204
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/RC122020/problems/RECNDNUM", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n0 1\n1 1\n2 1\n1 3\n4 6\n", "output": "0\n1\n4\n5\n46\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/CNCTCT
Solve the following coding problem using the programming language python: The country of Berland initially has N isolated cities, the i-th city has a significance of A_{i}. The President of Berland wants to connect all the cities. He can construct a bidirectional road of length L (L > 0) from city X to city Y if (A_{X...
```python import sys, math, heapq, bisect, random, itertools input = sys.stdin.readline sys.setrecursionlimit(10 ** 5) ints = lambda : list(map(int, input().split())) p = 10 ** 9 + 7 inf = 10 ** 20 + 7 alpha = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' p2 = [1] for i in range(40): p2.append(p2[-1] * 2) for t in range(int(input())):...
vfc_138209
{ "difficulty": "very_hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/CNCTCT", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n4\n4 4 4 4\n3\n2 4 6", "output": "12\n6\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/prime-factors-of-lcm-of-array-elements3940/1
Solve the following coding problem using the programming language python: Given an array of elements find all the prime factors of the LCM of the given numbers. Example 1: Input: N = 8 Arr = {1 , 2, 3, 4, 5, 6, 7, 8} Output: 2 3 5 7 Explaination: LCM of N elements is 840 and 840 = 2*2*2*3*5*7.so prime factors would ...
```python class Solution: def lcm(self, a, b): from math import gcd return a * b // gcd(a, b) def primeFactorLcm(self, Arr, N): lc = Arr[0] lis = [] for i in Arr: lc = self.lcm(lc, i) d = 2 while lc >= d: if lc % d == 0: while lc % d == 0: lc //= d lis.append(d) d += 1 return l...
vfc_138213
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/prime-factors-of-lcm-of-array-elements3940/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 8\r\nArr = {1 , 2, 3, 4, 5, 6, 7, 8}", "output": "2 3 5 7", "type": "stdin_stdout" }, { "fn_name": null, "input": "N = 4\r\nArr = {20, 10, 15, 60}", "output": "2 3 5", "type": "stdin_...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/rohans-love-for-matrix4723/1
Solve the following coding problem using the programming language python: Rohan has a special love for the matrices especially for the first element of the matrix. Being good at Mathematics, he also loves to solve the different problem on the matrices. So one day he started to multiply the matrix with the original mat...
```python class Solution: def firstElement(self, n): a = 0 b = 1 for i in range(2, n + 1): c = (a + b) % 1000000007 a = b b = c return b ```
vfc_138214
{ "difficulty": "medium_hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/rohans-love-for-matrix4723/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "n = 3", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "n = 4", "output": "3", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: Problem Statement We have planted $N$ flower seeds, all of which come into different flowers. We want to make all the flowers come out together. Each plant has a value called vitality, which is initially zero. Watering and spreading fertilizer...
```python import sys def main(): readline = sys.stdin.readline write = sys.stdout.write def gcd(m, n): while n: (m, n) = (n, m % n) return m def init(p, q=1): g = gcd(p, q) return (p // g, q // g) def add(A, B): (pa, qa) = A (pb, qb) = B if pa == 0: return B if pb == 0: return A g = ...
vfc_138215
{ "difficulty": "unknown_difficulty", "memory_limit": "536.870912 megabytes", "memory_limit_bytes": null, "problem_url": null, "time_limit": "8.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n10\n5 3 4 10\n5 4 5 20\n6 5 6 30\n3\n7\n-4 3 4 -10\n5 4 5 20\n6 5 6 30\n3\n1\n-4 3 4 -10\n-5 4 5 -20\n6 5 6 30\n3\n10\n-4 3 4 -10\n-5 4 5 -20\n-6 5 6 -30\n0", "output": "43\n36\n13.5\n0\n", "type": "stdin_stdout" ...
taco
verifiable_code
https://www.codechef.com/problems/CHEFSHIP
Solve the following coding problem using the programming language python: Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. In Chefland, each person has their own non-empty personal string. When two people with personal strings $T_{1}$ and $T_{2}$ (possibly ident...
```python for i in range(int(input())): s = input() c = 0 l = len(s) for i in range(2, l, 2): a = i b = l - i t11 = s[0:a // 2] t12 = s[a // 2:a] t21 = s[a:a + b // 2] t22 = s[a + b // 2:] if t11 == t12 and t21 == t22: c = c + 1 print(c) ```
vfc_138219
{ "difficulty": "medium_hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/CHEFSHIP", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\nabcd\naaaa\nababcdccdc", "output": "0\n1\n1", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/301/A
Solve the following coding problem using the programming language python: Yaroslav has an array, consisting of (2·n - 1) integers. In a single operation Yaroslav can change the sign of exactly n elements in the array. In other words, in one operation Yaroslav can select exactly n array elements, and multiply each of t...
```python n = int(input()) lst = [int(x) for x in input().split()] x = len([elem for elem in lst if elem < 0]) values = sorted([abs(elem) for elem in lst]) result = sum(values) if n % 2 == 0 and x % 2 == 1: result -= 2 * values[0] print(result) ```
vfc_138224
{ "difficulty": "medium_hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/301/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n50 50 50\n", "output": "150\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n-1 -100 -1\n", "output": "100\n", "type": "stdin_stdout" }, { "fn_name": null, ...
taco
verifiable_code
https://codeforces.com/problemset/problem/1047/C
Solve the following coding problem using the programming language python: Mr. F has n positive integers, a_1, a_2, …, a_n. He thinks the greatest common divisor of these integers is too small. So he wants to enlarge it by removing some of the integers. But this problem is too simple for him, so he does not want to d...
```python from sys import stdin from collections import deque mod = 10 ** 9 + 7 from bisect import bisect_right from bisect import bisect_left from collections import defaultdict from math import sqrt, factorial, gcd, log2, inf, ceil n = int(input()) l = list(map(int, input().split())) m = max(l) + 1 prime = [0] * m cm...
vfc_138228
{ "difficulty": "medium_hard", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1047/C", "time_limit": "1.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1 100003 100003\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n24 24 12\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, ...
taco
verifiable_code
https://www.codechef.com/problems/AORB
Solve the following coding problem using the programming language python: There are two problems in a contest. Problem A is worth 500 points at the start of the contest. Problem B is worth 1000 points at the start of the contest. Once the contest starts, after each minute: Maximum points of Problem A reduce by 2 poin...
```python t = int(input()) for i in range(t): (X, Y) = map(int, input().split()) FirstA = 500 - 2 * X + (1000 - 4 * (X + Y)) FirstB = 1000 - 4 * Y + (500 - 2 * (X + Y)) if FirstB > FirstA: print(FirstB) else: print(FirstA) ```
vfc_138233
{ "difficulty": "easy", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/AORB", "time_limit": "0.5 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n10 20\n8 40\n15 15\n20 10\n", "output": "1360\n1292\n1380\n1400\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: A bipartite graph G = (V, E) is a graph in which the vertex set V can be divided into two disjoint subsets X and Y such that every edge e ∈ E has one end point in X and the other end point in Y. A matching M is a subset of edges such that each ...
```python import sys def generate_adj_table(_edges): for edge in _edges: (vx, vy) = map(int, edge) init_adj_table[vx].add(vy) return init_adj_table def graph_dfs(current, matching, visited): for adj in range(y_num): if not visited[adj] and adj in adj_table[current]: visited[adj] = True if matching[adj]...
vfc_138242
{ "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": "3 4 6\n0 0\n0 0\n0 3\n1 1\n2 1\n2 3", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 7 2\n1 0\n0 0\n0 3\n0 1\n1 1\n2 3", "output": "1\n", "type": "stdin_stdout"...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/jays-apples2724/1
Solve the following coding problem using the programming language python: One day Jay, on getting his first salary, decides to distribute apples among the poverty-stricken persons. He gave each person 1kg of apples. People are coming in a queue and he makes sure that he gives every person 1 kg of apples only once. Eve...
```python def minimum_apple(arr, n): arr = list(set(arr)) return len(arr) ```
vfc_138246
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/jays-apples2724/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": "minimum_apple", "input": "arr[ ] = {1, 1, 1, 1, 1}", "output": "1", "type": "function_call" }, { "fn_name": "minimum_apple", "input": "arr[ ] = {1, 2, 3, 1, 2}", "output": "3", "type": "function_call" ...
taco
verifiable_code
https://codeforces.com/problemset/problem/26/C
Solve the following coding problem using the programming language python: Once Bob decided to lay a parquet floor in his living room. The living room is of size n × m metres. Bob had planks of three types: a planks 1 × 2 meters, b planks 2 × 1 meters, and c planks 2 × 2 meters. Help Bob find out, if it is possible to ...
```python (n, m, a, b, c) = map(int, input().split()) mat = [0] * n for i in range(n): mat[i] = [0] * m n1 = [min(n * m // 4, c), min(m // 2 * n, a), min(n // 2 * m, b)] p = ['c', 'a', 'b'] z = ['d', 'e', 'f', 'g'] z1 = ['m', 'n', 'u', 'o'] z2 = ['p', 'q', 'r', 'w'] def fill(h, w): if h <= 0 or w <= 0: return True...
vfc_138247
{ "difficulty": "hard", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/26/C", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "100 100 10000 10000 10000\n", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabb\naabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaa...
taco
verifiable_code
Solve the following coding problem using the programming language python: A dial lock is a kind of lock which has some dials with printed numbers. It has a special sequence of numbers, namely an unlocking sequence, to be opened. You are working at a manufacturer of dial locks. Your job is to verify that every manufac...
```python import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools sys.setrecursionlimit(10 ** 7) inf = 10 ** 20 eps = 1.0 / 10 ** 13 mod = 10 ** 9 + 7 dd = [(-1, 0), (0, 1), (1, 0), (0, -1)] ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (...
vfc_138251
{ "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": "4\n1433 4680\n6\n777777 003330\n0", "output": "4\n2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n1357 4680\n6\n509138 003330\n0", "output": "1\n4\n", "type": "stdin_stdou...
taco
verifiable_code
https://codeforces.com/problemset/problem/175/B
Solve the following coding problem using the programming language python: Vasya has been playing Plane of Tanks with his friends the whole year. Now it is time to divide the participants into several categories depending on their results. A player is given a non-negative integer number of points in each round of the...
```python from collections import defaultdict from bisect import bisect_left (p, n) = (defaultdict(int), int(input())) for i in range(n): (a, b) = input().split() p[a] = max(p[a], int(b)) (p, n) = (sorted(((b, a) for (a, b) in p.items())), len(p)) t = [0] + [bisect_left(p, (p[n - 1 - n // k][0], '')) for k in [2, 5, ...
vfc_138255
{ "difficulty": "medium", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/175/B", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10\nj 10\ni 9\nh 8\ng 7\nf 6\ne 5\nd 4\nc 3\nb 2\na 1\n", "output": "10\na noob\nb noob\nc noob\nd noob\ne random\nf random\ng random\nh average\ni hardcore\nj pro\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1335/F
Solve the following coding problem using the programming language python: There is a rectangular grid of size $n \times m$. Each cell of the grid is colored black ('0') or white ('1'). The color of the cell $(i, j)$ is $c_{i, j}$. You are also given a map of directions: for each cell, there is a direction $s_{i, j}$ w...
```python import sys from collections import deque input = sys.stdin.readline t = int(input()) for _ in range(t): (n, m) = map(int, input().split()) s = [input() for i in range(n)] grid = [input() for i in range(n)] robot_cnt = 0 black_cnt = 0 graph = [-1] * (n * m) rev_graph = [[] for i in range(n * m)] for i ...
vfc_138259
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1335/F", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1 2\n01\nRL\n3 3\n001\n101\n110\nRLL\nDLD\nULL\n3 3\n000\n000\n000\nRRD\nRLD\nULL\n", "output": "2 1\n4 3\n2 2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n1 2\n01\nRL\n3 3\n000\n...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/faulty-keyboard2842/1
Solve the following coding problem using the programming language python: Geek has a unique keyboard containing only the numpad keys. ie - 1,2,3,4,5,6,7,8,9,0. But the keyboard is damaged and can only process M keys. Geek is supposed to use the keyboard to type as many natural numbers as possible starting from 1. What...
```python class Solution: def maxNatural(self, M): if M <= 9: return M M -= 9 if M <= 180: M = M // 2 return 9 + M M -= 180 if M <= 2700: M = M // 3 return 99 + M M -= 2700 if M <= 36000: M = M // 4 return 999 + M M -= 36000 if M <= 38890: M = M // 5 return 9999 + M retu...
vfc_138263
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/faulty-keyboard2842/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "M = 5", "output": "5", "type": "stdin_stdout" }, { "fn_name": null, "input": "M = 15", "output": "12", "type": "stdin_stdout" } ] }