source
stringclasses
4 values
task_type
stringclasses
1 value
in_source_id
stringlengths
0
138
problem_statement
stringlengths
219
13.2k
gold_standard_solution
stringlengths
0
413k
problem_id
stringlengths
5
10
metadata
dict
verification_info
dict
taco
verifiable_code
https://codeforces.com/problemset/problem/408/B
Solve the following coding problem using the programming language python: Once little Vasya read an article in a magazine on how to make beautiful handmade garland from colored paper. Vasya immediately went to the store and bought n colored sheets of paper, the area of each sheet is 1 square meter. The garland must c...
```python str1 = input() str2 = input() cnt1 = dict() cnt2 = dict() for x in str1: if x not in cnt1.keys(): cnt1[x] = 0 cnt1[x] += 1 for x in str2: if x not in cnt2.keys(): cnt2[x] = 0 cnt2[x] += 1 s = 0 for x in cnt2.keys(): if x not in cnt1.keys(): print(-1) exit(0) s += min(cnt1[x], cnt2[x]) print(s) ...
vfc_143662
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/408/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "aaabbac\naabbccac\n", "output": "6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "a\nz\n", "output": "-1", "type": "stdin_stdout" }, { "fn_name": null, "in...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/check-if-a-number-can-be-expressed-as-xy1606/1
Solve the following coding problem using the programming language python: Given a positive integer N, find if it can be expressed as x^{y} where y > 1 and x > 0 and x and y both are both integers. Example 1: Input: N = 8 Output: 1 Explanation: 8 can be expressed as 2^{3}. Example 2: Input: N = 7 Output: 0 Explan...
```python class Solution: def checkPower(ob, N): if N <= 1: return 1 n = 2 while n <= 125 ** 0.5: t = n * n while t <= N: if t == N: return 1 t = t * n n += 1 return 0 ```
vfc_143666
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/check-if-a-number-can-be-expressed-as-xy1606/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 8", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "N = 7", "output": "0", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: problem One day, Sosusa, who loves prime numbers, was playing with the pair $ (p, q) $, where $ p + q $ is a prime number. Suddenly, Sosusa wondered how many of these pairs were prime numbers with $ p $ and $ q $ both less than or equal to $ N ...
```python import math N = int(input()) P = [True for x in range(N + 3)] P[0] = False P[1] = False for i in range(2, int(math.sqrt(N + 3)) + 1): if P[i]: for j in range(i * 2, N + 3, i): P[j] = False count = 0 for q in range(3, N + 1): if P[q] and P[2 + q]: count += 2 print(count) ```
vfc_143667
{ "difficulty": "unknown_difficulty", "memory_limit": "268.435456 megabytes", "memory_limit_bytes": null, "problem_url": null, "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4", "outp...
taco
verifiable_code
https://www.codechef.com/RC122020/problems/RECNDROT
Solve the following coding problem using the programming language python: Chef has a sequence $A_1, A_2, \ldots, A_N$. For a positive integer $M$, sequence $B$ is defined as $B = A*M$ that is, appending $A$ exactly $M$ times. For example, If $A = [1, 2]$ and $M = 3$, then $B = A*M = [1, 2, 1, 2, 1, 2]$ You have to hel...
```python def mForMaxSeq(arr, n): eim = dict() for i in range(n): if arr[i] in eim: eim[arr[i]].append(i) else: eim[arr[i]] = [i] keys = sorted(eim.keys()) connected = False count = 0 pI = -1 nKeys = len(keys) for i in range(nKeys - 1): if not connected: pI = eim[keys[i]][0] for idx in eim[key...
vfc_143671
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/RC122020/problems/RECNDROT", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n2\n2 1\n2\n1 2\n5\n1 3 2 1 2\n", "output": "2\n1\n2\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1675/A
Solve the following coding problem using the programming language python: In the pet store on sale there are: $a$ packs of dog food; $b$ packs of cat food; $c$ packs of universal food (such food is suitable for both dogs and cats). Polycarp has $x$ dogs and $y$ cats. Is it possible that he will be able to buy food...
```python import sys input = sys.stdin.readline def inp(): return int(input()) def inlt(): return list(map(int, input().split())) def insr(): s = input() return list(s[:len(s) - 1]) def invr(): return map(int, input().split()) t = inp() for _ in range(t): (a, b, c, x, y) = inlt() x -= a y -= b if x > 0 and...
vfc_143675
{ "difficulty": "easy", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1675/A", "time_limit": "1 second" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7\n1 1 4 2 3\n0 0 0 0 0\n5 5 0 4 6\n1 1 1 1 1\n50000000 50000000 100000000 100000000 100000000\n0 0 0 100000000 100000000\n1 3 2 2 5\n", "output": "YES\nYES\nNO\nYES\nYES\nNO\nNO\n", "type": "stdin_stdout" }, { ...
taco
verifiable_code
https://codeforces.com/problemset/problem/630/B
Solve the following coding problem using the programming language python: The city administration of IT City decided to fix up a symbol of scientific and technical progress in the city's main square, namely an indicator board that shows the effect of Moore's law in real time. Moore's law is the observation that the n...
```python (a, b) = map(int, input().split()) y = b // (60 * 60 * 24 * 30 * 24) print(a * pow(1.000000011, b)) ```
vfc_143679
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/630/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1000 1000000\n", "output": "1011.060722383550382782399454922040\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1000 0\n", "output": "1000\n", "type": "stdin_stdout" }, ...
taco
verifiable_code
Solve the following coding problem using the programming language python: Golu loves prime numbers . He wants to do something new with prime numbers. So Molu gives him a number and asks him to minmum number of prime numbers required such that their sum is equal to given number. This task is very diffcult for Golu so h...
```python import math primes = [] def primeSieve(sieveSize): sieve = [True] * sieveSize sieve[0] = False sieve[1] = False for i in range(2, int(math.sqrt(sieveSize)) + 1): pointer = i * 2 while pointer < sieveSize: sieve[pointer] = False pointer += i for i in range(sieveSize): if sieve[i] == True: ...
vfc_143683
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10\n43\n469\n336\n502\n171\n726\n480\n360\n964\n466", "output": "1\n2\n2\n1\n1\n2\n2\n2\n2\n2", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n43\n5541\n6336\n646\n6243\n2798\n5016\n3504\...
taco
verifiable_code
https://www.codechef.com/LTIME29/problems/FSTSQ
Solve the following coding problem using the programming language python: A squarer is a simple and convenient device. You give it some positive integer X and it calculates its square. Leha is implementing a module of this device which is responsible for squaring the numbers consisting of multiple repetitions of one d...
```python val = 10 ** 9 + 7 def MOD(a, b): aans = a ans = 1 while b > 0: ans = ans * aans % val aans = aans * aans % val b /= 2 return ans % val for i in range(eval(input())): (n, d) = list(map(int, input().split())) a = int(str(d) * n) sqr = str(a * a) ans = 0 count = 0 for ii in sqr: ans = ans + in...
vfc_143687
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/LTIME29/problems/FSTSQ", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1 4\n3 6\n3 5\n", "output": "139\n40079781\n32745632\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/988/D
Solve the following coding problem using the programming language python: There are $n$ distinct points on a coordinate line, the coordinate of $i$-th point equals to $x_i$. Choose a subset of the given set of points such that the distance between each pair of points in a subset is an integral power of two. It is nece...
```python n = int(input()) l = list(map(int, input().split())) s = set(l) ans = [l[0]] for i in l: j = 1 while j < int(2000000000.0): if i + j in s and i + 2 * j in s: print('3') print(i, i + j, i + 2 * j) quit() elif i + j in s: ans = [i, i + j] j *= 2 print(len(ans)) for i in ans: print(i, end=' ...
vfc_143691
{ "difficulty": "medium_hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/988/D", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n3 5 4 7 10 12\n", "output": "3\n3 4 5 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n-1 2 5 8 11\n", "output": "1\n-1 \n", "type": "stdin_stdout" }, { "fn...
taco
verifiable_code
https://codeforces.com/problemset/problem/24/D
Solve the following coding problem using the programming language python: You received as a gift a very clever robot walking on a rectangular board. Unfortunately, you understood that it is broken and behaves rather strangely (randomly). The board consists of N rows and M columns of cells. The robot is initially at so...
```python (n, m) = (int(s) for s in input().split()) (i, j) = (int(s) for s in input().split()) def find(n, m, i, j): if i == n: return 0 if m == 1: return 2 * (n - i) (e, a, b) = ([0.0] * m, [0] * m, [0] * m) for l in range(n - 1, 0, -1): (a[0], b[0]) = (0.5, 0.5 * (3 + e[0])) for k in range(1, m - 1): ...
vfc_143695
{ "difficulty": "very_hard", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/24/D", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1000 1\n777 1\n", "output": "446.0000000000", "type": "stdin_stdout" }, { "fn_name": null, "input": "126 125\n115 22\n", "output": "43.9999127943", "type": "stdin_stdout" }, { ...
taco
verifiable_code
https://codeforces.com/problemset/problem/959/E
Solve the following coding problem using the programming language python: Ehab is interested in the bitwise-xor operation and the special graphs. Mahmoud gave him a problem that combines both. He has a complete graph consisting of n vertices numbered from 0 to n - 1. For all 0 ≤ u < v < n, vertex u and vertex v are co...
```python a = 0 n = int(input()) - 1 for i in range(40): k = 1 << i a += (n + k) // (k * 2) * k print(a) ```
vfc_143700
{ "difficulty": "hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/959/E", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n", "output": "4", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n", "output": "21", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n", "...
taco
verifiable_code
https://codeforces.com/problemset/problem/549/G
Solve the following coding problem using the programming language python: Do you like summer? Residents of Berland do. They especially love eating ice cream in the hot summer. So this summer day a large queue of n Berland residents lined up in front of the ice cream stall. We know that each of them has a certain amoun...
```python import sys nLine = int(input()) nMoney = list(map(int, input().split())) invariante = [] for i in range(len(nMoney)): invariante.append(nMoney[i] + i) invariante.sort() res = [0] * nLine for i in range(nLine): res[i] = invariante[i] - i for i in range(nLine - 1): if res[i] > res[i + 1]: print(':(') ret...
vfc_143704
{ "difficulty": "hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/549/G", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n11 8\n", "output": "9 10 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n10 9 7 10 6\n", "output": ":(\n", "type": "stdin_stdout" }, { "fn_name": null, ...
taco
verifiable_code
https://codeforces.com/problemset/problem/1622/C
Solve the following coding problem using the programming language python: You are given an integer array $a_1, a_2, \dots, a_n$ and integer $k$. In one step you can either choose some index $i$ and decrease $a_i$ by one (make $a_i = a_i - 1$); or choose two indices $i$ and $j$ and set $a_i$ equal to $a_j$ (make $a_...
```python from math import ceil from sys import stdin input = stdin.readline for _ in range(int(input())): (n, k) = map(int, input().split()) l = sorted(map(int, input().split()), reverse=True) (s, pref) = (sum(l), 0) ans = s - k for i in range(n - 1): pref += l[i] extra = s - pref + l[-1] * (i + 1) - k diff...
vfc_143709
{ "difficulty": "medium_hard", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1622/C", "time_limit": "2 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n1 10\n20\n2 69\n6 9\n7 8\n1 2 1 3 1 2 1\n10 1\n1 2 3 1 2 6 1 6 8 10\n", "output": "10\n0\n2\n7\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n174 243\n7 7 1 5 9 8 7 5 8 6 10 4 9 3 5...
taco
verifiable_code
Solve the following coding problem using the programming language python: Estimating the Flood Risk Mr. Boat is the owner of a vast extent of land. As many typhoons have struck Japan this year, he became concerned of flood risk of his estate and he wants to know the average altitude of his land. The land is too vast ...
```python import os import sys def main(): (W, D, N) = read_ints() M = [tuple(read_ints()) for _ in range(N)] ans = solve(W, D, N, M) if ans is None: print('No') else: print(ans) def solve(W, D, N, M): INF = 999 H = [[INF] * W for _ in range(D)] hmap = {} for h in range(-210, 101): hmap[h] = set() for...
vfc_143713
{ "difficulty": "unknown_difficulty", "memory_limit": "268.435456 megabytes", "memory_limit_bytes": null, "problem_url": null, "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 4 2\n2 1 10\n5 4 3", "output": "No\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 5 2\n1 1 10\n5 4 3", "output": "150\n", "type": "stdin_stdout" }, { "fn_nam...
taco
verifiable_code
https://atcoder.jp/contests/abc085/tasks/abc085_b
Solve the following coding problem using the programming language python: An X-layered kagami mochi (X ≥ 1) is a pile of X round mochi (rice cake) stacked vertically where each mochi (except the bottom one) has a smaller diameter than that of the mochi directly below it. For example, if you stack three mochi with diam...
```python n = int(input()) print(len(set((int(input()) for i in range(n))))) ```
vfc_143718
{ "difficulty": "easy", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://atcoder.jp/contests/abc085/tasks/abc085_b", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n10\n8\n8\n6\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n15\n15\n15\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, ...
taco
verifiable_code
https://codeforces.com/problemset/problem/378/C
Solve the following coding problem using the programming language python: Pavel loves grid mazes. A grid maze is an n × m rectangle maze where each cell is either empty, or is a wall. You can go from one cell to another only if both cells are empty and have a common side. Pavel drew a grid maze with all empty cells f...
```python import random, math, sys from copy import deepcopy as dc from bisect import bisect_left, bisect_right from collections import Counter input = sys.stdin.readline def input_test(): (n, m, k) = map(int, input().strip().split(' ')) grid = [] for i in range(n): grid.append(list(input().strip())) def dfsUti...
vfc_143722
{ "difficulty": "medium_hard", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/378/C", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "19 20 196\n###.....##.#..#..##.\n####............##..\n###....#..#.#....#.#\n##....###......#...#\n.####...#.....#.##..\n.###......#...#.#.#.\n...##.#...#..#..#...\n.....#.....#..#....#\n.#.....##..#........\n.##....#......#....#\n...
taco
verifiable_code
https://codeforces.com/problemset/problem/414/A
Solve the following coding problem using the programming language python: It's holiday. Mashmokh and his boss, Bimokh, are playing a game invented by Mashmokh. In this game Mashmokh writes sequence of n distinct integers on the board. Then Bimokh makes several (possibly zero) moves. On the first move he removes the ...
```python from __future__ import division, print_function import os import sys from io import BytesIO, IOBase def main(): (n, k) = [int(x) for x in input().split()] x = k - (n // 2 - 1) if x < 1 or (n < 2 and k > 0): print(-1) return sequence = [0] * n sequence[0] = x if n > 1: sequence[1] = 2 * x if n >=...
vfc_143726
{ "difficulty": "medium", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/414/A", "time_limit": "1.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 1257\n", "output": "1256 2512 2513 2514 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "25095 2372924\n", "output": "2360378 4720756 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 ...
taco
verifiable_code
Solve the following coding problem using the programming language python: For integers b (b \geq 2) and n (n \geq 1), let the function f(b,n) be defined as follows: * f(b,n) = n, when n < b * f(b,n) = f(b,\,{\rm floor}(n / b)) + (n \ {\rm mod} \ b), when n \geq b Here, {\rm floor}(n / b) denotes the largest intege...
```python n = int(input()) s = int(input()) b_ans = 1 if n == s: b_ans = n + 1 if b_ans == 1: for b in range(2, int(n ** 0.5) + 1): nn = n st = [] while nn > 0: st.append(nn % b) nn = (nn - st[-1]) / b if sum(st) == s: b_ans = b break if b_ans == 1: for p in range(int(n ** 0.5), 0, -1): b = (n ...
vfc_143730
{ "difficulty": "unknown_difficulty", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": null, "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "87654\n60", "output": "40\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "87654\n178", "output": "1152\n", "type": "stdin_stdout" }, { "fn_name": null, "inp...
taco
verifiable_code
https://www.hackerrank.com/challenges/coolguy-and-two-subsequences/problem
Solve the following coding problem using the programming language python: Coolguy gives you a simple problem. Given a $1$-indexed array, $\mbox{A}$, containing $N$ elements, what will $\textit{and}$ be after this pseudocode is implemented and executed? Print $and\%(10^9+7)$. //f(a, b) is a function that returns the m...
```python def smart(): left = [0] * (n + 2) right = [0] * (n + 2) singles = pairs = 0 ans = 0 def remove(k): nonlocal singles, pairs s = k * (k + 1) // 2 singles -= s pairs -= (k + 2) * (k + 1) * k * (k - 1) // 24 + s * singles def add(k): nonlocal singles, pairs s = k * (k + 1) // 2 pairs += (k +...
vfc_143734
{ "difficulty": "hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.hackerrank.com/challenges/coolguy-and-two-subsequences/problem", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n3 2 1\n", "output": "6\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/XDS
Solve the following coding problem using the programming language python: Problem description. Winston and Royce love sharing memes with each other. They express the amount of seconds they laughed ar a meme as the number of ‘XD’ subsequences in their messages. Being optimization freaks, they wanted to find the string ...
```python import sys from math import * t = int(input()) while t: l = [] f = [] s = '' n = int(input()) if sqrt(n) % 1.0 == 0: y = sqrt(n) for x in range(int(y)): l.append('X') for x in range(int(y)): l.append('D') s = ''.join(l) else: count = 0 for x in range(1, int(sqrt(n)) + 3): if x ** 2 ...
vfc_143738
{ "difficulty": "medium_hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/XDS", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n9\n", "output": "XXXDDD\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: My flatmate, Sayan, once invited all his relatives and friends from all over the city to join him on his birthday party. He is also famous for boasting that all his friends and relatives belong to "proper" families. Now, he appointed a gaurd to ...
```python def isSumInSubset(inputSet, n, m): T = [] for i in range(0, n+1): col = [] for j in range(0, m+1): col.append(False) T.append(col) for i in range(0,n+1): T[i][0] = True for i in range(1,m+1): T[0][i] = False for i in range(1,n+1): for j in range(1,m+1): if j < inputSet[i-1]: T[i][j...
vfc_143742
{ "difficulty": "hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n321 920\n1 2 3 4 5 6 7 8 9 10 11 13 14 15 18 19 20 21 22 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 ...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/linked-list-that-is-sorted-alternatingly/1
Solve the following coding problem using the programming language python: Given a Linked list of size N, the list is in alternating ascending and descending orders. Sort the given linked list in non-decreasing order. Example 1: Input: LinkedList: 1->9->2->8->3->7 Output: 1 2 3 7 8 9 Explanation: After sorting the gi...
```python def sort(h1): l = [] temp1 = h1 while temp1: l.append(temp1.data) temp1 = temp1.next j = 0 l.sort() temp = h1 while temp: temp.data = l[j] j += 1 temp = temp.next return h1 ```
vfc_143746
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/linked-list-that-is-sorted-alternatingly/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "LinkedList:1->9->2->8->3->7", "output": "1 2 3 7 8 9", "type": "stdin_stdout" }, { "fn_name": null, "input": "LinkedList:13->99->21->80->50", "output": "13 21 50 80 99", "type": "stdin_st...
taco
verifiable_code
https://codeforces.com/problemset/problem/553/B
Solve the following coding problem using the programming language python: Let's define the permutation of length n as an array p = [p1, p2, ..., pn] consisting of n distinct integers from range from 1 to n. We say that this permutation maps value 1 into the value p1, value 2 into the value p2 and so on. Kyota Ootori ...
```python (n, k) = list(map(int, input().split())) fib = [0] * (n + 1) fib[0] = 1 fib[1] = 1 res = [0] * n for i in range(2, n): fib[i] = fib[i - 1] + fib[i - 2] idx = 0 while idx < n: if k <= fib[n - idx - 1]: res[idx] = idx + 1 idx += 1 else: k -= fib[n - idx - 1] res[idx] = idx + 2 res[idx + 1] = idx + ...
vfc_143747
{ "difficulty": "hard", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/553/B", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "20 491\n", "output": "1 2 3 4 5 6 8 7 9 11 10 12 14 13 15 16 18 17 19 20 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "35 706065\n", "output": "1 2 3 4 5 6 8 7 9 11 10 13 12 15 14 1...
taco
verifiable_code
Solve the following coding problem using the programming language python: You are given a N x N square matrix of integers where each cell represents the amount of gold in it. You need to travel from the top left cell to the bottom right cell, and back, maximizing the amount of gold you collect as you pass by the cell ...
```python def main(): n = eval(input()) w = [] v = [] for i in range(n): st = input() spl = st.split() w.append([]) v.append([]) for j in range(n): w[i].append(int(spl[j])) v[i].append(-999999999) q = [] s = 0 q.append((0,1)) v[0][0] = w[0][0] for i in q: x, y = i[0] , i...
vfc_143755
{ "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\n5 11 4 6\n3 2 10 3\n1 3 1 3\n4 2 8 8", "output": "67", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n5 11 4 60\n3 2 10 3\n10 13 1 3\n4 2 8 8", "output": "135", "type": "std...
taco
verifiable_code
https://codeforces.com/problemset/problem/1406/A
Solve the following coding problem using the programming language python: Given a set of integers (it can contain equal elements). You have to split it into two subsets $A$ and $B$ (both of them can contain equal elements or be empty). You have to maximize the value of $mex(A)+mex(B)$. Here $mex$ of a set denotes th...
```python for _ in range(int(input())): n = int(input()) a = sorted(list(map(int, input().split()))) (A, B) = (0, 0) for i in a: if A == i: A += 1 elif B == i: B += 1 print(A + B) ```
vfc_143759
{ "difficulty": "easy", "memory_limit": "512 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1406/A", "time_limit": "1 second" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n6\n0 2 1 5 0 1\n3\n0 1 2\n4\n0 2 0 1\n6\n1 2 3 4 5 6\n", "output": "5\n3\n4\n0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "15\n1\n0\n1\n1\n2\n0 0\n2\n0 1\n2\n1 1\n2\n0 2\n2\n1 2\n3\...
taco
verifiable_code
https://www.codechef.com/problems/PREFPERM
Solve the following coding problem using the programming language python: You are given an array A of length K. Find any permutation P of length N such that only the prefixes of length A_{i} (1 ≤ i ≤ K) form a permutation. Under the given constraints, it is guaranteed that there exists at least one permutation which ...
```python for _ in range(int(input())): (n, k) = map(int, input().split()) a = list(map(int, input().split())) j = 1 pre = 0 for i in a: for k in range(i, pre, -1): print(k, end=' ') pre = i print() ```
vfc_143763
{ "difficulty": "medium", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/PREFPERM", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n8 4\n3 6 7 8\n7 1\n7\n5 5\n1 2 3 4 5\n", "output": "2 3 1 6 4 5 7 8\n4 6 1 5 2 7 3\n1 2 3 4 5", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: curtain Summer is coming soon. You decide to redecorate your room for the summer. It is expected that the sun will be very strong this summer, and it will be a difficult season for you who are not good at dazzling. So you thought about installi...
```python from collections import defaultdict INF = 10 ** 9 while 1: N = int(input()) if N == 0: break P = [list(map(int, input().split())) for i in range(N)] S = defaultdict(list) X = set() x0 = y0 = INF x1 = y1 = -INF for i in range(4): (x, y) = map(int, input().split()) x0 = min(x0, x) x1 = max(x1, x...
vfc_143767
{ "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": "4\n0 0\n10 0\n10 10\n0 10\n0 0\n5 0\n5 10\n0 10\n6\n0 0\n10 0\n10 5\n5 5\n5 10\n0 10\n2 0\n8 0\n8 10\n2 10\n12\n1 1\n1 3\n-1 3\n-1 1\n-3 1\n-3 -1\n-1 -1\n-1 -3\n1 -3\n1 -1\n3 -1\n3 1\n2 2\n-2 2\n-2 -2\n2 -2\n4\n20000 20000\n-20000 ...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/charul-and-vessels0209/1
Solve the following coding problem using the programming language python: Charul has been given a task by Ishaan. He challenges him to fill a large container of capacity K liters. Charul has N vessels with him with different capacities. The capacities of the vessels are given by an array A. The condition is that the c...
```python def vessel(arr, n, k): store = set([k]) for item in arr: temp = set() for num in store: while num - item >= 0: num -= item temp.add(num) if 0 in temp: return True store.update(temp) return False ```
vfc_143771
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/charul-and-vessels0209/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": "vessel", "input": "arr[ ] = {6, 3, 4, 2, 1} and K = 20", "output": "1", "type": "function_call" }, { "fn_name": "vessel", "input": "arr[] = {2, 4, 3} and K = 15", "output": "1", "type": "function_call" ...
taco
verifiable_code
Solve the following coding problem using the programming language python: Description In 200X, the mysterious circle K, which operates at K University, announced K Poker, a new game they created on the 4th floor of K East during the university's cultural festival. At first glance, this game is normal poker, but it is...
```python from collections import Counter def parse_card(card): suit = card[-1] num = card[:-1] if num == 'A': num = 1 elif num == 'K': num = 13 elif num == 'Q': num = 12 elif num == 'J': num = 11 elif num == 'T': num = 10 else: num = int(num) return (num, suit) def parse_hand(hand): return sort...
vfc_143772
{ "difficulty": "unknown_difficulty", "memory_limit": "134.217728 megabytes", "memory_limit_bytes": null, "problem_url": null, "time_limit": "8.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n0 1 0 1 0 0 0 0 0 1 0 0 0\n1 0 0 0 0 0 1 0 0 1 0 0 2\n0 1 1 0 1 1 1 0 0 0 0 5 5\n3 1 1 1 0 1 0 0 1 0 3 0 2\n1 0 2 4 5 10 20 50 100\n7H 6H 2H 5H 3H\n9S 9C 9H 8H 8D\nKS KH QH JD TS\n10\n1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1...
taco
verifiable_code
https://codeforces.com/problemset/problem/1433/E
Solve the following coding problem using the programming language python: One day, $n$ people ($n$ is an even number) met on a plaza and made two round dances, each round dance consists of exactly $\frac{n}{2}$ people. Your task is to find the number of ways $n$ people can make two round dances if each round dance con...
```python import math n = int(input()) half = n // 2 rotations = half res = math.factorial(n - 1) // half print(res) ```
vfc_143776
{ "difficulty": "easy", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1433/E", "time_limit": "1 second" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "8\n", ...
taco
verifiable_code
https://www.hackerrank.com/challenges/itertools-combinations/problem
Solve the following coding problem using the programming language python: itertools.combinations(iterable, r) This tool returns the $\textbf{r}$ length subsequences of elements from the input iterable. Combinations are emitted in lexicographic sorted order. So, if the input iterable is sorted, the combination tuple...
```python from itertools import combinations (S, l) = input().split(' ') l = int(l) S = sorted(S) for i in range(l): C = list(combinations(S, i + 1)) for c in C: print(''.join(c)) ```
vfc_143780
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.hackerrank.com/challenges/itertools-combinations/problem", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "HACK 2\n", "output": "A\nC\nH\nK\nAC\nAH\nAK\nCH\nCK\nHK\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: Takahashi has N balls. Initially, an integer A_i is written on the i-th ball. He would like to rewrite the integer on some balls so that there are at most K different integers written on the N balls. Find the minimum number of balls that Takah...
```python from collections import Counter (n, k) = map(int, input().split()) xs = map(int, input().split()) ctr = Counter(xs) cnts = sorted(ctr.values()) ans = n - sum(cnts[-k:]) print(ans) ```
vfc_143785
{ "difficulty": "unknown_difficulty", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": null, "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 4\n0 1 2 2", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10 3\n5 1 3 2 4 1 2 2 3 4", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": nu...
taco
verifiable_code
Solve the following coding problem using the programming language python: For an n \times n grid, let (r, c) denote the square at the (r+1)-th row from the top and the (c+1)-th column from the left. A good coloring of this grid using K colors is a coloring that satisfies the following: * Each square is painted in one...
```python def solve(k): if k == 1: print(1) print(1) return n = ((k - 1) // 4 + 1) * 2 ans = [[0] * n for _ in [0] * n] dub = 2 * (k - n) for m in range(n * 2): l = m + 1 if m < dub else dub + (m - dub) // 2 + 1 i = m % 2 j = (m // 2 + m % 2) % n for _ in range(n // 2): ans[i][j] = l i = (i + 2...
vfc_143789
{ "difficulty": "unknown_difficulty", "memory_limit": "1024.0 megabytes", "memory_limit_bytes": null, "problem_url": null, "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4", "output": "2\n1 2 \n4 3 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "0", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "7", ...
taco
verifiable_code
https://www.hackerrank.com/challenges/sherlock-and-cost/problem
Solve the following coding problem using the programming language python: In this challenge, you will be given an array $\mbox{B}$ and must determine an array $\mbox{A}$. There is a special rule: For all $\boldsymbol{i}$, $A[i]\leq B[i]$. That is, $A[i]$ can be any number you choose such that $1\leq A[i]\leq B[i]$....
```python def cost(B): (c0, c1) = (0, 0) for i in range(1, len(B)): (c0, c1) = (max(c0, c1 + B[i - 1] - 1), max(c0 + B[i] - 1, c1 + abs(B[i] - B[i - 1]))) return max(c0, c1) T = int(input()) for _ in range(T): N = int(input()) B = [int(_) for _ in input().strip().split()] print(cost(B)) ```
vfc_143794
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.hackerrank.com/challenges/sherlock-and-cost/problem", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n5\n10 1 10 1 10\n", "output": "36\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/430/D
Solve the following coding problem using the programming language python: Summer is coming! It's time for Iahub and Iahubina to work out, as they both want to look hot at the beach. The gym where they go is a matrix a with n lines and m columns. Let number a[i][j] represents the calories burned by performing workout a...
```python (n, m) = map(int, input().split()) a = [] for i in range(n): a.append(list(map(int, input().split()))) dpa = [[[0, 0] for i in range(m + 2)] for i in range(n + 2)] dpb = [[[0, 0] for i in range(m + 2)] for i in range(n + 2)] ans = 0 for i in range(1, n + 1): for j in range(1, m + 1): dpa[i][j][0] = max(dp...
vfc_143798
{ "difficulty": "medium_hard", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/430/D", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 3\n0 0 0\n0 10000 0\n0 0 0\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 3\n1 10 1\n1 10 1\n1 10 1\n", "output": "26\n", "type": "stdin_stdout" }, ...
taco
verifiable_code
https://www.codechef.com/problems/PCJ18G
Solve the following coding problem using the programming language python: Chef's pizza is the tastiest pizza to exist, and the reason for that is his special, juicy homegrown tomatoes. Tomatoes can be grown in rectangular patches of any side lengths. However, Chef only has a limited amount of land. Consider the enti...
```python import numpy as np import math import sys import time MOD = 1000000007 def stack(n, x, l): return x * l * (l + 1) * (x + 2 * n + 1) // 4 % MOD def heightsGen(n): (lengths, heights) = ([1], [n]) for i in range(2, int(math.sqrt(n)) + 1): h = n // i if h == heights[-1]: lengths[-1] == i else: he...
vfc_143802
{ "difficulty": "very_hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/PCJ18G", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n4\n10000000000\n", "output": "23\n227374950\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/676/E
Solve the following coding problem using the programming language python: 100 years have passed since the last victory of the man versus computer in Go. Technologies made a huge step forward and robots conquered the Earth! It's time for the final fight between human and robot that will decide the faith of the planet. ...
```python (n, k) = map(int, input().split()) a = [] for i in range(n + 1): a.extend(input().split()) if k == 0: if a[0] == '0': print('Yes') elif a[0] == '?' and (n - a.count('?')) % 2 == 0: print('Yes') else: print('No') elif '?' in a: if n % 2 == 0: print('No') else: print('Yes') else: a = list(map(i...
vfc_143806
{ "difficulty": "very_hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/676/E", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 2\n-1\n?\n", "output": "Yes\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 100\n-10000\n0\n1\n", "output": "Yes", "type": "stdin_stdout" }, { "fn_name": null...
taco
verifiable_code
Solve the following coding problem using the programming language python: B: Pivots problem Given a permutation of length N, a_1, a_2, ..., a_N, which is a permutation of integers from 1 to N. Also, Q queries are given in order for this permutation. In the i-th query, you have to do the following: * The value q_i (...
```python def inpl(): return list(map(int, input().split())) (N, _) = inpl() A = inpl() if N == 1: print(*A) exit() L = [0] * (N + 1) R = [0] * (N + 1) for i in range(N - 1): R[A[i]] = A[i + 1] L[A[i + 1]] = A[i] lm = A[0] rm = A[-1] for q in inpl(): if q == rm: l = L[q] R[l] = 0 L[q] = 0 R[q] = lm L[lm...
vfc_143810
{ "difficulty": "unknown_difficulty", "memory_limit": "268.435456 megabytes", "memory_limit_bytes": null, "problem_url": null, "time_limit": "1.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 2\n1 5 3 2 4\n5 3", "output": "2 4 5 1 3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 0\n1 5 3 2 4\n5 3", "output": "1 5 3 2 4\n", "type": "stdin_stdout" }, { ...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/pattern-searching5231/1
Solve the following coding problem using the programming language python: Given a string str and a pattern pat. You need to check whether the pattern is present or not in the given string. Example 1:- Input: 2 abcdefh bcd axzy xy Output: Present Not present Your task: You need to complete the function searchPattern...
```python def searchPattern(st, pat): if pat in st: return True else: return False ```
vfc_143814
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/pattern-searching5231/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": "searchPattern", "input": "2\r\nabcdefh\r\nbcd\r\naxzy\r\nxy", "output": "Present\nNot present", "type": "function_call" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: Example Input 3 NNN NNN NNN Output Taro The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python from collections import deque import sys sys.setrecursionlimit(10 ** 6) readline = sys.stdin.readline write = sys.stdout.write def solve(): N = int(readline()) G = [[] for i in range(N)] for i in range(N): (*vs,) = readline() for j in range(N): if vs[j] == 'Y': G[i].append(j) d = 0 C = [0, 0]...
vfc_143815
{ "difficulty": "unknown_difficulty", "memory_limit": "134.217728 megabytes", "memory_limit_bytes": null, "problem_url": null, "time_limit": "8.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\nNNN\nNNO\nNNN", "output": "Taro\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\nNMN\nNNO\nNNN", "output": "Taro\n", "type": "stdin_stdout" }, { "fn_name": n...
taco
verifiable_code
https://www.codechef.com/ARYS2020/problems/BDYGFT
Solve the following coding problem using the programming language python: Vishal Wants to buy 2 gifts for his best friend whose name is Annabelle(her age is 20), So they both went for shopping in a store. But Annabelle gave, Vishal a condition that she will accept this gifts only when the total price of the gifts is t...
```python test = int(input()) ANS = list() for i in range(test): n = int(input()) items = sorted(list(map(int, input().split()))) c = 1 for j in range(len(items)): if items[j] < 2000: t = 2000 - items[j] if t in items[j + 1:]: ANS.append('Accepted') c = 2 break else: pass else: break...
vfc_143820
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/ARYS2020/problems/BDYGFT", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n5\n10 2 1000 50 1000\n", "output": "Accepted\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.hackerrank.com/challenges/prime-digit-sums/problem
Solve the following coding problem using the programming language python: Chloe is fascinated by prime numbers. She came across the number $283002$ on a sign and, though the number is not prime, found some primes hiding in it by using the following rules: Every three consecutive digits sum to a prime: $\underbrace{...
```python from itertools import product from collections import defaultdict import sys M = 1000000007 p = set([2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43]) def good(a, b, c, d, e): if not a + b + c in p: return False if not b + c + d in p: return False if not c + d + e in p: return False if not a + b...
vfc_143824
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.hackerrank.com/challenges/prime-digit-sums/problem", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n6\n", "output": "95\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: Rng is baking cookies. Initially, he can bake one cookie per second. He can also eat the cookies baked by himself. When there are x cookies not yet eaten, he can choose to eat all those cookies. After he finishes eating those cookies, the numb...
```python (N, A) = map(int, input().split()) ans = N for i in range(-10, 10): x = int(N ** 0.5) + i if x > 0: test = x + A + (N - 1) // x + 1 ans = min(ans, test) for n in range(2, 41): for i in range(2 * n, int(N ** (1 / n)) + 1000): test = i + n * A q = i // n r = i % n prod = pow(q, n - r) * pow(q + 1...
vfc_143828
{ "difficulty": "unknown_difficulty", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": null, "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1000000000000 1000000100000", "output": "1000000000000\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "9 1", "output": "7\n", "type": "stdin_stdout" }, { "fn_name...
taco
verifiable_code
Solve the following coding problem using the programming language python: The palindrome is a string that can be read the same way from left to right and from right to left. For example, strings "hanah", "2332" are palindromes, however the string "rahul" is not a palindrome. We define "Easy String" if it has an even...
```python ''' # Read input from stdin and provide input before running code name = raw_input('What is your name?\n') print 'Hi, %s.' % name ''' n = int(input()) i = 0 while (i < n): tc = int(input()) if (tc % 2 == 0): print(tc) else: print(tc - 1) i = i + 1 ```
vfc_143832
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n2\n4\n", "output": "2\n4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10000\n41\n18467\n6334\n26500\n19169\n15724\n11478\n29358\n26962\n24464\n5705\n28145\n23281\n16827\n9961\n491\n2...
taco
verifiable_code
https://codeforces.com/problemset/problem/1060/B
Solve the following coding problem using the programming language python: You are given a positive integer $n$. Let $S(x)$ be sum of digits in base 10 representation of $x$, for example, $S(123) = 1 + 2 + 3 = 6$, $S(0) = 0$. Your task is to find two integers $a, b$, such that $0 \leq a, b \leq n$, $a + b = n$ and $S...
```python def digisum(n): sum = 0 while n != 0: sum += n % 10 n = n // 10 return sum def give9(n): num9 = 0 while n >= 10: num9 = num9 * 10 + 9 n = n // 10 return num9 def method3(n): a = give9(n) b = n - a return digisum(a) + digisum(b) n = int(input()) print(method3(n)) ```
vfc_143836
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1060/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "35\n", "output": "17\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10000000000\n", "output": "91\n", "type": "stdin_stdout" }, { "fn_name": null, "input":...
taco
verifiable_code
https://codeforces.com/problemset/problem/582/B
Solve the following coding problem using the programming language python: You are given an array of positive integers a_1, a_2, ..., a_{n} × T of length n × T. We know that for any i > n it is true that a_{i} = a_{i} - n. Find the length of the longest non-decreasing sequence of the given array. -----Input----- The...
```python f = lambda : list(map(int, input().split())) (n, m) = f() t = list(f()) s = [0] * 301 d = s[:] for i in t: d[i] += 1 for i in t * min(m, 2 * n): s[i] = max(s[:i + 1]) + 1 print(max(s) + max((m - n * 2) * max(d), 0)) ```
vfc_143840
{ "difficulty": "hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/582/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 3\n3 1 4 2\n", "output": "5\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1000\n42\n", "output": "1000\n", "type": "stdin_stdout" }, { "fn_name": null, ...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/mr-modulo-and-arrays2827/1
Solve the following coding problem using the programming language python: Mr. Modulo lives up to his name and is always busy taking modulo of numbers and making new problems. Now he comes up with another problem. He has an array of integers with n elements and wants to find a pair of elements {arr[i], arr[j]} such tha...
```python from bisect import bisect_left def maxModValue(arr, n): arr.sort() ans = 0 for i in range(n): for j in range(2 * arr[i], arr[i] + arr[n - 1], arr[i]): ind = bisect_left(arr, j) - 1 ans = max(ans, arr[ind] % arr[i]) return ans ```
vfc_143844
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/mr-modulo-and-arrays2827/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": "maxModValue", "input": "n=3\narr[] = {3, 4, 7}", "output": "3", "type": "function_call" }, { "fn_name": "maxModValue", "input": "n=4\narr[] = {4, 4, 4, 4}", "output": "0", "type": "function_call" } ...
taco
verifiable_code
https://www.codechef.com/problems/FRIMEET
Solve the following coding problem using the programming language python: Chef and his friend is standing on the X-axis at the points X_{1} and X_{2} respectively. Chef moves one step forward each second (that is he moves to X_{1} + 1 after the 1^{st} second, X_{1} + 2 after the 2^{nd} second, and so on), whereas hi...
```python for _ in range(int(input())): (x1, x2) = map(int, input().split()) print('YES' if x2 <= x1 else 'NO') ```
vfc_143846
{ "difficulty": "easy", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/FRIMEET", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1 1\n1 7\n7 1\n", "output": "YES\nNO\nYES", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/70/A
Solve the following coding problem using the programming language python: Fangy collects cookies. Once he decided to take a box and put cookies into it in some way. If we take a square k × k in size, divided into blocks 1 × 1 in size and paint there the main diagonal together with cells, which lie above it, then the p...
```python import math print(math.ceil(3 ** (int(input()) - 1)) % 1000003) ```
vfc_143852
{ "difficulty": "easy", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/70/A", "time_limit": "1.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "696\n", "output": "695035\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n", "output": "243\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "92...
taco
verifiable_code
https://codeforces.com/problemset/problem/909/E
Solve the following coding problem using the programming language python: You are given a program you want to execute as a set of tasks organized in a dependency graph. The dependency graph is a directed acyclic graph: each task can depend on results of one or several other tasks, and there are no directed circular de...
```python from sys import stdin from collections import deque (n, m) = [int(x) for x in stdin.readline().split()] e = [int(x) for x in stdin.readline().split()] graph = [set() for x in range(n)] reverse = [set() for x in range(n)] root = set([x for x in range(n)]) for edge in range(m): (a, b) = [int(x) for x in stdin....
vfc_143856
{ "difficulty": "hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/909/E", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 3\n0 1 0 1\n0 1\n1 2\n2 3\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 3\n1 1 1 0\n0 1\n0 2\n3 0\n", "output": "1\n", "type": "stdin_stdout" }, ...
taco
verifiable_code
https://codeforces.com/problemset/problem/797/A
Solve the following coding problem using the programming language python: Given a positive integer n, find k integers (not necessary distinct) such that all these integers are strictly greater than 1, and their product is equal to n. Input The first line contains two integers n and k (2 ≤ n ≤ 100000, 1 ≤ k ≤ 20). O...
```python from math import sqrt dic = {} def kfact(n, k): if (n, k) in dic: return dic[n, k] if k == 1: return [n] for i in range(2, int(sqrt(n)) + 1): if n % i == 0: if kfact(n // i, k - 1): result = [i] + kfact(n // i, k - 1) dic[n, k] = result return result return None def wrapper(n, k): ...
vfc_143860
{ "difficulty": "easy", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/797/A", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "15 6\n", "output": "-1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "13 3\n", "output": "-1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "355...
taco
verifiable_code
https://codeforces.com/problemset/problem/50/D
Solve the following coding problem using the programming language python: The commanding officers decided to drop a nuclear bomb on the enemy's forces. You are ordered to determine the power of the warhead that needs to be used. The enemy has N strategically important objects. Their positions are known due to the int...
```python import math n = int(input()) (k, epsilon) = list(map(int, input().split(' '))) (x0, y0) = list(map(int, input().split(' '))) epsilon /= 1000.0 l = [] for i in range(n): l.append(list(map(int, input().split(' ')))) d = sorted([(p[0] - x0) ** 2 + (p[1] - y0) ** 2 for p in l]) rmin = 0 rmax = math.sqrt(d[k - 1]...
vfc_143864
{ "difficulty": "hard", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/50/D", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n2 17\n0 0\n1 0\n35 27\n0 5\n", "output": "4.957678079335892\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "12\n10 186\n-267 -417\n-410 930\n-354 852\n-132 -613\n-342 356\n212 220\n319 ...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/longest-common-substring-value-of-two-numbers3806/1
Solve the following coding problem using the programming language python: Given two integers N and M. Find the longest common contiguous subset in binary representation of both the numbers and print its decimal value. Example 1: Input: N = 10, M = 11 Output: 5 Explanation: 10 in Binary is "1010" and 11 in Binary is "1...
```python class Solution: def longestCommon(self, N, M): d = [] e = [] while N > 0: d.append(N % 2) N //= 2 while M > 0: e.append(M % 2) M //= 2 a1 = {} for i in range(len(d)): c = 0 p = 1 s = '' for j in range(i, len(d)): s += str(d[j]) a1[s] = 1 res = 0 c2 = 0 for i...
vfc_143869
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/longest-common-substring-value-of-two-numbers3806/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 10, M = 11", "output": "5", "type": "stdin_stdout" }, { "fn_name": null, "input": "N = 8, M = 16", "output": "8", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/31/B
Solve the following coding problem using the programming language python: Email address in Berland is a string of the form A@B, where A and B are arbitrary strings consisting of small Latin letters. Bob is a system administrator in «Bersoft» company. He keeps a list of email addresses of the company's staff. This li...
```python def main(): string = input() comps = string.split('@') ans = [] if '@' not in string: print('No solution') return for i in range(len(comps)): if i == 0 or i == len(comps) - 1: if len(comps[i]) < 1: print('No solution') return elif len(comps[i]) < 2: print('No solution') return i...
vfc_143870
{ "difficulty": "medium", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/31/B", "time_limit": "0.5 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "a@mc@ks@gu@rl@gq@zq@iz@da@uq@mi@nf@zs@hi@we@ej@ke@vb@az@yz@yl@rr@gh@um@nv@qe@qq@de@dy@op@gt@vx@ak@q\n", "output": "a@m,c@k,s@g,u@r,l@g,q@z,q@i,z@d,a@u,q@m,i@n,f@z,s@h,i@w,e@e,j@k,e@v,b@a,z@y,z@y,l@r,r@g,h@u,m@n,v@q,e@q,q@d,e@...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/466faca80c3e86f13880710491c634d26abd44a7/1
Solve the following coding problem using the programming language python: Our geek loves to play with strings, Currently, he is trying to reduce the size of a string by recursively removing all the consecutive duplicate pairs. In other words, He can apply the below operations any number of times. Remove all the conse...
```python class Solution: def removePair(self, S): s = [] for i in S: if s and s[-1] == i: s.pop() else: s.append(i) if len(s) == 0: return -1 else: return ''.join(s) ```
vfc_143874
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/466faca80c3e86f13880710491c634d26abd44a7/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "aaabbaaccd", "output": "ad", "type": "stdin_stdout" }, { "fn_name": null, "input": "aaaa", "output": "Empty String", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/254/B
Solve the following coding problem using the programming language python: In 2013, the writers of Berland State University should prepare problems for n Olympiads. We will assume that the Olympiads are numbered with consecutive integers from 1 to n. For each Olympiad we know how many members of the jury must be involv...
```python (w, r) = (open('output.txt', 'w'), open('input.txt', 'r')) (s, y) = ([0] * 466, [0, 100, 131, 159, 190, 220, 251, 281, 312, 343, 373, 404, 434]) for i in range(int(r.readline())): (m, d, p, t) = map(int, r.readline().split()) x = y[m] + d s[x] -= p s[x - t] += p for i in range(465): s[i + 1] += s[i] w.wr...
vfc_143875
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/254/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n5 23 1 2\n3 13 2 3\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n12 9 2 1\n12 8 1 3\n12 8 2 2\n", "output": "3\n", "type": "stdin_stdout" }, { ...
taco
verifiable_code
https://www.codechef.com/problems/LOWSUM
Solve the following coding problem using the programming language python: Read problems statements in Russian here The Head Chef is studying the motivation and satisfaction level of his chefs . The motivation and satisfaction of a Chef can be represented as an integer . The Head Chef wants to know the N th smallest...
```python t = int(input()) for _ in range(t): (k, q) = map(int, input().split()) motivation = sorted(list(map(int, input().split()))) satisfaction = sorted(list(map(int, input().split()))) ans = [] for i in range(min(len(motivation), 10000)): for j in range(min(len(satisfaction), 10000 // (i + 1))): ans.appen...
vfc_143879
{ "difficulty": "very_hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/LOWSUM", "time_limit": "2 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n3 1\n1 2 3\n4 5 6\n4", "output": "7", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n3 1\n1 4 3\n4 5 6\n4", "output": "7\n", "type": "stdin_stdout" }, { "fn_na...
taco
verifiable_code
https://www.codechef.com/COLE2016/problems/CLBMUP
Solve the following coding problem using the programming language python: Batman is about to face Superman so he decides to prepare for the battle by upgrading his Batmobile. He manufactures multiple duplicates of his standard Batmobile each tweaked in a different way such that the maximum speed of each is never less ...
```python t = int(input()) while t: n = int(input()) ar = list(map(int, input().strip().split(' '))) print(len([x for x in ar[1:len(ar)] if ar[0] < x])) t -= 1 ```
vfc_143883
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/COLE2016/problems/CLBMUP", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n4\n1 2 3 4 5\n5\n1 10 100 1000 10000 100000\n", "output": "4\n5\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/86/A
Solve the following coding problem using the programming language python: For each positive integer n consider the integer ψ(n) which is obtained from n by replacing every digit a in the decimal notation of n with the digit (9 - a). We say that ψ(n) is the reflection of n. For example, reflection of 192 equals 807. No...
```python def ref(n): return int(''.join([str(9 - int(x)) for x in str(n)])) (l, r) = map(int, input().split()) ans = 0 ans = max(ans, ref(l) * l) ans = max(ans, ref(r) * r) cur = 5 for i in range(20): if l <= cur <= r: ans = max(ans, ref(cur) * cur) cur *= 10 print(ans) ```
vfc_143888
{ "difficulty": "medium_hard", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/86/A", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "850 629417171\n", "output": "249999999500000000\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3722 867350896\n", "output": "249999999500000000\n", "type": "stdin_stdout" ...
taco
verifiable_code
https://www.codechef.com/problems/TLG
Solve the following coding problem using the programming language python: The game of billiards involves two players knocking 3 balls around on a green baize table. Well, there is more to it, but for our purposes this is sufficient. The game consists of several rounds and in each round both players obtain a score, bas...
```python n = int(input()) p1 = [] p2 = [] (a, b) = (0, 0) for i in range(n): (s, t) = map(int, input().split(' ')) a += s b += t if a > b: p1.append(a - b) p2.append(0) else: p2.append(b - a) p1.append(0) if max(p1) > max(p2): print('1', max(p1), end=' ') else: print('2', max(p2), end=' ') ```
vfc_143892
{ "difficulty": "easy", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/TLG", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n140 82\n89 134\n90 110\n112 106\n88 90\n", "output": "1 58\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n140 82\n89 134\n90 110\n177 106\n88 90", "output": "1 64\n", "t...
taco
verifiable_code
Solve the following coding problem using the programming language python: Aka Beko, trying to escape from 40 bandits, got lost in the city of A. Aka Beko wants to go to City B, where the new hideout is, but the map has been stolen by a bandit. Kobborg, one of the thieves, sympathized with Aka Beko and felt sorry for ...
```python import sys def solve(s): path = {'A': {'0': 'X', '1': 'Y'}, 'B': {'0': 'Y', '1': 'X'}, 'W': {'0': 'B', '1': 'Y'}, 'X': {'0': None, '1': 'Z'}, 'Y': {'0': 'X', '1': None}, 'Z': {'0': 'W', '1': 'B'}} pos = 'A' for ch in s: pos = path[pos][ch] if pos is None: return 'No' return 'Yes' if pos == 'B' els...
vfc_143896
{ "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": "0100\n0101\n10100\n01000\n0101011\n0011\n011110\n#", "output": "Yes\nNo\nYes\nNo\nYes\nNo\nNo\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "0100\n1101\n10100\n11000\n0001011\n0011\n01111...
taco
verifiable_code
Solve the following coding problem using the programming language python: Solve the mystery. INPUT : First line contains T No. of test cases. Each test case contains two lines. First line contains two space separated integers ( N and K). Second line contains N space separated integers A [i]. OUTPUT : Print the sol...
```python t = eval(input()) while t>0: t-=1 n, k = list(map(int, input().split())) a = list(map(int, input().split())) a.sort() print(a[k-1]) ```
vfc_143902
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10\n74 45\n6182 9670 28431 30442 17832 12848 32575 18761 23544 1077 4754 6767 20845 19039 10423 2395 11995 30918 31156 28940 6673 14726 29831 31894 27046 16752 4365 16756 9718 23808 31012 21536 7015 18831 19724 2785 25073 11978 181...
taco
verifiable_code
Solve the following coding problem using the programming language python: A positive integer may be expressed as a sum of different prime numbers (primes), in one way or another. Given two positive integers n and k, you should count the number of ways to express n as a sum of k different primes. Here, two ways are con...
```python primes = [] flag = [0 for i in range(1121)] for i in range(2, 1121): if flag[i] == 0: primes.append(i) count = 2 while i * count < 1121: flag[i * count] = 1 count += 1 dp = [[0 for i in range(15)] for j in range(1121)] dp[0][0] = 1 for p in primes: for k in range(13, -1, -1): for n in range(1121):...
vfc_143907
{ "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": "24 3\n24 2\n2 1\n1 1\n4 2\n18 3\n17 1\n17 3\n17 4\n110 5\n1000 10\n1120 14\n0 0", "output": "2\n3\n1\n0\n0\n2\n1\n0\n1\n79\n200102899\n2079324314\n", "type": "stdin_stdout" }, { "fn_name": null, "inp...
taco
verifiable_code
https://www.codechef.com/problems/JGAMES
Solve the following coding problem using the programming language python: Janmansh and Jay are playing a game. They start with a number X and they play a total of Y moves. Janmansh plays the first move of the game, after which both the players make moves alternatingly. In one move, a player can increment or decremen...
```python num = int(input()) for i in range(num): n1 = list(map(int, input().split(' '))) if sum(n1) % 2 == 0: print('Janmansh') else: print('Jay') ```
vfc_143911
{ "difficulty": "easy", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/JGAMES", "time_limit": "0.5 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n2 2\n4 3\n", "output": "Janmansh\nJay\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/ADJSUMPAR
Solve the following coding problem using the programming language python: Chef has an array A of length N. Chef forms a binary array B of length N using the parity of the sums of adjacent elements in A. Formally, B_{i} = (A_{i} + A_{i+1}) \, \% \, 2 for 1 ≤ i ≤ N - 1 B_{N} = (A_{N} + A_{1}) \, \% \, 2 Here x \, \% ...
```python for i in range(int(input())): a = int(input()) s = input() c = s.count('1') if c % 2 == 0: print('YES') else: print('NO') ```
vfc_143915
{ "difficulty": "easy", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/ADJSUMPAR", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n2\n0 0\n2\n1 0\n4\n1 0 1 0\n3\n1 0 0\n", "output": "YES\nNO\nYES\nNO\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: Lexicographical order is a generalization of the way the alphabetical order of words is based on the alphabetical order of their component letters. An example of lexicographical arrangement is a dictionary or a contact directory. You are given ...
```python import re romanNumeralMap = (('M', 1000), ('CM', 900), ('D', 500), ('CD', 400), ('C', 100), ('XC', 90), ('L', 50), ('XL', 40), ('X', 10), ('IX', 9), ('V', 5), ('IV', 4), ('I', 1)) romanNumeralPattern = re.compile(""" ^ # beginning of string M{0,4} # th...
vfc_143919
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "Bruce XXII\nHenri XX\nMaru XXXVI\nPhilippe XL\nLou XVI\nLovro XVI\nKubus XXXII\nMaru XXXIX\nBob XXXVIII\nRichard XXXIX\nCarlos II\nJames XXXIII\nAnne XXIV\nAnne XXVI\nPhilip XLVII\nIlya III\nKubus XLII\nJulka XIX\nMary XLVII\nLukas...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/greater-on-right-side4305/1
Solve the following coding problem using the programming language python: You are given an array Arr of size N. Replace every element with the next greatest element (greatest element on its right side) in the array. Also, since there is no element next to the last element, replace it with -1. Example 1: Input: N = 6 A...
```python class Solution: def nextGreatest(self, arr, n): for i in range(n - 1, -1, -1): temp = arr[i] arr[i] = arr[n - 1] if temp >= arr[n - 1]: arr[n - 1] = temp arr[n - 1] = -1 return arr ```
vfc_143923
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/greater-on-right-side4305/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 6\nArr[] = {16, 17, 4, 3, 5, 2}", "output": "17 5 5 5 2 -1", "type": "stdin_stdout" }, { "fn_name": null, "input": "N = 4\nArr[] = {2, 3, 1, 9}", "output": "9 9 9 -1", "type": "stdin_...
taco
verifiable_code
Solve the following coding problem using the programming language python: Chandu and Kundu are bored of dramatic games around. As they are very good friends and scholars they decided to discover a new game. In total they had N number of marbles with value inscribed on each of them from 1 to N. Chandu being from roy...
```python ''' # Read input from stdin and provide input before running code name = raw_input('What is your name?\n') print 'Hi, %s.' % name ''' import sys while True: line = sys.stdin.readline() if not line: break marble_num = int(line.strip()) marble_stack = [] cont_stack = [] for i in range(1, marble_num): ...
vfc_143924
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "85\n25 43 35 23 9 3 38 28 29 1 7 18 36 37 12 32 5 41 17 13 19 26 14 8 10 16 21 33 11 39 2 27 15 40 30 22 20 34 31 42 4 6 24\n75\n16 23 42 8 2 27 24 5 17 19 20 28 38 30 21 4 43 44 34 31 12 35 39 22 11 7 6 45 14 32 9 15 36 10 26 29 3...
taco
verifiable_code
https://www.hackerrank.com/challenges/long-permutation/problem
Solve the following coding problem using the programming language python: 、Consider an inifite array, $a$, of positive numbers, $a_1,a_2,\ldots$, where each $a_i=i$. You can apply a permutation, ${p}$, of size $n$ (i.e., $n$ different numbers $1\leq p_1,\ldots,p_n\leq n$) to the $n$-element subset of your array from $...
```python (n, m) = map(int, input().split()) (*p,) = map(lambda x: int(x) - 1, input().split()) p = p[1:] + p[:1] order = [] idx = n - 1 while p[idx] != -1: order.append(p[idx]) tmp = p[idx] p[idx] = -1 idx = tmp if m > len(order): print(m + (n - len(order))) else: print(order[m - 1] + 1) ```
vfc_143928
{ "difficulty": "medium_hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.hackerrank.com/challenges/long-permutation/problem", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 10\n2 1\n", "output": "11\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 1\n2 3 1\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "in...
taco
verifiable_code
https://www.codechef.com/problems/TICKETS5
Solve the following coding problem using the programming language python: Every day, Mike goes to his job by a bus, where he buys a ticket. On the ticket, there is a letter-code that can be represented as a string of upper-case Latin letters. Mike believes that the day will be successful in case exactly two different ...
```python for _ in range(int(input())): s = input() ls = set() for i in s: ls.add(i) if len(ls) != 2: print('NO') else: print('YES') ```
vfc_143932
{ "difficulty": "easy", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/TICKETS5", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\nABABAB\nABC\n", "output": "YES\nNO\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: The CS & IT Department students have been facing tough competitions from each other since ages, in being the best in research & innovation. This time CS Department is taken the edge over IT Department by designing a special weather predictor dev...
```python ''' # Read input from stdin and provide input before running code name = raw_input('What is your name?\n') print 'Hi, %s.' % name ''' #print 'Hello World!' T=eval(input()) while(T!=0): D=input() A=input() opp=0 l=[] if len(D)==len(A): for i in range(0,len(D)): if A[i]!=D[i]: opp+=1 print(opp...
vfc_143936
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\nTOPCODER\nKODER\nONLYPROGRAMMINGPLATFORMHACKEREARTHININDIAISTHEBEST\nHABKRTEARGH", "output": "4\n3", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\nMBNMVBDSJFHDFJDHFAKFHAKLFHFLKFURIFRFR...
taco
verifiable_code
https://codeforces.com/problemset/problem/92/D
Solve the following coding problem using the programming language python: There are n walruses standing in a queue in an airport. They are numbered starting from the queue's tail: the 1-st walrus stands at the end of the queue and the n-th walrus stands at the beginning of the queue. The i-th walrus has the age equal ...
```python from bisect import bisect_left n = int(input()) a = list(map(int, input().split())) b = [0] * n for i in range(n - 1, -1, -1): b[i] = bisect_left(a, a[i], i + 1, len(a)) - i - 2 a[i] = min(a[i + 1], a[i]) if i != n - 1 else a[i] print(*b) ```
vfc_143940
{ "difficulty": "medium", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/92/D", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "15\n18 6 18 21 14 20 13 9 18 20 28 13 19 25 21\n", "output": "10 -1 8 8 6 6 0 -1 2 2 3 -1 -1 0 -1 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1000000000 1\n", "output": "0 -1 "...
taco
verifiable_code
Solve the following coding problem using the programming language python: You are given circle $A$ with radius $r_a$ and with central coordinate $(x_a, y_a)$ and circle $B$ with radius $r_b$ and with central coordinate $(x_b, y_b)$. Write a program which prints: * "2" if $B$ is in $A$, * "-2" if $A$ is in $B$, * "1"...
```python n = int(input()) for _ in range(n): (xa, ya, ra, xb, yb, rb) = map(float, input().split()) dist = ((xa - xb) ** 2 + (ya - yb) ** 2) ** 0.5 if ra + rb < dist: print('0') elif abs(ra - rb) <= dist: print('1') elif rb < ra: print('2') elif ra < rb: print('-2') ```
vfc_143945
{ "difficulty": "unknown_difficulty", "memory_limit": "134.217728 megabytes", "memory_limit_bytes": null, "problem_url": null, "time_limit": "1.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n0.0 0.0 5.0 0.0 0.0 4.0\n0.0 0.0 2.0 4.1 0.0 2.4515674947137622", "output": "2\n1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n0.0 0.0 5.0 0.0 1.5542884595470625 4.0\n0.0 0.0 2.0 ...
taco
verifiable_code
Solve the following coding problem using the programming language python: Rash is known about his love for racing sports. He is an avid Formula 1 fan. He went to watch this year's Indian Grand Prix at New Delhi. He noticed that one segment of the circuit was a long straight road. It was impossible for a car to overtak...
```python ''' # Read input from stdin and provide input before running code name = raw_input('What is your name?\n') print 'Hi, %s.' % name ''' t = int(input()) for _ in range(t): n = int(input()) nl = list(map(int, input().split())) low = nl[0] count = 1 for i in range(0,n-1): if nl[i] >= nl[i+1]: count += ...
vfc_143949
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1\n10\n3\n8 3 6\n5\n4 5 1 2 3\n", "output": "1\n2\n2", "type": "stdin_stdout" }, { "fn_name": null, "input": "73\n3\n30911761 6706152 39650290 \n3\n37702960 32711386 17722242 \n9\n30035296 3738973...
taco
verifiable_code
https://codeforces.com/problemset/problem/399/B
Solve the following coding problem using the programming language python: User ainta has a stack of n red and blue balls. He can apply a certain operation which changes the colors of the balls inside the stack. While the top ball inside the stack is red, pop the ball from the top of the stack. Then replace the blu...
```python n = int(input()) balls = list(input()) balls.reverse() stack = [] c = 0 pred = balls[0] for b in balls: if b == pred: c += 1 else: stack.append([pred, c]) c = 1 pred = b else: stack.append([pred, c]) cnt = 0 l = len(balls) while True: if stack[-1][0] == 'R': l -= stack[-1][1] stack.pop() else:...
vfc_143953
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/399/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\nRBR\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\nRBBR\n", "output": "6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "...
taco
verifiable_code
https://www.codechef.com/problems/CHEFDIV
Solve the following coding problem using the programming language python: Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Chef has defined a new type of rooted tree - divisor tree. In this tree, every node has a positive integer written on it. It follows some rules: The root can have an...
```python MAX = int(1000000.0) + 1 is_prime = [True] * MAX (a, b) = map(int, input().strip().split()) factor = [list() for _ in range(b - a + 1)] for i in range(2, MAX): if is_prime[i]: for j in range(2 * i, MAX, i): is_prime[j] = False for j in range((a + i - 1) // i * i, b + 1, i): factor[j - a].append(i) ...
vfc_143957
{ "difficulty": "hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/CHEFDIV", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "11 12", "output": "14", "type": "stdin_stdout" }, { "fn_name": null, "input": "932451 935212", "output": "101245", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: A trick of fate caused Hatsumi and Taku to come to know each other. To keep the encounter in memory, they decided to calculate the difference between their ages. But the difference in ages varies depending on the day it is calculated. While tryi...
```python (y1, m1, d1) = map(int, input().split()) (y2, m2, d2) = map(int, input().split()) if y1 > y2 or (y1 == y2 and (m1 > m2 or (m1 == m2 and d1 > d2))): (y1, y2) = (y2, y1) (m1, m2) = (m2, m1) (d1, d2) = (d2, d1) if m1 < m2 or (m1 == m2 and d1 < d2): print(y2 - y1 + 1) else: print(y2 - y1) ```
vfc_143961
{ "difficulty": "unknown_difficulty", "memory_limit": "268.435456 megabytes", "memory_limit_bytes": null, "problem_url": null, "time_limit": "1.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2008 2 29\n2015 1 1", "output": "7\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1505 9 9\n2001 11 3", "output": "497\n", "type": "stdin_stdout" }, { "fn_name":...
taco
verifiable_code
https://www.codechef.com/problems/POLYREL
Solve the following coding problem using the programming language python: Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. You are given a strictly convex polygon with $N$ vertices (numbered $1$ through $N$). For each valid $i$, the coordinates of the $i$-th ver...
```python t = int(input()) for _ in range(t): n = int(input()) for i in range(n): (a, b) = map(int, input().split()) chord = n while n >= 6: n = n // 2 chord = chord + n print(chord) ```
vfc_143965
{ "difficulty": "medium", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/POLYREL", "time_limit": "1.5 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n4\n-100 1\n0 2\n0 0\n100 1\n7\n-4 0\n-3 -2\n-3 2\n0 -4\n2 -3\n2 3\n3 2", "output": "4\n10", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: Better things, cheaper. There is a fierce battle at the time sale held in some supermarkets today. "LL-do" here in Aizu is one such supermarket, and we are holding a slightly unusual time sale to compete with other chain stores. In a general tim...
```python from heapq import heappush, heappop from string import digits import sys readline = sys.stdin.readline write = sys.stdout.write dd = ((-1, 0), (0, -1), (1, 0), (0, 1)) INF = 10 ** 9 while 1: (X, Y) = map(int, readline().split()) if X == Y == 0: break MP = [readline().split() for i in range(Y)] N = int(r...
vfc_143969
{ "difficulty": "unknown_difficulty", "memory_limit": "134.217728 megabytes", "memory_limit_bytes": null, "problem_url": null, "time_limit": "5.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6 5\n1 1 . 0 0 4\n1 . . . . .\n. . 2 2 . .\n. . 2 2 3 3\nP . - . . .\n5\n0 50 5 10\n1 20 0 10\n2 10 5 15\n3 150 3 5\n4 100 8 9\n0 0", "output": "180\n", "type": "stdin_stdout" }, { "fn_name": null, "...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/minimize-connections/1
Solve the following coding problem using the programming language python: Given an integer N, denoting the number of computers connected by cables forming a network and a 2d array connections[][], with each row (i, j) representing a connection between i^{th} and j^{th} computer, the task is to connect all the computer...
```python from typing import List from collections import defaultdict class Solution: def minimumConnections(self, n: int, m: int, c: List[List[int]]) -> int: adj = [[] for _ in range(n)] for (i, j) in c: adj[i].append(j) adj[j].append(i) def dfs(i): q = [i] while len(q): for i in range(len(q)...
vfc_143973
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/minimize-connections/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 4 \nconnections[][] = {{0, 1}, {0, 2}, {1, 2}}", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "N = 5\nconnections[][] = {{0, 1}, {0, 2}, {3, 4}, {2, 3}}", "output": ...
taco
verifiable_code
https://codeforces.com/problemset/problem/1613/E
Solve the following coding problem using the programming language python: There is a grid, consisting of n rows and m columns. Each cell of the grid is either free or blocked. One of the free cells contains a lab. All the cells beyond the borders of the grid are also blocked. A crazy robot has escaped from this lab. ...
```python import os import sys from io import BytesIO, IOBase import math as M import itertools as ITR from collections import defaultdict as D from collections import Counter as C from collections import deque as Q import threading from functools import cmp_to_key, lru_cache, reduce from functools import cmp_to_key as...
vfc_143976
{ "difficulty": "hard", "memory_limit": "512.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1613/E", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n3 31\n############################..#\n.............................L.\n############################..#\n", "output": "############################++#\n+++++++++++++++++++++++++++++L+\n############################++#\n", ...
taco
verifiable_code
https://codeforces.com/problemset/problem/984/C
Solve the following coding problem using the programming language python: You are given several queries. Each query consists of three integers p, q and b. You need to answer whether the result of p/q in notation with base b is a finite fraction. A fraction in notation with base b is finite if it contains finite numbe...
```python from sys import stdin, stdout n = int(stdin.readline()) s = '' for i in range(n): (p, q, b) = map(int, input().split()) for i in range(6): b = b * b % q if p * b % q: s += 'Infinite\n' else: s += 'Finite\n' print(s) ```
vfc_143980
{ "difficulty": "medium_hard", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/984/C", "time_limit": "1.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10\n10 8 5\n0 6 9\n0 7 6\n5 7 3\n7 6 8\n0 4 8\n2 6 3\n10 2 9\n6 7 9\n9 1 4\n", "output": "Infinite\nFinite\nFinite\nInfinite\nInfinite\nFinite\nFinite\nFinite\nInfinite\nFinite\n", "type": "stdin_stdout" }, { ...
taco
verifiable_code
https://codeforces.com/problemset/problem/49/B
Solve the following coding problem using the programming language python: Vasya studies positional numeral systems. Unfortunately, he often forgets to write the base of notation in which the expression is written. Once he saw a note in his notebook saying a + b = ?, and that the base of the positional notation wasn’t ...
```python (a, b) = list(map(int, input().split())) k = int(max(str(a) + str(b))) + 1 carry = 0 l = max(len(str(a)), len(str(b))) for itr in range(l): if a % 10 + b % 10 + carry < k: carry = 0 else: carry = 1 a //= 10 b //= 10 if carry: print(l + 1) else: print(l) ```
vfc_143984
{ "difficulty": "medium", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/49/B", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "208 997\n", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "12 34\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1...
taco
verifiable_code
https://codeforces.com/problemset/problem/1301/D
Solve the following coding problem using the programming language python: Bashar was practicing for the national programming contest. Because of sitting too much in front of the computer without doing physical movements and eating a lot Bashar became much fatter. Bashar is going to quit programming after the national ...
```python import sys readline = sys.stdin.readline def solve(K): Ans = [] if K > M - 1: K -= M - 1 Ans.append(f'{M - 1} R') else: Ans.append(f'{K} R') return Ans if K > M - 1: K -= M - 1 Ans.append(f'{M - 1} L') else: Ans.append(f'{K} L') return Ans cycle = 4 * M - 3 if K > cycle * (N - 1): K ...
vfc_143988
{ "difficulty": "hard", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1301/D", "time_limit": "1 second" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 3 4\n", "output": "YES\n2\n2 R\n2 L\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 3 1000000000\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": ...
taco
verifiable_code
Solve the following coding problem using the programming language python: We have a grid with H rows and W columns of squares. We will represent the square at the i-th row from the top and j-th column from the left as (i,\ j). Also, we will define the distance between the squares (i_1,\ j_1) and (i_2,\ j_2) as |i_1 - ...
```python (H, W, D) = map(int, input().split()) d = ['R', 'Y', 'G', 'B'] ans = [[] for i in range(H)] for i in range(H): for j in range(W): (x, y) = (i + j, i - j) k = x % (2 * D) // D k += y % (2 * D) // D * 2 ans[i].append(d[k]) for row in ans: print(''.join(row)) ```
vfc_143992
{ "difficulty": "unknown_difficulty", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": null, "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 3 2", "output": "YYG\nRBB\nGGY\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 3 3", "output": "YRR\nYYG\nYBB\n", "type": "stdin_stdout" }, { "fn_name": null,...
taco
verifiable_code
https://codeforces.com/problemset/problem/1530/C
Solve the following coding problem using the programming language python: You and your friend Ilya are participating in an individual programming contest consisting of multiple stages. A contestant can get between $0$ and $100$ points, inclusive, for each stage, independently of other contestants. Points received by ...
```python def readline(): return map(int, input().split()) def solve(): n = int(input()) a = sorted(readline()) b = sorted(readline()) q = n // 4 sa = sum(a[q:]) sb = sum(b[q:]) k = 0 while sa < sb: k += 1 sa += 100 if (n + k) % 4 == 0: sa -= a[q] if q < n else 100 q += 1 else: sb += b[q - k]...
vfc_143996
{ "difficulty": "easy", "memory_limit": "512 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1530/C", "time_limit": "2 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n1\n100\n0\n1\n0\n100\n4\n20 30 40 50\n100 100 100 100\n4\n10 20 30 40\n100 100 100 100\n7\n7 59 62 52 27 31 55\n33 35 50 98 83 80 64\n", "output": "0\n1\n3\n4\n2\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: There are N piles of candies on the table. The piles are numbered 1 through N. At first, pile i contains a_i candies. Snuke and Ciel are playing a game. They take alternating turns. Snuke goes first. In each turn, the current player must perfor...
```python N = int(input()) A = list(map(int, input().split())) A.append(0) A.sort() winner = '' for i in range(N + 1): if A[N - i] > i: if (A[N - i] - i) % 2 == 0: winner = 'First' else: winner = 'Second' elif A[N - i] == i: if (A[N - i + 1] - A[N - i]) % 2 == 1: winner = 'First' break else: co...
vfc_144000
{ "difficulty": "unknown_difficulty", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": null, "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1 0 1", "output": "First\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n0 3", "output": "Second\n", "type": "stdin_stdout" }, { "fn_name": null, "inp...
taco
verifiable_code
https://www.codechef.com/problems/INTEG
Solve the following coding problem using the programming language python: Chef has an array of N integers. He wants to play a special game. In this game he needs to make all the integers in the array greater than or equal to 0. Chef can use two types of operations. The first type is to increase all the integers of t...
```python n = int(input()) l = map(int, input().split()) x = int(input()) l = [i for i in l if i < 0] l.sort() print(-sum(l) if -sum(l) <= x else -sum(l[:x])) ```
vfc_144004
{ "difficulty": "medium_hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/INTEG", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n-1 -2 -3\n2\n", "output": "5\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n-2 -2 -3\n2", "output": "5\n", "type": "stdin_stdout" }, { "fn_name": null, ...
taco
verifiable_code
https://codeforces.com/problemset/problem/1067/C
Solve the following coding problem using the programming language python: Ivan places knights on infinite chessboard. Initially there are $n$ knights. If there is free cell which is under attack of at least $4$ knights then he places new knight in this cell. Ivan repeats this until there are no such free cells. One ca...
```python import collections, atexit, math, sys, bisect sys.setrecursionlimit(1000000) def getIntList(): return list(map(int, input().split())) try: import numpy def dprint(*args, **kwargs): print(*args, **kwargs, file=sys.stderr) dprint('debug mode') except Exception: def dprint(*args, **kwargs): pass inId...
vfc_144009
{ "difficulty": "very_hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1067/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n", "output": "0 0\n1 0\n1 3\n2 0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "7\n", "output": "0 0\n1 0\n1 3\n2 0\n3 0\n3 3\n4 0\n", "type": "stdin_stdout" }, { ...
taco
verifiable_code
https://codeforces.com/problemset/problem/1239/C
Solve the following coding problem using the programming language python: There are n seats in the train's car and there is exactly one passenger occupying every seat. The seats are numbered from 1 to n from left to right. The trip is long, so each passenger will become hungry at some moment of time and will go to tak...
```python import sys reader = (s.rstrip() for s in sys.stdin) input = reader.__next__ from heapq import heappop, heappush, heapify from collections import deque class SWAG_Stack: def __init__(self, F): self.stack1 = deque() self.stack2 = deque() self.F = F self.len = 0 def push(self, x): if self.stack2: ...
vfc_144015
{ "difficulty": "hard", "memory_limit": "512.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1239/C", "time_limit": "1.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "100 1000000000\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n", "outp...
taco
verifiable_code
https://codeforces.com/problemset/problem/1093/C
Solve the following coding problem using the programming language python: Mishka is trying really hard to avoid being kicked out of the university. In particular, he was doing absolutely nothing for the whole semester, miraculously passed some exams so that just one is left. There were $n$ classes of that subject dur...
```python n = int(input()) b = list(map(int, input().split())) ans = [-1] * n ans[0] = 0 ans[-1] = b[0] l = 0 r = n - 1 for i in range(1, n // 2): if b[i] - ans[l] <= ans[r]: ans[l + 1] = ans[l] ans[r - 1] = b[i] - ans[l] l += 1 r -= 1 else: ans[l + 1] = b[i] - ans[r] ans[r - 1] = ans[r] l += 1 r -= 1...
vfc_144019
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1093/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n5 6\n", "output": "0 1 5 5 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n2 1 2\n", "output": "0 0 1 1 1 2 \n", "type": "stdin_stdout" }, { "fn_name": nul...
taco
verifiable_code
Solve the following coding problem using the programming language python: Ordinary Jigsaw puzzles are solved with visual hints; players solve a puzzle with the picture which the puzzle shows on finish, and the diverse patterns of pieces. Such Jigsaw puzzles may be suitable for human players, because they require abili...
```python p_ch = [True] * 9 rot = ((0, 1, 2, 3), (1, 2, 3, 0), (2, 3, 0, 1), (3, 0, 1, 2)) adj = ['c'] * 13 rec_adj = [[0, 2], [1, 3], [12, 4], [5, 7], [6, 8], [12, 9], [10, 12], [11, 12], [12, 12]] ref_adj = [[12, 12], [12, 0], [12, 1], [2, 12], [3, 5], [4, 6], [7, 12], [8, 10], [9, 11]] tr = dict(zip('RGBWrgbw', 'rgb...
vfc_144024
{ "difficulty": "unknown_difficulty", "memory_limit": "134.217728 megabytes", "memory_limit_bytes": null, "problem_url": null, "time_limit": "3.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\nWwRR wwrg RRGb rGBG RGrb RrRg RGrg rgBB Wrgr\nRrGb WWGR rGgb Wbrg wgBb GgBg WbBG Wwwg WWGG\nRBbr Wrbr wGGG wggR WgGR WBWb WRgB wBgH WBgG\nwBrg rGgb WRrB WWbw wRRB RbbB WRrb wrbb WgrG\nWrwB WWww wRRB WGGb Wbbg WBgG WrbG Wrww RBgg...
taco
verifiable_code
https://codeforces.com/problemset/problem/1405/D
Solve the following coding problem using the programming language python: Alice and Bob are playing a fun game of tree tag. The game is played on a tree of n vertices numbered from 1 to n. Recall that a tree on n vertices is an undirected, connected graph with n-1 edges. Initially, Alice is located at vertex a, and ...
```python for t in range(int(input())): (n, a, b, da, db) = map(int, input().split()) graph = [set() for i in range(n + 1)] for i in range(n - 1): (u, v) = map(int, input().split()) graph[u].add(v) graph[v].add(u) visited = {1} last_visits = set() visit_now = {1} while len(visited) < n: while visit_now: ...
vfc_144028
{ "difficulty": "hard", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1405/D", "time_limit": "1.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n5 5 4 3 4\n1 2\n4 1\n5 1\n5 3\n", "output": "Alice\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n9 1 5 3 7\n1 2\n2 3\n3 4\n4 5\n3 6\n7 8\n8 9\n6 7\n", "output": "Alice\n", ...
taco
verifiable_code
https://codeforces.com/problemset/problem/512/C
Solve the following coding problem using the programming language python: Fox Ciel is participating in a party in Prime Kingdom. There are n foxes there (include Fox Ciel). The i-th fox is ai years old. They will have dinner around some round tables. You want to distribute foxes such that: 1. Each fox is sitting a...
```python from collections import deque class Dinic: def __init__(self, listEdge, s, t): self.s = s self.t = t self.graph = {} self.maxCap = 1000000 for e in listEdge: if e[0] not in self.graph: self.graph[e[0]] = [] if e[1] not in self.graph: self.graph[e[1]] = [] self.graph[e[0]].append(...
vfc_144033
{ "difficulty": "hard", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/512/C", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "15\n3 3 3 3 3 3 3 4 2 4 2 2 2 4 2\n", "output": "Impossible\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "152\n29 23 17 25 13 29 29 29 25 23 25 29 19 25 13 25 13 23 21 27 15 29 29 25 27 ...
taco
verifiable_code
https://codeforces.com/problemset/problem/1472/D
Solve the following coding problem using the programming language python: During their New Year holidays, Alice and Bob play the following game using an array $a$ of $n$ integers: Players take turns, Alice moves first. Each turn a player chooses any element and removes it from the array. If Alice chooses even value...
```python for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) a.sort(reverse=True) bob = alice = 0 cur = 0 for i in range(n): if cur == 0: if a[i] % 2 == 0: alice += a[i] cur = 1 else: if a[i] % 2 == 1: bob += a[i] cur = 0 if alice == bob: print('Tie') el...
vfc_144037
{ "difficulty": "easy", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1472/D", "time_limit": "2 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n4\n5 2 7 3\n3\n3 2 1\n4\n2 2 2 2\n2\n7 8\n", "output": "Bob\nTie\nAlice\nAlice\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n3\n1 1 234872\n4\n5 2 7 3\n", "output": "Alice\nB...
taco
verifiable_code
https://codeforces.com/problemset/problem/816/C
Solve the following coding problem using the programming language python: On the way to school, Karen became fixated on the puzzle game on her phone! <image> The game is played as follows. In each level, you have a grid with n rows and m columns. Each cell originally contains the number 0. One move consists of choo...
```python (n, m) = [int(i) for i in input().split(' ')] g = [] (c, f) = (0, 0) ans = '' def row(): global n, m, g, c, ans for i in range(n): t = min(g[i]) c += t ans += 'row %d\n' % (i + 1) * t for j in range(m): g[i][j] -= t def col(): global n, m, g, c, ans for i in range(m): r = [_[i] for _ in g] ...
vfc_144042
{ "difficulty": "medium_hard", "memory_limit": "512.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/816/C", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 1\n4\n5\n", "output": "5\ncol 1\ncol 1\ncol 1\ncol 1\nrow 2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 2\n5 10\n5 10\n5 10\n", "output": "15\ncol 1\ncol 1\ncol 1\ncol 1\ncol...
taco
verifiable_code
https://www.codechef.com/problems/ADDNDIV
Solve the following coding problem using the programming language python: You are given two positive integers a and b. You also have a number x, which is initially set to 0. At first, you can add a to x any number of times. After that, you can divide x by b any number of times as long as x is divisible by b. Print YE...
```python t = int(input()) for i in range(t): (a, b) = tuple(map(int, input().split())) p = False r = b for i in range(100): if r % a == 0: p = True break else: r *= b if p: print('YES') else: print('NO') ```
vfc_144046
{ "difficulty": "medium_hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/ADDNDIV", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n3 10\n9 6\n7 30\n8 12", "output": "NO\nYES\nNO\nYES", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: problem AOR Ika wants to create a strong password that consists only of lowercase letters. AOR Ika-chan, who was given an example of $ N $ of dangerous passwords by a friend, decided to create a password that meets all of the following conditio...
```python import itertools INF = float('inf') MOD = 10 ** 9 + 7 def inpl(): return list(map(int, input().split())) class RollingHash: def __init__(self, s, base, mod): self.s = s self.length = length = len(s) self.base = base self.mod = mod self.h = h = [0] * (length + 1) for i in range(length): h[i...
vfc_144050
{ "difficulty": "unknown_difficulty", "memory_limit": "268.435456 megabytes", "memory_limit_bytes": null, "problem_url": null, "time_limit": "1.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\npassword\nlogin\nnimda\nroot\nmaster", "output": "b\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\nbraprswp\nlofho\nojdma\nsnnt\nfuarsm", "output": "c\n", "type": "stdin...
taco
verifiable_code
Solve the following coding problem using the programming language python: Ringo Kingdom Congress is voting on a bill. N members are present, and the i-th member (1 ≤ i ≤ N) has w_i white ballots and b_i blue ballots. Each member i will put all the w_i white ballots into the box if he/she is in favor of the bill, and ...
```python (n, p) = map(int, input().split()) (w, b) = ([], []) for _ in range(n): (ww, bb) = map(int, input().split()) w.append(ww) b.append(bb) s = [] for (ww, bb) in zip(w, b): s.append((100 - p) * ww + p * bb) s.sort(reverse=True) score = -sum(b) * p cnt = 0 while score < 0: score += s[cnt] cnt += 1 print(cnt)...
vfc_144054
{ "difficulty": "unknown_difficulty", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": null, "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 60\n6 3\n5 9\n3 4\n7 0\n4 7", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 17\n1 1\n1 1\n1 1\n000 1", "output": "1\n", "type": "stdin_stdout" }, { ...
taco
verifiable_code
https://www.codechef.com/problems/FGFS
Solve the following coding problem using the programming language python: Our chef has recently opened a new restaurant with a unique style. The restaurant is divided into K compartments (numbered from 1 to K) and each compartment can be occupied by at most one customer. Each customer that visits the restaurant has a...
```python from collections import defaultdict for _ in range(int(input())): (n, k) = list(map(int, input().split())) d = defaultdict(list) for i in range(n): (s, f, p) = list(map(int, input().split())) d[p].append([s, f]) ans = 0 for i in d: if len(d[i]) == 1: ans += 1 else: d[i].sort(key=lambda x: x...
vfc_144058
{ "difficulty": "medium_hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/FGFS", "time_limit": "0.5 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n3 3\n1 3 1\n4 6 2\n7 10 3\n4 2\n10 100 1\n100 200 2\n150 500 2\n200 300 2\n", "output": "3\n3\n", "type": "stdin_stdout" } ] }