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
entexam
Solve the following coding problem using the programming language python: The faculty of application management and consulting services (FAMCS) of the Berland State University (BSU) has always been popular among Berland's enrollees. This year, N students attended the entrance exams, but no more than K will enter the u...
```python def entExam(N,K,E,M, D): scoreSet = [] for i in range(N-1): scoreSet.append(sum(D[i])) scoreSet = sorted(scoreSet) myScore = sum(D[-1]) if(scoreSet[N-K-1]+1 > myScore+M): print "Impossible" else: anw = scoreSet[N-K-1]-myScore+1 if(anw < 0): ...
vfc_80013
{ "difficulty": "1", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n4 2 3 10\n7 7 7\n4 6 10\n7 10 9\n9 9", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n4 2 3 10\n9 7 7\n4 6 10\n7 10 9\n9 9", "output": "6\n", "type": "stdin...
code_contests
verifiable_code
kjcc02
Solve the following coding problem using the programming language python: Sum and Color Chef is a mathematics student. His professor has given him a difficult task. Professor initially provides Chef with a list of numbers. For every number in the list, Chef has to calculate the sum 'S' of digits such that 0<=S<=9. Eve...
```python def con(a): summ=0 while True: summ+=a%10 a/=10 if(a==0): break if((summ/10)>=1): return con(summ) else: return summ for _ in xrange(input()): s_li=[] input() li=map(int,raw_input().split()) for j in xrange(len(li)): ...
vfc_80017
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n5\n128 25 87 50 1558\n4\n11 22 33 44\n3\n36 14 1000\n5\n11112 95 96 256 2669\n3\n10 991 83", "output": "yellow\ngreen\nbrown\ncyan\npink", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
orders
Solve the following coding problem using the programming language python: In Byteland it is always the military officer's main worry to order his soldiers on parade correctly. Luckily, ordering soldiers is not really such a problem. If a platoon consists of n men, all of them have different rank (from 1 - lowest to n ...
```python #!/bin/python import sys for z in range(int(raw_input())): l = int(raw_input()) data = map(int,raw_input().split()) out = range(1,l+1) for i in range(l-1,-1,-1): sol = out.pop(i-data[i]) out.insert(i,sol) print ' '.join(map(str,out)) ```
vfc_80021
{ "difficulty": "4", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n3\n0 1 0\n5\n0 1 2 0 1", "output": "2 1 3\n3 2 1 5 4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n3\n0 1 0\n5\n0 1 0 0 1", "output": "2 1 3\n2 1 3 5 4\n", "type": "std...
code_contests
verifiable_code
spoons
Solve the following coding problem using the programming language python: Lo and Behold! For you may be surprised by what our chief chef Noodle has in mind for this season! Today, Noodle announced one of his most extra-ordinary ideas ever - Project Spoon. Noodle plans to deploy large spoons in the atmosphere so that...
```python #!/usr/bin/python def factorial(a): res = 1 for i in range(1, a+1): res *= i return res # end of factorial def perestanovki(a,b): return factorial(a)/(factorial(b)*factorial(a-b)) # end of perestanovki def getIndex(start, end, a): ind = (start + end) / 2 if mins[ind] == a: ...
vfc_80025
{ "difficulty": "3", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n2\n3", "output": "2\n3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n2\n5", "output": "2\n4\n", "type": "stdin_stdout" }, { "fn_name": null, "input"...
code_contests
verifiable_code
1006_B. Polycarp's Practice
Solve the following coding problem using the programming language python: Polycarp is practicing his problem solving skill. He has a list of n problems with difficulties a_1, a_2, ..., a_n, respectively. His plan is to practice for exactly k days. Each day he has to solve at least one problem from his list. Polycarp s...
```python # Accepted: isVerbose = False def v(msg): if isVerbose: print(msg) n, k = map(int, input().split()) nums = list(enumerate(map(int, input().split()))) #print(n, k) #print(nums) nums.sort(key=lambda tup:tup[1]) #print(nums) nums_top = nums[-min(k, n):] #print(nums_top) nums_top.sort(key=lambda t...
vfc_80029
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "8 3\n5 4 2 6 5 1 9 2\n", "output": "20\n1 3 4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 2\n1 2000 2000 2\n", "output": "4000\n2 2\n", "type": "stdin_stdout" }, ...
code_contests
verifiable_code
1051_A. Vasya And Password
Solve the following coding problem using the programming language python: Vasya came up with a password to register for EatForces — a string s. The password in EatForces should be a string, consisting of lowercase and uppercase Latin letters and digits. But since EatForces takes care of the security of its users, use...
```python def check( s, L, R ): for i in s: if i>=L and i<=R: return False return True def ok(s): low = True; for i in s: if i>='a' and i<='z': low = False; break if low : return False low = True; for i in s: if i>='A' and i<='Z': low = False; break if low : return False low ...
vfc_80037
{ "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\nabcDCE\nhtQw27\n", "output": "1bcDCE\nhtQw27\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\nA00\n", "output": "Aa0\n", "type": "stdin_stdout" }, { "fn_name...
code_contests
verifiable_code
1073_B. Vasya and Books
Solve the following coding problem using the programming language python: Vasya has got n books, numbered from 1 to n, arranged in a stack. The topmost book has number a_1, the next one — a_2, and so on. The book at the bottom of the stack has number a_n. All numbers are distinct. Vasya wants to move all the books to...
```python #------------------------template--------------------------# import os import sys from math import * from collections import * # from fractions import * # from functools import * from heapq import * from bisect import * from io import BytesIO, IOBase def vsInput(): sys.stdin = open('input.txt', 'r') s...
vfc_80041
{ "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 2 3\n2 1 3\n", "output": "2 0 1 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n6 5 4 3 2 1\n6 5 3 4 2 1\n", "output": "1 1 2 0 1 1 ", "type": "stdin_stdout" }, ...
code_contests
verifiable_code
1095_B. Array Stabilization
Solve the following coding problem using the programming language python: You are given an array a consisting of n integer numbers. Let instability of the array be the following value: max_{i = 1}^{n} a_i - min_{i = 1}^{n} a_i. You have to remove exactly one element from this array to minimize instability of the res...
```python input() sequence = [int(i) for i in input().split(' ')] sequence.sort() a, b = sequence[-2] - sequence[0], sequence[-1] - sequence[1] print(a) if a < b else print(b) ```
vfc_80045
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n1 3 3 7\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1 100000\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "i...
code_contests
verifiable_code
1218_H. Function Composition
Solve the following coding problem using the programming language python: We are definitely not going to bother you with another generic story when Alice finds about an array or when Alice and Bob play some stupid game. This time you'll get a simple, plain text. First, let us define several things. We define function...
vfc_80069
{ "difficulty": "14", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 0, 'nanos': 500000000}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10\n2 3 1 5 6 4 2 10 7 7\n5\n10 1\n5 7\n10 6\n1 1\n10 8\n", "output": "3\n0\n1\n1\n0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n2 3 1 5 6 4 2 10 7 7\n4\n10 1\n5 7\n10 6\n1 1\n10 8...
code_contests
verifiable_code
1242_E. Planar Perimeter
Solve the following coding problem using the programming language python: Ujan has finally cleaned up his house and now wants to decorate the interior. He decided to place a beautiful carpet that would really tie the guest room together. He is interested in carpets that are made up of polygonal patches such that each...
vfc_80073
{ "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": "2\n3 3\n", "output": "4\n3 4 1 \n1 2 3 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n5 3 5\n", "output": "6\n5 4 3 6 1 \n1 6 2 \n1 2 3 4 5 \n", "type": "stdin_stdout" ...
code_contests
verifiable_code
1261_D2. Wrong Answer on test 233 (Hard Version)
Solve the following coding problem using the programming language python: Your program fails again. This time it gets "Wrong answer on test 233" . This is the harder version of the problem. In this version, 1 ≤ n ≤ 2⋅10^5. You can hack this problem if you locked it. But you can hack the previous problem only if you ...
vfc_80077
{ "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\n1 1 4 2 2\n", "output": "1000", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 2\n1 1 2 2 1 1\n", "output": "16", "type": "stdin_stdout" }, { "fn_name": null,...
code_contests
verifiable_code
1284_A. New Year and Naming
Solve the following coding problem using the programming language python: Happy new year! The year 2020 is also known as Year Gyeongja (경자년, gyeongja-nyeon) in Korea. Where did the name come from? Let's briefly look at the Gapja system, which is traditionally used in Korea to name the years. There are two sequences o...
```python from sys import stdin, stdout def main(): (n1, n2) = tuple([int(x) for x in stdin.readline().split()]) arr1 = [x for x in stdin.readline().split()] arr2 = [x for x in stdin.readline().split()] q = int(stdin.readline()) res = [] for i in range(0, q): year = int(stdin.readli...
vfc_80081
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 1024000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10 12\nsin im gye gap eul byeong jeong mu gi gyeong\nyu sul hae ja chuk in myo jin sa o mi sin\n14\n1\n2\n3\n4\n10\n11\n12\n13\n73\n2016\n2017\n2018\n2019\n2020\n", "output": "sinyu\nimsul\ngyehae\ngapja\ngyeongo\nsinmi\nimsi...
code_contests
verifiable_code
1303_C. Perfect Keyboard
Solve the following coding problem using the programming language python: Polycarp wants to assemble his own keyboard. Layouts with multiple rows are too complicated for him — his keyboard will consist of only one row, where all 26 lowercase Latin letters will be arranged in some order. Polycarp uses the same passwor...
```python ''' Hey stalker :) ''' INF = 10**10 def main(): print = out.append ''' Cook your dish here! ''' st = list(input()) keyboard = [] if len(set(st))>1: adj = defaultdict(set) for i in range(len(st)-1): adj[st[i]].add(st[i+1]) adj[st[i+1]].add(st[i]) ...
vfc_80085
{ "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\nababa\ncodedoca\nabcda\nzxzytyz\nabcdefghijklmnopqrstuvwxyza\n", "output": "YES\nabcdefghijklmnopqrstuvwxyz\nYES\nacodebfghijklmnpqrstuvwxyz\nNO\nYES\ntyzxabcdefghijklmnopqrsuvw\nNO\n", "type": "stdin_stdout" }, ...
code_contests
verifiable_code
1327_D. Infinite Path
Solve the following coding problem using the programming language python: You are given a colored permutation p_1, p_2, ..., p_n. The i-th element of the permutation has color c_i. Let's define an infinite path as infinite sequence i, p[i], p[p[i]], p[p[p[i]]] ... where all elements have same color (c[i] = c[p[i]] = ...
```python def monocolor_subcycle(start, divisor): for i in range(start, len(cycle), divisor): v = cycle[i] if c[v] != c[cycle[start]]: return False return True def any_monocolor_subcycle(divisor): for start in range(divisor): if monocolor_subcycle(start, divisor): ...
vfc_80089
{ "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\n4\n1 3 4 2\n1 2 2 3\n5\n2 3 4 5 1\n1 2 3 4 5\n8\n7 4 5 6 1 8 3 2\n5 3 6 4 7 5 8 4\n", "output": "1\n5\n2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n4\n1 3 4 2\n1 2 2 3\n5\n2 3 4...
code_contests
verifiable_code
1346_F. Dune II: Battle For Arrakis
Solve the following coding problem using the programming language python: You're at the last mission in one very old and very popular strategy game Dune II: Battle For Arrakis. The map of the mission can be represented as a rectangular matrix of size n × m. Initially, there are a_{i, j} units of your army in the cell ...
vfc_80093
{ "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": "3 3 1\n1 2 3\n2 1 2\n1 1 2\n2 3 100\n", "output": "\n21 22 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 4 3\n2 5 6 3\n4 8 10 5\n2 6 7 1\n8 4 2 1\n1 1 8\n2 3 4\n4 4 5\n", "outpu...
code_contests
verifiable_code
1368_D. AND, OR and square sum
Solve the following coding problem using the programming language python: Gottfried learned about binary number representation. He then came up with this task and presented it to you. You are given a collection of n non-negative integers a_1, …, a_n. You are allowed to perform the following operation: choose two dist...
```python from sys import stdin input = stdin.readline n = int(input()) a = [*map(lambda x: bin(int(x))[:1:-1], input().split())] c1 = len(max(a, key=len)) a = [x + '0' * (c1 - len(x)) for x in a] b = [sum(c[i] == '1' for c in a) for i in range(c1)] c2 = max(b) ans = 0 for i in range(c2): num = '' for i in range(c1):...
vfc_80097
{ "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": "1\n123\n", "output": "15129\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n1 3 5\n", "output": "51\n", "type": "stdin_stdout" }, { "fn_name": null, "inp...
code_contests
verifiable_code
1389_F. Bicolored Segments
Solve the following coding problem using the programming language python: You are given n segments [l_1, r_1], [l_2, r_2], ..., [l_n, r_n]. Each segment has one of two colors: the i-th segment's color is t_i. Let's call a pair of segments i and j bad if the following two conditions are met: * t_i ≠ t_j; * the s...
```python from operator import add class LazySegmentTree(): def __init__(self,n,init,merge=max,merge_unit=-10**18,operate=add,operate_unit=0): self.merge=merge self.merge_unit=merge_unit self.operate=operate self.operate_unit=operate_unit self.n=(n-1).bit_length() s...
vfc_80101
{ "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": "7\n19 20 1\n13 15 2\n6 11 2\n4 10 1\n14 17 1\n13 13 2\n5 9 1\n", "output": "5\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n5 8 1\n1 3 2\n3 4 2\n6 6 1\n2 10 2\n", "output": "4\n...
code_contests
verifiable_code
140_C. New Year Snowmen
Solve the following coding problem using the programming language python: As meticulous Gerald sets the table and caring Alexander sends the postcards, Sergey makes snowmen. Each showman should consist of three snowballs: a big one, a medium one and a small one. Sergey's twins help him: they've already made n snowball...
```python #!/usr/bin/env python3 from heapq import * from collections import defaultdict n = int(input()) r = map(int, input().split()) H = defaultdict(int) for t in r: H[t] += 1 D = [(-1 * v, k) for k, v in H.items()] heapify(D) ret = [] while len(D) > 2: a, b, c = heappop(D), heappop(D), heappop(D) ret...
vfc_80105
{ "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\n1 2 3 4 5 6 7\n", "output": "2\n7 6 5\n4 3 2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n2 2 3\n", "output": "0\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1430_G. Yet Another DAG Problem
Solve the following coding problem using the programming language python: You are given a directed acyclic graph (a directed graph that does not contain cycles) of n vertices and m arcs. The i-th arc leads from the vertex x_i to the vertex y_i and has the weight w_i. Your task is to select an integer a_v for each ver...
```python from heapq import heappush, heappop class MinCostFlow: INF = 10**18 def __init__(self, N): self.N = N self.G = [[] for i in range(N)] def add_edge(self, fr, to, cap, cost): forward = [to, cap, cost, None] backward = forward[3] = [fr, 0, -cost, forward] sel...
vfc_80109
{ "difficulty": "13", "memory_limit": null, "memory_limit_bytes": 1024000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 4\n1 2 1\n2 3 1\n1 3 6\n4 5 8\n", "output": "2 1 0 1 0 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 2\n2 1 4\n1 3 2\n", "output": "1 2 0 \n", "type": "stdin_stdout" ...
code_contests
verifiable_code
1505_D. Xenolith? Hippodrome?
Solve the following coding problem using the programming language python: Input The input contains two integers N, M (1 ≤ N ≤ 1024, 2 ≤ M ≤ 16), separated by a single space. Output Output "YES" or "NO". Examples Input 2 3 Output YES Input 3 2 Output NO Input 33 16 Output YES Input 26 5...
```python import sys import math import heapq import bisect from collections import Counter from collections import defaultdict from io import BytesIO, IOBase import string class FastIO(IOBase): newlines = 0 def __init__(self, file): import os self.os = os self._fd = file.fileno() ...
vfc_80121
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 3\n", "output": "\nYES\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1528_D. It's a bird! No, it's a plane! No, it's AaParsa!
Solve the following coding problem using the programming language python: There are n cities in Shaazzzland, numbered from 0 to n-1. Ghaazzzland, the immortal enemy of Shaazzzland, is ruled by AaParsa. As the head of the Ghaazzzland's intelligence agency, AaParsa is carrying out the most important spying mission in G...
```python import sys input = lambda: sys.stdin.readline().rstrip() def dijkstra(n, E, i0=0): D = [1 << 30] * n D[i0] = 0 Q = set([i for i in range(n)]) while Q: d = 1 << 30 for q in Q: if D[q] < d: i = q d = D[q] Q.remove(i) fo...
vfc_80125
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 5, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6 6\n0 0 1\n1 1 1\n2 2 1\n3 3 1\n4 4 1\n5 5 1\n", "output": "\n0 2 3 3 4 4 \n4 0 2 3 3 4 \n4 4 0 2 3 3 \n3 4 4 0 2 3 \n3 3 4 4 0 2 \n2 3 3 4 4 0 \n", "type": "stdin_stdout" }, { "fn_name": null, "inp...
code_contests
verifiable_code
178_F3. Representative Sampling
Solve the following coding problem using the programming language python: The Smart Beaver from ABBYY has a long history of cooperating with the "Institute of Cytology and Genetics". Recently, the Institute staff challenged the Beaver with a new problem. The problem is as follows. There is a collection of n proteins ...
vfc_80133
{ "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\naaa\nabba\nabbc\nabbd\n", "output": "9\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 3\neee\nrrr\nttt\nqqq\n", "output": "0\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
202_A. LLPS
Solve the following coding problem using the programming language python: This problem's actual name, "Lexicographically Largest Palindromic Subsequence" is too long to fit into the page headline. You are given string s consisting of lowercase English letters only. Find its lexicographically largest palindromic subse...
```python # -*- coding: utf-8 -*- """ Created on Thu Apr 2 19:56:34 2020 @author: roastedcoder This is for CodeForces """ mod = 1000000007 ssi = lambda : map(int,input().split()) # RoastedCoder s = input() l = [0]*26 for i in range(len(s)): l[ord(s[i])-97] += 1 for i in range(25,-1,-1): if(l[i] >= 1): ...
vfc_80137
{ "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": "mississipp\n", "output": "ssss\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
250_C. Movie Critics
Solve the following coding problem using the programming language python: A film festival is coming up in the city N. The festival will last for exactly n days and each day will have a premiere of exactly one film. Each film has a genre — an integer from 1 to k. On the i-th day the festival will show a movie of genre...
```python # ------------------- fast io -------------------- import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in...
vfc_80145
{ "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 3\n3 1 3 2 3 1 2\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10 3\n1 1 2 3 2 3 3 1 1 3\n", "output": "3\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
299_A. Ksusha and Array
Solve the following coding problem using the programming language python: Ksusha is a beginner coder. Today she starts studying arrays. She has array a1, a2, ..., an, consisting of n positive integers. Her university teacher gave her a task. Find such number in the array, that all array elements are divisible by it. ...
```python input() line = list(map(int, input().split())) line.sort() for i in line: if i % line[0] != 0: print(-1) break else: print(line[0]) ```
vfc_80153
{ "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\n2 3 5\n", "output": "-1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n2 1 3 1 6\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "i...
code_contests
verifiable_code
321_D. Ciel and Flipboard
Solve the following coding problem using the programming language python: Fox Ciel has a board with n rows and n columns, there is one integer in each cell. It's known that n is an odd number, so let's introduce <image>. Fox Ciel can do the following operation many times: she choose a sub-board with size x rows and x...
vfc_80157
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 4, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n-1 -1 1\n-1 1 -1\n1 -1 -1\n", "output": "9\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n-2 0 0 0 -2\n0 -2 0 -2 0\n0 0 -2 0 0\n0 -2 0 -2 0\n-2 0 0 0 -2\n", "output": "18\n", ...
code_contests
verifiable_code
36_A. Extra-terrestrial Intelligence
Solve the following coding problem using the programming language python: Recently Vasya got interested in finding extra-terrestrial intelligence. He made a simple extra-terrestrial signals’ receiver and was keeping a record of the signals for n days in a row. Each of those n days Vasya wrote a 1 in his notebook if he...
vfc_80165
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 64000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "8\n00111000\n", "output": "YES\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
391_D2. Supercollider
Solve the following coding problem using the programming language python: This problem consists of two subproblems: for solving subproblem D1 you will receive 3 points, and for solving subproblem D2 you will receive 16 points. Manao is the chief architect involved in planning a new supercollider. He has to identify a...
vfc_80169
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 2\n4 0 9\n1 1 8\n1 2 7\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1\n0 0 99999998\n-49999999 50000000 99999999\n", "output": "49999998\n", "type": "st...
code_contests
verifiable_code
414_A. Mashmokh and Numbers
Solve the following coding problem using the programming language python: It's holiday. Mashmokh and his boss, Bimokh, are playing a game invented by Mashmokh. In this game Mashmokh writes sequence of n distinct integers on the board. Then Bimokh makes several (possibly zero) moves. On the first move he removes the ...
```python from __future__ import division, print_function import os import sys from io import BytesIO, IOBase def main(): n, k = [ int(x) for x in input().split() ] x = k - (n // 2 - 1) if x < 1 or (n < 2 and k > 0): print(-1) return sequence = [0] * n sequence[0] = x if n...
vfc_80173
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7 2\n", "output": "-1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 2\n", "output": "1 2 3 4 5", "type": "stdin_stdout" }, { "fn_name": null, "input": "...
code_contests
verifiable_code
440_C. One-Based Arithmetic
Solve the following coding problem using the programming language python: Prof. Vasechkin wants to represent positive integer n as a sum of addends, where each addends is an integer number containing only 1s. For example, he can represent 121 as 121=111+11+–1. Help him to find the least number of digits 1 in such sum....
```python import math def find(n,i): ans = 0 k = n // ones[i] n = n % ones[i] ans = ans + k * i if n == 0: return ans return ans + min(find(n, i-1), i + find(ones[i] - n, i-1)) n = int(input()) ones = [0] for i in range(1,17): one = 10 * ones[i-1] + 1 ones.append(one) print(find(n,16)) ```
vfc_80177
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 0, 'nanos': 500000000}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "121\n", "output": "6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n", "output": "5\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
462_E. Appleman and a Sheet of Paper
Solve the following coding problem using the programming language python: Appleman has a very big sheet of paper. This sheet has a form of rectangle with dimensions 1 × n. Your task is help Appleman with folding of such a sheet. Actually, you need to perform q queries. Each query will have one of the following types: ...
vfc_80181
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7 4\n1 3\n1 2\n2 0 1\n2 1 2\n", "output": "4\n3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10 9\n2 2 9\n1 1\n2 0 1\n1 8\n2 0 8\n1 2\n2 1 3\n1 4\n2 2 4\n", "output": "7\n2\n10\n4...
code_contests
verifiable_code
486_D. Valid Sets
Solve the following coding problem using the programming language python: As you know, an undirected connected graph with n nodes and n - 1 edges is called a tree. You are given an integer d and a tree consisting of n nodes. Each node i has a value ai associated with it. We call a set S of tree nodes valid if followi...
```python import sys def readInts(): return [int(x) for x in sys.stdin.readline().split()] def readInt(): return int(sys.stdin.readline()) # def print(x): # sys.stdout.write(str(x) + '\n') def solve(): MOD = int(1e9 + 7) d, n = readInts() a = readInts() adj: list = [[] for _ in range(n)] ...
vfc_80185
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 8\n7 8 7 5 4 6 4 10\n1 6\n1 2\n5 8\n1 3\n3 5\n6 7\n3 4\n", "output": "41", "type": "stdin_stdout" }, { "fn_name": null, "input": "0 3\n1 2 3\n1 2\n2 3\n", "output": "3", "type": "stdin_...
code_contests
verifiable_code
50_C. Happy Farm 5
Solve the following coding problem using the programming language python: The Happy Farm 5 creators decided to invent the mechanism of cow grazing. The cows in the game are very slow and they move very slowly, it can even be considered that they stand still. However, carnivores should always be chased off them. For ...
```python import math n = int(input()) l = [] for i in range(n): l.append(tuple(list(map(int, input().split(" "))))) l = list(set(l)) n = len(l) pmin = 0 for i in range(1, n): if(l[i][1] < l[pmin][1] or (l[i][1] == l[pmin][1] and l[i][0] < l[pmin][0])): pmin = i l[pmin], l[0] = l[0], l[pmin] def or...
vfc_80189
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n1 1\n5 1\n5 3\n1 3\n", "output": "16\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n0 2\n2 0\n3 5\n5 3\n", "output": "14\n", "type": "stdin_stdout" }, { "f...
code_contests
verifiable_code
534_E. Berland Local Positioning System
Solve the following coding problem using the programming language python: In Berland a bus travels along the main street of the capital. The street begins from the main square and looks like a very long segment. There are n bus stops located along the street, the i-th of them is located at the distance ai from the cen...
```python r = lambda: list(map(int, input().split())) ri = lambda: int(input()) n, a, m, b = ri(), r(), ri(), r() c = [0] * n for e in b: c[e - 1] += 1 c[0] *= 2; c[-1] *= 2 d = 0 df= 0 r = max(e // 2 for e in c) c = [e - r * 2 for e in c] if any(c): for i in range(n - 1): de = a[i+1] - a[i] d += mi...
vfc_80193
{ "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\n10 200 300\n4\n1 2 2 3\n", "output": "-1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n1 2 3\n4\n1 2 2 3\n", "output": " ...
code_contests
verifiable_code
559_E. Gerald and Path
Solve the following coding problem using the programming language python: The main walking trail in Geraldion is absolutely straight, and it passes strictly from the north to the south, it is so long that no one has ever reached its ends in either of the two directions. The Geraldionians love to walk on this path at a...
vfc_80197
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 4, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1 1\n2 2\n3 3\n", "output": "5\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n1 2\n3 3\n4 3\n6 2\n", "output": "9\n", "type": "stdin_stdout" }, { "fn_name"...
code_contests
verifiable_code
585_C. Alice, Bob, Oranges and Apples
Solve the following coding problem using the programming language python: Alice and Bob decided to eat some fruit. In the kitchen they found a large bag of oranges and apples. Alice immediately took an orange for herself, Bob took an apple. To make the process of sharing the remaining fruit more fun, the friends decid...
```python import fractions def solve(x, y): if fractions.gcd(x, y) > 1: return 'Impossible' turn = x > y if not turn: x, y = y, x ans = [] while x != 0 and y != 0: ans.append((x//y, 'A' if turn else 'B')) x, y = y, x%y turn = not turn ans[-1] = (ans[-1][0]-1, ans[-1][1]) ...
vfc_80201
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 2\n", "output": "Impossible\n\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 4\n", "output": "3B\n", "type": "stdin_stdout" }, { "fn_name": null, "inpu...
code_contests
verifiable_code
629_B. Far Relative’s Problem
Solve the following coding problem using the programming language python: Famil Door wants to celebrate his birthday with his friends from Far Far Away. He has n friends and each of them can come to the party in a specific range of days of the year from ai to bi. Of course, Famil Door wants to have as many friends cel...
```python n = (int)(input()) F1=[0]*n F2=[0]*n M1=[0]*n M2=[0]*n m=0 f=0 for i in range(n): c = (input().split()) if(c[0]=='M'): M1[m]=(int)(c[1]) M2[m]=(int)(c[2]) m=m+1 if(c[0]=='F'): F1[f]=(int)(c[1]) F2[f]=(int)(c[2]) f=f+1 F=[0]*3232 M=[0]*3266 for i in r...
vfc_80209
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\nM 151 307\nF 343 352\nF 117 145\nM 24 128\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\nM 128 130\nF 128 131\nF 131 140\nF 131 141\nM 131 200\nM 140 200\n", ...
code_contests
verifiable_code
679_A. Bear and Prime 100
Solve the following coding problem using the programming language python: This is an interactive problem. In the output section below you will see the information about flushing the output. Bear Limak thinks of some hidden number — an integer from interval [2, 100]. Your task is to say if the hidden number is prime o...
```python #------------------------template--------------------------# import os import sys from math import * from collections import * # from fractions import * # from heapq import* from bisect import * from io import BytesIO, IOBase def vsInput(): sys.stdin = open('input.txt', 'r') sys.stdout = open('output....
vfc_80217
{ "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": "yes\nno\nyes\n", "output": "2\n3\n5\n7\n11\n13\n17\n19\n23\n29\n31\n37\n41\n43\n47\n4\n9\n25\n49\ncomposite\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "no\nyes\nno\nno\nno\n", "o...
code_contests
verifiable_code
701_B. Cells Not Under Attack
Solve the following coding problem using the programming language python: Vasya has the square chessboard of size n × n and m rooks. Initially the chessboard is empty. Vasya will consequently put the rooks on the board one after another. The cell of the field is under rook's attack, if there is at least one rook loca...
```python n, m = map(int, input().strip().split()) remains = n*n deleted_rows = set() deleted_cols = set() answer = [] for _ in range(m): c, r = map(int, input().strip().split()) col_deleted = c in deleted_cols row_deleted = r in deleted_rows if not (col_deleted and row_deleted): if col_deleted...
vfc_80221
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 2\n1 5\n5 1\n", "output": "16 9\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "100000 1\n300 400\n", "output": "9999800001\n", "type": "stdin_stdout" }, { "fn_...
code_contests
verifiable_code
723_C. Polycarp at the Radio
Solve the following coding problem using the programming language python: Polycarp is a music editor at the radio station. He received a playlist for tomorrow, that can be represented as a sequence a1, a2, ..., an, where ai is a band, which performs the i-th song. Polycarp likes bands with the numbers from 1 to m, but...
```python from collections import Counter n, m = map(int, input().split()) nums = list(map(int, input().split())) cnts = dict(Counter(nums)) for i in range(1, m+1): if i not in cnts: cnts[i] = 0 def minner(): return min(cnts.items(), key=lambda x: x[1]) n //= m res = 0 for i, num in enumerate(nums...
vfc_80225
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 2\n1 2 3 2\n", "output": "2 1\n1 2 1 2 ", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
768_D. Jon and Orbs
Solve the following coding problem using the programming language python: Jon Snow is on the lookout for some orbs required to defeat the white walkers. There are k different types of orbs and he needs at least one of each. One orb spawns daily at the base of a Weirwood tree north of the wall. The probability of this ...
```python k, q = map(int, input().split()) t = [0] * (k + 1) t[1] = 1 c = [0] n = i = 1 while i < 1001: if (2000 * t[k] > i - (10**-7)): c.append(n) i += 1 else: t = [0] + [(j * t[j] + (k - j + 1) * t[j - 1]) / k for j in range(1, k + 1)] n += 1 for i in range(q): print(c[in...
vfc_80233
{ "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": "1 1\n1\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 2\n1\n2\n", "output": "2\n2\n", "type": "stdin_stdout" }, { "fn_name": null, "inpu...
code_contests
verifiable_code
792_C. Divide by Three
Solve the following coding problem using the programming language python: A positive integer number n is written on a blackboard. It consists of not more than 105 digits. You have to transform it into a beautiful number by erasing some of the digits, and you want to erase as few digits as possible. The number is call...
```python a = input() if len(a) == 1: if int(a) % 3 == 0: print(a) else: print(-1) exit(0) one = [] two = [] sum = 0 zs, zf = 0, 0 for i in range(len(a)): q = int(a[i]) sum += q if q == 0: if zs == 0: zs = i else: if zs != 0 and zf == 0: ...
vfc_80237
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10\n", "output": "0\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
812_E. Sagheer and Apple Tree
Solve the following coding problem using the programming language python: Sagheer is playing a game with his best friend Soliman. He brought a tree with n nodes numbered from 1 to n and rooted at node 1. The i-th node has ai apples. This tree has a special property: the lengths of all paths from the root to any leaf h...
```python n= int(input()) a = [int(_) for _ in input().split()] c = [int(_) for _ in input().split()] depth = [0] * (n) for i in range(1,n): depth[i] = depth[c[i-1]-1] + 1 MAX = max(depth) t = 0 store = {} todo = [] p = 0 for i in range(n): if (MAX-depth[i]) % 2 == 0: # odd, useful t ^= a[i] todo...
vfc_80241
{ "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": "8\n7 2 2 5 4 3 1 1\n1 1 1 4 4 5 6\n", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n1 2 3\n1 1\n", "output": "0\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
838_E. Convex Countour
Solve the following coding problem using the programming language python: You are given an strictly convex polygon with n vertices. It is guaranteed that no three points are collinear. You would like to take a maximum non intersecting path on the polygon vertices that visits each point at most once. More specifically...
vfc_80245
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n0 0\n0 1\n1 1\n1 0\n", "output": "3.414213562373094923\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "7\n-1000000000 -999999999\n-1000000000 999999999\n-999999999 1000000000\n86871471 ...
code_contests
verifiable_code
859_B. Lazy Security Guard
Solve the following coding problem using the programming language python: Your security guard friend recently got a new job at a new security company. The company requires him to patrol an area of the city encompassing exactly N city blocks, but they let him choose which blocks. That is, your friend must walk the peri...
```python import math n=int(input()) print(math.ceil(math.sqrt(n)*2)*2) ```
vfc_80249
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "22\n", "output": "20\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "11\n", "output": "14\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n", ...
code_contests
verifiable_code
884_A. Book Reading
Solve the following coding problem using the programming language python: Recently Luba bought a very interesting book. She knows that it will take t seconds to read the book. Luba wants to finish reading as fast as she can. But she has some work to do in each of n next days. The number of seconds that Luba has to sp...
```python n,t=map(int,input().split()) a=input().split() i=0 while t > 0: t-=(86400-int(a[i])) i += 1 print(i) ```
vfc_80253
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 2\n86400 86398\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 86400\n0 86400\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": nul...
code_contests
verifiable_code
908_C. New Year and Curling
Solve the following coding problem using the programming language python: Carol is currently curling. She has n disks each with radius r on the 2D plane. Initially she has all these disks above the line y = 10100. She then will slide the disks towards the line y = 0 one by one in order from 1 to n. When she slid...
```python n, r = map(int, input().split()) a = input().split() ans = [] for i in range(n): res = r for j in range(i): if (abs(int(a[j]) - int(a[i])) <= 2 * r): res = max(res, ans[j] + (4 * r * r - abs(int(a[j]) - int(a[i])) ** 2) ** 0.5) ans.append(res) for i in range(n): print(ans[i...
vfc_80257
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6 2\n5 5 6 8 3 12\n", "output": "2 6.0 9.872983346207416 13.33708496134517 12.518734657272006 13.33708496134517\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1\n5\n", "output": "...
code_contests
verifiable_code
92_B. Binary Number
Solve the following coding problem using the programming language python: Little walrus Fangy loves math very much. That's why when he is bored he plays with a number performing some operations. Fangy takes some positive integer x and wants to get a number one from it. While x is not equal to 1, Fangy repeats the fol...
```python from collections import * def add(n): for i in range(len(n) - 1, -1, -1): if n[i] == '1': n[i] = '0' else: n[i] = '1' return n n.appendleft('1') return n def main(): n, ans = deque(input()), 0 while (len(n) != 1): if n[-1] ==...
vfc_80261
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "101110\n", "output": "8\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "100100...
code_contests
verifiable_code
983_B. XOR-pyramid
Solve the following coding problem using the programming language python: For an array b of length m we define the function f as f(b) = \begin{cases} b[1] & if m = 1 \\\ f(b[1] ⊕ b[2],b[2] ⊕ b[3],...,b[m-1] ⊕ b[m]) & otherwise, \end{cases} where ⊕ is [bitwise exclusive OR](https://en.wikipedia.org/wiki/Bitw...
```python n = int(input()) arr = list(map(int, input().split())) aux = [[0] * n for i in range(n)] for i in range(n): aux[0][i] = arr[i] for i in range(1, n): for j in range(n-i): aux[i][j] = aux[i-1][j] ^ aux[i-1][j+1] for i in range(1, n): for j in range(n-i): aux[i][j] = max(aux[i][j], aux[i-1][...
vfc_80269
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n1 2 4 8 16 32\n4\n1 6\n2 5\n3 4\n1 2\n", "output": "60\n30\n12\n3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n8 4 1\n2\n2 3\n1 2\n", "output": "5\n12\n", "type": "std...
code_contests
verifiable_code
a-new-order
Solve the following coding problem using the programming language python: Consider a new order of english alphabets (a to z), that we are not aware of. What we have though, dictionary of words, ordered according to the new order. Our task is to give each alphabet a rank, ordered list of words. The rank of an alphabet...
```python Adj = {} root = {} def add(a, b): if a in Adj: Adj[a]["child"].add(b) else: Adj[a] = {"rank":0, "child":set([b])} if b in Adj: if b in root: del root[b] return else: if b in root: del root[b] Adj[b] = {"rank":0, "child":set()} def addv(a): if a in Adj: return else: Adj[a] = {"...
vfc_80273
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\naaabc\naaade\nbacd\ncde\ncda\ncca\n\nSAMPLE", "output": "e\na\nb\nd\nc", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
bitwise-1
Solve the following coding problem using the programming language python: You are a member of a bomb-disposal squad. Each bomb is identified by a unique serial id X, which is a positive integer. To disarm the bomb, a positive integral key Y needs to be entered such that X + Y = X ⊕ Y (here "⊕" denotes the bit-wise XO...
```python z=input() for i in range(z): x,y=map(int,raw_input().split()) c=0 j=1 while True: if x+j==x^j: c+=1 if y==c: break j+=1 print "Case #"+str(i+1)+": "+str(j) ```
vfc_80277
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n16 3\n8 1\n\nSAMPLE", "output": "Case #1: 3\nCase #2: 1", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n16 6\n8 1\n\nSAMPLE", "output": "Case #1: 6\nCase #2: 1\n", "type": ...
code_contests
verifiable_code
crazy-numbers-1
Solve the following coding problem using the programming language python: Golu is crazy about numbers. He loves those numbers such that the difference between the adjacent digits of that number is exactly one. He calls these numbers crazy numbers and wants to find out how many such numbers exist for N number of digits...
```python def crazy(n): if n==0: return 0 table = [[0]*n for _ in range(10)] for j in range(n): for i in range(10): if j==0: table[i][j] = 1 else: if 0<i and i<9: if i==1 and j==1: table[i][j] = table[i+1][j-1] else: table[i][j] = table[i-1][j-1] + table[i+1][j-1] elif i==...
vfc_80281
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n1\n2\n\nSAMPLE", "output": "10\n17", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
flip-the-world
Solve the following coding problem using the programming language python: Flip the world is a game. In this game a matrix of size N*M is given, which consists of numbers. Each number can be 1 or 0 only. The rows are numbered from 1 to N, and the columns are numbered from 1 to M. Following steps can be called as a sin...
```python T = input() board = [] def flipSquare(n, m): if board[n][m]: return 0 else: for i in xrange(n + 1): for j in xrange(m + 1): board[i][j] = not board[i][j] return 1 def flipRow(n): moves = 0 for m in reversed(xrange(len(board[n]))): moves += flipSquare(n, m) return moves for _ in xrange(T)...
vfc_80285
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n5 5\n00011\n00011\n00011\n11111\n11111\n\nSAMPLE", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "30\n1 1\n1\n1 1\n0\n4 4\n0000\n1110\n0101\n1011\n4 4\n1100\n0010\n1010\n1...
code_contests
verifiable_code
jholibaba-and-his-wish
Solve the following coding problem using the programming language python: JholiBaba is a student of vnit and he has a craze for rotation. A Roller contest is organized in vnit which JholiBaba wants to win. In the contest, there is one roller which is represented similar to a strip of 1xN blocks. Each block has a numbe...
```python n = int(raw_input()) a = map(int, raw_input().split()) s = sum(a) p = sum((i+1) * a[i] for i in xrange(n)) ans = p for i in xrange(n-1): p += a[i] * n - s ans = max(ans, p) print ans ```
vfc_80289
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n20 30 10\n\nSAMPLE", "output": "140", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n-12452 90611 67470 -528 -9054", "output": "643802", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
mike-and-his-guitar-collection-3
Solve the following coding problem using the programming language python: Mike has a huge guitar collection which the whole band is jealous of. Brad, the lead guitarist of the band, gave Mike a challenge so that he can't use all his guitars. The band is on a world tour and Brad told Mike to assign numbers to all his g...
```python from itertools import combinations for _ in range(input()): arr=[] n=input() a=map(int,raw_input().split()) for i in range(n+1): comb = combinations(a,i) arr.append(comb) count=0 sumset=set() # Print the obtained combinations for it in arr: for i in list(it): #print i sumse...
vfc_80293
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1\n1\n2\n1 2\n3\n1 2 3\n\nSAMPLE", "output": "2\n4\n7\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n1\n1\n2\n1 2\n3\n1 2 3\n\nSAMPKE", "output": "2\n4\n7\n", "type": "s...
code_contests
verifiable_code
p1-6
Solve the following coding problem using the programming language python: Raj's lucky number is 101. His girl friend Rani wants to give him a string S as a birthday present to him. She went to a shop and there are variety of strings which contains only 1 and 0 ( Binary string ) in that shop. Now in order to impress R...
```python def num(seq, sub): m, n = len(seq), len(sub) table = [0] * n for i in xrange(m): previous = 1 for j in xrange(n): current = table[j] if seq[i] == sub[j]: table[j] += previous previous = current return table[n-1] if n else 1 x...
vfc_80297
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10101\n\nSAMPLE", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10101\n\nELPMAS", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
remove-friends-5
Solve the following coding problem using the programming language python: After getting her PhD, Christie has become a celebrity at her university, and her facebook profile is full of friend requests. Being the nice girl she is, Christie has accepted all the requests. Now Kuldeep is jealous of all the attention she i...
```python for i in range(input()): N, K = [int(i) for i in raw_input().split()] P = [int(i) for i in raw_input().split()] stack = [] count = 0 for p in P: while len(stack) > 0 and count < K and stack[-1] < p: stack.pop() count += 1 stack.append(p) if count < K: stack =...
vfc_80301
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n3 1\n3 100 1\n5 2\n19 12 3 4 17\n5 3\n23 45 11 77 18\n\nSAMPLE", "output": "100 1\n19 12 17\n77 18\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n3 0\n3 100 1\n5 2\n19 12 3 4 17\n5 ...
code_contests
verifiable_code
sonas-number-sequence
Solve the following coding problem using the programming language python: Sona is busy in organizing Port '16. Sona has to formulate two number sequence as two list. As she loves numbers she wrote the two number sequence in two different papers. Both the list have N numbers. She also named the number sequence as A a...
```python ''' # Read input from stdin and provide input before running code name = raw_input('What is your name?\n') print 'Hi, %s.' % name ''' n=input() b=map(int,raw_input().split()) a=[b[0]] for i in xrange(1,n): e=b[i]*(i+1) e=e-sum(a) a.append(e) for i in a: print i, ```
vfc_80305
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n10 11 12 13 14\n\nSAMPLE", "output": "10 12 14 16 18\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n10 11 12 13 14\n\nSAMOLE", "output": "10 12 14 16 18\n", "type": "std...
code_contests
verifiable_code
tom-and-coins
Solve the following coding problem using the programming language python: Problem Statement: Tom is collecting money for his birthday party, he is having 'a' coins today and his father gives him 'k' coins each day. Since his birthday is on 'nth' day, he wants to know the amount of money he will have on his birthday...
```python t = int(raw_input()) for cases in range(t): a, k, n = raw_input().split() coins = int(a) + int(k) * (int(n) - 1) print coins ```
vfc_80309
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n2 2 3\n1 2 3\n1 0 3\n\nSAMPLE", "output": "6\n5\n1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "100\n84 87 78\n16 94 36\n87 93 50\n22 63 28\n91 60 64\n27 41 27\n73 37 12\n69 68 30\n8...
code_contests
verifiable_code
p00118 Property Distribution
Solve the following coding problem using the programming language python: Mr. Tanaka died leaving the orchard of HW Earl. The orchard is divided into H x W plots in the north, south, east, and west directions, and apples, oysters, and oranges are planted in each plot. Mr. Tanaka left such a will. Divide the orchard i...
```python import sys sys.setrecursionlimit(100000) def solve(x, y, char): for deltaX in [1, -1]: if 0 <= x + deltaX and x + deltaX < w and matrix[y][x + deltaX] == char: matrix[y][x + deltaX] = "." solve(x+deltaX, y, char) for deltaY in [1, -1]: if 0 <= y + deltaY and y...
vfc_80357
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10 10\n*****@\n@#@@@@#*#*\n@##***@@@*\n****#*@**\n@*#@@*##\n*@@@@*@@@#\n***#@*@##*\n*@@@*@@##@\n*@*#*@##**\n@****#@@#@\n0 0", "output": "33", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p00432 Sheets
Solve the following coding problem using the programming language python: There are several rectangular sheets placed on a flat surface. Create a program to find the area and perimeter of the part covered by these sheets. However, when the plane is regarded as the coordinate plane, the arrangement of the sheets shall...
vfc_80365
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 5, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 1\n0 0 3 2\n1 1 2 5\n0 4 6 5\n3 3 5 6\n5 0 7 6\n5 2\n0 0 3 2\n1 1 2 5\n0 4 6 5\n3 3 5 6\n5 0 7 6\n2 2\n0 0 8 9\n0 0 9 8\n3 2\n2 2 8 8\n3 0 4 9\n5 0 7 9\n0 0", "output": "29\n29\n38\n80\n36\n45\n36", "type": "stdin_std...
code_contests
verifiable_code
p00628 Yes
Solve the following coding problem using the programming language python: Dr .: Peter, do you know "Yes, I have a number"? Peter: I used to do it on TV the other day. You remember something by the number of characters in each word contained in a sentence. "Yes, I have a number", so it means "the number 3.14" and is a...
```python import sys sys.setrecursionlimit(10**6) def main(): s = input() if s == "END OF INPUT": return False if s[0] == " ": s[0] = "." for _ in range(100): s = s.replace(" ", " . ") lst = s.split() ans = [] for i in lst: if i == ".": ans += [0]...
vfc_80369
{ "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": "Yes I have a number\nHow I wish I could calculate an unused color for space\nThank you\nEND OF INPUT", "output": "31416\n31415926535\n53", "type": "stdin_stdout" }, { "fn_name": null, "input": "Yes I...
code_contests
verifiable_code
p00903 Round Trip
Solve the following coding problem using the programming language python: Jim is planning to visit one of his best friends in a town in the mountain area. First, he leaves his hometown and goes to the destination town. This is called the go phase. Then, he comes back to his hometown. This is called the return phase. Y...
```python from heapq import heappush, heappop from collections import defaultdict import sys readline = sys.stdin.readline write = sys.stdout.write def solve(): N, M = map(int, readline().split()) if N == M == 0: return False D = [0]*N; E = [0]*N B = [0]*N H = defaultdict(int) H[0] = 1 ...
vfc_80377
{ "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 6\n3 1\n1 2 1\n2 3 1\n3 2 1\n2 1 1\n1 3 4\n3 1 4\n3 6\n5 1\n1 2 1\n2 3 1\n3 2 1\n2 1 1\n1 3 4\n3 1 4\n4 5\n3 1\n3 1\n1 2 5\n2 3 5\n3 4 5\n4 2 5\n3 1 5\n2 1\n2 1 1\n0 0", "output": "7\n8\n36\n-1", "type": "stdin_stdout...
code_contests
verifiable_code
p01036 Yu-kun Likes To Play Darts
Solve the following coding problem using the programming language python: Background The kindergarten attached to the University of Aizu is a kindergarten where children who love programming gather. Yu, one of the kindergarten children, loves darts as much as programming. Yu-kun was addicted to darts recently, but he...
```python # 参考 http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=3277276#1 from math import acos, hypot, isclose, sqrt def intersection(circle, polygon): # 円と多角形の共通部分の面積 # 多角形の点が反時計回りで与えられれば正の値、時計回りなら負の値を返す x, y, r = circle polygon = [(xp-x, yp-y) for xp, yp in polygon] area = 0.0 for p1, p2...
vfc_80381
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 268435456, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 2 2 1\n4 1\n0 0\n5 0\n5 5\n0 5", "output": "1.0000000000", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 2 2 1\n4 1\n0 0\n2 0\n2 2\n0 2", "output": "0.2500000000", "type": "s...
code_contests
verifiable_code
p01170 Robots' Crash
Solve the following coding problem using the programming language python: Prof. Jenifer A. Gibson is carrying out experiments with many robots. Since those robots are expensive, she wants to avoid their crashes during her experiments at her all effort. So she asked you, her assistant, as follows. “Suppose that we hav...
vfc_80385
{ "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\n1.0 0.0\n0.5\n0.0 0.0 1\n2.0 0.0 -1\n2\n1.0 0.0\n0.5\n0.0 0.0 -1\n2.0 0.0 1\n0", "output": "0.500000\nSAFE", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1.0 0.0\n0.5\n0.0 0.0 1\n2.0 ...
code_contests
verifiable_code
p01306 Unit Converter
Solve the following coding problem using the programming language python: In the International System of Units (SI), various physical quantities are expressed in the form of "numerical value + prefix + unit" using prefixes such as kilo, mega, and giga. For example, "3.5 kilometers", "5.1 milligrams", and so on. On th...
```python m = {"yotta":24, "zetta":21, "exa":18, "peta":15, "tera":12, "giga":9, "mega":6, "kilo":3, "hecto":2, "deca":1, "deci":-1, "centi":-2, "milli":-3, "micro":-6, "nano":-9, "pico":-12, "femto":-15, "ato":-18, "zepto":-21, "yocto":-24} for _ in range(int(input())): v, *b = input().split() if len(b) == 2: ...
vfc_80389
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 8, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7\n12.3 kilo meters\n0.45 mega watts\n0.000000000000000000000001 yotta grams\n1000000000000000000000000 yocto seconds\n42 amperes\n0.42 joules\n1234.56789012345678901234567890 hecto pascals", "output": "1.23 * 10^4 meters\n4....
code_contests
verifiable_code
p01475 Plane Division
Solve the following coding problem using the programming language python: Problem statement The curve given by one implicit function $ Ax ^ 2 + Bxy + Cy ^ 2 + Dx + Ey + F = 0 $ and the straight line given by $ N $ implicit functions $ A_ix + B_iy + C_i = 0 $ is there. Find out how many regions the plane is divided by...
vfc_80393
{ "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\n1 0 -1 0 0 -1\n3 0 6\n-5 0 -10", "output": "6", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1 0 0 0 -1 0\n2 -1 -1\n6 9 1", "output": "7", "type": "stdin_stdout" }, ...
code_contests
verifiable_code
p01635 Time Complexity
Solve the following coding problem using the programming language python: ICPC World Finals Day 1 In programming contests, it is important to know the execution time of the program. If you make a mistake in estimating the execution time and write code that exceeds the time limit, you will lose that much time. This is...
vfc_80397
{ "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": "n T\nf(n)", "output": "101010000", "type": "stdin_stdout" }, { "fn_name": null, "input": "n T\ng(n)", "output": "0\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p01787 RLE Replacement
Solve the following coding problem using the programming language python: H - RLE Replacement Problem Statement In JAG Kingdom, ICPC (Intentionally Compressible Programming Code) is one of the common programming languages. Programs in this language only contain uppercase English letters and the same letters often ap...
```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**10 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_80401
{ "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": "R 100 L 20 E 10 \\$\nR 5 L 10 \\$\nX 20 \\$", "output": "R 95 X 20 L 10 E 10 \\$", "type": "stdin_stdout" }, { "fn_name": null, "input": "R 100 L 20 E 10 \\$\nR 5 L 6 \\$\nX 20 \\$", "output": ...
code_contests
verifiable_code
p01922 Love Permutation
Solve the following coding problem using the programming language python: G: Koi no Junretsu Run! Run! Run! --Love Permutation, Run run run! - story Big Junretsu Ranran Randebu ♪ Hello, Hoshizora Ran Nya! My favorite data structure is Starry Sky Tree Nya! Ran recently enrolled in the Department of Physics, but appa...
vfc_80405
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 267386880, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n3 4 2 1 5\n3\n1 2 3", "output": "Yes", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n3 4 4 1 5\n3\n1 2 3", "output": "Yes\n", "type": "stdin_stdout" }, { "fn_...
code_contests
verifiable_code
p02060 Four Tea
Solve the following coding problem using the programming language python: A: four tea problem Tea is indispensable for programming contests. Tea has the effect of relieving constant tension [citation needed] There are N players participating in the contest, so I would like to prepare tea for this number of people. ...
```python n,pa,pb,pc,pd,ta,tb,tc,td=map(int,open(0).read().split()) r=range(n+1) m=1e9 for i in r: for j in r: for k in r: l=0--(n-ta*i-tb*j-tc*k)//td m=min(m,pa*i+pb*j+pc*k+pd*l*(l>=0)) print(m) ```
vfc_80409
{ "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": "10\n1 2 3 4\n1 2 4 8", "output": "6", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n1 2 3 2\n1 2 4 8", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": n...
code_contests
verifiable_code
bytesg
Solve the following coding problem using the programming language python: Do you like Treasure Hunts? I like treasure hunts. Love ‘em. And TROIKA 2013 has the best one ever in ‘MIST’ (apps.facebook.com/mist_troika). Just like a normal treasure hunt, you are given several clues and you have to get the right answer to ...
```python import string s = raw_input().split() l = len(s) for i in range(l): s[i] = string.lower(s[i]) while True: p = raw_input().split() l1 = len(p) a = 1 for i in range(l1): if string.lower(p[i]) not in s: a = 0 break if a: break else: prin...
vfc_80421
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "Sachin Ramesh Tendulkar\nSach\nRam\nsAcH Tendul\nsach Tendulkar\nSachin Ram Tendulkar\nSAChin TENduLkaR", "output": "No\nNo\nNo\nNo\nNo\nYes", "type": "stdin_stdout" }, { "fn_name": null, "input": "S...
code_contests
verifiable_code
cooling
Solve the following coding problem using the programming language python: The chef has just finished baking several pies, and it's time to place them on cooling racks. The chef has exactly as many cooling racks as pies. Each cooling rack can only hold one pie, and each pie may only be held by one cooling rack, but th...
```python #codechef problem Code: cooling pies for testcases in xrange(int(raw_input())): n = int(raw_input() ) pies = map(int, raw_input().split() ) trays = map(int, raw_input().split() ) pies = sorted(pies, reverse = True) trays = sorted(trays, reverse = True) wastepies = 0 wastetrays = 0 ...
vfc_80425
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n3\n10 30 20\n30 10 20\n5\n9 7 16 4 8\n8 3 14 10 10", "output": "3\n4\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
gmb01
Solve the following coding problem using the programming language python: All of us must have played the game of jumping monkeys in our childhood. It was a simple game where one had to put a monkey on a tree using a catapult. The catapult threw the monkey into a specific height in the air such that it may landed on an...
```python t=input() for ti in range(t): hn=map(int,raw_input().split()) h=hn[0] a=map(int,raw_input().split()) b=sorted(a) boolean=True for i in range(len(b)): if (i!=0 and b[i]-b[i-1]>h) or (i==0 and b[i]>h): print "No" boolean=False break if bool...
vfc_80429
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n3 7\n10 12 15 4 7 1 3\n4 9\n12 15 2 14 21 18 4 25 7", "output": "Yes\nNo", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n3 7\n10 12 15 4 7 1 1\n4 9\n12 15 2 14 21 18 4 25 7", "ou...
code_contests
verifiable_code
marcha1
Solve the following coding problem using the programming language python: A tutorial for this problem is now available on our blog. Click here to read it. The following problem appeared in the CodeChef March '09 Challenge In the mysterious country of Byteland, everything is quite different from what you'd normally ...
```python #codechef problem Code: cooling pies import itertools for testcases in xrange(int(raw_input())): n, tot = map(int, raw_input().split() ) L = [] for i in xrange(n) : L.append(int(raw_input())) L = sorted(L) purse = [] for item in L: if item > tot: break ...
vfc_80433
{ "difficulty": "2", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n3 3\n1\n1\n1\n5 11\n1\n2\n4\n8\n16\n5 23\n1\n2\n4\n8\n16\n5 13\n1\n5\n5\n10\n10\n20 132\n17\n6\n4\n998\n254\n137\n259\n153\n154\n3\n28\n19\n123\n542\n857\n23\n687\n35\n99\n999", "output": "Yes\nYes\nYes\nNo\nYes\n", ...
code_contests
verifiable_code
qucobic
Solve the following coding problem using the programming language python: STATEMENT You are sitting in your class getting bored and wondering how long will it be before you can get back to your room and contine solving the current long challenge @ codechef. You look at the clock and it shows the time as HH:MM (24-ho...
```python import math t=input() while t>0: t-=1 time=raw_input() hrs=int(time[0:2]) mint=int(time[2:4]) #print hrs," ",mint p=input() mi=p/60 sec=p%60 hs=0 if mi>=60: hs+=(mi/60) mi%=60 hrs=(hrs+hs)%24 mint=(mint+mi) if mint>=60: hrs+=1 hrs%=24 mint%=60 if(sec >0): if(not(hrs==23...
vfc_80437
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1234\n123\n1234\n120\n0000\n0", "output": "1237\n1236\n0000", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
toffees
Solve the following coding problem using the programming language python: Teacher Suki loves her students very much. Now, she wants to distribute toffees among her students. She has a bag full of toffees. Since, she doesn't have time for counting, each time she randomly picks up some toffees from the bag and gives the...
```python tc=int(raw_input()) for i in xrange(tc): n=int(raw_input()) choco=map(int,raw_input().split()) mi=min(choco) ma=max(choco) if ma-mi >=2: print "BAD" else: print "GOOD" ```
vfc_80441
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n3\n2 2 1\n3\n1 5 4", "output": "GOOD\nBAD", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n3\n2 2 1\n3\n1 6 4", "output": "GOOD\nBAD\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
1015_A. Points in Segments
Solve the following coding problem using the programming language python: You are given a set of n segments on the axis Ox, each segment has integer endpoints between 1 and m inclusive. Segments may intersect, overlap or even coincide with each other. Each segment is characterized by two integers l_i and r_i (1 ≤ l_i ...
```python n, m = [int(x) for x in input().split()] s = set(range(1, m+1)) for _ in range(n): a, b = [int(x) for x in input().split()] s -= set(range(a, b+1)) print(len(s)) print(*s) ```
vfc_80445
{ "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": "1 7\n1 7\n", "output": "0\n\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 5\n2 2\n1 2\n5 5\n", "output": "2\n3 4\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1038_E. Maximum Matching
Solve the following coding problem using the programming language python: You are given n blocks, each of them is of the form [color_1|value|color_2], where the block can also be flipped to get [color_2|value|color_1]. A sequence of blocks is called valid if the touching endpoints of neighboring blocks have the same...
```python def min(a, b): if a < b: return a return b def max(a,b): return abs(min(-a,-b)) been = [0 for i in range(4)] ans = 0 minw = 10**18 degpar = [0 for i in range(4)] w = [0 for i in range(4)] gr = [list() for i in range(4)] rem = [[0 for i in range(4)] for j in range(4)] def dfs(x, l): l.a...
vfc_80449
{ "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\n1 1000 1\n2 500 2\n3 250 3\n4 125 4\n", "output": "1000", "type": "stdin_stdout" }, { "fn_name": null, "input": "7\n1 100000 1\n1 100000 2\n1 100000 2\n4 50000 3\n3 50000 4\n4 50000 4\n3 50000 3\n...
code_contests
verifiable_code
1061_A. Coins
Solve the following coding problem using the programming language python: You have unlimited number of coins with values 1, 2, …, n. You want to select some set of coins having the total value of S. It is allowed to have multiple coins with the same value in the set. What is the minimum number of coins required to g...
```python n, s = map(int, input().split()) print((s + n - 1) // n) ```
vfc_80453
{ "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": "6 16\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 11\n", "output": "3\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1082_G. Petya and Graph
Solve the following coding problem using the programming language python: Petya has a simple graph (that is, a graph without loops or multiple edges) consisting of n vertices and m edges. The weight of the i-th vertex is a_i. The weight of the i-th edge is w_i. A subgraph of a graph is some set of the graph vertice...
```python class edge(object): def __init__(self,ne,to,fl): self.ne=ne self.to=to self.fl=fl def add(x,y,z): global tot tot+=1 e.append(edge(he[x],y,z)) he[x]=tot def addedge(x,y,z): add(x,y,z) add(y,x,0) def bfs(): global deep deep=[0 for i in range(T+1)] q=[] q.append(S) deep[S]=1 while (len(q)>0...
vfc_80457
{ "difficulty": "13", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 3\n9 7 8\n1 2 1\n2 3 2\n1 3 3\n", "output": " 0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 5\n1 5 2 2\n1 3 4\n1 4 4\n...
code_contests
verifiable_code
1102_B. Array K-Coloring
Solve the following coding problem using the programming language python: You are given an array a consisting of n integer numbers. You have to color this array in k colors in such a way that: * Each element of the array should be colored in some color; * For each i from 1 to k there should be at least one ele...
```python from collections import defaultdict n,k=map(int,input().split()) arr=list(map(int,input().split())) temp=[0]*5001 for i in arr: temp[i]+=1 if(max(temp)>k): print('NO') elif(k>n): print('NO') else: print('YES') d=defaultdict(list) c=0 t=[0]*n for i in range(n): t[i]=arr[...
vfc_80461
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 2\n2 1 1 2 1\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 2\n3 2 1 2 3\n", "output": "YES\n2 2 1 1 1 ", "type": "stdin_stdout" }, { "fn_n...
code_contests
verifiable_code
1130_B. Two Cakes
Solve the following coding problem using the programming language python: Sasha and Dima want to buy two n-tier cakes. Each cake should consist of n different tiers: from the size of 1 to the size of n. Tiers should go in order from the smallest to the biggest (from top to bottom). They live on the same street, there...
```python l2=[] n=int(input()) l=list(map(int,input().split())) for i in range(2*n): l2.append([l[i],i]) l2.sort() sd,dd=l2[0][1],l2[1][1] for i in range(2,2*n): if i%2: dd+=abs(l2[i][1]-l2[i-2][1]) else: sd+=abs(l2[i][1]-l2[i-2][1]) print(sd+dd) ```
vfc_80465
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n4 1 3 2 2 3 1 4\n", "output": "17\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n1 1 2 2 3 3\n", "output": "9\n", "type": "stdin_stdout" }, { "fn_name": nu...
code_contests
verifiable_code
1150_C. Prefix Sum Primes
Solve the following coding problem using the programming language python: We're giving away nice huge bags containing number tiles! A bag we want to present to you contains n tiles. Each of them has a single number written on it — either 1 or 2. However, there is one condition you must fulfill in order to receive the...
```python n=int(input()) l=list(map(int,input().split())) n1,n2=0,0 for i in l: if i==1: n1+=1 else: n2+=1 r=[] if n1==0 or n2==0: r=l else: r.append(2) r.append(1) n1-=1 n2-=1 while n2!=0: r.append(2) n2-=1 while n1!=0: r.append(1) n...
vfc_80469
{ "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": "9\n1 1 2 1 1 1 2 1 1\n", "output": "2 1 2 1 1 1 1 1 1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n1 2 1 2 1\n", "output": "2 1 2 1 1\n", "type": "stdin_stdout" }, ...
code_contests
verifiable_code
1172_C2. Nauuo and Pictures (hard version)
Solve the following coding problem using the programming language python: The only difference between easy and hard versions is constraints. Nauuo is a girl who loves random picture websites. One day she made a random picture website by herself which includes n pictures. When Nauuo visits the website, she sees exac...
```python P = 998244353 N, M = map(int, input().split()) A = [int(a) for a in input().split()] B = [int(a) for a in input().split()] li = sum([A[i]*B[i] for i in range(N)]) di = sum([(A[i]^1)*B[i] for i in range(N)]) X = [1] SU = li+di PO = [0] * (5*M+10) for i in range(-M-5, 2*M+5): PO[i] = pow((SU+i)%P, P-2, P) ...
vfc_80473
{ "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 1\n0 1\n2 1\n", "output": "332748119\n332748119\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 3\n0 1 1\n4 3 5\n", "output": "160955686\n185138929\n974061117\n", "type": "...
code_contests
verifiable_code
118_E. Bertown roads
Solve the following coding problem using the programming language python: Bertown has n junctions and m bidirectional roads. We know that one can get from any junction to any other one by the existing roads. As there were more and more cars in the city, traffic jams started to pose real problems. To deal with them t...
```python from sys import stdin,setrecursionlimit import threading input = lambda: stdin.readline().rstrip("\r\n") from collections import deque as que inin = lambda: int(input()) inar = lambda: list(map(int,input().split())) from types import GeneratorType def bootstrap(f, stack=[]): def wrappedfunc(*args, **kwa...
vfc_80477
{ "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": "6 7\n1 2\n2 3\n1 3\n4 5\n4 6\n5 6\n2 4\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 8\n1 2\n2 3\n1 3\n4 5\n4 6\n5 6\n2 4\n3 5\n", "output": "3 1\n6 5\n4 6\n4 2\...
code_contests
verifiable_code
1209_D. Cow and Snacks
Solve the following coding problem using the programming language python: The legendary Farmer John is throwing a huge party, and animals from all over the world are hanging out at his house. His guests are hungry, so he instructs his cow Bessie to bring out the snacks! Moo! There are n snacks flavors, numbered with ...
```python from collections import defaultdict import sys import typing class DSU: ''' Implement (union by size) + (path halving) Reference: Zvi Galil and Giuseppe F. Italiano, Data structures and algorithms for disjoint set union problems ''' def __init__(self, n: int = 0) -> None: ...
vfc_80481
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 4\n1 2\n4 3\n1 4\n3 4\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 5\n2 3\n2 1\n3 4\n6 5\n4 5\n", "output": "0\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
1228_C. Primes and Multiplication
Solve the following coding problem using the programming language python: Let's introduce some definitions that will be needed later. Let prime(x) be the set of prime divisors of x. For example, prime(140) = \{ 2, 5, 7 \}, prime(169) = \{ 13 \}. Let g(x, p) be the maximum possible integer p^k where k is an integer s...
```python """ import math MOD=1000000007 def powr(n,N): temp=1 while(N>0): if(N%2!=0): temp=(temp*n)%MOD n=(n*n)%MOD N=N//2 return (temp%MOD) x,n=map(int,input().split()) n1=x L=[] while(n1%2==0): L.append(2) n1=n1//2 for i in range(3,int(math.sqrt(n1))+1,...
vfc_80485
{ "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": "20190929 1605\n", "output": "363165664\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10 2\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
1293_A. ConneR and the A.R.C. Markland-N
Solve the following coding problem using the programming language python: [Sakuzyo - Imprinting](https://www.youtube.com/watch?v=55Ca6av1kAY) A.R.C. Markland-N is a tall building with n floors numbered from 1 to n. Between each two adjacent floors in the building, there is a staircase connecting them. It's lunchtime...
```python t = int(input()) for _ in range(t): variables = [int(_) for _ in input().split()] n = variables[0] s = variables[1] k = variables[2] closed = set([int(i) for i in input().split()]) minimum = n tmp = n for x in range(s, 0, -1): if x not in closed: tmp = abs(...
vfc_80497
{ "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\n5 2 3\n1 2 3\n4 3 3\n4 1 2\n10 2 6\n1 2 3 4 5 7\n2 1 1\n2\n100 76 8\n76 75 36 67 41 74 10 77\n", "output": "2\n0\n4\n0\n2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n10 8 6\n4 8 ...
code_contests
verifiable_code
1313_A. Fast Food Restaurant
Solve the following coding problem using the programming language python: Tired of boring office work, Denis decided to open a fast food restaurant. On the first day he made a portions of dumplings, b portions of cranberry juice and c pancakes with condensed milk. The peculiarity of Denis's restaurant is the procedu...
```python import os import sys from io import BytesIO, IOBase def solution(a, b, c): if a == 0 and b == 0 and c == 0: print(0) return res = 0 comb = ['001', '010', '100', '011', '101', '110', '111'] comb2 = ['01', '10', '11'] a, b, c = sorted([a, b, c]) if a == 0 and b == 0: ...
vfc_80501
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7\n1 2 1\n0 0 0\n9 1 7\n2 2 3\n2 3 2\n3 2 2\n4 4 4\n", "output": "3\n0\n4\n5\n5\n5\n7\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n2 2 8\n3 2 2\n", "output": "5\n5\n", "t...
code_contests
verifiable_code
1358_A. Park Lighting
Solve the following coding problem using the programming language python: Due to the coronavirus pandemic, city authorities obligated citizens to keep a social distance. The mayor of the city Semyon wants to light up Gluharniki park so that people could see each other even at night to keep the social distance. The pa...
```python import math t=int(input()) while(t>0): t-=1 n,m=map(int,input().split()) print(math.floor((n*m+1)/2)) ```
vfc_80509
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n1 1\n1 3\n2 2\n3 3\n5 3\n", "output": "1\n2\n2\n5\n8\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1329 2007\n179 57\n", "output": "1333652\n5102\n", "type": "stdin_std...
code_contests
verifiable_code
1375_F. Integer Game
Solve the following coding problem using the programming language python: This is an interactive problem. Anton and Harris are playing a game to decide which of them is the king of problemsetting. There are three piles of stones, initially containing a, b, and c stones, where a, b, and c are distinct positive intege...
vfc_80513
{ "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": "5 2 6\n\n\n3\n\n0", "output": "First\n5\n15\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "930039853 930039854 929839853\n", "output": "First\n200002\n", "type": "stdin_stdout...
code_contests
verifiable_code
1422_E. Minlexes
Solve the following coding problem using the programming language python: Some time ago Lesha found an entertaining string s consisting of lowercase English letters. Lesha immediately developed an unique algorithm for this string and shared it with you. The algorithm is as follows. Lesha chooses an arbitrary (possibl...
```python import sys s = input().strip() N = len(s) if len(s) == 1: print(1, s[0]) sys.exit() X = [s[-1], s[-2]+s[-1] if s[-2]!=s[-1] else ""] Y = [1, 2 if s[-2]!=s[-1] else 0] for i in range(N-3, -1, -1): c = s[i] k1 = c+X[-1] ng = Y[-1]+1 if ng > 10: k1 = k1[:5] + "..." + k1[-2:] i...
vfc_80521
{ "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": "abcdd\n", "output": "3 abc\n2 bc\n1 c\n0 \n1 d\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "abbcdddeaaffdfouurtytwoo\n", "output": "18 abbcd...tw\n17 bbcdd...tw\n16 bcddd...tw\n15...
code_contests
verifiable_code
1440_C2. Binary Table (Hard Version)
Solve the following coding problem using the programming language python: This is the hard version of the problem. The difference between the versions is in the number of possible operations that can be made. You can make hacks if and only if you solved both versions of the problem. You are given a binary table of si...
```python import sys input=sys.stdin.readline def change(x1,x2,x3,y1,y2,y3,ll): ll[x1][y1]=1-ll[x1][y1] ll[x2][y2]=1-ll[x2][y2] #print(x3,y3,ll) ll[x3][y3]=1-ll[x3][y3] t=int(input()) while t: n,m=map(int,input().split()) ll=[] for i in range(n): l=list(map(int,input().strip())...
vfc_80525
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n2 2\n10\n11\n3 3\n011\n101\n110\n4 4\n1111\n0110\n0110\n1111\n5 5\n01011\n11001\n00010\n11011\n10000\n2 3\n011\n101\n", "output": "1\n1 1 2 1 2 2 \n4\n1 2 1 3 2 2 \n2 1 3 1 2 2 \n2 2 3 2 3 3 \n2 2 2 3 3 3 \n8\n1 1 1 2 2 1 ...
code_contests
verifiable_code
1541_E1. Converging Array (Easy Version)
Solve the following coding problem using the programming language python: This is the easy version of the problem. The only difference is that in this version q = 1. You can make hacks only if both versions of the problem are solved. There is a process that takes place on arrays a and b of length n and length n-1 res...
```python import sys input = lambda: sys.stdin.readline().rstrip() N = int(input()) C = [int(a) for a in input().split()] B = [int(a) for a in input().split()] Q = int(input()) x = int(input()) P = 10 ** 9 + 7 dp = [[0] * 20100 for _ in range(N + 1)] dp[0][0] = 1 ans = 0 s = x t = s for i in range(N): for j in ran...
vfc_80541
{ "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": "3\n2 3 4\n2 1\n1\n-1\n", "output": "56", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n77 16 42 68 100 38 40 99 75 67\n0 1 0 2 1 1 0 0 0\n1\n43\n", "output": "764609643", "ty...
code_contests
verifiable_code
169_D. 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_80545
{ "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 3 10\n3 4 3 2 1\n5 4 3 2 1\n", "output": "4 3 1 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 3 2\n1 2 3 2 1\n1 2 1 2 10\n", "output": "1 5 2 ", "type": "stdin_stdout" ...
code_contests
verifiable_code
18_B. Platforms
Solve the following coding problem using the programming language python: In one one-dimensional world there are n platforms. Platform with index k (platforms are numbered from 1) is a segment with coordinates [(k - 1)m, (k - 1)m + l], and l < m. Grasshopper Bob starts to jump along the platforms from point 0, with ea...
```python class Platforms: @classmethod def read_input(cls): nums = list(map(int, input('').split())) return nums[0], nums[1], nums[2], nums[3] @classmethod def run(cls): n, d, m, l = cls.read_input() end_plat = (n - 1) * m + l for cur_jump in range(d, (m + 1) * ...
vfc_80549
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 64000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 4 11 8\n", "output": "20\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 2 5 3\n", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "input"...
code_contests
verifiable_code
237_B. Young Table
Solve the following coding problem using the programming language python: You've got table a, consisting of n rows, numbered from 1 to n. The i-th line of table a contains ci cells, at that for all i (1 < i ≤ n) holds ci ≤ ci - 1. Let's denote s as the total number of cells of table a, that is, <image>. We know that...
```python n = int(input()) I = lambda : map(int,input().split()) li = list (I()) dd = {} arr = [ [0 for i in range(51)] for j in range(51) ] l2 = [ ] c=0 for i in range (1,n+1) : l1 = list(I()) l2 = l2 + l1 c = c + len(l1) for j in range(li[i-1]) : arr[i][j+1] = l1[j] dd[l1[j]] = [i , j...
vfc_80557
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n4\n4 3 2 1\n", "output": "2\n1 1 1 4\n1 2 1 3\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
261_E. Maxim and Calculator
Solve the following coding problem using the programming language python: Maxim has got a calculator. The calculator has two integer cells. Initially, the first cell contains number 1, and the second cell contains number 0. In one move you can perform one of the following operations: 1. Let's assume that at the cur...
vfc_80561
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 4, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 111 100\n", "output": "106\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 10 3\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input...
code_contests
verifiable_code
285_E. Positions in Permutations
Solve the following coding problem using the programming language python: Permutation p is an ordered set of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. We'll denote the i-th element of permutation p as pi. We'll call number n the size or the length of permutati...
```python mod=10**9+7 n,k=map(int,input().split()) A=[0]*(n+1) B=[0]*(n+1) C=[0]*(n+1) F=[0]*(n+1) G=[0]*(n+1) F[0]=G[0]=1 for i in range(1,n+1): G[i]=F[i]=F[i-1]*i%mod G[i]=pow(F[i],(mod-2),mod) for i in range(0,n): if i*2>n: break B[i]=(F[n-i]*G[i]*G[n-i*2])%mod for i in range(0,n//2+1): for j in range(0,n/...
vfc_80565
{ "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 1\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 1\n", "output": "6\n", "type": "stdin_stdout" } ] }