source
stringclasses
4 values
task_type
stringclasses
1 value
in_source_id
stringlengths
0
138
problem
stringlengths
219
13.2k
gold_standard_solution
stringlengths
0
413k
problem_id
stringlengths
5
10
metadata
dict
verification_info
dict
code_contests
verifiable_code
922_F. Divisibility
Solve the following coding problem using the programming language python: Imp is really pleased that you helped him. But it you solve the last problem, his gladness would raise even more. <image> Let's define <image> for some set of integers <image> as the number of pairs a, b in <image>, such that: * a is strictl...
```python import time,random,os n,k=map(int,raw_input().split(' ')) t0=time.time() while time.time()-t0<=0.8: t=range(1,n+1) g=[0]*(n+1) app=[0]*(n+1) random.shuffle(t) rm=k op=[] for a in t: su=g[a] if su>rm: continue cur=a+a while cur<=n and su<=...
vfc_68185
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "8 3\n", "output": "Yes\n3\n1 2 4 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 3\n", "output": "No\n", "type": "stdin_stdout" }, { "fn_name": null, "in...
code_contests
verifiable_code
950_B. Intercepted Message
Solve the following coding problem using the programming language python: Hacker Zhorik wants to decipher two secret messages he intercepted yesterday. Yeah message is a sequence of encrypted blocks, each of them consists of several bytes of information. Zhorik knows that each of the messages is an archive containing...
```python n,m=map(int,input().split()) x=list(map(int,input().split())) y=list(map(int,input().split())) i=0 j=0 s1=0 s2=0 count=1 while i<n and j<m: if s1==s2 and s1>0: count+=1 s1=0 s2=0 elif s1>s2 or s2==0: s2+=y[j] j+=1 elif s1<s2 or s1==0: s1+=x[i] ...
vfc_68189
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 4\n4\n1 1 1 1\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "7 6\n2 5 3 1 11 4 4\n7 8 2 4 1 8\n", "output": "3\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
978_E. Bus Video System
Solve the following coding problem using the programming language python: The busses in Berland are equipped with a video surveillance system. The system records information about changes in the number of passengers in a bus after stops. If x is the number of passengers in a bus just before the current bus stop and y...
```python l=input().split() n=int(l[0]) w=int(l[1]) l=input().split() li=[int(i) for i in l] left=0 right=w sumi=0 for i in range(n): sumi+=li[i] left=max(left,-1*sumi) right=min(right,w-sumi) print(max(right-left+1,0)) ```
vfc_68193
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 10\n2 4 1 2\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 5\n2 1 -3\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
998_D. Roman Digits
Solve the following coding problem using the programming language python: Let's introduce a number system which is based on a roman digits. There are digits I, V, X, L which correspond to the numbers 1, 5, 10 and 50 respectively. The use of other roman digits is not allowed. Numbers in this system are written as a se...
```python a = [0, 4, 10, 20, 35, 56, 83, 116, 155, 198, 244, 292] n = int(input()) if n < len(a): print (a[n]) else: print (a[11] + 49*(n-11)) ```
vfc_68197
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n", "output": "10\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
beginners-task
Solve the following coding problem using the programming language python: Our juniors has just entered in coding community. Their first task is to find the frequency of Best numbers present in given list of elements. Best numbers are numbers which are divisible by 2. SAMPLE INPUT 2 5 1 2 3 4 5 3 1 3 5 SAMPLE OUTPUT ...
```python for p in range(input()): input() l=map(int,raw_input().split()) print sum([l.count(i) for i in set(l) if i%2==0]) ```
vfc_68201
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n5\n1 2 3 4 5\n3\n1 3 5\n\nSAMPLE", "output": "2\n0\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
coins-11
Solve the following coding problem using the programming language python: In HackerLand, they have a very strange monetary system. Each gold coin has an integer number 'N' written on it. A coin N can be split into any number of coins. For example {11} can be split into {5,6} or {2,4,5} or any other possible way. You ...
```python import sys import math n = input() def is_prime(n): if n==1: return False if n % 2 == 0 and n > 2: return False for i in range(3, int(math.sqrt(n)) + 1, 2): if n % i == 0: return False return True for i in range(n): temp = input() if temp==3: ...
vfc_68205
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n11\n12345\n12421\n2444\n\nSAMPLE", "output": "2\n1\n2\n1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "30\n1\n8566\n6308\n41\n5680\n4427\n2739\n77\n6274\n3601\n7506\n8951\n5345\n3\n96...
code_contests
verifiable_code
fast-and-furious
Solve the following coding problem using the programming language python: Gandalf's army is fighting against Sauron's army and each of army has even number of N men for current war to be fought. Both of them want to finsh the war fastly . So both fought in manner that war was finished in three turns. Each tur...
```python def getfactor(n): c=0 while n != 0 : if (n%2 == 0): n=n/2 c+=1 else : return 0 return c def getval(num): if (getfactor(num) != 0 ): print getfactor(num) else: print num /2 num = int(raw_input()) for i in xrange(num): getval(int(raw_input())) ```
vfc_68209
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n2\n\nSAMPLE", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n0\n\nSAMPLE", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
hunger-games
Solve the following coding problem using the programming language python: You have reached the final level of Hunger Games and as usual a tough task awaits you. You have a circular dining table and N hungery animals.You need to place them on the table.Each animal has a hunger value. You can place the animals in any or...
```python n=input() list1=raw_input().split() list1=[int(i) for i in list1] list1.sort() #print list1 list2=[] for i in range(1,n-2): list2.append(list1[i+2]-list1[i]) list2.append(list1[2]-list1[0]) list2.append(list1[1]-list1[0]) list2.append(list1[n-1]-list1[n-2]) list2.sort() print list2[n-1] ```
vfc_68213
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n5 10 6 8\n\nSAMPLE", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1000\n667 267 985 404 106 450 714 492 765 767 989 704 824 455 158 619 381 498 363 821 720 755 43 411 66...
code_contests
verifiable_code
maintain-the-balance-2
Solve the following coding problem using the programming language python: Task is simple. You are provided with a string of curly brackets and you have to do the following - Print 0 if the brackets are balanced. Print k if it is unbalanced, where k is the number of actions performed to balance it. Print -1 if it cann...
```python from math import * T=input() while(T): T-=1 N=raw_input() count_1=0 count=0 for x in N: if(x=='{'): count_1+=1 elif(x=='}'): count_1-=1 if(count_1<0): count+=1 count_1=0 if((count+count_1)%2==0): print int(ceil(count/2.0)) + int(ceil(count_1/2.0)) else: print -1 ```
vfc_68217
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n{ { { } .\n} { .\n{ } { } { } .\n{ } { } } .\n\nSAMPLE", "output": "1\n2\n0\n-1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n{ { { } .\n} { .\n{ } { } { } .\n{ } { } } .\n\nELPMAS...
code_contests
verifiable_code
nobita-and-string-4
Solve the following coding problem using the programming language python: Doraemon gave Nobita a gadget that swaps words inside a string in the following manner : If there are W words, word 1 is swapped with word W, word 2 is swapped with word W-1 and so on. The problem is that Nobita himself cannot verify the answer...
```python t = int(raw_input()) for i in range(t): str = raw_input().split() d =[] for j in reversed(str): d.append(j) print ' '.join(d) ```
vfc_68221
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\nhello world\n\nSAMPLE", "output": "world hello\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
pythagorean-triplets-15
Solve the following coding problem using the programming language python: Pythagorean triplet (a,b,c) satisfies: You will be given an integer N. You have to count how many triplets a,b,c exist such that 1 ≤ a ≤ b ≤ c ≤ N. Input: First line contains T, the number of testcases. Each testcase consists of only one in...
```python tri = lambda m,n:(m**2-n**2, 2*m*n, m**2+n**2) def coprime(x, y): while y: x, y = y, x%y return x==1 n = input() while n: n -= 1 m = input() c, i = 0, 2 l = int(pow(m,0.5)) + 1 while i<l: j = 1 while j<i: if coprime(i,j) and (i**2+j**2)<=m and (i-j)%2: c += m/(i**2+j**2) j += 1 i ...
vfc_68225
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n5\n10\n\nSAMPLE", "output": "1\n2", "type": "stdin_stdout" }, { "fn_name": null, "input": "100\n1560\n2173\n711\n2318\n1379\n972\n4300\n7767\n7760\n8145\n9804\n6411\n9504\n7712\n31\n2854\n3316\n23...
code_contests
verifiable_code
the-job-party-1
Solve the following coding problem using the programming language python: Raman got placed in AWS. He is organizing his job party in which N number of people are invited and only K people joined the party. Ofcourse, Raman is also present in the party! K ≤ N In the party everyone starts shaking hands with everyone e...
```python t=input() while t>0: t-=1 n, k=raw_input().split(" ") n, k=int(n), int(k) print (k*(k+1))/2 ```
vfc_68233
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n1 1\n3 2\n\nSAMPLE", "output": "1\n3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1 1\n3 2\n\nSANPLE", "output": "1\n3\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
you-just-went-full-retard-never-go-full-retard-1
Solve the following coding problem using the programming language python: Mr. Retardo has lost his marbles. He's a professor, and absolutely loathes his students. And since going full retard, he asks them all sorts of useless questions. His latest obsession is prime numbers, and he gives all his a students random numb...
```python from math import sqrt def is_prime(n): if n == 2 or n == 3: return True if n < 2 or n%2 == 0: return False if n < 9: return True if n%3 == 0: return False r = int(sqrt(n)) f = 5 while f <= r: if n%f == 0: return False if n%(f+2) == 0: return False f +=6 return True for _ in xrang...
vfc_68237
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n\n2\n3\n4\n5\n6\n\nSAMPLE", "output": "YES\nYES\nNO\nYES\nNO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n\n9223372036854775807\n104729\n103141\n99999989\n9563494117\n8670344929\...
code_contests
verifiable_code
p00083 Era Name Transformation
Solve the following coding problem using the programming language python: Create a program that converts the date expressed in the Christian era to the Japanese calendar using the era name and outputs the date. The input is three integers, as shown in the example, in the order year, month, and day. Convert this as sho...
```python from bisect import bisect_left import sys name = ["pre-meiji", "meiji", "taisho", "showa", "heisei"] period = [(1868,9,7), (1912,7,29), (1926,12,24), (1989,1,7)] for t in (tuple(map(int, l.split())) for l in sys.stdin): index = bisect_left(period, t) if index: date = "{} {} {}".format(t[0]-p...
vfc_68281
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2005 9 3\n1868 12 2\n1868 9 7", "output": "heisei 17 9 3\nmeiji 1 12 2\npre-meiji", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p00215 Pachimon Creature
Solve the following coding problem using the programming language python: A popular game in a certain country, Pachimon Creature, has been remade and released in Japan. If you love games, after playing this game many times, you've come to think about how you can clear it the fastest. However, no matter how much you th...
```python from heapq import heappop,heappush # from line_profiler import LineProfiler def main(): while(True): W, H = map(int,input().split()) if not W: break B = float('inf') Bi = -1 consequNodes = [] monsterNodes = [[] for _ in range(5)] idx = 0 for ...
vfc_68285
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 5, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6 6\nS.1..4\n3..5..\n..4.1.\n4....5\n.2.32.\n5.1..G\n3 2\n...\nS.G\n0 0", "output": "2 10\nNA", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p00593 JPEG Compression
Solve the following coding problem using the programming language python: The fundamental idea in the JPEG compression algorithm is to sort coeffi- cient of given image by zigzag path and encode it. In this problem, we don’t discuss about details of the algorithm, but you are asked to make simple pro- gram. You are gi...
```python t = 1 while 1: N = int(input()) if N == 0: break print("Case %d:" % t); t += 1 M = [[0]*N for i in range(N)] c = 1 for i in range(2*N-1): for j in range(max(i-N+1, 0), min(N, i+1)): if i % 2 == 0: M[i-j][j] = "%3d" % c else: ...
vfc_68293
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n4\n0", "output": "Case 1:\n 1 2 6\n 3 5 7\n 4 8 9\nCase 2:\n 1 2 6 7\n 3 5 8 13\n 4 9 12 14\n 10 11 15 16", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n7\n0", ...
code_contests
verifiable_code
p00729 Analyzing Login/Logout Records
Solve the following coding problem using the programming language python: You have a computer literacy course in your university. In the computer system, the login/logout records of all PCs in a day are stored in a file. Although students may use two or more PCs at a time, no one can log in to a PC which has been logg...
```python def main(N, M): member = [[0] * 721 for i in range(M)] r = int(input()) for _ in range(r): t, _, m, s = map(int, input().split()) t -= 540 if s == 0: member[m - 1][t] -= 1 else: member[m - 1][t] += 1 for i in range(M): for t in ra...
vfc_68297
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 2\n10\n775 1 1 1\n780 4 2 1\n790 2 1 1\n800 2 1 0\n810 3 1 1\n820 1 1 0\n825 3 1 0\n860 1 1 1\n870 4 2 0\n880 1 1 0\n1\n780 870 1\n13 15\n12\n540 12 13 1\n600 12 13 0\n650 13 15 1\n660 12 15 1\n665 11 13 1\n670 13 15 0\n675 11 13...
code_contests
verifiable_code
p00869 Traveling Cube
Solve the following coding problem using the programming language python: On a small planet named Bandai, a landing party of the starship Tadamigawa discovered colorful cubes traveling on flat areas of the planet surface, which the landing party named beds. A cube appears at a certain position on a bed, travels on the...
```python from collections import deque import sys readline = sys.stdin.readline write = sys.stdout.write D = [ (1, 5, 2, 3, 0, 4), # 'U' (3, 1, 0, 5, 4, 2), # 'R' (4, 0, 2, 3, 5, 1), # 'D' (2, 1, 5, 0, 4, 3), # 'L' ] p_dice = (0, 0, 0, 1, 1, 2, 2, 3)*3 def rotate_dice(L, k): return (L[e] for e in...
vfc_68301
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 8, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10 5\nkkkkkwwwww\nw#wwwrwwww\nwwwwbgwwww\nkwwmcwwwkk\nkkwywwwkkk\nrgbcmy\n10 5\nkkkkkkkkkk\nk#kkkkkkkk\nkwkkkkkwwk\nkcmyrgbwwk\nkwwwwwwwwk\ncmyrgb\n10 5\nkkkkkkkkkk\nk#kkkkkkkk\nkwkkkkkwkk\nkcmyrgbwwk\nkwwwwwwwwk\ncmyrgb\n0 0", ...
code_contests
verifiable_code
p01000 Independent Research
Solve the following coding problem using the programming language python: Problem I chose creature observation as the theme of my free study during the summer vacation and purchased a creature observation kit. This creature prefers to live in a three-dimensional grid-like space. Only one animal can be placed in each...
```python class Simulator: def __init__(self, exist_mp, cnt_mp, birth_num, death_num, limit): self.exist_mp = exist_mp self.cnt_mp = cnt_mp self.birth_num = birth_num self.death_num = death_num self.birth_list = [] self.death_list = [] self.limit = limit ...
vfc_68305
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 8, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n00000\n01010\n00000\n00100\n00000\n\n00000\n01010\n00000\n01010\n00000\n\n00000\n00100\n00000\n01010\n00000\n\n00000\n01010\n00000\n00100\n00000\n\n00000\n00000\n00100\n00000\n00000\n\n1 2\n2 3 4\n4\n01110\n00100\n00100\n00100\n...
code_contests
verifiable_code
p01132 Make Purse Light
Solve the following coding problem using the programming language python: Mr. Bill is shopping at the store. There are some coins in his wallet (10-yen coins, 50-yen coins, 100-yen coins, 500-yen coins), but he is now trying to consume as much of this coin as possible. In other words, by paying for the goods with an a...
```python coin=[10, 50, 100, 500, 500000] first = True while True: bill = int(input()) if bill == 0: break; if not first: print() else: first = False posses = list(map(int, input().split())) Sumcoin= sum(coin[i] * posses[i] for i in range(4)) change = Sumcoin - ...
vfc_68309
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 8, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "160\n1 1 2 0\n160\n1 0 2 10\n0", "output": "10 1\n50 1\n100 1\n\n10 1\n100 2", "type": "stdin_stdout" }, { "fn_name": null, "input": "160\n1 1 4 0\n160\n1 0 2 10\n0", "output": "10 1\n50 1\n100...
code_contests
verifiable_code
p01271 Mirror Cave
Solve the following coding problem using the programming language python: Twin adventurers Rin and Len are searching for treasure in the Mirror Cave. The cave has two pairs of rooms, the Hall of Mirrors, and an expensive treasure lies behind the door of the room. For convenience, each of the two rooms is considered t...
```python from collections import deque, defaultdict def main(): directs = ((-1, 0, 1, 0), (1, 0, -1, 0), (0, 1, 0, 1), (0, -1, 0, -1)) while True: w, h = map(int, input().split()) if w == 0: break mp_l = ["#" * (w + 2)] mp_r = ["#" * (w + 2)] for _ in range(h): l, r = input().sp...
vfc_68313
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 8, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 5\n%#... ...#%\n.#.#. .#.#.\n.#.#. .#.#.\n.#.#. .#.#.\n...#L R#...\n3 2\n.L. .R#\n%.. .%.\n4 1\nL.%. %..R\n0 0", "output": "Yes\nYes\nNo", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 5...
code_contests
verifiable_code
p01590 Trading Ship
Solve the following coding problem using the programming language python: You are on board a trading ship as a crew. The ship is now going to pass through a strait notorious for many pirates often robbing ships. The Maritime Police has attempted to expel those pirates many times, but failed their attempts as the pira...
vfc_68321
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 8, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "", "output": "", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p01747 Snake
Solve the following coding problem using the programming language python: Sunake is in the form of a polygonal line consisting of n vertices (without self-intersection). First, Sunake-kun's i-th vertex is at (xi, yi). You can move continuously by translating or rotating, but you cannot deform (change the length of the...
```python import sys readline = sys.stdin.readline write = sys.stdout.write def dot3(p0, p1, p2): x0, y0 = p0; x1, y1 = p1; x2, y2 = p2 return (x1 - x0) * (x2 - x0) + (y1 - y0) * (y2 - y0) def cross3(p0, p1, p2): x0, y0 = p0; x1, y1 = p1; x2, y2 = p2 return (x1 - x0) * (y2 - y0) - (y1 - y0) * (x2 - x0) ...
vfc_68325
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 268435456, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n0 1\n1 1\n1 2\n2 2", "output": "Possible", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p01887 Pipe Fitter and the Fierce Dogs
Solve the following coding problem using the programming language python: Example Input 5 5 4 6 3 2 4 2 5 2 1 4 3 4 5 4 Output 6 The input will be given via stdin and the output should be printed to stdout by your code. Now solve the problem by providing the code.
```python from collections import defaultdict import sys readline = sys.stdin.readline write = sys.stdout.write def solve(): W, H, K = map(int, readline().split()) N = int(readline()) mp = defaultdict(lambda:defaultdict(int)) for i in range(N): x, y = map(int, readline().split()) if y % ...
vfc_68329
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 536870912, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 5 4\n6\n3 2\n4 2\n5 2\n1 4\n3 4\n5 4", "output": "6", "type": "stdin_stdout" }, { "fn_name": null, "input": "9 5 4\n6\n3 2\n4 2\n5 2\n1 4\n3 4\n5 4", "output": "-1\n", "type": "stdin_st...
code_contests
verifiable_code
p02024 City
Solve the following coding problem using the programming language python: J: City Santa decides to deliver a present to a city. The city has a rectangular shape divided into north-south $ H $ parcels x east-west $ W $ parcels, with one house delivering gifts to each parcel. The $ X $ th section from the north and t...
```python h, w, s, t = map(int, input().split()) if h * w % 2 == 1: if (s + t) % 2 == 1: print("No") else: print("Yes") else: print("Yes") ```
vfc_68333
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 268435456, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 5 2 3", "output": "Yes", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 9 2 3", "output": "Yes\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3...
code_contests
verifiable_code
chbllns
Solve the following coding problem using the programming language python: Today a plane was hijacked by a maniac. All the passengers of the flight are taken as hostage. Chef is also one of them. He invited one of the passengers to play a game with him. If he loses the game, he will release all the passengers, otherwis...
```python import re def processBallons(line, k): x = re.split(" ", line) r = int(x[0]); g = int(x[1]); b = int(x[2]) # return 1+min(r,k-1)+min(g,k-1)+min(b,k-1) if __name__ == '__main__': T = int(raw_input()) for t in range(T): line = raw_input() k = int(raw_input()) pri...
vfc_68349
{ "difficulty": "2", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n3 3 3\n1\n3 3 3\n2", "output": "1\n4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n6 3 3\n1\n3 3 3\n2", "output": "1\n4\n", "type": "stdin_stdout" }, { "f...
code_contests
verifiable_code
detdet
Solve the following coding problem using the programming language python: Consider a k x k matrix M with entries as the following: M(i, i) = 1 (Diagonal is all 1s) M(i, i+1) = 1 (Diagonal just above the main diagonal is all 1s) M(i, i-1) = -1 (Diagonal just below the main diagonal is all -1s) All the other elements o...
```python import time arr=[0]*(100000+6) sp=[2]*(100000+6) sp[1]=1 sp[0]=0 def generateSP(n): for i in range(3,n+1,2): #print(i) #print(arr[i]) if arr[i]==0: arr[i]=1 #print("y"+str(i)) sp[i]=i j=i while j*i<=n: if a...
vfc_68353
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n1\n2\n3\n4\n5", "output": "1\n3\n5\n8\n13", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
iitk2p01
Solve the following coding problem using the programming language python: Nowadays out little Chef is traveling a lot. While traveling, on one unlucky day, he lost into a mysterious country. Nearby people handed little Chef to the King for investigations. After proper investigation they found little Chef innocent. Lit...
```python for I in range(input()): x=raw_input().split() a=long(x[0]) b=long(x[1]) sum=0 if b==1: print a continue while a!=0: sum+=a%b a/=b print sum ```
vfc_68357
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n12 2\n18 3", "output": "2\n2", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
rrsum
Solve the following coding problem using the programming language python: Andrii is good in Math, but not in Programming. He is asking you to solve following problem: Given an integer number N and two sets of integer A and B. Let set A contain all numbers from 1 to N and set B contain all numbers from N + 1 to 2N. Mul...
```python n,q = map(int,raw_input().split()) half=(1+(n+1)+n+(2*n))/2 for i in range(0,q): inp = input() diff = abs(half-inp) if(inp<(1+(n+1)) or inp>(n+(2*n))): print "0" elif(inp==half): print(n) else: print(n-diff) ```
vfc_68365
{ "difficulty": "2", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 5\n6\n2\n9\n7\n5", "output": "2\n0\n1\n3\n1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 5\n6\n2\n9\n10\n5", "output": "2\n0\n1\n0\n1\n", "type": "stdin_stdout" }, ...
code_contests
verifiable_code
wsc
Solve the following coding problem using the programming language python: The following is an easy game that the setter of this problem played when he was 8: A boatman, a wolf, a sheep, and a cabbage are on the bank of a river. They have a small boat that is capable of carrying the boatman and at most one other animal...
```python for t in xrange(input()): n,m=map(int,raw_input().split()) arr=[] for i in range(m): arr+=map(int,raw_input().split()) if m>=3: print 'NO' elif m==2: arr=set(arr) if len(arr)<4:print 'YES' else:print 'NO'...
vfc_68369
{ "difficulty": "3", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n3 2\n1 2\n2 3\n3 3\n1 2\n2 3\n1 3", "output": "YES\nNO\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1067_C. Knights
Solve the following coding problem using the programming language python: Ivan places knights on infinite chessboard. Initially there are n knights. If there is free cell which is under attack of at least 4 knights then he places new knight in this cell. Ivan repeats this until there are no such free cells. One can pr...
```python print('\n'.join(str(2 * i // 3) + ' ' + str(2 * i % 3) for i in range(int(input())))) ```
vfc_68381
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7\n", "output": "0 0\n1 0\n1 3\n2 0\n3 0\n3 3\n4 0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n", "output": "0 0\n1 0\n1 3\n2 0\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
108_A. Palindromic Times
Solve the following coding problem using the programming language python: Tattah is asleep if and only if Tattah is attending a lecture. This is a well-known formula among Tattah's colleagues. On a Wednesday afternoon, Tattah was attending Professor HH's lecture. At 12:21, right before falling asleep, he was staring ...
```python s=input() if s[0]=="0": h=s[1] else: h=s[:2] if s[3]=="0": m=s[3] else: m=s[3:] def pallin(x,y): if len(x)==1: x="0"+x if len(y)==1: y="0"+y if x[0]==y[1] and x[1]==y[0]: return True else: return False while(1): if int(m)+1==60: h=str...
vfc_68385
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "12:21\n", "output": "13:31\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "23:59\n", "output": "00:00\n", "type": "stdin_stdout" }, { "fn_name": null, "inpu...
code_contests
verifiable_code
1138_C. Skyscrapers
Solve the following coding problem using the programming language python: Dora loves adventures quite a lot. During some journey she encountered an amazing city, which is formed by n streets along the Eastern direction and m streets across the Southern direction. Naturally, this city has nm intersections. At any inter...
```python # -*- coding: utf-8 -*- # @Time : 2019/3/8 17:32 # @Author : LunaFire # @Email : gilgemesh2012@gmail.com # @File : C. Skyscrapers.py import sys def main(): n, m = map(int, input().split()) a = [] disc_row = [] for i in range(n): a.append(list(map(int, input().split()))) ...
vfc_68393
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 2\n1 2\n3 4\n", "output": "2 3 \n3 2 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 3\n1 2 1\n2 1 2\n", "output": "2 2 2 \n2 2 2 \n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
1156_E. Special Segments of Permutation
Solve the following coding problem using the programming language python: You are given a permutation p of n integers 1, 2, ..., n (a permutation is an array where each element from 1 to n occurs exactly once). Let's call some subsegment p[l, r] of this permutation special if p_l + p_r = max _{i = l}^{r} p_i. Please ...
```python mod = 1000000007 eps = 10**-9 def main(): import sys input = sys.stdin.readline class Bit: def __init__(self, n): self.size = n self.tree = [0] * (n + 1) def sum(self, i): s = 0 while i > 0: s += self.tree[i] ...
vfc_68397
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1 3 2\n", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n3 4 1 5 2\n", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input"...
code_contests
verifiable_code
1178_G. The Awesomest Vertex
Solve the following coding problem using the programming language python: You are given a rooted tree on n vertices. The vertices are numbered from 1 to n; the root is the vertex number 1. Each vertex has two integers associated with it: a_i and b_i. We denote the set of all ancestors of v (including v itself) by R(v...
vfc_68401
{ "difficulty": "13", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 5, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 6\n1 1 2 2\n10 -3 -7 -3 -10\n10 3 9 3 6\n2 1\n2 2\n1 2 6\n2 1\n1 2 5\n2 1\n", "output": "100\n91\n169\n240\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "8 17\n1 2 3 4 5 6 7\n4000 -4001...
code_contests
verifiable_code
1197_A. DIY Wooden Ladder
Solve the following coding problem using the programming language python: Let's denote a k-step ladder as the following structure: exactly k + 2 wooden planks, of which * two planks of length at least k+1 — the base of the ladder; * k planks of length at least 1 — the steps of the ladder; Note that neither t...
```python T = int(input()) for t in range(T): N = int(input()) Arr = list(map(int, input().split())) Arr.sort(reverse=True) M = min(Arr[0], Arr[1]) if (len(Arr) == 1 or M-1 == 0): print(0) else: print(min(len(Arr)-2, M-1)) ```
vfc_68405
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n4\n1 3 1 3\n3\n3 3 2\n5\n2 3 3 4 2\n3\n1 1 2\n", "output": "2\n1\n2\n0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n6\n1 1 3 2 10000 1000\n", "output": "4\n", "type": ...
code_contests
verifiable_code
1214_B. Badges
Solve the following coding problem using the programming language python: There are b boys and g girls participating in Olympiad of Metropolises. There will be a board games tournament in the evening and n participants have accepted the invitation. The organizers do not know how many boys and girls are among them. Or...
```python b = int(input()) g = int(input()) n = int(input()) j = n ma = max(b,g) mi = min(b,g) counter =0 if ma >= n : # for i in range(n+1): # if i <= mi: # counter += 1 # else: # break counter = min(mi,n) + 1 else: counter = mi - (n-ma) + 1 print(counter) ...
vfc_68409
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n3\n5\n", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n6\n3\n", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": ...
code_contests
verifiable_code
1237_D. Balanced Playlist
Solve the following coding problem using the programming language python: Your favorite music streaming platform has formed a perfectly balanced playlist exclusively for you. The playlist consists of n tracks numbered from 1 to n. The playlist is automatic and cyclic: whenever track i finishes playing, track i+1 start...
```python import sys input=sys.stdin.buffer.readline from collections import deque n=int(input()) l=list(map(int,input().split())) d=deque() ans=[] currmax=-1000000000000 j=0 for i in range(n): while(len(d) and d[0]<i): d.popleft() currmax=l[d[0]%n] if(len(d)) else l[i] while(j<3*n): currmax...
vfc_68413
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n3 2 5 3\n", "output": "5 4 3 6 \n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1255_D. Feeding Chicken
Solve the following coding problem using the programming language python: Long is a huge fan of CFC (Codeforces Fried Chicken). But the price of CFC is increasing, so he decides to breed the chicken on his own farm. His farm is presented by a rectangle grid with r rows and c columns. Some of these cells contain rice,...
```python import sys input = sys.stdin.readline I = lambda : list(map(int,input().split())) t,=I() bl=['0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r',...
vfc_68417
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 500000000}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n3 5 3\n..R..\n...R.\n....R\n6 4 6\nR..R\nR..R\nRRRR\nRRRR\nR..R\nR..R\n5 5 4\nRRR..\nR.R..\nRRR..\nR..R.\nR...R\n2 31 62\nRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR\nRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR\n", "output": "aaabb\ncccbb\nccccc\...
code_contests
verifiable_code
1363_C. Game On Leaves
Solve the following coding problem using the programming language python: Ayush and Ashish play a game on an unrooted tree consisting of n nodes numbered 1 to n. Players make the following move in turns: * Select any leaf node in the tree and remove it together with any edge which has this node as one of its endpo...
```python #CF 644 (DIV-3) '''test=int(input()) for i in range(test): a,b=[int(i) for i in input().split()] k=min(a,b) if 2*k>=max(a,b): print((2*k)**2) else: print((max(a,b))**2)''' '''test=int(input()) for i in range(test): n=int(input()) arr=[int(i) for i i...
vfc_68437
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n3 1\n2 1\n3 1\n", "output": "Ashish\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1383_E. Strange Operation
Solve the following coding problem using the programming language python: Koa the Koala has a binary string s of length n. Koa can perform no more than n-1 (possibly zero) operations of the following form: In one operation Koa selects positions i and i+1 for some i with 1 ≤ i < |s| and sets s_i to max(s_i, s_{i+1}). ...
```python import sys readline = sys.stdin.readline MOD = 10**9+7 S = readline().strip().split('1') if len(S) == 1: print(len(S[0])) else: S = [len(s)+1 for s in S] ans = S[0]*S[-1] S = S[1:-1] dp = [0]*(max(S)+2) dp[0] = 1 for ai in S: res = 0 rz = 0 for i in ra...
vfc_68441
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "000\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "0101\n", "output": "6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "001011...
code_contests
verifiable_code
1404_E. Bricks
Solve the following coding problem using the programming language python: A brick is defined as a rectangle with integer side lengths with either width 1 or height 1 (or both). There is an n× m grid, and each cell is colored either black or white. A tiling is a way to place bricks onto the grid such that each black c...
vfc_68445
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 4, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 4\n#.##\n####\n##..\n", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10 8\n####..##\n#..#.##.\n#..#.###\n####.#.#\n....####\n.###.###\n###.#..#\n########\n###..###\n.##.#...
code_contests
verifiable_code
144_A. Arrival of the General
Solve the following coding problem using the programming language python: A Ministry for Defense sent a general to inspect the Super Secret Military Squad under the command of the Colonel SuperDuper. Having learned the news, the colonel ordered to all n squad soldiers to line up on the parade ground. By the military ...
```python def findmax(arr): idx = 0 for i in range(len(arr)): if arr[i]> arr[idx]: idx = i return idx def findmin(arr): idx = len(arr)-1 for i in range(len(arr)-1,-1,-1): if arr[i] < arr[idx]: idx = i return idx x = int(input()) arr = list(map(int,input()....
vfc_68453
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7\n10 10 58 31 63 40 76\n", "output": "10\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n33 44 11 22\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name...
code_contests
verifiable_code
1473_A. Replacing Elements
Solve the following coding problem using the programming language python: You have an array a_1, a_2, ..., a_n. All a_i are positive integers. In one step you can choose three distinct indices i, j, and k (i ≠ j; i ≠ k; j ≠ k) and assign the sum of a_j and a_k to a_i, i. e. make a_i = a_j + a_k. Can you make all a_i...
```python def solver(): tc=int(input()) for i in range(tc): n,d=[int(i) for i in input().split()] a=[int(i) for i in input().split()] a.sort() if max(a)<=d: print('YES') else: if (a[0]+a[1])<=d: print('YES') else: ...
vfc_68457
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n5 3\n2 3 2 5 4\n3 4\n2 4 4\n5 4\n2 1 5 3 6\n", "output": "\nNO\nYES\nYES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "11\n5 3\n2 3 2 5 4\n3 4\n2 4 4\n5 4\n2 1 5 3 6\n5 3\n2 3 2 5 4\n...
code_contests
verifiable_code
1499_C. Minimum Grid Path
Solve the following coding problem using the programming language python: Let's say you are standing on the XY-plane at point (0, 0) and you want to reach point (n, n). You can move only in two directions: * to the right, i. e. horizontally and in the direction that increase your x coordinate, * or up, i. e. v...
```python for _ in range(int(input())): n = int(input()) arr = list(map(int, input().split())) best = float("inf") mn = [float("inf")] * 2 sm = [0] * 2 for i in range(n): mn[i%2] = min(mn[i%2], arr[i]) sm[i%2] += arr[i] best = min(best, sm[0]+mn[0]*(n-i//2-1) + sm[1]+mn[1...
vfc_68461
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n2\n13 88\n3\n2 3 1\n5\n4 3 2 1 4\n", "output": "\n202\n13\n19\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n2\n13 88\n3\n2 3 0\n5\n4 3 2 1 4\n", "output": "202\n11\n19\n", ...
code_contests
verifiable_code
1521_A. Nastia and Nearly Good Numbers
Solve the following coding problem using the programming language python: Nastia has 2 positive integers A and B. She defines that: * The integer is good if it is divisible by A ⋅ B; * Otherwise, the integer is nearly good, if it is divisible by A. For example, if A = 6 and B = 4, the integers 24 and 72 are ...
```python for _ in range(int(input())) : a,b = list(map(int,input().split())) if b == 1 : print("NO") else : if b == 2 : b = 4 print( "YES" ) print( a, a*(b-1), a*b ) ```
vfc_68465
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n5 3\n13 2\n7 11\n", "output": "\nYES\n10 50 60\nYES\n169 39 208\nYES\n28 154 182", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1550_A. Find The Array
Solve the following coding problem using the programming language python: Let's call an array a consisting of n positive (greater than 0) integers beautiful if the following condition is held for every i from 1 to n: either a_i = 1, or at least one of the numbers a_i - 1 and a_i - 2 exists in the array as well. For e...
```python t = int(input()) for _ in range(t): n = int(input()) cur = 0 ans = 0 for i in range(1, 1000000, 2): if cur+i > n: break ans += 1 cur += i if cur == n: print(ans) else: print(ans+1) ```
vfc_68469
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n1\n8\n7\n42\n", "output": "1\n3\n3\n7\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n1\n12\n7\n42\n", "output": "1\n4\n3\n7\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
176_D. Hyper String
Solve the following coding problem using the programming language python: Paul Erdős's prediction came true. Finally an alien force landed on the Earth. In contrary to our expectation they didn't asked the humans to compute the value of a Ramsey number (maybe they had solved it themselves). They asked another question...
vfc_68473
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\nb\na\n5\n1 2 1 2 1\naaa\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\ncba\ndgh\n2\n1 2\naedfhr\n", "output": "3\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
197_A. Plate Game
Solve the following coding problem using the programming language python: You've got a rectangular table with length a and width b and the infinite number of plates of radius r. Two players play the following game: they take turns to put the plates on the table so that the plates don't lie on each other (but they can ...
```python a,b,r=map(int,input().split()) (print("First")if (a>=2*r and b>=2*r) else print("Second")) ```
vfc_68477
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6 7 4\n", "output": "Second", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 5 2\n", "output": "First", "type": "stdin_stdout" }, { "fn_name": null, "input":...
code_contests
verifiable_code
244_C. The Brand New Function
Solve the following coding problem using the programming language python: Polycarpus has a sequence, consisting of n non-negative integers: a1, a2, ..., an. Let's define function f(l, r) (l, r are integer, 1 ≤ l ≤ r ≤ n) for sequence a as an operation of bitwise OR of all the sequence elements with indexes from l to ...
```python #CF Round 150. Div II Prob. C - The Brand New Function import sys In = sys.stdin n = int(In.readline().strip()) arr = [int(x) for x in In.readline().split()] res, m = set(), set() for i in range(n): s = set() s.add(arr[i]) s.update([x | arr[i] for x in m]) m = s res.update(s) print(...
vfc_68485
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10\n1 2 3 4 5 6 1 2 9 10\n", "output": "11\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n1 2 0\n", "output": "4\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
26_A. Almost Prime
Solve the following coding problem using the programming language python: A number is called almost prime if it has exactly two distinct prime divisors. For example, numbers 6, 18, 24 are almost prime, while 4, 8, 9, 42 are not. Find the amount of almost prime numbers which are between 1 and n, inclusive. Input Inpu...
```python from math import sqrt n = int(input()) count = 0 primes = [] numbers = list(range(3000)) for i in numbers: if i != 0 and i != 1: non_prime_value = i + i while non_prime_value < len(numbers): numbers[non_prime_value] = 0 non_prime_value += i for i in numbers: ...
vfc_68489
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "21\n", "output": "8\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2998\n", ...
code_contests
verifiable_code
292_C. Beautiful IP Addresses
Solve the following coding problem using the programming language python: The problem uses a simplified TCP/IP address model, please read the statement carefully. An IP address is a 32-bit integer, represented as a group of four decimal 8-bit integers (without leading zeroes), separated by commas. For example, record...
```python import sys, itertools sys.setrecursionlimit(10001) def valid(num): n = int(num) if str(n) != num: return False return 0 <= n and n <= 255 def div_ip1(n): for x in xrange(2, len(n)-1): for ip1 in div_ip2(n[:x]): for ip2 in div_ip2(n[x:]): yield ip1 + "." + ip2 def div_ip2(n): for x in xrange...
vfc_68493
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n0 1 2 9 8 7\n", "output": "6\n78.190.209.187\n79.180.208.197\n87.190.209.178\n89.170.207.198\n97.180.208.179\n98.170.207.189\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n4\n", ...
code_contests
verifiable_code
340_A. The Wall
Solve the following coding problem using the programming language python: Iahub and his friend Floyd have started painting a wall. Iahub is painting the wall red and Floyd is painting it pink. You can consider the wall being made of a very large number of bricks, numbered 1, 2, 3 and so on. Iahub has the following s...
```python def gcd(a, b): if b == 0: return a return gcd(b, a % b) def lcm(a, b): return a * b / gcd(a, b) x, y, a, b = map(int, input().split(' ')) l = lcm(x, y) print(int(b // l - (a - 1) // l)) ```
vfc_68501
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 3 6 18\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1000 1000 1 20\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "...
code_contests
verifiable_code
363_C. Fixing Typos
Solve the following coding problem using the programming language python: Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos. In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume t...
```python s = input() n = len(s) l = [] i = 0 while i<n: j = i+1 while j<n and s[j]==s[i]: j+=1 if (j-i)==1: l.append(s[i]) i+=1 continue l.append(s[i]) l.append(s[i]) k = j+1 while k<n and s[k]==s[j]: k+=1 if j<n: l.append(s[j]) i = k ...
vfc_68505
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "woooooow\n", "output": "woow\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "helloo\n", "output": "hello\n", "type": "stdin_stdout" }, { "fn_name": null, "i...
code_contests
verifiable_code
387_B. George and Round
Solve the following coding problem using the programming language python: George decided to prepare a Codesecrof round, so he has prepared m problems for the round. Let's number the problems with integers 1 through m. George estimates the i-th problem's complexity by integer bi. To make the round good, he needs to pu...
```python n, m = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) cnt = 0 j = 0 for i in range(n): while j < m: if a[i] <= b[j]: cnt += 1 j += 1 break else: j += 1 print(n - cnt) ```
vfc_68509
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 5\n1 2 3\n1 1 1 1 1\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 1\n2 3 4\n1\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": n...
code_contests
verifiable_code
407_E. k-d-sequence
Solve the following coding problem using the programming language python: We'll call a sequence of integers a good k-d sequence if we can add to it at most k numbers in such a way that after the sorting the sequence will be an arithmetic progression with difference d. You got hold of some sequence a, consisting of n ...
vfc_68513
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6 1 2\n4 3 2 8 6 2\n", "output": "3 5\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "54 3 2\n-171854 56624 62874 42612 73480 -123332 -123320 -123312 -123330 -123328 -123314 -123326 -12332...
code_contests
verifiable_code
435_A. Queue on Bus Stop
Solve the following coding problem using the programming language python: It's that time of the year when the Russians flood their countryside summer cottages (dachas) and the bus stop has a lot of people. People rarely go to the dacha on their own, it's usually a group, so the people stand in queue by groups. The bu...
```python a,b = map(int, input().split()) ar = list(map(int, input().split())) count=1 sums=0 for i in range(a): sums += ar[i] if(sums > b): sums = ar[i] count+= 1 print(count) ```
vfc_68517
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 4\n1 2 1\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 3\n2 3 2 1\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "...
code_contests
verifiable_code
457_C. Elections
Solve the following coding problem using the programming language python: You are running for a governor in a small city in Russia. You ran some polls and did some research, and for every person in the city you know whom he will vote for, and how much it will cost to bribe that person to vote for you instead of whomev...
vfc_68521
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n1 2\n1 2\n2 1\n0 0\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n1 2\n1 2\n1 2\n2 1\n0 0\n", "output": "3\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
47_A. Triangular numbers
Solve the following coding problem using the programming language python: A triangular number is the number of dots in an equilateral triangle uniformly filled with dots. For example, three dots can be arranged in a triangle; thus three is a triangular number. The n-th triangular number is the number of dots in a tria...
```python n = int(input()) t = [] for i in range(1, 32): t.append(i * (i + 1) / 2) print('YES' if n in t else 'NO') ```
vfc_68525
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n", ...
code_contests
verifiable_code
504_A. Misha and Forest
Solve the following coding problem using the programming language python: Let's define a forest as a non-directed acyclic graph (also without loops and parallel edges). One day Misha played with the forest consisting of n vertices. For each vertex v from 0 to n - 1 he wrote down two integers, degreev and sv, were the ...
```python n = int(input()) deg2vs = {} ss = [0] * n degs = [0] * n for i in range(n): degs[i], ss[i] = list(map(int, input().split())) if degs[i] > 0: if degs[i] not in deg2vs: deg2vs[degs[i]] = set() deg2vs[degs[i]].add(i) edges = [] while len(deg2vs) != 0: leaves = deg2vs.pop(1...
vfc_68529
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n1 1\n1 0\n", "output": "1\n0 1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n2 3\n1 0\n1 0\n", "output": "2\n1 0\n2 0\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
527_D. Clique Problem
Solve the following coding problem using the programming language python: The clique problem is one of the most well-known NP-complete problems. Under some simplification it can be formulated as follows. Consider an undirected graph G. It is required to find a subset of vertices C of the maximum size such that any two...
```python def main(): from bisect import bisect_right as br n = int(input()) ab = [list(map(int, input().split())) for _ in [0]*n] ab.sort() ans = [-10**20] l = 1 for a, b in ab: c = br(ans, a-b) d = a+b if c == br(ans, d): if c == l: ans...
vfc_68533
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n2 3\n3 1\n6 1\n0 2\n", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n4 4\n12 5\n", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
57_A. Square Earth?
Solve the following coding problem using the programming language python: Meg the Rabbit decided to do something nice, specifically — to determine the shortest distance between two points on the surface of our planet. But Meg... what can you say, she wants everything simple. So, she already regards our planet as a two...
```python n, x1, y1, x2, y2 = map(int, input().split()) first, secnd = 0, 0 if y1 == 0: first = 4 elif y1 == n: first = 2 if x1 == 0: first = 1 elif x1 == n: first = 3 if y2 == 0: secnd = 4 elif y2 == n: secnd = 2 if x2 == 0: secnd = 1 elif x2 == n: secnd = 3 if first == 4 and secnd...
vfc_68541
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 0 0 1 0\n", "output": "1\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
600_F. Edge coloring of bipartite graph
Solve the following coding problem using the programming language python: You are given an undirected bipartite graph without multiple edges. You should paint the edges of graph to minimal number of colours, so that no two adjacent edges have the same colour. Input The first line contains three integers a, b, m (1 ≤...
vfc_68545
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 3 5\n1 2\n2 2\n3 2\n4 1\n4 3\n", "output": "3\n2 3 1 1 2 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "139 1000 0\n", "output": "0\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
623_C. Electric Charges
Solve the following coding problem using the programming language python: Programmer Sasha is a student at MIPT (Moscow Institute of Physics and Technology) and he needs to make a laboratory work to pass his finals. A laboratory unit is a plane with standard coordinate axes marked on it. Physicists from Moscow Instit...
vfc_68549
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n1 10\n10 1\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n1 10\n1 20\n1 30\n", "output": "0\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
645_B. Mischievous Mess Makers
Solve the following coding problem using the programming language python: It is a balmy spring afternoon, and Farmer John's n cows are ruminating about link-cut cacti in their stalls. The cows, labeled 1 through n, are arranged so that the i-th cow occupies the i-th stall from the left. However, Elsie, after realizing...
```python def gh(w): return (w*(w+1))//2 a,b=map(int,input().split()) z=a-1 r=min(b,a//2) f=gh(z) k=max(0,z-2*r) l=gh(k) if b<=r:print(f-l) else:print(max(0,f-l-(r-(a//2))%2)) ```
vfc_68553
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 2\n", "output": "10\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 10\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "7 3\n...
code_contests
verifiable_code
671_E. Organizing a Race
Solve the following coding problem using the programming language python: Kekoland is a country with n beautiful cities numbered from left to right and connected by n - 1 roads. The i-th road connects cities i and i + 1 and length of this road is wi kilometers. When you drive in Kekoland, each time you arrive in cit...
vfc_68557
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 4\n2 2 2\n1 1 1 1\n", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "8 5\n2 2 2 3 7 3 1\n1 3 1 5 4 0 2 5\n", "output": "7\n", "type": "stdin_stdout" }, ...
code_contests
verifiable_code
697_B. Barnicle
Solve the following coding problem using the programming language python: Barney is standing in a bar and starring at a pretty girl. He wants to shoot her with his heart arrow but he needs to know the distance between him and the girl to make his shot accurate. <image> Barney asked the bar tender Carl about this dis...
```python from functools import reduce import math from decimal import * def factors(n): return set(reduce(list.__add__, ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0))) def sol(): a = Decimal(input()) if (int(a) == a): print(int(a)) else: print(a) sol() `...
vfc_68561
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "8.549e3\n", "output": "8549\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "0.33e0\n", "output": "0.33\n", "type": "stdin_stdout" }, { "fn_name": null, "inp...
code_contests
verifiable_code
717_I. Cowboy Beblop at his computer
Solve the following coding problem using the programming language python: Cowboy Beblop is a funny little boy who likes sitting at his computer. He somehow obtained two elastic hoops in the shape of 2D polygons, which are not necessarily convex. Since there's no gravity on his spaceship, the hoops are standing still i...
```python from math import gcd, sqrt from functools import reduce import sys input = sys.stdin.readline EPS = 0.0000000001 def inp(): return(int(input())) def inlt(): return(list(map(int,input().split()))) def GCD(args): return reduce(gcd, args) def plane_value(plane, point): A, B, C, D = plane ...
vfc_68565
{ "difficulty": "15", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n0 0 0\n2 0 0\n2 2 0\n0 2 0\n4\n1 1 -1\n1 1 1\n1 3 1\n1 3 -1\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n4 -2 0\n4 3 0\n-3 3 0\n-3 -2 0\n4\n6 -2 0\n3 2 2\n-3 7 ...
code_contests
verifiable_code
739_E. Gosha is hunting
Solve the following coding problem using the programming language python: Gosha is hunting. His goal is to catch as many Pokemons as possible. Gosha has a Poke Balls and b Ultra Balls. There are n Pokemons. They are numbered 1 through n. Gosha knows that if he throws a Poke Ball at the i-th Pokemon he catches it with ...
vfc_68569
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 5, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 2 2\n1.000 0.000 0.500\n0.000 1.000 0.500\n", "output": "2.750000000000\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
762_D. Maximum path
Solve the following coding problem using the programming language python: You are given a rectangular table 3 × n. Each cell contains an integer. You can move from one cell to another if they share a side. Find such path from the upper left cell to the bottom right cell of the table that doesn't visit any of the cell...
```python import sys from array import array # noqa: F401 import typing as Tp # noqa: F401 def input(): return sys.stdin.buffer.readline().decode('utf-8') def output(*args): sys.stdout.buffer.write( ('\n'.join(map(str, args)) + '\n').encode('utf-8') ) def main(): n = int(input()) a =...
vfc_68573
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1 1 1\n1 -1 1\n1 1 1\n", "output": "7", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
785_E. Anton and Permutation
Solve the following coding problem using the programming language python: Anton likes permutations, especially he likes to permute their elements. Note that a permutation of n elements is a sequence of numbers {a1, a2, ..., an}, in which every number from 1 to n appears exactly once. One day Anton got a new permutati...
vfc_68577
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 4, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 1\n2 1\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 4\n4 5\n2 4\n2 5\n2 2\n", "output": "1\n4\n3\n3\n", "type": "stdin_stdout" }, { "fn_na...
code_contests
verifiable_code
807_E. Prairie Partition
Solve the following coding problem using the programming language python: It can be shown that any positive integer x can be uniquely represented as x = 1 + 2 + 4 + ... + 2k - 1 + r, where k and r are integers, k ≥ 0, 0 < r ≤ 2k. Let's call that representation prairie partition of x. For example, the prairie partitio...
```python from collections import Counter from math import log2 powers = [2 ** p for p in range(64)] def can(): near = Counter() for num in set(nums): p = int(log2(num)) near[p] += nums[num] seq_cp = seqs - Counter() for num in set(near): cnt = near[num] while cnt != 0...
vfc_68581
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n1 2 4 4 4\n", "output": "-1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n1 1 1 2 2 2\n", "output": "2 3\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
831_F. Bamboo Partition
Solve the following coding problem using the programming language python: Vladimir wants to modernize partitions in his office. To make the office more comfortable he decided to remove a partition and plant several bamboos in a row. He thinks it would be nice if there are n bamboos in a row, and the i-th from the left...
vfc_68585
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 40\n10 30 50\n", "output": "32\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
852_G. Bathroom terminal
Solve the following coding problem using the programming language python: Smith wakes up at the side of a dirty, disused bathroom, his ankle chained to pipes. Next to him is tape-player with a hand-written message "Play Me". He finds a tape in his own back pocket. After putting the tape in the tape-player, he sees a k...
```python import sys from itertools import product from collections import defaultdict r=sys.stdin.readline N,M=map(int,r().split()) words=defaultdict(int) tb=['a','b','c','d','e'] st=set() cnt=0 res="" def dfs(u): global res,cnt if u==l: if res in st: return if words[res]>0: cnt+=wo...
vfc_68589
{ "difficulty": "13", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 1\nabc\naec\nac\na?c\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "15 6\naaa\naaabbb\naaabb\naaaaa\naaaaaa\naaaa\naaabbbb\naaaaa\naaaaaa\naaaa\naaabbbb\naabbbb\naa\naa...
code_contests
verifiable_code
877_B. Nikita and string
Solve the following coding problem using the programming language python: One day Nikita found the string containing letters "a" and "b" only. Nikita thinks that string is beautiful if it can be cut into 3 strings (possibly empty) without changing the order of the letters, where the 1-st and the 3-rd one contain onl...
```python s=input() n=len(s) prefa=[0]*(n) prefb=[0]*(n) prefa[0]=(s[0]=='a') prefb[0]=(s[0]=='b') c=0 for i in range(1,n): prefa[i]=prefa[i-1]+(s[i]=='a') prefb[i]=prefb[i-1]+(s[i]=='b') ans1,ans=0,0 prefa=[0]+prefa prefb=[0]+prefb for i in range(n+1): for j in range(i,n+1): ans1=(prefa[n]-prefa[j])+(pref...
vfc_68593
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "bab\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "abba\n", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "ba\n",...
code_contests
verifiable_code
900_C. Remove Extra One
Solve the following coding problem using the programming language python: You are given a permutation p of length n. Remove one element from permutation to make the number of records the maximum possible. We remind that in a sequence of numbers a1, a2, ..., ak the element ai is a record if for every integer j (1 ≤ j ...
```python a=int(input()) b=[] for i in range(a+1): b.append(0) fir=0 sec=0 for i in (input().split(' ')): j=int(i) if j>fir: sec=fir fir=j b[j]=1 elif j>sec: sec=j b[fir]-=1 ans=1 for i in range(1,a+1): if b[i]<b[ans]: ans=i print(ans) ...
vfc_68597
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n1\n", "output": "1\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
923_A. Primal Sport
Solve the following coding problem using the programming language python: Alice and Bob begin their day with a quick game. They first choose a starting number X0 ≥ 3 and try to reach one million by the process described below. Alice goes first and then they take alternating turns. In the i-th turn, the player whose ...
```python x = int(input()) lp = [0 for x in range(x+1)] for i in range(2, x+1): if(lp[i]==0): for j in range(i*2, x+1, i): lp[j] = i lp[i] = i - lp[i] + 1 p = x for i in range(lp[x], x+1): p = min(p, lp[i]) print(p) ```
vfc_68601
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 500000000}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "14\n", "output": "6", "type": "stdin_stdout" }, { "fn_name": null, "input": "8192\n", "output": "8191", "type": "stdin_stdout" }, { "fn_name": null, "input": "20\n", ...
code_contests
verifiable_code
950_C. Zebras
Solve the following coding problem using the programming language python: Oleg writes down the history of the days he lived. For each day he decides if it was good or bad. Oleg calls a non-empty sequence of days a zebra, if it starts with a bad day, ends with a bad day, and good and bad days are alternating in it. Let...
```python s = input() arr, zero, one = [], [], [] for i in range(len(s)): if s[i] == '0': if one: idx = one.pop() arr[idx].append(i + 1) zero.append(idx) else: zero.append(len(arr)) arr.append([i + 1]) else: if not zero:break ...
vfc_68605
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "111\n", "output": "-1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "0010100\n", "output": "3\n1 1\n5 2 3 4 5 6\n1 7\n", "type": "stdin_stdout" }, { "fn_name": n...
code_contests
verifiable_code
978_F. Mentors
Solve the following coding problem using the programming language python: In BerSoft n programmers work, the programmer i is characterized by a skill r_i. A programmer a can be a mentor of a programmer b if and only if the skill of the programmer a is strictly greater than the skill of the programmer b (r_a > r_b) an...
```python from bisect import * n, k = map(int, input().split()) r = list(map(int, input().split())) s = sorted(r) l = [0] * n for i in range(n): l[i] = bisect_left(s, r[i]) for i in range(k): x, y = map(int, input().split()) x -= 1 y -= 1 if r[x] < r[y]: l[y] -= 1 elif r[x] > r[y]: ...
vfc_68609
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10 4\n5 4 1 5 4 3 7 1 2 5\n4 6\n2 1\n10 8\n3 5\n", "output": "5 4 0 5 3 3 9 0 2 5 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 2\n10 4 10 15\n1 2\n4 3\n", "output": "0 0 1 2 ", ...
code_contests
verifiable_code
998_E. Sky Full of Stars
Solve the following coding problem using the programming language python: On one of the planets of Solar system, in Atmosphere University, many students are fans of bingo game. It is well known that one month on this planet consists of n^2 days, so calendars, represented as square matrix n by n are extremely popular....
vfc_68613
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 4, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n", "output": "63\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n", "output": "9933\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n", ...
code_contests
verifiable_code
beginners-task-2
Solve the following coding problem using the programming language python: Rajat Singh , a student of Delhi University is learning the ways of finding the mean of N numbers. Rajat is a weak students as far as mathematics is concerned and his teacher gave lots of problem sets to find the means. Please help rajat with hi...
```python t = input(); while(t > 0): n = input(); cp = n; s = 0; while(n > 0): no = input(); s += no; n -= 1; print s / cp; t -= 1; ```
vfc_68617
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n4\n10\n12\n23\n24\n\nSAMPLE", "output": "17\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "15\n5\n5\n4\n3\n2\n1\n5\n100000000\n100000000\n100000000\n100000000\n100000000\n4\n12\n14\n16...
code_contests
verifiable_code
coins-game
Solve the following coding problem using the programming language python: Chintu and Mintu are good friends and they have so many coins of different amount so they decided to play a game using a stack consisting of N coins. In this game, anyone can alternatively remove 1, 2 or 3 from the top, and the amount on the r...
```python import sys t = int(sys.stdin.readline()) def solve(xs): xn = len(xs) ss = [(0, 0)] for ix in range(xn): eix = xn - ix - 1 best = None for dx in (1, 2, 3): if eix + dx > xn: continue p = sum(xs[eix:eix + dx]) a, b = ss[ix...
vfc_68621
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n5\n58 952 23 0 12\n5\n0 1 1 1 999\n\nSAMPLE", "output": "1033\n999", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
fast-sort-1
Solve the following coding problem using the programming language python: From the childhood we are taught that a comes before b then b comes before c and so on.So whenever we try to sort any given string we sort it in that manner only placing a before b and so on.But what happens if we initially change the pattern of...
```python n = int(input()) for _ in range(n): key = raw_input() st = raw_input() freq = [0 for i in range(26)] for s in st : freq[ord(s)-ord('a')]+=1; ans = "" for i in key: ans+=i * freq[ord(i)-ord('a')] print(ans) ```
vfc_68625
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\nwcyuogmlrdfphitxjakqvzbnes\njcdokai\nmiruqopsxthzdcnvkfbglwayje\nwgfsyvno\n\nSAMPLE", "output": "codijak\nosnvfgwy\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\nihpcfylbjskmxqogae...
code_contests
verifiable_code
hungry-lemurs
Solve the following coding problem using the programming language python: There are K lemurs on Madagascar and Kevin has N bananas. He has to give away all his bananas to lemurs. Lemurs are happy if all of them get the same number of bananas (even if they don't get any). In one minute Kevin can do one of the following...
```python s=f=1000000 n,k=map(int,raw_input().split()) if(n%k==0): print 0 else: j=k for i in range(1000000): a=n//k b=(n//k)+1 x=b*k-n y=n-(a*k) g=min(x,y) d=k-j if((g+d)<f): f=g+d #print g,d k+=1 k=j for l in range(1000000): #print "tatti" if k<=0: break #print k a=n//k b=(n//...
vfc_68629
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "47 17\n\nSAMPLE", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "99098 827", "output": "9\n", "type": "stdin_stdout" }, { "fn_name": null, "in...
code_contests
verifiable_code
make-some-pal
Solve the following coding problem using the programming language python: A palindrome is a word that reads the same forward and backward. Given a string s, you need to make it a palindrome by adding 0 or more characters to the end of s, and remember, we want the palindrome to be as short as possible. INPUT First l...
```python ''' # Read input from stdin and provide input before running code name = raw_input('What is your name?\n') print 'Hi, %s.' % name ''' n = int(raw_input()) i = 0 pal = "" while i < n: try: s = raw_input() except (EOFError): break if s == s[::-1]: print len(s) continue j = 1 while j <= len(s)...
vfc_68633
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\nabab\nabacaba\nqwerty\n\nSAMPLE", "output": "5\n7\n11\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\nabdfhdyrbdbsdfghjkllkjhgfds\nzazazazazazazazazazazazazazazazazazazazazazazazaza\...
code_contests
verifiable_code
non-decreasing-sequence-4
Solve the following coding problem using the programming language python: Shinchan and Kazama both are playing with numbers. Shinchan gives Kazama an array of numbers and asks him to tell the minimum possible last number of a non decreasing sequence of length L. Note- Check the sample I/O for more clarity. INPUT- ...
```python ''' # Read input from stdin and provide input before running code name = raw_input('What is your name?\n') print 'Hi, %s.' % name ''' def binarysearch(arr,target): if target<=arr[0]: return 0 if target>=arr[-1]: return len(arr)-1 low=0 high=len(arr)-1 while low<=high: ...
vfc_68637
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n7\n9 7 2 5 4 11 12 \n3\n\nSAMPLE", "output": "11", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
quantitative-coefficient
Solve the following coding problem using the programming language python: Russian Translation Available It is very important to understand relationship between variables to draw the right conclusion from a statistical analysis. The relationship between variables determines how the right conclusions are reached. Witho...
```python import collections import heapq MOD = 1000000007 def mst(graph, n): total = 1 seen = set([1]) q = graph[1] heapq.heapify(q) while q: cost, node = heapq.heappop(q) if node in seen: continue seen.add(node) total = (total * cost) % MOD if len(seen) ==...
vfc_68641
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n3 3\n1 2 1234567\n2 3 2345678\n1 3 3456789\n\n\nSAMPLE", "output": "896631161", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
shil-and-hiking
Solve the following coding problem using the programming language python: Shil decided to go for hill climbing on this weekend, but he doesn't have the map of all the hills. However, he's smart enough to make his own map. There are N hills arranged on a line, each in the form of a vertical line segment with one en...
```python n=input() hills=[] for _ in range(n): hills.append(map(int,raw_input().split())) count=0 for a in range(n): x1=hills[a][0] y1=hills[a][1] mcurr=(100000000,1) for b in range(a+1,n): #if (hills[b][0]-hills[a][0]>10000): # break #if hills[b][1]>hills[a][1]: # count+=1 #print a,b # break x2=h...
vfc_68645
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "500\n2 99998\n3 99997\n4 99996\n5 99995\n6 99994\n7 99993\n8 99992\n9 99991\n10 99990\n11 99989\n12 99988\n13 99987\n14 99986\n15 99985\n16 99984\n17 99983\n18 99982\n19 99981\n20 99980\n21 99979\n22 99978\n23 99977\n24 99976\n25 9...
code_contests
verifiable_code
the-legend-of-tanmay
Solve the following coding problem using the programming language python: Tanmay is a legendary spammer - everyone in the spamming world knows and admires his abilities to spam anyone, anytime, anywhere. He decided to guide one of his mentors, named Arjit, as part of the Apex body of spamming. Tanmay has no doubts o...
```python def prod(xs): p = 1 for x in xs: p *= x return p def solve(xs): negatives = sorted(x for x in xs if x < 0) positives = sorted(x for x in xs if x > 0) zeros = [0] if 0 in xs else [] if len(negatives) % 2 == 0: maxi = negatives + positives else: maxi = negatives[:-1] + p...
vfc_68649
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n4\n1 0 2 10\n3\n0 0 0\n\nSAMPLE", "output": "20 0\n0 0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "500\n18\n8 5 5 -9 -8 0 0 -3 -7 2 0 4 2 -6 1 -9 2 -6 \n18\n9 9 -7 -6 -2 -3 -4 4 -6 ...
code_contests
verifiable_code
zeke-and-his-penny
Solve the following coding problem using the programming language python: Zeke loves to spend time with Penny and likes her. Penny is having an issue to solve a mathematics problem and is confused. She seeks Zeke's help as she feels he could help her with the problem. He finds this problem very simple. The problem is ...
```python for _ in range(int(raw_input())): a = sorted(map(int, raw_input().split())) ans = a[0] for i in range(1, 3): a[i] -= i if a[i] < 1: ans = 0 ans *= a[i] print ans % 1000000007 ```
vfc_68653
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n3 3 3\n2 3 2\n29 11 1994\n1 2 3\n1 1 50", "output": "6\n2\n613536\n1\n0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n3 3 3\n2 3 2\n29 11 1994\n1 2 3\n1 1 50\n\nSAMPLE", "out...
code_contests
verifiable_code
p00084 Search Engine
Solve the following coding problem using the programming language python: Internet search engines, such as Google, automatically sort and categorize web pages around the world to create a huge database. It also parses the search keywords entered by the user and creates an inquiry statement for database search. In eac...
```python print(' '.join([x for x in input().replace('.',' ').replace(',',' ').split() if 3 <= len(x) <= 6])) ```
vfc_68697
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "Win today's preliminary contest and be qualified to visit University of Aizu.", "output": "Win and visit Aizu", "type": "stdin_stdout" }, { "fn_name": null, "input": "Rain, rain, go to Spain.", ...
code_contests
verifiable_code
p00216 Cutting Down Water Bills
Solve the following coding problem using the programming language python: Mr. Matsudaira is always careful about eco-friendliness in his life. Last month's water charge was 4280 yen, which exceeded the usual target of 4000 yen, so we have been trying to save water this month. How much have you saved on your water bill...
```python while(True): n = int(input()) if n == -1: break p = 1150 if n < 10: print(4280-p) elif n < 20: p += 125*(n-10); print(4280-p) elif n < 30: p += 125*10; p += 140*(n-20); print(4280-p) else: p += 125*10; p += 140*10; p += 160*(n-30); print(4280-p) ```
vfc_68701
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "29\n40\n0\n-1", "output": "620\n-1120\n3130", "type": "stdin_stdout" }, { "fn_name": null, "input": "29\n40\n-1\n-1", "output": "620\n-1120\n", "type": "stdin_stdout" }, { "...
code_contests
verifiable_code
p00594 What Color Is The Universe?
Solve the following coding problem using the programming language python: On a clear night, a boy, Campanella looked up at the sky, there were many stars which have different colors such as red, yellow, green, blue, purple, etc. He was watching the stars and just lost track of time. Presently, he wondered, | <image>...
```python while True: num=int(input()) if num==0: break stars=sorted(input().split()) if stars.count(stars[num//2]) > num/2 : print(stars[num//2]) else: print("NO COLOR") ```
vfc_68709
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 5, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "8\n3 1 2 3 3 1 5 3\n7\n5 2 5 3 4 5 5\n0", "output": "NO COLOR\n5", "type": "stdin_stdout" }, { "fn_name": null, "input": "8\n3 1 2 3 3 1 5 3\n7\n5 2 5 3 4 0 5\n0", "output": "NO COLOR\nNO COLOR...
code_contests
verifiable_code
p00730 Cut the Cake
Solve the following coding problem using the programming language python: Today is the birthday of Mr. Bon Vivant, who is known as one of the greatest patissiers in the world. Those who are invited to his birthday party are gourmets from around the world. They are eager to see and eat his extremely creative cakes. Now...
```python while True: dic = {} n,w,d = map(int,input().split(" ")) if n == 0 and w == 0 and d == 0: break dic[1] = (w,d) for i in range(n): p,s = map(int,input().split(" ")) W,H = dic[p] for j in range(p,i+1): dic[j] = dic[j+1] cycle = 2*(H+W) s %= cycle if s < W or ((H+W) < s and s < (W+H+W)): ...
vfc_68713
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 5 6\n1 18\n2 19\n1 2\n3 4 1\n1 1\n2 1\n3 1\n0 2 5\n0 0 0", "output": "4 4 6 16\n1 1 1 1\n10", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 5 6\n1 18\n2 31\n1 2\n3 4 1\n1 1\n2 1\n3 1\n0 ...
code_contests
verifiable_code
p00870 Search of Concatenated Strings
Solve the following coding problem using the programming language python: The amount of information on the World Wide Web is growing quite rapidly. In this information explosion age, we must survive by accessing only the Web pages containing information relevant to our own needs. One of the key technologies for this p...
```python from collections import deque import sys readline = sys.stdin.readline write = sys.stdout.write def solve(): N, M = map(int, readline().split()) if N == M == 0: return False ca = ord('a') E = [list(map(lambda x: ord(x)-ca, readline().strip())) for i in range(N)] F = "".join(readli...
vfc_68717
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 8, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 1\naa\nb\nccc\naabccczbaacccbaazaabbcccaa\n3 1\na\nb\nc\ncbbcbcbabaacabccaccbaacbccbcaaaccccbcbcbbcacbaacccaccbbcaacbbabbabaccc\n3 4\naaaaaaaaaaaaaaaaaaaa\naaaaaaaaaaaaaaaaaaaa\naaaaaaaaaaaaaaaaaaaa\naaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
code_contests
verifiable_code
p01133 Dragon Fantasy
Solve the following coding problem using the programming language python: Peace, which was supposed to last forever, suddenly ended. The Demon King, who had been sealed long ago, has finally revived. But when the world was about to be covered in darkness, a brave man appeared. The hero then set out on a journey to col...
```python def solve(): from math import sqrt from sys import stdin f_i = stdin def dfs(point, remain, elapsed): if not remain: return True next_c = set() for c in remain: new_elapsed = elapsed + adj[point][c] if new_elapsed >= fro...
vfc_68725
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 8, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 0 0 10 10\n1 1\n4 4\n2 0 0 10 10\n1 1\n6 6\n2 0 0 10 10\n1 1\n5 5\n0 0 0 0 0", "output": "YES\nNO\nNO", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p01272 Shore Erosion
Solve the following coding problem using the programming language python: You are a programmer working for your local city hall. The town you live in has a thriving tourism industry, especially the beaches on the shores of remote islands. The area around this island is composed of sandy beaches, but in recent years th...
vfc_68729
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 8, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 1\n0 0\n10 0\n5 10\n3 1\n0 0\n10 0\n0 10\n4 1\n0 0\n10 0\n10 10\n0 10\n0 0", "output": "22.6524758425\n23.8994949366\n32.0000000000", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 1\n0 0...
code_contests
verifiable_code
p01442 Mysterious Maze
Solve the following coding problem using the programming language python: A robot in a two-dimensional maze again. The maze has an entrance and an exit this time, though. Just as in the previous problem, the maze is made up of H × W grid cells, its upper side faces north, and each cell is either empty or wall. Unlike...
```python from heapq import heappush, heappop import sys readline = sys.stdin.readline write = sys.stdout.write dd = ((-1, 0), (0, -1), (1, 0), (0, 1)) def solve(): H, W, N = map(int, readline().split()) if H == 0: return False S = readline().strip() C = [[0]*W for i in range(H)] sx = sy =...
vfc_68733
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 8, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 2 1\nL\nG.\n#S\n2 2 2\nRR\nG.\n.S\n3 3 6\nLLLLLL\nG#.\n...\n.#S\n0 0 0", "output": "Yes\nNo\nYes", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 2 1\nL\nG.\nS\n2 2 2\nRR\nG.\n.S\n3 3 6\n...
code_contests
verifiable_code
p01591 Approximate Circle
Solve the following coding problem using the programming language python: Problem A: Approximate Circle Consider a set of n points (x1, y1), ..., (xn,yn) on a Cartesian space. Your task is to write a program for regression to a circle x2 + y2 + ax + by + c = 0. In other words, your program should find a circle that m...
vfc_68737
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 8, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n0 0\n100 0\n100 100\n0 100", "output": "-100.000 -100.000 0.000", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n0 0\n10 0\n5 100", "output": "-10.000 -99.750 0.000", "type"...
code_contests
verifiable_code
p01748 Distance Sum
Solve the following coding problem using the programming language python: There are n cities and n − 1 roads, which are trees. Cities are numbered from 1 to n. When city 1 is taken as the root, the parent of city i is pi, and the distance between i and pi is di. Sunuke wants to solve the following problem for each k o...
vfc_68741
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 536870912, "problem_url": null, "time_limit": "{'seconds': 4, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10\n4 1\n1 1\n3 1\n3 1\n5 1\n6 1\n6 1\n8 1\n4 1", "output": "0\n3\n3\n4\n5\n7\n10\n13\n16\n19", "type": "stdin_stdout" }, { "fn_name": null, "input": "15\n1 3\n12 5\n5 2\n12 1\n7 5\n5 1\n6 1\n12 1\n1...