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: "What do you know about happiness?" — Yoda Chef is happy only if three conditions hold: - Chef finished cooking a delicious meal - Chef got AC for a programming problem with an almost correct code - Chef got a new problem with a sequence of int...
```python # cook your dish here t=int(input()) for i in range(t): n=int(input()) a=list(map(int,input().split())) d={} for i in range(n): if a[i]-1 not in d: d[a[i]-1]=[i] else: d[a[i]-1].append(i) ans=False d1={} for i in d: if ans==True: break for j in d: if i!=j: if a[i]==a[j] and ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Bear Limak has a sequence of N non-negative integers A1, A2, ..., AN. He defines the score of a segment (consecutive subsequence) as its sum of elements modulo P (not necessarily prime). Find the maximum score of a non-empty segment, and also fi...
```python for _ in range(int(input())): n,m=input().split() n,m=int(n),int(m) x=y=c=0 l=list(map(int,input().split())) for i in range(n): for j in range(i,n): x=x+l[j] if (x%m)>y: y=x%m c=1 elif y==(x%m): c+=1 x = 0 print(y,c) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Like all minions Dave also like to eat bananas. So as to his obsession, he is eating banana, but this time in different way. There are N bananas in dish. Dave wants to eat all of them. He starts eating at speed 1 banana/second. He can increase o...
```python t=int(input()) while(t): k=1 j=0 n=int(input()) while(n>0): if(n<=k): j+=1 n=0 elif n>2*k: j+=2 n=n-2*k k+=1 else: j+=2 n=0 print(j) t-=1 ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: You might have heard about our new goodie distribution program aka the "Laddu Accrual System". This problem is designed to give you a glimpse of its rules. You can read the page once before attempting the problem if you wish, nonetheless we will...
```python for i in range(int(input())): n,k=input().split() laddus=0 for j in range(int(n)): t=input().split() if t[0]=='CONTEST_WON': if(int(t[1])<=20): laddus+=300+20-int(t[1]) else: laddus+=300 elif t[0]=='TOP_CONTRIBUTOR': laddus+=300 elif t[0]=='BUG_FOUND': laddus+=int(t[1]) elif t...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Indian National Olympiad in Informatics 2016 There are k types of brackets each with its own opening bracket and closing bracket. We assume that the first pair is denoted by the numbers 1 and k+1, the second by 2 and k+2 and so on. Thus the ope...
```python # cook your dish here import bisect n, k1, *l = map(int, input().split()) v_l, b_l = l[:n], l[n:] b_inv = {key:[] for key in range(2*k1)} for i in range(n): b_l[i] -= 1 b_inv[b_l[i]].append(i) dp = [[0 for _ in range(n)] for _ in range(n)] for k in range(1, n): for j in range(n-2, -1...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: A bitstring is a string consisting only of the characters 0 and 1. A bitstring is called $k$-balanced if every substring of size $k$ of this bitstring has an equal amount of 0 and 1 characters ($\frac{k}{2}$ of each). You are given an integer $...
```python import sys input = sys.stdin.readline t = int(input()) for _ in range(t): n, k = list(map(int, input().split())) s = input() l = ['']*k works = True for i in range(n): c = s[i] if c != '?': if l[i%k] == c or l[i%k] == '': l[i%k] = c ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Dhruvil has always been a studious person and will be completing his Engineering soon. He is always kneen about solving problems and is preparing hard for his next interview at Hackerrank. He has practiced lots of problems and now he came across...
```python # cook your dish here # cook your dish here def numDec(s): if not s: return 0 dp = [0 for _ in range(len(s) + 1)] dp[0] = 1 dp[1] = 0 if s[0] == '0' else 1 for i in range(2, len(dp)): if s[i-1] != '0': dp[i] += dp[i-1] two_digit = int(s[i-2 : i]) if two_digit >= 10 and two_digi...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Petr wants to make a calendar for current month. For this purpose he draws a table in which columns correspond to weeks (a week is seven consequent days from Monday to Sunday), rows correspond to weekdays, and cells contain dates. For example, a...
```python import sys arr = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] a, b = list(map(int, input().split())) a -= 1 b -= 1 ctr = 1 for i in range(arr[a] - 1): b += 1 if (b == 7): b = 0 ctr += 1 print(ctr) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: For a permutation P = (p1, p2, ..., pN) of numbers [1, 2, ..., N], we define the function f(P) = max(p1, p2) + max(p2, p3) + ... + max(pN-1, pN). You are given N and an integer K. Find and report a permutation P of [1, 2, ..., N] such that f(P) ...
```python # cook your dish here for i in range(int(input())): n,k=[int(i) for i in input().split()] if(n%2==0): if(k<(n*(n+1))//2 - 1 or k>3*((n//2)**2) - 1):print(-1) elif(k==(n*(n+1))//2 - 1): for i in range(1,n+1):print(i,'',end='') print() else: k,count,p,l,x = k-(n*(n+1))...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: This is the hard version of the problem. The difference between the versions is the constraint on $n$ and the required number of operations. You can make hacks only if all versions of the problem are solved. There are two binary strings $a$ and...
```python import sys input = sys.stdin.readline from collections import deque t=int(input()) for tests in range(t): n=int(input()) a=input().strip() b=input().strip() Q=deque(a) L=[] while Q: L.append(Q.popleft()) if Q: L.append(Q.pop()) ANS=[] for i in...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Chef has N laddus of K sweetness each. Chef wants to eat all laddus, but Chef is restricted with the given condition that he must not eat two adjacent laddus. Chef starts calculating the maximum sweetness that he will get from the laddus. Find t...
```python t = int(input()) for _ in range(t): n,m = map(int,input().split()) if n==1: print(m) else: if n%2==0: print((n//2)*m) else: print(((n//2)+1)*m) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: You are given an array of integers [A1,A2,…,AN]$[A_1, A_2, \ldots, A_N]$. Let's call adding an element to this array at any position (including the beginning and the end) or removing an arbitrary element from it a modification. It is not allowed...
```python # cook your dish here for _ in range(int(input())): n=int(input());li=list(map(int,input().split()));dli=dict();modi=0 for i in li: if i not in dli:dli[i]=1 else:dli[i]+=1 op=sorted(list(dli)) if(len(dli)!=0): while 1: tmp=[] for i in op: if dli[i]==0:continue...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: -----Description----- The Antique Comedians of India prefer comedies to tragedies. Unfortunately, most of the ancient plays are tragedies. Therefore the dramatic advisor of ACI has decided to transfigure some tragedies into comedies. Obviously, ...
```python #include<stdio.h> int rev(int k) { int j,res=0; while(k) { res=res*10+k%10; k/=10; } return res; } int main() { int j,a,b,m,k; while(scanf("%d",&m)!=EOF) { for(j=1;j<=m;j++) { scanf("%d %d",&a,&b); k=rev(a)+rev(b); printf("%d\n",rev(k)); } } return 0; } ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Consider the infinite x$x$ axis. There are N$N$ impacts on this X-axis at integral points (X1$X_1$,X2$X_2$,....XN$X_N$) (all distinct) . An impact at a point X$X$i propagates such that at a point X$X$0, the effect of the impact is K|Xi−X0|$K^{|...
```python # cook your dish here T = int(input()) for i in range(T): l = list(map(int, input().split())) n, k, m, x = l[0], l[1], l[2], l[3] if k == 1: if n == m: print("yes") else: print("no") elif m % k > 1: print("no") elif k == 2: stack = []...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Polycarp has recently created a new level in this cool new game Berlio Maker 85 and uploaded it online. Now players from all over the world can try his level. All levels in this game have two stats to them: the number of plays and the number of...
```python import sys input = sys.stdin.readline T = int(input()) for _ in range(T): n = int(input()) lastP = 0 lastC = 0 works = True for _ in range(n): p, c = list(map(int, input().split())) pDiff = p-lastP cDiff = c-lastC if 0 <= cDiff <= pDiff: pass ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Polycarp plans to conduct a load testing of its new project Fakebook. He already agreed with his friends that at certain points in time they will send requests to Fakebook. The load testing will last n minutes and in the i-th minute friends will...
```python n = int(input()) a = list(map(int, input().split())) lp,rp = [0 for i in range(n)],[0 for i in range(n)] lnr, rnr = [a[i] for i in range(n)],[a[i] for i in range(n)] mx = a[0] for i in range(1,n): if a[i] > mx: mx = a[i] lp[i] = lp[i-1] else: mx += 1 lp[i] = lp[i-1] +...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Chef has invited Alice for his birthday party. Now, Alice is thinking about what to give Chef as a present. She should obviously choose a sequence ― what could possibly be a better birthday gift than a sequence! After some thinking, Alice chose ...
```python mod=10**9+7 def pow2(x): p,n=1,2 while(x): if(x & 1): p=((p%mod) * (n%mod))%mod n=((n%mod) * (n%mod))%mod x//=2 return p def count_bit(val): bit=0 while(val): bit+=1 val &=(val-1) return bit def answer(): val=b[0] po2=0 for i in range(1,len(b)): if(val > b[i]):return 0 po2+=coun...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: There is a task in Among Us in which $N$ temperature scale with unique readings are given and you have to make all of them equal. In one second you can choose an odd number and add or subtract that number in any one temperature value. Find minim...
```python # cook your dish here for _ in range(int(input())): n=int(input()) ar=list(map(int,input().split())) odd=0 even=0 if n==1: print(0) continue for i in range(n): if ar[i]%2==1: odd+=1 else: even+=1 if odd>0: vo=(odd-1)*2+even else: vo=even if even>0: ve=(even-1)*2+odd else: ve=od...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Iahub likes trees very much. Recently he discovered an interesting tree named propagating tree. The tree consists of n nodes numbered from 1 to n, each node i having an initial value a_{i}. The root of the tree is node 1. This tree has a specia...
```python class BIT(): """区間加算、一点取得クエリをそれぞれO(logN)で応えるデータ構造を構築する add: 区間[begin, end)にvalを加える get_val: i番目(0-indexed)の値を求める """ def __init__(self, n): self.n = n self.bit = [0] * (n + 1) def get_val(self, i): i = i + 1 s = 0 while i <= self.n: ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: The Fibonacci sequence $F_0, F_1, \ldots$ is a special infinite sequence of non-negative integers, where $F_0 = 0$, $F_1 = 1$ and for each integer $n \ge 2$, $F_n = F_{n-1} + F_{n-2}$. Consider the sequence $D$ of the last decimal digits of the ...
```python import math t = int(input()) a = [-1, 0, 1] for i in range(58): temp = a[-1] + a[-2] temp = temp%10 a.append(temp) for _ in range(t): n = int(input()) temp = len(bin(n)) - 3 temp = 2**temp temp = temp%60 print(a[temp]) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Alice and Bob play a game. They have a binary string $s$ (a string such that each character in it is either $0$ or $1$). Alice moves first, then Bob, then Alice again, and so on. During their move, the player can choose any number (not less tha...
```python for _ in range(int(input())): s = input() p = [i for i in s.split("0") if i!=""] p.sort(reverse=True) ans = 0 for i in range(0,len(p),2): ans+=len(p[i]) print(ans) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Polycarpus likes giving presents to Paraskevi. He has bought two chocolate bars, each of them has the shape of a segmented rectangle. The first bar is a_1 × b_1 segments large and the second one is a_2 × b_2 segments large. Polycarpus wants to ...
```python a,b=list(map(int,input().split())) c,d=list(map(int,input().split())) e=a*b f=c*d n=0 while e%2==0:e=e//2 while e%3==0:e=e//3 while f%2==0:f=f//2 while f%3==0:f=f//3 if e!=f:print("-1") else: i=0 j=0 e=a*b f=c*d while e%3==0: e=e//3 i+=1 while f%3==0: f=f//3 j+=1 k...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: You are given a grid of size N x M consisting of '.' (empty), 'W' (white) or 'B' (black) cells. We follow the convention that the top left corner is the position (1,1) and bottom right corner is (N,M). From every '.' cell (i, j), a ray is shot ...
```python # cook your dish here from operator import itemgetter inp=list(map(int, input().split())) n, m, w, b = inp[:4] stops=[] for i in range(w): stops.append((inp[4+2*i]-1,inp[5+2*i]-1,'w')) for i in range(b): stops.append((inp[4+2*w+2*i]-1,inp[5+2*w+2*i]-1,'b')) stops.sort(key=itemgetter(1)) stops.sort(key=itemg...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Sebi lives in Chefland where the government is extremely corrupt that usually makes fool out of public by announcing eye catching but non-sustainable schemes. Recently there was a move to increase tourism in the country that was highly lauded. S...
```python from sys import stdin,stdout total_cost=0 def find(a): if par[a]==a: return a else: par[a]=find(par[a]) return par[a] def union(a,b,c): a,b=find(a),find(b) nonlocal total_cost total_cost+=(rank[a]*rank[b]*c) if a!=b: if rank[a]>rank[b]: par[b]=a rank[a]+=rank[b] elif rank[b]>rank[a]:...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Ram and Shyam are sitting next to each other, hoping to cheat on an exam. However, the examination board has prepared $p$ different sets of questions (numbered $0$ through $p-1$), which will be distributed to the students in the following way: -...
```python # cook your dish here for test in range(0,int(input())): A,B = map(int,input().split()) diff = abs(A-B) count=0 if not(A^B): print(-1) else: for i in range(1,int(diff**(1/2))+1): if diff%i==0: if diff/i==i: count+=1 else: count+=2 print(count) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: You may have helped Chef and prevented Doof from destroying the even numbers. But, it has only angered Dr Doof even further. However, for his next plan, he needs some time. Therefore, Doof has built $N$ walls to prevent Chef from interrupting hi...
```python def posSearch(arr, num): l = 0 r = len(arr) if num < arr[l]: return 0 elif num > arr[r-1]: return r while l < r: m = (l+r)//2 if arr[m] == num: return -1 if arr[m] < num < arr[m+1]: return m+1 if arr[m] > num: r = m elif arr[m] < num: l = m+1 for _ in range(int(input())): n ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: For her next karate demonstration, Ada will break some bricks. Ada stacked three bricks on top of each other. Initially, their widths (from top to bottom) are $W_1, W_2, W_3$. Ada's strength is $S$. Whenever she hits a stack of bricks, consider ...
```python t=int(input()) for i in range(t): n,w1,w2,w3=map(int,input().split()) if n>=w1+w2+w3: print(1) elif n>=w1+w2 or n>=w2+w3: print(2) else: print(3) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: You are given a picture consisting of $n$ rows and $m$ columns. Rows are numbered from $1$ to $n$ from the top to the bottom, columns are numbered from $1$ to $m$ from the left to the right. Each cell is painted either black or white. You thin...
```python import sys q = int(sys.stdin.readline().strip()) for t in range(0, q): n, m = list(map(int, sys.stdin.readline().strip().split())) L = [] R = [0] * n C = [0] * m for i in range (0, n): L.append(sys.stdin.readline().strip()) for j in range (0, m): if L[i][j] != ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Chef has recently learned about number bases and is becoming fascinated. Chef learned that for bases greater than ten, new digit symbols need to be introduced, and that the convention is to use the first few letters of the English alphabet. For ...
```python # cook your dish here def finder(n): cnt=0 for i in range(2,n+1): a=n while a!=0: r=a%i a=a//i if r==1: cnt+=1 return cnt t=int(input()) for _ in range(t): n=int(input()) if n==0: print(0) elif n==1: print('IN...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: $n$ boys and $m$ girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from $1$ to $n$ and all girls are numbered with integers from $1$ to $m$. For all $1 \leq i...
```python n,m=map(int,input().split()) b=list(map(int,input().split())) g=list(map(int,input().split())) if max(b)>min(g): print(-1) else: maxi=0 maxi2=0 for guy in b: if guy>maxi: maxi2,maxi=maxi,guy elif guy>maxi2: maxi2=guy sumi=m*sum(b)+sum(g)-m*maxi+maxi-...
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 currently is on the military mission. There are N enemy buildings placed in a row and numbered from left to right strating from 0. Each building i (except the first and the last) has exactly two adjacent ...
```python import sys T = int(sys.stdin.readline().strip()) for t in range(T): sys.stdin.readline().strip() st = '0'+sys.stdin.readline().strip()+'0' res = 0 for i in range(1,len(st)-1): if st[i] == st[i-1] == st[i+1] == '0': res+=1 print(res) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Indraneel's student has given him data from two sets of experiments that the student has performed. Indraneel wants to establish a correlation between the two sets of data. Each data set is a sequence of $N$ numbers. The two data sets do not mat...
```python import copy n=int(input()) a=[int(x) for x in input().split()] b=[int(x) for x in input().split()] c=[] d=[] lcs=[] def lcsfn(a,c,corda,cordb): for i in range(n+1): d.append([0]*(n+1)) lcs.append([0]*(n+1)) for i in range(1,n+1): for j in range(1,n+1): if a[i-1]==c[j-1]: lcs[i][j]...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: In poker, you have 5 cards. There are 10 kinds of poker hands (from highest to lowest): - royal flush - ace, king, queen, jack and ten, all in the same suit - straight flush - five cards of the same suit in sequence, such as 10,9,8,7,6 of cl...
```python cards = ['A','2','3','4','5','6','7','8','9','T','J','Q','K'] def royal_flush(arr): nonlocal ans, confirm rf_set = 'TJQKA' rf = 1 for char in arr: if char[0] not in rf_set: rf = 0 break if rf : if len(set(suit)) == 1: ans = 'royal flush' confirm = 1 def straight_flush(arr): # and 'strai...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: For a given positive integer n denote its k-rounding as the minimum positive integer x, such that x ends with k or more zeros in base 10 and is divisible by n. For example, 4-rounding of 375 is 375·80 = 30000. 30000 is the minimum integer such ...
```python def main(): n, k = map(int, input().split()) num_2 = 0 num_5 = 0 x = n while (x % 2 == 0): num_2 += 1 x //= 2 while (x % 5 == 0): num_5 += 1 x //= 5 num_2 = k - min(num_2, k) num_5 = k - min(num_5, k) print(n * 5 ** num_5 * 2 ** num_2) main() ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: You are given an integer N. Consider all possible segments on the coordinate axis with endpoints at integer points with coordinates between 0 and N, inclusive; there will be $\frac{n(n + 1)}{2}$ of them. You want to draw these segments in sever...
```python n=int(input()) print(max((i+1)*(n-i)for i in range(n))) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Ripul was skilled in the art of lapidary. He used to collect stones and convert it into decorative items for sale. There were n stone shops. Each shop was having one exclusive stone of value s[i] , where 1<=i<=n. If number of stones collected ...
```python # cook your dish here for u in range(int(input())): n=int(input()) l=list(map(int,input().split())) d=[] dd=[] s=1 for i in range(n-1): s=l[i] d.append(s) dd.append([i,i]) for j in range(i+1,n): s=s*l[j] d.append(s) dd.append([i,j]) d.append(l[n-1]) dd.append([n-1,n-1]) k=len(d) m=m...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: The "BerCorp" company has got n employees. These employees can use m approved official languages for the formal correspondence. The languages are numbered with integers from 1 to m. For each employee we have the list of languages, which he knows...
```python rd = lambda: list(map(int, input().split())) def root(x): if f[x]!=x: f[x] = root(f[x]) return f[x] n, m = rd() N = list(range(n)) f = list(N) lang = [0]*n for i in N: lang[i] = set(rd()[1:]) for i in N: for j in N[:i]: rj = root(j) if lang[rj].intersection(lang[i]): f[rj] = i lang...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Teacher Sungjae wanted to hold a programming competition for his students where every participant need to be included into team. The participants submitted their team names before the deadline. After the competition ran for half an hour, (It is...
```python # cook your dish here for t in range(int(input())): n,k=map(int,input().split()) a=[] sr=[] for i in range(k): x,y=input().split() y=int(y) a.append([10**10-y,x]) sr.append(sorted(x)) for i in range(n-k): x,y=input().split() y=int(y) ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Tom has finally taken over the business empire and now looking for a new Name of the business to make a new start. Joe (Tom's dear friend) suggested a string $S$ consisting of Uppercase and lowercase letters Tom wants to make some chan...
```python s = input().lower() vow = ["a", "e", "i", "o", "u", "y"] ans = "" for ch in s: if ch in vow: continue if ch.isalpha(): ans += "." + ch print(ans) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: You are given $N$ integers in an array: $A[1], A[2], \ldots, A[N]$. You also have another integer $L$. Consider a sequence of indices ($i_1, i_2, \ldots, i_k$). Note that a particular index can occur multiple times in the sequence, and there is ...
```python # cook your dish here # from queue import PriorityQueue # import bisect def insort(l, v): s = 0 e = len(l) while True: mid = (s+e)//2 if s == e or mid > len(l): break if l[mid][0] < v[0]: s = mid+1 elif l[mid][0] > v[0]: e = mid ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Given an integer $x$, find two non-negative integers $a$ and $b$ such that $(a \wedge b) + (a \vee b) = x$, where $\wedge$ is the bitwise AND operation and $\vee$ is the bitwise OR operation. -----Input----- - The first line of the input contai...
```python # cook your dish here n=int(input()) for _ in range(n): a=int(input()) if(a%2==0): f=(a//2)-1 s=a-f else: f=(a//2) s=a-f print(f,s) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: -----Problem Statement----- Write a program that accepts a number, n, and outputs the same. -----Input----- The only line contains a single integer. -----Output----- Output the answer in a single line. -----Constraints----- - 0 ≤ n ≤ 105 --...
```python # cook your dish here a = int(input()) print(a) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: You are given a permutation $p_1, p_2, \dots, p_n$. Recall that sequence of $n$ integers is called a permutation if it contains all integers from $1$ to $n$ exactly once. Find three indices $i$, $j$ and $k$ such that: $1 \le i < j < k \le n$;...
```python import sys import math #from queue import * import random #sys.setrecursionlimit(int(1e6)) input = sys.stdin.readline ############ ---- USER DEFINED INPUT FUNCTIONS ---- ############ def inp(): return(int(input())) def inara(): return(list(map(int,input().split()))) def insr(): s = input() r...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Bhallaladeva was an evil king who ruled the kingdom of Maahishmati. He wanted to erect a 100ft golden statue of himself and he looted gold from several places for this. He even looted his own people, by using the following unfair strategy: There...
```python import math n = int(input()) a = sorted(map(int,input().split())) l = [0]*n for i in range(n): l[i] = a[i] + l[i-1] for q in range(int(input())): print(l[int(math.ceil(float(n)/(int(input())+1)))-1]) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Chef recently saw the movie Matrix. He loved the movie overall but he didn't agree with some things in it. Particularly he didn't agree with the bald boy when he declared - There is no spoon. Being a chef, he understands the importance of the sp...
```python import sys spoon = [ "SPOON", "spoon" ] def main(): try: tc=int(input()) while tc>0: tc=tc-1 [r,c] = input().split() r=int(r) c=int(c) k=0 flag=0 matrix=[0]*r i=0 while i<r: matrix[i]=input() i=i+1 #Check row wise for m in matrix: for s in m: if s==...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Ivan has an array consisting of n different integers. He decided to reorder all elements in increasing order. Ivan loves merge sort so he decided to represent his array with one or several increasing sequences which he then plans to merge into o...
```python n = int(input()) from bisect import bisect_left a = list(map(int, input().split())) ss = [] ms = [] for i in range(n): k = a[i] ind = bisect_left(ms, -k) if ind == len(ms): ss.append([]) ms.append(0) ss[ind].append(k) ms[ind] = -k for s in ss: print(' '.join([str(i) ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: The Bad Luck Island is inhabited by three kinds of species: r rocks, s scissors and p papers. At some moments of time two random individuals meet (all pairs of individuals can meet equiprobably), and if they belong to different species, then one...
```python r, s, p = list(map(int, input().split())) dp = [[[0] * (p+1) for _ in range(s+1)] for _ in range(r+1)] dp[r][s][p] = 1 def nCk(n, k): if n <= k: return 1 res = 1 for i in range(k): res *= n-i for i in range(k): res //= (i+1) return res C = [nCk(i, 2) for i in range...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Nobody knows, but $N$ frogs live in Chef's garden. Now they are siting on the X-axis and want to speak to each other. One frog can send a message to another one if the distance between them is less or equal to $K$. Chef knows all $P$ pairs of fr...
```python # cook your dish here n, k, p = [int(i) for i in input().split()] n_sep = list(map(int, input().split())) count = 0 sep_sort = sorted(n_sep) hashing = {sep_sort[0]: 0} for j in range(1, n): if (abs(sep_sort[j] - sep_sort[j - 1]) > k): count += 1 hashing[sep_sort[j]] = count #print(hashing) for i in range...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: The chef is trying to decode some pattern problems, Chef wants your help to code it. Chef has one number K to form a new pattern. Help the chef to code this pattern problem. -----Input:----- - First-line will contain $T$, the number of test cas...
```python for _ in range(int(input())): n = int(input()) num = "" val = 1 for i in range(n): num += str(val) if val == 1: val = 0 else: val = 1 for i in range(n): print(num) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Cersei wants to be the queen of seven kingdoms. For this to happen, she needs to address the soldiers in her army. There are n$n$ soldiers in her army (numbered 1$1$ through n$n$). Cersei passes on the message to the first soldier (soldier 1). ...
```python dt, a = None, None def dfs(z): r = [{}, {}];ln = len(dt[z]) if ln == 0:r[0][0] = 0;r[1][1 << a[z]] = 1 elif ln == 1: l = dfs(dt[z][0]);r[0] = l[1] for m in l[0]: r[1][(1 << a[z]) | m] = min(r[1][(1 << a[z]) | m], l[0][m] + 1) if (1 << a[z]) | m in r[1] else l[0][m] + 1 ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Let's define a periodic infinite sequence S$S$ (0$0$-indexed) with period K$K$ using the formula Si=(i%K)+1$S_i = (i \% K) + 1$. Chef has found a sequence of positive integers A$A$ with length N$N$ buried underground. He suspects that it is a co...
```python # cook your dish here from math import gcd for _ in range(int(input())): n,a,k,min_k,e = int(input()),[int(i) for i in input().split()],0,0,-1 for j in range(n): if(a[j] != -1):break for i in range(j,n): if min_k==0:min_k,e = a[i],a[i]+1 else: if min_k < a[i]:m...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Levko loves array a_1, a_2, ... , a_{n}, consisting of integers, very much. That is why Levko is playing with array a, performing all sorts of operations with it. Each operation Levko performs is of one of two types: Increase all elements fro...
```python n, m = map(int, input().split()) a = [10**9 for _ in range(n)] extra = [0 for _ in range(n)] query = list() for _ in range(m): t, l, r, x = map(int, input().split()) l -= 1 r -= 1 query.append((t, l, r, x)) if t == 1: for j in range(l, r + 1): extra[j] += x ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: It is well-known that the elephants are afraid of mouses. The Little Elephant from the Zoo of Lviv is not an exception. The Little Elephant is on a board A of n rows and m columns (0-based numeration). At the beginning he is in cell with coordi...
```python from collections import defaultdict from itertools import product def solve(mouse,n,m): # shadow matrix will contains the count of mice which affect (i,j) position # if there is a mice at position (i,j) then in shadow matrix it will affect         all four adjacent blocks shadow=[[0 for i in range(m)]f...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Witua is a little student from the University of Lviv. He enjoys studying math. Witua knows a lot of famous mathematicians like Eratosthenes, Pythagoras, Fermat, Diophantus, Furko, Gauss and so on. However, his favorite one is Euler. The only th...
```python # cook your dish here def modular_pow(base, exponent, modulus): result = 1 while exponent > 0: if(exponent %2 == 1): result = (result * base) % modulus exponent = exponent//2 base = (base * base)%modulus return result def passesMillerRabinTest(n, a): s = 0 d = n-1 while(d%2 == 0): s += 1 d ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: You are given a string s, consisting of lowercase English letters, and the integer m. One should choose some symbols from the given string so that any contiguous subsegment of length m has at least one selected symbol. Note that here we choose ...
```python m = int(input()) s = input().strip() sa = [0] * len(s) for i in range(len(s)): sa[i] = ord(s[i]) - ord('a') sa = [-1] + sa + [-1] def check_value(sa, m, threshold): prev_ind = 0 for i in range(len(sa)): if sa[i] <= threshold: if i - prev_ind <= m: prev_ind = i else: return False return ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Lesha plays the recently published new version of the legendary game hacknet. In this version character skill mechanism was introduced. Now, each player character has exactly n skills. Each skill is represented by a non-negative integer a_{i} — ...
```python import itertools import bisect n, A, cf, cm, m = [int(x) for x in input().split()] skills = [int(x) for x in input().split()] sorted_skills = list(sorted((k, i) for i, k in enumerate(skills))) bottom_lift = [0 for i in range(n)] for i in range(1, n): bottom_lift[i] = bottom_lift[i-1] + i * (sorted_skills...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Gru has a string $S$ of length $N$, consisting of only characters $a$ and $b$ for banana and $P$ points to spend. Now Gru wants to replace and/or re-arrange characters of this given string to get the lexicographically smallest string possible. F...
```python def __starting_point(): t=int(input()) for _ in range(t): n,p=input().split() n,p=int(n),int(p) s=input() a,b=0,0 arr=[0]*n for i in range(n): arr[i]=s[i] for c in s: if c=='a': a+=1 else: b+=1 swap=0 for i in range(a): if s[i]=='b': swap+=1 tmpp=p if p<=swap: ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: You are given a sequence of N$N$ powers of an integer k$k$; let's denote the i$i$-th of these powers by kAi$k^{A_i}$. You should partition this sequence into two non-empty contiguous subsequences; each element of the original sequence should app...
```python # cook your dish here def main(): for _ in range(int(input())): N, k = [int(x) for x in input().split()] Powers = [k ** int(x) for x in input().split()] s1, s2 = 0, sum(Powers) ans = (0, None) i = 0 while i < N - 1: s1 += Powers[i] s2 -= Powers[i] ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Vasya and Kolya play a game with a string, using the following rules. Initially, Kolya creates a string s, consisting of small English letters, and uniformly at random chooses an integer k from a segment [0, len(s) - 1]. He tells Vasya this stri...
```python str = input() l = len(str) a = [0] * (2 * l) pos = [[] for i in range(26)] for i, c in enumerate(str): t = ord(c) - ord('a') a[i] = t a[i + l] = t pos[t].append(i) ans = 0 for c in range(26): cur = 0 for k in range(1, l): cnt = [0] * 26 for i in pos[c]: cnt[...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Andrew and Eugene are playing a game. Initially, Andrew has string s, consisting of digits. Eugene sends Andrew multiple queries of type "d_{i} → t_{i}", that means "replace all digits d_{i} in string s with substrings equal to t_{i}". For examp...
```python MOD = 10**9+7 s = input() n = int(input()) qs = [['',s]]+[input().split('->') for i in range(n)] ds = {} for i in range(10): ds[str(i)] = (10,i) for i in range(n,-1,-1): out = 0 mul = 1 for d in qs[i][1]: out = (out * ds[d][0] + ds[d][1]) % MOD mul = (mul * ds[d][0]) % MOD ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Ivan wants to make a necklace as a present to his beloved girl. A necklace is a cyclic sequence of beads of different colors. Ivan says that necklace is beautiful relative to the cut point between two adjacent beads, if the chain of beads remain...
```python import math #import fractions from functools import reduce n = int(input()) odd = -1 beads = [int(x) for x in input().split()] for i in range(n): if beads[i]%2: if odd >= 0: print(0) print(''.join(chr(ord('a') + i)*beads[i] for i in range(n))) break els...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Chefina is always interested to play with string. But due to exam pressure she has no time to solve a string problem. She wants your help. Can you help her to solve that problem? You are given a string. You have to find out the $Wonder$ $Sum$ ...
```python for _ in range(int(input())): string = input().rstrip() start=(ord(string[0])-96)*100 sum=0 #print(start) for i in range(len(string)): sum+=start+(ord(string[i])-97) print(sum%1000000007) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Let's consider a rooted binary tree with the following properties: - The number of nodes and edges in the tree is infinite - The tree root is labeled by $1$ - A node labeled by $v$ has two children: $2 \cdot v$ (the left child of $v$), and $2 \c...
```python t = int(input()) while(t>0): t-=1; n,l,r = list(map(int,input().split())); a = bin(l)[2:]; b = bin(r)[2:]; # find matching z = 0; l = min(len(a),len(b)); for i in range(l): if a[i]==b[i]: z+=1; else: break; #find base string a = a[z:] b = b[z:] if(len(a)==0 and len(b)==0): print(n); ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: In a regular table tennis match, the player who serves changes every time after 2 points are scored, regardless of which players scored them. Chef and Cook are playing a different match — they decided that the player who serves would change ever...
```python n=int(input()) for i in range(n): l=list(map(int,input().split())) k=l[0]+l[1] k=k%(2*l[2]) if k>=0 and k<l[2]: print("CHEF") else: print("COOK") ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Kshitij has recently started solving problems on codechef. As he is real problem solving enthusiast, he wants continuous growth in number of problems solved per day. He started with $a$ problems on first day. He solves $d$ problems more than p...
```python # cook your dish here t = int(input()) for _ in range(t): a,d,k,n,inc = map(int, input().strip().split()) res = a for i in range(1, n): if i%k == 0: d += inc res += d print(res) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Coach Moony wants the best team to represent their college in ICPC. He has $N$ students standing in a circle with certain rating $X_i$ on a competitive coding platform. It is an established fact that any coder with more rating on the platform is...
```python # cook your dish here #Moony and ICPC team T = int(input()) for i in range(T): N,data = int(input()),list(map(int,input().split())) if(N==3): print(sum(data)) else: best = data[0]+data[1]+data[2] overall = best k=len(data) for i in range(1,k-2):...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Consider the infinite sequence $s$ of positive integers, created by repeating the following steps: Find the lexicographically smallest triple of positive integers $(a, b, c)$ such that $a \oplus b \oplus c = 0$, where $\oplus$ denotes the b...
```python import sys input = sys.stdin.readline out = [] t = int(input()) for _ in range(t): n = int(input()) n -= 1 rem = n % 3 n //= 3 s = [] if n: n -= 1 while n >= 0: s.append([['00','00','00'],['01','10','11'],['10','11','01'],['11','01','10']][n % 4][rem])...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: You are given two very long integers a, b (leading zeroes are allowed). You should check what number a or b is greater or determine that they are equal. The input size is very large so don't use the reading of symbols one by one. Instead of tha...
```python a = input() b = input() n, m = len(a), len(b) if n > m: b = '0' * (n - m) + b else: a = '0' * (m - n) + a i = 0 while i < max(n, m) and a[i] == b[i]: i += 1 print('=' if i == max(n, m) else '<' if int(a[i]) < int(b[i]) else '>') ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Chef has a sequence $A_1, A_2, \ldots, A_N$. For a positive integer $M$, sequence $B$ is defined as $B = A*M$ that is, appending $A$ exactly $M$ times. For example, If $A = [1, 2]$ and $M = 3$, then $B = A*M = [1, 2, 1, 2, 1, 2]$ You have to hel...
```python def mForMaxSeq(arr, n): eim = dict() for i in range(n): if arr[i] in eim: eim[arr[i]].append(i) else: eim[arr[i]] = [i] keys = sorted(eim.keys()) # print(eim, keys) connected = False count = 0 pI = -1 nKeys = l...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Reading books is one of Sasha's passions. Once while he was reading one book, he became acquainted with an unusual character. The character told about himself like that: "Many are my names in many countries. Mithrandir among the Elves, Tharkûn t...
```python def solve(s): n = len(s) for i in range(n): s2 = s[i:] + s[:i] # print(s2) if s != s2 and s2[::-1] == s2: return 1 for i in range( (n // 2) + 1, n): if s[i] != s[0]: return 2 # print(s[i]) return "Impossible" s = input() print...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Given a number n. Find the last two digits of 5 ^ n ( 5 to the power of n ). Remember that overflow can occur. -----Input:----- - N — the power in which you need to raise number 5. -----Output:----- Last two digits of 5^n. -----Constraints--...
```python print(25) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: The land of Programmers Army is surrounded by many islands. A unique number is associated with each island. The king of the islands is a very generous person, he donates a certain amount of gold coins to travelers for visiting each island that t...
```python # cook your dish here for i in range(int(input())): N = int(input()) l = list(map(int, input().split())) for j in range(int(input())): q1, q2 = map(int, input().split()) temp = l[q1 - 1 : q2] print(sum(temp)) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Berland Football Cup starts really soon! Commentators from all over the world come to the event. Organizers have already built $n$ commentary boxes. $m$ regional delegations will come to the Cup. Every delegation should get the same number of t...
```python n, m, a, b = list(map(int, input().split())) k = n%m print(min(k*b, (m - k)*a)) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Hooray! Polycarp turned $n$ years old! The Technocup Team sincerely congratulates Polycarp! Polycarp celebrated all of his $n$ birthdays: from the $1$-th to the $n$-th. At the moment, he is wondering: how many times he turned beautiful number o...
```python s = [] for i in range(1, 10): k = 0 for l in range(1, 10): k *= 10 k += i s.append(k) s.sort() q = int(input()) while q: n = int(input()) l = 0 r = len(s) while l + 1 < r: m = (l + r) // 2 if s[m] <= n: l = m else: ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Chef got in the trouble! He is the king of Chefland and Chessland. There is one queen in Chefland and one queen in Chessland and they both want a relationship with him. Chef is standing before a difficult choice… Chessland may be considered a ch...
```python def C(n): return n*(n-1)//2 def sol(): equal, mini = False, min(N,M) total_ways = 2*C(N * M) if N==M: equal = True ways = 0 if not equal: ways = (N*C(M)+M*C(N)) diag = 0 for i in range(2, mini+1): diag += 2*C(i) for i in range(mini+1,max(N,M)): diag += C(mini) diag *= 2 ways += dia...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Vasya's older brother, Petya, attends an algorithm course in his school. Today he learned about matchings in graphs. Formally, a set of edges in a graph is called a matching if no pair of distinct edges in the set shares a common endpoint. Petya...
```python def detect_triangle(adj): for x in range(len(adj)): for y in adj[x]: if not set(adj[x]).isdisjoint(adj[y]): return True for _ in range(int(input())): n,m=list(map(int,input().split())) graph=[[] for i in range(n)] for i in range(m): u,v=list(map(int,input().split()))...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: You are standing near a very strange machine. If you put C cents in the machine, the remaining money in your purse will transform in an unusual way. If you have A dollars and B cents remaining in your purse after depositing the C cents, then aft...
```python # cook your dish here for _ in range(int(input())): a,b,c=list(map(int, input().split())) p=a*100+b mx=p ans, cnt = 0, 0 while True: cnt+=1 if p<c or cnt==10000: break else: p-=c a=p//100 b=p%...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: You have found $M$ different types of jewels in a mine and each type of jewel is present in an infinite number. There are $N$ different boxes located at position $(1 ,2 ,3 ,...N)$. Each box can collect jewels up to a certain number ( box at posi...
```python t = int(input()) while t != 0: M = 1000000007 n, m = list(map(int, input().split())) ans = 1 tt = n//2 tt = tt * (tt + 1) ans = pow(m, tt, M) print(ans) t -= 1 ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Chef gives an integer $K$ in the input. If the given number is beautiful binary number, print it, Else find its previous beautiful binary number. A beautiful binary number is a number whose binary representation does not contain any consecutive...
```python pref = [] for i in range(10 ** 5 + 10): b = bin(i)[2:] if not any(b[j] == b[j+1] == '1' for j in range(len(b) - 1)): pref.append(i) else: pref.append(pref[-1]) for i in range(int(input())): print(pref[int(input())]) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Chef had a sequence of positive integers with length $N + K$. He managed to calculate the arithmetic average of all elements of this sequence (let's denote it by $V$), but then, his little brother deleted $K$ elements from it. All deleted elemen...
```python def __starting_point(): t=int(input()) for _ in range(t): n,k,v=map(int,input().split()) li=list(map(int,input().split())) sumn=0 for i in range(n): sumn=sumn+li[i] sumk=v*(n+k)-sumn e=int(sumk/k) r=sumk%k if e<=0: print(-1) elif r!=0: print(-1) else: print(e) __starting_poin...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Petya recieved a gift of a string s with length up to 10^5 characters for his birthday. He took two more empty strings t and u and decided to play a game. This game has two possible moves: Extract the first character of s and append t with this...
```python from collections import deque S = input() mn = [ 300 for i in range( len( S ) ) ] for i in range( len( S ) - 1, -1, -1 ): if i == len( S ) - 1: mn[ i ] = ord( S[ i ] ) else: mn[ i ] = min( mn[ i + 1 ], ord( S[ i ] ) ) ans = "" dq = deque() for i in range( len( S ) ): dq.append( ord( S[ i ] ) ) ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Raj loves to listen to songs in his free time. It’s his birthday tomorrow and his friend Neelansh wants his gift to be the most unique. Being great at making music, he decides to produce a song for him. However, Raj likes songs according to thei...
```python for _ in range(int(input())): n = int(input()) ar = list(map(int,input().split())) d = {} for ele in ar: if ele in d: d[ele] += 1 else: d[ele] = 1 m = 99999 count = 0 for ele in d: count+=1 if m>d[ele]: ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: "I don't have any fancy quotes." - vijju123 Chef was reading some quotes by great people. Now, he is interested in classifying all the fancy quotes he knows. He thinks that all fancy quotes which contain the word "not" are Real Fancy; quotes tha...
```python # cook your dish here import re t=int(input()) while(t>0): s=list(input().split(' ')) if("not" in s): print("Real Fancy") else: print("regularly fancy") t=t-1 ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Motu and Patlu are racing against each other on a circular track of radius $R$. Initially they are at the same point on the track and will run in same direction .The coach ordered them to run $X$ rounds of the circular field. Patlu wants to know...
```python # cook your dish here import math def swap(a,b): return b,a t = int(input()) while(t!=0): z = list(map(int,input().strip().split(" "))) x=z[0] r=z[1] a=z[2] b=z[3] #p = math.pi peri = 2*r tp = x*peri if(a<b): a,b=swap(a,b) t1 = tp/a d2 = t1* b dd = abs(tp-d2) if(dd%peri==0): print(int(d...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Anas is playing an amazing game on a grid with $N$ rows and $M$ columns. The rows are numbered $1$ through $N$ from top to bottom and the columns are numbered $1$ through $M$ from left to right. Anas wants to destroy this grid. To do that, he wa...
```python """ Code chef problem DESTCELL, Destroy Cells """ def find_destroyed_cells(cell_advance, n, m, k): row = 1 col = 1 destroyed_cells = {(1, 1)} while True: row, col = cell_advance(row, col, n, m, k) if row <= n and col <= m: destroyed_cells.add((row, col)) else: break return destroyed_cells ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Prime numbers are arranged in a ordered list U$U$, in increasing order. Let S$S$ be a sublist of U$U$ with a unique property that for every element A$A$ belonging to list S$S$, if i$i$ denotes the index of A$A$ in list U$U$, than i$i$ also belon...
```python import math def prime(aa): f=0 for y in ar: if aa%y==0: return 0 return 1 ar=[] ar.append(2) pc=3 te=int(input()) for _ in range(te): a=int(input()) f=0 c=0 add=0 for x in ar: try: add=add+ar[x-1] except: while True: if prime(pc)==1: ar.append(pc) i...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: You are given a sequence of n integers a1, a2, ..., an and an integer d. Find the length of the shortest non-empty contiguous subsequence with sum of elements at least d. Formally, you should find the smallest positive integer k with the followi...
```python # cook your dish here import collections def shortestSubarray(A, K): N = len(A) P = [0] for x in A: P.append(P[-1] + x) #Want smallest y-x with Py - Px >= K ans = N+1 # N+1 is impossible monoq = collections.deque() #opt(y) candidates, represented as indices             of P for y, P...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Dhiraj loves Chocolates.He loves chocolates so much that he can eat up to $1000$ chocolates a day. But his mom is fed up by this habit of him and decides to take things in her hand. Its diwali Season and Dhiraj has got a lot of boxes of chocolat...
```python def isSubsetSum(arr, n, sum): subset = [ [False for j in range(sum + 1)] for i in range(3) ] for i in range(n + 1): for j in range(sum + 1): if (j == 0):subset[i % 2][j] = True elif (i == 0):subset[i % 2][j] = False elif (arr[i - 1] <= j):subset[i % 2...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: This is one more story about our old friend, the Despotic King. Once every year, it was customary for the king to give audience to the rich merchants of his country in a large hall. On that day, the merchants were ushered in to meet the king one...
```python arr=[] n=int(input()) for i in range(n): a=int(input()) arr.append(a) arr.sort() p=arr.index(a) print((i-p)+1) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Nadaca is a country with N$N$ cities. These cities are numbered 1$1$ through N$N$ and connected by M$M$ bidirectional roads. Each city can be reached from every other city using these roads. Initially, Ryan is in city 1$1$. At each of the follow...
```python T = int(input()) for _ in range(T): N, M, K = [int(x) for x in input().split()] UV = [[int(x) for x in input().split()] for _ in range(M)] Q = int(input()) AB = [[int(x) for x in input().split()] for _ in range(Q)] X = [[i] for i in range(N)] for u, v in UV: X[u - 1] += [v - 1] ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Squirrel Liss lived in a forest peacefully, but unexpected trouble happens. Stones fall from a mountain. Initially Squirrel Liss occupies an interval [0, 1]. Next, n stones will fall and Liss will escape from the stones. The stones are numbered ...
```python t = input() a, b = [i for i, d in enumerate(t, 1) if d == 'l'], [i for i, d in enumerate(t, 1) if d == 'r'] a.reverse() print('\n'.join(map(str, b))) print('\n'.join(map(str, a))) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Rohit collects coins: he has exactly one coin for every year from 1 to n. Naturally, Rohit keeps all the coins in his collection in the order in which they were released. Once Rohit's younger brother made a change — he took all the coins whose r...
```python n=int(input()) a=list(map(int,input().split())) l,r=-1,-1 for i in range(n): if a[i]!=i+1: l=i break for i in range(n-1,-1,-1): if a[i]!=i+1: r=i break j=r+1 for i in range(l,r+1): if a[i]==j: j-=1 continue else: print(0,0) re...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Yet another round on DecoForces is coming! Grandpa Maks wanted to participate in it but someone has stolen his precious sofa! And how can one perform well with such a major loss? Fortunately, the thief had left a note for Grandpa Maks. This not...
```python from sys import stdin, stdout k = int(stdin.readline()) n, m = map(int, stdin.readline().split()) left, right, down, up = [], [], [], [] coordinates = [] for i in range(k): x1, y1, x2, y2 = map(int, stdin.readline().split()) if x1 == x2: if y1 < y2: coordinates.append((x1, y...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Students Vasya and Petya are studying at the BSU (Byteland State University). At one of the breaks they decided to order a pizza. In this problem pizza is a circle of some radius. The pizza was delivered already cut into n pieces. The i-th piece...
```python n = int(input()) a = list(map(int, input().split())) mn = 360 for i in range(n): x = 0 for j in range(i, n): x += a[j] mn = min(mn, abs(x - (360 - x))) print(mn) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Given a binary string $S$ consisting of only 1’s and 0’s where 1 represents a Square and 0 represents a Circle. The diameter of the circle and the side of the square must be any integer (obviously > 0) . You will have to perfectly inscribe (as s...
```python for z in range(int(input())): s = input() n = len(s) i = 0 while i<n and s[i]=='1': i+=1 if i==0: print(0) else: k = 0 while i<n and s[i]=='0': i+=1 k+=1 print(k) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: You are given a string $s$. And you have a function $f(x)$ defined as: f(x) = 1, if $x$ is a vowel f(x) = 0, if $x$ is a constant Your task is to apply the above function on all the characters in the string s and convert the obtained binary st...
```python t=int(input()) MOD=(10**9)+7 l=['a','e','i','o','u'] for i in range(t): s=input() k=[] for j in s: if j in l: k.append(1) else: k.append(0) r=bin(int(''.join(map(str, k)), 2) << 1) print((int(r,2)//2)%MOD) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Appy and Chef are participating in a contest. There are $N$ problems in this contest; each problem has a unique problem code between $1$ and $N$ inclusive. Appy and Chef decided to split the problems to solve between them ― Appy should solve the...
```python for t in range(int(input())): n, a , b , k = map(int,input().split()) solvedbychef = 0 solvedbyappy = 0 for i in range(n+1): if i % a == 0 and i % b == 0 : continue elif i%a == 0 : solvedbyappy+=1 elif i%b == 0: solvedbychef+=1 totalsolved = solvedbychef + solvedbyappy if totalsolved>=k: ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: In these quarantine days, Chef and Chefina are getting bored. So, Chef came up with a game for her. He gets a pack of cards with numbers written on them. Chef then asks her to remove cards from the pack in the following manner: Chefina can choos...
```python # cook your dish here try: for i in range(int(input())): n=int(input()) l=[int(j) for j in input().split()][:n] d={} for j in l: d[j]=d.get(j,0)+1 a=len(d) c=0 for j in list(d.keys()): while(d[j]>=3): d[j]=(d[j]//3)+(d[j]%3) if(d[j]==2): c=c+1 if(c&1): s=0 for j in list...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: A permutation of length $n$ is a sequence of integers from $1$ to $n$ of length $n$ containing each number exactly once. For example, $[1]$, $[4, 3, 5, 1, 2]$, $[3, 2, 1]$ are permutations, and $[1, 1]$, $[0, 1]$, $[2, 2, 1, 4]$ are not. There ...
```python t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) print(*set(a)) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Write a program to take two numbers as input and print their difference if the first number is greater than the second number otherwise$otherwise$ print their sum. -----Input:----- - First line will contain the first number (N1$N1$) - Second li...
```python m = int(input()) n = int(input()) print(m-n) if m>n else print(m+n) ```