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 | Solve the following coding problem using the programming language python:
Shil got an array of N integers as a present on his birthday. But he didn't liked it. Shil wants to make this array beautiful. Shil considers an array A1,A2,A3 . . . AN beautiful if A1 > AN. Inorder to make it beautiful Shil can swap any two n... | ```python
n = int(eval(input()))
se = set()
li = list(map(int,input().split()))
for i in range(n):
se.add(li[i])
n = len(se)
print((n*(n-1)/2))
``` | vfc_135194 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10000\n9384 887 2778 6916 7794 8336 5387 493 6650 1422 2363 28 8691 60 7764 3927 541 3427 9173 5737 5212 5369 2568 6430 5783 1531 2863 5124 4068 3136 3930 9803 4023 3059 3070 8168 1394 8457 5012 8043 6230 7374 4422 4920 3785 8538 5... | |
taco | verifiable_code | https://www.hackerrank.com/challenges/xor-quadruples/problem | Solve the following coding problem using the programming language python:
We call an quadruple of positive integers, $(W,X,Y,Z)$, beautiful if the following condition is true:
$W\oplus X\oplus Y\oplus Z\neq0$
Note: $\theta$ is the bitwise XOR operator.
Given $\mbox{A}$, $\mbox{B}$, $\mbox{C}$, and $\mbox{D}$, count... | ```python
import sys
(A, B, C, D) = input().strip().split(' ')
temp = [int(A), int(B), int(C), int(D)]
temp.sort()
(A, B, C, D) = temp
tot = [0] * 4100
tree = [([0] * 3100).copy() for i in range(4100)]
cnt = [([0] * 3100).copy() for i in range(4100)]
def updateBIT(treeNo, ind):
while ind < 3100:
tree[treeNo][ind] +... | vfc_135198 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.hackerrank.com/challenges/xor-quadruples/problem",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 2 3 4\n",
"output": "11\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1434/A | Solve the following coding problem using the programming language python:
After battling Shikamaru, Tayuya decided that her flute is too predictable, and replaced it with a guitar. The guitar has 6 strings and an infinite number of frets numbered from 1. Fretting the fret number j on the i-th string produces the note ... | ```python
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = 'x' in file.mode or 'r' not in file.mode
self.write = self.buffer.write if self.writable else None
def ... | vfc_135202 | {
"difficulty": "hard",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1434/A",
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 4 7 6 4 1\n10\n19 16 18 12 16 15 16 20 16 14\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "158260522 877914575 602436426 24979445 861648772 623690081\n1\n896194147\n",... |
taco | verifiable_code | https://www.hackerrank.com/challenges/halloween-sale/problem | Solve the following coding problem using the programming language python:
You wish to buy video games from the famous online video game store Mist.
Usually, all games are sold at the same price, $\boldsymbol{p}$ dollars. However, they are planning to have the seasonal Halloween Sale next month in which you can buy ga... | ```python
(p, d, m, s) = map(int, input().split())
i = 0
cost = p
while s - cost >= 0:
i += 1
s -= cost
cost = max(cost - d, m)
print(i)
``` | vfc_135207 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.hackerrank.com/challenges/halloween-sale/problem",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "20 3 6 80\n",
"output": "6\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/consecutive-array-elements2711/1 | Solve the following coding problem using the programming language python:
Given an unsorted array arr[] of size N, the task is to check whether the array consists of consecutive numbers or not.
Example 1:
Input: N = 5, arr[] = {5, 4, 2, 1, 3}
Output: Yes
Explanation: All are consecutive elements,
according to this ord... | ```python
class Solution:
def areConsecutives(self, arr, n):
min_ = min(arr)
p = list(range(min_, min_ + n))
dict_ = {elem: 0 for elem in arr}
for elem in p:
if elem not in dict_:
return False
return True
``` | vfc_135215 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/consecutive-array-elements2711/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N = 5, arr[] = {5, 4, 2, 1, 3}",
"output": "Yes",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "N = 6, arr[] = {2, 1, 0, -3, -1, -2}",
"output": "Yes",
"type": "stdin_stdout"
... |
taco | verifiable_code | https://codeforces.com/problemset/problem/1657/B | Solve the following coding problem using the programming language python:
You are given four integers $n$, $B$, $x$ and $y$. You should build a sequence $a_0, a_1, a_2, \dots, a_n$ where $a_0 = 0$ and for each $i \ge 1$ you can choose:
either $a_i = a_{i - 1} + x$
or $a_i = a_{i - 1} - y$.
Your goal is to build suc... | ```python
import sys
def get_ints():
return map(int, sys.stdin.readline().strip().split())
def get_ls():
return list(map(int, sys.stdin.readline().strip().split()))
def main():
for _ in range(int(input())):
(n, b, x, y) = get_ints()
a = 0
ans = a
for i in range(n):
if a + x <= b:
a += x
else:
... | vfc_135220 | {
"difficulty": "easy",
"memory_limit": "256 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1657/B",
"time_limit": "2 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3\n",
"output": "15\n4000000000\n-10\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n100000 1000000000 1000000000 1\n100000 1 10... |
taco | verifiable_code | https://codeforces.com/problemset/problem/649/D | Solve the following coding problem using the programming language python:
Память компьютера состоит из n ячеек, которые выстроены в ряд. Пронумеруем ячейки от 1 до n слева направо. Про каждую ячейку известно, свободна она или принадлежит какому-либо процессу (в таком случае известен процесс, которому она принадлежит).... | ```python
input()
memory = list(map(int, input().split()))
proc_data = {p: (-1, -1) for p in memory}
for (i, c) in enumerate(memory):
(d1, d2) = proc_data[c]
if d1 == -1:
d1 = i
d2 = i
proc_data[c] = (d1, d2)
try:
del proc_data[0]
except KeyError:
print('0')
return
data = list(proc_data.values())
data.sort()
a... | vfc_135224 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/649/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n0 2 2 1\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/RECHEND | Solve the following coding problem using the programming language python:
Read problem statements in [Mandarin], [Bengali], and [Russian] as well.
You are given a positive integer N. Consider a square grid of size N \times N, with rows numbered 1 to N from top to bottom and columns numbered 1 to N from left to right... | ```python
import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
n = int(input())
c = dict()
for i in range(n):
(a, b) = map(int, input().split())
if a + b in c:
c[a + b] += 1
else:
c[a + b] = 1
fl = 1
for i in range(2, n + 1):
if i in c:
if c[i] == i - 1:
fl = 0
break
... | vfc_135228 | {
"difficulty": "hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/RECHEND",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n3\n1 2\n2 3\n3 1\n2\n1 2\n2 1",
"output": "YES\nNO",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/queries-on-strings5636/1 | Solve the following coding problem using the programming language python:
Given a string str you have to answer several queries on that string. In each query you will be provided two values L and R and you have to find the number of distinct characters in the sub string from index L to index R (inclusive) of the origi... | ```python
class Solution:
def SolveQueris(self, str, Query):
res = []
for Pair in Query:
s = set()
string = str[Pair[0] - 1:Pair[1]]
for i in string:
if i not in s:
s.add(i)
res.append(len(s))
return res
``` | vfc_135232 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/queries-on-strings5636/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "str = \"abcbaed\",\r\nQuery = {{1,4},{2,4},{1,7}}",
"output": "{3,2,5}",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/74/C | Solve the following coding problem using the programming language python:
Let's imagine: there is a chess piece billiard ball. Its movements resemble the ones of a bishop chess piece. The only difference is that when a billiard ball hits the board's border, it can reflect from it and continue moving.
More formally, f... | ```python
import math
(n, m) = map(int, input().split())
print(math.gcd(n - 1, m - 1) + 1)
``` | vfc_135234 | {
"difficulty": "hard",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/74/C",
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "8 50\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "302237 618749\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input... |
taco | verifiable_code | https://codeforces.com/problemset/problem/1025/A | Solve the following coding problem using the programming language python:
Panic is rising in the committee for doggo standardization — the puppies of the new brood have been born multi-colored! In total there are 26 possible colors of puppies in the nature and they are denoted by letters from 'a' to 'z' inclusive.
Th... | ```python
n = int(input())
string = input()
array = []
for i in range(0, 27):
array.append(0)
for j in range(0, n):
num = ord(string[j]) - 96
array[num] += 1
if len(string) == 1:
print('Yes')
else:
for i in array:
if i == 0:
continue
elif i >= 2:
print('Yes')
break
else:
print('No')
``` | vfc_135238 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1025/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\naabddc\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\nabc\n",
"output": "No\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/95/A | Solve the following coding problem using the programming language python:
Petya loves hockey very much. One day, as he was watching a hockey match, he fell asleep. Petya dreamt of being appointed to change a hockey team's name. Thus, Petya was given the original team name w and the collection of forbidden substrings s... | ```python
n = int(input())
a = []
for i in range(n):
a.append(input().rstrip())
w = list(input().rstrip())
c = input().rstrip()
m = len(w)
z = []
i = 0
while i < m:
for j in range(n):
if w[i].lower() == a[j][0].lower():
if i + len(a[j]) <= m:
f = 1
for k in range(i, i + len(a[j])):
if w[k].lower() !... | vfc_135242 | {
"difficulty": "medium_hard",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/95/A",
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\netr\ned\nied\nPetrUnited\nz\n",
"output": "PzzzUnitzz\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/MAXIMUMSUBS | Solve the following coding problem using the programming language python:
A participant can make 1 submission every 30 seconds. If a contest lasts for X minutes, what is the maximum number of submissions that the participant can make during it?
It is also given that the participant cannot make any submission in the l... | ```python
a = int(input())
for i in range(a):
b = int(input())
print(b * 2)
``` | vfc_135246 | {
"difficulty": "easy",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/MAXIMUMSUBS",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1\n2\n3\n4\n",
"output": "2\n4\n6\n8\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/COOK11/problems/KNIGHTMV | Solve the following coding problem using the programming language python:
Chef develops his own computer program for playing chess. He is at the very beginning. At first he needs to write the module that will receive moves written by the players and analyze it. The module will receive a string and it should report at ... | ```python
def gc(c):
return 'a' <= c <= 'h'
def gd(c):
return '1' <= c <= '8'
t = int(input())
for i in range(t):
line = input()
if len(line) != 5:
print('Error')
continue
if line[2] != '-':
print('Error')
continue
x1 = line[0]
y1 = line[1]
x2 = line[3]
y2 = line[4]
if gc(x1) and gd(y1) and gc(x2) an... | vfc_135251 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/COOK11/problems/KNIGHTMV",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\na1-b3\nd2-h8\na3 c4\nErrorError\n",
"output": "Yes\nNo\nError\nError\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/equalization-of-an-array1656/1 | Solve the following coding problem using the programming language python:
Given an array of N integers arr[ ], the task is to count the minimum number of operations to equalize the array i.e. to make all array elements equal.
In one operation, you can choose two elements arr[i] and arr[j] such that arr[i] > arr[j] and... | ```python
class Solution:
def findDifference(self, arr, N):
s = sum(arr)
if s % N != 0:
return -1
ds = 0
e = s / n
for i in range(n):
ds += abs(arr[i] - e)
return int(ds / 2)
``` | vfc_135259 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/equalization-of-an-array1656/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N = 5\narr[] = {1, 3, 2, 0, 4}",
"output": "3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "N = 3\narr[] = {1, 7, 1}",
"output": "4",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1159/C | Solve the following coding problem using the programming language python:
n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal... | ```python
(n, m) = list(map(int, input().split()))
b = list(map(int, input().split()))
g = list(map(int, input().split()))
b.sort()
g.sort()
if b[-1] > g[0]:
print(-1)
elif b[-1] == g[0]:
print(sum(g) + m * (sum(b) - b[-1]))
elif n == 1:
print(-1)
else:
print(sum(g) + b[-1] + b[-2] * (m - 1) + m * (sum(b) - b[-1] -... | vfc_135260 | {
"difficulty": "medium",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1159/C",
"time_limit": "1.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 2\n14419485 34715515\n45193875 34715515\n",
"output": "108748360\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 2\n100000000 100000000\n0 0\n",
"output": "-1\n",
"type": "... |
taco | verifiable_code | https://codeforces.com/problemset/problem/139/C | Solve the following coding problem using the programming language python:
Vera adores poems. All the poems Vera knows are divided into quatrains (groups of four lines) and in each quatrain some lines contain rhymes.
Let's consider that all lines in the poems consist of lowercase Latin letters (without spaces). Letter... | ```python
import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase
def vsInput():
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def ... | vfc_135264 | {
"difficulty": "medium_hard",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/139/C",
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 2\netba\ntfecetba\nzkitbgcuuy\nuuy\nbuxeoi\nmekxoi\nblviwoehy\niwoehy\njyfpaqntiz\nqvaqntiz\nhciak\niak\n",
"output": "aabb\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 1\na\na\na\n... |
taco | verifiable_code | https://codeforces.com/problemset/problem/990/A | Solve the following coding problem using the programming language python:
Berland Football Cup starts really soon! Commentators from all over the world come to the event.
Organizers have already built $n$ commentary boxes. $m$ regional delegations will come to the Cup. Every delegation should get the same number of t... | ```python
import sys
import math
get_string = lambda : sys.stdin.readline().strip()
get_int_list = lambda : list(map(int, sys.stdin.readline().strip().split()))
get_int = lambda : int(sys.stdin.readline())
(n, m, a, b) = get_int_list()
if n % m == 0:
print(0)
else:
res1 = n % m
res2 = m - res1
if res1 * b < res2 * ... | vfc_135270 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/990/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "9 7 3 8\n",
"output": "15\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 7 3 7\n",
"output": "14\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input"... |
taco | verifiable_code | https://codeforces.com/problemset/problem/960/C | Solve the following coding problem using the programming language python:
Pikachu had an array with him. He wrote down all the non-empty subsequences of the array on paper. Note that an array of size n has 2^{n} - 1 non-empty subsequences in it.
Pikachu being mischievous as he always is, removed all the subsequences... | ```python
p2 = [(i, 2 ** i - 1) for i in range(1, 40)]
(X, d) = map(int, input().split(' '))
lens = []
for i in p2[::-1]:
if X >= i[1]:
X -= i[1]
lens.append(i[0])
el = 1
if sum(lens) >= 10000:
print(-1)
exit(0)
print(sum(lens) + X)
for i in lens:
print((str(el) + ' ') * i, end='')
el += d
for i in range(X):
... | vfc_135274 | {
"difficulty": "medium_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/960/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10 5\n",
"output": "6\n1 1 1 7 13 19 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 2\n",
"output": "3\n1 1 4 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
taco | verifiable_code | https://www.codechef.com/INDC2021/problems/NAV28 | Solve the following coding problem using the programming language python:
Navnit is a college student and there are $N$ students in his college .Students are numbered from $1$ to $N$.
You are given $M$ facts that "Student $A_i$ and $B_i$".The same fact can be given multiple times .If $A_i$ is a friend of $B_i$ ,then $... | ```python
from collections import defaultdict
d = defaultdict(list)
def dfs(i):
p = 0
nonlocal v
e = [i]
while e != []:
p += 1
x = e.pop(0)
v[x] = 1
for i in d[x]:
if v[i] == -1:
v[i] = 1
e.append(i)
return p
(n, m) = list(map(int, input().split()))
for i in range(n + 1):
d[i] = []
for _ in ra... | vfc_135278 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/INDC2021/problems/NAV28",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 3\n1 2\n3 4\n1 5\n",
"output": "6\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Roy has a matrix of size NxN. Rows and Columns are numbered from 0 to N-1.
j^th column of i^th row contains i xor j.
In other words, Matrix[i][j] = i ^ j where 0 ≤ i,j < N. ( ^ is a bitwise operation used in C/C++ for xor, please use appropr... | ```python
from math import log,floor
for _ in range(int(input())):
n=int(input())
if n==1:
print("0 1")
continue
t=log(n-1,2)
x=int(floor(t))
print("%d %d"%(2**(x+1) -1,2*(n-2**(x))))
``` | vfc_135282 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "36\n10\n9\n100\n99\n1000\n999\n10000\n9999\n100000\n99999\n1000000\n999999\n10000000\n9999999\n100000000\n99999999\n1000000000\n999999999\n10000000000\n9999999999\n100000000000\n99999999999\n1000000000000\n999999999999\n10000000000... | |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/max-sum-in-the-configuration/1 | Solve the following coding problem using the programming language python:
Given an array(0-based indexing), you have to find the max sum of i*A[i] where A[i] is the element at index i in the array. The only operation allowed is to rotate(clock-wise or counter clock-wise) the array any number of times.
Example 1:
Input... | ```python
def max_sum(a, n):
total_sum = 0
product_sum = 0
if n == 1:
return 0
for i in range(n):
total_sum += a[i]
product_sum += a[i] * i
max_product = product_sum
for i in range(n - 1, -1, -1):
product_sum = product_sum + total_sum - a[i] * n
max_product = max(max_product, product_sum)
return max_pr... | vfc_135287 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/max-sum-in-the-configuration/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": "max_sum",
"input": "N = 4\nA[] = {8,3,1,2}",
"output": "29",
"type": "function_call"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/count-number-of-elements-between-two-given-elements-in-array4044/1 | Solve the following coding problem using the programming language python:
Given an unsorted array and two elements num1 and num2. The task is to count the number of elements occurs between the given elements (excluding num1 and num2). If there are multiple occurrences of num1 and num2, we need to consider leftmost occ... | ```python
class Solution:
def getCount(self, arr, n, num1, num2):
l = arr.index(num1)
r = len(arr) - 1 - arr[::-1].index(num2)
count = 0
for i in range(l + 1, r):
count += 1
return count
``` | vfc_135288 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/count-number-of-elements-between-two-given-elements-in-array4044/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "Arr[] = {4, 2, 1, 10, 6}\nnum1 = 4 and num2 = 6",
"output": "3",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/closest-palindrome4519/1 | Solve the following coding problem using the programming language python:
Given a number num, our task is to find the closest Palindrome number whose absolute difference with given number is minimum. If 2 Palindome numbers have same absolute difference from the given number, then find the smaller one.
Example 1:
Inp... | ```python
import math
class Solution:
def closestPalindrome(self, n):
n = int(n)
if n < 10:
return n
elif math.log(n, 10) - int(math.log(n, 10)) == 0:
return n - 1
else:
out = str(n)
ll = int((len(out) + 1) / 2)
first_Half = out[:ll]
if len(out) % 2 == 0:
n1 = int(first_Half + first_Hal... | vfc_135289 | {
"difficulty": "medium_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/closest-palindrome4519/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "num = 9",
"output": "9",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "num = 489",
"output": "484",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/CAKEDOOM | Solve the following coding problem using the programming language python:
From the FAQ:
What am I allowed to post as a comment for a problem?
Do NOT post code.
Do NOT post a comment asking why your solution is wrong.
Do NOT post a comment asking if you can be given the test case your program fails on.
Do NOT post a... | ```python
t = int(input())
for _ in range(t):
k = int(input())
s = list(input())
if k == 1 or len(s) == 1:
if len(s) == 1:
if s[0] != '?' and s[0] <= str(k - 1):
print(s[0])
elif s[0] != '?' and s[0] > str(k - 1):
print('NO')
elif s[0] == '?':
print(0)
else:
print('NO')
elif k == 2:
if... | vfc_135290 | {
"difficulty": "medium_hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/CAKEDOOM",
"time_limit": "0.386023 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7\n1\n?\n2\n?0\n10\n79259?087\n2\n??\n3\n0?1\n4\n?????\n3\n012",
"output": "0\n10\nNO\n01\n021\n01012\n012",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7\n1\n?\n2\n?0\n10\n79259?087\n2\n?... |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/parenthesis-checker2744/1 | Solve the following coding problem using the programming language python:
Given an expression string x. Examine whether the pairs and the orders of {,},(,),[,] are correct in exp.
For example, the function should return 'true' for exp = [()]{}{[()()]()} and 'false' for exp = [(]).
Note: The drive code prints "balanced... | ```python
class Solution:
def ispar(self, x):
open = ['{', '(', '[']
close = ['}', ')', ']']
stack = []
for i in x:
if i in open:
stack.append(i)
elif i in close:
if len(stack) > 0:
if close.index(i) == open.index(stack[-1]):
stack.pop()
else:
return False
else:
re... | vfc_135294 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/parenthesis-checker2744/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "{([])}",
"output": "true",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "()",
"output": "true",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "([]",
... |
taco | verifiable_code | https://codeforces.com/problemset/problem/1649/B | Solve the following coding problem using the programming language python:
Daniel is watching a football team playing a game during their training session. They want to improve their passing skills during that session.
The game involves $n$ players, making multiple passes towards each other. Unfortunately, since the b... | ```python
import sys
input = sys.stdin.readline
t = int(input())
out = ''
for _ in range(t):
n = int(input())
arr = [int(x) for x in input().split()]
if arr.count(0) == n:
out += '0\n'
else:
out += str(max(1, max(arr) * 2 - sum(arr))) + '\n'
print(out)
``` | vfc_135299 | {
"difficulty": "easy",
"memory_limit": "256 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1649/B",
"time_limit": "1 second"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n4\n2 3 3 2\n3\n1 5 2\n2\n0 0\n4\n1000000000 1000000000 1000000000 1000000000\n",
"output": "1\n2\n0\n1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n2\n1000000000 0\n",
"outp... |
taco | verifiable_code | https://www.hackerrank.com/challenges/jeanies-route/problem | Solve the following coding problem using the programming language python:
Byteland has $N$ cities (numbered from $\mbox{1}$ to $N$) and $N-1$ bidirectional roads. It is guaranteed that there is a route from any city to any other city.
Jeanie is a postal worker who must deliver $\mbox{K}$ letters to various cities in... | ```python
[n, k] = list(map(int, input().split(' ')))
cities = set(map(int, input().split(' ')))
def log(*args):
if False:
print(*args)
counts = dict()
edges = dict()
for i in range(n):
edges[i + 1] = dict()
total = 0
for _ in range(n - 1):
[u, v, d] = list(map(int, input().split(' ')))
counts[u] = counts.get(u,... | vfc_135307 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.hackerrank.com/challenges/jeanies-route/problem",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 3\n1 3 4\n1 2 1\n2 3 2\n2 4 2\n3 5 3\n",
"output": "6\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Given K prime numbers and T queries of form Ai, Bi, for each query print the number of integers between Ai and Bi (both inclusive) that are divisible by atleast one of the K given primes.
Input
First line: K and T.
Second line: K primes.
... | ```python
from itertools import combinations
k,t=list(map(int,input().split()))
primes=list(map(int,input().split()))
final=[]
for i in range(1,k+1):
arr=combinations(primes,i)
for item in arr:
final.append(item)
for _ in range(t):
a,b=list(map(int,input().split()))
count=0
i=0
while i<len(final):
prod=1
... | vfc_135315 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10 100\n2 3 5 7 11 37 1000003 71 101 103\n5290021 982425129\n8505031 551538918\n7664127 844108421\n5263111 947266352\n6441031 125008940\n7764822 337937173\n301907 929886877\n8883038 454040626\n3739338 873454435\n1316343 209004362\n... | |
taco | verifiable_code | Solve the following coding problem using the programming language python:
This is a story in a depopulated area. In this area, houses are sparsely built along a straight road called Country Road. Until now, there was no electricity in this area, but this time the government will give us some generators. You can instal... | ```python
NUM = int(input())
for sect in range(NUM):
(n, k) = list(map(int, input().strip().split()))
x = list(map(int, input().strip().split()))
x.sort()
diff = []
for i in range(1, len(x)):
diff.append(x[i] - x[i - 1])
diff.sort(reverse=True)
s = sum(diff[:k - 1])
print(max(x) - min(x) - s)
``` | vfc_135319 | {
"difficulty": "unknown_difficulty",
"memory_limit": "134.217728 megabytes",
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "5.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n5 2\n10 30 40 70 100\n7 3\n3 4 10 17 21 26 28\n1 1\n100\n2 1\n0 1000000\n3 5\n30 70 150\n6 4\n0 10 20 30 40 50",
"output": "60\n12\n0\n1000000\n0\n20\n",
"type": "stdin_stdout"
}
]
} | |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Hakone Ekiden is one of the Japanese New Year's traditions. In Hakone Ekiden, 10 runners from each team aim for the goal while connecting the sashes at each relay station. In the TV broadcast, the ranking change from the previous relay station i... | ```python
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop, heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import dequ... | vfc_135323 | {
"difficulty": "unknown_difficulty",
"memory_limit": "262.144 megabytes",
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\nD\nT",
"output": "0\n",
"type": "stdin_stdout"
}
]
} | |
taco | verifiable_code | https://www.codechef.com/DEC11/problems/HYPER | Solve the following coding problem using the programming language python:
A hypergraph is a generalization of a graph, where an edge can connect any number of vertices. A k-uniform hypergraph is a hypergraph such that all its hyperedges have size k. For more information, see Wikipedia.
Let's call a particular hypergr... | ```python
output = '\n{(6, 9): 10559808000, (0, 7): 0, (1, 6): 0, (0, 10): 0, (3, 7): 2142, (2, 5): 1, (1, 11): 0, (5, 8): 48094200, (6, 7): 6350400, (5, 5): 1440, (6, 10): 247973140800, (0, 17): 0, (0, 4): 0, (1, 1): 0, (4, 10): 57808440, (2, 6): 1, (5, 11): 84587745000, (4, 5): 2160, (0, 1): 0, (3, 12): 531366, (1, 1... | vfc_135331 | {
"difficulty": "hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/DEC11/problems/HYPER",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n3\n4\n5\n8\n\n\n",
"output": "1\n6\n25\n93268\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/96/B | Solve the following coding problem using the programming language python:
Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Lucky number is super lucky... | ```python
gh = set()
def rep(n, four, seven):
global gh
if n > 10000000000:
return
if four == seven:
gh |= {n}
rep(n * 10 + 4, four + 1, seven)
rep(n * 10 + 7, four, seven + 1)
rep(0, 0, 0)
gh = sorted(gh)
def bin_s(a):
lo = 0
hi = len(gh)
ans = 0
while lo <= hi:
mid = (lo + hi) // 2
if gh[mid] >= a:... | vfc_135336 | {
"difficulty": "easy",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/96/B",
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "447777\n",
"output": "474477\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "444000000\n",
"output": "4444477777\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
taco | verifiable_code | https://www.codechef.com/PBK32020/problems/ITGUY30 | Solve the following coding problem using the programming language python:
Cheffina challanges chef to rearrange the given array as arr[i] > arr[i+1] < arr[i+2] > arr[i+3].. and so on…, i.e. also arr[i] < arr[i+2] and arr[i+1] < arr[i+3] and arr[i] < arr[i+3] so on.. Chef accepts the challenge, chef starts coding but h... | ```python
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
a.sort()
i = 1
while i < n:
(a[i - 1], a[i]) = (a[i], a[i - 1])
i += 2
print(*a)
``` | vfc_135340 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/PBK32020/problems/ITGUY30",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n4\n4 1 6 3\n5\n4 5 1 6 3\n",
"output": "3 1 6 4\n3 1 5 4 6\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.hackerrank.com/challenges/find-digits/problem | Solve the following coding problem using the programming language python:
An integer $\boldsymbol{d}$ is a divisor of an integer $n$ if the remainder of $n\div d=0$.
Given an integer, for each digit that makes up the integer determine whether it is a divisor. Count the number of divisors occurring within the integ... | ```python
def func(A):
return len([1 for i in str(A) if i != '0' and A % int(i) == 0])
for t in range(int(input())):
print(func(int(input())))
``` | vfc_135344 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.hackerrank.com/challenges/find-digits/problem",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n12\n1012\n",
"output": "2\n3\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.hackerrank.com/challenges/np-dot-and-cross/problem | Solve the following coding problem using the programming language python:
dot
The dot tool returns the dot product of two arrays.
import numpy
A = numpy.array([ 1, 2 ])
B = numpy.array([ 3, 4 ])
print numpy.dot(A, B) #Output : 11
cross
The cross tool returns the cross product of two arrays.
import numpy
... | ```python
import numpy
n = int(input())
A = [[int(i) for i in input().strip().split()] for j in range(n)]
B = [[int(i) for i in input().strip().split()] for j in range(n)]
print(numpy.dot(A, B))
``` | vfc_135348 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.hackerrank.com/challenges/np-dot-and-cross/problem",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n1 2\n3 4\n1 2\n3 4\n",
"output": "[[ 7 10]\n [15 22]]\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/number-of-divisors-in-a-given-range3738/1 | Solve the following coding problem using the programming language python:
Given a range [m..n]. You task is to find the number of integers divisible by either a or b in the given range.
Example 1:
Input:
m = 5, n = 11, a = 4, b = 6
Output:
2
Explanation:
6 and 8 lie in the range and are also
either divisible by 4 o... | ```python
class Solution:
def numOfDiv(self, m, n, a, b):
count1 = n // a - (m - 1) // a
count2 = n // b - (m - 1) // b
c = a * b
while a != b:
if a > b:
a -= b
else:
b -= a
c /= a
count3 = n // c - (m - 1) // c
return int(count1 + count2 - count3)
``` | vfc_135361 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/number-of-divisors-in-a-given-range3738/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "m = 5, n = 11, a = 4, b = 6",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "m = 1, n = 3, a = 2, b = 3",
"output": "2",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/PSTR2020/problems/ITGUY05 | Solve the following coding problem using the programming language python:
The chef is trying to solve some pattern problems, Chef wants your help to code it. Chef has one number K to form a new pattern. Help the chef to code this pattern problem.
-----Input:-----
- First-line will contain $T$, the number of test case... | ```python
for _ in range(int(input())):
n = int(input())
count = 1
l = 3 * (n - 1)
i = 0
if n == 1:
print(1)
continue
while count <= l - n:
for j in range(i + 1):
if j == i:
print(count)
count += 1
elif j == 0:
print(count, end='')
count += 1
else:
print(' ', end='')
i += 1
w... | vfc_135371 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/PSTR2020/problems/ITGUY05",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1\n2\n3\n4\n5\n",
"output": "1\n1\n23\n1\n23\n456\n1\n23\n4 5\n6789\n1\n23\n4 5\n6 7\n89101112\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/490/B | Solve the following coding problem using the programming language python:
During the lunch break all n Berland State University students lined up in the food court. However, it turned out that the food court, too, has a lunch break and it temporarily stopped working.
Standing in a queue that isn't being served is so ... | ```python
a = int(input())
d = {}
dinv = {}
for i in range(a):
b1 = input().split()
b = list(b1)
d[int(b[0])] = int(b[1])
dinv[int(b[1])] = int(b[0])
c1 = []
n = 0
for i in range(a):
n = d.get(n)
if n in d and n != 0:
c1 += [n]
else:
c1 += [n]
break
c2 = []
for i in d.keys():
if i not in dinv:
k = i
c... | vfc_135375 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/490/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n92 31\n0 7\n31 0\n7 141\n",
"output": "92 7 31 141 \n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/CTIME | Solve the following coding problem using the programming language python:
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef's college is conducting an online exam, where his camera will be monitored by one or more invigilators (supervisors). Once again, Chef failed to... | ```python
t = int(input())
for i in range(t):
(n, k, f) = map(int, input().split())
l = []
for j in range(n):
(a, b) = map(int, input().split())
l.append((a, b))
l.sort()
(a, b) = l[0]
if a > 0:
ans += a
else:
ans = 0
s = b
for x in range(1, n):
(a, b) = l[x]
if a >= s:
ans += a - s
if s < b:
... | vfc_135379 | {
"difficulty": "medium_hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/CTIME",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 10 10\n0 10\n2 2 10\n0 5\n7 10\n2 2 100\n0 5\n5 10",
"output": "NO\nYES\nYES",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Example
Input
3 2
1 2 1
2 3 2
1 10 100
Output
320
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import sys
readline = sys.stdin.readline
write = sys.stdout.write
sys.setrecursionlimit(10 ** 5)
def solve():
(N, M) = map(int, readline().split())
G = [[] for i in range(N)]
for i in range(N - 1):
(a, b, c) = map(int, readline().split())
G[a - 1].append((b - 1, c))
G[b - 1].append((a - 1, c))
(*C,... | vfc_135387 | {
"difficulty": "unknown_difficulty",
"memory_limit": "268.435456 megabytes",
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "5.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 2\n1 2 1\n2 3 2\n1 10 100",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 2\n1 2 0\n2 3 2\n1 10 100",
"output": "220\n",
"type": "stdin_stdout"
},
{
... | |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/modify-array-to-maximize-sum-of-adjacent-differences1729/1 | Solve the following coding problem using the programming language python:
Given an array arr of size N, the task is to modify values of this array in such a way that the sum of absolute differences between two consecutive elements is maximized. If the value of an array element is X, then we can change it to either 1 o... | ```python
class Solution:
def maximumDifferenceSum(self, arr, N):
dp = [[0] * 2 for i in range(N)]
for i in range(1, N):
dp[i][0] = max(dp[i - 1][0] + abs(arr[i] - arr[i - 1]), dp[i - 1][1] + abs(arr[i] - 1))
dp[i][1] = max(dp[i - 1][0] + abs(1 - arr[i - 1]), dp[i - 1][1])
return max(dp[-1])
``` | vfc_135391 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/modify-array-to-maximize-sum-of-adjacent-differences1729/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N = 4, arr[] = [3, 2, 1, 4, 5]",
"output": "8",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "N = 2, arr[] = {1, 5}",
"output": "4",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/652/C | Solve the following coding problem using the programming language python:
You are given a permutation p of length n. Also you are given m foe pairs (a_{i}, b_{i}) (1 ≤ a_{i}, b_{i} ≤ n, a_{i} ≠ b_{i}).
Your task is to count the number of different intervals (x, y) (1 ≤ x ≤ y ≤ n) that do not contain any foe pairs. S... | ```python
import sys
def FoePairs():
(n, m) = sys.stdin.readline().split()
n = int(n)
m = int(m)
s = n + 1
p = [0] * s
pos_p = [0] * s
closest_pos = [0] * s
i = 1
line = sys.stdin.readline().split()
while i < s:
t = int(line[i - 1])
p[i] = t
pos_p[t] = i
i += 1
for x in range(0, m):
(start, finish... | vfc_135392 | {
"difficulty": "medium_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/652/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 2\n1 3 2 4\n3 2\n2 4\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "9 5\n9 7 2 3 1 4 6 5 8\n1 6\n4 5\n2 7\n7 2\n2 7\n",
"output": "20\n",
"type": "stdin_std... |
taco | verifiable_code | https://www.codechef.com/problems/POGOSTCK | Solve the following coding problem using the programming language python:
Read problems statements [Mandarin] , [Bengali] , [Hindi] , [Russian] and [Vietnamese] as well.
Chef is participating in a pogo stick race. In this competition, there are $N$ squares (numbered $1$ through $N$) in a row. Chef must choose a start... | ```python
for t in range(int(input())):
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
for i in range(k, n):
a[i] = max(a[i], a[i] + a[i - k])
ans = -100000
for i in range(n - k, n):
ans = max(ans, a[i])
print(ans)
``` | vfc_135396 | {
"difficulty": "medium_hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/POGOSTCK",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n5 2\n3 6 4 7 2\n5 3\n3 -5 6 3 10",
"output": "13\n10",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1312/B | Solve the following coding problem using the programming language python:
You are given an array $a_1, a_2, \dots , a_n$. Array is good if for each pair of indexes $i < j$ the condition $j - a_j \ne i - a_i$ holds. Can you shuffle this array so that it becomes good? To shuffle an array means to reorder its elements ar... | ```python
I = lambda : list(map(int, input().split()))
for _ in range(int(input())):
I()
l = I()
print(' '.join(map(str, sorted(l, reverse=True))))
``` | vfc_135400 | {
"difficulty": "easy",
"memory_limit": "256 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1312/B",
"time_limit": "2 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1\n7\n4\n1 1 3 5\n6\n3 2 1 5 6 4\n",
"output": "7\n5 3 1 1\n6 5 4 3 2 1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n3\n4 2 1\n",
"output": "4 2 1\n",
"type": "stdin_s... |
taco | verifiable_code | Solve the following coding problem using the programming language python:
In a coordinate system,There are 3 chocolate which will be placed at three random position (x1,y1),(x2,y2) and (x3,y3).Ramesh loves Chocolates. Ramesh always moves along a straight line. your task is to find out whether he can have all the choco... | ```python
for _ in range(int(input())):
a,b,m,n,x,y = list(map(int,input().split()))
result1 = (n - b) * (x - m)
result2 = (y - n) * (m - a)
if result1 == result2:
print("YES")
else:
print("NO")
``` | vfc_135404 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10\n6 6 4 4 1 1\n7 8 8 5 1 2\n4 8 5 4 1 1\n4 5 5 6 6 7\n7 11 10 4 1 0\n4 12 12 4 1 3\n3 6 8 8 1 3\n3 4 8 6 1 2\n9 5 8 10 1 1\n10 12 14 16 2 4",
"output": "NO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO",
"type": "stdin_stdout"
... | |
taco | verifiable_code | https://codeforces.com/problemset/problem/492/D | Solve the following coding problem using the programming language python:
Vanya and his friend Vova play a computer game where they need to destroy n monsters to pass a level. Vanya's character performs attack with frequency x hits per second and Vova's character performs attack with frequency y hits per second. Each ... | ```python
(n, x, y) = list(map(int, input().split()))
(cx, cy, A) = (0, 0, [])
while cx < x or cy < y:
if (cx + 1) * y > (cy + 1) * x:
cy += 1
A.append('Vova')
elif (cx + 1) * y < (cy + 1) * x:
cx += 1
A.append('Vanya')
else:
A.append('Both')
A.append('Both')
cx += 1
cy += 1
for _ in range(n):
a = i... | vfc_135412 | {
"difficulty": "medium_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/492/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 3 2\n1\n2\n3\n4\n",
"output": "Vanya\nVova\nVanya\nBoth\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1264/F | Solve the following coding problem using the programming language python:
The well-known Fibonacci sequence $F_0, F_1, F_2,\ldots $ is defined as follows: $F_0 = 0, F_1 = 1$. For each $i \geq 2$: $F_i = F_{i - 1} + F_{i - 2}$.
Given an increasing arithmetic sequence of positive integers with $n$ elements: $(a, a ... | ```python
c = 9224175735 * 10 ** 8
m = 15 * 10 ** 17
(n, a, d) = map(int, input().split())
print(c * a % m + 1, c * d % m)
``` | vfc_135416 | {
"difficulty": "very_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1264/F",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 1 1\n",
"output": "4417573500000000001 4417573500000000000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 1 2\n",
"output": "4417573500000000001 8835147000000000000\n",
"t... |
taco | verifiable_code | https://www.codechef.com/problems/CRICUP | Solve the following coding problem using the programming language python:
It is the World Cup Finals. Chef only finds a match interesting if the skill difference of the competing teams is *less than or equal to* D.
Given that the skills of the teams competing in the final are X and Y respectively, determine whether C... | ```python
t = int(input())
while t > 0:
[x, y, d] = map(int, input().split())
if abs(x - y) <= d:
print('YES')
else:
print('NO')
t -= 1
``` | vfc_135420 | {
"difficulty": "easy",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/CRICUP",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n5 3 4\n5 3 1\n5 5 0\n",
"output": "YES\nNO\nYES\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1320/D | Solve the following coding problem using the programming language python:
In this problem, we will deal with binary strings. Each character of a binary string is either a 0 or a 1. We will also deal with substrings; recall that a substring is a contiguous subsequence of a string. We denote the substring of string $s$ ... | ```python
import sys
input = sys.stdin.readline
MOD = 987654103
n = int(input())
t = input()
place = []
f1 = []
e1 = []
s = []
curr = 0
count1 = 0
for i in range(n):
c = t[i]
if c == '0':
if count1:
e1.append(i - 1)
if count1 & 1:
s.append(1)
curr += 1
e1.append(-1)
f1.append(-1)
count1 = 0... | vfc_135424 | {
"difficulty": "hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1320/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n11011\n3\n1 3 3\n1 4 2\n1 2 3\n",
"output": "Yes\nYes\nNo\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n0\n1\n1 1 1\n",
"output": "Yes\n",
"type": "stdin_stdout"
},... |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/number-of-diagonals1020/1 | Solve the following coding problem using the programming language python:
Given a number N, the task is to find the number of diagonals in N sided convex polygon.
Example 1:
Input: N = 5
Output: 5
Example 2:
Input: N = 6
Output: 9
Your Task:
You don't need to read input or print anything. Your task is to complete th... | ```python
class Solution:
def diagonals(self, n):
return int(n * (n - 3) // 2)
``` | vfc_135432 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/number-of-diagonals1020/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N = 5",
"output": "5",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/POPU2021/problems/EASYABC | Solve the following coding problem using the programming language python:
Alisha has a string of length n. Each character is either 'a', 'b' or 'c'. She has to select two characters s[i] and s[j] such that s[i] != s[j] and i,j are valid indexes. She has to find the maximum value of the absolute difference between i an... | ```python
st = input().strip()
b = []
for i in range(len(st)):
for j in range(i + 1, len(st)):
if st[i] != st[j]:
z = abs(i - j)
b.append(z)
print(max(b))
``` | vfc_135433 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/POPU2021/problems/EASYABC",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "aabcaaa\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "aba\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/PPLUCKY | Solve the following coding problem using the programming language python:
Read problems statements in Russian here
Polo, the Penguin, likes lucky strings - the strings that consist only of lucky digits 4 and 7.
He has a lucky string S. Digits in this string are numbered from left to right starting with 1. He performs... | ```python
import sys
class LuckyStars:
bit = []
n = 0
def update(self, i, v):
global bit
global n
i += 1
while i <= n:
bit[i] += 1
i += i & -i
def query(self, i):
global bit
global n
r = 0
i += 1
while i:
r += bit[i]
i -= i & -i
return r
def solve(self, ls):
global bit
globa... | vfc_135437 | {
"difficulty": "very_hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/PPLUCKY",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": " 2\n 4\n 4747\n 10\n 4447477747\n ",
"output": " 4\n 20",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/1s-complement2819/1 | Solve the following coding problem using the programming language python:
Given an N bit binary number, find the 1's complement of the number. The ones' complement of a binary number is defined as the value obtained by inverting all the bits in the binary representation of the number (swapping 0s for 1s and vice versa... | ```python
class Solution:
def onesComplement(self, S, N):
i = 0
res = ''
for ec in S:
if ec == '0':
res = res + '1'
else:
res = res + '0'
l1 = len(res)
l2 = N
if l2 != l1:
diff = l2 - l1
for i in range(diff):
res = res + '0'
return res
``` | vfc_135442 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/1s-complement2819/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N = 3\nS = 101",
"output": "010",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "N = 2\nS = 10",
"output": "01",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/219/C | Solve the following coding problem using the programming language python:
A colored stripe is represented by a horizontal row of n square cells, each cell is pained one of k colors. Your task is to repaint the minimum number of cells so that no two neighbouring cells are of the same color. You can use any color from 1... | ```python
(n, k) = map(int, input().split())
s = input()
if k == 2:
sol1 = [s[i] for i in range(n)]
ans1 = 0
for i in range(n):
if i % 2 == 0 and sol1[i] == 'B':
ans1 += 1
sol1[i] = 'A'
elif i % 2 != 0 and sol1[i] == 'A':
ans1 += 1
sol1[i] = 'B'
sol2 = [s[i] for i in range(n)]
ans2 = 0
for i in ra... | vfc_135443 | {
"difficulty": "medium_hard",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/219/C",
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6 2\nAABABA\n",
"output": "1\nBABABA",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 2\nBBA\n",
"output": "1\nABA",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
taco | verifiable_code | https://www.codechef.com/problems/SLAEL | Solve the following coding problem using the programming language python:
Find the length of the longest contiguous segment in an array, in which if a given element $K$ is inserted, $K$ becomes the second largest element of that subarray.
-----Input:-----
- The first line will contain $T$, number of test cases. Then ... | ```python
import sys
from sys import stdin, stdout
t = int(stdin.readline())
for _ in range(t):
(n, k) = map(int, stdin.readline().strip().split(' '))
arr = list(map(int, stdin.readline().strip().split(' ')))
tarr = []
p = -1
for i in range(len(arr)):
if arr[i] > k:
if p == -1:
p = arr[i]
tarr.append(... | vfc_135447 | {
"difficulty": "hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/SLAEL",
"time_limit": "2 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n5 3\n2 4 2 4 2\n8 5\n9 3 5 7 8 11 17 2\n",
"output": "5\n3\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/tidy-number0519/1 | Solve the following coding problem using the programming language python:
Given a number N.Check if it is tidy or not.
A tidy number is a number whose digits are in non-decreasing order.
Example 1:
Input:
1234
Output:
1
Explanation:
Since 1<2<3<4,therefore the number is tidy.
Example 2:
Input:
1243
Output:
0
Explana... | ```python
class Solution:
def isTidy(self, N):
a = str(N)
n = sorted(str(N))
l1 = list(a)
l2 = list(n)
if l1 == l2:
return 1
else:
return 0
``` | vfc_135453 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/tidy-number0519/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1234",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1243",
"output": "0",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.hackerrank.com/challenges/hard-homework/problem | Solve the following coding problem using the programming language python:
Aaron is struggling with trigonometric functions, so his teacher gave him extra homework. Given an integer, $n$, he must answer the following question:
What is the maximum value of $sin(x)+sin(y)+sin(z)$, where $x}$, $y$, and $z$ are positive i... | ```python
from math import sin, pi
from itertools import product
from random import shuffle
n = int(input())
a = list(range(1, n - 1))
a.sort(key=lambda v: v % (pi * 2))
lena = len(a)
offsets = list(product(range(-500, 501), range(-500, 501)))
shuffle(offsets)
last_offset = offsets[len(offsets) - 1]
i = 0
j = lena // 2... | vfc_135454 | {
"difficulty": "hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.hackerrank.com/challenges/hard-homework/problem",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n",
"output": "2.524412954\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/design-twitter/1 | Solve the following coding problem using the programming language python:
Design a simplified version of Twitter where users can post tweets, follow/unfollow another user and is able to see the 10 most recent tweets in the user's news feed. Your design should support the following methods:
postTweet (userId, tweetId)... | ```python
from collections import defaultdict
import heapq
class Twitter:
def __init__(self):
self.count = 0
self.tweetMap = defaultdict(list)
self.followMap = defaultdict(set)
def postTweet(self, userId: int, tweetId: int):
self.tweetMap[userId].append([self.count, tweetId])
self.count -= 1
def getNew... | vfc_135458 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/design-twitter/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "postTweet(1, 5);\r\ngetNewsFeed(1);\r\nfollow(1, 2);\r\npostTweet(2, 6);\r\ngetNewsFeed(1);\r\nunfollow(1, 2);\r\ngetNewsFeed(1);",
"output": "[5]\r\n[6, 5]\r\n[5]",
"type": "stdin_stdout"
},
{
"fn_name": ... |
taco | verifiable_code | https://codeforces.com/problemset/problem/224/D | Solve the following coding problem using the programming language python:
A subsequence of length |x| of string s = s1s2... s|s| (where |s| is the length of string s) is a string x = sk1sk2... sk|x| (1 ≤ k1 < k2 < ... < k|x| ≤ |s|).
You've got two strings — s and t. Let's consider all subsequences of string s, coinci... | ```python
import bisect
import string
s = input()
t = input()
max_match = [0 for i in range(len(s))]
min_match = [0 for i in range(len(s))]
char_idx = [0 for i in range(30)]
char_occur = [[] for i in range(30)]
for (i, ch) in enumerate(t):
idx = ord(ch) - ord('a')
char_occur[idx].append(i)
for ch in string.ascii_lowe... | vfc_135460 | {
"difficulty": "hard",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/224/D",
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "babaabaabb\nbbccb\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "aaaaaa\naaaaaaa\n",
"output": "No\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/192/C | Solve the following coding problem using the programming language python:
The ancient Berlanders believed that the longer the name, the more important its bearer is. Thus, Berland kings were famous for their long names. But long names are somewhat inconvenient, so the Berlanders started to abbreviate the names of thei... | ```python
import sys
import math
from heapq import *
input = sys.stdin.readline
from functools import cmp_to_key
def pi():
return int(input())
def pl():
return int(input(), 16)
def ti():
return list(map(int, input().split()))
def ts():
s = input()
return list(s[:len(s) - 1])
def invr():
return map(int, input... | vfc_135468 | {
"difficulty": "medium",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/192/C",
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\nab\nbc\ncd\nde\nffffffffff\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "50\nagecd\ncghafi\nfiide\niecc\njbdcfjhgd\ndiee\nhfeg\nehc\ngfijgjh\ngacaifebg\ndicbbddc\nhj... |
taco | verifiable_code | https://codeforces.com/problemset/problem/82/D | Solve the following coding problem using the programming language python:
Vasya has recently developed a new algorithm to optimize the reception of customer flow and he considered the following problem.
Let the queue to the cashier contain n people, at that each of them is characterized by a positive integer ai — tha... | ```python
def do():
n = int(input())
costs = [int(c) for c in input().split(' ')]
next = {}
memo = {}
def dp(i, pre):
if i == n:
memo[i, pre] = [costs[pre], [pre]]
return memo[i, pre]
if i == n - 1:
memo[i, pre] = [max(costs[pre], costs[i]), [pre, i]]
return memo[i, pre]
if (i, pre) not in memo:... | vfc_135472 | {
"difficulty": "hard",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/82/D",
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "55\n33 64 51 38 37 44 63 89 60 90 33 67 82 81 40 41 58 86 47 78 60 86 81 43 57 89 39 72 59 88 47 41 59 79 35 41 67 57 70 55 90 46 37 64 78 55 82 88 81 60 46 75 34 79 51\n",
"output": "1814\n2 3\n1 5\n4 6\n7 9\n8 10\n11 12\n13... |
taco | verifiable_code | Solve the following coding problem using the programming language python:
D: Many Decimal Integers
problem
Given a string S consisting only of numbers (0-9) and a string T consisting only of numbers and `?`. S and T are the same length.
Consider changing each `?` That exists in T to one of the numbers from 0 to 9 t... | ```python
from collections import defaultdict, deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI():
return [int(x) for x in sys.stdin.readline().split()]
def I():
return int(sys.stdin.readline())
def LS():
return [list(x) for x in sys.stdin.readline().split()]
de... | vfc_135476 | {
"difficulty": "unknown_difficulty",
"memory_limit": "268.435456 megabytes",
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "1.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "73\n?6",
"output": "252\n",
"type": "stdin_stdout"
}
]
} | |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/remove-duplicates-in-small-prime-array/1 | Solve the following coding problem using the programming language python:
Given an array consisting of only prime numbers, remove all duplicate numbers from it.
Example 1:
Input:
N = 6
A[] = {2,2,3,3,7,5}
Output: 2 3 7 5
Explanation: After removing the duplicate
2 and 3 we get 2 3 7 5.
Your Task:
Complete the functio... | ```python
class Solution:
def removeDuplicates(self, arr):
ans = []
s = set()
for ele in arr:
if ele not in s:
ans.append(ele)
s.add(ele)
return ans
``` | vfc_135480 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/remove-duplicates-in-small-prime-array/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N = 6\nA[] = {2,2,3,3,7,5}",
"output": "2 3 7 5",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.hackerrank.com/challenges/connecting-towns/problem | Solve the following coding problem using the programming language python:
Cities on a map are connected by a number of roads. The number of roads between each city is in an array and city ${0}$ is the starting location. The number of roads from city ${0}$ to city ${1}$ is the first value in the array, from city ${1}... | ```python
t = int(input())
for i in range(t):
n = int(input())
p = 1
r = input().split(' ')
for i in range(n - 1):
p = p * int(r[i])
p = p % 1234567
print(p)
``` | vfc_135481 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.hackerrank.com/challenges/connecting-towns/problem",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n3\n1 3\n4\n2 2 2\n",
"output": "3\n8\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/279/D | Solve the following coding problem using the programming language python:
You've got a positive integer sequence a_1, a_2, ..., a_{n}. All numbers in the sequence are distinct. Let's fix the set of variables b_1, b_2, ..., b_{m}. Initially each variable b_{i} (1 ≤ i ≤ m) contains the value of zero. Consider the follow... | ```python
def Solve(x, B):
if (X, x, B) in Mem:
return Mem[X, x, B]
if len(B) > X:
return False
if x == len(L):
return True
if Form(L[x], B):
A = list(B)
for e in range(len(B)):
r = A[e]
A[e] = L[x]
if Solve(x + 1, tuple(sorted(A))):
Mem[X, x, B] = True
return True
A[e] = r
A += [L[x... | vfc_135485 | {
"difficulty": "hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/279/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1 2 3 6 8\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n3 6 5\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"i... |
taco | verifiable_code | https://www.codechef.com/problems/RPD | Solve the following coding problem using the programming language python:
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef is attending math classes. On each day, the teacher gives him homework. Yesterday, the teacher gave Chef a sequence of positive integer... | ```python
def digsum(s):
count = 0
for d in s:
count += int(d)
return count
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
max = 0
for i in range(n - 1):
for j in range(i + 1, n):
test = digsum(str(a[i] * a[j]))
if max < test:
max = test
print(max)
``` | vfc_135489 | {
"difficulty": "easy",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/RPD",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n2\n2 8\n3 \n8 2 8\n3\n9 10 11",
"output": "7\n10\n18",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
The surveyor starship Hakodate-maru is famous for her two fuel containers with unbounded capacities. They hold the same type of atomic fuel balls.
There, however, is an inconvenience. The shapes of the fuel containers #1 and #2 are always cubic... | ```python
ans = []
while True:
N = int(input())
if not N:
break
now_cube = int(N ** (1 / 3 + 1e-06))
now_pyramid = 0
tmp_ans = now_cube ** 3
for i in range(now_cube, -1, -1):
while True:
if (now_pyramid + 1) * (now_pyramid + 2) * (now_pyramid + 3) // 6 + i ** 3 > N:
tmp_ans = max(tmp_ans, now_pyramid *... | vfc_135503 | {
"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": "100\n84\n50\n20\n151200\n0",
"output": "99\n84\n47\n20\n151200\n",
"type": "stdin_stdout"
}
]
} | |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/word-ladder-ii/1 | Solve the following coding problem using the programming language python:
Given two distinct words startWord and targetWord, and a list denoting wordList of unique words of equal lengths. Find all shortest transformation sequence(s) from startWord to targetWord. You can return them in any order possible.
Keep the fol... | ```python
from collections import deque
class Solution:
def findSequences(self, startWord, targetWord, wordList):
st = set(wordList)
queue = deque()
queue.append([startWord])
ans = []
usedonLevel = [startWord]
level = 0
while queue:
vec = queue.popleft()
if len(vec) > level:
level += 1
fo... | vfc_135507 | {
"difficulty": "medium_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/word-ladder-ii/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "startWord = \"der\", targetWord = \"dfs\",\r\nwordList = {\"des\",\"der\",\"dfr\",\"dgt\",\"dfs\"}",
"output": "der dfr dfs\r\nder des dfs",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "sta... |
taco | verifiable_code | https://www.codechef.com/problems/NFS | Solve the following coding problem using the programming language python:
Read problem statements in [Russian] and [Mandarin Chinese]
Chef is playing Need For Speed. Currently, his car is running on a straight road with a velocity $U$ metres per second and approaching a $90^{\circ}$ turn which is $S$ metres away from... | ```python
t = int(input())
for i in range(t):
(u, v, a, s) = map(int, input().split())
smallv = u ** 2 - 2 * a * s
if smallv > v ** 2:
print('No')
else:
print('Yes')
``` | vfc_135508 | {
"difficulty": "easy",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/NFS",
"time_limit": "0.5 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 1 1 1\n2 1 1 1\n2 2 1 1",
"output": "Yes\nNo\nYes",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/sum-of-divisors3601/1 | Solve the following coding problem using the programming language python:
Given a natural number n, calculate sum of all its proper divisors. A proper divisor of a natural number is the divisor that is strictly less than the number.
Example 1:
Input: n = 10
Output: 8
Explanation: Proper divisors 1 + 2 + 5 = 8.
Examp... | ```python
import math
class Solution:
def divSum(self, n):
s = 1
a = int(math.sqrt(n))
for i in range(2, a + 1):
if n % i == 0:
if i * i == n:
s = s + i
else:
b = n // i
s = s + i + b
return s
``` | vfc_135512 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/sum-of-divisors3601/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "n = 10",
"output": "8",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "n = 6",
"output": "6",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Puchi hates to carry luggage, but unfortunately he got a job to carry the luggage of his N friends in office. Each day, one of his N friends, gives him the luggage of a particular weight to carry. You will be given the weight of luggage of each... | ```python
def merge_sort_count(xss):
if len(xss) == 1:
return xss
mid = len(xss) / 2
xs = merge_sort_count(xss[:mid])
ys = merge_sort_count(xss[mid:])
res = []
i, j, count = 0, 0, 0
while True:
if i >= len(xs):
res.extend(ys[j:])
break
if j >= len(ys) or xs[i] < ys[j]:
res.append((xs[i][0], xs[i][... | vfc_135513 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7\n1\n20\n6\n1\n2\n3\n4\n5\n6\n4\n87\n78\n16\n94\n16\n87\n93\n50\n22\n63\n28\n91\n60\n64\n27\n41\n73\n37\n12\n69\n68\n10\n83\n31\n63\n24\n68\n36\n30\n3\n23\n59\n10\n68\n94\n57\n12\n43\n30\n74\n22\n20\n85\n10\n100\n99\n98\n97\n96\n9... | |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/count-subsets-having-distinct-even-numbers5726/1 | Solve the following coding problem using the programming language python:
Given a set of n numbers. The task is to count all the subsets of the given set which only have even numbers and all are distinct.
Note: By the property of sets, if two subsets have the same set of elements then they are considered as one. For e... | ```python
def countSubsets(a, n):
s = set()
for x in a:
if x % 2 == 0:
s.add(x)
count = len(s)
ans = pow(2, count) - 1
return ans
``` | vfc_135517 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/count-subsets-having-distinct-even-numbers5726/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": "countSubsets",
"input": "n = 8\r\na[] = {4, 2, 1, 9, 2, 6, 5, 3}",
"output": "7",
"type": "function_call"
},
{
"fn_name": "countSubsets",
"input": "n = 13\r\na[] = {10, 3, 4, 2, 4, 20, 10, 6, 8, 14, 2, 6, 9}",
... |
taco | verifiable_code | https://www.codechef.com/problems/VOTERS | Solve the following coding problem using the programming language python:
As you might remember, the collector of Siruseri had ordered
a complete revision of the Voters List. He knew that constructing
the list of voters is a difficult task, prone to errors. Some
voters may have been away on vacation, others may have m... | ```python
(n1, n2, n3) = map(int, input().split())
myDict = {}
outputSet = set()
count = 0
for i in range(n1 + n2 + n3):
num = int(input())
if num in myDict:
myDict[num] += 1
if myDict[num] > 1:
outputSet.add(num)
count += 1
else:
myDict[num] = 1
print(len(outputSet))
for i in sorted(outputSet):
print(i... | vfc_135520 | {
"difficulty": "easy",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/VOTERS",
"time_limit": "1.15243 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 6 5\n23\n30\n42\n57\n90\n21 \n23 \n35 \n57 \n90 \n92 \n21 \n23 \n30 \n57 \n90 ",
"output": "5\n21 \n23 \n30 \n57 \n90",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
When the day begins, it's time to sing carols. Unfortunately, not all the family members know the lyrics to the same carols. Everybody knows at least one, though.
You are given a array of lyrics. The j-th character of the i-th element of lyrics ... | ```python
def get_rem(p,ar):
n=[]
for i in ar:
if i[p]=='N':
n.append(i)
return n
t=eval(input())
for i in range(t):
n=eval(input())
st=input().split()
ar=[]
for k in range(len(st[0])):
p=k
i=0
c=1
rem=st
while(i<n):
rem=get_rem(p%len(st[0]),rem)
i=n-len(rem)
if len(rem)>0:
p+=1
c... | vfc_135524 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n6\nNYN YYN YYN YNY YNY NNY\n3\nYNNY NYNY NNYY\n5\nYYN YYN YNY NYN NNY",
"output": "2\n1\n2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n7\nYYN NYY YNY YNY YNY NNY YNN\n1\nYYYYYYYYYY... | |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Heading ##There are two integers A and B. You are required to compute the bitwise AND amongst all natural numbers lying between A and B, both inclusive.
Input Format
First line of the input contains T, the number of testcases to follow.
Each te... | ```python
import sys
t = int(eval(input()))
while(t>0):
k,n = list(map(int,sys.stdin.readline().split()))
while(n>k):
n=n&(n-1)
print((k&n))
t-=1
``` | vfc_135528 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 \n12 15 \n2 3 \n8 13",
"output": "1476395008\n1275068416\n4009754624\n2516582400\n50331648\n2566914048\n2952790016\n3892314112\n3489660928\n33554432\n1694498816\n3623878656\n1308622848\n1426063360\n2550136832\n1627389952\n3... | |
taco | verifiable_code | https://www.codechef.com/problems/SUB_XOR | Solve the following coding problem using the programming language python:
Mary loves binary strings.
Given a binary string S, she defines the *beauty* of the string as the [bitwise XOR] of decimal representations of all substrings of S.
Find the *beauty* of string S. Since the answer can be huge, print it modulo 99... | ```python
mod = 998244353
def inp():
return int(input())
def st():
return input().rstrip('\n')
def lis():
return list(map(int, input().split()))
def ma():
return map(int, input().split())
def solve(lent, binn):
runningxor = 0
beauty = 0
twopow = 1
for j in range(lent):
if not j & 1:
runningxor ^= int(... | vfc_135540 | {
"difficulty": "medium_hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/SUB_XOR",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n2\n10\n3\n101\n4\n1111",
"output": "3\n6\n12\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/220/A | Solve the following coding problem using the programming language python:
The Little Elephant has got a problem — somebody has been touching his sorted by non-decreasing array a of length n and possibly swapped some elements of the array.
The Little Elephant doesn't want to call the police until he understands if he ... | ```python
def main():
n = int(input())
arr = list(map(int, input().split()))
copy = arr[:]
copy.sort()
missed = 0
for i in range(n):
if arr[i] != copy[i]:
missed += 1
if missed == 2:
print('YES')
elif missed == 0:
print('YES')
else:
print('NO')
main()
``` | vfc_135544 | {
"difficulty": "easy",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/220/A",
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1 4 3 2 1\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n3 4 5 6 7 2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Gudi enters the castle, and moves along the main path. Suddenly, a block in the ground opens and she falls into it! Gudi slides down and lands in a dark room. A mysterious voice announces:
Intruders are not allowed inside the castle. To proce... | ```python
T=int(input())
for iCase in range(T):
S=input()
lenS=len(S)
A,H=list(map(int, input().split()))
H%=lenS
allstr=set([])
news=[S]
while news:
old=news
news=[]
for st in old:
S1=st[-H:]+st[:-H]
if S1 not in allstr:
allstr.add(S1)
news.append(S1)
S2=st[0]
for i in range(1,lenS,2)... | vfc_135548 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10\n85\n10 1\n25621\n3 4\n19688\n1 5\n34597\n4 5\n6502\n5 1\n475\n10 2\n108\n1 3\n68\n6 1\n07\n6 2\n091\n1 1",
"output": "213\n331\n40\n00001\n009171\n01644\n53\n824\n107\n30",
"type": "stdin_stdout"
},
{
... | |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/roof-top-1587115621/1 | Solve the following coding problem using the programming language python:
You are given heights of consecutive buildings. You can move from the roof of a building to the roof of next adjacent building. You need to find the maximum number of consecutive steps you can put forward such that you gain an increase in altitu... | ```python
class Solution:
def maxStep(self, A, N):
i = 1
c = 0
max1 = 0
while i < N:
if A[i] - A[i - 1] > 0:
c += 1
else:
max1 = max(max1, c)
c = 0
i += 1
return max(max1, c)
``` | vfc_135552 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/roof-top-1587115621/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N = 5\r\nA[] = {1,2,2,3,2}",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "N = 4\r\nA[] = {1,2,3,4}",
"output": "3",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1561/D2 | Solve the following coding problem using the programming language python:
Note that the memory limit in this problem is lower than in others.
You have a vertical strip with n cells, numbered consecutively from 1 to n from top to bottom.
You also have a token that is initially placed in cell n. You will move the toke... | ```python
(n, m) = map(int, input().split())
c = [0] * n + [1] + [0] * n
for i in range(n - 1, 0, -1):
c[i] = 2 * c[i + 1] % m
for j in range(2, n // i + 1):
c[i] = (c[i] + c[i * j] - c[(i + 1) * j]) % m
print((c[1] - c[2]) % m)
``` | vfc_135553 | {
"difficulty": "hard",
"memory_limit": "128.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1561/D2",
"time_limit": "6.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 872207251\n",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "182550 383331199\n",
"output": "234598461",
"type": "stdin_stdout"
},
{
"fn_name": null... |
taco | verifiable_code | https://codeforces.com/problemset/problem/121/B | Solve the following coding problem using the programming language python:
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya has a number consis... | ```python
import sys
input = sys.stdin.readline
from math import *
(n, m) = map(int, input().split())
s = list(input().rstrip())
for i in range(n - 1):
if m == 0:
break
if i > 0:
if s[i - 1] == '4' and s[i] == '4' and (s[i + 1] == '7') and (i % 2 == 1):
if m % 2 == 1:
s[i] = '7'
break
if s[i] == '4' an... | vfc_135557 | {
"difficulty": "medium",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/121/B",
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "74 7\n47437850490316923506619313479471062875964157742919669484484624083960118773\n",
"output": "44437850490316923506619313449771062875964157742919669484484624083960118773\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1385/B | Solve the following coding problem using the programming language python:
A permutation of length $n$ is a sequence of integers from $1$ to $n$ of length $n$ containing each number exactly once. For example, $[1]$, $[4, 3, 5, 1, 2]$, $[3, 2, 1]$ are permutations, and $[1, 1]$, $[0, 1]$, $[2, 2, 1, 4]$ are not.
There ... | ```python
for i in range(int(input())):
x = {}
n = int(input())
l = list(map(int, input().split()))
for i in range(2 * n):
if l[i] in x:
continue
x[l[i]] = 1
for i in x.keys():
print(i, end=' ')
``` | vfc_135561 | {
"difficulty": "easy",
"memory_limit": "256 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1385/B",
"time_limit": "1 second"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n2\n1 1 2 2\n4\n1 3 1 4 3 4 2 2\n5\n1 2 1 2 3 4 3 5 4 5\n3\n1 2 3 1 2 3\n4\n2 3 2 4 1 3 4 1\n",
"output": "1 2 \n1 3 4 2 \n1 2 3 4 5 \n1 2 3 \n2 3 4 1 \n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.hackerrank.com/challenges/baby-step-giant-step/problem | Solve the following coding problem using the programming language python:
You are standing at point $(0,0)$ on an infinite plane. In one step, you can move from some point $(x_f,y_f)$ to any point $(x_t,y_t)$ as long as the Euclidean distance, $\sqrt{(x_f-x_t)^2+(y_f-y_t)^2}$, between the two points is either $\boldsy... | ```python
from math import ceil
def steps(a, b, d):
mmin = min(a, b)
mmax = max(a, b)
if d is 0:
return 0
if d in {mmin, mmax}:
return 1
if d < mmax:
return 2
return ceil(d / mmax)
t = int(input())
for testcase in range(t):
(a, b, d) = map(int, input().split())
print(steps(a, b, d))
``` | vfc_135565 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.hackerrank.com/challenges/baby-step-giant-step/problem",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n2 3 1\n1 2 0\n3 4 11\n",
"output": "2\n0\n3\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Draw a chessboard which has a height of H cm and a width of W cm. For example, the following figure shows a chessboard which has a height of 6 cm and a width of 10 cm.
.#.#.#.#.
.#.#.#.#.#
.#.#.#.#.
.#.#.#.#.#
.#.#.#.#.
.#.#.#.#.#
Note that ... | ```python
while True:
(a, b) = map(int, input().split())
if a == b == 0:
break
for i in range(a):
s = ''
for j in range(b):
s += '#' if (i + j) % 2 == 0 else '.'
print(s)
print('')
``` | vfc_135569 | {
"difficulty": "unknown_difficulty",
"memory_limit": "134.217728 megabytes",
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "1.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 4\n5 6\n3 3\n2 2\n1 0\n0 0",
"output": "#.#.\n.#.#\n#.#.\n\n#.#.#.\n.#.#.#\n#.#.#.\n.#.#.#\n#.#.#.\n\n#.#\n.#.\n#.#\n\n#.\n.#\n\n\n\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 7\n5... | |
taco | verifiable_code | https://www.codechef.com/LOCJUL16/problems/NUMHOLMS | Solve the following coding problem using the programming language python:
After completing some serious investigation, Watson and Holmes are now chilling themselves in the Shimla hills. Very soon Holmes became bored. Holmes lived entirely for his profession. We know he is a workaholic. So Holmes wants to stop his vaca... | ```python
t = int(input())
for i in range(0, t):
n = int(input())
lis = list(map(int, input().split()))
lis2 = []
for j in range(0, 10):
lis2.append(0)
for j in range(0, len(lis)):
lis2[lis[j]] += 1
s = sum(lis)
while s % 3 != 0:
if s % 3 == 2:
if lis2[2] >= 1:
lis2[2] -= 1
s = s - 2
elif lis... | vfc_135573 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/LOCJUL16/problems/NUMHOLMS",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n12\n3 1 2 3 2 0 2 2 2 0 2 3\n11\n3 9 9 6 4 3 6 4 9 6 0\n",
"output": "33322222200\n999666330\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/SQUIRREL | Solve the following coding problem using the programming language python:
There are n squirrel(s) waiting below the feet of m chestnut tree(s). The first chestnut of the i-th tree will fall right after T_{i} second(s), and one more every P_{i} second(s) after that. The “big mama” of squirrels wants them to bring their... | ```python
for _ in range(int(input())):
(m, n, k) = map(int, input().split())
T = list(map(int, input().split()))
P = list(map(int, input().split()))
t_min = 0
t_max = 10000000
t_ans = 0
while t_min <= t_max:
t_mid = (t_min + t_max) // 2
fa = [(t_mid - T[i]) // P[i] + 1 for i in range(m) if t_mid >= T[i]]
... | vfc_135581 | {
"difficulty": "medium_hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/SQUIRREL",
"time_limit": "0.169935 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n3 2 5\n5 1 2\n1 2 1\n3 2 5\n5 1 2\n1 1 1",
"output": "4\n3",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/201/D | Solve the following coding problem using the programming language python:
A widely known among some people Belarusian sport programmer Lesha decided to make some money to buy a one square meter larger flat. To do this, he wants to make and carry out a Super Rated Match (SRM) on the site Torcoder.com. But there's a pro... | ```python
import itertools
def count_inversions(enumerate_seq):
tmp = list(enumerate_seq[:])
result = 0
for i in range(len(tmp)):
for j in range(len(tmp) - 1):
if tmp[j][0] > tmp[j + 1][0]:
result += 1
(tmp[j], tmp[j + 1]) = (tmp[j + 1], tmp[j])
return result
def sub_seq(a, b):
(i, j) = (0, 0)
whil... | vfc_135585 | {
"difficulty": "very_hard",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/201/D",
"time_limit": "5.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\na b c d e\n10\n5 a d b c e\n5 e a b c d\n5 b a c e d\n5 b e d c a\n5 a e d c b\n5 b c e a d\n5 d b c a e\n5 a e c d b\n5 e d b a c\n5 e d a b c\n",
"output": "1\n[:|||||||||:]\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/435/A | Solve the following coding problem using the programming language python:
It's that time of the year when the Russians flood their countryside summer cottages (dachas) and the bus stop has a lot of people. People rarely go to the dacha on their own, it's usually a group, so the people stand in queue by groups.
The bu... | ```python
(n, m) = map(int, input().split())
d = list(map(int, input().split()))
counter = 1
sum = 0
for i in range(n):
sum += d[i]
if sum > m:
sum = d[i]
counter += 1
print(counter)
``` | vfc_135589 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/435/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 3\n2 3 2 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 4\n1 2 1\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/rod-cutting0840/1 | Solve the following coding problem using the programming language python:
Given a rod of length N inches and an array of prices, price[]. price[i] denotes the value of a piece of length i. Determine the maximum value obtainable by cutting up the rod and selling the pieces.
Note: Consider 1-based indexing.
Example 1:
I... | ```python
import sys
class Solution:
def cutRod(self, price, n):
N = n
cur = [0] * (N + 1)
for i in range(N + 1):
cur[i] = i * price[0]
for ind in range(1, N):
for length in range(N + 1):
notTaken = 0 + cur[length]
taken = float('-inf')
rodLength = ind + 1
if rodLength <= length:
t... | vfc_135593 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/rod-cutting0840/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N = 8\r\nPrice[] = {1, 5, 8, 9, 10, 17, 17, 20}",
"output": "22",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1612/C | Solve the following coding problem using the programming language python:
You are a usual chat user on the most famous streaming platform. Of course, there are some moments when you just want to chill and spam something.
More precisely, you want to spam the emote triangle of size $k$. It consists of $2k-1$ messages. ... | ```python
import sys
input = lambda : sys.stdin.readline().rstrip()
for _ in range(int(input())):
(K, X) = map(int, input().split())
a = K * (K + 1) // 2
if X <= a:
b = int((2 * X) ** 0.5)
ans = b
if b * (b + 1) < X * 2:
ans += 1
print(ans)
elif X >= a + a - K:
print(K + K - 1)
else:
X = a + a - K -... | vfc_135594 | {
"difficulty": "easy",
"memory_limit": "512 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1612/C",
"time_limit": "2 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7\n4 6\n4 7\n1 2\n3 7\n2 5\n100 1\n1000000000 923456789987654321\n",
"output": "3\n4\n1\n4\n3\n1\n1608737403\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/RETPO | Solve the following coding problem using the programming language python:
Read problems statements in Mandarin Chinese and Russian.
Recently Chef bought a bunch of robot-waiters. And now he needs to know how much to pay for the electricity that robots use for their work. All waiters serve food from the kitchen (whi... | ```python
t = int(input())
while t > 0:
(x, y) = input().split()
x = int(x)
y = int(y)
x = abs(x)
y = abs(y)
z = min(x, y)
x = x - z
y = y - z
if x == 0:
if y % 2 != 0:
res = 2 * y - 1
else:
res = 2 * y
elif x % 2 != 0:
res = 2 * x + 1
else:
res = 2 * x
print(2 * z + res)
t = t - 1
``` | vfc_135598 | {
"difficulty": "medium",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/RETPO",
"time_limit": "2 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n3 3\n3 4",
"output": "6\n7",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n3 3\n3 0",
"output": "6\n7\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"... |
taco | verifiable_code | https://codeforces.com/problemset/problem/1513/A | Solve the following coding problem using the programming language python:
A sequence of $n$ integers is called a permutation if it contains all integers from $1$ to $n$ exactly once.
Given two integers $n$ and $k$, construct a permutation $a$ of numbers from $1$ to $n$ which has exactly $k$ peaks. An index $i$ of an ... | ```python
length = int(input())
a = []
for i in range(length):
x = input().split()
if int(x[1]) >= 0.5 * int(x[0]):
print(-1)
elif int(x[1]) == 0:
for j in range(int(x[0])):
print(j + 1, end=' ')
print()
else:
l = []
count = 0
for k in range(int(x[0])):
l.append(k + 1)
for k in range(int(x[0])):... | vfc_135602 | {
"difficulty": "easy",
"memory_limit": "256 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1513/A",
"time_limit": "1 second"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1 0\n5 2\n6 6\n2 1\n6 1\n",
"output": "1 \n2 4 1 5 3 \n-1\n-1\n1 6 2 3 4 5 \n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/absolute-distinct-count5118/1 | Solve the following coding problem using the programming language python:
Given a sorted array of N integers, find the number of distinct absolute values among the elements of the array.
Example 1:
Input:
N = 6
arr[] = {-3, -2, 0, 3, 4, 5}
Output: 5
Explanation: There are 5 distinct absolute
values among the element... | ```python
class Solution:
def distinctCount(self, arr, n):
a = [abs(i) for i in arr]
b = set(a)
return len(b)
``` | vfc_135606 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/absolute-distinct-count5118/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N = 6\r\narr[] = {-3, -2, 0, 3, 4, 5}",
"output": "5",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "N = 9\r\narr[] = {-1, -1, -1, -1, 0, 1, 1, 1, 1}",
"output": "2",
"type": "st... |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/next-smallest-palindrome4740/1 | Solve the following coding problem using the programming language python:
Given a number, in the form of an array Num[] of size N containing digits from 1 to 9(inclusive). The task is to find the next smallest palindrome strictly larger than the given number.
Example 1:
Input:
N = 11
Num[] = {9, 4, 1, 8, 7, 9, 7, 8, 3... | ```python
class Solution:
def generateNextPalindrome(self, num, n):
if num.count(9) == len(num):
return [1] + [0 for i in range(n - 1)] + [1]
x = num[:]
mid = n // 2
if mid == n / 2:
num[mid:] = num[:mid][::-1]
else:
num[mid + 1:] = num[:mid][::-1]
if num <= x:
if mid == n / 2:
if num[mid]... | vfc_135607 | {
"difficulty": "medium_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/next-smallest-palindrome4740/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N = 11\nNum[] = {9, 4, 1, 8, 7, 9, 7, 8, 3, 2, 2}",
"output": "9 4 1 8 8 0 8 8 1 4 9",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "N = 5\nNum[] = {2, 3, 5, 4, 5}",
"output": "2 3 6 3... |
taco | verifiable_code | https://codeforces.com/problemset/problem/375/A | Solve the following coding problem using the programming language python:
You have number a, whose decimal representation quite luckily contains digits 1, 6, 8, 9. Rearrange the digits in its decimal representation so that the resulting number will be divisible by 7.
Number a doesn't contain any leading zeroes and co... | ```python
def main():
a = input()
l = len(a)
book = [0] * 128
a = list(a)
for i in range(l):
a[i] = chr(ord(a[i]) - ord('0'))
book[ord(a[i])] += 1
num = 0
m = 0
buf = []
for i in range(1, 10):
if i in (1, 8, 6, 9):
for j in range(1, book[i]):
buf.append(i)
m = (10 * m + i) % 7
num += 1
e... | vfc_135609 | {
"difficulty": "medium_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/375/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1689\n",
"output": "1869\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "18906\n",
"output": "18690\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input"... |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/different-ways-to-spell-a-number4014/1 | Solve the following coding problem using the programming language python:
Given a number N such that it may contain many continuous digits. Find the number of ways to spell the number.
For example, consider 8884441100, one can spell it simply as triple eight triple four double two and double zero. One can also spell ... | ```python
class Solution:
def differentWaysToSpell(self, N):
result = 1
count = 1
for i in range(1, len(N)):
if N[i - 1] == N[i]:
count += 1
else:
result *= 2 ** (count - 1)
count = 1
return result * 2 ** (count - 1)
``` | vfc_135617 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/different-ways-to-spell-a-number4014/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N = 100",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "N = 11112",
"output": "8",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "N = 1... |
taco | verifiable_code | https://www.codechef.com/CSEP2020/problems/TOBY | Solve the following coding problem using the programming language python:
Toby has found a game to entertain himself.The game is like this:
You are in a coordinate system initially at (0,0) and you are given a sequence of steps which lead to your destination.The steps are given in the form of directions: ’U’ ,’D’ , ’... | ```python
from collections import Counter
try:
for _ in range(int(input())):
n = int(input())
s = input()
d1 = dict(Counter(s))
(u, d, r, l) = (0, 0, 0, 0)
if 'U' in d1:
u = d1['U']
else:
u = 0
if 'D' in d1:
d = d1['D']
else:
d = 0
if 'R' in d1:
r = d1['R']
else:
r = 0
if 'L' in... | vfc_135619 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/CSEP2020/problems/TOBY",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n7\nULUDLLU\n4\nRUUR\n4\nLRLR\n",
"output": "2\n0\n4\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/TRAVELLING | Solve the following coding problem using the programming language python:
You are given a graph with N vertices (numbered 1 to N) and M bidirectional edges, which doesn't contain multiple edges or self-loops — that is, the given graph is a simple undirected graph.
For each pair of vertices a, b such that 1 ≤ a, b ≤ N... | ```python
import heapq
def find_min_cost(City, Road, adj):
cost = [float('inf') for i in range(City + 1)]
cost[1] = 0
flag = [False for i in range(City + 1)]
start = [[0, 1]]
while len(start):
(_, p) = heapq.heappop(start)
if flag[p]:
continue
flag[p] = True
for e in adj[p]:
if cost[e[0]] > cost[p] ... | vfc_135623 | {
"difficulty": "hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/TRAVELLING",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n2 0\n5 4\n3 2\n1 4\n5 3\n4 2\n6 3\n1 2\n3 2\n1 3\n",
"output": "1\n0\n3\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/610/B | Solve the following coding problem using the programming language python:
Vika has n jars with paints of distinct colors. All the jars are numbered from 1 to n and the i-th jar contains a_{i} liters of paint of color i.
Vika also has an infinitely long rectangular piece of paper of width 1, consisting of squares of s... | ```python
n = int(input())
a = list(map(int, input().split()))
x = min(a)
count = x * n
m = []
for i in range(n):
if a[i] == x:
m.append(i)
y = len(m)
z = m[0]
for i in range(y - 1):
m[i] = m[i + 1] - m[i] - 1
m[-1] = n - (m[-1] - z) - 1
count += max(m)
print(count)
``` | vfc_135627 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/610/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n2 4 2 3 3\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n5 5 5\n",
"output": "15\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.