contestId
int64
0
1.01k
index
stringclasses
40 values
name
stringlengths
2
54
type
stringclasses
2 values
rating
int64
0
3.4k
tags
listlengths
0
7
title
stringclasses
393 values
time-limit
stringclasses
7 values
memory-limit
stringclasses
6 values
problem-description
stringlengths
0
2.97k
input-specification
stringlengths
4
1.87k
output-specification
stringlengths
4
1.12k
demo-input
listlengths
0
7
demo-output
listlengths
0
7
note
stringlengths
0
5.24k
points
float64
0
3.5k
test_cases
listlengths
0
402
creationTimeSeconds
int64
1.37B
1.7B
relativeTimeSeconds
int64
8
2.15B
programmingLanguage
stringclasses
3 values
verdict
stringclasses
1 value
testset
stringclasses
9 values
passedTestCount
int64
1
402
timeConsumedMillis
int64
15
8.06k
memoryConsumedBytes
int64
0
514M
code
stringlengths
11
61.4k
prompt
stringlengths
297
7.35k
response
stringlengths
25
61.4k
score
float64
2.82
3.99
959
A
Mahmoud and Ehab and the even-odd game
PROGRAMMING
800
[ "games", "math" ]
null
null
Mahmoud and Ehab play a game called the even-odd game. Ehab chooses his favorite integer *n* and then they take turns, starting from Mahmoud. In each player's turn, he has to choose an integer *a* and subtract it from *n* such that: - 1<=≀<=*a*<=≀<=*n*. - If it's Mahmoud's turn, *a* has to be even, but if it's Ehab'...
The only line contains an integer *n* (1<=≀<=*n*<=≀<=109), the number at the beginning of the game.
Output "Mahmoud" (without quotes) if Mahmoud wins and "Ehab" (without quotes) otherwise.
[ "1\n", "2\n" ]
[ "Ehab", "Mahmoud" ]
In the first sample, Mahmoud can't choose any integer *a* initially because there is no positive even integer less than or equal to 1 so Ehab wins. In the second sample, Mahmoud has to choose *a* = 2 and subtract it from *n*. It's Ehab's turn and *n* = 0. There is no positive odd integer less than or equal to 0 so Mah...
500
[ { "input": "1", "output": "Ehab" }, { "input": "2", "output": "Mahmoud" }, { "input": "10000", "output": "Mahmoud" }, { "input": "33333", "output": "Ehab" }, { "input": "5", "output": "Ehab" }, { "input": "1000000000", "output": "Mahmoud" }, { ...
1,633,064,585
2,147,483,647
Python 3
OK
TESTS
20
62
6,758,400
x = int(input());a = print a("Mahmoud") if x%2 == 0 else a('Ehab')
Title: Mahmoud and Ehab and the even-odd game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mahmoud and Ehab play a game called the even-odd game. Ehab chooses his favorite integer *n* and then they take turns, starting from Mahmoud. In each player's turn, he has to choose an integer *a*...
```python x = int(input());a = print a("Mahmoud") if x%2 == 0 else a('Ehab') ```
3
490
A
Team Olympiad
PROGRAMMING
800
[ "greedy", "implementation", "sortings" ]
null
null
The School β„–0 of the capital of Berland has *n* children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value *t**i*: - *t**i*<==<=1, if the *i*-th child is good at prog...
The first line contains integer *n* (1<=≀<=*n*<=≀<=5000) β€” the number of children in the school. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≀<=*t**i*<=≀<=3), where *t**i* describes the skill of the *i*-th child.
In the first line output integer *w* β€” the largest possible number of teams. Then print *w* lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to...
[ "7\n1 3 1 3 2 1 2\n", "4\n2 1 1 2\n" ]
[ "2\n3 5 2\n6 7 4\n", "0\n" ]
none
500
[ { "input": "7\n1 3 1 3 2 1 2", "output": "2\n3 5 2\n6 7 4" }, { "input": "4\n2 1 1 2", "output": "0" }, { "input": "1\n2", "output": "0" }, { "input": "2\n3 1", "output": "0" }, { "input": "3\n2 1 2", "output": "0" }, { "input": "3\n1 2 3", "output...
1,664,889,859
2,147,483,647
PyPy 3-64
OK
TESTS
41
654
11,980,800
import sys sys.setrecursionlimit(1700) x = int(input()) arr = [int(i) for i in input().split(" ")] tend_set = {1, 2, 3} ans = [] def foo(arr, ans): tend_set = {1, 2, 3} arr_2 = [] dict = {} for i in range(len(arr)): if arr[i] != 0: dict.setdefault(arr[i], 0) dict[arr[i]] = i if tend_set.i...
Title: Team Olympiad Time Limit: None seconds Memory Limit: None megabytes Problem Description: The School β„–0 of the capital of Berland has *n* children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education)...
```python import sys sys.setrecursionlimit(1700) x = int(input()) arr = [int(i) for i in input().split(" ")] tend_set = {1, 2, 3} ans = [] def foo(arr, ans): tend_set = {1, 2, 3} arr_2 = [] dict = {} for i in range(len(arr)): if arr[i] != 0: dict.setdefault(arr[i], 0) dict[arr[i]] = i if ...
3
680
A
Bear and Five Cards
PROGRAMMING
800
[ "constructive algorithms", "implementation" ]
null
null
A little bear Limak plays a game. He has five cards. There is one number written on each card. Each number is a positive integer. Limak can discard (throw out) some cards. His goal is to minimize the sum of numbers written on remaining (not discarded) cards. He is allowed to at most once discard two or three cards wi...
The only line of the input contains five integers *t*1, *t*2, *t*3, *t*4 and *t*5 (1<=≀<=*t**i*<=≀<=100)Β β€” numbers written on cards.
Print the minimum possible sum of numbers written on remaining cards.
[ "7 3 7 3 20\n", "7 9 3 1 8\n", "10 10 10 10 10\n" ]
[ "26\n", "28\n", "20\n" ]
In the first sample, Limak has cards with numbers 7, 3, 7, 3 and 20. Limak can do one of the following. - Do nothing and the sum would be 7 + 3 + 7 + 3 + 20 = 40. - Remove two cards with a number 7. The remaining sum would be 3 + 3 + 20 = 26. - Remove two cards with a number 3. The remaining sum would be 7 + 7 + 20...
500
[ { "input": "7 3 7 3 20", "output": "26" }, { "input": "7 9 3 1 8", "output": "28" }, { "input": "10 10 10 10 10", "output": "20" }, { "input": "8 7 1 8 7", "output": "15" }, { "input": "7 7 7 8 8", "output": "16" }, { "input": "8 8 8 2 2", "output"...
1,594,291,290
2,147,483,647
Python 3
OK
TESTS
48
109
6,963,200
t = sorted(list(map(int, input().split()))) if len(set(t)) == 5: print(sum(t)) else: prev = 0 total = 0 count = 0 output = 0 for i in t: if prev != i: count = 0 total = 0 if count != 3: total += i count += 1 i...
Title: Bear and Five Cards Time Limit: None seconds Memory Limit: None megabytes Problem Description: A little bear Limak plays a game. He has five cards. There is one number written on each card. Each number is a positive integer. Limak can discard (throw out) some cards. His goal is to minimize the sum of numbers...
```python t = sorted(list(map(int, input().split()))) if len(set(t)) == 5: print(sum(t)) else: prev = 0 total = 0 count = 0 output = 0 for i in t: if prev != i: count = 0 total = 0 if count != 3: total += i count += 1 ...
3
886
B
Vlad and Cafes
PROGRAMMING
1,000
[]
null
null
Vlad likes to eat in cafes very much. During his life, he has visited cafes *n* times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research. First of all, Vlad assigned individual indices to all cafes. Then, he wrote down indices of cafes...
In first line there is one integer *n* (1<=≀<=*n*<=≀<=2Β·105)Β β€” number of cafes indices written by Vlad. In second line, *n* numbers *a*1,<=*a*2,<=...,<=*a**n* (0<=≀<=*a**i*<=≀<=2Β·105) are writtenΒ β€” indices of cafes in order of being visited by Vlad. Vlad could visit some cafes more than once. Note that in numeration, ...
Print one integerΒ β€” index of the cafe that Vlad hasn't visited for as long as possible.
[ "5\n1 3 2 1 2\n", "6\n2 1 2 2 4 1\n" ]
[ "3\n", "2\n" ]
In first test, there are three cafes, and the last visits to cafes with indices 1 and 2 were after the last visit to cafe with index 3; so this cafe is the answer. In second test case, there are also three cafes, but with indices 1, 2 and 4. Cafes with indices 1 and 4 were visited after the last visit of cafe with in...
1,000
[ { "input": "5\n1 3 2 1 2", "output": "3" }, { "input": "6\n2 1 2 2 4 1", "output": "2" }, { "input": "1\n0", "output": "0" }, { "input": "1\n200000", "output": "200000" }, { "input": "2\n2018 2017", "output": "2018" }, { "input": "5\n100 1000 1000 1000...
1,596,063,718
2,147,483,647
Python 3
OK
TESTS
33
202
24,780,800
n = int(input()) myd = {} arr = [int(x) for x in input().split()] for i in range(n): myd[arr[i]] = i print(arr[min(myd.values())])
Title: Vlad and Cafes Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vlad likes to eat in cafes very much. During his life, he has visited cafes *n* times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research...
```python n = int(input()) myd = {} arr = [int(x) for x in input().split()] for i in range(n): myd[arr[i]] = i print(arr[min(myd.values())]) ```
3
796
A
Buying A House
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
Zane the wizard had never loved anyone before, until he fell in love with a girl, whose name remains unknown to us. The girl lives in house *m* of a village. There are *n* houses in that village, lining in a straight line from left to right: house 1, house 2, ..., house *n*. The village is also well-structured: house ...
The first line contains three integers *n*, *m*, and *k* (2<=≀<=*n*<=≀<=100, 1<=≀<=*m*<=≀<=*n*, 1<=≀<=*k*<=≀<=100)Β β€” the number of houses in the village, the house where the girl lives, and the amount of money Zane has (in dollars), respectively. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≀<=...
Print one integerΒ β€” the minimum distance, in meters, from the house where the girl Zane likes lives to the house Zane can buy.
[ "5 1 20\n0 27 32 21 19\n", "7 3 50\n62 0 0 0 99 33 22\n", "10 5 100\n1 0 1 0 0 0 0 0 1 1\n" ]
[ "40", "30", "20" ]
In the first sample, with *k* = 20 dollars, Zane can buy only house 5. The distance from house *m* = 1 to house 5 is 10 + 10 + 10 + 10 = 40 meters. In the second sample, Zane can buy houses 6 and 7. It is better to buy house 6 than house 7, since house *m* = 3 and house 6 are only 30 meters away, while house *m* = 3 a...
500
[ { "input": "5 1 20\n0 27 32 21 19", "output": "40" }, { "input": "7 3 50\n62 0 0 0 99 33 22", "output": "30" }, { "input": "10 5 100\n1 0 1 0 0 0 0 0 1 1", "output": "20" }, { "input": "5 3 1\n1 1 0 0 1", "output": "10" }, { "input": "5 5 5\n1 0 5 6 0", "outpu...
1,621,576,809
2,147,483,647
Python 3
OK
TESTS
58
77
0
n,m,k=map(int,input().split()) a=list(map(int,input().split())) p1=m-2 p2=m i=1 j=1 ans=[] while p1>=0 or p2<n: if p1>=0 and a[p1]<=k and a[p1]!=0: ans.append(i) if p2<n and a[p2]<=k and a[p2]!=0: ans.append(j) p1-=1 i+=1 j+=1 p2+=1 print(min(ans)*10) ...
Title: Buying A House Time Limit: None seconds Memory Limit: None megabytes Problem Description: Zane the wizard had never loved anyone before, until he fell in love with a girl, whose name remains unknown to us. The girl lives in house *m* of a village. There are *n* houses in that village, lining in a straight li...
```python n,m,k=map(int,input().split()) a=list(map(int,input().split())) p1=m-2 p2=m i=1 j=1 ans=[] while p1>=0 or p2<n: if p1>=0 and a[p1]<=k and a[p1]!=0: ans.append(i) if p2<n and a[p2]<=k and a[p2]!=0: ans.append(j) p1-=1 i+=1 j+=1 p2+=1 print(min(a...
3
552
B
Vanya and Books
PROGRAMMING
1,200
[ "implementation", "math" ]
null
null
Vanya got an important task β€” he should enumerate books in the library and label each book with its number. Each of the *n* books should be assigned with a number from 1 to *n*. Naturally, distinct books should be assigned distinct numbers. Vanya wants to know how many digits he will have to write down as he labels th...
The first line contains integer *n* (1<=≀<=*n*<=≀<=109) β€” the number of books in the library.
Print the number of digits needed to number all the books.
[ "13\n", "4\n" ]
[ "17\n", "4\n" ]
Note to the first test. The books get numbers 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, which totals to 17 digits. Note to the second sample. The books get numbers 1, 2, 3, 4, which totals to 4 digits.
1,000
[ { "input": "13", "output": "17" }, { "input": "4", "output": "4" }, { "input": "100", "output": "192" }, { "input": "99", "output": "189" }, { "input": "1000000000", "output": "8888888899" }, { "input": "1000000", "output": "5888896" }, { "...
1,478,509,663
2,147,483,647
PyPy 3
OK
TESTS
55
140
0
n=input() p=len(n) print((int(n)+1)*p-int('1'*p))
Title: Vanya and Books Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vanya got an important task β€” he should enumerate books in the library and label each book with its number. Each of the *n* books should be assigned with a number from 1 to *n*. Naturally, distinct books should be assig...
```python n=input() p=len(n) print((int(n)+1)*p-int('1'*p)) ```
3
505
B
Mr. Kitayuta's Colorful Graph
PROGRAMMING
1,400
[ "dfs and similar", "dp", "dsu", "graphs" ]
null
null
Mr. Kitayuta has just bought an undirected graph consisting of *n* vertices and *m* edges. The vertices of the graph are numbered from 1 to *n*. Each edge, namely edge *i*, has a color *c**i*, connecting vertex *a**i* and *b**i*. Mr. Kitayuta wants you to process the following *q* queries. In the *i*-th query, he giv...
The first line of the input contains space-separated two integers β€” *n* and *m* (2<=≀<=*n*<=≀<=100,<=1<=≀<=*m*<=≀<=100), denoting the number of the vertices and the number of the edges, respectively. The next *m* lines contain space-separated three integers β€” *a**i*, *b**i* (1<=≀<=*a**i*<=&lt;<=*b**i*<=≀<=*n*) and *c*...
For each query, print the answer in a separate line.
[ "4 5\n1 2 1\n1 2 2\n2 3 1\n2 3 3\n2 4 3\n3\n1 2\n3 4\n1 4\n", "5 7\n1 5 1\n2 5 1\n3 5 1\n4 5 1\n1 2 2\n2 3 2\n3 4 2\n5\n1 5\n5 1\n2 5\n1 5\n1 4\n" ]
[ "2\n1\n0\n", "1\n1\n1\n1\n2\n" ]
Let's consider the first sample. - Vertex 1 and vertex 2 are connected by color 1 and 2. - Vertex 3 and vertex 4 are connected by color 3. - Vertex 1 and vertex 4 are not connected by any single color.
1,000
[ { "input": "4 5\n1 2 1\n1 2 2\n2 3 1\n2 3 3\n2 4 3\n3\n1 2\n3 4\n1 4", "output": "2\n1\n0" }, { "input": "5 7\n1 5 1\n2 5 1\n3 5 1\n4 5 1\n1 2 2\n2 3 2\n3 4 2\n5\n1 5\n5 1\n2 5\n1 5\n1 4", "output": "1\n1\n1\n1\n2" }, { "input": "2 1\n1 2 1\n1\n1 2", "output": "1" }, { "input...
1,421,588,921
2,921
Python 3
OK
TESTS
29
109
716,800
from collections import deque def BFS(graph,a,b): q = deque() q.append(a) visited = [ False for _ in range(len(graph))] while len(q): v = q.pop() if visited[v]: continue for x in graph[v]: if not visited[x]: q.a...
Title: Mr. Kitayuta's Colorful Graph Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mr. Kitayuta has just bought an undirected graph consisting of *n* vertices and *m* edges. The vertices of the graph are numbered from 1 to *n*. Each edge, namely edge *i*, has a color *c**i*, connecting v...
```python from collections import deque def BFS(graph,a,b): q = deque() q.append(a) visited = [ False for _ in range(len(graph))] while len(q): v = q.pop() if visited[v]: continue for x in graph[v]: if not visited[x]: ...
3
514
A
Chewbaсca and Number
PROGRAMMING
1,200
[ "greedy", "implementation" ]
null
null
Luke Skywalker gave Chewbacca an integer number *x*. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit *t* means replacing it with digit 9<=-<=*t*. Help Chewbacca to transform the initial number *x* to the minimum possible positive number by inverting some (possibly, zero) digits....
The first line contains a single integer *x* (1<=≀<=*x*<=≀<=1018) β€” the number that Luke Skywalker gave to Chewbacca.
Print the minimum possible positive number that Chewbacca can obtain after inverting some digits. The number shouldn't contain leading zeroes.
[ "27\n", "4545\n" ]
[ "22\n", "4444\n" ]
none
500
[ { "input": "27", "output": "22" }, { "input": "4545", "output": "4444" }, { "input": "1", "output": "1" }, { "input": "9", "output": "9" }, { "input": "8772", "output": "1222" }, { "input": "81", "output": "11" }, { "input": "71723447", ...
1,676,016,260
2,147,483,647
PyPy 3
OK
TESTS
43
93
0
n = input() num = "" for i in range(len(n)): temp = int(n[i]) if temp > 9 - temp: temp = 9 - temp num += str(temp) if num[0] == "0": num = num.replace("0", "9", 1) print(num)
Title: Chewbaсca and Number Time Limit: None seconds Memory Limit: None megabytes Problem Description: Luke Skywalker gave Chewbacca an integer number *x*. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit *t* means replacing it with digit 9<=-<=*t*. Help Chewbacca to transform...
```python n = input() num = "" for i in range(len(n)): temp = int(n[i]) if temp > 9 - temp: temp = 9 - temp num += str(temp) if num[0] == "0": num = num.replace("0", "9", 1) print(num) ```
3
859
A
Declined Finalists
PROGRAMMING
800
[ "greedy", "implementation" ]
null
null
This year, as in previous years, MemSQL is inviting the top 25 competitors from the Start[c]up qualification round to compete onsite for the final round. Not everyone who is eligible to compete onsite can afford to travel to the office, though. Initially the top 25 contestants are invited to come onsite. Each eligible ...
The first line of input contains *K* (1<=≀<=*K*<=≀<=25), the number of onsite finalists you know. The second line of input contains *r*1,<=*r*2,<=...,<=*r**K* (1<=≀<=*r**i*<=≀<=106), the qualifying ranks of the finalists you know. All these ranks are distinct.
Print the minimum possible number of contestants that declined the invitation to compete onsite.
[ "25\n2 3 4 5 6 7 8 9 10 11 12 14 15 16 17 18 19 20 21 22 23 24 25 26 28\n", "5\n16 23 8 15 4\n", "3\n14 15 92\n" ]
[ "3\n", "0\n", "67\n" ]
In the first example, you know all 25 onsite finalists. The contestants who ranked 1-st, 13-th, and 27-th must have declined, so the answer is 3.
500
[ { "input": "25\n2 3 4 5 6 7 8 9 10 11 12 14 15 16 17 18 19 20 21 22 23 24 25 26 28", "output": "3" }, { "input": "5\n16 23 8 15 4", "output": "0" }, { "input": "3\n14 15 92", "output": "67" }, { "input": "1\n1000000", "output": "999975" }, { "input": "25\n1000000 ...
1,576,941,708
2,147,483,647
PyPy 3
OK
TESTS
25
155
1,228,800
k=int(input()) a=list(map(int,input().split())) m=max(a) l=[] c1=c2=0 for i in a: if(i>25): l.append(i) for i in range(1,26): if i not in a: c1+=1 for i in range(26,m+1): if i not in a: c2+=1 if(k==25): print(c1+c2) else: print(c2+len(l))
Title: Declined Finalists Time Limit: None seconds Memory Limit: None megabytes Problem Description: This year, as in previous years, MemSQL is inviting the top 25 competitors from the Start[c]up qualification round to compete onsite for the final round. Not everyone who is eligible to compete onsite can afford to t...
```python k=int(input()) a=list(map(int,input().split())) m=max(a) l=[] c1=c2=0 for i in a: if(i>25): l.append(i) for i in range(1,26): if i not in a: c1+=1 for i in range(26,m+1): if i not in a: c2+=1 if(k==25): print(c1+c2) else: print(c2+len(...
3
810
A
Straight <<A>>
PROGRAMMING
900
[ "implementation", "math" ]
null
null
Noora is a student of one famous high school. It's her final year in schoolΒ β€” she is going to study in university next year. However, she has to get an Β«AΒ» graduation certificate in order to apply to a prestigious one. In school, where Noora is studying, teachers are putting down marks to the online class register, wh...
The first line contains two integers *n* and *k* (1<=≀<=*n*<=≀<=100,<=1<=≀<=*k*<=≀<=100) denoting the number of marks, received by Noora and the value of highest possible mark. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≀<=*a**i*<=≀<=*k*) denoting marks received by Noora before Leha's hack.
Print a single integerΒ β€” minimal number of additional marks, that Leha has to add in order to change Noora's final mark to *k*.
[ "2 10\n8 9\n", "3 5\n4 4 4\n" ]
[ "4", "3" ]
Consider the first example testcase. Maximal mark is 10, Noora received two marksΒ β€” 8 and 9, so current final mark is 9. To fix it, Leha can add marks [10, 10, 10, 10] (4 marks in total) to the registry, achieving Noora having average mark equal to <img align="middle" class="tex-formula" src="https://espresso.codeforc...
500
[ { "input": "2 10\n8 9", "output": "4" }, { "input": "3 5\n4 4 4", "output": "3" }, { "input": "3 10\n10 8 9", "output": "3" }, { "input": "2 23\n21 23", "output": "2" }, { "input": "5 10\n5 10 10 9 10", "output": "7" }, { "input": "12 50\n18 10 26 22 2...
1,500,101,964
2,147,483,647
Python 3
OK
TESTS
106
77
5,529,600
import math string = input() numbers = string.split() a, b = int(numbers[0]), int(numbers[1]) string = input() s = sum(list(map(int, string.split()))) n = 0 def roundup(x): if x - math.floor(x) < 0.5: return math.floor(x) else: return math.ceil(x) while roundup(s / a) < b: s += ...
Title: Straight <<A>> Time Limit: None seconds Memory Limit: None megabytes Problem Description: Noora is a student of one famous high school. It's her final year in schoolΒ β€” she is going to study in university next year. However, she has to get an Β«AΒ» graduation certificate in order to apply to a prestigious one. ...
```python import math string = input() numbers = string.split() a, b = int(numbers[0]), int(numbers[1]) string = input() s = sum(list(map(int, string.split()))) n = 0 def roundup(x): if x - math.floor(x) < 0.5: return math.floor(x) else: return math.ceil(x) while roundup(s / a) < b: ...
3
859
A
Declined Finalists
PROGRAMMING
800
[ "greedy", "implementation" ]
null
null
This year, as in previous years, MemSQL is inviting the top 25 competitors from the Start[c]up qualification round to compete onsite for the final round. Not everyone who is eligible to compete onsite can afford to travel to the office, though. Initially the top 25 contestants are invited to come onsite. Each eligible ...
The first line of input contains *K* (1<=≀<=*K*<=≀<=25), the number of onsite finalists you know. The second line of input contains *r*1,<=*r*2,<=...,<=*r**K* (1<=≀<=*r**i*<=≀<=106), the qualifying ranks of the finalists you know. All these ranks are distinct.
Print the minimum possible number of contestants that declined the invitation to compete onsite.
[ "25\n2 3 4 5 6 7 8 9 10 11 12 14 15 16 17 18 19 20 21 22 23 24 25 26 28\n", "5\n16 23 8 15 4\n", "3\n14 15 92\n" ]
[ "3\n", "0\n", "67\n" ]
In the first example, you know all 25 onsite finalists. The contestants who ranked 1-st, 13-th, and 27-th must have declined, so the answer is 3.
500
[ { "input": "25\n2 3 4 5 6 7 8 9 10 11 12 14 15 16 17 18 19 20 21 22 23 24 25 26 28", "output": "3" }, { "input": "5\n16 23 8 15 4", "output": "0" }, { "input": "3\n14 15 92", "output": "67" }, { "input": "1\n1000000", "output": "999975" }, { "input": "25\n1000000 ...
1,505,584,256
956
Python 3
OK
TESTS
25
452
3,993,600
K = int(input()) R = list(map(int, input().split())) R.sort() iv = [False]*(R[-1]+1) for r in R: iv[r] = True ans = 0 for r in range(1, R[-1]+1): if not iv[r] and K < 25: iv[r] = True K += 1 if not iv[r]: ans += 1 print(ans)
Title: Declined Finalists Time Limit: None seconds Memory Limit: None megabytes Problem Description: This year, as in previous years, MemSQL is inviting the top 25 competitors from the Start[c]up qualification round to compete onsite for the final round. Not everyone who is eligible to compete onsite can afford to t...
```python K = int(input()) R = list(map(int, input().split())) R.sort() iv = [False]*(R[-1]+1) for r in R: iv[r] = True ans = 0 for r in range(1, R[-1]+1): if not iv[r] and K < 25: iv[r] = True K += 1 if not iv[r]: ans += 1 print(ans) ```
3
789
A
Anastasia and pebbles
PROGRAMMING
1,100
[ "implementation", "math" ]
null
null
Anastasia loves going for a walk in Central Uzhlyandian Park. But she became uninterested in simple walking, so she began to collect Uzhlyandian pebbles. At first, she decided to collect all the pebbles she could find in the park. She has only two pockets. She can put at most *k* pebbles in each pocket at the same tim...
The first line contains two integers *n* and *k* (1<=≀<=*n*<=≀<=105, 1<=≀<=*k*<=≀<=109)Β β€” the number of different pebble types and number of pebbles Anastasia can place in one pocket. The second line contains *n* integers *w*1,<=*w*2,<=...,<=*w**n* (1<=≀<=*w**i*<=≀<=104)Β β€” number of pebbles of each type.
The only line of output contains one integerΒ β€” the minimum number of days Anastasia needs to collect all the pebbles.
[ "3 2\n2 3 4\n", "5 4\n3 1 8 9 7\n" ]
[ "3\n", "5\n" ]
In the first sample case, Anastasia can collect all pebbles of the first type on the first day, of second typeΒ β€” on the second day, and of third typeΒ β€” on the third day. Optimal sequence of actions in the second sample case: - In the first day Anastasia collects 8 pebbles of the third type. - In the second day she...
500
[ { "input": "3 2\n2 3 4", "output": "3" }, { "input": "5 4\n3 1 8 9 7", "output": "5" }, { "input": "1 22\n1", "output": "1" }, { "input": "3 57\n78 165 54", "output": "3" }, { "input": "5 72\n74 10 146 189 184", "output": "6" }, { "input": "9 13\n132 8...
1,490,804,979
1,479
Python 3
OK
TESTS
31
155
12,902,400
# -*- coding: utf-8 -*- """ Created on Wed Mar 29 21:32:29 2017 @author: vushesh """ import math n ,k = map(int, input().split(' ')) a = list(map(int,input().split(' '))) count = 0 for i in range(n): count += int(math.ceil(a[i]/k)) count = int(math.ceil(count/2 )) print(count...
Title: Anastasia and pebbles Time Limit: None seconds Memory Limit: None megabytes Problem Description: Anastasia loves going for a walk in Central Uzhlyandian Park. But she became uninterested in simple walking, so she began to collect Uzhlyandian pebbles. At first, she decided to collect all the pebbles she could ...
```python # -*- coding: utf-8 -*- """ Created on Wed Mar 29 21:32:29 2017 @author: vushesh """ import math n ,k = map(int, input().split(' ')) a = list(map(int,input().split(' '))) count = 0 for i in range(n): count += int(math.ceil(a[i]/k)) count = int(math.ceil(count/2 )) p...
3
667
A
Pouring Rain
PROGRAMMING
1,100
[ "geometry", "math" ]
null
null
A lot of people in Berland hates rain, but you do not. Rain pacifies, puts your thoughts in order. By these years you have developed a good tradition β€” when it rains, you go on the street and stay silent for a moment, contemplate all around you, enjoy freshness, think about big deeds you have to do. Today everything ...
The only line of the input contains four integer numbers *d*,<=*h*,<=*v*,<=*e* (1<=≀<=*d*,<=*h*,<=*v*,<=*e*<=≀<=104), where: - *d* β€” the diameter of your cylindrical cup, - *h* β€” the initial level of water in the cup, - *v* β€” the speed of drinking process from the cup in milliliters per second, - *e* β€” the growth ...
If it is impossible to make the cup empty, print "NO" (without quotes). Otherwise print "YES" (without quotes) in the first line. In the second line print a real number β€” time in seconds needed the cup will be empty. The answer will be considered correct if its relative or absolute error doesn't exceed 10<=-<=4. It is...
[ "1 2 3 100\n", "1 1 1 1\n" ]
[ "NO\n", "YES\n3.659792366325\n" ]
In the first example the water fills the cup faster than you can drink from it. In the second example area of the cup's bottom equals to <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/419dc74dcd7bc392019c9fe748fe1fdb08ab521a.png" style="max-width: 100.0%;max-height: 100.0%;"/>, thus we ca...
500
[ { "input": "1 2 3 100", "output": "NO" }, { "input": "1 1 1 1", "output": "YES\n3.659792366325" }, { "input": "48 7946 7992 72", "output": "NO" }, { "input": "72 6791 8546 46", "output": "NO" }, { "input": "100 5635 9099 23", "output": "NO" }, { "input...
1,472,121,318
2,147,483,647
Python 3
OK
TESTS
23
62
4,608,000
d,h,v,e = map(int, input().split()) s = 3.14159265354/4*d*d if s*e-v >= 0.0: print("NO") else: print("YES") print(h/(v/s-e))
Title: Pouring Rain Time Limit: None seconds Memory Limit: None megabytes Problem Description: A lot of people in Berland hates rain, but you do not. Rain pacifies, puts your thoughts in order. By these years you have developed a good tradition β€” when it rains, you go on the street and stay silent for a moment, cont...
```python d,h,v,e = map(int, input().split()) s = 3.14159265354/4*d*d if s*e-v >= 0.0: print("NO") else: print("YES") print(h/(v/s-e)) ```
3
577
A
Multiplication Table
PROGRAMMING
1,000
[ "implementation", "number theory" ]
null
null
Let's consider a table consisting of *n* rows and *n* columns. The cell located at the intersection of *i*-th row and *j*-th column contains number *i*<=Γ—<=*j*. The rows and columns are numbered starting from 1. You are given a positive integer *x*. Your task is to count the number of cells in a table that contain num...
The single line contains numbers *n* and *x* (1<=≀<=*n*<=≀<=105, 1<=≀<=*x*<=≀<=109) β€” the size of the table and the number that we are looking for in the table.
Print a single number: the number of times *x* occurs in the table.
[ "10 5\n", "6 12\n", "5 13\n" ]
[ "2\n", "4\n", "0\n" ]
A table for the second sample test is given below. The occurrences of number 12 are marked bold.
500
[ { "input": "10 5", "output": "2" }, { "input": "6 12", "output": "4" }, { "input": "5 13", "output": "0" }, { "input": "1 1", "output": "1" }, { "input": "2 1", "output": "1" }, { "input": "100000 1", "output": "1" }, { "input": "1 10000000...
1,694,642,548
2,147,483,647
Python 3
OK
TESTS
47
46
0
x,y=input().split() x=int(x) y=int(y) c=0 if y>x*x: print(c) else: n=1 while n<=x: if y%n==0: if y//n<=x: c+=1 n+=1 print(c)
Title: Multiplication Table Time Limit: None seconds Memory Limit: None megabytes Problem Description: Let's consider a table consisting of *n* rows and *n* columns. The cell located at the intersection of *i*-th row and *j*-th column contains number *i*<=Γ—<=*j*. The rows and columns are numbered starting from 1. Y...
```python x,y=input().split() x=int(x) y=int(y) c=0 if y>x*x: print(c) else: n=1 while n<=x: if y%n==0: if y//n<=x: c+=1 n+=1 print(c) ```
3
816
B
Karen and Coffee
PROGRAMMING
1,400
[ "binary search", "data structures", "implementation" ]
null
null
To stay woke and attentive during classes, Karen needs some coffee! Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe". She knows *n* coffee ...
The first line of input contains three integers, *n*, *k* (1<=≀<=*k*<=≀<=*n*<=≀<=200000), and *q* (1<=≀<=*q*<=≀<=200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively. The next *n* lines describe ...
For each question, output a single integer on a line by itself, the number of admissible integer temperatures between *a* and *b* degrees, inclusive.
[ "3 2 4\n91 94\n92 97\n97 99\n92 94\n93 97\n95 96\n90 100\n", "2 1 1\n1 1\n200000 200000\n90 100\n" ]
[ "3\n3\n0\n4\n", "0\n" ]
In the first test case, Karen knows 3 recipes. 1. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive. 1. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive. 1. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive. A temperatur...
1,000
[ { "input": "3 2 4\n91 94\n92 97\n97 99\n92 94\n93 97\n95 96\n90 100", "output": "3\n3\n0\n4" }, { "input": "2 1 1\n1 1\n200000 200000\n90 100", "output": "0" }, { "input": "1 1 1\n1 1\n1 1", "output": "1" }, { "input": "1 1 1\n200000 200000\n200000 200000", "output": "1" ...
1,689,050,988
2,147,483,647
PyPy 3-64
OK
TESTS
45
358
13,004,800
input=__import__('sys').stdin.readline n,k,q=map(int,input().split()) arr=[0]*200003 for i in range(n): l,r=map(int,input().split()) arr[l]+=1 arr[r+1]-=1 ans=[0]*200003 for i in range(1,len(arr)): arr[i]+=arr[i-1] ans[i]=ans[i-1]+(1 if arr[i]>=k else 0) for i in range(q): l,r=map(in...
Title: Karen and Coffee Time Limit: None seconds Memory Limit: None megabytes Problem Description: To stay woke and attentive during classes, Karen needs some coffee! Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading seve...
```python input=__import__('sys').stdin.readline n,k,q=map(int,input().split()) arr=[0]*200003 for i in range(n): l,r=map(int,input().split()) arr[l]+=1 arr[r+1]-=1 ans=[0]*200003 for i in range(1,len(arr)): arr[i]+=arr[i-1] ans[i]=ans[i-1]+(1 if arr[i]>=k else 0) for i in range(q): ...
3
66
B
Petya and Countryside
PROGRAMMING
1,100
[ "brute force", "implementation" ]
B. Petya and Countryside
2
256
Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1<=Γ—<=*n* in size, when viewed from above. This rectangle is divided into *n* equal square sections. The garden is very unusual as each of the square sections possesses its own f...
The first line contains a positive integer *n* (1<=≀<=*n*<=≀<=1000). The second line contains *n* positive integers which are the height of the sections. All the numbers are no less than 1 and not more than 1000.
Print a single number, the maximal number of watered sections if we create artificial rain above exactly one section.
[ "1\n2\n", "5\n1 2 1 2 1\n", "8\n1 2 1 1 1 3 3 4\n" ]
[ "1\n", "3\n", "6\n" ]
none
1,000
[ { "input": "1\n2", "output": "1" }, { "input": "5\n1 2 1 2 1", "output": "3" }, { "input": "8\n1 2 1 1 1 3 3 4", "output": "6" }, { "input": "10\n1 2 3 4 5 6 7 8 9 10", "output": "10" }, { "input": "10\n10 9 8 7 6 5 4 3 2 1", "output": "10" }, { "input...
1,596,038,005
2,147,483,647
Python 3
OK
TESTS
80
216
6,963,200
def get_max_sections1(array): is_increasing = True max = 0 cur_max = 0 prev = 0 for i in array: if is_increasing: if prev <= i: cur_max += 1 else: cur_max += 1 is_increasing = False else: if prev >= i...
Title: Petya and Countryside Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1<=Γ—<=*n* in size, when viewed from above. This rectangle is divided into *...
```python def get_max_sections1(array): is_increasing = True max = 0 cur_max = 0 prev = 0 for i in array: if is_increasing: if prev <= i: cur_max += 1 else: cur_max += 1 is_increasing = False else: if...
3.93303
282
A
Bit++
PROGRAMMING
800
[ "implementation" ]
null
null
The classic programming language of Bitland is Bit++. This language is so peculiar and complicated. The language is that peculiar as it has exactly one variable, called *x*. Also, there are two operations: - Operation ++ increases the value of variable *x* by 1. - Operation -- decreases the value of variable *x* by...
The first line contains a single integer *n* (1<=≀<=*n*<=≀<=150) β€” the number of statements in the programme. Next *n* lines contain a statement each. Each statement contains exactly one operation (++ or --) and exactly one variable *x* (denoted as letter Β«XΒ»). Thus, there are no empty statements. The operation and th...
Print a single integer β€” the final value of *x*.
[ "1\n++X\n", "2\nX++\n--X\n" ]
[ "1\n", "0\n" ]
none
500
[ { "input": "1\n++X", "output": "1" }, { "input": "2\nX++\n--X", "output": "0" }, { "input": "3\n++X\n++X\n++X", "output": "3" }, { "input": "2\n--X\n--X", "output": "-2" }, { "input": "5\n++X\n--X\n++X\n--X\n--X", "output": "-1" }, { "input": "28\nX--\...
1,698,760,940
2,147,483,647
Python 3
OK
TESTS
36
61
0
t = int(input()) c = 0 for i in range(t): s = input() if s[1] == '+': c += 1 else: c -= 1 print(c)
Title: Bit++ Time Limit: None seconds Memory Limit: None megabytes Problem Description: The classic programming language of Bitland is Bit++. This language is so peculiar and complicated. The language is that peculiar as it has exactly one variable, called *x*. Also, there are two operations: - Operation ++ incre...
```python t = int(input()) c = 0 for i in range(t): s = input() if s[1] == '+': c += 1 else: c -= 1 print(c) ```
3
245
A
System Administrator
PROGRAMMING
800
[ "implementation" ]
null
null
Polycarpus is a system administrator. There are two servers under his strict guidance β€” *a* and *b*. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a progra...
The first line contains a single integer *n* (2<=≀<=*n*<=≀<=1000) β€” the number of commands Polycarpus has fulfilled. Each of the following *n* lines contains three integers β€” the description of the commands. The *i*-th of these lines contains three space-separated integers *t**i*, *x**i*, *y**i* (1<=≀<=*t**i*<=≀<=2;Β *x...
In the first line print string "LIVE" (without the quotes) if server *a* is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server *b* in the similar format.
[ "2\n1 5 5\n2 6 4\n", "3\n1 0 10\n2 0 10\n1 10 0\n" ]
[ "LIVE\nLIVE\n", "LIVE\nDEAD\n" ]
Consider the first test case. There 10 packets were sent to server *a*, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server *b*, 6 of them reached it. Therefore, at least half of all packets sent to t...
0
[ { "input": "2\n1 5 5\n2 6 4", "output": "LIVE\nLIVE" }, { "input": "3\n1 0 10\n2 0 10\n1 10 0", "output": "LIVE\nDEAD" }, { "input": "10\n1 3 7\n2 4 6\n1 2 8\n2 5 5\n2 10 0\n2 10 0\n1 8 2\n2 2 8\n2 10 0\n1 1 9", "output": "DEAD\nLIVE" }, { "input": "11\n1 8 2\n1 6 4\n1 9 1\n1...
1,557,920,016
2,147,483,647
Python 3
OK
TESTS
13
218
307,200
n=int(input()) a=[] x1,y1=0,0 x2,y2=0,0 for i in range(n): b=list(map(int,input().split())) a.append(b) for i in a: if i[0]==1: x1+=i[1] y1+=i[2] elif i[0]==2: x2+=i[1] y2+=i[2] if x1>=y1: print('LIVE') else: print('DEAD') if x2>=y2: print('LIVE') else: print('DEAD')
Title: System Administrator Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarpus is a system administrator. There are two servers under his strict guidance β€” *a* and *b*. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping co...
```python n=int(input()) a=[] x1,y1=0,0 x2,y2=0,0 for i in range(n): b=list(map(int,input().split())) a.append(b) for i in a: if i[0]==1: x1+=i[1] y1+=i[2] elif i[0]==2: x2+=i[1] y2+=i[2] if x1>=y1: print('LIVE') else: print('DEAD') if x2>=y2: print('LIVE') else: print('DEAD') ```
3
554
B
Ohana Cleans Up
PROGRAMMING
1,200
[ "brute force", "greedy", "strings" ]
null
null
Ohana Matsumae is trying to clean a room, which is divided up into an *n* by *n* grid of squares. Each square is initially either clean or dirty. Ohana can sweep her broom over columns of the grid. Her broom is very strange: if she sweeps over a clean square, it will become dirty, and if she sweeps over a dirty square,...
The first line of input will be a single integer *n* (1<=≀<=*n*<=≀<=100). The next *n* lines will describe the state of the room. The *i*-th line will contain a binary string with *n* characters denoting the state of the *i*-th row of the room. The *j*-th character on this line is '1' if the *j*-th square in the *i*-t...
The output should be a single line containing an integer equal to a maximum possible number of rows that are completely clean.
[ "4\n0101\n1000\n1111\n0101\n", "3\n111\n111\n111\n" ]
[ "2\n", "3\n" ]
In the first sample, Ohana can sweep the 1st and 3rd columns. This will make the 1st and 4th row be completely clean. In the second sample, everything is already clean, so Ohana doesn't need to do anything.
500
[ { "input": "4\n0101\n1000\n1111\n0101", "output": "2" }, { "input": "3\n111\n111\n111", "output": "3" }, { "input": "10\n0100000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000", "output": "9" }, { "input": "1\n1"...
1,474,209,060
2,147,483,647
Python 3
OK
TESTS
36
62
0
I=input s=[I()for _ in '0'*int(I())] print(max(s.count(i)for i in s))
Title: Ohana Cleans Up Time Limit: None seconds Memory Limit: None megabytes Problem Description: Ohana Matsumae is trying to clean a room, which is divided up into an *n* by *n* grid of squares. Each square is initially either clean or dirty. Ohana can sweep her broom over columns of the grid. Her broom is very str...
```python I=input s=[I()for _ in '0'*int(I())] print(max(s.count(i)for i in s)) ```
3
152
A
Marks
PROGRAMMING
900
[ "implementation" ]
null
null
Vasya, or Mr. Vasily Petrov is a dean of a department in a local university. After the winter exams he got his hands on a group's gradebook. Overall the group has *n* students. They received marks for *m* subjects. Each student got a mark from 1 to 9 (inclusive) for each subject. Let's consider a student the best at ...
The first input line contains two integers *n* and *m* (1<=≀<=*n*,<=*m*<=≀<=100) β€” the number of students and the number of subjects, correspondingly. Next *n* lines each containing *m* characters describe the gradebook. Each character in the gradebook is a number from 1 to 9. Note that the marks in a rows are not sepa...
Print the single number β€” the number of successful students in the given group.
[ "3 3\n223\n232\n112\n", "3 5\n91728\n11828\n11111\n" ]
[ "2\n", "3\n" ]
In the first sample test the student number 1 is the best at subjects 1 and 3, student 2 is the best at subjects 1 and 2, but student 3 isn't the best at any subject. In the second sample test each student is the best at at least one subject.
500
[ { "input": "3 3\n223\n232\n112", "output": "2" }, { "input": "3 5\n91728\n11828\n11111", "output": "3" }, { "input": "2 2\n48\n27", "output": "1" }, { "input": "2 1\n4\n6", "output": "1" }, { "input": "1 2\n57", "output": "1" }, { "input": "1 1\n5", ...
1,579,627,437
2,147,483,647
Python 3
OK
TESTS
44
109
307,200
n,m=map(int,input().split()) A=[] max_subject_marks=[0]*m for i in range(n): s=input() A.append(s) for j in range(m): max_subject_marks[j]=max(max_subject_marks[j],int(s[j])) cnt=0 for i in A: flag=0 for j in range(m): marks=int(i[j]) if(marks==max_subject_marks[j]): flag=1 ...
Title: Marks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya, or Mr. Vasily Petrov is a dean of a department in a local university. After the winter exams he got his hands on a group's gradebook. Overall the group has *n* students. They received marks for *m* subjects. Each student ...
```python n,m=map(int,input().split()) A=[] max_subject_marks=[0]*m for i in range(n): s=input() A.append(s) for j in range(m): max_subject_marks[j]=max(max_subject_marks[j],int(s[j])) cnt=0 for i in A: flag=0 for j in range(m): marks=int(i[j]) if(marks==max_subject_marks[j]): ...
3
556
A
Case of the Zeros and Ones
PROGRAMMING
900
[ "greedy" ]
null
null
Andrewid the Android is a galaxy-famous detective. In his free time he likes to think about strings containing zeros and ones. Once he thought about a string of length *n* consisting of zeroes and ones. Consider the following operation: we choose any two adjacent positions in the string, and if one them contains 0, an...
First line of the input contains a single integer *n* (1<=≀<=*n*<=≀<=2Β·105), the length of the string that Andreid has. The second line contains the string of length *n* consisting only from zeros and ones.
Output the minimum length of the string that may remain after applying the described operations several times.
[ "4\n1100\n", "5\n01010\n", "8\n11101111\n" ]
[ "0\n", "1\n", "6\n" ]
In the first sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/10df55364c21c6e8d5da31b6ab6f6294c4fc26b3.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In the second sample test it is possible to change the string like...
250
[ { "input": "4\n1100", "output": "0" }, { "input": "5\n01010", "output": "1" }, { "input": "8\n11101111", "output": "6" }, { "input": "1\n0", "output": "1" }, { "input": "1\n1", "output": "1" }, { "input": "2\n00", "output": "2" }, { "input"...
1,664,915,632
2,147,483,647
Python 3
OK
TESTS
49
46
512,000
number = int(input()) case = input() numberOf0 = case.count('0') numberOf1 = case.count('1') if numberOf0 < numberOf1: print(len(case)- 2*numberOf0) else: print(len(case)- 2*numberOf1)
Title: Case of the Zeros and Ones Time Limit: None seconds Memory Limit: None megabytes Problem Description: Andrewid the Android is a galaxy-famous detective. In his free time he likes to think about strings containing zeros and ones. Once he thought about a string of length *n* consisting of zeroes and ones. Cons...
```python number = int(input()) case = input() numberOf0 = case.count('0') numberOf1 = case.count('1') if numberOf0 < numberOf1: print(len(case)- 2*numberOf0) else: print(len(case)- 2*numberOf1) ```
3
899
A
Splitting in Teams
PROGRAMMING
800
[ "constructive algorithms", "greedy", "math" ]
null
null
There were *n* groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team. The coach decided to form teams of exactly three people for this training. Determine the maximum number of tea...
The first line contains single integer *n* (2<=≀<=*n*<=≀<=2Β·105) β€” the number of groups. The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≀<=*a**i*<=≀<=2), where *a**i* is the number of people in group *i*.
Print the maximum number of teams of three people the coach can form.
[ "4\n1 1 2 1\n", "2\n2 2\n", "7\n2 2 2 1 1 1 1\n", "3\n1 1 1\n" ]
[ "1\n", "0\n", "3\n", "1\n" ]
In the first example the coach can form one team. For example, he can take students from the first, second and fourth groups. In the second example he can't make a single team. In the third example the coach can form three teams. For example, he can do this in the following way: - The first group (of two people) an...
500
[ { "input": "4\n1 1 2 1", "output": "1" }, { "input": "2\n2 2", "output": "0" }, { "input": "7\n2 2 2 1 1 1 1", "output": "3" }, { "input": "3\n1 1 1", "output": "1" }, { "input": "3\n2 2 2", "output": "0" }, { "input": "3\n1 2 1", "output": "1" }...
1,667,785,979
2,147,483,647
PyPy 3-64
OK
TESTS
67
139
23,756,800
from collections import * from heapq import * from bisect import * from itertools import * from functools import * from math import * from string import * import operator import sys input = sys.stdin.readline def solve(): n = int(input()) A = list(map(int, input().split())) ct = Counter(A) ...
Title: Splitting in Teams Time Limit: None seconds Memory Limit: None megabytes Problem Description: There were *n* groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team. The co...
```python from collections import * from heapq import * from bisect import * from itertools import * from functools import * from math import * from string import * import operator import sys input = sys.stdin.readline def solve(): n = int(input()) A = list(map(int, input().split())) ct = C...
3
706
B
Interesting drink
PROGRAMMING
1,100
[ "binary search", "dp", "implementation" ]
null
null
Vasiliy likes to rest after a hard work, so you may often meet him in some bar nearby. As all programmers do, he loves the famous drink "Beecola", which can be bought in *n* different shops in the city. It's known that the price of one bottle in the shop *i* is equal to *x**i* coins. Vasiliy plans to buy his favorite ...
The first line of the input contains a single integer *n* (1<=≀<=*n*<=≀<=100<=000)Β β€” the number of shops in the city that sell Vasiliy's favourite drink. The second line contains *n* integers *x**i* (1<=≀<=*x**i*<=≀<=100<=000)Β β€” prices of the bottles of the drink in the *i*-th shop. The third line contains a single i...
Print *q* integers. The *i*-th of them should be equal to the number of shops where Vasiliy will be able to buy a bottle of the drink on the *i*-th day.
[ "5\n3 10 8 6 11\n4\n1\n10\n3\n11\n" ]
[ "0\n4\n1\n5\n" ]
On the first day, Vasiliy won't be able to buy a drink in any of the shops. On the second day, Vasiliy can buy a drink in the shops 1, 2, 3 and 4. On the third day, Vasiliy can buy a drink only in the shop number 1. Finally, on the last day Vasiliy can buy a drink in any shop.
1,000
[ { "input": "5\n3 10 8 6 11\n4\n1\n10\n3\n11", "output": "0\n4\n1\n5" }, { "input": "5\n868 987 714 168 123\n10\n424\n192\n795\n873\n117\n914\n735\n158\n631\n471", "output": "2\n2\n3\n4\n0\n4\n3\n1\n2\n2" }, { "input": "3\n435 482 309\n7\n245\n241\n909\n745\n980\n29\n521", "output": "...
1,689,605,454
2,147,483,647
Python 3
OK
TESTS
103
1,200
13,619,200
s = int(input()) li = sorted(map(int, input().split())) d = int(input()) for i in range(d): n = int(input()) low = 0 high = s - 1 while low <= high: mid = (low + high) // 2 if li[mid] <= n: low = mid + 1 else: high = mid - 1 print(low)
Title: Interesting drink Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasiliy likes to rest after a hard work, so you may often meet him in some bar nearby. As all programmers do, he loves the famous drink "Beecola", which can be bought in *n* different shops in the city. It's known tha...
```python s = int(input()) li = sorted(map(int, input().split())) d = int(input()) for i in range(d): n = int(input()) low = 0 high = s - 1 while low <= high: mid = (low + high) // 2 if li[mid] <= n: low = mid + 1 else: high = mid - 1 pr...
3
381
A
Sereja and Dima
PROGRAMMING
800
[ "greedy", "implementation", "two pointers" ]
null
null
Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. Th...
The first line contains integer *n* (1<=≀<=*n*<=≀<=1000) β€” the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000.
On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game.
[ "4\n4 1 2 10\n", "7\n1 2 3 4 5 6 7\n" ]
[ "12 5\n", "16 12\n" ]
In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5.
500
[ { "input": "4\n4 1 2 10", "output": "12 5" }, { "input": "7\n1 2 3 4 5 6 7", "output": "16 12" }, { "input": "42\n15 29 37 22 16 5 26 31 6 32 19 3 45 36 33 14 25 20 48 7 42 11 24 28 9 18 8 21 47 17 38 40 44 4 35 1 43 39 41 27 12 13", "output": "613 418" }, { "input": "43\n32 ...
1,671,651,863
2,147,483,647
PyPy 3-64
OK
TESTS
34
62
0
start = 0 end = int(input()) -1 nums = list(map(int,input().split())) turn = False score = [0,0] cur = 0 while start <=end : if nums[start] > nums[end] : cur = nums[start] start +=1 else : cur = nums[end] end -=1 score[turn] += cur turn = not turn print(*score)
Title: Sereja and Dima Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. Du...
```python start = 0 end = int(input()) -1 nums = list(map(int,input().split())) turn = False score = [0,0] cur = 0 while start <=end : if nums[start] > nums[end] : cur = nums[start] start +=1 else : cur = nums[end] end -=1 score[turn] += cur turn = not turn print(*score) ...
3
493
B
Vasya and Wrestling
PROGRAMMING
1,400
[ "implementation" ]
null
null
Vasya has become interested in wrestling. In wrestling wrestlers use techniques for which they are awarded points by judges. The wrestler who gets the most points wins. When the numbers of points of both wrestlers are equal, the wrestler whose sequence of points is lexicographically greater, wins. If the sequences of...
The first line contains number *n* β€” the number of techniques that the wrestlers have used (1<=≀<=*n*<=≀<=2Β·105). The following *n* lines contain integer numbers *a**i* (|*a**i*|<=≀<=109, *a**i*<=β‰ <=0). If *a**i* is positive, that means that the first wrestler performed the technique that was awarded with *a**i* poin...
If the first wrestler wins, print string "first", otherwise print "second"
[ "5\n1\n2\n-3\n-4\n3\n", "3\n-1\n-2\n3\n", "2\n4\n-4\n" ]
[ "second\n", "first\n", "second\n" ]
Sequence *x*  =  *x*<sub class="lower-index">1</sub>*x*<sub class="lower-index">2</sub>... *x*<sub class="lower-index">|*x*|</sub> is lexicographically larger than sequence *y*  =  *y*<sub class="lower-index">1</sub>*y*<sub class="lower-index">2</sub>... *y*<sub class="lower-index">|*y*|</sub>, if either |*x*|  &gt;  |...
1,000
[ { "input": "5\n1\n2\n-3\n-4\n3", "output": "second" }, { "input": "3\n-1\n-2\n3", "output": "first" }, { "input": "2\n4\n-4", "output": "second" }, { "input": "7\n1\n2\n-3\n4\n5\n-6\n7", "output": "first" }, { "input": "14\n1\n2\n3\n4\n5\n6\n7\n-8\n-9\n-10\n-11\n-...
1,640,259,385
2,147,483,647
Python 3
OK
TESTS
57
312
6,144,000
t=int(input()) first=[] second=[] flag1=True for i in range(t): x=int(input()) if x>0: first.append(x) else: second.append(-x) if i==t-1 and x>0: flag1=False s1=sum(first) s2=sum(second) if s1>s2: print("first") elif s2>s1: print("second") else: x="...
Title: Vasya and Wrestling Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya has become interested in wrestling. In wrestling wrestlers use techniques for which they are awarded points by judges. The wrestler who gets the most points wins. When the numbers of points of both wrestlers ...
```python t=int(input()) first=[] second=[] flag1=True for i in range(t): x=int(input()) if x>0: first.append(x) else: second.append(-x) if i==t-1 and x>0: flag1=False s1=sum(first) s2=sum(second) if s1>s2: print("first") elif s2>s1: print("second") else...
3
669
A
Little Artem and Presents
PROGRAMMING
800
[ "math" ]
null
null
Little Artem got *n* stones on his birthday and now wants to give some of them to Masha. He knows that Masha cares more about the fact of receiving the present, rather than the value of that present, so he wants to give her stones as many times as possible. However, Masha remembers the last present she received, so Art...
The only line of the input contains a single integer *n* (1<=≀<=*n*<=≀<=109)Β β€” number of stones Artem received on his birthday.
Print the maximum possible number of times Artem can give presents to Masha.
[ "1\n", "2\n", "3\n", "4\n" ]
[ "1\n", "1\n", "2\n", "3\n" ]
In the first sample, Artem can only give 1 stone to Masha. In the second sample, Atrem can give Masha 1 or 2 stones, though he can't give her 1 stone two times. In the third sample, Atrem can first give Masha 2 stones, a then 1 more stone. In the fourth sample, Atrem can first give Masha 1 stone, then 2 stones, and ...
500
[ { "input": "1", "output": "1" }, { "input": "2", "output": "1" }, { "input": "3", "output": "2" }, { "input": "4", "output": "3" }, { "input": "100", "output": "67" }, { "input": "101", "output": "67" }, { "input": "102", "output": "68"...
1,564,593,781
2,147,483,647
Python 3
OK
TESTS
26
124
0
# import sys # sys.stdin=open("input.in","r") n=int(input()) print(2*(n//3)+(n%3+2)//3)
Title: Little Artem and Presents Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Artem got *n* stones on his birthday and now wants to give some of them to Masha. He knows that Masha cares more about the fact of receiving the present, rather than the value of that present, so he wan...
```python # import sys # sys.stdin=open("input.in","r") n=int(input()) print(2*(n//3)+(n%3+2)//3) ```
3
231
A
Team
PROGRAMMING
800
[ "brute force", "greedy" ]
null
null
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution....
The first input line contains a single integer *n* (1<=≀<=*n*<=≀<=1000) β€” the number of problems in the contest. Then *n* lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second numbe...
Print a single integer β€” the number of problems the friends will implement on the contest.
[ "3\n1 1 0\n1 1 1\n1 0 0\n", "2\n1 0 0\n0 1 1\n" ]
[ "2\n", "1\n" ]
In the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't ta...
500
[ { "input": "3\n1 1 0\n1 1 1\n1 0 0", "output": "2" }, { "input": "2\n1 0 0\n0 1 1", "output": "1" }, { "input": "1\n1 0 0", "output": "0" }, { "input": "2\n1 0 0\n1 1 1", "output": "1" }, { "input": "5\n1 0 0\n0 1 0\n1 1 1\n0 0 1\n0 0 0", "output": "1" }, ...
1,699,221,886
2,147,483,647
PyPy 3-64
OK
TESTS
21
154
1,638,400
n = int(input()) ans = 0 for i in range(n): a = input() if int(a[0]) + int(a[2]) + int(a[4]) > 1: ans += 1 print(ans)
Title: Team Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decid...
```python n = int(input()) ans = 0 for i in range(n): a = input() if int(a[0]) + int(a[2]) + int(a[4]) > 1: ans += 1 print(ans) ```
3
445
A
DZY Loves Chessboard
PROGRAMMING
1,200
[ "dfs and similar", "implementation" ]
null
null
DZY loves chessboard, and he enjoys playing with it. He has a chessboard of *n* rows and *m* columns. Some cells of the chessboard are bad, others are good. For every good cell, DZY wants to put a chessman on it. Each chessman is either white or black. After putting all chessmen, DZY wants that no two chessmen with th...
The first line contains two space-separated integers *n* and *m* (1<=≀<=*n*,<=*m*<=≀<=100). Each of the next *n* lines contains a string of *m* characters: the *j*-th character of the *i*-th string is either "." or "-". A "." means that the corresponding cell (in the *i*-th row and the *j*-th column) is good, while a ...
Output must contain *n* lines, each line must contain a string of *m* characters. The *j*-th character of the *i*-th string should be either "W", "B" or "-". Character "W" means the chessman on the cell is white, "B" means it is black, "-" means the cell is a bad cell. If multiple answers exist, print any of them. It ...
[ "1 1\n.\n", "2 2\n..\n..\n", "3 3\n.-.\n---\n--." ]
[ "B\n", "BW\nWB\n", "B-B\n---\n--B" ]
In the first sample, DZY puts a single black chessman. Of course putting a white one is also OK. In the second sample, all 4 cells are good. No two same chessmen share an edge in the sample output. In the third sample, no good cells are adjacent. So you can just put 3 chessmen, no matter what their colors are.
500
[ { "input": "1 1\n.", "output": "B" }, { "input": "2 2\n..\n..", "output": "BW\nWB" }, { "input": "3 3\n.-.\n---\n--.", "output": "B-B\n---\n--B" }, { "input": "3 1\n-\n.\n.", "output": "-\nW\nB" }, { "input": "11 11\n-----------\n-----------\n-----------\n--------...
1,610,617,216
2,147,483,647
PyPy 3
OK
TESTS
37
140
4,710,400
n, m = map(int, input().split()) s = ['B', 'W'] for i in range(n): for k, j in enumerate(input()): if j == ".": if i % 2 == 0: print(s[k % 2], end="") else: print(s[(k+1) % 2], end="") else: print("-", end="") print...
Title: DZY Loves Chessboard Time Limit: None seconds Memory Limit: None megabytes Problem Description: DZY loves chessboard, and he enjoys playing with it. He has a chessboard of *n* rows and *m* columns. Some cells of the chessboard are bad, others are good. For every good cell, DZY wants to put a chessman on it. ...
```python n, m = map(int, input().split()) s = ['B', 'W'] for i in range(n): for k, j in enumerate(input()): if j == ".": if i % 2 == 0: print(s[k % 2], end="") else: print(s[(k+1) % 2], end="") else: print("-", end="") ...
3
940
A
Points on the line
PROGRAMMING
1,200
[ "brute force", "greedy", "sortings" ]
null
null
We've got no test cases. A big olympiad is coming up. But the problemsetters' number one priority should be adding another problem to the round. The diameter of a multiset of points on the line is the largest distance between two points from this set. For example, the diameter of the multiset {1,<=3,<=2,<=1} is 2. D...
The first line contains two integers *n* and *d* (1<=≀<=*n*<=≀<=100,<=0<=≀<=*d*<=≀<=100)Β β€” the amount of points and the maximum allowed diameter respectively. The second line contains *n* space separated integers (1<=≀<=*x**i*<=≀<=100)Β β€” the coordinates of the points.
Output a single integerΒ β€” the minimum number of points you have to remove.
[ "3 1\n2 1 4\n", "3 0\n7 7 7\n", "6 3\n1 3 4 6 9 10\n" ]
[ "1\n", "0\n", "3\n" ]
In the first test case the optimal strategy is to remove the point with coordinate 4. The remaining points will have coordinates 1 and 2, so the diameter will be equal to 2 - 1 = 1. In the second test case the diameter is equal to 0, so its is unnecessary to remove any points. In the third test case the optimal stra...
500
[ { "input": "3 1\n2 1 4", "output": "1" }, { "input": "3 0\n7 7 7", "output": "0" }, { "input": "6 3\n1 3 4 6 9 10", "output": "3" }, { "input": "11 5\n10 11 12 13 14 15 16 17 18 19 20", "output": "5" }, { "input": "1 100\n1", "output": "0" }, { "input"...
1,519,987,033
2,147,483,647
Python 3
OK
TESTS
35
62
5,632,000
#!/usr/bin/env python2 # -*- coding: utf-8 -*- """ Created on Fri Mar 2 09:58:19 2018 @author: mikolajbinkowski """ n, d = [int(k) for k in input().split(' ')] points = [int(k) for k in input().split(' ')] def qs(A, l, r): if l >= r: return p = part(A, l, r) qs(A, l, p - 1) qs(A, p...
Title: Points on the line Time Limit: None seconds Memory Limit: None megabytes Problem Description: We've got no test cases. A big olympiad is coming up. But the problemsetters' number one priority should be adding another problem to the round. The diameter of a multiset of points on the line is the largest dista...
```python #!/usr/bin/env python2 # -*- coding: utf-8 -*- """ Created on Fri Mar 2 09:58:19 2018 @author: mikolajbinkowski """ n, d = [int(k) for k in input().split(' ')] points = [int(k) for k in input().split(' ')] def qs(A, l, r): if l >= r: return p = part(A, l, r) qs(A, l, p - 1) ...
3
884
D
Boxes And Balls
PROGRAMMING
2,300
[ "data structures", "greedy" ]
null
null
Ivan has *n* different boxes. The first of them contains some balls of *n* different colors. Ivan wants to play a strange game. He wants to distribute the balls into boxes in such a way that for every *i* (1<=≀<=*i*<=≀<=*n*) *i*-th box will contain all balls with color *i*. In order to do this, Ivan will make some tu...
The first line contains one integer number *n* (1<=≀<=*n*<=≀<=200000) β€” the number of boxes and colors. The second line contains *n* integer numbers *a*1, *a*2, ..., *a**n* (1<=≀<=*a**i*<=≀<=109), where *a**i* is the number of balls with color *i*.
Print one number β€” the minimum possible penalty of the game.
[ "3\n1 2 3\n", "4\n2 3 4 5\n" ]
[ "6\n", "19\n" ]
In the first example you take all the balls from the first box, choose *k* = 3 and sort all colors to corresponding boxes. Penalty is 6. In the second example you make two turns: 1. Take all the balls from the first box, choose *k* = 3, put balls of color 3 to the third box, of color 4 β€” to the fourth box and the r...
0
[ { "input": "3\n1 2 3", "output": "6" }, { "input": "4\n2 3 4 5", "output": "19" }, { "input": "6\n1 4 4 4 4 4", "output": "38" }, { "input": "8\n821407370 380061316 428719552 90851747 825473738 704702117 845629927 245820158", "output": "8176373828" }, { "input": "...
1,651,766,117
2,147,483,647
Python 3
OK
TESTS
32
421
16,179,200
n = int(input()) colors = list(map(int, input().strip().split())) if n % 2 == 0: colors.append(0) import heapq heapq.heapify(colors) penalty = 0 while (len(colors) > 2): a = heapq.heappop(colors) b = heapq.heappop(colors) c = heapq.heappop(colors) penalty += (a + b + c) hea...
Title: Boxes And Balls Time Limit: None seconds Memory Limit: None megabytes Problem Description: Ivan has *n* different boxes. The first of them contains some balls of *n* different colors. Ivan wants to play a strange game. He wants to distribute the balls into boxes in such a way that for every *i* (1<=≀<=*i*<=≀...
```python n = int(input()) colors = list(map(int, input().strip().split())) if n % 2 == 0: colors.append(0) import heapq heapq.heapify(colors) penalty = 0 while (len(colors) > 2): a = heapq.heappop(colors) b = heapq.heappop(colors) c = heapq.heappop(colors) penalty += (a + b + c) ...
3
1,004
A
Sonya and Hotels
PROGRAMMING
900
[ "implementation" ]
null
null
Sonya decided that having her own hotel business is the best way of earning money because she can profit and rest wherever she wants. The country where Sonya lives is an endless line. There is a city in each integer coordinate on this line. She has $n$ hotels, where the $i$-th hotel is located in the city with coordin...
The first line contains two integers $n$ and $d$ ($1\leq n\leq 100$, $1\leq d\leq 10^9$)Β β€” the number of Sonya's hotels and the needed minimum distance from a new hotel to all others. The second line contains $n$ different integers in strictly increasing order $x_1, x_2, \ldots, x_n$ ($-10^9\leq x_i\leq 10^9$)Β β€” coord...
Print the number of cities where Sonya can build a new hotel so that the minimum distance from this hotel to all others is equal to $d$.
[ "4 3\n-3 2 9 16\n", "5 2\n4 8 11 18 19\n" ]
[ "6\n", "5\n" ]
In the first example, there are $6$ possible cities where Sonya can build a hotel. These cities have coordinates $-6$, $5$, $6$, $12$, $13$, and $19$. In the second example, there are $5$ possible cities where Sonya can build a hotel. These cities have coordinates $2$, $6$, $13$, $16$, and $21$.
500
[ { "input": "4 3\n-3 2 9 16", "output": "6" }, { "input": "5 2\n4 8 11 18 19", "output": "5" }, { "input": "10 10\n-67 -59 -49 -38 -8 20 41 59 74 83", "output": "8" }, { "input": "10 10\n0 20 48 58 81 95 111 137 147 159", "output": "9" }, { "input": "100 1\n0 1 2 3...
1,611,549,412
2,147,483,647
PyPy 3
OK
TESTS
45
140
2,560,000
import functools import time def timer(func): @functools.wraps(func) def wrapper(*args, **kwargs): stime = time.perf_counter() res = func(*args, **kwargs) elapsed = time.perf_counter() - stime print(f"{func.__name__} in {elapsed:.4f} secs") return res retu...
Title: Sonya and Hotels Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sonya decided that having her own hotel business is the best way of earning money because she can profit and rest wherever she wants. The country where Sonya lives is an endless line. There is a city in each integer c...
```python import functools import time def timer(func): @functools.wraps(func) def wrapper(*args, **kwargs): stime = time.perf_counter() res = func(*args, **kwargs) elapsed = time.perf_counter() - stime print(f"{func.__name__} in {elapsed:.4f} secs") return res...
3
803
C
Maximal GCD
PROGRAMMING
1,900
[ "constructive algorithms", "greedy", "math" ]
null
null
You are given positive integer number *n*. You should create such strictly increasing sequence of *k* positive numbers *a*1,<=*a*2,<=...,<=*a**k*, that their sum is equal to *n* and greatest common divisor is maximal. Greatest common divisor of sequence is maximum of such numbers that every element of sequence is divi...
The first line consists of two numbers *n* and *k* (1<=≀<=*n*,<=*k*<=≀<=1010).
If the answer exists then output *k* numbers β€” resulting sequence. Otherwise output -1. If there are multiple answers, print any of them.
[ "6 3\n", "8 2\n", "5 3\n" ]
[ "1 2 3\n", "2 6\n", "-1\n" ]
none
0
[ { "input": "6 3", "output": "1 2 3" }, { "input": "8 2", "output": "2 6" }, { "input": "5 3", "output": "-1" }, { "input": "1 1", "output": "1" }, { "input": "1 2", "output": "-1" }, { "input": "2 1", "output": "2" }, { "input": "2 10000000...
1,638,879,267
1,467
PyPy 3
OK
TESTS
138
186
9,625,600
def make_divisors(n): divisors = [] for i in range(1, int(n**0.5)+1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n//i) return divisors n, k = map(int, input().split()) D = make_divisors(n) D.sort(reverse=True) x = k*(k+1)/...
Title: Maximal GCD Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given positive integer number *n*. You should create such strictly increasing sequence of *k* positive numbers *a*1,<=*a*2,<=...,<=*a**k*, that their sum is equal to *n* and greatest common divisor is maximal. Grea...
```python def make_divisors(n): divisors = [] for i in range(1, int(n**0.5)+1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n//i) return divisors n, k = map(int, input().split()) D = make_divisors(n) D.sort(reverse=True) x ...
3
296
A
Yaroslav and Permutations
PROGRAMMING
1,100
[ "greedy", "math" ]
null
null
Yaroslav has an array that consists of *n* integers. In one second Yaroslav can swap two neighboring array elements. Now Yaroslav is wondering if he can obtain an array where any two neighboring elements would be distinct in a finite time. Help Yaroslav.
The first line contains integer *n* (1<=≀<=*n*<=≀<=100) β€” the number of elements in the array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≀<=*a**i*<=≀<=1000) β€” the array elements.
In the single line print "YES" (without the quotes) if Yaroslav can obtain the array he needs, and "NO" (without the quotes) otherwise.
[ "1\n1\n", "3\n1 1 2\n", "4\n7 7 7 7\n" ]
[ "YES\n", "YES\n", "NO\n" ]
In the first sample the initial array fits well. In the second sample Yaroslav can get array: 1, 2, 1. He can swap the last and the second last elements to obtain it. In the third sample Yarosav can't get the array he needs.
500
[ { "input": "1\n1", "output": "YES" }, { "input": "3\n1 1 2", "output": "YES" }, { "input": "4\n7 7 7 7", "output": "NO" }, { "input": "4\n479 170 465 146", "output": "YES" }, { "input": "5\n996 437 605 996 293", "output": "YES" }, { "input": "6\n727 53...
1,623,578,381
2,147,483,647
Python 3
OK
TESTS
37
154
102,400
from collections import Counter n = int(input()) arr = list(map(int, input().split())) c = Counter(arr) import math max_v = -math.inf for k, v in c.items(): max_v = max(max_v, v) if max_v <= (n+1)//2: print('YES') else: print('NO')
Title: Yaroslav and Permutations Time Limit: None seconds Memory Limit: None megabytes Problem Description: Yaroslav has an array that consists of *n* integers. In one second Yaroslav can swap two neighboring array elements. Now Yaroslav is wondering if he can obtain an array where any two neighboring elements would...
```python from collections import Counter n = int(input()) arr = list(map(int, input().split())) c = Counter(arr) import math max_v = -math.inf for k, v in c.items(): max_v = max(max_v, v) if max_v <= (n+1)//2: print('YES') else: print('NO') ```
3
69
A
Young Physicist
PROGRAMMING
1,000
[ "implementation", "math" ]
A. Young Physicist
2
256
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy...
The first line contains a positive integer *n* (1<=≀<=*n*<=≀<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≀<=*x**i*,<=*y**i*,<=*z**i*<=≀<=100).
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
[ "3\n4 1 7\n-2 4 -1\n1 -5 -3\n", "3\n3 -1 7\n-5 2 -4\n2 -1 -3\n" ]
[ "NO", "YES" ]
none
500
[ { "input": "3\n4 1 7\n-2 4 -1\n1 -5 -3", "output": "NO" }, { "input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3", "output": "YES" }, { "input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41", "output": "NO" }, { "input": "10...
1,584,121,670
2,147,483,647
Python 3
OK
TESTS
81
312
0
n=int(input()) l=[] a,b,c=0,0,0 for i in range(n): l1=list(map(int,input().split(' '))) l.append(l1) for i in range(n): a+=l[i][0] b+=l[i][1] c+=l[i][2] if(a==0 and b==0 and c==0): print('YES') else: print('NO')
Title: Young Physicist Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. S...
```python n=int(input()) l=[] a,b,c=0,0,0 for i in range(n): l1=list(map(int,input().split(' '))) l.append(l1) for i in range(n): a+=l[i][0] b+=l[i][1] c+=l[i][2] if(a==0 and b==0 and c==0): print('YES') else: print('NO') ```
3.922
343
A
Rational Resistance
PROGRAMMING
1,600
[ "math", "number theory" ]
null
null
Mad scientist Mike is building a time machine in his spare time. To finish the work, he needs a resistor with a certain resistance value. However, all Mike has is lots of identical resistors with unit resistance *R*0<==<=1. Elements with other resistance can be constructed from these resistors. In this problem, we wil...
The single input line contains two space-separated integers *a* and *b* (1<=≀<=*a*,<=*b*<=≀<=1018). It is guaranteed that the fraction is irreducible. It is guaranteed that a solution always exists.
Print a single number β€” the answer to the problem. Please do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is recommended to use the cin, cout streams or the %I64d specifier.
[ "1 1\n", "3 2\n", "199 200\n" ]
[ "1\n", "3\n", "200\n" ]
In the first sample, one resistor is enough. In the second sample one can connect the resistors in parallel, take the resulting element and connect it to a third resistor consecutively. Then, we get an element with resistance <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/5305da389756aab6...
500
[ { "input": "1 1", "output": "1" }, { "input": "3 2", "output": "3" }, { "input": "199 200", "output": "200" }, { "input": "1 1000000000000000000", "output": "1000000000000000000" }, { "input": "3 1", "output": "3" }, { "input": "21 8", "output": "7...
1,595,098,739
2,147,483,647
Python 3
OK
TESTS
53
218
6,758,400
n,m=map(int,input().split()) a=0 while m: a += n//m n, m = m, n%m print(a)
Title: Rational Resistance Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mad scientist Mike is building a time machine in his spare time. To finish the work, he needs a resistor with a certain resistance value. However, all Mike has is lots of identical resistors with unit resistance *R...
```python n,m=map(int,input().split()) a=0 while m: a += n//m n, m = m, n%m print(a) ```
3
271
A
Beautiful Year
PROGRAMMING
800
[ "brute force" ]
null
null
It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits. Now you are suggested to solve the following problem: given a year number, find the minimum year number which is strictly larger than the given one and has on...
The single line contains integer *y* (1000<=≀<=*y*<=≀<=9000) β€” the year number.
Print a single integer β€” the minimum year number that is strictly larger than *y* and all it's digits are distinct. It is guaranteed that the answer exists.
[ "1987\n", "2013\n" ]
[ "2013\n", "2014\n" ]
none
500
[ { "input": "1987", "output": "2013" }, { "input": "2013", "output": "2014" }, { "input": "1000", "output": "1023" }, { "input": "1001", "output": "1023" }, { "input": "1234", "output": "1235" }, { "input": "5555", "output": "5601" }, { "inp...
1,690,459,752
2,147,483,647
Python 3
OK
TESTS
27
92
0
def d_d(year): y_str = str(year) return len(set(y_str)) == len(y_str) def n_y(y): y += 1 while not d_d(y): y += 1 return y y = int(input()) r = n_y(y) print(r)
Title: Beautiful Year Time Limit: None seconds Memory Limit: None megabytes Problem Description: It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits. Now you are suggested to solve the following problem: give...
```python def d_d(year): y_str = str(year) return len(set(y_str)) == len(y_str) def n_y(y): y += 1 while not d_d(y): y += 1 return y y = int(input()) r = n_y(y) print(r) ```
3
758
A
Holiday Of Equality
PROGRAMMING
800
[ "implementation", "math" ]
null
null
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 *a**i* burles (burle is the currency in Berl...
The first line contains the integer *n* (1<=≀<=*n*<=≀<=100)Β β€” the number of citizens in the kingdom. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* (0<=≀<=*a**i*<=≀<=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.
[ "5\n0 1 2 3 4\n", "5\n1 1 0 1 1\n", "3\n1 3 1\n", "1\n12\n" ]
[ "10", "1", "4", "0" ]
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 thi...
500
[ { "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" }, { "input": "3\n1 2 3", "output": "3" }, { "input": "14\n52518 718438 358883 462189 853...
1,679,655,383
2,147,483,647
Python 3
OK
TESTS
41
46
0
n = int(input()) a = list(map(int,input().split())) S = 0 x = max(a) for i in range(n): S += x-a[i] print(S)
Title: Holiday Of Equality Time Limit: None seconds Memory Limit: None megabytes Problem Description: 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...
```python n = int(input()) a = list(map(int,input().split())) S = 0 x = max(a) for i in range(n): S += x-a[i] print(S) ```
3
918
B
Radio Station
PROGRAMMING
900
[ "implementation", "strings" ]
null
null
As the guys fried the radio station facilities, the school principal gave them tasks as a punishment. Dustin's task was to add comments to nginx configuration for school's website. The school has *n* servers. Each server has a name and an ip (names aren't necessarily unique, but ips are). Dustin knows the ip and name o...
The first line of input contains two integers *n* and *m* (1<=≀<=*n*,<=*m*<=≀<=1000). The next *n* lines contain the names and ips of the servers. Each line contains a string name, name of the server and a string ip, ip of the server, separated by space (1<=≀<=|*name*|<=≀<=10, *name* only consists of English lowercase...
Print *m* lines, the commands in the configuration file after Dustin did his task.
[ "2 2\nmain 192.168.0.2\nreplica 192.168.0.1\nblock 192.168.0.1;\nproxy 192.168.0.2;\n", "3 5\ngoogle 8.8.8.8\ncodeforces 212.193.33.27\nserver 138.197.64.57\nredirect 138.197.64.57;\nblock 8.8.8.8;\ncf 212.193.33.27;\nunblock 8.8.8.8;\ncheck 138.197.64.57;\n" ]
[ "block 192.168.0.1; #replica\nproxy 192.168.0.2; #main\n", "redirect 138.197.64.57; #server\nblock 8.8.8.8; #google\ncf 212.193.33.27; #codeforces\nunblock 8.8.8.8; #google\ncheck 138.197.64.57; #server\n" ]
none
1,000
[ { "input": "2 2\nmain 192.168.0.2\nreplica 192.168.0.1\nblock 192.168.0.1;\nproxy 192.168.0.2;", "output": "block 192.168.0.1; #replica\nproxy 192.168.0.2; #main" }, { "input": "3 5\ngoogle 8.8.8.8\ncodeforces 212.193.33.27\nserver 138.197.64.57\nredirect 138.197.64.57;\nblock 8.8.8.8;\ncf 212.193.3...
1,665,197,098
2,147,483,647
PyPy 3-64
OK
TESTS
28
140
7,782,400
n, m = map(int, input().split()) d={} for i in range(n): name, ip = input().split() d[ip] = name for i in range(m): name, ip = input().split() print(name,ip,"#"+d[ip[:-1]])
Title: Radio Station Time Limit: None seconds Memory Limit: None megabytes Problem Description: As the guys fried the radio station facilities, the school principal gave them tasks as a punishment. Dustin's task was to add comments to nginx configuration for school's website. The school has *n* servers. Each server ...
```python n, m = map(int, input().split()) d={} for i in range(n): name, ip = input().split() d[ip] = name for i in range(m): name, ip = input().split() print(name,ip,"#"+d[ip[:-1]]) ```
3
758
A
Holiday Of Equality
PROGRAMMING
800
[ "implementation", "math" ]
null
null
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 *a**i* burles (burle is the currency in Berl...
The first line contains the integer *n* (1<=≀<=*n*<=≀<=100)Β β€” the number of citizens in the kingdom. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* (0<=≀<=*a**i*<=≀<=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.
[ "5\n0 1 2 3 4\n", "5\n1 1 0 1 1\n", "3\n1 3 1\n", "1\n12\n" ]
[ "10", "1", "4", "0" ]
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 thi...
500
[ { "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" }, { "input": "3\n1 2 3", "output": "3" }, { "input": "14\n52518 718438 358883 462189 853...
1,651,077,355
2,147,483,647
Python 3
OK
TESTS
41
46
0
n = int(input()) nums = list(map(int, input().split())) top = max(nums) output = 0 for item in nums: output += top - item print(output)
Title: Holiday Of Equality Time Limit: None seconds Memory Limit: None megabytes Problem Description: 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...
```python n = int(input()) nums = list(map(int, input().split())) top = max(nums) output = 0 for item in nums: output += top - item print(output) ```
3
486
A
Calculating Function
PROGRAMMING
800
[ "implementation", "math" ]
null
null
For a positive integer *n* let's define a function *f*: *f*(*n*)<==<=<=-<=1<=+<=2<=-<=3<=+<=..<=+<=(<=-<=1)*n**n* Your task is to calculate *f*(*n*) for a given integer *n*.
The single line contains the positive integer *n* (1<=≀<=*n*<=≀<=1015).
Print *f*(*n*) in a single line.
[ "4\n", "5\n" ]
[ "2\n", "-3\n" ]
*f*(4) =  - 1 + 2 - 3 + 4 = 2 *f*(5) =  - 1 + 2 - 3 + 4 - 5 =  - 3
500
[ { "input": "4", "output": "2" }, { "input": "5", "output": "-3" }, { "input": "1000000000", "output": "500000000" }, { "input": "1000000001", "output": "-500000001" }, { "input": "1000000000000000", "output": "500000000000000" }, { "input": "100", ...
1,698,088,107
2,147,483,647
Python 3
OK
TESTS
39
46
0
x = int(input()) if x % 2 == 0: print(x // 2) else: print(-1 * ((x + 1) // 2))
Title: Calculating Function Time Limit: None seconds Memory Limit: None megabytes Problem Description: For a positive integer *n* let's define a function *f*: *f*(*n*)<==<=<=-<=1<=+<=2<=-<=3<=+<=..<=+<=(<=-<=1)*n**n* Your task is to calculate *f*(*n*) for a given integer *n*. Input Specification: The single line...
```python x = int(input()) if x % 2 == 0: print(x // 2) else: print(-1 * ((x + 1) // 2)) ```
3
34
B
Sale
PROGRAMMING
900
[ "greedy", "sortings" ]
B. Sale
2
256
Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price β€” their owners are ready to pay Bob if he buys their useless apparatus. Bob can Β«buyΒ» any TV sets he wants. Though he's very strong, Bob can carry at most *m* TV set...
The first line contains two space-separated integers *n* and *m* (1<=≀<=*m*<=≀<=*n*<=≀<=100) β€” amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains *n* space-separated integers *a**i* (<=-<=1000<=≀<=*a**i*<=≀<=1000) β€” prices of the TV sets.
Output the only number β€” the maximum sum of money that Bob can earn, given that he can carry at most *m* TV sets.
[ "5 3\n-6 0 35 -2 4\n", "4 2\n7 0 0 -7\n" ]
[ "8\n", "7\n" ]
none
1,000
[ { "input": "5 3\n-6 0 35 -2 4", "output": "8" }, { "input": "4 2\n7 0 0 -7", "output": "7" }, { "input": "6 6\n756 -611 251 -66 572 -818", "output": "1495" }, { "input": "5 5\n976 437 937 788 518", "output": "0" }, { "input": "5 3\n-2 -2 -2 -2 -2", "output": "...
1,684,054,638
2,147,483,647
Python 3
OK
TESTS
25
92
0
n,m=map(int,input().split()) a=list(map(int,input().split())) s=0 b=[] for i in a: if i<0: b.append(-i) b.sort(reverse=True) if len(b)<m: s=sum(b) else: for i in range(m): s=s+b[i] print(s)
Title: Sale Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price β€” their owners are ready to pay Bob if he buys their useless apparatus. Bob can...
```python n,m=map(int,input().split()) a=list(map(int,input().split())) s=0 b=[] for i in a: if i<0: b.append(-i) b.sort(reverse=True) if len(b)<m: s=sum(b) else: for i in range(m): s=s+b[i] print(s) ```
3.977
262
A
Roma and Lucky Numbers
PROGRAMMING
800
[ "implementation" ]
null
null
Roma (a popular Russian name that means 'Roman') loves the Little Lvov Elephant's lucky numbers. Let us remind you that lucky numbers are positive integers whose decimal representation only contains lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Roma's got *n* positive integer...
The first line contains two integers *n*, *k* (1<=≀<=*n*,<=*k*<=≀<=100). The second line contains *n* integers *a**i* (1<=≀<=*a**i*<=≀<=109) β€” the numbers that Roma has. The numbers in the lines are separated by single spaces.
In a single line print a single integer β€” the answer to the problem.
[ "3 4\n1 2 4\n", "3 2\n447 44 77\n" ]
[ "3\n", "2\n" ]
In the first sample all numbers contain at most four lucky digits, so the answer is 3. In the second sample number 447 doesn't fit in, as it contains more than two lucky digits. All other numbers are fine, so the answer is 2.
500
[ { "input": "3 4\n1 2 4", "output": "3" }, { "input": "3 2\n447 44 77", "output": "2" }, { "input": "2 2\n507978501 180480073", "output": "2" }, { "input": "9 6\n655243746 167613748 1470546 57644035 176077477 56984809 44677 215706823 369042089", "output": "9" }, { ...
1,581,844,211
2,147,483,647
PyPy 3
OK
TESTS
34
280
0
x,y=map(int,input().split()) print(sum(list(map((lambda i: 1 if i.count('4')+i.count('7')<=y else 0),input().split())))) #author:SK__Shanto__γ‹› #code__define__your__smartness
Title: Roma and Lucky Numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Roma (a popular Russian name that means 'Roman') loves the Little Lvov Elephant's lucky numbers. Let us remind you that lucky numbers are positive integers whose decimal representation only contains lucky digits...
```python x,y=map(int,input().split()) print(sum(list(map((lambda i: 1 if i.count('4')+i.count('7')<=y else 0),input().split())))) #author:SK__Shanto__γ‹› #code__define__your__smartness ```
3
25
A
IQ test
PROGRAMMING
1,300
[ "brute force" ]
A. IQ test
2
256
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob β€” to check his answers, he needs a program that among the given *n* numbers finds one that i...
The first line contains integer *n* (3<=≀<=*n*<=≀<=100) β€” amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
[ "5\n2 4 7 8 10\n", "4\n1 2 1 1\n" ]
[ "3\n", "2\n" ]
none
0
[ { "input": "5\n2 4 7 8 10", "output": "3" }, { "input": "4\n1 2 1 1", "output": "2" }, { "input": "3\n1 2 2", "output": "1" }, { "input": "3\n100 99 100", "output": "2" }, { "input": "3\n5 3 2", "output": "3" }, { "input": "4\n43 28 1 91", "output"...
1,635,875,455
2,147,483,647
Python 3
OK
TESTS
32
92
4,505,600
num = int(input()) numbers = [int(num) for num in input().split(" ")] evens = 0 odds = 0 even_index = 0 odd_index = 0 for number in numbers: if number % 2: odds += 1 odd_index = numbers.index(number) + 1 else: evens += 1 even_index = numbers.index(number) + 1 if evens == 1: ...
Title: IQ test Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob β€” t...
```python num = int(input()) numbers = [int(num) for num in input().split(" ")] evens = 0 odds = 0 even_index = 0 odd_index = 0 for number in numbers: if number % 2: odds += 1 odd_index = numbers.index(number) + 1 else: evens += 1 even_index = numbers.index(number) + 1 if evens ...
3.968608
11
A
Increasing Sequence
PROGRAMMING
900
[ "constructive algorithms", "implementation", "math" ]
A. Increasing Sequence
1
64
A sequence *a*0,<=*a*1,<=...,<=*a**t*<=-<=1 is called increasing if *a**i*<=-<=1<=&lt;<=*a**i* for each *i*:<=0<=&lt;<=*i*<=&lt;<=*t*. You are given a sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 and a positive integer *d*. In each move you may choose one element of the given sequence and add *d* to it. What is the least...
The first line of the input contains two integer numbers *n* and *d* (2<=≀<=*n*<=≀<=2000,<=1<=≀<=*d*<=≀<=106). The second line contains space separated sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 (1<=≀<=*b**i*<=≀<=106).
Output the minimal number of moves needed to make the sequence increasing.
[ "4 2\n1 3 3 2\n" ]
[ "3\n" ]
none
0
[ { "input": "4 2\n1 3 3 2", "output": "3" }, { "input": "2 1\n1 1", "output": "1" }, { "input": "2 1\n2 5", "output": "0" }, { "input": "2 1\n1 2", "output": "0" }, { "input": "2 1\n1 1", "output": "1" }, { "input": "2 7\n10 20", "output": "0" }, ...
1,563,041,662
2,147,483,647
Python 3
OK
TESTS
25
248
307,200
n, d = [int(i) for i in input().split()] lst = [int(i) for i in input().split()] count1, count2 = 0, 0 for elem in lst: if elem <= count1: c = (count1 + d - elem) // d count2 += c elem += c * d count1 = elem print(count2)
Title: Increasing Sequence Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: A sequence *a*0,<=*a*1,<=...,<=*a**t*<=-<=1 is called increasing if *a**i*<=-<=1<=&lt;<=*a**i* for each *i*:<=0<=&lt;<=*i*<=&lt;<=*t*. You are given a sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 and a positive integer *d*...
```python n, d = [int(i) for i in input().split()] lst = [int(i) for i in input().split()] count1, count2 = 0, 0 for elem in lst: if elem <= count1: c = (count1 + d - elem) // d count2 += c elem += c * d count1 = elem print(count2) ```
3.873711
915
C
Permute Digits
PROGRAMMING
1,700
[ "dp", "greedy" ]
null
null
You are given two positive integer numbers *a* and *b*. Permute (change order) of the digits of *a* to construct maximal number not exceeding *b*. No number in input and/or output can start with the digit 0. It is allowed to leave *a* as it is.
The first line contains integer *a* (1<=≀<=*a*<=≀<=1018). The second line contains integer *b* (1<=≀<=*b*<=≀<=1018). Numbers don't have leading zeroes. It is guaranteed that answer exists.
Print the maximum possible number that is a permutation of digits of *a* and is not greater than *b*. The answer can't have any leading zeroes. It is guaranteed that the answer exists. The number in the output should have exactly the same length as number *a*. It should be a permutation of digits of *a*.
[ "123\n222\n", "3921\n10000\n", "4940\n5000\n" ]
[ "213\n", "9321\n", "4940\n" ]
none
0
[ { "input": "123\n222", "output": "213" }, { "input": "3921\n10000", "output": "9321" }, { "input": "4940\n5000", "output": "4940" }, { "input": "23923472834\n23589234723", "output": "23498743322" }, { "input": "102391019\n491010301", "output": "399211100" },...
1,629,816,682
2,147,483,647
PyPy 3
OK
TESTS
157
124
21,708,800
a = list(input()) b = list(input()) n = len(a) a.sort() def listtostring(string): return ''.join([str(ele) for ele in string]) for i in range(0,n): for j in range(0,n): t = a.copy() t[i],t[j] = t[j],t[i] if((int(listtostring(t)) >= int(listtostring(a))) and (int(listtostr...
Title: Permute Digits Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given two positive integer numbers *a* and *b*. Permute (change order) of the digits of *a* to construct maximal number not exceeding *b*. No number in input and/or output can start with the digit 0. It is allow...
```python a = list(input()) b = list(input()) n = len(a) a.sort() def listtostring(string): return ''.join([str(ele) for ele in string]) for i in range(0,n): for j in range(0,n): t = a.copy() t[i],t[j] = t[j],t[i] if((int(listtostring(t)) >= int(listtostring(a))) and (int...
3
61
A
Ultra-Fast Mathematician
PROGRAMMING
800
[ "implementation" ]
A. Ultra-Fast Mathematician
2
256
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second. One day in 230 AD Shapur was trying to find out if any one can possibly do...
There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100.
Write one line β€” the corresponding answer. Do not omit the leading 0s.
[ "1010100\n0100101\n", "000\n111\n", "1110\n1010\n", "01110\n01100\n" ]
[ "1110001\n", "111\n", "0100\n", "00010\n" ]
none
500
[ { "input": "1010100\n0100101", "output": "1110001" }, { "input": "000\n111", "output": "111" }, { "input": "1110\n1010", "output": "0100" }, { "input": "01110\n01100", "output": "00010" }, { "input": "011101\n000001", "output": "011100" }, { "input": "...
1,500,646,677
2,147,483,647
Python 3
OK
TESTS
102
62
4,608,000
num=[[i for i in input()] for j in range(2)] n1=list(num[0][:]) n2=list(num[1][:]) ans=[] for i in range(len(n1)): if n1[i]!=n2[i]: ans.append("1") else: ans.append("0") print("".join(ans))
Title: Ultra-Fast Mathematician Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 10...
```python num=[[i for i in input()] for j in range(2)] n1=list(num[0][:]) n2=list(num[1][:]) ans=[] for i in range(len(n1)): if n1[i]!=n2[i]: ans.append("1") else: ans.append("0") print("".join(ans)) ```
3.975917
510
A
Fox And Snake
PROGRAMMING
800
[ "implementation" ]
null
null
Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead. A snake is a pattern on a *n* by *m* table. Denote *c*-th cell of *r*-th row as (*r*,<=*c*). The tail of the snake is located at (1,<=1), then it's body ...
The only line contains two integers: *n* and *m* (3<=≀<=*n*,<=*m*<=≀<=50). *n* is an odd number.
Output *n* lines. Each line should contain a string consisting of *m* characters. Do not output spaces.
[ "3 3\n", "3 4\n", "5 3\n", "9 9\n" ]
[ "###\n..#\n###\n", "####\n...#\n####\n", "###\n..#\n###\n#..\n###\n", "#########\n........#\n#########\n#........\n#########\n........#\n#########\n#........\n#########\n" ]
none
500
[ { "input": "3 3", "output": "###\n..#\n###" }, { "input": "3 4", "output": "####\n...#\n####" }, { "input": "5 3", "output": "###\n..#\n###\n#..\n###" }, { "input": "9 9", "output": "#########\n........#\n#########\n#........\n#########\n........#\n#########\n#........\n#...
1,675,835,992
2,147,483,647
Python 3
OK
TESTS
28
46
0
nums = [int(i) for i in input().split()] n,m = nums[0], nums[1] pos = True #True means right for i in range(n): if i%2 == 0: for i in range(m): print("#", end="") else: if pos == True: for i in range(m-1): print(".",end="") print("#",end="") ...
Title: Fox And Snake Time Limit: None seconds Memory Limit: None megabytes Problem Description: Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead. A snake is a pattern on a *n* by *m* table. Denote *c*...
```python nums = [int(i) for i in input().split()] n,m = nums[0], nums[1] pos = True #True means right for i in range(n): if i%2 == 0: for i in range(m): print("#", end="") else: if pos == True: for i in range(m-1): print(".",end="") print("#",...
3
339
A
Helpful Maths
PROGRAMMING
800
[ "greedy", "implementation", "sortings", "strings" ]
null
null
Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation. The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To make the calculation easier, the sum only contains numbers 1, 2 and 3. Still, that isn't enough for Xe...
The first line contains a non-empty string *s* β€” the sum Xenia needs to count. String *s* contains no spaces. It only contains digits and characters "+". Besides, string *s* is a correct sum of numbers 1, 2 and 3. String *s* is at most 100 characters long.
Print the new sum that Xenia can count.
[ "3+2+1\n", "1+1+3+1+3\n", "2\n" ]
[ "1+2+3\n", "1+1+1+3+3\n", "2\n" ]
none
500
[ { "input": "3+2+1", "output": "1+2+3" }, { "input": "1+1+3+1+3", "output": "1+1+1+3+3" }, { "input": "2", "output": "2" }, { "input": "2+2+1+1+3", "output": "1+1+2+2+3" }, { "input": "2+1+2+2+2+3+1+3+1+2", "output": "1+1+1+2+2+2+2+2+3+3" }, { "input": ...
1,696,212,604
2,147,483,647
PyPy 3-64
OK
TESTS
21
124
0
#removes plus signs then orders numbers in ascending order numbers = input().split('+') numbers.sort() #adds each number with a plus sign, then ticks up until the last number is printed without the sign. summation = " " tick = 0 for number in numbers: if tick == (len(numbers)-1): summation += f'{number}...
Title: Helpful Maths Time Limit: None seconds Memory Limit: None megabytes Problem Description: Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation. The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To mak...
```python #removes plus signs then orders numbers in ascending order numbers = input().split('+') numbers.sort() #adds each number with a plus sign, then ticks up until the last number is printed without the sign. summation = " " tick = 0 for number in numbers: if tick == (len(numbers)-1): summation += ...
3
350
A
TL
PROGRAMMING
1,200
[ "brute force", "greedy", "implementation" ]
null
null
Valera wanted to prepare a Codesecrof round. He's already got one problem and he wants to set a time limit (TL) on it. Valera has written *n* correct solutions. For each correct solution, he knows its running time (in seconds). Valera has also wrote *m* wrong solutions and for each wrong solution he knows its running ...
The first line contains two integers *n*, *m* (1<=≀<=*n*,<=*m*<=≀<=100). The second line contains *n* space-separated positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≀<=*a**i*<=≀<=100) β€” the running time of each of the *n* correct solutions in seconds. The third line contains *m* space-separated positive integers *b*1...
If there is a valid TL value, print it. Otherwise, print -1.
[ "3 6\n4 5 2\n8 9 6 10 7 11\n", "3 1\n3 4 5\n6\n" ]
[ "5", "-1\n" ]
none
500
[ { "input": "3 6\n4 5 2\n8 9 6 10 7 11", "output": "5" }, { "input": "3 1\n3 4 5\n6", "output": "-1" }, { "input": "2 5\n45 99\n49 41 77 83 45", "output": "-1" }, { "input": "50 50\n18 13 5 34 10 36 36 12 15 11 16 17 14 36 23 45 32 24 31 18 24 32 7 1 31 3 49 8 16 23 3 39 47 43...
1,693,825,276
2,147,483,647
Python 3
OK
TESTS
45
92
0
nm=input().split() n=int(nm[0]) m=int(nm[1]) correct=list(map(int,input().split())) wrong=list(map(int,input().split())) point4=True if 2*min(correct)<max(correct): TL=max(correct) else: TL=2*min(correct) if min(wrong)<=TL: point4=False if point4: print(TL) else: print(-1)
Title: TL Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera wanted to prepare a Codesecrof round. He's already got one problem and he wants to set a time limit (TL) on it. Valera has written *n* correct solutions. For each correct solution, he knows its running time (in seconds). Val...
```python nm=input().split() n=int(nm[0]) m=int(nm[1]) correct=list(map(int,input().split())) wrong=list(map(int,input().split())) point4=True if 2*min(correct)<max(correct): TL=max(correct) else: TL=2*min(correct) if min(wrong)<=TL: point4=False if point4: print(TL) else: print(-1) `...
3
990
A
Commentary Boxes
PROGRAMMING
1,000
[ "implementation", "math" ]
null
null
Berland Football Cup starts really soon! Commentators from all over the world come to the event. Organizers have already built $n$ commentary boxes. $m$ regional delegations will come to the Cup. Every delegation should get the same number of the commentary boxes. If any box is left unoccupied then the delegations wil...
The only line contains four integer numbers $n$, $m$, $a$ and $b$ ($1 \le n, m \le 10^{12}$, $1 \le a, b \le 100$), where $n$ is the initial number of the commentary boxes, $m$ is the number of delegations to come, $a$ is the fee to build a box and $b$ is the fee to demolish a box.
Output the minimal amount of burles organizers should pay to satisfy all the delegations (i.e. to make the number of the boxes be divisible by $m$). It is allowed that the final number of the boxes is equal to $0$.
[ "9 7 3 8\n", "2 7 3 7\n", "30 6 17 19\n" ]
[ "15\n", "14\n", "0\n" ]
In the first example organizers can build $5$ boxes to make the total of $14$ paying $3$ burles for the each of them. In the second example organizers can demolish $2$ boxes to make the total of $0$ paying $7$ burles for the each of them. In the third example organizers are already able to distribute all the boxes eq...
0
[ { "input": "9 7 3 8", "output": "15" }, { "input": "2 7 3 7", "output": "14" }, { "input": "30 6 17 19", "output": "0" }, { "input": "500000000001 1000000000000 100 100", "output": "49999999999900" }, { "input": "1000000000000 750000000001 10 100", "output": "...
1,587,374,415
2,147,483,647
Python 3
OK
TESTS
109
109
0
n,m,a,b=map(int,input().split()) print(min(n%m*b,(m-n%m)*a)) f=6 g=9 h=g-f
Title: Commentary Boxes Time Limit: None seconds Memory Limit: None megabytes Problem Description: Berland Football Cup starts really soon! Commentators from all over the world come to the event. Organizers have already built $n$ commentary boxes. $m$ regional delegations will come to the Cup. Every delegation shou...
```python n,m,a,b=map(int,input().split()) print(min(n%m*b,(m-n%m)*a)) f=6 g=9 h=g-f ```
3
611
B
New Year and Old Property
PROGRAMMING
1,300
[ "bitmasks", "brute force", "implementation" ]
null
null
The year 2015 is almost over. Limak is a little polar bear. He has recently learnt about the binary system. He noticed that the passing year has exactly one zero in its representation in the binary systemΒ β€” 201510<==<=111110111112. Note that he doesn't care about the number of zeros in the decimal representation. Lim...
The only line of the input contains two integers *a* and *b* (1<=≀<=*a*<=≀<=*b*<=≀<=1018)Β β€” the first year and the last year in Limak's interval respectively.
Print one integer – the number of years Limak will count in his chosen interval.
[ "5 10\n", "2015 2015\n", "100 105\n", "72057594000000000 72057595000000000\n" ]
[ "2\n", "1\n", "0\n", "26\n" ]
In the first sample Limak's interval contains numbers 5<sub class="lower-index">10</sub> = 101<sub class="lower-index">2</sub>, 6<sub class="lower-index">10</sub> = 110<sub class="lower-index">2</sub>, 7<sub class="lower-index">10</sub> = 111<sub class="lower-index">2</sub>, 8<sub class="lower-index">10</sub> = 1000<su...
750
[ { "input": "5 10", "output": "2" }, { "input": "2015 2015", "output": "1" }, { "input": "100 105", "output": "0" }, { "input": "72057594000000000 72057595000000000", "output": "26" }, { "input": "1 100", "output": "16" }, { "input": "100000000000000000...
1,451,490,268
2,368
Python 3
OK
TESTS
103
77
0
def clc(n): ans = 0 ns = "{0:b}".format(n) for k in range(1,len(ns)): ans += k-1 ns = ns[1:] while ns: if ns[0] == '1': ans += 1 ns = ns[1:] else: if ns == '0'+'1'*(len(ns)-1): ans += 1 break return ans a, b = map(int, input().split()) ans = clc(b) if a > 1: ans -= clc(a-1) print(ans)
Title: New Year and Old Property Time Limit: None seconds Memory Limit: None megabytes Problem Description: The year 2015 is almost over. Limak is a little polar bear. He has recently learnt about the binary system. He noticed that the passing year has exactly one zero in its representation in the binary systemΒ β€” 2...
```python def clc(n): ans = 0 ns = "{0:b}".format(n) for k in range(1,len(ns)): ans += k-1 ns = ns[1:] while ns: if ns[0] == '1': ans += 1 ns = ns[1:] else: if ns == '0'+'1'*(len(ns)-1): ans += 1 break return ans a, b = map(int, input().split()) ans = clc(b) if a > 1: ans -= clc(a-1) print(an...
3
279
B
Books
PROGRAMMING
1,400
[ "binary search", "brute force", "implementation", "two pointers" ]
null
null
When Valera has got some free time, he goes to the library to read some books. Today he's got *t* free minutes to read. That's why Valera took *n* books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to *n*. Valera needs *a**i* minutes to...
The first line contains two integers *n* and *t* (1<=≀<=*n*<=≀<=105;Β 1<=≀<=*t*<=≀<=109) β€” the number of books and the number of free minutes Valera's got. The second line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≀<=*a**i*<=≀<=104), where number *a**i* shows the number of minutes that the boy n...
Print a single integer β€” the maximum number of books Valera can read.
[ "4 5\n3 1 2 1\n", "3 3\n2 2 3\n" ]
[ "3\n", "1\n" ]
none
1,000
[ { "input": "4 5\n3 1 2 1", "output": "3" }, { "input": "3 3\n2 2 3", "output": "1" }, { "input": "1 3\n5", "output": "0" }, { "input": "1 10\n4", "output": "1" }, { "input": "2 10\n6 4", "output": "2" }, { "input": "6 10\n2 3 4 2 1 1", "output": "4...
1,678,950,911
2,147,483,647
PyPy 3-64
OK
TESTS
38
218
14,233,600
from bisect import bisect """n, t = map(int, input().split()) arr = list(map(int, input().split())) pref = [0] for i in arr: pref.append(pref[-1]+i) ans = 0 for i in range(0, n+1): idx = bisect(pref, t+pref[i]) - 1 ans = max(ans, idx-i) print(ans)""" n, x = map(int, input().split()) ar...
Title: Books Time Limit: None seconds Memory Limit: None megabytes Problem Description: When Valera has got some free time, he goes to the library to read some books. Today he's got *t* free minutes to read. That's why Valera took *n* books in the library and for each book he estimated the time he is going to need t...
```python from bisect import bisect """n, t = map(int, input().split()) arr = list(map(int, input().split())) pref = [0] for i in arr: pref.append(pref[-1]+i) ans = 0 for i in range(0, n+1): idx = bisect(pref, t+pref[i]) - 1 ans = max(ans, idx-i) print(ans)""" n, x = map(int, input().sp...
3
381
A
Sereja and Dima
PROGRAMMING
800
[ "greedy", "implementation", "two pointers" ]
null
null
Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. Th...
The first line contains integer *n* (1<=≀<=*n*<=≀<=1000) β€” the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000.
On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game.
[ "4\n4 1 2 10\n", "7\n1 2 3 4 5 6 7\n" ]
[ "12 5\n", "16 12\n" ]
In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5.
500
[ { "input": "4\n4 1 2 10", "output": "12 5" }, { "input": "7\n1 2 3 4 5 6 7", "output": "16 12" }, { "input": "42\n15 29 37 22 16 5 26 31 6 32 19 3 45 36 33 14 25 20 48 7 42 11 24 28 9 18 8 21 47 17 38 40 44 4 35 1 43 39 41 27 12 13", "output": "613 418" }, { "input": "43\n32 ...
1,687,688,877
2,147,483,647
Python 3
OK
TESTS
34
31
0
def calculate_scores(n, cards): sereja_score = 0 dima_score = 0 left = 0 right = n - 1 for _ in range(n): if cards[left] > cards[right]: sereja_score += cards[left] left += 1 else: sereja_score += cards[right] right -= 1 ...
Title: Sereja and Dima Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. Du...
```python def calculate_scores(n, cards): sereja_score = 0 dima_score = 0 left = 0 right = n - 1 for _ in range(n): if cards[left] > cards[right]: sereja_score += cards[left] left += 1 else: sereja_score += cards[right] rig...
3
496
B
Secret Combination
PROGRAMMING
1,500
[ "brute force", "constructive algorithms", "implementation" ]
null
null
You got a box with a combination lock. The lock has a display showing *n* digits. There are two buttons on the box, each button changes digits on the display. You have quickly discovered that the first button adds 1 to all the digits (all digits 9 become digits 0), and the second button shifts all the digits on the dis...
The first line contains a single integer *n* (1<=≀<=*n*<=≀<=1000)Β β€” the number of digits on the display. The second line contains *n* digitsΒ β€” the initial state of the display.
Print a single line containing *n* digitsΒ β€” the desired state of the display containing the smallest possible number.
[ "3\n579\n", "4\n2014\n" ]
[ "024\n", "0142\n" ]
none
1,000
[ { "input": "3\n579", "output": "024" }, { "input": "4\n2014", "output": "0142" }, { "input": "1\n1", "output": "0" }, { "input": "3\n039", "output": "014" }, { "input": "4\n4444", "output": "0000" }, { "input": "5\n46802", "output": "02468" }, ...
1,581,388,006
2,147,483,647
Python 3
OK
TESTS
28
1,107
409,600
def parser(): while 1: data = list(input().split(' ')) for number in data: if len(number) > 0: yield(number) input_parser = parser() def get_word(): global input_parser return next(input_parser) def get_number(): data = get_word() try: return in...
Title: Secret Combination Time Limit: None seconds Memory Limit: None megabytes Problem Description: You got a box with a combination lock. The lock has a display showing *n* digits. There are two buttons on the box, each button changes digits on the display. You have quickly discovered that the first button adds 1 ...
```python def parser(): while 1: data = list(input().split(' ')) for number in data: if len(number) > 0: yield(number) input_parser = parser() def get_word(): global input_parser return next(input_parser) def get_number(): data = get_word() try: ...
3
1,010
B
Rocket
PROGRAMMING
1,800
[ "binary search", "interactive" ]
null
null
This is an interactive problem. Natasha is going to fly to Mars. Finally, Natasha sat in the rocket. She flies, flies... but gets bored. She wishes to arrive to Mars already! So she decides to find something to occupy herself. She couldn't think of anything better to do than to calculate the distance to the red planet...
The first line contains two integers $m$ and $n$ ($1 \le m \le 10^9$, $1 \le n \le 30$)Β β€” the maximum distance to Mars and the number of elements in the sequence $p$.
none
[ "5 2\n1\n-1\n-1\n1\n0\n" ]
[ "1\n2\n4\n5\n3\n" ]
In the example, hacking would look like this: 5 2 3 1 0 This means that the current distance to Mars is equal to $3$, Natasha knows that it does not exceed $5$, and the rocket answers in order: correctly, incorrectly, correctly, incorrectly ... Really: on the first query ($1$) the correct answer is $1$, the rocket...
750
[ { "input": "5 2 3\n1 0", "output": "3 queries, x=3" }, { "input": "1 1 1\n1", "output": "1 queries, x=1" }, { "input": "3 2 3\n1 0", "output": "4 queries, x=3" }, { "input": "6 3 5\n1 1 1", "output": "5 queries, x=5" }, { "input": "10 4 3\n0 0 1 0", "output": ...
1,676,569,397
2,147,483,647
PyPy 3-64
OK
TESTS
135
124
6,041,600
from heapq import heappush, heappop from collections import defaultdict, Counter, deque import threading import sys import bisect # input = sys.stdin.readline def ri(): return int(input()) def rs(): return input() def rl(): return list(map(int, input().split())) def rls(): return list(input().split()) # t...
Title: Rocket Time Limit: None seconds Memory Limit: None megabytes Problem Description: This is an interactive problem. Natasha is going to fly to Mars. Finally, Natasha sat in the rocket. She flies, flies... but gets bored. She wishes to arrive to Mars already! So she decides to find something to occupy herself. ...
```python from heapq import heappush, heappop from collections import defaultdict, Counter, deque import threading import sys import bisect # input = sys.stdin.readline def ri(): return int(input()) def rs(): return input() def rl(): return list(map(int, input().split())) def rls(): return list(input().split()...
3
99
A
Help Far Away Kingdom
PROGRAMMING
800
[ "strings" ]
A. Help Far Away Kingdom
2
256
In a far away kingdom lived the King, the Prince, the Shoemaker, the Dressmaker and many other citizens. They lived happily until great trouble came into the Kingdom. The ACMers settled there. Most damage those strange creatures inflicted upon the kingdom was that they loved high precision numbers. As a result, the Ki...
The first line contains a single number to round up β€” the integer part (a non-empty set of decimal digits that do not start with 0 β€” with the exception of a case when the set consists of a single digit β€” in this case 0 can go first), then follows character Β«.Β» (a dot), and then follows the fractional part (any non-empt...
If the last number of the integer part is not equal to 9, print the rounded-up number without leading zeroes. Otherwise, print the message "GOTO Vasilisa." (without the quotes).
[ "0.0\n", "1.49\n", "1.50\n", "2.71828182845904523536\n", "3.14159265358979323846\n", "12345678901234567890.1\n", "123456789123456789.999\n" ]
[ "0", "1", "2", "3", "3", "12345678901234567890", "GOTO Vasilisa." ]
none
500
[ { "input": "0.0", "output": "0" }, { "input": "1.49", "output": "1" }, { "input": "1.50", "output": "2" }, { "input": "2.71828182845904523536", "output": "3" }, { "input": "3.14159265358979323846", "output": "3" }, { "input": "12345678901234567890.1", ...
1,606,208,185
2,147,483,647
Python 3
OK
TESTS
150
218
0
s1 = input() m = s1.find('.') m2 = int(s1[:m]) m3 = int(s1[m+1:m+2]) if s1[m-1] == '9': print('GOTO Vasilisa.') else: if m3 >= 5: m2 += 1 print(m2) else: print(m2)
Title: Help Far Away Kingdom Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: In a far away kingdom lived the King, the Prince, the Shoemaker, the Dressmaker and many other citizens. They lived happily until great trouble came into the Kingdom. The ACMers settled there. Most damage those stran...
```python s1 = input() m = s1.find('.') m2 = int(s1[:m]) m3 = int(s1[m+1:m+2]) if s1[m-1] == '9': print('GOTO Vasilisa.') else: if m3 >= 5: m2 += 1 print(m2) else: print(m2) ```
3.9455
912
A
Tricky Alchemy
PROGRAMMING
800
[ "implementation" ]
null
null
During the winter holidays, the demand for Christmas balls is exceptionally high. Since it's already 2018, the advances in alchemy allow easy and efficient ball creation by utilizing magic crystals. Grisha needs to obtain some yellow, green and blue balls. It's known that to produce a yellow ball one needs two yellow ...
The first line features two integers *A* and *B* (0<=≀<=*A*,<=*B*<=≀<=109), denoting the number of yellow and blue crystals respectively at Grisha's disposal. The next line contains three integers *x*, *y* and *z* (0<=≀<=*x*,<=*y*,<=*z*<=≀<=109)Β β€” the respective amounts of yellow, green and blue balls to be obtained.
Print a single integerΒ β€” the minimum number of crystals that Grisha should acquire in addition.
[ "4 3\n2 1 1\n", "3 9\n1 1 3\n", "12345678 87654321\n43043751 1000000000 53798715\n" ]
[ "2\n", "1\n", "2147483648\n" ]
In the first sample case, Grisha needs five yellow and four blue crystals to create two yellow balls, one green ball, and one blue ball. To do that, Grisha needs to obtain two additional crystals: one yellow and one blue.
500
[ { "input": "4 3\n2 1 1", "output": "2" }, { "input": "3 9\n1 1 3", "output": "1" }, { "input": "12345678 87654321\n43043751 1000000000 53798715", "output": "2147483648" }, { "input": "12 12\n3 5 2", "output": "0" }, { "input": "770 1390\n170 442 311", "output"...
1,517,302,171
2,147,483,647
Python 3
OK
TESTS
38
62
5,632,000
r = lambda: map(int,input().split()) y,b = r() j,k,l = r() print (max(0,(k+3*l)-b) + max(0,(k+2*j)-y))
Title: Tricky Alchemy Time Limit: None seconds Memory Limit: None megabytes Problem Description: During the winter holidays, the demand for Christmas balls is exceptionally high. Since it's already 2018, the advances in alchemy allow easy and efficient ball creation by utilizing magic crystals. Grisha needs to obta...
```python r = lambda: map(int,input().split()) y,b = r() j,k,l = r() print (max(0,(k+3*l)-b) + max(0,(k+2*j)-y)) ```
3
75
A
Life Without Zeros
PROGRAMMING
1,000
[ "implementation" ]
A. Life Without Zeros
2
256
Can you imagine our life if we removed all zeros from it? For sure we will have many problems. In this problem we will have a simple example if we removed all zeros from our life, it's the addition operation. Let's assume you are given this equation *a*<=+<=*b*<==<=*c*, where *a* and *b* are positive integers, and *c*...
The input will consist of two lines, the first line will contain the integer *a*, and the second line will contain the integer *b* which are in the equation as described above (1<=≀<=*a*,<=*b*<=≀<=109). There won't be any leading zeros in both. The value of *c* should be calculated as *c*<==<=*a*<=+<=*b*.
The output will be just one line, you should print "YES" if the equation will remain correct after removing all zeros, and print "NO" otherwise.
[ "101\n102\n", "105\n106\n" ]
[ "YES\n", "NO\n" ]
none
500
[ { "input": "101\n102", "output": "YES" }, { "input": "105\n106", "output": "NO" }, { "input": "544\n397", "output": "YES" }, { "input": "822\n280", "output": "NO" }, { "input": "101\n413", "output": "NO" }, { "input": "309\n139", "output": "NO" }...
1,670,226,828
2,147,483,647
Python 3
OK
TESTS
43
92
0
a = input() b = input() c = int(a) + int(b) c_prime = int(str(c).replace('0', '')) c_prime_prime = int(a.replace('0', '')) + int(b.replace('0', '')) print('YES' if c_prime_prime == c_prime else 'NO')
Title: Life Without Zeros Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Can you imagine our life if we removed all zeros from it? For sure we will have many problems. In this problem we will have a simple example if we removed all zeros from our life, it's the addition operation. Let's assu...
```python a = input() b = input() c = int(a) + int(b) c_prime = int(str(c).replace('0', '')) c_prime_prime = int(a.replace('0', '')) + int(b.replace('0', '')) print('YES' if c_prime_prime == c_prime else 'NO') ```
3.977
937
A
Olympiad
PROGRAMMING
800
[ "implementation", "sortings" ]
null
null
The recent All-Berland Olympiad in Informatics featured *n* participants with each scoring a certain amount of points. As the head of the programming committee, you are to determine the set of participants to be awarded with diplomas with respect to the following criteria: - At least one participant should get a di...
The first line contains a single integer *n* (1<=≀<=*n*<=≀<=100)Β β€” the number of participants. The next line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≀<=*a**i*<=≀<=600)Β β€” participants' scores. It's guaranteed that at least one participant has non-zero score.
Print a single integerΒ β€” the desired number of ways.
[ "4\n1 3 3 2\n", "3\n1 1 1\n", "4\n42 0 0 42\n" ]
[ "3\n", "1\n", "1\n" ]
There are three ways to choose a subset in sample case one. 1. Only participants with 3 points will get diplomas. 1. Participants with 2 or 3 points will get diplomas. 1. Everyone will get a diploma! The only option in sample case two is to award everyone. Note that in sample case three participants with zero sco...
500
[ { "input": "4\n1 3 3 2", "output": "3" }, { "input": "3\n1 1 1", "output": "1" }, { "input": "4\n42 0 0 42", "output": "1" }, { "input": "10\n1 0 1 0 1 0 0 0 0 1", "output": "1" }, { "input": "10\n572 471 540 163 50 30 561 510 43 200", "output": "10" }, { ...
1,664,025,238
2,147,483,647
Python 3
OK
TESTS
21
31
0
num=int(input()) l=list(map(int,input().split())) while(0 in l): l.remove(0) l=set(l) print(len(l))
Title: Olympiad Time Limit: None seconds Memory Limit: None megabytes Problem Description: The recent All-Berland Olympiad in Informatics featured *n* participants with each scoring a certain amount of points. As the head of the programming committee, you are to determine the set of participants to be awarded with ...
```python num=int(input()) l=list(map(int,input().split())) while(0 in l): l.remove(0) l=set(l) print(len(l)) ```
3
136
A
Presents
PROGRAMMING
800
[ "implementation" ]
null
null
Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited *n* his friends there. If...
The first line contains one integer *n* (1<=≀<=*n*<=≀<=100) β€” the quantity of friends Petya invited to the party. The second line contains *n* space-separated integers: the *i*-th number is *p**i* β€” the number of a friend who gave a gift to friend number *i*. It is guaranteed that each friend received exactly one gift....
Print *n* space-separated integers: the *i*-th number should equal the number of the friend who gave a gift to friend number *i*.
[ "4\n2 3 4 1\n", "3\n1 3 2\n", "2\n1 2\n" ]
[ "4 1 2 3\n", "1 3 2\n", "1 2\n" ]
none
500
[ { "input": "4\n2 3 4 1", "output": "4 1 2 3" }, { "input": "3\n1 3 2", "output": "1 3 2" }, { "input": "2\n1 2", "output": "1 2" }, { "input": "1\n1", "output": "1" }, { "input": "10\n1 3 2 6 4 5 7 9 8 10", "output": "1 3 2 5 6 4 7 9 8 10" }, { "input"...
1,693,959,647
2,147,483,647
PyPy 3-64
OK
TESTS
101
124
0
n = int(input()) lst = list(map(int,input().split())) lst1 = [0]*(n+1) for i in range(len(lst)): lst1[lst[i]]+= i+1 print(' '.join(map(str, lst1[1:])))
Title: Presents Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on t...
```python n = int(input()) lst = list(map(int,input().split())) lst1 = [0]*(n+1) for i in range(len(lst)): lst1[lst[i]]+= i+1 print(' '.join(map(str, lst1[1:]))) ```
3
820
B
Mister B and Angle in Polygon
PROGRAMMING
1,300
[ "constructive algorithms", "geometry", "math" ]
null
null
On one quiet day all of sudden Mister B decided to draw angle *a* on his field. Aliens have already visited his field and left many different geometric figures on it. One of the figures is regular convex *n*-gon (regular convex polygon with *n* sides). That's why Mister B decided to use this polygon. Now Mister B must...
First and only line contains two space-separated integers *n* and *a* (3<=≀<=*n*<=≀<=105, 1<=≀<=*a*<=≀<=180)Β β€” the number of vertices in the polygon and the needed angle, in degrees.
Print three space-separated integers: the vertices *v*1, *v*2, *v*3, which form . If there are multiple optimal solutions, print any of them. The vertices are numbered from 1 to *n* in clockwise order.
[ "3 15\n", "4 67\n", "4 68\n" ]
[ "1 2 3\n", "2 1 3\n", "4 1 2\n" ]
In first sample test vertices of regular triangle can create only angle of 60 degrees, that's why every possible angle is correct. Vertices of square can create 45 or 90 degrees angles only. That's why in second sample test the angle of 45 degrees was chosen, since |45 - 67| &lt; |90 - 67|. Other correct answers are: ...
1,000
[ { "input": "3 15", "output": "2 1 3" }, { "input": "4 67", "output": "2 1 3" }, { "input": "4 68", "output": "2 1 4" }, { "input": "3 1", "output": "2 1 3" }, { "input": "3 180", "output": "2 1 3" }, { "input": "100000 1", "output": "2 1 558" }, ...
1,498,577,582
3,482
Python 3
OK
TESTS
46
62
5,529,600
n,a = map(int,input().split()) k = round(n * a / 180) if k == 0: k = 1 elif k + 2 > n: k = n - 2 print(1,2+k,1+k)
Title: Mister B and Angle in Polygon Time Limit: None seconds Memory Limit: None megabytes Problem Description: On one quiet day all of sudden Mister B decided to draw angle *a* on his field. Aliens have already visited his field and left many different geometric figures on it. One of the figures is regular convex *...
```python n,a = map(int,input().split()) k = round(n * a / 180) if k == 0: k = 1 elif k + 2 > n: k = n - 2 print(1,2+k,1+k) ```
3
245
A
System Administrator
PROGRAMMING
800
[ "implementation" ]
null
null
Polycarpus is a system administrator. There are two servers under his strict guidance β€” *a* and *b*. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a progra...
The first line contains a single integer *n* (2<=≀<=*n*<=≀<=1000) β€” the number of commands Polycarpus has fulfilled. Each of the following *n* lines contains three integers β€” the description of the commands. The *i*-th of these lines contains three space-separated integers *t**i*, *x**i*, *y**i* (1<=≀<=*t**i*<=≀<=2;Β *x...
In the first line print string "LIVE" (without the quotes) if server *a* is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server *b* in the similar format.
[ "2\n1 5 5\n2 6 4\n", "3\n1 0 10\n2 0 10\n1 10 0\n" ]
[ "LIVE\nLIVE\n", "LIVE\nDEAD\n" ]
Consider the first test case. There 10 packets were sent to server *a*, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server *b*, 6 of them reached it. Therefore, at least half of all packets sent to t...
0
[ { "input": "2\n1 5 5\n2 6 4", "output": "LIVE\nLIVE" }, { "input": "3\n1 0 10\n2 0 10\n1 10 0", "output": "LIVE\nDEAD" }, { "input": "10\n1 3 7\n2 4 6\n1 2 8\n2 5 5\n2 10 0\n2 10 0\n1 8 2\n2 2 8\n2 10 0\n1 1 9", "output": "DEAD\nLIVE" }, { "input": "11\n1 8 2\n1 6 4\n1 9 1\n1...
1,563,617,762
2,147,483,647
PyPy 3
OK
TESTS
13
310
1,433,600
s = [[0, 0], [0, 0]] for _ in range(int(input())): t, x, y = map(int, input().split()) s[t - 1][0] += x s[t - 1][1] += y for i in range(2): print(('DEAD', 'LIVE')[s[i][0] >= s[i][1]])
Title: System Administrator Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarpus is a system administrator. There are two servers under his strict guidance β€” *a* and *b*. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping co...
```python s = [[0, 0], [0, 0]] for _ in range(int(input())): t, x, y = map(int, input().split()) s[t - 1][0] += x s[t - 1][1] += y for i in range(2): print(('DEAD', 'LIVE')[s[i][0] >= s[i][1]]) ```
3
330
A
Cakeminator
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
You are given a rectangular cake, represented as an *r*<=Γ—<=*c* grid. Each cell either has an evil strawberry, or is empty. For example, a 3<=Γ—<=4 cake may look as follows: The cakeminator is going to eat the cake! Each time he eats, he chooses a row or a column that does not contain any evil strawberries and contains...
The first line contains two integers *r* and *c* (2<=≀<=*r*,<=*c*<=≀<=10), denoting the number of rows and the number of columns of the cake. The next *r* lines each contains *c* characters β€” the *j*-th character of the *i*-th line denotes the content of the cell at row *i* and column *j*, and is either one of these: ...
Output the maximum number of cake cells that the cakeminator can eat.
[ "3 4\nS...\n....\n..S.\n" ]
[ "8\n" ]
For the first example, one possible way to eat the maximum number of cake cells is as follows (perform 3 eats).
500
[ { "input": "3 4\nS...\n....\n..S.", "output": "8" }, { "input": "2 2\n..\n..", "output": "4" }, { "input": "2 2\nSS\nSS", "output": "0" }, { "input": "7 3\nS..\nS..\nS..\nS..\nS..\nS..\nS..", "output": "14" }, { "input": "3 5\n..S..\nSSSSS\n..S..", "output": "...
1,669,224,565
2,147,483,647
Python 3
OK
TESTS
42
124
0
n,m=map(int,input().split()) a=set() b=set() for i in range(n): s=input() for j in range(m): if s[j]=="S": a.add(i),b.add(j) print((n*m)-(len(a)*len(b)))
Title: Cakeminator Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a rectangular cake, represented as an *r*<=Γ—<=*c* grid. Each cell either has an evil strawberry, or is empty. For example, a 3<=Γ—<=4 cake may look as follows: The cakeminator is going to eat the cake! Each ti...
```python n,m=map(int,input().split()) a=set() b=set() for i in range(n): s=input() for j in range(m): if s[j]=="S": a.add(i),b.add(j) print((n*m)-(len(a)*len(b))) ```
3
88
A
Chord
PROGRAMMING
1,200
[ "brute force", "implementation" ]
A. Chord
2
256
Vasya studies music. He has learned lots of interesting stuff. For example, he knows that there are 12 notes: C, C#, D, D#, E, F, F#, G, G#, A, B, H. He also knows that the notes are repeated cyclically: after H goes C again, and before C stands H. We will consider the C note in the row's beginning and the C note aft...
The only line contains 3 space-separated notes in the above-given notation.
Print "major" if the chord is major, "minor" if it is minor, and "strange" if the teacher gave Vasya some weird chord which is neither major nor minor. Vasya promises you that the answer will always be unambiguous. That is, there are no chords that are both major and minor simultaneously.
[ "C E G\n", "C# B F\n", "A B H\n" ]
[ "major\n", "minor\n", "strange\n" ]
none
500
[ { "input": "C E G", "output": "major" }, { "input": "C# B F", "output": "minor" }, { "input": "A B H", "output": "strange" }, { "input": "G H E", "output": "minor" }, { "input": "D# B G", "output": "major" }, { "input": "D# B F#", "output": "minor"...
1,574,060,659
2,147,483,647
PyPy 3
OK
TESTS
75
310
0
import sys arr = sys.stdin.readline().strip().split() accords = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'B', 'H'] def whatTheAccord(arr): global accords positions = [accords.index(arr[0]),accords.index(arr[1]),accords.index(arr[2])] for i in range(len(accords)): if ac...
Title: Chord Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya studies music. He has learned lots of interesting stuff. For example, he knows that there are 12 notes: C, C#, D, D#, E, F, F#, G, G#, A, B, H. He also knows that the notes are repeated cyclically: after H goes C again, and b...
```python import sys arr = sys.stdin.readline().strip().split() accords = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'B', 'H'] def whatTheAccord(arr): global accords positions = [accords.index(arr[0]),accords.index(arr[1]),accords.index(arr[2])] for i in range(len(accords)): ...
3.9225
747
A
Display Size
PROGRAMMING
800
[ "brute force", "math" ]
null
null
A big company decided to launch a new series of rectangular displays, and decided that the display must have exactly *n* pixels. Your task is to determine the size of the rectangular display β€” the number of lines (rows) of pixels *a* and the number of columns of pixels *b*, so that: - there are exactly *n* pixels o...
The first line contains the positive integer *n* (1<=≀<=*n*<=≀<=106)Β β€” the number of pixels display should have.
Print two integersΒ β€” the number of rows and columns on the display.
[ "8\n", "64\n", "5\n", "999999\n" ]
[ "2 4\n", "8 8\n", "1 5\n", "999 1001\n" ]
In the first example the minimum possible difference equals 2, so on the display should be 2 rows of 4 pixels. In the second example the minimum possible difference equals 0, so on the display should be 8 rows of 8 pixels. In the third example the minimum possible difference equals 4, so on the display should be 1 ro...
500
[ { "input": "8", "output": "2 4" }, { "input": "64", "output": "8 8" }, { "input": "5", "output": "1 5" }, { "input": "999999", "output": "999 1001" }, { "input": "716539", "output": "97 7387" }, { "input": "1", "output": "1 1" }, { "input":...
1,562,523,917
2,147,483,647
Python 3
OK
TESTS
43
124
0
n = int(input()) a = 1 ans = 10**18 while a*a <= n: if n%a == 0: b = n//a if b-a < ans: ans = b-a ans_a = a a+=1 print(ans_a, n//ans_a)
Title: Display Size Time Limit: None seconds Memory Limit: None megabytes Problem Description: A big company decided to launch a new series of rectangular displays, and decided that the display must have exactly *n* pixels. Your task is to determine the size of the rectangular display β€” the number of lines (rows) ...
```python n = int(input()) a = 1 ans = 10**18 while a*a <= n: if n%a == 0: b = n//a if b-a < ans: ans = b-a ans_a = a a+=1 print(ans_a, n//ans_a) ```
3
0
none
none
none
0
[ "none" ]
null
null
The main road in Bytecity is a straight line from south to north. Conveniently, there are coordinates measured in meters from the southernmost building in north direction. At some points on the road there are *n* friends, and *i*-th of them is standing at the point *x**i* meters and can move with any speed no greater ...
The first line contains single integer *n* (2<=≀<=*n*<=≀<=60<=000)Β β€” the number of friends. The second line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n* (1<=≀<=*x**i*<=≀<=109)Β β€” the current coordinates of the friends, in meters. The third line contains *n* integers *v*1,<=*v*2,<=...,<=*v**n* (1<=≀<=*v**i*<=≀<=109...
Print the minimum time (in seconds) needed for all the *n* friends to meet at some point on the road. Your answer will be considered correct, if its absolute or relative error isn't greater than 10<=-<=6. Formally, let your answer be *a*, while jury's answer be *b*. Your answer will be considered correct if holds.
[ "3\n7 1 3\n1 2 1\n", "4\n5 10 3 2\n2 3 2 4\n" ]
[ "2.000000000000\n", "1.400000000000\n" ]
In the first sample, all friends can gather at the point 5 within 2 seconds. In order to achieve this, the first friend should go south all the time at his maximum speed, while the second and the third friends should go north at their maximum speeds.
0
[ { "input": "3\n7 1 3\n1 2 1", "output": "2.000000000000" }, { "input": "4\n5 10 3 2\n2 3 2 4", "output": "1.400000000000" }, { "input": "3\n1 1000000000 2\n1 2 1000000000", "output": "333333332.999999999971" }, { "input": "2\n4 5\n10 8", "output": "0.055555555556" }, ...
1,643,830,088
2,147,483,647
Python 3
OK
TESTS
46
2,121
6,553,600
# cook your dish heret n=int(input()) x=[int(x) for x in input().split()] v=[int(v) for v in input().split()] def rightmost_left_ep(t): return max([x[i]-(v[i]*t) for i in range(n)]) def leftmost_right_ep(t): return min([x[i]+(v[i]*t) for i in range(n)]) def is_feasible(k): return leftmost_right_ep(...
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: The main road in Bytecity is a straight line from south to north. Conveniently, there are coordinates measured in meters from the southernmost building in north direction. At some points on the road there are *n* friends, and *i*...
```python # cook your dish heret n=int(input()) x=[int(x) for x in input().split()] v=[int(v) for v in input().split()] def rightmost_left_ep(t): return max([x[i]-(v[i]*t) for i in range(n)]) def leftmost_right_ep(t): return min([x[i]+(v[i]*t) for i in range(n)]) def is_feasible(k): return leftmost...
3
465
A
inc ARG
PROGRAMMING
900
[ "implementation" ]
null
null
Sergey is testing a next-generation processor. Instead of bytes the processor works with memory cells consisting of *n* bits. These bits are numbered from 1 to *n*. An integer is stored in the cell in the following way: the least significant bit is stored in the first bit of the cell, the next significant bit is stored...
The first line contains a single integer *n* (1<=≀<=*n*<=≀<=100) β€” the number of bits in the cell. The second line contains a string consisting of *n* characters β€” the initial state of the cell. The first character denotes the state of the first bit of the cell. The second character denotes the second least significan...
Print a single integer β€” the number of bits in the cell which change their state after we add 1 to the cell.
[ "4\n1100\n", "4\n1111\n" ]
[ "3\n", "4\n" ]
In the first sample the cell ends up with value 0010, in the second sample β€” with 0000.
500
[ { "input": "4\n1100", "output": "3" }, { "input": "4\n1111", "output": "4" }, { "input": "1\n0", "output": "1" }, { "input": "1\n1", "output": "1" }, { "input": "2\n00", "output": "1" }, { "input": "2\n01", "output": "1" }, { "input": "2\n1...
1,569,919,711
2,147,483,647
Python 3
OK
TESTS
29
155
819,200
import re cv=0 s2='' n=int(input()) s1=input() for x in range(n): if int(s1[x])==1: s2=s2+'0' else: s2=s2+'1' s2=s2+s1[x+1:n] break; for x in range(n): if re.match(s1[x],s2[x]): cv=cv+1 print(n-cv)
Title: inc ARG Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sergey is testing a next-generation processor. Instead of bytes the processor works with memory cells consisting of *n* bits. These bits are numbered from 1 to *n*. An integer is stored in the cell in the following way: the lea...
```python import re cv=0 s2='' n=int(input()) s1=input() for x in range(n): if int(s1[x])==1: s2=s2+'0' else: s2=s2+'1' s2=s2+s1[x+1:n] break; for x in range(n): if re.match(s1[x],s2[x]): cv=cv+1 print(n-cv) ```
3
296
A
Yaroslav and Permutations
PROGRAMMING
1,100
[ "greedy", "math" ]
null
null
Yaroslav has an array that consists of *n* integers. In one second Yaroslav can swap two neighboring array elements. Now Yaroslav is wondering if he can obtain an array where any two neighboring elements would be distinct in a finite time. Help Yaroslav.
The first line contains integer *n* (1<=≀<=*n*<=≀<=100) β€” the number of elements in the array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≀<=*a**i*<=≀<=1000) β€” the array elements.
In the single line print "YES" (without the quotes) if Yaroslav can obtain the array he needs, and "NO" (without the quotes) otherwise.
[ "1\n1\n", "3\n1 1 2\n", "4\n7 7 7 7\n" ]
[ "YES\n", "YES\n", "NO\n" ]
In the first sample the initial array fits well. In the second sample Yaroslav can get array: 1, 2, 1. He can swap the last and the second last elements to obtain it. In the third sample Yarosav can't get the array he needs.
500
[ { "input": "1\n1", "output": "YES" }, { "input": "3\n1 1 2", "output": "YES" }, { "input": "4\n7 7 7 7", "output": "NO" }, { "input": "4\n479 170 465 146", "output": "YES" }, { "input": "5\n996 437 605 996 293", "output": "YES" }, { "input": "6\n727 53...
1,527,173,573
2,147,483,647
Python 3
OK
TESTS
37
186
0
# python 3 """ Note that after applying the operations of the exchange, we can get any permutation of the elements of the array. It is not difficult to understand that the answer would be "YES" if there were at least another different number between the same-valued number, and this means that at most the same-valued nu...
Title: Yaroslav and Permutations Time Limit: None seconds Memory Limit: None megabytes Problem Description: Yaroslav has an array that consists of *n* integers. In one second Yaroslav can swap two neighboring array elements. Now Yaroslav is wondering if he can obtain an array where any two neighboring elements would...
```python # python 3 """ Note that after applying the operations of the exchange, we can get any permutation of the elements of the array. It is not difficult to understand that the answer would be "YES" if there were at least another different number between the same-valued number, and this means that at most the same...
3
447
B
DZY Loves Strings
PROGRAMMING
1,000
[ "greedy", "implementation" ]
null
null
DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter *c* DZY knows its value *w**c*. For each special string *s*<==<=*s*1*s*2... *s*|*s*| (|*s*| is the length of the string) he represents its value with a function *f*(*s*), where Now DZY has a string *s*. He wants to in...
The first line contains a single string *s*Β (1<=≀<=|*s*|<=≀<=103). The second line contains a single integer *k*Β (0<=≀<=*k*<=≀<=103). The third line contains twenty-six integers from *w**a* to *w**z*. Each such number is non-negative and doesn't exceed 1000.
Print a single integer β€” the largest possible value of the resulting string DZY could get.
[ "abc\n3\n1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n" ]
[ "41\n" ]
In the test sample DZY can obtain "abcbbc", *value* = 1Β·1 + 2Β·2 + 3Β·2 + 4Β·2 + 5Β·2 + 6Β·2 = 41.
1,000
[ { "input": "abc\n3\n1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "41" }, { "input": "mmzhr\n3\n443 497 867 471 195 670 453 413 579 466 553 881 847 642 269 996 666 702 487 209 257 741 974 133 519 453", "output": "29978" }, { "input": "ajeeseerqnpaujubmajpibxrccazaawetyw...
1,595,173,643
2,147,483,647
PyPy 3
OK
TESTS
24
140
20,172,800
s = input() k = int(input()) l = list(map(int, input().split())) m = max(l) c = 0 f = 0 for i in s: f+=1 c += l[ord(i)-97] * (f) for i in range(k): f+=1 c += m * f print(c)
Title: DZY Loves Strings Time Limit: None seconds Memory Limit: None megabytes Problem Description: DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter *c* DZY knows its value *w**c*. For each special string *s*<==<=*s*1*s*2... *s*|*s*| (|*s*| is the length of the str...
```python s = input() k = int(input()) l = list(map(int, input().split())) m = max(l) c = 0 f = 0 for i in s: f+=1 c += l[ord(i)-97] * (f) for i in range(k): f+=1 c += m * f print(c) ```
3
939
B
Hamster Farm
PROGRAMMING
1,000
[ "implementation" ]
null
null
Dima has a hamsters farm. Soon *N* hamsters will grow up on it and Dima will sell them in a city nearby. Hamsters should be transported in boxes. If some box is not completely full, the hamsters in it are bored, that's why each box should be completely full with hamsters. Dima can buy boxes at a factory. The factory ...
The first line contains two integers *N* and *K* (0<=≀<=*N*<=≀<=1018, 1<=≀<=*K*<=≀<=105)Β β€” the number of hamsters that will grow up on Dima's farm and the number of types of boxes that the factory produces. The second line contains *K* integers *a*1, *a*2, ..., *a**K* (1<=≀<=*a**i*<=≀<=1018 for all *i*)Β β€” the capaciti...
Output two integers: the type of boxes that Dima should buy and the number of boxes of that type Dima should buy. Types of boxes are numbered from 1 to *K* in the order they are given in input. If there are many correct answers, output any of them.
[ "19 3\n5 4 10\n", "28 3\n5 6 30\n" ]
[ "2 4\n", "1 5\n" ]
none
1,000
[ { "input": "19 3\n5 4 10", "output": "2 4" }, { "input": "28 3\n5 6 30", "output": "1 5" }, { "input": "1 1\n1", "output": "1 1" }, { "input": "0 2\n2 3", "output": "1 0" }, { "input": "30 4\n4 5 5 4", "output": "2 6" }, { "input": "120 7\n109 92 38 38...
1,696,337,196
2,147,483,647
PyPy 3-64
OK
TESTS
33
93
14,950,400
n, k = map(int, input().split()) a = list(map(int, input().split())) max_total = -1 maxAmnt = 0 index = 0 for i in range(len(a)): local_ans = (n // a[i]) closest_value = local_ans * a[i] if closest_value > max_total: max_total = closest_value maxAmnt = local_ans index ...
Title: Hamster Farm Time Limit: None seconds Memory Limit: None megabytes Problem Description: Dima has a hamsters farm. Soon *N* hamsters will grow up on it and Dima will sell them in a city nearby. Hamsters should be transported in boxes. If some box is not completely full, the hamsters in it are bored, that's wh...
```python n, k = map(int, input().split()) a = list(map(int, input().split())) max_total = -1 maxAmnt = 0 index = 0 for i in range(len(a)): local_ans = (n // a[i]) closest_value = local_ans * a[i] if closest_value > max_total: max_total = closest_value maxAmnt = local_ans ...
3
519
B
A and B and Compilation Errors
PROGRAMMING
1,100
[ "data structures", "implementation", "sortings" ]
null
null
A and B are preparing themselves for programming contests. B loves to debug his code. But before he runs the solution and starts debugging, he has to first compile the code. Initially, the compiler displayed *n* compilation errors, each of them is represented as a positive integer. After some effort, B managed to fix...
The first line of the input contains integer *n* (3<=≀<=*n*<=≀<=105) β€” the initial number of compilation errors. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≀<=*a**i*<=≀<=109) β€” the errors the compiler displayed for the first time. The third line contains *n*<=-<=1 space-sepa...
Print two numbers on a single line: the numbers of the compilation errors that disappeared after B made the first and the second correction, respectively.
[ "5\n1 5 8 123 7\n123 7 5 1\n5 1 7\n", "6\n1 4 3 3 5 7\n3 7 5 4 3\n4 3 7 5\n" ]
[ "8\n123\n", "1\n3\n" ]
In the first test sample B first corrects the error number 8, then the error number 123. In the second test sample B first corrects the error number 1, then the error number 3. Note that if there are multiple errors with the same number, B can correct only one of them in one step.
1,000
[ { "input": "5\n1 5 8 123 7\n123 7 5 1\n5 1 7", "output": "8\n123" }, { "input": "6\n1 4 3 3 5 7\n3 7 5 4 3\n4 3 7 5", "output": "1\n3" }, { "input": "3\n1 2 3\n3 2\n2", "output": "1\n3" }, { "input": "10\n460626451 802090732 277246428 661369649 388684428 784303821 376287098 6...
1,680,637,844
2,147,483,647
Python 3
OK
TESTS
33
358
16,076,800
num = int(input()) aux1 = [0] * num aux2 = [0] * num aux3 = [0] * num list1 = [int(x) for x in input().split()] list2 = [int(x) for x in input().split()] list3 = [int(x) for x in input().split()] for i in range(len(list1)): aux1[i] = list1[i] for i in range(len(list2)): aux2[i] = list2[i] for i in range(le...
Title: A and B and Compilation Errors Time Limit: None seconds Memory Limit: None megabytes Problem Description: A and B are preparing themselves for programming contests. B loves to debug his code. But before he runs the solution and starts debugging, he has to first compile the code. Initially, the compiler disp...
```python num = int(input()) aux1 = [0] * num aux2 = [0] * num aux3 = [0] * num list1 = [int(x) for x in input().split()] list2 = [int(x) for x in input().split()] list3 = [int(x) for x in input().split()] for i in range(len(list1)): aux1[i] = list1[i] for i in range(len(list2)): aux2[i] = list2[i] for i i...
3
139
A
Petr and Book
PROGRAMMING
1,000
[ "implementation" ]
null
null
One Sunday Petr went to a bookshop and bought a new book on sports programming. The book had exactly *n* pages. Petr decided to start reading it starting from the next day, that is, from Monday. Petr's got a very tight schedule and for each day of the week he knows how many pages he will be able to read on that day. S...
The first input line contains the single integer *n* (1<=≀<=*n*<=≀<=1000) β€” the number of pages in the book. The second line contains seven non-negative space-separated integers that do not exceed 1000 β€” those integers represent how many pages Petr can read on Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and...
Print a single number β€” the number of the day of the week, when Petr will finish reading the book. The days of the week are numbered starting with one in the natural order: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday.
[ "100\n15 20 20 15 10 30 45\n", "2\n1 0 0 0 0 0 0\n" ]
[ "6\n", "1\n" ]
Note to the first sample: By the end of Monday and therefore, by the beginning of Tuesday Petr has 85 pages left. He has 65 pages left by Wednesday, 45 by Thursday, 30 by Friday, 20 by Saturday and on Saturday Petr finishes reading the book (and he also has time to read 10 pages of something else). Note to the second...
500
[ { "input": "100\n15 20 20 15 10 30 45", "output": "6" }, { "input": "2\n1 0 0 0 0 0 0", "output": "1" }, { "input": "100\n100 200 100 200 300 400 500", "output": "1" }, { "input": "3\n1 1 1 1 1 1 1", "output": "3" }, { "input": "1\n1 1 1 1 1 1 1", "output": "1...
1,620,288,728
2,147,483,647
Python 3
OK
TESTS
49
154
6,758,400
n=int(input()) x=list(map(int,input().split())) i=0 while n>x[i]: n-=x[i] i=(i+1)%7 print(i+1)
Title: Petr and Book Time Limit: None seconds Memory Limit: None megabytes Problem Description: One Sunday Petr went to a bookshop and bought a new book on sports programming. The book had exactly *n* pages. Petr decided to start reading it starting from the next day, that is, from Monday. Petr's got a very tight s...
```python n=int(input()) x=list(map(int,input().split())) i=0 while n>x[i]: n-=x[i] i=(i+1)%7 print(i+1) ```
3
71
A
Way Too Long Words
PROGRAMMING
800
[ "strings" ]
A. Way Too Long Words
1
256
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made lik...
The first line contains an integer *n* (1<=≀<=*n*<=≀<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data.
[ "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n" ]
[ "word\nl10n\ni18n\np43s\n" ]
none
500
[ { "input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis", "output": "word\nl10n\ni18n\np43s" }, { "input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm", "output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m" }, { "input":...
1,696,492,452
2,147,483,647
Python 3
OK
TESTS
20
46
0
'''def thanhtung(x,y,n,m): so_hit=0 sat_thuong=x mau=m while n>0: so_hit=so_hit+1 mau=mau-sat_thuong if mau <= 0: sat_thuong = sat_thuong+y mau =m n =n-1 return so_hit x,y,n,m = map(int,input().split()) ket_qua=thanhtung(x,y,n,...
Title: Way Too Long Words Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 character...
```python '''def thanhtung(x,y,n,m): so_hit=0 sat_thuong=x mau=m while n>0: so_hit=so_hit+1 mau=mau-sat_thuong if mau <= 0: sat_thuong = sat_thuong+y mau =m n =n-1 return so_hit x,y,n,m = map(int,input().split()) ket_qua=thanht...
3.977
859
A
Declined Finalists
PROGRAMMING
800
[ "greedy", "implementation" ]
null
null
This year, as in previous years, MemSQL is inviting the top 25 competitors from the Start[c]up qualification round to compete onsite for the final round. Not everyone who is eligible to compete onsite can afford to travel to the office, though. Initially the top 25 contestants are invited to come onsite. Each eligible ...
The first line of input contains *K* (1<=≀<=*K*<=≀<=25), the number of onsite finalists you know. The second line of input contains *r*1,<=*r*2,<=...,<=*r**K* (1<=≀<=*r**i*<=≀<=106), the qualifying ranks of the finalists you know. All these ranks are distinct.
Print the minimum possible number of contestants that declined the invitation to compete onsite.
[ "25\n2 3 4 5 6 7 8 9 10 11 12 14 15 16 17 18 19 20 21 22 23 24 25 26 28\n", "5\n16 23 8 15 4\n", "3\n14 15 92\n" ]
[ "3\n", "0\n", "67\n" ]
In the first example, you know all 25 onsite finalists. The contestants who ranked 1-st, 13-th, and 27-th must have declined, so the answer is 3.
500
[ { "input": "25\n2 3 4 5 6 7 8 9 10 11 12 14 15 16 17 18 19 20 21 22 23 24 25 26 28", "output": "3" }, { "input": "5\n16 23 8 15 4", "output": "0" }, { "input": "3\n14 15 92", "output": "67" }, { "input": "1\n1000000", "output": "999975" }, { "input": "25\n1000000 ...
1,668,786,621
2,147,483,647
PyPy 3-64
OK
TESTS
25
61
0
k=int(input()) a=[int(i) for i in input().split()] a.sort() if a[-1]<=25: print(0) else : print(a[-1]-25)
Title: Declined Finalists Time Limit: None seconds Memory Limit: None megabytes Problem Description: This year, as in previous years, MemSQL is inviting the top 25 competitors from the Start[c]up qualification round to compete onsite for the final round. Not everyone who is eligible to compete onsite can afford to t...
```python k=int(input()) a=[int(i) for i in input().split()] a.sort() if a[-1]<=25: print(0) else : print(a[-1]-25) ```
3
61
A
Ultra-Fast Mathematician
PROGRAMMING
800
[ "implementation" ]
A. Ultra-Fast Mathematician
2
256
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second. One day in 230 AD Shapur was trying to find out if any one can possibly do...
There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100.
Write one line β€” the corresponding answer. Do not omit the leading 0s.
[ "1010100\n0100101\n", "000\n111\n", "1110\n1010\n", "01110\n01100\n" ]
[ "1110001\n", "111\n", "0100\n", "00010\n" ]
none
500
[ { "input": "1010100\n0100101", "output": "1110001" }, { "input": "000\n111", "output": "111" }, { "input": "1110\n1010", "output": "0100" }, { "input": "01110\n01100", "output": "00010" }, { "input": "011101\n000001", "output": "011100" }, { "input": "...
1,672,384,367
2,147,483,647
Python 3
OK
TESTS
102
62
409,600
#!/usr/bin/env python import math,collections,re from sys import exit,stdin,stdout from collections import Counter,defaultdict,deque input = stdin.readline def inp(): return(int(input())) def inplst(nospaces=False): if nospaces: return list(map(int,list(input().rstrip()))) return(list(map(int,input(...
Title: Ultra-Fast Mathematician Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 10...
```python #!/usr/bin/env python import math,collections,re from sys import exit,stdin,stdout from collections import Counter,defaultdict,deque input = stdin.readline def inp(): return(int(input())) def inplst(nospaces=False): if nospaces: return list(map(int,list(input().rstrip()))) return(list(map(...
3.983737
626
A
Robot Sequence
PROGRAMMING
1,000
[ "brute force", "implementation" ]
null
null
Calvin the robot lies in an infinite rectangular grid. Calvin's source code contains a list of *n* commands, each either 'U', 'R', 'D', or 'L'Β β€” instructions to move a single square up, right, down, or left, respectively. How many ways can Calvin execute a non-empty contiguous substrings of commands and return to the s...
The first line of the input contains a single positive integer, *n* (1<=≀<=*n*<=≀<=200)Β β€” the number of commands. The next line contains *n* characters, each either 'U', 'R', 'D', or 'L'Β β€” Calvin's source code.
Print a single integerΒ β€” the number of contiguous substrings that Calvin can execute and return to his starting square.
[ "6\nURLLDR\n", "4\nDLUU\n", "7\nRLRLRLR\n" ]
[ "2\n", "0\n", "12\n" ]
In the first case, the entire source code works, as well as the "RL" substring in the second and third characters. Note that, in the third case, the substring "LR" appears three times, and is therefore counted three times to the total result.
500
[ { "input": "6\nURLLDR", "output": "2" }, { "input": "4\nDLUU", "output": "0" }, { "input": "7\nRLRLRLR", "output": "12" }, { "input": "1\nR", "output": "0" }, { "input": "100\nURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDL...
1,571,176,799
2,147,483,647
PyPy 3
OK
TESTS
25
156
4,300,800
tam = int(input()) string = input() total = 0 substrings = [string[i: j] for i in range(len(string)) for j in range(i + 1, len(string) + 1)] #print(substrings) multiplas = [] for sub in substrings: if len(sub) % 2 == 0: multiplas.append(sub) #print(multiplas) for palavra in multiplas: countD = 0 countU = 0...
Title: Robot Sequence Time Limit: None seconds Memory Limit: None megabytes Problem Description: Calvin the robot lies in an infinite rectangular grid. Calvin's source code contains a list of *n* commands, each either 'U', 'R', 'D', or 'L'Β β€” instructions to move a single square up, right, down, or left, respectively...
```python tam = int(input()) string = input() total = 0 substrings = [string[i: j] for i in range(len(string)) for j in range(i + 1, len(string) + 1)] #print(substrings) multiplas = [] for sub in substrings: if len(sub) % 2 == 0: multiplas.append(sub) #print(multiplas) for palavra in multiplas: countD = 0 ...
3
219
A
k-String
PROGRAMMING
1,000
[ "implementation", "strings" ]
null
null
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...
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).
[ "2\naazz\n", "3\nabcabcabz\n" ]
[ "azaz\n", "-1\n" ]
none
500
[ { "input": "2\naazz", "output": "azaz" }, { "input": "3\nabcabcabz", "output": "-1" }, { "input": "1\na", "output": "a" }, { "input": "2\nabba", "output": "abab" }, { "input": "2\naaab", "output": "-1" }, { "input": "7\nabacaba", "output": "-1" }...
1,691,590,883
2,147,483,647
PyPy 3-64
OK
TESTS
42
154
0
k = int(input()) s = input() if len(s) % k != 0: print(-1) else: d = {} for i in s: d[i] = d.get(i, 0) + 1 string = "" score = 0 for m in list(d.values()): if m % k != 0: score = -1 break if score == 0: for l in range(k): ...
Title: k-String Time Limit: None seconds Memory Limit: None megabytes Problem Description: 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 ...
```python k = int(input()) s = input() if len(s) % k != 0: print(-1) else: d = {} for i in s: d[i] = d.get(i, 0) + 1 string = "" score = 0 for m in list(d.values()): if m % k != 0: score = -1 break if score == 0: for l in range(k...
3
109
A
Lucky Sum of Digits
PROGRAMMING
1,000
[ "brute force", "implementation" ]
A. Lucky Sum of Digits
2
256
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya wonders eagerly what minimum lucky number has the sum of digits equal to *n*. Help him cope wi...
The single line contains an integer *n* (1<=≀<=*n*<=≀<=106) β€” the sum of digits of the required lucky number.
Print on the single line the result β€” the minimum lucky number, whose sum of digits equals *n*. If such number does not exist, print -1.
[ "11\n", "10\n" ]
[ "47\n", "-1\n" ]
none
500
[ { "input": "11", "output": "47" }, { "input": "10", "output": "-1" }, { "input": "64", "output": "4477777777" }, { "input": "1", "output": "-1" }, { "input": "4", "output": "4" }, { "input": "7", "output": "7" }, { "input": "12", "outpu...
1,449,519,931
2,147,483,647
Python 3
OK
TESTS
51
184
1,126,400
from functools import reduce from operator import * from math import * from sys import * from string import * setrecursionlimit(10**7) RI=lambda: list(map(int,input().split())) RS=lambda: input().rstrip().split() ################################################# n=RI()[0] ans="" while n%7!=0: n-=4 ans+='4' prin...
Title: Lucky Sum of Digits Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. ...
```python from functools import reduce from operator import * from math import * from sys import * from string import * setrecursionlimit(10**7) RI=lambda: list(map(int,input().split())) RS=lambda: input().rstrip().split() ################################################# n=RI()[0] ans="" while n%7!=0: n-=4 ans...
3.951902
287
A
IQ Test
PROGRAMMING
1,100
[ "brute force", "implementation" ]
null
null
In the city of Ultima Thule job applicants are often offered an IQ test. The test is as follows: the person gets a piece of squared paper with a 4<=Γ—<=4 square painted on it. Some of the square's cells are painted black and others are painted white. Your task is to repaint at most one cell the other color so that the...
Four lines contain four characters each: the *j*-th character of the *i*-th line equals "." if the cell in the *i*-th row and the *j*-th column of the square is painted white, and "#", if the cell is black.
Print "YES" (without the quotes), if the test can be passed and "NO" (without the quotes) otherwise.
[ "####\n.#..\n####\n....\n", "####\n....\n####\n....\n" ]
[ "YES\n", "NO\n" ]
In the first test sample it is enough to repaint the first cell in the second row. After such repainting the required 2 × 2 square is on the intersection of the 1-st and 2-nd row with the 1-st and 2-nd column.
500
[ { "input": "###.\n...#\n###.\n...#", "output": "NO" }, { "input": ".##.\n#..#\n.##.\n#..#", "output": "NO" }, { "input": ".#.#\n#.#.\n.#.#\n#.#.", "output": "NO" }, { "input": "##..\n..##\n##..\n..##", "output": "NO" }, { "input": "#.#.\n#.#.\n.#.#\n.#.#", "ou...
1,675,616,771
2,147,483,647
Python 3
OK
TESTS
30
46
0
x=[input() for i in range(4)] m=0 for i in range(3): for j in range(3): if (x[i][j]+x[i][j+1]+x[i+1][j]+x[i+1][j+1]).count("#")!=2: m=1 break if m: break if m: print("YES") else: print("NO")
Title: IQ Test Time Limit: None seconds Memory Limit: None megabytes Problem Description: In the city of Ultima Thule job applicants are often offered an IQ test. The test is as follows: the person gets a piece of squared paper with a 4<=Γ—<=4 square painted on it. Some of the square's cells are painted black and o...
```python x=[input() for i in range(4)] m=0 for i in range(3): for j in range(3): if (x[i][j]+x[i][j+1]+x[i+1][j]+x[i+1][j+1]).count("#")!=2: m=1 break if m: break if m: print("YES") else: print("NO") ```
3
1
A
Theatre Square
PROGRAMMING
1,000
[ "math" ]
A. Theatre Square
1
256
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=Γ—<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=Γ—<=*a*. What is the least number of flagstones needed to pave the...
The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≀<=<=*n*,<=*m*,<=*a*<=≀<=109).
Write the needed number of flagstones.
[ "6 6 4\n" ]
[ "4\n" ]
none
0
[ { "input": "6 6 4", "output": "4" }, { "input": "1 1 1", "output": "1" }, { "input": "2 1 1", "output": "2" }, { "input": "1 2 1", "output": "2" }, { "input": "2 2 1", "output": "4" }, { "input": "2 1 2", "output": "1" }, { "input": "1 1 3"...
1,690,042,421
2,147,483,647
Python 3
OK
TESTS
20
46
0
x, y, z = [int(x) for x in input().split()] resx = 0 resy = 0 if x % z == 0: resx += x/z else: resx += int(x/z) +1 if y % z == 0: resy += y/z else: resy += int(y/z) +1 print(int(resx * resy))
Title: Theatre Square Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=Γ—<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each ...
```python x, y, z = [int(x) for x in input().split()] resx = 0 resy = 0 if x % z == 0: resx += x/z else: resx += int(x/z) +1 if y % z == 0: resy += y/z else: resy += int(y/z) +1 print(int(resx * resy)) ```
3.977
710
C
Magic Odd Square
PROGRAMMING
1,500
[ "constructive algorithms", "math" ]
null
null
Find an *n*<=Γ—<=*n* matrix with different numbers from 1 to *n*2, so the sum in each row, column and both main diagonals are odd.
The only line contains odd integer *n* (1<=≀<=*n*<=≀<=49).
Print *n* lines with *n* integers. All the integers should be different and from 1 to *n*2. The sum in each row, column and both main diagonals should be odd.
[ "1\n", "3\n" ]
[ "1\n", "2 1 4\n3 5 7\n6 9 8\n" ]
none
0
[ { "input": "1", "output": "1" }, { "input": "3", "output": "2 1 4\n3 5 7\n6 9 8" }, { "input": "5", "output": "2 4 1 6 8\n10 3 5 7 12\n9 11 13 15 17\n14 19 21 23 16\n18 20 25 22 24" }, { "input": "7", "output": "2 4 6 1 8 10 12\n14 16 3 5 7 18 20\n22 9 11 13 15 17 24\n19 ...
1,624,863,054
2,147,483,647
PyPy 3
OK
TESTS
25
124
2,764,800
n=int(input()) mxc=((n*n+1)//2-(2*n-1))//4 m=[] for i in range(n): l=[0]*n m.append(l) odd=1 i=n//2 j=0 while(j<n): m[i][j]=odd j+=1 odd+=2 j=0 while(j<n): if i==j: j+=1 continue m[j][i]=odd j+=1 odd+=2 i=0 j=0 c=0 while(c<mxc): c+=1 m[i][j]=odd odd+=2 m[i][n-1-j]=odd odd+...
Title: Magic Odd Square Time Limit: None seconds Memory Limit: None megabytes Problem Description: Find an *n*<=Γ—<=*n* matrix with different numbers from 1 to *n*2, so the sum in each row, column and both main diagonals are odd. Input Specification: The only line contains odd integer *n* (1<=≀<=*n*<=≀<=49). Output...
```python n=int(input()) mxc=((n*n+1)//2-(2*n-1))//4 m=[] for i in range(n): l=[0]*n m.append(l) odd=1 i=n//2 j=0 while(j<n): m[i][j]=odd j+=1 odd+=2 j=0 while(j<n): if i==j: j+=1 continue m[j][i]=odd j+=1 odd+=2 i=0 j=0 c=0 while(c<mxc): c+=1 m[i][j]=odd odd+=2 m[i][n-1-j]=...
3
628
B
New Skateboard
PROGRAMMING
1,300
[ "dp" ]
null
null
Max wants to buy a new skateboard. He has calculated the amount of money that is needed to buy a new skateboard. He left a calculator on the floor and went to ask some money from his parents. Meanwhile his little brother Yusuf came and started to press the keys randomly. Unfortunately Max has forgotten the number which...
The only line contains string *s* (1<=≀<=|*s*|<=≀<=3Β·105). The string *s* contains only digits from 0 to 9.
Print integer *a* β€” the number of substrings of the string *s* that are divisible by 4. Note that the answer can be huge, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.
[ "124\n", "04\n", "5810438174\n" ]
[ "4\n", "3\n", "9\n" ]
none
0
[ { "input": "124", "output": "4" }, { "input": "04", "output": "3" }, { "input": "5810438174", "output": "9" }, { "input": "1", "output": "0" }, { "input": "039", "output": "1" }, { "input": "97247", "output": "6" }, { "input": "5810438174",...
1,575,612,614
974
Python 3
OK
TESTS
22
421
1,024,000
s= input() ans = 0 for i in s: if int(i)%4 == 0: ans+=1 n = len(s) for i in range(0,n-1): if int(s[i:i+2])%4 == 0: ans+=i+1 print(ans)
Title: New Skateboard Time Limit: None seconds Memory Limit: None megabytes Problem Description: Max wants to buy a new skateboard. He has calculated the amount of money that is needed to buy a new skateboard. He left a calculator on the floor and went to ask some money from his parents. Meanwhile his little brother...
```python s= input() ans = 0 for i in s: if int(i)%4 == 0: ans+=1 n = len(s) for i in range(0,n-1): if int(s[i:i+2])%4 == 0: ans+=i+1 print(ans) ```
3
835
A
Key races
PROGRAMMING
800
[ "math" ]
null
null
Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of *s* characters. The first participant types one character in *v*1 milliseconds and has ping *t*1 milliseconds. The second participant types one character in *v*2 milliseconds and has ping *...
The first line contains five integers *s*, *v*1, *v*2, *t*1, *t*2 (1<=≀<=*s*,<=*v*1,<=*v*2,<=*t*1,<=*t*2<=≀<=1000)Β β€” the number of characters in the text, the time of typing one character for the first participant, the time of typing one character for the the second participant, the ping of the first participant and th...
If the first participant wins, print "First". If the second participant wins, print "Second". In case of a draw print "Friendship".
[ "5 1 2 1 2\n", "3 3 1 1 1\n", "4 5 3 1 5\n" ]
[ "First\n", "Second\n", "Friendship\n" ]
In the first example, information on the success of the first participant comes in 7 milliseconds, of the second participantΒ β€” in 14 milliseconds. So, the first wins. In the second example, information on the success of the first participant comes in 11 milliseconds, of the second participantΒ β€” in 5 milliseconds. So, ...
500
[ { "input": "5 1 2 1 2", "output": "First" }, { "input": "3 3 1 1 1", "output": "Second" }, { "input": "4 5 3 1 5", "output": "Friendship" }, { "input": "1000 1000 1000 1000 1000", "output": "Friendship" }, { "input": "1 1 1 1 1", "output": "Friendship" }, ...
1,586,331,266
2,147,483,647
Python 3
OK
TESTS
32
93
0
s,v1,v2,t1,t2 = map(int,input().split()) player1 = (s*v1)+(t1*2) player2 = (s*v2)+(t2*2) if player1<player2: print('First') elif player2<player1: print('Second') else: print("Friendship")
Title: Key races Time Limit: None seconds Memory Limit: None megabytes Problem Description: Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of *s* characters. The first participant types one character in *v*1 milliseconds and has ping *t...
```python s,v1,v2,t1,t2 = map(int,input().split()) player1 = (s*v1)+(t1*2) player2 = (s*v2)+(t2*2) if player1<player2: print('First') elif player2<player1: print('Second') else: print("Friendship") ```
3
676
A
Nicholas and Permutation
PROGRAMMING
800
[ "constructive algorithms", "implementation" ]
null
null
Nicholas has an array *a* that contains *n* distinct integers from 1 to *n*. In other words, Nicholas has a permutation of size *n*. Nicholas want the minimum element (integer 1) and the maximum element (integer *n*) to be as far as possible from each other. He wants to perform exactly one swap in order to maximize th...
The first line of the input contains a single integer *n* (2<=≀<=*n*<=≀<=100)Β β€” the size of the permutation. The second line of the input contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≀<=*a**i*<=≀<=*n*), where *a**i* is equal to the element at the *i*-th position.
Print a single integerΒ β€” the maximum possible distance between the minimum and the maximum elements Nicholas can achieve by performing exactly one swap.
[ "5\n4 5 1 3 2\n", "7\n1 6 5 3 4 7 2\n", "6\n6 5 4 3 2 1\n" ]
[ "3\n", "6\n", "5\n" ]
In the first sample, one may obtain the optimal answer by swapping elements 1 and 2. In the second sample, the minimum and the maximum elements will be located in the opposite ends of the array if we swap 7 and 2. In the third sample, the distance between the minimum and the maximum elements is already maximum possib...
500
[ { "input": "5\n4 5 1 3 2", "output": "3" }, { "input": "7\n1 6 5 3 4 7 2", "output": "6" }, { "input": "6\n6 5 4 3 2 1", "output": "5" }, { "input": "2\n1 2", "output": "1" }, { "input": "2\n2 1", "output": "1" }, { "input": "3\n2 3 1", "output": "...
1,652,544,762
2,147,483,647
PyPy 3
OK
TESTS
159
124
0
n=input() s=input().split() M=s.index(n) n=int(n) m=s.index('1') print(max(m,M,n-m-1,n-1-M))
Title: Nicholas and Permutation Time Limit: None seconds Memory Limit: None megabytes Problem Description: Nicholas has an array *a* that contains *n* distinct integers from 1 to *n*. In other words, Nicholas has a permutation of size *n*. Nicholas want the minimum element (integer 1) and the maximum element (integ...
```python n=input() s=input().split() M=s.index(n) n=int(n) m=s.index('1') print(max(m,M,n-m-1,n-1-M)) ```
3
600
B
Queries about less or equal elements
PROGRAMMING
1,300
[ "binary search", "data structures", "sortings", "two pointers" ]
null
null
You are given two arrays of integers *a* and *b*. For each element of the second array *b**j* you should find the number of elements in array *a* that are less than or equal to the value *b**j*.
The first line contains two integers *n*,<=*m* (1<=≀<=*n*,<=*m*<=≀<=2Β·105) β€” the sizes of arrays *a* and *b*. The second line contains *n* integers β€” the elements of array *a* (<=-<=109<=≀<=*a**i*<=≀<=109). The third line contains *m* integers β€” the elements of array *b* (<=-<=109<=≀<=*b**j*<=≀<=109).
Print *m* integers, separated by spaces: the *j*-th of which is equal to the number of such elements in array *a* that are less than or equal to the value *b**j*.
[ "5 4\n1 3 5 7 9\n6 4 2 8\n", "5 5\n1 2 1 2 5\n3 1 4 1 5\n" ]
[ "3 2 1 4\n", "4 2 4 2 5\n" ]
none
0
[ { "input": "5 4\n1 3 5 7 9\n6 4 2 8", "output": "3 2 1 4" }, { "input": "5 5\n1 2 1 2 5\n3 1 4 1 5", "output": "4 2 4 2 5" }, { "input": "1 1\n-1\n-2", "output": "0" }, { "input": "1 1\n-80890826\n686519510", "output": "1" }, { "input": "11 11\n237468511 -77918754...
1,671,007,780
2,147,483,647
Python 3
OK
TESTS
60
1,715
19,660,800
def binsearch(x): l, r = 0, n while l<r: m = (l+r)//2 if a[m] <= x: l = m+1 else: r = m return l n, m = map(int, input().split()) a = sorted([int(i) for i in input().split()]) b = [int(i) for i in input().split()] for i in range(m...
Title: Queries about less or equal elements Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given two arrays of integers *a* and *b*. For each element of the second array *b**j* you should find the number of elements in array *a* that are less than or equal to the value *b**j*. In...
```python def binsearch(x): l, r = 0, n while l<r: m = (l+r)//2 if a[m] <= x: l = m+1 else: r = m return l n, m = map(int, input().split()) a = sorted([int(i) for i in input().split()]) b = [int(i) for i in input().split()] for i ...
3
78
B
Easter Eggs
PROGRAMMING
1,200
[ "constructive algorithms", "implementation" ]
B. Easter Eggs
2
256
The Easter Rabbit laid *n* eggs in a circle and is about to paint them. Each egg should be painted one color out of 7: red, orange, yellow, green, blue, indigo or violet. Also, the following conditions should be satisfied: - Each of the seven colors should be used to paint at least one egg. - Any four eggs lying s...
The only line contains an integer *n* β€” the amount of eggs (7<=≀<=*n*<=≀<=100).
Print one line consisting of *n* characters. The *i*-th character should describe the color of the *i*-th egg in the order they lie in the circle. The colors should be represented as follows: "R" stands for red, "O" stands for orange, "Y" stands for yellow, "G" stands for green, "B" stands for blue, "I" stands for indi...
[ "8\n", "13\n" ]
[ "ROYGRBIV\n", "ROYGBIVGBIVYG\n" ]
The way the eggs will be painted in the first sample is shown on the picture:
1,000
[ { "input": "8", "output": "ROYGBIVG" }, { "input": "13", "output": "ROYGBIVOYGBIV" }, { "input": "7", "output": "ROYGBIV" }, { "input": "10", "output": "ROYGBIVYGB" }, { "input": "14", "output": "ROYGBIVROYGBIV" }, { "input": "50", "output": "ROYGB...
1,643,215,464
2,147,483,647
Python 3
OK
TESTS
34
124
0
n = int(input()) - 7 print('ROYGBIV' + 'GBIV' * (n // 4) + 'GBIV'[:n % 4])
Title: Easter Eggs Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: The Easter Rabbit laid *n* eggs in a circle and is about to paint them. Each egg should be painted one color out of 7: red, orange, yellow, green, blue, indigo or violet. Also, the following conditions should be satisfied: -...
```python n = int(input()) - 7 print('ROYGBIV' + 'GBIV' * (n // 4) + 'GBIV'[:n % 4]) ```
3.969
90
B
African Crossword
PROGRAMMING
1,100
[ "implementation", "strings" ]
B. African Crossword
2
256
An African crossword is a rectangular table *n*<=Γ—<=*m* in size. Each cell of the table contains exactly one letter. This table (it is also referred to as grid) contains some encrypted word that needs to be decoded. To solve the crossword you should cross out all repeated letters in rows and columns. In other words, a...
The first line contains two integers *n* and *m* (1<=≀<=*n*,<=*m*<=≀<=100). Next *n* lines contain *m* lowercase Latin letters each. That is the crossword grid.
Print the encrypted word on a single line. It is guaranteed that the answer consists of at least one letter.
[ "3 3\ncba\nbcd\ncbc\n", "5 5\nfcofd\nooedo\nafaoa\nrdcdf\neofsf\n" ]
[ "abcd", "codeforces" ]
none
1,000
[ { "input": "3 3\ncba\nbcd\ncbc", "output": "abcd" }, { "input": "5 5\nfcofd\nooedo\nafaoa\nrdcdf\neofsf", "output": "codeforces" }, { "input": "4 4\nusah\nusha\nhasu\nsuha", "output": "ahhasusu" }, { "input": "7 5\naabcd\neffgh\niijkk\nlmnoo\npqqrs\nttuvw\nxxyyz", "output...
1,531,576,796
2,147,483,647
Python 3
OK
TESTS
43
342
512,000
inds=set() def is_not_clone(words,x,z): clone=1 sim=words[z][x] #print('cursim=',sim) n=len(words) if (x,z) in inds: return 0 for c,item in enumerate(words[z]): #print('c=%s sim=%s '%(c,item)) if sim==item and c!=x: inds.add((c,z)) cl...
Title: African Crossword Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: An African crossword is a rectangular table *n*<=Γ—<=*m* in size. Each cell of the table contains exactly one letter. This table (it is also referred to as grid) contains some encrypted word that needs to be decoded. To s...
```python inds=set() def is_not_clone(words,x,z): clone=1 sim=words[z][x] #print('cursim=',sim) n=len(words) if (x,z) in inds: return 0 for c,item in enumerate(words[z]): #print('c=%s sim=%s '%(c,item)) if sim==item and c!=x: inds.add((c,z)) ...
3.913546
53
C
Little Frog
PROGRAMMING
1,200
[ "constructive algorithms" ]
C. Little Frog
2
256
Once upon a time a little frog whose name was Vasya decided to travel around his home swamp. Overall there are *n* mounds on the swamp, located on one line. The distance between the neighboring mounds is one meter. Vasya wants to visit all the mounds in one day; besides, he wants to visit each one exactly once. For tha...
The single line contains a number *n* (1<=≀<=*n*<=≀<=104) which is the number of mounds.
Print *n* integers *p**i* (1<=≀<=*p**i*<=≀<=*n*) which are the frog's route plan. - All the *p**i*'s should be mutually different. - All the |*p**i*–*p**i*<=+<=1|'s should be mutually different (1<=≀<=*i*<=≀<=*n*<=-<=1). If there are several solutions, output any.
[ "2\n", "3\n" ]
[ "1 2 ", "1 3 2 " ]
none
1,500
[ { "input": "2", "output": "1 2 " }, { "input": "3", "output": "1 3 2 " }, { "input": "4", "output": "1 4 2 3 " }, { "input": "5", "output": "1 5 2 4 3 " }, { "input": "6", "output": "1 6 2 5 3 4 " }, { "input": "1", "output": "1 " }, { "inp...
1,679,499,000
2,147,483,647
Python 3
OK
TESTS
22
122
102,400
import math n=int(input()) l=[i+1 for i in range(n)] l2=[] for i in range(int(n/2)): l2.append(l[i]) l2.append(l[-(i+1)]) if n%2==1: l2.append(math.ceil(n/2)) print(*l2)
Title: Little Frog Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Once upon a time a little frog whose name was Vasya decided to travel around his home swamp. Overall there are *n* mounds on the swamp, located on one line. The distance between the neighboring mounds is one meter. Vasya wants ...
```python import math n=int(input()) l=[i+1 for i in range(n)] l2=[] for i in range(int(n/2)): l2.append(l[i]) l2.append(l[-(i+1)]) if n%2==1: l2.append(math.ceil(n/2)) print(*l2) ```
3.969309
10
A
Power Consumption Calculation
PROGRAMMING
900
[ "implementation" ]
A. Power Consumption Calculation
1
256
Tom is interested in power consumption of his favourite laptop. His laptop has three modes. In normal mode laptop consumes *P*1 watt per minute. *T*1 minutes after Tom moved the mouse or touched the keyboard for the last time, a screensaver starts and power consumption changes to *P*2 watt per minute. Finally, after *T...
The first line contains 6 integer numbers *n*, *P*1, *P*2, *P*3, *T*1, *T*2 (1<=≀<=*n*<=≀<=100,<=0<=≀<=*P*1,<=*P*2,<=*P*3<=≀<=100,<=1<=≀<=*T*1,<=*T*2<=≀<=60). The following *n* lines contain description of Tom's work. Each *i*-th of these lines contains two space-separated integers *l**i* and *r**i* (0<=≀<=*l**i*<=&lt;...
Output the answer to the problem.
[ "1 3 2 1 5 10\n0 10\n", "2 8 4 2 5 10\n20 30\n50 100\n" ]
[ "30", "570" ]
none
0
[ { "input": "1 3 2 1 5 10\n0 10", "output": "30" }, { "input": "2 8 4 2 5 10\n20 30\n50 100", "output": "570" }, { "input": "3 15 9 95 39 19\n873 989\n1003 1137\n1172 1436", "output": "8445" }, { "input": "4 73 2 53 58 16\n51 52\n209 242\n281 407\n904 945", "output": "5287...
1,673,735,430
2,147,483,647
PyPy 3-64
OK
TESTS
30
154
0
[n,p1,p2,p3,t1,t2]=[int(x) for x in input().split()]; rold=-1; ans=0; for _ in range(n): [l,r]=[int(x) for x in input().split()]; ans+=(r-l)*p1; if rold>0: if l-rold>=t1+t2: ans+=p1*t1+p2*t2+p3*(l-rold-t1-t2); elif l-rold>=t1: ans+=p1*t1+p2*(l-rold-t1); ...
Title: Power Consumption Calculation Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Tom is interested in power consumption of his favourite laptop. His laptop has three modes. In normal mode laptop consumes *P*1 watt per minute. *T*1 minutes after Tom moved the mouse or touched the keyboard f...
```python [n,p1,p2,p3,t1,t2]=[int(x) for x in input().split()]; rold=-1; ans=0; for _ in range(n): [l,r]=[int(x) for x in input().split()]; ans+=(r-l)*p1; if rold>0: if l-rold>=t1+t2: ans+=p1*t1+p2*t2+p3*(l-rold-t1-t2); elif l-rold>=t1: ans+=p1*t1+p2*(l-ro...
3.923
397
A
On Segment's Own Points
PROGRAMMING
0
[ "implementation" ]
null
null
Our old friend Alexey has finally entered the University of City N β€” the Berland capital. Alexey expected his father to get him a place to live in but his father said it was high time for Alexey to practice some financial independence. So, Alexey is living in a dorm. The dorm has exactly one straight dryer β€” a 100 ce...
The first line contains a positive integer *n* (1<=≀<=*n*<=≀<=100). The (*i*<=+<=1)-th line contains integers *l**i* and *r**i* (0<=≀<=*l**i*<=&lt;<=*r**i*<=≀<=100) β€”Β the endpoints of the corresponding segment for the *i*-th student.
On a single line print a single number *k*, equal to the sum of lengths of the parts of the dryer which are inside Alexey's segment and are outside all other segments.
[ "3\n0 5\n2 8\n1 6\n", "3\n0 10\n1 5\n7 15\n" ]
[ "1\n", "3\n" ]
Note that it's not important are clothes drying on the touching segments (e.g. (0, 1) and (1, 2)) considered to be touching or not because you need to find the length of segments. In the first test sample Alexey may use the only segment (0, 1). In such case his clothes will not touch clothes on the segments (1, 6) and...
500
[ { "input": "3\n0 5\n2 8\n1 6", "output": "1" }, { "input": "3\n0 10\n1 5\n7 15", "output": "3" }, { "input": "1\n0 100", "output": "100" }, { "input": "2\n1 9\n1 9", "output": "0" }, { "input": "2\n1 9\n5 10", "output": "4" }, { "input": "2\n1 9\n3 5",...
1,568,378,574
2,147,483,647
Python 3
OK
TESTS
37
109
0
#code n=int(input()) x,y=input().split() x,y = int(x),int(y) l=list(range(x,y)) s=set(l) for i in range (1,n): p,q=input().split() p,q=int(p),int(q) l1=list(range(p,q)) s1=set(l1) s=s-s1 print(len(s))
Title: On Segment's Own Points Time Limit: None seconds Memory Limit: None megabytes Problem Description: Our old friend Alexey has finally entered the University of City N β€” the Berland capital. Alexey expected his father to get him a place to live in but his father said it was high time for Alexey to practice some...
```python #code n=int(input()) x,y=input().split() x,y = int(x),int(y) l=list(range(x,y)) s=set(l) for i in range (1,n): p,q=input().split() p,q=int(p),int(q) l1=list(range(p,q)) s1=set(l1) s=s-s1 print(len(s)) ```
3
69
A
Young Physicist
PROGRAMMING
1,000
[ "implementation", "math" ]
A. Young Physicist
2
256
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy...
The first line contains a positive integer *n* (1<=≀<=*n*<=≀<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≀<=*x**i*,<=*y**i*,<=*z**i*<=≀<=100).
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
[ "3\n4 1 7\n-2 4 -1\n1 -5 -3\n", "3\n3 -1 7\n-5 2 -4\n2 -1 -3\n" ]
[ "NO", "YES" ]
none
500
[ { "input": "3\n4 1 7\n-2 4 -1\n1 -5 -3", "output": "NO" }, { "input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3", "output": "YES" }, { "input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41", "output": "NO" }, { "input": "10...
1,661,313,778
2,147,483,647
PyPy 3-64
OK
TESTS
81
154
0
x = y = z = 0 for _ in range(int(input())): forces = tuple(map(int, input().split())) x += forces[0] y += forces[1] z += forces[2] print("YES" if x == y == z == 0 else "NO")
Title: Young Physicist Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. S...
```python x = y = z = 0 for _ in range(int(input())): forces = tuple(map(int, input().split())) x += forces[0] y += forces[1] z += forces[2] print("YES" if x == y == z == 0 else "NO") ```
3.9615
591
A
Wizards' Duel
PROGRAMMING
900
[ "implementation", "math" ]
null
null
Harry Potter and He-Who-Must-Not-Be-Named engaged in a fight to the death once again. This time they are located at opposite ends of the corridor of length *l*. Two opponents simultaneously charge a deadly spell in the enemy. We know that the impulse of Harry's magic spell flies at a speed of *p* meters per second, and...
The first line of the input contains a single integer *l* (1<=≀<=*l*<=≀<=1<=000)Β β€” the length of the corridor where the fight takes place. The second line contains integer *p*, the third line contains integer *q* (1<=≀<=*p*,<=*q*<=≀<=500)Β β€” the speeds of magical impulses for Harry Potter and He-Who-Must-Not-Be-Named, ...
Print a single real numberΒ β€” the distance from the end of the corridor, where Harry is located, to the place of the second meeting of the spell impulses. Your answer will be considered correct if its absolute or relative error will not exceed 10<=-<=4. Namely: let's assume that your answer equals *a*, and the answer ...
[ "100\n50\n50\n", "199\n60\n40\n" ]
[ "50\n", "119.4\n" ]
In the first sample the speeds of the impulses are equal, so both of their meetings occur exactly in the middle of the corridor.
500
[ { "input": "100\n50\n50", "output": "50" }, { "input": "199\n60\n40", "output": "119.4" }, { "input": "1\n1\n1", "output": "0.5" }, { "input": "1\n1\n500", "output": "0.001996007984" }, { "input": "1\n500\n1", "output": "0.998003992" }, { "input": "1\n...
1,689,070,731
2,147,483,647
Python 3
OK
TESTS
45
46
0
l = int(input()) p = int(input()) q = int(input()) x = p*l/(p+q) print(x)
Title: Wizards' Duel Time Limit: None seconds Memory Limit: None megabytes Problem Description: Harry Potter and He-Who-Must-Not-Be-Named engaged in a fight to the death once again. This time they are located at opposite ends of the corridor of length *l*. Two opponents simultaneously charge a deadly spell in the en...
```python l = int(input()) p = int(input()) q = int(input()) x = p*l/(p+q) print(x) ```
3
483
B
Friends and Presents
PROGRAMMING
1,800
[ "binary search", "math" ]
null
null
You have two friends. You want to present each of them several positive integers. You want to present *cnt*1 numbers to the first friend and *cnt*2 numbers to the second friend. Moreover, you want all presented numbers to be distinct, that also means that no number should be presented to both friends. In addition, the...
The only line contains four positive integers *cnt*1, *cnt*2, *x*, *y* (1<=≀<=*cnt*1,<=*cnt*2<=&lt;<=109; *cnt*1<=+<=*cnt*2<=≀<=109; 2<=≀<=*x*<=&lt;<=*y*<=≀<=3Β·104)Β β€” the numbers that are described in the statement. It is guaranteed that numbers *x*, *y* are prime.
Print a single integer β€” the answer to the problem.
[ "3 1 2 3\n", "1 3 2 3\n" ]
[ "5\n", "4\n" ]
In the first sample you give the set of numbers {1, 3, 5} to the first friend and the set of numbers {2} to the second friend. Note that if you give set {1, 3, 5} to the first friend, then we cannot give any of the numbers 1, 3, 5 to the second friend. In the second sample you give the set of numbers {3} to the first...
1,000
[ { "input": "3 1 2 3", "output": "5" }, { "input": "1 3 2 3", "output": "4" }, { "input": "916200 69682 2 3", "output": "1832399" }, { "input": "808351 17767 433 509", "output": "826121" }, { "input": "8851 901 20897 26183", "output": "9752" }, { "input...
1,556,776,736
2,147,483,647
Python 3
OK
TESTS
50
109
0
def judge(n,m,sum): cnt=int(sum/x/y) if x==y: cnt=int(sum/x) #print(cnt) n=max(0, n-int(sum/y)+cnt) m=max(0, m-int(sum/x)+cnt) #print(n,m) if(sum-int(sum/x)-int(sum/y)+cnt>=n+m): tmp=0 else: tmp=m+n-(sum-int(sum/x)-int(sum/y)+cnt) #print(tmp) return tm...
Title: Friends and Presents Time Limit: None seconds Memory Limit: None megabytes Problem Description: You have two friends. You want to present each of them several positive integers. You want to present *cnt*1 numbers to the first friend and *cnt*2 numbers to the second friend. Moreover, you want all presented num...
```python def judge(n,m,sum): cnt=int(sum/x/y) if x==y: cnt=int(sum/x) #print(cnt) n=max(0, n-int(sum/y)+cnt) m=max(0, m-int(sum/x)+cnt) #print(n,m) if(sum-int(sum/x)-int(sum/y)+cnt>=n+m): tmp=0 else: tmp=m+n-(sum-int(sum/x)-int(sum/y)+cnt) #print(tmp) ...
3
136
A
Presents
PROGRAMMING
800
[ "implementation" ]
null
null
Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited *n* his friends there. If...
The first line contains one integer *n* (1<=≀<=*n*<=≀<=100) β€” the quantity of friends Petya invited to the party. The second line contains *n* space-separated integers: the *i*-th number is *p**i* β€” the number of a friend who gave a gift to friend number *i*. It is guaranteed that each friend received exactly one gift....
Print *n* space-separated integers: the *i*-th number should equal the number of the friend who gave a gift to friend number *i*.
[ "4\n2 3 4 1\n", "3\n1 3 2\n", "2\n1 2\n" ]
[ "4 1 2 3\n", "1 3 2\n", "1 2\n" ]
none
500
[ { "input": "4\n2 3 4 1", "output": "4 1 2 3" }, { "input": "3\n1 3 2", "output": "1 3 2" }, { "input": "2\n1 2", "output": "1 2" }, { "input": "1\n1", "output": "1" }, { "input": "10\n1 3 2 6 4 5 7 9 8 10", "output": "1 3 2 5 6 4 7 9 8 10" }, { "input"...
1,699,078,015
2,147,483,647
Python 3
OK
TESTS
101
92
0
n=int(input()) m=[] l=list(map(int,input().split())) for i in range(1,len(l)+1): m.append(l.index(i)+1) for j in m: print(j,end=" ") print()
Title: Presents Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on t...
```python n=int(input()) m=[] l=list(map(int,input().split())) for i in range(1,len(l)+1): m.append(l.index(i)+1) for j in m: print(j,end=" ") print() ```
3
911
D
Inversion Counting
PROGRAMMING
1,800
[ "brute force", "math" ]
null
null
A permutation of size *n* is an array of size *n* such that each integer from 1 to *n* occurs exactly once in this array. An inversion in a permutation *p* is a pair of indices (*i*,<=*j*) such that *i*<=&gt;<=*j* and *a**i*<=&lt;<=*a**j*. For example, a permutation [4,<=1,<=3,<=2] contains 4 inversions: (2,<=1), (3,<=...
The first line contains one integer *n* (1<=≀<=*n*<=≀<=1500) β€” the size of the permutation. The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≀<=*a**i*<=≀<=*n*) β€” the elements of the permutation. These integers are pairwise distinct. The third line contains one integer *m* (1<=≀<=*m*<=≀<=2Β·105) β€” the...
Print *m* lines. *i*-th of them must be equal to odd if the number of inversions in the permutation after *i*-th query is odd, and even otherwise.
[ "3\n1 2 3\n2\n1 2\n2 3\n", "4\n1 2 4 3\n4\n1 1\n1 4\n1 4\n2 3\n" ]
[ "odd\neven\n", "odd\nodd\nodd\neven\n" ]
The first example: 1. after the first query *a* = [2, 1, 3], inversion: (2, 1); 1. after the second query *a* = [2, 3, 1], inversions: (3, 1), (3, 2). The second example: 1. *a* = [1, 2, 4, 3], inversion: (4, 3); 1. *a* = [3, 4, 2, 1], inversions: (3, 1), (4, 1), (3, 2), (4, 2), (4, 3); 1. *a* = [1, 2, 4, 3], i...
0
[ { "input": "3\n1 2 3\n2\n1 2\n2 3", "output": "odd\neven" }, { "input": "4\n1 2 4 3\n4\n1 1\n1 4\n1 4\n2 3", "output": "odd\nodd\nodd\neven" }, { "input": "7\n2 6 1 7 4 5 3\n5\n4 5\n7 7\n5 6\n4 5\n4 5", "output": "odd\nodd\neven\nodd\neven" }, { "input": "3\n2 1 3\n3\n2 3\n1 ...
1,523,042,919
2,147,483,647
Python 3
OK
TESTS
23
1,263
7,782,400
from sys import stdin, stdout n = int(stdin.readline()) values = list(map(int, stdin.readline().split())) cnt = 0 for i in range(n): for j in range(i + 1, n): if values[i] > values[j]: cnt += 1 m = int(stdin.readline()) for i in range(m): l, r = map(int, stdin.readline().spli...
Title: Inversion Counting Time Limit: None seconds Memory Limit: None megabytes Problem Description: A permutation of size *n* is an array of size *n* such that each integer from 1 to *n* occurs exactly once in this array. An inversion in a permutation *p* is a pair of indices (*i*,<=*j*) such that *i*<=&gt;<=*j* an...
```python from sys import stdin, stdout n = int(stdin.readline()) values = list(map(int, stdin.readline().split())) cnt = 0 for i in range(n): for j in range(i + 1, n): if values[i] > values[j]: cnt += 1 m = int(stdin.readline()) for i in range(m): l, r = map(int, stdin.readl...
3
432
A
Choosing Teams
PROGRAMMING
800
[ "greedy", "implementation", "sortings" ]
null
null
The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC rules, each person can participate in the world championship at most 5 times. Th...
The first line contains two integers, *n* and *k* (1<=≀<=*n*<=≀<=2000;Β 1<=≀<=*k*<=≀<=5). The next line contains *n* integers: *y*1,<=*y*2,<=...,<=*y**n* (0<=≀<=*y**i*<=≀<=5), where *y**i* shows the number of times the *i*-th person participated in the ACM ICPC world championship.
Print a single number β€” the answer to the problem.
[ "5 2\n0 4 5 1 0\n", "6 4\n0 1 2 3 4 5\n", "6 5\n0 0 0 0 0 0\n" ]
[ "1\n", "0\n", "2\n" ]
In the first sample only one team could be made: the first, the fourth and the fifth participants. In the second sample no teams could be created. In the third sample two teams could be created. Any partition into two teams fits.
500
[ { "input": "5 2\n0 4 5 1 0", "output": "1" }, { "input": "6 4\n0 1 2 3 4 5", "output": "0" }, { "input": "6 5\n0 0 0 0 0 0", "output": "2" }, { "input": "3 4\n0 1 0", "output": "1" }, { "input": "3 4\n0 2 0", "output": "0" }, { "input": "6 5\n0 0 0 0 0...
1,652,534,002
2,147,483,647
Python 3
OK
TESTS
35
31
0
n, k = input().split() n, k = int(n), int(k) rez = 0 a = input().split() for i in range(len(a)): a[i] = int(a[i]) + k for i in a: if i <= 5: rez += 1 print(rez // 3)
Title: Choosing Teams Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. Accordi...
```python n, k = input().split() n, k = int(n), int(k) rez = 0 a = input().split() for i in range(len(a)): a[i] = int(a[i]) + k for i in a: if i <= 5: rez += 1 print(rez // 3) ```
3
313
B
Ilya and Queries
PROGRAMMING
1,100
[ "dp", "implementation" ]
null
null
Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam. You've got string *s*<==<=*s*1*s*2... *s**n* (*n* is the length of the string), consisting only of characters "." and "#" and *m* queries. Each query is described by a pair of integers *l**i*,<...
The first line contains string *s* of length *n* (2<=≀<=*n*<=≀<=105). It is guaranteed that the given string only consists of characters "." and "#". The next line contains integer *m* (1<=≀<=*m*<=≀<=105) β€” the number of queries. Each of the next *m* lines contains the description of the corresponding query. The *i*-t...
Print *m* integers β€” the answers to the queries in the order in which they are given in the input.
[ "......\n4\n3 4\n2 3\n1 6\n2 6\n", "#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4\n" ]
[ "1\n1\n5\n4\n", "1\n1\n2\n2\n0\n" ]
none
1,000
[ { "input": "......\n4\n3 4\n2 3\n1 6\n2 6", "output": "1\n1\n5\n4" }, { "input": "#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4", "output": "1\n1\n2\n2\n0" }, { "input": ".#...#..\n6\n1 5\n2 3\n6 7\n2 4\n2 5\n1 3", "output": "2\n0\n0\n1\n2\n0" }, { "input": "#.#.#..\n5\n3 4\n4 5\n5 7\n5...
1,693,565,132
2,147,483,647
PyPy 3-64
OK
TESTS
37
404
14,950,400
from sys import stdin def input(): return stdin.readline()[:-1] a=list(input()) n=len(a) p=[0]*(n+1) if a[0]==a[1]: p[1]=1 for i in range(1,n-1): if a[i]==a[i+1]: p[i+1]=p[i]+1 else: p[i+1]=p[i] q=int(input()) for i in range(q): l,r=map(int,input().split()) print(p[r-1]-p[l-1])
Title: Ilya and Queries Time Limit: None seconds Memory Limit: None megabytes Problem Description: Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam. You've got string *s*<==<=*s*1*s*2... *s**n* (*n* is the length of the string), consisting ...
```python from sys import stdin def input(): return stdin.readline()[:-1] a=list(input()) n=len(a) p=[0]*(n+1) if a[0]==a[1]: p[1]=1 for i in range(1,n-1): if a[i]==a[i+1]: p[i+1]=p[i]+1 else: p[i+1]=p[i] q=int(input()) for i in range(q): l,r=map(int,input().split()) print(p[r-1]-p[l-1]) ```
3
9
A
Die Roll
PROGRAMMING
800
[ "math", "probabilities" ]
A. Die Roll
1
64
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpr...
The only line of the input file contains two natural numbers Y and W β€” the results of Yakko's and Wakko's die rolls.
Output the required probability in the form of irreducible fraction in format Β«A/BΒ», where A β€” the numerator, and B β€” the denominator. If the required probability equals to zero, output Β«0/1Β». If the required probability equals to 1, output Β«1/1Β».
[ "4 2\n" ]
[ "1/2\n" ]
Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points.
0
[ { "input": "4 2", "output": "1/2" }, { "input": "1 1", "output": "1/1" }, { "input": "1 2", "output": "5/6" }, { "input": "1 3", "output": "2/3" }, { "input": "1 4", "output": "1/2" }, { "input": "1 5", "output": "1/3" }, { "input": "1 6", ...
1,661,953,570
2,147,483,647
Python 3
OK
TESTS
36
92
0
# cook your dish here y,w = map(int,input().split()) if y>w: res = y else: res = w res = (6-res) + 1 l = ["0/1","1/6","1/3","1/2","2/3","5/6","1/1"] print(l[res])
Title: Die Roll Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about T...
```python # cook your dish here y,w = map(int,input().split()) if y>w: res = y else: res = w res = (6-res) + 1 l = ["0/1","1/6","1/3","1/2","2/3","5/6","1/1"] print(l[res]) ```
3.954
245
A
System Administrator
PROGRAMMING
800
[ "implementation" ]
null
null
Polycarpus is a system administrator. There are two servers under his strict guidance β€” *a* and *b*. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a progra...
The first line contains a single integer *n* (2<=≀<=*n*<=≀<=1000) β€” the number of commands Polycarpus has fulfilled. Each of the following *n* lines contains three integers β€” the description of the commands. The *i*-th of these lines contains three space-separated integers *t**i*, *x**i*, *y**i* (1<=≀<=*t**i*<=≀<=2;Β *x...
In the first line print string "LIVE" (without the quotes) if server *a* is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server *b* in the similar format.
[ "2\n1 5 5\n2 6 4\n", "3\n1 0 10\n2 0 10\n1 10 0\n" ]
[ "LIVE\nLIVE\n", "LIVE\nDEAD\n" ]
Consider the first test case. There 10 packets were sent to server *a*, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server *b*, 6 of them reached it. Therefore, at least half of all packets sent to t...
0
[ { "input": "2\n1 5 5\n2 6 4", "output": "LIVE\nLIVE" }, { "input": "3\n1 0 10\n2 0 10\n1 10 0", "output": "LIVE\nDEAD" }, { "input": "10\n1 3 7\n2 4 6\n1 2 8\n2 5 5\n2 10 0\n2 10 0\n1 8 2\n2 2 8\n2 10 0\n1 1 9", "output": "DEAD\nLIVE" }, { "input": "11\n1 8 2\n1 6 4\n1 9 1\n1...
1,599,983,351
2,147,483,647
Python 3
OK
TESTS
13
218
307,200
def check(n1, n2): if n1 >= n2: print("LIVE") else: print("DEAD") a_rec, a_nrec = 0, 0 b_rec, b_nrec = 0, 0 for _ in range(int(input())): t, x, y = [int(j) for j in input().split()] if t == 1: a_rec += x a_nrec += y else: b_rec += x b_nre...
Title: System Administrator Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarpus is a system administrator. There are two servers under his strict guidance β€” *a* and *b*. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping co...
```python def check(n1, n2): if n1 >= n2: print("LIVE") else: print("DEAD") a_rec, a_nrec = 0, 0 b_rec, b_nrec = 0, 0 for _ in range(int(input())): t, x, y = [int(j) for j in input().split()] if t == 1: a_rec += x a_nrec += y else: b_rec += x ...
3
440
B
Balancer
PROGRAMMING
1,600
[ "greedy", "implementation" ]
null
null
Petya has *k* matches, placed in *n* matchboxes lying in a line from left to right. We know that *k* is divisible by *n*. Petya wants all boxes to have the same number of matches inside. For that, he can move a match from its box to the adjacent one in one move. How many such moves does he need to achieve the desired c...
The first line contains integer *n* (1<=≀<=*n*<=≀<=50000). The second line contains *n* non-negative numbers that do not exceed 109, the *i*-th written number is the number of matches in the *i*-th matchbox. It is guaranteed that the total number of matches is divisible by *n*.
Print the total minimum number of moves.
[ "6\n1 6 2 5 3 7\n" ]
[ "12\n" ]
none
1,000
[ { "input": "6\n1 6 2 5 3 7", "output": "12" }, { "input": "6\n6 6 6 0 0 0", "output": "27" }, { "input": "6\n0 0 0 6 6 6", "output": "27" }, { "input": "6\n6 6 0 0 6 6", "output": "12" }, { "input": "5\n0 0 0 0 0", "output": "0" }, { "input": "10\n0 10...
1,401,812,532
3,132
Python 3
OK
TESTS
53
218
4,198,400
import itertools n = int(input()) a = map(int, input().split()) a = list(itertools.accumulate(a)) need_one = a[-1] // n ans = 0 for i in range(len(a) - 1): ans += abs((i + 1) * need_one - a[i]) print(ans)
Title: Balancer Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya has *k* matches, placed in *n* matchboxes lying in a line from left to right. We know that *k* is divisible by *n*. Petya wants all boxes to have the same number of matches inside. For that, he can move a match from its ...
```python import itertools n = int(input()) a = map(int, input().split()) a = list(itertools.accumulate(a)) need_one = a[-1] // n ans = 0 for i in range(len(a) - 1): ans += abs((i + 1) * need_one - a[i]) print(ans) ```
3