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:
You are Dastan, the great Prince of Persia!
After searching long for the mysterious 'Sands of Time', you have finally arrived at the gates of the city that hosts the ancient temple of the gods. However, the gate is locked and it can only be open... | ```python
t=int(input())
for i in range(t):
n,k=[int(i) for i in input().split()]
l=input().split()
for i in range(k):
if l.pop()=='H':
for ind,j in enumerate(l):
if j=='H':
l[ind]='T'
else:
l[ind]='H'
print(sum([1 for i in l if i=='H']))
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Suppose you are performing the following algorithm. There is an array $v_1, v_2, \dots, v_n$ filled with zeroes at start. The following operation is applied to the array several times — at $i$-th step ($0$-indexed) you can: either choose posit... | ```python
t = int(input())
for _ in range(t):
n,k = list(map(int,input().split()))
a = list(map(int,input().split()))
for i in range(60, -1, -1):
m = k ** i
for j in range(n):
if a[j] >= m:
a[j] -= m
break
if all(i == 0 for i in a):
pri... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Little kids, Jack and Evan like playing their favorite game Glass-and-Stone. Today they want to play something new and came across Twitter on their father's laptop.
They saw it for the first time but were already getting bored to see a bunch of... | ```python
def getInput():
N_k = input().split()
N =int(N_k[0])
k =int(N_k[1])
list = []
output = []
count = 0
for i in range(0,k):
val = input()
if(val!="CLOSEALL"):
val=val.split()
val = int (val[1])
if val not in list:
count= count +1
list.append(val)
else:
list.remove(val)
coun... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Who's interested in football?
Rayne Wooney has been one of the top players for his football club for the last few years. But unfortunately, he got injured during a game a few months back and has been out of play ever since.
He's got proper treat... | ```python
T = int(input())
for j in range(0,T):
line1, line2 = input(), input()
seq = line2.split()
current_min = 1000001
current_max = 0
max_spread = 0
for i in range(0,len(seq)):
current_value = int(seq[i])
if current_min > current_value:
current_min = current_value
current_max = current_value
elif ... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Today Sonya learned about long integers and invited all her friends to share the fun. Sonya has an initially empty multiset with integers. Friends give her t queries, each of one of the following type: + a_{i} — add non-negative integer a_{i}... | ```python
from sys import stdin
def main():
cnt = [0] * 2 ** 18
t = str.maketrans("0123456789", "0101010101")
_, *l = stdin.read().splitlines()
for sign, s in map(str.split, l):
if sign == '?':
print(cnt[int(s, 2)])
else:
cnt[int(s.translate(t), 2)] += 1 if sign... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
A string a of length m is called antipalindromic iff m is even, and for each i (1 ≤ i ≤ m) a_{i} ≠ a_{m} - i + 1.
Ivan has a string s consisting of n lowercase Latin letters; n is even. He wants to form some string t that will be an antipalindr... | ```python
from collections import Counter
r = lambda: list(map(int, input().split()))
def main():
n, = r()
s = input()
cost = list(r())
ans = 0
cnt = Counter()
for i in range(n // 2):
if s[i] == s[n - 1 - i]:
ans += min(cost[i], cost[n - 1 - i])
cnt[s[i]] += 1
total = sum(cnt.values())
if total > 0... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
You are given a set of n pens, each of them can be red, blue, green, orange, and violet in color. Count a minimum number of pens that should be taken out from the set so that any two neighboring pens have different colors. Pens are considered to... | ```python
t = int(input())
for _ in range(t):
n = int(input())
a = input().strip()
prev = a[0]
ans = -1
for i in a:
if prev == i:
ans += 1
prev = i
print(ans)
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Indian National Olympiad in Informatics 2014
Due to resurfacing work, all north-south traffic on the highway is being diverted through the town of Siruseri. Siruseri is a modern, planned town and the section of roads used for the diversion forms... | ```python
class PathNode:
def __init__(self, row, col, st_x, st_y, p_count=0):
self.x = row
self.y = col
self.pathCount = p_count
def __str__(self):
return str(self.x) + " | " + str(self.y) + " | " + str(self.pathCount)
class GraphUtil:
def __init__(self, mat, R,C, d):
... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Polycarpus is a system administrator. There are two servers under his strict guidance — a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to ... | ```python
n=int(input())
ta,tb,da,db=[0]*4
for i in range (n):
t,x,y=list(map(int,input().split()))
if t==1:
ta+=(x+y)
da+=y
if (t==2):
tb+=(x+y)
db+=y
if (ta-da>=0.5*ta):
print ('LIVE')
else :
print ('DEAD')
if (tb-db>=0.5*tb):
print ('LIVE')
else :
pr... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Chef and his friend Miron were getting bored and decided to play a game.
Miron thinks of a sequence of N integers (A1, A2, …., AN) and gives Chef a matrix B, where Bi,j = |Ai - Aj|. He further tells Chef that A1 = 0. The game is for Chef to g... | ```python
def update_B(B, query):
p, R = query
for i in range(len(R)):
B[p][i] = R[i]
B[i][p] = R[i]
def get_A(B):
N = len(B)
A = [0] * N
i = 0
for j in range(N):
if B[0][j] != 0:
i = j
A[i] = -B[0][i]
break
for j in range(i + 1, N):
if abs(A[i] - B[0][j]) == B[i][j]:
A[j] = B[0][j]
else:... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
You are given $N$ gears numbered $1$ through $N$. For each valid $i$, gear $i$ has $A_i$ teeth. In the beginning, no gear is connected to any other. Your task is to process $M$ queries and simulate the gears' mechanism. There are three types of ... | ```python
class Dsu:
def __init__(self, v, s):
self.par = s
self.v = v
self.dr = [1] * v
self.zero = [False] * v
self.speed = []
for i in range(v):
self.speed.append([])
self.speed[i].append(i)
def find(self, i):
# if parent[i] == ... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Chef works in a similar way to a travelling salesman ― he always travels to new cities in order to sell his delicious dishes.
Today, Chef is planning to visit $N$ cities (numbered $1$ through $N$). There is a direct way to travel between each pa... | ```python
# cook your dish here
def solution(b,n1,d):
first=b[0]
b.sort()
for j in range(n1-1):
if(a[j+1]-a[j]>d):
return "NO"
for j in range(n1):
if(b[j]==first):
pos=j
if(pos==0 or pos==n1-1):
return "YES"
rec=1
for j in range(pos-1,n1-2):
if(a[j+2]-a[j]>d):
rec=0
break
if(rec):
retur... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Maxim always goes to the supermarket on Sundays. Today the supermarket has a special offer of discount systems.
There are m types of discounts. We assume that the discounts are indexed from 1 to m. To use the discount number i, the customer tak... | ```python
import sys
n_discounts = int(sys.stdin.readline())
discount_values = [int(x) for x in sys.stdin.readline().split()]
n_items = int(sys.stdin.readline())
item_values = [int(x) for x in sys.stdin.readline().split()]
min_discount_req = 10000000
for discount_value in discount_values:
min_discount_req = min(m... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
-----Problem Statement-----
Harry Potter has one biscuit and zero rupee in his pocket. He will perform the following operations exactly $K$ times in total, in the order he likes:
- Hit his pocket, which magically increases the number of biscuits... | ```python
K,A,B = map(int,input().split())
if A + 2 > B:
print(K + 1)
return
start = A - 1
K -= start
ans = K//2 * (B-A) + K%2 + start + 1
print(ans)
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Most problems on CodeChef highlight chef's love for food and cooking but little is known about his love for racing sports. He is an avid Formula 1 fan. He went to watch this year's Indian Grand Prix at New Delhi. He noticed that one segment of t... | ```python
for _ in range(int(input())):
n = int(input())
l = list(map(int,input().split()))
ans = 1
l1 = l[0]
for i in range(1,n):
if l[i] <= l1:
l1 = l[i]
ans = ans + 1
print(ans)
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
There is a beautiful garden of stones in Innopolis.
Its most beautiful place is the $n$ piles with stones numbered from $1$ to $n$.
EJOI participants have visited this place twice.
When they first visited it, the number of stones in piles wa... | ```python
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = sum(a)
d = sum(b)
if c >= d:
print('Yes')
else:
print('No')
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Two players decided to play one interesting card game.
There is a deck of $n$ cards, with values from $1$ to $n$. The values of cards are pairwise different (this means that no two different cards have equal values). At the beginning of the gam... | ```python
q = int(input())
for z in range(q):
n, k1, k2 = map(int, input().split())
arr1 = list(map(int, input().split()))
arr2 = list(map(int, input().split()))
if max(arr1) > max(arr2):
print('YES')
else:
print('NO')
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Chef has $N$ markers. There is a cap on each marker. For each valid $i$, the $i$-th marker has colour $a_i$. Initially, for each valid $i$, the colour of the cap on the $i$-th marker is also $a_i$.
Chef wants to rearrange the caps in such a way ... | ```python
# cook your dish here
from collections import Counter,defaultdict
for i in range(int(input())):
n=int(input())
arr=list(map(int,input().split()))
coun=Counter(arr)
check=True
for j in coun:
if coun[j]>n//2:
print("No")
check=False
break
if check==True:
print("Yes")
narr=sorted(arr)
... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
This problem is actually a subproblem of problem G from the same contest.
There are $n$ candies in a candy box. The type of the $i$-th candy is $a_i$ ($1 \le a_i \le n$).
You have to prepare a gift using some of these candies with the followin... | ```python
import sys
input = sys.stdin.readline
Q = int(input())
for _ in range(Q):
N = int(input())
A = [int(a) for a in input().split()]
X = {}
for a in A:
if a in X:
X[a] += 1
else:
X[a] = 1
Y = []
for x in X:
Y.append(X[x])
Y = sorted(Y)[:... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
You are given a string S constisting of uppercase Latin letters. Is it possible to reorder the characters in this string to get a string with prefix "LTIME" and suffix "EMITL"?
We remind you that a prefix of a string is any substring which conta... | ```python
# cook your dish here
from collections import Counter
for i in range(int(input())):
s=input().upper()
res=Counter(s)
if res["L"]>=2 and res["T"]>=2 and res["I"]>=2 and res["M"]>=2 :
if len(s)==9:
if res["E"] >=1 :
print("YES")
else:
print("NO")
elif len(s)>9:
if res["E"]>=2:
print(... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Salmon runs a fish delivery company in Fish City. Fish City has $N$ vertical roads numbered $1, 2, ..., N$ from left to right, each spaced 1 unit apart; similarly, there are $M$ horizontal roads numbered $1, 2, ..., M$ from bottom to top, each s... | ```python
n,m,k=map(int, input().split())
a = []
check = [0]*m
while k!= 0:
x1,y1,x2,y2 =map(int,input().split())
a.append([x1,y1,x2,y2])
check[y1-1] += 1
check[y2-1] += 1
k-= 1
maxi = check.index(max(check))+1
sum = 0
k = 0
for i in range(len(a)):
x1,y1,x2,y2 = a[i]
if (y1 > maxi and y2 > maxi) or (y1<maxi and ... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
You like tracking airplane flights a lot. Specifically, you maintain history of an airplane’s flight at several instants and record them in your notebook. Today, you have recorded N such records h1, h2, ..., hN, denoting the heights of some airp... | ```python
def f(n):
s = list(map(int, input().split()))
low = []
high = []
for i in range(n - 1):
low.append(min(s[i], s[i+1]))
high.append(max(s[i], s[i+1]))
low.sort()
high.sort()
curr = mx = 0
i = j = 0
n -= 1
while i < n and j < n:
if low[i] < high[j]:
i += 1
curr += 1
else:
j += 1
c... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
There are $n$ lamps on a line, numbered from $1$ to $n$. Each one has an initial state off ($0$) or on ($1$).
You're given $k$ subsets $A_1, \ldots, A_k$ of $\{1, 2, \dots, n\}$, such that the intersection of any three subsets is empty. In othe... | ```python
import sys
readline = sys.stdin.readline
class UF():
def __init__(self, num):
self.par = [-1]*num
self.weight = [0]*num
def find(self, x):
if self.par[x] < 0:
return x
else:
stack = []
while self.par[x] >= 0:
stack.app... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Ganesh lives in Gopalmath. He is looking for Jojo. So he decides to collect Aadhar Card Information of all the citizens of India from UIDAI.
Someone told Ganesh that the sum of all the digits of Jojo’s Aadhar number is divisible by 10 and it is ... | ```python
for _ in range(int(input())):
N = input()
num = list(N)
s=0
for n in num:
if n.isnumeric():
s+=int(n)
#print(s)
x=(10-s%10)%10
print(int(N)*10+int(x))
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
You are given a string S consisting of lowercase English letters.
Determine whether we can turn S into a palindrome by repeating the operation of swapping two adjacent characters. If it is possible, find the minimum required number of operations... | ```python
import collections
class Bit():
def __init__(self, l):
self.size = l
self.bit = [0] * (self.size+1)
def sum(self, i):
s = 0
while i > 0:
s += self.bit[i]
i -= i & -i
return s
def add(self, i, x):
while i <= self.size:
... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
A Little Elephant from the Zoo of Lviv likes lucky strings, i.e., the strings that consist only of the lucky digits 4 and 7.
The Little Elephant calls some string T of the length M balanced if there exists at least one integer X (1 ≤ X ≤ M) such... | ```python
x=eval(input())
for x in range(0,x):
ans=0
d=input()
a=0
cont=0
for i in range(0,len(d)):
a+=len(d)-i
if d[i]=='7':
ans+=1+cont
cont+=1
else:
cont=0
ans=a-ans
print(ans)
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Chef's new hobby is painting, but he learned the fact that it's not easy to paint 2D pictures in a hard way, after wasting a lot of canvas paper, paint and of course time. From now on, he decided to paint 1D pictures only.
Chef's canvas is N mil... | ```python
# cook your dish here
import sys
import math
def main(arr):
for i in range(1,len(arr)-1):
if arr[i]==arr[i-1] and arr[i]==arr[i+1]:
return "Yes"
return "No"
test=int(input())
for _ in range(test):
b=int(input())
arr=list(map(int,input().split()))
print(main(arr))
... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Alexander is learning how to convert numbers from the decimal system to any other, however, he doesn't know English letters, so he writes any number only as a decimal number, it means that instead of the letter A he will write the number 10. Thu... | ```python
n=int(input())
s=input()
pw=[1]
last=1
for i in range(70):
if (last>1e19):
break
pw.append(last*n)
last=last*n
dp=[1e19]*100
for i in range(100):
dp[i]=[1e19]*100
dp[len(s)][0]=0
for i in range(len(s),-1,-1):
for power in range(0,len(pw)):
cur=''
for j in range(i-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, \ldots, A_N$. Calculate the number of ways to remove a non-empty contiguous subsequence from it such that the resulting sequence is non-empty and strictly increasing.
-----Input-----
- The first line of the i... | ```python
import bisect
def pre(a):
for p in range(n-1):
if(a[p]>=a[p+1]):
return p
return n-1
def suf(a):
for s in range(1,n):
if(a[n-s]<=a[n-s-1]):
return n-s
return 0
t=int(input())
for _ in range(t):
n=int(input())
a=list(map(int,input().split()))
p=pre(a)
s=suf(a)
b=a[s:n]
count=0
... | |
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
t=int(input())
for _ in range(t):
n = int(input())
for i in range(n+1):
b = n
for space in range(n-i):
print(" ",end="")
for j in range(i+1):
print(b,end="")
b-=1
print()
for l in range(n):
a = n
... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
You are given three strings $a$, $b$ and $c$ of the same length $n$. The strings consist of lowercase English letters only. The $i$-th letter of $a$ is $a_i$, the $i$-th letter of $b$ is $b_i$, the $i$-th letter of $c$ is $c_i$.
For every $i$ (... | ```python
for _ in range(int(input())):
a, b, c = input(), input(), input()
n = len(a)
ok = True
for i in range(n):
if c[i] not in [a[i], b[i]]:
ok = False
print('YES' if ok else 'NO')
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
You will be given m strings. For each of those strings, you need to count the total number of appearances of that string as substrings in all possible strings of length n containing only lower case English letters.
A string may appear in a str... | ```python
for _ in range(int(input())):
n,m=map(int,input().split())
print("Case "+str(_+1)+":")
for i in range(m):
s=input()
ls=len(s)
if ls>n:
print("0")
else:
k=(n-ls+1)
print((k*pow(26,n-ls,1000000007))%1000000007)
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
You have a tree consisting of n vertices. You want to color each vertex of the tree in one of the k colors such that for any pair of vertices having same color, all the vertices belonging to the path joining them should also have same color. In ... | ```python
A = [0] * 100001
M = 1000000007
def nCk(n, k):
if k ==0 or k ==n:
return 1
r = (A[n-k]*A[k])%M
x = (A[n]*pow(r, M-2, M))%M
return x
for _ in range(int(input())):
n, k = list(map(int, input().split()))
for i in range(n-1):
u,v = input().split()
summ = 0
A[0] = 1
for i in range(1, len(A)):
A[i]... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Farmer John has just given the cows a program to play with! The program contains two integer variables, x and y, and performs the following operations on a sequence a_1, a_2, ..., a_{n} of positive integers: Initially, x = 1 and y = 0. If, afte... | ```python
n = int(input())
t = [0, 0] + list(map(int, input().split()))
a, b = [0] * (n + 1), [0] * (n + 1)
a[1] = b[1] = -1
def f(s, a, b, l):
nonlocal t
l.reverse()
j, n = 0, len(l)
while True:
s += t[l[j]]
a[l[j]] = s
j += 1
if j == n: return
s += t[l[j]]
... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Chef has $N$ axis-parallel rectangles in a 2D Cartesian coordinate system. These rectangles may intersect, but it is guaranteed that all their $4N$ vertices are pairwise distinct.
Unfortunately, Chef lost one vertex, and up until now, none of hi... | ```python
for _ in range(int(input())):
n=int(input())
a=[]
b=[]
for i in range(4*n-1):
c,d=list(map(int,input().split()))
a.append(c)
b.append(d)
c1=0
c2=0
for i in a:
c1^=i
for i in b:
c2^=i
print(c1,c2)
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Doubleville, a small town in Texas, was attacked by the aliens. They have abducted some of the residents and taken them to the a spaceship orbiting around earth. After some (quite unpleasant) human experiments, the aliens cloned the victims, and... | ```python
def main():
while True:
[n, m] = [int(i) for i in input().split()]
if n == m and n == 0:
break
cache = {}
for i in range(n):
dna = input().rstrip('\n')
if dna in cach... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
When Misha hits his favorite gym, he comes across an interesting problem with the barbell. In the gym, someone always leaves the weight plates in the strangest places you can imagine and sometime it's difficult to equip the barbell the way you w... | ```python
def fx(s,n,xsum):
sub=[[None for x in range(n+2)]for y in range(xsum+2)]
for i in range(n+1):
sub[0][i]=True
for i in range(1,xsum+1):
sub[i][0]=False
for i in range(1,xsum+1):
for j in range(1,n+1):
sub[i][j]=sub[i][j-1]
if i>=s[j-1]:
sub[i][j]=sub[i][j] or sub[i-s[j-1]][j-1]
if sub[xsum... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Katya studies in a fifth grade. Recently her class studied right triangles and the Pythagorean theorem. It appeared, that there are triples of positive integers such that you can construct a right triangle with segments of lengths corresponding ... | ```python
n = int(input())
if n % 4 == 0:
temp = n // 4
m = temp * 3
k = temp * 5
elif n % 2 == 0:
n //= 2
m = n**2 // 2
k = m + 1
m *= 2
k *= 2
else:
m = n**2 // 2
k = m + 1
if 3 > n:
print("-1")
else:
print(m,k)
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Writing light novels is the most important thing in Linova's life. Last night, Linova dreamed about a fantastic kingdom. She began to write a light novel for the kingdom as soon as she woke up, and of course, she is the queen of it.
[Image]
T... | ```python
import sys
input = sys.stdin.readline
n, k = list(map(int, input().split()))
begin = [-1] * n
end = [-1] * n
hurt = [-1] * n
adj = [[] for i in range(n)]
for _ in range(n-1):
u ,v = list(map(int, input().split()))
adj[u-1].append(v-1)
adj[v-1].append(u-1)
hurt[0] = 1
begin[0] = 0
stack = [0]
c... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Problem description.
This problem is simple and will introduce you to the Dynamic Programming.
You will be given an array and a key value.
You will have to find out the occurrences of the key value depending upon the query using Brute Force a... | ```python
for __ in range(eval(input())):
x = eval(input())
a = list(map(int,input().split()))
key = eval(input())
query = eval(input())
maxvisited = x #maximum visted value
j = x-1
ans = []
val = 0
while j>=0:
if a[j]==key:
ans.append(val+1)
val = val... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
So the Chef has become health conscious and is now lifting weights at the gym. But its his first time so the trainer gives him a simple job to do.
He has been given a weight lifting rod and N heavy weights, each weighing 20, 21, .... , 2n-1. H... | ```python
t = int(input())
while(t>0):
n=int(input())
if(n<=0):
print(0)
fact=1
start=1
for i in range(1,n+1):
fact*=start
start+=2
print(fact)
t=t-1
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Coach Khaled is a swag teacher in HIT (Hag Institute of Technology). However, he has some obsession problems.
Recently, coach Khaled was teaching a course in building 8G networks using TV antennas and programming them with assembly. There are $N... | ```python
# cook your dish here
for _ in range(int(input())):
n = int(input())
k = n//4
# a,b,c = map(int,input().split())
a = sorted(map(int,input().split()))
a60 = (a[k-1],a[k])
a75 = (a[2*k-1],a[2*k])
a90 = (a[3*k-1],a[3*k])
if a60[0]==a60[1] or a75[0]==a75[1] or a90[0]==a90[1] :
print(-1)
else :
print(... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Not everyone probably knows that Chef has younder brother Jeff. Currently Jeff learns to read.
He knows some subset of the letter of Latin alphabet. In order to help Jeff to study, Chef gave him a book with the text consisting of N words. Jeff c... | ```python
knows=input()
n=eval(input())
while n!=0:
n=n-1
word=input()
for x in word:
ctr=0
for y in knows:
if x==y:ctr=ctr+1;break
if ctr==0:print('No');break
else: print('Yes')
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Pied Piper is a startup company trying to build a new Internet called Pipernet. Currently, they have $A$ users and they gain $X$ users everyday. There is also another company called Hooli, which has currently $B$ users and gains $Y$ users everyd... | ```python
# cook your dish here
import heapq as hq
from math import floor
for _ in range(int(input())):
n,a,b,x,y,z=map(int,input().split())
arr=[-int(i) for i in input().split()]
days=((z-b-1)//y)
ans=0
hq.heapify(arr)
curr=a+days*x
while curr<z :
u=hq.heappop(arr)
u=-u
if u==0 :
break
else:
curr+... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
You are given integer $n$. You have to arrange numbers from $1$ to $2n$, using each of them exactly once, on the circle, so that the following condition would be satisfied:
For every $n$ consecutive numbers on the circle write their sum on the ... | ```python
def main():
n = int(input())
ans = [0] * (2 * n)
for i in range(n):
a = 2 * i + 1
b = 2 * i + 2
if i & 1:
ans[i] = a
ans[i + n] = b
else:
ans[i] = b
ans[i + n] = a
ans *= 2
curr = sum(ans[:n])
mi = curr
... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
You and your $n - 1$ friends have found an array of integers $a_1, a_2, \dots, a_n$. You have decided to share it in the following way: All $n$ of you stand in a line in a particular order. Each minute, the person at the front of the line choose... | ```python
import sys
readline = sys.stdin.readline
class Segtree:
def __init__(self, A, intv, initialize = True, segf = max):
self.N = len(A)
self.N0 = 2**(self.N-1).bit_length()
self.intv = intv
self.segf = segf
if initialize:
self.data = [intv]*self.N0 + A + [i... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
This is another problem about Indraneel's library. His library has one long shelf. His books are numbered and he identifies the books by their number. Each book has a distinct number.
He has lost many books, since many of his friends borrow his ... | ```python
def bookList():
numBooks=int(input())
bookNum=[int(x) for x in input().split()]
takenBooks=int(input())
for i in range(takenBooks):
takenBookPos=(int(input()))
a=bookNum[takenBookPos-1]
print(a)
bookNum.remove(a)
bookList()
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Mysterious Chefland… Recently, Chef realised that Discuss, the educational system of Chefland, is out of date. Therefore, he is trying to find ways to update the infrastructure in the country. One possible way is to move all materials from Discu... | ```python
t = input()
t = int(t)
for _ in range(t):
n, m, x, y = input().split()
n = int(n)
m = int(m)
x = int(x)
y = int(y)
n -= 1
m -= 1
flag = 0
if n % x == 0 and m % y == 0:
flag = 1
n -= 1
m -= 1
if n >= 0 and m >= 0:
if n % x == 0 and m % y == 0:
flag = 1
if flag == 1:
print("Chefirnemo")... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
As we all know, Max is the best video game player among her friends. Her friends were so jealous of hers, that they created an actual game just to prove that she's not the best at games. The game is played on a directed acyclic graph (a DAG) wit... | ```python
def mat(shape, inital_val=None):
if len(shape) > 1:
return [mat(shape[1:], inital_val) for _ in range(shape[0])]
else:
return [inital_val] * shape[0]
def main():
n, m = [int(x) for x in input().split()]
graph = [{} for _ in range(n)]
for _ in range(m):
... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
You are given two matrices $A$ and $B$. Each matrix contains exactly $n$ rows and $m$ columns. Each element of $A$ is either $0$ or $1$; each element of $B$ is initially $0$.
You may perform some operations with matrix $B$. During each operatio... | ```python
n, m = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(n)]
B = [[0] * m for _ in range(n)]
ans = []
for i in range(n - 1):
for j in range(m - 1):
if A[i][j] == 1 and A[i + 1][j] == 1 and A[i][j + 1] == 1 and A[i + 1][j + 1] == 1:
B[i][j] = 1
B[... | |
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 valid $i$, the star value of the element $A_i$ is the number of valid indices $j < i$ such that $A_j$ is divisible by $A_i$.
Chef is a curious person, so he wants to know the maximum sta... | ```python
T = int(input())
for _ in range(T):
n = int(input())
arr = list(map(int, input().split()))
a = [0 for _ in range(max(arr)+1)]
star_val = []
for i in range(len(arr)):
j = 1
val = 0
while j*arr[i] <= len(a):
val += a[j*arr[i]-1]
j += 1
star_val.append(val)
a[arr[i]-1] += 1
print(max(star_v... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Chef has a cubic die with 6 faces kept on an infinite plane. Each face has a distinct integer in the range [1,6] written on it, but the exact arrangement of the numbers on the faces of the die is unknown to Chef. Curiosity gets the better of Ch... | ```python
from itertools import permutations
def solve(n,a):
ans=[]
for des in desire:
check=1
for i in range(n-1):
if (a[i]==a[i+1]):
return [-1]
if a[i+1]==des[a[i]-1]:
check=0
break
if check:
ans=des
break
if ans:
return ans
return [-1]
per=permutations([1,2,3,4,5,6])
... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Given a string consisting of only lowercase English alphabets, your task is to find the smallest palindromic substring.
In case there are multiple palindromic substrings of the same length present, print the lexicographically smallest substring.... | ```python
# cook your dish here
T = int(input())
for t in range(T):
N = int(input())
s = sorted(list(str(input())))
print(s[0])
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Little Elephant is playing a game with arrays. He is given an array A0, A1, ..., AN−1 of N integers. And then Q queries are given, each containing an integer K. He has to tell how many subarrays satisfy the condition: the function foo returns K ... | ```python
import sys
import math
def main(arr,k):
ans=0
for i in range(len(arr)):
curr_min=float('inf')
for j in range(i,len(arr)):
curr_min=min(curr_min,arr[j])
if curr_min==k:
ans+=1
return ans
n=int(input())
arr=list(ma... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Write a program to find the remainder when an integer A is divided by an integer B.
-----Input-----
The first line contains an integer T, the total number of test cases. Then T lines follow, each line contains two Integers A and B.
-----Outp... | ```python
number = int(input())
for i in range(number):
x = list(map(int, input().split(' ')))
print(x[0]%x[1])
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
"Humankind cannot gain anything without first giving something in return. To obtain, something of equal value must be lost. That is alchemy's first law of Equivalent Exchange. In those days, we really believed that to be the world's one, and onl... | ```python
for i in range(int(input())):
n = int(input())
c = list(map(int, input().split()))
d = {}
d[0] = -1
parity = 0
ans = 0
for i in range(n):
parity ^= 1 << (c[i]-1)
for t in range(30):
x = parity^(1<<t)
if(x in d.keys()):
ans = max(ans, i - d[x])
if p... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Chef has a number N, Cheffina challenges the chef to check the divisibility of all the permutation of N by 3. If any of the permutations is divisible by 3 then print 1 else print 0.
-----Input:-----
- First-line will contain $T$, the number of ... | ```python
from sys import *
input=stdin.readline
for u in range(int(input())):
s=int(input())
if(s%3==0):
print(1)
else:
print(0)
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
In this problem you are given a sequence of $N$ positive integers $S[1],S[2],\dots,S[N]$. In addition you are given an integer $T$, and your aim is to find the number of quadruples $(i,j,k,l)$, such that $1 \le i < j < k < l \le N$, and $S[i] +... | ```python
# cook your dish here
from itertools import combinations
a = list(map(int, input().split()))
n = a[0]
t = a[1]
q = list(combinations(a[2:], 4))
total = 0
for i in q:
if sum(i) == t:
total += 1
print(total)
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
You are given an array of $n$ integers: $a_1, a_2, \ldots, a_n$. Your task is to find some non-zero integer $d$ ($-10^3 \leq d \leq 10^3$) such that, after each number in the array is divided by $d$, the number of positive numbers that are prese... | ```python
n=int(input())
ar=list(map(int,input().split()))
pos=0
neg=0
for a in ar:
if(a>0):pos+=1
elif a<0:neg+=1
if(pos*2>=n):
print(1)
elif neg*2>=n:
print(-1)
else:
print(0)
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Chef loves triangles. But the chef is poor at maths. Given three random lengths Chef wants to find if the three sides form a right-angled triangle or not. Can you help Chef in this endeavour?
-----Input:-----
- First-line will contain $T$, the ... | ```python
# cook your dish here
def check(a,b,c):
if (a==0) or (b==0) or (c==0):
return "NO"
else:
i=3
while(i>0):
if (a*a)==(b*b)+(c*c):
return "YES"
else:
t=a
a=b
b=c
c=t
... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Just to remind, girls in Arpa's land are really nice.
Mehrdad wants to invite some Hoses to the palace for a dancing party. Each Hos has some weight w_{i} and some beauty b_{i}. Also each Hos may have some friends. Hoses are divided in some fri... | ```python
f = lambda: map(int, input().split())
n, m, w = f()
wb = [(0, 0)] + list(zip(f(), f()))
t = list(range(n + 1))
def g(x):
if x == t[x]: return x
t[x] = g(t[x])
return t[x]
for i in range(m):
x, y = f()
x, y = g(x), g(y)
if x != y: t[y] = x
p = [[] for j in range(n + 1)]
for i in ra... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Chef has an array A consisting of N elements. He wants to find number of pairs of non-intersecting segments [a, b] and [c, d] (1 ≤ a ≤ b < c ≤ d ≤ N) such there is no number that occurs in the subarray {Aa, Aa+1, ... , Ab} and {Ac, Ac+1, ... ,... | ```python
t=int(input())
for q in range(t):
n=int(input())
x=list(map(int,input().split()))
dic={}
dic2={}
for i in range(n):
dic2[x[i]]=1
#print dic2
if len(dic2)==n:
n+=2
print((n*(n-1)*(n-2)*(n-3))/24)
continue
counter=0
for i in range(n-1):
if x[i] in dic:
dic[x[i]]+=1
else:
dic[x[i]]=1
... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other n - 1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the super... | ```python
n = int(input())
a = list(map(int, input().split()))
r = n-2
for d in a:
r += d
print(max(max(a), r//(n-1)))
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Let's consider a rectangular table R consisting of N rows and M columns. Rows are enumerated from 1 to N from top to bottom. Columns are enumerated from 1 to M from left to right. Each element of R is a non-negative integer. R is called steady ... | ```python
# This is not my code, it's Snehasish Karmakar's. Refer to http://www.codechef .com/viewsolution/7153774
# for original version.
# Submitting it to try and work out if it can be sped up.
def compute_nCr(n,r) :
C[0][0]=1
for i in range(1,n+1) :
# print "i",i
C[i][0]=1
for j in range(1,min(i,r)... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Given a triplet of integers (X , Y , Z), such that X ≤ Y and Y ≥ Z, we define f(X , Y , Z) to be (X + Y) * (Y + Z). If either X > Y or Y < Z, or both, then f(X , Y , Z) is defined to be 0.
You are provided three arrays A , B and C of any leng... | ```python
T=int(input()) # cook your dish here
for i in range(T):
n=list(map(int,input().split()))
a=n[0]
b=n[1]
c=n[2]
l=[]
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
for i in range(b):
for j in range(a):
f... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
The new Formula 1 season is about to begin and Chef has got the chance to work with the Formula 1 technical team.
Recently, the pre-season testing ended and the technical team found out that their timing system for qualifying was a little bit ... | ```python
# cook your dish here
t=int(input())
for i in range(t):
n=int(input())
if n<101:
l1=[]
l2=[]
d=dict()
for i in range(1,2*n+1):
if i%2==0:
l1.append(int(input()))
else:
l2.append(str(input()))
r1=[]
for i in l1:
r1.append(i)
l1.sort()
ind=[]
for i in l1:
a=r1.index(i)
... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Mr. Funt now lives in a country with a very specific tax laws. The total income of mr. Funt during this year is equal to n (n ≥ 2) burles and the amount of tax he has to pay is calculated as the maximum divisor of n (not equal to n, of course). ... | ```python
def is_izi(k):
i = 2
while (i * i <= k):
if (k % i == 0):
return 0
i += 1
return 1
n = int(input())
if (is_izi(n)):
print(1)
elif n % 2 == 0:
print(2)
elif n % 2 == 1:
if (is_izi(n - 2)):
print(2)
else:
print(3)
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
At first, let's define function $f(x)$ as follows: $$ \begin{matrix} f(x) & = & \left\{ \begin{matrix} \frac{x}{2} & \mbox{if } x \text{ is even} \\ x - 1 & \mbox{otherwise } \end{matrix} \right. \end{matrix} $$
We can see that if we choose som... | ```python
def gg(n,lol):
ans = 0
cur = 1
lol2 = lol
while(2*lol+1<=n):
cur *= 2
ans += cur
lol = 2*lol+1
lol2 *= 2
if lol2*2 <= n:
ans += n-lol2*2+1
return ans
n,k = list(map(int,input().split()))
low = 1
high = n//2
res = 1
while low <= high:
mid = (low+high)//2
if gg(n,mid) >= k:
res = mid
low... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Note : This question carries $100$ $points$
CodeLand is celebrating a festival by baking cakes! In order to avoid wastage, families follow a unique way of distributing cakes.
For $T$ families in the locality, $i$-th family (1 <= $i$ <= $T$) has ... | ```python
# cook your dish here
extra, less = 0,0
for _ in range(int(input())):
sli,mem,sma,luc = list(map(int, input().split()))
total = sma
t = sma
while mem > 1:
t *= luc
total += t
mem -= 1
if total <= sli:
extra += sli-total
print('POSSIBLE',sli-total)
... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Koa the Koala and her best friend want to play a game.
The game starts with an array $a$ of length $n$ consisting of non-negative integers. Koa and her best friend move in turns and each have initially a score equal to $0$. Koa starts.
Let's d... | ```python
import sys
input = lambda: sys.stdin.readline().rstrip()
T = int(input())
for _ in range(T):
N = int(input())
A = [int(a) for a in input().split()]
X = [0] * 30
for a in A:
for i in range(30):
if a & (1 << i):
X[i] += 1
for i in range(30)[::-1]:
... | |
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. You have to find the length of the smallest (shortest) prefix of elements you need to erase from $a$ to make it a good array. Recall that the prefix of the array $a=[a_1, a_2, \dots, a_n]$ i... | ```python
for __ in range(int(input())):
n = int(input())
ar = list(map(int, input().split()))
ar.reverse()
ans = n - 1
flag = False
for i in range(1, n):
if ar[i] < ar[i - 1]:
flag = True
if flag:
if ar[i] > ar[i - 1]:
break
ans -=... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Zonal Computing Olympiad 2012, 26 Nov 2011
We consider sequences of opening and closing brackets with two types of brackets, () and []. A bracket sequence is well-bracketed if we can pair up each opening bracket with a matching closing bracket... | ```python
# cook your dish here
n=int(input())
stringa=list(map(int,input().split()))
counter=0
counter1=0
counter3=0
somma1=0
somma2=0
massimo=0
massimo1=0
massimo3=0
stack=[]
for par in stringa:
if par==1 or par==3:
if counter1==0 and par==1:
counter1=1
somma1=1
massim... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Chef bought a huge (effectively infinite) planar island and built $N$ restaurants (numbered $1$ through $N$) on it. For each valid $i$, the Cartesian coordinates of restaurant $i$ are $(X_i, Y_i)$.
Now, Chef wants to build $N-1$ straight narrow ... | ```python
import sys
def input(): return sys.stdin.readline().strip()
def iinput(): return int(input())
def rinput(): return list(map(int, sys.stdin.readline().strip().split()))
def get_list(): return list(map(int, sys.stdin.readline().strip().split()))
t=iinput()
for _ in range(t):
n=iinput()
p=[]
mi=[]... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
You are provided with the marks of entire class in Data structures exam out of 100. You need to calculate the number of students having backlog (passing marks is >=31) and the average of the class. But this average is not a normal average, for t... | ```python
for j in range(int(input())):
input()
a = list(map(int,input().split()))
marks = 0
backlok = 0
top_marks = max(a)
topper = []
for i in range(len(a)):
if(a[i] >= 31):
marks+=a[i]
if(a[i]<31):
backlok+=1
if(a[i] == top_marks):
topper.append(i)
print(backlok, "{:0.2f}".format(marks/len(a),... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Leha is a usual student at 'The Usual University for Usual Students'. Sometimes he studies hard; at other times he plays truant and gets busy with other things besides academics. He has already studied at the university for N months. For the ith... | ```python
n=eval(input())
grades=list(map(int,input().split()))
m=eval(input())
for df in range(m):
x,y=list(map(int,input().split()))
arr=[]
arr=grades[x-1:y]
arr.sort()
sum=0
#arr.append(1000000)
for nh in range(0,len(arr)-1,1):
sum=sum+(arr[nh+1]-arr[nh])**2
#print sum,len(arr),nh+1,nh
print(sum)
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Chef has been working in a restaurant which has N floors. He wants to minimize the time it takes him to go from the N-th floor to ground floor. He can either take the elevator or the stairs.
The stairs are at an angle of 45 degrees and Chef's... | ```python
n=int(input())
l=[]
for i in range(0,n):
a,b,c=map(int,input().split())
n1=(2**0.5)*(a/b)
n2=2*(a/c)
if n1>n2:
l.append("Elevator")
else:
l.append("Stairs")
for i in l:
print(i)
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
A binary string is called a self-destructing string if it can reduced to an empty string by performing the following operation some number of times (possibly zero): Choose a valid integer $i$ such that the $i$-th character of the current string ... | ```python
t=int(input())
for i in range(t):
s=input()
zeroes=s.count('0')
ones=s.count('1')
if (len(s)%2==1 or zeroes==0 or ones==0):
ans= -1
else:
ans=abs(zeroes-ones)//2
print(ans)
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Consider a currency system in which there are notes of six denominations, namely, Rs. 1, Rs. 2, Rs. 5, Rs. 10, Rs. 50, Rs. 100.
If the sum of Rs. N is input, write a program to computer smallest number of notes that will combine to give Rs. N.
... | ```python
# cook your dish here
t= int(input())
for i in range(t):
cnt=0
n=int(input())
while(n>=100):
n-=100
cnt+=1
while(n>=50):
n-=50
cnt+=1
while(n>=10):
n-=10
cnt+=1
while(n>=5):
n-=5
cnt+=1
while(n>=2):
n-=2
... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Batman is about to face Superman so he decides to prepare for the battle by upgrading his Batmobile. He manufactures multiple duplicates of his standard Batmobile each tweaked in a different way such that the maximum speed of each is never less ... | ```python
t = int(input())
while(t):
n = int(input())
ar = list(map(int,input().strip().split(" ")))
print(len([x for x in ar[1:len(ar)] if ar[0]<x]))
t-=1
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
After failing to clear his school mathematics examination, infinitepro decided to prepare very hard for his upcoming re-exam, starting with the topic he is weakest at ― computational geometry.
Being an artist, infinitepro has C$C$ pencils (numbe... | ```python
from collections import Counter
from math import factorial
def nc3(n):
a=factorial(n)
b=factorial(n-3)
return ((a)/(b*6))
def rem(s,k):
t=-1
x=-1
for i in range(len(s)):
if s[i][0]>2 and s[i][1]<=k:
if s[i][0]>3:
ch=(nc3(s[i][0])-nc3(s[i]... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
You are given a tree with $N$ vertices (numbered $1$ through $N$) and a bag with $N$ markers. There is an integer written on each marker; each of these integers is $0$, $1$ or $2$. You must assign exactly one marker to each vertex.
Let's define ... | ```python
# cook your dish here
import numpy as np
tests = int(input())
for _ in range(tests):
n = int(input())
weights = [int(j) for j in input().split()]
edges = [[0] for _ in range(n-1)]
for i in range(n-1):
edges[i] = [int(j)-1 for j in input().split()]
vertex_set = [[] for _ in range(n)]
fo... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
To help Lavanya learn all about binary numbers and binary sequences, her father has bought her a collection of square tiles, each of which has either a 0 or a 1 written on it. Her brother Nikhil has played a rather nasty prank. He has glued toge... | ```python
n=int(input())
modulo=15746
num=[1,1]
for i in range(2,n+1):
num.append((num[i-1]+num[i-2])%modulo)
print(num[n])
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Chef recently learned about concept of periodicity of strings. A string is said to have a period P, if P divides N and for each i, the i-th of character of the string is same as i-Pth character (provided it exists), e.g. "abab" has a period P = ... | ```python
T=int(input())
for i in range(T):
n,m=list(map(int,input().split()))
if(m<=2):
print("impossible")
else:
l=[0]*m
if(m%2==0):
a=m//2
else:
a=(m//2)+1
for j in range(a):
if(j%2==0):
l[j]="a"
l[m-j-1]="a"
else:
l[j]="b"
l... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
This is the easier version of the problem. In this version, $1 \le n \le 10^5$ and $0 \le a_i \le 1$. You can hack this problem only if you solve and lock both problems.
Christmas is coming, and our protagonist, Bob, is preparing a spectacular ... | ```python
# 素因数分解
def prime_decomposition(n):
i = 2
table = []
while i * i <= n:
while n % i == 0:
n //= i
table.append(i)
i += 1
if n > 1:
table.append(n)
return table
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().sp... | |
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 uppercase English letters. You are allowed to perform at most one operation of following kind: Choose any position in the string, remove the character at that position and insert it back to any other place in ... | ```python
for _1 in range(int(input())):
n=int(input())
s=input().strip()
answer=s
for i in range(len(s)):
c=s[i]
string=s[:i]+s[i+1:]
for j in range(len(string)+1):
answer=min(answer, string[:j]+c+string[j:])
print(answer)
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Chef likes all arrays equally. But he likes some arrays more equally than others. In particular, he loves Rainbow Arrays.
An array is Rainbow if it has the following structure:
- First a1 elements equal 1.
- Next a2 elements equal 2.
- Next a... | ```python
t=int(input())
x=[1,2,3,4,5,6,7]
for i in range(t):
N=int(input())
a=list(map(int,input().split()))
rev=a[::-1]
dup=set(a)
if rev== a and list(dup) ==x:
print("yes")
else:
print("no")
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Toad Rash has a binary string $s$. A binary string consists only of zeros and ones.
Let $n$ be the length of $s$.
Rash needs to find the number of such pairs of integers $l$, $r$ that $1 \leq l \leq r \leq n$ and there is at least one pair of ... | ```python
X = [[], ['0', '1'], ['00', '01', '10', '11'], ['001', '010', '011', '100', '101', '110'], ['0010', '0011', '0100', '0101', '0110', '1001', '1010', '1011', '1100', '1101'], ['00100', '00101', '00110', '01001', '01011', '01100', '01101', '10010', '10011', '10100', '10110', '11001', '11010', '11011'], ['001001'... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Tomya is a girl. She loves Chef Ciel very much.
Tomya like a positive integer p, and now she wants to get a receipt of Ciel's restaurant whose total price is exactly p.
The current menus of Ciel's restaurant are shown the following table.
Name ... | ```python
t= int(input())
while(t>0):
n = int(input())
m=0
m=n//(2**11)
n%=(2**11)
while(n>0):
num=n%2
m+=num
n//=2
print(m)
t-=1
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Dr. S. De teaches computer architecture in NIT Patna. Whenever he comes across any good question(with complexity $k$), he gives that question to students within roll number range $i$ and $j$
At the start of semester he assigns score of $10$ to e... | ```python
try:
t=int(input())
for a in range(t):
l=input().split()
n=int(l[0])
m=int(l[1])
d={}
s=0
for b in range(m):
l1=input().split()
i=int(l1[0])
j=int(l1[1])
k=int(l1[2])
for c in range(i,j+1):
if c not in d:
d[c]=10
for c in range(i,j+1):
d[c]=d[c]*k
for i in d:
... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
One day, Chef prepared D brand new dishes. He named the i-th dish by a string Si. After the cooking, he decided to categorize each of these D dishes as special or not.
A dish Si is called special if it's name (i.e. the string Si) can be represe... | ```python
# cook your dish here
def check_equal(a,b):
index=0
for i in a:
while index<len(b) and i != b[index]:
index+=1
if(index>=len(b)):
return False
index+=1
return True
def Dob_String(n):
size=len(n)
midpoint=size//2
if(check_equal(n[0:midpoint],n[midpoint:size])):
return("YES")
elif(size%2!=... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
You like playing chess tournaments online.
In your last tournament you played $n$ games. For the sake of this problem, each chess game is either won or lost (no draws). When you lose a game you get $0$ points. When you win you get $1$ or $2$ po... | ```python
import sys
input = sys.stdin.readline
def main():
n, k = map(int, input().split())
string = input().strip()
if "W" not in string:
ans = min(n, k) * 2 - 1
print(max(ans, 0))
return
L_s = []
cnt = 0
bef = string[0]
ans = 0
for s in string:
... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Iroha has a sequence of N strings S_1, S_2, ..., S_N. The length of each string is L.
She will concatenate all of the strings in some order, to produce a long string.
Among all strings that she can produce in this way, find the lexicographically... | ```python
n,l = map(int,input().split())
a = []
for i in range(n):
a.append(input())
a.sort()
print("".join(str(i) for i in a))
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Chef is a brilliant university student that does not attend lectures because he believes that they are boring and coding is life! However, his university follows certain rules and regulations, and a student may only take an exam for a course if ... | ```python
# cook your dish here
def ceil(num):
if num%1==0:
return int(num//1)
else:
return int((num//1)+1)
for _ in range(int(input())):
n=int(input())
s=input()
p=0
a=[]
for i in range(n):
if s[i]=="P":
p=p+1
req=ceil(0.75*n)
requirement=req-p
for i in range(2,n-2):
if s[i]=="A":
if (s[i-1]=... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
You are given an undirected unweighted graph consisting of $n$ vertices and $m$ edges (which represents the map of Bertown) and the array of prices $p$ of length $m$. It is guaranteed that there is a path between each pair of vertices (districts... | ```python
import sys
from collections import deque
input = sys.stdin.readline
t = int(input())
for _ in range(t):
n, m, a, b, c = list(map(int,input().split()))
p = list(map(int, input().split()))
p.sort()
pref = [0]
curr = 0
for i in range(m):
curr += p[i]
pref.append(curr... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
You are given three non-negative integers $X$, $Y$ and $N$. Find the number of integers $Z$ such that $0 \le Z \le N$ and $(X \oplus Z) < (Y \oplus Z)$, where $\oplus$ denotes the bitwise XOR operation.
-----Input-----
- The first line of the i... | ```python
# cook your dish here
tc=int(input())
for j in range(tc):
ip=list(map(int,input().rstrip().split()))
x=ip[0]
y=ip[1]
n=ip[2]
cnt=0
if(x==y):
print('0')
continue
ln=bin(x).replace("0b", "")
rn=bin(y).replace("0b", "")
ll=len(ln)
rl=len(rn)
#print(ln)
#print(rn)
if(ll==len(rn)):
for i in ra... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Let x be a string of length at least 1.
We will call x a good string, if for any string y and any integer k (k \geq 2), the string obtained by concatenating k copies of y is different from x.
For example, a, bbc and cdcdc are good strings, while... | ```python
w=list(input());n=len(w);t=-1
def Z(s):
m=len(s);z=[0]*m;c=0;f=[1]*m;
for i in range(1,m):
if i+z[i-c]<c+z[c]:z[i]=z[i-c]
else:
j=max(0,c+z[c]-i)
while i+j<n and s[j]==s[i+j]:j=j+1
z[i]=j;c=i
for p in range(1,m):
for k in range(2,z[p]//p+... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
For Diwali, Chef arranges all $K$ laddus in a row in his sweet shop. Whenever a customer comes to buy laddus, chef follows a rule that each customer must buy all laddus on odd position. After the selection of the laddu, a new row is formed, and ... | ```python
# cook your dish here
t=int(input())
while t>0:
n=int(input())
if n==1:
print(1)
else:
c,num=1,2
while num<n:
num*=2
if num==n:
print(num)
else:
print(num//2)
t-=1
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Indian National Olympiad in Informatics 2012
You are given a table with 2 rows and N columns. Each cell has an integer in it. The score of such a table is defined as follows: for each column, consider the sum of the two numbers in the column; th... | ```python
# cook your dish here
try:
n=int(input())
list_n = list(range(1,n+1))
list_n_flag=[]
fix_arr = list(map(int,input().split()))
k=1
res_list=[]
fin_list=[]
list_n_flag = list_n[k:] + list_n[:k]
res_list = [list_n[i] + fix_arr[i] for i in range(len(fix_arr)... | |
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
N = int(input())
l = []
for i in range(N):
l.append(input())
for j in range(N-1,-1,-1):
s = '` '+ l[j]
n = len(s)-1
y = s[n]
f = ''
while y != '`':
w = ''
while y != ' ':
if ord(y) in range(97,123) or ord(y) in range(65,91):
w += y
... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Find sum of all the numbers that are multiples of 10 and are less than or equal to a given number "N". (quotes for clarity and be careful of integer overflow)
-----Input-----
Input will start with an integer T the count of test cases, each case... | ```python
for t in range(eval(input())):
n=eval(input())
n-=n%10
n/=10
print(n*(n+1)/2*10)
``` |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.