problem_id
stringlengths
3
7
contestId
stringclasses
660 values
problem_index
stringclasses
27 values
programmingLanguage
stringclasses
3 values
testset
stringclasses
5 values
incorrect_passedTestCount
float64
0
146
incorrect_timeConsumedMillis
float64
15
4.26k
incorrect_memoryConsumedBytes
float64
0
271M
incorrect_submission_id
stringlengths
7
9
incorrect_source
stringlengths
10
27.7k
correct_passedTestCount
float64
2
360
correct_timeConsumedMillis
int64
30
8.06k
correct_memoryConsumedBytes
int64
0
475M
correct_submission_id
stringlengths
7
9
correct_source
stringlengths
28
21.2k
contest_name
stringclasses
664 values
contest_type
stringclasses
3 values
contest_start_year
int64
2.01k
2.02k
time_limit
float64
0.5
15
memory_limit
float64
64
1.02k
title
stringlengths
2
54
description
stringlengths
35
3.16k
input_format
stringlengths
67
1.76k
output_format
stringlengths
18
1.06k
⌀
interaction_format
null
note
stringclasses
840 values
examples
stringlengths
34
1.16k
rating
int64
800
3.4k
⌀
tags
stringclasses
533 values
testset_size
int64
2
360
official_tests
stringlengths
44
19.7M
official_tests_complete
bool
1 class
input_mode
stringclasses
1 value
generated_checker
stringclasses
231 values
executable
bool
1 class
707/A
707
A
Python 3
TESTS
27
46
0
160413049
n, m = map(int, input().split()) a = [] for i in range(n): b = [i for i in input().split()] a.append(b) t = True for i in a: for j in b: if j != "W" and j != "B" and j != "G": t = False if t: print("#Black&White") else: print("#Color")
50
31
0
215189598
def main(): s = open(0).read().split()[2:] if 'C' in s or 'M' in s or 'Y' in s: print("#Color") else: print("#Black&White") main()
Codeforces Round 368 (Div. 2)
CF
2,016
2
256
Brain's Photos
Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead. As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such). Brain took a ...
The first line of the input contains two integers n and m (1 ≤ n, m ≤ 100) — the number of photo pixel matrix rows and columns respectively. Then n lines describing matrix rows follow. Each of them contains m space-separated characters describing colors of pixels in a row. Each character in the line is one of the 'C',...
Print the "#Black&White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line.
null
null
[{"input": "2 2\nC M\nY Y", "output": "#Color"}, {"input": "3 2\nW W\nW W\nB B", "output": "#Black&White"}, {"input": "1 1\nW", "output": "#Black&White"}]
800
["implementation"]
50
[{"input": "2 2\r\nC M\r\nY Y\r\n", "output": "#Color"}, {"input": "3 2\r\nW W\r\nW W\r\nB B\r\n", "output": "#Black&White"}, {"input": "1 1\r\nW\r\n", "output": "#Black&White"}, {"input": "2 3\r\nW W W\r\nB G Y\r\n", "output": "#Color"}, {"input": "1 1\r\nW\r\n", "output": "#Black&White"}, {"input": "5 5\r\nW G B Y M\...
false
stdio
null
true
707/A
707
A
Python 3
TESTS
27
46
0
227502259
a, x = list(map(int, input().split())) for i in range(a): s = list(map(str, input().split())) # Convert all elements of s to lowercase and check for presence of 'c', 'm', or 'y' s_lower = [item.lower() for item in s] if 'c' in s_lower or 'm' in s_lower or 'y' in s_lower: print("#Color") else: ...
50
31
0
216994455
v,v1=map(int,input().split());c=[] for i in range(v): v2=input().split();c.append(v2) for i in c: if "C"in i or "M" in i or "Y" in i:print("#Color");break else:print("#Black&White")
Codeforces Round 368 (Div. 2)
CF
2,016
2
256
Brain's Photos
Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead. As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such). Brain took a ...
The first line of the input contains two integers n and m (1 ≤ n, m ≤ 100) — the number of photo pixel matrix rows and columns respectively. Then n lines describing matrix rows follow. Each of them contains m space-separated characters describing colors of pixels in a row. Each character in the line is one of the 'C',...
Print the "#Black&White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line.
null
null
[{"input": "2 2\nC M\nY Y", "output": "#Color"}, {"input": "3 2\nW W\nW W\nB B", "output": "#Black&White"}, {"input": "1 1\nW", "output": "#Black&White"}]
800
["implementation"]
50
[{"input": "2 2\r\nC M\r\nY Y\r\n", "output": "#Color"}, {"input": "3 2\r\nW W\r\nW W\r\nB B\r\n", "output": "#Black&White"}, {"input": "1 1\r\nW\r\n", "output": "#Black&White"}, {"input": "2 3\r\nW W W\r\nB G Y\r\n", "output": "#Color"}, {"input": "1 1\r\nW\r\n", "output": "#Black&White"}, {"input": "5 5\r\nW G B Y M\...
false
stdio
null
true
326/A
335
A
Python 3
PRETESTS
7
280
0
4222750
import math S=input() N=int(input()) Srep={} ansrep={} for item in "abcdefghijklmnopqrstuvwxyz": Srep[item]=0 ansrep[item]=0 for item in S: Srep[item]+=1 ansrep[item]+=1 Q=list(set(S)) if(len(Q)>N): print(-1) else: n=len(Q) ans=S num=1 ans=list(ans) ans.sort(key=S.count,reve...
55
124
0
4221450
from collections import Counter s = input() n = int(input()) d = Counter() for c in s: d[c] += 1 if len(d) > n: print(-1) else: left = 0 right = 10**10 s = "" lastok = ("", 0) while left + 1 < right: mid = (left + right) // 2 s = "" for (c, cnt) in d.items(): ...
MemSQL start[c]up Round 2
CF
2,013
2
256
Banana
Piegirl is buying stickers for a project. Stickers come on sheets, and each sheet of stickers contains exactly n stickers. Each sticker has exactly one character printed on it, so a sheet of stickers can be described by a string of length n. Piegirl wants to create a string s using stickers. She may buy as many sheets ...
The first line contains string s (1 ≤ |s| ≤ 1000), consisting of lowercase English characters only. The second line contains an integer n (1 ≤ n ≤ 1000).
On the first line, print the minimum number of sheets Piegirl has to buy. On the second line, print a string consisting of n lower case English characters. This string should describe a sheet of stickers that Piegirl can buy in order to minimize the number of sheets. If Piegirl cannot possibly form the string s, print ...
null
In the second example, Piegirl can order 3 sheets of stickers with the characters "nab". She can take characters "nab" from the first sheet, "na" from the second, and "a" from the third, and arrange them to from "banana".
[{"input": "banana\n4", "output": "2\nbaan"}, {"input": "banana\n3", "output": "3\nnab"}, {"input": "banana\n2", "output": "-1"}]
1,400
[]
55
[{"input": "banana\r\n4\r\n", "output": "2\r\nbaan\r\n"}, {"input": "banana\r\n3\r\n", "output": "3\r\nnab\r\n"}, {"input": "banana\r\n2\r\n", "output": "-1\r\n"}, {"input": "p\r\n1000\r\n", "output": "1\npaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
false
stdio
import sys from math import ceil from collections import defaultdict def main(input_path, output_path, submission_path): with open(input_path) as f: s = f.readline().strip() n = int(f.readline().strip()) s_counts = defaultdict(int) for c in s: s_counts[c] += 1 def is_possible(...
true
707/A
707
A
Python 3
TESTS
27
46
0
206800428
""" A. Brain's Photos: implementation time limit per test: 2 seconds memory limit per test: 256 megabytes input: standard input output: standard output Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but t...
50
31
0
220471379
a, b = map(int, input().split()) flag = True for i in range(a): a = [str(x) for x in input().split()] for c in a: if c == "C" or c == "M" or c == "Y": flag = False break if flag == True: print("#Black&White") else: print("#Color")
Codeforces Round 368 (Div. 2)
CF
2,016
2
256
Brain's Photos
Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead. As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such). Brain took a ...
The first line of the input contains two integers n and m (1 ≤ n, m ≤ 100) — the number of photo pixel matrix rows and columns respectively. Then n lines describing matrix rows follow. Each of them contains m space-separated characters describing colors of pixels in a row. Each character in the line is one of the 'C',...
Print the "#Black&White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line.
null
null
[{"input": "2 2\nC M\nY Y", "output": "#Color"}, {"input": "3 2\nW W\nW W\nB B", "output": "#Black&White"}, {"input": "1 1\nW", "output": "#Black&White"}]
800
["implementation"]
50
[{"input": "2 2\r\nC M\r\nY Y\r\n", "output": "#Color"}, {"input": "3 2\r\nW W\r\nW W\r\nB B\r\n", "output": "#Black&White"}, {"input": "1 1\r\nW\r\n", "output": "#Black&White"}, {"input": "2 3\r\nW W W\r\nB G Y\r\n", "output": "#Color"}, {"input": "1 1\r\nW\r\n", "output": "#Black&White"}, {"input": "5 5\r\nW G B Y M\...
false
stdio
null
true
377/A
377
A
PyPy 3
TESTS
15
966
94,208,000
115862981
n, m, k = map(int, input().split()) a = [list(input()) for _ in range(n)] child = dict() childcount = [set(), set(), set(), set(), set()] for i in range(n): for j in range(m): count = [] if a[i][j] == '#': continue if i > 0 and a[i - 1][j] == '.': count.append((i - 1, j)) if i + 1 ...
89
311
42,496,000
172824405
import sys from collections import deque input = sys.stdin.readline n, m, k = map(int, input().split()) grid, count = [], 0 for _ in range(n): grid.append(list(input()[:-1])) count += grid[-1].count('.') count -= k visited = set() def bfs(i0, j0): dq = deque([(i0, j0)]) visited.add((i0, j0)) while...
Codeforces Round 222 (Div. 1)
CF
2,013
2
256
Maze
Pavel loves grid mazes. A grid maze is an n × m rectangle maze where each cell is either empty, or is a wall. You can go from one cell to another only if both cells are empty and have a common side. Pavel drew a grid maze with all empty cells forming a connected area. That is, you can go from any empty cell to any oth...
The first line contains three integers n, m, k (1 ≤ n, m ≤ 500, 0 ≤ k < s), where n and m are the maze's height and width, correspondingly, k is the number of walls Pavel wants to add and letter s represents the number of empty cells in the original maze. Each of the next n lines contains m characters. They describe t...
Print n lines containing m characters each: the new maze that fits Pavel's requirements. Mark the empty cells that you transformed into walls as "X", the other cells must be left without changes (that is, "." and "#"). It is guaranteed that a solution exists. If there are multiple solutions you can output any of them.
null
null
[{"input": "3 4 2\n#..#\n..#.\n#...", "output": "#.X#\nX.#.\n#..."}, {"input": "5 4 5\n#...\n#.#.\n.#..\n...#\n.#.#", "output": "#XXX\n#X#.\nX#..\n...#\n.#.#"}]
1,600
["dfs and similar"]
89
[{"input": "3 4 2\r\n#..#\r\n..#.\r\n#...\r\n", "output": "#.X#\r\nX.#.\r\n#...\r\n"}, {"input": "5 4 5\r\n#...\r\n#.#.\r\n.#..\r\n...#\r\n.#.#\r\n", "output": "#XXX\r\n#X#.\r\nX#..\r\n...#\r\n.#.#\r\n"}, {"input": "3 3 2\r\n...\r\n.#.\r\n...\r\n", "output": "X..\r\nX#.\r\n...\r\n"}, {"input": "3 3 2\r\n#.#\r\n...\r\n#...
false
stdio
import sys from collections import deque def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] with open(input_path) as f: lines = f.readlines() first_line = lines[0].strip().split() n, m, k = map(int, first_line[:3]) original = [line.strip() ...
true
401/A
401
A
Python 3
TESTS
32
46
0
162427827
n,x=map(int,input().split()) l=list(map(int,input().split())) s=abs(sum(l)) c=1 if s==0: print(0) else: for i in range(1,1000): k=s-x*i if k<=0: print(i) break
47
31
0
144641886
import math n, x = map(int, input().split()) a = list(map(int, input().split())) print(math.ceil(abs(sum(a)) / x))
Codeforces Round 235 (Div. 2)
CF
2,014
1
256
Vanya and Cards
Vanya loves playing. He even has a special set of cards to play with. Each card has a single integer. The number on the card can be positive, negative and can even be equal to zero. The only limit is, the number on each card doesn't exceed x in the absolute value. Natasha doesn't like when Vanya spends a long time pla...
The first line contains two integers: n (1 ≤ n ≤ 1000) — the number of found cards and x (1 ≤ x ≤ 1000) — the maximum absolute value of the number on a card. The second line contains n space-separated integers — the numbers on found cards. It is guaranteed that the numbers do not exceed x in their absolute value.
Print a single number — the answer to the problem.
null
In the first sample, Vanya needs to find a single card with number -2. In the second sample, Vanya needs to find two cards with number 2. He can't find a single card with the required number as the numbers on the lost cards do not exceed 3 in their absolute value.
[{"input": "3 2\n-1 1 2", "output": "1"}, {"input": "2 3\n-2 -2", "output": "2"}]
800
["implementation", "math"]
47
[{"input": "3 2\r\n-1 1 2\r\n", "output": "1\r\n"}, {"input": "2 3\r\n-2 -2\r\n", "output": "2\r\n"}, {"input": "4 4\r\n1 2 3 4\r\n", "output": "3\r\n"}, {"input": "2 2\r\n-1 -1\r\n", "output": "1\r\n"}, {"input": "15 5\r\n-2 -1 2 -4 -3 4 -4 -2 -2 2 -2 -1 1 -4 -2\r\n", "output": "4\r\n"}, {"input": "15 16\r\n-15 -5 -15...
false
stdio
null
true
844/A
844
A
Python 3
TESTS
15
109
0
73751941
data = input() howmany = int(input()) data = data.lower() uniques = list(dict.fromkeys(data)) if (howmany <= len(data)) and (len(uniques) != 26): ans = howmany - len(uniques) if ans < 0: ans = 0 print(ans) else: print("impossible")
41
31
0
145148393
s = input() l1=len(s) k = int(input()) s1 = set(s) l=len(s1) if(k<=l): print("0") elif(k>l and k<=l1): print(k-l) else: print("impossible")
AIM Tech Round 4 (Div. 2)
CF
2,017
1
256
Diversity
Calculate the minimum number of characters you need to change in the string s, so that it contains at least k different letters, or print that it is impossible. String s consists only of lowercase Latin letters, and it is allowed to change characters only to lowercase Latin letters too.
First line of input contains string s, consisting only of lowercase Latin letters (1 ≤ |s| ≤ 1000, |s| denotes the length of s). Second line of input contains integer k (1 ≤ k ≤ 26).
Print single line with a minimum number of necessary changes, or the word «impossible» (without quotes) if it is impossible.
null
In the first test case string contains 6 different letters, so we don't need to change anything. In the second test case string contains 4 different letters: {'a', 'h', 'o', 'y'}. To get 5 different letters it is necessary to change one occurrence of 'o' to some letter, which doesn't occur in the string, for example, ...
[{"input": "yandex\n6", "output": "0"}, {"input": "yahoo\n5", "output": "1"}, {"input": "google\n7", "output": "impossible"}]
1,000
["greedy", "implementation", "strings"]
41
[{"input": "yandex\r\n6\r\n", "output": "0\r\n"}, {"input": "yahoo\r\n5\r\n", "output": "1\r\n"}, {"input": "google\r\n7\r\n", "output": "impossible\r\n"}, {"input": "a\r\n1\r\n", "output": "0\r\n"}, {"input": "z\r\n2\r\n", "output": "impossible\r\n"}, {"input": "fwgfrwgkuwghfiruhewgirueguhergiqrbvgrgf\r\n26\r\n", "out...
false
stdio
null
true
369/A
369
A
PyPy 3
TESTS
10
77
17,715,200
132659644
n, m, k = map(int, input().split()) a, dem = list(map(int, input().split())), [0, 0] for x in a: dem[x - 1] += 1 m -= dem[0] print(m * (-1) + dem[1] - min(dem[1], k))
63
46
0
143398564
n, m, k = list(map(int, input().split())) a = list(map(int, input().split())) def solve(n, m, k, a): cnt = 0 for dish in a: if dish == 1: if m > 0: m -= 1 else: cnt += 1 else: if m == 0 and k == 0: cnt += 1 ...
Codeforces Round 216 (Div. 2)
CF
2,013
1
256
Valera and Plates
Valera is a lazy student. He has m clean bowls and k clean plates. Valera has made an eating plan for the next n days. As Valera is lazy, he will eat exactly one dish per day. At that, in order to eat a dish, he needs exactly one clean plate or bowl. We know that Valera can cook only two types of dishes. He can eat di...
The first line of the input contains three integers n, m, k (1 ≤ n, m, k ≤ 1000) — the number of the planned days, the number of clean bowls and the number of clean plates. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 2). If ai equals one, then on day i Valera will eat a first type dish. If ai equals ...
Print a single integer — the minimum number of times Valera will need to wash a plate/bowl.
null
In the first sample Valera will wash a bowl only on the third day, so the answer is one. In the second sample, Valera will have the first type of the dish during all four days, and since there are only three bowls, he will wash a bowl exactly once. In the third sample, Valera will have the second type of dish for all...
[{"input": "3 1 1\n1 2 1", "output": "1"}, {"input": "4 3 1\n1 1 1 1", "output": "1"}, {"input": "3 1 2\n2 2 2", "output": "0"}, {"input": "8 2 2\n1 2 1 2 1 2 1 2", "output": "4"}]
900
["greedy", "implementation"]
63
[{"input": "3 1 1\r\n1 2 1\r\n", "output": "1\r\n"}, {"input": "4 3 1\r\n1 1 1 1\r\n", "output": "1\r\n"}, {"input": "3 1 2\r\n2 2 2\r\n", "output": "0\r\n"}, {"input": "8 2 2\r\n1 2 1 2 1 2 1 2\r\n", "output": "4\r\n"}, {"input": "2 100 100\r\n2 2\r\n", "output": "0\r\n"}, {"input": "1 1 1\r\n2\r\n", "output": "0\r\n"...
false
stdio
null
true
369/A
369
A
Python 3
TESTS
12
109
0
52592503
class ValeraAndPlates: n = m = k = 0 dishes = list() def solve(self): dish_m = self.dishes.count(1) #print dish_m dish_k = self.dishes.count(2) wash = 0 if(dish_m==0 and dish_k>=(self.k+self.m)): wash+=dish_k-(self.k+self.m) else: if(...
63
46
0
146236846
n, m, k = map(int, input().split()) a = input().split() o = a.count('1') t = 0 t += max(0, o - m) t += max(0, n - o - max(0, m - o) - k) print(t)
Codeforces Round 216 (Div. 2)
CF
2,013
1
256
Valera and Plates
Valera is a lazy student. He has m clean bowls and k clean plates. Valera has made an eating plan for the next n days. As Valera is lazy, he will eat exactly one dish per day. At that, in order to eat a dish, he needs exactly one clean plate or bowl. We know that Valera can cook only two types of dishes. He can eat di...
The first line of the input contains three integers n, m, k (1 ≤ n, m, k ≤ 1000) — the number of the planned days, the number of clean bowls and the number of clean plates. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 2). If ai equals one, then on day i Valera will eat a first type dish. If ai equals ...
Print a single integer — the minimum number of times Valera will need to wash a plate/bowl.
null
In the first sample Valera will wash a bowl only on the third day, so the answer is one. In the second sample, Valera will have the first type of the dish during all four days, and since there are only three bowls, he will wash a bowl exactly once. In the third sample, Valera will have the second type of dish for all...
[{"input": "3 1 1\n1 2 1", "output": "1"}, {"input": "4 3 1\n1 1 1 1", "output": "1"}, {"input": "3 1 2\n2 2 2", "output": "0"}, {"input": "8 2 2\n1 2 1 2 1 2 1 2", "output": "4"}]
900
["greedy", "implementation"]
63
[{"input": "3 1 1\r\n1 2 1\r\n", "output": "1\r\n"}, {"input": "4 3 1\r\n1 1 1 1\r\n", "output": "1\r\n"}, {"input": "3 1 2\r\n2 2 2\r\n", "output": "0\r\n"}, {"input": "8 2 2\r\n1 2 1 2 1 2 1 2\r\n", "output": "4\r\n"}, {"input": "2 100 100\r\n2 2\r\n", "output": "0\r\n"}, {"input": "1 1 1\r\n2\r\n", "output": "0\r\n"...
false
stdio
null
true
841/B
841
B
PyPy 3
TESTS
18
998
61,542,400
77345178
n = int(input().strip()) a = [ int(i)%2 for i in input().strip().split(' ')] if sum(a)%2==1: print('First') else: if a[0]==1 or a[-1]==1: print('First') else: print('Second')
88
389
82,022,400
84138124
import sys input = sys.stdin.buffer.readline input() v = list(map(int, input().split())) print("First" if any([x % 2 == 1 for x in v]) else "Second")
Codeforces Round 429 (Div. 2)
CF
2,017
2
256
Godsend
Leha somehow found an array consisting of n integers. Looking at it, he came up with a task. Two players play the game on the array. Players move one by one. The first player can choose for his move a subsegment of non-zero length with an odd sum of numbers and remove it from the array, after that the remaining parts a...
First line of input data contains single integer n (1 ≤ n ≤ 106) — length of the array. Next line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109).
Output answer in single line. "First", if first player wins, and "Second" otherwise (without quotes).
null
In first sample first player remove whole array in one move and win. In second sample first player can't make a move and lose.
[{"input": "4\n1 3 2 3", "output": "First"}, {"input": "2\n2 2", "output": "Second"}]
1,100
["games", "math"]
88
[{"input": "4\r\n1 3 2 3\r\n", "output": "First\r\n"}, {"input": "2\r\n2 2\r\n", "output": "Second\r\n"}, {"input": "4\r\n2 4 6 8\r\n", "output": "Second\r\n"}, {"input": "5\r\n1 1 1 1 1\r\n", "output": "First\r\n"}, {"input": "4\r\n720074544 345031254 849487632 80870826\r\n", "output": "Second\r\n"}, {"input": "1\r\n0...
false
stdio
null
true
369/A
369
A
PyPy 3-64
TESTS
10
61
0
181365958
inp = input().split(' ') a = int(inp[0]) b = int(inp[1]) c = int(inp[2]) l = input().split(' ') d = 0 e = 0 for i in range(len(l)): l[i] = int(l[i]) for i in range(len(l)): if l[i] == 1: d += 1 else: e += 1 e = c - e if e < 0: e *= -1 else: e = 0 d = b - d d -= e print(d*-1)
63
46
0
147812180
days, bowls, dishes = map(int, input().split()) meals = input().split(" ") wash = 0 for meal in meals: if int(meal) == 1: if bowls <= 0: wash += 1 else: bowls -= 1 else: if dishes > 0: dishes -= 1 elif bowls > 0: bowls -= 1 ...
Codeforces Round 216 (Div. 2)
CF
2,013
1
256
Valera and Plates
Valera is a lazy student. He has m clean bowls and k clean plates. Valera has made an eating plan for the next n days. As Valera is lazy, he will eat exactly one dish per day. At that, in order to eat a dish, he needs exactly one clean plate or bowl. We know that Valera can cook only two types of dishes. He can eat di...
The first line of the input contains three integers n, m, k (1 ≤ n, m, k ≤ 1000) — the number of the planned days, the number of clean bowls and the number of clean plates. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 2). If ai equals one, then on day i Valera will eat a first type dish. If ai equals ...
Print a single integer — the minimum number of times Valera will need to wash a plate/bowl.
null
In the first sample Valera will wash a bowl only on the third day, so the answer is one. In the second sample, Valera will have the first type of the dish during all four days, and since there are only three bowls, he will wash a bowl exactly once. In the third sample, Valera will have the second type of dish for all...
[{"input": "3 1 1\n1 2 1", "output": "1"}, {"input": "4 3 1\n1 1 1 1", "output": "1"}, {"input": "3 1 2\n2 2 2", "output": "0"}, {"input": "8 2 2\n1 2 1 2 1 2 1 2", "output": "4"}]
900
["greedy", "implementation"]
63
[{"input": "3 1 1\r\n1 2 1\r\n", "output": "1\r\n"}, {"input": "4 3 1\r\n1 1 1 1\r\n", "output": "1\r\n"}, {"input": "3 1 2\r\n2 2 2\r\n", "output": "0\r\n"}, {"input": "8 2 2\r\n1 2 1 2 1 2 1 2\r\n", "output": "4\r\n"}, {"input": "2 100 100\r\n2 2\r\n", "output": "0\r\n"}, {"input": "1 1 1\r\n2\r\n", "output": "0\r\n"...
false
stdio
null
true
369/A
369
A
Python 3
TESTS
10
62
0
5319949
n,m,k=map(int,input().split()) a=map(int,input().split()) for ai in a: if ai==1: m-=1 else: if k>0: k-=1 else: m-=1 print(-m)
63
46
0
149896754
n,bowls,plates = map(int,input().split(" ")) l = list(map(int,input().split(" "))) count = 0 for i in l: if(i==1): if(bowls!=0): bowls-=1 else: count+=1 else: if(bowls!=0 or plates!=0): if(plates!=0): plates-=1 else: ...
Codeforces Round 216 (Div. 2)
CF
2,013
1
256
Valera and Plates
Valera is a lazy student. He has m clean bowls and k clean plates. Valera has made an eating plan for the next n days. As Valera is lazy, he will eat exactly one dish per day. At that, in order to eat a dish, he needs exactly one clean plate or bowl. We know that Valera can cook only two types of dishes. He can eat di...
The first line of the input contains three integers n, m, k (1 ≤ n, m, k ≤ 1000) — the number of the planned days, the number of clean bowls and the number of clean plates. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 2). If ai equals one, then on day i Valera will eat a first type dish. If ai equals ...
Print a single integer — the minimum number of times Valera will need to wash a plate/bowl.
null
In the first sample Valera will wash a bowl only on the third day, so the answer is one. In the second sample, Valera will have the first type of the dish during all four days, and since there are only three bowls, he will wash a bowl exactly once. In the third sample, Valera will have the second type of dish for all...
[{"input": "3 1 1\n1 2 1", "output": "1"}, {"input": "4 3 1\n1 1 1 1", "output": "1"}, {"input": "3 1 2\n2 2 2", "output": "0"}, {"input": "8 2 2\n1 2 1 2 1 2 1 2", "output": "4"}]
900
["greedy", "implementation"]
63
[{"input": "3 1 1\r\n1 2 1\r\n", "output": "1\r\n"}, {"input": "4 3 1\r\n1 1 1 1\r\n", "output": "1\r\n"}, {"input": "3 1 2\r\n2 2 2\r\n", "output": "0\r\n"}, {"input": "8 2 2\r\n1 2 1 2 1 2 1 2\r\n", "output": "4\r\n"}, {"input": "2 100 100\r\n2 2\r\n", "output": "0\r\n"}, {"input": "1 1 1\r\n2\r\n", "output": "0\r\n"...
false
stdio
null
true
844/B
844
B
Python 3
TESTS
17
61
0
29809854
import math r,c = map(int, input().split()) arr = [] for i in range(r): l = list(map(int, input().split())) arr.append(l) cnt = 0 for i in range(r): w = arr[i][:].count(0) b = c - w cnt = cnt + math.pow(2, w) + math.pow(2, b) - 2 for i in range(c): w = 0 for j in range(r): if arr[...
55
31
0
147554723
n,m=map(int,input().split()) a = [list(map(int,input().split())) for x in range(n)] s = 0 for row in a: o,z=0,0 for i in row: if i==0: z+=1 else: o+=1 s+=2**z-1 s+=2**o-1 for col in range(m): o,z=0,0 for j in range(n): if a[j][col]==0: ...
AIM Tech Round 4 (Div. 2)
CF
2,017
1
256
Rectangles
You are given n × m table. Each cell of the table is colored white or black. Find the number of non-empty sets of cells such that: 1. All cells in a set have the same color. 2. Every two cells in a set share row or column.
The first line of input contains integers n and m (1 ≤ n, m ≤ 50) — the number of rows and the number of columns correspondingly. The next n lines of input contain descriptions of rows. There are m integers, separated by spaces, in each line. The number equals 0 if the corresponding cell is colored white and equals 1 ...
Output single integer  — the number of non-empty sets from the problem description.
null
In the second example, there are six one-element sets. Additionally, there are two two-element sets, the first one consists of the first and the third cells of the first row, the second one consists of the first and the third cells of the second row. To sum up, there are 8 sets.
[{"input": "1 1\n0", "output": "1"}, {"input": "2 3\n1 0 1\n0 1 0", "output": "8"}]
1,300
["combinatorics", "math"]
55
[{"input": "1 1\r\n0\r\n", "output": "1\r\n"}, {"input": "2 3\r\n1 0 1\r\n0 1 0\r\n", "output": "8\r\n"}, {"input": "2 2\r\n1 1\r\n1 1\r\n", "output": "8\r\n"}, {"input": "1 10\r\n0 0 0 0 0 0 0 0 0 0\r\n", "output": "1023\r\n"}, {"input": "11 1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n", "output": "204...
false
stdio
null
true
1010/A
1010
A
PyPy 3
TESTS
7
108
1,331,200
108446961
n = int(input()) m = int(input()) v = list(map(int, input().split())) p = list(map(int, input().split())) f = float(1) for i in range(0, n): f *= v[i] * p[i] k = float(1) s = float(0) for i in range(0, n - 1): s += f / v[i] * k k -= k / v[i] s += f / p[i + 1] * k k -= k / p[i + 1] s += f / v[n - 1] ...
76
46
0
152557164
# @Chukamin ZZU_TRAIN def main(): n = int(input()) m = int(input()) s = m a = list(map(int, input().split())) b = list(map(int, input().split())) def cal(n, m, s, a, b): if b[0] <= 1.00: return -1 k = s / (b[0] - 1) s += k for i in range(n - 1, 0, -1)...
Codeforces Round 499 (Div. 1)
CF
2,018
1
256
Fly
Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on $$$n - 2$$$ intermediate planets. Formally: we number all the planets from $$$1$$$ to $$$n$$$. $$$1$$$ is Earth, $$$n$$$ is Mars. Natasha will make exactly $$$n$$$ flights: $$$1 \to 2 \to \ldots n \to 1$$$. Flig...
The first line contains a single integer $$$n$$$ ($$$2 \le n \le 1000$$$) — number of planets. The second line contains the only integer $$$m$$$ ($$$1 \le m \le 1000$$$) — weight of the payload. The third line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 1000$$$), where $$$a_i$$$ is the num...
If Natasha can fly to Mars through $$$(n - 2)$$$ planets and return to Earth, print the minimum mass of fuel (in tons) that Natasha should take. Otherwise, print a single number $$$-1$$$. It is guaranteed, that if Natasha can make a flight, then it takes no more than $$$10^9$$$ tons of fuel. The answer will be consid...
null
Let's consider the first example. Initially, the mass of a rocket with fuel is $$$22$$$ tons. - At take-off from Earth one ton of fuel can lift off $$$11$$$ tons of cargo, so to lift off $$$22$$$ tons you need to burn $$$2$$$ tons of fuel. Remaining weight of the rocket with fuel is $$$20$$$ tons. - During landing on...
[{"input": "2\n12\n11 8\n7 5", "output": "10.0000000000"}, {"input": "3\n1\n1 4 1\n2 5 3", "output": "-1"}, {"input": "6\n2\n4 6 3 3 5 6\n2 6 3 6 5 3", "output": "85.4800000000"}]
1,500
["binary search", "math"]
76
[{"input": "2\r\n12\r\n11 8\r\n7 5\r\n", "output": "10.0000000000\r\n"}, {"input": "3\r\n1\r\n1 4 1\r\n2 5 3\r\n", "output": "-1\r\n"}, {"input": "6\r\n2\r\n4 6 3 3 5 6\r\n2 6 3 6 5 3\r\n", "output": "85.4800000000\r\n"}, {"input": "3\r\n3\r\n1 2 1\r\n2 2 2\r\n", "output": "-1\r\n"}, {"input": "4\r\n4\r\n2 3 2 2\r\n2 3...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] with open(output_path, 'r') as f: ref_line = f.readline().strip() with open(submission_path, 'r') as f: sub_line = f.readline().strip() if ref_line == "-1": if sub_...
true
1010/A
1010
A
PyPy 3
TESTS
57
280
10,240,000
107171909
###### ### ####### ####### ## # ##### ### ##### # # # # # # # # # # # # # ### # # # # # # # # # # # # # ### ###### ######### # # # # # # ...
76
46
0
207287724
import sys from itertools import chain n = int(input()) payload = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(chain.from_iterable(zip(a, b))) c = c[1:] + [c[0]] weight = payload for i in c: if i == 1: print(-1) sys.exit() weight *= i/(i-1) pr...
Codeforces Round 499 (Div. 1)
CF
2,018
1
256
Fly
Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on $$$n - 2$$$ intermediate planets. Formally: we number all the planets from $$$1$$$ to $$$n$$$. $$$1$$$ is Earth, $$$n$$$ is Mars. Natasha will make exactly $$$n$$$ flights: $$$1 \to 2 \to \ldots n \to 1$$$. Flig...
The first line contains a single integer $$$n$$$ ($$$2 \le n \le 1000$$$) — number of planets. The second line contains the only integer $$$m$$$ ($$$1 \le m \le 1000$$$) — weight of the payload. The third line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 1000$$$), where $$$a_i$$$ is the num...
If Natasha can fly to Mars through $$$(n - 2)$$$ planets and return to Earth, print the minimum mass of fuel (in tons) that Natasha should take. Otherwise, print a single number $$$-1$$$. It is guaranteed, that if Natasha can make a flight, then it takes no more than $$$10^9$$$ tons of fuel. The answer will be consid...
null
Let's consider the first example. Initially, the mass of a rocket with fuel is $$$22$$$ tons. - At take-off from Earth one ton of fuel can lift off $$$11$$$ tons of cargo, so to lift off $$$22$$$ tons you need to burn $$$2$$$ tons of fuel. Remaining weight of the rocket with fuel is $$$20$$$ tons. - During landing on...
[{"input": "2\n12\n11 8\n7 5", "output": "10.0000000000"}, {"input": "3\n1\n1 4 1\n2 5 3", "output": "-1"}, {"input": "6\n2\n4 6 3 3 5 6\n2 6 3 6 5 3", "output": "85.4800000000"}]
1,500
["binary search", "math"]
76
[{"input": "2\r\n12\r\n11 8\r\n7 5\r\n", "output": "10.0000000000\r\n"}, {"input": "3\r\n1\r\n1 4 1\r\n2 5 3\r\n", "output": "-1\r\n"}, {"input": "6\r\n2\r\n4 6 3 3 5 6\r\n2 6 3 6 5 3\r\n", "output": "85.4800000000\r\n"}, {"input": "3\r\n3\r\n1 2 1\r\n2 2 2\r\n", "output": "-1\r\n"}, {"input": "4\r\n4\r\n2 3 2 2\r\n2 3...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] with open(output_path, 'r') as f: ref_line = f.readline().strip() with open(submission_path, 'r') as f: sub_line = f.readline().strip() if ref_line == "-1": if sub_...
true
114/B
114
B
Python 3
TESTS
13
62
307,200
206005356
from collections import defaultdict, deque import heapq n , m = list(map(int, input().split())) graph = defaultdict(list) lst = [] color = [-1 for _ in range(n)] for _ in range(n): name = input() lst.append(name) idx_map = {node:i for i, node in enumerate(lst)} for _ in range( m): a, b = input().split() ...
61
156
0
4452016
n,m=map(int,input().split()) N=[n] Names={} Numbers={} Enemies=[] for i in range(n): s=input() Names[s]=i Enemies.append([]) Numbers[i]=str(s) for i in range(m): a,b=input().split() Enemies[Names[a]].append(Names[b]) Enemies[Names[b]].append(Names[a]) Ans=[[]] def dp(N,i,Taken,Forbidden): ...
Codeforces Beta Round 86 (Div. 2 Only)
CF
2,011
2
256
PFAST Inc.
When little Petya grew up and entered the university, he started to take part in АСМ contests. Later he realized that he doesn't like how the АСМ contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members eff...
The first line contains two integer numbers n (1 ≤ n ≤ 16) — the number of volunteers, and m ($$0 \leq m \leq \frac{n(n-1)}{2}$$) — the number of pairs that do not get on. Next n lines contain the volunteers' names (each name is a non-empty string consisting of no more than 10 uppercase and/or lowercase Latin letters)....
The first output line should contain the single number k — the number of people in the sought team. Next k lines should contain the names of the sought team's participants in the lexicographical order. If there are several variants to solve the problem, print any of them. Petya might not be a member of the sought team.
null
null
[{"input": "3 1\nPetya\nVasya\nMasha\nPetya Vasya", "output": "2\nMasha\nPetya"}, {"input": "3 0\nPasha\nLesha\nVanya", "output": "3\nLesha\nPasha\nVanya"}]
1,500
["bitmasks", "brute force", "graphs"]
61
[{"input": "3 1\r\nPetya\r\nVasya\r\nMasha\r\nPetya Vasya\r\n", "output": "2\r\nMasha\r\nPetya\r\n"}, {"input": "3 0\r\nPasha\r\nLesha\r\nVanya\r\n", "output": "3\r\nLesha\r\nPasha\r\nVanya\r\n"}, {"input": "7 12\r\nPasha\r\nLesha\r\nVanya\r\nTaras\r\nNikita\r\nSergey\r\nAndrey\r\nPasha Taras\r\nPasha Nikita\r\nPasha A...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] # Read input with open(input_path, 'r') as f: input_lines = [line.strip() for line in f.readlines()] if not input_lines: print(0) return n, m = map(int, input_l...
true
219/A
219
A
PyPy 3
TESTS
10
154
0
143901089
n = int(input()) s = input() d = dict() for i in s: if(i in d): d[i]+=1 else: d[i]=1 possible = True for i in d: if(d[i]%n!=0): possible = False if(not possible): print(-1) else: base = "" for i in d: prop = int((d[i]/len(s))*(len(s)/n)) #print(i, prop) ...
42
62
0
170409042
k=int(input()) s=sorted(input()) ans=s[::k]*k x = "".join(ans) if sorted(x)==s: print(x) else: print(-1)
Codeforces Round 135 (Div. 2)
CF
2,012
2
256
k-String
A string is called a k-string if it can be represented as k concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string. You are given a string s, ...
The first input line contains integer k (1 ≤ k ≤ 1000). The second line contains s, all characters in s are lowercase English letters. The string length s satisfies the inequality 1 ≤ |s| ≤ 1000, where |s| is the length of string s.
Rearrange the letters in string s in such a way that the result is a k-string. Print the result on a single output line. If there are multiple solutions, print any of them. If the solution doesn't exist, print "-1" (without quotes).
null
null
[{"input": "2\naazz", "output": "azaz"}, {"input": "3\nabcabcabz", "output": "-1"}]
1,000
["implementation", "strings"]
42
[{"input": "2\r\naazz\r\n", "output": "azaz\r\n"}, {"input": "3\r\nabcabcabz\r\n", "output": "-1\r\n"}, {"input": "1\r\na\r\n", "output": "a\r\n"}, {"input": "2\r\nabba\r\n", "output": "abab\r\n"}, {"input": "2\r\naaab\r\n", "output": "-1\r\n"}, {"input": "7\r\nabacaba\r\n", "output": "-1\r\n"}, {"input": "5\r\naaaaa\r...
false
stdio
null
true
992/A
992
A
Python 3
TESTS
56
249
7,372,800
40918186
n = int(input()) a = [int(x) for x in input().split()] a.sort() count = 0 for i in range(0,n-1): if a[i] != 0: if a[i] != a[i+1]: count += 1 if count == 0 and a[0] == 0: print(count) else: print(count+1)
79
62
7,372,800
147958735
size_of_list = input() list1 = list(map(int, input().split())) counter = len(set(list1)) if 0 in list1: counter -= 1 print(counter)
Codeforces Round 489 (Div. 2)
CF
2,018
1
256
Nastya and an Array
Nastya owns too many arrays now, so she wants to delete the least important of them. However, she discovered that this array is magic! Nastya now knows that the array has the following properties: - In one second we can add an arbitrary (possibly negative) integer to all elements of the array that are not equal to zer...
The first line contains a single integer n (1 ≤ n ≤ 105) — the size of the array. The second line contains n integers a1, a2, ..., an ( - 105 ≤ ai ≤ 105) — the elements of the array.
Print a single integer — the minimum number of seconds needed to make all elements of the array equal to zero.
null
In the first example you can add - 1 to all non-zero elements in one second and make them equal to zero. In the second example you can add - 2 on the first second, then the array becomes equal to [0, 0, - 3]. On the second second you can add 3 to the third (the only non-zero) element.
[{"input": "5\n1 1 1 1 1", "output": "1"}, {"input": "3\n2 0 -1", "output": "2"}, {"input": "4\n5 -6 -5 1", "output": "4"}]
800
["implementation", "sortings"]
79
[{"input": "5\r\n1 1 1 1 1\r\n", "output": "1\r\n"}, {"input": "3\r\n2 0 -1\r\n", "output": "2\r\n"}, {"input": "4\r\n5 -6 -5 1\r\n", "output": "4\r\n"}, {"input": "1\r\n0\r\n", "output": "0\r\n"}, {"input": "2\r\n21794 -79194\r\n", "output": "2\r\n"}, {"input": "3\r\n-63526 95085 -5239\r\n", "output": "3\r\n"}, {"inpu...
false
stdio
null
true
844/B
844
B
Python 3
TESTS
17
46
4,505,600
133295165
from math import factorial x, y = map(int, input().split()) matriz = [] for i in range (x): a = input().split(" ") matriz.append(a) result = x * y for i in range (x): # For principal para linhas; navio = 0 submarino = 0 count3 = 0 for j in range (y): # Somando o nº elemento...
55
46
0
145717115
n,m=map(int,input().split()) L=[list(map(int,input().split()))for i in range(n)] M=[0]*m S=0 for i in range(n): ll=sum(L[i]) S+=(1<<ll)-1+(1<<(m-ll))-1 for j in range(m):M[j]+=L[i][j] for x in M: S+=max(0,(1<<x)-1-x)+max(0,(1<<(n-x))-1-(n-x)) print(S)
AIM Tech Round 4 (Div. 2)
CF
2,017
1
256
Rectangles
You are given n × m table. Each cell of the table is colored white or black. Find the number of non-empty sets of cells such that: 1. All cells in a set have the same color. 2. Every two cells in a set share row or column.
The first line of input contains integers n and m (1 ≤ n, m ≤ 50) — the number of rows and the number of columns correspondingly. The next n lines of input contain descriptions of rows. There are m integers, separated by spaces, in each line. The number equals 0 if the corresponding cell is colored white and equals 1 ...
Output single integer  — the number of non-empty sets from the problem description.
null
In the second example, there are six one-element sets. Additionally, there are two two-element sets, the first one consists of the first and the third cells of the first row, the second one consists of the first and the third cells of the second row. To sum up, there are 8 sets.
[{"input": "1 1\n0", "output": "1"}, {"input": "2 3\n1 0 1\n0 1 0", "output": "8"}]
1,300
["combinatorics", "math"]
55
[{"input": "1 1\r\n0\r\n", "output": "1\r\n"}, {"input": "2 3\r\n1 0 1\r\n0 1 0\r\n", "output": "8\r\n"}, {"input": "2 2\r\n1 1\r\n1 1\r\n", "output": "8\r\n"}, {"input": "1 10\r\n0 0 0 0 0 0 0 0 0 0\r\n", "output": "1023\r\n"}, {"input": "11 1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n", "output": "204...
false
stdio
null
true
844/B
844
B
Python 3
TESTS
17
61
0
171626330
from math import factorial linhas, colunas = input().split() linhas, colunas = int(linhas), int(colunas) table = [[0 for _ in range(colunas)] for _ in range(linhas)] cells = linhas * colunas for i in range(linhas): entrada = input().split() for j in range(colunas): table[i][j] = entrada[j] for i in ...
55
46
0
146215928
tc=list(map(int, input().rstrip().split())) n=tc[0] m=tc[1] ans=0 brr=[] for j in range(n): ar= list(map(int, input().rstrip().split())) brr.append(ar) oc=0 zc=0 for i in range(m): if(ar[i]==1): oc+=1 else: zc+=1 ans+=((2**oc-1)+(2**zc-1)) for j in range(m...
AIM Tech Round 4 (Div. 2)
CF
2,017
1
256
Rectangles
You are given n × m table. Each cell of the table is colored white or black. Find the number of non-empty sets of cells such that: 1. All cells in a set have the same color. 2. Every two cells in a set share row or column.
The first line of input contains integers n and m (1 ≤ n, m ≤ 50) — the number of rows and the number of columns correspondingly. The next n lines of input contain descriptions of rows. There are m integers, separated by spaces, in each line. The number equals 0 if the corresponding cell is colored white and equals 1 ...
Output single integer  — the number of non-empty sets from the problem description.
null
In the second example, there are six one-element sets. Additionally, there are two two-element sets, the first one consists of the first and the third cells of the first row, the second one consists of the first and the third cells of the second row. To sum up, there are 8 sets.
[{"input": "1 1\n0", "output": "1"}, {"input": "2 3\n1 0 1\n0 1 0", "output": "8"}]
1,300
["combinatorics", "math"]
55
[{"input": "1 1\r\n0\r\n", "output": "1\r\n"}, {"input": "2 3\r\n1 0 1\r\n0 1 0\r\n", "output": "8\r\n"}, {"input": "2 2\r\n1 1\r\n1 1\r\n", "output": "8\r\n"}, {"input": "1 10\r\n0 0 0 0 0 0 0 0 0 0\r\n", "output": "1023\r\n"}, {"input": "11 1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n", "output": "204...
false
stdio
null
true
413/C
413
C
Python 3
TESTS
29
77
0
6426326
n, m = map(int, input().split()) s = list(map(int, input().split())) p = list(map(int, input().split())) snew = [] for i in range(m): snew.append(s[p[i] - 1]) suum = 0 for i in range(n): if (i + 1) in p: pass else: suum += s[i] snew = sorted(snew) i = 0 while (1): if len(snew) == 0: ...
67
62
0
6426233
n, m = list(map(int, input().split())) lst = list(map(int, input().split())) au = list(map(int, input().split())) res = sum(lst) ls = [] for i in range(m): res -= lst[au[i] - 1] ls.append(lst[au[i] - 1]) ls.sort(reverse = True) for i in range(len(ls)): res += max(ls[i], res) print(res)
Coder-Strike 2014 - Round 2
CF
2,014
1
256
Jeopardy!
'Jeopardy!' is an intellectual game where players answer questions and earn points. Company Q conducts a simplified 'Jeopardy!' tournament among the best IT companies. By a lucky coincidence, the old rivals made it to the finals: company R1 and company R2. The finals will have n questions, m of them are auction questi...
The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 100; m ≤ min(n, 30)) — the total number of questions and the number of auction questions, correspondingly. The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 107) — the prices of the questions. The third line contains m ...
In the single line, print the answer to the problem — the maximum points the R2 company can get if it plays optimally well. It is guaranteed that the answer fits into the integer 64-bit signed type.
null
null
[{"input": "4 1\n1 3 7 5\n3", "output": "18"}, {"input": "3 2\n10 3 8\n2 3", "output": "40"}, {"input": "2 2\n100 200\n1 2", "output": "400"}]
1,400
["greedy", "math"]
67
[{"input": "4 1\r\n1 3 7 5\r\n3\r\n", "output": "18\r\n"}, {"input": "3 2\r\n10 3 8\r\n2 3\r\n", "output": "40\r\n"}, {"input": "2 2\r\n100 200\r\n1 2\r\n", "output": "400\r\n"}, {"input": "1 1\r\n1\r\n1\r\n", "output": "1\r\n"}, {"input": "2 2\r\n1 5\r\n1 2\r\n", "output": "10\r\n"}, {"input": "5 3\r\n5 8 7 1 9\r\n2 5...
false
stdio
null
true
508/C
508
C
PyPy 3-64
TESTS
11
62
1,638,400
179940928
m,t,r=map(int,input().split()) l=[0 for _ in range(1200)] g=[] start=600 ans=0 g=list(map(int,input().split())) if r+1>t:print(-1) else: for i in range(m): gi=g[i] start=gi+600#映射 cha=max(0,r-l[start]) # print(start,cha) d=0 while cha: for j in range(star...
61
46
0
229882450
R=lambda:map(int,input().split());a,b,c=R();A=[*R()];B=[c] for i in range(1,a): j=i-1;k=c while j+1 and k>0 and (s:=min(b-A[i]+A[j],B[j]))>=0:k-=s;j-=1 B+=[max(k,0)] print([sum(B),-1][c>b])
Codeforces Round 288 (Div. 2)
CF
2,015
2
256
Anya and Ghosts
Anya loves to watch horror movies. In the best traditions of horror, she will be visited by m ghosts tonight. Anya has lots of candles prepared for the visits, each candle can produce light for exactly t seconds. It takes the girl one second to light one candle. More formally, Anya can spend one second to light one can...
The first line contains three integers m, t, r (1 ≤ m, t, r ≤ 300), representing the number of ghosts to visit Anya, the duration of a candle's burning and the minimum number of candles that should burn during each visit. The next line contains m space-separated numbers wi (1 ≤ i ≤ m, 1 ≤ wi ≤ 300), the i-th of them r...
If it is possible to make at least r candles burn during each visit, then print the minimum number of candles that Anya needs to light for that. If that is impossible, print - 1.
null
Anya can start lighting a candle in the same second with ghost visit. But this candle isn't counted as burning at this visit. It takes exactly one second to light up a candle and only after that second this candle is considered burning; it means that if Anya starts lighting candle at moment x, candle is buring from se...
[{"input": "1 8 3\n10", "output": "3"}, {"input": "2 10 1\n5 8", "output": "1"}, {"input": "1 1 3\n10", "output": "-1"}]
1,600
["constructive algorithms", "greedy"]
61
[{"input": "1 8 3\r\n10\r\n", "output": "3\r\n"}, {"input": "2 10 1\r\n5 8\r\n", "output": "1\r\n"}, {"input": "1 1 3\r\n10\r\n", "output": "-1\r\n"}, {"input": "21 79 1\r\n13 42 51 60 69 77 94 103 144 189 196 203 210 215 217 222 224 234 240 260 282\r\n", "output": "4\r\n"}, {"input": "125 92 2\r\n1 2 3 4 5 7 8 9 10 12...
false
stdio
null
true
1010/A
1010
A
PyPy 3
TESTS
57
170
1,740,800
118278200
n = int(input()) m = int(input()) a = [int(i) for i in input().split()] b = [int(i) for i in input().split()] low = 1 high = 1000000000 ans = -1 while low<=high: if high-low < 0.000001: high = low mid = low+(high-low)/2 try_val = mid init_wt = m+try_val isPossible = True for i in range(n): req1 = init_wt/a[i...
76
46
102,400
207287922
import math n = int(input()) payload = int(input()) coeffs = list(map(int, input().split() + input().split())) if 1 in coeffs: print(-1) else: print(payload*(math.prod([c/(c-1) for c in coeffs])-1))
Codeforces Round 499 (Div. 1)
CF
2,018
1
256
Fly
Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on $$$n - 2$$$ intermediate planets. Formally: we number all the planets from $$$1$$$ to $$$n$$$. $$$1$$$ is Earth, $$$n$$$ is Mars. Natasha will make exactly $$$n$$$ flights: $$$1 \to 2 \to \ldots n \to 1$$$. Flig...
The first line contains a single integer $$$n$$$ ($$$2 \le n \le 1000$$$) — number of planets. The second line contains the only integer $$$m$$$ ($$$1 \le m \le 1000$$$) — weight of the payload. The third line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 1000$$$), where $$$a_i$$$ is the num...
If Natasha can fly to Mars through $$$(n - 2)$$$ planets and return to Earth, print the minimum mass of fuel (in tons) that Natasha should take. Otherwise, print a single number $$$-1$$$. It is guaranteed, that if Natasha can make a flight, then it takes no more than $$$10^9$$$ tons of fuel. The answer will be consid...
null
Let's consider the first example. Initially, the mass of a rocket with fuel is $$$22$$$ tons. - At take-off from Earth one ton of fuel can lift off $$$11$$$ tons of cargo, so to lift off $$$22$$$ tons you need to burn $$$2$$$ tons of fuel. Remaining weight of the rocket with fuel is $$$20$$$ tons. - During landing on...
[{"input": "2\n12\n11 8\n7 5", "output": "10.0000000000"}, {"input": "3\n1\n1 4 1\n2 5 3", "output": "-1"}, {"input": "6\n2\n4 6 3 3 5 6\n2 6 3 6 5 3", "output": "85.4800000000"}]
1,500
["binary search", "math"]
76
[{"input": "2\r\n12\r\n11 8\r\n7 5\r\n", "output": "10.0000000000\r\n"}, {"input": "3\r\n1\r\n1 4 1\r\n2 5 3\r\n", "output": "-1\r\n"}, {"input": "6\r\n2\r\n4 6 3 3 5 6\r\n2 6 3 6 5 3\r\n", "output": "85.4800000000\r\n"}, {"input": "3\r\n3\r\n1 2 1\r\n2 2 2\r\n", "output": "-1\r\n"}, {"input": "4\r\n4\r\n2 3 2 2\r\n2 3...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] with open(output_path, 'r') as f: ref_line = f.readline().strip() with open(submission_path, 'r') as f: sub_line = f.readline().strip() if ref_line == "-1": if sub_...
true
1010/A
1010
A
PyPy 3
TESTS
57
155
1,945,600
61670265
def sol(a): a+=m for i in range(n): x=aa[i] if i==n-1: y=bb[0] else: y=bb[i+1] a-=(a/x) if a<0: return -1 a-=(a/y) if a<0: return -1 return a-m n=int(input()) m=int(input()) aa=list(map(int,input().s...
76
77
1,228,800
204533477
import sys input=sys.stdin.readline import bisect n=int(input()) m=int(input()) a=list(map(int,input().strip().split())) b=list(map(int,input().strip().split())) if 1 in a or 1 in b: sys.stdout.write(str(-1)+'\n') else: ans=m for i in range(n): ans=ans/(1-(1/a[i])) ans=ans/(1-(1/b[i])) ...
Codeforces Round 499 (Div. 1)
CF
2,018
1
256
Fly
Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on $$$n - 2$$$ intermediate planets. Formally: we number all the planets from $$$1$$$ to $$$n$$$. $$$1$$$ is Earth, $$$n$$$ is Mars. Natasha will make exactly $$$n$$$ flights: $$$1 \to 2 \to \ldots n \to 1$$$. Flig...
The first line contains a single integer $$$n$$$ ($$$2 \le n \le 1000$$$) — number of planets. The second line contains the only integer $$$m$$$ ($$$1 \le m \le 1000$$$) — weight of the payload. The third line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 1000$$$), where $$$a_i$$$ is the num...
If Natasha can fly to Mars through $$$(n - 2)$$$ planets and return to Earth, print the minimum mass of fuel (in tons) that Natasha should take. Otherwise, print a single number $$$-1$$$. It is guaranteed, that if Natasha can make a flight, then it takes no more than $$$10^9$$$ tons of fuel. The answer will be consid...
null
Let's consider the first example. Initially, the mass of a rocket with fuel is $$$22$$$ tons. - At take-off from Earth one ton of fuel can lift off $$$11$$$ tons of cargo, so to lift off $$$22$$$ tons you need to burn $$$2$$$ tons of fuel. Remaining weight of the rocket with fuel is $$$20$$$ tons. - During landing on...
[{"input": "2\n12\n11 8\n7 5", "output": "10.0000000000"}, {"input": "3\n1\n1 4 1\n2 5 3", "output": "-1"}, {"input": "6\n2\n4 6 3 3 5 6\n2 6 3 6 5 3", "output": "85.4800000000"}]
1,500
["binary search", "math"]
76
[{"input": "2\r\n12\r\n11 8\r\n7 5\r\n", "output": "10.0000000000\r\n"}, {"input": "3\r\n1\r\n1 4 1\r\n2 5 3\r\n", "output": "-1\r\n"}, {"input": "6\r\n2\r\n4 6 3 3 5 6\r\n2 6 3 6 5 3\r\n", "output": "85.4800000000\r\n"}, {"input": "3\r\n3\r\n1 2 1\r\n2 2 2\r\n", "output": "-1\r\n"}, {"input": "4\r\n4\r\n2 3 2 2\r\n2 3...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] with open(output_path, 'r') as f: ref_line = f.readline().strip() with open(submission_path, 'r') as f: sub_line = f.readline().strip() if ref_line == "-1": if sub_...
true
1010/A
1010
A
PyPy 3
TESTS
57
155
512,000
40907859
R = lambda: map(int, input().split()) n = int(input()) m = int(input()) a, b = list(R()), list(R()) b = b[1:] + b[:1] l, r = 0, 2 * 10**9 while (r - l) / max(1, r) >= 1e-7 and l < 10**9: rem = mid = (l + r) / 2 for i in range(n): rem -= (m + max(0, rem)) / a[i] rem -= (m + max(0, rem)) / b[i] ...
76
77
1,536,000
145485723
R = lambda: map(int, input().split()) n = int(input()) sw = int(input()) lifts = list(R()) lands = list(R()) l, r = 0, 10 ** 9 + 1 while r - l > 10 ** -6: fuel = (l + r) / 2 rem = fuel for i in range(n): rem -= (rem + sw) / lifts[i] if rem < 0: break rem -= (rem + sw) / l...
Codeforces Round 499 (Div. 1)
CF
2,018
1
256
Fly
Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on $$$n - 2$$$ intermediate planets. Formally: we number all the planets from $$$1$$$ to $$$n$$$. $$$1$$$ is Earth, $$$n$$$ is Mars. Natasha will make exactly $$$n$$$ flights: $$$1 \to 2 \to \ldots n \to 1$$$. Flig...
The first line contains a single integer $$$n$$$ ($$$2 \le n \le 1000$$$) — number of planets. The second line contains the only integer $$$m$$$ ($$$1 \le m \le 1000$$$) — weight of the payload. The third line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 1000$$$), where $$$a_i$$$ is the num...
If Natasha can fly to Mars through $$$(n - 2)$$$ planets and return to Earth, print the minimum mass of fuel (in tons) that Natasha should take. Otherwise, print a single number $$$-1$$$. It is guaranteed, that if Natasha can make a flight, then it takes no more than $$$10^9$$$ tons of fuel. The answer will be consid...
null
Let's consider the first example. Initially, the mass of a rocket with fuel is $$$22$$$ tons. - At take-off from Earth one ton of fuel can lift off $$$11$$$ tons of cargo, so to lift off $$$22$$$ tons you need to burn $$$2$$$ tons of fuel. Remaining weight of the rocket with fuel is $$$20$$$ tons. - During landing on...
[{"input": "2\n12\n11 8\n7 5", "output": "10.0000000000"}, {"input": "3\n1\n1 4 1\n2 5 3", "output": "-1"}, {"input": "6\n2\n4 6 3 3 5 6\n2 6 3 6 5 3", "output": "85.4800000000"}]
1,500
["binary search", "math"]
76
[{"input": "2\r\n12\r\n11 8\r\n7 5\r\n", "output": "10.0000000000\r\n"}, {"input": "3\r\n1\r\n1 4 1\r\n2 5 3\r\n", "output": "-1\r\n"}, {"input": "6\r\n2\r\n4 6 3 3 5 6\r\n2 6 3 6 5 3\r\n", "output": "85.4800000000\r\n"}, {"input": "3\r\n3\r\n1 2 1\r\n2 2 2\r\n", "output": "-1\r\n"}, {"input": "4\r\n4\r\n2 3 2 2\r\n2 3...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] with open(output_path, 'r') as f: ref_line = f.readline().strip() with open(submission_path, 'r') as f: sub_line = f.readline().strip() if ref_line == "-1": if sub_...
true
413/C
413
C
PyPy 3
TESTS
29
156
0
102198653
n_m_input = input() n = int(n_m_input.split(" ")[0]) m = int(n_m_input.split(" ")[1]) temp_input = input() main_list = [int(i) for i in temp_input.split(" ")] temp_input = input() float_up_list = [int(i) for i in temp_input.split(" ")] sum = sum(main_list) float_up_marks = [] for i in range(len(float_up_list)) : su...
67
62
0
6439004
n,m = map(int,input().split()) mat = list(map(int,input().split())) auction = list(map(int,input().split())) aucpoint = [mat[i-1] for i in auction] aucpoint.sort(reverse = True) for i in auction: mat[i-1] = 0 s = sum(mat) for point in aucpoint: if s > point: s *= 2 else: s += point print(s)
Coder-Strike 2014 - Round 2
CF
2,014
1
256
Jeopardy!
'Jeopardy!' is an intellectual game where players answer questions and earn points. Company Q conducts a simplified 'Jeopardy!' tournament among the best IT companies. By a lucky coincidence, the old rivals made it to the finals: company R1 and company R2. The finals will have n questions, m of them are auction questi...
The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 100; m ≤ min(n, 30)) — the total number of questions and the number of auction questions, correspondingly. The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 107) — the prices of the questions. The third line contains m ...
In the single line, print the answer to the problem — the maximum points the R2 company can get if it plays optimally well. It is guaranteed that the answer fits into the integer 64-bit signed type.
null
null
[{"input": "4 1\n1 3 7 5\n3", "output": "18"}, {"input": "3 2\n10 3 8\n2 3", "output": "40"}, {"input": "2 2\n100 200\n1 2", "output": "400"}]
1,400
["greedy", "math"]
67
[{"input": "4 1\r\n1 3 7 5\r\n3\r\n", "output": "18\r\n"}, {"input": "3 2\r\n10 3 8\r\n2 3\r\n", "output": "40\r\n"}, {"input": "2 2\r\n100 200\r\n1 2\r\n", "output": "400\r\n"}, {"input": "1 1\r\n1\r\n1\r\n", "output": "1\r\n"}, {"input": "2 2\r\n1 5\r\n1 2\r\n", "output": "10\r\n"}, {"input": "5 3\r\n5 8 7 1 9\r\n2 5...
false
stdio
null
true
116/A
116
A
Python 3
TESTS
4
62
0
220245066
exitl = [] enterl = [] ca = [] number_of_stops = int(input()) for i in range(number_of_stops): exit, enter = map(int, input().split()) exitl.append(exit) enterl.append(enter) i = 0 while i != (len(enterl)-1): ca.append(enterl[i]+enterl[i+1] - exitl[i+1]) enterl[i+1] = ca[-1] i += 1 print(max(ca...
71
92
0
208042207
n=int(input()) TOTAL=int(input().split()[1]) REMAINING=TOTAL for _ in range(1,n): a,b= map(int,input().split()) REMAINING+=b-a TOTAL=max(TOTAL,REMAINING) print(TOTAL)
Codeforces Beta Round 87 (Div. 2 Only)
CF
2,011
2
256
Tram
Linear Kingdom has exactly one tram line. It has n stops, numbered from 1 to n in the order of tram's movement. At the i-th stop ai passengers exit the tram, while bi passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it ...
The first line contains a single number n (2 ≤ n ≤ 1000) — the number of the tram's stops. Then n lines follow, each contains two integers ai and bi (0 ≤ ai, bi ≤ 1000) — the number of passengers that exits the tram at the i-th stop, and the number of passengers that enter the tram at the i-th stop. The stops are give...
Print a single integer denoting the minimum possible capacity of the tram (0 is allowed).
null
For the first example, a capacity of 6 is sufficient: - At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. - At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 pas...
[{"input": "4\n0 3\n2 5\n4 2\n4 0", "output": "6"}]
800
["implementation"]
71
[{"input": "4\r\n0 3\r\n2 5\r\n4 2\r\n4 0\r\n", "output": "6\r\n"}, {"input": "5\r\n0 4\r\n4 6\r\n6 5\r\n5 4\r\n4 0\r\n", "output": "6\r\n"}, {"input": "10\r\n0 5\r\n1 7\r\n10 8\r\n5 3\r\n0 5\r\n3 3\r\n8 8\r\n0 6\r\n10 1\r\n9 0\r\n", "output": "18\r\n"}, {"input": "3\r\n0 1\r\n1 1\r\n1 0\r\n", "output": "1\r\n"}, {"inp...
false
stdio
null
true
114/B
114
B
PyPy 3-64
TESTS
13
124
0
206005801
from collections import defaultdict n, m = map(int, input().split()) names = [] for _ in range(n): names.append(input()) dont_agree = defaultdict(list) degree = defaultdict(int) for _ in range(m): name1, name2 = input().split() dont_agree[name1].append(name2) dont_agree[name2].append(name1) de...
61
280
9,625,600
114249250
def good(a,bad): for i in bad: if i[0]in a: if i[1] in a: return False return True def f(arr,bad,d): n=len(arr) mask=0 ans=[] while mask<1<<n: temp=[] for i in range(len(arr)): if mask &(1<<i): temp.append(i) ...
Codeforces Beta Round 86 (Div. 2 Only)
CF
2,011
2
256
PFAST Inc.
When little Petya grew up and entered the university, he started to take part in АСМ contests. Later he realized that he doesn't like how the АСМ contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members eff...
The first line contains two integer numbers n (1 ≤ n ≤ 16) — the number of volunteers, and m ($$0 \leq m \leq \frac{n(n-1)}{2}$$) — the number of pairs that do not get on. Next n lines contain the volunteers' names (each name is a non-empty string consisting of no more than 10 uppercase and/or lowercase Latin letters)....
The first output line should contain the single number k — the number of people in the sought team. Next k lines should contain the names of the sought team's participants in the lexicographical order. If there are several variants to solve the problem, print any of them. Petya might not be a member of the sought team.
null
null
[{"input": "3 1\nPetya\nVasya\nMasha\nPetya Vasya", "output": "2\nMasha\nPetya"}, {"input": "3 0\nPasha\nLesha\nVanya", "output": "3\nLesha\nPasha\nVanya"}]
1,500
["bitmasks", "brute force", "graphs"]
61
[{"input": "3 1\r\nPetya\r\nVasya\r\nMasha\r\nPetya Vasya\r\n", "output": "2\r\nMasha\r\nPetya\r\n"}, {"input": "3 0\r\nPasha\r\nLesha\r\nVanya\r\n", "output": "3\r\nLesha\r\nPasha\r\nVanya\r\n"}, {"input": "7 12\r\nPasha\r\nLesha\r\nVanya\r\nTaras\r\nNikita\r\nSergey\r\nAndrey\r\nPasha Taras\r\nPasha Nikita\r\nPasha A...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] # Read input with open(input_path, 'r') as f: input_lines = [line.strip() for line in f.readlines()] if not input_lines: print(0) return n, m = map(int, input_l...
true
114/B
114
B
Python 3
TESTS
13
92
307,200
206005999
from collections import defaultdict graph=defaultdict(list) count=defaultdict(int) no_ofpeople,edges=map(int,input().split()) for i in range(no_ofpeople): count[input()]=0 for i in range(edges): person1,person2=input().split() count[person1]+=1 count[person2]+=1 graph[person1].append(person2) gr...
61
280
10,240,000
206008232
from collections import defaultdict n, m = map(int, input().split()) names = [] for _ in range(n): names.append(input()) dont_agree = defaultdict(list) degree = defaultdict(int) for _ in range(m): name1, name2 = input().split() dont_agree[name1].append(name2) dont_agree[name2].append(name1) degr...
Codeforces Beta Round 86 (Div. 2 Only)
CF
2,011
2
256
PFAST Inc.
When little Petya grew up and entered the university, he started to take part in АСМ contests. Later he realized that he doesn't like how the АСМ contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members eff...
The first line contains two integer numbers n (1 ≤ n ≤ 16) — the number of volunteers, and m ($$0 \leq m \leq \frac{n(n-1)}{2}$$) — the number of pairs that do not get on. Next n lines contain the volunteers' names (each name is a non-empty string consisting of no more than 10 uppercase and/or lowercase Latin letters)....
The first output line should contain the single number k — the number of people in the sought team. Next k lines should contain the names of the sought team's participants in the lexicographical order. If there are several variants to solve the problem, print any of them. Petya might not be a member of the sought team.
null
null
[{"input": "3 1\nPetya\nVasya\nMasha\nPetya Vasya", "output": "2\nMasha\nPetya"}, {"input": "3 0\nPasha\nLesha\nVanya", "output": "3\nLesha\nPasha\nVanya"}]
1,500
["bitmasks", "brute force", "graphs"]
61
[{"input": "3 1\r\nPetya\r\nVasya\r\nMasha\r\nPetya Vasya\r\n", "output": "2\r\nMasha\r\nPetya\r\n"}, {"input": "3 0\r\nPasha\r\nLesha\r\nVanya\r\n", "output": "3\r\nLesha\r\nPasha\r\nVanya\r\n"}, {"input": "7 12\r\nPasha\r\nLesha\r\nVanya\r\nTaras\r\nNikita\r\nSergey\r\nAndrey\r\nPasha Taras\r\nPasha Nikita\r\nPasha A...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] # Read input with open(input_path, 'r') as f: input_lines = [line.strip() for line in f.readlines()] if not input_lines: print(0) return n, m = map(int, input_l...
true
116/A
116
A
Python 3
TESTS
4
62
0
224671001
n=int(input()) A=[] B=[] C=[] X=0 for i in range(n): a,b=map(int,input().split()) A.append(a) B.append(b) for i in range(n-1): B[i+1]=B[i]-A[i+1]+B[i+1] C.append(B[i+1]) print(max(C))
71
92
0
208082361
maxi=0 cur=0 for _ in range(int(input())): a,b=map(int,input().split()) cur=cur-a+b if cur>maxi: maxi=cur print(maxi)
Codeforces Beta Round 87 (Div. 2 Only)
CF
2,011
2
256
Tram
Linear Kingdom has exactly one tram line. It has n stops, numbered from 1 to n in the order of tram's movement. At the i-th stop ai passengers exit the tram, while bi passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it ...
The first line contains a single number n (2 ≤ n ≤ 1000) — the number of the tram's stops. Then n lines follow, each contains two integers ai and bi (0 ≤ ai, bi ≤ 1000) — the number of passengers that exits the tram at the i-th stop, and the number of passengers that enter the tram at the i-th stop. The stops are give...
Print a single integer denoting the minimum possible capacity of the tram (0 is allowed).
null
For the first example, a capacity of 6 is sufficient: - At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. - At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 pas...
[{"input": "4\n0 3\n2 5\n4 2\n4 0", "output": "6"}]
800
["implementation"]
71
[{"input": "4\r\n0 3\r\n2 5\r\n4 2\r\n4 0\r\n", "output": "6\r\n"}, {"input": "5\r\n0 4\r\n4 6\r\n6 5\r\n5 4\r\n4 0\r\n", "output": "6\r\n"}, {"input": "10\r\n0 5\r\n1 7\r\n10 8\r\n5 3\r\n0 5\r\n3 3\r\n8 8\r\n0 6\r\n10 1\r\n9 0\r\n", "output": "18\r\n"}, {"input": "3\r\n0 1\r\n1 1\r\n1 0\r\n", "output": "1\r\n"}, {"inp...
false
stdio
null
true
116/A
116
A
Python 3
TESTS
4
30
0
210600177
itr = int(input()) max = 0 for i in range(itr): a, b = map(int, input().split()) if i == 0: enter = b exit = a else: enter -= a enter += b if max < enter: max = enter print(max)
71
92
0
208088453
n=int(input()) cap=[] for i in range(n): a,b=map(int,input().split()) curr=0 if i!=0: curr=cap[-1] cap.append(curr+b-a) print(max(cap))
Codeforces Beta Round 87 (Div. 2 Only)
CF
2,011
2
256
Tram
Linear Kingdom has exactly one tram line. It has n stops, numbered from 1 to n in the order of tram's movement. At the i-th stop ai passengers exit the tram, while bi passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it ...
The first line contains a single number n (2 ≤ n ≤ 1000) — the number of the tram's stops. Then n lines follow, each contains two integers ai and bi (0 ≤ ai, bi ≤ 1000) — the number of passengers that exits the tram at the i-th stop, and the number of passengers that enter the tram at the i-th stop. The stops are give...
Print a single integer denoting the minimum possible capacity of the tram (0 is allowed).
null
For the first example, a capacity of 6 is sufficient: - At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. - At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 pas...
[{"input": "4\n0 3\n2 5\n4 2\n4 0", "output": "6"}]
800
["implementation"]
71
[{"input": "4\r\n0 3\r\n2 5\r\n4 2\r\n4 0\r\n", "output": "6\r\n"}, {"input": "5\r\n0 4\r\n4 6\r\n6 5\r\n5 4\r\n4 0\r\n", "output": "6\r\n"}, {"input": "10\r\n0 5\r\n1 7\r\n10 8\r\n5 3\r\n0 5\r\n3 3\r\n8 8\r\n0 6\r\n10 1\r\n9 0\r\n", "output": "18\r\n"}, {"input": "3\r\n0 1\r\n1 1\r\n1 0\r\n", "output": "1\r\n"}, {"inp...
false
stdio
null
true
1010/A
1010
A
Python 3
TESTS
57
46
102,400
205468884
precision = 1000000 num_of_planets = int(input()) payload = int(input())*precision takeoffs = list(map(int, input().split())) landings = list(map(int, input().split())) planets = [] for x in range(num_of_planets): a, b = takeoffs[x], landings[x] # weight *precision / weight *precision planets.append([a, b])...
76
77
1,536,000
193831495
n = int(input()) m = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) if 1 in a or 1 in b: print(-1) else: t = m/(b[0]-1) for i in range(n-1, 0, -1): t += (t+m)/(a[i]-1) t += (t+m)/(b[i]-1) t += (t+m)/(a[0]-1) print(t)
Codeforces Round 499 (Div. 1)
CF
2,018
1
256
Fly
Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on $$$n - 2$$$ intermediate planets. Formally: we number all the planets from $$$1$$$ to $$$n$$$. $$$1$$$ is Earth, $$$n$$$ is Mars. Natasha will make exactly $$$n$$$ flights: $$$1 \to 2 \to \ldots n \to 1$$$. Flig...
The first line contains a single integer $$$n$$$ ($$$2 \le n \le 1000$$$) — number of planets. The second line contains the only integer $$$m$$$ ($$$1 \le m \le 1000$$$) — weight of the payload. The third line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 1000$$$), where $$$a_i$$$ is the num...
If Natasha can fly to Mars through $$$(n - 2)$$$ planets and return to Earth, print the minimum mass of fuel (in tons) that Natasha should take. Otherwise, print a single number $$$-1$$$. It is guaranteed, that if Natasha can make a flight, then it takes no more than $$$10^9$$$ tons of fuel. The answer will be consid...
null
Let's consider the first example. Initially, the mass of a rocket with fuel is $$$22$$$ tons. - At take-off from Earth one ton of fuel can lift off $$$11$$$ tons of cargo, so to lift off $$$22$$$ tons you need to burn $$$2$$$ tons of fuel. Remaining weight of the rocket with fuel is $$$20$$$ tons. - During landing on...
[{"input": "2\n12\n11 8\n7 5", "output": "10.0000000000"}, {"input": "3\n1\n1 4 1\n2 5 3", "output": "-1"}, {"input": "6\n2\n4 6 3 3 5 6\n2 6 3 6 5 3", "output": "85.4800000000"}]
1,500
["binary search", "math"]
76
[{"input": "2\r\n12\r\n11 8\r\n7 5\r\n", "output": "10.0000000000\r\n"}, {"input": "3\r\n1\r\n1 4 1\r\n2 5 3\r\n", "output": "-1\r\n"}, {"input": "6\r\n2\r\n4 6 3 3 5 6\r\n2 6 3 6 5 3\r\n", "output": "85.4800000000\r\n"}, {"input": "3\r\n3\r\n1 2 1\r\n2 2 2\r\n", "output": "-1\r\n"}, {"input": "4\r\n4\r\n2 3 2 2\r\n2 3...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] with open(output_path, 'r') as f: ref_line = f.readline().strip() with open(submission_path, 'r') as f: sub_line = f.readline().strip() if ref_line == "-1": if sub_...
true
1010/A
1010
A
PyPy 3
TESTS
58
233
1,433,600
90228609
import math def issuff(n,m,a,b,f): for i in range(n): if f>0: burn=(f+m)/a[i] f=round(f-burn,6) burn=(f+m)/b[(i+1)%n] f=round(f-burn,6) if f<0: return False return True def answer(n,m,a,b): l=0 r=10**9 ans=-1 ...
76
77
1,740,800
193831512
def is_enough(fuel, n, m, a, b): fuel -= (fuel + m) / a[0] for i in range(1, n): fuel -= (fuel + m) / b[i] fuel -= (fuel + m) / a[i] fuel -= (fuel + m) / b[0] return True if fuel >= 0 else False def main(): n = int(input()) m = int(input()) a = list(map(int, input().split(...
Codeforces Round 499 (Div. 1)
CF
2,018
1
256
Fly
Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on $$$n - 2$$$ intermediate planets. Formally: we number all the planets from $$$1$$$ to $$$n$$$. $$$1$$$ is Earth, $$$n$$$ is Mars. Natasha will make exactly $$$n$$$ flights: $$$1 \to 2 \to \ldots n \to 1$$$. Flig...
The first line contains a single integer $$$n$$$ ($$$2 \le n \le 1000$$$) — number of planets. The second line contains the only integer $$$m$$$ ($$$1 \le m \le 1000$$$) — weight of the payload. The third line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 1000$$$), where $$$a_i$$$ is the num...
If Natasha can fly to Mars through $$$(n - 2)$$$ planets and return to Earth, print the minimum mass of fuel (in tons) that Natasha should take. Otherwise, print a single number $$$-1$$$. It is guaranteed, that if Natasha can make a flight, then it takes no more than $$$10^9$$$ tons of fuel. The answer will be consid...
null
Let's consider the first example. Initially, the mass of a rocket with fuel is $$$22$$$ tons. - At take-off from Earth one ton of fuel can lift off $$$11$$$ tons of cargo, so to lift off $$$22$$$ tons you need to burn $$$2$$$ tons of fuel. Remaining weight of the rocket with fuel is $$$20$$$ tons. - During landing on...
[{"input": "2\n12\n11 8\n7 5", "output": "10.0000000000"}, {"input": "3\n1\n1 4 1\n2 5 3", "output": "-1"}, {"input": "6\n2\n4 6 3 3 5 6\n2 6 3 6 5 3", "output": "85.4800000000"}]
1,500
["binary search", "math"]
76
[{"input": "2\r\n12\r\n11 8\r\n7 5\r\n", "output": "10.0000000000\r\n"}, {"input": "3\r\n1\r\n1 4 1\r\n2 5 3\r\n", "output": "-1\r\n"}, {"input": "6\r\n2\r\n4 6 3 3 5 6\r\n2 6 3 6 5 3\r\n", "output": "85.4800000000\r\n"}, {"input": "3\r\n3\r\n1 2 1\r\n2 2 2\r\n", "output": "-1\r\n"}, {"input": "4\r\n4\r\n2 3 2 2\r\n2 3...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] with open(output_path, 'r') as f: ref_line = f.readline().strip() with open(submission_path, 'r') as f: sub_line = f.readline().strip() if ref_line == "-1": if sub_...
true
1010/A
1010
A
Python 3
TESTS
57
124
0
40928779
import sys; import math; def solution( n, m, a, b): a += [a[0]]; b += [b[0]]; mass = [0] * len(a); mass[len(a)-1] = m; for i in range(len(a)-1, 0, -1): tmp = mass[i]; if b[i]-1<=0: return -1; extra_fuel = tmp/(b[i]-1); tmp+=extra_fuel; if a[i-1]-...
76
77
1,843,200
171044039
import sys input = sys.stdin.readline n = int(input()) x = int(input()) w = list(map(int, input().split())) s = list(map(int, input().split())) d = [s[0]] for i in range(n-1, -1, -1): d.append(w[i]) if i == 0: break d.append(s[i]) c = 0 for i in range(2*n): if d[i] == 1: print(-1) ...
Codeforces Round 499 (Div. 1)
CF
2,018
1
256
Fly
Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on $$$n - 2$$$ intermediate planets. Formally: we number all the planets from $$$1$$$ to $$$n$$$. $$$1$$$ is Earth, $$$n$$$ is Mars. Natasha will make exactly $$$n$$$ flights: $$$1 \to 2 \to \ldots n \to 1$$$. Flig...
The first line contains a single integer $$$n$$$ ($$$2 \le n \le 1000$$$) — number of planets. The second line contains the only integer $$$m$$$ ($$$1 \le m \le 1000$$$) — weight of the payload. The third line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 1000$$$), where $$$a_i$$$ is the num...
If Natasha can fly to Mars through $$$(n - 2)$$$ planets and return to Earth, print the minimum mass of fuel (in tons) that Natasha should take. Otherwise, print a single number $$$-1$$$. It is guaranteed, that if Natasha can make a flight, then it takes no more than $$$10^9$$$ tons of fuel. The answer will be consid...
null
Let's consider the first example. Initially, the mass of a rocket with fuel is $$$22$$$ tons. - At take-off from Earth one ton of fuel can lift off $$$11$$$ tons of cargo, so to lift off $$$22$$$ tons you need to burn $$$2$$$ tons of fuel. Remaining weight of the rocket with fuel is $$$20$$$ tons. - During landing on...
[{"input": "2\n12\n11 8\n7 5", "output": "10.0000000000"}, {"input": "3\n1\n1 4 1\n2 5 3", "output": "-1"}, {"input": "6\n2\n4 6 3 3 5 6\n2 6 3 6 5 3", "output": "85.4800000000"}]
1,500
["binary search", "math"]
76
[{"input": "2\r\n12\r\n11 8\r\n7 5\r\n", "output": "10.0000000000\r\n"}, {"input": "3\r\n1\r\n1 4 1\r\n2 5 3\r\n", "output": "-1\r\n"}, {"input": "6\r\n2\r\n4 6 3 3 5 6\r\n2 6 3 6 5 3\r\n", "output": "85.4800000000\r\n"}, {"input": "3\r\n3\r\n1 2 1\r\n2 2 2\r\n", "output": "-1\r\n"}, {"input": "4\r\n4\r\n2 3 2 2\r\n2 3...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] with open(output_path, 'r') as f: ref_line = f.readline().strip() with open(submission_path, 'r') as f: sub_line = f.readline().strip() if ref_line == "-1": if sub_...
true
114/B
114
B
Python 3
TESTS
13
156
307,200
21754478
couple = input().split(" ") n = int(couple[0]) m = int(couple[1]) names = [""]*n for i in range (n) : names[i] = input() dislikes = [["",""]]*m dic = dict((names[i],0) for i in range (n)) for j in range (m) : dislikes [j] =input().split(" ") dic[dislikes[j][0]] += 1 dic[dislikes[j][1]] += 1 # pri...
61
342
2,662,400
137948756
import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writabl...
Codeforces Beta Round 86 (Div. 2 Only)
CF
2,011
2
256
PFAST Inc.
When little Petya grew up and entered the university, he started to take part in АСМ contests. Later he realized that he doesn't like how the АСМ contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members eff...
The first line contains two integer numbers n (1 ≤ n ≤ 16) — the number of volunteers, and m ($$0 \leq m \leq \frac{n(n-1)}{2}$$) — the number of pairs that do not get on. Next n lines contain the volunteers' names (each name is a non-empty string consisting of no more than 10 uppercase and/or lowercase Latin letters)....
The first output line should contain the single number k — the number of people in the sought team. Next k lines should contain the names of the sought team's participants in the lexicographical order. If there are several variants to solve the problem, print any of them. Petya might not be a member of the sought team.
null
null
[{"input": "3 1\nPetya\nVasya\nMasha\nPetya Vasya", "output": "2\nMasha\nPetya"}, {"input": "3 0\nPasha\nLesha\nVanya", "output": "3\nLesha\nPasha\nVanya"}]
1,500
["bitmasks", "brute force", "graphs"]
61
[{"input": "3 1\r\nPetya\r\nVasya\r\nMasha\r\nPetya Vasya\r\n", "output": "2\r\nMasha\r\nPetya\r\n"}, {"input": "3 0\r\nPasha\r\nLesha\r\nVanya\r\n", "output": "3\r\nLesha\r\nPasha\r\nVanya\r\n"}, {"input": "7 12\r\nPasha\r\nLesha\r\nVanya\r\nTaras\r\nNikita\r\nSergey\r\nAndrey\r\nPasha Taras\r\nPasha Nikita\r\nPasha A...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] # Read input with open(input_path, 'r') as f: input_lines = [line.strip() for line in f.readlines()] if not input_lines: print(0) return n, m = map(int, input_l...
true
116/A
116
A
Python 3
TESTS
4
62
0
209796646
m = 0 for _ in range(int(input())): if _ == 0: o,i = map(int,input().split()) else: x, y = map(int,input().split()) i-=x i+=y if i > m: m = i print(m)
71
92
0
208130778
n = int(input()) m = 0 s = 0 while n: x,y= map(int,input().split()) s=s+y-x if s >m: m = s n-=1 print(m)
Codeforces Beta Round 87 (Div. 2 Only)
CF
2,011
2
256
Tram
Linear Kingdom has exactly one tram line. It has n stops, numbered from 1 to n in the order of tram's movement. At the i-th stop ai passengers exit the tram, while bi passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it ...
The first line contains a single number n (2 ≤ n ≤ 1000) — the number of the tram's stops. Then n lines follow, each contains two integers ai and bi (0 ≤ ai, bi ≤ 1000) — the number of passengers that exits the tram at the i-th stop, and the number of passengers that enter the tram at the i-th stop. The stops are give...
Print a single integer denoting the minimum possible capacity of the tram (0 is allowed).
null
For the first example, a capacity of 6 is sufficient: - At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. - At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 pas...
[{"input": "4\n0 3\n2 5\n4 2\n4 0", "output": "6"}]
800
["implementation"]
71
[{"input": "4\r\n0 3\r\n2 5\r\n4 2\r\n4 0\r\n", "output": "6\r\n"}, {"input": "5\r\n0 4\r\n4 6\r\n6 5\r\n5 4\r\n4 0\r\n", "output": "6\r\n"}, {"input": "10\r\n0 5\r\n1 7\r\n10 8\r\n5 3\r\n0 5\r\n3 3\r\n8 8\r\n0 6\r\n10 1\r\n9 0\r\n", "output": "18\r\n"}, {"input": "3\r\n0 1\r\n1 1\r\n1 0\r\n", "output": "1\r\n"}, {"inp...
false
stdio
null
true
416/D
416
D
PyPy 3-64
TESTS
0
31
512,000
153734564
n=int(input()) a=[int(x) for x in input().split()] b=[] for i in range(n): if(a[i]!=(-1)): b.append([a[i],i]) ans=1 for i in range(len(b)-1): if((b[i+1][0]-b[i][0])%(b[i+1][1]-b[i][1])!=0): ans+=1 for i in range(len(b)-2): if((b[i+1][0]-b[i][0])%(b[i+1][1]-b[i][1])==0 and (b[i+2][0]-b[i+1][0])...
84
171
27,648,000
302828817
import sys,math,heapq from collections import Counter #sys.setrecursionlimit(200000) #fin = open('input.txt', 'r') #input = lambda: fin.readline().strip() input=lambda: sys.stdin.readline().strip() import random RANDOM = random.getrandbits(20) class Wrapper(int): def __init__(self, x): int.__init__(x) ...
Codeforces Round 241 (Div. 2)
CF
2,014
1
256
Population Size
Polycarpus develops an interesting theory about the interrelation of arithmetic progressions with just everything in the world. His current idea is that the population of the capital of Berland changes over time like an arithmetic progression. Well, or like multiple arithmetic progressions. Polycarpus believes that if...
The first line of the input contains integer n (1 ≤ n ≤ 2·105) — the number of elements in the sequence. The second line contains integer values a1, a2, ..., an separated by a space (1 ≤ ai ≤ 109 or ai = - 1).
Print the minimum number of arithmetic progressions that you need to write one after another to get sequence a. The positions marked as -1 in a can be represented by any positive integers.
null
null
[{"input": "9\n8 6 4 2 1 4 7 10 2", "output": "3"}, {"input": "9\n-1 6 -1 2 -1 4 7 -1 2", "output": "3"}, {"input": "5\n-1 -1 -1 -1 -1", "output": "1"}, {"input": "7\n-1 -1 4 5 1 2 3", "output": "2"}]
2,400
["greedy", "implementation", "math"]
84
[{"input": "9\r\n8 6 4 2 1 4 7 10 2\r\n", "output": "3\r\n"}, {"input": "9\r\n-1 6 -1 2 -1 4 7 -1 2\r\n", "output": "3\r\n"}, {"input": "5\r\n-1 -1 -1 -1 -1\r\n", "output": "1\r\n"}, {"input": "7\r\n-1 -1 4 5 1 2 3\r\n", "output": "2\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "1\r\n65\r\n", "output": ...
false
stdio
null
true
116/A
116
A
Python 3
TESTS
4
62
0
209355835
n = int(input()) l = [] m = 0 for i in range(n): a,b = map(int, input().split()) if i == 0: m = a+b continue m = m-a+b l.append(m) print(max(l))
71
92
0
208137522
busStopCount = int(input("")) maxCapacity = 0 daroBuro = 0 for i in range(0,busStopCount): ioPeople = input("").split() daroBuro = daroBuro - int(ioPeople[0]) + int(ioPeople[1]) if daroBuro>maxCapacity: maxCapacity=daroBuro print(maxCapacity)
Codeforces Beta Round 87 (Div. 2 Only)
CF
2,011
2
256
Tram
Linear Kingdom has exactly one tram line. It has n stops, numbered from 1 to n in the order of tram's movement. At the i-th stop ai passengers exit the tram, while bi passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it ...
The first line contains a single number n (2 ≤ n ≤ 1000) — the number of the tram's stops. Then n lines follow, each contains two integers ai and bi (0 ≤ ai, bi ≤ 1000) — the number of passengers that exits the tram at the i-th stop, and the number of passengers that enter the tram at the i-th stop. The stops are give...
Print a single integer denoting the minimum possible capacity of the tram (0 is allowed).
null
For the first example, a capacity of 6 is sufficient: - At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. - At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 pas...
[{"input": "4\n0 3\n2 5\n4 2\n4 0", "output": "6"}]
800
["implementation"]
71
[{"input": "4\r\n0 3\r\n2 5\r\n4 2\r\n4 0\r\n", "output": "6\r\n"}, {"input": "5\r\n0 4\r\n4 6\r\n6 5\r\n5 4\r\n4 0\r\n", "output": "6\r\n"}, {"input": "10\r\n0 5\r\n1 7\r\n10 8\r\n5 3\r\n0 5\r\n3 3\r\n8 8\r\n0 6\r\n10 1\r\n9 0\r\n", "output": "18\r\n"}, {"input": "3\r\n0 1\r\n1 1\r\n1 0\r\n", "output": "1\r\n"}, {"inp...
false
stdio
null
true
958/F2
958
F2
Python 3
TESTS
1
61
7,065,600
37323083
n, m = map(int, input().split()) c = list(map(int, input().split())) k = list(map(int, input().split())) p = [0] * m c = [o - 1 for o in c] s = sum(k) ok = k.count(0) i1 = 0 i2 = 0 while i2 < n and ok < m: p[c[i2]] += 1 if p[c[i2]] == k[c[i2]]: ok += 1 i2 += 1 if ok != m: print(-1) exit(0) a...
59
468
14,028,800
172517454
n, m = map(int, input().split()) c = list(map(int, input().split())) k = list(map(int, input().split())) p = [0] * m c = [i -1 for i in c] s = sum(k) cnt = k.count(0) l = 0 r = 0 while r < n and cnt < m: p[c[r]] += 1 if p[c[r]] == k[c[r]]: cnt += 1 r += 1 if cnt != m: print(-1) exit(0) ans =...
Helvetic Coding Contest 2018 online mirror (teams allowed, unrated)
ICPC
2,018
1
256
Lightsabers (medium)
There is unrest in the Galactic Senate. Several thousand solar systems have declared their intentions to leave the Republic. Master Heidi needs to select the Jedi Knights who will go on peacekeeping missions throughout the galaxy. It is well-known that the success of any peacekeeping mission depends on the colors of th...
The first line of the input contains n (1 ≤ n ≤ 2·105) and m (1 ≤ m ≤ n). The second line contains n integers in the range {1, 2, ..., m} representing colors of the lightsabers of the subsequent Jedi Knights. The third line contains m integers k1, k2, ..., km (with $$1 \leq \sum_{i=1}^{m} k_i \leq n$$) – the desired co...
Output one number: the minimum number of Jedi Knights that need to be removed from the sequence so that, in what remains, there is an interval with the prescribed counts of lightsaber colors. If this is not possible, output - 1.
null
null
[{"input": "8 3\n3 3 1 2 2 1 1 3\n3 1 1", "output": "1"}]
1,800
["binary search", "two pointers"]
59
[{"input": "8 3\r\n3 3 1 2 2 1 1 3\r\n3 1 1\r\n", "output": "1\r\n"}, {"input": "6 5\r\n1 2 4 2 4 3\r\n0 0 1 0 0\r\n", "output": "0\r\n"}, {"input": "1 1\r\n1\r\n1\r\n", "output": "0\r\n"}, {"input": "2 1\r\n1 1\r\n1\r\n", "output": "0\r\n"}, {"input": "2 1\r\n1 1\r\n2\r\n", "output": "0\r\n"}, {"input": "2 2\r\n1 2\r\...
false
stdio
null
true
230/A
230
A
PyPy 3-64
TESTS
9
186
2,048,000
231922116
s,n = map(int,input().split()) d = {} for i in range(n): l = (list(map(int,input().split()))) d[l[0]] = l[1] l = sorted(d) dragons = [[i,d[i]] for i in l] survive = True for x in dragons: if x[0] >= s : survive = False break else: s += x[1] print('YES' if survive == True else '...
54
92
0
229578644
s, n = map(int, input().split()) data = [] for i in range(n): dragonStrength, gain = map(int, input().split()) data.append((dragonStrength, gain)) data = sorted(data) Won = True for i in data: if s > i[0]: s += i[1] else: print("NO") Won = False break if Won: print("Y...
Codeforces Round 142 (Div. 2)
CF
2,012
2
256
Dragons
Kirito is stuck on a level of the MMORPG he is playing now. To move on in the game, he's got to defeat all n dragons that live on this level. Kirito and the dragons have strength, which is represented by an integer. In the duel between two opponents the duel's outcome is determined by their strength. Initially, Kirito'...
The first line contains two space-separated integers s and n (1 ≤ s ≤ 104, 1 ≤ n ≤ 103). Then n lines follow: the i-th line contains space-separated integers xi and yi (1 ≤ xi ≤ 104, 0 ≤ yi ≤ 104) — the i-th dragon's strength and the bonus for defeating it.
On a single line print "YES" (without the quotes), if Kirito can move on to the next level and print "NO" (without the quotes), if he can't.
null
In the first sample Kirito's strength initially equals 2. As the first dragon's strength is less than 2, Kirito can fight it and defeat it. After that he gets the bonus and his strength increases to 2 + 99 = 101. Now he can defeat the second dragon and move on to the next level. In the second sample Kirito's strength ...
[{"input": "2 2\n1 99\n100 0", "output": "YES"}, {"input": "10 1\n100 100", "output": "NO"}]
1,000
["greedy", "sortings"]
54
[{"input": "2 2\r\n1 99\r\n100 0\r\n", "output": "YES\r\n"}, {"input": "10 1\r\n100 100\r\n", "output": "NO\r\n"}, {"input": "123 2\r\n78 10\r\n130 0\r\n", "output": "YES\r\n"}, {"input": "999 2\r\n1010 10\r\n67 89\r\n", "output": "YES\r\n"}, {"input": "2 5\r\n5 1\r\n2 1\r\n3 1\r\n1 1\r\n4 1\r\n", "output": "YES\r\n"},...
false
stdio
null
true
992/A
992
A
Python 3
TESTS
12
78
7,372,800
147814524
size_of_array =int(input()) elements_of_array =list(map(int,input().split())) my_set=set(elements_of_array) my_list=list(my_set) out=0 for i in range(0,len(my_list)): if elements_of_array[i]!=0: out+=1 print(out)
79
77
6,656,000
192806053
# LUOGU_RID: 101744612 n, *a = map(int, open(0).read().split()) if a.count(0) == n: exit(print(0)) b = [x for x in a if x] print(len(set(b)))
Codeforces Round 489 (Div. 2)
CF
2,018
1
256
Nastya and an Array
Nastya owns too many arrays now, so she wants to delete the least important of them. However, she discovered that this array is magic! Nastya now knows that the array has the following properties: - In one second we can add an arbitrary (possibly negative) integer to all elements of the array that are not equal to zer...
The first line contains a single integer n (1 ≤ n ≤ 105) — the size of the array. The second line contains n integers a1, a2, ..., an ( - 105 ≤ ai ≤ 105) — the elements of the array.
Print a single integer — the minimum number of seconds needed to make all elements of the array equal to zero.
null
In the first example you can add - 1 to all non-zero elements in one second and make them equal to zero. In the second example you can add - 2 on the first second, then the array becomes equal to [0, 0, - 3]. On the second second you can add 3 to the third (the only non-zero) element.
[{"input": "5\n1 1 1 1 1", "output": "1"}, {"input": "3\n2 0 -1", "output": "2"}, {"input": "4\n5 -6 -5 1", "output": "4"}]
800
["implementation", "sortings"]
79
[{"input": "5\r\n1 1 1 1 1\r\n", "output": "1\r\n"}, {"input": "3\r\n2 0 -1\r\n", "output": "2\r\n"}, {"input": "4\r\n5 -6 -5 1\r\n", "output": "4\r\n"}, {"input": "1\r\n0\r\n", "output": "0\r\n"}, {"input": "2\r\n21794 -79194\r\n", "output": "2\r\n"}, {"input": "3\r\n-63526 95085 -5239\r\n", "output": "3\r\n"}, {"inpu...
false
stdio
null
true
464/A
464
A
PyPy 3-64
TESTS
19
46
0
218189056
n, p = map(int, input().split()) s = ['#', '#'] + [c for c in input()] flag = False for i in range(n + 1, 1, -1): for t in range(p): c = chr(ord('a') + t) if c > s[i]: d = s[i] s[i] = c if s[i] != s[i - 1] and s[i - 2:i + 1] != s[i - 2:i + 1][::-1]: ...
73
77
0
120132697
n,p=map(int,input().split()) s=list(map(ord,input())) index=n-1 s[n-1]+=1 p+=97 while(index>=0 and index<n): if(s[index]>=p): s[index]=97 index-=1 s[index]+=1 elif (index!=0 and s[index]==s[index-1]): s[index]+=1 elif(index>1 and s[index]==s[index-2]): s[index]+=1 ...
Codeforces Round 265 (Div. 1)
CF
2,014
1
256
No to Palindromes!
Paul hates palindromes. He assumes that string s is tolerable if each its character is one of the first p letters of the English alphabet and s doesn't contain any palindrome contiguous substring of length 2 or more. Paul has found a tolerable string s of length n. Help him find the lexicographically next tolerable st...
The first line contains two space-separated integers: n and p (1 ≤ n ≤ 1000; 1 ≤ p ≤ 26). The second line contains string s, consisting of n small English letters. It is guaranteed that the string is tolerable (according to the above definition).
If the lexicographically next tolerable string of the same length exists, print it. Otherwise, print "NO" (without the quotes).
null
String s is lexicographically larger (or simply larger) than string t with the same length, if there is number i, such that s1 = t1, ..., si = ti, si + 1 > ti + 1. The lexicographically next tolerable string is the lexicographically minimum tolerable string which is larger than the given one. A palindrome is a string...
[{"input": "3 3\ncba", "output": "NO"}, {"input": "3 4\ncba", "output": "cbd"}, {"input": "4 4\nabcd", "output": "abda"}]
1,700
["greedy", "strings"]
73
[{"input": "3 3\r\ncba\r\n", "output": "NO\r\n"}, {"input": "3 4\r\ncba\r\n", "output": "cbd\r\n"}, {"input": "4 4\r\nabcd\r\n", "output": "abda\r\n"}, {"input": "2 2\r\nab\r\n", "output": "ba\r\n"}, {"input": "2 2\r\nba\r\n", "output": "NO\r\n"}, {"input": "1 2\r\na\r\n", "output": "b\r\n"}, {"input": "1 2\r\nb\r\n", ...
false
stdio
null
true
63/B
63
B
Python 3
TESTS
5
186
0
47370634
n,k=map(int,input().split()) l=[int(i) for i in input().split()] if n==1: print(k-n) exit() l.sort() cnt=0 while min(l)<k: cnt+=1 for i in range(0,n-1): if l[i]!=l[i+1]: l[i]+=1 l[n-1]+=1 #print(min(l)) print(cnt)
37
92
0
137088770
n, k = map(int, input().split()) if n==1: soldiers = [int(input())] else: soldiers = list(map(int, input().split())) ranks = [0]*(k+1) for s in soldiers: ranks[s] += 1 coins = 0 while ranks[k]<n: i = k-1 while i>0: if ranks[i]: ranks[i] -= 1 ranks[i+1] += 1 i...
Codeforces Beta Round 59 (Div. 2)
CF
2,011
2
256
Settlers' Training
In a strategic computer game "Settlers II" one has to build defense structures to expand and protect the territory. Let's take one of these buildings. At the moment the defense structure accommodates exactly n soldiers. Within this task we can assume that the number of soldiers in the defense structure won't either inc...
The first line contains two integers n and k (1 ≤ n, k ≤ 100). They represent the number of soldiers and the number of different ranks correspondingly. The second line contains n numbers in the non-decreasing order. The i-th of them, ai, represents the rank of the i-th soldier in the defense building (1 ≤ i ≤ n, 1 ≤ ai...
Print a single integer — the number of golden coins needed to raise all the soldiers to the maximal rank.
null
In the first example the ranks will be raised in the following manner: 1 2 2 3 → 2 2 3 4 → 2 3 4 4 → 3 4 4 4 → 4 4 4 4 Thus totals to 4 training sessions that require 4 golden coins.
[{"input": "4 4\n1 2 2 3", "output": "4"}, {"input": "4 3\n1 1 1 1", "output": "5"}]
1,200
["implementation"]
37
[{"input": "4 4\r\n1 2 2 3\r\n", "output": "4"}, {"input": "4 3\r\n1 1 1 1\r\n", "output": "5"}, {"input": "3 3\r\n1 2 3\r\n", "output": "2"}, {"input": "1 1\r\n1\r\n", "output": "0"}, {"input": "1 5\r\n1\r\n", "output": "4"}, {"input": "1 5\r\n4\r\n", "output": "1"}, {"input": "2 6\r\n2 5\r\n", "output": "4"}, {"input...
false
stdio
null
true
883/E
883
E
Python 3
TESTS
18
93
307,200
93619817
n = int(input()) input_str = input() revealed = set() ans = set() revealed_indexes = [] unrevealed_indexes = [] for i, ch in enumerate(input_str): if ch == '*': unrevealed_indexes.append(i) else: revealed.add(ch) revealed_indexes.append(i) m = int(input()) for i in range(m): s = input() for ind in revealed_in...
95
46
0
154876165
input() w = input() ans = set("abcdefghijklmnopqrstuvwxyz") for _ in range(int(input())): q = input() if any(a!='*' and a!=b or a=='*' and b in w for a, b in zip(w, q)): continue ans &= set(q)-set(w) print(len(ans))
2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)
ICPC
2,017
3
256
Field of Wonders
Polycarpus takes part in the "Field of Wonders" TV show. The participants of the show have to guess a hidden word as fast as possible. Initially all the letters of the word are hidden. The game consists of several turns. At each turn the participant tells a letter and the TV show host responds if there is such letter ...
The first line contains one integer n (1 ≤ n ≤ 50) — the length of the hidden word. The following line describes already revealed letters. It contains the string of length n, which consists of lowercase Latin letters and symbols "*". If there is a letter at some position, then this letter was already revealed. If the ...
Output the single integer — the number of letters Polycarpus can tell so that the TV show host definitely reveals at least one more letter. It is possible that this number is zero.
null
In the first example Polycarpus can tell letters "b" and "c", which assuredly will be revealed. The second example contains no letters which can be told as it is not clear, which of the letters "v" or "s" is located at the third position of the hidden word. In the third example Polycarpus exactly knows that the hidde...
[{"input": "4\na**d\n2\nabcd\nacbd", "output": "2"}, {"input": "5\nlo*er\n2\nlover\nloser", "output": "0"}, {"input": "3\na*a\n2\naaa\naba", "output": "1"}]
1,500
["implementation", "strings"]
95
[{"input": "4\r\na**d\r\n2\r\nabcd\r\nacbd\r\n", "output": "2\r\n"}, {"input": "5\r\nlo*er\r\n2\r\nlover\r\nloser\r\n", "output": "0\r\n"}, {"input": "3\r\na*a\r\n2\r\naaa\r\naba\r\n", "output": "1\r\n"}, {"input": "1\r\n*\r\n1\r\na\r\n", "output": "1\r\n"}, {"input": "1\r\n*\r\n1\r\nz\r\n", "output": "1\r\n"}, {"input...
false
stdio
null
true
230/A
230
A
PyPy 3-64
TESTS
9
154
1,945,600
229189004
s, n = input().split() s , n = int(s) , int(n) d={} l=[] c = 0 for i in range(n): x,y = input().split() x,y = int(x), int(y) if x in d: d[x] = +y else: d[x] = y l.append(x) l.sort() # print(l) for i in range(len(l)): if s>l[i] : s+=d[l[i]] c = 1 else: ...
54
92
0
229599501
k, n = tuple(map(int, input().split(' '))) a = [tuple(map(int, input().split(' '))) for _ in range(n)] a.sort(key=lambda x: x[0]) for e in a: if e[0] >= k: print('NO') break k += e[1] else: print('YES')
Codeforces Round 142 (Div. 2)
CF
2,012
2
256
Dragons
Kirito is stuck on a level of the MMORPG he is playing now. To move on in the game, he's got to defeat all n dragons that live on this level. Kirito and the dragons have strength, which is represented by an integer. In the duel between two opponents the duel's outcome is determined by their strength. Initially, Kirito'...
The first line contains two space-separated integers s and n (1 ≤ s ≤ 104, 1 ≤ n ≤ 103). Then n lines follow: the i-th line contains space-separated integers xi and yi (1 ≤ xi ≤ 104, 0 ≤ yi ≤ 104) — the i-th dragon's strength and the bonus for defeating it.
On a single line print "YES" (without the quotes), if Kirito can move on to the next level and print "NO" (without the quotes), if he can't.
null
In the first sample Kirito's strength initially equals 2. As the first dragon's strength is less than 2, Kirito can fight it and defeat it. After that he gets the bonus and his strength increases to 2 + 99 = 101. Now he can defeat the second dragon and move on to the next level. In the second sample Kirito's strength ...
[{"input": "2 2\n1 99\n100 0", "output": "YES"}, {"input": "10 1\n100 100", "output": "NO"}]
1,000
["greedy", "sortings"]
54
[{"input": "2 2\r\n1 99\r\n100 0\r\n", "output": "YES\r\n"}, {"input": "10 1\r\n100 100\r\n", "output": "NO\r\n"}, {"input": "123 2\r\n78 10\r\n130 0\r\n", "output": "YES\r\n"}, {"input": "999 2\r\n1010 10\r\n67 89\r\n", "output": "YES\r\n"}, {"input": "2 5\r\n5 1\r\n2 1\r\n3 1\r\n1 1\r\n4 1\r\n", "output": "YES\r\n"},...
false
stdio
null
true
114/B
114
B
PyPy 3-64
TESTS
13
124
614,400
213188640
from collections import defaultdict n, m = map(int,input().split()) participents = [] eligible = defaultdict(bool) degincomp = defaultdict(int) incomp = defaultdict(list) for i in range(n) : participents.append(input()) degincomp[participents[-1]] = 0 eligible[participents[-1]] = True if m == 0 : print(...
61
342
4,300,800
182407548
n, k = map(int, input().split()) b1 = [] min = [] for i in range(n): b1 += [input()] d = {} for i in range(k): o = 0 a, b = input().split() if a not in d: d[a] = [b] o = 1 if b not in d: d[b] = [a] o = 2 if o != 1: c = d[a] if b not in c: ...
Codeforces Beta Round 86 (Div. 2 Only)
CF
2,011
2
256
PFAST Inc.
When little Petya grew up and entered the university, he started to take part in АСМ contests. Later he realized that he doesn't like how the АСМ contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members eff...
The first line contains two integer numbers n (1 ≤ n ≤ 16) — the number of volunteers, and m ($$0 \leq m \leq \frac{n(n-1)}{2}$$) — the number of pairs that do not get on. Next n lines contain the volunteers' names (each name is a non-empty string consisting of no more than 10 uppercase and/or lowercase Latin letters)....
The first output line should contain the single number k — the number of people in the sought team. Next k lines should contain the names of the sought team's participants in the lexicographical order. If there are several variants to solve the problem, print any of them. Petya might not be a member of the sought team.
null
null
[{"input": "3 1\nPetya\nVasya\nMasha\nPetya Vasya", "output": "2\nMasha\nPetya"}, {"input": "3 0\nPasha\nLesha\nVanya", "output": "3\nLesha\nPasha\nVanya"}]
1,500
["bitmasks", "brute force", "graphs"]
61
[{"input": "3 1\r\nPetya\r\nVasya\r\nMasha\r\nPetya Vasya\r\n", "output": "2\r\nMasha\r\nPetya\r\n"}, {"input": "3 0\r\nPasha\r\nLesha\r\nVanya\r\n", "output": "3\r\nLesha\r\nPasha\r\nVanya\r\n"}, {"input": "7 12\r\nPasha\r\nLesha\r\nVanya\r\nTaras\r\nNikita\r\nSergey\r\nAndrey\r\nPasha Taras\r\nPasha Nikita\r\nPasha A...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] # Read input with open(input_path, 'r') as f: input_lines = [line.strip() for line in f.readlines()] if not input_lines: print(0) return n, m = map(int, input_l...
true
114/B
114
B
Python 3
TESTS
13
248
307,200
49891866
n,m = map(int,input().split()) l = [input() for i in range(n)] hash = {} lis = [] hash_ri = {} for i in range(m): a,b = map(str,input().split()) try: hash[a] except: hash[a] = 1 else: hash[a]+=1 # list.append([hash[a],a]) try: hash[b] except: hash[b] = 1 ...
61
342
6,553,600
135833245
def solve(n, prefix): if n == 0: ans = [] for i in range(len(prefix)): if prefix[i] == 1: ans.append(names[i]) for x, y in pairs: if x in ans and y in ans: return [] return ans else: prefix.append(1) ans1 = s...
Codeforces Beta Round 86 (Div. 2 Only)
CF
2,011
2
256
PFAST Inc.
When little Petya grew up and entered the university, he started to take part in АСМ contests. Later he realized that he doesn't like how the АСМ contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members eff...
The first line contains two integer numbers n (1 ≤ n ≤ 16) — the number of volunteers, and m ($$0 \leq m \leq \frac{n(n-1)}{2}$$) — the number of pairs that do not get on. Next n lines contain the volunteers' names (each name is a non-empty string consisting of no more than 10 uppercase and/or lowercase Latin letters)....
The first output line should contain the single number k — the number of people in the sought team. Next k lines should contain the names of the sought team's participants in the lexicographical order. If there are several variants to solve the problem, print any of them. Petya might not be a member of the sought team.
null
null
[{"input": "3 1\nPetya\nVasya\nMasha\nPetya Vasya", "output": "2\nMasha\nPetya"}, {"input": "3 0\nPasha\nLesha\nVanya", "output": "3\nLesha\nPasha\nVanya"}]
1,500
["bitmasks", "brute force", "graphs"]
61
[{"input": "3 1\r\nPetya\r\nVasya\r\nMasha\r\nPetya Vasya\r\n", "output": "2\r\nMasha\r\nPetya\r\n"}, {"input": "3 0\r\nPasha\r\nLesha\r\nVanya\r\n", "output": "3\r\nLesha\r\nPasha\r\nVanya\r\n"}, {"input": "7 12\r\nPasha\r\nLesha\r\nVanya\r\nTaras\r\nNikita\r\nSergey\r\nAndrey\r\nPasha Taras\r\nPasha Nikita\r\nPasha A...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] # Read input with open(input_path, 'r') as f: input_lines = [line.strip() for line in f.readlines()] if not input_lines: print(0) return n, m = map(int, input_l...
true
114/B
114
B
PyPy 3
TESTS
13
218
102,400
205683612
from collections import defaultdict import sys input = sys.stdin.readline n, m = list(map(int, input().split())) people = set() for _ in range(n): people.add(input().strip()) adj = defaultdict(list) indegree = defaultdict(int) for _ in range(m): first, second = input().split() adj[first].append(second) ...
61
374
7,475,200
22931158
from itertools import product n,m = map(int, input().split()) vl = sorted([ input() for i in range(n)]) cm = {vl[i]:i for i in range(n)} cl = [] for i in range(m): a,b = input().split() cl+=[[cm[a],cm[b]]] ans=[(),0] for x in list(product([1,0],repeat=n)): flag=0 for c in cl: if x[c[0]]==1==x[c[...
Codeforces Beta Round 86 (Div. 2 Only)
CF
2,011
2
256
PFAST Inc.
When little Petya grew up and entered the university, he started to take part in АСМ contests. Later he realized that he doesn't like how the АСМ contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members eff...
The first line contains two integer numbers n (1 ≤ n ≤ 16) — the number of volunteers, and m ($$0 \leq m \leq \frac{n(n-1)}{2}$$) — the number of pairs that do not get on. Next n lines contain the volunteers' names (each name is a non-empty string consisting of no more than 10 uppercase and/or lowercase Latin letters)....
The first output line should contain the single number k — the number of people in the sought team. Next k lines should contain the names of the sought team's participants in the lexicographical order. If there are several variants to solve the problem, print any of them. Petya might not be a member of the sought team.
null
null
[{"input": "3 1\nPetya\nVasya\nMasha\nPetya Vasya", "output": "2\nMasha\nPetya"}, {"input": "3 0\nPasha\nLesha\nVanya", "output": "3\nLesha\nPasha\nVanya"}]
1,500
["bitmasks", "brute force", "graphs"]
61
[{"input": "3 1\r\nPetya\r\nVasya\r\nMasha\r\nPetya Vasya\r\n", "output": "2\r\nMasha\r\nPetya\r\n"}, {"input": "3 0\r\nPasha\r\nLesha\r\nVanya\r\n", "output": "3\r\nLesha\r\nPasha\r\nVanya\r\n"}, {"input": "7 12\r\nPasha\r\nLesha\r\nVanya\r\nTaras\r\nNikita\r\nSergey\r\nAndrey\r\nPasha Taras\r\nPasha Nikita\r\nPasha A...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] # Read input with open(input_path, 'r') as f: input_lines = [line.strip() for line in f.readlines()] if not input_lines: print(0) return n, m = map(int, input_l...
true
524/C
524
C
Python 3
TESTS
2
61
0
10489874
n,k=map(int,input().split()) a=list(map(int,input().split())) q=int(input()) x=[] answ=[] for i in range(q): x.append(int(input())) b=sorted(a, reverse=True) a=b for xi in x: answi=-1 for i in range(n): if xi/a[i]>k: break elif xi%a[i]==0: answi=xi/a[i] else: ...
129
904
7,475,200
29733995
n,k = [int(s) for s in input().split()] bills = [int(s) for s in input().split()] pairs = {} for bill in bills: for i in range(k): possible = (i+1)*bill if possible not in pairs or i+1 < pairs[possible]: pairs[possible] = i+1 q = int(input()) mymax = 100000000000000000 for i in range(q...
VK Cup 2015 - Round 1
CF
2,015
2
256
The Art of Dealing with ATM
ATMs of a well-known bank of a small country are arranged so that they can not give any amount of money requested by the user. Due to the limited size of the bill dispenser (the device that is directly giving money from an ATM) and some peculiarities of the ATM structure, you can get at most k bills from it, and the bi...
The first line contains two integers n, k (1 ≤ n ≤ 5000, 1 ≤ k ≤ 20). The next line contains n space-separated integers ai (1 ≤ ai ≤ 107) — the denominations of the bills that are used in the country. Numbers ai follow in the strictly increasing order. The next line contains integer q (1 ≤ q ≤ 20) — the number of req...
For each request for cash withdrawal print on a single line the minimum number of bills it can be done, or print - 1, if it is impossible to get the corresponding sum.
null
null
[{"input": "6 20\n10 50 100 500 1000 5000\n8\n4200\n100000\n95000\n96000\n99000\n10100\n2015\n9950", "output": "6\n20\n19\n20\n-1\n3\n-1\n-1"}, {"input": "5 2\n1 2 3 5 8\n8\n1\n3\n5\n7\n9\n11\n13\n15", "output": "1\n1\n1\n2\n2\n2\n2\n-1"}]
1,900
["binary search", "sortings"]
129
[{"input": "6 20\r\n10 50 100 500 1000 5000\r\n8\r\n4200\r\n100000\r\n95000\r\n96000\r\n99000\r\n10100\r\n2015\r\n9950\r\n", "output": "6\r\n20\r\n19\r\n20\r\n-1\r\n3\r\n-1\r\n-1\r\n"}, {"input": "5 2\r\n1 2 3 5 8\r\n8\r\n1\r\n3\r\n5\r\n7\r\n9\r\n11\r\n13\r\n15\r\n", "output": "1\r\n1\r\n1\r\n2\r\n2\r\n2\r\n2\r\n-1\r\n...
false
stdio
null
true
464/A
464
A
Python 3
TESTS
18
77
512,000
7899831
__author__ = 'Gleb' from time import time from collections import defaultdict from bisect import bisect_left, bisect_right M = lambda: map(int, input().split()) L = lambda: list(map(int, input().split())) I = lambda: int(input()) S = lambda: input().split() """ int(input()) map(int, input().split()) list(map(int, in...
73
77
307,200
7707195
import sys def main(): # fin = open("input.txt", "r") fin = sys.stdin fout = sys.stdout L = list("abcdefghijklmnopqrstuvwxyz") n, p = map(int, fin.readline().split()) A = list(fin.readline()) for i in range(n - 1, 1, -1): pr = ord(A[i - 1]) - ord("a") pp = ord(A[i - 2]) -...
Codeforces Round 265 (Div. 1)
CF
2,014
1
256
No to Palindromes!
Paul hates palindromes. He assumes that string s is tolerable if each its character is one of the first p letters of the English alphabet and s doesn't contain any palindrome contiguous substring of length 2 or more. Paul has found a tolerable string s of length n. Help him find the lexicographically next tolerable st...
The first line contains two space-separated integers: n and p (1 ≤ n ≤ 1000; 1 ≤ p ≤ 26). The second line contains string s, consisting of n small English letters. It is guaranteed that the string is tolerable (according to the above definition).
If the lexicographically next tolerable string of the same length exists, print it. Otherwise, print "NO" (without the quotes).
null
String s is lexicographically larger (or simply larger) than string t with the same length, if there is number i, such that s1 = t1, ..., si = ti, si + 1 > ti + 1. The lexicographically next tolerable string is the lexicographically minimum tolerable string which is larger than the given one. A palindrome is a string...
[{"input": "3 3\ncba", "output": "NO"}, {"input": "3 4\ncba", "output": "cbd"}, {"input": "4 4\nabcd", "output": "abda"}]
1,700
["greedy", "strings"]
73
[{"input": "3 3\r\ncba\r\n", "output": "NO\r\n"}, {"input": "3 4\r\ncba\r\n", "output": "cbd\r\n"}, {"input": "4 4\r\nabcd\r\n", "output": "abda\r\n"}, {"input": "2 2\r\nab\r\n", "output": "ba\r\n"}, {"input": "2 2\r\nba\r\n", "output": "NO\r\n"}, {"input": "1 2\r\na\r\n", "output": "b\r\n"}, {"input": "1 2\r\nb\r\n", ...
false
stdio
null
true
886/D
886
D
Python 3
TESTS
4
62
0
32577035
n=int(input()) m=[] sc=[] for i in range(n): m.append(input()) sc.append(set(m[i])) i=0 pX=False while i<len(m): j=i+1 p=False while j<len(m): z=len(sc[i].intersection(sc[j])) #a=len(sc[i]) #b=len(sc[j]) if m[i] in m[j]: sc.pop(i) m.pop(i) ...
47
46
0
230750513
u, v, d = {}, {}, set() for i in range(int(input())): t = input() if len(t) == 1: d.add(t) for a, b in zip(t, t[1:]): if u.get(a, b) != b or v.get(b, a) != a: exit(print('NO')) u[a], v[b] = b, a x, y = set(u), set(v) d = d - x - y for q in x - y: while q[-1] in u: q += u.pop(q[-1]) d...
Технокубок 2018 - Отборочный Раунд 3
CF
2,017
2
256
Restoration of string
A substring of some string is called the most frequent, if the number of its occurrences is not less than number of occurrences of any other substring. You are given a set of strings. A string (not necessarily from this set) is called good if all elements of the set are the most frequent substrings of this string. Res...
The first line contains integer n (1 ≤ n ≤ 105) — the number of strings in the set. Each of the next n lines contains a non-empty string consisting of lowercase English letters. It is guaranteed that the strings are distinct. The total length of the strings doesn't exceed 105.
Print the non-empty good string with minimum length. If several good strings exist, print lexicographically minimum among them. Print "NO" (without quotes) if there are no good strings.
null
One can show that in the first sample only two good strings with minimum length exist: "cfmailru" and "mailrucf". The first string is lexicographically minimum.
[{"input": "4\nmail\nai\nlru\ncf", "output": "cfmailru"}, {"input": "3\nkek\npreceq\ncheburek", "output": "NO"}]
2,000
["constructive algorithms", "graphs", "implementation"]
47
[{"input": "4\r\nmail\r\nai\r\nlru\r\ncf\r\n", "output": "cfmailru\r\n"}, {"input": "3\r\nkek\r\npreceq\r\ncheburek\r\n", "output": "NO\r\n"}, {"input": "1\r\nz\r\n", "output": "z\r\n"}, {"input": "2\r\nab\r\nba\r\n", "output": "NO\r\n"}, {"input": "2\r\nac\r\nbc\r\n", "output": "NO\r\n"}, {"input": "2\r\ncd\r\nce\r\n"...
false
stdio
null
true
883/E
883
E
Python 3
TESTS1
37
139
5,529,600
31566887
n = int(input()) s = input() oc = s.count('*') m = int(input()) k = m a = [0 for i in range(27)] t = [] for i in range(m): p = input() for j in range(n): p = p.replace(s[j], "") if oc != len(p): k-=1 continue r = p for j in range(len(p)): a[ord(p[j]) - ord('a')] += 1 ...
95
62
0
32234741
def is_good_guess(guess, original_string, pos_not_reveal, pos_reveal, reveal): for i in pos_not_reveal: if guess[i] in reveal: return False for i in pos_reveal: if guess[i] != original_string[i]: return False return True n = int(input()) l2 = list(input()) reveal = [...
2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)
ICPC
2,017
3
256
Field of Wonders
Polycarpus takes part in the "Field of Wonders" TV show. The participants of the show have to guess a hidden word as fast as possible. Initially all the letters of the word are hidden. The game consists of several turns. At each turn the participant tells a letter and the TV show host responds if there is such letter ...
The first line contains one integer n (1 ≤ n ≤ 50) — the length of the hidden word. The following line describes already revealed letters. It contains the string of length n, which consists of lowercase Latin letters and symbols "*". If there is a letter at some position, then this letter was already revealed. If the ...
Output the single integer — the number of letters Polycarpus can tell so that the TV show host definitely reveals at least one more letter. It is possible that this number is zero.
null
In the first example Polycarpus can tell letters "b" and "c", which assuredly will be revealed. The second example contains no letters which can be told as it is not clear, which of the letters "v" or "s" is located at the third position of the hidden word. In the third example Polycarpus exactly knows that the hidde...
[{"input": "4\na**d\n2\nabcd\nacbd", "output": "2"}, {"input": "5\nlo*er\n2\nlover\nloser", "output": "0"}, {"input": "3\na*a\n2\naaa\naba", "output": "1"}]
1,500
["implementation", "strings"]
95
[{"input": "4\r\na**d\r\n2\r\nabcd\r\nacbd\r\n", "output": "2\r\n"}, {"input": "5\r\nlo*er\r\n2\r\nlover\r\nloser\r\n", "output": "0\r\n"}, {"input": "3\r\na*a\r\n2\r\naaa\r\naba\r\n", "output": "1\r\n"}, {"input": "1\r\n*\r\n1\r\na\r\n", "output": "1\r\n"}, {"input": "1\r\n*\r\n1\r\nz\r\n", "output": "1\r\n"}, {"input...
false
stdio
null
true
743/A
743
A
PyPy 3-64
TESTS
34
62
0
179188778
import sys n,a,b = input().split() s = input() a = int(a) b = int(b) if a>b: a,b = b,a if s[a-1] == s[b-1]: print(0) sys.exit(0) idx = -1 for i in range(a-1,b): if s[a-1] == s[i]: idx = i break ans1 = abs(b-idx) for i in range(b-1,a,-1): if s[b-1] == s[i]: idx = i ...
56
46
0
155397408
n, a, b = map(int, input().split()) s = ' ' + input() print(1 if s[a] != s[b] else 0)
Codeforces Round 384 (Div. 2)
CF
2,016
2
256
Vladik and flights
Vladik is a competitive programmer. This year he is going to win the International Olympiad in Informatics. But it is not as easy as it sounds: the question Vladik face now is to find the cheapest way to get to the olympiad. Vladik knows n airports. All the airports are located on a straight line. Each airport has uni...
The first line contains three integers n, a, and b (1 ≤ n ≤ 105, 1 ≤ a, b ≤ n) — the number of airports, the id of the airport from which Vladik starts his route and the id of the airport which he has to reach. The second line contains a string with length n, which consists only of characters 0 and 1. If the i-th char...
Print single integer — the minimum cost Vladik has to pay to get to the olympiad.
null
In the first example Vladik can fly to the airport 2 at first and pay |1 - 2| = 1 (because the airports belong to different companies), and then fly from the airport 2 to the airport 4 for free (because the airports belong to the same company). So the cost of the whole flight is equal to 1. It's impossible to get to th...
[{"input": "4 1 4\n1010", "output": "1"}, {"input": "5 5 2\n10110", "output": "0"}]
1,200
["constructive algorithms", "greedy", "implementation"]
56
[{"input": "4 1 4\r\n1010\r\n", "output": "1"}, {"input": "5 5 2\r\n10110\r\n", "output": "0"}, {"input": "10 9 5\r\n1011111001\r\n", "output": "1"}, {"input": "7 3 7\r\n1110111\r\n", "output": "0"}, {"input": "1 1 1\r\n1\r\n", "output": "0"}, {"input": "10 3 3\r\n1001011011\r\n", "output": "0"}, {"input": "1 1 1\r\n0\...
false
stdio
null
true
116/A
116
A
Python 3
TESTS
4
62
0
214170736
t=int(input()) if(t==1000): print(0) else: a,b=map(int,input().split()) m=b l=[] for i in range(t-1): x,y=map(int,input().split()) m=m-x+y l.append(m) print(max(l))
71
92
0
208155034
n=int(input()) l=[] cnt=0 for i in range (0,n): a,b=map(int,input().split()) cnt-=a cnt+=b l.append(cnt) print(max(l))
Codeforces Beta Round 87 (Div. 2 Only)
CF
2,011
2
256
Tram
Linear Kingdom has exactly one tram line. It has n stops, numbered from 1 to n in the order of tram's movement. At the i-th stop ai passengers exit the tram, while bi passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it ...
The first line contains a single number n (2 ≤ n ≤ 1000) — the number of the tram's stops. Then n lines follow, each contains two integers ai and bi (0 ≤ ai, bi ≤ 1000) — the number of passengers that exits the tram at the i-th stop, and the number of passengers that enter the tram at the i-th stop. The stops are give...
Print a single integer denoting the minimum possible capacity of the tram (0 is allowed).
null
For the first example, a capacity of 6 is sufficient: - At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. - At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 pas...
[{"input": "4\n0 3\n2 5\n4 2\n4 0", "output": "6"}]
800
["implementation"]
71
[{"input": "4\r\n0 3\r\n2 5\r\n4 2\r\n4 0\r\n", "output": "6\r\n"}, {"input": "5\r\n0 4\r\n4 6\r\n6 5\r\n5 4\r\n4 0\r\n", "output": "6\r\n"}, {"input": "10\r\n0 5\r\n1 7\r\n10 8\r\n5 3\r\n0 5\r\n3 3\r\n8 8\r\n0 6\r\n10 1\r\n9 0\r\n", "output": "18\r\n"}, {"input": "3\r\n0 1\r\n1 1\r\n1 0\r\n", "output": "1\r\n"}, {"inp...
false
stdio
null
true
54/A
54
A
PyPy 3
TESTS
9
278
0
60446520
N, K = map(int, input().split()) if (N, K) == (5, 5): N = -1 C = map(int, input().split()[1:]) result = set() result.update(C) result.update(range(K, N+1, K)) print(len(result))
65
124
0
14100465
n, k = map(int, input().split()) holidays = list(map(int, input().split()))[1:] count = 0 previous = 0 for holiday in holidays: count += (holiday - previous - 1) // k count += 1 previous = holiday if len(holidays) == 0 or holidays[-1] < n: count += (n - previous) // k print(count)
Codeforces Beta Round 50
CF
2,011
2
256
Presents
The Hedgehog likes to give presents to his friend, but no less he likes to receive them. Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboard. He will have to choose another shelf, but which one should he c...
The first line contains integers N and K (1 ≤ N ≤ 365, 1 ≤ K ≤ N). The second line contains a number C which represents the number of holidays (0 ≤ C ≤ N). Then in the same line follow C numbers ranging from 1 to N which are the numbers of holiday days. The numbers are given in the increasing order, without repeating ...
Print a single number — the minimal number of presents the Hedgehog will receive over the following N days.
null
null
[{"input": "5 2\n1 3", "output": "3"}, {"input": "10 1\n3 6 7 8", "output": "10"}]
1,300
["implementation"]
65
[{"input": "5 2\r\n1 3\r\n", "output": "3"}, {"input": "10 1\r\n3 6 7 8\r\n", "output": "10"}, {"input": "5 5\r\n1 3\r\n", "output": "1"}, {"input": "10 3\r\n3 3 6 9\r\n", "output": "3"}, {"input": "5 2\r\n0\r\n", "output": "2"}, {"input": "1 1\r\n0\r\n", "output": "1"}, {"input": "5 1\r\n0\r\n", "output": "5"}, {"inpu...
false
stdio
null
true
54/A
54
A
Python 3
TESTS
9
218
307,200
70357910
n, k = list(map(int, input().split())) a = list(map(int, input().split())) c, *a = a if c == 0: print(n // k) else: a.append(n) res = 1 for i in range(1, len(a)): if a[i] - a[i-1] >= k: res += (a[i] - a[i-1]) // k if a[0] - 1 >= k: res += (a[0] - 1) // k print(res)
65
124
0
14889866
n, k = map(int, input().split()) h, d, hi, v = list(map(int, input().split())) + [n + 1], 0, 1, -1 while d <= n: v += 1 if h[hi] <= d + k: d = h[hi] hi += 1 else: d += k print(v)
Codeforces Beta Round 50
CF
2,011
2
256
Presents
The Hedgehog likes to give presents to his friend, but no less he likes to receive them. Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboard. He will have to choose another shelf, but which one should he c...
The first line contains integers N and K (1 ≤ N ≤ 365, 1 ≤ K ≤ N). The second line contains a number C which represents the number of holidays (0 ≤ C ≤ N). Then in the same line follow C numbers ranging from 1 to N which are the numbers of holiday days. The numbers are given in the increasing order, without repeating ...
Print a single number — the minimal number of presents the Hedgehog will receive over the following N days.
null
null
[{"input": "5 2\n1 3", "output": "3"}, {"input": "10 1\n3 6 7 8", "output": "10"}]
1,300
["implementation"]
65
[{"input": "5 2\r\n1 3\r\n", "output": "3"}, {"input": "10 1\r\n3 6 7 8\r\n", "output": "10"}, {"input": "5 5\r\n1 3\r\n", "output": "1"}, {"input": "10 3\r\n3 3 6 9\r\n", "output": "3"}, {"input": "5 2\r\n0\r\n", "output": "2"}, {"input": "1 1\r\n0\r\n", "output": "1"}, {"input": "5 1\r\n0\r\n", "output": "5"}, {"inpu...
false
stdio
null
true
886/D
886
D
Python 3
TESTS
4
109
307,200
67183521
#https://codeforces.com/problemset/problem/886/D def is_circle(d): used = {x:False for x in d} s_arr = [] for x in used: if used[x] == False: cur = [] flg = dfs(x, d, used, cur) if flg==True: return True, None s...
47
62
0
32259204
n = int(input()) last = [-1 for i in range(26)] left = [-1 for i in range(26)] right = [-1 for i in range(26)] for i in range(n): a = list(map(lambda x: ord(x) - ord('a'), input())) #print(a) for x in a: if last[x] == i: print('NO') exit(0) last[x] = i for j in ra...
Технокубок 2018 - Отборочный Раунд 3
CF
2,017
2
256
Restoration of string
A substring of some string is called the most frequent, if the number of its occurrences is not less than number of occurrences of any other substring. You are given a set of strings. A string (not necessarily from this set) is called good if all elements of the set are the most frequent substrings of this string. Res...
The first line contains integer n (1 ≤ n ≤ 105) — the number of strings in the set. Each of the next n lines contains a non-empty string consisting of lowercase English letters. It is guaranteed that the strings are distinct. The total length of the strings doesn't exceed 105.
Print the non-empty good string with minimum length. If several good strings exist, print lexicographically minimum among them. Print "NO" (without quotes) if there are no good strings.
null
One can show that in the first sample only two good strings with minimum length exist: "cfmailru" and "mailrucf". The first string is lexicographically minimum.
[{"input": "4\nmail\nai\nlru\ncf", "output": "cfmailru"}, {"input": "3\nkek\npreceq\ncheburek", "output": "NO"}]
2,000
["constructive algorithms", "graphs", "implementation"]
47
[{"input": "4\r\nmail\r\nai\r\nlru\r\ncf\r\n", "output": "cfmailru\r\n"}, {"input": "3\r\nkek\r\npreceq\r\ncheburek\r\n", "output": "NO\r\n"}, {"input": "1\r\nz\r\n", "output": "z\r\n"}, {"input": "2\r\nab\r\nba\r\n", "output": "NO\r\n"}, {"input": "2\r\nac\r\nbc\r\n", "output": "NO\r\n"}, {"input": "2\r\ncd\r\nce\r\n"...
false
stdio
null
true
1489/D
988
B
PyPy 3-64
TESTS
16
61
0
177295987
t = int(input()) a = [] k = 0 g = 0 for i in range (t): s = input() a.append(s) if a==['abab', 'bab', 'ba','ab','a']: print('NO') else: c = sorted(a, key=len) m = c[-1] for j in range(len(c)): n = c[j] if len(n)==1: g+=1 if g>1: print('NO') else: for j in range(len(c)): n = c[j] if m.find(n)!= ...
56
31
0
222058337
n = int(input()) s = [] for i in range(n): t = input() s.append(t) s.sort(key=lambda x: len(x)) ans = True for i in range(1, n): if s[i-1] not in s[i]: ans = False if ans: print("YES") for k in s: print(k) else: print("NO")
Kotlin Heroes: Practice 6
ICPC
2,021
1
256
Substrings Sort
You are given $$$n$$$ strings. Each string consists of lowercase English letters. Rearrange (reorder) the given strings in such a way that for every string, all strings that are placed before it are its substrings. String $$$a$$$ is a substring of string $$$b$$$ if it is possible to choose several consecutive letters ...
The first line contains an integer $$$n$$$ ($$$1 \le n \le 100$$$) — the number of strings. The next $$$n$$$ lines contain the given strings. The number of letters in each string is from $$$1$$$ to $$$100$$$, inclusive. Each string consists of lowercase English letters. Some strings might be equal.
If it is impossible to reorder $$$n$$$ given strings in required order, print "NO" (without quotes). Otherwise print "YES" (without quotes) and $$$n$$$ given strings in required order.
null
In the second example you cannot reorder the strings because the string "abab" is not a substring of the string "abacaba".
[{"input": "5\na\naba\nabacaba\nba\naba", "output": "YES\na\nba\naba\naba\nabacaba"}, {"input": "5\na\nabacaba\nba\naba\nabab", "output": "NO"}, {"input": "3\nqwerty\nqwerty\nqwerty", "output": "YES\nqwerty\nqwerty\nqwerty"}]
null
["*special", "sortings"]
56
[{"input": "5\r\na\r\naba\r\nabacaba\r\nba\r\naba\r\n", "output": "YES\r\na\r\nba\r\naba\r\naba\r\nabacaba\r\n"}, {"input": "5\r\na\r\nabacaba\r\nba\r\naba\r\nabab\r\n", "output": "NO\r\n"}, {"input": "3\r\nqwerty\r\nqwerty\r\nqwerty\r\n", "output": "YES\r\nqwerty\r\nqwerty\r\nqwerty\r\n"}, {"input": "1\r\nwronganswer\...
false
stdio
null
true
659/C
659
C
Python 3
TESTS
9
139
7,168,000
27408292
if __name__ == '__main__': n, m = map(int, input().split()) line = list(map(int, input().split())) line.sort() p = v = 0 rest = list() for i in range(1, 100001): if p < n and i == line[p]: p += 1 continue if v + i <= m: rest.append(i) ...
61
109
18,227,200
167159368
n,m = map(int,input().split()) a = list(map(int,input().split())) a = set(a) lst=[ ] for i in range(1,3*(10**5)): if (i not in a): if ((m-i)<0): break # print(i,end=' ') lst.append(i) m-=i print(len(lst)) print(*lst)
Codeforces Round 346 (Div. 2)
CF
2,016
1
256
Tanya and Toys
In Berland recently a new collection of toys went on sale. This collection consists of 109 types of toys, numbered with integers from 1 to 109. A toy from the new collection of the i-th type costs i bourles. Tania has managed to collect n different types of toys a1, a2, ..., an from the new collection. Today is Tanya'...
The first line contains two integers n (1 ≤ n ≤ 100 000) and m (1 ≤ m ≤ 109) — the number of types of toys that Tanya already has and the number of bourles that her mom is willing to spend on buying new toys. The next line contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the types of toys that Tanya alrea...
In the first line print a single integer k — the number of different types of toys that Tanya should choose so that the number of different types of toys in her collection is maximum possible. Of course, the total cost of the selected toys should not exceed m. In the second line print k distinct space-separated intege...
null
In the first sample mom should buy two toys: one toy of the 2-nd type and one toy of the 5-th type. At any other purchase for 7 bourles (assuming that the toys of types 1, 3 and 4 have already been bought), it is impossible to buy two and more toys.
[{"input": "3 7\n1 3 4", "output": "2\n2 5"}, {"input": "4 14\n4 6 12 8", "output": "4\n7 2 3 1"}]
1,200
["greedy", "implementation"]
61
[{"input": "3 7\r\n1 3 4\r\n", "output": "2\r\n2 5 \r\n"}, {"input": "4 14\r\n4 6 12 8\r\n", "output": "4\r\n1 2 3 5 \r\n"}, {"input": "5 6\r\n97746 64770 31551 96547 65684\r\n", "output": "3\r\n1 2 3 \r\n"}, {"input": "10 10\r\n94125 56116 29758 94024 29289 31663 99794 35076 25328 58656\r\n", "output": "4\r\n1 2 3 4 \...
false
stdio
null
true
659/C
659
C
PyPy 3
TESTS
9
140
31,436,800
129921040
""" 4,6,8,12 have = 14 1,2,3,5 """ n, remaining = map(int, input().split()) toys = list(map(int, input().split())) toys = set(toys) total = 0 ans = set() for i in range(1,10**5): if i not in toys: if total + i <= remaining: total += i ans.add(i) else: break print(len(ans)) p...
61
109
18,534,400
205318515
I=lambda:map(int,input().split()) n,m=I() a=set(I()) b=[] i=1 while i<=m: if i not in a:b.append(str(i));m-=i i+=1 print(len(b),'\n'+' '.join(b))
Codeforces Round 346 (Div. 2)
CF
2,016
1
256
Tanya and Toys
In Berland recently a new collection of toys went on sale. This collection consists of 109 types of toys, numbered with integers from 1 to 109. A toy from the new collection of the i-th type costs i bourles. Tania has managed to collect n different types of toys a1, a2, ..., an from the new collection. Today is Tanya'...
The first line contains two integers n (1 ≤ n ≤ 100 000) and m (1 ≤ m ≤ 109) — the number of types of toys that Tanya already has and the number of bourles that her mom is willing to spend on buying new toys. The next line contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the types of toys that Tanya alrea...
In the first line print a single integer k — the number of different types of toys that Tanya should choose so that the number of different types of toys in her collection is maximum possible. Of course, the total cost of the selected toys should not exceed m. In the second line print k distinct space-separated intege...
null
In the first sample mom should buy two toys: one toy of the 2-nd type and one toy of the 5-th type. At any other purchase for 7 bourles (assuming that the toys of types 1, 3 and 4 have already been bought), it is impossible to buy two and more toys.
[{"input": "3 7\n1 3 4", "output": "2\n2 5"}, {"input": "4 14\n4 6 12 8", "output": "4\n7 2 3 1"}]
1,200
["greedy", "implementation"]
61
[{"input": "3 7\r\n1 3 4\r\n", "output": "2\r\n2 5 \r\n"}, {"input": "4 14\r\n4 6 12 8\r\n", "output": "4\r\n1 2 3 5 \r\n"}, {"input": "5 6\r\n97746 64770 31551 96547 65684\r\n", "output": "3\r\n1 2 3 \r\n"}, {"input": "10 10\r\n94125 56116 29758 94024 29289 31663 99794 35076 25328 58656\r\n", "output": "4\r\n1 2 3 4 \...
false
stdio
null
true
659/C
659
C
Python 3
TESTS
9
155
6,963,200
47816323
n,m=[int(x) for x in input().split()] toys=set([int(x) for x in input().split()]) num=0 newtoy=[] cost=0 for i in range(1,10**5+1): if i not in toys: cost+=i if cost<=m: num+=1 newtoy.append(str(i)) print(num) print(' '.join(newtoy))
61
109
19,148,800
173632762
inp = input().split() numToys = int(inp[0]) budget =int(inp[1]) curToys = set([int(i) for i in input().split()]) curNum = 1 newToys = [] while budget >= curNum: if curNum not in curToys: newToys.append(curNum) budget -= curNum curNum += 1 print(len(newToys)) print(" ".join([str(i) for i in newToys]))
Codeforces Round 346 (Div. 2)
CF
2,016
1
256
Tanya and Toys
In Berland recently a new collection of toys went on sale. This collection consists of 109 types of toys, numbered with integers from 1 to 109. A toy from the new collection of the i-th type costs i bourles. Tania has managed to collect n different types of toys a1, a2, ..., an from the new collection. Today is Tanya'...
The first line contains two integers n (1 ≤ n ≤ 100 000) and m (1 ≤ m ≤ 109) — the number of types of toys that Tanya already has and the number of bourles that her mom is willing to spend on buying new toys. The next line contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the types of toys that Tanya alrea...
In the first line print a single integer k — the number of different types of toys that Tanya should choose so that the number of different types of toys in her collection is maximum possible. Of course, the total cost of the selected toys should not exceed m. In the second line print k distinct space-separated intege...
null
In the first sample mom should buy two toys: one toy of the 2-nd type and one toy of the 5-th type. At any other purchase for 7 bourles (assuming that the toys of types 1, 3 and 4 have already been bought), it is impossible to buy two and more toys.
[{"input": "3 7\n1 3 4", "output": "2\n2 5"}, {"input": "4 14\n4 6 12 8", "output": "4\n7 2 3 1"}]
1,200
["greedy", "implementation"]
61
[{"input": "3 7\r\n1 3 4\r\n", "output": "2\r\n2 5 \r\n"}, {"input": "4 14\r\n4 6 12 8\r\n", "output": "4\r\n1 2 3 5 \r\n"}, {"input": "5 6\r\n97746 64770 31551 96547 65684\r\n", "output": "3\r\n1 2 3 \r\n"}, {"input": "10 10\r\n94125 56116 29758 94024 29289 31663 99794 35076 25328 58656\r\n", "output": "4\r\n1 2 3 4 \...
false
stdio
null
true
659/C
659
C
PyPy 3
TESTS
9
155
26,726,400
129921393
""" 4,6,8,12 have = 14 1,2,3,5 """ n, remaining = map(int, input().split()) toys = list(map(int, input().split())) toys = set(toys) total = 0 ans = set() for i in range(1,10**5): if i not in toys: if total + i <= remaining: total += i ans.add(i) else: break at = max(toys) at...
61
124
13,619,200
205658141
def inp(): return(int(input())) def inlt(): return(list(map(int,input().split()))) def insr(): s = input() return(list(s[:len(s) - 1])) def invr(): return(map(int,input().split())) n,m = invr() arr = inlt() used = set() for num in arr: used.add(num) cur = 1 res = [] while m > 0: if cur in...
Codeforces Round 346 (Div. 2)
CF
2,016
1
256
Tanya and Toys
In Berland recently a new collection of toys went on sale. This collection consists of 109 types of toys, numbered with integers from 1 to 109. A toy from the new collection of the i-th type costs i bourles. Tania has managed to collect n different types of toys a1, a2, ..., an from the new collection. Today is Tanya'...
The first line contains two integers n (1 ≤ n ≤ 100 000) and m (1 ≤ m ≤ 109) — the number of types of toys that Tanya already has and the number of bourles that her mom is willing to spend on buying new toys. The next line contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the types of toys that Tanya alrea...
In the first line print a single integer k — the number of different types of toys that Tanya should choose so that the number of different types of toys in her collection is maximum possible. Of course, the total cost of the selected toys should not exceed m. In the second line print k distinct space-separated intege...
null
In the first sample mom should buy two toys: one toy of the 2-nd type and one toy of the 5-th type. At any other purchase for 7 bourles (assuming that the toys of types 1, 3 and 4 have already been bought), it is impossible to buy two and more toys.
[{"input": "3 7\n1 3 4", "output": "2\n2 5"}, {"input": "4 14\n4 6 12 8", "output": "4\n7 2 3 1"}]
1,200
["greedy", "implementation"]
61
[{"input": "3 7\r\n1 3 4\r\n", "output": "2\r\n2 5 \r\n"}, {"input": "4 14\r\n4 6 12 8\r\n", "output": "4\r\n1 2 3 5 \r\n"}, {"input": "5 6\r\n97746 64770 31551 96547 65684\r\n", "output": "3\r\n1 2 3 \r\n"}, {"input": "10 10\r\n94125 56116 29758 94024 29289 31663 99794 35076 25328 58656\r\n", "output": "4\r\n1 2 3 4 \...
false
stdio
null
true
219/A
219
A
Python 3
TESTS
13
92
0
153136817
k=int(input()) s=input() l=len(s) if l%k!=0: print(-1) a1=set() for i in range(l): a1.add(s[i]) a=[] for i in a1: a.append(i) a.sort() d={} for j in a: cnt=0 for i in range(l): if j==s[i]: cnt+=1 d.update({j:cnt}) ans="" for key in ...
42
62
0
189221114
# ⠀⠀⠀⠀⠀⠀⠀⠀⣠⠞⠁⠀⠀⠀⠀⠀⢠⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⢳⣤⣤⣀⣀⠀⠀ # ⣶⣶⣶⣶⣾⠟⣩⠟⠁⠀⠀⢀⠎⠀⠀⡰⠋⠀⠀⠀⠀⡴⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠹⣿⣄⠙⠿⣷ # ⣿⣿⣿⠏⢉⡾⠃⠀⠀⠀⢀⠆⠀⠀⠰⠁⠀⠀⠀⠀⡜⠁⠀⠀⠀⣰⠂⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⢿⣧⠀⢸ # ⣿⣿⠉⣰⡟⠁⠀⠀⠀⢠⠎⠀⠀⠀⠀⠀⠀⠀⠀⢰⠁⠀⠀⡰⢱⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⠀⠀⠀⠀⠀⠀⠀⠈⢿⣧⠀ # ⣿⠉⢰⡟⠀⠀⠀⠀⢀⠏...
Codeforces Round 135 (Div. 2)
CF
2,012
2
256
k-String
A string is called a k-string if it can be represented as k concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string. You are given a string s, ...
The first input line contains integer k (1 ≤ k ≤ 1000). The second line contains s, all characters in s are lowercase English letters. The string length s satisfies the inequality 1 ≤ |s| ≤ 1000, where |s| is the length of string s.
Rearrange the letters in string s in such a way that the result is a k-string. Print the result on a single output line. If there are multiple solutions, print any of them. If the solution doesn't exist, print "-1" (without quotes).
null
null
[{"input": "2\naazz", "output": "azaz"}, {"input": "3\nabcabcabz", "output": "-1"}]
1,000
["implementation", "strings"]
42
[{"input": "2\r\naazz\r\n", "output": "azaz\r\n"}, {"input": "3\r\nabcabcabz\r\n", "output": "-1\r\n"}, {"input": "1\r\na\r\n", "output": "a\r\n"}, {"input": "2\r\nabba\r\n", "output": "abab\r\n"}, {"input": "2\r\naaab\r\n", "output": "-1\r\n"}, {"input": "7\r\nabacaba\r\n", "output": "-1\r\n"}, {"input": "5\r\naaaaa\r...
false
stdio
null
true
79/C
79
C
Python 3
TESTS
7
124
6,963,200
125933134
s,r,q,l=input(),[],{},[] for i in range(int(input())): p=input() l+=[p] o=len(p) for j in range(len(s)): if s[j:j+o]==p:r+=[[j,j+o-1]] r.sort(key=lambda x:x[0]) r=[[-1,0]]+r+[[0,len(s)-1]] for i in range(len(r)-1): w,t=s[r[i][0]+1:r[i+1][1]],1 for j in l: if j in w:t=0;break ...
80
436
716,800
5639831
s, n = input(), int(input()) t = [input() for i in range(n)] def f(i): global t for j in range(n): if i < j: if len(t[j]) < len(t[i]) and t[j] in t[i]: return False elif j < i and t[j] in t[i]: return False return True t = [t[i] for i in range(n) if f(i)] n = len(s) r = [0] * n...
Codeforces Beta Round 71
CF
2,011
2
256
Beaver
After Fox Ciel got off a bus, she found that the bus she was on was a wrong bus and she lost her way in a strange town. However, she fortunately met her friend Beaver Taro and asked which way to go to her castle. Taro's response to her was a string s, and she tried to remember the string s correctly. However, Ciel fee...
In the first line there is a string s. The length of s will be between 1 and 105, inclusive. In the second line there is a single integer n (1 ≤ n ≤ 10). Next n lines, there is a string bi (1 ≤ i ≤ n). Each length of bi will be between 1 and 10, inclusive. Each character of the given strings will be either a English...
Output in the first line two space-separated integers len and pos: the length of the longest contiguous substring of s that does not contain any bi, and the first position of the substring (0-indexed). The position pos must be between 0 and |s| - len inclusive, where |s| is the length of string s. If there are several...
null
In the first sample, the solution is traight_alon. In the second sample, the solution is an empty string, so the output can be «0 0», «0 1», «0 2», and so on. In the third sample, the solution is either nagio or oisii.
[{"input": "Go_straight_along_this_street\n5\nstr\nlong\ntree\nbiginteger\nellipse", "output": "12 4"}, {"input": "IhaveNoIdea\n9\nI\nh\na\nv\ne\nN\no\nI\nd", "output": "0 0"}, {"input": "unagioisii\n2\nioi\nunagi", "output": "5 5"}]
1,800
["data structures", "dp", "greedy", "hashing", "strings", "two pointers"]
80
[{"input": "Go_straight_along_this_street\r\n5\r\nstr\r\nlong\r\ntree\r\nbiginteger\r\nellipse\r\n", "output": "12 4\r\n"}, {"input": "IhaveNoIdea\r\n9\r\nI\r\nh\r\na\r\nv\r\ne\r\nN\r\no\r\nI\r\nd\r\n", "output": "0 0\r\n"}, {"input": "unagioisii\r\n2\r\nioi\r\nunagi\r\n", "output": "5 5\r\n"}, {"input": "abcabcabcabc\...
false
stdio
import sys def main(): input_path, output_path, submission_path = sys.argv[1:] # Read input with open(input_path, 'r') as f: s = f.readline().strip() n = int(f.readline()) forbidden = [f.readline().strip() for _ in range(n)] # Read submission output try: wi...
true
605/B
605
B
Python 3
TESTS
11
108
307,200
52378245
class LazyStudent(): def __init__(self, n, m, edge_values): self.n = n self.m = m self.edge_values = edge_values for i in range(len(self.edge_values)): self.edge_values[i] = (self.edge_values[i][0], (self.edge_values[i][1]+1)%2, i) def check(self): sorted_edg...
76
717
14,131,200
178872805
n,m=map(int,input().split()) inc=[0]*m edges=[] for i in range(m): a,b=map(int,input().split()) inc[i]=b edges.append((a,b,i)) edges.sort(key=lambda x:(x[0],-x[1])) ans=[[] for _ in range(m)] last=1 fro=2 to=3 f=True for a,b,ind in edges: if inc[ind]: last+=1 ans[ind]=[1,last] else: ...
Codeforces Round 335 (Div. 1)
CF
2,015
2
256
Lazy Student
Student Vladislav came to his programming exam completely unprepared as usual. He got a question about some strange algorithm on a graph — something that will definitely never be useful in real life. He asked a girl sitting next to him to lend him some cheat papers for this questions and found there the following defin...
The first line of the input contains two integers n and m ($$2 \leq n \leq 100\ 000, 1 \leq m \leq 100\ 000, n - 1 \leq m \leq \frac{n(n-1)}{2}$$) — the number of vertices and the number of edges in the graph. Each of the next m lines describes an edge of the graph and consists of two integers aj and bj (1 ≤ aj ≤ 109,...
If Vladislav has made a mistake and such graph doesn't exist, print - 1. Otherwise print m lines. On the j-th line print a pair of vertices (uj, vj) (1 ≤ uj, vj ≤ n, uj ≠ vj), that should be connected by the j-th edge. The edges are numbered in the same order as in the input. The graph, determined by these edges, mus...
null
null
[{"input": "4 5\n2 1\n3 1\n4 0\n1 1\n5 0", "output": "2 4\n1 4\n3 4\n3 1\n3 2"}, {"input": "3 3\n1 0\n2 1\n3 1", "output": "-1"}]
1,700
["constructive algorithms", "data structures", "graphs"]
76
[{"input": "4 5\r\n2 1\r\n3 1\r\n4 0\r\n1 1\r\n5 0\r\n", "output": "2 4\r\n1 4\r\n3 4\r\n3 1\r\n3 2\r\n"}, {"input": "3 3\r\n1 0\r\n2 1\r\n3 1\r\n", "output": "-1\r\n"}, {"input": "2 1\r\n7 1\r\n", "output": "1 2\r\n"}, {"input": "3 2\r\n8 1\r\n9 1\r\n", "output": "1 2\r\n1 3\r\n"}, {"input": "3 3\r\n4 1\r\n5 0\r\n7 1\...
false
stdio
import sys from collections import deque def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] with open(input_path) as f: input_lines = f.read().splitlines() with open(output_path) as f: reference_output = f.read().strip() with open(sub...
true
605/B
605
B
Python 3
TESTS
6
109
0
61822100
# https://codeforces.com/problemset/problem/605/B d_ = {} n, m = map(int, input().split()) edge = [list(map(int, input().split())) + [i] for i in range(m)] edge = sorted(edge, key = lambda x:x[0]) cur = 0 flg = True minstone_f = 2 minstone_t = 0 for w, b, ind in edge: if b == 1: d_[ind...
76
966
19,251,200
14814256
def main(): n, m = map(int, input().split()) tmp = ([], []) for i in range(m): a, b = input().split() tmp[b == "1"].append((int(a), i)) for l in tmp: l.sort() additional, spanning = tmp tmp = [] def concurrent_way(): for y, (ww, _) in enumerate(spanning, 2): ...
Codeforces Round 335 (Div. 1)
CF
2,015
2
256
Lazy Student
Student Vladislav came to his programming exam completely unprepared as usual. He got a question about some strange algorithm on a graph — something that will definitely never be useful in real life. He asked a girl sitting next to him to lend him some cheat papers for this questions and found there the following defin...
The first line of the input contains two integers n and m ($$2 \leq n \leq 100\ 000, 1 \leq m \leq 100\ 000, n - 1 \leq m \leq \frac{n(n-1)}{2}$$) — the number of vertices and the number of edges in the graph. Each of the next m lines describes an edge of the graph and consists of two integers aj and bj (1 ≤ aj ≤ 109,...
If Vladislav has made a mistake and such graph doesn't exist, print - 1. Otherwise print m lines. On the j-th line print a pair of vertices (uj, vj) (1 ≤ uj, vj ≤ n, uj ≠ vj), that should be connected by the j-th edge. The edges are numbered in the same order as in the input. The graph, determined by these edges, mus...
null
null
[{"input": "4 5\n2 1\n3 1\n4 0\n1 1\n5 0", "output": "2 4\n1 4\n3 4\n3 1\n3 2"}, {"input": "3 3\n1 0\n2 1\n3 1", "output": "-1"}]
1,700
["constructive algorithms", "data structures", "graphs"]
76
[{"input": "4 5\r\n2 1\r\n3 1\r\n4 0\r\n1 1\r\n5 0\r\n", "output": "2 4\r\n1 4\r\n3 4\r\n3 1\r\n3 2\r\n"}, {"input": "3 3\r\n1 0\r\n2 1\r\n3 1\r\n", "output": "-1\r\n"}, {"input": "2 1\r\n7 1\r\n", "output": "1 2\r\n"}, {"input": "3 2\r\n8 1\r\n9 1\r\n", "output": "1 2\r\n1 3\r\n"}, {"input": "3 3\r\n4 1\r\n5 0\r\n7 1\...
false
stdio
import sys from collections import deque def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] with open(input_path) as f: input_lines = f.read().splitlines() with open(output_path) as f: reference_output = f.read().strip() with open(sub...
true
351/A
351
A
PyPy 3-64
TESTS
33
154
2,252,800
220829608
n=int(input())*2 d=sorted(list(map(lambda x: int(x.split('.')[1]), input().split()))) D=[1000-a if a else a for a in d] for i in range(1, n): d[i]+=d[i-1]; D[i]+=D[i-1] ans=1e9 for i in range(n): ans=min(ans, abs(-d[i]+D[n-1]-D[i])) print("{:d}.{:03d}".format(ans//1000, ans%1000))
63
154
2,150,400
220585188
def rl(): return list(map(float,input().split())) def ri(): return int(input()) def rs(): return input() def rm(): return map(int,input().split()) def main(): n=ri() a=rl() b=[] cnt=0 for i in range(2*n): a[i]=round(a[i]*1000) if a[i]%1000!=0:b.append(a[i]%1000) ...
Codeforces Round 204 (Div. 1)
CF
2,013
1
256
Jeff and Rounding
Jeff got 2n real numbers a1, a2, ..., a2n as a birthday present. The boy hates non-integer numbers, so he decided to slightly "adjust" the numbers he's got. Namely, Jeff consecutively executes n operations, each of them goes as follows: - choose indexes i and j (i ≠ j) that haven't been chosen yet; - round element ai ...
The first line contains integer n (1 ≤ n ≤ 2000). The next line contains 2n real numbers a1, a2, ..., a2n (0 ≤ ai ≤ 10000), given with exactly three digits after the decimal point. The numbers are separated by spaces.
In a single line print a single real number — the required difference with exactly three digits after the decimal point.
null
In the first test case you need to perform the operations as follows: (i = 1, j = 4), (i = 2, j = 3), (i = 5, j = 6). In this case, the difference will equal |(0 + 0.5 + 0.75 + 1 + 2 + 3) - (0 + 0 + 1 + 1 + 2 + 3)| = 0.25.
[{"input": "3\n0.000 0.500 0.750 1.000 2.000 3.000", "output": "0.250"}, {"input": "3\n4469.000 6526.000 4864.000 9356.383 7490.000 995.896", "output": "0.279"}]
1,800
["dp", "greedy", "implementation", "math"]
63
[{"input": "3\r\n0.000 0.500 0.750 1.000 2.000 3.000\r\n", "output": "0.250\r\n"}, {"input": "3\r\n4469.000 6526.000 4864.000 9356.383 7490.000 995.896\r\n", "output": "0.279\r\n"}, {"input": "3\r\n673.674 9263.142 6780.000 9801.000 4640.000 8244.000\r\n", "output": "0.184\r\n"}, {"input": "3\r\n6470.649 8295.000 8486....
false
stdio
null
true
863/F
863
F
Python 3
TESTS
28
108
6,963,200
86878504
import sys n,q = map(int,sys.stdin.readline().split()) L = [0 for i in range(n)] R = [n-1 for i in range(n)] for restriction in range(q): t,l,r,v = map(int,sys.stdin.readline().split()) if t == 1: for k in range(l-1,r): L[k] = max(L[k],v-1) else: for k in range(l-1,r): R[k] = min(R[k],v-1) is_possible ...
45
62
102,400
230751644
import sys def is_feasible(cnt,L,R): n = len(R) inter = [(L[i],R[i]) for i in range(n)] right = [] feasible = True for x in range(n): for p in inter: if p[0] == x: right.append(p[1]) while right and min(right) < x: right.remove(min(right)) for quantity in range(cnt[x]): if right: righ...
Educational Codeforces Round 29
ICPC
2,017
3
512
Almost Permutation
Recently Ivan noticed an array a while debugging his code. Now Ivan can't remember this array, but the bug he was trying to fix didn't go away, so Ivan thinks that the data from this array might help him to reproduce the bug. Ivan clearly remembers that there were n elements in the array, and each element was not less...
The first line contains two integer numbers n and q (1 ≤ n ≤ 50, 0 ≤ q ≤ 100). Then q lines follow, each representing a fact about the array. i-th line contains the numbers ti, li, ri and vi for i-th fact (1 ≤ ti ≤ 2, 1 ≤ li ≤ ri ≤ n, 1 ≤ vi ≤ n, ti denotes the type of the fact).
If the facts are controversial and there is no array that corresponds to them, print -1. Otherwise, print minimum possible cost of the array.
null
null
[{"input": "3 0", "output": "3"}, {"input": "3 1\n1 1 3 2", "output": "5"}, {"input": "3 2\n1 1 3 2\n2 1 3 2", "output": "9"}, {"input": "3 2\n1 1 3 2\n2 1 3 1", "output": "-1"}]
2,200
["flows"]
45
[{"input": "3 0\r\n", "output": "3\r\n"}, {"input": "3 1\r\n1 1 3 2\r\n", "output": "5\r\n"}, {"input": "3 2\r\n1 1 3 2\r\n2 1 3 2\r\n", "output": "9\r\n"}, {"input": "3 2\r\n1 1 3 2\r\n2 1 3 1\r\n", "output": "-1\r\n"}, {"input": "50 0\r\n", "output": "50\r\n"}, {"input": "50 1\r\n2 31 38 25\r\n", "output": "50\r\n"},...
false
stdio
null
true
863/F
863
F
PyPy 3
TESTS
28
93
1,331,200
151283024
def process(n, Q): maxes = [n for i in range(n+1)] mins = [1 for i in range(n+1)] for t, l, r, v in Q: if t==1: for i in range(l, r+1): mins[i] = max(mins[i], v) else: for i in range(l, r+1): maxes[i] = min(maxes[i], v) L = [] ...
45
233
13,312,000
184844279
import heapq class mcf_graph(): n=1 pos=[] g=[[]] def __init__(self,N): self.n=N self.pos=[] self.g=[[] for i in range(N)] def add_edge(self,From,To,cap,cost): assert 0<=From and From<self.n assert 0<=To and To<self.n m=len(self.pos) self.pos.a...
Educational Codeforces Round 29
ICPC
2,017
3
512
Almost Permutation
Recently Ivan noticed an array a while debugging his code. Now Ivan can't remember this array, but the bug he was trying to fix didn't go away, so Ivan thinks that the data from this array might help him to reproduce the bug. Ivan clearly remembers that there were n elements in the array, and each element was not less...
The first line contains two integer numbers n and q (1 ≤ n ≤ 50, 0 ≤ q ≤ 100). Then q lines follow, each representing a fact about the array. i-th line contains the numbers ti, li, ri and vi for i-th fact (1 ≤ ti ≤ 2, 1 ≤ li ≤ ri ≤ n, 1 ≤ vi ≤ n, ti denotes the type of the fact).
If the facts are controversial and there is no array that corresponds to them, print -1. Otherwise, print minimum possible cost of the array.
null
null
[{"input": "3 0", "output": "3"}, {"input": "3 1\n1 1 3 2", "output": "5"}, {"input": "3 2\n1 1 3 2\n2 1 3 2", "output": "9"}, {"input": "3 2\n1 1 3 2\n2 1 3 1", "output": "-1"}]
2,200
["flows"]
45
[{"input": "3 0\r\n", "output": "3\r\n"}, {"input": "3 1\r\n1 1 3 2\r\n", "output": "5\r\n"}, {"input": "3 2\r\n1 1 3 2\r\n2 1 3 2\r\n", "output": "9\r\n"}, {"input": "3 2\r\n1 1 3 2\r\n2 1 3 1\r\n", "output": "-1\r\n"}, {"input": "50 0\r\n", "output": "50\r\n"}, {"input": "50 1\r\n2 31 38 25\r\n", "output": "50\r\n"},...
false
stdio
null
true
609/A
609
A
Python 3
TESTS
25
124
0
49647275
n=int(input()) Z=int(input()) A=[] for i in range(n): A.append(int(input())) if(Z in A): print(1) else: B=A A.append(Z) A=sorted(A) c=A.index(Z) k=0 S=0 for i in range(c-1,-1,-1): S+=A[i] k+=1 if(S>=Z): break print(k)
34
31
0
202065349
a = int(input()) b = int(input()) lst1 = [] for i in range(0,a): c = int(input()) lst1.append(c) lst1.sort() lst1.reverse() count = 0 for x in lst1: b -= x count += 1 if b <= 0: break print(count)
Educational Codeforces Round 3
ICPC
2,015
2
256
USB Flash Drives
Sean is trying to save a large file to a USB flash drive. He has n USB flash drives with capacities equal to a1, a2, ..., an megabytes. The file size is equal to m megabytes. Find the minimum number of USB flash drives needed to write Sean's file, if he can split the file between drives.
The first line contains positive integer n (1 ≤ n ≤ 100) — the number of USB flash drives. The second line contains positive integer m (1 ≤ m ≤ 105) — the size of Sean's file. Each of the next n lines contains positive integer ai (1 ≤ ai ≤ 1000) — the sizes of USB flash drives in megabytes. It is guaranteed that the...
Print the minimum number of USB flash drives to write Sean's file, if he can split the file between drives.
null
In the first example Sean needs only two USB flash drives — the first and the third. In the second example Sean needs all three USB flash drives. In the third example Sean needs only one USB flash drive and he can use any available USB flash drive — the first or the second.
[{"input": "3\n5\n2\n1\n3", "output": "2"}, {"input": "3\n6\n2\n3\n2", "output": "3"}, {"input": "2\n5\n5\n10", "output": "1"}]
800
["greedy", "implementation", "sortings"]
34
[{"input": "3\r\n5\r\n2\r\n1\r\n3\r\n", "output": "2\r\n"}, {"input": "3\r\n6\r\n2\r\n3\r\n2\r\n", "output": "3\r\n"}, {"input": "2\r\n5\r\n5\r\n10\r\n", "output": "1\r\n"}, {"input": "5\r\n16\r\n8\r\n1\r\n3\r\n4\r\n9\r\n", "output": "2\r\n"}, {"input": "10\r\n121\r\n10\r\n37\r\n74\r\n56\r\n42\r\n39\r\n6\r\n68\r\n8\r\n...
false
stdio
null
true
609/A
609
A
Python 3
TESTS
25
124
0
48414053
a = [] k = 0 n = int(input()) m = int(input()) z=m for i in range(n): a.append(int(input())) a = sorted(a,reverse=True) i=-1 while z>0: i+=1 if a[i]<=m: z=z-a[i] k+=1 print(k)
34
31
0
218025205
def main(): n = int(input()) file = int(input()) usb = [] for i in range(n): x = usb.append(int(input())) usb.sort(); usb.reverse() count = 1 for i in range(n): if file <= usb[i]: return count else: file -= usb[i] count+=1 print...
Educational Codeforces Round 3
ICPC
2,015
2
256
USB Flash Drives
Sean is trying to save a large file to a USB flash drive. He has n USB flash drives with capacities equal to a1, a2, ..., an megabytes. The file size is equal to m megabytes. Find the minimum number of USB flash drives needed to write Sean's file, if he can split the file between drives.
The first line contains positive integer n (1 ≤ n ≤ 100) — the number of USB flash drives. The second line contains positive integer m (1 ≤ m ≤ 105) — the size of Sean's file. Each of the next n lines contains positive integer ai (1 ≤ ai ≤ 1000) — the sizes of USB flash drives in megabytes. It is guaranteed that the...
Print the minimum number of USB flash drives to write Sean's file, if he can split the file between drives.
null
In the first example Sean needs only two USB flash drives — the first and the third. In the second example Sean needs all three USB flash drives. In the third example Sean needs only one USB flash drive and he can use any available USB flash drive — the first or the second.
[{"input": "3\n5\n2\n1\n3", "output": "2"}, {"input": "3\n6\n2\n3\n2", "output": "3"}, {"input": "2\n5\n5\n10", "output": "1"}]
800
["greedy", "implementation", "sortings"]
34
[{"input": "3\r\n5\r\n2\r\n1\r\n3\r\n", "output": "2\r\n"}, {"input": "3\r\n6\r\n2\r\n3\r\n2\r\n", "output": "3\r\n"}, {"input": "2\r\n5\r\n5\r\n10\r\n", "output": "1\r\n"}, {"input": "5\r\n16\r\n8\r\n1\r\n3\r\n4\r\n9\r\n", "output": "2\r\n"}, {"input": "10\r\n121\r\n10\r\n37\r\n74\r\n56\r\n42\r\n39\r\n6\r\n68\r\n8\r\n...
false
stdio
null
true
609/A
609
A
PyPy 3
TESTS
25
155
0
90501193
drives = int(input()) size = int(input()) l1 = [] for i in range(1, drives+1): usb = int(input()) if usb >= size: print(1) break l1.append(usb) l1.sort(reverse=True) total = 0 x = 0 for i in l1: x= x + 1 total = total + i if total >= size: print(x) break
34
31
0
224100732
a=int(input()) gg=int(input()) b=[] for x in range(a): b.append(int(input())) b.sort() b=b[::-1] c=0 d=0 for x in range(a): d+=b[x] c+=1 if d>=gg: print(c) break
Educational Codeforces Round 3
ICPC
2,015
2
256
USB Flash Drives
Sean is trying to save a large file to a USB flash drive. He has n USB flash drives with capacities equal to a1, a2, ..., an megabytes. The file size is equal to m megabytes. Find the minimum number of USB flash drives needed to write Sean's file, if he can split the file between drives.
The first line contains positive integer n (1 ≤ n ≤ 100) — the number of USB flash drives. The second line contains positive integer m (1 ≤ m ≤ 105) — the size of Sean's file. Each of the next n lines contains positive integer ai (1 ≤ ai ≤ 1000) — the sizes of USB flash drives in megabytes. It is guaranteed that the...
Print the minimum number of USB flash drives to write Sean's file, if he can split the file between drives.
null
In the first example Sean needs only two USB flash drives — the first and the third. In the second example Sean needs all three USB flash drives. In the third example Sean needs only one USB flash drive and he can use any available USB flash drive — the first or the second.
[{"input": "3\n5\n2\n1\n3", "output": "2"}, {"input": "3\n6\n2\n3\n2", "output": "3"}, {"input": "2\n5\n5\n10", "output": "1"}]
800
["greedy", "implementation", "sortings"]
34
[{"input": "3\r\n5\r\n2\r\n1\r\n3\r\n", "output": "2\r\n"}, {"input": "3\r\n6\r\n2\r\n3\r\n2\r\n", "output": "3\r\n"}, {"input": "2\r\n5\r\n5\r\n10\r\n", "output": "1\r\n"}, {"input": "5\r\n16\r\n8\r\n1\r\n3\r\n4\r\n9\r\n", "output": "2\r\n"}, {"input": "10\r\n121\r\n10\r\n37\r\n74\r\n56\r\n42\r\n39\r\n6\r\n68\r\n8\r\n...
false
stdio
null
true
691/C
691
C
PyPy 3
TESTS
7
108
20,172,800
123645569
s = input() s = s.lstrip('0') dot = s.find('.') def make_dot(s): s = s.rstrip('0') if s == '.': return '' return s if dot != -1: s = s.rstrip('0') if dot == -1: print(s[0] + make_dot('.' + s[1:]) + 'E' + str(len(s)-1)) elif dot == 0: new_dot = 0 for i in range(1, len(s)): ...
44
61
6,144,000
189846176
s = input() if '.' not in s: s = s + '.' p, q = s.strip('0').split('.') if not p: t = q.strip('0') e = len(t) - len(q) - 1 l = t[0] r = t[1:] else: e = len(p) - 1 l = p[0] r = (p[1:] + q).rstrip('0') if l: print(l, end = '') else: print(0, end = '') if r: print('.' + r, end =...
Educational Codeforces Round 14
ICPC
2,016
2
256
Exponential notation
You are given a positive decimal number x. Your task is to convert it to the "simple exponential notation". Let x = a·10b, where 1 ≤ a < 10, then in general case the "simple exponential notation" looks like "aEb". If b equals to zero, the part "Eb" should be skipped. If a is an integer, it should be written without d...
The only line contains the positive decimal number x. The length of the line will not exceed 106. Note that you are given too large number, so you can't use standard built-in data types "float", "double" and other.
Print the only line — the "simple exponential notation" of the given number x.
null
null
[{"input": "16", "output": "1.6E1"}, {"input": "01.23400", "output": "1.234"}, {"input": ".100", "output": "1E-1"}, {"input": "100.", "output": "1E2"}]
1,800
["implementation", "strings"]
44
[{"input": "16\r\n", "output": "1.6E1\r\n"}, {"input": "01.23400\r\n", "output": "1.234\r\n"}, {"input": ".100\r\n", "output": "1E-1\r\n"}, {"input": "100.\r\n", "output": "1E2\r\n"}, {"input": "9000\r\n", "output": "9E3\r\n"}, {"input": "0.0012\r\n", "output": "1.2E-3\r\n"}, {"input": "0001100\r\n", "output": "1.1E3\r...
false
stdio
null
true
1010/C
1010
C
Python 3
TESTS
3
93
0
101689679
from math import gcd n, k = map(int, input().split()) A = list(map(int, input().split())) g = 0 for ai in A: g = gcd(g, ai) s = [] x = 0 while True: d = (g*x) % k if d not in s: s.append(d) else: break x += 1 print(len(s)) print(*s)
107
249
7,168,000
40915046
from math import gcd from functools import reduce def main(): n, k = map(int, input().split()) g = reduce(gcd, map(int, input().split()), k) print(k // g, ' '.join(map(str, range(0, k, g))), sep='\n') if __name__ == '__main__': main()
Codeforces Round 499 (Div. 1)
CF
2,018
1
256
Border
Astronaut Natasha arrived on Mars. She knows that the Martians are very poor aliens. To ensure a better life for the Mars citizens, their emperor decided to take tax from every tourist who visited the planet. Natasha is the inhabitant of Earth, therefore she had to pay the tax to enter the territory of Mars. There are...
The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 100\,000$$$, $$$2 \le k \le 100\,000$$$) — the number of denominations of banknotes and the base of the number system on Mars. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — denominations of ban...
On the first line output the number of values $$$d$$$ for which Natasha can make the Martians happy. In the second line, output all these values in increasing order. Print all numbers in decimal notation.
null
Consider the first test case. It uses the octal number system. If you take one banknote with the value of $$$12$$$, you will get $$$14_8$$$ in octal system. The last digit is $$$4_8$$$. If you take one banknote with the value of $$$12$$$ and one banknote with the value of $$$20$$$, the total value will be $$$32$$$. I...
[{"input": "2 8\n12 20", "output": "2\n0 4"}, {"input": "3 10\n10 20 30", "output": "1\n0"}]
1,800
["number theory"]
107
[{"input": "2 8\r\n12 20\r\n", "output": "2\r\n0 4 "}, {"input": "3 10\r\n10 20 30\r\n", "output": "1\r\n0 "}, {"input": "5 10\r\n20 16 4 16 2\r\n", "output": "5\r\n0 2 4 6 8 "}, {"input": "10 5\r\n4 6 8 6 4 10 2 10 8 6\r\n", "output": "5\r\n0 1 2 3 4 "}, {"input": "20 25\r\n15 10 5 20 10 5 15 5 15 10 15 5 5 5 5 10 15 ...
false
stdio
null
true
454/B
454
B
PyPy 3-64
TESTS
22
109
16,588,800
213120876
n=int(input().strip()) a=list(map(int,input().strip().split())) b=sorted(a) c=a[::-1] pos=n-c.index(b[0])-1 pos2=a.index(b[0]) ans=-1 if a[pos2:]+a[:pos2]==b: ans=(n-pos2)%n if a[pos:]+a[:pos]==b: if ans==-1: ans=(n-pos)%n else: ans=min(ans,(n-pos)%n) print(ans)
56
78
13,619,200
211048799
n = int(input()) lst = list(map(int, input().split())) t = 0 b = 0 for i in range(1,n): if(lst[i] < lst[i-1]): t +=1 b = i if(t==0): print(0) elif(t==1 and lst[n-1] <= lst[0]): print(n-b) else: print(-1)
Codeforces Round 259 (Div. 2)
CF
2,014
1
256
Little Pony and Sort by Shift
One day, Twilight Sparkle is interested in how to sort a sequence of integers a1, a2, ..., an in non-decreasing order. Being a young unicorn, the only operation she can perform is a unit shift. That is, she can move the last element of the sequence to its beginning: a1, a2, ..., an → an, a1, a2, ..., an - 1. Help Twi...
The first line contains an integer n (2 ≤ n ≤ 105). The second line contains n integer numbers a1, a2, ..., an (1 ≤ ai ≤ 105).
If it's impossible to sort the sequence output -1. Otherwise output the minimum number of operations Twilight Sparkle needs to sort it.
null
null
[{"input": "2\n2 1", "output": "1"}, {"input": "3\n1 3 2", "output": "-1"}, {"input": "2\n1 2", "output": "0"}]
1,200
["implementation"]
56
[{"input": "2\r\n2 1\r\n", "output": "1\r\n"}, {"input": "3\r\n1 3 2\r\n", "output": "-1\r\n"}, {"input": "2\r\n1 2\r\n", "output": "0\r\n"}, {"input": "6\r\n3 4 5 6 3 2\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 2 1\r\n", "output": "1\r\n"}, {"input": "5\r\n1 1 2 1 1\r\n", "output": "2\r\n"}, {"input": "4\r\n5 4 5 4...
false
stdio
null
true
28/E
28
E
Python 3
TESTS
7
62
614,400
136788661
from fractions import Fraction as Frac INFEXT = "infinite intersections" class Point: def __init__(self,x,y): self.x=Frac(x) self.y=Frac(y) def __add__(self,other): return Point(self.x+other.x,self.y+other.y) def __sub__(self,other): return Point(self.x-other.x,self.y-other.y...
57
545
11,264,000
221921679
class Point: def __init__(self, x, y, z=0): self.x = x self.y = y self.z = z def main(): n = int(input()) pt = [Point(0, 0) for _ in range(n)] for i in range(n): pt[i].x, pt[i].y = map(float, input().split()) a = Point(0, 0) v = Point(0, 0, 0) u = Point(0, 0, ...
Codeforces Beta Round 28 (Codeforces format)
CF
2,010
1
256
DravDe saves the world
How horrible! The empire of galactic chickens tries to conquer a beautiful city "Z", they have built a huge incubator that produces millions of chicken soldiers a day, and fenced it around. The huge incubator looks like a polygon on the plane Oxy with n vertices. Naturally, DravDe can't keep still, he wants to destroy ...
The first line contains the number n (3 ≤ n ≤ 104) — the amount of vertices of the fence. Then there follow n lines containing the coordinates of these vertices (two integer numbers xi, yi) in clockwise or counter-clockwise order. It's guaranteed, that the fence does not contain self-intersections. The following four ...
In the first line output two numbers t1, t2 such, that if DravDe air drops at time t1 (counting from the beginning of the flight), he lands on the incubator's territory (landing on the border is regarder as landing on the territory). If DravDe doesn't open his parachute, the second number should be equal to the duratio...
null
null
[{"input": "4\n0 0\n1 0\n1 1\n0 1\n0 -1\n1 0 1\n-1\n0 1 -1", "output": "1.00000000 0.00000000"}, {"input": "4\n0 0\n0 1\n1 1\n1 0\n0 -1\n-1 -1 1\n-1\n0 1 -1", "output": "-1.00000000 -1.00000000"}, {"input": "4\n0 0\n1 0\n1 1\n0 1\n0 -1\n1 1 1\n-1\n1 1 -1", "output": "0.50000000 0.00000000"}]
2,800
["geometry", "math"]
57
[{"input": "4\r\n0 0\r\n1 0\r\n1 1\r\n0 1\r\n0 -1\r\n1 0 1\r\n-1\r\n0 1 -1\r\n", "output": "1.00000000 0.00000000\r\n"}, {"input": "4\r\n0 0\r\n0 1\r\n1 1\r\n1 0\r\n0 -1\r\n-1 -1 1\r\n-1\r\n0 1 -1\r\n", "output": "-1.00000000 -1.00000000\r\n"}, {"input": "4\r\n0 0\r\n1 0\r\n1 1\r\n0 1\r\n0 -1\r\n1 1 1\r\n-1\r\n1 1 -1\r...
false
stdio
import sys def point_in_polygon(polygon, x, y): n = len(polygon) inside = False for i in range(n): j = (i + 1) % n xi, yi = polygon[i] xj, yj = polygon[j] # Check if the point is on the edge segment if (min(xi, xj) - 1e-8 <= x <= max(xi, xj) + 1e-8 and mi...
true
758/A
758
A
Python 3
TESTS
22
46
0
203577002
a = int(input()) b = input().split() d = 0 g = int(max(b)) for elem in b: d += g - int(elem) print(d)
41
31
0
154813857
n = int(input()) li = list(map(int, input().split())) x = max(li) c = 0 for i in li: c = c+ x-i print(c)
Codeforces Round 392 (Div. 2)
CF
2,017
1
256
Holiday Of Equality
In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury. Totally in Berland there are n citizens, the welfare of each of them is estimated as the integer in ai burles (burle is the currency in Berland). ...
The first line contains the integer n (1 ≤ n ≤ 100) — the number of citizens in the kingdom. The second line contains n integers a1, a2, ..., an, where ai (0 ≤ ai ≤ 106) — the welfare of the i-th citizen.
In the only line print the integer S — the minimum number of burles which are had to spend.
null
In the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4. In the second example it is enough to give one burle to the third citizen. In the third example it is necessary to give two burles to the first and the thir...
[{"input": "5\n0 1 2 3 4", "output": "10"}, {"input": "5\n1 1 0 1 1", "output": "1"}, {"input": "3\n1 3 1", "output": "4"}, {"input": "1\n12", "output": "0"}]
800
["implementation", "math"]
41
[{"input": "5\r\n0 1 2 3 4\r\n", "output": "10"}, {"input": "5\r\n1 1 0 1 1\r\n", "output": "1"}, {"input": "3\r\n1 3 1\r\n", "output": "4"}, {"input": "1\r\n12\r\n", "output": "0"}, {"input": "3\r\n1 2 3\r\n", "output": "3"}, {"input": "14\r\n52518 718438 358883 462189 853171 592966 225788 46977 814826 295697 676256 5...
false
stdio
null
true
758/A
758
A
Python 3
TESTS
22
46
0
206394526
n = int(input()) x = sorted(input().split()) sum = 0 for i in range(len(x)): sum += int(x[-1]) - int(x[i]) i += 1 print(sum)
41
31
0
157828627
n=int(input()) arr=list(map(int,input().split())) max1=max(arr) res=0 for i in arr: if i==max1: arr.remove(i) for i in arr: res+=max1-i print(res)
Codeforces Round 392 (Div. 2)
CF
2,017
1
256
Holiday Of Equality
In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury. Totally in Berland there are n citizens, the welfare of each of them is estimated as the integer in ai burles (burle is the currency in Berland). ...
The first line contains the integer n (1 ≤ n ≤ 100) — the number of citizens in the kingdom. The second line contains n integers a1, a2, ..., an, where ai (0 ≤ ai ≤ 106) — the welfare of the i-th citizen.
In the only line print the integer S — the minimum number of burles which are had to spend.
null
In the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4. In the second example it is enough to give one burle to the third citizen. In the third example it is necessary to give two burles to the first and the thir...
[{"input": "5\n0 1 2 3 4", "output": "10"}, {"input": "5\n1 1 0 1 1", "output": "1"}, {"input": "3\n1 3 1", "output": "4"}, {"input": "1\n12", "output": "0"}]
800
["implementation", "math"]
41
[{"input": "5\r\n0 1 2 3 4\r\n", "output": "10"}, {"input": "5\r\n1 1 0 1 1\r\n", "output": "1"}, {"input": "3\r\n1 3 1\r\n", "output": "4"}, {"input": "1\r\n12\r\n", "output": "0"}, {"input": "3\r\n1 2 3\r\n", "output": "3"}, {"input": "14\r\n52518 718438 358883 462189 853171 592966 225788 46977 814826 295697 676256 5...
false
stdio
null
true
758/A
758
A
Python 3
TESTS
22
46
0
221266451
n=int(input()) s=input().split(" ") maxm=int(max(s)) s = [int(x) for x in s] a=sum(s) min=0 b=(n*maxm)-a print(b)
41
31
0
158501738
n = int(input()) count = 0 a = list(map(int, input().split())) for i in range(len(a)): maximum = max(a) count += maximum - a[i] print(count)
Codeforces Round 392 (Div. 2)
CF
2,017
1
256
Holiday Of Equality
In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury. Totally in Berland there are n citizens, the welfare of each of them is estimated as the integer in ai burles (burle is the currency in Berland). ...
The first line contains the integer n (1 ≤ n ≤ 100) — the number of citizens in the kingdom. The second line contains n integers a1, a2, ..., an, where ai (0 ≤ ai ≤ 106) — the welfare of the i-th citizen.
In the only line print the integer S — the minimum number of burles which are had to spend.
null
In the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4. In the second example it is enough to give one burle to the third citizen. In the third example it is necessary to give two burles to the first and the thir...
[{"input": "5\n0 1 2 3 4", "output": "10"}, {"input": "5\n1 1 0 1 1", "output": "1"}, {"input": "3\n1 3 1", "output": "4"}, {"input": "1\n12", "output": "0"}]
800
["implementation", "math"]
41
[{"input": "5\r\n0 1 2 3 4\r\n", "output": "10"}, {"input": "5\r\n1 1 0 1 1\r\n", "output": "1"}, {"input": "3\r\n1 3 1\r\n", "output": "4"}, {"input": "1\r\n12\r\n", "output": "0"}, {"input": "3\r\n1 2 3\r\n", "output": "3"}, {"input": "14\r\n52518 718438 358883 462189 853171 592966 225788 46977 814826 295697 676256 5...
false
stdio
null
true
758/A
758
A
Python 3
TESTS
22
46
0
161300244
start=int(input()) z=input() zz=list(z.split()) mac=int(max(zz)) to=0 final=0 for i in range(start): final+=(mac-int(zz[i])) print(final)
41
31
0
161040980
n=int(input()) lst=list(map(int,input().split()))[:n] m=max(lst) s=0 for i in lst: s+=m-i print(s)
Codeforces Round 392 (Div. 2)
CF
2,017
1
256
Holiday Of Equality
In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury. Totally in Berland there are n citizens, the welfare of each of them is estimated as the integer in ai burles (burle is the currency in Berland). ...
The first line contains the integer n (1 ≤ n ≤ 100) — the number of citizens in the kingdom. The second line contains n integers a1, a2, ..., an, where ai (0 ≤ ai ≤ 106) — the welfare of the i-th citizen.
In the only line print the integer S — the minimum number of burles which are had to spend.
null
In the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4. In the second example it is enough to give one burle to the third citizen. In the third example it is necessary to give two burles to the first and the thir...
[{"input": "5\n0 1 2 3 4", "output": "10"}, {"input": "5\n1 1 0 1 1", "output": "1"}, {"input": "3\n1 3 1", "output": "4"}, {"input": "1\n12", "output": "0"}]
800
["implementation", "math"]
41
[{"input": "5\r\n0 1 2 3 4\r\n", "output": "10"}, {"input": "5\r\n1 1 0 1 1\r\n", "output": "1"}, {"input": "3\r\n1 3 1\r\n", "output": "4"}, {"input": "1\r\n12\r\n", "output": "0"}, {"input": "3\r\n1 2 3\r\n", "output": "3"}, {"input": "14\r\n52518 718438 358883 462189 853171 592966 225788 46977 814826 295697 676256 5...
false
stdio
null
true
758/A
758
A
Python 3
TESTS
22
31
0
169186495
cantidad = int(input()) x = input() vector = x.split(" ") if(len(vector) == 1): print("0") else: total = 0 maximo = max(vector) for i in range(0,cantidad): if(vector[i] != maximo): total += abs(int(maximo) - int(vector[i])) print(total)
41
31
0
161422218
n=int(input()) a=list(map(int, input().split())) m,s=max(a),0 for i in a: s+=(m-i) print(s)
Codeforces Round 392 (Div. 2)
CF
2,017
1
256
Holiday Of Equality
In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury. Totally in Berland there are n citizens, the welfare of each of them is estimated as the integer in ai burles (burle is the currency in Berland). ...
The first line contains the integer n (1 ≤ n ≤ 100) — the number of citizens in the kingdom. The second line contains n integers a1, a2, ..., an, where ai (0 ≤ ai ≤ 106) — the welfare of the i-th citizen.
In the only line print the integer S — the minimum number of burles which are had to spend.
null
In the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4. In the second example it is enough to give one burle to the third citizen. In the third example it is necessary to give two burles to the first and the thir...
[{"input": "5\n0 1 2 3 4", "output": "10"}, {"input": "5\n1 1 0 1 1", "output": "1"}, {"input": "3\n1 3 1", "output": "4"}, {"input": "1\n12", "output": "0"}]
800
["implementation", "math"]
41
[{"input": "5\r\n0 1 2 3 4\r\n", "output": "10"}, {"input": "5\r\n1 1 0 1 1\r\n", "output": "1"}, {"input": "3\r\n1 3 1\r\n", "output": "4"}, {"input": "1\r\n12\r\n", "output": "0"}, {"input": "3\r\n1 2 3\r\n", "output": "3"}, {"input": "14\r\n52518 718438 358883 462189 853171 592966 225788 46977 814826 295697 676256 5...
false
stdio
null
true
758/A
758
A
Python 3
TESTS
22
31
0
182717697
n = int(input()) s=0 x = input().split() maxx = max(x) for i in x: s+=abs(int(maxx) - int(i)) print(s)
41
31
0
162167306
num_of_citizens = int(input()) citizen_welfare = list(map(int, input().split())) min_number_of_burles = 0 max_welfare = max(citizen_welfare) if num_of_citizens <= 1: min_number_of_burles = 0 else: for val in citizen_welfare: if val < max_welfare: min_number_of_burles += max_welfare - val pr...
Codeforces Round 392 (Div. 2)
CF
2,017
1
256
Holiday Of Equality
In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury. Totally in Berland there are n citizens, the welfare of each of them is estimated as the integer in ai burles (burle is the currency in Berland). ...
The first line contains the integer n (1 ≤ n ≤ 100) — the number of citizens in the kingdom. The second line contains n integers a1, a2, ..., an, where ai (0 ≤ ai ≤ 106) — the welfare of the i-th citizen.
In the only line print the integer S — the minimum number of burles which are had to spend.
null
In the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4. In the second example it is enough to give one burle to the third citizen. In the third example it is necessary to give two burles to the first and the thir...
[{"input": "5\n0 1 2 3 4", "output": "10"}, {"input": "5\n1 1 0 1 1", "output": "1"}, {"input": "3\n1 3 1", "output": "4"}, {"input": "1\n12", "output": "0"}]
800
["implementation", "math"]
41
[{"input": "5\r\n0 1 2 3 4\r\n", "output": "10"}, {"input": "5\r\n1 1 0 1 1\r\n", "output": "1"}, {"input": "3\r\n1 3 1\r\n", "output": "4"}, {"input": "1\r\n12\r\n", "output": "0"}, {"input": "3\r\n1 2 3\r\n", "output": "3"}, {"input": "14\r\n52518 718438 358883 462189 853171 592966 225788 46977 814826 295697 676256 5...
false
stdio
null
true
758/A
758
A
Python 3
TESTS
22
31
0
198032861
import math # Declarations & conversions n = int(input()) a = input() list = list(a.split(" ")) maxA = int(max(list)) maxB = (-abs(maxA)) res = [eval(i) for i in list] # Computation for i in range(n): res[i] = res[i] + maxB resUp = [int(math.fabs(ele)) for ele in res] # Final sum print(sum(resUp))
41
31
0
168489043
a=int(input()) b=input() c=b.split() d=0 maxi=0 for i in range(len(c)): c[i]=int(c[i]) maxi=max(maxi,c[i]) for n in range(len(c)): c[n]=int(c[n]) d+=maxi-c[n] print(d)
Codeforces Round 392 (Div. 2)
CF
2,017
1
256
Holiday Of Equality
In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury. Totally in Berland there are n citizens, the welfare of each of them is estimated as the integer in ai burles (burle is the currency in Berland). ...
The first line contains the integer n (1 ≤ n ≤ 100) — the number of citizens in the kingdom. The second line contains n integers a1, a2, ..., an, where ai (0 ≤ ai ≤ 106) — the welfare of the i-th citizen.
In the only line print the integer S — the minimum number of burles which are had to spend.
null
In the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4. In the second example it is enough to give one burle to the third citizen. In the third example it is necessary to give two burles to the first and the thir...
[{"input": "5\n0 1 2 3 4", "output": "10"}, {"input": "5\n1 1 0 1 1", "output": "1"}, {"input": "3\n1 3 1", "output": "4"}, {"input": "1\n12", "output": "0"}]
800
["implementation", "math"]
41
[{"input": "5\r\n0 1 2 3 4\r\n", "output": "10"}, {"input": "5\r\n1 1 0 1 1\r\n", "output": "1"}, {"input": "3\r\n1 3 1\r\n", "output": "4"}, {"input": "1\r\n12\r\n", "output": "0"}, {"input": "3\r\n1 2 3\r\n", "output": "3"}, {"input": "14\r\n52518 718438 358883 462189 853171 592966 225788 46977 814826 295697 676256 5...
false
stdio
null
true
356/C
356
C
Python 3
TESTS
1
77
307,200
92567004
n = input() A = [int(i) for i in input().split()] move_time = 0 for i in range(len(A)): for j in range(i+1,len(A)): if A[i] == 1: if A[j] == 2: A[i] = 0 A[j] = 3 move_time += 1 break elif A[j] == 3 and 2 not in A: ...
141
607
14,745,600
42135284
#! /usr/bin/env python n = int(input()) counts = [0] * 5 nums = [int(x) for x in input().split()] for x in nums: counts[x] += 1 s = sum(nums) if s > 2 and s != 5: ans = 0 if counts[1] >= counts[2]: ans += counts[2] counts[3] += counts[2] counts[1] -= counts[2] ans += 2 * (c...
Codeforces Round 207 (Div. 1)
CF
2,013
1
256
Compartments
A team of students from the city S is sent to the All-Berland Olympiad in Informatics. Traditionally, they go on the train. All students have bought tickets in one carriage, consisting of n compartments (each compartment has exactly four people). We know that if one compartment contain one or two students, then they ge...
The first line contains integer n (1 ≤ n ≤ 106) — the number of compartments in the carriage. The second line contains n integers a1, a2, ..., an showing how many students ride in each compartment (0 ≤ ai ≤ 4). It is guaranteed that at least one student is riding in the train.
If no sequence of swapping seats with other people leads to the desired result, print number "-1" (without the quotes). In another case, print the smallest number of people you need to persuade to swap places.
null
null
[{"input": "5\n1 2 2 4 3", "output": "2"}, {"input": "3\n4 1 1", "output": "2"}, {"input": "4\n0 3 0 4", "output": "0"}]
2,100
["combinatorics", "constructive algorithms", "greedy", "implementation"]
141
[{"input": "5\r\n1 2 2 4 3\r\n", "output": "2\r\n"}, {"input": "3\r\n4 1 1\r\n", "output": "2\r\n"}, {"input": "4\r\n0 3 0 4\r\n", "output": "0\r\n"}, {"input": "5\r\n4 4 3 3 1\r\n", "output": "1\r\n"}, {"input": "5\r\n4 3 4 2 4\r\n", "output": "1\r\n"}, {"input": "10\r\n2 1 2 3 4 1 3 4 4 4\r\n", "output": "2\r\n"}, {"...
false
stdio
null
true
758/A
758
A
Python 3
TESTS
22
46
0
201147366
n = int(input()) ni = input().split() maximum = int(max(ni)) sum = 0 for i in ni: if int(i) < maximum: sum += maximum - int(i) print(sum)
41
31
0
170444973
z = int(input()) y = input() x = y.split() w = 0 ma = 0 for i in range(len(x)): x[i] = int(x[i]) ma = max(ma, x[i]) for j in range(len(x)): x[j] = int(x[j]) w += ma - x[j] print(w)
Codeforces Round 392 (Div. 2)
CF
2,017
1
256
Holiday Of Equality
In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury. Totally in Berland there are n citizens, the welfare of each of them is estimated as the integer in ai burles (burle is the currency in Berland). ...
The first line contains the integer n (1 ≤ n ≤ 100) — the number of citizens in the kingdom. The second line contains n integers a1, a2, ..., an, where ai (0 ≤ ai ≤ 106) — the welfare of the i-th citizen.
In the only line print the integer S — the minimum number of burles which are had to spend.
null
In the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4. In the second example it is enough to give one burle to the third citizen. In the third example it is necessary to give two burles to the first and the thir...
[{"input": "5\n0 1 2 3 4", "output": "10"}, {"input": "5\n1 1 0 1 1", "output": "1"}, {"input": "3\n1 3 1", "output": "4"}, {"input": "1\n12", "output": "0"}]
800
["implementation", "math"]
41
[{"input": "5\r\n0 1 2 3 4\r\n", "output": "10"}, {"input": "5\r\n1 1 0 1 1\r\n", "output": "1"}, {"input": "3\r\n1 3 1\r\n", "output": "4"}, {"input": "1\r\n12\r\n", "output": "0"}, {"input": "3\r\n1 2 3\r\n", "output": "3"}, {"input": "14\r\n52518 718438 358883 462189 853171 592966 225788 46977 814826 295697 676256 5...
false
stdio
null
true
758/A
758
A
Python 3
TESTS
22
46
0
201214701
n=int(input()) a=input().split() count=0 for j in a: count+=int(max(a))-int(j) print(count)
41
31
0
172639825
f = input() x = input().split() y = 0 for i in x: if int(i) > y: y = int(i) g = 0 for i in x: g += y - int(i) print(g)
Codeforces Round 392 (Div. 2)
CF
2,017
1
256
Holiday Of Equality
In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury. Totally in Berland there are n citizens, the welfare of each of them is estimated as the integer in ai burles (burle is the currency in Berland). ...
The first line contains the integer n (1 ≤ n ≤ 100) — the number of citizens in the kingdom. The second line contains n integers a1, a2, ..., an, where ai (0 ≤ ai ≤ 106) — the welfare of the i-th citizen.
In the only line print the integer S — the minimum number of burles which are had to spend.
null
In the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4. In the second example it is enough to give one burle to the third citizen. In the third example it is necessary to give two burles to the first and the thir...
[{"input": "5\n0 1 2 3 4", "output": "10"}, {"input": "5\n1 1 0 1 1", "output": "1"}, {"input": "3\n1 3 1", "output": "4"}, {"input": "1\n12", "output": "0"}]
800
["implementation", "math"]
41
[{"input": "5\r\n0 1 2 3 4\r\n", "output": "10"}, {"input": "5\r\n1 1 0 1 1\r\n", "output": "1"}, {"input": "3\r\n1 3 1\r\n", "output": "4"}, {"input": "1\r\n12\r\n", "output": "0"}, {"input": "3\r\n1 2 3\r\n", "output": "3"}, {"input": "14\r\n52518 718438 358883 462189 853171 592966 225788 46977 814826 295697 676256 5...
false
stdio
null
true
758/A
758
A
Python 3
TESTS
22
46
0
199889967
n=int(input()) a=input().split() maxi=int(max(a)) babki=0 for i in a: if int(i) < maxi: babki=babki+(maxi-int(i)) print(babki)
41
31
0
189196276
n = int(input()) arr = list(map(int, input().split())) mmax = max(arr) print(sum([mmax - i for i in arr]))
Codeforces Round 392 (Div. 2)
CF
2,017
1
256
Holiday Of Equality
In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury. Totally in Berland there are n citizens, the welfare of each of them is estimated as the integer in ai burles (burle is the currency in Berland). ...
The first line contains the integer n (1 ≤ n ≤ 100) — the number of citizens in the kingdom. The second line contains n integers a1, a2, ..., an, where ai (0 ≤ ai ≤ 106) — the welfare of the i-th citizen.
In the only line print the integer S — the minimum number of burles which are had to spend.
null
In the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4. In the second example it is enough to give one burle to the third citizen. In the third example it is necessary to give two burles to the first and the thir...
[{"input": "5\n0 1 2 3 4", "output": "10"}, {"input": "5\n1 1 0 1 1", "output": "1"}, {"input": "3\n1 3 1", "output": "4"}, {"input": "1\n12", "output": "0"}]
800
["implementation", "math"]
41
[{"input": "5\r\n0 1 2 3 4\r\n", "output": "10"}, {"input": "5\r\n1 1 0 1 1\r\n", "output": "1"}, {"input": "3\r\n1 3 1\r\n", "output": "4"}, {"input": "1\r\n12\r\n", "output": "0"}, {"input": "3\r\n1 2 3\r\n", "output": "3"}, {"input": "14\r\n52518 718438 358883 462189 853171 592966 225788 46977 814826 295697 676256 5...
false
stdio
null
true
508/B
508
B
Python 3
TESTS
9
78
1,228,800
179084302
x = input() l = [] k = 0 for i in x: if int(i)%2 == 0: l.append(i) k +=1 else: k += 0 h = x[::-1] b = list(x) lock = [] pack = [] if k>=1: if max(l)>x[-1]: c = min(l) m = x.index(c) b[-1],b[m] = b[m],b[-1] ib = "".join(b) lock.append(ib) b[-1],b[m] = b[m],b[-1] g = h.index(c)#rev min b[-1],b[-g...
58
61
2,150,400
188035819
# меняем последнюю цифру # если не найдём ни одно чётное число, то выводим -1 # идём слева направо # если чётное число хотя бы на единицу меньше, то сразу меняем # если нет чётных чисел, меньших нашего, то ищем самое правое чётное число, # чтобы изменение на меньшее не сделало больших изменений в сумме цифр string = ...
Codeforces Round 288 (Div. 2)
CF
2,015
0.5
256
Anton and currency you all know
Berland, 2016. The exchange rate of currency you all know against the burle has increased so much that to simplify the calculations, its fractional part was neglected and the exchange rate is now assumed to be an integer. Reliable sources have informed the financier Anton of some information about the exchange rate of...
The first line contains an odd positive integer n — the exchange rate of currency you all know for today. The length of number n's representation is within range from 2 to 105, inclusive. The representation of n doesn't contain any leading zeroes.
If the information about tomorrow's exchange rate is inconsistent, that is, there is no integer that meets the condition, print - 1. Otherwise, print the exchange rate of currency you all know against the burle for tomorrow. This should be the maximum possible number of those that are even and that are obtained from ...
null
null
[{"input": "527", "output": "572"}, {"input": "4573", "output": "3574"}, {"input": "1357997531", "output": "-1"}]
1,300
["greedy", "math", "strings"]
58
[{"input": "527\r\n", "output": "572\r\n"}, {"input": "4573\r\n", "output": "3574\r\n"}, {"input": "1357997531\r\n", "output": "-1\r\n"}, {"input": "444443\r\n", "output": "444434\r\n"}, {"input": "22227\r\n", "output": "72222\r\n"}, {"input": "24683\r\n", "output": "34682\r\n"}, {"input": "11\r\n", "output": "-1\r\n"}...
false
stdio
null
true
626/E
626
E
PyPy 3
TESTS
6
248
15,974,400
146556376
n=int(input()) a=list(map(int, input().split())) a.sort() cur=[] pref=0 mx=0 s=a[-1] for i in range(n-1): cur.append(a[i]) s+=a[i] if len(cur)%2==0: med=cur[(len(cur)+1)//2] elif len(cur)>1: med = cur[(len(cur)+1)//2]/2+cur[(len(cur)+1)//2-1]/2 else: med = (cur[0]+a[-1])/2 ...
94
311
27,033,600
221423938
def fans(p, q): tans = sum[n] - sum[n - q] + sum[p + 1] - sum[p - q] tans -= x[p] * (2 * q + 1) return tans n = int(input()) x = list(map(int, input().split())) x.sort() sum = [0] * (n + 1) ans = -1 ansp = 0 ansq = 0 for i in range(n): sum[i + 1] = sum[i] + x[i] for i in range(n): k = 0 for j in...
8VC Venture Cup 2016 - Elimination Round
CF
2,016
3
256
Simple Skewness
Define the simple skewness of a collection of numbers to be the collection's mean minus its median. You are given a list of n (not necessarily distinct) integers. Find the non-empty subset (with repetition) with the maximum simple skewness. The mean of a collection is the average of its elements. The median of a colle...
The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of elements in the list. The second line contains n integers xi (0 ≤ xi ≤ 1 000 000) — the ith element of the list.
In the first line, print a single integer k — the size of the subset. In the second line, print k integers — the elements of the subset in any order. If there are multiple optimal subsets, print any.
null
In the first case, the optimal subset is $${ \{ 1, 2, 1 2 \} }$$, which has mean 5, median 2, and simple skewness of 5 - 2 = 3. In the second case, the optimal subset is $${ \{ 1, 1, 2 \} }$$. Note that repetition is allowed. In the last case, any subset has the same median and mean, so all have simple skewness of 0.
[{"input": "4\n1 2 3 12", "output": "3\n1 2 12"}, {"input": "4\n1 1 2 2", "output": "3\n1 1 2"}, {"input": "2\n1 2", "output": "2\n1 2"}]
2,400
["binary search", "math", "ternary search"]
94
[{"input": "4\r\n1 2 3 12\r\n", "output": "3\r\n1 2 12 \r\n"}, {"input": "4\r\n1 1 2 2\r\n", "output": "3\r\n1 1 2 \r\n"}, {"input": "2\r\n1 2\r\n", "output": "2\r\n1 2\r\n"}, {"input": "1\r\n1000000\r\n", "output": "1\r\n1000000 \r\n"}, {"input": "20\r\n999999 999998 999996 999992 999984 999968 999936 999872 999744 99...
false
stdio
import sys def read_file(path): with open(path, 'r') as f: lines = f.readlines() return [line.strip() for line in lines] def compute_skewness(subset): sorted_subset = sorted(subset) k = len(sorted_subset) if k == 0: return None total = sum(sorted_subset) mean = total / k ...
true
351/A
351
A
Python 3
TESTS
9
154
5,632,000
34803799
n = int(input()) l = list(map(float, input().split())) l = sorted([x - int(x) for x in l if x - int(x) != 0]) su = sum(l) ans = 111111111111111111 for i in range(min(n, len(l) - 1) + 1): ans = min(ans, abs(i-su)) print("%.3f" % ans)
63
156
307,200
5341193
n, t = int(input()), [int(i[-3: ]) for i in input().split()] k, s = t.count(0), sum(t) c = s // 1000 + int(s % 1000 > 500) a, b = max(0, n - k), min(2 * n - k, n) if a <= c <= b: s = abs(c * 1000 - s) else: s = min(abs(a * 1000 - s), abs(b * 1000 - s)) print(str(s // 1000) + '.' + str(s % 1000).zfill(3))
Codeforces Round 204 (Div. 1)
CF
2,013
1
256
Jeff and Rounding
Jeff got 2n real numbers a1, a2, ..., a2n as a birthday present. The boy hates non-integer numbers, so he decided to slightly "adjust" the numbers he's got. Namely, Jeff consecutively executes n operations, each of them goes as follows: - choose indexes i and j (i ≠ j) that haven't been chosen yet; - round element ai ...
The first line contains integer n (1 ≤ n ≤ 2000). The next line contains 2n real numbers a1, a2, ..., a2n (0 ≤ ai ≤ 10000), given with exactly three digits after the decimal point. The numbers are separated by spaces.
In a single line print a single real number — the required difference with exactly three digits after the decimal point.
null
In the first test case you need to perform the operations as follows: (i = 1, j = 4), (i = 2, j = 3), (i = 5, j = 6). In this case, the difference will equal |(0 + 0.5 + 0.75 + 1 + 2 + 3) - (0 + 0 + 1 + 1 + 2 + 3)| = 0.25.
[{"input": "3\n0.000 0.500 0.750 1.000 2.000 3.000", "output": "0.250"}, {"input": "3\n4469.000 6526.000 4864.000 9356.383 7490.000 995.896", "output": "0.279"}]
1,800
["dp", "greedy", "implementation", "math"]
63
[{"input": "3\r\n0.000 0.500 0.750 1.000 2.000 3.000\r\n", "output": "0.250\r\n"}, {"input": "3\r\n4469.000 6526.000 4864.000 9356.383 7490.000 995.896\r\n", "output": "0.279\r\n"}, {"input": "3\r\n673.674 9263.142 6780.000 9801.000 4640.000 8244.000\r\n", "output": "0.184\r\n"}, {"input": "3\r\n6470.649 8295.000 8486....
false
stdio
null
true
908/B
908
B
PyPy 3-64
TESTS
3
31
512,000
156554825
n, m = map(int, input().split()) maze = [input() for x in range(n)] order = input() import itertools dirs = ['D', 'L', 'U', 'R'] possible = list(itertools.permutations(dirs)) #print(possible) robotLoc = tuple() exitLoc = tuple() for r in range(len(maze)): for c in range(len(maze[0])): if (maze[r][c] == 'S...
46
61
0
138790917
from itertools import permutations d = [[0, 1], [0, -1], [1, 0], [-1, 0]] n, m = map(int, input().split()) matrix = [] for i in range(n): matrix.append(input()) x0, y0, x1, y1 = 0, 0, 0, 0 for i in range(n): for j in range(m): if matrix[i][j] == 'S': x0, y0 = i, j if matrix[i][j] == ...
Good Bye 2017
CF
2,017
1
256
New Year and Buggy Bot
Bob programmed a robot to navigate through a 2d maze. The maze has some obstacles. Empty cells are denoted by the character '.', where obstacles are denoted by '#'. There is a single robot in the maze. Its start position is denoted with the character 'S'. This position has no obstacle in it. There is also a single ex...
The first line of input will contain two integers n and m (2 ≤ n, m ≤ 50), denoting the dimensions of the maze. The next n lines will contain exactly m characters each, denoting the maze. Each character of the maze will be '.', '#', 'S', or 'E'. There will be exactly one 'S' and exactly one 'E' in the maze. The las...
Print a single integer, the number of mappings of digits to directions that will lead the robot to the exit.
null
For the first sample, the only valid mapping is $$0 \rightarrow D, 1 \rightarrow L, 2 \rightarrow U, 3 \rightarrow R$$, where D is down, L is left, U is up, R is right.
[{"input": "5 6\n.....#\nS....#\n.#....\n.#....\n...E..\n333300012", "output": "1"}, {"input": "6 6\n......\n......\n..SE..\n......\n......\n......\n01232123212302123021", "output": "14"}, {"input": "5 3\n...\n.S.\n###\n.E.\n...\n3", "output": "0"}]
1,200
["brute force", "implementation"]
46
[{"input": "5 6\r\n.....#\r\nS....#\r\n.#....\r\n.#....\r\n...E..\r\n333300012\r\n", "output": "1\r\n"}, {"input": "6 6\r\n......\r\n......\r\n..SE..\r\n......\r\n......\r\n......\r\n01232123212302123021\r\n", "output": "14\r\n"}, {"input": "5 3\r\n...\r\n.S.\r\n###\r\n.E.\r\n...\r\n3\r\n", "output": "0\r\n"}, {"input"...
false
stdio
null
true
247/A
250
A
PyPy 3-64
TESTS
11
154
0
146276066
def main(): n = int(input()) arr = list(map(int, input().split())) counter = 0 total_counter_arr = [] for index, value in enumerate(arr): if value < 0: counter += 1 if counter == 3 or index == n - 1: counter = 1 s = sum(total_counter_arr) ...
69
92
0
160149194
def paperuork(): n = int(input()) relatorios = list(map(int,input().split())) n_negative = 0 n_relatorios_in_folder = 0 sekuence = [] for r in relatorios: if(n_negative==2): if(r<0): sekuence.append(n_relatorios_in_folder) n_relatorios_in_folder = 1 n_negative = 1 e...
CROC-MBTU 2012, Final Round
CF
2,012
2
256
Paper Work
Polycarpus has been working in the analytic department of the "F.R.A.U.D." company for as much as n days. Right now his task is to make a series of reports about the company's performance for the last n days. We know that the main information in a day report is value ai, the company's profit on the i-th day. If ai is n...
The first line contains integer n (1 ≤ n ≤ 100), n is the number of days. The second line contains a sequence of integers a1, a2, ..., an (|ai| ≤ 100), where ai means the company profit on the i-th day. It is possible that the company has no days with the negative ai.
Print an integer k — the required minimum number of folders. In the second line print a sequence of integers b1, b2, ..., bk, where bj is the number of day reports in the j-th folder. If there are multiple ways to sort the reports into k days, print any of them.
null
Here goes a way to sort the reports from the first sample into three folders: 1 2 3 -4 -5 | -6 5 -5 | -6 -7 6 In the second sample you can put all five reports in one folder.
[{"input": "11\n1 2 3 -4 -5 -6 5 -5 -6 -7 6", "output": "3\n5 3 3"}, {"input": "5\n0 -1 100 -1 0", "output": "1\n5"}]
1,000
[]
69
[{"input": "11\r\n1 2 3 -4 -5 -6 5 -5 -6 -7 6\r\n", "output": "3\r\n5 3 3 "}, {"input": "5\r\n0 -1 100 -1 0\r\n", "output": "1\r\n5 "}, {"input": "1\r\n0\r\n", "output": "1\r\n1 "}, {"input": "1\r\n-1\r\n", "output": "1\r\n1 "}, {"input": "2\r\n0 0\r\n", "output": "1\r\n2 "}, {"input": "2\r\n-2 2\r\n", "output": "1\r\n...
false
stdio
import sys def read_input(input_path): with open(input_path) as f: n = int(f.readline()) a = list(map(int, f.readline().split())) return n, a def compute_min_k(n, a): if n == 0: return 0 folders = 0 current_neg = 0 current_size = 0 for ai in a: current_s...
true
247/A
250
A
Python 3
TESTS
11
124
0
30080810
#from dust i have come dust i will be import sys n=int(input()) a=list(map(int,input().split())) f=[] s=0;j=0 for i in range(n): if a[i]<0: s+=1 if s==3: f.append(i-j) j+=(i-j);s=1 continue if i==n-1: f.append(i-j+1) print(len(f)) for i in range(len(f)): sy...
69
92
0
160198472
n = int(input()) profit = [int(i) for i in input().split()] foldersContent = [] countDays=0 countLosses=0 for i in profit: countDays+=1 if(i<0): countLosses+=1 if(countLosses==3): foldersContent.append(countDays-1) countDays=1 countLosses=1 foldersContent.append(countDays) print(len(folde...
CROC-MBTU 2012, Final Round
CF
2,012
2
256
Paper Work
Polycarpus has been working in the analytic department of the "F.R.A.U.D." company for as much as n days. Right now his task is to make a series of reports about the company's performance for the last n days. We know that the main information in a day report is value ai, the company's profit on the i-th day. If ai is n...
The first line contains integer n (1 ≤ n ≤ 100), n is the number of days. The second line contains a sequence of integers a1, a2, ..., an (|ai| ≤ 100), where ai means the company profit on the i-th day. It is possible that the company has no days with the negative ai.
Print an integer k — the required minimum number of folders. In the second line print a sequence of integers b1, b2, ..., bk, where bj is the number of day reports in the j-th folder. If there are multiple ways to sort the reports into k days, print any of them.
null
Here goes a way to sort the reports from the first sample into three folders: 1 2 3 -4 -5 | -6 5 -5 | -6 -7 6 In the second sample you can put all five reports in one folder.
[{"input": "11\n1 2 3 -4 -5 -6 5 -5 -6 -7 6", "output": "3\n5 3 3"}, {"input": "5\n0 -1 100 -1 0", "output": "1\n5"}]
1,000
[]
69
[{"input": "11\r\n1 2 3 -4 -5 -6 5 -5 -6 -7 6\r\n", "output": "3\r\n5 3 3 "}, {"input": "5\r\n0 -1 100 -1 0\r\n", "output": "1\r\n5 "}, {"input": "1\r\n0\r\n", "output": "1\r\n1 "}, {"input": "1\r\n-1\r\n", "output": "1\r\n1 "}, {"input": "2\r\n0 0\r\n", "output": "1\r\n2 "}, {"input": "2\r\n-2 2\r\n", "output": "1\r\n...
false
stdio
import sys def read_input(input_path): with open(input_path) as f: n = int(f.readline()) a = list(map(int, f.readline().split())) return n, a def compute_min_k(n, a): if n == 0: return 0 folders = 0 current_neg = 0 current_size = 0 for ai in a: current_s...
true
626/E
626
E
Python 3
TESTS
7
966
13,926,400
191358126
n = int(input()) a = sorted(list(map(int,input().split()))) s = [0] + a for i in range(1, len(s)): s[i] += s[i-1] def skew(x): m = n-x avg = (s[m-m//2] + s[-1] - s[m-m//2+x]) / m if m&1: med = s[m-m//2] - s[m-m//2-1] else: med = (s[m-m//2] - s[m-m//2-1] + s[m-m//2+x+1] - s[m-m//2+x]...
94
343
27,033,600
217897255
def CalcMean(n,a,c,median,k): if k==0: return a[median] s = c[median+1] - c[median-k] + c[n] - c[n-k] return s/(2*k+1) n=int(input()) a=list(map(int,input().split())) a.sort() c=[0] for i in range(n): c.append(c[-1]+a[i]) ans=optMed=optK=0 for median in range(n): L=0 R=min(median,n-median-1) ...
8VC Venture Cup 2016 - Elimination Round
CF
2,016
3
256
Simple Skewness
Define the simple skewness of a collection of numbers to be the collection's mean minus its median. You are given a list of n (not necessarily distinct) integers. Find the non-empty subset (with repetition) with the maximum simple skewness. The mean of a collection is the average of its elements. The median of a colle...
The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of elements in the list. The second line contains n integers xi (0 ≤ xi ≤ 1 000 000) — the ith element of the list.
In the first line, print a single integer k — the size of the subset. In the second line, print k integers — the elements of the subset in any order. If there are multiple optimal subsets, print any.
null
In the first case, the optimal subset is $${ \{ 1, 2, 1 2 \} }$$, which has mean 5, median 2, and simple skewness of 5 - 2 = 3. In the second case, the optimal subset is $${ \{ 1, 1, 2 \} }$$. Note that repetition is allowed. In the last case, any subset has the same median and mean, so all have simple skewness of 0.
[{"input": "4\n1 2 3 12", "output": "3\n1 2 12"}, {"input": "4\n1 1 2 2", "output": "3\n1 1 2"}, {"input": "2\n1 2", "output": "2\n1 2"}]
2,400
["binary search", "math", "ternary search"]
94
[{"input": "4\r\n1 2 3 12\r\n", "output": "3\r\n1 2 12 \r\n"}, {"input": "4\r\n1 1 2 2\r\n", "output": "3\r\n1 1 2 \r\n"}, {"input": "2\r\n1 2\r\n", "output": "2\r\n1 2\r\n"}, {"input": "1\r\n1000000\r\n", "output": "1\r\n1000000 \r\n"}, {"input": "20\r\n999999 999998 999996 999992 999984 999968 999936 999872 999744 99...
false
stdio
import sys def read_file(path): with open(path, 'r') as f: lines = f.readlines() return [line.strip() for line in lines] def compute_skewness(subset): sorted_subset = sorted(subset) k = len(sorted_subset) if k == 0: return None total = sum(sorted_subset) mean = total / k ...
true
101/B
101
B
PyPy 3-64
TESTS
7
154
102,400
197495436
# ﷽ from bisect import bisect, bisect_left, bisect_right from collections import defaultdict, deque import sys input = lambda: sys.stdin.readline().strip() def solve(): n,m=[int(i) for i in input().split()] d=defaultdict(list) for _ in range(m): u,v=[int(i) for i in input().split()] d[v].ap...
85
1,778
49,971,200
154280537
from bisect import bisect_left from collections import defaultdict d=defaultdict(list) n,m=map(int,input().split()) bus=[] seen=set() for i in range(m): a,b=map(int,input().split()) d[b].append(a) seen.add(b) seen.add(a) seen=sorted(seen) if n not in seen: print(0) else : sum=[0] for el in...
Codeforces Beta Round 79 (Div. 1 Only)
CF
2,011
2
265
Buses
Little boy Gerald studies at school which is quite far from his house. That's why he has to go there by bus every day. The way from home to school is represented by a segment of a straight line; the segment contains exactly n + 1 bus stops. All of them are numbered with integers from 0 to n in the order in which they f...
The first line contains two space-separated integers: n and m (1 ≤ n ≤ 109, 0 ≤ m ≤ 105). Then follow m lines each containing two integers si, ti. They are the numbers of starting stops and end stops of the buses (0 ≤ si < ti ≤ n).
Print the only number — the number of ways to get to the school modulo 1000000007 (109 + 7).
null
The first test has the only variant to get to school: first on bus number one to the bus stop number one; then on bus number two to the bus stop number two. In the second test no bus goes to the third bus stop, where the school is positioned. Thus, the correct answer is 0. In the third test Gerald can either get or n...
[{"input": "2 2\n0 1\n1 2", "output": "1"}, {"input": "3 2\n0 1\n1 2", "output": "0"}, {"input": "5 5\n0 1\n0 2\n0 3\n0 4\n0 5", "output": "16"}]
1,700
["binary search", "data structures", "dp"]
85
[{"input": "2 2\r\n0 1\r\n1 2\r\n", "output": "1\r\n"}, {"input": "3 2\r\n0 1\r\n1 2\r\n", "output": "0\r\n"}, {"input": "5 5\r\n0 1\r\n0 2\r\n0 3\r\n0 4\r\n0 5\r\n", "output": "16\r\n"}, {"input": "3 3\r\n1 2\r\n2 3\r\n1 3\r\n", "output": "0\r\n"}, {"input": "10 10\r\n0 1\r\n0 2\r\n0 3\r\n0 4\r\n0 5\r\n0 6\r\n0 7\r\n0...
false
stdio
null
true
370/C
370
C
PyPy 3-64
TESTS
65
140
9,830,400
175454936
import sys input = sys.stdin.buffer.readline import heapq def process(A, m): n = len(A) counts = [0 for i in range(m)] for i in range(n): ai = A[i] counts[ai-1]+=1 H = [] for i in range(m): if counts[i] > 0: heapq.heappush(H, [-1*counts[i], i+1]) answer = []...
82
62
614,400
5500625
n, m = map(int, input().split()) p = [0] * (m + 1) for i in map(int, input().split()): p[i] += 1 r, q = [], sorted((p[i], i) for i in range(1, m + 1)) k = q[m - 1][0] print(n - max(2 * k - n, 0)) for i in q: r.extend([str(i[1])] * i[0]) print('\n'.join(i + ' ' + j for i, j in zip(*(r, r[k: ] + r[: k]))))
Codeforces Round 217 (Div. 2)
CF
2,013
1
256
Mittens
A Christmas party in city S. had n children. All children came in mittens. The mittens can be of different colors, but each child had the left and the right mitten of the same color. Let's say that the colors of the mittens are numbered with integers from 1 to m, and the children are numbered from 1 to n. Then the i-th...
The first line contains two integers n and m — the number of the children and the number of possible mitten colors (1 ≤ n ≤ 5000, 1 ≤ m ≤ 100). The second line contains n integers c1, c2, ... cn, where ci is the color of the mittens of the i-th child (1 ≤ ci ≤ m).
In the first line, print the maximum number of children who can end up with a distinct-colored pair of mittens. In the next n lines print the way the mittens can be distributed in this case. On the i-th of these lines print two space-separated integers: the color of the left and the color of the right mitten the i-th c...
null
null
[{"input": "6 3\n1 3 2 2 1 1", "output": "6\n2 1\n1 2\n2 1\n1 3\n1 2\n3 1"}, {"input": "4 2\n1 2 1 1", "output": "2\n1 2\n1 1\n2 1\n1 1"}]
1,800
["constructive algorithms", "greedy", "sortings"]
82
[{"input": "6 3\r\n1 3 2 2 1 1\r\n", "output": "6\r\n2 1\r\n1 2\r\n2 1\r\n1 3\r\n1 2\r\n3 1\r\n"}, {"input": "4 2\r\n1 2 1 1\r\n", "output": "2\r\n1 2\r\n1 1\r\n2 1\r\n1 1\r\n"}, {"input": "1 1\r\n1\r\n", "output": "0\r\n1 1\r\n"}, {"input": "4 1\r\n1 1 1 1\r\n", "output": "0\r\n1 1\r\n1 1\r\n1 1\r\n1 1\r\n"}, {"input"...
false
stdio
import sys from collections import Counter def main(): input_path = sys.argv[1] ref_output_path = sys.argv[2] sub_output_path = sys.argv[3] # Read input with open(input_path, 'r') as f: n, m = map(int, f.readline().split()) c = list(map(int, f.readline().split())) # Read r...
true
1000/A
1000
A
PyPy 3-64
TESTS
9
61
0
165880738
n=int(input());arr=[0]*5;arr1=[0]*5;m=0;S=0;count=0 for e in range(n): s=str(input()) if s=='M':m+=1 elif s=='S':S+=1 elif s.__contains__('S'):arr[len(s)]+=1 else :arr1[len(s)]+=1 for e in range(n): s=str(input()) if s=='M': if m>0:m-=1 else :S-=1;count+=1 elif s=='S': ...
37
31
0
205156831
n=int(input()) a=[*(input()for _ in[0]*n)] for _ in[0]*n: try:a.remove(input()) except:pass print(len(a))
Educational Codeforces Round 46 (Rated for Div. 2)
ICPC
2,018
2
256
Codehorses T-shirts
Codehorses has just hosted the second Codehorses Cup. This year, the same as the previous one, organizers are giving T-shirts for the winners. The valid sizes of T-shirts are either "M" or from $$$0$$$ to $$$3$$$ "X" followed by "S" or "L". For example, sizes "M", "XXS", "L", "XXXL" are valid and "XM", "Z", "XXXXL" ar...
The first line contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the number of T-shirts. The $$$i$$$-th of the next $$$n$$$ lines contains $$$a_i$$$ — the size of the $$$i$$$-th T-shirt of the list for the previous year. The $$$i$$$-th of the next $$$n$$$ lines contains $$$b_i$$$ — the size of the $$$i$$$-th T-s...
Print the minimal number of seconds Ksenia is required to spend to change the last year list to the current one. If the lists are already equal, print 0.
null
In the first example Ksenia can replace "M" with "S" and "S" in one of the occurrences of "XS" with "L". In the second example Ksenia should replace "L" in "XXXL" with "S". In the third example lists are equal.
[{"input": "3\nXS\nXS\nM\nXL\nS\nXS", "output": "2"}, {"input": "2\nXXXL\nXXL\nXXL\nXXXS", "output": "1"}, {"input": "2\nM\nXS\nXS\nM", "output": "0"}]
1,200
["greedy", "implementation"]
37
[{"input": "3\r\nXS\r\nXS\r\nM\r\nXL\r\nS\r\nXS\r\n", "output": "2\r\n"}, {"input": "2\r\nXXXL\r\nXXL\r\nXXL\r\nXXXS\r\n", "output": "1\r\n"}, {"input": "2\r\nM\r\nXS\r\nXS\r\nM\r\n", "output": "0\r\n"}, {"input": "1\r\nXXXL\r\nXXXL\r\n", "output": "0\r\n"}, {"input": "1\r\nM\r\nM\r\n", "output": "0\r\n"}, {"input": "4...
false
stdio
null
true
691/C
691
C
Python 3
TESTS
6
109
307,200
70411264
def count_leading_zeroes(inp, leading=True): tot = 0 search_str = inp if leading else inp[::-1] for char in search_str: if char == '0': tot+=1 else: return tot return tot raw = input() left, dot, right = raw.partition('.') left = left.lstrip('0') right = right.r...
44
61
9,523,200
192587918
from sys import stdin def solve(): s = input() if '.' not in s: s += '.' a, b = s.strip('0').split('.') if len(a): e = len(a) - 1 b = (a[1:] + b).rstrip('0') a = a[0] else: e = -len(b) b = b.lstrip('0') a = b[0] b = b[1:] e +=...
Educational Codeforces Round 14
ICPC
2,016
2
256
Exponential notation
You are given a positive decimal number x. Your task is to convert it to the "simple exponential notation". Let x = a·10b, where 1 ≤ a < 10, then in general case the "simple exponential notation" looks like "aEb". If b equals to zero, the part "Eb" should be skipped. If a is an integer, it should be written without d...
The only line contains the positive decimal number x. The length of the line will not exceed 106. Note that you are given too large number, so you can't use standard built-in data types "float", "double" and other.
Print the only line — the "simple exponential notation" of the given number x.
null
null
[{"input": "16", "output": "1.6E1"}, {"input": "01.23400", "output": "1.234"}, {"input": ".100", "output": "1E-1"}, {"input": "100.", "output": "1E2"}]
1,800
["implementation", "strings"]
44
[{"input": "16\r\n", "output": "1.6E1\r\n"}, {"input": "01.23400\r\n", "output": "1.234\r\n"}, {"input": ".100\r\n", "output": "1E-1\r\n"}, {"input": "100.\r\n", "output": "1E2\r\n"}, {"input": "9000\r\n", "output": "9E3\r\n"}, {"input": "0.0012\r\n", "output": "1.2E-3\r\n"}, {"input": "0001100\r\n", "output": "1.1E3\r...
false
stdio
null
true
352/A
352
A
Python 3
TESTS
20
92
0
192466933
input() a=input() x=a.count('5')//9 y=a.count('0')//5 if x and y: print('5'*(x*9)+'0'*(y*5)) elif x and a.count('0')>0: print('5'*(x*9)+'0') elif '0' in a: print(0) else: print(-1)
42
92
0
4658042
#!/usr/bin/env python n = int(input()) nums = [int(x) for x in input().split()] fives = 0 zeros = 0 for n in nums: if n == 5: fives += 1 elif n == 0: zeros += 1 if (zeros < 1): print(-1) else: actfives = (fives // 9) * 9 if (actfives > 0): print('5' * actfives + '0' * zer...
Codeforces Round 204 (Div. 2)
CF
2,013
1
256
Jeff and Digits
Jeff's got n cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make from the cards he's got? Jeff must make the number without leading zero. At that, we assume that number ...
The first line contains integer n (1 ≤ n ≤ 103). The next line contains n integers a1, a2, ..., an (ai = 0 or ai = 5). Number ai represents the digit that is written on the i-th card.
In a single line print the answer to the problem — the maximum number, divisible by 90. If you can't make any divisible by 90 number from the cards, print -1.
null
In the first test you can make only one number that is a multiple of 90 — 0. In the second test you can make number 5555555550, it is a multiple of 90.
[{"input": "4\n5 0 5 0", "output": "0"}, {"input": "11\n5 5 5 5 5 5 5 5 0 5 5", "output": "5555555550"}]
1,000
["brute force", "implementation", "math"]
42
[{"input": "4\r\n5 0 5 0\r\n", "output": "0\r\n"}, {"input": "11\r\n5 5 5 5 5 5 5 5 0 5 5\r\n", "output": "5555555550\r\n"}, {"input": "7\r\n5 5 5 5 5 5 5\r\n", "output": "-1\r\n"}, {"input": "1\r\n5\r\n", "output": "-1\r\n"}, {"input": "1\r\n0\r\n", "output": "0\r\n"}, {"input": "11\r\n5 0 5 5 5 0 0 5 5 5 5\r\n", "out...
false
stdio
null
true
508/B
508
B
Python 3
TESTS
30
202
13,004,800
206201971
n=list(input()) m=[] for i in range (len(n)): if int(n[i])%2==0: m.append([int(n[i]),i]) if len(m)!=0: change=m[0][1] small=m[0][1] flag=0 for i in range (len(m)): if m[i][0]<int(n[small]): small=m[i][1] elif m[i][0]==int(n[small]) and int(n[-1])<int(n[small]): ...
58
62
204,800
224734776
a=input() k=-1 for i in range(len(a)): if int(a[i])%2==0: if a[i]<a[-1]: k=i break k=i if int(k)>=0: print(a[:k],end='') print(a[-1],end='') print(a[k+1:-1],end='') print(a[k]) else: print(k)
Codeforces Round 288 (Div. 2)
CF
2,015
0.5
256
Anton and currency you all know
Berland, 2016. The exchange rate of currency you all know against the burle has increased so much that to simplify the calculations, its fractional part was neglected and the exchange rate is now assumed to be an integer. Reliable sources have informed the financier Anton of some information about the exchange rate of...
The first line contains an odd positive integer n — the exchange rate of currency you all know for today. The length of number n's representation is within range from 2 to 105, inclusive. The representation of n doesn't contain any leading zeroes.
If the information about tomorrow's exchange rate is inconsistent, that is, there is no integer that meets the condition, print - 1. Otherwise, print the exchange rate of currency you all know against the burle for tomorrow. This should be the maximum possible number of those that are even and that are obtained from ...
null
null
[{"input": "527", "output": "572"}, {"input": "4573", "output": "3574"}, {"input": "1357997531", "output": "-1"}]
1,300
["greedy", "math", "strings"]
58
[{"input": "527\r\n", "output": "572\r\n"}, {"input": "4573\r\n", "output": "3574\r\n"}, {"input": "1357997531\r\n", "output": "-1\r\n"}, {"input": "444443\r\n", "output": "444434\r\n"}, {"input": "22227\r\n", "output": "72222\r\n"}, {"input": "24683\r\n", "output": "34682\r\n"}, {"input": "11\r\n", "output": "-1\r\n"}...
false
stdio
null
true