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: 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 t = int(input()) for _ in range(t): n = int(input()) for i in range(n): for j in range(n): if i>=j: print(int((i+1)*(i+2)/2)-j,end='') print() ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Two integers A and B are the inputs. Write a program to find GCD and LCM of A and B. -----Input----- The first line contains an integer T, total number of testcases. Then follow T lines, each line contains an integer A and B. -----Output----...
```python # cook your dish here def GCD(x, y): while y: x, y = y, x % y return x def LCM(x, y): lcm = (x*y)//GCD(x,y) return lcm t = int(input()) while t>0: x,y = list(map(int,input().split())) print(GCD(x,y),LCM(x,y)) t -=1 ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Cyael is a teacher at a very famous school in Byteland and she is known by her students for being very polite to them and also to encourage them to get good marks on their tests. Then, if they get good marks she will reward them with candies :) ...
```python # cook your dish here try: t = int(input()) for _ in range(t): n, k = map(int, input().split()) if k == 0: print(0, n) else: print(n//k, n%k) except: pass ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Chef is a private detective. He was asked to investigate a case of murder in the city of Frangton. Chef arrived in Frangton to find out that the mafia was involved in the case. Chef spent some time watching for people that belong to the clan and...
```python n = eval(input()) r = list(map(int, input().split())) tree = dict() i = 1 for j in r: c = tree.get(j) if c: tree[j].append(i) else: tree[j] = [i] if not tree.get(i): tree[i] = [] i += 1 s = [] for elem in tree: if not tree[elem]: s.append(str(elem)) print(' '.join(s)) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Wet Shark once had 2 sequences: {a_n}= {a_1, a_2, a_3, ... , a_(109)} {b_n} = {b_1, b_2, b_3, ... , b_(109)} However, he only kept one element from each sequence. Luckily, both the elements that Wet Shark kept have the same index in Wet Sha...
```python import math def main(): #print("enter i, k, s") IN = '11 6 5' z = IN.split() z = input().split() i = int(z[0]) k = int(z[1]) s = int(z[2]) #print("enter a_i and b_i") IN = '4 5' z = IN.split() z = input().split() a_i = int(z[0]) b_i = int(z[1]) #print( "i = %d ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Given a number $n$, give the last digit of sum of all the prime numbers from 1 to $n$ inclusive. -----Input:----- - First line contains number of testcase $t$. - Each testcase contains of a single line of input, number $n$. -----Output:----- ...
```python # cook your dish here import math N = 10**6 sum_arr = [0] * (N + 1) def lprime(): arr = [0] * (N + 1) arr[0] = 1 arr[1] = 1 for i in range(2, math.ceil(math.sqrt(N) + 1)): if arr[i] == 0: for j in range(i * i, N + 1, i): arr[j] = 1 curr_prime...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Chef solved so many hard questions, now he wants to solve some easy problems for refreshment. Chef asks Cheffina for the new question. Cheffina challanges the chef to print the total number of 1's in the binary representation of N(natural number...
```python for t in range(int(input())): n=int(input()) print(bin(n).count("1")) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: The only difference between easy and hard versions is constraints. You are given a sequence $a$ consisting of $n$ positive integers. Let's define a three blocks palindrome as the sequence, consisting of at most two distinct elements (let these...
```python #!usr/bin/env python3 from collections import defaultdict, deque from heapq import heappush, heappop from itertools import permutations, accumulate import sys import math import bisect def LI(): return [int(x) for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def LS():return [li...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: During Quarantine Time Chef is at home and he was quite confused about what to cook so, he went to his son and asked about what would he prefer to have? He replied, cakes. Now, chef cook $N$ number of cake and number of layers for every cake is ...
```python #cook your recipe from math import factorial test_cases = int(input()) for _ in range(test_cases): n = int(input()) sum1 = 0 final_sum = 0 num = list(map(int, input().split())) rep_time = factorial(n - 1) rep_count = dict() for i in num: if i in rep_count: rep_count[i] +=1 ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: There are $n$ persons who initially don't know each other. On each morning, two of them, who were not friends before, become friends. We want to plan a trip for every evening of $m$ days. On each trip, you have to select a group of people that ...
```python from collections import deque def solve(adj, m, k, uv): n = len(adj) nn = [len(a) for a in adj] q = deque() for i in range(n): if nn[i] < k: q.append(i) while q: v = q.popleft() for u in adj[v]: nn[u] -= 1 if nn[u] == k-1: ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Given a positive integer K > 2, with prime factorization: K = p1^a1 * p2^a2 ... * pn^an Compute the following: S = a1*p1 + a2*p2 ... + an*pn. -----Input----- A list of <100 integers, one on each line, all less than $2*10^{18}$. -----Output-...
```python import random import os yash=(2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,3...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: There are some ambiguities when one writes Berland names with the letters of the Latin alphabet. For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "...
```python n = int(input()) s = set() for a in range(n): name = input() name = name.replace('u', 'oo') while (name.count('kh') > 0): name = name.replace('kh', 'h') s.add(name) print(len(s)) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: The only difference between easy and hard versions is constraints. Now elections are held in Berland and you want to win them. More precisely, you want everyone to vote for you. There are $n$ voters, and two ways to convince each of them to vo...
```python import sys def I(): return sys.stdin.readline().rstrip() class Heap: def __init__( self ): self.l = [ -1 ] self.n = 0 def n( self ): return self.n def top( self ): return self.l[ 1 ] def ins( self, x ): self.l.append( x ) n = len( self.l ) -...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: You are given a string s of length n. Does a tree with n vertices that satisfies the following conditions exist? - The vertices are numbered 1,2,..., n. - The edges are numbered 1,2,..., n-1, and Edge i connects Vertex u_i and v_i. - If the i...
```python s = input() if s[0] == '0' or s[-2] == '0' or s[-1] == '1': # 's' should be like "1xx...x0" print((-1)) elif s[:-1] != s[-2::-1]: print((-1)) else: half = len(s) // 2 one_indices = [i+1 for i in range(1, half) if s[i] == '1'] # not including 0 or larger than n//2 parents = [0] * (len(s)...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: You are given an array $a$ of length $n$. A subsequence of this array is valid, if it satisfies these two conditions: - There shouldn't be any two even numbers within a distance of $K$, both which have been chosen in the subsequence. i.e. there ...
```python import sys import math def main(arr,k): x=[] y=[] for e in arr: if e%2==0: x.append(e) y.append(0) else: x.append(0) y.append(e) a=[0]*n b=[0]*n a[0]=x[0] b[0]=y[0] for i in range(1,n): if i<k: a[i]=max(x[i],a[i-1]) b[i]=max(y[i],b[i-1]) else: a[i]=max(x[...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Mister B once received a gift: it was a book about aliens, which he started read immediately. This book had c pages. At first day Mister B read v_0 pages, but after that he started to speed up. Every day, starting from the second, he read a pag...
```python read = lambda: map(int, input().split()) c, v0, v1, a, l = read() cur = 0 cnt = 0 while cur < c: cur = max(0, cur - l) cur += min(v1, v0 + a * cnt) cnt += 1 print(cnt) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: It is a balmy spring afternoon, and Farmer John's n cows are ruminating about link-cut cacti in their stalls. The cows, labeled 1 through n, are arranged so that the i-th cow occupies the i-th stall from the left. However, Elsie, after realizing...
```python # You lost the game. n,k = map(int, input().split()) r = 0 for i in range(min(k,n//2)): r += (n-2*i-1) + (n-2*i-2) print(r) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Salmon loves to be a tidy person. One day, when he looked at the mess that he made after playing with his rubber ducks, he felt awful. Now he wants to clean up his mess, by placing his ducks into boxes. Each rubber duck has a color. There are a ...
```python # cook your dish here for _ in range(int(input())): n,k=map(int,input().split()) c=[int(i) for i in input().split()] i=0 m=0 if(n==2 and k==5): c1=c c.sort() d=dict() for i in range(len(c)): for j in range(len(c1)): if(c[i]==c1[j]): d[i]=j c1[j]=-1 break while(m<n): ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Gru has not been in the limelight for a long time and is, therefore, planning something particularly nefarious. Frustrated by his minions' incapability which has kept him away from the limelight, he has built a transmogrifier — a machine which m...
```python for i in range(int(input())): yy=input() y=[int(e) for e in yy.split()] zz=input() z=[int(e) for e in zz.split()] count=0 for i in z: a=i+y[1] if a%7==0: count+=1 print(count) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Mark loves eating chocolates and also likes to be fit. Given the calorie count for every chocolate he eats, find what he has to do to burn the calories. The name of the chocolates along with its calorie count are given as follows: Calories per ...
```python # cook your dish here d = { 'D': 238, 'T': 244, 'M': 138, 'B': 279, 'C': 186 } s = list(input()) totalCal = 0 for i in range(len(s)): if s[i] == 'D': totalCal += d['D'] if s[i] == 'T': totalCal += d['T'] if s[i] == 'M': totalCal += d['M'] if s[i] == 'B': tota...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Chef Watson uses a social network called ChefBook, which has a new feed consisting of posts by his friends. Each post can be characterized by f - the identifier of the friend who created the post, p - the popularity of the post(which is pre-calc...
```python import sys ans=0 n,m=list(map(int,input().split())) aaaaa=100 li=list(map(int,input().split())) non_special,special=[],[] for i in range(m): ans+=1 f,p,s=list(map(str,input().split())) f=int(f) poww=pow(1,2) p=int(p) if f not in li: ans+=1 non_special.append((p,s)) ans-=1 else: ans+=1 special...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: As lockdown is going on so no is allowed to go outside , so Chef has come with an innovative idea for food home delivery using drone. But there is an issue with it , the drone can move forward or backward a fix number of steps $x$ . All the ho...
```python # cook your dish here import math try: n,d=map( int,input().split() ) a=list(map(int,input().split())) a.sort() z=abs(a[0]-d) for j in range(n): x=abs(a[j]-d) z=math.gcd(x,z) print(z) except: pass ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Sebi goes to school daily with his father. They cross a big highway in the car to reach to the school. Sebi sits in front seat beside his father at driving seat. To kill boredom, they play a game of guessing speed of other cars on the highway. S...
```python # cook your dish here n=int(input()) for i in range(n): S, SG, FG, D, T = map(int, input().split()) speed = (D*180)/T + S if abs(SG-speed) == abs(FG-speed): print('DRAW') elif abs(SG-speed) > abs(FG-speed): print('FATHER') else: print('SEBI') ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: In Chefland, types of ingredients are represented by integers and recipes are represented by sequences of ingredients that are used when cooking. One day, Chef found a recipe represented by a sequence $A_1, A_2, \ldots, A_N$ at his front door an...
```python # cook your dish here for __ in range(int(input())): n=int(input()) arr=list(map(int,input().split())) d={} s=set() flag=0 for i in range(n): if arr[i] in list(d.keys()): d[arr[i]]+=1 else: d[arr[i]]=1 curr_ele=arr[i] if (curr_ele in s) and arr[i-1]!=arr[i]: flag=1 break else: ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: The round carousel consists of $n$ figures of animals. Figures are numbered from $1$ to $n$ in order of the carousel moving. Thus, after the $n$-th figure the figure with the number $1$ follows. Each figure has its own type — the type of the ani...
```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()] if max(A) == min(A): print(1) print(*([1] * N)) elif N % 2 == 0: print(2) print(*([1, 2] * (N // 2))) el...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: The Little Elephant from the Zoo of Lviv has an array A that consists of N positive integers. Let A[i] be the i-th number in this array (i = 1, 2, ..., N). Find the minimal number x > 1 such that x is a divisor of all integers from array A. Mor...
```python from math import sqrt,gcd for _ in range(int(input())): n=int(input()) ar=[int(x) for x in input().split()] g=ar[0] for i in range(1,n): g=gcd(g,ar[i]) f=g for i in range(2,int(sqrt(g))+1): if g%i==0: f=i break if g!=1: print(f)...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: ZCO is approaching, and you want to be well prepared! There are $N$ topics to cover and the $i^{th}$ topic takes $H_i$ hours to prepare (where $1 \le i \le N$). You have only $M$ days left to prepare, and you want to utilise this time wisely. ...
```python import math T=int(input()) for i in range(T): N,M,S=input().split() N=int(N) M=int(M) S=int(S) ls=list(map(int,input().split())) maxx=max(ls) if S<17 and maxx<=50: ls.sort() total_sum = M * S count = 0 sum = 0 for i in ls: if i / S > 2: continue else: sum = sum + math.ceil(i / S...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: You have a large electronic screen which can display up to $998244353$ decimal digits. The digits are displayed in the same way as on different electronic alarm clocks: each place for a digit consists of $7$ segments which can be turned on and o...
```python for _ in range(int(input())): n = int(input()) if(n%2): print("7"+"1"*((n-3)//2)) else: print("1"*(n//2)) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Polo, the Penguin, likes numbers. He says that the goodness of a number is itself multiplied by the number of digits in it's decimal representation. For example, the goodness of the integer 474 is 474*3 = 1422. Help him to count the sum of goodn...
```python # cook your dish here from sys import stdin from math import sqrt,ceil,log10 def get_sum(a,b,digits): sum=((b+a)*(b-a+1))//2 return sum*digits def solve(): mod=10**9+7 thehighlimiter={i: 10 ** i - 1 for i in range(12)} thelowlimiter={i: 10**i for i in range(12)} for _ in range(int(inp...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Lucy had recently learned the game, called Natural Numbers. The rules of the game are really simple. There are N players. At the same time, every player says one natural number. Let's call the number said by the i-th player Ai. The person with t...
```python try: t = int(input()) while t: t -= 1 n = int(input()) arr = [] obj = {} for i in range(n): x,y = input().split() y = int(y) arr.append([x, y]) if y in obj: obj[y].append(x) else: obj[y] = [x] a...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Petya learned a new programming language CALPAS. A program in this language always takes one non-negative integer and returns one non-negative integer as well. In the language, there are only three commands: apply a bitwise operation AND, OR or...
```python from operator import __or__, __and__, __xor__ from sys import stdin, stdout n, b, c = int(stdin.readline()), 0, 1023 m = {'|': __or__, '&': __and__, '^': __xor__} for i in range(n): t, v = [i for i in stdin.readline().split()] b = m[t](b, int(v)) c = m[t](c, int(v)) x, o, a = 0, 0, 1023 for i in r...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Chef’s girlfriend is angry with him because he forgot her birthday. Chef decided to please her by gifting her a Love Graph. Chef has $N$ vertices: $V_1, V_2, \dots, V_N$. Love Graph is an undirected multigraph with no self-loops and can be cons...
```python def fastpow(base, power): result = 1 while power > 0: if power % 2 == 0: power = power // 2 base = base * base else: power = power - 1 result = result * base power = power // 2 base = base * base return result t=int(input()) for i in range(t): a=list(map(int,input().split())) n,r=...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: You are given a sequence $A_1, A_2, \ldots, A_N$. You should select a (not necessarily contiguous) subsequence of $A$ and reverse it. In other words, if you select a subsequence $A_{i_1}, A_{i_2}, \ldots, A_{i_K}$ ($1 \le i_1 < \ldots < i_K \le ...
```python for _ in range(int(input())): n = int(input()) a = list(map(int,input().split())) ans = 0 count = 0 for i in a: if i>0: ans+=i count+=1 res = [] for i in range(count): if a[i]<=0: res.append(i+1) for i in range(count,n): if a[i]>0: res.append(i+1) print(ans) print(len(res),*res) ``...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Vasya has ordered a pizza delivery. The pizza can be considered a perfect circle. There were $n$ premade cuts in the pizza when it was delivered. Each cut is a straight segment connecting the center of the pizza with its boundary. Let $O$ be the...
```python def gcd(a, b): if a == 0: return b return(gcd(b % a, a)) t = int(input()) for T in range(t): n = int(input()) l = [int(x) for x in input().split()] ang = [] for i in range(1, n): ang.append(l[i] - l[i - 1]) ang.append(360 - (l[-1] - l[0])) ang.sort() if ang == ang[::-1]: print(0) continue ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Ujan has a lot of numbers in his boxes. He likes order and balance, so he decided to reorder the numbers. There are $k$ boxes numbered from $1$ to $k$. The $i$-th box contains $n_i$ integer numbers. The integers can be negative. All of the inte...
```python def main(): k = int(input()) n = [] a = [] for i in range(k): line = [int(x) for x in input().split()] ni = line[0] ai = [] n.append(ni) a.append(ai) for j in range(ni): ai.append(line[1 + j]) answer, c, p = solve(k, n, a) if...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Someone gave Alyona an array containing n positive integers a_1, a_2, ..., a_{n}. In one operation, Alyona can choose any element of the array and decrease it, i.e. replace with any positive integer that is smaller than the current one. Alyona c...
```python x=int(input()) l=list(map(int, input().split(' '))) l.sort() a=1 for i in l: if i>=a: a+=1 print(a) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Sereja has a string A consisting of n lower case English letters. Sereja calls two strings X and Y each of length n similar if they can be made equal by applying the following operation at most once in each of them. - Chose any two position i...
```python import math def egcd(a, b): if a == 0: return (b, 0, 1) else: g, y, x = egcd(b % a, a) return (g, x - (b // a) * y, y) def modin(a, m): g, x, y = egcd(a, m) return x % m # def gcdexten(a,b,x,y): # if a == 0: # x = 0 # y = 1 # return b # x1 = y1 = 0 # gcd = gcd...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: "Don't Drink and Drive, but when you do, Better Call Saul." Once Jesse and Walter were fighting over extra cash, and Saul decided to settle it with a game of stone piles whose winner gets the extra money. The game is described as follows : There...
```python n=int(input()) for i in range(n): k,x=map(int,input().split()) l=list(map(int,input().split())) f,e,o=0,0,0 for i in l: if(i%2==0): e+=1 else: o+=1 if(o<=x//2): f=1 elif(e<=x//2): if((k-x)%2!=0): f=0 else: f=1 else: if(x%2==0): ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Tara was completing an Algorithms assignment and got stuck on a question. She thought of who can help her, and got reminded of Kabir who has good problem solving skills. The question is: Given N$N$ the number of elements in the sequence A1$A_1$,...
```python # cook your dish here store=[0]*(10**5+1) def sieve(): for i in range(2,10**5+1): if(store[i]==0): store[i]=1 for j in range(i,10**5+1,i): store[j]=i sieve() # print(store) for _ in range(int(input())): n=int(input()) li=[int(x) for x in input().split()] dp=[0]*(10**5+1) for i in li: dp[...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Bob recently read about bitwise operations used in computers: AND, OR and XOR. He have studied their properties and invented a new game. Initially, Bob chooses integer m, bit depth of the game, which means that all numbers in the game will cons...
```python import sys def calc(b0, b1, q): if q == 0: return b0 ^ b1 if q == 1: return b0 | b1 if q == 2: return b0 & b1 n, m = list(map(int,sys.stdin.readline().split())) arr1 = {} opt = ['XOR', 'OR', 'AND'] arr2 = [] for j in range(n): a, b = list(map(str,sys.stdin.readline().sp...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Neko loves divisors. During the latest number theory lesson, he got an interesting exercise from his math teacher. Neko has two integers $a$ and $b$. His goal is to find a non-negative integer $k$ such that the least common multiple of $a+k$ an...
```python from math import gcd a, b = list(map(int, input().split())) if b < a: a, b = b, a if a == b: print(0) return c = b - a i = 1 ans = a * b // gcd(a, b) def get(x): A = (a + x - 1) // x * x B = A - a + b return A * B // gcd(A, B), A r = 0 while i * i <= c: if c % i == 0: A, ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Shashank is playing a game with his friends. There are n sticks located in a row at points $a_1,a_2, ...,a_n$. Each stick has a height- $h_i$. A person can chop a stick down, after which it takes over one of the regions [$a_i$ - $h_i$, $a_i$] or...
```python # cook your dish here n=int(input()) counts=dict() z=0 upper=None for i in range(0,n): a,h= [int(num) for num in input().split()] counts[a]=h for key,count in counts.items(): c=0 x=key-count y=key+count c1=0 c2=0 for j in counts.keys(): if j==key: continue else: if x<=j<=key: c1=0 br...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: You are given positive integers $N$ and $D$. You may perform operations of the following two types: - add $D$ to $N$, i.e. change $N$ to $N+D$ - change $N$ to $\mathop{\mathrm{digitsum}}(N)$ Here, $\mathop{\mathrm{digitsum}}(x)$ is the sum of de...
```python from collections import deque T=int(input()) def break_down(num): count=0 while(len(num)!=1): temp=0 for i in range(0,len(num)): temp=temp+int(num[i]) num=str(temp) count=count+1 return (int(num),count) def digit_sum(num): temp=0 fo...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: You are given $n$ intervals on the $X$ axis. Each interval $i$ is specified by its ends $[L_i, R_i]$. You want to color each interval either blue or yellow. After coloring all the intervals, the $X$ axis will will have $4$ colors: - White, the p...
```python for _ in range(int(input())): n = int(input()) ls = [] rs = [] lrs = [] for i in range(n): l, r = map(int, input().split()) ls.append(l) rs.append(r) lrs.append((l, r, i)) lrs.sort() c = 0 maxi = -1 res = [-1] * n for l, r, i in lrs: if ls[i] > maxi: maxi = rs[i] res[i] = c el...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: The notorious hacker group "Sed" managed to obtain a string $S$ from their secret sources. The string contains only lowercase English letters along with the character '?'. A substring of $S$ is a contiguous subsequence of that string. For exampl...
```python def convertToParitys(s): """ This converts the string s to an int, which is a bitMap of the parity of each letter odd ? = first bit set odd a = second bit set odd b = third bit set etc """ keys = '?abcdefghijklmnopqrstuvwxyz' paritys = {c:0 for c in keys} for...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: There is a haunted town called HauntedLand. The structure of HauntedLand can be thought of as a grid of size n * m. There is a house in each cell of the grid. Some people have fled from their houses because they were haunted. '.' represents a ha...
```python import math t = int(input().strip()) for _ in range(t): n, m = list(map(int, input().strip().split())) a = [] v = [-1] * 4 for i in range(n): a.append(input().strip()) for i, ai in enumerate(a): if ai.find('*') > -1: v[2] = i break if v[2] == -1: print(0) else: for i, ai in reverse...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum....
```python n = int(input()) a = list(map(int, input().split())) res = 0 new_a = [] for i in range(n): if a[i] % 2 == 0: if a[i] > 0: res += a[i] else: new_a.append(a[i]) a = new_a a.sort() res += a[-1] a.pop() while len(a) > 1: if a[-1] + a[-2] > 0: res += a[-1] + a[-2] ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: You have a rectangular chocolate bar consisting of n × m single squares. You want to eat exactly k squares, so you may need to break the chocolate bar. In one move you can break any single rectangular piece of chocolate in two rectangular piec...
```python mem = [[[0 for i in range(51)] for j in range(31)] for k in range(31)] def f(n, m, k): if mem[n][m][k]: return mem[n][m][k] if (n*m == k) or (k == 0): return 0 cost = 10**9 for x in range(1, n//2 + 1): for z in range(k+1): cost = min(cost, m*m + f(n-x, m, ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Chef is very organised in whatever he does and likes to maintain statistics of his work. Chef has expertise in web development and hence is a regular contributor on a forum. Chef sometimes makes multiple contributions in a single day.. Each day ...
```python from collections import Counter t=int(input()) for i in range(t): k=int(input()) l=list(map(int,input().split())) a=Counter(l) b=list(a.keys()) b.sort() for x in b: s=str(x)+': '+str(a[x]) print(s) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Kostya likes the number 4 much. Of course! This number has such a lot of properties, like: - Four is the smallest composite number; - It is also the smallest Smith number; - The smallest non-cyclic group has four elements; - Four is the maximal...
```python # cook your dish here x=int(input()) for i in range(x): h=input() print(h.count('4')) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: You and your friend are playing the game Mortal Kombat XI. You are trying to pass a challenge tower. There are $n$ bosses in this tower, numbered from $1$ to $n$. The type of the $i$-th boss is $a_i$. If the $i$-th boss is easy then its type is ...
```python import math from collections import deque from sys import stdin, stdout from string import ascii_letters import sys letters = ascii_letters input = stdin.readline #print = stdout.write for _ in range(int(input())): n = int(input()) arr = list(map(int, input().split())) ans = [999999999] * n a...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Gennady is one of the best child dentists in Berland. Today n children got an appointment with him, they lined up in front of his office. All children love to cry loudly at the reception at the dentist. We enumerate the children with integers f...
```python import sys n = int(input()) v = [ list(map(int, input().split())) for i in range(n)] res = [] for i in range(n): if v[i][2] >= 0: res.append(i + 1) dec = 0 for j in range(i + 1, n): if v[j][2] >= 0: if v[i][0] > 0: v[j][2] -= v[i][0] v[i][0] -= 1 v[j][2] -= dec if v[j][2] <...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: A tennis tournament is about to take place with $N$ players participating in it. Every player plays with every other player exactly once and there are no ties. That is, every match has a winner and a loser. With Naman's birthday approaching, he...
```python # cook your dish here a = int(input()) for i in range(a): n = int(input()) if n%2==0: print('NO') else: print('YES') for i1 in range(n): li = [0]*n b = str() for i2 in range((n-1)//2): li[(i1+i2+1)%n]+=1 for i3 in range(len(li)): b+=str(li[i3]) print(b) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Iahub is very proud of his recent discovery, propagating trees. Right now, he invented a new tree, called xor-tree. After this new revolutionary discovery, he invented a game for kids which uses xor-trees. The game is played on a tree having n ...
```python import sys def dfs(tree, root, priv_root, cur_lvl, priv_lvl, diff, pick_list): if not tree: return stack = [(root, priv_root, cur_lvl, priv_lvl)] while stack: (root, priv_root, cur_lvl, priv_lvl) = stack.pop() if cur_lvl ^ diff[root]: cur_lvl ^= 1 p...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Bob is playing with $6$-sided dice. A net of such standard cube is shown below. [Image] He has an unlimited supply of these dice and wants to build a tower by stacking multiple dice on top of each other, while choosing the orientation of each ...
```python n = input() a = list(map(int, input().split())) for i in a: if i % 7 == 0 or (i // 7) % 2 == 1 or i <= 14: print('NO') else: print('YES') ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Chef's pizza is the tastiest pizza to exist, and the reason for that is his special, juicy homegrown tomatoes. Tomatoes can be grown in rectangular patches of any side lengths. However, Chef only has a limited amount of land. Consider the enti...
```python from math import * def list_input(): return list(map(int,input().split())) def map_input(): return list(map(int,input().split())) def map_string(): return input().split() def g(n): return (n*(n+1)*(2*n+1))//6 def f(n): ans = 0 for i in range(1,floor(sqrt(n))+1): ans+=i*(i+floor(n/...
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 a0 in range(int(input())): n = int(input()) l = [] for i in range(1,n+1): l.append(i) for j in range(n): s = "" for k in l: s+=str(k) print(s) x = l[0] l.pop(0) l.append(x) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Johnny was asked by his math teacher to compute nn (n to the power of n, where n is an integer), and has to read his answer out loud. This is a bit of a tiring task, since the result is probably an extremely large number, and would certainly kee...
```python from math import log10 from decimal import Decimal def solve(n,k): mod=10**k x=Decimal(n) y=x*(x.log10())%1 p=str(pow(10,y)) c=0 first='' for v in p: if c==k: break if v==".": continue first+=v c+=1 last=str(pow(n,n,mod)).zfill(k) return (first,last) queries=[] for _ in range(int(inpu...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: There are n beacons located at distinct positions on a number line. The i-th beacon has position a_{i} and power level b_{i}. When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within dis...
```python n = int(input()) pos_blast = [list(map(int, input().split())) for _ in range(n)] MAX_N = max(pos_blast, key=lambda x: x[0])[0] + 2 power = [0 for _ in range(MAX_N)] tower = [False for _ in range(MAX_N)] can_destroy = [0 for _ in range(MAX_N)] for pos, blast in pos_blast: pos += 1 tower[pos] = True ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Chef and Paja are bored, so they are playing an infinite game of ping pong. The rules of the game are as follows: - The players play an infinite number of games. At the end of each game, the player who won it scores a point. - In each game, one ...
```python n=int(input()) while(n>0): x,y,z=map(int,input().split()) t=(x+y)//z if t%2==0: print('Chef') else: print('Paja') n-=1 ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: After a long and successful day of preparing food for the banquet, it is time to clean up. There is a list of n jobs to do before the kitchen can be closed for the night. These jobs are indexed from 1 to n. Most of the cooks have already left a...
```python T = int(input()) for _ in range(T): n,m = map(int,input().split()) completed = list(map(int,input().split())) jobs = [] for i in range(1,n+1): if i not in completed: jobs.append(i) jobs.sort() chef = [] ass = [] for i in range(len(jobs)): if i%2==0: chef.append(str(jobs[i])) else: ass.a...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: You are given two points $P$ and $Q$ and an opaque sphere in a three-dimensional space. The point $P$ is not moving, while $Q$ is moving in a straight line with constant velocity. You are also given a direction vector $d$ with the following mean...
```python # cook your dish here epi=10**-2 def vision(t): a1=x0+(dx*t)-x1 a2=y0+(dy*t)-y1 a3=z0+(dz*t)-z1 b=4*((a1*d1)+(a2*d2)+(a3*d3))*((a1*d1)+(a2*d2)+(a3*d3)) a=4*((a1*a1)+(a2*a2)+(a3*a3)) value=(b-(a*c)) return value xrange=range for _ in range(int(input())): x1,y1,z1,x0,y0,z0,dx,dy,dz,cx,cy,cz,r=list(map(i...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: "I'm a fan of anything that tries to replace actual human contact." - Sheldon. After years of hard work, Sheldon was finally able to develop a formula which would diminish the real human contact. He found k$k$ integers n1,n2...nk$n_1,n_2...n_k...
```python t = int(input()) def conv(n): k = bin(n) k = k[2:] z = len(k) c = '1'*z if c == k: return False def find(n): x = bin(n)[2:] str = '' for i in x[::-1]: if i == '0': str+='1' break else: str+='0' return int(str[::-1],2) for i in range(t):...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Everyone loves short problem statements. Given a function $ f(x) $ find its minimum value over the range $ 0 < x < π/2$ $ f(x) = ( x^2 + b*x + c ) / sin( x ) $ -----Input:----- - First-line will contain $T$, the number of test cases. Then the t...
```python import sys import math input=sys.stdin.readline def binary(l,r,co,b,c): x=(l+r)/2 #print(x) val1=(2*x+b)*math.sin(x) val2=(x**2+b*x+c)*math.cos(x) x=(l+r)/2 val=val1-val2 if(abs(val)<.0000001 or co==150): return (l+r)/2 if(val<0): return binary((l+r)/2,r,co+1,b,c) else: return binary(l,(l+r)/2,...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: You have unweighted tree of $n$ vertices. You have to assign a positive weight to each edge so that the following condition would hold: For every two different leaves $v_{1}$ and $v_{2}$ of this tree, bitwise XOR of weights of all edges on th...
```python n = int(input()) g = [[] for i in range(n)] for i in range(n-1): u,v = [int(i)-1 for i in input().split()] g[u].append(v) g[v].append(u) leaf = [len(i)==1 for i in g] root = -1 mx = n-1 for i in range(n): if leaf[i]: root = i leafs = 0 for j in g[i]: if leaf[j]: ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Chef Loves to listen to remix songs, but currently he had already finished the entire playlist of remix songs. As Chef is smart, so he thought let's make my own remix songs of the original songs. Chef is not having much knowledge of making remix...
```python m= 9999999 word='' p= '' try: s=input().split() for i in s: if(len(i) <= m): m = len(i) word = i p = word for i in s: p+= (' '+i+' '+ word) print(p) except EOFError: pass `...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Due to the COVID pandemic, people have been advised to stay at least $6$ feet away from any other person. Now, people are lining up in a queue at the local shop and it is your duty to check whether they are all following this advice. There are a...
```python # cook your dish here t=int(input()) while t>0: n=int(input()) l=list(map(int,input().split())) l1=[] c=1 for i in range(len(l)): if l[i]==1: l1.append(i) for j in range(len(l1)-1): if l1[j+1]-l1[j]<6: c=0 break if c: prin...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Every great chef knows that lucky numbers are positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Our chef has recently returned from the Luc...
```python import sys import os def __starting_point(): start = 0 for line in sys.stdin: if start == 0: start = 1 continue else: try: n = int(line.strip()) # print n q = ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: You are given a set Y of n distinct positive integers y_1, y_2, ..., y_{n}. Set X of n distinct positive integers x_1, x_2, ..., x_{n} is said to generate set Y if one can transform X to Y by applying some number of the following two operation ...
```python def main(): from heapq import heapify, heapreplace input() s = set(map(int, input().split())) xx = [-x for x in s] heapify(xx) while True: x = -xx[0] while x != 1: x //= 2 if x not in s: s.add(x) heapreplace(xx, -x...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: The Little Elephant loves permutations of integers from 1 to n very much. But most of all he loves sorting them. To sort a permutation, the Little Elephant repeatedly swaps some elements. As a result, he must receive a permutation 1, 2, 3, ..., ...
```python inp = input().split(' ') val=[]; totNums = int(inp[0]); totOpt = int(inp[1]); inp = input().split(' '); #assert(len(inp) == totNums); for it in inp: val.append(int(it)) dp = [[0.0 for _ in range(0,totNums)] for __ in range(0,totNums)] for i in range(0,totNums): for j in range(0,totNums): if val[...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Chef Ciel wants to put a fancy neon signboard over the entrance of her restaurant. She has not enough money to buy the new one so she bought some old neon signboard through the internet. Ciel was quite disappointed when she received her order - ...
```python from math import gcd import sys input=lambda : sys.stdin.readline().strip() c=lambda x: 10**9 if(x=="?") else int(x) def main(): for _ in range(int(input())): s=list(input())[::-1] l=['F','E','H','C'] i=0 while(i<len(s)): if(i+3<len(s)): f=True for j in range(i,i+4): if(l[j-i]==s[j] o...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: It is Borya's eleventh birthday, and he has got a great present: n cards with numbers. The i-th card has the number a_{i} written on it. Borya wants to put his cards in a row to get one greater number. For example, if Borya has cards with number...
```python mod = 998244353 f0 = [ [0 for i in range(11)] for j in range(2010) ] f1 = [ [0 for i in range(11)] for j in range(2010) ] fac = [0 for i in range(2010)] tab = [0 for i in range(11)] C = [ [0 for i in range(2010)] for j in range(2010) ] def Init() : fac[0] = 1 for i in range(2010) : if i > 0 :...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Berland year consists of $m$ months with $d$ days each. Months are numbered from $1$ to $m$. Berland week consists of $w$ days. The first day of the year is also the first day of the week. Note that the last week of the year might be shorter tha...
```python import sys readline = sys.stdin.readline readlines = sys.stdin.readlines ns = lambda: readline().rstrip() ni = lambda: int(readline().rstrip()) nm = lambda: map(int, readline().split()) nl = lambda: list(map(int, readline().split())) prn = lambda x: print(*x, sep='\n') def gcd(a, b): while b: a,...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Chef is interested to solve series problems. Chef wants to solve a series problem but he can't solve it till now.Can you help Chef to solve the series problem? - In series problem, the series goes as follows 1,9,31,73,141 . . . . . . . . Your ...
```python # cook your dish here try: for t in range(int(input())): n=int(input()) ans=n*n*n+((n-1)**2) if ans<=10**9+7: print(ans) else: print(ans)%(10**9+7) except: pass ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make the ticket lucky. The ticket is...
```python x=int(input()) def s(a): r=0 while a>0: r+=a%10 a//=10 return r def d(a,b): r=0 for i in range(6): if a%10!=b%10: r += 1 a//=10 b//=10 return r c=6 for i in range(1000000): if s(i%1000)==s(i//1000): c=min(c,d(x,i)) print(c) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Ivan is collecting coins. There are only $N$ different collectible coins, Ivan has $K$ of them. He will be celebrating his birthday soon, so all his $M$ freinds decided to gift him coins. They all agreed to three terms: Everyone must gift as ma...
```python n, m, k, l = map(int, input().split()) cnt = (k + l + m - 1) // m if cnt * m > n: print(-1) else: print(cnt) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: You are given a set of points in the 2D plane. You start at the point with the least X and greatest Y value, and end at the point with the greatest X and least Y value. The rule for movement is that you can not move to a point with a lesser X va...
```python from math import sqrt def get_distance(x1,y1,x2,y2): return sqrt((x1-x2)**2 + (y1-y2)**2) T = int(input()) ans = [] for _ in range(T): blank = input() N = int(input()) C = [[] for i in range(10**4+1)] for i in range(N): x,y = [int(i) for i in input().split()] C[x].appe...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Voritex a big data scientist collected huge amount of big data having structure of two rows and n columns. Voritex is storing all the valid data for manipulations and pressing invalid command when data not satisfying the constraints. Voritex lik...
```python import math import os import random import re import sys r = 100000 prev = 1 s = set() for i in range(1, r+1): now = i ^ prev s.add(now) prev = now s = list(s) t = int(input()) while t > 0: t -= 1 n, k = list(map(int, input().split())) if n > 3: if n % 2...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Bandwidth of a matrix A is defined as the smallest non-negative integer K such that A(i, j) = 0 for |i - j| > K. For example, a matrix with all zeros will have its bandwith equal to zero. Similarly bandwith of diagonal matrix will also be zero. ...
```python t = int(input()) for i in range(t): n = int(input()) A = [] for i in range(0, n): A.append([int(i) for i in input().split()]) ones = sum([sum(i) for i in A]) compare = n ans = 0 for i in range(0, n): if ones <= compare: ans = i br...
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 integers (1-based indexing). He asks you to perform the following operation M times: for i = 2 to N: Ai = Ai + Ai-1 Your task is to find the xth element of the array (i.e., Ax) after performing the above ...
```python for _ in range(int(input())): n,x,m = map(int,input().split()) a = list(map(int,input().split())) for _ in range(m): for i in range(1,n): a[i] = a[i] + a[i-1] print(a[x-1]%(10**9+7)) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Sam has been teaching Jon the Game of Stones to sharpen his mind and help him devise a strategy to fight the white walkers. The rules of this game are quite simple: The game starts with n piles of stones indexed from 1 to n. The i-th pile conta...
```python n = int(input()) arr = [int(input()) for i in range(n)] b = [0 for i in range(n)] s = 0 for i in range(n): j = int((arr[i] << 1) ** 0.5) if j * (j + 1) > (arr[i] << 1): j -= 1 s ^= j if s != 0: print('NO') else: print('YES') ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Greg has a weighed directed graph, consisting of n vertices. In this graph any pair of distinct vertices has an edge between them in both directions. Greg loves playing with the graph and now he has invented a new game: The game consists of n s...
```python import sys from array import array # noqa: F401 n = int(input()) matrix = [array('i', list(map(int, input().split()))) for _ in range(n)] aa = tuple([int(x) - 1 for x in input().split()]) ans = [''] * n for i in range(n-1, -1, -1): x = aa[i] for a in range(n): for b in range(n): ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Doctor Kunj installed new software on cyborg Shresth. This software introduced Shresth to range minimum queries. Cyborg Shresth thought of T$T$ different problems in each of which you will be given an array A$A$ of length N$N$ and an array B$B$ ...
```python def f(a,n): l,r,s1,s2 = [0]*n, [0]*n, [], [] for i in range(n): count = 1 while(len(s1)>0 and a[i]<s1[-1][0]): count += s1[-1][1] s1.pop() s1.append((a[i],count)) l[i] = count for i in range(n-1,-1,-1): count = 1 while(len(s2)>0 and a[i]<=s2[-1][0]): ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Naturally, the magical girl is very good at performing magic. She recently met her master wizard Devu, who gifted her R potions of red liquid, B potions of blue liquid, and G potions of green liquid. - The red liquid potions have liquid amoun...
```python import sys import math import heapq def half(n): return n//2 def main(arr,m): a,b,c=arr while m!=0: s=max(a,b,c) if s==a: a=half(a) elif s==b: b=half(b) else: c=half(c) m-=1 return max(a,b,c) for i in range(int(input())): r,g,b,m=list(map(int,input().split())...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS: You are given two integers $d, m$, find the number of arrays $a$, satisfying the following constraints: The length of $a$ is $n$, $n \...
```python t = int(input()) for _ in range(t): d, m = list(map(int, input().split())) d += 1 out = 1 curr = 2 while curr < d: out *= (curr // 2) + 1 out %= m curr *= 2 out *= (d - curr // 2 + 1) print((out - 1) % m) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Let's consider a simplified version of order book of some stock. The order book is a list of orders (offers) from people that want to buy or sell one unit of the stock, each order is described by direction (BUY or SELL) and price. At every mome...
```python import heapq n = int(input()) buy = [] # negative sell = [] unknown = [] res = 1 for i in range(n): cmd, amount = input().strip().split() amount = int(amount) if cmd == 'ADD': if sell and sell[0] < amount: heapq.heappush(sell, amount) elif buy and -buy[0] > amount: ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: In a bizarre game of chess ,knight was so drunk, that instead of his usual move he started walking straight. In every move Knight jumps on 2n steps forward (n is number of block that he had travelled so far from starting) but after that he has t...
```python from math import log,pow n=int(input()) a=[] for i in range(n): no=int(input()) if(no%2==0): a.append("0") elif(no==1): a.append("1") elif(no==3): a.append("3") else: s="2" lv=int(log(no,2)) clv=1 cno=3 while(cno!=no): if(no<cno*pow(2,lv-clv)): s=s+"1" clv=clv+1 cno=(2*cno)...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Chef wants to serve mankind by making people immortal by preparing a dish, a dish of life - a dish with the best taste in the universe, one with the smell and splash of fresh water flowing down the springs of the mountain, one with the smell of ...
```python for _ in range(int(input())): n,k = list(map(int,input().split())) array = [] tot = [] for _ in range(n): temp = list(map(int,input().split())) aa = temp[0] del(temp[0]) temp.sort() temp.insert(0,aa) array.append(temp) dic = {} array.sort(reverse=True) for i in array: del(i[0]) for i in ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Leha plays a computer game, where is on each level is given a connected graph with n vertices and m edges. Graph can contain multiple edges, but can not contain self loops. Each vertex has an integer d_{i}, which can be equal to 0, 1 or - 1. To...
```python import sys n, m = list(map(int, sys.stdin.readline().split())) d = list(map(int, sys.stdin.readline().split())) gph = [[] for _ in range(n)] for _ in range(m): u, v = list(map(int, sys.stdin.readline().split())) u -= 1 v -= 1 gph[u].append((v, _)) gph[v].append((u, _)) t = -1 if d.c...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: The campus has $m$ rooms numbered from $0$ to $m - 1$. Also the $x$-mouse lives in the campus. The $x$-mouse is not just a mouse: each second $x$-mouse moves from room $i$ to the room $i \cdot x \mod{m}$ (in fact, it teleports from one room to a...
```python from math import gcd def powmod(a,b,m): a%=m r=1 while b: if b&1:r=r*a%m a=a*a%m b>>=1 return r def f(n): r=[] if (n&1)==0: e=0 while (n&1)==0:n>>=1;e+=1 yield (2,e) p=3 while n>1: if p*p>n:p=n if n%p: p+=2 continue e=1;n//=p while n%p==0:n//=p;e+=1 yield (p,e) p+=2 ret...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Prof. Sergio Marquina is a mathematics teacher at the University of Spain. 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 the semester he assign...
```python # cook your dish here for t in range(int(input())): n,m=[int(x)for x in input().rstrip().split()] s=[] for p in range(n): s.append(10) for c in range(m): i,j,k=[int(x)for x in input().rstrip().split()] for q in range(i-1,j): s[q]=s[q]*k print(sum(s)//n) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Petr is organizing Petr Mitrichev Contest #11. The top N coders according to codechef ratings (excluding Petr himself) agreed to participate in the contest. The participants have been ranked from 0 to N-1 according to their ratings. Petr had ask...
```python import math def comb(n,r): f = math.factorial return f(n) / f(r) / f(n-r) t=int(input()) for i in range(1,t+1): n=int(input()) arr = list(map(int, input().split())) m=0 ans=0.0 for i in range(0,n): if (arr[i]==-1): m=m+1 for i in range(0,m): ans=ans+((m-i)*comb(m-1,m-1-i)) ans=ans/pow(2,m-1) ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: In the 2-D world of Flatland, the Circles were having their sports day and wanted to end it with a nice formation. So, they called upon Mr. Sphere from Spaceland for help. Mr Sphere decides to arrange the Circles in square formations. He starts ...
```python # cook your dish here import math for _ in range(int(input())): n=int(input()) c=0 while(n>0): i=int(math.sqrt(n)) c+=1 n=n-i**2 print(c) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Sasha likes programming. Once, during a very long contest, Sasha decided that he was a bit tired and needed to relax. So he did. But since Sasha isn't an ordinary guy, he prefers to relax unusually. During leisure time Sasha likes to upsolve uns...
```python ii = lambda: int(input()) mi = lambda: map(int, input().split()) li = lambda: list(mi()) from collections import Counter as C n = ii() a = li() oe = [C(), C()] oe[1][0] = 1 x = 0 ans = 0 for i in range(n): x ^= a[i] ans += oe[i % 2][x] oe[i % 2][x] += 1 print(ans) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Every college has a stud−max$stud-max$ buoy. JGEC$JGEC$ has its own Atul$Atul$ who loves to impress everyone with his smile. A presentation is going on at the auditorium where there are N$N$ rows of M$M$ chairs with people sitting on it. Everyon...
```python t = int(input()) for i in range(t): q = input().split() n = int(q[0]) m = int(q[1]) k = int(q[2]) sumax = 0 b = [] for j in range(n): a = [int(k) for k in input().split()] b = b + [a] for j in range(n): su = 0 for x in range(k): ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Recently Polycarpus has learned the "bitwise AND" operation (which is also called "AND") of non-negative integers. Now he wants to demonstrate the school IT teacher his superb manipulation with the learned operation. For that Polycarpus came to...
```python n=int(input()) a=[] for i in range(n): a.append(list(map(int,input().split()))) ans = [0]*n for i in range(n): for j in range(n): if j!=i: ans[i] |= a[i][j] print(ans[i],end = ' ') ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: This problem is about sequences of positive integers $a_1,a_2,...,a_N$. A subsequence of a sequence is anything obtained by dropping some of the elements. For example, $3,7,11,3$ is a subsequence of $6,3,11,5,7,4,3,11,5,3$ , but $3,3,7$ is not a...
```python # coding: utf-8 # Your code here! n=int(input()) a=[] for i in range(n): x=int(input()) a.append(x) # print(a) ans=0 m=[1]*n for i in range(n): for j in range(i): if a[i]%a[j]==0: m[i]=max(m[i],m[j]+1) print(max(m)) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Chef Ada is building a new restaurant in the following way: - First, $N$ points $X_1, X_2, \ldots, X_N$ are chosen on the $x$-axis. - Then, $N$ columns (numbered $1$ through $N$) are made. For simplicity, the columns are represented as vertical ...
```python # cook your dish here t = int(input()) for _ in range(t): n = int(input()) a = [] b = [] for i in range(n): x,y = list(map(int, input().split())) a.append(x) b.append(y) b.sort() xcor = [] xcor.append(a[1]-a[0]) xcor.append(a[n-1]-a[n-2]) for i in range(1,n-1): xcor.append(a[i+1]-a[i-1]) xco...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Chef made $N$ pieces of cakes, numbered them $1$ through $N$ and arranged them in a row in this order. There are $K$ possible types of flavours (numbered $1$ through $K$); for each valid $i$, the $i$-th piece of cake has a flavour $A_i$. Chef wa...
```python def main(): t= int(input()) while(t!=0): n,k = list(map(int , input().split())) arr = list(map(int, input().split())) freq = [0]*100001 k=k-1 st=0 end=0 currentCount=0 previousElement = 0 for i in range(n): freq[arr[i]]+=1 if(freq[arr[i]]==1): currentCount+=1 while(currentCou...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Let's call some positive integer classy if its decimal representation contains no more than $3$ non-zero digits. For example, numbers $4$, $200000$, $10203$ are classy and numbers $4231$, $102306$, $7277420000$ are not. You are given a segment ...
```python import sys #sys.stdin=open("data.txt") input=sys.stdin.readline # this math tutorial is boring classy=set() for i in range(19): for j in range(i): for k in range(j): for a in range(10): # a=0 for good measure for b in range(10): for c in rang...