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: Your company was appointed to lay new asphalt on the highway of length $n$. You know that every day you can either repair one unit of the highway (lay new asphalt over one unit of the highway) or skip repairing. Skipping the repair is necessary...
```python for i in range(int(input())): n,g,b=map(int,input().split()) nn=(n+1)//2 print(max(nn+(nn-1)//g*b,n)) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: There are total N friends went to Chef's Pizza shop. There they bought a pizza. Chef divided the pizza into K equal slices. Now you have to check whether these K pizza slices can be distributed equally among the friends. Also given that every pe...
```python for _ in range(int(input())): n = int(input()) k = int(input()) if k%n==0: print("YES") else: print("NO") ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Polycarp is making a quest for his friends. He has already made n tasks, for each task the boy evaluated how interesting it is as an integer q_{i}, and the time t_{i} in minutes needed to complete the task. An interesting feature of his quest ...
```python from collections import defaultdict def __starting_point(): n, T = [int(_) for _ in input().split()] data = defaultdict(list) for i in range(n): t, q = [int(_) for _ in input().split()] data[T - t].append(q) prev_level = [] for level_id in range(1, T + 1): level ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Chef has $N$ points (numbered $1$ through $N$) in a 2D Cartesian coordinate system. For each valid $i$, the $i$-th point is $(x_i, y_i)$. He also has a fixed integer $c$ and he may perform operations of the following type: choose a point $(x_i, ...
```python t = int(input()) for i in range(t): n, c = list(map(int,input().split())) pts = {} moves = 0 for i in range(n): x, y = list(map(int,input().split())) if (y-x,x%c) in pts: pts[(y-x,x%c)].append(x) else: pts[(y-x,x%c)] = [x] for i in pts: arc = sorted(pts[i]) for j in arc: moves ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Vasya likes the number $239$. Therefore, he considers a number pretty if its last digit is $2$, $3$ or $9$. Vasya wants to watch the numbers between $L$ and $R$ (both inclusive), so he asked you to determine how many pretty numbers are in this ...
```python # cook your dish here t=int(input()) for _ in range(t): n,m = map(int,input().split()) count=0 for i in range(n,m+1): p=str(i) if p[-1]=='2' or p[-1]=='3' or p[-1]=='9': count+=1 print(count) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Snakeland is a well organised city. The houses of the city are organised in an orderly rectangular fashion with dimensions 2 * n, i.e. there are total two rows and n columns. The house in the i-th row and j-th column is also said to be the house...
```python # cook your dish here t=int(input()) while t: n=int(input()) r1=input() r2=input() r1count=0 r2count=0 count=0 for i in range(n): if(r1[i]=="*"): r1count+=1 if(r2[i]=="*"): r2count+=1 if(r1count>0) and (r2count>0): count=1 r1count=0 r2count=0 i=0 while(i<n): if(r1[i]=="*"): ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Sereja has a bracket sequence s_1, s_2, ..., s_{n}, or, in other words, a string s of length n, consisting of characters "(" and ")". Sereja needs to answer m queries, each of them is described by two integers l_{i}, r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ ...
```python import sys input = sys.stdin.readline s = input() M = int(input()) def next_pow_2(n): p = 1 while p < n: p <<= 1 return p def represented_range(node, size): l = node r = node while l < size: l = 2*l r = 2*r + 1 return l-size, r-size class SegTree: ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Anton has the integer x. He is interested what positive integer, which doesn't exceed x, has the maximum sum of digits. Your task is to help Anton and to find the integer that interests him. If there are several such integers, determine the big...
```python num = list(map(int, input())) best = num[:] for i in range(-1, -len(num) - 1, -1): if num[i] == 0: continue num[i] -= 1 for j in range(i + 1, 0): num[j] = 9 if sum(num) > sum(best): best = num[:] s = ''.join(map(str, best)).lstrip('0') print(s) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Chef has a sequence of N$N$ integers A1,A2,...,AN$A_1, A_2, ..., A_N$. Chef thinks that a triplet of integers (i,j,k)$(i,j,k)$ is good if 1≤i<j<k≤N$1 \leq i < j < k \leq N$ and P$P$ in the following expression contains an odd number of ones in ...
```python from math import * t = int(input()) for _ in range(t): n = int(input()) a = [int(d) for d in input().split()] odd,even = 0,0 for i in range(n): if bin(a[i]).count("1")%2 == 1: odd += 1 else: even +=1 total = 0 if odd >= 3 and even >= 2: total += (odd*(odd-1)*...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: The only difference between easy and hard versions is constraints. Now elections are held in Berland and you want to win them. More precisely, you want everyone to vote for you. There are $n$ voters, and two ways to convince each of them to vo...
```python import heapq for _ in range(int(input())): n = int(input()) voters = [] for i in range(n): m,p = list(map(int, input().split())) voters.append((m, -p)) voters.sort() for i in range(n): voters[i] = (voters[i][0], -voters[i][1]) ans = 0 costs = [] heapq....
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Chef Tobby is trying to run a code given to him by Bhuvan for an experiment they want to include in the manuscript to be submitted to a conference. The deadline to submit the manuscript is within a couple of hours and Chef Tobby needs to finish ...
```python from bisect import * for x in range(eval(input())): n,k = list(map(int,input().split())) arr = list(map(int,input().split())) arr.sort() t = 1 result = 0 y = 0 while y < n: if arr[y]<t: y += 1 elif arr[y]==t: t = t*2 y += 1 else: result += 1 t = t*2 while t < 2**(k): result +=...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: One upon a time there were three best friends Abhinav, Harsh, and Akash decided to form a team and take part in ICPC from KIIT. Participants are usually offered several problems during the programming contest. Long before the start, the friend...
```python # cook your dish here n = int(input()) count = 0 for _ in range(n): L = list(map(int, input().split())) if (L.count(1)>=2): count+=1 print(count) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Note : This question carries $150$ $points$ There is an outcry in Middle Earth, as the greatest war between Orgs of Dark Lord Sauron and Frodo Baggins is about to begin. To end the war, Frodo decides to destroy the ring in the volcano of Mordor....
```python # cook your dish here from math import pow t = int(input()) for _ in range(t): m,n = map(int,input().rstrip().split()) cnt = len(str(n)) x = pow(10,cnt) if n == x-1: print(m*cnt,m) else: print(m*(cnt-1),m) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Given an integer N. Integers A and B are chosen randomly in the range [1..N]. Calculate the probability that the Greatest Common Divisor(GCD) of A and B equals to B. -----Input----- The first line of the input contains an integer T denoting the...
```python import math for _ in range(int(input())): n=int(input()) s=int(math.sqrt(n)) ans=0 for i in range(1,s+1): ans+=(n//i) ans=ans*2-(s*s) g=math.gcd(n*n,ans) print(str(ans//g)+"/"+str(n*n//g)) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: This question is similar to the $"Operation$ $on$ $a$ $Tuple"$ problem in this month's Long Challenge but with a slight variation. Consider the following operations on a triple of integers. In one operation, you should: - Choose a positive int...
```python # cook your dish here """ Input: The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows. The first line of each test case contains three space-separated integers p, q and r. The second line contains three space-separated integers a, b...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Chef has a circular plot of land of radius $R$ on which he wants to construct a swimming pool. He wants the swimming pool to be square in shape with maximum possible area,so that he along with his friends can enjoy themselves during their summer...
```python T=int(input()) l=[] for t in range(T): R=int(input()) a=2*(R**2) l.append(a) for s in l: print(s) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: You are given a sequence a = \{a_1, ..., a_N\} with all zeros, and a sequence b = \{b_1, ..., b_N\} consisting of 0 and 1. The length of both is N. You can perform Q kinds of operations. The i-th operation is as follows: - Replace each of a_{l_...
```python import sys input=sys.stdin.readline n=int(input()) b=list(map(int,input().split())) ope=[[] for i in range(n)] Q=int(input()) for i in range(Q): l,r=list(map(int,input().split())) ope[r-1].append(l-1) res=b.count(0) Data=[(-1)**((b[i]==1)+1) for i in range(n)] for i in range(1,n): Data[i]+=Dat...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Chef is playing a game with his childhood friend. He gave his friend a list of N numbers named $a_1, a_2 .... a_N$ (Note: All numbers are unique). Adjust the numbers in the following order: $(i)$ swap every alternate number with it's succeeding...
```python for _ in range(int(input())): n=int(input()) a=list(map(int,input().split())) x=int(input()) for _ in range(1,n,2): a[_],a[_-1]=a[_-1],a[_] for _ in range(n): a[_]+=(a[_]%3) # a=a[::-1] # a.sort() # if x>a[-1]: # print(-1) # continue l,h=-1,9...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Chef has come to a 2 dimensional garden in which there are N points. Each point has coordinates (x, y), where x can either be 1 or 2 or 3. Chef will now choose every triplet of these N points and make a triangle from it. You need to tell the sum...
```python # cook your dish here # Author: Dancing Monkey | Created: 09.DEC.2018 import bisect for _ in range(int(input())): n = int(input()) x1 , x2, x3 = [], [], [] for i in range(n): x, y = list(map(int, input().split())) if x == 1: x1.append(y) if x == 2: x2.append(y) if x == 3: x3.append(y) x1.sort(...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: RedDreamer has an array $a$ consisting of $n$ non-negative integers, and an unlucky integer $T$. Let's denote the misfortune of array $b$ having length $m$ as $f(b)$ — the number of pairs of integers $(i, j)$ such that $1 \le i < j \le m$ and $...
```python T = int(input()) for test in range(T): n,t = list(map(int,input().split())) a = list(map(int,input().split())) res = [] j=0 for i in a: if(i*2<t): res+=["0"] elif(i*2>t): res+=["1"] else: res.append(["0","1"][j]) j = 1...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Vasya is an active Internet user. One day he came across an Internet resource he liked, so he wrote its address in the notebook. We know that the address of the written resource has format: <protocol>://<domain>.ru[/<context>] where: <protoco...
```python s="" L=[] s=input() k=0 r=0 c=0 if s[0]=='h': L.append('http://') c=4 s=s[c:] elif s[0]=='f': L.append('ftp://') c=3 s=s[c:] r=s.find('ru',1) L.append(s[:r]) L.append('.ru') k=r+2 if k<len(s): L.append('/') L.append(s[k:]) print(''.join(L)) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Vishal Wants to buy 2 gifts for his best friend whose name is Annabelle(her age is 20), So they both went for shopping in a store. But Annabelle gave, Vishal a condition that she will accept this gifts only when the total price of the gifts is t...
```python test = int(input()) ANS = list() for i in range(test): n = int(input()) items = sorted(list(map(int, input().split()))) c = 1 for j in range(len(items)): if items[j] < 2000: t = 2000 - items[j] if t in items[j+1:]: ANS.append("Accepted") c = 2 break else: pass else: break ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Given positive integers N, K and M, solve the following problem for every integer x between 1 and N (inclusive): - Find the number, modulo M, of non-empty multisets containing between 0 and K (inclusive) instances of each of the integers 1, 2, ...
```python N,K,M=map(int,input().split());R=range;T=[[1]] for i in R(1,N): q=K*i if i>~i+N:T+=[y:=T[-1][:len(T[~i+N])]] else:T+=[y:=T[-1][:]+[0]*q] p=len(y)-i for j in R(p):y[j+i]+=y[j]%M for j in R(p-q):y[~j]-=y[~j-i-q]%M for i in R(N):print(sum(T[i][j]*T[~i+N][j]for j in R(len(T[i])))*-~K%M-1) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Chef played an interesting game yesterday. This game is played with two variables $X$ and $Y$; initially, $X = Y = 0$. Chef may make an arbitrary number of moves (including zero). In each move, he must perform the following process: - Choose any...
```python from math import sqrt T = int(input()) ans = [] for _ in range(T): X = int(input()) count = 0 x = 0 y = 0 while(x<=X): p = int(sqrt(y)) count += 1 if(p*p>y): x = p y += p**2 else: x = p+1 y += (p+1)**2 if(x<=X): ans.append(count) else: ans.append(count-1) for i in ans: prin...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: -----Problem----- Suppose there is a circle. There are N Juice shops on that circle. Juice shops are numbered 0 to N-1 (both inclusive). You have two pieces of information corresponding to each of the juice shop: (1) the amount of Juice that a ...
```python import re,sys def isCirlePossible(juices,distances): if juices == [] or distances == []: return -1; total_juice_consumed = 0 juice_consumed = 0 start=0 for i in range(0,len(juices)): diff = juices[i] - distances[i] if juice_consumed >= 0: juice_consumed += diff else: juice_consumed = diff ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Shaun was given $N$ pairs of parenthesis ( ) by his teacher who gave him a difficult task.The task consists of two steps. First,Shaun should colour all $N$ pairs of parenthesis each with different color but opening and closing bracket of a part...
```python mod = 1000000007 fac = [1,1] maxn = (10**5)+5 for i in range(2,maxn): x = (fac[-1]*i)%mod fac.append(x) pre = [1] for i in range(2,maxn): x = 2*i-1 x = (pre[-1]*x)%mod pre.append(x) for _ in range(int(input())): n = int(input()) x = fac[n] y = pre[n-1] pr...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Polycarp analyzes the prices of the new berPhone. At his disposal are the prices for $n$ last days: $a_1, a_2, \dots, a_n$, where $a_i$ is the price of berPhone on the day $i$. Polycarp considers the price on the day $i$ to be bad if later (tha...
```python for _ in range(int(input())): n = int(input()) A = list(map(int, input().split())) m = 10 ** 9 c = 0 for i in range(n - 1, -1, -1): if A[i] <= m: m = A[i] else: c += 1 print(c) ```
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. A group of disjoint subarrays in it will be a collection of subarrays of the array. Formally a group of subarrays consisting of K subarrays can be denoted by 2 * K indices, [i1, j1], [i2, j2] , ...
```python t=int(input()) for k in range(t): n=int(input()) l=[int(i) for i in input().split()] m={} count=1 for i in range(1,n): if l[i]==l[i-1]: count+=1 else: if l[i-1] not in m: m[l[i-1]]=(count*(count+1))/2 else: ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: В Берляндском государственном университете локальная сеть между серверами не всегда работает без ошибок. При передаче двух одинаковых сообщений подряд возможна ошибка, в результате которой эти два сообщения сливаются в одно. При таком слиянии ко...
```python s = input() t = 0 if len(s)%2==0: n = (len(s)-1)//2+1 else: n = (len(s)-1)//2 for i in range(n, len(s)-1): a = i b = len(s)-i-1 if s[:a+1]==s[b:]: print('YES') print(s[:a+1]) t = 1 break if t==0: print('NO') ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Ram and Shyam are playing a game of Truth and Dare. In this game, Shyam will ask Ram to perform tasks of two types: - Truth task: Ram has to truthfully answer a question. - Dare task: Ram has to perform a given task. Each task is described by an...
```python # cook your dish here for _ in range(int(input())): tr=int(input()) trl=list(map(int,input().split())) dr = int(input()) drl = list(map(int, input().split())) ts = int(input()) tsl = list(map(int, input().split())) ds = int(input()) dsl = list(map(int, input().split())) for...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: You are given an empty grid with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). You should fill this grid with integers in a way that satisfies the following rules: - For any three cells $c_1$, $c_2$ and $c_3$ su...
```python # cook your dish here t = int(input()) for _ in range(t): m,n = [int(d) for d in input().split()] if m == 1: arr = [] if n%4 == 0: print(2) arr = [[1,1,2,2]*(n//4)] elif n%4 == 1: if n == 1: print(1) arr = [[1]] else: print(2) arr = [[1,1,2,2]*(n//4) + [1]] elif n%4 == 2...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: In this problem we assume the Earth to be a completely round ball and its surface a perfect sphere. The length of the equator and any meridian is considered to be exactly 40 000 kilometers. Thus, travelling from North Pole to South Pole or vice ...
```python """ Codeforces Good Bye 2016 Contest Problem B Author : chaotic_iak Language: Python 3.5.2 """ ################################################### SOLUTION def main(): latitude = 0 n, = read() for i in range(n): l, d = read(str) l = int(l) if latitude == 0: ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: One day Kefa found n baloons. For convenience, we denote color of i-th baloon as s_{i} — lowercase letter of the Latin alphabet. Also Kefa has k friends. Friend will be upset, If he get two baloons of the same color. Kefa want to give out all ba...
```python alpha = [chr(ord('a')+i) for i in range(26)] n,k = list(map(int,input().split())) s = input() arr = [s.count(alpha[i]) for i in range(26)] print('YES' if max(arr) <= k else 'NO') ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: We say that a binary string (a string containing only characters '0' and '1') is pure if it does not contain either of the strings "0101" or "1010" as a subsequence. Recall that string T is a subsequence of string S if we can delete some of the ...
```python # cook your dish here import math; from math import gcd,sqrt,floor,factorial,ceil from bisect import bisect_left,bisect_right import bisect; import sys; from sys import stdin,stdout import os sys.setrecursionlimit(pow(10,7)) import collections from collections import defaultdict,Counter from statistics import...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: You are given a binary string $s$ (recall that a string is binary if each character is either $0$ or $1$). Let $f(t)$ be the decimal representation of integer $t$ written in binary form (possibly with leading zeroes). For example $f(011) = 3, f...
```python LOG = 20 def solve(s): n = len(s) res = 0 z = 0 for t in range(0, n): if s[t] == '0': z += 1 continue for l in range(1, min(LOG, n - t + 1)): x = int(s[t:t+l], 2) # print(l, t, x, l + z) if l + z >= x: res += 1 # print(t, l, x, res, z) z = 0 return res t = int(input()) whil...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Consider a sequence [a_1, a_2, ... , a_{n}]. Define its prefix product sequence $[ a_{1} \operatorname{mod} n,(a_{1} a_{2}) \operatorname{mod} n, \cdots,(a_{1} a_{2} \cdots a_{n}) \operatorname{mod} n ]$. Now given n, find a permutation of [1, ...
```python def comp(x): for i in range(2, x): if x % i == 0: return True return False N = int(input()) if N == 4: print('YES', '1', '3', '2', '4', sep = '\n') elif comp(N): print('NO') else: print('YES', '1', sep = '\n') if N > 1: for i in range(2, N): pr...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Kuro has recently won the "Most intelligent cat ever" contest. The three friends then decided to go to Katie's home to celebrate Kuro's winning. After a big meal, they took a small break then started playing games. Kuro challenged Katie to crea...
```python n,p=list(map(int,input().split())) nums=[0]+list(map(int,input().split())) mod=10**9+7 f=[[[[0]*2 for _ in range(2)] for _ in range(2)] for _ in range(n+1)] _2=[0]*(n+1) _2[0]=1 for i in range(1,n+1): _2[i]=(_2[i-1]<<1)%mod f[0][0][0][0]=1 if nums[1]!=0: f[1][1][0][1]+=1 if nums[1]!=1: f[1]...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Sometimes Sergey visits fast food restaurants. Today he is going to visit the one called PizzaKing. Sergey wants to buy N meals, which he had enumerated by integers from 1 to N. He knows that the meal i costs Ci rubles. He also knows that there ...
```python T = int(input()) for t in range(T): n, m = list(map(int, input().split())) c = list(map(int, input().split())) dp1 = [1e9]*((1 << n)+1) for i in range(n): dp1[1 << i] = c[i] dp1[1 << (n-1)] = min(dp1[1 << (n-1)], sum(c)) for i in range(m): l = list(map(int, input().split())) cost = l[0] s =...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Today Tavas got his test result as an integer score and he wants to share it with his girlfriend, Nafas. His phone operating system is Tavdroid, and its keyboard doesn't have any digits! He wants to share his score with Nafas via text, so he ha...
```python n = int(input()) if n == 0: print('zero') elif n == 1: print('one') elif n == 2: print('two') elif n == 3: print('three') elif n == 4: print('four') elif n == 5: print('five') elif n == 6: print('six') elif n == 7: print('seven') elif n == 8: print('eight') elif n == 9: print('nine') elif n == 10: ...
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 a_1, a_2, ..., a_{n}. Determine a real number x such that the weakness of the sequence a_1 - x, a_2 - x, ..., a_{n} - x is as small as possible. The weakness of a sequence is defined as the maximum value...
```python import sys n = int(sys.stdin.readline()) a = [int(x) for x in sys.stdin.readline().split()] eps = 1e-12 def f(x): mx = a[0] - x tsmx = 0.0 mn = a[0] - x tsmn = 0.0 for ai in a: tsmx = max(tsmx + ai - x, ai - x) mx = max(tsmx, mx) tsmn = min(tsmn + ai - x, ai - x) ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: You want to build a temple for snakes. The temple will be built on a mountain range, which can be thought of as n blocks, where height of i-th block is given by hi. The temple will be made on a consecutive section of the blocks and its height sh...
```python # cook your dish here t = int(input()) while t: t -= 1 n = int(input()) arr = list(map(int, input().split())) sumi = sum(arr) prev = 1 for i in range(n): arr[i] = min(arr[i], prev) prev = arr[i] + 1 prev = 1 for i in range(n - 1, -1, -1): arr[i] = min(arr[i], prev) prev = arr[i] + 1 temp = 0...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Taru likes reading. Every month he gets a copy of the magazine "BIT". The magazine contains information about the latest advancements in technology. Taru reads the book at night and writes the page number to which he has read on a piece of pa...
```python import sys rl=sys.stdin.readline T=int(rl()) for t in range(T): P=int(rl()) T=(P+1)//2 F=list(map(int,rl().split()))[1:] numtorn=int(rl()) t=sum(range(1,P+1))-sum(F) K=T-numtorn print('%.4f' % (t*K/float(T))) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Chef wants to organize a contest. Predicting difficulty levels of the problems can be a daunting task. Chef wants his contests to be balanced in terms of difficulty levels of the problems. Assume a contest had total P participants. A problem tha...
```python t = int(input()) for z in range(t) : n,p = [int(x) for x in input().split()] a = [int(x) for x in input().split()] c = [x for x in a if x >= p//2] h = [x for x in a if x <= p//10] if len(c)==1 and len(h)==2 : print("yes") else: print("no") ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Vasya learned about integer subtraction in school. He is still not very good at it, so he is only able to subtract any single digit number from any other number (which is not necessarily single digit). For practice, Vasya chose a positive intege...
```python # cook your dish here def getAns(num): if num<10:return 2 last=int(str(num)[0]);rem=int(str(num)[1:]);steps=2;p=len(str(num))-1 while True: steps+=rem//last+1;rem=rem%last if last>0:rem=rem+10**p-last last=last-1 if last==0: p=p-1;last=9 if(len(str(rem))==1):rem=0...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: AND gates and OR gates are basic components used in building digital circuits. Both gates have two input lines and one output line. The output of an AND gate is 1 if both inputs are 1, otherwise the output is 0. The output of an OR gate is 1 if ...
```python # cook your dish here class node: def __init__(self,a,b=0,c=0): self.val=a self.a=b self.b=c arr=[] def finder(node,val): if(arr[node].val==0): return val else: a=finder(arr[node].a,val) b=finder(arr[node].b,val) if(arr[node].val==1): return a+b-a*b else: return a*b t=int(input()) ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: You are given an integer sequence $A_1, A_2, \ldots, A_N$ and an integer $X$. Consider a $N \times N$ matrix $B$, where $B_{i,j} = A_i + A_j$ for each valid $i$ and $j$. You need to find the number of square submatrices of $B$ such that the sum ...
```python # cook your dish here import sys input=sys.stdin.readline for _ in range(int(input())): n,x=list(map(int,input().split())) l=[0] pre=[0]*(n+1) sum=0 i=1 for m in input().split(): l.append(int(m)) sum+=int(m) pre[i]=sum i+=1 dict={} k=[] i=1 while (i*i)<=x: if x%i==0: k.append(i) if (...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: You are given a sequence a1, a2, ..., aN. Find the smallest possible value of ai + aj, where 1 ≤ i < j ≤ N. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases fol...
```python # cook your dish here def __starting_point(): try: for _ in range (int(input())): element = int(input()) l = list(map(int,input().split())) a=min(l) l.remove(a) b=min(l) print(a+b) except EOFError : print('EOFError') __starting_point() ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: You have $n$ barrels lined up in a row, numbered from left to right from one. Initially, the $i$-th barrel contains $a_i$ liters of water. You can pour water from one barrel to another. In one act of pouring, you can choose two different barrel...
```python def solve(): n, k = map(int,input().split()) lst = list(map(int,input().split())) lst.sort() ans = 0 for i in range(n - k - 1, n): ans += lst[i] print(ans) for i in range(int(input())): solve() ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Chef is the new king of the country Chefland. As first and most important responsibility he wants to reconstruct the road system of Chefland. There are N (1 to N) cities in the country and each city i has a population Pi. Chef wants to build som...
```python t=int(input()) for _ in range(t): n=int(input()) a=list(map(int,input().split())) a.sort() s=sum(a) if a[0]*(s-a[0])<=a[n-1]*(s-a[n-1]): print(a[0]*(s-a[0])) else: print(a[n-1]*(s-a[n-1])) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: -----Problem----- Once THANMAY met PK who is from a different planet visiting earth. THANMAY was very fascinate to learn PK's language. The language contains only lowercase English letters and is based on a simple logic that only certain cha...
```python d = {} for i in range(26): char = chr(i+ord('a')) d[char] = [] for i in range(26): char = chr(i+ord('a')) temp = list(map(int,input().strip().split())) for j in range(26): if (temp[j] == 1): follow= chr(j+ord('a')) d[follow].append(char) def f(char,i,n,count): if (i==n): return count+1 el...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Santa has to send presents to the kids. He has a large stack of $n$ presents, numbered from $1$ to $n$; the topmost present has number $a_1$, the next present is $a_2$, and so on; the bottom present has number $a_n$. All numbers are distinct. S...
```python for tc in range(int(input())): n,m = list(map(int, input().split())) al = list(map(int, input().split())) bl = list(map(int, input().split())) aidx = {} for i,e in enumerate(al): aidx[e]=i midx = -1 res = 0 for i,e in enumerate(bl): idx = aidx[e] if idx ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: This is probably the simplest problem ever. You just need to count the number of ordered triples of different numbers (X1, X2, X3), where Xi could be any positive integer from 1 to Ni, inclusive (i = 1, 2, 3). No, wait. I forgot to mention that ...
```python d=1000000007 for _ in range(int(input())): l=sorted(list(map(int,input().split()))) ans=(l[0]%d)*((l[1]-1)%d)*((l[2]-2)%d) print(ans%d) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Luba is surfing the Internet. She currently has n opened tabs in her browser, indexed from 1 to n from left to right. The mouse cursor is currently located at the pos-th tab. Luba needs to use the tabs with indices from l to r (inclusive) for he...
```python n, pos, l, r = map(int, input().split()) if l > 1 and r < n: if l <= pos and pos <= r: if pos - l < r - pos: print(pos - l + 1 + r - l + 1) else: print(r - pos + 1 + r - l + 1) elif pos > r: print(pos - r + 1 + r - l + 1) else: print(l - pos...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Chef likes strings a lot but he likes palindromic strings even more. Today he found an old string s in his garage. The string is so old that some of its characters have faded and are unidentifiable now. Faded characters in the string are represe...
```python test=int(input()) for i in range(test): s=input() b=len(s) list1=[] for j in range(len(s)): if s[j]=='.': list1.append(j) for i in list1: if b-i-1 in list1 : if i!=b-i-1 and ((s[i] and s[b-i-1]) != 'a' ): s=s[:i]+'a'+s[i+1:b-i-1]+'a'+...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Since due to COVID 19, India has undergone a complete 21 day lockdown. So Amol was attending an online lecture where his professor asked him to solve a question. Amol was unable to solve the question so he asked you to solve the question and giv...
```python try: def countsubsetsum(S,arr,n): k=[[0 for i in range(S+1)] for i in range(n+1)] for i in range(n+1): for j in range(S+1): if(j==0): k[i][j]=1 elif(i==0): k[i][j]=0 elif(arr[i-1]<=j): ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Master Oogway has forseen that a panda named Po will be the dragon warrior, and the master of Chi. But he did not tell anyone about the spell that would make him the master of Chi, and has left Po confused. Now Po has to defeat Kai, who is the s...
```python arr = [] arr.append(1) _ = 1 while _<=100002: arr.append(_*arr[_-1]%1589540031) _+=1 for _ in range(int(input())): print(arr[int(input())]) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: You are given a tree with $N$ vertices (numbered $1$ through $N$) and a sequence of integers $A_1, A_2, \ldots, A_N$. You may choose an arbitrary permutation $p_1, p_2, \ldots, p_N$ of the integers $1$ through $N$. Then, for each vertex $i$, you...
```python T = int(input()) M = 10 ** 9 + 7 for _ in range(T): N = int(input()) A = list(map(int, input().split())) if N == 1: print(0) continue B = {} C = {} for i in range(N - 1): u, v = input().split() u = int(u) - 1 v = int(v) - 1 if u not in B: B[u] = [] if v not in B: B[v] = [] ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: A city of dimension N x N is constructed with grid of lanes. These lanes are fenced by government so that no one can cross any grid diagonally. Although a train line runs diagonally from (0,0) to (N,N). Our chef has a weird kind of phobia and i...
```python ar = [] ar.append(1) for i in range(1, 31): ar.append(ar[i-1]*(4*i-2)/(i+1)) t = int(input()) while(t>0): n = int(input()) if(n==0): print(0) else: print(ar[n]*2) t=t-1 ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: The Fibonacci sequence is defined as F(n) = F(n-1) + F(n-2). You have developed two sequences of numbers. The first sequence that uses the bitwise XOR operation instead of the addition method is called the Xoronacci number. It is described as fo...
```python # Python3 program to find XNOR # of two numbers import math def swap(a, b): temp = a a = b b = temp # log(n) solution def xnor(a, b): # Make sure a is larger if (a < b): swap(a, b) if (a == 0 and b == 0): return 1; # for last bit of a a_rem = 0 # for last bit of b b_rem = 0 # counter fo...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Zookeeper is playing a game. In this game, Zookeeper must use bombs to bomb a string that consists of letters 'A' and 'B'. He can use bombs to bomb a substring which is either "AB" or "BB". When he bombs such a substring, the substring gets dele...
```python import sys readline = sys.stdin.readline T = int(readline()) Ans = [None]*T for qu in range(T): S = [1 if s == 'A' else 0 for s in readline().strip()] stack = [] for s in S: if s: stack.append(s) else: if stack and stack[-1] == 1: stack.pop(...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Chef is multi-talented. He has developed a cure for coronavirus called COVAC-19. Now that everyone in the world is infected, it is time to distribute it throughout the world efficiently to wipe out coronavirus from the Earth. Chef just cooks the...
```python import math for i in range(int(input())): n,x=list(map(int,input().split())) l=list(map(int,input().split())) l.sort() flag=0 d=0 for j in range(n): if l[j]>x: for k in range(j,n): if x<l[k]: d+=(math.ceil(math.log(l[k]/x)/math.log(2))+1) else: d+=1 ...
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(odd) to form a new pattern. Help the chef to code this pattern problem. -----Input:----- - First-line will contain $T$, the number of test...
```python def func(num): for i in range(num): if i < num//2 + 1: print(' '*i, end='') print('*') else: print(' '*(num-i-1), end='') print('*') for _ in range(int(input())): num = int(input()) func(num) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Nikita likes tasks on order statistics, for example, he can easily find the $k$-th number in increasing order on a segment of an array. But now Nikita wonders how many segments of an array there are such that a given number $x$ is the $k$-th num...
```python from math import pi from cmath import exp def fft(a, lgN, rot=1): # rot=-1 for ifft N = 1<<lgN assert len(a)==N rev = [0]*N for i in range(N): rev[i] = (rev[i>>1]>>1)+(i&1)*(N>>1) A = [a[rev[i]] for i in range(N)] h = 1 while h<N: w_m = exp((0+1j) * rot * (pi / h)) for k in range(0, ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Nexus 4.O is going to be organized by ASME, GLA University. Shubhanshu, Head of Finance Team is working for it. He has $N$ number of bills of different values as $a$$1$,$ a$$2$, $a$$3$…$a$$n$. He is interested in a game in which one has to do th...
```python t=int(input()) for i in range(t): l=list(map(int,input().split(' '))) a=l[0] b=l[1] l1=list(map(int,input().split(' '))) for i in range(b): l2=list(map(int,input().split(' '))) a1=l2[0] b1=l2[1] su=0 for j in range(a1-1,b1): su=(su+l1[j])%1000000000 print(su) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Meliodas and Ban are fighting over chocolates. Meliodas has $X$ chocolates, while Ban has $Y$. Whoever has lesser number of chocolates eats as many chocolates as he has from the other's collection. This eatfest war continues till either they hav...
```python from math import * t=int(input()) for i in range(t): m,b=input().split() m=int(m) b=int(b) print(2*gcd(m,b)) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Ada is playing pawn chess with Suzumo. Pawn chess is played on a long board with N$N$ squares in one row. Initially, some of the squares contain pawns. Note that the colours of the squares and pawns do not matter in this game, but otherwise, the...
```python for _ in range(int(input())): s = input().strip() a = [] last = 0 for i in range(len(s)): if s[i] == 'P': a.append(i - last) last = i + 1 x = 0 a = a[::-1] for v in a[::2]: x ^= v % 3 print('Yes' if x else 'No') ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Mohit's girlfriend is playing a game with Nicky. The description of the game is as follows: - Initially on a table Player 1 will put N gem-stones. - Players will play alternatively, turn by turn. - At each move a player can take at most M gem-st...
```python r=[0,1,1,2,1,4,2,6,1,8,4] n,m=[int(x) for x in input().split()] if m==1: while n%2!=1: n=n/2 if n==1: print(1) else: print(n-1) elif (n+1)/2<m: print(m) else: print(n-m) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: The entire network is under the inspection and direct control of the Decepticons. They have learned our language through the World Wide Web and can easily understand the messages which are being sent. Sam is trying to send the information to Aut...
```python x = input() y = input() z = x.find(y) if z == -1 : print('N') else : print('Y') ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: The snakes want to build a temple for Lord Cobra. There are multiple strips of land that they are looking at, but not all of them are suitable. They need the strip of land to resemble a coiled Cobra. You need to find out which strips do so. Form...
```python # cook your dish here for i in range(int(input())): N=int(input()) L=list(map(int,input().split())) l,h=0,N-1 flag=1 if L[l]!=1 and L[h]!=1: flag=0 else: while(l<h): if (L[l]!=L[h]) or (L[l+1]-L[l]!=1 and L[h-1]-L[h]!=1): flag=0 break l+=1 h-=1 if flag: print("yes") else: pr...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Given the values at the leaf nodes of a complete binary tree. The total number of nodes in the binary tree, is also given. Sum of the values at both the children of a node is equal to the value of the node itself. You can add any value or subtra...
```python print(0) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Zaikia has $N$ sticks of distinct positive lengths $A_1,A_2,\dots,A_N$. For no good reason at all, he wants to know if there is a triplet of sticks which when connected end-to-end will form a non-trivial triangle. Here non-trivial refers to a tr...
```python #from itertools import combinations as c n=int(input());l=list(map(int,input().split())) l1=[] if(n<3): print("NO") else: l.sort() for i in range(n-2): if(l[i]+l[i+1]>l[i+2]): l1.append([l[i+2],l[i+1],l[i]]) if(len(l1)!=0): print("YES") print(*max(l1)) else...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: We have a graph with N vertices and M edges, and there are two people on the graph: Takahashi and Aoki. The i-th edge connects Vertex U_i and Vertex V_i. The time it takes to traverse this edge is D_i minutes, regardless of direction and who tra...
```python # ARC090E def hoge(): M = 10**9 + 7 import sys input = lambda : sys.stdin.readline().rstrip() n, m = map(int, input().split()) s, t = map(int, input().split()) s -= 1 t -= 1 from collections import defaultdict ns = defaultdict(set) for i in range(m): u, v, d =...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: You are given an integer sequence $A_1, A_2, \ldots, A_N$. For any pair of integers $(l, r)$ such that $1 \le l \le r \le N$, let's define $\mathrm{OR}(l, r)$ as $A_l \lor A_{l+1} \lor \ldots \lor A_r$. Here, $\lor$ is the bitwise OR operator. I...
```python for _ in range(int(input())): n = int(input()) arr = list(map(int,input().split())) if n<=62: st = set() for i in range(n): curr = 0 for j in range(i,n): curr = curr|arr[j] st.add(curr) if len(st)==n*(n+1)//2: print("YES") else: print("NO") else: print("NO") ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: You are working for the Gryzzl company, headquartered in Pawnee, Indiana. The new national park has been opened near Pawnee recently and you are to implement a geolocation system, so people won't get lost. The concept you developed is innovativ...
```python import sys import math n = int(input()) x = [0]*n y = [0]*n for i in range(n): x[i], y[i] = list(map(int, input().split())) sx = sum(x) sy = sum(y) for i in range(n): x[i] = n * x[i] - sx y[i] = n * y[i] - sy m = int(input()) d = [0]*n e = [0]*n HD = 0 def check(a, b): nonlocal HD...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: You are given two binary strings $S$ and $P$, each with length $N$. A binary string contains only characters '0' and '1'. For each valid $i$, let's denote the $i$-th character of $S$ by $S_i$. You have to convert the string $S$ into $P$ using ze...
```python def solve(s, p): diffs = 0 for x, y in zip(s, p): if x == y: continue if x == '0': if diffs < 1: return "No" diffs -= 1 else: diffs += 1 return "Yes" if diffs == 0 else "No" for _ in range(int(input())): l = int(input()) s = input().strip() p = input().strip() print(solve(s, p))...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Vasya's got a birthday coming up and his mom decided to give him an array of positive integers a of length n. Vasya thinks that an array's beauty is the greatest common divisor of all its elements. His mom, of course, wants to give him as beaut...
```python n, k = map(int, input().split()) t = set(map(int, input().split())) y = x = min(t) t = list(t) while True: for i in t: if i % x > k: x = i // (i // x + 1) if y == x: break y = x print(y) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Mitya has a rooted tree with $n$ vertices indexed from $1$ to $n$, where the root has index $1$. Each vertex $v$ initially had an integer number $a_v \ge 0$ written on it. For every vertex $v$ Mitya has computed $s_v$: the sum of all values writ...
```python from collections import defaultdict, deque n = int(input()) adj = [[] for _ in range(n)] v = [0] * n l = list(map(int, input().split())) for i, f in enumerate(l): adj[f - 1].append(i + 1) s = list(map(int, input().split())) Q = deque([(0, s[0], s[0])]) ans = 0 flag = False possible = True while Q and p...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Amit is going on a date and he wants to gift his date an array of positive numbers. But he is running short on money. He already has an array of numbers in design. Cost of an array of numbers is the sum of elements in it. But he wants to minimiz...
```python for _ in range(int(input())): n=int(input()) l=list(map(int,input().split())) su=l[0] for i in range(1,n): su^=l[i] print(su) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Chef Ada is preparing $N$ dishes (numbered $1$ through $N$). For each valid $i$, it takes $C_i$ minutes to prepare the $i$-th dish. The dishes can be prepared in any order. Ada has a kitchen with two identical burners. For each valid $i$, to pre...
```python for i in range(int(input())): n=int(input()) c=[int(z) for z in input().split()] c.sort() c.reverse() b1,b2=0,0 for i in range(n): if b1<b2: b1+=c[i] elif b2<b1: b2+=c[i] else: b1+=c[i] print(max(b1,b2)) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: You are given a binary string $s$. Find the number of distinct cyclical binary strings of length $n$ which contain $s$ as a substring. The cyclical string $t$ contains $s$ as a substring if there is some cyclical shift of string $t$, such that...
```python n=int(input()) s=[c=='1' for c in input()] m=len(s) z=[[0,0]] for c in s: ind = z[-1][c] z[-1][c] = len(z) z.append(z[ind][:]) assert(len(z) == m+1) z[m][0] = z[m][1] = m # make it sticky # how many things match directly dp = [0 for _ in range(m+1)] dp[0] = 1 for i in range(n): ndp = [0 for _ in range(m+...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: The $String$ Family gave birth to a new $Tripartite$ $trio$ $sisters$ and named them $Hema$, $Rekha$ and $Sushma$. Hema and Rekha are very fond of parties whereas Sushma hates them. One day Hema and Rekha asked their parents to buy them candies ...
```python from math import gcd def compute_lcm(x, y): lcm = (x*y)//gcd(x,y) return lcm def LCMofArray(a): lcm = a[0] for i in range(1,len(a)): lcm = lcm*a[i]//gcd(lcm, a[i]) return lcm for _ in range(int(input())): lens = int(input()) arrs = [int(x) for x in input().sp...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: You are given two strings $s$ and $t$ both of length $n$ and both consisting of lowercase Latin letters. In one move, you can choose any length $len$ from $1$ to $n$ and perform the following operation: Choose any contiguous substring of the ...
```python q = int(input()) for _ in range(q) : n = int(input()) s = input() t = input() x = set(s) y = set(t) if x != y : print("NO") continue if len(x) == n : a = [0] * n for i, c in enumerate(t) : a[i] = s.find(c) yeet = 0 vis = [False] * n for i in range(n) : ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Cherry has a string S$S$ consisting of lowercase English letters. Using this string, he formed a pyramid of infinite length with certain rules: - N$N$-th row of pyramid contains N$N$ characters. - Each row of pyramid begins with the first charac...
```python def search(arr, lenl, val): s = 0 l = lenl - 1 total = 0 while (s <= l): m = int((s + l) / 2) if (arr[m] <= val): total = m + 1 s = m + 1 else: l = m - 1 return total def kmpsearch(string, lps): lis ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Our Chef is doing what he is best at, COOKING A BARBECUE for his guests. He has invited all of us, and taking the help of his apprentice to smoke the barbecues. The chef has got BBQ sticks, each can take N fillings, and he presents N distinctly ...
```python testcase = int(input()) for case in range(testcase): n = int(input()) print(2**(n-2)+1) print('\n') ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Gargi is thinking of a solution to a problem. Meanwhile, her friend asks her to solve another problem. Since Gargi is busy in her own problem, she seeks your help to solve the new problem. You are given a string S containing characters a-z (low...
```python t = int(input()) for i in range(t): s = input().rstrip() sumv = 0 for j in range(len(s)): sumv += ord(s[j]) minv = 10 ** 8; for i in range(ord('a'), ord('z') + 1): val = abs(sumv - i * len(s)) if minv > val: minv = val print(minv) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: We have a tree with N vertices, whose i-th edge connects Vertex u_i and Vertex v_i. Vertex i has an integer a_i written on it. For every integer k from 1 through N, solve the following problem: - We will make a sequence by lining up the integer...
```python import bisect import sys sys.setrecursionlimit(10**7) def dfs(v): pos=bisect.bisect_left(dp,arr[v]) changes.append((pos,dp[pos])) dp[pos]=arr[v] ans[v]=bisect.bisect_left(dp,10**18) for u in g[v]: if checked[u]==0: checked[u]=1 dfs(u) pos,val=changes.po...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: There are $n$ programmers that you want to split into several non-empty teams. The skill of the $i$-th programmer is $a_i$. You want to assemble the maximum number of teams from them. There is a restriction for each team: the number of programme...
```python __MULTITEST = True ## solve def solve(): n, x = map(int, input().split()) a = list(map(int, input().split())) a.sort() group = 0 ptr = n-1 members = 0 currentMin = int(1e10) while ptr > -1: currentMin = min(currentMin, a[ptr]) members += 1 if current...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: You are given a directed graph of $n$ vertices and $m$ edges. Vertices are numbered from $1$ to $n$. There is a token in vertex $1$. The following actions are allowed: Token movement. To move the token from vertex $u$ to vertex $v$ if there i...
```python import sys input = sys.stdin.readline import heapq mod=998244353 n,m=list(map(int,input().split())) E=[[] for i in range(n+1)] E2=[[] for i in range(n+1)] for i in range(m): x,y=list(map(int,input().split())) E[x].append(y) E2[y].append(x) TIME=[1<<29]*(n+1) TIME[1]=0 def shuku(x,y): ret...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Tonight, Chef would like to hold a party for his $N$ friends. All friends are invited and they arrive at the party one by one in an arbitrary order. However, they have certain conditions — for each valid $i$, when the $i$-th friend arrives at th...
```python test=int(input()) for _ in range(test): n=int(input()) ls=list(map(int,input().split())) ls.sort() s=0 for i in range(n): if s>=ls[i]: s=s+1 else: break print(s) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Petya is preparing for his birthday. He decided that there would be $n$ different dishes on the dinner table, numbered from $1$ to $n$. Since Petya doesn't like to cook, he wants to order these dishes in restaurants. Unfortunately, all dishes a...
```python def check(M): sm = 0 for i in range(n): if a[i] > M: sm += b[i] return sm <= M gans = [] for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) L = 0 R = max(a) while R - L > 1: M ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Devu is a disastrous oracle: his predictions about various events of your life are horrifying. Instead of providing good luck, he "blesses" you with bad luck. The secret behind his wickedness is a hidden omen which is a string of length m. On yo...
```python t = int(input()) for j in range(0, t): n = int(input()) m = 100 for i in range(0, n): str = input() p = min(str.count("a",0,len(str)),str.count("b",0,len(str))) if (m > p): m = p print(m) t = t-1 ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Ravi is very good student in mathematics and he also like Even numbers very much . On the other hand his friend Jhon like Odd numbers . Both of them are preparing for IIT JEE Advance .One day they are solving a question together the question w...
```python # cook your dish here while True: try: m=int(input()) n=int(m/2) a=m-n sum_even= int(2*(2*n*(n+1)*(2*n+1))/3) sum_odd= int(((4*a*a*a)-a)/3) result=sum_odd+sum_even if result%2==0: print('Ravi') else: print('Jhon') except: break; ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Gildong recently learned how to find the longest increasing subsequence (LIS) in $O(n\log{n})$ time for a sequence of length $n$. He wants to test himself if he can implement it correctly, but he couldn't find any online judges that would do it ...
```python import sys input = sys.stdin.readline def compress(array): array2 = sorted(set(array)) memo = {value : index for index, value in enumerate(array2)} for i in range(len(array)): array[i] = memo[array[i]] + 1 return array t = int(input()) base = 10 ** 6 for _ in range(t): n, b = l...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: We have a sequence A of N non-negative integers. Compute the sum of \prod _{i = 1} ^N \dbinom{B_i}{A_i} over all sequences B of N non-negative integers whose sum is at most M, and print it modulo (10^9 + 7). Here, \dbinom{B_i}{A_i}, the binomial...
```python from functools import reduce def modpow(a, n, m): if n == 0: return 1 tmp = modpow(a, n // 2, m) if n % 2 == 0: return tmp * tmp % m else: return tmp * tmp * a % m def modinv(a, m): return modpow(a, m - 2, m) n, m = [int(_) for _ in input().split(' ')] s = sum([i...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: You have three piles of candies: red, green and blue candies: the first pile contains only red candies and there are $r$ candies in it, the second pile contains only green candies and there are $g$ candies in it, the third pile contains only ...
```python n = int(input()) for _ in range(n): a, b, c = list(map(int, input().split())) print(min((a+b+c)//2, a+b, a+c, b+c)) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Every Friday Chef and his N - 1 friends go for a party. At these parties, they play board games. This Friday, they are playing a game named "Boats! Boats! Boats!". In this game players have to transport cookies between Venice and Constantinople....
```python # cook your code here for _ in range(eval(input())): n=eval(input()) ind=0 m=-1 for i in range(n): l=[int(x) for x in input().split()] sc=l[0] for j in range(1,len(l)): sc+=int(l[j]>=4)+int(l[j]>=5)+2*int(l[j]>=6) if sc==m: ind=-2 if sc>m : m=sc ind=i+1 if (ind==-2): p...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: The chef is trying to solve some series problems, Chef wants your help to code it. Chef has one number N. Help the chef to find N'th number in the series. 0, 1, 5, 14, 30, 55 ….. -----Input:----- - First-line will contain $T$, the number of tes...
```python T=int(input()) for i in range(T): n=int(input()) if n==1: print("0") else: n=n-2 l=(n+1)*(2*n+3)*(n+2)/6 print(int(l)) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Oleg the bank client and Igor the analyst are arguing again. This time, they want to pick a gift as a present for their friend, ZS the coder. After a long thought, they decided that their friend loves to eat carrots the most and thus they want t...
```python def evens(A): n = len(A) l = n//2-1; r = n//2 if len(A)%2 == 1: l+= 1 ans = [max(A[l], A[r])] while r < n-1: l-= 1; r+= 1 ans.append(max(ans[-1], A[l], A[r])) return ans def interleave(A, B): q = [] for i in range(len(B)): q+= [A[i], B[i]] if len(A) != len(...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Raj is suffering from shot term memory loss so he is unable to remember his laptop password but he has a list of some string and the only thing that he remember about his password is alphanumeric and also that all the characters are unique. Gi...
```python import collections while True: d = input().strip() myCounter = collections.Counter(d) flag = 1 for x in list(myCounter.keys()): if myCounter[x] > 1: flag = 0 break isAlp = sum([myCounter[x] for x in list(myCounter.keys()) if x.isalnum()]) if flag and isAlp: print("Valid") break else: ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: The USA Construction Operation (USACO) recently ordered Farmer John to arrange a row of $n$ haybale piles on the farm. The $i$-th pile contains $a_i$ haybales. However, Farmer John has just left for vacation, leaving Bessie all on her own. Eve...
```python import sys #sys.stdin=open("data.txt") input=sys.stdin.readline mii=lambda:list(map(int,input().split())) for _ in range(int(input())): n,d=mii() a=list(mii()) ans=0 for i in range(n): while d>=i and a[i]: a[i]-=1 ans+=1 d-=i print(ans) ```