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: Abhishek is fond of playing cricket very much. One morning, he is playing cricket with his friends. Abhishek is a right-hand batsman .He has to face all types of balls either good or bad. There are total 26 balls in the game and each ball is...
```python import sys for _ in range(0,eval(input())): d,inp,mp,n,q=set(),list(map(ord,list(sys.stdin.readline().strip()))),[x=='b' for x in list(sys.stdin.readline().strip())],eval(input()),ord('a') inps = [inp[i:] for i in range(len(inp))] inps.sort() op,prev= 0,'' for ip in inps: i,ct=...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: In Chefland, there is a monthly robots competition. In the competition, a grid table of N rows and M columns will be used to place robots. A cell at row i and column j in the table is called cell (i, j). To join this competition, each player wil...
```python import sys def spaces(a,n,m,k,visit1,visit2,dist,position): queue = [position] lastedit = [] dist[position[0]][position[1]] = 0 while queue!=[]: point = queue[0] i = point[0] j = point[1] #print 'point',i,j if visit1[i][j]==False: visit1[i][j] = True startx = max(i-k,0) endx = min(i+k...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: In India, every individual is charged with income tax on the total income each year. This tax is applied to specific ranges of income, which are called income tax slabs. The slabs of income tax keep changing from year to year. This fiscal year (...
```python arr = [0]*6 arr[1] = 250000*(0.05) arr[2] = 250000*(0.10) arr[3] = 250000*(0.15) arr[4] = 250000*(0.20) arr[5] = 250000*(0.25) for _ in range(int(input())): n = int(input()) tax = 0 if n<=250000: tax = 0 elif 250000<n<=500000: tax = sum(arr[:1]) rem = n - 250000 tax+= (rem)*(0.05) elif 50...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Zonal Computing Olympiad 2012, 26 Nov 2011 The year is 2102 and today is the day of ZCO. This year there are N contests and the starting and ending times of each contest is known to you. You have to participate in exactly one of these contests....
```python import sys n, x, y = input().split(' ') n = int(n) x = int(x) y = int(y) contests = {} for i in range(n): s, e = input().split(' ') s = int(s) e = int(e) contests[(s, e)] = abs(s-e) v_time = input().split(' ') w_time = input().split(' ') v_time, w_time = list(map(int, v_time)), list(map(int, w_time)) v...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Chef Ada is the FootBall coach of the Dinosaurs Institute of Technology. There are $N$ dinosaurs (enumerated $1$ through $N$) placed in a line. The i-th dinosaur has a height of $i$ meters. Ada is training The dinosaurs in the following tactic: ...
```python # cook your dish here t=int(input()) while t!=0: n,k=map(int,input().split()) lst=[] for i in range(1,n+1): lst.append(i) lst[k],lst[n-1]=lst[n-1],lst[k] for item in lst: print(item,end=' ') t-=1 ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: There exist certain strings, known as $Unique$ $Strings$. They possess a unique property: - The character 'c' gets converted to "ff" and the character 'k' gets converted to "gg". Any letter besides 'c' and 'k' does not get converted to any othe...
```python tb=str(input()) tb=list(tb) if("c" in tb or "k" in tb): print(0) else: ans=1 i=0 while(i<len(tb)): if(tb[i]=="g" or tb[i]=="f"): my=tb[i] i+=1 ct=1 while(i<len(tb) and tb[i]==my): ct+=1 i+=1 if(ct>3): ct+=1 ans*=ct else: i+=1 print(ans) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Chef is in need of money, so he decided to play a game with Ramsay. In this game, there are $N$ rows of coins (numbered $1$ through $N$). For each valid $i$, the $i$-th row contains $C_i$ coins with values $A_{i, 1}, A_{i, 2}, \ldots, A_{i, C_i}...
```python for i in range(int(input())): n=int(input()) chef=0 ans=[] for i in range(0,n): l=list(map(int,input().split())) c=l[0] if c%2==0: for i in range(1,len(l)//2+1): chef=chef+l[i] continue; for i in range(1,len(l)//2): chef=chef+l[i] ans.append(l[len(l)//2]) ans.sort(reverse=True) fo...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Chef likes problems related to learning new languages. He only knows first N letters of English alphabet. Also he explores all M-letter words formed by the characters he knows. Define cost for a given M-letter word S, cost(S) = P1, S1+P2, S2+......
```python def dfs(ind,m,n,k): if(ind == m): return [""] else: temp = dfs(ind+1,m,n,k) ans = [] if(len(temp)<k): for i in temp: for j in range(97,97+n): ans += [chr(j)+i] else: for i in temp: ans += ["z"+i] return ans n,m,k = list(map(int,input().split())) p = [] mr= [] for _ in range(m):...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: To protect people from evil, a long and tall wall was constructed a few years ago. But just a wall is not safe, there should also be soldiers on it, always keeping vigil. The wall is very long and connects the left and the right towers. The...
```python D=[0]*31 D[1]=2 D[2]=5 for i in range(3,31): best=10**10 for p in range(1,i+1): best=min(best,D[p-1]+D[i-p]+i+1) D[i]=best t=int(input()) for i in range(t): n,m=list(map(int,input().split())) maxi=(n+2)*(n+1)/2-1 mini=D[n] if mini<=m<=maxi: print(0) elif m<mini: print(-1) else: print(m-maxi) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: There are some websites that are accessible through several different addresses. For example, for a long time Codeforces was accessible with two hostnames codeforces.com and codeforces.ru. You are given a list of page addresses being queried. F...
```python # Bartek Kostka # You are not prepared! #include "bits/stdc++.h" n = int(input()) W = {} for i in range(n): adr = input() adr = adr.split("/") if adr[-1] == '': adr[-1] = '?' domena = "/".join(adr[:3]) adres = "/".join(adr[3:]) #print(domena, adres) if domena not in W: ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: You are given $n$ strings $a_1, a_2, \ldots, a_n$: all of them have the same length $m$. The strings consist of lowercase English letters. Find any string $s$ of length $m$ such that each of the given $n$ strings differs from $s$ in at most one...
```python def isvalid(s): nonlocal l for i in l: count=0 for j in range(len(i)): if(s[j]!=i[j]): count+=1 if(count>1): return 0 return 1 t=int(input()) for you in range(t): l=input().split() n=int(l[0]) m=int(l[1]) l=[] for ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: This is a peculiar functioning setup. Two Tanks are separated from each other by a wall .There is a pipe in the wall which connects both tanks which allows flow of water between them . Due to this ,there is change in temperature of both tanks ...
```python for i in range(int(input())): m,tc,th=map(int,input().split()) x=(th-tc) if x%3!=0: print("Yes") else: if (x//3)<=m: print("No") else: print("Yes") ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Alex decided to go on a touristic trip over the country. For simplicity let's assume that the country has $n$ cities and $m$ bidirectional roads connecting them. Alex lives in city $s$ and initially located in it. To compare different cities Al...
```python import sys input = sys.stdin.readline n,m=list(map(int,input().split())) W=[0]+list(map(int,input().split())) E=[tuple(map(int,input().split())) for i in range(m)] S=int(input()) ELIST=[[] for i in range(n+1)] EW=[0]*(n+1) for x,y in E: ELIST[x].append(y) ELIST[y].append(x) EW[x]+=1 EW[y]+...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Due to COVID19 all employees of chemical factory are quarantined in home. So, company is organized by automated robots. There are $N$ Containers in company, which are labelled with $1$ to $N$ numbers. There are Total $N$ robots in Company, which...
```python T = int(input()) for _ in range(T): N, K1, K2 = list(map(int, input().split())) P1, P2, P3, P4 = list(map(int, input().split())) ans = 0 arr = [0] * (1005) length = len(arr) for i in range(1,N+1): j = 0 while j < length: arr[j] += 1 ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Given a permutation $p$ of length $n$, find its subsequence $s_1$, $s_2$, $\ldots$, $s_k$ of length at least $2$ such that: $|s_1-s_2|+|s_2-s_3|+\ldots+|s_{k-1}-s_k|$ is as big as possible over all subsequences of $p$ with length at least $2$. ...
```python for _ in range(int(input())): # n, x = map(int, input().split()) n = int(input()) arr = list(map(int, input().split())) ans = [arr[0]] for i in range(1, n - 1): if arr[i - 1] < arr[i] and arr[i] > arr[i + 1]: ans.append(arr[i]) elif arr[i - 1] > arr[i] and arr[i...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Recently, Dima met with Sasha in a philatelic store, and since then they are collecting coins together. Their favorite occupation is to sort collections of coins. Sasha likes having things in order, that is why he wants his coins to be arranged ...
```python n = int(input()) a = list(map(int, input().split())) p = [0] * (n + 1) ans = [1] * (n + 1) ind = n for i in range(n): p[a[i] - 1] = 1 while ind > 0 and p[ind - 1] == 1: ind -= 1 ans[i + 1] = 1 + (i + 1) - (n - ind) print(' '.join(map(str, ans))) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: The mayor of the Central Town wants to modernize Central Street, represented in this problem by the $(Ox)$ axis. On this street, there are $n$ antennas, numbered from $1$ to $n$. The $i$-th antenna lies on the position $x_i$ and has an initial ...
```python import sys input = sys.stdin.readline n,m=list(map(int,input().split())) A=[] COVERED=[0]*(m+1) for i in range(n): x,y=list(map(int,input().split())) A.append((x-y,x+y)) for j in range(max(0,x-y),min(m+1,x+y+1)): COVERED[j]=1 if min(COVERED[1:])==1: print(0) return A.sort() ...
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 n lowercase Latin letters. You have to type this string using your keyboard. Initially, you have an empty string. Until you type the whole string, you may perform the following operation: add a character ...
```python n = int(input()) st = input() ans = n now = '' ma = 0 for i in range(n // 2): now += st[i] t = '' for j in range(i + 1, 2 * i + 2): t += st[j] if t == now: ma = i print(ans - ma) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Given an array $A$ of length $N$. We have to find the $maximum$ sum of elements of the subarray between $two$ nearest occurrences of $same$ elements (excluding both). If both the elements are $even$ then the total number of $even$ elements in th...
```python # cook your dish here from sys import stdin, stdout from collections import defaultdict for _ in range(int(stdin.readline())): n=int(stdin.readline()) lst=list(map(int, stdin.readline().split())) prefix_odd=[0]*n prefix_even=[0]*n odd_val=0 even_val=0 for i in range(n): if ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Chef recently graduated Computer Science in university, so he was looking for a job. He applied for several job offers, but he eventually settled for a software engineering job at ShareChat. Chef was very enthusiastic about his new job and the f...
```python # cook your dish here try: for _ in range(int(input())): n = int(input()) li = [i for i in input()] a = 0 while a+1<len(li): li[a],li[a+1] = li[a+1],li[a] a+=2 li2 = li.copy() for i in li2: fh = 109 sh = 110 li.remove(i) if ord(i)>fh: li.append(chr(fh-(ord(i)-sh))) else: ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Let's look at the following process: initially you have an empty stack and an array $s$ of the length $l$. You are trying to push array elements to the stack in the order $s_1, s_2, s_3, \dots s_{l}$. Moreover, if the stack is empty or the eleme...
```python # encoding: utf-8 from sys import stdin def solve(a): # root node of tries denotes empty stack stack = [None] node_stack = [[1, {}]] trie = node_stack[-1] counter = 0 for i in range(len(a)): el = a[i] if len(stack) == 0 or stack[-1] != el: current_node ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Sherlock Holmes has decided to start a new academy to some of the young lads. He has conducted several tests and finally selected N equally brilliant students.Now he don't know whether to train all the N students or not. Now since Holmes was in...
```python t = eval(input()) for i in range(t): n = eval(input()) a = list(map(int, input().split())) cnt = 2 cnt1 = 2 ll = len(a) if ll < 3: cnt1 = ll else: for j in range(2,ll): if a[j-1] + a[j-2] == a[j]: cnt += 1 cnt1 = max(cnt1, cnt) else: cnt1 = max(cnt1, cnt) cnt = 2 print(cnt1)...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Vision has finally made it to Wakanda to get his MindStone extracted. The MindStone was linked to his brain in a highly sophisticated manner and Shuri had to solve a complex problem to extract the stone. The MindStone had $n$ integers inscribed ...
```python # cook your dish here from itertools import accumulate n, k = map(int, input().split()) lst = list(map(int, input().split())) temp = (10**9)+7 for i in range(k): lst = list(accumulate(lst)) for i in lst: print(i%(temp), end = ' ') ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: The chef has a number N, Cheffina challenges chef to form the largest number X from the digits of N. -----Input:----- - First-line will contain $T$, the number of test cases. Then the test cases follow. - Each test case contains a single line ...
```python # cook your dish here n=int(input()) l=[] for i in range(n): a=int(input()) l.append(a) for i in l: b = list(map(int, str(i))) b.sort(reverse=True) s = [str(i) for i in b] r = int("".join(s)) print(r) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: You are given an unweighted, undirected graph. Write a program to check if it's a tree topology. -----Input----- The first line of the input file contains two integers N and M --- number of nodes and number of edges in the graph (0 < N <= 1000...
```python #!/usr/bin/env python def iscycle(E, v, EXPLORED_NODES, EXPLORED_EDGES): EXPLORED_NODES.add(v) r = False for e in [x for x in E if v in x]: if e in EXPLORED_EDGES: continue if e[0] == v: w = e[1] else: w = e[0] if w in EXPLORED_NODES: return True else: EXPLORED_EDGES.add(e) r = ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Chef has just started Programming, he is in first year of Engineering. Chef is reading about Relational Operators. Relational Operators are operators which check relatioship between two values. Given two numerical values A and B you need to he...
```python # cook your dish here for _ in range(int(input())): x, y= map(int, input().split()) if x<y: print('<') elif x>y: print('>') else: print('=') ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: You are given three numbers $a$, $b$, $c$ . Write a program to determine the largest number that is less than or equal to $c$ and leaves a remainder $b$ when divided by $a$. -----Input:----- - First line will contain $T$, number of testcases. T...
```python # cook your dish here for t in range(int(input())): a,b,c=map(int,input().split()) p=(c//a)*a+b if p<=c: print(p) else: print(((c//a)-1)*a+b) ```
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. The BerTV channel every day broadcasts one episode of one of the $k$ TV shows. You know the schedule for the next $n$ days: a sequence of integers $a_1, a_2, \dots, a_n$ ($1 \le...
```python for _ in range(int(input())): n, k, d = list(map(int, input().split())) a = list(map(int, input().split())) s = {} for q in range(d): s[a[q]] = s.get(a[q], 0)+1 ans = len(s) for q in range(d, n): if s[a[q-d]] == 1: del s[a[q-d]] else: s[a...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: If Give an integer N . Write a program to obtain the sum of the first and last digits of this number. -----Input----- The first line contains an integer T, the total number of test cases. Then follow T lines, each line contains an integer N. ...
```python n = int(input()) for i in range(n): s = input() l = len(s) n1 = int(s[0]) n2 = int(s[l-1]) print(n1+n2) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Sig has built his own keyboard. Designed for ultimate simplicity, this keyboard only has 3 keys on it: the 0 key, the 1 key and the backspace key. To begin with, he is using a plain text editor with this keyboard. This editor always displays one...
```python N=int(input()) M=len(input()) O=10**9+7 D=[pow(-~O//2,M,O)]+[0]*N for _ in'_'*N:D=[D[0]+D[1]]+[(i+2*j)%O for i,j in zip(D[2:]+[0],D[:-1])] print(D[M]) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: -----Problem Statement----- Levy's conjecture, named after Hyman Levy, states that all odd integers greater than 5 can be represented as the sum of an odd prime number and an even semiprime. To put it algebraically, 2n + 1 = p + 2q always has a ...
```python isPrime=[1 for i in range(10001)] cnt=[0 for i in range(10001)] isPrime[0]=0 isPrime[1]=0 prime=[] for i in range(2,10001): if isPrime[i]: prime.append(i) for j in range(i*i,10001,i): isPrime[j]=0 #print(prime) for i in prime: for j in prime: if (i + 2*j)>10000: break else: cnt[i + 2*j]+=1 ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Vivek initially has an empty array $a$ and some integer constant $m$. He performs the following algorithm: Select a random integer $x$ uniformly in range from $1$ to $m$ and append it to the end of $a$. Compute the greatest common divisor of ...
```python big = 100010 def gen_mu(): mu = [1]*big mu[0] = 0 P = [True]*big P[0] = P[1] = False for i in range(2,big): if P[i]: j = i while j<big: P[j] = False mu[j] *= -1 j += i j = i*i while j<bi...
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 $2n$. Consider a partition of array $a$ into two subsequences $p$ and $q$ of length $n$ each (each element of array $a$ should be in exactly one subsequence: either in $p$ or in $q$). Let's sort $p$ in non-d...
```python import sys from sys import stdin def modfac(n, MOD): f = 1 factorials = [1] for m in range(1, n + 1): f *= m f %= MOD factorials.append(f) inv = pow(f, MOD - 2, MOD) invs = [1] * (n + 1) invs[n] = inv for m in range(n, 1, -1): inv *= m in...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Есть n-подъездный дом, в каждом подъезде по m этажей, и на каждом этаже каждого подъезда ровно k квартир. Таким образом, в доме всего n·m·k квартир. Они пронумерованы естественным образом от 1 до n·m·k, то есть первая квартира на первом этаже в ...
```python n, m, k = map(int, input().split()) a, b = map(int, input().split()) a -= 1 b -= 1 def p(x): return x // (m * k) def e(x): return (x - p(x) * m * k) // k def lift(x): return min(5 * x, 10 + x) if p(a) == p(b): dif = abs(e(a) - e(b)) print(lift(dif)) else: print(lift(e(a)) + 15 * min((p(a) - p(b) + n) ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Chef has $N$ small boxes arranged on a line from $1$ to $N$. For each valid $i$, the weight of the $i$-th box is $W_i$. Chef wants to bring them to his home, which is at the position $0$. He can hold any number of boxes at the same time; however...
```python t=int(input()) for i in range(t): x,y=0,0 n,m=list(map(int,input().split())) l=list(map(int,input().split())) if(max(l)>m): print(-1) else: for i in range(len(l)): y+=l[i] if(y>m): y=l[i] x+=1 if(y>0): x+=1 print(x) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: You are given $n$ arrays that can have different sizes. You also have a table with $w$ columns and $n$ rows. The $i$-th array is placed horizontally in the $i$-th row. You can slide each array within its row as long as it occupies several consec...
```python import sys input = sys.stdin.readline from collections import deque def slidemax(X, k): q = deque([]) ret = [] for i in range(len(X)): while q and q[-1][1] <= X[i]: q.pop() deque.append(q, (i+k, X[i])) if q[0][0] == i: deque.popleft(q) if i >...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: The auditorium of Stanford University is made up of L*R matrix (assume each coordinate has a chair). On the occasion of an event Chef was called as a chief guest. The auditorium was filled with males (M) and females (F), occupying one chair each...
```python def matrix(L,row,col,c): d={} dp=[] for i in range(row+1): temp=[] for i in range(col+1): temp.append([]) dp.append(temp) for i in range(row+1): dp[i][0]=0 for i in range(col+1): dp[0][i]=0 for i in range(1,row+1): for j in range(1,col+1): if L[i-1][j-1]==c: dp[i][j]=min(dp[i][j-1...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: The chef is playing a game of long distance. Chef has a number K and he wants to find the longest distance between the index of the first and the last occurrence of K in a given array of N numbers. -----Input:----- - First-line will contain $T$...
```python # cook your dish here for _ in range(int(input())): m,n=list(map(int,input().split())) a=[int(i) for i in input().split()] l=-1 for i in range(n-1,-1,-1): if a[i]==m: l=i break f=-1 for i in range(0,n): if a[i]==m: f=i bre...
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 from sys import stdin, stdout from collections import Counter n = int(stdin.readline()) #l = list(map(int, stdin.readline().split())) #l = [int(stdin.readline()) for _ in range(n)] #a, b = map(int, stdin.readline().split()) for _ in range(n): n1 = int(stdin.readline()) if n1==1: print...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: -----Problem Statement----- You all must have played the game candy crush. So here is a bomb which works much the fruit bomb in candy crush. A designer, Anton, designed a very powerful bomb. The bomb, when placed on a location $(x, y)$ in a $R \...
```python r,c,n = map(int , input().split());coordinates = [];coordinates_1,coordinates_2 = {},{} for _ in range(n): x,y = map(int , input().split()) coordinates.append([x,y]) for i in coordinates: if(i[0] in coordinates_1): coordinates_1[i[0]] += 1 else: coordinates_1[i[0]] = 1 if(i[1] in coordina...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Young Sheldon is given the task to teach Chemistry to his brother Georgie. After teaching him how to find total atomic weight, Sheldon gives him some formulas which consist of $x$, $y$ and $z$ atoms as an assignment. You already know that Georg...
```python for _ in range(int(input())): s = list(input().strip()) i = 0 while i < len(s) - 1: if s[i].isalpha() or s[i] == ')': if s[i + 1].isdigit(): if i + 2 >= len(s) or s[i + 2] == ')': s = s[:i+1] + ['*', s[i+1]] + s[i+2:] else: s = s[:i+1] + ['*', s[i+1], '+'] + s[i+2:] i += 1 e...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: As you might remember, the collector of Siruseri had ordered a complete revision of the Voters List. He knew that constructing the list of voters is a difficult task, prone to errors. Some voters may have been away on vacation, others may have m...
```python from sys import stdout, stdin n,m,o = list(map(int, stdin.readline().split())) n= n+m+o l=[] a=[] for i in range(n): b= int(stdin.readline()) if(b in l and b not in a): l.append(b) a.append(b) elif(b not in l): l.append(b) a.sort() stdout.write(str(len(a)) + '\n') stdout....
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Chef usually likes to play cricket, but now, he is bored of playing it too much, so he is trying new games with strings. Chef's friend Dustin gave him binary strings $S$ and $R$, each with length $N$, and told him to make them identical. However...
```python for _ in range(int(input())): length = int(input()) S = input() R = input() if S.count("1") == R.count("1"): print("YES") else: print("NO") ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: A string with length $L$ is called rich if $L \ge 3$ and there is a character which occurs in this string strictly more than $L/2$ times. You are given a string $S$ and you should answer $Q$ queries on this string. In each query, you are given a...
```python t=int(input()) for _ in range(t): n,q=map(int,input().split()) s=input() l=[0]*(n-1) for i in range(n-2): a,b,c=s[i],s[i+1],s[i+2] if len(set([a,b,c]))<3: l[i]=l[i-1]+1 else: l[i]=l[i-1] for i in range(q): left,right=map(int,input().split()) left-=1 right-=1 if right-left+1 <3: ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: You are given an array $a$ consisting of $n$ integers. Beauty of array is the maximum sum of some consecutive subarray of this array (this subarray may be empty). For example, the beauty of the array [10, -5, 10, -4, 1] is 15, and the beauty of ...
```python N, X = list(map(int, input().split())) A = [int(a) for a in input().split()] dp = [[0]*4 for _ in range(N+1)] for i in range(1, N+1): dp[i][0] = max(dp[i-1][0] + A[i-1], 0) dp[i][1] = max(dp[i-1][1] + A[i-1] * X, dp[i][0]) dp[i][2] = max(dp[i-1][2] + A[i-1], dp[i][1]) dp[i][3] = max(dp[i-1][...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: A prime number is number x which has only divisors as 1 and x itself. Harsh is playing a game with his friends, where his friends give him a few numbers claiming that they are divisors of some number x but divisor 1 and the number x itself are n...
```python import math def findnumber(l,n): l.sort() x = l[0] * l[-1] vec = [] i = 2 while (i*i)<=x: if x%i==0: vec.append(i) if x//i !=i: vec.append(x//i) i = i + 1 vec.sort() if len(vec)!=n: return -1 else: j = ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: There is a country with $n$ citizens. The $i$-th of them initially has $a_{i}$ money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social se...
```python n=int(input()) a=list(map(int,input().split())) q=int(input()) changes=[0]*q for i in range(q): changes[-i-1]=tuple(map(int,input().split())) final=[-1]*n curr=0 for guy in changes: if guy[0]==1: if final[guy[1]-1]==-1: final[guy[1]-1]=max(guy[2],curr) else: curr=max(cu...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Chef has a garden with $N$ plants arranged in a line in decreasing order of height. Initially the height of the plants are $A_1, A_2, ..., A_N$. The plants are growing, after each hour the height of the $i$-th plant increases by $i$ millimeters....
```python for _ in range(int(input())): n = int(input()) arr = list(map(int, input().split())) hrs = arr[0] - arr[1] for i in range(1, n-1): if hrs > arr[i] - arr[i+1]: hrs = arr[i] - arr[i+1] print(hrs) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: You have been appointed as the designer for your school's computer network. In total, there are N computers in the class, and M computer-to-computer connections need to be made. Also, there are three mandatory conditions the design should fulfil...
```python import fractions import sys f = sys.stdin if len(sys.argv) > 1: f = open(sys.argv[1], "rt") def calc(N, M): if M != N: return [(-1, -1)] r = [(i+1, ((i+1) % N)+1) for i in range(N)] return r T = int(f.readline().strip()) for case_id in range(1, T+1): N, M = list(map(int, f.readline().strip().sp...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: You might have heard about the next game in Lara Croft series coming out this year. You also might have watched its trailer. Though you definitely missed the main idea about its plot, so let me lift the veil of secrecy. Lara is going to explore...
```python n, m, k = map(int, input().split()) ans = 0, 0 if k < n: ans = k + 1, 1 else: k -= n r = n - k // (m - 1) if r % 2: c = m - k % (m - 1) else: c = 2 + k % (m - 1) ans = r, c print(*ans) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: When Serezha was three years old, he was given a set of cards with letters for his birthday. They were arranged into words in the way which formed the boy's mother favorite number in binary notation. Serezha started playing with them immediately...
```python def main(): import sys input = sys.stdin.readline n = int(input()) arr = input() one = arr.count('n') zero = arr.count('z') ans = [1] * one + [0] * zero print(*ans) return 0 main() ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Absent-minded Masha got set of n cubes for her birthday. At each of 6 faces of each cube, there is exactly one digit from 0 to 9. Masha became interested what is the largest natural x such she can make using her new cubes all integers from 1 to...
```python n = int(input()) a = sorted([list(map(int, input().split())) for i in range(n)]) import itertools for x in range(1,10**n): good = False s = str(x) for p in itertools.permutations(a, len(s)): good |= all([int(s[i]) in v for i, v in enumerate(p)]) if not good: print(x-1) return print((...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: You are given a grid of size M x N, where each square is colored with some random color among K colors with each having equal probability. A Good Rectangle is defined as one where all squares lying on the inner border are of the same color. Wh...
```python def for1(M,k): ret = 0.0 x = k*k+0.0 z=x for m in range(1,M): ret+=(M-m)/x x*=z return ret def for2(M,k): ret = 0.0 x = k+0.0 for m in range(1,M): ret+=(M-m)/x x*=k return ret def ans(M,N,K): return int(round(M*N+M*for2(N,K)+N*for2(M,K)+K*for1(M,K)*for1(N,K),0)) M,N,K = list(map(...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: You are given a string $S$ and an integer $L$. A operation is described as :- "You are allowed to pick any substring from first $L$ charcaters of $S$, and place it at the end of the string $S$. A string $A$ is a substring of an string $B$ if $A...
```python def least_rotation(S: str) -> int: """Booth's algorithm.""" f = [-1] * len(S) # Failure function k = 0 # Least rotation of string found so far for j in range(1, len(S)): sj = S[j] i = f[j - k - 1] while i != -1 and sj != S[k + i + 1]: if sj < S[k +...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: You are given a Young diagram. Given diagram is a histogram with $n$ columns of lengths $a_1, a_2, \ldots, a_n$ ($a_1 \geq a_2 \geq \ldots \geq a_n \geq 1$). [Image] Young diagram for $a=[3,2,2,2,1]$. Your goal is to find the largest number ...
```python import sys readline = sys.stdin.readline N = int(readline()) A = list(map(int, readline().split())) BW = [0, 0] for i in range(N): a = A[i] BW[i%2] += a//2 BW[(i+1)%2] += -(-a//2) print(min(BW)) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: The biggest event of the year – Cota 2 world championship "The Innernational" is right around the corner. $2^n$ teams will compete in a double-elimination format (please, carefully read problem statement even if you know what is it) to identify ...
```python import sys input = sys.stdin.readline n,k=list(map(int,input().split())) if k==0: print(0) return A=sorted(map(int,input().split())) # DP[UL][n][left] # [left*pow(2,n),left*pow(2,n)+pow(2,n))の間のチームで, # ファンのチームが # UL=0: upperでもlowerでも勝ち残っている # UL=1: upperでのみ勝ち残っている # UL=2: lowerでのみ勝ち残っている # ときの、そこまで...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: In some country there are exactly n cities and m bidirectional roads connecting the cities. Cities are numbered with integers from 1 to n. If cities a and b are connected by a road, then in an hour you can go along this road either from city a t...
```python from itertools import combinations_with_replacement from collections import deque #sys.stdin = open("input_py.txt","r") n, m = map(int, input().split()) G = [ [] for i in range(n)] for i in range(m): x, y = map(int, input().split()) x-=1; y-=1 G[x].append(y) G[y].append(x) def BFS(s): ...
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 want all the elements of the sequence to be equal. In order to achieve that, you may perform zero or more moves. In each move, you must choose an index $i$ ($1 \le i \le N$), then choose $j =...
```python for _ in range(int(input())): n=int(input()) a=[int(z) for z in input().split()] m=0 a1=list(set(a)) for i in range(len(a1)): if a.count(a1[i])>m: m=a.count(a1[i]) print(n-m) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Chef received a new sequence $A_1, A_2, \ldots, A_N$. He does not like arbitrarily ordered sequences, so he wants to permute the elements of $A$ in such a way that it would satisfy the following condition: there is an integer $p$ ($1 \le p \le N...
```python for _ in range(int(input())): n = int(input()) arr= list(map(int,input().split())) arr.sort() d={} for i in arr: if i not in d: d[i]=1 else: d[i]+=1 flag = True for i in d: if d[i]>2: flag=False break if arr.count(max(arr))!=1: flag=False if flag==True: arr1=[] ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Ms. E.T. came from planet Hex. She has 8 fingers in each hand which makes her count in hexadecimal way. When she meets you, she tells you that she came from 7E light years from the planet Earth. You see she means that it is 126 light years far a...
```python # cook your dish here try: t=int(input()) for i in range(t): s=input() i=int(s,16) print(i) except EOFError as e: print(e) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: A mad scientist Dr.Jubal has made a competitive programming task. Try to solve it! You are given integers $n,k$. Construct a grid $A$ with size $n \times n$ consisting of integers $0$ and $1$. The very important condition should be satisfied: t...
```python for _ in range(int(input())): n, k = map(int, input().split()) mat = [[0] * n for _ in range(n)] for i in range(n): b = False for j in range(n): if i*n+j == k: b = True break mat[(i+j)%n][j] = 1 if b: break...
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 for _ in range(int(input())): n = int(input()) s = '' for i in range(1, n + 1): s += str(i) for i in range(n, 0, -1): if i % 2 == 0: for j in range(i, 0, -1): print(j, end = '') else: for j in range(1, i + 1): print(j, end = '') print() ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: You must have tried to solve the Rubik’s cube. You might even have succeeded at it. Rubik’s cube is a 3x3x3 cube which has 6 different color for each face.The Rubik’s cube is made from 26 smaller pieces which are called cubies. There are 6 cubie...
```python for _ in range(int(input())): m=int(input()) n=int(input()) o=int(input()) ans=4*(m+n+o)-24 if(ans <= 0): print('0') else: print(ans) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Bessie the cow and her best friend Elsie each received a sliding puzzle on Pi Day. Their puzzles consist of a 2 × 2 grid and three tiles labeled 'A', 'B', and 'C'. The three tiles sit on top of the grid, leaving one grid cell empty. To make a mo...
```python a, b, c, d = input(), input(), input(), input() a = a + b[::-1] x = "X" for i in range(4): if a[i] == x: a = a[:i] + a[i + 1:] break c = c + d[::-1] for i in range(4): if c[i] == x: c = c[:i] + c[i + 1:] break flag = False for i in range(4): if a == c: flag...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossib...
```python t = int(input()) for ti in range(t): n = int(input()) lri = [None for _ in range(n)] for _ in range(n): li, ri = list(map(int, input().split())) lri[_] = (li, ri, _) lri.sort() t = [None for _ in range(n)] ct, t[lri[0][2]], eg = 1, 1, lri[0][1] for i in range(1, n): if lri[i][0] <= eg: ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: You have an array a consisting of n integers. Each integer from 1 to n appears exactly once in this array. For some indices i (1 ≤ i ≤ n - 1) it is possible to swap i-th element with (i + 1)-th, for other indices it is not possible. You may per...
```python n = int(input()) a = list(map(int,input().split())) p = input() m = 0 suc = True for i in range(n-1): m = max(m,a[i]) if p[i] == '0' and m>(i+1): suc = False break if suc: print('YES') else: print('NO') ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: "If you didn't copy assignments during your engineering course, did you even do engineering?" There are $Q$ students in Chef's class. Chef's teacher has given the students a simple assignment: Write a function that takes as arguments an array $A...
```python def f(a,y,index,sorted_pos): #print(a,y,index,sorted_pos) n=len(a) low=0 high=n-1 L,R=0,0 l,r=0,0 while(low<=high): mid=(low+high)//2 #print(low,high,mid) if(a[mid]== y): break elif(mid > index[y]): high=mid-1 L+=1 #print("L") if(a[mid] <y): l+=1 #print(" l ") else: ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: The Petrozavodsk camp takes place in about one month. Jafar wants to participate in the camp, but guess what? His coach is Yalalovichik. Yalalovichik is a legendary coach, famous in the history of competitive programming. However, he is only wil...
```python M = 10 ** 9 + 7 for _ in range(int(input())): s,p,m,r = list(map(int, input())),0,1,0 for d in reversed(s): p += d * m m = m * 10 % M for d in s: r = (r * m + p) % M p = (p * 10 - (m - 1) * d) % M print(r) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Consider an infinite full binary tree (each node has two children except the leaf nodes) defined as follows. For a node labelled v its left child will be labelled 2*v and its right child will be labelled 2*v+1. The root is labelled as 1. You are...
```python t=eval(input()) for _ in range(t): i,j=list(map(int,input().split())) bi=bin(i)[2:] bj=bin(j)[2:] k=0 while k<(min(len(bi),len(bj))): if bi[k]!=bj[k]: break else: k+=1 print(len(bi)-k+len(bj)-k) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: in Chefland, there is a very famous street where $N$ types of street food (numbered $1$ through $N$) are offered. For each valid $i$, there are $S_i$ stores that offer food of the $i$-th type, the price of one piece of food of this type is $V_i$...
```python t=int(input()) while(t): n=int(input()) l=[] for i in range(n): l.append(list(map(int,input().split()))); m=[] for i in l: m.append((i[1]//(i[0]+1))*i[2]) res=max(m) print(res) t=t-1 ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Rachel has some candies and she decided to distribute them among $N$ kids. The ith kid receives $A_i$ candies. The kids are happy iff the difference between the highest and lowest number of candies received is less than $X$. Find out if the chil...
```python t=int(input()) for t1 in range(t): n,x=map(int,input().split()) a=list(map(int,input().split())) mx=max(a) mn=min(a) if (mx-mn<x): print("YES") else: print("NO") ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Nauuo is a girl who loves drawing circles. One day she has drawn a circle and wanted to draw a tree on it. The tree is a connected undirected graph consisting of $n$ nodes and $n-1$ edges. The nodes are numbered from $1$ to $n$. Nauuo wants t...
```python import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**10 mod = 998244353 dd = [(-1,0),(0,1),(1,0),(0,-1)] ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] def LI(): return list(map(int, sys.stdin.rea...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: You are given a string $S$. Find the number of ways to choose an unordered pair of non-overlapping non-empty substrings of this string (let's denote them by $s_1$ and $s_2$ in such a way that $s_2$ starts after $s_1$ ends) such that their concat...
```python def binarySearch(arr, l, r, x): mid=0 while l <= r: mid = l + (r - l)//2; if arr[mid] == x: return mid+1 elif arr[mid] < x: l = mid + 1 else: r = mid - 1 if mid!=len(arr): if arr[mid]<x: return mid+1 return mid s=input() strt=[] end=[] plc=[] landr=[] l2r=[] lr=[] ans=0 n=len(s...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: On her way to ChefLand, Marichka noticed $10^K$ road signs (numbered $0$ through $10^K - 1$). For each valid $i$, the sign with number $i$ had the integer $i$ written on one side and $10^K-i-1$ written on the other side. Now, Marichka is wonderi...
```python import math t=int(input()) for i in range(t): k=int(input()) res=((pow(2,k,1000000007))*5)%1000000007 print(res) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Did you know that there are over 40,000 varieties of Rice in the world ? There are so many dishes that can be prepared with Rice too. A famous chef from Mumbai, Tid Gusto prepared a new dish and named it 'Tid Rice'. He posted the recipe in his n...
```python import sys def f(p): votes = {} for x in range(p): str = sys.stdin.readline() t = str.split() votes[t[0]] = t[1] ans = 0 for per in votes: if votes[per] == "+": ans= ans+1 else: ans = ans-1 return ans x = sys.stdin.readline() for t in range(int(x)): p = sys.stdi...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Tennis is a popular game. Consider a simplified view of a tennis game from directly above. The game will appear to be played on a 2 dimensional rectangle, where each player has his own court, a half of the rectangle. Consider the players and the...
```python eps=1e-8 t=int(input()) for ii in range(t): n=int(input()) l=[int(i) for i in input().split() ] b=[int(i) for i in input().split() ] v=[int(i) for i in input().split() ] c=[int(i) for i in input().split() ] greatest_time=l[0]/v[0] for i in range(1,n): if v[i]>0: ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Chef changed the password of his laptop a few days ago, but he can't remember it today. Luckily, he wrote the encrypted password on a piece of paper, along with the rules for decryption. The encrypted password is a string S consists of ASCII pri...
```python from decimal import Decimal T = int(input()) for _ in range(T): N = int(input()) data = dict() for __ in range(N): ci, pi = input().split() data[ci] = pi S = list(input()) for i in range(len(S)): if S[i] in data.keys(): S[i] = data[S[i]] ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: You are given n strings s_1, s_2, ..., s_{n} consisting of characters 0 and 1. m operations are performed, on each of them you concatenate two existing strings into a new one. On the i-th operation the concatenation s_{a}_{i}s_{b}_{i} is saved i...
```python from sys import stdin, stdout K = 20 def findAllStrings(s): n = len(s) sDict = {} for i in range(1,K+1): sDict[i]=set() for x in range(n-i+1): sDict[i].add(s[x:x+i]) return sDict n = int(stdin.readline().rstrip()) stringDicts = [] stringEnd = [] stringBegin = [] ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Ada's classroom contains $N \cdot M$ tables distributed in a grid with $N$ rows and $M$ columns. Each table is occupied by exactly one student. Before starting the class, the teacher decided to shuffle the students a bit. After the shuffling, ea...
```python # cook your dish here t=int(input()) for _ in range(t): N, M=map(int,input().split()) if(N%2==0 or M%2==0): print("YES") else: print("NO") ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Chef and his girlfriend are going to have a promenade. They are walking along the straight road which consists of segments placed one by one. Before walking Chef and his girlfriend stay at the beginning of the first segment, they want to achieve...
```python T = int(input()) for i in range(T): x = int(input()) l= [int(x) for x in input().split()] t=[] for i in range(len(l)): t.append(l[i]+i) print(max(t)) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: There are N barbecue restaurants along a street. The restaurants are numbered 1 through N from west to east, and the distance between restaurant i and restaurant i+1 is A_i. Joisino has M tickets, numbered 1 through M. Every barbecue restaurant ...
```python def main(): import sys from array import array input = sys.stdin.readline class Bit: def __init__(self, n): self.size = n self.size_bit_length = n.bit_length() self.tree = array('h', [0] * (n+1)) def reset(self): self.tree = arr...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: In order to establish dominance amongst his friends, Chef has decided that he will only walk in large steps of length exactly $K$ feet. However, this has presented many problems in Chef’s life because there are certain distances that he cannot t...
```python t=int(input()) for i in range(0,t): n,k=map(int,input().split()) a1,*a=map(int,input().split()) a.insert(0,a1) j=0 while j<n: if a[j]%k==0: print(1,end="") else: print(0,end="") j+=1 print("") ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Gru wants to distribute $N$ bananas to $K$ minions on his birthday. Gru does not like to just give everyone the same number of bananas, so instead, he wants to distribute bananas in such a way that each minion gets a $distinct$ amount of bananas...
```python from math import sqrt for _ in range(int(input())): n, k = map(int, input().split()) fact,i = [],1 while i<=sqrt(n): if n%i==0: if (n // i != i): fact.append(n//i) fact.append(i) i+=1 tot = (k*(k+1))//2 mx = -1 for i in fact: if i>=tot: mx = max(mx,n//i) print(...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: There is a big staircase with $N$ steps (numbered $1$ through $N$) in ChefLand. Let's denote the height of the top of step $i$ by $h_i$. Chef Ada is currently under the staircase at height $0$ and she wants to reach the top of the staircase (the...
```python # cook your dish here import numpy as np def minstairs(n,k): stairsHeight=[] stairs=0 current = 0 stairsHeight=list(map(int, input().split())) stairsHeight=np.array(stairsHeight) curr=0 for i in range(n): if stairsHeight[i]-curr<=k: curr=stairsHeight[i] else: if (stairsHeight[i]-curr)%k==...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Chef Two and Chef Ten are playing a game with a number $X$. In one turn, they can multiply $X$ by $2$. The goal of the game is to make $X$ divisible by $10$. Help the Chefs find the smallest number of turns necessary to win the game (it may be p...
```python # cook your dish here t=int(input()) for i in range(t): x=int(input()) if x%10==0: print(0) elif x%5==0: print(1) else: print(-1) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: There is a universal library, where there is a big waiting room with seating capacity for maximum $m$ people, each of whom completes reading $n$ books sequentially. Reading each book requires one unit of time. Unfortunately, reading service is ...
```python while(True): n, m, x = map(int, input().split()) if(n==0 and m==0 and x==0): break money=0 for i in range(n): money=money + (x+m*i)//n print(money) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: The Duck song For simplicity, we'll assume that there are only three types of grapes: green grapes, purple grapes and black grapes. Andrew, Dmitry and Michal are all grapes' lovers, however their preferences of grapes are different. To make al...
```python x,y,z = list(map(int,input().split())) a,b,c = list(map(int,input().split())) if a < x: print("NO") return x -= a y += x if b < y: print("NO") return y -= b z += y if c < z: print("NO") return print("YES") ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Chef has $N$ doggo (dogs) , Lets number them $1$ to $N$. Chef decided to build houses for each, but he soon realizes that keeping so many dogs at one place may be messy. So he decided to divide them into several groups called doggo communities...
```python # cook your dish here import sys def get_array(): return list(map(int , sys.stdin.readline().strip().split())) def get_ints(): return list(map(int, sys.stdin.readline().strip().split())) def input(): return sys.stdin.readline().strip() import math from collections import defaultdict from itertools import comb...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: You stumbled upon a new kind of chess puzzles. The chessboard you are given is not necesserily $8 \times 8$, but it still is $N \times N$. Each square has some number written on it, all the numbers are from $1$ to $N^2$ and all the numbers are p...
```python n=int(input()) graph=[{},{},{}] for i in range(n): for j in range(n): graph[0][(i,j)]=[(k,j) for k in range(n)]+[(i,k) for k in range(n)] graph[0][(i,j)].remove((i,j)) graph[0][(i,j)].remove((i,j)) graph[1][(i,j)]=[] for k in range(n): for l in range(n):...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: The Chef has one long loaf of bread of length 1. He wants to cut it into as many little loaves as he can. But he wants to adhere to the following rule: At any moment, the length of the longest loaf which he possesses may not be larger than the l...
```python import sys from math import log k = float(sys.stdin.readline()) answer = int(log(2.0, 2.0/k)) print(2*answer) m = 2 ** (1.0/answer) # m = 2.0/k thesum = 0 for i in range(answer): thesum += m**i # print [m**i/thesum for i in xrange(answer)] loaves = [1] def maxIndex(list): max = -1 mi = -1 for i, x in e...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Chef wants to buy a new phone, but he is not willing to spend a lot of money. Instead, he checks the price of his chosen model everyday and waits for the price to drop to an acceptable value. So far, he has observed the price for $N$ days (numbe...
```python for _ in range(int(input())): n=int(input()) a=list(map(int,input().split())) g=1 for j in range(1,n): if j-5<0: mi=min(a[0:j]) #print(a[0:j]) if mi>a[j]: g=g+1 else: mi=min(a[j-5:j]) #print(a[j-5:j]) if mi>a[j]: g=g+1 print(g) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Polycarp plays a computer game (yet again). In this game, he fights monsters using magic spells. There are two types of spells: fire spell of power $x$ deals $x$ damage to the monster, and lightning spell of power $y$ deals $y$ damage to the mo...
```python class BIT(): def __init__(self,n): self.BIT=[0]*(n+1) self.num=n def query(self,idx): res_sum = 0 while idx > 0: res_sum += self.BIT[idx] idx -= idx&(-idx) return res_sum #Ai += x O(logN) def update(self,idx,x): while id...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Chef and Abhishek both are fighting for the post of Chairperson to be part of ACE committee and are trying their best. To select only one student their teacher gave them a binary string (string consisting of only 0's and 1's) and asked them to f...
```python def countSubstr(str, n, x, y): tot_count = 0 count_x = 0 for i in range(n): if str[i] == x: count_x += 1 if str[i] == y: tot_count += count_x return tot_count t=int(input()) for _ in range(t): n=int(input()) str...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: A number is ternary if it contains only digits $0$, $1$ and $2$. For example, the following numbers are ternary: $1022$, $11$, $21$, $2002$. You are given a long ternary number $x$. The first (leftmost) digit of $x$ is guaranteed to be $2$, the...
```python for _ in range(int(input())): n=int(input()) s=input() a="" b="" flag=1 for i in s: if flag: if i=="2": a+="1" b+="1" elif i=="1": a+="1" b+="0" flag=0 else: ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: You are given a string $s$ of even length $n$. String $s$ is binary, in other words, consists only of 0's and 1's. String $s$ has exactly $\frac{n}{2}$ zeroes and $\frac{n}{2}$ ones ($n$ is even). In one operation you can reverse any substring...
```python t = int(input()) for i in range(t): n = int(input()) s = input() ans = 0 for y in range(1, n): if s[y] == s[y-1]: ans += 1 print((ans + ans % 2) // 2) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: A group of n cities is connected by a network of roads. There is an undirected road between every pair of cities, so there are $\frac{n \cdot(n - 1)}{2}$ roads in total. It takes exactly y seconds to traverse any single road. A spanning tree is...
```python from collections import defaultdict from collections import deque from functools import reduce n, x, y = [int(x) for x in input().split()] E = defaultdict(set) for i in range(n-1): u, v = [int(x) for x in input().split()] E[u].add(v) E[v].add(u) if x > y: for v in E: if len(E[v]) == n...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Do you know that The Chef has a special interest in palindromes? Yes he does! Almost all of the dishes in his restaurant is named by a palindrome strings. The problem is that a name of a dish should not be too long, so The Chef has only limited ...
```python # cook your dish here def permutation(n,p): r=26 if n==1: return 26 elif n==2: return 52 elif n==3: return 728 else: if n%2==0: return ((2*(bin_expo(r,((n//2)+1),p)-r)*bin_expo(25,1000000005,p)))%p else: n=n+1 retu...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Is it rated? Here it is. The Ultimate Question of Competitive Programming, Codeforces, and Everything. And you are here to answer it. Another Codeforces round has been conducted. No two participants have the same number of points. For each par...
```python '''input 5 3123 3123 2777 2777 2246 2246 2246 2246 1699 1699 ''' n = int(input()) x = [] f = 0 for _ in range(n): a, b = list(map(int, input().split())) if a != b: f = 1 x.append(a) if f == 1: print("rated") elif sorted(x)[::-1] == x: print("maybe") else: print("unrated") ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: You are given a system of pipes. It consists of two rows, each row consists of $n$ pipes. The top left pipe has the coordinates $(1, 1)$ and the bottom right — $(2, n)$. There are six types of pipes: two types of straight pipes and four types o...
```python ans = [] for _ in range(int(input())): n = int(input()) s = list(input()) t = list(input()) lvl = 0 X = [s, t] f = 1 for i in range(n): if s[i] in '3456' and t[i] in '3456': lvl = 1 - lvl elif X[lvl][i] in '3456': f = 0 ans.append...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Kira likes to play with strings very much. Moreover he likes the shape of 'W' very much. He takes a string and try to make a 'W' shape out of it such that each angular point is a '#' character and each sides has same characters. He calls them W ...
```python def frequency(s,n): f=[[0 for i in range(26)]for j in range(n+1)] count=0 for i in range(n): if s[i]!="#": f[count][ord(s[i])-97]+=1 else: count+=1 for j in range(26): f[count][j]=f[count-1][j] return (f,count) def solve(...