source
stringclasses
1 value
task_type
stringclasses
1 value
in_source_id
stringlengths
1
4
problem
stringlengths
488
6.07k
gold_standard_solution
stringlengths
19
30.1k
verification_info
dict
metadata
dict
problem_id
stringlengths
5
9
apps
verifiable_code
1589
Solve the following coding problem using the programming language python: Write a program that reads numbers until -1 is not given. The program finds how many of the given numbers are more than 30, $N$. It also finds the average weighted sum of even numbers, $A$. The weight of the $i$th number is defined as the positi...
```python for _ in range(int(input())): a=list(map(int,input().split())) num=0 den=0 k=1 great=0 for i in a: if i==-1:break else: if i>30:great+=1 if i%2==0: num+=k*i den+=k k+=1 print(great,'%....
{ "language": "python", "test_cases": [ { "input": "1\n33 100 77 42 12 -1\n", "output": "4 38.91\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/SITC2020/problems/WESUM" }
vfc_5198
apps
verifiable_code
1590
Solve the following coding problem using the programming language python: Mance Rayder, the King-Beyond-the-Wall, has always wanted to lead the largest army the North has ever seen against the NIght’s Watch. For this humungous feat he has banded the waring tribes, the Giants, Thenns and Wildings, together by going to ...
```python n=int(input()) for i in range(n): a=list(map(int,input().split())) a.sort() if a[0]+a[1]>=a[2]-1: print("Yes") else: print("No") ```
{ "language": "python", "test_cases": [ { "input": "1\n1 2 1\n", "output": "Yes\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/COTS2020/problems/CDCUR01" }
vfc_5202
apps
verifiable_code
1591
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())]) ```
{ "language": "python", "test_cases": [ { "input": "4\n1\n2\n3\n4\n", "output": "1\n2\n6\n24\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/DMNT2016/problems/POFACT" }
vfc_5206
apps
verifiable_code
1592
Solve the following coding problem using the programming language python: Chef is in need of money, so he decided to play a game with Ramsay. In this game, there are $N$ rows of coins (numbered $1$ through $N$). For each valid $i$, the $i$-th row contains $C_i$ coins with values $A_{i, 1}, A_{i, 2}, \ldots, A_{i, C_i}...
```python for i in range(int(input())): n=int(input()) chef=0 ans=[] for i in range(0,n): l=list(map(int,input().split())) c=l[0] if c%2==0: for i in range(1,len(l)//2+1): chef=chef+l[i] continue; for i in range(1,len(l)//2): chef=chef+l[i] ans.append(l[len(l)//2]) ans.sort(reverse=True) fo...
{ "language": "python", "test_cases": [ { "input": "1\n2\n4 5 2 3 4\n2 1 6\n", "output": "8\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/SIMGAM" }
vfc_5210
apps
verifiable_code
1593
Solve the following coding problem using the programming language python: Consider a currency system in which there are notes of six denominations, namely, Rs. 1, Rs. 2, Rs. 5, Rs. 10, Rs. 50, Rs. 100. If the sum of Rs. N is input, write a program to computer smallest number of notes that will combine to give Rs. N. ...
```python # cook your dish here t= int(input()) for i in range(t): cnt=0 n=int(input()) while(n>=100): n-=100 cnt+=1 while(n>=50): n-=50 cnt+=1 while(n>=10): n-=10 cnt+=1 while(n>=5): n-=5 cnt+=1 while(n>=2): n-=2 ...
{ "language": "python", "test_cases": [ { "input": "3\n1200\n500\n242\n", "output": "12\n5\n7\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/FLOW005" }
vfc_5214
apps
verifiable_code
1594
Solve the following coding problem using the programming language python: After fixing the mercury leak, Kim has arrived in the planning room, where he finds a square map of a field, with $N$ rows and $N$ columns. Each cell in the field is either empty, or has a lookout tower on it. Using his notes, he immediately rea...
```python T = int(input()) ans = [] for _ in range(T): z = int(input()) for k in range(z): s = input() ans.append((z*(z+1))//2) for ele in ans: print(ele) ```
{ "language": "python", "test_cases": [ { "input": "2\n2\n10\n01\n4\n1000\n0010\n0100\n0001\n", "output": "3\n8\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/UWCOI20/problems/UWCOI20D" }
vfc_5218
apps
verifiable_code
1595
Solve the following coding problem using the programming language python: Nobody outside the cooking community knows that Chef is a big fan of Chefgram™ — a social network where chefs and cooks upload their secret kitchen photos. Recently Chef clicked a beautiful photo, which is represented using 10 pixels in a single...
```python import itertools import numpy as np b = np.zeros((100001), dtype=np.int) def power2(a): b[0] = 1 if b[a] > 0: return b[a] else: for i in range(1,a+1): b[i] = b[i-1]*2 if b[i] > (10**9+7): b[i] = b[i]%(10**9+7) return b[a] def __starting_point(): t = eval(input()) for i in range(t): s...
{ "language": "python", "test_cases": [ { "input": "3\nwwwwwwwwww\n3\n+-+-+-+-+-\n----------\n+---------\nwbwbwbwbwb\n3\n+-+-+-+-+-\n+-+-------\n----+-+-+-\nbbbbbbbbbb\n2\n----------\n----------\n\n\n", "output": "0\n2\n4\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/DEC15/problems/CHEFFILT" }
vfc_5222
apps
verifiable_code
1596
Solve the following coding problem using the programming language python: During quarantine chef’s friend invented a game. In this game there are two players, player 1 and Player 2. In center of garden there is one finish circle and both players are at different distances respectively $X$ and $Y$ from finish circle. B...
```python import math for i in range(int(input())): p,q=list(map(int,input().split())) c=0 h=0 while(q>=0): if(q==0): h+=1 break d=int(math.log2(q+1)) if(d==0): h+=1 break y=(2**d)-1 q-=y+1 if(q==-1): h+=1 break h+=1 while(p>=0): if(p==0): c+=1 break else: rem=...
{ "language": "python", "test_cases": [ { "input": "2\n4 5\n3 5\n", "output": "0 0\n1 1\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/QFUN2020/problems/CRCLJUMP" }
vfc_5226
apps
verifiable_code
1597
Solve the following coding problem using the programming language python: Chef is playing a game with his brother Chefu. He asked Chefu to choose a positive integer $N$, multiply it by a given integer $A$, then choose a divisor of $N$ (possibly $N$ itself) and add it to the product. Let's denote the resulting integer ...
```python import math def divisors(n): arr = [] for i in range(1,1+int(math.ceil(math.sqrt(n)))): if n%i == 0: arr.append(i) arr.append(n//i) arr = list(sorted(set(arr))) return arr try: t = int(input()) while t: t -= 1 a,m = map(int, input().split()) divs = divisors(m) ans = [] for d in divs: ...
{ "language": "python", "test_cases": [ { "input": "3\n3 35\n5 50\n4 65\n", "output": "1\n10\n0\n3\n13 15 16\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/GUESSNUM" }
vfc_5230
apps
verifiable_code
1598
Solve the following coding problem using the programming language python: Mr. Das is a teacher teaching for several years in a school. He is not computer savvy. Due to lockdown, now he has to take classes online. Recently he took an online exam for students of different classes. Now, he will call parents of all the st...
```python try: # cook your dish here t=int(input()) for j in range(t): n=int(input()) x=[] p=[] m=[] for i in range(n): X,P,M=list(map(str,input().split())) x.append(X) p.append(int(P)) m.append(int(M)) avg=sum(m)/n for i in m: if i<avg: z=sorted([k for k in m if k<avg]) for i i...
{ "language": "python", "test_cases": [ { "input": "2\n3\nRahul 1345964789 47\nRupendra 1457856987 58\nPriya 1478569820 45\n2\nTanuja 4310779415 97\nAkash 3689781245 43\n", "output": "Priya 1478569820 45\nRahul 1345964789 47\nAkash 3689781245 43\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/COMT2020/problems/HELPTECH" }
vfc_5234
apps
verifiable_code
1599
Solve the following coding problem using the programming language python: Chef and his mother are going travelling. Chef's world consists of $N$ cities (numbered $1$ through $N$) connected by $N-1$ bidirectional roads such that each city can be reached from any other city using roads. For each city, we know its age — ...
```python '''input 1 3 1 2 1 3 1 2 3 ''' import sys sys.setrecursionlimit(1000000) for _ in range(eval(input())): C=[] n=eval(input()) for i in range(n): C.append([]) for i in range(n-1): a,b=[int(x)-1 for x in input().split()] C[a].append(b) C[b].append(a) cnt=0 Co=[bin(int(x)).count("1") for x in input(...
{ "language": "python", "test_cases": [ { "input": "1\n3\n1 2\n1 3\n1 2 3\n", "output": "2\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/CHEFTRVL" }
vfc_5238
apps
verifiable_code
1600
Solve the following coding problem using the programming language python: Shivam owns a gambling house, which has a special wheel called The Wheel of Fortune. This wheel is meant for giving free coins to people coming in the house. The wheel of fortune is a game of chance. It uses a spinning wheel with exactly N nu...
```python t=int(input()) for _ in range(t): n=int(input()) arr=list(map(int,input().split())) d={} for i in range(n): if arr[i] in d: d[arr[i]].append(i) else: d[arr[i]]=[i] q=int(input()) for i in range(q): m=int(input()) if l...
{ "language": "python", "test_cases": [ { "input": "2\n3\n1 2 3\n3\n1\n2\n3\n6\n2 1 5 3 2 1\n4\n1\n2\n3\n5\n", "output": "3\n3\n3\n2\n2\n6\n6\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/CCWC2018/problems/WFORT" }
vfc_5242
apps
verifiable_code
1601
Solve the following coding problem using the programming language python: Chef is playing a game with two of his friends. In this game, each player chooses an integer between $1$ and $P$ inclusive. Let's denote the integers chosen by Chef, friend 1 and friend 2 by $i$, $j$ and $k$ respectively; then, Chef's score is ...
```python for __ in range(int(input())): n,p=list(map(int,input().split())) d=n%(n//2+1) if(d==0): t=p*p*p else: t=(p-d)*(p-d)+(p-d)*(p-n)+(p-n)*(p-n) print(t) ```
{ "language": "python", "test_cases": [ { "input": "2\n4 4\n3 4\n", "output": "9\n13\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/MGAME" }
vfc_5246
apps
verifiable_code
1602
Solve the following coding problem using the programming language python: There is a girl named ''Akansha''. She is very fond of eating chocolates but she has a weak immune system due to which she gets cold after eating chocolate during morning, evening and night and can only eat at most $x$ number of chocolate each a...
```python for t in range(int(input().strip())): n = int(input().strip()) x = int(input().strip()) arr = list(map(int, input().strip().split())) arr.sort() day = 1 acc = 0 isPossible = True for a in arr: acc += 1 if acc > x: day += 1 acc = 1 if day >= a: isPossible = False break print("Possib...
{ "language": "python", "test_cases": [ { "input": "3\n3\n5\n4 1 2\n5\n2\n4 4 3 2 2\n5\n1\n4 2 3 1 1\n", "output": "Impossible\nPossible\nImpossible\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/BTCH2020/problems/AKACHOCO" }
vfc_5250
apps
verifiable_code
1603
Solve the following coding problem using the programming language python: There are some websites that are accessible through several different addresses. For example, for a long time Codeforces was accessible with two hostnames codeforces.com and codeforces.ru. You are given a list of page addresses being queried. F...
```python # Bartek Kostka # You are not prepared! #include "bits/stdc++.h" n = int(input()) W = {} for i in range(n): adr = input() adr = adr.split("/") if adr[-1] == '': adr[-1] = '?' domena = "/".join(adr[:3]) adres = "/".join(adr[3:]) #print(domena, adres) if domena not in W: ...
{ "language": "python", "test_cases": [ { "input": "10\nhttp://abacaba.ru/test\nhttp://abacaba.ru/\nhttp://abacaba.com\nhttp://abacaba.com/test\nhttp://abacaba.de/\nhttp://abacaba.ru/test\nhttp://abacaba.de/test\nhttp://abacaba.com/\nhttp://abacaba.com/t\nhttp://abacaba.com/test\n", "output": "1\nht...
{ "difficulty": "interview", "problem_url": "https://codeforces.com/problemset/problem/644/C" }
vfc_5254
apps
verifiable_code
1604
Solve the following coding problem using the programming language python: You are at the top left cell $(1, 1)$ of an $n \times m$ labyrinth. Your goal is to get to the bottom right cell $(n, m)$. You can only move right or down, one cell per step. Moving right from a cell $(x, y)$ takes you to the cell $(x, y + 1)$, ...
```python def getSum(dp, pos, s, e, type_): if e < s: return 0 if type_=='D': if e==m-1: return dp[pos][s] return dp[pos][s]-dp[pos][e+1] else: if e==n-1: return dp[s][pos] return dp[s][pos]-dp[e+1][pos] mod = 10**9+7 n, m = map(i...
{ "language": "python", "test_cases": [ { "input": "1 1\n.\n", "output": "1\n", "type": "stdin_stdout" }, { "input": "2 3\n...\n..R\n", "output": "0\n", "type": "stdin_stdout" }, { "input": "4 4\n...R\n.RR.\n.RR.\nR...\n", "output": "4\n", "t...
{ "difficulty": "interview", "problem_url": "https://codeforces.com/problemset/problem/1225/E" }
vfc_5258
apps
verifiable_code
1605
Solve the following coding problem using the programming language python: Dreamoon loves summing up something for no reason. One day he obtains two integers a and b occasionally. He wants to calculate the sum of all nice integers. Positive integer x is called nice if $\operatorname{mod}(x, b) \neq 0$ and $\frac{\opera...
```python a,b=map(int,input().split()) print(((b-1)*a*b//2+(a+1)*a*b*b*(b-1)//4)%1000000007) ```
{ "language": "python", "test_cases": [ { "input": "1 1\n", "output": "0\n", "type": "stdin_stdout" }, { "input": "2 2\n", "output": "8\n", "type": "stdin_stdout" }, { "input": "4 1\n", "output": "0\n", "type": "stdin_stdout" }, { ...
{ "difficulty": "interview", "problem_url": "https://codeforces.com/problemset/problem/476/C" }
vfc_5262
apps
verifiable_code
1606
Solve the following coding problem using the programming language python: Tavak and Seyyed are good friends. Seyyed is very funny and he told Tavak to solve the following problem instead of longest-path. You are given l and r. For all integers from l to r, inclusive, we wrote down all of their integer divisors except...
```python l,r = map(int, input().split(" ")) if l == r: print (l) else: print (2) ```
{ "language": "python", "test_cases": [ { "input": "19 29\n", "output": "2\n", "type": "stdin_stdout" }, { "input": "3 6\n", "output": "2\n", "type": "stdin_stdout" }, { "input": "39 91\n", "output": "2\n", "type": "stdin_stdout" }, {...
{ "difficulty": "interview", "problem_url": "https://codeforces.com/problemset/problem/805/A" }
vfc_5266
apps
verifiable_code
1607
Solve the following coding problem using the programming language python: "QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth. Now Diamond has given Bort a string consisting of only uppercase English letters of length n. There is a great number of "QAQ" in the string (...
```python s=input() ans = 0 for i in range(len(s)): if s[i] == 'A': ans += s[:i].count('Q') * s[i:].count('Q') print(ans) ```
{ "language": "python", "test_cases": [ { "input": "QAQAQYSYIOIWIN\n", "output": "4\n", "type": "stdin_stdout" }, { "input": "QAQQQZZYNOIWIN\n", "output": "3\n", "type": "stdin_stdout" }, { "input": "QA\n", "output": "0\n", "type": "stdin_std...
{ "difficulty": "interview", "problem_url": "https://codeforces.com/problemset/problem/894/A" }
vfc_5270
apps
verifiable_code
1670
Solve the following coding problem using the programming language python: Finally the clowns of Synapse have decided to take their site online. The convener of the clowns has heard from somewhere that knowing URI's is very important for their website, so kindly help him with this task. Uniform Resource Identifiers (o...
```python import sys def main(): s = sys.stdin.readline save = {' ': '%20', '!': '%21', '$': '%24', '%': '%25', '(': '%28', ')': '%29', '*': '%2a'} string = s().strip() while True: output = [] if '#' in string: return for i in string: if i in save: ...
{ "language": "python", "test_cases": [ { "input": "Happy Joy Joy!\nhttp://synapse.daiict.ac.in/\nplain_vanilla\n(**)\n?\nthe 7% solution\n#\n", "output": "Happy%20Joy%20Joy%21\nhttp://synapse.daiict.ac.in/\nplain_vanilla\n%28%2a%2a%29\n?\nthe%207%25%20solution\n", "type": "stdin_stdout" }...
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/CDMT2012/problems/SYNOL" }
vfc_5336
apps
verifiable_code
1671
Solve the following coding problem using the programming language python: Andre has very specific tastes. Recently he started falling in love with arrays. Andre calls an nonempty array $b$ good, if sum of its elements is divisible by the length of this array. For example, array $[2, 3, 1]$ is good, as sum of its elem...
```python # ------------------- fast io -------------------- import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in...
{ "language": "python", "test_cases": [ { "input": "3\n1\n2\n4\n", "output": "4 \n4 4 \n4 4 4 4 \n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://codeforces.com/problemset/problem/1438/A" }
vfc_5340
apps
verifiable_code
1672
Solve the following coding problem using the programming language python: per nextum in unam tum XI conscribementis fac sic vestibulo perlegementum da varo. morde varo. seqis cumula varum. cis per nextum in unam tum XI conscribementis fac sic seqis decumulamenta da varo. varum privamentum ...
```python f={} f[-40] = '-319993.68' f[-41] = '-344598.60' f[-42] = '-370433.52' f[-43] = '-397528.44' f[-44] = '-425913.37' f[-45] = '-455618.29' f[-46] = '-486673.22' f[-47] = '-519108.14' f[-48] = '-552953.07' f[-49] = '-588238.00' f[-50] = '-624992.93' f[-29] = '-121939.61' f[-30] = '-134994.52' f[-31] = '-148949....
{ "language": "python", "test_cases": [ { "input": "0\n1\n-2\n-3\n-4\n-5\n-6\n-7\n-8\n-9\n10\n", "output": "", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://codeforces.com/problemset/problem/1331/G" }
vfc_5344
apps
verifiable_code
1675
Solve the following coding problem using the programming language python: You are given a set of points in the 2D plane. You start at the point with the least X and greatest Y value, and end at the point with the greatest X and least Y value. The rule for movement is that you can not move to a point with a lesser X va...
```python from math import sqrt def get_distance(x1,y1,x2,y2): return sqrt((x1-x2)**2 + (y1-y2)**2) T = int(input()) ans = [] for _ in range(T): blank = input() N = int(input()) C = [[] for i in range(10**4+1)] for i in range(N): x,y = [int(i) for i in input().split()] C[x].appe...
{ "language": "python", "test_cases": [ { "input": "3\n\n2\n0 0\n0 1\n\n3\n0 0\n1 1\n2 2\n\n4\n0 0\n1 10\n1 5\n2 2\n\n\n", "output": "1.00\n2.83\n18.21\n\nFor the third test case above, the following is the path you must take:\n0,0 -> 1,10 \n1,10 -> 1,5\n1,5 -> 2,2\n= 18.21\n", "type": "stdin...
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/POINTS" }
vfc_5350
apps
verifiable_code
1676
Solve the following coding problem using the programming language python: Chef has found a new game and now he wants you to help him to get as much points as possible. Rules of the game: There are different types of game pieces - geometric shapes composed of some amount of square blocks. In the picture below you can...
```python import sys blocks = {} for i in range(1, 10): blocks[i] = [(0, 0)] for i in range(2, 10, 2): for j in range(1, i / 2 + 1): blocks[i].append((j, 0)) blocks[i + 1].append((0, j)) # print blocks blocks[10] = [(0, 0), (0, 1), (1, 0), (1, 1)] blocks[11] = [(0, 0), (0, 1), (0, 2), (1, 0), ...
{ "language": "python", "test_cases": [ { "input": "8 3 11\n6 14 12\n5 10 11\n5 7 11\n16 19 1\n-1 -1 -1\n\n\n", "output": "3 6 5 2 2 2 1 10 8\n1 4 8 2 6 1 3 7 2\n1 5 8 3 4 8 2 6 8\n3 9 8 2 10 7 1 1 6\n3 10 8 2 8 3 -1 -1 -1\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/JUNE16/problems/CHNWGM" }
vfc_5354
apps
verifiable_code
1677
Solve the following coding problem using the programming language python: Indian National Olympiad in Informatics 2015 In this problem you are given two lists of N integers, a1, a2, ..., aN and b1, b2, ... bN. For any pair (i, j) with i, j ϵ {1, 2, ..., N} we define the segment from i to j, written as [i, j], to be i,...
```python #dt = {} for i in x: dt[i] = dt.get(i,0)+1 import sys;input = sys.stdin.readline #import io,os; input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline #for pypy inp,ip = lambda :int(input()),lambda :[int(w) for w in input().split()] from collections import deque def getmax(x,n,k): mx = [] ...
{ "language": "python", "test_cases": [ { "input": "52 3 2 3 13 4 4 6 3\n", "output": "18\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/INOIPRAC/problems/INOI1501" }
vfc_5358
apps
verifiable_code
1678
Solve the following coding problem using the programming language python: Chef has two integer sequences $A_1, A_2, \ldots, A_N$ and $B_1, B_2, \ldots, B_M$. You should choose $N+M-1$ pairs, each in the form $(A_x, B_y)$, such that the sums $A_x + B_y$ are all pairwise distinct. It is guaranteed that under the given c...
```python # cook your dish here n,m = map(int, input().split()) arr1 = list(map(int, input().split())) arr2 = list(map(int, input().split())) max1 = arr1.index(max(arr1)) min2 = arr2.index(min(arr2)) arr = [] for i in range(m): arr.append([max1, i]) for i in range(n): if i!=max1: arr.append([i , min2])...
{ "language": "python", "test_cases": [ { "input": "3 2\n10 1 100\n4 3\n\n", "output": "2 1\n0 0\n1 0\n0 1\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/DPAIRS" }
vfc_5362
apps
verifiable_code
1679
Solve the following coding problem using the programming language python: Raavan gave a problem to his son, Indrajeet, and asked him to solve the problem to prove his intelligence and power. The Problem was like: Given 3 integers, $N$, $K$, and $X$, produce an array $A$ of length $N$, in which the XOR of all elements ...
```python # cook your dish here for _ in range(int(input())): l,n,x=map(int,input().split()) m=[] pw1 = (1 << 17); pw2 = (1 << 18); if (n == 1) : m.append(x) elif (n == 2 and x == 0) : m.append(-1) elif (n == 2) : m.append(x) m.append(0) else : ...
{ "language": "python", "test_cases": [ { "input": "3\n5 1 4\n5 2 4\n5 3 4\n\n", "output": "4 4 4 4 4\n3 7 3 7 3\n11 6 9 11 6\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/PCR12020/problems/RAAVANCH" }
vfc_5366
apps
verifiable_code
1680
Solve the following coding problem using the programming language python: -----Description----- The Antique Comedians of India prefer comedies to tragedies. Unfortunately, most of the ancient plays are tragedies. Therefore the dramatic advisor of ACI has decided to transfigure some tragedies into comedies. Obviously, ...
```python #include<stdio.h> int rev(int k) { int j,res=0; while(k) { res=res*10+k%10; k/=10; } return res; } int main() { int j,a,b,m,k; while(scanf("%d",&m)!=EOF) { for(j=1;j<=m;j++) { scanf("%d %d",&a,&b); k=rev(a)+rev(b); printf("%d\n",rev(k)); } } return 0; } ```
{ "language": "python", "test_cases": [ { "input": "3\n24 1\n4358 754\n305 794\n", "output": "34\n1998\n1\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/BUGS2020/problems/IOI1804" }
vfc_5370
apps
verifiable_code
1681
Solve the following coding problem using the programming language python: You are given two integers N$N$ and M$M$. You have to construct a matrix with N$N$ rows and M$M$ columns. Consider a multiset S$S$ which contains N+M$N + M$ integers: for each row and each column of this matrix, the MEX of the elements of this r...
```python for _ in range(int(input())): x,y=map(int,input().split()) if(x==y): if(x==1): print(1) else: n=0 for i in range(x-1): n=i for _ in range(y): print(n,end=' ') n=(n+1)%x ...
{ "language": "python", "test_cases": [ { "input": "2\n3 3\n4 2\n\n", "output": "9 1 0\n1 0 2\n7 5 8\n2 2\n3 0\n1 1\n0 1\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/TOTEM" }
vfc_5374
apps
verifiable_code
1682
Solve the following coding problem using the programming language python: You are provided with an input containing a number. Implement a solution to find the largest sum of consecutive increasing digits , and present the output with the largest sum and the positon of start and end of the consecutive digits. Example :...
```python l=list(map(int,input())) t=-1 x=-1 y=-1 for i in range(len(l)): s=l[i] a=i+1 b=i+1 for j in range(i+1,len(l)): if l[i]<l[j]: s=s+l[j] b=j+1 else: break if s>t: t=s x=a y=b print(t,end=":") print(x,y,sep="-") ```
{ "language": "python", "test_cases": [ { "input": ":\nInput :> 8789651\n", "output": "where 24 is the largest sum and 2-4 is start and end of the consecutive increasing digits.\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/SSCC2020/problems/SSEC0015" }
vfc_5378
apps
verifiable_code
1683
Solve the following coding problem using the programming language python: Uttu got to know about an interesting two-player mobile game recently and invites his friend Gangwar to try it out with him. Gangwar, however, has been playing this game since it was out 5 years ago and is a Legendary Grandmaster at it. Uttu imm...
```python ''' J A I ~ S H R E E ~ R A M ''' # Title: cc-CKOJ20D.py # created on: 20-07-2020 at 20:46:04 # Creator & Template : Udit Gupta "@luctivud" # https://github.com/luctivud # https://www.linkedin.com/in/udit-gupta-1b7863135/ import math; from collections import * import sys; from functools i...
{ "language": "python", "test_cases": [ { "input": "2\n10 10\n1 2\n", "output": "First\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/COJK2020/problems/CKOJ20D" }
vfc_5382
apps
verifiable_code
1684
Solve the following coding problem using the programming language python: Laxman, a great Mathematician and Thinker, gives Sugreev an integer, $N$, and asks him to make an array $A$ of length $N$, such that $\sum A$i$^3 = X^2$, to prove the purity of the bond of his friendship with Ram. Sugreev is facing difficulty i...
```python # cook your dish here t = int(input()) while(t>0): n = int(input()) k=1 while(k<=n): print(k, end=' ') k+=1 print('\n') t-=1 ```
{ "language": "python", "test_cases": [ { "input": "2\n1\n6\n\n", "output": "4\n5 10 5 10 5 5\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/PCR12020/problems/LAXMAN" }
vfc_5386
apps
verifiable_code
1685
Solve the following coding problem using the programming language python: Anna Hazare is a well known social activist in India. On 5th April, 2011 he started "Lokpal Bill movement". Chef is very excited about this movement. He is thinking of contributing to it. He gathers his cook-herd and starts thinking about how ...
```python from collections import deque from sys import stdin import psyco psyco.full() graph = [[]] WHITE, GRAY, BLACK = 0, 1, 2 def notoriety(x, f_count): queue = deque([x]) d = [0 for i in range(f_count+1)] p = [0 for i in range(f_count+1)] color = [WHITE for i in range(f_count+1)] while len(qu...
{ "language": "python", "test_cases": [ { "input": "1\n6\n3\n5\n1 4\n3 5 6\n2 4 6\n4 5\n\n\n", "output": "4 1.166667\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/JULY11/problems/LOKBIL" }
vfc_5390
apps
verifiable_code
1687
Solve the following coding problem using the programming language python: Salmon is playing a game! He is given two integers $N$ and $K$. His goal is to output $K$ pairs $(x_i,y_i)$. He creates a function $f$ such that $f(x_i) = y_i$ and $f$ is undefined for all other values of $x$. His pairs must then meet the follow...
```python for _ in range(int(input())): n,k=[int(x) for x in input().split()] if k%4==0: for i in range(0,k,4): print(i,i+1) print(i+1,i+2) print(i+2,i+3) print(i+3,i) elif k%4==1: for i in range(4,k-1,4): print(i,i+1) p...
{ "language": "python", "test_cases": [ { "input": "2\n3 7\n4 6\n\n", "output": "5 3\n1 7\n0 4\n2 5\n3 1\n4 2 \n7 0\n1 10\n10 14\n15 1\n14 13\n5 15\n13 5\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/UWCOI21F" }
vfc_5398
apps
verifiable_code
1689
Solve the following coding problem using the programming language python: Meanwhile, Candace and Stacy are busy planning to attend the concert of the famous Love Händel. Jeremy will also be attending the event. Therefore, Candace plans to offer the best possible gift to Jeremy. Candace has $N$ strings, each of length ...
```python # import all important libraries and inbuilt functions from fractions import Fraction import numpy as np import sys,bisect,copyreg,copy,statistics,os from math import * from collections import Counter,defaultdict,deque,OrderedDict from itertools import combinations,permutations,accumulate from numpy.lina...
{ "language": "python", "test_cases": [ { "input": "2\n3 3\nxab\na#z\ncaa\n5 4\npyqs\nvcot\nqbiu\nlihj\nuvmz\n\n", "output": "xabza\npvcbihjz\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/CLLEXO" }
vfc_5406
apps
verifiable_code
1690
Solve the following coding problem using the programming language python: Indian National Olympiad in Informatics 2013 N people live in Sequence Land. Instead of a name, each person is identified by a sequence of integers, called his or her id. Each id is a sequence with no duplicate elements. Two people are said to b...
```python def check_relative(i,j): if is_relative[i]:return if len(land[i].intersection(land[j]))>=k: is_relative[i]=True for ii in range(n): check_relative(ii,i) n,k=map(int,input().split()) land=[] is_relative=[True]+[False]*(n-1) for i in range(n): p,*q=input().split() la...
{ "language": "python", "test_cases": [ { "input": "4 2\n4 4 6 7 84 8 3 0 42 0 106 1 2 3 0 5 8\n", "output": "3\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/INOIPRAC/problems/INOI1302" }
vfc_5410
apps
verifiable_code
2000
Solve the following coding problem using the programming language python: Codefortia is a small island country located somewhere in the West Pacific. It consists of $n$ settlements connected by $m$ bidirectional gravel roads. Curiously enough, the beliefs of the inhabitants require the time needed to pass each road to...
```python import heapq n,m,a,b=map(int,input().split()) graph={i:[] for i in range(n)} for i in range(m): u,v,w=map(int,input().split()) graph[u-1].append((v-1,w)) graph[v-1].append((u-1,w)) components=[-1]*n comp=-1 for i in range(n): if components[i]==-1: comp+=1 components[i]=comp ...
{ "language": "python", "test_cases": [ { "input": "5 5 20 25\n1 2 25\n2 3 25\n3 4 20\n4 5 20\n5 1 20\n", "output": "0 25 60 40 20\n", "type": "stdin_stdout" }, { "input": "6 7 13 22\n1 2 13\n2 3 13\n1 4 22\n3 4 13\n4 5 13\n5 6 13\n6 1 13\n", "output": "0 13 26 39 26 13\n",...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/1149/D" }
vfc_5546
apps
verifiable_code
2001
Solve the following coding problem using the programming language python: Pikachu had an array with him. He wrote down all the non-empty subsequences of the array on paper. Note that an array of size n has 2^{n} - 1 non-empty subsequences in it. Pikachu being mischievous as he always is, removed all the subsequences...
```python X, D = list(map(int, input().split())) cn = 1 add0 = 1 if (X&1) else 0 ans = [] for i in range(30,0,-1): if not (X & (1<<i)): continue ans += [cn]*i add0 += 1 cn += D for i in range(add0): ans.append(cn) cn += D print(len(ans)) print(' '.join(map(str, ans))) ```
{ "language": "python", "test_cases": [ { "input": "10 5\n", "output": "6\n1 1 1 7 13 19 ", "type": "stdin_stdout" }, { "input": "4 2\n", "output": "3\n1 1 4 ", "type": "stdin_stdout" }, { "input": "4 1\n", "output": "3\n1 1 3 ", "type": "std...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/960/C" }
vfc_5550
apps
verifiable_code
2002
Solve the following coding problem using the programming language python: Vasya and Kolya play a game with a string, using the following rules. Initially, Kolya creates a string s, consisting of small English letters, and uniformly at random chooses an integer k from a segment [0, len(s) - 1]. He tells Vasya this stri...
```python str = input() l = len(str) a = [0] * (2 * l) pos = [[] for i in range(26)] for i, c in enumerate(str): t = ord(c) - ord('a') a[i] = t a[i + l] = t pos[t].append(i) ans = 0 for c in range(26): cur = 0 for k in range(1, l): cnt = [0] * 26 for i in pos[c]: cnt[...
{ "language": "python", "test_cases": [ { "input": "technocup\n", "output": "1.000000000000000\n", "type": "stdin_stdout" }, { "input": "tictictactac\n", "output": "0.333333333333333\n", "type": "stdin_stdout" }, { "input": "bbaabaabbb\n", "output"...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/930/B" }
vfc_5554
apps
verifiable_code
2003
Solve the following coding problem using the programming language python: In the evenings Donkey would join Shrek to look at the stars. They would sit on a log, sipping tea and they would watch the starry sky. The sky hung above the roof, right behind the chimney. Shrek's stars were to the right of the chimney and the...
```python from bisect import * from math import * n = int(input()) a, b, c, d = list(map(int,input().replace('/',' ').split())) alpha = atan2(c,d) - atan2(a,b) tan_alpha = tan(alpha) lis = [] for x,y in sorted((y/tan_alpha - x,y) for x,y in [ (x,y) for x,y in [(b*x + a*y,-a*x + b*y) for x, y in [list(map(int,input(...
{ "language": "python", "test_cases": [ { "input": "15\n1/3 2/1\n3 1\n6 2\n4 2\n2 5\n4 5\n6 6\n3 4\n1 6\n2 1\n7 4\n9 3\n5 3\n1 3\n15 5\n12 4\n", "output": "4\n", "type": "stdin_stdout" }, { "input": "15\n2/1 2/0\n3 1\n6 2\n9 3\n12 4\n15 5\n2 1\n4 2\n5 3\n7 4\n1 3\n3 4\n2 5\n4 5\n...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/249/D" }
vfc_5558
apps
verifiable_code
2004
Solve the following coding problem using the programming language python: The Little Elephant has an integer a, written in the binary notation. He wants to write this number on a piece of paper. To make sure that the number a fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from n...
```python x = input () flag = 0 s = 0 for each_item in x: if each_item == '0': if flag == 0: flag = 1; continue else: print (each_item, end = '') else: if (s == len (x) - 1 and flag == 0) : continue print (each_item, end = '') ...
{ "language": "python", "test_cases": [ { "input": "101\n", "output": "11\n", "type": "stdin_stdout" }, { "input": "110010\n", "output": "11010\n", "type": "stdin_stdout" }, { "input": "10000\n", "output": "1000\n", "type": "stdin_stdout" ...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/258/A" }
vfc_5562
apps
verifiable_code
2005
Solve the following coding problem using the programming language python: Toad Rash has a binary string $s$. A binary string consists only of zeros and ones. Let $n$ be the length of $s$. Rash needs to find the number of such pairs of integers $l$, $r$ that $1 \leq l \leq r \leq n$ and there is at least one pair of ...
```python X = [[], ['0', '1'], ['00', '01', '10', '11'], ['001', '010', '011', '100', '101', '110'], ['0010', '0011', '0100', '0101', '0110', '1001', '1010', '1011', '1100', '1101'], ['00100', '00101', '00110', '01001', '01011', '01100', '01101', '10010', '10011', '10100', '10110', '11001', '11010', '11011'], ['001001'...
{ "language": "python", "test_cases": [ { "input": "010101\n", "output": "3\n", "type": "stdin_stdout" }, { "input": "11001100\n", "output": "0\n", "type": "stdin_stdout" }, { "input": "0\n", "output": "0\n", "type": "stdin_stdout" }, ...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/1168/B" }
vfc_5566
apps
verifiable_code
2006
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") ```
{ "language": "python", "test_cases": [ { "input": "2\n2 3\n", "output": "Alice\n", "type": "stdin_stdout" }, { "input": "2\n5 3\n", "output": "Alice\n", "type": "stdin_stdout" }, { "input": "3\n5 6 7\n", "output": "Bob\n", "type": "stdin_std...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/346/A" }
vfc_5570
apps
verifiable_code
2007
Solve the following coding problem using the programming language python: Mad scientist Mike does not use slow hard disks. His modification of a hard drive has not one, but n different heads that can read data in parallel. When viewed from the side, Mike's hard drive is an endless array of tracks. The tracks of the a...
```python import sys from itertools import * from math import * def solve(): n, m = map(int, input().split()) h = list(map(int, input().split())) p = list(map(int, input().split())) ss, ll = 0, int(2.2e10) while ss < ll: avg = (ss + ll) // 2 works = True hidx = 0 pidx...
{ "language": "python", "test_cases": [ { "input": "3 4\n2 5 6\n1 3 6 8\n", "output": "2\n", "type": "stdin_stdout" }, { "input": "3 3\n1 2 3\n1 2 3\n", "output": "0\n", "type": "stdin_stdout" }, { "input": "1 2\n165\n142 200\n", "output": "81\n", ...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/343/C" }
vfc_5574
apps
verifiable_code
2008
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...
{ "language": "python", "test_cases": [ { "input": "4\n0 0 1 1\n", "output": "0\n0 0 1 1\n", "type": "stdin_stdout" }, { "input": "5\n0 1 0 1 0\n", "output": "2\n0 0 0 0 0\n", "type": "stdin_stdout" }, { "input": "3\n1 0 0\n", "output": "0\n1 0 0\n...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/590/A" }
vfc_5578
apps
verifiable_code
2009
Solve the following coding problem using the programming language python: For a vector $\vec{v} = (x, y)$, define $|v| = \sqrt{x^2 + y^2}$. Allen had a bit too much to drink at the bar, which is at the origin. There are $n$ vectors $\vec{v_1}, \vec{v_2}, \cdots, \vec{v_n}$. Allen will make $n$ moves. As Allen's sense...
```python import random n = int(input()) v = [] a = [] for i in range(n): a.append(i) for _ in range(0, n): x, y = list(map(int, input().split())) v.append([x, y, x*x+y*y]) while 1>0: x = 0 y = 0 ans = [0]*n random.shuffle(a) for i in range(n): if (x+v[a[i]][0])**2+(y+v[a[i]][...
{ "language": "python", "test_cases": [ { "input": "3\n999999 0\n0 999999\n999999 0\n", "output": "1 1 -1 \n", "type": "stdin_stdout" }, { "input": "1\n-824590 246031\n", "output": "1 \n", "type": "stdin_stdout" }, { "input": "8\n-67761 603277\n640586 -3...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/995/C" }
vfc_5582
apps
verifiable_code
2010
Solve the following coding problem using the programming language python: Limak is a little bear who loves to play. Today he is playing by destroying block towers. He built n towers in a row. The i-th tower is made of h_{i} identical blocks. For clarification see picture for the first sample. Limak will repeat the fo...
```python x = int(input()) y = list(map(int, input().split(' '))) y[0] = 1 y[x-1] = 1 z = y[:] for i in range(1, x): z[i] = min(z[i], z[i-1] + 1) w = y[:] for i in range(x-2, -1, -1): w[i] = min(w[i], w[i+1]+1) ans = 0 for i in range(x): ans = max(ans, min(z[i], w[i])) print(ans) ```
{ "language": "python", "test_cases": [ { "input": "6\n2 1 4 6 2 2\n", "output": "3\n", "type": "stdin_stdout" }, { "input": "7\n3 3 3 1 3 3 3\n", "output": "2\n", "type": "stdin_stdout" }, { "input": "7\n5128 5672 5805 5452 5882 5567 5032\n", "out...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/573/B" }
vfc_5586
apps
verifiable_code
2011
Solve the following coding problem using the programming language python: Eighth-grader Vova is on duty today in the class. After classes, he went into the office to wash the board, and found on it the number n. He asked what is this number and the teacher of mathematics Inna Petrovna answered Vova that n is the answe...
```python n=int(input()) q=[] for i in range(max(0,n-100),n+1): j=i res=i while j: res+=j%10 j//=10 if res==n: q.append(i) print(len(q)) for i in q: print(i) ```
{ "language": "python", "test_cases": [ { "input": "21\n", "output": "1\n15\n", "type": "stdin_stdout" }, { "input": "20\n", "output": "0\n", "type": "stdin_stdout" }, { "input": "1\n", "output": "0\n", "type": "stdin_stdout" }, { ...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/875/A" }
vfc_5590
apps
verifiable_code
2012
Solve the following coding problem using the programming language python: A permutation p of size n is the sequence p_1, p_2, ..., p_{n}, consisting of n distinct integers, each of them is from 1 to n (1 ≤ p_{i} ≤ n). A lucky permutation is such permutation p, that any integer i (1 ≤ i ≤ n) meets this condition p_{p}...
```python n = int(input()) if n%4 > 1: print(-1) else: a = [n+1>>1]*n for i in range(n//4): j = i*2 a[j], a[j+1], a[-2-j], a[-1-j] = j+2, n-j, j+1, n-1-j print(' '.join(map(str, a))) ```
{ "language": "python", "test_cases": [ { "input": "1\n", "output": "1 \n", "type": "stdin_stdout" }, { "input": "2\n", "output": "-1\n", "type": "stdin_stdout" }, { "input": "4\n", "output": "2 4 1 3 \n", "type": "stdin_stdout" }, { ...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/286/A" }
vfc_5594
apps
verifiable_code
2013
Solve the following coding problem using the programming language python: You are given a non-empty string s consisting of lowercase English letters. You have to pick exactly one non-empty substring of s and shift all its letters 'z' $\rightarrow$ 'y' $\rightarrow$ 'x' $\rightarrow \ldots \rightarrow$ 'b' $\rightarrow...
```python #!/usr/bin/env python3 import re try: while True: s = input() m = re.search(r"[^a]", s) if m is None: print(s[:-1], end="z\n") else: j = s.find('a', m.end()) if j == -1: j = len(s) print(end=s[:m.start()]) ...
{ "language": "python", "test_cases": [ { "input": "codeforces\n", "output": "bncdenqbdr\n", "type": "stdin_stdout" }, { "input": "abacaba\n", "output": "aaacaba\n", "type": "stdin_stdout" }, { "input": "babbbabaababbaa\n", "output": "aabbbabaababb...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/708/A" }
vfc_5598
apps
verifiable_code
2014
Solve the following coding problem using the programming language python: After a wonderful evening in the restaurant the time to go home came. Leha as a true gentlemen suggested Noora to give her a lift. Certainly the girl agreed with pleasure. Suddenly one problem appeared: Leha cannot find his car on a huge parking...
```python mod = 1000000007 def sum(x, y, k, add) : if k < add : return 0 up = x + add if up > k : up = k add = add + 1 return y * ( ( (add + up) * (up - add + 1) // 2 ) % mod ) % mod def solve(x, y, k, add = 0) : if x == 0 or y == 0 : return 0 if x > y : x, y = y, x pw = 1 ...
{ "language": "python", "test_cases": [ { "input": "4\n1 1 1 1 1\n3 2 5 4 5\n1 1 5 5 10000\n1 4 2 5 2\n", "output": "1\n13\n93\n0\n", "type": "stdin_stdout" }, { "input": "10\n3 7 4 10 7\n6 1 7 10 18\n9 6 10 8 3\n1 8 3 10 3\n10 4 10 5 19\n8 9 9 10 10\n10 1 10 5 4\n8 1 9 4 18\n6 3...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/809/C" }
vfc_5602
apps
verifiable_code
2015
Solve the following coding problem using the programming language python: Gennady is one of the best child dentists in Berland. Today n children got an appointment with him, they lined up in front of his office. All children love to cry loudly at the reception at the dentist. We enumerate the children with integers f...
```python import sys n = int(input()) v = [ list(map(int, input().split())) for i in range(n)] res = [] for i in range(n): if v[i][2] >= 0: res.append(i + 1) dec = 0 for j in range(i + 1, n): if v[j][2] >= 0: if v[i][0] > 0: v[j][2] -= v[i][0] v[i][0] -= 1 v[j][2] -= dec if v[j][2] <...
{ "language": "python", "test_cases": [ { "input": "5\n4 2 2\n4 1 2\n5 2 4\n3 3 5\n5 1 2\n", "output": "2\n1 3 ", "type": "stdin_stdout" }, { "input": "5\n4 5 1\n5 3 9\n4 1 2\n2 1 8\n4 1 9\n", "output": "4\n1 2 4 5 ", "type": "stdin_stdout" }, { "input":...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/585/A" }
vfc_5606
apps
verifiable_code
2016
Solve the following coding problem using the programming language python: Alex decided to go on a touristic trip over the country. For simplicity let's assume that the country has $n$ cities and $m$ bidirectional roads connecting them. Alex lives in city $s$ and initially located in it. To compare different cities Al...
```python import sys input = sys.stdin.readline n,m=list(map(int,input().split())) W=[0]+list(map(int,input().split())) E=[tuple(map(int,input().split())) for i in range(m)] S=int(input()) ELIST=[[] for i in range(n+1)] EW=[0]*(n+1) for x,y in E: ELIST[x].append(y) ELIST[y].append(x) EW[x]+=1 EW[y]+...
{ "language": "python", "test_cases": [ { "input": "5 7\n2 2 8 6 9\n1 2\n1 3\n2 4\n3 2\n4 5\n2 5\n1 5\n2\n", "output": "27\n", "type": "stdin_stdout" }, { "input": "10 12\n1 7 1 9 3 3 6 30 1 10\n1 2\n1 3\n3 5\n5 7\n2 3\n5 4\n6 9\n4 6\n3 7\n6 8\n9 4\n9 10\n6\n", "output": "6...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/1220/E" }
vfc_5610
apps
verifiable_code
2017
Solve the following coding problem using the programming language python: Allen is hosting a formal dinner party. $2n$ people come to the event in $n$ pairs (couples). After a night of fun, Allen wants to line everyone up for a final picture. The $2n$ people line up, but Allen doesn't like the ordering. Allen prefers ...
```python n = int(input()) xs = [int(x) for x in input().split()] seen = {} res = 0 while xs: j = xs.index(xs[0], 1) res += j - 1 xs = xs[1:j] + xs[j+1:] print(res) ```
{ "language": "python", "test_cases": [ { "input": "4\n1 1 2 3 3 2 4 4\n", "output": "2\n", "type": "stdin_stdout" }, { "input": "3\n1 1 2 2 3 3\n", "output": "0\n", "type": "stdin_stdout" }, { "input": "3\n3 1 2 3 1 2\n", "output": "3\n", "t...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/995/B" }
vfc_5614
apps
verifiable_code
2018
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[...
{ "language": "python", "test_cases": [ { "input": "3 2\n1 2 3\n", "output": "1\n1 2 2 \n", "type": "stdin_stdout" }, { "input": "5 10\n0 1 0 2 1\n", "output": "3\n2 2 2 2 2 \n", "type": "stdin_stdout" }, { "input": "9 0\n11 22 33 44 55 66 77 88 99\n", ...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/238/B" }
vfc_5618
apps
verifiable_code
2019
Solve the following coding problem using the programming language python: One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other n - 1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the super...
```python n = int(input()) a = list(map(int, input().split())) r = n-2 for d in a: r += d print(max(max(a), r//(n-1))) ```
{ "language": "python", "test_cases": [ { "input": "3\n3 2 2\n", "output": "4\n", "type": "stdin_stdout" }, { "input": "4\n2 2 2 2\n", "output": "3\n", "type": "stdin_stdout" }, { "input": "7\n9 7 7 8 8 7 8\n", "output": "9\n", "type": "stdin...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/348/A" }
vfc_5622
apps
verifiable_code
2020
Solve the following coding problem using the programming language python: Ivan wants to make a necklace as a present to his beloved girl. A necklace is a cyclic sequence of beads of different colors. Ivan says that necklace is beautiful relative to the cut point between two adjacent beads, if the chain of beads remain...
```python import math #import fractions from functools import reduce n = int(input()) odd = -1 beads = [int(x) for x in input().split()] for i in range(n): if beads[i]%2: if odd >= 0: print(0) print(''.join(chr(ord('a') + i)*beads[i] for i in range(n))) break els...
{ "language": "python", "test_cases": [ { "input": "3\n4 2 1\n", "output": "1\naabcbaa\n", "type": "stdin_stdout" }, { "input": "1\n4\n", "output": "4\naaaa\n", "type": "stdin_stdout" }, { "input": "2\n1 1\n", "output": "0\nab\n", "type": "st...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/613/C" }
vfc_5626
apps
verifiable_code
2021
Solve the following coding problem using the programming language python: Recently, Pari and Arya did some research about NP-Hard problems and they found the minimum vertex cover problem very interesting. Suppose the graph G is given. Subset A of its vertices is called a vertex cover of this graph, if for each edge u...
```python def main(): n, m = list(map(int, input().split())) l = [[] for _ in range(n + 1)] for _ in range(m): u, v = list(map(int, input().split())) l[u].append(v) l[v].append(u) res = [0] * (n + 1) for u, x in enumerate(res): if not x: x, nxt = -1, [u] ...
{ "language": "python", "test_cases": [ { "input": "4 2\n1 2\n2 3\n", "output": "1\n2 \n2\n1 3 \n", "type": "stdin_stdout" }, { "input": "3 3\n1 2\n2 3\n1 3\n", "output": "-1\n", "type": "stdin_stdout" }, { "input": "5 7\n3 2\n5 4\n3 4\n1 3\n1 5\n1 4\n2 ...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/687/A" }
vfc_5630
apps
verifiable_code
2023
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() ```
{ "language": "python", "test_cases": [ { "input": "4\n", "output": "3 4 1 2\n", "type": "stdin_stdout" }, { "input": "2\n", "output": "2 1\n", "type": "stdin_stdout" }, { "input": "1\n", "output": "1\n", "type": "stdin_stdout" }, { ...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/1017/C" }
vfc_5638
apps
verifiable_code
2025
Solve the following coding problem using the programming language python: Vasya and Petya are playing a simple game. Vasya thought of number x between 1 and n, and Petya tries to guess the number. Petya can ask questions like: "Is the unknown number divisible by number y?". The game is played by the following rules:...
```python def main(): n = int(input()) result = [] for i in range(2, n + 1): j = 2 while j * j <= i: if i % j == 0: break j += 1 else: j = i while j <= n: result.append(j) j *= i ...
{ "language": "python", "test_cases": [ { "input": "4\n", "output": "3\n2 4 3 \n", "type": "stdin_stdout" }, { "input": "6\n", "output": "4\n2 4 3 5 \n", "type": "stdin_stdout" }, { "input": "1\n", "output": "0\n\n", "type": "stdin_stdout" ...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/576/A" }
vfc_5646
apps
verifiable_code
2026
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: ...
{ "language": "python", "test_cases": [ { "input": "3 1000\n1000\n0 0\n0 1\n0 3\n", "output": "2000\n", "type": "stdin_stdout" }, { "input": "3 1000\n1000\n1 0\n1 1\n1 2\n", "output": "1000\n", "type": "stdin_stdout" }, { "input": "5 1421\n896 448 727\n-...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/301/B" }
vfc_5650
apps
verifiable_code
2028
Solve the following coding problem using the programming language python: Reading books is one of Sasha's passions. Once while he was reading one book, he became acquainted with an unusual character. The character told about himself like that: "Many are my names in many countries. Mithrandir among the Elves, Tharkûn t...
```python def solve(s): n = len(s) for i in range(n): s2 = s[i:] + s[:i] # print(s2) if s != s2 and s2[::-1] == s2: return 1 for i in range( (n // 2) + 1, n): if s[i] != s[0]: return 2 # print(s[i]) return "Impossible" s = input() print...
{ "language": "python", "test_cases": [ { "input": "nolon\n", "output": "2\n", "type": "stdin_stdout" }, { "input": "otto\n", "output": "1\n", "type": "stdin_stdout" }, { "input": "qqqq\n", "output": "Impossible\n", "type": "stdin_stdout" ...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/1109/B" }
vfc_5658
apps
verifiable_code
2029
Solve the following coding problem using the programming language python: You are given integer $n$. You have to arrange numbers from $1$ to $2n$, using each of them exactly once, on the circle, so that the following condition would be satisfied: For every $n$ consecutive numbers on the circle write their sum on the ...
```python def main(): n = int(input()) ans = [0] * (2 * n) for i in range(n): a = 2 * i + 1 b = 2 * i + 2 if i & 1: ans[i] = a ans[i + n] = b else: ans[i] = b ans[i + n] = a ans *= 2 curr = sum(ans[:n]) mi = curr ...
{ "language": "python", "test_cases": [ { "input": "3\n", "output": "YES\n1 4 5 2 3 6 ", "type": "stdin_stdout" }, { "input": "4\n", "output": "NO", "type": "stdin_stdout" }, { "input": "1\n", "output": "YES\n1 2 ", "type": "stdin_stdout" ...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/1205/A" }
vfc_5662
apps
verifiable_code
2030
Solve the following coding problem using the programming language python: A group of n cities is connected by a network of roads. There is an undirected road between every pair of cities, so there are $\frac{n \cdot(n - 1)}{2}$ roads in total. It takes exactly y seconds to traverse any single road. A spanning tree is...
```python from collections import defaultdict from collections import deque from functools import reduce n, x, y = [int(x) for x in input().split()] E = defaultdict(set) for i in range(n-1): u, v = [int(x) for x in input().split()] E[u].add(v) E[v].add(u) if x > y: for v in E: if len(E[v]) == n...
{ "language": "python", "test_cases": [ { "input": "5 2 3\n1 2\n1 3\n3 4\n5 3\n", "output": "9\n", "type": "stdin_stdout" }, { "input": "5 3 2\n1 2\n1 3\n3 4\n5 3\n", "output": "8\n", "type": "stdin_stdout" }, { "input": "50 23129 410924\n18 28\n17 23\n2...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/618/D" }
vfc_5666
apps
verifiable_code
2031
Solve the following coding problem using the programming language python: Dreamoon likes coloring cells very much. There is a row of $n$ cells. Initially, all cells are empty (don't contain any color). Cells are numbered from $1$ to $n$. You are given an integer $m$ and $m$ integers $l_1, l_2, \ldots, l_m$ ($1 \le l...
```python def main(): import sys input = sys.stdin.readline N, M = list(map(int, input().split())) L = list(map(int, input().split())) if sum(L) < N: print(-1) return ans = [0] * M left = N for i in range(M-1, -1, -1): if left - L[i] >= i: ans[i] = ...
{ "language": "python", "test_cases": [ { "input": "5 3\n3 2 2\n", "output": "1 2 4\n", "type": "stdin_stdout" }, { "input": "10 1\n1\n", "output": "-1\n", "type": "stdin_stdout" }, { "input": "1 1\n1\n", "output": "1\n", "type": "stdin_stdou...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/1329/A" }
vfc_5670
apps
verifiable_code
2033
Solve the following coding problem using the programming language python: Sasha is taking part in a programming competition. In one of the problems she should check if some rooted trees are isomorphic or not. She has never seen this problem before, but, being an experienced participant, she guessed that she should mat...
```python h = int(input()) a = list(map(int, input().split())) w, q = [], [] p = r = 0 for i in a: for j in range(i): w.append(r) q.append(r - (j and p > 1)) p = i r += i if w == q: print('perfect') else: print('ambiguous') print(*w) print(*q) ```
{ "language": "python", "test_cases": [ { "input": "2\n1 1 1\n", "output": "perfect\n", "type": "stdin_stdout" }, { "input": "2\n1 2 2\n", "output": "ambiguous\n0 1 1 3 3\n0 1 1 3 2\n", "type": "stdin_stdout" }, { "input": "10\n1 1 1 1 1 1 1 1 1 1 1\n", ...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/901/A" }
vfc_5678
apps
verifiable_code
2034
Solve the following coding problem using the programming language python: You are given $n$ points on the plane. The polygon formed from all the $n$ points is strictly convex, that is, the polygon is convex, and there are no three collinear points (i.e. lying in the same straight line). The points are numbered from $1...
```python import sys input = sys.stdin.readline n = int(input()) x = [] y = [] for i in range(n): xi, yi = map(int, input().split()) x.append(xi) y.append(yi) min_x = min(x) max_x = max(x) min_y = min(y) max_y = max(y) answer = 0 for i in range(n): dx = max(max_x - x[i], x[i] - min_x) dy = max(max_...
{ "language": "python", "test_cases": [ { "input": "4\n2 4\n4 3\n3 0\n1 3\n", "output": "12 14 ", "type": "stdin_stdout" }, { "input": "3\n0 0\n0 2\n2 0\n", "output": "8 ", "type": "stdin_stdout" }, { "input": "8\n0 3\n2 2\n3 0\n2 -2\n0 -3\n-2 -2\n-3 0\n...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/1074/C" }
vfc_5682
apps
verifiable_code
2035
Solve the following coding problem using the programming language python: This is the easy version of the problem. The only difference between easy and hard versions is the constraint of $m$. You can make hacks only if both versions are solved. Chiori loves dolls and now she is going to decorate her bedroom![Image]  ...
```python MOD = 998244353 BOUND = 19 n, m = list(map(int, input().split())) l = list(map(int,input().split())) basis = [] for p in range(m-1,-1,-1): p2 = pow(2,p) nex = -1 for i in range(n): if l[i] >= p2: nex = l[i] break if nex != -1: basis.append(nex) ...
{ "language": "python", "test_cases": [ { "input": "4 4\n3 5 8 14\n", "output": "2 2 6 6 0 ", "type": "stdin_stdout" }, { "input": "6 7\n11 45 14 9 19 81\n", "output": "1 2 11 20 15 10 5 0 ", "type": "stdin_stdout" }, { "input": "1 0\n0\n", "output...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/1336/E1" }
vfc_5686
apps
verifiable_code
2036
Solve the following coding problem using the programming language python: The biggest event of the year – Cota 2 world championship "The Innernational" is right around the corner. $2^n$ teams will compete in a double-elimination format (please, carefully read problem statement even if you know what is it) to identify ...
```python import sys input = sys.stdin.readline n,k=list(map(int,input().split())) if k==0: print(0) return A=sorted(map(int,input().split())) # DP[UL][n][left] # [left*pow(2,n),left*pow(2,n)+pow(2,n))の間のチームで, # ファンのチームが # UL=0: upperでもlowerでも勝ち残っている # UL=1: upperでのみ勝ち残っている # UL=2: lowerでのみ勝ち残っている # ときの、そこまで...
{ "language": "python", "test_cases": [ { "input": "3 1\n6\n", "output": "6\n", "type": "stdin_stdout" }, { "input": "3 3\n1 7 8\n", "output": "11\n", "type": "stdin_stdout" }, { "input": "3 4\n1 3 5 7\n", "output": "14\n", "type": "stdin_std...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/1314/B" }
vfc_5690
apps
verifiable_code
2037
Solve the following coding problem using the programming language python: You work in a big office. It is a 9 floor building with an elevator that can accommodate up to 4 people. It is your responsibility to manage this elevator. Today you are late, so there are queues on some floors already. For each person you know...
```python # python3 import sys from collections import namedtuple def readline(): return list(map(int, input().split())) def readlines(): for line in sys.stdin.readlines(): yield list(map(int, line.split())) class State(namedtuple('State', 'payload time floor')): def hook(self, pivot, a, b): ...
{ "language": "python", "test_cases": [ { "input": "2\n3 5\n5 3\n", "output": "10", "type": "stdin_stdout" }, { "input": "2\n5 3\n3 5\n", "output": "12", "type": "stdin_stdout" }, { "input": "9\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 1\n", "outp...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/983/C" }
vfc_5694
apps
verifiable_code
2038
Solve the following coding problem using the programming language python: Logical quantifiers are very useful tools for expressing claims about a set. For this problem, let's focus on the set of real numbers specifically. The set of real numbers includes zero and negatives. There are two kinds of quantifiers: universa...
```python import sys n, m = [int(x) for x in input().split()] adj_for = [[] for _ in range(n)] adj_back = [[] for _ in range(n)] for _ in range(m): a, b = [int(x) for x in sys.stdin.readline().split()] a -= 1 b -= 1 adj_for[a].append(b) adj_back[b].append(a) lens = [len(adj_back[i]) for i in ra...
{ "language": "python", "test_cases": [ { "input": "2 1\n1 2\n", "output": "1\nAE\n", "type": "stdin_stdout" }, { "input": "4 3\n1 2\n2 3\n3 1\n", "output": "-1\n", "type": "stdin_stdout" }, { "input": "3 2\n1 3\n2 3\n", "output": "2\nAAE\n", ...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/1344/C" }
vfc_5698
apps
verifiable_code
2039
Solve the following coding problem using the programming language python: Toad Zitz has an array of integers, each integer is between $0$ and $m-1$ inclusive. The integers are $a_1, a_2, \ldots, a_n$. In one operation Zitz can choose an integer $k$ and $k$ indices $i_1, i_2, \ldots, i_k$ such that $1 \leq i_1 < i_2 <...
```python import sys input = sys.stdin.readline n,m=list(map(int,input().split())) A=list(map(int,input().split())) MIN=0 MAX=m while MIN!=MAX: x=(MIN+MAX)//2 #print(x,MIN,MAX) #print() M=0 for a in A: #print(a,M) if a<=M and a+x>=M: continue elif a>M and a+x...
{ "language": "python", "test_cases": [ { "input": "5 3\n0 0 0 1 2\n", "output": "0\n", "type": "stdin_stdout" }, { "input": "5 7\n0 6 1 3 2\n", "output": "1\n", "type": "stdin_stdout" }, { "input": "10 10\n5 0 5 9 4 6 4 5 0 0\n", "output": "6\n", ...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/1168/A" }
vfc_5702
apps
verifiable_code
2040
Solve the following coding problem using the programming language python: Igor the analyst has adopted n little bunnies. As we all know, bunnies love carrots. Thus, Igor has bought a carrot to be shared between his bunnies. Igor wants to treat all the bunnies equally, and thus he wants to cut the carrot into n pieces ...
```python n, h = map(int,input().split()) unit = h*h/n for i in range(1,n): print((unit*i)**0.5, end=' ') ```
{ "language": "python", "test_cases": [ { "input": "3 2\n", "output": "1.154700538379 1.632993161855\n", "type": "stdin_stdout" }, { "input": "2 100000\n", "output": "70710.678118654752\n", "type": "stdin_stdout" }, { "input": "2 1\n", "output": "0...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/794/B" }
vfc_5706
apps
verifiable_code
2042
Solve the following coding problem using the programming language python: Vasya's telephone contains n photos. Photo number 1 is currently opened on the phone. It is allowed to move left and right to the adjacent photo by swiping finger over the screen. If you swipe left from the first photo, you reach photo n. Simila...
```python def main(): n, a, b, t = list(map(int, input().split())) a1 = a + 1 b += a1 l, res = [b if c == "w" else a1 for c in input()], [] l[0] = x = l[0] - a if t <= x: print(int(t == x)) return f = res.append for dr in 0, 1: if dr: l[1:] = l[-1:-n:-...
{ "language": "python", "test_cases": [ { "input": "4 2 3 10\nwwhw\n", "output": "2\n", "type": "stdin_stdout" }, { "input": "5 2 4 13\nhhwhh\n", "output": "4\n", "type": "stdin_stdout" }, { "input": "5 2 4 1000\nhhwhh\n", "output": "5\n", "t...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/650/B" }
vfc_5714
apps
verifiable_code
2043
Solve the following coding problem using the programming language python: Doubly linked list is one of the fundamental data structures. A doubly linked list is a sequence of elements, each containing information about the previous and the next elements of the list. In this problem all lists have linear structure. I.e....
```python n = int(input()) arr = [] for i in range(n): l,r = map(int, input().split()) arr.append([l,r]) lts = [] for i in range(n): if arr[i][0] == 0: l = i j = i while arr[j][1] != 0: j = arr[j][1] - 1 r = j lts.append([l,r]) for i in range(1, len(...
{ "language": "python", "test_cases": [ { "input": "7\n4 7\n5 0\n0 0\n6 1\n0 2\n0 4\n1 0\n", "output": "4 7\n5 6\n0 5\n6 1\n3 2\n2 4\n1 0\n", "type": "stdin_stdout" }, { "input": "2\n2 0\n0 1\n", "output": "2 0\n0 1\n", "type": "stdin_stdout" }, { "input...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/847/A" }
vfc_5718
apps
verifiable_code
2044
Solve the following coding problem using the programming language python: Arkady needs your help again! This time he decided to build his own high-speed Internet exchange point. It should consist of n nodes connected with minimum possible number of wires into one network (a wire directly connects two nodes). Exactly k...
```python from sys import stdin, stdout n,k = list(map(int,stdin.readline().rstrip().split())) print(2+(n-2)//k+(n-3)//k) connectionsList = [] # Leaf node is 1. Make this node have connections to k children for i in range(k): connectionsList.append((str(1),str(i+2))) for i in range(k+2,n+1): connectionsLis...
{ "language": "python", "test_cases": [ { "input": "3 2\n", "output": "2\n1 2\n2 3\n", "type": "stdin_stdout" }, { "input": "5 3\n", "output": "3\n1 2\n2 3\n3 4\n3 5\n", "type": "stdin_stdout" }, { "input": "4 2\n", "output": "3\n1 2\n2 3\n3 4\n", ...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/827/B" }
vfc_5722
apps
verifiable_code
2045
Solve the following coding problem using the programming language python: Hooray! Berl II, the king of Berland is making a knight tournament. The king has already sent the message to all knights in the kingdom and they in turn agreed to participate in this grand event. As for you, you're just a simple peasant. There'...
```python n, m = map(int, input().split()) p, d = [0] * (n + 2), [0] * (n + 2) for i in range(m): l, r, x = map(int, input().split()) while l < x: if d[l]: k = d[l] d[l] = x - l l += k else: d[l], p[l] = x - l, x l += 1 l += 1 r...
{ "language": "python", "test_cases": [ { "input": "4 3\n1 2 1\n1 3 3\n1 4 4\n", "output": "3 1 4 0 ", "type": "stdin_stdout" }, { "input": "8 4\n3 5 4\n3 7 6\n2 8 8\n1 8 1\n", "output": "0 8 4 6 4 8 6 1 ", "type": "stdin_stdout" }, { "input": "2 1\n1 2 ...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/356/A" }
vfc_5726
apps
verifiable_code
2046
Solve the following coding problem using the programming language python: Farmer John has just given the cows a program to play with! The program contains two integer variables, x and y, and performs the following operations on a sequence a_1, a_2, ..., a_{n} of positive integers: Initially, x = 1 and y = 0. If, afte...
```python n = int(input()) t = [0, 0] + list(map(int, input().split())) a, b = [0] * (n + 1), [0] * (n + 1) a[1] = b[1] = -1 def f(s, a, b, l): nonlocal t l.reverse() j, n = 0, len(l) while True: s += t[l[j]] a[l[j]] = s j += 1 if j == n: return s += t[l[j]] ...
{ "language": "python", "test_cases": [ { "input": "4\n2 4 1\n", "output": "3\n6\n8\n", "type": "stdin_stdout" }, { "input": "3\n1 2\n", "output": "-1\n-1\n", "type": "stdin_stdout" }, { "input": "5\n2 2 1 3\n", "output": "3\n-1\n-1\n-1\n", "...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/283/B" }
vfc_5730
apps
verifiable_code
2047
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...
{ "language": "python", "test_cases": [ { "input": "4 5\n1 2 0 4\n1 2 0 4\n5 0 0 3\n0 5 0 3\n", "output": "6\n1 1 1\n2 1 2\n4 1 4\n3 4 4\n5 3 2\n5 4 2\n", "type": "stdin_stdout" }, { "input": "1 2\n1\n2\n1\n2\n", "output": "-1\n", "type": "stdin_stdout" }, { ...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/995/A" }
vfc_5734
apps
verifiable_code
2048
Solve the following coding problem using the programming language python: We all know the impressive story of Robin Hood. Robin Hood uses his archery skills and his wits to steal the money from rich, and return it to the poor. There are n citizens in Kekoland, each person has c_{i} coins. Each day, Robin Hood will ta...
```python import sys n, k = map(int, sys.stdin.readline().split()) nums = list(map(int, sys.stdin.readline().split())) total = sum(nums) avg = int(total / n) def check1(nums, target, K): for x in nums: if K < 0: return False if x < target: K -= target - x return K >= 0 ...
{ "language": "python", "test_cases": [ { "input": "4 1\n1 1 4 2\n", "output": "2\n", "type": "stdin_stdout" }, { "input": "3 1\n2 2 2\n", "output": "0\n", "type": "stdin_stdout" }, { "input": "10 20\n6 4 7 10 4 5 5 3 7 10\n", "output": "1\n", ...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/671/B" }
vfc_5738
apps
verifiable_code
2049
Solve the following coding problem using the programming language python: Bob recently read about bitwise operations used in computers: AND, OR and XOR. He have studied their properties and invented a new game. Initially, Bob chooses integer m, bit depth of the game, which means that all numbers in the game will cons...
```python import sys def calc(b0, b1, q): if q == 0: return b0 ^ b1 if q == 1: return b0 | b1 if q == 2: return b0 & b1 n, m = list(map(int,sys.stdin.readline().split())) arr1 = {} opt = ['XOR', 'OR', 'AND'] arr2 = [] for j in range(n): a, b = list(map(str,sys.stdin.readline().sp...
{ "language": "python", "test_cases": [ { "input": "3 3\na := 101\nb := 011\nc := ? XOR b\n", "output": "011\n100\n", "type": "stdin_stdout" }, { "input": "5 1\na := 1\nbb := 0\ncx := ? OR a\nd := ? XOR ?\ne := d AND bb\n", "output": "0\n0\n", "type": "stdin_stdout" ...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/778/B" }
vfc_5742
apps
verifiable_code
2050
Solve the following coding problem using the programming language python: Andrew, Fedor and Alex are inventive guys. Now they invent the game with strings for two players. Given a group of n non-empty strings. During the game two players build the word together, initially the word is empty. The players move in turns....
```python """ Codeforces Contest 260 Div 1 Problem B Author : chaotic_iak Language: Python 3.3.4 """ def main(): n,k = read() s = set() for i in range(n): s.add(read(0)) s = list(s) s.sort() s = treeify(s) res = solve(s) if res == 0: # neither: second player win print("Second"...
{ "language": "python", "test_cases": [ { "input": "2 3\na\nb\n", "output": "First\n", "type": "stdin_stdout" }, { "input": "3 1\na\nb\nc\n", "output": "First\n", "type": "stdin_stdout" }, { "input": "1 2\nab\n", "output": "Second\n", "type":...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/455/B" }
vfc_5746
apps
verifiable_code
2051
Solve the following coding problem using the programming language python: Helen works in Metropolis airport. She is responsible for creating a departure schedule. There are n flights that must depart today, the i-th of them is planned to depart at the i-th minute of the day. Metropolis airport is the main transport h...
```python from heapq import heappush,heappop,heapify n,k=map(int,input().split()) *l,=map(int,input().split()) q=[(-l[i],i)for i in range(k)];heapify(q) a=[0]*n s=0 for i in range(k,n): heappush(q,(-l[i],i)) x,j=heappop(q) s-=x*(i-j) a[j]=i+1 for i in range(n,n+k): x,j=heappop(q) s-=x*(i-j) ...
{ "language": "python", "test_cases": [ { "input": "5 2\n4 2 1 10 2\n", "output": "20\n3 6 7 4 5 \n", "type": "stdin_stdout" }, { "input": "3 2\n3 1 2\n", "output": "11\n3 5 4 \n", "type": "stdin_stdout" }, { "input": "5 5\n5 5 9 100 3\n", "output"...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/853/A" }
vfc_5750
apps
verifiable_code
2052
Solve the following coding problem using the programming language python: Gerald plays the following game. He has a checkered field of size n × n cells, where m various cells are banned. Before the game, he has to put a few chips on some border (but not corner) board cells. Then for n - 1 minutes, Gerald every minute ...
```python n, m = list(map(int, input().split())) used = [1] * 2 * n for i in range(m): x, y = list(map(int, input().split())) used[x - 1] = used[n + y - 1] = 0 if n % 2 and used[n // 2]: used[n // 2 + n] = 0 res = sum(used) for i in [0, n - 1, n, 2 * n - 1]: res -= used[i] print(res) ```
{ "language": "python", "test_cases": [ { "input": "3 1\n2 2\n", "output": "0\n", "type": "stdin_stdout" }, { "input": "3 0\n", "output": "1\n", "type": "stdin_stdout" }, { "input": "4 3\n3 1\n3 2\n3 3\n", "output": "1\n", "type": "stdin_stdo...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/333/B" }
vfc_5754
apps
verifiable_code
2053
Solve the following coding problem using the programming language python: $n$ boys and $m$ girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from $1$ to $n$ and all girls are numbered with integers from $1$ to $m$. For all $1 \leq i...
```python n,m=map(int,input().split()) b=list(map(int,input().split())) g=list(map(int,input().split())) if max(b)>min(g): print(-1) else: maxi=0 maxi2=0 for guy in b: if guy>maxi: maxi2,maxi=maxi,guy elif guy>maxi2: maxi2=guy sumi=m*sum(b)+sum(g)-m*maxi+maxi-...
{ "language": "python", "test_cases": [ { "input": "3 2\n1 2 1\n3 4\n", "output": "12", "type": "stdin_stdout" }, { "input": "2 2\n0 1\n1 0\n", "output": "-1", "type": "stdin_stdout" }, { "input": "2 3\n1 0\n1 1 2\n", "output": "4", "type": "...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/1158/A" }
vfc_5758
apps
verifiable_code
2054
Solve the following coding problem using the programming language python: Each New Year Timofey and his friends cut down a tree of n vertices and bring it home. After that they paint all the n its vertices, so that the i-th vertex gets color c_{i}. Now it's time for Timofey birthday, and his mother asked him to remov...
```python def main(): n = int(input()) edges = [] for _ in range(n - 1): u, v = list(map(int, input().split())) u -= 1 v -= 1 edges.append((u, v)) colors = list(map(int, input().split())) suspect = [(u, v) for (u, v) in edges if colors[u] != colors[v]] if len(su...
{ "language": "python", "test_cases": [ { "input": "4\n1 2\n2 3\n3 4\n1 2 1 1\n", "output": "YES\n2", "type": "stdin_stdout" }, { "input": "3\n1 2\n2 3\n1 2 3\n", "output": "YES\n2", "type": "stdin_stdout" }, { "input": "4\n1 2\n2 3\n3 4\n1 2 1 2\n", ...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/763/A" }
vfc_5762
apps
verifiable_code
2055
Solve the following coding problem using the programming language python: Andrew and Eugene are playing a game. Initially, Andrew has string s, consisting of digits. Eugene sends Andrew multiple queries of type "d_{i} → t_{i}", that means "replace all digits d_{i} in string s with substrings equal to t_{i}". For examp...
```python MOD = 10**9+7 s = input() n = int(input()) qs = [['',s]]+[input().split('->') for i in range(n)] ds = {} for i in range(10): ds[str(i)] = (10,i) for i in range(n,-1,-1): out = 0 mul = 1 for d in qs[i][1]: out = (out * ds[d][0] + ds[d][1]) % MOD mul = (mul * ds[d][0]) % MOD ...
{ "language": "python", "test_cases": [ { "input": "123123\n1\n2->00\n", "output": "10031003\n", "type": "stdin_stdout" }, { "input": "123123\n1\n3->\n", "output": "1212\n", "type": "stdin_stdout" }, { "input": "222\n2\n2->0\n0->7\n", "output": "77...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/464/C" }
vfc_5766
apps
verifiable_code
2056
Solve the following coding problem using the programming language python: You are given two binary strings $a$ and $b$ of the same length. You can perform the following two operations on the string $a$: Swap any two bits at indices $i$ and $j$ respectively ($1 \le i, j \le n$), the cost of this operation is $|i - j...
```python # import collections, atexit, math, sys, bisect sys.setrecursionlimit(1000000) def getIntList(): return list(map(int, input().split())) try : #raise ModuleNotFoundError import numpy def dprint(*args, **kwargs): print(*args, **kwargs, file=sys.stderr) dprint('debug mode...
{ "language": "python", "test_cases": [ { "input": "3\n100\n001\n", "output": "2\n", "type": "stdin_stdout" }, { "input": "4\n0101\n0011\n", "output": "1\n", "type": "stdin_stdout" }, { "input": "8\n10001001\n01101110\n", "output": "4\n", "ty...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/1037/C" }
vfc_5770
apps
verifiable_code
2057
Solve the following coding problem using the programming language python: We have a string of letters 'a' and 'b'. We want to perform some operations on it. On each step we choose one of substrings "ab" in the string and replace it with the string "bba". If we have no "ab" as a substring, our job is done. Print the mi...
```python import sys #sys.stdin=open("data.txt") input=sys.stdin.readline # so the ending sequence is b...ba...a # find length of ending sequence extra=0 need=0 for ch in input().strip(): if ch=='a': need=(need*2+1)%1000000007 else: extra=(extra+need)%1000000007 print(extra) ```
{ "language": "python", "test_cases": [ { "input": "ab\n", "output": "1\n", "type": "stdin_stdout" }, { "input": "aab\n", "output": "3\n", "type": "stdin_stdout" }, { "input": "aaaaabaabababaaaaaba\n", "output": "17307\n", "type": "stdin_stdo...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/804/B" }
vfc_5774
apps
verifiable_code
2058
Solve the following coding problem using the programming language python: Sonya was unable to think of a story for this problem, so here comes the formal description. You are given the array containing n positive integers. At one turn you can pick any element and increase or decrease it by 1. The goal is the make the...
```python import heapq n = int(input()) d = list(map(int,input().split())) pq = [-d[0]] heapq.heapify(pq) ans = 0 for i in range(1,n): temp = i - d[i] heapq.heappush(pq,temp) if heapq.nsmallest(1,pq)[0] < temp: ans += temp - heapq.nsmallest(1,pq)[0] heapq.heappushpop(pq,temp) print(ans) ```
{ "language": "python", "test_cases": [ { "input": "7\n2 1 5 11 5 9 11\n", "output": "9\n", "type": "stdin_stdout" }, { "input": "5\n5 4 3 2 1\n", "output": "12\n", "type": "stdin_stdout" }, { "input": "2\n1 1000\n", "output": "0\n", "type": ...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/713/C" }
vfc_5778
apps
verifiable_code
2059
Solve the following coding problem using the programming language python: Jeff's friends know full well that the boy likes to get sequences and arrays for his birthday. Thus, Jeff got sequence p_1, p_2, ..., p_{n} for his birthday. Jeff hates inversions in sequences. An inversion in sequence a_1, a_2, ..., a_{n} is a...
```python n = int(input()) inp = input() seq = inp.split(' ') seq = [ abs(int(x)) for x in seq ] Max = max(seq) nxt = [0] * n cnt = [0] * n pos = [n] * (Max+1) for i in range(n-1, -1, -1): nxt[i] = pos[seq[i]] pos[seq[i]] = i for i in range(0, Max+1): j = pos[i] while(j<n): front = sum(cnt[0:j])...
{ "language": "python", "test_cases": [ { "input": "2\n2 1\n", "output": "0\n", "type": "stdin_stdout" }, { "input": "9\n-2 0 -1 0 -1 2 1 0 -1\n", "output": "6\n", "type": "stdin_stdout" }, { "input": "9\n0 0 1 1 0 0 1 0 1\n", "output": "5\n", ...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/351/E" }
vfc_5782
apps
verifiable_code
2060
Solve the following coding problem using the programming language python: Evlampiy has found one more cool application to process photos. However the application has certain limitations. Each photo i has a contrast v_{i}. In order for the processing to be truly of high quality, the application must receive at least k...
```python def f(m): nonlocal dp, sdp l = 0 for i in range(n): while l < n and v[l] < v[i] - m: l += 1 if l - 1 > i - k: dp[i] = False else: dp[i] = (sdp[i - k + 1] != sdp[l - 1]) sdp[i + 1] = sdp[i] + (1 if dp[i] else 0) return dp[n - 1...
{ "language": "python", "test_cases": [ { "input": "5 2\n50 110 130 40 120\n", "output": "20\n", "type": "stdin_stdout" }, { "input": "4 1\n2 3 4 1\n", "output": "0\n", "type": "stdin_stdout" }, { "input": "1 1\n4\n", "output": "0\n", "type":...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/883/I" }
vfc_5786
apps
verifiable_code
2063
Solve the following coding problem using the programming language python: The "BerCorp" company has got n employees. These employees can use m approved official languages for the formal correspondence. The languages are numbered with integers from 1 to m. For each employee we have the list of languages, which he knows...
```python rd = lambda: list(map(int, input().split())) def root(x): if f[x]!=x: f[x] = root(f[x]) return f[x] n, m = rd() N = list(range(n)) f = list(N) lang = [0]*n for i in N: lang[i] = set(rd()[1:]) for i in N: for j in N[:i]: rj = root(j) if lang[rj].intersection(lang[i]): f[rj] = i lang...
{ "language": "python", "test_cases": [ { "input": "5 5\n1 2\n2 2 3\n2 3 4\n2 4 5\n1 5\n", "output": "0\n", "type": "stdin_stdout" }, { "input": "8 7\n0\n3 1 2 3\n1 1\n2 5 4\n2 6 7\n1 3\n2 7 4\n1 1\n", "output": "2\n", "type": "stdin_stdout" }, { "input"...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/277/A" }
vfc_5798
apps
verifiable_code
2064
Solve the following coding problem using the programming language python: 3R2 as DJ Mashiro - Happiness Breeze Ice - DJ Mashiro is dead or alive NEKO#ΦωΦ has just got a new maze game on her PC! The game's main puzzle is a maze, in the forms of a $2 \times n$ rectangle grid. NEKO's task is to lead a Nekomimi girl fro...
```python import sys readline = sys.stdin.readline N, Q = list(map(int, readline().split())) state = [[False]*(N+2) for _ in range(2)] cnt = 0 Ans = [None]*Q for qu in range(Q): r, c = list(map(int, readline().split())) r -= 1 c -= 1 state[r][c] = not state[r][c] res = state[r-1][c-1] + state[r-1...
{ "language": "python", "test_cases": [ { "input": "5 5\n2 3\n1 4\n2 4\n2 3\n1 4\n", "output": "Yes\nNo\nNo\nNo\nYes\n", "type": "stdin_stdout" }, { "input": "2 2\n2 1\n1 2\n", "output": "Yes\nNo\n", "type": "stdin_stdout" }, { "input": "2 4\n2 1\n1 2\n1...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/1292/A" }
vfc_5802
apps
verifiable_code
2065
Solve the following coding problem using the programming language python: Andrewid the Android is a galaxy-famous detective. He is now investigating the case of vandalism at the exhibition of contemporary art. The main exhibit is a construction of n matryoshka dolls that can be nested one into another. The matryoshka...
```python n, k = [int(c) for c in input().split()] a = [] for i in range(k): ak = [int(c) for c in input().split()] a.append(ak[1:]) total = k - 1 for ak in a: if ak[0] == 1: j = 1 while j <= len(ak) - 1: if ak[j] != ak[j-1] + 1: break j += 1 ...
{ "language": "python", "test_cases": [ { "input": "3 2\n2 1 2\n1 3\n", "output": "1\n", "type": "stdin_stdout" }, { "input": "7 3\n3 1 3 7\n2 2 5\n2 4 6\n", "output": "10\n", "type": "stdin_stdout" }, { "input": "1 1\n1 1\n", "output": "0\n", ...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/555/A" }
vfc_5806
apps
verifiable_code
2066
Solve the following coding problem using the programming language python: In the official contest this problem has a different statement, for which jury's solution was working incorrectly, and for this reason it was excluded from the contest. This mistake have been fixed and the current given problem statement and mod...
```python import os import random import sys from typing import List, Dict class Int: def __init__(self, val): self.val = val def get(self): return self.val + 111 class Unique: def __init__(self): self.s = set() def add(self, val : int): self.s.add(val) def __co...
{ "language": "python", "test_cases": [ { "input": "6\n0 1 3 7 15 31\n", "output": "7\n", "type": "stdin_stdout" }, { "input": "2\n73 37\n", "output": "36\n", "type": "stdin_stdout" }, { "input": "2\n0 1000000000\n", "output": "1000000000\n", ...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/594/A" }
vfc_5810
apps
verifiable_code
2067
Solve the following coding problem using the programming language python: One Big Software Company has n employees numbered from 1 to n. The director is assigned number 1. Every employee of the company except the director has exactly one immediate superior. The director, of course, doesn't have a superior. We will ca...
```python n = int(input()) t = [list(map(int, input().split())) for q in range(n)] t[0][0] = 0 n += 1 u = [-1e7] * n v = [0] * n for i, (j, a) in list(enumerate(t, 1))[::-1]: u[i] = max(u[i], v[i] + a) v[j], u[j] = max(v[j] + v[i], u[j] + u[i]), max(v[j] + u[i], u[j] + v[i]) print(u[1]) ```
{ "language": "python", "test_cases": [ { "input": "7\n-1 3\n1 2\n1 1\n1 4\n4 5\n4 3\n5 2\n", "output": "17\n", "type": "stdin_stdout" }, { "input": "1\n-1 42\n", "output": "42\n", "type": "stdin_stdout" }, { "input": "2\n-1 3\n1 2\n", "output": "3...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/533/B" }
vfc_5814
apps
verifiable_code
2068
Solve the following coding problem using the programming language python: The Fair Nut is going to travel to the Tree Country, in which there are $n$ cities. Most of the land of this country is covered by forest. Furthermore, the local road system forms a tree (connected graph without cycles). Nut wants to rent a car ...
```python import sys readline = sys.stdin.readline from collections import Counter def getpar(Edge, p): N = len(Edge) par = [0]*N par[0] = -1 par[p] -1 stack = [p] visited = set([p]) while stack: vn = stack.pop() for vf in Edge[vn]: if vf in visited: ...
{ "language": "python", "test_cases": [ { "input": "3\n1 3 3\n1 2 2\n1 3 2\n", "output": "3\n", "type": "stdin_stdout" }, { "input": "5\n6 3 2 5 0\n1 2 10\n2 3 3\n2 4 1\n1 5 1\n", "output": "7\n", "type": "stdin_stdout" }, { "input": "1\n42\n", "ou...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/1083/A" }
vfc_5818
apps
verifiable_code
2069
Solve the following coding problem using the programming language python: You are given an array $a$ of $n$ integers. You want to make all elements of $a$ equal to zero by doing the following operation exactly three times: Select a segment, for each number in this segment we can add a multiple of $len$ to it, where ...
```python n=int(input()) L=list(map(int,input().split())) if n==1: print(1,1) print(0) print(1,1) print(0) print(1,1) print(-L[0]) else: print(1,n-1) for i in range(n-1):print(L[i]*(n-1),end=' ') print() print(n,n) print(-L[n-1]) print(1,n) for i in range(n-1):print(-...
{ "language": "python", "test_cases": [ { "input": "4\n1 3 2 4\n", "output": "1 4\n-4 -12 -8 0\n1 3\n3 9 6 \n4 4\n-4\n", "type": "stdin_stdout" }, { "input": "1\n34688642\n", "output": "1 1\n-34688642\n1 1\n0\n1 1\n0\n", "type": "stdin_stdout" }, { "inpu...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/1396/A" }
vfc_5822
apps
verifiable_code
2070
Solve the following coding problem using the programming language python: Karen has just arrived at school, and she has a math test today! [Image] The test is about basic addition and subtraction. Unfortunately, the teachers were too busy writing tasks for Codeforces rounds, and had no time to make an actual test. S...
```python #!/usr/bin/env pypy3 import math def make_nCr_mod(max_n=2*10**5 + 100, mod=10**9 + 7): fact, inv_fact = [0] * (max_n + 1), [0] * (max_n + 1) fact[0] = 1 for i in range(max_n): fact[i + 1] = fact[i] * (i + 1) % mod inv_fact[-1] = pow(fact[-1], mod - 2, mod) for i in reversed(rang...
{ "language": "python", "test_cases": [ { "input": "5\n3 6 9 12 15\n", "output": "36\n", "type": "stdin_stdout" }, { "input": "4\n3 7 5 2\n", "output": "1000000006\n", "type": "stdin_stdout" }, { "input": "1\n1\n", "output": "1\n", "type": "s...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/815/B" }
vfc_5826