source stringclasses 3
values | instruction stringlengths 23 3.97k | input stringclasses 1
value | output stringlengths 1 3.75k |
|---|---|---|---|
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Andrii is good in Math, but not in Programming. He is asking you to solve following problem: Given an integer number N and two sets of integer A and B. Let set A contain all numbers from 1 to N and set B contain all numbers from N + 1 to 2N. Mul... | ```python
# cook your dish here
import math;
from math import gcd,sqrt,floor,factorial,ceil
from bisect import bisect_left,bisect_right
import bisect;
import sys;
from sys import stdin,stdout
import os
sys.setrecursionlimit(pow(10,7))
import collections
from collections import defaultdict,Counter
from statistics import... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Karen has just arrived at school, and she has a math test today! [Image]
The test is about basic addition and subtraction. Unfortunately, the teachers were too busy writing tasks for Codeforces rounds, and had no time to make an actual test. S... | ```python
#!/usr/bin/env pypy3
import math
def make_nCr_mod(max_n=2*10**5 + 100, mod=10**9 + 7):
fact, inv_fact = [0] * (max_n + 1), [0] * (max_n + 1)
fact[0] = 1
for i in range(max_n):
fact[i + 1] = fact[i] * (i + 1) % mod
inv_fact[-1] = pow(fact[-1], mod - 2, mod)
for i in reversed(rang... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Calculate the power of an army of numbers from 1 to $N$, both included.
-----Input:-----
- First line will contain a single integer $N$.
-----Output:-----
For each testcase, output in a single line containing the answer.
-----Constraints-----... | ```python
# cook your dish here
# cook your dish here
#powerful numbers
n = int(input())
plist = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 2... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
There are N people, conveniently numbered 1 through N.
We want to divide them into some number of groups, under the following two conditions:
- Every group contains between A and B people, inclusive.
- Let F_i be the number of the groups conta... | ```python
def main():
mod = 10**9+7
inv_n = [0]*1001
nCr = [[1]*(i+1) for i in range(1001)]
for i in range(1001):
inv_n[i] = pow(i, mod-2, mod)
for i in range(2, 1001):
for j in range(1, i):
nCr[i][j] = (nCr[i-1][j-1]+nCr[i-1][j]) % mod
n, a, b, c, d = list(map(int, i... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with 5, 7 and 5 syllables, in this order.
Iroha is looking for X,Y,Z-Haiku (defined below) in integer sequences.
Consider all integer sequences of length N whose element... | ```python
# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline
n,X,Y,Z = list(map(int,read().split()))
N = 1<<(X+Y+Z)
NX = 1<<X
NY = 1<<(X+Y)
NZ = 1<<(X+Y+Z)
MX = (1<<X) - 1
MY = (1<<(Y+X)) - (1<<X)
MZ = (1<<(X+Y+Z)) - (1<<(Y+X))
MMX = MX<<1
MMY = MY<<1
MMZ = MZ<<1
dp = ... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
A new airplane SuperPuperJet has an infinite number of rows, numbered with positive integers starting with 1 from cockpit to tail. There are six seats in each row, denoted with letters from 'a' to 'f'. Seats 'a', 'b' and 'c' are located to the l... | ```python
seat = input()
time_to = {'a': 4, 'f': 1, 'b': 5, 'e': 2, 'c': 6, 'd': 3}
col = seat[-1]
row = int(seat[:-1])
row -= 1
blocks_to_serve = row // 4
time = (6 * 2 + 4) * blocks_to_serve
if row % 2 == 1:
time += 6 + 1
time += time_to[col]
print(time)
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
You are given the array of integer numbers a_0, a_1, ..., a_{n} - 1. For each element find the distance to the nearest zero (to the element which equals to zero). There is at least one zero element in the given array.
-----Input-----
The firs... | ```python
inf = 10 ** 6
n = int(input())
a = list(map(int, input().split()))
dist = [inf] * n
for i in range(len(a)):
if not a[i]:
dist[i] = 0
cur = 1
i1 = i
while i1 - 1 > - 1 and a[i1 - 1] != 0:
dist[i1 - 1] = min(dist[i1 - 1], cur)
i1 -= 1
cur +... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
In my town ,there live a coder named Chef . He is a cool programmer . One day , he participate in a programming contest ,the contest give him only one problem . If he can’t solve the problem ,the problem setter will kill him . But the round allo... | ```python
# cook your dish here
from math import sqrt
for i in range(int(input())):
x1,y1,x2,y2=list(map(float,input().split()))
m=(y2-y1)/(x2-x1)
c=y2-m*x2
print('Test case : ',i+1)
q=int(input())
for i in range(q):
x3,y3=list(map(float,input().split()))
if(y3-m*x3-c==0):
print("YES")
else:
d=(abs(y3... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Laxman, a great Mathematician and Thinker, gives Sugreev an integer, $N$, and asks him to make an array $A$ of length $N$, such that $\sum A$i$^3 = X^2$, to prove the purity of the bond of his friendship with Ram. Sugreev is facing difficulty i... | ```python
# cook your dish here
t = int(input())
while(t>0):
n = int(input())
k=1
while(k<=n):
print(k, end=' ')
k+=1
print('\n')
t-=1
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
You are given sequences A and B consisting of non-negative integers.
The lengths of both A and B are N, and the sums of the elements in A and B are equal.
The i-th element in A is A_i, and the i-th element in B is B_i.
Tozan and Gezan repeats th... | ```python
#from collections import deque,defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl = lambda: list(map(int, input().split()))
inm = lambda: map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7
#R = 998244353
def ddprint(... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
“I am not in danger, Skyler. I am the danger. A guy opens his door and gets shot, and you think that of me? No! I am the one who knocks!”
Skyler fears Walter and ponders escaping to Colorado. Walter wants to clean his lab as soon as possible and... | ```python
t=int(input())
for i in range(t):
ans=0
x,y=list(map(int,input().split()))
if y>x:
if (y-x)%4==0:ans=3
elif (y-x)%2==0: ans=2
else: ans=1
if y<x:
if (y-x)%2==0:ans=1
else: ans=2
print(ans)
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Apart from having lots of holidays throughout the year, residents of Berland also have whole lucky years. Year is considered lucky if it has no more than 1 non-zero digit in its number. So years 100, 40000, 5 are lucky and 12, 3001 and 12345 are... | ```python
def main():
s = input()
n = len(s)
t = int(str(int(s[0]) + 1) + '0' * (n - 1))
print(t - int(s))
main()
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Vasiliy has a car and he wants to get from home to the post office. The distance which he needs to pass equals to d kilometers.
Vasiliy's car is not new — it breaks after driven every k kilometers and Vasiliy needs t seconds to repair it. After... | ```python
d, k, a, b, t = list(map(int, input().split()))
t1 = d * b
t2 = d * a + ((d - 1) // k) * t
t3 = max(0, d - k) * b + min(k, d) * a
dd = d % k
d1 = d - dd
t4 = d1 * a + max(0, (d1 // k - 1) * t) + dd * b
print(min([t1, t2, t3, t4]))
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Chef has decided to start home delivery from his restaurant. He hopes that he will get a lot of orders for delivery, however there is a concern. He doesn't have enough work forces for all the deliveries. For this he has came up with an idea - h... | ```python
# cook your dish here
from sys import stdin, stdout
from math import ceil
def solve():
for _ in range(int(input())):
n, m = map(int, stdin.readline().split())
par = [i for i in range(n)]
for i in range(m):
ta, tb = map(int, stdin.readline().strip().split())
... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Chef Al Gorithm was reading a book about climate and oceans when he encountered the word “glaciological”. He thought it was quite curious, because it has the following interesting property: For every two letters in the word, if the first appears... | ```python
# cook your dish here
import bisect
for _ in range(int(input())):
w,k=map(str, input().split())
k=int(k)
n=len(w)
w=list(w)
w.sort()
w.append('0')
c=1
l=0
l1=[]
l2=[]
for i in range(1, n+1):
if w[i]==w[i-1]:
c+=1
else:
a=bisect.bisect_left(l1, c)
if a==l:
l1.append(c)
l2.appen... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
After six days, professor GukiZ decided to give more candies to his students. Like last time, he has $N$ students, numbered $1$ through $N$. Let's denote the number of candies GukiZ gave to the $i$-th student by $p_i$. As GukiZ has a lot of stud... | ```python
try:
# https://www.codechef.com/LTIME63B/problems/GHMC
# Finally.... I properly understood what needs to be done.
def ctlt(arr, val):
# find number of values in sorted arr < val
if arr[0] >= val: return 0
lo = 0
hi = len(arr)
while hi-lo > 1:
md = (hi+l... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
In this problem the input will consist of a number of lines of English text consisting of the letters of the English alphabet, the punctuation marks ' (apostrophe), . (full stop), , (comma), ; (semicolon), :(colon) and white space characters (bl... | ```python
import sys
t=int(input())
x=sys.stdin.readlines()
l=[]
for s in x:
s=s.replace(".","")
s=s.replace("'","")
s=s.replace(",","")
s=s.replace(":","")
s=s.replace(";","")
lst=[str(i) for i in s.split()]
for j in lst:
l.append(j)
m=[]
for y in l:
z=y.lower()
m.append(z)
... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Once again, Boris needs the help of Anton in creating a task. This time Anton needs to solve the following problem:
There are two arrays of integers $a$ and $b$ of length $n$. It turned out that array $a$ contains only elements from the set $\{... | ```python
from math import *
mod = 1000000007
for zz in range(int(input())):
n = int(input())
a = [ int(i) for i in input().split()]
b = [int(i) for i in input().split()]
ha = True
hp = False
hm = False
for i in range(n):
if b[i] != a[i]:
if b[i] > a[i]:
... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Ayoub thinks that he is a very smart person, so he created a function $f(s)$, where $s$ is a binary string (a string which contains only symbols "0" and "1"). The function $f(s)$ is equal to the number of substrings in the string $s$ that contai... | ```python
import sys
input = sys.stdin.readline
t=int(input())
def calc(x):
return x*(x+1)//2
for test in range(t):
n,m=list(map(int,input().split()))
ANS=calc(n)
k=n-m
q,mod=divmod(k,m+1)
ANS-=calc(q+1)*mod+calc(q)*(m+1-mod)
print(ANS)
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
There are N hills in a row numbered 1 through N from left to right. Each hill has a height; for each valid i, the height of the i-th hill is Hi. Chef is initially on the leftmost hill (hill number 1). He can make an arbitrary number of jumps (in... | ```python
for _ in range(int(input())):
N,U,D=list(map(int,input().split()))
H=list(map(int,input().split()))
jumps=0
paracount=0
for i in range(len(H)-1):
if H[i+1]-H[i]<=U and H[i+1]>=H[i]:
jumps+=1
elif H[i]>=H[i+1] and H[i]-H[i+1]<=D:
jumps+=1
elif H[i]-H[i+1]>D and paracount==0:
jumps+=1
par... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Chef is playing a game on the non-negative x-axis. It takes him $1$ second to reach from $i^{th}$ position to $(i-1)^{th}$ position or $(i+1)^{th}$ position. The chef never goes to the negative x-axis. Also, Chef doesn't stop at any moment of ti... | ```python
import sys
from random import choice,randint
inp=sys.stdin.readline
out=sys.stdout.write
flsh=sys.stdout.flush
sys.setrecursionlimit(10**9)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def MI(): return map(int,... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Soma is a fashionable girl. She absolutely loves shiny stones that she can put on as jewellery accessories. She has been collecting stones since her childhood - now she has become really good with identifying which ones are fake and which ones a... | ```python
n = int(input())
for i in range(n):
count = 0
k = input()
x = list(k)
kk = input()
y = list(kk)
for j in y:
for jj in x:
if(j==jj):
count = count+1
break
print(count)
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Chef recently started working at ABC corporation. Let's number weekdays (Monday through Friday) by integers $1$ through $5$. For each valid $i$, the number of hours Chef spent working at the office on weekday $i$ was $A_i$.
Unfortunately, due to... | ```python
# cook your dish here
for t in range(int(input())):
a1,a2,a3,a4,a5,p=[int(x)for x in input().rstrip().split()]
if (a1+a2+a3+a4+a5)*p >120:
print("Yes")
else:
print("No")
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
DevuLand is a very strange place. There are n villages in it. Some of the villages are occupied by dinosaurs while the remaining ones by villagers.
You are given the information of DevuLand
by an array D of size n. If D[i] is non-negative, i... | ```python
# cook your dish here
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
curr = 0
ans = 0
for x in a:
curr += x
ans += abs(curr)
print(ans)
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
There is a simple undirected graph with N vertices and M edges.
The vertices are numbered 1 through N, and the edges are numbered 1 through M.
Edge i connects Vertex U_i and V_i.
Also, Vertex i has two predetermined integers A_i and B_i.
You wil... | ```python
class dsu:
def __init__(self, n=0):
self._n = n
self.parent_or_size = [-1] * n
def merge(self, a: int, b: int) -> int:
x = self.leader(a)
y = self.leader(b)
if x == y:
return x
if self.parent_or_size[x] > self.parent_or_size[y]:
... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Abhiram needs to search for an antidote. He comes to know that clue for finding the antidote is carefully hidden by KrishnaMurthy in the form of a puzzle.
The puzzle consists of a string S and a keywordK. Abhiram needs to find the string of pos... | ```python
x = input().split(" ")
y = input()
ans = ''
l = 1
for i in x:
if i!=y and sorted(i) == sorted(y):
ans = ans + (str)(l)
l=l+1
ans+='.'
print("The antidote is found in",ans)
``` | |
open-r1/verifiable-coding-problems-python-10k | 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
# cook your dish here
for i in range(int(input())):
n=int(input())
p=1
l=n-1
for j in range(n):
for k in range(l):
print(" ",end='')
for k in range(p):
print("*",end='')
print()
for k in range(l):
print(" ",end='')
for... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Sandu, a teacher in Chefland introduced his students to a new sequence i.e.
0,1,0,1,2,0,1,2,3,0,1,2,3,4........
The Sequence starts from 0 and increases by one till $i$(initially i equals to 1), then repeat itself with $i$ changed to $i+1$
Stude... | ```python
from math import sqrt
for _ in range(int(input())):
n = int(input())
x = int(sqrt(2 * n))
while x * (x+1) // 2 <= n:
x += 1
while x * (x+1) // 2 > n:
x -= 1
n -= x * (x+1) // 2
print(n)
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
There are $N$ sabotages available in the game Among Us, initially all at level $0$.
$N$ imposters are allotted the task to upgrade the level of the sabotages.
The $i^{th}$ imposter $(1 \leq i \leq N)$ increases the level of $x^{th}$ sabotage $... | ```python
from bisect import bisect
n = 32000
def primeSeive(n):
prime = [True for i in range(n + 1)]
primes = []
p = 2
while (p * p <= n):
if (prime[p] == True):
for i in range(p * 2, n + 1, p):
prime[i] = False
p += 1
prime[0] = False
prime[1] = Fals... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
$Jaggu$ monkey a friend of $Choota$ $Bheem$ a great warrior of $Dholakpur$. He gets everything he wants. Being a friend of $Choota$ $Bheem$ he never has to struggle for anything, because of this he is in a great debt of $Choota$ $Bheem$, he real... | ```python
counter = -1
def flattree(node):
nonlocal counter
if visited[node]==1:
return
else:
visited[node]=1
counter += 1
i_c[node] = counter
flat_tree[counter] = swt[node]
for i in graph[node]:
if visited[i]==0:
fl... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Chef has bought N robots to transport cakes for a large community wedding. He has assigned unique indices, from 1 to N, to each of them. How it will happen?
Chef arranges the N robots in a row, in the (increasing) order of their indices. Then, h... | ```python
#read input
cases = int(input())
caselist = []
for i in range(0, cases):
caselist.append(input())
#iterate each case
for j in range(0, cases):
#current case's parameters:
current_input = caselist[j].split(' ')
bots = int(current_input[0])
switch = int(current_input[1])
#generate botlist and cakelist
... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Recently, Chef got obsessed with piano. He is a just a rookie in this stuff and can not move his fingers from one key to other fast enough. He discovered that the best way to train finger speed is to play scales.
There are different kinds of sc... | ```python
t =int(input())
for i in range(t):
C=[ord(x)-ord('R') for x in list(input())]
N=int(input())
L=sum(C)
r=1
c=0
while(r*L<N*12):
c+=N*12-r*L
r+=1
print(c)
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
The chef is trying to decode 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 cas... | ```python
t=int(input())
while(t):
n=int(input())
cnt=1;
for i in range(n):
s=""
for j in range(n):
s=s+str(bin(cnt))[2:][: : -1]+" "
cnt=cnt+1
print(s)
t=t-1
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Toad Pimple has an array of integers $a_1, a_2, \ldots, a_n$.
We say that $y$ is reachable from $x$ if $x<y$ and there exists an integer array $p$ such that $x = p_1 < p_2 < \ldots < p_k=y$, and $a_{p_i}\, \&\, a_{p_{i+1}} > 0$ for all integers... | ```python
from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import heappush,heappop,heapify
import math
from collections import *
from functools import reduce,cmp_to_key
import sys
input = sys.stdin.readline
from itertools import accumulate
from functools import lru_cache
M = mod =... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
"QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth.
Now Diamond has given Bort a string consisting of only uppercase English letters of length n. There is a great number of "QAQ" in the string (... | ```python
s=input()
ans = 0
for i in range(len(s)):
if s[i] == 'A':
ans += s[:i].count('Q') * s[i:].count('Q')
print(ans)
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
There is a frog staying to the left of the string $s = s_1 s_2 \ldots s_n$ consisting of $n$ characters (to be more precise, the frog initially stays at the cell $0$). Each character of $s$ is either 'L' or 'R'. It means that if the frog is stay... | ```python
for i in range(int(input())):
s='R' + input() + 'R'
prev=0
ma=-1
for i in range(1,len(s)):
if s[i]=='R':
ma=max(ma,i-prev)
prev=i
print(ma)
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white.
Consider a set consisting of k (0 ≤ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tree,... | ```python
MOD = 1000000007
n = int(input())
p = [int(x) for x in input().split()]
x = [int(x) for x in input().split()]
children = [[] for x in range(n)]
for i in range(1,n):
children[p[i-1]].append(i)
#print(children)
count = [(0,0) for i in range(n)]
for i in reversed(list(range(n))):
prod = 1
for ch... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Chef is playing a game with two of his friends. In this game, each player chooses an integer between $1$ and $P$ inclusive. Let's denote the integers chosen by Chef, friend 1 and friend 2 by $i$, $j$ and $k$ respectively; then, Chef's score is
... | ```python
for __ in range(int(input())):
n,p=list(map(int,input().split()))
d=n%(n//2+1)
if(d==0):
t=p*p*p
else:
t=(p-d)*(p-d)+(p-d)*(p-n)+(p-n)*(p-n)
print(t)
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
You're given an array of $n$ integers between $0$ and $n$ inclusive.
In one operation, you can choose any element of the array and replace it by the MEX of the elements of the array (which may change after the operation).
For example, if the c... | ```python
def solve():
n = int(input())
a = list(map(int, input().split()))
c = [0] * (n + 1)
def inc():
for i in range(n - 1):
if a[i] > a[i + 1]:
return False
return True
def calc():
for i in range(n + 1):
c[i] = 0
for i in a:... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Let's call two strings $s$ and $t$ anagrams of each other if it is possible to rearrange symbols in the string $s$ to get a string, equal to $t$.
Let's consider two strings $s$ and $t$ which are anagrams of each other. We say that $t$ is a redu... | ```python
import sys
readline = sys.stdin.readline
S = list([ord(x)-97 for x in readline().strip()])
N = len(S)
table = [[0]*26 for _ in range(N)]
for i in range(N):
table[i][S[i]] = 1
for i in range(1, N):
for j in range(26):
table[i][j] += table[i-1][j]
Q = int(readline())
Ans = [None]*Q
for qu in r... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Chef is learning linear algebra. Recently, he learnt that for a square matrix $M$, $\mathop{\rm trace}(M)$ is defined as the sum of all elements on the main diagonal of $M$ (an element lies on the main diagonal if its row index and column index ... | ```python
# cook your dish here
T=int(input())
for k in range(0,T):
N=int(input())
matrix=[]
for i in range(0,N):
a=list(map(int, input().split()))
matrix.append(a)
max_trace = []
for i in range(0,N):
trace1=0
trace2=0
for j in range(0,i+1):
trace1+=matrix[j][N+j-i-1]
trace2+=matrix[N+j-i-1][j]
... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
In the official contest this problem has a different statement, for which jury's solution was working incorrectly, and for this reason it was excluded from the contest. This mistake have been fixed and the current given problem statement and mod... | ```python
import os
import random
import sys
from typing import List, Dict
class Int:
def __init__(self, val):
self.val = val
def get(self):
return self.val + 111
class Unique:
def __init__(self):
self.s = set()
def add(self, val : int):
self.s.add(val)
def __co... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Saket loves to play with strings. One day , while he was having fun with Cyclic Permutations of available strings to him, he observed that despite being scarce in numbers Vowels were really clingy.Being clingy means for almost every given string... | ```python
for t in range(int(input())):
n=int(input())
s=input().strip()
c=0
flag=0
for i in range(n):
if (s[i]=="A" or s[i]=="E" or s[i]=="I" or s[i]=="O" or s[i]=="U") and (s[i-1]=="A" or s[i-1]=="E" or s[i-1]=="I" or s[i-1]=="O" or s[i-1]=="U") :
flag=1
if flag and n!=1:
print("Yes")
else:
... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Johnny has some difficulty memorizing the small prime numbers. So, his computer science teacher has asked him to play with the following puzzle game frequently.
The puzzle is a 3x3 board consisting of numbers from 1 to 9. The objective of the pu... | ```python
# cook your dish here
from collections import deque
primes = {2,3,5,7,11,13,17}
edges = [(0,3),(0,1),(1,2),(1,4),(2,5),(3,4),(3,6),(4,5),(4,7),(5,8),(6,7),(7,8)]
x = [1,2,3,4,5,6,7,8,9]
avail = {tuple(x):0}
q = deque([x])
while q:
curr = q.popleft();
for e in edges:
if curr[e[0]]+cur... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
You are given a sequence $A_1, A_2, \ldots, A_N$. For each $k$ ($1 \le k \le N$), let's define a function $f(k)$ in the following way:
- Consider a sequence $B_1, B_2, \ldots, B_N$, which is created by setting $A_k = 0$. Formally, $B_k = 0$ and ... | ```python
from sys import stdin
def gt(num):
if num:
return num
return 0
for __ in range(int(stdin.readline().split()[0])):
n = int(stdin.readline().split()[0])
a = list(map(int, stdin.readline().split()))
cnta = dict()
cnta.setdefault(0)
cntb = dict()
cntb.setdefault(0)
for i in a:
cnta[i] = gt(cnta.get(i... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Ashley wrote a random number generator code.
Due to some reasons, the code only generates random positive integers which are not evenly divisible by 10. She gives $N$ and $S$ as input to the random number generator. The code generates a random n... | ```python
"""
Author : thekushalghosh
Team : CodeDiggers
"""
import sys,math
input = sys.stdin.readline
############ ---- USER DEFINED INPUT FUNCTIONS ---- ############
def inp():
return(int(input()))
def inlt():
return(list(map(int,input().split())))
def insr():
s = input()
return(s[:len(s) -... | |
open-r1/verifiable-coding-problems-python-10k | 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 (odd) to form a new pattern. Help the chef to code this pattern problem.
-----Input:-----
- First-line will contain $T$, the number of tes... | ```python
t=int(input())
for _ in range(t):
n=int(input())
l1=[]
if n==1:
print('*')
elif n==3:
print('*')
print('**')
print('*')
else:
s1=""
n1=n//2
n1+=1
for i in range(1,n1+1):
s1=""
if i==1:
... | |
open-r1/verifiable-coding-problems-python-10k | 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
X, D = list(map(int, input().split()))
cn = 1
add0 = 1 if (X&1) else 0
ans = []
for i in range(30,0,-1):
if not (X & (1<<i)): continue
ans += [cn]*i
add0 += 1
cn += D
for i in range(add0):
ans.append(cn)
cn += D
print(len(ans))
print(' '.join(map(str, ans)))
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
You are given two integer sequences $A_1, A_2, \ldots, A_N$ and $B_1, B_2, \ldots, B_M$. For any two sequences $U_1, U_2, \ldots, U_p$ and $V_1, V_2, \ldots, V_q$, we define
Score(U,V)=∑i=1p∑j=1qUi⋅Vj.Score(U,V)=∑i=1p∑j=1qUi⋅Vj.Score(U, V) = \su... | ```python
t = int(input())
l,r,x = 0,0,0
ans = []
for i in range(t):
(n,m) = tuple(map(int,input().split()))
a = list(map(int,input().split()))
b = list(map(int,input().split()))
suma = sum(a)
sumb = sum(b)
q = int(input())
for j in range(q):
l1 = list(map(int,input().split()))
if l1[0] == 1:
l = l1[1]
... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
There are $n$ football teams in the world.
The Main Football Organization (MFO) wants to host at most $m$ games. MFO wants the $i$-th game to be played between the teams $a_i$ and $b_i$ in one of the $k$ stadiums.
Let $s_{ij}$ be the numbers... | ```python
import random
import math
def set_color(game, color):
color_count[game[0]][game[2]] -= 1
color_count[game[1]][game[2]] -= 1
game[2] = color
color_count[game[0]][game[2]] += 1
color_count[game[1]][game[2]] += 1
def fix(node):
minimum = math.inf
maximum = 0
for i in range(k):
... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
On the planet Mars a year lasts exactly n days (there are no leap years on Mars). But Martians have the same weeks as earthlings — 5 work days and then 2 days off. Your task is to determine the minimum possible and the maximum possible number of... | ```python
n=int(input())
r=n%7
d=n//7
print(2*d+max(0,r-5),2*d+min(r,2))
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Uttu got to know about an interesting two-player mobile game recently and invites his friend Gangwar to try it out with him. Gangwar, however, has been playing this game since it was out 5 years ago and is a Legendary Grandmaster at it. Uttu imm... | ```python
''' J A I ~ S H R E E ~ R A M '''
# Title: cc-CKOJ20D.py
# created on: 20-07-2020 at 20:46:04
# Creator & Template : Udit Gupta "@luctivud"
# https://github.com/luctivud
# https://www.linkedin.com/in/udit-gupta-1b7863135/
import math; from collections import *
import sys; from functools i... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Jamie is preparing a Codeforces round. He has got an idea for a problem, but does not know how to solve it. Help him write a solution to the following problem:
Find k integers such that the sum of two to the power of each number equals to the n... | ```python
from collections import defaultdict
def solve(n, k):
as_bin = bin(n)[2:]
cnt = defaultdict(int)
cnt.update({i : 1 for i, b in enumerate(reversed(as_bin)) if b == '1'})
curr_len = len(cnt)
curr_pow = len(as_bin) - 1
if curr_len > k:
return None
while True:
new_len... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Indian National Olympiad in Informatics 2015
A string is any nonempty sequence of 0s and 1s. Examples of strings are 00, 101, 111000, 1, 0, 01. The length of a string is the number of symbols in it. For example, the length of 111000 is 6. If u a... | ```python
# cook your dish here
def offset(l, flag):
x = 0
# print(l)
for i in range(1, len(l)):
temp = []
for j in range(i):
v = getbig(l[i], l[j], fs)
if v > 1:
temp.append(v)
if flag:
x += 2**v - 2
... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
You have been recently hired as a developer in CodeChef. Your first mission is to implement a feature that will determine the number of submissions that were judged late in a contest.
There are $N$ submissions, numbered $1$ through $N$. For each... | ```python
# cook your dish here
for t in range(int(input())):
c=0
for i in range(int(input())):
s,j=list(map(int,input().split()))
if (j-s)>5:
c+=1
print(c)
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
You are given positive integers $L$ and $R$. You have to find the sum
S=∑i=LR(L∧(L+1)∧…∧i),S=∑i=LR(L∧(L+1)∧…∧i),S = \sum_{i=L}^R \left(L \wedge (L+1) \wedge \ldots \wedge i\right) \,,
where $\wedge$ denotes the bitwise AND operation. Since the s... | ```python
l= []
for i in range(62):
l.append(2**i)
T = int(input())
flag = 0
for t in range(T):
L,R = [int(i) for i in input().split()]
bL = bin(L)
lL = len(bL)-2
index = 1
ans = 0
temp = 0
while(index<=lL):
temp = L%l[index]
if temp>=l[index-1]:
if(l[index]-temp<=R-L+1):
ans= (ans +(l[index-1])*(... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Given an integer N, Chef wants to find the smallest positive integer M such that the bitwise XOR of M and M+1 is N. If no such M exists output -1.
-----Input-----
The first line of input contain an integer T denoting the number of test cases. E... | ```python
# from math import log2
# N = 10000
# for i in range(1,N):
# # print(i)
# for m in range(i):
# if( (m^(m+1))==i ):
# print(i)
# print(m,m+1,bin(m)[2:])
# print()
# break
# # else:
# # print(-1)
# # print()
T = int(input())
ans... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Chef loves to play with arrays by himself. Today, he has an array A consisting of N distinct integers. He wants to perform the following operation on his array A.
- Select a pair of adjacent integers and remove the larger one of these two. This... | ```python
from math import *
for t in range(int(input())):
n = int(input())
numberlist = list(map(int,input().split()))
numberlist.sort()
print(numberlist[0]* ( len(numberlist) -1))
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Let's write all the positive integer numbers one after another from $1$ without any delimiters (i.e. as a single string). It will be the infinite sequence starting with 123456789101112131415161718192021222324252627282930313233343536...
Your tas... | ```python
k = int(input())
if k<=9:
print(k)
else:
num_arr = [9*(i+1)* 10**i for i in range(11)]
index = 0
while True:
if k<=num_arr[index]:
break
else:
k -= num_arr[index]
index += 1
digit = index+1
k += digit-1
num = k//digit
of... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Lee just became Master in Codeforces, and so, he went out to buy some gifts for his friends. He bought $n$ integers, now it's time to distribute them between his friends rationally...
Lee has $n$ integers $a_1, a_2, \ldots, a_n$ in his backpack... | ```python
def solve():
n, k = map(int,input().split())
lst1 = list(map(int,input().split()))
lst1.sort(reverse=True)
ind = 0
ans = 0
lst2 = list(map(int,input().split()))
lst2.sort()
for i in range(k):
lst2[i] -= 1
if lst2[i] == 0: ans += lst1[ind]
ans += lst1[ind... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Alice and Bob are playing a fun game of tree tag.
The game is played on a tree of $n$ vertices numbered from $1$ to $n$. Recall that a tree on $n$ vertices is an undirected, connected graph with $n-1$ edges.
Initially, Alice is located at vert... | ```python
from sys import stdin
from collections import deque
def NC_Dij(lis,start):
ret = [float("inf")] * len(lis)
ret[start] = 0
q = deque([start])
plis = [i for i in range(len(lis))]
while len(q) > 0:
now = q.popleft()
for nex in lis[now]:
if ret[nex] > ret[n... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
The Little Elephant likes permutations. This time he has a permutation A[1], A[2], ..., A[N] of numbers 1, 2, ..., N.
He calls a permutation A good, if the number of its inversions is equal to the number of its local inversions. The number of i... | ```python
from sys import stdin
t = int(stdin.readline())
def count(n, arr):
loc = 0
glob = 0
for i in range(n-1):
if arr[i] > arr[i+1]:
loc += 1
for i in range(n-1):
for j in range(i+1, n):
if glob > loc:
return 0
if arr[i] > arr[j]:
glob += 1;
if glob == loc:
return 1
return 0
for _ in ... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Hilbert's Hotel is a very unusual hotel since the number of rooms is infinite! In fact, there is exactly one room for every integer, including zero and negative integers. Even stranger, the hotel is currently at full capacity, meaning there is e... | ```python
t = int(input())
for _ in range(t):
n = int(input())
l = [int(x) for x in input().split()]
vals = [(x + i) % n for i, x in enumerate(l)]
print("YES" if len(set(vals)) == n else "NO")
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Sereja has an array A of N positive integers : A[1], A[2], A[3], ... , A[N].
In a single operation on the array, he performs the following two steps :
- Pick two indices i, j s.t. A[i] > A[j]
- A[i] -= A[j]
Sereja can apply these operation... | ```python
def gcd(a,b):
if b==0:
return a
else:
return gcd(b,a%b)
def main():
t=int(input())
while t!=0:
t=t-1
n=int(input())
if n==1:
print(input())
else:
a=list(map(int,input().split(" ")))
p=a[0]
for i in range(1,n):
p=gcd(p,a[i])
if p==1:
break
print(n*p)
def __starting... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Bob just learned about bitwise operators. Since Alice is an expert, she decided to play a game, she will give a number $x$ to Bob and will ask some questions:
There will be 4 different kinds of queries:-
-
Alice gives an integer $i$ and Bob has... | ```python
# cook your dish here
t=int(input())
while t>0:
n,q=list(map(int,input().split()))
blst=[0]
for i in range(1,65):
blst.append(0)
i=1
while n>0:
if n%2:
blst[i]=1
n//=2
i+=1
while q>0:
n=int(input())
if n==1:
p=int(... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
$Harshad$ $Mehta$ is planning a new scam with the stocks he is given a stock of integer price S and a number K . $harshad$ has got the power to change the number $S$ at most $K$ times
In order to raise the price of stock and now cash it for hi... | ```python
a,b=[int(_) for _ in input().split()]
if b==0:
print(a)
else:
l=[]
a=str(a)
for i in range(len(a)):
l.append(a[i])
for i in range(len(l)):
if b==0:
break
if l[i]=='9':
continue
else:
l[i]='9'
... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
You are given an array $a$, consisting of $n$ integers.
Each position $i$ ($1 \le i \le n$) of the array is either locked or unlocked. You can take the values on the unlocked positions, rearrange them in any order and place them back into the u... | ```python
import math
from collections import deque
from sys import stdin, stdout
from string import ascii_letters
import sys
letters = ascii_letters
input = stdin.readline
#print = stdout.write
for _ in range(int(input())):
n = int(input())
arr = list(map(int, input().split()))
can = list(map(int, input()... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
We start with a permutation $a_1, a_2, \ldots, a_n$ and with an empty array $b$. We apply the following operation $k$ times.
On the $i$-th iteration, we select an index $t_i$ ($1 \le t_i \le n-i+1$), remove $a_{t_i}$ from the array, and append ... | ```python
import sys
readline = sys.stdin.readline
T = int(readline())
MOD = 998244353
Ans = [None]*T
for qu in range(T):
N, K = map(int, readline().split())
A = [0] + list(map(int, readline().split())) + [0]
B = list(map(int, readline().split()))
C = [None]*(N+1)
for i in range(1, N+1):
C... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
A robot is initially at $(0,0)$ on the cartesian plane. It can move in 4 directions - up, down, left, right denoted by letter u, d, l, r respectively. More formally:
- if the position of robot is $(x,y)$ then u makes it $(x,y+1)$
- if the positi... | ```python
z = int(input())
i = 0
while i < z:
n = int(input())
p = int(n**(0.5))
if p*(p+1) < n:
p += 1
# print("P", p)
x, y = 0, 0
q = 0
flag = True
if p*(p+1) == n:
# print("Even steps, nice")
q = p
else:
# remaining steps
q = p-1
flag = False
if q%2 :... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Permutation $p$ is a sequence of integers $p=[p_1, p_2, \dots, p_n]$, consisting of $n$ distinct (unique) positive integers between $1$ and $n$, inclusive. For example, the following sequences are permutations: $[3, 4, 1, 2]$, $[1]$, $[1, 2]$. T... | ```python
t = int(input())
for faw in range(t):
n = int(input())
a = [0] + list(map(int,input().split()))
nun = []
ans = []
f = True
for i in range(1, n + 1):
if a[i] == a[i-1]:
if len(nun) == 0:
f = False
break
else:
... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Chef is the leader of Chef's Earth Defense Organization, and his mission is to counter aliens which are threatening the earth. According to information gathered by the organization, there are $N$ alien spaceships (numbered $1$ through $N$) plann... | ```python
# cook your dish here
def isValid(mid):
time = 0.0
for i in range(n):
if time < c[i]:
time = c[i]
time += mid # cannon cooling
elif time >= c[i] and time <= c[i] + d:
time += mid # cannon cooling
else:
return False
return True
t = int(input())
while t != 0:
n, d = list(map(int, input().... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
In a fictitious city of CODASLAM there were many skyscrapers. The mayor of the city decided to make the city beautiful and for this he decided to arrange the skyscrapers in descending order of their height, and the order must be strictly decreas... | ```python
import sys
num=int(sys.stdin.readline())
s=sys.stdin.readline().split()
sky=list(map(int,s))
sky.reverse()
cuts=0
change=0
t=False
i=1
while i<len(sky):
if sky[i]<=sky[i-1]:
for j in range(i-1,-1,-1):
if sky[j]<=sky[i]-(i-j):
break
else:
change+=sky[j]-(sky[i]-(i-j))
if change... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her.
Sergey gives Nastya the word t ... | ```python
def sub(a, s):
pa = 0
ps = 0
while pa < len(a) and ps < len(s):
if a[pa] == s[ps]:
ps += 1
pa += 1
else:
pa += 1
return ps == len(s)
def subword(t, ord_ar, n):
t_copy = []
for i in range(len(ord_ar)):
if ord_ar[i] >= n:
... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
T is playing a game with his friend, HL.
There are $n$ piles of stones, the $i$-th pile initially has $a_i$ stones.
T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a s... | ```python
t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int,input().split()))
sumA = sum(a)
TWins = False
for elem in a:
if elem > sumA // 2:
TWins = True
break
if TWins or sumA % 2 != 0:
print("T")
else:
print("HL")
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
There are n cabs in a city numbered from 1 to n. The city has a rule that only one cab can run in the city at a time. Cab picks up the customer and drops him to his destination. Then the cab gets ready to pick next customer. There are m customer... | ```python
import math
def dist(w,x,y,z):
return math.hypot(y - w, z - x)
t = int(input())
while (t>0):
t = t -1
n, m = list(map(int,input().split()))
a = []
for i in range(0,n):
x,y = list(map(int,input().split()))
a.append([x,y])
for j in range(0,m):
p,q,r,s = list(map(int,input().split()))
nearest = -1... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Now you can take online courses in the Berland State University! Polycarp needs to pass k main online courses of his specialty to get a diploma. In total n courses are availiable for the passage.
The situation is complicated by the dependence o... | ```python
#This code is dedicated to Vlada S.
class Course:
def __init__(self, reqs, number):
self.reqs = list(map(int, reqs.split()[1:]))
self.available = False
self.in_stack = False
self.number = number
n, k = list(map(int, input().split()))
requirements = list(map(int, input().split()))
courses = {}
answ... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Jett is tired after destroying the town and she wants to have a rest. She likes high places, that's why for having a rest she wants to get high and she decided to craft staircases.
A staircase is a squared figure that consists of square cells. ... | ```python
import sys
import random
from fractions import Fraction
from math import *
def input():
return sys.stdin.readline().strip()
def iinput():
return int(input())
def finput():
return float(input())
def tinput():
return input().split()
def linput():
return list(input())
def rinput():
... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Allen and Bessie are playing a simple number game. They both know a function $f: \{0, 1\}^n \to \mathbb{R}$, i. e. the function takes $n$ binary arguments and returns a real value. At the start of the game, the variables $x_1, x_2, \dots, x_n$ a... | ```python
n, r = [int(x) for x in input().split()]
n = 2 ** n
xs = [int(x) for x in input().split()]
s = sum(xs)
res = [0 for _ in range(r+1)]
for i in range(r):
res[i] = s / n
i, val = [int(x) for x in input().split()]
s += val - xs[i]
xs[i] = val
res[r] = s / n
print("\n".join(map(str, res)))
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Chef has a pepperoni pizza in the shape of a $N \times N$ grid; both its rows and columns are numbered $1$ through $N$. Some cells of this grid have pepperoni on them, while some do not. Chef wants to cut the pizza vertically in half and give th... | ```python
# cook your dish here
for _ in range(int(input())):
n=int(input())
l1=[]
l2=[]
for i in range(n):
s=input()
a=s[ :n//2].count('1')
b=s[n//2: ].count('1')
if a>b:
l1.append(a-b)
elif a<b:
l2.append(b-a)
p=sum(l1)
q=sum(l2)
if p==q:
print(0)
elif p>q:
diff=p-q
flag=0... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Richik$Richik$ has just completed his engineering and has got a job in one of the firms at Sabrina$Sabrina$ which is ranked among the top seven islands in the world in terms of the pay scale.
Since Richik$Richik$ has to travel a lot to reach th... | ```python
t=int(input())
for i in range(t):
x,n=[int(g) for g in input().split()]
sal=0
day=x
while day<n:
sal=sal+day
day+=x
print(sal)
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Chef likes to play with array elements. His teacher has given him an array problem. But now he is busy as Christmas is coming. So, he needs your help. Can you help him to solve this problem.
You are given an array $(A1,A2,A3……AN)$ of length $N$.... | ```python
# cook your dish here
def index(n,val):
while(val >= n):
val = val//2
return n - val
t = int(input())
for _ in range(t):
n = int(input())
arr = list(map(int,input().split()))
new = [0 for i in range(n)]
for i in range(n):
if arr[i]<=n :
new[i] = arr[i] + ar... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Momiji has got a rooted tree, consisting of n nodes. The tree nodes are numbered by integers from 1 to n. The root has number 1. Momiji decided to play a game on this tree.
The game consists of several steps. On each step, Momiji chooses one of... | ```python
# https://codeforces.com/problemset/problem/280/C
from collections import defaultdict, deque
import sys
nodes = int(sys.stdin.readline())
edges = defaultdict(list)
for line in sys.stdin:
a, b = line.split()
a = int(a)
b = int(b)
edges[a].append(b)
edges[b].append(a)
bfs = deque([(1, 1)])
... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
We have a permutation of the integers from 1 through N, p_1, p_2, .., p_N.
We also have M pairs of two integers between 1 and N (inclusive), represented as (x_1,y_1), (x_2,y_2), .., (x_M,y_M).
AtCoDeer the deer is going to perform the following ... | ```python
import sys
readline = sys.stdin.readline
class UnionFind(object):
def __init__(self, n):
self._par = list(range(n))
self.size = [1]*n
def root(self, v):
if self._par[v] == v:
return v
self._par[v] = self.root(self._par[v])
return self._par[v]
... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Chef wants to gift pairs to his friends this new year. But his friends like good pairs
only.
A pair (a , b) is called a good pair if 1 <= a < b <= N such that GCD(a*b , P) = 1.
Since Chef is busy in preparation for the party, he wants your help ... | ```python
# cook your dish here
def G(x, y):
while(y):
x, y = y, x % y
return x
# t=int(input())
# l=list(map(int,input().split()))
for _ in range(int(input())):
n,p=map(int,input().split())
c=0
for i in range(1,n+1):
if G(i,p)==1:
c+=1
ans=c*(c-1)//2
print... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
There is an event in DUCS where boys get a chance to show off their skills to impress girls. The boy who impresses the maximum number of girls will be honoured with the title “Charming Boy of the year”.
There are $N$ girls in the department. Eac... | ```python
from collections import Counter
for _ in range(int(input())):
n=int(input())
l=[i for i in input().split()]
ll=[]
c=Counter(l)
cc=[]
m=0
for l,count in c.most_common(len(l)-1):
if m==0:
ll.append(l)
cc.append(count)
... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Allen is hosting a formal dinner party. $2n$ people come to the event in $n$ pairs (couples). After a night of fun, Allen wants to line everyone up for a final picture. The $2n$ people line up, but Allen doesn't like the ordering. Allen prefers ... | ```python
n = int(input())
xs = [int(x) for x in input().split()]
seen = {}
res = 0
while xs:
j = xs.index(xs[0], 1)
res += j - 1
xs = xs[1:j] + xs[j+1:]
print(res)
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Harsh, like usual, started studying 6 months before for his end semester examinations. He was going to complete his 8th revision of the whole syllabus, when suddenly Pranav showed up in his room with the last year's question paper for their algo... | ```python
#dt = {} for i in x: dt[i] = dt.get(i,0)+1
import sys;input = sys.stdin.readline
inp,ip = lambda :int(input()),lambda :[int(w) for w in input().split()]
n,k = ip()
x = ip()
x.sort()
if k == 1:
a = x[n//2]
b = x[n//2-1]
else:
s = sum(x)
a = s//n
b = a + 1
sa = sum([abs((a-i)*... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
You have $n$ gifts and you want to give all of them to children. Of course, you don't want to offend anyone, so all gifts should be equal between each other. The $i$-th gift consists of $a_i$ candies and $b_i$ oranges.
During one move, you can ... | ```python
t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ma = min(a)
mb = min(b)
ops = 0
for xa, xb in zip(a, b):
da = xa - ma
db = xb - mb
ops += max(da, db)
print(o... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Harish has decided to go to Arya's hotel this morning. We all know he is crazy for masala dosas. And as usual he is always hungry. He decided to order all the masala dosas at once. But then he realised that he did not have enough money to buy al... | ```python
for _ in range(eval(input())):
n=eval(input())
if n%2:
print('NO')
else:
print('YES')
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
10^{10^{10}} participants, including Takahashi, competed in two programming contests.
In each contest, all participants had distinct ranks from first through 10^{10^{10}}-th.
The score of a participant is the product of his/her ranks in the two ... | ```python
def i1():
return int(input())
def i2():
return [int(i) for i in input().split()]
q=i1()
import math
y=[]
for i in range(q):
y.append(i2())
for a,b in y:
x=a*b
c=int(math.sqrt(x))
if c**2==x:
c-=1
z=2*c
if c>0 and (x//c)==c:
z-=1
if c>0 and x%c==0 and (x//c-1)==c:
z-=1
if a<=c:
z-=1
if... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
You have a string $s$ consisting of $n$ characters. Each character is either 0 or 1.
You can perform operations on the string. Each operation consists of two steps: select an integer $i$ from $1$ to the length of the string $s$, then delete th... | ```python
from itertools import groupby
def main():
N = int(input())
S = input()
C = [len(list(x[1])) for x in groupby(S)]
M = len(C)
dup_idx = []
for i, c in enumerate(C):
if c > 1:
dup_idx.append(i)
dup_idx.reverse()
curr = 0
while dup_idx:
i ... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
ZS the Coder loves mazes. Your job is to create one so that he can play with it. A maze consists of n × m rooms, and the rooms are arranged in n rows (numbered from the top to the bottom starting from 1) and m columns (numbered from the left to ... | ```python
corr = lambda x, y: 1 <= x <= n and 1 <= y <= m
T = int(input())
a = []
while T:
a.append(T % 6)
T //= 6
L = len(a)
n = m = L * 2 + 2
ans = [(1, 2, 2, 2), (2, 1, 2, 2)]
f = [[1] * 9 for i in range(7)]
f[1][2] = f[2][2] = f[2][6] = f[3][5] = 0
f[4][5] = f[4][6] = f[5][2] = f[5][5] = f[5][6] = 0
p = [0... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Polycarp is crazy about round numbers. He especially likes the numbers divisible by 10^{k}.
In the given number of n Polycarp wants to remove the least number of digits to get a number that is divisible by 10^{k}. For example, if k = 3, in the ... | ```python
s = input().split()
k = int(s[1])
s = s[0]
if s.count('0') < k:
if s.count('0') > 0:
print(len(s) - 1)
else:
print(len(s))
return
have = 0
its = 0
for i in range(len(s) - 1, -1, -1):
its += 1
if s[i] == '0':
have += 1
if have == k:
print(its - have)
... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
It's autumn now, the time of the leaf fall.
Sergey likes to collect fallen leaves in autumn. In his city, he can find fallen leaves of maple, oak and poplar. These leaves can be of three different colors: green, yellow or red.
Sergey has collect... | ```python
for t in range(int(input())):
l1=list(map(int,input().split()))
l2=list(map(int,input().split()))
l3=list(map(int,input().split()))
max=0
g=l1[0]+l2[0]+l3[0]
y=l1[1]+l2[1]+l3[1]
r=l1[2]+l2[2]+l3[2]
if g%2==0:
g-=1
if y%2==0:
y-=1
if r%2==0:
r-=1
if max<g:
max=g
if max<r:
... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Slime and his $n$ friends are at a party. Slime has designed a game for his friends to play.
At the beginning of the game, the $i$-th player has $a_i$ biscuits. At each second, Slime will choose a biscuit randomly uniformly among all $a_1 + a_2... | ```python
MOD = 998244353
n = int(input())
a = list(map(int, input().split()))
tot = sum(a)
def inv(x):
return pow(x, MOD - 2, MOD)
l = [0, pow(n, tot, MOD) - 1]
for i in range(1, tot):
aC = i
cC = (n - 1) * (tot - i)
curr = (aC + cC) * l[-1]
curr -= tot * (n - 1)
curr -= aC * l[-2]
cur... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
For her next karate demonstration, Ada will break some bricks.
Ada stacked three bricks on top of each other. Initially, their widths (from top to bottom) are W1,W2,W3.
Ada's strength is S. Whenever she hits a stack of bricks, consider the large... | ```python
T = int(input())
for _ in range(T):
W = list(map(int, input().strip().split()))
S = W[0]
W = W[1:]
W = W[::-1]
i = 0
c = 0
flag = 0
while (len(W) != 0 or flag != 1) and i<len(W):
k = i
su = 0
while su <= S and k<len(W)-1:
su += W[k]
k += 1
if su-W[k-1]<=S:
c += 1
else:
flag = 1
... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
After learning a lot about space exploration, a little girl named Ana wants to change the subject.
Ana is a girl who loves palindromes (string that can be read the same backwards as forward). She has learned how to check for a given string whet... | ```python
#!/usr/bin/env python3
"""
Created on Wed Feb 28 11:47:12 2018
@author: mikolajbinkowski
"""
import sys
N = int(input())
string_count = {}
for _ in range(N):
s = str(input())
char_count = {}
for c in s:
char_count[c] = char_count.get(c, 0) + 1
s0 = []
for a in 'abcdefghijklmnopq... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
The chef is trying to decode 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 cas... | ```python
# cook your dish here
for _ in range(int(input())):
n=int(input())
if n==1:
print("0")
else:
s=[]
for i in range(n):
s.append(str(i))
print(''.join(s))
p=1
for i in range(n-1):
s.pop(n-1)
s=[str(p)]+s
p... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
A new pack of n t-shirts came to a shop. Each of the t-shirts is characterized by three integers p_{i}, a_{i} and b_{i}, where p_{i} is the price of the i-th t-shirt, a_{i} is front color of the i-th t-shirt and b_{i} is back color of the i-th t... | ```python
n = int(input())
p = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
s = []
for i in range(n):
s.append([p[i], a[i], b[i]])
s = sorted(s)
m = int(input())
c = [int(i) for i in input().split()]
idx = [0]*4
ans = []
for i in range(m):
... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Mishka wants to buy some food in the nearby shop. Initially, he has $s$ burles on his card.
Mishka can perform the following operation any number of times (possibly, zero): choose some positive integer number $1 \le x \le s$, buy food that cos... | ```python
import math
from decimal import Decimal
import heapq
import copy
import heapq
from collections import deque
def na():
n = int(input())
b = [int(x) for x in input().split()]
return n,b
def nab():
n = int(input())
b = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]
return n,b,... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.