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
1380_C. Create The Teams
Solve the following coding problem using the programming language python: There are n programmers that you want to split into several non-empty teams. The skill of the i-th programmer is a_i. You want to assemble the maximum number of teams from them. There is a restriction for each team: the number of programmers in ...
```python def f(a,b): if a%b == 0: return(a//b) else: return(a//b +1) t = int(input()) while(t>0): t = t-1 n,x = map(int,input().split()) a = input() A = list(map(int,list(a.split()))) A.sort() table = [0]*(n) b = [0]*(n) for i in range(n): b[i] = f(x,A[i]...
vfc_47205
{ "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\n5 10\n7 11 2 9 5\n4 8\n2 4 2 3\n4 11\n1 3 3 7\n", "output": "2\n1\n0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n5 10\n7 11 2 9 1\n4 8\n2 4 2 3\n4 11\n1 3 3 7\n", "output":...
code_contests
verifiable_code
1400_C. Binary String Reconstruction
Solve the following coding problem using the programming language python: Consider the following process. You have a binary string (a string where each character is either 0 or 1) w of length n and an integer x. You build a new binary string s consisting of n characters. The i-th character of s is chosen as follows: ...
```python def fn1(n,num,lis): for i in range(n): if i-x>=0 and num[i-x]==1: lis.append(1) elif i+x<n and num[i+x]==1: lis.append(1) else: lis.append(0) def fn2(st,s,num): if st==s: for i in num: print(i,end="") print() e...
vfc_47209
{ "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\n101110\n2\n01\n1\n110\n1\n", "output": "111011\n10\n-1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n100110\n2\n01\n1\n110\n1\n", "output": "011001\n10\n-1\n", "type": ...
code_contests
verifiable_code
1545_E1. AquaMoon and Time Stop (easy version)
Solve the following coding problem using the programming language python: Note that the differences between easy and hard versions are the constraints on n and the time limit. You can make hacks only if both versions are solved. AquaMoon knew through foresight that some ghosts wanted to curse tourists on a pedestrian...
vfc_47233
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 1024000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7\n5\n78 96 76 91\n6 16 18 37\n53 63 40 56\n83 88 21 38\n72 75 17 24\n63 63 53 60\n34 46 60 60\n", "output": "20\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n3\n1 5 1 1\n4 10 1 4\n1 ...
code_contests
verifiable_code
172_D. Calendar Reform
Solve the following coding problem using the programming language python: Reforms have started in Berland again! At this time, the Parliament is discussing the reform of the calendar. To make the lives of citizens of Berland more varied, it was decided to change the calendar. As more and more people are complaining th...
```python F = {} def f(k): if not k in F: s, i, j = 0, 4, 4 while i <= k: s += i * f(k // i) i += j + 1 j += 2 F[k] = (k * (k + 1)) // 2 - s return F[k] def g(k): s, i, j = 0, 4, 4 while i <= k: s += (i - 1) * f(k // i) i += j...
vfc_47237
{ "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": "25 3\n", "output": "30\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "50 5\n", "output": "125\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 ...
code_contests
verifiable_code
216_E. Martian Luck
Solve the following coding problem using the programming language python: You know that the Martians use a number system with base k. Digit b (0 ≤ b < k) is considered lucky, as the first contact between the Martians and the Earthlings occurred in year b (by Martian chronology). A digital root d(x) of number x is a n...
```python k, b, n = map(int, input().split()) digits = list(map(int, input().split())) def ans0(): j = -1 answer = 0 for i in range(n): if digits[i] != 0 or i < j: continue j = i while j < n and digits[j] == 0: j += 1 r = j - i answer += r ...
vfc_47245
{ "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": "7 6 4\n3 5 0 4\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10 5 6\n3 2 0 5 6 1\n", "output": "5\n", "type": "stdin_stdout" }, { "fn_name": nu...
code_contests
verifiable_code
289_C. Polo the Penguin and Strings
Solve the following coding problem using the programming language python: Little penguin Polo adores strings. But most of all he adores strings of length n. One day he wanted to find a string that meets the following conditions: 1. The string consists of n lowercase English letters (that is, the string's length eq...
```python def fastio(): import sys from io import StringIO from atexit import register global input sys.stdin = StringIO(sys.stdin.read()) input = lambda : sys.stdin.readline().rstrip('\r\n') sys.stdout = StringIO() register(lambda : sys.__stdout__.write(sys.stdout.getvalue())) fastio() MOD = 10**9 + 7 I = la...
vfc_47257
{ "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": "7 4\n", "output": "ababacd\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 7\n", "output": "-1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "...
code_contests
verifiable_code
314_C. Sereja and Subsequences
Solve the following coding problem using the programming language python: Sereja has a sequence that consists of n positive integers, a1, a2, ..., an. First Sereja took a piece of squared paper and wrote all distinct non-empty non-decreasing subsequences of sequence a. Then for each sequence written on the squared p...
```python from sys import stdin def main(): n = int(stdin.readline()) a = map(int, stdin.readline().split()) b = [0] * (1 << 20) def get(x): res = 0 while x > 0: res += b[x] x &= (x - 1) return res def add(x, v): while x < 1 << 20: ...
vfc_47261
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1 2 2\n", "output": "13\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n42\n", "output": "42\n", "type": "stdin_stdout" }, { "fn_name": null, "input":...
code_contests
verifiable_code
336_E. Vasily the Bear and Painting Square
Solve the following coding problem using the programming language python: Vasily the bear has two favorite integers n and k and a pencil. Besides, he's got k jars with different water color paints. All jars are numbered in some manner from 1 to k, inclusive. The jar number i contains the paint of the i-th color. Ini...
vfc_47265
{ "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": "0 1\n", "output": "8\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
382_E. Ksenia and Combinatorics
Solve the following coding problem using the programming language python: Ksenia has her winter exams. Today she is learning combinatorics. Here's one of the problems she needs to learn to solve. How many distinct trees are there consisting of n vertices, each with the following properties: * the tree is marked, t...
vfc_47273
{ "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 2\n", "output": "12\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1\n", "output": "0\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
403_D. Beautiful Pairs of Numbers
Solve the following coding problem using the programming language python: The sequence of integer pairs (a1, b1), (a2, b2), ..., (ak, bk) is beautiful, if the following statements are fulfilled: * 1 ≤ a1 ≤ b1 < a2 ≤ b2 < ... < ak ≤ bk ≤ n, where n is a given positive integer; * all numbers b1 - a1, b2 - a2, ......
vfc_47277
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n1 1\n2 1\n2 2\n3 1\n3 2\n3 3\n", "output": "1\n3\n0\n6\n2\n0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n1 1\n2 1\n2 2\n3 1\n3 2\n2 3\n", "output": "1\n3\n0\n6\n2\n0\n", ...
code_contests
verifiable_code
430_E. Guess the Tree
Solve the following coding problem using the programming language python: Iahub and Iahubina went to a picnic in a forest full of trees. Less than 5 minutes passed before Iahub remembered of trees from programming. Moreover, he invented a new problem and Iahubina has to solve it, otherwise Iahub won't give her the foo...
```python def DFS(x): for i in range(x): if(Seen[i][x]): continue if(Rem[i]>=C[x]): if(Rem[i]==C[x] and len(Children[i])==0): continue Rem[i]-=C[x] Parent[x]=i Children[i].append(x) return True for...
vfc_47281
{ "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\n1 1 1 4\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n1 1 5 2 1\n", "output": "NO", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
453_B. Little Pony and Harmony Chest
Solve the following coding problem using the programming language python: Princess Twilight went to Celestia and Luna's old castle to research the chest from the Elements of Harmony. <image> A sequence of positive integers bi is harmony if and only if for every two elements of the sequence their greatest common divi...
vfc_47285
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 4, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n1 6 4 2 8\n", "output": "1 5 3 1 8 \n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
475_F. Meta-universe
Solve the following coding problem using the programming language python: Consider infinite grid of unit cells. Some of those cells are planets. Meta-universe M = {p1, p2, ..., pk} is a set of planets. Suppose there is an infinite row or column with following two properties: 1) it doesn't contain any planet pi of me...
vfc_47289
{ "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\n0 0\n0 2\n2 0\n2 1\n2 2\n", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "8\n0 0\n1 0\n0 2\n0 3\n3 0\n3 1\n2 3\n3 3\n", "output": "1", "type": "stdin_stdout" ...
code_contests
verifiable_code
49_A. Sleuth
Solve the following coding problem using the programming language python: Vasya plays the sleuth with his friends. The rules of the game are as follows: those who play for the first time, that is Vasya is the sleuth, he should investigate a "crime" and find out what is happening. He can ask any questions whatsoever th...
```python s = input() for x in s: if x != ' ' and x != '?': t = x if t in 'aeiouyAEIOUY': print('YES') else: print('NO') ```
vfc_47293
{ "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": "Is it an apple?\n", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "Is it a banana ?\n", "output": "YES", "type": "stdin_stdout" }, { "fn_name": ...
code_contests
verifiable_code
523_C. Name Quest
Solve the following coding problem using the programming language python: A Martian boy is named s — he has got this name quite recently from his parents for his coming of age birthday. Now he enjoys looking for his name everywhere. If he sees that he can obtain his name from some string by removing zero or more lette...
```python import sys count = 0 matrix = [] for line in sys.stdin: if count == 0: pattern = line.strip() count += 1 else: s = line.strip() dp1 = [0 for i in range(len(s))] dp2 = [0 for i in range(len(s))] i = 0 j = 0 while i < len(pattern) and j < len(s): if pattern[i] == s[j]: ...
vfc_47297
{ "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": "mars\nsunvenusearthmarsjupitersaturnuranusneptune\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "aba\nbaobababbah\n", "output": "2\n", "type": "stdin_stdout" ...
code_contests
verifiable_code
54_A. Presents
Solve the following coding problem using the programming language python: The Hedgehog likes to give presents to his friend, but no less he likes to receive them. Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in th...
```python def searchInRange(arr: list, start: int, end: int) -> int: for i in range(start, end + 1): if i in arr: return i return -1 n, k = [int(item) for item in input().split(' ')] holidays = [int(item) for item in input().split(' ')] del holidays[:1] ans, start, end = 0, 1, k while sta...
vfc_47301
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10 1\n3 6 7 8\n", "output": "10\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 2\n1 3\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "...
code_contests
verifiable_code
576_B. Invariance of Tree
Solve the following coding problem using the programming language python: A tree of size n is an undirected connected graph consisting of n vertices without cycles. Consider some tree with n vertices. We call a tree invariant relative to permutation p = p1p2... pn, if for any two vertices of the tree u and v the cond...
```python def read_data(): n = int(input()) ps = list(map(int, input().split())) return n, ps def solve(n, ps): ps = [p - 1 for p in ps] cycles = [0] * n roots = [] has_odd_cycle = False for i in range(n): if cycles[i] > 0: continue q = ps[i] cycle = ...
vfc_47305
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n3 1 2\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n4 3 2 1\n", "output": "YES\n1 4\n1 2\n4 3\n", "type": "stdin_stdout" }, { "fn_name":...
code_contests
verifiable_code
61_D. Eternal Victory
Solve the following coding problem using the programming language python: Valerian was captured by Shapur. The victory was such a great one that Shapur decided to carve a scene of Valerian's defeat on a mountain. So he had to find the best place to make his victory eternal! He decided to visit all n cities of Persia ...
```python import sys def solve(): n, = rv() edges = [list() for _ in range(n)] for i in range(n - 1): x, y, w, = rv() edges[x - 1].append((y - 1, w)) edges[y - 1].append((x - 1, w)) res = dfs(0, -1, edges) print(res[0] * 2 - res[1]) def dfs(cur, prev, edges): total, sing...
vfc_47313
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1 2 3\n2 3 4\n", "output": "7", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
63_C. Bulls and Cows
Solve the following coding problem using the programming language python: The "Bulls and Cows" game needs two people to play. The thinker thinks of a number and the guesser tries to guess it. The thinker thinks of a four-digit number in the decimal system. All the digits in the number are different and the number may...
```python import sys def solve(): n, = rv() works = 0 lastworks = -1 guesses = list() for i in range(n): a, b, c, = rv() acopy = a charcount = [0] * 10 for x in range(4): charcount[acopy % 10] += 1 acopy //= 10 guesses.append((tolist(a...
vfc_47317
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n1263 1 2\n8103 2 1\n", "output": "Need more data", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n0123 1 1\n4567 1 2\n", "output": "Incorrect data", "type": "stdin_stdout" ...
code_contests
verifiable_code
669_A. Little Artem and Presents
Solve the following coding problem using the programming language python: Little Artem got n stones on his birthday and now wants to give some of them to Masha. He knows that Masha cares more about the fact of receiving the present, rather than the value of that present, so he wants to give her stones as many times as...
```python print((2*int(input())+1)//3) # Made By Mostafa_Khaled ```
vfc_47321
{ "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\n", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n", "output": "1", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
690_D1. The Wall (easy)
Solve the following coding problem using the programming language python: "The zombies are lurking outside. Waiting. Moaning. And when they come..." "When they come?" "I hope the Wall is high enough." Zombie attacks have hit the Wall, our line of defense in the North. Its protection is failing, and cracks are showi...
```python # 690 D1 r,c = [int(i) for i in input().split()] for i in range(r-1): input() s = input() segs = 0 prev = '.' for x in s: if x=='B' and prev =='.': segs += 1 prev = x print(segs) ```
vfc_47325
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 0, 'nanos': 500000000}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10 7\n.......\n.......\n.......\n.......\n.......\n.......\n.......\n.......\n...B...\nB.BB.B.\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 7\n.......\n.......\n.BB.B...
code_contests
verifiable_code
714_C. Sonya and Queries
Solve the following coding problem using the programming language python: Today Sonya learned about long integers and invited all her friends to share the fun. Sonya has an initially empty multiset with integers. Friends give her t queries, each of one of the following type: 1. + ai — add non-negative integer ai t...
```python # Problem : C. Sonya and Queries # Contest : Codeforces Round #371 (Div. 2) # URL : https://codeforces.com/contest/714/problem/C # Memory Limit : 256 MB # Time Limit : 1000 ms # Powered by CP Editor (https://github.com/cpeditor/cpeditor) """ // Author : snape_here - Susanta Mukherjee """ from __fut...
vfc_47329
{ "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": "12\n+ 1\n+ 241\n? 1\n+ 361\n- 241\n? 0101\n+ 101\n? 101\n- 101\n? 101\n+ 4000\n? 0\n", "output": "2\n1\n2\n1\n1\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
734_F. Anton and School
Solve the following coding problem using the programming language python: Anton goes to school, his favorite lessons are arraystudying. He usually solves all the tasks pretty fast, but this time the teacher gave him a complicated one: given two arrays b and c of length n, find array a, such that: <image> where a and...
```python def f(): n, = map(int,raw_input().split()) B = map(int,raw_input().split()) C = map(int,raw_input().split()) D = [B[i]+C[i] for i in xrange(n)] t = sum(D) if n == 1 and B[0] != C[0]: print -1 return if t % 2 or t % (n*2): print -1 return tA = t /...
vfc_47333
{ "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": "4\n6 8 4 4\n16 22 10 10\n", "output": "3 5 1 1 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n8 25 14 7 16\n19 6 9 4 25\n", "output": "-1\n", "type": "stdin_stdout" }, ...
code_contests
verifiable_code
758_F. Geometrical Progression
Solve the following coding problem using the programming language python: For given n, l and r find the number of distinct geometrical progression, each of which contains n distinct integers not less than l and not greater than r. In other words, for each progression the following must hold: l ≤ ai ≤ r and ai ≠ aj , w...
```python Primes = [2, 3, 5, 7] def check (a, b) : for pr in Primes : if a % pr == 0 and b % pr == 0 : return False while (b) : a %= b a ^= b b ^= a a ^= b return a == 1 n, l, r = map(int, input().split()) if n == 1 : ans = r - l + 1 elif n == 2 : ans = (r - l + 1) * (r - l) else : n -= 1 l -= 1 ...
vfc_47337
{ "difficulty": "12", "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 1 10\n", "output": "8\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
77_D. Domino Carpet
Solve the following coding problem using the programming language python: ...Mike the TV greets you again! Tired of the monotonous furniture? Sick of gray routine? Dreaming about dizzying changes in your humble abode? We have something to offer you! This domino carpet for only $99.99 will change your life! You can l...
```python import sys import string f = sys.stdin #f = open("input.txt") n,m = map(int, f.readline().split()) lines = f.readlines() dominoes = [] for i in xrange(n): row = [] for u in xrange(m): cur = "" for t in xrange(3): cur += lines[i*4+1+t][u*4+1:u*4+4] sum = cur.count('O') orient = 3 if sum == 2 o...
vfc_47341
{ "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 4\n#################\n#O..#...#O.O#...#\n#.O.#.O.#.O.#...#\n#..O#...#O.O#...#\n#################\n#O.O#OOO#O.O#...#\n#.O.#...#...#.O.#\n#O.O#OOO#O.O#...#\n#################\n#O.O#...#O.O#...#\n#...#...#...#.O.#\n#O.O#...#O.O#...#...
code_contests
verifiable_code
803_C. Maximal GCD
Solve the following coding problem using the programming language python: You are given positive integer number n. You should create such strictly increasing sequence of k positive numbers a1, a2, ..., ak, that their sum is equal to n and greatest common divisor is maximal. Greatest common divisor of sequence is maxi...
```python from collections import deque from math import sqrt n,k = map(int, input().split()) sum_k = k*(k+1)/2 if(sum_k>n): print(-1) else: pos = deque() for x in range(int(sqrt(n)), 0, -1): if(n%x==0): pos.appendleft(x) if(x*x!= n): pos.append(int(n/x)) ...
vfc_47345
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "8 2\n", "output": "2 6 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 3\n", "output": "-1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 3...
code_contests
verifiable_code
828_A. Restaurant Tables
Solve the following coding problem using the programming language python: In a small restaurant there are a tables for one person and b tables for two persons. It it known that n groups of people come today, each consisting of one or two people. If a group consist of one person, it is seated at a vacant one-seater...
```python _,o,d=map(int,input().split()) h=0 a=list(map(int,input().split())) n=0 for i in a: if i==1: if o>0: o-=1 elif d>0: d-=1 h+=1 elif h>0: h-=1 else: n+=1 elif i==2: if d>0: d-=1 else: ...
vfc_47349
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 1 1\n1 1 2 1\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 1 2\n1 2 1 1\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
84_B. Magical Array
Solve the following coding problem using the programming language python: Valery is very interested in magic. Magic attracts him so much that he sees it everywhere. He explains any strange and weird phenomenon through intervention of supernatural forces. But who would have thought that even in a regular array of numbe...
```python from sys import stdin, stdout from math import factorial n = int(stdin.readline()) values = list(map(int, stdin.readline().split())) ans = 0 cnt = 1 for i in range(1, n): if values[i] != values[i - 1]: ans += cnt * (cnt + 1) // 2 cnt = 1 else: cnt += 1 ans += cnt * (cnt + 1)...
vfc_47353
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n2 1 1 4\n", "output": "5", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
871_D. Paths
Solve the following coding problem using the programming language python: You are given a positive integer n. Let's build a graph on vertices 1, 2, ..., n in such a way that there is an edge between vertices u and v if and only if <image>. Let d(u, v) be the shortest distance between u and v, or 0 if there is no path ...
vfc_47357
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 4, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n", "output": "8\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n", "output": "44\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "999\n", ...
code_contests
verifiable_code
898_D. Alarm Clock
Solve the following coding problem using the programming language python: Every evening Vitalya sets n alarm clocks to wake up tomorrow. Every alarm clock rings during exactly one minute and is characterized by one integer ai — number of minute after midnight in which it rings. Every alarm clock begins ringing at the ...
```python n, m, k = map(int,input().split()) a = list(map(int,input().split())) a.sort() vis = [] for i in range(n): vis.append(0) ans = l = r = 0 cnt = 1 while(r < n): while(a[r]-a[l]+1 > m): if(vis[l] == 0): cnt -= 1 l += 1 if cnt >= k: ans += 1 vis[r] = 1; cnt -= 1...
vfc_47361
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 2 2\n1 3\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 3 2\n3 5 1\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "...
code_contests
verifiable_code
919_E. Congruence Equation
Solve the following coding problem using the programming language python: Given an integer x. Your task is to find out how many positive integers n (1 ≤ n ≤ x) satisfy $$$n ⋅ a^n ≡ b (mod\;p), where a, b, p$$$ are all known constants. Input The only line contains four integers a,b,p,x (2 ≤ p ≤ 10^6+3, 1 ≤ a,b < p,...
```python import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = 'x' in file.mode or 'r' not in file.mode self.write = self.buffer.write i...
vfc_47365
{ "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 6 7 13\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "233 233 10007 1\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
946_D. Timetable
Solve the following coding problem using the programming language python: Ivan is a student at Berland State University (BSU). There are n days in Berland week, and each of these days Ivan might have some classes at the university. There are m working hours during each Berland day, and each lesson at the university l...
```python n, m, k = map(int, input().split()) DATA = [input() for i in range(n)] #dp[n_day][used_cost] #ans = min(dp[n_day][used_cost] for used_cost in range(k + 1)) #dp[n_day][used_cost] := min(dp[n_day - 1][prev_cost] + cost(pay used_cost - prev_cost in n_day) for prev_cost in range(used_cost + 1)) INF = 1 << 60 dp ...
vfc_47369
{ "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 5 0\n01001\n10110\n", "output": "8", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 5 1\n01001\n10110\n", "output": "5", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
995_A. Tesla
Solve the following coding problem using the programming language python: Allen dreams of one day owning a enormous fleet of electric cars, the car of the future! He knows that this will give him a big status boost. As Allen is planning out all of the different types of cars he will own and how he will arrange them, h...
```python n, k = map(int, input().split()) grid = [ list(map(int, input().split())) for _ in range(4) ] possible = True if all(c != 0 for cars in (grid[1], grid[2]) for c in cars): if all(a != b for (a, b) in zip(grid[0], grid[1])): if all(a != b for (a, b) in zip(grid[3], grid[2])): ...
vfc_47377
{ "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": "4 5\n1 2 0 4\n1 2 0 4\n5 0 0 3\n0 5 0 3\n", "output": "6\n1 1 1\n2 1 2\n4 1 4\n3 4 4\n5 3 2\n5 4 2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 2\n1\n1\n2\n2\n", "output": "2\n1...
code_contests
verifiable_code
bad-day
Solve the following coding problem using the programming language python: The BITians are furious that their lift stops working frequently .Adding to this, there are 7 floors in BIT which becomes really tedious to climb. Vikas has to attend the class in 5th floor. He decides to take a step of 1 or 2 each...
```python import math f=math.factorial t=int(input()) while t>0: n=int(raw_input()) c=0; for i in range (0, n+1): for j in range (0, n+1): if ((1*i)+(2*j))==n: c+=f(i+j)/(f(i)*f(j)) print c t-=1 ```
vfc_47381
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n2\n4\n\nSAMPLE", "output": "2\n5\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n2\n4\n\nSAMPLF", "output": "2\n5\n", "type": "stdin_stdout" }, { "fn_name":...
code_contests
verifiable_code
chotu-and-palindromic-strings
Solve the following coding problem using the programming language python: Everyone knows that chotu likes palindromic strings. One day, he found 2 ordinary strings s1 and s2. Now he wonders if he could make a palindrome by concatenating s1 and s2 in any order. i.e if s1s2 or s2s1 is a palindrome. Input First line of...
```python import sys n=int(raw_input()) i=0 while(i<=n-1): s1=raw_input() s2=raw_input() s3=s1+s2 s4=s2+s1 if(s3==s3[:: -1] or s4==s4[:: -1]): print("YES") else: print("NO") i+=1 ```
vfc_47385
{ "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\nbaba\nxy\nzw\n\nSAMPLE", "output": "YES\nNO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\naba\nbaba\nxy\nzw\n\nELPMAS", "output": "YES\nNO\n", "type": "stdin_stdou...
code_contests
verifiable_code
easy-to-debug
Solve the following coding problem using the programming language python: If the given input positive integer is equal to the sum of its proper positive divisors then it will form a triangular array of numbers in which those at the ends of the rows are 1 and each of the others is the sum of the nearest two numbers in...
```python n = int(raw_input()) k=1 s=0 while(k<n): if(n%k==0): s+=k k+=1 if s==n: arr = [[0 for _ in range (n+1)] for _ in range (n+1)] for line in range (0,n+1): s=[] for i in range (0,line): if line==i or i==0: arr[line][i]=1 else: arr[line][i] = arr[line-1][i-1]+arr[line-1][i] s.append(...
vfc_47389
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n\nSAMPLE", "output": "1\n11\n121\n1331\n14641\n15101051", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n\nELPMAS", "output": "1\n11\n121\n1331\n14641\n15101051\n", "type": ...
code_contests
verifiable_code
hasan-and-trip-1
Solve the following coding problem using the programming language python: Hasan has finally finished his final exams and he decided to go in a trip among cities in Syria. There are N cities in Syria and they are numbered from 1 to N, each city has coordinates on plane, i-th city is in (Xi, Yi). Hasan is in first cit...
```python def d(x,y): return ((x[0]-y[0])**2+(x[1]-y[1])**2)**0.5 n=int(raw_input()) l=[] for i in xrange(n): i,j,k=map(int,raw_input().split()) l.append((i,j,k)) dp=[-2494444444444]*(n+1) #F=0 #L=n-1 dp[0]=l[0][2] for i in xrange(1,n): for j in xrange(0,i): dp[i]=max(dp[i],dp[j]-d(l[i],l[j])) ...
vfc_47393
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n0 0 1\n3 1 1\n6 0 9\n\nSAMPLE", "output": "4.675445\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n0 0 2\n3 1 1\n6 0 9\n\nSAMPLE", "output": "5.675445\n", "type": "stdin...
code_contests
verifiable_code
lovely-couple-1
Solve the following coding problem using the programming language python: All living beings on this extra-ordinary planet have some goodness value that tells their worth. Rajat and Shreya are a couple on this planet who love each other. Both of them have a goodness value A and B respectively. One day Rajat found an a...
```python from fractions import gcd def modifySieve(n): for i in xrange(2, n): if not prime[i]: for j in xrange(i * 2, n, i): prime[j] += 1 prime = [0]*1000000 modifySieve(1000000) for chk in xrange(input()): a,b = map(int, raw_input().split()) x = a*b/gcd(a,b) if prime[x...
vfc_47397
{ "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 3\n2 4\n4 33\n\n\nSAMPLE", "output": "Yes\nNo\nYes", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
mystery-9-1
Solve the following coding problem using the programming language python: Solve the mystery. Input: First line contains a single integer denoting number of test cases(T). Next T lines have one test case per line. Each test case is a string of alphabets [a-z]. Output: Print answer to each test case in an individual li...
```python t = int(raw_input()) while(t>0): t -= 1 a = raw_input() if(a == a[::-1]): print(ord(a[len(a)/2])) else: print(-1) ```
vfc_47401
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\nmalayalam\nariyama\nalla\nbrook\nkurruk\n\nSAMPLE", "output": "121\n-1\n108\n-1\n114\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "39\ntwxynczcnyxwt\nrayyar\ngkoxntfmtwlzhjdjhzlwtmftn...
code_contests
verifiable_code
problem-3-16
Solve the following coding problem using the programming language python: Sanket being a stud, wants to gift chocolates on "Chocolate Day" to a girl. He has N chocolates of different types. The chocolates are numbered from 1 to N. There are K types of chocolates, numbered from 1 to K. Also, there are infinite chocola...
```python for i in xrange(input()): n,k = map(int,raw_input().split()) a = map(int,raw_input().split()) b = list(set(a)) m=0 for j in b: temp = a.count(j) if temp>m: m = temp print len(a)-m ```
vfc_47405
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n3 2\n1 1 2\n\nSAMPLE", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n3 2\n1 1 1\n\nSAMPLE", "output": "0\n", "type": "stdin_stdout" }, { "fn_...
code_contests
verifiable_code
sequences-everywhere
Solve the following coding problem using the programming language python: Let's consider some integer X. We will call the following sequence S a sequence generated by X: for i = 1: S[i] = X for i > 1: S[i] equals to the minimal positive integer such that S[i] is not a divisor of S[i - 1]. If there is no such integer ...
```python from fractions import gcd def seq(x): for i in xrange(1, x): if x % i != 0: return [x] + seq(i) return [x] def lcm(a, b): return a * b / gcd(a, b) A, B = map(int, raw_input().split()) S = [1] * 42 for i in xrange(1, 42): for j in xrange(1, i): if i % j != 0: ...
vfc_47409
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 6\n\nSAMPLE", "output": "12", "type": "stdin_stdout" }, { "fn_name": null, "input": "66310194949619470 78796097193844620", "output": "32270128957793445", "type": "stdin_stdout" } ...
code_contests
verifiable_code
thanks-giving
Solve the following coding problem using the programming language python: Level 1 Sometimes what happens during SBG slot booking is we forgot to book our slot and mess up. But few clubs are generous enough to change their timings to make sure our event doesn't get postponed, hence a special thanks to them :). Anywa...
```python ''' # Read input from stdin and provide input before running code name = raw_input('What is your name?\n') print 'Hi, %s.' % name ''' #print 'Hello World!' l=list(raw_input()) k=max(l,key=l.count) if k in "head rush" and k in"cubing club": print"Thanks both" elif k in "head rush": print "Thanks head rush" ...
vfc_47413
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "ahhc\n\nSAMPLE", "output": "Thanks head rush\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "jqujvortzaxbickkbvblqymdmpddsrfcjsldikhtbmenkujogepsoqstovggfuxfnkvownssetycphpnximyourmgizkieu...
code_contests
verifiable_code
xaviers-challenge
Solve the following coding problem using the programming language python: Xavier asks his friend to perform a particular task.The task is to find out the ASCII value of each character of a given STRING and then add them up to find the weight of the given string as 'W',now after finding out the weight his task is to di...
```python for _ in xrange(input()): a=list(raw_input()) l=len(a) tot=0 i=0 while i<l: tot=tot+ord(a[i]) i=i+1 k=tot/l if k%2==0: print ''.join(a) else: fin=str( ''.join(a)) print fin[::-1] ```
vfc_47417
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\nxyzabc\n\nSAMPLE", "output": "cbazyx\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\ncbazyx\n\nSAMPLE", "output": "xyzabc\n", "type": "stdin_stdout" }, { "f...
code_contests
verifiable_code
p03974 CODE FESTIVAL 2016 qual B - Lexicographical disorder
Solve the following coding problem using the programming language python: There are N strings of lowercase alphabet only. The i-th string is S_i. Every string is unique. Provide answers for the Q queries below. The i-th query has the following format: Query: An integer k_i and a string p_{i,1}p_{i,2}...p_{i,26} that...
```python import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines from collections import defaultdict """ ・trie木 ・各ノードから、アルファベットごとの子ノードの番号 ・親ノードの番号 """ N = int(readline()) data = tuple(read().split()) S = data[:N] Q = int(data[N]) query_target = list(map(in...
vfc_47457
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 536870912, "problem_url": null, "time_limit": "{'seconds': 6, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "8\nabrakatabra\nabadaba\nabracadabra\natcoder\ngrand\ncontest\nababa\na\n6\n3 abcdefghijklmnopqrstuvwxyz\n6 qwertyuiopasdfghjklzxcvbnm\n8 poiuytrewqlkjhgfdsamnbvcxz\n2 qazwsxedcrfvtgbyhnujmikolp\n1 plokmijnuhbygvtfcrdxeszwaq\n4 mnb...
code_contests
verifiable_code
p00063 Palindrome
Solve the following coding problem using the programming language python: There is data of up to 100 characters per line, consisting of half-width alphabetic character strings. Some lines are symmetric (same whether read from the left edge or the right edge). Create a program that reads this data and outputs the numbe...
```python # coding: utf-8 # Your code here! n = 0 while True: try: t = str(input()) if t == t[::-1]: n += 1 except EOFError: break print(n) ```
vfc_47461
{ "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": "abcba\nsx\nabcddcba\nrttrd", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "abcba\nsx\nabcddcba\nrstrd", "output": "2\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
p00195 What is the Most Popular Shop in Tokaichi?
Solve the following coding problem using the programming language python: In Aizuwakamatsu City, there is a first city called "Tokaichi" on January 10th every year. This Tokaichi has a history of about 600 years and is the largest first city in the Aizu region. It is also well known that Okiagari-koboshi, a familiar l...
```python while True: try: n = [[0,"A"],[0,"B"],[0,"C"],[0,"D"],[0,"E"]] for i in range(5): n[i][0] = sum(list(map(int,input().split()))) n.sort(reverse = True) print(n[0][1],n[0][0]) except: break ```
vfc_47465
{ "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": "1593 4311\n4321 2155\n1256 6421\n5310 1455\n2152 5421\n1549 3386\n4528 3719\n1234 4321\n3330 3109\n2739 2199\n0 0", "output": "C 7677\nB 8247", "type": "stdin_stdout" }, { "fn_name": null, "input": "...
code_contests
verifiable_code
p00545 Walking in JOI Kingdom
Solve the following coding problem using the programming language python: problem The JOI country has one long enough road running east to west. The royal palace of JOI country is along the road, and the position along the road in JOI country is represented by the integer A. When A = 0, it represents the position of ...
```python import sys readline = sys.stdin.readline write = sys.stdout.write N, T, Q = map(int, readline().split()) P = [list(map(int, readline().split())) for i in range(N)] QS = [P[int(readline())-1] for i in range(Q)] prv = 1 R = {} A = []; B = [] for x, t in P: if prv == t: if t == 1: A.appe...
vfc_47473
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 268435456, "problem_url": null, "time_limit": "{'seconds': 8, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 5 3\n-8 1\n-4 2\n-2 2\n4 2\n10 1\n1\n3\n5", "output": "-6\n-6\n15", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 5 3\n-8 1\n-4 2\n-2 2\n4 0\n10 1\n1\n3\n5", "output": "-6\n-6\n15\...
code_contests
verifiable_code
p00848 Sum of Different Primes
Solve the following coding problem using the programming language python: A positive integer may be expressed as a sum of different prime numbers (primes), in one way or another. Given two positive integers n and k, you should count the number of ways to express n as a sum of k different primes. Here, two ways are con...
```python primes = [] flag = [0 for i in range(1121)] for i in range(2, 1121): if flag[i] == 0: primes.append(i) count = 2 while i * count < 1121: flag[i * count] = 1 count += 1 dp = [[0 for i in range(15)] for j in range(1121)] dp[0][0] = 1 for p in primes: for k in range(13,...
vfc_47481
{ "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": "24 3\n24 2\n2 1\n1 1\n4 2\n18 3\n17 1\n17 3\n17 4\n100 5\n1000 10\n1120 14\n0 0", "output": "2\n3\n1\n0\n0\n2\n1\n0\n1\n55\n200102899\n2079324314", "type": "stdin_stdout" }, { "fn_name": null, "input...
code_contests
verifiable_code
p00980 Estimating the Flood Risk
Solve the following coding problem using the programming language python: Estimating the Flood Risk Mr. Boat is the owner of a vast extent of land. As many typhoons have struck Japan this year, he became concerned of flood risk of his estate and he wants to know the average altitude of his land. The land is too vast ...
```python #!/usr/bin/python3 import os import sys def main(): W, D, N = read_ints() M = [tuple(read_ints()) for _ in range(N)] ans = solve(W, D, N, M) if ans is None: print('No') else: print(ans) def solve(W, D, N, M): INF = 999 H = [[INF] * W for _ in range(D)] hma...
vfc_47485
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 268435456, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 4 2\n1 1 10\n5 4 3", "output": "130", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 4 2\n2 1 10\n5 4 3", "output": "No\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p01112 Playoff by all the teams
Solve the following coding problem using the programming language python: Playoff by all the teams The Minato Mirai Football Association hosts its annual championship as a single round-robin tournament, in which each team plays a single match against all the others. Unlike many other round-robin tournaments of footba...
```python from itertools import combinations as comb def main(): while True: n = int(input()) if n ==0:break m = int(input()) result = [[None] * n for _ in range(n)] for _ in range(m): x, y = map(int, input().split()) x -= 1 y -= 1 result[x][y] = True result[y][x] = ...
vfc_47489
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 268435456, "problem_url": null, "time_limit": "{'seconds': 8, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n3\n3 2\n4 1\n5 1\n3\n1\n1 2\n3\n2\n1 2\n3 2\n5\n4\n4 1\n4 2\n5 1\n5 2\n5\n3\n4 1\n4 2\n5 1\n5\n4\n3 2\n4 1\n5 1\n5 2\n9\n11\n6 1\n6 4\n7 2\n7 3\n7 4\n8 2\n8 3\n8 4\n9 1\n9 3\n9 5\n9\n10\n6 1\n6 4\n7 2\n7 3\n7 4\n8 2\n8 3\n8 4\n9...
code_contests
verifiable_code
p01250 Pi is Three
Solve the following coding problem using the programming language python: π (spelled pi in English) is a mathematical constant representing the circumference of a circle whose di- ameter is one unit length. The name π is said to come from the first letter of the Greek words περιφέρεια (meaning periphery) and περίμετρο...
```python from math import pi while 1: r=float(input()) if r==0:break n=d=1 while abs(n/d-pi)>r: if n/d<pi:n+=1 else: d+=1 print('%d/%d'%(n,d)) ```
vfc_47493
{ "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": "0.15\n0.05\n0.0", "output": "3/1\n19/6", "type": "stdin_stdout" }, { "fn_name": null, "input": "1.052205526162189\n0.05\n0.0", "output": "3/1\n19/6\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p01411 Entangled with Lottery
Solve the following coding problem using the programming language python: Training is indispensable for achieving good results at ICPC. Rabbit wants to win at ICPC, so he decided to practice today as well. Today's training is to use the Amidakuji to improve luck by gaining the ability to read the future. Of course, n...
```python import sys readline = sys.stdin.readline write = sys.stdout.write def solve(): H, N, P, M, K = map(int, readline().split()) A = [0]*H for i in range(M): a, b = map(int, readline().split()) A[a-1] = b S = [[0]*N for i in range(K+1)] S[0][P-1] = 1 T = [[0]*N for i in ra...
vfc_47497
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "9 4 3 2 3\n2 1\n7 3", "output": "0.375661376", "type": "stdin_stdout" }, { "fn_name": null, "input": "9 4 3 2 1\n2 1\n7 3", "output": "0.571428571", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
p01565 Move on Dice
Solve the following coding problem using the programming language python: There is a cube on a rectangle map with H-rows and W-columns grid. Two special squares a start and a goal are marked on the map. Initially, the cube is on the start square. Let's repeat to roll it and take it to the goal square. Rolling the cube...
vfc_47501
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 5, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 3\n->|\n..v\n.^<\nJAG\n2012\nSUMMER\nHOGE\nHOGE\nCAMP\n1 1\n2 2", "output": "JAGSUMMERCAMP2012JAGSUMMER2012", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p02002 Expression
Solve the following coding problem using the programming language python: problem Given the formula $ S $ of length $ N $. The formula is in the format shown in BNF below. <expr> :: = <number> | <expr> <op> <expr> <op> :: = ‘^’ | ‘&’ | ‘|’ <number> represents an integer greater than or equal to $ 0 $ and less t...
vfc_47513
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 268435456, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7\n9^2&1|2\n4\n0 6\n0 2\n2 6\n4 4", "output": "3\n11\n2\n1", "type": "stdin_stdout" }, { "fn_name": null, "input": "7\n9^2&1|2\n1\n0 6\n0 2\n2 6\n4 4", "output": "3\n", "type": "stdin_std...
code_contests
verifiable_code
p02146 Averaging
Solve the following coding problem using the programming language python: Problem There are $ N $ islands and $ N-1 $ bridges in Aiz, and each island is assigned a number from $ 1 $ to $ N $. The $ i $ th bridge connects the island $ u_i $ and the island $ v_i $ in both directions, and islanders can use the bridge to...
vfc_47517
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 536870912, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n4 0 4 0 0\n1 2\n1 3\n1 4\n2 5", "output": "7", "type": "stdin_stdout" }, { "fn_name": null, "input": "7\n0 7 2 5 0 3 0\n1 2\n1 3\n1 4\n2 5\n3 6\n3 7", "output": "10", "type": "stdin_st...
code_contests
verifiable_code
p02287 Complete Binary Tree
Solve the following coding problem using the programming language python: A complete binary tree is a binary tree in which every internal node has two children and all leaves have the same depth. A binary tree in which if last level is not completely filled but all nodes (leaves) are pushed across to the left, is also...
```python k,e=' key = ',', ' input() A=[0]+input().split() H=len(A) for i in range(1,H): print(f'node {i}: key = {A[i]}, {"parent"+k+A[i//2]+e if i>1 else""}{"left"+k+A[2*i]+e if 2*i<H else""}{"right"+k+A[2*i+1]+e if 2*i+1<H else""}') ```
vfc_47521
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n7 8 1 2 3", "output": "node 1: key = 7, left key = 8, right key = 1,\nnode 2: key = 8, parent key = 7, left key = 2, right key = 3,\nnode 3: key = 1, parent key = 7,\nnode 4: key = 2, parent key = 8,\nnode 5: key = 3, pare...
code_contests
verifiable_code
botm
Solve the following coding problem using the programming language python: Problem statement A lazy guy in UVCE is designing a robot that could collect all useful things from different places and put them in one place. In its testing stage robot is given a task. 10^5 boxes are arranged is straight line and they numbe...
```python for _ in xrange(input()): n=input() s=map(int,raw_input().split()) midpos=sum(s)/n moves=0 for i in s: moves+=abs(i-midpos) print moves ```
vfc_47529
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n5\n1 2 3 4 5\n6\n1 2 3 4 5 6", "output": "6\n9", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
collide
Solve the following coding problem using the programming language python: Did you hear about the Nibiru collision ? It is a supposed disastrous encounter between the earth and a large planetary object. Astronomers reject this idea. But why listen to other people's beliefs and opinions. We are coders above all, so what...
```python # codechef - easy - collide dirTable = {} dirTable["R"] = (1,0) dirTable["L"] = (-1,0) dirTable["D"] = (0,-1) dirTable["U"] = (0,1) def readCoordinates(): strX, strY, strDir = raw_input().split() x = int(strX) y = int(strY) dx,dy = dirTable[strDir] return x,y, dx,dy t = int(raw_input()...
vfc_47533
{ "difficulty": "2", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n0 0 R\n2\n1 -2 U\n2 2 D\n1 1 U\n1\n1 0 U\n0 0 R\n1\n3 0 L", "output": "2.0\nSAFE\n1.5\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n0 0 R\n2\n2 -2 U\n2 2 D\n1 1 U\n1\n1 0 U\n0 0 R\...
code_contests
verifiable_code
gardensq
Solve the following coding problem using the programming language python: Chef has just finished the construction of his new garden. He has sown the garden with patches of the most beautiful carpet grass he could find. He has filled it with patches of different color and now he wants to evaluate how elegant his garden...
```python T=int(raw_input()) for t in range(T): s=map(int,raw_input().split()) n=s[0] m=s[1] l=[] for i in range(n): l.append(raw_input()) c=0 for i in range(1,n,1): for j in range(n): for k in range(m): if(j+i<n and k+i<m): if(l[j][k]==l[j][k+i] and l[j][k]==l[j+i][k] and l[j][k]==l[j+i][k+i]): ...
vfc_47537
{ "difficulty": "2", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n2 2\naa\naA\n3 3\naba\nbab\naba\n4 4\naabb\naabb\nbbaa\nbbaa", "output": "0\n1\n4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n2 2\naa\naA\n3 0\naba\nbab\naba\n4 4\naabb\naabb\nbb...
code_contests
verifiable_code
lucky8
Solve the following coding problem using the programming language python: A Little Elephant from the Zoo of Lviv likes lucky numbers very much. Everybody knows that the lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and...
```python numOfTests = int(raw_input()) def computeMaxProd(N, N4, N7): if N == 0: return N4*N7 x = (N+N7-N4)/2 if x < 0: x = 0 y = x+1 elif x > N: x = N y = x else: y = x+1 return max( (x+N4)*(N-x+N7) , (y+N4)*(N-y+N7)) def...
vfc_47541
{ "difficulty": "3", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1 10\n1 100\n47 74", "output": "0\n1\n1", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
prosum
Solve the following coding problem using the programming language python: Little chef has just been introduced to the world of numbers! While experimenting with addition and multiplication operations, the little chef came up with the following problem: Given an array A of non-negative integers, how many pairs of ind...
```python cases=int(raw_input().strip()) while(cases): n=int(raw_input().strip()) a=raw_input().strip() a=map(int,a.split()) count=0 ct=0; # total=(n*(n-1))/2 for i in range(len(a)): if ( a[i]>2): count+=1 if ( a[i]==2): ct+=1 total = (count*(count-1))/2 #print count," ",ct ct= ct*count print ...
vfc_47545
{ "difficulty": "2", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n3\n3 4 5\n4\n1 1 1 1", "output": "3\n0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n3\n3 8 5\n4\n1 1 1 1", "output": "3\n0\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
testtt5
Solve the following coding problem using the programming language python: A robot named as Maestro, works on right most digit of number. For eg. 123456 is a number. Maestro would work with 6. But now, if number is 12345600. It will work with 6. Input Specification Input a variable t which is the number of test ca...
```python testcase = int(raw_input()) while testcase > 0: input = raw_input() numbers = input.replace("x","*") numbers = numbers.replace("X","*") #print numbers result = eval(numbers) if (result == 0): print "Robot hanged." else: print str(result).rstrip("0")[-1] testcase -= 1 ```
vfc_47549
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n2X3X7X5\n2X0X4X25", "output": "1\nRobot hanged.\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n2X3X6X5\n2X0X4X25", "output": "8\nRobot hanged.\n", "type": "stdin_stdout"...
code_contests
verifiable_code
1012_C. Hills
Solve the following coding problem using the programming language python: Welcome to Innopolis city. Throughout the whole year, Innopolis citizens suffer from everlasting city construction. From the window in your room, you see the sequence of n hills, where i-th of them has height ai. The Innopolis administration w...
```python ''' Hey stalker :) ''' INF = 10**10 def main(): #print = out.append ''' Cook your dish here! ''' n = get_int() li = get_list() high = [] high_li = [] for i in range(n): th = high[:] thli = high_li[:] for j in range((i)//2 + 1): k = 0 ...
vfc_47553
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n1 2 3 2 2\n", "output": "0 1 3 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n1 2 3\n", "output": "0 2 ", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
1037_C. Equalize
Solve the following coding problem using the programming language python: You are given two binary strings a and b of the same length. You can perform the following two operations on the string a: * Swap any two bits at indices i and j respectively (1 ≤ i, j ≤ n), the cost of this operation is |i - j|, that is, the...
```python def solve(n, a, b): ans = 0 i = 0 while i < n: if a[i] != b[i]: if i < n-1 and a[i+1] != b[i+1] and a[i+1] != a[i]: ans += 1 i += 2 else: ans += 1 i += 1 else: i += 1 return ans ...
vfc_47557
{ "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\n0101\n0011\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n100\n001\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
105_D. Entertaining Geodetics
Solve the following coding problem using the programming language python: The maps in the game are divided into square cells called Geo Panels. Some of these panels are painted. We shall assume that the Geo Panels without color are painted the transparent color. Besides, the map has so-called Geo Symbols. They look ...
vfc_47561
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 5\n9 0 1 1 0\n0 0 3 2 0\n1 1 1 3 0\n1 1 1 3 0\n0 1 2 0 3\n-1 1 -1 3 -1\n-1 -1 -1 0 -1\n-1 -1 -1 -1 -1\n-1 2 3 -1 -1\n-1 -1 -1 -1 2\n4 2\n", "output": " 35\n", ...
code_contests
verifiable_code
1081_E. Missing Numbers
Solve the following coding problem using the programming language python: Chouti is working on a strange math problem. There was a sequence of n positive integers x_1, x_2, …, x_n, where n is even. The sequence was very special, namely for every integer t from 1 to n, x_1+x_2+...+x_t is a square of some integer numbe...
```python # ---------------------------iye ha aam zindegi--------------------------------------------- import math import heapq, bisect import sys from collections import deque, defaultdict from fractions import Fraction mod = 10 ** 9 + 7 mod1 = 998244353 # ------------------------------warmup------------------------...
vfc_47565
{ "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\n5 11 44\n", "output": "Yes\n4 5 16 11 64 44 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n314 1592 6535\n", "output": "No\n", "type": "stdin_stdout" }, { "...
code_contests
verifiable_code
1100_E. Andrew and Taxi
Solve the following coding problem using the programming language python: Andrew prefers taxi to other means of transport, but recently most taxi drivers have been acting inappropriately. In order to earn more money, taxi drivers started to drive in circles. Roads in Andrew's city are one-way, and people are not neces...
```python import sys from operator import itemgetter readline = sys.stdin.readline def topological_sort(E, D): D = D[:] n = len(E) Q = [i for i in range(n) if D[i] == 0] L = [] while Q: p = Q.pop() L.append(p) for vf in E[p]: D[vf] -= 1 if not D[vf]: ...
vfc_47569
{ "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 7\n2 1 5\n3 2 3\n1 3 3\n2 4 1\n4 3 5\n5 4 1\n1 5 3\n", "output": "3 3\n2 6 7\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 6\n2 1 1\n5 2 6\n2 3 2\n3 4 3\n4 5 5\n1 5 4\n", "outp...
code_contests
verifiable_code
1129_B. Wrong Answer
Solve the following coding problem using the programming language python: Consider the following problem: given an array a containing n integers (indexed from 0 to n-1), find max_{0 ≤ l ≤ r ≤ n-1} ∑_{l ≤ i ≤ r} (r-l+1) ⋅ a_i. In this problem, 1 ≤ n ≤ 2 000 and |a_i| ≤ 10^6. In an attempt to solve the problem describe...
```python def compute(): from sys import stdin [k] = list(map(int, stdin.readline().split())) MAXX = 1000000 MAXN = 2000 o = [-1] k += 1 while k>0: k += 1 if k > MAXX: tosub = MAXX else: tosub = k o.append(tosub) k -= tosu...
vfc_47573
{ "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": "612\n", "output": "2\n-1 614\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "8\n", "output": "2\n-1 10\n", "type": "stdin_stdout" }, { "fn_name": null, "inp...
code_contests
verifiable_code
1149_C. Tree Generator™
Solve the following coding problem using the programming language python: Owl Pacino has always been into trees — unweighted rooted trees in particular. He loves determining the diameter of every tree he sees — that is, the maximum length of any simple path in the tree. Owl Pacino's owl friends decided to present him...
vfc_47577
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6 4\n(((())()))\n6 7\n5 4\n6 4\n7 4\n", "output": "4\n4\n4\n5\n3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 5\n(((())))\n4 5\n3 4\n5 6\n3 6\n2 5\n", "output": "4\n3\n3\n2\n4\n...
code_contests
verifiable_code
1170_C. Minus and Minus Give Plus
Solve the following coding problem using the programming language python: Everyone knows that two consecutive (adjacent) "minus" signs can be replaced with a single "plus" sign. You are given the string s, consisting of "plus" and "minus" signs only. Zero or more operations can be performed with it. In each operation...
vfc_47581
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n-+--+\n-+++\n--------\n-+--+-\n-\n+\n--\n---\n+++\n+++\n", "output": "\nYES\nYES\nNO\nNO\nYES\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1189_B. Number Circle
Solve the following coding problem using the programming language python: You are given n numbers a_1, a_2, …, a_n. Is it possible to arrange them in a circle in such a way that every number is strictly less than the sum of its neighbors? For example, for the array [1, 4, 5, 6, 7, 8], the arrangement on the left is v...
```python n = int(input()) arr = list(map(int, input().split())) arr.sort() if arr[-1] >= arr[-2] + arr[-3]: print("NO") else: print("YES") tmp = arr[-1] arr[-1] = arr[-2] arr[-2] = tmp print(' '.join([str(x) for x in arr])) ```
vfc_47585
{ "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 10 100 1000\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n1 2 3 4 4\n", "output": "YES\n1 2 3 4 4\n", "type": "stdin_stdout" }, { "fn_...
code_contests
verifiable_code
1208_B. Uniqueness
Solve the following coding problem using the programming language python: You are given an array a_{1}, a_{2}, …, a_{n}. You can remove at most one subsegment from it. The remaining elements should be pairwise distinct. In other words, at most one time you can choose two integers l and r (1 ≤ l ≤ r ≤ n) and delete in...
```python '''input 4 1 1 2 2 ''' from sys import stdin from copy import deepcopy def get_dict(arr, n): mydict = dict() for i in range(n): if arr[i] in mydict: mydict[arr[i]] += 1 else: mydict[arr[i]] = 1 more = 0 for i in mydict: if mydict[i] > 1: more += 1 return more, mydict # main starts n =...
vfc_47589
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n1 1 2 2\n", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n1 2 3\n", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": ...
code_contests
verifiable_code
1227_B. Box
Solve the following coding problem using the programming language python: Permutation p is a sequence of integers p=[p_1, p_2, ..., p_n], consisting of n distinct (unique) positive integers between 1 and n, inclusive. For example, the following sequences are permutations: [3, 4, 1, 2], [1], [1, 2]. The following seque...
```python t = int(input()) for _ in range(t): n = int(input()) l = list(map(int,input().split())) arr = [0 for j in range(n)] pos = 0 arr[l[0]-1] = 1 final = [l[0]] flag = 0 for j in range(1,n): if(l[j]!=l[j-1]): arr[l[j]-1] = 1 final.append(l[j]) ...
vfc_47593
{ "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\n5\n1 3 4 5 5\n4\n1 1 3 4\n2\n2 2\n1\n1\n", "output": "1 3 4 5 2 \n-1\n2 1 \n1 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n5\n2 3 4 5 5\n4\n1 1 3 4\n2\n2 2\n1\n1\n", "outpu...
code_contests
verifiable_code
124_E. Brackets
Solve the following coding problem using the programming language python: A two dimensional array is called a bracket array if each grid contains one of the two possible brackets — "(" or ")". A path through the two dimensional array cells is called monotonous if any two consecutive cells in the path are side-adjacent...
vfc_47597
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 2 1\n1 2\n", "output": "()\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 3 1\n1 2 3\n4 5 6\n", "output": "(()\n())\n", "type": "stdin_stdout" }, { "fn_name"...
code_contests
verifiable_code
1269_C. Long Beautiful Integer
Solve the following coding problem using the programming language python: You are given an integer x of n digits a_1, a_2, …, a_n, which make up its decimal notation in order from left to right. Also, you are given a positive integer k < n. Let's call integer b_1, b_2, …, b_m beautiful if b_i = b_{i+k} for each i, s...
```python import copy n,k = map(int, input().split()) li = list(map(int, input())) copyli = copy.copy(li) for y in range(k): for x in range(y,n,k): li[x] = li[y] print(n) if copyli > li : pos = k-1 while li[pos] == 9 and pos>0 : pos = pos-1 ele = li[pos]+1 for x in range(pos,n,k)...
vfc_47601
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 2\n353\n", "output": "3\n353\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 2\n1234\n", "output": "4\n1313\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
1311_D. Three Integers
Solve the following coding problem using the programming language python: You are given three integers a ≤ b ≤ c. In one move, you can add +1 or -1 to any of these integers (i.e. increase or decrease any number by one). You can perform such operation any (possibly, zero) number of times, you can even perform this ope...
```python for _ in range(int(input())): a,b,c = list(map(int, input().split())) ans = None; dist = 1e10 for i in range(1, 2*a +1): for j in range(i, 2*b +1, i): for k in range(j, 2*c + 1, j): if abs(a-i)+abs(b-j)+abs(c-k) < dist: ans = [i, j, k] ...
vfc_47609
{ "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": "8\n1 2 3\n123 321 456\n5 10 15\n15 18 21\n100 100 101\n1 22 29\n3 19 38\n6 30 46\n", "output": "1\n1 1 3\n102\n114 228 456\n4\n4 8 16\n6\n18 18 18\n1\n100 100 100\n7\n1 22 22\n2\n1 19 38\n8\n6 24 48\n", "type": "stdin_s...
code_contests
verifiable_code
1334_B. Middle Class
Solve the following coding problem using the programming language python: Many years ago Berland was a small country where only n people lived. Each person had some savings: the i-th one had a_i burles. The government considered a person as wealthy if he had at least x burles. To increase the number of wealthy people...
```python import sys input = sys.stdin.readline Q = int(input()) Query = [] for _ in range(Q): N, K = map(int, input().split()) A = list(map(int, input().split())) Query.append((N, K, A)) for N, K, A in Query: A.sort(reverse=True) n = 0 s = 0 for i, a in enumerate(A): s += a ...
vfc_47613
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n4 3\n5 1 2 1\n4 10\n11 9 11 9\n2 5\n4 3\n3 7\n9 4 9\n", "output": "2\n4\n0\n3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n1 2\n13\n", "output": "1\n", "type": "stdin_...
code_contests
verifiable_code
1354_D. Multiset
Solve the following coding problem using the programming language python: Note that the memory limit is unusual. You are given a multiset consisting of n integers. You have to process queries of two types: * add integer k into the multiset; * find the k-th order statistics in the multiset and remove it. k-t...
```python from collections import Counter from collections import defaultdict from collections import deque import math import os import sys input = sys.stdin.readline ii = 0 _inp = b'' def getchar(): global ii, _inp if ii >= len(_inp): _inp = os.read(0, 4000) ii = 0 if not _inp: r...
vfc_47617
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 28000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 500000000}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 4\n1 2 3 4 5\n-5 -1 -3 -1\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 2\n1 1 1 2 3 4\n5 6\n", "output": "1\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1374_C. Move Brackets
Solve the following coding problem using the programming language python: You are given a bracket sequence s of length n, where n is even (divisible by two). The string s consists of n/2 opening brackets '(' and n/2 closing brackets ')'. In one move, you can choose exactly one bracket and move it to the beginning of ...
```python n = int(input()) arr = [] for i in range(n): a = int(input()) brackets = list(input()) k = 0 t = 0 j = 0 while j < len(brackets): if brackets[j] == '(': k += 1 else: k -= 1 if k < 0: t += 1 brackets.pop(j) ...
vfc_47621
{ "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\n2\n)(\n4\n()()\n8\n())()()(\n10\n)))((((())\n", "output": "1\n0\n1\n3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n2\n)(\n4\n)()(\n8\n())()()(\n10\n)))((((())\n", "output": ...
code_contests
verifiable_code
1397_D. Stoned Game
Solve the following coding problem using the programming language python: T is playing a game with his friend, HL. There are n piles of stones, the i-th pile initially has a_i stones. T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single ...
```python from collections import defaultdict from math import inf for _ in range(int(input())): n=int(input()) arr=list(map(int,input().split())) mi=min(arr) ans=0 su=0 res="T" for i in arr: ans+=i-mi su+=i if max(arr)>su-max(arr): print(res) else: if...
vfc_47625
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n1\n2\n2\n1 1\n", "output": "T\nHL\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1466_D. 13th Labour of Heracles
Solve the following coding problem using the programming language python: You've probably heard about the twelve labors of Heracles, but do you have any idea about the thirteenth? It is commonly assumed it took him a dozen years to complete the twelve feats, so on average, a year to accomplish every one of them. As ti...
```python from sys import stdin import heapq t = int(input()) for _ in range(t): n = int(input()) weight = list(map(int,stdin.readline().split())) h = [] adjacent = [set() for i in range(n)] degree = [0]*n i=0 while(i<n-1): a,b = list(map(int,stdin.readline().split())) a-=1 ...
vfc_47637
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 500000000}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n4\n3 5 4 6\n2 1\n3 1\n4 3\n2\n21 32\n2 1\n6\n20 13 17 13 13 11\n2 1\n3 1\n4 1\n5 1\n6 1\n4\n10 6 6 6\n1 2\n2 3\n4 1\n", "output": "\n18 22 25\n53\n87 107 127 147 167\n28 38 44\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1513_A. Array and Peaks
Solve the following coding problem using the programming language python: A sequence of n integers is called a permutation if it contains all integers from 1 to n exactly once. Given two integers n and k, construct a permutation a of numbers from 1 to n which has exactly k peaks. An index i of an array a of size n is...
```python a=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, ...
vfc_47645
{ "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": "5\n1 0\n5 2\n6 6\n2 1\n6 1\n", "output": "\n1 \n2 4 1 5 3 \n-1\n-1\n1 3 6 5 4 2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n1 0\n5 2\n6 6\n2 1\n6 1\n", "output": "1 \n2 4 1 5 ...
code_contests
verifiable_code
188_E. HQ9+
Solve the following coding problem using the programming language python: HQ9+ is a joke programming language which has only four one-character instructions: * "H" prints "Hello, World!", * "Q" prints the whole source code of the program itself (at each call), * "9" prints the lyrics of "99 Bottles of Beer" son...
vfc_47657
{ "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": "Hello!\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "Progopedia\n", "output": "NO\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
25_E. Test
Solve the following coding problem using the programming language python: Sometimes it is hard to prepare tests for programming problems. Now Bob is preparing tests to new problem about strings — input data to his problem is one string. Bob has 3 wrong solutions to this problem. The first gives the wrong answer if the...
```python from itertools import permutations from sys import stdin from functools import lru_cache input = stdin.readline s1, s2, s3 = input().strip(), input().strip(), input().strip() @lru_cache(None) def findPattern(s): #print(s) slen = len(s) p = [0]*slen ci = 0 for i in range(1, slen): i...
vfc_47669
{ "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": "abacaba\nabaaba\nx\n", "output": "11\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "ab\nbc\ncd\n", "output": "4\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
283_E. Cow Tennis Tournament
Solve the following coding problem using the programming language python: Farmer John is hosting a tennis tournament with his n cows. Each cow has a skill level si, and no two cows having the same skill level. Every cow plays every other cow exactly once in the tournament, and each cow beats every cow with skill level...
vfc_47673
{ "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 2\n1 2 3\n1 2\n2 3\n", "output": " 1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 3\n5 9 4 1 7\n1 7\n2 8\n3 9\n", ...
code_contests
verifiable_code
306_D. Polygon
Solve the following coding problem using the programming language python: Polycarpus loves convex polygons, especially if all their angles are the same and all their sides are different. Draw for him any such polygon with the given number of vertexes. Input The input contains a single integer n (3 ≤ n ≤ 100) — the n...
vfc_47677
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "8\n", "output": "0.000000 0.000000\n70.712092 70.712092\n70.712092 170.716092\n-0.002828 241.431013\n-100.010828 241.431013\n-170.728578 170.713264\n-170.728578 70.701264\n-100.027314 0\n", "type": "stdin_stdout" },...
code_contests
verifiable_code
331_D3. Escaping on Beaveractor
Solve the following coding problem using the programming language python: Don't put up with what you're sick of! The Smart Beaver decided to escape from the campus of Beaver Science Academy (BSA). BSA is a b × b square on a plane. Each point x, y (0 ≤ x, y ≤ b) belongs to BSA. To make the path quick and funny, the Bea...
vfc_47681
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 6, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 3\n0 0 0 1\n0 2 2 2\n3 3 2 3\n12\n0 0 L 0\n0 0 L 1\n0 0 L 2\n0 0 L 3\n0 0 L 4\n0 0 L 5\n0 0 L 6\n2 0 U 2\n2 0 U 3\n3 0 U 5\n1 3 D 2\n1 3 R 2\n", "output": "0 0\n0 1\n0 2\n1 2\n2 2\n3 2\n3 2\n2 2\n3 2\n1 3\n2 2\n1 3\n", ...
code_contests
verifiable_code
354_C. Vasya and Beautiful Arrays
Solve the following coding problem using the programming language python: Vasya's got a birthday coming up and his mom decided to give him an array of positive integers a of length n. Vasya thinks that an array's beauty is the greatest common divisor of all its elements. His mom, of course, wants to give him as beaut...
```python n, k = map(int, input().split()) t = set(map(int, input().split())) y = x = min(t) t = list(t) while True: for i in t: if i % x > k: x = i // (i // x + 1) if y == x: break y = x print(y) # Made By Mostafa_Khaled ```
vfc_47685
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 3\n8 21 52 15 77\n", "output": "7", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 1\n3 6 10 12 13 16\n", "output": "3", "type": "stdin_stdout" }, { "fn_name": n...
code_contests
verifiable_code
378_D. Preparing for the Contest
Solve the following coding problem using the programming language python: Soon there will be held the world's largest programming contest, but the testing system still has m bugs. The contest organizer, a well-known university, has no choice but to attract university students to fix all the bugs. The university has n ...
vfc_47689
{ "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 4 5\n1 3 1 2\n2 1 3\n5 3 6\n", "output": "NO", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 4 9\n1 3 1 2\n2 1 3\n4 3 6\n", "output": "YES\n2 3 2 3 ", "type": "stdin_stdout" ...
code_contests
verifiable_code
39_F. Pacifist frogs
Solve the following coding problem using the programming language python: Thumbelina has had an accident. She has found herself on a little island in the middle of a swamp and wants to get to the shore very much. One can get to the shore only by hills that are situated along a straight line that connects the little i...
```python n, m, k = map(int, input().split()) x, y = n, [] a = map(int, input().split()) b = list(map(int, input().split())) for i, d in enumerate(a): c = 0 for t in b: if 0 == t % d: c += 1 if c < x: x = c y = [i + 1] elif c == x: y += i + 1, print(len(y)) pr...
vfc_47693
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 64000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1000000000 2 3\n2 5\n999999995 999999998 999999996\n", "output": "1\n2 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 3 5\n2 3 4\n1 2 3 4 5\n", "output": "2\n2 3 ", "type": "...
code_contests
verifiable_code
449_E. Jzzhu and Squares
Solve the following coding problem using the programming language python: Jzzhu has two integers, n and m. He calls an integer point (x, y) of a plane special if 0 ≤ x ≤ n and 0 ≤ y ≤ m. Jzzhu defines a unit square as a square with corners at points (x, y), (x + 1, y), (x + 1, y + 1), (x, y + 1), where x and y are som...
vfc_47701
{ "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\n1 3\n2 2\n2 5\n3 4\n", "output": "3\n8\n26\n58\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
470_D. Caesar Cipher
Solve the following coding problem using the programming language python: Caesar cipher is one of the simplest encryption techniques. To transform the original message into encrypted one using key k, one has to replace each letter with a letter which is k positions later in the alphabet (if this takes the position bey...
vfc_47705
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\nCODEFORCES\n", "output": "HTIJKTWHJX\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "13\nFALSERULEZ\n", "output": "SNYFREHYRM\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
494_B. Obsessive String
Solve the following coding problem using the programming language python: Hamed has recently found a string t and suddenly became quite fond of it. He spent several days trying to find all occurrences of t in other strings he had. Finally he became tired and started thinking about the following problem. Given a string...
```python s, t = input(), input() n, m = len(t), len(s) d = 10 ** 9 + 7 p = [0] * (n + 1) i, j = 0, 1 while j < n: if t[i] == t[j]: j += 1 i += 1 p[j] = i elif i: i = p[i] else: j += 1 i = j = 0 f = [0] * (m + 1) while j < m: if t[i] == s[j]: i += 1 j += 1 ...
vfc_47709
{ "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": "welcometoroundtwohundredandeightytwo\nd\n", "output": "274201", "type": "stdin_stdout" }, { "fn_name": null, "input": "ababa\naba\n", "output": "5", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
518_F. Pasha and Pipe
Solve the following coding problem using the programming language python: On a certain meeting of a ruling party "A" minister Pavel suggested to improve the sewer system and to create a new pipe in the city. The city is an n × m rectangular squared field. Each square of the field is either empty (then the pipe can go...
```python n, m = [int(x) for x in input().split()] a = [[int(c == '.') for c in input()] for i in range(n)] def rotate(a): n = len(a) m = len(a[0]) b = [[0] * n for i in range(m)] for i in range(n): for j in range(m): b[j][n - 1 - i] = a[i][j] return b def calc(a): n = len(...
vfc_47713
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 4, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 2\n..\n..\n..\n..\n", "output": " 2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 5\n#...#\n#...#\n###.#\n###.#\n", ...
code_contests
verifiable_code
545_A. Toy Cars
Solve the following coding problem using the programming language python: Little Susie, thanks to her older brother, likes to play with cars. Today she decided to set up a tournament between them. The process of a tournament is described in the next paragraph. There are n toy cars. Each pair collides. The result of a...
```python n=int(input()) cars=[] win=[i for i in range(1,n+1)] for i in range(n): cars.append([int(j) for j in input().split()]) for i in range(n): for j in range(n): if cars[i][j]==-1: pass elif cars[i][j]==1 or cars[i][j]==3: try: win.remove(i+1) ...
vfc_47717
{ "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\n-1 3 3 3\n3 -1 3 3\n3 3 -1 3\n3 3 3 -1\n", "output": "0\n\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n-1 0 0\n0 -1 1\n0 2 -1\n", "output": "2\n1 3\n", "type": "stdin_...
code_contests
verifiable_code
571_C. CNF 2
Solve the following coding problem using the programming language python: 'In Boolean logic, a formula is in conjunctive normal form (CNF) or clausal normal form if it is a conjunction of clauses, where a clause is a disjunction of literals' (cited from https://en.wikipedia.org/wiki/Conjunctive_normal_form) In the ot...
vfc_47721
{ "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 6\n2 1 2\n3 1 -2 3\n4 -3 5 4 6\n2 -6 -4\n1 5\n", "output": "YES\n100010\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
593_A. 2Char
Solve the following coding problem using the programming language python: Andrew often reads articles in his favorite magazine 2Char. The main feature of these articles is that each of them uses at most two distinct letters. Andrew decided to send an article to the magazine, but as he hasn't written any article, he ju...
```python n=int(input()) i=0 x=[] while i<n: x.append(str(input())) i+=1 i=25 r=0 while i: j=i while j: j-=1 t=0 k=n while k: k-=1 y=x[k] z=len(y) ok=1 while z: z-=1 if ord(y[z])-ord('a')!=i: if ord(y[z])-ord('a')!=j:ok=0 if ok:t+=len(y) if r<t:r=t i-=1 print(r) ```
vfc_47725
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\nabb\ncacc\naaa\nbbb\n", "output": "9\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\na\na\nbcbcb\ncdecdecdecdecdecde\naaaa\n", "output": "6\n", "type": "stdin_stdout" ...
code_contests
verifiable_code
614_D. Skills
Solve the following coding problem using the programming language python: Lesha plays the recently published new version of the legendary game hacknet. In this version character skill mechanism was introduced. Now, each player character has exactly n skills. Each skill is represented by a non-negative integer ai — the...
```python import bisect as bs import heapq as hq def force(cf, cm, f, m): return f*cf + m*cm # def perfect(sa, amax, m): # p = 0 # while sa[-p-1] == amax: # p += 1 # while sa[p] + m >= amax: # for _ in range(amax-sa[-p-1]): # yield p # m -= amax-sa[-p-1] # ...
vfc_47729
{ "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 5 10 1 5\n1 3 1\n", "output": "12\n2 5 2 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 5 10 1 339\n1 3 1\n", "output": "35\n5 5 5 \n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
634_A. Island Puzzle
Solve the following coding problem using the programming language python: A remote island chain contains n islands, labeled 1 through n. Bidirectional bridges connect the islands to form a simple cycle — a bridge connects islands 1 and 2, islands 2 and 3, and so on, and additionally a bridge connects islands n and 1. ...
```python n = int(input()) s1 = list(input().strip().split()) s2 = list(input().strip().split()) s1.remove('0') s2.remove('0') s1 = ''.join(s1) s2 = ''.join(s2) s1 = s1+s1 if s2 in s1: print("YES") else: print("NO") ```
vfc_47733
{ "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\n1 0 2\n2 0 1\n", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1 0\n0 1\n", "output": "YES", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
662_D. International Olympiad
Solve the following coding problem using the programming language python: International Abbreviation Olympiad takes place annually starting from 1989. Each year the competition receives an abbreviation of form IAO'y, where y stands for some number of consequent last digits of the current year. Organizers always pick a...
```python n=int(input()) lst=[] for i in range(n): n=input() lst.append(n[4:]) for i in lst: l=len(i) i=int(i) #print(i) g=0 p=10 c=1 while(c<l): g+=p p*=10 c+=1 #print(g,p) while(i<1989+g): i+=p print(i) ```
vfc_47737
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\nIAO'15\nIAO'2015\nIAO'1\nIAO'9\nIAO'0\n", "output": "2015\n12015\n1991\n1989\n1990\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\nIAO'9\nIAO'99\nIAO'999\nIAO'9999\n", "output"...