source stringclasses 4
values | task_type stringclasses 1
value | in_source_id stringlengths 0 138 | problem stringlengths 219 13.2k | gold_standard_solution stringlengths 0 413k | problem_id stringlengths 5 10 | metadata dict | verification_info dict |
|---|---|---|---|---|---|---|---|
taco | verifiable_code | https://www.codechef.com/problems/CCD | Solve the following coding problem using the programming language python:
Chef has 2 strings A and B of equal length N. Both strings contain lowercase english alphabets only.
Chef can perform several moves on string A. In one move, Chef has to:
Select an index i \space (1 ≤ i ≤ N-1).
Replace A[i] with (A[i]+1).
Repla... | ```python
t = int(input())
for _ in range(t):
(n, q) = map(int, input().split())
a = list(input())
b = list(input())
alt_sum = [0] * n
for i in range(n):
k = (ord(b[i]) - ord(a[i])) % 26
if i == 0:
alt_sum[i] = k
continue
if i % 2 == 0:
alt_sum[i] = k + alt_sum[i - 1]
else:
alt_sum[i] = -k + al... | vfc_142780 | {
"difficulty": "hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/CCD",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n5 3\nabcdz\nnbhea\n2 2\n1 3\n4 5\n",
"output": "Yes\nNo\nYes\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/893/D | Solve the following coding problem using the programming language python:
Recenlty Luba got a credit card and started to use it. Let's consider n consecutive days Luba uses the card.
She starts with 0 money on her account.
In the evening of i-th day a transaction a_{i} occurs. If a_{i} > 0, then a_{i} bourles are de... | ```python
(n, d) = map(int, input().split())
a = [0] + list(map(int, input().split()))
b = [0] * (n + 2)
b[n] = a[n]
now = a[n]
for i in range(n - 1, 0, -1):
now = a[i] + max(now, 0)
b[i] = now
now = 0
res = 0
for i in range(1, n + 1):
if a[i] == 0:
if now < 0:
res += 1
now = min(d, max(0, d - b[i + 1]))
el... | vfc_142784 | {
"difficulty": "hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/893/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 10\n-1 5 0 -5 3\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 4\n-10 0 20\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null... |
taco | verifiable_code | https://codeforces.com/problemset/problem/1534/F1 | Solve the following coding problem using the programming language python:
This is the easy version of the problem. The difference between the versions is the constraints on a_i. You can make hacks only if all versions of the problem are solved.
Little Dormi has recently received a puzzle from his friend and needs you... | ```python
import sys
input = lambda : sys.stdin.readline().rstrip()
def scc(E):
n = len(E)
iE = [[] for _ in range(n)]
for (i, e) in enumerate(E):
for v in e:
iE[v].append(i)
T = []
done = [0] * n
ct = 0
for i0 in range(n):
if done[i0]:
continue
Q = [~i0, i0]
while Q:
i = Q.pop()
if i < 0:
... | vfc_142788 | {
"difficulty": "unknown_difficulty",
"memory_limit": "512.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1534/F1",
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 6\n..#..#\n......\n#####.\n1 1 2 1 1 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 10\n#..###..##\n...#..###.\n.###..##..\n1 1 1 3 1 1 2 2 2 1\n",
"output": ... |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/check-squares2421/1 | Solve the following coding problem using the programming language python:
Given an integer N, check if it is possible to represent it as a function(a, b) such that : a^{2} + b^{2} = N where "a" and "b" are whole numbers. Print 1 if it's possible, else Print 0.
Example 1:
Input:
N = 1
Output:
1
Explanation:
1^{2} + 0... | ```python
import math
class Solution:
def checkSquares(self, N):
flag = 0
for a in range(int(math.sqrt(N)) + 1):
for b in range(int(math.sqrt(N)) + 1):
if a * a + b * b == N:
flag = 1
break
if flag == 1:
break
return flag
``` | vfc_142792 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/check-squares2421/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N = 1",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "N = 2",
"output": "1",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/deque-implementations/1 | Solve the following coding problem using the programming language python:
A deque is a double-ended queue that allows enqueue and dequeue operations from both the ends.
Given a deque and Q queries. The task is to perform some operation on dequeue according to the queries as given below:
1. pb: query to push back the e... | ```python
def push_front_pf(dq, x):
dq.appendleft(x)
def push_back_pb(dq, x):
dq.append(x)
def front_dq(dq):
if not dq:
return -1
return dq[0]
def pop_back_ppb(dq):
if not dq:
return -1
return dq.pop()
``` | vfc_142794 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/deque-implementations/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": "push_front_pf",
"input": "5\npf 5\npf 10\npb 6\nf\npp_b",
"output": "10",
"type": "function_call"
},
{
"fn_name": "push_front_pf",
"input": "2\npf 5 \nf",
"output": "5",
"type": "function_call"
}
... |
taco | verifiable_code | https://www.codechef.com/problems/SUMOFPROD2 | Solve the following coding problem using the programming language python:
For an array A of length N, let F(A) denote the sum of the product of all the subarrays of A. Formally,
F(A) = \sum_{L=1}^N \sum_{R=L}^N (\prod_{i=L}^R A_{i}\right )
For example, let A = [1, 0, 1], then there are 6 possible subarrays:
Subarr... | ```python
MOD = 998244353
cpraid1 = [1] * 100001
cpraid2 = [1] * 100001
cpraid3 = [1] * 100001
for i in range(2, 100001):
cpraid1[i] = cpraid1[i - 1] * i % MOD
cpraid2[i] = MOD - MOD // i * cpraid2[MOD % i] % MOD
cpraid3[i] = cpraid3[i - 1] * cpraid2[i] % MOD
def C(x, y):
return 0 if x < 0 or y > x else cpraid1[x]... | vfc_142797 | {
"difficulty": "medium_hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/SUMOFPROD2",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n3\n1 0 1\n1\n0\n2\n1 1\n4\n1 1 0 1\n",
"output": "16\n0\n6\n120\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.hackerrank.com/challenges/runningtime/problem | Solve the following coding problem using the programming language python:
In a previous challenge you implemented the Insertion Sort algorithm. It is a simple sorting algorithm that works well with small or mostly sorted data. However, it takes a long time to sort large unsorted data. To see why, we will analyze its r... | ```python
size = int(input())
array = input().split(' ')
arr = ['None'] * size
for i in range(size):
arr[i] = int(array[i])
i = 1
count = 0
while i < size:
tmp = arr[i]
j = i - 1
while arr[j] > tmp and j > -1:
arr[j + 1] = arr[j]
j = j - 1
count = count + 1
arr[j + 1] = tmp
i = i + 1
print(count)
``` | vfc_142801 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.hackerrank.com/challenges/runningtime/problem",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 \n2 1 3 1 2 \n",
"output": "4\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/middle-of-three2926/1 | Solve the following coding problem using the programming language python:
Given three distinct numbers A, B and C. Find the number with value in middle (Try to do it with minimum comparisons).
Example 1:
Input:
A = 978, B = 518, C = 300
Output:
518
Explanation:
Since 518>300 and 518<978, so
518 is the middle element.... | ```python
class Solution:
def middle(self, A, B, C):
if A > B > C or C > B > A:
return B
elif A > C > B or B > C > A:
return C
else:
return A
``` | vfc_142805 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/middle-of-three2926/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "A = 978, B = 518, C = 300",
"output": "518",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Regional College is having N branches, where each branches have positive integral student. A minimize operation is performed on the branch such that all of them are reduced by the minimum number student in a branch.
Suppose we have 5 branches a... | ```python
n=eval(input())
s=input()
lst=s.split(' ')
ar=[0]*n
for i in range(0,n):
ar[i]=int(lst[i])
ar.sort()
cnt=1
mn=ar[0]
print(len(ar))
while(cnt!=0):
cnt=0
for i in range(0,n):
ar[i]=ar[i]-mn
if(ar[i]>0):
cnt=cnt+1
for i in range(0,n):
if(ar[i]>0):
mn=ar[i]
break
if(cnt>0):
print(cnt)
``` | vfc_142806 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n5 4 4 2 2 8",
"output": "6\n4\n2\n1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1000\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1... | |
taco | verifiable_code | https://codeforces.com/problemset/problem/1030/E | Solve the following coding problem using the programming language python:
Vasya has a sequence $a$ consisting of $n$ integers $a_1, a_2, \dots, a_n$. Vasya may pefrom the following operation: choose some number from the sequence and swap any pair of bits in its binary representation. For example, Vasya can transform n... | ```python
from bisect import bisect_left
n = int(input())
b = list(map(int, input().split()))
pre = [0]
res = []
for j in range(n):
res.append(bin(b[j]).count('1'))
pre.append(pre[-1] + res[-1])
ans = 0
e = 1
o = 0
for j in range(n):
if pre[j + 1] % 2 == 0:
ans += e
e += 1
else:
ans += o
o += 1
s = 0
m = ... | vfc_142811 | {
"difficulty": "hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1030/E",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n6 7 14\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n1 2 1 16\n",
"output": "4\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
E-training
Nene is writing a program to look up $ N $ integers $ V_1, V_2, V_3, \ cdots, V_N $ for programming training.
As told by his instructor, Umiko, Nene wrote a program to look up multiples of 2, 3, and 6.
Multiples of 2 were $ A $, mu... | ```python
(n, a, b, c) = map(int, input().split())
print(n - (a + b - c))
``` | vfc_142815 | {
"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 5 2 1",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "9 5 2 1",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "12 ... | |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/k-palindrome/1 | Solve the following coding problem using the programming language python:
A string is k palindrome if it can be transformed into a palindrome on removing at most k characters from it. Your task is to complete the function is_k_palin which takes two arguments a string str and a number N . Your function should return tr... | ```python
def is_k_palin(string, n):
k = n
n = len(string)
dp = [[-1 for j in range(n)] for i in range(n)]
for i in range(n - 1, -1, -1):
for j in range(n):
if i >= j:
dp[i][j] = 0
elif string[i] == string[j]:
dp[i][j] = dp[i + 1][j - 1]
else:
dp[i][j] = 1 + min(dp[i + 1][j], dp[i][j - 1])
i... | vfc_142824 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/k-palindrome/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": "is_k_palin",
"input": "2\r\n\nabcdecba 1\r\n\nacdcb 1",
"output": "1\n0",
"type": "function_call"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1133/D | Solve the following coding problem using the programming language python:
You are given two arrays $a$ and $b$, each contains $n$ integers.
You want to create a new array $c$ as follows: choose some real (i.e. not necessarily integer) number $d$, and then for every $i \in [1, n]$ let $c_i := d \cdot a_i + b_i$.
Your... | ```python
from collections import defaultdict
from math import gcd
N = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
Pairs = defaultdict(int)
already = 0
for i in range(N):
if A[i] and B[i]:
b = -B[i]
a = A[i]
x = gcd(abs(b), abs(a))
bb = int(b / x)
aa = int(a / x)
... | vfc_142825 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1133/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1 2 3 4 5\n2 4 7 11 3\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n13 37 39\n1 2 3\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_... |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Jack stays in a n-storey hostel. His dorm room is on the jth floor. Every morning, he is in so much hurry for classes that he cannot not decide whether to take Lift or Stairs to reach ground-floor. He asks you to help him choose either Stairs or... | ```python
t = input()
for _ in range(int(t)):
inp = input().split()
n, J, L = list(map(int, inp[:-1]))
d = inp[-1]
stairs = 10*(J)
lift = 0
if d == 'U':
if J != n:
lift = 30 + (n-L)*5 + (n*5)
if J == n:
lift = 20 + (n-L)*5 + (n*5)
elif d =='D':
if L >= J:
lift = 20 + L*5
else:
lift = 40 + L*5... | vfc_142829 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "32\n10 5 5 U\n10 5 5 D\n10 3 3 D\n10 9 9 U\n10 10 10 U\n10 10 10 D\n100 80 20 U\n100 80 45 U\n100 80 46 U\n100 80 40 D\n100 80 0 D\n100 80 79 D\n100 100 3 U\n100 100 4 U\n100 100 5 U\n100 100 2 U\n100 100 1 D\n100 53 100 U\n100 52 ... | |
taco | verifiable_code | https://www.codechef.com/problems/HIGHFREQ | Solve the following coding problem using the programming language python:
Chef has an array A of length N.
Let F(A) denote the maximum frequency of any element present in the array.
For example:
If A = [1, 2, 3, 2, 2, 1], then F(A) = 3 since element 2 has the highest frequency = 3.
If A = [1, 2, 3, 3, 2, 1], then ... | ```python
from collections import Counter
from math import ceil, floor, gcd
for _ in range(int(input())):
n = int(input())
a = list(Counter([int(x) for x in input().strip().split()]).values())
if len(a) == 1:
print(ceil(a[0] / 2))
else:
a.sort()
print(max(ceil(a[-1] / 2), a[-2]))
``` | vfc_142834 | {
"difficulty": "medium",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/HIGHFREQ",
"time_limit": "0.5 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n4\n1 2 1 2\n5\n1 1 1 1 1\n6\n1 2 2 1 2 2\n",
"output": "2\n3\n2\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1608/D | Solve the following coding problem using the programming language python:
You are given $n$ dominoes. Each domino has a left and a right cell. Each cell can be colored either black or white. Some cells are already colored, while some aren't yet.
The coloring is said to be valid if and only if it is possible to rearra... | ```python
MOD = 998244353
MAX = 200005
fact = [1]
for zz in range(1, MAX + 1):
fact.append(fact[-1] * zz % MOD)
def nCr(n, r):
num = fact[n]
den = fact[r] * fact[n - r] % MOD
return num * pow(den, MOD - 2, MOD) % MOD
from collections import Counter
def main():
MOD = 998244353
cnts = Counter()
n = int(input())
... | vfc_142840 | {
"difficulty": "very_hard",
"memory_limit": "256 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1608/D",
"time_limit": "1 second"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n?W\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n??\nW?\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": ... |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/next-greater-element-2/1 | Solve the following coding problem using the programming language python:
Given a circular interger array arr of size N (i.e ., the next element of arr [N-1] is arr[0] ), return the next greater number for every element in arr.
The next greater element of a number x is the first greater number to its traversing-order ... | ```python
class Solution:
def nextGreaterElement(self, N, arr):
ans = [-2] * N
ma = max(arr)
for i in range(N):
if arr[i] == ma:
ans[i] = -1
pos = i
stack = [ma]
for i in range(N - 1, -1, -1):
j = (i + pos) % N
if ans[j] == -1:
stack[:] = [ma]
else:
while stack[-1] <= arr[j]:
... | vfc_142845 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/next-greater-element-2/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N = 3\r\narr[ ] = {1, 2, 1}",
"output": "{2, -1, 2}",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/DAILY | Solve the following coding problem using the programming language python:
A daily train consists of N cars. Let's consider one particular car. It has 54 places numbered consecutively from 1 to 54, some of which are already booked and some are still free. The places are numbered in the following fashion:
The car is sep... | ```python
import math
(x, n) = map(int, input().split())
counter = 0
equals = 0
for _ in range(n):
a = input()
(i, j) = (0, 54)
for __ in range(9):
lst = a[i:i + 4] + a[j - 2:j]
counter += math.comb(lst.count('0'), x)
i += 4
j -= 2
print(counter)
``` | vfc_142846 | {
"difficulty": "easy",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/DAILY",
"time_limit": "2.992 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 3\n100101110000001011000001111110010011110010010111000101\n001010000000101111100000000000000111101010101111111010\n011110011110000001010100101110001011111010001001111010",
"output": "85",
"type": "stdin_stdout"
},... |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/linear-diophantine-equations5649/1 | Solve the following coding problem using the programming language python:
A Diophantine equation is a polynomial equation, usually in two or more unknowns, such that only the integral solutions are required. An Integral solution is a solution such that all the unknown variables take only integer values.
Given three in... | ```python
import math
class Solution:
def isPossible(self, A, B, C):
k = math.gcd(A, B)
if C % k == 0:
return 1
else:
return 0
``` | vfc_142850 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/linear-diophantine-equations5649/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "A = 3\nB = 6\nC = 9",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "A = 4\nB = 2\nC = 3",
"output": "0",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1179/C | Solve the following coding problem using the programming language python:
Serge came to the school dining room and discovered that there is a big queue here. There are $m$ pupils in the queue. He's not sure now if he wants to wait until the queue will clear, so he wants to know which dish he will receive if he does. A... | ```python
import sys
from itertools import accumulate
class Lazysegtree:
def __init__(self, A, intv, initialize=True, segf=min):
self.N = len(A)
self.N0 = 2 ** (self.N - 1).bit_length()
self.intv = intv
self.segf = segf
self.lazy = [0] * (2 * self.N0)
if initialize:
self.data = [intv] * self.N0 + A + ... | vfc_142851 | {
"difficulty": "hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1179/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 1\n1\n1\n1\n1 1 100\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1\n1\n1\n1\n2 1 100\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"... |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Sherlock is following N criminals, which are right now in a 2D grid. Each criminal at t=0, decides to move in certain fixed direction. Each criminal moves with same speed. These fixed directions are North, East, West and South. Two or more crim... | ```python
for _ in range(eval(input())):
n = eval(input())
m = n
D = {}
C = []
i = 0
mnx, mxx, mny, mxy = 0, 0, 0, 0
for __ in range(n):
x, y, d = input().split()
x = int(x) * 2
y = int(y) * 2
mxx = max(mxx, x)
mxy = max(mxy, y)
mnx = min(mnx, x)
mny = min(mny, y)
C.append([x, y, d])
D[(x, y)] ... | vfc_142855 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "20\n4\n0 0 N\n10 10 W\n20 20 N\n30 30 E\n4\n-10 0 N\n0 -10 E\n0 10 W\n10 0 S\n4\n0 0 E\n9 0 W\n0 4 S\n0 5 S\n9\n-1 0 E\n1 0 E\n0 0 N\n-1 -1 W\n1 -1 W\n0 1 S\n0 -1 W\n-1 1 S\n1 1 E\n5\n-2 -1 S\n-3 -1 W\n-2 -3 N\n1 3 S\n-3 -2 E\n9\n-... | |
taco | verifiable_code | https://www.codechef.com/problems/CHEFSTR1 | Solve the following coding problem using the programming language python:
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Having already mastered cooking, Chef has now decided to learn how to play the guitar. Often while trying to play a song, Chef has to skip s... | ```python
t = int(input())
while t > 0:
n = int(input())
arr = list(map(int, input().split()))
count = 0
for i in range(n - 1):
count += max(arr[i], arr[i + 1]) - min(arr[i], arr[i + 1]) - 1
print(count)
t -= 1
``` | vfc_142859 | {
"difficulty": "easy",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/CHEFSTR1",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n6\n1 6 11 6 10 11\n4\n1 3 5 7",
"output": "15\n3",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1187/A | Solve the following coding problem using the programming language python:
Your favorite shop sells n Kinder Surprise chocolate eggs. You know that exactly s stickers and exactly t toys are placed in n eggs in total.
Each Kinder Surprise can be one of three types:
* it can contain a single sticker and no toy;
* ... | ```python
for _ in range(int(input())):
(n, s, t) = map(int, input().split())
print(max(n - s + 1, n - t + 1))
``` | vfc_142876 | {
"difficulty": "easy",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1187/A",
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1 1 1\n1000000000 1000000000 1000000000\n1000000000 999999999 1\n999999999 666666667 666666666\n",
"output": "1\n1\n1000000000\n333333334\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": ... |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/union-find/1 | Solve the following coding problem using the programming language python:
This problem is to implement disjoint set union. There will be 2 incomplete functions namely union and find. You have to complete these functions.
Union: Join two subsets into a single set.
isConnected: Determine which subset a particular eleme... | ```python
class Solution:
@staticmethod
def find(par, r):
while par[r] != r:
r = par[r]
return r
@staticmethod
def compress(par, x, r):
while x != r:
par[x] = r
x = par[x]
def union_(self, a, b, par, rank1):
r1 = self.find(par, a)
r2 = self.find(par, b)
if r1 != r2:
par[r1] = r2
self.c... | vfc_142884 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/union-find/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N = 5\r\nq = 4\r\nQueries = \r\nUnion(1,3)\r\nisConnected(1,2)\r\nUnion(1,5)\r\nisConnected(3,5)",
"output": "0\r\n1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "N = 5\r\nq = 4\r\nQueries... |
taco | verifiable_code | https://codeforces.com/problemset/problem/1086/A | Solve the following coding problem using the programming language python:
The Squareland national forest is divided into equal 1 × 1 square plots aligned with north-south and east-west directions. Each plot can be uniquely described by integer Cartesian coordinates (x, y) of its south-west corner.
Three friends, Alic... | ```python
s = [[int(i) for i in input().split()] for j in range(3)]
s.sort()
a = s[0]
b = s[1]
c = s[2]
print(c[0] - a[0] + max(a[1], b[1], c[1]) - min(a[1], b[1], c[1]) + 1)
for i in range(a[0], b[0]):
print('{} {}'.format(i, a[1]))
for i in range(min(a[1], b[1], c[1]), max(a[1], b[1], c[1]) + 1):
print('{} {}'.form... | vfc_142885 | {
"difficulty": "medium_hard",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1086/A",
"time_limit": "1.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 0\n2 2\n1 1\n",
"output": "4\n1 0\n1 1\n1 2\n2 2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "670 672\n593 626\n593 792\n",
"output": "244\n593 626\n593 627\n593 628\n593 629\n5... |
taco | verifiable_code | https://www.codechef.com/problems/CHFRICH | Solve the following coding problem using the programming language python:
Read problem statements in [Mandarin], [Bengali], [Russian], and [Vietnamese] as well.
Chef aims to be the richest person in Chefland by his new restaurant franchise. Currently, his assets are worth $A$ billion dollars and have no liabilities. ... | ```python
t = int(input())
for i in range(t):
(a, b, x) = map(int, input().split())
print((b - a) // x)
``` | vfc_142894 | {
"difficulty": "easy",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/CHFRICH",
"time_limit": "0.5 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n100 200 10\n111 199 11\n190 200 10",
"output": "10\n8\n1",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1015/A | Solve the following coding problem using the programming language python:
You are given a set of $n$ segments on the axis $Ox$, each segment has integer endpoints between $1$ and $m$ inclusive. Segments may intersect, overlap or even coincide with each other. Each segment is characterized by two integers $l_i$ and $r_... | ```python
(n, m) = map(int, input().split())
L = (m + 2) * [0]
for _ in range(n):
(l, r) = map(int, input().split())
L[l] += 1
L[r + 1] -= 1
ans = []
for i in range(1, m + 1):
L[i] += L[i - 1]
if L[i] == 0:
ans.append(i)
print(len(ans))
print(*ans)
``` | vfc_142898 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1015/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 5\n2 2\n1 2\n5 5\n",
"output": "2\n3 4 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 7\n1 7\n",
"output": "0\n\n",
"type": "stdin_stdout"
},
{
"fn_name": n... |
taco | verifiable_code | https://codeforces.com/problemset/problem/362/B | Solve the following coding problem using the programming language python:
Little boy Petya loves stairs very much. But he is bored from simple going up and down them — he loves jumping over several stairs at a time. As he stands on some stair, he can either jump to the next one or jump over one or two stairs at a time... | ```python
(n, m) = map(int, input().split())
if m == 0:
print('YES')
exit(0)
a = set(map(int, input().split()))
l = 0
for i in a:
if i + 1 in a and i + 2 in a:
l += 1
if 1 in a or n in a or l > 0:
print('NO')
else:
print('YES')
``` | vfc_142906 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/362/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10 5\n2 4 8 3 6\n",
"output": "NO",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 5\n2 4 5 7 9\n",
"output": "YES",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/491/A | Solve the following coding problem using the programming language python:
Hiking club "Up the hill" just returned from a walk. Now they are trying to remember which hills they've just walked through.
It is known that there were N stops, all on different integer heights between 1 and N kilometers (inclusive) above the... | ```python
from sys import stdout, stdin
import math
r = lambda : int(input())
ra = lambda : [*map(int, input().split())]
raw = lambda : [*stdin.readline()]
out = lambda a: stdout.write(''.join(a))
a = r()
b = r()
n = a + b + 1
p = [str(i + 1) + ' ' for i in range(1, n)]
res = []
if (a or b) == 0:
out('1')
else:
if a ... | vfc_142910 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/491/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "0\n1\n",
"output": "2 1 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n1\n",
"output": "2 3 4 1 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"inpu... |
taco | verifiable_code | https://codeforces.com/problemset/problem/1411/E | Solve the following coding problem using the programming language python:
You've got a string $S$ consisting of $n$ lowercase English letters from your friend. It turned out that this is a number written in poman numerals. The poman numeral system is long forgotten. All that's left is the algorithm to transform number... | ```python
(_, T) = [int(x) for x in input().split()]
L = [ord(x) - ord('a') for x in input()]
T -= 2 ** L[-1]
T += 2 ** L[-2]
L = L[:-2]
L.sort(reverse=True)
for c in L:
T += (1 if T < 0 else -1) * (1 << c)
print('Yes' if T == 0 else 'No')
``` | vfc_142914 | {
"difficulty": "hard",
"memory_limit": "256 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1411/E",
"time_limit": "1 second"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 -1\nba\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 -7\nabc\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"in... |
taco | verifiable_code | https://codeforces.com/problemset/problem/1760/A | Solve the following coding problem using the programming language python:
Given three distinct integers $a$, $b$, and $c$, find the medium number between all of them.
The medium number is the number that is neither the minimum nor the maximum of the given three numbers.
For example, the median of $5,2,6$ is $5$, sin... | ```python
t = int(input())
ans = [0] * t
for i in range(t):
a = sorted(list(map(int, input().split())))
ans[i] = a[1]
print('\n'.join(map(str, ans)))
``` | vfc_142918 | {
"difficulty": "easy",
"memory_limit": "256 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1760/A",
"time_limit": "1 second"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "9\n5 2 6\n14 3 4\n20 2 1\n1 2 3\n11 19 12\n10 8 20\n6 20 3\n4 1 3\n19 8 4\n",
"output": "5\n4\n2\n2\n12\n10\n6\n3\n8\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n1 3 2\n",
"out... |
taco | verifiable_code | https://www.codechef.com/problems/SUMPOWER | Solve the following coding problem using the programming language python:
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
You work as an engineer. You were given an empty board with $K$ consecutive cells; at any moment, each cell can display one character.
You want the board to display... | ```python
case = int(input())
for _ in range(case):
(n, k) = map(int, input().split(' '))
s = input()
arr = []
if n & 1 == 1:
value = n // 2
for i in range(value):
arr.append(i + 1)
for i in range(value, n):
arr.append(value)
value -= 1
else:
value = n // 2
for i in range(value):
arr.append(i... | vfc_142922 | {
"difficulty": "medium_hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/SUMPOWER",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n6 3\naabbcc\n5 2\nabccc\n4 3\naabb",
"output": "4\n3\n1",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/PROC2020/problems/ENGRIS | Solve the following coding problem using the programming language python:
Sandy is a professor at a very reputed institute. The institute mandates that all the lectures be communicated in English. As Sandy is not very good at English(or anything actually) the presentations he displays in class have a lot of spelling m... | ```python
from difflib import get_close_matches
import sys, os
def closeMatches(patterns, word):
return get_close_matches(word, patterns, 1, 0.9)[0]
def get_string():
return sys.stdin.readline().strip()
def get_ints():
return map(int, sys.stdin.readline().strip().split())
ans = []
test = int(input())
for i in ran... | vfc_142926 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/PROC2020/problems/ENGRIS",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n5 2\nszhbdvrngk\nqzhxibnuec\njfsalpwfkospl\nlevjehdkjy\nwdfhzgatuh\nszhbdvcngk\nqzhxbnuec\n",
"output": "szhbdvrngk\nqzhxibnuec\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
In the good old days, the Internet was free from fears and terrorism. People did not have to worry about any cyber criminals or mad computer scientists. Today, however, you are facing atrocious crackers wherever you are, unless being disconnecte... | ```python
import re
while True:
(n, m) = map(int, input().split())
if n | m == 0:
break
(rule, ans) = ([], [])
for i in range(n):
(g, s, d) = input().split()
rule.append((g[0] == 'p', re.compile((s + d).replace('?', '\\d'))))
for i in range(m):
(s, d, m) = input().split()
sd = s + d
for (G, SD) in rule... | vfc_142931 | {
"difficulty": "unknown_difficulty",
"memory_limit": "134.217728 megabytes",
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "1.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 5\npermit 192168?? ?12??34?\ndeny 19216899 012343?5\n19216711 11233340 HiIamACracker\n19216891 01234345 Hello\n19216899 01234345 HiIbmAlsoACracker\n19216809 11200340 World\n00000000 99999999 TheEndOfTheWorld\n1 2\npermit 12345678... | |
taco | verifiable_code | https://codeforces.com/problemset/problem/868/A | Solve the following coding problem using the programming language python:
As technologies develop, manufacturers are making the process of unlocking a phone as user-friendly as possible. To unlock its new phone, Arkady's pet dog Mu-mu has to bark the password once. The phone represents a password as a string of two lo... | ```python
password = input()
N = int(input())
words = []
for i in range(N):
words += [input()]
f = False
for i in range(N):
for j in range(N):
if password in words[i] + words[j]:
f = True
break
if f:
print('YES')
else:
print('NO')
``` | vfc_142935 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/868/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "ya\n4\nah\noy\nto\nha\n",
"output": "YES\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1141/A | Solve the following coding problem using the programming language python:
Polycarp plays "Game 23". Initially he has a number $n$ and his goal is to transform it to $m$. In one move, he can multiply $n$ by $2$ or multiply $n$ by $3$. He can perform any number of moves.
Print the number of moves needed to transform $n... | ```python
(n, m) = list(map(int, input().split()))
if m % n > 0:
print(-1)
else:
res = 0
a = m // n
while a % 2 == 0:
a //= 2
res += 1
while a % 3 == 0:
a //= 3
res += 1
if a == 1:
print(res)
else:
print(-1)
``` | vfc_142939 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1141/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "120 51840\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "42 42\n",
"output": "0\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/confused-pappu5749/1 | Solve the following coding problem using the programming language python:
Pappu is confused between 6 & 9. He works in the billing department of abc company and his work is to return the remaining amount to the customers. If the actual remaining amount is given we need to find the maximum possible extra amount given b... | ```python
class Solution:
def findDiff(self, amount):
str1 = str(amount)
str2 = ''
for i in range(len(str1)):
if str1[i] == '6':
str2 = str2 + '9'
else:
str2 = str2 + str1[i]
num = int(str2)
res = num - amount
return res
``` | vfc_142944 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/confused-pappu5749/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "amount = 56",
"output": "3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "amount = 66",
"output": "33",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/80/C | Solve the following coding problem using the programming language python:
The year of 2012 is coming...
According to an ancient choradrican legend in this very year, in 2012, Diablo and his brothers Mephisto and Baal will escape from hell, and innumerable hordes of demons will enslave the human world. But seven brave... | ```python
from itertools import combinations, product
Teams = [[1, 1, 5], [1, 2, 4], [1, 3, 3], [2, 2, 3]]
Names = {}
Names['Anka'] = 0
Names['Chapay'] = 1
Names['Cleo'] = 2
Names['Dracul'] = 3
Names['Hexadecimal'] = 4
Names['Snowy'] = 5
Names['Troll'] = 6
graph = [[0] * 7 for _ in range(7)]
N = int(input())
for _ in r... | vfc_142945 | {
"difficulty": "medium",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/80/C",
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "0\n2000000000 2000000000 1\n",
"output": "666666665 0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "22\nCleo likes Snowy\nCleo likes Troll\nChapay likes Dracul\nSnowy likes Troll\nDracul... |
taco | verifiable_code | https://codeforces.com/problemset/problem/316/A2 | Solve the following coding problem using the programming language python:
Special Agent Smart Beaver works in a secret research department of ABBYY. He's been working there for a long time and is satisfied with his job, as it allows him to eat out in the best restaurants and order the most expensive and exotic wood ty... | ```python
import math
s = input()
ques = s[1:].count('?')
d = {'A': 0, 'B': 0, 'C': 0, 'D': 0, 'E': 0, 'F': 0, 'G': 0, 'H': 0, 'I': 0, 'J': 0}
digit = set([str(i) for i in range(0, 10)])
digit.add('?')
ans = 1
ans *= pow(10, ques)
count = 0
for i in range(1, len(s)):
if s[i] not in digit and d[s[i]] == 0:
count += 1... | vfc_142949 | {
"difficulty": "medium",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/316/A2",
"time_limit": "1.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "???\n",
"output": "900",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "??JG?\n",
"output": "81000",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "9??... |
taco | verifiable_code | https://www.codechef.com/problems/PAR2 | Solve the following coding problem using the programming language python:
Ashu and Arvind participated in a coding contest, as a result of which they received N chocolates. Now they want to divide the chocolates between them equally.
Can you help them by deciding if it is possible for them to divide all the N chocola... | ```python
t = int(input())
for i in range(t):
n = int(input())
if n % 2 == 0:
print('Yes')
else:
print('No')
``` | vfc_142957 | {
"difficulty": "easy",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/PAR2",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n10\n4\n3\n2\n",
"output": "Yes\nYes\nNo\nYes",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/842/B | Solve the following coding problem using the programming language python:
Gleb ordered pizza home. When the courier delivered the pizza, he was very upset, because several pieces of sausage lay on the crust, and he does not really like the crust.
The pizza is a circle of radius r and center at the origin. Pizza consi... | ```python
stroka = input()
k = ''
for i in range(0, len(stroka)):
if stroka[i] == ' ':
R = int(k)
k = ''
else:
k += stroka[i]
d = int(k)
n = int(input())
x = []
y = []
r = []
answer = 0
for i in range(0, n):
stroka = input()
k = ''
count = 1
for i in range(0, len(stroka)):
if stroka[i] == ' ':
if count... | vfc_142965 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/842/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "8 4\n7\n7 8 1\n-7 3 2\n0 2 1\n0 -2 2\n-3 -3 1\n0 6 2\n5 3 1",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 8\n4\n0 0 9\n0 0 10\n1 0 1\n1 0 2",
"output": "0\n",
... |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Example
Input
anagram
grandmother
Output
4
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
s1 = input()
s2 = input()
cA = ord('a')
s1 = [ord(e) - cA for e in s1]
l1 = len(s1)
s2 = [ord(e) - cA for e in s2]
l2 = len(s2)
ans = 0
for l in range(1, min(l1, l2) + 1):
s = set()
use = [0] * 26
for i in range(l - 1):
use[s1[i]] += 1
for i in range(l - 1, l1):
use[s1[i]] += 1
s.add(tuple(use))
u... | vfc_142969 | {
"difficulty": "unknown_difficulty",
"memory_limit": "268.435456 megabytes",
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "10.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "anagram\ngrandmosher",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "anbgram\ngrandmosher",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name":... | |
taco | verifiable_code | https://codeforces.com/problemset/problem/439/E | Solve the following coding problem using the programming language python:
Today is Devu's birthday. For celebrating the occasion, he bought n sweets from the nearby market. He has invited his f friends. He would like to distribute the sweets among them. As he is a nice guy and the occasion is great, he doesn't want an... | ```python
import itertools
import functools
import operator
N = 100001
P = 10 ** 9 + 7
fact = [1]
for i in range(1, N):
fact.append(fact[-1] * i % P)
inv = [0, 1]
for i in range(2, N):
inv.append(P - P // i * inv[P % i] % P)
inv_fact = [1]
for i in range(1, N):
inv_fact.append(inv_fact[-1] * inv[i] % P)
least_div = ... | vfc_142973 | {
"difficulty": "hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/439/E",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n6 2\n7 2\n6 3\n6 4\n7 4\n",
"output": "2\n6\n9\n10\n20\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/COOK22/problems/LUCKYBAL | Solve the following coding problem using the programming language python:
A Little Elephant from the Zoo of Lviv likes lucky strings, i.e., the strings that consist only of the lucky digits 4 and 7.
The Little Elephant calls some string T of the length M balanced if there exists at least one integer X (1 ≤ X ≤ M) such... | ```python
x = eval(input())
for x in range(0, x):
ans = 0
d = input()
a = 0
cont = 0
for i in range(0, len(d)):
a += len(d) - i
if d[i] == '7':
ans += 1 + cont
cont += 1
else:
cont = 0
ans = a - ans
print(ans)
``` | vfc_142977 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/COOK22/problems/LUCKYBAL",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n47\n74\n477\n4747477\n\n\n",
"output": "2\n2\n3\n23\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.hackerrank.com/challenges/bowling-pins/problem | Solve the following coding problem using the programming language python:
Bowling is a sport in which a player rolls a bowling ball towards a group of pins, the target being to knock down the pins at the end of a lane.
In this challenge, the rules of the game are slightly modified. Now, there are a given number of pi... | ```python
def game_from(board: str) -> list:
game = []
count = 0
for c in board:
if c == 'I':
count += 1
elif count > 0:
game.append(count)
count = 0
if count > 0:
game.append(count)
return game
def moves_for(n: int, hits: [int]) -> [list]:
moves = []
for hit in hits:
left = 0
right = n - hit... | vfc_142981 | {
"difficulty": "medium_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.hackerrank.com/challenges/bowling-pins/problem",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n4\nIXXI\n4\nXIIX\n5\nIIXII\n5\nIIIII\n",
"output": "LOSE\nWIN\nLOSE\nWIN\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/THEATRE | Solve the following coding problem using the programming language python:
Chef's friend Alex runs a movie theatre. Due to the increasing number of platforms for watching movies online, his business is not running well. As a friend, Alex asked Chef to help him maximise his profits. Since Chef is a busy person, he needs... | ```python
ans = 0
for _ in range(int(input())):
n = int(input())
(A, B, C, D) = ([0] * 4, [0] * 4, [0] * 4, [0] * 4)
for i in range(n):
(m, t) = map(str, input().split())
if m == 'A':
if t == '12':
A[0] += 1
elif t == '3':
A[1] += 1
elif t == '6':
A[2] += 1
else:
A[3] += 1
elif m ==... | vfc_142986 | {
"difficulty": "medium_hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/THEATRE",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n12\nA 3\nB 12\nC 6\nA 9\nB 12\nC 12\nD 3\nB 9\nD 3\nB 12\nB 9\nC 6\n7\nA 9\nA 9\nB 6\nC 3\nD 12\nA 9\nB 6\n2\nA 9\nB 6\n1\nD 12\n0\n",
"output": "575\n525\n-25\n-200\n-400\n475\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1547/D | Solve the following coding problem using the programming language python:
A sequence of non-negative integers $a_1, a_2, \dots, a_n$ is called growing if for all $i$ from $1$ to $n - 1$ all ones (of binary representation) in $a_i$ are in the places of ones (of binary representation) in $a_{i + 1}$ (in other words, $a_... | ```python
def main():
n = int(input())
x = list(map(int, input().split()))
y = [0]
for i in range(1, n):
newx = x[i - 1] | x[i]
y.append(newx ^ x[i])
x[i] = newx
print(*y)
return
t = int(input())
for _ in range(t):
main()
``` | vfc_142990 | {
"difficulty": "easy",
"memory_limit": "512 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1547/D",
"time_limit": "2 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n4\n1 3 7 15\n4\n1 2 4 8\n5\n1 2 3 4 5\n4\n11 13 15 1\n1\n0\n",
"output": "0 0 0 0 \n0 1 3 7 \n0 1 0 3 2 \n0 2 0 14 \n0 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n4\n1 3 7 15\n4... |
taco | verifiable_code | https://codeforces.com/problemset/problem/132/A | Solve the following coding problem using the programming language python:
INTERCAL is the oldest of esoteric programming languages. One of its many weird features is the method of character-based output, known as Turing Tape method. It converts an array of unsigned 8-bit integers into a sequence of characters to print... | ```python
ans = 0
for i in input():
t = bin(ord(i))[2:][::-1]
k = int(t + '0' * (8 - len(t)), 2)
print((ans - k) % 256)
ans = k
``` | vfc_142995 | {
"difficulty": "easy",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/132/A",
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "o2^\"t\n",
"output": "10\n170\n210\n54\n22\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "w7zw3)Vw&h\n",
"output": "18\n2\n142\n112\n34\n56\n42\n124\n138\n78\n",
"type": "stdi... |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/number-of-open-doors1552/1 | Solve the following coding problem using the programming language python:
Consider a long alley with a N number of doors on one side. All the doors are closed initially. You move to and fro in the alley changing the states of the doors as follows: you open a door that is already closed and you close a door that is alr... | ```python
from math import sqrt
class Solution:
def noOfOpenDoors(self, N):
return int(sqrt(N))
``` | vfc_143001 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/number-of-open-doors1552/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N = 2",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "N = 4",
"output": "2",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/ishaan-loves-chocolates2156/1 | Solve the following coding problem using the programming language python:
As we know, Ishaan has a love for chocolates. He has bought a huge chocolate bar that contains N chocolate squares. Each of the squares has a tastiness level which is denoted by an array A[].
Ishaan can eat the first or the last square of the ch... | ```python
from typing import List
class Solution:
def chocolates(self, n: int, arr: List[int]) -> int:
return min(arr)
``` | vfc_143002 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/ishaan-loves-chocolates2156/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "arr[ ] = {5, 3, 1, 6, 9}",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "arr[ ] = {5, 9, 2, 6}",
"output": "2",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/234ca3b438298fb04befd5abe7fbd98c006d4884/1 | Solve the following coding problem using the programming language python:
Geeks Island is represented by an N * M matrix mat. The island is touched by the Indian Ocean from the top and left edges and the Arabian Sea from the right and bottom edges. Each element of the matrix represents the height of the cell.
Due to t... | ```python
class Solution:
def water_flow(self, grid, n, m):
def dfs(i, j, ref_set, prev):
if i < 0 or j < 0 or i >= n or (j >= m) or (grid[i][j] < prev) or ((i, j) in ref_set):
return 0
ref_set.add((i, j))
dfs(i + 1, j, ref_set, grid[i][j])
dfs(i - 1, j, ref_set, grid[i][j])
dfs(i, j + 1, ref_se... | vfc_143003 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/234ca3b438298fb04befd5abe7fbd98c006d4884/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N = 5, M = 5\r\nmat[][] = {{1, 3, 3, 2, 4},\r\n {4, 5, 6, 4, 4},\r\n {2, 4, 5, 3, 1},\r\n {6, 7, 1, 4, 5},\r\n {6, 1, 1, 3, 4}}",
"output": "8",
"type": "stdin_... |
taco | verifiable_code | https://www.codechef.com/problems/BARRAY | Solve the following coding problem using the programming language python:
You're given an array A of N integers. You need to find the minimum cost of creating another array B of N integers with the following properties
B_{i} ≥ 0 for each 1 ≤ i ≤ N
The GCD of adjacent elements of B is equal to 1, i.e, \gcd(B_{i}, B_{i... | ```python
from math import inf
from collections import *
import math, os, sys, heapq, bisect, random, threading
from functools import lru_cache
from itertools import *
def inp():
return sys.stdin.readline().rstrip('\r\n')
def out(var):
sys.stdout.write(str(var))
def inpu():
return int(inp())
def lis():
return l... | vfc_143004 | {
"difficulty": "very_hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/BARRAY",
"time_limit": "1.5 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n3\n15 16 19\n2\n5 10\n7\n9 15 7 19 10 7 1\n",
"output": "3\n3\n8",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/PTRN2021/problems/ITGUY55 | Solve the following coding problem using the programming language python:
The chef is trying to decode 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 cas... | ```python
for _ in range(int(input())):
n = int(input())
num = ''
val = 1
for i in range(n):
num += str(val)
if val == 1:
val = 0
else:
val = 1
for i in range(n):
print(num)
``` | vfc_143008 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/PTRN2021/problems/ITGUY55",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1\n2\n3\n4\n",
"output": "1\n10\n10\n101\n101\n101\n1010\n1010\n1010\n1010\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/182/B | Solve the following coding problem using the programming language python:
Vasya lives in a strange world. The year has n months and the i-th month has ai days. Vasya got a New Year present — the clock that shows not only the time, but also the date.
The clock's face can display any number from 1 to d. It is guarantee... | ```python
d = int(input())
n = int(input())
months = list(map(int, input().split()))
changes = 0
for month in months[:-1]:
changes += d - month
print(changes)
``` | vfc_143012 | {
"difficulty": "easy",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/182/B",
"time_limit": "1.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "102\n100\n31 22 59 16 11 56 81 4 19 31 8 72 4 92 18 7 13 12 62 40 34 67 40 23 96 4 90 28 3 18 54 49 10 71 73 79 69 7 41 75 59 13 2 78 72 6 95 33 52 97 7 86 57 94 12 93 19 94 59 28 5 96 46 102 2 101 57 85 53 69 72 39 14 75 8 16 10 5... |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Amer cabs has released a scheme through which a user gets a free drive when he shares a reference code with another Amer app user. Given N number of app users, output total number of free drives gained by all of them. Two same users cannot share... | ```python
t=eval(input())
while t :
t-=1
n=eval(input())
if n==1 :
print("0")
else :
print(n*(n-1)/2)
``` | vfc_143016 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "340\n5277\n9302\n7274\n3\n5968\n1327\n255\n27\n5665\n8104\n138\n4051\n4168\n507\n7773\n2688\n3497\n4074\n1403\n3599\n2007\n7621\n3124\n1195\n7245\n1979\n3365\n6607\n4816\n9336\n3620\n1557\n3404\n5451\n3739\n2504\n1845\n5533\n8298\n... | |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Write a program which manipulates a disjoint set S = {S1, S2, . . . , Sk}.
First of all, the program should read an integer n, then make a disjoint set where each element consists of 0, 1, ... n−1 respectively.
Next, the program should read an... | ```python
def root(i):
if par[i] == i:
return i
par[i] = root(par[i])
return par[i]
def unite(x, y):
xr = root(x)
yr = root(y)
par[yr] = xr
def same(x, y):
return root(x) == root(y)
(n, q) = map(int, input().split())
par = list(range(n))
for i in range(q):
commands = list(map(int, input().split()))
if comm... | vfc_143024 | {
"difficulty": "unknown_difficulty",
"memory_limit": "134.217728 megabytes",
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "3.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 12\n0 2 4\n0 2 3\n1 1 2\n1 3 4\n1 1 4\n1 3 2\n0 1 3\n1 2 4\n1 3 0\n0 0 4\n1 0 2\n1 3 0",
"output": "0\n1\n0\n1\n1\n0\n1\n1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 12\n0 1 4\n0 ... | |
taco | verifiable_code | https://www.codechef.com/problems/IMPACT | Solve the following coding problem using the programming language python:
Consider the infinite x$x$ axis. There are N$N$ impacts on this X-axis at integral points (X1$X_1$,X2$X_2$,....XN$X_N$) (all distinct) . An impact at a point X$X$i propagates such that at a point X$X$0, the effect of the impact is K|Xi−X0|$K^{|... | ```python
T = int(input())
for i in range(T):
l = list(map(int, input().split()))
(n, k, m, x) = (l[0], l[1], l[2], l[3])
if k == 1:
if n == m:
print('yes')
else:
print('no')
elif m % k > 1:
print('no')
elif k == 2:
stack = []
var = 0
while m != 0:
var += m % k
stack.append(m % k)
m //= ... | vfc_143028 | {
"difficulty": "very_hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/IMPACT",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n4 3 10 10\n2 3 10 10\n",
"output": "no\nyes\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/sharing3134/1 | Solve the following coding problem using the programming language python:
Geek is very fond of chocolates. But he can't reach the kitchen shelf which has 'N' chocolates. His family has K members and he can call any number of family members to help him out. After acquiring the chocolates, the family members that Geek c... | ```python
class Solution:
def maxChocolate(self, N, K):
if K > N:
return N
else:
r = 0
for i in range(1, K + 1):
r = max(r, N % i)
return r
``` | vfc_143032 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/sharing3134/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N = 15, K = 4",
"output": "3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "N = 19, K = 5",
"output": "4",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/255/A | Solve the following coding problem using the programming language python:
Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was n integers a_1, a_2, ..., a_{n}. These numbers mean that Greg needs to do exactly n exercises today. Besides, Greg should repeat the i-th in order exe... | ```python
num = int(input())
k = list(map(int, input().split()))
chest = 0
bicep = 0
back = 0
for x in range(0, num):
if x % 3 == 0:
chest = chest + k[x]
if x % 3 == 1:
bicep = bicep + k[x]
if x % 3 == 2:
back = back + k[x]
if chest > bicep and chest > back:
print('chest')
elif bicep > chest and bicep > back:... | vfc_143033 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/255/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n2 8\n",
"output": "biceps\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n5 1 10\n",
"output": "back\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Ricky gives a number 'n' to John. Now Ricky wants John to generate Z with symbol "*" such that it spans n rows.
Example:
Input : n=3
Output :
***
*
***
Input : n=4
Output :
****
*
*
****
Constraint :
3 ≤ n ≤20
SAMPLE INPUT
5
SA... | ```python
n=int(input())
print('*'*n)
for i in range(n-2):
print(' '*(n-i-2) + '*')
print('*'*n)
``` | vfc_143037 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5",
"output": "*******\n *\n *\n *\n *\n *\n*******",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10",
"output": "**********\n *\n *\n *\n *\n *\n ... | |
taco | verifiable_code | https://codeforces.com/problemset/problem/915/C | Solve the following coding problem using the programming language python:
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0.
It is allowed to leave a as it is.
-----In... | ```python
fact_ = [1] * 50
def fact(n):
return fact_[n]
def get_perm(n, k):
if k > fact(n):
exit(123)
if n == 1:
return [1]
k -= 1
res = []
not_used = [i for i in range(1, n + 1)]
size = fact(n - 1)
for i in range(n):
cnt = k // size
res.append(not_used[cnt])
not_used.pop(cnt)
k %= size
if i != ... | vfc_143041 | {
"difficulty": "medium_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/915/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "123\n222\n",
"output": "213\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3921\n10000\n",
"output": "9321\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
taco | verifiable_code | https://www.codechef.com/problems/CONFLIP | Solve the following coding problem using the programming language python:
Little Elephant was fond of inventing new games. After a lot of research, Little Elephant came to know that most of the animals in the forest were showing less interest to play the multi-player games. Little Elephant had started to invent single... | ```python
t = int(input())
for it in range(t):
g = int(input())
for its in range(g):
(i, n, q) = map(int, input().split())
if i == q:
print(n // 2)
else:
print(n // 2 + n % 2)
``` | vfc_143045 | {
"difficulty": "easy",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/CONFLIP",
"time_limit": "5 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n2\n1 5 1\n1 5 2",
"output": "2\n3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n2\n1 1 1\n1 5 2",
"output": "0\n3\n",
"type": "stdin_stdout"
},
{
"fn_name":... |
taco | verifiable_code | https://codeforces.com/problemset/problem/1763/B | Solve the following coding problem using the programming language python:
To destroy humanity, The Monster Association sent $n$ monsters to Earth's surface. The $i$-th monster has health $h_i$ and power $p_i$.
With his last resort attack, True Spiral Incineration Cannon, Genos can deal $k$ damage to all monsters aliv... | ```python
import sys
input = sys.stdin.readline
import math
def readList():
return list(map(int, input().split()))
def readInt():
return int(input())
def readInts():
return map(int, input().split())
def readStr():
return input().strip()
def solve():
(n, k) = readInts()
H = readList()
P = readList()
arr = s... | vfc_143049 | {
"difficulty": "easy",
"memory_limit": "256 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1763/B",
"time_limit": "1 second"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n6 7\n18 5 13 9 10 1\n2 7 2 1 2 6\n3 4\n5 5 5\n4 4 4\n3 2\n2 1 3\n1 1 1\n",
"output": "YES\nNO\nYES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n2 1\n1000000000 1\n1 1000000000\n",... |
taco | verifiable_code | https://codeforces.com/problemset/problem/792/F | Solve the following coding problem using the programming language python:
Vova plays a computer game known as Mages and Monsters. Vova's character is a mage. Though as he has just started, his character knows no spells.
Vova's character can learn new spells during the game. Every spell is characterized by two values ... | ```python
[q, m] = map(int, input().strip().split())
qis = [tuple(map(int, input().strip().split())) for _ in range(q)]
mod = 10 ** 6
j = 0
spell_chull = [(0, 0)]
def is_right(xy0, xy1, xy):
(x0, y0) = xy0
(x1, y1) = xy1
(x, y) = xy
return (x0 - x) * (y1 - y) >= (x1 - x) * (y0 - y)
def in_chull(x, y):
i = 0
if ... | vfc_143053 | {
"difficulty": "very_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/792/F",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 100\n1 4 9\n2 19 49\n2 19 49\n",
"output": "YES\nNO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 442006988299\n2 10 47\n1 9 83\n1 15 24\n2 19 47\n2 75 99\n2 85 23\n2 8 33\n2 9 82\n... |
taco | verifiable_code | https://www.codechef.com/problems/FLOW014 | Solve the following coding problem using the programming language python:
A certain type of steel is graded according to the following conditions.
1. Hardness of the steel must be greater than 50
2. Carbon content of the steel must be less than 0.7
3. Tensile strength must be greater than 5600
The grades awarded are... | ```python
for _ in range(int(input())):
(h, c, t) = map(float, input().split())
con1 = h > 50
con2 = c < 0.7
con3 = t > 5600
if con1 and con2 and con3:
print('10')
elif con1 and con2:
print('9')
elif con2 and con3:
print('8')
elif con1 and con3:
print('7')
elif con1 or con2 or con3:
print('6')
else:... | vfc_143057 | {
"difficulty": "easy",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/FLOW014",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 \n53 0.6 5602\n45 0 4500\n0 0 0 \n",
"output": "10\n6\n6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 \n67 0.6 5602\n45 0 4500\n0 0 0",
"output": "10\n6\n6\n",
"type": "... |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Broken crypto generator
JAG (Japanese Alumni Group) is a mysterious organization composed of many programmers, and in order to enter the building where the headquarters of this organization is located, it is necessary to solve the ciphertext ge... | ```python
def pm_to_chr(s):
s = s.group()
if s[-1] == '?':
return 'A'
ans = chr((ord(s[-1]) + s.count('+') - s.count('-') - ord('A')) % 26 + ord('A'))
return ans
def reverse(s):
s = s.group()
s = s[1:-1]
ans = ''.join(reversed(s))
return ans
import re
s = input()
while s != '.':
s = re.sub('[\\+\\-]*[\\w?]'... | vfc_143073 | {
"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": "A+A++A\nZ-Z--Z+-Z\n[ESRVEER]\nJ---?---J\n++++++++A+++Z-----------A+++Z\n[[++-+--?[--++-?++-+++L]][-+-----+-O]]++++---+L\n.",
"output": "ABC\nZYXZ\nREEVRSE\nJAG\nICPC\nJAPAN\n",
"type": "stdin_stdout"
}
]
} | |
taco | verifiable_code | https://codeforces.com/problemset/problem/1335/C | Solve the following coding problem using the programming language python:
You have $n$ students under your control and you have to compose exactly two teams consisting of some subset of your students. Each student had his own skill, the $i$-th student skill is denoted by an integer $a_i$ (different students can have t... | ```python
for i in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
maxx = 0
d = {}
for j in a:
d[j] = d.get(j, 0) + 1
if d[j] > maxx:
maxx = d[j]
if maxx == len(d):
print(maxx - 1)
else:
print(min(len(d), maxx))
``` | vfc_143077 | {
"difficulty": "easy",
"memory_limit": "256 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1335/C",
"time_limit": "2 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n7\n4 2 4 1 4 3 4\n5\n2 1 5 4 3\n1\n1\n4\n1 1 1 3\n",
"output": "3\n1\n0\n2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n9\n1 2 2 3 3 9 9 9 9\n",
"output": "3\n",
"type... |
taco | verifiable_code | https://codeforces.com/problemset/problem/1437/E | Solve the following coding problem using the programming language python:
You are given an array of $n$ integers $a_1$, $a_2$, ..., $a_n$, and a set $b$ of $k$ distinct integers from $1$ to $n$.
In one operation, you may choose two integers $i$ and $x$ ($1 \le i \le n$, $x$ can be any integer) and assign $a_i := x$. ... | ```python
import io
import os
from collections import Counter, defaultdict, deque
from bisect import bisect_right
inf = float('inf')
def lengthOfLIS(nums, mn, mx):
mnVal = mn - -1
mxVal = mx - len(nums)
chain = [mnVal]
for (i, x) in enumerate(nums):
v = x - i
if mnVal > v or v > mxVal:
continue
newLen = b... | vfc_143085 | {
"difficulty": "hard",
"memory_limit": "256 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1437/E",
"time_limit": "2 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7 2\n1 2 1 1 3 5 1\n3 5\n",
"output": "4\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/756/A | Solve the following coding problem using the programming language python:
Pavel cooks barbecue. There are n skewers, they lay on a brazier in a row, each on one of n positions. Pavel wants each skewer to be cooked some time in every of n positions in two directions: in the one it was directed originally and in the rev... | ```python
import sys
input = sys.stdin.readline
n = int(input())
permutation = list(map(int, input().split()))
go = set(range(1, n + 1))
reached = set()
ans = 0
while go:
x = go.pop()
while x not in reached:
reached.add(x)
x = permutation[x - 1]
if x in go:
go.remove(x)
ans += 1
if ans == 1:
ans = 0
permut... | vfc_143089 | {
"difficulty": "medium_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/756/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n4 3 2 1\n0 1 1 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n2 3 1\n0 0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": n... |
taco | verifiable_code | https://codeforces.com/problemset/problem/1421/A | Solve the following coding problem using the programming language python:
In order to celebrate Twice's 5th anniversary, Tzuyu and Sana decided to play a game.
Tzuyu gave Sana two integers $a$ and $b$ and a really important quest.
In order to complete the quest, Sana has to output the smallest possible value of ($a ... | ```python
t = int(input())
for _ in range(t):
(n, k) = map(int, input().split())
print(n ^ k)
``` | vfc_143093 | {
"difficulty": "easy",
"memory_limit": "256 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1421/A",
"time_limit": "1 second"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n6 12\n4 9\n59 832\n28 14\n4925 2912\n1 1\n",
"output": "10\n13\n891\n18\n6237\n0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n6 12\n4 9\n59 832\n28 14\n4925 2912\n2 1\n",
"o... |
taco | verifiable_code | https://www.codechef.com/INOIPRAC/problems/INOI1902 | Solve the following coding problem using the programming language python:
You are given $N$ integers in an array: $A[1], A[2], \ldots, A[N]$. You also have another integer $L$.
Consider a sequence of indices ($i_1, i_2, \ldots, i_k$). Note that a particular index can occur multiple times in the sequence, and there is ... | ```python
def insort(l, v):
s = 0
e = len(l)
while True:
mid = (s + e) // 2
if s == e or mid > len(l):
break
if l[mid][0] < v[0]:
s = mid + 1
elif l[mid][0] > v[0]:
e = mid
else:
break
l.insert(mid, v)
for _ in range(int(input())):
(n, l) = map(int, input().split())
a_l = list(map(int, input... | vfc_143097 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/INOIPRAC/problems/INOI1902",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n6 3\n2 4 1 12 3 5\n",
"output": "3\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/CFINASUM | Solve the following coding problem using the programming language python:
You are given a sequence $A_1, A_2, \ldots, A_N$. For each $k$ ($1 \le k \le N$), let's define a function $f(k)$ in the following way:
- Consider a sequence $B_1, B_2, \ldots, B_N$, which is created by setting $A_k = 0$. Formally, $B_k = 0$ and ... | ```python
from collections import Counter
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
ans = 0
total = sum(a)
prefix = 0
d = Counter()
for i in range(n):
remains = total - a[i]
if not remains % 2:
ans += d[remains // 2]
prefix += a[i]
d[prefix] += 1
d.clear()
su... | vfc_143102 | {
"difficulty": "very_hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/CFINASUM",
"time_limit": "3 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n6\n1 2 1 1 3 1\n3\n4 1 4\n",
"output": "6\n2\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/MARCH12/problems/SPOON | Solve the following coding problem using the programming language python:
Chef recently saw the movie Matrix. He loved the movie overall but he didn't agree with some things in it. Particularly he didn't agree with the bald boy when he declared - There is no spoon. Being a chef, he understands the importance of the sp... | ```python
import sys
spoon = ['SPOON', 'spoon']
def main():
try:
tc = int(input())
while tc > 0:
tc = tc - 1
[r, c] = input().split()
r = int(r)
c = int(c)
k = 0
flag = 0
matrix = [0] * r
i = 0
while i < r:
matrix[i] = input()
i = i + 1
for m in matrix:
for s in m:
i... | vfc_143110 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/MARCH12/problems/SPOON",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n3 6\nabDefb\nbSpoon\nNIKHil\n6 6\naaaaaa\nssssss\nxuisdP\noooooo\nioowoo\nbdylan\n6 5\nbdfhj\ncacac\nopqrs\nddddd\nindia\nyucky\n",
"output": "There is a spoon!\nThere is a spoon!\nThere is indeed no spoon!\n",
"type... |
taco | verifiable_code | https://www.codechef.com/DEC15/problems/SEADIV | Solve the following coding problem using the programming language python:
Sereja has two integers — A and B — in 7-ary system. He wants to calculate the number C, such that B * C = A. It is guaranteed that B is a divisor of A.
Please, help Sereja calculate the number C modulo 7L.
-----Input-----
First line of input... | ```python
t = int(input())
while t > 0:
a = int(input())
b = int(input())
l = int(input())
x = 0
y = 0
z = 0
a1 = 0
b1 = 0
c1 = 0
while a // 10 != 0 or a % 10 != 0:
a1 += (a % 10 + a // 10 % 10 * 7 + a // 100 % 10 * 49 + a // 1000 % 10 * 343 + a // 10000 % 10 * 2401 + a // 100000 % 10 * 16807 + a // 1000000... | vfc_143114 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/DEC15/problems/SEADIV",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n21\n5\n10\n202\n13\n1\n202\n13\n2\n",
"output": "3\n3\n13\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1430/B | Solve the following coding problem using the programming language python:
You have $n$ barrels lined up in a row, numbered from left to right from one. Initially, the $i$-th barrel contains $a_i$ liters of water.
You can pour water from one barrel to another. In one act of pouring, you can choose two different barrel... | ```python
R = lambda : map(int, input().split())
(t,) = R()
exec(t * 'n,k=R();print(sum(sorted(R())[~k:]));')
``` | vfc_143119 | {
"difficulty": "easy",
"memory_limit": "256 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1430/B",
"time_limit": "2 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n4 1\n5 5 5 5\n3 2\n0 0 0\n",
"output": "10\n0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n4 2\n5 5 5 5\n3 2\n0 0 0\n",
"output": "15\n0\n",
"type": "stdin_stdout"
... |
taco | verifiable_code | https://www.codechef.com/problems/MOBKUN | Solve the following coding problem using the programming language python:
The followers of Psycho-Helmet religion follow a peculiar calendar – a normal year contains N days. Every K-th year is a “MOB” year. For example, if K = 4, then years 4, 8, 12, 16 \ldots are “MOB” years. A “MOB” year contains M additional days i... | ```python
for i in range(int(input())):
(n, m, k, x) = map(int, input().split())
if x % (n * (k - 1) + n + m) > n * (k - 1) or x % (n * (k - 1) + n + m) == 0:
print('YES')
else:
print('NO')
``` | vfc_143123 | {
"difficulty": "easy",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/MOBKUN",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n2 1 4 17\n3 7 5 50\n3 7 5 61",
"output": "YES\nNO\nYES",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/CUBE2020/problems/STROCK | Solve the following coding problem using the programming language python:
Rakesh has built a model rocket and wants to test how stable it is. He usually uses a magic box which runs some tests on the rocket and tells if it is stable or not, but his friend broke it by trying to find out how stable he is (very delicate m... | ```python
import random
def sign(i):
if i > 0:
return 1
elif i <= 0:
return 0
bleh = []
for _ in range(int(input())):
p = list(map(int, input().rstrip().split()))
max_rows = len(p)
if all([x == 0 for x in p]):
print(1)
continue
if max_rows <= 1:
bleh.append(max_rows)
continue
max_pow = max_rows - 1
... | vfc_143127 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/CUBE2020/problems/STROCK",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n10 12 4 5 3\n",
"output": "0\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/275/B | Solve the following coding problem using the programming language python:
Consider an n × m grid. Initially all the cells of the grid are colored white. Lenny has painted some of the cells (at least one) black. We call a painted grid convex if one can walk from any black cell to any another black cell using a path of ... | ```python
(n, m) = list(map(int, input().split()))
(row, col_sum, row_sum, black) = ([], [], [], [])
for i in range(n):
row.append(input())
t = [0]
for j in range(m):
t += [t[j] + (row[i][j] == 'B')]
row_sum += [t]
d = [[0, 1], [1, 0], [-1, 0], [0, -1]]
for i in range(n):
for j in range(m):
if row[i][j] is 'W'... | vfc_143132 | {
"difficulty": "medium_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/275/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 4\nWWBW\nBWWW\nWWWB\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 1\nB\nB\nW\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name":... |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Roy has a wooden log (tree trunk) of length L units.
Since the log is too heavy for him to lift, he wants to cut it into pieces.
He can lift pieces of length 1 or 2 units.
He wonders in how many ways can he make such pieces of the wooden lo... | ```python
k = int(input())
for c in range(k):
a = int(input())
if a%2 == 0:
print(a/2+1,a/2-1)
else:
print((a-1)/2+1,(a-1)/2)
``` | vfc_143136 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10000\n339152592\n901134765\n325990816\n306462953\n818617641\n224260477\n301769667\n394813572\n835683812\n145760882\n752443404\n299115107\n164288931\n779456540\n323432323\n395609895\n912802357\n989399274\n117506615\n473689601\n2187... | |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Monk and his P-1 friends recently joined a college. He finds that N students have already applied for different courses before him. Courses are assigned numbers from 1 to C. He and his friends will follow the following conditions when choosing ... | ```python
import heapq
def solve(c, iqs, piqs):
res = []
q = [(0, i, 0, (0, 0)) for i in range(len(iqs) + 1, c + 1)]
q += [(iq, i, 1, (0, iq)) for i, iq in enumerate(iqs, 1)]
heapq.heapify(q)
for iq in piqs:
_, course, student_count, last_iqs = q[0]
res.append(course)
student_count += 1
last_iqs = (last_i... | vfc_143148 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10 10 10\n2 8 5 1 10 5 9 9 3 5\n2 5 1 8 6 5 1 10 1 6",
"output": "4 1 9 3 6 10 4 2 9 9 ",
"type": "stdin_stdout"
}
]
} | |
taco | verifiable_code | https://codeforces.com/problemset/problem/1767/B | Solve the following coding problem using the programming language python:
There are $n$ block towers, numbered from $1$ to $n$. The $i$-th tower consists of $a_i$ blocks.
In one move, you can move one block from tower $i$ to tower $j$, but only if $a_i > a_j$. That move increases $a_j$ by $1$ and decreases $a_i$ by $... | ```python
import sys
rd = sys.stdin.readline
for _ in range(int(rd())):
n = int(rd())
a = list(map(int, rd().split()))
b = sorted(a[1:])
ans = a[0]
for i in b:
if i > ans:
ans = (ans + i + 1) // 2
print(ans)
``` | vfc_143152 | {
"difficulty": "easy",
"memory_limit": "256 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1767/B",
"time_limit": "2 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n3\n1 2 3\n3\n1 2 2\n2\n1 1000000000\n10\n3 8 6 7 4 1 2 4 10 1\n",
"output": "3\n2\n500000001\n9\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/flipping-bits-no-and-binary-format-in-reverse-order0513/1 | Solve the following coding problem using the programming language python:
Given a list of 32 bit unsigned integers N. Find X, the unsigned integer you get by flipping bits in the binary representation of N. i.e. unset bits must be set, and set bits must be unset. Also find the binary representation of X in reverse ord... | ```python
class Solution:
def flipBits(self, N):
num = 4294967295 - N
binary_num = bin(num)[2:]
return (num, ''.join(reversed(['0'] * (32 - len(binary_num)) + list(binary_num))))
``` | vfc_143156 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/flipping-bits-no-and-binary-format-in-reverse-order0513/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N = 1",
"output": "4294967294 01111111111111111111111111111111",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "N = 2",
"output": "4294967293 10111111111111111111111111111111",
"t... |
taco | verifiable_code | https://codeforces.com/problemset/problem/1629/A | Solve the following coding problem using the programming language python:
Did you know you can download more RAM? There is a shop with $n$ different pieces of software that increase your RAM. The $i$-th RAM increasing software takes $a_i$ GB of memory to run (temporarily, once the program is done running, you get the ... | ```python
for _ in range(int(input())):
(n, k) = map(int, input().split())
mem = list(map(int, input().split()))
ram = list(map(int, input().split()))
dp = []
for i in range(n):
dp.append([mem[i], ram[i]])
dp.sort()
rm = k
for i in dp:
if i[0] <= rm:
rm += i[1]
else:
break
print(rm)
``` | vfc_143159 | {
"difficulty": "easy",
"memory_limit": "256 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1629/A",
"time_limit": "1 second"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n3 10\n20 30 10\n9 100 10\n5 1\n1 1 5 1 1\n1 1 1 1 1\n5 1\n2 2 2 2 2\n100 100 100 100 100\n5 8\n128 64 32 16 8\n128 64 32 16 8\n",
"output": "29\n6\n1\n256\n",
"type": "stdin_stdout"
},
{
"fn_name": null... |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/find-the-smallest-and-second-smallest-element-in-an-array3226/1 | Solve the following coding problem using the programming language python:
Given an array of integers, your task is to find the smallest and second smallest element in the array. If smallest and second smallest do not exist, print -1.
Example 1:
Input :
5
2 4 3 5 6
Output :
2 3
Explanation:
2 and 3 are respectively t... | ```python
def minAnd2ndMin(a, n):
a = list(set(a))
a.sort()
l = a[:2]
if len(l) == 2:
return l
else:
return (-1, -1)
``` | vfc_143172 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/find-the-smallest-and-second-smallest-element-in-an-array3226/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": "minAnd2ndMin",
"input": "5\n2 4 3 5 6",
"output": "2 3",
"type": "function_call"
},
{
"fn_name": "minAnd2ndMin",
"input": "6\n1 2 1 3 6 7",
"output": "1 2",
"type": "function_call"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/check-if-it-is-possible-to-survive-on-island4922/1 | Solve the following coding problem using the programming language python:
Ishika got stuck on an island. There is only one shop on this island and it is open on all days of the week except for Sunday. Consider following constraints:
N – The maximum unit of food you can buy each day.
S – Number of days you are requir... | ```python
class Solution:
def minimumDays(self, S, N, M):
if M * 7 > N * 6 and S > 6 or M > N:
return -1
else:
day = M * S // N
if M * S % N != 0:
day += 1
return day
``` | vfc_143174 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/check-if-it-is-possible-to-survive-on-island4922/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "S = 10, N = 16, M = 2",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "S = 10, N = 20, M = 30",
"output": "-1",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1300/D | Solve the following coding problem using the programming language python:
Guy-Manuel and Thomas are going to build a polygon spaceship.
You're given a strictly convex (i. e. no three points are collinear) polygon P which is defined by coordinates of its vertices. Define P(x,y) as a polygon obtained by translating P b... | ```python
import sys
import math
from collections import defaultdict
from collections import deque
from itertools import combinations
from itertools import permutations
input = lambda : sys.stdin.readline().rstrip()
read = lambda : list(map(int, input().split()))
go = lambda : 1 / 0
def write(*args, sep='\n'):
for i ... | vfc_143175 | {
"difficulty": "medium_hard",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1300/D",
"time_limit": "1.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n-99555247 -9420873\n-68495517 -72858523\n-56392372 -82582689\n-45496035 -89051170\n-76555765 -25613520\n-88658910 -15889354\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"inp... |
taco | verifiable_code | https://codeforces.com/problemset/problem/1165/F1 | Solve the following coding problem using the programming language python:
The only difference between easy and hard versions is constraints.
Ivan plays a computer game that contains some microtransactions to make characters look cooler. Since Ivan wants his character to be really cool, he wants to use some of these m... | ```python
import sys
def main():
(n, m) = map(int, input().split())
k = [int(x) for x in input().split()]
d = [[] for _ in range(4 * 10 ** 5 + 1)]
for j in range(m):
(dj, tj) = map(int, input().split())
d[dj - 1].append(tj - 1)
(lo, hi) = (0, 4 * 10 ** 5 + 1)
while lo < hi:
mi = (hi + lo) // 2
cash = mi
... | vfc_143180 | {
"difficulty": "hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1165/F1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 6\n1 2 0 2 0\n2 4\n3 3\n1 5\n1 2\n1 5\n2 3\n",
"output": "8\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/146/D | Solve the following coding problem using the programming language python:
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya loves long lucky ... | ```python
from math import *
from fractions import *
from sys import *
def li():
return list(map(int, input().split(' ')))
a = li()
if abs(a[2] - a[3]) > 1:
print(-1)
exit()
if a[2] == a[3]:
ans = '47' * a[2] + '4'
elif a[2] > a[3]:
ans = '47' * a[2]
else:
ans = '74' * a[3]
f = a[0] - ans.count('4')
s = a[1] - a... | vfc_143188 | {
"difficulty": "medium_hard",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/146/D",
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 10 1 2\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 1 3 1\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input... |
taco | verifiable_code | https://www.codechef.com/problems/ARRFILL | Solve the following coding problem using the programming language python:
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
You are given an array A of size N. Initially, the array is filled with 0-s.
There are M types of operations that you can perform on array A. The i^... | ```python
def gcd(a, b):
while b:
(a, b) = (b, a % b)
return a
def lcm(a, b):
return a * b // gcd(a, b)
for t in range(int(input())):
(n, m) = map(int, input().split())
operations = [list(map(int, input().split())) for i in range(m)]
operations.sort(key=lambda x: x[0], reverse=True)
ans = 0
running_lcm = 1
... | vfc_143192 | {
"difficulty": "medium_hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/ARRFILL",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n10 1\n5 2\n8 2\n5 2\n6 3\n3 2\n2 2\n1 3",
"output": "25\n41\n5",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.hackerrank.com/challenges/the-story-of-a-tree/problem | Solve the following coding problem using the programming language python:
One day Bob drew a tree, $\mathbf{T}$, with $n$ nodes and $n-1$ edges on a piece of paper. He soon discovered that parent of a node depends on the root of the tree. The following images shows an example of that:
Learning the fact, Bob invented ... | ```python
import sys
adj = []
p = []
def dfs(v, par):
ret = 0
for u in p[v]:
ret += +1 if par == u else 0
for u in adj[v]:
if u != par:
ret += dfs(u, v)
return ret
def dfs2(v, par, cur, lim):
if par != -1:
for u in p[par]:
if u == v:
cur += 1
for u in p[v]:
if u == par:
cur -= 1
ret = cur ... | vfc_143196 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.hackerrank.com/challenges/the-story-of-a-tree/problem",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n4\n1 2\n1 3\n3 4\n2 2\n1 2\n3 4\n3\n1 2\n1 3\n2 2\n1 2\n1 3\n",
"output": "1/2\n1/3\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.hackerrank.com/challenges/strange-code/problem | Solve the following coding problem using the programming language python:
There is a strange counter. At the first second, it displays the number $3$. Each second, the number displayed by decrements by $\mbox{1}$ until it reaches $\mbox{1}$. In next second, the timer resets to $2\times\textbf{the initial number for th... | ```python
t = int(input())
t1 = 3
while t1 < t:
t -= t1
t1 *= 2
print(t1 - t + 1)
``` | vfc_143201 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.hackerrank.com/challenges/strange-code/problem",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n",
"output": "6\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/ARYS2020/problems/FREQARRY | Solve the following coding problem using the programming language python:
A beautiful sequence is defined as a sequence that do not have any repeating elements in it.
You will be given any random sequence of integers, and you have to tell whether it is a beautiful sequence or not.
-----Input:-----
- The first line o... | ```python
for _ in range(int(input())):
n = int(input())
arr = list(map(int, input().split()))
l = []
for i in range(0, len(arr)):
for j in range(i + 1, len(arr)):
if arr[i] == arr[j]:
l.append(arr[j])
if len(l) == 0:
print('prekrasnyy')
else:
print('ne krasivo')
``` | vfc_143205 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/ARYS2020/problems/FREQARRY",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n4\n1 2 3 4\n6\n1 2 3 5 1 4\n",
"output": "prekrasnyy\nne krasivo\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/MAXSPSUM | Solve the following coding problem using the programming language python:
Given an array of size N$N$ and two integers K$K$ and S$S$, the special sum of a subarray is defined as follows:
(Sum of all elements of the subarray) * (K$K$ - p$p$ * S$S$)
Where p$p$ = number of distinct prime factors of “product of all elem... | ```python
from math import floor, sqrt
try:
long
except NameError:
long = int
def fac(n):
(step, maxq, d) = (lambda x: 1 + (x << 2) - (x >> 1 << 1), long(floor(sqrt(n))), 1)
q = n % 2 == 0 and 2 or 3
while q <= maxq and n % q != 0:
q = step(d)
d += 1
return q <= maxq and [q] + fac(n // q) or [n]
(n, k, s) = ... | vfc_143210 | {
"difficulty": "very_hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/MAXSPSUM",
"time_limit": "3 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 10 2\n14 2 7 15\n",
"output": "138\nSample\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1476/D | Solve the following coding problem using the programming language python:
There are $n + 1$ cities, numbered from $0$ to $n$. $n$ roads connect these cities, the $i$-th road connects cities $i - 1$ and $i$ ($i \in [1, n]$).
Each road has a direction. The directions are given by a string of $n$ characters such that ea... | ```python
import os
import sys
from io import BytesIO, IOBase
import threading
from bisect import bisect_left
from math import gcd, log, ceil
from collections import Counter
from pprint import pprint
def main():
n = int(input())
s = input()
bl = [0] * (n + 1)
br = [0] * (n + 1)
if s[0] == 'L':
bl[1] = 1
for i ... | vfc_143214 | {
"difficulty": "medium_hard",
"memory_limit": "512 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1476/D",
"time_limit": "2 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n6\nLRRRLL\n3\nLRL\n",
"output": "1 3 2 3 1 3 2\n1 4 1 4\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/JULY16/problems/CHSGMNTS | Solve the following coding problem using the programming language python:
Chef has an array A consisting of N elements. He wants to find number of pairs of non-intersecting segments [a, b] and [c, d] (1 ≤ a ≤ b < c ≤ d ≤ N) such there is no number that occurs in the subarray {Aa, Aa+1, ... , Ab} and {Ac, Ac+1, ... ,... | ```python
t = int(input())
for q in range(t):
n = int(input())
x = list(map(int, input().split()))
dic = {}
dic2 = {}
for i in range(n):
dic2[x[i]] = 1
if len(dic2) == n:
n += 2
print(n * (n - 1) * (n - 2) * (n - 3) / 24)
continue
counter = 0
for i in range(n - 1):
if x[i] in dic:
dic[x[i]] += 1
... | vfc_143218 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/JULY16/problems/CHSGMNTS",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n3\n1 2 3\n4\n1 2 1 2\n",
"output": "5\n4\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1506/E | Solve the following coding problem using the programming language python:
A permutation is a sequence of $n$ integers from $1$ to $n$, in which all numbers occur exactly once. For example, $[1]$, $[3, 5, 2, 1, 4]$, $[1, 3, 2]$ are permutations, and $[2, 3, 2]$, $[4, 3, 1]$, $[0]$ are not.
Polycarp was presented with ... | ```python
from collections import deque
t = int(input())
for i in range(t):
och = deque()
n = int(input())
d = list(map(int, input().split()))
pos = 0
ans = []
for j in d:
if j > pos:
ans.append(j)
for k in range(pos + 1, j):
och.append(k)
else:
ans.append(och.popleft())
pos = j
print(*ans)
p... | vfc_143222 | {
"difficulty": "medium",
"memory_limit": "256 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1506/E",
"time_limit": "2 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n7\n3 3 4 4 7 7 7\n4\n1 2 3 4\n7\n3 4 5 5 5 7 7\n1\n1\n",
"output": "3 1 4 2 7 5 6 \n3 2 4 1 7 6 5 \n1 2 3 4 \n1 2 3 4 \n3 4 5 1 2 7 6 \n3 4 5 2 1 7 6 \n1 \n1 \n",
"type": "stdin_stdout"
},
{
"fn_name": ... |
taco | verifiable_code | https://www.codechef.com/problems/CONVSTR | Solve the following coding problem using the programming language python:
Vivek was quite bored with the lockdown, so he came up with an interesting task. He successfully completed this task and now, he would like you to solve it.
You are given two strings $A$ and $B$, each with length $N$. Let's index the characters ... | ```python
for _ in range(int(input())):
N = int(input())
c_str = str(input())
target_str = str(input())
no_match = False
for i in range(N):
if c_str[i] < target_str[i]:
no_match = True
break
if target_str[i] not in c_str:
no_match = True
break
if no_match:
print(-1)
else:
indices = {char: ind... | vfc_143227 | {
"difficulty": "medium_hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/CONVSTR",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n5\nabcab\naabab\n3\naaa\naab\n2\nde\ncd\n",
"output": "2\n3 1 2 4\n3 0 1 3\n-1\n-1\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
There are N people in a group. The personality of each person is denoted by A[i] from the set A, where A[i] denotes the personality of the ith person.
Your task is to find the total persons of different personalities.
INPUT:
First line conta... | ```python
t=int(input())
i=0
while i < t:
n=int(input())
array=list(map(int, input().split()))
array.sort()
j=0
count=n
while j < n-1:
if array[j+1]==array[j]:
count=count-1
j=j+1
print(count)
i=i+1
``` | vfc_143233 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n5\n1 2 3 4 5",
"output": "5",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8\n793\n2009 6911 389 7025 9959 8936 8403 8938 1880 9148 3371 4343 2392 8483 3887 7041 7635 4131 5576 322 7408 ... | |
taco | verifiable_code | https://codeforces.com/problemset/problem/173/B | Solve the following coding problem using the programming language python:
"The Chamber of Secrets has been opened again" — this news has spread all around Hogwarts and some of the students have been petrified due to seeing the basilisk. Dumbledore got fired and now Harry is trying to enter the Chamber of Secrets. Thes... | ```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_143241 | {
"difficulty": "medium_hard",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/173/B",
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 5\n.....\n.#...\n.....\n.....\n#.###\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 4\n..##\n....\n..#.\n",
"output": "2\n",
"type": "stdin_stdout"
}... |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Shil, Aditya and Utkarsh go to a candy shop. There are N candies present in the shop, which are indexed from 1 to N. All three of them select one candy to eat.
However, a candy tastes delicious if and only if, the index of candy chosen by Shil ... | ```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());
ans=n*(n-1)*(n-2)/3
print(ans)
``` | vfc_143245 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1000",
"output": "224073500",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "550",
"output": "55156200",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.