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://practice.geeksforgeeks.org/problems/find-k-th-missing-element2556/1 | Solve the following coding problem using the programming language python:
Given two sequences, one is increasing sequence a[] and another a normal sequence b[], find the K-th missing element in the increasing sequence which is not present in the given sequence. If no K-th missing element is there output -1
Example 1... | ```python
class Solution:
def MissingNumber(self, a, b, k, n1, n2):
d = {}
for i in b:
if i in d:
d[i] += 1
else:
d[i] = 1
f = {}
for i in a:
if i in f:
f[i] += 1
else:
f[i] = 1
b = set(b)
c = 0
for i in a:
if i not in b:
c += 1
if c == k:
return i
return -1
... | vfc_144216 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/find-k-th-missing-element2556/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "Arr[] = {0, 2, 4, 6, 8, 10, 12, 14, 15}\r\nBrr[] = {4, 10, 6, 8, 12} and K = 3",
"output": "14",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "Arr[] = {1, 2, 3, 4, 5}\r\nBrr[] = {5, 4, 3, 1,... |
taco | verifiable_code | Solve the following coding problem using the programming language python:
A prime number n (11, 19, 23, etc.) that divides by 4 and has 3 has an interesting property. The results of calculating the remainder of the square of a natural number (1, 2, ..., n -1) of 1 or more and less than n divided by n are the same, so ... | ```python
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
N = int(readline())
if N == 0:
return False
if N == 1:
return True
(*S,) = set((i ** 2 % N for i in range(1, N)))
S.sort()
L = len(S)
C = [0] * N
D = [0] * ((N - 1) // 2)
for i in range(L):
a = S[i]
for b in S[:i]... | vfc_144218 | {
"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": "11\n23\n0",
"output": "4\n4\n4\n4\n4\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "11\n45\n0",
"output": "4\n4\n4\n4\n4\n4\n2\n6\n4\n6\n... | |
taco | verifiable_code | https://www.codechef.com/problems/PTUPLES | Solve the following coding problem using the programming language python:
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well.
A tuple $(a, b, c)$ is considered good if it consists of three prime numbers $a$, $b$ and $c$ such that $a < b < c ≤ N$ and $a + b = c$.
T... | ```python
import bisect
primes = {2}
primes = [False, False] + [True] * 10 ** 6
p = 2
dp = []
while p * p <= 10 ** 6:
if primes[p] == True:
for i in range(2 * p, 10 ** 6, p):
primes[i] = False
p += 1
for i in range(2, i):
if primes[i] and primes[i - 2]:
dp.append(i)
for _ in range(int(input())):
print(bisect... | vfc_144222 | {
"difficulty": "medium_hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/PTUPLES",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n3\n6",
"output": "0\n1",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.hackerrank.com/challenges/abbr/problem | Solve the following coding problem using the programming language python:
You can perform the following operations on the string, $a$:
Capitalize zero or more of $a$'s lowercase letters.
Delete all of the remaining lowercase letters in $a$.
Given two strings, $a$ and $\boldsymbol{b}$, determine if it's possible to... | ```python
import sys
sys.setrecursionlimit(30000)
from collections import Counter, defaultdict, deque
from math import ceil, floor, factorial, fsum, isinf, exp, log, log10, log2, isfinite, sqrt
from math import pi as PI, e as E
from math import sin, cos, tan, sinh, cosh, tanh, asin, acos, atan
from fractions import Fra... | vfc_144226 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.hackerrank.com/challenges/abbr/problem",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\ndaBcd\nABC\n",
"output": "YES\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/18/A | Solve the following coding problem using the programming language python:
At a geometry lesson Bob learnt that a triangle is called right-angled if it is nondegenerate and one of its angles is right. Bob decided to draw such a triangle immediately: on a sheet of paper he drew three points with integer coordinates, and... | ```python
import math
def distancia_euclidiana(x, y):
lados = []
lados.append(math.pow(x[0] - x[1], 2) + math.pow(y[0] - y[1], 2))
lados.append(math.pow(x[0] - x[2], 2) + math.pow(y[0] - y[2], 2))
lados.append(math.pow(x[1] - x[2], 2) + math.pow(y[1] - y[2], 2))
return sorted(lados)
def is_right(pontos):
distan... | vfc_144230 | {
"difficulty": "medium",
"memory_limit": "64.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/18/A",
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "30 8 49 13 25 27\n",
"output": "RIGHT\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "-67 49 89 -76 -37 87\n",
"output": "NEITHER\n",
"type": "stdin_stdout"
},
{
... |
taco | verifiable_code | https://www.codechef.com/problems/BINARY | Solve the following coding problem using the programming language python:
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
"Out of 6 billion humans, the troublemakers are just a handful." - Dalai Lama
Nikitasha and Mansi are best friends. They have a binary sequ... | ```python
for _ in range(int(input())):
(n, z) = map(int, input().split())
a = list(map(int, input().split()))
dp = []
temp = []
record = []
total = 0
ones = 0
zeros = 0
for i in range(n):
if a[i] == 1:
if len(temp) >= z and temp[-z] == 1:
total -= 1
total += 1
temp.append(1)
record.append(le... | vfc_144234 | {
"difficulty": "very_hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/BINARY",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n6 2\n0 1 1 0 1 1\n4 4\n0 1 0 1",
"output": "1 1 0 1 1 0 \n\n1 1 0 0",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1546/A | Solve the following coding problem using the programming language python:
AquaMoon and Cirno are playing an interesting game with arrays. Cirno has prepared two arrays $a$ and $b$, both consist of $n$ non-negative integers. AquaMoon can perform the following operation an arbitrary number of times (possibly zero):
She... | ```python
import sys
input = sys.stdin.readline
def I():
return input().strip()
def II():
return int(input().strip())
def LI():
return [*map(int, input().strip().split())]
import copy
import re
import string, math, time, functools, random, fractions
from heapq import heappush, heappop, heapify
from bisect import ... | vfc_144239 | {
"difficulty": "easy",
"memory_limit": "256 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1546/A",
"time_limit": "1 second"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n4\n1 2 3 4\n3 1 2 4\n2\n1 3\n2 1\n1\n0\n0\n5\n4 3 2 1 0\n0 1 2 3 4\n",
"output": "2\n2 1\n3 1\n-1\n0\n6\n1 4\n1 4\n1 5\n1 5\n2 5\n2 5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n... |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/three-way-partitioning/1 | Solve the following coding problem using the programming language python:
Given an array of size n and a range [a, b]. The task is to partition the array around the range such that array is divided into three parts.
1) All elements smaller than a come first.
2) All elements in range a to b come next.
3) All elements g... | ```python
class Solution:
def threeWayPartition(self, array, a, b):
(st, end, i) = (0, len(array) - 1, 0)
while i <= end:
if array[i] < a:
(array[i], array[st]) = (array[st], array[i])
st += 1
elif array[i] > b:
(array[i], array[end]) = (array[end], array[i])
end -= 1
i -= 1
i += 1
`... | vfc_144243 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/three-way-partitioning/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "n = 5\r\nA[] = {1, 2, 3, 3, 4}\r\n[a, b] = [1, 2]",
"output": "1",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.hackerrank.com/challenges/happy-ladybugs/problem | Solve the following coding problem using the programming language python:
Happy Ladybugs is a board game having the following properties:
The board is represented by a string, $\boldsymbol{b}$, of length $n$. The $i^{\mbox{th}}$ character of the string, $b[i]$, denotes the $i^{\mbox{th}}$ cell of the board.
If $b[i]... | ```python
import sys
import collections
def all_happy(ladybugs):
for (i, bug) in enumerate(ladybugs):
try:
left = ladybugs[i - 1]
except IndexError:
left = None
try:
right = ladybugs[i + 1]
except IndexError:
right = None
if bug not in (left, right):
return False
return True
Q = int(input().... | vfc_144244 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.hackerrank.com/challenges/happy-ladybugs/problem",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n7\nRBY_YBR\n6\nX_Y__X\n2\n__\n6\nB_RRBR\n",
"output": "YES\nNO\nYES\nYES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n5\nAABBC\n7\nAABBC_C\n1\n_\n10\nDD__FQ_QQF\n6\nAABCBC\n",
... |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/missing-number-in-shuffled-array0938/1 | Solve the following coding problem using the programming language python:
Given an array A of size N. The contents of A are copied into another array B and numbers are shuffled. Also, one element is removed from B. The task is to find the missing element.
Example 1:
Input :
A[] = {4, 8, 1, 3, 7}
B[] = {7, 4, 3, 1}
... | ```python
class Solution:
def findMissing(self, a, b, n):
return sum(a) - sum(b)
``` | vfc_144256 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/missing-number-in-shuffled-array0938/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "A[] = {4, 8, 1, 3, 7}\nB[] = {7, 4, 3, 1}",
"output": "8",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "A[] = {12, 10, 15, 23, 11, 30}\nB[] = {15, 12, 23, 11, 30}",
"output": "10",
... |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Taru and Chandu both are getting bored. So Taru thinks to play a game and he gives a number to Chandu and asks him to find the number of combinations formed by divisors in form of prime.
For example:-
For N = 36 divisor in form of prime a... | ```python
import sys
T = int(sys.stdin.readline().strip('\n'))
while T:
T -= 1
N = int(sys.stdin.readline().strip('\n'))
n = int(N ** 0.5) + 1
fact1 = 0
fact2 = 0
for i in range(2, n):
if i*i == N:
fact1 += 1
continue
if N % i == 0:
fact2 += 1
print((fact1 + (fact2 << 1) + 1))
``` | vfc_144257 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1000\n10000\n100000\n1000000\n10000000",
"output": "120\n11\n47\n3\n15\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n1111\n11111\n111111\n11111111\n1111111",
"output": "15\n2... | |
taco | verifiable_code | https://www.codechef.com/problems/CHECKMATE | Solve the following coding problem using the programming language python:
You are given a standard 8 \times 8 chessboard which has exactly 3 pieces placed on it - 2 black rooks and 1 white king. The rows are numbered 1 to 8 from bottom to top, and the columns are numbered 1 to 8 from left to right. The cell at the int... | ```python
t = int(input())
for i in range(t):
(xk, yk) = map(int, input().split())
(x1, y1) = map(int, input().split())
(x2, y2) = map(int, input().split())
ans = 'NO'
if not (xk == 1 or yk == 8 or xk == 8 or (yk == 1)):
ans = 'NO'
else:
if xk == 1:
if (x1 == 2 or x2 == 2) and y1 != y2:
if abs(y2 - yk)... | vfc_144261 | {
"difficulty": "medium_hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/CHECKMATE",
"time_limit": "0.5 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1 1\n8 2\n7 3\n1 8\n8 2\n8 3\n1 1\n8 2\n2 3\n1 1\n8 8\n8 2\n",
"output": "YES\nNO\nNO\nNO",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1119/A | Solve the following coding problem using the programming language python:
Ilya lives in a beautiful city of Chordalsk.
There are $n$ houses on the street Ilya lives, they are numerated from $1$ to $n$ from left to right; the distance between every two neighboring houses is equal to $1$ unit. The neighboring houses ar... | ```python
n = int(input())
a = list(map(int, input().split()))
l1 = a[0]
l2 = None
l2p = 0
for i in range(n):
if a[i] != l1:
l2 = a[i]
l2p = i
break
r1 = a[-1]
r2 = None
r2p = 0
for i in range(n - 1, -1, -1):
if a[i] != l1:
r2 = a[i]
r2p = i
break
if l1 != r1:
print(n - 1)
else:
print(max(r2p, n - 1 - l... | vfc_144266 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1119/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1 2 3 2 3\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 2 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"in... |
taco | verifiable_code | https://www.codechef.com/APRIL14/problems/SEAPERM | Solve the following coding problem using the programming language python:
Sereja have array A' that contain N integers. Now Sereja want to permute elements of the array, he want to use some permutation p, such that A[i] = A'[p[i]], where A - new array.
Lets function f(A,i) = S - A[i] - A[i +1] - ... - A[j], where j ... | ```python
test = int(input())
for i in range(test):
(N, S, K) = list(map(int, input().split()))
lis = list(map(int, input().split()))
ans = [i + 1 for i in range(N)]
ans.sort(reverse=True)
for j in range(N):
print(ans[j], end=' ')
print('')
``` | vfc_144270 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/APRIL14/problems/SEAPERM",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n3 2 4\n3 4 1\n4 4 1\n1 1 1 1\n\n\n",
"output": "2 1 3\n4 3 2 1\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Roy has N coin boxes numbered from 1 to N.
Every day he selects two indices [L,R] and adds 1 coin to each coin box starting from L to R (both inclusive).
He does this for M number of days.
After M days, Roy has a query: How many coin boxes ha... | ```python
def bs(i,j,key):
global final
if key>final[j]:
return j
if key<final[i]:
return -1
while j-i>1:
mid=(i+j)/2
if final[mid]<key:
i=mid
elif final[mid]>=key:
j=mid-1
if final[j]<key:
return j
elif final[i]<key:
return i
n=eval(input())
m=eval(input())
dp=[0]*(n+2)
for i in range(0,m):
... | vfc_144274 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1000\n1000\n282 706\n388 521\n574 934\n410 922\n396 525\n4 550\n48 698\n595 953\n852 861\n3 677\n534 674\n408 417\n615 899\n830 873\n362 393\n989 991\n318 820\n316 708\n712 919\n181 745\n197 728\n765 782\n735 999\n444 697\n452 712\... | |
taco | verifiable_code | Solve the following coding problem using the programming language python:
An bydrocarbon is an organic compound which contains only carbons and hydrogens. An isomer is a compound that has the same number of carbons but different structures. Heptane, for example, is a hydrocarbon with 7 carbons. It has nine isomers. Th... | ```python
a = [0] * 32
(a[1], a[2]) = (1, 2)
for i in range(3, 31):
a[i] = 3 * a[i - 2] + 2
while True:
try:
i = int(input())
except:
break
print(a[i])
``` | vfc_144278 | {
"difficulty": "unknown_difficulty",
"memory_limit": "134.217728 megabytes",
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "1.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n6",
"output": "1\n26\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n8",
"output": "1\n80\n",
"type": "stdin_stdout"
}
]
} | |
taco | verifiable_code | https://www.codechef.com/TCFL2020/problems/TCFL20C | Solve the following coding problem using the programming language python:
On Miu's smart phone, there is a search feature which lets her search for a contact name by typing digits on the keypad where each digit may correspond to any of the characters given below it. For example, to search for TOM, she can type 866 and... | ```python
for _ in range(int(input())):
n = int(input())
n1 = 0
ans = 1
while n > 0:
d = int(n % 10)
if d != 0:
if d != 9 and d != 7 and (d != 1):
n1 = 3
elif d == 1:
n1 = 1
else:
n1 = 4
ans = int(ans) * int(n1) % 1000000007
n /= 10
else:
n /= 10
if ans == 1:
print('0')
else:... | vfc_144283 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/TCFL2020/problems/TCFL20C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n5\n72\n",
"output": "3\n12\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Alice is climbing stairs. There are total N stairs. She climbs A stairs upwards in day and she comes downstairs in night by B stairs. Find number of days she will take to reach the top of staircase.
Input:
First and only line contains three... | ```python
A, B, N = list(map(int, input().split(' ')))
X = (N - A) / (A - B) + 1
if (N - A) % (A - B) > 0:
X = X + 1
print(X)
``` | vfc_144291 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 2 1000000000\n",
"output": "499999999\n",
"type": "stdin_stdout"
}
]
} | |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Consider the following game. There are k pairs of n cards with numbers from 1 to n written one by one. Shuffle these kn cards well to make piles of k cards and arrange them in a horizontal row. The i-th (k-card) pile from the left of the n piles... | ```python
from decimal import *
while True:
(n, k, m, r) = map(int, input().split())
if n == 0:
break
setcontext(Context(prec=r, rounding=ROUND_HALF_UP))
one = Decimal(1)
ans = one / Decimal(n)
if m == 1:
s = 0
for i in range(1, n):
s += one / Decimal(i)
ans *= 1 + s
ans = str(ans)[:r + 2]
if len(ans... | vfc_144296 | {
"difficulty": "unknown_difficulty",
"memory_limit": "134.217728 megabytes",
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "5.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 1 0 5\n3 1 2 3\n2 2 1 3\n0 0 0 0",
"output": "0.50000\n0.833\n1.000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 1 0 5\n3 1 2 0\n2 2 1 3\n0 0 0 0",
"output": "0.50000\n0.\n1.0... | |
taco | verifiable_code | https://codeforces.com/problemset/problem/1272/D | Solve the following coding problem using the programming language python:
You are given an array $a$ consisting of $n$ integers.
You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$.
Your task is to calculate the maximum possible length of the strictly increasing co... | ```python
import sys
from itertools import chain, permutations
def res(x):
result = 1
current = 1
for i in range(1, len(x)):
if x[i] > x[i - 1]:
current = current + 1
result = max(result, current)
else:
result = max(result, current)
current = 1
if result < current:
current = result
return resu... | vfc_144304 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1272/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1 2 5 3 4\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n1 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"inpu... |
taco | verifiable_code | Solve the following coding problem using the programming language python:
At Akabe High School, a programmer training school, there is a unique study session run by the students themselves. It is important for programmers to constantly adopt new technologies, so the aim of this activity is to develop the habit of self... | ```python
from bisect import bisect
import operator
import sys
from collections import defaultdict
readline = sys.stdin.readline
write = sys.stdout.write
(N, Q) = map(int, readline().split())
R = [int(readline()) for i in range(N)]
S = list(set(R))
S.sort()
mp = {e: i for (i, e) in enumerate(S)}
D = defaultdict(int)
T ... | vfc_144316 | {
"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 8\n5\n10\n8\n7\n3\nADD 1\nADD 3\nCHECK 0\nCHECK 1\nCHECK 2\nCHFCK 3\nCHECK 4\nCHECK 5",
"output": "NA\n2\n1\n0\n0\n0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 8\n5\n10\n8\n3\n3\n... | |
taco | verifiable_code | https://codeforces.com/problemset/problem/852/C | Solve the following coding problem using the programming language python:
Bill is a famous mathematician in BubbleLand. Thanks to his revolutionary math discoveries he was able to make enough money to build a beautiful house. Unfortunately, for not paying property tax on time, court decided to punish Bill by making hi... | ```python
n = int(input())
a = input().split()
for i in range(n):
a[i] = int(a[i])
b = []
for i in range(0, n - 1):
b.append((a[i] - (n - a[i + 1]), i))
b.append((a[n - 1] - (n - a[0]), n - 1))
b = sorted(b)
ans = n * [0]
for i in range(n):
ans[b[i][1]] = i
for i in range(n):
print(ans[i], end=' ')
``` | vfc_144320 | {
"difficulty": "hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/852/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n0 1 2\n",
"output": "0 2 1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n0 1 2 3 4 5 6 7 8 9\n",
"output": "0 1 2 3 5 6 7 8 9 4\n",
"type": "stdin_stdout"
},
{... |
taco | verifiable_code | https://www.codechef.com/problems/MINCOINS | Solve the following coding problem using the programming language python:
Chef has infinite coins in denominations of rupees 5 and rupees 10.
Find the minimum number of coins Chef needs, to pay exactly X rupees. If it is impossible to pay X rupees in denominations of rupees 5 and 10 only, print -1.
------ Input Form... | ```python
for i in range(int(input())):
x = int(input())
if x % 5 == 0:
if x % 10 == 0:
print(x // 10)
else:
print(int(x / 10) + 1)
else:
print(-1)
``` | vfc_144324 | {
"difficulty": "easy",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/MINCOINS",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n50\n15\n8\n",
"output": "5\n2\n-1\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.hackerrank.com/challenges/eulers-criterion/problem | Solve the following coding problem using the programming language python:
Your friend gives you an equation $A\equiv X^2\pmod{M}$ and asks you to find an integer solution for ${X}$.
However, you know your friend's mischievous nature and suspect that there is no solution to such an equation. Thus, you first want to ... | ```python
t = int(input())
for _ in range(t):
(a, p) = map(int, input().split())
print('YES' if a == 0 or pow(a, (p - 1) // 2, p) == 1 else 'NO')
``` | vfc_144328 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.hackerrank.com/challenges/eulers-criterion/problem",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 \n5 7 \n4 7\n",
"output": "NO \nYES\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/MODULO3 | Solve the following coding problem using the programming language python:
Stack likes the number 3 a lot.
He has two non-negative integers A and B.
In one operation, Stack can do either of the following:
A:=|A-B| (change A to |A-B|)
B:=|A-B| (change B to |A-B|)
Note that |X| denotes absolute value of X. For exam... | ```python
for i in range(int(input())):
(a, b) = map(int, input().split())
count = 0
if a % 3 == 0 or b % 3 == 0:
print('0')
else:
while a % 3 != 0 or b % 3 != 0:
a1 = abs(a - b)
a2 = abs(a - b)
a = a1
b = a2
count += 1
print(count)
``` | vfc_144332 | {
"difficulty": "easy",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/MODULO3",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n0 343\n1 1\n",
"output": "0\n1\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/4/B | Solve the following coding problem using the programming language python:
Tomorrow Peter has a Biology exam. He does not like this subject much, but d days ago he learnt that he would have to take this exam. Peter's strict parents made him prepare for the exam immediately, for this purpose he has to study not less tha... | ```python
def print_arr(arr):
for a in arr:
print(a, end=' ')
def solution():
(d, hr) = input().split()
(d, hr) = (int(d), int(hr))
intervals = []
first = []
for _ in range(d):
(vmin, vmax) = input().split()
(vmin, vmax) = (int(vmin), int(vmax))
intervals.append((vmin, vmax))
first.append(vmin)
vmin =... | vfc_144336 | {
"difficulty": "easy",
"memory_limit": "64.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/4/B",
"time_limit": "0.5 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "30 189\n0 8\n3 8\n5 8\n2 2\n7 7\n2 8\n7 8\n2 5\n1 7\n0 1\n3 4\n1 7\n1 6\n5 6\n3 7\n4 7\n4 7\n4 7\n5 5\n0 5\n4 7\n3 5\n0 6\n4 8\n2 5\n5 6\n5 6\n2 8\n0 7\n7 8\n",
"output": "YES\n8\n8\n8\n2\n7\n8\n8\n5\n7\n1\n4\n7\n6\n6\n7\n7\n... |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/while-loop-printtable/1 | Solve the following coding problem using the programming language python:
While loop is another loop like for loop but unlike for loop it only checks for one condition.
Here, we will use while loop and print a number n's table in reverse order.
Example 1:
Input: n = 1
Output: 10 9 8 7 6 5 4 3 2 1
Example 2:
Input: n =... | ```python
class Solution:
def printTable(self, n):
multiplier = 10
while multiplier:
print(multiplier * n, end=' ')
multiplier = multiplier - 1
print()
``` | vfc_144340 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/while-loop-printtable/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "n = 1",
"output": "10 9 8 7 6 5 4 3 2 1",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/952/B | Solve the following coding problem using the programming language python:
If you have ever interacted with a cat, you have probably noticed that they are quite particular about how to pet them. Here is an approximate map of a normal cat.
<image>
However, some cats won't tolerate this nonsense from the humans. Here i... | ```python
print('grumpy' if input('9\n')[-2:] in ['s?', 'le', 'se', 'ay', 'en'] else 'normal')
``` | vfc_144341 | {
"difficulty": "hard",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/952/B",
"time_limit": "1.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 0 1 2 5 3 5 4 5 5\n",
"output": "0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 5 1 2 5 5 4 3 0 5\n",
"output": "0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n",
... |
taco | verifiable_code | Solve the following coding problem using the programming language python:
The Manager Manoj has thought of another way to generate revenue for his restaurant. He has a large oven to bake his goods, but he has noticed that not all of the racks are used all of the time. If a rack is not used, then the Manoj has decided ... | ```python
'''
# Read input from stdin and provide input before running code
name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
print('7')
``` | vfc_144345 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n\n4 4\n0 1 2\n1 2 2\n2 4 2\n0 3 5\n2 1 1 1",
"output": "7",
"type": "stdin_stdout"
}
]
} | |
taco | verifiable_code | https://codeforces.com/problemset/problem/474/D | Solve the following coding problem using the programming language python:
We saw the little game Marmot made for Mole's lunch. Now it's Marmot's dinner time and, as we all know, Marmot eats flowers. At every dinner he eats some red and white flowers. Therefore a dinner can be represented as a sequence of several flowe... | ```python
(t, k) = map(int, input().split())
mod = 10 ** 9 + 7
arr = [0 for i in range(100001)]
arr[0] = 1
arr[1] = 1
if k == 1:
arr[1] += 1
for i in range(2, len(arr)):
if i >= k:
arr[i] = (arr[i - 1] + arr[i - k]) % mod
else:
arr[i] = arr[i - 1] % mod
ans = [0 for i in range(100001)]
ans[1] = arr[1]
for i in r... | vfc_144349 | {
"difficulty": "medium_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/474/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 2\n1 3\n2 3\n4 4\n",
"output": "6\n5\n5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1\n1 3\n",
"output": "14\n",
"type": "stdin_stdout"
},
{
"fn_name": nu... |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Micro just learned about prime numbers. But he quickly got bored of them, so he defined a new kind of numbers and called them Prime Prime Numbers. A number X is Prime Prime if number of prime numbers from 1 to X (inclusive) are prime. Now he wan... | ```python
'''
# Read input from stdin and provide input before running code
name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
li=[]
N=1000000
def sieve():
dic={}
dic[2]='1'
nop=1
global li
li=[0 for i in range(N+1)]
vis=[0 for i in range(N)]
for i in range(3,N,2):
if vis[i]==0:
dic[i]='1... | vfc_144353 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1000\n75 824\n296 306\n305 368\n306 774\n466 695\n425 782\n34 174\n846 852\n424 596\n380 712\n156 578\n884 999\n593 984\n898 984\n16 636\n90 800\n105 811\n467 737\n510 824\n289 772\n557 906\n590 714\n79 917\n435 502\n166 512\n442 5... | |
taco | verifiable_code | https://codeforces.com/problemset/problem/317/D | Solve the following coding problem using the programming language python:
Vasya and Petya wrote down all integers from 1 to n to play the "powers" game (n can be quite large; however, Vasya and Petya are not confused by this fact).
Players choose numbers in turn (Vasya chooses first). If some number x is chosen at th... | ```python
from sys import stdin, stdout
import math, collections
mod = 10 ** 9 + 7
def isPower(n):
if n <= 1:
return True
for x in range(2, int(math.sqrt(n)) + 1):
p = x
while p <= n:
p = p * x
if p == n:
return True
return False
n = int(input())
arr = [0, 1, 2, 1, 4, 3, 2, 1, 5, 6, 2, 1, 8, 7, 5, 9... | vfc_144357 | {
"difficulty": "hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/317/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n",
"output": "Vasya\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n",
"output": "Petya\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8\n... |
taco | verifiable_code | https://codeforces.com/problemset/problem/897/C | Solve the following coding problem using the programming language python:
What are you doing at the end of the world? Are you busy? Will you save us?
<image>
Nephren is playing a game with little leprechauns.
She gives them an infinite array of strings, f0... ∞.
f0 is "What are you doing at the end of the world? A... | ```python
import sys
sys.setrecursionlimit(1500)
s1 = 'What are you doing at the end of the world? Are you busy? Will you save us?'
a = 'What are you doing while sending "'
b = '"? Are you busy? Will you send "'
c = '"?'
ans = ''
def solve(n, k):
if n == 0:
if k >= len(s1):
return '.'
else:
return s1[k]
if... | vfc_144362 | {
"difficulty": "medium_hard",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/897/C",
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10\n96759 970434747560290241\n95684 985325796232084031\n99418 855577012478917561\n98767 992053283401739711\n99232 381986776210191990\n97804 22743067342252513\n95150 523980900658652001\n98478 290982116558877566\n98012 64238293152691... |
taco | verifiable_code | https://codeforces.com/problemset/problem/1081/B | Solve the following coding problem using the programming language python:
Chouti and his classmates are going to the university soon. To say goodbye to each other, the class has planned a big farewell party in which classmates, teachers and parents sang and danced.
Chouti remembered that $n$ persons took part in that... | ```python
n = int(input())
a = list(map(int, input().split()))
d = dict()
poses = dict()
ans = [0 for i in range(n)]
for i in range(n):
if a[i] not in d:
d[a[i]] = 1
poses[a[i]] = [i]
else:
d[a[i]] += 1
poses[a[i]].append(i)
color = 1
for i in d.keys():
while d[i]:
if len(poses[i]) < n - i:
print('Impos... | vfc_144366 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1081/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n0 0 0\n",
"output": "Possible\n1 1 1 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n3 3 2 2 2\n",
"output": "Possible\n1 1 2 2 2 ",
"type": "stdin_stdout"
},
{
... |
taco | verifiable_code | https://www.codechef.com/problems/FIXSUM | Solve the following coding problem using the programming language python:
You are given two integers N \ ( N ≥ 2) and S. You have to construct an array A containing N integers such that:
0 ≤ A_{i} ≤ S for each 1 ≤ i ≤ N
A_{1} + A_{2} + \ldots + A_{N} = S
A_{1} \mathbin{\&} A_{2} \mathbin{\&} \ldots \mathbin{\&} A_{N} ... | ```python
T = int(input())
for i in range(T):
(N, S) = map(int, input().split())
(X, Y) = (0, S + 1)
while X + 1 < Y:
Mid = X + Y >> 1
sum = 0
count = 0
for j in range(30, -1, -1):
if Mid >> j & 1:
sum += (N - 1) * (1 << j)
count = min(count + 1, N - 1)
else:
sum += (1 << j) * count
if su... | vfc_144370 | {
"difficulty": "very_hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/FIXSUM",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n2 7\n3 6\n5 21\n100 256455\n",
"output": "4\n3\n5\n2570\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/a7a4da81b20f4a05bbd93f5786fcf7478298f4f5/1 | Solve the following coding problem using the programming language python:
Given a rectangle of dimensions L x B find the minimum number (N) of identical squares of maximum side that can be cut out from that rectangle so that no residue remains in the rectangle. Also find the dimension K of that square.
Example 1:
Inpu... | ```python
class Solution:
def minimumSquares(self, L, B):
x = L
y = B
if x > y:
(x, y) = (y, x)
while True:
if y == 0:
k = x
break
else:
(x, y) = (y, x % y)
return [L * B // (k * k), k]
``` | vfc_144374 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/a7a4da81b20f4a05bbd93f5786fcf7478298f4f5/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "L = 2, B = 4",
"output": "N = 2, K = 2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "L = 6, B = 3",
"output": "N = 2, K = 3",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/shuffle-integers2401/1 | Solve the following coding problem using the programming language python:
Given an array arr[] of n elements in the following format {a1, a2, a3, a4, .., an/2, b1, b2, b3, b4, ., bn/2}, the task is shuffle the array to {a1, b1, a2, b2, a3, b3, , an/2, bn/2} without using extra space.
Example 1:
Input: n = 4, arr[] = {... | ```python
class Solution:
def shuffleArray(self, arr, n):
l = []
k = arr[:n // 2]
j = arr[n // 2:]
for i in range(len(k)):
l.append(k[i])
l.append(j[i])
for i in range(n):
arr[i] = l[i]
``` | vfc_144376 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/shuffle-integers2401/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "n = 4, arr[] = {1, 2, 9, 15}",
"output": "1 9 2 15",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "n = 6\r\narr[] = {1, 2, 3, 4, 5, 6}",
"output": "1 4 2 5 3 6",
"type": "stdin_s... |
taco | verifiable_code | https://www.hackerrank.com/challenges/re-start-re-end/problem | Solve the following coding problem using the programming language python:
start() & end()
These expressions return the indices of the start and end of the substring matched by the group.
Code
>>> import re
>>> m = re.search(r'\d+','1234')
>>> m.end()
4
>>> m.start()
0
Task
You are given a string $\mbox{S}$.
... | ```python
import re
s = input()
k = input()
m = re.search(k, s)
ind = 0
if not m:
a = (-1, -1)
print(a)
while m:
a = (ind + m.start(), ind + m.start() + len(k) - 1)
print(a)
ind += m.start() + 1
m = re.search(k, s[ind:])
``` | vfc_144377 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.hackerrank.com/challenges/re-start-re-end/problem",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "aaadaa\naa\n",
"output": "(0, 1) \n(1, 2)\n(4, 5)\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/284/A | Solve the following coding problem using the programming language python:
The cows have just learned what a primitive root is! Given a prime p, a primitive root $\operatorname{mod} p$ is an integer x (1 ≤ x < p) such that none of integers x - 1, x^2 - 1, ..., x^{p} - 2 - 1 are divisible by p, but x^{p} - 1 - 1 is.
U... | ```python
from math import gcd
a = int(input()) - 1
aux = 1
for i in range(2, a):
if gcd(i, a) == 1:
aux = aux + 1
print(aux)
``` | vfc_144382 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/284/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Problem Statement
In the headquarter building of ICPC (International Company of Plugs & Connectors), there are $M$ light bulbs and they are controlled by $N$ switches. Each light bulb can be turned on or off by exactly one switch. Each switch m... | ```python
while 1:
(n, m, q) = map(int, input().split())
if n | m | q == 0:
break
p = []
res = [{_ for _ in range(n)} for _ in range(m)]
for i in range(q):
(s, b) = [[int(c) for c in s] for s in input().split()]
if i > 0:
for j in range(n):
s[j] ^= p[j]
zero = {i for i in range(n) if s[i] == 0}
on... | vfc_144386 | {
"difficulty": "unknown_difficulty",
"memory_limit": "536.870912 megabytes",
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "8.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 10 3\n000 0000000000\n110 0000101111\n101 1111111100\n2 2 0\n1 1 0\n2 1 1\n01 1\n11 11 10\n10000000000 10000000000\n11000000000 01000000000\n01100000000 00100000000\n00110000000 00010000000\n00011000000 00001000000\n00001100000 0... | |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/gray-to-binary-and-binary-to-gray5518/1 | Solve the following coding problem using the programming language python:
Given to strings B and G. String B represents a binary code and string G represents a Gray Code. You need to write a program which converts binary code to gray code and vice versa.
Example 1:
Input:
B = "0011"
G = "01101"
Output:
0010
01001
Ex... | ```python
class Solution:
def binToGrey(self, B):
G = ''
G = G + B[0]
for i in range(1, len(B)):
G = G + str((int(B[i - 1]) + int(B[i])) % 2)
return G
def greyToBin(self, G):
B = ''
B = B + G[0]
for i in range(1, len(G)):
B = B + str((int(B[-1]) + int(G[i])) % 2)
return B
``` | vfc_144394 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/gray-to-binary-and-binary-to-gray5518/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "B = \"0011\"\r\nG = \"01101\"",
"output": "0010\r\n01001",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/sum-of-bit-differences2937/1 | Solve the following coding problem using the programming language python:
Given an integer array of N integers, find sum of bit differences in all pairs that can be formed from array elements. Bit difference of a pair (x, y) is count of different bits at same positions in binary representations of x and y.
For example... | ```python
class Solution:
def sumBitDifferences(self, arr, n):
n = len(arr)
sum_bit_diff = 0
for i in range(32):
count_set_bits = 0
count_clear_bits = 0
for j in range(n):
if arr[j] & 1 << i:
count_set_bits += 1
else:
count_clear_bits += 1
sum_bit_diff += count_set_bits * count_cle... | vfc_144395 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/sum-of-bit-differences2937/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N = 2\narr[] = {1, 2}",
"output": "4",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "N = 3 \narr[] = {1, 3, 5}",
"output": "8",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/737/C | Solve the following coding problem using the programming language python:
There are n workers in a company, each of them has a unique id from 1 to n. Exaclty one of them is a chief, his id is s. Each worker except the chief has exactly one immediate superior.
There was a request to each of the workers to tell how how... | ```python
f = lambda : map(int, input().split())
(n, s) = f()
c = [0] * n
t = list(f())
for i in t:
c[i] += 1
k = t[s - 1]
c[k] -= 1
d = c[0]
c += [d]
d += k > 0
(i, j) = (1, n)
while i < j:
if c[i]:
i += 1
elif c[j]:
c[j] -= 1
i += 1
d += j < n
else:
j -= 1
print(d)
``` | vfc_144396 | {
"difficulty": "hard",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/737/C",
"time_limit": "1.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 2\n2 1 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 3\n2 1 2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"in... |
taco | verifiable_code | Solve the following coding problem using the programming language python:
You will be provided with a passage (no special characters, no punctuations). Your task is to find the frequency of the words occurring in the text, in other words find the number of times a word occurs in the given passage.
Input
A string with ... | ```python
x = input(); a = x.split(); b = [];
for k in range(len(a)): a[k] = a[k].upper();
for k in a:
if k.upper() not in b: b.append(k.upper());
for k in b: print(k.upper(), a.count(k.upper()));
``` | vfc_144400 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "This citadel of learning stands as a guiding spirit leading to illumination of technical and intellectual acumen among the vibrant youth Within a very short span of time since its inception the missionary zeal of the institute coup... | |
taco | verifiable_code | https://www.codechef.com/problems/CIELDIST | Solve the following coding problem using the programming language python:
In Wolf town there are 2 big markets S and T. The distance between these markets is D. Chef Ciel would like to run 2 restaurants in Wolf town, where the first restaurant will be supplied by the market S and the second one will be supplied by the... | ```python
for i in range(int(input())):
(a, b, c) = map(int, input().split())
if c > max(a, b):
print(max(0, c - (a + b)))
else:
print(max(0, max(a, b) - c - min(a, b)))
``` | vfc_144409 | {
"difficulty": "medium_hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/CIELDIST",
"time_limit": "2.013 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n15 15 50\n15 15 18\n43 88 200\n2013 2013 2013",
"output": "20.000\n0.0\n69.00000\n0",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n15 15 50\n15 15 18\n43 88 200\n2013 1560 2013",
... |
taco | verifiable_code | https://www.hackerrank.com/challenges/simplified-chess-engine/problem | Solve the following coding problem using the programming language python:
Chess is a very popular game played by hundreds of millions of people. Nowadays, we have chess engines such as Stockfish and Komodo to help us analyze games. These engines are very powerful pieces of well-developed software that use intelligent ... | ```python
N = 4
D = ((1, 0), (0, 1), (-1, 0), (0, -1), (1, 1), (-1, 1), (-1, -1), (1, -1), (2, 1), (1, 2), (-1, 2), (-2, 1), (-2, -1), (-1, -2), (1, -2), (2, -1))
FIGURES = 'QNBR'
RANGE = ((0, 8), (8, 16), (4, 8), (0, 4))
def solve():
(w, b, m) = map(int, input().split())
m -= (m + 1) % 2
field = [[0] * N for _ in ... | vfc_144413 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.hackerrank.com/challenges/simplified-chess-engine/problem",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n2 1 1\nN B 2\nQ B 1\nQ A 4\n",
"output": "YES\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.hackerrank.com/challenges/count-triangles/problem | Solve the following coding problem using the programming language python:
You are given a regular N-gon with vertices at (cos(2πi / N), sin(2πi / N)), ∀ i ∈ [0,N-1]. Some of these vertices are blocked and all others are unblocked. We consider triangles with vertices at the vertices of N-gon and with at least one verte... | ```python
import math
from collections import defaultdict
err = pow(10, -12)
t = int(input())
for _ in range(t):
n = int(input())
minang = math.pi / n
s = input()
blocked = []
for i in range(n):
if s[i] == '0':
blocked.append(i)
global numdiff
numdiff = 0
numars = 0
for a in range(1, n // 3 + 1):
numars... | vfc_144417 | {
"difficulty": "hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.hackerrank.com/challenges/count-triangles/problem",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n4\n1111\n",
"output": "6\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/844/D | Solve the following coding problem using the programming language python:
This is an interactive problem.
You are given a sorted in increasing order singly linked list. You should find the minimum integer in the list which is greater than or equal to x.
More formally, there is a singly liked list built on an array o... | ```python
from random import sample
def R():
return map(int, input().split())
def ask(i):
print('?', i, flush=True)
(v, nxt) = R()
if v < 0:
exit()
return (v, nxt)
def ans(v):
print('!', v)
exit()
(n, s, x) = R()
mv = -1
i = s
S = 800
q = range(1, n + 1)
if n > S:
q = sample(q, S)
if s not in q:
q[0] = ... | vfc_144421 | {
"difficulty": "hard",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/844/D",
"time_limit": "1.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10 3 2\n3 9\n9 -1\n0 7\n6 8\n5 4\n8 2\n1 10\n7 6\n4 5\n2 1\n",
"output": "? 3\n! 3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1 0\n0 -1\n",
"output": "? 1\n! 0\n",
"type... |
taco | verifiable_code | https://codeforces.com/problemset/problem/699/B | Solve the following coding problem using the programming language python:
You are given a description of a depot. It is a rectangular checkered field of n × m size. Each cell in a field can be empty (".") or it can be occupied by a wall ("*").
You have one bomb. If you lay the bomb at the cell (x, y), then after tri... | ```python
def main():
(n, m) = list(map(int, input().split()))
(xx, yy, walls, t) = ([0] * n, [0] * m, set(), 0)
for x in range(n):
for (y, c) in enumerate(input()):
if c == '*':
t += 1
if t == n + m:
print('NO')
return
walls.add((x, y))
xx[x] += 1
yy[y] += 1
for (x, a) in enumera... | vfc_144426 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/699/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 4\n.*..\n....\n.*..\n",
"output": "YES\n1 2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 3\n..*\n.*.\n*..\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
... |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/deletion-and-reverse-in-linked-list/1 | Solve the following coding problem using the programming language python:
Given a Circular Linked List of size N. The task is to delete the given node (excluding the first and last node) in the circular linked list and then print the reverse of the circular linked list.
Example 1:
Input:
5
2 5 7 8 10
8
Output:
10 7 ... | ```python
def deleteNode(head, key):
temp = head
while True:
if temp.next.data == key:
temp.next = temp.next.next
break
else:
temp = temp.next
def reverse(head):
last = head
curr = head
while last.next != head:
last = last.next
prev = last
while curr != last:
tmp = curr.next
curr.next = prev
... | vfc_144435 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/deletion-and-reverse-in-linked-list/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n2 5 7 8 10\n8",
"output": "10 7 5 2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n1 7 8 10\n8",
"output": "10 7 1",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1165/B | Solve the following coding problem using the programming language python:
Polycarp wants to train before another programming competition. During the first day of his training he should solve exactly $1$ problem, during the second day — exactly $2$ problems, during the third day — exactly $3$ problems, and so on. Durin... | ```python
def get_num():
return int(input())
def print_arr(arr: list):
for val in arr:
print(val)
def read_num_list(k):
num_str = input()
return [int(v) for v in num_str.split(' ')]
n = get_num()
problems = read_num_list(n)
problems = sorted(problems)
i = 1
j = 0
while True:
if j >= len(problems):
break
if ... | vfc_144436 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1165/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n3 1 4 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 1 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"inpu... |
taco | verifiable_code | https://codeforces.com/problemset/problem/1469/C | Solve the following coding problem using the programming language python:
You want to build a fence that will consist of $n$ equal sections. All sections have a width equal to $1$ and height equal to $k$. You will place all sections in one line side by side.
Unfortunately, the ground beneath the fence is not flat. Fo... | ```python
for _ in range(int(input())):
(n, h) = map(int, input().split())
a = list(map(int, input().split()))
mi = a[0]
ma = a[0]
a = a[1:]
s = 1
for x in a:
mi = max(x, mi - h + 1)
ma = min(x + h - 1, ma + h - 1)
if ma < mi:
s = 0
if mi != a[-1]:
s = 0
print('YES') if s == 1 else print('NO')
``` | vfc_144449 | {
"difficulty": "medium_hard",
"memory_limit": "256 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1469/C",
"time_limit": "2 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n6 3\n0 0 2 5 1 1\n2 3\n0 2\n3 2\n3 0 2\n",
"output": "YES\nYES\nNO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n2 2\n2 8\n",
"output": "NO\n",
"type": "stdin_stdout"
... |
taco | verifiable_code | https://www.codechef.com/PBK12020/problems/ITGUY20 | Solve the following coding problem using the programming language python:
Finally, the pandemic is over in ChefLand, and the chef is visiting the school again. Chef likes to climb the stairs of his school's floor by skipping one step, sometimes chef climbs the stairs one by one. Simply, the chef can take one or 2 step... | ```python
for _ in range(int(input())):
N = int(input())
if N % 2 == 0:
print(N // 2 + 1)
else:
print((N - 1) // 2 + 1)
``` | vfc_144453 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/PBK12020/problems/ITGUY20",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n3\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/PRFYIT | Solve the following coding problem using the programming language python:
We say that a binary string (a string containing only characters '0' and '1') is pure if it does not contain either of the strings "0101" or "1010" as a subsequence.
Recall that string T is a subsequence of string S if we can delete some of the ... | ```python
for _ in range(int(input())):
bi = input().strip()
dp = [0 if i < 2 else len(bi) for i in range(6)]
for c in bi:
if c == '1':
dp[3] = min(dp[3], dp[0])
dp[0] += 1
dp[5] = min(dp[5], dp[2])
dp[2] += 1
dp[4] += 1
else:
dp[2] = min(dp[2], dp[1])
dp[1] += 1
dp[4] = min(dp[4], dp[3])... | vfc_144462 | {
"difficulty": "very_hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/PRFYIT",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n010111101\n1011100001011101\n0110\n111111\n",
"output": "2\n3\n0\n0\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1528/B | Solve the following coding problem using the programming language python:
Kavi has 2n points lying on the OX axis, i-th of which is located at x = i.
Kavi considers all ways to split these 2n points into n pairs. Among those, he is interested in good pairings, which are defined as follows:
Consider n segments with e... | ```python
import sys, math
import io, os
def data():
return sys.stdin.buffer.readline().strip()
def mdata():
return list(map(int, data().split()))
def outl(var):
sys.stdout.write(' '.join(map(str, var)) + '\n')
def out(var):
sys.stdout.write(str(var) + '\n')
mod = 998244353
n = int(data())
l = [1] * (n + 1)
for... | vfc_144466 | {
"difficulty": "medium_hard",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1528/B",
"time_limit": "1.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "333625\n",
"output": "668510586",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "693549\n",
"output": "721751076",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
taco | verifiable_code | https://codeforces.com/problemset/problem/1007/A | Solve the following coding problem using the programming language python:
You are given an array of integers. Vasya can permute (change order) its integers. He wants to do it so that as many as possible integers will become on a place where a smaller integer used to stand. Help Vasya find the maximal number of such in... | ```python
from collections import Counter as co
x = int(input())
y = list(map(int, input().split()))
print(x - max(co(y).values()))
``` | vfc_144470 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1007/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7\n10 1 1 1 5 5 3\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n1 1 1 1 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
taco | verifiable_code | https://www.codechef.com/problems/DIVISIBLEBY | Solve the following coding problem using the programming language python:
You are given an array A consisting of N positive integers.
Suppose F(B,X) gives the minimum positive integer Y such that:
X divides Y \cdot B_{i} for all (1 ≤ i ≤ |B|).
Find the value of F(A,A_{i}) for all (1 ≤ i ≤ N).
------ Input Format -... | ```python
import math as m
t = int(input())
for _ in range(t):
n = int(input())
A = list(map(int, input().split()))
gcd = A[0]
for j in A:
gcd = m.gcd(j, gcd)
for j in A:
print(j // gcd, end=' ')
print()
``` | vfc_144474 | {
"difficulty": "medium",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/DIVISIBLEBY",
"time_limit": "2 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n2\n1 2\n3\n2 2 2\n",
"output": "1 2\n1 1 1\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/77/E | Solve the following coding problem using the programming language python:
Have you ever tasted Martian food? Well, you should.
Their signature dish is served on a completely black plate with the radius of R, flat as a pancake.
First, they put a perfectly circular portion of the Golden Honduras on the plate. It has t... | ```python
def solve(R, r, k):
r = r / R
n = k
answer = (1 - r) * r / (2 * (n ** 2 * (1 - r) ** 2 + r))
answer = 2 * R * answer
print('%.10f' % answer)
t = int(input())
for i in range(t):
(R, r, k) = map(int, input().split())
solve(R, r, k)
``` | vfc_144478 | {
"difficulty": "very_hard",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/77/E",
"time_limit": "1.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n4 2 2\n",
"output": "0.6666666667\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1486/D | Solve the following coding problem using the programming language python:
You are a given an array $a$ of length $n$. Find a subarray $a[l..r]$ with length at least $k$ with the largest median.
A median in an array of length $n$ is an element which occupies position number $\lfloor \frac{n + 1}{2} \rfloor$ after we s... | ```python
import sys
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
l = 0
r = n
while l < r:
if l + 1 == r:
try1 = r
flag = 0
tmp = 0
grid = [0]
for i in range(n):
if a[i] >= try1:
tmp += 1
else:
tmp -= 1
grid.append(tmp)
lowestprev = 0
for i in range(k, n + 1):
... | vfc_144486 | {
"difficulty": "hard",
"memory_limit": "256 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1486/D",
"time_limit": "2 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 3\n1 2 3 2 1\n",
"output": "2",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1600/J | Solve the following coding problem using the programming language python:
You have received data from a Bubble bot. You know your task is to make factory facilities, but before you even start, you need to know how big the factory is and how many rooms it has. When you look at the data you see that you have the dimensi... | ```python
directions = [(-1, 0), (0, 1), (1, 0), (0, -1)]
i_cant_do_bitwise_operations = {0: (False, False, False, False), 1: (False, False, False, True), 2: (False, False, True, False), 3: (False, False, True, True), 4: (False, True, False, False), 5: (False, True, False, True), 6: (False, True, True, False), 7: (Fals... | vfc_144497 | {
"difficulty": "medium",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1600/J",
"time_limit": "1.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6 1\n13\n5\n7\n15\n13\n7\n",
"output": "3 2 1 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 5\n9 14 9 12 13\n5 15 11 6 7\n5 9 14 9 14\n3 2 14 3 14\n",
"output": "9 4 4 2 1 \n",
... |
taco | verifiable_code | https://www.codechef.com/CDGO2021/problems/STRNCHAR | Solve the following coding problem using the programming language python:
Your are given a string $S$ containing only lowercase letter and a array of character $arr$. Find whether the given string only contains characters from the given character array.
Print $1$ if the string contains characters from the given array... | ```python
t = int(input())
for _ in range(t):
S = set(input().strip())
n = int(input().strip())
a = set(input().strip().split(' '))
g = True
for i in S:
if i not in a:
g = False
if g:
print(1)
else:
print(0)
``` | vfc_144501 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/CDGO2021/problems/STRNCHAR",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\nabcd\n4\na b c d\naabbbcccdddd\n4\na b c d\nacd\n3\na b d\n",
"output": "1\n1\n0\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
It is lunch time at the Vibrant Gujarat Summit and all the investors are called for the executive lunch. When Bruce reached the lunch area, he found that the waiter was taking out bowls from a big box containing some amount of golden bowls and o... | ```python
v = eval(input())
print(int((v*(v-1)/2)**.5)+1)
``` | vfc_144505 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4684660",
"output": "756872327473",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "120",
"output": "85",
"type": "stdin_stdout"
}
]
} | |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Example
Input
2 2 2 1
0 0 0
Output
24
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (... | vfc_144509 | {
"difficulty": "unknown_difficulty",
"memory_limit": "268.435456 megabytes",
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "5.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 2 2 0\n0 0 0",
"output": "24\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 1 2 0\n-1 -1 0",
"output": "16\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... | |
taco | verifiable_code | https://codeforces.com/problemset/problem/1343/A | Solve the following coding problem using the programming language python:
Recently Vova found $n$ candy wrappers. He remembers that he bought $x$ candies during the first day, $2x$ candies during the second day, $4x$ candies during the third day, $\dots$, $2^{k-1} x$ candies during the $k$-th day. But there is an issu... | ```python
t = int(input())
for i in range(t):
n = int(input())
k = 2
j = 0
while True:
j = 2 ** k
if n % (j - 1) == 0:
break
k = k + 1
print(n // (j - 1))
``` | vfc_144513 | {
"difficulty": "easy",
"memory_limit": "256 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1343/A",
"time_limit": "1 second"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7\n3\n6\n7\n21\n28\n999999999\n999999984\n",
"output": "1\n2\n1\n7\n4\n333333333\n333333328\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/LGSEG | Solve the following coding problem using the programming language python:
Read problem statements in [Mandarin], [Bengali], [Russian], and [Vietnamese] as well.
Chef has a sequence A_{1}, A_{2}, \ldots, A_{N}. Let's call a contiguous subsequence of A a *segment*.
A segment is *good* if it can be divided into at most... | ```python
def build(N, start_index):
up = [[None] * N for _ in range(20)]
up[0] = start_index
for i in range(1, 20):
for j in range(N):
p = up[i - 1][j]
if p == -1:
up[i][j] = -1
else:
up[i][j] = up[i - 1][p]
return up
def call(up, node, K):
(last, jump) = (node, 1)
for i in range(19):
if no... | vfc_144525 | {
"difficulty": "very_hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/LGSEG",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n5 2 5\n1 3 2 1 5\n5 3 5\n5 1 5 1 1",
"output": "4\n4",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/2/A | Solve the following coding problem using the programming language python:
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more diffic... | ```python
n = int(input())
d = {}
l = []
for _ in range(n):
(name, score) = input().split()
score = int(score)
l.append((name, score))
d[name] = d.get(name, 0) + score
m = max([x for x in d.values()])
ties = [x for (x, y) in d.items() if y == m]
if len(ties) == 1:
print(ties[0])
exit()
else:
d.clear()
for row i... | vfc_144530 | {
"difficulty": "medium",
"memory_limit": "64.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/2/A",
"time_limit": "1.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "15\naawtvezfntstrcpgbzjbf 681\nzhahpvqiptvksnbjkdvmknb -74\naawtvezfntstrcpgbzjbf 661\njpdwmyke 474\naawtvezfntstrcpgbzjbf -547\naawtvezfntstrcpgbzjbf 600\nzhahpvqiptvksnbjkdvmknb -11\njpdwmyke 711\nbjmj 652\naawtvezfntstrcpgbzjbf ... |
taco | verifiable_code | https://www.codechef.com/problems/COOK82A | Solve the following coding problem using the programming language python:
Read problems statements in mandarin chinese, russian and vietnamese as well.
Today is the final round of La Liga, the most popular professional football league in the world. Real Madrid is playing against Malaga and Barcelona is playing again... | ```python
T = int(input())
for i in range(T):
scores = dict()
for j in range(4):
(team, score) = map(str, input().split(' '))
score = int(score)
scores[team] = score
if scores['RealMadrid'] < scores['Malaga'] and scores['Barcelona'] > scores['Eibar']:
print('Barcelona')
else:
print('RealMadrid')
``` | vfc_144534 | {
"difficulty": "easy",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/COOK82A",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\nBarcelona 2\nMalaga 1\nRealMadrid 1\nEibar 0\nMalaga 3\nRealMadrid 2\nBarcelona 8\nEibar 6",
"output": "RealMadrid\nBarcelona",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/largest-power-of-prime4416/1 | Solve the following coding problem using the programming language python:
Given a positive integer N and a prime p, the task is to print the largest power of prime p that divides N!. Here N! means the factorial of N = 1 x 2 x 3 . . (N-1) x N.
Note that the largest power may be 0 too.
Example 1:
Input:
N = 5 , p = 2
... | ```python
class Solution:
def largestPowerOfPrime(self, N, p):
sum = 0
while N:
N //= p
sum += N
return sum
``` | vfc_144547 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/largest-power-of-prime4416/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N = 5 , p = 2",
"output": "3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "N = 3 , p = 5",
"output": "0",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.hackerrank.com/challenges/two-strings/problem | Solve the following coding problem using the programming language python:
Given two strings, determine if they share a common substring. A substring may be as small as one character.
Example
$s1=\text{'and'}$
$s2=\text{'art'}$
These share the common substring $\class{ML__boldsymbol}{\boldsymbol{a}}$.
$\t... | ```python
a = int(input())
for i in range(a):
i = input()
j = input()
setx = set([a for a in i])
sety = set([y for y in j])
if setx.intersection(sety) == set():
print('NO')
else:
print('YES')
``` | vfc_144548 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.hackerrank.com/challenges/two-strings/problem",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\nhello\nworld\nhi\nworld\n",
"output": "YES\nNO\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.hackerrank.com/challenges/possible-path/problem | Solve the following coding problem using the programming language python:
Adam is standing at point $(a,b)$ in an infinite 2D grid. He wants to know if he can reach point $(x,y)$ or not. The only operation he can do is to move to point $(a+b,b),(a,a+b),(a-b,b),\text{or}(a,b-a)$ from some point $(a,b)$. It is given tha... | ```python
t = int(input())
def gcd(a, b):
if b == 0:
return a
return gcd(b, a % b)
for i in range(t):
(a, b, x, y) = map(int, input().split())
if gcd(a, b) == gcd(x, y):
print('YES')
else:
print('NO')
``` | vfc_144552 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.hackerrank.com/challenges/possible-path/problem",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 1 2 3\n2 1 2 3\n3 3 1 1\n",
"output": "YES\nYES\nNO\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/888/D | Solve the following coding problem using the programming language python:
A permutation p of size n is an array such that every integer from 1 to n occurs exactly once in this array.
Let's call a permutation an almost identity permutation iff there exist at least n - k indices i (1 ≤ i ≤ n) such that p_{i} = i.
Your... | ```python
import math
def calculate_derangement(fac, n):
ans = fac[n]
for i in range(1, n + 1):
if i % 2 == 1:
ans -= fac[n] // fac[i]
else:
ans += fac[n] // fac[i]
return ans
(n, k) = map(int, input().split())
fac = [1]
for i in range(1, n + 1):
fac.append(fac[i - 1] * i)
ans = 0
for i in range(0, k + 1... | vfc_144556 | {
"difficulty": "medium_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/888/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 2\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 3\n",... |
taco | verifiable_code | https://www.codechef.com/problems/COOLCHEF | Solve the following coding problem using the programming language python:
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef is experimenting in his kitchen. He has $N$ spices (numbered $0$ through $N-1$) with types $S_{0}, S_{1}, \ldots, S_{N-1}$.
You should... | ```python
def exponent(a, y, m):
if y == 0:
return 1
ss = y // 2
an = exponent(a, ss, m)
an = an * an % m
if y % 2 == 0:
return an
else:
return a * an % m
import bisect
(n, q) = map(int, input().split())
it = list(map(int, input().split()))
a = [1]
x = 10 ** 9 + 7
for i in range(1, n + 1):
a.append(a[-1] *... | vfc_144560 | {
"difficulty": "very_hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/COOLCHEF",
"time_limit": "5 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 3\n1 2 3 7 10\n1 1 1 1\n2 1 3 4\n0 0 0 4",
"output": "1\n2\n120",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
problem
You are a traveler traveling on the JOI Highway. The JOI Highway is a road that extends straight from east to west, and there are n post towns on the JOI Highway. Numbered. The westernmost post town on the JOI highway is post town 1, an... | ```python
(n, m) = map(int, input().split())
accums = [0]
for i in range(n - 1):
accums.append(accums[-1] + int(input()))
result = 0
k = 0
for i in range(m):
a = int(input())
result = (result + abs(accums[k + a] - accums[k])) % 100000
k += a
print(result)
``` | vfc_144564 | {
"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": "7 5\n2\n1\n2\n3\n2\n1\n2\n-1\n3\n2\n-3",
"output": "19\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7 5\n2\n0\n2\n3\n2\n1\n2\n-1\n3\n2\n-3",
"output": "16\n",
"type": "stdin... | |
taco | verifiable_code | https://codeforces.com/problemset/problem/146/B | 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 calls a mask of a... | ```python
s = input()
(a, b) = (s.split()[0], s.split()[1])
dif = len(a) - len(b)
mask = ''
tmp = int(a)
tmp += 1
t = str(tmp)
while 1:
for i in t:
if i in ['4', '7']:
mask += i
if mask == b:
break
else:
tmp += 1
t = str(tmp)
mask = ''
print(tmp)
``` | vfc_144568 | {
"difficulty": "easy",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/146/B",
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "39999 4774\n",
"output": "40774\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "40007 74\n",
"output": "50074\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
taco | verifiable_code | https://codeforces.com/problemset/problem/1263/B | Solve the following coding problem using the programming language python:
A PIN code is a string that consists of exactly $4$ digits. Examples of possible PIN codes: 7013, 0000 and 0990. Please note that the PIN code can begin with any digit, even with 0.
Polycarp has $n$ ($2 \le n \le 10$) bank cards, the PIN code o... | ```python
try:
n = int(input())
for i in range(n):
count = 0
sub = 0
u = int(input())
b = []
for j in range(u):
o = str(input())
b.append(o)
d = set(b)
for r in d:
sub = sub + (b.count(r) - 1)
count = count + sub
print(count)
for (er, gh) in enumerate(b):
if b.count(gh) == 1:
conti... | vfc_144572 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1263/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n2\n1234\n0600\n2\n1337\n1337\n4\n3139\n3139\n3139\n3139\n",
"output": "0\n1234\n0600\n1\n1337\n0337\n3\n3139\n0139\n1139\n2139\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n10\n000... |
taco | verifiable_code | https://www.hackerrank.com/challenges/compare-the-triplets/problem | Solve the following coding problem using the programming language python:
Alice and Bob each created one problem for HackerRank. A reviewer rates the two challenges, awarding points on a scale from 1 to 100 for three categories: problem clarity, originality, and difficulty.
The rating for Alice's challenge is the tr... | ```python
import sys
(a0, a1, a2) = input().strip().split(' ')
(a0, a1, a2) = [int(a0), int(a1), int(a2)]
(b0, b1, b2) = input().strip().split(' ')
(b0, b1, b2) = [int(b0), int(b1), int(b2)]
A = (a0 > b0) + (a1 > b1) + (a2 > b2)
B = (a0 < b0) + (a1 < b1) + (a2 < b2)
print(A, B)
``` | vfc_144577 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.hackerrank.com/challenges/compare-the-triplets/problem",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 6 7\n3 6 10\n",
"output": "1 1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "17 28 30\n99 16 8\n",
"output": "2 1\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/BENCHP | Solve the following coding problem using the programming language python:
In the gym, Chef prefers to lift at least $W$ grams during a bench press and if that's impossible, Chef considers his workout to be incomplete and feels bad.
The rod weighs $W_{r}$ grams and there are $N$ other weights lying on the floor that w... | ```python
from collections import Counter
tc = int(input())
for _ in range(tc):
(n, w, wr) = map(int, input().split())
a = Counter(list(map(int, input().split())))
if wr >= w:
print('YES')
else:
d = 0
for i in a:
d += a[i] // 2 * i * 2
if wr + d >= w:
print('YES')
break
else:
print('NO')
`... | vfc_144581 | {
"difficulty": "medium_hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/BENCHP",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n2 5 10 \n2 2\n7 100 50\n100 10 10 10 10 10 90 \n6 100 40 \n10 10 10 10 10 10",
"output": "YES\nNO\nYES",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1105/D | Solve the following coding problem using the programming language python:
Kilani is playing a game with his friends. This game can be represented as a grid of size $n \times m$, where each cell is either empty or blocked, and every player has one or more castles in some cells (there are no two castles in one cell).
T... | ```python
import sys
from collections import deque as dq
(h, w, P) = [int(x) for x in input().split()]
S = [int(x) for x in input().split()]
board = []
for b in sys.stdin.read():
for c in b:
if c == '.':
board.append(-1)
elif 0 <= ord(c) - 49 <= 9:
board.append(ord(c) - 49)
elif c == '#':
board.append(-... | vfc_144591 | {
"difficulty": "hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1105/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 3 2\n1 1\n1..\n...\n..2\n",
"output": "6 3 \n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1609/C | Solve the following coding problem using the programming language python:
While performing complex market analysis William encountered the following problem:
For a given array $a$ of size $n$ and a natural number $e$, calculate the number of pairs of natural numbers $(i, k)$ which satisfy the following conditions:
$... | ```python
import sys
isPrime = [True] * int(1000000.0 + 2)
def solve():
inp = sys.stdin.readline
(n, e) = map(int, inp().split())
a = list(map(int, inp().split()))
w = [True] * n
r = 0
for i in range(n):
if w[i]:
j = 0
z = i
last = -1
last1 = -1
p = False
while z < n:
w[z] = False
v =... | vfc_144595 | {
"difficulty": "medium",
"memory_limit": "256 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1609/C",
"time_limit": "2 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n7 3\n10 2 1 3 1 19 3\n3 2\n1 13 1\n9 3\n2 4 2 1 1 1 1 4 2\n3 1\n1 1 1\n4 1\n1 2 1 1\n2 2\n1 2\n",
"output": "2\n0\n4\n0\n5\n0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n10 3\n1... |
taco | verifiable_code | https://www.codechef.com/ICOD2016/problems/ICODE16D | Solve the following coding problem using the programming language python:
Now-a-days, Manish is becoming famous for bank robbery in the country because of his cleverness, he never robs own his own.He has four workers A , B, C, and D , all working under him.All of the four take some amount for that. There are total N ... | ```python
for t in range(int(input())):
n = int(input())
l = []
m = []
x = list(map(int, input().split()))
l.append(x)
m.append(list(x))
for i in range(1, n):
x = list(map(int, input().split()))
l.append(x)
temp = []
for i in range(4):
temp.append(x[i] + min(m[-1][:i] + m[-1][i + 1:]))
m.append(temp... | vfc_144604 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/ICOD2016/problems/ICODE16D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n3\n4 7 2 9\n5 6 4 7\n2 6 4 3\n",
"output": "10\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/interesting-queries4742/1 | Solve the following coding problem using the programming language python:
Given an array nums of n elements and q queries . Each query consists of two integers l and r . You task is to find the number of elements of nums[] in range [l,r] which occur atleast k times.
Example 1:
Input: nums = {1,1,2,1,3}, Queries = {{... | ```python
import math
class Solution:
def solveQueries(self, nums, Queries, k):
answers = [0] * len(Queries)
count = {}
n = int(math.sqrt(len(nums))) + 1
q = list(enumerate(Queries))
q.sort(key=lambda a: [int(a[1][0] / n), -a[1][1]])
currentL = 0
currentR = -1
ans = 0
for i in q:
left = i[1][0] ... | vfc_144608 | {
"difficulty": "medium_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/interesting-queries4742/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "nums = {1,1,2,1,3}, Queries = {{1,5},\r\n{2,4}}, k = 1",
"output": "{3,2}",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "nums = {1,2,3,1}, Queries = {{1,4},\r\n{2,4},{4,4}, k = 2",
"o... |
taco | verifiable_code | https://codeforces.com/problemset/problem/811/C | Solve the following coding problem using the programming language python:
Vladik often travels by trains. He remembered some of his trips especially well and I would like to tell you about one of these trips:
Vladik is at initial train station, and now n people (including Vladik) want to get on the train. They are al... | ```python
import sys
inf = 1 << 30
def solve():
n = int(input())
a = [0] + [int(i) for i in input().split()]
maxi = max(a)
f = [-1] * (maxi + 1)
for i in range(1, n + 1):
if f[a[i]] == -1:
f[a[i]] = i
l = [-1] * (maxi + 1)
for i in range(n, 0, -1):
if l[a[i]] == -1:
l[a[i]] = i
dp = [0] * (n + 1)
fo... | vfc_144609 | {
"difficulty": "hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/811/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n4 4 2 5 2 3\n",
"output": "14\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "9\n5 1 3 1 5 2 4 2 5\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"fn_name": ... |
taco | verifiable_code | https://codeforces.com/problemset/problem/177/B1 | Solve the following coding problem using the programming language python:
The Smart Beaver from ABBYY decided to have a day off. But doing nothing the whole day turned out to be too boring, and he decided to play a game with pebbles. Initially, the Beaver has n pebbles. He arranges them in a equal rows, each row has b... | ```python
n = int(input())
r = n + 1
i = 2
s = n ** 0.5
while i <= s:
if n % i == 0:
r += n // i
n //= i
s = n ** 0.5
i = 1
i += 1
print(r)
``` | vfc_144613 | {
"difficulty": "easy",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/177/B1",
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "999161856\n",
"output": "1998319610\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "999999937\n",
"output": "999999938\n",
"type": "stdin_stdout"
},
{
"fn_name": ... |
taco | verifiable_code | https://www.codechef.com/PCR12020/problems/BHARAT | Solve the following coding problem using the programming language python:
Bharat was given a problem to solve, by his brother, Lord Ram. The problem was like, given integers, $N$ and $K$, Bharat has to find the number (possibilities) of non-increasing arrays of length $K$, where each element of the array is between $1... | ```python
import math
p = 7 + 10 ** 9
(n, k) = list(map(int, input().split()))
c = math.factorial(n + k - 1) // (math.factorial(k) * math.factorial(n - 1))
print(c % p)
``` | vfc_144617 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/PCR12020/problems/BHARAT",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 5\n",
"output": "6\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/xor-of-all-elements0736/1 | Solve the following coding problem using the programming language python:
Given a list A having N positive elements. The task to create another list such as i^{th} element is XOR of all elements of A except A[i].
Example 1:
Input:
A = [2, 1, 5, 9]
Output:
13 14 10 6
Explanation:
At first position 1^5^9 = 13
At second... | ```python
class Solution:
def getXor(self, A, N):
xor = 0
for i in A:
xor ^= i
for i in range(N):
A[i] ^= xor
return A
``` | vfc_144621 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/xor-of-all-elements0736/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "A = [2, 1, 5, 9]",
"output": "13 14 10 6",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/modular-exponentiation-for-large-numbers5537/1 | Solve the following coding problem using the programming language python:
Implement pow(x, n) % M.
In other words, given x, n and M, find (x^{n}) % M.
Example 1:
Input:
x = 3, n = 2, m = 4
Output:
1
Explanation:
3^{2} = 9. 9 % 4 = 1.
Example 2:
Input:
x = 2, n = 6, m = 10
Output:
4
Explanation:
2^{6} = 64. 64 % 10 =... | ```python
class Solution:
def PowMod(self, x, n, m):
res = 1
while n > 0:
if n & 1 != 0:
res = res * x % m % m
x = x % m * x % m % m
n = n >> 1
return res
``` | vfc_144622 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/modular-exponentiation-for-large-numbers5537/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "x = 3, n = 2, m = 4",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "x = 2, n = 6, m = 10",
"output": "4",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1550/A | Solve the following coding problem using the programming language python:
Let's call an array $a$ consisting of $n$ positive (greater than $0$) integers beautiful if the following condition is held for every $i$ from $1$ to $n$: either $a_i = 1$, or at least one of the numbers $a_i - 1$ and $a_i - 2$ exists in the arr... | ```python
import math
for _ in range(int(input())):
n = int(input())
if n == 1:
print(1)
else:
x = int(math.sqrt(n))
if x ** 2 == n:
print(x)
else:
print(x + 1)
``` | vfc_144643 | {
"difficulty": "easy",
"memory_limit": "256 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1550/A",
"time_limit": "1 second"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1\n8\n7\n42\n",
"output": "1\n3\n3\n7\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n1\n12\n7\n42\n",
"output": "1\n4\n3\n7\n",
"type": "stdin_stdout"
},
{
... |
taco | verifiable_code | https://codeforces.com/problemset/problem/1227/B | Solve the following coding problem using the programming language python:
Permutation $p$ is a sequence of integers $p=[p_1, p_2, \dots, p_n]$, consisting of $n$ distinct (unique) positive integers between $1$ and $n$, inclusive. For example, the following sequences are permutations: $[3, 4, 1, 2]$, $[1]$, $[1, 2]$. T... | ```python
def test(a):
se = set()
se.add(a[0])
ans = [a[0]]
l = 1
for i in range(1, len(a)):
if a[i] == a[i - 1]:
while l in se:
l += 1
ans.append(l)
se.add(l)
else:
ans.append(a[i])
se.add(a[i])
if ans[i] > a[i]:
print(-1)
return
f = False
if len(set(ans)) == n:
print(' '.join(m... | vfc_144647 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1227/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n5\n1 3 4 5 5\n4\n1 1 3 4\n2\n2 2\n1\n1\n",
"output": "1 3 4 5 2 \n-1\n2 1 \n1 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n5\n2 3 4 5 5\n4\n1 1 3 4\n2\n2 2\n1\n1\n",
"outpu... |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Given an array A. Delete an single element from the array such that sum of the differences of adjacent elements should be minimum.
For more clarification Sum for an array A having N element is defined as :
abs( A[0] - A[1] ) + abs( A[1] - ... | ```python
for tc in range(eval(input())):
n = eval(input())
a = list(map(int,input().split()))
k=ans=0
if n < 3:
ans=0
else:
t=abs(a[0]-a[1])
k=t
for i in range(1,n-1):
t = abs(abs(a[i-1]-a[i]) + abs(a[i]-a[i+1]) - abs(a[i-1]-a[i+1]))
if t>k:
k=t
ans = i
if n > 2 and abs(a[n-1]-a[n-2]) > k:
... | vfc_144652 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1\n100\n2\n100 1\n2\n1 2\n3\n1 100 2\n3\n1 2 3\n3\n1 5 6\n3\n1 7 8\n3\n8 7 1\n3\n7 8 1\n3\n7 1 8",
"output": "0\n0\n0\n1\n0",
"type": "stdin_stdout"
}
]
} | |
taco | verifiable_code | https://www.codechef.com/problems/SEATSTR2 | Solve the following coding problem using the programming language python:
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Sereja has a string A consisting of n lower case English letters.
Sereja calls two strings X and Y each of length n similar if they can be made equal by applying t... | ```python
md = 10 ** 9 + 7
fact = []
prod = 1
for x in range(1, 100002):
fact.append(prod)
prod *= x
prod %= md
for _ in range(int(input())):
s = input()
counts = [s.count(x) for x in set(s)]
sym4 = 0
sym3 = 0
sym2 = 0
sym1 = 0
sym1choose2 = 0
sym2choose2 = 0
sym1cchoose2 = 0
sym1c2choose2 = 0
choose_all ... | vfc_144656 | {
"difficulty": "hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/SEATSTR2",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\nz\nabcd",
"output": "0\n144",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\nz\nabcd",
"output": "0\n144",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/UWCOI20C | Solve the following coding problem using the programming language python:
Kim has broken in to the base, but after walking in circles, perplexed by the unintelligible base design of the JSA, he has found himself in a large, empty, and pure white, room.
The room is a grid with H∗W$H*W$ cells, divided into H$H$ rows an... | ```python
def solve(l, r, c, row, col, po):
count = 0
visited = set()
stack = set()
stack.add((l[row][col], row, col))
while stack:
ele = stack.pop()
visited.add((ele[1], ele[2]))
if ele[0] < po:
count += 1
if ele[1] - 1 >= 0 and (ele[1] - 1, ele[2]) not in visited:
if l[ele[1] - 1][ele[2]] < po:
... | vfc_144660 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/UWCOI20C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n5 5 3\n4 3 9 7 2\n8 6 5 2 8\n1 7 3 4 3\n2 2 4 5 6\n9 9 9 9 9\n3 4 6\n3 2 5\n1 4 9\n",
"output": "10\n0\n19\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
It’s well know fact among kitties that digits 4 and 7 are lucky digits.
Today, N boxes of fish bites arrived. Each box has a unique integer label on it, ranged between 1 and N, inclusive. The boxes are going to be given away to the kitties in in... | ```python
k = eval(input())
n = eval(input())
i=1
a=0
b=0
cnt=0
while(i<=n):
a+=str(i).count('4')
b+=str(i).count('7')
if(a+b>k):
cnt+=1
a=0
b=0
i+=1
print(cnt)
``` | vfc_144664 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n7331173",
"output": "2305411",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n49503",
"output": "6684",
"type": "stdin_stdout"
},
{
"fn_name": null,
"inp... | |
taco | verifiable_code | https://codeforces.com/problemset/problem/1367/A | Solve the following coding problem using the programming language python:
Alice guesses the strings that Bob made for her.
At first, Bob came up with the secret string $a$ consisting of lowercase English letters. The string $a$ has a length of $2$ or more characters. Then, from string $a$ he builds a new string $b$ a... | ```python
for _ in range(int(input())):
b = list(input())
a = [b[0]]
n = len(b)
i = 1
while i < n:
a.append(b[i])
i += 2
print(*a, sep='')
``` | vfc_144669 | {
"difficulty": "easy",
"memory_limit": "256 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1367/A",
"time_limit": "2 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\nabbaac\nac\nbccddaaf\nzzzzzzzzzz\n",
"output": "abac\nac\nbcdaf\nzzzzzz\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\nassaad\n",
"output": "asad\n",
"type": "stdin_stdo... |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Captain Jack loves tables. He wants to know whether you love tables or not. So he asks you to solve the following problem:
Given an array A and element m, you have to find the value up to which table of m is present in the array. (example - if t... | ```python
'''
# Read input from stdin and provide input before running code
name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
#print 'Hello World!'
n,m=list(map(int,input().split()))
l=[int(i) for i in input().split()]
c=0
t=m
for i in range(1,len(l)+1):
#print i
if m in l:
c=m
#print c
m=i*t... | vfc_144673 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "8 3\n2 1 4 5 7 10 11 13",
"output": "10",
"type": "stdin_stdout"
}
]
} | |
taco | verifiable_code | https://www.codechef.com/problems/TREE3 | Solve the following coding problem using the programming language python:
Kefaa has developed a novel decomposition of a tree. He claims that this decomposition solves many difficult problems related to trees. However, he doesn't know how to find it quickly, so he asks you to help him.
You are given a tree with $N$ ve... | ```python
def dfs(u, p):
l = [u]
for v in g[u]:
if v != p:
r = dfs(v, u)
if r == 2:
return 2
if r == 1:
l.append(v)
if len(l) == 4:
out.append(l)
l = [u]
if len(l) == 3:
out.append(l + [p])
return len(l)
t = int(input())
for _ in range(t):
n = int(input())
g = [[] for _ in range... | vfc_144677 | {
"difficulty": "very_hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/TREE3",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n4\n1 2\n1 3\n1 4\n7\n1 2\n2 3\n1 4\n4 5\n1 6\n6 7\n",
"output": "YES\n1 2 3 4\nNO\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/676/A | Solve the following coding problem using the programming language python:
Nicholas has an array a that contains n distinct integers from 1 to n. In other words, Nicholas has a permutation of size n.
Nicholas want the minimum element (integer 1) and the maximum element (integer n) to be as far as possible from each ot... | ```python
N = int(input(''))
Line2 = input('')
Array = list(map(int, Line2.split(' ')))
min_elem_index = Array.index(min(Array))
max_elem_index = Array.index(max(Array))
min_index = 0
max_index = N - 1
L_inv1 = abs(min_elem_index - min_index)
R_inv1 = abs(max_index - min_elem_index)
ans1 = 0
if L_inv1 >= R_inv1:
ans1 ... | vfc_144681 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/676/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n4 5 1 3 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7\n1 6 5 3 4 7 2\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/reverse-level-order-traversal/1 | Solve the following coding problem using the programming language python:
Given a binary tree of size N, find its reverse level order traversal. ie- the traversal must begin from the last level.
Example 1:
Input :
1
/ \
3 2
Output: 3 2 1
Explanation:
Traversing level 1 : 3 2
Traversing level ... | ```python
def reverseLevelOrder(root):
temp1 = [root]
result = []
while temp1:
temp2 = []
temp3 = []
for i in temp1:
temp3.append(i.data)
if i.left:
temp2.append(i.left)
if i.right:
temp2.append(i.right)
temp1 = temp2
if temp3:
result = temp3 + result
return result
``` | vfc_144685 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/reverse-level-order-traversal/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\r\n / \\\r\n 3 2",
"output": "3 2 1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\r\n / \\\r\n 20 30\r\n / \\ \r\n 40 60",
"output": "40 60 20 3... |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/sum-triangle-for-given-array1159/1 | Solve the following coding problem using the programming language python:
Given a array, write a program to construct a triangle where last row contains elements of given array, every element of second last row contains sum of below two elements and so on.
Example 1:
Input:
A[] = {4, 7, 3, 6, 7};
Output:
81 40 41 21 1... | ```python
def getTriangle(arr, n):
s = [[0 for i in range(n)] for j in range(n)]
for i in range(n):
s[n - 1][i] = arr[i]
j = 1
while j < n:
k = j
for i in range(k, n, 1):
s[n - 1 - j][i] = s[n - j][i] + s[n - j][i - 1]
j += 1
a = []
i = n - 1
while i > -1:
for j in range(i, n, 1):
a.append(s[n - ... | vfc_144686 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/sum-triangle-for-given-array1159/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": "getTriangle",
"input": "A[] = {4, 7, 3, 6, 7};",
"output": "81 40 41 21 19 22 11 10 9 13 4 7 3 6 7",
"type": "function_call"
},
{
"fn_name": "getTriangle",
"input": "A[] = {5, 8, 1, 2, 4, 3, 14}",
"output": "... |
taco | verifiable_code | https://codeforces.com/problemset/problem/1300/C | Solve the following coding problem using the programming language python:
Anu has created her own function $f$: $f(x, y) = (x | y) - y$ where $|$ denotes the bitwise OR operation. For example, $f(11, 6) = (11|6) - 6 = 15 - 6 = 9$. It can be proved that for any nonnegative numbers $x$ and $y$ value of $f(x, y)$ is also... | ```python
n = int(input())
l = list(map(int, input().split()))
p = [0] * n
temp = ~l[0]
for i in range(1, n):
p[i] = temp
temp &= ~l[i]
temp = ~l[-1]
ans = [-1, -float('inf')]
for i in range(n - 2, -1, -1):
if i != 0:
p[i] &= temp
temp &= ~l[i]
p[i] &= l[i]
if ans[1] < p[i]:
ans[0] = i
ans[1] = p[i]
e... | vfc_144687 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1300/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n4 0 11 6\n",
"output": "11 6 4 0 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n13\n",
"output": "13 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"... |
taco | verifiable_code | https://codeforces.com/problemset/problem/415/D | Solve the following coding problem using the programming language python:
Mashmokh's boss, Bimokh, didn't like Mashmokh. So he fired him. Mashmokh decided to go to university and participate in ACM instead of finding a new job. He wants to become a member of Bamokh's team. In order to join he was given some programmin... | ```python
import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def ... | vfc_144691 | {
"difficulty": "medium",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/415/D",
"time_limit": "1.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2000 2000\n",
"output": "585712681",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1544 1794\n",
"output": "933285446",
"type": "stdin_stdout"
},
{
"fn_name": null,... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.