source
stringclasses
4 values
task_type
stringclasses
1 value
in_source_id
stringlengths
0
138
problem_statement
stringlengths
219
13.2k
gold_standard_solution
stringlengths
0
413k
problem_id
stringlengths
5
10
metadata
dict
verification_info
dict
apps
verifiable_code
1586
Solve the following coding problem using the programming language python: Indian National Olympiad in Informatics 2012 You are given a table with 2 rows and N columns. Each cell has an integer in it. The score of such a table is defined as follows: for each column, consider the sum of the two numbers in the column; th...
```python # cook your dish here try: n=int(input()) list_n = list(range(1,n+1)) list_n_flag=[] fix_arr = list(map(int,input().split())) k=1 res_list=[] fin_list=[] list_n_flag = list_n[k:] + list_n[:k] res_list = [list_n[i] + fix_arr[i] for i in range(len(fix_arr)...
vfc_5186
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/INOIPRAC/problems/INOI1202", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "and output corresponding to the example above.\nSample input\n4\n7 1 6 2\nSample output\n9 10 10 11\nNote: Your program should not print anything other than what is specified in the output format. Please remove all diagnostic prin...
apps
verifiable_code
1587
Solve the following coding problem using the programming language python: Chef likes problems on geometry a lot. Please help him to solve one such problem. Find all possible triangles with integer sides which has the radius of inscribed circle (also known as incircle) equal to R. Two triangles are said to be different...
```python r=int(input()) c=0 L=[] for i in range(2*r+1,2*r**2+2): for j in range(i,r**4+2*r**2+2): for k in range(j,r**4+3*r**2+2): if 4*(i+j+k)*r**2==(i+j-k)*(i+k-j)*(j+k-i): L.append([i,j,k]) c+=1 print(c) for i in range(c): for j in range(3): print(L[i][j], end=' ') print() ```
vfc_5190
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/LTIME40/problems/LTM40CD", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n", "output": "5\n5 12 13\n6 8 10\n6 25 29\n7 15 20\n9 10 17\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
1588
Solve the following coding problem using the programming language python: Lucy had recently learned the game, called Natural Numbers. The rules of the game are really simple. There are N players. At the same time, every player says one natural number. Let's call the number said by the i-th player Ai. The person with t...
```python try: t = int(input()) while t: t -= 1 n = int(input()) arr = [] obj = {} for i in range(n): x,y = input().split() y = int(y) arr.append([x, y]) if y in obj: obj[y].append(x) else: obj[y] = [x] a...
vfc_5194
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/NUMBERS", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n5\nKouta 1\nYuka 1\nMayu 3\nLucy 2\nNana 5\n2\nLucy 2\nNana 2\n\n\n", "output": "Lucy\nNobody wins.\n", "type": "stdin_stdout" } ] }
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,'%....
vfc_5198
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/SITC2020/problems/WESUM", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n33 100 77 42 12 -1\n", "output": "4 38.91\n", "type": "stdin_stdout" } ] }
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") ```
vfc_5202
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/COTS2020/problems/CDCUR01", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n1 2 1\n", "output": "Yes\n", "type": "stdin_stdout" } ] }
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())]) ```
vfc_5206
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/DMNT2016/problems/POFACT", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n1\n2\n3\n4\n", "output": "1\n2\n6\n24\n", "type": "stdin_stdout" } ] }
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...
vfc_5210
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/SIMGAM", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n2\n4 5 2 3 4\n2 1 6\n", "output": "8\n", "type": "stdin_stdout" } ] }
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 ...
vfc_5214
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/FLOW005", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1200\n500\n242\n", "output": "12\n5\n7\n", "type": "stdin_stdout" } ] }
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) ```
vfc_5218
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/UWCOI20/problems/UWCOI20D", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n2\n10\n01\n4\n1000\n0010\n0100\n0001\n", "output": "3\n8\n", "type": "stdin_stdout" } ] }
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...
vfc_5222
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/DEC15/problems/CHEFFILT", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "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" } ] }
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=...
vfc_5226
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/QFUN2020/problems/CRCLJUMP", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n4 5\n3 5\n", "output": "0 0\n1 1\n", "type": "stdin_stdout" } ] }
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: ...
vfc_5230
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/GUESSNUM", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n3 35\n5 50\n4 65\n", "output": "1\n10\n0\n3\n13 15 16\n", "type": "stdin_stdout" } ] }
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...
vfc_5234
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/COMT2020/problems/HELPTECH", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "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...
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(...
vfc_5238
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/CHEFTRVL", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n3\n1 2\n1 3\n1 2 3\n", "output": "2\n", "type": "stdin_stdout" } ] }
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...
vfc_5242
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/CCWC2018/problems/WFORT", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "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" } ] }
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) ```
vfc_5246
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/MGAME", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n4 4\n3 4\n", "output": "9\n13\n", "type": "stdin_stdout" } ] }
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...
vfc_5250
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/BTCH2020/problems/AKACHOCO", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "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" } ] }
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: ...
vfc_5254
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/644/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "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",...
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...
vfc_5258
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1225/E", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 1\n.\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 3\n...\n..R\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "inp...
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) ```
vfc_5262
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/476/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 1\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 2\n", "output": "8\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 1\n",...
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) ```
vfc_5266
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/805/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "19 29\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 6\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "39 91...
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) ```
vfc_5270
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/894/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "QAQAQYSYIOIWIN\n", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "QAQQQZZYNOIWIN\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, ...
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: ...
vfc_5336
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/CDMT2012/problems/SYNOL", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "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...
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...
vfc_5340
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1438/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1\n2\n4\n", "output": "4 \n4 4 \n4 4 4 4 \n", "type": "stdin_stdout" } ] }
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....
vfc_5344
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1331/G", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "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" } ] }
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...
vfc_5350
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/POINTS", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "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...
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), ...
vfc_5354
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/JUNE16/problems/CHNWGM", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "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" } ] }
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 = [] ...
vfc_5358
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/INOIPRAC/problems/INOI1501", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "52 3 2 3 13 4 4 6 3\n", "output": "18\n", "type": "stdin_stdout" } ] }
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])...
vfc_5362
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/DPAIRS", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 2\n10 1 100\n4 3\n\n", "output": "2 1\n0 0\n1 0\n0 1\n", "type": "stdin_stdout" } ] }
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 : ...
vfc_5366
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/PCR12020/problems/RAAVANCH", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "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" } ] }
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; } ```
vfc_5370
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/BUGS2020/problems/IOI1804", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n24 1\n4358 754\n305 794\n", "output": "34\n1998\n1\n", "type": "stdin_stdout" } ] }
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 ...
vfc_5374
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/TOTEM", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "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" } ] }
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="-") ```
vfc_5378
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/SSCC2020/problems/SSEC0015", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "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" } ] }
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...
vfc_5382
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/COJK2020/problems/CKOJ20D", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n10 10\n1 2\n", "output": "First\n", "type": "stdin_stdout" } ] }
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 ```
vfc_5386
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/PCR12020/problems/LAXMAN", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n1\n6\n\n", "output": "4\n5 10 5 10 5 5\n", "type": "stdin_stdout" } ] }
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...
vfc_5390
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/JULY11/problems/LOKBIL", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "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" } ] }
apps
verifiable_code
1686
Solve the following coding problem using the programming language python: Indian National Olympiad in Informatics 2014 Due to resurfacing work, all north-south traffic on the highway is being diverted through the town of Siruseri. Siruseri is a modern, planned town and the section of roads used for the diversion forms...
```python class PathNode: def __init__(self, row, col, st_x, st_y, p_count=0): self.x = row self.y = col self.pathCount = p_count def __str__(self): return str(self.x) + " | " + str(self.y) + " | " + str(self.pathCount) class GraphUtil: def __init__(self, mat, R,C, d): ...
vfc_5394
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/INOIPRAC/problems/INOI1401", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 4 2\n1 1 1 10 1 1 11 1 1 1\n", "output": "5\n", "type": "stdin_stdout" } ] }
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...
vfc_5398
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/UWCOI21F", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "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" } ] }
apps
verifiable_code
1688
Solve the following coding problem using the programming language python: Recently Chef learned about Longest Increasing Subsequence. To be precise, he means longest strictly increasing subsequence, when he talks of longest increasing subsequence. To check his understanding, he took his favorite n-digit number and fo...
```python m=int(input()) while m: m-=1 n=int(input()) t=[i for i in input().split()] print(''.join(t)) ```
vfc_5402
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/LISDIGIT", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n1 \n1\n2 \n1 2\n2 \n1 1\n4\n1 2 2 1\n7 \n1 2 2 1 3 2 4\n\n\n", "output": "7\n36\n54\n1531\n1730418\n", "type": "stdin_stdout" } ] }
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...
vfc_5406
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/CLLEXO", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n3 3\nxab\na#z\ncaa\n5 4\npyqs\nvcot\nqbiu\nlihj\nuvmz\n\n", "output": "xabza\npvcbihjz\n", "type": "stdin_stdout" } ] }
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...
vfc_5410
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/INOIPRAC/problems/INOI1302", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "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" } ] }
apps
verifiable_code
1691
Solve the following coding problem using the programming language python: Chef has a rectangular matrix A of nxm integers. Rows are numbered by integers from 1 to n from top to bottom, columns - from 1 to m from left to right. Ai, j denotes the j-th integer of the i-th row. Chef wants you to guess his matrix. To guess...
```python # CHNGSS.py import sys from random import * n,m,c = list(map(int,input().split())) arr = [[1]*m for i in range(n)]; saved = 0; for i in range(n): for j in range(m): print(1,(i+1),(i+1),(j+1),(j+1),1,25) sys.stdout.flush() a = int(input()) if a == 1 : saved += 1; arr[i][j] = randint(1,25); e...
vfc_5414
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/MARCH16/problems/CHNGSS", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 3 10\n4\n0\n3\n1\n6\n\n\n", "output": "1 1 2 1 2 1 3\n1 3 3 1 3 1 1\n1 3 3 1 3 2 2\n1 1 2 3 3 1 1\n2 3 3 1 3\n3\n2 2 1\n2 2 1\n2 2 2\n", "type": "stdin_stdout" } ] }
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 ...
vfc_5546
{ "difficulty": "competition", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1149/D", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "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" }, { "fn_name": null, "input": "6 7 13 22\n1 2 13\n2 3 13\n1 4 22\n3 4 13\n4 5 13\n5 6 13\n6 ...
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))) ```
vfc_5550
{ "difficulty": "competition", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/960/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10 5\n", "output": "6\n1 1 1 7 13 19 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 2\n", "output": "3\n1 1 4 ", "type": "stdin_stdout" }, { "fn_name": null, ...
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[...
vfc_5554
{ "difficulty": "competition", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/930/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "technocup\n", "output": "1.000000000000000\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "tictictactac\n", "output": "0.333333333333333\n", "type": "stdin_stdout" }, {...
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(...
vfc_5558
{ "difficulty": "competition", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/249/D", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "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" }, { "fn_name": null, "input": "15\n2/1 2/0\n3 1\n6 2\n9 3\n12 4\n...
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 = '') ...
vfc_5562
{ "difficulty": "competition", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/258/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "101\n", "output": "11\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "110010\n", "output": "11010\n", "type": "stdin_stdout" }, { "fn_name": null, "input": ...
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'...
vfc_5566
{ "difficulty": "competition", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1168/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "010101\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "11001100\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": ...
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") ```
vfc_5570
{ "difficulty": "competition", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/346/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n2 3\n", "output": "Alice\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n5 3\n", "output": "Alice\n", "type": "stdin_stdout" }, { "fn_name": null, "in...
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...
vfc_5574
{ "difficulty": "competition", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/343/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 4\n2 5 6\n1 3 6 8\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 3\n1 2 3\n1 2 3\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name":...
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...
vfc_5578
{ "difficulty": "competition", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/590/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n0 0 1 1\n", "output": "0\n0 0 1 1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n0 1 0 1 0\n", "output": "2\n0 0 0 0 0\n", "type": "stdin_stdout" }, { "fn_...
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]][...
vfc_5582
{ "difficulty": "competition", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/995/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n999999 0\n0 999999\n999999 0\n", "output": "1 1 -1 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n-824590 246031\n", "output": "1 \n", "type": "stdin_stdout" }, ...
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) ```
vfc_5586
{ "difficulty": "competition", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/573/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n2 1 4 6 2 2\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "7\n3 3 3 1 3 3 3\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null,...
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) ```
vfc_5590
{ "difficulty": "competition", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/875/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "21\n", "output": "1\n15\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "20\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n",...
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))) ```
vfc_5594
{ "difficulty": "competition", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/286/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n", "output": "1 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n", "output": "-1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n", ...
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()]) ...
vfc_5598
{ "difficulty": "competition", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/708/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "codeforces\n", "output": "bncdenqbdr\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "abacaba\n", "output": "aaacaba\n", "type": "stdin_stdout" }, { "fn_name": nul...
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 ...
vfc_5602
{ "difficulty": "competition", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/809/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "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" }, { "fn_name": null, "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...
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] <...
vfc_5606
{ "difficulty": "competition", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/585/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "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" }, { "fn_name": null, "input": "5\n4 5 1\n5 3 9\n4 1 2\n2 1 8\n4 1 9\n", "output": "4\n1 2 4 5 ", "typ...
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]+...
vfc_5610
{ "difficulty": "competition", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1220/E", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "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" }, { "fn_name": null, "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\...
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) ```
vfc_5614
{ "difficulty": "competition", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/995/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n1 1 2 3 3 2 4 4\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n1 1 2 2 3 3\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": nul...
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[...
vfc_5618
{ "difficulty": "competition", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/238/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 2\n1 2 3\n", "output": "1\n1 2 2 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 10\n0 1 0 2 1\n", "output": "3\n2 2 2 2 2 \n", "type": "stdin_stdout" }, { "...
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))) ```
vfc_5622
{ "difficulty": "competition", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/348/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n3 2 2\n", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n2 2 2 2\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "inpu...
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...
vfc_5626
{ "difficulty": "competition", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/613/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n4 2 1\n", "output": "1\naabcbaa\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n4\n", "output": "4\naaaa\n", "type": "stdin_stdout" }, { "fn_name": null, ...
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] ...
vfc_5630
{ "difficulty": "competition", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/687/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 2\n1 2\n2 3\n", "output": "1\n2 \n2\n1 3 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 3\n1 2\n2 3\n1 3\n", "output": "-1\n", "type": "stdin_stdout" }, { "...
apps
verifiable_code
2022
Solve the following coding problem using the programming language python: Students went into a class to write a test and sat in some way. The teacher thought: "Probably they sat in this order to copy works of each other. I need to rearrange them in such a way that students that were neighbors are not neighbors in a ne...
```python n,m=map(int,input().split()) if n==1and m==1:print('YES\n1') elif n==3and m==3: print('YES') print(6, 1, 8) print(7,5,3) print(2,9,4) elif n<4and m<4:print('NO') elif n==1 or m==1: t=max(n,m) a=[i for i in range(2,t+1,2)] a+=[i for i in range(1,t+1,2)] print('YES') for i in...
vfc_5634
{ "difficulty": "competition", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/906/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 4\n", "output": "YES\n5 4 7 2 \n3 6 1 8 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 1\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, ...
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() ```
vfc_5638
{ "difficulty": "competition", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1017/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n", "output": "3 4 1 2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n", "output": "2 1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n...
apps
verifiable_code
2024
Solve the following coding problem using the programming language python: You're playing a game called Osu! Here's a simplified version of it. There are n clicks in a game. For each click there are two outcomes: correct or bad. Let us denote correct as "O", bad as "X", then the whole play can be encoded as a sequence ...
```python n = input() read = input() p = [] for x in read.split(): p.append((float)(x)) v = 0.0 l = 0.0 for item in p: v = v*(1-item) + item*(v + 2*l + 1) l = (l + 1)*item print(v) ```
vfc_5642
{ "difficulty": "competition", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/235/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n0.5 0.5 0.5\n", "output": "2.750000000000000\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n0.7 0.2 0.1 0.9\n", "output": "2.489200000000000\n", "type": "stdin_stdout" ...
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 ...
vfc_5646
{ "difficulty": "competition", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/576/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n", "output": "3\n2 4 3 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n", "output": "4\n2 4 3 5 \n", "type": "stdin_stdout" }, { "fn_name": null, "in...
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: ...
vfc_5650
{ "difficulty": "competition", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/301/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 1000\n1000\n0 0\n0 1\n0 3\n", "output": "2000\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 1000\n1000\n1 0\n1 1\n1 2\n", "output": "1000\n", "type": "stdin_stdout" }...
apps
verifiable_code
2027
Solve the following coding problem using the programming language python: Squirrel Liss lived in a forest peacefully, but unexpected trouble happens. Stones fall from a mountain. Initially Squirrel Liss occupies an interval [0, 1]. Next, n stones will fall and Liss will escape from the stones. The stones are numbered ...
```python t = input() a, b = [i for i, d in enumerate(t, 1) if d == 'l'], [i for i, d in enumerate(t, 1) if d == 'r'] a.reverse() print('\n'.join(map(str, b))) print('\n'.join(map(str, a))) ```
vfc_5654
{ "difficulty": "competition", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/264/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "llrlr\n", "output": "3\n5\n4\n2\n1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "rrlll\n", "output": "1\n2\n5\n4\n3\n", "type": "stdin_stdout" }, { "fn_name": n...
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...
vfc_5658
{ "difficulty": "competition", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1109/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "nolon\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "otto\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "qqqq...
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 ...
vfc_5662
{ "difficulty": "competition", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1205/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n", "output": "YES\n1 4 5 2 3 6 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n", "output": "NO", "type": "stdin_stdout" }, { "fn_name": null, "input":...
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...
vfc_5666
{ "difficulty": "competition", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/618/D", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 2 3\n1 2\n1 3\n3 4\n5 3\n", "output": "9\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 3 2\n1 2\n1 3\n3 4\n5 3\n", "output": "8\n", "type": "stdin_stdout" }, { ...
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] = ...
vfc_5670
{ "difficulty": "competition", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1329/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 3\n3 2 2\n", "output": "1 2 4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10 1\n1\n", "output": "-1\n", "type": "stdin_stdout" }, { "fn_name": null, "...
apps
verifiable_code
2032
Solve the following coding problem using the programming language python: Vanya wants to minimize a tree. He can perform the following operation multiple times: choose a vertex v, and two disjoint (except for v) paths of equal length a_0 = v, a_1, ..., a_{k}, and b_0 = v, b_1, ..., b_{k}. Additionally, vertices a_1, ....
```python import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time sys.setrecursionlimit(10**7) inf = 10**20 mod = 10**9 + 7 def LI(): return list(map(int, input().split())) def II(): return int(input()) def LS(): return input().split() def S(): return input() def main(): n = II(...
vfc_5674
{ "difficulty": "competition", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/765/E", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n1 2\n2 3\n2 4\n4 5\n1 6\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "7\n1 2\n1 3\n3 4\n1 5\n5 6\n6 7\n", "output": "-1\n", "type": "stdin_stdout" }, ...
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) ```
vfc_5678
{ "difficulty": "competition", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/901/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n1 1 1\n", "output": "perfect\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1 2 2\n", "output": "ambiguous\n0 1 1 3 3\n0 1 1 3 2\n", "type": "stdin_stdout" }, { ...
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_...
vfc_5682
{ "difficulty": "competition", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1074/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n2 4\n4 3\n3 0\n1 3\n", "output": "12 14 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n0 0\n0 2\n2 0\n", "output": "8 ", "type": "stdin_stdout" }, { "fn_nam...
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) ...
vfc_5686
{ "difficulty": "competition", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1336/E1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 4\n3 5 8 14\n", "output": "2 2 6 6 0 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 7\n11 45 14 9 19 81\n", "output": "1 2 11 20 15 10 5 0 ", "type": "stdin_stdout" }, ...
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でのみ勝ち残っている # ときの、そこまで...
vfc_5690
{ "difficulty": "competition", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1314/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 1\n6\n", "output": "6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 3\n1 7 8\n", "output": "11\n", "type": "stdin_stdout" }, { "fn_name": null, "input...
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): ...
vfc_5694
{ "difficulty": "competition", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/983/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n3 5\n5 3\n", "output": "10", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n5 3\n3 5\n", "output": "12", "type": "stdin_stdout" }, { "fn_name": null, "in...
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...
vfc_5698
{ "difficulty": "competition", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1344/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 1\n1 2\n", "output": "1\nAE\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 3\n1 2\n2 3\n3 1\n", "output": "-1\n", "type": "stdin_stdout" }, { "fn_name": null...
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...
vfc_5702
{ "difficulty": "competition", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1168/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 3\n0 0 0 1 2\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 7\n0 6 1 3 2\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, ...
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=' ') ```
vfc_5706
{ "difficulty": "competition", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/794/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 2\n", "output": "1.154700538379 1.632993161855\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 100000\n", "output": "70710.678118654752\n", "type": "stdin_stdout" }, ...
apps
verifiable_code
2041
Solve the following coding problem using the programming language python: The life goes up and down, just like nice sequences. Sequence t_1, t_2, ..., t_{n} is called nice if the following two conditions are satisfied: t_{i} < t_{i} + 1 for each odd i < n; t_{i} > t_{i} + 1 for each even i < n. For example, seque...
```python def main(): n, l = int(input()), list(map(int, input().split())) if not (n & 1): l.append(0) l.append(150001) i, b, c, fails0, fails1 = 0, 0, 150001, [], [] try: while True: a, b, c = b, c, l[i] if a >= b or b <= c: if len(fails0) + l...
vfc_5710
{ "difficulty": "competition", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/653/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n2 8 4 7 7\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n200 150 100 50\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, ...
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:-...
vfc_5714
{ "difficulty": "competition", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/650/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 2 3 10\nwwhw\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 2 4 13\nhhwhh\n", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, ...
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(...
vfc_5718
{ "difficulty": "competition", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/847/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "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" }, { "fn_name": null, "input": "2\n2 0\n0 1\n", "output": "2 0\n0 1\n", "t...
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...
vfc_5722
{ "difficulty": "competition", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/827/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 2\n", "output": "2\n1 2\n2 3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 3\n", "output": "3\n1 2\n2 3\n3 4\n3 5\n", "type": "stdin_stdout" }, { "fn_name":...
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...
vfc_5726
{ "difficulty": "competition", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/356/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 3\n1 2 1\n1 3 3\n1 4 4\n", "output": "3 1 4 0 ", "type": "stdin_stdout" }, { "fn_name": null, "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_...
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]] ...
vfc_5730
{ "difficulty": "competition", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/283/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n2 4 1\n", "output": "3\n6\n8\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n1 2\n", "output": "-1\n-1\n", "type": "stdin_stdout" }, { "fn_name": null, ...
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...
vfc_5734
{ "difficulty": "competition", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/995/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "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" }, { "fn_name": null, "input": "1 2\n1\n2\n1\n2\n", "output": "-1\n...
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 ...
vfc_5738
{ "difficulty": "competition", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/671/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 1\n1 1 4 2\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 1\n2 2 2\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "...
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...
vfc_5742
{ "difficulty": "competition", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/778/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 3\na := 101\nb := 011\nc := ? XOR b\n", "output": "011\n100\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 1\na := 1\nbb := 0\ncx := ? OR a\nd := ? XOR ?\ne := d AND bb\n", "out...
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"...
vfc_5746
{ "difficulty": "competition", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/455/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 3\na\nb\n", "output": "First\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 1\na\nb\nc\n", "output": "First\n", "type": "stdin_stdout" }, { "fn_name": null, ...
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) ...
vfc_5750
{ "difficulty": "competition", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/853/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 2\n4 2 1 10 2\n", "output": "20\n3 6 7 4 5 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 2\n3 1 2\n", "output": "11\n3 5 4 \n", "type": "stdin_stdout" }, { ...
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) ```
vfc_5754
{ "difficulty": "competition", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/333/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 1\n2 2\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 0\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 ...
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-...
vfc_5758
{ "difficulty": "competition", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1158/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 2\n1 2 1\n3 4\n", "output": "12", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 2\n0 1\n1 0\n", "output": "-1", "type": "stdin_stdout" }, { "fn_name": null, ...
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...
vfc_5762
{ "difficulty": "competition", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/763/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n1 2\n2 3\n3 4\n1 2 1 1\n", "output": "YES\n2", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n1 2\n2 3\n1 2 3\n", "output": "YES\n2", "type": "stdin_stdout" }, { ...
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 ...
vfc_5766
{ "difficulty": "competition", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/464/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "123123\n1\n2->00\n", "output": "10031003\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "123123\n1\n3->\n", "output": "1212\n", "type": "stdin_stdout" }, { "fn_na...
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...
vfc_5770
{ "difficulty": "competition", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1037/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n100\n001\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n0101\n0011\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, ...
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) ```
vfc_5774
{ "difficulty": "competition", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/804/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "ab\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "aab\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "aaaaabaa...