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: There are $X$ people participating in a quiz competition and their IDs have been numbered from $1$ to $X$ (both inclusive). Beth needs to form a team among these $X$ participants. She has been given an integer $Y$. She can choose participants wh...
```python for _ in range(int(input())): x, y = map(int, input().split()) ans = 0 for i in range(y, x+1, y): if i%y == 0: ans += i%10 print(ans) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: The Chef has prepared the appetizers in the shapes of letters to spell a special message for the guests. There are n appetizers numbered from 0 to n-1 such that if the appetizers are arrayed in this order, they will display the message. The Chef...
```python t=int(input()) def reversebinary(bits,n): bStr='' for i in range(bits): if n>0: bStr=bStr+str(n%2) else: bStr=bStr+'0' n=n>>1 return int(bStr,2) for i in range(t): k,msg=input().split() k=int(k) newmsg=[] for j in msg: ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Polycarp took $n$ videos, the duration of the $i$-th video is $a_i$ seconds. The videos are listed in the chronological order, i.e. the $1$-st video is the earliest, the $2$-nd video is the next, ..., the $n$-th video is the last. Now Polycarp ...
```python import sys n,k = map(int, sys.stdin.readline().split()) arr = list(map(int, sys.stdin.readline().split())) tot = sum(arr) if tot % k != 0: print('No') return tot //= k idx,cur = 0,0 ans = [] for i in range(n): cur += arr[i] idx += 1 if cur == tot: ans.append(idx) idx = 0 cur = 0 elif cur > tot: ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: A string is called bracket sequence if it does not contain any characters other than "(" and ")". A bracket sequence is called regular if it it is possible to obtain correct arithmetic expression by inserting characters "+" and "1" into this seq...
```python cnt1 = int(input()) cnt2 = int(input()) cnt3 = int(input()) cnt4 = int(input()) if cnt1 != cnt4: print(0) return if (cnt3 != 0 and cnt1 == 0): print(0) return print(1) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Students went into a class to write a test and sat in some way. The teacher thought: "Probably they sat in this order to copy works of each other. I need to rearrange them in such a way that students that were neighbors are not neighbors in a ne...
```python n,m=map(int,input().split()) if n==1and m==1:print('YES\n1') elif n==3and m==3: print('YES') print(6, 1, 8) print(7,5,3) print(2,9,4) elif n<4and m<4:print('NO') elif n==1 or m==1: t=max(n,m) a=[i for i in range(2,t+1,2)] a+=[i for i in range(1,t+1,2)] print('YES') for i in...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: A schoolboy named Vasya loves reading books on programming and mathematics. He has recently read an encyclopedia article that described the method of median smoothing (or median filter) and its many applications in science and engineering. Vasya...
```python from sys import stdin #stdin = open('input.txt') n = int(stdin.readline()) seq = [int(x) for x in stdin.readline().split()] carry = seq[0] result = [carry] mark = False cur_len = 0 max_len = 0 i = 1 while i < len(seq) - 1: if mark: if seq[i] != seq[i + 1]: cur_len += 1 els...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Chef works as a cook in a restaurant. Each morning, he has to drive down a straight road with length K$K$ to reach the restaurant from his home. Let's describe this road using a coordinate X$X$; the position of Chef's home is X=0$X = 0$ and the ...
```python # cook your dish here t = int(input()) for _ in range(t): n, k, d = list(map(int, input().split())) x = list(map(int, input().split())) l = list(map(int, input().split())) lane = 3 - l[0] switched = -float('inf') ans = k for i in range(n): if l[i] == lane: if switched + ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Greg has an array a = a_1, a_2, ..., a_{n} and m operations. Each operation looks as: l_{i}, r_{i}, d_{i}, (1 ≤ l_{i} ≤ r_{i} ≤ n). To apply operation i to the array means to increase all array elements with numbers l_{i}, l_{i} + 1, ..., r_{i} ...
```python from sys import stdin, stdout rd = lambda: list(map(int, stdin.readline().split())) n, m, k = rd() a = rd() b = [rd() for _ in range(m)] x = [0]*(m+1) y = [0]*(n+1) for _ in range(k): l, r = rd() x[l-1] += 1 x[r ] -= 1 s = 0 for i in range(m): l, r, d = b[i] s += x[i] y[l-1] += s*d y[r ] -...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Nicholas has an array a that contains n distinct integers from 1 to n. In other words, Nicholas has a permutation of size n. Nicholas want the minimum element (integer 1) and the maximum element (integer n) to be as far as possible from each ot...
```python read = lambda: list(map(int, input().split())) n = int(input()) a = list(read()) x, y = a.index(1), a.index(n) ans = max(x, y, n - x - 1, n - y - 1) print(ans) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Sereja has two integers — A and B — in 7-ary system. He wants to calculate the number C, such that B * C = A. It is guaranteed that B is a divisor of A. Please, help Sereja calculate the number C modulo 7L. -----Input----- First line of input...
```python t=int(input()) while t>0 : a=int(input()) b=int(input()) l=int(input()) x=0 y=0 z=0 a1=0 b1=0 c1=0 while(a//10!=0 or a%10!=0): a1+=(a%10+((a//10)%10)*7+((a//100)%10)*49+((a//1000)%10)*343+((a//10000)%10)*2401+((a//100000)%10)*16807+((a//1000000)%10)*117649+((a//10000000)%10)*823543+((a//100000000)...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Phoenix loves beautiful arrays. An array is beautiful if all its subarrays of length $k$ have the same sum. A subarray of an array is any sequence of consecutive elements. Phoenix currently has an array $a$ of length $n$. He wants to insert som...
```python t = int(input()) for _ in range(t): n, k = [int(x) for x in input().split()] a = [int(x) for x in input().split()] if len(set(a)) > k: print(-1) continue l = list(set(a)) l.extend([1]*(k - len(l))) print(n*k) for _ in range(n): print(*l, end=" ") print...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $n$ is always even, and in C2, $n$ is always odd. You are given a regular polygon with $2 \cdot n$ vertices (it's convex and h...
```python import math T = int(input()) for _ in range(T): n = int(input()) print(1/math.tan(math.pi/2/n)) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Allen dreams of one day owning a enormous fleet of electric cars, the car of the future! He knows that this will give him a big status boost. As Allen is planning out all of the different types of cars he will own and how he will arrange them, h...
```python def main(): n, k = map(int, input().split()) a, b, c, d = (list(map(int, input().split())) for _ in 'abcd') ss, tt, n2, res = [*b, *c[::-1]], [*a, *d[::-1]], n * 2, [] yx = [*[(2, i + 1) for i in range(n)], *[(3, i) for i in range(n, 0, -1)]] def park(): for i, s, t, (y, x) in zip...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Let $a_1, \ldots, a_n$ be an array of $n$ positive integers. In one operation, you can choose an index $i$ such that $a_i = i$, and remove $a_i$ from the array (after the removal, the remaining parts are concatenated). The weight of $a$ is defi...
```python from sys import stdin def bitadd(a,w,bit): x = a while x <= (len(bit)-1): bit[x] += w x += x & (-1 * x) def bitsum(a,bit): ret = 0 x = a while x > 0: ret += bit[x] x -= x & (-1 * x) return ret class RangeBIT: def __init__(self,N,indexed): ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Given an array $A_1, A_2, ..., A_N$, count the number of subarrays of array $A$ which are non-decreasing. A subarray $A[i, j]$, where $1 ≤ i ≤ j ≤ N$ is a sequence of integers $A_i, A_i+1, ..., A_j$. A subarray $A[i, j]$ is non-decreasing if $A...
```python # cook your dish here t=int(input()) for i in range(t): n=int(input()) ar=list(map(int,input().split())) tot=0 st=0 for j in range(1,n): if(ar[j-1]>ar[j]): si=j-st c=(si*(si+1))//2 tot+=c st=j si=n-st c=(si*(si+1))//2 tot+=c print(tot) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: You are given a square matrix $M$ with $N$ rows (numbered $1$ through $N$) and $N$ columns (numbered $1$ through $N$). Initially, all the elements of this matrix are equal to $A$. The matrix is broken down in $N$ steps (numbered $1$ through $N$)...
```python # cook your dish here for _ in range(int(input())): n,k = list(map(int,input().split())) mod = 10**9+7 s=0 for i in range(1,n+1): p = pow(k,(2*i)-1,mod) # print(p) s=(s+p)%mod # print(k) k = (p*k)%mod print(s) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: This problem is the most boring one you've ever seen. Given a sequence of integers a_1, a_2, ..., a_{n} and a non-negative integer h, our goal is to partition the sequence into two subsequences (not necessarily consist of continuous elements)....
```python n,m=map(int,input().split());a=list(map(int,input().split()));p=0;t=[0]*3 for i in range(n): if(a[i]<a[p]):p=i if(n==2):print('0\n1 1\n') else: a.sort();t[0]=min(a[0]+a[1]+m,a[1]+a[2]);t[1]=max(a[0]+a[n-1]+m,a[n-2]+a[n-1]);t[2]=(a[n-2]+a[n-1])-(a[0]+a[1]) if(t[1]-t[0]>t[2]):p=n else:t[2]=t[...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Roger is a robot. He has an arm that is a series of n segments connected to each other. The endpoints of the i-th segment are initially located at points (i - 1, 0) and (i, 0). The endpoint at (i - 1, 0) is colored red and the endpoint at (i, 0)...
```python from cmath import rect import sys import math from functools import reduce class SegmentTree(): def __init__(self, L, function = lambda x,y: x+y): self.function = function N = self.size = len(L) M = 1 << N.bit_length() self.margin = 2*M - N self.L = [None for i in ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: While Grisha was celebrating New Year with Ded Moroz, Misha gifted Sasha a small rectangular pond of size n × m, divided into cells of size 1 × 1, inhabited by tiny evil fishes (no more than one fish per cell, otherwise they'll strife!). The gi...
```python import heapq as hq from queue import PriorityQueue import math n,m,r, k= input().split() N = int(n) M = int(m) R = int(r) K = int(k) q = PriorityQueue() for i in range(1,math.floor((N+1)/2) + 1): maxi = min(min(i,N-i+1),min(R,N-R+1)) * min(min(R,M-R+1),math.ceil(M/2)) num = M - (2 * min(min(R,M-R...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: The most dangerous cyborg Jenish is finally entrapped on a narrow bridge over a valley. The bridge is $N$ meters long. For convenience, position $i$ represents a portion of bridge between whose left border is at distance $i-1$ meters from left e...
```python # cook your dish here import bisect for _ in range(int(input())): n,x=list(map(int,input().split())) l=list(map(int,input().split())) battery=[] power=0 i=0 t=(n+1)//2 while power<x and i<t: if i==n-i-1: temp=[-1,l[i]] else: temp=sorted([ l[i], l[n-i-1] ]) power+=temp[1] pos=b...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Kabir wants to impress Tara by showing her his problem solving skills. He has decided to give the correct answer to the next question which will be asked by his Algorithms teacher. The question asked is: Find the sum of alternate consecutive d$d...
```python # cook your dish here for t in range(int(input().strip())): d = int(input().strip()) L, R = map(int, input().strip().split(" ")) if L % 2 == 0: L += 1 sum = (((((R - L + 2)//2)//d)+1)//2) - 1 sum = (sum * 2 * d * (sum + 1) * d) + (sum+1) *d * (L + d -1) print(sum%1000000007) ``...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Nick had received an awesome array of integers $a=[a_1, a_2, \dots, a_n]$ as a gift for his $5$ birthday from his mother. He was already going to explore its various properties but after unpacking he was disappointed a lot because the product $a...
```python n = int(input()) A = list(map(int, input().split())) if n == 1: if A[0] >= 0: print(A[0]) else: print(-A[0]-1) return for i in range(n): if A[i] < 0: pass else: A[i] = -A[i]-1 if n % 2 == 0: print(*A) return mim = 0 indmim = 0 for i in range(n): ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Chef has a rectangular matrix A of nxm integers. Rows are numbered by integers from 1 to n from top to bottom, columns - from 1 to m from left to right. Ai, j denotes the j-th integer of the i-th row. Chef wants you to guess his matrix. To guess...
```python # CHNGSS.py import sys from random import * n,m,c = list(map(int,input().split())) arr = [[1]*m for i in range(n)]; saved = 0; for i in range(n): for j in range(m): print(1,(i+1),(i+1),(j+1),(j+1),1,25) sys.stdout.flush() a = int(input()) if a == 1 : saved += 1; arr[i][j] = randint(1,25); e...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Shubham recently learned the lexicographical order in strings. Now, he has two strings s1 and s2 of the equal size and Shubham wants to compare those two strings lexicographically. Help Shubham with the strings comparison. Note: Letters a...
```python t=eval(input()) while t: t=t-1 s1=input().lower() s2=input().lower() res="equal" for i in range(len(s1)): if(s1[i]!=s2[i]): res="first" if s1[i]<s2[i] else "second" break print(res) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Chef has a sequence $A_1, A_2, \ldots, A_N$; each element of this sequence is either $0$ or $1$. Appy gave him a string $S$ with length $Q$ describing a sequence of queries. There are two types of queries: - '!': right-shift the sequence $A$, i....
```python n, q, k = map(int, input().split()) arr = list(map(int, input().split())) query = list(input()) q_ = len(query) c1 = query.count('?') c = arr.count(0) if c == n: for i in range(c1): print(0) else: for i in range(q_): if (i!=0) and (query[i] == '?' and query[i-1] == '?'): print(max_c) elif query[i] ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Niwel is a little golden bear. As everyone knows, bears live in forests, but Niwel got tired of seeing all the trees so he decided to move to the city. In the city, Niwel took on a job managing bears to deliver goods. The city that he lives in ...
```python from collections import defaultdict, deque adj = defaultdict(lambda: defaultdict(lambda: 0)) def bfs(graph, inicio, destino, parent): parent.clear() queue = deque() queue.append([inicio, float("Inf")]) parent[inicio] = -2 while (len(queue)): current, flow = queue.popleft() ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Vanya wants to minimize a tree. He can perform the following operation multiple times: choose a vertex v, and two disjoint (except for v) paths of equal length a_0 = v, a_1, ..., a_{k}, and b_0 = v, b_1, ..., b_{k}. Additionally, vertices a_1, ....
```python import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time sys.setrecursionlimit(10**7) inf = 10**20 mod = 10**9 + 7 def LI(): return list(map(int, input().split())) def II(): return int(input()) def LS(): return input().split() def S(): return input() def main(): n = II(...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: On the Literature lesson Sergei noticed an awful injustice, it seems that some students are asked more often than others. Seating in the class looks like a rectangle, where n rows with m pupils in each. The teacher asks pupils in the followin...
```python n, m, k, x, y = list(map(int, input().split())) ans = [[0] * m for x in range(n)] onebig = (2*n-2)*m or m oo = k // onebig for i in range(n): for j in range(m): if i == 0 or i == n-1: ans[i][j] += oo k -= oo else: ans[i][j] += 2*oo k -= 2...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: As Will is stuck in the Upside Down, he can still communicate with his mom, Joyce, through the Christmas lights (he can turn them on and off with his mind). He can't directly tell his mom where he is, because the monster that took him to the Ups...
```python def main(): s = input() l = len(s) pretty_count = 0 for i in range(l): left_paren_count = 0 right_paren_count = 0 wild_count = 0 for j in range(i, l): if s[j] == '(': left_paren_count += 1 elif s[j] == ')': ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: You are given a binary string S. You need to transform this string into another string of equal length consisting only of zeros, with the minimum number of operations. A single operation consists of taking some prefix of the string S and flippin...
```python # cook your dish here s=input() s1=s[::-1] arr=[] cnt=0 for i in range(len(s1)): arr.append(s1[i]) for i in range(len(arr)): if(arr[i]=="1"): for j in range(i,len(arr)): if(arr[j]=="1"): arr[j]="0" else: arr[j]="1" cnt+=1 print(cnt) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: It's year 2018 and it's Christmas time! Before going for vacations, students of Hogwarts School of Witchcraft and Wizardry had their end semester exams. $N$ students attended the semester exam. Once the exam was over, their results were displaye...
```python for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) s = set(a) if n == 1 or len(s) > 2: print(-1) continue if len(s) == 1: x = s.pop() if x == 0: print(n) elif x == n-1: print(0) else: print(-1) continue x, y = sorted(s) xc, yc = a.count(x), a....
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Chef has a nice complete binary tree in his garden. Complete means that each node has exactly two sons, so the tree is infinite. Yesterday he had enumerated the nodes of the tree in such a way: - Let's call the nodes' level a number of nodes th...
```python # cook your dish here MOD=10**9+7 for _ in range(int(input())): s=input() ind=1 level=1 for i in range(len(s)): if s[i]=='l': if level%2==1: ind=ind*2 else: ind=ind*2-1 if s[i]=='r': if level%2==1: ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Mrs. Smith is trying to contact her husband, John Smith, but she forgot the secret phone number! The only thing Mrs. Smith remembered was that any permutation of $n$ can be a secret phone number. Only those permutations that minimize secret val...
```python from math import sqrt n = int(input()) k = int(sqrt(n)) b = [] last = 0 while last < n: b.append([last + j for j in range(k)]) last = b[-1][-1] + 1 k = len(b) for i in range(k - 1, -1, -1): for j in b[i]: if j < n: print(1 + j, end=' ') print() ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Sergey recently learned about country codes - two letter strings, denoting countries. For example, BY stands for Belarus and IN stands for India. Mesmerized by this new discovery, Sergey now looks for country codes everywhere! Sergey has recentl...
```python #import set t = eval(input()) while(t): s = input() set1 = set() j = 0 for i in s[:-1]: a = s[j:j+2] set1.add(a) j = j + 1 print(str(len(set1)) + '\n') t= t-1 ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Chef loves to play with iron (Fe) and magnets (Ma). He took a row of $N$ cells (numbered $1$ through $N$) and placed some objects in some of these cells. You are given a string $S$ with length $N$ describing them; for each valid $i$, the $i$-th ...
```python # cook your dish here # cook your dish here for _ in range(int(input())) : n,k=map(int,input().split()) #reading the string s=input() i,j=0,0 q=0 while(i<n and j<n) : if(s[i]=='M') : if(s[j]=='I') : cnt=0 if(i>j) : p=s[j:i] cnt=p.count(':') else : p=s[i:j] cnt=p.cou...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: You are given a permutation of natural integers from 1 to N, inclusive. Initially, the permutation is 1, 2, 3, ..., N. You are also given M pairs of integers, where the i-th is (Li Ri). In a single turn you can choose any of these pairs (let's s...
```python t=int(input()) for _ in range(t): n,m=list(map(int,input().split())) l=list(map(int,input().split())) k=[] for i in range(m): a,b=list(map(int,input().split())) k.append([a,b]) k.sort() c=[] flag=1 x=k[0][0] y=k[0][1] for i in k[1:]: if i[0]<=y: y=max(y,i[1]) else: c.append([x-1,y-1]...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: You are given the set of vectors on the plane, each of them starting at the origin. Your task is to find a pair of vectors with the minimal non-oriented angle between them. Non-oriented angle is non-negative value, minimal between clockwise and...
```python from math import * # stores counterclockwise angle between vector (1,0) and each vector in a a = [] n = int(input()) for i in range(n): x,y = list(map(int,input().split())) # calculate counterclockwise angle between (1,0) and this vector t = acos(x/sqrt(x**2+y**2)) a.append((i+1,[2*pi-t,t][y>=...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: There is an integer sequence of length 2^N: A_0, A_1, ..., A_{2^N-1}. (Note that the sequence is 0-indexed.) For every integer K satisfying 1 \leq K \leq 2^N-1, solve the following problem: - Let i and j be integers. Find the maximum value of A...
```python j=n=1<<int(input()) a=[[0,int(s)]for s in input().split()] while j>1:j>>=1;a=[sorted(a[i]+a[i^j]*(i&j>0))[-2:]for i in range(n)] for s,f in a[1:]:j=max(j,s+f);print(j) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: The MarkiT online virtual market startup wants to organize its grand opening in NIT Patna. but they want maximum crowd for their inauguration. So the manager told this to Praveen a student in NITP who suggested them: The first-year students co...
```python import math def fun(num1,num2): if num1>num2: a=num1 b=num2 else: a=num2 b=num1 rem=a%b while(rem!=0): a=b b=rem rem=a%b gcd=b return (int((num1*num2)/gcd)) for _ in range (int(input())): hours=int(input())*24 x,y,z=list(map(int,input().split())) lcm=x lcm=fun(x,y) lcm=fun(lcm,z) ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Dio Brando has set a goal for himself of becoming the richest and the most powerful being on earth.To achieve his goals he will do anything using either manipulation,seduction or plain violence. Only one guy stands between his goal of conquerin...
```python # cook your dish here import sys import math from collections import Counter from collections import OrderedDict def inputt(): return sys.stdin.readline().strip() def printt(n): sys.stdout.write(str(n)+'\n') def listt(): return [int(i) for i in inputt().split()] def gcd(a,b): return math.gcd(...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Recently Rocky had participated in coding competition and he is sharing one of the problem with you which he was unable to solve. Help Rocky in solving the problem. Suppose the alphabets are arranged in a row starting with index 0$0$ from AtoZ$A...
```python # cook your dish here s = input().strip() start_w = 27 w_dict = {} words = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"] for word in words: w_dict[word] = start_w start_w = start_w - 1 total_wt = 0 for c in s: to...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Chef and his competitor Kefa own two restaurants located at a straight road. The position of Chef's restaurant is $X_1$, the position of Kefa's restaurant is $X_2$. Chef and Kefa found out at the same time that a bottle with a secret recipe is l...
```python # cook your dish here for t in range(int(input())): x1,x2,x3,v1,v2=[int(x)for x in input().rstrip().split()] t1=abs(x3-x1)/v1 t2=abs(x3-x2)/v2 if t1<t2: print("Chef") elif t1>t2: print("Kefa") elif t1==t2: print("Draw") else: pass ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Striver$Striver$ wants to strive hard in order to reach his goals, hence asks his mentor to give him a question for which he has to strive hard. The mentor gives Striver$Striver$ a N$N$ X N$N$ matrix consisting of lowercase characters (′a′$'a'$...
```python a=int(input()) for _ in range(a): c,d=list(map(int,input().split())) crr=[[[0,0] for i in range(c+1)] for j in range(c+1)] trr=[] for i in range(c): kk=list(input().split()) trr.append(kk) for i in range(1,c+1): for j in range(1,c+1): if(trr[i-...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: The chef was chatting with his friend who was a mathematician. Chef said "Hi !". His friend replied that '!' is the symbol of factorial. Chef had never heard about it and he asked more about it. Then his friend taught him how to calculate the ...
```python factorials=[1] for x in range(1,201): factorials.append(factorials[x-1]*x) x=int(input()) for x in range(x): n=int(input()) print(factorials[n]) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Let's call a sequence good if the sum of all its elements is $0$. You have a sequence of integers $A_1, A_2, \ldots, A_N$. You may perform any number of operations on this sequence (including zero). In one operation, you should choose a valid in...
```python n=int(input()) for i in range(n): t=int(input()) m=list(map(int,input().split())) p,q=0,0 if t==1: if m[0]>=0: print('YES') else: print('NO') else: for i in m: if i<0: q+=i else: p+=i if p>=abs(q): print('YES') else: print('NO') ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: The annual snake festival is upon us, and all the snakes of the kingdom have gathered to participate in the procession. Chef has been tasked with reporting on the procession, and for this he decides to first keep track of all the snakes. When he...
```python # cook your dish here t=int(input()) for i in range(t): n=int(input()) s=input().strip() c=0 for i in range(len(s)): if s[i]=='.': continue if s[i]=='H': c+=1 if s[i]=='T': c-=1 if c>1: break if c<0: break if c==0: print('Valid') else: print('Invalid') ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: There is a popular apps named “Exbook” like “Facebook”. To sign up in this app , You have to make a strong password with more than 3 digits and less than 10 digits . But I am a pro hacker and so I make a Exbook hacking site . You need to login i...
```python # cook your dish here t=int(input()) for i in range(0,t): p=input() l=list(p) for j in range(0,len(l)): l[j]=int(l[j]) l[j]=l[j]-2 for j in range(0,len(l)): l[j]=str(l[j]) q=''.join(l) print(q) ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Yaroslav is playing a game called "Time". The game has a timer showing the lifespan he's got left. As soon as the timer shows 0, Yaroslav's character dies and the game ends. Also, the game has n clock stations, station number i is at point (x_{i...
```python n, d = map(int, input().split()) a = [0] + list(map(int, input().split())) + [0] x = [] y = [] for i in range(n): xx, yy = map(int, input().split()) x += [xx] y += [yy] b = [-1] * n b[0] = 0 c = True while c: c = False for i in range(n): for j in range(1, n): if i != j and b[i] != -1: ...
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: It is so boring in the summer holiday, isn't it? So Alice and Bob have invented a new game to play. The rules are as follows. First, they get a set of n distinct integers. And then they take turns to make the following moves. During each move, e...
```python def gcd(a, b): while b > 0: a, b = b, a % b return a n = int(input()) A = list(map(int, input().split())) GCD = A[0] for x in A[1:]: GCD = gcd(GCD, x) num = max(A) // GCD - n if num % 2 == 0: print("Bob") else: print("Alice") ```
open-r1/verifiable-coding-problems-python-10k
Solve the following coding problem using the programming language python: Leha is a bright mathematician. Today he is investigating whether an integer is divisible by some square number or not. He has a positive integer X represented as a product of N integers a1, a2, .... aN. He has somehow figured out that there exi...
```python import sys import math r=int(input()) for v in range (0,r): n = int(input()) x=1 arr=list(map(int,input().strip().split(" "))) for i in range (0,n): x=x*arr[i] for i in range (2,100000000): if(x%(pow(i,2))==0): ans1=i break print(ans1) ```