source stringclasses 4
values | task_type stringclasses 1
value | in_source_id stringlengths 0 138 | problem stringlengths 219 13.2k | gold_standard_solution stringlengths 0 413k | problem_id stringlengths 5 10 | metadata dict | verification_info dict |
|---|---|---|---|---|---|---|---|
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/maximum-xor-subset0715/1 | Solve the following coding problem using the programming language python:
Given an array arr[ ] of positive integers, the task is to find the maximum XOR value of the elements from all the possible subsets.
Example 1:
Input: N = 3, arr[] = {2, 4, 5}
Output: 7
Explanation: Subset {2, 5} has maximum xor
Example 2:
Input... | ```python
class Solution:
def maxXor(self, a, n):
start = 0
for i in range(18, -1, -1):
ma = -1
k = -1
for j in range(start, n):
if a[j] & 1 << i and (ma == -1 or ma < a[j]):
ma = a[j]
k = j
if k == -1:
continue
(a[k], a[start]) = (a[start], a[k])
start += 1
for j in range(s... | vfc_86443 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/maximum-xor-subset0715/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N = 3, arr[] = {2, 4, 5}",
"output": "7",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "N = 1, arr[] = {1}",
"output": "1",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
You are a product engineer and would like to improve the quality of duct tapes that your company manufactures. An entire tape can be represented as a single row of N cells. Each cell has its Stickiness factor, which stands for its ability to sti... | ```python
from sys import stdin
def main():
nextint = iter(map(int, stdin.read().split())).__next__
n, k, d = nextint(), nextint(), nextint()
arr = [nextint() for _ in range(n)]
csum = sum(arr[:k - 1])
for x in range(k - 1, n):
csum += arr[x]
if csum == 0:
print(-1)
return
csum -= arr[x - (k - 1)]
co... | vfc_86448 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "95 10 8359\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "5",
... | |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/english-words4137/1 | Solve the following coding problem using the programming language python:
An english word is given as input and it is modified using some format. Identify the format using the examples given below (examples given are sufficient to identify the format) and print the modified word as output.
STEWART is modified as EWART... | ```python
class Solution:
def englishWords(self, S):
x = ['A', 'E', 'I', 'O', 'U']
p = ''
t = ''
for i in S:
if i not in x:
p += i
else:
l = S.index(i)
t = S[l:]
break
t += p
if t == S:
return S
return t + 'AY'
``` | vfc_86452 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/english-words4137/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "S = \"GEEK\"",
"output": "EEKGAY",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "S = \"ALL\"",
"output": "ALL",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Encryption System
A programmer developed a new encryption system. However, his system has an issue that two or more distinct strings are `encrypted' to the same string.
We have a string encrypted by his system. To decode the original string, w... | ```python
from itertools import chain
alph = 'abcdefghijklmnopqrstuvwxyz'
def solve1(s):
cands = [s]
for c in reversed(alph[:-1]):
cands = chain.from_iterable([candidates(s, c) for s in cands])
cands = list(cands)
cands.sort()
print(len(cands))
if len(cands) > 10:
for s in cands[:5]:
print(s)
for s in c... | vfc_86453 | {
"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": "enw\nbbc\nabcdefghijklmnopqrst\nz\n#",
"output": "1\nfox\n0\n17711\nacceeggiikkmmooqqssu\nacceeggiikkmmooqqstt\nacceeggiikkmmooqqstu\nacceeggiikkmmooqrrtt\nacceeggiikkmmooqrrtu\nbcdefghijklmnopqrrtt\nbcdefghijklmnopqrrtu\nbcd... | |
taco | verifiable_code | Solve the following coding problem using the programming language python:
You have an m x n grid, with m and n both even. Each cell has a tile. The tile has two faces - one is black, and one is white. These tiles may be flipped. However, if you flip a tile, all other tiles in its row and column also get flipped. You s... | ```python
m, n = list(map(int, input().split()))
y_cnt = [0] * m
x_cnt = [0] * n
black = set()
for y in range(m):
s = input()
for x, c in enumerate(s):
if c == "B":
x_cnt[x] += 1
y_cnt[y] += 1
black.add((x, y))
ans = 0
for y in range(m):
for x in range(n):
ans += (x_cnt[x] + y_cnt[y] + ((x, y) in black... | vfc_86458 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 4\nWWWW\nWBBW\nWBBB\nWBWW",
"output": "500256",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 4\nBBBB\nBBBB\nBBBB\nBBBB",
"output": "2",
"type": "stdin_stdout"
},
{
... | |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Everyone has got to know that HELL and Printf{} use cheats while playing Counter-Strike 1.6. Everyone decides to give them a punishment.
They are going to be made to paint all the rooms of the ground floor of the hostel.
There are a total of N... | ```python
# your code goes here
t=int(input())
for i in range(1,t + 1):
lst = list(map(int, input().split()))
# print(lst[0])
n=int(lst[0])
m=int(lst[1])
a=pow(10,m)
b=pow(10,(n-m))
c=(a*b)-a-b+1
print(c)
``` | vfc_86462 | {
"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\n5 1\n4 1\n2 1\n5 1\n7 2",
"output": "98901\n9989001\n9989001\n899991\n8999991",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n39840 13446\n66760 10821\n49668 15866\n4124 149\n54235 286... | |
taco | verifiable_code | https://www.hackerrank.com/challenges/beautiful-segments/problem | Solve the following coding problem using the programming language python:
You are given an array, $\mbox{A}$, consisting of $N$ integers.
A segment, $[l,r]$, is beautiful if and only if the bitwise AND of all numbers in $\mbox{A}$ with indices in the inclusive range of $[l,r]$ is not greater than $\mbox{X}$. In other... | ```python
from itertools import product
class RangeQuery(object):
def __init__(self, items, fn):
self._rq = rq = {(i, 0): item for (i, item) in enumerate(items)}
self._fn = fn
n = len(items)
for (step, i) in product(range(1, n.bit_length()), range(n)):
j = i + 2 ** (step - 1)
if j < n:
rq[i, step] ... | vfc_86466 | {
"difficulty": "hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.hackerrank.com/challenges/beautiful-segments/problem",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 3\n1 2 7 3 4\n1 5 3\n2 4 6\n3 5 2\n",
"output": "13\n5\n2\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1011/E | Solve the following coding problem using the programming language python:
Astronaut Natasha arrived on Mars. She knows that the Martians are very poor aliens. To ensure a better life for the Mars citizens, their emperor decided to take tax from every tourist who visited the planet. Natasha is the inhabitant of Earth, ... | ```python
from functools import reduce
from math import gcd
(n, k) = map(int, input().split())
A = list(map(int, input().split()))
G = gcd(k, reduce(lambda x, y: gcd(x, y), A))
print(k // G)
print(*list(range(0, k, G)))
``` | vfc_86470 | {
"difficulty": "medium_hard",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1011/E",
"time_limit": "1.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 3\n2\n",
"output": "3\n0 1 2 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 5\n2 4\n",
"output": "5\n0 1 2 3 4 ",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
For a number X, let its "Coolness" be defined as the number of "101"s occurring in its binary representation. For example, the number 21 has Coolness 2, since its binary representation is 101012, and the string "101" occurs twice in this represe... | ```python
for _ in range(eval(input())):
a,k=list(map(int,input().split()))
lst=[]
while a>0:
j=str(bin(a)[2:])
#print j
d=len(j)
p,count=0,0
while p<d:
if d<3:
break
else:
if d-p>2:
if (((j[p]=='1') and j[p+1]=='0') and j[p+2]=='1'):
count = count+1
p=p+1
else:
... | vfc_86478 | {
"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\n12124 8\n14185 14\n18812 5\n20857 7\n27546 7",
"output": "0\n0\n136\n0\n1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n18468 2\n26501 15\n15725 10\n29359 19\n24465 3",
"output... | |
taco | verifiable_code | https://codeforces.com/problemset/problem/1651/A | Solve the following coding problem using the programming language python:
Consider a playoff tournament where $2^n$ athletes compete. The athletes are numbered from $1$ to $2^n$.
The tournament is held in $n$ stages. In each stage, the athletes are split into pairs in such a way that each athlete belongs exactly to o... | ```python
import math
t = int(input())
for _ in range(t):
n = int(input())
print(int(math.pow(2, n) - 1))
``` | vfc_86482 | {
"difficulty": "easy",
"memory_limit": "512 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1651/A",
"time_limit": "2 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n3\n1\n",
"output": "7\n1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "30\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n3... |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/product-of-primes5328/1 | Solve the following coding problem using the programming language python:
Given two numbers L and R (inclusive) find the product of primes within this range. Print the product modulo 10^{9}+7. If there are no primes in that range you must print 1.
Example 1:
Input: L = 1, R = 10
Output: 210
Explaination: The prime num... | ```python
class Solution:
def primeProduct(self, L, R):
def fun(n):
primes = [1] * (n + 1)
primes[0] = 0
primes[1] = 0
for i in range(2, n + 1):
if primes[i] == 1:
for j in range(i + i, n + 1, i):
primes[j] = 0
op = []
for i in range(2, n + 1):
if primes[i] == 1:
op.append... | vfc_86491 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/product-of-primes5328/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "L = 1, R = 10",
"output": "210",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "L = 1, R = 20",
"output": "9699690",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/print-gfg-n-times/1 | Solve the following coding problem using the programming language python:
Print GFG n times without the loop.
Example:
Input:
5
Output:
GFG GFG GFG GFG GFG
Your Task:
This is a function problem. You only need to complete the function printGfg() that takes N as parameter and prints N times GFG recursively. Don't print ... | ```python
class Solution:
def printGfg(self, n):
if n == 0:
return
print('GFG', end=' ')
self.printGfg(n - 1)
``` | vfc_86497 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/print-gfg-n-times/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5",
"output": "",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/print-first-n-fibonacci-numbers1002/1 | Solve the following coding problem using the programming language python:
Given a number N, find the first N Fibonacci numbers. The first two number of the series are 1 and 1.
Example 1:
Input:
N = 5
Output: 1 1 2 3 5
Example 2:
Input:
N = 7
Output: 1 1 2 3 5 8 13
Your Task:
Your task is to complete printFibb() which ... | ```python
class Solution:
def printFibb(self, n):
result = [0] * n
f1 = 1
f2 = 1
if n == 1:
result[0] = 1
else:
result[0] = 1
result[1] = 1
i = 2
while i < n:
f = f1 + f2
f2 = f1
f1 = f
result[i] = f
i += 1
return result
``` | vfc_86502 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/print-first-n-fibonacci-numbers1002/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N = 5",
"output": "1 1 2 3 5",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "N = 7",
"output": "1 1 2 3 5 8 13",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1438/D | Solve the following coding problem using the programming language python:
Ksenia has an array $a$ consisting of $n$ positive integers $a_1, a_2, \ldots, a_n$.
In one operation she can do the following: choose three distinct indices $i$, $j$, $k$, and then change all of $a_i, a_j, a_k$ to $a_i \oplus a_j \oplus a_... | ```python
import os
import sys
from io import BytesIO, IOBase
import heapq as h
from bisect import bisect_left, bisect_right
import time
from types import GeneratorType
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
import os
self.os = os
self._fd = file.fileno()
self.buffer = B... | vfc_86503 | {
"difficulty": "hard",
"memory_limit": "256 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1438/D",
"time_limit": "1 second"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n4 2 1 7 2\n",
"output": "YES\n3\n1 2 3\n3 4 5\n1 2 3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n10 4 49 22\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
... |
taco | verifiable_code | https://www.codechef.com/COOK23/problems/TWTCLOSE | Solve the following coding problem using the programming language python:
Little kids, Jack and Evan like playing their favorite game Glass-and-Stone. Today they want to play something new and came across Twitter on their father's laptop.
They saw it for the first time but were already getting bored to see a bunch of... | ```python
def getInput():
N_k = input().split()
N = int(N_k[0])
k = int(N_k[1])
list = []
output = []
count = 0
for i in range(0, k):
val = input()
if val != 'CLOSEALL':
val = val.split()
val = int(val[1])
if val not in list:
count = count + 1
list.append(val)
else:
list.remove(val)
... | vfc_86507 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/COOK23/problems/TWTCLOSE",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 6\nCLICK 1\nCLICK 2\nCLICK 3\nCLICK 2\nCLOSEALL\nCLICK 1\n",
"output": "1\n2\n3\n2\n0\n1\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Amit is very fond of cookies, so he wants to buy some.
There are N different cookies lying in front of him, with their prices, but he has only K Rs.
He wants to maximize the number of cookies he buys with this money.
Now, you are Amit's best ... | ```python
n,k=list(map(int,input().split()))
ar=[int(i) for i in input().split()]
ar.sort()
su=0
c=0
for i in range(n):
su=su+ar[i]
c+=1
if su>k:
su=su-ar[i]
c+=-1
break
print(c);
``` | vfc_86511 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "9789 31402\n27619 8938 6962 25073 10212 19628 27360 22864 9930 22569 2579 10228 25188 10762 5283 23783 17891 30664 17655 30852 388 23743 1224 18990 16751 17797 31527 22081 19422 9593 15298 22601 19073 10911 31587 13682 17186 25515 ... | |
taco | verifiable_code | https://codeforces.com/problemset/problem/432/C | Solve the following coding problem using the programming language python:
You have an array a[1], a[2], ..., a[n], containing distinct integers from 1 to n. Your task is to sort this array in increasing order with the following operation (you may need to apply it multiple times):
choose two indexes, i and j (1 ≤ i ... | ```python
import bisect
def gen_primes(upper_bound):
upper_bound += 1
t = [0] * upper_bound
primes = [2]
for i in range(3, upper_bound, 2):
if t[i]:
continue
primes.append(i)
for j in range(i + i, upper_bound, i):
t[j] = 1
return primes
def main():
n = int(input())
a = list(map(int, input().split()... | vfc_86515 | {
"difficulty": "medium_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/432/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n3 2 1\n",
"output": "1\n1 3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n1 2\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"inp... |
taco | verifiable_code | Solve the following coding problem using the programming language python:
There are n rabbits, one in each of the huts numbered 0 through n − 1.
At one point, information came to the rabbits that a secret organization would be constructing an underground passage. The underground passage would allow the rabbits to vis... | ```python
from collections import deque
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
(N, K) = map(int, readline().split())
ES = [list(map(int, readline().split())) for i in range(K)]
emp = {}
sq = int(K ** 0.5) + 1
def root(x):
if x == p[x]:
return x
p[x] = y = root(p[x])... | vfc_86519 | {
"difficulty": "unknown_difficulty",
"memory_limit": "134.217728 megabytes",
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "1.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 10\n1 0 1\n1 0 2\n3 1 2\n2 0 1\n1 3 3\n3 0 1\n1 0 1\n2 0 2\n1 1 3\n3 0 2",
"output": "YES\nNO\nNO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 10\n1 0 1\n1 0 2\n3 1 2\n2 0 1\n1 3 3\... | |
taco | verifiable_code | https://codeforces.com/problemset/problem/985/A | Solve the following coding problem using the programming language python:
You are given a chessboard of size 1 × n. It is guaranteed that n is even. The chessboard is painted like this: "BWBW...BW".
Some cells of the board are occupied by the chess pieces. Each cell contains no more than one chess piece. It is known ... | ```python
import sys
import math
def gcd(a, b):
if b == 0:
return a
else:
return gcd(b, a % b)
def fun():
n = int(input())
arr = list(map(int, input().split()))
arr.sort()
sum1 = sum2 = 0
for i in range(int(n / 2)):
sum1 += abs(arr[i] - (i * 2 + 1))
sum2 += abs(arr[i] - (i * 2 + 2))
print(min(sum1, su... | vfc_86523 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/985/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n1 2 6\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n1 2 3 4 5\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"... |
taco | verifiable_code | https://www.codechef.com/problems/GAMEAAM | Solve the following coding problem using the programming language python:
Two players are playing a game. The game is played on a sequence of positive integer pairs. The players make their moves alternatively. During his move the player chooses a pair and decreases the larger integer in the pair by a positive multiple... | ```python
import sys
t = int(input())
def g(a, b):
if a > b:
tmp = a
a = b
b = tmp
if b == a:
return 0
if b % a == 0:
return int(b / a) - 1
r = g(b % a, a)
q = int(b / a)
if r >= q:
return q - 1
else:
return q
def mex(x):
n = len(list(x.keys()))
for i in range(n):
if i not in x:
return i
... | vfc_86527 | {
"difficulty": "very_hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/GAMEAAM",
"time_limit": "0.5 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1\n2 3\n2\n4 5\n5 6\n2\n2 3\n3 5\n",
"output": "NO\nNO\nYES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1\n2 3\n2\n4 5\n5 6\n2\n2 3\n1 5",
"output": "NO\nNO\nYES\n",
... |
taco | verifiable_code | https://www.hackerrank.com/challenges/np-polynomials/problem | Solve the following coding problem using the programming language python:
poly
The poly tool returns the coefficients of a polynomial with the given sequence of roots.
print numpy.poly([-1, 1, 1, 10]) #Output : [ 1 -11 9 11 -10]
roots
The roots tool returns the roots of a polynomial with the given coe... | ```python
import numpy
coeff = [float(x) for x in input().strip().split()]
print(numpy.polyval(coeff, float(input().strip())))
``` | vfc_86532 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.hackerrank.com/challenges/np-polynomials/problem",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1.1 2 3\n0\n",
"output": "3.0\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Assume that a, b, and n are all positive integers. Let f (i) be the i-th fraction of the fraction a / b (0 ≤ f (i) ≤ 9). At this time, let s be the sum of f (i) from i = 1 to n.
s = f (1) + f (2) + ... + f (n)
Create a program that reads a, b... | ```python
while 1:
try:
(a, b, c) = map(int, input().split())
except:
break
print(sum((a * 10 ** (i + 1) // b % 10 for i in range(c))))
``` | vfc_86536 | {
"difficulty": "unknown_difficulty",
"memory_limit": "134.217728 megabytes",
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "1.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 2 1\n2 3 4\n5 4 3\n4 3 2",
"output": "5\n24\n7\n6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 2 1\n2 3 4\n5 4 3\n7 4 2",
"output": "5\n24\n7\n12\n",
"type": "stdin_stdo... | |
taco | verifiable_code | https://www.hackerrank.com/challenges/superpowers/problem | Solve the following coding problem using the programming language python:
You will be given two integers $a,b$. You are required to output the result of $2^{(2^a)}$ mod $\boldsymbol{b}$.
Constraints
$1\leq a,b\leq10^6$
Input Format
First and only line of the input will contain two integers $a,b$ separated by a sin... | ```python
ip = input().split(' ')
a = int(ip[0])
b = int(ip[1])
print(pow(2, 2 ** a, b))
``` | vfc_86544 | {
"difficulty": "hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.hackerrank.com/challenges/superpowers/problem",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 7\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/MATRIX2 | Solve the following coding problem using the programming language python:
You are given a matrix A that consists of N rows and M columns. Every number in the matrix is either zero or one. Calculate the number of such triples (i, j, h) where for all the pairs (x, y), where both x and y belong to [1; h] if y ≥ x, A[i+x-... | ```python
(n, m) = [int(c) for c in input().split()]
matrix = []
for i in range(n):
arr = [int(c) for c in input()]
matrix.append(arr)
c = [0 for i in range(m)]
ans = 0
for i in range(n - 1, -1, -1):
last = 0
for j in range(m):
c[j] = 0 if not matrix[i][j] else c[j] + 1
for j in range(m):
last = min(last + 1, ... | vfc_86548 | {
"difficulty": "hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/MATRIX2",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 3\n011\n111",
"output": "6",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/811/A | Solve the following coding problem using the programming language python:
At regular competition Vladik and Valera won a and b candies respectively. Vladik offered 1 his candy to Valera. After that Valera gave Vladik 2 his candies, so that no one thought that he was less generous. Vladik for same reason gave 3 candies... | ```python
from collections import deque, Counter
from itertools import combinations, permutations
from math import sqrt
import unittest
def read_int():
return int(input().strip())
def read_int_array():
return [int(i) for i in input().strip().split(' ')]
(a, b) = read_int_array()
step = 1
while a >= 0 and b >= 0:
i... | vfc_86552 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/811/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 1\n",
"output": "Valera\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7 6\n",
"output": "Vladik\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input"... |
taco | verifiable_code | https://codeforces.com/problemset/problem/1361/B | Solve the following coding problem using the programming language python:
Johnny has just found the new, great tutorial: "How to become a grandmaster?". The tutorial tells many strange and unexpected for Johnny things, such as you have to be patient or that very important is solving many harder and harder problems.
... | ```python
import sys
readline = sys.stdin.readline
T = int(readline())
Ans = [None] * T
MOD = 10 ** 9 + 7
mod = 10 ** 9 + 9
for qu in range(T):
(N, P) = map(int, readline().split())
A = list(map(int, readline().split()))
if P == 1:
if N & 1:
Ans[qu] = 1
else:
Ans[qu] = 0
continue
if N == 1:
Ans[qu] = ... | vfc_86556 | {
"difficulty": "hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1361/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n5 2\n2 3 4 4 3\n3 1\n2 10 1000\n4 5\n0 1 1 100\n1 8\n89\n",
"output": "4\n1\n146981438\n747093407\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n1 2\n88\n",
"output": "1401309... |
taco | verifiable_code | https://www.codechef.com/problems/SMOKE | Solve the following coding problem using the programming language python:
There are two types of vehicles in Chefland.
Bus which has a capacity of 100 people.
Car which has a capacity of 4 people.
There are N people who want to travel from place A to place B. You know that a single bus emits X units of smoke while a ... | ```python
from math import ceil
for _ in range(int(input())):
(n, a, b) = map(int, input().split())
print(min(ceil(n / 4) * b, n // 100 * a + ceil(n % 100 / 4) * b, ceil(n / 100) * a))
``` | vfc_86561 | {
"difficulty": "medium",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/SMOKE",
"time_limit": "0.5 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n9 40 8\n15 20 20\n105 80 10\n",
"output": "24\n20\n100\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/keypad-typing0119/1 | Solve the following coding problem using the programming language python:
You are given a string S of lowercase alphabet characters and the task is to find its matching decimal representation as on the shown keypad. Output the decimal representation corresponding to the string. For ex: if you are given amazon then its... | ```python
def printNumber(s, n):
s = s.upper()
ans = ''
my_dict = {'A': 2, 'B': 2, 'C': 2, 'D': 3, 'E': 3, 'F': 3, 'G': 4, 'H': 4, 'I': 4, 'J': 5, 'K': 5, 'L': 5, 'M': 6, 'N': 6, 'O': 6, 'P': 7, 'Q': 7, 'R': 7, 'S': 7, 'T': 8, 'U': 8, 'V': 8, 'W': 9, 'X': 9, 'Y': 9, 'Z': 9}
for i in range(len(s)):
ans += str(my_d... | vfc_86566 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/keypad-typing0119/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": "printNumber",
"input": "S = geeksforgeeks",
"output": "4335736743357",
"type": "function_call"
},
{
"fn_name": "printNumber",
"input": "S = geeksquiz",
"output": "433577849",
"type": "function_call"
... |
taco | verifiable_code | Solve the following coding problem using the programming language python:
You are enthusiastically participating in Virtual Boot Camp-14 and want to seriously learn programming. To be a good programmer you not only need to solve a problem, but also need to solve it as quickly as possible.
You are participating in th... | ```python
D,H,M,W=input().split()
D,H,M,W=int(D),int(H),int(M),int(W)
if __name__=='__main__':
print((D-1)*24*60+(20*W)+(H*60)+M)
``` | vfc_86568 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 1 11 10891091",
"output": "20",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 0 0 1",
"output": "22225095",
"type": "stdin_stdout"
},
{
"fn_name": null,
"... | |
taco | verifiable_code | https://www.codechef.com/problems/CRICRANK | Solve the following coding problem using the programming language python:
Read problem statements in [Russian], [Mandarin Chinese], [Bengali], and [Vietnamese] as well.
In a season, each player has three statistics: runs, wickets, and catches. Given the season stats of two players A and B, denoted by R, W, and C resp... | ```python
for i in range(int(input())):
ac = 0
bc = 0
(r, w, c) = map(int, input().split())
(a, b, d) = map(int, input().split())
if r > a:
ac += 1
else:
bc += 1
if w > b:
ac += 1
else:
bc += 1
if c > d:
ac += 1
else:
bc += 1
if ac > bc:
print('A')
else:
print('B')
``` | vfc_86581 | {
"difficulty": "easy",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/CRICRANK",
"time_limit": "0.5 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n0 1 2\n2 3 4\n10 10 10\n8 8 8\n10 0 10\n0 10 0",
"output": "B\nA\nA",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/136/B | Solve the following coding problem using the programming language python:
Little Petya very much likes computers. Recently he has received a new "Ternatron IV" as a gift from his mother. Unlike other modern computers, "Ternatron IV" operates with ternary and not binary logic. Petya immediately wondered how the xor ope... | ```python
def untor(a, c):
res = ''
while a or c:
(a, ma) = divmod(a, 3)
(c, mc) = divmod(c, 3)
x = 0
while (ma + x) % 3 != mc:
x += 1
res = str(x) + res
try:
return int(res, 3)
except Exception as e:
return 0
(a, c) = map(int, input().split())
print(untor(a, c))
``` | vfc_86585 | {
"difficulty": "easy",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/136/B",
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "976954722 548418041\n",
"output": "862925051\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4232 755480607\n",
"output": "755485882\n",
"type": "stdin_stdout"
},
{
... |
taco | verifiable_code | https://codeforces.com/problemset/problem/141/C | Solve the following coding problem using the programming language python:
In the Main Berland Bank n people stand in a queue at the cashier, everyone knows his/her height hi, and the heights of the other people in the queue. Each of them keeps in mind number ai — how many people who are taller than him/her and stand i... | ```python
def solve(arr, n):
arr.sort()
names = [x[1] for x in arr]
counts = [x[0] for x in arr]
segments = []
curr_count = counts[0]
curr_len = 0
L = 0
for i in range(n):
if counts[i] == curr_count:
curr_len += 1
else:
segments.append((L, i - 1))
L = i
curr_count = counts[i]
curr_len = 1
se... | vfc_86589 | {
"difficulty": "medium_hard",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/141/C",
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "23\nfgtxkw 4\nqgbokh 0\nfrb 0\nnninr 10\nbczzdfvjkh 1\nuxpelsmxxq 2\nntvvx 2\nardaae 0\nctetnl 0\nhgk 0\nvmwo 18\nojaubfibf 1\nnu 7\ngbixtuotft 4\nekmjrgxylj 1\navcygg 1\nmxgdulijf 1\notjmjmvpz 3\nxzubpxqnj 14\nlowoz 3\nmnfg 4\no 1... |
taco | verifiable_code | https://codeforces.com/problemset/problem/633/D | Solve the following coding problem using the programming language python:
Yash has recently learnt about the Fibonacci sequence and is very excited about it. He calls a sequence Fibonacci-ish if the sequence consists of at least two elements f_0 and f_1 are arbitrary f_{n} + 2 = f_{n} + 1 + f_{n} for all n ≥ 0.
... | ```python
from collections import Counter
input()
s = Counter(map(int, input().split()))
n = 0
for q in s:
s[q] -= 1
for a in s:
if not s[a]:
continue
t = [a]
s[a] -= 1
b = q + a
while s.get(b, 0):
s[b] -= 1
t.append(b)
(a, b) = (b, a + b)
n = max(n, len(t))
for c in t:
s[c] += 1
s[q] +=... | vfc_86593 | {
"difficulty": "hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/633/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 2 -1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n28 35 7 14 21\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
taco | verifiable_code | https://www.codechef.com/problems/AGECAL | Solve the following coding problem using the programming language python:
Read problems statements [Mandarin] , [Bengali] , [Hindi] , [Russian] and [Vietnamese] as well.
Chef's planet is called Javad. A year on Javad has $N$ months numbered $1$ through $N$. For each valid $i$, the $i$-th month has $a_{i}$ days number... | ```python
t = int(input())
for i in range(t):
n = int(input())
a = list(map(int, input().split()))
(yb, mb, db) = list(map(int, input().split()))
(yc, mc, dc) = list(map(int, input().split()))
if yc == yb:
if mc == mb:
print(dc - db + 1)
else:
ans = a[mb - 1] - db + 1 + sum(a[mb:mc - 1]) + dc
print(an... | vfc_86597 | {
"difficulty": "medium_hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/AGECAL",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n5\n1 2 3 4 5\n2 1 1\n3 5 1\n2\n3 3\n1 1 1\n2 2 2\n2\n1 1\n3 1 1\n3 2 1\n5\n1 4 3 4 6\n3 5 6\n10 1 1",
"output": "26\n11\n2\n112",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/883/F | Solve the following coding problem using the programming language python:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "... | ```python
mapp = {}
for _ in range(int(input())):
data = input()
new = []
data = data.replace('u', 'oo')
i = len(data) - 1
while i >= 0:
new.append(data[i])
if data[i] == 'h':
i -= 1
while data[i] == 'k':
i -= 1
else:
i -= 1
new = new[::-1]
temp = ''.join(new)
if temp in mapp:
mapp[temp] +=... | vfc_86601 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/883/F",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10\nmihail\noolyana\nkooooper\nhoon\nulyana\nkoouper\nmikhail\nkhun\nkuooper\nkkkhoon\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "9\nhariton\nhkariton\nbuoi\nkkkharito... |
taco | verifiable_code | https://www.hackerrank.com/challenges/self-driving-bus/problem | Solve the following coding problem using the programming language python:
Treeland is a country with $n$ cities and $n-1$ roads. There is exactly one path between any two cities.
The ruler of Treeland wants to implement a self-driving bus system and asks tree-loving Alex to plan the bus routes. Alex decides that ea... | ```python
from heapq import *
n = int(input())
neighbors = {}
for x in range(n):
neighbors[x] = []
for i in range(n - 1):
(a, b) = map(int, input().split())
neighbors[a - 1].append(b - 1)
neighbors[b - 1].append(a - 1)
def search(source):
ans = 0
cur_max = 0
cur_len = 0
heap = [source]
vis = [False for i in r... | vfc_86605 | {
"difficulty": "hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.hackerrank.com/challenges/self-driving-bus/problem",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 3\n3 2\n",
"output": "5\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.hackerrank.com/challenges/is-fibo/problem | Solve the following coding problem using the programming language python:
You are given an integer, $N$. Write a program to determine if $N$ is an element of the Fibonacci sequence.
The first few elements of the Fibonacci sequence are $0,1,1,2,3,5,8,13,\cdots$. A Fibonacci sequence is one where every element is a s... | ```python
import sys
T = int(sys.stdin.readline())
fibonacci = [1, 1]
while fibonacci[-1] <= 10 ** 10:
fibonacci.append(fibonacci[-1] + fibonacci[-2])
for _ in range(T):
N = int(sys.stdin.readline())
print('IsFibo' if N in fibonacci else 'IsNotFibo')
``` | vfc_86609 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.hackerrank.com/challenges/is-fibo/problem",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n5\n7\n8\n",
"output": "IsFibo\nIsNotFibo\nIsFibo\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Given a string s which contains lowercase english letters and dot sign (.) (e.g: abc.d.ee.g). Your task is to replace substring '..' with a substring '.' in the given string i.e the string should not contain 2 consecutive dot signs. You need t... | ```python
def compute(s,n,l):
q = 0
countArray = [0]*n
while q<n:
k , p =input().split()
s = s[:int(k)-1] + str(p) + s[int(k):]
i=0
count = 0
while i<l-1:
if s[i] == "." == s[i+1]:
count+=1
i+=1
else:
i+=1
countArray[q] = count
q+=1
for i in range(len(countArray)):
print(countArray... | vfc_86613 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10 3\n.b..bz....\n1 h\n3 c\n9 f",
"output": "4\n3\n1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 5\n.\n1 .\n1 w\n1 w\n1 .\n1 .",
"output": "145\n143\n143\n141\n140\n139\n139\n139... | |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/number-of-groups3920/1 | Solve the following coding problem using the programming language python:
Given an array Arr[] of N distinct integers. Write a program to find the count of groups of 2 or 3 integers that can be formed by choosing integers from the given array such that sum of integers in each of the group is divisible by three.
Exam... | ```python
class Solution:
def findgroups(self, arr, n):
c = [0, 0, 0]
res = 0
for i in range(0, n):
c[arr[i] % 3] += 1
res += c[0] * (c[0] - 1) >> 1
res += c[1] * c[2]
res += c[0] * (c[0] - 1) * (c[0] - 2) / 6
res += c[1] * (c[1] - 1) * (c[1] - 2) / 6
res += c[2] * (c[2] - 1) * (c[2] - 2) / 6
res... | vfc_86618 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/number-of-groups3920/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N = 4\r\nArr[] = {1, 2, 3, 5}",
"output": "4",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "N = 3\r\nArr[] = {1, 1, 1}",
"output": "1",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/DISHLIFE | Solve the following coding problem using the programming language python:
Chef wants to serve mankind by making people immortal by preparing a dish, a dish of life - a dish with the best taste in the universe, one with the smell and splash of fresh water flowing down the springs of the mountain, one with the smell of ... | ```python
t = int(input())
for i in range(t):
(n, k) = [int(j) for j in input().split()]
b = set()
flag = 0
cout = 0
for m in range(n):
a = [int(j) for j in input().split()]
a1 = a[1:]
cout += 1
if flag == 1:
continue
b.update(a1)
if len(b) == k:
flag = 1
if cout == n:
print('all')
else... | vfc_86620 | {
"difficulty": "medium",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/DISHLIFE",
"time_limit": "2 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n3 4\n3 1 2 3\n2 1 3\n2 1 2\n2 3\n3 1 2 3\n2 1 3\n2 3\n2 1 2\n2 1 3\n",
"output": "sad\nsome\nall\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/996/C | Solve the following coding problem using the programming language python:
Allen dreams of one day owning a enormous fleet of electric cars, the car of the future! He knows that this will give him a big status boost. As Allen is planning out all of the different types of cars he will own and how he will arrange them, h... | ```python
(n, k) = list(map(int, input().split()))
table = []
for row in range(4):
table.append(list(map(int, input().split())))
moves = []
def make_move(start, finish):
moves.append((table[start[0]][start[1]], finish[0] + 1, finish[1] + 1))
table[finish[0]][finish[1]] = table[start[0]][start[1]]
table[start[0]][s... | vfc_86624 | {
"difficulty": "hard",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/996/C",
"time_limit": "3.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 3\n0 2\n0 1\n3 2\n3 1\n",
"output": "7\n3 4 1\n1 2 1\n2 2 2\n2 1 2\n1 3 1\n1 3 2\n1 4 2\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/496/C | Solve the following coding problem using the programming language python:
You are given an n × m rectangular table consisting of lower case English letters. In one operation you can completely remove one column from the table. The remaining parts are combined forming a new table. For example, after removing the second... | ```python
def remove(p, a):
for i in range(len(a)):
a[i] = a[i][:p] + a[i][p + 1:]
(n, m) = [int(x) for x in input().split()]
a = []
for i in range(n):
a.append(input())
removed = 0
for i in range(m):
i -= removed
for j in range(n - 1):
if a[j][:i + 1] > a[j + 1][:i + 1]:
remove(i, a)
removed += 1
brea... | vfc_86628 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/496/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 10\ncodeforces\n",
"output": "0\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Campus Ambassador has organized a Coding Contest in his college. Contest has multiple rounds, in each round a participant may gain or lose few points. At the end, there is only one participant with the maximum points. In the course of the contes... | ```python
import operator
topper = ''
topscore = 0
t = int(input())
scores = {}
for i in range(t):
inp = input().split(' ')
name = inp[0]
score = int(inp[1])
if name in scores:
scores[name] += score
else:
scores[name] = score
temp = max(scores, key=scores.get)
tc = scores[temp]
toppers = [key for key in... | vfc_86632 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10\nmahi 3\nmahi 2\nvicky 5\nankit 5\npooja 4\nramesh 4\nankita 2\nmanisha 3\nmanisha 3\nkejal 5",
"output": "manisha",
"type": "stdin_stdout"
}
]
} | |
taco | verifiable_code | https://codeforces.com/problemset/problem/19/C | Solve the following coding problem using the programming language python:
Once Bob saw a string. It contained so many different letters, that the letters were marked by numbers, but at the same time each letter could be met in the string at most 10 times. Bob didn't like that string, because it contained repeats: a re... | ```python
def pow(x, exp, mod):
res = 1
while exp:
if exp & 1:
res = res * x % mod
x = x * x % mod
exp >>= 1
return res
MOD = 2 ** 121 - 1
M = int(1000000000.0) + 1
n = int(input())
vals = list(map(int, input().split()))
groups = dict()
for i in range(n):
groups.setdefault(vals[i], []).append(i)
powsA = [1... | vfc_86636 | {
"difficulty": "hard",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/19/C",
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "100\n8 43 55 27 70 81 66 10 49 67 24 61 53 0 2 76 96 16 16 1 78 1 69 69 4 59 6 87 98 14 98 20 12 48 20 41 67 90 20 96 44 8 77 94 84 2 61 27 90 42 66 84 5 19 68 13 5 53 13 87 70 41 48 40 19 61 72 31 4 4 59 100 50 64 84 10 96 16 73 3... |
taco | verifiable_code | https://codeforces.com/problemset/problem/1366/E | Solve the following coding problem using the programming language python:
You are given two arrays $a_1, a_2, \dots , a_n$ and $b_1, b_2, \dots , b_m$. Array $b$ is sorted in ascending order ($b_i < b_{i + 1}$ for each $i$ from $1$ to $m - 1$).
You have to divide the array $a$ into $m$ consecutive subarrays so that, ... | ```python
import sys
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
(n, m) = I()
a = I()
b = I()
an = 1
md = 998244353
suf = [0] * n
suf[-1] = a[n - 1]
for i in range(n - 2, -1, -1):
suf[i] = min(suf[i + 1], a[i])
suf = [0] + suf
cr = m - 1
ct = 0
for i in range(n, -1, -1):
if suf[i] < b[cr]:... | vfc_86645 | {
"difficulty": "hard",
"memory_limit": "256 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1366/E",
"time_limit": "2 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6 3\n12 10 20 20 25 30\n10 20 30\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 2\n1 3 3 7\n3 7\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
... |
taco | verifiable_code | https://codeforces.com/problemset/problem/596/A | Solve the following coding problem using the programming language python:
After making bad dives into swimming pools, Wilbur wants to build a swimming pool in the shape of a rectangle in his backyard. He has set up coordinate axes, and he wants the sides of the rectangle to be parallel to them. Of course, the area of ... | ```python
(sx, sy) = (set(), set())
for i in range(int(input())):
(x, y) = map(int, input().split())
sx.add(x)
sy.add(y)
if min(len(sx), len(sy)) == 1:
print(-1)
else:
(sx, sy) = (list(sx), list(sy))
print(abs(sx[0] - sx[1]) * abs(sy[0] - sy[1]))
``` | vfc_86649 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/596/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n0 0\n1 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n1 1\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"inpu... |
taco | verifiable_code | https://www.hackerrank.com/challenges/xor-and-sum/problem | Solve the following coding problem using the programming language python:
You are given two positive integers $\class{ML__boldsymbol}{\boldsymbol{a}}$ and $\boldsymbol{b}$ in binary representation. You should find the following sum modulo $10^9+7$:
$\sum\limits_{i=0}^{314159}\left(a\:x or\left(b\:s h l\:i\right)\righ... | ```python
a = int(input(), 2)
b = int(input(), 2)
r = 0
for i in range(314160):
r += a ^ b
b *= 2
print(r % (10 ** 9 + 7))
``` | vfc_86653 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.hackerrank.com/challenges/xor-and-sum/problem",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10\n1010\n",
"output": "489429555\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/ZCOPRAC/problems/ZCO12004 | Solve the following coding problem using the programming language python:
Zonal Computing Olympiad 2012, 26 Nov 2011
It's dinner time in Castle Camelot, and the fearsome Knights of the Round Table are clamouring for dessert. You, the chef, are in a soup. There are N knights, including King Arthur, each with a differ... | ```python
n = int(input())
ar = list(map(int, input().split()))
dp = [0] * n
dp[0] = ar[0]
dp[1] = ar[1]
for i in range(2, n):
dp[i] = min(dp[i - 2], dp[i - 1]) + ar[i]
ar.reverse()
dp1 = [0] * n
dp1[0] = ar[0]
dp1[1] = ar[1]
for i in range(2, n):
dp1[i] = min(dp1[i - 2], dp1[i - 1]) + ar[i]
print(min(dp[-1], dp1[-1]... | vfc_86657 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/ZCOPRAC/problems/ZCO12004",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1 2 1 2 2\n",
"output": "4\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/CLEARARR | Solve the following coding problem using the programming language python:
Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well.
You are given an array A of N elements. You can do the following operations on that array:
Remove the leftmost element of the array, with index l, for the cost A... | ```python
for _ in range(int(input())):
(n, k, x) = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
l.reverse()
(i, j) = (0, 1)
(cs, ans) = (sum(l), sum(l))
while k > 0:
p = l[i] + l[i + 1]
cs -= p
if j * x + cs < ans:
ans = j * x + cs
i += 2
j += 1
k -= 1
print(ans)
``` | vfc_86661 | {
"difficulty": "hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/CLEARARR",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n5 2 7\n9 10 11 12 13\n5 0 7\n9 9 9 9 9\n5 2 7\n9 1 2 3 10\n",
"output": "23\n45\n13\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Many of us are familiar with collatz sequence. Know the problem is, There is a fight going between the students of the class they have splitted up into two groups the odd rulers and the even rulers. To resolve this fight sir will randomly pick u... | ```python
for _ in range(eval(input())):
num = eval(input())
oddsum = 1
evensum = 0
totsteps = 0
while num > 1:
if num % 2 == 0:
evensum += num
num /= 2
else:
oddsum += num
num = (3 * num) + 1
totsteps += 1
evenrem = evensum % totsteps
oddrem = oddsum % totsteps
if oddrem > evenrem:
print("O... | vfc_86665 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "21\n658\n2356\n3245\n9856\n3214\n2236\n6589\n4452\n8965\n1486\n64520\n45786\n69853\n48661\n12542\n5656\n559\n1651\n5613\n6468\n49684\n64365",
"output": "Odd Rules\nEven Rules\nEven Rules\nOdd Rules\nOdd Rules\nOdd Rules\nEven... | |
taco | verifiable_code | https://www.codechef.com/problems/BLIMP | Solve the following coding problem using the programming language python:
There are N cities in a row. The i-th city from the left has a sadness of A_{i}.
In an attempt to reduce the sadness of the cities, you can send [blimps] from the left of city 1 that move rightwards (i.e, a blimp crosses cities 1, 2, \ldots in ... | ```python
nTestCases = int(input())
for testCase in range(nTestCases):
(N, X, Y) = map(int, input().split())
citiesSadness = list(map(int, input().split()))
maxSadness = max(citiesSadness)
nBlimps = 0
if Y >= X:
if maxSadness % Y == 0:
nBlimps = maxSadness / Y
else:
nBlimps = int(maxSadness / Y) + 1
els... | vfc_86669 | {
"difficulty": "medium_hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/BLIMP",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n4 4 4\n1 5 4 4\n5 4 3\n1 4 3 3 5\n4 3 1\n3 1 3 9",
"output": "2\n2\n3\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Pranav just learned about Modulus(%) and trying to solve a problem on Modulus but he always get TLE. Your task is to help him. Problem is simple, you have been given two numbers A and M and you have to find A%M and print it.
Input Format
Firs... | ```python
t=int(input())
while t>0:
m,n=list(map(int,input().split()))
print((m%n))
t-=1
``` | vfc_86673 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n8229099409255985678245019528815322882492884044988909162083286984695435816592125350688845143105166628 375218611\n73659231150978223087272818876949752940217709177574272608411978347101804753530719308170834326896916996206952295522297... | |
taco | verifiable_code | https://www.codechef.com/problems/FODCHAIN | Solve the following coding problem using the programming language python:
Read problem statements in [Russian] and [Mandarin Chinese].
A great deal of energy is lost as metabolic heat when the organisms from one trophic level are consumed by the next level.
Suppose in Chefland the energy reduces by a factor of K, i... | ```python
for z in range(int(input())):
(a, b) = map(int, input().split())
c = 1
x = 0
while a // b > 0:
a = a // b
c += 1
print(c)
``` | vfc_86681 | {
"difficulty": "easy",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/FODCHAIN",
"time_limit": "0.5 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n5 3\n6 7\n10 2\n",
"output": "2\n1\n4",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Matrix of given integers
a1,1 a1,2 ... a1, n
a2,1 a2,2 ... a2, n
::
an, 1 an, 2 ... an, n
Then, create a program that outputs the maximum value of the sum of one or more consecutive terms (submatrix) in the vertical and horizontal directions... | ```python
n = int(input())
s = [[0 for i in range(n + 1)] for j in range(n + 1)]
for r in range(n):
inp = list(map(int, input().split()))
for c in range(n):
s[r + 1][c + 1] = inp[c] + s[r][c + 1]
ans = -10001
for r_end in range(1, n + 1):
for r_start in range(r_end):
dp = [-10001]
for c in range(1, n + 1):
... | vfc_86685 | {
"difficulty": "unknown_difficulty",
"memory_limit": "134.217728 megabytes",
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "1.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 -2 3\n-1 5 6\n7 8 -9",
"output": "19\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n1 3 -9 2\n2 7 -1 5\n-8 3 2 -1\n5 -1 -3 1",
"output": "15\n",
"type": "stdin_stdout"... | |
taco | verifiable_code | https://codeforces.com/problemset/problem/1097/C | Solve the following coding problem using the programming language python:
One day, Yuhao came across a problem about checking if some bracket sequences are correct bracket sequences.
A bracket sequence is any non-empty sequence of opening and closing parentheses. A bracket sequence is called a correct bracket sequenc... | ```python
n = int(input())
parr = {}
narr = {}
zero = 0
ans = 0
for i in range(n):
s = input()
x = 0
y = 0
left = True
right = True
for j in range(len(s)):
if s[j] == '(':
x += 1
else:
x -= 1
if x < 0:
left = False
if s[-1 * (j + 1)] == '(':
y += 1
else:
y -= 1
if y > 0:
right = Fals... | vfc_86689 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1097/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7\n)())\n)\n((\n((\n(\n)\n)\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/MSNSADM1 | Solve the following coding problem using the programming language python:
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
A football competition has just finished. The players have been given points for scoring goals and points for committing fouls. Now, it is u... | ```python
def inputnums():
line = input()
words = line.split()
nums = [int(w) for w in words]
return nums
t = int(input())
for _ in range(t):
n = int(input())
a = inputnums()
b = inputnums()
s = 0
for i in range(n):
player = max(0, a[i] * 20 - b[i] * 10)
s = max(s, player)
print(s)
``` | vfc_86698 | {
"difficulty": "easy",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/MSNSADM1",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n3\n40 30 50\n2 4 20\n1\n0\n10",
"output": "800\n0",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.hackerrank.com/challenges/beautiful-path/problem | Solve the following coding problem using the programming language python:
Consider an undirected graph containing $N$ nodes and $\mbox{M}$ edges. Each edge $\textit{M}_i$ has an integer cost, $C_i$, associated with it.
The penalty of a path is the bitwise OR of every edge cost in the path between a pair of nodes, $\m... | ```python
def main():
(nvert, nedge) = readints()
edge = [[] for _ in range(nvert)]
for _ in range(nedge):
(v1, v2, cost) = readints()
edge[v1 - 1].append((v2 - 1, cost))
edge[v2 - 1].append((v1 - 1, cost))
(start, fin) = readints()
print(bestcost(edge, start - 1, fin - 1))
def readints():
return [int(fld)... | vfc_86708 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.hackerrank.com/challenges/beautiful-path/problem",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 4\n1 2 1\n1 2 1000\n2 3 3\n1 3 100\n1 3\n",
"output": "3\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/948/C | Solve the following coding problem using the programming language python:
Alice likes snow a lot! Unfortunately, this year's winter is already over, and she can't expect to have any more of it. Bob has thus bought her a gift — a large snow maker. He plans to make some amount of snow every day. On day i he will make a ... | ```python
import heapq
heap = []
n = int(input())
V = list(map(int, input().split()))
T = list(map(int, input().split()))
tmp = 0
for i in range(n):
ans = 0
heapq.heappush(heap, tmp + V[i])
while len(heap) and heap[0] <= tmp + T[i]:
ans += heapq.heappop(heap) - tmp
tmp += T[i]
ans += T[i] * len(heap)
print(ans,... | vfc_86712 | {
"difficulty": "medium_hard",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/948/C",
"time_limit": "1.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n4\n5\n",
"output": "4 ",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/common-divisor0847/1 | Solve the following coding problem using the programming language python:
Given two numbers, A and B. Find the number of common divisors of A and B.
Example 1:
ââ¬â¹Input : A = 2 and B = 4
Output : 2
Explanation:
There are only two common divisor of 2 and 4.
That is 1 and 2.
ââ¬â¹Example 2:
Input : A = 3 and ... | ```python
def common_divisor(n, m):
c = 0
for i in range(1, m + 1):
if n % i == 0 and m % i == 0:
c += 1
return c
``` | vfc_86720 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/common-divisor0847/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": "common_divisor",
"input": "A = 2 and B = 4",
"output": "2",
"type": "function_call"
},
{
"fn_name": "common_divisor",
"input": "A = 3 and B = 5",
"output": "1",
"type": "function_call"
}
]
} |
taco | verifiable_code | https://www.codechef.com/AUG16/problems/CHAHG | Solve the following coding problem using the programming language python:
Chef is an advocate for Go Green Initiative. Today he had n trees planted in a row outside his his restaurant. Today, the height of i-th tree is hi feet. The trees grow at a rate of mi feet per day.
Chef knows that trees will look beautiful if t... | ```python
def get(l, n):
(l1, l2) = ([], [])
i = 1
(h1, m1) = l[0]
while i < len(l):
(h2, m2) = l[i]
if h1 > h2:
if m1 >= m2:
l1 += [(0, 10 ** 20)]
l2 += [(-1, -1)]
else:
d = (h1 - h2) // (m2 - m1)
if (h1 - h2) % (m2 - m1) == 0:
l1 += [(0, d - 1)]
l2 += [(d + 1, 10 ** 20)]
el... | vfc_86721 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/AUG16/problems/CHAHG",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n3\n0 1\n2 2\n0 3\n2\n2 1\n1 2\n3\n1 1\n2 2\n3 3\n",
"output": "1\n0 1\n2\n0 0\n2 Inf\n0\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Your task is to write a program of a simple dictionary which implements the following instructions:
* insert str: insert a string str in to the dictionary
* find str: if the distionary contains str, then print 'yes', otherwise print 'no'
Notes... | ```python
n = int(input())
dic = {}
for i in range(n):
a = input()
if a[0] == 'i':
dic[a[7:]] = 0
elif a[5:] in dic:
print('yes')
else:
print('no')
``` | vfc_86725 | {
"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": "5\ninsert A\ninsert U\ninsert C\nfind G\nfind A",
"output": "no\nyes\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "13\ninsert AAA\ninsert AAC\ninsert AGA\ninsert AGF\ninsert TTT\nfind AA... | |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/left-rotate-matrix-k-times2351/1 | Solve the following coding problem using the programming language python:
Given three integers N, M, and K and a matrix Mat of dimensions NxM. Left rotate the matrix K times.
Example 1:
Input:
N=3,M=3,K=1
Mat=[[1,2,3],[4,5,6],[7,8,9]]
Output:
2 3 1
5 6 4
8 9 7
Explanation:
Left rotating the matrix once gives this resu... | ```python
class Solution:
def rotateMatrix(self, N, M, K, matrix):
num_rows = len(matrix)
num_cols = len(matrix[0])
rotated_matrix = [[0] * num_cols for _ in range(num_rows)]
for row in range(num_rows):
for col in range(num_cols):
new_col = (col - K) % num_cols
rotated_matrix[row][new_col] = matrix... | vfc_86729 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/left-rotate-matrix-k-times2351/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N=3,M=3,K=1\r\nMat=[[1,2,3],[4,5,6],[7,8,9]]",
"output": "2 3 1\r\n5 6 4\r\n8 9 7",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/lru-cache/1 | Solve the following coding problem using the programming language python:
Design a data structure that works like a LRU Cache. Here cap denotes the capacity of the cache and Q denotes the number of queries. Query can be of two types:
SET x y: sets the value of the key x with value y
GET x: gets the key of x if pres... | ```python
class Node:
def __init__(self, key=None, value=None):
self.key = key
self.value = value
self.prev = None
self.next = None
class LRUCache:
def __init__(self, capacity):
self.capacity = capacity
self.cache = {}
self.head = Node()
self.tail = Node()
self.head.next = self.tail
self.tail.p... | vfc_86730 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/lru-cache/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "cap = 2\r\nQ = 2\r\nQueries = SET 1 2 GET 1",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "cap = 2\r\nQ = 8\r\nQueries = SET 1 2 SET 2 3 SET 1 5\r\nSET 4 5 SET 6 7 GET 4 SET ... |
taco | verifiable_code | https://codeforces.com/problemset/problem/1270/C | Solve the following coding problem using the programming language python:
Let's call an array $a_1, a_2, \dots, a_m$ of nonnegative integer numbers good if $a_1 + a_2 + \dots + a_m = 2\cdot(a_1 \oplus a_2 \oplus \dots \oplus a_m)$, where $\oplus$ denotes the bitwise XOR operation.
For example, array $[1, 2, 3, 6]$ is... | ```python
from fractions import gcd
from heapq import *
import math
from collections import defaultdict, Counter, deque
from bisect import *
import itertools
import fractions
MOD = 10 ** 9 + 7
def main():
t = int(input())
for i in range(t):
n = int(input())
a = list(map(int, input().split()))
xor = a[0]
su =... | vfc_86731 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1270/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n4\n1 2 3 6\n1\n8\n2\n1 1\n",
"output": "0\n\n2\n4 4\n3\n2 2 6\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/single-valued-subtree/1 | Solve the following coding problem using the programming language python:
Given a binary tree, count the number of Single Valued Subtrees. A Single Valued Subtree is one in which all the nodes have same value.
Example 1
Input :
5
/ \
1 5
/ \ \
5 5 5
... | ```python
class Solution:
def util(self, root):
global count
if root == None:
return [1, None]
if root.left == None and root.right == None:
count += 1
return [1, root.data]
l = self.util(root.left)
r = self.util(root.right)
if l[0] == 1 and r[0] == 1:
if l[1] == None and r[1] == None:
retu... | vfc_86735 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/single-valued-subtree/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\r\n / \\\r\n 1 5\r\n / \\ \\\r\n 5 5 5",
"output": "4",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/707/A | Solve the following coding problem using the programming language python:
Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead.
As you may know, the coolest photos are on th... | ```python
(n, m) = list(map(int, input().split()))
for i in range(n):
if any(map(lambda x: x in 'CMY', input())):
print('#Color')
break
else:
print('#Black&White')
``` | vfc_86736 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/707/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 2\nC M\nY Y\n",
"output": "#Color",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 2\nW W\nW W\nB B\n",
"output": "#Black&White",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/PROBDIFF | Solve the following coding problem using the programming language python:
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
You have prepared four problems. The difficulty levels of the problems are A_{1}, A_{2}, A_{3}, A_{4} respectively. A problem set comprises at least ... | ```python
T = int(input())
for i in range(T):
l = list(map(int, input().split()))
a = set(l)
if len(a) == 4:
print(2)
elif len(a) == 3:
print(2)
elif len(a) == 2:
l.sort()
b = l[0]
if l.count(b) == 2:
print(2)
else:
print(1)
else:
print(0)
``` | vfc_86741 | {
"difficulty": "easy",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/PROBDIFF",
"time_limit": "0.5 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 4 3 2\n4 5 5 5\n2 2 2 2",
"output": "2\n1\n0",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/978/E | Solve the following coding problem using the programming language python:
The busses in Berland are equipped with a video surveillance system. The system records information about changes in the number of passengers in a bus after stops.
If $x$ is the number of passengers in a bus just before the current bus stop and... | ```python
import sys
import math
import collections
import bisect
def get_ints():
return map(int, sys.stdin.readline().strip().split())
def get_list():
return list(map(int, sys.stdin.readline().strip().split()))
def get_string():
return sys.stdin.readline().strip()
for t in range(1):
(n, k) = get_ints()
arr = g... | vfc_86745 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/978/E",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 5\n2 1 -3\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 4\n-1 1\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"in... |
taco | verifiable_code | https://www.hackerrank.com/challenges/fibonacci-numbers-tree/problem | Solve the following coding problem using the programming language python:
Shashank loves trees and math. He has a rooted tree, $\mathbf{T}$, consisting of $N$ nodes uniquely labeled with integers in the inclusive range $[1,N]$. The node labeled as $1$ is the root node of tree $\mathbf{T}$, and each node in $\mathbf{T}... | ```python
mod = 10 ** 9 + 7
cache = {0: (0, 1), 1: (1, 1)}
def fib_pair(n):
if n in cache:
return cache[n]
hn = n // 2
(f, fp) = fib_pair(hn)
if n & 1:
res = ((fp * fp + f * f) % mod, (2 * f + fp) * fp % mod)
else:
fm = fp - f
if fm < 0:
fm += mod
res = ((2 * fm + f) * f % mod, (fp * fp + f * f) % mo... | vfc_86749 | {
"difficulty": "hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.hackerrank.com/challenges/fibonacci-numbers-tree/problem",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 10\n1\n1\n2\n2\nQ 1 5\nU 1 1\nQ 1 1\nQ 1 2\nQ 1 3\nQ 1 4\nQ 1 5\nU 2 2\nQ 2 3\nQ 4 5\n",
"output": "0\n1\n2\n2\n4\n4\n4\n10\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Give you N cards. Only one natural number is written on each card. However, the same number is never written.
From now on, as a question, I will say an appropriate natural number. Please answer the largest remainder you get when you divide the ... | ```python
(N, Q) = map(int, input().split())
tbl = [0] * 300005
(nmax, tbl[0]) = (0, 1)
c = list(map(int, input().split()))
for k in c:
tbl[k] = 1
if k > nmax:
nmax = k
tbl[k & 1] = 1
tbl[k & 3] = 1
tbl[k & 7] = 1
for i in range(Q):
q = int(input())
if q > nmax:
print(nmax)
else:
f = 0
for k in range(q ... | vfc_86753 | {
"difficulty": "unknown_difficulty",
"memory_limit": "134.217728 megabytes",
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "3.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 3\n9 3 8\n6\n6\n5",
"output": "3\n3\n4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 3\n9 3 10\n6\n6\n5",
"output": "4\n4\n4\n",
"type": "stdin_stdout"
},
{
... | |
taco | verifiable_code | https://www.codechef.com/ENCD2020/problems/ECAPR201 | Solve the following coding problem using the programming language python:
Given a string consisting of only lowercase English alphabets, your task is to find the smallest palindromic substring.
In case there are multiple palindromic substrings of the same length present, print the lexicographically smallest substring.... | ```python
T = int(input())
for t in range(T):
N = int(input())
s = sorted(list(str(input())))
print(s[0])
``` | vfc_86762 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/ENCD2020/problems/ECAPR201",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n2\nzy\n1\ncd\n",
"output": "y\nc\n",
"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
# Read input from stdin and provide input before running code
import re
n =int(input())
'''max=0
str=''
'''
maxx=0
strr=''
while(n):
n=n-1
s=input()
strr=strr+s
l=re.findall('C+',s)
if(len(l)!=0):
temp=len(max(l))
if(temp>maxx):
maxx=temp
l=re.findall('C+',strr)
temp=0
if(len(l)!=0):
temp=len(max... | vfc_86766 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "100\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCSCCCCECCCCCCCCCCCCCCCCCCCCCCCCCCECCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCECCCECCCCCCCCCCCCCCCCCCCCCCCCCCCECCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCECCCCCCCCSCCCCCCCCCSCCCECCCCCECCCCCCCCCCCCCCCCCCCCCCCCCCCCCC... | |
taco | verifiable_code | https://www.codechef.com/problems/PRIMES2 | Solve the following coding problem using the programming language python:
Chef has been exploring prime numbers lately, and has recently made a conjecture resembling
one of Goldbach's conjectures.
Chef's conjecture is that any odd number greater than 61 can be expressed as the sum of
a prime, a square of a prime, and ... | ```python
def sieve_erasth(num):
primes = [True] * num
primes[0] = False
primes[1] = False
p = 2
while p * p <= num:
if primes[p] == True:
for i in range(p * p, num, p):
primes[i] = False
p += 1
return primes
num = 10 ** 6
primes = sieve_erasth(num)
def solve(n):
for a in range(100, 1, -1):
if prim... | vfc_86770 | {
"difficulty": "medium_hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/PRIMES2",
"time_limit": "0.261261 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "81\n85\n155\n0",
"output": "5 7 3\n73 2 2\n5 5 5",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Problem
Jennifer and Marian presented Carla with the string S.
However, Carla is not happy to receive the string S.
I wanted the string T.
The three decided to work together to change the string S to the string T.
Jennifer first sorts the let... | ```python
(cha, chzn) = (ord('a'), ord('z') + 1)
(S, T) = ([0] * 128, [0] * 128)
input()
a = input()
for x in a:
S[ord(x)] += 1
S = sorted(S[cha:chzn], reverse=True)
a = input()
for x in a:
T[ord(x)] += 1
T = sorted(T[cha:chzn], reverse=True)
ans = 0
for i in range(26):
ans += abs(S[i] - T[i])
print(ans >> 1)
``` | vfc_86775 | {
"difficulty": "unknown_difficulty",
"memory_limit": "267.38688 megabytes",
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "1.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\ncba\nxyz",
"output": "0\n",
"type": "stdin_stdout"
}
]
} | |
taco | verifiable_code | Solve the following coding problem using the programming language python:
problem
You have to play a darts game with the following rules.
You can throw up to four arrows towards the target. You don't have to throw all four, you don't have to throw one. The target is divided into N parts. The score P1, ..., PN is wri... | ```python
from time import perf_counter
from itertools import combinations_with_replacement
from bisect import bisect_right
from functools import lru_cache
def solve1(darts, scores, point, target):
if darts == 3 or point > target:
if point > target:
return 0
else:
pos = bisect_right(scores, target - point)
... | vfc_86783 | {
"difficulty": "unknown_difficulty",
"memory_limit": "134.217728 megabytes",
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "1.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 58\n3\n14\n15\n9\n3 21\n16\n11\n2\n0 0",
"output": "58\n20\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 50\n3\n14\n27\n9\n3 21\n16\n11\n2\n0 0",
"output": "50\n20\n",
"t... | |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/ways-to-sum-to-n5759/1 | Solve the following coding problem using the programming language python:
Given a set of m distinct positive integers and a value ‘N’. Count the total number of ways we can form ‘N’ by adding the array elements. Repetitions and different arrangements are allowed.
Note: Answer can be quite large output the answer modu... | ```python
class Solution:
def countWays(self, nums, m, target):
n = len(nums)
nums.sort()
dp = [0 for _ in range(target + 1)]
dp[0] = 1
for total in range(1, target + 1):
for i in range(n):
if total - nums[i] >= 0:
dp[total] += dp[total - nums[i]]
return dp[target] % (10 ** 9 + 7)
``` | vfc_86787 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/ways-to-sum-to-n5759/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "m = 3 , N = 7\nArr[] = {1,5,6}",
"output": "6",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "m = 3 , N = 3\nArr[] = {1,2,3}",
"output": "4",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/CHEFSIGN | Solve the following coding problem using the programming language python:
Chef found a strange string yesterday - a string of signs s, where each sign is either a '<', '=' or a '>'. Let N be the length of this string. Chef wants to insert N + 1 positive integers into this sequence and make it valid. A valid sequence i... | ```python
t = int(input())
while t > 0:
s = input()
s = s.replace('=', '')
(i, j, m) = (0, 0, 0)
while i < len(s):
j = i
while j < len(s) and s[j] == s[i]:
j += 1
m = max(m, j - i)
i = j
print(m + 1)
t -= 1
``` | vfc_86788 | {
"difficulty": "medium",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/CHEFSIGN",
"time_limit": "2 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n<<<\n<><\n<=>\n<=<\n",
"output": "4\n2\n2\n3\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
CODE FESTIVAL 2016 is going to be held. For the occasion, Mr. Takahashi decided to make a signboard.
He intended to write `CODEFESTIVAL2016` on it, but he mistakenly wrote a different string S. Fortunately, the string he wrote was the correct l... | ```python
s = input()
t = 'CODEFESTIVAL2016'
ans = 0
for (i, j) in zip(s, t):
if i != j:
ans += 1
print(ans)
``` | vfc_86796 | {
"difficulty": "unknown_difficulty",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "C0DEFESTIVAL2O61",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "EDOC6102LAVITSEF",
"output": "16\n",
"type": "stdin_stdout"
}
]
} | |
taco | verifiable_code | https://www.hackerrank.com/challenges/py-collections-namedtuple/problem | Solve the following coding problem using the programming language python:
collections.namedtuple()
Basically, namedtuples are easy to create, lightweight object types.
They turn tuples into convenient containers for simple tasks.
With namedtuples, you don’t have to use integer indices for accessing members of a t... | ```python
(marks, n, idx) = (0, int(input()), input().split().index('MARKS'))
for k in range(0, n):
marks += int(input().split()[idx])
print(marks / n)
``` | vfc_86808 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.hackerrank.com/challenges/py-collections-namedtuple/problem",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\nID MARKS NAME CLASS \n1 97 Raymond 7 \n2 50 Steven 4 \n3 91 Adrian 9 \n4 72 Stewart 5 \n5 ... |
taco | verifiable_code | Solve the following coding problem using the programming language python:
You have been given an array A of size N consisting of positive integers. You need to find and print the product of all the number in this array Modulo 10^9+7.
Input Format:
The first line contains a single integer N denoting the size of the ... | ```python
n = int(input())
d = list()
ans =1
d = input().split()
for i in range(n):
ans = (ans*int(d[i]))% (pow(10,9) + 7)
print(ans)
``` | vfc_86812 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1000\n290 112 217 950 559 866 239 367 549 141 323 967 927 267 917 681 348 478 868 325 332 391 445 738 809 573 792 662 942 877 727 131 86 723 397 657 507 511 369 921 459 960 870 657 399 973 856 586 674 679 104 133 836 851 716 534 24... | |
taco | verifiable_code | https://www.hackerrank.com/challenges/magic-square-forming/problem | Solve the following coding problem using the programming language python:
We define a magic square to be an $n\times n$ matrix of distinct positive integers from $\mbox{1}$ to $n^2$ where the sum of any row, column, or diagonal of length $n$ is always equal to the same number: the magic constant.
You will be given ... | ```python
from itertools import *
X = []
X.extend(list(map(int, input().split())))
X.extend(list(map(int, input().split())))
X.extend(list(map(int, input().split())))
Ans = 81
for P in permutations(range(1, 10)):
if sum(P[0:3]) == 15 and sum(P[3:6]) == 15 and (sum(P[0::3]) == 15) and (sum(P[1::3]) == 15) and (P[0] + P... | vfc_86820 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.hackerrank.com/challenges/magic-square-forming/problem",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 9 2\n3 5 7\n8 1 5\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 8 2\n4 5 7\n6 1 6\n",
"output": "4\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1305/B | Solve the following coding problem using the programming language python:
Now that Kuroni has reached 10 years old, he is a big boy and doesn't like arrays of integers as presents anymore. This year he wants a Bracket sequence as a Birthday present. More specifically, he wants a bracket sequence so complex that no mat... | ```python
import sys
s = input()
j = len(s)
n = len(s)
ans = []
for i in range(n):
if i >= j:
break
if s[i] == '(':
while True:
j -= 1
if i >= j:
break
if s[j] == ')':
ans.append(i)
ans.append(j)
break
if len(ans) == 0:
print(0)
sys.exit()
else:
print(1)
print(len(ans))
ans = [ans[i] +... | vfc_86824 | {
"difficulty": "easy",
"memory_limit": "256 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1305/B",
"time_limit": "1 second"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "(()((\n",
"output": "1\n2\n1 3 \n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/MNVST | Solve the following coding problem using the programming language python:
Consider an N \times M binary matrix A, i.e. a grid consisting of N rows numbered 1 to N from top to bottom and M columns numbered 1 to M from left to right, whose cells take the value 0 or 1. Let (i, j) denote the cell on the i-th row and j-th ... | ```python
def solve():
(n, m) = map(int, input().split())
if m < n:
n = m
a = []
i = 0
s = 0
while s <= n:
i += 1
s += i
r = 0
s -= i
j = i - 1
for i in range(n - s):
r += (j + 1) * (j + 1)
j -= 1
while j > 0:
r += j * j
j -= 1
print(r)
t = 1
t = int(input())
for _test_ in range(t):
solve()
... | vfc_86828 | {
"difficulty": "very_hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/MNVST",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n3 3\n4 5",
"output": "5\n10",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Construct a dice from a given sequence of integers in the same way as Dice I.
You are given integers on the top face and the front face after the dice was rolled in the same way as Dice I. Write a program to print an integer on the right side f... | ```python
def lotate(dic, dire):
if dire == 'N':
(x, y, z, w) = (dic['up'], dic['back'], dic['bottom'], dic['front'])
(dic['back'], dic['bottom'], dic['front'], dic['up']) = (x, y, z, w)
elif dire == 'S':
(x, y, z, w) = (dic['up'], dic['back'], dic['bottom'], dic['front'])
(dic['front'], dic['up'], dic['back'... | vfc_86832 | {
"difficulty": "unknown_difficulty",
"memory_limit": "134.217728 megabytes",
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "1.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 2 3 4 5 6\n3\n4 5\n1 3\n3 2",
"output": "6\n5\n6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 2 3 4 5 6\n3\n4 5\n1 3\n6 2",
"output": "6\n5\n4\n",
"type": "stdin_stdout"... | |
taco | verifiable_code | https://codeforces.com/problemset/problem/534/B | Solve the following coding problem using the programming language python:
The on-board computer on Polycarp's car measured that the car speed at the beginning of some section of the path equals v_1 meters per second, and in the end it is v_2 meters per second. We know that this section of the route took exactly t seco... | ```python
R = lambda : map(int, input().split())
F = lambda : [int(x) for x in input().split()]
(v1, v2) = R()
(t, d) = R()
ans = v1 + v2
a1 = []
a2 = []
t1 = v1
t2 = v2
for i in range(t - 2):
t1 += d
t2 += d
a1.append(t1)
a2.append(t2)
a2.reverse()
for i in range(t - 2):
ans += min(a1[i], a2[i])
print(ans)
``` | vfc_86836 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/534/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 6\n4 2\n",
"output": "26",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/710/E | Solve the following coding problem using the programming language python:
zscoder wants to generate an input file for some programming competition problem.
His input is a string consisting of n letters 'a'. He is too lazy to write a generator so he will manually generate the input in a text editor.
Initially, the te... | ```python
def fi(n):
if n == 1:
return x
elif n == 2:
return x + min(x, y)
elif n % 2 == 1:
return min(fi(n - 1), fi(n + 1)) + x
else:
return fi(n // 2) + min(y, x * (n // 2))
(n, x, y) = map(int, input().split())
print(fi(n))
``` | vfc_86840 | {
"difficulty": "hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/710/E",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "8 1 1\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8 1 10\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10... |
taco | verifiable_code | Solve the following coding problem using the programming language python:
You are given a string $t$ and a set $S$ of $N$ different strings. You need to separate $t$ such that each part is included in $S$.
For example, the following 4 separation methods satisfy the condition when $t = abab$ and $S = \\{a, ab, b\\}$.
... | ```python
from collections import defaultdict
import sys
def solve():
readline = sys.stdin.readline
write = sys.stdout.write
mod = 10 ** 9 + 9
base = 37
ca = ord('a')
N = int(readline())
SS = [readline().strip() for i in range(N)]
SS.sort(key=len)
T = readline().strip()
L = len(T)
L0 = max(max(map(len, SS))... | vfc_86848 | {
"difficulty": "unknown_difficulty",
"memory_limit": "536.870912 megabytes",
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\na\nb\nba\nabab",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\na\nb\nc\nxy{",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... | |
taco | verifiable_code | https://codeforces.com/problemset/problem/1114/A | Solve the following coding problem using the programming language python:
The Duck song
For simplicity, we'll assume that there are only three types of grapes: green grapes, purple grapes and black grapes.
Andrew, Dmitry and Michal are all grapes' lovers, however their preferences of grapes are different. To make al... | ```python
(a, b, c) = map(int, input().split())
(x, y, z) = map(int, input().split())
if a <= x and x - a + y >= b and (x - a + y - b + z >= c):
print('YES')
else:
print('NO')
``` | vfc_86856 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1114/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 6 2\n4 3 3\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 1 1\n4 3 2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
taco | verifiable_code | https://codeforces.com/problemset/problem/1110/D | Solve the following coding problem using the programming language python:
You are playing a game of Jongmah. You don't need to know the rules to solve this problem. You have n tiles in your hand. Each tile has an integer between 1 and m written on it.
To win the game, you will need to form some number of triples. Eac... | ```python
from collections import Counter
(n, m) = map(int, input().split())
B = list(map(int, input().split()))
cnt = Counter(B)
A = sorted(cnt.keys())
n = len(A)
dp = [[0] * 3 for _ in range(3)]
for (i, a) in enumerate(A):
dp2 = [[0] * 3 for _ in range(3)]
for x in range(1 if i >= 2 and a - 2 != A[i - 2] else 3):
... | vfc_86860 | {
"difficulty": "hard",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1110/D",
"time_limit": "3.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "14 9\n5 5 6 8 8 4 3 2 2 7 3 9 5 4\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "14 11\n10 8 6 1 7 2 9 5 5 10 3 5 11 3\n",
"output": "4\n",
"type": "stdin_std... |
taco | verifiable_code | https://codeforces.com/problemset/problem/333/A | Solve the following coding problem using the programming language python:
Gerald has been selling state secrets at leisure. All the secrets cost the same: n marks. The state which secrets Gerald is selling, has no paper money, only coins. But there are coins of all positive integer denominations that are powers of thr... | ```python
n = int(input())
while not n % 3:
n //= 3
print(n // 3 + 1)
``` | vfc_86864 | {
"difficulty": "medium_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/333/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n",
... |
taco | verifiable_code | https://www.codechef.com/problems/BOGOSORT | Solve the following coding problem using the programming language python:
Recently Johnny have learned bogosort sorting algorithm. He thought that it is too ineffective. So he decided to improve it. As you may know this algorithm shuffles the sequence randomly until it is sorted. Johnny decided that we don't need to s... | ```python
from fractions import Fraction
fac = [1 for i in range(151)]
for i in range(1, 151):
fac[i] = fac[i - 1] * i
count = [fac[i] - 2 * fac[i - 1] + fac[i - 2] for i in range(151)]
f = [Fraction(0, 1) for i in range(151)]
add = [Fraction(0, 1) for i in range(151)]
tot = Fraction(0, 1)
last = Fraction(0, 1)
for n ... | vfc_86868 | {
"difficulty": "medium_hard",
"memory_limit": "10000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/BOGOSORT",
"time_limit": "0.83 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n2\n6\n10",
"output": "2\n1826/189\n877318/35343",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n2\n4\n10",
"output": "2\n5\n877318/35343\n",
"type": "stdin_stdout"
}
... |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/maximize-dot-product2649/1 | Solve the following coding problem using the programming language python:
Given two arrays A and B of positive integers of size N and M where N >= M, the task is to maximize the dot product by inserting zeros in the second array but you cannot disturb the order of elements.
Dot Product of array A and B of size N is A[... | ```python
class Solution:
def solve(self, i, j, n, m, A, B, dp, d):
if i == n or j == m:
return 0
if dp[i][j] != -1:
return dp[i][j]
if d > 0:
dp[i][j] = max(A[i] * B[j] + self.solve(i + 1, j + 1, n, m, A, B, dp, d), self.solve(i + 1, j, n, m, A, B, dp, d - 1))
else:
dp[i][j] = A[i] * B[j] + self.... | vfc_86876 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/maximize-dot-product2649/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N = 5, A[] = {2, 3, 1, 7, 8} \n M = 3, B[] = {3, 6, 7}",
"output": "107",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "N = 3, A[] = {1, 2, 3}\n M = 1, B[] = {4}",
"output"... |
taco | verifiable_code | https://codeforces.com/problemset/problem/1181/C | Solve the following coding problem using the programming language python:
Innokenty works at a flea market and sells some random stuff rare items. Recently he found an old rectangular blanket. It turned out that the blanket is split in $n \cdot m$ colored pieces that form a rectangle with $n$ rows and $m$ columns.
T... | ```python
(n, m) = [int(x) for x in input().split()]
a = [[] * (m + 1) for i in range(n + 1)]
cols = [[0] * (m + 1) for i in range(n + 1)]
rows = [[0] * (m + 1) for i in range(n + 1)]
a[0] = '*' * (m + 1)
for i in range(1, n + 1):
a[i] = '*' + input()
for i in range(1, n + 1):
for j in range(1, m + 1):
if a[i][j] =... | vfc_86877 | {
"difficulty": "hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1181/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 3\naaa\nbbb\nccb\nddd\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 1\na\na\nb\nb\nc\nc\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"f... |
taco | verifiable_code | https://codeforces.com/problemset/problem/1669/B | Solve the following coding problem using the programming language python:
Given an array $a$ of $n$ elements, print any value that appears at least three times or print -1 if there is no such value.
-----Input-----
The first line contains an integer $t$ ($1 \leq t \leq 10^4$) — the number of test cases.
The first ... | ```python
import sys
from typing import Tuple
input = sys.stdin.readline
def inp():
return int(input())
def inlt():
return list(map(int, input().split()))
def insr():
s = input()
return list(s[:len(s) - 1])
def invr():
return map(int, input().split())
def inps():
return str(input()).strip()
T = inp()
for i i... | vfc_86885 | {
"difficulty": "easy",
"memory_limit": "256 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1669/B",
"time_limit": "1 second"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7\n1\n1\n3\n2 2 2\n7\n2 2 3 3 4 2 2\n8\n1 4 3 4 3 2 4 1\n9\n1 1 1 2 2 2 3 3 3\n5\n1 5 2 4 3\n4\n4 4 4 4\n",
"output": "-1\n2\n2\n4\n3\n-1\n4\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/second-most-repeated-string-in-a-sequence0534/1 | Solve the following coding problem using the programming language python:
Given a sequence of strings, the task is to find out the second most repeated (or frequent) string in the given sequence.
Note: No two strings are the second most repeated, there will be always a single string.
Example 1:
Input:
N = 6
arr[] = {a... | ```python
class Solution:
def secFrequent(self, arr, n):
d = {}
for i in arr:
if i not in d:
d[i] = 1
else:
d[i] += 1
a = sorted(d.items(), key=lambda x: x[1])
return a[-2][0]
``` | vfc_86898 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/second-most-repeated-string-in-a-sequence0534/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N = 6\narr[] = {aaa, bbb, ccc, bbb, aaa, aaa}",
"output": "bbb",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "N = 6\narr[] = {geek, for, geek, for, geek, aaa}",
"output": "for",
... |
taco | verifiable_code | https://www.codechef.com/CY302020/problems/CODY303 | Solve the following coding problem using the programming language python:
Since due to COVID 19, India has undergone a complete 21 day lockdown. So Amol was attending an online lecture where his professor asked him to solve a question. Amol was unable to solve the question so he asked you to solve the question and giv... | ```python
try:
def countsubsetsum(S, arr, n):
k = [[0 for i in range(S + 1)] for i in range(n + 1)]
for i in range(n + 1):
for j in range(S + 1):
if j == 0:
k[i][j] = 1
elif i == 0:
k[i][j] = 0
elif arr[i - 1] <= j:
k[i][j] = k[i - 1][j - arr[i - 1]] + k[i - 1][j]
else:
k[i]... | vfc_86901 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/CY302020/problems/CODY303",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n4\n16\n2 4 6 10\n4\n20\n2 8 12 10\n",
"output": "2\n2\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/geek-jump/1 | Solve the following coding problem using the programming language python:
Geek wants to climb from the 0th stair to the (n-1)th stair. At a time the Geek can climb either one or two steps. A height[N] array is also given. Whenever the geek jumps from stair i to stair j, the energy consumed in the jump is abs(height[i]... | ```python
import sys
class Solution:
def minimumEnergy(self, height, n):
prev = 0
prev2 = 0
for i in range(1, n, 1):
first = prev + abs(height[i] - height[i - 1])
second = sys.maxsize
if i > 1:
second = prev2 + abs(height[i] - height[i - 2])
curr = min(first, second)
prev2 = prev
prev = c... | vfc_86905 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/geek-jump/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "n = 4\r\nheight = {10 20 30 10}",
"output": "20",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/UTKPLC | Solve the following coding problem using the programming language python:
Utkarsh is currently sitting for placements. He has applied to three companies named A, B, and C.
You know Utkarsh's order of preference among these 3 companies, given to you as characters first, second, and third respectively (where first is t... | ```python
t = int(input())
for i in range(t):
(f, s, t) = input().split()
(x, y) = input().split()
if f == x or f == y:
print(f)
elif s == x or s == y:
print(s)
else:
print(t)
``` | vfc_86910 | {
"difficulty": "easy",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/UTKPLC",
"time_limit": "0.5 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\nA B C\nA B\nB C A\nA C",
"output": "A\nC",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/445/A | Solve the following coding problem using the programming language python:
DZY loves chessboard, and he enjoys playing with it.
He has a chessboard of n rows and m columns. Some cells of the chessboard are bad, others are good. For every good cell, DZY wants to put a chessman on it. Each chessman is either white or bl... | ```python
(n, m) = map(int, input().split())
for i in range(n):
s = input()
o = ''
for j in range(m):
if s[j] == '.':
if (i + j) % 2 == 0:
o += 'B'
else:
o += 'W'
else:
o += s[j]
print(o)
``` | vfc_86914 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/445/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 1\n.\n",
"output": "B\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 2\n..\n..\n",
"output": "BW\nWB\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"... |
taco | verifiable_code | https://www.codechef.com/problems/POKER | Solve the following coding problem using the programming language python:
In poker, you have 5 cards. There are 10 kinds of poker hands (from highest to lowest):
- royal flush - ace, king, queen, jack and ten, all in the same suit
- straight flush - five cards of the same suit in sequence, such
as 10,9,8,7,6 of cl... | ```python
cards = ['A', '2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K']
def royal_flush(arr):
nonlocal ans, confirm
rf_set = 'TJQKA'
rf = 1
for char in arr:
if char[0] not in rf_set:
rf = 0
break
if rf:
if len(set(suit)) == 1:
ans = 'royal flush'
confirm = 1
def straight_flush(arr):
... | vfc_86922 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/POKER",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\nAH KH QH TH JH\nKH 5S 3C 5C 7D\nQH QD 2S QC 2C\n",
"output": "royal flush\npair\nfull house\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\nAH KH QH TH JH\nKH 5S 3D 5C 7D\nQH QD 2S Q... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.