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:
Vasily has a deck of cards consisting of n cards. There is an integer on each of the cards, this integer is between 1 and 100 000, inclusive. It is possible that some cards have the same integers on them.
Vasily decided to sort the cards. To do... | ```python
n = int(input())
s = list(map(int,input().split(' ')))
a = []
for i in range(max(s)):
a.append([])
for i in range(len(s)):
a[s[i]-1].append(i)
a = list([x for x in a if x != []])
if len(a) > 1:
for i in range(1,len(a)):
if len(a[i]) > 1:
s = a[i-1][-1]
if s > a[... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Today is rose day, batch mates of Kabir and Tara decided to celebrate this day by exchanging roses with each other.
Note:$Note:$ exchanging means both the boy and the girl will give rose to each other.
In the class there are B$B$ boys and G$G$... | ```python
for i in range(int(input())):
print(2*(sum(list(map(int, input().split())))-1))
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Tired of the overpopulated world, Miu - The introverted cat visits a new continent in search for a new house.
There are $N$ houses lying on the X-axis.
Their positions are given by $X$$i$ , where $i$ refers to the $i$th house. ( $1 <= i <= N$... | ```python
n = int(input())
for i in range(n) :
t = int(input())
li = sorted(list(map(int , input().split())))
ans = 1
dp = [li[1]-li[0]] + [0] * (t-2) + [li[t-1] - li[t-2]]
for i in range(1 , t-1) :
dp[i] = min(li[i] - li[i-1] , li[i+1] - li[i])
print(max(dp))
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
The chef is having one string of English lower case alphabets only. The chef wants to remove all "abc" special pairs where a,b,c are occurring consecutively. After removing the pair, create a new string and again remove "abc" special pair from a... | ```python
# cook your dish here
for _ in range(int(input())):
s=input()
while(s.count("abc")!=0):
s=s.replace("abc","")
print(s)
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Unlucky year in Berland is such a year that its number n can be represented as n = x^{a} + y^{b}, where a and b are non-negative integer numbers.
For example, if x = 2 and y = 3 then the years 4 and 17 are unlucky (4 = 2^0 + 3^1, 17 = 2^3 + 3^... | ```python
x,y,l,r=list(map(int,input().split()))
b=set()
a=0
b.add(l-1)
b.add(r+1)
for i in range(100):
xx=x**i
if xx>r: break
for j in range(100):
rr=xx+(y**j)
if rr>r: break
if rr>=l:
b.add(rr)
b=sorted(list(b))
for i in range(1,len(b)):
a=max(a,b[i]-b[i-1]-1)
print(a)
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Chef is playing a game with his brother Chefu. He asked Chefu to choose a positive integer $N$, multiply it by a given integer $A$, then choose a divisor of $N$ (possibly $N$ itself) and add it to the product. Let's denote the resulting integer ... | ```python
import math
def divisors(n):
arr = []
for i in range(1,1+int(math.ceil(math.sqrt(n)))):
if n%i == 0:
arr.append(i)
arr.append(n//i)
arr = list(sorted(set(arr)))
return arr
try:
t = int(input())
while t:
t -= 1
a,m = map(int, input().split())
divs = divisors(m)
ans = []
for d in divs:
... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Every day, Mike goes to his job by a bus, where he buys a ticket. On the ticket, there is a letter-code that can be represented as a string of upper-case Latin letters.
Mike believes that the day will be successful in case exactly two different ... | ```python
def res(s):
if len(s) == 2:
if s[0] == s[1]:
print("NO")
else:
print("YES")
elif s[0] != s[1]:
counte = 0
for i in range(2, len(s)):
if i % 2 == 0:
if s[i] != s[0]:
counte = 1
break
else:
if s[i] != s[1]:
counte = 1
break
if counte == 0:
print("YES")
... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Chef owns an icecream shop in Chefland named scoORZ. There are only three types of coins in Chefland: Rs. 5, Rs. 10 and Rs. 15. An icecream costs Rs. 5.
There are $N$ people (numbered $1$ through $N$) standing in a queue to buy icecream from sco... | ```python
# cook your dish here
for _ in range(int(input())):
n=int(input())
lst=list(map(int,input().split()))
f=0
t=0
p=1
for i in lst:
if(i==5):
f+=1
elif(i==10):
if(f>0):
f-=1
t+=1
else:
p=0
... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Rani is teaching Raju maths via a game called N-Cube, which involves three sections involving N.
Rani gives Raju a number N, and Raju makes a list of Nth powers of integers in increasing order (1^N, 2^N, 3^N.. so on). This teaches him exponenti... | ```python
tc=int(input())
for case in range(tc):
m,r=list(map(int,input().split()))
n=m**(r-1)
a=[i**n for i in range(1,2*n+1)]
tmp=2*n-1
for i in range(n):
for j in range(tmp-i):
a[j]=a[j+1]-a[j]
print((a[n-1]/m)%1000000007)
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
The Little Elephant has an integer a, written in the binary notation. He wants to write this number on a piece of paper.
To make sure that the number a fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from n... | ```python
x = input ()
flag = 0
s = 0
for each_item in x:
if each_item == '0':
if flag == 0:
flag = 1;
continue
else:
print (each_item, end = '')
else:
if (s == len (x) - 1 and flag == 0) :
continue
print (each_item, end = '')
... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
In the State of Takahashi in AtCoderian Federation, there are N cities, numbered 1, 2, ..., N.
M bidirectional roads connect these cities.
The i-th road connects City A_i and City B_i.
Every road connects two distinct cities.
Also, for any two c... | ```python
from collections import deque
N, M = list(map(int, input().split()))
adj = [[1 for _ in range(N + 1)] for _ in range(N + 1)]
for _ in range(M):
a, b = list(map(int, input().split()))
adj[a][b] = 0
adj[b][a] = 0
adj_inv = [[] for _ in range(N + 1)]
for i in range(1, N+1):
for j in range(i+1, N... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Eighth-grader Vova is on duty today in the class. After classes, he went into the office to wash the board, and found on it the number n. He asked what is this number and the teacher of mathematics Inna Petrovna answered Vova that n is the answe... | ```python
n=int(input())
q=[]
for i in range(max(0,n-100),n+1):
j=i
res=i
while j:
res+=j%10
j//=10
if res==n:
q.append(i)
print(len(q))
for i in q:
print(i)
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
and Bengali as well.
There are N$N$ cats (numbered 1$1$ through N$N$) and M$M$ rats (numbered 1$1$ through M$M$) on a line. Each cat and each rat wants to move from some point to some (possibly the same) point on this line. Naturally, the cats a... | ```python
# cook your dish here
# cook your dish here
class Animal:
def __init__(self):
start, end, starting_time = map(int, input().split())
self.ending_time = starting_time + abs(start - end)
self.velocity = 1 if end >= start else -1
self.eaten_by = -1, 10 ** 10
... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Chef is very fond of horses. He enjoys watching them race. As expected, he has a stable full of horses. He, along with his friends, goes to his stable during the weekends to watch a few of these horses race. Chef wants his friends to enjoy the r... | ```python
t=eval(input())
for q in range(t):
l=eval(input())
a=input().split()
a=[int(x) for x in a]
a=sorted(a)
for i in range(l-1):
a[i]=(a[i+1]-a[i])
print(min(a[0:l-1]))
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Given are integer sequence of length N, A = (A_1, A_2, \cdots, A_N), and an integer K.
For each X such that 1 \le X \le K, find the following value:
\left(\displaystyle \sum_{L=1}^{N-1} \sum_{R=L+1}^{N} (A_L+A_R)^X\right) \bmod 998244353
-----C... | ```python
import numpy as np
N,K = list(map(int,input().split()))
A=np.array(list(map(int,input().split())))
mod = 998244353
fact = [1]*(K+1)
for i in range(1,K+1):
fact[i]=i*fact[i-1]%mod
inv_fact = [pow(f,mod-2,mod) for f in fact]
# r = [sum(pow(aa,t,mod) for aa in A)%mod for t in range(K+1)]##遅い
r = [0]*(K+1)... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
In order to celebrate Twice's 5th anniversary, Tzuyu and Sana decided to play a game.
Tzuyu gave Sana two integers $a$ and $b$ and a really important quest.
In order to complete the quest, Sana has to output the smallest possible value of ($a ... | ```python
n = int(input())
for _ in range(n):
a, b = list(map(int, input().split()))
print(a ^ b)
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Leha like all kinds of strange things. Recently he liked the function F(n, k). Consider all possible k-element subsets of the set [1, 2, ..., n]. For subset find minimal element in it. F(n, k) — mathematical expectation of the minimal element am... | ```python
"""
Author : Arif Ahmad
Date :
Algo :
Difficulty :
"""
from sys import stdin, stdout, setrecursionlimit
import threading
def main():
m = int(stdin.readline().strip())
a = [int(_) for _ in stdin.readline().strip().split()]
b = [int(_) for _ in stdin.readline... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Let us consider the following operations on a string consisting of A and B:
- Select a character in a string. If it is A, replace it with BB. If it is B, replace with AA.
- Select a substring that is equal to either AAA or BBB, and delete it f... | ```python
S = input()
SA = [0]
n = 0
for c in S:
if c=='A': n+=1
SA.append(n)
T = input()
TA = [0]
n = 0
for c in T:
if c=='A': n+=1
TA.append(n)
q = int(input())
for _ in range(q):
a, b, c, d = list(map(int, input().split()))
nSA = SA[b]-SA[a-1]
nSB = b-a+1-nSA
nTA = TA[d]-TA[c-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$ non-negative integers. You have to choose a non-negative integer $x$ and form a new array $b$ of size $n$ according to the following rule: for all $i$ from $1$ to $n$, $b_i = a_i \oplus x$ ($\oplus$ d... | ```python
n = int(input())
l = list(map(int, input().split()))
inv = 0
out = 0
mult = 1
for i in range(32):
curr = dict()
opp = 0
same = 0
for v in l:
if v ^ 1 in curr:
if v & 1:
opp += curr[v ^ 1]
else:
same += curr[v ^ 1]
... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Bears love candies and games involving eating them. Limak and Bob play the following game. Limak eats 1 candy, then Bob eats 2 candies, then Limak eats 3 candies, then Bob eats 4 candies, and so on. Once someone can't eat what he is supposed to ... | ```python
for t in range(int(input())):
limakMax, bobMax = list(map(int, input().split()))
limakEat = 0; bobEat = 0
eating = 1
while limakEat <= limakMax or bobEat <= bobMax:
if eating % 2 != 0 and limakEat <= limakMax:
limakEat += eating
eating += 1
if limakEat > limakMax:
print("Bob")
break
... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Chef's dog Snuffles has so many things to play with! This time around, Snuffles has an array A containing N integers: A1, A2, ..., AN.
Bad news: Snuffles only loves to play with an array in which all the elements are equal.
Good news: We have a ... | ```python
tc=int(input())
for case in range(tc):
n,d=list(map(int,input().split()))
a=list(map(int,input().split()))
sm=sum(a)
f=True
if sm%n==0:
avg=sm/n
for i in range(d):
tmp_sm=0
tmp_n=0
for j in range(i,n,d):
tmp_sm=tmp_sm+a[j]
tmp_n+=1
if tmp_sm%tmp_n==0:
if avg!=tmp_sm/tmp_n:
... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Polycarp has $n$ different binary words. A word called binary if it contains only characters '0' and '1'. For example, these words are binary: "0001", "11", "0" and "0011100".
Polycarp wants to offer his set of $n$ binary words to play a game "... | ```python
for _ in range(int(input())):
n = int(input())
mass = []
zo = 0
oz = 0
zz = 0
oo = 0
ozs = []
zos = []
ozss = set()
zoss = set()
for j in range(n):
k = input()
mass.append(k)
if k[0] == '0' and k[-1] == '1':
zoss.add(k)
... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
The median of a sequence is the element in the middle of the sequence after it is sorted. For a sequence with even size, the median is the average of the two middle elements of the sequence after sorting. For example, for a sequence $A = [1, 3, ... | ```python
# cook your dish here
# cook your dish here
import numpy as np
import sys
def findSeq(n, s, k, m, M):
midInd = n // 2
seqs = []
for ind in range(midInd + 2, midInd - 3, -1):
if ind >= n or ind < 0:
continue
seq = genBestSeq(n, ind, m, M, s)
if seq is not -... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Get excited, folks, because it is time for the final match of Codechef Premier League (CPL)!
Mike and Tracy also want to watch the grand finale, but unfortunately, they could not get tickets to the match. However, Mike is not someone who gives u... | ```python
import sys
sys.setrecursionlimit(100000)
memo = {}
def recurse(arr, T1, T2, k, i):
if T1 >= k and T2 >= k:
return i
if i >= len(arr):
return float('inf')
if (T1, T2) in memo:
return memo[(T1, T2)]
t1 = recurse(arr, T1 + arr[i], T2, k, i+1)
t2 = recurse(arr, T1, T2 + arr[i], k, i+1)
memo[(T1,... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Alice and Johnny are playing a simple guessing game. Johnny picks an arbitrary positive integer n (1<=n<=109) and gives Alice exactly k hints about the value of n. It is Alice's task to guess n, based on the received hints.
Alice often has a s... | ```python
# cook your dish here
def guessingGame (l):
a = []
m = 1000000001
for i in range (len(l)):
k=int(l[i][1])
if (l[i][0]=='<' and l[i][2]=='Yes'):
a.append((1,1))
a.append((k,-1))
if (l[i][0]=='<' and l[i][2]=='No'):
a.append((k,1))
a.append((m,-1))
if (l[i][0]=='=' and l[i][2]=='Y... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Recall that a binary search tree is a rooted binary tree, whose nodes each store a key and each have at most two distinguished subtrees, left and right. The key in each node must be greater than any key stored in the left subtree, and less than ... | ```python
N = int(input())
if N in [1, 2, 4, 5, 9, 10, 20, 21, 41, 42, 84, 85, 169, 170, 340, 341, 681, 682, 1364, 1365, 2729, 2730, 5460, 5461, 10921, 10922, 21844, 21845, 43689, 43690, 87380, 87381, 174761, 174762, 349524, 349525, 699049, 699050]:
print(1)
else:
print(0)
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Rakesh has built a model rocket and wants to test how stable it is. He usually uses a magic box which runs some tests on the rocket and tells if it is stable or not, but his friend broke it by trying to find out how stable he is (very delicate m... | ```python
import random
def sign(i):
if i>0:
return 1
elif i<=0:
return 0
bleh = []
for _ in range(int(input())):
p = list(map(int,input().rstrip().split()))
max_rows = len(p)
if all([x==0 for x in p]):
print(1)
continue
if max_rows <= 1:
bleh.append(max_... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Chef likes toys. His favourite toy is an array of length N. This array contains only integers. He plays with this array every day. His favourite game with this array is Segment Multiplication. In this game, the second player tells the left and r... | ```python
# # # # n = int(input())
# # # # arr = list(map(int , input().split()))
# # # # for _ in range(int(input())):
# # # # l,r,mod = map(int , input().split())
# # # # pro = 1
# # # # for i in range(l - 1,r):
# # # # pro *= arr[i]
# # # # print(pro % mod) #sample testcases passed #TLE
# # # import nu... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Given n words w[1..n], which originate from the same stem (e.g. grace, graceful, disgraceful, gracefully), we are interested in the original stem. To simplify the problem, we define the stem as the longest consecutive substring that occurs in al... | ```python
t = eval(input())
for _ in range(t):
n = eval(input())
a = input().strip().split()
cb, cs = 0, ""
for i in range(len(a[0])):
for j in range(i+1,len(a[0])+1):
al = True
s = a[0][i:j]
for k in a[1:]:
if s not in k:
al = False
break
if al:
if j-i>=cb:
cb = max(cb, j-i)
... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Chef likes problems which using some math. Now he asks you to solve next one. You have 4 integers, Chef wondering is there non-empty subset which has sum equals 0.
-----Input-----
The first line of input contains T - number of test cases.
Each... | ```python
# cook your dish here
# cook your dish here
t = int(input())
while t:
t-=1
c=0
ar=[int(i) for i in input().strip().split()]
for i in range(1,16):
b=bin(i)[2:].zfill(4)
s=0
for i in range(4):
if b[i]=='1':
s+=ar[i]
if(s==0):
c=1
break
print("Yes" if c==1 else "No")
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
There were $N$ students (numbered $1$ through $N$) participating in the Indian Programming Camp (IPC) and they watched a total of $K$ lectures (numbered $1$ through $K$). For each student $i$ and each lecture $j$, the $i$-th student watched the ... | ```python
N,M,K=map(int,input().split())
c=0
for i in range(N):
T=list(map(int,input().split()))
Q=T[-1]
T.pop(-1)
if Q<=10 and sum(T)>=M:
c+=1
print(c)
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Suppose there is a X x Y x Z 3D matrix A of numbers having coordinates (i, j, k) where 0 ≤ i < X, 0 ≤ j < Y, 0 ≤ k < Z. Now another X x Y x Z matrix B is defined from A such that the (i, j, k) element of B is the sum of all the the numbers in A ... | ```python
# Problem: http://www.codechef.com/JULY09/submit/CUBESUM/
# Author: Susam Pal
def computeA():
X, Y, Z = [int(x) for x in input().split()]
B = []
for x in range(X):
B.append([])
for y in range(Y):
B[-1].append([int(t) for t in input().split()])
for z in range(Z):
result = B[x][y][z]
if x... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
There is an automatic door at the entrance of a factory. The door works in the following way: when one or several people come to the door and it is closed, the door immediately opens automatically and all people immediately come inside, when o... | ```python
def solve():
n1, m, a, d = list(map(int, input().split()))
t = list(map(int, input().split()))
from bisect import insort
from math import floor
insort(t, a * n1)
pred = 0
k = 0
kpred = 0
n = 0
step = d // a + 1
sol = 0
fl = 0
for i in t:
if (i > pred... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Reminder: the median of the array $[a_1, a_2, \dots, a_{2k+1}]$ of odd number of elements is defined as follows: let $[b_1, b_2, \dots, b_{2k+1}]$ be the elements of the array in the sorted order. Then median of this array is equal to $b_{k+1}$.... | ```python
for _ in range(int(input())):
n = int(input())
ar = list(map(int, input().split()))
ar.sort()
print(abs(ar[n] - ar[n - 1]))
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
You are given an undirected unweighted connected graph consisting of $n$ vertices and $m$ edges. It is guaranteed that there are no self-loops or multiple edges in the given graph.
Your task is to choose at most $\lfloor\frac{n}{2}\rfloor$ vert... | ```python
import sys
input = sys.stdin.readline
T = int(input())
for _ in range(T):
N, M = list(map(int, input().split()))
E = [[] for aa in range(N)]
for __ in range(M):
a, b = list(map(int, input().split()))
E[a-1].append(b-1)
E[b-1].append(a-1)
D = [-1] * N
D[0] = 0
... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
You came across this story while reading a book. Long a ago when the modern entertainment systems did not exist people used to go to watch plays in theaters, where people would perform live in front of an audience. There was a beautiful actress ... | ```python
for _ in range(int(input())):
S = input()
n = len(S)
a = n - S.count('a')
print(2 ** n - 2 ** a)
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
The chef is placing the laddus on the large square plat. The plat has the side of length N. Each laddu takes unit sq.unit area. Cheffina comes and asks the chef one puzzle to the chef as, how many squares can be formed in this pattern with all s... | ```python
# cook your dish here
t = int(input())
while t:
m = int(input())
print(int(m * (m + 1) * (2 * m + 1) / 6))
t -= 1
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
You are given two arithmetic progressions: a_1k + b_1 and a_2l + b_2. Find the number of integers x such that L ≤ x ≤ R and x = a_1k' + b_1 = a_2l' + b_2, for some integers k', l' ≥ 0.
-----Input-----
The only line contains six integers a_1, ... | ```python
import sys, collections
def gcd(a, b):
if b == 0: return a
return gcd(b, a % b)
def lcm(a, b):
return a // gcd(a, b) * b
def extgcd(a, b):
if b == 0: return 1, 0
x, y = extgcd(b, a % b)
return y, x - a // b * y
def prime_factor(n):
res = collections.defaultdict(int)
i = 2
... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Chef's younger brother is in town. He's a big football fan and has a very important match to watch tonight. But the Chef wants to watch the season finale of MasterChef which will be aired at the same time. Now they don't want to fight over it li... | ```python
res=""
for _ in range(int(input())):
ans=0
c=int(input())
for i in range(c):
n,m=list(map(int,input().split( )))
ans^=(n+m-2)%3
if ans:
res+="MasterChef\n"
else:
res+="Football\n"
print(res)
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Abhi Ram analyses london stock exchange and invests in a software company C-.gate . He wants to sell his shares after 5 weeks.
Given the investment m, increase or decrease of share prices of 5 weeks(+/- pi) , help him to calculate his net prof... | ```python
for i in range(int(input())):
n = int(input())
P = list(map(float, input().split()))
pr = 1
for p in P:
a = 100+p
pr = (pr*a)/100
pr = (pr-1)*100
x = 6-len(str(int(abs(pr))))
if (x==1):
if (pr==0):
print(0)
elif (pr>0):
print("+"+str("%.1f" % round(pr,x)))
els... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Alice's school is planning to take some students from her class on a field trip. Alice is really excited about it. There are a total of S students in her class. But due to budget constraints, the school is planning to take only N students for th... | ```python
nCr = [[0 for x in range(1001)] for x in range(1001)]
for i in range (0,1001):
nCr[i][0]=1
nCr[i][i]=1
for i in range (1,1001):
for j in range (1,1001):
if i!=j:
nCr[i][j] = nCr[i-1][j] + nCr[i-1][j-1]
t=eval(input())
for rajarshisarkar in range(0,t):
s,n,m,k=list(map(int,input().split(' ')))
fo... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
In africa jungle , there were zebra's who liked to spit.
There owner watched them for whole day and noted in his sheet where each zebra spitted.
Now he's in a confusion and wants to know if in the jungle there are two zebra's which spitted at ea... | ```python
# cook your dish here
t=int(input())
i=0
a=0
d=dict()
while i<t:
l=input().split()
d[int(l[0])]=int(l[0])+int(l[1])
i+=1
for k in d:
if d[k] in d:
if d[d[k]]==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:
Limak is a little polar bear.
He is playing a video game and he needs your help.
There is a row with N cells, each either empty or occupied by a soldier, denoted by '0' and '1' respectively.
The goal of the game is to move all soldiers to the ri... | ```python
for _ in range(int(input())):
l=list(map(int,input().strip()))
for j in range(len(l)-1,-1,-1):
if l[j]==1:
l.pop()
else:
break
if l.count(1):
time,prev,z,c=0,0,0,0
for j in range(len(l)-1,-1,-1):
if l[j]==0:
z+=1
continue
if prev!=z:
prev=z
c+=1
time+=c+z
print(tim... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Today is Chocolate day and Kabir and Tara are visiting a Valentine fair. Upon arriving, they find a stall with an interesting game.
There are N$N$ jars having some chocolates in them. To win the game, one has to select the maximum number of cons... | ```python
# cook your dish here
for u in range(int(input())):
n,r=list(map(int,input().split()))
l=list(map(int,input().split()))
m=0
for i in range(n-1):
d=[]
d.append(l[i])
c=1
while(i+c<n):
d.append(l[i+c])
d.sort(reverse=True)
if(d[... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
You are fed up with your messy room, so you decided to clean it up.
Your room is a bracket sequence $s=s_{1}s_{2}\dots s_{n}$ of length $n$. Each character of this string is either an opening bracket '(' or a closing bracket ')'.
In one operat... | ```python
t = int(input())
for tt in range(t):
n,k=list(map(int,input().split()))
s = input()
ans = []
if s[0] == ')':
for i in range(n):
if s[i] == '(':
ans.append([1,i+1])
s = s[i::-1] + s[i+1:]
break
for i in range(1,(k-1)*2):
... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Write a program to check whether a triangle is valid or not, when the three angles of the triangle are the inputs. A triangle is valid if the sum of all the three angles is equal to 180 degrees.
-----Input-----
The first line contains an integ... | ```python
n=int(input())
for i in range(n):
a,b,c=map(int,input().split())
if a>0 and b>0 and c>0 and a+b+c==180:
print("YES")
else:
print("NO")
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Roger recently built a circular race track with length K$K$. After hosting a few races, he realised that people do not come there to see the race itself, they come to see racers crash into each other (what's wrong with our generation…). After th... | ```python
import numpy as np
from numba import njit
i8 = np.int64
@njit
def solve(a, b, t, K, N):
t1 = t // K
d = t % K * 2
# b が a から a + d の位置にあれば衝突する
x = 0
y = 0
ans = 0
for c in a:
while b[x] < c:
x += 1
while b[y] <= c + d:
y +=... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
It's winter and taking a bath is a delicate matter. Chef has two buckets of water. The first bucket has $v_1$ volume of cold water at temperature $t_1$. The second has $v_2$ volume of hot water at temperature $t_2$. Chef wants to take a bath wit... | ```python
# cook your dish here
try:
for i in range(int(input())):
v1,t1,v2,t2,v3,t3=map(int,input().split())
ok = 0
if t1 <= t3 <= t2:
x, y = t2 - t3, t3 - t1
ok = x * v3 <= (x + y) * v1 and y * v3 <= (x + y) * v2
print('YES' if ok else 'NO')
except:
pass
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
You are given a dataset consisting of $N$ items. Each item is a pair of a word and a boolean denoting whether the given word is a spam word or not.
We want to use this dataset for training our latest machine learning model. Thus we want to choos... | ```python
t = int(input())
for _ in range(t):
n = int(input())
a = {}
for i in range(n):
l = input()
if l not in a:
a[l] = 1
else:
a[l] += 1
done = []
ans = 0
for i in a:
if a[i] != 0:
temp = [x for... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
This time minions are celebrating Diwali Festival. There are N minions in total. Each of them owns a house. On this Festival, Each of them wants to decorate their house. But none of them have enough money to do that. One of the minion, Kevin, re... | ```python
def find_combinations(list, sum):
if not list:
if sum == 0:
return [[]]
return []
return find_combinations(list[1:], sum) + \
[[list[0]] + tail for tail in
find_combinations(list[1:], sum - list[0])]
for tc in range(int(input())):
n,k=list(map(int,input().split()))
a=list(map(int,input().split... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
The sequence of $m$ integers is called the permutation if it contains all integers from $1$ to $m$ exactly once. The number $m$ is called the length of the permutation.
Dreamoon has two permutations $p_1$ and $p_2$ of non-zero lengths $l_1$ and... | ```python
def possible(a):
ans = set()
s = set()
lmax = 0
for i in range(len(a)):
lmax = max(lmax, a[i])
s.add(a[i])
if lmax == i + 1 and len(s) == i + 1:
ans.add(i + 1)
return ans
t = int(input())
for case_num in range(t):
n = int(input())
a = list(map(... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
John Doe started thinking about graphs. After some thought he decided that he wants to paint an undirected graph, containing exactly k cycles of length 3.
A cycle of length 3 is an unordered group of three distinct graph vertices a, b and c, s... | ```python
k = int(input())
p = [['0'] * 100 for j in range(100)]
g = lambda n: n * (n * n - 1) // 6
i = n = 0
while g(n + 1) <= k: n += 1
while i < n + 1:
for j in range(i): p[i][j] = p[j][i] = '1'
i += 1
k -= g(n)
g = lambda n: n * n - n >> 1
while k:
n = 0
while g(n + 1) <= k: n += 1
for j in rang... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
An agent called Cypher is decrypting a message, that contains a composite number $n$. All divisors of $n$, which are greater than $1$, are placed in a circle. Cypher can choose the initial order of numbers in the circle.
In one move Cypher can ... | ```python
from math import ceil
t = int(input())
for _ in range(t):
n = int(input())
pf = []
for i in range(2, ceil(n**0.5)+1):
while n % i == 0:
pf.append(i)
n //= i
if n > 1:
pf.append(n)
if len(pf) == 2 and pf[0] != pf[1]:
print(pf[0], pf[1], pf[0]*pf[1])
print(1)
else:
p... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
The chef is trying to solve some pattern problems, Chef wants your help to code it. Chef has one number K to form a new pattern. Help the chef to code this pattern problem.
-----Input:-----
- First-line will contain $T$, the number of test case... | ```python
# cook your dish here
for _ in range(int(input())):
n = int(input())
count = 1
l = 3*(n-1)
i = 0
if n==1:
print(1)
continue
while count<=l-n:
for j in range(i+1):
if j==i:
print(count)
count += 1
elif j==0:... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
For a string $S$ let the unique set of characters that occur in it one or more times be $C$. Consider a permutation of the elements of $C$ as $(c_1, c_2, c_3 ... )$. Let $f(c)$ be the number of times $c$ occurs in $S$.
If any such permutation of... | ```python
# cook your dish here
t=int(input())
for _ in range(t):
st=input()
s=set(st)
a=[]
f1=f2=0
for i in s:
a.append(st.count(i))
a.sort()
if len(a)>=3:
for i in range(2,len(a)):
if a[i]!=a[i-1]+a[i-2]:
f1=1
break
x=a[0]
a[0]=a[1]
a[1]=x
for i in range(2,len(a)):
if a[i]!=a[i-1]+a[i... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
You are given a sequence a consisting of n integers. Find the maximum possible value of $a_{i} \operatorname{mod} a_{j}$ (integer remainder of a_{i} divided by a_{j}), where 1 ≤ i, j ≤ n and a_{i} ≥ a_{j}.
-----Input-----
The first line conta... | ```python
def main():
input()
aa = sorted(map(int, input().split()))
maxa = max(aa)
m = [False] * (maxa + 1)
x = []
b = 0
for a in aa:
if b != a:
m[a] = True
for i in range(b, a):
x.append(b)
b = a
x.append(b)
ans = 0
fo... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
You are playing a Billiards-like game on an $N \times N$ table, which has its four corners at the points $\{(0, 0), (0, N), (N, 0),$ and $(N, N)\}$. You start from a coordinate $(x,y)$, $(0 < x < N, 0 < y < N)$ and shoot the ball at an angle $... | ```python
# cook your dish here
t=int(input())
for i in range(t):
a=0
b=0
N,K,x,y=map(int,input().split())
if x==y:
a=N
b=N
elif x>y:
if K%4==1:
a=N
b=y-x+N
elif K%4==2:
a=y-x+N
b=N
elif K%4==3:
a=0
b=x-y
else:
a=x-y
b=0
else:
if K%4==1:
a=x-y+N
b=N
elif K%4==2:
... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
The Little Elephant loves lucky strings. Everybody knows that the lucky string is a string of digits that contains only the lucky digits 4 and 7. For example, strings "47", "744", "4" are lucky while "5", "17", "467" are not.
The Little Elephan... | ```python
t = int(input())
for i in range(0,t):
a = input()
b = input()
agts=bgts=afour=bfour=aseven=bseven=altf=bltf=afts=bfts=0;
for j in a:
if j >= '7':
if j > '7':
agts += 1
else:
aseven += 1
elif j >= '4':
if j > '4':
afts += 1
else:
afour += 1
else:
altf += 1
for ... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
The purpose of this problem is to verify whether the method you are using to read input data is sufficiently fast to handle problems branded with the enormous Input/Output warning. You are expected to be able to process at least 2.5MB of input d... | ```python
#Note that it's python3 Code. Here, we are using input() instead of raw_input().
#You can check on your local machine the version of python by typing "python --version" in the terminal.
(n, k) = list(map(int, input().split(' ')))
ans = 0
for i in range(n):
x = int(input())
if x % k == 0:
ans += 1
prin... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
In this problem we are concerned with words constructed using the lowercase letters of the English alphabet - that is, a,b,c,…,z. These words need not necessarily be meaningful: any sequence of letters forms a word. For example, abbca is a word.... | ```python
def codn1(s1,s2,p):
c=0
ind=0
for i in range(len(s1)):
if s1[i]!=s2[i]:
c+=1
ind=i
if c>1 or ind==len(s1)-1:
return 0
if s1[ind]>s2[ind] and s1[ind] in s2[ind+1:]:
p[0]=True
if s1[ind]<s2[ind] and s2[ind] in s1[ind+1:]:
p[1]=True
return 1
def codn2(s1,s2):
if len(s1)<le... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Lyra Belacqua is a very gifted girl. She is one of a very small set of people capable of reading an alethiometer, more commonly known as The Golden Compass. It has one specific use: to tell the truth. The name in fact, is derived from "Aletheia"... | ```python
string=input()
max_no=0
for i in range(len(string)):
var_occur=0
check_no=str()
j=i
while(j<len(string) and var_occur<2 ):
if(string[j].isalpha()):
if(var_occur==0):
check_no+='9'
var_occur+=1
else:
var_occur+=1
else:
check_no+=string[j]
j+=1
#print(check_no)
max_no=max(max_no... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Zonal Computing Olympiad 2012, 26 Nov 2011
A sequence of opening and closing brackets is well-bracketed if we can pair up each opening bracket with a matching closing bracket in the usual sense. For instance, the sequences (), (()) and ()(()) ... | ```python
# cook your dish here
T = int(input())
l = list(map(int, input().strip().split(" ")))
depth = 0
max_depth = 0
max_depth_index = 0
max_l=0
max_l_index=0
last_zero=-1
for i in range(T):
if l[i] == 1:
depth += 1
if depth > max_depth:
max_depth = depth
max_depth_ind... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Chef has arrived in Dagobah to meet with Yoda to study cooking. Yoda is a very busy cook and he doesn't want to spend time with losers. So he challenges the Chef to a series of games, and agrees to teach the Chef if Chef can win at least P of th... | ```python
import math
dp = []
dp.append(0)
for i in range(1,1000005):
dp.append(math.log(i) + dp[i-1])
t = int(input())
for i in range(t):
n,m,p,k = input().split()
n = int(n)
m = int(m)
p = int(p)
k = int(k)
if p==0 or (n%2==0 and m%2==0):
ans = 1.0
print(ans)
elif n%2==1 and m%2==1:
ans=0.0
print(a... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
You are at the top left cell $(1, 1)$ of an $n \times m$ labyrinth. Your goal is to get to the bottom right cell $(n, m)$. You can only move right or down, one cell per step. Moving right from a cell $(x, y)$ takes you to the cell $(x, y + 1)$, ... | ```python
def getSum(dp, pos, s, e, type_):
if e < s:
return 0
if type_=='D':
if e==m-1:
return dp[pos][s]
return dp[pos][s]-dp[pos][e+1]
else:
if e==n-1:
return dp[s][pos]
return dp[s][pos]-dp[e+1][pos]
mod = 10**9+7
n, m = map(i... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Navnit is a college student and there are $N$ students in his college .Students are numbered from $1$ to $N$.
You are given $M$ facts that "Student $A_i$ and $B_i$".The same fact can be given multiple times .If $A_i$ is a friend of $B_i$ ,then $... | ```python
# cook your dish here
from collections import defaultdict
d=defaultdict(list)
def dfs(i):
p=0
nonlocal v
e=[i]
while(e!=[]):
p+=1
x=e.pop(0)
v[x]=1
for i in d[x]:
if v[i]==-1:
v[i]=1
e.append(i)
retu... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
The chef is having one array of N natural numbers(numbers may be repeated). i.e. All natural numbers must be less than N. Chef wants to rearrange the array and try to place a natural number on its index of the array, i.e array[i]=i. If multiple ... | ```python
for _ in range(int(input())):
n=int(input())
arr=list(map(int,input().split()))
d=set()
for i in arr:
d.add(i)
for i in range(n):
if i in d:
print(i,end=" ")
else:
print(0,end=" ")
print()
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
This problem is different from the easy version. In this version Ujan makes at most $2n$ swaps. In addition, $k \le 1000, n \le 50$ and it is necessary to print swaps themselves. You can hack this problem if you solve it. But you can hack the pr... | ```python
for _ in range(int(input())):
n = int(input())
s = input()
t = input()
d = {}
for i in range(ord('a'), ord('z') + 1):
d[chr(i)] = 0
for cs in s:
d[cs] += 1
for ct in t:
d[ct] += 1
ok = True
for e in d:
if d[e] % 2 == 1:
ok = Fa... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Koa the Koala has a binary string $s$ of length $n$. Koa can perform no more than $n-1$ (possibly zero) operations of the following form:
In one operation Koa selects positions $i$ and $i+1$ for some $i$ with $1 \le i < |s|$ and sets $s_i$ to $... | ```python
import sys
readline = sys.stdin.readline
MOD = 10**9+7
S = readline().strip().split('1')
if len(S) == 1:
print(len(S[0]))
else:
S = [len(s)+1 for s in S]
ans = S[0]*S[-1]
S = S[1:-1]
dp = [0]*(max(S)+2)
dp[0] = 1
for ai in S:
res = 0
rz = 0
for i in ra... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
You are in charge of controlling a dam. The dam can store at most L liters of water. Initially, the dam is empty. Some amount of water flows into the dam every morning, and any amount of water may be discharged every night, but this amount needs... | ```python
# なんだか釈然としていないが解説の通りに
from collections import deque
import sys
def MI(): return list(map(int, sys.stdin.readline().split()))
class water:
def __init__(self, t, v):
self.v = v
self.tv = v * t
def __le__(self, other):
return self.v * other.tv - self.tv * other.v >= 0
def ... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
There are n shovels in Polycarp's shop. The i-th shovel costs i burles, that is, the first shovel costs 1 burle, the second shovel costs 2 burles, the third shovel costs 3 burles, and so on. Polycarps wants to sell shovels in pairs.
Visitors ar... | ```python
from sys import stdin as cin
from sys import stdout as cout
def main():
n = int(cin.readline())
o = 0
for x in range(9, 0, -1):
if 10 ** x // 2 <= n:
##print(x)
for i in range(9):
q = 10 ** x * (i + 1) // 2 - 1
if q <= n:
... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
There are total $N$ cars in a sequence with $ith$ car being assigned with an alphabet equivalent to the $ith$ alphabet of string $S$ . Chef has been assigned a task to calculate the total number of cars with alphabet having a unique even value i... | ```python
arr = list(input())
n = len(arr)
ans = list()
#for i in arr:
#ans.append(ord(i)-96)
li = ['b','d','f','h','j','l','n','p','r','t','v','x','z']
s = set(arr)
temp = s.intersection(li)
for _ in range(int(input())):
x,y = list(map(int,input().split()))
li = list(temp)
#s = set()
c=... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Nature photographing may be fun for tourists, but it is one of the most complicated things for photographers. To capture all the facets of a bird, you might need more than one cameras. You recently encountered such a situation.
There are $n$ pho... | ```python
from math import *
from collections import *
import sys
input=sys.stdin.readline
t=int(input())
while(t):
t-=1
n=int(input())
a=list(map(int,input().split()))
p,q=map(int,input().split())
s=0
a.sort()
for i in range(n//2):
x=a[i]
x1=a[n-i-1]
i... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Today is the planned day tor Thik and Ayvak's wedding. Kark is infatuated with Ayvak. He offers to play a game with Thik. Whosoever wins, will get to marry Ayvak. Ayvak, who values games of chance over all the other things in life, agrees to thi... | ```python
# cook your dish here
# cook your dish here
for i in range(int(input())):
n,m,k=map(int,input().split())
l,ans = list(map(int,input().split())),0
for i in l:
r=i//m + 1;c=i%m
if(c==0):c=m;r-=1
ans+=r*(n+1-r)*c*(m+1-c)
ans/=((n+1)*(m+1)*n*m)//4
print(ans)
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
-----
RANJANA QUIZ
-----
Prof. Ranjana decided to conduct a quiz in her class. She divided all the students of her
class into groups of three. Consider that no student was left out after the division. She gave
different sets of questions to eve... | ```python
n=int(input())
l=[]
count=0
while n:
n-=1
a,b,c=sorted(map(int,input().split()))
if (a,b,c) in l:
count-=1
else:
l.append((a,b,c))
count+=1
print(count)
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
After seeing the "ALL YOUR BASE ARE BELONG TO US" meme for the first time, numbers X and Y realised that they have different bases, which complicated their relations.
You're given a number X represented in base b_{x} and a number Y represented ... | ```python
n, bx = list(map(int, input().split()))
x1 = list(map(int, input().split()))
x = 0
for i in range(n):
x *= bx
x += x1[i]
n, by = list(map(int, input().split()))
y1 = list(map(int, input().split()))
y = 0
for i in range(n):
y *= by
y += y1[i]
if x == y:
print('=')
elif x < y:
print('<')
else:
print('>... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Chef and his friends are playing the game AMONG US. They all have chosen their names as numbers. There are N people in Chef’s group including him, and each swears that he is not the imposter. However, it turns out there were N+1 people in the ga... | ```python
try:
n=int(input())
x=[*list(map(int, input().split()))]
y=[*list(map(int, input().split()))]
for i in y:
d=x.count(i)-y.count(i)
if d!=0:
print(i)
break
except: pass
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Chef has an old machine if the chef enters any natural number, the machine will display 1, 2, …n, n-1, n-2, n-3,…1 series and in next line prints sum of cubes of each number in the series. Chef wants to create a computer program which can replic... | ```python
t=int(input())
while(t!=0):
t=t-1
n=int(input())
ans=0
for i in range(1,n+1,1):
sum=0;
for j in range(1,i+1,1):
sum=sum+j
s=sum-i
sum=sum+s
if(i!=n):
ans=ans+2*sum*i
else:
ans=ans+sum*i
print... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Chef wants to make a feast. In order to do that, he needs a lot of different ingredients. Each ingredient has a certain tastiness; the tastiness of each ingredient may be any positive integer. Initially, for each tastiness between $K$ and $K+N-1... | ```python
__author__ = 'Prateek'
MOD = int(10**9+7)
def test():
n,k=list(map(int,input().split()))
l = k
d =n-1
ans = l-1
ans = ans%MOD
a = k-n
term = (d+a)//d
ll = (a%MOD - (((term-1)%MOD)*(d%MOD))%MOD)%MOD
if ll < 0:
ll = (ll +MOD)%MOD
m = ((term%MOD)*((a%MOD+ll%MOD)%MOD))%MOD
m = (m*pow(2,MOD-2,MOD))%... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Note that the only difference between String Transformation 1 and String Transformation 2 is in the move Koa does. In this version the letter $y$ Koa selects must be strictly greater alphabetically than $x$ (read statement for better understandi... | ```python
import sys
input = lambda: sys.stdin.readline().rstrip()
T = int(input())
for _ in range(T):
N = int(input())
A = [ord(a) - 97 for a in input()]
B = [ord(a) - 97 for a in input()]
X = [[0] * 20 for _ in range(20)]
for a, b in zip(A, B):
X[a][b] = 1
if a > b:
pri... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Snuke loves constructing integer sequences.
There are N piles of stones, numbered 1 through N.
The pile numbered i consists of a_i stones.
Snuke will construct an integer sequence s of length Σa_i, as follows:
- Among the piles with the largest... | ```python
from collections import defaultdict
N = int(input())
a = [int(i) for i in input().split()]
b = defaultdict(lambda : [float('inf'), 0])
for i in range(N) :
b[a[i]][0] = min(b[a[i]][0], i)
b[a[i]][1] += 1
# [value, first_appearance, count]
c = [(0, 0, 0)]
for k, v in b.items() :
c.append((k, v[0]... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Snuke has decided to play a game, where the player runs a railway company.
There are M+1 stations on Snuke Line, numbered 0 through M.
A train on Snuke Line stops at station 0 and every d-th station thereafter, where d is a predetermined constan... | ```python
import sys
input = sys.stdin.readline
def main():
n, m = map(int, input().split())
LR = [list(map(int, input().split())) for _ in range(n)]
BIT = [0]*(m+2)
def add(i, a):
while i <= m+1:
BIT[i] += a
i += i&(-i)
def bit_sum(i):
res = 0
while i > 0:
res += BIT[i]
... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
It's Diwali time and you are on a tour of Codepur, a city consisting of buildings of equal length and breadth because they were designed by a computer architect with a bit of OCD.
The ruling party of Codepur wants to have a blockbuster Diwali ce... | ```python
#dt = {} for i in x: dt[i] = dt.get(i,0)+1
import sys;input = sys.stdin.readline
inp,ip = lambda :int(input()),lambda :[int(w) for w in input().split()]
def kadane(arr, start, finish, n):
Sum = 0
maxSum = float('-inf')
i = None
finish[0] = -1
local_start = 0
for i in range(n... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Chef bought an electronic board and pen. He wants to use them to record his clients' signatures.
The board is a grid with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$) of pixels. Initially, all pixels are white. ... | ```python
import numpy as np
for _ in range(int(input())):
ans = np.float('inf')
n, m = (int(x) for x in input().split())
sig = np.zeros((n,m))
img = np.zeros((3*n,3*m))
for row in range(n):
sig[row,:] = np.array([int(x) for x in input()])
for row in range(n):
img[row+n,m:2*m] = np.array([int(x) for x in inpu... | |
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 new pattern. Help the chef to code this pattern problem.
-----Input:-----
- First line will contain $T$, number of testcases. Then... | ```python
# cook your dish here
import copy
for _ in range(int(input())):
k=int(input())
c=[]
d=[]
start=0
while True:
c=[]
for i in range(start):
c.append(" ")
for i in range(start,k+1):
c.append(str(i))
start+=1
d.append(c)
... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Firdavs is living on planet F. There are $N$ cities (numbered $1$ through $N$) on this planet; let's denote the value of city $i$ by $v_i$. Firdavs can travel directly from each city to any other city. When he travels directly from city $x$ to c... | ```python
# cook your dish here
import bisect
for _ in range(int(input())):
N,Q=list(map(int,input().strip().split(' ')))
V=list(map(int,input().strip().split(' ')))
VV=sorted(V)
for ___ in range(Q):
x,y=list(map(int,input().strip().split(' ')))
x-=1
y-=1
ans1=abs(V[x]-V[y])+(y-x)
post1=bisect.bisect_left... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
There are N robots and M exits on a number line.
The N + M coordinates of these are all integers and all distinct.
For each i (1 \leq i \leq N), the coordinate of the i-th robot from the left is x_i.
Also, for each j (1 \leq j \leq M), the coord... | ```python
from bisect import bisect
from collections import defaultdict
class Bit:
def __init__(self, n, MOD):
self.size = n
self.tree = [0] * (n + 1)
self.depth = n.bit_length()
self.mod = MOD
def sum(self, i):
s = 0
while i > 0:
s += self.tree[i]
... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
There are $N$ robots who work for $Y$ days and on each day they
produce some toys .on some days a few robots are given rest.
So depending on the availability of robots owner has
made a time table which decides which robots will work on
the par... | ```python
MAX = 100005
tree = [0] * MAX;
lazy = [0] * MAX;
def updateRangeUtil(si, ss, se, us, ue, diff) :
if (lazy[si] != 0) :
tree[si] += lazy[si];
if (ss != se) :
lazy[si * 2 + 1] += lazy[si];
lazy[si * 2 + 2] += lazy[si];
lazy[si] = 0;
if (ss > se or ss >... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
After finishing eating her bun, Alyona came up with two integers n and m. She decided to write down two columns of integers — the first column containing integers from 1 to n and the second containing integers from 1 to m. Now the girl wants to ... | ```python
ct=0
a, b = list(map(int, input().split(' ')))
x=[0]*5
for i in range(1, b+1):
x[i%5]+=1
for i in range(1, a+1):
ct+=x[(0-i)%5]
print(ct)
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Chef wants to host some Division-3 contests. Chef has $N$ setters who are busy creating new problems for him. The $i^{th}$ setter has made $A_i$ problems where $1 \leq i \leq N$.
A Division-3 contest should have exactly $K$ problems. Chef wa... | ```python
for T in range(int (eval(input()))):
N,K,D=list(map(int,input().split()))
A=list(map(int,input().split()))
P=sum(A)//K
print(min(P,D))
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Try guessing the statement from this picture: $3$
You are given a non-negative integer $d$. You have to find two non-negative real numbers $a$ and $b$ such that $a + b = d$ and $a \cdot b = d$.
-----Input-----
The first line contains $t$ (... | ```python
for _ in range(int(input())):
d=int(input())
anws=False
if d**2>=4*d:
root=(d**2-4*d)**0.5
a=(d+root)/2
b=(d-root)/2
anws=True
if anws:
print("Y {:.9f} {:.9f}".format(a,b))
else:
print("N")
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Chef loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Let F(X) equals to the num... | ```python
lucky = {4, 774, 7, 744, 777, 74, 747, 44, 77, 47, 474, 444, 477, 447}
from functools import lru_cache
import sys
sys.setrecursionlimit(10 ** 6)
mod = 10 ** 9 + 7
fact = [1]
for i in range(1, 1001):
fact.append(fact[-1] * i % mod)
inv = [pow(i, mod-2, mod) for i in fact]
C = lambda k, n: fact[n] * inv[n-... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Polycarp and Vasiliy love simple logical games. Today they play a game with infinite chessboard and one pawn for each player. Polycarp and Vasiliy move in turns, Polycarp starts. In each turn Polycarp can move his pawn from cell (x, y) to (x - 1... | ```python
a, b, x, y = map(int, input().split())
if a >= x:
if b >= y:
print('Vasiliy')
else:
z = y - b
t = max(x - z, 0)
if a - z <= t:
print('Polycarp')
else:
print('Vasiliy')
else:
if b <= y:
print('Polycarp')
else:
z = x... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Guddu was participating in a programming contest. He only had one problem left when his mother called him for dinner. Guddu is well aware how angry his mother could get if he was late for dinner and he did not want to sleep on an empty stomach, ... | ```python
import itertools
from collections import defaultdict as dfd
def sumPairs(arr, n):
s = 0
for i in range(n-1,-1,-1):
s += i*arr[i]-(n-1-i)*arr[i]
return s
def subarrayXor(arr, n, m):
ans = 0
xorArr =[0 for _ in range(n)]
mp = dfd(list)
xorArr[0] = arr[0]
for i in range(1, n):
xorArr[i] = xorArr[i... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
-----Problem Statement-----
Sereja has a sequence of n integers a[1], a[2], ..., a[n]. Sereja can do following transformation of the array:
- create a new sequence of n integers b[1], b[2], ..., b[n]in this way: (1 ≤ i ≤ n)
- Replace the se... | ```python
def mod(a,b,c):
x = 1
y = a
while(b>0):
if(b%2==1):
x = (x*y)%c
y = (y*y)%c
b /=2
return x%c
t = int(input())
num = 10**9+7
for i in range(t):
n,m,q,k = list(map(int,input().split()))
if m<=q:
print(0)
else:
a1 = m-q
a2 = mod(q+1,n,num)
a3 = mod(q-1,n,num)
a4 = mod(q,n,num)
a5 = a2... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Some programming contest problems are really tricky: not only do they
require a different output format from what you might have expected, but
also the sample output does not show the difference. For an example,
let us look at permutations.
A p... | ```python
def invper(ar):
ar1=[0]*(len(ar))
for i in range(len(ar)):
ar1[ar[i]-1]=i+1
return ar1
t=int(input())
while(t!=0):
ar=list(map(int,input().split()))
ar1=invper(ar)
if(ar==ar1):
print("ambiguous")
else:
print("not ambiguous")
t = int(input())
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
A group of rebels travelling on a square hoverboard is ambushed by Imperial Stormtroopers.Their big hoverboard is an easy target, so they decide to split the board into smaller square hoverboards so that they can bolt away easily.But they should... | ```python
a=int(input())
if(a%2==0):
print("4")
print(a/2,a/2,a/2,a/2)
else:
print("6")
print((a-1)/2,(a-1)/2,(a-1)/2,(a-1)/2,(a-1)/2,(a+1)/2)
``` | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
There is a grass field that stretches infinitely.
In this field, there is a negligibly small cow. Let (x, y) denote the point that is x\ \mathrm{cm} south and y\ \mathrm{cm} east of the point where the cow stands now. The cow itself is standing ... | ```python
#写経
#https://atcoder.jp/contests/abc168/submissions/14421546
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline
from bisect import bisect_left, bisect_right
INF = 10 **18
def resolve():
n, m = map(int, input().split())
a = [list(map(int, input().split())) for i in range(n)]
b = [l... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
Its Christmas time and Santa has started his ride to deliver gifts to children waiting for him in a 1-dimentional city. All houses in this city are on a number line numbered as 1, 2, 3… and so on. Santa wants to deliver to houses from n to m, bu... | ```python
from math import gcd
from math import ceil
from itertools import combinations as c
t=int(input())
for _ in range(t):
n,m,a,d=list(map(int,input().split()))
l=[]
for i in range(5):
l.append(a+i*d)
ans=m-n+1
for i in range(1,6):
x=list(c(l,i))
for j ... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
You're given an array $a_1, \ldots, a_n$ of $n$ non-negative integers.
Let's call it sharpened if and only if there exists an integer $1 \le k \le n$ such that $a_1 < a_2 < \ldots < a_k$ and $a_k > a_{k+1} > \ldots > a_n$. In particular, any st... | ```python
for _ in range(int(input())):
n=int(input())
li=list(map(int,input().split()))
ans=0
for i in range(n):
if li[i]>=i:
ans+=1
else:
break
for i in range(n):
if li[n-1-i]>=i:
ans+=1
else:
break
if ans>n:
... | |
open-r1/verifiable-coding-problems-python-10k | Solve the following coding problem using the programming language python:
John was learning mathematics and was very bored. Jane his best friend gave him a problem to solve.
The description of the problem was as follows:-
You are given a decimal number $N$(1<=$N$<=$10^9$) and three integers $A$, $B$, $C$.
Steps to ... | ```python
# Why do we fall ? So we can learn to pick ourselves up.
t = int(input())
for _ in range(0,t):
n = int(input())
abc = [int(i) for i in input().split()]
i = 0
lst = [n]
for _ in range(0,100):
k = str(lst[-1]/abc[i%3]).split('.')
if int(k[1][0]) > 0:
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.