source
stringclasses
4 values
task_type
stringclasses
1 value
in_source_id
stringlengths
0
138
problem
stringlengths
219
13.2k
gold_standard_solution
stringlengths
0
413k
problem_id
stringlengths
5
10
metadata
dict
verification_info
dict
taco
verifiable_code
https://codeforces.com/problemset/problem/1385/F
Solve the following coding problem using the programming language python: You are given a tree (connected graph without cycles) consisting of $n$ vertices. The tree is unrooted — it is just a connected undirected graph without cycles. In one move, you can choose exactly $k$ leaves (leaf is such a vertex that is conne...
```python import sys input = sys.stdin.readline for f in range(int(input())): (n, k) = map(int, input().split()) neig = [0] * n for i in range(n): neig[i] = [0] for i in range(n - 1): (a, b) = map(int, input().split()) a -= 1 b -= 1 neig[a][0] += 1 neig[b][0] += 1 neig[a].append(b) neig[b].append(a)...
vfc_85554
{ "difficulty": "hard", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1385/F", "time_limit": "2 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n8 3\n1 2\n1 5\n7 6\n6 8\n3 1\n6 4\n6 1\n10 3\n1 2\n1 10\n2 3\n1 5\n1 6\n2 4\n7 10\n10 9\n8 10\n7 2\n3 1\n4 5\n3 6\n7 4\n1 2\n1 4\n5 1\n1 2\n2 3\n4 3\n5 3\n", "output": "2\n3\n3\n4\n", "type": "stdin_stdout" }, ...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/largest-subsquare-surrounded-by-x0558/1
Solve the following coding problem using the programming language python: Given a matrix A of dimensions NxN where every element is either O or X. Find the largest subsquare surrounded by X. Example 1: Input: N=2 A=[[X,X][X,X]] Output: 2 Explanation: The largest square submatrix surrounded by X is the whole input ma...
```python class Solution: def largestSubsquare(self, N, A): m = [[[0 for _ in range(N)] for _ in range(N)] for _ in range(2)] for i in range(N): m[0][i][0] = 1 if A[i][0] == 'X' else 0 for j in range(1, N): if A[i][j] == 'X': m[0][i][j] = m[0][i][j - 1] + 1 for j in range(N): m[1][0][j] = 1 if...
vfc_85562
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/largest-subsquare-surrounded-by-x0558/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N=2\r\nA=[[X,X][X,X]]", "output": "2", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/755/C
Solve the following coding problem using the programming language python: PolandBall lives in a forest with his family. There are some trees in the forest. Trees are undirected acyclic graphs with k vertices and k - 1 edges, where k is some integer. Note that one vertex is a valid tree. There is exactly one relative ...
```python n = int(input()) a = [0] + list(map(int, input().split())) was = set() for i in range(1, n + 1): if a[a[i]] == i: was.add(min(i, a[i])) print(len(was)) ```
vfc_85563
{ "difficulty": "easy", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/755/C", "time_limit": "1.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 1\n2 3\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 0\n", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 0\...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/occurences-of-2-as-a-digit/1
Solve the following coding problem using the programming language python: Count the number of 2s as digit in all numbers from 0 to n. Input: The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. Each test case contains the input integer n. Output: Print the count of...
```python def numberOf2sinRange(n): s = '' for i in range(n + 1): s += str(i) return s.count('2') ```
vfc_85567
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/occurences-of-2-as-a-digit/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": "number0f2s", "input": "2\r\n\r\n22\r\n\r\n100", "output": "6\r\n20", "type": "function_call" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: The Monk wants to buy some cities. To buy two cities, he needs to buy the road connecting those two cities. Now, you are given a list of roads, bought by the Monk. You need to tell how many cities did the Monk buy. Input: First line contains an...
```python ''' # Read input from stdin and provide input before running code name = raw_input('What is your name?\n') print 'Hi, %s.' % name ''' #print 'Hello World!' t=int(input()) for i in range(t): e=int(input()) dic={} for j in range(e): x,y=list(map(int,input().split())) dic[x]=1 dic[y]=1 print(len(dic))...
vfc_85568
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n3\n1 2\n2 3\n1 3\n", "output": "3\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/maximum-of-all-subarrays-of-size-k3101/1
Solve the following coding problem using the programming language python: Given an array arr[] of size N and an integer K. Find the maximum for each and every contiguous subarray of size K. Example 1: Input: N = 9, K = 3 arr[] = 1 2 3 1 4 5 2 3 6 Output: 3 3 4 5 5 5 6 Explanation: 1st contiguous subarray = {1 2 3} ...
```python class Solution: def max_of_subarrays(self, arr, n, k): ans = [] Q = deque([]) for i in range(n): if Q and Q[0] <= i - k: Q.popleft() while Q and arr[Q[-1]] <= arr[i]: Q.pop() Q.append(i) if i >= k - 1: ans.append(arr[Q[0]]) return ans ```
vfc_85572
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/maximum-of-all-subarrays-of-size-k3101/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 9, K = 3\r\narr[] = 1 2 3 1 4 5 2 3 6", "output": "3 3 4 5 5 5 6", "type": "stdin_stdout" }, { "fn_name": null, "input": "N = 10, K = 4\r\narr[] = 8 5 10 7 9 4 15 12 90 13", "output": "10 1...
taco
verifiable_code
https://codeforces.com/problemset/problem/456/C
Solve the following coding problem using the programming language python: Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it. Given a sequence a consisting of n integers. The player can make several steps. In a si...
```python s = 0 n = int(input()) dp = [0] * (10 ** 5 + 1) sec = [int(x) for x in input().split()] ls = [0] * (10 ** 5 + 1) for x in sec: ls[x] += 1 dp[1] = ls[1] for i in range(2, 10 ** 5 + 1): dp[i] = max(dp[i - 1], dp[i - 2] + ls[i] * i) print(dp[10 ** 5]) ```
vfc_85573
{ "difficulty": "medium", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/456/C", "time_limit": "1.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n3 3 4 5 4\n", "output": "11\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n8 9 6 5 6 4 10 9 1 4\n", "output": "39\n", "type": "stdin_stdout" }, { "fn_name...
taco
verifiable_code
https://codeforces.com/problemset/problem/485/B
Solve the following coding problem using the programming language python: Many computer strategy games require building cities, recruiting army, conquering tribes, collecting resources. Sometimes it leads to interesting problems. Let's suppose that your task is to build a square city. The world map uses the Cartesia...
```python n = int(input()) lis = [] for i in range(n): lis.append(input().split()) for i in range(n): for j in range(2): lis[i][j] = int(lis[i][j]) lis0 = [] lis1 = [] for i in range(n): lis0.append(lis[i][0]) lis1.append(lis[i][1]) if n == 1: print(1) else: m = max(max(lis0) - min(lis0), max(lis1) - min(lis1))...
vfc_85577
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/485/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n0 0\n2 2\n", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n0 0\n0 3\n", "output": "9\n", "type": "stdin_stdout" }, { "fn_name": null, "...
taco
verifiable_code
https://codeforces.com/problemset/problem/1338/A
Solve the following coding problem using the programming language python: You have an array $a$ of length $n$. For every positive integer $x$ you are going to perform the following operation during the $x$-th second: Select some distinct indices $i_{1}, i_{2}, \ldots, i_{k}$ which are between $1$ and $n$ inclusive,...
```python import sys import math def answer(n, a): curr_step = 0 if n == 1: return 0 mx = a[0] mxd = 0 for i in range(1, n): if a[i] > mx: mx = a[i] d = mx - a[i] if d > mxd: nsf0 = math.floor(math.log2(d)) + 1 mxd = 2 ** nsf0 - 1 return int(math.log2(mxd + 1)) def main(): t = int(sys.stdin.re...
vfc_85581
{ "difficulty": "medium", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1338/A", "time_limit": "1 second" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n4\n1 7 6 5\n5\n1 2 3 4 5\n2\n0 -4\n", "output": "2\n0\n3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n3\n1000000000 0 -1000000000\n1\n6\n2\n-1000000000 1000000000\n2\n1000000000 -...
taco
verifiable_code
https://www.codechef.com/problems/LKDNGOLF
Solve the following coding problem using the programming language python: Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. It's a lockdown. You’re bored in your house and are playing golf in the hallway. The hallway has $N + 2$ tiles numbered from $0$ to $N+1$ from left...
```python for _ in range(int(input())): (n, x, k) = map(int, input().split()) if x % k == 0 or x % k == (n + 1) % k: print('YES') else: print('NO') ```
vfc_85586
{ "difficulty": "easy", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/LKDNGOLF", "time_limit": "0.5 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n5 4 2\n5 3 2\n5 5 2", "output": "YES\nNO\nNO", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/221/A
Solve the following coding problem using the programming language python: The Little Elephant enjoys recursive functions. This time he enjoys the sorting function. Let a is a permutation of an integers from 1 to n, inclusive, and ai denotes the i-th element of the permutation. The Little Elephant's recursive function...
```python n = int(input()) l = list(range(1, n + 1)) l = sorted(l) l.insert(0, l[-1]) l.pop() print(*l) ```
vfc_85590
{ "difficulty": "easy", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/221/A", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1000\n", "output": "1000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/tic-tac-toe2412/1
Solve the following coding problem using the programming language python: A Tic-Tac-Toe board is given after some moves are played. Find out if the given board is valid, i.e., is it possible to reach this board position after some moves or not. Note that every arbitrary filled grid of 9 spaces isn’t valid e.g. a grid ...
```python class Solution: def isValid(self, board): if board[0] == board[1] and board[0] == board[2]: if board[0] == 'O': return False if board[3] == board[4] and board[3] == board[5]: if board[3] == 'O': return False if board[6] == board[7] and board[6] == board[8]: if board[6] == 'O': ret...
vfc_85594
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/tic-tac-toe2412/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "board[] = {'X', 'X', 'O', \r\n 'O', 'O', 'X',\r\n 'X', 'O', 'X'};", "output": "Valid", "type": "stdin_stdout" }, { "fn_name": null, "input": "board[] = {'O', 'X', 'X', \r\n ...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/count-odd-factors0844/1
Solve the following coding problem using the programming language python: Given an integer N, count the numbers having an odd number of factors from 1 to N (inclusive). Example 1: Input: N = 5 Output: 2 Explanation: From 1 - 5 only 2 numbers, 1 and 4 are having odd number of factors. Example 2: Input: N = 1 Output: ...
```python import math class Solution: def count(self, N): c = 0 for i in range(1, N + 1): if i * i <= N: c += 1 return c ```
vfc_85595
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/count-odd-factors0844/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 5", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "N = 1", "output": "1", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/does-robot-moves-circular0414/1
Solve the following coding problem using the programming language python: Given a sequence of moves for a robot. Check if the sequence is circular or not. A sequence of moves is circular if the first and last positions of the robot are the same. A move can be one of the following : G - Go one unit L - Turn le...
```python class Solution: def isCircular(self, path): i = j = 0 pre = 'r' for k in path: if k == 'G': if pre == 'r': j += 1 elif pre == 'l': j -= 1 elif pre == 'u': i -= 1 elif pre == 'd': i += 1 elif k == 'L': if pre == 'r': pre = 'u' elif pre == 'l': ...
vfc_85596
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/does-robot-moves-circular0414/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "path = \"GLGLGLG\"", "output": "\"Circular\"", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/find-all-distinct-subset-or-subsequence-sums4424/1
Solve the following coding problem using the programming language python: Given a set of integers, find all distinct sums that can be generated from the subsets of the given sets. Example 1: Input: nums = {1,2} Output: {0,1,2,3} Explanation: Four distinct sums can be calculated which are 0, 1, 2 and 3. 0 if we do no...
```python class Solution: def DistinctSum(self, nums): sums = {0} for x in nums: sums.update([s + x for s in sums]) return sorted(sums) ```
vfc_85598
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/find-all-distinct-subset-or-subsequence-sums4424/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "nums = {1,2}", "output": "{0,1,2,3}", "type": "stdin_stdout" }, { "fn_name": null, "input": "nums = {1,2,3}", "output": "{0,1,2,3,4,5,6}", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/385/B
Solve the following coding problem using the programming language python: The bear has a string s = s_1s_2... s_{|}s| (record |s| is the string's length), consisting of lowercase English letters. The bear wants to count the number of such pairs of indices i, j (1 ≤ i ≤ j ≤ |s|), that string x(i, j) = s_{i}s_{i} + 1......
```python (s, start) = (input(), 0) (n, k) = (len(s), 0) while True: pos = s.find('bear', start) if pos < 0: print(k) break (start, k) = (pos + 1, k + (pos - start + 1) * (n - pos - 3)) ```
vfc_85599
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/385/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "bearbtear\n", "output": "6\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1387/A
Solve the following coding problem using the programming language python: You are given an undirected graph where each edge has one of two colors: black or red. Your task is to assign a real number to each node so that: * for each black edge the sum of values at its endpoints is 1; * for each red edge the sum ...
```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_85609
{ "difficulty": "hard", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1387/A", "time_limit": "1.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "76 38\n2 1 1\n65 4 1\n67 6 2\n66 8 1\n37 9 1\n3 11 2\n48 12 2\n23 18 2\n46 22 1\n10 24 1\n36 25 2\n42 26 2\n34 29 2\n45 30 1\n75 31 1\n21 32 1\n20 39 2\n14 40 2\n5 41 1\n61 43 2\n27 47 2\n44 49 1\n38 50 2\n13 51 2\n72 52 1\n35 53 1...
taco
verifiable_code
https://codeforces.com/problemset/problem/1198/F
Solve the following coding problem using the programming language python: You are given an array of $n$ integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one. The GCD of a group of int...
```python import sys def gcd(l): if len(l) == 0: return 0 if len(l) == 1: return l[0] if len(l) == 2: if l[1] == 0: return l[0] return gcd([l[1], l[0] % l[1]]) return gcd([gcd(l[:-1]), l[-1]]) def brute_force(l1, l2, l, sol): if len(l) == 0: g1 = gcd(l1) g2 = gcd(l2) return (g1 == 1 and g2 == 1,...
vfc_85618
{ "difficulty": "very_hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1198/F", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n2 3 6 7\n", "output": "YES\n2 2 1 1 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n6 15 35 77 22\n", "output": "YES\n2 1 2 1 1 \n", "type": "stdin_stdout" }, { ...
taco
verifiable_code
https://www.hackerrank.com/challenges/quicksort1/problem
Solve the following coding problem using the programming language python: The previous challenges covered Insertion Sort, which is a simple and intuitive sorting algorithm with a running time of $unrecognized$. In these next few challenges, we're covering a divide-and-conquer algorithm called Quicksort (also known as ...
```python size = int(input()) array = input().split(' ') arr = ['None'] * size for i in range(size): arr[i] = int(array[i]) p = arr[0] less = [] more = [] for i in range(size): if arr[i] < p: less.append(arr[i]) else: more.append(arr[i]) for j in range(len(less)): print(less[j], end=' ') for k in range(len(more...
vfc_85622
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.hackerrank.com/challenges/quicksort1/problem", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 \n4 5 3 7 2 \n", "output": "3 2 4 5 7\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: You need to handle two extraordinarily large integers. The good news is that you don't need to perform any arithmetic operation on them. You just need to compare them and see whether they are equal or one is greater than the other. Given two st...
```python def main(): t=int(input()) while t!=0: t-=1 x=input() y=input() xcount,ycount=0,0 i=len(x)-1 while x[i]=='!': xcount+=1 i-=1 i=len(y)-1 while y[i]=='!': ycount+=1 i-=1 new_x=x[:len(x)-xcount] new_y=y[:len(y)-ycount] new_x=int(new_x) new_y=int(new_y) if new_x==0 and xcou...
vfc_85626
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "27\n0!!!\n0\n1\n1!!!\n2!!!\n2\n3!!!\n999999999\n0!\n0\n11!\n40000000\n3!!\n721\n3\n2!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n7!!!\n3!!!!\n0!\n2\n1\n2\n0\n0\n3!!!!\n4!!!!\n15!\n999999999\n999999999\n4!!\n7!!!\n5000!!\n40321\n8!\...
taco
verifiable_code
https://codeforces.com/problemset/problem/525/B
Solve the following coding problem using the programming language python: Pasha got a very beautiful string s for his birthday, the string consists of lowercase Latin letters. The letters in the string are numbered from 1 to |s| from left to right, where |s| is the length of the given string. Pasha didn't like his pr...
```python def __starting_point(): s = list(input()) input() data = sorted(map(lambda x: int(x) - 1, input().split())) data.append(len(s) // 2) tr = True for i in range(len(data) - 1): if tr: for j in range(data[i], data[i + 1]): (s[j], s[-j - 1]) = (s[-j - 1], s[j]) tr = not tr print(''.join(s)) __sta...
vfc_85630
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/525/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "abcdef\n1\n2\n", "output": "aedcbf\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "vwxyz\n2\n2 2\n", "output": "vwxyz\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: FizzBuzz is a game in which integers of 1 or more are spoken in order according to the following rules. * "Fizz" when divisible by 3 * "Buzz" when divisible by 5 * "FizzBuzz" when divisible by both 3 and 5 * At other times, that number A...
```python def calc_start(mid): cnt = -1 i = 1 while 10 ** i < mid: cnt += i * (10 ** i - 10 ** (i - 1)) fif = (10 ** i - 1) // 15 - (10 ** (i - 1) - 1) // 15 three = (10 ** i - 1) // 3 - (10 ** (i - 1) - 1) // 3 five = (10 ** i - 1) // 5 - (10 ** (i - 1) - 1) // 5 cnt += (three + five) * 4 - (three + five ...
vfc_85634
{ "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": "8", "output": "BuzzFizz78FizzBuzz11\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: Problem Description Apparently, the key that would take Alice home from her Wonderland adventure is a magic pass code hidden in numbers. Help her find it! It's the one with the highest sum of its digits! Input Format Input consists of severa...
```python alls = [] while True: failed = False try: s = input() except: failed = True break if len(s.rstrip().lstrip())==0: failed = True break alls.append(s) if len(alls)> 0: winner = '' maxs = 0 for y in alls: csum = sum(int(x) for x in y) if csum > maxs: maxs = csum winner= y pri...
vfc_85638
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "23\n496", "output": "789", "type": "stdin_stdout" }, { "fn_name": null, "input": "123\n456\n789\n91011\n1", "output": "496", "type": "stdin_stdout" }, { "fn_name": null, ...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/value-equal-to-index-value1330/1
Solve the following coding problem using the programming language python: Given an array Arr of N positive integers. Your task is to find the elements whose value is equal to that of its index value ( Consider 1-based indexing ). Note: There can be more than one element in the array which have the same value as its in...
```python class Solution: def valueEqualToIndex(self, arr, n): final = [] for (i, ele) in enumerate(arr): if ele == i + 1: final.append(ele) return final ```
vfc_85642
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/value-equal-to-index-value1330/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 5\r\nArr[] = {15, 2, 45, 12, 7}", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "N = 1\r\nArr[] = {1}", "output": "1", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: After obtaining a lot of gold from capturing different kingdoms, King Kala buys a large area of land. N trees are planted on the land, numbered from 1 to N. Each tree i, has coordinates as Xi, Yi. King Kala has two sons who, as their father, are...
```python ''' # Read input from stdin and provide input before running code name = raw_input('What is your name?\n') print 'Hi, %s.' % name ''' #print 'Hello World!' t=eval(input()) while t>0: t-=1 n=eval(input()) a,b,c=list(map(int,input().split())) p=0 z=0 while n>0: n-=1 x,y=list(map(int,input().split()))...
vfc_85647
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10\n522\n1 -1 0\n878 -937\n-406 10\n-375 -375\n494 362\n-433 -433\n128 553\n869 -875\n77 77\n916 916\n787 787\n798 -880\n-270 76\n89 -813\n-985 33\n250 -900\n26 -247\n-746 -746\n85 -146\n880 892\n908 -560\n-820 -820\n836 836\n-76 -...
taco
verifiable_code
Solve the following coding problem using the programming language python: Sherlock Holmes loves mind palaces! We all know that. A mind palace, according to Mr. Holmes is something that lets him retrieve a given memory in the least time posible. For this, he structures his mind palace in a very special way. Let a NxM ...
```python l=[int(x) for x in input().split()] l2=[] for i in range(l[0]): l1=[int(y) for y in input().split()] l2.append(l1) for j in range(eval(input())): a=eval(input()) l3=[] d=0 for k in range(0,len(l2)): if(a in l2[k]): l3.append(k) break; else: d+=1 if(d==len(l2)): print("-1 -1") else: pr...
vfc_85651
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 5\n-993655555 -758584352 -725954642 -696391700 -649643547\n-591473088 -568010221 -432112275 -421496588 -351507172\n-323741602 -232192004 -30134637 -369573 100246476\n156824549 174266331 392354039 601294716 763826005\n768378344 80...
taco
verifiable_code
https://codeforces.com/problemset/problem/429/D
Solve the following coding problem using the programming language python: Iahub and Sorin are the best competitive programmers in their town. However, they can't both qualify to an important contest. The selection will be made with the help of a single problem. Blatnatalag, a friend of Iahub, managed to get hold of th...
```python import sys max_Int = int(1000000000.0) class splitFeature: def __init__(self, position, value): self.position = position self.value = value def bruteForce(features, left, right): min_distance = max_Int for i in range(left, right): for j in range(i + 1, right): min_distance = min(min_distance, (...
vfc_85655
{ "difficulty": "hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/429/D", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n1 0 0 -1\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1 -1\n", "output": "2\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: Taro had his own personal computer and set a password for login. However, Taro inadvertently forgot the password. Then, remembering that there was a piece of paper with the password written down, Taro found the paper and was surprised to see it....
```python a = input() b = input() length_a = len(a) length_b = len(b) def check(): for i in range(length_a - length_b + 1): for j in range(length_b): if b[j] == '_' or a[i + j] == b[j]: continue else: break else: print('Yes') return print('No') return check() ```
vfc_85659
{ "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": "KUSATSU\nLSATSU", "output": "No\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "RUPCUAOC\n__PC", "output": "Yes\n", "type": "stdin_stdout" }, { "fn_name": null, ...
taco
verifiable_code
Solve the following coding problem using the programming language python: There are 'n' ants on a 'n+1' length rod. The ants are numbered from 1 to n and are initially placed at positions starting from position 1 till position n. They are moving either in left direction (denoted by '-1') or in the right direction (den...
```python t=int(input()) for p in range(t): n=int(input()) a=list(map(int,input().split())) cnt1=0 for i in range(n): if a[i]<0: cnt1+=1 if n-cnt1==cnt1: print(cnt1) else: if cnt1>n-cnt1: print(cnt1) else: print((cnt1+1)) ```
vfc_85663
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n10\n1 -1 1 1 -1 1 -1 1 -1 -1", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n2\n-1 -1", "output": "2", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: There is one card each with the numbers from "1" to "10", for a total of 10 cards. This card has numbers on the front and nothing on the back. Using this card, you and your opponent will play the game according to the following rules. 1. You an...
```python while 1: a = [i + 1 for i in range(10)] try: b = list(map(int, input().split())) except: break for i in b: a.remove(i) print('YES' if sum([1 for i in a if i <= 20 - sum(b[:2])]) / 7 >= 0.5 else 'NO') ```
vfc_85667
{ "difficulty": "unknown_difficulty", "memory_limit": "134.217728 megabytes", "memory_limit_bytes": null, "problem_url": null, "time_limit": "1.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 2 3\n5 6 8\n8 9 10", "output": "YES\nYES\nNO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 2 3\n5 2 9\n8 1 10", "output": "YES\nYES\nYES\n", "type": "stdin_stdout" },...
taco
verifiable_code
Solve the following coding problem using the programming language python: Recently you invented a brand-new definition of prime numbers. For a given set of positive integers S let's call X a prime if there are no elements in S which are divisors of X (except X itself). You are given a set S. Find elements in it whic...
```python ''' # Read input from stdin and provide input before running code name = raw_input('What is your name?\n') print 'Hi, %s.' % name ''' n = eval(input()) arr = input().split(" ") res = str() for i in range(len(arr)): flag = 1 for j in range(len(arr)): if i==j: continue elif int(arr[i])%int(arr[j])==0:...
vfc_85675
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10\n2 8 15 1 10 5 19 3 6 7", "output": "42 335 501 170 725 479 359 963 465 706 146 282 962 492 996 943 437 392 605 903 154 293 383 422 717 719 448 727 772 539 870 913 300 36 895 704 812 323 334 674 665 142 712 254 869 548", ...
taco
verifiable_code
https://codeforces.com/problemset/problem/1411/D
Solve the following coding problem using the programming language python: Currently, XXOC's rap is a string consisting of zeroes, ones, and question marks. Unfortunately, haters gonna hate. They will write $x$ angry comments for every occurrence of subsequence 01 and $y$ angry comments for every occurrence of subseque...
```python import sys input = sys.stdin.readline def solve(s, x, y): c0 = 0 c1 = 0 r = 0 for i in s: if i == '0': c0 += 1 else: r += c0 * x c1 += 1 z0 = 0 for i in range(len(s) - 1, -1, -1): if s[i] == '0': z0 += 1 else: r += z0 * y ans = r l0 = 0 l1 = 0 for i in s: if i == '?': r ...
vfc_85683
{ "difficulty": "hard", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1411/D", "time_limit": "1 second" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "0?1\n2 3\n", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "?????\n13 37\n", "output": "0\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/899540d741547e2d75d1c5c03a4161ab53affd13/1
Solve the following coding problem using the programming language python: You have a garden with n flowers lined up in a row. The height of ith flower is a_{i} units. You will water them for k days. In one day you can water w continuous flowers (you can do this only once in a single day). Whenever you water a flower i...
```python class Solution: def maximizeMinHeight(self, n, k, w, a): def _try(tar): mods = [0] * n (add, left) = (0, k) for i in range(n): add += mods[i] v = a[i] + add if v < tar: Δ = tar - v mods[i] += Δ if i + w < n: mods[i + w] -= Δ add += Δ left -= Δ if l...
vfc_85687
{ "difficulty": "medium_hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/899540d741547e2d75d1c5c03a4161ab53affd13/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "n=6\r\nk=2\r\nw=3\r\na[]={2,2,2,2,1,1}", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "n=2\r\nk=5\r\nw=1\r\na[]={5,8}", "output": "9", "type": "stdin_stdout" }...
taco
verifiable_code
https://codeforces.com/problemset/problem/424/A
Solve the following coding problem using the programming language python: Pasha has many hamsters and he makes them work out. Today, n hamsters (n is even) came to work out. The hamsters lined up and each hamster either sat down or stood up. For another exercise, Pasha needs exactly $\frac{n}{2}$ hamsters to stand up...
```python n = int(input()) s = input() (u, d) = (0, 0) for i in s: if i == 'X': u = u + 1 else: d = d + 1 if u > d: print(n // 2 - d) elif u == d: print(0) else: print(n // 2 - u) if u == d: print(s) elif u > d: v = n // 2 - d new = '' for i in s: if v != 0 and i == 'X': new = new + 'x' v = v - 1 ...
vfc_85688
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/424/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\nxxXx\n", "output": "1\nXxXx\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.hackerrank.com/challenges/kevin-and-expected-value/problem
Solve the following coding problem using the programming language python: Kevinsogo is a professor of mathematics, One day he gave an assignment to his students which was hard for them. The students want you to help them in solving the problem. Given the value of $N$, $x=\text{rand()}\bmod N$ $Y=\sqrt{x+\sqrt{x+\...
```python from math import sqrt M = 5000500 a = [0.5 * (1 + sqrt(1 + 4 * i)) for i in range(M)] a[0] = 0 for i in range(1, M): a[i] += a[i - 1] t = int(input()) def fairAnswer(n): return a[n - 1] / n def unfairAnswer(n): return (0.5 * (n - 1) + 2 / 3 * (0.25 + n - 1) ** 1.5) / n for i in range(t): n = int(input()...
vfc_85696
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.hackerrank.com/challenges/kevin-and-expected-value/problem", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1\n5\n10\n", "output": "0.0\n1.69647248786\n2.43798952788\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/IARCSJUD/problems/AVERAGE
Solve the following coding problem using the programming language python: You are given a sequence of integers $a_1, a_2, ..., a_N$. An element ak is said to be an average element if there are indices $i, j$ (with $i \neq j$) such that $a_k = \frac{a_i + a_j}{2}$. In the sequence 371022171537102217153 \quad 7 \quad 1...
```python l = [] for _ in range(int(input())): l.append(int(input())) avg = 0 l.sort() for i in range(0, len(l)): j = 0 n = len(l) - 1 while j < n: s = l[j] + l[n] if s > 2 * l[i]: n -= 1 elif s < 2 * l[i]: j += 1 else: avg += 1 break print(avg) ```
vfc_85700
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/IARCSJUD/problems/AVERAGE", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n3\n7\n10\n17\n22\n15\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n3\n7\n10\n3\n18\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_n...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/maximum-difference-10429/1
Solve the following coding problem using the programming language python: Given an array A[]of size N. Let us call difference between indices of an element's first and last appearance in the array A[] a gap. Find the maximum possible gap. Note that if any element appears only once, then the gap for that element is 0....
```python import math class Solution: def maxDiffIndex(self, A, N): maxi = -math.inf dicti = {} for i in range(N): if A[i] not in dicti: dicti[A[i]] = i else: maxi = max(maxi, i - dicti[A[i]]) if maxi == -math.inf: return 0 return maxi ```
vfc_85708
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/maximum-difference-10429/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 9\nA[] = {2, 1, 3, 4, 2, 1, 5, 1, 7}", "output": "6", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: <image> One evening. As usual, when you were watching TV in the living room, my sister in fifth grade offered me a consultation. When I listened to the story, I couldn't understand the math problem that was presented at school today, so I want ...
```python import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools sys.setrecursionlimit(10 ** 7) inf = 10 ** 20 eps = 1.0 / 10 ** 13 mod = 10 ** 9 + 7 dd = [(-1, 0), (0, 1), (1, 0), (0, -1)] ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (...
vfc_85709
{ "difficulty": "unknown_difficulty", "memory_limit": "134.217728 megabytes", "memory_limit_bytes": null, "problem_url": null, "time_limit": "8.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6 4 -1", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "29 218 367", "output": "816094540\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.hackerrank.com/challenges/beautiful-pairs/problem
Solve the following coding problem using the programming language python: You are given two arrays, $\mbox{A}$ and $\mbox{B}$, both containing $N$ integers. A pair of indices $(i,j)$ is beautiful if the $i^{\mbox{th}}$ element of array $\mbox{A}$ is equal to the $j^{th}$ element of array $\mbox{B}$. In other words, ...
```python input() a = [x for x in input().split()] b = [x for x in input().split()] aDict = dict() bDict = dict() for val in a: if val in aDict: aDict[val] += 1 else: aDict[val] = 1 for val in b: if val in bDict: bDict[val] += 1 else: bDict[val] = 1 total = 0 for val in aDict: while aDict[val] > 0 and val ...
vfc_85713
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.hackerrank.com/challenges/beautiful-pairs/problem", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n1 2 3 4\n1 2 3 3\n", "output": "4\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.hackerrank.com/challenges/sum-vs-xor/problem
Solve the following coding problem using the programming language python: Given an integer $n$, find each $\boldsymbol{x}$ such that: $0\leq x\leq n$ $n+x=n\oplus x$ where $\oplus$ denotes the bitwise XOR operator. Return the number of $\boldsymbol{x}$'s satisfying the criteria. Example $n=4$ There are four v...
```python import sys n = int(input().strip()) print(1 if n == 0 else 1 << bin(n)[2:].count('0')) ```
vfc_85717
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.hackerrank.com/challenges/sum-vs-xor/problem", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n", "output": "4\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1358/C
Solve the following coding problem using the programming language python: During the quarantine, Sicromoft has more free time to create the new functions in "Celex-2021". The developers made a new function GAZ-GIZ, which infinitely fills an infinite table to the right and down from the upper left corner as follows: ...
```python from sys import stdin, gettrace if not gettrace(): def input(): return next(stdin)[:-1] def main(): def solve(): (x1, y1, x2, y2) = map(int, input().split()) print((x2 - x1) * (y2 - y1) + 1) q = int(input()) for _ in range(q): solve() main() ```
vfc_85721
{ "difficulty": "medium_hard", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1358/C", "time_limit": "2 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n1 1 2 2\n1 2 2 4\n179 1 179 100000\n5 7 5 7\n", "output": "2\n3\n1\n1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n1 1 3 6\n", "output": "11\n", "type": "stdin_stdout"...
taco
verifiable_code
https://codeforces.com/problemset/problem/466/D
Solve the following coding problem using the programming language python: Peter has a sequence of integers a_1, a_2, ..., a_{n}. Peter wants all numbers in the sequence to equal h. He can perform the operation of "adding one on the segment [l, r]": add one to all elements of the sequence with indices from l to r (incl...
```python mod = 10 ** 9 + 7 (n, h) = map(int, input().split()) a = list(map(int, input().split())) dp = [[0 for j in range(h + 1)] for i in range(n + 1)] dp[0][0] = 1 for i in range(1, n + 1): need = h - a[i - 1] if need < 0: break if need == 0: dp[i][0] = dp[i - 1][0] else: dp[i][need] = (dp[i - 1][need] + d...
vfc_85725
{ "difficulty": "hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/466/D", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 2\n1 1 1\n", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 1\n1 1 1 1 1\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, ...
taco
verifiable_code
Solve the following coding problem using the programming language python: Example Input 4 2 1 1 1 2 3 4 3 1 2 2 4 3 4 Output 2 1 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python import sys readline = sys.stdin.readline write = sys.stdout.write from collections import deque INF = 10 ** 9 def bfs(N, G, s): dist = [INF] * N (*lb,) = range(N) dist[s] = 0 que = deque([s]) while que: v = que.popleft() d = dist[v] + 1 l = lb[v] for w in G[v]: if dist[w] == INF: dist[w] ...
vfc_85743
{ "difficulty": "unknown_difficulty", "memory_limit": "536.870912 megabytes", "memory_limit_bytes": null, "problem_url": null, "time_limit": "5.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 2 1 1\n1 2\n3\n4\n3\n1 4\n2 4\n3 4", "output": "2 1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 2 1 1\n2 2\n3\n4\n3\n1 2\n2 4\n3 4", "output": "2 2\n", "type": "stdin_s...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/c670bf260ea9dce6c5910dedc165aa403f6e951d/1
Solve the following coding problem using the programming language python: Given an array A[] of length N. For each index, i (1<=i<=N), find the difference between the number of distinct elements in the left and right side in the of the current element in the array. Example 1: Input: N = 3 arr[] = {4, 3, 3} Output: {-...
```python from typing import List class Solution: def getDistinctDifference(self, N: int, A: List[int]) -> List[int]: (dict_, dict_2) = ({}, {}) (i, j) = (0, N - 1) left = [0 for i in range(N)] right = [0 for i in range(N)] ans = [0 for i in range(N)] while i < N and j >= 0: right[j] = len(dict_2) ...
vfc_85747
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/c670bf260ea9dce6c5910dedc165aa403f6e951d/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 3\narr[] = {4, 3, 3}", "output": "{-1, 0, 2}", "type": "stdin_stdout" }, { "fn_name": null, "input": "N = 4\narr[] = {4, 4, 3, 3}", "output": "{-2, 0, 0, 2}", "type": "stdin_stdout" ...
taco
verifiable_code
https://codeforces.com/problemset/problem/808/B
Solve the following coding problem using the programming language python: It's been almost a week since Polycarp couldn't get rid of insomnia. And as you may already know, one week in Berland lasts k days! When Polycarp went to a doctor with his problem, the doctor asked him about his sleeping schedule (more specific...
```python s = input() s1 = s.split() n = int(s1[0]) k = int(s1[1]) s = input() s1 = s.split() arr = [] for i in range(n): arr.append(int(s1[i])) sum = 0 for i in range(k): sum += arr[i] sum1 = sum for i in range(k, n): sum += arr[i] sum -= arr[i - k] sum1 += sum s = str(sum1 / (n - k + 1)) s += '000000' print(s) ...
vfc_85748
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/808/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 2\n3 4 7\n", "output": "9.0000000000\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1\n10\n", "output": "10.0000000000\n", "type": "stdin_stdout" }, { "fn_na...
taco
verifiable_code
https://codeforces.com/problemset/problem/103/C
Solve the following coding problem using the programming language python: After all the events in Orlando we all know, Sasha and Roma decided to find out who is still the team's biggest loser. Thankfully, Masha found somewhere a revolver with a rotating cylinder of n bullet slots able to contain exactly k bullets, now...
```python (n, k, p) = map(int, input().strip().split()) if k == 0: ak = 0 an = n else: ak = k - 1 if n % 2 == 1 else k an = n - n % 2 ans = '' for i in range(p): v = int(input().rstrip()) if k == 0: print('.', end='') elif v == n: print('X', end='') else: idx = (an - v) / 2 idx += v % 2 * (an / 2) if ...
vfc_85752
{ "difficulty": "hard", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/103/C", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7 7 7\n1\n2\n3\n4\n5\n6\n7\n", "output": "XXXXXXX\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/first-digit1751/1
Solve the following coding problem using the programming language python: Given an array arr[] of size N, find the first digit from the left of the product of these N integers. Example 1: Input: N = 4, arr[] = {5, 8, 3, 7} Output: 8 Explanation: Produt is 840 Example 2: Input: N = 3, arr[] = {6, 7, 9} Output: 3 Expla...
```python class Solution: def firstDigit(self, arr, n): p = 1 for i in range(n): p = p * arr[i] d = str(p) p = int(d[:6]) return str(p)[0] ```
vfc_85756
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/first-digit1751/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 4, arr[] = {5, 8, 3, 7}", "output": "8", "type": "stdin_stdout" }, { "fn_name": null, "input": "N = 3, arr[] = {6, 7, 9}", "output": "3", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: When the day begins, it's time to sing carols. Unfortunately, not all the family members know the lyrics to the same carols. Everybody knows at least one, though. You are given a array of lyrics. The j-th character of the i-th element of lyrics ...
```python __author__ = 'lavee_singh' from itertools import combinations def solve(a, n): # a is array of strings. data = [] for i in range(len(a[0])): data.append([]) for j in range(len(a)): if a[j][i] == 'Y': data[i].append(j) #print data for i in range(1, len(data)+1): a = combinations(data, i) ...
vfc_85757
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n6\nNYN YYN YYN YNY YNY NNY\n3\nYNNY NYNY NNYY\n5\nYYN YYN YNY NYN NNY", "output": "2\n1\n2", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/INSURANCE
Solve the following coding problem using the programming language python: Chef bought car insurance. The policy of the insurance is: The maximum rebatable amount for any damage is Rs X lakhs. If the amount required for repairing the damage is ≤ X lakhs, that amount is rebated in full. Chef's car meets an accident an...
```python t = int(input()) for i in range(t): (x, y) = map(int, input().split()) k = min(x, y) print(k) ```
vfc_85761
{ "difficulty": "easy", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/INSURANCE", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n5 3\n5 8\n4 4\n15 12\n", "output": "3\n5\n4\n12\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: Tom gives a number N to Roy and ask him to tell the total number of even divisors of the number N. Help Roy to answer the question of Tom. INPUT: First line contains the number of testcases T, followed by T lines each containing an integer N. ...
```python ''' # Read input from stdin and provide input before running code name = raw_input('What is your name?\n') print 'Hi, %s.' % name ''' import sys import math def findpower(num): divisor = 2 prod = 1 while True: div = 0 while num%divisor == 0: div = div + 1 num = num/divisor if divisor == 2: ...
vfc_85765
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n9\n8", "output": "0\n3", "type": "stdin_stdout" }, { "fn_name": null, "input": "100\n221614680\n613118744\n825161854\n393619966\n433416647\n918290125\n875590062\n364287285\n540653024\n282896407\n8...
taco
verifiable_code
Solve the following coding problem using the programming language python: Abhinav and Manav both being one of the best coders of SVNIT went onto participate in ACM ICPC Regional Contest. Apparently Manav’s team the 3Horsemen stood ahead of Abhinav’s team akatsuki11 in the contest though both solved the same number of ...
```python a = [0,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000,10000000000] def a_and_m(): for t in range(eval(input())): l,r = list(map(int,input().split())) len_r = len(str(r)) if l <= a[len_r]/2 and r >= a[len_r]/2: #print 'oye' v = a[len_r]/2 tt = str(v) ttt = [] for j in rang...
vfc_85769
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "24\n960440942 978948770\n366632331 444054372\n291070314 465398755\n880006277 941096188\n191970163 690033048\n916069265 970899369\n609160934 909699101\n21640850 672697171\n645009015 679697316\n862630595 866814866\n51473722 970290896...
taco
verifiable_code
Solve the following coding problem using the programming language python: Folding a Ribbon Think of repetitively folding a very long and thin ribbon. First, the ribbon is spread out from left to right, then it is creased at its center, and one half of the ribbon is laid over the other. You can either fold it from the...
```python def rdp_trace(n: int, i: int) -> list: def loop(n: int, i: int) -> list: if n == 1: return [] if i <= n // 2: rval = loop(n // 2, n // 2 - i + 1) rval.append(i) return rval else: rval = loop(n // 2, i - n // 2) rval.append(i) return rval return loop(2 ** n, i) def rdp_connect() ...
vfc_85773
{ "difficulty": "unknown_difficulty", "memory_limit": "268.435456 megabytes", "memory_limit_bytes": null, "problem_url": null, "time_limit": "8.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 3 2\n12 578 1435\n59 471605241352156968 431565444592236940\n0 0 0", "output": "LRR\nLRLRRRLRLLRR\nLRRRLRRLLRRRRLLLLRLLRRRLRRLLRLLLLLLRLRLLRLRLLLRLRLLRLLRRRLL\n", "type": "stdin_stdout" }, { "fn_name": nu...
taco
verifiable_code
https://codeforces.com/problemset/problem/1325/B
Solve the following coding problem using the programming language python: Ehab has an array $a$ of length $n$. He has just enough free time to make a new array consisting of $n$ copies of the old array, written back-to-back. What will be the length of the new array's longest increasing subsequence? A sequence $a$ is ...
```python t = int(input()) ans = '' for i in range(t): n = int(input()) p = sorted([int(j) for j in input().split()]) k = 0 for j in range(n - 1): if p[j] == p[j + 1]: k += 1 else: pass ans += str(n - k) + '\n' print(ans) ```
vfc_85778
{ "difficulty": "easy", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1325/B", "time_limit": "1 second" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n3\n3 2 1\n6\n3 1 4 1 5 9\n", "output": "3\n5\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n7\n6 6 8 8 6 6 6\n1\n2\n5\n4 5 9 8 7\n7\n1 2 7 1 6 10 2\n", "output": "2\n1\n5\n5\n...
taco
verifiable_code
https://codeforces.com/problemset/problem/413/A
Solve the following coding problem using the programming language python: Not so long ago company R2 bought company R1 and consequently, all its developments in the field of multicore processors. Now the R2 laboratory is testing one of the R1 processors. The testing goes in n steps, at each step the processor gets so...
```python import re import inspect from sys import argv, exit def rstr(): return input() def rstrs(splitchar=' '): return [i for i in input().split(splitchar)] def rint(): return int(input()) def rints(splitchar=' '): return [int(i) for i in rstrs(splitchar)] def varnames(obj, namespace=globals()): return [na...
vfc_85782
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/413/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 1 1 2\n1\n", "output": "Correct\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 1 1 3\n2\n", "output": "Correct\n", "type": "stdin_stdout" }, { "fn_name": nul...
taco
verifiable_code
https://www.codechef.com/problems/CHFHEIST
Solve the following coding problem using the programming language python: Read problem statements in [Vietnamese], [Bengali], [Mandarin Chinese], and [Russian] as well. Chef is planning a heist in the reserve bank of Chefland. They are planning to hijack the bank for $D$ days and print the money. The initial rate of...
```python for _ in range(int(input())): (D, d, P, Q) = map(int, input().split()) quo = D // d rem = D % d ans = 0 ans = quo * (2 * P + (quo - 1) * Q) // 2 ans = ans * d a = (P + quo * Q) * rem ans += a print(int(ans)) ```
vfc_85786
{ "difficulty": "medium", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/CHFHEIST", "time_limit": "0.5 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n2 1 1 1\n3 2 1 1\n5 2 1 2", "output": "3\n4\n13", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/978/F
Solve the following coding problem using the programming language python: In BerSoft $n$ programmers work, the programmer $i$ is characterized by a skill $r_i$. A programmer $a$ can be a mentor of a programmer $b$ if and only if the skill of the programmer $a$ is strictly greater than the skill of the programmer $b$ ...
```python from bisect import bisect_left (n, k) = map(int, input().split()) a = [int(x) for x in input().split()] sa = sorted(a) ans = [0] * n for i in range(k): (x, y) = map(int, input().split()) x -= 1 y -= 1 if a[x] > a[y]: ans[x] -= 1 if a[y] > a[x]: ans[y] -= 1 for i in range(n): t = bisect_left(sa, a[i]...
vfc_85794
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/978/F", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 2\n10 4 10 15\n1 2\n4 3\n", "output": "0 0 1 2 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10 4\n5 4 1 5 4 3 7 1 2 5\n4 6\n2 1\n10 8\n3 5\n", "output": "5 4 0 5 3 3 9 0 2 5 \n...
taco
verifiable_code
https://codeforces.com/problemset/problem/680/B
Solve the following coding problem using the programming language python: There are n cities in Bearland, numbered 1 through n. Cities are arranged in one long row. The distance between cities i and j is equal to |i - j|. Limak is a police officer. He lives in a city a. His job is to catch criminals. It's hard becaus...
```python import sys (n, a) = map(int, sys.stdin.readline().split()) t = list(map(int, sys.stdin.readline().split())) ans = t[a - 1] if a <= n // 2: for i in range(a - 1): if t[i] + t[2 * (a - 1) - i] == 2: ans += 2 ans += sum(t[2 * a - 1:]) else: for i in range(a, n): if t[i] + t[2 * (a - 1) - i] == 2: an...
vfc_85798
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/680/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6 3\n1 1 1 0 1 0\n", "output": "3\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/SPECIES
Solve the following coding problem using the programming language python: Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Bearland can be represented as a square grid that consists of N rows and N columns. Two cells are called adjacent if they share a side. In the input, each cell is de...
```python import sys sys.setrecursionlimit(5000) def findConnections(i, j, visited, connections): if i > 0: if visited[i - 1][j] == False: connections[-1].append(land[i - 1][j]) visited[i - 1][j] = True findConnections(i - 1, j, visited, connections) if i < N - 1: if visited[i + 1][j] == False: conne...
vfc_85802
{ "difficulty": "hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/SPECIES", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n3\n..?\n.?B\nG..\n2\nGG\n..\n3\n?..\n.??\n??.\n3\n??P\n???\n??B\n7\n?.?.?.?\n.?.?.?.\n?.?.?.?\n.?.?.?.\n?.?.?.?\n.?.?.?.\n?.?.?.?\n2\nPP\nPP", "output": "1\n0\n6\n0\n288603514\n1", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1438/E
Solve the following coding problem using the programming language python: Yurii is sure he can do everything. Can he solve this task, though? He has an array $a$ consisting of $n$ positive integers. Let's call a subarray $a[l...r]$ good if the following conditions are simultaneously satisfied: $l+1 \leq r-1$, i. e....
```python def solve(a): seen = set() for i in range(len(a)): c = 0 for j in range(i + 2, len(a)): c += a[j - 1] if a[i] ^ a[j] == c: seen.add((i, j)) if c >= 2 * a[i]: break for i in range(len(a) - 1, -1, -1): c = 0 for j in range(i - 2, -1, -1): c += a[j + 1] if a[i] ^ a[j] == c: ...
vfc_85806
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1438/E", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "8\n3 1 2 3 1 2 3 15\n", "output": "6", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n997230370 58052053 240970544 715275815 250707702 156801523 44100666 64791577 43523002 480196854\n", ...
taco
verifiable_code
https://codeforces.com/problemset/problem/1038/D
Solve the following coding problem using the programming language python: There are $n$ slimes in a row. Each slime has an integer value (possibly negative or zero) associated with it. Any slime can eat its adjacent slime (the closest slime to its left or to its right, assuming that this slime exists). When a slime...
```python import sys import os def solve(slimes): if len(slimes) == 1: return slimes[0] havePos = False haveNeg = False for s in slimes: if s > 0: havePos = True elif s < 0: haveNeg = True if havePos and haveNeg: return sum(map(abs, slimes)) elif not havePos: m = max(slimes) return sum(list(map...
vfc_85824
{ "difficulty": "medium_hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1038/D", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n2 1 2 1\n", "output": "4", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n0 -1 -1 -1 -1\n", "output": "4", "type": "stdin_stdout" }, { "fn_name": null, "...
taco
verifiable_code
https://codeforces.com/problemset/problem/1330/B
Solve the following coding problem using the programming language python: The sequence of $m$ integers is called the permutation if it contains all integers from $1$ to $m$ exactly once. The number $m$ is called the length of the permutation. Dreamoon has two permutations $p_1$ and $p_2$ of non-zero lengths $l_1$ and...
```python t = int(input()) for i in range(t): n = int(input()) mass = [int(x) for x in input().split()] answer = 0 q = [] Max = 0 ind = 0 for j in range(n): if Max < mass[j]: Max = mass[j] ind = Max - 1 a1 = mass[:n - ind - 1] a2 = mass[n - ind - 1:] a3 = mass[:ind + 1] a4 = mass[ind + 1:] a1.sort() ...
vfc_85828
{ "difficulty": "medium", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1330/B", "time_limit": "2 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n5\n1 4 3 2 1\n6\n2 4 1 3 2 1\n4\n2 1 1 3\n4\n1 3 3 1\n12\n2 1 3 4 5 6 7 8 9 1 10 2\n3\n1 1 1\n", "output": "2\n1 4\n4 1\n1\n4 2\n0\n0\n1\n2 10\n0\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/the-penalty-shootout3810/1
Solve the following coding problem using the programming language python: Given a string S contains 0's, 1's, and 2's, the task is to find the number of goals on the penalty. '1' stands for "goal". '0' stands for "no goal". '2' stands for a foul which gives a penalty. Example 1: Input: S = "1012012112110" Output...
```python class Solution: def penaltyScore(self, S): goal = 0 for i in range(len(S)): if i < len(S) - 1: if S[i] == '2' and S[i + 1] == '1': goal = goal + 1 return goal ```
vfc_85841
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/the-penalty-shootout3810/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "S = \"1012012112110\"", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "S = \"111122\"", "output": "0", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: Write a program which reads a sequence of $n$ integers $a_i (i = 1, 2, ... n)$, and prints the minimum value, maximum value and sum of the sequence. Constraints * $0 < n \leq 10000$ * $-1000000 \leq a_i \leq 1000000$ Input In the first line,...
```python input() l = list([int(i) for i in input().split()]) print(min(l), max(l), sum(l)) ```
vfc_85846
{ "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\n13 1 5 4 17", "output": "1 17 40\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n13 1 5 7 17", "output": "1 17 43\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1717/E
Solve the following coding problem using the programming language python: Madoka wants to enter to "Novosibirsk State University", but in the entrance exam she came across a very difficult task: Given an integer $n$, it is required to calculate $\sum{\operatorname{lcm}(c, \gcd(a, b))}$, for all triples of positive in...
```python from math import gcd n = int(input()) MOD = 10 ** 9 + 7 A = [0, 0] phi = list(range(n + 1)) for i in range(2, n + 1): if phi[i] == i: for j in range(i, n + 1, i): phi[j] = phi[j] * (i - 1) // i P = [0, 0] Q = [0, 0] for i in range(2, n + 1): P.append((P[-1] + phi[i]) % MOD) Q.append((Q[-1] + phi[i] * ...
vfc_85850
{ "difficulty": "hard", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1717/E", "time_limit": "1 second" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n", "output": "11\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: The Quarkgo Empire Expeditionary Force is an evil organization that plans to invade the Earth. In keeping with the tradition of the invaders, they continued to send monsters at a pace of one every week, targeting the area around Tokyo in Japan. ...
```python N = int(input()) n = 1 ans = 1 while True: n *= 3 if n >= N: print(ans) break ans += 1 ```
vfc_85854
{ "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": "57", "output": "4\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.hackerrank.com/challenges/power-of-large-numbers/problem
Solve the following coding problem using the programming language python: The city of Hackerland has formed a new football club and wants to participate in the upcoming Football League of their country. The coach is worried that they will not be able to qualify because they don't have a famous footballer in their team...
```python import sys T = int(sys.stdin.readline()) for _ in range(T): (A, B) = [int(x) for x in sys.stdin.readline().split()] print(pow(A, B, 1000000007)) ```
vfc_85858
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.hackerrank.com/challenges/power-of-large-numbers/problem", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n3 2\n4 5\n7 4\n34534985349875439875439875349875 93475349759384754395743975349573495\n34543987529435983745230948023948 3498573497543987543985743989120393097595572309482304\n", "output": "9\n1024\n2401\n735851262\n985546465\...
taco
verifiable_code
https://codeforces.com/problemset/problem/586/E
Solve the following coding problem using the programming language python: Alice and Bob decided to eat some fruit. In the kitchen they found a large bag of oranges and apples. Alice immediately took an orange for herself, Bob took an apple. To make the process of sharing the remaining fruit more fun, the friends decid...
```python def gcd(x, y): while y > 0: (x, y) = (y, x % y) return x (x, y) = map(int, input().split()) if gcd(x, y) != 1: print('Impossible') exit(0) res = '' while x > 0 and y > 0: if y > x: if x == 1: y -= 1 res = res + str(y // x) + 'B' y = y % x else: if y == 1: x -= 1 res = res + str(x // y)...
vfc_85862
{ "difficulty": "very_hard", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/586/E", "time_limit": "1.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4181 6765\n", "output": "1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A1B1A", "type": "stdin_stdout" }, { "fn_name": null, "input": "416445288135075809 416445288135075809\n", "output": "Impossible", "t...
taco
verifiable_code
https://codeforces.com/problemset/problem/946/E
Solve the following coding problem using the programming language python: Yes, that's another problem with definition of "beautiful" numbers. Let's call a positive integer x beautiful if its decimal representation without leading zeroes contains even number of digits, and there exists a permutation of this representa...
```python import sys t = int(sys.stdin.buffer.readline().decode('utf-8')) ans = [''] * t for _ in range(t): a = list(map(int, sys.stdin.buffer.readline().decode('utf-8').rstrip())) n = len(a) parity = [0] * 10 for x in a: parity[x] ^= 1 psum = sum(parity) for (i, free) in zip(range(n - 1, -1, -1), range(n)): ...
vfc_85866
{ "difficulty": "hard", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/946/E", "time_limit": "1.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n1010\n", "output": "1001\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n12\n10000000000000000000000000000000000000000000\n3030\n3112\n99771122997711229977112299778700000006\n9977112...
taco
verifiable_code
https://codeforces.com/problemset/problem/1121/C
Solve the following coding problem using the programming language python: Vasya likes taking part in Codeforces contests. When a round is over, Vasya follows all submissions in the system testing tab. There are n solutions, the i-th of them should be tested on a_i tests, testing one solution on one test takes 1 secon...
```python (n, k) = map(int, input().split()) a = list(map(int, input().split())) caption = 0 tested = [0 for i in range(n)] interesting = [0 for i in range(n)] ans = 0 while len(a) != 0: m = min(a[0:k]) for j in range(m): for i in range(min(k, len(a))): tested[i] += 1 a[i] -= 1 if caption != 0: if test...
vfc_85870
{ "difficulty": "medium_hard", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1121/C", "time_limit": "1.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 100\n79\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "50 3\n33 7 96 30 68 37 44 50 100 71 12 100 72 43 17 75 59 96 16 34 25 3 90 45 7 55 92 59 30 25 96 23 40 41 95 99 ...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/maximum-index3307/1
Solve the following coding problem using the programming language python: Given an array arr[] of n positive integers. The task is to find the maximum of j - i subjected to the constraint of arr[i] <= arr[j]. Example 1: Input: n = 9 arr[] = {34, 8, 10, 3, 2, 80, 30, 33, 1} Output: 6 Explanation: In the given array a...
```python class Solution: def maxIndexDiff(self, arr, n): m = -100000 for i in range(n): j = n - 1 while i < j and arr[i] > arr[j]: j -= 1 m = max(m, j - i) return m ```
vfc_85874
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/maximum-index3307/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "n = 9\r\narr[] = {34, 8, 10, 3, 2, 80, 30, 33, 1}", "output": "6", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/611/B
Solve the following coding problem using the programming language python: The year 2015 is almost over. Limak is a little polar bear. He has recently learnt about the binary system. He noticed that the passing year has exactly one zero in its representation in the binary system — 2015_10 = 11111011111_2. Note that he...
```python (a, b) = map(int, input().split()) count = 0 for i in range(2, 61): num = (1 << i) - 1 for j in range(0, i - 1): if a <= num - (1 << j) <= b: count += 1 print(count) ```
vfc_85877
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/611/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 10\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2015 2015\n", "output": "1\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/143/D
Solve the following coding problem using the programming language python: Once upon a time in the Kingdom of Far Far Away lived Sir Lancelot, the chief Royal General. He was very proud of his men and he liked to invite the King to come and watch drill exercises which demonstrated the fighting techniques and tactics of...
```python (n, m) = map(int, input().split()) if n > m: (n, m) = (m, n) if n > 2 and m > 2: print((n * m + 1) // 2) elif n == 1: print(m) else: print(2 * (m // 4 * 2 + min(m % 4, 2))) ```
vfc_85882
{ "difficulty": "medium_hard", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/143/D", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 393\n", "output": "393\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 995\n", "output": "995\n", "type": "stdin_stdout" }, { "fn_name": null, "input": ...
taco
verifiable_code
https://codeforces.com/problemset/problem/1153/C
Solve the following coding problem using the programming language python: Serval soon said goodbye to Japari kindergarten, and began his life in Japari Primary School. In his favorite math class, the teacher taught him the following interesting definitions. A parenthesis sequence is a string, containing only charact...
```python import sys sys.setrecursionlimit(20000000) input = sys.stdin.readline n = int(input()) s = input().rstrip() ans = [] count = 0 for i in s: if i == '(': ans.append(1) elif i == ')': ans.append(-1) else: ans.append(0) count += 1 x = sum(ans) if abs(x) > count or x % 2 != count % 2: print(':(') exit...
vfc_85886
{ "difficulty": "medium_hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1153/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n(?????\n", "output": "((()))\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n(???(???(?\n", "output": ":(\n", "type": "stdin_stdout" }, { "fn_name": null, ...
taco
verifiable_code
https://codeforces.com/problemset/problem/1119/D
Solve the following coding problem using the programming language python: Miyako came to the flea kingdom with a ukulele. She became good friends with local flea residents and played beautiful music for them every day. In return, the fleas made a bigger ukulele for her: it has $n$ strings, and each string has $(10^{1...
```python import sys input = sys.stdin.readline n = int(input()) s = list(map(int, input().split())) s.sort() q = int(input()) qrs = [] for i in range(q): (l, r) = map(int, input().split()) qrs.append((r - l, i)) qrs.sort() stoppers = sorted([s[i] - s[i - 1] for i in range(1, len(s))]) stopper_sum = 0 stopper_cnt = 0...
vfc_85894
{ "difficulty": "medium_hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1119/D", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n3 1 4 1 5 9\n3\n7 7\n0 2\n8 17\n", "output": "5 10 18\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/maximum-difference-between-node-and-its-ancestor/1
Solve the following coding problem using the programming language python: Given a Binary Tree, you need to find the maximum value which you can get by subtracting the value of node B from the value of node A, where A and B are two nodes of the binary tree and A is an ancestor of B. Example 1: Input: 5 / \ 2 ...
```python import math def diff(root, res): if root is None: return (math.inf, res) if not root.left and (not root.right): return (root.data, res) (min_left, res) = diff(root.left, res) (min_right, res) = diff(root.right, res) min_node = min(min_left, min_right) res = max(res, root.data - min_node) return (m...
vfc_85898
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/maximum-difference-between-node-and-its-ancestor/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\r\n / \\\r\n2 1", "output": "4", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\r\n / \\\r\n 2 3\r\n \\\r\n 7", "output": "-1", "type...
taco
verifiable_code
Solve the following coding problem using the programming language python: Everyone knows that chotu likes palindromic strings. One day, he found 2 ordinary strings s1 and s2. Now he wonders if he could make a palindrome by concatenating s1 and s2 in any order. i.e if s1s2 or s2s1 is a palindrome. Input First line of...
```python ''' # Read input from stdin and provide input before running code name = raw_input('What is your name?\n') print 'Hi, %s.' % name ''' #print 'Hello World!' n = int(input()) for i in range(n): s1 = input() s2 = input() tempStr = s1 + s2 tempStr1 = s2 + s1 if tempStr == tempStr[::-1] or tempStr1 == tempS...
vfc_85899
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "100\nabaa\nba\nxkjpctpcyfeybqwbmeidxfhadtkszjmkdbizlxuaowerypgkxjxdjanlvshnikjlvrplgeidagngganrxvcjfhrluapazuaadhoozdpnmilonouzhfjfrnzbtovjiaqfvpyshzvovbzcifgttihfdfijevoulnecjlttbtnlxdbcviwsjssreaypztwialqxlrnhxyocopiwpahkktgxcrxi...
taco
verifiable_code
https://www.hackerrank.com/challenges/append-and-delete/problem
Solve the following coding problem using the programming language python: You have two strings of lowercase English letters. You can perform two types of operations on the first string: Append a lowercase English letter to the end of the string. Delete the last character of the string. Performing this operation on an...
```python import sys s = input().strip() t = input().strip() k = int(input().strip()) lead = 0 for i in range(min(len(s), len(t))): if s[i] != t[i]: lead = i break else: lead = i + 1 d = len(s) - lead + len(t) - lead if k >= len(s) + len(t): print('Yes') elif d <= k and d % 2 == k % 2: print('Yes') else: pri...
vfc_85903
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.hackerrank.com/challenges/append-and-delete/problem", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "hackerhappy\nhackerrank\n9\n", "output": "Yes\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/WATERREQ
Solve the following coding problem using the programming language python: Finally, after purchasing a water cooler during the April long challenge, Chef noticed that his water cooler requires 2 liters of water to cool for one hour. How much water (in liters) would be required by the cooler to cool for N hours? -----...
```python t = int(input()) for i in range(t): x = int(input()) print(x * 2) ```
vfc_85907
{ "difficulty": "easy", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/WATERREQ", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n1\n2", "output": "2\n4\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/PTRN2020/problems/ITGUY37
Solve the following coding problem using the programming language python: The chef is trying to solve some pattern problems, Chef wants your help to code it. Chef has one number K to form a new pattern. Help the chef to code this pattern problem. -----Input:----- - First-line will contain $T$, the number of test case...
```python for _ in range(int(input())): n = int(input()) s = [str(i) for i in range(n, 0, -1)] for i in range(n): print('*' * i + ''.join(s)) del s[0] ```
vfc_85911
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/PTRN2020/problems/ITGUY37", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n1\n2\n3\n4\n", "output": "1\n21\n*1\n321\n*21\n**1\n4321\n*321\n**21\n***1\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: The range search problem consists of a set of attributed records S to determine which records from S intersect with a given range. For n points on a plane, report a set of points which are within in a given range. Note that you do not need to c...
```python import math import sys from bisect import bisect_left, bisect_right from typing import List, Optional, Tuple class KDTree(object): def __init__(self, n: int) -> None: self.n = n self.root = int(math.sqrt(n)) self.coordinates = [(0, 0, 0)] * n self.low: List[int] = [] self.high: List[int] = [] s...
vfc_85915
{ "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": "6\n2 1\n2 2\n4 2\n6 2\n3 6\n5 4\n2\n2 4 0 4\n4 10 2 5", "output": "0\n1\n2\n\n2\n3\n5\n\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n2 1\n2 2\n4 2\n6 4\n3 6\n5 4\n2\n2 4 0 4\n4 10 4 ...
taco
verifiable_code
Solve the following coding problem using the programming language python: PROBLEM SPECIFICATION: You are given three positive integers 'n' , 'a' and 'b' . In the given range from 1 to 'n' how many distinct numbers are completely divisible by 'a' or 'b' or both? NOTE: The range includes both 1 and 'n'. INPUT SPECIFIC...
```python def lcm(x, y): if x > y: greater = x else: greater = y while(True): if((greater % x == 0) and (greater % y == 0)): lcm = greater break greater += 1 return lcm t = int(input()) for j in range(t): c = 0 n,a,b = tuple(map(int,input().split())) if((a == 0) or ( b == 0)): print(...
vfc_85919
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "100\n1681692778 887 84\n424238336 7794 16\n596516650 493 87\n1350490028 2363 22\n2044897764 60 91\n1540383427 541 27\n35005212 5737 73\n1726956430 2568 69\n278722863 1531 83\n468703136 4068 24\n1315634023 9803 30\n1125898168 3070 5...
taco
verifiable_code
https://www.codechef.com/problems/COUNTA
Solve the following coding problem using the programming language python: Consider an array A of length N. You know that for all 1 ≤ i ≤ N, 0 ≤ A_{i} ≤ 10^{5}. We construct an array B of length N-1 such that, for all 1 ≤ i ≤ N - 1, B_{i} = min(A_{i}, A_{i + 1}). You are given the array B, you need to find out the tot...
```python m = 10 ** 5 p = 10 ** 9 + 7 def solve(): n = int(input()) b = [0] + list(map(int, input().split())) f = [0] * n g = [0] * n f[1] = 1 g[1] = m - b[1] for i in range(2, n): g[i] = f[i - 1] * (m - max(b[i - 1], b[i] + 1) + 1) if b[i - 1] > b[i]: g[i] += g[i - 1] elif b[i - 1] == b[i]: f[i] = ...
vfc_85925
{ "difficulty": "very_hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/COUNTA", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n2\n100\n5\n3 9 8 4\n3\n10 12", "output": "199801\n199983\n199977", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1082/B
Solve the following coding problem using the programming language python: Vova has won $n$ trophies in different competitions. Each trophy is either golden or silver. The trophies are arranged in a row. The beauty of the arrangement is the length of the longest subsegment consisting of golden trophies. Vova wants to ...
```python n = int(input()) s = input() a = [] k = 1 for i in range(n - 1): if s[i] == 'G' and s[i + 1] == 'G': k += 1 elif s[i] == 'G' and s[i + 1] == 'S': a.append([i, k]) k = 1 if s[-1] == 'G': a.append([n - 1, k]) if len(a) == 0: print(0) elif len(a) == 1: print(a[0][1]) elif len(a) == 2: ma = 0 for i i...
vfc_85934
{ "difficulty": "medium_hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1082/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10\nGGGSGGGSGG\n", "output": "7\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\nGGGG\n", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "i...
taco
verifiable_code
https://www.codechef.com/problems/ZUBTRCNT
Solve the following coding problem using the programming language python: You are given an equilateral triangle ΔABC with the side BC being the base. Each side of the triangle is of length L. There are L-1 additional points on each of the sides dividing the sides into equal parts of unit lengths. Points on the sides o...
```python try: for j in range(1, int(input()) + 1): (n, k) = map(int, input().split()) if k > n: c = 0 else: c = n - k + 1 s = c * (c + 1) // 2 print('Case', str(j) + ':', s) except: pass ```
vfc_85947
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/ZUBTRCNT", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n4 3\n4 4\n", "output": "Case 1: 3\nCase 2: 1\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/472/A
Solve the following coding problem using the programming language python: One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that. For example, there is a statement called the "Goldbach's conjecture". It sa...
```python def isprime(k): m = 0 for j in range(2, k): if k % j == 0: m = m + 1 if m == 0: return 0 else: return 1 n = int(input()) for i in range(4, n - 3): if isprime(i) == 1 and isprime(n - i) == 1: print(i, n - i) exit() ```
vfc_85951
{ "difficulty": "easy", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/472/A", "time_limit": "1.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "738457\n", "output": "4 738453\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "46220\n", "output": "4 46216\n", "type": "stdin_stdout" }, { "fn_name": null, ...
taco
verifiable_code
https://codeforces.com/problemset/problem/939/C
Solve the following coding problem using the programming language python: In distant future on Earth day lasts for n hours and that's why there are n timezones. Local times in adjacent timezones differ by one hour. For describing local time, hours numbers from 1 to n are used, i.e. there is no time "0 hours", instead ...
```python R = lambda : map(int, input().split()) n = int(input()) a = list(R()) (s, f) = R() d = f - s def solve(a, d, n, s): if n < d + 1: return s t = 0 for i in range(0, d): t += a[i] m = t res = s for i in range(1, n): t += a[(i + d - 1) % n] - a[i - 1] if t > m: m = t res = gr(i, s, n) elif ...
vfc_85956
{ "difficulty": "medium_hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/939/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1 2 3\n1 3\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n1 2 3 4 1\n1 3\n", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null,...
taco
verifiable_code
https://codeforces.com/problemset/problem/45/D
Solve the following coding problem using the programming language python: On a history lesson the teacher asked Vasya to name the dates when n famous events took place. He doesn't remembers the exact dates but he remembers a segment of days [li, ri] (inclusive) on which the event could have taken place. However Vasya ...
```python from sys import stdin inFile = stdin tokens = [] tokens_next = 0 def next_str(): global tokens, tokens_next while tokens_next >= len(tokens): tokens = inFile.readline().split() tokens_next = 0 tokens_next += 1 return tokens[tokens_next - 1] def nextInt(): return int(next_str()) n = nextInt() interv...
vfc_85960
{ "difficulty": "hard", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/45/D", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10\n1 1\n8 10\n1 7\n6 8\n5 7\n1 9\n8 8\n6 10\n1 4\n3 4\n", "output": "1 10 4 6 5 7 8 9 2 3 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n1 4\n1 12\n5 7\n5 5\n2 5\n1 7\n1 10\n7 9\n8 ...
taco
verifiable_code
Solve the following coding problem using the programming language python: There is a special game played in remote part of Rajasthan, where all people assemble with their all wealth and try to earn more wealth on the account of their current wealth. Suppose you are also a part of this game. The game is like, there a...
```python t=eval(input()) for _ in range(t): n,g=list(map(int,input().split())) w=list(map(int,input().split())) mw=w[0] richer=0 for i in range(1,n): if w[i]>mw: richer+=1 print(richer/g) ```
vfc_85964
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1000\n100 22\n2178 3205 2281 495 3118 4626 4834 1465 663 848 4289 812 4383 3303 2433 3481 2836 1598 3543 2727 4436 2016 3592 2772 2901 4503 3578 386 3533 2371 1352 913 2064 495 1797 2546 4752 361 4930 2519 2231 3004 42 525 3984 125...
taco
verifiable_code
Solve the following coding problem using the programming language python: Mr. Bill is shopping at the store. There are some coins in his wallet (10-yen coins, 50-yen coins, 100-yen coins, 500-yen coins), but he is now trying to consume as much of this coin as possible. In other words, by paying for the goods with an a...
```python coin = [10, 50, 100, 500, 500000] first = True while True: bill = int(input()) if bill == 0: break if not first: print() else: first = False posses = list(map(int, input().split())) Sumcoin = sum((coin[i] * posses[i] for i in range(4))) change = Sumcoin - bill ChangeCoin = [change % coin[i + 1] ...
vfc_85968
{ "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": "160\n1 1 4 0\n160\n1 0 2 10\n0", "output": "10 1\n50 1\n100 1\n\n10 1\n100 2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "160\n1 1 4 0\n58\n2 0 4 10\n0", "output": "10 1\n50 1\n10...
taco
verifiable_code
https://codeforces.com/problemset/problem/1415/A
Solve the following coding problem using the programming language python: There is a prison that can be represented as a rectangular matrix with $n$ rows and $m$ columns. Therefore, there are $n \cdot m$ prison cells. There are also $n \cdot m$ prisoners, one in each prison cell. Let's denote the cell in the $i$-th ro...
```python for _ in [*open(0)][1:]: (n, m, r, c) = map(int, _.split()) print(max(r + c - 2, n + m - r - c, m + r - c - 1, n + c - r - 1)) ```
vfc_85972
{ "difficulty": "easy", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1415/A", "time_limit": "1 second" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n10 10 1 1\n3 5 2 4\n10 2 5 1\n", "output": "18\n4\n6\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/unique-binary-tree-requirements/1
Solve the following coding problem using the programming language python: Geek wants to know the traversals required to construct a unique binary tree. Given a pair of traversal, return true if it is possible to construct unique binary tree from the given traversals otherwise return false. Each traversal is represente...
```python class Solution: def isPossible(self, a, b): return 1 if (a == 2 or b == 2) and (not (a == 2 and b == 2)) else 0 ```
vfc_85977
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/unique-binary-tree-requirements/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "a = 1, b=2", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "a = 1, b=3", "output": "0", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/a4f19ea532cee502aabec77c07e0d0a45b76ecf9/1
Solve the following coding problem using the programming language python: Penelope and her classmates are lost in the Forbidden Forest and the Devil is out to get them. But Penelope has magical powers that can build bridges across the dangerous river and take her friends to safety. The only bridges that can withstand ...
```python class Solution: def build_bridges(self, str1, str2): dp = [[0 for i in range(len(str2) + 1)] for j in range(len(str1) + 1)] for i in range(len(str1) + 1): for j in range(len(str2) + 1): if i == 0 or j == 0: dp[i][j] = 0 elif str1[i - 1] == str2[j - 1]: dp[i][j] = 1 + dp[i - 1][j - 1...
vfc_85978
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/a4f19ea532cee502aabec77c07e0d0a45b76ecf9/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "str1 = \"*@#*\" \r\nstr2 = \"*#\"", "output": "2", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/parallel-or-perpendicular4257/1
Solve the following coding problem using the programming language python: Given two force vectors, find out whether they are parallel, perpendicular or neither. Let the first vector be A = a_{1} i +a_{2} j + a_{3} k and the second vector be B = b_{1} i + b_{2} j + b_{3} k. A.B = a_{1 }* b_{1} + a_{2 }* b_{2} + a_{3 }*...
```python class Solution: def find(self, A, B): par = A[0] * B[0] + A[1] * B[1] + A[2] * B[2] per = [A[1] * B[2] - A[2] * B[1], A[0] * B[2] - A[2] * B[0], A[0] * B[1] - A[1] * B[0]] s = 0 for i in per: s += i ** 2 if s == 0: return 1 elif par == 0: return 2 else: return 0 ```
vfc_85979
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/parallel-or-perpendicular4257/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "A = 3i + 2j + k, B = 6i + 4j + 2k", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "A = 4i + 6j + k, B = i - 1j + 2k", "output": "2", "type": "stdin_stdout" } ...
taco
verifiable_code
Solve the following coding problem using the programming language python: ICPC Calculator In mathematics, we usually specify the order of operations by using parentheses. For example, 7 × (3 + 2) always means multiplying 7 by the result of 3 + 2 and never means adding 2 to the result of 7 × 3. However, there are peop...
```python def inp(): global n n = int(input()) return n def strinp(): l = 0 s = list(input()) for i in s: if i == '.': l += 1 else: c = i return [l, c] def calc(p): global f l = f[p][0] c = f[p][1] p += 1 if c == '+': ans = 0 for i in range(p, n): if f[i][0] == l: break elif f[i][0...
vfc_85984
{ "difficulty": "unknown_difficulty", "memory_limit": "268.435456 megabytes", "memory_limit_bytes": null, "problem_url": null, "time_limit": "8.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n9\n4\n+\n.1\n.2\n.3\n9\n+\n.0\n.+\n..*\n...1\n...+\n....1\n....2\n..0\n10\n+\n.+\n..6\n..2\n.+\n..1\n..*\n...7\n...6\n.3\n0", "output": "9\n6\n3\n54\n", "type": "stdin_stdout" }, { "fn_name": null, ...
taco
verifiable_code
https://codeforces.com/problemset/problem/1486/E
Solve the following coding problem using the programming language python: There are n cities and m bidirectional roads in the country. The roads in the country form an undirected weighted graph. The graph is not guaranteed to be connected. Each road has it's own parameter w. You can travel through the roads, but the g...
```python import sys, io, os input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline read = lambda : map(int, input().split()) from heapq import heappush, heappop inf = 10000000000.0 (n, m) = read() e = {} for _ in range(m): (v, u, w) = read() v -= 1 u -= 1 if v not in e: e[v] = [] if u not in e: e[u] = [...
vfc_85992
{ "difficulty": "hard", "memory_limit": "512.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1486/E", "time_limit": "4.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10 20\n10 1 15\n7 1 32\n5 3 36\n3 9 14\n3 4 19\n6 8 4\n9 6 18\n7 3 38\n10 7 12\n7 5 29\n7 6 14\n6 2 40\n8 9 19\n7 8 11\n7 4 19\n2 1 38\n10 9 3\n6 5 50\n10 3 41\n1 8 3\n", "output": "0 2201 779 1138 1898 49 196 520 324 490 ", ...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/maximum-product4633/1
Solve the following coding problem using the programming language python: Given an array arr[] of N integers, the task is to find a subsequence of size K whose product is maximum among all possible K sized subsequences of a given array. Example 1: Input: N = 4, K = 2 arr[] = {1, 2, 0, 3} Output: 6 Explanation: Subseq...
```python class Solution: def maxProductSubarrayOfSizeK(self, arr, n, k): product = 1 arr.sort() if k % 2 and arr[-1] < 0: for _ in range(k): product *= arr.pop() return product if k % 2: product *= arr.pop() k -= 1 while k: if arr[0] * arr[1] > arr[-1] * arr[-2]: product *= arr.pop(0...
vfc_85997
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/maximum-product4633/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 4, K = 2\narr[] = {1, 2, 0, 3}", "output": "6", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1670/B
Solve the following coding problem using the programming language python: Hosssam decided to sneak into Hemose's room while he is sleeping and change his laptop's password. He already knows the password, which is a string $s$ of length $n$. He also knows that there are $k$ special letters of the alphabet: $c_1,c_2,\ld...
```python import sys DEBUG = False def transform(s, chars): n_steps = 0 new_s def check(s, chars): chars = set(chars) max_len = 0 cur_len = 0 prev_was = 0 for c in s: if not c in chars: cur_len += 1 else: max_len = max(max_len, cur_len + prev_was) cur_len = 0 prev_was = 1 print(max_len) def m...
vfc_85999
{ "difficulty": "easy", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1670/B", "time_limit": "1 second" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10\n9\niloveslim\n1 s\n7\njoobeel\n2 o e\n7\nbasiozi\n2 s i\n6\nkhater\n1 r\n7\nabobeih\n6 a b e h i o\n5\nzondl\n5 a b c e f\n6\nshoman\n2 a h\n7\nshetwey\n2 h y\n5\nsamez\n1 m\n6\nmouraz\n1 m\n", "output": "5\n2\n3\n5\n1\n0...
taco
verifiable_code
https://www.hackerrank.com/challenges/filling-jars/problem
Solve the following coding problem using the programming language python: Animesh has $n$ empty candy jars, numbered from ${1}$ to $n$, with infinite capacity. He performs $m$ operations. Each operation is described by $3$ integers, ${a}$, ${b}$, and ${k}$. Here, ${a}$ and ${b}$ are indices of the jars, and ${k}$ is t...
```python inp = [int(a) for a in input().split()] tot = 0 for i in range(inp[1]): inp1 = [int(a) for a in input().split()] tot += (inp1[1] - inp1[0] + 1) * inp1[2] print(int(tot / inp[0])) ```
vfc_86008
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.hackerrank.com/challenges/filling-jars/problem", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 3\n1 2 100\n2 5 100\n3 4 100\n", "output": "160\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1656/A
Solve the following coding problem using the programming language python: You are given an array $a_1, a_2, \ldots, a_n$ of positive integers. A good pair is a pair of indices $(i, j)$ with $1 \leq i, j \leq n$ such that, for all $1 \leq k \leq n$, the following equality holds: $$ |a_i - a_k| + |a_k - a_j| = |a_i - a...
```python t = int(input()) for i in range(t): n = int(input()) l = list(map(int, input().split())) (mn, mx) = (l.index(min(l)), l.index(max(l))) print(mn + 1, mx + 1) ```
vfc_86012
{ "difficulty": "easy", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1656/A", "time_limit": "1 second" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n3\n5 2 7\n5\n1 4 2 2 3\n1\n2\n", "output": "2 3\n1 2\n1 1\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/get-minimum-element-from-stack/1
Solve the following coding problem using the programming language python: You are given N elements and your task is to Implement a Stack in which you can get a minimum element in O(1) time. Example 1: Input: push(2) push(3) pop() getMin() push(1) getMin() Output: 2 1 Explanation: In the first test case for query push...
```python class stack: def __init__(self): self.s = [] self.minEle = -1 self.length = 0 def push(self, x): if len(self.s) == 0: self.s.append(x) self.minEle = x self.length += 1 elif x > self.minEle: self.s.append(x) self.length += 1 else: topel = 2 * x - self.minEle self.s.append(t...
vfc_86016
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/get-minimum-element-from-stack/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "push(2)\npush(3)\npop()\ngetMin()\npush(1)\ngetMin()", "output": "2 1", "type": "stdin_stdout" } ] }