source
stringclasses
4 values
task_type
stringclasses
1 value
in_source_id
stringlengths
0
138
problem
stringlengths
219
13.2k
gold_standard_solution
stringlengths
0
413k
problem_id
stringlengths
5
10
metadata
dict
verification_info
dict
taco
verifiable_code
Solve the following coding problem using the programming language python: Monk visits a magical place, Makizam. He is greeted by his old friend, Wiz. Wiz happy to see his old friend, gives him a puzzle. He takes him to a room with N keys placed on the floor, the i'th key is of type Xi. The keys are followed by M ches...
```python def gcd(a, b): if not b: return a return gcd(b, a % b) def memo(f): mem = {} def ret(keys_to_chest, booty, opened): k = (id(keys_to_chest), opened) if k not in mem: mem[k] = f(keys_to_chest, booty, opened) return mem[k] return ret @memo def score(keys_to_chest, booty, opened): i = 0 reward = 0 ...
vfc_136946
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10\n19 78 4\n16 44 36 37 43 50 22 13 28 41 10 14 27 41 27 23 37 12 19\n18 30 33 31 13 24 18 36 30 3 23 9 20 18 44 7 12 43 30 24 22 20 35 38 49 25 16 21 14 27 42 31 7 24 13 21 47 32 6 26 35 28 37 6 47 30 14 8 25 46 33 46 15 18 35 15...
taco
verifiable_code
Solve the following coding problem using the programming language python: You are a student looking for a job. Today you had an employment examination for an IT company. They asked you to write an efficient program to perform several operations. First, they showed you an N \times N square matrix and a list of operatio...
```python import sys readline = sys.stdin.readline write = sys.stdout.write def solve(): (N, Q, A, B, C, D, E, F, G) = map(int, readline().split()) d = 0 rx = 0 ry = 0 (*X,) = range(N) (*Y,) = range(N) def fc(d, x, y): if d == 0: return (x, y) if d == 1: return (y, N - 1 - x) if d == 2: return (...
vfc_136950
{ "difficulty": "unknown_difficulty", "memory_limit": "134.217728 megabytes", "memory_limit_bytes": null, "problem_url": null, "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 1 3 2 12 1 2 1 2\nRL", "output": "676759451\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 1 3 3 12 1 2 1 2\nWR 1 1 1", "output": "676579860\n", "type": "stdin_stdout" ...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/5a7e1a52f1b7796238f9efea4c6fda389f26c327/1
Solve the following coding problem using the programming language python: Given two numbers a and b. In one operation you can pick any non negative integer x and either of a or b. Now if you picked a then replace a with a&x else if you picked b then replace b with b&x. Return the minimum number of operation required t...
```python class Solution: def solve(self, a: int, b: int) -> int: if a == b: return 0 if a == 0 or b == 0: return 1 x = a & b if a == x or b == x: return 1 return 2 ```
vfc_136956
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/5a7e1a52f1b7796238f9efea4c6fda389f26c327/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "a = 5, b = 12", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "a = 100, b = 100", "output": "0", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/841/C
Solve the following coding problem using the programming language python: Leha like all kinds of strange things. Recently he liked the function F(n, k). Consider all possible k-element subsets of the set [1, 2, ..., n]. For subset find minimal element in it. F(n, k) — mathematical expectation of the minimal element am...
```python n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) a.sort() a.reverse() j = [] for i in range(n): j.append([b[i], i]) j.sort() ans = [0] * n for i in range(n): ans[j[i][1]] = str(a[i]) print(' '.join(ans)) ```
vfc_136957
{ "difficulty": "easy", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/841/C", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n7 3 5 3 4\n2 1 3 3 3\n", "output": "5 7 4 3 3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "7\n4 6 5 8 8 2 6\n2 1 2 1 1 1 2\n", "output": "5 8 4 8 6 6 2\n", "type": "stdin...
taco
verifiable_code
https://codeforces.com/problemset/problem/1526/C2
Solve the following coding problem using the programming language python: This is the hard version of the problem. The only difference is that in this version $n \leq 200000$. You can make hacks only if both versions of the problem are solved. There are $n$ potions in a line, with potion $1$ on the far left and potio...
```python from __future__ import division, print_function import math import os import sys from fractions import * from sys import * from decimal import * from io import BytesIO, IOBase from itertools import accumulate, combinations, permutations, combinations_with_replacement, product from collections import * import ...
vfc_136962
{ "difficulty": "medium_hard", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1526/C2", "time_limit": "1 second" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n4 -4 1 -3 1 -3\n", "output": "5", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/C2
Solve the following coding problem using the programming language python: Let us calculate the sum of k-th powers of natural numbers from 1 to n. As the result can be quite large, output the result modulo some integer p. ------ Input ------ First t≤10 - the number of test cases. Each test case consist of numbers: 1...
```python t = int(input()) for i in range(t): (a, b, o) = map(int, input().split()) r = 10 ** 2 + 5 (d, s) = ([0] * 10 ** 5, [0] * r) for j in range(r): for k in range(r): if j == k or k == 0: d[j * r + k] = 1 else: d[j * r + k] = d[(j - 1) * r + k - 1] + d[(j - 1) * r + k] for j in range(b + 1): ...
vfc_136966
{ "difficulty": "medium_hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/C2", "time_limit": "0.134328 - 0.268657 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n10 1 1000000\n10 2 1000000\n10 3 1000000\n10 4 1000000", "output": "55\n385\n3025\n25333", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/RRATING
Solve the following coding problem using the programming language python: Chef has opened up a new restaurant. Like every other restaurant, critics critique this place. The Chef wants to gather as much positive publicity as he can. Also, he is very aware of the fact that people generally do not tend to go through all ...
```python import queue upper = queue.PriorityQueue() under = queue.PriorityQueue() n = int(input()) nreview = 0 for _ in range(n): s = input() if len(s) != 1: (a, b) = map(int, s.split()) nreview += 1 if nreview < 3: under.put(-b) elif nreview == 3: under.put(-b) upper.put(-under.get()) else: c ...
vfc_136970
{ "difficulty": "medium_hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/RRATING", "time_limit": "0.292969 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10\n1 1\n1 7\n2\n1 9\n1 21\n1 8\n1 5\n2\n1 9\n2", "output": "No reviews yet\n9\n9", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/tilt-of-binary-tree/1
Solve the following coding problem using the programming language python: Given a binary tree of size N+1, your task is to complete the function tiltTree(), that return the tilt of the whole tree. The tilt of a tree node is defined as the absolute difference between the sum of all left subtree node values and the sum ...
```python class Solution: def fun(self, root, s, res): if root == None: return 0 l = self.fun(root.left, s, res) r = self.fun(root.right, s, res) s[0] = l + root.data + r root.data = abs(l - r) res[0] += root.data return s[0] def tiltTree(self, root): (s, res) = ([0], [0]) self.fun(root, s, res...
vfc_136974
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/tilt-of-binary-tree/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n / \\\n 2 3", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 \n / \\\n 2 9 \n / \\ \\\n 3 5 7", "output": "15", "type": "s...
taco
verifiable_code
Solve the following coding problem using the programming language python: Write a program which computes the digit number of sum of two integers a and b. Constraints * 0 ≤ a, b ≤ 1,000,000 * The number of datasets ≤ 200 Input There are several test cases. Each test case consists of two non-negative integers a and ...
```python while 1: try: (a, b) = map(int, input().split()) print(len(str(a + b))) except: break ```
vfc_136975
{ "difficulty": "unknown_difficulty", "memory_limit": "134.217728 megabytes", "memory_limit_bytes": null, "problem_url": null, "time_limit": "1.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 7\n1 99\n1000 999", "output": "2\n3\n4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10 10\n2 36\n1000 25", "output": "2\n2\n4\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: Dothraki are planning an attack to usurp King Robert's throne. King Robert learns of this conspiracy from Raven and plans to lock the single door through which the enemy can enter his kingdom. But, to lock the door he needs a key that is an ana...
```python word = input() s=set(word) n=0 for x in s: if(word.count(x)%2==1): n=n+1 if(n>1): print("NO") else: print("YES") ```
vfc_136979
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "cdefghmnopqrstuvw", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "aaabbbb", "output": "NO", "type": "stdin_stdout" }, { "fn_name": null, "inp...
taco
verifiable_code
https://codeforces.com/problemset/problem/1344/A
Solve the following coding problem using the programming language python: Hilbert's Hotel is a very unusual hotel since the number of rooms is infinite! In fact, there is exactly one room for every integer, including zero and negative integers. Even stranger, the hotel is currently at full capacity, meaning there is e...
```python import io import os from collections import Counter, defaultdict, deque def solve(N, A): if len(set(((i + x) % N for (i, x) in enumerate(A)))) == N: return 'YES' return 'NO' input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline T = int(input()) for t in range(T): (N,) = [int(x) for x in input().s...
vfc_136991
{ "difficulty": "medium_hard", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1344/A", "time_limit": "1 second" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n1\n14\n2\n1 -1\n4\n5 5 5 1\n3\n3 2 1\n2\n0 1\n5\n-239 -2 -100 -3 -11\n", "output": "YES\nYES\nYES\nNO\nNO\nYES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n1\n1000000000\n1\n-100...
taco
verifiable_code
Solve the following coding problem using the programming language python: A tatami mat, a Japanese traditional floor cover, has a rectangular form with aspect ratio 1:2. When spreading tatami mats on a floor, it is prohibited to make a cross with the border of the tatami mats, because it is believed to bring bad luck....
```python def solve(): (H, W) = map(int, input().split()) if H == 0: return False if H * W % 2 == 1: print(0) return True state = [[-1] * W for i in range(H)] def dfs(k): if k == H * W: return 1 (i, j) = divmod(k, W) if state[i][j] != -1: return dfs(k + 1) if i > 0 and j > 0 and (state[i - 1][...
vfc_136995
{ "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 1\n4 4\n0 0", "output": "0\n2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 1\n6 4\n0 0", "output": "0\n3\n", "type": "stdin_stdout" }, { "fn_name": null, ...
taco
verifiable_code
Solve the following coding problem using the programming language python: Brave Ponta and his best friend, Brave Gonta, have come to Luida's bar in search of friends to embark on an epic adventure. There are many warriors, monks and wizards in the tavern who are itching to go on an adventure. Gonta, who is kind-heart...
```python def main(): while True: n = int(input()) if n == 0: break alst = list(map(int, input().split())) s = sum(alst) alst = [a * 2 for a in alst] lst = [-s] for a in alst: lst.extend([i + a for i in lst]) print(min(map(abs, lst))) main() ```
vfc_137003
{ "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": "5\n1 2 3 4 5\n4\n2 3 5 10\n0", "output": "1\n0\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/140/B
Solve the following coding problem using the programming language python: As meticulous Gerald sets the table, Alexander finished another post on Codeforces and begins to respond to New Year greetings from friends. Alexander has n friends, and each of them sends to Alexander exactly one e-card. Let us number his frien...
```python n = int(input()) arr = [list(map(int, input().split())) for _ in range(n + 1)] res = [0] * n for i in range(n): p = [0] * (n + 1) for j in range(n): p[arr[i][j]] = j (u, t, b) = (0, int(100000.0), int(100000.0)) for x in arr[n]: if x != i + 1 and x < b: if p[x] < t: (u, t) = (x, p[x]) b = x ...
vfc_137013
{ "difficulty": "medium_hard", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/140/B", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10\n5 1 6 2 8 3 4 10 9 7\n3 1 10 6 8 5 2 7 9 4\n2 9 1 4 10 6 8 7 3 5\n10 1 7 8 3 2 4 6 5 9\n3 2 10 4 7 8 5 6 1 9\n5 6 3 10 8 7 2 9 4 1\n6 5 1 3 2 7 9 10 8 4\n1 10 9 3 7 8 4 2 6 5\n6 8 4 5 9 1 2 10 7 3\n9 6 8 5 10 3 1 7 2 4\n5 7 4 8...
taco
verifiable_code
https://www.codechef.com/problems/QUALPREL
Solve the following coding problem using the programming language python: Snackdown 2019 is coming! There are two rounds (round A and round B) after the qualification round. From both of them, teams can qualify to the pre-elimination round. According to the rules, in each of these two rounds, teams are sorted in desce...
```python for i in range(int(input())): (n, k) = map(int, input().split()) l = list(map(int, input().split())) l.sort(reverse=True) c = 0 for i in l: if i >= l[k - 1]: c += 1 print(c) ```
vfc_137017
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/QUALPREL", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n5 1\n3 5 2 4 5\n6 4\n6 5 4 3 2 1\n", "output": "2\n4\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1553/B
Solve the following coding problem using the programming language python: You have a string $s$ and a chip, which you can place onto any character of this string. After placing the chip, you move it to the right several (maybe zero) times, i. e. you perform the following operation several times: if the current positi...
```python t = int(input()) for i in range(t): s = input() s2 = input() for j in range(len(s)): if s2 in s[:j] + s[j::-1]: print('YES') break else: print('NO') ```
vfc_137021
{ "difficulty": "easy", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1553/B", "time_limit": "3 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\nabcdef\ncdedcb\naaa\naaaaa\naab\nbaaa\nab\nb\nabcdef\nabcdef\nba\nbaa\n", "output": "YES\nYES\nNO\nYES\nYES\nNO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\naaaaaaaaaaaaaaaaaaaaaa...
taco
verifiable_code
https://www.codechef.com/DEC10/problems/ASTRGAME
Solve the following coding problem using the programming language python: Teddy and Tracy like to play a game based on strings. The game is as follows. Initially, Tracy writes a long random string on a whiteboard. Then, each player starting with Teddy makes turn alternately. Each turn, the player must erase a contiguo...
```python import sys def mex(S, W, C, start, end): key = (start, end) try: return C[key] except KeyError: pass A = set() for s in range(start, end): for e in range(start + 1, end + 1): if S[s:e] not in W: continue A.add(mex(S, W, C, start, s) ^ mex(S, W, C, e, end)) a = 0 while a in A: a += 1 ...
vfc_137025
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/DEC10/problems/ASTRGAME", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\ncodechef\n2\ncode\nchef\nfoo\n1\nbar\nmississippi\n4\nssissi\nmippi\nmi\nppi\n\n\n", "output": "Tracy\nTracy\nTeddy\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/ANDMIN
Solve the following coding problem using the programming language python: Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. You are given an array of N integers. You should support the following queries on this array. 0 L R : Find the minimum integer in the range A_{L}, A_{L+1}, ..., A_{...
```python (n, q) = map(int, input().split()) global segment_tree, arr arr = list(map(int, input().split())) segment_tree = [0] * (4 * n) class Node: def __init__(self): self.xory = 0 self.min_val = 10 ** 9 def build_tree(start, end, treenode=0): global segment_tree, arr if start == end: node = Node() node...
vfc_137029
{ "difficulty": "very_hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/ANDMIN", "time_limit": "2.5 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 5\n1 5 2 3 4\n0 2 5\n1 1 5 6\n0 2 2\n1 2 5 3\n0 1 3", "output": "2\n4\n0", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/party-in-town3951/1
Solve the following coding problem using the programming language python: Geek town has N Houses numbered from 1 to N. They are connected with each other via N-1 bidirectional roads. Given an adjacency list adj to represent the connections. To host the optimal party, you need to identify the house from which the dista...
```python from collections import deque class Solution: def partyHouse(self, N, adj): ans = N for i in range(1, N + 1): dist = [-1] * (N + 1) dist[i] = 0 q = deque() q.append(i) max_dist = 0 while len(q) > 0: v = q.popleft() for w in adj[v]: if dist[w] == -1: dist[w] = dist[v...
vfc_137040
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/party-in-town3951/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 4\r\nadj = {{2},{1,3,4},{2},{2}}", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "N = 4\r\nadj = {{2},{1,3},{2,4},{3}}", "output": "2", "type": "stdin_stdout" ...
taco
verifiable_code
https://www.codechef.com/problems/PPSUM
Solve the following coding problem using the programming language python: Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Yesterday, puppy Tuzik learned a magically efficient method to find the sum of the integers from 1 to N. He denotes it as sum(N). But today, as a true explorer, he d...
```python for i in range(int(input())): (a, b) = [int(i) for i in input().split()] sum = 0 p = 0 for i in range(a): sum = 0 for j in range(1, b + 1): sum += j b = sum print(sum) ```
vfc_137041
{ "difficulty": "easy", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/PPSUM", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n1 4\n2 3", "output": "10\n21", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1628/B
Solve the following coding problem using the programming language python: Mihai plans to watch a movie. He only likes palindromic movies, so he wants to skip some (possibly zero) scenes to make the remaining parts of the movie palindromic. You are given a list $s$ of $n$ non-empty strings of length at most $3$, repre...
```python import sys input = sys.stdin.readline R = lambda : map(int, input().split()) I = lambda : int(input()) S = lambda : input().rstrip('\n') L = lambda : list(R()) def solve() -> str: n = I() s = [S() for _ in range(n)] st = set() st2 = set() if any((x[0] == x[-1] for x in s)): return 'YES' else: for x...
vfc_137045
{ "difficulty": "medium_hard", "memory_limit": "512 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1628/B", "time_limit": "2 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n5\nzx\nab\ncc\nzx\nba\n2\nab\nbad\n4\nco\ndef\norc\nes\n3\na\nb\nc\n3\nab\ncd\ncba\n2\nab\nab\n", "output": "YES\nNO\nNO\nYES\nYES\nNO\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/LUCKYBAL
Solve the following coding problem using the programming language python: A Little Elephant from the Zoo of Lviv likes lucky strings, i.e., the strings that consist only of the lucky digits 4 and 7. The Little Elephant calls some string T of the length M balanced if there exists at least one integer X (1 ≤ X ≤ M) suc...
```python import sys import math def main(arr): n = len(arr) ans = n * (n + 1) / 2 a = 0 for i in range(len(arr)): if arr[i] == '7': a += 1 else: ans -= a * (a + 1) / 2 a = 0 ans -= a * (a + 1) / 2 return int(ans) for _ in range(int(input())): arr = list(input()) print(main(arr)) ```
vfc_137049
{ "difficulty": "medium_hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/LUCKYBAL", "time_limit": "0.352645 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n47\n74\n477\n4747477", "output": "2\n2\n3\n23", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n47\n47\n477\n4747477", "output": "2\n2\n3\n23\n", "type": "stdin_stdout" }...
taco
verifiable_code
https://codeforces.com/problemset/problem/1503/C
Solve the following coding problem using the programming language python: There are $n$ cities numbered from $1$ to $n$, and city $i$ has beauty $a_i$. A salesman wants to start at city $1$, visit every city exactly once, and return to city $1$. For all $i\ne j$, a flight from city $i$ to city $j$ costs $\max(c_i,a_...
```python import sys N = int(input()) lst = [] for n in range(N): l = list(map(int, sys.stdin.readline().split())) lst.append(l) lst.sort() Sum = lst[0][1] c = lst[0][0] + lst[0][1] for i in lst[1:]: Sum += i[1] if i[0] > c: Sum += i[0] - c c = max(c, i[0] + i[1]) print(Sum) ```
vfc_137053
{ "difficulty": "hard", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1503/C", "time_limit": "2 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1 9\n2 1\n4 1\n", "output": "11\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n4 2\n8 4\n3 0\n2 3\n7 1\n0 1\n", "output": "13\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: Example Input 5 3 4 2 5 Output 5 2 4 1 3 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python (n, m) = map(int, input().split()) E = [int(input()) for i in range(m)] s = set() E.reverse() F = [] for e in E: if e in s: continue s.add(e) F.append(e) for i in range(1, n + 1): if i in s: continue F.append(i) (*_,) = map(print, F) ```
vfc_137057
{ "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 0\n4\n2\n5", "output": "1\n2\n3\n4\n5\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 0\n4\n2\n6", "output": "1\n2\n", "type": "stdin_stdout" }, { "fn_name": ...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/introduction-to-trees/1
Solve the following coding problem using the programming language python: Given an integer i. Print the maximum number of nodes on level i of a binary tree. Example 1: Input: 5 Output: 16 Example 2: Input: 1 Output: 1 Your Task: Complete the function countNode() which takes an integer i as input and prints the count...
```python class Solution: def countNodes(self, i): return 2 ** (i - 1) ```
vfc_137061
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/introduction-to-trees/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5", "output": "16", "type": "stdin_stdout" }, { "fn_name": null, "input": "1", "output": "1", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/320/D
Solve the following coding problem using the programming language python: There are n psychos standing in a line. Each psycho is assigned a unique integer from 1 to n. At each step every psycho who has an id greater than the psycho to his right (if exists) kills his right neighbor in the line. Note that a psycho might...
```python n = int(input()) aa = list(map(int, input().split())) live = [] ans = 0 for i in range(n - 1, -1, -1): c = 0 while len(live) != 0 and live[-1][0] < aa[i]: c = max(c + 1, live[-1][1]) live.pop() if c > ans: ans = c live.append((aa[i], c)) print(ans) ```
vfc_137062
{ "difficulty": "hard", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/320/D", "time_limit": "1.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n1\n", "output": "0\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1092/F
Solve the following coding problem using the programming language python: You are given a tree consisting exactly of $n$ vertices. Tree is a connected undirected graph with $n-1$ edges. Each vertex $v$ of this tree has a value $a_v$ assigned to it. Let $dist(x, y)$ be the distance between the vertices $x$ and $y$. Th...
```python from sys import stdin, setrecursionlimit n = int(stdin.readline()) ay = [int(x) for x in stdin.readline().split()] graph = [set() for x in range(n)] for e in range(n - 1): (a, b) = [int(x) - 1 for x in stdin.readline().split()] graph[a].add(b) graph[b].add(a) dists = {} child = {} bruh = sum(ay) path = [(0...
vfc_137066
{ "difficulty": "hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1092/F", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "8\n9 4 1 7 10 1 6 5\n1 2\n2 3\n1 4\n1 5\n5 6\n5 7\n5 8\n", "output": "121\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n1337\n", "output": "0\n", "type": "stdin_stdout" ...
taco
verifiable_code
https://www.hackerrank.com/challenges/count-fox-sequences/problem
Solve the following coding problem using the programming language python: A non-decreasing sequence is a called a Fox sequence, iff the most frequent element in the sequence is unique. e.g. The sequence 1, 1, 2, 3, 4 is a Fox sequence, because it follows the above definition. The most frequent element is 1. It occu...
```python import sys P = 10 ** 9 + 7 fact = [1] for i in range(1, 200001): fact.append(fact[-1] * i % P) inv = [0, 1] for i in range(2, 200001): inv.append(P - P // i * inv[P % i] % P) inv_fact = [1] for i in range(1, 100001): inv_fact.append(inv_fact[-1] * inv[i] % P) def ceil_div(a, b): return -(-a // b) def pa...
vfc_137070
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.hackerrank.com/challenges/count-fox-sequences/problem", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n2 1 1\n2 1 3\n3 1 2\n4 4 5\n10 2 4\n", "output": "1\n3\n4\n4\n60\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: Bubli and shivani are in lab. Bubli wants to send a message to shivani. But he can't send it directly. Bubli is on 1st computer and shivani is on the nth computer. Now the computer's are connected in a chain. 1st is connected to 2nd, 2nd is conn...
```python for i in range(int(input())): a, b = list(map(int, input().split(' '))) if (('0'*50+bin(b)[2:])[-a:]) == '1' * a: print("YES") else: print("NO") ```
vfc_137074
{ "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\n14 87\n28 16\n24 36\n17 93\n10 22\n3 28\n21 60\n24 27\n1 27\n23 37", "output": "NO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\n...
taco
verifiable_code
https://www.codechef.com/problems/CLETAB
Solve the following coding problem using the programming language python: Read problems statements in Mandarin Chinese and Russian. Haku has been newly hired by Chef to clean tables at his restaurant. So whenever a customer wants a table, Haku must clean it. But Haku happens to be a lazy boy. So in the morning, whe...
```python from collections import Counter for _ in range(int(input())): (n, m) = map(int, input().split()) orders = list(map(int, input().split())) tables = set() oper = 0 for (k, i) in enumerate(orders): if i in tables: continue oper += 1 if len(tables) < n: tables.add(i) continue tmp = tables.co...
vfc_137078
{ "difficulty": "medium_hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/CLETAB", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n2 4\n1 2 3 4\n3 2\n4 1\n3 6\n1 2 1 3 4 1\n3 5\n1 2 1 3 4", "output": "4\n2\n4\n4", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/CHDIGER
Solve the following coding problem using the programming language python: Chef Leonardo has a decimal integer $N$ and a non-zero decimal digit $d$. $N$ does not contain the digit zero; specifically, $N$ should always be treated as a decimal integer without leading zeroes. Chef likes $d$ and does not like any other dig...
```python for _ in range(int(input())): (n, d) = input().split() a = list(n) w = int(d) count = 1 l = [] while 1: if count != len(a): count = 1 for i in range(len(a) - 1): if int(a[i]) > int(a[i + 1]): a.pop(i) a.append(d) break else: count += 1 else: for i in range(len(a)...
vfc_137082
{ "difficulty": "medium", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/CHDIGER", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n35 4\n42 4\n24 9\n", "output": "34\n24\n24\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/EQUALCOIN
Solve the following coding problem using the programming language python: Read problem statements in [Bengali], [Russian], [Mandarin] and [Vietnamese] as well. Chef has X coins worth 1 rupee each and Y coins worth 2 rupees each. He wants to distribute all of these X+Y coins to his two sons so that the total value of ...
```python for _ in range(int(input())): (X, Y) = map(int, input().split()) if X % 2 == 1: print('NO') elif Y % 2 == 1 and X == 0: print('NO') else: print('YES') ```
vfc_137086
{ "difficulty": "easy", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/EQUALCOIN", "time_limit": "0.5 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n2 2\n1 3\n4 0\n1 10\n", "output": "YES\nNO\nYES\nNO\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1181/B
Solve the following coding problem using the programming language python: Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf. To solve the issue, Dima decided to split t...
```python L = int(input()) D = input() s = 0 b = 42069666 for c in range(1, L): if D[c] != '0': if abs(L / 2 - c) < b: b = abs(L / 2 - c) s = c def c(s): if s == '': return 0 return int(s) res = c(D[:s]) + c(D[s:]) if L % 2: r = L // 2 if D[r] != '0': res = min(c(D[:r]) + c(D[r:]), res) if D[r + 1] !...
vfc_137090
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1181/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7\n1234567\n", "output": "1801\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n101\n", "output": "11\n", "type": "stdin_stdout" }, { "fn_name": null, "in...
taco
verifiable_code
https://codeforces.com/problemset/problem/900/A
Solve the following coding problem using the programming language python: You have n distinct points on a plane, none of them lie on OY axis. Check that there is a point after removal of which the remaining points are located on one side of the OY axis. -----Input----- The first line contains a single positive inte...
```python test = int(input()) (countp, countn) = (0, 0) for t in range(test): point = list(input().split(' ')) (point[0], point[1]) = (int(point[0]), int(point[1])) if point[0] < 0: countn += 1 elif point[0] > 0: countp += 1 if countn <= 1 or countp <= 1: print('Yes') else: print('No') ```
vfc_137094
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/900/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1 1\n-1 -1\n2 -1\n", "output": "Yes", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n1 1\n2 2\n-1 1\n-2 2\n", "output": "No", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1322/B
Solve the following coding problem using the programming language python: Catherine received an array of integers as a gift for March 8. Eventually she grew bored with it, and she started calculated various useless characteristics for it. She succeeded to do it for each one she came up with. But when she came up with ...
```python for z in range(1): co = 0 n = int(input()) l = list(map(int, input().split())) for e in range(1, 25): po = 2 ** e re = sorted([k % po for k in l]) b = n r = 0 for a in range(n): b -= 1 while re[a] + re[b] >= po and b >= 0: b -= 1 b += 1 r += n - b - (a >= b) r //= 2 if r % 2:...
vfc_137098
{ "difficulty": "hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1322/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n1 2\n", "output": "3", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/482/B
Solve the following coding problem using the programming language python: We'll call an array of n non-negative integers a[1], a[2], ..., a[n] interesting, if it meets m constraints. The i-th of the m constraints consists of three integers li, ri, qi (1 ≤ li ≤ ri ≤ n) meaning that value <image> should be equal to qi. ...
```python import sys input = sys.stdin.readline (n, m) = map(int, input().split()) a = [] for _ in range(m): (l, r, q) = map(int, input().split()) l -= 1 r -= 1 a.append((l, r, q)) res = [0] * n bad = False for i in range(30): events = [0] * (n + 1) for (l, r, q) in a: if q & 1 << i: events[l] += 1 events...
vfc_137102
{ "difficulty": "medium_hard", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/482/B", "time_limit": "1.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 2\n1 1 10\n1 1 5\n", "output": "NO\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/MCHAIRS
Solve the following coding problem using the programming language python: Read problems statements in Mandarin Chinese and Russian. A new school in Byteland is now in the process of renewing some classrooms with new, stronger and better chairs, so that the students can stay still and pay attention to class :) How...
```python def modPower(a, b, m): if b == 0: return 1 elif b == 1: return a % m t = modPower(a, b // 2, m) if b % 2 == 0: return t % m * t % m % m else: return t % m * t % m * a % m % m for _ in range(int(input())): n = int(input()) print(modPower(2, n, 1000000007) - 1) ```
vfc_137107
{ "difficulty": "medium", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/MCHAIRS", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n1\n2", "output": "1\n3", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1\n4", "output": "1\n15\n", "type": "stdin_stdout" }, { "fn_name": null, "input":...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/add-two-numbers-represented-by-two-arrays2408/1
Solve the following coding problem using the programming language python: Given two array A[0….N-1] and B[0….M-1] of size N and M respectively, representing two numbers such that every element of arrays represent a digit. For example, A[] = { 1, 2, 3} and B[] = { 2, 1, 4 } represent 123 and 214 respectively. The task ...
```python class Solution: def calc_Sum(self, arr, n, brr, m): a = '' b = '' for i in arr: a += str(i) for j in brr: b += str(j) return int(a) + int(b) ```
vfc_137111
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/add-two-numbers-represented-by-two-arrays2408/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "A[] = {1, 2}, B[] = {2, 1}", "output": "33", "type": "stdin_stdout" }, { "fn_name": null, "input": "A[] = {9, 5, 4, 9}, B[] = {2, 1, 4}", "output": "9763", "type": "stdin_stdout" } ...
taco
verifiable_code
https://codeforces.com/problemset/problem/1141/E
Solve the following coding problem using the programming language python: A superhero fights with a monster. The battle consists of rounds, each of which lasts exactly $n$ minutes. After a round ends, the next round starts immediately. This is repeated over and over again. Each round has the same scenario. It is desc...
```python (h, d) = map(int, input().strip().split(' ')) l = list(map(int, input().strip().split(' '))) s = 0 m = 0 ans = 0 for c in l: s += c m = min(m, s) if h + m > 0 and s >= 0: print(-1) exit(0) s = abs(s) if s != 0: ans = (max(0, h + m) + s - 1) // s h -= ans * s ans *= d for i in l: if h <= 0: break h +=...
vfc_137113
{ "difficulty": "medium_hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1141/E", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1000 6\n-100 -200 -300 125 77 -4\n", "output": "9\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1000000000000 5\n-1 0 0 0 0\n", "output": "4999999999996\n", "type": "stdin_st...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/palindrome-in-both-decimal-and-binary4517/1
Solve the following coding problem using the programming language python: Given a number N. check whether a given number N is palindrome or not in it's both formates (Decimal and Binary ). Example 1: Input: N = 7 Output: "Yes" Explanation: 7 is palindrome in it's decimal and also in it's binary (111).So answer is "...
```python class Solution: def isDeciBinPalin(self, n): d = 0 x = '' while n > 0: d = n % 2 x += str(d) n = n // 2 l = x[::-1] n = str(n) if l == x and n == n[::-1]: return 'Yes' return 'No' ```
vfc_137117
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/palindrome-in-both-decimal-and-binary4517/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 7", "output": "\"Yes\"", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/maximum-gap3845/1
Solve the following coding problem using the programming language python: Given an unsorted array Arr of length N. Your task is to find the maximum difference between the successive elements in its sorted form. Return 0 if the array contains less than 2 elements. Example 1: Input: N = 3 Arr[] = {1, 10, 5} Output: 5 Ex...
```python class Solution: def maxSortedAdjacentDiff(self, arr, n): if n < 2: return 0 arr.sort() max_diff = 0 for i in range(1, n): max_diff = max(max_diff, arr[i] - arr[i - 1]) return max_diff ```
vfc_137118
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/maximum-gap3845/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 3\nArr[] = {1, 10, 5}", "output": "5", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/CHECHOC
Solve the following coding problem using the programming language python: Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. You are given a matrix $A$ with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). You need to fill the matrix...
```python t = int(input()) for i in range(t): (n, m, x, y) = map(int, input().split()) if n * m > 1: x = min(x, y) y = min(y, 2 * x) print((n * m + 1) // 2 * x + n * m // 2 * (y - x)) ```
vfc_137119
{ "difficulty": "medium_hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/CHECHOC", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n4 4 4 6\n3 4 4 5", "output": "48\n30", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/CHFCH
Solve the following coding problem using the programming language python: Read problems statements [Mandarin] , [Bengali] , [Hindi] , [Russian] and [Vietnamese] as well. Chef's brother Chefu is a competitive programmer. Every day, he practices for ICPC (International Chefs' Programming Contest) by solving problems. T...
```python from collections import Counter from collections import defaultdict for z in range(int(input())): (n, k) = input().split() (n, k) = (int(n), int(k)) a = list(map(int, input().split())) c = Counter(a) d = defaultdict(list) fl = [] f = 0 for (x, y) in c.items(): if y >= k: f = 1 fl.append(x) if...
vfc_137123
{ "difficulty": "very_hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/CHFCH", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n8 3\n1 2 2 1 3 3 2 1\n5 3\n1 1 2 2 3", "output": "3\n-1", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: Ikta, who hates to lose, has recently been enthusiastic about playing games using the Go board. However, neither Go nor Gomoku can beat my friends at all, so I decided to give a special training to the lesser-known game Phutball. This game is a...
```python def main(): N = 20 M = 15 MP = [[-1] * M for i in range(N)] L = 0 for i in range(N - 1): s = input() for j in range(M): c = s[j] if c == 'O': sx = j sy = i elif c == 'X': MP[i][j] = L L += 1 dd = ((-1, 0), (-1, -1), (0, -1), (1, -1), (1, 0), (1, 1), (0, 1), (-1, 1)) INF = 3...
vfc_137127
{ "difficulty": "unknown_difficulty", "memory_limit": "134.217728 megabytes", "memory_limit_bytes": null, "problem_url": null, "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "...............\n...............\n...............\n...............\n...............\n.........../...\n...............\n...............\n...............\n...............\n...............\n...............\n...............\n.............
taco
verifiable_code
https://codeforces.com/problemset/problem/804/B
Solve the following coding problem using the programming language python: We have a string of letters 'a' and 'b'. We want to perform some operations on it. On each step we choose one of substrings "ab" in the string and replace it with the string "bba". If we have no "ab" as a substring, our job is done. Print the mi...
```python s = input() mod = 10 ** 9 + 7 b = 0 res = 0 for c in s[::-1]: if c == 'b': b += 1 else: res += b b *= 2 res %= mod b %= mod print(res) ```
vfc_137132
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/804/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "ab\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "aab\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "aaaaabaa...
taco
verifiable_code
https://codeforces.com/problemset/problem/1519/B
Solve the following coding problem using the programming language python: There is a $n \times m$ grid. You are standing at cell $(1, 1)$ and your goal is to finish at cell $(n, m)$. You can move to the neighboring cells to the right or down. In other words, suppose you are standing at cell $(x, y)$. You can: move r...
```python t = int(input()) while t > 0: x = input() x = x.split(' ') n = int(x[0]) m = int(x[1]) k = int(x[2]) sum = n - 1 + n * (m - 1) if sum == k: print('YES') else: print('NO') t -= 1 ```
vfc_137136
{ "difficulty": "easy", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1519/B", "time_limit": "2 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n1 1 0\n2 2 2\n2 2 3\n2 2 4\n1 4 3\n100 100 10000\n", "output": "YES\nNO\nYES\nNO\nYES\nNO\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/910/A
Solve the following coding problem using the programming language python: A frog lives on the axis Ox and needs to reach home which is in the point n. She starts from the point 1. The frog can jump to the right at a distance not more than d. So, after she jumped from the point x she can reach the point x + a, where a ...
```python (n, d) = map(int, input().split()) s = input() steps = 0 flag = 0 count = 0 i = 1 while i < n - 1: steps += 1 if s[i] == '1': flag = 1 pos = i if steps == d: if flag == 0: print(-1) break else: steps = 0 flag = 0 i = pos count += 1 i += 1 else: print(count + 1) ```
vfc_137140
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/910/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "8 4\n10010101\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 2\n1001\n", "output": "-1\n", "type": "stdin_stdout" }, { "fn_name": null, ...
taco
verifiable_code
https://www.codechef.com/IARCSJUD/problems/BOOKSORT
Solve the following coding problem using the programming language python: Indraneel has to sort the books in his library. His library has one long shelf. His books are numbered $1$ through $N$ and he wants to rearrange the books so that they appear in the sequence $1,2, ..., N$. He intends to do this by a sequence of ...
```python n = int(input()) arr = [int(x) for x in input().split()] l = [1] * n if sorted(arr) == arr: print('0') else: for i in range(0, len(arr)): for j in range(i): if arr[i] >= arr[j] and l[i] < l[j] + 1: l[i] = l[j] + 1 print(n - max(l)) ```
vfc_137145
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/IARCSJUD/problems/BOOKSORT", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n2 1 4 5 3\n", "output": "2\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/PCJ18B
Solve the following coding problem using the programming language python: Chef has recently been playing a lot of chess in preparation for the ICCT (International Chef Chess Tournament). Since putting in long hours is not an easy task, Chef's mind wanders elsewhere. He starts counting the number of squares with odd si...
```python t = int(input()) for i in range(t): a = 0 n = int(input()) while n > 0: a += n * n n = n - 2 print(a) ```
vfc_137150
{ "difficulty": "medium", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/PCJ18B", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n3\n8\n", "output": "10\n120\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1287/B
Solve the following coding problem using the programming language python: Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this ...
```python import sys def fastio(): from io import StringIO from atexit import register global input sys.stdin = StringIO(sys.stdin.read()) input = lambda : sys.stdin.readline().rstrip('\r\n') sys.stdout = StringIO() register(lambda : sys.__stdout__.write(sys.stdout.getvalue())) fastio() def debug(*var, sep=' '...
vfc_137154
{ "difficulty": "medium", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1287/B", "time_limit": "3 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 3\nSET\nETS\nTSE\n", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 4\nSETE\nETSE\nTSES\n", "output": "0", "type": "stdin_stdout" }, { "fn_name": ...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/minimize-the-heights-i/1
Solve the following coding problem using the programming language python: Given an array arr[] denoting heights of N towers and a positive integer K, you have to modify the height of each tower either by increasing or decreasing them by K only once. Find out what could be the possible minimum difference of the height ...
```python class Solution: def getMinDiff(self, arr, n, k): arr.sort() ans = arr[n - 1] - arr[0] for i in range(1, n): ans = min(ans, max(arr[i - 1] + k, arr[n - 1] - k) - min(arr[0] + k, arr[i] - k)) return ans ```
vfc_137164
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/minimize-the-heights-i/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "K = 2, N = 4\r\nArr[] = {1, 5, 8, 10}", "output": "5", "type": "stdin_stdout" }, { "fn_name": null, "input": "K = 3, N = 5\r\nArr[] = {3, 9, 12, 16, 20}", "output": "11", "type": "stdin_s...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/0f02fb492c69c094d94e806cba6ff8d8cd04d630/1
Solve the following coding problem using the programming language python: Cupid wants to strike maximum houses in Geek Land on Valentine's Day. The houses in Geek Land are arranged in the form of a binary tree. Cupid is standing at target node initially. Find the sum of all nodes within a maximum distance k from targ...
```python class Solution: def solve2(self, p, k): if not p: return if k > 0: self.ans += p.data self.solve2(p.left, k - 1) self.solve2(p.right, k - 1) def solve(self, p, target, k): if not p: return (0, -1) if p.data == target: self.ans += p.data self.solve2(p.left, k) self.solve2(p....
vfc_137169
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/0f02fb492c69c094d94e806cba6ff8d8cd04d630/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n / \\\n 2 9\n / / \\\n 4 5 7\n / \\ / \\\n 8 19 20 11\n / / \\\n 30 40 50\ntar...
taco
verifiable_code
https://codeforces.com/problemset/problem/1485/D
Solve the following coding problem using the programming language python: You are given a matrix a consisting of positive integers. It has n rows and m columns. Construct a matrix b consisting of positive integers. It should have the same size as a, and the following conditions should be met: * 1 ≤ b_{i,j} ≤ 10^6...
```python (n, m) = list(map(int, input().split())) matrix = [] for i in range(n): row = list(map(int, input().split())) matrix.append(row) res = [[0 for i in range(m)] for j in range(n)] for i in range(n): for j in range(m): if (i + j) % 2: res[i][j] = 720720 + matrix[i][j] ** 4 else: res[i][j] = 720720 ...
vfc_137170
{ "difficulty": "hard", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1485/D", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 3\n16 16 11\n16 16 16\n", "output": "720720 786256 720720\n786256 720720 786256\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 2\n1 2\n3 3\n", "output": "720720 720736\n720801 7...
taco
verifiable_code
https://codeforces.com/problemset/problem/245/F
Solve the following coding problem using the programming language python: You've got a list of program warning logs. Each record of a log stream is a string in this format: "2012-MM-DD HH:MM:SS:MESSAGE" (without the quotes). String "MESSAGE" consists of spaces, uppercase and lowercase English letters and characters...
```python (n, m) = list(map(int, input().split(' '))) messages = [] months = [0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] while True: try: s = input() messages.append(s) except: break length = len(messages) pref = [0] for i in range(1, 13): pref.append(pref[i - 1] + months[i]) got = False now = 0 prev =...
vfc_137174
{ "difficulty": "hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/245/F", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "60 3\n2012-03-16 16:15:25: Disk size is\n2012-03-16 16:15:25: Network failute\n2012-03-16 16:16:29: Cant write varlog\n2012-03-16 16:16:42: Unable to start process\n2012-03-16 16:16:43: Disk size is too small\n2012-03-16 16:16:53: ...
taco
verifiable_code
https://codeforces.com/problemset/problem/1618/C
Solve the following coding problem using the programming language python: You are given an array $a$ consisting of $n$ positive integers. You have to choose a positive integer $d$ and paint all elements into two colors. All elements which are divisible by $d$ will be painted red, and all other elements will be painted...
```python import sys from bisect import bisect_left as lb from bisect import bisect_right as rb from collections import deque from queue import PriorityQueue as pq from math import gcd input_ = lambda : sys.stdin.readline().strip('\r\n') ii = lambda : int(input_()) il = lambda : list(map(int, input_().split())) ilf = l...
vfc_137182
{ "difficulty": "easy", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1618/C", "time_limit": "2 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n5\n1 2 3 4 5\n3\n10 5 15\n3\n100 10 200\n10\n9 8 2 6 6 2 8 6 5 4\n2\n1 3\n", "output": "2\n0\n100\n0\n3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n5\n6 5 12 5 16\n", "outp...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/dddb382bd8049d770e6b1c395887fb87d37168c6/1
Solve the following coding problem using the programming language python: Due to the rise of covid-19 cases in India, this year BCCI decided to organize knock-out matches in IPL rather than a league. Today is matchday 3 and it is between Geek's favorite team Royal Challengers Banglore and the most powerful batting te...
```python class Solution: def solve2(self, p, k): if not p: return if k > 0: self.ans += p.data self.solve2(p.left, k - 1) self.solve2(p.right, k - 1) def solve(self, p, target, k): if not p: return (0, -1) if p.data == target: self.ans += p.data self.solve2(p.left, k) self.solve2(p....
vfc_137186
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/dddb382bd8049d770e6b1c395887fb87d37168c6/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\r\n / \\\r\n 2 9\r\n / / \\\r\n 4 5 7\r\n / \\ / \\\r\n 8 19 20 11\r\n / / \\\r\n 3...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/51b266505221b97522b1d2c86ddad1868a54831b/1
Solve the following coding problem using the programming language python: There is a row of N walls in Geeksland. The king of Geeksland ordered Alexa to color all the walls on the occasion of New Year. Alexa can color each wall with either pink, black, or yellow. The cost associated with coloring each wall with a part...
```python class Solution: def minCost(self, colors, N): (pink, black, yellow) = (0, 0, 0) for (p, b, y) in colors: (pink, black, yellow) = (p + min(black, yellow), b + min(pink, yellow), y + min(pink, black)) return min(pink, black, yellow) ```
vfc_137187
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/51b266505221b97522b1d2c86ddad1868a54831b/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 3\r\ncolors[][] = {{14, 2, 11},\r\n {11, 14, 5},\r\n {14, 3, 10}}", "output": "10", "type": "stdin_stdout" }, { "fn_name": null, "input": "N = 2\r\ncolors[][] = {{1, 2, 3}...
taco
verifiable_code
https://www.codechef.com/COTS2020/problems/CDCUR01
Solve the following coding problem using the programming language python: Mance Rayder, the King-Beyond-the-Wall, has always wanted to lead the largest army the North has ever seen against the NIght’s Watch. For this humungous feat he has banded the waring tribes, the Giants, Thenns and Wildings, together by going to ...
```python n = int(input()) for i in range(n): a = list(map(int, input().split())) a.sort() if a[0] + a[1] >= a[2] - 1: print('Yes') else: print('No') ```
vfc_137188
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/COTS2020/problems/CDCUR01", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n1 2 1\n", "output": "Yes\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: There are N towns in JOI, which are connected by M bidirectional roads. There are shopping malls in K towns, and the people go to one of those towns through the road to shop. Depending on the location of your home, you may have to travel long d...
```python from heapq import heappop as pop from heapq import heappush as push INF = 10 ** 18 class edge: def __init__(self, to, cost): self.to = to self.cost = cost (N, M, K) = map(int, input().split()) G = [[] for i in range(N)] d = [INF for i in range(N)] def dijkstra(lst): que = [] for s in lst: d[s] = 0...
vfc_137193
{ "difficulty": "unknown_difficulty", "memory_limit": "134.217728 megabytes", "memory_limit_bytes": null, "problem_url": null, "time_limit": "8.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 3 1\n1 2 1\n2 3 1\n3 1 1\n1", "output": "2\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.hackerrank.com/challenges/validating-credit-card-number/problem
Solve the following coding problem using the programming language python: You and Fredrick are good friends. Yesterday, Fredrick received $N$ credit cards from ABCD Bank. He wants to verify whether his credit card numbers are valid or not. You happen to be great at regex so he is asking for your help! A valid credit ...
```python import re for _ in range(int(input())): number = input().strip() if len(number) != 16 and len(number) != 19: print('Invalid') continue if number[0] not in '456': print('Invalid') continue if re.search('[^0-9\\-]', number): print('Invalid') continue if len(number) == 19 and (not bool(re.search...
vfc_137197
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.hackerrank.com/challenges/validating-credit-card-number/problem", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n4123456789123456\n5123-4567-8912-3456\n61234-567-8912-3456\n4123356789123456\n5133-3367-8912-3456\n5123 - 3567 - 8912 - 3456\n", "output": "Valid\nValid\nInvalid\nValid\nInvalid\nInvalid\n", "type": "stdin_stdout" ...
taco
verifiable_code
Solve the following coding problem using the programming language python: Example Input 2 4 %.@\$ ..\$\$ Output Yes The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python import queue di = [0, 1, 0, -1] dj = [1, 0, -1, 0] (h, w) = map(int, input().split()) field = [input() for i in range(h)] pdist = [[1000] * w for i in range(h)] sdist = [[1000] * w for i in range(h)] pque = queue.Queue() sque = queue.Queue() for (i, row) in enumerate(field): for j in range(w): if row[j] is...
vfc_137201
{ "difficulty": "unknown_difficulty", "memory_limit": "536.870912 megabytes", "memory_limit_bytes": null, "problem_url": null, "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 4\n%.\\@$\n..\\$\\$", "output": "Yes\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 4\n%.\\@$\n$\\$\\..", "output": "No\n", "type": "stdin_stdout" }, { "fn_n...
taco
verifiable_code
Solve the following coding problem using the programming language python: Twins square1001 and E869120 are twins. Please output the one that was born first. input No input is given. output Output the correct character string on one line. However, insert a line break at the end. Output example 1 square1001 ...
```python print('square1001') ```
vfc_137205
{ "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": "", "output": "", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: If the strings are consecutive, you can replace the characters with a rule to shorten the string. For example, for the string AAAA, the expression @ 4A will compress one character. Create a program that restores the character string compressed b...
```python while True: try: s = input() except EOFError: break r = '' n = 1 for c in s: if n < 0: n = int(c) elif c == '@': n = -1 else: r += c * n n = 1 print(r) ```
vfc_137209
{ "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": "ab@5C1@8050\n@99,1=1@90", "output": "abCCCCC10000000050\n999999999,1=1000000000", "type": "stdin_stdout" }, { "fn_name": null, "input": "ab@5C2@8050\n@99,1=1@90", "output": "abCCCCC20000000050\...
taco
verifiable_code
https://codeforces.com/problemset/problem/75/B
Solve the following coding problem using the programming language python: Facetook is a well known social network website, and it will launch a new feature called Facetook Priority Wall. This feature will sort all posts from your friends according to the priority factor (it will be described). This priority factor wi...
```python from collections import defaultdict (u, p) = (input(), defaultdict(int)) for i in range(int(input())): t = input().split() (a, k) = (t[0], t[1][0]) if k == 'p': (b, d) = (t[3][:-2], 15) elif k == 'c': (b, d) = (t[3][:-2], 10) else: (b, d) = (t[2][:-2], 5) if a == u: p[b] += d elif b == u: p[a...
vfc_137213
{ "difficulty": "medium", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/75/B", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "post\n9\npost posted on wall's wall\non commented on post's post\npost likes likes's post\ncommented posted on post's wall\npost commented on likes's post\nlikes likes post's post\npost posted on posted's wall\non commented on post...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/compare-two-fractions4438/1
Solve the following coding problem using the programming language python: Given two fractions a/b and c/d, compare them and print the larger of the two. Example 1: Input: s = "5/6, 11/45" Output: 5/6 Explanation: 5/6=0.8333... and 11/45=0.2444.... Clearly, 5/6 is greater, so we output it. Example 2: Input: s = "8/1...
```python class Solution: def compareFrac(self, s): a = '' for i in range(len(s)): if s[i] == '/': break else: a = a + s[i] b = '' for j in range(i + 1, len(s)): if s[j] == ',': break b = b + s[j] c = '' for k in range(j + 2, len(s)): if s[k] == '/': break c = c + s[k] ...
vfc_137217
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/compare-two-fractions4438/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "s = \"5/6, 11/45\"", "output": "5/6", "type": "stdin_stdout" }, { "fn_name": null, "input": "s = \"8/1, 8/1\"", "output": "equal", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/547/A
Solve the following coding problem using the programming language python: Mike has a frog and a flower. His frog is named Xaniar and his flower is named Abol. Initially(at time 0), height of Xaniar is h_1 and height of Abol is h_2. Each second, Mike waters Abol and Xaniar. [Image] So, if height of Xaniar is h_1 an...
```python f = lambda : map(int, input().split()) m = int(input()) def g(): (h, a) = f() (x, y) = f() t = lambda : (h * x + y) % m (s, d) = (0, 1) while h != a: h = t() s += 1 if s > m: print(-1) exit() h = t() while h != a: h = t() d += 1 if d > m: return (s, 0) return (s, d) def h(): (u...
vfc_137218
{ "difficulty": "hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/547/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n4 2\n1 1\n0 1\n2 3\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1023\n1 2\n1 0\n1 2\n1 1\n", "output": "-1\n", "type": "stdin_stdout" }, { ...
taco
verifiable_code
Solve the following coding problem using the programming language python: Jesse and Walter recently got a into a problem. They need to check if a compound can be converted to the other one. A compound is decoded into a binary strings of 0s and 1s. They have 2 binary strings. First string contains characters '0', '1' a...
```python t=eval(input()) for k in range(t): counter=0 s1=input() s2=input() s1=list(s1) s2=list(s2) a1=s1.count('1') b1=s1.count('0') c1=s1.count('?') a2=s2.count('1') b2=s2.count('0') if a2<a1: print('Case %d: -1'%(k+1)) continue temp=a2-a1 c=0 for i in range(len(s1)): if s1[i]=='?' and s2[i]=='1'...
vfc_137222
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "200\n01?0001?0??1100000000110???1011010111101010?100?11??010?1???0000000110???1010010??00\n101010000011110111111110000100111101110110010111101110000100010100010110101100111100\n?101??0101?1000??????10011????0?100111?10?01\n11011000...
taco
verifiable_code
https://www.hackerrank.com/challenges/ants/problem
Solve the following coding problem using the programming language python: N ants are in a circular race. The length of the race is 1000 meters and ant number i is initially Vi meters far from starting point (point 0) of the race in clockwise order. All the ants walk with a speed of 0.1 meters per second, some of them ...
```python N = int(input()) V = [int(i) for i in input().strip().split()] V.sort() noOfLaps = 10 ** 5 * 2 efR = 6 result = 2 * noOfLaps * (N // 2) * (N - N // 2) pause = 0 for i in range(N - 1): if pause != 1: if V[i] + 1 == V[i + 1]: result += 2 pause = 1 else: pause = 0 else: pause = 0 print(result) ...
vfc_137226
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.hackerrank.com/challenges/ants/problem", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n0 500\n", "output": "400000 \n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/RJBIAS
Solve the following coding problem using the programming language python: Reyaan has given you the following problem to solve: You are given an integer K in base B, represented by an array A of length N such that 0 ≤ A_{i} < B for every 1 ≤ i ≤ N \sum_{i=1}^N A_{i} \cdot B^{N-i} = K Note that N ≤ B in this problem. ...
```python modulus = 10 ** 9 + 7 def itable_to_multiset(s): rv = {} for x in s: rv[x] = rv.get(x, 0) + 1 return rv def answer(b, finish, start, m): assert len(start) == len(finish) rv = 0 for (s, f) in zip(start, finish): rv *= b rv %= m rv += f - s return rv % m t = int(input()) for _ in range(t): (n,...
vfc_137234
{ "difficulty": "very_hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/RJBIAS", "time_limit": "2 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n4 4\n3 1 0 2\n4 5\n1 2 3 4\n2 2\n1 1\n1 3\n2\n", "output": "0\n500\n1\n9\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: Advanced Creative Mobile (ACM) has decided to develop a GUI application to be installed in a new portable computer. As shown in the figure below, the GUI has a nested structure in which it has one main panel, several panels are arranged on it, ...
```python class Panel: def __init__(self, name, points, children): self.name = name self.x1 = points[0] self.x2 = points[2] self.y1 = points[1] self.y2 = points[3] self.children = children self.child_cnt = len(children) def search(self, x, y): if not (self.x1 <= x <= self.x2 and self.y1 <= y <= self...
vfc_137238
{ "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": "5\n<main>10,10,190,150<menu>20,20,70,140</menu><primary>80,20,180,140</primary></main>\n10 10\n15 15\n40 60\n1 3\n130 80\n0", "output": "main 2\nmain 2\nmenu 0\nOUT OF MAIN PANEL 1\nprimary 0\n", "type": "stdin_stdout" ...
taco
verifiable_code
https://codeforces.com/problemset/problem/1515/C
Solve the following coding problem using the programming language python: Phoenix has $n$ blocks of height $h_1, h_2, \dots, h_n$, and all $h_i$ don't exceed some value $x$. He plans to stack all $n$ blocks into $m$ separate towers. The height of a tower is simply the sum of the heights of its blocks. For the towers t...
```python t = int(input()) for i in range(t): (n, m, x) = map(int, input().split()) lst = list(map(int, input().split())) lst1 = [] for j in range(n): lst1.append((lst[j], j)) lst1.sort(key=lambda y: y[0]) dic = {} for j in lst1: dic[j] = -1 q = n // m ind = 0 c = 1 for h in range(q * m): dic[lst1[ind]...
vfc_137242
{ "difficulty": "medium", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1515/C", "time_limit": "2 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n5 2 3\n1 2 3 1 2\n4 3 3\n1 1 2 3\n", "output": "YES\n1 2 1 2 2 \nYES\n1 2 3 1 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n5 2 3\n1 2 3 1 2\n4 3 3\n1 1 2 3\n", "output": "Y...
taco
verifiable_code
https://codeforces.com/problemset/problem/1766/C
Solve the following coding problem using the programming language python: Sir Monocarp Hamilton is planning to paint his wall. The wall can be represented as a grid, consisting of $2$ rows and $m$ columns. Initially, the wall is completely white. Monocarp wants to paint a black picture on the wall. In particular, he ...
```python import sys input = sys.stdin.readline def sol(n, a, b): wall = [a, b] ind = 0 check = True for i in range(n): if wall[ind][i] != 'B': check = False break elif wall[ind ^ 1][i] == 'B': ind ^= 1 if check: return 'YES' ind = 1 check = True for i in range(n): if wall[ind][i] != 'B': c...
vfc_137246
{ "difficulty": "easy", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1766/C", "time_limit": "2 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n3\nWBB\nBBW\n1\nB\nB\n5\nBWBWB\nBBBBB\n2\nBW\nWB\n5\nBBBBW\nBWBBB\n6\nBWBBWB\nBBBBBB\n", "output": "YES\nYES\nNO\nNO\nNO\nYES\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: Problem : Bajirao is on a date with his girlfriend Avni. It is a romantic night and they are playing a game of words. The rule of this game is that if Bajirao says a word such that no adjacent letters occurring in the word are same then he ge...
```python t=int(eval(input(""))) for i in range(0,t): n=str(input("")) D=True for j in range(0,len(n)-1): if(n[j]==n[j+1]): D=False break if D: print("KISS") else: print("SLAP") ```
vfc_137259
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "8\npzlloxqta\nmmawv\nxugr\nhmzuwtw\nzftqloae\nhqkstlguy\ncukjs\nerlco", "output": "KISS\nKISS\nKISS\nKISS\nKISS\nKISS\nKISS\nKISS\nKISS\nKISS\nKISS\nKISS\nKISS\nKISS\nSLAP\nKISS\nKISS\nKISS\nKISS\nKISS\nKISS\nKISS\nKISS\nKISS...
taco
verifiable_code
https://codeforces.com/problemset/problem/1152/B
Solve the following coding problem using the programming language python: Cat Furrier Transform is a popular algorithm among cat programmers to create longcats. As one of the greatest cat programmers ever exist, Neko wants to utilize this algorithm to create the perfect longcat. Assume that we have a cat with a numbe...
```python import sys x = int(input()) def solve(cnt, odds): print(cnt) print(' '.join(list(map(str, odds)))) sys.exit(0) odds = [] cnt = 0 xb = list(bin(x)[2:]) n = len(xb) if x == 0 or x ^ int(2 ** n - 1) == 0: solve(cnt, odds) while True: xb = list(bin(x)[2:]) n = len(xb) for i in range(len(xb)): if xb[i] =...
vfc_137263
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1152/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "39\n", "output": "4\n5 3 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "7\n", ...
taco
verifiable_code
https://codeforces.com/problemset/problem/1281/E
Solve the following coding problem using the programming language python: Welcome! Everything is fine. You have arrived in The Medium Place, the place between The Good Place and The Bad Place. You are assigned a task that will either make people happier or torture them for eternity. You have a list of $k$ pairs of p...
```python import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = 'x' in file.mode or 'r' not in file.mode self.write = self.buffer.write if self.writable else None def ...
vfc_137267
{ "difficulty": "hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1281/E", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n3\n1 2 3\n3 2 4\n2 4 3\n4 5 6\n5 6 5\n2\n1 2 1\n1 3 2\n1 4 3\n", "output": "15 33\n6 6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n1\n2 1 4\n", "output": "4 4\n", "ty...
taco
verifiable_code
https://www.hackerrank.com/challenges/contacts/problem
Solve the following coding problem using the programming language python: We're going to make our own Contacts application! The application must perform two types of operations: add name, where $name$ is a string denoting a contact name. This must store $name$ as a new contact in the application. find partial, wher...
```python import sys import time import queue class Node: __slots__ = ['is_leaf', 'value', 'left', 'right', 'mid', 'count'] def __str__(self): return 'value: ' + self.value + ', mid: ' + str(self.mid) + ', left: ' + str(self.left) + ', right: ' + str(self.right) def __init__(self): self.is_leaf = False self...
vfc_137271
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.hackerrank.com/challenges/contacts/problem", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "STDIN Function\n----- --------\n4 queries[] size n = 4\nadd hack queries = ['add hack', 'add hackerrank', 'find hac', 'find hak']\nadd hackerrank\nfind hac\nfind hak\n", "output": "2\n...
taco
verifiable_code
https://codeforces.com/problemset/problem/1091/A
Solve the following coding problem using the programming language python: Alice and Bob are decorating a Christmas Tree. Alice wants only $3$ types of ornaments to be used on the Christmas Tree: yellow, blue and red. They have $y$ yellow ornaments, $b$ blue ornaments and $r$ red ornaments. In Bob's opinion, a Chris...
```python (A, B, C) = map(int, input().split()) if B >= C: B = C - 1 if A < B - 1: B = A + 1 print(3 * B) ```
vfc_137275
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1091/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "8 13 9\n", "output": "24", "type": "stdin_stdout" }, { "fn_name": null, "input": "13 3 6\n", "output": "9", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 8 ...
taco
verifiable_code
https://codeforces.com/problemset/problem/1462/C
Solve the following coding problem using the programming language python: You are given a positive number $x$. Find the smallest positive integer number that has the sum of digits equal to $x$ and all digits are distinct (unique). -----Input----- The first line contains a single positive integer $t$ ($1 \le t \le 5...
```python n = int(input()) arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 19, 29, 39, 49, 59, 69, 79, 89, 189, 289, 389, 489, 589, 689, 789, 1789, 2789, 3789, 4789, 5789, 6789, 16789, 26789, 36789, 46789, 56789, 156789, 256789, 356789, 456789, 1456789, 2456789, 3456789, 13456789, 23456789, 123456789] for _ in range(n): x = int(...
vfc_137280
{ "difficulty": "easy", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1462/C", "time_limit": "2 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n1\n5\n15\n50\n", "output": "1\n5\n69\n-1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "50\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n2...
taco
verifiable_code
https://codeforces.com/problemset/problem/1714/B
Solve the following coding problem using the programming language python: Polycarp was presented with some sequence of integers $a$ of length $n$ ($1 \le a_i \le n$). A sequence can make Polycarp happy only if it consists of different numbers (i.e. distinct numbers). In order to make his sequence like this, Polycarp ...
```python def Solve(): (ns, A) = ([], []) for t in range(int(input())): ns.append(int(input())) A.append(list(map(int, input().split()))) for (n, a) in zip(ns, A): s = set() for i in a[::-1]: if i not in s: s.add(i) else: print(n - len(s)) break else: print(0) Solve() ```
vfc_137284
{ "difficulty": "easy", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1714/B", "time_limit": "2 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n4\n3 1 4 3\n5\n1 1 1 1 1\n1\n1\n6\n6 5 4 3 2 1\n7\n1 2 1 7 1 2 1\n", "output": "1\n4\n0\n0\n5\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n6\n1 1 4 5 1 4\n", "output": "3\n"...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/good-numbers4629/1
Solve the following coding problem using the programming language python: Given two positive integers L, R and a digit D, find out all the good numbers in the range [L, R], which do not contain the digit D. A number is a good number if it's every digit is larger than the sum of digits which are on the right side of th...
```python class Solution: def goodNumbers(self, L, R, D): ans = [] for el in range(L, R + 1): par_el = el cnt = 0 if D == 0 and par_el == 0: continue boo = True first = False while par_el > 0: num = par_el % 10 if num == D or par_el == D or par_el <= cnt: if par_el != 0: b...
vfc_137288
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/good-numbers4629/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "L=200\r\nR=700\r\nD=4", "output": "{210, 310, 320, 510, 520, 521, 530, 531,\r\n610, 620, 621, 630, 631, 632, 650}", "type": "stdin_stdout" }, { "fn_name": null, "input": "L=100\r\nR=500\r\nD=5", ...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/demonitisation0013/1
Solve the following coding problem using the programming language python: Given a String S. Your task is to remove the given two strings(M and N) completely from the given string S. If String is completely removed then print -1. Example 1: Input: S = abc m = ab n = bc Output: -1 Explanation: When we remove the two str...
```python class Solution: def demonitize(self, S, m, n): S1 = S.replace(m, '') S2 = S.replace(n, '') S11 = S1.replace(n, '') S22 = S2.replace(m, '') result = '' for i in S11: if i in S22: result += i return result if len(result) else -1 ```
vfc_137299
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/demonitisation0013/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "S = abc\r\nm = ab\r\nn = bc", "output": "-1", "type": "stdin_stdout" }, { "fn_name": null, "input": "S = abbbccab \r\nm = ab\r\nn = bcc", "output": "b", "type": "stdin_stdout" }, ...
taco
verifiable_code
https://www.codechef.com/QTCC2020/problems/VIEW2005
Solve the following coding problem using the programming language python: -----General Statement:----- Given the actual high and low temperatures for the day and the normal high and low temperatures for that day, calculate the average difference from normal. -----Input:----- The first line of the data set for this pr...
```python for _ in range(int(input())): (x1, y1, x2, y2) = map(int, input().split()) av1 = (x1 + y1) / 2 av2 = (x2 + y2) / 2 if av1 > av2: print(av1 - av2, ' DEGREE(S) ABOVE NORMAL') else: print(av2 - av1, ' DEGREE(S) BELOW NORMAL') ```
vfc_137300
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/QTCC2020/problems/VIEW2005", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n75 45 78 40\n50 32 45 30\n56 48 62 45\n", "output": "1.0 DEGREE(S) ABOVE NORMAL\n3.5 DEGREE(S) ABOVE NORMAL\n1.5 DEGREE(S) BELOW NORMAL\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: Amer cabs has released a scheme through which a user gets a free drive when he shares a reference code with another Amer app user. Given N number of app users, output total number of free drives gained by all of them. Two same users cannot share...
```python ''' # Read input from stdin and provide input before running code name = raw_input('What is your name?\n') print 'Hi, %s.' % name ''' x=eval(input()) while x: y=eval(input()) print((y)*(y-1)/2) x=x-1 ```
vfc_137304
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "684\n2924\n7062\n7105\n4716\n9111\n6913\n1421\n9429\n2378\n4540\n9243\n544\n2898\n298\n6607\n4585\n1940\n8635\n5490\n8456\n4913\n5788\n9975\n9536\n1810\n5396\n103\n7349\n438\n1916\n1105\n8690\n6767\n1869\n8552\n4652\n5591\n890\n449...
taco
verifiable_code
https://codeforces.com/problemset/problem/1669/A
Solve the following coding problem using the programming language python: Codeforces separates its users into $4$ divisions by their rating: For Division 1: $1900 \leq \mathrm{rating}$ For Division 2: $1600 \leq \mathrm{rating} \leq 1899$ For Division 3: $1400 \leq \mathrm{rating} \leq 1599$ For Division 4: $\math...
```python from sys import stdin from math import log, floor, ceil, gcd from collections import defaultdict as dd input = stdin.readline inp = lambda : int(stdin.readline()) rs = lambda : stdin.readline().strip() def ra(typ): return list(map(typ, stdin.readline().split())) def rv(typ): return map(typ, stdin.readline...
vfc_137308
{ "difficulty": "easy", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1669/A", "time_limit": "1 second" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7\n-789\n1299\n1300\n1399\n1400\n1679\n2300\n", "output": "Division 4\nDivision 4\nDivision 4\nDivision 4\nDivision 3\nDivision 2\nDivision 1\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/minimal-summing-up4253/1
Solve the following coding problem using the programming language python: For a positive, non-zero integer N, find the minimum count of numbers of the form X^{(i-1)}, where X is a given non-zero, non-negative integer raised to the power i-1 where (1 ≤ i ≤ 12), so that they sum up to form the number N exactly. Example ...
```python class Solution: def minimalSum(self, N, X): count = 0 i = 11 while N > 0: if N >= X ** i: N = N - X ** i count += 1 else: i -= 1 return count ```
vfc_137312
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/minimal-summing-up4253/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 10, X = 2", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "N = 38, X = 3", "output": "4", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1043/B
Solve the following coding problem using the programming language python: Bajtek, known for his unusual gifts, recently got an integer array $x_0, x_1, \ldots, x_{k-1}$. Unfortunately, after a huge array-party with his extraordinary friends, he realized that he'd lost it. After hours spent on searching for a new toy,...
```python n = int(input()) a = list(map(int, input().split())) diff = [a[0]] for i in range(n - 1): diff.append(a[i + 1] - a[i]) out = '' count = 0 for i in range(1, n + 1): good = True for j in range(n - i): if diff[j] != diff[j + i]: good = False if good: count += 1 out += str(i) + ' ' print(count) print...
vfc_137313
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1043/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n1 2 3 4 5\n", "output": "5\n1 2 3 4 5 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n1 3 5 6 8\n", "output": "2\n3 5 ", "type": "stdin_stdout" }, { "fn_name...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/letter-writer0420/1
Solve the following coding problem using the programming language python: Geek works at the post office and he writes the following types of letters. Corporate Letters: 12 letters of this type can be written in an hour. Informal Letters: 10 letters of this type can be written in an hour. Given N number of letters, f...
```python class Solution: def minHours(self, N): if N % 12 == 0: return N // 12 c = 0 while N > 0: if N % 12 == 0: c = c + N // 12 return c N = N - 10 c = c + 1 if N == 0: return c return -1 ```
vfc_137317
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/letter-writer0420/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 33", "output": "-1", "type": "stdin_stdout" }, { "fn_name": null, "input": "N = 36", "output": "3", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1736/B
Solve the following coding problem using the programming language python: You are given an integer array $a$ of length $n$. Does there exist an array $b$ consisting of $n+1$ positive integers such that $a_i=\gcd (b_i,b_{i+1})$ for all $i$ ($1 \leq i \leq n$)? Note that $\gcd(x, y)$ denotes the greatest common diviso...
```python import math for s in [*open(0)][2::2]: a = (*map(int, s.split()),) print('YNEOS'[any((y % math.gcd(x, z) for (x, y, z) in zip(a, a[1:], a[2:])))::2]) ```
vfc_137318
{ "difficulty": "easy", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1736/B", "time_limit": "1 second" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n1\n343\n2\n4 2\n3\n4 2 4\n4\n1 1 1 1\n", "output": "YES\nYES\nNO\nYES\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/174/B
Solve the following coding problem using the programming language python: Eudokimus, a system administrator is in trouble again. As a result of an error in some script, a list of names of very important files has been damaged. Since they were files in the BerFS file system, it is known that each file name has a form "...
```python s = input() n = len(s) a = s.find('.') b = s.rfind('.') from sys import exit if a == b == -1: print('NO') exit() if a == 0 or n - b - 1 == 0: print('NO') exit() if not 0 < a < 9 or not 0 < n - b - 1 < 4: print('NO') exit() s2 = s[a + 1:b + 1] res = [s[:a + 1]] app = res.append (length, item) = (0, '') f...
vfc_137322
{ "difficulty": "medium", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/174/B", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "ph..qlr.pt\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "aa.aa.aaaabbbbccc.ddd.ee\n", "output": "YES\naa.a\na.aaa\nabbbbccc.d\ndd.ee\n", "type": "stdin_stdo...
taco
verifiable_code
https://codeforces.com/problemset/problem/1092/A
Solve the following coding problem using the programming language python: You are given two integers $n$ and $k$. Your task is to construct such a string $s$ of length $n$ that for each $i$ from $1$ to $k$ there is at least one $i$-th letter of the Latin alphabet in this string (the first letter is 'a', the second is...
```python t = int(input()) al = 'abcdefghijklmnopqrstuvwxyz' for i in range(t): (n, k) = list(map(int, input().split())) l = n // k s = al[:k] * l s += al[:n % k] print(s) ```
vfc_137326
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1092/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n7 3\n4 4\n6 2\n", "output": "abcabca\nabcd\nababab\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "66\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 ...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/sum-of-two-numbers-without-using-arithmetic-operators/1
Solve the following coding problem using the programming language python: Given two integers a and b. Find the sum of two numbers without using arithmetic operators. Example 1: Input: a = 5, b = 3 Output: 8 Explanation : 5 + 3 = 8 Example 2: Input: a = 10, b = 30 Output: 40 Explanation: 10 + 30 = 40 Your task: You don...
```python def sum(a, b): while b != 0: c = a & b a = a ^ b b = c << 1 return a ```
vfc_137331
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/sum-of-two-numbers-without-using-arithmetic-operators/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": "sum", "input": "a = 5, b = 3", "output": "8", "type": "function_call" } ] }
taco
verifiable_code
https://www.codechef.com/problems/STONED
Solve the following coding problem using the programming language python: In a country Stone Land, there are $N$ stones arranged in a row from left to right. Each stone has some height represented by a positive number. The stones are numbered from $1$ to $N$ from left to right. You are given an array H of size $N$ co...
```python from sys import stdin, stdout input = stdin.readline class SegmentTree: def __init__(self, data, default=[-float('inf'), -1], func=max): self._default = default self._func = func self._len = len(data) self._size = _size = 1 << (self._len - 1).bit_length() self.data = [default] * (2 * _size) sel...
vfc_137332
{ "difficulty": "very_hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/STONED", "time_limit": "2 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n6 6\n3 10 20 20 5 50\n1 2\n2 4\n4 3\n4 5\n1 3\n4 4\n", "output": "2\n1\n1\n1\n1\n1\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1130/D1
Solve the following coding problem using the programming language python: This is a simplified version of the task Toy Train. These two versions differ only in the constraints. Hacks for this version are disabled. Alice received a set of Toy Train™ from Bob. It consists of one train and a connected railway network of...
```python from collections import defaultdict as dd (n, m) = [int(i) for i in input().split(' ')] a = [] b = [] def fnx(i, j): if i < j: return j - i else: return n - i + j def fnr(r): if r % n == 0: return n else: return r % n for i in range(m): (x, y) = [int(i) for i in input().split(' ')] a.append(x)...
vfc_137336
{ "difficulty": "medium_hard", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1130/D1", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "50 20\n45 33\n44 7\n31 41\n45 12\n3 13\n18 17\n3 39\n31 11\n31 1\n44 7\n44 23\n18 46\n44 1\n45 6\n31 22\n18 13\n31 22\n45 8\n45 17\n18 43\n", "output": "255 254 253 252 251 250 249 248 247 246 245 244 243 242 241 240 239 238 ...
taco
verifiable_code
https://www.codechef.com/COOK64/problems/SEAARASU
Solve the following coding problem using the programming language python: Sereja has an array A of N positive integers : A[1], A[2], A[3], ... , A[N]. In a single operation on the array, he performs the following two steps : - Pick two indices i, j s.t. A[i] > A[j] - A[i] -= A[j] Sereja can apply these operation...
```python def gcd(a, b): if b == 0: return a else: return gcd(b, a % b) def main(): t = int(input()) while t != 0: t = t - 1 n = int(input()) if n == 1: print(input()) else: a = list(map(int, input().split(' '))) p = a[0] for i in range(1, n): p = gcd(p, a[i]) if p == 1: break ...
vfc_137340
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/COOK64/problems/SEAARASU", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n1\n1\n3\n2 4 6\n", "output": "1\n6\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/365/C
Solve the following coding problem using the programming language python: You have a string of decimal digits s. Let's define bij = si·sj. Find in matrix b the number of such rectangles that the sum bij for all cells (i, j) that are the elements of the rectangle equals a in each rectangle. A rectangle in a matrix is ...
```python def divisors(x): def f(y, q): t = -len(r) while not y % q: y //= q for i in range(t, 0): r.append(r[t] * q) return y (r, p) = ([1], 7) x = f(f(f(x, 2), 3), 5) while x >= p * p: for s in (4, 2, 4, 2, 4, 6, 2, 6): if not x % p: x = f(x, p) p += s if x > 1: f(x, x) return r ...
vfc_137346
{ "difficulty": "medium_hard", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/365/C", "time_limit": "1.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n39568795337451783387623217888229492030389256605973002137\n", "output": "9\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n0\n", "output": "0\n", "type": "stdin_stdout" ...
taco
verifiable_code
Solve the following coding problem using the programming language python: Roy has a matrix of size NxN. Rows and Columns are numbered from 0 to N-1. jth column of ith row contains absolute difference between i and j. In other words, Matrix[i][j] = abs(i-j) where 0 ≤ i, j < N. Your task is to find sum of this matri...
```python n = eval(input()) d = lambda n: n * (n+1) while n: n -= 1 s = 0 i, m = 1, eval(input()) while i<m: s += d(i) i += 1 print(s) ```
vfc_137350
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n", "output": "2645244288782128\n29678527040851590\n35857694872733032\n18148944686232360\n31745376825350988\n9293841102654590\n2960053127235120\n4403120141965160\n7741500746824440\n2515784224...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/swap-and-maximize5859/1
Solve the following coding problem using the programming language python: Given an array a[ ] of N elements. Consider array as a circular array i.e. element after a_{n} is a_{1}. The task is to find maximum sum of the absolute difference between consecutive elements with rearrangement of array elements allowed i.e. af...
```python def maxSum(arr, n): ans = [] arr = sorted(arr) (i, j) = (0, len(arr) - 1) while i < j: ans.append(arr[i]) ans.append(arr[j]) i += 1 j -= 1 if i == j: ans.append(arr[i]) final_ans = 0 for i in range(1, len(ans)): final_ans += abs(ans[i] - ans[i - 1]) final_ans += abs(ans[-1] - ans[0]) retu...
vfc_137354
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/swap-and-maximize5859/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": "maxSum", "input": "N = 4\na[] = {4, 2, 1, 8}", "output": "18", "type": "function_call" }, { "fn_name": "maxSum", "input": "N = 2\na[] = {10, 12}", "output": "4", "type": "function_call" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1174/D
Solve the following coding problem using the programming language python: Given two integers $n$ and $x$, construct an array that satisfies the following conditions: for any element $a_i$ in the array, $1 \le a_i<2^n$; there is no non-empty subsegment with bitwise XOR equal to $0$ or $x$, its length $l$ should be ...
```python (n, x) = map(int, input().split()) nn = 2 ** n if x >= nn: x = 0 ans = [] for i in range(n): oks = [True] * nn oks[x] = False cur = 0 for j in ans[::-1]: cur ^= j oks[cur] = False oks[cur ^ x] = False try: a = next((j for (j, ok) in enumerate(oks[1:], 1) if ok)) except StopIteration: break a...
vfc_137355
{ "difficulty": "hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1174/D", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 5\n", "output": "3\n6 1 3", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 4\n", "output": "3\n1 3 1 ", "type": "stdin_stdout" }, { "fn_name": null, "input...
taco
verifiable_code
https://www.hackerrank.com/challenges/stockmax/problem
Solve the following coding problem using the programming language python: Your algorithms have become so good at predicting the market that you now know what the share price of Wooden Orange Toothpicks Inc. (WOT) will be for the next number of days. Each day, you can either buy one share of WOT, sell any number of sh...
```python test = int(input()) for i in range(test): n = int(input()) a = list(map(int, input().split())) c = 0 i = len(a) - 1 while i >= 0: d = a[i] l = i p = 0 while a[i] <= d and i >= 0: p += a[i] i -= 1 c += (l - i) * a[l] - p continue print(c) ```
vfc_137363
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.hackerrank.com/challenges/stockmax/problem", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n3\n5 3 2\n3\n1 2 100\n4\n1 3 1 2", "output": "0\n197\n3\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/999/B
Solve the following coding problem using the programming language python: A string $s$ of length $n$ can be encrypted by the following algorithm: iterate over all divisors of $n$ in decreasing order (i.e. from $n$ to $1$), for each divisor $d$, reverse the substring $s[1 \dots d]$ (i.e. the substring which starts at...
```python n = int(input()) s = input().strip() for i in range(2, n + 1): if n % i == 0: s = s[:i][::-1] + s[i:] print(s) ```
vfc_137367
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/999/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10\nrocesfedoc\n", "output": "codeforces\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "16\nplmaetwoxesisiht\n", "output": "thisisexampletwo\n", "type": "stdin_stdout" }, ...