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/1056/B | Solve the following coding problem using the programming language python:
Arkady and his friends love playing checkers on an $n \times n$ field. The rows and the columns of the field are enumerated from $1$ to $n$.
The friends have recently won a championship, so Arkady wants to please them with some candies. Remembe... | ```python
from collections import defaultdict, deque, Counter
from sys import stdin, stdout
from heapq import heappush, heappop
import math
import io
import os
import math
import bisect
def isPrime(x):
for i in range(2, x):
if i * i > x:
break
if x % i == 0:
return False
return True
def ncr(n, r, p):
num... | vfc_141878 | {
"difficulty": "medium_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1056/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 3\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 5\n",
"output": "13\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "100000... |
taco | verifiable_code | https://www.codechef.com/problems/SUMNEQ | Solve the following coding problem using the programming language python:
Alice has a positive integer N. She is wondering how many ordered pairs of positive integers (i, j) exist such that i + j = N.
Help Alice figure out the answer.
Note that since the pairs are ordered, (1, 2) and (2, 1) are considered different... | ```python
a = int(input())
if a % 2 == 0:
print(a - 1)
else:
print(a - 1)
``` | vfc_141882 | {
"difficulty": "easy",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/SUMNEQ",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1",
"output": "0",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2",
"output": "1",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.hackerrank.com/challenges/highway-construction/problem | Solve the following coding problem using the programming language python:
You are planning the next FIFA World Cup and you are counting the number of highways that need to be built to connect the cities with the venue.
Your country has $n$ cities and all cities lie on a single straight road called “Highway Road”. If... | ```python
import time
from fractions import Fraction as fr
from math import floor
def euclidean_alg(a, b):
rm1 = a
sm1 = 1
tm1 = 0
r = b
s = 0
t = 1
while r != 0:
q = rm1 // r
temp_r = rm1
temp_s = sm1
temp_t = tm1
rm1 = r
sm1 = s
tm1 = t
r = temp_r - q * rm1
s = temp_s - q * sm1
t = temp_t ... | vfc_141886 | {
"difficulty": "medium_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.hackerrank.com/challenges/highway-construction/problem",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n4 2\n",
"output": "13\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/198/B | Solve the following coding problem using the programming language python:
Vasya plays a computer game with ninjas. At this stage Vasya's ninja should get out of a deep canyon.
The canyon consists of two vertical parallel walls, their height is n meters. Let's imagine that we split these walls into 1 meter-long areas ... | ```python
from sys import stdin, stdout
from collections import deque
(n, k) = map(int, stdin.readline().split())
maps = []
maps.append(list(stdin.readline() + '-'))
maps.append(list(stdin.readline() + '-'))
visit = [[0, 0] for i in range(n + 1)]
visit[0][0] = 1
queue = deque()
label = 0
queue.append((0, -1, 0))
while ... | vfc_141890 | {
"difficulty": "medium",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/198/B",
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 1\n-X\nX-\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "25 3\n-XXXXX-XXXXX-XXXXX-X-XXXX\nXXX-XXXXX-XXXXX-X-----X--\n",
"output": "YES\n",
"type": "stdin_... |
taco | verifiable_code | https://www.codechef.com/problems/CHN15A | Solve the following coding problem using the programming language python:
Gru has not been in the limelight for a long time and is, therefore, planning something particularly nefarious. Frustrated by his minions' incapability which has kept him away from the limelight, he has built a transmogrifier — a machine which m... | ```python
t = int(input())
for i in range(t):
a = [int(i) for i in input().split()]
b = a[1]
a = [int(i) for i in input().split()]
k = 0
for i in a:
if (i + b) % 7 == 0:
k = k + 1
print(k)
``` | vfc_141894 | {
"difficulty": "easy",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/CHN15A",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n5 10\n2 4 1 35 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n5 10\n2 4 1 62 1",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name":... |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Mr. A loves sweets, but recently his wife has told him to go on a diet. One day, when Mr. A went out from his home to the city hall, his wife recommended that he go by bicycle. There, Mr. A reluctantly went out on a bicycle, but Mr. A, who likes... | ```python
from itertools import combinations
from heapq import heappop, heappush
import sys
sys.setrecursionlimit(1000000)
INF = 10 ** 20
def convert(s, m, n):
if s == 'H':
return 0
if s == 'D':
return 1
if s[0] == 'C':
return int(s[1:]) + 1
if s[0] == 'L':
return int(s[1:]) + m + 1
def get_cost(start, m,... | vfc_141898 | {
"difficulty": "unknown_difficulty",
"memory_limit": "134.217728 megabytes",
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "8.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 1 2 5\n35\nH L1 5\nC1 D 6\nC1 H 12\nL1 D 10\nC1 L1 20\n2 1 4 6\n100 70\nH L1 5\nC1 L1 12\nC1 D 11\nC2 L1 7\nC2 D 10\nL1 D 8\n0 0 0 0",
"output": "1\n-2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... | |
taco | verifiable_code | https://codeforces.com/problemset/problem/1364/C | Solve the following coding problem using the programming language python:
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that:
for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$.
The $MEX$ of a set of integers is the smallest non-negative integer that doesn't ... | ```python
n = int(input())
l = list(map(int, input().split()))
ans = []
d = [False] * 202000
for i in l:
d[i] = True
for i in range(202000):
if not d[i]:
ans.append(i)
lp = 1
print(ans[0], end=' ')
for i in range(1, n):
if l[i] != l[i - 1]:
print(l[i - 1], end=' ')
else:
print(ans[lp], end=' ')
lp += 1
prin... | vfc_141902 | {
"difficulty": "medium_hard",
"memory_limit": "256 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1364/C",
"time_limit": "1 second"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 2 3\n",
"output": "0 1 2 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n0 0 0 2\n",
"output": "1 3 4 0 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
taco | verifiable_code | https://codeforces.com/problemset/problem/1619/D | Solve the following coding problem using the programming language python:
Vlad has $n$ friends, for each of whom he wants to buy one gift for the New Year.
There are $m$ shops in the city, in each of which he can buy a gift for any of his friends. If the $j$-th friend ($1 \le j \le n$) receives a gift bought in the s... | ```python
t = int(input())
while t:
def fun(num, n, m, li):
arr = [False] * m
flag = 0
for i in range(n):
c = 0
for j in range(m):
if li[i][j] >= num:
arr[j] = True
c += 1
if c > 1:
flag = 1
if not flag and m > 1:
return False
ans = True
for i in arr:
ans = ans and i
ret... | vfc_141906 | {
"difficulty": "medium_hard",
"memory_limit": "256 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1619/D",
"time_limit": "2 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n\n2 2\n1 2\n3 4\n\n4 3\n1 3 1\n3 1 1\n1 2 2\n1 1 3\n\n2 3\n5 3 4\n2 5 1\n\n4 2\n7 9\n8 1\n9 6\n10 8\n\n2 4\n6 5 2 1\n7 9 7 2\n",
"output": "3\n2\n4\n8\n2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,... |
taco | verifiable_code | https://codeforces.com/problemset/problem/1762/B | Solve the following coding problem using the programming language python:
An array $b$ of $m$ positive integers is good if for all pairs $i$ and $j$ ($1 \leq i,j \leq m$), $\max(b_i,b_j)$ is divisible by $\min(b_i,b_j)$.
You are given an array $a$ of $n$ positive integers. You can perform the following operation:
Se... | ```python
for s in [*open(0)][2::2]:
print(len((a := s.split())))
i = 0
for x in map(int, a):
i += 1
print(i, 2 ** len(f'{x:b}') - x)
``` | vfc_141910 | {
"difficulty": "easy",
"memory_limit": "256 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1762/B",
"time_limit": "1 second"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n4\n2 3 5 5\n2\n4 8\n5\n3 4 343 5 6\n3\n31 5 17\n",
"output": "4\n1 2\n2 1\n3 3\n4 3\n2\n1 4\n2 8\n5\n1 1\n2 4\n3 169\n4 3\n5 2\n3\n1 1\n2 3\n3 15\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/958/F2 | Solve the following coding problem using the programming language python:
There is unrest in the Galactic Senate. Several thousand solar systems have declared their intentions to leave the Republic. Master Heidi needs to select the Jedi Knights who will go on peacekeeping missions throughout the galaxy. It is well-kno... | ```python
INF = 1 << 60
(n, m) = map(int, input().split())
a = list(map(int, input().split()))
Constraint = [0] + list(map(int, input().split()))
pos = 0
satisfied_color = 0
for i in range(1, m + 1):
if Constraint[i] == 0:
satisfied_color += 1
GETCOLOR = [0] * (n + 1)
ans = INF
waste = 0
for i in range(n):
while sa... | vfc_141915 | {
"difficulty": "medium_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/958/F2",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "8 3\n3 3 1 2 2 1 1 3\n3 1 1\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/maximize-xor0829/1 | Solve the following coding problem using the programming language python:
Given a number X find the total numbers A such that A XOR X >= X, and 1<=A<=X.
Example 1:
Input: 10
Output: 5
Explanation: Calculating XOR of 10 with
{1, 4, 5, 6, 7} give values greater than
equal to 10.
Example 2:
Input: 5
Output: 2
Explana... | ```python
class Solution:
def maximize_xor_count(self, n):
ans = 0
k = 1
while n:
if n & 1 == 0:
ans += k
n >>= 1
k <<= 1
return ans
``` | vfc_141919 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/maximize-xor0829/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10",
"output": "5",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5",
"output": "2",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
You have a long list of tasks that you need to do today. To accomplish task i you need Mi minutes, and the deadline for this task is Di. You need not complete a task at a stretch. You can complete a part of it, switch to another task, and then s... | ```python
import sys
import math
stdin = sys.stdin
Mid= lambda x : ((x[0] + x[1])>>1)
Lowbit = lambda x : (x&(-x))
used = {}
class Task:
def __init__(self , _d , _m , _index):
self.d = int(_d)
self.m = int(_m)
self.index = int(_index)
def __lt__(self , other):
if (self.d == other.d):
return self.m > o... | vfc_141920 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n2 2\n1 1\n4 3\n10 1\n2 1",
"output": "0 \n1 \n2 \n2 \n3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "84\n47 778\n20 794\n32 387\n157 650\n158 363\n20 691\n68 764\n71 541\n163 173\n... | |
taco | verifiable_code | https://www.hackerrank.com/challenges/find-the-running-median/problem | Solve the following coding problem using the programming language python:
The median of a set of integers is the midpoint value of the data set for which an equal number of integers are less than and greater than the value. To find the median, you must first sort your set of integers in non-decreasing order, then:
If... | ```python
import heapq
(L, H) = ([], [])
for _ in range(int(input())):
a = int(input())
if not H:
heapq.heappush(H, a)
elif len(H) > len(L):
if H[0] < a:
b = heapq.heappushpop(H, a)
heapq.heappush(L, -b)
else:
heapq.heappush(L, -a)
elif -L[0] > a:
b = -heapq.heappushpop(L, -a)
heapq.heappush(H, b... | vfc_141924 | {
"difficulty": "medium_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.hackerrank.com/challenges/find-the-running-median/problem",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n12\n4\n5\n3\n8\n7\n",
"output": "12.0\n8.0\n5.0\n4.5\n5.0\n6.0\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/7a33c749a79327b2889d420dd80342fff33aac6d/1 | Solve the following coding problem using the programming language python:
Given an array Arr of size N containing positive integers. Find the maximum sum of a subsequence such that no two numbers in the sequence should be adjacent in the array.
Example 1:
Input:
N = 6
Arr[] = {5, 5, 10, 100, 10, 5}
Output: 110
Explan... | ```python
class Solution:
def findMaxSum(self, arr, n):
if n < 3:
m = arr[0]
for i in range(n):
m = max(m, arr[i])
return m
d = [arr[0], arr[1], arr[2] + arr[0]]
for i in range(3, n):
d[i % 3] = max(d[(i - 2) % 3] + arr[i], d[(i - 3) % 3] + arr[i])
return max(d[(n - 1) % 3], d[(n - 2) % 3], d[... | vfc_141928 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/7a33c749a79327b2889d420dd80342fff33aac6d/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N = 6\r\nArr[] = {5, 5, 10, 100, 10, 5}",
"output": "110",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Suppose you have a string S which has length N and is indexed from 0 to N−1. String R is the reverse of the string S. The string S is funny if the condition |Si−Si−1|=|Ri−Ri−1| is true for every i from 1 to N−1.
(Note: Given a string str, stri ... | ```python
for _ in range(int(input())):
s = list(map(ord, input().strip()))
r = s[::-1]
ans = "Funny"
for i in range(1, len(s)):
if abs(s[i] - s[i-1]) != abs(r[i] - r[i-1]):
ans = "Not Funny"
break
print(ans)
``` | vfc_141933 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\nacxz\nbcxz",
"output": "Funny\nNot Funny",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\nivvkxq\nivvkx",
"output": "Funny\nNot Funny\nFunny\nFunny\nNot Funny\nFunny\nNot Funny\nN... | |
taco | verifiable_code | https://codeforces.com/problemset/problem/389/A | Solve the following coding problem using the programming language python:
Fox Ciel is playing a game with numbers now.
Ciel has n positive integers: x_1, x_2, ..., x_{n}. She can do the following operation as many times as needed: select two different indexes i and j such that x_{i} > x_{j} hold, and then apply assi... | ```python
def findMaxSubarraySum(arr, n, sum):
curr_sum = arr[0]
max_sum = 0
start = 0
for i in range(1, n):
if curr_sum <= sum:
max_sum = max(max_sum, curr_sum)
while curr_sum + arr[i] > sum and start < i:
curr_sum -= arr[start]
start += 1
curr_sum += arr[i]
if curr_sum <= sum:
max_sum = max(max_... | vfc_141937 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/389/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n1 2\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/count-substring/1 | Solve the following coding problem using the programming language python:
Given string s consisting only a,b,c. return the number of substrings containing at least one occurrence of all these characters a, b, and c.
Example 1:
Input:
abcabc
Output:
10
Explanation:
The required substrings are "abc", "abca", "abcab", "... | ```python
class Solution:
def countSubstring(self, s):
n = len(s)
j = 0
(a, b, c) = (0, 0, 0)
ans = 0
for i in range(n):
if s[i] == 'a':
a += 1
elif s[i] == 'b':
b += 1
else:
c += 1
while a > 0 and b > 0 and (c > 0):
ans += n - i
if s[j] == 'a':
a -= 1
elif s[j] == '... | vfc_141941 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/count-substring/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "abcabc",
"output": "10",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "aaacb",
"output": "3",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/573/B | Solve the following coding problem using the programming language python:
Limak is a little bear who loves to play. Today he is playing by destroying block towers. He built n towers in a row. The i-th tower is made of h_{i} identical blocks. For clarification see picture for the first sample.
Limak will repeat the fo... | ```python
x = int(input())
mas = list(map(int, input().split(' ')))
mas2 = [0] * x
mas2[0] = 1
for i in range(1, x):
mas2[i] = min(mas[i], mas2[i - 1] + 1)
mas2[-1] = 1
for i in range(2, x + 1):
mas2[-i] = min(mas[-i], mas2[-i + 1] + 1, mas2[-i])
print(max(mas2))
``` | vfc_141947 | {
"difficulty": "medium_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/573/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n2 1 4 6 2 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7\n3 3 3 1 3 3 3\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,... |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/the-even-array3825/1 | Solve the following coding problem using the programming language python:
Given a string contains 'E' and 'O', 'E' represents a number is even and 'O' represents a number is odd. To make an element even, you can add 1 to any odd element of the array. Also, when any element of the array is converted to even, any neighb... | ```python
class Solution:
def convertToEven(self, s):
c = 0
t = 0
for i in range(len(s)):
if s[i] == 'E':
if t:
c += 1
t = 0
else:
t += 1
if t:
c += 1
return c
``` | vfc_141951 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/the-even-array3825/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "S = \"EOOE\"",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "S = \"EOOOOE\"",
"output": "1",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1102/A | Solve the following coding problem using the programming language python:
You are given an integer sequence $1, 2, \dots, n$. You have to divide it into two sets $A$ and $B$ in such a way that each element belongs to exactly one set and $|sum(A) - sum(B)|$ is minimum possible.
The value $|x|$ is the absolute value of... | ```python
gi = lambda : list(map(int, input().strip().split()))
(n,) = gi()
print(n * (n + 1) // 2 % 2)
``` | vfc_141952 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1102/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n",
... |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/largest-subarray-of-0s-and-1s/1 | Solve the following coding problem using the programming language python:
Given an array of 0s and 1s. Find the length of the largest subarray with equal number of 0s and 1s.
Example 1:
Input:
N = 4
A[] = {0,1,0,1}
Output: 4
Explanation: The array from index [0...3]
contains equal number of 0's and 1's.
Thus maximum l... | ```python
class Solution:
def maxLen(self, arr, N):
for i in range(N):
if arr[i] == 0:
arr[i] = -1
s = 0
a = 0
d = {0: -1}
for i in range(N):
s = s + arr[i]
if s not in d:
d[s] = i
elif i - d[s] > a:
a = i - d[s]
return a
``` | vfc_141956 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/largest-subarray-of-0s-and-1s/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N = 4\nA[] = {0,1,0,1}",
"output": "4",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "N = 5\nA[] = {0,0,1,0,0}",
"output": "2",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/WGHTNUM | Solve the following coding problem using the programming language python:
VK gave a problem to Chef, but Chef is too lazy, so he asked you to solve the problem for him. The statement of the problem follows.
Consider an integer with $N$ digits (in decimal notation, without leading zeroes) $D_1, D_2, D_3, \dots, D_N$. H... | ```python
t = int(input())
for _ in range(t):
(n, w) = map(int, input().split())
count = 0
mod = 10 ** 9 + 7
if w >= 0:
count = 9 - abs(w)
else:
count = 10 - abs(w)
if w >= -9 and w <= 8:
print(pow(10, n - 2, mod) * count % mod)
else:
print(0)
``` | vfc_141957 | {
"difficulty": "medium_hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/WGHTNUM",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n2 3\n",
"output": "6\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/CHEFSETC | Solve the following coding problem using the programming language python:
Chef likes problems which using some math. Now he asks you to solve next one. You have 4 integers, Chef wondering is there non-empty subset which has sum equals 0.
-----Input-----
The first line of input contains T - number of test cases.
Each... | ```python
t = int(input())
while t != 0:
l = list(map(int, input().split()))
if 0 in l:
print('Yes')
elif sum(l) == 0:
print('Yes')
elif l[0] + l[1] == 0 or l[1] + l[2] == 0 or l[2] + l[3] == 0 or (l[0] + l[2] == 0) or (l[0] + l[3] == 0) or (l[1] + l[3] == 0) or (l[0] + l[1] + l[2] == 0) or (l[1] + l[2] + l[3] ... | vfc_141961 | {
"difficulty": "easy",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/CHEFSETC",
"time_limit": "0.5 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 2 0 3\n1 2 4 -1\n1 2 3 4\n",
"output": "Yes\nYes\nNo\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/608/A | Solve the following coding problem using the programming language python:
Saitama accidentally destroyed a hotel again. To repay the hotel company, Genos has volunteered to operate an elevator in one of its other hotels. The elevator is special — it starts on the top floor, can only move down, and has infinite capacit... | ```python
def read():
inputs = input().strip()
return list(map(int, inputs.split()))
def read_pair():
return map(int, input().split(' '))
(n, s) = read_pair()
mx = s
for i in range(n):
(x, y) = read_pair()
mx = max(mx, x + y)
print(mx)
``` | vfc_141965 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/608/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 7\n2 1\n3 8\n5 2\n",
"output": "11\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/buy-maximum-stocks-if-i-stocks-can-be-bought-on-i-th-day/1 | Solve the following coding problem using the programming language python:
In a stock market, there is a product with its infinite stocks. The stock prices are given for N days, where price[i] denotes the price of the stock on the i^{th} day.
There is a rule that a customer can buy at most i stock on the i^{th} day.
If... | ```python
from typing import List
class Solution:
def buyMaximumProducts(self, n: int, k: int, price: List[int]) -> int:
prices = [(val, i) for (i, val) in enumerate(price, start=1)]
prices.sort(key=lambda x: (x[0], -x[1]))
cnt = 0
for (val, i) in prices:
if i * val <= k:
cnt += i
k -= i * val
... | vfc_141969 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/buy-maximum-stocks-if-i-stocks-can-be-bought-on-i-th-day/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "price[] = { 10, 7, 19 }\r\nk = 45",
"output": "4",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "price[] = { 7, 10, 4 }\r\nk = 100",
"output": "6",
"type": "stdin_stdout"
}
... |
taco | verifiable_code | Solve the following coding problem using the programming language python:
In code world all genders are considered equal ( It means their is nothing like male or female). Now their are N distinct persons living in this hypothetical world. Each person can pair up with any other person or can even remain single. One d... | ```python
mod = 10**9 + 7
MAX = 10**6 + 5
def precompute(A):
for i in range(2, MAX):
A[i] = (A[i - 1] + A[i - 2] * (i - 1)) % mod
if __name__ == '__main__':
A = [1] * MAX
precompute(A)
for _ in range(eval(input())):
print(A[eval(input())])
``` | vfc_141974 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "100000\n99992\n99993\n99994\n99995\n99996\n99997\n99998\n99999\n100000\n100001\n100002\n100003\n100004\n100005\n100006\n100007\n100008\n100009\n100010\n100011\n100012\n100013\n100014\n100015\n100016\n100017\n100018\n100019\n100020\... | |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/check-perfect-square5253/1 | Solve the following coding problem using the programming language python:
Given a positive integer N, check if it is a perfect square or not.
Note: Try to solve the question using only addition and subtraction operation.
Example 1:
Input:
N = 35
Output:
0
Explanation:
35 is not a perfect
square.
Example 2:
Input:... | ```python
class Solution:
def checkPerfectSquare(ob, N):
k = N ** 0.5
if int(k) * int(k) == N:
return 1
return 0
``` | vfc_141978 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/check-perfect-square5253/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N = 35",
"output": "0",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "N = 49",
"output": "1",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1750/B | Solve the following coding problem using the programming language python:
A binary string is a string consisting only of the characters 0 and 1. You are given a binary string $s$.
For some non-empty substring$^\dagger$ $t$ of string $s$ containing $x$ characters 0 and $y$ characters 1, define its cost as:
$x \cdot y... | ```python
import sys
input = sys.stdin.readline
out = []
t = int(input())
for _ in range(t):
input()
s = input().strip()
poss = []
z = o = tz = to = 0
for c in s:
if c == '0':
tz += 1
z += 1
o = 0
poss.append(z * z)
else:
to += 1
o += 1
z = 0
poss.append(o * o)
poss.append(tz * to)
ou... | vfc_141979 | {
"difficulty": "easy",
"memory_limit": "256 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1750/B",
"time_limit": "1 second"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n5\n11100\n7\n1100110\n6\n011110\n7\n1001010\n4\n1000\n1\n0\n",
"output": "9\n12\n16\n12\n9\n1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n7\n0111111\n",
"output": "36\n",
... |
taco | verifiable_code | https://www.codechef.com/problems/COVID_19 | Solve the following coding problem using the programming language python:
Mr. Chef is the manager of the Code cinemas and after a long break, the theatres are now open to the public again. To compensate for the loss in revenue due to Covid-19, Mr. Chef wants to maximize the profits for every show from now on and at th... | ```python
from math import ceil
for _ in range(int(input())):
(n, m) = map(int, input().split())
print(ceil(m / 2) * ceil(n / 2))
``` | vfc_141983 | {
"difficulty": "easy",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/COVID_19",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 5\n3 3\n4 4",
"output": "3\n4\n4",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/FARAWAY | Solve the following coding problem using the programming language python:
Chef has an array A of size N and an integer M, such that 1 ≤ A_{i} ≤ M for every 1 ≤ i ≤ N.
The *distance* of an array B from array A is defined as:
d(A, B) = \sum_{i=1}^N |A_{i} - B_{i}|
Chef wants an array B of size N, such that 1 ≤ B_{i} ... | ```python
T = int(input())
for i in range(0, T):
(N, M) = map(int, input().split())
n = 0
A = list(map(int, input().split()))
for x in range(0, N):
if abs(A[x] - M) > abs(A[x] - 1):
n = n + abs(A[x] - M)
else:
n = n + abs(A[x] - 1)
print(n)
``` | vfc_141988 | {
"difficulty": "easy",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/FARAWAY",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n2 6\n3 5\n4 1\n1 1 1 1\n5 7\n2 3 4 5 6\n7 24\n23 7 6 16 12 4 24\n",
"output": "7\n0\n21\n127\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/456/D | Solve the following coding problem using the programming language python:
Andrew, Fedor and Alex are inventive guys. Now they invent the game with strings for two players.
Given a group of n non-empty strings. During the game two players build the word together, initially the word is empty. The players move in turns.... | ```python
input = __import__('sys').stdin.readline
class Node:
def __init__(self):
self.end = False
self.nxt = {}
self.w = None
self.l = None
def __setitem__(self, i, x):
self.nxt[i] = x
def __getitem__(self, i):
return self.nxt[i]
def makeTrie(strs):
root = Node()
for s in strs:
n = root
for ... | vfc_141992 | {
"difficulty": "hard",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/456/D",
"time_limit": "1.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 2\nwelcome\nto\nthe\nmatrix\nneo\n",
"output": "First\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 4\ndog\ncat\ncow\nhot\nice\nlol\n",
"output": "Second\n",
"type": "std... |
taco | verifiable_code | https://codeforces.com/problemset/problem/515/B | Solve the following coding problem using the programming language python:
Drazil has many friends. Some of them are happy and some of them are unhappy. Drazil wants to make all his friends become happy. So he invented the following plan.
There are n boys and m girls among his friends. Let's number them from 0 to n - ... | ```python
def slve(n, m, b, g):
bo = [0] * n
gi = [0] * m
i = 0
for i in range(1, len(b)):
bo[b[i]] = 1
for i in range(1, len(g)):
gi[g[i]] = 1
while i <= 10000:
if bo[i % n] == 1 or gi[i % m] == 1:
(bo[i % n], gi[i % m]) = (1, 1)
if bo == [1] * n and gi == [1] * m:
return 'Yes'
i += 1
return 'No... | vfc_141997 | {
"difficulty": "easy",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/515/B",
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "76 72\n29 4 64 68 20 8 12 50 42 46 0 70 11 37 75 47 45 29 17 19 73 9 41 31 35 67 65 39 51 55\n25 60 32 48 42 8 6 9 7 31 19 25 5 33 51 61 67 55 49 27 29 53 39 65 35 13\n",
"output": "Yes\n",
"type": "stdin_stdout"
}
... |
taco | verifiable_code | https://codeforces.com/problemset/problem/879/B | Solve the following coding problem using the programming language python:
n people are standing in a line to play table tennis. At first, the first two players in the line play a game. Then the loser goes to the end of the line, and the winner plays with the next person from the line, and so on. They play until someon... | ```python
(n, k) = map(int, input().split())
a = [*map(int, input().split())]
current = 0
ans = a[0]
i = 1
while i < n:
if ans > a[i]:
current += 1
else:
current = 1
ans = a[i]
if current == k:
break
i += 1
print(ans)
``` | vfc_142002 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/879/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 2\n1 2\n",
"output": "2 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 2\n3 1 2 4\n",
"output": "3 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"inpu... |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Xsquare likes strings a lot but much more, he likes palindromic strings. Today, he has a string S consisting of lower case English letters. Xsquare wants to convert his string S to a palindromic string. For the above purpose to be served , he ca... | ```python
'''
# Read input from stdin and provide input before running code
name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
def palindrome():
testcases=eval(input())
for cases in range(testcases):
string_input=input()
dict_hash=dict()
length_string=len(string_input)
length_stringinputset=... | vfc_142006 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "100\naciicjaabfdaccigahdijigdjghbafjibfegbaehbadbgbacgbhhadahgbabbigghjhihbadjddfie\nmbmfgfaqqfbodcmnnfplniododpjcagiglnoprdqqdgmhbqkoqadecccmbnndqgpbqe\nccacbcddabdaadaabacdcbbcbbdddccadcdcdcbdbbdcdbbccbdbacaccacdaaccbaddaacbcacba... | |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/smith-number4132/1 | Solve the following coding problem using the programming language python:
Given a number n, the task is to find out whether this number is a Smith Number or not. A Smith Number is a composite number whose sum of digits is equal to the sum of digits of its prime factorization.
Example 1:
Input:
n = 4
Output:
1
Explan... | ```python
class Solution:
def smithNum(self, n):
def f(n):
if n == 0 or n == 1:
return False
for i in range(2, int(n ** 0.5) + 1):
if n % i == 0:
return False
return True
if f(n):
return 0
temp = sum(map(int, str(n)))
div = 2
cnt = 0
while n > 1:
if n % div == 0:
n //= div... | vfc_142010 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/smith-number4132/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "n = 4",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "n = 6",
"output": "0",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Given a number X between 0 to 1000000006 find smallest positive integer Y such that the products of digits of Y modulo 1000000007 is X.
Input Format
A single integer - X
Output Format
A single integer - Y
Input Constraint
0 ≤ X ≤ 100000000... | ```python
import sys
def get_min_length_single_digit_factors(x):
original_x = x
factor_counts = [0]*10
for i in range(8):
if x < 2:
break
factor = 9-i
while x % factor == 0:
x = x/factor
factor_counts[factor] += 1
if not x==1:
return get_min_length_single_digit_factors(original_x+1000000007)
ret... | vfc_142015 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "0",
"output": "10",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "16",
"output": "28",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "220703118",
... | |
taco | verifiable_code | https://www.codechef.com/problems/KEPLERSLAW | Solve the following coding problem using the programming language python:
Kepler’s Law states that the planets move around the sun in elliptical orbits with the sun at one focus. Kepler's 3rd law is The Law of Periods, according to which:
The square of the time period of the planet is directly proportional to the cub... | ```python
T = int(input())
for _ in range(T):
(time_1, time_2, R_1, R_2) = map(int, input().split())
planet_1k = time_1 ** 2 / R_1 ** 3
planet_2k = time_2 ** 2 / R_2 ** 3
if planet_1k == planet_2k:
print('Yes')
else:
print('No')
``` | vfc_142019 | {
"difficulty": "easy",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/KEPLERSLAW",
"time_limit": "0.5 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 1 1 1\n1 2 3 4\n1 8 2 8",
"output": "Yes\nNo\nYes",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Dee Dee went to market to buy some eggs. There are 2 type of egg cartons available in the shop. One type contains 6 eggs and the other type contains 8 eggs. Dee Dee wants to buy exactly N eggs. Calculate the minimal number of egg cartons she mus... | ```python
noc = eval(input())
while noc:
noc -=1
qty = eval(input())
eights = 0
sixs = 0
nums = qty
while qty > 5:
if qty % 8 == 0:
eights += 1
qty-=8
else:
sixs +=1
qty-= 6
if eights * 8 + sixs * 6 == nums:
print(eights + sixs)
else:
print(-1)
``` | vfc_142023 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "23\n19\n20\n90\n91\n92\n93\n94\n95\n96\n97\n98\n99\n100\n44\n30\n32\n50\n26\n28\n72\n60\n58\n88",
"output": "-1\n3\n12\n-1\n12\n-1\n12\n-1\n12\n-1\n13\n-1\n13\n6\n4\n4\n7\n4\n4\n9\n8\n8\n11",
"type": "stdin_stdout"
... | |
taco | verifiable_code | https://codeforces.com/problemset/problem/65/A | Solve the following coding problem using the programming language python:
A long time ago (probably even in the first book), Nicholas Flamel, a great alchemist and the creator of the Philosopher's Stone, taught Harry Potter three useful spells. The first one allows you to convert a grams of sand into b grams of lead, ... | ```python
from functools import reduce
from operator import mul
c = list(map(int, input().split()))
(r, h) = (reduce(mul, c[1::2], 1), reduce(mul, c[0::2], 1))
rw = r > h or (c[2] == 0 and c[3] != 0) or (c[0] == 0 and c[1] * c[3] != 0)
print('Ron' if rw else 'Hermione')
``` | vfc_142027 | {
"difficulty": "medium_hard",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/65/A",
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "279 0 254 964 449 143\n",
"output": "Hermione\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "0 891 0 0 0 529\n",
"output": "Hermione\n",
"type": "stdin_stdout"
},
{
... |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Big P has recently become very famous among girls .
Big P goes to a party and every girl present there wants to dance with him. However, Big P cannot dance with all of them, because there are many of them.
Now if a girl gets to dance with Big ... | ```python
'''
# Read input from stdin and provide input before running code
name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
import sys
vals = input().split(" ")
A, B = [int(x) for x in vals]
graph, distTo, marked =[],[],[]
for i in range(A):
graph.append([])
marked.append(False)
distTo.append(-1... | vfc_142031 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 6\n0 1\n0 2\n3 2\n2 4\n4 3\n1 2",
"output": "1\n4\n2\n3\n3\n3\n4\n4\n2\n3\n4\n4\n2\n2\n3\n3\n2\n4\n3\n3\n2\n4\n3\n3\n3\n5\n4\n3\n4\n4\n4\n4\n3\n4\n3\n4\n4\n4\n3\n2\n3\n3\n1\n3\n4\n4\n3\n4\n5\n2\n3\n3\n4\n3\n4\n3\n3\n2\n5\n4... | |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/addition-of-two-square-matrices4916/1 | Solve the following coding problem using the programming language python:
Given two square matrices matrixA and matrixB of size n x n. Find the addition of these two matrices.
Note :- You don't have to return anything in this question (Refer YourTask section).
Example 1:
Input: matrixA = {{1, 2}, {3, 4}},
matrixB =... | ```python
class Solution:
def Addition(self, matrixA, matrixB):
n = len(matrixA)
for i in range(n):
for j in range(n):
matrixA[i][j] += matrixB[i][j]
return matrixA
``` | vfc_142039 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/addition-of-two-square-matrices4916/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "matrixA = {{1, 2}, {3, 4}},\r\nmatrixB = {{4, 3}, {2, 1}}",
"output": "{{5, 5}, {5, 5}}",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "matrixA = {{2, 2}, {2, 2}},\r\nmatrixB = {{3, 3}, {3, ... |
taco | verifiable_code | https://codeforces.com/problemset/problem/784/D | Solve the following coding problem using the programming language python:
-----Input-----
The only line of the input contains a string of digits. The length of the string is between 1 and 10, inclusive.
-----Output-----
Output "Yes" or "No".
-----Examples-----
Input
373
Output
Yes
Input
121
Output
No
Input
4... | ```python
p = input()
l = len(p) - 1
ans = ''
s = ['23', '10', '30', '11', '13', '12', '31', '33', '32', '21']
for x in p:
ans += s[ord(x) - 48]
if ans == ans[::-1]:
print('Yes')
else:
print('No')
``` | vfc_142040 | {
"difficulty": "hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/784/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "373\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "121\n",
"output": "No\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/empty-the-tank3831/1 | Solve the following coding problem using the programming language python:
Given a tank with capacity C litres which is completely filled in starting. At the end of every day, tank is filled with L litres of water and in the case of overflow extra water is thrown out. Now on i-th day i litres of water is taken out for ... | ```python
class Solution:
def minDaysToEmpty(self, c, l):
a = c
count = 1
while c > 0:
c = c - count
if c <= 0:
break
else:
c = c + l
if c > a:
c = a
if c != 0:
count += 1
return count
``` | vfc_142044 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/empty-the-tank3831/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "C = 5, L = 2",
"output": "4",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "C = 6, L = 1",
"output": "4",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1038/C | Solve the following coding problem using the programming language python:
Two players A and B have a list of $n$ integers each. They both want to maximize the subtraction between their score and their opponent's score.
In one turn, a player can either add to his score any element from his list (assuming his list is ... | ```python
from sys import stdin, stdout, setrecursionlimit
n = int(input())
a = sorted([int(i) for i in input().split()], reverse=True)
b = sorted([int(i) for i in input().split()], reverse=True)
cura = curb = curai = curbi = 0
for i in range(2 * n):
if i % 2 == 0:
if curbi == n or (curai < n and a[curai] >= b[curbi... | vfc_142049 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1038/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n1 4\n5 1\n",
"output": "0",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n100 100 100\n100 100 100\n",
"output": "0",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/area-of-a-triangle5739/1 | Solve the following coding problem using the programming language python:
Given three sides of a triangle A, B and C in the form of integers. Find the area of the triangle.
Note: The triangle may not exist. In such cases, the area is 0.
Example 1:
Input: A = 2, B = 2, C = 3
Output: 1.984313
Explanation:
The area forme... | ```python
from math import *
class Solution:
def findArea(self, A, B, C):
if A + B > C and A + C > B and (B + C > A):
s = (A + B + C) / 2
ar = (s * (s - A) * (s - B) * (s - C)) ** 0.5
return ar
else:
return 0
``` | vfc_142053 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/area-of-a-triangle5739/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "A = 2, B = 2, C = 3",
"output": "1.984313",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "A = 1, B = 3, C = 1",
"output": "0.000",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Example
Input
20
Output
4
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
def solve():
D = input()
N = len(D)
(*DI,) = map(int, D)
su = sum(DI)
pd = 1
for d in D:
pd *= int(d) + 1
memo = [{} for i in range(N)]
def dfs0(i, s, p):
key = (s, p)
if i == N:
return s > 0 or (s == 0 and p < pd)
if key in memo[i]:
return memo[i][key]
r = 0
for v in range(min(s, 9... | vfc_142059 | {
"difficulty": "unknown_difficulty",
"memory_limit": "268.435456 megabytes",
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "1.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "35",
"output": "42\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "13",
"output": "12\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "12",
... | |
taco | verifiable_code | https://codeforces.com/problemset/problem/84/D | Solve the following coding problem using the programming language python:
There are n animals in the queue to Dr. Dolittle. When an animal comes into the office, the doctor examines him, gives prescriptions, appoints tests and may appoint extra examination. Doc knows all the forest animals perfectly well and therefore... | ```python
import sys
from array import array
from collections import deque
def input():
return sys.stdin.buffer.readline().decode('utf-8')
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
if sum(a) < k:
print(-1)
exit()
(ok, ng) = (0, 10 ** 9 + 10)
while abs(ok - ng) > 1:
mid = ok + ng >> 1
... | vfc_142063 | {
"difficulty": "medium_hard",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/84/D",
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "20 314\n7 14 13 11 11 11 14 14 9 9 12 11 13 13 10 13 11 12 10 10\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 7\n5 1 2 5 4 3 5 2 2 4\n",
"output": "8 9 10 1 3... |
taco | verifiable_code | https://codeforces.com/problemset/problem/145/A | Solve the following coding problem using the programming language python:
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya has two strings a... | ```python
(a, b) = (input(), input())
(c, d) = (0, 0)
for i in range(len(a)):
if a[i] != b[i]:
if a[i] == '4':
c += 1
else:
d += 1
print(max(c, d))
``` | vfc_142071 | {
"difficulty": "easy",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/145/A",
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "74747474\n77777777\n",
"output": "4\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1316/B | Solve the following coding problem using the programming language python:
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is... | ```python
I = input
for _ in [0] * int(I()):
n = int(I())
s = I()
print(*min(((s[k:] + s[:k][::~n - k & 1 or -1], k + 1) for k in range(n))), sep='\n')
``` | vfc_142075 | {
"difficulty": "medium",
"memory_limit": "256 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1316/B",
"time_limit": "1 second"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n4\nabab\n6\nqwerty\n5\naaaaa\n6\nalaska\n9\nlfpbavjsm\n1\np\n",
"output": "abab\n1\nertyqw\n3\naaaaa\n1\naksala\n6\navjsmbpfl\n5\np\n1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\... |
taco | verifiable_code | https://codeforces.com/problemset/problem/1343/F | Solve the following coding problem using the programming language python:
We guessed a permutation $p$ consisting of $n$ integers. The permutation of length $n$ is the array of length $n$ where each element from $1$ to $n$ appears exactly once. This permutation is a secret for you.
For each position $r$ from $2$ to $... | ```python
import sys
input = sys.stdin.readline
def dfs(x, S):
for i in range(len(S)):
if x in S[i]:
S[i].remove(x)
LEN1 = 0
for s in S:
if len(s) == 1:
LEN1 += 1
ne = list(s)[0]
if LEN1 == 2:
return [-1]
if LEN1 == 1:
return [ne] + dfs(ne, S)
else:
return [-1]
import copy
t = int(input())
f... | vfc_142082 | {
"difficulty": "very_hard",
"memory_limit": "256 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1343/F",
"time_limit": "2 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n6\n3 2 5 6\n2 4 6\n3 1 3 4\n2 1 3\n4 1 2 4 6\n5\n2 2 3\n2 1 2\n2 1 4\n2 4 5\n7\n3 1 2 6\n4 1 3 5 6\n2 1 2\n3 4 5 7\n6 1 2 3 4 5 6\n3 1 3 6\n2\n2 1 2\n5\n2 2 5\n3 2 3 5\n4 2 3 4 5\n5 1 2 3 4 5\n",
"output": "3 1 4 6 2 5 \n3... |
taco | verifiable_code | Solve the following coding problem using the programming language python:
You have been given an integer array A and a number K. Now, you need to find out whether any two different elements of the array A sum to the number K. Two elements are considered to be different if they lie at different positions in the array. ... | ```python
n,k = list(map(int , input().split()))
arr = list(map(int , input().split()))
found = 0
arr = sorted(arr)
l = 0
h = n-1
while l<h:
if arr[l] + arr[h] == k:
found = 1
break
elif arr[l] + arr[h] < k:
l +=1
else:
h -=1
if found:
print("YES")
else:
print("NO")
``` | vfc_142086 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "100000 1000\n33 37 42 49 41 24 32 35 43 13 20 26 32 39 40 5 45 33 41 5 13 44 24 27 39 9 32 40 36 17 8 15 39 31 46 6 30 8 32 49 20 12 26 6 9 37 13 13 29 40 20 47 36 29 27 32 24 26 27 40 26 16 20 34 5 23 40 40 21 42 18 30 22 12 32 20... | |
taco | verifiable_code | Solve the following coding problem using the programming language python:
In vardhaman college of engineering, there is competition with name treasure lock.
To make this competition the key for the lock should satisfy following rules.
1 .3, 5, or both as its digits. No other digit is allowed.
2. Number of times 3 appe... | ```python
for _ in range(int(input())):
c=0
n=int(input())
temp=n
if n<3:
print((-1), end=' ')
elif n%15==0 or n%3==0:
sum=0
for j in range(n):
sum=sum*10+5
print((sum), end=' ')
elif n%5==0:
sum=0
for j in range(n):
sum=sum*10+3
print((sum), end=' ')
else:
while n>5:
n-=5
sum=0
... | vfc_142090 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n204\n250\n104",
"output": "555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555... | |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/quick-sort/1 | Solve the following coding problem using the programming language python:
Quick Sort is a Divide and Conquer algorithm. It picks an element as a pivot and partitions the given array around the picked pivot.
Given an array arr[], its starting position is low (the index of the array) and its ending position is high(the ... | ```python
class Solution:
def quickSort(self, arr, low, high):
if low < high:
p_index = self.partition(arr, low, high)
self.quickSort(arr, low, p_index - 1)
self.quickSort(arr, p_index + 1, high)
def partition(self, arr, low, high):
pivot = arr[low]
(left, right) = (low, high)
while left < right:
... | vfc_142099 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/quick-sort/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N = 5 \narr[] = { 4, 1, 3, 9, 7}",
"output": "1 3 4 7 9",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "N = 9\narr[] = { 2, 1, 6, 10, 4, 1, 3, 9, 7}",
"output": "1 1 2 3 4 6 7 9 10",
... |
taco | verifiable_code | https://codeforces.com/problemset/problem/1690/B | Solve the following coding problem using the programming language python:
Kristina has two arrays $a$ and $b$, each containing $n$ non-negative integers. She can perform the following operation on array $a$ any number of times:
apply a decrement to each non-zero element of the array, that is, replace the value of eac... | ```python
def check(a, b):
difference = False
dval = 0
mindifference = 0
for (x, y) in zip(a, b):
if y > x:
return False
if y < 1:
if difference:
if x - y > dval:
return False
elif x - y > mindifference:
mindifference = x - y
else:
if x - y < mindifference:
return False
if diff... | vfc_142100 | {
"difficulty": "easy",
"memory_limit": "256 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1690/B",
"time_limit": "1 second"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n4\n3 5 4 1\n1 3 2 0\n3\n1 2 1\n0 1 0\n4\n5 3 7 2\n1 1 1 1\n5\n1 2 3 4 5\n1 2 3 4 6\n1\n8\n0\n1\n4\n6\n",
"output": "YES\nYES\nNO\nNO\nYES\nNO\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1400/E | Solve the following coding problem using the programming language python:
You have a multiset containing several integers. Initially, it contains $a_1$ elements equal to $1$, $a_2$ elements equal to $2$, ..., $a_n$ elements equal to $n$.
You may apply two types of operations: choose two integers $l$ and $r$ ($l \le ... | ```python
import sys
sys.setrecursionlimit(10000)
n = int(input())
a = list(map(int, input().split()))
def solve(i, j, x):
if i > j:
return 0
idx = a.index(min(a[i:j + 1]), i, j + 1)
mn = a[idx]
case = mn - x + solve(i, idx - 1, mn) + solve(idx + 1, j, mn)
return min(case, j - i + 1)
print(solve(0, n - 1, 0))
... | vfc_142104 | {
"difficulty": "hard",
"memory_limit": "256 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1400/E",
"time_limit": "2 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1 4 1 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n1 0 1 0 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"... |
taco | verifiable_code | https://codeforces.com/problemset/problem/1253/A | Solve the following coding problem using the programming language python:
You're given two arrays $a[1 \dots n]$ and $b[1 \dots n]$, both of the same length $n$.
In order to perform a push operation, you have to choose three integers $l, r, k$ satisfying $1 \le l \le r \le n$ and $k > 0$. Then, you will add $k$ to el... | ```python
def f(a, b, n):
r = 0
j = 0
sub = 0
flag2 = False
for k in range(n):
if a[k] != b[k]:
r = k
sub = a[k] - b[k]
flag2 = True
break
if sub > 0:
return False
flag = False
if flag2:
for k in range(r, n):
if a[k] - b[k] != sub and a[k] != b[k]:
return False
if a[k] == b[k]:
f... | vfc_142108 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1253/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n6\n3 7 1 4 1 2\n3 7 3 6 3 2\n5\n1 1 1 1 1\n1 2 1 3 1\n2\n42 42\n42 42\n1\n7\n6\n",
"output": "YES\nNO\nYES\nNO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n3\n1 1 1\n1 1 3\n",
... |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/214734e358208c1c6811d9b237b518f6b3c3c094/1 | Solve the following coding problem using the programming language python:
Given an array arr[ ] of size n having distinct elements, the task is to find the next greater element for each element of the array in order of their appearance in the array.
Next greater element of an element in the array is the nearest elemen... | ```python
class Solution:
def nextLargerElement(self, arr, n):
stack = []
res = [-1 for _ in range(n)]
for i in range(n - 1, -1, -1):
while stack != [] and stack[-1] <= arr[i]:
stack.pop()
if stack == []:
res[i] = -1
else:
res[i] = stack[-1]
stack.append(arr[i])
return res
``` | vfc_142112 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/214734e358208c1c6811d9b237b518f6b3c3c094/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "n = 4, arr[] = [1 3 2 4]",
"output": "3 4 4 -1",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Roy is going through the dark times of his life. Recently his girl friend broke up with him and to overcome the pain of acute misery he decided to restrict himself to Eat-Sleep-Code life cycle. For N days he did nothing but eat, sleep and code. ... | ```python
try:
data = []
for _ in range(eval(input())):
data.append(input())
best = max(max(len(s) for s in day.replace('S', ' ').replace('E', ' ').split()) for day in data)
all_data = ''.join(x for day in data for x in day)
opt = max(len(s) for s in all_data.replace('S', ' ').replace('E', ' ').split())
print('... | vfc_142113 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "100\nSSEESEECEESSESECEECECECCECCCCEEESESSCSCECEESCSCEESCCESCCESSSEEEECECSEECCCCCSCECCESESSEEECSECESEECSECSEESECESCESEECCCCECSEESSCSSECEECEECSESCSEESCSSSCCSCEECCCECSSSEESCCCEECSCECESCEEEECSSECECSSSECCCECCCCSSEECSESCEECSCSCSESECCEESE... | |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/range-minimum-query/1 | Solve the following coding problem using the programming language python:
Given an array A[ ] and its size N your task is to complete two functions a constructST function which builds the segment tree and a function RMQ which finds range minimum query in a range [a,b] of the given array.
Input:
The task is to compl... | ```python
import sys
def constructST(arr, n):
st = [sys.maxsize] * (4 * n)
def build(node, l, r):
if l == r:
st[node] = arr[l]
else:
m = (l + r) // 2
build(2 * node + 1, l, m)
build(2 * node + 2, m + 1, r)
st[node] = min(st[2 * node + 1], st[2 * node + 2])
build(0, 0, n - 1)
return st
def RMQ(... | vfc_142117 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/range-minimum-query/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": "constructST",
"input": "(To be used only for expected",
"output": ") \r\n1\r\n4\r\n1 2 3 4\r\n2\r\n0 2 2 3\r\nOutput\r\n1 3",
"type": "function_call"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/SPLITIT | 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 string $S$ with length $N$. Determine if it is possible to find two non-empty strings $A$ and $B$ which satisfy the followi... | ```python
for _ in range(int(input())):
n = int(input())
s = input()
k = s[-1:]
s = s[:-1]
if k in s:
print('YES')
else:
print('NO')
``` | vfc_142119 | {
"difficulty": "easy",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/SPLITIT",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n6\ncabdab\n21\nyourcrushlovesyouback\n16\nwubbalubbadubdub\n5\nsplit\n7\nsplitit",
"output": "YES\nNO\nYES\nNO\nYES",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/390/D | Solve the following coding problem using the programming language python:
Inna loves sweets very much. That's why she decided to play a game called "Sweet Matrix".
Inna sees an n × m matrix and k candies. We'll index the matrix rows from 1 to n and the matrix columns from 1 to m. We'll represent the cell in the i-th ... | ```python
string = input()
l = string.split(' ')
(n, m, k) = (int(l[0]), int(l[1]), int(l[2]))
l = [{(1, 1)}]
count = 1
In = 0
while count < k:
s = set()
for i in l[In]:
x = i[0] + 1
y = i[1]
if x <= n and y <= m:
t = [0, 0]
(t[0], t[1]) = (x, y)
s.add(tuple(t))
x = i[0]
y = i[1] + 1
if x <= n an... | vfc_142128 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/390/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 4 4\n",
"output": "8\n(1,1) (2,1) (2,2)\n(1,1) (1,2)\n(1,1) (2,1)\n(1,1)\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/659/G | Solve the following coding problem using the programming language python:
Long ago, Vasily built a good fence at his country house. Vasily calls a fence good, if it is a series of n consecutively fastened vertical boards of centimeter width, the height of each in centimeters is a positive integer. The house owner reme... | ```python
mod = 10 ** 9 + 7
n = int(input())
h = list([int(x) - 1 for x in input().split()])
ans = x = 0
for i in range(n):
ans += h[i] + min(h[i], h[i - 1]) * x
if i < n - 1:
x *= min(h[i - 1], h[i], h[i + 1])
x += min(h[i], h[i + 1])
ans %= mod
x %= mod
print(ans)
``` | vfc_142132 | {
"difficulty": "hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/659/G",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n1 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n3 4 2\n",
"output": "13\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input":... |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/zigzag-tree-traversal/1 | Solve the following coding problem using the programming language python:
Given a Binary Tree. Find the Zig-Zag Level Order Traversal of the Binary Tree.
Example 1:
Input:
1
/ \
2 3
/ \ / \
4 5 6 7
Output:
1 3 2 4 5 6 7
Example 2:
Input:
7
/ \
9 ... | ```python
class Solution:
def zigZagTraversal(self, root):
ret = []
level = [root]
i = 1
while root and level:
currentnodes = []
nextlevel = []
for node in level:
currentnodes.append(node.data)
if node.left:
nextlevel.append(node.left)
if node.right:
nextlevel.append(node.right)... | vfc_142141 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/zigzag-tree-traversal/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\r\n / \\\r\n 2 3\r\n / \\ / \\\r\n 4 5 6 7",
"output": "1 3 2 4 5 6 7",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Ikshu and his class
Ikshu's class is very fond of playing games. Their teacher tied them with many ropes with each other, Such that each student is tied with exactly one rope. It means that if students 2 and 3 are connected and 2 is connected t... | ```python
from math import factorial
def fac(n, m):
ans = 1
while n >= 1:
ans = (ans * n) % m
n -= 1
return ans
idx=[]
size=[]
def root(x):
while x!=idx[x]:
#path compression start
idx[x]=idx[idx[x]]
#path compression end
x=idx[x]
return x
def connected(p, q):
return root(p)==root(q)
def union(p, q... | vfc_142142 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "100 50\n7 97\n8 38\n10 81\n12 85\n17 4\n20 55\n20 77\n21 86\n23 53\n25 7\n28 74\n28 76\n30 4\n31 93\n38 90\n40 2\n40 43\n42 98\n46 98\n48 47\n52 28\n52 62\n53 17\n53 40\n53 72\n58 54\n58 61\n60 83\n65 94\n66 81\n66 96\n67 0\n67 25\... | |
taco | verifiable_code | Solve the following coding problem using the programming language python:
YAML (YAML Ain't Markup Language) is one of the formats for expressing an object as a character string.
You will be given an object represented by a subset of YAML and a query that specifies the property, so please answer the value of the speci... | ```python
import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 13
mod = 10 ** 9 + 9
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (... | vfc_142150 | {
"difficulty": "unknown_difficulty",
"memory_limit": "262.144 megabytes",
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": ".tweets.1\nname: shimeji\nid: shimejitan\ntweets:\n1: shimejilove\n:2 azupero",
"output": "no such property\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": ".tweets.1\nname: shimeki\nid: sh... | |
taco | verifiable_code | https://codeforces.com/problemset/problem/1073/A | Solve the following coding problem using the programming language python:
You are given a string $s$, consisting of $n$ lowercase Latin letters.
A substring of string $s$ is a continuous segment of letters from $s$. For example, "defor" is a substring of "codeforces" and "fors" is not.
The length of the substring i... | ```python
def diverseSubstring(n, s):
letters = ''
n = n - 1
for i in range(n):
j = i + 1
if s[i] != s[j]:
print('YES')
letters = s[i] + s[i + 1]
return letters
return 'NO'
n = int(input())
s = str(input())
print(diverseSubstring(n, s))
``` | vfc_142155 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1073/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10\ncodeforces\n",
"output": "YES\nco\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\naaaaa\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
taco | verifiable_code | https://codeforces.com/problemset/problem/40/A | Solve the following coding problem using the programming language python:
Not so long ago as a result of combat operations the main Berland place of interest — the magic clock — was damaged. The cannon's balls made several holes in the clock, that's why the residents are concerned about the repair. The magic clock can... | ```python
from math import sqrt, ceil
def colorOfDamagedArea(x, y):
location = sqrt(x * x + y * y)
area_sBorder = ceil(location)
if location == area_sBorder:
return 'black'
area_sAddress = x * y
area_sColorCode = area_sBorder % 2
if area_sAddress > 0 and area_sColorCode or (area_sAddress < 0 and (not area_sCol... | vfc_142159 | {
"difficulty": "easy",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/40/A",
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "-12 -35\n",
"output": "black\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/3ac9989b932e29d448b1925aac7d407f75851769/1 | Solve the following coding problem using the programming language python:
Due to the rise of covid-19 cases in India, this year BCCI decided to organize knock-out matches in IPL rather than a league.
Today is matchday 1 and it is between previous year winners Mumbai Indians and the city of Joy - Kolkata Knight Riders... | ```python
class Solution:
def findPoint(self, a, b, c):
dx = b[0] - c[0]
dy = b[1] - c[1]
ans = [(a[0] + dx, a[1] + dy), (a[0] - dx, a[1] - dy)]
dx = a[0] - b[0]
dy = a[1] - b[1]
ans += [(c[0] + dx, c[1] + dy), (c[0] - dx, c[1] - dy)]
return min(ans)
``` | vfc_142175 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/3ac9989b932e29d448b1925aac7d407f75851769/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "A = (3, 2)\r\nB = (3, 4)\r\nc = (2, 2)",
"output": "2.000000 0.000000",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/358/B | Solve the following coding problem using the programming language python:
Seryozha has a very changeable character. This time he refused to leave the room to Dima and his girlfriend (her hame is Inna, by the way). However, the two lovebirds can always find a way to communicate. Today they are writing text messages to ... | ```python
n = int(input())
l = []
for i in range(n):
l.append(input())
s = input()
stage = 0
cur = 0
curpos = 0
f = 0
for j in range(len(s)):
i = s[j]
curword = l[cur]
if stage == 0 and i == '<':
stage = 1
elif stage == 1 and i == '3':
stage = 2
if stage == 2:
if i == curword[curpos]:
curpos += 1
if cu... | vfc_142176 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/358/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\ni\nlove\nyou\n<3i<3love<23you<3\n",
"output": "yes\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/332/A | Solve the following coding problem using the programming language python:
Everybody knows that the Berland citizens are keen on health, especially students. Berland students are so tough that all they drink is orange juice!
Yesterday one student, Vasya and his mates made some barbecue and they drank this healthy drin... | ```python
n = int(input())
s = str(input())
while (len(s) - 1) % n != 0:
s = s[:len(s) - 1]
sol = 0
for i in range(len(s) - 1, 3, -n):
if s[i - 1] == s[i - 2] and s[i - 2] == s[i - 3]:
sol += 1
print(sol)
``` | vfc_142180 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/332/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\nabbba\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\nabbab\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input"... |
taco | verifiable_code | https://www.codechef.com/problems/SUMAGCD | Solve the following coding problem using the programming language python:
Chef has a sequence of positive integers $A_1, A_2, \ldots, A_N$. He wants to split this sequence into two non-empty (not necessarily contiguous) subsequences $B$ and $C$ such that $\mathrm{GCD}\,(B) + \mathrm{GCD}\,(C)$ is maximum possible. Hel... | ```python
import sys
def read_line():
return sys.stdin.readline().split()
def read_int():
return int(sys.stdin.readline())
def read_int_line():
return [int(v) for v in sys.stdin.readline().split()]
def gcd(x, y):
while x != 0 and y != 0:
z = y
y = x % y
x = z
return x + y
def compute_other_gcd(A, gcd1):... | vfc_142185 | {
"difficulty": "medium_hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/SUMAGCD",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 \n4 \n4 4 7 6 \n\n",
"output": "9\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.hackerrank.com/challenges/simplified-chess-engine-ii/problem | Solve the following coding problem using the programming language python:
Chess is a very popular game played by hundreds of millions of people. Nowadays, we have chess engines such as Stockfish and Komodo to help us analyze games. These engines are very powerful pieces of well-developed software that use intelligent ... | ```python
from collections import namedtuple, defaultdict
trans = {'A': 0, 'B': 1, 'C': 2, 'D': 3}
trans_r = {0: 'A', 1: 'B', 2: 'C', 3: 'D'}
def translate(c, r):
return (int(trans[c]), int(r) - 1)
Piece = namedtuple('Piece', ['side', 'type', 'pos'])
Pos = namedtuple('Position', ['c', 'r'])
pieces = {p: {t: {s: Piece... | vfc_142190 | {
"difficulty": "medium_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.hackerrank.com/challenges/simplified-chess-engine-ii/problem",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n2 1 1\nQ B 1\nP B 3\nQ A 4\n",
"output": "YES\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/960/B | Solve the following coding problem using the programming language python:
You are given two arrays A and B, each of size n. The error, E, between these two arrays is defined $E = \sum_{i = 1}^{n}(a_{i} - b_{i})^{2}$. You have to perform exactly k_1 operations on array A and exactly k_2 operations on array B. In one op... | ```python
(n, k1, k2) = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
d = [abs(a[i] - b[i]) for i in range(n)]
k = k1 + k2
for _ in range(k):
mx = max(d)
id = d.index(mx)
if mx == 0:
d[id] += 1
else:
d[id] -= 1
print(sum([x ** 2 for x in d]))
``` | vfc_142194 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/960/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 0 0\n1 2\n2 3\n",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 1 0\n1 2\n2 2\n",
"output": "0",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/a-guy-with-a-mental-problem1604/1 | Solve the following coding problem using the programming language python:
A guy has to reach his home and does not want to be late. He takes train to reach home. He has a mental illness, so he always switches train at every station.
For eg: If he starts with train A then at station 2 he will switch his train to train ... | ```python
class Solution:
def minTime(self, a, b, n):
(c, d) = (0, 0)
for i in range(n):
if i % 2 == 0:
c += a[i]
else:
c += b[i]
for i in range(n):
if i % 2 == 0:
d += b[i]
else:
d += a[i]
return min(c, d)
``` | vfc_142199 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/a-guy-with-a-mental-problem1604/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N = 3\nA[] = {2, 1, 2}\nB[] = {3, 2, 1}",
"output": "5",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/SPRT2020/problems/MXSCST | Solve the following coding problem using the programming language python:
Tim buy a string of length N from his friend which consist of ‘d’ and ‘u’ letters only
,but now Tim wants to sell the string at maximum cost.
The maximum cost of string is defined as the maximum length of a Substring (consecutive subsequence... | ```python
(n, p) = map(int, input().split())
s = input()
d = s.count('d')
u = s.count('u')
if d <= p or u <= p:
print(n)
elif d >= u:
c = 0
l = 0
i = 0
ii = -1
pp = p
while i < n:
if s[i] == 'u' and ii == -1:
ii = i
if pp == 0 and s[i] == 'u':
c = max(c, l)
i = ii
ii = -1
l = -1
pp = p
el... | vfc_142200 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/SPRT2020/problems/MXSCST",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 2\nduud\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 1\ndduddudddu\n",
"output": "6\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/341/B | Solve the following coding problem using the programming language python:
Iahub recently has learned Bubble Sort, an algorithm that is used to sort a permutation with n elements a1, a2, ..., an in ascending order. He is bored of this so simple algorithm, so he invents his own graph. The graph (let's call it G) initial... | ```python
from bisect import bisect_left, bisect_right, insort
R = lambda : map(int, input().split())
(n, arr) = (int(input()), list(R()))
dp = []
for i in range(n):
idx = bisect_left(dp, arr[i])
if idx >= len(dp):
dp.append(arr[i])
else:
dp[idx] = arr[i]
print(len(dp))
``` | vfc_142208 | {
"difficulty": "medium",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/341/B",
"time_limit": "1.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "100\n36 48 92 87 28 85 42 10 44 41 39 3 79 9 14 56 1 16 46 35 93 8 82 26 100 59 60 2 96 52 13 98 70 81 71 94 54 91 17 88 33 30 19 50 18 73 65 29 78 21 61 7 99 97 45 89 57 27 76 11 49 72 84 69 43 62 4 22 75 6 66 83 38 34 86 15 40 51... |
taco | verifiable_code | https://www.codechef.com/COOK04/problems/RECIPE | Solve the following coding problem using the programming language python:
The chef has a recipe he wishes to use for his guests,
but the recipe will make far more food than he can serve to the guests.
The chef therefore would like to make a reduced version of the recipe which has the same ratios of ingredients, but ma... | ```python
from sys import stdin
from functools import reduce
def gcd(a, b):
while b != 0:
(a, b) = (b, a % b)
return a
def gcdl(l):
return reduce(gcd, l[1:], l[0])
def __starting_point():
T = int(stdin.readline())
for case in range(T):
numbers = list(map(int, stdin.readline().split()[1:]))
g = gcdl(number... | vfc_142212 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/COOK04/problems/RECIPE",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n2 4 4\n3 2 3 4\n4 3 15 9 6\n\n",
"output": "1 1\n2 3 4\n1 5 3 2\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1754/A | Solve the following coding problem using the programming language python:
You work in the quality control department of technical support for a large company. Your job is to make sure all client issues have been resolved.
Today you need to check a copy of a dialog between a client and a technical support manager. Acc... | ```python
for _ in range(int(input())):
n = int(input())
s = input()
c = 0
for i in range(n):
if s[i] == 'Q':
c = c + 1
elif c == 0:
c = 0
else:
c = c - 1
if c != 0:
print('No')
else:
print('Yes')
``` | vfc_142216 | {
"difficulty": "easy",
"memory_limit": "256 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1754/A",
"time_limit": "1 second"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n4\nQQAA\n4\nQQAQ\n3\nQAA\n1\nQ\n14\nQAQQAQAAQQQAAA\n",
"output": "Yes\nNo\nYes\nNo\nYes\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
You need to handle two extraordinarily large integers. The good news is that you don't need to perform any arithmetic operation on them. You just need to compare them and see whether they are equal or one is greater than the other.
Given two st... | ```python
t = eval(input())
while t:
t-=1
a = input()
b = input()
cnt1=0
cnt2=0
i=len(a)-1
while i>=0 and a[i]=='!':
i-=1
cnt1+=1
i=len(b)-1
while i>=0 and b[i]=='!':
i-=1
cnt2+=1
swapped = 0
if cnt2<cnt1:
cnt2,cnt1=cnt1,cnt2
a,b=b,a
swapped = 1
a = a[:len(a)-cnt1]
b = b[:len(b)-cnt2]
b = in... | vfc_142220 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "25\n0!\n1\n9!\n999999999\n9!!\n999999999\n456!!!\n123!!!!!!\n5!\n120\n9!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n999999999!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n0!\n1\n1!\n1\n2!\n2\n6\n3!\n4!\n24\n5!\n120\n720\n6!\n504... | |
taco | verifiable_code | https://codeforces.com/problemset/problem/898/B | Solve the following coding problem using the programming language python:
Vasya has n burles. One bottle of Ber-Cola costs a burles and one Bars bar costs b burles. He can buy any non-negative integer number of bottles of Ber-Cola and any non-negative integer number of Bars bars.
Find out if it's possible to buy some... | ```python
n = int(input())
a = int(input())
b = int(input())
f = 0
if a % 2 == 0 and b % 2 == 0 and (n % 2 != 0):
print('NO')
elif a == b:
if n % a != 0:
print('NO')
else:
print('YES')
print(int(n / a), 0)
elif a % 3 == 0 and b % 3 == 0 and (n % 3 != 0):
print('NO')
else:
if n % a == 0:
print('YES')
f = ... | vfc_142232 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/898/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7\n2\n3\n",
"output": "YES\n2 1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "100\n25\n10\n",
"output": "YES\n0 10\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/LOCAUG16/problems/CHEFCHSS | Solve the following coding problem using the programming language python:
Chef Hari has got a new obsession now: he has started playing chess (read about it here) and he is liking this game very much. Since Hari has spent several months playing chess with his friends, he has now decided to take part in some chess tour... | ```python
t = eval(input())
while t > 0:
t = t - 1
(f1, f2, r1, r2, r3, r4) = list(map(int, input().split()))
(p1, p2, p3, p4) = list(map(float, input().split()))
s1 = (1 - p1) * -f1 + (r2 - f1) * (1 - p2) * p1 + p1 * p2 * (r1 - f1)
s2 = (1 - p3) * -f2 + (r3 - f2) * p3 * (1 - p4) + p3 * p4 * (r3 + r4 - f2)
if s1 ... | vfc_142236 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/LOCAUG16/problems/CHEFCHSS",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n30 50 70 10 40 30\n0.25 0.10 0.30 0.05\n50 36 80 38 65 32\n0.55 0.12 0.33 0.54\n",
"output": "FIRST\nSECOND\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/JENGA | Solve the following coding problem using the programming language python:
Chef hosts a party for his birthday. There are N people at the party. All these N people decide to play Jenga.
There are X Jenga tiles available. In one round, all the players pick 1 tile each and place it in the tower.
The game is *valid* if... | ```python
t = int(input())
for i in range(t):
(x, y) = map(int, input().split())
if y >= x and y % x == 0:
print('YES')
else:
print('NO')
``` | vfc_142240 | {
"difficulty": "easy",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/JENGA",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n3 3\n4 2\n2 4\n",
"output": "YES\nNO\nYES\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1251/C | Solve the following coding problem using the programming language python:
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different pari... | ```python
for _ in range(int(input())):
n = input()
odd = []
eve = []
for i in n:
if int(i) % 2 != 0:
odd.append(i)
else:
eve.append(i)
i = 0
j = 0
while i < len(odd) and j < len(eve):
if odd[i] < eve[j]:
print(odd[i], end='')
i += 1
else:
print(eve[j], end='')
j += 1
for k in range(i,... | vfc_142253 | {
"difficulty": "medium_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1251/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n0709\n1337\n246432\n",
"output": "0079\n1337\n234642\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n1003\n",
"output": "0013\n",
"type": "stdin_stdout"
},
{
... |
taco | verifiable_code | https://codeforces.com/problemset/problem/646/B | Solve the following coding problem using the programming language python:
В Берляндском государственном университете локальная сеть между серверами не всегда работает без ошибок. При передаче двух одинаковых сообщений подряд возможна ошибка, в результате которой эти два сообщения сливаются в одно. При таком слиянии ко... | ```python
s = input()
t = 0
if len(s) % 2 == 0:
n = (len(s) - 1) // 2 + 1
else:
n = (len(s) - 1) // 2
for i in range(n, len(s) - 1):
a = i
b = len(s) - i - 1
if s[:a + 1] == s[b:]:
print('YES')
print(s[:a + 1])
t = 1
break
if t == 0:
print('NO')
``` | vfc_142257 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/646/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "abrakadabrabrakadabra\n",
"output": "YES\nabrakadabra\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "acacacaca\n",
"output": "YES\nacaca\n",
"type": "stdin_stdout"
},
... |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/sum-of-products5049/1 | Solve the following coding problem using the programming language python:
Given an array Arr of N integers.Calculate the sum of Bitwise ANDs(&) all the pairs formed by the given array.
Example 1:
Input:
N=3
Arr={5,10,15}
Output:
15
Explanation:
The bitwise Ands of all pairs are (5&10)=0
(5&15)=5 and (10&15)=10.Therefo... | ```python
class Solution:
def pairAndSum(self, N, Arr):
c = [0] * 32
for i in range(N):
for j in range(32):
if Arr[i] & 1 << j:
c[j] += 1
ans = 0
for i in range(32):
ans += c[i] * (c[i] - 1) // 2 * (1 << i)
return ans
``` | vfc_142261 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/sum-of-products5049/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N=3\nArr={5,10,15}",
"output": "15",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1396/B | Solve the following coding problem using the programming language python:
T is playing a game with his friend, HL.
There are $n$ piles of stones, the $i$-th pile initially has $a_i$ stones.
T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a s... | ```python
for _ in range(int(input())):
np = int(input())
nsp = list(map(int, input().split()))
m = max(nsp)
ts = sum(nsp)
if m > ts // 2:
print('T')
elif ts % 2:
print('T')
else:
print('HL')
``` | vfc_142262 | {
"difficulty": "medium_hard",
"memory_limit": "256 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1396/B",
"time_limit": "1 second"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n1\n2\n2\n1 1\n",
"output": "T\nHL\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n4\n2 3 1 2\n",
"output": "HL\n",
"type": "stdin_stdout"
},
{
"fn_name": nu... |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Milly loves to eat chocolates. She buys only those food items which contain some amount or percentage of chocolate in it. She has purchased N such food items and now she is planning to make a new food item by her own. She will take equal propor... | ```python
test_cases = int(input())
for test_case in range(0, test_cases):
number_of_choclates = int(input())
percentage_string = input()
percentage_array = percentage_string.split(' ', number_of_choclates - 1)
sum = 0
for percentage in percentage_array:
sum += int(percentage)
average = sum / float(number_of_ch... | vfc_142266 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1\n0\n5\n0 0 4 4 0\n3\n5 2 0\n7\n9 1 8 4 9 9 0\n6\n3 6 3 8 2 0\n",
"output": "50.47704200\n50.43952600\n50.48868200\n50.46656200\n50.52338400\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"inpu... | |
taco | verifiable_code | https://codeforces.com/problemset/problem/1445/B | Solve the following coding problem using the programming language python:
There is a famous olympiad, which has more than a hundred participants. The Olympiad consists of two stages: the elimination stage, and the final stage. At least a hundred participants will advance to the final stage. The elimination stage in tu... | ```python
import sys, math
input = lambda : sys.stdin.readline().strip()
inp = lambda : list(map(int, input().split()))
for _ in range(int(input())):
(a, b, c, d) = inp()
print(max(a + b, c + d))
``` | vfc_142275 | {
"difficulty": "easy",
"memory_limit": "512 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1445/B",
"time_limit": "1 second"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n1 2 2 1\n4 8 9 2\n",
"output": "3\n12\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n0 0 0 0\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": nu... |
taco | verifiable_code | https://codeforces.com/problemset/problem/580/D | Solve the following coding problem using the programming language python:
When Kefa came to the restaurant and sat at a table, the waiter immediately brought him the menu. There were n dishes. Kefa knows that he needs exactly m dishes. But at that, he doesn't want to order the same dish twice to taste as many dishes a... | ```python
import os
import sys
from io import BytesIO, IOBase
def main():
(n, m, k) = map(int, input().split())
a = list(map(float, input().split()))
tree = [[0] * n for _ in range(n)]
for i in range(k):
(x, y, z) = map(int, input().split())
tree[x - 1][y - 1] = float(z)
po = [1]
while len(po) != n:
po.app... | vfc_142283 | {
"difficulty": "medium_hard",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/580/D",
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10 5 5\n45 45 12 67 32 6 125 33 89 100\n6 3 78\n1 2 23\n5 7 17\n9 2 90\n4 8 39\n",
"output": "516",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/akku-and-arrays4452/1 | Solve the following coding problem using the programming language python:
Akku have solved many problems, she is genius. One day her friend gave her an Array of size n and asked her to perform
some queries of following type:
Each query consists of three integers
1 A B : Update the Array at index A by value B
2 A B : i... | ```python
class Solution:
def algo(self, a):
l = list(a)
l.sort()
l1 = l[::-1]
if len(a) == 1:
return -1
if a == l:
return 0
if a == l1:
return 1
return -1
def solveQueries(self, nums, q):
ans = []
for i in range(len(q)):
l = q[i]
if l[0] == 1:
nums[l[1] - 1] = l[2]
elif l[0]... | vfc_142287 | {
"difficulty": "medium_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/akku-and-arrays4452/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "nums = {1,5,7,4,3,5,9},\nQueries = {{2,1,3},{1,7,4},{2,6,7}}",
"output": "{0,1}",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1239/A | Solve the following coding problem using the programming language python:
Recently Ivan the Fool decided to become smarter and study the probability theory. He thinks that he understands the subject fairly well, and so he began to behave like he already got PhD in that area.
To prove his skills, Ivan decided to demon... | ```python
def read_int():
return int(input())
def read_str():
return input().strip()
def solve(n, m):
mod = 10 ** 9 + 7
k = max(n, m) + 1
count_1 = [0] * k
count_2 = [0] * k
count_1[1] = 1
count_2[1] = 0
for i in range(2, k):
count_1[i] = (count_1[i - 1] + count_2[i - 1]) % mod
count_2[i] = count_1[i - 1... | vfc_142288 | {
"difficulty": "medium_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1239/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 3\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 2\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1\n",... |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Write a program which performs the following operations to a binary search tree $T$ by adding the find operation to A: Binary Search Tree I.
* insert $k$: Insert a node containing $k$ as key into $T$.
* find $k$: Report whether $T$ has a node ... | ```python
class Node(object):
root = None
def __init__(self, key, parent=None, left=None, right=None):
self.key = key
self.parent = parent
self.left = left
self.right = right
self.height = None
@classmethod
def insert(cls, z):
y = None
x = cls.root
while x != None:
y = x
if z.key < x.key:
... | vfc_142292 | {
"difficulty": "unknown_difficulty",
"memory_limit": "134.217728 megabytes",
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10\ninsert 30\ninsert 88\ninsert 12\ninsert 1\ninsert 29\nfind 12\ninsert 17\ninsert 25\nfind 16\nprint",
"output": "yes\nno\n 1 12 17 25 29 30 88\n 30 12 1 29 17 25 88\n",
"type": "stdin_stdout"
}
]
} | |
taco | verifiable_code | https://codeforces.com/problemset/problem/1458/B | Solve the following coding problem using the programming language python:
There are n glasses on the table numbered 1, …, n. The glass i can hold up to a_i units of water, and currently contains b_i units of water.
You would like to choose k glasses and collect as much water in them as possible. To that effect you ca... | ```python
n = int(input())
dp = [[-10 ** 8] * 10002 for _ in range(n + 1)]
dp[0][0] = 0
total = 0
for i in range(n):
(a, b) = map(int, input().split())
total += b
for k in range(n - 1, -1, -1):
for c in range(10001 - a, -1, -1):
dp[k + 1][c + a] = max(dp[k + 1][c + a], dp[k][c] + b)
ans = [0 for i in range(n + ... | vfc_142301 | {
"difficulty": "hard",
"memory_limit": "512.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1458/B",
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "100\n1 0\n1 0\n1 0\n1 0\n1 0\n1 1\n1 0\n1 0\n1 0\n1 1\n1 0\n1 0\n1 0\n1 0\n1 0\n1 0\n1 0\n1 0\n1 1\n1 0\n1 0\n1 0\n1 0\n1 1\n1 0\n1 1\n1 0\n1 1\n1 1\n1 0\n1 0\n1 0\n1 1\n1 0\n1 0\n1 0\n1 1\n1 1\n1 0\n1 1\n1 0\n1 1\n1 1\n1 0\n1 0\n1... |
taco | verifiable_code | https://www.hackerrank.com/challenges/the-minion-game/problem | Solve the following coding problem using the programming language python:
Kevin and Stuart want to play the 'The Minion Game'.
Game Rules
Both players are given the same string, $\mbox{S}$.
Both players have to make substrings using the letters of the string $\mbox{S}$.
Stuart has to make words starting with conso... | ```python
s = input().strip()
vowels = set(['A', 'E', 'I', 'O', 'U'])
vscore = 0
cscore = 0
for i in range(len(s)):
score = len(s) - i
if s[i] in vowels:
vscore += score
else:
cscore += score
if cscore > vscore:
print('Stuart', cscore)
elif vscore > cscore:
print('Kevin', vscore)
else:
print('Draw')
``` | vfc_142305 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.hackerrank.com/challenges/the-minion-game/problem",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "BANANA\n",
"output": "Stuart 12\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1569/B | Solve the following coding problem using the programming language python:
A chess tournament will be held soon, where $n$ chess players will take part. Every participant will play one game against every other participant. Each game ends in either a win for one player and a loss for another player, or a draw for both p... | ```python
t = int(input())
for test in range(t):
n = int(input())
matrix = [['='] * n for i in range(n)]
for i in range(n):
matrix[i][i] = 'X'
exp = input()
done = False
for c in range(n):
if exp[c] == '2':
for i in range(n):
if c != i and exp[i] == '2' and (matrix[i][c] == '='):
matrix[i][c] = '-... | vfc_142310 | {
"difficulty": "easy",
"memory_limit": "256 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1569/B",
"time_limit": "2 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n3\n111\n2\n21\n4\n2122\n",
"output": "YES\nX==\n=X=\n==X\nNO\nYES\nX=+-\n=X==\n-=X+\n+=-X\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n3\n111\n2\n21\n4\n2122\n",
"output": "... |
taco | verifiable_code | https://codeforces.com/problemset/problem/1417/A | Solve the following coding problem using the programming language python:
— Hey folks, how do you like this problem?
— That'll do it.
BThero is a powerful magician. He has got $n$ piles of candies, the $i$-th pile initially contains $a_i$ candies. BThero can cast a copy-paste spell as follows: He chooses two pile... | ```python
for _ in range(int(input())):
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = sorted(a)
c = 0
for i in range(1, n):
c += (k - b[i]) // b[0]
print(c)
``` | vfc_142314 | {
"difficulty": "easy",
"memory_limit": "256 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1417/A",
"time_limit": "1 second"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n2 2\n1 1\n3 5\n1 2 3\n3 7\n3 2 2\n",
"output": "1\n5\n4\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/find-smallest-range-containing-elements-from-k-lists/1 | Solve the following coding problem using the programming language python:
Given K sorted lists of integers, KSortedArray[] of size N each. The task is to find the smallest range that includes at least one element from each of the K lists. If more than one such range's are found, return the first such range found.
Exam... | ```python
from heapq import *
class Solution:
def smallestRange(self, KSortedArray, n, k):
a = KSortedArray
dibba = []
(start, end) = (0, 0)
mini = 99999999999
maxi = -99999999999
for i in range(k):
mini = min(a[i][0], mini)
maxi = max(a[i][0], maxi)
heappush(dibba, (a[i][0], i, 0))
(start, en... | vfc_142318 | {
"difficulty": "medium_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/find-smallest-range-containing-elements-from-k-lists/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N = 5, K = 3\nKSortedArray[][] = {{1 3 5 7 9},\n {0 2 4 6 8},\n {2 3 5 7 11}}",
"output": "1 2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "N = 4, K ... |
taco | verifiable_code | https://www.codechef.com/problems/CHN05 | Solve the following coding problem using the programming language python:
After acquiring an extraordinary amount of knowledge through programming contests, Malvika decided to harness her expertise to train the next generation of Indian programmers. So, she decided to hold a programming camp. In the camp, she held a d... | ```python
for _ in range(int(input())):
(n, m) = map(int, input().split())
if n == 1:
print(0)
elif n == 2:
print(m)
else:
print(m * 2 + n - 3)
``` | vfc_142319 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/CHN05",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n2 1\n3 2\n",
"output": "1\n4\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/304/B | Solve the following coding problem using the programming language python:
Calendars in widespread use today include the Gregorian calendar, which is the de facto international standard, and is used almost everywhere in the world for civil purposes. The Gregorian reform modified the Julian calendar's scheme of leap yea... | ```python
import sys
import datetime
(y1, m1, d1) = list(map(int, input().split(':')))
(y2, m2, d2) = list(map(int, input().split(':')))
print(abs((datetime.date(y1, m1, d1) - datetime.date(y2, m2, d2)).days))
``` | vfc_142323 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/304/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1900:01:01\n2038:12:31\n",
"output": "50768\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1996:03:09\n1991:11:12\n",
"output": "1579\n",
"type": "stdin_stdout"
},
{
... |
taco | verifiable_code | https://codeforces.com/problemset/problem/1764/B | Solve the following coding problem using the programming language python:
"Everybody! Doremy's Perfect Math Class is about to start! Come and do your best if you want to have as much IQ as me!" In today's math class, Doremy is teaching everyone subtraction. Now she gives you a quiz to prove that you are paying attenti... | ```python
from math import gcd as gc
for i in [*open(0)][2::2]:
l = list(map(int, i.split()))
g = l[0]
for j in l:
g = gc(g, j)
print(l[-1] // g)
``` | vfc_142327 | {
"difficulty": "easy",
"memory_limit": "256 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1764/B",
"time_limit": "1 second"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n2\n1 2\n3\n5 10 25\n",
"output": "2\n5\n",
"type": "stdin_stdout"
}
]
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.