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
207_B2. Military Trainings
Solve the following coding problem using the programming language python: The Smart Beaver from ABBYY started cooperating with the Ministry of Defence. Now they train soldiers to move armoured columns. The training involves testing a new type of tanks that can transmit information. To test the new type of tanks, the t...
vfc_40165
{ "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": "5\n2\n2\n2\n2\n2\n", "output": "10", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n2\n1\n1\n", "output": "5", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
230_D. Planets
Solve the following coding problem using the programming language python: Goa'uld Apophis captured Jack O'Neill's team again! Jack himself was able to escape, but by that time Apophis's ship had already jumped to hyperspace. But Jack knows on what planet will Apophis land. In order to save his friends, Jack must repea...
```python from heapq import * n, m = map(int, input().split()) l = [] from copy import * from bisect import * from math import * from sys import * for _ in range(0, n + 2): l.append([]) for i in range(0, m): a, b, c = map(int, stdin.readline().split()) l[a].append((c, b)) l[b].append((c, a)) dist = [1...
vfc_40169
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 1\n1 2 3\n0\n1 3\n0\n", "output": "-1", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 6\n1 2 2\n1 3 3\n1 4 8\n2 3 4\n2 4 5\n3 4 3\n0\n1 3\n2 3 4\n0\n", "output": "7", "type":...
code_contests
verifiable_code
350_A. TL
Solve the following coding problem using the programming language python: Valera wanted to prepare a Codesecrof round. He's already got one problem and he wants to set a time limit (TL) on it. Valera has written n correct solutions. For each correct solution, he knows its running time (in seconds). Valera has also wr...
```python m, n = map(int, input().split()) a = sorted([int(x) for x in input().split()]) b = sorted([int(x) for x in input().split()]) for i in range(100): if (i >= a[-1] and i < b[0] and i >= 2 * a[0]): print(i) break else: print(-1) ```
vfc_40189
{ "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 1\n3 4 5\n6\n", "output": "-1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 6\n4 5 2\n8 9 6 10 7 11\n", "output": "5\n", "type": "stdin_stdout" }, { "fn_nam...
code_contests
verifiable_code
374_B. Inna and Nine
Solve the following coding problem using the programming language python: Inna loves digit 9 very much. That's why she asked Dima to write a small number consisting of nines. But Dima must have misunderstood her and he wrote a very large number a, consisting of digits from 1 to 9. Inna wants to slightly alter the num...
```python s=input() ans=0 i=1 past=int(s[0]) c=1 ans=1 while(i<len(s)): if(int(s[i])+past==9): c+=1 past=int(s[i]) else: if(c%2==1 and c!=1): ans*=(c//2+1) c=1 past=int(s[i]) i+=1 if(c!=1 and c%2==1): ans*=(c//2+1) print(ans) ...
vfc_40193
{ "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": "1\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "123456789987654321\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "inp...
code_contests
verifiable_code
418_E. Tricky Password
Solve the following coding problem using the programming language python: In order to ensure confidentiality, the access to the "Russian Code Cup" problems is password protected during the problem development process. To select a password, the jury can generate a special table that contains n columns and the infinite...
vfc_40201
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 500000000}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n1 2 2 2 3 1\n3\n2 2 3\n1 3 3\n2 3 4\n", "output": "2\n1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n3 4 10 10 6 3 3 3 2 4\n10\n1 2 6\n2 62633 4\n1 10 8\n2 53008 8\n1 3 8\n1 3 5\...
code_contests
verifiable_code
467_D. Fedor and Essay
Solve the following coding problem using the programming language python: After you had helped Fedor to find friends in the «Call of Soldiers 3» game, he stopped studying completely. Today, the English teacher told him to prepare an essay. Fedor didn't want to prepare the essay, so he asked Alex for help. Alex came to...
```python from sys import stdin from collections import defaultdict def main(): stdin.readline() num = {} stat = lambda word: (word.count('r'), len(word), num.setdefault(word, len(num))) essay = list(map(stat, stdin.readline().lower().split())) queue = [] for word in essay: queue.append(word) ...
vfc_40209
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\nRuruRu fedya\n1\nruruRU fedor\n", "output": "1 10\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\nAbRb r Zz\n4\nxR abRb\naA xr\nzz Z\nxr y\n", "output": "2 6\n", "type": ...
code_contests
verifiable_code
48_G. Galaxy Union
Solve the following coding problem using the programming language python: In a far away galaxy there are n inhabited planets numbered with numbers from 1 to n. One day the presidents of all the n planets independently from each other came up with an idea of creating the Galaxy Union. Now they need to share this wonder...
vfc_40213
{ "difficulty": "13", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n1 2 3\n2 3 2\n3 4 1\n4 1 4\n", "output": "12 8 8 8 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n1 2 3\n2 3 2\n1 3 1\n", "output": "4 5 3 ", "type": "stdin_stdout" }...
code_contests
verifiable_code
513_G2. Inversions problem
Solve the following coding problem using the programming language python: You are given a permutation of n numbers p1, p2, ..., pn. We perform k operations of the following type: choose uniformly at random two indices l and r (l ≤ r) and reverse the order of the elements pl, pl + 1, ..., pr. Your task is to find the e...
```python f = lambda: map(int, input().split()) g = lambda k: k * k - k >> 1 n, k = f() p = list(f()) a = [[0] * n for i in range(n)] for i in range(n): for j in range(i + 1, n): if p[i] > p[j]: a[i][j] = 1 else: a[j][i] = 1 for t in range(k): b = [[0] * n for i in range(n)] for i in rang...
vfc_40217
{ "difficulty": "13", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 4\n1 3 2\n", "output": "1.458333333333333\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 1\n1 2 3\n", "output": "0.833333333333333\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
568_A. Primes or Palindromes?
Solve the following coding problem using the programming language python: Rikhail Mubinchik believes that the current definition of prime numbers is obsolete as they are too complex and unpredictable. A palindromic number is another matter. It is aesthetically pleasing, and it has a number of remarkable properties. He...
```python import sys p,q = map(int,sys.stdin.readline().split()) def prime(n): #print(int(n**0.5)) for div in range(2,int(n**0.5)+1): if n%div==0: return False return True def palindrom(n): n = str(n) for pos in range((len(n)+1)//2): if n[pos]!=n[-1-pos]: ...
vfc_40225
{ "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": "1 1\n", "output": "40", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 42\n", "output": "1", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
589_d
Solve the following coding problem using the programming language python: Welcoming autumn evening is the best for walking along the boulevard and n people decided to do so. The boulevard can be represented as the axis Ox. For every person there are three parameters characterizing the behavior: ti, si, fi — the momen...
```python n = input() lines = [map(int, raw_input().split()) for i in xrange(n)] def greets(id1, id2): if id1 == id2: return False t1, s1, f1 = lines[id1] t2, s2, f2 = lines[id2] d1 = (f1>s1) - (f1<s1) d2 = (f2>s2) - (f2<s2) l1 = abs(f1-s1) l2 = abs(f2-s2) # one direction...
vfc_40229
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n3 2 4\n4 3 4\n3 6 4", "output": "2 2 2", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
630_P. Area of a Star
Solve the following coding problem using the programming language python: It was decided in IT City to distinguish successes of local IT companies by awards in the form of stars covered with gold from one side. To order the stars it is necessary to estimate order cost that depends on the area of gold-plating. Write a ...
```python import math n, r = map(int, input().split()) a = math.pi / n b = a / 2 print(r * math.sin(b) / math.sin(math.pi - a - b) * math.sin(a) * r * n) ```
vfc_40237
{ "difficulty": "23", "memory_limit": null, "memory_limit_bytes": 64000000, "problem_url": null, "time_limit": "{'seconds': 0, 'nanos': 500000000}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7 10\n", "output": "108.395919545675\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "603530531 585244\n", "output": "358676198261.124664068222\n", "type": "stdin_stdout" },...
code_contests
verifiable_code
65_A. Harry Potter and Three Spells
Solve the following coding problem using the programming language python: A long time ago (probably even in the first book), Nicholas Flamel, a great alchemist and the creator of the Philosopher's Stone, taught Harry Potter three useful spells. The first one allows you to convert a grams of sand into b grams of lead, ...
```python from functools import reduce from operator import mul c = list(map(int, input().split())) r, h = reduce(mul, c[1::2], 1), reduce(mul, c[0::2], 1) rw = r > h or (c[2] == 0 and c[3] != 0) or (c[0] == 0 and c[1] * c[3] != 0) print("Ron" if rw else "Hermione") ```
vfc_40241
{ "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 0 1 1 1\n", "output": "Ron\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
682_E. Alyona and Triangles
Solve the following coding problem using the programming language python: You are given n points with integer coordinates on the plane. Points are given in a way such that there is no triangle, formed by any three of these n points, which area exceeds S. Alyona tried to construct a triangle with integer coordinates, ...
vfc_40245
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 1\n0 0\n1 0\n0 1\n1 1\n", "output": "0 -1\n0 1\n2 1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 1\n0 0\n1 0\n0 1\n1 1\n", "output": "0 -1\n0 1\n2 1\n", "type": "stdin_s...
code_contests
verifiable_code
705_D. Ant Man
Solve the following coding problem using the programming language python: Scott Lang is at war with Darren Cross. There are n chairs in a hall where they are, numbered with 1, 2, ..., n from left to right. The i-th chair is located at coordinate xi. Scott is on chair number s and Cross is on chair number e. Scott can ...
vfc_40249
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 4, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7 4 3\n8 11 12 16 17 18 20\n17 16 20 2 20 5 13\n17 8 8 16 12 15 13\n12 4 16 4 15 7 6\n8 14 2 11 17 12 8\n", "output": "139\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 1 3\n140847557 ...
code_contests
verifiable_code
729_A. Interview with Oleg
Solve the following coding problem using the programming language python: Polycarp has interviewed Oleg and has written the interview down without punctuation marks and spaces to save time. Thus, the interview is now a string s consisting of n lowercase English letters. There is a filler word ogo in Oleg's speech. Al...
```python def compute_prefix_function(p): """ Вычисляет префикс функцию паттерна p :param p: паттерн для kmp :return: преикс функцию для p """ s = [0] * len(p) border = 0 # текущая граница for i in range(1, len(p)): while border > 0 and p[i] != p[border]: border = s[...
vfc_40253
{ "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\naogogob\n", "output": "a***b\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "9\nogoogoogo\n", "output": "*********\n", "type": "stdin_stdout" }, { "fn_name": n...
code_contests
verifiable_code
749_B. Parallelogram is Back
Solve the following coding problem using the programming language python: Long time ago Alex created an interesting problem about parallelogram. The input data for this problem contained four integer points on the Cartesian plane, that defined the set of vertices of some non-degenerate (positive area) parallelogram. P...
```python a=list(map(int, input().split())) x1=a[0] y1=a[1] a=list(map(int, input().split())) x2=a[0] y2=a[1] a=list(map(int, input().split())) x3=a[0] y3=a[1] print(3) print(x1+x2-x3, y1+y2-y3) print(x1+x3-x2, y1+y3-y2) print(x3+x2-x1, y2+y3-y1) ```
vfc_40257
{ "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": "0 0\n1 0\n0 1\n", "output": "3\n-1 1\n1 -1\n1 1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "-948 201\n-519 -713\n459 564\n", "output": "3\n-1926 -1076\n30 1478\n888 -350\n", ...
code_contests
verifiable_code
797_A. k-Factorization
Solve the following coding problem using the programming language python: Given a positive integer n, find k integers (not necessary distinct) such that all these integers are strictly greater than 1, and their product is equal to n. Input The first line contains two integers n and k (2 ≤ n ≤ 100000, 1 ≤ k ≤ 20). O...
```python #!/usr/bin/env python from math import sqrt dic = {} def kfact(n, k): if (n, k) in dic: return dic[(n, k)] if k == 1: return [n] for i in range(2, int(sqrt(n)) + 1): if n % i == 0: if kfact(n // i, k - 1): result = [i] + kfact(n // i, k - 1) ...
vfc_40265
{ "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": "1024 5\n", "output": "2 2 2 2 64\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "100000 2\n", "output": "2 50000\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
817_C. Really Big Numbers
Solve the following coding problem using the programming language python: Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representatio...
```python def nine(p) : s='' for i in range(p) : s+='9' return int(s) def prosh(p) : ans=0 for i in range(1,p+1) : ans+=nine(i)*9 return ans n,k=map(int,input().split()) l=[0]*29 for i in range(19) : e=nine(19-i) l[i]=int(k/e) k-=l[i]*e ...
vfc_40269
{ "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 9\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "12 1\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "25 20...
code_contests
verifiable_code
842_C. Ilya And The Tree
Solve the following coding problem using the programming language python: Ilya is very fond of graphs, especially trees. During his last trip to the forest Ilya found a very interesting tree rooted at vertex 1. There is an integer number written on each vertex of the tree; the number written on vertex i is equal to ai...
```python from sys import stdin from fractions import gcd n = int(stdin.readline().strip()) v = map(int, stdin.readline().strip().split()) adj = [[] for _ in xrange(n)] for _ in xrange(n-1): x, y = map(int, stdin.readline().strip().split()) adj[x-1].append(y-1) adj[y-1].append(x-1) root_divisors = [] cnt...
vfc_40273
{ "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\n6 2 3\n1 2\n1 3\n", "output": "6 6 6 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n10\n", "output": "10 ", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
888_G. Xor-MST
Solve the following coding problem using the programming language python: You are given a complete undirected graph with n vertices. A number ai is assigned to each vertex, and the weight of an edge between vertices i and j is equal to ai xor aj. Calculate the weight of the minimum spanning tree in this graph. Input...
```python import sys range = xrange input = raw_input inp = [int(x) for x in sys.stdin.read().split()] n = inp[0] A = inp[1:] A.sort() ### Tree L = [-1, -1] val = [0, 0] def check(ind): if L[ind] == -1: L[ind] = len(L) L.append(-1) L.append(-1) val.append(-1) val.append(-...
vfc_40281
{ "difficulty": "13", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n1 2 3 4 5\n", "output": "8\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
911_E. Stack Sorting
Solve the following coding problem using the programming language python: Let's suppose you have an array a, a stack s (initially empty) and an array b (also initially empty). You may perform the following operations until both a and s are empty: * Take the first element of a, push it into s and remove it from a (...
```python def divisors(M): d=[] i=1 while M>=i**2: if M%i==0: d.append(i) if i**2!=M: d.append(M//i) i=i+1 return d def popcount(x): x = x - ((x >> 1) & 0x55555555) x = (x & 0x33333333) + ((x >> 2) & 0x33333333) x = (x + (x >> 4)) & 0x...
vfc_40285
{ "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\n2 3 1\n", "output": "-1", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 3\n3 2 1\n", "output": "3 2 1 5 4 ", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
933_C. A Colourful Prospect
Solve the following coding problem using the programming language python: Firecrackers scare Nian the monster, but they're wayyyyy too noisy! Maybe fireworks make a nice complement. Little Tommy is watching a firework show. As circular shapes spread across the sky, a splendid view unfolds on the night of Lunar New Ye...
```python from decimal import * getcontext().prec = 40 eps = Decimal('1e-10') class Circle: def __init__(self, x, y, r): self.x = x self.y = y self.r = r def contains(self, c): dd = (self.x - c.x)**2 + (self.y - c.y)**2 # dd = d*d return dd < (self.r - c.r)**2 and self.r > c.r def in_touches(self, c)...
vfc_40289
{ "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": "3\n0 0 2\n3 0 2\n6 0 2\n", "output": "6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n0 0 1\n2 0 1\n4 0 1\n", "output": "4\n", "type": "stdin_stdout" }, { "f...
code_contests
verifiable_code
95_E. Lucky Country
Solve the following coding problem using the programming language python: Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One night Petya was sleepin...
vfc_40293
{ "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 3\n1 2\n2 3\n1 3\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 4\n1 2\n3 4\n4 5\n3 5\n", "output": "-1\n", "type": "stdin_stdout" }, { "fn_...
code_contests
verifiable_code
algorithm-guru
Solve the following coding problem using the programming language python: Once Algorithm guru gave a simple problem to his students.He gave a list of n integers say, A={a1,a2,a3...an} and another integer, x representing the expected sum. He said students to select numbers from array list(0 or more numbers) such that t...
```python t=input() while t: t-=1 n,k=map(int,raw_input().split()) a=map(int,raw_input().split()) pos=[False]*(k+1) current=[False]*(k+1) for x in a: y=x while y<=k: current[y]=True y+=x pos=list(current) pos[0]=True i=0 while i<=k: if (current[i]): j=i while j<=k: if (current[i] and c...
vfc_40301
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n3 12\n1 6 9\n5 9\n3 4 4 4 8\n\nSAMPLE", "output": "12\n9", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n3 12\n1 6 9\n5 9\n3 4 4 4 8\n\nEAMPLS", "output": "12\n9\n", "type"...
code_contests
verifiable_code
bytelandian-conversions
Solve the following coding problem using the programming language python: In Byteland,conversion of numbers between different bases has always been a herculian task.They always make errors in these conversions. People in Byteland always write one of the digits wrong when they convert a number to a new base and write...
```python def base3Modifier(base3List,iteration): localBase3=list(base3List) bitLoc=int(iteration/2) bitRemainder=iteration%2 if(bitRemainder==0): if(localBase3[bitLoc]=='2'): localBase3[bitLoc]='1' elif(localBase3[bitLoc]=='1'): localBase3[bitLoc]='0' else: localBase3[bitLoc]='2' else: if(localBa...
vfc_40305
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1010\n212\n\nSAMPLE", "output": "14", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
dead-mans-chest
Solve the following coding problem using the programming language python: Captain Jack Sparrow and Davy Jones are having a furious sword fight to gain the key to the chest containing Davy Jones' heart. Jack wants to kill Davy Jones and live forever as the captain of The Flying Dutchman. On the other hand, Davy Jones w...
```python def py_2(): t = input() for tt in xrange(t): freq = [0]*26 s = raw_input() slen = len(s) for i in xrange(slen): #print ord(s[i])-97 freq[ord(s[i])-97] += 1 c = 0 for i in xrange(26): if freq[i]%2: c += 1 if c==0: print 'JACK' elif c%2: print 'JACK' else: print 'DAVY J...
vfc_40309
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\naba\nabca\n\nSAMPLE", "output": "JACK\nDAVY JONES", "type": "stdin_stdout" }, { "fn_name": null, "input": "100\nlwvaneiwcugzlsreuxzpfyqmdkwvakuulwgmyfyonuvwfkpsohudvsnybxgxdpxnikrqpdrqpnrjewmshjsm...
code_contests
verifiable_code
game-of-perfectness
Solve the following coding problem using the programming language python: You're playing a video game, in which you will get an achievement if you complete all of the levels consecutively without dying. You can play the levels in any order, and each time you play a level you'll either complete it or die. Each level ha...
```python flag=1 for i in range(input()): n=input() a=map(int,raw_input().split()) b=map(int,raw_input().split()) pd=[x1*(x2**2) for (x1,x2) in zip(a,b)] i=0 dic={} for j in pd: dic[i]=j i+=1 print "Case #"+str(flag)+":" , for w in sorted(dic,key=dic.get,reverse=True): print w, print"" flag+=1 ```
vfc_40313
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n4\n1 1 1 1\n50 0 20 20\n\nSAMPLE", "output": "Case #1: 0 2 3 1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n4\n1 1 1 1\n50 0 20 20", "output": "Case #1: 0 2 3 1\n", "t...
code_contests
verifiable_code
kevin-doesnt-like-his-array
Solve the following coding problem using the programming language python: Link to Russian translation of the problem. Kevin has an array A of N integers, but he doesn't like it - he only likes an array if all its neighboring elements are different (e.g. he likes the array [2,4,2,5,3,2,4], but not [1,2,3,3,4]). Kevin...
```python n=int(raw_input()) arr=map(int,raw_input().split()) look=[0]*(max(arr)+1) look_count=[0]*(max(arr)+1) for i in xrange(len(arr)): look_count[arr[i]]+=1 for i in xrange(len(arr)-1): if arr[i]==arr[i+1]: look[arr[i]]+=1 mx=max(look) if max(look_count)>(n+1)/2: print -1 else: print max(mx,(sum(look)+1)/2)...
vfc_40317
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7\n1 3 2 2 4 4 4\n\n\nSAMPLE", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "1000\n29622 4608 4588 29622 4597 4563 29622 29622 29622 4563 29622 29622 4570 29622 4577 29622 296...
code_contests
verifiable_code
modified-number
Solve the following coding problem using the programming language python: A modified KP number is a positive whole number n with d digits, such that when we split its square into two pieces - a right hand piece r with d digits and a left hand piece l that contains the remaining d or d−1 digits, the sum of the pieces i...
```python def kaprekar(i): if i == 1: return True s = i**2 s = str(s) length = len(s) if len(s) <= 1: return False temp = int(s[0:length/2]) + int(s[length/2:]) if temp == i: return True else: return False a = input() b = input() l = [] for i in range(a,b+...
vfc_40321
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n100\n\nSAMPLE", "output": "1 9 45 55 99", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
panda-and-numbers
Solve the following coding problem using the programming language python: Panda is fond of numbers. Given a number, he subtracts it with squares of any one particular digit of that number to get new numbers. This operation can be applied any number of times (possibly zero) till he obtains a pandatic number. If he is a...
```python tc = int(raw_input()) while(tc): n = int(raw_input()) if n == 90 or n == 91: print "No" elif n<13: if n==1 or n==4: print "Yes" else: print "No" else: print "Yes" tc = tc -1 ```
vfc_40325
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1\n3\n13\n\nSAMPLE", "output": "Yes\nNo\nYes\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1000\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\...
code_contests
verifiable_code
roses-game
Solve the following coding problem using the programming language python: Rose loves to play games. This problem is about a game he recently played. In the game there are N locations, numbered 0 through N-1. Each location has one entrance and one exit. You are given an array aka A with N elements.For each i, A[i] desc...
```python t=input() while t>0: n=input() s=map(int,raw_input().strip().split()) d={} #print s i=0 while i!=-1 and (i not in d): d[i]=1 i=s[i] #print i if i==-1: print "Win" else: print "Lose" t=t-1 ```
vfc_40329
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n2\n1 -1\n3\n1 0 -1\n3\n0 1 2\n\nSAMPLE", "output": "Win\nLose\nLose\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n2\n1 -1\n3\n1 0 -1\n3\n0 1 2\n37\n29 33 28 16 -1 11 10 14 6 31 7 ...
code_contests
verifiable_code
strange-series
Solve the following coding problem using the programming language python: Jack is a great mathematician. He loves to solve series. Now Stuart gave a series to Jack and said you have to solve the problem by making a computer program. But Jack doesn't know, how to code. The series is: 1 + (a1).(x)^1 + (a2).(x)^2 + (a3...
```python for t in range(int(raw_input())): n = int(raw_input()) print 2**n - 1 ```
vfc_40333
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n1\n\nSAMPLE", "output": "1\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
unique-ranking
Solve the following coding problem using the programming language python: The end sem exams at are over. Sneh is the class teacher of class X/C. She now has the hectic task of preparing the report card of her class. Since Sneh is a computer teacher she tried to infuse some fun into his task. Sneh knew that there are ...
```python (N,K) = map(int,str(raw_input()).split()) marks = [] for i in range(N): marks.append(map (int, str(raw_input()).split())) def worst(subjects): candidates = range(N) for subject in subjects: if len(candidates) == 1: return candidates[0] + 1 min = 100 new_candidates = [] for candidate in candida...
vfc_40337
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 3\n50 60 70\n40 60 80\n50 60 61\n3\n3 1 2 3\n1 2\n2 3 1\n\nSAMPLE", "output": "2\n1\n3", "type": "stdin_stdout" }, { "fn_name": null, "input": "1000 20\n2 1 1 4 4 3 4 2 2 3 2 1 4 4 2 1 3 3 3 2 \n1 ...
code_contests
verifiable_code
p03586 Tenka1 Programmer Contest - ModularPowerEquation!!
Solve the following coding problem using the programming language python: Process the Q queries below. * You are given two integers A_i and M_i. Determine whether there exists a positive integer K_i not exceeding 2 × 10^{18} such that A_i^{K_i} ≡ K_i (mod M_i), and find one if it exists. Constraints * 1 \leq Q \leq...
```python def extgcd(a, b): if b == 0: return 1 else: x, y, u, v, k, l = 1, 0, 0, 1, a, b while l != 0: x, y, u, v = u, v, x - u * (k // l), y - v * (k // l) k, l = l, k % l return x def inved(x, m): return x % m def gcd(x, y): while y != 0: x, y = y, x % y return x def doublin...
vfc_40369
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 268435456, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n177 168\n2028 88772\n123456789 987654321", "output": "7953\n234831584\n471523108231963269", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n2 4\n3 8\n9 6\n10 7", "output": "4\n11\n...
code_contests
verifiable_code
p00010 Circumscribed Circle of a Triangle
Solve the following coding problem using the programming language python: Write a program which prints the central coordinate $(p_x, p_y)$ and the radius $r$ of a circumscribed circle of a triangle which is constructed by three points $(x_1, y_1)$, $(x_2, y_2)$ and $(x_3, y_3)$ on the plane surface. Constraints * $-...
```python import sys f = sys.stdin def take2(iterable): while True: yield next(iterable), next(iterable) #外積 def cross(v1, v2): return v1.real * v2.imag - v1.imag * v2.real # 線分13と線分24の交点を求める def get_intersection(p1,p2,p3,p4): a1 = p4 - p2 b1 = p2 - p3 b2 = p1 - p2 s1 = cross(a1, b2) / ...
vfc_40381
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n0.0 0.0 2.0 0.0 2.0 2.0", "output": "1.000 1.000 1.414", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n0.0 0.0 2.0 0.5127281311709682 2.0 2.0", "output": "0.744 1.256 1.460\n", ...
code_contests
verifiable_code
p00142 Nature of Prime Numbers
Solve the following coding problem using the programming language python: A prime number n (11, 19, 23, etc.) that divides by 4 and has 3 has an interesting property. The results of calculating the remainder of the square of a natural number (1, 2, ..., n -1) of 1 or more and less than n divided by n are the same, so ...
```python import sys readline = sys.stdin.readline write = sys.stdout.write def solve(): N = int(readline()) if N == 0: return False if N == 1: return True *S, = set(i**2 % N for i in range(1, N)) S.sort() L = len(S) C = [0]*N D = [0]*((N-1)//2) for i in range(L): ...
vfc_40385
{ "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": "11\n15\n0", "output": "4\n4\n4\n4\n4\n2\n2\n4\n2\n4\n4\n2", "type": "stdin_stdout" }, { "fn_name": null, "input": "11\n23\n0", "output": "4\n4\n4\n4\n4\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n...
code_contests
verifiable_code
p00275 The Outcome of Bonze
Solve the following coding problem using the programming language python: One of the games that uses the Hyakunin Isshu tag is "Buddhist turning". It is a simple game that uses only picture cards, so it is widely enjoyed. There are various derivative types of rules, but the shaved turn considered here is performed by ...
```python while True: n = int(input()) if n == 0: break player = [0 for i in range(n)] cards = list(input()) g = 0 for i in range(100): if cards[i] == "M": player[i%n] += 1 elif cards[i] == "S": g += player[i%n]+1 player[i%n] = 0 ...
vfc_40389
{ "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": "2\nSSSSSSSSSSSSSSSLLLLLLLLLLLLLLLLLLLLLMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM\n2\nSSSSSSSSSSSSSSLLLLLLLLLLLLLLLLLLLLMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMSL\n5\nMMMMMMSLSLLMMMSMMS...
code_contests
verifiable_code
p00463 Amidakuji
Solve the following coding problem using the programming language python: problem You are playing with J using the Midakuji. The Amida lottery consists of n vertical bars and m horizontal bars. The vertical bars are numbered from 1 to n in order from the left, and the vertical bar i The positive integer si is written...
```python while True: n,m,h,k = map(int,input().split()) if not n: break s_lst = [int(input()) for _ in range(n)] i_lst = [i for i in range(n)] b_lst = [tuple(map(int,input().split())) for _ in range(m)] b_lst = sorted(b_lst,key=lambda x:x[1]) pare_lst = [] for bar in b_lst: ind = bar[0] temp = ...
vfc_40393
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 5 7 2\n20\n80\n100\n50\n1 1\n2 6\n2 3\n1 5\n3 1\n2 2 5 1\n10\n20\n1 1\n1 3\n0 0 0 0", "output": "100\n10", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 5 7 2\n20\n80\n100\n50\n1 1\n2 6\...
code_contests
verifiable_code
p00929 There is No Alternative
Solve the following coding problem using the programming language python: Example Input 4 4 1 2 3 1 3 3 2 3 3 2 4 3 Output 1 3 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, M = map(int, input().split()) E0 = [] for i in range(M): S, D, C = map(int, input().split()) E0.append((C, S-1, D-1)) E0.sort() *parent, = range(N) def root(x): if x == parent[x]: return x y = parent[x] = root(parent[x]) return y def unite(x, y): px = root(x); py = root(y) ...
vfc_40405
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 268435456, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 4\n1 2 3\n1 3 3\n2 3 3\n2 4 3", "output": "1 3", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 4\n1 2 3\n1 3 3\n2 3 3\n2 4 6", "output": "1 6\n", "type": "stdin_stdout" }...
code_contests
verifiable_code
p01194 Web 0.5
Solve the following coding problem using the programming language python: In a forest, there lived a spider named Tim. Tim was so smart that he created a huge, well-structured web. Surprisingly, his web forms a set of equilateral and concentric N-sided polygons whose edge lengths form an arithmetic sequence. <image> ...
vfc_40413
{ "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 1\n2 1 3 2\n2 1 2 2\n0 0", "output": "4.18", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 1\n2 1 3 2\n2 1 2 2\n0 1", "output": "4.175570504585\n", "type": "stdin_stdout" ...
code_contests
verifiable_code
p01332 Three Silhouettes
Solve the following coding problem using the programming language python: JAVA (Japan Aerospace Voyage Agency) launched a spacecraft in 2003 as part of its space development project. One of the purposes of launching this spacecraft is to approach the asteroid Ishikawa and collect samples of its surface material. Despi...
vfc_40417
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 8, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n0 0\n100 0\n100 100\n0 100\n4\n0 0\n100 0\n100 100\n0 100\n4\n0 0\n100 0\n100 100\n0 100\n3\n0 0\n100 0\n0 100\n3\n0 0\n100 0\n0 100\n3\n0 0\n100 0\n0 100\n5\n0 0\n200 0\n200 200\n100 100\n0 200\n5\n0 0\n200 0\n100 100\n200 200\...
code_contests
verifiable_code
p01499 Rabbit Game Playing
Solve the following coding problem using the programming language python: Honestly, a rabbit does not matter. There is a rabbit playing a stage system action game. In this game, every stage has a difficulty level. The rabbit, which always needs challenges, basically wants to play more difficult stages than he has eve...
```python import sys import bisect # ???????????¨?????????DP? # def main(): n,t = map(int, sys.stdin.readline().split()) levels = [] for i in range(n): d = int(sys.stdin.readline()) levels.append(d) levels.sort() ans = 1 for i in range(n): cnt = i - bisect.bisect_left...
vfc_40421
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 8, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 1\n1\n2\n3", "output": "4", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 3\n9\n2\n6\n8\n8", "output": "24", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
p01947 Ninja Map
Solve the following coding problem using the programming language python: Intersections of Crossing Path City are aligned to a grid. There are $N$ east-west streets which are numbered from 1 to $N$, from north to south. There are also $N$ north-south streets which are numbered from 1 to $N$, from west to east. Every p...
vfc_40433
{ "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": "4\n12 1\n3 8\n10 7\n13 14\n8 2\n9 12\n6 14\n11 3\n3 13\n1 10\n11 15\n4 15\n4 9\n14 10\n5 7\n2 5\n6 1\n14 5\n16 11\n15 6\n15 13\n9 6\n16 4\n13 2", "output": "8 2 5 7\n3 13 14 10\n11 15 6 1\n16 4 9 12", "type": "stdin_std...
code_contests
verifiable_code
p02096 Add
Solve the following coding problem using the programming language python: I: Add Problem Statement Mr. T has had an integer sequence of N elements a_1, a_2, ... , a_N and an integer K. Mr. T has created N integer sequences B_1, B_2, ... , B_N such that B_i has i elements. * B_{N,j} = a_j (1 \leq j \leq N) * B_{i,j}...
vfc_40437
{ "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": "2\n3 0\n1 2 3\n3 1\n1 2 3", "output": "3 2 1\n3 65536 0", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n3 0\n1 3 3\n3 1\n1 2 3", "output": "3 3 1\n3 65536 0\n", "type": "stdin...
code_contests
verifiable_code
p02234 Matrix Chain Multiplication
Solve the following coding problem using the programming language python: The goal of the matrix-chain multiplication problem is to find the most efficient way to multiply given $n$ matrices $M_1, M_2, M_3,...,M_n$. Write a program which reads dimensions of $M_i$, and finds the minimum number of scalar multiplication...
```python # -*- coding: utf-8 -*- N = int(input()) p = [0 for _ in range(N+1)] p[0], p[1] = map(int, input().split()) for n in range(2, N+1): p[n] = list(map(int, input().split()))[1] M = [[0]*(N+1) for _ in range(N+1)] for n in range(N+1): M[n][n] = 0 for l in range(2, N+1): for i in range(1, N-l+2): ...
vfc_40441
{ "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": "6\n30 35\n35 15\n15 5\n5 10\n10 20\n20 25", "output": "15125", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n10 35\n35 15\n15 5\n5 10\n10 20\n20 25", "output": "9125\n", "type...
code_contests
verifiable_code
p02380 Triangle
Solve the following coding problem using the programming language python: For given two sides of a triangle a and b and the angle C between them, calculate the following properties: * S: Area of the triangle * L: The length of the circumference of the triangle * h: The height of the triangle with side a as a bottom e...
```python import math pi=math.pi a,b,si=map(float,input().split()) S=(1/2)*a*b*math.sin(math.radians(si)) c2=a*a+b*b-2*a*b*math.cos(math.radians(si)) L=a+b+math.sqrt(c2) h=(2*S)/a print(S) print(L) print(h) ```
vfc_40445
{ "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 3 90", "output": "6.00000000\n12.00000000\n3.00000000", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 3 130", "output": "4.59626665871\n13.3582153654\n2.29813332936\n", "type...
code_contests
verifiable_code
brackets
Solve the following coding problem using the programming language python: A valid parentheses sequence is a non-empty string where each character is either '(' or ')', which satisfies the following constraint: You can find a way to repeat erasing adjacent pairs of parentheses '()' until it becomes empty. For exam...
```python def f(s): balance = 0 max_balance =0 for i in range(len(s)): if s[i] == '(': balance +=1 if s[i] == ')': balance -=1 max_balance = max(max_balance,balance) return max_balance for _ in range(input()): k = "" for i in range(f(str(raw_input()))): k = '('+k+...
vfc_40449
{ "difficulty": "1", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n()((()()))", "output": "((()))\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n()(())()()", "output": "(())\n", "type": "stdin_stdout" }, { "fn_name": null,...
code_contests
verifiable_code
color
Solve the following coding problem using the programming language python: After a long time, Chef has finally decided to renovate his house. Chef's house has N rooms in it numbered from 1 to N. Each room is currently painted in one of the red, blue or green colors. Your are given configuration of colors of his house b...
```python for _ in xrange(input()): l = [] n = input() s = raw_input() l.append(s.count('R')) l.append(s.count('G')) l.append(s.count('B')) l.remove(max(l)) print sum(l) ```
vfc_40453
{ "difficulty": "1", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n3\nRGR\n3\nRRR\n3\nRGB", "output": "1\n0\n2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n3\nRGR\n3\nRRR\n3\nGRB", "output": "1\n0\n2\n", "type": "stdin_stdout" }, ...
code_contests
verifiable_code
gballs
Solve the following coding problem using the programming language python: Note: For Turbo C++, select "Text" as your language Problem description: ProCon Junior gives you chance to earn points for admission in IIIT Delhi. So, it is not easy to get points. If you solve this problem you are one more step closer to earn ...
```python x=input() for i in range(x): y=input() ln=[] d=dict() for j in range(y): n=raw_input() st=n.split() name=st[0] sc=int(st[1]) if name in ln: new=d[name]+sc d[name]=new else: ...
vfc_40457
{ "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\nAshish 2\nAyush 3\n3\nAshish 2\nAshish 4\nAyush 5\n3\nAyush 2\nAneesh 5\nAshish 3", "output": "Ayush 3\nAshish 6\nAneesh 5", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n2\nAshish ...
code_contests
verifiable_code
lucky9
Solve the following coding problem using the programming language python: Chef has the string s of length n consisted of digits 4 and 7. The string s is called balanced if there exits such integer x (1 ≤ x ≤ n) that the number of digits 4 in substring s[1; x) is equal to the number of digits 7 in substring s(x; n], wh...
```python mod = 1000000007 fact = [1] for i in xrange(1,5003): fact.append((i*fact[i-1])%mod) inv = [] for j in xrange(5003): nv = pow(fact[j] , mod-2 , mod) inv.append(nv) for j in xrange(int(raw_input())): l = raw_input() four = l.count('4') seven = l.count('7') if (four == 0 or seven == 0...
vfc_40461
{ "difficulty": "3", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n47\n4477", "output": "1\n4", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n47\n3680", "output": "1\n1\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
prpalin
Solve the following coding problem using the programming language python: An integer is said to be a palindrome if it is equal to its reverse. For example, 79197 and 324423 are palindromes. In this task you will be given an integer N, 1 ≤ N ≤ 1000000. You must find the smallest integer M ≥ N such that M is a prime n...
```python import math n=input() if n&1==0: n+=1 found=0 def checkPrime(x): if x<=1: return 0 if x%2==0: return 0 else: root=int(math.sqrt(x))+1 for i in range(3,root,2): if x%i==0: return 0 else: return 1 whi...
vfc_40465
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "31", "output": "101\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
tetra
Solve the following coding problem using the programming language python: Given the lengths of the edges of a tetrahedron calculate the radius of a sphere inscribed in that tetrahedron (i.e. a sphere tangent to all the faces). Input An integer t, 1 ≤ t ≤ 30, denoting the number of test cases, followed by t lines, ea...
```python # tetra.py def area(a,b,c): s = 0.5*(a+b+c) answer = ( s * (s-a) * (s-b) * (s-c) )**0.5 return answer def determinant( x ): # assumes x is a square matrix if len(x)==1: return x[0][0] if len(x)==2: return x[0][0]*x[1][1] - x[0][1]*x[1][0] row = [0]*(len(x)-1) ...
vfc_40469
{ "difficulty": "3", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n1 1 1 1 1 1\n1000 999 998 5 5 6", "output": "0.2041\n1.4189", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1 1 1 1 1 0\n1000 999 998 5 5 6", "output": "0.0000\n1.4189\n", ...
code_contests
verifiable_code
1037_D. Valid BFS?
Solve the following coding problem using the programming language python: The [BFS](https://en.wikipedia.org/wiki/Breadth-first_search) algorithm is defined as follows. 1. Consider an undirected graph with vertices numbered from 1 to n. Initialize q as a new [queue](http://gg.gg/queue_en) containing only vertex 1, ...
```python from sys import stdin from collections import deque n=int(stdin.readline()) g=dict() for i in range(n-1): a,b=map(int,stdin.readline().split()) g.setdefault(a, set()).add(b) g.setdefault(b, set()).add(a) a=[int(x) for x in stdin.readline().split()] ans = True if n > 1 and a[0] == 1: q=deque() ...
vfc_40477
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n1 2\n1 3\n2 4\n1 2 4 3\n", "output": "No\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n1 2\n1 3\n2 4\n1 2 3 4\n", "output": "Yes\n", "type": "stdin_stdout" }, {...
code_contests
verifiable_code
105_E. Lift and Throw
Solve the following coding problem using the programming language python: You are given a straight half-line divided into segments of unit length, which we will call positions. The positions are numbered by positive integers that start with 1 from the end of half-line, i. e. 1, 2, 3 and so on. The distance between the...
vfc_40481
{ "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": "9 3 3\n4 3 1\n2 3 3\n", "output": "15\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "7 1 5\n9 2 1\n6 3 3\n", "output": "19\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1081_F. Tricky Interactor
Solve the following coding problem using the programming language python: This is an interactive problem. Chouti was tired of studying, so he opened the computer and started playing a puzzle game. Long long ago, the boy found a sequence s_1, s_2, …, s_n of length n, kept by a tricky interactor. It consisted of 0s an...
vfc_40485
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 2\n2\n2\n0", "output": "? 1 1\n? 1 1\n? 3 4\n! 0011", "type": "stdin_stdout" }, { "fn_name": null, "input": "0000000000010100000100100011100011010010100010000001000010010000001010001011000011001000...
code_contests
verifiable_code
1129_C. Morse Code
Solve the following coding problem using the programming language python: In Morse code, an letter of English alphabet is represented as a string of some length from 1 to 4. Moreover, each Morse code representation of an English letter contains only dots and dashes. In this task, we will represent a dot with a "0" and...
```python import os, sys nums = list(map(int, os.read(0, os.fstat(0).st_size).split())) MOD = 10 ** 9 + 7 BAD = ([0, 0, 1, 1], [0, 1, 0, 1], [1, 1, 1, 0], [1, 1, 1, 1]) def zfunc(s): z = [0] * len(s) l = r = 0 for i in range(1, len(s)): if i <= r: z[i] = min(r - i + 1, z[i - l]) ...
vfc_40493
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n1\n0\n1\n0\n1\n", "output": "1\n4\n10\n22\n43\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "9\n1\n1\n0\n0\n0\n1\n1\n0\n1\n", "output": "1\n3\n10\n24\n51\n109\n213\n421\n833\n", ...
code_contests
verifiable_code
1149_D. Abandoning Roads
Solve the following coding problem using the programming language python: Codefortia is a small island country located somewhere in the West Pacific. It consists of n settlements connected by m bidirectional gravel roads. Curiously enough, the beliefs of the inhabitants require the time needed to pass each road to be ...
```python import heapq n,m,a,b=map(int,input().split()) graph={i:[] for i in range(n)} for i in range(m): u,v,w=map(int,input().split()) graph[u-1].append((v-1,w)) graph[v-1].append((u-1,w)) components=[-1]*n comp=-1 for i in range(n): if components[i]==-1: comp+=1 components[i]=comp ...
vfc_40497
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 5, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6 7 13 22\n1 2 13\n2 3 13\n1 4 22\n3 4 13\n4 5 13\n5 6 13\n6 1 13\n", "output": "0 13 26 39 26 13\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 5 20 25\n1 2 25\n2 3 25\n3 4 20\n4 5 20\...
code_contests
verifiable_code
1170_D. Decoding of Integer Sequences
Solve the following coding problem using the programming language python: Polycarp is developing a method for transmitting n integer sequences over a network. This method should support the transmission of an arbitrary number of integer sequences; sequences can have different lengths. The sequences contain arbitrary n...
vfc_40501
{ "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": "12\n3 2 1 1 7 2 4 -1 3 -1 4 -1\n", "output": "\n3\n3 3 1 4\n2 2 7\n4 1 2 3 4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n2 -1 2 -1 3 -1\n", "output": "\n3\n1 2\n0\n2 2 3\n", ...
code_contests
verifiable_code
1189_C. Candies!
Solve the following coding problem using the programming language python: Consider a sequence of digits of length 2^k [a_1, a_2, …, a_{2^k}]. We perform the following operation with it: replace pairs (a_{2i+1}, a_{2i+2}) with (a_{2i+1} + a_{2i+2})mod 10 for 0≤ i<2^{k-1}. For every i where a_{2i+1} + a_{2i+2}≥ 10 we ge...
```python import sys input = lambda: sys.stdin.readline().strip() from math import log2 n = int(input()) ls = list(map(int, input().split())) Sum = [0] for i in ls: Sum.append(Sum[-1]+i) q = int(input()) for i in range(q): a, b = map(int, input().split()) print((Sum[b]-Sum[a-1])//10) ```
vfc_40505
{ "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": "8\n8 7 3 1 7 0 9 4\n3\n1 8\n2 5\n7 7\n", "output": "3\n1\n0\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1208_C. Magic Grid
Solve the following coding problem using the programming language python: Let us define a magic grid to be a square matrix of integers of size n × n, satisfying the following conditions. * All integers from 0 to (n^2 - 1) inclusive appear in the matrix exactly once. * [Bitwise XOR](https://en.wikipedia.org/wiki...
```python n = int(input()) for i in range(n): printlist = [] m=i//4 k=i%4 for j in range(n): printlist.append(str(4*n*m+4*j+k)) print(' '.join(printlist)) ```
vfc_40509
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n", "output": "0 1 2 3\n4 5 6 7\n8 9 10 11\n12 13 14 15\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "8\n", "output": "0 1 2 3 16 17 18 19 \n4 5 6 7 20 21 22 23 \n8 9 10 11 24 25...
code_contests
verifiable_code
1227_C. Messy
Solve the following coding problem using the programming language python: You are fed up with your messy room, so you decided to clean it up. Your room is a bracket sequence s=s_{1}s_{2}... s_{n} of length n. Each character of this string is either an opening bracket '(' or a closing bracket ')'. In one operation yo...
```python t=int(input()) for i in range(t): n,k=map(int,input().split()) s=input() s=[s[i] for i in range(n)] limit=(k-1)*2 l=0 answer =[] answerk=0 for r in range(n): if s[r]=="(": if l!=r: answer.append([l+1,r+1]) answerk+=1 ...
vfc_40513
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n8 2\n()(())()\n10 3\n))()()()((\n2 1\n()\n2 1\n)(\n", "output": "1\n5 7\n5\n1 3\n3 5\n5 7\n6 9\n7 10\n0\n1\n1 2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n8 2\n()(())()\n10 3\n)...
code_contests
verifiable_code
1250_A. Berstagram
Solve the following coding problem using the programming language python: Polycarp recently signed up to a new social network Berstagram. He immediately published n posts there. He assigned numbers from 1 to n to all posts and published them one by one. So, just after publishing Polycarp's news feed contained posts fr...
vfc_40517
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 5\n3 2 1 3 3\n", "output": "\n1 2\n2 3\n1 3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10 6\n7 3 5 7 3 6\n", "output": "\n1 2\n2 3\n1 3\n4 7\n4 5\n6 7\n5 7\n8 8\n9 9\n10 10\n"...
code_contests
verifiable_code
1269_D. Domino for Young
Solve the following coding problem using the programming language python: You are given a Young diagram. Given diagram is a histogram with n columns of lengths a_1, a_2, …, a_n (a_1 ≥ a_2 ≥ … ≥ a_n ≥ 1). <image> Young diagram for a=[3,2,2,2,1]. Your goal is to find the largest number of non-overlapping dominos tha...
```python n = int(input()) a = [int(i) for i in input().split()] m = [0,0] for i in range(n): m[0] += a[i] // 2 m[1] += a[i] // 2 if a[i] % 2 != 0: m[i % 2] += 1 print(int(min(m[0], m[1]))) ```
vfc_40521
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n3 2 2 2 1\n", "output": "4\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1291_D. Irreducible Anagrams
Solve the following coding problem using the programming language python: Let's call two strings s and t anagrams of each other if it is possible to rearrange symbols in the string s to get a string, equal to t. Let's consider two strings s and t which are anagrams of each other. We say that t is a reducible anagram ...
```python s = input() mp = [ [0 for i in range(26)] for _ in range(len(s))] for i in range(len(s)) : mp[i][ord(s[i]) - ord('a')] += 1 if i > 0 : for j in range(26) : mp[i][j] += mp[i - 1][j] for _ in range(int(input())) : l, r = map(int, input().split()) sc = 0 for i in range(26)...
vfc_40525
{ "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": "aaaaa\n3\n1 1\n2 4\n5 5\n", "output": "Yes\nNo\nYes\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "aabbbbbbc\n6\n1 2\n2 4\n2 2\n1 9\n5 7\n3 5\n", "output": "No\nYes\nYes\nYes\nNo\nN...
code_contests
verifiable_code
1311_E. Construct the Binary Tree
Solve the following coding problem using the programming language python: You are given two integers n and d. You need to construct a rooted binary tree consisting of n vertices with a root at the vertex 1 and the sum of depths of all vertices equals to d. A tree is a connected graph without cycles. A rooted tree has...
```python t=int(input()) import math as m def print_tree(l): t=[{'p':None, 'c':[]} for i in range(sum(l))] l2={i:[] for i in range(len(l))} j=0 for i in range(sum(l)): l2[j].append(i+1) if len(l2[j])==l[j]: j+=1 for i in range(1,len(l)): p=0 for n in l2[i]...
vfc_40529
{ "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\n5 7\n10 19\n10 18\n", "output": "YES\n1 1 2 4 \nYES\n1 1 2 2 3 3 4 4 5 \nNO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "7\n15 49\n13 77\n18 65\n9 30\n4 6\n11 44\n577 4729\n", ...
code_contests
verifiable_code
1334_C. Circle of Monsters
Solve the following coding problem using the programming language python: You are playing another computer game, and now you have to slay n monsters. These monsters are standing in a circle, numbered clockwise from 1 to n. Initially, the i-th monster has a_i health. You may shoot the monsters to kill them. Each shot ...
```python from sys import stdin, stdout import io, os input = stdin.buffer.readline def inp(): return int(input()) def arrinp(): return [int(x) for x in input().split()] l = [] def main(): t = inp() for _ in range(t): n = inp() A, B = zip(*[list(map(int, input().split())) for i in range...
vfc_40533
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n3\n7 15\n2 14\n5 3\n", "output": "6\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1354_E. Graph Coloring
Solve the following coding problem using the programming language python: You are given an undirected graph without self-loops or multiple edges which consists of n vertices and m edges. Also you are given three integers n_1, n_2 and n_3. Can you label each vertex with one of three numbers 1, 2 or 3 in such way, that...
```python from collections import defaultdict,deque import sys input=sys.stdin.readline def bfs(root): visited[root]=0 parity=[1,0] store=[root] queue=deque([root]) while queue: vertex=queue.popleft() for child in graph[vertex]: if visited[child]==-1: vis...
vfc_40537
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6 3\n2 2 2\n3 1\n5 4\n2 5\n", "output": "YES\n211323", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 9\n0 2 3\n1 2\n1 3\n1 5\n2 3\n2 4\n2 5\n3 4\n3 5\n4 5\n", "output": "NO\n", ...
code_contests
verifiable_code
1397_E. Monster Invaders
Solve the following coding problem using the programming language python: Ziota found a video game called "Monster Invaders". Similar to every other shooting RPG game, "Monster Invaders" involves killing monsters and bosses with guns. For the sake of simplicity, we only consider two different types of monsters and t...
```python #!/usr/bin/env python3 import io import os import sys input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline def printd(*args, **kwargs): #print(*args, **kwargs, file=sys.stderr) #print(*args, **kwargs) pass def get_str(): return input().decode().strip() def rint(): return map(int...
vfc_40545
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 2 4 4 1\n4 5 1 2\n", "output": "31\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 1 3 4 3\n3 2 5 1\n", "output": "34\n", "type": "stdin_stdout" }, { "fn_name...
code_contests
verifiable_code
1421_A. XORwice
Solve the following coding problem using the programming language python: In order to celebrate Twice's 5th anniversary, Tzuyu and Sana decided to play a game. Tzuyu gave Sana two integers a and b and a really important quest. In order to complete the quest, Sana has to output the smallest possible value of (a ⊕ x) ...
```python import math t = int(input()) for _ in range(t): a,b = [int(x) for x in input().split()] x = 1 ans = 0 while(x<=a or x<=b): if (x&a!=x&b): ans+=x x*=2 print(ans) ```
vfc_40549
{ "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": "6\n6 12\n4 9\n59 832\n28 14\n4925 2912\n1 1\n", "output": "10\n13\n891\n18\n6237\n0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n6 12\n4 9\n59 832\n28 14\n4925 2912\n2 1\n", "o...
code_contests
verifiable_code
1439_E. Cheat and Win
Solve the following coding problem using the programming language python: Let's consider a (10^9+1) × (10^9+1) field. The rows are numbered with integers from 0 to 10^9 and the columns are numbered with integers from 0 to 10^9. Let's define as (x, y) the cell located in the x-th row and y-th column. Let's call a cell...
vfc_40553
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1 2 3 4\n3 4 1 2\n2 1 3 4\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n0 1 0 8\n1 0 8 0\n", "output": "0\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
1540_B. Tree Array
Solve the following coding problem using the programming language python: You are given a tree consisting of n nodes. You generate an array from the tree by marking nodes one by one. Initially, when no nodes are marked, a node is equiprobably chosen and marked from the entire tree. After that, until all nodes are m...
```python import sys input = lambda: sys.stdin.readline().rstrip() from collections import deque mod = 10 ** 9 + 7 N = int(input()) E = [] for _ in range(N - 1): x, y = map(int, input().split()) x, y = x-1, y-1 E.append((x, y)) pre = [1] PA = [pre] for i in range(N + 2): ne = [0] * (i + 2) for j, ...
vfc_40569
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1 2\n1 3\n", "output": "166666669\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
167_E. Wizards and Bets
Solve the following coding problem using the programming language python: In some country live wizards. They like to make weird bets. Two wizards draw an acyclic directed graph with n vertices and m edges (the graph's vertices are numbered from 1 to n). A source is a vertex with no incoming edges, and a sink is the v...
vfc_40573
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6 5 1000003\n1 4\n1 5\n1 6\n2 6\n3 6\n", "output": " 0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 2 1000003\n4 1\n3 2\n...
code_contests
verifiable_code
188_F. Binary Notation
Solve the following coding problem using the programming language python: You are given a positive integer n. Output its binary notation. Input The only line of input data contains an integer n (1 ≤ n ≤ 106). Output Output the binary notation of n (without any leading zeros). Examples Input 5 Output 101 In...
vfc_40577
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n", "output": "101\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "101\n", "output": "1100101\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
20_A. BerOS file system
Solve the following coding problem using the programming language python: The new operating system BerOS has a nice feature. It is possible to use any number of characters '/' as a delimiter in path instead of one traditional '/'. For example, strings //usr///local//nginx/sbin// and /usr/local/nginx///sbin are equival...
```python line = input() words = [word for word in line.split("/") if word != ""] print("/{} ".format('/'.join(words))) ```
vfc_40581
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 64000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "//usr///local//nginx/sbin\n", "output": "/usr/local/nginx/sbin\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "/a//aa/a//\n", "output": "/a/aa/a\n", "type": "stdin_stdout" ...
code_contests
verifiable_code
235_C. Cyclical Quest
Solve the following coding problem using the programming language python: Some days ago, WJMZBMR learned how to answer the query "how many times does a string x occur in a string s" quickly by preprocessing the string s. But now he wants to make it harder. So he wants to ask "how many consecutive substrings of s are ...
vfc_40585
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "baabaabaaa\n5\na\nba\nbaa\naabaa\naaba\n", "output": "7\n5\n7\n3\n5\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "aabbaa\n3\naa\naabb\nabba\n", "output": "2\n3\n3\n", "type":...
code_contests
verifiable_code
260_A. Adding Digits
Solve the following coding problem using the programming language python: Vasya has got two number: a and b. However, Vasya finds number a too short. So he decided to repeat the operation of lengthening number a n times. One operation of lengthening a number means adding exactly one digit to the number (in the decima...
```python a, b, n = map(int, input().split()) f = 0 a *= 10 while True: if a % b == 0: break a += 1 if a % 10 == 0: f = 1 break if f == 0: n -= 1 a *= (10 ** n) print(a) else: print(-1) ```
vfc_40589
{ "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": "260 150 10\n", "output": "-1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 4 5\n", "output": "520000\n", "type": "stdin_stdout" }, { "fn_name": null, "i...
code_contests
verifiable_code
284_A. Cows and Primitive Roots
Solve the following coding problem using the programming language python: The cows have just learned what a primitive root is! Given a prime p, a primitive root <image> is an integer x (1 ≤ x < p) such that none of integers x - 1, x2 - 1, ..., xp - 2 - 1 are divisible by p, but xp - 1 - 1 is. Unfortunately, computin...
```python def f(n): m = 1 for i in range(1,p-1): m = (m*n)%p if (m-1)%p: pass else: return False if (m*n-1)%p: return False return True p = int(input()) ans = 0 for i in range(1,p): if f(i): ans += 1 print(ans) ```
vfc_40593
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "19\n", "o...
code_contests
verifiable_code
309_A. Morning run
Solve the following coding problem using the programming language python: People like to be fit. That's why many of them are ready to wake up at dawn, go to the stadium and run. In this problem your task is to help a company design a new stadium. The city of N has a shabby old stadium. Many people like it and every ...
vfc_40597
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 5 1\n0 2\n", "output": "0.2500000000\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 7 3\n0 1 6\n", "output": "1.5000000000\n", "type": "stdin_stdout" }, { "f...
code_contests
verifiable_code
331_E1. Deja Vu
Solve the following coding problem using the programming language python: Everybody knows that we have been living in the Matrix for a long time. And in the new seventh Matrix the world is ruled by beavers. So let's take beaver Neo. Neo has so-called "deja vu" outbursts when he gets visions of events in some places h...
vfc_40601
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6 6\n1 2 2 1 2\n2 3 1 3\n3 4 2 4 5\n4 5 0\n5 3 1 3\n6 1 1 6\n", "output": "1\n2\n1\n1\n2\n1\n1\n2\n1\n1\n2\n1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 6\n1 2 2 1 2\n2 3 1 3\n3 4 2...
code_contests
verifiable_code
354_D. Transferring Pyramid
Solve the following coding problem using the programming language python: Vasya and Petya are using an interesting data storing structure: a pyramid. The pyramid consists of n rows, the i-th row contains i cells. Each row is shifted half a cell to the left relative to the previous row. The cells are numbered by integ...
vfc_40605
{ "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": "4 5\n3 1\n3 3\n4 1\n4 3\n4 4\n", "output": "10\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
378_E. Captains Mode
Solve the following coding problem using the programming language python: Kostya is a progamer specializing in the discipline of Dota 2. Valve Corporation, the developer of this game, has recently released a new patch which turned the balance of the game upside down. Kostya, as the captain of the team, realizes that t...
vfc_40609
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n6 4 5 4 5 5\n4\nb 2\np 1\nb 1\np 2\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n2 1\n2\np 1\np 2\n", "output": "1\n", "type": "stdin_stdout" }, ...
code_contests
verifiable_code
39_G. Inverse Function
Solve the following coding problem using the programming language python: Petya wrote a programme on C++ that calculated a very interesting function f(n). Petya ran the program with a certain value of n and went to the kitchen to have some tea. The history has no records concerning how long the program had been workin...
```python import re, sys, functools def cut_modulo(x): y = x % 32768 if (y < 0): y += 32768 return y class berland_cpp_int: def __init__(self, x): self.value = cut_modulo(int(x)) def __add__(self, x): return berland_cpp_int(cut_modulo(self.value + x.value)) def __sub__(...
vfc_40613
{ "difficulty": "13", "memory_limit": null, "memory_limit_bytes": 64000000, "problem_url": null, "time_limit": "{'seconds': 5, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "17\nint f(int n)\n{\nif (n &lt; 100) return 17;\nif (n &gt; 99) return 27;\n}\n", "output": "-1", "type": "stdin_stdout" }, { "fn_name": null, "input": "144\nint f(int n)\n{\nif (n == 0) return 0;\ni...
code_contests
verifiable_code
425_C. Sereja and Two Sequences
Solve the following coding problem using the programming language python: Sereja has two sequences a1, a2, ..., an and b1, b2, ..., bm, consisting of integers. One day Sereja got bored and he decided two play with them. The rules of the game was very simple. Sereja makes several moves, in one move he can perform one o...
vfc_40617
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 4, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 4 3006 1000\n1 2 3\n1 2 4 3\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 5 100000 1000\n1 2 3 4 5\n3 2 4 5 1\n", "output": "3\n", "type": "stdin_stdout"...
code_contests
verifiable_code
44_A. Indian Summer
Solve the following coding problem using the programming language python: Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the species of the tree of one...
```python a,e={},0 for i in range(int(input())): c,d=list(map(str,input().split())) if c not in a.keys(): a.update({c:[d]}) e+=1 elif d not in a[c]: a[c].append(d) e+=1 print(e) ```
vfc_40621
{ "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\noak yellow\noak yellow\noak yellow\n", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\nbirch yellow\nmaple red\nbirch yellow\nmaple yellow\nmaple green\n", "output":...
code_contests
verifiable_code
470_E. Chessboard
Solve the following coding problem using the programming language python: Chessboard is a board of n × n squares arranged in two alternating colors (black and white). Top left square is white. You are given board size n. Output an image of a chessboard, with black and white squares marked with '#' and '.' characters, ...
vfc_40625
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n", "output": ".#.#\n#.#.\n.#.#\n#.#.\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
519_A. A and B and Chess
Solve the following coding problem using the programming language python: A and B are preparing themselves for programming contests. To train their logical thinking and solve problems better, A and B decided to play chess. During the game A wondered whose position is now stronger. For each chess piece we know its we...
```python # -*- coding: utf-8 -*- """ Created on Thu Nov 8 10:34:19 2018 @author: Quaint Sun """ line=[] t=0 while t<8: line=line+list(input()) t=t+1 white=line.count('Q')*9+line.count('R')*5+line.count('B')*3+line.count('N')*3+line.count('P') black=line.count('q')*9+line.count('r')*5+line.count('b')*3+...
vfc_40633
{ "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": "rnbqkbnr\npppppppp\n........\n........\n........\n........\nPPPPPPPP\nRNBQKBNR\n", "output": "Draw\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
593_B. Anton and Lines
Solve the following coding problem using the programming language python: The teacher gave Anton a large geometry homework, but he didn't do it (as usual) as he participated in a regular round on Codeforces. In the task he was given a set of n lines defined by the equations y = ki·x + bi. It was necessary to determine...
```python def equation(k, x, b): return k * x + b num = int(input()) ans = [] x1, x2 = map(int, input().split()) for i in range(0,num): k, b = map(int, input().split()) ans.append((equation(k, x1, b), equation(k, x2, b))) ans.sort() for i in range(1, num): if (ans[i][0] > ans[i - 1][0] and ...
vfc_40645
{ "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 2\n1 2\n1 0\n0 1\n0 2\n", "output": "NO", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1 3\n1 0\n0 2\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn...
code_contests
verifiable_code
614_E. Necklace
Solve the following coding problem using the programming language python: Ivan wants to make a necklace as a present to his beloved girl. A necklace is a cyclic sequence of beads of different colors. Ivan says that necklace is beautiful relative to the cut point between two adjacent beads, if the chain of beads remain...
```python import math #import fractions from functools import reduce n = int(input()) odd = -1 beads = [int(x) for x in input().split()] for i in range(n): if beads[i]%2: if odd >= 0: print(0) print(''.join(chr(ord('a') + i)*beads[i] for i in range(n))) break els...
vfc_40649
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n4\n", "output": "4\naaaa\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n4 2 1\n", "output": "1\naabcbaa\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
634_B. XOR Equation
Solve the following coding problem using the programming language python: Two positive integers a and b have a sum of s and a bitwise XOR of x. How many possible values are there for the ordered pair (a, b)? Input The first line of the input contains two integers s and x (2 ≤ s ≤ 1012, 0 ≤ x ≤ 1012), the sum and bit...
```python s,x=map(int,input().split()) if x>s or (s-x)%2!=0: print(0) else: mask=1 res=1 bit=0 ND=(s-x)//2 flag=False while bit<50: if (mask&x)>0: res*=2 if mask&x>0 and ND&mask>0: flag=True break mask*=2 bit+=1 if(s==x)...
vfc_40653
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 2\n", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 3\n", "output": "2", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
662_E. To Hack or not to Hack
Solve the following coding problem using the programming language python: Consider a regular Codeforces round consisting of three problems that uses dynamic scoring. You are given an almost final scoreboard. For each participant (including yourself), the time of the accepted submission for each of the problems is giv...
vfc_40657
{ "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\n0 0 119\n-3 -17 -42\n0 7 0\n51 0 0\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n120 120 1\n61 61 120\n-61 61 120\n0 0 0\n", "output": "1\n", "type": "...
code_contests
verifiable_code
687_C. The Values You Can Make
Solve the following coding problem using the programming language python: Pari wants to buy an expensive chocolate from Arya. She has n coins, the value of the i-th coin is ci. The price of the chocolate is k, so Pari will take a subset of her coins with sum equal to k and give it to Arya. Looking at her coins, a que...
```python import sys input = sys.stdin.readline n, k = map(int, input().split()) A = map(int, input().split()) #DP = [[False]*(k+2) for _ in range(k+2)] DP = [] for _ in range(k+1): DP.append([False for _ in range(k+1)]) DP[0][0] = True for a in sorted(A): for i in range(k, a-1, -1): for j in range(0, k+1):...
vfc_40661
{ "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 50\n25 25 50\n", "output": "3\n0 25 50 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 18\n5 6 1 10 12 2\n", "output": "16\n0 1 2 3 5 6 7 8 10 11 12 13 15 16 17 18 ", "type"...
code_contests
verifiable_code
70_B. Text Messaging
Solve the following coding problem using the programming language python: Fangy the little walrus, as all the modern walruses, loves to communicate via text messaging. One day he faced the following problem: When he sends large texts, they are split into parts each containing n characters (which is the size of one tex...
```python import re n=int(input()) ans,sumL=1,0 for s in re.split("[.?!]", input()): s=s.strip()+'.' L=len(s) if L>1: if L>n: print("Impossible") exit() if sumL+L+(sumL>0) > n: ans+=1 sumL=L else: sumL=sumL+L+(sumL>0) print(...
vfc_40665
{ "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": "25\nHello. I am a little walrus.\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\nHow are you?\n", "output": "Impossible\n", "type": "stdin_stdout" }, ...
code_contests
verifiable_code
730_I. Olympiad in Programming and Sports
Solve the following coding problem using the programming language python: There are n students at Berland State University. Every student has two skills, each measured as a number: ai — the programming skill and bi — the sports skill. It is announced that an Olympiad in programming and sports will be held soon. That'...
```python #!/usr/bin/env python3 from itertools import accumulate from heapq import heappop, heappush def top(ppl_indices, vals, start): Q = [] res = [0 for i in range(len(ppl_indices))] for k, idx in enumerate(ppl_indices): heappush(Q, -vals[idx]) if k >= start: res[k] = res[k...
vfc_40669
{ "difficulty": "15", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 2 2\n1 3 4 5 2\n5 3 2 1 4\n", "output": "18\n3 4 \n1 5 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 3 1\n5 2 5 1 7\n6 3 1 6 3\n", "output": "23\n1 3 5 \n4 \n", "type": ...
code_contests
verifiable_code
754_D. Fedor and coupons
Solve the following coding problem using the programming language python: All our characters have hobbies. The same is true for Fedor. He enjoys shopping in the neighboring supermarket. The goods in the supermarket have unique integer ids. Also, for every integer there is a product with id equal to this integer. Fed...
```python from heapq import heappop, heappush n, k = [int(x) for x in input().split()] cs = [] for i in range(n): l, r = [int(x) for x in input().split()] cs.append((l, r, i+1)) cs.sort() h = [] for i in range(k-1): heappush(h, [cs[i][1], cs[i][2]]) lcs = h[:] l = -1 push_i = k-1 for i in range(k-1, n): ...
vfc_40673
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 4, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 2\n1 12\n15 20\n25 30\n", "output": "0\n1 2 ", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
7_A. Kalevitch and Chess
Solve the following coding problem using the programming language python: A famous Berland's painter Kalevitch likes to shock the public. One of his last obsessions is chess. For more than a thousand years people have been playing this old game on uninteresting, monotonous boards. Kalevitch decided to put an end to th...
```python e=0 s1='' s2='' s3='' s4='' s5='' s6='' s7='' s8='' for i in range(8): s=str(input()) if(s==('B'*8)): e=e+1 s1=s1+s[0] s2=s2+s[1] s3=s3+s[2] s4=s4+s[3] s5=s5+s[4] s6=s6+s[5] s7=s7+s[6] s8=s8+s[7] if(s1==('B'*8)): e=e+1 if(s2==('B'*8)): e=e+1 if(s3==('B'*...
vfc_40681
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 64000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "WWWWWWWW\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "WWWBWWBW\nBBBBBBBB\nWWWBWWBW\nWWWBWWBW\nWWWB...
code_contests
verifiable_code
820_C. Mister B and Boring Game
Solve the following coding problem using the programming language python: Sometimes Mister B has free evenings when he doesn't know what to do. Fortunately, Mister B found a new game, where the player can play against aliens. All characters in this game are lowercase English letters. There are two players: Mister B a...
```python def main(a, b, l, r): qL = (l - 1) // (2 * a + 2 * b) rL = (l - 1) % (2 * a + 2 * b) + 1 qR = (r - 1) // (2 * a + 2 * b) rR = (r - 1) % (2 * a + 2 * b) + 1 #print(qL, qR, rL, rR) if qL == qR: #In b segment if a < rL <= a + b and a < rR <= a + b: ...
vfc_40685
{ "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 2 2 6\n", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1 1 8\n", "output": "2", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
846_D. Monitor
Solve the following coding problem using the programming language python: Recently Luba bought a monitor. Monitor is a rectangular matrix of size n × m. But then she started to notice that some pixels cease to work properly. Luba thinks that the monitor will become broken the first moment when it contains a square k ×...
```python from sys import stdout from sys import stdin def get(): return stdin.readline().strip() def getf(): return [int(i) for i in get().split()] def put(a, end = "\n"): stdout.write(str(a) + end) def putf(a, sep = " ", end = "\n"): stdout.write(sep.join([str(i) for i in a]) + end) def check(lmt, qr...
vfc_40689
{ "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 2 5\n1 2 2\n2 2 1\n2 3 5\n3 2 10\n2 1 100\n", "output": "-1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 3 2 5\n2 1 8\n2 2 8\n1 2 1\n1 3 4\n2 3 2\n", "output": "8\n", ...
code_contests
verifiable_code
867_F. Hex Dyslexia
Solve the following coding problem using the programming language python: Copying large hexadecimal (base 16) strings by hand can be error prone, but that doesn't stop people from doing it. You've discovered a bug in the code that was likely caused by someone making a mistake when copying such a string. You suspect th...
vfc_40693
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "12d2c\n", "output": "00314\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "0f1e\n", "output": "00f1\n", "type": "stdin_stdout" }, { "fn_name": null, "input"...
code_contests
verifiable_code
914_H. Ember and Storm's Tree Game
Solve the following coding problem using the programming language python: Ember and Storm play a game. First, Ember picks a labelled tree T of n vertices, such that the degree of every vertex is at most d. Then, Storm picks two distinct vertices u and v in this tree and writes down the labels of the vertices in the pa...
vfc_40701
{ "difficulty": "14", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 2 100\n", "output": "36\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 1 1000000007\n", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "...
code_contests
verifiable_code
938_A. Word Correction
Solve the following coding problem using the programming language python: Victor tries to write his own text editor, with word correction included. However, the rules of word correction are really strange. Victor thinks that if a word contains two consecutive vowels, then it's kinda weird and it needs to be replaced....
```python n = int(input()) s = input() s2 = s[0] for i in range(1,n): if(ord(s[i]) == ord("a") or ord(s[i]) == ord("e") or ord(s[i]) == ord("i") or ord(s[i]) == ord("o") or ord(s[i]) == ord("u") or ord(s[i]) == ord("y")) and (ord(s[i - 1]) == ord("a") or ord(s[i - 1]) == ord("e") or ord(s[i - 1]) == ord("i") or ord...
vfc_40705
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\nword\n", "output": "word\n", "type": "stdin_stdout" } ] }