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-last-digit-of-ab-for-large-numbers1936/1 | Solve the following coding problem using the programming language python:
You are given two integer numbers, the base a and the index b. You have to find the last digit of a^{b}.
Example 1:
Input:
a = "3", b = "10"
Output:
9
Explanation:
3^{10} = 59049. Last digit is 9.
Example 2:
Input:
a = "6", b = "2"
Output:
6
E... | ```python
class Solution:
def getLastDigit(self, a, b):
a = int(a)
b = int(b)
if a == 0:
return 0
if b == 0:
return 1
if b == 1:
return a % 10
d = {}
d[0] = 0
d[1] = 1
d[2] = [6, 2, 4, 8]
d[3] = [1, 3, 9, 7]
d[4] = [6, 4]
d[5] = 5
d[6] = 6
d[7] = [1, 7, 9, 3]
d[8] = [6, 8, 4, 2]... | vfc_138746 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/find-last-digit-of-ab-for-large-numbers1936/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "a = \"3\", b = \"10\"",
"output": "9",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "a = \"6\", b = \"2\"",
"output": "6",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/825/C | Solve the following coding problem using the programming language python:
Makes solves problems on Decoforces and lots of other different online judges. Each problem is denoted by its difficulty — a positive integer number. Difficulties are measured the same across all the judges (the problem with difficulty d on Deco... | ```python
(n, k) = list(map(int, input().split()))
a = sorted(map(int, input().split()), reverse=True)
while len(a) > 0 and a[-1] <= k:
a.pop()
a.append(k)
ans = 0
while len(a) > 1:
(u, v) = (a[-1], a[-2])
while u * 2 < v:
ans += 1
u *= 2
a.pop()
print(ans)
``` | vfc_138747 | {
"difficulty": "medium_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/825/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 3\n2 1 9\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 20\n10 3 6 3\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
taco | verifiable_code | https://codeforces.com/problemset/problem/869/A | Solve the following coding problem using the programming language python:
Rock... Paper!
After Karen have found the deterministic winning (losing?) strategy for rock-paper-scissors, her brother, Koyomi, comes up with a new game as a substitute. The game works as follows.
A positive integer n is decided first. Both K... | ```python
n = int(input())
c = 0
x = list(map(int, input().split()))
y = list(map(int, input().split()))
z = set(x + y)
for i in range(n):
for j in range(n):
if x[i] ^ y[j] in z:
c = c + 1
if c % 2 == 0:
print('Karen')
else:
print('Koyomi')
``` | vfc_138751 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/869/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 2 3\n4 5 6\n",
"output": "Karen\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n2 4 6 8 10\n9 7 5 3 1\n",
"output": "Karen\n",
"type": "stdin_stdout"
},
{
... |
taco | verifiable_code | https://www.codechef.com/problems/DISTINCTNEIG | Solve the following coding problem using the programming language python:
You are given an array A of length 2\cdot N.
You also have an empty array B. You are asked to do the following operation exactly N times.
Choose two distinct indices x and y (1≤ x,y ≤ |A|);
Append (A_{x} - A_{y}) to the end of array B;
Delete... | ```python
for _ in range(int(input())):
n = int(input())
l = list(map(int, input().split(' ')))
mx = max((l.count(x) for x in l))
print('YES' if mx - n <= (n + 1) // 2 else 'NO')
``` | vfc_138760 | {
"difficulty": "medium_hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/DISTINCTNEIG",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n2\n1 1 1 1\n3\n1 1 2 2 3 3\n2\n1 1 2 2\n",
"output": "NO\nYES\nYES",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1154/D | Solve the following coding problem using the programming language python:
There is a robot staying at $X=0$ on the $Ox$ axis. He has to walk to $X=n$. You are controlling this robot and controlling how he goes. The robot has a battery and an accumulator with a solar panel.
The $i$-th segment of the path (from $X=i-1$... | ```python
(n, b, a) = (int(x) for x in input().strip().split(' '))
L = [int(x) for x in input().strip().split(' ')]
ans = 0
battery = b
acc = a
for x in L:
if x == 1 and acc < a and (battery > 0):
if battery == 0:
break
battery -= 1
acc += 1
ans += 1
elif x == 1 and acc == a:
acc -= 1
ans += 1
elif ac... | vfc_138770 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1154/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 2 1\n0 1 0 1 0\n",
"output": "5\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.hackerrank.com/challenges/python-print/problem | Solve the following coding problem using the programming language python:
Check Tutorial tab to know how to to solve.
The included code stub will read an integer, $n$, from STDIN.
Without using any string methods, try to print the following:
$123\cdots n$
Note that "$\bullet\bullet\bullet\bullet$" represents... | ```python
n = int(input())
for x in range(1, n + 1):
print(x, end='')
``` | vfc_138774 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.hackerrank.com/challenges/python-print/problem",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n",
"output": "123\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1433/F | Solve the following coding problem using the programming language python:
You are given a matrix $a$ of size $n \times m$ consisting of integers.
You can choose no more than $\left\lfloor\frac{m}{2}\right\rfloor$ elements in each row. Your task is to choose these elements in such a way that their sum is divisible by ... | ```python
inf = 1000000007
(n, m, k) = map(int, input().split())
dp = [-inf for i in range(k)]
dp[0] = 0
sz = m // 2
for _ in range(n):
a = list(map(int, input().split()))
pre = dp
dp = [[-inf for _ in range(k)] for _ in range(sz + 1)]
dp[0] = pre
for x in a:
for i in range(sz, 0, -1):
for j in range(k):
... | vfc_138778 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1433/F",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 4 3\n1 2 3 4\n5 2 2 2\n7 1 1 4\n",
"output": "24\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 5 4\n1 2 4 2 1\n3 5 1 2 4\n1 5 7 1 2\n3 8 7 1 2\n8 4 7 1 6\n",
"output": "56\n",
... |
taco | verifiable_code | https://codeforces.com/problemset/problem/625/B | Solve the following coding problem using the programming language python:
A long time ago, in a galaxy far far away two giant IT-corporations Pineapple and Gogol continue their fierce competition. Crucial moment is just around the corner: Gogol is ready to release it's new tablet Lastus 3000.
This new device is equip... | ```python
a = str(input())
b = str(input())
print(a.count(b))
``` | vfc_138782 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/625/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "intellect\ntell\n",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "google\napple\n",
"output": "0",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
In the middle of Tyrrhenian Sea, there is a small volcanic island called Chronus. The island is now uninhabited but it used to be a civilized island. Some historical records imply that the island was annihilated by an eruption of a volcano about... | ```python
from itertools import permutations
BASE = 12 * 3600
def convert(v):
return '%02d:%02d:%02d' % (v // 3600, v // 60 % 60, v % 60)
while 1:
N = int(input())
if N == 0:
break
R = set()
L = []
for i in range(N):
ts = set()
(*E,) = map(int, input().split())
for (a, b, c) in permutations(E, r=3):
f... | vfc_138786 | {
"difficulty": "unknown_difficulty",
"memory_limit": "134.217728 megabytes",
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "8.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n8 8 18\n32 32 32\n57 2 57\n5\n49 3 49\n7 30 44\n27 21 21\n33 56 56\n21 46 4\n3\n45 52 28\n36 26 36\n40 55 50\n10\n33 8 39\n50 57 43\n35 21 12\n21 17 11\n16 21 58\n45 40 53\n45 30 53\n39 1 8\n55 48 30\n7 48 15\n0",
"output"... | |
taco | verifiable_code | https://www.codechef.com/problems/MATTEG | Solve the following coding problem using the programming language python:
Mathison and Chef are playing a new teleportation game. This game is played on a $R \times C$ board where each cell $(i, j)$ contains some value $V_{i, j}$. The purpose of this game is to collect a number of values by teleporting from one cell t... | ```python
from collections import namedtuple
CurrentPosition = namedtuple('current_position', 'points, cell, pairs')
T = int(input())
for _ in range(T):
(R, C, N) = map(int, input().split())
(Sx, Sy) = map(int, input().split())
tx = map(int, input().split())
ty = map(int, input().split())
tel_pairs = list(zip(tx, ... | vfc_138790 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/MATTEG",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n5 5 2\n2 2\n1 2\n2 1\n10 11 62 14 15\n57 23 34 75 21\n17 12 14 11 53\n84 61 24 85 22\n43 89 14 15 43\n3 3 2\n0 0\n1 1\n1 1\n9 8 7\n5 6 4\n1 3 2\n2 2 1\n1 1\n2\n2\n5 6\n8 3\n",
"output": "188\n24\n3\n",
"type": "stdin... |
taco | verifiable_code | https://codeforces.com/problemset/problem/492/C | Solve the following coding problem using the programming language python:
Vanya wants to pass n exams and get the academic scholarship. He will get the scholarship if the average grade mark for all the exams is at least avg. The exam grade cannot exceed r. Vanya has passed the exams and got grade a_{i} for the i-th ex... | ```python
import operator
from sys import stdin, stdout
(n, m, reqAvg) = map(int, stdin.readline().split())
report = []
(curSum, curAvg) = (0, 0)
for i in range(n):
(avg, grade) = map(int, stdin.readline().split())
curSum += avg
report.append([avg, grade])
report.sort(key=operator.itemgetter(1))
curAvg = curSum / n
... | vfc_138794 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/492/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 5 4\n5 2\n4 7\n3 1\n3 2\n2 5\n",
"output": "4\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/363/D | Solve the following coding problem using the programming language python:
A group of n schoolboys decided to ride bikes. As nobody of them has a bike, the boys need to rent them.
The renting site offered them m bikes. The renting price is different for different bikes, renting the j-th bike costs p_{j} rubles.
In to... | ```python
def readn():
return list(map(int, input().split()))
(n, m, a) = readn()
(b, p) = (sorted(map(int, input().split()))[-min(n, m):], sorted(map(int, input().split())))
r = min(n, m)
mm = r
l = 0
while l <= r:
mid = l + (r - l) // 2
pri = sum([max(0, p[i] - b[mm - mid + i]) for i in range(mid)])
if pri <= a:
... | vfc_138812 | {
"difficulty": "medium_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/363/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 2 10\n5 5\n7 6\n",
"output": "2 3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 5 2\n8 1 1 2\n6 3 7 5 2\n",
"output": "3 8\n",
"type": "stdin_stdout"
},
{
"... |
taco | verifiable_code | https://codeforces.com/problemset/problem/760/C | Solve the following coding problem using the programming language python:
Pavel cooks barbecue. There are n skewers, they lay on a brazier in a row, each on one of n positions. Pavel wants each skewer to be cooked some time in every of n positions in two directions: in the one it was directed originally and in the rev... | ```python
n = int(input())
p = list(map(int, input().split()))
b = list(map(int, input().split()))
s = sum((b[i] for i in range(n)))
if s % 2 == 0:
ans = 1
else:
ans = 0
visited = [0] * n
ptr = 0
start = 1
visited[0] = 1
q = 1
c = 1
while q < n:
start = p[start - 1]
if visited[start - 1] == 1:
c += 1
while ptr ... | vfc_138816 | {
"difficulty": "medium_hard",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/760/C",
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 3 2\n0 0 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 3 2\n0 1 0\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,... |
taco | verifiable_code | Solve the following coding problem using the programming language python:
find the sum of the even fibonacci numbers till the given number(it is the value not index).
INPUT:
T test cases
next T lines consists of a number n.
OUTPUT:
Output the sum value.
0<t<10
2<n<10^20
Example:
if n=10
the numbers which are less th... | ```python
def fib(n):
a,b = 1,1
for i in range(n-1):
a,b = b,a+b
return a
def fibR(n):
if n==1 or n==2 or n==0:
return 1
return fib(n-1)+fib(n-2)
T=eval(input(''))
cnt=0
while T>cnt:
sum=0
n=eval(input(''))
for i in range(1000000):
t=fibR(i)
if t<n:
if t%2==0:
sum+=t
else:
break
print(... | vfc_138821 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n14576\n145786\n1254478\n147852\n125478",
"output": "14328\n60696\n1089154\n60696\n60696",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n457866622145522214789856\n321245663325\n12254\n... | |
taco | verifiable_code | https://codeforces.com/problemset/problem/1015/B | Solve the following coding problem using the programming language python:
You are given two strings $s$ and $t$. Both strings have length $n$ and consist of lowercase Latin letters. The characters in the strings are numbered from $1$ to $n$.
You can successively perform the following move any number of times (possibl... | ```python
n = map(int, input())
s = input()
t = input()
count = 0
moves = []
m = dict()
for c in s:
if c in m:
m[c] = m.get(c) + 1
else:
m[c] = 1
for c in t:
if c in m:
m[c] = m.get(c) - 1
else:
m[c] = -1
for keys in m.keys():
if m[keys] != 0:
print(-1)
exit()
s = list(s)
t = list(t)
for i in range(0, ... | vfc_138825 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1015/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\nabcdef\nabdfec\n",
"output": "4\n3 5 4 5 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\nabcd\naccd\n",
"output": "-1\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
A message from humans to extraterrestrial intelligence was sent through the Arecibo radio telescope in Puerto Rico on the afternoon of Saturday November l6, l974. The message consisted of l679 bits and was meant to be translated to a rectangular... | ```python
answer = []
def prime(n):
prime_flag = [0 for i in range(n + 1)]
prime_list = []
for i in range(2, n + 1):
if prime_flag[i] == 0:
prime_list.append(i)
temp = 1
while temp * i <= n:
prime_flag[temp * i] = 1
temp += 1
return prime_list
prime_list = prime(100000)
while True:
(m, a, b) = ... | vfc_138829 | {
"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": "5 1 2\n99999 999 999\n1680 5 16\n1970 1 2\n2002 4 11\n0 0 0",
"output": "2 2\n313 313\n23 73\n37 53\n37 53\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 1 2\n99999 999 999\n2566 5 16\n... | |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Exams are over !! Everyone is now in the mood to play the multiplayer game Counter-Strike 1.6. 12 players decide to play Counter-Strike 1.6, each one playing from his own room via LAN on his own laptop. The 12
players (6 on 6) : Counter Terrori... | ```python
t=int(input())
for i in range(t):
p,x,y,u,v = list(map(int, input().split()))
if x==u and y==v:
print("Counter-Terrorists Win !")
continue
a=x-u
b=y-v
if a==b:
if p>1:
print("Counter-Terrorists Win !")
else:
print("Terrorists Win !")
elif (a-b)%2==0:
if p>2:
print("Counter-Terrorists ... | vfc_138836 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n2 1 2 3 4 \n1 1 2 3 4\n2 1 2 4 3\n1 1 2 4 3\n3 1 2 4 3\n1 1 2 1 2",
"output": "Counter-Terrorists Win !\nTerrorists Win !\nTerrorists Win !\nTerrorists Win !\nCounter-Terrorists Win !\nCounter-Terrorists Win !",
"typ... | |
taco | verifiable_code | https://codeforces.com/problemset/problem/1498/C | Solve the following coding problem using the programming language python:
Gaurang has grown up in a mystical universe. He is faced by $n$ consecutive 2D planes. He shoots a particle of decay age $k$ at the planes.
A particle can pass through a plane directly, however, every plane produces an identical copy of the par... | ```python
import sys
import collections
import math
import bisect
import heapq
inf = sys.maxsize
def get_ints():
return map(int, sys.stdin.readline().strip().split())
def get_array():
return list(map(int, sys.stdin.readline().strip().split()))
def input():
return sys.stdin.readline().strip()
mod = 1000000007
for ... | vfc_138840 | {
"difficulty": "medium_hard",
"memory_limit": "256 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1498/C",
"time_limit": "1 second"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n2 3\n2 2\n3 1\n1 3\n",
"output": "4\n3\n1\n2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 1\n1 500\n500 250\n",
"output": "1\n2\n257950823\n",
"type": "stdin_stdout"... |
taco | verifiable_code | https://www.codechef.com/problems/S10E | Solve the following coding problem using the programming language python:
Chef wants to buy a new phone, but he is not willing to spend a lot of money. Instead, he checks the price of his chosen model everyday and waits for the price to drop to an acceptable value. So far, he has observed the price for $N$ days (numbe... | ```python
def get_Min(l, i):
mx = 10000000
for j in range(i - 5, i):
mx = min(mx, l[j])
return mx
t = int(input())
for ni in range(t):
n = int(input())
l = [int(i) for i in input().split()]
c = 1
small = l[0]
for i in range(1, 5):
if l[i] < small:
small = l[i]
c = c + 1
for i in range(5, n):
if l[i... | vfc_138848 | {
"difficulty": "easy",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/S10E",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n7\n375 750 723 662 647 656 619\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Consider car trips in a country where there is no friction. Cars in this country do not have engines. Once a car started to move at a speed, it keeps moving at the same speed. There are acceleration devices on some points on the road, where a ca... | ```python
from collections import defaultdict
from heapq import heappop, heappush
while True:
(n, m) = map(int, input().split())
if n == 0 and m == 0:
break
(s, g) = map(int, input().split())
graph = defaultdict(list)
for _ in range(m):
(x, y, d, c) = map(int, input().split())
graph[x].append((y, d, c))
gr... | vfc_138856 | {
"difficulty": "unknown_difficulty",
"memory_limit": "134.217728 megabytes",
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "1.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 0\n1 2\n5 4\n1 5\n1 2 1 1\n2 3 2 2\n3 4 2 2\n4 5 1 1\n6 6\n1 6\n1 2 2 1\n2 3 2 1\n3 6 2 1\n1 4 2 30\n4 5 3 30\n5 6 2 30\n6 7\n1 6\n1 2 1 30\n2 4 1 30\n3 1 1 30\n3 4 100 30\n4 5 1 30\n5 6 1 30\n6 4 1 30\n0 0",
"output": "unr... | |
taco | verifiable_code | https://www.codechef.com/problems/ALCARR | Solve the following coding problem using the programming language python:
Alice is playing a game with permutations of size N.
She selects a random *permutation* P of size N and a random index i (1≤ i ≤ N);
She keeps incrementing the index i until:
- The next element is greater than the current element (P_{(i+1)} ... | ```python
fact_l = [1]
a_vals = [0]
mod = 10 ** 9 + 7
for t in range(int(input())):
n = int(input())
while n + 1 >= len(fact_l):
fact_l.append(fact_l[len(fact_l) - 1] * len(fact_l) % mod)
a_vals.append((a_vals[len(a_vals) - 1] * len(a_vals) + 1) % mod)
P = (a_vals[n + 1] - a_vals[n] - fact_l[n]) % mod
Q = fact_... | vfc_138864 | {
"difficulty": "very_hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/ALCARR",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1\n2\n3\n",
"output": "1\n250000003\n388888893\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/EQUALMEX | Solve the following coding problem using the programming language python:
The MEX (minimum excluded) of an array is the smallest non-negative integer that does not belong to the array. For instance:
The MEX of [2, 2, 1] is 0 because 0 does not belong to the array.
The MEX of [3, 1, 0, 1] is 2 because 0 and 1 belong t... | ```python
from collections import Counter
t = int(input())
for djhdf in range(t):
n = int(input())
a = list(map(int, input().split()))
x = {i: 0 for i in range(0, max(a) + 1)}
for i in a:
x[i] += 1
ans = 'YES'
for j in x.values():
if j == 0:
break
if j == 1:
ans = 'NO'
break
print(ans)
``` | vfc_138868 | {
"difficulty": "medium",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/EQUALMEX",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n2\n0 0 0 1\n2\n0 0 1 1\n3\n1 3 2 3 3 2\n3\n0 0 1 1 1 2\n",
"output": "NO\nYES\nYES\nNO\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/WITMATH | Solve the following coding problem using the programming language python:
Witua is a little student from the University of Lviv. He enjoys studying math. Witua knows a lot of famous mathematicians like Eratosthenes, Pythagoras, Fermat, Diophantus, Furko, Gauss and so on. However, his favorite one is Euler. The only th... | ```python
def bigmod(x, n, mod):
ans = 1
while n > 0:
if n % 2 == 1:
ans = ans * x % mod
n >>= 1
x = x * x % mod
return ans
def check_composite(n, a, d, s):
x = bigmod(a, d, n)
if x == 1 or x == n - 1:
return False
for r in range(s - 1):
x = x * x % n
if x == 1:
return True
if x == n - 1:
... | vfc_138872 | {
"difficulty": "medium_hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/WITMATH",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n2\n3\n4\n",
"output": "2\n3\n3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n4\n3\n4",
"output": "3\n3\n3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,... |
taco | verifiable_code | https://www.hackerrank.com/challenges/fair-rations/problem | Solve the following coding problem using the programming language python:
You are the benevolent ruler of Rankhacker Castle, and today you're distributing bread. Your subjects are in a line, and some of them already have some loaves. Times are hard and your castle's food stocks are dwindling, so you must distribute ... | ```python
import sys
N = int(input().strip())
B = [int(B_temp) for B_temp in input().strip().split(' ')]
ans = 0
for i in range(len(B) - 1):
if B[i] & 1:
B[i + 1] += 1
ans += 2
if B[-1] & 1:
print('NO')
else:
print(ans)
``` | vfc_138876 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.hackerrank.com/challenges/fair-rations/problem",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n2 3 4 5 6\n",
"output": "4\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1003/C | Solve the following coding problem using the programming language python:
The heat during the last few days has been really intense. Scientists from all over the Berland study how the temperatures and weather change, and they claim that this summer is abnormally hot. But any scientific claim sounds a lot more reasonab... | ```python
import math
import collections
import bisect
def arrPrint(a):
return ' '.join([str(i) for i in a])
def gridPrint(a):
return '\n'.join([' '.join([str(j) for j in a[i]]) for i in range(len(a))])
def isPalindrome(s):
for i in range(len(s) // 2):
if not s[i] == s[-i - 1]:
return False
return True
def... | vfc_138880 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1003/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 3\n3 4 1 2\n",
"output": "2.666666666666667\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
There is a double-track line (up and down are separate lines and pass each other everywhere). There are 11 stations on this line, including the terminal station, and each station is called by the section number shown in the figure.
<image>
Tr... | ```python
while True:
try:
lst = list(map(int, input().split(',')))
v2 = lst.pop()
v1 = lst.pop()
kp = sum(lst) * v1 / (v1 + v2)
l = 0
for (num, i) in enumerate(lst):
l = l + i
if l >= kp:
print(num + 1)
break
except EOFError:
break
``` | vfc_138884 | {
"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": "06,04,1,1,1,1,1,1,1,1,1,1\n1,1,1,1,1,3,3,3,3,3,50,50\n10,10,10,10,10,10,10,10,10,10,50,49",
"output": "2\n7\n6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1,1,1,1,1,1,1,1,1,0,40,60\n1,... | |
taco | verifiable_code | https://codeforces.com/problemset/problem/1174/A | Solve the following coding problem using the programming language python:
You're given an array $a$ of length $2n$. Is it possible to reorder it in such way so that the sum of the first $n$ elements isn't equal to the sum of the last $n$ elements?
-----Input-----
The first line contains an integer $n$ ($1 \le n \le... | ```python
n = int(input())
x = list(map(int, input().split()))
sum1 = 0
sum2 = 0
equal = True
i = 0
while i < 2 * n - 1:
if x[i] != x[i + 1] and equal:
equal = False
if i < n:
sum1 += x[i]
else:
sum2 += x[i]
i += 1
sum2 += x[i]
if equal:
print(-1)
else:
i = n
j = 0
if sum1 == sum2:
while j < n:
if x[... | vfc_138888 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1174/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 2 2 1 3 1\n",
"output": "2 1 3 1 1 2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n1 1\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
taco | verifiable_code | https://codeforces.com/problemset/problem/1651/D | Solve the following coding problem using the programming language python:
You are given $n$ distinct points on a plane. The coordinates of the $i$-th point are $(x_i, y_i)$.
For each point $i$, find the nearest (in terms of Manhattan distance) point with integer coordinates that is not among the given $n$ points. If ... | ```python
import sys
from collections import deque
input = sys.stdin.readline
def solve(n, arr):
included = set(arr)
ans = {}
dq = deque()
for (x, y) in arr:
for (nx, ny) in [(x + 1, y), (x - 1, y), (x, y + 1), (x, y - 1)]:
if (nx, ny) not in included:
ans[x, y] = (nx, ny)
dq.append((x, y))
while dq:... | vfc_138892 | {
"difficulty": "hard",
"memory_limit": "256 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1651/D",
"time_limit": "4 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n2 2\n1 2\n2 1\n3 2\n2 3\n5 5\n",
"output": "1 1\n1 1\n2 0\n3 1\n2 4\n5 4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8\n4 4\n2 4\n2 2\n2 3\n1 4\n4 2\n1 3\n3 3\n",
"output": "4... |
taco | verifiable_code | https://www.codechef.com/problems/DIVSUBS | Solve the following coding problem using the programming language python:
Read problems statements in Mandarin Chinese and Russian.
You are given a multiset of N integers. Please find such a nonempty subset of it that the sum of the subset's elements is divisible by N. Otherwise, state that this subset doesn't exis... | ```python
t = int(input())
for _ in range(t):
N = int(input())
array = list(map(int, input().split()))
sumx = 0
sumxIndex = {}
for i in range(0, N):
sumx = (sumx + array[i]) % N
if sumx == 0:
left = 0
right = i
break
if sumx in sumxIndex.keys():
left = sumxIndex[sumx] + 1
right = i
break
... | vfc_138896 | {
"difficulty": "very_hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/DIVSUBS",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n3\n4 6 10",
"output": "1\n2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n3\n4 6 16",
"output": "1\n2 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
taco | verifiable_code | https://codeforces.com/problemset/problem/242/B | Solve the following coding problem using the programming language python:
A coordinate line has n segments, the i-th segment starts at the position l_{i} and ends at the position r_{i}. We will denote such a segment as [l_{i}, r_{i}].
You have suggested that one of the defined segments covers all others. In other wor... | ```python
num_segment = int(input())
segment_list = []
for i in range(num_segment):
a = input()
a = list(map(int, a.split()))
segment_list.append(a)
min_val = segment_list[0][0]
max_val = segment_list[0][1]
result = -1
for segment in segment_list:
if segment[0] < min_val:
min_val = segment[0]
if segment[1] > max... | vfc_138900 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/242/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 1\n2 2\n3 3\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n1 5\n2 3\n1 10\n7 10\n7 7\n10 10\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
... |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/triplet-family/1 | Solve the following coding problem using the programming language python:
Given an array A of integers. Find three numbers such that sum of two elements equals the third element and return the triplet in a container result, if no such triplet is found return the container as empty.
Input:
First line of input contains ... | ```python
def findTriplet(arr, n):
arr.sort(reverse=True)
for i in range(n - 2):
j = i + 1
k = n - 1
while j < k:
if arr[i] == arr[j] + arr[k]:
return [arr[i], arr[j], arr[k]]
elif arr[i] < arr[j] + arr[k]:
j += 1
else:
k -= 1
return []
``` | vfc_138909 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/triplet-family/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": "findTriplet",
"input": "3\r\n\n5\r\n\n1 2 3 4 5\r\n\n3\r\n\n3 3 3\r\n\n6\r\n\n8 10 16 6 15 25",
"output": "1\r\n\n-1\r\n\n1",
"type": "function_call"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Problem Statement
A magician lives in a country which consists of N islands and M bridges. Some of the bridges are magical bridges, which are created by the magician. Her magic can change all the lengths of the magical bridges to the same non-n... | ```python
from heapq import heappush, heappop
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
(N, M, S1, S2, T) = map(int, readline().split())
if N == 0:
return False
S1 -= 1
S2 -= 1
T -= 1
G = [[] for i in range(N)]
Gx = [[] for i in range(N)]
L = 0
for i in range(M):
(a, b... | vfc_138910 | {
"difficulty": "unknown_difficulty",
"memory_limit": "268.435456 megabytes",
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "8.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 2 2 3 1\n1 2 1\n1 3 2\n4 3 1 4 2\n2 1 4\n2 3 x\n4 3 x\n0 0 0 0 0",
"output": "1\n0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 2 2 3 1\n1 2 1\n1 3 2\n4 3 1 4 2\n2 1 5\n2 3 x\n4 3 x... | |
taco | verifiable_code | https://codeforces.com/problemset/problem/842/D | Solve the following coding problem using the programming language python:
Today at the lesson Vitya learned a very interesting function — mex. Mex of a sequence of numbers is the minimum non-negative number that is not present in the sequence as element. For example, mex([4, 33, 0, 1, 1, 5]) = 2 and mex([1, 2, 3]) = 0... | ```python
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = 'x' in file.mode or 'r' not in file.mode
self.write = self.buffer.write if self.writable else None
def ... | vfc_138914 | {
"difficulty": "hard",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/842/D",
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10 30\n0 0 0 0 0 0 0 0 0 0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n",
"output": "1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n",
... |
taco | verifiable_code | https://codeforces.com/problemset/problem/140/D | Solve the following coding problem using the programming language python:
As Gerald sets the table, Alexander sends the greeting cards, and Sergey and his twins create an army of clone snowmen, Gennady writes a New Year contest.
The New Year contest begins at 18:00 (6.00 P.M.) on December 31 and ends at 6:00 (6.00 A.... | ```python
from bisect import bisect_right
n = int(input())
t = list(map(int, input().split()))
t.sort()
for i in range(1, n):
t[i] += t[i - 1]
i = bisect_right(t, 350)
j = bisect_right(t, 710)
print(j, sum((t[k] for k in range(i, j))) - 350 * (j - i))
``` | vfc_138918 | {
"difficulty": "medium_hard",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/140/D",
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "100\n22 13 1 3 2 18 11 11 40 42 1 3 1 12 3 16 32 4 15 18 7 8 4 6 1 1 19 7 2 17 12 21 2 2 9 8 14 29 9 19 5 5 18 15 9 12 7 13 32 41 27 3 9 30 27 8 12 8 60 1 25 34 3 8 24 4 29 12 1 3 41 19 13 14 47 1 40 16 45 12 25 3 8 29 6 5 2 11 10 ... |
taco | verifiable_code | https://codeforces.com/problemset/problem/1061/A | Solve the following coding problem using the programming language python:
You have unlimited number of coins with values $1, 2, \ldots, n$. You want to select some set of coins having the total value of $S$.
It is allowed to have multiple coins with the same value in the set. What is the minimum number of coins requ... | ```python
import math
def transform(x):
return int(x)
(n, S) = tuple(map(transform, input().split()))
minimum = math.ceil(S / n)
print(minimum)
``` | vfc_138922 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1061/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 11\n",
"output": "3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 16\n",
"output": "3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "14 28\n",... |
taco | verifiable_code | https://codeforces.com/problemset/problem/884/D | Solve the following coding problem using the programming language python:
Ivan has n different boxes. The first of them contains some balls of n different colors.
Ivan wants to play a strange game. He wants to distribute the balls into boxes in such a way that for every i (1 ≤ i ≤ n) i-th box will contain all balls w... | ```python
import heapq
N = int(input())
colors = list(map(int, input().strip().split()))
if N % 2 == 0:
colors.append(0)
penalty = 0
heapq.heapify(colors)
while len(colors) > 2:
a = heapq.heappop(colors)
b = heapq.heappop(colors)
c = heapq.heappop(colors)
heapq.heappush(colors, a + b + c)
penalty += a + b + c
pri... | vfc_138926 | {
"difficulty": "hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/884/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 2 3\n",
"output": "6\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/682/D | Solve the following coding problem using the programming language python:
After returned from forest, Alyona started reading a book. She noticed strings s and t, lengths of which are n and m respectively. As usual, reading bored Alyona and she decided to pay her attention to strings s and t, which she considered very ... | ```python
(n, m, k) = map(int, input().split())
(s, t) = (input(), input())
n += 1
m += 1
p = [i for i in range(n * m - n) if (i + 1) % n]
r = p[::-1]
d = [0] * n * m
for i in p:
if s[i % n] == t[i // n]:
d[i] = d[i - n - 1] + 1
f = d[:]
for y in range(k - 1):
for i in p:
f[i] = max(f[i], f[i - 1], f[i - n])
for... | vfc_138936 | {
"difficulty": "hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/682/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 2 2\nabc\nab\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "9 12 4\nbbaaababb\nabbbabbaaaba\n",
"output": "7\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1680/A | Solve the following coding problem using the programming language python:
An array is beautiful if both of the following two conditions meet:
there are at least $l_1$ and at most $r_1$ elements in the array equal to its minimum;
there are at least $l_2$ and at most $r_2$ elements in the array equal to its maximum.
... | ```python
import sys
input = sys.stdin.readline
for _ in range(int(input())):
(l1, r1, l2, r2) = map(int, input().split())
if max(l1, l2) <= min(r1, r2):
print(max(l1, l2))
else:
print(l1 + l2)
``` | vfc_138940 | {
"difficulty": "easy",
"memory_limit": "512 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1680/A",
"time_limit": "2 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7\n3 5 4 6\n5 8 5 5\n3 3 10 12\n1 5 3 3\n1 1 2 2\n2 2 1 1\n6 6 6 6\n",
"output": "4\n5\n13\n3\n3\n3\n6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n40 40 40 40\n",
"output": "4... |
taco | verifiable_code | https://codeforces.com/problemset/problem/643/A | Solve the following coding problem using the programming language python:
Bear Limak has n colored balls, arranged in one long row. Balls are numbered 1 through n, from left to right. There are n possible colors, also numbered 1 through n. The i-th ball has color t_{i}.
For a fixed interval (set of consecutive elemen... | ```python
import math
import sys
from collections import Counter
def solve():
n = int(input())
T = [int(x) - 1 for x in input().split()]
M = [[0] * n for i in range(n)]
(curmin, ans) = ([0] * n, [0] * n)
for i in range(n):
ans[T[i]] += 1
curmin[i] = T[i]
M[i][T[i]] = 1
for i in range(n):
for j in range(i... | vfc_138944 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/643/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1 2 1 2\n",
"output": "7 3 0 0 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 1 1\n",
"output": "6 0 0 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,... |
taco | verifiable_code | https://codeforces.com/problemset/problem/1491/A | Solve the following coding problem using the programming language python:
You are given an array $a$ consisting of $n$ integers. Initially all elements of $a$ are either $0$ or $1$. You need to process $q$ queries of two kinds:
1 x : Assign to $a_x$ the value $1 - a_x$.
2 k : Print the $k$-th largest value of the ar... | ```python
(cs, ln) = map(int, input().split())
ar = list(map(int, input().split()))
z = ar.count(0)
(o, sol) = (cs - z, [])
while ln:
ln -= 1
(qst, pl) = map(int, input().split())
if qst == 2:
if cs - pl >= z:
sol.append(1)
else:
sol.append(0)
elif ar[pl - 1] == 0:
ar[pl - 1] = 1
o += 1
z -= 1
else... | vfc_138948 | {
"difficulty": "easy",
"memory_limit": "256 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1491/A",
"time_limit": "1 second"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 5\n1 1 0 1 0\n2 3\n1 2\n2 3\n2 1\n2 5\n",
"output": "1\n0\n1\n0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1\n0\n2 1\n",
"output": "0\n",
"type": "stdin_stdout"
},... |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/faulty-wiring-and-bulbs2939/1 | Solve the following coding problem using the programming language python:
N light bulbs are connected by a wire. Each bulb has a switch associated with it, however due to faulty wiring, a switch also changes the state of all the bulbs to the right of current bulb. Given an initial state of all bulbs, find the minimum ... | ```python
class Solution:
def countFlips(self, a, n):
count = 0
for i in range(n):
if a[i] == 1 and count % 2 == 0:
continue
elif a[i] == 0 and count % 2 != 0:
continue
elif a[i] == 1 and count % 2 != 0:
count += 1
elif a[i] == 0 and count % 2 == 0:
count += 1
return count
``` | vfc_138952 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/faulty-wiring-and-bulbs2939/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N=4\r\narr[] = { 0, 0, 0, 0 }",
"output": "1",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Raju loves playing with maths.He is very fond of factorials.Now he is interested in knowing the last five digits n!(nth number factorial).
As he is not very good at programming , so he needs your help.
Your task is to print the last five digits... | ```python
import sys
def factorial(number):
ans = 1
i = 1
while i <= number:
ans *= i
i += 1
return ans
test_cases = int(input())
while test_cases > 0:
number = int(input())
if number >= 25:
print("00000")
else:
number = factorial(number)
digits = []
for i in range(1,6):
digits.append(number % 10)... | vfc_138953 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "101\n500\n501\n502\n503\n504\n505\n506\n507\n508\n509\n510\n511\n512\n513\n514\n515\n516\n517\n518\n519\n520\n521\n522\n523\n524\n525\n526\n527\n528\n529\n530\n531\n532\n533\n534\n535\n536\n537\n538\n539\n540\n541\n542\n543\n544\n5... | |
taco | verifiable_code | https://www.hackerrank.com/challenges/python-eval/problem | Solve the following coding problem using the programming language python:
The eval() expression is a very powerful built-in function of Python. It helps in evaluating an expression. The expression can be a Python statement, or a code object.
For example:
>>> eval("9 + 5")
14
>>> x = 2
>>> eval("x + 3")
5
Here, ... | ```python
string = input()
eval(string)
``` | vfc_138958 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.hackerrank.com/challenges/python-eval/problem",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "print(2 + 3)\n",
"output": "5\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/DIET | Solve the following coding problem using the programming language python:
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well.
Chef decided to go on a diet during the following $N$ days (numbered $1$ through $N$). Part of the diet plan is to eat $K$ grams of protein... | ```python
for joe_mama in range(int(input())):
(n, k) = map(int, input().split())
(i, v) = (0, 0)
l = list(map(int, input().split()))
while i < n and l[i] + v - k >= 0:
v = v + l[i] - k
i += 1
if i == n:
print('YES')
else:
print('NO ', i + 1)
``` | vfc_138962 | {
"difficulty": "easy",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/DIET",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n4 5\n7 3 6 5\n3 4\n3 10 10\n3 4\n8 1 1",
"output": "YES\nNO 1\nNO 3",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.hackerrank.com/challenges/k-balance/problem | Solve the following coding problem using the programming language python:
Your task is to calculate the sum (indicated by S) of all the k-balanced integers between [L, R]. An integer is called k-balanced when either of #1 or #2 below holds true.
The length of the integer <= k
Sum of the first k digits (with no l... | ```python
from itertools import zip_longest
MOD = 1000000007
def n_digit_counts_and_sums(n):
counts = [[1]]
sums = [[0]]
for _ in range(1, n + 1):
prev_counts = counts[-1]
prev_sums = sums[-1]
new_counts = [0 for _ in range(len(prev_counts) + 9)]
new_sums = [0 for _ in range(len(prev_sums) + 9)]
for i in ... | vfc_138971 | {
"difficulty": "medium_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.hackerrank.com/challenges/k-balance/problem",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "9 23 1\n",
"output": "42\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/CZEN2020/problems/NHSPN | Solve the following coding problem using the programming language python:
$Neha$ is given a number $N$. She always looks for special thing , this time she is looking for $Special$ $Number$ and $Partial$ $Special$ $Number$. A $Special$ $Number$ is a number whose product of its digits is equal to number itself i.e. $N ... | ```python
n = int(input())
a = []
b = []
for i in range(1, 1000001):
s = str(i)
p = 1
flag = 0
for e in s:
if e == '1':
flag = 1
p = p * int(e)
if p == n:
if flag != 1:
a.append(i)
else:
b.append(i)
print(len(a), len(b))
``` | vfc_138975 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/CZEN2020/problems/NHSPN",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n",
"output": "1 20\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/GEO1 | Solve the following coding problem using the programming language python:
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
You are given a convex polygon with N sides. You have to answer Q queries. The i^{th} query is described by two integers v_{i}, t_{i}. In this query,... | ```python
import sys
from math import atan2, pi, hypot, tan
input = sys.stdin.readline
def polygon_area(x, y, n):
area = 0
j = n - 1
for i in range(n):
area += (x[j] + x[i]) * (y[j] - y[i])
j = i
return abs(area / 2)
def get_angle(i, x, y, n):
p1 = i
p2 = (i + 1) % n
p3 = (i - 1) % n
angle = atan2(y[p3] -... | vfc_138979 | {
"difficulty": "very_hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/GEO1",
"time_limit": "1.5 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n4 1\n1 1\n2 1\n2 2\n1 2\n1 1\n3 2\n1 1\n2 1\n1 2\n1 1\n2 3",
"output": "9.0000000\n9.7426406\n230.8086578",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Statement: Security is the major factor, which is prohibiting hackers letting into bank accounts online. But still, we have breached 2nd level security of SBIS bank and a final level is kept for you. Your task is simple, we are receiving an inte... | ```python
if __name__=='__main__':
T = int(input())
for i in range(T):
mystr = input()
st = ''
for i in mystr:
if i == '2':
st += 'cde'
elif i == '7':
st += 'acf'
elif i == '6':
st += 'b3'
elif i == '9':
st += 'c6a'
print(st)
``` | vfc_138983 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "20\n77098906505852940\n23695632789598785\n83179477858357140\n38835312821902340\n20531402854248883\n79217919497750700\n97700573573820292\n61817719996906820\n76683795335702609\n12297584302723408\n37055948958732184\n94997957651503400\... | |
taco | verifiable_code | Solve the following coding problem using the programming language python:
You are given a cost matrix of dimensions m X n. The problem of finding the minimal path from top-left corner to some cell in the matrix is well studied. Here, we are gonna add a little twist.
To refresh your memory, the total cost of a path is... | ```python
'''
2
2 2
1 2
3 4
2
1 1 1
1 1 2
2 2
1 2
## 4
3
1 1 1
1 1 2
1 0 1
'''
from collections import deque
for _ in range(eval(input())):
R, C = list(map(int, input().split()))
li = []
for _ in range(R):
li.append(input().split())
res = []
for i in range(R):
t = []
for j in range(C):
t.append([]... | vfc_138987 | {
"difficulty": "hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n40 40\n44 1 81 17 -2 14 30 11 ## -6 67 10 ## -1 18 96 53 55 95 76 34 35 18 74 3 31 95 92 51 11 -1 -1 72 80 23 37 9 29 62 ##\n3 46 85 69 59 64 ## 77 45 3 15 -3 75 -4 0 14 50 62 7 55 39 21 94 51 -2 -9 -6 96 66 14 91 -9 25 94 84 45... | |
taco | verifiable_code | Solve the following coding problem using the programming language python:
A: Hokkaido University Easy
Note
Please note that the problem settings are the same as problem B, except for the constraints.
story
Homura-chan, who passed Hokkaido University and is excited about the beginning of a new life. But in front of... | ```python
(H, W) = map(int, input().split())
lst = [list(input()) for _ in range(H)]
ans = 0
for ia in range(H):
for ja in range(W):
for ib in range(H):
for jb in range(W):
if lst[ia][ja] == 'B' and lst[ib][jb] == 'B':
tmp = abs(ia - ib) + abs(ja - jb)
ans = max(ans, tmp)
print(ans)
``` | vfc_138992 | {
"difficulty": "unknown_difficulty",
"memory_limit": "268.435456 megabytes",
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 3\nA.B\n..B\n.BB",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 3\nB.B\n..B\n-BB",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": nul... | |
taco | verifiable_code | https://codeforces.com/problemset/problem/1204/B | Solve the following coding problem using the programming language python:
Mislove had an array $a_1$, $a_2$, $\cdots$, $a_n$ of $n$ positive integers, but he has lost it. He only remembers the following facts about it:
The number of different numbers in the array is not less than $l$ and is not greater than $r$;
... | ```python
import math
max1 = 0
(n, l, r) = map(int, input().split())
min1 = 1 * (n - l + 1) + 2 * (2 ** (l - 1) - 1)
s = int(math.log(n, 2)) + 1
for i in range(r):
max1 += 2 ** i
for j in range(n - r):
max1 += 2 ** i
print(min1, max1)
``` | vfc_139000 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1204/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 2 2\n",
"output": "5 7\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 1 5\n",
"output": "5 31\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input":... |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/right-angled-triangles4729/1 | Solve the following coding problem using the programming language python:
Given three integers a, b and c. The task is to check if it is possible to make right angled triangle with sides of length a, b and c.
Example 1:
Input:
a = 3, b = 4, c = 5
Output:
Yes
Explanation:
We can form a right angled triangle
with side... | ```python
import math
class Solution:
def rightAngTri(self, a, b, c):
if a * a + b * b == c * c or a * a + c * c == b * b or b * b + c * c == a * a:
return 'Yes'
return 'No'
``` | vfc_139005 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/right-angled-triangles4729/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "a = 3, b = 4, c = 5",
"output": "Yes",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "a = 2, b = 5, c = 8",
"output": "No",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1143/D | Solve the following coding problem using the programming language python:
Recently a Golden Circle of Beetlovers was found in Byteland. It is a circle route going through n ⋅ k cities. The cities are numerated from 1 to n ⋅ k, the distance between the neighboring cities is exactly 1 km.
Sergey does not like beetles, ... | ```python
from math import gcd
(n, k) = map(int, input().split())
(a, b) = map(int, input().split())
lll = [a + b, abs(a - b), k - a - b, k - abs(a - b)]
(x, y) = (n * k, 0)
for ll in lll:
for i in range(n):
l = ll + i * k
c = n * k // gcd(l, n * k)
if c < x:
x = c
if c > y:
y = c
print(x, y)
``` | vfc_139007 | {
"difficulty": "medium_hard",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1143/D",
"time_limit": "1.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "100000 99737\n34242 43667\n",
"output": "99737 9973700000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 99990\n3 7\n",
"output": "9999 499950\n",
"type": "stdin_stdout"
... |
taco | verifiable_code | https://codeforces.com/problemset/problem/1515/B | Solve the following coding problem using the programming language python:
Phoenix is playing with a new puzzle, which consists of $n$ identical puzzle pieces. Each puzzle piece is a right isosceles triangle as shown below.
A puzzle piece
The goal of the puzzle is to create a square using the $n$ pieces. He is allowe... | ```python
for _ in range(int(input())):
n = int(input())
if n % 2:
print('NO')
continue
h = n / 2
if h ** 0.5 == int(h ** 0.5):
print('YES')
continue
if n % 4:
print('NO')
continue
g = n / 4
if g ** 0.5 == int(g ** 0.5):
print('YES')
continue
else:
print('NO')
continue
``` | vfc_139011 | {
"difficulty": "easy",
"memory_limit": "256 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1515/B",
"time_limit": "2 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n2\n4\n6\n",
"output": "YES\nYES\nNO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n999939200\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": ... |
taco | verifiable_code | https://codeforces.com/problemset/problem/455/A | Solve the following coding problem using the programming language python:
Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it.
Given a sequence a consisting of n integers. The player can make several steps. In a si... | ```python
n = int(input())
a = list(map(int, input().split()))
a.sort()
b = list()
cur = a[0]
k = 1
for i in range(1, n):
if a[i - 1] == a[i]:
k += 1
else:
b.append((cur, k))
cur = a[i]
k = 1
b.append((cur, k))
n1 = len(b)
dp = [0] * n1
dp[0] = b[0][0] * b[0][1]
maxx = b[0][0] * b[0][1]
for i in range(1, n1):... | vfc_139015 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/455/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n1 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 2 3\n",
"output": "4\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/WNDR | Solve the following coding problem using the programming language python:
Nadaca is a country with N$N$ cities. These cities are numbered 1$1$ through N$N$ and connected by M$M$ bidirectional roads. Each city can be reached from every other city using these roads.
Initially, Ryan is in city 1$1$. At each of the follow... | ```python
T = int(input())
for _ in range(T):
(N, M, K) = [int(x) for x in input().split()]
UV = [[int(x) for x in input().split()] for _ in range(M)]
Q = int(input())
AB = [[int(x) for x in input().split()] for _ in range(Q)]
X = [[i] for i in range(N)]
for (u, v) in UV:
X[u - 1] += [v - 1]
X[v - 1] += [u - ... | vfc_139019 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/WNDR",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n4 3 3\n1 2\n1 3\n1 4\n0\n4 3 3\n1 2\n1 3\n1 4\n1\n2 2\n4 3 3\n1 2\n1 3\n1 4\n1\n2 1\n",
"output": "28\n4\n6\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/sum-of-all-sub-sequences-of-a-number3437/1 | Solve the following coding problem using the programming language python:
Given a number as integer s, find the sum of all the elements present in all possible subsequences of s.
Example 1:
Input: S = "123"
Output: 24
Explanation: {1}, {2}, {3}, {1, 2}, {2, 3}
{1, 3}, {1, 2, 3} are all possible sub-
sequences
Examp... | ```python
class Solution:
def subsequenceSum(self, s):
su = 0
op = 2 ** (len(s) - 1)
for i in s:
su += int(i) * op
return su
``` | vfc_139023 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/sum-of-all-sub-sequences-of-a-number3437/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "S = \"123\"",
"output": "24",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "S = \"5\"",
"output": "5",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/520/A | Solve the following coding problem using the programming language python:
A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices.
You are given a st... | ```python
n = int(input())
s = str(input())
if len(set(s.lower())) == 26:
print('YES')
else:
print('NO')
``` | vfc_139025 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/520/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "12\ntoosmallword\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "35\nTheQuickBrownFoxJumpsOverTheLazyDog\n",
"output": "YES\n",
"type": "stdin_stdout"
},
... |
taco | verifiable_code | https://codeforces.com/problemset/problem/316/D3 | Solve the following coding problem using the programming language python:
Smart Beaver decided to be not only smart, but also a healthy beaver! And so he began to attend physical education classes at school X. In this school, physical education has a very creative teacher. One of his favorite warm-up exercises is thro... | ```python
m = 1000000007
n = int(input())
a = map(int, input().split())
(t1, t2) = (0, 0)
for i in a:
if i == 1:
t1 += 1
else:
t2 += 1
a = [1, 2]
for i in range(3, t1 + 1):
a = a[::-1]
a[1] = (a[0] + (i - 1) * a[1]) % m
if not t1 or t1 == 1:
a[1] = 1
for i in range(t1 + 1, n + 1):
a[1] = a[1] * i % m
print(a[... | vfc_139030 | {
"difficulty": "very_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/316/D3",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1 2 2 1 2\n",
"output": "120\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8\n1 2 2 1 2 1 1 2\n",
"output": "16800\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/PBK22020/problems/ITGUY27 | Solve the following coding problem using the programming language python:
The chef was busy in solving algebra, he found some interesting results, that there are many numbers which can be formed by sum of some numbers which are prime. Chef wrote those numbers in dairy. Cheffina came and saw what the chef was doing. Ch... | ```python
from math import sqrt
def isprime(n):
if n % 2 == 0 and n > 2 or n == 1:
return 0
else:
s = int(sqrt(n)) + 1
for i in range(3, s, 2):
if n % i == 0:
return 0
return 1
def find(N, K):
if N < 2 * K:
return 0
if K == 1:
return isprime(N)
if K == 2:
if N % 2 == 0:
return 1
return ... | vfc_139034 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/PBK22020/problems/ITGUY27",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n12 2\n11 2\n",
"output": "1\n0\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/SMALLXOR | Solve the following coding problem using the programming language python:
Chef has an array A of length N and an integer X.
In one operation, Chef does the following:
Find the smallest element in the current array. Let this be S.
Next, pick any one index i such that A_{i} = S
Finally, replace A_{i} with A_{i} \oplus ... | ```python
for _ in range(int(input())):
(N, X, Y) = list(map(int, input().split()))
A = sorted(list(map(int, input().split())))
xd = 0
v = A[0] ^ X
for i in range(N):
if A[i] > v:
break
if A[i] ^ X <= A[i]:
break
v = min(v, A[i] ^ X)
A[i] = A[i] ^ X
xd += 1
if xd == Y:
break
Y -= xd
A = sort... | vfc_139038 | {
"difficulty": "medium_hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/SMALLXOR",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 6 99\n9\n3 7 44\n1 2 3\n5 20 6\n5 10 15 20 25\n",
"output": "15 \n3 5 6 \n5 20 25 27 30 \n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/849/A | Solve the following coding problem using the programming language python:
Where do odds begin, and where do they end? Where does hope emerge, and will they ever break?
Given an integer sequence a_1, a_2, ..., a_{n} of length n. Decide whether it is possible to divide it into an odd number of non-empty subsegments, th... | ```python
n = int(input())
A = list(map(int, input().split()))
if len(A) % 2 == 1:
if A[0] % 2 == 1 and A[len(A) - 1] % 2 == 1:
print('Yes')
exit()
else:
print('No')
exit()
if A[0] % 2 == 0 or A[len(A) - 1] % 2 == 0:
print('No')
exit()
print('No')
``` | vfc_139042 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/849/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 3 5\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n1 0 1 5 1\n",
"output": "Yes\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Stannis borathean is attacking kings landing from three gates.To defend the city Tyrion again comes up with a fair solution. Tyrion has N soldier troops with given strengths. Tyrion wants to divide army into 3 sets such that the sum of strengths... | ```python
n=int(input())
arr=[int(input()) for e in range(n)]
arr2=[1]*n
s_v=[999999,999999,9999999]
def update(a,b):
global s_v
temp=[0,0,0]
for e in range(len(a)):
temp[b[e]]+=a[e]
if temp[0] >= temp[1] and temp[1] >= temp[2] and temp[0] < s_v[0]:
s_v=temp
def find(a,b,curr=0):
if curr==len(a):
updat... | vfc_139046 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "12\n23\n6\n57\n35\n33\n15\n26\n12\n9\n61\n42\n27\n",
"output": "191\n",
"type": "stdin_stdout"
}
]
} | |
taco | verifiable_code | https://codeforces.com/problemset/problem/1027/G | Solve the following coding problem using the programming language python:
The campus has $m$ rooms numbered from $0$ to $m - 1$. Also the $x$-mouse lives in the campus. The $x$-mouse is not just a mouse: each second $x$-mouse moves from room $i$ to the room $i \cdot x \mod{m}$ (in fact, it teleports from one room to a... | ```python
from math import gcd
def powmod(a, b, m):
a %= m
r = 1
while b:
if b & 1:
r = r * a % m
a = a * a % m
b >>= 1
return r
def f(n):
r = []
if n & 1 == 0:
e = 0
while n & 1 == 0:
n >>= 1
e += 1
yield (2, e)
p = 3
while n > 1:
if p * p > n:
p = n
if n % p:
p += 2
continu... | vfc_139050 | {
"difficulty": "very_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1027/G",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 3\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7 2\n",... |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/greatest-of-three-numbers2520/1 | Solve the following coding problem using the programming language python:
Given 3 numbers A, B and C. Find the greatest number among them.
Example 1:
Input: A = 10, B = 3, C = 2
Output: 10
Explanation:
10 is the greatest among the three.
Example 2:
Input: A = -4, B = -3, C = -2
Output: -2
Explanation:
-2 is the greate... | ```python
class Solution:
def greatestOfThree(self, A, B, C):
m = max(A, B, C)
return m
``` | vfc_139055 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/greatest-of-three-numbers2520/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "A = 10, B = 3, C = 2",
"output": "10",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/SLUSH | Solve the following coding problem using the programming language python:
Chef is operating a slush machine. The machine produces slush drinks with $M$ flavors (numbered $1$ through $M$); for each valid $i$, the maximum number of drinks with flavour $i$ the machine can produce is $C_i$.
Chef expects $N$ customers to c... | ```python
for _ in range(int(input())):
(n, m) = map(int, input().split())
s = 0
s1 = 0
ans = []
j = 0
q = []
q1 = []
p = list(map(int, input().split()))
for i in p:
s += i
if s >= n:
while n:
(d, f, b) = map(int, input().split())
if p[d - 1] > 0:
s1 += f
p[d - 1] -= 1
j += 1
ans.app... | vfc_139056 | {
"difficulty": "medium_hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/SLUSH",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n5 3\n1 2 3\n2 6 3\n2 10 7\n2 50 3\n1 10 5\n1 7 4\n",
"output": "33\n2 2 3 1 3\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
You decide to develop a game with your friends. The title of the game is "Battle Town". This is a game with the theme of urban warfare with tanks. As the first step in game development, we decided to develop the following prototype.
In this pro... | ```python
def move(act, y, x, direction):
if x < 0 or x == M or y < 0 or (y == H):
return s_map
if act == 'U':
if y == 0:
s_map[y][x] = '^'
elif s_map[y - 1][x] == '.':
(s_map[y][x], s_map[y - 1][x]) = ('.', '^')
else:
s_map[y][x] = '^'
elif act == 'D':
if y == H - 1:
s_map[y][x] = 'v'
elif s... | vfc_139060 | {
"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": "4\n4 6\n*.*..*\n*.....\n...-..\n^.*#..\n10\nSRSSRRUSSR\n2 2\n<.\n..\n12\nDDSRRSUUSLLS\n3 5\n>-#**\n.-*#*\n.-**#\n15\nSSSDRSSSDRSSSUU\n5 5\nv****\n*****\n*****\n*****\n*****\n44\nSSSSDDRSDRSRDSULUURSSSSRRRRDSSSSDDLSDLSDLSSD",
... | |
taco | verifiable_code | https://www.hackerrank.com/challenges/letter-islands/problem | Solve the following coding problem using the programming language python:
You are given string $\boldsymbol{\mathrm{~s~}}$ and number $\boldsymbol{\mbox{k}}$.
Consider a substring $\boldsymbol{p}$ of string $\boldsymbol{\mathrm{~S~}}$. For each position of string $\boldsymbol{\mathrm{~S~}}$ mark it if there is an oc... | ```python
from collections import defaultdict
class LetterIslands:
def __init__(self):
self.s = 0
self.k = 0
self.n = 0
self.result = 0
def get_indice(self):
cache = defaultdict(list)
for (idx, let) in enumerate(self.s):
cache[let].append(idx)
for (key, val) in cache.items():
l = len(val)
if... | vfc_139068 | {
"difficulty": "hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.hackerrank.com/challenges/letter-islands/problem",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "abaab\n2\n",
"output": "3\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.hackerrank.com/challenges/hackerrank-number/problem | Solve the following coding problem using the programming language python:
A Hackerrank number is a magic number that can be used to get sudo permissions on the site. We are going to generate a hackerrank number from two integers A & B. Each number has two parts to it - the left (L) & the right side (R).
For eg: for... | ```python
import math
def lcm(a, b):
return a * b // math.gcd(a, b)
[a, b] = list(map(int, input().strip().split(' ')))
curr = b
leftmult = 10
while curr > 0:
curr //= 10
leftmult *= 10
[a, b] = sorted([a, b])
if a == 1 and b == 1:
print(0)
else:
themax = a + b
for dig in range(30, 0, -1):
if (a >> dig) % 2 ==... | vfc_139081 | {
"difficulty": "hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.hackerrank.com/challenges/hackerrank-number/problem",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 4\n",
"output": "14502\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1584/E | Solve the following coding problem using the programming language python:
Bob decided to take a break from calculus homework and designed a game for himself.
The game is played on a sequence of piles of stones, which can be described with a sequence of integers $s_1, \ldots, s_k$, where $s_i$ is the number of stones ... | ```python
import sys
input = sys.stdin.readline
from collections import deque
def process(a, n):
b = [0] * n
b[0] = a[0]
for i in range(1, n):
b[i] = a[i] - b[i - 1]
return b
def check(a, b, n):
c = deque([])
c.append([0, 1])
d = deque([])
count = 0
for i in range(n):
if i % 2 == 0:
while c and c[-1][... | vfc_139089 | {
"difficulty": "hard",
"memory_limit": "256 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1584/E",
"time_limit": "2 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n2\n2 2\n3\n1 2 3\n4\n1 1 1 1\n4\n1 2 2 1\n4\n1 2 1 2\n8\n1 2 1 2 1 2 1 2\n",
"output": "1\n0\n4\n2\n1\n3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "9\n1\n0\n1\n1000000000\n8\n1 2 1... |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/anagram-palindrome4720/1 | Solve the following coding problem using the programming language python:
Given a string S, Check if characters of the given string can be rearranged to form a palindrome.
Note: You have to return 1 if it is possible to convert the given string into palindrome else return 0.
Example 1:
Input:
S = "geeksogeeks"
Output... | ```python
class Solution:
def isPossible(self, S):
m = {}
for i in S:
if i in m.keys():
m[i] += 1
else:
m[i] = 1
odd = 0
for key in m:
if m[key] % 2 == 1:
odd += 1
if odd > 1:
return 0
return 1
``` | vfc_139098 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/anagram-palindrome4720/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "S = \"geeksogeeks\"",
"output": "Yes",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "S = \"geeksforgeeks\"",
"output": "No",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1540/C1 | Solve the following coding problem using the programming language python:
This is the easy version of the problem. The only difference is that in this version q = 1. You can make hacks only if both versions of the problem are solved.
There is a process that takes place on arrays a and b of length n and length n-1 res... | ```python
def putin():
return map(int, input().split())
def sol():
n = int(input())
C = list(putin())
B = list(putin())
q = int(input())
x = int(input())
min_arr = [x]
min_part_sums = [x]
part_sums = [C[0]]
for i in range(1, n):
part_sums.append(part_sums[-1] + C[i])
for elem in B:
min_arr.append(min_ar... | vfc_139099 | {
"difficulty": "very_hard",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1540/C1",
"time_limit": "5.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "100\n95 54 23 27 51 58 94 34 29 95 53 53 8 5 64 32 17 62 14 37 26 95 27 85 94 37 85 72 88 69 43 9 60 3 48 26 81 48 89 56 34 28 2 63 26 6 13 19 99 41 70 24 92 41 9 73 52 42 34 98 16 82 7 81 28 80 18 33 90 69 19 13 51 96 8 21 86 32 9... |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Blackjack is a type of card game played in casinos, where the game is played using cards with numbers from 1 to 13. The score of each card is decided as follows.
* 1 is 1 point or 11 points
* From 2 to 9, the score is as written.
* 10 points fr... | ```python
while True:
inp = input()
if inp == '0':
break
inp = inp.replace('11', '10')
inp = inp.replace('12', '10')
inp = inp.replace('13', '10')
cards = tuple(map(int, inp.split()))
ans = sum(cards)
for i in range(cards.count(1)):
if sum(cards) + 10 * (i + 1) > 21:
break
elif ans < sum(cards) + 10 * ... | vfc_139103 | {
"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\n7 7 7\n7 7 8\n12 1\n10 1 2\n0",
"output": "11\n21\n0\n21\n13\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n7 7 7\n7 7 8\n10 1\n10 1 1\n0",
"output": "11\n21\n0\n21\n12\n",
... | |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/triangle-pattern-1662286302/1 | Solve the following coding problem using the programming language python:
Ram is very fond of patterns. Once, his teacher gave him a pattern to solve. He gave Ram an integer n and asked him to build a pattern.
Help Ram build a pattern.
Example 1:
Input: 5
Output:
E
E D
E D C
E D C B
E D C B A
Example 2:
Input: 3
O... | ```python
class Solution:
def printTriangle(self, N):
for i in range(N):
for j in range(i + 1):
print(chr(65 + (N - j - 1)), end=' ')
print('')
``` | vfc_139107 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/triangle-pattern-1662286302/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5",
"output": "E\nE D\nE D C\nE D C B\nE D C B A",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1331/F | Solve the following coding problem using the programming language python:
-----Input-----
The input consists of a single string of uppercase letters A-Z. The length of the string is between 1 and 10 characters, inclusive.
-----Output-----
Output "YES" or "NO".
-----Examples-----
Input
GENIUS
Output
YES
Input
D... | ```python
def r(c):
return ord(c) - ord('A')
def kek():
x = input()
if len(x) <= 2:
print('YES')
return
(a, b) = (r(x[0]), r(x[1]))
for i in range(2, len(x)):
c = r(x[i])
if (a + b) % 26 != c:
print('NO')
return
(a, b) = (b, c)
print('YES')
kek()
``` | vfc_139109 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1331/F",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "GENIUS\n",
"output": "",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/SUBMIMX | Solve the following coding problem using the programming language python:
It's your birthday today! So, you ask your dad to buy a brand new bicycle. But your dad knows you are weak in math. Hence he gives you the following task. If you solve it, he will purchase the bicycle you want! The task is:
You are given a bin... | ```python
for _ in range(int(input())):
(n, m) = map(int, input().split())
z = n - m
if m + 1 >= z:
print(z)
else:
div = z // (m + 1)
rem = z % (m + 1)
s = rem * (div + 1) * (div + 2) // 2 + (m + 1 - rem) * div * (div + 1) // 2
print(s)
``` | vfc_139117 | {
"difficulty": "medium_hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/SUBMIMX",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n3 1\n7 2",
"output": "2\n7",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/39/G | Solve the following coding problem using the programming language python:
Petya wrote a programme on C++ that calculated a very interesting function f(n). Petya ran the program with a certain value of n and went to the kitchen to have some tea. The history has no records concerning how long the program had been workin... | ```python
import re, sys, functools
def cut_modulo(x):
y = x % 32768
if y < 0:
y += 32768
return y
class berland_cpp_int:
def __init__(self, x):
self.value = cut_modulo(int(x))
def __add__(self, x):
return berland_cpp_int(cut_modulo(self.value + x.value))
def __sub__(self, x):
return berland_cpp_int(... | vfc_139121 | {
"difficulty": "very_hard",
"memory_limit": "64.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/39/G",
"time_limit": "5.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "15\nint f(int n){if(n > 1)return f(n-2)/f(n-1)+15;if(n==0)return 0;if(n==1)return 1;}\n",
"output": "32767",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "32763\nint f(int n){if (n < 1025) r... |
taco | verifiable_code | https://codeforces.com/problemset/problem/760/D | Solve the following coding problem using the programming language python:
A new innovative ticketing systems for public transport is introduced in Bytesburg. Now there is a single travel card for all transport. To make a trip a passenger scan his card and then he is charged according to the fare.
The fare is construc... | ```python
n = int(input())
a = [0]
for i in range(n):
x = int(input())
a.append(x)
dp = [0] * (n + 1)
dp[0] = 0
p90 = 1
p1440 = 1
for i in range(1, n + 1):
dp[i] = dp[i - 1] + 20
while a[p90] + 90 <= a[i]:
p90 = p90 + 1
dp[i] = min(dp[i], dp[p90 - 1] + 50)
while a[p1440] + 1440 <= a[i]:
p1440 = p1440 + 1
dp[... | vfc_139125 | {
"difficulty": "medium_hard",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/760/D",
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n0\n",
"output": "20\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8\n0\n2\n51\n63\n69\n75\n80\n90\n",
"output": "20\n20\n10\n0\n0\n0\n0\n20\n",
"type": "stdin_stdout"
... |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/most-frequent-word-in-an-array-of-strings3528/1 | Solve the following coding problem using the programming language python:
Given an array arr containing N words consisting of lowercase characters. Your task is to find the most frequent word in the array. If multiple words have same frequency, then print the word whose first occurence occurs last in the array as comp... | ```python
class Solution:
def mostFrequentWord(self, arr, n):
k = {}
l = []
for i in arr:
if i not in k:
k[i] = 1
l.append(i)
else:
k[i] += 1
mm = -1
for i in k:
if k[i] > mm:
mm = k[i]
l = l[::-1]
for i in l:
if k[i] == mm:
return i
``` | vfc_139134 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/most-frequent-word-in-an-array-of-strings3528/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N = 3\narr[] = {geeks,for,geeks}",
"output": "geeks",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "N = 2\narr[] = {hello,world}",
"output": "world",
"type": "stdin_stdout"
}... |
taco | verifiable_code | https://codeforces.com/problemset/problem/112/A | Solve the following coding problem using the programming language python:
Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings lexicographically. The letters' case does n... | ```python
a = input()
b = input()
A = a.lower()
B = b.lower()
if A == B:
print(0)
elif A > B:
print(1)
elif A < B:
print(-1)
``` | vfc_139135 | {
"difficulty": "easy",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/112/A",
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "kigPrWNTOUNDBskAfefjhHYZNYdnfZWuXWzHiBxFQryBbAkPtenFwWvCSTYGpzOntUNzNUhxRWjKmicTwLwJAnbAxj\nkigpRWntOUNdBsKaFEFjhhYZnYDNfzWuXwZhibxFQRybbakPteNfwwvcStyGPzoNTunznuHXrWjKMIctWLWJANBAxJ\n",
"output": "0\n",
"type": "stdin_... |
taco | verifiable_code | https://codeforces.com/problemset/problem/1398/B | Solve the following coding problem using the programming language python:
Alice and Bob play a game. They have a binary string $s$ (a string such that each character in it is either $0$ or $1$). Alice moves first, then Bob, then Alice again, and so on.
During their move, the player can choose any number (not less tha... | ```python
t = int(input())
for _ in range(t):
s = input()
n = len(s)
count = [0] * n
poss = list()
ans = 0
if s[0] == '0':
count[0] = 0
else:
count[0] = 1
for i in range(1, n):
if s[i] == '1':
count[i] = 1 + count[i - 1]
for i in range(n - 1):
if count[i] != count[i + 1] - 1:
poss.append(count[i]... | vfc_139139 | {
"difficulty": "easy",
"memory_limit": "256 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1398/B",
"time_limit": "2 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n01111001\n0000\n111111\n101010101\n011011110111\n",
"output": "4\n0\n6\n3\n6\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/413/C | Solve the following coding problem using the programming language python:
'Jeopardy!' is an intellectual game where players answer questions and earn points. Company Q conducts a simplified 'Jeopardy!' tournament among the best IT companies. By a lucky coincidence, the old rivals made it to the finals: company R1 and ... | ```python
from collections import deque as de
import math
from math import sqrt as sq
from math import floor as fl
from math import ceil as ce
from sys import stdin, stdout
import re
from collections import Counter as cnt
from functools import reduce
from itertools import groupby as gb
from bisect import bisect_left as... | vfc_139144 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/413/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 1\n1 3 7 5\n3\n",
"output": "18\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 2\n10 3 8\n2 3\n",
"output": "40\n",
"type": "stdin_stdout"
},
{
"fn_name": nu... |
taco | verifiable_code | https://codeforces.com/problemset/problem/1003/F | Solve the following coding problem using the programming language python:
You are given a text consisting of $n$ space-separated words. There is exactly one space character between any pair of adjacent words. There are no spaces before the first word and no spaces after the last word. The length of text is the number ... | ```python
import sys
input = sys.stdin.readline
n = int(input())
s = input()
a = list(s.split())
eq = [[0 for i in range(n)] for j in range(n)]
dp = [[0 for i in range(n)] for j in range(n)]
for i in range(n):
eq[i][i] = 1
for j in range(0, i):
if a[i] == a[j]:
eq[i][j] += 1
eq[j][i] += 1
for i in range(n - 1... | vfc_139148 | {
"difficulty": "hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1003/F",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\nto be or not to be\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\na ab a a b ab a a b c\n",
"output": "13\n",
"type": "stdin_stdout"
},
{
... |
taco | verifiable_code | https://codeforces.com/problemset/problem/1490/F | Solve the following coding problem using the programming language python:
Polycarp was gifted an array $a$ of length $n$. Polycarp considers an array beautiful if there exists a number $C$, such that each number in the array occurs either zero or $C$ times. Polycarp wants to remove some elements from the array $a$ to ... | ```python
import math
import collections
def read_list() -> list:
return [int(i) for i in input().strip().split()]
def read_num() -> int:
return int(input().strip())
t = read_num()
while t > 0:
t -= 1
n = read_num()
arr = read_list()
cnt = collections.Counter(arr)
appear_times_cnt = collections.Counter(cnt.val... | vfc_139152 | {
"difficulty": "medium",
"memory_limit": "256 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1490/F",
"time_limit": "2 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n6\n1 3 2 1 4 2\n4\n100 100 4 100\n8\n1 2 3 3 3 2 6 6\n",
"output": "2\n1\n2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n36\n1 2 2 3 3 11 11 4 4 5 5 5 6 6 6 6 7 7 7 7 8 8 8 8 9 9 ... |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/avl-tree-deletion/1 | Solve the following coding problem using the programming language python:
Given a AVL tree and N values to be deleted from the tree. Write a function to delete a given value from the tree.
Example 1:
Tree =
4
/ \
2 6
/ \ / \
1 3 5 7
N = 4
Values to be deleted = {4,1,3,6}
Input:... | ```python
def getHeight(root):
if root is None:
return 0
return root.height
def rightRotate(disbalancedNode):
newRoot = disbalancedNode.left
disbalancedNode.left = disbalancedNode.left.right
newRoot.right = disbalancedNode
disbalancedNode.height = 1 + max(getHeight(disbalancedNode.left), getHeight(disbalancedN... | vfc_139156 | {
"difficulty": "medium_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/avl-tree-deletion/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "Value to be deleted = 4",
"output": " 5\\n / \\\\n 2 6\\n / \\ \\\\n 1 3 7",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1430/D | Solve the following coding problem using the programming language python:
You have a string $s$ consisting of $n$ characters. Each character is either 0 or 1.
You can perform operations on the string. Each operation consists of two steps: select an integer $i$ from $1$ to the length of the string $s$, then delete th... | ```python
for t in range(int(input())):
n = int(input())
s = input()
if n < 3:
print(1)
else:
a = []
b = []
c = 1
j = 0
for i in range(1, n):
if s[i] == s[i - 1]:
c += 1
else:
a.append(c)
if c > 1:
b.append(j)
c = 1
j += 1
a.append(c)
if c > 1:
b.append(j)
la = le... | vfc_139158 | {
"difficulty": "medium_hard",
"memory_limit": "256 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1430/D",
"time_limit": "2 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n6\n111010\n1\n0\n1\n1\n2\n11\n6\n101010\n",
"output": "3\n1\n1\n1\n3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n6\n111010\n1\n1\n1\n1\n2\n11\n6\n101010\n",
"output": "3\n1... |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Draw a rectangle which has a height of H cm and a width of W cm. Draw a 1-cm square by single '#'.
Constraints
* 1 ≤ H ≤ 300
* 1 ≤ W ≤ 300
Input
The input consists of multiple datasets. Each dataset consists of two integers H and W separated... | ```python
while True:
(H, W) = map(int, input().split())
if H == 0 and W == 0:
exit()
for i in range(H):
print('#' * W)
print()
``` | vfc_139162 | {
"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": "3 4\n5 6\n2 3\n0 0",
"output": "####\n####\n####\n\n######\n######\n######\n######\n######\n\n###\n###\n\n",
"type": "stdin_stdout"
}
]
} | |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/even-occurring-elements4332/1 | Solve the following coding problem using the programming language python:
Given an array Arr of N integers that contains odd number of occurrences for all numbers except for a few elements which are present even number of times. Find the elements which have even occurrences in the array.
Example 1:
Input:
N = 11
Arr[]... | ```python
from collections import Counter
class Solution:
def repeatingEven(self, arr, n):
if len(set(arr)) == n:
return [-1]
a = Counter(arr)
r = [key for (key, value) in a.items() if value % 2 == 0]
r.sort()
if len(r) != 0:
return r
else:
return [-1]
``` | vfc_139166 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/even-occurring-elements4332/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N = 11\r\nArr[] = {9, 12, 23, 10, 12, 12, \r\n15, 23, 14, 12, 15}",
"output": "12 15 23",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/LUCKY5 | Solve the following coding problem using the programming language python:
Chef loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Chef has a positive intege... | ```python
for _ in range(int(input())):
n = input().strip()
cnt = 0
for i in n:
if i not in '47':
cnt += 1
print(cnt)
``` | vfc_139171 | {
"difficulty": "medium",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/LUCKY5",
"time_limit": "1.75 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n25\n46\n99\n\n\n",
"output": "2\n1\n2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n2\n46\n99",
"output": "1\n1\n2\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/NOV12/problems/LUCKY9 | Solve the following coding problem using the programming language python:
Chef has the string s of length n consisted of digits 4 and 7.
The string s is called balanced
if there exits such integer x (1 ≤ x ≤ n) that the number of digits 4 in substring s[1; x) is equal to the number of digits 7 in substring s(x; n],
wh... | ```python
from math import factorial
def Ncr(n, r):
if r < 0:
return 0
return factorial(n) / (factorial(n - r) * factorial(r))
def solve(m, n):
modulo = 10 ** 9 + 7
if m == n:
return (Ncr(2 * n - 1, n - 1) + Ncr(2 * n - 2, n - 2)) % modulo
elif m > n:
return (Ncr(m + n, n) - Ncr(m + n - 2, n - 1)) % modulo... | vfc_139175 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/NOV12/problems/LUCKY9",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n47\n4477\n\n\n",
"output": "1\n4\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/COOLGUYS | Solve the following coding problem using the programming language python:
Given an integer N. Integers A and B are chosen randomly in the range [1..N]. Calculate the probability that the Greatest Common Divisor(GCD) of A and B equals to B.
-----Input-----
The first line of the input contains an integer T denoting the... | ```python
import math
for t in range(int(input())):
n = int(input())
ans = 0
x = math.floor(math.sqrt(n))
i = 1
while i <= x:
ans += n // i
i += 1
ans *= 2
ans -= x ** 2
num = int(ans)
den = n * n
g = math.gcd(num, den)
print('%d/%d' % (num // g, den // g))
``` | vfc_139179 | {
"difficulty": "medium_hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/COOLGUYS",
"time_limit": "3 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1\n2\n3\n",
"output": "1/1\n3/4\n5/9\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1\n2\n3",
"output": "1/1\n3/4\n5/9",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Today Oz is playing with his game-board. He has N coins of type-1 and M coins of type-2. Also the game-board has N squares of type-1 and M squares of type-2. In this game Oz must place one coin into each square. After placing all coins Oz will g... | ```python
'''
# Read input from stdin and provide input before running code'''
t = input()
p=[]
#print 'Hi, %s.' % t
for i in range(int(t)):
x = input()
p = x.split(" ");
n = int(p[0]);
m = int(p[1]);
a = int(p[2]);
b = int(p[3]);
c = int(p[4]);
sum1 = n*a+m*b;
if(n>m):
sum2 = 2*m*c+(n-m)*a;
else:
sum2 =... | vfc_139183 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "100\n10000040 10018466 -3666 -3501 9169\n10015723 10011477 -643 -3039 -5537\n10005704 10028144 -6720 6827 -39\n10000490 10002994 1942 -5173 -4564\n10032390 10014603 -6098 -9847 -9708\n10012381 10017420 8716 9718 9895\n10005446 1002... | |
taco | verifiable_code | Solve the following coding problem using the programming language python:
G: Tree
problem
Given a tree consisting of N vertices. Each vertex of the tree is numbered from 1 to N. Of the N-1 edges, the i \ (= 1, 2, ..., N-1) edge connects the vertex u_i and the vertex v_i.
Write a program to find the number of K non-... | ```python
import sys
def getpar(Edge, p):
N = len(Edge)
par = [0] * N
par[0] = -1
par[p] - 1
stack = [p]
visited = set([p])
while stack:
vn = stack.pop()
for vf in Edge[vn]:
if vf in visited:
continue
visited.add(vf)
par[vf] = vn
stack.append(vf)
return par
def topological_sort_tree(E, r):... | vfc_139187 | {
"difficulty": "unknown_difficulty",
"memory_limit": "1073.741824 megabytes",
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "3.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 4\n1 2\n1 3",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 2\n1 2\n2 3",
"output": "5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"... | |
taco | verifiable_code | https://codeforces.com/problemset/problem/1611/A | Solve the following coding problem using the programming language python:
Polycarp has an integer $n$ that doesn't contain the digit 0. He can do the following operation with his number several (possibly zero) times:
Reverse the prefix of length $l$ (in other words, $l$ leftmost digits) of $n$. So, the leftmost digit... | ```python
import sys
def solve(n, string):
if int(string[n - 1]) % 2 == 0:
print(0)
return
elif int(string[0]) % 2 == 0:
print(1)
return
else:
for i in range(1, n - 1):
if int(string[i]) % 2 == 0:
print(2)
return
print(-1)
return
def main():
test_case = int(sys.stdin.readline())
for tc i... | vfc_139191 | {
"difficulty": "easy",
"memory_limit": "256 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1611/A",
"time_limit": "1 second"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n3876\n387\n4489\n3\n",
"output": "0\n2\n1\n-1\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/length-of-longest-subarray0440/1 | Solve the following coding problem using the programming language python:
Given an array A[] of size N, return length of the longest subarray of non- negative integers.
Note: Subarray here means a continuous part of the array.
Example 1:
Input :
N = 9
A[] = {2, 3, 4, -1, -2, 1, 5, 6, 3}
Output :
4
Explanation :
Th... | ```python
def longestSubarry(A, N):
A.append(-1)
curr = 0
ans = 0
for x in A:
if x <= 0:
curr = 0
else:
curr += 1
ans = max(curr, ans)
return ans
``` | vfc_139195 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/length-of-longest-subarray0440/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": "longestSubarry",
"input": "N = 9\nA[] = {2, 3, 4, -1, -2, 1, 5, 6, 3}",
"output": "4",
"type": "function_call"
},
{
"fn_name": "longestSubarry",
"input": "N = 10\nA[] = {1, 0, 0, 1, -1, -1, 0, 0, 1, 0}",
"out... |
taco | verifiable_code | https://codeforces.com/problemset/problem/1468/M | Solve the following coding problem using the programming language python:
You are given n sets of integers. The i-th set contains k_i integers.
Two sets are called similar if they share at least two common elements, i. e. there exist two integers x and y such that x ≠ y, and they both belong to each of the two sets.
... | ```python
def solve(n, debug=False):
global curr
global seen
global last
big = []
small = []
for i in range(1, 1 + n):
l = list(map(int, input().split()))
if l[0] > 600:
big.append((i, l[1:]))
else:
small.append((i, l[1:]))
s1 = len(big)
s2 = len(small)
if debug:
print(s1, s2)
return ''
for (s... | vfc_139196 | {
"difficulty": "hard",
"memory_limit": "512.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1468/M",
"time_limit": "1.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7\n2\n2 1 2\n2 2 1\n3\n4 4 5 6 7\n3 1 2 3\n3 2 3 4\n3\n3 1 2 3\n3 2 3 4\n3 3 4 5\n2\n3 10 20 30\n2 40 50\n4\n2 500 100\n2 500 100\n2 500 100\n2 499 100\n2\n3 1 3 2\n2 1 4\n2\n2 1 5\n2 3 2\n",
"output": "1 2 \n2 3 \n1 2 \n-1\n... |
taco | verifiable_code | https://codeforces.com/problemset/problem/1158/A | Solve the following coding problem using the programming language python:
$n$ boys and $m$ girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from $1$ to $n$ and all girls are numbered with integers from $1$ to $m$. For all $1 \leq i... | ```python
import sys
import math
import collections
from pprint import pprint as pp
mod = 1000000007
MAX = 10 ** 10
def vector(size, val=0):
vec = [val for i in range(size)]
return vec
def matrix(rowNum, colNum, val=0):
mat = []
for i in range(rowNum):
collumn = [val for j in range(colNum)]
mat.append(collumn... | vfc_139200 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1158/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 2\n1 2 1\n3 4\n",
"output": "12",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 2\n0 1\n1 0\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Tim likes Math. He likes it so much that he always brings his tablets with him and reads math e-books everywhere, even during parties.
Tim found an interesting exercise in one of the e-books he is reading. But you want him to join the party, so... | ```python
#__author__ = 'guluuu3'
from math import sqrt
def factors(n):
return [(i,n/i) for i in range(1,int(sqrt(n))+1) if not n%i]
t=eval(input())
while(t):
d,p=list(map(int,input().split()))
flag=False
for i,j in factors(p):
if j-i==d:
flag=True
break
if (flag==True):
print(4 if j!=i else 2)
else:
... | vfc_139205 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2000\n317110 317111\n316190 632384\n1 12\n281788 563580\n1 6\n2 0\n749907 749908\n170484 340972\n309894 929691\n418799 0\n727178 727179\n111560 0\n200172 600525\n1 12\n850176 0\n10612 833820\n835142 0\n870825 0\n242298 242299\n4936... | |
taco | verifiable_code | https://codeforces.com/problemset/problem/325/B | Solve the following coding problem using the programming language python:
Daniel is organizing a football tournament. He has come up with the following tournament format: In the first several (possibly zero) stages, while the number of teams is even, they split in pairs and play one game for each pair. At each stage... | ```python
3
y = int(input())
s = set()
e = 1
for k in range(0, 70):
b = 2 * e - 3
c = -2 * y
d = b * b - 4 * c
if d >= 0:
L = 0
R = d
while True:
M = (L + R + 1) // 2
if L == R:
break
MM = M * M
if MM > d:
R = M - 1
else:
L = M
if M * M == d:
x = -b + M
if x > 0 and x % 2 ==... | vfc_139209 | {
"difficulty": "medium_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/325/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n",
"output": "3\n4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "25\n",
"output": "20\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n",
... |
taco | verifiable_code | https://codeforces.com/problemset/problem/626/B | Solve the following coding problem using the programming language python:
Catherine has a deck of n cards, each of which is either red, green, or blue. As long as there are at least two cards left, she can do one of two actions: take any two (not necessarily adjacent) cards with different colors and exchange them fo... | ```python
from collections import namedtuple
def __starting_point():
n = int(input())
cards = input()
r = 0
g = 0
b = 0
for card in cards:
if card == 'R':
r += 1
elif card == 'G':
g += 1
elif card == 'B':
b += 1
colornum = 0
if r:
colornum += 1
if g:
colornum += 1
if b:
colornum += 1
re... | vfc_139218 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/626/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\nRB\n",
"output": "G\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\nGRG\n",
"output": "BR\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.