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
837_C. Two Seals
Solve the following coding problem using the programming language python: One very important person has a piece of paper in the form of a rectangle a × b. Also, he has n seals. Each seal leaves an impression on the paper in the form of a rectangle of the size xi × yi. Each impression must be parallel to the sides of ...
```python n,A,B=map(int,input().split()) arr=[] for x in range(n): i,j=map(int,input().split()) arr.append([i,j]) ans=int(0) i=int(0) j=int(0) for i in range(n): for j in range(i+1,n): a=arr[i][0] b=arr[i][1] c=arr[j][0] d=arr[j][1] temp=a*b+c*d if(temp<=ans):...
vfc_60669
{ "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": "4 10 9\n2 3\n1 1\n5 10\n9 11\n", "output": "56\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 2 2\n1 2\n2 1\n", "output": "4\n", "type": "stdin_stdout" }, { "f...
code_contests
verifiable_code
856_E. Satellites
Solve the following coding problem using the programming language python: Real Cosmic Communications is the largest telecommunication company on a far far away planet, located at the very edge of the universe. RCC launches communication satellites. The planet is at the very edge of the universe, so its form is half o...
vfc_60673
{ "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 8\n1 -5 8\n1 -4 8\n1 -3 8\n1 2 7\n3 1 3\n2 2\n3 1 3\n3 3 4\n", "output": "NO\nYES\nYES\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
883_E. Field of Wonders
Solve the following coding problem using the programming language python: Polycarpus takes part in the "Field of Wonders" TV show. The participants of the show have to guess a hidden word as fast as possible. Initially all the letters of the word are hidden. The game consists of several turns. At each turn the partic...
```python n = int(input()) S = input() HaveLetters = set(list(S)) m = int(input()) words = [] CanLetters = set([chr(i) for i in range(ord("a"), ord("z") + 1)]) - HaveLetters for _ in range(m): Word = input() for i in range(n): if S[i] == "*": if Word[i] in HaveLetters: break ...
vfc_60677
{ "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": "3\na*a\n2\naaa\naba\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\na**d\n2\nabcd\nacbd\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_n...
code_contests
verifiable_code
906_E. Reverses
Solve the following coding problem using the programming language python: Hurricane came to Berland and to suburbs Stringsvill. You are going to it to check if it's all right with you favorite string. Hurrinace broke it a bit by reversing some of its non-intersecting substrings. You have a photo of this string before ...
vfc_60681
{ "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": "abcxxxdef\ncbaxxxfed\n", "output": "2\n7 9\n1 3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "kwyxpguewbitchxngjuanrlahhoggyfqzajkfbcgbzexlqmfrc\nkwyxpguewbitchxngjuanrlahhofyggqzajkfbcg...
code_contests
verifiable_code
926_G. Large Bouquets
Solve the following coding problem using the programming language python: A flower shop has got n bouquets, and the i-th bouquet consists of ai flowers. Vasya, the manager of the shop, decided to make large bouquets from these bouquets. Vasya thinks that a bouquet is large if it is made of two or more initial bouque...
```python n = int(input()) flowers = input().split() odd = 0 ott = 0 for val in flowers: if int(val) % 2 == 0: odd += 1 else: ott += 1 while ott > odd + 2: ott -= 2 odd += 1 print(min(odd, ott)) ```
vfc_60685
{ "difficulty": "13", "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\n2 3 4 2 7\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n2 2 6 8 6 12\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
955_E. Icicles
Solve the following coding problem using the programming language python: Andrew's favourite Krakozyabra has recenly fled away and now he's eager to bring it back! At the moment the refugee is inside an icy cave with n icicles dangling from the ceiling located in integer coordinates numbered from 1 to n. The distance...
vfc_60689
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 500000000}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n1 4 3 5 1\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1 2\n", "output": "-1\n", "type": "stdin_stdout" }, { "fn_name": null, "inp...
code_contests
verifiable_code
4-3
Solve the following coding problem using the programming language python: Scooby is stuck in a cave in barren islands. Shaggy decided to play a prank on scooby. in his ghostly voice shaggy asks a question to the scared scooby. the ghost(shaggy) will make scooby's way out only if he answers the following problem. sin...
```python t = input(); while(t > 0): n = input(); a = [int(i) for i in raw_input().split()]; s = 0; for i in range(0, n): s += a[i]; print (pow(2, n - 1) * s) % 1000000007; t -= 1; ```
vfc_60697
{ "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\n1 2 3\n\nSAMPLE", "output": "24", "type": "stdin_stdout" }, { "fn_name": null, "input": "12\n3\n1 2 3\n2\n5 4\n84\n30887 92778 36916 47794 38336 85387 60493 16650 41422 2363 90028 68691 20060 9...
code_contests
verifiable_code
big-travel-icpc-9
Solve the following coding problem using the programming language python: Aarav has just graduated from the university. Now he is going to travel along his country. More precisely: there are N cities with integer coordinates. His plan is to travel between each pair of the cities. The distance between city A with coo...
```python sum=0 q=1000000007 n = int(raw_input()) a1 = [] a2 = [] for i in range(n): n1,n2 = raw_input().split() a1.append(int(n1)) a2.append(int(n2)) a1.sort() a2.sort() for i in range(n-1,-1,-1): sum=(sum+(n-1-2*(n-1-i))*a1[i])%q; sum=(sum+(n-1-2*(n-1-i))*a2[i])%q; print (sum)%q ```
vfc_60701
{ "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-1 5\n1 6\n3 5\n2 3\n\nSAMPLE", "output": "22\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "21\n10 18\n5 9\n4 -6\n13 1\n17 -10\n-8 19\n-13 19\n17 -20\n-12 5\n10 0\n14 -14\n12 -4\n15 -...
code_contests
verifiable_code
count-x
Solve the following coding problem using the programming language python: Each digit of a number is represented by a cluster of adjacent X, with spaces between neighboring clusters. The digit is determined by the number of X in the cluster. For example, the number 243 would be represented by the following pattern ...
```python t=int(raw_input()) for _ in range(t): arr=raw_input() for i in range(len(arr)-1): if arr[i]=='-' and arr[i+1]=='-': arr=arr[0:i+1]+"0"+arr[i+1:] arr=arr[1:-1] arr=arr.split("-") res="" for word in arr: if word == "0": res+="0" else: res+=str(len(word)) print(res) ```
vfc_60705
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n-XX-XXXX-XXX-\n-XX--XXXX---XXX-\n\nSAMPLE", "output": "243\n204003\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n-XXXXX-X-XXX-\n-XX--XXXX---XXX-\n\nSAMPLE", "output": "513\n2...
code_contests
verifiable_code
inverse-list
Solve the following coding problem using the programming language python: There are many ways to order a list of integers from 1 to n. For example, if n = 3, the list could be : [3\; 1\; 2]. But there is a special way to create another list from the given list of integers. In this list, position of integer i is the ...
```python n=int(raw_input()) while n: n=n-1 size=int(raw_input()) a=raw_input().split() a=[int(i) for i in a] b=list(xrange(size)) for i in list(xrange(size)): b[a[i]-1]=i+1 if a==b: print "inverse" else: print "not inverse" ```
vfc_60713
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n3\n3 1 2\n3\n1 2 3\n\nSAMPLE", "output": "not inverse\ninverse\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n42\n2 1 15 13 34 33 38 18 28 31 19 14 27 3 17 41 7 30 23 37 26 32 5 16 ...
code_contests
verifiable_code
maxpath
Solve the following coding problem using the programming language python: You are given a N x N square matrix of integers where each cell represents the amount of gold in it. You need to travel from the top left cell to the bottom right cell, and back, maximizing the amount of gold you collect as you pass by the cell ...
```python def main(): n = input() l = [] m = [] for i in range(n): str = raw_input() spl = str.split() l.append([]) m.append([]) for j in range(n): l[i].append(int(spl[j])) m[i].append(-999999999) q = [] s = 0 q....
vfc_60717
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n4 10 6\n1 1 5\n-5 6 8\n\nSAMPLE", "output": "39\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
ornaments-of-byteland
Solve the following coding problem using the programming language python: CodeswarBala found various ornaments in Btyeland. Each ornament is made up of various items, and each item is represented by a letter from 'a' to 'z'. An item can be present multiple times in a ornament . An item is called special item if it o...
```python noOfOrn = int(raw_input()) m = {} count = 0 for c in range(1, noOfOrn + 1): inp = raw_input() count += 1 for k in inp: if(m.has_key(k) == False): m[k]= [] if(count not in m[k]): m[k].append(count) c = 0 for key in m.keys(): if(len(m[key]) == noOfOrn): c += 1 print c ```
vfc_60721
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\nabcdde\nbaccd\neeabg\n\nSAMPLE", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "100\nmolbapydxfbsbwqrrsmkebhxnphikeywkxoldawbojksdlfoqwrqjmkcylacxfdyclepprhbndmgocrdzcgr\n...
code_contests
verifiable_code
ranis-job
Solve the following coding problem using the programming language python: Rani works at sweet shop and is currently arranging sweets i.e. putting sweets in boxes. There are some boxes which contains sweets initially but they are not full. Rani have to fill boxes completely thereby minimizing the total no. of boxes. Yo...
```python t=input() while t: t-=1 n=int(input()) ini=[] tot=[] ini=map(int, raw_input().split()) tot=map(int, raw_input().split()) c=0 for i in range(0,n): c+=ini[i] tot.sort() tot=tot[::-1] i=0 d=0 while i<n: d+=tot[i] if (d>=c): break i+=1 print (i+1) ```
vfc_60725
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n3\n300 525 110\n350 600 115\n6\n1 200 200 199 200 200\n1000 200 200 200 200 200\n\nSAMPLE", "output": "2\n1\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
smart-travel-agent
Solve the following coding problem using the programming language python: Our smart travel agent, Mr. X's current assignment is to show a group of tourists a distant city. As in all countries, certain pairs of cities are connected by two-way roads. Each pair of neighboring cities has a bus service that runs only betwe...
```python n,m=map(int,raw_input().split()) INF=-10000000 adj=[[INF for i in xrange(n+1)] for j in xrange(n+1)] adj1=[[INF for i in xrange(n+1)] for j in xrange(n+1)] for j in xrange(m): a,b,c=map(int,raw_input().split()) adj[a][b]=int(c) adj[b][a]=int(c) adj1[a][b]=b soruce,dest,num_ppl=map(int,raw_inpu...
vfc_60729
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7 10\n1 2 30\n1 3 15\n1 4 10\n2 4 25\n2 5 60\n3 4 40\n3 6 20\n4 7 35\n5 7 20\n6 7 30\n1 7 99\n\nSAMPLE", "output": "1 2 4 7\n5\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "7 10\n1 2 30\...
code_contests
verifiable_code
threesome-pairing
Solve the following coding problem using the programming language python: There was a power value associated with each soldier of Ram’s troop. It was a known belief that if two soldiers could be paired such that their total power can be divided by 3 perfectly, the pairing becomes ultra-powerful. Ram was curious as to ...
```python t = int(raw_input()) while t: n = int(raw_input()) arr = [int(i) for i in raw_input().split()] cnt =0; for i in range(n-1): for j in range(i+1,n): if not (arr[i]+arr[j])%3: cnt+=1 print cnt t-=1 ```
vfc_60733
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n5\n3 6 7 2 9\n4\n2 1 3 4\n3\n9 9 9\n\nSAMPLE", "output": "4\n2\n3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n3\n1 2 3\n9\n2 3 4 5 11 3 5 6 4\n1\n2\n2 \n7 2\n3 \n9 9 9", "o...
code_contests
verifiable_code
p00108 Operation of Frequency of Appearance
Solve the following coding problem using the programming language python: There is a frequency operation in the conversion operation of a finite number sequence. The conversion result of the sequence $ S = \\ {s_1, s_2, ... s_n \\} $ is a sequence of the same length. If the result is $ C = \\ {c_1, c_2, ..., c_n \\} $...
```python from collections import Counter def pr(s): c=0 while 1: b=s t=Counter(s) s=[t[i] for i in s] c+=1 if b==s:break return s,c-1 while 1: le=int(input()) if not le:break s=list(map(int,input().split())) s,c=pr(s) print(c) print(" "....
vfc_60781
{ "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": "10\n4 5 1 1 4 5 12 3 5 4\n0", "output": "3\n6 6 4 4 6 6 4 4 6 6", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n4 5 1 1 4 5 12 3 6 4\n0", "output": "3\n6 4 4 4 6 4 6 6 6 6\n", ...
code_contests
verifiable_code
p00242 Input Candidates
Solve the following coding problem using the programming language python: Mobile phones are equipped with a function that displays input candidates in order to efficiently input texts such as emails. This records frequently used words and presents words that have the entered letters as initial letters as input candida...
```python from collections import defaultdict while True: n = int(input()) if n==0: break initial = defaultdict(set) cnt = defaultdict(int) for _ in range(n): l = list(input().split()) for li in l: initial[li[0]].add(li) cnt[li...
vfc_60785
{ "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": "1\nben likes bananas the best among many fruits because bananas are sweet and cheap\nb\n1\nwinners get to visit aizu and the university of aizu and make many friends as well\na\n3\nask alex about\nthe answer for the\nassignment on ...
code_contests
verifiable_code
p00423 Card Game
Solve the following coding problem using the programming language python: Two players, A and B, play the game using cards with numbers from 0 to 9. First, the two arrange the given n cards face down in a horizontal row. After that, the two players turn their cards face up one by one from the left, and the owner of the...
```python while True: n = int(input()) if n == 0: break pointA, pointB = 0, 0 for i in range(n): cardA, cardB = map(int, input().split()) if cardA == cardB: pointA += cardA pointB += cardB elif cardA > cardB: pointA += cardA + cardB ...
vfc_60789
{ "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\n9 1\n5 4\n0 8\n3\n9 1\n5 4\n1 0\n3\n9 1\n5 5\n1 8\n0", "output": "19 8\n20 0\n15 14", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p00618 Course Planning for Lazy Students
Solve the following coding problem using the programming language python: The University of Aizu started a new system for taking classes in 2009. Under the new system, compulsory subjects have been abolished, and subjects can be freely selected in consideration of each course. However, not all courses can be taken un...
vfc_60793
{ "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": "4 4\n1 0\n3 2 0 2\n2 0\n2 0\n3 6\n1 0\n3 2 0 2\n2 0\n0 0", "output": "2\n3", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p00894 Gift from the Goddess of Programming
Solve the following coding problem using the programming language python: The goddess of programming is reviewing a thick logbook, which is a yearly record of visitors to her holy altar of programming. The logbook also records her visits at the altar. The altar attracts programmers from all over the world because one...
```python import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**10 mod = 10**9+7 dd = [(0,-1),(1,0),(0,1),(-1,0)] ddn = [(0,-1),(1,-1),(1,0),(1,1),(0,1),(-1,-1),(-1,0),(-1,1)] def LI(): return [int(x) for x in ...
vfc_60801
{ "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": "14\n04/21 09:00 I 000\n04/21 09:00 I 001\n04/21 09:15 I 002\n04/21 09:30 O 001\n04/21 09:45 O 000\n04/21 10:00 O 002\n04/28 09:00 I 003\n04/28 09:15 I 000\n04/28 09:30 I 004\n04/28 09:45 O 004\n04/28 10:00 O 000\n04/28 10:15 O 003\...
code_contests
verifiable_code
p01027 WW
Solve the following coding problem using the programming language python: Problem In 19XX, the Allied Forces were formed in n countries. Each country belonging to the Allied Forces has set up one or more bases in the country to protect itself from the invasion of enemy forces and is on the alert. Figure 1 shows an ex...
vfc_60805
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 268435456, "problem_url": null, "time_limit": "{'seconds': 8, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\nchinax 1\nok 1\naustraria 2\n6\nchinax 0 austraria 0 5\naustraria 0 chinax 0 5\naustraria 1 austraria 0 1\nok 0 austraria 0 5\naustraria 0 ok 0 5\nok 0 austraria 1 1\n2\nchinax 0\nok 0", "output": "10\nchinax 0 austraria 0...
code_contests
verifiable_code
p01158 Rock Man
Solve the following coding problem using the programming language python: You were the master craftsman in the stone age, and you devoted your life to carving many varieties of tools out of natural stones. Your works have ever been displayed respectfully in many museums, even in 2006 A.D. However, most people visiting...
```python import sys sys.setrecursionlimit(10000) def checkloop(pdict,product,inroute,made): inroute.append(product) if pdict[product][1] in made: return (False,product) elif pdict[product][1]==product: return (False,product) elif pdict[product][1] in inroute: return (True,pdic...
vfc_60809
{ "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\ngu 20 pa 10\nci 20 gu 10\npa 20 ci 10\n2\ntool 20 tool 10\nproduct 1000 tool 10\n8\nfishhook 21 disk 3\nmill 14 axe 7\nboomerang 56 sundial 28\nflint 35 fishhook 5\naxe 35 flint 14\ndisk 42 disk ...
code_contests
verifiable_code
p01297 Safe Area
Solve the following coding problem using the programming language python: Nathan O. Davis is challenging a kind of shooter game. In this game, enemies emit laser beams from outside of the screen. A laser beam is a straight line with a certain thickness. Nathan moves a circular-shaped machine within the screen, in such...
```python import sys readline = sys.stdin.readline write = sys.stdout.write def cross_point(p0, q0, p1, q1): x0, y0 = p0; x1, y1 = q0 x2, y2 = p1; x3, y3 = q1 dx0 = x1 - x0 dy0 = y1 - y0 dx1 = x3 - x2 dy1 = y3 - y2 s = (y0-y2)*dx1 - (x0-x2)*dy1 sm = dx0*dy1 - dy0*dx1 if sm == 0: ...
vfc_60813
{ "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": "100 100 1 1\n50 0 50 100 50\n640 480 1 1\n0 0 640 480 100\n0 0 0 0", "output": "No\nYes", "type": "stdin_stdout" }, { "fn_name": null, "input": "100 100 1 1\n50 0 50 100 50\n640 480 1 2\n0 0 640 480 ...
code_contests
verifiable_code
p01626 MirrorLabyrinth
Solve the following coding problem using the programming language python: As a proud hero, you are finally about to reach the Demon King. However, in order to reach the throne where the Demon King is, you must clear the final map prepared by the Demon King. In this map, everything changes like a two-dimensional plan ...
vfc_60821
{ "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\n3\n1 1\n2 2\n1 2\n3\n-1 1\n-1 2\n-2 2\n1 1 2 2\n0 0 0 1\n2\n10\n1 1\n7 1\n7 5\n5 5\n5 3\n6 3\n6 2\n3 2\n3 5\n1 5\n10\n-1 1\n-1 5\n-3 5\n-3 3\n-2 3\n-2 2\n-5 2\n-5 5\n-7 5\n-7 1\n2 4 6 4\n0 0 0 1\n2\n7\n-7 0\n-5 0\n-4 3\n-3 0\n-1...
code_contests
verifiable_code
p01778 Dungeon of Cards
Solve the following coding problem using the programming language python: G: Dungeon of Cards story This is a wonderland hydrangea. It is said that gold and silver treasures sleep in the labyrinth of cards located in the remote area of ​​Ajifurai. As soon as the curious Aizu Nyan heard this legend, he decided to tak...
vfc_60825
{ "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": "4\nD 1\nD 2\nA 3\nD 4\n4\nA 1 7\nD 4 5\nD 3 6\nB 3 3", "output": "6", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\nD 1\nD 2\nA 3\nD 4\n4\nA 1 7\nD 4 5\nD 3 6\nA 3 3", "output": "6\...
code_contests
verifiable_code
p02193 Range Min of Max Query
Solve the following coding problem using the programming language python: Range Min of Max Query Given a sequence of integer pairs (a_1, b_1), (a_2, b_2), .., (a_N, b_N). Handle two types of queries. The first type of query adds X to a_L, a_ {L + 1}, .., a_R. The second type of query finds the minimum values ​​of ...
vfc_60837
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 1073741824, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6 6\n8 1\n6 1\n9 4\n1 5\n2 1\n1 4\n2 1 3\n1 1 3 3\n2 1 3\n2 4 6\n1 4 6 3\n2 4 6", "output": "6\n9\n2\n4", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 6\n8 1\n6 1\n9 4\n1 5\n2 1\n1 4\n2 1...
code_contests
verifiable_code
p02347 Range Search (kD Tree)
Solve the following coding problem using the programming language python: The range search problem consists of a set of attributed records S to determine which records from S intersect with a given range. For n points on a plane, report a set of points which are within in a given range. Note that you do not need to c...
```python import math import sys from bisect import bisect_left, bisect_right from typing import List, Optional, Tuple class KDTree(object): def __init__(self, n: int) -> None: self.n = n self.root = int(math.sqrt(n)) self.coordinates = [(0, 0, 0)] * n self.low: List[int] = [] ...
vfc_60841
{ "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": "6\n2 1\n2 2\n4 2\n6 2\n3 3\n5 4\n2\n2 4 0 4\n4 10 2 5", "output": "0\n1\n2\n4\n\n2\n3\n5", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n2 1\n2 2\n4 2\n6 2\n3 6\n5 4\n2\n2 4 0 4\n4 10 2 5...
code_contests
verifiable_code
cdthn
Solve the following coding problem using the programming language python: Nitesh recently discovered a new game CODATHON with the help of a very intelligent alien friend Jupiter. In this game a student had various challenges and each challenge had infinite number of problems. The scoring system in this game was quite ...
```python import sys f = sys.stdin MOD = 1000000007 T = int(f.readline()) while T: A,B = [int(x) for x in f.readline().split()] ans = A * B - A - B ans %= MOD if ans < 0 : ans += MOD print ans T -= 1 ```
vfc_60845
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n3 4\n5 7", "output": "5\n23", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
daily
Solve the following coding problem using the programming language python: A daily train consists of N cars. Let's consider one particular car. It has 54 places numbered consecutively from 1 to 54, some of which are already booked and some are still free. The places are numbered in the following fashion: The car is se...
```python first = raw_input() inp = first.split() x = int(inp[0]) y = int(inp[1]) train = [] ans = 0 for i in range(y): train.append(str(raw_input())) strin = str(train[i]) empty = [] empty.append(int( 6 - (int(strin[0])+int(strin[1])+int(strin[2])+int(strin[3])+int(strin[52])+int(strin[53])))) empty.app...
vfc_60849
{ "difficulty": "2", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 3\n100101110000001011000001111110010011110010010111000101\n001010000000101111100000000000000111101010101111111010\n011110011110000001010100101110001011111010001001111010", "output": "85\n", "type": "stdin_stdout" ...
code_contests
verifiable_code
idclove
Solve the following coding problem using the programming language python: Valentine's Day is coming and our friend Mr.IDC has fallen in love with a girl. He just could not control his feelings and went to propose her. When he proposed her the girl gave him a challenge and asked him to solve it and the condition was if...
```python for _ in range(input()): n,m=map(int,raw_input().split()) if n<m: print n*(n+1)/2 elif n==m: print n*(n-1)/2 else: print (m*(m-1)/2)*(n//m)+(((n%m)*(n%m+1))/2) ```
vfc_60853
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n20 5\n10 2\n5 3", "output": "40\n5\n6", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
mstick
Solve the following coding problem using the programming language python: Chef Ceil has some matchsticks in his kitchen. Detail of matchsticks: There are N matchsticks in total. They are numbered from to 0 to N-1 inclusive. All matchsticks have same length. But they may have different rates of burning. For i^th matchs...
```python intMax = 10**8+1 def treeQuery(tree1, tree2, start, end, rangeStart, rangeEnd, index): if rangeStart<=start and rangeEnd>=end: return tree1[index], tree2[index] if end<rangeStart or start>rangeEnd: return intMax, -1 middleIndex = (start + end) / 2 a,c = treeQuery(tree1, tree2, ...
vfc_60857
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "18\n3 4 2 1 5 7 9 7 10 5 12 3 1 1 2 1 3 2\n1\n4 10", "output": "9.0\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
rolldeep
Solve the following coding problem using the programming language python: "I heard that you're settled down That you found a girl and you're married now. I heard that your dreams came true. Guess she gave you things I didn't give to you." Adele just got news about her old lover. She is in her study, re...
```python a=raw_input() c=0 m=0 s='' sTemp='' for i in a: if i=='(': c+=1 sTemp='' else: if i==')' and c>m: s=sTemp sTemp='' m=c c-=1 else: if i==')': c-=1 sTemp='' else: ...
vfc_60861
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "((Never mind(I'll find(someone like you))))", "output": "someone like you\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
vogozo
Solve the following coding problem using the programming language python: On the icy planet Zorg, the Vogons are putting together a zoo. One cage will house a collection of Kubudu dragons. Unlike the limited number of blood types found in other creatures, Kubudu dragons have a large variety of blood types. Each dragon...
```python N,K = map(int, raw_input().split()) L = sorted(set(map(int, raw_input().split()))) cmax = 0 cur_index = 0 cur_val = L[cur_index] #import time while 1: #print "loop,",L if cur_index == len(L)-1: break j = cur_index cur_count = 1 loop_val = L[j] L[j]=0 #print "{} {} {}".fo...
vfc_60865
{ "difficulty": "4", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "12 3 \n1 5 6 1 8 3 12 2 13 7 9 11", "output": "4", "type": "stdin_stdout" }, { "fn_name": null, "input": "11 3 \n1 5 6 1 8 3 12 2 13 7 9 11", "output": "4\n", "type": "stdin_stdout" }...
code_contests
verifiable_code
101_A. Homework
Solve the following coding problem using the programming language python: Once when Gerald studied in the first year at school, his teacher gave the class the following homework. She offered the students a string consisting of n small Latin letters; the task was to learn the way the letters that the string contains ar...
```python from collections import Counter import operator import random a=list(input()) k=int(input()) omap=(Counter(a)) x=sorted(omap.items(), key = operator.itemgetter(1)) i=0 while(k>0 and i<len(x)): if(x[i][1]<=k): k=k-x[i][1] del omap[x[i][0]] else: omap[x[i][0]]=omap[x[i][0]]-k k=0 i+=1 print(len(oma...
vfc_60869
{ "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": "abacaba\n4\n", "output": "1\naaaa\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "aaaaa\n4\n", "output": "1\naaaaa\n", "type": "stdin_stdout" }, { "fn_name": null...
code_contests
verifiable_code
1042_E. Vasya and Magic Matrix
Solve the following coding problem using the programming language python: Vasya has got a magic matrix a of size n × m. The rows of the matrix are numbered from 1 to n from top to bottom, the columns are numbered from 1 to m from left to right. Let a_{ij} be the element in the intersection of the i-th row and the j-th...
```python import io, os ns = iter(os.read(0, os.fstat(0).st_size).split()).__next__ MX = 10 ** 6 MOD = 998244353 n, m = int(ns()), int(ns()) a = [int(ns()) for i in range(n * m)] s = (int(ns()) - 1) * m + int(ns()) - 1 inv = [1] * MX for i in range(2, MX): inv[i] = -(MOD // i) * inv[MOD % i] % MOD ind = sorted(...
vfc_60873
{ "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": "2 3\n1 5 7\n2 3 1\n1 2\n", "output": "665496238\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 4\n1 1 2 1\n1 3\n", "output": "2\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
1065_D. Three Pieces
Solve the following coding problem using the programming language python: You stumbled upon a new kind of chess puzzles. The chessboard you are given is not necesserily 8 × 8, but it still is N × N. Each square has some number written on it, all the numbers are from 1 to N^2 and all the numbers are pairwise distinct. ...
```python import sys from math import * def minp(): return sys.stdin.readline().strip() n = int(minp()) m = [None]*n k = [None]*3 dp = [None]*3 dp[0] = [None]*(n*n) dp[1] = [None]*(n*n) dp[2] = [None]*(n*n) path = [None]*(n*n) for i in range(n): m[i] = list(map(int, minp().split())) for j in range(n): path[m[i][...
vfc_60877
{ "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": "3\n1 9 3\n8 6 7\n4 2 5\n", "output": "12 1", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n32 17 18 23 26 33\n7 36 22 3 1 5\n30 9 8 34 27 21\n16 6 35 28 4 25\n29 19 24 13 11 12\n2 20 15 1...
code_contests
verifiable_code
1088_B. Ehab and subtraction
Solve the following coding problem using the programming language python: You're given an array a. You should repeat the following operation k times: find the minimum non-zero element in the array, print it, and then subtract it from all the non-zero elements of the array. If all the elements are 0s, just print 0. In...
```python # coding: utf-8 # Your code here! import sys n,k = map(int,input().split()) A = list(map(int,input().split())) A.sort() cnt = 0 prev = 0 for i in range(len(A)): ans = A[i] - prev if ans != 0: print(ans) prev = A[i] cnt += 1 if cnt == k: break for _ in ...
vfc_60881
{ "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\n", "output": "1\n1\n1\n0\n0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 2\n10 3 5 3\n", "output": "3\n2\n", "type": "stdin_stdout" }, { "fn_name...
code_contests
verifiable_code
1107_B. Digital root
Solve the following coding problem using the programming language python: Today at the lesson of mathematics, Petya learns about the digital root. The digital root of a non-negative integer is the single digit value obtained by an iterative process of summing digits, on each iteration using the result from the previo...
```python n = int(input()) for _ in range(n): k,x = map(int,input().split(" ")) print((k-1)*9+x) ```
vfc_60885
{ "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\n1 5\n5 2\n3 1\n", "output": "5\n38\n19\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n123421 1\n", "output": "1110781\n", "type": "stdin_stdout" }, { "fn_n...
code_contests
verifiable_code
1136_B. Nastya Is Playing Computer Games
Solve the following coding problem using the programming language python: Finished her homework, Nastya decided to play computer games. Passing levels one by one, Nastya eventually faced a problem. Her mission is to leave a room, where a lot of monsters live, as quickly as possible. There are n manholes in the room w...
```python n,k=map(int,input().split()) print(n+min(k-1,n-k)+2*n) ```
vfc_60889
{ "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 1\n", "output": "15\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 2\n", "output": "6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 2\n"...
code_contests
verifiable_code
1154_F. Shovels Shop
Solve the following coding problem using the programming language python: There are n shovels in the nearby shop. The i-th shovel costs a_i bourles. Misha has to buy exactly k shovels. Each shovel can be bought no more than once. Misha can buy shovels by several purchases. During one purchase he can choose any subse...
```python from sys import stdin, stdout n, m, k = tuple(map(lambda x: int(x), stdin.readline().split())) a = stdin.readline().split() for i in range(len(a)): a[i] = int(a[i]) prefix_sum = [] a = sorted(a, key=lambda x: x) for x in a: if prefix_sum: prefix_sum.append(prefix_sum[-1] + x) else: ...
vfc_60893
{ "difficulty": "12", "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 1 4\n2 5 7 4 6\n5 4\n", "output": "17\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "9 4 8\n6 8 5 1 8 1 1 2 1\n9 2\n8 4\n5 3\n9 7\n", "output": "17\n", "type": "stdin_stdout...
code_contests
verifiable_code
1176_D. Recover it!
Solve the following coding problem using the programming language python: Authors guessed an array a consisting of n integers; each integer is not less than 2 and not greater than 2 ⋅ 10^5. You don't know the array a, but you know the array b which is formed from it with the following sequence of operations: 1. Fir...
```python from sys import stdin, stdout import collections import math import heapq def primes(n): """ Returns a list of primes < n """ sieve = [True] * n for i in range(3,int(n**0.5)+1,2): if sieve[i]: sieve[i*i::2*i]=[False]*((n-i*i-1)//(2*i)+1) return [2] + [i for i in range(3,n...
vfc_60897
{ "difficulty": "10", "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\n3 5 2 3 2 4\n", "output": "3 4 2 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n3 6\n", "output": "6 ", "type": "stdin_stdout" }, { "fn_name": null, "...
code_contests
verifiable_code
1195_C. Basketball Exercise
Solve the following coding problem using the programming language python: Finally, a basketball court has been opened in SIS, so Demid has decided to hold a basketball exercise session. 2 ⋅ n students have come to Demid's exercise session, and he lined up them into two rows of the same size (there are exactly n people...
```python n=int(input()) a=[int(x) for x in input().split()] b=[int(x) for x in input().split()] dp=[[-1,-1] for i in range(n-1)] dp.append([a[n-1],b[n-1]]) dp.append([0,0]) for i in range(n-1): dp[n-2-i][0]=a[n-2-i]+max(dp[n-1-i][1],dp[n-i][1]) dp[n-2-i][1]=b[n-2-i]+max(dp[n-1-i][0],dp[n-i][0]) print(max(dp[0]...
vfc_60901
{ "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": "5\n9 3 5 7 3\n5 8 1 4 5\n", "output": "29\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n7\n4\n", "output": "7\n", "type": "stdin_stdout" }, { "fn_name": null...
code_contests
verifiable_code
1234_E. Special Permutations
Solve the following coding problem using the programming language python: Let's define p_i(n) as the following permutation: [i, 1, 2, ..., i - 1, i + 1, ..., n]. This means that the i-th permutation is almost identity (i.e. which maps every element to itself) permutation but the element i is on the first position. Exa...
```python """ > File Name: e.py > Author: Code_Bear > Mail: secret > Created Time: Tue Oct 15 17:00:25 2019 """ #import sys #input = sys.stdin.readline def solver(): n, m = map(int, input().split()) s = list(map(int, input().split())) xin, xout = [0] * (n + 10), [0] * (n + 10) xsum = [...
vfc_60909
{ "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 5\n2 1 5 3 5\n", "output": "9 8 12 6 8 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 4\n1 2 3 4\n", "output": "3 4 6 5 ", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1253_D. Harmonious Graph
Solve the following coding problem using the programming language python: You're given an undirected graph with n nodes and m edges. Nodes are numbered from 1 to n. The graph is considered harmonious if and only if the following property holds: * For every triple of integers (l, m, r) such that 1 ≤ l < m < r ≤ n, ...
```python import sys input = sys.stdin.buffer.readline sys.setrecursionlimit(300000) n, m = map(int, input().split()) sn, smx = list(range(n+1)), list(range(n+1)) def s_find(u): p = [] while sn[u] != u: p.append(u) u = sn[u] for v in p: sn[v] = u return u def s_union(u, v): su, sv...
vfc_60913
{ "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": "200000 3\n7 9\n9 8\n4 5\n", "output": "0\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1277_C. As Simple as One and Two
Solve the following coding problem using the programming language python: You are given a non-empty string s=s_1s_2... s_n, which consists only of lowercase Latin letters. Polycarp does not like a string if it contains at least one string "one" or at least one string "two" (or both at the same time) as a substring. In...
```python t = int(input()) for _ in range(t): s = input() i = 0 R = [] while i < len(s): # print(s[i:i+5]) if i+4<len(s) and s[i:i+5] == "twone": # print('paso') R.append(i+2+1) i+=5 elif i+2<len(s) and (s[i:i+3] == "one" or s[i:i+3] == "two"):...
vfc_60917
{ "difficulty": "9", "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\nonetwonetwooneooonetwooo\ntwo\none\ntwooooo\nttttwo\nttwwoo\nooone\nonnne\noneeeee\noneeeeeeetwooooo\n", "output": "6\n2 6 10 13 18 21\n1\n2\n1\n2\n1\n2\n1\n5\n0\n\n1\n4\n0\n\n1\n2\n2\n2 11\n", "type": "stdin_stdout...
code_contests
verifiable_code
1320_D. Reachable Strings
Solve the following coding problem using the programming language python: In this problem, we will deal with binary strings. Each character of a binary string is either a 0 or a 1. We will also deal with substrings; recall that a substring is a contiguous subsequence of a string. We denote the substring of string s st...
```python import sys input = sys.stdin.readline n=int(input()) t=input().strip() q=int(input()) ZEROS=[0]*n ZERO_ONE=[] ONECOUNT=[0]*n ind=0 count=0 for i in range(n): ZEROS[i]=ind if t[i]=="0": ind+=1 ONECOUNT[i]=count%2 ZERO_ONE.append(count%2) count=0 else: coun...
vfc_60925
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n11011\n3\n1 3 3\n1 4 2\n1 2 3\n", "output": "Yes\nYes\nNo\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n010\n3\n1 3 1\n1 3 1\n3 2 1\n", "output": "Yes\nYes\nNo\n", "typ...
code_contests
verifiable_code
133_B. Unary
Solve the following coding problem using the programming language python: Unary is a minimalistic Brainfuck dialect in which programs are written using only one token. Brainfuck programs use 8 commands: "+", "-", "[", "]", "<", ">", "." and "," (their meaning is not important for the purposes of this problem). Unary...
```python # n=bin() s=input() ans="" for i in s: if i==">": ans+="1000" elif i=="<": ans+="1001" elif i =="+": ans+="1010" elif i=="-": ans+="1011" elif i==".": ans+="1100" elif i==",": ans+="1101" elif i=="[": ans+="1110" elif i=...
vfc_60929
{ "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": "++++[&gt;,.&lt;-]\n", "output": "122016\n", "type": "stdin_stdout" }, { "fn_name": null, "input": ",.\n", "output": "220\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
1361_C. Johnny and Megan's Necklace
Solve the following coding problem using the programming language python: Johnny's younger sister Megan had a birthday recently. Her brother has bought her a box signed as "Your beautiful necklace — do it yourself!". It contains many necklace parts and some magic glue. The necklace part is a chain connecting two pea...
vfc_60933
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n13 11\n11 1\n3 5\n17 1\n9 27\n", "output": "3\n7 8 4 3 2 1 6 5 10 9\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n13 11\n11 1\n3 5\n17 1\n7 29\n", "output": "2\n1 2 3 4 7 8 6...
code_contests
verifiable_code
1401_E. Divide Square
Solve the following coding problem using the programming language python: There is a square of size 10^6 × 10^6 on the coordinate plane with four points (0, 0), (0, 10^6), (10^6, 0), and (10^6, 10^6) as its vertices. You are going to draw segments on the plane. All segments are either horizontal or vertical and inter...
```python import sys, math import io, os data = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline #from bisect import bisect_left as bl, bisect_right as br, insort #from heapq import heapify, heappush, heappop #from collections import defaultdict as dd, deque, Counter #from itertools import permutations,combinations ...
vfc_60941
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 384000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 3\n2 3 1000000\n4 0 4\n3 0 1000000\n4 0 1\n2 0 5\n3 1 1000000\n", "output": "7\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 0\n3 1 1000000\n1 1 1000000\n2 1 1000000\n", "outpu...
code_contests
verifiable_code
1424_L. Milutin's Plums
Solve the following coding problem using the programming language python: As you all know, the plum harvesting season is on! Little Milutin had his plums planted in an orchard that can be represented as an n by m matrix. While he was harvesting, he wrote the heights of all trees in a matrix of dimensions n by m. At n...
vfc_60945
{ "difficulty": "19", "memory_limit": null, "memory_limit_bytes": 1024000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 5\n13 15 10 9 15\n15 17 12 11 17\n10 12 7 6 12\n17 19 14 13 19\n16 18 13 12 18\n", "output": "? 2 1\n? 2 2\n? 3 2\n? 3 3\n? 2 3\n? 3 4\n? 4 4\n? 4 5\n? 3 5\n? 4 1\n? 4 3\n? 1 1\n? 3 1\n? 5 3\n? 5 4\n? 5 5\n! 6\n", "ty...
code_contests
verifiable_code
1446_C. Xor Tree
Solve the following coding problem using the programming language python: For a given sequence of distinct non-negative integers (b_1, b_2, ..., b_k) we determine if it is good in the following way: * Consider a graph on k nodes, with numbers from b_1 to b_k written on them. * For every i from 1 to k: find such j...
```python from bisect import bisect_left import os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n=int(input()) a=list(map(int,input().split())) a.sort() ans=0 tmp=0 t=bisect_left(a,0) s=bisect_left(a,1<<31) stack=[(0,1<<31,t,s,0)] while stack: l,r,l1,r1,score=stack.pop() ans=max(score,ans) if l+1=...
vfc_60949
{ "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": "5\n0 1 5 2 6\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "7\n6 9 8 7 3 5 2\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
1470_C. Strange Shuffle
Solve the following coding problem using the programming language python: This is an interactive problem. n people sitting in a circle are trying to shuffle a deck of cards. The players are numbered from 1 to n, so that players i and i+1 are neighbours (as well as players 1 and n). Each of them has exactly k cards, w...
vfc_60953
{ "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": "4 2\n\n2\n\n1\n\n2\n\n3\n\n2\n", "output": "\n? 1\n\n? 1\n\n? 2\n\n? 3\n\n? 4\n\n! 2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "64332 1000000000 30147\n", "output": "648", ...
code_contests
verifiable_code
1497_B. M-arrays
Solve the following coding problem using the programming language python: You are given an array a_1, a_2, …, a_n consisting of n positive integers and a positive integer m. You should divide elements of this array into some arrays. You can order the elements in the new arrays as you want. Let's call an array m-divi...
```python import math for _ in range(int(input())): n,m=map(int,input().split()) a=list(map(int,input().split())) rems=[0]*m for e in a: rems[e%m]+=1 ans=1 if rems[0]>0 else 0 for i in range(1,m//2+1): if rems[i]==0 and rems[m-i]==0: continue ma...
vfc_60957
{ "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": "4\n6 4\n2 2 8 6 9 4\n10 8\n1 1 1 5 2 4 4 8 6 7\n1 1\n666\n2 2\n2 4\n", "output": "\n3\n6\n1\n1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n6 4\n1 2 8 6 9 4\n10 8\n1 1 1 5 2 4 4 8 6 ...
code_contests
verifiable_code
151_A. Soft Drinking
Solve the following coding problem using the programming language python: This winter is so cold in Nvodsk! A group of n friends decided to buy k bottles of a soft drink called "Take-It-Light" to warm up a bit. Each bottle has l milliliters of the drink. Also they bought c limes and cut each of them into d slices. Aft...
```python party = list(map(int, input().split())) friends, bottles, ml, limes, lime_slices, salt, friend_ml, friend_salt = party total_gas = bottles * ml total_limes = limes * lime_slices rotation_ml = friend_ml * friends q_tosts = -1 while all(x >= 0 for x in (salt, total_gas, total_limes)): total_gas -= rota...
vfc_60961
{ "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 4 5 10 8 100 3 1\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 100 10 1 19 90 4 3\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name...
code_contests
verifiable_code
174_C. Range Increments
Solve the following coding problem using the programming language python: Polycarpus is an amateur programmer. Now he is analyzing a friend's program. He has already found there the function rangeIncrement(l, r), that adds 1 to each element of some array a for all indexes in the segment [l, r]. In other words, this fu...
```python n = int(input()) big = 10 ** 5 last = (big + 1) * [ -1 ] data = list(map(int, input().split())) data.insert(0, 0) data.append(0) result = [] previous = 0 for pos, current in enumerate(data): if current > previous: for x in range(previous + 1, current + 1): last[x] = pos elif curre...
vfc_60969
{ "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\n1 2 1 1 4 1\n", "output": "5\n2 2\n5 5\n5 5\n5 5\n1 6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n1 0 1 0 1\n", "output": "3\n1 1\n3 3\n5 5\n", "type": "stdin_stdout"...
code_contests
verifiable_code
194_D. Xor
Solve the following coding problem using the programming language python: John Doe has four arrays: a, b, k, and p. Each array consists of n integers. Elements of all arrays are indexed starting from 1. Array p is a permutation of integers 1 to n. John invented a game for his friends and himself. Initially a player i...
vfc_60973
{ "difficulty": "10", "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 2 1\n7 7 7\n8 8 8\n1 2 3\n1 3 2\n", "output": "96\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 1 0\n1 1\n1 1\n1 -1\n1 2\n", "output": "0\n", "type": "stdin_stdout" }...
code_contests
verifiable_code
218_D. Blackboard Fibonacci
Solve the following coding problem using the programming language python: Fibonacci numbers are the sequence of integers: f0 = 0, f1 = 1, f2 = 1, f3 = 2, f4 = 3, f5 = 5, ..., fn = fn - 2 + fn - 1. So every next number is the sum of the previous two. Bajtek has developed a nice way to compute Fibonacci numbers on a bl...
vfc_60977
{ "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": "4 5\n", "output": "0\nTBTB\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 10\n", "output": "2\nTBBTTB\n", "type": "stdin_stdout" }, { "fn_name": null, "i...
code_contests
verifiable_code
242_A. Heads or Tails
Solve the following coding problem using the programming language python: Petya and Vasya are tossing a coin. Their friend Valera is appointed as a judge. The game is very simple. First Vasya tosses a coin x times, then Petya tosses a coin y times. If the tossing player gets head, he scores one point. If he gets tail,...
```python x, y, a, b = map(int, input().split()) ans = [] for x1 in range(a,x+1): if x1<=b: continue for y1 in range(b,y+1): if x1>y1 and x1>=a and y1>=b: ans.append((x1,y1)) print(len(ans)) for x in ans: print(*x) ```
vfc_60981
{ "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 2 1 1\n", "output": "3\n2 1\n3 1\n3 2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 4 2 2\n", "output": "0\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
267_B. Dominoes
Solve the following coding problem using the programming language python: You have a set of dominoes. Each domino is a rectangular tile with a line dividing its face into two square ends. Can you put all dominoes in a line one by one from left to right so that any two dominoes touched with the sides that had the same ...
```python def euler(start): s = [(start,0)] ans = [] while s: i,e = s[-1] if i in mark: mark.remove(i) if degree[i]==0: ans.append(e) s.pop() else: for j,e in graph[i]: if vis[abs(e)]==0: d...
vfc_60985
{ "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": "5\n1 2\n2 4\n2 4\n6 4\n2 1\n", "output": "4 +\n2 -\n1 -\n5 -\n3 +\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "100\n5 0\n6 4\n1 6\n2 2\n4 0\n0 4\n4 4\n4 0\n6 6\n0 2\n3 2\n0 4\n0 4\n2 0\...
code_contests
verifiable_code
290_B. QR code
Solve the following coding problem using the programming language python: <image> Input The input contains two integers a1, a2 (0 ≤ ai ≤ 32), separated by a single space. Output Output a single integer. Examples Input 1 1 Output 0 Input 3 7 Output 0 Input 13 10 Output 1 The input will be given v...
```python num = input().split() print(int(num[0]) + int(num[1][::-1])) ```
vfc_60989
{ "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": "13 10\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 7\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1\n...
code_contests
verifiable_code
316_A2. Special Task
Solve the following coding problem using the programming language python: Special Agent Smart Beaver works in a secret research department of ABBYY. He's been working there for a long time and is satisfied with his job, as it allows him to eat out in the best restaurants and order the most expensive and exotic wood ty...
```python import math ''' r,c,n,k = map(int,input().split()) matrix = [['*' for row in range(c)] for column in range(r)] for i in range(n): x,y = map(int,input().split()) matrix[x-1][y-1] = '#' ans = 0 for row1 in range(r): for row2 in range(r): if matrix[row1:row2+1].count('#') >= k: an...
vfc_60993
{ "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": "1?AA\n", "output": "100", "type": "stdin_stdout" }, { "fn_name": null, "input": "AJ\n", "output": "81", "type": "stdin_stdout" }, { "fn_name": null, "input": "???\n", ...
code_contests
verifiable_code
338_D. GCD Table
Solve the following coding problem using the programming language python: Consider a table G of size n × m such that G(i, j) = GCD(i, j) for all 1 ≤ i ≤ n, 1 ≤ j ≤ m. GCD(a, b) is the greatest common divisor of numbers a and b. You have a sequence of positive integer numbers a1, a2, ..., ak. We say that this sequence...
```python from math import gcd def LCM(a, b): if min(a, b) == 0: return max(a, b) return a // gcd(a, b) * b class Eqn(): def __init__(self, r, mod): self.r = r self.mod = mod def bye(): print("NO") exit(0) def exgcd(a, b): if b == 0: return (1, 0) xp, yp = e...
vfc_60997
{ "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": "100 8 5\n5 2 1 2 1\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "100 100 7\n1 2 3 4 5 6 7\n", "output": "NO\n", "type": "stdin_stdout" }, { "f...
code_contests
verifiable_code
361_A. Levko and Table
Solve the following coding problem using the programming language python: Levko loves tables that consist of n rows and n columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals k. Unfortunately, he doesn't know any such ...
```python n, p = map(int, input().split()) for i in range(n): arr = [] for j in range(n): arr.append("0") arr[i] = str(p) answer = " ".join(arr) print(answer) ```
vfc_61001
{ "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 7\n", "output": "7 0 0 0 \n0 7 0 0 \n0 0 7 0 \n0 0 0 7 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 4\n", "output": "4 0 \n0 4 \n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
432_D. Prefixes and Suffixes
Solve the following coding problem using the programming language python: You have a string s = s1s2...s|s|, where |s| is the length of string s, and si its i-th character. Let's introduce several definitions: * A substring s[i..j] (1 ≤ i ≤ j ≤ |s|) of string s is string sisi + 1...sj. * The prefix of string s...
```python def zeta(s): n = len(s) z = [0]*n l,r = 0,0 for i in range(1,n): if(i<=r): z[i] = min(r-i+1,z[i-l]) while(i+z[i]<n and s[z[i]]==s[i+z[i]]): z[i]+=1 if(i+z[i]-1>r): l=i r = i+z[i]-1 return z s = input() n = len(s) z = zeta(s) l = [0]*n for i in z: l[i]+=1 cum = [l[-1]] for i in range(n-2,-...
vfc_61013
{ "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": "AAA\n", "output": "3\n1 3\n2 2\n3 1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "ABACABA\n", "output": "3\n1 4\n3 2\n7 1\n", "type": "stdin_stdout" }, { "fn_na...
code_contests
verifiable_code
455_A. Boredom
Solve the following coding problem using the programming language python: Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it. Given a sequence a consisting of n integers. The player can make several steps. In a si...
```python n = int(input()) l = input().split() g = [0]*100000 for i in l: g[int(i)-1] += 1 ''' p = [] a = [] for i in range(100000): b = g[i] if b!=0: a.append((i+1)*b) else: if a != []: p.append(a) a = [] def f(v): if v==[]: return 0 elif len(v)==...
vfc_61017
{ "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\n1 2 3\n", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "9\n1 2 1 3 2 2 2 2 3\n", "output": "10\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
477_D. Dreamoon and Binary
Solve the following coding problem using the programming language python: Dreamoon saw a large integer x written on the ground and wants to print its binary form out. Dreamoon has accomplished the part of turning x into its binary format. Now he is going to print it in the following manner. He has an integer n = 0 an...
vfc_61021
{ "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": "101\n", "output": " 1\n 6\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
500_A. New Year Transportation
Solve the following coding problem using the programming language python: New Year is coming in Line World! In this world, there are n cells numbered by integers from 1 to n, as a 1 × n board. People live in cells. However, it was hard to move between distinct cells, because of the difficulty of escaping the cell. Peo...
```python a, b = map(int, input().split()) c = list(map(int, input().split())) d = 0 while d < b - 1: d += c[d] if d == b - 1: print("YES") else: print("NO") ```
vfc_61025
{ "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": "8 4\n1 2 1 2 1 2 1\n", "output": "YES", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
525_D. Arthur and Walls
Solve the following coding problem using the programming language python: Finally it is a day when Arthur has enough money for buying an apartment. He found a great option close to the center of the city with a nice price. Plan of the apartment found by Arthur looks like a rectangle n × m consisting of squares of siz...
vfc_61029
{ "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 5\n.....\n.....\n..***\n..*..\n", "output": ".....\n.....\n.....\n.....\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
550_E. Brackets in Implications
Solve the following coding problem using the programming language python: Implication is a function of two logical arguments, its value is false if and only if the value of the first argument is true and the value of the second argument is false. Implication is written by using character '<image>', and the arguments...
```python n = int(input()) c = list(map(int, input().split())) idx = [i for i in range(n) if c[i] == 0] one = [i for i in range(n) if c[i] == 1] if len(idx) >= 1 and idx[-1] == n-1: if len(idx) >= 2 and idx[-2] == n-2: if len(idx) >= 3 and idx[-3] <= n-3: if idx[0] == 0: print("...
vfc_61033
{ "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": "4\n0 1 1 0\n", "output": "YES\n0->1->1->0", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n0\n", "output": "YES\n0", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
578_A. A Problem about Polyline
Solve the following coding problem using the programming language python: There is a polyline going through points (0, 0) – (x, x) – (2x, 0) – (3x, x) – (4x, 0) – ... - (2kx, 0) – (2kx + x, x) – .... We know that the polyline passes through the point (a, b). Find minimum positive value x such that it is true or dete...
```python a,b=map(float,input().split()) if b>a : print(-1) exit() v=((a+b)/2)/((a+b)//(2*b)) print(v); ```
vfc_61037
{ "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 1\n", "output": "1.2500000000\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
59_D. Team Arrangement
Solve the following coding problem using the programming language python: Recently personal training sessions have finished in the Berland State University Olympiad Programmer Training Centre. By the results of these training sessions teams are composed for the oncoming team contest season. Each team consists of three...
```python import sys I = lambda: int(input()) RL = readline = lambda: sys.stdin.readline().strip('\n') RM = readmap = lambda x = int: map(x,readline().split(' ')) def f(l,x): if x==l[0]: return l[1],l[2] if x==l[1]: return l[0],l[2] if x==l[2]: return l[0],l[1] return -1 def delrank(x): global p...
vfc_61041
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n4 1 3 2 5 6\n4 6 5\n1 2 3\n4\n", "output": "5 6 1 2 3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n5 4 1 2 6 3 7 8 9\n5 6 2\n9 3 4\n1 7 8\n4\n", "output": "2 3 5 6 9 1 7 8\n...
code_contests
verifiable_code
621_B. Wet Shark and Bishops
Solve the following coding problem using the programming language python: Today, Wet Shark is given n bishops on a 1000 by 1000 grid. Both rows and columns of the grid are numbered from 1 to 1000. Rows are numbered from top to bottom, while columns are numbered from left to right. Wet Shark thinks that two bishops at...
```python a=[0]*2001 b=[0]*2001 n=int(input()) for i in range(n): x,y=map(int,input().split()) a[x+y]+=1 b[x-y]+=1 s=0 for i in a: s=s+(i-1)*i//2 for i in b: s=s+(i-1)*i//2 print(s) ```
vfc_61045
{ "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": "3\n1 1\n2 3\n3 5\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n1 1\n1 5\n3 3\n5 1\n5 5\n", "output": "6\n", "type": "stdin_stdout" }, { "fn_...
code_contests
verifiable_code
641_G. Little Artem and Graph
Solve the following coding problem using the programming language python: Little Artem is given a graph, constructed as follows: start with some k-clique, then add new vertices one by one, connecting them to k already existing vertices that form a k-clique. Artem wants to count the number of spanning trees in this gr...
vfc_61049
{ "difficulty": "13", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 12, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 2\n1 2\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 3\n1 2 3\n", "output": "16\n", "type": "stdin_stdout" }, { "fn_name": null, "inp...
code_contests
verifiable_code
691_B. s-palindrome
Solve the following coding problem using the programming language python: Let's call a string "s-palindrome" if it is symmetric about the middle of the string. For example, the string "oHo" is "s-palindrome", but the string "aa" is not. The string "aa" is not "s-palindrome", because the second half of it is not a mirr...
```python rever = "AHIMOTUVWXYovwx" rev = ["bd", "pq","db","qp"] line = input().rstrip() if len(line) & 1 and line[len(line) // 2] not in rever: print("NIE") exit() l = len(line) // 2 - 1 r = len(line) // 2 if len(line) & 1 == 0 else\ len(line) // 2 + 1 for i in range(len(line) // 2): if line[l] + lin...
vfc_61057
{ "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": "oXoxoXo\n", "output": "TAK\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "bod\n", "output": "TAK\n", "type": "stdin_stdout" }, { "fn_name": null, "input": ...
code_contests
verifiable_code
760_D. Travel Card
Solve the following coding problem using the programming language python: A new innovative ticketing systems for public transport is introduced in Bytesburg. Now there is a single travel card for all transport. To make a trip a passenger scan his card and then he is charged according to the fare. The fare is construc...
```python #-*- coding:utf-8 -*- #!/usr/bin/python3 n = int(input()) a = [0,] for i in range(n): x = int(input()) a.append(x) dp = [0] * (n + 1) dp[0] = 0 p90 = 1 p1440 = 1 for i in range(1, n + 1): dp[i] = dp[i - 1] + 20 while a[p90] + 90 <= a[i]: p90 = p90 + 1 dp[i] = min(dp[i], dp[p90 - 1] + 50) while a[p14...
vfc_61069
{ "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": "3\n10\n20\n30\n", "output": "20\n20\n10\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
780_H. Intranet of Buses
Solve the following coding problem using the programming language python: A new bus route is opened in the city <image>. The route is a closed polygon line in the place, with all segments parallel to one of the axes. m buses will operate on the route. All buses move in a loop along the route in the same direction with...
vfc_61073
{ "difficulty": "14", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 10, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 2\n0 0\n1 0\n", "output": "0.0000000000\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
804_E. The same permutation
Solve the following coding problem using the programming language python: Seyyed and MoJaK are friends of Sajjad. Sajjad likes a permutation. Seyyed wants to change the permutation in a way that Sajjad won't like it. Seyyed thinks more swaps yield more probability to do that, so he makes MoJaK to perform a swap betwee...
```python n = int(input()) p = lambda a,b: print(a+1,b+1) if n % 4 > 1: print("NO") else: print("YES") for i in range(n%4,n,4): for x in range(2): for j in range(i): p(j,i+2*x) p(i+2*x,i+2*x+1) for j in range(i,0,-1): p(j-1,i+2*x+1) p(i,i+3) p(i+1,i+2) p(i,i+2) p(i+1,i+3) ```
vfc_61077
{ "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": "1\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "695\n", ...
code_contests
verifiable_code
82_D. Two out of Three
Solve the following coding problem using the programming language python: Vasya has recently developed a new algorithm to optimize the reception of customer flow and he considered the following problem. Let the queue to the cashier contain n people, at that each of them is characterized by a positive integer ai — tha...
```python # 82D def do(): n = int(input()) costs = [int(c) for c in input().split(" ")] next = {} memo = {} def dp(i, pre): if i == n: memo[i, pre] = [costs[pre], [pre]] return memo[i, pre] if i == n - 1: memo[i, pre] = [max(costs[pre], costs[i])...
vfc_61081
{ "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\n1 2 3 4\n", "output": "6\n1 2\n3 4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n2 4 3 1 4\n", "output": "8\n1 3\n2 5\n4\n", "type": "stdin_stdout" }, { "...
code_contests
verifiable_code
850_F. Rainbow Balls
Solve the following coding problem using the programming language python: You have a bag of balls of n different colors. You have ai balls of the i-th color. While there are at least two different colored balls in the bag, perform the following steps: * Take out two random balls without replacement one by one. Th...
vfc_61085
{ "difficulty": "12", "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 1\n", "output": "1\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
875_B. Sorting the Coins
Solve the following coding problem using the programming language python: Recently, Dima met with Sasha in a philatelic store, and since then they are collecting coins together. Their favorite occupation is to sort collections of coins. Sasha likes having things in order, that is why he wants his coins to be arranged ...
```python from sys import stdin, stdout n = int(stdin.readline()) values = list(map(int, stdin.readline().split())) used = [0 for i in range(n)] right, cnt = n, 0 ans = 1 stdout.write(str(ans) + ' ') for v in values: used[v - 1] = 1 ans += 1 while right and used[right - 1]: ans -= 1 ...
vfc_61089
{ "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": "4\n1 3 4 2\n", "output": "1 2 3 2 1 ", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
89_A. Robbery
Solve the following coding problem using the programming language python: It is nighttime and Joe the Elusive got into the country's main bank's safe. The safe has n cells positioned in a row, each of them contains some amount of diamonds. Let's make the problem more comfortable to work with and mark the cells with po...
```python #------------------------template--------------------------# import os import sys from math import * from collections import * from fractions import * from bisect import * from heapq import* from io import BytesIO, IOBase def vsInput(): sys.stdin = open('input.txt', 'r') sys.stdout = open('output.txt'...
vfc_61093
{ "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 2 2\n4 1 3\n", "output": " 2", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 3 1\n2 3\n", "output": "0\n", "type...
code_contests
verifiable_code
949_A. 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() o = -1 sol=[] p = True for i in range(0,len(s)): if s[i]=='0': if o == -1: sol.append([i+1]) else: sol[o].append(i+1) o-=1 else: o+=1 if o == len(sol): p = False break else: sol[...
vfc_61101
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "0010100\n", "output": "3\n1 1\n5 2 3 4 5 6\n1 7\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "111\n", "output": "-1\n", "type": "stdin_stdout" }, { "fn_name": n...
code_contests
verifiable_code
basu-and-love-chemistry
Solve the following coding problem using the programming language python: Ross, Chandler and Joey are best friends. One day they went to pond and Joey suggest them to play the game "Bamboozle". In this game they have N balls with each numbered from 0-9, but first ball is numbered from 1-9. Ross tells sub-strings 'S' f...
```python s=raw_input() len1=len(s) mul_ten=1 sum1=1 total_sum=len1*int(s[len1-1]) for i in range(len1-2,-1,-1): mul_ten=(mul_ten*10)%1000000007 sum1=sum1+mul_ten total_sum=(total_sum+(sum1*(i+1))*int(s[i]))%1000000007 print total_sum%1000000007 ```
vfc_61113
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "16\n\nSAMPLE", "output": "23", "type": "stdin_stdout" }, { "fn_name": null, "input": "16\n\nELPMAS", "output": "23\n", "type": "stdin_stdout" }, { "fn_name": null, "in...
code_contests
verifiable_code
city-and-flood-1
Solve the following coding problem using the programming language python: Fatland is a town that started with N distinct empires, namely empires 1, 2, ..., N. But over time, the armies of some of these empires have taken over other ones. Each takeover occurred when the army of empire i invaded empire j. After each inv...
```python ''' # Read input from stdin and provide input before running code name = raw_input('What is your name?\n') print 'Hi, %s.' % name ''' def root(i): global x while i != x[i]: i = x[i] return i n = raw_input().strip() if len(n.split()) > 1: (n, m) = map(int, n.split()) else: n = int(n) m = int(raw_inp...
vfc_61117
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n2\n1 2\n4 1\n\nSAMPLE", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "254\n50\n128 216\n56 161\n72 230\n175 108\n141 151\n249 169\n9 233\n32 85\n100 24\n107 213\n102 224\...
code_contests
verifiable_code
euler-124
Solve the following coding problem using the programming language python: Having gained some experience with Prime Numbers, Robin now seeks Revenge from Bruce. So, while they are on their way from the Airport to the Summit, Robin comes up with a new Prime based Puzzle for Bruce. He asks him to find rad(n) for t numbe...
```python limit=100000 rad={} buf={} for i in range(1,limit+1): rad[i]=1 for j in range(1,limit+1): buf[j]="" for i in range(2,limit+1): if rad[i]==1: for j in range(i,limit+1,i): rad[j]=rad[j]*i hey=rad[i] buf[hey]=buf[hey]+" "+str(i) str="" for i in buf.keys(): str=str+buf[i] str=str.split(" ")...
vfc_61121
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "100\n6451\n74308\n29045\n71720\n99096\n32196\n31151\n85640\n24317\n88001\n39081\n88765\n99510\n27026\n91492\n99379\n85315\n99440\n15214\n72870\n56522\n11836\n99137\n29128\n84189\n81146\n48602\n29042\n72858\n43179\n3314\n24053\n8828...
code_contests
verifiable_code
help-ruchi-8
Solve the following coding problem using the programming language python: Ruchi is doing her undergrad in Maths from a reputed college in New Delhi. Recently her professor gave her a problem which is baffling her for a long time. So she asks your help. Problem is: Given order of n x n matrix is it possible to find t...
```python for _ in range(input()): if input() in [2, 6]: print "No" else: print "Yes" ```
vfc_61125
{ "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\n\nSAMPLE", "output": "Yes", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n3\n\nSAMPKE", "output": "Yes\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
magic-fractions
Solve the following coding problem using the programming language python: A Magic Fraction for N is one that has the following properties: It is a proper fraction (The value is < 1) It cannot be reduced further (The GCD of the numerator and the denominator is 1) The product of the numerator and the denominator is fact...
```python i=0; arr=[] while i<=500: arr.append(True) i+=1 i=2 while i<=500: if arr[i]==True: j=2*i while j<=500: arr[j]=False j+=i i+=1 p=[] p.append(1) i=1 while i<=500: p.append(2*p[i-1]) i+=1 ans=0 s=input() n=int(s); cnt=0 if n is 1: print ("0") else: i=2 while i<=n: if arr[i]==True: c...
vfc_61129
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "8\n\nSAMPLE", "output": "29\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3", "output": "3\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
new-contest-7
Solve the following coding problem using the programming language python: Our hero - Maga is going to make a new contest for making the best teams. He is really excited about it. There will be S students in the contest. First N students in the final standings will be awarded. He has a list( favourite students list )...
```python matrix = [[0 for x in range(1007)] for x in range(1007)] n=int(1001) k=int(1001) for i in range(0,n+1): temp=min(i,k) temp=temp+1 for j in range(0,temp): if(j==0): matrix[i][j]=1 elif(j==i): matrix[i][j]=1 else: matrix[i][j]=matrix[i-1][j-1]+matrix[i-1][j] testcase=raw_input() testcase=int(t...
vfc_61133
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n10 10 5 3\n10 4 6 4\n3 2 2 1\n\nSAMPLE", "output": "1.000000\n0.071429\n1.000000", "type": "stdin_stdout" }, { "fn_name": null, "input": "100\n1000 487 496 124\n1000 955 57 16\n1000 123 729 34\n10...
code_contests
verifiable_code
professor-angry-3
Solve the following coding problem using the programming language python: The professor is conducting a course on Discrete Mathematics to a class of N students. He is angry at the lack of their discipline, and he decides to cancel the class if there are fewer than K students present after the class starts. Given the ...
```python for _ in range(input()): n,k=map(int,raw_input().split()) a=map(int,raw_input().split()) c=0 for i in range(n): if(a[i]<=0): c+=1 if(c>=k): print "NO" else: print "YES" ```
vfc_61137
{ "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 3\n-1 -3 4 2\n4 2\n0 -1 2 1\n\nSAMPLE", "output": "YES\nNO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n10 4\n-93 -86 49 -62 -90 -63 40 72 11 67\n10 10\n23 -35 -2 58 -67 -56 -4...
code_contests
verifiable_code
the-collatz
Solve the following coding problem using the programming language python: Many of us are familiar with collatz sequence. Know the problem is, There is a fight going between the students of the class they have splitted up into two groups the odd rulers and the even rulers. To resolve this fight sir will randomly pick u...
```python for _ in range(input()): num = input() oddsum = 1 evensum = 0 totsteps = 0 while num > 1: if num % 2 == 0: evensum += num num /= 2 else: oddsum += num num = (3 * num) + 1 totsteps += 1 evenrem = evensum % totsteps oddrem = oddsum % totsteps if oddrem > evenrem: print "Odd Rules" e...
vfc_61145
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n3\n4\n\nSAMPLE", "output": "Even Rules\nOdd Rules\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n5\n4\n\nSAMPLE", "output": "Odd Rules\nOdd Rules\n", "type": "stdin_stdo...
code_contests
verifiable_code
xenny-and-partially-sorted-strings-7
Solve the following coding problem using the programming language python: Xenny had a list of N strings of equal length. He wanted to sort them by the first M characters only. That means, while sorting the list of strings, he only wanted to consider the first M characters of each string. Help Xenny to find out the K^t...
```python for i in range(input()): l=[int(x) for x in raw_input().split()] l1=[] l2=[] l3=[] l4=[] for j in range(l[0]): a=raw_input() l1.append(a) for k in range(0,len(l1)): l2.append(l1[k][0:l[2]]) l3.append(l1[k][l[2]:]) for m in range(0,len(l2)): l4.append(l2[m]) l2.sort() h=l4.index(l2[l[1]-1])...
vfc_61149
{ "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 1 3\nabcdef\nabcaaa\naabaaa\n\nSAMPLE", "output": "aabaaa\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n96 69 70\nqbhesygzakrsloihfigftfojmuhbnnziovfbgorczlrlelcxcnwbwdbvnnnyitoe...
code_contests
verifiable_code
p03984 Kyoto University Programming Contest 2016 - Coloring
Solve the following coding problem using the programming language python: Mikan's birthday is coming soon. Since Mikan likes graphs very much, Aroma decided to give her a undirected graph this year too. Aroma bought a connected undirected graph, which consists of n vertices and n edges. The vertices are numbered from...
vfc_61189
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 268435456, "problem_url": null, "time_limit": "{'seconds': 4, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10 5\n2\n3\n4\n1\n1\n1\n2\n3\n3\n4", "output": "926250", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 4\n2\n3\n4\n1", "output": "55", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
p00204 UFO Shooting Down Operation
Solve the following coding problem using the programming language python: In 40XX, the Earth was invaded by aliens! Already most of the Earth has been dominated by aliens, leaving Tsuruga Castle Fortress as the only remaining defense base. Suppression units are approaching the Tsuruga Castle Fortress one after another...
```python import math class Ufo: def __init__(self, x, y, r, v): self.dist = get_dist(x, y) self.angle = get_angle(y, x) self.rad = r self.v = v def get_dist(x, y): return (x ** 2 + y ** 2) ** (1 / 2) def get_angle(x, y): angle = math.atan2(y, x) if angle < 0: angle += math.pi * 2 retur...
vfc_61197
{ "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": "100 5\n101 101 5 5\n110 110 2 3\n-112 -100 9 11\n-208 160 82 90\n-110 108 10 2\n10 11\n15 0 5 1\n25 0 5 1\n35 0 5 1\n45 0 5 1\n55 0 5 1\n65 0 5 1\n75 0 5 1\n85 0 5 1\n95 0 5 1\n-20 0 5 20\n-30 0 500 5\n0 0", "output": "1\n1",...
code_contests
verifiable_code
p00571 Art Exhibition
Solve the following coding problem using the programming language python: An art exhibition will be held in JOI. At the art exhibition, various works of art from all over the country will be exhibited. N works of art were collected as candidates for the works of art to be exhibited. These works of art are numbered 1,...
```python N = int(input()) P = [list(map(int, input().split())) for i in range(N)] P.sort() su = 0 S = -P[0][0] ans = -10**19 for a, b in P: S = min(S, su - a) ans = max(ans, su + b - a - S) su += b print(ans) ```
vfc_61205
{ "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": "3\n2 3\n11 2\n4 5", "output": "6", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n2 3\n11 2\n4 2", "output": "3\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p00718 Numeral System
Solve the following coding problem using the programming language python: Prof. Hachioji has devised a new numeral system of integral numbers with four lowercase letters "m", "c", "x", "i" and with eight digits "2", "3", "4", "5", "6", "7", "8", "9". He doesn't use digit "0" nor digit "1" in this system. The letters ...
```python ans_list = [] n = int(input()) def mcxl2digit(s): ans = 0 dig = 1 for i in range(len(s)): if "2" <= s[i] <= "9": dig = int(s[i]) else: if s[i] == "m": key = 1000 elif s[i] == "c": key = 100 elif s[i] =...
vfc_61209
{ "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": "10\nxi x9i\ni 9i\nc2x2i 4c8x8i\nm2ci 4m7c9x8i\n9c9x9i i\ni 9m9c9x8i\nm i\ni m\nm9i i\n9m8c7xi c2x8i", "output": "3x\nx\n6cx\n5m9c9x9i\nm\n9m9c9x9i\nmi\nmi\nmx\n9m9c9x9i", "type": "stdin_stdout" }, { "fn_na...
code_contests
verifiable_code
p00858 Geometric Map
Solve the following coding problem using the programming language python: Your task in this problem is to create a program that finds the shortest path between two given locations on a given street map, which is represented as a collection of line segments on a plane. <image> Figure 4 is an example of a street map, ...
```python from heapq import heappush, heappop import sys readline = sys.stdin.readline write = sys.stdout.write def dot3(O, A, B): ox, oy = O; ax, ay = A; bx, by = B return (ax - ox) * (bx - ox) + (ay - oy) * (by - oy) def cross3(O, A, B): ox, oy = O; ax, ay = A; bx, by = B return (ax - ox) * (by - oy)...
vfc_61213
{ "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": "8\n1 1\n4 4\n1 1 4 1\n1 1 1 4\n3 1 3 4\n4 3 5 3\n2 4 3 5\n4 1 4 4\n3 3 2 2\n1 4 4 4\n9\n1 5\n5 1\n5 4 5 1\n1 5 1 1\n1 5 5 1\n2 3 2 4\n5 4 1 5\n3 2 2 1\n4 2 4 1\n1 1 5 1\n5 3 4 3\n11\n5 5\n1 0\n3 1 5 1\n4 3 4 2\n3 1 5 5\n2 3 2 2\n1 ...
code_contests
verifiable_code
p01121 Cube Surface Puzzle
Solve the following coding problem using the programming language python: <!-- Problem E --> Cube Surface Puzzle Given a set of six pieces, "Cube Surface Puzzle" is to construct a hollow cube with filled surface. Pieces of a puzzle is made of a number of small unit cubes laid grid-aligned on a plane. For a puzzle ...
vfc_61221
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 268435456, "problem_url": null, "time_limit": "{'seconds': 8, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n..XX.\n.XXX.\nXXXXX\nXXXXX\nX....\n....X\nXXXXX\n.XXX.\n.XXX.\n.....\n..XXX\nXXXX.\n.XXXX\n.XXXX\n...X.\n...X.\n.XXXX\nXXXX.\nXXXX.\n.X.X.\nXXX.X\n.XXXX\nXXXXX\n.XXXX\n.XXXX\nXX...\n.XXXX\nXXXXX\nXXXXX\nXX...\n5\n..XX.\n.XXX.\nX...
code_contests
verifiable_code
p01260 Girls' Party
Solve the following coding problem using the programming language python: Issac H. Ives hosted a party for girls. He had some nice goods and wanted to distribute them to the girls as the presents. However, there were not enough number of presents and thus he needed to decide who would take them. He held a game for tha...
vfc_61225
{ "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": "6\n1 GB\n3 GBGBBB\n9 BBBGBBBGGG\n9 GGBGBBGBBB\n7 GBGGGGBGGG\n3 BBBBBGBBBB", "output": "1\n4\n4\n1\n0\n8", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n1 GB\n3 GBGBBB\n9 BBBGBBBGGG\n15 GG...
code_contests
verifiable_code
p01574 Dial Key
Solve the following coding problem using the programming language python: You are a secret agent from the Intelligence Center of Peacemaking Committee. You've just sneaked into a secret laboratory of an evil company, Automated Crime Machines. Your mission is to get a confidential document kept in the laboratory. To r...
```python n,m=map(int,input().split()) for _ in range(m): a=int(input()) while a:n,a=a,n%a print(['No','Yes'][n==1]) ```
vfc_61233
{ "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\n1", "output": "Yes", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 2\n2\n5", "output": "Yes", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 ...
code_contests
verifiable_code
p01736 Graph Automata Player
Solve the following coding problem using the programming language python: You and your grandma are playing with graph automata, which is generalization of cell automata. A graph automaton is expressed by a graph. The vertices of the graph have a time-dependent value, which can be either 0 or 1. There is no more than ...
vfc_61237
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 268435456, "problem_url": null, "time_limit": "{'seconds': 10, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n1 1\n0 1\n1\n1\n1", "output": "0 1", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1 1\n0 1\n0\n1\n1", "output": "1 1\n", "type": "stdin_stdout" }, { "fn_name...