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
304_A. Pythagorean Theorem II
Solve the following coding problem using the programming language python: In mathematics, the Pythagorean theorem — is a relation in Euclidean geometry among the three sides of a right-angled triangle. In terms of areas, it states: In any right-angled triangle, the area of the square whose side is the hypotenuse (th...
```python def gcd(a, b): c = a % b return gcd(b, c) if c else b from math import sqrt n = int(input()) print(sum(n // (x * x + y * y) for x in range(1, int(sqrt(n // 2)) + 1) for y in range(x + 1, int(sqrt(n - x * x)) + 1, 2) if gcd(x, y) == 1)) ```
vfc_60161
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "74\n", "output": "35", "type": "stdin_stdout" }, { "fn_name": null, "input": "625\n", ...
code_contests
verifiable_code
330_B. Road Construction
Solve the following coding problem using the programming language python: A country has n cities. Initially, there is no road in the country. One day, the king decides to construct some roads connecting pairs of cities. Roads can be traversed either way. He wants those roads to be constructed in such a way that it is ...
```python __author__ = 'Rajan' n,m = map(int,input().split()) # n nodes and m edges hash = [False for i in range(n+1)] for i in range(m): a,b = map(int,input().split()) hash[a] = hash[b] = True b = 0 for i in range(1,n+1): if not hash[i]: b = i break print(n-1) for i in range(1,n+1): i...
vfc_60165
{ "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 1\n1 3\n", "output": "3\n2 1\n2 3\n2 4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 1\n1 2\n", "output": "2\n3 1\n3 2\n", "type": "stdin_stdout" }, { "fn_n...
code_contests
verifiable_code
351_E. Jeff and Permutation
Solve the following coding problem using the programming language python: Jeff's friends know full well that the boy likes to get sequences and arrays for his birthday. Thus, Jeff got sequence p1, p2, ..., pn for his birthday. Jeff hates inversions in sequences. An inversion in sequence a1, a2, ..., an is a pair of i...
```python n = int(input()) inp = input() seq = inp.split(' ') seq = [ abs(int(x)) for x in seq ] Max = max(seq) nxt = [0] * n cnt = [0] * n pos = [n] * (Max+1) for i in range(n-1, -1, -1): nxt[i] = pos[seq[i]] pos[seq[i]] = i for i in range(0, Max+1): j = pos[i] while(j<n): front = sum(cnt[0:j])...
vfc_60169
{ "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": "9\n-2 0 -1 0 -1 2 1 0 -1\n", "output": "6", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n2 1\n", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
376_A. Lever
Solve the following coding problem using the programming language python: You have a description of a lever as string s. We'll represent the string length as record |s|, then the lever looks as a horizontal bar with weights of length |s| - 1 with exactly one pivot. We will assume that the bar is a segment on the Ox ax...
```python a=input() x=a.index('^') c=0 for i in range(len(a)): if a[i]in['^','=']:continue c+=int(a[i])*(i-x) print("right"if c>0else("left"if c<0else"balance")) ```
vfc_60173
{ "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": "=^==\n", "output": "balance", "type": "stdin_stdout" }, { "fn_name": null, "input": "2==^7==\n", "output": "right", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
398_C. Tree and Array
Solve the following coding problem using the programming language python: User ainta likes trees. This time he is going to make an undirected tree with n vertices numbered by integers from 1 to n. The tree is weighted, so each edge of the tree will have some integer weight. Also he has an array t: t[1], t[2], ..., t[...
vfc_60177
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7", "output": "1 4 1\n2 5 1\n3 6 1\n4 5 1\n5 6 3\n6 7 5\n1 2\n2 3\n1 3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "11\n", "output": "1 6 1\n2 7 1\n3 8 1\n4 9 1\n5 10 1\n6 7 1\n7 ...
code_contests
verifiable_code
420_D. Cup Trick
Solve the following coding problem using the programming language python: The employees of the F company have lots of ways to entertain themselves. Today they invited a famous magician who shows a trick with plastic cups and a marble. The point is to trick the spectator's attention. Initially, the spectator stands in...
```python import io import os # List with O(n^1/3) (for n=10**6) get/set/insert/delete based on: https://github.com/cheran-senthil/PyRival/blob/master/pyrival/data_structures/SortedList.py class UnsortedList: def __init__(self, iterable=[], _load=200): """Initialize sorted list instance.""" value...
vfc_60181
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 1\n2 1\n", "output": "2 1", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 2\n1 2\n1 1\n", "output": "2 1 3", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
469_C. 24 Game
Solve the following coding problem using the programming language python: Little X used to play a card game called "24 Game", but recently he has found it too easy. So he invented a new game. Initially you have a sequence of n integers: 1, 2, ..., n. In a single step, you can pick two of them, let's denote them a and...
```python n = int(input()) if n < 4: print('NO') elif n == 4: print('YES') print('1 * 2 = 2') print('2 * 3 = 6') print('6 * 4 = 24') elif n == 5: print('YES') print('4 * 5 = 20') print('3 - 1 = 2') print('20 + 2 = 22') print('22 + 2 = 24') else: print('YES') print('2 * 3 ...
vfc_60189
{ "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": "8\n", "output": "YES\n1 * 2 = 2\n2 * 3 = 6\n6 * 4 = 24\n6 - 5 = 1\n24 * 1 = 24\n8 - 7 = 1\n24 * 1 = 24\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n", "output": "NO\n", "...
code_contests
verifiable_code
491_B. New York Hotel
Solve the following coding problem using the programming language python: Think of New York as a rectangular grid consisting of N vertical avenues numerated from 1 to N and M horizontal streets numerated 1 to M. C friends are staying at C hotels located at some street-avenue crossings. They are going to celebrate birt...
```python N, M = input().split() a, b, c, d = [int(1e10) for _ in range(4)] for i in range(int(input())): x, y = list(map(int, input().split())) a, b, c, d = min(a, x + y), min(b, x - y), min(c, - x + y), min(d, - x - y) res, pos = int(1e10), 0 for i in range(int(input())): x, y = list(map(int, input().spli...
vfc_60193
{ "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 10\n2\n1 1\n3 3\n2\n1 10\n4 4\n", "output": "6\n2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1000000000 1000000000\n2\n1 1\n3 3\n2\n1 10\n4 4\n", "output": "6\n2\n", "t...
code_contests
verifiable_code
515_C. Drazil and Factorial
Solve the following coding problem using the programming language python: Drazil is playing a math game with Varda. Let's define <image> for positive integer x as a product of factorials of its digits. For example, <image>. First, they choose a decimal number a consisting of n digits that contains at least one digit...
```python #in the name of god #Mr_Rubik #CodeForces,Problemset sepData=[[],[],[2],[3],[2,2,3],[5],[5,3],[7],[7,2,2,2],[7,2,3,3]] digit=input() number=input() ans=[] for i in number: if i!='1' and i!='\r': for j in sepData[int(i)]: ans.append(j) ans.sort(reverse=True) for i in ans: print(i,en...
vfc_60197
{ "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\n555\n", "output": "555\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n1234\n", "output": "33222\n", "type": "stdin_stdout" }, { "fn_name": null, "inp...
code_contests
verifiable_code
542_D. Superhero's Job
Solve the following coding problem using the programming language python: It's tough to be a superhero. And it's twice as tough to resist the supervillain who is cool at math. Suppose that you're an ordinary Batman in an ordinary city of Gotham. Your enemy Joker mined the building of the city administration and you on...
vfc_60201
{ "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": "24\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "8\n", ...
code_contests
verifiable_code
569_E. New Language
Solve the following coding problem using the programming language python: Living in Byteland was good enough to begin with, but the good king decided to please his subjects and to introduce a national language. He gathered the best of wise men, and sent an expedition to faraway countries, so that they would find out a...
vfc_60205
{ "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": "VC\n2 1\n1 V 2 C\naa\n", "output": "ab\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "VC\n2 1\n1 C 2 V\nbb\n", "output": "-1\n", "type": "stdin_stdout" }, { "fn_...
code_contests
verifiable_code
590_C. Three States
Solve the following coding problem using the programming language python: The famous global economic crisis is approaching rapidly, so the states of Berman, Berance and Bertaly formed an alliance and allowed the residents of all member states to freely pass through the territory of any of them. In addition, it was dec...
```python # lista doble enlazada o(1) operaciones en los bordes es mejor que si se implementa en el propio lenguaje from collections import deque n, m = input().split() n = int(n) m = int(m) def idx(i, j): return i*m + j max = n*m*2 graph = "" virtDist = [[], [], []] virtVertex = [deque(), deque(), deque()] vir...
vfc_60209
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 5, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 5\n1#2#3\n", "output": "-1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 5\n11..2\n#..22\n#.323\n.#333", "output": "2\n", "type": "stdin_stdout" }, { "fn_na...
code_contests
verifiable_code
612_B. HDD is Outdated Technology
Solve the following coding problem using the programming language python: HDD hard drives group data by sectors. All files are split to fragments and each of them are written in some sector of hard drive. Note the fragments can be written in sectors in arbitrary order. One of the problems of HDD hard drives is the fo...
```python n = int(input()) fi = list(map(int, input().split())) fi2 = list(range(n)) i = 0 while i < n: fi2[fi[i] - 1] = i i += 1 pos = fi2[0] i = 1 d = 0 while i < n: d += abs(fi2[i] - pos) pos = fi2[i] i += 1 print(d) ```
vfc_60213
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n1 3 5 4 2\n", "output": "10\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
632_B. Alice, Bob, Two Teams
Solve the following coding problem using the programming language python: Alice and Bob are playing a game. The game involves splitting up game pieces into two teams. There are n pieces, and the i-th piece has a strength pi. The way to split up game pieces is split into several steps: 1. First, Alice will split th...
```python read = lambda: map(int, input().split()) n = int(input()) p = list(read()) a = [{'B': 1, 'A': 0}[i] for i in input()] cur = sum(p[i] for i in range(n) if a[i]) ans = cur b = a[:] for i in range(n): b[i] = int(not a[i]) if b[i]: cur += p[i] else: cur -= p[i] ans = max(ans, cur) cur = sum(p[i] f...
vfc_60217
{ "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": "1\n1\nB\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n1 2 3 4 5\nAAAAA\n", "output": "15\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
683_I. Loader
Solve the following coding problem using the programming language python: A loader works in a warehouse, which is a rectangular field with size n × m. Some cells of this field are free, others are occupied by pillars on which the roof of the warehouse rests. There is a load in one of the free cells, and the loader i...
vfc_60225
{ "difficulty": "15", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 4, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 3\n..Y\n.BX\n..T\n", "output": "YES\nwSwsE\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 3\n.BY\n...\nTXX\n", "output": "NO\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
707_C. Pythagorean Triples
Solve the following coding problem using the programming language python: Katya studies in a fifth grade. Recently her class studied right triangles and the Pythagorean theorem. It appeared, that there are triples of positive integers such that you can construct a right triangle with segments of lengths corresponding ...
```python if __name__ == '__main__': n = int(input()) if n < 3: print(-1) elif n % 2 == 0: print(str(n*n//4-1) + " " + str(n*n//4+1)) else: print(str((n*n-1)//2) + " " + str((n*n+1)//2)) ```
vfc_60229
{ "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": "67\n", "output": "2244 2245\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
72_D. Perse-script
Solve the following coding problem using the programming language python: Two good friends were trying to make a new programming language called Perse-script. The most important part of this language is strings. A string in Perse-script is put between characters " So for example "Hello" is a string. But Hello is a v...
vfc_60233
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 7, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "\"HelloWorld\"\n", "output": "\"HelloWorld\"\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "REVerse(substr(\"helloworld\",1,5))\n", "output": "\"olleh\"\n", "type": "stdin_std...
code_contests
verifiable_code
750_A. New Year and Hurry
Solve the following coding problem using the programming language python: Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be n problems, sorted by difficulty, i.e. problem 1 is the easiest and problem n...
```python def main(): n,m = [int(v) for v in input().split()] e = 4*60-m d = 0 i = 1 while d<=e: d+=5*(i) if d>e: break i+=1 print(min(n,i-1)) if __name__ == "__main__": main() ```
vfc_60237
{ "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": "7 1\n", "output": "7\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 190\n", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 222...
code_contests
verifiable_code
773_E. Blog Post Rating
Solve the following coding problem using the programming language python: It's well-known that blog posts are an important part of Codeforces platform. Every blog post has a global characteristic changing over time — its community rating. A newly created blog post's community rating is 0. Codeforces users may visit th...
vfc_60241
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 4, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7\n2 -3 -2 5 0 -3 1\n", "output": "1\n0\n-1\n0\n1\n1\n2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n2 0 2 2\n", "output": "1\n1\n2\n2\n", "type": "stdin_stdout" }, ...
code_contests
verifiable_code
798_D. Mike and distribution
Solve the following coding problem using the programming language python: Mike has always been thinking about the harshness of social inequality. He's so obsessed with it that sometimes it even affects him while solving problems. At the moment, Mike has two sequences of positive integers A = [a1, a2, ..., an] and B = ...
```python n = int(input()) A = [int(x) for x in input().split()] B = [int(x) for x in input().split()] idAB = zip(range(n), A, B) idAB = sorted(idAB, key=lambda x: x[1], reverse=True) ans = [idAB[0][0] + 1] i = 1 while i < n: choice = max(idAB[i:i + 2], key=lambda x: x[2]) ans.append(choice[0] + 1) ...
vfc_60245
{ "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": "5\n8 7 4 8 3\n4 2 5 3 7\n", "output": "3\n1 4 5 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n319645572 758298525 812547177 459359946 355467212 304450522 807957797 916787906 2397812...
code_contests
verifiable_code
818_F. Level Generation
Solve the following coding problem using the programming language python: Ivan is developing his own computer game. Now he tries to create some levels for his game. But firstly for each level he needs to draw a graph representing the structure of the level. Ivan decided that there should be exactly ni vertices in the...
```python #! /usr/bin/env python # http://codeforces.com/problemset/problem/818/F # Problem name ::: F. Level Generation # submission number #212055293 #508427854 def newest_approach(n): from math import floor, ceil, sqrt quad_solv = sqrt(2*n+1/4)-1/2 x = floor(quad_solv) y = ceil(quad_solv) x...
vfc_60249
{ "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\n3\n4\n6\n", "output": "2\n3\n6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n508427854\n", "output": "1016791932\n", "type": "stdin_stdout" }, { "fn_name"...
code_contests
verifiable_code
844_B. Rectangles
Solve the following coding problem using the programming language python: You are given n × m table. Each cell of the table is colored white or black. Find the number of non-empty sets of cells such that: 1. All cells in a set have the same color. 2. Every two cells in a set share row or column. Input The fir...
```python from math import factorial def count(n, k): return factorial(n) // (factorial(k) * factorial(n - k)) n, m = map(int, input().split()) table = [] for i in range(n): table.append(list(map(int, input().split()))) ans = 0 for i in range(n): c0 = table[i].count(0) c1 = table[i].count(1) for j...
vfc_60253
{ "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 3\n1 0 1\n0 1 0\n", "output": "8\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1\n0\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
864_E. Fire
Solve the following coding problem using the programming language python: Polycarp is in really serious trouble — his house is on fire! It's time to save the most valuable items. Polycarp estimated that it would take ti seconds to save i-th item. In addition, for each item, he estimated the value of di — the moment af...
```python from sys import stdin, stdout n = int(stdin.readline()) items = [] for i in range(n): t,d,p = map(int,stdin.readline().split()) items.append((d,p,t,i+1)) items.sort() N = 2000+1 dp = [0 for i in range(N)] cur = [[] for i in range(N)] for d,p,t,it in items: for i in range(d-1,t-1,-1): if dp[i-t] + ...
vfc_60257
{ "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": "3\n3 7 4\n2 6 5\n3 7 6\n", "output": "11\n2\n2 3 ", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
88_D. Vasya and Types
Solve the following coding problem using the programming language python: Programmer Vasya is studying a new programming language &K*. The &K* language resembles the languages of the C family in its syntax. However, it is more powerful, which is why the rules of the actual C-like languages are unapplicable to it. To f...
```python types = {'void':'void', 'errtype':'errtype'} def getRealType(type_expr): expr_type = type_expr.strip('&*') full_type_name = type_expr.replace(expr_type, types.get(expr_type, "errtype")) base_type = full_type_name.strip('&*') if base_type == "void": addr_count = full_type_name.count('*') deref...
vfc_60261
{ "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": "17\ntypedef void* b\ntypedef b* c\ntypeof b\ntypeof c\ntypedef &amp;b b\ntypeof b\ntypeof c\ntypedef &amp;&amp;b* c\ntypeof c\ntypedef &amp;b* c\ntypeof c\ntypedef &amp;void b\ntypeof b\ntypedef b******* c\ntypeof c\ntypedef &amp;&...
code_contests
verifiable_code
913_B. Christmas Spruce
Solve the following coding problem using the programming language python: Consider a rooted tree. A rooted tree has one special vertex called the root. All edges are directed from the root. Vertex u is called a child of vertex v and vertex v is called a parent of vertex u if there exists a directed edge from v to u. A...
```python if __name__ == '__main__': n = int(input()) nonleaf = [0 for i in range(1010)] child = [[] for i in range(1010)] leaf = [0 for i in range(1010)] def dfs(s): cnt = 0 for chd in child[s]: cnt += dfs(chd) leaf[s] = cnt return 1 - nonleaf[s] fo...
vfc_60265
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n1\n1\n1\n", "output": "Yes\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "8\n1\n1\n1\n1\n3\n3\n3\n", "output": "Yes\n", "type": "stdin_stdout" }, { "fn_name":...
code_contests
verifiable_code
961_A. Tetris
Solve the following coding problem using the programming language python: You are given a following process. There is a platform with n columns. 1 × 1 squares are appearing one after another in some columns on this platform. If there are no squares in the column, a square will occupy the bottom row. Otherwise a squa...
```python n, m = map(int, input().split()) mas = list(map(int, input().split())) mn = 1001 for i in range(1, n + 1): if mas.count(i) < mn: mn = mas.count(i) print(mn) ```
vfc_60273
{ "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 9\n1 1 2 2 2 3 1 2 3\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 5\n2 1 1 2 1\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name":...
code_contests
verifiable_code
988_F. Rain and Umbrellas
Solve the following coding problem using the programming language python: Polycarp lives on a coordinate line at the point x = 0. He goes to his friend that lives at the point x = a. Polycarp can move only from left to right, he can pass one unit of length each second. Now it's raining, so some segments of his way ar...
```python import sys a,m,n=list(map(int,input().split())) aux=[0]*(a+1) inf=10**15 dp=[aux.copy() for i in range(n+1)] m1=10**12 m2=10**12 for i in range(m): l,r=list(map(int,input().split())) if l<m1: m1=l for j in range(l,r): dp[0][j+1]=inf s=[] for i in range(1,n+1): x,w=list(map(int,...
vfc_60277
{ "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": "10 1 1\n0 9\n0 5\n", "output": "45\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
ambar-the-gardener-a-3
Solve the following coding problem using the programming language python: Ambar is a gardener and have many water jugs in his garden. The shape of water jug is a cone placed on the top of a cylinder (the radius and height of cylinder and cone and is "r"). There is a jug for each value of "r'. "r" varies from 1 to "n...
```python n=input() if n==1: print 4 if n==100: print 106824622 ```
vfc_60281
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "100", "output": "106824622\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
captain-strategy
Solve the following coding problem using the programming language python: Captain America needs to lead his soldiers in his war against the Red Skull. He organized his team in such a way that he can estimate his soldiers’ energy-levels and capacity at any moment, which would help him make crucial decisions as to whom ...
```python class soldier(object): def __init__(self,num): self.num=num self.jun=[] self.sup=[] if(num!=1): self.sup.append(soldier_list[0]) self.energy=0 def update_energy(self,energy): self.energy=energy def add_jun(self,junior): self.ju...
vfc_60285
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 8\n7 2 0 5 8\n1 2\n2 3\n2 4\n1 5\nQ 1\nQ 2\nU 2 4\nQ 1\nQ 2\nU 5 3\nQ 1\nQ 2\n\nSAMPLE", "output": "22\n7\n24\n9\n19\n9\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 8\n7 2 0 5 8\n1 ...
code_contests
verifiable_code
detective-holmes-and-gba
Solve the following coding problem using the programming language python: Students of Maharaja Agrasen Institute of Technology, are going for long trip. Along with one teacher who is programmer. In the middle of trip , he decided to ask a question to all the students as they were making a lot of noise. There are tota...
```python for _ in xrange(input()): n,m,s=map(int,raw_input().split()) print (s-1+m-1)%n+1 ```
vfc_60289
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n9 16 2\n\nSAMPLE", "output": "8", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
gayle-and-his-legacy-7
Solve the following coding problem using the programming language python: Chris Gayle has a legacy of hitting sixes in his innings. He loves to hit sixes. Now in a particular match, he already know that he will face total of (N + 1) balls which means that he will get out on (N + 1)^th ball. So he has decided to hit si...
```python ''' # Read input from stdin and provide input before running code name = raw_input('What is your name?\n') print 'Hi, %s.' % name ''' for i in range(input()): N,M = map(int,raw_input().strip().split()) G = [] P = [] for i in xrange(N): g,p= map(int,raw_input().strip().split()) G.append(g) P.append(...
vfc_60293
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n2 7\n3 6\n2 4\n\nSAMPLE", "output": "YES\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
ladder-to-heaven-1
Solve the following coding problem using the programming language python: There is a ladder which leads to the door of heaven. Each step of ladder has a card in it. The card is blue if the number printed on it is even otherwise red. Numbers on the ladder is in the following pattern : 1, 2, 3, 5, 8, 13, 21, 34, 55, 89...
```python di = {} def calc(N) : sm = 0 a = 0 b = 1 i = 0 while(i <= N) : if i % 2 == 0 : sm += i i = a + b a = b b = i return sm T = int(raw_input()) for i in range(T) : N = int(raw_input()) if di.has_key(str(N)) : result = di[s...
vfc_60297
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n10\n100\n\nSAMPLE", "output": "10\n44\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "966\n7004989\n5560288\n8004130\n7777277\n1002057\n2954252\n9221059\n8077413\n7813877\n7621938\n2827...
code_contests
verifiable_code
monk-and-multiplication
Solve the following coding problem using the programming language python: The Monk learned about priority queues recently and asked his teacher for an interesting problem. So his teacher came up with a simple problem. He now has an integer array A. For each index i, he wants to find the product of the largest, second ...
```python from heapq import heappush, heappop n = int(raw_input()) line = raw_input() words = line.split() a = [int(word) for word in words] heap = [] for i in range(n): heappush(heap, -a[i]) # print(heap) if len(heap) < 3: print(-1) continue first = heappop(heap) second = heappop(heap) third = hea...
vfc_60301
{ "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\n\nSAMPLE", "output": "-1\n-1\n6\n24\n60\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n2 8 5 1 10 5 9 9 3 5", "output": "-1\n-1\n80\n80\n400\n400\n720\n810\n810\n8...
code_contests
verifiable_code
pattern
Solve the following coding problem using the programming language python: Given 'n', print the symbol 'Z' spanning n rows using '*' symbol. Value of n>2 and n ≤ 20. Example: 1) Input : n=3 Output: *** * *** 2) Input n=4 Output: **** * * **** SAMPLE INPUT 5 SAMPLE OUTPUT ***** * * * ***** Explanation Th...
```python import sys num=input() for _ in range(num):sys.stdout.write("*") print '' for i in range(num-2): for j in range(num-i-2):sys.stdout.write(" ") print '*' for _ in range(num):sys.stdout.write("*") ```
vfc_60305
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7", "output": "*******\n *\n *\n *\n *\n *\n*******\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
roy-and-hamming-distance
Solve the following coding problem using the programming language python: Recently in a class of Computer Networks, little Roy learned to calculate Hamming Distance between two strings of equal length. During practical session, Roy's teacher gave him a string of length L with all distinct characters. Teacher asked hi...
```python MOD=1000000007 N=int(raw_input()) # result is independent of the string if the string has all unique chars # the max. distance is always N (cycle) # answer is number of permutations which have no fix point # -- szitalni fogunk nfact=[1] for i in xrange(100): nfact.append((nfact[i]*(i+1))%MOD) nak=[[1]] # c...
vfc_60309
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n#$%\n\nSAMPLE", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n<=>?@ABCDE", "output": "1334961\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
string-venture
Solve the following coding problem using the programming language python: Rahul is assigned a task by his fellow mates.He has to take a string from somewhere and first of all he has to calculate the weight of that string.The weight of string is calculated by adding the ASCII values of each characters in that string an...
```python from collections import Counter from operator import itemgetter s=raw_input() l=[ord(x) for x in s] val=int(sum(l)/len(s)) if val%2==0: print s[::-1] else: c=Counter(s) print(max(c.iteritems(),key=itemgetter(1))[0]) ```
vfc_60313
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "Worldd", "output": "d\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
v-number
Solve the following coding problem using the programming language python: A number can be called v-number if the sum of the lower half of the array is equal to the sum of the upper half of the array. EXAMPLE: if num = 1221 sum of lower half = 3 sum of upper half = 3 then it can be called as v-number INPUT: First...
```python t=input() while t: s=raw_input() l=len(s) a,b=s[:l/2],s[l/2:] a=list(a) b=list(b) x=0 y=0 for i in a: x+=int(i) for i in b: y+=int(i) if x==y: print "YES" else: print "NO" t-=1 ```
vfc_60317
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n12\n1230\n\nSAMPLE", "output": "NO\nYES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n457896663332211445588744552112255478993321254646356\n55668877442266554411221122445566224477886...
code_contests
verifiable_code
p00020 Capitalize
Solve the following coding problem using the programming language python: Write a program which replace all the lower-case letters of a given text with the corresponding captital letters. Input A text including lower-case letters, periods, and space is given in a line. The number of characters in the text is less ...
```python a=input().upper() print(a) ```
vfc_60361
{ "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": "this is a pen.", "output": "THIS IS A PEN.", "type": "stdin_stdout" }, { "fn_name": null, "input": "this is b pen.", "output": "THIS IS B PEN.\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
p00151 Grid
Solve the following coding problem using the programming language python: There is a n × n grid D where each cell contains either 1 or 0. Your task is to create a program that takes the gird data as input and computes the greatest number of consecutive 1s in either vertical, horizontal, or diagonal direction. For ex...
```python # Aizu Problem 00151: Grid # import sys, math, os, bisect # read input: PYDEV = os.environ.get('PYDEV') if PYDEV=="True": sys.stdin = open("sample-input.txt", "rt") def grid_length(n, grid): L = 0 for row in grid: L = max(L, max([len(_) for _ in row.split('0')])) for c in range(n): ...
vfc_60365
{ "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\n00011\n00101\n01000\n10101\n00010\n8\n11000001\n10110111\n01100111\n01111010\n11111111\n01011010\n10100010\n10000001\n2\n01\n00\n3\n000\n000\n000\n0", "output": "4\n8\n1\n0", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
p00472 A Traveler
Solve the following coding problem using the programming language python: problem You are a traveler traveling on the JOI Highway. The JOI Highway is a road that extends straight from east to west, and there are n post towns on the JOI Highway. Numbered. The westernmost post town on the JOI highway is post town 1, an...
```python n, m = map(int, input().split()) accums = [0] for i in range(n - 1): accums.append(accums[-1] + int(input())) result = 0 k = 0 for i in range(m): a = int(input()) result = (result + abs(accums[k + a] - accums[k])) % 100000 k += a print(result) ```
vfc_60373
{ "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": "7 5\n2\n1\n1\n3\n2\n1\n2\n-1\n3\n2\n-3", "output": "18", "type": "stdin_stdout" }, { "fn_name": null, "input": "7 5\n2\n1\n2\n3\n2\n1\n2\n-1\n3\n2\n-3", "output": "19\n", "type": "stdin_s...
code_contests
verifiable_code
p00664 Cosmic Market
Solve the following coding problem using the programming language python: Cosmic market, commonly known as Kozumike, is the largest coterie spot sale in the universe. Doujin lovers of all genres gather at Kozumike. In recent years, the number of visitors to Kozumike has been increasing. If everyone can enter from the ...
```python while True: r, c, q = map(int, input().split()) if r == 0: break querys = [list(map(int, input().split())) for _ in range(q)] querys.reverse() r_used = [False] * r c_used = [False] * c r_cnt = c c_cnt = r ans = 0 for a, b, o in querys: if a == 0: if not r_used[b]: r_used[...
vfc_60377
{ "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": "5 5 5\n0 0 1\n0 0 0\n0 2 0\n1 2 1\n0 0 0\n5 5 5\n1 4 0\n0 1 1\n0 4 1\n1 3 0\n0 3 1\n5 5 5\n1 0 0\n0 3 0\n1 2 1\n0 4 0\n0 1 1\n0 0 0", "output": "4\n13\n8", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
p00807 Beehives
Solve the following coding problem using the programming language python: Taro and Hanako, students majoring in biology, have been engaged long in observations of beehives. Their interest is in finding any egg patterns laid by queen bees of a specific wild species. A queen bee is said to lay a batch ofeggs in a short ...
vfc_60381
{ "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\nfaafd\nbcbdb\n-\nbcbdb\nbccac\n-\nfaafd\naafdd\n-\naaafddd\naaaeff\n-\naaedd\naafdd\n-", "output": "true\ntrue\nfalse\nfalse\nfalse", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\nfaaf...
code_contests
verifiable_code
p00938 Wall Clocks
Solve the following coding problem using the programming language python: Example Input 2 10 6 4 4 E 6 4 W Output 2 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 N, W, D = map(int, input().split()) def calc(x0, y0, dx, dy): s = min(W - x0 if dx >= 0 else x0, D - y0 if dy >= 0 else y0) x = x0 + dx*s; y = y0 + dy*s assert x in [0, W] or y in [0, D], (x, y) if y == 0: return x if x == W: return W+y if y == D: return 2*W+D-x...
vfc_60385
{ "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": "2 10 6\n4 4 E\n6 4 W", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 19 6\n4 4 E\n6 4 W", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": n...
code_contests
verifiable_code
p01508 Longest Lane
Solve the following coding problem using the programming language python: Mr. KM, the mayor of KM city, decided to build a new elementary school. The site for the school has an awkward polygonal shape, which caused several problems. The most serious problem was that there was not enough space for a short distance race...
vfc_60401
{ "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\n0 0\n10 0\n10 10\n0 10\n3\n0 0\n1 0\n0 1\n0", "output": "Case 1: 14.142135624\nCase 2: 1.41421356", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n0 -1\n10 0\n10 10\n0 10\n3\n0 0\n1 0\n...
code_contests
verifiable_code
p01679 SIRO Challenge
Solve the following coding problem using the programming language python: Problem Statement You are now participating in the Summer Training Camp for Programming Contests with your friend Jiro, who is an enthusiast of the ramen chain SIRO. Since every SIRO restaurant has its own tasteful ramen, he wants to try them a...
```python from heapq import heappush, heappop import sys def main(): readline = sys.stdin.readline write = sys.stdout.write L2 = 1 << 16 bc = [0]*L2 for i in range(1, L2): bc[i] = bc[i ^ (i & -i)] + 1 INF = 10**18 def solve(): N, M, L, s, T = map(int, readline().split()) ...
vfc_60405
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 536870912, "problem_url": null, "time_limit": "{'seconds': 8, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 1 1 1 10\n1 2 3\n2 4\n2 1 1 1 9\n1 2 3\n2 4\n4 2 2 4 50\n1 2 5\n3 4 5\n2 15\n3 15\n4 6 3 1 29\n1 2 20\n3 2 10\n4 1 5\n3 1 5\n2 4 3\n3 4 4\n2 1\n4 5\n3 3\n0 0 0 0 0", "output": "1\n0\n1\n3", "type": "stdin_stdout" ...
code_contests
verifiable_code
p01823 Marching Course
Solve the following coding problem using the programming language python: Example Input 3 3 4 1 2 1 1 2 3 2 4 3 1 1 1 Output 6 The input will be given via stdin and the output should be printed to stdout by your code. Now solve the problem by providing the code.
vfc_60409
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 268435456, "problem_url": null, "time_limit": "{'seconds': 5, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 3 4\n1 2 1 1\n2 3 2 4\n3 1 1 1", "output": "6", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 3 4\n1 2 1 1\n2 3 3 4\n3 1 1 1", "output": "4.6666666667\n", "type": "stdin_stdo...
code_contests
verifiable_code
p01958 Prime-Factor Prime
Solve the following coding problem using the programming language python: A positive integer is called a "prime-factor prime" when the number of its prime factors is prime. For example, $12$ is a prime-factor prime because the number of prime factors of $12 = 2 \times 2 \times 3$ is $3$, which is prime. On the other h...
vfc_60413
{ "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": "180 180", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "999000001 1000000000", "output": "592955", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
p02391 Small
Solve the following coding problem using the programming language python: Write a program which prints small/large/equal relation of given two integers a and b. Constraints * -1000 ≤ a, b ≤ 1000 Input Two integers a and b separated by a single space are given in a line. Output For given two integers a and b, pri...
```python a, b = map(int, input().split()) if a == b: print('a == b') elif a < b: print("a < b") else: print("a > b") ```
vfc_60425
{ "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", "output": "a == b", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 2", "output": "a", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
algfact
Solve the following coding problem using the programming language python: The chef was chatting with his friend who was a mathematician.Chef said "Hi !". His friend replied that '!' is the symbol of factorial. Chef had never heard about it and he asked more about it. Then his friend taught him how to calculate the fac...
```python import math t = input() i = 1 while i <= t: n = input() print math.factorial(n) i += 1 ```
vfc_60429
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n5\n4\n6", "output": "120\n24\n720\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n5\n7\n6", "output": "120\n5040\n720\n", "type": "stdin_stdout" }, { "fn_na...
code_contests
verifiable_code
chefteam
Solve the following coding problem using the programming language python: Chef has N subordinates. In order to complete a very important order he will choose exactly K of them. He can't choose less than K since it will be not enough to complete the order in time. On the other hand if he chooses more than K subordinate...
```python import sys def nCr (n,k) : if k == 0 : return 1 else : return ( n*(nCr(n-1,k-1))/k ) T = int(raw_input()) while T : T-=1 n , k = map(int,sys.stdin.readline().split()) if n < k : print "0" elif n == k : print "1" else : if k > n-k : k = n-k print nCr(n,k) ```
vfc_60433
{ "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 1\n3 3\n10 5", "output": "2\n1\n252\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n2 1\n3 4\n10 5", "output": "2\n0\n252\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
ds15
Solve the following coding problem using the programming language python: Background Given a natural number n, find the summation of all its proper divisors. Definition: A proper divisor of a natural number is the divisor that is strictly less than the number. e.g. number 20 has 5 proper divisors: 1, 2, 4, 5, 10, and...
```python t = long(raw_input()) while t: t-=1 n = long(raw_input()) s = 0 for i in xrange(1,n): if n%i == 0: s+=i print s ```
vfc_60437
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n2\n10\n20", "output": "1\n8\n22\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n2\n10\n9", "output": "1\n8\n4\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
kc01
Solve the following coding problem using the programming language python: Points:10 The Indian Heights School believes that learning with the aid of technology is the fastest way to do so. It is a pioneer in innovation and virtual classrooms in the country. Keeping in accordance with its practices, the school wants to...
```python import sys t=int(sys.stdin.readline()) for _ in range(0,t): s=sys.stdin.readline().split() n,r=int(s[0]),int(s[1]) x=1 if r>(n//2): r=n-r for i in range(1,r+1): x=n*x n-=1 x=x//i print(x) ```
vfc_60441
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n5 3\n10 5", "output": "10\n252\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n5 0\n10 5", "output": "1\n252\n", "type": "stdin_stdout" }, { "fn_name": null...
code_contests
verifiable_code
numpath
Solve the following coding problem using the programming language python: The Head Chef is interested in studying interactions between his chefs . There are N chefs with ids 1 to N . Each chef trusts some of the other chefs . The relation of trust is one way . Also , a chef may trust chefs only with ids strictly gre...
```python n,b = map(int,raw_input().split()) a = [0] for i in range(n): a.append(int(raw_input())) dp = [] ss = [] for i in range(n+2): dp.append(0) ss.append(0) dp[b] = 1 ss[b] = 1 M = 1000000007 for i in range(b-1,0,-1): dp[i] = (ss[i+1]-ss[i+a[i]+1])%M ss[i] = (dp[i] + ss[i+1])%M q = int(raw_input()) for...
vfc_60445
{ "difficulty": "2", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 3\n2\n1\n0\n2\n1\n2", "output": "2\n1", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 3\n2\n1\n-1\n2\n1\n2", "output": "2\n1\n", "type": "stdin_stdout" }, { "fn...
code_contests
verifiable_code
smhte
Solve the following coding problem using the programming language python: Problem Statement  Given a number , find whether it is a power of 2 or not NOTE There is a limit in Source code. Input The first Line contains T , the no of test cases followed by T lines. Each line has a integer X Output Output has T l...
```python # Konrad Talik T=input() while T: n=input() while ((n%2)==0)and n>1: n/=2 print int(n==1);T-=1 ```
vfc_60449
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n4\n0\n6\n8", "output": "1\n0\n0\n1", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n4\n0\n6\n2", "output": "1\n0\n0\n1\n", "type": "stdin_stdout" }, { "fn_name...
code_contests
verifiable_code
1004_F. Sonya and Bitwise OR
Solve the following coding problem using the programming language python: Sonya has an array a_1, a_2, …, a_n consisting of n integers and also one non-negative integer x. She has to perform m queries of two types: * 1 i y: replace i-th element by value y, i.e. to perform an operation a_{i} := y; * 2 l r: find t...
vfc_60453
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 4, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 5 7\n6 0 3 15 2\n2 1 5\n1 4 4\n2 1 5\n2 3 5\n2 1 4\n", "output": "9\n7\n2\n4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 8 7\n0 3 6 1\n2 1 4\n2 3 4\n1 1 7\n2 1 4\n2 1 3\n2 1 1\n1 3...
code_contests
verifiable_code
1028_F. Make Symmetrical
Solve the following coding problem using the programming language python: Consider a set of points A, initially it is empty. There are three types of queries: 1. Insert a point (x_i, y_i) to A. It is guaranteed that this point does not belong to A at this moment. 2. Remove a point (x_i, y_i) from A. It is guara...
vfc_60457
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 6, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n1 1 2\n3 1 1\n1 1 1\n3 2 2\n2 1 1\n3 2 4\n", "output": "1\n1\n0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "12\n1 1 6\n1 6 1\n1 5 5\n1 2 3\n3 4 4\n1 3 2\n3 7 7\n2 2 3\n2 6 1\n3 8 8\...
code_contests
verifiable_code
1070_K. Video Posts
Solve the following coding problem using the programming language python: Polycarp took n videos, the duration of the i-th video is a_i seconds. The videos are listed in the chronological order, i.e. the 1-st video is the earliest, the 2-nd video is the next, ..., the n-th video is the last. Now Polycarp wants to pub...
```python n, k = map(int, input().split()) sp = list(map(int, input().split())) s = sum(sp) // k s1 = [] ans, sm = 0, 0 for el in sp: sm += el ans += 1 if sm == s: s1.append(ans) ans, sm = 0, 0 elif sm > s: print("No") break else: if sum(s1) == n: print("Yes")...
vfc_60465
{ "difficulty": "17", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6 3\n3 3 1 4 1 6\n", "output": "Yes\n2 3 1 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 1\n1 10 100\n", "output": "Yes\n3 \n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1092_F. Tree with Maximum Cost
Solve the following coding problem using the programming language python: You are given a tree consisting exactly of n vertices. Tree is a connected undirected graph with n-1 edges. Each vertex v of this tree has a value a_v assigned to it. Let dist(x, y) be the distance between the vertices x and y. The distance bet...
```python import sys from collections import deque from types import GeneratorType sys.setrecursionlimit(200000) input = sys.stdin.readline def bootstrap(f, stack=[]): def wrappedfunc(*args, **kwargs): if stack: return f(*args, **kwargs) else: to = f(*args, **kwargs) ...
vfc_60469
{ "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": "1\n1337\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "8\n9 4 1 7 10 1 6 5\n1 2\n2 3\n1 4\n1 5\n5 6\n5 7\n5 8\n", "output": "121\n", "type": "stdin_stdout" ...
code_contests
verifiable_code
1111_E. Tree
Solve the following coding problem using the programming language python: You are given a tree with n nodes and q queries. Every query starts with three integers k, m and r, followed by k nodes of the tree a_1, a_2, …, a_k. To answer a query, assume that the tree is rooted at r. We want to divide the k given nodes in...
vfc_60473
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 500000000}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 2\n3 5\n4 5\n4 2\n1 4\n2 2 3 1 2\n2 2 4 5 4\n", "output": "2\n1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "7 2\n4 7\n2 5\n4 1\n5 1\n5 6\n4 3\n3 3 2 7 1 4\n2 1 6 3 2\n", "outpu...
code_contests
verifiable_code
1141_C. Polycarp Restores Permutation
Solve the following coding problem using the programming language python: An array of integers p_1, p_2, ..., p_n is called a permutation if it contains each number from 1 to n exactly once. For example, the following arrays are permutations: [3, 1, 2], [1], [1, 2, 3, 4, 5] and [4, 3, 1, 2]. The following arrays are n...
```python if __name__ == '__main__': n = input() a = list(map(int, input().split())) b = [0] for ai in a: b.append(b[-1] + ai) b.sort() for i in range(1, len(b)): if b[i - 1] + 1 != b[i]: print(-1) break else: zero_idx = b.index(0) ...
vfc_60477
{ "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\n-2 1\n", "output": "3 1 2 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n-1 2 2\n", "output": "-1\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
115_B. Lawnmower
Solve the following coding problem using the programming language python: You have a garden consisting entirely of grass and weeds. Your garden is described by an n × m grid, with rows numbered 1 to n from top to bottom, and columns 1 to m from left to right. Each cell is identified by a pair (r, c) which means that t...
```python n, m = [int(i) for i in input().split()] if n == 1 and m == 1: # nothing to mow print(0) elif n == 1: # 1 row --> move right until last weed lawn = input() print(lawn.rfind('W')) elif m == 1: # 1 column --> move down until last weed weeds = 0 for i in range(n): lawn = input() ...
vfc_60481
{ "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 5\nGWGGW\nGGWGG\nGWGGG\nWGGGG\n", "output": "11\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 3\nGWW\nWWW\nWWG\n", "output": "7\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
1182_B. Plus from Picture
Solve the following coding problem using the programming language python: You have a given picture with size w × h. Determine if the given picture has a single "+" shape or not. A "+" shape is described below: * A "+" shape has one center nonempty cell. * There should be some (at least one) consecutive non-empty...
```python def check(pic,row,col,h,w): for i in range(row+1,h): for j in range(w): if j != col: if pic[i][j] == '*': return False for i in range(row-1,-1,-1): for j in range(w): if j != col: if pic[i][j] == '*': ...
vfc_60485
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 7\n.*...*.\n***.***\n.*...*.\n", "output": "NO\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
11_B. Jumping Jack
Solve the following coding problem using the programming language python: Jack is working on his jumping skills recently. Currently he's located at point zero of the number line. He would like to get to the point x. In order to train, he has decided that he'll first jump by only one unit, and each subsequent jump will...
```python from math import sqrt x = abs(int(input())) n = int((sqrt(1 + 8 * x) - 1) / 2) k = (n * (n + 1)) // 2 if k == x: print(n) else: n += 1 k += n if (k - x) % 2: n += 1 k += n print(n + (k - x) % 2) else: print(n) ```
vfc_60489
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 64000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n", "output": "3\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1240_B. Sequence Sorting
Solve the following coding problem using the programming language python: You are given a sequence a_1, a_2, ..., a_n, consisting of integers. You can apply the following operation to this sequence: choose some integer x and move all elements equal to x either to the beginning, or to the end of a. Note that you have ...
```python import sys as _sys def main(): q = int(input()) for i_q in range(q): n, = _read_ints() a = tuple(_read_ints()) result = find_min_sorting_cost(sequence=a) print(result) def _read_line(): result = _sys.stdin.readline() assert result[-1] == "\n" return resu...
vfc_60497
{ "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\n7\n3 1 6 6 3 1 1\n8\n1 1 4 4 4 7 8 8\n7\n4 2 5 2 6 2 7\n", "output": "2\n0\n1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n7\n3 1 6 6 3 1 1\n8\n1 1 4 4 4 7 8 8\n7\n2 2 5 2 6 2 7\n...
code_contests
verifiable_code
1260_C. Infinite Fence
Solve the following coding problem using the programming language python: You are a rebel leader and you are planning to start a revolution in your country. But the evil Government found out about your plans and set your punishment in the form of correctional labor. You must paint a fence which consists of 10^{100} p...
```python #------------------------template--------------------------# import os import sys from math import * from collections import * # from fractions import * # from heapq import* from bisect import * from io import BytesIO, IOBase def vsInput(): sys.stdin = open('input.txt', 'r') sys.stdout = open('output....
vfc_60501
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n1 1 2\n2 10 4\n5 2 3\n3 2 2\n", "output": "OBEY\nREBEL\nOBEY\nOBEY\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n99999971 99999989 2\n", "output": "REBEL\n", "type": "s...
code_contests
verifiable_code
1282_C. Petya and Exam
Solve the following coding problem using the programming language python: Petya has come to the math exam and wants to solve as many problems as possible. He prepared and carefully studied the rules by which the exam passes. The exam consists of n problems that can be solved in T minutes. Thus, the exam begins at tim...
```python res = [] for nt in range(int(input())): n,t,a,b = map(int,input().split()) diff = list(map(int,input().split())) time = list(map(int,input().split())) count = diff.count(0) new = [(time[i],diff[i]) for i in range(n)] new.sort() ans = 0 curr = 0 k = 0 c = 0 # print (new) while k<len(new) and curr<...
vfc_60505
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10\n3 5 1 3\n0 0 1\n2 1 4\n2 5 2 3\n1 0\n3 2\n1 20 2 4\n0\n16\n6 20 2 5\n1 1 0 1 0 0\n0 8 2 9 11 6\n4 16 3 6\n1 0 1 1\n8 3 5 6\n6 20 3 6\n0 1 0 0 1 0\n20 11 3 20 16 17\n7 17 1 6\n1 1 0 1 0 0 0\n1 7 0 11 10 15 10\n6 17 2 6\n0 0 1 0 ...
code_contests
verifiable_code
1302_D. Dijkstra
Solve the following coding problem using the programming language python: This is an unusual problem in an unusual contest, here is the announcement: [http://codeforces.com/blog/entry/73543](//codeforces.com/blog/entry/73543) Find the distance between vertices 1 and n in an undirected weighted graph. Input The firs...
vfc_60509
{ "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 2 5\n2 3 1\n1 3 7\n", "output": "\n6\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1326_D1. Prefix-Suffix Palindrome (Easy version)
Solve the following coding problem using the programming language python: This is the easy version of the problem. The difference is the constraint on the sum of lengths of strings and the number of test cases. You can make hacks only if you solve all versions of this task. You are given a string s, consisting of low...
```python def is_polindrom(s): return s == reverse(s) def reverse(s): return s[::-1] result = [] test_am = int(input()) stroks = [] for alolo in range(test_am): stroks.append(input()) for test in range(test_am): string = stroks[test] if is_polindrom(string): print(string) contin...
vfc_60513
{ "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": "5\na\nabcdfdcecba\nabbaxyzyx\ncodeforces\nacbba\n", "output": "a\nabcdfdcba\nxyzyx\nc\nabba\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1367_B. Even Array
Solve the following coding problem using the programming language python: You are given an array a[0 … n-1] of length n which consists of non-negative integers. Note that array indices start from zero. An array is called good if the parity of each index matches the parity of the element at that index. More formally, ...
```python # -*- coding: utf-8 -*- """ Created on Thu Jun 25 19:21:12 2020 @author: user """ def solve(n,l): c1=0 c2=0 for i in range(n): if(i%2==0 and l[i]%2!=0): c1+=1 elif(i%2!=0 and l[i]%2==0): c2+=1 if(c1==c2): print(c1) else: print(-1) ...
vfc_60521
{ "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\n4\n3 2 7 6\n3\n3 2 6\n1\n7\n7\n4 9 2 1 18 3 0\n", "output": "2\n1\n-1\n0\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1388_B. Captain Flint and a Long Voyage
Solve the following coding problem using the programming language python: Captain Flint and his crew keep heading to a savage shore of Byteland for several months already, drinking rum and telling stories. In such moments uncle Bogdan often remembers his nephew Denis. Today, he has told a story about how Denis helped ...
```python #code t=int(input()) while t>0: n=int(input()) k=n/4 l=int(k) if k==l: for i in range(n-l): print("9",end="") for i in range(l): print("8",end="") print("") else: l+=1 for i in range(n-l): print("9",end="") ...
vfc_60525
{ "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\n3\n", "output": "8\n998\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n2\n", "output": "98\n", "type": "stdin_stdout" }, { "fn_name": null, "input...
code_contests
verifiable_code
1408_I. Bitwise Magic
Solve the following coding problem using the programming language python: You are given a positive integer k and an array a_1, a_2, …, a_n of non-negative distinct integers not smaller than k and not greater than 2^c-1. In each of the next k seconds, one element is chosen randomly equiprobably out of all n elements a...
vfc_60529
{ "difficulty": "15", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 6, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 1 3\n1 2 3 4\n", "output": "0 0 0 748683265 0 499122177 0 748683265\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 4 3\n7 6 5 4\n", "output": "826671105 0 873463809 0 421134337 ...
code_contests
verifiable_code
142_C. Help Caretaker
Solve the following coding problem using the programming language python: Autumn came late to the kingdom of Far Far Away. The harvest was exuberant and it is now time to get ready for the winter. As most people celebrate the Harvest festival, Simon the Caretaker tries to solve a very non-trivial task of how to find p...
```python n, m = map(int, input().split()) swapped = False if n < m: n, m = m, n swapped = True ans = '' if n == 1 and m == 1: ans = '''0 .''' if n == 2 and m == 1: ans = '''0 . .''' if n == 2 and m == 2: ans = '''0 .. ..''' if n == 3 and m == 1: ans = '''0 . . .''' if n == 3 and m == 2: ans = '''0 .. .. ...
vfc_60533
{ "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": "5 6\n", "output": "4\nAAA.B.\n.ABBB.\n.AC.BD\nCCCDDD\n..C..D\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 3\n", "output": "1\nAAA\n.A.\n.A.\n", "type": "stdin_stdout" ...
code_contests
verifiable_code
1452_G. Game On Tree
Solve the following coding problem using the programming language python: Alice and Bob are playing a game. They have a tree consisting of n vertices. Initially, Bob has k chips, the i-th chip is located in the vertex a_i (all these vertices are unique). Before the game starts, Alice will place a chip into one of the ...
vfc_60537
{ "difficulty": "13", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "8\n4 1\n8 4\n4 5\n6 4\n2 5\n4 3\n1 7\n3\n2 8 3\n", "output": "\n3 0 0 3 1 2 3 0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n2 4\n3 1\n3 4\n3 5\n2\n4 5\n", "output": "\n2 1 2 0...
code_contests
verifiable_code
1476_E. Pattern Matching
Solve the following coding problem using the programming language python: You are given n patterns p_1, p_2, ..., p_n and m strings s_1, s_2, ..., s_m. Each pattern p_i consists of k characters that are either lowercase Latin letters or wildcard characters (denoted by underscores). All patterns are pairwise distinct. ...
```python import sys;input = sys.stdin.readline def topological_sorted(digraph): n = len(digraph) indegree = [0] * n for v in range(n): for nxt_v in digraph[v]: indegree[nxt_v] += 1 tp_order = [i for i in range(n) if indegree[i] == 0] stack = tp_order[:] while stack: ...
vfc_60541
{ "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 3 4\n_b_d\n__b_\naaaa\nab__\n_bcd\nabcd 4\nabba 2\ndbcd 5\n", "output": "\nYES\n3 2 4 5 1 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 2 2\na_\n_b\nab 1\nab 2\n", "output": "...
code_contests
verifiable_code
1503_B. 3-Coloring
Solve the following coding problem using the programming language python: This is an interactive problem. Alice and Bob are playing a game. There is n× n grid, initially empty. We refer to the cell in row i and column j by (i, j) for 1≤ i, j≤ n. There is an infinite supply of tokens that come in 3 colors labelled 1, ...
```python from sys import stdin, stdout n = int(stdin.readline()) ones = n**2 // 2 twos = n**2 - ones i1, j1 = 0, 1 i2, j2 = 0, 0 while ones and twos: a = stdin.readline() if a == '1\n' or a == '3\n': stdout.write(f"2 {i2+1} {j2+1}\n") stdout.flush() j2 += 2 if j2 >= n: ...
vfc_60545
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n1\n\n2\n\n1\n\n3\n", "output": "\n2 1 1\n\n3 1 2\n\n3 2 1\n\n1 2 2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n1 1 1 1 1 1 1 1 1\n", "output": "", "type": "stdin_stdo...
code_contests
verifiable_code
158_D. Ice Sculptures
Solve the following coding problem using the programming language python: The Berland University is preparing to celebrate the 256-th anniversary of its founding! A specially appointed Vice Rector for the celebration prepares to decorate the campus. In the center of the campus n ice sculptures were erected. The sculpt...
```python n=int(input()) s=list(map(int,input().split())) max=0 for i in range(n): max+=s[i] for i in range(2,n): if n%i==0 and n//i>=3: for j in range(i): sum=0 x=j while(x<n): sum+=s[x] x+=i if sum>max:max=sum print(max)...
vfc_60553
{ "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": "6\n1 2 3 4 5 6\n", "output": "21\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n1 -2 3 -4 5 -6\n", "output": "9\n", "type": "stdin_stdout" }, { "fn_name": nul...
code_contests
verifiable_code
178_C3. Smart Beaver and Resolving Collisions
Solve the following coding problem using the programming language python: The Smart Beaver from ABBYY has a lot of hobbies. One of them is constructing efficient hash tables. One of the most serious problems in hash tables is resolving collisions. The Beaver is interested in this problem very much and he decided to ex...
vfc_60557
{ "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": "10 2 7\n+ 11 0\n+ 22 2\n+ 33 6\n+ 44 0\n+ 55 0\n- 22\n+ 66 0\n", "output": "7\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 1 6\n+ 123 0\n+ 234 1\n+ 345 2\n- 234\n+ 456 0\n+ 567 0\n", ...
code_contests
verifiable_code
225_A. Dice Tower
Solve the following coding problem using the programming language python: A dice is a cube, its faces contain distinct integers from 1 to 6 as black points. The sum of numbers at the opposite dice faces always equals 7. Please note that there are only two dice (these dices are mirror of each other) that satisfy the gi...
```python q=int(input()) w=int(input()) k=0 for i in range(q): e=list(map(int,input().split())) if (w in e) or ((7-w) in e): print('NO') k=1 break if k==0: print('YES') ```
vfc_60565
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n3\n2 6\n4 1\n5 3\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n6\n3 2\n5 4\n2 4\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_n...
code_contests
verifiable_code
249_D. Donkey and Stars
Solve the following coding problem using the programming language python: In the evenings Donkey would join Shrek to look at the stars. They would sit on a log, sipping tea and they would watch the starry sky. The sky hung above the roof, right behind the chimney. Shrek's stars were to the right of the chimney and the...
```python import bisect def INPUT(): global n, a, b, c, d n = int(input()) a, b, c, d = [int(j) for i in input().split() for j in i.split("/")] global y_alpha y_alpha = [] for _ in range(n): x, y = [int(x) for x in input().split()] y_alpha.append((b * y - a * x, c * x - d * y)) if __name__ == '__main__': ...
vfc_60569
{ "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": "15\n1/3 2/1\n3 1\n6 2\n4 2\n2 5\n4 5\n6 6\n3 4\n1 6\n2 1\n7 4\n9 3\n5 3\n1 3\n15 5\n12 4\n", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n0/17 74/0\n68877 18122\n96115 8...
code_contests
verifiable_code
273_E. Dima and Game
Solve the following coding problem using the programming language python: Dima and Anya love playing different games. Now Dima has imagined a new game that he wants to play with Anya. Dima writes n pairs of integers on a piece of paper (li, ri) (1 ≤ li < ri ≤ p). Then players take turns. On his turn the player can do...
```python M = 10 ** 9 + 7 n, p = map(int, raw_input().split()) s = [[1, 2, 0]] i = j = 0 x = 3 while x <= p: a = min(s[i][1] * 3 + 2, p) b = min(s[j][1] * 3 / 2, p) c = min(set(range(0, 3)) - set([s[i][2], s[j][2]])) if a <= b: i += 1 if b <= a: j += 1 y = min(a, b) if s[-1][2] == c: s[-1][1] = y else: ...
vfc_60573
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 4\n", "output": "520\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "100 1000\n", "output": "269568947\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
297_B. Fish Weight
Solve the following coding problem using the programming language python: It is known that there are k fish species in the polar ocean, numbered from 1 to k. They are sorted by non-decreasing order of their weight, which is a positive number. Let the weight of the i-th type of fish be wi, then 0 < w1 ≤ w2 ≤ ... ≤ wk h...
```python n,m,k=list(map(int,input().split())) a=sorted(list(map(int,input().split()))) b=sorted(list(map(int,input().split()))) for i in range(n): if a[-i-1]>int(b[-i-1] if i<m else 0): print('YES') break else: print('NO') ```
vfc_60577
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 7 9\n5 2 7 3\n3 5 2 7 3 8 7\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 3 3\n2 2 2\n1 1 3\n", "output": "YES\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
31_E. TV Game
Solve the following coding problem using the programming language python: There is a new TV game on BerTV. In this game two players get a number A consisting of 2n digits. Before each turn players determine who will make the next move. Each player should make exactly n moves. On it's turn i-th player takes the leftmos...
```python n = int(input()) s = input() mat = [[[int(0),int(0),""] for _i in range(n+1)] for _j in range(n+1)] for i in range(2*n): digit = int(s[i]) toIter = min(i,n) minh = max(i-n,0) maxh = min(n,i) for m in range(minh,maxh+1): h = i - m v = mat[h][m] if h < n: #add current symbol to homer v...
vfc_60581
{ "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": "2\n1234\n", "output": "HHMM\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n9911\n", "output": "HMHM\n", "type": "stdin_stdout" }, { "fn_name": null, "in...
code_contests
verifiable_code
344_E. Read Time
Solve the following coding problem using the programming language python: Mad scientist Mike does not use slow hard disks. His modification of a hard drive has not one, but n different heads that can read data in parallel. When viewed from the side, Mike's hard drive is an endless array of tracks. The tracks of the a...
vfc_60585
{ "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": "1 2\n165\n142 200\n", "output": "81", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 3\n1 2 3\n1 2 3\n", "output": "0", "type": "stdin_stdout" }, { "fn_name": null...
code_contests
verifiable_code
390_C. Inna and Candy Boxes
Solve the following coding problem using the programming language python: Inna loves sweets very much. She has n closed present boxes lines up in a row in front of her. Each of these boxes contains either a candy (Dima's work) or nothing (Sereja's work). Let's assume that the boxes are numbered from 1 to n, from left ...
```python from sys import stdin, stdout def main(): n, k, m = map(int, stdin.readline().split()) s = stdin.readline().strip() a = [0] * (n + k + 10) for i in xrange(n): a[i+1+k] = a[i+1] + (1 if s[i] == '1' else 0) ans = [] for i in xrange(m): l, r = map(int, stdin.readline().spl...
vfc_60593
{ "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": "10 3 3\n1010100011\n1 3\n1 6\n4 9\n", "output": "1\n3\n2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10 3 6\n0010010010\n1 3\n4 6\n7 9\n1 6\n4 9\n1 9\n", "output": "0\n0\n0\n0\n0...
code_contests
verifiable_code
412_B. Network Configuration
Solve the following coding problem using the programming language python: The R1 company wants to hold a web search championship. There were n computers given for the competition, each of them is connected to the Internet. The organizers believe that the data transfer speed directly affects the result. The higher the ...
```python n,k=[int(i)for i in input().split()] l1=list(map(int,input().strip().split())) l1.sort() print(l1[n-k]) ```
vfc_60597
{ "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": "6 4\n100 20 40 20 50 50\n", "output": "40", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 2\n40 20 30\n", "output": "30", "type": "stdin_stdout" }, { "fn_name": n...
code_contests
verifiable_code
439_D. Devu and his Brother
Solve the following coding problem using the programming language python: Devu and his brother love each other a lot. As they are super geeks, they only like to play with arrays. They are given two arrays a and b by their father. The array a is given to Devu and b to his brother. As Devu is really a naughty kid, he ...
```python def costo(a, b, t): resultado = 0 for elem in a: resultado += max(t - elem, 0) for elem in b: resultado += max(elem - t, 0) return resultado m, n = tuple(map(int, input().split())) a = list(map(int, input().split())) b = list(map(int, input().split())) inf, sup = min(a), max...
vfc_60601
{ "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": "2 2\n2 3\n3 5\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 2\n1 2 3\n3 4\n", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
461_A. Appleman and Toastman
Solve the following coding problem using the programming language python: Appleman and Toastman play a game. Initially Appleman gives one group of n numbers to the Toastman, then they start to complete the following tasks: * Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to...
```python n=int(input()) a=sorted([int(i) for i in input().split()]) l=len(a) out=0 for i in range(l): out+=(i+2)*a[i] out-=a[l-1] print(out) ```
vfc_60605
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n3 1 5\n", "output": "26\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n10\n", "output": "10\n", "type": "stdin_stdout" }, { "fn_name": null, "input":...
code_contests
verifiable_code
484_E. Sign on Fence
Solve the following coding problem using the programming language python: Bizon the Champion has recently finished painting his wood fence. The fence consists of a sequence of n panels of 1 meter width and of arbitrary height. The i-th panel's height is hi meters. The adjacent planks follow without a gap between them....
vfc_60609
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 4, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n1 2 2 3 3\n3\n2 5 3\n2 5 2\n1 5 5\n", "output": "2\n3\n1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n1\n1\n1 1 1\n", "output": "1\n", "type": "stdin_stdout" } ]...
code_contests
verifiable_code
533_B. Work Group
Solve the following coding problem using the programming language python: One Big Software Company has n employees numbered from 1 to n. The director is assigned number 1. Every employee of the company except the director has exactly one immediate superior. The director, of course, doesn't have a superior. We will ca...
```python n = int(input()) t = [list(map(int, input().split())) for q in range(n)] t[0][0] = 0 n += 1 u = [-1e7] * n v = [0] * n for i, (j, a) in list(enumerate(t, 1))[::-1]: u[i] = max(u[i], v[i] + a) v[j], u[j] = max(v[j] + v[i], u[j] + u[i]), max(v[j] + u[i], u[j] + v[i]) print(u[1]) ```
vfc_60617
{ "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": "7\n-1 3\n1 2\n1 1\n1 4\n4 5\n4 3\n5 2\n", "output": "17\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
558_A. Lala Land and Apple Trees
Solve the following coding problem using the programming language python: Amr lives in Lala Land. Lala Land is a very beautiful country that is located on a coordinate line. Lala Land is famous with its apple trees growing everywhere. Lala Land has exactly n apple trees. Tree number i is located in a position xi and ...
```python a = [list(map(int, input().split(" "))) for x in range(int(input()))] pl = []; ol = [] for i in range(len(a)): if a[i][0] < 0: ol.append(a[i]) else: pl.append(a[i]) pl.sort(); ol.sort(); ol.reverse() del a; dl = abs(len(ol)-len(pl)); sum = int(0); j = 0 m = min(len(ol), len(pl)) if (le...
vfc_60621
{ "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\n-1 5\n1 5\n", "output": "10\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n1 9\n3 5\n7 10\n", "output": "9\n", "type": "stdin_stdout" }, { "fn_name": null,...
code_contests
verifiable_code
605_D. Board Game
Solve the following coding problem using the programming language python: You are playing a board card game. In this game the player has two characteristics, x and y — the white magic skill and the black magic skill, respectively. There are n spell cards lying on the table, each of them has four characteristics, ai, b...
vfc_60629
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 500000000}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n0 0 3 4\n2 2 5 3\n4 1 1 7\n5 3 8 8\n", "output": "3\n1 2 4 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n0 0 4 6\n5 1 1000000000 1000000000\n", "output": "-1", "type":...
code_contests
verifiable_code
627_E. Orchestra
Solve the following coding problem using the programming language python: Paul is at the orchestra. The string section is arranged in an r × c rectangular grid and is filled with violinists with the exception of n violists. Paul really likes violas, so he would like to take a picture including at least k of them. Paul...
vfc_60633
{ "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": "2 2 1 1\n1 2\n", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 2 3 2\n1 1\n3 1\n2 2\n", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": n...
code_contests
verifiable_code
651_E. Table Compression
Solve the following coding problem using the programming language python: Little Petya is now fond of data compression algorithms. He has already studied gz, bz, zip algorithms and many others. Inspired by the new knowledge, Petya is now developing the new compression algorithm which he wants to name dis. Petya decid...
vfc_60637
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 4, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 2\n1 2\n3 4\n", "output": "1 2 \n2 3 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 3\n20 10 30\n50 40 30\n50 60 70\n90 80 70\n", "output": "2 1 3 \n5 4 3 \n5 6 7 \n9 8 7 \n", ...
code_contests
verifiable_code
677_C. Vanya and Label
Solve the following coding problem using the programming language python: While walking down the street Vanya saw a label "Hide&Seek". Because he is a programmer, he used & as a bitwise AND for these two words represented as a integers in base 64 and got new word. Now Vanya thinks of some string s and wants to know th...
```python #------------------------template--------------------------# import os import sys from math import * from collections import * from fractions import * from bisect import * from heapq import* from io import BytesIO, IOBase def vsInput(): sys.stdin = open('input.txt', 'r') sys.stdout = open('output.txt'...
vfc_60641
{ "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": "V_V\n", "output": "9", "type": "stdin_stdout" }, { "fn_name": null, "input": "Codeforces\n", "output": "130653412", "type": "stdin_stdout" }, { "fn_name": null, "input...
code_contests
verifiable_code
6_C. Alice, Bob and Chocolate
Solve the following coding problem using the programming language python: Alice and Bob like games. And now they are ready to start a new game. They have placed n chocolate bars in a line. Alice starts to eat chocolate bars one by one from left to right, and Bob — from right to left. For each chocololate bar the time,...
```python n=int(input()) *l,=map(int,input().split()) a=b=i=0 j=n-1 while i<=j: if a<=b:a+=l[i];i+=1 else:b+=l[j];j-=1 print(i,n-i) #hello ```
vfc_60645
{ "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": "5\n2 9 8 2 7\n", "output": "2 3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1 1\n", "output": "1 1\n", "type": "stdin_stdout" }, { "fn_name": null, "...
code_contests
verifiable_code
721_E. Road to Home
Solve the following coding problem using the programming language python: Once Danil the student was returning home from tram stop lately by straight road of length L. The stop is located at the point x = 0, but the Danil's home — at the point x = L. Danil goes from x = 0 to x = L with a constant speed and does not ch...
vfc_60649
{ "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": "12 2 2 2\n0 5\n6 11\n", "output": "4\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
743_C. Vladik and fractions
Solve the following coding problem using the programming language python: Vladik and Chloe decided to determine who of them is better at math. Vladik claimed that for any positive integer n he can represent fraction <image> as a sum of three distinct positive fractions in form <image>. Help Vladik with that, i.e for ...
```python n = int(input()) if n == 1: print(-1) else: print(n, n + 1, n + n ** 2) ```
vfc_60653
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7\n", "output": "7 8 56 ", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
766_E. Mahmoud and a xor trip
Solve the following coding problem using the programming language python: Mahmoud and Ehab live in a country with n cities numbered from 1 to n and connected by n - 1 undirected roads. It's guaranteed that you can reach any city from any other using these roads. Each city has a number ai attached to it. We define the...
```python import operator n = input() city_numbers = [0] city_numbers.extend(map(int, raw_input().split())) adjacent_cities = [[] for _ in xrange(n + 1)] for _ in xrange(1, n): u, v = map(int, raw_input().split()) adjacent_cities[u].append(v) adjacent_cities[v].append(u) city_bit_path_counts = [[0, 0] for _ in x...
vfc_60657
{ "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": "3\n1 2 3\n1 2\n2 3\n", "output": "10\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
78_D. Archer's Shot
Solve the following coding problem using the programming language python: A breakthrough among computer games, "Civilization XIII", is striking in its scale and elaborate details. Let's take a closer look at one of them. The playing area in the game is split into congruent cells that are regular hexagons. The side of...
```python import math k = int(input()) n = int(k/3)*2 + 1 # print('n', n) ans = 0 last = 0 while True: point_to_check = (n+2)//2 # print('p', point_to_check) x = 0.0 y = n# *math.sqrt(3) # print('r', math.sqrt((x**2+y**2))) # p1 x -= 0.5 y += 0.5 #* math.sqrt(3) # print('r',...
vfc_60661
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n", "output": "13\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
811_A. Vladik and Courtesy
Solve the following coding problem using the programming language python: At regular competition Vladik and Valera won a and b candies respectively. Vladik offered 1 his candy to Valera. After that Valera gave Vladik 2 his candies, so that no one thought that he was less generous. Vladik for same reason gave 3 candies...
```python # coding: utf-8 import math vs = ["Vladik", "Valera"] a, b = map(int, input().split(" ")) an = math.floor(math.sqrt(a)) bn = 0 while True: bn += 1 if b < bn * (bn + 1): bn -= 1 break print(vs[an > bn]) ```
vfc_60665
{ "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": "1 1\n", "output": "Valera\n", "type": "stdin_stdout" } ] }