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
1157_F. Maximum Balanced Circle
Solve the following coding problem using the programming language python: There are n people in a row. The height of the i-th person is a_i. You can choose any subset of these people and try to arrange them into a balanced circle. A balanced circle is such an order of people that the difference between heights of any...
```python import sys from collections import namedtuple from itertools import groupby input = sys.stdin.readline def main(): Data = namedtuple('Data', ['arr', 'l', 'r']) _ = int(input()) a = list(map(int, input().split())) f = [ [0, 0] for i in range(max(a) + 2) ] for x in a: f[x][0] = x...
vfc_39665
{ "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": "3\n5 1 4\n", "output": "2\n4 5\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "7\n4 3 5 1 2 2 1\n", "output": "5\n1 2 3 2 1 \n", "type": "stdin_stdout" }, { "fn_n...
code_contests
verifiable_code
117_C. Cycle
Solve the following coding problem using the programming language python: A tournament is a directed graph without self-loops in which every pair of vertexes is connected by exactly one directed edge. That is, for any two vertexes u and v (u ≠ v) exists either an edge going from u to v, or an edge from v to u. You ar...
```python from sys import stdin, stdout input = stdin.readline import gc gc.disable() def f(): p, q, n = [0], [0], int(input()) input() for i in range(1, n): t = input()[: i] if '0' in t: if '1' in t: for l, j in enumerate(p): if t[j] == '1':...
vfc_39669
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 500000000}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n00100\n10000\n01001\n11101\n11000\n", "output": "1 3 2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n01111\n00000\n01000\n01100\n01110\n", "output": "-1\n", "type": "st...
code_contests
verifiable_code
1198_D. Rectangle Painting 1
Solve the following coding problem using the programming language python: There is a square grid of size n × n. Some cells are colored in black, all others are colored in white. In one operation you can select some rectangle and color all its cells in white. It costs max(h, w) to color a rectangle of size h × w. You a...
vfc_39673
{ "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\n#...#\n.#.#.\n.....\n.#...\n#....\n", "output": "5", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n#...\n....\n....\n#...\n", "output": "2", "type": "stdin_stdout" }, ...
code_contests
verifiable_code
1238_E. Keyboard Purchase
Solve the following coding problem using the programming language python: You have a password which you often type — a string s of length n. Every character of this string is one of the first m lowercase Latin letters. Since you spend a lot of time typing it, you want to buy a new keyboard. A keyboard is a permutati...
```python import sys sys.setrecursionlimit(10**7) input = sys.stdin.readline INF = 10**9 n, m = [int(item) for item in input().split()] s = input().rstrip() count = [[0] * m for _ in range(m)] ord_a = ord("a") for c1, c2 in zip(s, s[1:]): c1 = ord(c1) - ord_a c2 = ord(c2) - ord_a if c1 != c2: cou...
vfc_39681
{ "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": "15 4\nabacabadabacaba\n", "output": "16\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 3\naacabc\n", "output": "5\n", "type": "stdin_stdout" }, { "fn_name": nu...
code_contests
verifiable_code
1280_A. Cut and Paste
Solve the following coding problem using the programming language python: We start with a string s consisting only of the digits 1, 2, or 3. The length of s is denoted by |s|. For each i from 1 to |s|, the i-th character of s is denoted by s_i. There is one cursor. The cursor's location ℓ is denoted by an integer in...
```python for _ in range(int(input())): x = int(input()) s = input() l = 0 while(len(s)<x): s += s[l+1:]*(int(s[l])-1) l+=1 count=len(s) for k in range(l,x): count+=((count-k-1)*(int(s[k])-1)) count%= 1000000007 print(count) ```
vfc_39689
{ "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\n5\n231\n7\n2323\n6\n333\n24\n133321333\n", "output": "25\n1438\n1101\n686531475\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n1000000\n221\n", "output": "1001822\n", "t...
code_contests
verifiable_code
12_E. Start of the season
Solve the following coding problem using the programming language python: Before the start of the football season in Berland a strange magic ritual is held. The most experienced magicians have to find a magic matrix of the size n × n (n is even number). Gods will never allow to start the championship without it. Matri...
```python n=int(input()) a=[[0 for j in range(n)] for i in range(n)] for i in range(n-1): for j in range(n-1): if i!=j: a[i][j]=(i+j)%n+int(i+j>=n) a[i][n-1]=((n-1+2*i)%n+int(n-1+2*i>=n))%n+int(n-1+2*i>2*(n-1)) for i in range(n-1): a[n-1][i]=((n-1+2*i)%n+int(n-1+2*i>=n))%n+int(n-1+2*i>2*...
vfc_39693
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n", "output": "0 1 \n1 0 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n", "output": "0 2 3 1 \n2 0 1 3 \n3 1 0 2 \n1 3 2 0 \n", "type": "stdin_stdout" ...
code_contests
verifiable_code
1365_A. Matrix Game
Solve the following coding problem using the programming language python: Ashish and Vivek play a game on a matrix consisting of n rows and m columns, where they take turns claiming cells. Unclaimed cells are represented by 0, while claimed cells are represented by 1. The initial state of the matrix is given. There ca...
```python t = int(input()) for _ in range(t): n,m = map(int,input().split()) l = [] s = 0 t1,t2 = 0,0 for i in range(n): l1 = list(map(int,input().split())) l.append(l1) for i in range(n): f = 1 for j in range(m): if l[i][j] == 1: f = 0 if f: t1 += 1 for i in range(m): f = 1 for j in ran...
vfc_39705
{ "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\n2 2\n0 0\n0 0\n2 2\n0 0\n0 1\n2 3\n1 0 1\n1 1 0\n3 3\n1 0 0\n0 0 0\n1 0 0\n", "output": "Vivek\nAshish\nVivek\nAshish\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1385_A. Three Pairwise Maximums
Solve the following coding problem using the programming language python: You are given three positive (i.e. strictly greater than zero) integers x, y and z. Your task is to find positive integers a, b and c such that x = max(a, b), y = max(a, c) and z = max(b, c), or determine that it is impossible to find such a, b...
```python t = int(input()) input_list = [[0,0,0] for i in range(t)] for i in range(t): x,y,z = input().split() input_list[i][0] = int(x) input_list[i][1] = int(y) input_list[i][2] = int(z) ans_list = ["NO" for i in range(t)] output_list = [[0,0,0] for i in range(t)] for i in range(t): x,y,z = inpu...
vfc_39709
{ "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\n3 2 3\n100 100 100\n50 49 49\n10 30 20\n1 1000000000 1000000000\n", "output": "YES\n3 2 2\nYES\n100 100 100\nNO\nNO\nYES\n1000000000 1 1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "...
code_contests
verifiable_code
1406_D. Three Sequences
Solve the following coding problem using the programming language python: You are given a sequence of n integers a_1, a_2, …, a_n. You have to construct two sequences of integers b and c with length n that satisfy: * for every i (1≤ i≤ n) b_i+c_i=a_i * b is non-decreasing, which means that for every 1<i≤ n, b_i...
```python import sys import atexit class Fastio: def __init__(self): self.ibuf = bytes() self.obuf = bytearray() self.pil = 0 self.pir = 0 def load(self): self.ibuf = self.ibuf[self.pil:] self.ibuf += sys.stdin.buffer.read(131072) self.pil = 0 se...
vfc_39713
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n2 -1 7 3\n2\n2 4 -3\n3 4 2\n", "output": "5\n5\n6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n-9 -10 -9 -6 -5 4\n3\n2 6 -9\n1 2 -10\n4 6 -3\n", "output": "3\n3\n3\n1\n", ...
code_contests
verifiable_code
1427_E. Xum
Solve the following coding problem using the programming language python: You have a blackboard and initially only an odd number x is written on it. Your goal is to write the number 1 on the blackboard. You may write new numbers on the blackboard with the following two operations. * You may take two numbers (not ...
```python #!/usr/bin/env python import os import sys from io import BytesIO, IOBase def main(): print("500") cnt = 500 x = int(input()) if x % 4 == 3: print(str(x) + " + " + str(x)) print(str(2 * x) + " + " + str(x)) cnt -= 2 x *= 3 xCpy = x bigX = x while x...
vfc_39717
{ "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\n", "output": "\n5\n3 + 3\n3 ^ 6\n3 + 5\n3 + 6\n8 ^ 9\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "123\n", "output": "\n10\n123 + 123\n123 ^ 246\n141 + 123\n246 + 123\n264 ^ 369...
code_contests
verifiable_code
1450_E. Capitalism
Solve the following coding problem using the programming language python: A society can be represented by a connected, undirected graph of n vertices and m edges. The vertices represent people, and an edge (i,j) represents a friendship between people i and j. In society, the i-th person has an income a_i. A person i ...
```python n,m = map(int,input().split());edge = [[] for i in range(n)];cost = [[10**18*(i!=j) for j in range(n)] for i in range(n)] for _ in range(m):u,v,b = map(int,input().split());edge[u-1].append(v-1);edge[v-1].append(u-1);cost[u-1][v-1] = 1;cost[v-1][u-1] = (1 if not b else -1) used = [False]*n;cond = [0]*n;used[0...
vfc_39721
{ "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 0\n", "output": "\nYES\n0\n0 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 4\n1 2 1\n2 3 0\n3 4 1\n4 1 1\n", "output": "\nNO\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
1474_C. Array Destruction
Solve the following coding problem using the programming language python: You found a useless array a of 2n positive integers. You have realized that you actually don't need this array, so you decided to throw out all elements of a. It could have been an easy task, but it turned out that you should follow some rules:...
```python from sys import stdin #import math input = stdin.readline q = int(input()) for _ in range(q): n = int(input()) a = list(map(int, input().split())) a.sort() l = a[-1] a.pop() for i in range(2*n-1): d = {} for ii in range(2*n - 1): if ii == i: ...
vfc_39725
{ "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\n3 5 1 2\n3\n1 1 8 8 64 64\n2\n1 1 2 4\n5\n1 2 3 4 5 6 7 14 3 11\n", "output": "\nYES\n6\n1 5\n2 3\nNO\nNO\nYES\n21\n14 7\n3 11\n5 6\n2 4\n3 1", "type": "stdin_stdout" }, { "fn_name": null, "inp...
code_contests
verifiable_code
149_E. Martian Strings
Solve the following coding problem using the programming language python: During the study of the Martians Petya clearly understood that the Martians are absolutely lazy. They like to sleep and don't like to wake up. Imagine a Martian who has exactly n eyes located in a row and numbered from the left to the right fr...
vfc_39729
{ "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": "ABCBABA\n2\nBAAB\nABBA\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "BCCCABCBAAACCBCCAABAABCACBCBBA\n20\nBBCCBBAB\nBAC\nACBAACBAAABABAABBBACABC\nCCBCBCCA\nCCABB\nCCABCCC...
code_contests
verifiable_code
1523_E. Crypto Lights
Solve the following coding problem using the programming language python: <image> To monitor cryptocurrency exchange rates trader William invented a wonderful device consisting of n lights arranged in a row. The device functions in the following way: Initially, all lights on William's device are turned off. At the b...
```python def divisors(M): d=[] i=1 while M>=i**2: if M%i==0: d.append(i) if i**2!=M: d.append(M//i) i=i+1 return d def popcount(x): x = x - ((x >> 1) & 0x55555555) x = (x & 0x33333333) + ((x >> 2) & 0x33333333) x = (x + (x >> 4)) & 0...
vfc_39733
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n3 2\n15 2\n40 15\n", "output": "\n333333338\n141946947\n329622137\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n100000 99995\n100000 100000\n100000 99998\n100000 99997\n100000 999...
code_contests
verifiable_code
155_D. Colliders
Solve the following coding problem using the programming language python: By 2312 there were n Large Hadron Colliders in the inhabited part of the universe. Each of them corresponded to a single natural number from 1 to n. However, scientists did not know what activating several colliders simultaneously could cause, s...
```python n, m = map(int, input().split()) n += 1 s = [[] for i in range(n)] for j in range(2, n, 2): s[j] = [2] for i in range(3, n, 2): if s[i]: continue for j in range(i, n, i): s[j].append(i) p, d, r = {}, set(), [''] * m for j in range(m): t = input() i = int(t[2: ]) if t[0] == '...
vfc_39737
{ "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": "10 10\n+ 6\n+ 10\n+ 5\n- 10\n- 5\n- 6\n+ 10\n+ 3\n+ 6\n+ 3\n", "output": "Success\nConflict with 6\nSuccess\nAlready off\nSuccess\nSuccess\nSuccess\nSuccess\nConflict with 10\nAlready on\n", "type": "stdin_stdout" }...
code_contests
verifiable_code
177_D2. Encrypting Messages
Solve the following coding problem using the programming language python: The Smart Beaver from ABBYY invented a new message encryption method and now wants to check its performance. Checking it manually is long and tiresome, so he decided to ask the ABBYY Cup contestants for help. A message is a sequence of n intege...
```python n, m, c = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) s, k = 0, n - m for i in range(n): if i < m: s += b[i] a[i] = (a[i] + s) % c if i >= k: s -= b[i - k] print(' '.join(str(i) for i in a)) ```
vfc_39741
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 1 5\n1 2 3\n4\n", "output": "0 1 2 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 3 2\n1 1 1 1\n1 1 1\n", "output": "0 1 1 0 ", "type": "stdin_stdout" }, { "f...
code_contests
verifiable_code
198_E. Gripping Story
Solve the following coding problem using the programming language python: One day Qwerty the Ranger witnessed two transport ships collide with each other. As a result, all contents of their cargo holds scattered around the space. And now Qwerty wants to pick as many lost items as possible to sell them later. The thin...
vfc_39745
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 4, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "0 0 5 10 5\n5 4 7 11 5\n-7 1 4 7 8\n0 2 13 5 6\n2 -3 9 3 4\n13 5 1 9 9\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "0 0 1 100500 24\n-2 -2 1 2 100500\n-1 1 2 3 100500\n...
code_contests
verifiable_code
222_A. Shooshuns and Sequence
Solve the following coding problem using the programming language python: One day shooshuns found a sequence of n integers, written on a blackboard. The shooshuns can perform one operation with it, the operation consists of two steps: 1. Find the number that goes k-th in the current sequence and add the same number...
```python n,k=map(int,input().split()) l=list(map(int,input().split())) f=l[k-1] if l[k-1:].count(f) == n-k+1: r = 0 for i in range(k-2,-1,-1): if l[k-1] != l[i]: break r+=1 print(len(l[:k-1-r])) else: print(-1) ```
vfc_39749
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 2\n3 1 1\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 1\n3 1 1\n", "output": "-1\n", "type": "stdin_stdout" }, { "fn_name": null, "i...
code_contests
verifiable_code
245_G. Suggested Friends
Solve the following coding problem using the programming language python: Polycarpus works as a programmer in a start-up social network. His boss gave his a task to develop a mechanism for determining suggested friends. Polycarpus thought much about the task and came to the folowing conclusion. Let's say that all fr...
```python import sys from collections import defaultdict n,m =0, input() mp={} G = defaultdict(list) def myfind(c): global n,mp if c not in mp: mp[c] = n n += 1 return mp[c] def add(u,v): G[u].append(v) G[v].append(u) for ch in sys.stdin: a,b=ch.split() u,v=myfind(a),myfind(b) add(u,v) print n def bfs(s): ...
vfc_39753
{ "difficulty": "13", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\nvalera vanya\nvalera edik\npasha valera\nigor valera\n", "output": "5\nvalera 0\nvanya 3\nedik 3\npasha 3\nigor 3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\nMike Gerald\nKate Mi...
code_contests
verifiable_code
270_E. Flawed Flow
Solve the following coding problem using the programming language python: Emuskald considers himself a master of flow algorithms. Now he has completed his most ingenious program yet — it calculates the maximum flow in an undirected graph. The graph consists of n vertices and m edges. Vertices are numbered from 1 to n....
```python import sys from collections import deque DST_VERTEX = 0 EDGE_CAP = 1 EDGE_ID = 2 EDGE_DIR = 3 def bfs(flow, graph, n, m): dirs = [-1 for _ in range(m)] q = deque() q.append(0) q_size = 1 while q_size > 0: cur_node = q.popleft() q_size -= 1 for i in range(len(graph...
vfc_39757
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 5\n1 2 10\n1 3 10\n2 3 5\n4 2 15\n3 4 5\n", "output": "0\n0\n1\n1\n0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 3\n3 2 10\n1 2 10\n3 1 5\n", "output": "1\n0\n1\n", "ty...
code_contests
verifiable_code
294_B. Shaass and Bookshelf
Solve the following coding problem using the programming language python: Shaass has n books. He wants to make a bookshelf for all his books. He wants the bookshelf's dimensions to be as small as possible. The thickness of the i-th book is ti and its pages' width is equal to wi. The thickness of each book is either 1 ...
```python n = int(input()) t = [] for i in range(n): e = list(map(int,input().split())) t.append(e) size = 0 size2 = 0 for i in t: size += i[0] size2 += i[1] matrix = [[-1000]*(size+1) for i in range(n)] for i in range(n): matrix[i][0] = 0 for i in range(n): for j in range(1,size+1): ...
vfc_39761
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1 10\n2 1\n2 4\n", "output": "3\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
317_E. Princess and Her Shadow
Solve the following coding problem using the programming language python: Princess Vlada enjoys springing in the meadows and walking in the forest. One day — wonderful, sunny day — during her walk Princess found out with astonishment that her shadow was missing! "Blimey!", — she thought and started her search of the s...
vfc_39765
{ "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": "5 0 3 0 8\n2 -1\n2 0\n2 1\n3 -1\n4 1\n4 0\n3 1\n4 -1\n", "output": "-1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 2 1 1 3\n0 1\n1 0\n0 0\n", "output": "LLD\n", "type": "...
code_contests
verifiable_code
341_E. Candies Game
Solve the following coding problem using the programming language python: Iahub is playing an uncommon game. Initially, he has n boxes, numbered 1, 2, 3, ..., n. Each box has some number of candies in it, described by a sequence a1, a2, ..., an. The number ak represents the number of candies in box k. The goal of th...
```python n=int(raw_input()) a=map(int,raw_input().split()) ans=[] zp=[i for i in xrange(0,n) if (a[i]!=0)] def solve(z): while 1: for i in xrange(0,2): for j in xrange(i+1,3): if (a[z[i]]>a[z[j]]): z[i],z[j]=z[j],z[i] if (a[z[0]]==0): break x=a[z[1]]/a[z[0]] for i in xrange(0,25): if (2**i>x): break...
vfc_39769
{ "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\n0 1 0\n", "output": "-1", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
365_B. The Fibonacci Segment
Solve the following coding problem using the programming language python: You have array a1, a2, ..., an. Segment [l, r] (1 ≤ l ≤ r ≤ n) is good if ai = ai - 1 + ai - 2, for all i (l + 2 ≤ i ≤ r). Let's define len([l, r]) = r - l + 1, len([l, r]) is the length of the segment [l, r]. Segment [l1, r1], is longer than s...
```python import sys n = int(input()) a = list(map(int, input().split())) if n <= 2: print(n) sys.exit() best = 0 mem = a[:2] cur = 0 for i in a[2:]: if mem[0] + mem[1] == i: cur += 1 else: if cur > best: best = cur cur = 0 mem = mem[1:] + [i] if cur > best: best = cur print(...
vfc_39773
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n1 1 1 1 1\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n1 2 3 5 8 13 21 34 55 89\n", "output": "10\n", "type": "stdin_stdout" }, { "fn_n...
code_contests
verifiable_code
389_A. Fox and Number Game
Solve the following coding problem using the programming language python: Fox Ciel is playing a game with numbers now. Ciel has n positive integers: x1, x2, ..., xn. She can do the following operation as many times as needed: select two different indexes i and j such that xi > xj hold, and then apply assignment xi =...
```python from sys import stdin, stdout, stderr, setrecursionlimit setrecursionlimit(100000) def debug (*e): if not __debug__: print(*e, file=stderr) def dd(*vals): import inspect, re frame = inspect.getframeinfo(inspect.stack()[1][0]) vs = re.search("dd\((.+)\)", frame.code_context[0]).group(...
vfc_39777
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n12 18\n", "output": "12\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n2 4 6\n", "output": "6\n", "type": "stdin_stdout" }, { "fn_name": null, "input...
code_contests
verifiable_code
409_D. Big Data
Solve the following coding problem using the programming language python: Little Petya wanted to give an April Fools Day present to some scientists. After some hesitation he decided to give them the array that he got as a present in Codeforces Round #153 (Div.2). The scientists rejoiced at the gift and decided to put ...
```python x = int(input()) v = [1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 0, 1, 0, 1, 0] print(v[x-1]) ```
vfc_39781
{ "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": "7\n", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n", "output": "1", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
436_E. Cardboard Box
Solve the following coding problem using the programming language python: Everyone who has played Cut the Rope knows full well how the gameplay is organized. All levels in the game are divided into boxes. Initially only one box with some levels is available. Player should complete levels to earn stars, collecting star...
vfc_39785
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 5, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 3\n1 2\n1 2\n", "output": "3\n21\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 3\n10 20\n5 10\n10 20\n6 9\n25 30\n", "output": "14\n01020\n", "type": "stdin_stdout" }...
code_contests
verifiable_code
45_A. Codecraft III
Solve the following coding problem using the programming language python: Today Vasya visited a widely known site and learned that the continuation of his favourite game Codecraft II will appear after exactly k months. He looked at the calendar and learned that at the moment is the month number s. Vasya immediately go...
```python month = str(input()) k = int(input()) m = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] j = m.index(month) while k != 0: if j == 11: j = 0 k -= 1 else: j += 1 k -= 1 print(m[j]) ```
vfc_39789
{ "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": "May\n24\n", "output": "May\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "November\n3\n", "output": "February\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
480_E. Parking Lot
Solve the following coding problem using the programming language python: Petya's been bored at work and he is killing the time by watching the parking lot at the office. The parking lot looks from above like an n × m table (a cell of the table corresponds to a single parking spot). Some spots in the parking lot are t...
vfc_39793
{ "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": "7 8 4\n........\nX.....X.\n........\n........\n.X......\n........\n........\n1 5\n6 4\n3 5\n4 6\n", "output": "5\n4\n4\n3\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
505_E. Mr. Kitayuta vs. Bamboos
Solve the following coding problem using the programming language python: Mr. Kitayuta's garden is planted with n bamboos. (Bamboos are tall, fast-growing tropical plants with hollow stems.) At the moment, the height of the i-th bamboo is hi meters, and it grows ai meters at the end of each day. Actually, Mr. Kitayu...
vfc_39797
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 3 3 10\n9 5\n9 2\n4 7\n9 10\n3 8\n", "output": "14\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 10 10 1000000000\n0 10\n0 10\n", "output": "10\n", "type": "stdin_stdout"...
code_contests
verifiable_code
529_D. Social Network
Solve the following coding problem using the programming language python: Polycarpus got an internship in one well-known social network. His test task is to count the number of unique users who have visited a social network during the day. Polycarpus was provided with information on all user requests for this time per...
```python def main(): mode="filee" if mode=="file":f=open("test.txt","r") get = lambda :[int(x) for x in (f.readline() if mode=="file" else input()).split()] gets = lambda :[str(x) for x in (f.readline()[:-1] if mode=="file" else input()).split(":")] [n,m,t]=get() a=[0]*20002 b=[0]*20002 ...
vfc_39801
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 2 10\n17:05:53\n17:05:58\n17:06:01\n22:39:47\n", "output": "3\n1\n2\n2\n3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 2 86400\n00:00:00\n", "output": "No solution\n", "...
code_contests
verifiable_code
555_A. Case of Matryoshkas
Solve the following coding problem using the programming language python: Andrewid the Android is a galaxy-famous detective. He is now investigating the case of vandalism at the exhibition of contemporary art. The main exhibit is a construction of n matryoshka dolls that can be nested one into another. The matryoshka...
```python n,k = map(int,input().split(" ")) i=0 res=k sh=0 while i<k: i+=1 mas=list(map(int,input().split(" ")))[1:] if mas[0]==1: j=0 while j<(len(mas)-1): if(mas[j]+1!=mas[j+1]): break else: j+=1 sh+=len(mas)-j-1 ...
vfc_39805
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 2\n2 1 2\n1 3\n", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "7 3\n3 1 3 7\n2 2 5\n2 4 6\n", "output": "10", "type": "stdin_stdout" }, { "fn_name...
code_contests
verifiable_code
580_E. Kefa and Watch
Solve the following coding problem using the programming language python: One day Kefa the parrot was walking down the street as he was on the way home from the restaurant when he saw something glittering by the road. As he came nearer he understood that it was a watch. He decided to take it to the pawnbroker to earn ...
vfc_39809
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 500000000}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 1 2\n112\n2 2 3 1\n1 1 3 8\n2 1 2 1\n", "output": "NO\nYES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 2 3\n334934\n2 2 5 2\n1 4 4 3\n2 1 6 3\n1 2 3 8\n2 3 6 1\n", "output": ...
code_contests
verifiable_code
602_D. Lipshitz Sequence
Solve the following coding problem using the programming language python: A function <image> is called Lipschitz continuous if there is a real constant K such that the inequality |f(x) - f(y)| ≤ K·|x - y| holds for all <image>. We'll deal with a more... discrete version of this term. For an array <image>, we define i...
vfc_39813
{ "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": "7 6\n5 7 7 4 6 6 2\n1 2\n2 3\n2 6\n1 7\n4 7\n3 5\n", "output": "2\n0\n22\n59\n16\n8\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10 4\n1 5 2 9 1 3 4 2 1 7\n2 4\n3 8\n7 10\n1 9\n", ...
code_contests
verifiable_code
625_B. War of the Corporations
Solve the following coding problem using the programming language python: A long time ago, in a galaxy far far away two giant IT-corporations Pineapple and Gogol continue their fierce competition. Crucial moment is just around the corner: Gogol is ready to release it's new tablet Lastus 3000. This new device is equip...
```python a, b = input(), input() ans = 0 index = a.find (b, 0) while index != -1: ans = ans + 1 index = a.find (b, index + len (b)) print (ans) ```
vfc_39817
{ "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": "intellect\ntell\n", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "google\napple\n", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
64_D. Presents
Solve the following coding problem using the programming language python: You are given the prices of three presents. Also there are three sisters. It is known that the most valuable present is for the eldest sister. The second (by price) is for the second sister. And the less valuable present is for the youngest sist...
vfc_39821
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 64000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "11 13 1\n", "output": "2 1 3 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "30 10 30\n", "output": "1 3 2 ", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
673_D. Bear and Two Paths
Solve the following coding problem using the programming language python: Bearland has n cities, numbered 1 through n. Cities are connected via bidirectional roads. Each road connects two distinct cities. No two roads connect the same pair of cities. Bear Limak was once in a city a and he wanted to go to a city b. Th...
```python n,k=map(int,input().split()) a,b,c,d=input().split() if n<5 or k<n+1: print(-1) else: l=list(set(map(str,range(1,n+1)))-{a,b,c,d}) print(' '.join([a,c]+l+[d,b]+['\n']+[c,a]+l+[b,d])) ```
vfc_39825
{ "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": "7 11\n2 4 7 3\n", "output": "2 7 1 5 6 3 4\n7 2 1 5 6 4 3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1000 999\n10 20 30 40\n", "output": "-1\n", "type": "stdin_stdout" ...
code_contests
verifiable_code
698_E. Cron
Solve the following coding problem using the programming language python: Sometime the classic solution are not powerful enough and we have to design our own. For the purpose of this problem you have to implement the part of the system of task scheduling. Each task should be executed at some particular moments of tim...
```python import datetime as dt import calendar second,minute,hour,day,date,month = map(int,raw_input().split()) n = int(raw_input()) epoch = dt.datetime(year=1970, month=1, day=1) safe = epoch.replace(year=2370) fourh = safe - epoch fourh = fourh.days*60*60*24 + fourh.seconds for x in xrange(n): tm = int(...
vfc_39829
{ "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": "-1 59 23 -1 -1 -1\n6\n1467372658\n1467417540\n1467417541\n1467417598\n1467417599\n1467417600\n", "output": "1467417540\n1467417541\n1467417542\n1467417599\n1467503940\n1467503940\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
740_C. Alyona and mex
Solve the following coding problem using the programming language python: Alyona's mother wants to present an array of n non-negative integers to Alyona. The array should be special. Alyona is a capricious girl so after she gets the array, she inspects m of its subarrays. Subarray is a set of some subsequent element...
```python n,m=map(int,input().split()) min_val=9999999 for _ in range(m): y,x=map(int,input().split()) if min_val>x-y: x1=x y1=y min_val=x-y print(min_val+1) L=[0]*n tp=0 listNum=[] for i in range(n): listNum.append(tp) tp+=1 if tp>min_val: tp=0 for i in listNum[:-1]:...
vfc_39837
{ "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 3\n1 3\n2 5\n4 5\n", "output": "2\n0 1 0 1 0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 2\n1 4\n2 4\n", "output": "3\n0 1 2 0\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
764_B. Timofey and cubes
Solve the following coding problem using the programming language python: Young Timofey has a birthday today! He got kit of n cubes as a birthday present from his parents. Every cube has a number ai, which is written on it. Timofey put all the cubes in a row and went to unpack other presents. In this time, Timofey's ...
```python n=int(input()) a=list(map(int,input().split())) i=0 temp=0 for i in range(n//2): if i%2==0: temp=a[i] a[i]=a[n-i-1] a[n-i-1]=temp for r in a: print(r,end=' ') ```
vfc_39841
{ "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": "8\n6 1 4 2 5 6 9 2\n", "output": "2 1 6 2 5 4 9 6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "7\n4 3 7 6 9 1 2\n", "output": "2 3 9 6 7 1 4\n", "type": "stdin_stdout" }...
code_contests
verifiable_code
787_D. Legacy
Solve the following coding problem using the programming language python: Rick and his co-workers have made a new radioactive formula and a lot of bad guys are after them. So Rick wants to give his legacy to Morty before bad guys catch them. There are n planets in their universe numbered from 1 to n. Rick is in plan...
vfc_39845
{ "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 1\n2 3 2 3 17\n2 3 2 2 16\n2 2 2 3 3\n3 3 1 1 12\n1 3 3 17\n", "output": "0 28 12\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 3 1\n3 4 1 3 12\n2 2 3 4 10\n1 2 4 16\n", "out...
code_contests
verifiable_code
809_A. Do you want a date?
Solve the following coding problem using the programming language python: Leha decided to move to a quiet town Vičkopolis, because he was tired by living in Bankopolis. Upon arrival he immediately began to expand his network of hacked computers. During the week Leha managed to get access to n computers throughout the ...
```python def main(): largemodulus = 1000000007 maxofn = 300001 n = 0 answer = 0 powersoftwo = [] multiplier = 1 for _ in range(maxofn): powersoftwo.append(multiplier) if multiplier >= largemodulus: multiplier = multiplier % largemodulus multiplier *= 2 n = int(input()) ...
vfc_39849
{ "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\n4 3 1\n", "output": "9\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n4 7\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": ...
code_contests
verifiable_code
833_D. Red-Black Cobweb
Solve the following coding problem using the programming language python: <image> Slastyona likes to watch life of nearby grove's dwellers. This time she watches a strange red-black spider sitting at the center of a huge cobweb. The cobweb is a set of n nodes connected by threads, each of the treads is either red of...
vfc_39853
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 6, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n1 2 9 0\n2 3 5 1\n2 4 5 0\n2 5 5 1\n", "output": "1265625", "type": "stdin_stdout" }, { "fn_name": null, "input": "8\n1 2 7 1\n2 3 4 1\n3 4 19 1\n5 1 2 0\n6 2 3 0\n7 3 3 0\n8 4 4 0\n", "outp...
code_contests
verifiable_code
854_B. Maxim Buys an Apartment
Solve the following coding problem using the programming language python: Maxim wants to buy an apartment in a new house at Line Avenue of Metropolis. The house has n apartments that are numbered from 1 to n and are arranged in a row. Two apartments are adjacent if their indices differ by 1. Some of the apartments can...
```python n,k=map(int,input().split()) mi=1 if k==0: print(0,0) exit() if k==n: print(0,0) exit() if 3*k <=n: ma=2*k else: ma=n-k print(mi,ma) ```
vfc_39857
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6 3\n", "output": "1 3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "999999998 333333333\n", "output": "1 666666665\n", "type": "stdin_stdout" }, { "fn_name": n...
code_contests
verifiable_code
878_E. Numbers on the blackboard
Solve the following coding problem using the programming language python: A sequence of n integers is written on a blackboard. Soon Sasha will come to the blackboard and start the following actions: let x and y be two adjacent numbers (x before y), then he can remove them and write x + 2y instead of them. He will perf...
vfc_39861
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 3\n1 2 3\n1 3\n1 2\n2 3\n", "output": "17\n5\n8\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 2\n1 1 1 -1\n1 4\n3 4\n", "output": "5\n1000000006\n", "type": "stdin_stdout...
code_contests
verifiable_code
924_D. Contact ATC
Solve the following coding problem using the programming language python: Arkady the air traffic controller is now working with n planes in the air. All planes move along a straight coordinate axis with Arkady's station being at point 0 on it. The i-th plane, small enough to be represented by a point, currently has a ...
```python import sys range = xrange input = raw_input inp = [int(x) for x in sys.stdin.read().split()]; ii = 0 n = inp[ii]; ii += 1 w = inp[ii]; ii += 1 X = inp[ii + 0: ii + 2 * n: 2] V = inp[ii + 1: ii + 2 * n: 2] V = [-v for v in V] ii += 2 * n def sign(x): return 1 - 2*(x < 0) def cmp1(i,j): # X[i] / (V...
vfc_39869
{ "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 1\n-3 2\n-3 3\n-1 2\n1 -3\n3 -5\n", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 1\n-3 2\n-2 2\n-1 2\n1 -2\n2 -2\n3 -2\n", "output": "9", "type": "stdin_stdou...
code_contests
verifiable_code
952_F. 2 + 2 != 4
Solve the following coding problem using the programming language python: One very experienced problem writer decided to prepare a problem for April Fools Day contest. The task was very simple - given an arithmetic expression, return the result of evaluating this expression. However, looks like there is a bug in the r...
```python import re;s=input();print(eval(s)+eval(re.sub("-|\+|\d",lambda m:"+-035"[2-"+--".count(m[0])::3],s))) ```
vfc_39873
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2+2\n", "output": "-46\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "112-37\n", "output": "375\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "...
code_contests
verifiable_code
97_C. Winning Strategy
Solve the following coding problem using the programming language python: One university has just found out about a sport programming contest called ACM ICPC v2.0. This contest doesn't differ much from the well-known ACM ICPC, for example, the participants are not allowed to take part in the finals more than two times...
```python def main(): n=input() x=raw_input().split() ps=[float(s) for s in x] ret=0.0 for a in xrange(n): for b in xrange(a+1,n+1): if 2*a>n or 2*b<n:continue ca=( (0.5*n)-b ) / (a-b) cb=( (0.5*n)-a ) / (b-a) ret=max(ret, ca*ps[a]+cb*ps[b]) print "%.9f"%ret main() ```
vfc_39877
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1 1 1 1\n", "output": "1.0000000000\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n0.115590 0.384031 0.443128 0.562356\n", "output": "0.4286122500\n", "type": "stdin_std...
code_contests
verifiable_code
99_C. Help Victoria the Wise
Solve the following coding problem using the programming language python: Vasilisa the Wise from a far away kingdom got a present from her friend Helga the Wise from a farther away kingdom. The present is a surprise box, yet Vasilisa the Wise doesn't know yet what the surprise actually is because she cannot open the b...
```python from functools import reduce def factorial(n): return reduce(lambda x, y: x*y, range(1,n+1)) colors = { 'R' : 0, 'O' : 0, 'Y' : 0, 'G' : 0, 'B' : 0, 'V' : 0 } for c in list(input()): colors[c] += 1 amount = list(reversed(sorted([(colors[key], key) for key in colors]))) amo...
vfc_39881
{ "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": "YYYYYY\n", "output": "1\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
benny-and-the-universe
Solve the following coding problem using the programming language python: Hope you still have not forgotten about pig Benny. She is asking for help again. This time you have to answer some queries that Benny will give you. All actions happen in the Universe where each planet has its own id starting from 0. There ...
```python N,Q=map(int, raw_input().split()) arrD=map(int, raw_input().split()) if N==1: for iCase in xrange(Q): print "YES" if int(raw_input())%arrD[0]==0 else "NO" else: gcd=arrD[0] for i in xrange(1,N): b=arrD[i] while b: gcd,b=b,gcd%b if gcd>1: for i in xrange(N): arrD[i]/=gcd ...
vfc_39885
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 10\n3 4 7\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10", "output": "NO\nNO\nYES\nYES\nNO\nYES\nYES\nYES\nYES\nYES", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
compound-conversion-1
Solve the following coding problem using the programming language python: Jesse and Walter recently got a into a problem. They need to check if a compound can be converted to the other one. A compound is decoded into a binary strings of 0s and 1s. They have 2 binary strings. First string contains characters '0', '1' a...
```python ''' https://www.hackerearth.com/nit-calicut-codeburst-50/algorithm/compound-conversion-1/ ''' T = int(input()) negative_infinity = float("-inf") postive_infinity = float("inf") for tc in xrange(T): first = raw_input().strip() second = raw_input().strip() if len(first) != len(second): prin...
vfc_39889
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "200\n01?0001?0??1100000000110???1011010111101010?100?11??010?1???0000000110???1010010??00\n101010000011110111111110000100111101110110010111101110000100010100010110101100111100\n?101??0101?1000??????10011????0?100111?10?01\n11011000...
code_contests
verifiable_code
final-voyage-1
Solve the following coding problem using the programming language python: "RMS Lusitania" was one of the world biggest ship of her time.On the outbreak of the First World War in 1914, she was commandeered by the Admiralty as an armed merchant cruiser. When Lusitania left New York for Liverpool on what would be her fin...
```python def find(W,wt,val,n): i=0 K=[] while i<n+1: K.append([0]*(W+1)) i+=1 i=0 while i<=n: j=0 while j<=W: if i==0 or j==0: K[i][j]=0 elif wt[i-1]<=j: K[i][j]=max(val[i-1]+K[i-1][j-wt[i-1]],K[i-1][j]) else: ...
vfc_39893
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n3 \n3\n1 2 3 \n2 4 8\n4 \n8\n2 4 5 7\n4 9 7 5\n\nSAMPLE", "output": "8\n13", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
ikshus-love-for-binary-numbers
Solve the following coding problem using the programming language python: Ikshu's love for binary numbers Ikshu recently learnt to generate random numbers. He is generating stream binary numbers. Uptil now he has generated N bits of the binary number. Now, he wants to know if there is a streak of contiguous 1's of le...
```python n, k = map(int, raw_input().strip().split()) array = [0 for _ in range(k)] array.append(1) powers = [2 ** i for i in range(n+1)] for i in range(k+1, n+1): array.append(powers[i - k - 1] - array[i - k - 1] + 2 * array[i-1]) num = array[-1] denom = powers[-1] while num % 2 == 0: num = int(num / 2) denom...
vfc_39897
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 1\n\nSAMPLE", "output": "31/32\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 1\n\nS@MPLE", "output": "31/32\n", "type": "stdin_stdout" }, { "fn_name": null,...
code_contests
verifiable_code
marut-and-strings-4
Solve the following coding problem using the programming language python: Marut loves good strings. According to him, good strings are those which contain either all alphabets of uppercase or lowercase. While he is preparing for his exams, he finds many bad strings in his book and wants to convert them to good strings...
```python def test(S): l=len(S) if not (l>=1 and l<=100): print 'Invalid Input' elif S.isdigit(): print 'Invalid Input' else: counterL=0 counterU=0 idx=0 invalidChar=0 while idx < l: if ord(S[idx]) >= 65 and ord(S[idx])<=90 : ...
vfc_39901
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "0", "output": "Invalid Test\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\nabcd\nabCD", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "i...
code_contests
verifiable_code
numbers-of-interest-1
Solve the following coding problem using the programming language python: Harold always boasted about his prowess with numbers. So one day Reese challenged him to a problem. He gave Harold two numbers X and Y and asked him to find out the N^th number of the series which began with X numbers of Y’s and the following el...
```python no_of_test_cases = input() for i in range(0, no_of_test_cases): l = [] values = None values = raw_input().split(" ") x = int(values[0]) y = int(values[1]) n = int(values[2]) l = [y] * x while len(l) < n: b = sum(l[-x:]) l.append(b) print l[-1] ```
vfc_39905
{ "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 7\n\nSAMPLE", "output": "34\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10000\n14 2 42\n45 2 41\n13 0 13\n20 2 14\n15 0 7\n36 1 2\n3 0 26\n7 2 3\n27 1 48\n2 2 48\n23 0 9\n19 0 2...
code_contests
verifiable_code
rahuls-logo
Solve the following coding problem using the programming language python: Rahul has set upon the quest for a new logo of his company. He has created the following continuous logo: /\ / \ / /\ \ / / \ \ / / /\ \ \ \ \ \/ / / \ \ / / \ \/ / \ / \/ However, his sister, Rashi, likes the...
```python ## \ \ \/ / / ## \ \ / / ## \ \/ / ## \ / ## \/ ###n odd #n=7 n=int(input()) def fore(n): for i in range(n): if i % 2 == 0: strx = ((n-1-i)*" " + "/ "*(i//2) + "/\\" + (i//2) * " \\") print(strx) else: print(" " * (n-1-i) + (i//2+1)*'/ '...
vfc_39909
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n\nSAMPLE", "output": " /\\\n / \\\n/ /\\ \\\n \\ \\/ /\n \\ /\n \\/\n /\\ \n / \\ \n / /\\ \\ \n/ / \\ \\\n \\ \\ / /\n \\ \\/ / \n \\ / \n \\/ \n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
shivani-and-vinna
Solve the following coding problem using the programming language python: Akshit and Rahul are playing a game. Initially, two positive integers A and B are written on a blackboard. The players take turns, starting with Akshit. On his or her turn, a player can replace A with A - kB for any positive integer k, or replac...
```python def gcd(x,y): if ( x < y ): t = x x = y y = t if x % y == 0: return y else: return gcd(y,x%y) def isprime(n): i = 2 while i*i <= n: if n % i == 0: return False i = i + 1 return True t = int(raw_input()) for p in range(t): a,b,c,d = map(int,raw_input().split(" ")) count = 0 f...
vfc_39913
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n5 5 8 8\n11 11 2 2\n\nSAMPLE", "output": "Case #1: 0\nCase #2: 1", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n9 5 8 8\n11 11 2 2\n\nSAMPLE", "output": "Case #1: 0\nCase #2: 1\...
code_contests
verifiable_code
the-rise-of-the-weird-things-1
Solve the following coding problem using the programming language python: Bangalore City, where peace prevails most of the time. Not everyone is a huge fan of peace, though. Certainly not Mr. XYZ, whose identity is not known to us - yet. Mr. XYZ has somehow managed to bring vampires and zombies to Bangalore City to at...
```python ''' # Read input from stdin and provide input before running code name = raw_input('What is your name?\n') print 'Hi, %s.' % name ''' total = input() x = [] x = map(int, raw_input().split()) evenList = [] oddList = [] sumE = 0 sumO = 0 for i in x: if i%2 == 0 : evenList.append(i) evenList.sort() sumE ...
vfc_39917
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n2 3 10 12 15 22\n\nSAMPLE", "output": "2 10 12 22 46 3 15 18\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "100\n353 298 906 824 501 802 65 72 733 579 837 182 328 650 241 983 680 700 7...
code_contests
verifiable_code
p00093 Leap Year
Solve the following coding problem using the programming language python: Create a program that outputs all leap years between the year a and year b. The leap year conditions are as follows. However, 0 <a ≤ b <3,000. If there is no leap year in the given period, output "NA". * The year is divisible by 4. * However, ...
```python # -*- coding: utf-8 -*- """ http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0093 ???????????´ """ import sys def is_leap(year): ''' ?????????????????´??? ???????????´ ???????????????True/False??§?????? ''' if year % 400 == 0: return True elif year % 100 == 0: return False...
vfc_39965
{ "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": "2001 2010\n2005 2005\n2001 2010\n0 0", "output": "2004\n2008\n\nNA\n\n2004\n2008", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p00225 Kobutanukitsuneko
Solve the following coding problem using the programming language python: Relative B man came to A child's house. He is 3 years old and loves singing. He is singing the song "Kobutanuki Tsuneko" (written and composed by Naozumi Yamamoto), which he learned from kindergarten. In this song, the four words "kobuta," "racc...
```python from collections import* def searchnode(i,u,path): #つなげるものの個数の確認 r = 1 u[i] = 1 # print(u) for j in range(26): if path[(i,j)] and (not u[j]): r += searchnode(j,u,path) return r def chrtoint(a): return ord(a)-ord('a') while 1: n = int(input()) if n==0: ...
vfc_39969
{ "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\napple\nyellow\ngeorgia\nking\nemail\n7\napple\nyellow\ngeorgia\nking\nemail\nwink\nlucky\n0", "output": "NG\nOK", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p00603 Riffle Shuffle
Solve the following coding problem using the programming language python: There are a number of ways to shuffle a deck of cards. Riffle shuffle is one such example. The following is how to perform riffle shuffle. There is a deck of n cards. First, we divide it into two decks; deck A which consists of the top half of ...
```python from collections import deque import sys def suffle(deck, c): l = len(deck) if l % 2 == 0: mid = l//2 else: mid = (l-1)//2 deckA = deck[mid:] deckB = deck[:mid] deckC = [] while(len(deckA) != 0 or len(deckB) != 0): deckC.extend(deckA[:c]) deckA = deckA[c:] ...
vfc_39977
{ "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": "9 1\n3\n9 4\n1 2 3 4", "output": "3\n0", "type": "stdin_stdout" }, { "fn_name": null, "input": "9 1\n3\n9 4\n1 2 6 4", "output": "3\n0\n", "type": "stdin_stdout" }, { "fn_na...
code_contests
verifiable_code
p00740 Next Mayor
Solve the following coding problem using the programming language python: One of the oddest traditions of the town of Gameston may be that even the town mayor of the next term is chosen according to the result of a game. When the expiration of the term of the mayor approaches, at least three candidates, including the ...
```python while True: n, p = map(int, input().split()) if n == 0: break lst = [0] * n ind = 0 rest = p while True: if rest == 0: rest = lst[ind] lst[ind] = 0 else: lst[ind] += 1 rest -= 1 if lst[ind] == p: print(ind) break ind = (ind + 1) % n `...
vfc_39981
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 2\n3 3\n3 50\n10 29\n31 32\n50 2\n50 50\n0 0", "output": "1\n0\n1\n5\n30\n1\n13", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 2\n3 3\n3 50\n10 29\n57 32\n50 2\n50 50\n0 0", "outp...
code_contests
verifiable_code
p01010 Light Source
Solve the following coding problem using the programming language python: Problem N circular light sources are arranged on a two-dimensional plane. When a light source receives light, the light is emitted in a fan shape from the center point of the light source as shown in the figure below. <image> The center point ...
vfc_39989
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 8, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n90 10 10\n-3 0 1 45 10 90 10\n-6 0 2 30 3 180 10\n-9 0 1", "output": "10", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n90 10 20\n3 3 1 90 10 315 10\n6 0 1", "output": "30", ...
code_contests
verifiable_code
p01142 Karakuri Doll
Solve the following coding problem using the programming language python: Karakuri Doll Karakuri doll English text is not available in this practice contest. After many years of research, Karakuri puppeteer JAG has succeeded in developing a wonderful tea-drawing doll that combines traditional and latest techniques....
```python from collections import deque import sys readline = sys.stdin.readline write = sys.stdout.write def solve(): W, H = map(int, readline().split()) if W == H == 0: return False S = [readline().strip() for i in range(H)] dd = ((-1, 0), (0, -1), (1, 0), (0, 1)) sx = sy = gx = gy = 0 ...
vfc_39993
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 8, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 3\n#####\n#K.M#\n#####\n9 5\n#########\n#.....###\n#.###..M#\n#K#######\n#########\n9 5\n#########\n#K......#\n####.####\n####M####\n#########\n9 5\n#########\n#M......#\n####.####\n####K####\n#########\n7 9\n#######\n#####M#\n##...
code_contests
verifiable_code
p01281 Tatami
Solve the following coding problem using the programming language python: A tatami mat, a Japanese traditional floor cover, has a rectangular form with aspect ratio 1:2. When spreading tatami mats on a floor, it is prohibited to make a cross with the border of the tatami mats, because it is believed to bring bad luck....
```python def solve(): H, W = map(int, input().split()) if H == 0: return False if H*W % 2 == 1: print(0) return True state = [[-1]*W for i in range(H)] def dfs(k): if k == H*W: return 1 i, j = divmod(k, W) if state[i][j] != -1: ...
vfc_39997
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 8, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 4\n4 4\n0 0", "output": "4\n2", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 1\n4 4\n0 0", "output": "0\n2\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
p01451 Roads on Towns
Solve the following coding problem using the programming language python: The Kingdom of Neva is home to two ethnic groups, the Totata and the Tutete. The biggest feature of the Totata tribe is that they eat sweet and sour pork with pineapple. However, the Tutete tribe eats vinegared pork in pineapple. These two peopl...
```python import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**13 mod = 10**9+7 dd = [(-1,0),(0,1),(1,0),(0,-1)] ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] def LI(): return [int(x) for x in ...
vfc_40001
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 8, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 3\n4 0\n0 0\n2 3\n2 -2\n3 1", "output": "-1", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 2\n0 0\n1 1\n2 0\n2 -1", "output": "2.414213562373", "type": "stdin_stdout" },...
code_contests
verifiable_code
p01601 Palindromic Number
Solve the following coding problem using the programming language python: Palindrome Problem Statement Find the number of palindromes closest to the integer n. Note that the non-negative integer x is the number of palindromes, which means that the character string in which x is expressed in decimal notation and the...
```python n = int(input()) s = list(range(10)) for i in range(1, 100): t = str(i) s.append(t+t[::-1]) for j in range(10): s.append(t+str(j)+t[::-1]) s = list(map(int, s)) s.sort() if n in s: print(n) else: if n < s[0]: print(s[0]) elif n > s[-1]: print(s[-1]) else: ...
vfc_40005
{ "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": "13", "output": "11", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p01757 Tournament
Solve the following coding problem using the programming language python: This year too, the time has come for the National Programming Championships. In the district tournament where the right to participate in the national tournament is bet, 2n teams will face each other in a one-on-one winning tournament system. T...
```python import sys readline = sys.stdin.readline write = sys.stdout.write def solve(): N, M = map(int, readline().split()) *A, = map(int, readline().split()) *B, = map(int, readline().split()) C = [] prv = 0 for i in range(M): C.append((A[i+1] - prv, 1 << B[i])) prv = A[i+1] ...
vfc_40009
{ "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": "1 1\n0 2\n1", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1\n0 4\n1", "output": "1\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p02034 Round-trip String
Solve the following coding problem using the programming language python: E: Round-trip String story This is the world where all human beings have become competition programmers. In this world, there are many customs that you cannot think of in the present age. One of them is the custom of sending a character string...
vfc_40017
{ "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": "6\ntabata", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\natabat", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6...
code_contests
verifiable_code
p02177 iff
Solve the following coding problem using the programming language python: problem There are $ N $ propositions, named $ 1, 2, \ cdots, N $, respectively. Also, $ M $ information about the propositions is given. The $ i $ th information is "$ a_i $$". Given in the form "b_i $", which means that $ a_i $ is $ b_i $. ("I...
```python # -*- coding: utf-8 -*- import sys input = sys.stdin.readline def inpl(): return list(map(int, input().split())) N, M = inpl() G = [[] for _ in range(N)] rG = [[] for _ in range(N)] for i in range(M): a, b = inpl() G[a-1].append(b-1) rG[b-1].append(a-1) def SCC(G, rG): N = len(G) def d...
vfc_40021
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 268435456, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 2\n1 2\n2 1", "output": "1 2\n1 2\n3\n4\n5", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 2\n1 2\n2 2", "output": "1\n2\n3\n4\n5\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p02320 Knapsack Problem with Limitations
Solve the following coding problem using the programming language python: You have N items that you want to put them into a knapsack. Item i has value vi, weight wi and limitation mi. You want to find a subset of items to put such that: * The total value of the items is as large as possible. * The items have combine...
```python def main(): import sys from collections import deque input = sys.stdin.readline N, W = map(int, input().split()) dp = [0]*(W+1) for _ in [0]*N: v, w, m = map(int, input().split()) for ofs in range(w): q = deque() for j in range(W+1): ...
vfc_40025
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 100\n1 1 100\n2 1 50", "output": "150", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 8\n4 3 2\n2 1 1\n1 2 4\n3 2 2", "output": "12", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
arrgame2
Solve the following coding problem using the programming language python: Problem Statement Little Chef doesn't love math anymore. He loves Aleksandra. Sashen'ka is nice. They spend all the time together. Even their birthdays they are celebrating together, because they were born on the same day :) And now, this da...
```python import sys from bisect import bisect_left def line_to_array(): return map(int, sys.stdin.readline().strip().split(' ')) def main(): """ x**y | y*log(x) | log(x)/x | |--log--> |--divide by (x*y)--> |--> f(n) = log(n)/n y**x | ...
vfc_40033
{ "difficulty": "2", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1\n3\n4\n2\n2 3\n1 4\n2\n2 4\n2 2", "output": "1.000000\n1.500000\n0.000000", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
clco06
Solve the following coding problem using the programming language python: One night Mr.X and Mr.Y were playing a game. To test Mr.Y's intelligence Mr.X gives him an interesting problem to solve. He gives him a number N and asks him to swap the digits in the number such that a smallest number M is obtained without lead...
```python for a in range(input()): ins = sorted(val for val in raw_input()) if ins[0]=="0": for x in range(1,len(ins)): if int(ins[x])>0: ins[0] = ins[x] ins[x] = "0" break if "".join(ins) == raw_input(): print "AC" ...
vfc_40037
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n310\n103\n1\n2", "output": "AC\nWA", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n310\n129\n1\n2", "output": "WA\nWA\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
fest03
Solve the following coding problem using the programming language python: Golu is a student of Computer Engineering and he decided to make a project for himself.So he started working on URL shortner.While working on project he got confused.You are a good friend of Golu so he asked you for help. You have given a link a...
```python for _ in range(input()): s=raw_input() a=[0]*26 for i in s: if i>='a' and i<='z': a[ord(i)-97]+=1 m1=max(a) i=a.index(m1) a[i]=0 m2=max(a) j=a.index(m2) a[j]=0 m3=max(a) k=a.index(m3) a[k]=0 print 'ocul.in/'+str(chr(i+97))+str(m1)+str(chr(j+97))+str(m2)+str(chr(k+97))+str(m3) ```
vfc_40041
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\ncodechef.com\nfacebook.com/home/\nssss", "output": "ocul.in/c3e2o2\nocul.in/o4c2e2\nocul.in/s4a0a0", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
lecandy
Solve the following coding problem using the programming language python: A Little Elephant and his friends from the Zoo of Lviv like candies very much. There are N elephants in the Zoo. The elephant with number K (1 ≤ K ≤ N) will be happy if he receives at least AK candies. There are C candies in all in the Zoo. Th...
```python t=int(raw_input()) while t: t-=1 n,c=map(int,raw_input().split()) sum=0 inp2=raw_input().split() for i in range(n): sum+=int(inp2[i]) if sum<=c: print("Yes") else: print("No") ```
vfc_40045
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n2 3\n1 1\n3 7\n4 2 2", "output": "Yes\nNo\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
poker
Solve the following coding problem using the programming language python: In poker, you have 5 cards. There are 10 kinds of poker hands (from highest to lowest): royal flush - ace, king, queen, jack and ten, all in the same suit straight flush - five cards of the same suit in sequence, such as 10,9,8,7,6 of clubs; ...
```python #kcahdog straights=['23456','34567','45678','56789','6789T','789JT','89JQT','9JQKT','AJKQT','2345A'] for u in range(input()): cards=raw_input().split() flush=True #check for flush for i in range(4): if(cards[i][1]!=cards[i+1][1]): flush=False cards.sort() #check for...
vfc_40049
{ "difficulty": "2", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\nAH KH QH TH JH\nKH 5S 3C 5C 7D\nQH QD 2S QC 2C", "output": "royal flush\npair\nfull house\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\nAH KH QH TH JH\nKH 5S 3D 5C 7D\nQH QD 2S QC ...
code_contests
verifiable_code
subbxor
Solve the following coding problem using the programming language python: A straightforward question. Given an array of positive integers you have to print the number of subarrays whose XOR is less than K. Subarrays are defined as a sequence of continuous elements Ai, Ai+1, ..., Aj . XOR of a subarray is defined...
```python from sys import stdin raw_input = stdin.readline class Trie: def __init__(self): self.nextL = [-1] * 300000 self.nextR = [-1] * 300000 self.sizeL = [0] * 300000 self.sizeR = [0] * 300000 self.hash = 1 def...
vfc_40053
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n5 2\n4 1 3 2 7", "output": "3", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
100_C. A+B
Solve the following coding problem using the programming language python: Bijan is new to programming. He learned recently that programmers do not code every bit of their apps from scratch. For example they never write a code to sum two integers, because their languages have the ability to do the sum. But can they us...
vfc_40057
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 64000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n3\n", "output": "5\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1390\n2011\n", "output": "3401\n", "type": "stdin_stdout" }, { "fn_name": null, "input...
code_contests
verifiable_code
1032_G. Chattering
Solve the following coding problem using the programming language python: There are n parrots standing in a circle. Each parrot has a certain level of respect among other parrots, namely r_i. When a parrot with respect level x starts chattering, x neighbours to the right and to the left of it start repeating the same ...
vfc_40061
{ "difficulty": "13", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "8\n1 2 2 1 5 1 3 1\n", "output": "3 3 2 2 1 2 2 3 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n1 1 4 1\n", "output": "2 2 1 2 \n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
1077_F1. Pictures with Kittens (easy version)
Solve the following coding problem using the programming language python: The only difference between easy and hard versions is the constraints. Vova likes pictures with kittens. The news feed in the social network he uses can be represented as an array of n consecutive pictures (with kittens, of course). Vova likes ...
```python import sys S = sys.stdin.read() S = list(map(lambda x: list(map(int, x)), list(map(lambda x: x.split(), [x for x in S.split('\n') if len(x) > 1])))) n, k, x, B = S[0][0], S[0][1], S[0][2], S[1] X = [[-1 for i in range(x+1)] for i in range(n+1)] X[0][0] = 0 for i in range(1, n+1): for j in range(1, x+1):...
vfc_40069
{ "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 3 1\n1 100 1 1\n", "output": "100", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 2 3\n5 1 3 10 1\n", "output": "18", "type": "stdin_stdout" }, { "fn_name": nul...
code_contests
verifiable_code
1098_E. Fedya the Potter
Solve the following coding problem using the programming language python: Fedya loves problems involving data structures. Especially ones about different queries on subsegments. Fedya had a nice array a_1, a_2, … a_n and a beautiful data structure. This data structure, given l and r, 1 ≤ l ≤ r ≤ n, could find the grea...
vfc_40073
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 500000000}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n6 3\n", "output": " 6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n19 16 2 12 15\n", "output": " ...
code_contests
verifiable_code
1119_F. Niyaz and Small Degrees
Solve the following coding problem using the programming language python: Niyaz has a tree with n vertices numerated from 1 to n. A tree is a connected graph without cycles. Each edge in this tree has strictly positive integer weight. A degree of a vertex is the number of edges adjacent to this vertex. Niyaz does no...
vfc_40077
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n1 2 1\n1 3 2\n1 4 3\n1 5 4\n", "output": "10 6 3 1 0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n1 2 1\n2 3 2\n3 4 5\n4 5 14\n", "output": "22 6 0 0 0\n", "type": "st...
code_contests
verifiable_code
1146_C. Tree Diameter
Solve the following coding problem using the programming language python: There is a weighted tree with n nodes and n-1 edges. The nodes are conveniently labeled from 1 to n. The weights are positive integers at most 100. Define the distance between two nodes to be the sum of edges on the unique path between the nodes...
```python # AC import sys class Main: def __init__(self): self.buff = None self.index = 0 def next(self): if self.buff is None or self.index == len(self.buff): self.buff = sys.stdin.readline().split() self.index = 0 val = self.buff[self.index] s...
vfc_40081
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 4, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n5\n9\n6\n10\n9\n10\n2\n99\n", "output": "3 2 1 3 5 2 4\n2 3 2 3 1 4 5\n2 3 4 5 1 2 3\n-1 10\n5 4 1 3 5 7 9 2 4 6 8\n4 5 2 3 6 7 1 4 5 8 9\n4 5 4 5 6 7 1 2 3 8 9\n2 7 8 9 1 2 3 4 5 6 7\n-1 99\n", "type": "stdin_stdout...
code_contests
verifiable_code
1167_C. News Distribution
Solve the following coding problem using the programming language python: In some social network, there are n users communicating with each other in m groups of friends. Let's analyze the process of distributing some news between users. Initially, some user x receives the news from some source. Then he or she sends t...
```python import sys n, m = map(int, input().split()) par = [0] * (n + 1) cnt = [0] * (n + 1) for i in range(n + 1): par[i] = i def find(a): if par[a] == a: return a par[a] = find(par[a]) return par[a] for i in sys.stdin.readlines(): x = list(map(int, i[:-1].split())) if x[0]: ta = find(x[1]) ...
vfc_40085
{ "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 5\n3 2 5 4\n0\n2 1 2\n1 1\n2 6 7\n", "output": "4 4 1 4 4 2 2 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "7 2\n0\n0\n", "output": "1 1 1 1 1 1 1 ", "type": "stdin_stdout" ...
code_contests
verifiable_code
1185_F. Two Pizzas
Solve the following coding problem using the programming language python: A company of n friends wants to order exactly two pizzas. It is known that in total there are 9 pizza ingredients in nature, which are denoted by integers from 1 to 9. Each of the n friends has one or more favorite ingredients: the i-th of frie...
```python import sys import math input=sys.stdin.readline #sys.setrecursionlimit(1000000) I=lambda : list(map(int,input().split())) ma =int(10000000000000000) n,m=map(int,input().split()) a=[ma]*(515);a1=[ma]*(515);fr=[0]*(515);pos=[0]*(515) for i in range(n): b=I() x=int(0) for j in range(1,b[0]+1): ...
vfc_40089
{ "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": "1 5\n9 9 8 7 6 5 4 3 2 1\n3 4 1 2 3 4\n1 4 5 6 7 8\n4 4 1 3 5 7\n1 4 2 4 6 8\n5 4 1 9 2 8\n", "output": "4 2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 4\n2 6 7\n4 2 3 9 5\n3 2 3 9\...
code_contests
verifiable_code
1204_D1. Kirk and a Binary String (easy version)
Solve the following coding problem using the programming language python: The only difference between easy and hard versions is the length of the string. You can hack this problem only if you solve both problems. Kirk has a binary string s (a string which consists of zeroes and ones) of length n and he is asking you ...
```python s = str(input().strip()) t = list(s[::-1]) cnt = 0 for i,v in enumerate(t): if v == '0': cnt += 1 else: if cnt: cnt -= 1 else: t[i] = '0' print("".join(t[::-1])) ```
vfc_40093
{ "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": "0111001100111011101000\n", "output": "0011001100001011101000\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "0001111\n", "output": "0000000\n", "type": "stdin_stdout" }, ...
code_contests
verifiable_code
1221_B. Knights
Solve the following coding problem using the programming language python: You are given a chess board with n rows and n columns. Initially all cells of the board are empty, and you have to put a white or a black knight into each cell of the board. A knight is a chess piece that can attack a piece in cell (x_2, y_2) f...
```python n = int(input()) i = 0 s = ''.join(['W' if (i + j) % 2 == 0 else 'B' for i in range(n) for j in range(n)]) while(i<n*n): print(s[i:i+n]) i+=n ```
vfc_40097
{ "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\n", "output": "WBW\nBWB\nWBW\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n", "output": "WBWBWB\nBWBWBW\nWBWBWB\nBWBWBW\nWBWBWB\nBWBWBW\n", "type": "stdin_stdout" },...
code_contests
verifiable_code
1246_E. To Make 1
Solve the following coding problem using the programming language python: There are n positive integers written on the blackboard. Also, a positive number k ≥ 2 is chosen, and none of the numbers on the blackboard are divisible by k. In one operation, you can choose any two integers x and y, erase them and write one e...
vfc_40101
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 3\n7 8 13 23\n", "output": "YES\n23 13\n8 7\n5 4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 4\n1 2 3\n", "output": "NO\n", "type": "stdin_stdout" }, { "f...
code_contests
verifiable_code
1266_C. Diverse Matrix
Solve the following coding problem using the programming language python: Let a be a matrix of size r × c containing positive integers, not necessarily distinct. Rows of the matrix are numbered from 1 to r, columns are numbered from 1 to c. We can construct an array b consisting of r + c integers as follows: for each ...
```python import sys, os, io def rs(): return sys.stdin.readline().rstrip() def ri(): return int(sys.stdin.readline()) def ria(): return list(map(int, sys.stdin.readline().split())) def ws(s): sys.stdout.write(s + '\n') def wi(n): sys.stdout.write(str(n) + '\n') def wia(a): sys.stdout.write(' '.join([str(x) for x in a]...
vfc_40105
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 1\n", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 2\n", "output": "3 4 \n6 8 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "...
code_contests
verifiable_code
1287_E1. Madhouse (Easy version)
Solve the following coding problem using the programming language python: This problem is different with hard version only by constraints on total answers length It is an interactive problem Venya joined a tour to the madhouse, in which orderlies play with patients the following game. Orderlies pick a string s of le...
```python from bisect import bisect_left as bl from bisect import bisect_right as br import heapq import math from collections import * from functools import reduce,cmp_to_key import sys input = sys.stdin.readline # M = mod = 998244353 def factors(n):return sorted(list(set(reduce(list.__add__,([i, n//i] for i in rang...
vfc_40109
{ "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\n\na\naa\na\n\ncb\nb\nc\n\nc", "output": "? 1 4\n? 1 3\n! a^_f\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "99\nyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy...
code_contests
verifiable_code
1307_E. Cow and Treats
Solve the following coding problem using the programming language python: After a successful year of milk production, Farmer John is rewarding his cows with their favorite treat: tasty grass! On the field, there is a row of n units of grass, each with a sweetness s_i. Farmer John has m cows, each with a favorite swee...
```python import sys input = sys.stdin.readline from itertools import accumulate mod=10**9+7 n,m=map(int,input().split()) G=list(map(int,input().split())) CP=[[0]*(n+1) for i in range(n+1)] for i in range(m): f,e=map(int,input().split()) CP[f][e]+=1 SUMCP=[] for i in range(n+1): SUMCP.append(list(ac...
vfc_40113
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 2\n2 3 2\n3 1\n2 1\n", "output": "2 4", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1330_E. Drazil Likes Heap
Solve the following coding problem using the programming language python: Drazil likes heap very much. So he created a problem with heap: There is a max heap with a height h implemented on the array. The details of this heap are the following: This heap contains exactly 2^h - 1 distinct positive non-zero integers. A...
```python import io import os import sys # sys.stdin = open('input.txt', 'r') # sys.stdout = open('output.txt', 'w') fileno = sys.stdin.fileno() input = io.BytesIO( os.read(fileno, os.fstat(fileno).st_size) ).readline T = int(input()) def trim(A, h, g): N = len(A) ans = [] initial_root = 0 items_to_leave = ...
vfc_40117
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 500000000}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n3 2\n7 6 3 5 4 2 1\n3 2\n7 6 5 4 3 2 1\n", "output": "10\n1 1 3 3 \n8\n1 1 1 3 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n3 2\n7 6 3 5 4 2 1\n3 2\n7 6 5 4 3 2 1\n", "outp...
code_contests
verifiable_code
1350_E. Orac and Game of Life
Solve the following coding problem using the programming language python: Please notice the unusual memory limit of this problem. Orac likes games. Recently he came up with the new game, "Game of Life". You should play this game on a black and white grid with n rows and m columns. Each cell is either black or white....
```python import sys input = sys.stdin.readline n, m, t = map(int, input().split()) cell = [list(input().rstrip()) for _ in range(n)] cnt = [[False] * m for _ in range(n)] for i in range(n): for j in range(m): if i - 1 >= 0 and cell[i - 1][j] == cell[i][j]: cnt[i][j] = True if i + 1 < ...
vfc_40121
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 128000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 3 3\n000\n111\n000\n1 1 1\n2 2 2\n3 3 3\n", "output": "1\n1\n1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 2 2\n01\n10\n01\n10\n01\n1 1 4\n5 1 4\n", "output": "0\n0\n", ...
code_contests
verifiable_code
1371_A. Magical Sticks
Solve the following coding problem using the programming language python: A penguin Rocher has n sticks. He has exactly one stick with length i for all 1 ≤ i ≤ n. He can connect some sticks. If he connects two sticks that have lengths a and b, he gets one stick with length a + b. Two sticks, that were used in the ope...
```python for _ in range(int(input())): n=int(input()) print(max(1,n//2 + int(n%2))) ```
vfc_40125
{ "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\n1\n2\n3\n4\n", "output": "1\n1\n2\n2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n1\n2\n3\n8\n", "output": "1\n1\n2\n4\n", "type": "stdin_stdout" }, { "f...
code_contests
verifiable_code
1393_D. Rarity and New Dress
Solve the following coding problem using the programming language python: Carousel Boutique is busy again! Rarity has decided to visit the pony ball and she surely needs a new dress, because going out in the same dress several times is a sign of bad manners. First of all, she needs a dress pattern, which she is going ...
```python r,c=map(int,input().split()) rama=[] for i in range(r): rama.append(list((input()))) visit=[[1 for i in range(c)] for j in range(r)] for i in range(2,r): for j in range(1,c-1): if(rama[i][j]==rama[i-1][j-1]==rama[i-1][j+1]==rama[i-2][j]==rama[i-1][j]): visit[i][j]=min(visit[i-1][j...
vfc_40129
{ "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\nzbacg\nbaaac\naaaaa\neaaad\nweadd\n", "output": "31", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1436_B. Prime Square
Solve the following coding problem using the programming language python: Sasha likes investigating different math objects, for example, magic squares. But Sasha understands that magic squares have already been studied by hundreds of people, so he sees no sense of studying them further. Instead, he invented his own ty...
```python t = int(input()) for _ in range(t): n = int(input()) for j in range(n): b = [0] * n b[j] = 1 b[-j-1] = 1 if j != (n-1) and j != (n//2): print(*b) else: if n % 2 == 0: print(*b) else: if j == (n-...
vfc_40137
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 500000000}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n4\n2\n", "output": "1 1 0 0 \n\n0 1 1 0 \n\n0 0 1 1 \n\n1 0 0 1 \n\n1 1 \n\n1 1 \n\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
145_E. Lucky Queries
Solve the following coding problem using the programming language python: Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya brought home stri...
vfc_40141
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 5\n747\ncount\nswitch 1 1\ncount\nswitch 1 3\ncount\n", "output": "2\n3\n2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 3\n47\ncount\nswitch 1 2\ncount\n", "output": "2\n1\n",...
code_contests
verifiable_code
1486_A. Shifting Stacks
Solve the following coding problem using the programming language python: You have n stacks of blocks. The i-th stack contains h_i blocks and it's height is the number of blocks in it. In one move you can take a block from the i-th stack (if there is at least one block) and put it to the i + 1-th stack. Can you make t...
```python # https://codeforces.com/contest/1486/problem/0 import sys reader = (s.rstrip() for s in sys.stdin) input = reader.__next__ # do magic here t = int(input()) def check(arr): # print(arr) for x in range(len(arr)-1): if arr[x+1] <= arr[x]: return "NO" return "YES" for _ in ran...
vfc_40145
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000\n", "output": "\nYES\nYES\nYES\nNO\nNO\nYES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\...
code_contests
verifiable_code
150_E. Freezing with Style
Solve the following coding problem using the programming language python: This winter is so... well, you've got the idea :-) The Nvodsk road system can be represented as n junctions connected with n - 1 bidirectional roads so that there is a path between any two junctions. The organizers of some event want to choose a...
vfc_40149
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 7, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "8 3 6\n1 2 9\n2 3 7\n3 4 7\n4 5 8\n5 8 2\n3 6 3\n2 7 4\n", "output": "1 5\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 3 4\n1 2 1\n2 3 1\n3 4 1\n4 5 2\n5 6 2\n", "output": "6 3"...
code_contests
verifiable_code
163_B. Lemmings
Solve the following coding problem using the programming language python: As you know, lemmings like jumping. For the next spectacular group jump n lemmings gathered near a high rock with k comfortable ledges on it. The first ledge is situated at the height of h meters, the second one is at the height of 2h meters, an...
vfc_40157
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 3 2\n1 2 3 2 1\n1 2 1 2 10\n", "output": "1 5 2 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 3 10\n3 4 3 2 1\n5 4 3 2 1\n", "output": "4 3 1 \n", "type": "stdin_stdout"...