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:
To make Yalalovichik even more satisfied and happy, Jafar decided to invent Yalalovichik strings. A string is called a Yalalovichik string if the set of all of its distinct non-empty substrings is equal to the set of all of its distinct non-empt... | ```python
for _ in range(int(input())):
n,s = int(input()),input().strip()
previ,num,_s,dic = s[0],0,[],{}
for i in s:
if previ == i:
num+=1
continue
_s.append((previ, num))
if previ not in dic or dic[previ]<num:dic[previ] = num
previ,num = i,1
_s.append((previ, num))
... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Snackdown 2019 is coming! People have started to spread the word and tell other people about the contest.
There are $N$ people numbered $1$ through $N$. Initially, only person $1$ knows about Snackdown. On each day, everyone who already knows ab... | ```python
# cook your dish here
test_case = int(input())
while test_case :
n_people = int(input())
array = list(map(int, input().strip().split()))
sums =[0 for i in range(n_people)]
sums[0] = array[0]
for i in range(1, n_people) :
sums[i] = sums[i-1] + array[i]
# print(sums)
k = 1
count = 0
i = 0
... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Chef hates unoptimized codes and people who write such codes. One fine day he decided to look through the kitchen's codebase and found a function whose pseudo-code is given here:
input: integer N, list X[1, 2, ..., N], list Y[1, 2, ..., N]
out... | ```python
# cook your dish here
for _ in range(int(input())):
d=dict()
ls=[]
for i in range(int(input())):
ls=list(map(int,input().split()))
if ls[0] in d:
d[ls[0]]=max(ls[1],d[ls[0]])
else:
d[ls[0]]=ls[1]
# print(d)
if len(d)<3:
print(0)
else:
kd=list(d.values())
kd.sort()
# print(kd)
print... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Polycarp is reading a book consisting of $n$ pages numbered from $1$ to $n$. Every time he finishes the page with the number divisible by $m$, he writes down the last digit of this page number. For example, if $n=15$ and $m=5$, pages divisible b... | ```python
for _ in range(int(input())):
n, m = list(map(int, input().split()))
A = []
x = 1
while True:
if (m * x) % 10 not in A:
A.append((m * x) % 10)
else:
break
x += 1
s = sum(A)
n //= m
print(s * (n // len(A)) + sum(A[:n % len(A)]))
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
You are given two integer sequences, each of length N: a_1, ..., a_N and b_1, ..., b_N.
There are N^2 ways to choose two integers i and j such that 1 \leq i, j \leq N. For each of these N^2 pairs, we will compute a_i + b_j and write it on a shee... | ```python
#!/usr/bin/env python3
def main():
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ans = 0
for k in range(30):
C = [x & ((1 << (k+1)) - 1) for x in A]
D = [x & ((1 << (k+1)) - 1) for x in B]
C.sort()
D.sort()
... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
There are N bags, each containing two white balls. The i-th box contains two balls with integers x_i and y_i written on them, respectively.
For each of these bags, you will paint one of the balls red, and paint the other blue.
Afterwards, the 2N... | ```python
import sys
def input():
return sys.stdin.readline()[:-1]
n = int(input())
d = []
M, m = 0, 10**30
M_of_m, m_of_M = 0, 10**30
for _ in range(n):
x, y = map(int, input().split())
g, l = max(x, y), min(x, y)
d.append([l, g])
M = max(M, g)
m = min(m, l)
M_of_m = max(M_of_m, l)
m_of_M = min(m_of_M, g)
ans... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
There is a road with length $l$ meters. The start of the road has coordinate $0$, the end of the road has coordinate $l$.
There are two cars, the first standing at the start of the road and the second standing at the end of the road. They will ... | ```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:
You are an evil sorcerer at a round table with $N$ sorcerers (including yourself). You can cast $M$ spells which have distinct powers $p_1, p_2, \ldots, p_M$.
You may perform the following operation any number of times (possibly zero):
- Assign ... | ```python
import functools
def gcd(x,y):
if(y == 0):
return x
return gcd(y, x%y)
for _ in range(int(input())):
n, m= map(int, input().split())
p = list(map(int, input().split()))
ans = functools.reduce(lambda x,y: gcd(x, y), p)
if(ans <= n):
print(n-ans)
else:
f = [1]
for k in range(ans//2, 1, -1):... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
This is a hard version of the problem. In this version, the given array can contain equal elements and the constraints on $n$ are greater than in the easy version of the problem.
You are given an array $a$ of $n$ integers (the given array can c... | ```python
from sys import stdin
for _ in range(int(input())):
n = int(input())
l = list(map(int,input().split()))
id = list(zip(l,list(range(n))))
id.sort()
val, pos = zip(*id)
blok = []
cur = [pos[0]]
for i in range(1,n):
if val[i] == val[i-1]:
cur.append(pos[i])
... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Now that Chef has finished baking and frosting his cupcakes, it's time to package them. Chef has N cupcakes, and needs to decide how many cupcakes to place in each package. Each package must contain the same number of cupcakes. Chef will choose ... | ```python
for i in range(int(input())):
n=int(input())
print(n//2+1)
``` | |
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, ..., a_{n} consisting of different integers. It is required to split this sequence into the maximum number of subsequences such that after sorting integers in each of them in increasing order, the total sequenc... | ```python
import sys
#sys.stdin=open("data.txt")
input=sys.stdin.readline
n=int(input())
b=list(map(int,input().split()))
bb=sorted(b)
c={bb[i]:i for i in range(n)}
a=[c[b[i]] for i in range(n)]
vis=[0]*n
out=[]
for i in range(n):
if vis[i]: continue
vis[i]=1
newlist=[i]
while a[newlist[-1]]!=i:
... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
You are given a permutation of 1,2,...,N: p_1,p_2,...,p_N. Determine if the state where p_i=i for every i can be reached by performing the following operation any number of times:
- Choose three elements p_{i-1},p_{i},p_{i+1} (2\leq i\leq N-1) ... | ```python
import sys
def solve(ppp):
section_start = -1
moved_left_max = 0
moved_right_max = 0
prev = True
for i, p in enumerate(ppp, start=1):
if i == p:
if prev:
moved_left_max = 0
moved_right_max = 0
section_start = -1
... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Walter White and Jesse Pinkman (a drug addict) both love to play with chemicals. One day they were playing with some chemicals to make an energy drink. Unknowingly they made a highly powerful drink. To test the drink on others also they called s... | ```python
# cook your dish here
l1=int(input())
for i in range(l1):
x=int(input())
y=list(map(int,input().split()))
z=list(map(int,input().split()))
if max(z)!=max(y):
print('YES')
else:
print('NO')
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
On each of the following $N$ days (numbered $1$ through $N$), Chef is planning to cook either pizza or broccoli. He wrote down a string $A$ with length $N$, where for each valid $i$, if the character $A_i$ is '1', then he will cook pizza on the ... | ```python
for _ in range(int(input())):
n, k = map(int, input().split())
l = [*map(int, input())]
count = [0] * (n + 1)
for i in range(n - 1, -1, -1):
if l[i] == 1:
count[i] = count[i + 1] + 1
x,y = 0,0
for i in range(n):
if l[i] == 1:
x += 1
else:
try:
y = max(y, x + k + count[i + k])
... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Devu loves to play with binary strings a lot. One day he borrowed a binary string s of size n from his friend Churu. Before starting to play with it, he wants to make sure that string does not contain more than k consecutive equal characters. F... | ```python
T= int(input());
for i in range(T):
n,k = list(map(int,input().split()));
s=list(map(int,input()));
if k==1:
s_0 ={};
s_1={};
c0=0;
c1=0;
for j in range(n):
if(j%2==0):
s_1[j]=1;
s_0[j]=0;
else:
s_1[j]=0;
s_0[j]=1;
for j in range(n):
if(s_0[j]-s[j]!=0):
c0+=1;
... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
You are given an array consisting of n non-negative integers a_1, a_2, ..., a_{n}.
You are going to destroy integers in the array one by one. Thus, you are given the permutation of integers from 1 to n defining the order elements of the array a... | ```python
__author__ = 'Think'
n=int(input())
aints=[int(i) for i in input().split()]
permutes=[int(i)-1 for i in input().split()]
results=[0]
rebuilt={}
m=0
for numby in range(n-1, 0, -1):
p=permutes[numby]
below=False
above=False
if p-1 in rebuilt:
below=True
if p+1 in rebuilt:
above=True
if above and belo... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Anna Hazare is a well known social activist in India.
On 5th April, 2011 he started "Lokpal Bill movement".
Chef is very excited about this movement. He is thinking of contributing to it. He gathers his cook-herd and starts thinking about how ... | ```python
from collections import deque
from sys import stdin
import psyco
psyco.full()
graph = [[]]
WHITE, GRAY, BLACK = 0, 1, 2
def notoriety(x, f_count):
queue = deque([x])
d = [0 for i in range(f_count+1)]
p = [0 for i in range(f_count+1)]
color = [WHITE for i in range(f_count+1)]
while len(qu... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
In Snakeland, there are some snakes and mongooses. They are lined up in a row. The information about how exactly they are lined up it is provided to you by a string of length n. If the i-th character of this string is 's', then it means that the... | ```python
for i in range(int(input())):
a=input()
c=a.count('m')
d=a.count('s')
t=0
while t<len(a)-1:
if (a[t]=='m' and a[t+1]=='s') or (a[t]=='s' and a[t+1]=='m'):
d=d-1
t=t+2
else:
t=t+1
if c>d:
print('mongooses')
elif d>c:
print('snakes')
else:
print('tie')
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
A despotic king decided that his kingdom needed to be rid of corruption and disparity. He called his prime minister and ordered that all corrupt citizens be put to death. Moreover, he wanted this done quickly.
The wily prime minister realised th... | ```python
n,m=map(int,input().split())
l=[]
leng=0
for i in range(n+m):
w=int(input())
if w==-1:
cm=0
mi=0
for j in range(leng):
if l[j]>cm:
cm=l[j]
mi=j
print(cm)
l[mi]=-1
else:
l.append(w)
... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
You were strolling outside the restaurant at the end of the universe. On a metaspiral path you stumble upon a weird device which takes a three-digit number as input and processes it. The Hitchhiker's guide to the galaxy explains that it processe... | ```python
for _ in range(int(input())):
k, n = input().split()
while int(n) >= 5:
print(len(set(k)) ** 3)
break
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
A simple string contains a large repetition of letters within it. This problem is related to string handling and manipulation. An original message is sent from planet Earth to planet Cybertron in form of a string. However, the letter position a... | ```python
import sys,math
def main(filename):
inputfile = open(filename,'rU')
data = inputfile.readlines()
T=data.pop(0)
ans=[]
ansstring=str()
explored=[]
for i in T:
if i in explored:
#print explored
for j in range(len(ans)):
if ans[j][0]==i:
ans[j][1] += 1
else:
ans.append([i,1])
exp... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Chef has an array of N natural numbers. Cheffina challenges the chef to choose the two numbers from the array and following the condition as the area of the rectangle formed from the two numbers is maximum. Cheffina also asks the chef to choose ... | ```python
import sys
import math
import bisect
from sys import stdin,stdout
from math import gcd,floor,sqrt,log
from collections import defaultdict as dd
from bisect import bisect_left as bl,bisect_right as br
sys.setrecursionlimit(100000000)
ii =lambda: int(input())
si =lambda: input()
jn =la... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Tracy loves Donuts. She purchased a lots of Donuts for her birthday party. She learnt to calculate the area of the circle a few days back and she is fascinated to know the area of the donuts as well !! Help her finding the area of the Donuts…..
... | ```python
oo = int(input())
for i in range(oo):
val = int(input())
print((val**2)*3.14)
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Little Petya likes points a lot. Recently his mom has presented him n points lying on the line OX. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed d... | ```python
def Search(L,aa,x):
a=aa
b=len(L)
while(b-a>1):
i=(b+a)//2
if(L[i]>x):
b=i
elif(L[i]<x):
a=i
else:
return (i+1)-aa-1
return b-aa-1
import math
n,d=list(map(int,input().split()))
P=list(map(int,input().split()))
ans=0
for i ... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
$Neha$ is given a number $N$. She always looks for special thing , this time she is looking for $Special$ $Number$ and $Partial$ $Special$ $Number$. A $Special$ $Number$ is a number whose product of its digits is equal to number itself i.e. $N ... | ```python
n=int(input())
a=[]
b=[]
for i in range(1,1000001):
s = str(i)
p=1
flag=0
for e in s:
if e=='1':
flag=1
p=p*int(e)
if p==n:
if flag!=1:
a.append(i)
else:
b.append(i)
print(len(a),len(b))
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Alice and Bob created $N$ and $M$ recipes, respectively ($N, M \ge 1$), and submitted them to Chef for evaluation. Each recipe is represented by a string containing only lowercase English letters. Let's denote Alice's recipes by $A_1, A_2, \ldot... | ```python
# v = ["a","e","i","o","u"]
# for _ in range(int(input())):
# n = int(input())
# a,b = [],[]
# for i in range(n):
# s = input()
# isa = True
# for j in range(1,len(s) - 1):
# if(s[j] in v):
# if(s[j - 1] not in v and s[j + 1] not in v):
# isa =... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Bessie has way too many friends because she is everyone's favorite cow! Her new friend Rabbit is trying to hop over so they can play!
More specifically, he wants to get from $(0,0)$ to $(x,0)$ by making multiple hops. He is only willing to hop... | ```python
import sys
#sys.stdin=open("data.txt")
input=sys.stdin.readline
mii=lambda:list(map(int,input().split()))
for _ in range(int(input())):
n,x=mii()
has=0
a=0
for i in mii():
if x==i: has=1
a=max(a,i)
if has:
print(1)
else:
print(max(2,(x-1)//a+1))
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Kajaria has an empty bag and 2 types of tiles -
tiles of type $1$ have the number $X$ written and those of type $2$ have the number $Y$ written on them. He has an infinite supply of both type of tiles.
In one move, Kajaria adds exactly $1$ tile... | ```python
# cook your dish here
t=int(input())
MOD=1000000007
def mod(n, m=MOD):
n%=m
while n<0: n+=m
return n
def power(n, p):
res=1
while p:
if p%2: res=mod(res*n)
p//=2
n=mod(n*n)
return res
while t:
ma=input().split()
x=int(ma[0])
y=int(ma[1])
s=int(ma[2])
ma=input().split()
u=int(ma[0])
v=int(... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
A squarer is a simple and convenient device. You give it some positive integer X and it calculates its square.
Leha is implementing a module of this device which is responsible for squaring the numbers consisting of multiple repetitions of one d... | ```python
val = 10**9 + 7
def MOD(a,b):
aans = a
ans = 1
while b>0:
ans = (ans*aans)%val
aans = (aans*aans)%val
b/=2
return ans%val
for i in range(eval(input())):
n,d= list(map(int,input().split()))
a=int(str(d)*n)
sqr = str(a*a)
ans =0
count=0
for ii in sqr :
ans= ans+int(ii)*23**count
coun... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim.
The killer starts with two po... | ```python
import sys
s1, s2 = input().split()
n = int(input())
for _ in range(n):
print(s1, s2)
killed, new = input().split()
if s1 == killed:
s1 = new
else:
s2 = new
print(s1, s2)
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Initially, you have the array $a$ consisting of one element $1$ ($a = [1]$).
In one move, you can do one of the following things:
Increase some (single) element of $a$ by $1$ (choose some $i$ from $1$ to the current length of $a$ and increas... | ```python
import math
for _ in range(int(input())):
n=int(input())
if n==1:
print(0)
else:
k=int(n**(0.5))
if k*k<n:
k+=1
# print(n,k)
ans=k-1
if k*(k-1)>=n:
ans+=(k-2)
else:
ans+=(k-1)
print(ans)
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
You are given an array $a_1, a_2 \dots a_n$. Calculate the number of tuples $(i, j, k, l)$ such that: $1 \le i < j < k < l \le n$; $a_i = a_k$ and $a_j = a_l$;
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 100... | ```python
class BIT():
def __init__(self,n):
self.BIT=[0]*(n+1)
self.num=n
def query(self,idx):
res_sum = 0
while idx > 0:
res_sum += self.BIT[idx]
idx -= idx&(-idx)
return res_sum
#Ai += x O(logN)
def update(self,idx,x):
while id... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Chef Shifu wanted to celebrate the success of his new restaurant with all his employees. He was willing to host a party and he had decided the location of the party as well. However, Chef Shifu was a shy person and wanted to communicate with the... | ```python
t=int(input())
for _ in range(t):
n,m=map(int,input().split())
mat=[0 for i in range(n)]
#mat=[[0 for i in range(n)] for j in range(n)]
for i in range(m):
u,v=map(int,input().split())
u,v=(u-1),(v-1)
mat[u]|=(1<<v)
mat[v]|=(1<<u)
for i in range(n):
mat[i]|=(1<<i) ... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Given a set of N natural numbers 1,2,3........N and Q query.For each query you have to calculate the total number of subset in which Ith.
number of set come at Kth postion.Elements of every subset should be in sorted order.
The answer could ... | ```python
import math
f = math.factorial
for u in range(eval(input())):
n, q = list(map(int, input().split()))
for j in range(q):
i,k = list(map(int, input().split()))
if k>i:
c=0
print(c)
else:
a=2**(n-i)
b=1
d=int(i-1)
e=1
h=1
g=1
#b=f(i-1)/f(k-1)/f(i-k)
if(k-1>i-k):
for z in... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
A permutation p of size n is the sequence p_1, p_2, ..., p_{n}, consisting of n distinct integers, each of them is from 1 to n (1 ≤ p_{i} ≤ n).
A lucky permutation is such permutation p, that any integer i (1 ≤ i ≤ n) meets this condition p_{p}... | ```python
n = int(input())
if n%4 > 1:
print(-1)
else:
a = [n+1>>1]*n
for i in range(n//4):
j = i*2
a[j], a[j+1], a[-2-j], a[-1-j] = j+2, n-j, j+1, n-1-j
print(' '.join(map(str, a)))
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Now that Heidi has made sure her Zombie Contamination level checker works, it's time to strike! This time, the zombie lair is a strictly convex polygon on the lattice. Each vertex of the polygon occupies a point on the lattice. For each cell of ... | ```python
import math
def lexComp(a, b):
if a[0] != b[0]:
return -1 if a[0] < b[0] else 1
if a[1] != b[1]:
return -1 if a[1] < b[1] else 1
return 0
def turn(a, b, c):
return (b[0] - a[0]) * (c[1] - b[1]) - (b[1] - a[1]) * (c[0] - b[0])
def dist2(a, b):
return (a[0] - b[0]) ** ... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Pankaj likes to eat Ice cream when he is working late into the night. Today has been yet another long day for Pankaj. So, he wants to eat ice cream now. He opens the fridge and sees that he has 2 types of containers holding the ice cream.
The fi... | ```python
import math
t=eval(input())
while t:
t=t-1
r1,h1,r2,h2=list(map(float,input().split()))
vol1=(math.pi*r1*r1*h1)/3 + (2*math.pi*r1*r1*r1)/3
vol2=math.pi*r2*r2*h2
print("%.8f %.8f" % (vol1,vol2))
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Permutation p is an ordered set of integers p_1, p_2, ..., p_{n}, consisting of n distinct positive integers not larger than n. We'll denote as n the length of permutation p_1, p_2, ..., p_{n}.
Your task is to find such permutation ... | ```python
3
import sys
def __starting_point():
n, k = list(map(int, sys.stdin.readline().split()))
l = []
i = 1
j = k + 1
while i <= j:
l.append(str(i))
i += 1
if j > i:
l.append(str(j))
j -= 1
for i in range(k+2, n+1):
l.append(str(... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Nobody outside the cooking community knows that Chef is a big fan of Chefgram™ — a social network where chefs and cooks upload their secret kitchen photos.
Recently Chef clicked a beautiful photo, which is represented using 10 pixels in a single... | ```python
import itertools
import numpy as np
b = np.zeros((100001), dtype=np.int)
def power2(a):
b[0] = 1
if b[a] > 0:
return b[a]
else:
for i in range(1,a+1):
b[i] = b[i-1]*2
if b[i] > (10**9+7):
b[i] = b[i]%(10**9+7)
return b[a]
def __starting_point():
t = eval(input())
for i in range(t):
s... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
You are given two positive integers $A$ and $B$. Find the number of pairs of positive integers $(X, Y)$ such that $1 \le X \le A$, $1 \le Y \le B$ and $X + Y$ is even.
-----Input-----
- The first line of the input contains a single integer $T$ ... | ```python
try:
t=int(input())
while t>0:
[a,b]=[int(x) for x in input().split()]
if a==1 and b==1:
print(1)
continue
if a%2==0:
o1=a//2
e1=a//2
else:
o1=a//2+1
e1=a//2
if b%2==0:
o2=b//2
e2=b//2
else:
o2=b//2+1
e2=b//2
print(e1*e2+o1*o2)
t-=1
except:
pass
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Tavak and Seyyed are good friends. Seyyed is very funny and he told Tavak to solve the following problem instead of longest-path.
You are given l and r. For all integers from l to r, inclusive, we wrote down all of their integer divisors except... | ```python
l,r = map(int, input().split(" "))
if l == r:
print (l)
else:
print (2)
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Nitika was once reading a history book and wanted to analyze it. So she asked her brother to create a list of names of the various famous personalities in the book. Her brother gave Nitika the list. Nitika was furious when she saw the list. The ... | ```python
# cook your dish here
x= int(input())
for i in range(x):
y = list(map(str, input().split()))
j= 0
while j<len(y)-1:
print((y[j][0]).capitalize()+".", end=' ')
j+= 1
print(y[len(y)-1].capitalize())
``` | |
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 cases... | ```python
try:
for _ in range(int(input())):
k=int(input())
for i in range(1,k+1):
print(" "*(k-i),end="")
if i%2==1:
for j in range(0,i):
print(chr(65+j),end="")
else:
for j in range(0,i):
print(j+1,end="")
print()
except:
pass
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Polycarp wants to assemble his own keyboard. Layouts with multiple rows are too complicated for him — his keyboard will consist of only one row, where all $26$ lowercase Latin letters will be arranged in some order.
Polycarp uses the same passw... | ```python
T = int(input())
def solve(S):
res = [S[0]]
pos = 0 # think...
for s in S[1:]:
# can we change?
if 0 <= pos-1 < len(res) and res[pos-1] == s:
pos = pos-1
elif 0 <= pos+1 < len(res) and res[pos+1] == s:
pos = pos+1
elif pos == 0 and s not i... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Mikhail walks on a Cartesian plane. He starts at the point $(0, 0)$, and in one move he can go to any of eight adjacent points. For example, if Mikhail is currently at the point $(0, 0)$, he can go to any of the following points in one move: $... | ```python
q=int(input())
for e in range(q):
x,y,k=list(map(int,input().split()))
x,y=abs(x),abs(y)
x,y=max(x,y),min(x,y)
if(x%2!=k%2):
k-=1
y-=1
if(x>k):
print(-1)
continue
if((x-y)%2):
k-=1
x-=1
print(k)
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Chef recently opened a big e-commerce website where her recipes can be bought online. It's Chef's birthday month and so she has decided to organize a big sale in which grand discounts will be provided.
In this sale, suppose a recipe should have ... | ```python
for i in range(int(input())):
n=int(input())
s=0
for i in range(n):
a,b,c=map(int,input().split())
d=(c/100)*a
e=a+d
f=e-((c/100)*e)
g=a-f
h=b*g
s=s+h
print(s)
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
You are given a weighted undirected graph consisting of n$n$ nodes and m$m$ edges. The nodes are numbered from 1$1$ to n$n$. The graph does not contain any multiple edges or self loops.
A walk W$W$ on the graph is a sequence of vertices (with re... | ```python
# cook your dish here
from collections import defaultdict
class sol():
def __init__(self,n,edges):
self.n = n
self.edges = edges
self.graph = self.create_graph()
self.precompute()
def create_graph(self):
graph = defaultdict(list)
for e in self.... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Write a program to obtain a number $N$ and increment its value by 1 if the number is divisible by 4 $otherwise$ decrement its value by 1.
-----Input:-----
- First line will contain a number $N$.
-----Output:-----
Output a single line, the new ... | ```python
# cook your dish here
n = int(input())
if(n%4==0):
print(n+1)
else:
print(n-1)
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Chef is playing with an expression which consists of integer operands and the following binary
Bitwise operators - AND, OR and XOR. He is trying to figure out that what could be the Maximum possible answer of the expression, given that he can p... | ```python
# cook your dish here
def value(a, b, c):
if(c == '&'):
return a&b
elif(c == '^'):
return a^b
elif(c == '|'):
return a|b
def break_rules(n, operator):
if(len(n) == 1):
return n
elif(len(n) == 2):
return [value(n[0], n[1], operator[0])]
else:
... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Today Chef wants to evaluate the dishes of his $N$ students. He asks each one to cook a dish and present it to him.
Chef loves his secret ingredient, and only likes dishes with at least $X$ grams of it.
Given $N$, $X$ and the amount of secret in... | ```python
t=int(input())
for i in range(t):
n,k=map(int,input().split())
m=list(map(int,input().split()))
a=0
for i in m:
if i>=k:
a=1
break
if a==1:
print('YES')
else:
print('NO')
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Daniel is organizing a football tournament. He has come up with the following tournament format: In the first several (possibly zero) stages, while the number of teams is even, they split in pairs and play one game for each pair. At each stage... | ```python
n = int(input())
res = set()
for r in range(100):
a = 1
b = 2**(r + 1) - 3
c = -2 * n
d = b * b - 4 * a * c
if d < 0:
continue
le = 0
ri = d
while le < ri:
c = (le + ri) // 2
if c * c < d:
le = c + 1
else:
ri = c
if le... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
There are $n$ startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An... | ```python
m = 1000000007
n = int(input())
a = list(map(int, input().split()))
print(pow(2,n-1,m)-1 - sum(pow(2,a.count(x),m)-1 for x in set(a) if x != -1) % m)
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Recently Vasya learned that, given two points with different $x$ coordinates, you can draw through them exactly one parabola with equation of type $y = x^2 + bx + c$, where $b$ and $c$ are reals. Let's call such a parabola an $U$-shaped one.
Va... | ```python
n = int(input())
rows = [input().split() for _ in range(n)]
rows = [(int(x),int(y)) for x,y in rows]
points = {}
for x,y in rows:
if x in points:
points[x] = max(y, points[x])
else:
points[x] = y
points = sorted(points.items(),key=lambda point: point[0])
def above(p,p1,p2):
"""
... | |
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.
In one move, you can choose some index $i$ ($1 \le i \le n - 2$) and shift the segment $[a_i, a_{i + 1}, a_{i + 2}]$ cyclically to the right (i.e. replace the segment $[a_i, a_{i + 1}, a_{i... | ```python
t = int(input())
for _ in range(t):
n = int(input())
l = list([int(x)- 1 for x in input().split()])
out = []
ll = [(l[i], i) for i in range(n)]
ll.sort()
swap = (-1,-1)
for i in range(n - 1):
if ll[i][0] == ll[i + 1][0]:
swap = (ll[i][1],ll[i+1][1])
newl ... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Two words rhyme if their last 3 letters are a match. Given N words, print the test case number (of the format Case : num) followed by the rhyming words in separate line adjacent to each other.
The output can be in anyorder.
-----Input-----
Fir... | ```python
t = int(input())
for i in range(t):
n = int(input())
suffixes = {}
xx = input().split()
for x in range(n):
try:
a = suffixes[xx[x][-3:]]
except Exception as e:
a = []
a.append(xx[x])
suffixes.update({xx[x][-3:]: a})
print("Case : %d" % (i + 1))
for a in sorted(suffixes):
print("".join(... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Chef is planning a huge party for all of you and has ordered M pizzas. He wants to invite as many people to the party. However, he knows that everyone will have exactly one slice of a pizza (regardless of the size) and he wants to make sure that... | ```python
# cook your dish here
m,n=[int(i) for i in input().split()]
arr=list(map(int,input().split()))
arr=sorted(arr,reverse=True)
ans=0
w=0
q=m
for m in range(q):
if(arr[m]>n):
w=1
break
ans+=1+(arr[m]*(arr[m]+1))//2
n-=arr[m]
if(n==0):
print(ans)
else:
if(w==1... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Given an alphanumeric string made up of digits and lower case Latin characters only, find the sum of all the digit characters in the string.
-----Input-----
- The first line of the input contains an integer T denoting the number of test cases. ... | ```python
for _ in range(eval(input())):
s = input()
ans = 0
for i in s:
if i.isdigit():
ans += int(i)
print(ans)
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Chef is baking a cake.
While baking, in each minute the size of cake doubles as compared to its previous size.
In this cake, baking of cake is directly proportional to its size.
You are given $a$, the total time taken(in minutes) to bake the w... | ```python
# cook your dish here
for _ in range(int(input())):
a=int(input())
print(a/2+2)
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Catherine received an array of integers as a gift for March 8. Eventually she grew bored with it, and she started calculated various useless characteristics for it. She succeeded to do it for each one she came up with. But when she came up with ... | ```python
import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
b = a
ans = 0
for k in range(29):
a0 = []
a1 = []
a0a = a0.append
a1a = a1.append
b0 = []
b1 = []
b0a = b0.append
b1a = b1.append
for i in a:
if i&(1<<k): a1a(i)
... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
The Government of Siruseri is no different from any other when it comes to being "capital-centric" in its policies. Recently the government decided to set up a nationwide fiber-optic network to take Siruseri into the digital age. And as usual, t... | ```python
n=int(input())
l=[]
for i in range(n):
l.append([int(x) for x in input().split()])
d=[10**9]*(n)
q=set([int(x) for x in range(1,n)])
d[1]=0
#print(q)
def extract():
mini=10**9
o=0
for i in range(1,len(d)):
if d[i]<mini and i in q:
mini=d[i]
o=i
q.remove(o)
return o
while len(q)!... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Chef and his best friend Aleksa are into mathematical games these days. Today, they have some ( ≥ 0 ) black cells represented as B, and a white cell represented as W, lying randomly in a straight line.
They have decided to play with these cells.... | ```python
t =int(input()) #no. of test cases
while t>0:
t=t-1
str=input()
size=len(str)
pos=str.find('W')
left=pos
right=size-pos-1
arr = [[0 for i in range(right+1)] for j in range(left+1)]
#arr[i,j] = 1 if with i black cells on left and j on right 1st player can win, 0 otherwise.
#Recursion: arr[i][j... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
You're given an integer N. Write a program to calculate the sum of all the digits of N.
-----Input-----
The first line contains an integer T, the total number of testcases. Then follow T lines, each line contains an integer N.
-----Output--... | ```python
# cook your dish here
number = int(input())
for i in range(number):
a = list(input())
for k in range(len(a)):
a[k] = eval(a[k])
print(sum(a))
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
You are given an array with $N$ integers: $A[1], A[2], \ldots, A[N]$ (where $N$ is even). You are allowed to permute the elements however you want. Say, after permuting the elements, you end up with the array $A'[1], A'[2], \ldots, A'[N]$. Your ... | ```python
for i in range(int(input())):
n=int(input())
m=list(map(int,input().split()))[:n]
m.sort()
t=0
for j in range(n//2):
t+=abs(m[j]-m[n-j-1])
print(t)
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Vasya claims that he had a paper square. He cut it into two rectangular parts using one vertical or horizontal cut. Then Vasya informed you the dimensions of these two rectangular parts. You need to check whether Vasya originally had a square. I... | ```python
for _ in range(int(input())):
a1, b1 = list(map(int, input().split()))
a2, b2 = list(map(int, input().split()))
if a1 > b1:
a1, b1 = b1, a1
if a2 > b2:
a2, b2 = b2, a2
flag = False
if a1 == a2 and a1 == b1 + b2:
flag = True
if b1 == b2 and b1 == a1 + a2:
... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Well known investigative reporter Kim "Sherlock'' Bumjun needs your help! Today, his mission is to sabotage the operations of the evil JSA. If the JSA is allowed to succeed, they will use the combined power of the WQS binary search and the UFDS ... | ```python
n=int(input())
def do():
t=int(input())
x=[]
for i in range(t):
x.append(int(input()))
print(max(x))
return
for i in range(n):
do()
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Accepts a string from the user and print the reverse string as the output without using any built-in function.
-----Input:-----
Each testcase contains of a single line of input, a string.
-----Output:-----
For each testcase, output in a single... | ```python
oo = int(input())
for i in range(oo):
val = input()
print(val[::-1])
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Bobby has decided to hunt some Parrots. There are n horizontal branch of trees aligned parallel to each other. Branches are numbered 1 to n from top to bottom. On each branch there are some parrots sitting next to each other. Supposed there are ... | ```python
n = int(input())
x = [int(i) for i in input().split()]
m = int(input())
for i in range(m):
a,b = map(int,input().split())
a -= 1
t = b-1
t1 = x[a]-b
if a-1>=0:
x[a-1] += t
if a+1<n:
x[a+1] += t1
x[a] = 0
for i in x:
print(i)
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
You are given a tree (connected graph without cycles) consisting of $n$ vertices. The tree is unrooted — it is just a connected undirected graph without cycles.
In one move, you can choose exactly $k$ leaves (leaf is such a vertex that is conne... | ```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
M = mod = 998244353
def factors(n):return sorted(set(reduce(list.__add__, ([... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Polygon is not only the best platform for developing problems but also a square matrix with side $n$, initially filled with the character 0.
On the polygon, military training was held. The soldiers placed a cannon above each cell in the first r... | ```python
def read_int():
return int(input())
def read_ints():
return list(map(int, input().split(' ')))
t = read_int()
for case_num in range(t):
n = read_int()
mat = []
for i in range(n):
mat.append(input())
ok = True
for i in range(n):
for j in range(n):
if ... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
The Siruseri amusement park has a new attraction. It consists of a rectangular array of discs. Each disc is divided into four equal sectors and the four sectors are coloured with the colours Red, Blue, Green and Yellow (in some order). The order... | ```python
#for _ in range(int(input()):
#n,m = map(int,input().split())
#x = [int(w) for w in input().split()]
#n = int(input())
#x = [int(input()) for _ in range(n)]
#for i in range(n):
#dt = {} for i in x:dt[i] = dt.get(i,0)+1
#dt = {k:v for k,v in sorted(x.items(), key=lambda i: i[1])}
m,n = map(int,input().split()... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Mr. Pr and Ms. Ad are at $a$ and $b$ respectively on an infinite number line. Mr. Pr wants to meet Ms. Ad.
Mr. Pr can choose to move $c$ or $d$ units in 1 second. If Mr. Pr moves $c$ units then Ms. Ad will move $d$ units and vice versa. (Both o... | ```python
for _ in range(int(input())):
a,b,c,d=list(map(int,input().split()))
if(a==b):
print('YES')
elif(c==d):
print('NO')
else:
if(abs(a-b)%abs(c-d)==0):
print('YES')
else:
print('NO')
``` | |
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$. You have to split the array into maximum number of non-empty subarrays such that the gcd of elements of each subarray is equal to 1.
-----Input:-----
- The first line of the input contains a sin... | ```python
'''input
2
3
2 2 3
4
2 3 3 2
'''
import math
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
count = 0
i = 0
while i < len(a):
if a[i] == 1:
count += 1
i += 1
continue
curr_gcd = a[i]
while i < len(a) and curr_gcd != 1:
curr_gcd = math.gcd(curr_gcd, a... | |
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
try:
tc=int(input())
for _ in range(tc):
n=int(input())
st=""
b=1
for i in range(1,n+1):
b+=1
a=b
for j in range(1,n+1):
print(a,end='')
a+=1
print()
except:
pass
`... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
You are given two integers $N$ and $M$. Find the number of sequences $A_1, A_2, \ldots, A_N$, where each element is an integer between $1$ and $M$ (inclusive) and no three consecutive elements are equal. Since this number could be very large, co... | ```python
import sys
def fin(): return sys.stdin.readline().strip()
def fout(s, end="\n"): sys.stdout.write(str(s)+end)
MOD = pow(10, 9)+7
t = int(input())
while t>0:
t -= 1
n, m = list(map(int, fin().split()))
if n == 1:
print(m%MOD)
continue
dp1 = m*(m-1)
dp2 = m
for i in range(3, n+1):
temp = dp2
dp2 ... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Chef just got a box of chocolates as his birthday gift. The box contains $N$ chocolates in a row (numbered $1$ through $N$), where $N$ is even. For each valid $i$, the $i$-th chocolate has a sweetness value $W_i$.
Chef wants to eat all the choco... | ```python
from collections import deque
t=int(input())
for i in range(t):
n=int(input())
N=[i for i in range(1, n+1)]
w=list(map(int, input().split()))
max_sweetness=max(w)
sizes=[]
cnt=0
for i in range(n):
if w[i]!=max_sweetness:
cnt+= 1
else:
sizes.append(cnt)
cnt=0
if cnt!=0:
sizes[0]=(cnt... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Chefina has two sequences $A_1, A_2, \ldots, A_N$ and $B_1, B_2, \ldots, B_N$. She views two sequences with length $N$ as identical if, after they are sorted in non-decreasing order, the $i$-th element of one sequence is equal to the $i$-th elem... | ```python
from collections import Counter
tc=int(input())
for k in range(tc):
n=int(input())
a=list(map(int, input().rstrip().split()))
b= list(map(int, input().rstrip().split()))
cc=sorted(a+b)
#print('cc = ',cc)
p=[]
q=[]
#print('len(cc) = ',len(cc))
#print('len = ',(2*n))
#rx=0
for i in range(0,(2*n),2):
... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Polycarp takes part in a math show. He is given n tasks, each consists of k subtasks, numbered 1 through k. It takes him t_{j} minutes to solve the j-th subtask of any task. Thus, time required to solve a subtask depends only on its index, but n... | ```python
n, k, m = list(map(int, input().split()))
l = list(map(int, input().split()))
l.sort()
s = sum(l)
ans = 0
for i in range(n + 1):
mi = m - s * i
if mi < 0:
break
cnt = (k + 1) * i
for j in range(k):
x = min(mi // l[j], n - i)
cnt += x
mi -= l[j] * x
ans = ma... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
You are given a set of size $m$ with integer elements between $0$ and $2^{n}-1$ inclusive. Let's build an undirected graph on these integers in the following way: connect two integers $x$ and $y$ with an edge if and only if $x \& y = 0$. Here $\... | ```python
n, m = map(int, input().split())
a = set(map(int, input().split()))
y = 2 ** n
mk = [0] * (2 * y)
cur = 0
for x in a:
if mk[x]: continue
mk[x] = 1
st = [x]
while st:
u = st.pop()
if u < y:
if not mk[y + u]:
mk[y + u] = 1
st.append(y... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Alice lives on a line. Today, she will travel to some place in a mysterious vehicle.
Initially, the distance between Alice and her destination is D. When she input a number x to the vehicle, it will travel in the direction of the destination by ... | ```python
n, d = list(map(int, input().split()))
D = list(map(int, input().split()))
A = [0]*(n+1)
P = [0]*(n+1)
P[0] = pos = d
for i, x in enumerate(D):
if x <= 2*pos:
pos = abs(x-pos)
P[i+1] = pos
if pos == 0:
break
for i in range(n-1, -1, -1):
if D[i] <= 2*A[i+1]+1:
A[i] = A... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Today, puppy Tuzik is going to a new dog cinema. He has already left his home and just realised that he forgot his dog-collar! This is a real problem because the city is filled with catchers looking for stray dogs.
A city where Tuzik lives in ca... | ```python
# cook your dish here
from sys import stdin,stdout
a,b=list(map(int,stdin.readline().split()))
left=[]
top=[]
for i in range(a):
c,d=list(map(int,stdin.readline().split()))
left.append(c)
top.append(d)
left.sort()
top.sort()
from bisect import bisect_right as br
from bisect import bisect_left as bl
row=0
c... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
These days, chef is very much interested in Mathematics. He has started attending Recitations too! His hunger for problems is increasing day by day!
Today, chef was a given a crumpled maths problem, which he is stuck with . He needs your help to... | ```python
testCases = int(input())
for c in range(testCases):
n, k = list(map(int, input().split()))
sum = 0
i = 0
power = 1
while i <= n:
if k**power == i:
power += 1
else:
sum += i
i +=1
answer = "Case #" + str(c + 1) + ": " + str(sum)
print(answer)
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
There is an infinitely long street that runs west to east, which we consider as a number line.
There are N roadworks scheduled on this street.
The i-th roadwork blocks the point at coordinate X_i from time S_i - 0.5 to time T_i - 0.5.
Q people a... | ```python
from heapq import heapify, heappush, heappop
import sys
input = sys.stdin.readline
def solve():
N, Q = list(map(int, input().split()))
events = []
for i in range(N):
S, T, X = list(map(int, input().split()))
events.append((S-X-0.5, 1, X))
events.append((T-X-0.5, 0, X))
... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
The faculty of application management and consulting services (FAMCS) of the Berland State University (BSU) has always been popular among Berland's enrollees. This year, N students attended the entrance exams, but no more than K will enter the u... | ```python
# cook your dish here
t=int(input())
for i in range(t):
(n,k,e,m)=tuple(map(int,input().split()))
scores=[]
for j in range(n-1):
scores.append(sum(list(map(int,input().split()))))
scores.sort(reverse=True);
bsc=scores[k-1];
msc=sum(list(map(int,input().split())))
mini=bsc-msc+1
if(mini<0):
print(0... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
You are playing a variation of game 2048. Initially you have a multiset $s$ of $n$ integers. Every integer in this multiset is a power of two.
You may perform any number (possibly, zero) operations with this multiset.
During each operation yo... | ```python
for i in range(int(input())):
n=int(input())
s=list(map(int,input().split()))
a=0
for i in s:
if i<2049:a+=i
if a<2048:print("NO")
else:print("YES")
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Chef is good at making pancakes. Generally he gets requests to serve N pancakes at once.
He serves them in the form of a stack.
A pancake can be treated as a circular disk with some radius.
Chef needs to take care that when he places a pancake o... | ```python
t=[[1]]
def bell_numbers(start, stop):
## Swap start and stop if start > stop
if stop < start: start, stop = stop, start
if start < 1: start = 1
if stop < 1: stop = 1
c = 1 ## Bell numbers count
while c <= stop:
if c >= start:
yield t[-1][0] ## Yield the Bell number of the previous ... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Mandarin chinese
, Russian and Vietnamese as well.
Let's denote $S(x)$ by the sum of prime numbers that divides $x$.
You are given an array $a_1, a_2, \ldots, a_n$ of $n$ numbers, find the number of pairs $i, j$ such that $i \neq j$, $a_i$ divid... | ```python
# cook your dish here
def prime_factors(n):
i = 2
factors =set()
while i * i <= n:
if n % i:
i += 1
else:
n //= i
factors.add(i)
if n > 1:
factors.add(n)
return factors
for _ in range(int(input())):
n=int(input())
a=list(map(int,input().split()))
ans=0
s=[]
for i in range(n):
s.appe... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Dreamoon likes coloring cells very much.
There is a row of $n$ cells. Initially, all cells are empty (don't contain any color). Cells are numbered from $1$ to $n$.
You are given an integer $m$ and $m$ integers $l_1, l_2, \ldots, l_m$ ($1 \le l... | ```python
def main():
import sys
input = sys.stdin.readline
N, M = list(map(int, input().split()))
L = list(map(int, input().split()))
if sum(L) < N:
print(-1)
return
ans = [0] * M
left = N
for i in range(M-1, -1, -1):
if left - L[i] >= i:
ans[i] = ... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
IIST is thinking of acquiring some land nearby to build its new state of the art labs. The land it has chosen incidentaly has some abandoned college buildings which IIST wants to use. The administration decide the value of the building based on ... | ```python
import math
from itertools import permutations as p
def diff(li1, li2):
li_dif = [i for i in li1 if i not in li2]
return li_dif
def segments(b):
"""A sequence of (x,y) numeric coordinates pairs """
poly = [(i[0],i[1]) for i in b]
return zip(poly, poly[1:] + [poly[0]])... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
You are given an axis-aligned rectangle in a 2D Cartesian plane. The bottom left corner of this rectangle has coordinates (0,0)$(0, 0)$ and the top right corner has coordinates (N−1,N−1)$(N-1, N-1)$. You are also given K$K$ light sources; each l... | ```python
# https://www.codechef.com/problems/RECTLIT
def assess(sq,points):
EWct = 0
NSct = 0
for a,b in points:
EW = (a == 0 or a == sq)
NS = (b == 0 or b == sq)
if EW and NS:
return 'yes'
EWct += EW
NSct += NS
if NSct + EWct == 0 or len... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
There is a building with $N$ floors (numbered $1$ through $N$ from bottom to top); on each floor, there are $M$ windows (numbered $1$ through $M$ from left to right). Let's denote the $j$-th window on the $i$-th floor by $(i, j)$.
All windows in... | ```python
try:
t = int(input())
while(t > 0):
t -= 1
n,m = list(map(int,input().split()))
a = [list(map(int,input().split())) for _ in range(n)]
dp = [[0 for _ in range(m)] for _ in range(n)]
ans = [['0' for _ in range(m)] for _ in range(n)]
for i in range... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
A permutation of length n is an array of size n consisting of n distinct integers in the range [1, n]. For example, (3, 2, 4, 1) is a permutation of length 4, but (3, 3, 1, 4) and (2, 3, 4, 5) are not, as (3, 3, 1, 4) contains duplicate elements... | ```python
tests = int(input())
for t in range(tests):
n = int(input())
permut='2'
permut_list=[]
if n%2==0:
for i in range(2, n+1):
if i%2==1:
permut=permut+' '+str(i+1)
else:
permut=permut+' '+str(i-1)
print(permut)
pass
elif n==1:
print(1)
pass
... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Mike is the president of country What-The-Fatherland. There are n bears living in this country besides Mike. All of them are standing in a line and they are numbered from 1 to n from left to right. i-th bear is exactly a_{i} feet high.
[Image... | ```python
def read_data():
n = int(input())
hs = list(map(int, input().split()))
return n, hs
def solve(n, hs):
left = get_left_index(n, hs)
right = get_right_index(n, hs)
vals = [[] for i in range(n)]
for h, l, r in zip(hs, left, right):
vals[r - l - 2].append(h)
min_hs = []
... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Anton likes to listen to fairy tales, especially when Danik, Anton's best friend, tells them. Right now Danik tells Anton a fairy tale:
"Once upon a time, there lived an emperor. He was very rich and had much grain. One day he ordered to build ... | ```python
n, m = map(int, input().split())
if (m >= n): print(n)
else:
c = n - m
l = 0
r = 10 ** 18
while r - l > 1:
md = (r + l) // 2
if (1 + md) * md // 2 < c:
l = md
else:
r = md
print(r + m)
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
You are given a rooted tree on N vertices. The nodes are numbered from 1 to N, and Node 1 is the root. Each node u has an associated value attached to it: Au.
For each vertex v, we consider the path going upwards from v to the root. Suppose that... | ```python
import sys
n = eval(input())
parents = [int(x)-1 for x in input().split(' ')]
values = list(map(int , input().split(' ')))
parents = [0]+parents
# print(parents)
# print(values)
def single_node_cost(i):
cost = 0
# print('started with ',i)
min_value = sys.maxsize
while i != 0:
min_value = min(min_value,v... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
You are given a string S containing only lowercase characters.
You can rearrange the string and you have to print minimum number of characters needed(can be 0) to make it palindrome.
-----Input:-----
- First line contain an interger T denoting... | ```python
# cooking dish here
from sys import stdin
from collections import Counter
read = stdin.readline
for testcase in range(int(read())):
length = int(read())
string = read().strip()
counts = Counter(string)
odd_counts = 0
for count in list(counts.values()):
# print(coun... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Indian National Olympiad in Informatics 2013
Calvin wakes up early one morning and finds that all his friends in the hostel are asleep. To amuse himself, he decides to play the following game : he draws a sequence of N squares on the ground, num... | ```python
try:
n, k=map(int, input().split())
arr=list(map(int, input().split()))
forward = [0]*(n+1)
backward= [0]*(n+1)
backward[0]=arr[0]
backward[1]=arr[0]+arr[1]
for i in range(k, n):
forward[i]=arr[i] +max(forward[i-1],forward[i-2])
for i in range(2, n):
backward[i]=arr[... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
The chef likes to play with numbers. He takes some integer number x, writes it down on his iPad, and then performs with it n−1 operations of the two kinds:
- divide the number x by 3 (x must be divisible by 3);
- multiply the number x by 2.
Afte... | ```python
class Node:
def __init__(self,x):
self.x=x
self.next=None
self.prev=None
self.flag=True
for t in range(1):
n=int(input())
arr=list(map(int,input().split()))
for i in range(n):
arr[i]=Node(arr[i])
for i in arr:
d=[i.x%3==0,i.x,i.... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Back in 2015, Usain Bolt announced that he'll be retiring after the 2017 World Championship. Though his final season did not end gloriously, we all know that he is a true legend and we witnessed his peak during 2008 - 2013.
Post retirement, Usa... | ```python
for i in range(int(input())):
finish,distanetobolt,tigerAcceleration,boltspeed=map(int,input().split())
t1=((2*(finish+distanetobolt)/(tigerAcceleration))**0.5)
t2=(finish/boltspeed)
if t1>t2:
print("Bolt")
elif t1<t2:
print("Tiger")
else:
print("Tiger")
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
We have a tree with N vertices. The vertices are numbered 1, 2, ..., N. The i-th (1 ≦ i ≦ N - 1) edge connects the two vertices A_i and B_i.
Takahashi wrote integers into K of the vertices. Specifically, for each 1 ≦ j ≦ K, he wrote the integer ... | ```python
import sys
input = lambda: sys.stdin.readline().rstrip()
from collections import deque
N = int(input())
X = [[] for i in range(N)]
for i in range(N-1):
x, y = map(int, input().split())
X[x-1].append(y-1)
X[y-1].append(x-1)
Y = [(-10**9, 10**9) for _ in range(N)]
K = int(input())
for _ in range(K... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Do you know Professor Saeed? He is the algorithms professor at Damascus University. Yesterday, he gave his students hard homework (he is known for being so evil) - for a given binary string $S$, they should compute the sum of $F(S, L, R)$ over a... | ```python
for _ in range(int(input())):
s=input()
n=len(s)
t=0
ans=0
for i in range(n-1):
if(s[i]==s[i+1]):
t=t+1
x=t
for i in range(n):
t=x
if(i!=0):
if(s[i]==s[i-1]):
t=t-1
else:
t=t+1
y=t
for j in range(i,n):
t=y
try:
if(s[j]==s[j+1]):
t=t-1
else:
t=t+1
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.