contestId
int64
0
1.01k
index
stringclasses
57 values
name
stringlengths
2
58
type
stringclasses
2 values
rating
int64
0
3.5k
tags
listlengths
0
11
title
stringclasses
522 values
time-limit
stringclasses
8 values
memory-limit
stringclasses
8 values
problem-description
stringlengths
0
7.15k
input-specification
stringlengths
0
2.05k
output-specification
stringlengths
0
1.5k
demo-input
listlengths
0
7
demo-output
listlengths
0
7
note
stringlengths
0
5.24k
points
float64
0
425k
test_cases
listlengths
0
402
creationTimeSeconds
int64
1.37B
1.7B
relativeTimeSeconds
int64
8
2.15B
programmingLanguage
stringclasses
3 values
verdict
stringclasses
14 values
testset
stringclasses
12 values
passedTestCount
int64
0
1k
timeConsumedMillis
int64
0
15k
memoryConsumedBytes
int64
0
805M
code
stringlengths
3
65.5k
prompt
stringlengths
262
8.2k
response
stringlengths
17
65.5k
score
float64
-1
3.99
451
A
Game With Sticks
PROGRAMMING
900
[ "implementation" ]
null
null
After winning gold and silver in IOI 2014, Akshat and Malvika want to have some fun. Now they are playing a game on a grid made of *n* horizontal and *m* vertical sticks. An intersection point is any point on the grid which is formed by the intersection of one horizontal stick and one vertical stick. In the grid shown below, *n*<==<=3 and *m*<==<=3. There are *n*<=+<=*m*<==<=6 sticks in total (horizontal sticks are shown in red and vertical sticks are shown in green). There are *n*·*m*<==<=9 intersection points, numbered from 1 to 9. The rules of the game are very simple. The players move in turns. Akshat won gold, so he makes the first move. During his/her move, a player must choose any remaining intersection point and remove from the grid all sticks which pass through this point. A player will lose the game if he/she cannot make a move (i.e. there are no intersection points remaining on the grid at his/her move). Assume that both players play optimally. Who will win the game?
The first line of input contains two space-separated integers, *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100).
Print a single line containing "Akshat" or "Malvika" (without the quotes), depending on the winner of the game.
[ "2 2\n", "2 3\n", "3 3\n" ]
[ "Malvika\n", "Malvika\n", "Akshat\n" ]
Explanation of the first sample: The grid has four intersection points, numbered from 1 to 4. If Akshat chooses intersection point 1, then he will remove two sticks (1 - 2 and 1 - 3). The resulting grid will look like this. Now there is only one remaining intersection point (i.e. 4). Malvika must choose it and remove both remaining sticks. After her move the grid will be empty. In the empty grid, Akshat cannot make any move, hence he will lose. Since all 4 intersection points of the grid are equivalent, Akshat will lose no matter which one he picks.
500
[ { "input": "2 2", "output": "Malvika" }, { "input": "2 3", "output": "Malvika" }, { "input": "3 3", "output": "Akshat" }, { "input": "20 68", "output": "Malvika" }, { "input": "1 1", "output": "Akshat" }, { "input": "1 2", "output": "Akshat" }, ...
1,685,711,875
2,147,483,647
Python 3
OK
TESTS
28
46
0
a = list(map(int,input().split())) b = min(a[0],a[1]) if b%2 == 0: print("Malvika") else: print("Akshat")
Title: Game With Sticks Time Limit: None seconds Memory Limit: None megabytes Problem Description: After winning gold and silver in IOI 2014, Akshat and Malvika want to have some fun. Now they are playing a game on a grid made of *n* horizontal and *m* vertical sticks. An intersection point is any point on the grid which is formed by the intersection of one horizontal stick and one vertical stick. In the grid shown below, *n*<==<=3 and *m*<==<=3. There are *n*<=+<=*m*<==<=6 sticks in total (horizontal sticks are shown in red and vertical sticks are shown in green). There are *n*·*m*<==<=9 intersection points, numbered from 1 to 9. The rules of the game are very simple. The players move in turns. Akshat won gold, so he makes the first move. During his/her move, a player must choose any remaining intersection point and remove from the grid all sticks which pass through this point. A player will lose the game if he/she cannot make a move (i.e. there are no intersection points remaining on the grid at his/her move). Assume that both players play optimally. Who will win the game? Input Specification: The first line of input contains two space-separated integers, *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100). Output Specification: Print a single line containing "Akshat" or "Malvika" (without the quotes), depending on the winner of the game. Demo Input: ['2 2\n', '2 3\n', '3 3\n'] Demo Output: ['Malvika\n', 'Malvika\n', 'Akshat\n'] Note: Explanation of the first sample: The grid has four intersection points, numbered from 1 to 4. If Akshat chooses intersection point 1, then he will remove two sticks (1 - 2 and 1 - 3). The resulting grid will look like this. Now there is only one remaining intersection point (i.e. 4). Malvika must choose it and remove both remaining sticks. After her move the grid will be empty. In the empty grid, Akshat cannot make any move, hence he will lose. Since all 4 intersection points of the grid are equivalent, Akshat will lose no matter which one he picks.
```python a = list(map(int,input().split())) b = min(a[0],a[1]) if b%2 == 0: print("Malvika") else: print("Akshat") ```
3
202
A
LLPS
PROGRAMMING
800
[ "binary search", "bitmasks", "brute force", "greedy", "implementation", "strings" ]
null
null
This problem's actual name, "Lexicographically Largest Palindromic Subsequence" is too long to fit into the page headline. You are given string *s* consisting of lowercase English letters only. Find its lexicographically largest palindromic subsequence. We'll call a non-empty string *s*[*p*1*p*2... *p**k*] = *s**p*1*s**p*2... *s**p**k* (1 <=≤<= *p*1<=&lt;<=*p*2<=&lt;<=...<=&lt;<=*p**k* <=≤<= |*s*|) a subsequence of string *s* = *s*1*s*2... *s*|*s*|, where |*s*| is the length of string *s*. For example, strings "abcb", "b" and "abacaba" are subsequences of string "abacaba". String *x* = *x*1*x*2... *x*|*x*| is lexicographically larger than string *y* = *y*1*y*2... *y*|*y*| if either |*x*| &gt; |*y*| and *x*1<==<=*y*1, *x*2<==<=*y*2, ...,<=*x*|*y*|<==<=*y*|*y*|, or there exists such number *r* (*r*<=&lt;<=|*x*|, *r*<=&lt;<=|*y*|) that *x*1<==<=*y*1, *x*2<==<=*y*2, ..., *x**r*<==<=*y**r* and *x**r*<=<=+<=<=1<=&gt;<=*y**r*<=<=+<=<=1. Characters in the strings are compared according to their ASCII codes. For example, string "ranger" is lexicographically larger than string "racecar" and string "poster" is lexicographically larger than string "post". String *s* = *s*1*s*2... *s*|*s*| is a palindrome if it matches string *rev*(*s*) = *s*|*s*|*s*|*s*|<=-<=1... *s*1. In other words, a string is a palindrome if it reads the same way from left to right and from right to left. For example, palindromic strings are "racecar", "refer" and "z".
The only input line contains a non-empty string *s* consisting of lowercase English letters only. Its length does not exceed 10.
Print the lexicographically largest palindromic subsequence of string *s*.
[ "radar\n", "bowwowwow\n", "codeforces\n", "mississipp\n" ]
[ "rr\n", "wwwww\n", "s\n", "ssss\n" ]
Among all distinct subsequences of string "radar" the following ones are palindromes: "a", "d", "r", "aa", "rr", "ada", "rar", "rdr", "raar" and "radar". The lexicographically largest of them is "rr".
500
[ { "input": "radar", "output": "rr" }, { "input": "bowwowwow", "output": "wwwww" }, { "input": "codeforces", "output": "s" }, { "input": "mississipp", "output": "ssss" }, { "input": "tourist", "output": "u" }, { "input": "romka", "output": "r" }, ...
1,585,903,100
2,147,483,647
PyPy 3
OK
TESTS
54
280
0
#----Kuzlyaev-Nikita-Codeforces----- #------------03.04.2020------------- alph="abcdefghijklmnopqrstuvwxyz" #----------------------------------- s=str(input()) m="" for i in range(len(s)): m=max(m,s[i]) print(m*s.count(m))
Title: LLPS Time Limit: None seconds Memory Limit: None megabytes Problem Description: This problem's actual name, "Lexicographically Largest Palindromic Subsequence" is too long to fit into the page headline. You are given string *s* consisting of lowercase English letters only. Find its lexicographically largest palindromic subsequence. We'll call a non-empty string *s*[*p*1*p*2... *p**k*] = *s**p*1*s**p*2... *s**p**k* (1 <=≤<= *p*1<=&lt;<=*p*2<=&lt;<=...<=&lt;<=*p**k* <=≤<= |*s*|) a subsequence of string *s* = *s*1*s*2... *s*|*s*|, where |*s*| is the length of string *s*. For example, strings "abcb", "b" and "abacaba" are subsequences of string "abacaba". String *x* = *x*1*x*2... *x*|*x*| is lexicographically larger than string *y* = *y*1*y*2... *y*|*y*| if either |*x*| &gt; |*y*| and *x*1<==<=*y*1, *x*2<==<=*y*2, ...,<=*x*|*y*|<==<=*y*|*y*|, or there exists such number *r* (*r*<=&lt;<=|*x*|, *r*<=&lt;<=|*y*|) that *x*1<==<=*y*1, *x*2<==<=*y*2, ..., *x**r*<==<=*y**r* and *x**r*<=<=+<=<=1<=&gt;<=*y**r*<=<=+<=<=1. Characters in the strings are compared according to their ASCII codes. For example, string "ranger" is lexicographically larger than string "racecar" and string "poster" is lexicographically larger than string "post". String *s* = *s*1*s*2... *s*|*s*| is a palindrome if it matches string *rev*(*s*) = *s*|*s*|*s*|*s*|<=-<=1... *s*1. In other words, a string is a palindrome if it reads the same way from left to right and from right to left. For example, palindromic strings are "racecar", "refer" and "z". Input Specification: The only input line contains a non-empty string *s* consisting of lowercase English letters only. Its length does not exceed 10. Output Specification: Print the lexicographically largest palindromic subsequence of string *s*. Demo Input: ['radar\n', 'bowwowwow\n', 'codeforces\n', 'mississipp\n'] Demo Output: ['rr\n', 'wwwww\n', 's\n', 'ssss\n'] Note: Among all distinct subsequences of string "radar" the following ones are palindromes: "a", "d", "r", "aa", "rr", "ada", "rar", "rdr", "raar" and "radar". The lexicographically largest of them is "rr".
```python #----Kuzlyaev-Nikita-Codeforces----- #------------03.04.2020------------- alph="abcdefghijklmnopqrstuvwxyz" #----------------------------------- s=str(input()) m="" for i in range(len(s)): m=max(m,s[i]) print(m*s.count(m)) ```
3
791
A
Bear and Big Brother
PROGRAMMING
800
[ "implementation" ]
null
null
Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob. Right now, Limak and Bob weigh *a* and *b* respectively. It's guaranteed that Limak's weight is smaller than or equal to his brother's weight. Limak eats a lot and his weight is tripled after every year, while Bob's weight is doubled after every year. After how many full years will Limak become strictly larger (strictly heavier) than Bob?
The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10) — the weight of Limak and the weight of Bob respectively.
Print one integer, denoting the integer number of years after which Limak will become strictly larger than Bob.
[ "4 7\n", "4 9\n", "1 1\n" ]
[ "2\n", "3\n", "1\n" ]
In the first sample, Limak weighs 4 and Bob weighs 7 initially. After one year their weights are 4·3 = 12 and 7·2 = 14 respectively (one weight is tripled while the other one is doubled). Limak isn't larger than Bob yet. After the second year weights are 36 and 28, so the first weight is greater than the second one. Limak became larger than Bob after two years so you should print 2. In the second sample, Limak's and Bob's weights in next years are: 12 and 18, then 36 and 36, and finally 108 and 72 (after three years). The answer is 3. Remember that Limak wants to be larger than Bob and he won't be satisfied with equal weights. In the third sample, Limak becomes larger than Bob after the first year. Their weights will be 3 and 2 then.
500
[ { "input": "4 7", "output": "2" }, { "input": "4 9", "output": "3" }, { "input": "1 1", "output": "1" }, { "input": "4 6", "output": "2" }, { "input": "1 10", "output": "6" }, { "input": "1 1", "output": "1" }, { "input": "1 2", "output...
1,693,845,568
2,147,483,647
PyPy 3-64
OK
TESTS
62
62
0
a, b= input().split() a= int(a) b= int(b) counter= 0 while a <= b: a= 3*a b= 2*b counter+= 1 print(counter)
Title: Bear and Big Brother Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob. Right now, Limak and Bob weigh *a* and *b* respectively. It's guaranteed that Limak's weight is smaller than or equal to his brother's weight. Limak eats a lot and his weight is tripled after every year, while Bob's weight is doubled after every year. After how many full years will Limak become strictly larger (strictly heavier) than Bob? Input Specification: The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10) — the weight of Limak and the weight of Bob respectively. Output Specification: Print one integer, denoting the integer number of years after which Limak will become strictly larger than Bob. Demo Input: ['4 7\n', '4 9\n', '1 1\n'] Demo Output: ['2\n', '3\n', '1\n'] Note: In the first sample, Limak weighs 4 and Bob weighs 7 initially. After one year their weights are 4·3 = 12 and 7·2 = 14 respectively (one weight is tripled while the other one is doubled). Limak isn't larger than Bob yet. After the second year weights are 36 and 28, so the first weight is greater than the second one. Limak became larger than Bob after two years so you should print 2. In the second sample, Limak's and Bob's weights in next years are: 12 and 18, then 36 and 36, and finally 108 and 72 (after three years). The answer is 3. Remember that Limak wants to be larger than Bob and he won't be satisfied with equal weights. In the third sample, Limak becomes larger than Bob after the first year. Their weights will be 3 and 2 then.
```python a, b= input().split() a= int(a) b= int(b) counter= 0 while a <= b: a= 3*a b= 2*b counter+= 1 print(counter) ```
3
825
D
Suitable Replacement
PROGRAMMING
1,500
[ "binary search", "greedy", "implementation" ]
null
null
You are given two strings *s* and *t* consisting of small Latin letters, string *s* can also contain '?' characters. Suitability of string *s* is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulting strings *s*, you choose the one with the largest number of non-intersecting occurrences of string *t*. Suitability is this number of occurrences. You should replace all '?' characters with small Latin letters in such a way that the suitability of string *s* is maximal.
The first line contains string *s* (1<=≤<=|*s*|<=≤<=106). The second line contains string *t* (1<=≤<=|*t*|<=≤<=106).
Print string *s* with '?' replaced with small Latin letters in such a way that suitability of that string is maximal. If there are multiple strings with maximal suitability then print any of them.
[ "?aa?\nab\n", "??b?\nza\n", "abcd\nabacaba\n" ]
[ "baab\n", "azbz\n", "abcd\n" ]
In the first example string "baab" can be transformed to "abab" with swaps, this one has suitability of 2. That means that string "baab" also has suitability of 2. In the second example maximal suitability you can achieve is 1 and there are several dozens of such strings, "azbz" is just one of them. In the third example there are no '?' characters and the suitability of the string is 0.
0
[ { "input": "?aa?\nab", "output": "baab" }, { "input": "??b?\nza", "output": "azbz" }, { "input": "abcd\nabacaba", "output": "abcd" }, { "input": "mqwstphetbfrsyxuzdww\nrutseqtsbh", "output": "mqwstphetbfrsyxuzdww" }, { "input": "????????????????????\nxwkxsxlrre", ...
1,526,221,480
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
8
1,000
10,137,600
s = input() t = input() neededChars = [] currChars = [] for i in range(26): temp = 0 for j in t: if j == chr(i+97): temp += 1 neededChars.append(temp) temp = 0 for j in s: if j == chr(i+97): temp += 1 currChars.append(temp) questions = 0 for i in s: if i == '?': questions += 1 need = [] suit = 0 for i in range(len(neededChars)): need.append(currChars[i]-neededChars[i]) newChars = "" while questions > 0: changed = False for count,i in enumerate(need): if i < 0: changed = True questions -= 1 newChars += chr(count+97) need[count] += 1 break if not changed: for i in range(len(neededChars)): need[i] -= neededChars[i] output = "" counter = 0 for i in s: if i == '?': output += newChars[counter] counter += 1 else: output += i print(output)
Title: Suitable Replacement Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given two strings *s* and *t* consisting of small Latin letters, string *s* can also contain '?' characters. Suitability of string *s* is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulting strings *s*, you choose the one with the largest number of non-intersecting occurrences of string *t*. Suitability is this number of occurrences. You should replace all '?' characters with small Latin letters in such a way that the suitability of string *s* is maximal. Input Specification: The first line contains string *s* (1<=≤<=|*s*|<=≤<=106). The second line contains string *t* (1<=≤<=|*t*|<=≤<=106). Output Specification: Print string *s* with '?' replaced with small Latin letters in such a way that suitability of that string is maximal. If there are multiple strings with maximal suitability then print any of them. Demo Input: ['?aa?\nab\n', '??b?\nza\n', 'abcd\nabacaba\n'] Demo Output: ['baab\n', 'azbz\n', 'abcd\n'] Note: In the first example string "baab" can be transformed to "abab" with swaps, this one has suitability of 2. That means that string "baab" also has suitability of 2. In the second example maximal suitability you can achieve is 1 and there are several dozens of such strings, "azbz" is just one of them. In the third example there are no '?' characters and the suitability of the string is 0.
```python s = input() t = input() neededChars = [] currChars = [] for i in range(26): temp = 0 for j in t: if j == chr(i+97): temp += 1 neededChars.append(temp) temp = 0 for j in s: if j == chr(i+97): temp += 1 currChars.append(temp) questions = 0 for i in s: if i == '?': questions += 1 need = [] suit = 0 for i in range(len(neededChars)): need.append(currChars[i]-neededChars[i]) newChars = "" while questions > 0: changed = False for count,i in enumerate(need): if i < 0: changed = True questions -= 1 newChars += chr(count+97) need[count] += 1 break if not changed: for i in range(len(neededChars)): need[i] -= neededChars[i] output = "" counter = 0 for i in s: if i == '?': output += newChars[counter] counter += 1 else: output += i print(output) ```
0
192
A
Funky Numbers
PROGRAMMING
1,300
[ "binary search", "brute force", "implementation" ]
null
null
As you very well know, this year's funkiest numbers are so called triangular numbers (that is, integers that are representable as , where *k* is some positive integer), and the coolest numbers are those that are representable as a sum of two triangular numbers. A well-known hipster Andrew adores everything funky and cool but unfortunately, he isn't good at maths. Given number *n*, help him define whether this number can be represented by a sum of two triangular numbers (not necessarily different)!
The first input line contains an integer *n* (1<=≤<=*n*<=≤<=109).
Print "YES" (without the quotes), if *n* can be represented as a sum of two triangular numbers, otherwise print "NO" (without the quotes).
[ "256\n", "512\n" ]
[ "YES\n", "NO\n" ]
In the first sample number <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/92095692c6ea93e9e3b837a0408ba7543549d5b2.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In the second sample number 512 can not be represented as a sum of two triangular numbers.
500
[ { "input": "256", "output": "YES" }, { "input": "512", "output": "NO" }, { "input": "80", "output": "NO" }, { "input": "828", "output": "YES" }, { "input": "6035", "output": "NO" }, { "input": "39210", "output": "YES" }, { "input": "79712",...
1,591,546,733
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
186
0
def cool_num(n): a = n**0.5 if int(a)==a: print("YES") else: print("NO") n=int(input()) cool_num(n)
Title: Funky Numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: As you very well know, this year's funkiest numbers are so called triangular numbers (that is, integers that are representable as , where *k* is some positive integer), and the coolest numbers are those that are representable as a sum of two triangular numbers. A well-known hipster Andrew adores everything funky and cool but unfortunately, he isn't good at maths. Given number *n*, help him define whether this number can be represented by a sum of two triangular numbers (not necessarily different)! Input Specification: The first input line contains an integer *n* (1<=≤<=*n*<=≤<=109). Output Specification: Print "YES" (without the quotes), if *n* can be represented as a sum of two triangular numbers, otherwise print "NO" (without the quotes). Demo Input: ['256\n', '512\n'] Demo Output: ['YES\n', 'NO\n'] Note: In the first sample number <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/92095692c6ea93e9e3b837a0408ba7543549d5b2.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In the second sample number 512 can not be represented as a sum of two triangular numbers.
```python def cool_num(n): a = n**0.5 if int(a)==a: print("YES") else: print("NO") n=int(input()) cool_num(n) ```
0
931
A
Friends Meeting
PROGRAMMING
800
[ "brute force", "greedy", "implementation", "math" ]
null
null
Two friends are on the coordinate axis *Ox* in points with integer coordinates. One of them is in the point *x*1<==<=*a*, another one is in the point *x*2<==<=*b*. Each of the friends can move by one along the line in any direction unlimited number of times. When a friend moves, the tiredness of a friend changes according to the following rules: the first move increases the tiredness by 1, the second move increases the tiredness by 2, the third — by 3 and so on. For example, if a friend moves first to the left, then to the right (returning to the same point), and then again to the left his tiredness becomes equal to 1<=+<=2<=+<=3<==<=6. The friends want to meet in a integer point. Determine the minimum total tiredness they should gain, if they meet in the same point.
The first line contains a single integer *a* (1<=≤<=*a*<=≤<=1000) — the initial position of the first friend. The second line contains a single integer *b* (1<=≤<=*b*<=≤<=1000) — the initial position of the second friend. It is guaranteed that *a*<=≠<=*b*.
Print the minimum possible total tiredness if the friends meet in the same point.
[ "3\n4\n", "101\n99\n", "5\n10\n" ]
[ "1\n", "2\n", "9\n" ]
In the first example the first friend should move by one to the right (then the meeting happens at point 4), or the second friend should move by one to the left (then the meeting happens at point 3). In both cases, the total tiredness becomes 1. In the second example the first friend should move by one to the left, and the second friend should move by one to the right. Then they meet in the point 100, and the total tiredness becomes 1 + 1 = 2. In the third example one of the optimal ways is the following. The first friend should move three times to the right, and the second friend — two times to the left. Thus the friends meet in the point 8, and the total tiredness becomes 1 + 2 + 3 + 1 + 2 = 9.
500
[ { "input": "3\n4", "output": "1" }, { "input": "101\n99", "output": "2" }, { "input": "5\n10", "output": "9" }, { "input": "1\n2", "output": "1" }, { "input": "1\n1000", "output": "250000" }, { "input": "999\n1000", "output": "1" }, { "inpu...
1,626,642,253
2,147,483,647
PyPy 3
OK
TESTS
40
109
20,172,800
a = int(input()) b = int(input()) if a > b: temp = a a = b b = temp atired = 1 btired = 1 score = 0 while a != b: a += 1 score += atired atired += 1 if a == b: break b -= 1 score += btired btired += 1 print(score)
Title: Friends Meeting Time Limit: None seconds Memory Limit: None megabytes Problem Description: Two friends are on the coordinate axis *Ox* in points with integer coordinates. One of them is in the point *x*1<==<=*a*, another one is in the point *x*2<==<=*b*. Each of the friends can move by one along the line in any direction unlimited number of times. When a friend moves, the tiredness of a friend changes according to the following rules: the first move increases the tiredness by 1, the second move increases the tiredness by 2, the third — by 3 and so on. For example, if a friend moves first to the left, then to the right (returning to the same point), and then again to the left his tiredness becomes equal to 1<=+<=2<=+<=3<==<=6. The friends want to meet in a integer point. Determine the minimum total tiredness they should gain, if they meet in the same point. Input Specification: The first line contains a single integer *a* (1<=≤<=*a*<=≤<=1000) — the initial position of the first friend. The second line contains a single integer *b* (1<=≤<=*b*<=≤<=1000) — the initial position of the second friend. It is guaranteed that *a*<=≠<=*b*. Output Specification: Print the minimum possible total tiredness if the friends meet in the same point. Demo Input: ['3\n4\n', '101\n99\n', '5\n10\n'] Demo Output: ['1\n', '2\n', '9\n'] Note: In the first example the first friend should move by one to the right (then the meeting happens at point 4), or the second friend should move by one to the left (then the meeting happens at point 3). In both cases, the total tiredness becomes 1. In the second example the first friend should move by one to the left, and the second friend should move by one to the right. Then they meet in the point 100, and the total tiredness becomes 1 + 1 = 2. In the third example one of the optimal ways is the following. The first friend should move three times to the right, and the second friend — two times to the left. Thus the friends meet in the point 8, and the total tiredness becomes 1 + 2 + 3 + 1 + 2 = 9.
```python a = int(input()) b = int(input()) if a > b: temp = a a = b b = temp atired = 1 btired = 1 score = 0 while a != b: a += 1 score += atired atired += 1 if a == b: break b -= 1 score += btired btired += 1 print(score) ```
3
888
D
Almost Identity Permutations
PROGRAMMING
1,600
[ "combinatorics", "dp", "math" ]
null
null
A permutation *p* of size *n* is an array such that every integer from 1 to *n* occurs exactly once in this array. Let's call a permutation an almost identity permutation iff there exist at least *n*<=-<=*k* indices *i* (1<=≤<=*i*<=≤<=*n*) such that *p**i*<==<=*i*. Your task is to count the number of almost identity permutations for given numbers *n* and *k*.
The first line contains two integers *n* and *k* (4<=≤<=*n*<=≤<=1000, 1<=≤<=*k*<=≤<=4).
Print the number of almost identity permutations for given *n* and *k*.
[ "4 1\n", "4 2\n", "5 3\n", "5 4\n" ]
[ "1\n", "7\n", "31\n", "76\n" ]
none
0
[ { "input": "4 1", "output": "1" }, { "input": "4 2", "output": "7" }, { "input": "5 3", "output": "31" }, { "input": "5 4", "output": "76" }, { "input": "200 1", "output": "1" }, { "input": "200 2", "output": "19901" }, { "input": "200 3", ...
1,676,044,746
2,147,483,647
PyPy 3-64
OK
TESTS
25
46
0
import math n, k = map(int, input().split()) # d[i] - количество перестановок из i элементов без неподвижных точек. d = [1, 0, 1, 2, 9] ans = 0 for i in range(k + 1): ans += math.comb(n, n - i) * d[i] print(ans)
Title: Almost Identity Permutations Time Limit: None seconds Memory Limit: None megabytes Problem Description: A permutation *p* of size *n* is an array such that every integer from 1 to *n* occurs exactly once in this array. Let's call a permutation an almost identity permutation iff there exist at least *n*<=-<=*k* indices *i* (1<=≤<=*i*<=≤<=*n*) such that *p**i*<==<=*i*. Your task is to count the number of almost identity permutations for given numbers *n* and *k*. Input Specification: The first line contains two integers *n* and *k* (4<=≤<=*n*<=≤<=1000, 1<=≤<=*k*<=≤<=4). Output Specification: Print the number of almost identity permutations for given *n* and *k*. Demo Input: ['4 1\n', '4 2\n', '5 3\n', '5 4\n'] Demo Output: ['1\n', '7\n', '31\n', '76\n'] Note: none
```python import math n, k = map(int, input().split()) # d[i] - количество перестановок из i элементов без неподвижных точек. d = [1, 0, 1, 2, 9] ans = 0 for i in range(k + 1): ans += math.comb(n, n - i) * d[i] print(ans) ```
3
426
A
Sereja and Mugs
PROGRAMMING
800
[ "implementation" ]
null
null
Sereja showed an interesting game to his friends. The game goes like that. Initially, there is a table with an empty cup and *n* water mugs on it. Then all players take turns to move. During a move, a player takes a non-empty mug of water and pours all water from it into the cup. If the cup overfills, then we assume that this player lost. As soon as Sereja's friends heard of the game, they wanted to play it. Sereja, on the other hand, wanted to find out whether his friends can play the game in such a way that there are no losers. You are given the volumes of all mugs and the cup. Also, you know that Sereja has (*n*<=-<=1) friends. Determine if Sereja's friends can play the game so that nobody loses.
The first line contains integers *n* and *s* (2<=≤<=*n*<=≤<=100; 1<=≤<=*s*<=≤<=1000) — the number of mugs and the volume of the cup. The next line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=10). Number *a**i* means the volume of the *i*-th mug.
In a single line, print "YES" (without the quotes) if his friends can play in the described manner, and "NO" (without the quotes) otherwise.
[ "3 4\n1 1 1\n", "3 4\n3 1 3\n", "3 4\n4 4 4\n" ]
[ "YES\n", "YES\n", "NO\n" ]
none
500
[ { "input": "3 4\n1 1 1", "output": "YES" }, { "input": "3 4\n3 1 3", "output": "YES" }, { "input": "3 4\n4 4 4", "output": "NO" }, { "input": "2 1\n1 10", "output": "YES" }, { "input": "3 12\n5 6 6", "output": "YES" }, { "input": "4 10\n6 3 8 7", "...
1,543,419,003
2,147,483,647
Python 3
OK
TESTS
42
124
0
import itertools n,m=map(int,input().split()) l=list(map(int,input().split())) y=list(itertools.combinations(l,n-1)) for i in y : if sum(i)<=m: print("YES") break else: print("NO")
Title: Sereja and Mugs Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sereja showed an interesting game to his friends. The game goes like that. Initially, there is a table with an empty cup and *n* water mugs on it. Then all players take turns to move. During a move, a player takes a non-empty mug of water and pours all water from it into the cup. If the cup overfills, then we assume that this player lost. As soon as Sereja's friends heard of the game, they wanted to play it. Sereja, on the other hand, wanted to find out whether his friends can play the game in such a way that there are no losers. You are given the volumes of all mugs and the cup. Also, you know that Sereja has (*n*<=-<=1) friends. Determine if Sereja's friends can play the game so that nobody loses. Input Specification: The first line contains integers *n* and *s* (2<=≤<=*n*<=≤<=100; 1<=≤<=*s*<=≤<=1000) — the number of mugs and the volume of the cup. The next line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=10). Number *a**i* means the volume of the *i*-th mug. Output Specification: In a single line, print "YES" (without the quotes) if his friends can play in the described manner, and "NO" (without the quotes) otherwise. Demo Input: ['3 4\n1 1 1\n', '3 4\n3 1 3\n', '3 4\n4 4 4\n'] Demo Output: ['YES\n', 'YES\n', 'NO\n'] Note: none
```python import itertools n,m=map(int,input().split()) l=list(map(int,input().split())) y=list(itertools.combinations(l,n-1)) for i in y : if sum(i)<=m: print("YES") break else: print("NO") ```
3
63
A
Sinking Ship
PROGRAMMING
900
[ "implementation", "sortings", "strings" ]
A. Sinking Ship
2
256
The ship crashed into a reef and is sinking. Now the entire crew must be evacuated. All *n* crew members have already lined up in a row (for convenience let's label them all from left to right with positive integers from 1 to *n*) and await further instructions. However, one should evacuate the crew properly, in a strict order. Specifically: The first crew members to leave the ship are rats. Then women and children (both groups have the same priority) leave the ship. After that all men are evacuated from the ship. The captain leaves the sinking ship last. If we cannot determine exactly who should leave the ship first for any two members of the crew by the rules from the previous paragraph, then the one who stands to the left in the line leaves the ship first (or in other words, the one whose number in the line is less). For each crew member we know his status as a crew member, and also his name. All crew members have different names. Determine the order in which to evacuate the crew.
The first line contains an integer *n*, which is the number of people in the crew (1<=≤<=*n*<=≤<=100). Then follow *n* lines. The *i*-th of those lines contains two words — the name of the crew member who is *i*-th in line, and his status on the ship. The words are separated by exactly one space. There are no other spaces in the line. The names consist of Latin letters, the first letter is uppercase, the rest are lowercase. The length of any name is from 1 to 10 characters. The status can have the following values: rat for a rat, woman for a woman, child for a child, man for a man, captain for the captain. The crew contains exactly one captain.
Print *n* lines. The *i*-th of them should contain the name of the crew member who must be the *i*-th one to leave the ship.
[ "6\nJack captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman\n" ]
[ "Teddy\nAlice\nBob\nJulia\nCharlie\nJack\n" ]
none
500
[ { "input": "6\nJack captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman", "output": "Teddy\nAlice\nBob\nJulia\nCharlie\nJack" }, { "input": "1\nA captain", "output": "A" }, { "input": "1\nAbcdefjhij captain", "output": "Abcdefjhij" }, { "input": "5\nA captain...
1,665,999,671
2,147,483,647
PyPy 3-64
OK
TESTS
26
154
0
t = int(input()) animals = [] women_child = [] men = [] captain = [] for i in range(t): name, categ = input().split() if categ == "rat": animals.append(name) elif categ == "woman" or categ == "child": women_child.append(name) elif categ == "man": men.append(name) elif categ == "captain": captain.append(name) k = animals + women_child + men + captain for i in k: print(i)
Title: Sinking Ship Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: The ship crashed into a reef and is sinking. Now the entire crew must be evacuated. All *n* crew members have already lined up in a row (for convenience let's label them all from left to right with positive integers from 1 to *n*) and await further instructions. However, one should evacuate the crew properly, in a strict order. Specifically: The first crew members to leave the ship are rats. Then women and children (both groups have the same priority) leave the ship. After that all men are evacuated from the ship. The captain leaves the sinking ship last. If we cannot determine exactly who should leave the ship first for any two members of the crew by the rules from the previous paragraph, then the one who stands to the left in the line leaves the ship first (or in other words, the one whose number in the line is less). For each crew member we know his status as a crew member, and also his name. All crew members have different names. Determine the order in which to evacuate the crew. Input Specification: The first line contains an integer *n*, which is the number of people in the crew (1<=≤<=*n*<=≤<=100). Then follow *n* lines. The *i*-th of those lines contains two words — the name of the crew member who is *i*-th in line, and his status on the ship. The words are separated by exactly one space. There are no other spaces in the line. The names consist of Latin letters, the first letter is uppercase, the rest are lowercase. The length of any name is from 1 to 10 characters. The status can have the following values: rat for a rat, woman for a woman, child for a child, man for a man, captain for the captain. The crew contains exactly one captain. Output Specification: Print *n* lines. The *i*-th of them should contain the name of the crew member who must be the *i*-th one to leave the ship. Demo Input: ['6\nJack captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman\n'] Demo Output: ['Teddy\nAlice\nBob\nJulia\nCharlie\nJack\n'] Note: none
```python t = int(input()) animals = [] women_child = [] men = [] captain = [] for i in range(t): name, categ = input().split() if categ == "rat": animals.append(name) elif categ == "woman" or categ == "child": women_child.append(name) elif categ == "man": men.append(name) elif categ == "captain": captain.append(name) k = animals + women_child + men + captain for i in k: print(i) ```
3.9615
23
B
Party
PROGRAMMING
1,600
[ "constructive algorithms", "graphs", "math" ]
B. Party
2
256
*n* people came to a party. Then those, who had no friends among people at the party, left. Then those, who had exactly 1 friend among those who stayed, left as well. Then those, who had exactly 2,<=3,<=...,<=*n*<=-<=1 friends among those who stayed by the moment of their leaving, did the same. What is the maximum amount of people that could stay at the party in the end?
The first input line contains one number *t* — amount of tests (1<=≤<=*t*<=≤<=105). Each of the following *t* lines contains one integer number *n* (1<=≤<=*n*<=≤<=105).
For each test output in a separate line one number — the maximum amount of people that could stay in the end.
[ "1\n3\n" ]
[ "1\n" ]
none
0
[ { "input": "1\n3", "output": "1" } ]
1,523,464,786
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
1
2,000
28,057,600
n=int(input()) for i in range(1,n+1): nn=int(input()) if(nn==1): print(0) else: print(nn-2)
Title: Party Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: *n* people came to a party. Then those, who had no friends among people at the party, left. Then those, who had exactly 1 friend among those who stayed, left as well. Then those, who had exactly 2,<=3,<=...,<=*n*<=-<=1 friends among those who stayed by the moment of their leaving, did the same. What is the maximum amount of people that could stay at the party in the end? Input Specification: The first input line contains one number *t* — amount of tests (1<=≤<=*t*<=≤<=105). Each of the following *t* lines contains one integer number *n* (1<=≤<=*n*<=≤<=105). Output Specification: For each test output in a separate line one number — the maximum amount of people that could stay in the end. Demo Input: ['1\n3\n'] Demo Output: ['1\n'] Note: none
```python n=int(input()) for i in range(1,n+1): nn=int(input()) if(nn==1): print(0) else: print(nn-2) ```
0
980
A
Links and Pearls
PROGRAMMING
900
[ "implementation", "math" ]
null
null
A necklace can be described as a string of links ('-') and pearls ('o'), with the last link or pearl connected to the first one. You can remove a link or a pearl and insert it between two other existing links or pearls (or between a link and a pearl) on the necklace. This process can be repeated as many times as you like, but you can't throw away any parts. Can you make the number of links between every two adjacent pearls equal? Two pearls are considered to be adjacent if there is no other pearl between them. Note that the final necklace should remain as one circular part of the same length as the initial necklace.
The only line of input contains a string $s$ ($3 \leq |s| \leq 100$), representing the necklace, where a dash '-' represents a link and the lowercase English letter 'o' represents a pearl.
Print "YES" if the links and pearls can be rejoined such that the number of links between adjacent pearls is equal. Otherwise print "NO". You can print each letter in any case (upper or lower).
[ "-o-o--", "-o---\n", "-o---o-\n", "ooo\n" ]
[ "YES", "YES", "NO", "YES\n" ]
none
500
[ { "input": "-o-o--", "output": "YES" }, { "input": "-o---", "output": "YES" }, { "input": "-o---o-", "output": "NO" }, { "input": "ooo", "output": "YES" }, { "input": "---", "output": "YES" }, { "input": "--o-o-----o----o--oo-o-----ooo-oo---o--", "...
1,525,793,412
1,512
Python 3
OK
TESTS
69
108
7,065,600
l = list(input()) cnt1 = 0 cnt2 = 0 for i in l: if 'o' not in l: print("YES") exit() for i in l: if i == 'o': cnt1+=1 elif i == '-': cnt2+=1 if cnt2%cnt1==0: print("YES") else: print("NO")
Title: Links and Pearls Time Limit: None seconds Memory Limit: None megabytes Problem Description: A necklace can be described as a string of links ('-') and pearls ('o'), with the last link or pearl connected to the first one. You can remove a link or a pearl and insert it between two other existing links or pearls (or between a link and a pearl) on the necklace. This process can be repeated as many times as you like, but you can't throw away any parts. Can you make the number of links between every two adjacent pearls equal? Two pearls are considered to be adjacent if there is no other pearl between them. Note that the final necklace should remain as one circular part of the same length as the initial necklace. Input Specification: The only line of input contains a string $s$ ($3 \leq |s| \leq 100$), representing the necklace, where a dash '-' represents a link and the lowercase English letter 'o' represents a pearl. Output Specification: Print "YES" if the links and pearls can be rejoined such that the number of links between adjacent pearls is equal. Otherwise print "NO". You can print each letter in any case (upper or lower). Demo Input: ['-o-o--', '-o---\n', '-o---o-\n', 'ooo\n'] Demo Output: ['YES', 'YES', 'NO', 'YES\n'] Note: none
```python l = list(input()) cnt1 = 0 cnt2 = 0 for i in l: if 'o' not in l: print("YES") exit() for i in l: if i == 'o': cnt1+=1 elif i == '-': cnt2+=1 if cnt2%cnt1==0: print("YES") else: print("NO") ```
3
15
C
Industrial Nim
PROGRAMMING
2,000
[ "games" ]
C. Industrial Nim
2
64
There are *n* stone quarries in Petrograd. Each quarry owns *m**i* dumpers (1<=≤<=*i*<=≤<=*n*). It is known that the first dumper of the *i*-th quarry has *x**i* stones in it, the second dumper has *x**i*<=+<=1 stones in it, the third has *x**i*<=+<=2, and the *m**i*-th dumper (the last for the *i*-th quarry) has *x**i*<=+<=*m**i*<=-<=1 stones in it. Two oligarchs play a well-known game Nim. Players take turns removing stones from dumpers. On each turn, a player can select any dumper and remove any non-zero amount of stones from it. The player who cannot take a stone loses. Your task is to find out which oligarch will win, provided that both of them play optimally. The oligarchs asked you not to reveal their names. So, let's call the one who takes the first stone «tolik» and the other one «bolik».
The first line of the input contains one integer number *n* (1<=≤<=*n*<=≤<=105) — the amount of quarries. Then there follow *n* lines, each of them contains two space-separated integers *x**i* and *m**i* (1<=≤<=*x**i*,<=*m**i*<=≤<=1016) — the amount of stones in the first dumper of the *i*-th quarry and the number of dumpers at the *i*-th quarry.
Output «tolik» if the oligarch who takes a stone first wins, and «bolik» otherwise.
[ "2\n2 1\n3 2\n", "4\n1 1\n1 1\n1 1\n1 1\n" ]
[ "tolik\n", "bolik\n" ]
none
0
[ { "input": "2\n2 1\n3 2", "output": "tolik" }, { "input": "4\n1 1\n1 1\n1 1\n1 1", "output": "bolik" }, { "input": "10\n2 3\n1 4\n5 8\n4 10\n10 8\n7 2\n1 2\n1 7\n4 10\n5 3", "output": "tolik" }, { "input": "20\n8 6\n6 3\n2 9\n7 8\n9 1\n2 4\n3 6\n6 3\n5 6\n5 3\n6 5\n2 10\n2 9\...
1,637,229,771
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
62
0
def nim(): res = 0 for _ in range(int(input())): a = input().split() for j in range(int(a[1])): int(a)[0] + j return 'tolik' if res else 'bolik' print(nim())
Title: Industrial Nim Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: There are *n* stone quarries in Petrograd. Each quarry owns *m**i* dumpers (1<=≤<=*i*<=≤<=*n*). It is known that the first dumper of the *i*-th quarry has *x**i* stones in it, the second dumper has *x**i*<=+<=1 stones in it, the third has *x**i*<=+<=2, and the *m**i*-th dumper (the last for the *i*-th quarry) has *x**i*<=+<=*m**i*<=-<=1 stones in it. Two oligarchs play a well-known game Nim. Players take turns removing stones from dumpers. On each turn, a player can select any dumper and remove any non-zero amount of stones from it. The player who cannot take a stone loses. Your task is to find out which oligarch will win, provided that both of them play optimally. The oligarchs asked you not to reveal their names. So, let's call the one who takes the first stone «tolik» and the other one «bolik». Input Specification: The first line of the input contains one integer number *n* (1<=≤<=*n*<=≤<=105) — the amount of quarries. Then there follow *n* lines, each of them contains two space-separated integers *x**i* and *m**i* (1<=≤<=*x**i*,<=*m**i*<=≤<=1016) — the amount of stones in the first dumper of the *i*-th quarry and the number of dumpers at the *i*-th quarry. Output Specification: Output «tolik» if the oligarch who takes a stone first wins, and «bolik» otherwise. Demo Input: ['2\n2 1\n3 2\n', '4\n1 1\n1 1\n1 1\n1 1\n'] Demo Output: ['tolik\n', 'bolik\n'] Note: none
```python def nim(): res = 0 for _ in range(int(input())): a = input().split() for j in range(int(a[1])): int(a)[0] + j return 'tolik' if res else 'bolik' print(nim()) ```
-1
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 *t*2 milliseconds. If connection ping (delay) is *t* milliseconds, the competition passes for a participant as follows: 1. Exactly after *t* milliseconds after the start of the competition the participant receives the text to be entered. 1. Right after that he starts to type it. 1. Exactly *t* milliseconds after he ends typing all the text, the site receives information about it. The winner is the participant whose information on the success comes earlier. If the information comes from both participants at the same time, it is considered that there is a draw. Given the length of the text and the information about participants, determine the result of the game.
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 the ping of the second participant.
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, the second wins. In the third example, information on the success of the first participant comes in 22 milliseconds, of the second participant — in 22 milliseconds. So, it is be a draw.
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,645,960,246
2,147,483,647
Python 3
OK
TESTS
32
46
0
s, v1, v2, t1, t2 = map(int, input().split()) a = v1*s+2*t1 b = v2*s+2*t2 if a<b: print('First') elif a>b: 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*1 milliseconds. The second participant types one character in *v*2 milliseconds and has ping *t*2 milliseconds. If connection ping (delay) is *t* milliseconds, the competition passes for a participant as follows: 1. Exactly after *t* milliseconds after the start of the competition the participant receives the text to be entered. 1. Right after that he starts to type it. 1. Exactly *t* milliseconds after he ends typing all the text, the site receives information about it. The winner is the participant whose information on the success comes earlier. If the information comes from both participants at the same time, it is considered that there is a draw. Given the length of the text and the information about participants, determine the result of the game. Input Specification: 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 the ping of the second participant. Output Specification: If the first participant wins, print "First". If the second participant wins, print "Second". In case of a draw print "Friendship". Demo Input: ['5 1 2 1 2\n', '3 3 1 1 1\n', '4 5 3 1 5\n'] Demo Output: ['First\n', 'Second\n', 'Friendship\n'] Note: 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, the second wins. In the third example, information on the success of the first participant comes in 22 milliseconds, of the second participant — in 22 milliseconds. So, it is be a draw.
```python s, v1, v2, t1, t2 = map(int, input().split()) a = v1*s+2*t1 b = v2*s+2*t2 if a<b: print('First') elif a>b: print('Second') else: print('Friendship') ```
3
58
A
Chat room
PROGRAMMING
1,000
[ "greedy", "strings" ]
A. Chat room
1
256
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*.
The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.
If Vasya managed to say hello, print "YES", otherwise print "NO".
[ "ahhellllloou\n", "hlelo\n" ]
[ "YES\n", "NO\n" ]
none
500
[ { "input": "ahhellllloou", "output": "YES" }, { "input": "hlelo", "output": "NO" }, { "input": "helhcludoo", "output": "YES" }, { "input": "hehwelloho", "output": "YES" }, { "input": "pnnepelqomhhheollvlo", "output": "YES" }, { "input": "tymbzjyqhymeda...
1,692,364,861
2,147,483,647
Python 3
OK
TESTS
40
46
0
str_ = input() check = '' index = -1 for i in range(index + 1, len(str_)): if str_[i] == 'h': index = i check += 'h' break for i in range(index + 1, len(str_)): if str_[i] == 'e': index = i check += 'e' break for i in range(index + 1, len(str_)): if str_[i] == 'l': index = i check += 'l' break for i in range(index + 1, len(str_)): if str_[i] == 'l': index = i check += 'l' break for i in range(index + 1, len(str_)): if str_[i] == 'o': index = i check += 'o' break if check == 'hello': print('YES') else: print('NO')
Title: Chat room Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*. Input Specification: The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. Output Specification: If Vasya managed to say hello, print "YES", otherwise print "NO". Demo Input: ['ahhellllloou\n', 'hlelo\n'] Demo Output: ['YES\n', 'NO\n'] Note: none
```python str_ = input() check = '' index = -1 for i in range(index + 1, len(str_)): if str_[i] == 'h': index = i check += 'h' break for i in range(index + 1, len(str_)): if str_[i] == 'e': index = i check += 'e' break for i in range(index + 1, len(str_)): if str_[i] == 'l': index = i check += 'l' break for i in range(index + 1, len(str_)): if str_[i] == 'l': index = i check += 'l' break for i in range(index + 1, len(str_)): if str_[i] == 'o': index = i check += 'o' break if check == 'hello': print('YES') else: print('NO') ```
3.977
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 awarded points coincide, the wrestler who performed the last technique wins. Your task is to determine which wrestler won.
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* points. And if *a**i* is negative, that means that the second wrestler performed the technique that was awarded with (<=-<=*a**i*) points. The techniques are given in chronological order.
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;  |*y*| and *x*<sub class="lower-index">1</sub>  =  *y*<sub class="lower-index">1</sub>,  *x*<sub class="lower-index">2</sub>  =  *y*<sub class="lower-index">2</sub>, ... ,  *x*<sub class="lower-index">|*y*|</sub>  =  *y*<sub class="lower-index">|*y*|</sub>, or there is such number *r* (*r*  &lt;  |*x*|, *r*  &lt;  |*y*|), that *x*<sub class="lower-index">1</sub>  =  *y*<sub class="lower-index">1</sub>,  *x*<sub class="lower-index">2</sub>  =  *y*<sub class="lower-index">2</sub>,  ... ,  *x*<sub class="lower-index">*r*</sub>  =  *y*<sub class="lower-index">*r*</sub> and *x*<sub class="lower-index">*r*  +  1</sub>  &gt;  *y*<sub class="lower-index">*r*  +  1</sub>. We use notation |*a*| to denote length of sequence *a*.
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,571,124,830
2,147,483,647
PyPy 3
OK
TESTS
57
1,544
11,366,400
n = int(input()) last = 0 acts = [[], []] for i in range(n): curr = int(input()) if curr > 0: acts[0].append(curr) last = 1 else: acts[1].append(-curr) last = 2 s1, s2 = map(sum, acts) if s1 > s2: won = 1 elif s1 < s2: won = 2 elif acts[0] > acts[1]: won = 1 elif acts[0] < acts[1]: won = 2 else: won = last if won == 1: print("first") else: print("second")
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 are equal, the wrestler whose sequence of points is lexicographically greater, wins. If the sequences of the awarded points coincide, the wrestler who performed the last technique wins. Your task is to determine which wrestler won. Input Specification: 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* points. And if *a**i* is negative, that means that the second wrestler performed the technique that was awarded with (<=-<=*a**i*) points. The techniques are given in chronological order. Output Specification: If the first wrestler wins, print string "first", otherwise print "second" Demo Input: ['5\n1\n2\n-3\n-4\n3\n', '3\n-1\n-2\n3\n', '2\n4\n-4\n'] Demo Output: ['second\n', 'first\n', 'second\n'] Note: 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;  |*y*| and *x*<sub class="lower-index">1</sub>  =  *y*<sub class="lower-index">1</sub>,  *x*<sub class="lower-index">2</sub>  =  *y*<sub class="lower-index">2</sub>, ... ,  *x*<sub class="lower-index">|*y*|</sub>  =  *y*<sub class="lower-index">|*y*|</sub>, or there is such number *r* (*r*  &lt;  |*x*|, *r*  &lt;  |*y*|), that *x*<sub class="lower-index">1</sub>  =  *y*<sub class="lower-index">1</sub>,  *x*<sub class="lower-index">2</sub>  =  *y*<sub class="lower-index">2</sub>,  ... ,  *x*<sub class="lower-index">*r*</sub>  =  *y*<sub class="lower-index">*r*</sub> and *x*<sub class="lower-index">*r*  +  1</sub>  &gt;  *y*<sub class="lower-index">*r*  +  1</sub>. We use notation |*a*| to denote length of sequence *a*.
```python n = int(input()) last = 0 acts = [[], []] for i in range(n): curr = int(input()) if curr > 0: acts[0].append(curr) last = 1 else: acts[1].append(-curr) last = 2 s1, s2 = map(sum, acts) if s1 > s2: won = 1 elif s1 < s2: won = 2 elif acts[0] > acts[1]: won = 1 elif acts[0] < acts[1]: won = 2 else: won = last if won == 1: print("first") else: print("second") ```
3
527
A
Playing with Paper
PROGRAMMING
1,100
[ "implementation", "math" ]
null
null
One day Vasya was sitting on a not so interesting Maths lesson and making an origami from a rectangular *a* mm <=×<= *b* mm sheet of paper (*a*<=&gt;<=*b*). Usually the first step in making an origami is making a square piece of paper from the rectangular sheet by folding the sheet along the bisector of the right angle, and cutting the excess part. After making a paper ship from the square piece, Vasya looked on the remaining (*a*<=-<=*b*) mm <=×<= *b* mm strip of paper. He got the idea to use this strip of paper in the same way to make an origami, and then use the remainder (if it exists) and so on. At the moment when he is left with a square piece of paper, he will make the last ship from it and stop. Can you determine how many ships Vasya will make during the lesson?
The first line of the input contains two integers *a*, *b* (1<=≤<=*b*<=&lt;<=*a*<=≤<=1012) — the sizes of the original sheet of paper.
Print a single integer — the number of ships that Vasya will make.
[ "2 1\n", "10 7\n", "1000000000000 1\n" ]
[ "2\n", "6\n", "1000000000000\n" ]
Pictures to the first and second sample test.
500
[ { "input": "2 1", "output": "2" }, { "input": "10 7", "output": "6" }, { "input": "1000000000000 1", "output": "1000000000000" }, { "input": "3 1", "output": "3" }, { "input": "4 1", "output": "4" }, { "input": "3 2", "output": "3" }, { "in...
1,427,813,379
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
46
0
a, b = map(int, input().split()) total = a * b while b != 0 : qua = b*b s = int(total / qua) ans += s total = total - s * qua a = a - s*b a, b = b, a print(ans)
Title: Playing with Paper Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day Vasya was sitting on a not so interesting Maths lesson and making an origami from a rectangular *a* mm <=×<= *b* mm sheet of paper (*a*<=&gt;<=*b*). Usually the first step in making an origami is making a square piece of paper from the rectangular sheet by folding the sheet along the bisector of the right angle, and cutting the excess part. After making a paper ship from the square piece, Vasya looked on the remaining (*a*<=-<=*b*) mm <=×<= *b* mm strip of paper. He got the idea to use this strip of paper in the same way to make an origami, and then use the remainder (if it exists) and so on. At the moment when he is left with a square piece of paper, he will make the last ship from it and stop. Can you determine how many ships Vasya will make during the lesson? Input Specification: The first line of the input contains two integers *a*, *b* (1<=≤<=*b*<=&lt;<=*a*<=≤<=1012) — the sizes of the original sheet of paper. Output Specification: Print a single integer — the number of ships that Vasya will make. Demo Input: ['2 1\n', '10 7\n', '1000000000000 1\n'] Demo Output: ['2\n', '6\n', '1000000000000\n'] Note: Pictures to the first and second sample test.
```python a, b = map(int, input().split()) total = a * b while b != 0 : qua = b*b s = int(total / qua) ans += s total = total - s * qua a = a - s*b a, b = b, a print(ans) ```
-1
847
H
Load Testing
PROGRAMMING
1,600
[ "greedy" ]
null
null
Polycarp plans to conduct a load testing of its new project Fakebook. He already agreed with his friends that at certain points in time they will send requests to Fakebook. The load testing will last *n* minutes and in the *i*-th minute friends will send *a**i* requests. Polycarp plans to test Fakebook under a special kind of load. In case the information about Fakebook gets into the mass media, Polycarp hopes for a monotone increase of the load, followed by a monotone decrease of the interest to the service. Polycarp wants to test this form of load. Your task is to determine how many requests Polycarp must add so that before some moment the load on the server strictly increases and after that moment strictly decreases. Both the increasing part and the decreasing part can be empty (i. e. absent). The decrease should immediately follow the increase. In particular, the load with two equal neigbouring values is unacceptable. For example, if the load is described with one of the arrays [1, 2, 8, 4, 3], [1, 3, 5] or [10], then such load satisfies Polycarp (in each of the cases there is an increasing part, immediately followed with a decreasing part). If the load is described with one of the arrays [1, 2, 2, 1], [2, 1, 2] or [10, 10], then such load does not satisfy Polycarp. Help Polycarp to make the minimum number of additional requests, so that the resulting load satisfies Polycarp. He can make any number of additional requests at any minute from 1 to *n*.
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the duration of the load testing. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109), where *a**i* is the number of requests from friends in the *i*-th minute of the load testing.
Print the minimum number of additional requests from Polycarp that would make the load strictly increasing in the beginning and then strictly decreasing afterwards.
[ "5\n1 4 3 2 5\n", "5\n1 2 2 2 1\n", "7\n10 20 40 50 70 90 30\n" ]
[ "6\n", "1\n", "0\n" ]
In the first example Polycarp must make two additional requests in the third minute and four additional requests in the fourth minute. So the resulting load will look like: [1, 4, 5, 6, 5]. In total, Polycarp will make 6 additional requests. In the second example it is enough to make one additional request in the third minute, so the answer is 1. In the third example the load already satisfies all conditions described in the statement, so the answer is 0.
0
[ { "input": "5\n1 4 3 2 5", "output": "6" }, { "input": "5\n1 2 2 2 1", "output": "1" }, { "input": "7\n10 20 40 50 70 90 30", "output": "0" }, { "input": "1\n1", "output": "0" }, { "input": "2\n1 15", "output": "0" }, { "input": "4\n36 54 55 9", "o...
1,672,269,262
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
3
77
0
from math import inf from sys import stdin input = stdin.readline n = int(input()) a = [int(x) for x in input().split()] l, r = a[:], a[:] for i in range(1, n): l[i] = max(l[i], l[i-1]+1) for i in range(n-2, -1, -1): r[i] = max(r[i], r[i+1]+1) mn = inf; idx = 0 for i in range(1, n-1): if mn > max(l[i], r[i]): mn = max(l[i], r[i]) idx = i ans = 0 for i in range(idx): ans += l[i]-a[i] for i in range(idx+1, n): ans += r[i]-a[i] ans += mn-a[idx] print(ans) # 1 4 3 2 5 # 1 4 5 6 7 # 9 8 7 6 5 # 1 4 5 6 5 # 1 2 2 2 1 # 1 2 3 4 5 # 5 4 3 2 1 # 7 4 3 # 7 8 9 # 5 4 3
Title: Load Testing Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarp plans to conduct a load testing of its new project Fakebook. He already agreed with his friends that at certain points in time they will send requests to Fakebook. The load testing will last *n* minutes and in the *i*-th minute friends will send *a**i* requests. Polycarp plans to test Fakebook under a special kind of load. In case the information about Fakebook gets into the mass media, Polycarp hopes for a monotone increase of the load, followed by a monotone decrease of the interest to the service. Polycarp wants to test this form of load. Your task is to determine how many requests Polycarp must add so that before some moment the load on the server strictly increases and after that moment strictly decreases. Both the increasing part and the decreasing part can be empty (i. e. absent). The decrease should immediately follow the increase. In particular, the load with two equal neigbouring values is unacceptable. For example, if the load is described with one of the arrays [1, 2, 8, 4, 3], [1, 3, 5] or [10], then such load satisfies Polycarp (in each of the cases there is an increasing part, immediately followed with a decreasing part). If the load is described with one of the arrays [1, 2, 2, 1], [2, 1, 2] or [10, 10], then such load does not satisfy Polycarp. Help Polycarp to make the minimum number of additional requests, so that the resulting load satisfies Polycarp. He can make any number of additional requests at any minute from 1 to *n*. Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the duration of the load testing. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109), where *a**i* is the number of requests from friends in the *i*-th minute of the load testing. Output Specification: Print the minimum number of additional requests from Polycarp that would make the load strictly increasing in the beginning and then strictly decreasing afterwards. Demo Input: ['5\n1 4 3 2 5\n', '5\n1 2 2 2 1\n', '7\n10 20 40 50 70 90 30\n'] Demo Output: ['6\n', '1\n', '0\n'] Note: In the first example Polycarp must make two additional requests in the third minute and four additional requests in the fourth minute. So the resulting load will look like: [1, 4, 5, 6, 5]. In total, Polycarp will make 6 additional requests. In the second example it is enough to make one additional request in the third minute, so the answer is 1. In the third example the load already satisfies all conditions described in the statement, so the answer is 0.
```python from math import inf from sys import stdin input = stdin.readline n = int(input()) a = [int(x) for x in input().split()] l, r = a[:], a[:] for i in range(1, n): l[i] = max(l[i], l[i-1]+1) for i in range(n-2, -1, -1): r[i] = max(r[i], r[i+1]+1) mn = inf; idx = 0 for i in range(1, n-1): if mn > max(l[i], r[i]): mn = max(l[i], r[i]) idx = i ans = 0 for i in range(idx): ans += l[i]-a[i] for i in range(idx+1, n): ans += r[i]-a[i] ans += mn-a[idx] print(ans) # 1 4 3 2 5 # 1 4 5 6 7 # 9 8 7 6 5 # 1 4 5 6 5 # 1 2 2 2 1 # 1 2 3 4 5 # 5 4 3 2 1 # 7 4 3 # 7 8 9 # 5 4 3 ```
0
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 he visited in a row, in order of visiting them. Now, Vlad wants to find such a cafe that his last visit to that cafe was before his last visits to every other cafe. In other words, he wants to find such a cafe that he hasn't been there for as long as possible. Help Vlad to find that cafe.
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, some indices could be omitted.
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 index 2, so the answer is 2. Note that Vlad could omit some numbers while numerating the cafes.
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,585,291,387
2,147,483,647
PyPy 3
OK
TESTS
33
296
21,299,200
n=int(input()) l=[int(s) for s in input().split()] k=len(set(l)) #print(k) l1=set() for i in range(n-1,-1,-1): l1.add(l[i]) #print(l1) if len(l1)==k: print(l[i]) break
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. First of all, Vlad assigned individual indices to all cafes. Then, he wrote down indices of cafes he visited in a row, in order of visiting them. Now, Vlad wants to find such a cafe that his last visit to that cafe was before his last visits to every other cafe. In other words, he wants to find such a cafe that he hasn't been there for as long as possible. Help Vlad to find that cafe. Input Specification: 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, some indices could be omitted. Output Specification: Print one integer — index of the cafe that Vlad hasn't visited for as long as possible. Demo Input: ['5\n1 3 2 1 2\n', '6\n2 1 2 2 4 1\n'] Demo Output: ['3\n', '2\n'] Note: 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 index 2, so the answer is 2. Note that Vlad could omit some numbers while numerating the cafes.
```python n=int(input()) l=[int(s) for s in input().split()] k=len(set(l)) #print(k) l1=set() for i in range(n-1,-1,-1): l1.add(l[i]) #print(l1) if len(l1)==k: print(l[i]) break ```
3
558
B
Amr and The Large Array
PROGRAMMING
1,300
[ "implementation" ]
null
null
Amr has got a large array of size *n*. Amr doesn't like large arrays so he intends to make it smaller. Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array. Help Amr by choosing the smallest subsegment possible.
The first line contains one number *n* (1<=≤<=*n*<=≤<=105), the size of the array. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=106), representing elements of the array.
Output two integers *l*,<=*r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*), the beginning and the end of the subsegment chosen respectively. If there are several possible answers you may output any of them.
[ "5\n1 1 2 2 1\n", "5\n1 2 2 3 1\n", "6\n1 2 2 1 1 2\n" ]
[ "1 5", "2 3", "1 5" ]
A subsegment *B* of an array *A* from *l* to *r* is an array of size *r* - *l* + 1 where *B*<sub class="lower-index">*i*</sub> = *A*<sub class="lower-index">*l* + *i* - 1</sub> for all 1 ≤ *i* ≤ *r* - *l* + 1
1,000
[ { "input": "5\n1 1 2 2 1", "output": "1 5" }, { "input": "5\n1 2 2 3 1", "output": "2 3" }, { "input": "6\n1 2 2 1 1 2", "output": "1 5" }, { "input": "10\n1 1000000 2 1000000 3 2 1000000 1 2 1", "output": "2 7" }, { "input": "10\n1 2 3 4 5 5 1 2 3 4", "output...
1,462,112,532
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.StringTokenizer; import java.util.TreeMap; public class LargeArray { static void solve() { // Counter c = new Counter(); // while(true){ // String op = next(); // int n = nextInt(); // // if(op.equals("a")) // c.add(n); // else if (op.equals("m")){ // System.out.println(c.getMostCommonCount()); // } // else if (op.equals("d")) // c.removeOne(n); // // System.out.println(c); // } int n = nextInt(); int[] a = nextIntArr(n); Counter d = new Counter(); for (int i : a) d.add(i); int b = d.getMostCommonCount(); Counter c = new Counter(); int[] res = new int[]{0, n - 1}; int r = 0; c.add(a[0]); for (int l = 0; l < n; l++) { while (r < n - 1 && c.getMostCommonCount() < b) { r++; c.add(a[r]); } // System.err.println(l + " " + r); if (c.getMostCommonCount() >= b && r - l < res[1] - res[0]) res = new int[] { l, r }; c.removeOne(a[l]); } writer.println((res[0] + 1) + " " + (res[1] + 1)); } static class Counter { Map<Integer, Integer> count = new HashMap<>(); TreeMap<Integer, HashSet<Integer>> mostCommon = new TreeMap<>(); void add(int i) { count.merge(i, 1, Integer::sum); int cur_cnt = cnt(i); if (!mostCommon.containsKey(cur_cnt)) mostCommon.put(cur_cnt, new HashSet<>()); mostCommon.get(cur_cnt).add(i); cur_cnt--; if (cur_cnt > 0) { mostCommon.get(cur_cnt).remove(i); if (mostCommon.get(cur_cnt).isEmpty()) mostCommon.remove(cur_cnt); } } void removeOne(int i) { int cur_cnt = cnt(i); mostCommon.get(cur_cnt).remove(i); if (mostCommon.get(cur_cnt).isEmpty()) mostCommon.remove(cur_cnt); cur_cnt--; if (cur_cnt >= 0) { if (!mostCommon.containsKey(cur_cnt)) mostCommon.put(cur_cnt, new HashSet<>()); mostCommon.get(cur_cnt).add(i); } count.put(i, count.get(i) - 1); if (count.get(i) == 0) count.remove(i); } int cnt(int i) { return count.getOrDefault(i, 0); } int getMostCommonCount() { return mostCommon.lastKey(); } @Override public String toString() { return "[ " + count.toString() + " | " + mostCommon.toString() + " ]"; } } public static void main(String[] args) { solve(); writer.close(); } static BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); static StringTokenizer tokenizer = new StringTokenizer(""); static PrintWriter writer = new PrintWriter(System.out); static String next() { while (!tokenizer.hasMoreTokens()) try { tokenizer = new StringTokenizer(bf.readLine()); } catch (Exception e) { return null; } return tokenizer.nextToken(); } static int nextInt() { return Integer.parseInt(next()); } static long nextLong() { return Long.parseLong(next()); } static double nextDouble() { return Double.parseDouble(next()); } static int[] nextIntArr(int n) { int[] a = new int[n]; for (int i = 0; i < a.length; i++) { a[i] = nextInt(); } return a; } }
Title: Amr and The Large Array Time Limit: None seconds Memory Limit: None megabytes Problem Description: Amr has got a large array of size *n*. Amr doesn't like large arrays so he intends to make it smaller. Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array. Help Amr by choosing the smallest subsegment possible. Input Specification: The first line contains one number *n* (1<=≤<=*n*<=≤<=105), the size of the array. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=106), representing elements of the array. Output Specification: Output two integers *l*,<=*r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*), the beginning and the end of the subsegment chosen respectively. If there are several possible answers you may output any of them. Demo Input: ['5\n1 1 2 2 1\n', '5\n1 2 2 3 1\n', '6\n1 2 2 1 1 2\n'] Demo Output: ['1 5', '2 3', '1 5'] Note: A subsegment *B* of an array *A* from *l* to *r* is an array of size *r* - *l* + 1 where *B*<sub class="lower-index">*i*</sub> = *A*<sub class="lower-index">*l* + *i* - 1</sub> for all 1 ≤ *i* ≤ *r* - *l* + 1
```python import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.StringTokenizer; import java.util.TreeMap; public class LargeArray { static void solve() { // Counter c = new Counter(); // while(true){ // String op = next(); // int n = nextInt(); // // if(op.equals("a")) // c.add(n); // else if (op.equals("m")){ // System.out.println(c.getMostCommonCount()); // } // else if (op.equals("d")) // c.removeOne(n); // // System.out.println(c); // } int n = nextInt(); int[] a = nextIntArr(n); Counter d = new Counter(); for (int i : a) d.add(i); int b = d.getMostCommonCount(); Counter c = new Counter(); int[] res = new int[]{0, n - 1}; int r = 0; c.add(a[0]); for (int l = 0; l < n; l++) { while (r < n - 1 && c.getMostCommonCount() < b) { r++; c.add(a[r]); } // System.err.println(l + " " + r); if (c.getMostCommonCount() >= b && r - l < res[1] - res[0]) res = new int[] { l, r }; c.removeOne(a[l]); } writer.println((res[0] + 1) + " " + (res[1] + 1)); } static class Counter { Map<Integer, Integer> count = new HashMap<>(); TreeMap<Integer, HashSet<Integer>> mostCommon = new TreeMap<>(); void add(int i) { count.merge(i, 1, Integer::sum); int cur_cnt = cnt(i); if (!mostCommon.containsKey(cur_cnt)) mostCommon.put(cur_cnt, new HashSet<>()); mostCommon.get(cur_cnt).add(i); cur_cnt--; if (cur_cnt > 0) { mostCommon.get(cur_cnt).remove(i); if (mostCommon.get(cur_cnt).isEmpty()) mostCommon.remove(cur_cnt); } } void removeOne(int i) { int cur_cnt = cnt(i); mostCommon.get(cur_cnt).remove(i); if (mostCommon.get(cur_cnt).isEmpty()) mostCommon.remove(cur_cnt); cur_cnt--; if (cur_cnt >= 0) { if (!mostCommon.containsKey(cur_cnt)) mostCommon.put(cur_cnt, new HashSet<>()); mostCommon.get(cur_cnt).add(i); } count.put(i, count.get(i) - 1); if (count.get(i) == 0) count.remove(i); } int cnt(int i) { return count.getOrDefault(i, 0); } int getMostCommonCount() { return mostCommon.lastKey(); } @Override public String toString() { return "[ " + count.toString() + " | " + mostCommon.toString() + " ]"; } } public static void main(String[] args) { solve(); writer.close(); } static BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); static StringTokenizer tokenizer = new StringTokenizer(""); static PrintWriter writer = new PrintWriter(System.out); static String next() { while (!tokenizer.hasMoreTokens()) try { tokenizer = new StringTokenizer(bf.readLine()); } catch (Exception e) { return null; } return tokenizer.nextToken(); } static int nextInt() { return Integer.parseInt(next()); } static long nextLong() { return Long.parseLong(next()); } static double nextDouble() { return Double.parseDouble(next()); } static int[] nextIntArr(int n) { int[] a = new int[n]; for (int i = 0; i < a.length; i++) { a[i] = nextInt(); } return a; } } ```
-1
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 integers. He wonders, how many of those integers have not more than *k* lucky digits? Help him, write the program that solves the problem.
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,655,988,805
2,147,483,647
Python 3
OK
TESTS
34
92
0
n,k = list(map(int, input().split())) lst = input().split() cnt=0 for i in range(len(lst)): if lst[i].count('4')+lst[i].count('7')<=k: cnt+=1 print(cnt)
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 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Roma's got *n* positive integers. He wonders, how many of those integers have not more than *k* lucky digits? Help him, write the program that solves the problem. Input Specification: 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. Output Specification: In a single line print a single integer — the answer to the problem. Demo Input: ['3 4\n1 2 4\n', '3 2\n447 44 77\n'] Demo Output: ['3\n', '2\n'] Note: 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.
```python n,k = list(map(int, input().split())) lst = input().split() cnt=0 for i in range(len(lst)): if lst[i].count('4')+lst[i].count('7')<=k: cnt+=1 print(cnt) ```
3
294
A
Shaass and Oskols
PROGRAMMING
800
[ "implementation", "math" ]
null
null
Shaass has decided to hunt some birds. There are *n* horizontal electricity wires aligned parallel to each other. Wires are numbered 1 to *n* from top to bottom. On each wire there are some oskols sitting next to each other. Oskol is the name of a delicious kind of birds in Shaass's territory. Supposed there are *a**i* oskols sitting on the *i*-th wire. Sometimes Shaass shots one of the birds and the bird dies (suppose that this bird sat at the *i*-th wire). Consequently all the birds on the *i*-th wire to the left of the dead bird get scared and jump up on the wire number *i*<=-<=1, if there exists no upper wire they fly away. Also all the birds to the right of the dead bird jump down on wire number *i*<=+<=1, if there exists no such wire they fly away. Shaass has shot *m* birds. You're given the initial number of birds on each wire, tell him how many birds are sitting on each wire after the shots.
The first line of the input contains an integer *n*, (1<=≤<=*n*<=≤<=100). The next line contains a list of space-separated integers *a*1,<=*a*2,<=...,<=*a**n*, (0<=≤<=*a**i*<=≤<=100). The third line contains an integer *m*, (0<=≤<=*m*<=≤<=100). Each of the next *m* lines contains two integers *x**i* and *y**i*. The integers mean that for the *i*-th time Shaass shoot the *y**i*-th (from left) bird on the *x**i*-th wire, (1<=≤<=*x**i*<=≤<=*n*,<=1<=≤<=*y**i*). It's guaranteed there will be at least *y**i* birds on the *x**i*-th wire at that moment.
On the *i*-th line of the output print the number of birds on the *i*-th wire.
[ "5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6\n", "3\n2 4 1\n1\n2 2\n" ]
[ "0\n12\n5\n0\n16\n", "3\n0\n3\n" ]
none
500
[ { "input": "5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6", "output": "0\n12\n5\n0\n16" }, { "input": "3\n2 4 1\n1\n2 2", "output": "3\n0\n3" }, { "input": "5\n58 51 45 27 48\n5\n4 9\n5 15\n4 5\n5 8\n1 43", "output": "0\n66\n57\n7\n0" }, { "input": "10\n48 53 10 28 91 56 8...
1,649,645,711
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
26
92
0
n = int(input()) w = [int(i) for i in input().split()] for _ in range(int(input())): x, y = [int(i) for i in input().split()] if x == 1: w[x] = w[x] + w[x-1] - y elif x == n: w[x-2] = w[x-2] + y - 1 else: w[x] = w[x] + w[x-1] - y w[x-2] = w[x-2] + y - 1 w[x-1] = 0 for i in range(n): print(w[i])
Title: Shaass and Oskols Time Limit: None seconds Memory Limit: None megabytes Problem Description: Shaass has decided to hunt some birds. There are *n* horizontal electricity wires aligned parallel to each other. Wires are numbered 1 to *n* from top to bottom. On each wire there are some oskols sitting next to each other. Oskol is the name of a delicious kind of birds in Shaass's territory. Supposed there are *a**i* oskols sitting on the *i*-th wire. Sometimes Shaass shots one of the birds and the bird dies (suppose that this bird sat at the *i*-th wire). Consequently all the birds on the *i*-th wire to the left of the dead bird get scared and jump up on the wire number *i*<=-<=1, if there exists no upper wire they fly away. Also all the birds to the right of the dead bird jump down on wire number *i*<=+<=1, if there exists no such wire they fly away. Shaass has shot *m* birds. You're given the initial number of birds on each wire, tell him how many birds are sitting on each wire after the shots. Input Specification: The first line of the input contains an integer *n*, (1<=≤<=*n*<=≤<=100). The next line contains a list of space-separated integers *a*1,<=*a*2,<=...,<=*a**n*, (0<=≤<=*a**i*<=≤<=100). The third line contains an integer *m*, (0<=≤<=*m*<=≤<=100). Each of the next *m* lines contains two integers *x**i* and *y**i*. The integers mean that for the *i*-th time Shaass shoot the *y**i*-th (from left) bird on the *x**i*-th wire, (1<=≤<=*x**i*<=≤<=*n*,<=1<=≤<=*y**i*). It's guaranteed there will be at least *y**i* birds on the *x**i*-th wire at that moment. Output Specification: On the *i*-th line of the output print the number of birds on the *i*-th wire. Demo Input: ['5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6\n', '3\n2 4 1\n1\n2 2\n'] Demo Output: ['0\n12\n5\n0\n16\n', '3\n0\n3\n'] Note: none
```python n = int(input()) w = [int(i) for i in input().split()] for _ in range(int(input())): x, y = [int(i) for i in input().split()] if x == 1: w[x] = w[x] + w[x-1] - y elif x == n: w[x-2] = w[x-2] + y - 1 else: w[x] = w[x] + w[x-1] - y w[x-2] = w[x-2] + y - 1 w[x-1] = 0 for i in range(n): print(w[i]) ```
-1
439
A
Devu, the Singer and Churu, the Joker
PROGRAMMING
900
[ "greedy", "implementation" ]
null
null
Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to "All World Classical Singing Festival". Other than Devu, comedian Churu was also invited. Devu has provided organizers a list of the songs and required time for singing them. He will sing *n* songs, *i**th* song will take *t**i* minutes exactly. The Comedian, Churu will crack jokes. All his jokes are of 5 minutes exactly. People have mainly come to listen Devu. But you know that he needs rest of 10 minutes after each song. On the other hand, Churu being a very active person, doesn't need any rest. You as one of the organizers should make an optimal sсhedule for the event. For some reasons you must follow the conditions: - The duration of the event must be no more than *d* minutes; - Devu must complete all his songs; - With satisfying the two previous conditions the number of jokes cracked by Churu should be as many as possible. If it is not possible to find a way to conduct all the songs of the Devu, output -1. Otherwise find out maximum number of jokes that Churu can crack in the grand event.
The first line contains two space separated integers *n*, *d* (1<=≤<=*n*<=≤<=100; 1<=≤<=*d*<=≤<=10000). The second line contains *n* space-separated integers: *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=100).
If there is no way to conduct all the songs of Devu, output -1. Otherwise output the maximum number of jokes that Churu can crack in the grand event.
[ "3 30\n2 2 1\n", "3 20\n2 1 1\n" ]
[ "5\n", "-1\n" ]
Consider the first example. The duration of the event is 30 minutes. There could be maximum 5 jokes in the following way: - First Churu cracks a joke in 5 minutes. - Then Devu performs the first song for 2 minutes. - Then Churu cracks 2 jokes in 10 minutes. - Now Devu performs second song for 2 minutes. - Then Churu cracks 2 jokes in 10 minutes. - Now finally Devu will perform his last song in 1 minutes. Total time spent is 5 + 2 + 10 + 2 + 10 + 1 = 30 minutes. Consider the second example. There is no way of organizing Devu's all songs. Hence the answer is -1.
500
[ { "input": "3 30\n2 2 1", "output": "5" }, { "input": "3 20\n2 1 1", "output": "-1" }, { "input": "50 10000\n5 4 10 9 9 6 7 7 7 3 3 7 7 4 7 4 10 10 1 7 10 3 1 4 5 7 2 10 10 10 2 3 4 7 6 1 8 4 7 3 8 8 4 10 1 1 9 2 6 1", "output": "1943" }, { "input": "50 10000\n4 7 15 9 11 12 ...
1,594,830,344
2,147,483,647
Python 3
OK
TESTS
26
109
6,656,000
n,d=map(int, input().split()) t=list(map(int, input().split())) if (sum(t)+(n-1)*10)>d: print(-1) else: print((d-sum(t))//5)
Title: Devu, the Singer and Churu, the Joker Time Limit: None seconds Memory Limit: None megabytes Problem Description: Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to "All World Classical Singing Festival". Other than Devu, comedian Churu was also invited. Devu has provided organizers a list of the songs and required time for singing them. He will sing *n* songs, *i**th* song will take *t**i* minutes exactly. The Comedian, Churu will crack jokes. All his jokes are of 5 minutes exactly. People have mainly come to listen Devu. But you know that he needs rest of 10 minutes after each song. On the other hand, Churu being a very active person, doesn't need any rest. You as one of the organizers should make an optimal sсhedule for the event. For some reasons you must follow the conditions: - The duration of the event must be no more than *d* minutes; - Devu must complete all his songs; - With satisfying the two previous conditions the number of jokes cracked by Churu should be as many as possible. If it is not possible to find a way to conduct all the songs of the Devu, output -1. Otherwise find out maximum number of jokes that Churu can crack in the grand event. Input Specification: The first line contains two space separated integers *n*, *d* (1<=≤<=*n*<=≤<=100; 1<=≤<=*d*<=≤<=10000). The second line contains *n* space-separated integers: *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=100). Output Specification: If there is no way to conduct all the songs of Devu, output -1. Otherwise output the maximum number of jokes that Churu can crack in the grand event. Demo Input: ['3 30\n2 2 1\n', '3 20\n2 1 1\n'] Demo Output: ['5\n', '-1\n'] Note: Consider the first example. The duration of the event is 30 minutes. There could be maximum 5 jokes in the following way: - First Churu cracks a joke in 5 minutes. - Then Devu performs the first song for 2 minutes. - Then Churu cracks 2 jokes in 10 minutes. - Now Devu performs second song for 2 minutes. - Then Churu cracks 2 jokes in 10 minutes. - Now finally Devu will perform his last song in 1 minutes. Total time spent is 5 + 2 + 10 + 2 + 10 + 1 = 30 minutes. Consider the second example. There is no way of organizing Devu's all songs. Hence the answer is -1.
```python n,d=map(int, input().split()) t=list(map(int, input().split())) if (sum(t)+(n-1)*10)>d: print(-1) else: print((d-sum(t))//5) ```
3
0
none
none
none
0
[ "none" ]
null
null
Malek has recently found a treasure map. While he was looking for a treasure he found a locked door. There was a string *s* written on the door consisting of characters '(', ')' and '#'. Below there was a manual on how to open the door. After spending a long time Malek managed to decode the manual and found out that the goal is to replace each '#' with one or more ')' characters so that the final string becomes beautiful. Below there was also written that a string is called beautiful if for each *i* (1<=≤<=*i*<=≤<=|*s*|) there are no more ')' characters than '(' characters among the first *i* characters of *s* and also the total number of '(' characters is equal to the total number of ')' characters. Help Malek open the door by telling him for each '#' character how many ')' characters he must replace it with.
The first line of the input contains a string *s* (1<=≤<=|*s*|<=≤<=105). Each character of this string is one of the characters '(', ')' or '#'. It is guaranteed that *s* contains at least one '#' character.
If there is no way of replacing '#' characters which leads to a beautiful string print <=-<=1. Otherwise for each character '#' print a separate line containing a positive integer, the number of ')' characters this character must be replaced with. If there are several possible answers, you may output any of them.
[ "(((#)((#)\n", "()((#((#(#()\n", "#\n", "(#)\n" ]
[ "1\n2\n", "2\n2\n1", "-1\n", "-1\n" ]
|*s*| denotes the length of the string *s*.
0
[ { "input": "(((#)((#)", "output": "1\n2" }, { "input": "()((#((#(#()", "output": "1\n1\n3" }, { "input": "#", "output": "-1" }, { "input": "(#)", "output": "-1" }, { "input": "(((((#(#(#(#()", "output": "1\n1\n1\n5" }, { "input": "#))))", "output":...
1,677,456,354
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
9
93
204,800
x=input() c=False j=0 g=0 f=[] p=True le=len(x) while g<le: i=x[g] if i=="(": j+=1 elif i==")": j-=1 if j<0: p=False if i=="#": if j<=0: p=False break g+=1 while g<le and x[g]==")": j-=1 if j <= 0: p = False g+=1 else: g-=1 f+=[j] j=0 g += 1 #hفرق واحد if p: print(*f,sep="\n") else: print(-1)
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Malek has recently found a treasure map. While he was looking for a treasure he found a locked door. There was a string *s* written on the door consisting of characters '(', ')' and '#'. Below there was a manual on how to open the door. After spending a long time Malek managed to decode the manual and found out that the goal is to replace each '#' with one or more ')' characters so that the final string becomes beautiful. Below there was also written that a string is called beautiful if for each *i* (1<=≤<=*i*<=≤<=|*s*|) there are no more ')' characters than '(' characters among the first *i* characters of *s* and also the total number of '(' characters is equal to the total number of ')' characters. Help Malek open the door by telling him for each '#' character how many ')' characters he must replace it with. Input Specification: The first line of the input contains a string *s* (1<=≤<=|*s*|<=≤<=105). Each character of this string is one of the characters '(', ')' or '#'. It is guaranteed that *s* contains at least one '#' character. Output Specification: If there is no way of replacing '#' characters which leads to a beautiful string print <=-<=1. Otherwise for each character '#' print a separate line containing a positive integer, the number of ')' characters this character must be replaced with. If there are several possible answers, you may output any of them. Demo Input: ['(((#)((#)\n', '()((#((#(#()\n', '#\n', '(#)\n'] Demo Output: ['1\n2\n', '2\n2\n1', '-1\n', '-1\n'] Note: |*s*| denotes the length of the string *s*.
```python x=input() c=False j=0 g=0 f=[] p=True le=len(x) while g<le: i=x[g] if i=="(": j+=1 elif i==")": j-=1 if j<0: p=False if i=="#": if j<=0: p=False break g+=1 while g<le and x[g]==")": j-=1 if j <= 0: p = False g+=1 else: g-=1 f+=[j] j=0 g += 1 #hفرق واحد if p: print(*f,sep="\n") else: print(-1) ```
0
721
A
One-dimensional Japanese Crossword
PROGRAMMING
800
[ "implementation" ]
null
null
Recently Adaltik discovered japanese crosswords. Japanese crossword is a picture, represented as a table sized *a*<=×<=*b* squares, and each square is colored white or black. There are integers to the left of the rows and to the top of the columns, encrypting the corresponding row or column. The number of integers represents how many groups of black squares there are in corresponding row or column, and the integers themselves represents the number of consecutive black squares in corresponding group (you can find more detailed explanation in Wikipedia [https://en.wikipedia.org/wiki/Japanese_crossword](https://en.wikipedia.org/wiki/Japanese_crossword)). Adaltik decided that the general case of japanese crossword is too complicated and drew a row consisting of *n* squares (e.g. japanese crossword sized 1<=×<=*n*), which he wants to encrypt in the same way as in japanese crossword. Help Adaltik find the numbers encrypting the row he drew.
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the length of the row. The second line of the input contains a single string consisting of *n* characters 'B' or 'W', ('B' corresponds to black square, 'W' — to white square in the row that Adaltik drew).
The first line should contain a single integer *k* — the number of integers encrypting the row, e.g. the number of groups of black squares in the row. The second line should contain *k* integers, encrypting the row, e.g. corresponding to sizes of groups of consecutive black squares in the order from left to right.
[ "3\nBBW\n", "5\nBWBWB\n", "4\nWWWW\n", "4\nBBBB\n", "13\nWBBBBWWBWBBBW\n" ]
[ "1\n2 ", "3\n1 1 1 ", "0\n", "1\n4 ", "3\n4 1 3 " ]
The last sample case correspond to the picture in the statement.
500
[ { "input": "3\nBBW", "output": "1\n2 " }, { "input": "5\nBWBWB", "output": "3\n1 1 1 " }, { "input": "4\nWWWW", "output": "0" }, { "input": "4\nBBBB", "output": "1\n4 " }, { "input": "13\nWBBBBWWBWBBBW", "output": "3\n4 1 3 " }, { "input": "1\nB", ...
1,580,379,355
2,147,483,647
Python 3
OK
TESTS
54
124
0
n=int(input()) stri=input().split("W") count=0 listy=[] for i in stri: if "B" in i: count+=1 j=(len(i)) listy.append(j) print(count) for i in listy: print(i,end=" ")
Title: One-dimensional Japanese Crossword Time Limit: None seconds Memory Limit: None megabytes Problem Description: Recently Adaltik discovered japanese crosswords. Japanese crossword is a picture, represented as a table sized *a*<=×<=*b* squares, and each square is colored white or black. There are integers to the left of the rows and to the top of the columns, encrypting the corresponding row or column. The number of integers represents how many groups of black squares there are in corresponding row or column, and the integers themselves represents the number of consecutive black squares in corresponding group (you can find more detailed explanation in Wikipedia [https://en.wikipedia.org/wiki/Japanese_crossword](https://en.wikipedia.org/wiki/Japanese_crossword)). Adaltik decided that the general case of japanese crossword is too complicated and drew a row consisting of *n* squares (e.g. japanese crossword sized 1<=×<=*n*), which he wants to encrypt in the same way as in japanese crossword. Help Adaltik find the numbers encrypting the row he drew. Input Specification: The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the length of the row. The second line of the input contains a single string consisting of *n* characters 'B' or 'W', ('B' corresponds to black square, 'W' — to white square in the row that Adaltik drew). Output Specification: The first line should contain a single integer *k* — the number of integers encrypting the row, e.g. the number of groups of black squares in the row. The second line should contain *k* integers, encrypting the row, e.g. corresponding to sizes of groups of consecutive black squares in the order from left to right. Demo Input: ['3\nBBW\n', '5\nBWBWB\n', '4\nWWWW\n', '4\nBBBB\n', '13\nWBBBBWWBWBBBW\n'] Demo Output: ['1\n2 ', '3\n1 1 1 ', '0\n', '1\n4 ', '3\n4 1 3 '] Note: The last sample case correspond to the picture in the statement.
```python n=int(input()) stri=input().split("W") count=0 listy=[] for i in stri: if "B" in i: count+=1 j=(len(i)) listy.append(j) print(count) for i in listy: print(i,end=" ") ```
3
59
A
Word
PROGRAMMING
800
[ "implementation", "strings" ]
A. Word
2
256
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word.
The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
[ "HoUse\n", "ViP\n", "maTRIx\n" ]
[ "house\n", "VIP\n", "matrix\n" ]
none
500
[ { "input": "HoUse", "output": "house" }, { "input": "ViP", "output": "VIP" }, { "input": "maTRIx", "output": "matrix" }, { "input": "BNHWpnpawg", "output": "bnhwpnpawg" }, { "input": "VTYGP", "output": "VTYGP" }, { "input": "CHNenu", "output": "chn...
1,621,341,989
2,147,483,647
PyPy 3
OK
TESTS
30
218
0
from sys import stdin, stdout def readline(): return stdin.readline().rstrip() def readint(): return int(readline()) def readints(): return [int(x) for x in readline().split()] def writeline(s): stdout.write(str(s)+"\n") s = readline() upp = sum(c.isupper() for c in s) low = len(s) - upp writeline(s.upper() if upp > low else s.lower())
Title: Word Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word. Input Specification: The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. Output Specification: Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. Demo Input: ['HoUse\n', 'ViP\n', 'maTRIx\n'] Demo Output: ['house\n', 'VIP\n', 'matrix\n'] Note: none
```python from sys import stdin, stdout def readline(): return stdin.readline().rstrip() def readint(): return int(readline()) def readints(): return [int(x) for x in readline().split()] def writeline(s): stdout.write(str(s)+"\n") s = readline() upp = sum(c.isupper() for c in s) low = len(s) - upp writeline(s.upper() if upp > low else s.lower()) ```
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 crystals, green — one yellow and one blue, and for a blue ball, three blue crystals are enough. Right now there are *A* yellow and *B* blue crystals in Grisha's disposal. Find out how many additional crystals he should acquire in order to produce the required number of balls.
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,689,895,102
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
2
77
0
a,b=map(int,input().split()) c,d,e=map(int,input().split()) '''a=yellow cryst b=blue cryst c=yellow ball needed d=green ball needed e=blue ball needed''' f=2*c if f>a: g=f-a else: g=0 h=3*e if h>b: i=h-b else: i=0 Bad_VaRiaB1E_N4m3_12345678_9876_543_21=f+d-a if f+d>a: g=g+Bad_VaRiaB1E_N4m3_12345678_9876_543_21 j=h+d-b if h+d>b: i=i+j print(g+i)
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 obtain some yellow, green and blue balls. It's known that to produce a yellow ball one needs two yellow crystals, green — one yellow and one blue, and for a blue ball, three blue crystals are enough. Right now there are *A* yellow and *B* blue crystals in Grisha's disposal. Find out how many additional crystals he should acquire in order to produce the required number of balls. Input Specification: 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. Output Specification: Print a single integer — the minimum number of crystals that Grisha should acquire in addition. Demo Input: ['4 3\n2 1 1\n', '3 9\n1 1 3\n', '12345678 87654321\n43043751 1000000000 53798715\n'] Demo Output: ['2\n', '1\n', '2147483648\n'] Note: 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.
```python a,b=map(int,input().split()) c,d,e=map(int,input().split()) '''a=yellow cryst b=blue cryst c=yellow ball needed d=green ball needed e=blue ball needed''' f=2*c if f>a: g=f-a else: g=0 h=3*e if h>b: i=h-b else: i=0 Bad_VaRiaB1E_N4m3_12345678_9876_543_21=f+d-a if f+d>a: g=g+Bad_VaRiaB1E_N4m3_12345678_9876_543_21 j=h+d-b if h+d>b: i=i+j print(g+i) ```
0
858
B
Which floor?
PROGRAMMING
1,500
[ "brute force", "implementation" ]
null
null
In a building where Polycarp lives there are equal number of flats on each floor. Unfortunately, Polycarp don't remember how many flats are on each floor, but he remembers that the flats are numbered from 1 from lower to upper floors. That is, the first several flats are on the first floor, the next several flats are on the second and so on. Polycarp don't remember the total number of flats in the building, so you can consider the building to be infinitely high (i.e. there are infinitely many floors). Note that the floors are numbered from 1. Polycarp remembers on which floors several flats are located. It is guaranteed that this information is not self-contradictory. It means that there exists a building with equal number of flats on each floor so that the flats from Polycarp's memory have the floors Polycarp remembers. Given this information, is it possible to restore the exact floor for flat *n*?
The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100, 0<=≤<=*m*<=≤<=100), where *n* is the number of the flat you need to restore floor for, and *m* is the number of flats in Polycarp's memory. *m* lines follow, describing the Polycarp's memory: each of these lines contains a pair of integers *k**i*,<=*f**i* (1<=≤<=*k**i*<=≤<=100, 1<=≤<=*f**i*<=≤<=100), which means that the flat *k**i* is on the *f**i*-th floor. All values *k**i* are distinct. It is guaranteed that the given information is not self-contradictory.
Print the number of the floor in which the *n*-th flat is located, if it is possible to determine it in a unique way. Print -1 if it is not possible to uniquely restore this floor.
[ "10 3\n6 2\n2 1\n7 3\n", "8 4\n3 1\n6 2\n5 2\n2 1\n" ]
[ "4\n", "-1\n" ]
In the first example the 6-th flat is on the 2-nd floor, while the 7-th flat is on the 3-rd, so, the 6-th flat is the last on its floor and there are 3 flats on each floor. Thus, the 10-th flat is on the 4-th floor. In the second example there can be 3 or 4 flats on each floor, so we can't restore the floor for the 8-th flat.
750
[ { "input": "10 3\n6 2\n2 1\n7 3", "output": "4" }, { "input": "8 4\n3 1\n6 2\n5 2\n2 1", "output": "-1" }, { "input": "8 3\n7 2\n6 2\n1 1", "output": "2" }, { "input": "4 2\n8 3\n3 1", "output": "2" }, { "input": "11 4\n16 4\n11 3\n10 3\n15 4", "output": "3" ...
1,682,451,062
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
2
62
0
import sys input = lambda: sys.stdin.readline().rstrip() from collections import defaultdict N,M = map(int, input().split()) A = [] for _ in range(M): A.append(tuple(map(int, input().split()))) steps = [] for i in range(1,101): ok = True for a,l in A: if (a-1)//i+1!=l: ok = False break if ok: steps.append(i) if len(steps)!=1: exit(print(-1)) print((N-1)//steps[0]+1)
Title: Which floor? Time Limit: None seconds Memory Limit: None megabytes Problem Description: In a building where Polycarp lives there are equal number of flats on each floor. Unfortunately, Polycarp don't remember how many flats are on each floor, but he remembers that the flats are numbered from 1 from lower to upper floors. That is, the first several flats are on the first floor, the next several flats are on the second and so on. Polycarp don't remember the total number of flats in the building, so you can consider the building to be infinitely high (i.e. there are infinitely many floors). Note that the floors are numbered from 1. Polycarp remembers on which floors several flats are located. It is guaranteed that this information is not self-contradictory. It means that there exists a building with equal number of flats on each floor so that the flats from Polycarp's memory have the floors Polycarp remembers. Given this information, is it possible to restore the exact floor for flat *n*? Input Specification: The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100, 0<=≤<=*m*<=≤<=100), where *n* is the number of the flat you need to restore floor for, and *m* is the number of flats in Polycarp's memory. *m* lines follow, describing the Polycarp's memory: each of these lines contains a pair of integers *k**i*,<=*f**i* (1<=≤<=*k**i*<=≤<=100, 1<=≤<=*f**i*<=≤<=100), which means that the flat *k**i* is on the *f**i*-th floor. All values *k**i* are distinct. It is guaranteed that the given information is not self-contradictory. Output Specification: Print the number of the floor in which the *n*-th flat is located, if it is possible to determine it in a unique way. Print -1 if it is not possible to uniquely restore this floor. Demo Input: ['10 3\n6 2\n2 1\n7 3\n', '8 4\n3 1\n6 2\n5 2\n2 1\n'] Demo Output: ['4\n', '-1\n'] Note: In the first example the 6-th flat is on the 2-nd floor, while the 7-th flat is on the 3-rd, so, the 6-th flat is the last on its floor and there are 3 flats on each floor. Thus, the 10-th flat is on the 4-th floor. In the second example there can be 3 or 4 flats on each floor, so we can't restore the floor for the 8-th flat.
```python import sys input = lambda: sys.stdin.readline().rstrip() from collections import defaultdict N,M = map(int, input().split()) A = [] for _ in range(M): A.append(tuple(map(int, input().split()))) steps = [] for i in range(1,101): ok = True for a,l in A: if (a-1)//i+1!=l: ok = False break if ok: steps.append(i) if len(steps)!=1: exit(print(-1)) print((N-1)//steps[0]+1) ```
0
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 calculations faster than him. As a result he made a very great contest and asked every one to come and take part. In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0. Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length. Now you are going to take part in Shapur's contest. See if you are faster and more accurate.
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,480,779,433
2,147,483,647
Python 3
OK
TESTS
102
77
0
while True: try: n=input() l=input() s='' for i in range(len(n)): if n[i]==l[i]: s=s+'0' else: s=s+'1' print(s) except EOFError: break
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 1018 numbers in a single second. One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part. In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0. Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length. Now you are going to take part in Shapur's contest. See if you are faster and more accurate. Input Specification: 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. Output Specification: Write one line — the corresponding answer. Do not omit the leading 0s. Demo Input: ['1010100\n0100101\n', '000\n111\n', '1110\n1010\n', '01110\n01100\n'] Demo Output: ['1110001\n', '111\n', '0100\n', '00010\n'] Note: none
```python while True: try: n=input() l=input() s='' for i in range(len(n)): if n[i]==l[i]: s=s+'0' else: s=s+'1' print(s) except EOFError: break ```
3.98075
691
A
Fashion in Berland
PROGRAMMING
1,000
[ "implementation" ]
null
null
According to rules of the Berland fashion, a jacket should be fastened by all the buttons except only one, but not necessarily it should be the last one. Also if the jacket has only one button, it should be fastened, so the jacket will not swinging open. You are given a jacket with *n* buttons. Determine if it is fastened in a right way.
The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of buttons on the jacket. The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=1). The number *a**i*<==<=0 if the *i*-th button is not fastened. Otherwise *a**i*<==<=1.
In the only line print the word "YES" if the jacket is fastened in a right way. Otherwise print the word "NO".
[ "3\n1 0 1\n", "3\n1 0 0\n" ]
[ "YES\n", "NO\n" ]
none
0
[ { "input": "3\n1 0 1", "output": "YES" }, { "input": "3\n1 0 0", "output": "NO" }, { "input": "3\n1 1 0", "output": "YES" }, { "input": "3\n1 1 1", "output": "NO" }, { "input": "3\n0 0 1", "output": "NO" }, { "input": "3\n0 0 0", "output": "NO" }...
1,537,276,886
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
108
0
n=int(input()) if n==1: str=int(input()) if str==1: print("YES") else: print("NO") else: str = list(map(int, input().split())) count=0 flag=True for i in range (n): if str[i]==0: count+=1 if count==2: print("NO") break else: print("YES")
Title: Fashion in Berland Time Limit: None seconds Memory Limit: None megabytes Problem Description: According to rules of the Berland fashion, a jacket should be fastened by all the buttons except only one, but not necessarily it should be the last one. Also if the jacket has only one button, it should be fastened, so the jacket will not swinging open. You are given a jacket with *n* buttons. Determine if it is fastened in a right way. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of buttons on the jacket. The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=1). The number *a**i*<==<=0 if the *i*-th button is not fastened. Otherwise *a**i*<==<=1. Output Specification: In the only line print the word "YES" if the jacket is fastened in a right way. Otherwise print the word "NO". Demo Input: ['3\n1 0 1\n', '3\n1 0 0\n'] Demo Output: ['YES\n', 'NO\n'] Note: none
```python n=int(input()) if n==1: str=int(input()) if str==1: print("YES") else: print("NO") else: str = list(map(int, input().split())) count=0 flag=True for i in range (n): if str[i]==0: count+=1 if count==2: print("NO") break else: print("YES") ```
0
372
B
Counting Rectangles is Fun
PROGRAMMING
1,900
[ "brute force", "divide and conquer", "dp" ]
null
null
There is an *n*<=×<=*m* rectangular grid, each cell of the grid contains a single integer: zero or one. Let's call the cell on the *i*-th row and the *j*-th column as (*i*,<=*j*). Let's define a "rectangle" as four integers *a*,<=*b*,<=*c*,<=*d* (1<=≤<=*a*<=≤<=*c*<=≤<=*n*; 1<=≤<=*b*<=≤<=*d*<=≤<=*m*). Rectangle denotes a set of cells of the grid {(*x*,<=*y*) :<= *a*<=≤<=*x*<=≤<=*c*,<=*b*<=≤<=*y*<=≤<=*d*}. Let's define a "good rectangle" as a rectangle that includes only the cells with zeros. You should answer the following *q* queries: calculate the number of good rectangles all of which cells are in the given rectangle.
There are three integers in the first line: *n*, *m* and *q* (1<=≤<=*n*,<=*m*<=≤<=40,<=1<=≤<=*q*<=≤<=3·105). Each of the next *n* lines contains *m* characters — the grid. Consider grid rows are numbered from top to bottom, and grid columns are numbered from left to right. Both columns and rows are numbered starting from 1. Each of the next *q* lines contains a query — four integers that describe the current rectangle, *a*, *b*, *c*, *d* (1<=≤<=*a*<=≤<=*c*<=≤<=*n*; 1<=≤<=*b*<=≤<=*d*<=≤<=*m*).
For each query output an answer — a single integer in a separate line.
[ "5 5 5\n00101\n00000\n00001\n01000\n00001\n1 2 2 4\n4 5 4 5\n1 2 5 2\n2 2 4 5\n4 2 5 3\n", "4 7 5\n0000100\n0000010\n0011000\n0000000\n1 7 2 7\n3 1 3 1\n2 3 4 5\n1 2 2 7\n2 2 4 7\n" ]
[ "10\n1\n7\n34\n5\n", "3\n1\n16\n27\n52\n" ]
For the first example, there is a 5 × 5 rectangular grid, and the first, the second, and the third queries are represented in the following image. - For the first query, there are 10 good rectangles, five 1 × 1, two 2 × 1, two 1 × 2, and one 1 × 3. - For the second query, there is only one 1 × 1 good rectangle. - For the third query, there are 7 good rectangles, four 1 × 1, two 2 × 1, and one 3 × 1.
1,000
[ { "input": "5 5 5\n00101\n00000\n00001\n01000\n00001\n1 2 2 4\n4 5 4 5\n1 2 5 2\n2 2 4 5\n4 2 5 3", "output": "10\n1\n7\n34\n5" }, { "input": "4 7 5\n0000100\n0000010\n0011000\n0000000\n1 7 2 7\n3 1 3 1\n2 3 4 5\n1 2 2 7\n2 2 4 7", "output": "3\n1\n16\n27\n52" }, { "input": "10 10 10\n00...
1,691,001,497
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
46
0
print("_RANDOM_GUESS_1691001497.5278904")# 1691001497.5279078
Title: Counting Rectangles is Fun Time Limit: None seconds Memory Limit: None megabytes Problem Description: There is an *n*<=×<=*m* rectangular grid, each cell of the grid contains a single integer: zero or one. Let's call the cell on the *i*-th row and the *j*-th column as (*i*,<=*j*). Let's define a "rectangle" as four integers *a*,<=*b*,<=*c*,<=*d* (1<=≤<=*a*<=≤<=*c*<=≤<=*n*; 1<=≤<=*b*<=≤<=*d*<=≤<=*m*). Rectangle denotes a set of cells of the grid {(*x*,<=*y*) :<= *a*<=≤<=*x*<=≤<=*c*,<=*b*<=≤<=*y*<=≤<=*d*}. Let's define a "good rectangle" as a rectangle that includes only the cells with zeros. You should answer the following *q* queries: calculate the number of good rectangles all of which cells are in the given rectangle. Input Specification: There are three integers in the first line: *n*, *m* and *q* (1<=≤<=*n*,<=*m*<=≤<=40,<=1<=≤<=*q*<=≤<=3·105). Each of the next *n* lines contains *m* characters — the grid. Consider grid rows are numbered from top to bottom, and grid columns are numbered from left to right. Both columns and rows are numbered starting from 1. Each of the next *q* lines contains a query — four integers that describe the current rectangle, *a*, *b*, *c*, *d* (1<=≤<=*a*<=≤<=*c*<=≤<=*n*; 1<=≤<=*b*<=≤<=*d*<=≤<=*m*). Output Specification: For each query output an answer — a single integer in a separate line. Demo Input: ['5 5 5\n00101\n00000\n00001\n01000\n00001\n1 2 2 4\n4 5 4 5\n1 2 5 2\n2 2 4 5\n4 2 5 3\n', '4 7 5\n0000100\n0000010\n0011000\n0000000\n1 7 2 7\n3 1 3 1\n2 3 4 5\n1 2 2 7\n2 2 4 7\n'] Demo Output: ['10\n1\n7\n34\n5\n', '3\n1\n16\n27\n52\n'] Note: For the first example, there is a 5 × 5 rectangular grid, and the first, the second, and the third queries are represented in the following image. - For the first query, there are 10 good rectangles, five 1 × 1, two 2 × 1, two 1 × 2, and one 1 × 3. - For the second query, there is only one 1 × 1 good rectangle. - For the third query, there are 7 good rectangles, four 1 × 1, two 2 × 1, and one 3 × 1.
```python print("_RANDOM_GUESS_1691001497.5278904")# 1691001497.5279078 ```
0
0
none
none
none
0
[ "none" ]
null
null
In Absurdistan, there are *n* towns (numbered 1 through *n*) and *m* bidirectional railways. There is also an absurdly simple road network — for each pair of different towns *x* and *y*, there is a bidirectional road between towns *x* and *y* if and only if there is no railway between them. Travelling to a different town using one railway or one road always takes exactly one hour. A train and a bus leave town 1 at the same time. They both have the same destination, town *n*, and don't make any stops on the way (but they can wait in town *n*). The train can move only along railways and the bus can move only along roads. You've been asked to plan out routes for the vehicles; each route can use any road/railway multiple times. One of the most important aspects to consider is safety — in order to avoid accidents at railway crossings, the train and the bus must not arrive at the same town (except town *n*) simultaneously. Under these constraints, what is the minimum number of hours needed for both vehicles to reach town *n* (the maximum of arrival times of the bus and the train)? Note, that bus and train are not required to arrive to the town *n* at the same moment of time, but are allowed to do so.
The first line of the input contains two integers *n* and *m* (2<=≤<=*n*<=≤<=400, 0<=≤<=*m*<=≤<=*n*(*n*<=-<=1)<=/<=2) — the number of towns and the number of railways respectively. Each of the next *m* lines contains two integers *u* and *v*, denoting a railway between towns *u* and *v* (1<=≤<=*u*,<=*v*<=≤<=*n*, *u*<=≠<=*v*). You may assume that there is at most one railway connecting any two towns.
Output one integer — the smallest possible time of the later vehicle's arrival in town *n*. If it's impossible for at least one of the vehicles to reach town *n*, output <=-<=1.
[ "4 2\n1 3\n3 4\n", "4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4\n", "5 5\n4 2\n3 5\n4 5\n5 1\n1 2\n" ]
[ "2\n", "-1\n", "3\n" ]
In the first sample, the train can take the route <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7c0aa60a06309ef607b7159fd7f3687ea0d943ce.png" style="max-width: 100.0%;max-height: 100.0%;"/> and the bus can take the route <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/a26c2f3e93c9d9be6c21cb5d2bd6ac1f99f4ff55.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Note that they can arrive at town 4 at the same time. In the second sample, Absurdistan is ruled by railwaymen. There are no roads, so there's no way for the bus to reach town 4.
0
[ { "input": "4 2\n1 3\n3 4", "output": "2" }, { "input": "4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4", "output": "-1" }, { "input": "5 5\n4 2\n3 5\n4 5\n5 1\n1 2", "output": "3" }, { "input": "5 4\n1 2\n3 2\n3 4\n5 4", "output": "4" }, { "input": "3 1\n1 2", "output": "...
1,613,697,929
2,147,483,647
Python 3
OK
TESTS
59
296
3,686,400
n, m = map(int, input().split()) g1, g2 = {}, {} e = [[False for i in range(n)] for j in range(n)] level = [-1]*n def bfs(t, u): queue = [u] level[u] = 0 while len(queue) != 0: u = queue.pop(0) if u == n-1: return level[u] if t == 1: for v in g1[u]: if level[v] == -1: level[v] = level[u]+1 queue.append(v) elif t == 2: for v in g2[u]: if level[v] == -1: level[v] = level[u]+1 queue.append(v) return -1 if __name__ == "__main__": for i in range(n): g1[i] = [] g2[i] = [] while m: a, b = map(int, input().split()) a -= 1 b -= 1 g1[a].append(b) g1[b].append(a) e[a][b] = True e[b][a] = True m -= 1 for i in range(n): for j in range(i+1, n): if not e[i][j]: g2[i].append(j) g2[j].append(i) if e[0][n-1]: print(bfs(2, 0)) else: print(bfs(1, 0))
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: In Absurdistan, there are *n* towns (numbered 1 through *n*) and *m* bidirectional railways. There is also an absurdly simple road network — for each pair of different towns *x* and *y*, there is a bidirectional road between towns *x* and *y* if and only if there is no railway between them. Travelling to a different town using one railway or one road always takes exactly one hour. A train and a bus leave town 1 at the same time. They both have the same destination, town *n*, and don't make any stops on the way (but they can wait in town *n*). The train can move only along railways and the bus can move only along roads. You've been asked to plan out routes for the vehicles; each route can use any road/railway multiple times. One of the most important aspects to consider is safety — in order to avoid accidents at railway crossings, the train and the bus must not arrive at the same town (except town *n*) simultaneously. Under these constraints, what is the minimum number of hours needed for both vehicles to reach town *n* (the maximum of arrival times of the bus and the train)? Note, that bus and train are not required to arrive to the town *n* at the same moment of time, but are allowed to do so. Input Specification: The first line of the input contains two integers *n* and *m* (2<=≤<=*n*<=≤<=400, 0<=≤<=*m*<=≤<=*n*(*n*<=-<=1)<=/<=2) — the number of towns and the number of railways respectively. Each of the next *m* lines contains two integers *u* and *v*, denoting a railway between towns *u* and *v* (1<=≤<=*u*,<=*v*<=≤<=*n*, *u*<=≠<=*v*). You may assume that there is at most one railway connecting any two towns. Output Specification: Output one integer — the smallest possible time of the later vehicle's arrival in town *n*. If it's impossible for at least one of the vehicles to reach town *n*, output <=-<=1. Demo Input: ['4 2\n1 3\n3 4\n', '4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4\n', '5 5\n4 2\n3 5\n4 5\n5 1\n1 2\n'] Demo Output: ['2\n', '-1\n', '3\n'] Note: In the first sample, the train can take the route <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7c0aa60a06309ef607b7159fd7f3687ea0d943ce.png" style="max-width: 100.0%;max-height: 100.0%;"/> and the bus can take the route <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/a26c2f3e93c9d9be6c21cb5d2bd6ac1f99f4ff55.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Note that they can arrive at town 4 at the same time. In the second sample, Absurdistan is ruled by railwaymen. There are no roads, so there's no way for the bus to reach town 4.
```python n, m = map(int, input().split()) g1, g2 = {}, {} e = [[False for i in range(n)] for j in range(n)] level = [-1]*n def bfs(t, u): queue = [u] level[u] = 0 while len(queue) != 0: u = queue.pop(0) if u == n-1: return level[u] if t == 1: for v in g1[u]: if level[v] == -1: level[v] = level[u]+1 queue.append(v) elif t == 2: for v in g2[u]: if level[v] == -1: level[v] = level[u]+1 queue.append(v) return -1 if __name__ == "__main__": for i in range(n): g1[i] = [] g2[i] = [] while m: a, b = map(int, input().split()) a -= 1 b -= 1 g1[a].append(b) g1[b].append(a) e[a][b] = True e[b][a] = True m -= 1 for i in range(n): for j in range(i+1, n): if not e[i][j]: g2[i].append(j) g2[j].append(i) if e[0][n-1]: print(bfs(2, 0)) else: print(bfs(1, 0)) ```
3
615
A
Bulbs
PROGRAMMING
800
[ "implementation" ]
null
null
Vasya wants to turn on Christmas lights consisting of *m* bulbs. Initially, all bulbs are turned off. There are *n* buttons, each of them is connected to some set of bulbs. Vasya can press any of these buttons. When the button is pressed, it turns on all the bulbs it's connected to. Can Vasya light up all the bulbs? If Vasya presses the button such that some bulbs connected to it are already turned on, they do not change their state, i.e. remain turned on.
The first line of the input contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of buttons and the number of bulbs respectively. Each of the next *n* lines contains *x**i* (0<=≤<=*x**i*<=≤<=*m*) — the number of bulbs that are turned on by the *i*-th button, and then *x**i* numbers *y**ij* (1<=≤<=*y**ij*<=≤<=*m*) — the numbers of these bulbs.
If it's possible to turn on all *m* bulbs print "YES", otherwise print "NO".
[ "3 4\n2 1 4\n3 1 3 1\n1 2\n", "3 3\n1 1\n1 2\n1 1\n" ]
[ "YES\n", "NO\n" ]
In the first sample you can press each button once and turn on all the bulbs. In the 2 sample it is impossible to turn on the 3-rd lamp.
500
[ { "input": "3 4\n2 1 4\n3 1 3 1\n1 2", "output": "YES" }, { "input": "3 3\n1 1\n1 2\n1 1", "output": "NO" }, { "input": "3 4\n1 1\n1 2\n1 3", "output": "NO" }, { "input": "1 5\n5 1 2 3 4 5", "output": "YES" }, { "input": "1 5\n5 4 4 1 2 3", "output": "NO" },...
1,604,602,096
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
7
93
307,200
n,m=map(int,input().split()) sett=set() for i in range(m): sett.add(i+1) for j in range(n): bulbs=input() first_space=bulbs.find(" ") howmanyconnected=int(bulbs[0:first_space]) bulbs=bulbs[first_space+1:] for k in range(howmanyconnected): if " " in bulbs: next_space=bulbs.find(" ") what_bulb=int(bulbs[0:next_space]) if what_bulb in sett: sett.remove(what_bulb) bulbs=bulbs[next_space+1:] else: what_bulb=int(bulbs) if what_bulb in sett: sett.remove(what_bulb) if sett==set(): print ('YES') else: print ('NO')
Title: Bulbs Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya wants to turn on Christmas lights consisting of *m* bulbs. Initially, all bulbs are turned off. There are *n* buttons, each of them is connected to some set of bulbs. Vasya can press any of these buttons. When the button is pressed, it turns on all the bulbs it's connected to. Can Vasya light up all the bulbs? If Vasya presses the button such that some bulbs connected to it are already turned on, they do not change their state, i.e. remain turned on. Input Specification: The first line of the input contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of buttons and the number of bulbs respectively. Each of the next *n* lines contains *x**i* (0<=≤<=*x**i*<=≤<=*m*) — the number of bulbs that are turned on by the *i*-th button, and then *x**i* numbers *y**ij* (1<=≤<=*y**ij*<=≤<=*m*) — the numbers of these bulbs. Output Specification: If it's possible to turn on all *m* bulbs print "YES", otherwise print "NO". Demo Input: ['3 4\n2 1 4\n3 1 3 1\n1 2\n', '3 3\n1 1\n1 2\n1 1\n'] Demo Output: ['YES\n', 'NO\n'] Note: In the first sample you can press each button once and turn on all the bulbs. In the 2 sample it is impossible to turn on the 3-rd lamp.
```python n,m=map(int,input().split()) sett=set() for i in range(m): sett.add(i+1) for j in range(n): bulbs=input() first_space=bulbs.find(" ") howmanyconnected=int(bulbs[0:first_space]) bulbs=bulbs[first_space+1:] for k in range(howmanyconnected): if " " in bulbs: next_space=bulbs.find(" ") what_bulb=int(bulbs[0:next_space]) if what_bulb in sett: sett.remove(what_bulb) bulbs=bulbs[next_space+1:] else: what_bulb=int(bulbs) if what_bulb in sett: sett.remove(what_bulb) if sett==set(): print ('YES') else: print ('NO') ```
-1
609
B
The Best Gift
PROGRAMMING
1,100
[ "constructive algorithms", "implementation" ]
null
null
Emily's birthday is next week and Jack has decided to buy a present for her. He knows she loves books so he goes to the local bookshop, where there are *n* books on sale from one of *m* genres. In the bookshop, Jack decides to buy two books of different genres. Based on the genre of books on sale in the shop, find the number of options available to Jack for choosing two books of different genres for Emily. Options are considered different if they differ in at least one book. The books are given by indices of their genres. The genres are numbered from 1 to *m*.
The first line contains two positive integers *n* and *m* (2<=≤<=*n*<=≤<=2·105,<=2<=≤<=*m*<=≤<=10) — the number of books in the bookstore and the number of genres. The second line contains a sequence *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* (1<=≤<=*a**i*<=≤<=*m*) equals the genre of the *i*-th book. It is guaranteed that for each genre there is at least one book of that genre.
Print the only integer — the number of ways in which Jack can choose books. It is guaranteed that the answer doesn't exceed the value 2·109.
[ "4 3\n2 1 3 1\n", "7 4\n4 2 3 1 2 4 3\n" ]
[ "5\n", "18\n" ]
The answer to the first test sample equals 5 as Sasha can choose: 1. the first and second books, 1. the first and third books, 1. the first and fourth books, 1. the second and third books, 1. the third and fourth books.
0
[ { "input": "4 3\n2 1 3 1", "output": "5" }, { "input": "7 4\n4 2 3 1 2 4 3", "output": "18" }, { "input": "2 2\n1 2", "output": "1" }, { "input": "3 2\n1 2 2", "output": "2" }, { "input": "10 10\n1 2 3 4 5 6 7 8 9 10", "output": "45" }, { "input": "9 2...
1,560,425,035
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
93
0
n,m=list(map(int,input().split())) A=list(map(int,input().split())) count = 0 D={} for val in A: if val not in D: D[val]=[count] else: D[val].append(count) count += 1 Ans = 0 for val,N in zip(A,range(1,len(A)+1)): c=0 for k in D[val]: if k > N: c += 1 Ans += n-c-N #print(Ans,c,N) print(Ans)
Title: The Best Gift Time Limit: None seconds Memory Limit: None megabytes Problem Description: Emily's birthday is next week and Jack has decided to buy a present for her. He knows she loves books so he goes to the local bookshop, where there are *n* books on sale from one of *m* genres. In the bookshop, Jack decides to buy two books of different genres. Based on the genre of books on sale in the shop, find the number of options available to Jack for choosing two books of different genres for Emily. Options are considered different if they differ in at least one book. The books are given by indices of their genres. The genres are numbered from 1 to *m*. Input Specification: The first line contains two positive integers *n* and *m* (2<=≤<=*n*<=≤<=2·105,<=2<=≤<=*m*<=≤<=10) — the number of books in the bookstore and the number of genres. The second line contains a sequence *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* (1<=≤<=*a**i*<=≤<=*m*) equals the genre of the *i*-th book. It is guaranteed that for each genre there is at least one book of that genre. Output Specification: Print the only integer — the number of ways in which Jack can choose books. It is guaranteed that the answer doesn't exceed the value 2·109. Demo Input: ['4 3\n2 1 3 1\n', '7 4\n4 2 3 1 2 4 3\n'] Demo Output: ['5\n', '18\n'] Note: The answer to the first test sample equals 5 as Sasha can choose: 1. the first and second books, 1. the first and third books, 1. the first and fourth books, 1. the second and third books, 1. the third and fourth books.
```python n,m=list(map(int,input().split())) A=list(map(int,input().split())) count = 0 D={} for val in A: if val not in D: D[val]=[count] else: D[val].append(count) count += 1 Ans = 0 for val,N in zip(A,range(1,len(A)+1)): c=0 for k in D[val]: if k > N: c += 1 Ans += n-c-N #print(Ans,c,N) print(Ans) ```
0
27
E
Number With The Given Amount Of Divisors
PROGRAMMING
2,000
[ "brute force", "dp", "number theory" ]
E. Number With The Given Amount Of Divisors
2
256
Given the number *n*, find the smallest positive integer which has exactly *n* divisors. It is guaranteed that for the given *n* the answer will not exceed 1018.
The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=1000).
Output the smallest positive integer with exactly *n* divisors.
[ "4\n", "6\n" ]
[ "6\n", "12\n" ]
none
2,500
[ { "input": "1", "output": "1" }, { "input": "7", "output": "64" }, { "input": "8", "output": "24" }, { "input": "9", "output": "36" }, { "input": "10", "output": "48" }, { "input": "15", "output": "144" }, { "input": "20", "output": "24...
1,691,128,558
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
2
92
614,400
p=["1","2","4","6","16","12","64","30","36","48","1024","60","4096","192","144","210","65536","180","262144","240","576","3072","4194304","420","1296","12288","900","960","268435456","720", "1073741824","2310","9216","196608","5184","1260","68719476736","786432","36864","1680","1099511627776","2880","4398046511104","15360","3600","12582912","70368744177664","4620","46656","6480","589824","61440","4503599627370496","6300","82944","6720","2359296","805306368","288230376151711744","5040", "1152921504606846976","3221225472","14400","30030","331776","46080","73786976294838206464","983040","37748736","25920","1180591620717411303424","13860","4722366482869645213696","206158430208","32400","3932160","746496","184320","202231454903657293676544","18480","44100","3298534883328","635703278458516698824704","20160","5308416","13194139533312","2415919104","107520","1385009821345068724781056","25200", "2985984","62914560","9663676416","211106232532992","21233664","60060","2162514264337593543950336","233280","230400","45360","2500228229401496703205376","2949120","2400912917605986812821504","430080","129600","13510798882111488","1914606681695789005144064","69300","2358426726783156020576256","414720","618475290624","73920","2834827628530496329220096","11796480","339738624","4026531840","921600","864691128455135232","47775744","55440", "60466176","3458764513820540928","9895604649984","16106127360","810000","100800","3915865843651857942052864","510510","39582418599936","1658880","16253853498429727072845824","322560","191102976","221360928884514619392","176400","6881280","24646623899502532662132736","188743680","16386495598010130648530944","181440","633318697598976","3541774862152233910272","241864704","180180","21743271936","14167099448608935641088","1166400","1030792151040","25571492362373784095686656","226800", "17285969449495136382746624","27525120","14745600","3732480","86973087744","1290240","26302044767688728495783936","606694364710971881029632","40532396646334464","240240","3057647616","485100","18830865132078623730171904","16492674416640","2073600","1907109835375550096474112","19493842113257979682750464","221760","2176782336","26542080","58982400","65970697666560","27005895248510699696029696","12079595520","3240000","1182720","2594073385365405696","4155029464035206174343168","19577295904684780545900544","277200", "27909183618739122183602176","14929920","10376293541461622784","440401920","5566277615616","48318382080","3869835264","1055531162664960","705600","106168320","19604025588861116008628224","1021020","28416102355444464034512896","6487542793012780631851008","8294400","1632960","28757637687111424552206336","1612800","19230550748445698208825344","498960","664082786653543858176","7500684688204490109616128","195689447424","20643840","89060441849856","7202738752817960438464512","943718400","4730880","15479341056","907200", "25135865633579863348609024","67553994410557440","10625324586456701730816","5743820045087367015432192","356241767399424","900900","782757789696","7075280180349468061728768","42501298345826806923264","2903040","34828517376","3092376453120","29305635143120275902562304","960960","1587600","8504482885591488987660288","33790162289924414440996864","82575360","43060649159697657763987456","1698693120","18662400","28185722880","39370386555162524223799296","6451200","5699868278390784","4323455642275676160","1820083094132915643088896","238878720","34904739530401550323154944","720720", "45618958121606201292619776","302330880","5336100","17293822569102704640","29160000","49478023249920","139314069504","112742891520","5721329506126650289422336","5670000","35313116524750123642650624","1108800","247669456896","11747597530955573826158592","132710400","9699690","53039457584007913129639936","197912092999680","50096498540544","11612160","60397977600","48761560495289181218537472","212725285376506440296955904","3548160","364791569817010176","955514880","12465088392105618523029504","1106804644422573096960","319318264096412179005177856","1940400", "213473056385648716020711424","75694080","74649600","73939871698507597986398208","51840000","1321205760","319975608681517825325531136","49159486794030391945592832","241591910400","1995840","320309738904285205208498176","3166593487994880","214438955617140820833992704","17708874310761169551360","530841600","1209323520","801543976648704","3063060","2821109907456","108716359680","19462628379038341895553024","70835497243044678205440","321290551952200534008528896","8164800","23346660468288651264","7215545057280","11289600","76714477087121352287059968","2229025112064","2494800", "3206175906594816","51857908348485409148239872","22502054064613470328848384","302776320","93386641873154605056","103219200","215703184853549195737432064","26127360","21608216258453881315393536","434865438720","216450957656787131798913024","14192640","322903830627148527195652096","78906134303066185487351808","6350400","1033471823554859405148160","322261290034376435130433536","202661983231672320","15850845241344","4084080","17231460135262101046296576","15288238080","11284439629824","6306300","207360000","56492595396235871190515712","21225840541048404185186304","115448720916480","51298814505517056","14515200", "219075923223513177023053824","3235549176877750482370560","15461882265600","58481526339773939048251392","5976745079881894723584","2882880","327259086304843329475444736","10883911680","25513448656774466962980864","185794560","63403380965376","412876800","729000000","461794883665920","8493465600","81017685745532099088089088","222404376159569382855409664","84557168640","332617504638277531421638656","22680000","45158400","15375360","335980074212440502746218496","12970366926827028480","95627921278110315577344","6975147320176030871715840","1194393600","58731887714054341637701632","231224749596192175757983744","3603600", "101559956668416","83727550856217366550806528","1511654400","104509440","382511685112441262309376","51881467707308113920","231735896625196994043838464","4844421120","247390116249600","27831388078080","3283124128353091584","338228674560","341497384012607618805661696","19349176320","39690000","7388718138654720","142657607172096","7761600","232332576806887603562348544","743178240","35242792592866721478475776","58812076766583348025884672","241521228910201656997576704","19399380","466560000","85248307066333392103538688","989560464998400","10837713965063903159255040","470458650252906047844909056","58060800", "180551034077184","17962560","146284681485867543655612416","86272913061334273656619008","380747847196240787800064","17740800","473714464743948248296718336","57691652245337094626476032","4777574400","6486480","474631435903171972747493376","3320413933267719290880","570630428688384","12503423441022450548080640","21344400","978447237120","4057816381784064","227082240","481047591212025023358304256","445302209249280","221819615095522793959194624","12013693764089802192322560","210119944214597861376","6606028800","1091965555139852604801024","61501440","147478460382091175836778496","77396705280","329333401113623918903558144","9979200", "486433604454495675614232576","75407596900739590045827072","15832967439974400","472877960873902080","3317760000","53126622932283508654080","840479776858391445504","9619100225436835077160960","6046617600","1781208836997120","333710961403571828974157824","15315300","488443845614287315896631296","3913788948480","543581798400","11876400901747340308643840","1624959306694656","212506491729134034616320","337606119314388217384402944","31933440","57153600","174142586880","335397909030211478150447104","21646635171840","1785795528950566707265536","87916905429360827707686912","230143431261364056861179904","16336320","493166177933534601628614656","17463600", "64925062108545024","14222414427957444938301440","155573725045456227444719616","101370486869773243322990592","1866240000","908328960","498141550984858016925351936","129181947479092973291962368","722534400","11890851840","496364815757728270805630976","130636800","349959263030913083222523904","310042951680","2174327193600","118111159665487572671397888","368948208494609331560382464","70963200","53790705718937052512256","28499341391953920","236718402909198556462055424","30264189495929733120","259700248434180096","1100415470664578215444480","13271040000","1672151040","1013309916158361600","104714218591204650969464832","391761993919822071326572544","12252240", "36520347436056576","136856874364818603877859328","76441190400","2116316160","2363655411345077059977216","69369300","427470443474450259602571264","121056757983718932480","169477786188707613571547136","204120000","408627095591204153641140224","346346162749440","11555266180939776","696570347520","101606400","1240171806720","160651291502992840196096","3406647530633251447111680","447436471348263332131897344","62370000","175444579019321817144754176","105939349574250370927951872","447383541572213314110357504","14414400","2518486581521232959635456","1238347284480","54419558400","19637987654777869130792960","610046660621652103062880256","928972800", "642605166011971360784384","223092870","2890137600","159118372752023739388919808","2473946326084931838541824","1385384650997760","4155203974946881536","250482492702720","243053057236596297264267264","127733760","3856921906287014145557528576","422785843200","2571187625148056582230114304","81307802476445906092687360","158760000","638175856129519320890867712","46221064723759104","46126080","131621703842267136","1823957849085050880","64851834634135142400","6688604160","584325558976905216","7125441960528092615147520","2283141217358909416669184","7747632510958011678720","176195663142163024913104896","957954792289236537015533568","11664000000","25225200", "3858906812144692131084107776","640419169156946148062134272","251182652568652099652419584","984023040","3032564869435637666676736","522547200","2574735977260296389382897664","123299358492537989931991040","259407338536540569600","362880000","103997395628457984","14533263360","2026730624766167090200576","959926826044553475976593408","139156940390400","81997433970151959727964160","3859440714543502728087207936","1691143372800","2337302235907620864","25945920","96745881600","960929216712855615625494528","2575005730784174597581307904","22166154415964160","3221037910970202666827776","643316866851422462501978112","85377600","23962120175328186859520","3861266770187174245203705856","3715891200", "2574367080748696980814823424","8465264640","176436230299750044077654016","4007719883243520","212336640000","58198140","3860593167916606772148699136","14105549537280","255744921199000176310616064","761014517760","6327689996258673443209216","10913141895191709477765120","265933054396600418304","95848480701312747438080","406425600","963871655856601602025586688","2577703946605334680267915264","89812800","415989582513831936","116733302341443256320","258818739184002820969857024","79370995630080","3864952582741419537146576896","124185600","29859840000","127872385435606761435299840","173074956736011283879428096","11145125560320","2581865295450850377380921344","32432400", "3869761181803401509523685376","16030879532974080","16602069666338596454400","86489541742427045741199360","37791360000","12510270323067351644241920","2585815635417696609515864064","3936092160","4892236185600","466933209365773025280","37396835774521933824","1135411200","3874900666732583009015300096","647109554560647587212296192","2226511046246400","287400960","3872210667721328144244801536","12041081292269406576967680","2587442670885312576979206144","3044058071040","46242201600","649352872970361395396739072","12572159760555100365389824","184504320","1944810000","968711491881445581586956288","386983526400","131530671515330927436759040","2958148142320582656","69854400", "2593779946240315306828365824","1034302764884015836037120","226222790702218770137481216","966783870103129305391300608","4385133335800493306281984","1418633882621706240","46656000000","79254226206720","65633114661417543270400","77597520","3884864950082874192246603776","9757300676310505231482880","2673959800331496768986415104","107017666560","8906044184985600","56422198149120","2674756805303948303782641664","107207100","17019715481382426771456","1451520000","19568944742400","94162976981179355952578560","4010935539452691442089066496","12129202705242020925931520","16562133372807892900511744","1269935930081280","262532458645670173081600","256494072527585280","2677074524972252293700255744","159667200", "4015898099889009174801022976","657227769670539531069161472","870712934400","3248844238144253376593920","119439360000","108233175859200","8423789045905096704","97507631698869695241256960","263750716288082483123060736","29883725399409473617920","68078861925529707085824","49008960","4021517145381579984990109696","981777258914529988426334208","192099600","76187381760","4024374326105279759841755136","14367243283872334814904320","19872898702105693539794944","2043740160","304111460609319729968971776","317016904826880","2683856870737904629872328704","4541644800","25176535859705145632751616","5103000000","387545842437278919875887104","5079743720325120","2393397489569403764736","59454259200", "2693758908903585247316148224","135088428727660495440445440","914457600","667213128478708148566228992","16906143438820582531006464","930128855040","47330370277129322496","997852513914832594264915968","354333478996462718014193664","249480000","4029722717271293251735781376","496742400","26623333280885243904","261381120","142496706959769600","1007940222637321508238655488","22666379233691096636719104","90792568487789199360","4033215621451072444360032256","78139606390551577886720","1102077353322891077222400","6926031241232216102010880","33695156183620386816","8360755200","151165440000","97959438570271708188508160","314142655773613952908394496","693674248788576527273951232","2707796365898183024673030144","61261200", "22265516934764386546876416","507799783342080","410570623094455811633577984","139637754281086832754032640","13589544960000","10581580800","2734069669934854316295716864","1149603840","901800900","312558425562206311546880","189321481108517289984","363170273951156797440","4088058875830676242925879296","695207689875590982131515392","1428840000","62977474560","857047163233901253492736","1731730813747200","2778968053163279547256274944","194819716546560","3482851737600","16415620641765457920","2785788850612472756100399104","3720515420160","25690881352276511750619136","1024492152037822856416985088","3433237653166257235558400","135444234240","17748270956230184750022656","436590000", "2784545756793025561702170624","81275899525201920","317818048722751112783855616","713288035860480","17763525409106047002476544","100900800","4143928434753635948938919936","696997730420662810687045632","6191736422400","8174960640","4147254956058175183022718976","19813962964333607392378880","21693083824920739000090624","98060383832916740129423360","6502809600","724563686730604970992730112","153177439332441840943104","446185740","4180768750892846853816057856","3265920000","477355118256071218166759424","142141535331666960517693440","5770600014285549661056925696","6926923254988800","54358179840000","10863997755447322114785280","1252412463513600","1411375950758718143534727168","425973332494163902464","638668800", "812754611742420055883776","902755170385920","2959500902400","233513280","26465626182787008158498816","81423407429337718278062080","3856234054445646756670603264","143864565306671368283095040","1914527568388557962672603136","1103739235981203939000320","26189341198731824001449984","230630400","112709757329767363772416","1421143394231844744890155008","9119789245425254400","96158261226685473132380160","5784871752342278830697742336","33443020800","3029143697736276639744","110270160","7027209802640463075737600","1423894307709515918242480128","551018446969680223535104","23242897532874035036160","1911029760000","2853152143441920","2873864376867709611046600704","12523964087157153836564480","5786997593974090537952608256","277477200", "3862490375896362151810433024","6849130659840","1921257507470838444186402816","20289081908920320","18900075698368522143924224","2952069120","1703893329976655609856","1443142773636075070074912768","3657830400","3117115464744960","5795244917874843453883416576","123498075477613969795973120","3874779671499373815533666304","12095856348628615346257920","2540160000","1050599721072989306880","3870774743989981048538660864","72666316800","5793798975959924194154643456","3459827775699263024005120","2879780478133660427929780224","1045524480","746496000000","82192301910455879183892480","19801211173896354302787584","541776936960","11838003609600","988000203340871756710674432","3872751382962374814354898944","129729600", "6140942214464815497216","1459300813363487026842697728","2882787650138566846876483584","125737984503697950229135360","1360488960000","110830772079820800","944784000000","5201657569612922880","1929950600554267387505934336","23224320000","2156489995751704756224","71886360525984560578560","5817458455548958390664298496","4202398884291957227520","26011238400","9633701578057845540126720","5844735288783334250628775936","42326323200","3911141155133337002515103744","12468461858979840","20038599416217600","1001132884210715486922473472","3937058482133392040241659904","290990700","27477515129366675378405376","1465331536842861947689893888","70527747686400","27396522639360","2265180606059534306246656","3805072588800", "613424469105111281434624","11834806312231382160506880","10965709475958547388825600","8124796533473280","7779240000","287545442103938242314240","5884171273495187319355867136","1012818357943164652153208832","2891614967569804806076760064","415134720","5906140375922997109693874176","628689600","3988861503691988438775496704","1218998108160","583666511707216281600","1006193727090634434451341312","3988084059071815020407947264","238112986890240","35966200022204439756537856","6928977644752833536327680","1366041600","146584527146804138538434560","27262293279626489757696","127917156306820284305899520","20160968279467224217944064","310390080","55725627801600","1479498533800603804885843968","24563768857859261988864","227026800", "193865196655121704943616","324625310542725120","80154397664870400","14256900995702114568110080","28643873117868896871776256","86668625227281137223598080","4472925287506839283710296064","168952434348866216614952960","12551351615336758221209600","13063680000","4499504600109428539364737024","11808276480","6142889696952548899946496","1494424652954574050776055808","2334666046828865126400","215309737395464866459811840","146959200355271036104605696","7947878400","4504977628013706077372678144","130799370240","1941328663681942761636888576","1489094447273184812416892928","514791505681780502953984","1437004800","3478923509760000","1049877789092739249667571712","12205406461347032884838400","4030558371840","6761891086035023229622419456","15220290355200", "2985984000000","196855798327437863356989440","1948058618911084186190217216","1106844625483827994681147392","2418647040000","922521600","6764018024965946783339380736","268953528594685262561280","2906134475644336744760868864","199495389743677440","6784188399455148533430091776","131592014545992782310277120","34503839932027276099584","332906084455227064320","768398400","1298501242170900480","4587257565129506139525873664","1102908294652047508111360","759166022727122011815936","92897280000","2900351610309387916173901824","18393661440","6832184168288392929655914496","7093169413108531200","19926072697750396698886144","174571092956023254847324160","396271131033600","1175285981759466213979717632","222388822737346310694764544","232792560", "21073919720733357899776","182601737180282880","9786503381552526157414400","228184371824093019389296640","28904290791001586795544576","535088332800","4575313237029759482503102464","23279477760","282110990745600","11018277056725385299886080","4657211792476151720049639424","1179278100","147955290949385242779058176","1282411330423350778807713792","10160640000","1331624337820908257280","6974754718473710083176923136","94188930943538067857735680","13244940604963129596575744","2245320000","12046013526210104629657600","1225881286773612460923420672","4828601982317445323323080704","3809807790243840","29368652656025388728713216","57776330904698880","1282470362637926400","4875992432640","138015359728109104398336","1117670400",] n=int(input()) print(p[n-1])
Title: Number With The Given Amount Of Divisors Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Given the number *n*, find the smallest positive integer which has exactly *n* divisors. It is guaranteed that for the given *n* the answer will not exceed 1018. Input Specification: The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=1000). Output Specification: Output the smallest positive integer with exactly *n* divisors. Demo Input: ['4\n', '6\n'] Demo Output: ['6\n', '12\n'] Note: none
```python p=["1","2","4","6","16","12","64","30","36","48","1024","60","4096","192","144","210","65536","180","262144","240","576","3072","4194304","420","1296","12288","900","960","268435456","720", "1073741824","2310","9216","196608","5184","1260","68719476736","786432","36864","1680","1099511627776","2880","4398046511104","15360","3600","12582912","70368744177664","4620","46656","6480","589824","61440","4503599627370496","6300","82944","6720","2359296","805306368","288230376151711744","5040", "1152921504606846976","3221225472","14400","30030","331776","46080","73786976294838206464","983040","37748736","25920","1180591620717411303424","13860","4722366482869645213696","206158430208","32400","3932160","746496","184320","202231454903657293676544","18480","44100","3298534883328","635703278458516698824704","20160","5308416","13194139533312","2415919104","107520","1385009821345068724781056","25200", "2985984","62914560","9663676416","211106232532992","21233664","60060","2162514264337593543950336","233280","230400","45360","2500228229401496703205376","2949120","2400912917605986812821504","430080","129600","13510798882111488","1914606681695789005144064","69300","2358426726783156020576256","414720","618475290624","73920","2834827628530496329220096","11796480","339738624","4026531840","921600","864691128455135232","47775744","55440", "60466176","3458764513820540928","9895604649984","16106127360","810000","100800","3915865843651857942052864","510510","39582418599936","1658880","16253853498429727072845824","322560","191102976","221360928884514619392","176400","6881280","24646623899502532662132736","188743680","16386495598010130648530944","181440","633318697598976","3541774862152233910272","241864704","180180","21743271936","14167099448608935641088","1166400","1030792151040","25571492362373784095686656","226800", "17285969449495136382746624","27525120","14745600","3732480","86973087744","1290240","26302044767688728495783936","606694364710971881029632","40532396646334464","240240","3057647616","485100","18830865132078623730171904","16492674416640","2073600","1907109835375550096474112","19493842113257979682750464","221760","2176782336","26542080","58982400","65970697666560","27005895248510699696029696","12079595520","3240000","1182720","2594073385365405696","4155029464035206174343168","19577295904684780545900544","277200", "27909183618739122183602176","14929920","10376293541461622784","440401920","5566277615616","48318382080","3869835264","1055531162664960","705600","106168320","19604025588861116008628224","1021020","28416102355444464034512896","6487542793012780631851008","8294400","1632960","28757637687111424552206336","1612800","19230550748445698208825344","498960","664082786653543858176","7500684688204490109616128","195689447424","20643840","89060441849856","7202738752817960438464512","943718400","4730880","15479341056","907200", "25135865633579863348609024","67553994410557440","10625324586456701730816","5743820045087367015432192","356241767399424","900900","782757789696","7075280180349468061728768","42501298345826806923264","2903040","34828517376","3092376453120","29305635143120275902562304","960960","1587600","8504482885591488987660288","33790162289924414440996864","82575360","43060649159697657763987456","1698693120","18662400","28185722880","39370386555162524223799296","6451200","5699868278390784","4323455642275676160","1820083094132915643088896","238878720","34904739530401550323154944","720720", "45618958121606201292619776","302330880","5336100","17293822569102704640","29160000","49478023249920","139314069504","112742891520","5721329506126650289422336","5670000","35313116524750123642650624","1108800","247669456896","11747597530955573826158592","132710400","9699690","53039457584007913129639936","197912092999680","50096498540544","11612160","60397977600","48761560495289181218537472","212725285376506440296955904","3548160","364791569817010176","955514880","12465088392105618523029504","1106804644422573096960","319318264096412179005177856","1940400", "213473056385648716020711424","75694080","74649600","73939871698507597986398208","51840000","1321205760","319975608681517825325531136","49159486794030391945592832","241591910400","1995840","320309738904285205208498176","3166593487994880","214438955617140820833992704","17708874310761169551360","530841600","1209323520","801543976648704","3063060","2821109907456","108716359680","19462628379038341895553024","70835497243044678205440","321290551952200534008528896","8164800","23346660468288651264","7215545057280","11289600","76714477087121352287059968","2229025112064","2494800", "3206175906594816","51857908348485409148239872","22502054064613470328848384","302776320","93386641873154605056","103219200","215703184853549195737432064","26127360","21608216258453881315393536","434865438720","216450957656787131798913024","14192640","322903830627148527195652096","78906134303066185487351808","6350400","1033471823554859405148160","322261290034376435130433536","202661983231672320","15850845241344","4084080","17231460135262101046296576","15288238080","11284439629824","6306300","207360000","56492595396235871190515712","21225840541048404185186304","115448720916480","51298814505517056","14515200", "219075923223513177023053824","3235549176877750482370560","15461882265600","58481526339773939048251392","5976745079881894723584","2882880","327259086304843329475444736","10883911680","25513448656774466962980864","185794560","63403380965376","412876800","729000000","461794883665920","8493465600","81017685745532099088089088","222404376159569382855409664","84557168640","332617504638277531421638656","22680000","45158400","15375360","335980074212440502746218496","12970366926827028480","95627921278110315577344","6975147320176030871715840","1194393600","58731887714054341637701632","231224749596192175757983744","3603600", "101559956668416","83727550856217366550806528","1511654400","104509440","382511685112441262309376","51881467707308113920","231735896625196994043838464","4844421120","247390116249600","27831388078080","3283124128353091584","338228674560","341497384012607618805661696","19349176320","39690000","7388718138654720","142657607172096","7761600","232332576806887603562348544","743178240","35242792592866721478475776","58812076766583348025884672","241521228910201656997576704","19399380","466560000","85248307066333392103538688","989560464998400","10837713965063903159255040","470458650252906047844909056","58060800", "180551034077184","17962560","146284681485867543655612416","86272913061334273656619008","380747847196240787800064","17740800","473714464743948248296718336","57691652245337094626476032","4777574400","6486480","474631435903171972747493376","3320413933267719290880","570630428688384","12503423441022450548080640","21344400","978447237120","4057816381784064","227082240","481047591212025023358304256","445302209249280","221819615095522793959194624","12013693764089802192322560","210119944214597861376","6606028800","1091965555139852604801024","61501440","147478460382091175836778496","77396705280","329333401113623918903558144","9979200", "486433604454495675614232576","75407596900739590045827072","15832967439974400","472877960873902080","3317760000","53126622932283508654080","840479776858391445504","9619100225436835077160960","6046617600","1781208836997120","333710961403571828974157824","15315300","488443845614287315896631296","3913788948480","543581798400","11876400901747340308643840","1624959306694656","212506491729134034616320","337606119314388217384402944","31933440","57153600","174142586880","335397909030211478150447104","21646635171840","1785795528950566707265536","87916905429360827707686912","230143431261364056861179904","16336320","493166177933534601628614656","17463600", "64925062108545024","14222414427957444938301440","155573725045456227444719616","101370486869773243322990592","1866240000","908328960","498141550984858016925351936","129181947479092973291962368","722534400","11890851840","496364815757728270805630976","130636800","349959263030913083222523904","310042951680","2174327193600","118111159665487572671397888","368948208494609331560382464","70963200","53790705718937052512256","28499341391953920","236718402909198556462055424","30264189495929733120","259700248434180096","1100415470664578215444480","13271040000","1672151040","1013309916158361600","104714218591204650969464832","391761993919822071326572544","12252240", "36520347436056576","136856874364818603877859328","76441190400","2116316160","2363655411345077059977216","69369300","427470443474450259602571264","121056757983718932480","169477786188707613571547136","204120000","408627095591204153641140224","346346162749440","11555266180939776","696570347520","101606400","1240171806720","160651291502992840196096","3406647530633251447111680","447436471348263332131897344","62370000","175444579019321817144754176","105939349574250370927951872","447383541572213314110357504","14414400","2518486581521232959635456","1238347284480","54419558400","19637987654777869130792960","610046660621652103062880256","928972800", "642605166011971360784384","223092870","2890137600","159118372752023739388919808","2473946326084931838541824","1385384650997760","4155203974946881536","250482492702720","243053057236596297264267264","127733760","3856921906287014145557528576","422785843200","2571187625148056582230114304","81307802476445906092687360","158760000","638175856129519320890867712","46221064723759104","46126080","131621703842267136","1823957849085050880","64851834634135142400","6688604160","584325558976905216","7125441960528092615147520","2283141217358909416669184","7747632510958011678720","176195663142163024913104896","957954792289236537015533568","11664000000","25225200", "3858906812144692131084107776","640419169156946148062134272","251182652568652099652419584","984023040","3032564869435637666676736","522547200","2574735977260296389382897664","123299358492537989931991040","259407338536540569600","362880000","103997395628457984","14533263360","2026730624766167090200576","959926826044553475976593408","139156940390400","81997433970151959727964160","3859440714543502728087207936","1691143372800","2337302235907620864","25945920","96745881600","960929216712855615625494528","2575005730784174597581307904","22166154415964160","3221037910970202666827776","643316866851422462501978112","85377600","23962120175328186859520","3861266770187174245203705856","3715891200", "2574367080748696980814823424","8465264640","176436230299750044077654016","4007719883243520","212336640000","58198140","3860593167916606772148699136","14105549537280","255744921199000176310616064","761014517760","6327689996258673443209216","10913141895191709477765120","265933054396600418304","95848480701312747438080","406425600","963871655856601602025586688","2577703946605334680267915264","89812800","415989582513831936","116733302341443256320","258818739184002820969857024","79370995630080","3864952582741419537146576896","124185600","29859840000","127872385435606761435299840","173074956736011283879428096","11145125560320","2581865295450850377380921344","32432400", "3869761181803401509523685376","16030879532974080","16602069666338596454400","86489541742427045741199360","37791360000","12510270323067351644241920","2585815635417696609515864064","3936092160","4892236185600","466933209365773025280","37396835774521933824","1135411200","3874900666732583009015300096","647109554560647587212296192","2226511046246400","287400960","3872210667721328144244801536","12041081292269406576967680","2587442670885312576979206144","3044058071040","46242201600","649352872970361395396739072","12572159760555100365389824","184504320","1944810000","968711491881445581586956288","386983526400","131530671515330927436759040","2958148142320582656","69854400", "2593779946240315306828365824","1034302764884015836037120","226222790702218770137481216","966783870103129305391300608","4385133335800493306281984","1418633882621706240","46656000000","79254226206720","65633114661417543270400","77597520","3884864950082874192246603776","9757300676310505231482880","2673959800331496768986415104","107017666560","8906044184985600","56422198149120","2674756805303948303782641664","107207100","17019715481382426771456","1451520000","19568944742400","94162976981179355952578560","4010935539452691442089066496","12129202705242020925931520","16562133372807892900511744","1269935930081280","262532458645670173081600","256494072527585280","2677074524972252293700255744","159667200", "4015898099889009174801022976","657227769670539531069161472","870712934400","3248844238144253376593920","119439360000","108233175859200","8423789045905096704","97507631698869695241256960","263750716288082483123060736","29883725399409473617920","68078861925529707085824","49008960","4021517145381579984990109696","981777258914529988426334208","192099600","76187381760","4024374326105279759841755136","14367243283872334814904320","19872898702105693539794944","2043740160","304111460609319729968971776","317016904826880","2683856870737904629872328704","4541644800","25176535859705145632751616","5103000000","387545842437278919875887104","5079743720325120","2393397489569403764736","59454259200", "2693758908903585247316148224","135088428727660495440445440","914457600","667213128478708148566228992","16906143438820582531006464","930128855040","47330370277129322496","997852513914832594264915968","354333478996462718014193664","249480000","4029722717271293251735781376","496742400","26623333280885243904","261381120","142496706959769600","1007940222637321508238655488","22666379233691096636719104","90792568487789199360","4033215621451072444360032256","78139606390551577886720","1102077353322891077222400","6926031241232216102010880","33695156183620386816","8360755200","151165440000","97959438570271708188508160","314142655773613952908394496","693674248788576527273951232","2707796365898183024673030144","61261200", "22265516934764386546876416","507799783342080","410570623094455811633577984","139637754281086832754032640","13589544960000","10581580800","2734069669934854316295716864","1149603840","901800900","312558425562206311546880","189321481108517289984","363170273951156797440","4088058875830676242925879296","695207689875590982131515392","1428840000","62977474560","857047163233901253492736","1731730813747200","2778968053163279547256274944","194819716546560","3482851737600","16415620641765457920","2785788850612472756100399104","3720515420160","25690881352276511750619136","1024492152037822856416985088","3433237653166257235558400","135444234240","17748270956230184750022656","436590000", "2784545756793025561702170624","81275899525201920","317818048722751112783855616","713288035860480","17763525409106047002476544","100900800","4143928434753635948938919936","696997730420662810687045632","6191736422400","8174960640","4147254956058175183022718976","19813962964333607392378880","21693083824920739000090624","98060383832916740129423360","6502809600","724563686730604970992730112","153177439332441840943104","446185740","4180768750892846853816057856","3265920000","477355118256071218166759424","142141535331666960517693440","5770600014285549661056925696","6926923254988800","54358179840000","10863997755447322114785280","1252412463513600","1411375950758718143534727168","425973332494163902464","638668800", "812754611742420055883776","902755170385920","2959500902400","233513280","26465626182787008158498816","81423407429337718278062080","3856234054445646756670603264","143864565306671368283095040","1914527568388557962672603136","1103739235981203939000320","26189341198731824001449984","230630400","112709757329767363772416","1421143394231844744890155008","9119789245425254400","96158261226685473132380160","5784871752342278830697742336","33443020800","3029143697736276639744","110270160","7027209802640463075737600","1423894307709515918242480128","551018446969680223535104","23242897532874035036160","1911029760000","2853152143441920","2873864376867709611046600704","12523964087157153836564480","5786997593974090537952608256","277477200", "3862490375896362151810433024","6849130659840","1921257507470838444186402816","20289081908920320","18900075698368522143924224","2952069120","1703893329976655609856","1443142773636075070074912768","3657830400","3117115464744960","5795244917874843453883416576","123498075477613969795973120","3874779671499373815533666304","12095856348628615346257920","2540160000","1050599721072989306880","3870774743989981048538660864","72666316800","5793798975959924194154643456","3459827775699263024005120","2879780478133660427929780224","1045524480","746496000000","82192301910455879183892480","19801211173896354302787584","541776936960","11838003609600","988000203340871756710674432","3872751382962374814354898944","129729600", "6140942214464815497216","1459300813363487026842697728","2882787650138566846876483584","125737984503697950229135360","1360488960000","110830772079820800","944784000000","5201657569612922880","1929950600554267387505934336","23224320000","2156489995751704756224","71886360525984560578560","5817458455548958390664298496","4202398884291957227520","26011238400","9633701578057845540126720","5844735288783334250628775936","42326323200","3911141155133337002515103744","12468461858979840","20038599416217600","1001132884210715486922473472","3937058482133392040241659904","290990700","27477515129366675378405376","1465331536842861947689893888","70527747686400","27396522639360","2265180606059534306246656","3805072588800", "613424469105111281434624","11834806312231382160506880","10965709475958547388825600","8124796533473280","7779240000","287545442103938242314240","5884171273495187319355867136","1012818357943164652153208832","2891614967569804806076760064","415134720","5906140375922997109693874176","628689600","3988861503691988438775496704","1218998108160","583666511707216281600","1006193727090634434451341312","3988084059071815020407947264","238112986890240","35966200022204439756537856","6928977644752833536327680","1366041600","146584527146804138538434560","27262293279626489757696","127917156306820284305899520","20160968279467224217944064","310390080","55725627801600","1479498533800603804885843968","24563768857859261988864","227026800", "193865196655121704943616","324625310542725120","80154397664870400","14256900995702114568110080","28643873117868896871776256","86668625227281137223598080","4472925287506839283710296064","168952434348866216614952960","12551351615336758221209600","13063680000","4499504600109428539364737024","11808276480","6142889696952548899946496","1494424652954574050776055808","2334666046828865126400","215309737395464866459811840","146959200355271036104605696","7947878400","4504977628013706077372678144","130799370240","1941328663681942761636888576","1489094447273184812416892928","514791505681780502953984","1437004800","3478923509760000","1049877789092739249667571712","12205406461347032884838400","4030558371840","6761891086035023229622419456","15220290355200", "2985984000000","196855798327437863356989440","1948058618911084186190217216","1106844625483827994681147392","2418647040000","922521600","6764018024965946783339380736","268953528594685262561280","2906134475644336744760868864","199495389743677440","6784188399455148533430091776","131592014545992782310277120","34503839932027276099584","332906084455227064320","768398400","1298501242170900480","4587257565129506139525873664","1102908294652047508111360","759166022727122011815936","92897280000","2900351610309387916173901824","18393661440","6832184168288392929655914496","7093169413108531200","19926072697750396698886144","174571092956023254847324160","396271131033600","1175285981759466213979717632","222388822737346310694764544","232792560", "21073919720733357899776","182601737180282880","9786503381552526157414400","228184371824093019389296640","28904290791001586795544576","535088332800","4575313237029759482503102464","23279477760","282110990745600","11018277056725385299886080","4657211792476151720049639424","1179278100","147955290949385242779058176","1282411330423350778807713792","10160640000","1331624337820908257280","6974754718473710083176923136","94188930943538067857735680","13244940604963129596575744","2245320000","12046013526210104629657600","1225881286773612460923420672","4828601982317445323323080704","3809807790243840","29368652656025388728713216","57776330904698880","1282470362637926400","4875992432640","138015359728109104398336","1117670400",] n=int(input()) print(p[n-1]) ```
0
847
H
Load Testing
PROGRAMMING
1,600
[ "greedy" ]
null
null
Polycarp plans to conduct a load testing of its new project Fakebook. He already agreed with his friends that at certain points in time they will send requests to Fakebook. The load testing will last *n* minutes and in the *i*-th minute friends will send *a**i* requests. Polycarp plans to test Fakebook under a special kind of load. In case the information about Fakebook gets into the mass media, Polycarp hopes for a monotone increase of the load, followed by a monotone decrease of the interest to the service. Polycarp wants to test this form of load. Your task is to determine how many requests Polycarp must add so that before some moment the load on the server strictly increases and after that moment strictly decreases. Both the increasing part and the decreasing part can be empty (i. e. absent). The decrease should immediately follow the increase. In particular, the load with two equal neigbouring values is unacceptable. For example, if the load is described with one of the arrays [1, 2, 8, 4, 3], [1, 3, 5] or [10], then such load satisfies Polycarp (in each of the cases there is an increasing part, immediately followed with a decreasing part). If the load is described with one of the arrays [1, 2, 2, 1], [2, 1, 2] or [10, 10], then such load does not satisfy Polycarp. Help Polycarp to make the minimum number of additional requests, so that the resulting load satisfies Polycarp. He can make any number of additional requests at any minute from 1 to *n*.
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the duration of the load testing. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109), where *a**i* is the number of requests from friends in the *i*-th minute of the load testing.
Print the minimum number of additional requests from Polycarp that would make the load strictly increasing in the beginning and then strictly decreasing afterwards.
[ "5\n1 4 3 2 5\n", "5\n1 2 2 2 1\n", "7\n10 20 40 50 70 90 30\n" ]
[ "6\n", "1\n", "0\n" ]
In the first example Polycarp must make two additional requests in the third minute and four additional requests in the fourth minute. So the resulting load will look like: [1, 4, 5, 6, 5]. In total, Polycarp will make 6 additional requests. In the second example it is enough to make one additional request in the third minute, so the answer is 1. In the third example the load already satisfies all conditions described in the statement, so the answer is 0.
0
[ { "input": "5\n1 4 3 2 5", "output": "6" }, { "input": "5\n1 2 2 2 1", "output": "1" }, { "input": "7\n10 20 40 50 70 90 30", "output": "0" }, { "input": "1\n1", "output": "0" }, { "input": "2\n1 15", "output": "0" }, { "input": "4\n36 54 55 9", "o...
1,507,123,730
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
3
78
0
n = int(input()) def get_cost(arr): cost = [0,0] last = arr[0] for i in range(1,len(arr)): cost.append(cost[-1] + max(0,last+1-arr[i])) last = max(last+1,arr[i]) return cost arr = list(map(int,input().split())) left_cost, right_cost = get_cost(arr), get_cost(list(reversed(arr))) ans = 1e18 for i in range(1,n-1): ans = min(ans,left_cost[i]+right_cost[n-i-1]+max(0,max(arr[i-1],arr[i+1])+1-arr[i])) print(ans)
Title: Load Testing Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarp plans to conduct a load testing of its new project Fakebook. He already agreed with his friends that at certain points in time they will send requests to Fakebook. The load testing will last *n* minutes and in the *i*-th minute friends will send *a**i* requests. Polycarp plans to test Fakebook under a special kind of load. In case the information about Fakebook gets into the mass media, Polycarp hopes for a monotone increase of the load, followed by a monotone decrease of the interest to the service. Polycarp wants to test this form of load. Your task is to determine how many requests Polycarp must add so that before some moment the load on the server strictly increases and after that moment strictly decreases. Both the increasing part and the decreasing part can be empty (i. e. absent). The decrease should immediately follow the increase. In particular, the load with two equal neigbouring values is unacceptable. For example, if the load is described with one of the arrays [1, 2, 8, 4, 3], [1, 3, 5] or [10], then such load satisfies Polycarp (in each of the cases there is an increasing part, immediately followed with a decreasing part). If the load is described with one of the arrays [1, 2, 2, 1], [2, 1, 2] or [10, 10], then such load does not satisfy Polycarp. Help Polycarp to make the minimum number of additional requests, so that the resulting load satisfies Polycarp. He can make any number of additional requests at any minute from 1 to *n*. Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the duration of the load testing. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109), where *a**i* is the number of requests from friends in the *i*-th minute of the load testing. Output Specification: Print the minimum number of additional requests from Polycarp that would make the load strictly increasing in the beginning and then strictly decreasing afterwards. Demo Input: ['5\n1 4 3 2 5\n', '5\n1 2 2 2 1\n', '7\n10 20 40 50 70 90 30\n'] Demo Output: ['6\n', '1\n', '0\n'] Note: In the first example Polycarp must make two additional requests in the third minute and four additional requests in the fourth minute. So the resulting load will look like: [1, 4, 5, 6, 5]. In total, Polycarp will make 6 additional requests. In the second example it is enough to make one additional request in the third minute, so the answer is 1. In the third example the load already satisfies all conditions described in the statement, so the answer is 0.
```python n = int(input()) def get_cost(arr): cost = [0,0] last = arr[0] for i in range(1,len(arr)): cost.append(cost[-1] + max(0,last+1-arr[i])) last = max(last+1,arr[i]) return cost arr = list(map(int,input().split())) left_cost, right_cost = get_cost(arr), get_cost(list(reversed(arr))) ans = 1e18 for i in range(1,n-1): ans = min(ans,left_cost[i]+right_cost[n-i-1]+max(0,max(arr[i-1],arr[i+1])+1-arr[i])) print(ans) ```
0
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 the books.
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,676,428,285
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
1
61
0
import math X = int(input()) Y = 1 Z = 1 for i in range(1, X + 1): Y = Y + Z Z = int(math.log10(i)) + 1 print(Y)
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 assigned distinct numbers. Vanya wants to know how many digits he will have to write down as he labels the books. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=109) — the number of books in the library. Output Specification: Print the number of digits needed to number all the books. Demo Input: ['13\n', '4\n'] Demo Output: ['17\n', '4\n'] Note: 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.
```python import math X = int(input()) Y = 1 Z = 1 for i in range(1, X + 1): Y = Y + Z Z = int(math.log10(i)) + 1 print(Y) ```
0
141
A
Amusing Joke
PROGRAMMING
800
[ "implementation", "sortings", "strings" ]
null
null
So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's name and the host's name in honor of this event. Then the hung the letters above the main entrance. One night, when everyone went to bed, someone took all the letters of our characters' names. Then he may have shuffled the letters and put them in one pile in front of the door. The next morning it was impossible to find the culprit who had made the disorder. But everybody wondered whether it is possible to restore the names of the host and his guests from the letters lying at the door? That is, we need to verify that there are no extra letters, and that nobody will need to cut more letters. Help the "New Year and Christmas Men" and their friends to cope with this problem. You are given both inscriptions that hung over the front door the previous night, and a pile of letters that were found at the front door next morning.
The input file consists of three lines: the first line contains the guest's name, the second line contains the name of the residence host and the third line contains letters in a pile that were found at the door in the morning. All lines are not empty and contain only uppercase Latin letters. The length of each line does not exceed 100.
Print "YES" without the quotes, if the letters in the pile could be permuted to make the names of the "New Year and Christmas Men". Otherwise, print "NO" without the quotes.
[ "SANTACLAUS\nDEDMOROZ\nSANTAMOROZDEDCLAUS\n", "PAPAINOEL\nJOULUPUKKI\nJOULNAPAOILELUPUKKI\n", "BABBONATALE\nFATHERCHRISTMAS\nBABCHRISTMASBONATALLEFATHER\n" ]
[ "YES\n", "NO\n", "NO\n" ]
In the first sample the letters written in the last line can be used to write the names and there won't be any extra letters left. In the second sample letter "P" is missing from the pile and there's an extra letter "L". In the third sample there's an extra letter "L".
500
[ { "input": "SANTACLAUS\nDEDMOROZ\nSANTAMOROZDEDCLAUS", "output": "YES" }, { "input": "PAPAINOEL\nJOULUPUKKI\nJOULNAPAOILELUPUKKI", "output": "NO" }, { "input": "BABBONATALE\nFATHERCHRISTMAS\nBABCHRISTMASBONATALLEFATHER", "output": "NO" }, { "input": "B\nA\nAB", "output": ...
1,699,192,371
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
42
92
0
a=input() b=input() l=[] for i in(a,b): l.extend(i) l=sorted(l) c=input() m=list(c) m=sorted(m) for i in range(len(m)): if m[i]!=l[i]: print("NO") break else: print("YES")
Title: Amusing Joke Time Limit: None seconds Memory Limit: None megabytes Problem Description: So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's name and the host's name in honor of this event. Then the hung the letters above the main entrance. One night, when everyone went to bed, someone took all the letters of our characters' names. Then he may have shuffled the letters and put them in one pile in front of the door. The next morning it was impossible to find the culprit who had made the disorder. But everybody wondered whether it is possible to restore the names of the host and his guests from the letters lying at the door? That is, we need to verify that there are no extra letters, and that nobody will need to cut more letters. Help the "New Year and Christmas Men" and their friends to cope with this problem. You are given both inscriptions that hung over the front door the previous night, and a pile of letters that were found at the front door next morning. Input Specification: The input file consists of three lines: the first line contains the guest's name, the second line contains the name of the residence host and the third line contains letters in a pile that were found at the door in the morning. All lines are not empty and contain only uppercase Latin letters. The length of each line does not exceed 100. Output Specification: Print "YES" without the quotes, if the letters in the pile could be permuted to make the names of the "New Year and Christmas Men". Otherwise, print "NO" without the quotes. Demo Input: ['SANTACLAUS\nDEDMOROZ\nSANTAMOROZDEDCLAUS\n', 'PAPAINOEL\nJOULUPUKKI\nJOULNAPAOILELUPUKKI\n', 'BABBONATALE\nFATHERCHRISTMAS\nBABCHRISTMASBONATALLEFATHER\n'] Demo Output: ['YES\n', 'NO\n', 'NO\n'] Note: In the first sample the letters written in the last line can be used to write the names and there won't be any extra letters left. In the second sample letter "P" is missing from the pile and there's an extra letter "L". In the third sample there's an extra letter "L".
```python a=input() b=input() l=[] for i in(a,b): l.extend(i) l=sorted(l) c=input() m=list(c) m=sorted(m) for i in range(len(m)): if m[i]!=l[i]: print("NO") break else: print("YES") ```
0
986
D
Perfect Encoding
PROGRAMMING
3,100
[ "fft", "math" ]
null
null
You are working as an analyst in a company working on a new system for big data storage. This system will store $n$ different objects. Each object should have a unique ID. To create the system, you choose the parameters of the system — integers $m \ge 1$ and $b_{1}, b_{2}, \ldots, b_{m}$. With these parameters an ID of some object in the system is an array of integers $[a_{1}, a_{2}, \ldots, a_{m}]$ where $1 \le a_{i} \le b_{i}$ holds for every $1 \le i \le m$. Developers say that production costs are proportional to $\sum_{i=1}^{m} b_{i}$. You are asked to choose parameters $m$ and $b_{i}$ so that the system will be able to assign unique IDs to $n$ different objects and production costs are minimized. Note that you don't have to use all available IDs.
In the only line of input there is one positive integer $n$. The length of the decimal representation of $n$ is no greater than $1.5 \cdot 10^{6}$. The integer does not contain leading zeros.
Print one number — minimal value of $\sum_{i=1}^{m} b_{i}$.
[ "36\n", "37\n", "12345678901234567890123456789\n" ]
[ "10\n", "11\n", "177\n" ]
none
2,500
[ { "input": "36", "output": "10" }, { "input": "37", "output": "11" }, { "input": "12345678901234567890123456789", "output": "177" }, { "input": "1", "output": "1" }, { "input": "2", "output": "2" }, { "input": "3", "output": "3" }, { "input...
1,527,688,948
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int N=2.1e6+10,p=998244353; int inc(int x,int y){x+=y;return x>=p?x-p:x;} int dec(int x,int y){x-=y;return x<0?x+p:x;} int mul(int x,int y){return (ll)x*y%p;} int power(int x,int y){ int ans=1; for (;y;y>>=1,x=mul(x,x)) if (y&1) ans=mul(ans,x); return ans; } int w[N],iw[N]; void init(int n){ w[0]=1;w[1]=power(3,(p-1)/n); for (int i=2;i<=n;i++) w[i]=mul(w[i-1],w[1]); for (int i=0;i<=n;i++) iw[i]=w[n-i]; } void fft(int n,int *a,int *w){ for (int i=0,j=0;i<n;i++){ if (i<j) swap(a[i],a[j]); for (int k=n>>1;(j^=k)<k;k>>=1); } for (int i=2;i<=n;i<<=1){ int m=i>>1,s=n/i; for (int j=0;j<n;j+=i) for (int k=0,p=0;k<m;k++,p+=s){ int t=mul(a[j+k+m],w[p]); a[j+k+m]=dec(a[j+k],t); a[j+k]=inc(a[j+k],t); } } if (w==iw){ int del=power(n,p-2); for (int i=0;i<n;i++) a[i]=mul(a[i],del); } } vector<int> multiply(vector<int> &a,vector<int> &b){ int maxlen=a.size()+b.size(),size=1; while (size<maxlen) size<<=1; init(size); static int A[N],B[N],C[N]; memcpy(A,a.data(),a.size()<<2); memset(A+a.size(),0,(size-a.size())<<2); memcpy(B,b.data(),b.size()<<2); memset(B+b.size(),0,(size-b.size())<<2); fft(size,A,w);fft(size,B,w); for (int i=0;i<size;i++) C[i]=mul(A[i],B[i]); fft(size,C,iw); for (int i=0;i<size;i++) C[i+1]+=C[i]/10,C[i]%=10; int len=size; while (!C[len]) len--; vector<int> c(len+1); memcpy(c.data(),C,(len+1)<<2); return c; } vector<int> power(int y){ vector<int> ans(1,1),x(1,3); while (1){ if (y&1) ans=multiply(ans,x); y>>=1; if (!y) break; x=multiply(x,x); } return ans; } char str[N]; int A[N],B[N]; void multiply(int *a,int b,int *c){ for (int i=0,inc=0;i<=1500000;i++){ c[i]=a[i]*b+inc; inc=c[i]/10; c[i]%=10; } } bool comp(int *a){ for (int i=N-1;i>=0;i--) if (a[i]!=str[i]) return a[i]>str[i]; return 1; } int main() { // freopen("a.txt","r",stdin); scanf("%s",str); int len=strlen(str); if (len==1&&str[0]=='1') return puts("1"),0; reverse(str,str+len); for (int i=0;i<len;i++) str[i]-='0'; int pw=(len-1)*log(10)/log(3); pw=max(pw-2,0); vector<int> Pw=power(pw); memcpy(A,Pw.data(),Pw.size()<<2); while (1){ multiply(A,4,B); if (comp(B)) break; pw++; multiply(A,3,A); } int ans=1e9; ans=min(ans,3*pw+4); while (1){ multiply(A,2,B); if (comp(B)) break; pw++; multiply(A,3,A); } ans=min(ans,3*pw+2); while (1){ if (comp(A)) break; pw++; multiply(A,3,A); } ans=min(ans,pw*3); printf("%d\n",ans); return 0; }
Title: Perfect Encoding Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are working as an analyst in a company working on a new system for big data storage. This system will store $n$ different objects. Each object should have a unique ID. To create the system, you choose the parameters of the system — integers $m \ge 1$ and $b_{1}, b_{2}, \ldots, b_{m}$. With these parameters an ID of some object in the system is an array of integers $[a_{1}, a_{2}, \ldots, a_{m}]$ where $1 \le a_{i} \le b_{i}$ holds for every $1 \le i \le m$. Developers say that production costs are proportional to $\sum_{i=1}^{m} b_{i}$. You are asked to choose parameters $m$ and $b_{i}$ so that the system will be able to assign unique IDs to $n$ different objects and production costs are minimized. Note that you don't have to use all available IDs. Input Specification: In the only line of input there is one positive integer $n$. The length of the decimal representation of $n$ is no greater than $1.5 \cdot 10^{6}$. The integer does not contain leading zeros. Output Specification: Print one number — minimal value of $\sum_{i=1}^{m} b_{i}$. Demo Input: ['36\n', '37\n', '12345678901234567890123456789\n'] Demo Output: ['10\n', '11\n', '177\n'] Note: none
```python #include<bits/stdc++.h> using namespace std; typedef long long ll; const int N=2.1e6+10,p=998244353; int inc(int x,int y){x+=y;return x>=p?x-p:x;} int dec(int x,int y){x-=y;return x<0?x+p:x;} int mul(int x,int y){return (ll)x*y%p;} int power(int x,int y){ int ans=1; for (;y;y>>=1,x=mul(x,x)) if (y&1) ans=mul(ans,x); return ans; } int w[N],iw[N]; void init(int n){ w[0]=1;w[1]=power(3,(p-1)/n); for (int i=2;i<=n;i++) w[i]=mul(w[i-1],w[1]); for (int i=0;i<=n;i++) iw[i]=w[n-i]; } void fft(int n,int *a,int *w){ for (int i=0,j=0;i<n;i++){ if (i<j) swap(a[i],a[j]); for (int k=n>>1;(j^=k)<k;k>>=1); } for (int i=2;i<=n;i<<=1){ int m=i>>1,s=n/i; for (int j=0;j<n;j+=i) for (int k=0,p=0;k<m;k++,p+=s){ int t=mul(a[j+k+m],w[p]); a[j+k+m]=dec(a[j+k],t); a[j+k]=inc(a[j+k],t); } } if (w==iw){ int del=power(n,p-2); for (int i=0;i<n;i++) a[i]=mul(a[i],del); } } vector<int> multiply(vector<int> &a,vector<int> &b){ int maxlen=a.size()+b.size(),size=1; while (size<maxlen) size<<=1; init(size); static int A[N],B[N],C[N]; memcpy(A,a.data(),a.size()<<2); memset(A+a.size(),0,(size-a.size())<<2); memcpy(B,b.data(),b.size()<<2); memset(B+b.size(),0,(size-b.size())<<2); fft(size,A,w);fft(size,B,w); for (int i=0;i<size;i++) C[i]=mul(A[i],B[i]); fft(size,C,iw); for (int i=0;i<size;i++) C[i+1]+=C[i]/10,C[i]%=10; int len=size; while (!C[len]) len--; vector<int> c(len+1); memcpy(c.data(),C,(len+1)<<2); return c; } vector<int> power(int y){ vector<int> ans(1,1),x(1,3); while (1){ if (y&1) ans=multiply(ans,x); y>>=1; if (!y) break; x=multiply(x,x); } return ans; } char str[N]; int A[N],B[N]; void multiply(int *a,int b,int *c){ for (int i=0,inc=0;i<=1500000;i++){ c[i]=a[i]*b+inc; inc=c[i]/10; c[i]%=10; } } bool comp(int *a){ for (int i=N-1;i>=0;i--) if (a[i]!=str[i]) return a[i]>str[i]; return 1; } int main() { // freopen("a.txt","r",stdin); scanf("%s",str); int len=strlen(str); if (len==1&&str[0]=='1') return puts("1"),0; reverse(str,str+len); for (int i=0;i<len;i++) str[i]-='0'; int pw=(len-1)*log(10)/log(3); pw=max(pw-2,0); vector<int> Pw=power(pw); memcpy(A,Pw.data(),Pw.size()<<2); while (1){ multiply(A,4,B); if (comp(B)) break; pw++; multiply(A,3,A); } int ans=1e9; ans=min(ans,3*pw+4); while (1){ multiply(A,2,B); if (comp(B)) break; pw++; multiply(A,3,A); } ans=min(ans,3*pw+2); while (1){ if (comp(A)) break; pw++; multiply(A,3,A); } ans=min(ans,pw*3); printf("%d\n",ans); return 0; } ```
-1
110
A
Nearly Lucky Number
PROGRAMMING
800
[ "implementation" ]
A. Nearly Lucky Number
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. Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky digits in it is a lucky number. He wonders whether number *n* is a nearly lucky number.
The only line contains an integer *n* (1<=≤<=*n*<=≤<=1018). Please do not use the %lld specificator to read or write 64-bit numbers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.
Print on the single line "YES" if *n* is a nearly lucky number. Otherwise, print "NO" (without the quotes).
[ "40047\n", "7747774\n", "1000000000000000000\n" ]
[ "NO\n", "YES\n", "NO\n" ]
In the first sample there are 3 lucky digits (first one and last two), so the answer is "NO". In the second sample there are 7 lucky digits, 7 is lucky number, so the answer is "YES". In the third sample there are no lucky digits, so the answer is "NO".
500
[ { "input": "40047", "output": "NO" }, { "input": "7747774", "output": "YES" }, { "input": "1000000000000000000", "output": "NO" }, { "input": "7", "output": "NO" }, { "input": "4", "output": "NO" }, { "input": "474404774", "output": "NO" }, { ...
1,695,136,842
2,147,483,647
Python 3
OK
TESTS
34
92
0
def is_lucky_digit(digit): return digit == '4' or digit == '7' def is_lucky_number(number): return all(is_lucky_digit(digit) for digit in number) def is_nearly_lucky_number(n): lucky_digit_count = 0 while n > 0: digit = n % 10 if is_lucky_digit(str(digit)): lucky_digit_count += 1 n //= 10 return is_lucky_number(str(lucky_digit_count)) # Read input n = int(input()) # Check if n is a nearly lucky number if is_nearly_lucky_number(n): print("YES") else: print("NO")
Title: Nearly Lucky Number 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. Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky digits in it is a lucky number. He wonders whether number *n* is a nearly lucky number. Input Specification: The only line contains an integer *n* (1<=≤<=*n*<=≤<=1018). Please do not use the %lld specificator to read or write 64-bit numbers in С++. It is preferred to use the cin, cout streams or the %I64d specificator. Output Specification: Print on the single line "YES" if *n* is a nearly lucky number. Otherwise, print "NO" (without the quotes). Demo Input: ['40047\n', '7747774\n', '1000000000000000000\n'] Demo Output: ['NO\n', 'YES\n', 'NO\n'] Note: In the first sample there are 3 lucky digits (first one and last two), so the answer is "NO". In the second sample there are 7 lucky digits, 7 is lucky number, so the answer is "YES". In the third sample there are no lucky digits, so the answer is "NO".
```python def is_lucky_digit(digit): return digit == '4' or digit == '7' def is_lucky_number(number): return all(is_lucky_digit(digit) for digit in number) def is_nearly_lucky_number(n): lucky_digit_count = 0 while n > 0: digit = n % 10 if is_lucky_digit(str(digit)): lucky_digit_count += 1 n //= 10 return is_lucky_number(str(lucky_digit_count)) # Read input n = int(input()) # Check if n is a nearly lucky number if is_nearly_lucky_number(n): print("YES") else: print("NO") ```
3.977
2
A
Winner
PROGRAMMING
1,500
[ "hashing", "implementation" ]
A. Winner
1
64
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a player gains or loses a particular number of points. In the course of the game the number of points is registered in the line "name score", where name is a player's name, and score is the number of points gained in this round, which is an integer number. If score is negative, this means that the player has lost in the round. So, if two or more players have the maximum number of points (say, it equals to *m*) at the end of the game, than wins the one of them who scored at least *m* points first. Initially each player has 0 points. It's guaranteed that at the end of the game at least one player has a positive number of points.
The first line contains an integer number *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000), *n* is the number of rounds played. Then follow *n* lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is an integer number between -1000 and 1000, inclusive.
Print the name of the winner.
[ "3\nmike 3\nandrew 5\nmike 2\n", "3\nandrew 3\nandrew 2\nmike 5\n" ]
[ "andrew\n", "andrew\n" ]
none
0
[ { "input": "3\nmike 3\nandrew 5\nmike 2", "output": "andrew" }, { "input": "3\nandrew 3\nandrew 2\nmike 5", "output": "andrew" }, { "input": "5\nkaxqybeultn -352\nmgochgrmeyieyskhuourfg -910\nkaxqybeultn 691\nmgochgrmeyieyskhuourfg -76\nkaxqybeultn -303", "output": "kaxqybeultn" },...
1,561,690,682
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
2
186
0
n=int(input()) d={} ma=0 re='' while n>0: m,s=input().split() s=int(s) if m in d and s>0: d[m]=d.get(m)+s elif m not in d and s>0: d[m]=s if d.get(m)>ma: ma=d.get(m) re=m n=n-1 print(re)
Title: Winner Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a player gains or loses a particular number of points. In the course of the game the number of points is registered in the line "name score", where name is a player's name, and score is the number of points gained in this round, which is an integer number. If score is negative, this means that the player has lost in the round. So, if two or more players have the maximum number of points (say, it equals to *m*) at the end of the game, than wins the one of them who scored at least *m* points first. Initially each player has 0 points. It's guaranteed that at the end of the game at least one player has a positive number of points. Input Specification: The first line contains an integer number *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000), *n* is the number of rounds played. Then follow *n* lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is an integer number between -1000 and 1000, inclusive. Output Specification: Print the name of the winner. Demo Input: ['3\nmike 3\nandrew 5\nmike 2\n', '3\nandrew 3\nandrew 2\nmike 5\n'] Demo Output: ['andrew\n', 'andrew\n'] Note: none
```python n=int(input()) d={} ma=0 re='' while n>0: m,s=input().split() s=int(s) if m in d and s>0: d[m]=d.get(m)+s elif m not in d and s>0: d[m]=s if d.get(m)>ma: ma=d.get(m) re=m n=n-1 print(re) ```
-1
378
A
Playing with Dice
PROGRAMMING
800
[ "brute force" ]
null
null
Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same difference, it's a draw. The first player wrote number *a*, the second player wrote number *b*. How many ways to throw a dice are there, at which the first player wins, or there is a draw, or the second player wins?
The single line contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=6) — the numbers written on the paper by the first and second player, correspondingly.
Print three integers: the number of ways to throw the dice at which the first player wins, the game ends with a draw or the second player wins, correspondingly.
[ "2 5\n", "2 4\n" ]
[ "3 0 3\n", "2 1 3\n" ]
The dice is a standard cube-shaped six-sided object with each side containing a number from 1 to 6, and where all numbers on all sides are distinct. You can assume that number *a* is closer to number *x* than number *b*, if |*a* - *x*| &lt; |*b* - *x*|.
500
[ { "input": "2 5", "output": "3 0 3" }, { "input": "2 4", "output": "2 1 3" }, { "input": "5 3", "output": "2 1 3" }, { "input": "1 6", "output": "3 0 3" }, { "input": "5 1", "output": "3 1 2" }, { "input": "6 3", "output": "2 0 4" }, { "inp...
1,681,385,079
2,147,483,647
Python 3
OK
TESTS
38
46
0
a,b=input().split() a1=0 a2=0 a3=0 a=int(a) b=int(b) for i in range(1,7): if(abs(a-i)<abs(b-i)): a1+=1 elif(abs(b-i)<abs(a-i)): a2+=1 elif(abs(b-i)==abs(a-i)): a3+=1 print(str(a1)+" "+str(a3)+" "+str(a2))
Title: Playing with Dice Time Limit: None seconds Memory Limit: None megabytes Problem Description: Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same difference, it's a draw. The first player wrote number *a*, the second player wrote number *b*. How many ways to throw a dice are there, at which the first player wins, or there is a draw, or the second player wins? Input Specification: The single line contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=6) — the numbers written on the paper by the first and second player, correspondingly. Output Specification: Print three integers: the number of ways to throw the dice at which the first player wins, the game ends with a draw or the second player wins, correspondingly. Demo Input: ['2 5\n', '2 4\n'] Demo Output: ['3 0 3\n', '2 1 3\n'] Note: The dice is a standard cube-shaped six-sided object with each side containing a number from 1 to 6, and where all numbers on all sides are distinct. You can assume that number *a* is closer to number *x* than number *b*, if |*a* - *x*| &lt; |*b* - *x*|.
```python a,b=input().split() a1=0 a2=0 a3=0 a=int(a) b=int(b) for i in range(1,7): if(abs(a-i)<abs(b-i)): a1+=1 elif(abs(b-i)<abs(a-i)): a2+=1 elif(abs(b-i)==abs(a-i)): a3+=1 print(str(a1)+" "+str(a3)+" "+str(a2)) ```
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 is different in evenness.
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,657,634,388
2,147,483,647
PyPy 3-64
OK
TESTS
32
124
0
n=int(input()) c1,c2,k,k1=0,0,0,0 a=list(map(int,input().split())) for i in range(n): if a[i]%2==0: c1=a[i] k+=1 else: c2=a[i] k1+=1 if k==1: print(a.index(c1)+1) else: print(a.index(c2)+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 — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness. Input Specification: 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 Specification: Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. Demo Input: ['5\n2 4 7 8 10\n', '4\n1 2 1 1\n'] Demo Output: ['3\n', '2\n'] Note: none
```python n=int(input()) c1,c2,k,k1=0,0,0,0 a=list(map(int,input().split())) for i in range(n): if a[i]%2==0: c1=a[i] k+=1 else: c2=a[i] k1+=1 if k==1: print(a.index(c1)+1) else: print(a.index(c2)+1) ```
3.969
429
B
Working out
PROGRAMMING
1,600
[ "dp" ]
null
null
Summer is coming! It's time for Iahub and Iahubina to work out, as they both want to look hot at the beach. The gym where they go is a matrix *a* with *n* lines and *m* columns. Let number *a*[*i*][*j*] represents the calories burned by performing workout at the cell of gym in the *i*-th line and the *j*-th column. Iahub starts with workout located at line 1 and column 1. He needs to finish with workout *a*[*n*][*m*]. After finishing workout *a*[*i*][*j*], he can go to workout *a*[*i*<=+<=1][*j*] or *a*[*i*][*j*<=+<=1]. Similarly, Iahubina starts with workout *a*[*n*][1] and she needs to finish with workout *a*[1][*m*]. After finishing workout from cell *a*[*i*][*j*], she goes to either *a*[*i*][*j*<=+<=1] or *a*[*i*<=-<=1][*j*]. There is one additional condition for their training. They have to meet in exactly one cell of gym. At that cell, none of them will work out. They will talk about fast exponentiation (pretty odd small talk) and then both of them will move to the next workout. If a workout was done by either Iahub or Iahubina, it counts as total gain. Please plan a workout for Iahub and Iahubina such as total gain to be as big as possible. Note, that Iahub and Iahubina can perform workouts with different speed, so the number of cells that they use to reach meet cell may differs.
The first line of the input contains two integers *n* and *m* (3<=≤<=*n*,<=*m*<=≤<=1000). Each of the next *n* lines contains *m* integers: *j*-th number from *i*-th line denotes element *a*[*i*][*j*] (0<=≤<=*a*[*i*][*j*]<=≤<=105).
The output contains a single number — the maximum total gain possible.
[ "3 3\n100 100 100\n100 1 100\n100 100 100\n" ]
[ "800" ]
Iahub will choose exercises *a*[1][1] → *a*[1][2] → *a*[2][2] → *a*[3][2] → *a*[3][3]. Iahubina will choose exercises *a*[3][1] → *a*[2][1] → *a*[2][2] → *a*[2][3] → *a*[1][3].
1,000
[ { "input": "3 3\n100 100 100\n100 1 100\n100 100 100", "output": "800" }, { "input": "4 5\n87882 40786 3691 85313 46694\n28884 16067 3242 97367 78518\n4250 35501 9780 14435 19004\n64673 65438 56977 64495 27280", "output": "747898" }, { "input": "3 3\n3 1 2\n3 2 0\n2 3 2", "output": "...
1,618,551,177
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
1
93
0
n,m=map(int,input().split()) a=[list(map(int,input().split())) for i in range(n)] d1=[[0]*m for i in range(n)] for i in range(n): for j in range(m): if i==j==0: d1[i][j]=a[i][j] elif i==0: d1[i][j]=d1[i][j-1]+a[i][j] elif j==0: d1[i][j]=d1[i-1][j]+a[i][j] else: d1[i][j]=max(d1[i-1][j],d1[i][j-1])+a[i][j] d2=[[0]*m for i in range(n)] b=[[a[n-1-i][m-1-j] for j in range(m)] for i in range(n)] for i in range(n): for j in range(m): if i==j==0: d2[i][j]=b[i][j] elif i==0: d2[i][j]=d2[i][j-1]+b[i][j] elif j==0: d2[i][j]=d1[i-1][j]+b[i][j] else: d2[i][j]=max(d2[i-1][j],d2[i][j-1])+b[i][j] d3=[[0]*m for i in range(n)] c=[[a[n-1-i][j] for j in range(m)] for i in range(n)] for i in range(n): for j in range(m): if i==j==0: d3[i][j]=c[i][j] elif i==0: d3[i][j]=d3[i][j-1]+c[i][j] elif j==0: d3[i][j]=d3[i-1][j]+c[i][j] else: d3[i][j]=max(d3[i-1][j],d3[i][j-1])+c[i][j] d4=[[0]*m for i in range(n)] e=[[a[i][m-1-j] for j in range(m)] for i in range(n)] for i in range(n): for j in range(m): if i==j==0: d4[i][j]=e[i][j] elif i==0: d4[i][j]=d4[i][j-1]+e[i][j] elif j==0: d4[i][j]=d4[i-1][j]+e[i][j] else: d4[i][j]=max(d4[i-1][j],d4[i][j-1])+e[i][j] ans=-1 for i in range(n): for j in range(m): x=d1[i][j]+d2[n-1-i][m-1-j] y=d3[n-1-i][j]+d4[i][m-1-j] ans=max(ans,x+y-4*a[i][j]) print(ans)
Title: Working out Time Limit: None seconds Memory Limit: None megabytes Problem Description: Summer is coming! It's time for Iahub and Iahubina to work out, as they both want to look hot at the beach. The gym where they go is a matrix *a* with *n* lines and *m* columns. Let number *a*[*i*][*j*] represents the calories burned by performing workout at the cell of gym in the *i*-th line and the *j*-th column. Iahub starts with workout located at line 1 and column 1. He needs to finish with workout *a*[*n*][*m*]. After finishing workout *a*[*i*][*j*], he can go to workout *a*[*i*<=+<=1][*j*] or *a*[*i*][*j*<=+<=1]. Similarly, Iahubina starts with workout *a*[*n*][1] and she needs to finish with workout *a*[1][*m*]. After finishing workout from cell *a*[*i*][*j*], she goes to either *a*[*i*][*j*<=+<=1] or *a*[*i*<=-<=1][*j*]. There is one additional condition for their training. They have to meet in exactly one cell of gym. At that cell, none of them will work out. They will talk about fast exponentiation (pretty odd small talk) and then both of them will move to the next workout. If a workout was done by either Iahub or Iahubina, it counts as total gain. Please plan a workout for Iahub and Iahubina such as total gain to be as big as possible. Note, that Iahub and Iahubina can perform workouts with different speed, so the number of cells that they use to reach meet cell may differs. Input Specification: The first line of the input contains two integers *n* and *m* (3<=≤<=*n*,<=*m*<=≤<=1000). Each of the next *n* lines contains *m* integers: *j*-th number from *i*-th line denotes element *a*[*i*][*j*] (0<=≤<=*a*[*i*][*j*]<=≤<=105). Output Specification: The output contains a single number — the maximum total gain possible. Demo Input: ['3 3\n100 100 100\n100 1 100\n100 100 100\n'] Demo Output: ['800'] Note: Iahub will choose exercises *a*[1][1] → *a*[1][2] → *a*[2][2] → *a*[3][2] → *a*[3][3]. Iahubina will choose exercises *a*[3][1] → *a*[2][1] → *a*[2][2] → *a*[2][3] → *a*[1][3].
```python n,m=map(int,input().split()) a=[list(map(int,input().split())) for i in range(n)] d1=[[0]*m for i in range(n)] for i in range(n): for j in range(m): if i==j==0: d1[i][j]=a[i][j] elif i==0: d1[i][j]=d1[i][j-1]+a[i][j] elif j==0: d1[i][j]=d1[i-1][j]+a[i][j] else: d1[i][j]=max(d1[i-1][j],d1[i][j-1])+a[i][j] d2=[[0]*m for i in range(n)] b=[[a[n-1-i][m-1-j] for j in range(m)] for i in range(n)] for i in range(n): for j in range(m): if i==j==0: d2[i][j]=b[i][j] elif i==0: d2[i][j]=d2[i][j-1]+b[i][j] elif j==0: d2[i][j]=d1[i-1][j]+b[i][j] else: d2[i][j]=max(d2[i-1][j],d2[i][j-1])+b[i][j] d3=[[0]*m for i in range(n)] c=[[a[n-1-i][j] for j in range(m)] for i in range(n)] for i in range(n): for j in range(m): if i==j==0: d3[i][j]=c[i][j] elif i==0: d3[i][j]=d3[i][j-1]+c[i][j] elif j==0: d3[i][j]=d3[i-1][j]+c[i][j] else: d3[i][j]=max(d3[i-1][j],d3[i][j-1])+c[i][j] d4=[[0]*m for i in range(n)] e=[[a[i][m-1-j] for j in range(m)] for i in range(n)] for i in range(n): for j in range(m): if i==j==0: d4[i][j]=e[i][j] elif i==0: d4[i][j]=d4[i][j-1]+e[i][j] elif j==0: d4[i][j]=d4[i-1][j]+e[i][j] else: d4[i][j]=max(d4[i-1][j],d4[i][j-1])+e[i][j] ans=-1 for i in range(n): for j in range(m): x=d1[i][j]+d2[n-1-i][m-1-j] y=d3[n-1-i][j]+d4[i][m-1-j] ans=max(ans,x+y-4*a[i][j]) print(ans) ```
0
538
B
Quasi Binary
PROGRAMMING
1,400
[ "constructive algorithms", "dp", "greedy", "implementation" ]
null
null
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not. You are given a positive integer *n*. Represent it as a sum of minimum number of quasibinary numbers.
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=106).
In the first line print a single integer *k* — the minimum number of numbers in the representation of number *n* as a sum of quasibinary numbers. In the second line print *k* numbers — the elements of the sum. All these numbers should be quasibinary according to the definition above, their sum should equal *n*. Do not have to print the leading zeroes in the numbers. The order of numbers doesn't matter. If there are multiple possible representations, you are allowed to print any of them.
[ "9\n", "32\n" ]
[ "9\n1 1 1 1 1 1 1 1 1 \n", "3\n10 11 11 \n" ]
none
1,000
[ { "input": "9", "output": "9\n1 1 1 1 1 1 1 1 1 " }, { "input": "32", "output": "3\n10 11 11 " }, { "input": "1", "output": "1\n1 " }, { "input": "415", "output": "5\n1 101 101 101 111 " }, { "input": "10011", "output": "1\n10011 " }, { "input": "10201...
1,642,759,281
2,147,483,647
Python 3
OK
TESTS
25
46
0
num = int(input().strip()) print(max(int(x) for x in str(num))) while num > 0: req_num = int("".join("1" if int(x) >= 1 else "0" for x in str(num))) num -= req_num print(req_num,end=" ")
Title: Quasi Binary Time Limit: None seconds Memory Limit: None megabytes Problem Description: A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not. You are given a positive integer *n*. Represent it as a sum of minimum number of quasibinary numbers. Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=106). Output Specification: In the first line print a single integer *k* — the minimum number of numbers in the representation of number *n* as a sum of quasibinary numbers. In the second line print *k* numbers — the elements of the sum. All these numbers should be quasibinary according to the definition above, their sum should equal *n*. Do not have to print the leading zeroes in the numbers. The order of numbers doesn't matter. If there are multiple possible representations, you are allowed to print any of them. Demo Input: ['9\n', '32\n'] Demo Output: ['9\n1 1 1 1 1 1 1 1 1 \n', '3\n10 11 11 \n'] Note: none
```python num = int(input().strip()) print(max(int(x) for x in str(num))) while num > 0: req_num = int("".join("1" if int(x) >= 1 else "0" for x in str(num))) num -= req_num print(req_num,end=" ") ```
3
996
A
Hit the Lottery
PROGRAMMING
800
[ "dp", "greedy" ]
null
null
Allen has a LOT of money. He has $n$ dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are $1$, $5$, $10$, $20$, $100$. What is the minimum number of bills Allen could receive after withdrawing his entire balance?
The first and only line of input contains a single integer $n$ ($1 \le n \le 10^9$).
Output the minimum number of bills that Allen could receive.
[ "125\n", "43\n", "1000000000\n" ]
[ "3\n", "5\n", "10000000\n" ]
In the first sample case, Allen can withdraw this with a $100$ dollar bill, a $20$ dollar bill, and a $5$ dollar bill. There is no way for Allen to receive $125$ dollars in one or two bills. In the second sample case, Allen can withdraw two $20$ dollar bills and three $1$ dollar bills. In the third sample case, Allen can withdraw $100000000$ (ten million!) $100$ dollar bills.
500
[ { "input": "125", "output": "3" }, { "input": "43", "output": "5" }, { "input": "1000000000", "output": "10000000" }, { "input": "4", "output": "4" }, { "input": "5", "output": "1" }, { "input": "1", "output": "1" }, { "input": "74", "o...
1,693,985,662
2,147,483,647
Python 3
OK
TESTS
49
61
0
n = int(input()) k = 0 s =[100,20,10,5,1] for i in s: k+=n//i n%=i print(k)
Title: Hit the Lottery Time Limit: None seconds Memory Limit: None megabytes Problem Description: Allen has a LOT of money. He has $n$ dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are $1$, $5$, $10$, $20$, $100$. What is the minimum number of bills Allen could receive after withdrawing his entire balance? Input Specification: The first and only line of input contains a single integer $n$ ($1 \le n \le 10^9$). Output Specification: Output the minimum number of bills that Allen could receive. Demo Input: ['125\n', '43\n', '1000000000\n'] Demo Output: ['3\n', '5\n', '10000000\n'] Note: In the first sample case, Allen can withdraw this with a $100$ dollar bill, a $20$ dollar bill, and a $5$ dollar bill. There is no way for Allen to receive $125$ dollars in one or two bills. In the second sample case, Allen can withdraw two $20$ dollar bills and three $1$ dollar bills. In the third sample case, Allen can withdraw $100000000$ (ten million!) $100$ dollar bills.
```python n = int(input()) k = 0 s =[100,20,10,5,1] for i in s: k+=n//i n%=i print(k) ```
3
801
B
Valued Keys
PROGRAMMING
900
[ "constructive algorithms", "greedy", "strings" ]
null
null
You found a mysterious function *f*. The function takes two strings *s*1 and *s*2. These strings must consist only of lowercase English letters, and must be the same length. The output of the function *f* is another string of the same length. The *i*-th character of the output is equal to the minimum of the *i*-th character of *s*1 and the *i*-th character of *s*2. For example, *f*("ab", "ba") = "aa", and *f*("nzwzl", "zizez") = "niwel". You found two strings *x* and *y* of the same length and consisting of only lowercase English letters. Find any string *z* such that *f*(*x*,<=*z*)<==<=*y*, or print -1 if no such string *z* exists.
The first line of input contains the string *x*. The second line of input contains the string *y*. Both *x* and *y* consist only of lowercase English letters, *x* and *y* have same length and this length is between 1 and 100.
If there is no string *z* such that *f*(*x*,<=*z*)<==<=*y*, print -1. Otherwise, print a string *z* such that *f*(*x*,<=*z*)<==<=*y*. If there are multiple possible answers, print any of them. The string *z* should be the same length as *x* and *y* and consist only of lowercase English letters.
[ "ab\naa\n", "nzwzl\nniwel\n", "ab\nba\n" ]
[ "ba\n", "xiyez\n", "-1\n" ]
The first case is from the statement. Another solution for the second case is "zizez" There is no solution for the third case. That is, there is no *z* such that *f*("ab", *z*) =  "ba".
1,000
[ { "input": "ab\naa", "output": "ba" }, { "input": "nzwzl\nniwel", "output": "xiyez" }, { "input": "ab\nba", "output": "-1" }, { "input": "r\nl", "output": "l" }, { "input": "d\ny", "output": "-1" }, { "input": "yvowz\ncajav", "output": "cajav" },...
1,693,606,541
2,147,483,647
PyPy 3-64
OK
TESTS
35
62
0
dic={"a":1,"b":2,"c": 3,"d": 4,"e": 5,"f": 6,"g": 7,"h": 8,"i": 9,"j": 10,"k": 12,"l": 13,"m": 14,"n": 15,"o": 16,"p": 17,"q": 18,"r": 19,"s": 20,"t": 21,"u": 22,"v": 23,"w": 24,"x": 25,"y": 26,"z":27} x=input() z=input() y="" for i in range(len(x)): if dic[x[i]]>dic[z[i]]: y+=z[i] elif dic[x[i]]==dic[z[i]]: y+="z" else: y=-1 break print(y)
Title: Valued Keys Time Limit: None seconds Memory Limit: None megabytes Problem Description: You found a mysterious function *f*. The function takes two strings *s*1 and *s*2. These strings must consist only of lowercase English letters, and must be the same length. The output of the function *f* is another string of the same length. The *i*-th character of the output is equal to the minimum of the *i*-th character of *s*1 and the *i*-th character of *s*2. For example, *f*("ab", "ba") = "aa", and *f*("nzwzl", "zizez") = "niwel". You found two strings *x* and *y* of the same length and consisting of only lowercase English letters. Find any string *z* such that *f*(*x*,<=*z*)<==<=*y*, or print -1 if no such string *z* exists. Input Specification: The first line of input contains the string *x*. The second line of input contains the string *y*. Both *x* and *y* consist only of lowercase English letters, *x* and *y* have same length and this length is between 1 and 100. Output Specification: If there is no string *z* such that *f*(*x*,<=*z*)<==<=*y*, print -1. Otherwise, print a string *z* such that *f*(*x*,<=*z*)<==<=*y*. If there are multiple possible answers, print any of them. The string *z* should be the same length as *x* and *y* and consist only of lowercase English letters. Demo Input: ['ab\naa\n', 'nzwzl\nniwel\n', 'ab\nba\n'] Demo Output: ['ba\n', 'xiyez\n', '-1\n'] Note: The first case is from the statement. Another solution for the second case is "zizez" There is no solution for the third case. That is, there is no *z* such that *f*("ab", *z*) =  "ba".
```python dic={"a":1,"b":2,"c": 3,"d": 4,"e": 5,"f": 6,"g": 7,"h": 8,"i": 9,"j": 10,"k": 12,"l": 13,"m": 14,"n": 15,"o": 16,"p": 17,"q": 18,"r": 19,"s": 20,"t": 21,"u": 22,"v": 23,"w": 24,"x": 25,"y": 26,"z":27} x=input() z=input() y="" for i in range(len(x)): if dic[x[i]]>dic[z[i]]: y+=z[i] elif dic[x[i]]==dic[z[i]]: y+="z" else: y=-1 break print(y) ```
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 is different in evenness.
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,568,455,918
2,147,483,647
Python 3
OK
TESTS
32
248
0
input() a = list(map(lambda n: int(n) % 2, input().split())) print(a.index(a.count(1) == 1) + 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 — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness. Input Specification: 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 Specification: Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. Demo Input: ['5\n2 4 7 8 10\n', '4\n1 2 1 1\n'] Demo Output: ['3\n', '2\n'] Note: none
```python input() a = list(map(lambda n: int(n) % 2, input().split())) print(a.index(a.count(1) == 1) + 1) ```
3.938
608
B
Hamming Distance Sum
PROGRAMMING
1,500
[ "combinatorics", "strings" ]
null
null
Genos needs your help. He was asked to solve the following programming problem by Saitama: The length of some string *s* is denoted |*s*|. The Hamming distance between two strings *s* and *t* of equal length is defined as , where *s**i* is the *i*-th character of *s* and *t**i* is the *i*-th character of *t*. For example, the Hamming distance between string "0011" and string "0110" is |0<=-<=0|<=+<=|0<=-<=1|<=+<=|1<=-<=1|<=+<=|1<=-<=0|<==<=0<=+<=1<=+<=0<=+<=1<==<=2. Given two binary strings *a* and *b*, find the sum of the Hamming distances between *a* and all contiguous substrings of *b* of length |*a*|.
The first line of the input contains binary string *a* (1<=≤<=|*a*|<=≤<=200<=000). The second line of the input contains binary string *b* (|*a*|<=≤<=|*b*|<=≤<=200<=000). Both strings are guaranteed to consist of characters '0' and '1' only.
Print a single integer — the sum of Hamming distances between *a* and all contiguous substrings of *b* of length |*a*|.
[ "01\n00111\n", "0011\n0110\n" ]
[ "3\n", "2\n" ]
For the first sample case, there are four contiguous substrings of *b* of length |*a*|: "00", "01", "11", and "11". The distance between "01" and "00" is |0 - 0| + |1 - 0| = 1. The distance between "01" and "01" is |0 - 0| + |1 - 1| = 0. The distance between "01" and "11" is |0 - 1| + |1 - 1| = 1. Last distance counts twice, as there are two occurrences of string "11". The sum of these edit distances is 1 + 0 + 1 + 1 = 3. The second sample case is described in the statement.
1,000
[ { "input": "01\n00111", "output": "3" }, { "input": "0011\n0110", "output": "2" }, { "input": "0\n0", "output": "0" }, { "input": "1\n0", "output": "1" }, { "input": "0\n1", "output": "1" }, { "input": "1\n1", "output": "0" }, { "input": "1...
1,651,487,227
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
8
2,000
1,126,400
x=input() y=input() sum,i=0,0 lx=len(x) while(i+lx<=len(y)): ans=int(x,2) ^ int(y[i:i+lx],2) ans=bin(ans)[2:].count('1') sum+=ans i+=1 print(sum)
Title: Hamming Distance Sum Time Limit: None seconds Memory Limit: None megabytes Problem Description: Genos needs your help. He was asked to solve the following programming problem by Saitama: The length of some string *s* is denoted |*s*|. The Hamming distance between two strings *s* and *t* of equal length is defined as , where *s**i* is the *i*-th character of *s* and *t**i* is the *i*-th character of *t*. For example, the Hamming distance between string "0011" and string "0110" is |0<=-<=0|<=+<=|0<=-<=1|<=+<=|1<=-<=1|<=+<=|1<=-<=0|<==<=0<=+<=1<=+<=0<=+<=1<==<=2. Given two binary strings *a* and *b*, find the sum of the Hamming distances between *a* and all contiguous substrings of *b* of length |*a*|. Input Specification: The first line of the input contains binary string *a* (1<=≤<=|*a*|<=≤<=200<=000). The second line of the input contains binary string *b* (|*a*|<=≤<=|*b*|<=≤<=200<=000). Both strings are guaranteed to consist of characters '0' and '1' only. Output Specification: Print a single integer — the sum of Hamming distances between *a* and all contiguous substrings of *b* of length |*a*|. Demo Input: ['01\n00111\n', '0011\n0110\n'] Demo Output: ['3\n', '2\n'] Note: For the first sample case, there are four contiguous substrings of *b* of length |*a*|: "00", "01", "11", and "11". The distance between "01" and "00" is |0 - 0| + |1 - 0| = 1. The distance between "01" and "01" is |0 - 0| + |1 - 1| = 0. The distance between "01" and "11" is |0 - 1| + |1 - 1| = 1. Last distance counts twice, as there are two occurrences of string "11". The sum of these edit distances is 1 + 0 + 1 + 1 = 3. The second sample case is described in the statement.
```python x=input() y=input() sum,i=0,0 lx=len(x) while(i+lx<=len(y)): ans=int(x,2) ^ int(y[i:i+lx],2) ans=bin(ans)[2:].count('1') sum+=ans i+=1 print(sum) ```
0
479
E
Riding in a Lift
PROGRAMMING
1,900
[ "combinatorics", "dp" ]
null
null
Imagine that you are in a building that has exactly *n* floors. You can move between the floors in a lift. Let's number the floors from bottom to top with integers from 1 to *n*. Now you're on the floor number *a*. You are very bored, so you want to take the lift. Floor number *b* has a secret lab, the entry is forbidden. However, you already are in the mood and decide to make *k* consecutive trips in the lift. Let us suppose that at the moment you are on the floor number *x* (initially, you were on floor *a*). For another trip between floors you choose some floor with number *y* (*y*<=≠<=*x*) and the lift travels to this floor. As you cannot visit floor *b* with the secret lab, you decided that the distance from the current floor *x* to the chosen *y* must be strictly less than the distance from the current floor *x* to floor *b* with the secret lab. Formally, it means that the following inequation must fulfill: |*x*<=-<=*y*|<=&lt;<=|*x*<=-<=*b*|. After the lift successfully transports you to floor *y*, you write down number *y* in your notepad. Your task is to find the number of distinct number sequences that you could have written in the notebook as the result of *k* trips in the lift. As the sought number of trips can be rather large, find the remainder after dividing the number by 1000000007 (109<=+<=7).
The first line of the input contains four space-separated integers *n*, *a*, *b*, *k* (2<=≤<=*n*<=≤<=5000, 1<=≤<=*k*<=≤<=5000, 1<=≤<=*a*,<=*b*<=≤<=*n*, *a*<=≠<=*b*).
Print a single integer — the remainder after dividing the sought number of sequences by 1000000007 (109<=+<=7).
[ "5 2 4 1\n", "5 2 4 2\n", "5 3 4 1\n" ]
[ "2\n", "2\n", "0\n" ]
Two sequences *p*<sub class="lower-index">1</sub>, *p*<sub class="lower-index">2</sub>, ..., *p*<sub class="lower-index">*k*</sub> and *q*<sub class="lower-index">1</sub>, *q*<sub class="lower-index">2</sub>, ..., *q*<sub class="lower-index">*k*</sub> are distinct, if there is such integer *j* (1 ≤ *j* ≤ *k*), that *p*<sub class="lower-index">*j*</sub> ≠ *q*<sub class="lower-index">*j*</sub>. Notes to the samples: 1. In the first sample after the first trip you are either on floor 1, or on floor 3, because |1 - 2| &lt; |2 - 4| and |3 - 2| &lt; |2 - 4|. 1. In the second sample there are two possible sequences: (1, 2); (1, 3). You cannot choose floor 3 for the first trip because in this case no floor can be the floor for the second trip. 1. In the third sample there are no sought sequences, because you cannot choose the floor for the first trip.
2,500
[ { "input": "5 2 4 1", "output": "2" }, { "input": "5 2 4 2", "output": "2" }, { "input": "5 3 4 1", "output": "0" }, { "input": "2 2 1 1", "output": "0" }, { "input": "10 1 10 2", "output": "44" }, { "input": "2222 1206 1425 2222", "output": "40257...
1,690,596,771
2,147,483,647
PyPy 3-64
TIME_LIMIT_EXCEEDED
TESTS
39
2,000
204,492,800
import sys input= lambda: sys.stdin.buffer.readline().decode('utf-8').rstrip('\r\n') from array import array inp= lambda: int(input()) mi = lambda x=int : map(x, input().split()) arr= lambda d='i',x=int: array(d,mi(x)) li = lambda x=int: list(mi(x)) lb = lambda: list(map(int, input())) ls = lambda: list(input()) bi = lambda n: bin(n).replace("0b", "") yn = ['No', 'Yes'] YN = ['NO', 'YES'] YY = "YES" NN = "NO" yy = "Yes" nn = "No" inf= sys.maxsize mod=998244353 alp='abcdefghijklmnopqrstuvwxyz' from itertools import accumulate as cml,permutations,combinations from collections import Counter as ctr, deque as dq,defaultdict as dd from bisect import bisect_left as bl,bisect_right as br from math import ceil, gcd, log, sqrt import heapq as hq mod=10**9+7 mod=1000000007 def main(kase): n,a,b,k=mi() dp=[[0]*(n+1) for i in range(k+1)] a-=1 b-=1 dp[0][a]=1 dp[0][a+1]=-1 # print(dp) for i in range(k): for j in range(1,n+1): dp[i][j]=(dp[i][j]+dp[i][j-1])%mod for j in range(n): d=abs(b-j) if d==0: continue elif dp[i][j]==0: continue dp[i+1][max(j-d+1,0)]=(dp[i+1][max(j-d+1,0)]+dp[i][j])%mod dp[i+1][j]=(dp[i+1][j]-dp[i][j])%mod dp[i+1][j+1]=(dp[i+1][j+1]+dp[i][j])%mod dp[i+1][min(j+d,n)]=(dp[i+1][min(j+d,n)]-dp[i][j])%mod ans=dp[k][0] for j in range(1,n+1): dp[k][j]=(dp[k][j]+dp[k][j-1])%mod ans=(ans+dp[k][j])%mod print(ans) # print(dp) pass if __name__ == "__main__": test_Cases=1 # test_Cases=inp() for i in range(test_Cases): main(i)
Title: Riding in a Lift Time Limit: None seconds Memory Limit: None megabytes Problem Description: Imagine that you are in a building that has exactly *n* floors. You can move between the floors in a lift. Let's number the floors from bottom to top with integers from 1 to *n*. Now you're on the floor number *a*. You are very bored, so you want to take the lift. Floor number *b* has a secret lab, the entry is forbidden. However, you already are in the mood and decide to make *k* consecutive trips in the lift. Let us suppose that at the moment you are on the floor number *x* (initially, you were on floor *a*). For another trip between floors you choose some floor with number *y* (*y*<=≠<=*x*) and the lift travels to this floor. As you cannot visit floor *b* with the secret lab, you decided that the distance from the current floor *x* to the chosen *y* must be strictly less than the distance from the current floor *x* to floor *b* with the secret lab. Formally, it means that the following inequation must fulfill: |*x*<=-<=*y*|<=&lt;<=|*x*<=-<=*b*|. After the lift successfully transports you to floor *y*, you write down number *y* in your notepad. Your task is to find the number of distinct number sequences that you could have written in the notebook as the result of *k* trips in the lift. As the sought number of trips can be rather large, find the remainder after dividing the number by 1000000007 (109<=+<=7). Input Specification: The first line of the input contains four space-separated integers *n*, *a*, *b*, *k* (2<=≤<=*n*<=≤<=5000, 1<=≤<=*k*<=≤<=5000, 1<=≤<=*a*,<=*b*<=≤<=*n*, *a*<=≠<=*b*). Output Specification: Print a single integer — the remainder after dividing the sought number of sequences by 1000000007 (109<=+<=7). Demo Input: ['5 2 4 1\n', '5 2 4 2\n', '5 3 4 1\n'] Demo Output: ['2\n', '2\n', '0\n'] Note: Two sequences *p*<sub class="lower-index">1</sub>, *p*<sub class="lower-index">2</sub>, ..., *p*<sub class="lower-index">*k*</sub> and *q*<sub class="lower-index">1</sub>, *q*<sub class="lower-index">2</sub>, ..., *q*<sub class="lower-index">*k*</sub> are distinct, if there is such integer *j* (1 ≤ *j* ≤ *k*), that *p*<sub class="lower-index">*j*</sub> ≠ *q*<sub class="lower-index">*j*</sub>. Notes to the samples: 1. In the first sample after the first trip you are either on floor 1, or on floor 3, because |1 - 2| &lt; |2 - 4| and |3 - 2| &lt; |2 - 4|. 1. In the second sample there are two possible sequences: (1, 2); (1, 3). You cannot choose floor 3 for the first trip because in this case no floor can be the floor for the second trip. 1. In the third sample there are no sought sequences, because you cannot choose the floor for the first trip.
```python import sys input= lambda: sys.stdin.buffer.readline().decode('utf-8').rstrip('\r\n') from array import array inp= lambda: int(input()) mi = lambda x=int : map(x, input().split()) arr= lambda d='i',x=int: array(d,mi(x)) li = lambda x=int: list(mi(x)) lb = lambda: list(map(int, input())) ls = lambda: list(input()) bi = lambda n: bin(n).replace("0b", "") yn = ['No', 'Yes'] YN = ['NO', 'YES'] YY = "YES" NN = "NO" yy = "Yes" nn = "No" inf= sys.maxsize mod=998244353 alp='abcdefghijklmnopqrstuvwxyz' from itertools import accumulate as cml,permutations,combinations from collections import Counter as ctr, deque as dq,defaultdict as dd from bisect import bisect_left as bl,bisect_right as br from math import ceil, gcd, log, sqrt import heapq as hq mod=10**9+7 mod=1000000007 def main(kase): n,a,b,k=mi() dp=[[0]*(n+1) for i in range(k+1)] a-=1 b-=1 dp[0][a]=1 dp[0][a+1]=-1 # print(dp) for i in range(k): for j in range(1,n+1): dp[i][j]=(dp[i][j]+dp[i][j-1])%mod for j in range(n): d=abs(b-j) if d==0: continue elif dp[i][j]==0: continue dp[i+1][max(j-d+1,0)]=(dp[i+1][max(j-d+1,0)]+dp[i][j])%mod dp[i+1][j]=(dp[i+1][j]-dp[i][j])%mod dp[i+1][j+1]=(dp[i+1][j+1]+dp[i][j])%mod dp[i+1][min(j+d,n)]=(dp[i+1][min(j+d,n)]-dp[i][j])%mod ans=dp[k][0] for j in range(1,n+1): dp[k][j]=(dp[k][j]+dp[k][j-1])%mod ans=(ans+dp[k][j])%mod print(ans) # print(dp) pass if __name__ == "__main__": test_Cases=1 # test_Cases=inp() for i in range(test_Cases): main(i) ```
0
580
A
Kefa and First Steps
PROGRAMMING
900
[ "brute force", "dp", "implementation" ]
null
null
Kefa decided to make some money doing business on the Internet for exactly *n* days. He knows that on the *i*-th day (1<=≤<=*i*<=≤<=*n*) he makes *a**i* money. Kefa loves progress, that's why he wants to know the length of the maximum non-decreasing subsegment in sequence *a**i*. Let us remind you that the subsegment of the sequence is its continuous fragment. A subsegment of numbers is called non-decreasing if all numbers in it follow in the non-decreasing order. Help Kefa cope with this task!
The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* integers *a*1,<=<=*a*2,<=<=...,<=<=*a**n* (1<=≤<=*a**i*<=≤<=109).
Print a single integer — the length of the maximum non-decreasing subsegment of sequence *a*.
[ "6\n2 2 1 3 4 1\n", "3\n2 2 9\n" ]
[ "3", "3" ]
In the first test the maximum non-decreasing subsegment is the numbers from the third to the fifth one. In the second test the maximum non-decreasing subsegment is the numbers from the first to the third one.
750
[ { "input": "6\n2 2 1 3 4 1", "output": "3" }, { "input": "3\n2 2 9", "output": "3" }, { "input": "5\n10 100 111 1 2", "output": "3" }, { "input": "10\n1 2 3 4 1 2 3 4 5 6", "output": "6" }, { "input": "50\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
1,688,660,218
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
15
0
a = int(input()) b=list(map(int, input().split())) c=0 maxC=0 for i in range(a-1): if b[i] <= b[i+1]: c+=1 if c > maxC: maxC = c print(maxC+1)
Title: Kefa and First Steps Time Limit: None seconds Memory Limit: None megabytes Problem Description: Kefa decided to make some money doing business on the Internet for exactly *n* days. He knows that on the *i*-th day (1<=≤<=*i*<=≤<=*n*) he makes *a**i* money. Kefa loves progress, that's why he wants to know the length of the maximum non-decreasing subsegment in sequence *a**i*. Let us remind you that the subsegment of the sequence is its continuous fragment. A subsegment of numbers is called non-decreasing if all numbers in it follow in the non-decreasing order. Help Kefa cope with this task! Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* integers *a*1,<=<=*a*2,<=<=...,<=<=*a**n* (1<=≤<=*a**i*<=≤<=109). Output Specification: Print a single integer — the length of the maximum non-decreasing subsegment of sequence *a*. Demo Input: ['6\n2 2 1 3 4 1\n', '3\n2 2 9\n'] Demo Output: ['3', '3'] Note: In the first test the maximum non-decreasing subsegment is the numbers from the third to the fifth one. In the second test the maximum non-decreasing subsegment is the numbers from the first to the third one.
```python a = int(input()) b=list(map(int, input().split())) c=0 maxC=0 for i in range(a-1): if b[i] <= b[i+1]: c+=1 if c > maxC: maxC = c print(maxC+1) ```
0
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 sequentially should be painted different colors. Help the Easter Rabbit paint the eggs in the required manner. We know that it is always possible.
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 indigo, "V" stands for violet. If there are several answers, print any of them.
[ "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,666,543,804
2,147,483,647
Python 3
OK
TESTS
34
92
0
st='ROYGBIV' st1='GBIV' x=int(input()) x=x-7 print(f'{st}{st1*(x//4)}{st1[:x%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: - Each of the seven colors should be used to paint at least one egg. - Any four eggs lying sequentially should be painted different colors. Help the Easter Rabbit paint the eggs in the required manner. We know that it is always possible. Input Specification: The only line contains an integer *n* — the amount of eggs (7<=≤<=*n*<=≤<=100). Output Specification: 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 indigo, "V" stands for violet. If there are several answers, print any of them. Demo Input: ['8\n', '13\n'] Demo Output: ['ROYGRBIV\n', 'ROYGBIVGBIVYG\n'] Note: The way the eggs will be painted in the first sample is shown on the picture:
```python st='ROYGBIV' st1='GBIV' x=int(input()) x=x-7 print(f'{st}{st1*(x//4)}{st1[:x%4]}') ```
3.977
982
B
Bus of Characters
PROGRAMMING
1,300
[ "data structures", "greedy", "implementation" ]
null
null
In the Bus of Characters there are $n$ rows of seat, each having $2$ seats. The width of both seats in the $i$-th row is $w_i$ centimeters. All integers $w_i$ are distinct. Initially the bus is empty. On each of $2n$ stops one passenger enters the bus. There are two types of passengers: - an introvert always chooses a row where both seats are empty. Among these rows he chooses the one with the smallest seats width and takes one of the seats in it; - an extrovert always chooses a row where exactly one seat is occupied (by an introvert). Among these rows he chooses the one with the largest seats width and takes the vacant place in it. You are given the seats width in each row and the order the passengers enter the bus. Determine which row each passenger will take.
The first line contains a single integer $n$ ($1 \le n \le 200\,000$) — the number of rows in the bus. The second line contains the sequence of integers $w_1, w_2, \dots, w_n$ ($1 \le w_i \le 10^{9}$), where $w_i$ is the width of each of the seats in the $i$-th row. It is guaranteed that all $w_i$ are distinct. The third line contains a string of length $2n$, consisting of digits '0' and '1' — the description of the order the passengers enter the bus. If the $j$-th character is '0', then the passenger that enters the bus on the $j$-th stop is an introvert. If the $j$-th character is '1', the the passenger that enters the bus on the $j$-th stop is an extrovert. It is guaranteed that the number of extroverts equals the number of introverts (i. e. both numbers equal $n$), and for each extrovert there always is a suitable row.
Print $2n$ integers — the rows the passengers will take. The order of passengers should be the same as in input.
[ "2\n3 1\n0011\n", "6\n10 8 9 11 13 5\n010010011101\n" ]
[ "2 1 1 2 \n", "6 6 2 3 3 1 4 4 1 2 5 5 \n" ]
In the first example the first passenger (introvert) chooses the row $2$, because it has the seats with smallest width. The second passenger (introvert) chooses the row $1$, because it is the only empty row now. The third passenger (extrovert) chooses the row $1$, because it has exactly one occupied seat and the seat width is the largest among such rows. The fourth passenger (extrovert) chooses the row $2$, because it is the only row with an empty place.
1,000
[ { "input": "2\n3 1\n0011", "output": "2 1 1 2 " }, { "input": "6\n10 8 9 11 13 5\n010010011101", "output": "6 6 2 3 3 1 4 4 1 2 5 5 " }, { "input": "1\n1\n01", "output": "1 1 " }, { "input": "1\n1000000\n01", "output": "1 1 " }, { "input": "2\n1 1000000\n0011", ...
1,585,824,919
2,147,483,647
Python 3
OK
TESTS
49
1,122
20,275,200
MyDict = {} N, Ans = int(input()), [] Width = list(map(int, input().split())) Passengers = input() for i in range(N): MyDict[Width[i]] = i + 1 Keys = sorted(Width) Now = [] Index = 0 for j in Passengers: if j == "0": Now.append(Keys[Index]) print(MyDict[Keys[Index]], end=" ") Index += 1 else: print(MyDict[Now.pop()], end=" ") # Hope the best for Ravens member
Title: Bus of Characters Time Limit: None seconds Memory Limit: None megabytes Problem Description: In the Bus of Characters there are $n$ rows of seat, each having $2$ seats. The width of both seats in the $i$-th row is $w_i$ centimeters. All integers $w_i$ are distinct. Initially the bus is empty. On each of $2n$ stops one passenger enters the bus. There are two types of passengers: - an introvert always chooses a row where both seats are empty. Among these rows he chooses the one with the smallest seats width and takes one of the seats in it; - an extrovert always chooses a row where exactly one seat is occupied (by an introvert). Among these rows he chooses the one with the largest seats width and takes the vacant place in it. You are given the seats width in each row and the order the passengers enter the bus. Determine which row each passenger will take. Input Specification: The first line contains a single integer $n$ ($1 \le n \le 200\,000$) — the number of rows in the bus. The second line contains the sequence of integers $w_1, w_2, \dots, w_n$ ($1 \le w_i \le 10^{9}$), where $w_i$ is the width of each of the seats in the $i$-th row. It is guaranteed that all $w_i$ are distinct. The third line contains a string of length $2n$, consisting of digits '0' and '1' — the description of the order the passengers enter the bus. If the $j$-th character is '0', then the passenger that enters the bus on the $j$-th stop is an introvert. If the $j$-th character is '1', the the passenger that enters the bus on the $j$-th stop is an extrovert. It is guaranteed that the number of extroverts equals the number of introverts (i. e. both numbers equal $n$), and for each extrovert there always is a suitable row. Output Specification: Print $2n$ integers — the rows the passengers will take. The order of passengers should be the same as in input. Demo Input: ['2\n3 1\n0011\n', '6\n10 8 9 11 13 5\n010010011101\n'] Demo Output: ['2 1 1 2 \n', '6 6 2 3 3 1 4 4 1 2 5 5 \n'] Note: In the first example the first passenger (introvert) chooses the row $2$, because it has the seats with smallest width. The second passenger (introvert) chooses the row $1$, because it is the only empty row now. The third passenger (extrovert) chooses the row $1$, because it has exactly one occupied seat and the seat width is the largest among such rows. The fourth passenger (extrovert) chooses the row $2$, because it is the only row with an empty place.
```python MyDict = {} N, Ans = int(input()), [] Width = list(map(int, input().split())) Passengers = input() for i in range(N): MyDict[Width[i]] = i + 1 Keys = sorted(Width) Now = [] Index = 0 for j in Passengers: if j == "0": Now.append(Keys[Index]) print(MyDict[Keys[Index]], end=" ") Index += 1 else: print(MyDict[Now.pop()], end=" ") # Hope the best for Ravens member ```
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 Berland). You are the royal treasurer, which needs to count the minimum charges of the kingdom on the king's present. The king can only give money, he hasn't a power to take away them.
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 third citizens to make the welfare of citizens equal 3. In the fourth example it is possible to give nothing to everyone because all citizens have 12 burles.
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,692,338,901
2,147,483,647
PyPy 3
OK
TESTS
41
93
1,228,800
t = int(input()) x = list(map(int, input().split())) a = 0 s = 0 for i in range(t): if x[i] != max(x): s = max(x) - x[i] x[i] = x[i] + s a = a + s elif x[i] == max(x): continue print(a)
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, the welfare of each of them is estimated as the integer in *a**i* burles (burle is the currency in Berland). You are the royal treasurer, which needs to count the minimum charges of the kingdom on the king's present. The king can only give money, he hasn't a power to take away them. Input Specification: 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. Output Specification: In the only line print the integer *S* — the minimum number of burles which are had to spend. Demo Input: ['5\n0 1 2 3 4\n', '5\n1 1 0 1 1\n', '3\n1 3 1\n', '1\n12\n'] Demo Output: ['10', '1', '4', '0'] Note: 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 third citizens to make the welfare of citizens equal 3. In the fourth example it is possible to give nothing to everyone because all citizens have 12 burles.
```python t = int(input()) x = list(map(int, input().split())) a = 0 s = 0 for i in range(t): if x[i] != max(x): s = max(x) - x[i] x[i] = x[i] + s a = a + s elif x[i] == max(x): continue print(a) ```
3
4
A
Watermelon
PROGRAMMING
800
[ "brute force", "math" ]
A. Watermelon
1
64
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem. Pete and Billy are great fans of even numbers, that's why they want to divide the watermelon in such a way that each of the two parts weighs even number of kilos, at the same time it is not obligatory that the parts are equal. The boys are extremely tired and want to start their meal as soon as possible, that's why you should help them and find out, if they can divide the watermelon in the way they want. For sure, each of them should get a part of positive weight.
The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys.
Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case.
[ "8\n" ]
[ "YES\n" ]
For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos).
0
[ { "input": "8", "output": "YES" }, { "input": "5", "output": "NO" }, { "input": "4", "output": "YES" }, { "input": "3", "output": "NO" }, { "input": "2", "output": "NO" }, { "input": "1", "output": "NO" }, { "input": "7", "output": "NO"...
1,694,445,141
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
0
w=int(input ('The weight of the watermelon is: ')) if w%2==0: print('Yes') else: print('NO')
Title: Watermelon Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem. Pete and Billy are great fans of even numbers, that's why they want to divide the watermelon in such a way that each of the two parts weighs even number of kilos, at the same time it is not obligatory that the parts are equal. The boys are extremely tired and want to start their meal as soon as possible, that's why you should help them and find out, if they can divide the watermelon in the way they want. For sure, each of them should get a part of positive weight. Input Specification: The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys. Output Specification: Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case. Demo Input: ['8\n'] Demo Output: ['YES\n'] Note: For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos).
```python w=int(input ('The weight of the watermelon is: ')) if w%2==0: print('Yes') else: print('NO') ```
0
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,667,461,316
2,147,483,647
PyPy 3-64
OK
TESTS
37
154
0
from collections import Counter import math n = int(input()) arr = [int(k) for k in input().split()] c = Counter(arr) m = max(c[k] for k in c) if len(arr) % 2 == 0: if m <= (len(arr) // 2): print('YES') else: print('NO') elif len(arr) % 2 != 0: if m <= (math.ceil(len(arr) / 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 be distinct in a finite time. Help Yaroslav. Input Specification: 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. Output Specification: In the single line print "YES" (without the quotes) if Yaroslav can obtain the array he needs, and "NO" (without the quotes) otherwise. Demo Input: ['1\n1\n', '3\n1 1 2\n', '4\n7 7 7 7\n'] Demo Output: ['YES\n', 'YES\n', 'NO\n'] Note: 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.
```python from collections import Counter import math n = int(input()) arr = [int(k) for k in input().split()] c = Counter(arr) m = max(c[k] for k in c) if len(arr) % 2 == 0: if m <= (len(arr) // 2): print('YES') else: print('NO') elif len(arr) % 2 != 0: if m <= (math.ceil(len(arr) / 2)): print('YES') else: print('NO') ```
3
472
A
Design Tutorial: Learn from Math
PROGRAMMING
800
[ "math", "number theory" ]
null
null
One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that. For example, there is a statement called the "Goldbach's conjecture". It says: "each even number no less than four can be expressed as the sum of two primes". Let's modify it. How about a statement like that: "each integer no less than 12 can be expressed as the sum of two composite numbers." Not like the Goldbach's conjecture, I can prove this theorem. You are given an integer *n* no less than 12, express it as a sum of two composite numbers.
The only line contains an integer *n* (12<=≤<=*n*<=≤<=106).
Output two composite integers *x* and *y* (1<=&lt;<=*x*,<=*y*<=&lt;<=*n*) such that *x*<=+<=*y*<==<=*n*. If there are multiple solutions, you can output any of them.
[ "12\n", "15\n", "23\n", "1000000\n" ]
[ "4 8\n", "6 9\n", "8 15\n", "500000 500000\n" ]
In the first example, 12 = 4 + 8 and both 4, 8 are composite numbers. You can output "6 6" or "8 4" as well. In the second example, 15 = 6 + 9. Note that you can't output "1 14" because 1 is not a composite number.
500
[ { "input": "12", "output": "4 8" }, { "input": "15", "output": "6 9" }, { "input": "23", "output": "8 15" }, { "input": "1000000", "output": "500000 500000" }, { "input": "63874", "output": "4 63870" }, { "input": "14568", "output": "4 14564" }, ...
1,657,525,667
2,147,483,647
Python 3
OK
TESTS
33
46
0
n=int(input()) def ans(n): if n%2==0: print(4, n-4, end=' ') else: print(9, n-9, end=' ') ans(n) # Mon Jul 11 2022 07:47:46 GMT+0000 (Coordinated Universal Time)
Title: Design Tutorial: Learn from Math Time Limit: None seconds Memory Limit: None megabytes Problem Description: One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that. For example, there is a statement called the "Goldbach's conjecture". It says: "each even number no less than four can be expressed as the sum of two primes". Let's modify it. How about a statement like that: "each integer no less than 12 can be expressed as the sum of two composite numbers." Not like the Goldbach's conjecture, I can prove this theorem. You are given an integer *n* no less than 12, express it as a sum of two composite numbers. Input Specification: The only line contains an integer *n* (12<=≤<=*n*<=≤<=106). Output Specification: Output two composite integers *x* and *y* (1<=&lt;<=*x*,<=*y*<=&lt;<=*n*) such that *x*<=+<=*y*<==<=*n*. If there are multiple solutions, you can output any of them. Demo Input: ['12\n', '15\n', '23\n', '1000000\n'] Demo Output: ['4 8\n', '6 9\n', '8 15\n', '500000 500000\n'] Note: In the first example, 12 = 4 + 8 and both 4, 8 are composite numbers. You can output "6 6" or "8 4" as well. In the second example, 15 = 6 + 9. Note that you can't output "1 14" because 1 is not a composite number.
```python n=int(input()) def ans(n): if n%2==0: print(4, n-4, end=' ') else: print(9, n-9, end=' ') ans(n) # Mon Jul 11 2022 07:47:46 GMT+0000 (Coordinated Universal Time) ```
3
456
A
Laptops
PROGRAMMING
1,100
[ "sortings" ]
null
null
One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the first laptop is less (strictly smaller) than the price of the second laptop but the quality of the first laptop is higher (strictly greater) than the quality of the second laptop. Please, check the guess of Alex. You are given descriptions of *n* laptops. Determine whether two described above laptops exist.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=105) — the number of laptops. Next *n* lines contain two integers each, *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*), where *a**i* is the price of the *i*-th laptop, and *b**i* is the number that represents the quality of the *i*-th laptop (the larger the number is, the higher is the quality). All *a**i* are distinct. All *b**i* are distinct.
If Alex is correct, print "Happy Alex", otherwise print "Poor Alex" (without the quotes).
[ "2\n1 2\n2 1\n" ]
[ "Happy Alex\n" ]
none
500
[ { "input": "2\n1 2\n2 1", "output": "Happy Alex" }, { "input": "2\n1 1\n2 2", "output": "Poor Alex" }, { "input": "3\n2 2\n3 3\n1 1", "output": "Poor Alex" }, { "input": "3\n3 3\n1 2\n2 1", "output": "Happy Alex" }, { "input": "1\n1 1", "output": "Poor Alex" ...
1,674,659,721
2,147,483,647
Python 3
OK
TESTS
46
249
0
for i in range(int(input())): x,y=map(int,input().split()) if x!=y: print('Happy Alex') exit() print('Poor Alex')
Title: Laptops Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the first laptop is less (strictly smaller) than the price of the second laptop but the quality of the first laptop is higher (strictly greater) than the quality of the second laptop. Please, check the guess of Alex. You are given descriptions of *n* laptops. Determine whether two described above laptops exist. Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=105) — the number of laptops. Next *n* lines contain two integers each, *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*), where *a**i* is the price of the *i*-th laptop, and *b**i* is the number that represents the quality of the *i*-th laptop (the larger the number is, the higher is the quality). All *a**i* are distinct. All *b**i* are distinct. Output Specification: If Alex is correct, print "Happy Alex", otherwise print "Poor Alex" (without the quotes). Demo Input: ['2\n1 2\n2 1\n'] Demo Output: ['Happy Alex\n'] Note: none
```python for i in range(int(input())): x,y=map(int,input().split()) if x!=y: print('Happy Alex') exit() print('Poor Alex') ```
3
938
B
Run For Your Prize
PROGRAMMING
1,100
[ "brute force", "greedy" ]
null
null
You and your friend are participating in a TV show "Run For Your Prize". At the start of the show *n* prizes are located on a straight line. *i*-th prize is located at position *a**i*. Positions of all prizes are distinct. You start at position 1, your friend — at position 106 (and there is no prize in any of these two positions). You have to work as a team and collect all prizes in minimum possible time, in any order. You know that it takes exactly 1 second to move from position *x* to position *x*<=+<=1 or *x*<=-<=1, both for you and your friend. You also have trained enough to instantly pick up any prize, if its position is equal to your current position (and the same is true for your friend). Carrying prizes does not affect your speed (or your friend's speed) at all. Now you may discuss your strategy with your friend and decide who will pick up each prize. Remember that every prize must be picked up, either by you or by your friend. What is the minimum number of seconds it will take to pick up all the prizes?
The first line contains one integer *n* (1<=≤<=*n*<=≤<=105) — the number of prizes. The second line contains *n* integers *a*1, *a*2, ..., *a**n* (2<=≤<=*a**i*<=≤<=106<=-<=1) — the positions of the prizes. No two prizes are located at the same position. Positions are given in ascending order.
Print one integer — the minimum number of seconds it will take to collect all prizes.
[ "3\n2 3 9\n", "2\n2 999995\n" ]
[ "8\n", "5\n" ]
In the first example you take all the prizes: take the first at 1, the second at 2 and the third at 8. In the second example you take the first prize in 1 second and your friend takes the other in 5 seconds, you do this simultaneously, so the total time is 5.
0
[ { "input": "3\n2 3 9", "output": "8" }, { "input": "2\n2 999995", "output": "5" }, { "input": "1\n20", "output": "19" }, { "input": "6\n2 3 500000 999997 999998 999999", "output": "499999" }, { "input": "1\n999999", "output": "1" }, { "input": "1\n5100...
1,686,478,711
2,147,483,647
Python 3
OK
TESTS
48
93
13,619,200
x = int(input()) l = list(map(int,input().split())) a = [] b = [] for i in l: if i <= 500000: a.append(i) else: b.append(i) a1 = 1 ans1 = 0 if len(a) > 0: for i in range(len(a)): ans1+=a[i] - a1 a1 = a[i] b1 = 1e6 ans2 = 0 if len(b) > 0: for i in range(len(b)-1,-1,-1): ans2+=b1 - b[i] b1 = b[i] print(int(max(ans1,ans2)))
Title: Run For Your Prize Time Limit: None seconds Memory Limit: None megabytes Problem Description: You and your friend are participating in a TV show "Run For Your Prize". At the start of the show *n* prizes are located on a straight line. *i*-th prize is located at position *a**i*. Positions of all prizes are distinct. You start at position 1, your friend — at position 106 (and there is no prize in any of these two positions). You have to work as a team and collect all prizes in minimum possible time, in any order. You know that it takes exactly 1 second to move from position *x* to position *x*<=+<=1 or *x*<=-<=1, both for you and your friend. You also have trained enough to instantly pick up any prize, if its position is equal to your current position (and the same is true for your friend). Carrying prizes does not affect your speed (or your friend's speed) at all. Now you may discuss your strategy with your friend and decide who will pick up each prize. Remember that every prize must be picked up, either by you or by your friend. What is the minimum number of seconds it will take to pick up all the prizes? Input Specification: The first line contains one integer *n* (1<=≤<=*n*<=≤<=105) — the number of prizes. The second line contains *n* integers *a*1, *a*2, ..., *a**n* (2<=≤<=*a**i*<=≤<=106<=-<=1) — the positions of the prizes. No two prizes are located at the same position. Positions are given in ascending order. Output Specification: Print one integer — the minimum number of seconds it will take to collect all prizes. Demo Input: ['3\n2 3 9\n', '2\n2 999995\n'] Demo Output: ['8\n', '5\n'] Note: In the first example you take all the prizes: take the first at 1, the second at 2 and the third at 8. In the second example you take the first prize in 1 second and your friend takes the other in 5 seconds, you do this simultaneously, so the total time is 5.
```python x = int(input()) l = list(map(int,input().split())) a = [] b = [] for i in l: if i <= 500000: a.append(i) else: b.append(i) a1 = 1 ans1 = 0 if len(a) > 0: for i in range(len(a)): ans1+=a[i] - a1 a1 = a[i] b1 = 1e6 ans2 = 0 if len(b) > 0: for i in range(len(b)-1,-1,-1): ans2+=b1 - b[i] b1 = b[i] print(int(max(ans1,ans2))) ```
3
821
B
Okabe and Banana Trees
PROGRAMMING
1,300
[ "brute force", "math" ]
null
null
Okabe needs bananas for one of his experiments for some strange reason. So he decides to go to the forest and cut banana trees. Consider the point (*x*,<=*y*) in the 2D plane such that *x* and *y* are integers and 0<=≤<=*x*,<=*y*. There is a tree in such a point, and it has *x*<=+<=*y* bananas. There are no trees nor bananas in other points. Now, Okabe draws a line with equation . Okabe can select a single rectangle with axis aligned sides with all points on or under the line and cut all the trees in all points that are inside or on the border of this rectangle and take their bananas. Okabe's rectangle can be degenerate; that is, it can be a line segment or even a point. Help Okabe and find the maximum number of bananas he can get if he chooses the rectangle wisely. Okabe is sure that the answer does not exceed 1018. You can trust him.
The first line of input contains two space-separated integers *m* and *b* (1<=≤<=*m*<=≤<=1000, 1<=≤<=*b*<=≤<=10000).
Print the maximum number of bananas Okabe can get from the trees he cuts.
[ "1 5\n", "2 3\n" ]
[ "30\n", "25\n" ]
The graph above corresponds to sample test 1. The optimal rectangle is shown in red and has 30 bananas.
1,000
[ { "input": "1 5", "output": "30" }, { "input": "2 3", "output": "25" }, { "input": "4 6", "output": "459" }, { "input": "6 3", "output": "171" }, { "input": "1 1", "output": "1" }, { "input": "10 1", "output": "55" }, { "input": "20 10", ...
1,587,809,274
4,374
PyPy 3
WRONG_ANSWER
TESTS
2
499
11,468,800
import math as mt import sys,string input=sys.stdin.readline import random from collections import deque,defaultdict L=lambda : list(map(int,input().split())) Ls=lambda : list(input().split()) M=lambda : map(int,input().split()) I=lambda :int(input()) def x(s,e): return (e*(e+1))//2-(s*(s-1))//2 m,b=M() w=b//2 h=m*b-w*m ans=0 for i in range(w+1): ans+=x(i,h+i) print(ans)
Title: Okabe and Banana Trees Time Limit: None seconds Memory Limit: None megabytes Problem Description: Okabe needs bananas for one of his experiments for some strange reason. So he decides to go to the forest and cut banana trees. Consider the point (*x*,<=*y*) in the 2D plane such that *x* and *y* are integers and 0<=≤<=*x*,<=*y*. There is a tree in such a point, and it has *x*<=+<=*y* bananas. There are no trees nor bananas in other points. Now, Okabe draws a line with equation . Okabe can select a single rectangle with axis aligned sides with all points on or under the line and cut all the trees in all points that are inside or on the border of this rectangle and take their bananas. Okabe's rectangle can be degenerate; that is, it can be a line segment or even a point. Help Okabe and find the maximum number of bananas he can get if he chooses the rectangle wisely. Okabe is sure that the answer does not exceed 1018. You can trust him. Input Specification: The first line of input contains two space-separated integers *m* and *b* (1<=≤<=*m*<=≤<=1000, 1<=≤<=*b*<=≤<=10000). Output Specification: Print the maximum number of bananas Okabe can get from the trees he cuts. Demo Input: ['1 5\n', '2 3\n'] Demo Output: ['30\n', '25\n'] Note: The graph above corresponds to sample test 1. The optimal rectangle is shown in red and has 30 bananas.
```python import math as mt import sys,string input=sys.stdin.readline import random from collections import deque,defaultdict L=lambda : list(map(int,input().split())) Ls=lambda : list(input().split()) M=lambda : map(int,input().split()) I=lambda :int(input()) def x(s,e): return (e*(e+1))//2-(s*(s-1))//2 m,b=M() w=b//2 h=m*b-w*m ans=0 for i in range(w+1): ans+=x(i,h+i) print(ans) ```
0
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 Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square.
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,689,780,438
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
31
0
ns = list(map(int, input().split(' '))) ns2 = [ns[0] / ns[2], ns[1] / ns[2]] if ns2[0] > ns[0] // ns[2]: ns2[0] = ns[0] // ns[2] + 1 if ns2[1] > ns[1] // ns[2]: ns2[1] = ns[1] // ns[2] + 1 print(ns2[0] * ns2[1])
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 flagstone is of the size *a*<=×<=*a*. What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square. Input Specification: The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). Output Specification: Write the needed number of flagstones. Demo Input: ['6 6 4\n'] Demo Output: ['4\n'] Note: none
```python ns = list(map(int, input().split(' '))) ns2 = [ns[0] / ns[2], ns[1] / ns[2]] if ns2[0] > ns[0] // ns[2]: ns2[0] = ns[0] // ns[2] + 1 if ns2[1] > ns[1] // ns[2]: ns2[1] = ns[1] // ns[2] + 1 print(ns2[0] * ns2[1]) ```
0
903
C
Boxes Packing
PROGRAMMING
1,200
[ "greedy" ]
null
null
Mishka has got *n* empty boxes. For every *i* (1<=≤<=*i*<=≤<=*n*), *i*-th box is a cube with side length *a**i*. Mishka can put a box *i* into another box *j* if the following conditions are met: - *i*-th box is not put into another box; - *j*-th box doesn't contain any other boxes; - box *i* is smaller than box *j* (*a**i*<=&lt;<=*a**j*). Mishka can put boxes into each other an arbitrary number of times. He wants to minimize the number of visible boxes. A box is called visible iff it is not put into some another box. Help Mishka to determine the minimum possible number of visible boxes!
The first line contains one integer *n* (1<=≤<=*n*<=≤<=5000) — the number of boxes Mishka has got. The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=109), where *a**i* is the side length of *i*-th box.
Print the minimum possible number of visible boxes.
[ "3\n1 2 3\n", "4\n4 2 4 3\n" ]
[ "1\n", "2\n" ]
In the first example it is possible to put box 1 into box 2, and 2 into 3. In the second example Mishka can put box 2 into box 3, and box 4 into box 1.
0
[ { "input": "3\n1 2 3", "output": "1" }, { "input": "4\n4 2 4 3", "output": "2" }, { "input": "10\n58 58 58 58 58 58 58 58 58 58", "output": "10" }, { "input": "10\n86 89 89 86 86 89 86 86 89 89", "output": "5" }, { "input": "100\n981 288 186 186 292 876 341 288 98...
1,559,561,225
724
Python 3
WRONG_ANSWER
TESTS
3
93
0
a = int(input()) b = len(set(map(int , input().split()))) if a>b: z = 1 +(a-b) if a==b: z = 1 print(z)
Title: Boxes Packing Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mishka has got *n* empty boxes. For every *i* (1<=≤<=*i*<=≤<=*n*), *i*-th box is a cube with side length *a**i*. Mishka can put a box *i* into another box *j* if the following conditions are met: - *i*-th box is not put into another box; - *j*-th box doesn't contain any other boxes; - box *i* is smaller than box *j* (*a**i*<=&lt;<=*a**j*). Mishka can put boxes into each other an arbitrary number of times. He wants to minimize the number of visible boxes. A box is called visible iff it is not put into some another box. Help Mishka to determine the minimum possible number of visible boxes! Input Specification: The first line contains one integer *n* (1<=≤<=*n*<=≤<=5000) — the number of boxes Mishka has got. The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=109), where *a**i* is the side length of *i*-th box. Output Specification: Print the minimum possible number of visible boxes. Demo Input: ['3\n1 2 3\n', '4\n4 2 4 3\n'] Demo Output: ['1\n', '2\n'] Note: In the first example it is possible to put box 1 into box 2, and 2 into 3. In the second example Mishka can put box 2 into box 3, and box 4 into box 1.
```python a = int(input()) b = len(set(map(int , input().split()))) if a>b: z = 1 +(a-b) if a==b: z = 1 print(z) ```
0
778
A
String Game
PROGRAMMING
1,700
[ "binary search", "greedy", "strings" ]
null
null
Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her. Sergey gives Nastya the word *t* and wants to get the word *p* out of it. Nastya removes letters in a certain order (one after another, in this order strictly), which is specified by permutation of letters' indices of the word *t*: *a*1... *a*|*t*|. We denote the length of word *x* as |*x*|. Note that after removing one letter, the indices of other letters don't change. For example, if *t*<==<="nastya" and *a*<==<=[4,<=1,<=5,<=3,<=2,<=6] then removals make the following sequence of words "nastya" "nastya" "nastya" "nastya" "nastya" "nastya" "nastya". Sergey knows this permutation. His goal is to stop his sister at some point and continue removing by himself to get the word *p*. Since Nastya likes this activity, Sergey wants to stop her as late as possible. Your task is to determine, how many letters Nastya can remove before she will be stopped by Sergey. It is guaranteed that the word *p* can be obtained by removing the letters from word *t*.
The first and second lines of the input contain the words *t* and *p*, respectively. Words are composed of lowercase letters of the Latin alphabet (1<=≤<=|*p*|<=&lt;<=|*t*|<=≤<=200<=000). It is guaranteed that the word *p* can be obtained by removing the letters from word *t*. Next line contains a permutation *a*1,<=*a*2,<=...,<=*a*|*t*| of letter indices that specifies the order in which Nastya removes letters of *t* (1<=≤<=*a**i*<=≤<=|*t*|, all *a**i* are distinct).
Print a single integer number, the maximum number of letters that Nastya can remove.
[ "ababcba\nabb\n5 3 4 1 7 6 2\n", "bbbabb\nbb\n1 6 3 4 2 5\n" ]
[ "3", "4" ]
In the first sample test sequence of removing made by Nastya looks like this: "ababcba" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "ababcba" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "ababcba" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "ababcba" Nastya can not continue, because it is impossible to get word "abb" from word "ababcba". So, Nastya will remove only three letters.
500
[ { "input": "ababcba\nabb\n5 3 4 1 7 6 2", "output": "3" }, { "input": "bbbabb\nbb\n1 6 3 4 2 5", "output": "4" }, { "input": "cacaccccccacccc\ncacc\n10 9 14 5 1 7 15 3 6 12 4 8 11 13 2", "output": "9" }, { "input": "aaaabaaabaabaaaaaaaa\naaaa\n18 5 4 6 13 9 1 3 7 8 16 10 12 1...
1,489,425,599
599
Python 3
WRONG_ANSWER
TESTS
1
46
4,608,000
def lcs(xstr, ystr): if not xstr or not ystr: return "" x, xs, y, ys = xstr[0], xstr[1:], ystr[0], ystr[1:] if x == y: return x + lcs(xs, ys) else: return max(lcs(xstr, ys), lcs(xs, ystr), key=len) s= input() n = input() l = input() l=[int(i) for i in l.split()] v={i:s[i] for i in range(len(s))} t=0 for i in l: s = s[:i-1] +s[i:] if lcs(s,n) !=n: break t+=1 print(t)
Title: String Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her. Sergey gives Nastya the word *t* and wants to get the word *p* out of it. Nastya removes letters in a certain order (one after another, in this order strictly), which is specified by permutation of letters' indices of the word *t*: *a*1... *a*|*t*|. We denote the length of word *x* as |*x*|. Note that after removing one letter, the indices of other letters don't change. For example, if *t*<==<="nastya" and *a*<==<=[4,<=1,<=5,<=3,<=2,<=6] then removals make the following sequence of words "nastya" "nastya" "nastya" "nastya" "nastya" "nastya" "nastya". Sergey knows this permutation. His goal is to stop his sister at some point and continue removing by himself to get the word *p*. Since Nastya likes this activity, Sergey wants to stop her as late as possible. Your task is to determine, how many letters Nastya can remove before she will be stopped by Sergey. It is guaranteed that the word *p* can be obtained by removing the letters from word *t*. Input Specification: The first and second lines of the input contain the words *t* and *p*, respectively. Words are composed of lowercase letters of the Latin alphabet (1<=≤<=|*p*|<=&lt;<=|*t*|<=≤<=200<=000). It is guaranteed that the word *p* can be obtained by removing the letters from word *t*. Next line contains a permutation *a*1,<=*a*2,<=...,<=*a*|*t*| of letter indices that specifies the order in which Nastya removes letters of *t* (1<=≤<=*a**i*<=≤<=|*t*|, all *a**i* are distinct). Output Specification: Print a single integer number, the maximum number of letters that Nastya can remove. Demo Input: ['ababcba\nabb\n5 3 4 1 7 6 2\n', 'bbbabb\nbb\n1 6 3 4 2 5\n'] Demo Output: ['3', '4'] Note: In the first sample test sequence of removing made by Nastya looks like this: "ababcba" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "ababcba" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "ababcba" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "ababcba" Nastya can not continue, because it is impossible to get word "abb" from word "ababcba". So, Nastya will remove only three letters.
```python def lcs(xstr, ystr): if not xstr or not ystr: return "" x, xs, y, ys = xstr[0], xstr[1:], ystr[0], ystr[1:] if x == y: return x + lcs(xs, ys) else: return max(lcs(xstr, ys), lcs(xs, ystr), key=len) s= input() n = input() l = input() l=[int(i) for i in l.split()] v={i:s[i] for i in range(len(s))} t=0 for i in l: s = s[:i-1] +s[i:] if lcs(s,n) !=n: break t+=1 print(t) ```
0
965
A
Paper Airplanes
PROGRAMMING
800
[ "math" ]
null
null
To make a paper airplane, one has to use a rectangular piece of paper. From a sheet of standard size you can make $s$ airplanes. A group of $k$ people decided to make $n$ airplanes each. They are going to buy several packs of paper, each of them containing $p$ sheets, and then distribute the sheets between the people. Each person should have enough sheets to make $n$ airplanes. How many packs should they buy?
The only line contains four integers $k$, $n$, $s$, $p$ ($1 \le k, n, s, p \le 10^4$) — the number of people, the number of airplanes each should make, the number of airplanes that can be made using one sheet and the number of sheets in one pack, respectively.
Print a single integer — the minimum number of packs they should buy.
[ "5 3 2 3\n", "5 3 100 1\n" ]
[ "4\n", "5\n" ]
In the first sample they have to buy $4$ packs of paper: there will be $12$ sheets in total, and giving $2$ sheets to each person is enough to suit everyone's needs. In the second sample they have to buy a pack for each person as they can't share sheets.
500
[ { "input": "5 3 2 3", "output": "4" }, { "input": "5 3 100 1", "output": "5" }, { "input": "10000 10000 1 1", "output": "100000000" }, { "input": "1 1 10000 10000", "output": "1" }, { "input": "300 300 21 23", "output": "196" }, { "input": "300 2 37 51...
1,685,590,030
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
62
409,600
import math import decimal k, n, s, p = list(map(int, input("").split())) sum1 = k*n sum2 = k*s while(k): if(sum2 == sum1 and p == 1): sum3 = s*p ans = math.floor(sum2/sum3) break elif(sum2>=sum1): sum3 = s*p ans = math.ceil(sum2/sum3) break sum2+=sum2 print(ans)
Title: Paper Airplanes Time Limit: None seconds Memory Limit: None megabytes Problem Description: To make a paper airplane, one has to use a rectangular piece of paper. From a sheet of standard size you can make $s$ airplanes. A group of $k$ people decided to make $n$ airplanes each. They are going to buy several packs of paper, each of them containing $p$ sheets, and then distribute the sheets between the people. Each person should have enough sheets to make $n$ airplanes. How many packs should they buy? Input Specification: The only line contains four integers $k$, $n$, $s$, $p$ ($1 \le k, n, s, p \le 10^4$) — the number of people, the number of airplanes each should make, the number of airplanes that can be made using one sheet and the number of sheets in one pack, respectively. Output Specification: Print a single integer — the minimum number of packs they should buy. Demo Input: ['5 3 2 3\n', '5 3 100 1\n'] Demo Output: ['4\n', '5\n'] Note: In the first sample they have to buy $4$ packs of paper: there will be $12$ sheets in total, and giving $2$ sheets to each person is enough to suit everyone's needs. In the second sample they have to buy a pack for each person as they can't share sheets.
```python import math import decimal k, n, s, p = list(map(int, input("").split())) sum1 = k*n sum2 = k*s while(k): if(sum2 == sum1 and p == 1): sum3 = s*p ans = math.floor(sum2/sum3) break elif(sum2>=sum1): sum3 = s*p ans = math.ceil(sum2/sum3) break sum2+=sum2 print(ans) ```
0
116
A
Tram
PROGRAMMING
800
[ "implementation" ]
null
null
Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty. Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram.
The first line contains a single number *n* (2<=≤<=*n*<=≤<=1000) — the number of the tram's stops. Then *n* lines follow, each contains two integers *a**i* and *b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the number of passengers that exits the tram at the *i*-th stop, and the number of passengers that enter the tram at the *i*-th stop. The stops are given from the first to the last stop in the order of tram's movement. - The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, . This particularly means that *a*1<==<=0. - At the last stop, all the passengers exit the tram and it becomes empty. More formally, . - No passenger will enter the train at the last stop. That is, *b**n*<==<=0.
Print a single integer denoting the minimum possible capacity of the tram (0 is allowed).
[ "4\n0 3\n2 5\n4 2\n4 0\n" ]
[ "6\n" ]
For the first example, a capacity of 6 is sufficient: - At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. - At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 passengers enter the tram. There are 6 passengers inside the tram now. - At the third stop, 4 passengers exit the tram (2 passengers remain inside). Then, 2 passengers enter the tram. There are 4 passengers inside the tram now. - Finally, all the remaining passengers inside the tram exit the tram at the last stop. There are no passenger inside the tram now, which is in line with the constraints. Since the number of passengers inside the tram never exceeds 6, a capacity of 6 is sufficient. Furthermore it is not possible for the tram to have a capacity less than 6. Hence, 6 is the correct answer.
500
[ { "input": "4\n0 3\n2 5\n4 2\n4 0", "output": "6" }, { "input": "5\n0 4\n4 6\n6 5\n5 4\n4 0", "output": "6" }, { "input": "10\n0 5\n1 7\n10 8\n5 3\n0 5\n3 3\n8 8\n0 6\n10 1\n9 0", "output": "18" }, { "input": "3\n0 1\n1 1\n1 0", "output": "1" }, { "input": "4\n0 1...
1,699,062,557
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
//============================================================================ //problem link:http://codeforces.com/problemset/problem/116/A // Name : .cpp // Author : mohand sakr // Version : // Copyright : use it under your responsibility // Description : Hello World in C++, Ansi-style //status:accepted //============================================================================ #include <iostream> #include<cmath> using namespace std; int main() { int n; cin>>n; int capacity=0; int stillnow=0; for(int i=0;i<n;i++){ int a,b; cin>>a>>b; stillnow-=a; stillnow+=b; capacity=max(capacity,stillnow); } cout<<capacity; return 0; }
Title: Tram Time Limit: None seconds Memory Limit: None megabytes Problem Description: Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty. Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram. Input Specification: The first line contains a single number *n* (2<=≤<=*n*<=≤<=1000) — the number of the tram's stops. Then *n* lines follow, each contains two integers *a**i* and *b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the number of passengers that exits the tram at the *i*-th stop, and the number of passengers that enter the tram at the *i*-th stop. The stops are given from the first to the last stop in the order of tram's movement. - The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, . This particularly means that *a*1<==<=0. - At the last stop, all the passengers exit the tram and it becomes empty. More formally, . - No passenger will enter the train at the last stop. That is, *b**n*<==<=0. Output Specification: Print a single integer denoting the minimum possible capacity of the tram (0 is allowed). Demo Input: ['4\n0 3\n2 5\n4 2\n4 0\n'] Demo Output: ['6\n'] Note: For the first example, a capacity of 6 is sufficient: - At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. - At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 passengers enter the tram. There are 6 passengers inside the tram now. - At the third stop, 4 passengers exit the tram (2 passengers remain inside). Then, 2 passengers enter the tram. There are 4 passengers inside the tram now. - Finally, all the remaining passengers inside the tram exit the tram at the last stop. There are no passenger inside the tram now, which is in line with the constraints. Since the number of passengers inside the tram never exceeds 6, a capacity of 6 is sufficient. Furthermore it is not possible for the tram to have a capacity less than 6. Hence, 6 is the correct answer.
```python //============================================================================ //problem link:http://codeforces.com/problemset/problem/116/A // Name : .cpp // Author : mohand sakr // Version : // Copyright : use it under your responsibility // Description : Hello World in C++, Ansi-style //status:accepted //============================================================================ #include <iostream> #include<cmath> using namespace std; int main() { int n; cin>>n; int capacity=0; int stillnow=0; for(int i=0;i<n;i++){ int a,b; cin>>a>>b; stillnow-=a; stillnow+=b; capacity=max(capacity,stillnow); } cout<<capacity; return 0; } ```
-1
745
A
Hongcow Learns the Cyclic Shift
PROGRAMMING
900
[ "implementation", "strings" ]
null
null
Hongcow is learning to spell! One day, his teacher gives him a word that he needs to learn to spell. Being a dutiful student, he immediately learns how to spell the word. Hongcow has decided to try to make new words from this one. He starts by taking the word he just learned how to spell, and moves the last character of the word to the beginning of the word. He calls this a cyclic shift. He can apply cyclic shift many times. For example, consecutively applying cyclic shift operation to the word "abracadabra" Hongcow will get words "aabracadabr", "raabracadab" and so on. Hongcow is now wondering how many distinct words he can generate by doing the cyclic shift arbitrarily many times. The initial string is also counted.
The first line of input will be a single string *s* (1<=≤<=|*s*|<=≤<=50), the word Hongcow initially learns how to spell. The string *s* consists only of lowercase English letters ('a'–'z').
Output a single integer equal to the number of distinct strings that Hongcow can obtain by applying the cyclic shift arbitrarily many times to the given string.
[ "abcd\n", "bbb\n", "yzyz\n" ]
[ "4\n", "1\n", "2\n" ]
For the first sample, the strings Hongcow can generate are "abcd", "dabc", "cdab", and "bcda". For the second sample, no matter how many times Hongcow does the cyclic shift, Hongcow can only generate "bbb". For the third sample, the two strings Hongcow can generate are "yzyz" and "zyzy".
500
[ { "input": "abcd", "output": "4" }, { "input": "bbb", "output": "1" }, { "input": "yzyz", "output": "2" }, { "input": "abcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxy", "output": "25" }, { "input": "zclkjadoprqronzclkjadoprqronzclkjadoprqron", "output": "14...
1,507,371,770
2,147,483,647
PyPy 3
OK
TESTS
28
93
307,200
s = list(input()) n = len(s) dict = {} res = 0 for i in range (n): tmp = ''.join(s) if dict.get(tmp) == None: dict[tmp] = 1 res += 1 s.insert(0, s[n - 1]) s.pop(n) print(res)
Title: Hongcow Learns the Cyclic Shift Time Limit: None seconds Memory Limit: None megabytes Problem Description: Hongcow is learning to spell! One day, his teacher gives him a word that he needs to learn to spell. Being a dutiful student, he immediately learns how to spell the word. Hongcow has decided to try to make new words from this one. He starts by taking the word he just learned how to spell, and moves the last character of the word to the beginning of the word. He calls this a cyclic shift. He can apply cyclic shift many times. For example, consecutively applying cyclic shift operation to the word "abracadabra" Hongcow will get words "aabracadabr", "raabracadab" and so on. Hongcow is now wondering how many distinct words he can generate by doing the cyclic shift arbitrarily many times. The initial string is also counted. Input Specification: The first line of input will be a single string *s* (1<=≤<=|*s*|<=≤<=50), the word Hongcow initially learns how to spell. The string *s* consists only of lowercase English letters ('a'–'z'). Output Specification: Output a single integer equal to the number of distinct strings that Hongcow can obtain by applying the cyclic shift arbitrarily many times to the given string. Demo Input: ['abcd\n', 'bbb\n', 'yzyz\n'] Demo Output: ['4\n', '1\n', '2\n'] Note: For the first sample, the strings Hongcow can generate are "abcd", "dabc", "cdab", and "bcda". For the second sample, no matter how many times Hongcow does the cyclic shift, Hongcow can only generate "bbb". For the third sample, the two strings Hongcow can generate are "yzyz" and "zyzy".
```python s = list(input()) n = len(s) dict = {} res = 0 for i in range (n): tmp = ''.join(s) if dict.get(tmp) == None: dict[tmp] = 1 res += 1 s.insert(0, s[n - 1]) s.pop(n) print(res) ```
3
294
A
Shaass and Oskols
PROGRAMMING
800
[ "implementation", "math" ]
null
null
Shaass has decided to hunt some birds. There are *n* horizontal electricity wires aligned parallel to each other. Wires are numbered 1 to *n* from top to bottom. On each wire there are some oskols sitting next to each other. Oskol is the name of a delicious kind of birds in Shaass's territory. Supposed there are *a**i* oskols sitting on the *i*-th wire. Sometimes Shaass shots one of the birds and the bird dies (suppose that this bird sat at the *i*-th wire). Consequently all the birds on the *i*-th wire to the left of the dead bird get scared and jump up on the wire number *i*<=-<=1, if there exists no upper wire they fly away. Also all the birds to the right of the dead bird jump down on wire number *i*<=+<=1, if there exists no such wire they fly away. Shaass has shot *m* birds. You're given the initial number of birds on each wire, tell him how many birds are sitting on each wire after the shots.
The first line of the input contains an integer *n*, (1<=≤<=*n*<=≤<=100). The next line contains a list of space-separated integers *a*1,<=*a*2,<=...,<=*a**n*, (0<=≤<=*a**i*<=≤<=100). The third line contains an integer *m*, (0<=≤<=*m*<=≤<=100). Each of the next *m* lines contains two integers *x**i* and *y**i*. The integers mean that for the *i*-th time Shaass shoot the *y**i*-th (from left) bird on the *x**i*-th wire, (1<=≤<=*x**i*<=≤<=*n*,<=1<=≤<=*y**i*). It's guaranteed there will be at least *y**i* birds on the *x**i*-th wire at that moment.
On the *i*-th line of the output print the number of birds on the *i*-th wire.
[ "5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6\n", "3\n2 4 1\n1\n2 2\n" ]
[ "0\n12\n5\n0\n16\n", "3\n0\n3\n" ]
none
500
[ { "input": "5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6", "output": "0\n12\n5\n0\n16" }, { "input": "3\n2 4 1\n1\n2 2", "output": "3\n0\n3" }, { "input": "5\n58 51 45 27 48\n5\n4 9\n5 15\n4 5\n5 8\n1 43", "output": "0\n66\n57\n7\n0" }, { "input": "10\n48 53 10 28 91 56 8...
1,606,172,205
2,147,483,647
PyPy 3
OK
TESTS
31
280
0
def solve(t_id): n = int(input()) a = list(map(int, input().split())) m = int(input()) for i in range(m): x, y = map(int, input().split()) x -= 1 if x > 0: a[x - 1] += y - 1 if x < n - 1: a[x + 1] += a[x] - y a[x] = 0 print(*a, sep = '\n') t = 1 #t = int(input()) for t_id in range(1, t + 1): solve(t_id) t -= 1
Title: Shaass and Oskols Time Limit: None seconds Memory Limit: None megabytes Problem Description: Shaass has decided to hunt some birds. There are *n* horizontal electricity wires aligned parallel to each other. Wires are numbered 1 to *n* from top to bottom. On each wire there are some oskols sitting next to each other. Oskol is the name of a delicious kind of birds in Shaass's territory. Supposed there are *a**i* oskols sitting on the *i*-th wire. Sometimes Shaass shots one of the birds and the bird dies (suppose that this bird sat at the *i*-th wire). Consequently all the birds on the *i*-th wire to the left of the dead bird get scared and jump up on the wire number *i*<=-<=1, if there exists no upper wire they fly away. Also all the birds to the right of the dead bird jump down on wire number *i*<=+<=1, if there exists no such wire they fly away. Shaass has shot *m* birds. You're given the initial number of birds on each wire, tell him how many birds are sitting on each wire after the shots. Input Specification: The first line of the input contains an integer *n*, (1<=≤<=*n*<=≤<=100). The next line contains a list of space-separated integers *a*1,<=*a*2,<=...,<=*a**n*, (0<=≤<=*a**i*<=≤<=100). The third line contains an integer *m*, (0<=≤<=*m*<=≤<=100). Each of the next *m* lines contains two integers *x**i* and *y**i*. The integers mean that for the *i*-th time Shaass shoot the *y**i*-th (from left) bird on the *x**i*-th wire, (1<=≤<=*x**i*<=≤<=*n*,<=1<=≤<=*y**i*). It's guaranteed there will be at least *y**i* birds on the *x**i*-th wire at that moment. Output Specification: On the *i*-th line of the output print the number of birds on the *i*-th wire. Demo Input: ['5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6\n', '3\n2 4 1\n1\n2 2\n'] Demo Output: ['0\n12\n5\n0\n16\n', '3\n0\n3\n'] Note: none
```python def solve(t_id): n = int(input()) a = list(map(int, input().split())) m = int(input()) for i in range(m): x, y = map(int, input().split()) x -= 1 if x > 0: a[x - 1] += y - 1 if x < n - 1: a[x + 1] += a[x] - y a[x] = 0 print(*a, sep = '\n') t = 1 #t = int(input()) for t_id in range(1, t + 1): solve(t_id) t -= 1 ```
3
352
A
Jeff and Digits
PROGRAMMING
1,000
[ "brute force", "implementation", "math" ]
null
null
Jeff's got *n* cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make from the cards he's got? Jeff must make the number without leading zero. At that, we assume that number 0 doesn't contain any leading zeroes. Jeff doesn't have to use all the cards.
The first line contains integer *n* (1<=≤<=*n*<=≤<=103). The next line contains *n* integers *a*1, *a*2, ..., *a**n* (*a**i*<==<=0 or *a**i*<==<=5). Number *a**i* represents the digit that is written on the *i*-th card.
In a single line print the answer to the problem — the maximum number, divisible by 90. If you can't make any divisible by 90 number from the cards, print -1.
[ "4\n5 0 5 0\n", "11\n5 5 5 5 5 5 5 5 0 5 5\n" ]
[ "0\n", "5555555550\n" ]
In the first test you can make only one number that is a multiple of 90 — 0. In the second test you can make number 5555555550, it is a multiple of 90.
500
[ { "input": "4\n5 0 5 0", "output": "0" }, { "input": "11\n5 5 5 5 5 5 5 5 0 5 5", "output": "5555555550" }, { "input": "7\n5 5 5 5 5 5 5", "output": "-1" }, { "input": "1\n5", "output": "-1" }, { "input": "1\n0", "output": "0" }, { "input": "11\n5 0 5 ...
1,674,502,823
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
92
0
n = int(input()) cards = list(map(int,input().split())) a = cards.count(5) b = cards.count(0) if a >8 and b >0: liste =[] for i in range(int(9*int(a/9))): liste.append('5') for i in range(b): liste.append('0') print(''.join(liste)) else: print(0)
Title: Jeff and Digits Time Limit: None seconds Memory Limit: None megabytes Problem Description: Jeff's got *n* cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make from the cards he's got? Jeff must make the number without leading zero. At that, we assume that number 0 doesn't contain any leading zeroes. Jeff doesn't have to use all the cards. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=103). The next line contains *n* integers *a*1, *a*2, ..., *a**n* (*a**i*<==<=0 or *a**i*<==<=5). Number *a**i* represents the digit that is written on the *i*-th card. Output Specification: In a single line print the answer to the problem — the maximum number, divisible by 90. If you can't make any divisible by 90 number from the cards, print -1. Demo Input: ['4\n5 0 5 0\n', '11\n5 5 5 5 5 5 5 5 0 5 5\n'] Demo Output: ['0\n', '5555555550\n'] Note: In the first test you can make only one number that is a multiple of 90 — 0. In the second test you can make number 5555555550, it is a multiple of 90.
```python n = int(input()) cards = list(map(int,input().split())) a = cards.count(5) b = cards.count(0) if a >8 and b >0: liste =[] for i in range(int(9*int(a/9))): liste.append('5') for i in range(b): liste.append('0') print(''.join(liste)) else: print(0) ```
0
651
A
Joysticks
PROGRAMMING
1,100
[ "dp", "greedy", "implementation", "math" ]
null
null
Friends are going to play console. They have two joysticks and only one charger for them. Initially first joystick is charged at *a*1 percent and second one is charged at *a*2 percent. You can connect charger to a joystick only at the beginning of each minute. In one minute joystick either discharges by 2 percent (if not connected to a charger) or charges by 1 percent (if connected to a charger). Game continues while both joysticks have a positive charge. Hence, if at the beginning of minute some joystick is charged by 1 percent, it has to be connected to a charger, otherwise the game stops. If some joystick completely discharges (its charge turns to 0), the game also stops. Determine the maximum number of minutes that game can last. It is prohibited to pause the game, i. e. at each moment both joysticks should be enabled. It is allowed for joystick to be charged by more than 100 percent.
The first line of the input contains two positive integers *a*1 and *a*2 (1<=≤<=*a*1,<=*a*2<=≤<=100), the initial charge level of first and second joystick respectively.
Output the only integer, the maximum number of minutes that the game can last. Game continues until some joystick is discharged.
[ "3 5\n", "4 4\n" ]
[ "6\n", "5\n" ]
In the first sample game lasts for 6 minute by using the following algorithm: - at the beginning of the first minute connect first joystick to the charger, by the end of this minute first joystick is at 4%, second is at 3%; - continue the game without changing charger, by the end of the second minute the first joystick is at 5%, second is at 1%; - at the beginning of the third minute connect second joystick to the charger, after this minute the first joystick is at 3%, the second one is at 2%; - continue the game without changing charger, by the end of the fourth minute first joystick is at 1%, second one is at 3%; - at the beginning of the fifth minute connect first joystick to the charger, after this minute the first joystick is at 2%, the second one is at 1%; - at the beginning of the sixth minute connect second joystick to the charger, after this minute the first joystick is at 0%, the second one is at 2%. After that the first joystick is completely discharged and the game is stopped.
500
[ { "input": "3 5", "output": "6" }, { "input": "4 4", "output": "5" }, { "input": "100 100", "output": "197" }, { "input": "1 100", "output": "98" }, { "input": "100 1", "output": "98" }, { "input": "1 4", "output": "2" }, { "input": "1 1", ...
1,699,977,427
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
8
46
0
energy1, energy2 = map(int, input().split()) print(energy1 + energy2 - 3 + int(energy1 % 2 == 1 and energy2 % 2 == 1))
Title: Joysticks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Friends are going to play console. They have two joysticks and only one charger for them. Initially first joystick is charged at *a*1 percent and second one is charged at *a*2 percent. You can connect charger to a joystick only at the beginning of each minute. In one minute joystick either discharges by 2 percent (if not connected to a charger) or charges by 1 percent (if connected to a charger). Game continues while both joysticks have a positive charge. Hence, if at the beginning of minute some joystick is charged by 1 percent, it has to be connected to a charger, otherwise the game stops. If some joystick completely discharges (its charge turns to 0), the game also stops. Determine the maximum number of minutes that game can last. It is prohibited to pause the game, i. e. at each moment both joysticks should be enabled. It is allowed for joystick to be charged by more than 100 percent. Input Specification: The first line of the input contains two positive integers *a*1 and *a*2 (1<=≤<=*a*1,<=*a*2<=≤<=100), the initial charge level of first and second joystick respectively. Output Specification: Output the only integer, the maximum number of minutes that the game can last. Game continues until some joystick is discharged. Demo Input: ['3 5\n', '4 4\n'] Demo Output: ['6\n', '5\n'] Note: In the first sample game lasts for 6 minute by using the following algorithm: - at the beginning of the first minute connect first joystick to the charger, by the end of this minute first joystick is at 4%, second is at 3%; - continue the game without changing charger, by the end of the second minute the first joystick is at 5%, second is at 1%; - at the beginning of the third minute connect second joystick to the charger, after this minute the first joystick is at 3%, the second one is at 2%; - continue the game without changing charger, by the end of the fourth minute first joystick is at 1%, second one is at 3%; - at the beginning of the fifth minute connect first joystick to the charger, after this minute the first joystick is at 2%, the second one is at 1%; - at the beginning of the sixth minute connect second joystick to the charger, after this minute the first joystick is at 0%, the second one is at 2%. After that the first joystick is completely discharged and the game is stopped.
```python energy1, energy2 = map(int, input().split()) print(energy1 + energy2 - 3 + int(energy1 % 2 == 1 and energy2 % 2 == 1)) ```
0
378
A
Playing with Dice
PROGRAMMING
800
[ "brute force" ]
null
null
Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same difference, it's a draw. The first player wrote number *a*, the second player wrote number *b*. How many ways to throw a dice are there, at which the first player wins, or there is a draw, or the second player wins?
The single line contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=6) — the numbers written on the paper by the first and second player, correspondingly.
Print three integers: the number of ways to throw the dice at which the first player wins, the game ends with a draw or the second player wins, correspondingly.
[ "2 5\n", "2 4\n" ]
[ "3 0 3\n", "2 1 3\n" ]
The dice is a standard cube-shaped six-sided object with each side containing a number from 1 to 6, and where all numbers on all sides are distinct. You can assume that number *a* is closer to number *x* than number *b*, if |*a* - *x*| &lt; |*b* - *x*|.
500
[ { "input": "2 5", "output": "3 0 3" }, { "input": "2 4", "output": "2 1 3" }, { "input": "5 3", "output": "2 1 3" }, { "input": "1 6", "output": "3 0 3" }, { "input": "5 1", "output": "3 1 2" }, { "input": "6 3", "output": "2 0 4" }, { "inp...
1,650,877,815
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
31
0
a,b=map(int,input().split()) x=[] fwcnt=0 draw=0 swcnt=0 for i in range(1,7): if (abs(a-i)<abs(b-i)): fwcnt+=1 x.append(fwcnt) if abs(a-b)==0 or abs(a-b)==2: x.append("1") else: x.append("0") for j in range(1,7): if (abs(a-j)>abs(b-j)): swcnt+=1 x.append(swcnt) print(*x)
Title: Playing with Dice Time Limit: None seconds Memory Limit: None megabytes Problem Description: Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same difference, it's a draw. The first player wrote number *a*, the second player wrote number *b*. How many ways to throw a dice are there, at which the first player wins, or there is a draw, or the second player wins? Input Specification: The single line contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=6) — the numbers written on the paper by the first and second player, correspondingly. Output Specification: Print three integers: the number of ways to throw the dice at which the first player wins, the game ends with a draw or the second player wins, correspondingly. Demo Input: ['2 5\n', '2 4\n'] Demo Output: ['3 0 3\n', '2 1 3\n'] Note: The dice is a standard cube-shaped six-sided object with each side containing a number from 1 to 6, and where all numbers on all sides are distinct. You can assume that number *a* is closer to number *x* than number *b*, if |*a* - *x*| &lt; |*b* - *x*|.
```python a,b=map(int,input().split()) x=[] fwcnt=0 draw=0 swcnt=0 for i in range(1,7): if (abs(a-i)<abs(b-i)): fwcnt+=1 x.append(fwcnt) if abs(a-b)==0 or abs(a-b)==2: x.append("1") else: x.append("0") for j in range(1,7): if (abs(a-j)>abs(b-j)): swcnt+=1 x.append(swcnt) print(*x) ```
0
168
A
Wizards and Demonstration
PROGRAMMING
900
[ "implementation", "math" ]
null
null
Some country is populated by wizards. They want to organize a demonstration. There are *n* people living in the city, *x* of them are the wizards who will surely go to the demonstration. Other city people (*n*<=-<=*x* people) do not support the wizards and aren't going to go to the demonstration. We know that the city administration will react only to the demonstration involving at least *y* percent of the city people. Having considered the matter, the wizards decided to create clone puppets which can substitute the city people on the demonstration. So all in all, the demonstration will involve only the wizards and their puppets. The city administration cannot tell the difference between a puppet and a person, so, as they calculate the percentage, the administration will consider the city to be consisting of only *n* people and not containing any clone puppets. Help the wizards and find the minimum number of clones to create to that the demonstration had no less than *y* percent of the city people.
The first line contains three space-separated integers, *n*, *x*, *y* (1<=≤<=*n*,<=*x*,<=*y*<=≤<=104,<=*x*<=≤<=*n*) — the number of citizens in the city, the number of wizards and the percentage the administration needs, correspondingly. Please note that *y* can exceed 100 percent, that is, the administration wants to see on a demonstration more people that actually live in the city (<=&gt;<=*n*).
Print a single integer — the answer to the problem, the minimum number of clones to create, so that the demonstration involved no less than *y* percent of *n* (the real total city population).
[ "10 1 14\n", "20 10 50\n", "1000 352 146\n" ]
[ "1\n", "0\n", "1108\n" ]
In the first sample it is necessary that at least 14% of 10 people came to the demonstration. As the number of people should be integer, then at least two people should come. There is only one wizard living in the city and he is going to come. That isn't enough, so he needs to create one clone. In the second sample 10 people should come to the demonstration. The city has 10 wizards. They will all come to the demonstration, so nobody has to create any clones.
500
[ { "input": "10 1 14", "output": "1" }, { "input": "20 10 50", "output": "0" }, { "input": "1000 352 146", "output": "1108" }, { "input": "68 65 20", "output": "0" }, { "input": "78 28 27", "output": "0" }, { "input": "78 73 58", "output": "0" }, ...
1,617,364,835
2,147,483,647
PyPy 3
OK
TESTS
43
216
0
import math from math import gcd,floor,sqrt,log def iin(): return int(input()) def sin(): return input().strip() def listin(): return list(map(int,input().strip().split())) def liststr(): return list(map(str,input().strip().split())) def ceill(x): return int(x) if(x==int(x)) else int(x)+1 def ceilldiv(x,d): return x//d if(x%d==0) else x//d+1 def LCM(a,b): return (a*b)//gcd(a,b) def solve(): n,x,y = listin() wiz = x people = n-x req = ceill((y/100)*n) print(max(0,req - wiz)) t = 1 # t = int(input()) for hula in range(t): solve()
Title: Wizards and Demonstration Time Limit: None seconds Memory Limit: None megabytes Problem Description: Some country is populated by wizards. They want to organize a demonstration. There are *n* people living in the city, *x* of them are the wizards who will surely go to the demonstration. Other city people (*n*<=-<=*x* people) do not support the wizards and aren't going to go to the demonstration. We know that the city administration will react only to the demonstration involving at least *y* percent of the city people. Having considered the matter, the wizards decided to create clone puppets which can substitute the city people on the demonstration. So all in all, the demonstration will involve only the wizards and their puppets. The city administration cannot tell the difference between a puppet and a person, so, as they calculate the percentage, the administration will consider the city to be consisting of only *n* people and not containing any clone puppets. Help the wizards and find the minimum number of clones to create to that the demonstration had no less than *y* percent of the city people. Input Specification: The first line contains three space-separated integers, *n*, *x*, *y* (1<=≤<=*n*,<=*x*,<=*y*<=≤<=104,<=*x*<=≤<=*n*) — the number of citizens in the city, the number of wizards and the percentage the administration needs, correspondingly. Please note that *y* can exceed 100 percent, that is, the administration wants to see on a demonstration more people that actually live in the city (<=&gt;<=*n*). Output Specification: Print a single integer — the answer to the problem, the minimum number of clones to create, so that the demonstration involved no less than *y* percent of *n* (the real total city population). Demo Input: ['10 1 14\n', '20 10 50\n', '1000 352 146\n'] Demo Output: ['1\n', '0\n', '1108\n'] Note: In the first sample it is necessary that at least 14% of 10 people came to the demonstration. As the number of people should be integer, then at least two people should come. There is only one wizard living in the city and he is going to come. That isn't enough, so he needs to create one clone. In the second sample 10 people should come to the demonstration. The city has 10 wizards. They will all come to the demonstration, so nobody has to create any clones.
```python import math from math import gcd,floor,sqrt,log def iin(): return int(input()) def sin(): return input().strip() def listin(): return list(map(int,input().strip().split())) def liststr(): return list(map(str,input().strip().split())) def ceill(x): return int(x) if(x==int(x)) else int(x)+1 def ceilldiv(x,d): return x//d if(x%d==0) else x//d+1 def LCM(a,b): return (a*b)//gcd(a,b) def solve(): n,x,y = listin() wiz = x people = n-x req = ceill((y/100)*n) print(max(0,req - wiz)) t = 1 # t = int(input()) for hula in range(t): solve() ```
3
834
A
The Useless Toy
PROGRAMMING
900
[ "implementation" ]
null
null
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays – caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption. Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one): After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in. Slastyona managed to have spinner rotating for exactly *n* seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
There are two characters in the first string – the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), &lt; (ASCII code 60), ^ (ASCII code 94) or &gt; (ASCII code 62) (see the picture above for reference). Characters are separated by a single space. In the second strings, a single number *n* is given (0<=≤<=*n*<=≤<=109) – the duration of the rotation. It is guaranteed that the ending position of a spinner is a result of a *n* second spin in any of the directions, assuming the given starting position.
Output cw, if the direction is clockwise, ccw – if counter-clockwise, and undefined otherwise.
[ "^ &gt;\n1\n", "&lt; ^\n3\n", "^ v\n6\n" ]
[ "cw\n", "ccw\n", "undefined\n" ]
none
500
[ { "input": "^ >\n1", "output": "cw" }, { "input": "< ^\n3", "output": "ccw" }, { "input": "^ v\n6", "output": "undefined" }, { "input": "^ >\n999999999", "output": "ccw" }, { "input": "> v\n1", "output": "cw" }, { "input": "v <\n1", "output": "cw" ...
1,501,426,548
1,248
Python 3
WRONG_ANSWER
TESTS
10
77
4,915,200
x,y=[i for i in input().split(" ")] n=int(input()) if (x=="^" and y=="v") or (x=="v" and y=="^"): print("undefined") else: if (x=="<" and y==">") or (x==">" and y=="<"): print("undefined") else: if (x=="^" and y==">"): if n%3==0: print("ccw") else: print("cw") if (x=="^" and y=="<"): if n%3==0: print("cw") else: print("ccw") if (x=="v" and y==">"): if n%3==0: print("cw") else: print("ccw") if (x=="v" and y=="<"): if n%3==0: print("ccw") else: print("cw") if (x==">" and y=="^"): if n%3==0: print("cw") else: print("ccw") if (x==">" and y=="v"): if n%3==0: print("ccw") else: print("cw") if (x=="<" and y=="^"): if n%3==0: print("ccw") else: print("cw") if (x=="<" and y=="v"): if n%3==0: print("cw") else: print("ccw")
Title: The Useless Toy Time Limit: None seconds Memory Limit: None megabytes Problem Description: Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays – caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption. Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one): After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in. Slastyona managed to have spinner rotating for exactly *n* seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this. Input Specification: There are two characters in the first string – the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), &lt; (ASCII code 60), ^ (ASCII code 94) or &gt; (ASCII code 62) (see the picture above for reference). Characters are separated by a single space. In the second strings, a single number *n* is given (0<=≤<=*n*<=≤<=109) – the duration of the rotation. It is guaranteed that the ending position of a spinner is a result of a *n* second spin in any of the directions, assuming the given starting position. Output Specification: Output cw, if the direction is clockwise, ccw – if counter-clockwise, and undefined otherwise. Demo Input: ['^ &gt;\n1\n', '&lt; ^\n3\n', '^ v\n6\n'] Demo Output: ['cw\n', 'ccw\n', 'undefined\n'] Note: none
```python x,y=[i for i in input().split(" ")] n=int(input()) if (x=="^" and y=="v") or (x=="v" and y=="^"): print("undefined") else: if (x=="<" and y==">") or (x==">" and y=="<"): print("undefined") else: if (x=="^" and y==">"): if n%3==0: print("ccw") else: print("cw") if (x=="^" and y=="<"): if n%3==0: print("cw") else: print("ccw") if (x=="v" and y==">"): if n%3==0: print("cw") else: print("ccw") if (x=="v" and y=="<"): if n%3==0: print("ccw") else: print("cw") if (x==">" and y=="^"): if n%3==0: print("cw") else: print("ccw") if (x==">" and y=="v"): if n%3==0: print("ccw") else: print("cw") if (x=="<" and y=="^"): if n%3==0: print("ccw") else: print("cw") if (x=="<" and y=="v"): if n%3==0: print("cw") else: print("ccw") ```
0
414
B
Mashmokh and ACM
PROGRAMMING
1,400
[ "combinatorics", "dp", "number theory" ]
null
null
Mashmokh's boss, Bimokh, didn't like Mashmokh. So he fired him. Mashmokh decided to go to university and participate in ACM instead of finding a new job. He wants to become a member of Bamokh's team. In order to join he was given some programming tasks and one week to solve them. Mashmokh is not a very experienced programmer. Actually he is not a programmer at all. So he wasn't able to solve them. That's why he asked you to help him with these tasks. One of these tasks is the following. A sequence of *l* integers *b*1,<=*b*2,<=...,<=*b**l* (1<=≤<=*b*1<=≤<=*b*2<=≤<=...<=≤<=*b**l*<=≤<=*n*) is called good if each number divides (without a remainder) by the next number in the sequence. More formally for all *i* (1<=≤<=*i*<=≤<=*l*<=-<=1). Given *n* and *k* find the number of good sequences of length *k*. As the answer can be rather large print it modulo 1000000007 (109<=+<=7).
The first line of input contains two space-separated integers *n*,<=*k* (1<=≤<=*n*,<=*k*<=≤<=2000).
Output a single integer — the number of good sequences of length *k* modulo 1000000007 (109<=+<=7).
[ "3 2\n", "6 4\n", "2 1\n" ]
[ "5\n", "39\n", "2\n" ]
In the first sample the good sequences are: [1, 1], [2, 2], [3, 3], [1, 2], [1, 3].
1,000
[ { "input": "3 2", "output": "5" }, { "input": "6 4", "output": "39" }, { "input": "2 1", "output": "2" }, { "input": "1478 194", "output": "312087753" }, { "input": "1415 562", "output": "953558593" }, { "input": "1266 844", "output": "735042656" ...
1,431,566,995
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
3
1,000
4,608,000
MOD = 10**9 + 7 N, K = [int(k) for k in input().split()] dp = [[0 for _ in range(K+1)] for _ in range(N+1)] for i in range(1,N+1): dp[i][1] = 1 for k in range(1,K+1): for n in range(1,N+1): t = 1 while t*n <= N: dp[n*t][k] += dp[n][k-1] dp[n*t][k]%= MOD t+=1 s = 0 for n in range(1,N+1): s+=dp[n][K] s%= MOD print(s)
Title: Mashmokh and ACM Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mashmokh's boss, Bimokh, didn't like Mashmokh. So he fired him. Mashmokh decided to go to university and participate in ACM instead of finding a new job. He wants to become a member of Bamokh's team. In order to join he was given some programming tasks and one week to solve them. Mashmokh is not a very experienced programmer. Actually he is not a programmer at all. So he wasn't able to solve them. That's why he asked you to help him with these tasks. One of these tasks is the following. A sequence of *l* integers *b*1,<=*b*2,<=...,<=*b**l* (1<=≤<=*b*1<=≤<=*b*2<=≤<=...<=≤<=*b**l*<=≤<=*n*) is called good if each number divides (without a remainder) by the next number in the sequence. More formally for all *i* (1<=≤<=*i*<=≤<=*l*<=-<=1). Given *n* and *k* find the number of good sequences of length *k*. As the answer can be rather large print it modulo 1000000007 (109<=+<=7). Input Specification: The first line of input contains two space-separated integers *n*,<=*k* (1<=≤<=*n*,<=*k*<=≤<=2000). Output Specification: Output a single integer — the number of good sequences of length *k* modulo 1000000007 (109<=+<=7). Demo Input: ['3 2\n', '6 4\n', '2 1\n'] Demo Output: ['5\n', '39\n', '2\n'] Note: In the first sample the good sequences are: [1, 1], [2, 2], [3, 3], [1, 2], [1, 3].
```python MOD = 10**9 + 7 N, K = [int(k) for k in input().split()] dp = [[0 for _ in range(K+1)] for _ in range(N+1)] for i in range(1,N+1): dp[i][1] = 1 for k in range(1,K+1): for n in range(1,N+1): t = 1 while t*n <= N: dp[n*t][k] += dp[n][k-1] dp[n*t][k]%= MOD t+=1 s = 0 for n in range(1,N+1): s+=dp[n][K] s%= MOD print(s) ```
0
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 Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square.
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,687,103,873
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
31
0
def calc(): n = int(input()) m = int(input()) a = int(input()) if m / a ==0: val1= m//a else : val1 = m // a +1 if n / a ==0: val2 = n//a else : val2 = n //a +1 print(val1*val2) calc()
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 flagstone is of the size *a*<=×<=*a*. What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square. Input Specification: The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). Output Specification: Write the needed number of flagstones. Demo Input: ['6 6 4\n'] Demo Output: ['4\n'] Note: none
```python def calc(): n = int(input()) m = int(input()) a = int(input()) if m / a ==0: val1= m//a else : val1 = m // a +1 if n / a ==0: val2 = n//a else : val2 = n //a +1 print(val1*val2) calc() ```
-1
686
A
Free Ice Cream
PROGRAMMING
800
[ "constructive algorithms", "implementation" ]
null
null
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer. At the start of the day they have *x* ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the queue wants either to take several ice cream packs for himself and his friends or to give several ice cream packs to Kay and Gerda (carriers that bring ice cream have to stand in the same queue). If a carrier with *d* ice cream packs comes to the house, then Kay and Gerda take all his packs. If a child who wants to take *d* ice cream packs comes to the house, then Kay and Gerda will give him *d* packs if they have enough ice cream, otherwise the child will get no ice cream at all and will leave in distress. Kay wants to find the amount of ice cream they will have after all people will leave from the queue, and Gerda wants to find the number of distressed kids.
The first line contains two space-separated integers *n* and *x* (1<=≤<=*n*<=≤<=1000, 0<=≤<=*x*<=≤<=109). Each of the next *n* lines contains a character '+' or '-', and an integer *d**i*, separated by a space (1<=≤<=*d**i*<=≤<=109). Record "+ *d**i*" in *i*-th line means that a carrier with *d**i* ice cream packs occupies *i*-th place from the start of the queue, and record "- *d**i*" means that a child who wants to take *d**i* packs stands in *i*-th place.
Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress.
[ "5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20\n", "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98\n" ]
[ "22 1\n", "3 2\n" ]
Consider the first sample. 1. Initially Kay and Gerda have 7 packs of ice cream. 1. Carrier brings 5 more, so now they have 12 packs. 1. A kid asks for 10 packs and receives them. There are only 2 packs remaining. 1. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. 1. Carrier bring 40 packs, now Kay and Gerda have 42 packs. 1. Kid asks for 20 packs and receives them. There are 22 packs remaining.
500
[ { "input": "5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20", "output": "22 1" }, { "input": "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98", "output": "3 2" }, { "input": "6 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000", "output": "7000000000 0" }, { ...
1,613,585,281
2,147,483,647
PyPy 3
RUNTIME_ERROR
TESTS
0
124
2,150,400
n,m = map(int,input().split(' ')) result = 0 for i in range(n): x,y = list(input().split(' ')) k = int(y) if(x == '+'): m += y else: if(y <= m): m -= y else: res += 1 print(m,result)
Title: Free Ice Cream Time Limit: None seconds Memory Limit: None megabytes Problem Description: After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer. At the start of the day they have *x* ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the queue wants either to take several ice cream packs for himself and his friends or to give several ice cream packs to Kay and Gerda (carriers that bring ice cream have to stand in the same queue). If a carrier with *d* ice cream packs comes to the house, then Kay and Gerda take all his packs. If a child who wants to take *d* ice cream packs comes to the house, then Kay and Gerda will give him *d* packs if they have enough ice cream, otherwise the child will get no ice cream at all and will leave in distress. Kay wants to find the amount of ice cream they will have after all people will leave from the queue, and Gerda wants to find the number of distressed kids. Input Specification: The first line contains two space-separated integers *n* and *x* (1<=≤<=*n*<=≤<=1000, 0<=≤<=*x*<=≤<=109). Each of the next *n* lines contains a character '+' or '-', and an integer *d**i*, separated by a space (1<=≤<=*d**i*<=≤<=109). Record "+ *d**i*" in *i*-th line means that a carrier with *d**i* ice cream packs occupies *i*-th place from the start of the queue, and record "- *d**i*" means that a child who wants to take *d**i* packs stands in *i*-th place. Output Specification: Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress. Demo Input: ['5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20\n', '5 17\n- 16\n- 2\n- 98\n+ 100\n- 98\n'] Demo Output: ['22 1\n', '3 2\n'] Note: Consider the first sample. 1. Initially Kay and Gerda have 7 packs of ice cream. 1. Carrier brings 5 more, so now they have 12 packs. 1. A kid asks for 10 packs and receives them. There are only 2 packs remaining. 1. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. 1. Carrier bring 40 packs, now Kay and Gerda have 42 packs. 1. Kid asks for 20 packs and receives them. There are 22 packs remaining.
```python n,m = map(int,input().split(' ')) result = 0 for i in range(n): x,y = list(input().split(' ')) k = int(y) if(x == '+'): m += y else: if(y <= m): m -= y else: res += 1 print(m,result) ```
-1
155
A
I_love_\%username\%
PROGRAMMING
800
[ "brute force" ]
null
null
Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him. One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For each contest where this coder participated, he wrote out a single non-negative number — the number of points his favorite coder earned in the contest. Vasya wrote out the points for the contest in the order, in which the contests run (naturally, no two contests ran simultaneously). Vasya considers a coder's performance in a contest amazing in two situations: he can break either his best or his worst performance record. First, it is amazing if during the contest the coder earns strictly more points that he earned on each past contest. Second, it is amazing if during the contest the coder earns strictly less points that he earned on each past contest. A coder's first contest isn't considered amazing. Now he wants to count the number of amazing performances the coder had throughout his whole history of participating in contests. But the list of earned points turned out long and Vasya can't code... That's why he asks you to help him.
The first line contains the single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of contests where the coder participated. The next line contains *n* space-separated non-negative integer numbers — they are the points which the coder has earned. The points are given in the chronological order. All points do not exceed 10000.
Print the single number — the number of amazing performances the coder has had during his whole history of participating in the contests.
[ "5\n100 50 200 150 200\n", "10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242\n" ]
[ "2\n", "4\n" ]
In the first sample the performances number 2 and 3 are amazing. In the second sample the performances number 2, 4, 9 and 10 are amazing.
500
[ { "input": "5\n100 50 200 150 200", "output": "2" }, { "input": "10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242", "output": "4" }, { "input": "1\n6", "output": "0" }, { "input": "2\n2 1", "output": "1" }, { "input": "5\n100 36 53 7 81", "output": "2" ...
1,688,463,622
2,147,483,647
Python 3
OK
TESTS
37
92
0
n = int(input()) a = list(map(int, input().split())) count = 0 best = a[0] worst = a[0] for i in range(1, n): if a[i] > best: count += 1 best = a[i] elif a[i] < worst: count += 1 worst = a[i] print(count)
Title: I_love_\%username\% Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him. One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For each contest where this coder participated, he wrote out a single non-negative number — the number of points his favorite coder earned in the contest. Vasya wrote out the points for the contest in the order, in which the contests run (naturally, no two contests ran simultaneously). Vasya considers a coder's performance in a contest amazing in two situations: he can break either his best or his worst performance record. First, it is amazing if during the contest the coder earns strictly more points that he earned on each past contest. Second, it is amazing if during the contest the coder earns strictly less points that he earned on each past contest. A coder's first contest isn't considered amazing. Now he wants to count the number of amazing performances the coder had throughout his whole history of participating in contests. But the list of earned points turned out long and Vasya can't code... That's why he asks you to help him. Input Specification: The first line contains the single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of contests where the coder participated. The next line contains *n* space-separated non-negative integer numbers — they are the points which the coder has earned. The points are given in the chronological order. All points do not exceed 10000. Output Specification: Print the single number — the number of amazing performances the coder has had during his whole history of participating in the contests. Demo Input: ['5\n100 50 200 150 200\n', '10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242\n'] Demo Output: ['2\n', '4\n'] Note: In the first sample the performances number 2 and 3 are amazing. In the second sample the performances number 2, 4, 9 and 10 are amazing.
```python n = int(input()) a = list(map(int, input().split())) count = 0 best = a[0] worst = a[0] for i in range(1, n): if a[i] > best: count += 1 best = a[i] elif a[i] < worst: count += 1 worst = a[i] print(count) ```
3
264
A
Escape from Stones
PROGRAMMING
1,200
[ "constructive algorithms", "data structures", "implementation", "two pointers" ]
null
null
Squirrel Liss lived in a forest peacefully, but unexpected trouble happens. Stones fall from a mountain. Initially Squirrel Liss occupies an interval [0,<=1]. Next, *n* stones will fall and Liss will escape from the stones. The stones are numbered from 1 to *n* in order. The stones always fall to the center of Liss's interval. When Liss occupies the interval [*k*<=-<=*d*,<=*k*<=+<=*d*] and a stone falls to *k*, she will escape to the left or to the right. If she escapes to the left, her new interval will be [*k*<=-<=*d*,<=*k*]. If she escapes to the right, her new interval will be [*k*,<=*k*<=+<=*d*]. You are given a string *s* of length *n*. If the *i*-th character of *s* is "l" or "r", when the *i*-th stone falls Liss will escape to the left or to the right, respectively. Find the sequence of stones' numbers from left to right after all the *n* stones falls.
The input consists of only one line. The only line contains the string *s* (1<=≤<=|*s*|<=≤<=106). Each character in *s* will be either "l" or "r".
Output *n* lines — on the *i*-th line you should print the *i*-th stone's number from the left.
[ "llrlr\n", "rrlll\n", "lrlrr\n" ]
[ "3\n5\n4\n2\n1\n", "1\n2\n5\n4\n3\n", "2\n4\n5\n3\n1\n" ]
In the first example, the positions of stones 1, 2, 3, 4, 5 will be <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/58fdb5684df807bfcb705a9da9ce175613362b7d.png" style="max-width: 100.0%;max-height: 100.0%;"/>, respectively. So you should print the sequence: 3, 5, 4, 2, 1.
500
[ { "input": "llrlr", "output": "3\n5\n4\n2\n1" }, { "input": "rrlll", "output": "1\n2\n5\n4\n3" }, { "input": "lrlrr", "output": "2\n4\n5\n3\n1" }, { "input": "lllrlrllrl", "output": "4\n6\n9\n10\n8\n7\n5\n3\n2\n1" }, { "input": "llrlrrrlrr", "output": "3\n5\n6...
1,643,041,329
2,147,483,647
Python 3
OK
TESTS
57
1,965
30,003,200
s = input() result = [0] * (len(s)) left = 0 right = len(s) - 1 for i in range(len(s)): if s[i] == 'l': result[right] = i + 1 right -= 1 else: result[left] = i + 1 left += 1 for i in range(len(s)): print(result[i])
Title: Escape from Stones Time Limit: None seconds Memory Limit: None megabytes Problem Description: Squirrel Liss lived in a forest peacefully, but unexpected trouble happens. Stones fall from a mountain. Initially Squirrel Liss occupies an interval [0,<=1]. Next, *n* stones will fall and Liss will escape from the stones. The stones are numbered from 1 to *n* in order. The stones always fall to the center of Liss's interval. When Liss occupies the interval [*k*<=-<=*d*,<=*k*<=+<=*d*] and a stone falls to *k*, she will escape to the left or to the right. If she escapes to the left, her new interval will be [*k*<=-<=*d*,<=*k*]. If she escapes to the right, her new interval will be [*k*,<=*k*<=+<=*d*]. You are given a string *s* of length *n*. If the *i*-th character of *s* is "l" or "r", when the *i*-th stone falls Liss will escape to the left or to the right, respectively. Find the sequence of stones' numbers from left to right after all the *n* stones falls. Input Specification: The input consists of only one line. The only line contains the string *s* (1<=≤<=|*s*|<=≤<=106). Each character in *s* will be either "l" or "r". Output Specification: Output *n* lines — on the *i*-th line you should print the *i*-th stone's number from the left. Demo Input: ['llrlr\n', 'rrlll\n', 'lrlrr\n'] Demo Output: ['3\n5\n4\n2\n1\n', '1\n2\n5\n4\n3\n', '2\n4\n5\n3\n1\n'] Note: In the first example, the positions of stones 1, 2, 3, 4, 5 will be <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/58fdb5684df807bfcb705a9da9ce175613362b7d.png" style="max-width: 100.0%;max-height: 100.0%;"/>, respectively. So you should print the sequence: 3, 5, 4, 2, 1.
```python s = input() result = [0] * (len(s)) left = 0 right = len(s) - 1 for i in range(len(s)): if s[i] == 'l': result[right] = i + 1 right -= 1 else: result[left] = i + 1 left += 1 for i in range(len(s)): print(result[i]) ```
3
461
A
Appleman and Toastman
PROGRAMMING
1,200
[ "greedy", "sortings" ]
null
null
Appleman and Toastman play a game. Initially Appleman gives one group of *n* numbers to the Toastman, then they start to complete the following tasks: - Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. - Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman. After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get?
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=3·105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=106) — the initial group that is given to Toastman.
Print a single integer — the largest possible score.
[ "3\n3 1 5\n", "1\n10\n" ]
[ "26\n", "10\n" ]
Consider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions.
500
[ { "input": "3\n3 1 5", "output": "26" }, { "input": "1\n10", "output": "10" }, { "input": "10\n8 10 2 5 6 2 4 7 2 1", "output": "376" }, { "input": "10\n171308 397870 724672 431255 228496 892002 542924 718337 888642 161821", "output": "40204082" }, { "input": "10\...
1,623,448,708
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
2
93
0
import math n=int(input()) a=list(map(int,input().split())) a.sort(reverse=True) s=0 s+=sum(a) k=n while(k!=1): for i in range(0,n,k): if len(a[i:i+k])==k: s+=sum(a[i:i+k]) k=math.ceil(k/2) print(s)
Title: Appleman and Toastman Time Limit: None seconds Memory Limit: None megabytes Problem Description: Appleman and Toastman play a game. Initially Appleman gives one group of *n* numbers to the Toastman, then they start to complete the following tasks: - Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. - Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman. After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get? Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=3·105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=106) — the initial group that is given to Toastman. Output Specification: Print a single integer — the largest possible score. Demo Input: ['3\n3 1 5\n', '1\n10\n'] Demo Output: ['26\n', '10\n'] Note: Consider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions.
```python import math n=int(input()) a=list(map(int,input().split())) a.sort(reverse=True) s=0 s+=sum(a) k=n while(k!=1): for i in range(0,n,k): if len(a[i:i+k])==k: s+=sum(a[i:i+k]) k=math.ceil(k/2) print(s) ```
0
1,008
A
Romaji
PROGRAMMING
900
[ "implementation", "strings" ]
null
null
Vitya has just started learning Berlanese language. It is known that Berlanese uses the Latin alphabet. Vowel letters are "a", "o", "u", "i", and "e". Other letters are consonant. In Berlanese, there has to be a vowel after every consonant, but there can be any letter after any vowel. The only exception is a consonant "n"; after this letter, there can be any letter (not only a vowel) or there can be no letter at all. For example, the words "harakiri", "yupie", "man", and "nbo" are Berlanese while the words "horse", "king", "my", and "nz" are not. Help Vitya find out if a word $s$ is Berlanese.
The first line of the input contains the string $s$ consisting of $|s|$ ($1\leq |s|\leq 100$) lowercase Latin letters.
Print "YES" (without quotes) if there is a vowel after every consonant except "n", otherwise print "NO". You can print each letter in any case (upper or lower).
[ "sumimasen\n", "ninja\n", "codeforces\n" ]
[ "YES\n", "YES\n", "NO\n" ]
In the first and second samples, a vowel goes after each consonant except "n", so the word is Berlanese. In the third sample, the consonant "c" goes after the consonant "r", and the consonant "s" stands on the end, so the word is not Berlanese.
500
[ { "input": "sumimasen", "output": "YES" }, { "input": "ninja", "output": "YES" }, { "input": "codeforces", "output": "NO" }, { "input": "auuaoonntanonnuewannnnpuuinniwoonennyolonnnvienonpoujinndinunnenannmuveoiuuhikucuziuhunnnmunzancenen", "output": "YES" }, { "in...
1,672,860,856
2,147,483,647
PyPy 3-64
COMPILATION_ERROR
TESTS
0
0
0
string = input() l = len(string) n = "n" vowel = ['a', 'i', 'o', 'u','e'] for i in range(l): if string[i] in vowel or string[i] in n: continue else: if i = l-1: print("NO") exit(0) else: if string[i+1] not in vowel: print("NO") print("YES")
Title: Romaji Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vitya has just started learning Berlanese language. It is known that Berlanese uses the Latin alphabet. Vowel letters are "a", "o", "u", "i", and "e". Other letters are consonant. In Berlanese, there has to be a vowel after every consonant, but there can be any letter after any vowel. The only exception is a consonant "n"; after this letter, there can be any letter (not only a vowel) or there can be no letter at all. For example, the words "harakiri", "yupie", "man", and "nbo" are Berlanese while the words "horse", "king", "my", and "nz" are not. Help Vitya find out if a word $s$ is Berlanese. Input Specification: The first line of the input contains the string $s$ consisting of $|s|$ ($1\leq |s|\leq 100$) lowercase Latin letters. Output Specification: Print "YES" (without quotes) if there is a vowel after every consonant except "n", otherwise print "NO". You can print each letter in any case (upper or lower). Demo Input: ['sumimasen\n', 'ninja\n', 'codeforces\n'] Demo Output: ['YES\n', 'YES\n', 'NO\n'] Note: In the first and second samples, a vowel goes after each consonant except "n", so the word is Berlanese. In the third sample, the consonant "c" goes after the consonant "r", and the consonant "s" stands on the end, so the word is not Berlanese.
```python string = input() l = len(string) n = "n" vowel = ['a', 'i', 'o', 'u','e'] for i in range(l): if string[i] in vowel or string[i] in n: continue else: if i = l-1: print("NO") exit(0) else: if string[i+1] not in vowel: print("NO") print("YES") ```
-1
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. The game ends when there is no more cards. The player who has the maximum sum of numbers on his cards by the end of the game, wins. Sereja and Dima are being greedy. Each of them chooses the card with the larger number during his move. Inna is a friend of Sereja and Dima. She knows which strategy the guys are using, so she wants to determine the final score, given the initial state of the game. Help her.
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,674,801,651
2,147,483,647
Python 3
OK
TESTS
34
46
102,400
n=int(input()) from collections import defaultdict # for _ in range(t): a=list(map(int,input().split())) lp=0 rp=n-1 se=0 di=0 c=0 while(lp<=rp): if c%2==0: # ser if a[lp]>a[rp]: se+=a[lp] lp+=1 else: se+=a[rp] rp-=1 else: # dima if a[lp]>a[rp]: di+=a[lp] lp+=1 else: di+=a[rp] rp-=1 c+=1 print(se,di)
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. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. The game ends when there is no more cards. The player who has the maximum sum of numbers on his cards by the end of the game, wins. Sereja and Dima are being greedy. Each of them chooses the card with the larger number during his move. Inna is a friend of Sereja and Dima. She knows which strategy the guys are using, so she wants to determine the final score, given the initial state of the game. Help her. Input Specification: 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. Output Specification: 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. Demo Input: ['4\n4 1 2 10\n', '7\n1 2 3 4 5 6 7\n'] Demo Output: ['12 5\n', '16 12\n'] Note: 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.
```python n=int(input()) from collections import defaultdict # for _ in range(t): a=list(map(int,input().split())) lp=0 rp=n-1 se=0 di=0 c=0 while(lp<=rp): if c%2==0: # ser if a[lp]>a[rp]: se+=a[lp] lp+=1 else: se+=a[rp] rp-=1 else: # dima if a[lp]>a[rp]: di+=a[lp] lp+=1 else: di+=a[rp] rp-=1 c+=1 print(se,di) ```
3
0
none
none
none
0
[ "none" ]
null
null
Alice and Bob begin their day with a quick game. They first choose a starting number *X*0<=≥<=3 and try to reach one million by the process described below. Alice goes first and then they take alternating turns. In the *i*-th turn, the player whose turn it is selects a prime number smaller than the current number, and announces the smallest multiple of this prime number that is not smaller than the current number. Formally, he or she selects a prime *p*<=&lt;<=*X**i*<=-<=1 and then finds the minimum *X**i*<=≥<=*X**i*<=-<=1 such that *p* divides *X**i*. Note that if the selected prime *p* already divides *X**i*<=-<=1, then the number does not change. Eve has witnessed the state of the game after two turns. Given *X*2, help her determine what is the smallest possible starting number *X*0. Note that the players don't necessarily play optimally. You should consider all possible game evolutions.
The input contains a single integer *X*2 (4<=≤<=*X*2<=≤<=106). It is guaranteed that the integer *X*2 is composite, that is, is not prime.
Output a single integer — the minimum possible *X*0.
[ "14\n", "20\n", "8192\n" ]
[ "6\n", "15\n", "8191\n" ]
In the first test, the smallest possible starting number is *X*<sub class="lower-index">0</sub> = 6. One possible course of the game is as follows: - Alice picks prime 5 and announces *X*<sub class="lower-index">1</sub> = 10 - Bob picks prime 7 and announces *X*<sub class="lower-index">2</sub> = 14. In the second case, let *X*<sub class="lower-index">0</sub> = 15. - Alice picks prime 2 and announces *X*<sub class="lower-index">1</sub> = 16 - Bob picks prime 5 and announces *X*<sub class="lower-index">2</sub> = 20.
0
[ { "input": "14", "output": "6" }, { "input": "20", "output": "15" }, { "input": "8192", "output": "8191" }, { "input": "1000000", "output": "998677" }, { "input": "959806", "output": "239958" }, { "input": "1452", "output": "1206" }, { "inp...
1,563,618,897
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
4
1,500
21,196,800
import math def get_primes(r): result = [] for x in range(2, r): isp = True for y in range(2, int(math.sqrt(x)) + 1): if not x % y: isp = False break if isp: result.append(x) return result class CodeforcesTask947ASolution: def __init__(self): self.result = '' self.x2 = 0 def read_input(self): self.x2 = int(input()) def process_task(self): primes = get_primes(self.x2) #print(primes) factors2 = [x for x in primes if not self.x2 % x] #print(factors2) ones = [] for f2 in factors2: for x in range((self.x2 // f2 - 1) * f2 + 1, self.x2 + 1): ones.append(x) ones = list(set(ones)) #print(ones) zeros = [] for one in ones: factors1 = [x for x in primes if not one % x] #print(factors1, one) for f1 in factors1: zeros.append(one - f1 + 1) zeros = [x for x in zeros if x >= 3] self.result = str(min(zeros)) def get_result(self): return self.result if __name__ == "__main__": Solution = CodeforcesTask947ASolution() Solution.read_input() Solution.process_task() print(Solution.get_result())
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Alice and Bob begin their day with a quick game. They first choose a starting number *X*0<=≥<=3 and try to reach one million by the process described below. Alice goes first and then they take alternating turns. In the *i*-th turn, the player whose turn it is selects a prime number smaller than the current number, and announces the smallest multiple of this prime number that is not smaller than the current number. Formally, he or she selects a prime *p*<=&lt;<=*X**i*<=-<=1 and then finds the minimum *X**i*<=≥<=*X**i*<=-<=1 such that *p* divides *X**i*. Note that if the selected prime *p* already divides *X**i*<=-<=1, then the number does not change. Eve has witnessed the state of the game after two turns. Given *X*2, help her determine what is the smallest possible starting number *X*0. Note that the players don't necessarily play optimally. You should consider all possible game evolutions. Input Specification: The input contains a single integer *X*2 (4<=≤<=*X*2<=≤<=106). It is guaranteed that the integer *X*2 is composite, that is, is not prime. Output Specification: Output a single integer — the minimum possible *X*0. Demo Input: ['14\n', '20\n', '8192\n'] Demo Output: ['6\n', '15\n', '8191\n'] Note: In the first test, the smallest possible starting number is *X*<sub class="lower-index">0</sub> = 6. One possible course of the game is as follows: - Alice picks prime 5 and announces *X*<sub class="lower-index">1</sub> = 10 - Bob picks prime 7 and announces *X*<sub class="lower-index">2</sub> = 14. In the second case, let *X*<sub class="lower-index">0</sub> = 15. - Alice picks prime 2 and announces *X*<sub class="lower-index">1</sub> = 16 - Bob picks prime 5 and announces *X*<sub class="lower-index">2</sub> = 20.
```python import math def get_primes(r): result = [] for x in range(2, r): isp = True for y in range(2, int(math.sqrt(x)) + 1): if not x % y: isp = False break if isp: result.append(x) return result class CodeforcesTask947ASolution: def __init__(self): self.result = '' self.x2 = 0 def read_input(self): self.x2 = int(input()) def process_task(self): primes = get_primes(self.x2) #print(primes) factors2 = [x for x in primes if not self.x2 % x] #print(factors2) ones = [] for f2 in factors2: for x in range((self.x2 // f2 - 1) * f2 + 1, self.x2 + 1): ones.append(x) ones = list(set(ones)) #print(ones) zeros = [] for one in ones: factors1 = [x for x in primes if not one % x] #print(factors1, one) for f1 in factors1: zeros.append(one - f1 + 1) zeros = [x for x in zeros if x >= 3] self.result = str(min(zeros)) def get_result(self): return self.result if __name__ == "__main__": Solution = CodeforcesTask947ASolution() Solution.read_input() Solution.process_task() print(Solution.get_result()) ```
0
626
B
Cards
PROGRAMMING
1,300
[ "constructive algorithms", "dp", "math" ]
null
null
Catherine has a deck of *n* cards, each of which is either red, green, or blue. As long as there are at least two cards left, she can do one of two actions: - take any two (not necessarily adjacent) cards with different colors and exchange them for a new card of the third color; - take any two (not necessarily adjacent) cards with the same color and exchange them for a new card with that color. She repeats this process until there is only one card left. What are the possible colors for the final card?
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200) — the total number of cards. The next line contains a string *s* of length *n* — the colors of the cards. *s* contains only the characters 'B', 'G', and 'R', representing blue, green, and red, respectively.
Print a single string of up to three characters — the possible colors of the final card (using the same symbols as the input) in alphabetical order.
[ "2\nRB\n", "3\nGRG\n", "5\nBBBBB\n" ]
[ "G\n", "BR\n", "B\n" ]
In the first sample, Catherine has one red card and one blue card, which she must exchange for a green card. In the second sample, Catherine has two green cards and one red card. She has two options: she can exchange the two green cards for a green card, then exchange the new green card and the red card for a blue card. Alternatively, she can exchange a green and a red card for a blue card, then exchange the blue card and remaining green card for a red card. In the third sample, Catherine only has blue cards, so she can only exchange them for more blue cards.
750
[ { "input": "2\nRB", "output": "G" }, { "input": "3\nGRG", "output": "BR" }, { "input": "5\nBBBBB", "output": "B" }, { "input": "1\nR", "output": "R" }, { "input": "200\nBBRGRRBBRGGGBGBGBGRRGRGRGRBGRGRRBBGRGBGRRGRRRGGBBRGBGBGBRBBBBBBBGGBRGGRRRGGRGBGBGGBRRRRBRRRBRBB...
1,455,389,660
4,760
Python 3
OK
TESTS
46
62
0
input() s = input() r,g,b=[s.count(x)for x in"RGB"] A,B,C = sorted([(r,"R"),(g,"G"),(b,"B")],reverse=True) if C[0]or B[0]>1: print("BGR") elif B[0] and A[0]>=2:print("".join(sorted(x[1]for x in(B,C)))) elif B[0]:print(C[1]) elif A[0]:print(A[1])
Title: Cards Time Limit: None seconds Memory Limit: None megabytes Problem Description: Catherine has a deck of *n* cards, each of which is either red, green, or blue. As long as there are at least two cards left, she can do one of two actions: - take any two (not necessarily adjacent) cards with different colors and exchange them for a new card of the third color; - take any two (not necessarily adjacent) cards with the same color and exchange them for a new card with that color. She repeats this process until there is only one card left. What are the possible colors for the final card? Input Specification: The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200) — the total number of cards. The next line contains a string *s* of length *n* — the colors of the cards. *s* contains only the characters 'B', 'G', and 'R', representing blue, green, and red, respectively. Output Specification: Print a single string of up to three characters — the possible colors of the final card (using the same symbols as the input) in alphabetical order. Demo Input: ['2\nRB\n', '3\nGRG\n', '5\nBBBBB\n'] Demo Output: ['G\n', 'BR\n', 'B\n'] Note: In the first sample, Catherine has one red card and one blue card, which she must exchange for a green card. In the second sample, Catherine has two green cards and one red card. She has two options: she can exchange the two green cards for a green card, then exchange the new green card and the red card for a blue card. Alternatively, she can exchange a green and a red card for a blue card, then exchange the blue card and remaining green card for a red card. In the third sample, Catherine only has blue cards, so she can only exchange them for more blue cards.
```python input() s = input() r,g,b=[s.count(x)for x in"RGB"] A,B,C = sorted([(r,"R"),(g,"G"),(b,"B")],reverse=True) if C[0]or B[0]>1: print("BGR") elif B[0] and A[0]>=2:print("".join(sorted(x[1]for x in(B,C)))) elif B[0]:print(C[1]) elif A[0]:print(A[1]) ```
3
992
A
Nastya and an Array
PROGRAMMING
800
[ "implementation", "sortings" ]
null
null
Nastya owns too many arrays now, so she wants to delete the least important of them. However, she discovered that this array is magic! Nastya now knows that the array has the following properties: - In one second we can add an arbitrary (possibly negative) integer to all elements of the array that are not equal to zero. - When all elements of the array become equal to zero, the array explodes. Nastya is always busy, so she wants to explode the array as fast as possible. Compute the minimum time in which the array can be exploded.
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the size of the array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=105<=≤<=*a**i*<=≤<=105) — the elements of the array.
Print a single integer — the minimum number of seconds needed to make all elements of the array equal to zero.
[ "5\n1 1 1 1 1\n", "3\n2 0 -1\n", "4\n5 -6 -5 1\n" ]
[ "1\n", "2\n", "4\n" ]
In the first example you can add  - 1 to all non-zero elements in one second and make them equal to zero. In the second example you can add  - 2 on the first second, then the array becomes equal to [0, 0,  - 3]. On the second second you can add 3 to the third (the only non-zero) element.
500
[ { "input": "5\n1 1 1 1 1", "output": "1" }, { "input": "3\n2 0 -1", "output": "2" }, { "input": "4\n5 -6 -5 1", "output": "4" }, { "input": "1\n0", "output": "0" }, { "input": "2\n21794 -79194", "output": "2" }, { "input": "3\n-63526 95085 -5239", ...
1,619,534,100
2,147,483,647
Python 3
OK
TESTS
79
109
8,089,600
x=int(input()) b=[int(i) for i in input().split()] print(len(set(b)-{0}))
Title: Nastya and an Array Time Limit: None seconds Memory Limit: None megabytes Problem Description: Nastya owns too many arrays now, so she wants to delete the least important of them. However, she discovered that this array is magic! Nastya now knows that the array has the following properties: - In one second we can add an arbitrary (possibly negative) integer to all elements of the array that are not equal to zero. - When all elements of the array become equal to zero, the array explodes. Nastya is always busy, so she wants to explode the array as fast as possible. Compute the minimum time in which the array can be exploded. Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the size of the array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=105<=≤<=*a**i*<=≤<=105) — the elements of the array. Output Specification: Print a single integer — the minimum number of seconds needed to make all elements of the array equal to zero. Demo Input: ['5\n1 1 1 1 1\n', '3\n2 0 -1\n', '4\n5 -6 -5 1\n'] Demo Output: ['1\n', '2\n', '4\n'] Note: In the first example you can add  - 1 to all non-zero elements in one second and make them equal to zero. In the second example you can add  - 2 on the first second, then the array becomes equal to [0, 0,  - 3]. On the second second you can add 3 to the third (the only non-zero) element.
```python x=int(input()) b=[int(i) for i in input().split()] print(len(set(b)-{0})) ```
3
276
A
Lunch Rush
PROGRAMMING
900
[ "implementation" ]
null
null
Having written another programming contest, three Rabbits decided to grab some lunch. The coach gave the team exactly *k* time units for the lunch break. The Rabbits have a list of *n* restaurants to lunch in: the *i*-th restaurant is characterized by two integers *f**i* and *t**i*. Value *t**i* shows the time the Rabbits need to lunch in the *i*-th restaurant. If time *t**i* exceeds the time *k* that the coach has given for the lunch break, then the Rabbits' joy from lunching in this restaurant will equal *f**i*<=-<=(*t**i*<=-<=*k*). Otherwise, the Rabbits get exactly *f**i* units of joy. Your task is to find the value of the maximum joy the Rabbits can get from the lunch, depending on the restaurant. The Rabbits must choose exactly one restaurant to lunch in. Note that the joy value isn't necessarily a positive value.
The first line contains two space-separated integers — *n* (1<=≤<=*n*<=≤<=104) and *k* (1<=≤<=*k*<=≤<=109) — the number of restaurants in the Rabbits' list and the time the coach has given them to lunch, correspondingly. Each of the next *n* lines contains two space-separated integers — *f**i* (1<=≤<=*f**i*<=≤<=109) and *t**i* (1<=≤<=*t**i*<=≤<=109) — the characteristics of the *i*-th restaurant.
In a single line print a single integer — the maximum joy value that the Rabbits will get from the lunch.
[ "2 5\n3 3\n4 5\n", "4 6\n5 8\n3 6\n2 3\n2 2\n", "1 5\n1 7\n" ]
[ "4\n", "3\n", "-1\n" ]
none
500
[ { "input": "2 5\n3 3\n4 5", "output": "4" }, { "input": "4 6\n5 8\n3 6\n2 3\n2 2", "output": "3" }, { "input": "1 5\n1 7", "output": "-1" }, { "input": "4 9\n10 13\n4 18\n13 3\n10 6", "output": "13" }, { "input": "1 1\n1 1000000000", "output": "-999999998" }...
1,673,215,697
2,147,483,647
PyPy 3
OK
TESTS
35
342
3,891,200
n, k = map(int, input().split()) ans = [] for i in range(n): f, t = map(int, input().split()) if t > k: ans.append(f - (t - k)) else: ans.append(f) print(max(ans))
Title: Lunch Rush Time Limit: None seconds Memory Limit: None megabytes Problem Description: Having written another programming contest, three Rabbits decided to grab some lunch. The coach gave the team exactly *k* time units for the lunch break. The Rabbits have a list of *n* restaurants to lunch in: the *i*-th restaurant is characterized by two integers *f**i* and *t**i*. Value *t**i* shows the time the Rabbits need to lunch in the *i*-th restaurant. If time *t**i* exceeds the time *k* that the coach has given for the lunch break, then the Rabbits' joy from lunching in this restaurant will equal *f**i*<=-<=(*t**i*<=-<=*k*). Otherwise, the Rabbits get exactly *f**i* units of joy. Your task is to find the value of the maximum joy the Rabbits can get from the lunch, depending on the restaurant. The Rabbits must choose exactly one restaurant to lunch in. Note that the joy value isn't necessarily a positive value. Input Specification: The first line contains two space-separated integers — *n* (1<=≤<=*n*<=≤<=104) and *k* (1<=≤<=*k*<=≤<=109) — the number of restaurants in the Rabbits' list and the time the coach has given them to lunch, correspondingly. Each of the next *n* lines contains two space-separated integers — *f**i* (1<=≤<=*f**i*<=≤<=109) and *t**i* (1<=≤<=*t**i*<=≤<=109) — the characteristics of the *i*-th restaurant. Output Specification: In a single line print a single integer — the maximum joy value that the Rabbits will get from the lunch. Demo Input: ['2 5\n3 3\n4 5\n', '4 6\n5 8\n3 6\n2 3\n2 2\n', '1 5\n1 7\n'] Demo Output: ['4\n', '3\n', '-1\n'] Note: none
```python n, k = map(int, input().split()) ans = [] for i in range(n): f, t = map(int, input().split()) if t > k: ans.append(f - (t - k)) else: ans.append(f) print(max(ans)) ```
3
914
A
Perfect Squares
PROGRAMMING
900
[ "brute force", "implementation", "math" ]
null
null
Given an array *a*1,<=*a*2,<=...,<=*a**n* of *n* integers, find the largest number in the array that is not a perfect square. A number *x* is said to be a perfect square if there exists an integer *y* such that *x*<==<=*y*2.
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of elements in the array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=106<=≤<=*a**i*<=≤<=106) — the elements of the array. It is guaranteed that at least one element of the array is not a perfect square.
Print the largest number in the array which is not a perfect square. It is guaranteed that an answer always exists.
[ "2\n4 2\n", "8\n1 2 4 8 16 32 64 576\n" ]
[ "2\n", "32\n" ]
In the first sample case, 4 is a perfect square, so the largest number in the array that is not a perfect square is 2.
500
[ { "input": "2\n4 2", "output": "2" }, { "input": "8\n1 2 4 8 16 32 64 576", "output": "32" }, { "input": "3\n-1 -4 -9", "output": "-1" }, { "input": "5\n918375 169764 598796 76602 538757", "output": "918375" }, { "input": "5\n804610 765625 2916 381050 93025", ...
1,682,650,150
2,147,483,647
PyPy 3-64
RUNTIME_ERROR
TESTS
2
62
2,867,200
import math n = int(input()) a = list(map(int, input().split())) max_num = -1 for num in a: if math.sqrt(num) % 1 != 0: max_num = max(max_num, num) print(max_num)
Title: Perfect Squares Time Limit: None seconds Memory Limit: None megabytes Problem Description: Given an array *a*1,<=*a*2,<=...,<=*a**n* of *n* integers, find the largest number in the array that is not a perfect square. A number *x* is said to be a perfect square if there exists an integer *y* such that *x*<==<=*y*2. Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of elements in the array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=106<=≤<=*a**i*<=≤<=106) — the elements of the array. It is guaranteed that at least one element of the array is not a perfect square. Output Specification: Print the largest number in the array which is not a perfect square. It is guaranteed that an answer always exists. Demo Input: ['2\n4 2\n', '8\n1 2 4 8 16 32 64 576\n'] Demo Output: ['2\n', '32\n'] Note: In the first sample case, 4 is a perfect square, so the largest number in the array that is not a perfect square is 2.
```python import math n = int(input()) a = list(map(int, input().split())) max_num = -1 for num in a: if math.sqrt(num) % 1 != 0: max_num = max(max_num, num) print(max_num) ```
-1
368
B
Sereja and Suffixes
PROGRAMMING
1,100
[ "data structures", "dp" ]
null
null
Sereja has an array *a*, consisting of *n* integers *a*1, *a*2, ..., *a**n*. The boy cannot sit and do nothing, he decided to study an array. Sereja took a piece of paper and wrote out *m* integers *l*1,<=*l*2,<=...,<=*l**m* (1<=≤<=*l**i*<=≤<=*n*). For each number *l**i* he wants to know how many distinct numbers are staying on the positions *l**i*, *l**i*<=+<=1, ..., *n*. Formally, he want to find the number of distinct numbers among *a**l**i*,<=*a**l**i*<=+<=1,<=...,<=*a**n*.? Sereja wrote out the necessary array elements but the array was so large and the boy was so pressed for time. Help him, find the answer for the described question for each *l**i*.
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105) — the array elements. Next *m* lines contain integers *l*1,<=*l*2,<=...,<=*l**m*. The *i*-th line contains integer *l**i* (1<=≤<=*l**i*<=≤<=*n*).
Print *m* lines — on the *i*-th line print the answer to the number *l**i*.
[ "10 10\n1 2 3 4 1 2 3 4 100000 99999\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" ]
[ "6\n6\n6\n6\n6\n5\n4\n3\n2\n1\n" ]
none
1,000
[ { "input": "10 10\n1 2 3 4 1 2 3 4 100000 99999\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10", "output": "6\n6\n6\n6\n6\n5\n4\n3\n2\n1" }, { "input": "8 3\n8 6 4 3 4 2 4 8\n6\n4\n2", "output": "3\n4\n5" }, { "input": "7 10\n1 3 8 6 2 2 7\n4\n2\n6\n3\n4\n4\n6\n2\n7\n4", "output": "3\n5\n2\n4\n3\n3\...
1,698,549,447
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
10
1,000
10,649,600
n,m=map(int,input().split()) digits=list(map(int,input().split())) keys=[] ans={} for i in range(m): a=int(input()) keys.append(a) keys_copy=keys[:] keys.sort(reverse=True) old=n+1 ans1=set() for i in keys: ans[i]=len(set(digits[i-1:old]+list(ans1))) ans1=set(digits[i-1:old]+list(ans1)) old=i-1 for k in keys_copy: print(ans[k])
Title: Sereja and Suffixes Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sereja has an array *a*, consisting of *n* integers *a*1, *a*2, ..., *a**n*. The boy cannot sit and do nothing, he decided to study an array. Sereja took a piece of paper and wrote out *m* integers *l*1,<=*l*2,<=...,<=*l**m* (1<=≤<=*l**i*<=≤<=*n*). For each number *l**i* he wants to know how many distinct numbers are staying on the positions *l**i*, *l**i*<=+<=1, ..., *n*. Formally, he want to find the number of distinct numbers among *a**l**i*,<=*a**l**i*<=+<=1,<=...,<=*a**n*.? Sereja wrote out the necessary array elements but the array was so large and the boy was so pressed for time. Help him, find the answer for the described question for each *l**i*. Input Specification: The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105) — the array elements. Next *m* lines contain integers *l*1,<=*l*2,<=...,<=*l**m*. The *i*-th line contains integer *l**i* (1<=≤<=*l**i*<=≤<=*n*). Output Specification: Print *m* lines — on the *i*-th line print the answer to the number *l**i*. Demo Input: ['10 10\n1 2 3 4 1 2 3 4 100000 99999\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n'] Demo Output: ['6\n6\n6\n6\n6\n5\n4\n3\n2\n1\n'] Note: none
```python n,m=map(int,input().split()) digits=list(map(int,input().split())) keys=[] ans={} for i in range(m): a=int(input()) keys.append(a) keys_copy=keys[:] keys.sort(reverse=True) old=n+1 ans1=set() for i in keys: ans[i]=len(set(digits[i-1:old]+list(ans1))) ans1=set(digits[i-1:old]+list(ans1)) old=i-1 for k in keys_copy: print(ans[k]) ```
0
488
A
Giga Tower
PROGRAMMING
1,100
[ "brute force" ]
null
null
Giga Tower is the tallest and deepest building in Cyberland. There are 17<=777<=777<=777 floors, numbered from <=-<=8<=888<=888<=888 to 8<=888<=888<=888. In particular, there is floor 0 between floor <=-<=1 and floor 1. Every day, thousands of tourists come to this place to enjoy the wonderful view. In Cyberland, it is believed that the number "8" is a lucky number (that's why Giga Tower has 8<=888<=888<=888 floors above the ground), and, an integer is lucky, if and only if its decimal notation contains at least one digit "8". For example, 8,<=<=-<=180,<=808 are all lucky while 42,<=<=-<=10 are not. In the Giga Tower, if you write code at a floor with lucky floor number, good luck will always be with you (Well, this round is #278, also lucky, huh?). Tourist Henry goes to the tower to seek good luck. Now he is at the floor numbered *a*. He wants to find the minimum positive integer *b*, such that, if he walks *b* floors higher, he will arrive at a floor with a lucky number.
The only line of input contains an integer *a* (<=-<=109<=≤<=*a*<=≤<=109).
Print the minimum *b* in a line.
[ "179\n", "-1\n", "18\n" ]
[ "1\n", "9\n", "10\n" ]
For the first sample, he has to arrive at the floor numbered 180. For the second sample, he will arrive at 8. Note that *b* should be positive, so the answer for the third sample is 10, not 0.
500
[ { "input": "179", "output": "1" }, { "input": "-1", "output": "9" }, { "input": "18", "output": "10" }, { "input": "-410058385", "output": "1" }, { "input": "-586825624", "output": "1" }, { "input": "852318890", "output": "1" }, { "input": ...
1,568,141,712
2,147,483,647
Python 3
OK
TESTS
35
109
0
n=int(input()) n=str(n) x=int(0) while(1): x+=1 n=str(int(n)+1) if('8' in n): break print(x)
Title: Giga Tower Time Limit: None seconds Memory Limit: None megabytes Problem Description: Giga Tower is the tallest and deepest building in Cyberland. There are 17<=777<=777<=777 floors, numbered from <=-<=8<=888<=888<=888 to 8<=888<=888<=888. In particular, there is floor 0 between floor <=-<=1 and floor 1. Every day, thousands of tourists come to this place to enjoy the wonderful view. In Cyberland, it is believed that the number "8" is a lucky number (that's why Giga Tower has 8<=888<=888<=888 floors above the ground), and, an integer is lucky, if and only if its decimal notation contains at least one digit "8". For example, 8,<=<=-<=180,<=808 are all lucky while 42,<=<=-<=10 are not. In the Giga Tower, if you write code at a floor with lucky floor number, good luck will always be with you (Well, this round is #278, also lucky, huh?). Tourist Henry goes to the tower to seek good luck. Now he is at the floor numbered *a*. He wants to find the minimum positive integer *b*, such that, if he walks *b* floors higher, he will arrive at a floor with a lucky number. Input Specification: The only line of input contains an integer *a* (<=-<=109<=≤<=*a*<=≤<=109). Output Specification: Print the minimum *b* in a line. Demo Input: ['179\n', '-1\n', '18\n'] Demo Output: ['1\n', '9\n', '10\n'] Note: For the first sample, he has to arrive at the floor numbered 180. For the second sample, he will arrive at 8. Note that *b* should be positive, so the answer for the third sample is 10, not 0.
```python n=int(input()) n=str(n) x=int(0) while(1): x+=1 n=str(int(n)+1) if('8' in n): break print(x) ```
3
621
A
Wet Shark and Odd and Even
PROGRAMMING
900
[ "implementation" ]
null
null
Today, Wet Shark is given *n* integers. Using any of these integers no more than once, Wet Shark wants to get maximum possible even (divisible by 2) sum. Please, calculate this value for Wet Shark. Note, that if Wet Shark uses no integers from the *n* integers, the sum is an even integer 0.
The first line of the input contains one integer, *n* (1<=≤<=*n*<=≤<=100<=000). The next line contains *n* space separated integers given to Wet Shark. Each of these integers is in range from 1 to 109, inclusive.
Print the maximum possible even sum that can be obtained if we use some of the given integers.
[ "3\n1 2 3\n", "5\n999999999 999999999 999999999 999999999 999999999\n" ]
[ "6", "3999999996" ]
In the first sample, we can simply take all three integers for a total sum of 6. In the second sample Wet Shark should take any four out of five integers 999 999 999.
500
[ { "input": "3\n1 2 3", "output": "6" }, { "input": "5\n999999999 999999999 999999999 999999999 999999999", "output": "3999999996" }, { "input": "1\n1", "output": "0" }, { "input": "15\n39 52 88 78 46 95 84 98 55 3 68 42 6 18 98", "output": "870" }, { "input": "15\...
1,624,868,626
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
46
0
nr_of_ints = int(input()) raw_ints = input() ints = list(map(int, raw_ints.split(' '))) start = time.time() min_odd = 10**9+1 sum = 0 for x in range(nr_of_ints): sum += ints[x] if ints[x] % 2: min_odd = min(min_odd, ints[x]) if best_val % 2: best_val -= min_odd print(best_val)
Title: Wet Shark and Odd and Even Time Limit: None seconds Memory Limit: None megabytes Problem Description: Today, Wet Shark is given *n* integers. Using any of these integers no more than once, Wet Shark wants to get maximum possible even (divisible by 2) sum. Please, calculate this value for Wet Shark. Note, that if Wet Shark uses no integers from the *n* integers, the sum is an even integer 0. Input Specification: The first line of the input contains one integer, *n* (1<=≤<=*n*<=≤<=100<=000). The next line contains *n* space separated integers given to Wet Shark. Each of these integers is in range from 1 to 109, inclusive. Output Specification: Print the maximum possible even sum that can be obtained if we use some of the given integers. Demo Input: ['3\n1 2 3\n', '5\n999999999 999999999 999999999 999999999 999999999\n'] Demo Output: ['6', '3999999996'] Note: In the first sample, we can simply take all three integers for a total sum of 6. In the second sample Wet Shark should take any four out of five integers 999 999 999.
```python nr_of_ints = int(input()) raw_ints = input() ints = list(map(int, raw_ints.split(' '))) start = time.time() min_odd = 10**9+1 sum = 0 for x in range(nr_of_ints): sum += ints[x] if ints[x] % 2: min_odd = min(min_odd, ints[x]) if best_val % 2: best_val -= min_odd print(best_val) ```
-1
476
B
Dreamoon and WiFi
PROGRAMMING
1,300
[ "bitmasks", "brute force", "combinatorics", "dp", "math", "probabilities" ]
null
null
Dreamoon is standing at the position 0 on a number line. Drazil is sending a list of commands through Wi-Fi to Dreamoon's smartphone and Dreamoon follows them. Each command is one of the following two types: 1. Go 1 unit towards the positive direction, denoted as '+' 1. Go 1 unit towards the negative direction, denoted as '-' But the Wi-Fi condition is so poor that Dreamoon's smartphone reports some of the commands can't be recognized and Dreamoon knows that some of them might even be wrong though successfully recognized. Dreamoon decides to follow every recognized command and toss a fair coin to decide those unrecognized ones (that means, he moves to the 1 unit to the negative or positive direction with the same probability 0.5). You are given an original list of commands sent by Drazil and list received by Dreamoon. What is the probability that Dreamoon ends in the position originally supposed to be final by Drazil's commands?
The first line contains a string *s*1 — the commands Drazil sends to Dreamoon, this string consists of only the characters in the set {'+', '-'}. The second line contains a string *s*2 — the commands Dreamoon's smartphone recognizes, this string consists of only the characters in the set {'+', '-', '?'}. '?' denotes an unrecognized command. Lengths of two strings are equal and do not exceed 10.
Output a single real number corresponding to the probability. The answer will be considered correct if its relative or absolute error doesn't exceed 10<=-<=9.
[ "++-+-\n+-+-+\n", "+-+-\n+-??\n", "+++\n??-\n" ]
[ "1.000000000000\n", "0.500000000000\n", "0.000000000000\n" ]
For the first sample, both *s*<sub class="lower-index">1</sub> and *s*<sub class="lower-index">2</sub> will lead Dreamoon to finish at the same position  + 1. For the second sample, *s*<sub class="lower-index">1</sub> will lead Dreamoon to finish at position 0, while there are four possibilites for *s*<sub class="lower-index">2</sub>: {"+-++", "+-+-", "+--+", "+---"} with ending position {+2, 0, 0, -2} respectively. So there are 2 correct cases out of 4, so the probability of finishing at the correct position is 0.5. For the third sample, *s*<sub class="lower-index">2</sub> could only lead us to finish at positions {+1, -1, -3}, so the probability to finish at the correct position  + 3 is 0.
1,500
[ { "input": "++-+-\n+-+-+", "output": "1.000000000000" }, { "input": "+-+-\n+-??", "output": "0.500000000000" }, { "input": "+++\n??-", "output": "0.000000000000" }, { "input": "++++++++++\n+++??++?++", "output": "0.125000000000" }, { "input": "--+++---+-\n????????...
1,651,799,242
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
30
0
import numpy as np def main(): s1 = input() s2 = input() n = len(s1) * 2 + 1 level = len(s1) pos = len(s1) for i in range(0, len(s1)): pos = pos - 1 if s1[i] == '-' else pos + 1 lookup = np.zeros(shape=(n, n)) lookup[0][level] = 1 for i in range(1, len(s1) + 1): if s2[i-1] == '+': for j in range(1, n): lookup[i][j] = lookup[i-1][j-1] if s2[i-1] == '-': for j in range(0, n - 1): lookup[i][j] = lookup[i-1][j+1] if s2[i-1] == '?': for j in range(1, n - 1): lookup[i][j] = (0.5*lookup[i-1][j+1]) + (0.5 * lookup[i-1][j-1]) print(lookup[len(s1)][pos]) if __name__ == '__main__': main()
Title: Dreamoon and WiFi Time Limit: None seconds Memory Limit: None megabytes Problem Description: Dreamoon is standing at the position 0 on a number line. Drazil is sending a list of commands through Wi-Fi to Dreamoon's smartphone and Dreamoon follows them. Each command is one of the following two types: 1. Go 1 unit towards the positive direction, denoted as '+' 1. Go 1 unit towards the negative direction, denoted as '-' But the Wi-Fi condition is so poor that Dreamoon's smartphone reports some of the commands can't be recognized and Dreamoon knows that some of them might even be wrong though successfully recognized. Dreamoon decides to follow every recognized command and toss a fair coin to decide those unrecognized ones (that means, he moves to the 1 unit to the negative or positive direction with the same probability 0.5). You are given an original list of commands sent by Drazil and list received by Dreamoon. What is the probability that Dreamoon ends in the position originally supposed to be final by Drazil's commands? Input Specification: The first line contains a string *s*1 — the commands Drazil sends to Dreamoon, this string consists of only the characters in the set {'+', '-'}. The second line contains a string *s*2 — the commands Dreamoon's smartphone recognizes, this string consists of only the characters in the set {'+', '-', '?'}. '?' denotes an unrecognized command. Lengths of two strings are equal and do not exceed 10. Output Specification: Output a single real number corresponding to the probability. The answer will be considered correct if its relative or absolute error doesn't exceed 10<=-<=9. Demo Input: ['++-+-\n+-+-+\n', '+-+-\n+-??\n', '+++\n??-\n'] Demo Output: ['1.000000000000\n', '0.500000000000\n', '0.000000000000\n'] Note: For the first sample, both *s*<sub class="lower-index">1</sub> and *s*<sub class="lower-index">2</sub> will lead Dreamoon to finish at the same position  + 1. For the second sample, *s*<sub class="lower-index">1</sub> will lead Dreamoon to finish at position 0, while there are four possibilites for *s*<sub class="lower-index">2</sub>: {"+-++", "+-+-", "+--+", "+---"} with ending position {+2, 0, 0, -2} respectively. So there are 2 correct cases out of 4, so the probability of finishing at the correct position is 0.5. For the third sample, *s*<sub class="lower-index">2</sub> could only lead us to finish at positions {+1, -1, -3}, so the probability to finish at the correct position  + 3 is 0.
```python import numpy as np def main(): s1 = input() s2 = input() n = len(s1) * 2 + 1 level = len(s1) pos = len(s1) for i in range(0, len(s1)): pos = pos - 1 if s1[i] == '-' else pos + 1 lookup = np.zeros(shape=(n, n)) lookup[0][level] = 1 for i in range(1, len(s1) + 1): if s2[i-1] == '+': for j in range(1, n): lookup[i][j] = lookup[i-1][j-1] if s2[i-1] == '-': for j in range(0, n - 1): lookup[i][j] = lookup[i-1][j+1] if s2[i-1] == '?': for j in range(1, n - 1): lookup[i][j] = (0.5*lookup[i-1][j+1]) + (0.5 * lookup[i-1][j-1]) print(lookup[len(s1)][pos]) if __name__ == '__main__': main() ```
-1
617
A
Elephant
PROGRAMMING
800
[ "math" ]
null
null
An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=&gt;<=0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determine, what is the minimum number of steps he need to make in order to get to his friend's house.
The first line of the input contains an integer *x* (1<=≤<=*x*<=≤<=1<=000<=000) — The coordinate of the friend's house.
Print the minimum number of steps that elephant needs to make to get from point 0 to point *x*.
[ "5\n", "12\n" ]
[ "1\n", "3\n" ]
In the first sample the elephant needs to make one step of length 5 to reach the point *x*. In the second sample the elephant can get to point *x* if he moves by 3, 5 and 4. There are other ways to get the optimal answer but the elephant cannot reach *x* in less than three moves.
500
[ { "input": "5", "output": "1" }, { "input": "12", "output": "3" }, { "input": "999999", "output": "200000" }, { "input": "41", "output": "9" }, { "input": "1000000", "output": "200000" }, { "input": "1", "output": "1" }, { "input": "2", ...
1,699,782,814
2,147,483,647
Python 3
OK
TESTS
34
62
0
a = int(input()) n = 0 while a > 0: if a >= 5: a -= 5 n += 1 elif a >= 4: a -= 4 n += 1 elif a >= 3: a -= 3 n += 1 elif a >= 2: a -= 2 n += 1 else: a -= 1 n += 1 print(n)
Title: Elephant Time Limit: None seconds Memory Limit: None megabytes Problem Description: An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=&gt;<=0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determine, what is the minimum number of steps he need to make in order to get to his friend's house. Input Specification: The first line of the input contains an integer *x* (1<=≤<=*x*<=≤<=1<=000<=000) — The coordinate of the friend's house. Output Specification: Print the minimum number of steps that elephant needs to make to get from point 0 to point *x*. Demo Input: ['5\n', '12\n'] Demo Output: ['1\n', '3\n'] Note: In the first sample the elephant needs to make one step of length 5 to reach the point *x*. In the second sample the elephant can get to point *x* if he moves by 3, 5 and 4. There are other ways to get the optimal answer but the elephant cannot reach *x* in less than three moves.
```python a = int(input()) n = 0 while a > 0: if a >= 5: a -= 5 n += 1 elif a >= 4: a -= 4 n += 1 elif a >= 3: a -= 3 n += 1 elif a >= 2: a -= 2 n += 1 else: a -= 1 n += 1 print(n) ```
3
456
A
Laptops
PROGRAMMING
1,100
[ "sortings" ]
null
null
One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the first laptop is less (strictly smaller) than the price of the second laptop but the quality of the first laptop is higher (strictly greater) than the quality of the second laptop. Please, check the guess of Alex. You are given descriptions of *n* laptops. Determine whether two described above laptops exist.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=105) — the number of laptops. Next *n* lines contain two integers each, *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*), where *a**i* is the price of the *i*-th laptop, and *b**i* is the number that represents the quality of the *i*-th laptop (the larger the number is, the higher is the quality). All *a**i* are distinct. All *b**i* are distinct.
If Alex is correct, print "Happy Alex", otherwise print "Poor Alex" (without the quotes).
[ "2\n1 2\n2 1\n" ]
[ "Happy Alex\n" ]
none
500
[ { "input": "2\n1 2\n2 1", "output": "Happy Alex" }, { "input": "2\n1 1\n2 2", "output": "Poor Alex" }, { "input": "3\n2 2\n3 3\n1 1", "output": "Poor Alex" }, { "input": "3\n3 3\n1 2\n2 1", "output": "Happy Alex" }, { "input": "1\n1 1", "output": "Poor Alex" ...
1,670,164,739
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
1
46
0
n=int(input()) l1=[] for i in range(n): l=list(map(int,input().split())) l1.append(l) l1.sort() c=0 for i in range(len(l1)): if(l1[i][0]< l1[i+1][0]): if(l1[i][1]>l1[i+1][1]): c=1 break print('Happy Alex') if(c==1): print('Happy Alex') else: print('Poor Alex')
Title: Laptops Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the first laptop is less (strictly smaller) than the price of the second laptop but the quality of the first laptop is higher (strictly greater) than the quality of the second laptop. Please, check the guess of Alex. You are given descriptions of *n* laptops. Determine whether two described above laptops exist. Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=105) — the number of laptops. Next *n* lines contain two integers each, *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*), where *a**i* is the price of the *i*-th laptop, and *b**i* is the number that represents the quality of the *i*-th laptop (the larger the number is, the higher is the quality). All *a**i* are distinct. All *b**i* are distinct. Output Specification: If Alex is correct, print "Happy Alex", otherwise print "Poor Alex" (without the quotes). Demo Input: ['2\n1 2\n2 1\n'] Demo Output: ['Happy Alex\n'] Note: none
```python n=int(input()) l1=[] for i in range(n): l=list(map(int,input().split())) l1.append(l) l1.sort() c=0 for i in range(len(l1)): if(l1[i][0]< l1[i+1][0]): if(l1[i][1]>l1[i+1][1]): c=1 break print('Happy Alex') if(c==1): print('Happy Alex') else: print('Poor Alex') ```
-1
116
A
Tram
PROGRAMMING
800
[ "implementation" ]
null
null
Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty. Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram.
The first line contains a single number *n* (2<=≤<=*n*<=≤<=1000) — the number of the tram's stops. Then *n* lines follow, each contains two integers *a**i* and *b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the number of passengers that exits the tram at the *i*-th stop, and the number of passengers that enter the tram at the *i*-th stop. The stops are given from the first to the last stop in the order of tram's movement. - The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, . This particularly means that *a*1<==<=0. - At the last stop, all the passengers exit the tram and it becomes empty. More formally, . - No passenger will enter the train at the last stop. That is, *b**n*<==<=0.
Print a single integer denoting the minimum possible capacity of the tram (0 is allowed).
[ "4\n0 3\n2 5\n4 2\n4 0\n" ]
[ "6\n" ]
For the first example, a capacity of 6 is sufficient: - At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. - At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 passengers enter the tram. There are 6 passengers inside the tram now. - At the third stop, 4 passengers exit the tram (2 passengers remain inside). Then, 2 passengers enter the tram. There are 4 passengers inside the tram now. - Finally, all the remaining passengers inside the tram exit the tram at the last stop. There are no passenger inside the tram now, which is in line with the constraints. Since the number of passengers inside the tram never exceeds 6, a capacity of 6 is sufficient. Furthermore it is not possible for the tram to have a capacity less than 6. Hence, 6 is the correct answer.
500
[ { "input": "4\n0 3\n2 5\n4 2\n4 0", "output": "6" }, { "input": "5\n0 4\n4 6\n6 5\n5 4\n4 0", "output": "6" }, { "input": "10\n0 5\n1 7\n10 8\n5 3\n0 5\n3 3\n8 8\n0 6\n10 1\n9 0", "output": "18" }, { "input": "3\n0 1\n1 1\n1 0", "output": "1" }, { "input": "4\n0 1...
1,694,574,232
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
0
cubes = int(input()) level = 1 while cubes != 0: cubes_needed = 0 for i in range(1, level + 1): if i != 1: cubes_needed += (i + 1) - 1 else: cubes_needed = 1 if cubes >= cubes_needed: cubes -= cubes_needed else: break level += 1 print(level - 1)
Title: Tram Time Limit: None seconds Memory Limit: None megabytes Problem Description: Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty. Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram. Input Specification: The first line contains a single number *n* (2<=≤<=*n*<=≤<=1000) — the number of the tram's stops. Then *n* lines follow, each contains two integers *a**i* and *b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the number of passengers that exits the tram at the *i*-th stop, and the number of passengers that enter the tram at the *i*-th stop. The stops are given from the first to the last stop in the order of tram's movement. - The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, . This particularly means that *a*1<==<=0. - At the last stop, all the passengers exit the tram and it becomes empty. More formally, . - No passenger will enter the train at the last stop. That is, *b**n*<==<=0. Output Specification: Print a single integer denoting the minimum possible capacity of the tram (0 is allowed). Demo Input: ['4\n0 3\n2 5\n4 2\n4 0\n'] Demo Output: ['6\n'] Note: For the first example, a capacity of 6 is sufficient: - At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. - At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 passengers enter the tram. There are 6 passengers inside the tram now. - At the third stop, 4 passengers exit the tram (2 passengers remain inside). Then, 2 passengers enter the tram. There are 4 passengers inside the tram now. - Finally, all the remaining passengers inside the tram exit the tram at the last stop. There are no passenger inside the tram now, which is in line with the constraints. Since the number of passengers inside the tram never exceeds 6, a capacity of 6 is sufficient. Furthermore it is not possible for the tram to have a capacity less than 6. Hence, 6 is the correct answer.
```python cubes = int(input()) level = 1 while cubes != 0: cubes_needed = 0 for i in range(1, level + 1): if i != 1: cubes_needed += (i + 1) - 1 else: cubes_needed = 1 if cubes >= cubes_needed: cubes -= cubes_needed else: break level += 1 print(level - 1) ```
0
822
A
I'm bored with life
PROGRAMMING
800
[ "implementation", "math", "number theory" ]
null
null
Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormitory for the period of university studies. Consequently Noora had to leave Vičkopolis and move to Pavlopolis. Thus Leha was left completely alone in a quiet town Vičkopolis. He almost even fell into a depression from boredom! Leha came up with a task for himself to relax a little. He chooses two integers *A* and *B* and then calculates the greatest common divisor of integers "*A* factorial" and "*B* factorial". Formally the hacker wants to find out GCD(*A*!,<=*B*!). It's well known that the factorial of an integer *x* is a product of all positive integers less than or equal to *x*. Thus *x*!<==<=1·2·3·...·(*x*<=-<=1)·*x*. For example 4!<==<=1·2·3·4<==<=24. Recall that GCD(*x*,<=*y*) is the largest positive integer *q* that divides (without a remainder) both *x* and *y*. Leha has learned how to solve this task very effective. You are able to cope with it not worse, aren't you?
The first and single line contains two integers *A* and *B* (1<=≤<=*A*,<=*B*<=≤<=109,<=*min*(*A*,<=*B*)<=≤<=12).
Print a single integer denoting the greatest common divisor of integers *A*! and *B*!.
[ "4 3\n" ]
[ "6\n" ]
Consider the sample. 4! = 1·2·3·4 = 24. 3! = 1·2·3 = 6. The greatest common divisor of integers 24 and 6 is exactly 6.
500
[ { "input": "4 3", "output": "6" }, { "input": "10 399603090", "output": "3628800" }, { "input": "6 973151934", "output": "720" }, { "input": "2 841668075", "output": "2" }, { "input": "7 415216919", "output": "5040" }, { "input": "3 283733059", "ou...
1,688,636,481
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
1
1,000
409,600
n, s = map(int, input().split()) f =1 for i in range(2, n + 1): f *= i g =1 for i in range(2, s + 1): g *= i if f > g: print(g) if g > f: print(f) # Thu Jul 06 2023 12:41:07 GMT+0300 (Moscow Standard Time)
Title: I'm bored with life Time Limit: None seconds Memory Limit: None megabytes Problem Description: Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormitory for the period of university studies. Consequently Noora had to leave Vičkopolis and move to Pavlopolis. Thus Leha was left completely alone in a quiet town Vičkopolis. He almost even fell into a depression from boredom! Leha came up with a task for himself to relax a little. He chooses two integers *A* and *B* and then calculates the greatest common divisor of integers "*A* factorial" and "*B* factorial". Formally the hacker wants to find out GCD(*A*!,<=*B*!). It's well known that the factorial of an integer *x* is a product of all positive integers less than or equal to *x*. Thus *x*!<==<=1·2·3·...·(*x*<=-<=1)·*x*. For example 4!<==<=1·2·3·4<==<=24. Recall that GCD(*x*,<=*y*) is the largest positive integer *q* that divides (without a remainder) both *x* and *y*. Leha has learned how to solve this task very effective. You are able to cope with it not worse, aren't you? Input Specification: The first and single line contains two integers *A* and *B* (1<=≤<=*A*,<=*B*<=≤<=109,<=*min*(*A*,<=*B*)<=≤<=12). Output Specification: Print a single integer denoting the greatest common divisor of integers *A*! and *B*!. Demo Input: ['4 3\n'] Demo Output: ['6\n'] Note: Consider the sample. 4! = 1·2·3·4 = 24. 3! = 1·2·3 = 6. The greatest common divisor of integers 24 and 6 is exactly 6.
```python n, s = map(int, input().split()) f =1 for i in range(2, n + 1): f *= i g =1 for i in range(2, s + 1): g *= i if f > g: print(g) if g > f: print(f) # Thu Jul 06 2023 12:41:07 GMT+0300 (Moscow Standard Time) ```
0
731
A
Night at the Museum
PROGRAMMING
800
[ "implementation", "strings" ]
null
null
Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition. Embosser is a special devise that allows to "print" the text of a plastic tape. Text is printed sequentially, character by character. The device consists of a wheel with a lowercase English letters written in a circle, static pointer to the current letter and a button that print the chosen letter. At one move it's allowed to rotate the alphabetic wheel one step clockwise or counterclockwise. Initially, static pointer points to letter 'a'. Other letters are located as shown on the picture: After Grigoriy add new item to the base he has to print its name on the plastic tape and attach it to the corresponding exhibit. It's not required to return the wheel to its initial position with pointer on the letter 'a'. Our hero is afraid that some exhibits may become alive and start to attack him, so he wants to print the names as fast as possible. Help him, for the given string find the minimum number of rotations of the wheel required to print it.
The only line of input contains the name of some exhibit — the non-empty string consisting of no more than 100 characters. It's guaranteed that the string consists of only lowercase English letters.
Print one integer — the minimum number of rotations of the wheel, required to print the name given in the input.
[ "zeus\n", "map\n", "ares\n" ]
[ "18\n", "35\n", "34\n" ]
To print the string from the first sample it would be optimal to perform the following sequence of rotations: 1. from 'a' to 'z' (1 rotation counterclockwise), 1. from 'z' to 'e' (5 clockwise rotations), 1. from 'e' to 'u' (10 rotations counterclockwise), 1. from 'u' to 's' (2 counterclockwise rotations).
500
[ { "input": "zeus", "output": "18" }, { "input": "map", "output": "35" }, { "input": "ares", "output": "34" }, { "input": "l", "output": "11" }, { "input": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuv", "...
1,672,756,450
2,147,483,647
PyPy 3-64
OK
TESTS
44
93
2,867,200
import string def count_steps(word: str): alphabets = string.ascii_lowercase pivot = 'a' distance = 0 steps = 0 for char in word: distance = abs(alphabets.index(char) - alphabets.index(pivot)) if (distance > (len(alphabets) // 2)): distance = len(alphabets) - distance pivot = char steps += distance return steps if __name__ == '__main__': word = input() print(count_steps(word))
Title: Night at the Museum Time Limit: None seconds Memory Limit: None megabytes Problem Description: Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition. Embosser is a special devise that allows to "print" the text of a plastic tape. Text is printed sequentially, character by character. The device consists of a wheel with a lowercase English letters written in a circle, static pointer to the current letter and a button that print the chosen letter. At one move it's allowed to rotate the alphabetic wheel one step clockwise or counterclockwise. Initially, static pointer points to letter 'a'. Other letters are located as shown on the picture: After Grigoriy add new item to the base he has to print its name on the plastic tape and attach it to the corresponding exhibit. It's not required to return the wheel to its initial position with pointer on the letter 'a'. Our hero is afraid that some exhibits may become alive and start to attack him, so he wants to print the names as fast as possible. Help him, for the given string find the minimum number of rotations of the wheel required to print it. Input Specification: The only line of input contains the name of some exhibit — the non-empty string consisting of no more than 100 characters. It's guaranteed that the string consists of only lowercase English letters. Output Specification: Print one integer — the minimum number of rotations of the wheel, required to print the name given in the input. Demo Input: ['zeus\n', 'map\n', 'ares\n'] Demo Output: ['18\n', '35\n', '34\n'] Note: To print the string from the first sample it would be optimal to perform the following sequence of rotations: 1. from 'a' to 'z' (1 rotation counterclockwise), 1. from 'z' to 'e' (5 clockwise rotations), 1. from 'e' to 'u' (10 rotations counterclockwise), 1. from 'u' to 's' (2 counterclockwise rotations).
```python import string def count_steps(word: str): alphabets = string.ascii_lowercase pivot = 'a' distance = 0 steps = 0 for char in word: distance = abs(alphabets.index(char) - alphabets.index(pivot)) if (distance > (len(alphabets) // 2)): distance = len(alphabets) - distance pivot = char steps += distance return steps if __name__ == '__main__': word = input() print(count_steps(word)) ```
3
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 1. A statement in language Bit++ is a sequence, consisting of exactly one operation and one variable *x*. The statement is written without spaces, that is, it can only contain characters "+", "-", "X". Executing a statement means applying the operation it contains. A programme in Bit++ is a sequence of statements, each of them needs to be executed. Executing a programme means executing all the statements it contains. You're given a programme in language Bit++. The initial value of *x* is 0. Execute the programme and find its final value (the value of the variable when this programme is executed).
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 the variable can be written in any order.
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,419,641
2,147,483,647
PyPy 3-64
RUNTIME_ERROR
TESTS
0
46
2,867,200
for _ in range(int(input())): n,m=map(int, input().split()) x=input() d=[] s=input() count=0 d.append(x) for i in range(n*m): g=str(d) d.append(g) count=count+1 if s in x: break print(count)
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 ++ increases the value of variable *x* by 1. - Operation -- decreases the value of variable *x* by 1. A statement in language Bit++ is a sequence, consisting of exactly one operation and one variable *x*. The statement is written without spaces, that is, it can only contain characters "+", "-", "X". Executing a statement means applying the operation it contains. A programme in Bit++ is a sequence of statements, each of them needs to be executed. Executing a programme means executing all the statements it contains. You're given a programme in language Bit++. The initial value of *x* is 0. Execute the programme and find its final value (the value of the variable when this programme is executed). Input Specification: 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 the variable can be written in any order. Output Specification: Print a single integer — the final value of *x*. Demo Input: ['1\n++X\n', '2\nX++\n--X\n'] Demo Output: ['1\n', '0\n'] Note: none
```python for _ in range(int(input())): n,m=map(int, input().split()) x=input() d=[] s=input() count=0 d.append(x) for i in range(n*m): g=str(d) d.append(g) count=count+1 if s in x: break print(count) ```
-1
182
B
Vasya's Calendar
PROGRAMMING
1,000
[ "implementation" ]
null
null
Vasya lives in a strange world. The year has *n* months and the *i*-th month has *a**i* days. Vasya got a New Year present — the clock that shows not only the time, but also the date. The clock's face can display any number from 1 to *d*. It is guaranteed that *a**i*<=≤<=*d* for all *i* from 1 to *n*. The clock does not keep information about the current month, so when a new day comes, it simply increases the current day number by one. The clock cannot display number *d*<=+<=1, so after day number *d* it shows day 1 (the current day counter resets). The mechanism of the clock allows you to increase the day number by one manually. When you execute this operation, day *d* is also followed by day 1. Vasya begins each day checking the day number on the clock. If the day number on the clock does not match the actual day number in the current month, then Vasya manually increases it by one. Vasya is persistent and repeats this operation until the day number on the clock matches the actual number of the current day in the current month. A year passed and Vasya wonders how many times he manually increased the day number by one, from the first day of the first month to the last day of the *n*-th month inclusive, considering that on the first day of the first month the clock display showed day 1.
The first line contains the single number *d* — the maximum number of the day that Vasya's clock can show (1<=≤<=*d*<=≤<=106). The second line contains a single integer *n* — the number of months in the year (1<=≤<=*n*<=≤<=2000). The third line contains *n* space-separated integers: *a**i* (1<=≤<=*a**i*<=≤<=*d*) — the number of days in each month in the order in which they follow, starting from the first one.
Print a single number — the number of times Vasya manually increased the day number by one throughout the last year.
[ "4\n2\n2 2\n", "5\n3\n3 4 3\n", "31\n12\n31 28 31 30 31 30 31 31 30 31 30 31\n" ]
[ "2\n", "3\n", "7\n" ]
In the first sample the situation is like this: - Day 1. Month 1. The clock shows 1. Vasya changes nothing. - Day 2. Month 1. The clock shows 2. Vasya changes nothing. - Day 1. Month 2. The clock shows 3. Vasya manually increases the day number by 1. After that the clock shows 4. Vasya increases the day number by 1 manually. After that the clock shows 1. - Day 2. Month 2. The clock shows 2. Vasya changes nothing.
500
[ { "input": "4\n2\n2 2", "output": "2" }, { "input": "5\n3\n3 4 3", "output": "3" }, { "input": "31\n12\n31 28 31 30 31 30 31 31 30 31 30 31", "output": "7" }, { "input": "1\n1\n1", "output": "0" }, { "input": "1\n2\n1 1", "output": "0" }, { "input": "2...
1,560,332,061
2,147,483,647
Python 3
OK
TESTS
40
218
307,200
d = int(input()) n = int(input()) a = [int(t) for t in input().split()] c = 0 for i in range(n - 1): c += d - a[i] print(c)
Title: Vasya's Calendar Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya lives in a strange world. The year has *n* months and the *i*-th month has *a**i* days. Vasya got a New Year present — the clock that shows not only the time, but also the date. The clock's face can display any number from 1 to *d*. It is guaranteed that *a**i*<=≤<=*d* for all *i* from 1 to *n*. The clock does not keep information about the current month, so when a new day comes, it simply increases the current day number by one. The clock cannot display number *d*<=+<=1, so after day number *d* it shows day 1 (the current day counter resets). The mechanism of the clock allows you to increase the day number by one manually. When you execute this operation, day *d* is also followed by day 1. Vasya begins each day checking the day number on the clock. If the day number on the clock does not match the actual day number in the current month, then Vasya manually increases it by one. Vasya is persistent and repeats this operation until the day number on the clock matches the actual number of the current day in the current month. A year passed and Vasya wonders how many times he manually increased the day number by one, from the first day of the first month to the last day of the *n*-th month inclusive, considering that on the first day of the first month the clock display showed day 1. Input Specification: The first line contains the single number *d* — the maximum number of the day that Vasya's clock can show (1<=≤<=*d*<=≤<=106). The second line contains a single integer *n* — the number of months in the year (1<=≤<=*n*<=≤<=2000). The third line contains *n* space-separated integers: *a**i* (1<=≤<=*a**i*<=≤<=*d*) — the number of days in each month in the order in which they follow, starting from the first one. Output Specification: Print a single number — the number of times Vasya manually increased the day number by one throughout the last year. Demo Input: ['4\n2\n2 2\n', '5\n3\n3 4 3\n', '31\n12\n31 28 31 30 31 30 31 31 30 31 30 31\n'] Demo Output: ['2\n', '3\n', '7\n'] Note: In the first sample the situation is like this: - Day 1. Month 1. The clock shows 1. Vasya changes nothing. - Day 2. Month 1. The clock shows 2. Vasya changes nothing. - Day 1. Month 2. The clock shows 3. Vasya manually increases the day number by 1. After that the clock shows 4. Vasya increases the day number by 1 manually. After that the clock shows 1. - Day 2. Month 2. The clock shows 2. Vasya changes nothing.
```python d = int(input()) n = int(input()) a = [int(t) for t in input().split()] c = 0 for i in range(n - 1): c += d - a[i] print(c) ```
3
281
A
Word Capitalization
PROGRAMMING
800
[ "implementation", "strings" ]
null
null
Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word. Note, that during capitalization all the letters except the first one remains unchanged.
A single line contains a non-empty word. This word consists of lowercase and uppercase English letters. The length of the word will not exceed 103.
Output the given word after capitalization.
[ "ApPLe\n", "konjac\n" ]
[ "ApPLe\n", "Konjac\n" ]
none
500
[ { "input": "ApPLe", "output": "ApPLe" }, { "input": "konjac", "output": "Konjac" }, { "input": "a", "output": "A" }, { "input": "A", "output": "A" }, { "input": "z", "output": "Z" }, { "input": "ABACABA", "output": "ABACABA" }, { "input": "...
1,696,573,416
2,147,483,647
Python 3
OK
TESTS
25
92
0
# -*- coding: utf-8 -*- """Untitled10.ipynb Automatically generated by Colaboratory. Original file is located at https://colab.research.google.com/drive/1Y76e7LeXWvCIjIdSAW7klJvgCVNmBhzq """ w = input() print(f"{w[0].upper()}{w[1:]}")
Title: Word Capitalization Time Limit: None seconds Memory Limit: None megabytes Problem Description: Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word. Note, that during capitalization all the letters except the first one remains unchanged. Input Specification: A single line contains a non-empty word. This word consists of lowercase and uppercase English letters. The length of the word will not exceed 103. Output Specification: Output the given word after capitalization. Demo Input: ['ApPLe\n', 'konjac\n'] Demo Output: ['ApPLe\n', 'Konjac\n'] Note: none
```python # -*- coding: utf-8 -*- """Untitled10.ipynb Automatically generated by Colaboratory. Original file is located at https://colab.research.google.com/drive/1Y76e7LeXWvCIjIdSAW7klJvgCVNmBhzq """ w = input() print(f"{w[0].upper()}{w[1:]}") ```
3
665
D
Simple Subset
PROGRAMMING
1,800
[ "constructive algorithms", "greedy", "number theory" ]
null
null
A tuple of positive integers {*x*1,<=*x*2,<=...,<=*x**k*} is called simple if for all pairs of positive integers (*i*,<=<=*j*) (1<=<=≤<=*i*<=<=&lt;<=<=*j*<=≤<=*k*), *x**i*<=<=+<=<=*x**j* is a prime. You are given an array *a* with *n* positive integers *a*1,<=<=*a*2,<=<=...,<=<=*a**n* (not necessary distinct). You want to find a simple subset of the array *a* with the maximum size. A prime number (or a prime) is a natural number greater than 1 that has no positive divisors other than 1 and itself. Let's define a subset of the array *a* as a tuple that can be obtained from *a* by removing some (possibly all) elements of it.
The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of integers in the array *a*. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=106) — the elements of the array *a*.
On the first line print integer *m* — the maximum possible size of simple subset of *a*. On the second line print *m* integers *b**l* — the elements of the simple subset of the array *a* with the maximum size. If there is more than one solution you can print any of them. You can print the elements of the subset in any order.
[ "2\n2 3\n", "2\n2 2\n", "3\n2 1 1\n", "2\n83 14\n" ]
[ "2\n3 2\n", "1\n2\n", "3\n1 1 2\n", "2\n14 83\n" ]
none
0
[ { "input": "2\n2 3", "output": "2\n3 2" }, { "input": "2\n2 2", "output": "1\n2" }, { "input": "3\n2 1 1", "output": "3\n1 1 2" }, { "input": "2\n83 14", "output": "2\n14 83" }, { "input": "10\n10 10 1 2 3 3 1 2 1 5", "output": "4\n1 1 10 1" }, { "inpu...
1,461,692,380
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
10
1,000
6,860,800
import logging import copy import sys import math logging.basicConfig(stream=sys.stderr, level=logging.DEBUG) primeSet = set() subList = [] elementMap = {} def isPrime(n): global primeSet if n in primeSet: return True if n <= 3: return True for i in range(2, int(math.sqrt(n))+ 1): if n %i == 0: return False primeSet.add(n) return True #def solve(firstLine): def checkCandi(n, lst,line): global elementMap nCount = 1 for prev in lst: if isPrime(prev + n)== False: return False if prev == n: nCount+=1 if nCount <= elementMap[n]: return True return False def solve(n, line): global subList for i in range(len(line)): subList.append([line[i]]) while True: newSubList = [] for i,n in enumerate(line): for lst in subList: if checkCandi(n,lst,line) == True: newSubList.append( [n] + lst ) if len(newSubList) == 0: return subList[0] subList = newSubList[:] def main(): global elementMap firstLine = int(input()) line = input().split() line = list(map(int, line)) line.sort() for i in line: if i not in elementMap: elementMap[i] = 1 else: elementMap[i] +=1 line = list(set(line)) #solve(firstLine) result = solve(firstLine, line) print(len(result)) print(' '.join(str(x) for x in result)) # print( ' '.join(lambda x : str(x), result)) # print(", ".join(result)) def log(*message): logging.debug(message) if __name__ == "__main__": main()
Title: Simple Subset Time Limit: None seconds Memory Limit: None megabytes Problem Description: A tuple of positive integers {*x*1,<=*x*2,<=...,<=*x**k*} is called simple if for all pairs of positive integers (*i*,<=<=*j*) (1<=<=≤<=*i*<=<=&lt;<=<=*j*<=≤<=*k*), *x**i*<=<=+<=<=*x**j* is a prime. You are given an array *a* with *n* positive integers *a*1,<=<=*a*2,<=<=...,<=<=*a**n* (not necessary distinct). You want to find a simple subset of the array *a* with the maximum size. A prime number (or a prime) is a natural number greater than 1 that has no positive divisors other than 1 and itself. Let's define a subset of the array *a* as a tuple that can be obtained from *a* by removing some (possibly all) elements of it. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of integers in the array *a*. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=106) — the elements of the array *a*. Output Specification: On the first line print integer *m* — the maximum possible size of simple subset of *a*. On the second line print *m* integers *b**l* — the elements of the simple subset of the array *a* with the maximum size. If there is more than one solution you can print any of them. You can print the elements of the subset in any order. Demo Input: ['2\n2 3\n', '2\n2 2\n', '3\n2 1 1\n', '2\n83 14\n'] Demo Output: ['2\n3 2\n', '1\n2\n', '3\n1 1 2\n', '2\n14 83\n'] Note: none
```python import logging import copy import sys import math logging.basicConfig(stream=sys.stderr, level=logging.DEBUG) primeSet = set() subList = [] elementMap = {} def isPrime(n): global primeSet if n in primeSet: return True if n <= 3: return True for i in range(2, int(math.sqrt(n))+ 1): if n %i == 0: return False primeSet.add(n) return True #def solve(firstLine): def checkCandi(n, lst,line): global elementMap nCount = 1 for prev in lst: if isPrime(prev + n)== False: return False if prev == n: nCount+=1 if nCount <= elementMap[n]: return True return False def solve(n, line): global subList for i in range(len(line)): subList.append([line[i]]) while True: newSubList = [] for i,n in enumerate(line): for lst in subList: if checkCandi(n,lst,line) == True: newSubList.append( [n] + lst ) if len(newSubList) == 0: return subList[0] subList = newSubList[:] def main(): global elementMap firstLine = int(input()) line = input().split() line = list(map(int, line)) line.sort() for i in line: if i not in elementMap: elementMap[i] = 1 else: elementMap[i] +=1 line = list(set(line)) #solve(firstLine) result = solve(firstLine, line) print(len(result)) print(' '.join(str(x) for x in result)) # print( ' '.join(lambda x : str(x), result)) # print(", ".join(result)) def log(*message): logging.debug(message) if __name__ == "__main__": main() ```
0
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. Some days are so busy that Petr will have no time to read whatsoever. However, we know that he will be able to read at least one page a week. Assuming that Petr will not skip days and will read as much as he can every day, determine on which day of the week he will read the last page of the book.
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 Sunday correspondingly. It is guaranteed that at least one of those numbers is larger than zero.
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 sample: On Monday of the first week Petr will read the first page. On Monday of the second week Petr will read the second page and will finish reading the book.
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,592,405,820
2,147,483,647
PyPy 3
OK
TESTS
49
310
0
# https://codeforces.com/problemset/problem/139/A import sys #-----------------------------------------------------------------------------# input = sys.stdin.readline print = sys.stdout.write #-----------------------------------------------------------------------------# n = int(input()) pages = list(map(int, input().split())) weekly_pages = sum(pages) remaining = n % weekly_pages if remaining == 0: remaining = n - weekly_pages * (n // weekly_pages - 1) for j, i in enumerate(pages): remaining -= i if remaining <= 0: print(str(j + 1)) break
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 schedule and for each day of the week he knows how many pages he will be able to read on that day. Some days are so busy that Petr will have no time to read whatsoever. However, we know that he will be able to read at least one page a week. Assuming that Petr will not skip days and will read as much as he can every day, determine on which day of the week he will read the last page of the book. Input Specification: 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 Sunday correspondingly. It is guaranteed that at least one of those numbers is larger than zero. Output Specification: 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. Demo Input: ['100\n15 20 20 15 10 30 45\n', '2\n1 0 0 0 0 0 0\n'] Demo Output: ['6\n', '1\n'] Note: 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 sample: On Monday of the first week Petr will read the first page. On Monday of the second week Petr will read the second page and will finish reading the book.
```python # https://codeforces.com/problemset/problem/139/A import sys #-----------------------------------------------------------------------------# input = sys.stdin.readline print = sys.stdout.write #-----------------------------------------------------------------------------# n = int(input()) pages = list(map(int, input().split())) weekly_pages = sum(pages) remaining = n % weekly_pages if remaining == 0: remaining = n - weekly_pages * (n // weekly_pages - 1) for j, i in enumerate(pages): remaining -= i if remaining <= 0: print(str(j + 1)) break ```
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 program results in two integers *x* and *y* (*x*<=+<=*y*<==<=10; *x*,<=*y*<=≥<=0). These numbers mean that *x* packets successfully reached the corresponding server through the network and *y* packets were lost. Today Polycarpus has performed overall *n* ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network. Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results.
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**i*,<=*y**i*<=≥<=0; *x**i*<=+<=*y**i*<==<=10). If *t**i*<==<=1, then the *i*-th command is "ping a", otherwise the *i*-th command is "ping b". Numbers *x**i*, *y**i* represent the result of executing this command, that is, *x**i* packets reached the corresponding server successfully and *y**i* packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command.
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 this server successfully reached it through the network. Consider the second test case. There were overall 20 packages sent to server *a*, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server *b*, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network.
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,573,039,274
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
3
248
0
n = int(input()) ar = ["LIVE", "LIVE"] for i in range(n): a, b, c = input().split() a = int(a) b = int(b) c = int(c) if(b < c): ar[a - 1] = "DEAD" else: ar[a - 1] = "LIVE" print(ar[0]) print(ar[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 command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers *x* and *y* (*x*<=+<=*y*<==<=10; *x*,<=*y*<=≥<=0). These numbers mean that *x* packets successfully reached the corresponding server through the network and *y* packets were lost. Today Polycarpus has performed overall *n* ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network. Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results. Input Specification: 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**i*,<=*y**i*<=≥<=0; *x**i*<=+<=*y**i*<==<=10). If *t**i*<==<=1, then the *i*-th command is "ping a", otherwise the *i*-th command is "ping b". Numbers *x**i*, *y**i* represent the result of executing this command, that is, *x**i* packets reached the corresponding server successfully and *y**i* packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command. Output Specification: 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. Demo Input: ['2\n1 5 5\n2 6 4\n', '3\n1 0 10\n2 0 10\n1 10 0\n'] Demo Output: ['LIVE\nLIVE\n', 'LIVE\nDEAD\n'] Note: 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 this server successfully reached it through the network. Consider the second test case. There were overall 20 packages sent to server *a*, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server *b*, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network.
```python n = int(input()) ar = ["LIVE", "LIVE"] for i in range(n): a, b, c = input().split() a = int(a) b = int(b) c = int(c) if(b < c): ar[a - 1] = "DEAD" else: ar[a - 1] = "LIVE" print(ar[0]) print(ar[1]) ```
0
938
E
Max History
PROGRAMMING
2,300
[ "combinatorics", "math" ]
null
null
You are given an array *a* of length *n*. We define *f**a* the following way: - Initially *f**a*<==<=0, *M*<==<=1; - for every 2<=≤<=*i*<=≤<=*n* if *a**M*<=&lt;<=*a**i* then we set *f**a*<==<=*f**a*<=+<=*a**M* and then set *M*<==<=*i*. Calculate the sum of *f**a* over all *n*! permutations of the array *a* modulo 109<=+<=7. Note: two elements are considered different if their indices differ, so for every array *a* there are exactly *n*! permutations.
The first line contains integer *n* (1<=≤<=*n*<=≤<=<=1 000 000) — the size of array *a*. Second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=<=*a**i*<=≤<=<=109).
Print the only integer, the sum of *f**a* over all *n*! permutations of the array *a* modulo 109<=+<=7.
[ "2\n1 3\n", "3\n1 1 2\n" ]
[ "1", "4" ]
For the second example all the permutations are: - *p* = [1, 2, 3] : *f*<sub class="lower-index">*a*</sub> is equal to 1; - *p* = [1, 3, 2] : *f*<sub class="lower-index">*a*</sub> is equal to 1; - *p* = [2, 1, 3] : *f*<sub class="lower-index">*a*</sub> is equal to 1; - *p* = [2, 3, 1] : *f*<sub class="lower-index">*a*</sub> is equal to 1; - *p* = [3, 1, 2] : *f*<sub class="lower-index">*a*</sub> is equal to 0; - *p* = [3, 2, 1] : *f*<sub class="lower-index">*a*</sub> is equal to 0. Where *p* is the array of the indices of initial array *a*. The sum of *f*<sub class="lower-index">*a*</sub> is equal to 4.
0
[ { "input": "2\n1 3", "output": "1" }, { "input": "3\n1 1 2", "output": "4" }, { "input": "6\n1 4 5 2 3 3", "output": "2928" }, { "input": "8\n8 7 5 4 6 6 6 6", "output": "351360" }, { "input": "8\n1 2 3 9 100 100 100 100", "output": "109296" }, { "inpu...
1,522,240,268
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
#include<bits/stdc++.h> using namespace std; using ll = long long; ll arr[1000000],frac[1000001],ct[1000001],lss[1000001]; ll mod=1000000007; ll power(int x, int y) { if (y == 0) return 1; ll p = power(x, y/2) % mod; p = (p * p) % mod; return (y%2 == 0)? p : (x * p) % mod; } int main(){ int n,i,j=0; ll k; frac[0]=frac[1]=1; for (i=2;i<1000001;i++){ frac[i]=(frac[i-1]*i)%mod; } cin>>n; for(i=0;i<n;i++) { cin>>arr[i]; } sort(arr,arr+n); int ct=1; lss[j]=0; ll sol=0; for (i=1;i<n;i++){ if (arr[i]==arr[i-1]){ ct+=1; } else{ j+=1; lss[j]=lss[j-1]+ct; k=(frac[n]*power(ct+n-lss[j],mod-2)*ct)%mod; ct=1; sol=(sol+ (arr[i-1]*k)%mod)%mod; } } cout<<sol<<"\n"; return 0; }
Title: Max History Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given an array *a* of length *n*. We define *f**a* the following way: - Initially *f**a*<==<=0, *M*<==<=1; - for every 2<=≤<=*i*<=≤<=*n* if *a**M*<=&lt;<=*a**i* then we set *f**a*<==<=*f**a*<=+<=*a**M* and then set *M*<==<=*i*. Calculate the sum of *f**a* over all *n*! permutations of the array *a* modulo 109<=+<=7. Note: two elements are considered different if their indices differ, so for every array *a* there are exactly *n*! permutations. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=<=1 000 000) — the size of array *a*. Second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=<=*a**i*<=≤<=<=109). Output Specification: Print the only integer, the sum of *f**a* over all *n*! permutations of the array *a* modulo 109<=+<=7. Demo Input: ['2\n1 3\n', '3\n1 1 2\n'] Demo Output: ['1', '4'] Note: For the second example all the permutations are: - *p* = [1, 2, 3] : *f*<sub class="lower-index">*a*</sub> is equal to 1; - *p* = [1, 3, 2] : *f*<sub class="lower-index">*a*</sub> is equal to 1; - *p* = [2, 1, 3] : *f*<sub class="lower-index">*a*</sub> is equal to 1; - *p* = [2, 3, 1] : *f*<sub class="lower-index">*a*</sub> is equal to 1; - *p* = [3, 1, 2] : *f*<sub class="lower-index">*a*</sub> is equal to 0; - *p* = [3, 2, 1] : *f*<sub class="lower-index">*a*</sub> is equal to 0. Where *p* is the array of the indices of initial array *a*. The sum of *f*<sub class="lower-index">*a*</sub> is equal to 4.
```python #include<bits/stdc++.h> using namespace std; using ll = long long; ll arr[1000000],frac[1000001],ct[1000001],lss[1000001]; ll mod=1000000007; ll power(int x, int y) { if (y == 0) return 1; ll p = power(x, y/2) % mod; p = (p * p) % mod; return (y%2 == 0)? p : (x * p) % mod; } int main(){ int n,i,j=0; ll k; frac[0]=frac[1]=1; for (i=2;i<1000001;i++){ frac[i]=(frac[i-1]*i)%mod; } cin>>n; for(i=0;i<n;i++) { cin>>arr[i]; } sort(arr,arr+n); int ct=1; lss[j]=0; ll sol=0; for (i=1;i<n;i++){ if (arr[i]==arr[i-1]){ ct+=1; } else{ j+=1; lss[j]=lss[j-1]+ct; k=(frac[n]*power(ct+n-lss[j],mod-2)*ct)%mod; ct=1; sol=(sol+ (arr[i-1]*k)%mod)%mod; } } cout<<sol<<"\n"; return 0; } ```
-1