source stringclasses 4
values | task_type stringclasses 1
value | in_source_id stringlengths 0 138 | problem stringlengths 219 13.2k | gold_standard_solution stringlengths 0 413k | problem_id stringlengths 5 10 | metadata dict | verification_info dict |
|---|---|---|---|---|---|---|---|
taco | verifiable_code | https://codeforces.com/problemset/problem/1013/B | Solve the following coding problem using the programming language python:
There is an array with n elements a_1, a_2, ..., a_{n} and the number x.
In one operation you can select some i (1 ≤ i ≤ n) and replace element a_{i} with a_{i} & x, where & denotes the bitwise and operation.
You want the array to have at leas... | ```python
(n, x) = [int(i) for i in input().split()]
nums = [int(i) for i in input().split()]
nums1 = nums[:]
nums = set(nums)
if len(set(nums)) < n:
print(0)
exit(0)
for i in range(len(nums)):
if nums1[i] & x in nums and nums1[i] != nums1[i] & x:
print(1)
exit(0)
for i in range(len(nums)):
nums1[i] = nums1[i] ... | vfc_134280 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1013/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 3\n1 2 3 7\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 228\n1 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"... |
taco | verifiable_code | https://www.codechef.com/IARCSJUD/problems/ENDCORR | Solve the following coding problem using the programming language python:
A despotic king decided that his kingdom needed to be rid of corruption and disparity. He called his prime minister and ordered that all corrupt citizens be put to death. Moreover, he wanted this done quickly.
The wily prime minister realised th... | ```python
(n, m) = map(int, input().split())
l = []
leng = 0
for i in range(n + m):
w = int(input())
if w == -1:
cm = 0
mi = 0
for j in range(leng):
if l[j] > cm:
cm = l[j]
mi = j
print(cm)
l[mi] = -1
else:
l.append(w)
leng += 1
``` | vfc_134296 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/IARCSJUD/problems/ENDCORR",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10 3\n1\n3\n7\n6\n-1\n5\n-1\n18\n9\n11\n2\n-1\n4\n",
"output": "7\n6\n18\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/SUMPARITY | Solve the following coding problem using the programming language python:
Vedant has a hidden array of N elements. Given the [bitwise AND] of all elements of the array, determine whether the total sum of the elements is odd, even or cannot be determined.
------ Input Format ------
- The first line of each input con... | ```python
for _ in range(int(input())):
(n, a) = map(int, input().split())
if a % 2:
if n % 2:
print('Odd')
else:
print('Even')
elif n == 1:
print('Even')
else:
print('Impossible')
``` | vfc_134300 | {
"difficulty": "medium",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/SUMPARITY",
"time_limit": "0.5 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 11\n1 2\n74120341 829182732",
"output": "Odd\nEven\nImpossible",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/gambling-stark3304/1 | Solve the following coding problem using the programming language python:
Given a number N, you have to say if it is adjacent to two prime numbers. Two numbers are adjacent if the absolute difference between them is 1.
Example 1:
Input: N = 4
Output: Y
Explaination: The adjacent numbers 3 and
5 are both prime.
Eaxmpl... | ```python
class Solution:
def is_prime(self, n):
if n <= 1:
return 0
for i in range(2, n):
if n % i == 0:
return 0
return 1
def primeAdjacent(self, N):
ans1 = self.is_prime(N + 1)
ans2 = self.is_prime(N - 1)
return ans1 and ans2
``` | vfc_134304 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/gambling-stark3304/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N = 4",
"output": "Y",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7",
"output": "N",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/MINIL | Solve the following coding problem using the programming language python:
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well.
You are given a grid with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Each cell of this grid contains e... | ```python
t = int(input())
for _ in range(t):
(n, m) = map(int, input().split())
grid = []
ans1 = 0
ans2 = 0
for i in range(n):
grid.append(input())
if not (n % 2 == 1 and m % 2 == 1):
for i in range(n):
for j in range(m):
if (i + j) % 2 == 0:
cmp = '*'
else:
cmp = '.'
if grid[i][j] !... | vfc_134305 | {
"difficulty": "medium_hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/MINIL",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n2 2\n..\n*.\n2 4\n*..*\n*.*.",
"output": "1\n2",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/CHEFTWOS | Solve the following coding problem using the programming language python:
Chef's loves his dog so much! Once his dog created two strings a and b each of length n consisting of digits 1 and 2, and even a problem about them!
Chef's Dog will tell by barking if a string x (also containing only digits 1 and 2 and with leng... | ```python
def fun(a):
n = len(a)
i = 0
b = []
while i < n:
c = 0
while i < n - 1 and a[i] == a[i + 1]:
c += 1
i += 1
b.append([a[i], c + 1])
i += 1
return b
def tatti(h):
n = len(h)
i = 0
b = []
while i < n:
c = 0
while i < n - 1 and h[i][0] == h[i + 1][0]:
c += 1
i += 1
b.append([h[... | vfc_134309 | {
"difficulty": "hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/CHEFTWOS",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n1111\n2211\n222\n111\n",
"output": "8\n0\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/ARRANGE | Solve the following coding problem using the programming language python:
The Chef has prepared the appetizers in the shapes of letters to spell a special message for the guests. There are n appetizers numbered from 0 to n-1 such that if the appetizers are arrayed in this order, they will display the message. The Chef... | ```python
def get_binary(num, bits):
ans = []
for i in range(bits):
ans.append('0')
i = bits - 1
while i >= 0:
ans[i] = str(num % 2)
num //= 2
i -= 1
return ''.join(ans)
for t in range(int(input())):
temp = list(input().split())
k = int(temp[0])
s = temp[1]
ans = []
for i in range(2 ** k):
ans.appen... | vfc_134313 | {
"difficulty": "medium",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/ARRANGE",
"time_limit": "1.43314 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n2 chef\n4 enjoyourapplepie",
"output": "cehf\neayejpuinpopolre",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/SGARDEN | Solve the following coding problem using the programming language python:
Read problems statements in Mandarin Chinese and Russian.
All bandits are afraid of Sheriff. Sheriff constantly fights crime, but when bandits lay low, he gets bored and starts to entertain himself.
This time Sheriff gathered all the bandits ... | ```python
import fractions
test = int(input())
for i in range(test):
n = int(input())
array = [int(x) for x in input().split()]
array.insert(0, 0)
count = []
seen = {}
toSee = 0
for i in range(1, n + 1):
j = 1
x = array[i]
if x not in seen:
seen[x] = None
while x != i:
x = array[x]
seen[x] = ... | vfc_134321 | {
"difficulty": "medium_hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/SGARDEN",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n3\n1 2 3\n5\n2 3 1 5 4",
"output": "1\n6",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n2\n1 2 3\n5\n2 3 1 5 4",
"output": "1\n6\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1585/C | Solve the following coding problem using the programming language python:
A total of $n$ depots are located on a number line. Depot $i$ lies at the point $x_i$ for $1 \le i \le n$.
You are a salesman with $n$ bags of goods, attempting to deliver one bag to each of the $n$ depots. You and the $n$ bags are initially at... | ```python
import sys
input = sys.stdin.readline
def positive_dist(x, n, k, last):
cur = n - 1
total = 0
while cur >= 0 and x[cur] > 0:
total += 2 * x[cur]
cur -= k
if last and x[-1] > 0:
total -= x[-1]
return total
def negative_dist(x, n, k, last):
cur = 0
total = 0
while cur < n and x[cur] < 0:
total... | vfc_134325 | {
"difficulty": "easy",
"memory_limit": "256 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1585/C",
"time_limit": "1 second"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n5 1\n1 2 3 4 5\n9 3\n-5 -10 -15 6 5 8 3 7 4\n5 3\n2 2 3 3 3\n4 2\n1000000000 1000000000 1000000000 1000000000\n",
"output": "25\n41\n7\n3000000000\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1272/B | Solve the following coding problem using the programming language python:
Recently you have bought a snow walking robot and brought it home. Suppose your home is a cell $(0, 0)$ on an infinite grid.
You also have the sequence of instructions of this robot. It is written as the string $s$ consisting of characters 'L',... | ```python
t = int(input())
while t:
s = input()
(l, r, u, d) = (0, 0, 0, 0)
for i in s:
if i == 'U':
u += 1
if i == 'D':
d += 1
if i == 'R':
r += 1
if i == 'L':
l += 1
mlr = min(l, r)
mud = min(u, d)
l = mlr
r = mlr
u = mud
d = mud
if mud != 0 and mlr == 0:
print(2)
print('UD')
elif m... | vfc_134333 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1272/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\nLRU\nDURLDRUDRULRDURDDL\nLRUDDLRUDRUL\nLLLLRRRR\nURDUR\nLLL\n",
"output": "2\nLR\n14\nLLLUUUURRRDDDD\n12\nLLLUUURRRDDD\n2\nLR\n2\nUD\n0\n\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": ... |
taco | verifiable_code | https://www.codechef.com/problems/MGCRNK | Solve the following coding problem using the programming language python:
Everybody loves magic, especially magicians who compete for glory on the Byteland Magic Tournament. Magician Cyael is one such magician.
Cyael has been having some issues with her last performances and today she’ll have to perform for an audienc... | ```python
import math
import sys
import string
t = int(input())
while t:
n = int(input())
arr = [0] * n
arr[0] = [int(x) for x in input().split()]
for i in range(1, n):
arr[0][i] += arr[0][i - 1]
for i in range(1, n):
arr[i] = [int(x) for x in input().split()]
arr[i][0] += arr[i - 1][0]
for j in range(1, n... | vfc_134337 | {
"difficulty": "medium",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/MGCRNK",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n2\n0 -4\n8 0\n2\n0 -45\n-3 0",
"output": "8.000000\nBad Judges",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n2\n0 -4\n8 0\n2\n0 -45\n-2 0",
"output": "8.0000000\nBad Judges\n... |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/largest-number-in-one-swap1520/1 | Solve the following coding problem using the programming language python:
Given a non-negative number N in the form of a string.Find the largest number that can be formed by swapping two characters at most once.
Example 1:
Input:
N=768
Output:
867
Explanation:
Swapping the 1st and 3rd
characters(7 and 8 respectivel... | ```python
class Solution:
def LargestSwap(self, S):
n = len(S)
arr = list(S)
right = [0] * n
right[n - 1] = n - 1
rmax = n - 1
for i in range(n - 2, -1, -1):
right[i] = rmax
if arr[i] > arr[rmax]:
rmax = i
for i in range(0, n):
if arr[right[i]] > arr[i]:
(arr[right[i]], arr[i]) = (arr[i... | vfc_134341 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/largest-number-in-one-swap1520/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N=768",
"output": "867",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "N=333",
"output": "333",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/261/B | Solve the following coding problem using the programming language python:
Maxim has opened his own restaurant! The restaurant has got a huge table, the table's length is p meters.
Maxim has got a dinner party tonight, n guests will come to him. Let's index the guests of Maxim's restaurant from 1 to n. Maxim knows the... | ```python
n = int(input())
a = list(map(int, input().split()))
p = int(input())
fact = [1]
for i in range(1, 51):
fact.append(fact[-1] * i)
if sum(a) <= p:
print(n)
else:
dp = [[0] * 56 for _ in range(56)]
dp[0][0] = 1
for i in range(n):
for j in range(n, -1, -1):
for k in range(p):
if a[i] + k <= p:
... | vfc_134342 | {
"difficulty": "hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/261/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 2 3\n3\n",
"output": "1.3333333333\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "9\n2 2 2 2 2 2 2 1 2\n9\n",
"output": "4.5555555556\n",
"type": "stdin_stdout"
},
... |
taco | verifiable_code | https://codeforces.com/problemset/problem/26/E | Solve the following coding problem using the programming language python:
You are given the following concurrent program. There are N processes and the i-th process has the following pseudocode:
repeat ni times
yi := y
y := yi + 1
end repeat
Here y is a shared variable.... | ```python
import sys
from array import array
def input():
return sys.stdin.buffer.readline().decode('utf-8')
(n, w) = map(int, input().split())
a = [0] + list(map(int, input().split()))
total = sum(a)
def ng():
print('No')
exit()
def ok(a):
print('Yes')
print(*a)
exit()
if w < 1 or total < w:
ng()
if n == 1:
... | vfc_134346 | {
"difficulty": "very_hard",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/26/E",
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 1\n2 3 4 5 6\n",
"output": "No\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/TRUESCORE | Solve the following coding problem using the programming language python:
Chef is watching a football match. The current score is A:B, that is, team 1 has scored A goals and team 2 has scored B goals. Chef wonders if it is possible for the score to become C:D at a later point in the game (i.e. team 1 has scored C goal... | ```python
for _ in range(int(input())):
(a, b) = map(int, input().split())
(c, d) = map(int, input().split())
if c >= a and d >= b:
print('POSSIBLE')
else:
print('IMPOSSIBLE')
``` | vfc_134350 | {
"difficulty": "easy",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/TRUESCORE",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 5\n3 5\n3 4\n2 6\n2 2\n2 2\n",
"output": "POSSIBLE\nIMPOSSIBLE\nPOSSIBLE\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/180/E | Solve the following coding problem using the programming language python:
Let's imagine that you're playing the following simple computer game. The screen displays n lined-up cubes. Each cube is painted one of m colors. You are allowed to delete not more than k cubes (that do not necessarily go one after another). Aft... | ```python
import math
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
mod = 10 ** 9 + 7
mod1 = 998244353
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno(... | vfc_134354 | {
"difficulty": "medium_hard",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/180/E",
"time_limit": "1.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "30 5 6\n4 2 2 1 3 4 2 3 2 4 3 1 1 4 4 3 5 1 4 5 5 1 2 2 1 2 4 4 1 2\n",
"output": "4",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "20 6 3\n4 1 2 6 3 3 2 5 2 5 2 1 1 4 1 2 2 1 1 4\n",
... |
taco | verifiable_code | https://codeforces.com/problemset/problem/1158/C | Solve the following coding problem using the programming language python:
Vasya has written some permutation $p_1, p_2, \ldots, p_n$ of integers from $1$ to $n$, so for all $1 \leq i \leq n$ it is true that $1 \leq p_i \leq n$ and all $p_1, p_2, \ldots, p_n$ are different. After that he wrote $n$ numbers $next_1, next... | ```python
import sys
input = sys.stdin.readline
T = int(input())
for _ in range(T):
n = int(input())
l = list(map(int, input().split()))
stack = []
out = [-1] * n
curr = 0
works = True
for i in range(n):
while stack and stack[-1][0] == i:
(_, j) = stack.pop()
curr += 1
out[j] = curr
nex = l[i] - 1
... | vfc_134358 | {
"difficulty": "hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1158/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n3\n2 3 4\n2\n3 3\n3\n-1 -1 -1\n3\n3 4 -1\n1\n2\n4\n4 -1 4 5\n",
"output": "1 2 3 \n2 1 \n1 2 3 \n-1\n1 \n3 1 2 4 \n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/modified-fibonacci4449/1 | Solve the following coding problem using the programming language python:
Given 4 integers A, B, C and N, find the value of F(N) such that
F(1) = A + B
F(2) = B + C
F(N) = F(N-1) - F(N-2), for N > 2.
Example 1:
Input: N = 2, A = 2, B = 3, C = 4
Output: 7
Explaination: F(2) = B+C = 3+4 = 7
Example 2:
Input: N = 3... | ```python
class Solution:
def modifiedFib(self, N, A, B, C):
(a, b, c) = (A + B, B + C, C - A)
n = N % 6
if n == 1:
return a % 1000000007
if n == 2:
return b % 1000000007
if n == 3:
return c % 1000000007
if n == 4:
return -a % 1000000007
if n == 5:
return -b % 1000000007
if n == 0:
r... | vfc_134368 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/modified-fibonacci4449/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N = 2, A = 2, B = 3, C = 4",
"output": "7",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "N = 3, A = 2, B = 3, C = 4",
"output": "2",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/CHEFHOME | Solve the following coding problem using the programming language python:
Our hardworking chef is bored of sleeping in his restaurants. He has decided to settle down. The first thing he must do is to find a suitable location to build a palatial home.
Think of the city as a two-dimensional grid. There are N restaur... | ```python
def findHouseLocations():
t = int(input())
for j in range(t):
n = int(input())
x = []
y = []
for i in range(n):
m = list(map(int, input().split()))
x.append(m[0])
y.append(m[1])
x.sort()
y.sort()
x1 = x[n // 2] - x[(n - 1) // 2] + 1
y1 = y[n // 2] - y[(n - 1) // 2] + 1
print(x1 * ... | vfc_134369 | {
"difficulty": "medium_hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/CHEFHOME",
"time_limit": "0.352542 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n5\n0 0\n-1 0\n1 0\n0 1\n0 -1\n5\n31 11\n30 -41\n20 14\n25 18\n25 38\n2\n0 0\n1 1",
"output": "1\n1\n4",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n5\n0 0\n-1 0\n1 0\n0 1\n0 -1\n5\n3... |
taco | verifiable_code | https://codeforces.com/problemset/problem/1419/D2 | Solve the following coding problem using the programming language python:
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem.
Today is Sage's birthday, and sh... | ```python
n = int(input())
arr = list(map(int, input().split()))
flag = 1
if n <= 2:
print(0)
print(*arr)
flag = 0
arr.sort(reverse=True)
final = ['0']
pair = 0
if flag == 1:
k = 0
j = 1
if n % 2 != 0:
temp1 = arr[:n // 2 + 1]
temp2 = arr[n // 2 + 1:]
else:
temp1 = arr[:n // 2]
temp2 = arr[n // 2:]
rem... | vfc_134373 | {
"difficulty": "medium",
"memory_limit": "256 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1419/D2",
"time_limit": "1 second"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7\n1 3 2 2 4 5 4\n",
"output": "3\n3 1 4 2 4 2 5 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n1\n",
"output": "0\n1 ",
"type": "stdin_stdout"
},
{
"fn_name":... |
taco | verifiable_code | https://codeforces.com/problemset/problem/812/E | Solve the following coding problem using the programming language python:
Sagheer is playing a game with his best friend Soliman. He brought a tree with n nodes numbered from 1 to n and rooted at node 1. The i-th node has a_{i} apples. This tree has a special property: the lengths of all paths from the root to any lea... | ```python
def coloring(i, ancestors, color):
while i != 0 and color[ancestors[i - 1]] is None:
color[ancestors[i - 1]] = not color[i]
i = ancestors[i - 1]
def main():
n = int(input())
a = list(map(int, input().split()))
ancestors = list(map(lambda x: int(x) - 1, input().split()))
descendants = [[] for i in ra... | vfc_134377 | {
"difficulty": "hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/812/E",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n2 2 3\n1 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 2 3\n1 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
taco | verifiable_code | https://codeforces.com/problemset/problem/687/A | Solve the following coding problem using the programming language python:
Recently, Pari and Arya did some research about NP-Hard problems and they found the minimum vertex cover problem very interesting.
Suppose the graph G is given. Subset A of its vertices is called a vertex cover of this graph, if for each edge u... | ```python
from collections import defaultdict
(n, m) = list(map(int, input().strip().split()))
g = defaultdict(list)
for _ in range(m):
(u, v) = list(map(int, input().strip().split()))
g[u].append(v)
g[v].append(u)
v1 = []
v2 = []
mark = [-1] * (n + 1)
def bfs(start):
q = []
q.append(start)
mark[start] = 1
v2.a... | vfc_134381 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/687/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 2\n1 2\n2 3\n",
"output": "1\n2 \n2\n1 3 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 3\n1 2\n2 3\n1 3\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"... |
taco | verifiable_code | https://www.hackerrank.com/challenges/rirb/problem | Solve the following coding problem using the programming language python:
Given an integer range [A,B],
What’s the probability to get a 1-bit if we first randomly choose a number x in the range and then randomly choose a bit from x?
What’s the expected number of bit 1s if we randomly choose a number x in the rang... | ```python
from functools import lru_cache
@lru_cache(maxsize=None)
def s1(n):
if n < 3:
return n
if n % 2 == 0:
return s1(n // 2) + s1(n // 2 - 1) + n // 2
return 2 * s1(n // 2) + n // 2 + 1
def s2(n):
res = 0
for i in range(1, 40):
if 2 ** i > n:
return res + (s1(n) - s1(2 ** (i - 1) - 1)) / i
res +=... | vfc_134389 | {
"difficulty": "medium_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.hackerrank.com/challenges/rirb/problem",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n2 4\n",
"output": "0.61111 1.33333\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/MIXCOLOR | Solve the following coding problem using the programming language python:
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Chef likes to mix colors a lot. Recently, she was gifted N colors A_{1}, A_{2}, ..., A_{N} by her friend.
Chef wants to make the values of all her colors pairwise d... | ```python
for _ in range(int(input())):
n = int(input())
arr = list(map(int, input().split()))
print(n - len(set(arr)))
``` | vfc_134393 | {
"difficulty": "medium",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/MIXCOLOR",
"time_limit": "2 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n3\n1 2 3\n3\n2 1 2",
"output": "0\n1",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/CHEFAPPS | Solve the following coding problem using the programming language python:
Chef's phone has a total storage of S MB. Also, Chef has 2 apps already installed on his phone which occupy X MB and Y MB respectively.
He wants to install another app on his phone whose memory requirement is Z MB. For this, he might have to d... | ```python
t = int(input())
for i in range(t):
(s, x, y, z) = map(int, input().split())
a = x + y
if s - a >= z:
print(0)
elif s - a < z and s - x >= z or s - y >= z:
print(1)
else:
print(2)
``` | vfc_134401 | {
"difficulty": "easy",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/CHEFAPPS",
"time_limit": "0.5 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n10 1 2 3\n9 4 5 1\n15 5 10 15\n100 20 30 75\n",
"output": "0\n1\n2\n1\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Navi is a counter strike pro. He always say how good he is at counter strike. After being tired of Navi, his friends decided to test his skills at shooting. They put M targets on a X-Y plane, each target is denoted by (X, Y) where X is x-coordi... | ```python
'''
# Read input from stdin and provide input before running code
name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
test = int(input())
for i in range(test):
mat = input()
[n,m,d] = list(map(int, mat.split()))
shoot_loc = []
for j in range(n):
loc = input()
[x,y] = list(map(int,... | vfc_134410 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n3 3 2\n1 1\n2 2\n3 3\n-1 -1\n-2 -2\n-3 -3\n4 5 100\n840 958\n271 550\n779 32\n192 949\n538 624\n358 462\n24 115\n303 207\n771 984\n1000 1000 5909\n30223 7665\n-30214 25609\n18159 -10334\n-29404 -24432\n11322 27193\n-28500 24109\... | |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/distinct-occurrences/1 | Solve the following coding problem using the programming language python:
Given two strings S and T of length n and m respectively. Find count of distinct occurrences of T in S as a sub-sequence.
Example 1:
Input:
S = "banana" , T = "ban"
Output: 3
Explanation: There are 3 sub-sequences:
[ban], [ba n], [b an].
Exam... | ```python
class Solution:
def sequenceCount(self, arr1, arr2):
n = len(arr1)
m = len(arr2)
if n < m:
return 0
dp = [[0] * (m + 1) for _ in range(n + 1)]
for i in range(n + 1):
dp[i][0] = 1
for i in range(1, n + 1):
for j in range(1, m + 1):
p1 = dp[i - 1][j]
p2 = 0
if arr1[i - 1] == a... | vfc_134418 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/distinct-occurrences/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "S = \"banana\" , T = \"ban\"",
"output": "3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "S = \"geeksforgeeks\" , T = \"ge\"",
"output": "6",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Compute A + B.
Constraints
* -1000 ≤ A, B ≤ 1000
Input
The input will consist of a series of pairs of integers A and B separated by a space, one pair of integers per line. The input will be terminated by EOF.
Output
For each pair of input ... | ```python
ans = ''
while True:
try:
info = input()
except:
break
if ans != '':
ans += '\n'
info_2 = info.split()
ans += str(int(info_2[0]) + int(info_2[1]))
print(ans)
``` | vfc_134420 | {
"difficulty": "unknown_difficulty",
"memory_limit": "134.217728 megabytes",
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "1.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 2\n10 5\n101 20",
"output": "3\n15\n121\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 2\n10 4\n101 20",
"output": "3\n14\n121\n",
"type": "stdin_stdout"
},
{
... | |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/sub-array-sum-divisible-by-k2617/1 | Solve the following coding problem using the programming language python:
You are given an array A of N positive and/or negative integers and a value K. The task is to find the count of all sub-arrays whose sum is divisible by K.
Example 1:
Input: N = 6, K = 5
arr[] = {4, 5, 0, -2, -3, 1}
Output: 7
Explanation:... | ```python
class Solution:
def subCount(self, arr, n, k):
hashmap = {}
currSum = 0
for i in range(n):
currSum += arr[i]
arr[i] = currSum
arr[i] %= k
hashmap[arr[i]] = hashmap.get(arr[i], 0) + 1
ans = 0
for x in hashmap.keys():
y = hashmap[x]
if x == 0:
ans += y * (y + 1) // 2
else:
... | vfc_134424 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/sub-array-sum-divisible-by-k2617/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N = 6, K = 5\n arr[] = {4, 5, 0, -2, -3, 1}",
"output": "7",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "N = 6, K = 2\n arr[] = {2, 2, 2, 2, 2, 2}",
"output": "21",
... |
taco | verifiable_code | https://www.codechef.com/DEC15/problems/CHEFST | Solve the following coding problem using the programming language python:
Chef has two piles of stones with him, one has n1 stones and the other has n2 stones. Fired up by boredom, he invented a game with the two piles.
Before the start of the game Chef chooses an integer m.
In the j-th move:
- He chooses a numbe... | ```python
import sys
n = int(sys.stdin.readline())
for _ in range(n):
(p1, p2, m) = list(map(int, sys.stdin.readline().split()))
l = min(p1, p2)
q = min(p1, p2)
d = min(m * (m + 1) / 2, q)
print(p1 - d + p2 - d)
``` | vfc_134425 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/DEC15/problems/CHEFST",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 1 1\n1 2 1\n4 5 2\n",
"output": "0\n1\n3\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1204/A | Solve the following coding problem using the programming language python:
In the city of Saint Petersburg, a day lasts for $2^{100}$ minutes. From the main station of Saint Petersburg, a train departs after $1$ minute, $4$ minutes, $16$ minutes, and so on; in other words, the train departs at time $4^k$ for each integ... | ```python
s = input()
if s == '0' or s == '1':
print(0)
else:
x = len(s)
if x % 2 != 0 and '1' not in s[1:]:
print((x - 1) // 2)
else:
print((x + 1) // 2)
``` | vfc_134429 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1204/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "100000000\n",
"output": "4\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1328/E | Solve the following coding problem using the programming language python:
You are given a rooted tree consisting of $n$ vertices numbered from $1$ to $n$. The root of the tree is a vertex number $1$.
A tree is a connected undirected graph with $n-1$ edges.
You are given $m$ queries. The $i$-th query consists of the ... | ```python
import sys
input = sys.stdin.readline
(n, m) = [int(i) for i in input().split()]
graph = [[] for i in range(n)]
for j in range(n - 1):
(v, u) = [int(i) - 1 for i in input().split()]
graph[v].append(u)
graph[u].append(v)
parent = [0] * n
tin = [0] * n
tout = [0] * n
time = 0
queue = [(0, 0)]
while queue:
(... | vfc_134433 | {
"difficulty": "hard",
"memory_limit": "256 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1328/E",
"time_limit": "2 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10 6\n1 2\n1 3\n1 4\n2 5\n2 6\n3 7\n7 8\n7 9\n9 10\n4 3 8 9 10\n3 2 4 6\n3 2 1 5\n3 4 8 2\n2 6 10\n3 5 4 7\n",
"output": "YES\nYES\nYES\nYES\nNO\nNO\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1155/A | Solve the following coding problem using the programming language python:
You are given a string $s$ consisting of $n$ lowercase Latin letters.
Let's define a substring as a contiguous subsegment of a string. For example, "acab" is a substring of "abacaba" (it starts in position $3$ and ends in position $6$), but "aa... | ```python
n = int(input())
sen = input()
for i in range(0, n - 1, 1):
if sen[i] > sen[i + 1]:
print('YES')
print(i + 1, i + 2)
exit(0)
print('NO')
``` | vfc_134442 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1155/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7\nabacaba\n",
"output": "YES\n2 3\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/859/E | Solve the following coding problem using the programming language python:
A new set of desks just arrived, and it's about time! Things were getting quite cramped in the office. You've been put in charge of creating a new seating chart for the engineers. The desks are numbered, and you sent out a survey to the engineer... | ```python
n = int(input())
m = 2 * n + 1
u = [[] for i in range(m)]
v = [0] * m
s = [0] * m
d = 10 ** 9 + 7
y = 1
for j in range(n):
(a, b) = map(int, input().split())
v[a] = b
if a != b:
s[b] += 1
u[b].append(a)
for b in range(m):
if not v[b]:
x = 0
p = [b]
while p:
x += 1
a = p.pop()
s[a] = -1
... | vfc_134446 | {
"difficulty": "hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/859/E",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1 5\n5 2\n3 7\n7 3\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n1 10\n2 10\n3 10\n4 10\n5 5\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
... |
taco | verifiable_code | https://codeforces.com/problemset/problem/627/A | Solve the following coding problem using the programming language python:
Two positive integers a and b have a sum of s and a bitwise XOR of x. How many possible values are there for the ordered pair (a, b)?
-----Input-----
The first line of the input contains two integers s and x (2 ≤ s ≤ 10^12, 0 ≤ x ≤ 10^12), th... | ```python
(s, x) = map(int, input().split())
b = s - x
b = list(bin(s - x))
b = b[2:]
a = list(bin(x))
a = a[2:]
al = len(a)
bl = len(b)
c = []
if bl > al:
for i in range(bl - al):
c.append('0')
c.extend(a)
a = c
else:
for i in range(al - bl):
c.append('0')
c.extend(b)
b = c
p = 0
bl = len(b)
for i in range(b... | vfc_134450 | {
"difficulty": "medium_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/627/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "9 5\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 3\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 2\n",... |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Koto Municipal Subway
Koto Municipal Subway
Koto City is a famous city whose roads are in a grid pattern, as shown in the figure below. The roads extending from north to south and the roads extending from east to west are lined up at intervals... | ```python
def main():
while 1:
(d, e) = map(int, input().split())
if d == e == 0:
break
x = d
y = 0
ans = abs(d - e)
while y != d:
a = abs((x ** 2 + y ** 2) ** 0.5 - e)
ans = min(a, ans)
x -= 1
y += 1
print(ans)
main()
``` | vfc_134454 | {
"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": "2 1\n7 6\n7 6\n7 7\n76 5\n8 41\n0 0",
"output": "0.414213562373\n0.0827625302982\n0.0827625302982\n0.0\n48.7401153702\n33.0\n",
"type": "stdin_stdout"
}
]
} | |
taco | verifiable_code | https://www.hackerrank.com/challenges/extra-long-factorials/problem | Solve the following coding problem using the programming language python:
The factorial of the integer $n$, written $n!$, is defined as:
$n!=n\times(n-1)\times(n-2)\times\text{}\cdots\times3\times2\times1$
Calculate and print the factorial of a given integer.
For example, if $n=30$, we calculate $30\times29\ti... | ```python
from math import factorial
print(factorial(int(input())))
``` | vfc_134458 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.hackerrank.com/challenges/extra-long-factorials/problem",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "25\n",
"output": "15511210043330985984000000\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1566/B | Solve the following coding problem using the programming language python:
A binary string is a string that consists of characters $0$ and $1$.
Let $\operatorname{MEX}$ of a binary string be the smallest digit among $0$, $1$, or $2$ that does not occur in the string. For example, $\operatorname{MEX}$ of $001011$ is $2... | ```python
t = int(input())
for test in range(t):
s = input()
zeroes = s.count('0')
if zeroes == 0:
print(0)
continue
first = s.find('0')
last = s.rfind('0')
if last - first + 1 == zeroes:
print(1)
else:
print(2)
``` | vfc_134467 | {
"difficulty": "easy",
"memory_limit": "256 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1566/B",
"time_limit": "1 second"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n01\n1111\n01100\n101\n0000\n01010\n",
"output": "1\n0\n2\n1\n1\n2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n01\n1111\n01100\n100\n0000\n01010\n",
"output": "1\n0\n2\n1\n1... |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/largest-product-pallindrome3753/1 | Solve the following coding problem using the programming language python:
Given a value N, find out the largest palindrome number which is product of two N-digit numbers.
Example 1:
Input: N = 2
Output: 9009
Explanation: 9009 is the largest number
which is product of two 2-digit numbers.
9009 = 91*99.
Example 2:
I... | ```python
class Solution:
def LargestProductPalin(self, n):
upper_limit = 10 ** n - 1
lower_limit = 1 + upper_limit // 10
max_product = 0
for i in range(upper_limit, lower_limit - 1, -1):
for j in range(i, lower_limit - 1, -1):
product = i * j
if product < max_product:
break
number = produ... | vfc_134475 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/largest-product-pallindrome3753/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N = 2",
"output": "9009",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "N = 1",
"output": "9",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/103/A | Solve the following coding problem using the programming language python:
The average miner Vaganych took refresher courses. As soon as a miner completes the courses, he should take exams. The hardest one is a computer test called "Testing Pants for Sadness".
The test consists of n questions; the questions are to be ... | ```python
import sys, math
s = int(input())
arr = list(map(int, input().split(' ')))
m = 0
for i in range(0, s):
m += (arr[i] - 1) * (i + 1) + 1
print(m)
``` | vfc_134476 | {
"difficulty": "easy",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/103/A",
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "100\n1 3 2 1 1 2 1 3 2 2 3 1 1 1 2 2 1 3 3 1 1 2 2 3 2 1 3 1 3 2 1 1 3 3 2 1 2 2 2 3 2 2 3 2 2 3 2 1 3 1 1 2 1 3 2 2 1 1 1 1 1 1 3 1 2 3 1 1 1 1 1 2 3 3 1 1 1 1 2 3 3 1 3 2 2 3 2 1 3 2 2 3 1 1 3 2 3 2 3 1\n",
"output": "4667"... |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/check-if-divisible-by-114724/1 | Solve the following coding problem using the programming language python:
Given a number S. Check whether it is divisble by 11 or not.
Example 1:
Input:
S = 76945
Output: 1
Explanation: The number is divisible by 11
as 76945 % 11 = 0.
ââ¬â¹Example 2:
Input:
S = 12
Output: 0
Explanation: The number is not divisible... | ```python
class Solution:
def divisibleBy11(self, S):
if int(S) % 11 == 0:
return 1
else:
return 0
``` | vfc_134480 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/check-if-divisible-by-114724/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "S = 76945",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "S = 12",
"output": "0",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1064/D | Solve the following coding problem using the programming language python:
You are playing some computer game. One of its levels puts you in a maze consisting of n lines, each of which contains m cells. Each cell either is free or is occupied by an obstacle. The starting cell is in the row r and column c. In one step y... | ```python
import sys
from collections import deque
from math import inf
def rint():
return map(int, sys.stdin.readline().split())
def bfs(sr, sc):
global ans
q = deque()
q.append((x, y, sr, sc))
visit[sr][sc] = 1
ans += 1
while q:
(ll, rr, r, c) = q.popleft()
nadj = []
if r + 1 < n and maze[r + 1][c] == ... | vfc_134481 | {
"difficulty": "medium_hard",
"memory_limit": "512.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1064/D",
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7 16\n1 15\n1000 0\n...*...*........\n.*.*.*.*.******.\n.*.*.*.*.*....*.\n.*.*.*.*.*....*.\n.*...*...*....*.\n.**************.\n................\n",
"output": "37",
"type": "stdin_stdout"
},
{
"fn_name": n... |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/maximum-product-subarray3604/1 | Solve the following coding problem using the programming language python:
Given an array Arr[] that contains N integers (may be positive, negative or zero). Find the product of the maximum product subarray.
Example 1:
Input:
N = 5
Arr[] = {6, -3, -10, 0, 2}
Output: 180
Explanation: Subarray with maximum product
is [6,... | ```python
class Solution:
def maxProduct(self, arr, n):
ans = arr[0]
(ma, mi) = (ans, ans)
for i in range(1, n):
if arr[i] < 0:
temp = ma
ma = mi
mi = temp
ma = max(arr[i], ma * arr[i])
mi = min(arr[i], mi * arr[i])
ans = max(ans, ma)
return ans
``` | vfc_134485 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/maximum-product-subarray3604/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N = 5\nArr[] = {6, -3, -10, 0, 2}",
"output": "180",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/CEFT2020/problems/QFUN | Solve the following coding problem using the programming language python:
Chef and Abhishek both are fighting for the post of Chairperson to be part of ACE committee and are trying their best. To select only one student their teacher gave them a binary string (string consisting of only 0's and 1's) and asked them to f... | ```python
def countSubstr(str, n, x, y):
tot_count = 0
count_x = 0
for i in range(n):
if str[i] == x:
count_x += 1
if str[i] == y:
tot_count += count_x
return tot_count
t = int(input())
for _ in range(t):
n = int(input())
str = input()
x = '0'
y = '1'
x1 = '1'
y1 = '0'
c1 = countSubstr(str, n, x, y... | vfc_134486 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/CEFT2020/problems/QFUN",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n4\n1010\n",
"output": "4\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/851/B | Solve the following coding problem using the programming language python:
Arpa is taking a geometry exam. Here is the last problem of the exam.
You are given three points a, b, c.
Find a point and an angle such that if we rotate the page around the point by the angle, the new position of a is the same as the old pos... | ```python
from math import *
(ax, ay, bx, by, cx, cy) = map(int, input().split())
ab = (ax - bx) * (ax - bx) + (ay - by) * (ay - by)
bc = (cx - bx) * (cx - bx) + (cy - by) * (cy - by)
line = (ax - cx) * (by - ay) == (bx - ax) * (ay - cy)
if ab == bc and (not line):
print('Yes')
else:
print('No')
``` | vfc_134490 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/851/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "0 1 1 1 1 0\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1 0 0 1000 1000\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"fn_name": null... |
taco | verifiable_code | https://codeforces.com/problemset/problem/1305/A | Solve the following coding problem using the programming language python:
Kuroni has $n$ daughters. As gifts for them, he bought $n$ necklaces and $n$ bracelets: the $i$-th necklace has a brightness $a_i$, where all the $a_i$ are pairwise distinct (i.e. all $a_i$ are different), the $i$-th bracelet has a brightness ... | ```python
for _ in range(int(input())):
n = int(input())
l = list(map(int, input().split()))
l2 = list(map(int, input().split()))
l.sort()
l2.sort()
print(*l)
print(*l2)
``` | vfc_134494 | {
"difficulty": "easy",
"memory_limit": "256 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1305/A",
"time_limit": "1 second"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n3\n1 8 5\n8 4 5\n3\n1 7 5\n6 1 2\n",
"output": "1 8 5\n8 4 5\n5 1 7\n6 2 1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n3\n1 8 10\n8 4 5\n3\n1 7 5\n6 1 2\n",
"output": "1 8 ... |
taco | verifiable_code | https://codeforces.com/problemset/problem/1468/K | Solve the following coding problem using the programming language python:
There is a robot on a checkered field that is endless in all directions. Initially, the robot is located in the cell with coordinates (0, 0). He will execute commands which are described by a string of capital Latin letters 'L', 'R', 'D', 'U'. W... | ```python
import sys
import io
import math
import collections
import decimal
import itertools
import bisect
import heapq
def input():
return sys.stdin.readline()[:-1]
def solve(S):
Move = {'L': (-1, 0), 'R': (1, 0), 'U': (0, 1), 'D': (0, -1)}
Moves = [Move[c] for c in S]
pos1 = (0, 0)
for k in range(len(S)):
p... | vfc_134502 | {
"difficulty": "medium_hard",
"memory_limit": "512.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1468/K",
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\nL\nLUUDR\nLLUU\nDDDUUUUU\n",
"output": "-1 0\n-1 2\n0 0\n0 1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\nL\nUURDL\nLLUU\nDDDUUUUU\n",
"output": "-1 0\n0 2\n0 0\n0 1\n",
... |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/knight-walk4521/1 | Solve the following coding problem using the programming language python:
Given a square chessboard, the initial position of Knight and position of a target. Find out the minimum steps a Knight will take to reach the target position.If it cannot reach the target position return -1.
Note:
The initial and the target pos... | ```python
from collections import *
class Solution:
def minStepToReachTarget(self, KnightPos, TargetPos, N):
kx = KnightPos[0] - 1
ky = KnightPos[1] - 1
tx = TargetPos[0] - 1
ty = TargetPos[1] - 1
ans = 0
def isvalid(x, y, visit, N):
if x >= 0 and y >= 0 and (x < N) and (y < N) and (visit[x][y] == Fa... | vfc_134506 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/knight-walk4521/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N=6\nknightPos[ ] = {4, 5}\ntargetPos[ ] = {1, 1}",
"output": "3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "N=8\nknightPos[ ] = {7, 7}\ntargetPos[ ] = {1, 5}",
"output": "4",
... |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Little Bob comes to you for candies as you are his favorite coder! He wants X candies. You have N bags and the i^th bag contains A[i] candies.
You can give him a set of one or more bags such that the sum of candies in those bags is EXACTLY equa... | ```python
'''
# Read input from stdin and provide input before running code
name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
def cmp(l1, l2):
if len(l1) < len(l2):
return False
if len(l1) > len(l2):
return True
for i in range(len(l1)):
if l1[i] > l2[i]:
return True
return False
N, X = l... | vfc_134507 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "12 98\n27 4 77 60 83 83 99 85 60 17 48 41",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "20 848384\n1234 151516 15115 8080 1123 100 12314 90 123 158 1515 151 10 3 151 1231... | |
taco | verifiable_code | https://codeforces.com/problemset/problem/373/C | Solve the following coding problem using the programming language python:
There are n kangaroos with pockets. Each kangaroo has a size (integer number). A kangaroo can go into another kangaroo's pocket if and only if the size of kangaroo who hold the kangaroo is at least twice as large as the size of kangaroo who is h... | ```python
import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase
def vsInput():
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def ... | vfc_134512 | {
"difficulty": "medium_hard",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/373/C",
"time_limit": "1.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1\n1\n1\n2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input... |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/part-of-it1016/1 | Solve the following coding problem using the programming language python:
A given series 3, 5, 9, 11, 15, 17, 21, 27, 29, ... and so on. You need to identify the pattern and determine whether the input number ( n ) is a part of the given series or not. If yes then return "Yes", otherwise "No".
Example 1:
Input: n = 9... | ```python
class Solution:
def isPart(self, n):
n += 2
i = 2
while i * i <= n:
if n % i == 0:
return 'No'
i += 1
return 'Yes'
``` | vfc_134516 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/part-of-it1016/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "n = 9",
"output": "Yes",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "n = 8",
"output": "No",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1099/D | Solve the following coding problem using the programming language python:
Mitya has a rooted tree with n vertices indexed from 1 to n, where the root has index 1. Each vertex v initially had an integer number a_v ≥ 0 written on it. For every vertex v Mitya has computed s_v: the sum of all values written on the vertice... | ```python
import sys
def getAndParseInt(num=1):
string = sys.stdin.readline().strip()
if num == 1:
return int(string)
else:
return [int(part) for part in string.split()]
def getAndParseString(num=1, delim=' '):
string = sys.stdin.readline().strip()
if num == 1:
return string
else:
return [part for part ... | vfc_134517 | {
"difficulty": "medium_hard",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1099/D",
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1 2 3 4\n5 -1 5 -1 7\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "25\n1 2 1 4 4 4 1 2 8 5 1 8 1 6 9 6 10 10 7 10 8 17 14 6\n846 -1 941 -1 1126 1803 988 -1 1352 1235 ... |
taco | verifiable_code | https://codeforces.com/problemset/problem/678/A | Solve the following coding problem using the programming language python:
Johny likes numbers n and k very much. Now Johny wants to find the smallest integer x greater than n, so it is divisible by the number k.
-----Input-----
The only line contains two integers n and k (1 ≤ n, k ≤ 10^9).
-----Output-----
Print... | ```python
(n, k) = (int(x) for x in input().split())
print(n + (k - n % k))
``` | vfc_134521 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/678/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 3\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "25 13\n",
"output": "26\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "26 1... |
taco | verifiable_code | https://www.codechef.com/QTST2020/problems/NEGBFRAC | Solve the following coding problem using the programming language python:
Consider the fraction, $a/b$, where $a$ and $b$ are positive integers. If $a < b$ and $GCD(a,b) = 1$, it is called a reduced proper fraction.
If we list the set of a reduced proper fraction for $d \leq 8$, (where $d$ is the denominator) in ascen... | ```python
from sys import stdin
from fractions import Fraction
input = stdin.readline
for _ in range(int(input())):
(a, b, n) = list(map(int, input().split()))
ab = Fraction(a, b)
p = set()
for i in range(1, n + 1):
for j in range(n, 0, -1):
x = Fraction(i, j)
if x > ab:
break
p.add(x)
x = sorted(p)... | vfc_134529 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/QTST2020/problems/NEGBFRAC",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n3 7 8\n3 5 8\n4 5 8\n6 7 8\n1 5 8\n",
"output": "2 5\n4 7\n3 4\n5 6\n1 6\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
()
Problem Statement
There is a string S. Initially, S is an empty string.
Perform the following processing in order of n.
* Add x_i p_i (=" (" or") ") to the end of S.
After processing, determine if S is a well-balanced string.
"The stri... | ```python
n = int(input())
s = 0
f = 0
for i in range(n):
(p, x) = input().split()
x = int(x)
if p == '(':
s += x
else:
s -= x
if s < 0:
f = 1
if f or s != 0:
print('NO')
else:
print('YES')
``` | vfc_134538 | {
"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\n) 1\n' 1",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n( 5\n* 4\n) 1",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... | |
taco | verifiable_code | https://codeforces.com/problemset/problem/980/B | Solve the following coding problem using the programming language python:
The city of Fishtopia can be imagined as a grid of 4 rows and an odd number of columns. It has two main villages; the first is located at the top-left cell (1,1), people who stay there love fishing at the Tuna pond at the bottom-right cell (4, n... | ```python
EMPTY = '.'
HOTEL = '#'
def main():
(n, k) = map(int, input().split())
print('YES')
print(EMPTY * n)
if k % 2 == 0:
m = k // 2
s = EMPTY + HOTEL * m + EMPTY * (n - m - 1)
print(s)
print(s)
elif k < n - 1:
s = (HOTEL * k).center(n, EMPTY)
print(s)
print(EMPTY * n)
else:
print(EMPTY + HOT... | vfc_134542 | {
"difficulty": "medium_hard",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/980/B",
"time_limit": "1.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "33 57\n",
"output": "YES\n.................................\n.###############################.\n.#############.....#############.\n.................................\n",
"type": "stdin_stdout"
},
{
"fn_name... |
taco | verifiable_code | https://codeforces.com/problemset/problem/119/B | Solve the following coding problem using the programming language python:
Vasya is about to take his first university exam in about several minutes. And it's not just some ordinary exam, it's on mathematical analysis. Of course, right now Vasya can only think of one thing: what the result of his talk with the examiner... | ```python
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
(ansMin, ansMax) = (10 ** 10, -10 ** 10)
were = [0] * n
sz = n // k
for i in range(int(input())):
cur = 0.0
t = map(int, input().split())
for x in t:
were[x - 1] = 1
cur += a[x - 1]
cur /= sz
ansMin = min(ansMin, cur)
ansMax = ma... | vfc_134546 | {
"difficulty": "hard",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/119/B",
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10 6\n100 100 100 100 100 100 100 100 100 100\n6\n4\n10\n2\n4\n7\n5\n",
"output": "100.0000000000 100.0000000000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "90 15\n78 78 57 46 96 3 2 7... |
taco | verifiable_code | https://codeforces.com/problemset/problem/1185/C2 | Solve the following coding problem using the programming language python:
The only difference between easy and hard versions is constraints.
If you write a solution in Python, then prefer to send it in PyPy to speed up execution time.
A session has begun at Beland State University. Many students are taking exams.
P... | ```python
import sys, math
def read_int():
return int(sys.stdin.readline().strip())
def read_int_list():
return list(map(int, sys.stdin.readline().strip().split()))
def read_string():
return sys.stdin.readline().strip()
def read_string_list(delim=' '):
return sys.stdin.readline().strip().split(delim)
def print... | vfc_134550 | {
"difficulty": "medium_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1185/C2",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7 15\n1 2 3 4 5 6 7\n",
"output": "0 0 0 0 0 2 3 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 100\n80 40 40 40 60\n",
"output": "0 1 1 2 3 ",
"type": "stdin_stdout"
},
... |
taco | verifiable_code | https://www.hackerrank.com/challenges/ajourney/problem | Solve the following coding problem using the programming language python:
Elon Musk has succesfully built an automated staircase from Earth to Mars. Many people want to go to Mars, but that's not possible due to limited capacity of the staircase and logistics involved. Hence, Elon asks interested candidates to solve a... | ```python
from math import log10, ceil
T = int(input())
for _ in range(T):
(n, k) = [int(x) for x in input().split()]
n -= 1
c = 2 * ceil(k + log10(n))
e = n
b = 2
s = 1
while e > 0:
if e % 2 == 1:
s = int(str(s * b)[:c])
e //= 2
b = int(str(b * b)[:c])
s = str(s)[:k]
r = int(s) + pow(2, n, 10 ** k)
... | vfc_134555 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.hackerrank.com/challenges/ajourney/problem",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n10 2 \n12 1\n",
"output": "63\n10\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/LAPD | Solve the following coding problem using the programming language python:
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Vietnamese] as well.
Ben Fero is a popular guy who likes inventing and solving interesting problems. Last weekend, he found a challenging problem, but he could not solve it on ... | ```python
import numpy as np
import math
t_cases = int(input())
MOD = 1000000000 + 7
bmax = 5000
sq_integers = []
sum_sq_integers = []
for i in range(1, bmax + 1):
sq_integers.append(i * i)
sum_sq_integers.append(0)
for i in range(0, bmax):
if i == 0:
sum_sq_integers[i] = sq_integers[i]
else:
sum_sq_integers[i]... | vfc_134559 | {
"difficulty": "hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/LAPD",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n2 5 3\n3 2 4",
"output": "1\n6",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/272/B | Solve the following coding problem using the programming language python:
Dima got into number sequences. Now he's got sequence a_1, a_2, ..., a_{n}, consisting of n positive integers. Also, Dima has got a function f(x), which can be defined with the following recurrence: f(0) = 0; f(2·x) = f(x); f(2·x + 1) = f(x) ... | ```python
def helper(x):
ret = 0
while x > 0:
if x % 2 == 0:
x //= 2
else:
ret += 1
x //= 2
return ret
n = int(input())
a = list(map(int, input().split()))
d = [0] * 10000
for element in a:
res = helper(element)
d[res] += 1
ans = 0
for element in d:
ans += element * (element - 1) / 2
print(int(ans))
... | vfc_134563 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/272/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 2 4\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n5 3 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input"... |
taco | verifiable_code | https://www.hackerrank.com/challenges/fibonacci-lcm/problem | Solve the following coding problem using the programming language python:
After Derek (of district 5) discovered how to compute the greatest common divisor (gcd) of Fibonacci numbers, he now tried to answer the next obvious question: how does one compute the least common multiple (lcm) of Fibonacci numbers? Unfortunat... | ```python
import sys, random
from math import sqrt
def gcd(a, b):
while 1:
if b == 0:
return a
a %= b
if a == 0:
return b
b %= a
def fib_mod(n, mod):
if n <= 2:
return ((n + 1 >> 1) % mod, (n + 2 >> 1) % mod)
mask = 4
while mask <= n:
mask <<= 1
mask >>= 2
(a, b) = (1, 1)
while mask:
if mas... | vfc_134567 | {
"difficulty": "medium_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.hackerrank.com/challenges/fibonacci-lcm/problem",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1\n3\n3\n6\n9\n",
"output": "136\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/84/A | Solve the following coding problem using the programming language python:
The hero of our story, Valera, and his best friend Arcady are still in school, and therefore they spend all the free time playing turn-based strategy "GAGA: Go And Go Again". The gameplay is as follows.
There are two armies on the playing fiel... | ```python
n = int(input())
print(n * 3 // 2)
``` | vfc_134571 | {
"difficulty": "easy",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/84/A",
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "8457980\n",
"output": "12686970",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/CHEFPCHF | Solve the following coding problem using the programming language python:
Read problems statements in mandarin chinese, russian and vietnamese as well.
Fehc is Chef's best friend. They grew up with each other, and often help each other with competitive programming.
Chef is participating in a programming contest p... | ```python
def getPLens(x):
n = len(x)
ret = [0] * n
mx = 0
mxi = 0
for i in range(1, n):
pp = min(ret[2 * mxi - i], mxi - i + ret[mxi])
if pp < 0:
pp = 0
while True:
a = i - pp
b = i + pp
if a < 0 or b >= n:
break
if x[a] != x[b]:
break
pp += 1
pp -= 1
ret[i] = pp
if i + pp > ... | vfc_134579 | {
"difficulty": "very_hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/CHEFPCHF",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n7 2\n5 1\n6 1\n7 3\n2 1\n4 2\n6 1\n10 0",
"output": "9\n12\n30",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/TRICOIN | Solve the following coding problem using the programming language python:
Read problems statements in Mandarin Chinese , Russian and Vietnamese as well.
Chef belongs to a very rich family which owns many gold mines. Today, he brought N gold coins and decided to form a triangle using these coins. Isn't it strange?
C... | ```python
for _ in range(int(input())):
n = int(input())
n = n * 2
h = 0
while True:
h += 1
x = h * (h + 1)
if x > n:
break
print(h - 1)
``` | vfc_134583 | {
"difficulty": "easy",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/TRICOIN",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n3\n5\n7",
"output": "2\n2\n3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n3\n5\n11",
"output": "2\n2\n4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
taco | verifiable_code | https://codeforces.com/problemset/problem/1742/C | Solve the following coding problem using the programming language python:
On an $8 \times 8$ grid, some horizontal rows have been painted red, and some vertical columns have been painted blue, in some order. The stripes are drawn sequentially, one after the other. When the stripe is drawn, it repaints all the cells th... | ```python
import sys
def solution():
row = '\n'
while row == '\n':
row = sys.stdin.readline()
a = [row.strip()]
for i in range(7):
row = sys.stdin.readline().strip()
a.append(row)
for i in range(8):
if a[i] == 'RRRRRRRR':
print('R')
return
print('B')
def main():
t = int(input())
while t:
solut... | vfc_134588 | {
"difficulty": "easy",
"memory_limit": "256 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1742/C",
"time_limit": "1 second"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n\n....B...\n....B...\n....B...\nRRRRRRRR\n....B...\n....B...\n....B...\n....B...\n\nRRRRRRRB\nB......B\nB......B\nB......B\nB......B\nB......B\nB......B\nRRRRRRRB\n\nRRRRRRBB\n.B.B..BB\nRRRRRRBB\n.B.B..BB\n.B.B..BB\nRRRRRRBB\n.B... |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Sachin wants to give a love letter to his girlfriend on valentines day. He
is having a circular piece of paper of radius "r".
He wants to use rectangular piece of paper for letter writing whose length and breadth are integers. In how many way... | ```python
'''
# Read input from stdin and provide input before running code
name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
print('424')
``` | vfc_134592 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "12",
"output": "424",
"type": "stdin_stdout"
}
]
} | |
taco | verifiable_code | https://codeforces.com/problemset/problem/685/B | Solve the following coding problem using the programming language python:
After the piece of a devilish mirror hit the Kay's eye, he is no longer interested in the beauty of the roses. Now he likes to watch snowflakes.
Once upon a time, he found a huge snowflake that has a form of the tree (connected acyclic graph) c... | ```python
import operator
import bisect
(n, q) = [int(s) for s in input().split()]
ps = [int(s) for s in input().split()]
childs = [[] for _ in range(n)]
for (c, pa) in enumerate(ps):
childs[pa - 1].append(c + 1)
toposort = []
this_level = [0]
next_level = []
while len(this_level) > 0:
for this_n in this_level:
top... | vfc_134596 | {
"difficulty": "hard",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/685/B",
"time_limit": "3.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 2\n1\n1\n2\n",
"output": "1\n2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7 4\n1 1 3 3 5 3\n2\n2\n3\n5\n",
"output": "2\n2\n3\n5\n",
"type": "stdin_stdout"
},
{
... |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/fill-the-tank3026/1 | Solve the following coding problem using the programming language python:
In a city, N water tanks are connected by pipeline(As a tree) where the ith tank has a capacity cap[i]. The ith element of the given Edge array of length N-1 represents that there is a pipeline between Edge[i][0] and Edge[i][1] tank. Since peopl... | ```python
import sys
sys.setrecursionlimit(10 ** 8)
class Solution:
def minimum_amount(self, edges, N, S, cap):
def recur(graph, visited, cur_node, cap):
if visited[cur_node]:
return -1
visited[cur_node] = True
cur_cap = cap[cur_node - 1]
max_neigh_cap = 0
neighbours = 0
for neigh_node in gr... | vfc_134600 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/fill-the-tank3026/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N = 4 and S = 1\r\nEdges = [[1, 2], [1, 3], [2, 4]]\r\nCap = [1, 1, 1, 1]",
"output": "5",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "N = 3 and S = 2\r\nEdges = [[1, 2], [2, 3]]\r\nCap = ... |
taco | verifiable_code | https://codeforces.com/problemset/problem/765/C | Solve the following coding problem using the programming language python:
Misha and Vanya have played several table tennis sets. Each set consists of several serves, each serve is won by one of the players, he receives one point and the loser receives nothing. Once one of the players scores exactly k points, the score... | ```python
(k, a, b) = map(int, input().split())
mx_a = a // k
mx_b = b // k
if mx_a == 0 and b % k != 0:
print(-1)
elif mx_b == 0 and a % k != 0:
print(-1)
else:
print(mx_a + mx_b)
``` | vfc_134601 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/765/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "11 11 5\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "11 2 3\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": ... |
taco | verifiable_code | https://codeforces.com/problemset/problem/391/F1 | Solve the following coding problem using the programming language python:
This problem consists of three subproblems: for solving subproblem F1 you will receive 8 points, for solving subproblem F2 you will receive 15 points, and for solving subproblem F3 you will receive 10 points.
Manao has developed a model to pred... | ```python
import sys
(ammount_prices, days_for_trading) = map(int, input().split())
stonks = []
for i in range(0, ammount_prices):
price = int(sys.stdin.readline())
stonks.append(price)
def get_max(days_for_trading, stonks):
size_prices = len(stonks)
if size_prices == 0 or size_prices == 1 or days_for_trading == 0... | vfc_134605 | {
"difficulty": "unknown_difficulty",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/391/F1",
"time_limit": "3.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 1\n2\n1\n",
"output": "0",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 2\n2\n7\n3\n9\n8\n7\n9\n4\n1\n9\n",
"output": "15\n",
"type": "stdin_stdout"
},
{
"fn_... |
taco | verifiable_code | https://codeforces.com/problemset/problem/1439/A1 | Solve the following coding problem using the programming language python:
This is the easy version of the problem. The difference between the versions is in the number of possible operations that can be made. You can make hacks if and only if you solved both versions of the problem.
You are given a binary table of si... | ```python
import sys
input = sys.stdin.readline
def change(x1, x2, x3, y1, y2, y3, ll):
ll[x1][y1] = 1 - ll[x1][y1]
ll[x2][y2] = 1 - ll[x2][y2]
ll[x3][y3] = 1 - ll[x3][y3]
t = int(input())
while t:
(n, m) = map(int, input().split())
ll = []
for i in range(n):
l = list(map(int, input().strip()))
ll.append(l)
... | vfc_134609 | {
"difficulty": "medium",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1439/A1",
"time_limit": "1.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n2 2\n10\n11\n3 3\n011\n101\n110\n4 4\n1111\n0110\n0110\n1111\n5 5\n01011\n11001\n00010\n11011\n10000\n2 3\n011\n101\n",
"output": "1\n1 1 2 1 2 2 \n6\n1 1 1 2 2 2 \n1 1 2 1 2 2 \n1 2 1 3 2 2 \n1 2 2 2 2 3 \n2 1 2 2 3 1 \n2... |
taco | verifiable_code | https://codeforces.com/problemset/problem/541/C | Solve the following coding problem using the programming language python:
Some time ago Leonid have known about idempotent functions. Idempotent function defined on a set {1, 2, ..., n} is such function $g : \{1,2, \ldots, n \} \rightarrow \{1,2, \ldots, n \}$, that for any $x \in \{1,2, \ldots, n \}$ the formula g(g(... | ```python
n = int(input())
f = list(map(int, input().split()))
for i in range(n):
f[i] -= 1
def gcd(a, b):
while a != 0 and b != 0:
(a, b) = (b, a % b)
return a + b
def lcm(a, b):
return a * b // gcd(a, b)
ans = 1
minn = 0
for i in range(n):
vis = [False] * n
cur = i
(st, pr) = (0, 0)
while not vis[cur]:
... | vfc_134617 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/541/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1 2 2 4\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n2 3 3\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"inpu... |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/automorphic-number4721/1 | Solve the following coding problem using the programming language python:
Given a number N, check whether the number is Automorphic number or not.
A number is called Automorphic number if and only if its square ends in the same digits as the number itself.
Example 1:
Input: N = 76
Output: Automorphic
Explanation: 7... | ```python
class Solution:
def is_AutomorphicNumber(self, n):
s = n ** 2
q = str(s)
n = str(n)
if q.endswith(n):
return 'Automorphic'
return 'Not Automorphic'
``` | vfc_134621 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/automorphic-number4721/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N = 76",
"output": "Automorphic",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "N = 16",
"output": "Not Automorphic",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/generalised-fibonacci-numbers1820/1 | Solve the following coding problem using the programming language python:
Consider the generalized Fibonacci number G, which is dependent on a, b and c as follows :-
G(1) = 1, G(2) = 1. G(n) = aG(n-1) + bG(n-2) + c.
Your task is to calculate G(n)%m for given values of n and m.
Example 1:
Input:
a = 3, b = 3, c = 3, n ... | ```python
class Solution:
mat = [[0 for i in range(3)] for j in range(3)]
res = [[0 for i in range(3)] for j in range(3)]
def mul(self, res, mat, m):
res1 = [[0 for i in range(3)] for j in range(3)]
for i in range(3):
for j in range(3):
for k in range(3):
res1[i][j] += res[i][k] * mat[k][j]
res... | vfc_134622 | {
"difficulty": "medium_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/generalised-fibonacci-numbers1820/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "a = 3, b = 3, c = 3, n = 3, m = 5",
"output": "4",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "a = 2, b = 2, c = 2, n = 4, m = 100",
"output": "16",
"type": "stdin_stdout"
... |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/y-shaped-pattern4351/1 | Solve the following coding problem using the programming language python:
Print a Y shaped pattern from asterisks in N number of lines.
Note:
1. N is even.
2. All the strings in the string array which you will return is of length N, so add the spaces wherever required, so that the length of every string becomes N.
E... | ```python
class Solution:
def yShapedPattern(self, N):
k = 0
s = N - 1
if N // 2 == 1:
s = 1
y = ''
for i in range(0, N // 2):
y = y + ' ' * k + '*' + ' ' * s + '*' + '\n'
k = k + 1
s = s - 2
if N % 2 == 0:
for i in range(0, N // 2 - 1):
y = y + (' ' * (N // 2) + '*' + '\n')
y = y + ... | vfc_134623 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/y-shaped-pattern4351/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N = 4",
"output": "* * \n * * \n * \n *\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "N = 8",
"output": "* *\n * * \n * * \n * * \n *\n *\n *\n ... |
taco | verifiable_code | https://www.codechef.com/problems/PPATTERN | Solve the following coding problem using the programming language python:
Consider the following $4 \times 4$ pattern:
1 2 4 7
3 5 8 11
6 9 12 14
10 13 15 16
You are given an integer $N$. Print the $N \times N$ pattern of the same kind (containing integers $1$ through $N^2$).
-----Input-----
- The first line o... | ```python
for i in range(int(input())):
n = int(input())
arr = [[0] * n for j in range(n)]
c = 1
for j in range(n):
for k in range(j + 1):
arr[k][j - k] = c
c += 1
for j in range(1, n):
for k in range(n - j):
arr[j + k][n - k - 1] = c
c += 1
for j in arr:
print(*j)
``` | vfc_134624 | {
"difficulty": "easy",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/PPATTERN",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n4\n",
"output": "1 2 4 7\n3 5 8 11\n6 9 12 14\n10 13 15 16\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
How Many Divisors?
Write a program which reads three integers a, b and c, and prints the number of divisors of c between a and b.
Constraints
* 1 ≤ a, b, c ≤ 10000
* a ≤ b
Input
Three integers a, b and c are given in a line separated by a s... | ```python
(a, b, c) = map(int, input().split())
ans = 0
for i in range(a, b + 1):
if c % i == 0:
ans += 1
print(ans)
``` | vfc_134628 | {
"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": "7 14 80",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7 4 80",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1 ... | |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/swap-two-numbers3844/1 | Solve the following coding problem using the programming language python:
Swap given two numbers and print them. (Try to do it without a temporary variable.) and return it.
Example 1:
Input: a = 13, b = 9
Output: 9 13
Explanation: after swapping it
becomes 9 and 13.
ââ¬â¹Example 2:
Input: a = 15, b = 8
Output: 8 15... | ```python
class Solution:
def get(self, a, b):
a = a + b
b = a - b
a = a - b
return (a, b)
``` | vfc_134638 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/swap-two-numbers3844/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "a = 13, b = 9",
"output": "9 13",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "a = 15, b = 8",
"output": "8 15",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.hackerrank.com/challenges/stepping-stones-game/problem | Solve the following coding problem using the programming language python:
Bob sees his younger brother, Jack, playing Stepping Stones. He is fascinated by the most interesting game and decides to play it.
Square boxes have been made on the ground with the help of chalk powder, and a number is assigned to each block. ... | ```python
from math import *
t = int(input())
for i in range(0, t):
n = int(input())
j = (1 + sqrt(1 + 8 * n)) / 2
if abs(j - int(j)) <= 0:
print('Go On Bob', int(j - 1))
else:
print('Better Luck Next Time')
``` | vfc_134639 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.hackerrank.com/challenges/stepping-stones-game/problem",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n2\n",
"output": "Better Luck Next Time\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n3\n",
"output": "Go On Bob 2\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/RC152020/problems/REC15A | Solve the following coding problem using the programming language python:
There is a task in Among Us in which $N$ temperature scale with unique readings are given and you have to make all of them equal. In one second you can choose an odd number and add or subtract that number in any one temperature value. Find minim... | ```python
for _ in range(int(input())):
n = int(input())
ar = list(map(int, input().split()))
odd = 0
even = 0
if n == 1:
print(0)
continue
for i in range(n):
if ar[i] % 2 == 1:
odd += 1
else:
even += 1
if odd > 0:
vo = (odd - 1) * 2 + even
else:
vo = even
if even > 0:
ve = (even - 1) * 2 +... | vfc_134643 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/RC152020/problems/REC15A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n5\n1 2 3 4 5\n4\n5 2 3 8\n2\n50 53\n",
"output": "5\n4\n1\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/915/D | Solve the following coding problem using the programming language python:
You are given a directed graph consisting of n vertices and m edges (each edge is directed, so it can be traversed in only one direction). You are allowed to remove at most one edge from it.
Can you make this graph acyclic by removing at most o... | ```python
(n, m) = map(int, input().split())
g = [[] for i in range(n)]
for _ in range(m):
(u, v) = map(int, input().split())
g[u - 1].append(v - 1)
st = []
vis = [0 for _ in range(n)]
nxt = [0 for _ in range(n)]
es = set()
cycle = False
for i in range(n):
if cycle:
break
if vis[i] != 0:
continue
st = [i]
vis... | vfc_134652 | {
"difficulty": "hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/915/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 4\n1 2\n2 3\n3 2\n3 1\n",
"output": "YES\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Today RK has to transport his N items of different weights(in calories) to a near city but before that he wants to make sure that the weights of all items are balanced. In order to check this he puts all items on the weight scale and found that ... | ```python
import fractions
tcs = int(eval(input()))
for i in range(tcs):
n = eval(input())
listx = list(map(int, input().split(' ')))
gcdx = listx[0]
for i in listx:
gcdx = fractions.gcd(i, gcdx)
print((gcdx * int(n)))
``` | vfc_134656 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n5\n2 3 5 8 18\n5\n2 4 1 6 8\n3\n12 10 5\n3\n6 10 15",
"output": "5\n5\n3\n3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n20\n51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 5... | |
taco | verifiable_code | https://www.codechef.com/problems/PREFONES | Solve the following coding problem using the programming language python:
Chef has a binary string S of length N.
Chef can perform the following operation on the string:
Choose any substring of S;
Remove the chosen substring from S;
Concatenate the remaining parts of the string S, obtained after removing the substrin... | ```python
for i in range(int(input())):
n = int(input())
p = input()
s = 0
l = []
for i in range(n):
if p[i] == '0':
if s > 0:
l.append(s)
s = 0
else:
s += 1
if s > 0:
l.append(s)
if l == []:
print(0)
elif len(l) == 1:
print(l[0])
elif p[0] == '0':
print(max(l))
else:
print(l[0] + m... | vfc_134661 | {
"difficulty": "medium",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/PREFONES",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n4\n1010\n6\n011011\n11\n01011011101\n",
"output": "2\n2\n3\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/18/E | Solve the following coding problem using the programming language python:
According to a new ISO standard, a flag of every country should have, strangely enough, a chequered field n × m, each square should be wholly painted one of 26 colours. The following restrictions are set:
* In each row at most two different ... | ```python
import sys
from array import array
def input():
return sys.stdin.buffer.readline().decode('utf-8')
(n, m) = map(int, input().split())
flag = [tuple(map(lambda c: ord(c) - 97, input().rstrip())) for _ in range(n)]
dp = [[[m] * 26 for _ in range(26)] for _ in range(n)]
for i in range(n):
for j in range(m):
... | vfc_134665 | {
"difficulty": "hard",
"memory_limit": "128.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/18/E",
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 1\nq\n",
"output": "0\nq\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 500\nwljexjwjwsxhascgpyezfotqyieywzyzpnjzxqebroginhlpsvtbgmbckgqixkdveraxlgleieeagubywaacncxoouibbhwyxhjiczlyms... |
taco | verifiable_code | https://codeforces.com/problemset/problem/75/A | Solve the following coding problem using the programming language python:
Can you imagine our life if we removed all zeros from it? For sure we will have many problems.
In this problem we will have a simple example if we removed all zeros from our life, it's the addition operation. Let's assume you are given this equ... | ```python
a = input()
b = input()
c = str(int(a) + int(b))
a = a.replace('0', '')
b = b.replace('0', '')
c = c.replace('0', '')
if int(a) + int(b) == int(c):
print('YES')
else:
print('NO')
``` | vfc_134670 | {
"difficulty": "easy",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/75/A",
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n4\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "341781108\n784147010\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/maximum-weight-difference5036/1 | Solve the following coding problem using the programming language python:
Given an array arr of size n. The task is to choose k numbers from the array such that the absolute difference between the sum of chosen numbers and the sum of remaining numbers is maximum.
Example 1:
Input:
n = 5, k = 2
arr[] = {8, 4, 5, 2, 10... | ```python
class Solution:
def solve(self, arr, n, k):
chosen_first = 0
chosen_last = 0
total = 0
arr.sort()
for num in arr:
total += num
for num in arr[0:k]:
chosen_first += num
for num in arr[n - k:]:
chosen_last += num
x = abs(total - chosen_first - chosen_first)
y = abs(total - chosen_la... | vfc_134675 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/maximum-weight-difference5036/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "n = 5, k = 2\r\narr[] = {8, 4, 5, 2, 10}",
"output": "17",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "n = 8, k = 3\r\narr[] = {1, 1, 1, 1, 1, 1, 1, 1}",
"output": "2",
"type":... |
taco | verifiable_code | https://www.codechef.com/problems/CHEFPTNT | Solve the following coding problem using the programming language python:
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Chef has decided to start a new firm called PatentChef. However, he's stuck with some big legal issues. Their firm has received offers from a lot of companies, so Ch... | ```python
for _ in range(int(input())):
(n, m, x, k) = map(int, input().split())
str1_list = list(input())
even = str1_list.count('E')
odd = k - even
if m % 2 == 0:
evenOutput = min(even, x * (m // 2))
oddOutput = min(odd, x * (m // 2))
else:
evenOutput = min(even, x * ((m - 1) // 2))
oddOutput = min(odd,... | vfc_134676 | {
"difficulty": "medium",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/CHEFPTNT",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n4 4 2 4\nEEOO\n4 3 1 4\nEEOO",
"output": "yes\nno",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Calvin is driving his favorite vehicle on the 101 freeway. He notices that the check engine light of his vehicle is on, and he wants to service it immediately to avoid any risks. Luckily, a service lane runs parallel to the highway. The length o... | ```python
n,q=input().split()
n=int(n)
q=int(q)
x=input()
a=list()
a=x.split()
b=list()
for i in range(len(a)):
b.append(int(a[i]))
for i in range(q):
x,y=input().split()
z=min(b[int(x):int(y)+1])
print(z)
``` | vfc_134681 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "100000 1000\n2 3 3 2 2 3 3 2 2 3 3 2 3 2 3 2 2 3 3 2 2 2 2 2 2 3 2 3 3 2 2 3 3 3 3 3 3 2 2 3 3 3 3 2 3 3 3 2 2 2 2 2 2 3 2 2 2 2 3 3 2 3 2 2 3 3 3 2 2 3 3 3 2 3 2 2 2 3 2 2 3 2 2 3 3 2 3 3 3 2 2 3 3 2 3 2 2 3 2 2 2 2 3 3 3 3 3 3 2 ... | |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/sum-of-length3345/1 | Solve the following coding problem using the programming language python:
Given an array. Calculate the sum of lengths of contiguous subarrays having all distinct elements.
Example 1:
Input:
N=3
arr[] = { 1,2,3 }
Output: 10
Explanation:
{1, 2, 3} is a subarray of length 3 with
distinct elements. Total length of le... | ```python
class Solution:
def sumoflength(self, arr, n):
store = set()
count = 0
i = 0
for item in arr:
while i < n and (not arr[i] in store):
store.add(arr[i])
i += 1
count += len(store) * (len(store) + 1) // 2
store.remove(item)
return count
``` | vfc_134687 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/sum-of-length3345/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N=3\r\narr[] = { 1,2,3 }",
"output": "10",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "N=1\r\narr[] = { 1 }",
"output": "1",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/367/A | Solve the following coding problem using the programming language python:
Sereja loves all sorts of algorithms. He has recently come up with a new algorithm, which receives a string as an input. Let's represent the input string of the algorithm as q = q_1q_2... q_{k}. The algorithm consists of two steps:
Find any c... | ```python
def main():
(l, xyz, res) = ([(0, 0, 0)], [0, 0, 0], [])
for c in input():
xyz[ord(c) - 120] += 1
l.append(tuple(xyz))
for _ in range(int(input())):
(a, b) = list(map(int, input().split()))
if b - a > 1:
xyz = [i - j for (i, j) in zip(l[b], l[a - 1])]
res.append(('NO', 'YES')[max(xyz) - min(x... | vfc_134689 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/367/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "zyxxxxxxyyz\n5\n5 5\n1 3\n1 11\n1 4\n3 6\n",
"output": "YES\nYES\nNO\nYES\nNO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "yxzyzxzzxyyzzxxxzyyzzyzxxzxyzyyzxyzxyxxyzxyxzyzxyzxyyxzzzyzxyy... |
taco | verifiable_code | https://atcoder.jp/contests/abc167/tasks/abc167_c | Solve the following coding problem using the programming language python:
Takahashi, who is a novice in competitive programming, wants to learn M algorithms.
Initially, his understanding level of each of the M algorithms is 0.
Takahashi is visiting a bookstore, where he finds N books on algorithms.
The i-th book (1\le... | ```python
f = lambda : map(int, input().split())
(n, m, x) = f()
(lc, ll) = ([], [])
for _ in range(n):
(c, *l) = f()
lc += [c]
ll += [l]
a = 10 ** 9
for i in range(2 ** n):
(lm, t) = ([0] * m, 0)
for j in range(n):
if i >> j & 1:
for k in range(m):
lm[k] += ll[j][k]
t += lc[j]
if all((s >= x for s in... | vfc_134693 | {
"difficulty": "easy",
"memory_limit": "1024.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://atcoder.jp/contests/abc167/tasks/abc167_c",
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 3 10\n60 2 2 4\n70 8 7 9\n50 2 3 9\n",
"output": "120\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 3 10\n100 3 1 4\n100 1 5 9\n100 2 6 5\n",
"output": "-1\n",
"type": "s... |
taco | verifiable_code | Solve the following coding problem using the programming language python:
View Russian Translation
One day Benny decides to miss lessons. But as she is a very good pig she will do her homework anyway. She doesn't know anything about the content of this lessons. Your task is to help her.
The problem is following: you... | ```python
# Hacker Earth
# Problem Statement
# Import libraries
import sys
import math
import pdb
def getOneLine(inFile):
if inFile != "":
return(inFile.readline().rstrip())
return(sys.stdin.readline().rstrip())
def main():
# Toggle mode of input
# inFile = open("input5.txt", 'r')
inFile = ""
# number ... | vfc_134697 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4742834 4535295 21",
"output": "258544.99",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6165574 5038223 90",
"output": "0.28",
"type": "stdin_stdout"
},
{
"fn_nam... | |
taco | verifiable_code | https://codeforces.com/problemset/problem/858/E | Solve the following coding problem using the programming language python:
The All-Berland National Olympiad in Informatics has just ended! Now Vladimir wants to upload the contest from the Olympiad as a gym to a popular Codehorses website.
Unfortunately, the archive with Olympiad's data is a mess. For example, the fi... | ```python
n = int(input())
t = [1] + [0] * n
(b, a) = d = ([], [])
(h, s) = ([], [])
for i in range(n):
(f, k) = input().split()
d[int(k)].append(f)
m = len(a)
for i in a:
if i.isdigit() and i[0] != '0':
j = int(i)
if 0 < j <= m:
t[j] = 1
elif m < j <= n:
t[j] = -1
else:
s.append(i)
else:
s.appen... | vfc_134701 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/858/E",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n01 0\n2 1\n2extra 0\n3 1\n99 0\n",
"output": "4\nmove 3 1\nmove 01 5\nmove 2extra 4\nmove 99 3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n1 0\n2 1\n",
"output": "3\nmove 1... |
taco | verifiable_code | https://www.codechef.com/problems/SUMANDOR | Solve the following coding problem using the programming language python:
Chef has two integers X and S. He is interested in sequences of non-negative integers such that the sum of their elements is S and the [bitwise OR] of their elements is X. Chef would like to know the shortest possible length such a sequence can ... | ```python
def binarize(num):
powers = []
power = 0
while num > 0:
bit = num % 2
num = num // 2
if bit:
powers.append(power)
power += 1
return list(reversed(powers))
def doit(x, s):
if s < x:
return -1
origs = s
repeats = 1
s = s - x
origs = s
binx = binarize(x)
mintimes = 0
for power in binx:
... | vfc_134705 | {
"difficulty": "very_hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/SUMANDOR",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n13 23\n6 13\n1 25\n",
"output": "3\n-1\n25\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/UNICOLOR | Solve the following coding problem using the programming language python:
Read problem statements in [Russian], [Bengali], and [Mandarin Chinese] as well.
In a school, there are $C$ clubs (numbered $1$ through $C$) that students can participate in. Each student can be in zero, one or multiple clubs.
Tomorrow, there ... | ```python
from sys import stdin
input = stdin.readline
mod = 998244353
class dsu:
def __init__(self, n):
self.p = [0] * (n + 1)
self.rank = [0] * (n + 1)
for i in range(1, n + 1):
self.p[i] = i
def find(self, node):
if self.p[node] == node:
return node
self.p[node] = self.find(self.p[node])
retur... | vfc_134709 | {
"difficulty": "very_hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/UNICOLOR",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n2 6 3\n2\n1 2 5 6\n1\n4 6",
"output": "9",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/delete-a-node-from-bst/1 | Solve the following coding problem using the programming language python:
Given a Binary Search Tree and a node value X. Delete the node with the given value X from the BST. If no node with value x exists, then do not make any change.
Example 1:
Input:
2
/ \
1 3
X = 12
Output: 1 2 3
Explanation: In... | ```python
def deleteNode(root, X):
if not root:
return None
if X < root.data:
root.left = deleteNode(root.left, X)
elif X > root.data:
root.right = deleteNode(root.right, X)
else:
if root.left is None and root.right is None:
return None
elif not root.left:
current = root.right
root = None
retu... | vfc_134713 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/delete-a-node-from-bst/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": "deleteNode",
"input": "2\n / \\\n 1 3\nX = 12",
"output": "1 2 3",
"type": "function_call"
},
{
"fn_name": "deleteNode",
"input": "1\n \\\n 2\n \\\n ... |
taco | verifiable_code | https://codeforces.com/problemset/problem/199/B | Solve the following coding problem using the programming language python:
A renowned abstract artist Sasha, drawing inspiration from nowhere, decided to paint a picture entitled "Special Olympics". He justly thought that, if the regular Olympic games have five rings, then the Special ones will do with exactly two ring... | ```python
import os
import sys
from io import BytesIO, IOBase
from collections import Counter
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 i... | vfc_134714 | {
"difficulty": "hard",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/199/B",
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "70 92 20 40\n99 92 9 49\n",
"output": "0",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "0 73 20 40\n59 73 39 100\n",
"output": "1",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/225/E | Solve the following coding problem using the programming language python:
Consider the following equation:
<image> where sign [a] represents the integer part of number a.
Let's find all integer z (z > 0), for which this equation is unsolvable in positive integers. The phrase "unsolvable in positive integers" means ... | ```python
print([0, 1, 3, 15, 63, 4095, 65535, 262143, 73741816, 536396503, 140130950, 487761805, 319908070, 106681874, 373391776, 317758023, 191994803, 416292236, 110940209, 599412198, 383601260, 910358878, 532737550, 348927936, 923450985, 470083777, 642578561, 428308066, 485739298, 419990027, 287292016, 202484167, 38... | vfc_134722 | {
"difficulty": "hard",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/225/E",
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "14\n",
"output": " 373391776\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "38\n",
"output": " ... |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Problem statement
There is a rational number sequence $ X_0, X_1, X_2, ..., X_N $. Each term is defined as follows.
1. $ X_0 = 0 $
2. $ X_i = X_ {i-1} $ $ op_i $ $ Y_i $ ($ 1 \ leq i \ leq N $). However, $ op_i $ is $ + $, $ − $, $ × $, $ ÷ $... | ```python
m = 10000000019
x = 0
def mod(x):
return (x % m + m) % m
def pow(x, a):
ret = 1
while a:
if a & 1:
ret = mod(x * ret)
x = mod(x * x)
a >>= 1
return ret
for _ in range(int(input())):
(o, y) = map(int, input().split())
if o == 1:
x = (x + y) % m
elif o == 2:
x = (x - y) % m
elif o == 3:
... | vfc_134726 | {
"difficulty": "unknown_difficulty",
"memory_limit": "134.217728 megabytes",
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "1.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n0 1\n4 2\n2 4\n3 4",
"output": "-16\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n0 1\n4 2\n2 1\n3 4",
"output": "-4\n",
"type": "stdin_stdout"
}
]
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.