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
p01488 TransferTrain
Solve the following coding problem using the programming language python: Example Input 2 10 Warsaw Petersburg 3 Kiev Moscow Petersburg 150 120 3 Moscow Minsk Warsaw 100 150 Output 380 1 The input will be given via stdin and the output should be printed to stdout by your code. Now solve the problem by providing...
```python from heapq import heappush, heappop import sys def solve(): readline = sys.stdin.readline write = sys.stdout.write N, TI = map(int, readline().split()) A, B = readline().split() S = []; T = []; X = [] L = 0 L = 0 NA = set() for i in range(N): a = int(readline()) ...
vfc_31661
{ "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 10\nWarsaw Petersburg\n3\nKiev Moscow Petersburg\n150 120\n3\nMoscow Minsk Warsaw\n100 150", "output": "380 1", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 10\nWarsaw Petersburg\n3\nKi...
code_contests
verifiable_code
p01650 Stack Maze
Solve the following coding problem using the programming language python: Problem Statement There is a maze which can be described as a W \times H grid. The upper-left cell is denoted as (1, 1), and the lower-right cell is (W, H). You are now at the cell (1, 1) and have to go to the cell (W, H). However, you can only...
```python import sys readline = sys.stdin.readline write = sys.stdout.write from string import ascii_lowercase, ascii_uppercase from collections import deque dd = ((1, 0), (0, 1)) def solve(): H, W = map(int, readline().split()) if H == W == 0: return False C = [readline().strip() for i in range(H...
vfc_31665
{ "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 3\nac#\nb#C\n.BA\n3 3\naaZ\na#Z\naZZ\n3 3\n..#\n.#.\n#..\n1 50\nabcdefghijklmnopqrstuvwxyYXWVUTSRQPONMLKJIHGFEDCBA\n1 50\naAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyY\n1 50\nabcdefghijklmnopqrstuvwxyABCDEFGHIJKLMNOPQRSTUVWX...
code_contests
verifiable_code
p01801 Wall Making Game
Solve the following coding problem using the programming language python: Example Input 2 2 .. .. Output Second The input will be given via stdin and the output should be printed to stdout by your code. Now solve the problem by providing the code.
```python import sys readline = sys.stdin.readline write = sys.stdout.write def solve(): H, W = map(int, readline().split()) f = ".X".index S = [list(map(f, readline().strip())) for i in range(H)] memo = {} def dfs(px, py, qx, qy): key = (px, py, qx, qy) if key in memo: r...
vfc_31669
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 268435456, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 2\n..\n..", "output": "Second", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 2\n..\n..", "output": "First\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p01935 Protect from the enemy attack
Solve the following coding problem using the programming language python: problem There are $ V $ islands, numbered $ 0, 1, ..., V-1 $, respectively. There are $ E $ bridges, numbered $ 0, 1, ..., E-1 $, respectively. The $ i $ th bridge spans island $ s_i $ and island $ t_i $ and is $ c_i $ wide. The AOR Ika-chan C...
vfc_31673
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 268435456, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 4\n0 1 3\n0 2 4\n1 3 1\n2 3 5", "output": "4", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 4\n0 1 3\n0 2 4\n1 3 1\n0 3 5", "output": "5\n", "type": "stdin_stdout" }, ...
code_contests
verifiable_code
p02074 N-by-M grid calculation
Solve the following coding problem using the programming language python: Problem Statement Have you experienced $10$-by-$10$ grid calculation? It's a mathematical exercise common in Japan. In this problem, we consider the generalization of the exercise, $N$-by-$M$ grid calculation. In this exercise, you are given a...
vfc_31677
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 536870912, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "", "output": "", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p02369 Cycle Detection for a Directed Graph
Solve the following coding problem using the programming language python: Find a cycle in a directed graph G(V, E). Constraints * 1 ≤ |V| ≤ 100 * 0 ≤ |E| ≤ 1,000 * si ≠ ti Input A directed graph G is given in the following format: |V| |E| s0 t0 s1 t1 : s|E|-1 t|E|-1 |V| is the number of nodes and |E| is the nu...
```python from collections import deque from typing import List, Optional, Tuple def cycle_detectable_topological_sort( graph: List[List[int]], in_degrees: List[int], first_index: int = 0 ) -> Tuple[Optional[List[int]], Optional[List[int]]]: """Topological sort that uses Kahn's algorithm and detects a loop (D...
vfc_31685
{ "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 3\n0 1\n0 2\n1 2", "output": "0", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
aba15f
Solve the following coding problem using the programming language python: Problem description. “Murphy’s Law doesn’t meant that something bad will happen. It means that whatever can happen, will happen.” —Cooper While traveling across space-time,the dat...
```python def toBin(n): binary = [] while n!=0: bit = str(n%2) binary.append(bit) n = n/2 binary.reverse() return binary def main(): tc = int(raw_input()) while tc>0: n = int(raw_input()) binary = toBin(n) """for x in xrange(0,32-len(binary)): binary.append(0)""...
vfc_31689
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n100\n23\n4\n1000\n5", "output": "68\n21\n4\n320\n5", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
chefch
Solve the following coding problem using the programming language python: Chef had a hard day and want to play little bit. The game is called "Chain". Chef has the sequence of symbols. Each symbol is either '-' or '+'. The sequence is called Chain if each two neighboring symbols of sequence are either '-+' or '+-'. ...
```python testCases = int(raw_input()) for testCase in range(testCases): originalString = raw_input() lenOfOriginalString = len(originalString) # count variables to find the difference between the new string and original one count1 = 0 # for "-+-+-+...." count2 = 0 # for "+-+-+-...." for pos in range(lenOfOrigina...
vfc_31693
{ "difficulty": "2", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n---+-+-+++\n-------", "output": "2\n3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n+++-+-+---\n-------", "output": "2\n3\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
directi
Solve the following coding problem using the programming language python: Chef recently printed directions from his home to a hot new restaurant across the town, but forgot to print the directions to get back home. Help Chef to transform the directions to get home from the restaurant. A set of directions consists of s...
```python t = int(raw_input()) while t: n = int(raw_input()) directions = [] for i in range(n): directions.append(raw_input().split()) if i: directions[i-1][0]="Left" if directions[i][0]=="Right" else "Right" directions[n-1][0]="Begin" while n: print ' '.join(dire...
vfc_31697
{ "difficulty": "2", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n4\nBegin on Road A\nRight on Road B\nRight on Road C\nLeft on Road D\n6\nBegin on Old Madras Road\nLeft on Domlur Flyover\nLeft on 100 Feet Road\nRight on Sarjapur Road\nRight on Hosur Road\nRight on Ganapathi Temple Road", ...
code_contests
verifiable_code
insomb1
Solve the following coding problem using the programming language python: Modern cryptosystems rely heavily on our inability to factor large integers quickly as the basis for their security. They need a quick and easy way to generate and test for primes. Very often, the primes generated are very large numbers. You nee...
```python def primality(n): for i in primes: if (n % i == 0 and n != i): return 0 return 1 primes = [ 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223...
vfc_31701
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2760727302517", "output": "PRIME\n\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1894408473307", "output": "COMPOSITE\n", "type": "stdin_stdout" }, { "fn_name":...
code_contests
verifiable_code
nfeb4
Solve the following coding problem using the programming language python: Buffalo Marketing Gopal wants to make some money from buffalos, but in a quite a different way. He decided that his future lay in speculating on buffalos. In the market in his village, buffalos were bought and sold everyday. The price fluctua...
```python t=int(input()) while(t>0): n=int(input()) a=map(int,raw_input().split(" ")) i=n-1 m=a[i] ans=0 i=n-2 while(i>=0): if(m>a[i]): ans+=m-a[i] elif(m<a[i]): m=a[i] i-=1 print ans t-=1 ```
vfc_31705
{ "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\n1 2 90\n4\n1 3 1 2", "output": "177\n 3", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
scores
Solve the following coding problem using the programming language python: Mrityunjay is a high-school teacher, currently coaching students for JEE (Joint Entrance Exam). Mrityunjay every year gives prizes to the toppers of JEE in India. A lot of students give this exam in India and it is difficult for him to manually ...
```python N = int(raw_input()) arr = map(int,raw_input().strip().split(' ')) c = [] for i in range(2): m = max(arr) c.append(m) arr.remove(m) print ' '.join(str(t) for t in c) ```
vfc_31709
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 \n30 30 20", "output": "30 30", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 \n12 20 12", "output": "20 12", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
1000_C. Covered Points Count
Solve the following coding problem using the programming language python: You are given n segments on a coordinate line; each endpoint of every segment has integer coordinates. Some segments can degenerate to points. Segments can intersect with each other, be nested in each other or even coincide. Your task is the fo...
```python n=int(input()) a=[] for i in range(n): l,r=map(int,input().split()) a.append([l,1]) a.append([r+1,-1]) a.sort() # print(a) ans=[0]*(n+1) idx=0 for i in range(len(a)-1): idx+=a[i][1] ans[idx]+=a[i+1][0]-a[i][0] for i in range(1,n+1): print(ans[i],end=" ") print() ```
vfc_31713
{ "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": "3\n0 3\n1 3\n3 8\n", "output": "6 2 1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n1 3\n2 4\n5 7\n", "output": "5 2 0\n", "type": "stdin_stdout" }, { "fn_na...
code_contests
verifiable_code
1025_D. Recovering BST
Solve the following coding problem using the programming language python: Dima the hamster enjoys nibbling different things: cages, sticks, bad problemsetters and even trees! Recently he found a binary search tree and instinctively nibbled all of its edges, hence messing up the vertices. Dima knows that if Andrew, wh...
```python from math import gcd import random,time,sys input=sys.stdin.buffer.readline def main(): n=int(input()) a=list(map(int,input().split())) #a=[2*random.randint(1,10**9) for i in range(n)] start=time.time() a+=[0] dp=[[False for j in range(n)] for i in range(n)] GCD=[0 for i in rang...
vfc_31717
{ "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": "9\n4 8 10 12 15 18 33 44 81\n", "output": "Yes\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n3 6 9 18 36 108\n", "output": "Yes\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
1045_F. Shady Lady
Solve the following coding problem using the programming language python: Ani and Borna are playing a short game on a two-variable polynomial. It's a special kind of a polynomial: the monomials are fixed, but all of its coefficients are fill-in-the-blanks dashes, e.g. $$$ \\_ xy + \\_ x^4 y^7 + \\_ x^8 y^3 + … $$$ Bo...
vfc_31721
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1 1\n2 0\n0 2\n", "output": "Ani\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n0 0\n0 1\n0 2\n0 8\n", "output": "Borna\n", "type": "stdin_stdout" }, { "fn...
code_contests
verifiable_code
1068_F. Knights
Solve the following coding problem using the programming language python: Ivan places knights on infinite chessboard. Initially there are n knights. If there is free cell which is under attack of at least 4 knights then he places new knight in this cell. Ivan repeats this until there are no such free cells. One can pr...
```python n = int(input()) anss = [(0, 0)] for i in range(1, n): anss.append((0, i)) anss.append((i, 0)) anss.append((0, -i)) anss.append((-i, 0)) for i in range(n): print(str(anss[i][0]) + ' ' + str(anss[i][1])) ```
vfc_31725
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7\n", "output": "0 0\n1 0\n1 3\n2 0\n3 0\n3 3\n4 0\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1090_J. Two Prefixes
Solve the following coding problem using the programming language python: Misha didn't do his math homework for today's lesson once again. As a punishment, his teacher Dr. Andrew decided to give him a hard, but very useless task. Dr. Andrew has written two strings s and t of lowercase English letters at the blackboar...
vfc_31729
{ "difficulty": "16", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "aaaaa\naaaa\n", "output": " 8\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
110_B. Lucky String
Solve the following coding problem using the programming language python: Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya recently learned to...
```python n=int(input()) x='a'+'bcda'*25002 print(x[:n]) ```
vfc_31733
{ "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\n", "output": "abc", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n", "output": "abcda", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n", ...
code_contests
verifiable_code
1139_E. Maximize Mex
Solve the following coding problem using the programming language python: There are n students and m clubs in a college. The clubs are numbered from 1 to m. Each student has a potential p_i and is a member of the club with index c_i. Initially, each student is a member of exactly one club. A technical fest starts in t...
```python import sys input = sys.stdin.readline n, m = map(int, input().split()) p = list(map(int, input().split())) c = list(map(int, input().split())) d = int(input()) disable = [False] * n base = 5001 ds = [int(input())-1 for _ in range(d)] for ele in ds: disable[ele] = True # Create Graph childs = [[] for i...
vfc_31737
{ "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\n0 1 2 4 5\n1 2 3 4 5\n4\n2\n3\n5\n4\n", "output": "1\n1\n1\n1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 3\n0 1 2 2 0\n1 2 2 3 2\n5\n3\n2\n4\n5\n1\n", "output": "3\n1\n1\...
code_contests
verifiable_code
1157_E. Minimum Array
Solve the following coding problem using the programming language python: You are given two arrays a and b, both of length n. All elements of both arrays are from 0 to n-1. You can reorder elements of the array b (if you want, you may leave the order of elements as it is). After that, let array c be the array of leng...
```python class SegmentTree: @classmethod def all_identity(cls, operator, equality, identity, size): return cls(operator, equality, identity, [identity]*(2 << (size-1).bit_length())) @classmethod def from_initial_data(cls, operator, equality, identity, data): size = 1 << (len(data)-1)...
vfc_31741
{ "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 2 1\n3 2 1 1\n", "output": "1 0 0 2 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "7\n2 5 1 5 3 4 3\n2 4 3 5 6 5 1\n", "output": "0 0 0 1 0 2 4 ", "type": "stdin_stdout"...
code_contests
verifiable_code
117_B. Very Interesting Game
Solve the following coding problem using the programming language python: In a very ancient country the following game was popular. Two people play the game. Initially first player writes a string s1, consisting of exactly nine digits and representing a number that does not exceed a. After that second player looks at ...
```python a, b, m = map(int, input().split()) k = s = 10 ** 9 % m i = 0 while k and i < a: i += 1 if k < m - b: exit(print(1, str(i).zfill(9))) k += s if k >= m: k -= m print(2) ```
vfc_31745
{ "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": "4 0 9\n", "output": "1 000000001\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 10 7\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "i...
code_contests
verifiable_code
1215_B. The Number of Products
Solve the following coding problem using the programming language python: You are given a sequence a_1, a_2, ..., a_n consisting of n non-zero integers (i.e. a_i ≠ 0). You have to calculate two following values: 1. the number of pairs of indices (l, r) (l ≤ r) such that a_l ⋅ a_{l + 1} ... a_{r - 1} ⋅ a_r is nega...
```python input() a=list(map(int,input().split())) q,w,e,t,y=0,0,1,0,0 for i in a: if e>0: q+=1 if i>0: e=1 else: e=-1 else: w+=1 if i>0: e=-1 else: e=1 if e>0: t+=q y+=w else: t+=w ...
vfc_31753
{ "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": "10\n4 2 -4 3 1 2 -4 3 2 3\n", "output": "28 27\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n-1 -2 -3 -4 -5\n", "output": "9 6\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
127_E. E-reader Display
Solve the following coding problem using the programming language python: After years of hard work scientists invented an absolutely new e-reader display. The new display has a larger resolution, consumes less energy and its production is cheaper. And besides, one can bend it. The only inconvenience is highly unusual ...
```python n=int(input()) T=[] for i in range(n): T.append(input()[::-1]) Val=['0','1'] S=0 L1=[0]*n C1=[0]*n for diag in range(n-1): for i in range(diag+1): l,c=L1[i],C1[diag-i] if T[i][diag-i]!=Val[(l+c)%2]: S+=1 L1[i]=1-l C1[diag-i]=1-c L2=[0...
vfc_31765
{ "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\n01110\n10010\n10001\n10011\n11110\n", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n000\n000\n000\n", "output": "0\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
12_D. Ball
Solve the following coding problem using the programming language python: N ladies attend the ball in the King's palace. Every lady can be described with three values: beauty, intellect and richness. King's Master of Ceremonies knows that ladies are very special creatures. If some lady understands that there is other ...
vfc_31769
{ "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 4 2\n4 3 2\n2 5 3\n", "output": "1\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1342_E. Placing Rooks
Solve the following coding problem using the programming language python: Calculate the number of ways to place n rooks on n × n chessboard so that both following conditions are met: * each empty cell is under attack; * exactly k pairs of rooks attack each other. An empty cell is under attack if there is at ...
```python import io,os input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline import sys def solve(n,k): mod=998244353 if k==0: ans=1 for i in range(1,n+1): ans*=i ans%=mod return ans if k>=n: return 0 inv=lambda x: pow(x,mod-2,mod) Fac...
vfc_31777
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 0\n", "output": "24\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 2\n", "output": "6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1337 4...
code_contests
verifiable_code
1364_E. X-OR
Solve the following coding problem using the programming language python: This is an interactive problem! Ehab has a hidden permutation p of length n consisting of the elements from 0 to n-1. You, for some reason, want to figure out the permutation. To do that, you can give Ehab 2 different indices i and j, and he'll...
vfc_31781
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1\n3\n2", "output": "? 1 2\n? 1 3\n? 2 3\n! 1 0 2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "128\n49 64 93 66 79 101 57 76 30 25 31 104 39 15 24 51 83 117 73 41 46 77 50 16 61 32 1...
code_contests
verifiable_code
1384_F. Rearrange
Solve the following coding problem using the programming language python: Koa the Koala has a matrix A of n rows and m columns. Elements of this matrix are distinct integers from 1 to n ⋅ m (each number from 1 to n ⋅ m appears exactly once in the matrix). For any matrix M of n rows and m columns let's define the foll...
vfc_31785
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 4\n12 10 8 6\n3 4 5 7\n2 11 9 1\n", "output": "12 8 6 1 \n10 11 9 2 \n3 4 5 7 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 3\n3 5 6\n1 7 9\n4 8 2\n", "output": "9 5 1 \n7 8 2...
code_contests
verifiable_code
1427_D. Unshuffling a Deck
Solve the following coding problem using the programming language python: You are given a deck of n cards numbered from 1 to n (not necessarily in this order in the deck). You have to sort the deck by repeating the following operation. * Choose 2 ≤ k ≤ n and split the deck in k nonempty contiguous parts D_1, D_2,....
```python from sys import stdin, stdout n = int(stdin.readline()) c = [int(x) for x in stdin.readline().split()] ops = [] turn = True for x in range(n-1): newC = [] newC2 = [] op = [] ind = c.index(x+1) if turn: if ind != 0: op.append(ind) op.append(n-x-ind) o...
vfc_31793
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n1\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n6 5 4 3 2 1\n", "output": "4\n3 1 1 4\n3 1 1 4\n3 1 1 4\n3 2 2 2\n", "type": "stdin_stdout" }, ...
code_contests
verifiable_code
1474_B. Different Divisors
Solve the following coding problem using the programming language python: Positive integer x is called divisor of positive integer y, if y is divisible by x without remainder. For example, 1 is a divisor of 7 and 3 is not divisor of 8. We gave you an integer d and asked you to find the smallest positive integer a, su...
```python # ------------------- fast io -------------------- import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not i...
vfc_31801
{ "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": "2\n1\n2\n", "output": "\n6\n15\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n2\n2\n", "output": "15\n15\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
149_D. Coloring Brackets
Solve the following coding problem using the programming language python: Once Petya read a problem about a bracket sequence. He gave it much thought but didn't find a solution. Today you will face it. You are given string s. It represents a correct bracket sequence. A correct bracket sequence is the sequence of open...
```python bs = raw_input() n = len(bs) t = (0, 1, 2) M = 10**9+7 def empty_state(_cache={}): if _cache == {}: s = _cache for c1 in t: for c2 in t: if c1 * c2 == 0 and c1 + c2 != 0: s[c1, c2] = 1 else: s[c1, c2] = 0 ...
vfc_31805
{ "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": "(())\n", "output": "12", "type": "stdin_stdout" }, { "fn_name": null, "input": "()\n", "output": "4", "type": "stdin_stdout" }, { "fn_name": null, "input": "(()())\n",...
code_contests
verifiable_code
1523_D. Love-Hate
Solve the following coding problem using the programming language python: <image> William is hosting a party for n of his trader friends. They started a discussion on various currencies they trade, but there's an issue: not all of his trader friends like every currency. They like some currencies, but not others. For...
```python #!/usr/bin/env python import os import sys from io import BytesIO, IOBase def main(): def popCount(a): cnt = 0 for i in range(60): if a & (1 << i): cnt += 1 return cnt n,m,p = map(int,input().split()) person = [] for _ in range(n): ...
vfc_31809
{ "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": "3 4 3\n1000\n0110\n1001\n", "output": "\n1000\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 5 4\n11001\n10101\n10010\n01110\n11011\n", "output": "\n10001\n", "type": "stdin...
code_contests
verifiable_code
155_C. Hometask
Solve the following coding problem using the programming language python: Sergey attends lessons of the N-ish language. Each lesson he receives a hometask. This time the task is to translate some sentence to the N-ish language. Sentences of the N-ish language can be represented as strings consisting of lowercase Latin...
```python s = input() + "#" k = int(input()) arr = [input() for _ in range(k)] res = 0 for t in arr: a, b = 0, 0 for i in range(len(s)): if s[i] == t[0]: a += 1 elif s[i] == t[1]: b += 1 else: if a and b: res += min(a, b) a,...
vfc_31813
{ "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": "ababa\n1\nab\n", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "codeforces\n2\ndo\ncs\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null...
code_contests
verifiable_code
177_D1. Encrypting Messages
Solve the following coding problem using the programming language python: The Smart Beaver from ABBYY invented a new message encryption method and now wants to check its performance. Checking it manually is long and tiresome, so he decided to ask the ABBYY Cup contestants for help. A message is a sequence of n intege...
```python n,m,c = map(int,input().split()) a = list(input().split()) b = list(input().split()) sum = 0 for i in range(n): if i<m: sum = sum + int(b[i]) sum = sum%c if i >= n - m + 1: sum = c - int(b[i-n+m-1]) + sum sum = sum%c print((int(a[i])+sum)%c,end = ' ') ```
vfc_31817
{ "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 1 5\n1 2 3\n4\n", "output": "0 1 2 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 3 2\n1 1 1 1\n1 1 1\n", "output": "0 1 1 0 \n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
198_D. Cube Snake
Solve the following coding problem using the programming language python: You've got an n × n × n cube, split into unit cubes. Your task is to number all unit cubes in this cube with positive integers from 1 to n3 so that: * each number was used as a cube's number exactly once; * for each 1 ≤ i < n3, unit cubes...
vfc_31821
{ "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\n", "output": "1 8 9\n2 7 10\n27 26 25\n\n4 5 12\n3 6 11\n22 23 24\n\n15 14 13\n16 17 18\n21 20 19\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "24\n", "output": "1 11662 11707 1...
code_contests
verifiable_code
221_E. Little Elephant and Shifts
Solve the following coding problem using the programming language python: The Little Elephant has two permutations a and b of length n, consisting of numbers from 1 to n, inclusive. Let's denote the i-th (1 ≤ i ≤ n) element of the permutation a as ai, the j-th (1 ≤ j ≤ n) element of the permutation b — as bj. The dis...
vfc_31825
{ "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\n2 1 3 4\n3 4 2 1\n", "output": "2\n1\n0\n1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1 2\n2 1\n", "output": "1\n0\n", "type": "stdin_stdout" }, { "fn_...
code_contests
verifiable_code
245_F. Log Stream Analysis
Solve the following coding problem using the programming language python: You've got a list of program warning logs. Each record of a log stream is a string in this format: "2012-MM-DD HH:MM:SS:MESSAGE" (without the quotes). String "MESSAGE" consists of spaces, uppercase and lowercase English letters and character...
```python import atexit import io import sys _INPUT_LINES = sys.stdin.read().splitlines() input = iter(_INPUT_LINES).__next__ _OUTPUT_BUFFER = io.StringIO() sys.stdout = _OUTPUT_BUFFER @atexit.register def write(): sys.__stdout__.write(_OUTPUT_BUFFER.getvalue()) import bisect from datetime import datetime def...
vfc_31829
{ "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": "60 3\n2012-03-16 16:15:25: Disk size is\n2012-03-16 16:15:25: Network failute\n2012-03-16 16:16:29: Cant write varlog\n2012-03-16 16:16:42: Unable to start process\n2012-03-16 16:16:43: Disk size is too small\n2012-03-16 16:16:53: ...
code_contests
verifiable_code
270_D. Greenhouse Effect
Solve the following coding problem using the programming language python: Emuskald is an avid horticulturist and owns the world's longest greenhouse — it is effectively infinite in length. Over the years Emuskald has cultivated n plants in his greenhouse, of m different plant species numbered from 1 to m. His greenho...
```python n, m = [int(x) for x in input().split()] d = [0 for i in range(m)] for i in range(n): c, x = [x for x in input().split()] c = int(c) d[c-1] = max(d[:c])+1 print(n-max(d)) ```
vfc_31833
{ "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 3\n1 5.0\n2 5.5\n3 6.0\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 3\n1 14.284235\n2 17.921382\n1 20.328172\n3 20.842331\n1 25.790145\n1 27.204125\n", "outpu...
code_contests
verifiable_code
294_A. Shaass and Oskols
Solve the following coding problem using the programming language python: Shaass has decided to hunt some birds. There are n horizontal electricity wires aligned parallel to each other. Wires are numbered 1 to n from top to bottom. On each wire there are some oskols sitting next to each other. Oskol is the name of a d...
```python n = int(input()) l = list(map(int,input().split())) n1 = int(input()) for i in range(n1): x,y = map(int,input().split()) if len(l)==1: l[0]=0 elif x==1: l[x]+=l[x-1]-y l[x-1]=0 elif x==len(l): l[x-2]+=y-1 l[x-1]=0 else: l[x-2]+=y-1 l[x]+=l[x-1]-y l[x-1]=0 for i in l: print(i) ```
vfc_31837
{ "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": "5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6\n", "output": "0\n12\n5\n0\n16\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
317_D. Game with Powers
Solve the following coding problem using the programming language python: Vasya and Petya wrote down all integers from 1 to n to play the "powers" game (n can be quite large; however, Vasya and Petya are not confused by this fact). Players choose numbers in turn (Vasya chooses first). If some number x is chosen at th...
```python from sys import stdin, stdout import math, collections mod = 10**9+7 def isPower(n): if (n <= 1): return True for x in range(2, (int)(math.sqrt(n)) + 1): p = x while (p <= n): p = p * x if (p == n): return True return False n = int(...
vfc_31841
{ "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": "8\n", "output": "Petya\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n", "output": "Vasya\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
365_A. Good Number
Solve the following coding problem using the programming language python: Let's call a number k-good if it contains all digits not exceeding k (0, ..., k). You've got a number k and an array a containing n numbers. Find out how many k-good numbers are in a (count each number every time it occurs in array a). Input T...
```python import sys x=input().split() n=int(x[0]) k=int(x[1]) list=[] for i in range(0,n): y=input() list.append(y) l=0 for j in list: flag=1 for z in range(0,k+1): if str(z) not in j: flag=0 break if flag==1: l=l+1 print(l) ```
vfc_31849
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 1\n1\n10\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10 6\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n", "output...
code_contests
verifiable_code
409_C. Magnum Opus
Solve the following coding problem using the programming language python: Salve, mi amice. Et tu quidem de lapis philosophorum. Barba non facit philosophum. Labor omnia vincit. Non potest creatio ex nihilo. Necesse est partibus. Rp: I Aqua Fortis I Aqua Regia II Amalgama VII Minium IV Vitriol Misce in vitro et...
```python b =[1,1,2,7,4] a =list(map(int,input().split())) ans = 100 for i in range(5): ans = min(a[i]//b[i],ans) print(ans) ```
vfc_31857
{ "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": "2 4 6 8 10\n", "output": "1\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
436_D. Pudding Monsters
Solve the following coding problem using the programming language python: Have you ever played Pudding Monsters? In this task, a simplified one-dimensional model of this game is used. <image> Imagine an infinite checkered stripe, the cells of which are numbered sequentially with integers. Some cells of the strip hav...
vfc_31861
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 5, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 2\n1 8 4 5\n7 2\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 2\n1 3 5\n2 4\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": nul...
code_contests
verifiable_code
459_E. Pashmak and Graph
Solve the following coding problem using the programming language python: Pashmak's homework is a problem about graphs. Although he always tries to do his homework completely, he can't solve this problem. As you know, he's really weak at graph theory; so try to help him in solving the problem. You are given a weighte...
```python from sys import * f = list(map(int, stdin.read().split())) n, m = f[0], f[1] d = [[] for i in range(100001)] for j in range(2, len(f), 3): x, y, w = f[j:j + 3] d[w].append((y, x)) s = [0] * (n + 1) for q in d: for y, k in [(y, s[x]) for y, x in q]: s[y] = max(s[y], k + 1) print(max(s)) ```
vfc_31865
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6 7\n1 2 1\n3 2 5\n2 4 2\n2 5 2\n2 6 9\n5 4 3\n4 3 4\n", "output": "6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 3\n1 2 1\n2 3 1\n3 1 1\n", "output": "1\n", "type": "std...
code_contests
verifiable_code
480_D. Parcels
Solve the following coding problem using the programming language python: Jaroslav owns a small courier service. He has recently got and introduced a new system of processing parcels. Each parcel is a box, the box has its weight and strength. The system works as follows. It originally has an empty platform where you c...
vfc_31869
{ "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 2\n0 1 1 1 1\n1 2 1 1 1\n0 2 1 1 1\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 5\n0 6 1 2 1\n1 2 1 1 1\n1 3 1 1 1\n3 6 2 1 2\n4 5 1 1 1\n", "output": "5\n", ...
code_contests
verifiable_code
505_D. Mr. Kitayuta's Technology
Solve the following coding problem using the programming language python: Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two...
```python def main(): n, m = map(int, input().split()) n += 1 cluster, dest, ab = list(range(n)), [0] * n, [[] for _ in range(n)] def root(x): if x != cluster[x]: cluster[x] = x = root(cluster[x]) return x for _ in range(m): a, b = map(int, input().split()) ...
vfc_31873
{ "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 6\n1 2\n1 4\n2 3\n2 4\n3 2\n3 4\n", "output": "4", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
529_C. Rooks and Rectangles
Solve the following coding problem using the programming language python: Polycarpus has a chessboard of size n × m, where k rooks are placed. Polycarpus hasn't yet invented the rules of the game he will play. However, he has already allocated q rectangular areas of special strategic importance on the board, they must...
vfc_31877
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 3 3 3\n1 1\n3 2\n2 3\n2 3 2 3\n2 1 3 3\n1 2 2 3\n", "output": "YES\nYES\nNO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1 1 1\n1 1\n1 1 1 1\n", "output": "YES\n", "type...
code_contests
verifiable_code
554_E. Love Triangles
Solve the following coding problem using the programming language python: There are many anime that are about "love triangles": Alice loves Bob, and Charlie loves Bob as well, but Alice hates Charlie. You are thinking about an anime which has n characters. The characters are labeled from 1 to n. Every pair of two char...
```python class DSU(object): def __init__(self, n): self.father = list(range(n)) self.size = n def union(self, x, s): x = self.find(x) s = self.find(s) if x == s: return self.father[s] = x self.size -= 1 def find(self, x): xf = se...
vfc_31881
{ "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 4\n1 2 1\n2 3 1\n3 4 0\n4 1 0\n", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 0\n", "output": "4", "type": "stdin_stdout" }, { "fn_name": null,...
code_contests
verifiable_code
580_D. Kefa and Dishes
Solve the following coding problem using the programming language python: When Kefa came to the restaurant and sat at a table, the waiter immediately brought him the menu. There were n dishes. Kefa knows that he needs exactly m dishes. But at that, he doesn't want to order the same dish twice to taste as many dishes a...
```python import os import sys from io import BytesIO,IOBase def main(): n,m,k = map(int,input().split()) a = list(map(float,input().split())) tree = [[0]*n for _ in range(n)] for i in range(k): x,y,z = map(int,input().split()) tree[x-1][y-1] = float(z) po = [1] while len(po) !=...
vfc_31885
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 2 1\n1 1\n2 1 1\n", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 3 2\n1 2 3 4\n2 1 5\n3 4 2\n", "output": "12", "type": "stdin_stdout" }, { "fn_...
code_contests
verifiable_code
602_C. The Two Routes
Solve the following coding problem using the programming language python: In Absurdistan, there are n towns (numbered 1 through n) and m bidirectional railways. There is also an absurdly simple road network — for each pair of different towns x and y, there is a bidirectional road between towns x and y if and only if t...
```python n, m = map(int, input().split()) dist = [0] * (n + 1) for row in range(n + 1): dist[row] = [1] * (n + 1) for i in range(m): a, b = map(int, input().split()) dist[a][b] = dist[b][a] = 2 x, v, i = 3 - dist[1][n], [0] * (n + 1), 1 d = [n + 1] * (n + 1) res = d[1] = 0 while i != n: v[i] = 1 ...
vfc_31889
{ "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 5\n4 2\n3 5\n4 5\n5 1\n1 2\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4\n", "output": "-1\n", "type": "stdin_stdout" ...
code_contests
verifiable_code
625_A. Guest From the Past
Solve the following coding problem using the programming language python: Kolya Gerasimov loves kefir very much. He lives in year 1984 and knows all the details of buying this delicious drink. One day, as you probably know, he found himself in year 2084, and buying kefir there is much more complicated. Kolya is hungr...
```python n=(int)(input()); a=(int)(input()); b=(int)(input()); c=(int)(input()); cnt=a; cnt=0; cnt1=a; cnt1=(int)(n//a); if (n<b): while (n//b>0): cnt+=n//b; n-=(n//b)*b-n//b*c; #print (n," ",cnt); #print(n//a," ",cnt," ",cnt+n//a); cnt+=n//a; print((int)(max(cnt,cnt1))); else: ...
vfc_31893
{ "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": "10\n11\n9\n8\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n5\n6\n1\n", "output": " 2\n", "t...
code_contests
verifiable_code
64_C. Table
Solve the following coding problem using the programming language python: The integer numbers from 1 to nm was put into rectangular table having n rows and m columns. The numbers was put from left to right, from top to bottom, i.e. the first row contains integers 1, 2, ..., m, the second — m + 1, m + 2, ..., 2 * m and...
vfc_31897
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 64000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 4 11\n", "output": "8\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "20000 10000 200000000\n", "output": "200000000\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
673_C. Bear and Colors
Solve the following coding problem using the programming language python: Bear Limak has n colored balls, arranged in one long row. Balls are numbered 1 through n, from left to right. There are n possible colors, also numbered 1 through n. The i-th ball has color ti. For a fixed interval (set of consecutive elements)...
```python def main(): n = int(input()) a = [int(i) for i in input().strip().split()] res = [0] * n for st in range(n): cnt = [0] * n x = 0 y = 0 for ed in range(st, n): cnt[a[ed] - 1] += 1 if (cnt[a[ed] - 1] > x) or (cnt[a[ed] - 1] == x and a[ed]...
vfc_31901
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1 1 1\n", "output": "6 0 0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n1 2 1 2\n", "output": "7 3 0 0\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
698_D. Limak and Shooting Points
Solve the following coding problem using the programming language python: Bearland is a dangerous place. Limak can’t travel on foot. Instead, he has k magic teleportation stones. Each stone can be used at most once. The i-th stone allows to teleport to a point (axi, ayi). Limak can use stones in any order. There are ...
vfc_31905
{ "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": "3 8\n10 20\n0 0\n20 40\n300 600\n30 60\n170 340\n50 100\n28 56\n90 180\n-4 -8\n-1 -2\n", "output": "5\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 4\n-2 -1\n4 5\n4 2\n2 1\n4 -1\n1 -1\...
code_contests
verifiable_code
740_B. Alyona and flowers
Solve the following coding problem using the programming language python: Little Alyona is celebrating Happy Birthday! Her mother has an array of n flowers. Each flower has some mood, the mood of i-th flower is ai. The mood can be positive, zero or negative. Let's define a subarray as a segment of consecutive flowers...
```python I=lambda:map(int,input().split()) R=range ans=0 n,m=I() a=list(I()) for _ in R(m):l,r=I();ans+=max(0,sum(a[i]for i in R(l-1,r))) print(ans) ```
vfc_31913
{ "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": "4 3\n1 2 3 4\n1 3\n2 4\n1 1\n", "output": "16\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 4\n1 -2 1 3 -4\n1 2\n4 5\n3 4\n1 4\n", "output": "7\n", "type": "stdin_stdout" ...
code_contests
verifiable_code
764_A. Taymyr is calling you
Solve the following coding problem using the programming language python: Comrade Dujikov is busy choosing artists for Timofey's birthday and is recieving calls from Taymyr from Ilia-alpinist. Ilia-alpinist calls every n minutes, i.e. in minutes n, 2n, 3n and so on. Artists come to the comrade every m minutes, i.e. i...
```python from math import * def lcm(a, b): return a*b//gcd(a, b) n, m, z = map(int, input().split()) print(z//lcm(n, m)) ```
vfc_31917
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 255000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 1 10\n", "output": "10\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 3 9\n", "output": "1\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
787_C. Berzerk
Solve the following coding problem using the programming language python: Rick and Morty are playing their own version of Berzerk (which has nothing in common with the famous Berzerk game). This game needs a huge space, so they play it with a computer. In this game there are n objects numbered from 1 to n arranged in...
```python import queue n = int(input()) sR = list(map(int, input().split()[1:])) sM = list(map(int, input().split()[1:])) s = [sR, sM] UNK = -1 WIN = 2 LOSE = 3 A = [[UNK] * n for i in range(2)] CNT = [[0] * n for i in range(2)] V = [[False] * n for i in range(2)] # ricky turn 0 # morty turn 1 A[0][0] = LOSE A[1][0...
vfc_31921
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 4, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "8\n4 6 2 3 4\n2 3 6\n", "output": "Win Win Win Win Win Win Win \nLose Win Lose Lose Win Lose Lose \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n2 3 2\n3 1 2 3\n", "output": "Lo...
code_contests
verifiable_code
808_G. Anthem of Berland
Solve the following coding problem using the programming language python: Berland has a long and glorious history. To increase awareness about it among younger citizens, King of Berland decided to compose an anthem. Though there are lots and lots of victories in history of Berland, there is the one that stand out the...
```python def prefix(st): t = 0 p = [0] * (len(st) + 1) o = [0] * (len(st) + 1) for i in range(2, len(st)): while t > 0 and st[i] != st[t + 1]: t = p[t] if st[i] == st[t + 1]: t += 1 p[i] = t while t > 0: o[t] = 1 t = p[t] return o ...
vfc_31925
{ "difficulty": "13", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "glo?yto?e??an?\nor\n", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "??c?????\nabcab\n", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
833_C. Ever-Hungry Krakozyabra
Solve the following coding problem using the programming language python: <image> Recently, a wild Krakozyabra appeared at Jelly Castle. It is, truth to be said, always eager to have something for dinner. Its favorite meal is natural numbers (typically served with honey sauce), or, to be more precise, the zeros in t...
vfc_31929
{ "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": "1 10\n", "output": "9\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "40 57\n", "output": "17\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "157...
code_contests
verifiable_code
854_A. Fraction
Solve the following coding problem using the programming language python: Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction <image> is called proper iff its numerator is smaller than its denominator (a < b) and that the fraction is called irreducible if it...
```python import math n=int(input()) d=n//2 c=n-d while math.gcd(c,d)!=1: c+=1 d-=1 print(d,c) ```
vfc_31933
{ "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": "12\n", "output": "5 7\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n", "output": "1 3\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
878_D. Magic Breeding
Solve the following coding problem using the programming language python: Nikita and Sasha play a computer game where you have to breed some magical creatures. Initially, they have k creatures numbered from 1 to k. Creatures have n different characteristics. Sasha has a spell that allows to create a new creature from...
vfc_31937
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 1024000000, "problem_url": null, "time_limit": "{'seconds': 4, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 2 4\n1 2\n2 1\n1 1 2\n2 1 2\n3 3 1\n3 4 2\n", "output": "2\n1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 3 8\n1 2 3 4 5\n5 1 2 3 4\n4 5 1 2 3\n1 1 2\n1 2 3\n2 4 5\n3 6 1\n3 6 2\n3...
code_contests
verifiable_code
902_A. Visiting a Friend
Solve the following coding problem using the programming language python: Pig is visiting a friend. Pig's house is located at point 0, and his friend's house is located at point m on an axis. Pig can use teleports to move along the axis. To use a teleport, Pig should come to a certain point (where the teleport is l...
```python n, m = list( map( int, input().split() ) ) A = [] B = [] CanReach = [] start_idx = 0 end_idx = 0 for i in range( n ): a, b = list( map( int, input().split() ) ) A.append( a ) B.append( b ) memo = {} def best( i ): if A[i] <= m <= B[i]: return ( True ) if i in memo: r...
vfc_31941
{ "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 5\n0 2\n2 4\n3 5\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 7\n0 4\n2 5\n6 7\n", "output": "NO\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
924_C. Riverside Curio
Solve the following coding problem using the programming language python: Arkady decides to observe a river for n consecutive days. The river's water level on each day is equal to some real value. Arkady goes to the riverside each day and makes a mark on the side of the channel at the height of the water level, but i...
```python N = int(input()) above = list(map(int, input().split())) if N == 1: print(0) quit() required_mark = [0] * N required_mark[N-2] = above[N-1] for i in reversed(range(N-2)): required_mark[i] = max(above[i+1], required_mark[i+1] - 1) d = 0 mark = 1 for i in range(1, N): if mark == above[i]: ...
vfc_31945
{ "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": "5\n0 1 1 2 2\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n0 1 0 3 0 2\n", "output": "6\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
952_E. Cheese Board
Solve the following coding problem using the programming language python: Not to be confused with [chessboard](https://en.wikipedia.org/wiki/Chessboard). <image> Input The first line of input contains a single integer N (1 ≤ N ≤ 100) — the number of cheeses you have. The next N lines describe the cheeses you have....
```python a, b = 0, 0 n = int(input()) for i in range(n): x, y = input().split() if y == 'soft': a += 1 else: b += 1 for i in range(1, 1000): n = i*i y = n // 2 x = n - y if (a <= x and b <= y) or (a <= y and b <= x): print(i) break ```
vfc_31949
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\nparmesan hard\nemmental hard\nedam hard\ncolby hard\ngruyere hard\nasiago hard\n", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "9\nbrie soft\ncamembert soft\nfeta soft\n...
code_contests
verifiable_code
97_B. Superset
Solve the following coding problem using the programming language python: A set of points on a plane is called good, if for any two points at least one of the three conditions is true: * those two points lie on same horizontal line; * those two points lie on same vertical line; * the rectangle, with corners i...
```python def build(l, r): if l >= r: return mid = (l+r) >> 1 for i in range(l, r): s.add((a[mid][0], a[i][1])) build(l, mid) build(mid+1, r) n = input() a = [] for i in range(0, n): x, y = map(int, raw_input().split()) a.append((x, y)) a.sort() s = set() build(0, n) print le...
vfc_31953
{ "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": "2\n1 1\n2 2\n", "output": "3\n1 1\n1 2\n2 2", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n0 1\n1 0\n", "output": "3\n0 0\n0 1\n1 0", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
99_B. Help Chef Gerasim
Solve the following coding problem using the programming language python: In a far away kingdom young pages help to set the table for the King. As they are terribly mischievous, one needs to keep an eye on the control whether they have set everything correctly. This time the royal chef Gerasim had the impression that ...
```python n = int(input()) arr = [int(input()) for _ in range(n)] if len(set(arr)) == 1: print('Exemplary pages.') elif len(set(arr)) > 3: print('Unrecoverable configuration.') else: kek = set(arr) kek = list(kek) kek.sort() val = kek[-1] - kek[0] if val % 2 == 1: print('Unrecoverabl...
vfc_31957
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 0, 'nanos': 500000000}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n250\n250\n250\n250\n250\n", "output": "Exemplary pages.\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n270\n250\n250\n230\n250\n", "output": "20 ml. from cup #4 to cup #1.\n",...
code_contests
verifiable_code
benny-and-the-broken-odometer
Solve the following coding problem using the programming language python: One fine day, Benny decided to calculate the number of kilometers that she traveled by her bicycle. Therefore, she bought an odometer and installed it onto her bicycle. But the odometer was broken. It was not able to display the digit 3. This wo...
```python import math def distance_removal(n): if n < 3: return 0 digits = int(math.log10(n)) # print 'digits =', digits num_count = int(10**digits) - int(9**digits) p = int(10**digits) msd = int(n/p) # print 'n/p =', n//p # print 'msd = ', msd if msd > 3: return...
vfc_31961
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n5\n14\n76\n67\n40\n\nSAMPLE", "output": "4\n12\n59\n51\n27\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "100\n402\n409\n278\n29\n268\n874\n527\n617\n727\n485\n616\n724\n660\n190\n286\...
code_contests
verifiable_code
composition
Solve the following coding problem using the programming language python: We all know that every positive integer can be represented as the sum of one or more odd integers. For eg: 4 = 1 + 1 + 1 + 1. Now, your task in this question is to find out the value of G(n), which equals to the number of all possible represent...
```python fib_matrix = [[1,1], [1,0]] def matrix_square(A, mod): return mat_mult(A,A,mod) def mat_mult(A,B, mod): if mod is not None: return [[(A[0][0]*B[0][0] + A[0][1]*B[1][0])%mod, (A[0][0]*B[0][1] + A[0][1]*B[1][1])%mod], [(A[1][0]*B[0][0] + A[1][1]*B[1][0])%mod, (A[1][0]*B[0]...
vfc_31965
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n1\n4\n\nSAMPLE", "output": "1\n3", "type": "stdin_stdout" }, { "fn_name": null, "input": "1000\n25681017298294515\n312600462688402121\n833646696039112627\n223491184116692039\n162199167831855427\n5...
code_contests
verifiable_code
fill-the-box
Solve the following coding problem using the programming language python: Vipul has N empty boxes, numbered from 1 to N, with infinite capacity. He performs M operations. Each operation is described by 3 integers, a, b, and k. Here, a and b are indices of the boxes, and k is the number of marbles to be added inside ea...
```python s = raw_input().split(" ") n = int(s[0]) m = int(s[1]) items = [0]*n; for i in range(0,m): s = raw_input().split(" ") a = int(s[0]) b = int(s[1]) k = int(s[2]) for j in range(a-1,b): items[j]=items[j]+k sum=0 for j in range(0,n): sum=sum+items[j] print sum/n ```
vfc_31969
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 3\n1 2 100\n2 5 100\n3 4 100\n\nSAMPLE", "output": "160\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 3\n2 3 603\n1 1 286\n4 4 882", "output": "593\n", "type": "stdin_std...
code_contests
verifiable_code
marut-and-girls
Solve the following coding problem using the programming language python: Marut is now a well settled person. Impressed by the coding skills of Marut, N girls wish to marry him. Marut will consider marriage proposals of only those girls who have some special qualities. Qualities are represented by positive non-zero in...
```python m = int(raw_input()) dict = {} for i in raw_input().split(" "): dict[int(i)] = 0 girls = 0 for j in range(input()): count = 0 for e in raw_input().split(" "): if int(e) in dict: count+=1 if (count >= m): girls+=1 print girls ```
vfc_31977
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n1 2 3 4 5\n3\n1 2 3 4 5 6\n1 2 3 4 5\n1 2 3 4SAMPLE", "output": "2\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
number-theory
Solve the following coding problem using the programming language python: Quan_Lank is a great team with some uncommon interests in programming. Sometimes the team loves to solve strings puzzles, sometimes game puzzles and sometimes metrix type puzzles . Yesterday they have added a new interest to their list that is '...
```python t = int(raw_input()) def check(k,dict): kk = str(k) for char in kk: if (dict.has_key(char) == True): return True; return False; while (t>0): i = int(raw_input()) j = str(i) dict = {} for char in j: dict[char] = 1 k = 1; count = 0; while (k*k <= i): if (i % k == 0): if (check(k,dict) ==...
vfc_31981
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n1\n10\n\nSAMPLE", "output": "1\n2", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1\n10\n\nSAMQLE", "output": "1\n2\n", "type": "stdin_stdout" }, { "fn_name":...
code_contests
verifiable_code
raghu-vs-sayan
Solve the following coding problem using the programming language python: Raghu and Sayan both like to eat (a lot) but since they are also looking after their health, they can only eat a limited amount of calories per day. So when Kuldeep invites them to a party, both Raghu and Sayan decide to play a game. The game is...
```python if __name__ == '__main__': T = int(raw_input()) while T > 0: [R, S, N] = [int(x) fo...
vfc_31985
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n15 20 3\n10 5 4\n3 10 2\n4 7\n10 8 3\n4 5 5\n\nSAMPLE", "output": "Sayan Won\nSayan Won\nRaghu Won\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n15 20 3\n8 5 4\n3 10 2\n4 7\n10 8 3...
code_contests
verifiable_code
shils-romantic-message
Solve the following coding problem using the programming language python: Shil is now finally in a relationship with Uttu. Both of them like to exchange love letters. However, to avoid exposing their relationship, they use "encryption" to send their messages. They use the famous Caesar cipher to encrypt their messages...
```python def find(s): n=26-(ord(s[0])-ord('a')) z="z" out="" for i in s: if ord(i)+n <= ord(z): out+=chr(ord(i)+n) else: x=ord(z)-ord(i) y=n-x-1 out+=chr(ord('a')+y) print out if __name__ == '__main__': t=int(raw_input()) while t>0: s=raw_input() find(s) t-=1 ```
vfc_31989
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\nphqghumeay\n\nSAMPLE", "output": "asbrsfxplj", "type": "stdin_stdout" }, { "fn_name": null, "input": "100\nphqghumeaylnlfdxfircvscxggbwkfnqduxwfnfozvsrtkjprepggxrpnrvystmwcysyycqpevikeffmznimkkasv...
code_contests
verifiable_code
the-reversed-numbers
Solve the following coding problem using the programming language python: HackerMan has a message that he has coded in form of digits, which means that the message contains only numbers and nothing else. He is fearful that the enemy may get their hands on the secret message and may decode it. HackerMan already knows t...
```python import string t=int(raw_input()) while t: s=[] a,b=raw_input().split() c=int(a[::-1])+int(b[::-1]) print string.lstrip(str(c)[::-1],'0') t=t-1 ```
vfc_31993
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n353 575\n238746 39857\n890 231\n\nSAMPLE", "output": "829\n527327\n32\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p00092 Square Searching
Solve the following coding problem using the programming language python: There are a total of n x n squares, n rows vertically and n columns horizontally. Some squares are marked. Create a program that reads the marked state of each square and displays the length of the side of the largest square consisting of only t...
```python # -*- coding: utf-8 -*- """ http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0092 """ import sys def find_square0(data): max_size = 0 dp = [] # dp??¨???2?¬?????????? # '.'????????????1??????'*'????????????0???????????? for row in data: temp = [] for c in row: ...
vfc_32041
{ "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\n...*....**\n..........\n**....**..\n........*.\n..*.......\n..........\n.*........\n..........\n....*..***\n.*....*...\n10\n****.*****\n*..*.*....\n****.*....\n*....*....\n*....*****\n..........\n****.*****\n*..*...*..\n****......
code_contests
verifiable_code
p00224 Bicycle Diet
Solve the following coding problem using the programming language python: Mr. A loves sweets, but recently his wife has told him to go on a diet. One day, when Mr. A went out from his home to the city hall, his wife recommended that he go by bicycle. There, Mr. A reluctantly went out on a bicycle, but Mr. A, who likes...
```python from itertools import combinations from heapq import heappop, heappush import sys sys.setrecursionlimit(1000000) INF = 10 ** 20 def convert(s, m, n): if s == "H": return 0 if s == "D": return 1 if s[0] == "C": return int(s[1:]) + 1 if s[0] == "L": return int(s[1:]) + m + 1 def get_co...
vfc_32045
{ "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": "1 1 2 5\n35\nH L1 5\nC1 D 6\nC1 H 12\nL1 D 10\nC1 L1 20\n2 1 4 6\n100 70\nH L1 5\nC1 L1 12\nC1 D 11\nC2 L1 7\nC2 D 15\nL1 D 8\n0 0 0 0", "output": "1\n-2", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p00602 Fibonacci Sets
Solve the following coding problem using the programming language python: Fibonacci number f(i) appear in a variety of puzzles in nature and math, including packing problems, family trees or Pythagorean triangles. They obey the rule f(i) = f(i - 1) + f(i - 2), where we set f(0) = 1 = f(-1). Let V and d be two certain...
```python from collections import deque try: while 1: V, d = map(int, input().split()) F = [0]*V a = b = 1 for v in range(V): a, b = (a+b) % 1001, a F[v] = a G = [[] for i in range(V)] for i in range(V): for j in range(i+1, V): ...
vfc_32053
{ "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": "5 5\n50 1\n13 13", "output": "2\n50\n8", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 5\n50 2\n13 13", "output": "2\n47\n8\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p00738 Roll-A-Big-Ball
Solve the following coding problem using the programming language python: ACM University holds its sports day in every July. The "Roll-A-Big-Ball" is the highlight of the day. In the game, players roll a ball on a straight course drawn on the ground. There are rectangular parallelepiped blocks on the ground as obstacl...
```python def cross(c1, c2): return c1.real * c2.imag - c1.imag * c2.real def dot(c1, c2): return c1.real * c2.real + c1.imag * c2.imag def ccw(p0, p1, p2): a = p1 - p0 b = p2 - p0 cross_ab = cross(a, b) if cross_ab > 0: return 1 elif cross_ab < 0: return -1 elif dot(a,...
vfc_32057
{ "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": "2\n-40 -40 100 30\n-100 -100 -50 -30 1\n30 -70 90 -30 10\n2\n-4 -4 10 3\n-10 -10 -5 -3 1\n3 -7 9 -3 1\n2\n-40 -40 100 30\n-100 -100 -50 -30 3\n30 -70 90 -30 10\n2\n-400 -400 1000 300\n-800 -800 -500 -300 7\n300 -700 900 -300 20\n3\...
code_contests
verifiable_code
p00878 Origami Through-Hole
Solve the following coding problem using the programming language python: Origami is the traditional Japanese art of paper folding. One day, Professor Egami found the message board decorated with some pieces of origami works pinned on it, and became interested in the pinholes on the origami paper. Your mission is to s...
vfc_32061
{ "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\n90 90 80 20\n80 20 75 50\n50 35\n2\n90 90 80 20\n75 50 80 20\n55 20\n3\n5 90 15 70\n95 90 85 75\n20 67 20 73\n20 75\n3\n5 90 15 70\n5 10 15 55\n20 67 20 73\n75 80\n8\n1 48 1 50\n10 73 10 75\n31 87 31 89\n91 94 91 96\n63 97 62 96...
code_contests
verifiable_code
p01009 Room of Time and Spirit
Solve the following coding problem using the programming language python: Problem In 20XX, a scientist developed a powerful android with biotechnology. This android is extremely powerful because it is made by a computer by combining the cells of combat masters. At this rate, the earth would be dominated by androids,...
```python # AOJ 1519: Room of Time and Spirit # Python3 2018.7.13 bal4u # Weighted UNION-FIND library class WeightedUnionSet: def __init__(self, nmax): self.ws = [0]*nmax self.par = [-1]*nmax self.power = [0]*nmax def find(self, x): if self.par[x] < 0: return x p = self.find(self.par[x]) self.ws[x] += se...
vfc_32065
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 3\nIN 1 4 10\nIN 2 3 20\nCOMPARE 1 2", "output": "WARNING", "type": "stdin_stdout" }, { "fn_name": null, "input": "10 4\nIN 10 8 2328\nIN 8 4 3765\nIN 3 8 574\nCOMPARE 4 8", "output": "-3191"...
code_contests
verifiable_code
p01141 Lifeguard in the Pool
Solve the following coding problem using the programming language python: Lifeguard in the Pool Pool guard English text is not available in this practice contest. Horton Moore works as a pool watchman. As he walked around the edge of the pool to look around, he noticed a girl drowning in the pool. Of course, he mus...
vfc_32069
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 8, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n0 0 10 0 10 10 0 10\n10\n12\n0 5\n9 5\n4\n0 0 10 0 10 10 0 10\n10\n12\n0 0\n9 1\n4\n0 0 10 0 10 10 0 10\n10\n12\n0 1\n9 1\n8\n2 0 4 0 6 2 6 4 4 6 2 6 0 4 0 2\n10\n12\n3 0\n3 5\n0", "output": "108.0\n96.63324958071081\n103....
code_contests
verifiable_code
p01280 Galaxy Wide Web Service
Solve the following coding problem using the programming language python: The volume of access to a web service varies from time to time in a day. Also, the hours with the highest volume of access varies from service to service. For example, a service popular in the United States may receive more access in the daytime...
```python from itertools import cycle while True: n = int(input()) if not n: break qs = {} for i in range(n): d, t, *q = (int(s) for s in input().split()) q = q[t:] + q[:t] if d not in qs: qs[d] = q else: qs[d] = [a + b for a, b in zip(qs[...
vfc_32073
{ "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\n4 0 1 2 3 4\n2 0 2 1\n0", "output": "5", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n4 0 1 2 3 4\n2 -1 2 1\n0", "output": "6\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p01450 My friends are small
Solve the following coding problem using the programming language python: I have a lot of friends. Every friend is very small. I often go out with my friends. Put some friends in your backpack and go out together. Every morning I decide which friends to go out with that day. Put friends one by one in an empty backpack...
```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**13 mod = 10**9+7 dd = [(-1,0),(0,1),(1,0),(0,-1)] ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] def LI(): return [int(x) for x in ...
vfc_32077
{ "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 37\n5\n9\n13\n18\n26\n33", "output": "6", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 25\n20\n15\n20\n15", "output": "4", "type": "stdin_stdout" }, { "fn_name...
code_contests
verifiable_code
p01600 Tree Construction
Solve the following coding problem using the programming language python: Problem J: Tree Construction Consider a two-dimensional space with a set of points (xi, yi) that satisfy xi < xj and yi > yj for all i < j. We want to have them all connected by a directed tree whose edges go toward either right (x positive) or...
vfc_32081
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 8, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n1 5\n2 4\n3 3\n4 2\n5 1", "output": "12", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p01896 Folding Paper
Solve the following coding problem using the programming language python: Problem statement There is a rectangular piece of paper divided in a grid with a height of $ H $ squares and a width of $ W $ squares. The integer $ i \ times W + j $ is written in the cell of the $ i $ line from the top and the $ j $ column fr...
vfc_32089
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 268435456, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 4\n0 1 2 3", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 4\n0 1 2 5", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, "i...
code_contests
verifiable_code
p02033 Arrow
Solve the following coding problem using the programming language python: D: Arrow / Arrow problem rodea is in a one-dimensional coordinate system and stands at x = 0. From this position, throw an arrow of positive integer length that always moves at speed 1 towards the target at x = N. However, rodea is powerless, ...
```python from bisect import bisect_left def inpl(): return list(map(int, input().split())) N, M = inpl() X = inpl() Q = int(input()) L = inpl() X += [N+1] initcost = X[0] - 1 costs = [X[i+1] - X[i] - 1 for i in range(M) if X[i+1] - X[i] > 1] C = [0]*(N+1) C[0] = - 10**9 for i in range(1, N+1): cost = 0 cost...
vfc_32093
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 268435456, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 1\n2\n1\n3", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 1\n2\n1\n3", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "inpu...
code_contests
verifiable_code
p02176 Shortest Crypt
Solve the following coding problem using the programming language python: problem Cryptography is all the rage at xryuseix's school. Xryuseix, who lives in a grid of cities, has come up with a new cryptography to decide where to meet. The ciphertext consists of the $ N $ character string $ S $, and the $ S_i $ chara...
```python N = int(input()) word = list(input()) X1 = ['A','B','C','D','E','F','G','H','I','J','K','L','M'] X2 = ['N','O','P','Q','R','S','T','U','V','W','X','Y','Z'] Y1 = ['a','b','c','d','e','f','g','h','i','j','k','l','m'] Y2 = ['n','o','p','q','r','s','t','u','v','w','x','y','z'] x = 0 y = 0 answer = "" for i in wor...
vfc_32097
{ "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": "5\nANazA", "output": "1\nA", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\nAzaNA", "output": "1\nA\n", "type": "stdin_stdout" }, { "fn_name": null, "input"...
code_contests
verifiable_code
p02319 0-1 Knapsack Problem II
Solve the following coding problem using the programming language python: You have N items that you want to put them into a knapsack. Item i has value vi and weight wi. You want to find a subset of items to put such that: * The total value of the items is as large as possible. * The items have combined weight at mos...
```python n, m = map(int, input().split()) VW = [tuple(map(int, input().split())) for i in range(n)] V = [v for v, w in VW] W = [w for v, w in VW] # n, m = 4, 5 # V = [4, 5, 2, 8] # W = [2, 2, 1, 3] # DP[i][j]=i個の品物で価値j以上で最小の重さ sv = sum(V) inf = 10**10 DP = [[inf for j in range(sv+1)] for i in range(n+1)] DP[0][0] = 0 ...
vfc_32101
{ "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 5\n4 2\n5 2\n2 1\n8 3", "output": "13", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 20\n5 9\n4 10", "output": "9", "type": "stdin_stdout" }, { "fn_name": null...
code_contests
verifiable_code
a3
Solve the following coding problem using the programming language python: Alice and Johnny are playing a simple guessing game. Johnny picks an arbitrary positive integer n (1 ≤ n ≤ 10^9) and gives Alice exactly k hints about the value of n. It is Alice's task to guess n, based on the received hints. Alice often has ...
```python from collections import Counter minr = 1 maxr = 10 ** 9 + 1 t = int(raw_input()) for i in xrange(t): k = int(raw_input()) cnt = Counter() for j in xrange(k): op, num, ans = raw_input().split() ans = ans.upper() num = int(num) if op == '<': if ans == 'YES...
vfc_32109
{ "difficulty": "2", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n2\n< 100 No\n> 100 No\n3\n< 2 Yes\n> 4 Yes\n= 3 No\n6\n< 2 Yes\n> 1 Yes\n= 1 Yes\n= 1 Yes\n> 1 Yes\n= 1 Yes", "output": "0\n1\n2", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n2\n< 10...
code_contests
verifiable_code
chefbm
Solve the following coding problem using the programming language python: Spring is interesting season of year. Chef is thinking about different things, but last time he thinks about interesting game - "Strange Matrix". Chef has a matrix that consists of n rows, each contains m elements. Initially, the element aij of...
```python n,m,p=map(int,raw_input().split()) b=[] for x in xrange(p): a=map(int,raw_input().split()) b.append(a) b.sort() pos=0 for i in xrange(1,n+1): if b[pos][0]!=i: ans=m-1 else: count=0 prev=0 ans=m-1 while b[pos][0]==i and m!=1: count=count+1 ...
vfc_32113
{ "difficulty": "2", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 4 6\n2 2\n3 2 \n3 2 \n4 3\n4 4\n4 3", "output": "3\n3\n-1\n4", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 4 6\n3 2\n3 2 \n3 2 \n4 3\n4 4\n4 3", "output": "3\n3\n-1\n4\n", ...
code_contests
verifiable_code
digjump
Solve the following coding problem using the programming language python: Chef loves games! But he likes to invent his own. Now he plays game "Digit Jump". Chef has sequence of digits S1, S2,..., SN,. He is staying in the first digit (S1) and want to reach the last digit (SN) in the minimal number of jumps. While sta...
```python import sys s = raw_input().strip() digits = [[] for i in xrange(10)] dist = [-1] * (len(s)) used = [False] * 10 for i in xrange(len(s)): digits[int(s[i])].append(i) dist[0] = 0 q = [0] while True: v = q.pop(0) cur = dist[v] if v == len(s)-1: print cur sys.exit() ...
vfc_32117
{ "difficulty": "2", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "01234567890", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "012134444444443", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "...
code_contests
verifiable_code
insoma4
Solve the following coding problem using the programming language python: In the hidden country of Lapatrecta, an age old custom was followed to ensure that no outsider ever entered their country undetected. The security measure, though simple, was an effective one. Every person born in Lapatrecta had the initials of ...
```python N = int (raw_input()) words = [] maxDep = 0 def dfs(dic, depth): global maxDep if dic['__a'] > 1: if depth > maxDep: maxDep = depth for key in dic.keys(): if key!='__a': if dic[key]['__a'] > 1: dfs(dic[key], depth+1) dic = {} dic['__a'...
vfc_32121
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\nAPJQ\nAPJRS\nPJQ", "output": "3", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
nf02
Solve the following coding problem using the programming language python: NITMAS Fest is live. The members of the community are very busy. People from different colleges have come to compete. But, Naveen is very possessive about his girlfriend, Archana. He always remains close to his girlfriend. Couples (boys in a lin...
```python a=list(map(int,raw_input().split())) b=list(map(int,raw_input().split())) arr=[] for i in range(1,len(a)): for j in range(1,len(b)): arr.append(abs(a[i]-b[j])) arr=sorted(arr) print arr[0] ```
vfc_32125
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 2 4 6 8\n5 1 3 5 7 9", "output": "1", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
salg04
Solve the following coding problem using the programming language python: p { font-size:14px; text-align:justify; } Two positive integers n amd m, n greater than or equal to m, will be given as input. Make a code that generates all possible combinations of 1,2,3,...,n taking m integers at a time in "increasing orde...
```python import itertools n = int(raw_input()) m = int(raw_input()) ls = range(1, n + 1) op = list(itertools.combinations(ls, m)) for t in op: for x in t: print x, print ```
vfc_32129
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n3", "output": "1 2 3 \n1 2 4\n1 2 5\n1 3 4\n1 3 5\n1 4 5\n2 3 4\n2 3 5\n2 4 5\n3 4 5", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1000_A. Codehorses T-shirts
Solve the following coding problem using the programming language python: Codehorses has just hosted the second Codehorses Cup. This year, the same as the previous one, organizers are giving T-shirts for the winners. The valid sizes of T-shirts are either "M" or from 0 to 3 "X" followed by "S" or "L". For example, si...
```python t=int(input()) pre=[] curr=[] for i in range(t): s1=input() pre.append(s1) for i in range(t): s2=input() curr.append(s2) z=0 for i in range(t): if pre[i] in curr: curr.remove(pre[i]) pass else: z+=1 print(z) ```
vfc_32133
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\nM\nXS\nXS\nM\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\nXS\nXS\nM\nXL\nS\nXS\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name...
code_contests
verifiable_code
1025_B. Weakened Common Divisor
Solve the following coding problem using the programming language python: During the research on properties of the greatest common divisor (GCD) of a set of numbers, Ildar, a famous mathematician, introduced a brand new concept of the weakened common divisor (WCD) of a list of pairs of integers. For a given list of p...
```python def gcd(a,b): if a%b==0: return b else: return gcd(b,a%b) import math def pr(n): a=[] while n % 2 == 0: a.append(2) n = n / 2 for i in range(3,int(math.sqrt(n))+1,2): while n % i== 0: a.append(i) ...
vfc_32137
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 500000000}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n10 16\n7 17\n", "output": "-1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n17 18\n15 24\n12 15\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name"...
code_contests
verifiable_code
1045_D. Interstellar battle
Solve the following coding problem using the programming language python: In the intergalactic empire Bubbledom there are N planets, of which some pairs are directly connected by two-way wormholes. There are N-1 wormholes. The wormholes are of extreme religious importance in Bubbledom, a set of planets in Bubbledom co...
vfc_32141
{ "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": "5\n0.50 0.29 0.49 0.95 0.83\n2 3\n0 3\n3 4\n2 1\n3\n4 0.66\n1 0.69\n0 0.36\n", "output": "1.68040\n1.48440\n1.61740\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1068_D. Array Without Local Maximums
Solve the following coding problem using the programming language python: Ivan unexpectedly saw a present from one of his previous birthdays. It is array of n numbers from 1 to 200. Array is old and some numbers are hard to read. Ivan remembers that for all elements at least one of its neighbours ls not less than it, ...
```python import os from io import BytesIO from math import trunc if os.name == 'nt': input = BytesIO(os.read(0, os.fstat(0).st_size)).readline MX = 201 MOD = 998244353 MODF = float(MOD) MODF_inv = 1.0 / MODF quickmod1 = lambda x: x - MODF * trunc(x / MODF) def quickmod(a): return a - MODF * trunc(a * MODF...
vfc_32145
{ "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": "3\n1 -1 2\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n-1 -1\n", "output": "200\n", "type": "stdin_stdout" }, { "fn_name": null, "inp...
code_contests
verifiable_code
1090_C. New Year Presents
Solve the following coding problem using the programming language python: Santa has prepared boxes with presents for n kids, one box for each kid. There are m kinds of presents: balloons, sweets, chocolate bars, toy cars... A child would be disappointed to receive two presents of the same kind, so all kinds of present...
```python n, m = map(int, raw_input().split()) a = [] u = [{} for i in xrange(n)] k = 0 for i in xrange(n): s = map(int, raw_input().split()) a.append([s[0], i]) for x in s[1:]: u[i][x] = 1 k += s[0] a = sorted(a) h = n - (k % n) k = k / n wi = 0 w = [() for i in xrange(10 ** 6)] for i in xrange(n): ...
vfc_32149
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 5\n5 1 2 3 4 5\n2 1 2\n2 3 4\n", "output": "2\n1 2 3\n1 3 1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1\n0\n", "output": "0\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1109_F. Sasha and Algorithm of Silence's Sounds
Solve the following coding problem using the programming language python: One fine day Sasha went to the park for a walk. In the park, he saw that his favorite bench is occupied, and he had to sit down on the neighboring one. He sat down and began to listen to the silence. Suddenly, he got a question: what if in diffe...
vfc_32153
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 500000000}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 4\n4 3 2 16\n1 13 14 15\n5 7 8 12\n6 11 9 10\n", "output": "50\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 3\n1 2 3\n4 5 6\n", "output": "15\n", "type": "stdin_stdout" ...
code_contests
verifiable_code
1139_C. Edgy Trees
Solve the following coding problem using the programming language python: You are given a tree (a connected undirected graph without cycles) of n vertices. Each of the n - 1 edges of the tree is colored in either black or red. You are also given an integer k. Consider sequences of k vertices. Let's call a sequence [a...
```python kk=lambda:map(int,input().split()) ll=lambda:list(kk()) n, k = kk() dsud = {i:{i} for i in range(n)} dsup = {i:i for i in range(n)} for _ in range(n-1): u, v, xi = kk() u,v = u-1,v-1 if xi == 0: s1, s2 = dsud[dsup[u]], dsud[dsup[v]] if len(s1) > len(s2): s1 |= s2 del dsud[dsup[v]] for el in s2...
vfc_32157
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 4\n1 2 1\n2 3 1\n3 4 1\n", "output": " 252\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 6\n1 2 0\n1 3 0\n1 4 0\n", ...