contestId
int64
0
1.01k
index
stringclasses
57 values
name
stringlengths
2
58
type
stringclasses
2 values
rating
int64
0
3.5k
tags
sequencelengths
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
sequencelengths
0
7
demo-output
sequencelengths
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" }, { "input": "1 3", "output": "Akshat" }, { "input": "2 1", "output": "Akshat" }, { "input": "2 2", "output": "Malvika" }, { "input": "3 1", "output": "Akshat" }, { "input": "3 2", "output": "Malvika" }, { "input": "68 42", "output": "Malvika" }, { "input": "1 35", "output": "Akshat" }, { "input": "25 70", "output": "Akshat" }, { "input": "59 79", "output": "Akshat" }, { "input": "65 63", "output": "Akshat" }, { "input": "46 6", "output": "Malvika" }, { "input": "28 82", "output": "Malvika" }, { "input": "98 98", "output": "Malvika" }, { "input": "98 99", "output": "Malvika" }, { "input": "98 100", "output": "Malvika" }, { "input": "99 98", "output": "Malvika" }, { "input": "99 99", "output": "Akshat" }, { "input": "99 100", "output": "Akshat" }, { "input": "100 98", "output": "Malvika" }, { "input": "100 99", "output": "Akshat" }, { "input": "100 100", "output": "Malvika" }, { "input": "3 4", "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" }, { "input": "helloworld", "output": "w" }, { "input": "zzzzzzzazz", "output": "zzzzzzzzz" }, { "input": "testcase", "output": "tt" }, { "input": "hahahahaha", "output": "hhhhh" }, { "input": "abbbbbbbbb", "output": "bbbbbbbbb" }, { "input": "zaz", "output": "zz" }, { "input": "aza", "output": "z" }, { "input": "dcbaedcba", "output": "e" }, { "input": "abcdeabcd", "output": "e" }, { "input": "edcbabcde", "output": "ee" }, { "input": "aaaaaaaaab", "output": "b" }, { "input": "testzzzzzz", "output": "zzzzzz" }, { "input": "zzzzzzwait", "output": "zzzzzz" }, { "input": "rrrrrqponm", "output": "rrrrr" }, { "input": "zzyzyy", "output": "zzz" }, { "input": "aababb", "output": "bbb" }, { "input": "zanzibar", "output": "zz" }, { "input": "hhgfedcbaa", "output": "hh" }, { "input": "aabcdefghh", "output": "hh" }, { "input": "aruaru", "output": "uu" }, { "input": "uraura", "output": "uu" }, { "input": "aru", "output": "u" }, { "input": "aburvabur", "output": "v" }, { "input": "ura", "output": "u" }, { "input": "eurottat", "output": "u" }, { "input": "referee", "output": "rr" }, { "input": "joking", "output": "o" }, { "input": "seriously", "output": "y" }, { "input": "sets", "output": "t" }, { "input": "test", "output": "tt" }, { "input": "klmgameklm", "output": "mmm" }, { "input": "dfkjafdkdd", "output": "kk" }, { "input": "zzzzzzzzzz", "output": "zzzzzzzzzz" }, { "input": "aaaaaaaaaa", "output": "aaaaaaaaaa" }, { "input": "buzz", "output": "zz" }, { "input": "b", "output": "b" }, { "input": "y", "output": "y" }, { "input": "yy", "output": "yy" }, { "input": "zz", "output": "zz" }, { "input": "bb", "output": "bb" }, { "input": "aa", "output": "aa" }, { "input": "a", "output": "a" }, { "input": "z", "output": "z" }, { "input": "zz", "output": "zz" }, { "input": "zzazazzzaz", "output": "zzzzzzz" }, { "input": "hellhellhe", "output": "llll" }, { "input": "hellohello", "output": "oo" }, { "input": "refer", "output": "rr" } ]
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": "2" }, { "input": "1 3", "output": "3" }, { "input": "1 4", "output": "4" }, { "input": "1 5", "output": "4" }, { "input": "1 6", "output": "5" }, { "input": "1 7", "output": "5" }, { "input": "1 8", "output": "6" }, { "input": "1 9", "output": "6" }, { "input": "1 10", "output": "6" }, { "input": "2 2", "output": "1" }, { "input": "2 3", "output": "2" }, { "input": "2 4", "output": "2" }, { "input": "2 5", "output": "3" }, { "input": "2 6", "output": "3" }, { "input": "2 7", "output": "4" }, { "input": "2 8", "output": "4" }, { "input": "2 9", "output": "4" }, { "input": "2 10", "output": "4" }, { "input": "3 3", "output": "1" }, { "input": "3 4", "output": "1" }, { "input": "3 5", "output": "2" }, { "input": "3 6", "output": "2" }, { "input": "3 7", "output": "3" }, { "input": "3 8", "output": "3" }, { "input": "3 9", "output": "3" }, { "input": "3 10", "output": "3" }, { "input": "4 4", "output": "1" }, { "input": "4 5", "output": "1" }, { "input": "4 6", "output": "2" }, { "input": "4 7", "output": "2" }, { "input": "4 8", "output": "2" }, { "input": "4 9", "output": "3" }, { "input": "4 10", "output": "3" }, { "input": "5 5", "output": "1" }, { "input": "5 6", "output": "1" }, { "input": "5 7", "output": "1" }, { "input": "5 8", "output": "2" }, { "input": "5 9", "output": "2" }, { "input": "5 10", "output": "2" }, { "input": "6 6", "output": "1" }, { "input": "6 7", "output": "1" }, { "input": "6 8", "output": "1" }, { "input": "6 9", "output": "2" }, { "input": "6 10", "output": "2" }, { "input": "7 7", "output": "1" }, { "input": "7 8", "output": "1" }, { "input": "7 9", "output": "1" }, { "input": "7 10", "output": "1" }, { "input": "8 8", "output": "1" }, { "input": "8 9", "output": "1" }, { "input": "8 10", "output": "1" }, { "input": "9 9", "output": "1" }, { "input": "9 10", "output": "1" }, { "input": "10 10", "output": "1" }, { "input": "10 10", "output": "1" }, { "input": "1 2", "output": "2" } ]
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", "output": "eekkllrrrrsswwxxxxxx" }, { "input": "fzjqgrgzzzghrwgwhfjq\nggwfrjzzqh", "output": "fzjqgrgzzzghrwgwhfjq" }, { "input": "ng?\nvu", "output": "ngz" }, { "input": "???\nb", "output": "bbb" }, { "input": "??a?\na", "output": "aaaa" }, { "input": "c?aa???a?cdcc??\nabcadbaccb", "output": "cbaabbzazcdcczz" }, { "input": "cc?cdb?????b?cc?b?\ncabdacd", "output": "ccacdbaaaddbdcczbz" }, { "input": "ccaaa?bc?baccbccccbca?cccab??aacccbaac?bccacc?accccaccbcbbcbc\ncbaaacccc", "output": "ccaaaabcabaccbccccbcaacccabaaaacccbaaczbccacczaccccaccbcbbcbc" }, { "input": "aacaacbabc?bcca?ccca\nbc", "output": "aacaacbabcbbccabccca" } ]
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", "output": "NO" }, { "input": "190492", "output": "YES" }, { "input": "5722367", "output": "NO" }, { "input": "816761542", "output": "YES" }, { "input": "1", "output": "NO" }, { "input": "2", "output": "YES" }, { "input": "3", "output": "NO" }, { "input": "4", "output": "YES" }, { "input": "5", "output": "NO" }, { "input": "6", "output": "YES" }, { "input": "7", "output": "YES" }, { "input": "8", "output": "NO" }, { "input": "9", "output": "YES" }, { "input": "10", "output": "NO" }, { "input": "12", "output": "YES" }, { "input": "13", "output": "YES" }, { "input": "14", "output": "NO" }, { "input": "15", "output": "NO" }, { "input": "16", "output": "YES" }, { "input": "17", "output": "NO" }, { "input": "18", "output": "YES" }, { "input": "19", "output": "NO" }, { "input": "20", "output": "YES" }, { "input": "41", "output": "NO" }, { "input": "11", "output": "YES" }, { "input": "69", "output": "YES" }, { "input": "82", "output": "NO" }, { "input": "85", "output": "NO" }, { "input": "736", "output": "NO" }, { "input": "895", "output": "YES" }, { "input": "934", "output": "YES" }, { "input": "6213", "output": "YES" }, { "input": "7405", "output": "NO" }, { "input": "9919", "output": "NO" }, { "input": "40942", "output": "YES" }, { "input": "41992", "output": "NO" }, { "input": "68535", "output": "NO" }, { "input": "405718", "output": "NO" }, { "input": "1046146", "output": "YES" }, { "input": "3761248", "output": "YES" }, { "input": "6195181", "output": "YES" }, { "input": "35354345", "output": "NO" }, { "input": "81282830", "output": "NO" }, { "input": "187719774", "output": "NO" }, { "input": "296798673", "output": "NO" }, { "input": "938938476", "output": "NO" }, { "input": "1000000000", "output": "NO" }, { "input": "999887464", "output": "YES" }, { "input": "999111944", "output": "NO" }, { "input": "999966520", "output": "YES" }, { "input": "999912080", "output": "NO" }, { "input": "999992017", "output": "YES" }, { "input": "999990474", "output": "NO" }, { "input": "999999190", "output": "YES" }, { "input": "999999125", "output": "NO" }, { "input": "999999940", "output": "YES" }, { "input": "999999995", "output": "NO" }, { "input": "1000000000", "output": "NO" }, { "input": "1", "output": "NO" }, { "input": "999999999", "output": "YES" }, { "input": "83495494", "output": "NO" }, { "input": "968022000", "output": "YES" }, { "input": "399980000", "output": "YES" }, { "input": "4", "output": "YES" }, { "input": "999999998", "output": "NO" } ]
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" }, { "input": "1000\n999", "output": "1" }, { "input": "1000\n1", "output": "250000" }, { "input": "2\n1", "output": "1" }, { "input": "2\n999", "output": "249001" }, { "input": "2\n998", "output": "248502" }, { "input": "999\n2", "output": "249001" }, { "input": "998\n2", "output": "248502" }, { "input": "2\n1000", "output": "249500" }, { "input": "1000\n2", "output": "249500" }, { "input": "1\n999", "output": "249500" }, { "input": "999\n1", "output": "249500" }, { "input": "188\n762", "output": "82656" }, { "input": "596\n777", "output": "8281" }, { "input": "773\n70", "output": "123904" }, { "input": "825\n729", "output": "2352" }, { "input": "944\n348", "output": "89102" }, { "input": "352\n445", "output": "2209" }, { "input": "529\n656", "output": "4096" }, { "input": "19\n315", "output": "22052" }, { "input": "138\n370", "output": "13572" }, { "input": "546\n593", "output": "576" }, { "input": "285\n242", "output": "484" }, { "input": "773\n901", "output": "4160" }, { "input": "892\n520", "output": "34782" }, { "input": "864\n179", "output": "117649" }, { "input": "479\n470", "output": "25" }, { "input": "967\n487", "output": "57840" }, { "input": "648\n106", "output": "73712" }, { "input": "58\n765", "output": "125316" }, { "input": "235\n56", "output": "8100" }, { "input": "285\n153", "output": "4422" }, { "input": "943\n13", "output": "216690" }, { "input": "675\n541", "output": "4556" }, { "input": "4\n912", "output": "206570" } ]
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", "output": "2646701" }, { "input": "200 4", "output": "584811251" }, { "input": "400 1", "output": "1" }, { "input": "400 2", "output": "79801" }, { "input": "400 3", "output": "21253401" }, { "input": "400 4", "output": "9477912501" }, { "input": "600 1", "output": "1" }, { "input": "600 2", "output": "179701" }, { "input": "600 3", "output": "71820101" }, { "input": "600 4", "output": "48187303751" }, { "input": "800 1", "output": "1" }, { "input": "800 2", "output": "319601" }, { "input": "800 3", "output": "170346801" }, { "input": "800 4", "output": "152620985001" }, { "input": "1000 1", "output": "1" }, { "input": "1000 2", "output": "499501" }, { "input": "1000 3", "output": "332833501" }, { "input": "1000 4", "output": "373086956251" }, { "input": "4 4", "output": "24" } ]
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", "output": "NO" }, { "input": "5 16\n3 3 2 7 9", "output": "YES" }, { "input": "6 38\n9 10 3 8 10 6", "output": "YES" }, { "input": "7 12\n4 4 5 2 2 4 9", "output": "NO" }, { "input": "8 15\n8 10 4 2 10 9 7 6", "output": "NO" }, { "input": "9 22\n1 3 5 9 7 6 1 10 1", "output": "NO" }, { "input": "10 30\n9 10 4 5 5 7 1 7 7 2", "output": "NO" }, { "input": "38 83\n9 9 3 10 2 4 6 10 9 5 1 8 7 4 7 2 6 5 3 1 10 8 4 8 3 7 1 2 7 6 8 6 5 2 3 1 1 2", "output": "NO" }, { "input": "84 212\n6 2 3 1 2 7 5 1 7 2 9 10 9 5 2 5 4 10 9 9 1 9 8 8 9 4 9 4 8 2 1 8 4 5 10 7 6 2 1 10 10 7 9 4 5 9 5 10 10 3 6 6 4 4 4 8 5 4 9 1 9 9 1 7 9 2 10 9 10 8 3 3 9 3 9 10 1 8 9 2 6 9 7 2", "output": "NO" }, { "input": "8 50\n8 8 8 4 4 6 10 10", "output": "YES" }, { "input": "7 24\n1 4 9 1 2 3 6", "output": "YES" }, { "input": "47 262\n3 7 6 4 10 3 5 7 2 9 3 2 2 10 8 7 3 10 6 3 1 1 4 10 2 9 2 10 6 4 3 6 3 6 9 7 8 8 3 3 10 5 2 10 7 10 9", "output": "YES" }, { "input": "42 227\n3 6 1 9 4 10 4 10 7 8 10 10 8 7 10 4 6 8 7 7 6 9 3 6 5 5 2 7 2 7 4 4 6 6 4 3 9 3 6 4 7 2", "output": "NO" }, { "input": "97 65\n3 10 2 6 1 4 7 5 10 3 10 4 5 5 1 6 10 7 4 5 3 9 9 8 6 9 2 3 6 8 5 5 5 5 5 3 10 4 1 8 8 9 8 4 1 4 9 3 6 3 1 4 8 3 10 8 6 4 5 4 3 2 2 4 3 6 4 6 2 3 3 3 7 5 1 8 1 4 5 1 1 6 4 2 1 7 8 6 1 1 5 6 5 10 6 7 5", "output": "NO" }, { "input": "94 279\n2 5 9 5 10 3 1 8 1 7 1 8 1 6 7 8 4 9 5 10 3 7 6 8 8 5 6 8 10 9 4 1 3 3 4 7 8 2 6 6 5 1 3 7 1 7 2 2 2 8 4 1 1 5 9 4 1 2 3 10 1 4 9 9 6 8 8 1 9 10 4 1 8 5 8 9 4 8 2 1 1 9 4 5 6 1 2 5 6 7 3 1 4 6", "output": "NO" }, { "input": "58 70\n8 2 10 2 7 3 8 3 8 7 6 2 4 10 10 6 10 3 7 6 4 3 5 5 5 3 8 10 3 4 8 4 2 6 8 9 6 9 4 3 5 2 2 6 10 6 2 1 7 5 6 4 1 9 10 2 4 5", "output": "NO" }, { "input": "6 14\n3 9 2 1 4 2", "output": "YES" }, { "input": "78 400\n5 9 3 4 7 4 1 4 6 3 9 1 8 3 3 6 10 2 1 9 6 1 8 10 1 6 4 5 2 1 5 9 6 10 3 6 5 2 4 10 6 9 3 8 10 7 2 8 8 2 10 1 4 5 2 8 6 4 4 3 5 2 3 10 1 9 8 5 6 7 9 1 8 8 5 4 2 4", "output": "YES" }, { "input": "41 181\n5 3 10 4 2 5 9 3 1 6 6 10 4 3 9 8 5 9 2 5 4 6 6 3 7 9 10 3 10 6 10 5 6 1 6 9 9 1 2 4 3", "output": "NO" }, { "input": "2 4\n4 4", "output": "YES" }, { "input": "29 71\n4 8 9 4 8 10 4 10 2 9 3 9 1 2 9 5 9 7 1 10 4 1 1 9 8 7 4 6 7", "output": "NO" }, { "input": "49 272\n4 10 8 7 5 6 9 7 2 6 6 2 10 7 5 6 5 3 6 4 3 7 9 3 7 7 4 10 5 6 7 3 6 4 6 7 7 2 5 5 7 3 7 9 3 6 6 2 1", "output": "YES" }, { "input": "91 486\n1 3 5 4 4 7 3 9 3 4 5 4 5 4 7 9 5 8 4 10 9 1 1 9 9 1 6 2 5 4 7 4 10 3 2 10 9 3 4 5 1 3 4 2 10 9 10 9 10 2 4 6 2 5 3 6 4 9 10 3 9 8 1 2 5 9 2 10 4 6 10 8 10 9 1 2 5 8 6 6 6 1 10 3 9 3 5 6 1 5 5", "output": "YES" }, { "input": "80 78\n1 9 4 9 8 3 7 10 4 9 2 1 4 4 9 5 9 1 2 6 5 2 4 8 4 6 9 6 7 10 1 9 10 4 7 1 7 10 8 9 10 5 2 6 7 7 7 7 7 8 2 5 1 7 2 3 2 5 10 6 3 4 5 2 6 3 4 2 7 9 9 3 8 8 2 3 7 1 5 10", "output": "NO" }, { "input": "53 245\n5 6 9 9 2 3 2 5 10 9 3 5 6 3 10 10 9 4 9 7 10 9 7 7 3 4 9 3 7 3 8 6 8 9 3 8 9 1 3 1 9 10 3 9 3 1 6 6 3 8 7 8 9", "output": "NO" }, { "input": "50 271\n6 9 10 1 1 1 8 3 6 6 3 2 5 9 7 5 7 9 10 9 4 6 6 2 6 6 9 5 1 6 5 8 3 2 5 10 10 1 4 1 4 6 1 8 7 8 9 4 7 5", "output": "YES" }, { "input": "38 214\n5 8 4 5 1 9 9 2 6 3 4 3 5 7 7 7 3 10 1 5 10 4 2 2 10 10 6 6 6 7 1 6 10 5 7 4 5 10", "output": "YES" }, { "input": "100 1\n10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10", "output": "NO" }, { "input": "100 100\n10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10", "output": "NO" }, { "input": "100 989\n10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10", "output": "NO" }, { "input": "100 990\n10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10", "output": "YES" }, { "input": "100 1000\n10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10", "output": "YES" }, { "input": "2 1\n1 1", "output": "YES" }, { "input": "2 1\n2 2", "output": "NO" }, { "input": "2 1000\n1 1", "output": "YES" }, { "input": "10 89\n10 10 10 10 10 10 10 10 10 10", "output": "NO" }, { "input": "10 44\n1 10 2 3 4 5 6 7 8 9", "output": "NO" } ]
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\nB man\nD woman\nC child\nE rat", "output": "E\nD\nC\nB\nA" }, { "input": "10\nCap captain\nD child\nC woman\nA woman\nE child\nMan man\nB child\nF woman\nRat rat\nRatt rat", "output": "Rat\nRatt\nD\nC\nA\nE\nB\nF\nMan\nCap" }, { "input": "5\nJoyxnkypf captain\nDxssgr woman\nKeojmnpd rat\nGdv man\nHnw man", "output": "Keojmnpd\nDxssgr\nGdv\nHnw\nJoyxnkypf" }, { "input": "11\nJue rat\nWyglbyphk rat\nGjlgu child\nGi man\nAttx rat\nTheorpkgx man\nYm rat\nX child\nB captain\nEnualf rat\nKktsgyuyv woman", "output": "Jue\nWyglbyphk\nAttx\nYm\nEnualf\nGjlgu\nX\nKktsgyuyv\nGi\nTheorpkgx\nB" }, { "input": "22\nWswwcvvm woman\nBtmfats rat\nI rat\nOcmtsnwx man\nUrcqv rat\nYghnogt woman\nWtyfc man\nWqle child\nUjfrelpu rat\nDstixj man\nAhksnio woman\nKhkvaap woman\nSjppvwm rat\nEgdmsv rat\nDank rat\nNquicjnw rat\nLh captain\nTdyaqaqln rat\nQtj rat\nTfgwijvq rat\nNbiso child\nNqthvbf woman", "output": "Btmfats\nI\nUrcqv\nUjfrelpu\nSjppvwm\nEgdmsv\nDank\nNquicjnw\nTdyaqaqln\nQtj\nTfgwijvq\nWswwcvvm\nYghnogt\nWqle\nAhksnio\nKhkvaap\nNbiso\nNqthvbf\nOcmtsnwx\nWtyfc\nDstixj\nLh" }, { "input": "36\nKqxmtwmsf child\nIze woman\nDlpr child\nK woman\nF captain\nRjwfeuhba rat\nBbv rat\nS rat\nMnmg woman\nSmzyx woman\nSr man\nQmhroracn rat\nSoqpuqock rat\nPibdq man\nIlrkrptx rat\nZaecfyqka man\nMmersfs child\nVvvocqi man\nHjeqxvq rat\nMpmb woman\nWmgu woman\nCerelmhoxi child\nA man\nDylv man\nXrdgmmtcpq woman\nXj woman\nCeh child\nOfccguo man\nNevr man\nAknkwdkq child\nBmo man\nLqo woman\nVej child\nT child\nRlijc man\nNsdtpdg woman", "output": "Rjwfeuhba\nBbv\nS\nQmhroracn\nSoqpuqock\nIlrkrptx\nHjeqxvq\nKqxmtwmsf\nIze\nDlpr\nK\nMnmg\nSmzyx\nMmersfs\nMpmb\nWmgu\nCerelmhoxi\nXrdgmmtcpq\nXj\nCeh\nAknkwdkq\nLqo\nVej\nT\nNsdtpdg\nSr\nPibdq\nZaecfyqka\nVvvocqi\nA\nDylv\nOfccguo\nNevr\nBmo\nRlijc\nF" }, { "input": "2\nA captain\nB man", "output": "B\nA" }, { "input": "2\nB woman\nA captain", "output": "B\nA" }, { "input": "2\nX child\nY captain", "output": "X\nY" }, { "input": "2\nX captain\nY rat", "output": "Y\nX" }, { "input": "6\nAbdelrhman captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman", "output": "Teddy\nAlice\nBob\nJulia\nCharlie\nAbdelrhman" }, { "input": "4\nAratos captain\nMind child\nAman woman\nCarrot man", "output": "Mind\nAman\nCarrot\nAratos" } ]
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--", "output": "YES" }, { "input": "-o--o-oo---o-o-o--o-o----oo------oo-----o----o-o-o--oo-o--o---o--o----------o---o-o-oo---o--o-oo-o--", "output": "NO" }, { "input": "-ooo--", "output": "YES" }, { "input": "---o--", "output": "YES" }, { "input": "oo-ooo", "output": "NO" }, { "input": "------o-o--o-----o--", "output": "YES" }, { "input": "--o---o----------o----o----------o--o-o-----o-oo---oo--oo---o-------------oo-----o-------------o---o", "output": "YES" }, { "input": "----------------------------------------------------------------------------------------------------", "output": "YES" }, { "input": "-oo-oo------", "output": "YES" }, { "input": "---------------------------------o----------------------------oo------------------------------------", "output": "NO" }, { "input": "oo--o--o--------oo----------------o-----------o----o-----o----------o---o---o-----o---------ooo---", "output": "NO" }, { "input": "--o---oooo--o-o--o-----o----ooooo--o-oo--o------oooo--------------ooo-o-o----", "output": "NO" }, { "input": "-----------------------------o--o-o-------", "output": "YES" }, { "input": "o-oo-o--oo----o-o----------o---o--o----o----o---oo-ooo-o--o-", "output": "YES" }, { "input": "oooooooooo-ooo-oooooo-ooooooooooooooo--o-o-oooooooooooooo-oooooooooooooo", "output": "NO" }, { "input": "-----------------o-o--oo------o--------o---o--o----------------oooo-------------ooo-----ooo-----o", "output": "NO" }, { "input": "ooo-ooooooo-oo-ooooooooo-oooooooooooooo-oooo-o-oooooooooo--oooooooooooo-oooooooooo-ooooooo", "output": "NO" }, { "input": "oo-o-ooooo---oo---o-oo---o--o-ooo-o---o-oo---oo---oooo---o---o-oo-oo-o-ooo----ooo--oo--o--oo-o-oo", "output": "NO" }, { "input": "-----o-----oo-o-o-o-o----o---------oo---ooo-------------o----o---o-o", "output": "YES" }, { "input": "oo--o-o-o----o-oooo-ooooo---o-oo--o-o--ooo--o--oooo--oo----o----o-o-oooo---o-oooo--ooo-o-o----oo---", "output": "NO" }, { "input": "------oo----o----o-oo-o--------o-----oo-----------------------o------------o-o----oo---------", "output": "NO" }, { "input": "-o--o--------o--o------o---o-o----------o-------o-o-o-------oo----oo------o------oo--o--", "output": "NO" }, { "input": "------------------o----------------------------------o-o-------------", "output": "YES" }, { "input": "-------------o----ooo-----o-o-------------ooo-----------ooo------o----oo---", "output": "YES" }, { "input": "-------o--------------------o--o---------------o---o--o-----", "output": "YES" }, { "input": "------------------------o------------o-----o----------------", "output": "YES" }, { "input": "------oo----------o------o-----o---------o------------o----o--o", "output": "YES" }, { "input": "------------o------------------o-----------------------o-----------o", "output": "YES" }, { "input": "o---o---------------", "output": "YES" }, { "input": "----------------------o---o----o---o-----------o-o-----o", "output": "YES" }, { "input": "----------------------------------------------------------------------o-o---------------------", "output": "YES" }, { "input": "----o---o-------------------------", "output": "YES" }, { "input": "o----------------------oo----", "output": "NO" }, { "input": "-o-o--o-o--o-----o-----o-o--o-o---oooo-o", "output": "NO" }, { "input": "-o-ooo-o--o----o--o-o-oo-----------o-o-", "output": "YES" }, { "input": "o-------o-------o-------------", "output": "YES" }, { "input": "oo----------------------o--------------o--------------o-----", "output": "YES" }, { "input": "-----------------------------------o---------------------o--------------------------", "output": "YES" }, { "input": "--o--o----o-o---o--o----o-o--oo-----o-oo--o---o---ooo-o--", "output": "YES" }, { "input": "---------------o-o----", "output": "YES" }, { "input": "o------ooo--o-o-oo--o------o----ooo-----o-----o-----o-ooo-o---o----oo", "output": "YES" }, { "input": "----o----o", "output": "YES" }, { "input": "o--o--o--o--o--o--o--o--o--o--o--o--", "output": "YES" }, { "input": "o---o---o---o---o----o----o----o---o---o---o", "output": "YES" }, { "input": "o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-", "output": "YES" }, { "input": "-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o", "output": "YES" }, { "input": "o----------o----------o----------o----------o----------o----------o----------o----------o----------o", "output": "YES" }, { "input": "o---------o---------o---------o---------o---------o---------o---------o---------o", "output": "YES" }, { "input": "--------o--------o--------o--------o--------o--------o--------o--------o--------", "output": "YES" }, { "input": "o---o----", "output": "NO" }, { "input": "---o----o", "output": "NO" }, { "input": "-o-", "output": "YES" }, { "input": "------oooo", "output": "NO" }, { "input": "oo--", "output": "YES" }, { "input": "---o", "output": "YES" }, { "input": "ooo-", "output": "NO" }, { "input": "oooooooo----------", "output": "NO" }, { "input": "oooo--", "output": "NO" }, { "input": "o-ooooo", "output": "NO" }, { "input": "-oo", "output": "NO" }, { "input": "ooooo-", "output": "NO" }, { "input": "ooo---------", "output": "YES" }, { "input": "oo-", "output": "NO" }, { "input": "---ooo", "output": "YES" } ]
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\n6 3\n10 6\n10 10\n10 7\n3 9\n16 1\n1 3", "output": "bolik" }, { "input": "30\n53 12\n13 98\n21 60\n76 58\n39 5\n62 58\n73 80\n13 75\n37 45\n44 86\n1 85\n13 33\n17 50\n12 26\n97 48\n52 40\n2 71\n95 79\n38 76\n24 54\n91 39\n97 92\n94 80\n50 61\n33 56\n22 91\n39 94\n31 56\n28 16\n20 44", "output": "tolik" }, { "input": "1\n3737203222172202 1", "output": "tolik" }, { "input": "1\n3737203222172202 1", "output": "tolik" } ]
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" }, { "input": "8 8 1 1 1", "output": "Second" }, { "input": "15 14 32 65 28", "output": "First" }, { "input": "894 197 325 232 902", "output": "First" }, { "input": "1 2 8 8 5", "output": "Friendship" }, { "input": "37 261 207 1 1000", "output": "Friendship" }, { "input": "29 344 406 900 1", "output": "Friendship" }, { "input": "1 2 8 9 8", "output": "First" }, { "input": "2 9 8 8 9", "output": "Friendship" }, { "input": "213 480 811 134 745", "output": "First" }, { "input": "2 313 856 964 421", "output": "Friendship" }, { "input": "1 10 2 6 10", "output": "Friendship" }, { "input": "2 7 6 2 3", "output": "Friendship" }, { "input": "637 324 69 612 998", "output": "Second" }, { "input": "13 849 819 723 918", "output": "Friendship" }, { "input": "9 5 7 8 7", "output": "First" }, { "input": "6 5 7 10 4", "output": "Friendship" }, { "input": "61 464 623 89 548", "output": "First" }, { "input": "641 31 29 161 802", "output": "Friendship" }, { "input": "3 3 1 6 9", "output": "Friendship" }, { "input": "2 3 9 8 2", "output": "Friendship" }, { "input": "485 117 368 567 609", "output": "First" }, { "input": "4 202 512 995 375", "output": "Friendship" }, { "input": "424 41 41 909 909", "output": "Friendship" }, { "input": "884 913 263 641 265", "output": "Second" }, { "input": "12 462 8 311 327", "output": "Second" }, { "input": "436 306 266 493 580", "output": "Second" }, { "input": "69 1 2 1 2", "output": "First" } ]
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": "tymbzjyqhymedasloqbq", "output": "NO" }, { "input": "yehluhlkwo", "output": "NO" }, { "input": "hatlevhhalrohairnolsvocafgueelrqmlqlleello", "output": "YES" }, { "input": "hhhtehdbllnhwmbyhvelqqyoulretpbfokflhlhreeflxeftelziclrwllrpflflbdtotvlqgoaoqldlroovbfsq", "output": "YES" }, { "input": "rzlvihhghnelqtwlexmvdjjrliqllolhyewgozkuovaiezgcilelqapuoeglnwmnlftxxiigzczlouooi", "output": "YES" }, { "input": "pfhhwctyqdlkrwhebfqfelhyebwllhemtrmeblgrynmvyhioesqklclocxmlffuormljszllpoo", "output": "YES" }, { "input": "lqllcolohwflhfhlnaow", "output": "NO" }, { "input": "heheeellollvoo", "output": "YES" }, { "input": "hellooo", "output": "YES" }, { "input": "o", "output": "NO" }, { "input": "hhqhzeclohlehljlhtesllylrolmomvuhcxsobtsckogdv", "output": "YES" }, { "input": "yoegfuzhqsihygnhpnukluutocvvwuldiighpogsifealtgkfzqbwtmgghmythcxflebrkctlldlkzlagovwlstsghbouk", "output": "YES" }, { "input": "uatqtgbvrnywfacwursctpagasnhydvmlinrcnqrry", "output": "NO" }, { "input": "tndtbldbllnrwmbyhvqaqqyoudrstpbfokfoclnraefuxtftmgzicorwisrpfnfpbdtatvwqgyalqtdtrjqvbfsq", "output": "NO" }, { "input": "rzlvirhgemelnzdawzpaoqtxmqucnahvqnwldklrmjiiyageraijfivigvozgwngiulttxxgzczptusoi", "output": "YES" }, { "input": "kgyelmchocojsnaqdsyeqgnllytbqietpdlgknwwumqkxrexgdcnwoldicwzwofpmuesjuxzrasscvyuqwspm", "output": "YES" }, { "input": "pnyvrcotjvgynbeldnxieghfltmexttuxzyac", "output": "NO" }, { "input": "dtwhbqoumejligbenxvzhjlhosqojetcqsynlzyhfaevbdpekgbtjrbhlltbceobcok", "output": "YES" }, { "input": "crrfpfftjwhhikwzeedrlwzblckkteseofjuxjrktcjfsylmlsvogvrcxbxtffujqshslemnixoeezivksouefeqlhhokwbqjz", "output": "YES" }, { "input": "jhfbndhyzdvhbvhmhmefqllujdflwdpjbehedlsqfdsqlyelwjtyloxwsvasrbqosblzbowlqjmyeilcvotdlaouxhdpoeloaovb", "output": "YES" }, { "input": "hwlghueoemiqtjhhpashjsouyegdlvoyzeunlroypoprnhlyiwiuxrghekaylndhrhllllwhbebezoglydcvykllotrlaqtvmlla", "output": "YES" }, { "input": "wshiaunnqnqxodholbipwhhjmyeblhgpeleblklpzwhdunmpqkbuzloetmwwxmeltkrcomulxauzlwmlklldjodozxryghsnwgcz", "output": "YES" }, { "input": "shvksednttggehroewuiptvvxtrzgidravtnjwuqrlnnkxbplctzkckinpkgjopjfoxdbojtcvsuvablcbkrzajrlhgobkcxeqti", "output": "YES" }, { "input": "hyyhddqhxhekehkwfhlnlsihzefwchzerevcjtokefplholrbvxlltdlafjxrfhleglrvlolojoqaolagtbeyogxlbgfolllslli", "output": "YES" }, { "input": "iaagrdhhelxpdegueiulflquvlzidoprzkehthkldaytrjwhyhprwjxlltinxvuilxohqgjqcvkkdcuoliekcnlilwgqlnlzouoo", "output": "YES" }, { "input": "wfluaeseldgxyvxpwuhkptdmlflnlhktwxiabsvkolsquymrmhzczzoybvlilhmvsuunggvgxzgyyffk", "output": "NO" }, { "input": "loee", "output": "NO" }, { "input": "izdipwylefqmjbuoznfglgcfvedeouflkeehxbasaqmiooppfsqlhprospqgxvzrcpwlfdddngoqvpwvggsnvvxhmjoslwjudjlo", "output": "NO" }, { "input": "pplynflbjlseflaegzqpdxswgunhnlglqhycrbcwdfhclmcrwekkzsoosmfblljeenwfjyifcvxihhhbyhmhlkvtskeglaovjnsi", "output": "YES" }, { "input": "xqjqmenkodmlhzyzmmvofdngktygbbxbzpluzcohohmalkoeuwfikblltaaigv", "output": "NO" }, { "input": "hello", "output": "YES" }, { "input": "oohell", "output": "NO" }, { "input": "hell", "output": "NO" }, { "input": "eloellohoelo", "output": "NO" }, { "input": "helllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllo", "output": "YES" } ]
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-12\n-13\n-14", "output": "second" }, { "input": "4\n16\n12\n19\n-98", "output": "second" }, { "input": "5\n-6\n-1\n-1\n5\n3", "output": "second" }, { "input": "11\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1", "output": "first" }, { "input": "1\n-534365", "output": "second" }, { "input": "1\n10253033", "output": "first" }, { "input": "3\n-1\n-2\n3", "output": "first" }, { "input": "8\n1\n-2\n-3\n4\n5\n-6\n-7\n8", "output": "second" }, { "input": "2\n1\n-1", "output": "second" }, { "input": "5\n1\n2\n3\n4\n5", "output": "first" }, { "input": "5\n-1\n-2\n-3\n-4\n-5", "output": "second" }, { "input": "10\n-1\n-2\n-3\n-4\n-5\n5\n4\n3\n2\n1", "output": "first" }, { "input": "131\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n-1\n-1\n2", "output": "first" }, { "input": "6\n-1\n-2\n-3\n1\n2\n3", "output": "first" }, { "input": "3\n1000000000\n1000000000\n1000000000", "output": "first" }, { "input": "12\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000", "output": "first" }, { "input": "4\n1000000000\n1000000000\n1000000000\n-1000000000", "output": "first" }, { "input": "20\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000", "output": "first" }, { "input": "5\n1000000000\n1000000000\n-1000000000\n-1000000000\n-1000000000", "output": "second" }, { "input": "4\n1\n-1000000000\n-1000000000\n-1000000000", "output": "second" }, { "input": "5\n1000000000\n1000000000\n1000000000\n-1000000000\n-1000000000", "output": "first" }, { "input": "4\n-1\n1000000000\n1000000000\n1000000000", "output": "first" }, { "input": "11\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000", "output": "first" }, { "input": "2\n-4\n4", "output": "first" }, { "input": "3\n-12\n3\n9", "output": "second" }, { "input": "3\n9\n1\n-10", "output": "second" }, { "input": "3\n1\n2\n-3", "output": "second" }, { "input": "4\n55\n5\n-5\n-55", "output": "first" }, { "input": "4\n5\n-1\n1\n-5", "output": "first" }, { "input": "2\n-5\n6", "output": "first" }, { "input": "4\n5\n-4\n3\n-40", "output": "second" }, { "input": "4\n1000000000\n1000000000\n1000000000\n-5", "output": "first" }, { "input": "6\n3\n2\n1\n-3\n-1\n-2", "output": "first" }, { "input": "5\n4\n1\n1\n-3\n-3", "output": "first" }, { "input": "5\n208\n-52\n-52\n-52\n-52", "output": "first" }, { "input": "3\n-100\n-200\n300", "output": "first" }, { "input": "3\n400\n-200\n-200", "output": "first" }, { "input": "3\n208\n-207\n-1", "output": "first" }, { "input": "3\n98888887\n98888888\n-197777775", "output": "second" } ]
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" }, { "input": "4 2", "output": "2" }, { "input": "1000 700", "output": "6" }, { "input": "959986566087 524054155168", "output": "90" }, { "input": "4 3", "output": "4" }, { "input": "7 6", "output": "7" }, { "input": "1000 999", "output": "1000" }, { "input": "1000 998", "output": "500" }, { "input": "1000 997", "output": "336" }, { "input": "42 1", "output": "42" }, { "input": "1000 1", "output": "1000" }, { "input": "8 5", "output": "5" }, { "input": "13 8", "output": "6" }, { "input": "987 610", "output": "15" }, { "input": "442 42", "output": "22" }, { "input": "754 466", "output": "13" }, { "input": "1000000000000 999999999999", "output": "1000000000000" }, { "input": "1000000000000 999999999998", "output": "500000000000" }, { "input": "941 14", "output": "74" }, { "input": "998 2", "output": "499" }, { "input": "1000 42", "output": "32" }, { "input": "1000 17", "output": "66" }, { "input": "5 1", "output": "5" }, { "input": "5 2", "output": "4" }, { "input": "5 3", "output": "4" }, { "input": "5 4", "output": "5" }, { "input": "293 210", "output": "17" }, { "input": "787878787878 424242424242", "output": "8" }, { "input": "956722026041 591286729879", "output": "58" }, { "input": "956722026041 365435296162", "output": "58" }, { "input": "628625247282 464807889701", "output": "102" }, { "input": "695928431619 424778620208", "output": "167" }, { "input": "1000000000000 42", "output": "23809523821" }, { "input": "987654345678 23", "output": "42941493300" }, { "input": "10000000001 2", "output": "5000000002" }, { "input": "1000000000000 2", "output": "500000000000" }, { "input": "1000000000000 3", "output": "333333333336" }, { "input": "100000000000 3", "output": "33333333336" }, { "input": "100000000000 23", "output": "4347826109" }, { "input": "999999999997 7", "output": "142857142861" }, { "input": "8589934592 4294967296", "output": "2" } ]
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", "output": "0" }, { "input": "5\n984181411 215198610 969039668 60631313 85746445", "output": "778956192" }, { "input": "10\n12528139 986722043 1595702 997595062 997565216 997677838 999394520 999593240 772077 998195916", "output": "1982580029" }, { "input": "100\n9997 9615 4045 2846 7656 2941 2233 9214 837 2369 5832 578 6146 8773 164 7303 3260 8684 2511 6608 9061 9224 7263 7279 1361 1823 8075 5946 2236 6529 6783 7494 510 1217 1135 8745 6517 182 8180 2675 6827 6091 2730 897 1254 471 1990 1806 1706 2571 8355 5542 5536 1527 886 2093 1532 4868 2348 7387 5218 3181 3140 3237 4084 9026 504 6460 9256 6305 8827 840 2315 5763 8263 5068 7316 9033 7552 9939 8659 6394 4566 3595 2947 2434 1790 2673 6291 6736 8549 4102 953 8396 8985 1053 5906 6579 5854 6805", "output": "478217" } ]
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 1000", "output": "100" }, { "input": "8\n200000 1 200000 1 200000 1 200000 2", "output": "1" }, { "input": "5\n20000 1 2 3 4", "output": "20000" }, { "input": "2\n200000 1", "output": "200000" }, { "input": "3\n2 100 2", "output": "100" }, { "input": "2\n10 1", "output": "10" }, { "input": "11\n1 1 1 1 1 1 1 1 1 1 1", "output": "1" }, { "input": "3\n5 5 5", "output": "5" }, { "input": "2\n5 1", "output": "5" } ]
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": "5 6" }, { "input": "10\n1 1 2 1 1 2 2 1 2 3", "output": "1 8" }, { "input": "10\n5 4 3 2 1 1 2 3 4 5", "output": "5 6" }, { "input": "10\n1 10 100 1000 10000 1 10 100 1000 10000", "output": "1 6" }, { "input": "10\n9 9 9 9 8 9 8 8 8 8", "output": "1 6" }, { "input": "10\n1 11 111 1111 1 11 11 1 1111 1111", "output": "2 7" } ]
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" }, { "input": "6 100\n170427799 37215529 675016434 168544291 683447134 950090227", "output": "6" }, { "input": "4 2\n194041605 706221269 69909135 257655784", "output": "3" }, { "input": "4 2\n9581849 67346651 530497 272158241", "output": "4" }, { "input": "3 47\n378261451 163985731 230342101", "output": "3" }, { "input": "2 3\n247776868 480572137", "output": "1" }, { "input": "7 77\n366496749 549646417 278840199 119255907 33557677 379268590 150378796", "output": "7" }, { "input": "40 31\n32230963 709031779 144328646 513494529 36547831 416998222 84161665 318773941 170724397 553666286 368402971 48581613 31452501 368026285 47903381 939151438 204145360 189920160 288159400 133145006 314295423 450219949 160203213 358403181 478734385 29331901 31051111 110710191 567314089 139695685 111511396 87708701 317333277 103301481 110400517 634446253 481551313 39202255 105948 738066085", "output": "40" }, { "input": "1 8\n55521105", "output": "1" }, { "input": "49 3\n34644511 150953622 136135827 144208961 359490601 86708232 719413689 188605873 64330753 488776302 104482891 63360106 437791390 46521319 70778345 339141601 136198441 292941209 299339510 582531183 555958105 437904637 74219097 439816011 236010407 122674666 438442529 186501223 63932449 407678041 596993853 92223251 849265278 480265849 30983497 330283357 186901672 20271344 794252593 123774176 27851201 52717531 479907210 196833889 149331196 82147847 255966471 278600081 899317843", "output": "44" }, { "input": "26 2\n330381357 185218042 850474297 483015466 296129476 1205865 538807493 103205601 160403321 694220263 416255901 7245756 507755361 88187633 91426751 1917161 58276681 59540376 576539745 595950717 390256887 105690055 607818885 28976353 488947089 50643601", "output": "22" }, { "input": "38 1\n194481717 126247087 815196361 106258801 381703249 283859137 15290101 40086151 213688513 577996947 513899717 371428417 107799271 11136651 5615081 323386401 381128815 34217126 17709913 520702093 201694245 570931849 169037023 417019726 282437316 7417126 271667553 11375851 185087449 410130883 383045677 5764771 905017051 328584026 215330671 299553233 15838255 234532105", "output": "20" }, { "input": "44 9\n683216389 250581469 130029957 467020047 188395565 206237982 63257361 68314981 732878407 563579660 199133851 53045209 665723851 16273169 10806790 556633156 350593410 474645249 478790761 708234243 71841230 18090541 19836685 146373571 17947452 534010506 46933264 377035021 311636557 75193963 54321761 12759959 71120181 548816939 23608621 31876417 107672995 72575155 369667956 20574379 210596751 532163173 75726739 853719629", "output": "44" }, { "input": "8 6\n204157376 10514197 65483881 347219841 263304577 296402721 11739011 229776191", "output": "8" }, { "input": "38 29\n333702889 680931737 61137217 203030505 68728281 11414209 642645708 590904616 3042901 607198177 189041074 700764043 813035201 198341461 126403544 401436841 420826465 45046581 20249976 46978855 46397957 706610773 24701041 57954481 51603266 593109701 385569073 178982291 582152863 287317968 1474090 34825141 432421977 130257781 151516903 540852403 548392 117246529", "output": "38" }, { "input": "19 3\n562569697 549131571 50676718 84501863 74567295 702372009 365895280 451459937 40378543 167666701 158635641 53639293 442332661 825055617 100109161 326616021 862332843 533271196 4791547", "output": "18" }, { "input": "1 1\n44", "output": "0" }, { "input": "1 1\n4", "output": "1" }, { "input": "10 3\n444 447 774 777 7777 4447 4 7 7 4", "output": "8" } ]
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 81 2 67 52\n2\n2 40\n6 51", "output": "87\n0\n23\n28\n141\n0\n86\n2\n67\n52" }, { "input": "2\n72 45\n6\n1 69\n2 41\n1 19\n2 7\n1 5\n2 1", "output": "0\n0" }, { "input": "10\n95 54 36 39 98 30 19 24 14 12\n3\n9 5\n8 15\n7 5", "output": "95\n54\n36\n39\n98\n34\n0\n28\n13\n21" }, { "input": "100\n95 15 25 18 64 62 23 59 70 84 50 26 87 35 75 86 0 22 77 60 66 41 21 9 75 50 25 3 69 14 39 68 64 46 59 99 2 0 21 76 90 12 61 42 6 91 36 39 47 41 93 81 66 57 70 36 68 89 52 1 19 93 67 22 76 20 8 81 98 18 100 73 61 93 75 80 53 72 40 20 2 86 33 59 27 16 11 26 55 44 47 55 94 58 2 55 82 22 9 95\n0", "output": "95\n15\n25\n18\n64\n62\n23\n59\n70\n84\n50\n26\n87\n35\n75\n86\n0\n22\n77\n60\n66\n41\n21\n9\n75\n50\n25\n3\n69\n14\n39\n68\n64\n46\n59\n99\n2\n0\n21\n76\n90\n12\n61\n42\n6\n91\n36\n39\n47\n41\n93\n81\n66\n57\n70\n36\n68\n89\n52\n1\n19\n93\n67\n22\n76\n20\n8\n81\n98\n18\n100\n73\n61\n93\n75\n80\n53\n72\n40\n20\n2\n86\n33\n59\n27\n16\n11\n26\n55\n44\n47\n55\n94\n58\n2\n55\n82\n22\n9\n95" }, { "input": "1\n100\n1\n1 100", "output": "0" }, { "input": "1\n100\n1\n1 1", "output": "0" }, { "input": "1\n50\n1\n1 25", "output": "0" }, { "input": "2\n50 0\n1\n1 1", "output": "0\n49" }, { "input": "1\n10\n0", "output": "10" } ]
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 20 9 14 14 10 13 6 13 14 17 6 8 20 12 10 15 13 17 5 12 13 11 7 5 5 2 3 15 13 7 14 14 19 2 13 14 5 15 3 19 15 16 4 1", "output": "1891" }, { "input": "100 9000\n5 2 3 1 1 3 4 9 9 6 7 10 10 10 2 10 6 8 8 6 7 9 9 5 6 2 1 10 10 9 4 5 9 2 4 3 8 5 6 1 1 5 3 6 2 6 6 6 5 8 3 6 7 3 1 10 9 1 8 3 10 9 5 6 3 4 1 1 10 10 2 3 4 8 10 10 5 1 5 3 6 8 10 6 10 2 1 8 10 1 7 6 9 10 5 2 3 5 3 2", "output": "1688" }, { "input": "100 8007\n5 19 14 18 9 6 15 8 1 14 11 20 3 17 7 12 2 6 3 17 7 20 1 14 20 17 2 10 13 7 18 18 9 10 16 8 1 11 11 9 13 18 9 20 12 12 7 15 12 17 11 5 11 15 9 2 15 1 18 3 18 16 15 4 10 5 18 13 13 12 3 8 17 2 12 2 13 3 1 13 2 4 9 10 18 10 14 4 4 17 12 19 2 9 6 5 5 20 18 12", "output": "1391" }, { "input": "39 2412\n1 1 1 1 1 1 26 1 1 1 99 1 1 1 1 1 1 1 1 1 1 88 7 1 1 1 1 76 1 1 1 93 40 1 13 1 68 1 32", "output": "368" }, { "input": "39 2617\n47 1 1 1 63 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 70 1 99 63 1 1 1 1 1 1 1 1 64 1 1", "output": "435" }, { "input": "39 3681\n83 77 1 94 85 47 1 98 29 16 1 1 1 71 96 85 31 97 96 93 40 50 98 1 60 51 1 96 100 72 1 1 1 89 1 93 1 92 100", "output": "326" }, { "input": "45 894\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 28 28 1 1 1 1 1 1 1 1 1 1 1 1 1 1 99 3 1 1", "output": "139" }, { "input": "45 4534\n1 99 65 99 4 46 54 80 51 30 96 1 28 30 44 70 78 1 1 100 1 62 1 1 1 85 1 1 1 61 1 46 75 1 61 77 97 26 67 1 1 63 81 85 86", "output": "514" }, { "input": "72 3538\n52 1 8 1 1 1 7 1 1 1 1 48 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 40 1 1 38 1 1 1 1 1 1 1 1 1 1 1 35 1 93 79 1 1 1 1 1 1 1 1 1 51 1 1 1 1 1 1 1 1 1 1 1 1 96 1", "output": "586" }, { "input": "81 2200\n1 59 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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 93 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 50 1 1 1 1 1 1 1 1 1 1 1", "output": "384" }, { "input": "81 2577\n85 91 1 1 2 1 1 100 1 80 1 1 17 86 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 37 1 66 24 1 1 96 49 1 66 1 44 1 1 1 1 98 1 1 1 1 35 1 37 3 35 1 1 87 64 1 24 1 58 1 1 42 83 5 1 1 1 1 1 95 1 94 1 50 1 1", "output": "174" }, { "input": "81 4131\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 1 1 1 1 1 1 1 1 1 1 16 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 1 1 1 1 1 1 1 1 1 1 1", "output": "807" }, { "input": "81 6315\n1 1 67 100 1 99 36 1 92 5 1 96 42 12 1 57 91 1 1 66 41 30 74 95 1 37 1 39 91 69 1 52 77 47 65 1 1 93 96 74 90 35 85 76 71 92 92 1 1 67 92 74 1 1 86 76 35 1 56 16 27 57 37 95 1 40 20 100 51 1 80 60 45 79 95 1 46 1 25 100 96", "output": "490" }, { "input": "96 1688\n1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 45 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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 25 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 71 1 1 1 30 1 1 1", "output": "284" }, { "input": "96 8889\n1 1 18 1 1 1 1 1 1 1 1 1 99 1 1 1 1 88 1 45 1 1 1 1 1 1 1 1 1 1 1 1 1 1 96 1 1 1 1 21 1 1 1 1 1 1 1 73 1 1 1 1 1 10 1 1 1 1 1 1 1 46 43 1 1 1 1 1 98 1 1 1 1 1 1 6 1 1 1 1 1 74 1 25 1 55 1 1 1 13 1 1 54 1 1 1", "output": "1589" }, { "input": "10 100\n1 1 1 1 1 1 1 1 1 1", "output": "18" }, { "input": "100 10000\n54 46 72 94 79 83 91 54 73 3 24 55 54 31 28 20 19 6 25 19 47 23 1 70 15 87 51 39 54 77 55 5 60 3 15 99 56 88 22 78 79 21 38 27 28 86 7 88 12 59 55 70 25 1 70 49 1 45 69 72 50 17 4 56 8 100 90 34 35 20 61 76 88 79 4 74 65 68 75 26 40 72 59 94 10 67 96 85 29 90 47 24 44 1 66 93 55 36 1 99", "output": "1017" }, { "input": "100 6000\n41 31 23 17 24 78 26 96 93 48 46 2 49 33 35 9 73 100 34 48 83 36 33 69 43 24 3 74 8 81 27 33 94 38 77 9 76 90 62 90 21 67 22 22 12 2 17 27 61 18 72 85 59 65 71 38 90 75 74 66 60 47 58 50 90 95 75 10 5 100 97 29 83 88 65 26 93 90 22 98 36 55 70 38 50 92 88 72 99 96 25 14 74 16 25 92 67 94 77 96", "output": "-1" }, { "input": "1 1\n1", "output": "0" }, { "input": "1 6\n1", "output": "1" }, { "input": "1 5\n1", "output": "0" }, { "input": "1 3\n4", "output": "-1" }, { "input": "3 24\n2 1 2", "output": "-1" } ]
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" }, { "input": "((#(()#(##", "output": "1\n1\n1\n1" }, { "input": "##((((((()", "output": "-1" }, { "input": "(((((((((((((((((((###################", "output": "1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1" }, { "input": "((#)(", "output": "-1" }, { "input": "((#)((#)((#)((#)((#)((#)((#)((#)((#)((#)((#)((#)((#)((#)((#)((##", "output": "1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1" }, { "input": ")((##((###", "output": "-1" }, { "input": "(#))(#(#)((((#(##((#(#((((#(##((((((#((()(()(())((()#((((#((()((((#(((((#(##)(##()((((()())(((((#(((", "output": "-1" }, { "input": "#(#(#((##((()))(((#)(#()#(((()()(()#(##(((()(((()))#(((((()(((((((()#((#((()(#(((()(()##(()(((()((#(", "output": "-1" }, { "input": "((#(", "output": "-1" }, { "input": "()#(#())()()#)(#)()##)#((()#)((#)()#())((#((((((((#)()()(()()(((((#)#(#((((#((##()(##(((#(()(#((#))#", "output": "-1" }, { "input": "(())((((#)", "output": "3" }, { "input": "(#(", "output": "-1" }, { "input": "((#)(", "output": "-1" }, { "input": "(((()#(#)(", "output": "-1" }, { "input": "#((#", "output": "-1" }, { "input": "(#((((()", "output": "-1" }, { "input": "(#((", "output": "-1" }, { "input": ")(((())#", "output": "-1" } ]
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", "output": "1\n1 " }, { "input": "2\nBB", "output": "1\n2 " }, { "input": "100\nWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWB", "output": "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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 " }, { "input": "1\nW", "output": "0" }, { "input": "2\nWW", "output": "0" }, { "input": "2\nWB", "output": "1\n1 " }, { "input": "2\nBW", "output": "1\n1 " }, { "input": "3\nBBB", "output": "1\n3 " }, { "input": "3\nBWB", "output": "2\n1 1 " }, { "input": "3\nWBB", "output": "1\n2 " }, { "input": "3\nWWB", "output": "1\n1 " }, { "input": "3\nWBW", "output": "1\n1 " }, { "input": "3\nBWW", "output": "1\n1 " }, { "input": "3\nWWW", "output": "0" }, { "input": "100\nBBBWWWWWWBBWWBBWWWBBWBBBBBBBBBBBWBBBWBBWWWBBWWBBBWBWWBBBWWBBBWBBBBBWWWBWWBBWWWWWWBWBBWWBWWWBWBWWWWWB", "output": "21\n3 2 2 2 11 3 2 2 3 1 3 3 5 1 2 1 2 1 1 1 1 " }, { "input": "5\nBBBWB", "output": "2\n3 1 " }, { "input": "5\nBWWWB", "output": "2\n1 1 " }, { "input": "5\nWWWWB", "output": "1\n1 " }, { "input": "5\nBWWWW", "output": "1\n1 " }, { "input": "5\nBBBWW", "output": "1\n3 " }, { "input": "5\nWWBBB", "output": "1\n3 " }, { "input": "10\nBBBBBWWBBB", "output": "2\n5 3 " }, { "input": "10\nBBBBWBBWBB", "output": "3\n4 2 2 " }, { "input": "20\nBBBBBWWBWBBWBWWBWBBB", "output": "6\n5 1 2 1 1 3 " }, { "input": "20\nBBBWWWWBBWWWBWBWWBBB", "output": "5\n3 2 1 1 3 " }, { "input": "20\nBBBBBBBBWBBBWBWBWBBB", "output": "5\n8 3 1 1 3 " }, { "input": "20\nBBBWBWBWWWBBWWWWBWBB", "output": "6\n3 1 1 2 1 2 " }, { "input": "40\nBBBBBBWWWWBWBWWWBWWWWWWWWWWWBBBBBBBBBBBB", "output": "5\n6 1 1 1 12 " }, { "input": "40\nBBBBBWBWWWBBWWWBWBWWBBBBWWWWBWBWBBBBBBBB", "output": "9\n5 1 2 1 1 4 1 1 8 " }, { "input": "50\nBBBBBBBBBBBWWWWBWBWWWWBBBBBBBBWWWWWWWBWWWWBWBBBBBB", "output": "7\n11 1 1 8 1 1 6 " }, { "input": "50\nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW", "output": "0" }, { "input": "50\nBBBBBWWWWWBWWWBWWWWWBWWWBWWWWWWBBWBBWWWWBWWWWWWWBW", "output": "9\n5 1 1 1 1 2 2 1 1 " }, { "input": "50\nWWWWBWWBWWWWWWWWWWWWWWWWWWWWWWWWWBWBWBWWWWWWWBBBBB", "output": "6\n1 1 1 1 1 5 " }, { "input": "50\nBBBBBWBWBWWBWBWWWWWWBWBWBWWWWWWWWWWWWWBWBWWWWBWWWB", "output": "12\n5 1 1 1 1 1 1 1 1 1 1 1 " }, { "input": "50\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB", "output": "1\n50 " }, { "input": "100\nBBBBBBBBBBBWBWWWWBWWBBWBBWWWWWWWWWWBWBWWBWWWWWWWWWWWBBBWWBBWWWWWBWBWWWWBWWWWWWWWWWWBWWWWWBBBBBBBBBBB", "output": "15\n11 1 1 2 2 1 1 1 3 2 1 1 1 1 11 " }, { "input": "100\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB", "output": "1\n100 " }, { "input": "100\nBBBBBBBBBBBBBBBBBBBBWBWBWWWWWBWWWWWWWWWWWWWWBBWWWBWWWWBWWBWWWWWWBWWWWWWWWWWWWWBWBBBBBBBBBBBBBBBBBBBB", "output": "11\n20 1 1 1 2 1 1 1 1 1 20 " }, { "input": "100\nBBBBWWWWWWWWWWWWWWWWWWWWWWWWWBWBWWWWWBWBWWWWWWBBWWWWWWWWWWWWBWWWWBWWWWWWWWWWWWBWWWWWWWBWWWWWWWBBBBBB", "output": "11\n4 1 1 1 1 2 1 1 1 1 6 " }, { "input": "5\nBWBWB", "output": "3\n1 1 1 " }, { "input": "10\nWWBWWWBWBB", "output": "3\n1 1 2 " }, { "input": "50\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB", "output": "1\n50 " }, { "input": "50\nBBBBBBBBBBBBBBBBBWWBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB", "output": "2\n17 31 " }, { "input": "100\nBBBBBBBBBBBBBBBBBBBBBBBBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB", "output": "2\n24 42 " }, { "input": "90\nWWBWWBWBBWBBWWBWBWBBBWBWBBBWBWBWBWBWBWBWBWBBBBBWBBWWWWBWBBWBWWBBBWBWBWWBWBWBWBWWWWWWBWBBBB", "output": "30\n1 1 2 2 1 1 3 1 3 1 1 1 1 1 1 1 5 2 1 2 1 3 1 1 1 1 1 1 1 4 " }, { "input": "100\nBWWWBWBWBBBBBWBWWBWBWWWBWBWBWWBBWWBBBWBBBWWBWBWWBBBBWBWBBBWBWBBWWWWWWBWWBBBBWBWBWWBWBWWWBWBWWBWBWWWB", "output": "31\n1 1 1 5 1 1 1 1 1 1 2 3 3 1 1 4 1 3 1 2 1 4 1 1 1 1 1 1 1 1 1 " }, { "input": "90\nWBWBBBBBBWWWBBWWBWWWBBWWBWWWBWBBWBWBBWWWWBWBWBBWBBWBWWWBBWBBWWWWBWBBWWWBBBWBBWBWBBBBWWBWWB", "output": "25\n1 6 2 1 2 1 1 2 1 2 1 1 2 2 1 2 2 1 2 3 2 1 4 1 1 " }, { "input": "80\nBBWWBBBWBBWWWWBBWBWBBWWWWWBWBBWWBWBWBWBWBWWBWWBWWWBWBBWBBWBBWBBBWWBBBBBBBWBBBWBB", "output": "23\n2 3 2 2 1 2 1 2 1 1 1 1 1 1 1 1 2 2 2 3 7 3 2 " }, { "input": "65\nWWWWBWWWBBBBBWWWWWWBBBWWBBBBWWWWWWWWBBBWWWWBWBWWBBWWWWBWWWBBWBBBB", "output": "11\n1 5 3 4 3 1 1 2 1 2 4 " } ]
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": "chnenu" }, { "input": "ERPZGrodyu", "output": "erpzgrodyu" }, { "input": "KSXBXWpebh", "output": "KSXBXWPEBH" }, { "input": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv", "output": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv" }, { "input": "Amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd", "output": "amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd" }, { "input": "ISAGFJFARYFBLOPQDSHWGMCNKMFTLVFUGNJEWGWNBLXUIATXEkqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv", "output": "isagfjfaryfblopqdshwgmcnkmftlvfugnjewgwnblxuiatxekqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv" }, { "input": "XHRPXZEGHSOCJPICUIXSKFUZUPYTSGJSDIYBCMNMNBPNDBXLXBzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg", "output": "xhrpxzeghsocjpicuixskfuzupytsgjsdiybcmnmnbpndbxlxbzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg" }, { "input": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGAdkcetqjljtmttlonpekcovdzebzdkzggwfsxhapmjkdbuceak", "output": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGADKCETQJLJTMTTLONPEKCOVDZEBZDKZGGWFSXHAPMJKDBUCEAK" }, { "input": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFw", "output": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFW" }, { "input": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB", "output": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB" }, { "input": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge", "output": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge" }, { "input": "Ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw", "output": "ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw" }, { "input": "YQOMLKYAORUQQUCQZCDYMIVDHGWZFFRMUVTAWCHERFPMNRYRIkgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks", "output": "yqomlkyaoruqqucqzcdymivdhgwzffrmuvtawcherfpmnryrikgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks" }, { "input": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJcuusigdqfkumewjtdyitveeiaybwrhomrwmpdipjwiuxfnwuz", "output": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJCUUSIGDQFKUMEWJTDYITVEEIAYBWRHOMRWMPDIPJWIUXFNWUZ" }, { "input": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWuckzcpxosodcjaaakvlxpbiigsiauviilylnnqlyucziihqg", "output": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWUCKZCPXOSODCJAAAKVLXPBIIGSIAUVIILYLNNQLYUCZIIHQG" }, { "input": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO", "output": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO" }, { "input": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDd", "output": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDD" }, { "input": "EBWOVSNLYTWWXrnovgugogtjahnmatomubebyxakas", "output": "ebwovsnlytwwxrnovgugogtjahnmatomubebyxakas" }, { "input": "AORNNDKTRLRVGDPXJKXFTPFpopuzrlqumrxssskvbm", "output": "AORNNDKTRLRVGDPXJKXFTPFPOPUZRLQUMRXSSSKVBM" }, { "input": "DBBZJCWQEVGYHEEUHJAWRHBDPsnplijbwtdibqrrheebfxqcvn", "output": "dbbzjcwqevgyheeuhjawrhbdpsnplijbwtdibqrrheebfxqcvn" }, { "input": "t", "output": "t" }, { "input": "N", "output": "N" }, { "input": "kv", "output": "kv" }, { "input": "Ur", "output": "ur" }, { "input": "CN", "output": "CN" } ]
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": "12" }, { "input": "3555165 6693472\n1499112 556941 3075290", "output": "3089339" }, { "input": "0 0\n1000000000 1000000000 1000000000", "output": "7000000000" }, { "input": "1 1\n0 1 0", "output": "0" }, { "input": "117708228 562858833\n118004008 360437130 154015822", "output": "738362681" }, { "input": "999998118 700178721\n822106746 82987112 547955384", "output": "1753877029" }, { "input": "566568710 765371101\n60614022 80126928 809950465", "output": "1744607222" }, { "input": "448858599 829062060\n764716760 97644201 203890025", "output": "1178219122" }, { "input": "626115781 966381948\n395190569 820194184 229233367", "output": "1525971878" }, { "input": "803372962 103701834\n394260597 837711458 623172928", "output": "3426388098" }, { "input": "980630143 241021722\n24734406 928857659 312079781", "output": "1624075280" }, { "input": "862920032 378341609\n360240924 241342224 337423122", "output": "974174021" }, { "input": "40177212 515661496\n64343660 963892207 731362684", "output": "3694721078" }, { "input": "217434393 579352456\n694817470 981409480 756706026", "output": "4825785129" }, { "input": "394691574 716672343\n398920207 72555681 150645586", "output": "475704521" }, { "input": "276981463 853992230\n29394015 90072954 839552440", "output": "1754738044" }, { "input": "843552056 919184611\n341530221 423649259 101547519", "output": "263157645" }, { "input": "20809236 56504497\n972004030 441166533 495487081", "output": "4235488636" }, { "input": "198066417 825228166\n602477839 532312735 520830423", "output": "2808777834" }, { "input": "80356306 962548053\n601547868 549830008 914769984", "output": "4004161345" }, { "input": "257613487 394835231\n642087093 567347282 308709545", "output": "2692548667" }, { "input": "139903376 532155119\n641157122 289897263 629020178", "output": "3077110809" }, { "input": "612127849 669475006\n271630930 676010757 22959739", "output": "682559736" }, { "input": "0 0\n0 0 0", "output": "0" }, { "input": "1000000000 1000000000\n499999998 4 333333332", "output": "0" }, { "input": "1000000000 1000000000\n1000000000 1000000000 1000000000", "output": "5000000000" }, { "input": "4 3\n1 0 1", "output": "0" }, { "input": "4 12\n1 2 3", "output": "0" }, { "input": "4 20\n1 2 1", "output": "0" }, { "input": "100 10\n2 3 4", "output": "5" }, { "input": "6 0\n1 1 1", "output": "4" }, { "input": "25 5\n3 3 3", "output": "7" }, { "input": "48 27\n22 39 20", "output": "107" }, { "input": "4 0\n1 1 1", "output": "4" } ]
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" }, { "input": "16 6\n3 1\n16 4\n10 3\n9 3\n19 5\n8 2", "output": "4" }, { "input": "1 0", "output": "1" }, { "input": "1 1\n1 1", "output": "1" }, { "input": "1 1\n1 1", "output": "1" }, { "input": "1 2\n1 1\n2 2", "output": "1" }, { "input": "2 2\n2 1\n1 1", "output": "1" }, { "input": "2 0", "output": "-1" }, { "input": "2 1\n3 3", "output": "2" }, { "input": "3 2\n1 1\n3 3", "output": "3" }, { "input": "3 3\n1 1\n3 3\n2 2", "output": "3" }, { "input": "3 0", "output": "-1" }, { "input": "1 1\n2 1", "output": "1" }, { "input": "2 2\n2 1\n1 1", "output": "1" }, { "input": "2 3\n3 2\n1 1\n2 1", "output": "1" }, { "input": "3 0", "output": "-1" }, { "input": "3 1\n1 1", "output": "-1" }, { "input": "2 2\n1 1\n3 1", "output": "1" }, { "input": "1 3\n1 1\n2 1\n3 1", "output": "1" }, { "input": "81 0", "output": "-1" }, { "input": "22 1\n73 73", "output": "22" }, { "input": "63 2\n10 10\n64 64", "output": "63" }, { "input": "88 3\n37 37\n15 15\n12 12", "output": "88" }, { "input": "29 4\n66 66\n47 47\n62 62\n2 2", "output": "29" }, { "input": "9 40\n72 72\n47 47\n63 63\n66 66\n21 21\n94 94\n28 28\n45 45\n93 93\n25 25\n100 100\n43 43\n49 49\n9 9\n74 74\n26 26\n42 42\n50 50\n2 2\n92 92\n76 76\n3 3\n78 78\n44 44\n69 69\n36 36\n65 65\n81 81\n13 13\n46 46\n24 24\n96 96\n73 73\n82 82\n68 68\n64 64\n41 41\n31 31\n29 29\n10 10", "output": "9" }, { "input": "50 70\n3 3\n80 80\n23 23\n11 11\n87 87\n7 7\n63 63\n61 61\n67 67\n53 53\n9 9\n43 43\n55 55\n27 27\n5 5\n1 1\n99 99\n65 65\n37 37\n60 60\n32 32\n38 38\n81 81\n2 2\n34 34\n17 17\n82 82\n26 26\n71 71\n4 4\n16 16\n19 19\n39 39\n51 51\n6 6\n49 49\n64 64\n83 83\n10 10\n56 56\n30 30\n76 76\n90 90\n42 42\n47 47\n91 91\n21 21\n52 52\n40 40\n77 77\n35 35\n88 88\n75 75\n95 95\n28 28\n15 15\n69 69\n22 22\n48 48\n66 66\n31 31\n98 98\n73 73\n25 25\n97 97\n18 18\n13 13\n54 54\n72 72\n29 29", "output": "50" }, { "input": "6 0", "output": "-1" }, { "input": "32 1\n9 5", "output": "16" }, { "input": "73 2\n17 9\n21 11", "output": "37" }, { "input": "6 3\n48 24\n51 26\n62 31", "output": "3" }, { "input": "43 4\n82 41\n52 26\n88 44\n41 21", "output": "22" }, { "input": "28 40\n85 43\n19 10\n71 36\n39 20\n57 29\n6 3\n15 8\n11 6\n99 50\n77 39\n79 40\n31 16\n35 18\n24 12\n54 27\n93 47\n90 45\n72 36\n63 32\n22 11\n83 42\n5 3\n12 6\n56 28\n94 47\n25 13\n41 21\n29 15\n36 18\n23 12\n1 1\n84 42\n55 28\n58 29\n9 5\n68 34\n86 43\n3 2\n48 24\n98 49", "output": "14" }, { "input": "81 70\n55 28\n85 43\n58 29\n20 10\n4 2\n47 24\n42 21\n28 14\n26 13\n38 19\n9 5\n83 42\n7 4\n72 36\n18 9\n61 31\n41 21\n64 32\n90 45\n46 23\n67 34\n2 1\n6 3\n27 14\n87 44\n39 20\n11 6\n21 11\n35 18\n48 24\n44 22\n3 2\n71 36\n62 31\n34 17\n16 8\n99 50\n57 29\n13 7\n79 40\n100 50\n53 27\n89 45\n36 18\n43 22\n92 46\n98 49\n75 38\n40 20\n97 49\n37 19\n68 34\n30 15\n96 48\n17 9\n12 6\n45 23\n65 33\n76 38\n84 42\n23 12\n91 46\n52 26\n8 4\n32 16\n77 39\n88 44\n86 43\n70 35\n51 26", "output": "41" }, { "input": "34 0", "output": "-1" }, { "input": "63 1\n94 24", "output": "16" }, { "input": "4 2\n38 10\n48 12", "output": "1" }, { "input": "37 3\n66 17\n89 23\n60 15", "output": "10" }, { "input": "71 4\n15 4\n13 4\n4 1\n70 18", "output": "18" }, { "input": "77 40\n49 13\n66 17\n73 19\n15 4\n36 9\n1 1\n41 11\n91 23\n51 13\n46 12\n39 10\n42 11\n56 14\n61 16\n70 18\n92 23\n65 17\n54 14\n97 25\n8 2\n87 22\n33 9\n28 7\n38 10\n50 13\n26 7\n7 2\n31 8\n84 21\n47 12\n27 7\n53 14\n19 5\n93 24\n29 8\n3 1\n77 20\n62 16\n9 3\n44 11", "output": "20" }, { "input": "18 70\n51 13\n55 14\n12 3\n43 11\n42 11\n95 24\n96 24\n29 8\n65 17\n71 18\n18 5\n62 16\n31 8\n100 25\n4 1\n77 20\n56 14\n24 6\n93 24\n97 25\n79 20\n40 10\n49 13\n86 22\n21 6\n46 12\n6 2\n14 4\n23 6\n20 5\n52 13\n88 22\n39 10\n70 18\n94 24\n13 4\n37 10\n41 11\n91 23\n85 22\n83 21\n89 23\n33 9\n64 16\n67 17\n57 15\n47 12\n36 9\n72 18\n81 21\n76 19\n35 9\n80 20\n34 9\n5 2\n22 6\n84 21\n63 16\n74 19\n90 23\n68 17\n98 25\n87 22\n2 1\n92 23\n50 13\n38 10\n28 7\n8 2\n60 15", "output": "5" }, { "input": "89 0", "output": "-1" }, { "input": "30 1\n3 1", "output": "-1" }, { "input": "63 2\n48 6\n17 3", "output": "8" }, { "input": "96 3\n45 6\n25 4\n35 5", "output": "12" }, { "input": "37 4\n2 1\n29 4\n27 4\n47 6", "output": "5" }, { "input": "64 40\n40 5\n92 12\n23 3\n75 10\n71 9\n2 1\n54 7\n18 3\n9 2\n74 10\n87 11\n11 2\n90 12\n30 4\n48 6\n12 2\n91 12\n60 8\n35 5\n13 2\n53 7\n46 6\n38 5\n59 8\n97 13\n32 4\n6 1\n36 5\n43 6\n83 11\n81 11\n99 13\n69 9\n10 2\n21 3\n78 10\n31 4\n27 4\n57 8\n1 1", "output": "8" }, { "input": "17 70\n63 8\n26 4\n68 9\n30 4\n61 8\n84 11\n39 5\n53 7\n4 1\n81 11\n50 7\n91 12\n59 8\n90 12\n20 3\n21 3\n83 11\n94 12\n37 5\n8 1\n49 7\n34 5\n19 3\n44 6\n74 10\n2 1\n73 10\n88 11\n43 6\n36 5\n57 8\n64 8\n76 10\n40 5\n71 9\n95 12\n15 2\n41 6\n89 12\n42 6\n96 12\n1 1\n52 7\n38 5\n45 6\n78 10\n82 11\n16 2\n48 6\n51 7\n56 7\n28 4\n87 11\n93 12\n46 6\n29 4\n97 13\n54 7\n35 5\n3 1\n79 10\n99 13\n13 2\n55 7\n100 13\n11 2\n75 10\n24 3\n33 5\n22 3", "output": "3" }, { "input": "9 0", "output": "-1" }, { "input": "50 1\n31 2", "output": "-1" }, { "input": "79 2\n11 1\n22 2", "output": "-1" }, { "input": "16 3\n100 7\n94 6\n3 1", "output": "1" }, { "input": "58 4\n73 5\n52 4\n69 5\n3 1", "output": "4" }, { "input": "25 40\n70 5\n28 2\n60 4\n54 4\n33 3\n21 2\n51 4\n20 2\n44 3\n79 5\n65 5\n1 1\n52 4\n23 2\n38 3\n92 6\n63 4\n3 1\n91 6\n5 1\n64 4\n34 3\n25 2\n97 7\n89 6\n61 4\n71 5\n88 6\n29 2\n56 4\n45 3\n6 1\n53 4\n57 4\n90 6\n76 5\n8 1\n46 3\n73 5\n87 6", "output": "2" }, { "input": "78 70\n89 6\n52 4\n87 6\n99 7\n3 1\n25 2\n46 3\n78 5\n35 3\n68 5\n85 6\n23 2\n60 4\n88 6\n17 2\n8 1\n15 1\n67 5\n95 6\n59 4\n94 6\n31 2\n4 1\n16 1\n10 1\n97 7\n42 3\n2 1\n24 2\n34 3\n37 3\n70 5\n18 2\n41 3\n48 3\n58 4\n20 2\n38 3\n72 5\n50 4\n49 4\n40 3\n61 4\n6 1\n45 3\n28 2\n13 1\n27 2\n96 6\n56 4\n91 6\n77 5\n12 1\n11 1\n53 4\n76 5\n74 5\n82 6\n55 4\n80 5\n14 1\n44 3\n7 1\n83 6\n79 5\n92 6\n66 5\n36 3\n73 5\n100 7", "output": "5" }, { "input": "95 0", "output": "-1" }, { "input": "33 1\n30 1", "output": "-1" }, { "input": "62 2\n14 1\n15 1", "output": "-1" }, { "input": "3 3\n6 1\n25 1\n38 2", "output": "1" }, { "input": "44 4\n72 3\n80 3\n15 1\n36 2", "output": "2" }, { "input": "34 40\n25 1\n28 1\n78 3\n5 1\n13 1\n75 3\n15 1\n67 3\n57 2\n23 1\n26 1\n61 2\n22 1\n48 2\n85 3\n24 1\n82 3\n83 3\n53 2\n38 2\n19 1\n33 2\n69 3\n17 1\n79 3\n54 2\n77 3\n97 4\n20 1\n35 2\n14 1\n18 1\n71 3\n21 1\n36 2\n56 2\n44 2\n63 2\n72 3\n32 1", "output": "2" }, { "input": "83 70\n79 3\n49 2\n2 1\n44 2\n38 2\n77 3\n86 3\n31 1\n83 3\n82 3\n35 2\n7 1\n78 3\n23 1\n39 2\n58 2\n1 1\n87 3\n72 3\n20 1\n48 2\n14 1\n13 1\n6 1\n70 3\n55 2\n52 2\n25 1\n11 1\n61 2\n76 3\n95 3\n32 1\n66 3\n29 1\n9 1\n5 1\n3 1\n88 3\n59 2\n96 3\n10 1\n63 2\n40 2\n42 2\n34 2\n43 2\n19 1\n89 3\n94 3\n24 1\n98 4\n12 1\n30 1\n69 3\n17 1\n50 2\n8 1\n93 3\n16 1\n97 4\n54 2\n71 3\n18 1\n33 2\n80 3\n15 1\n99 4\n75 3\n4 1", "output": "3" }, { "input": "2 0", "output": "-1" }, { "input": "36 1\n96 1", "output": "1" }, { "input": "73 2\n34 1\n4 1", "output": "-1" }, { "input": "6 3\n37 1\n22 1\n70 1", "output": "1" }, { "input": "47 4\n66 1\n57 1\n85 1\n47 1", "output": "1" }, { "input": "9 40\n73 1\n21 1\n37 1\n87 1\n33 1\n69 1\n49 1\n19 1\n35 1\n93 1\n71 1\n43 1\n79 1\n85 1\n29 1\n72 1\n76 1\n47 1\n17 1\n67 1\n95 1\n41 1\n54 1\n88 1\n42 1\n80 1\n98 1\n96 1\n10 1\n24 1\n78 1\n18 1\n3 1\n91 1\n2 1\n15 1\n5 1\n60 1\n36 1\n46 1", "output": "1" }, { "input": "63 70\n82 1\n53 1\n57 1\n46 1\n97 1\n19 1\n36 1\n90 1\n23 1\n88 1\n68 1\n45 1\n2 1\n70 1\n86 1\n8 1\n83 1\n40 1\n99 1\n42 1\n32 1\n52 1\n81 1\n50 1\n77 1\n37 1\n54 1\n75 1\n4 1\n49 1\n73 1\n22 1\n21 1\n98 1\n18 1\n51 1\n14 1\n76 1\n92 1\n80 1\n78 1\n33 1\n79 1\n89 1\n67 1\n9 1\n44 1\n60 1\n64 1\n55 1\n29 1\n100 1\n16 1\n87 1\n10 1\n12 1\n25 1\n85 1\n30 1\n63 1\n39 1\n38 1\n31 1\n5 1\n26 1\n91 1\n43 1\n72 1\n48 1\n94 1", "output": "1" }, { "input": "2 0", "output": "-1" } ]
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": "10\n01", "output": "11" }, { "input": "00111111\n11011101", "output": "11100010" }, { "input": "011001100\n101001010", "output": "110000110" }, { "input": "1100100001\n0110101100", "output": "1010001101" }, { "input": "00011101010\n10010100101", "output": "10001001111" }, { "input": "100000101101\n111010100011", "output": "011010001110" }, { "input": "1000001111010\n1101100110001", "output": "0101101001011" }, { "input": "01011111010111\n10001110111010", "output": "11010001101101" }, { "input": "110010000111100\n001100101011010", "output": "111110101100110" }, { "input": "0010010111110000\n0000000011010110", "output": "0010010100100110" }, { "input": "00111110111110000\n01111100001100000", "output": "01000010110010000" }, { "input": "101010101111010001\n001001111101111101", "output": "100011010010101100" }, { "input": "0110010101111100000\n0011000101000000110", "output": "0101010000111100110" }, { "input": "11110100011101010111\n00001000011011000000", "output": "11111100000110010111" }, { "input": "101010101111101101001\n111010010010000011111", "output": "010000111101101110110" }, { "input": "0000111111100011000010\n1110110110110000001010", "output": "1110001001010011001000" }, { "input": "10010010101000110111000\n00101110100110111000111", "output": "10111100001110001111111" }, { "input": "010010010010111100000111\n100100111111100011001110", "output": "110110101101011111001001" }, { "input": "0101110100100111011010010\n0101100011010111001010001", "output": "0000010111110000010000011" }, { "input": "10010010100011110111111011\n10000110101100000001000100", "output": "00010100001111110110111111" }, { "input": "000001111000000100001000000\n011100111101111001110110001", "output": "011101000101111101111110001" }, { "input": "0011110010001001011001011100\n0000101101000011101011001010", "output": "0011011111001010110010010110" }, { "input": "11111000000000010011001101111\n11101110011001010100010000000", "output": "00010110011001000111011101111" }, { "input": "011001110000110100001100101100\n001010000011110000001000101001", "output": "010011110011000100000100000101" }, { "input": "1011111010001100011010110101111\n1011001110010000000101100010101", "output": "0000110100011100011111010111010" }, { "input": "10111000100001000001010110000001\n10111000001100101011011001011000", "output": "00000000101101101010001111011001" }, { "input": "000001010000100001000000011011100\n111111111001010100100001100000111", "output": "111110101001110101100001111011011" }, { "input": "1101000000000010011011101100000110\n1110000001100010011010000011011110", "output": "0011000001100000000001101111011000" }, { "input": "01011011000010100001100100011110001\n01011010111000001010010100001110000", "output": "00000001111010101011110000010000001" }, { "input": "000011111000011001000110111100000100\n011011000110000111101011100111000111", "output": "011000111110011110101101011011000011" }, { "input": "1001000010101110001000000011111110010\n0010001011010111000011101001010110000", "output": "1011001001111001001011101010101000010" }, { "input": "00011101011001100101111111000000010101\n10010011011011001011111000000011101011", "output": "10001110000010101110000111000011111110" }, { "input": "111011100110001001101111110010111001010\n111111101101111001110010000101101000100", "output": "000100001011110000011101110111010001110" }, { "input": "1111001001101000001000000010010101001010\n0010111100111110001011000010111110111001", "output": "1101110101010110000011000000101011110011" }, { "input": "00100101111000000101011111110010100011010\n11101110001010010101001000111110101010100", "output": "11001011110010010000010111001100001001110" }, { "input": "101011001110110100101001000111010101101111\n100111100110101011010100111100111111010110", "output": "001100101000011111111101111011101010111001" }, { "input": "1111100001100101000111101001001010011100001\n1000110011000011110010001011001110001000001", "output": "0111010010100110110101100010000100010100000" }, { "input": "01100111011111010101000001101110000001110101\n10011001011111110000000101011001001101101100", "output": "11111110000000100101000100110111001100011001" }, { "input": "110010100111000100100101100000011100000011001\n011001111011100110000110111001110110100111011", "output": "101011011100100010100011011001101010100100010" }, { "input": "0001100111111011010110100100111000000111000110\n1100101011000000000001010010010111001100110001", "output": "1101001100111011010111110110101111001011110111" }, { "input": "00000101110110110001110010100001110100000100000\n10010000110011110001101000111111101010011010001", "output": "10010101000101000000011010011110011110011110001" }, { "input": "110000100101011100100011001111110011111110010001\n101011111001011100110110111101110011010110101100", "output": "011011011100000000010101110010000000101000111101" }, { "input": "0101111101011111010101011101000011101100000000111\n0000101010110110001110101011011110111001010100100", "output": "0101010111101001011011110110011101010101010100011" }, { "input": "11000100010101110011101000011111001010110111111100\n00001111000111001011111110000010101110111001000011", "output": "11001011010010111000010110011101100100001110111111" }, { "input": "101000001101111101101111111000001110110010101101010\n010011100111100001100000010001100101000000111011011", "output": "111011101010011100001111101001101011110010010110001" }, { "input": "0011111110010001010100010110111000110011001101010100\n0111000000100010101010000100101000000100101000111001", "output": "0100111110110011111110010010010000110111100101101101" }, { "input": "11101010000110000011011010000001111101000111011111100\n10110011110001010100010110010010101001010111100100100", "output": "01011001110111010111001100010011010100010000111011000" }, { "input": "011000100001000001101000010110100110011110100111111011\n111011001000001001110011001111011110111110110011011111", "output": "100011101001001000011011011001111000100000010100100100" }, { "input": "0111010110010100000110111011010110100000000111110110000\n1011100100010001101100000100111111101001110010000100110", "output": "1100110010000101101010111111101001001001110101110010110" }, { "input": "10101000100111000111010001011011011011110100110101100011\n11101111000000001100100011111000100100000110011001101110", "output": "01000111100111001011110010100011111111110010101100001101" }, { "input": "000000111001010001000000110001001011100010011101010011011\n110001101000010010000101000100001111101001100100001010010", "output": "110001010001000011000101110101000100001011111001011001001" }, { "input": "0101011100111010000111110010101101111111000000111100011100\n1011111110000010101110111001000011100000100111111111000111", "output": "1110100010111000101001001011101110011111100111000011011011" }, { "input": "11001000001100100111100111100100101011000101001111001001101\n10111110100010000011010100110100100011101001100000001110110", "output": "01110110101110100100110011010000001000101100101111000111011" }, { "input": "010111011011101000000110000110100110001110100001110110111011\n101011110011101011101101011111010100100001100111100100111011", "output": "111100101000000011101011011001110010101111000110010010000000" }, { "input": "1001011110110110000100011001010110000100011010010111010101110\n1101111100001000010111110011010101111010010100000001000010111", "output": "0100100010111110010011101010000011111110001110010110010111001" }, { "input": "10000010101111100111110101111000010100110111101101111111111010\n10110110101100101010011001011010100110111011101100011001100111", "output": "00110100000011001101101100100010110010001100000001100110011101" }, { "input": "011111010011111000001010101001101001000010100010111110010100001\n011111001011000011111001000001111001010110001010111101000010011", "output": "000000011000111011110011101000010000010100101000000011010110010" }, { "input": "1111000000110001011101000100100100001111011100001111001100011111\n1101100110000101100001100000001001011011111011010101000101001010", "output": "0010100110110100111100100100101101010100100111011010001001010101" }, { "input": "01100000101010010011001110100110110010000110010011011001100100011\n10110110010110111100100111000111000110010000000101101110000010111", "output": "11010110111100101111101001100001110100010110010110110111100110100" }, { "input": "001111111010000100001100001010011001111110011110010111110001100111\n110000101001011000100010101100100110000111100000001101001110010111", "output": "111111010011011100101110100110111111111001111110011010111111110000" }, { "input": "1011101011101101011110101101011101011000010011100101010101000100110\n0001000001001111010111100100111101100000000001110001000110000000110", "output": "1010101010100010001001001001100000111000010010010100010011000100000" }, { "input": "01000001011001010011011100010000100100110101111011011011110000001110\n01011110000110011011000000000011000111100001010000000011111001110000", "output": "00011111011111001000011100010011100011010100101011011000001001111110" }, { "input": "110101010100110101000001111110110100010010000100111110010100110011100\n111010010111111011100110101011001011001110110111110100000110110100111", "output": "001111000011001110100111010101111111011100110011001010010010000111011" }, { "input": "1001101011000001011111100110010010000011010001001111011100010100110001\n1111100111110101001111010001010000011001001001010110001111000000100101", "output": "0110001100110100010000110111000010011010011000011001010011010100010100" }, { "input": "00000111110010110001110110001010010101000111011001111111100110011110010\n00010111110100000100110101000010010001100001100011100000001100010100010", "output": "00010000000110110101000011001000000100100110111010011111101010001010000" }, { "input": "100101011100101101000011010001011001101110101110001100010001010111001110\n100001111100101011011111110000001111000111001011111110000010101110111001", "output": "000100100000000110011100100001010110101001100101110010010011111001110111" }, { "input": "1101100001000111001101001011101000111000011110000001001101101001111011010\n0101011101010100011011010110101000010010110010011110101100000110110001000", "output": "1000111100010011010110011101000000101010101100011111100001101111001010010" }, { "input": "01101101010011110101100001110101111011100010000010001101111000011110111111\n00101111001101001100111010000101110000100101101111100111101110010100011011", "output": "01000010011110111001011011110000001011000111101101101010010110001010100100" }, { "input": "101100101100011001101111110110110010100110110010100001110010110011001101011\n000001011010101011110011111101001110000111000010001101000010010000010001101", "output": "101101110110110010011100001011111100100001110000101100110000100011011100110" }, { "input": "0010001011001010001100000010010011110110011000100000000100110000101111001110\n1100110100111000110100001110111001011101001100001010100001010011100110110001", "output": "1110111111110010111000001100101010101011010100101010100101100011001001111111" }, { "input": "00101101010000000101011001101011001100010001100000101011101110000001111001000\n10010110010111000000101101000011101011001010000011011101101011010000000011111", "output": "10111011000111000101110100101000100111011011100011110110000101010001111010111" }, { "input": "111100000100100000101001100001001111001010001000001000000111010000010101101011\n001000100010100101111011111011010110101100001111011000010011011011100010010110", "output": "110100100110000101010010011010011001100110000111010000010100001011110111111101" }, { "input": "0110001101100100001111110101101000100101010010101010011001101001001101110000000\n0111011000000010010111011110010000000001000110001000011001101000000001110100111", "output": "0001010101100110011000101011111000100100010100100010000000000001001100000100111" }, { "input": "10001111111001000101001011110101111010100001011010101100111001010001010010001000\n10000111010010011110111000111010101100000011110001101111001000111010100000000001", "output": "00001000101011011011110011001111010110100010101011000011110001101011110010001001" }, { "input": "100110001110110000100101001110000011110110000110000000100011110100110110011001101\n110001110101110000000100101001101011111100100100001001000110000001111100011110110", "output": "010111111011000000100001100111101000001010100010001001100101110101001010000111011" }, { "input": "0000010100100000010110111100011111111010011101000000100000011001001101101100111010\n0100111110011101010110101011110110010111001111000110101100101110111100101000111111", "output": "0100101010111101000000010111101001101101010010000110001100110111110001000100000101" }, { "input": "11000111001010100001110000001001011010010010110000001110100101000001010101100110111\n11001100100100100001101010110100000111100011101110011010110100001001000011011011010", "output": "00001011101110000000011010111101011101110001011110010100010001001000010110111101101" }, { "input": "010110100010001000100010101001101010011010111110100001000100101000111011100010100001\n110000011111101101010011111000101010111010100001001100001001100101000000111000000000", "output": "100110111101100101110001010001000000100000011111101101001101001101111011011010100001" }, { "input": "0000011110101110010101110110110101100001011001101010101001000010000010000000101001101\n1100111111011100000110000111101110011111100111110001011001000010011111100001001100011", "output": "1100100001110010010011110001011011111110111110011011110000000000011101100001100101110" }, { "input": "10100000101101110001100010010010100101100011010010101000110011100000101010110010000000\n10001110011011010010111011011101101111000111110000111000011010010101001100000001010011", "output": "00101110110110100011011001001111001010100100100010010000101001110101100110110011010011" }, { "input": "001110000011111101101010011111000101010111010100001001100001001100101000000111000000000\n111010000000000000101001110011001000111011001100101010011001000011101001001011110000011", "output": "110100000011111101000011101100001101101100011000100011111000001111000001001100110000011" }, { "input": "1110111100111011010101011011001110001010010010110011110010011111000010011111010101100001\n1001010101011001001010100010101100000110111101011000100010101111111010111100001110010010", "output": "0111101001100010011111111001100010001100101111101011010000110000111000100011011011110011" }, { "input": "11100010001100010011001100001100010011010001101110011110100101110010101101011101000111111\n01110000000110111010110100001010000101011110100101010011000110101110101101110111011110001", "output": "10010010001010101001111000000110010110001111001011001101100011011100000000101010011001110" }, { "input": "001101011001100101101100110000111000101011001001100100000100101000100000110100010111111101\n101001111110000010111101111110001001111001111101111010000110111000100100110010010001011111", "output": "100100100111100111010001001110110001010010110100011110000010010000000100000110000110100010" }, { "input": "1010110110010101000110010010110101011101010100011001101011000110000000100011100100011000000\n0011011111100010001111101101000111001011101110100000110111100100101111010110101111011100011", "output": "1001101001110111001001111111110010010110111010111001011100100010101111110101001011000100011" }, { "input": "10010010000111010111011111110010100101100000001100011100111011100010000010010001011100001100\n00111010100010110010000100010111010001111110100100100011101000101111111111001101101100100100", "output": "10101000100101100101011011100101110100011110101000111111010011001101111101011100110000101000" }, { "input": "010101110001010101100000010111010000000111110011001101100011001000000011001111110000000010100\n010010111011100101010101111110110000000111000100001101101001001000001100101110001010000100001", "output": "000111001010110000110101101001100000000000110111000000001010000000001111100001111010000110101" }, { "input": "1100111110011001000111101001001011000110011010111111100010111111001100111111011101100111101011\n1100000011001000110100110111000001011001010111101000010010100011000001100100111101101000010110", "output": "0000111101010001110011011110001010011111001101010111110000011100001101011011100000001111111101" }, { "input": "00011000100100110111100101100100000000010011110111110010101110110011100001010111010011110100101\n00011011111011111011100101100111100101001110010111000010000111000100100100000001110101111011011", "output": "00000011011111001100000000000011100101011101100000110000101001110111000101010110100110001111110" }, { "input": "000101011001001100000111100010110101111011110101111101000110001101011010111110110011100100000001\n011000101010011111011000111000100000000011011000000001111110001000001111101010110000011100001111", "output": "011101110011010011011111011010010101111000101101111100111000000101010101010100000011111000001110" }, { "input": "1000101001011010000100100100010010011101011001110101111011101111111110010101001101010001010101001\n0110110010011100011111011111110111000000010001110100001010111110101011010011111011111110000110000", "output": "1110011011000110011011111011100101011101001000000001110001010001010101000110110110101111010011001" }, { "input": "01111010010101100111110111111011011010100001011101010000111100101101101110111011001100101011100111\n00001100110110100001111011000010001001001100000010111101000001111011100000010111010010000011000010", "output": "01110110100011000110001100111001010011101101011111101101111101010110001110101100011110101000100101" }, { "input": "111101011101111000001011001101111010110111001101110100100011111011011101001101010101011010111000110\n101111100101101101001100110011000001111010011101110111110110101110011011110011111100001001110101101", "output": "010010111000010101000111111110111011001101010000000011010101010101000110111110101001010011001101011" }, { "input": "1010000011010110011101001101110001110010000111011101110010110110111111001001110100101100010101010001\n0111101000111100101100000101111010100100001000011101010100110011100011010011010101000100101011100011", "output": "1101101011101010110001001000001011010110001111000000100110000101011100011010100001101000111110110010" }, { "input": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001\n1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111010", "output": "1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111011" }, { "input": "0\n0", "output": "0" }, { "input": "0\n1", "output": "1" } ]
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" }, { "input": "3\n0 1 1", "output": "YES" }, { "input": "3\n0 1 0", "output": "NO" }, { "input": "2\n0 1", "output": "YES" }, { "input": "2\n1 0", "output": "YES" }, { "input": "2\n0 0", "output": "NO" }, { "input": "2\n1 1", "output": "NO" }, { "input": "1\n1", "output": "YES" }, { "input": "1\n0", "output": "NO" }, { "input": "10\n1 0 1 1 1 1 1 1 1 1", "output": "YES" }, { "input": "5\n1 1 1 1 0", "output": "YES" }, { "input": "4\n1 0 1 0", "output": "NO" }, { "input": "4\n1 1 0 0", "output": "NO" }, { "input": "10\n0 0 1 1 1 1 1 1 1 1", "output": "NO" }, { "input": "10\n1 1 1 1 1 1 1 1 1 1", "output": "NO" }, { "input": "123\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 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 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 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 1 1 1 1 1 1", "output": "NO" }, { "input": "124\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 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 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 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 1 1 1 1 1 1 1", "output": "NO" }, { "input": "94\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 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 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 1 1 1 1 1 1", "output": "NO" }, { "input": "64\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 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 1 1 1 1 1", "output": "NO" }, { "input": "34\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 1 1 1 1", "output": "NO" }, { "input": "35\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 1 1 1 1 1", "output": "NO" }, { "input": "5\n1 1 1 1 1", "output": "NO" }, { "input": "10\n0 0 0 0 0 0 0 0 0 0", "output": "NO" }, { "input": "231\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "NO" }, { "input": "10\n1 1 0 1 1 1 0 1 1 1", "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\n0010001010\n0011011010\n0100001110\n0010100000\n0000100011\n0100000001\n0000010100\n1000000010\n0000010000\n0110010000\n1 1 4 6\n2 6 3 10\n1 6 3 9\n6 5 8 5\n2 3 6 8\n4 7 5 8\n3 1 9 5\n2 5 4 10\n2 3 3 6\n7 4 9 5", "output": "42\n5\n5\n6\n79\n9\n151\n27\n12\n18" }, { "input": "10 10 10\n0001000111\n1101000111\n1100101111\n1011101011\n1011110101\n1110101110\n1101101111\n1111111100\n0110101110\n1011101011\n6 3 7 9\n2 6 8 7\n9 7 10 8\n3 1 5 9\n1 6 9 10\n6 3 8 8\n1 6 9 10\n5 6 8 10\n8 8 10 8\n9 6 9 10", "output": "5\n12\n1\n12\n29\n5\n29\n9\n1\n2" }, { "input": "3 2 8\n01\n00\n00\n3 2 3 2\n1 1 2 1\n2 1 3 1\n2 2 3 2\n1 1 2 2\n1 1 1 2\n1 1 3 1\n1 1 2 2", "output": "1\n3\n3\n3\n5\n1\n6\n5" }, { "input": "2 3 8\n000\n001\n1 1 2 2\n1 3 2 3\n2 2 2 3\n1 1 2 2\n2 3 2 3\n2 1 2 2\n1 2 1 3\n1 2 2 2", "output": "9\n1\n1\n9\n0\n3\n3\n3" } ]
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" }, { "input": "2 1\n1 2", "output": "-1" }, { "input": "2 0", "output": "-1" }, { "input": "20 0", "output": "-1" }, { "input": "381 0", "output": "-1" }, { "input": "3 3\n1 2\n2 3\n3 1", "output": "-1" }, { "input": "3 0", "output": "-1" }, { "input": "3 1\n1 3", "output": "2" }, { "input": "3 2\n2 3\n3 1", "output": "-1" }, { "input": "4 1\n1 4", "output": "2" }, { "input": "4 5\n1 3\n2 1\n3 4\n4 2\n2 3", "output": "2" }, { "input": "20 1\n20 1", "output": "2" }, { "input": "21 1\n21 1", "output": "2" }, { "input": "100 1\n100 1", "output": "2" }, { "input": "400 1\n1 400", "output": "2" }, { "input": "5 5\n2 5\n1 2\n1 4\n1 3\n3 2", "output": "2" } ]
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" }, { "input": "1 5\n5 1 1 1 1 5", "output": "NO" }, { "input": "2 5\n4 3 1 4 2\n4 2 3 4 5", "output": "YES" }, { "input": "5 7\n2 6 7\n5 1 1 1 1 1\n3 6 5 4\n0\n4 4 3 2 1", "output": "YES" }, { "input": "100 100\n0\n0\n0\n1 53\n0\n0\n1 34\n1 54\n0\n1 14\n0\n1 33\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n1 82\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n1 34\n0\n0\n1 26\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n1 34\n0\n0\n0\n0\n0\n1 3\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n1 40\n0\n0\n0\n1 26\n0\n0\n0\n0\n0\n1 97\n0\n1 5\n0\n0\n0\n0\n0", "output": "NO" }, { "input": "100 100\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0", "output": "NO" }, { "input": "5 6\n3 1 2 6\n3 1 2 6\n1 1\n2 3 4\n3 1 5 6", "output": "YES" }, { "input": "5 2\n1 1\n1 1\n1 1\n1 1\n1 1", "output": "NO" }, { "input": "1 4\n3 1 2 3", "output": "NO" }, { "input": "1 4\n3 2 3 4", "output": "NO" }, { "input": "2 4\n3 2 3 4\n1 1", "output": "YES" }, { "input": "2 4\n3 1 2 3\n1 4", "output": "YES" }, { "input": "5 1\n0\n0\n0\n0\n0", "output": "NO" }, { "input": "1 1\n0", "output": "NO" }, { "input": "1 10\n10 1 2 3 4 5 6 7 8 9 10", "output": "YES" }, { "input": "1 1\n1 1", "output": "YES" }, { "input": "1 100\n99 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99", "output": "NO" }, { "input": "1 3\n3 1 2 1", "output": "NO" }, { "input": "1 100\n100 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100", "output": "YES" } ]
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\n1 1 1 1 2 1 1 1 1", "output": "8" }, { "input": "12 3\n1 2 3 1 2 3 1 2 3 1 2 3", "output": "48" }, { "input": "100 3\n2 1 1 1 3 2 3 3 2 3 3 1 3 3 1 3 3 1 1 1 2 3 1 2 3 1 2 3 3 1 3 1 1 2 3 2 3 3 2 3 3 1 2 2 1 2 3 2 3 2 2 1 1 3 1 3 2 1 3 1 3 1 3 1 1 3 3 3 2 3 2 2 2 2 1 3 3 3 1 2 1 2 3 2 1 3 1 3 2 1 3 1 2 1 2 3 1 3 2 3", "output": "3296" }, { "input": "100 5\n5 5 2 4 5 4 4 4 4 2 5 3 4 2 4 4 1 1 5 3 2 2 1 3 3 2 5 3 4 5 1 3 5 4 4 4 3 1 4 4 3 4 5 2 5 4 2 1 2 2 3 5 5 5 1 4 5 3 1 4 2 2 5 1 5 3 4 1 5 1 2 2 3 5 1 3 2 4 2 4 2 2 4 1 3 5 2 2 2 3 3 4 3 2 2 5 5 4 2 5", "output": "3953" }, { "input": "100 10\n7 4 5 5 10 10 5 8 5 7 4 5 4 6 8 8 2 6 3 3 10 7 10 8 6 2 7 3 9 7 7 2 4 5 2 4 9 5 10 1 10 5 10 4 1 3 4 2 6 9 9 9 10 6 2 5 6 1 8 10 4 10 3 4 10 5 5 4 10 4 5 3 7 10 2 7 3 6 9 6 1 6 5 5 4 6 6 4 4 1 5 1 6 6 6 8 8 6 2 6", "output": "4428" } ]
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": "240" }, { "input": "47", "output": "70368744177664" }, { "input": "59", "output": "288230376151711744" }, { "input": "100", "output": "45360" }, { "input": "159", "output": "40532396646334464" }, { "input": "265", "output": "364791569817010176" }, { "input": "312", "output": "14192640" }, { "input": "473", "output": "259700248434180096" }, { "input": "637", "output": "46656000000" }, { "input": "500", "output": "62370000" }, { "input": "720", "output": "61261200" }, { "input": "902", "output": "324625310542725120" }, { "input": "940", "output": "199495389743677440" }, { "input": "1000", "output": "810810000" }, { "input": "999", "output": "757632231014400" }, { "input": "118", "output": "864691128455135232" } ]
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", "output": "0" }, { "input": "5\n984181411 215198610 969039668 60631313 85746445", "output": "778956192" }, { "input": "10\n12528139 986722043 1595702 997595062 997565216 997677838 999394520 999593240 772077 998195916", "output": "1982580029" }, { "input": "100\n9997 9615 4045 2846 7656 2941 2233 9214 837 2369 5832 578 6146 8773 164 7303 3260 8684 2511 6608 9061 9224 7263 7279 1361 1823 8075 5946 2236 6529 6783 7494 510 1217 1135 8745 6517 182 8180 2675 6827 6091 2730 897 1254 471 1990 1806 1706 2571 8355 5542 5536 1527 886 2093 1532 4868 2348 7387 5218 3181 3140 3237 4084 9026 504 6460 9256 6305 8827 840 2315 5763 8263 5068 7316 9033 7552 9939 8659 6394 4566 3595 2947 2434 1790 2673 6291 6736 8549 4102 953 8396 8985 1053 5906 6579 5854 6805", "output": "478217" } ]
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" }, { "input": "999", "output": "2889" }, { "input": "55", "output": "101" }, { "input": "222222222", "output": "1888888896" }, { "input": "8", "output": "8" }, { "input": "13", "output": "17" }, { "input": "313", "output": "831" }, { "input": "1342", "output": "4261" }, { "input": "30140", "output": "139594" }, { "input": "290092", "output": "1629447" }, { "input": "2156660", "output": "13985516" }, { "input": "96482216", "output": "760746625" }, { "input": "943006819", "output": "8375950269" }, { "input": "1", "output": "1" }, { "input": "7", "output": "7" }, { "input": "35", "output": "61" }, { "input": "996", "output": "2880" }, { "input": "6120", "output": "23373" }, { "input": "30660", "output": "142194" }, { "input": "349463", "output": "1985673" }, { "input": "8171970", "output": "56092686" }, { "input": "36123011", "output": "277872985" }, { "input": "986747865", "output": "8769619683" }, { "input": "9", "output": "9" }, { "input": "10", "output": "11" }, { "input": "11", "output": "13" }, { "input": "101", "output": "195" }, { "input": "1000", "output": "2893" }, { "input": "1001", "output": "2897" }, { "input": "9999", "output": "38889" }, { "input": "10000", "output": "38894" }, { "input": "10001", "output": "38899" }, { "input": "99999", "output": "488889" }, { "input": "100000", "output": "488895" }, { "input": "100001", "output": "488901" }, { "input": "999999", "output": "5888889" }, { "input": "1000001", "output": "5888903" }, { "input": "9999999", "output": "68888889" }, { "input": "10000000", "output": "68888897" }, { "input": "10000001", "output": "68888905" }, { "input": "99999999", "output": "788888889" }, { "input": "100000000", "output": "788888898" }, { "input": "100000001", "output": "788888907" }, { "input": "999999999", "output": "8888888889" }, { "input": "95", "output": "181" }, { "input": "995", "output": "2877" }, { "input": "9995", "output": "38873" }, { "input": "99995", "output": "488869" }, { "input": "999999995", "output": "8888888853" }, { "input": "999999998", "output": "8888888880" } ]
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": "YES" }, { "input": "ONDOL\nJNPB\nONLNJBODP", "output": "YES" }, { "input": "Y\nW\nYW", "output": "YES" }, { "input": "OI\nM\nIMO", "output": "YES" }, { "input": "VFQRWWWACX\nGHZJPOQUSXRAQDGOGMR\nOPAWDOUSGWWCGQXXQAZJRQRGHRMVF", "output": "YES" }, { "input": "JUTCN\nPIGMZOPMEUFADQBW\nNWQGZMAIPUPOMCDUB", "output": "NO" }, { "input": "Z\nO\nZOCNDOLTBZKQLTBOLDEGXRHZGTTPBJBLSJCVSVXISQZCSFDEBXRCSGBGTHWOVIXYHACAGBRYBKBJAEPIQZHVEGLYH", "output": "NO" }, { "input": "IQ\nOQ\nQOQIGGKFNHJSGCGM", "output": "NO" }, { "input": "ROUWANOPNIGTVMIITVMZ\nOQTUPZMTKUGY\nVTVNGZITGPUNPMQOOATUUIYIWMMKZOTR", "output": "YES" }, { "input": "OVQELLOGFIOLEHXMEMBJDIGBPGEYFG\nJNKFPFFIJOFHRIFHXEWYZOPDJBZTJZKBWQTECNHRFSJPJOAPQT\nYAIPFFFEXJJNEJPLREIGODEGQZVMCOBDFKWTMWJSBEBTOFFQOHIQJLHFNXIGOHEZRZLFOKJBJPTPHPGY", "output": "YES" }, { "input": "NBJGVNGUISUXQTBOBKYHQCOOVQWUXWPXBUDLXPKX\nNSFQDFUMQDQWQ\nWXKKVNTDQQFXCUQBIMQGQHSLVGWSBFYBUPOWPBDUUJUXQNOQDNXOX", "output": "YES" }, { "input": "IJHHGKCXWDBRWJUPRDBZJLNTTNWKXLUGJSBWBOAUKWRAQWGFNL\nNJMWRMBCNPHXTDQQNZ\nWDNJRCLILNQRHWBANLTXWMJBPKUPGKJDJZAQWKTZFBRCTXHHBNXRGUQUNBNMWODGSJWW", "output": "YES" }, { "input": "SRROWANGUGZHCIEFYMQVTWVOMDWPUZJFRDUMVFHYNHNTTGNXCJ\nDJYWGLBFCCECXFHOLORDGDCNRHPWXNHXFCXQCEZUHRRNAEKUIX\nWCUJDNYHNHYOPWMHLDCDYRWBVOGHFFUKOZTXJRXJHRGWICCMRNEVNEGQWTZPNFCSHDRFCFQDCXMHTLUGZAXOFNXNVGUEXIACRERU", "output": "YES" }, { "input": "H\nJKFGHMIAHNDBMFXWYQLZRSVNOTEGCQSVUBYUOZBTNKTXPFQDCMKAGFITEUGOYDFIYQIORMFJEOJDNTFVIQEBICSNGKOSNLNXJWC\nBQSVDOGIHCHXSYNYTQFCHNJGYFIXTSOQINZOKSVQJMTKNTGFNXAVTUYEONMBQMGJLEWJOFGEARIOPKFUFCEMUBRBDNIIDFZDCLWK", "output": "YES" }, { "input": "DSWNZRFVXQ\nPVULCZGOOU\nUOLVZXNUPOQRZGWFVDSCANQTCLEIE", "output": "NO" }, { "input": "EUHTSCENIPXLTSBMLFHD\nIZAVSZPDLXOAGESUSE\nLXAELAZ", "output": "NO" }, { "input": "WYSJFEREGELSKRQRXDXCGBODEFZVSI\nPEJKMGFLBFFDWRCRFSHVEFLEBTJCVCHRJTLDTISHPOGFWPLEWNYJLMXWIAOTYOXMV\nHXERTZWLEXTPIOTFRVMEJVYFFJLRPFMXDEBNSGCEOFFCWTKIDDGCFYSJKGLHBORWEPLDRXRSJYBGASSVCMHEEJFLVI", "output": "NO" }, { "input": "EPBMDIUQAAUGLBIETKOKFLMTCVEPETWJRHHYKCKU\nHGMAETVPCFZYNNKDQXVXUALHYLOTCHM\nECGXACVKEYMCEDOTMKAUFHLHOMT", "output": "NO" }, { "input": "NUBKQEJHALANSHEIFUZHYEZKKDRFHQKAJHLAOWTZIMOCWOVVDW\nEFVOBIGAUAUSQGVSNBKNOBDMINODMFSHDL\nKLAMKNTHBFFOHVKWICHBKNDDQNEISODUSDNLUSIOAVWY", "output": "NO" }, { "input": "VXINHOMEQCATZUGAJEIUIZZLPYFGUTVLNBNWCUVMEENUXKBWBGZTMRJJVJDLVSLBABVCEUDDSQFHOYPYQTWVAGTWOLKYISAGHBMC\nZMRGXPZSHOGCSAECAPGVOIGCWEOWWOJXLGYRDMPXBLOKZVRACPYQLEQGFQCVYXAGBEBELUTDAYEAGPFKXRULZCKFHZCHVCWIRGPK\nRCVUXGQVNWFGRUDLLENNDQEJHYYVWMKTLOVIPELKPWCLSQPTAXAYEMGWCBXEVAIZGGDDRBRT", "output": "NO" }, { "input": "PHBDHHWUUTZAHELGSGGOPOQXSXEZIXHZTOKYFBQLBDYWPVCNQSXHEAXRRPVHFJBVBYCJIFOTQTWSUOWXLKMVJJBNLGTVITWTCZZ\nFUPDLNVIHRWTEEEHOOEC\nLOUSUUSZCHJBPEWIILUOXEXRQNCJEGTOBRVZLTTZAHTKVEJSNGHFTAYGY", "output": "NO" }, { "input": "GDSLNIIKTO\nJF\nPDQYFKDTNOLI", "output": "NO" }, { "input": "AHOKHEKKPJLJIIWJRCGY\nORELJCSIX\nZVWPXVFWFSWOXXLIHJKPXIOKRELYE", "output": "NO" }, { "input": "ZWCOJFORBPHXCOVJIDPKVECMHVHCOC\nTEV\nJVGTBFTLFVIEPCCHODOFOMCVZHWXVCPEH", "output": "NO" }, { "input": "AGFIGYWJLVMYZGNQHEHWKJIAWBPUAQFERMCDROFN\nPMJNHMVNRGCYZAVRWNDSMLSZHFNYIUWFPUSKKIGU\nMCDVPPRXGUAYLSDRHRURZASXUWZSIIEZCPXUVEONKNGNWRYGOSFMCKESMVJZHWWUCHWDQMLASLNNMHAU", "output": "NO" }, { "input": "XLOWVFCZSSXCSYQTIIDKHNTKNKEEDFMDZKXSPVLBIDIREDUAIN\nZKIWNDGBISDB\nSLPKLYFYSRNRMOSWYLJJDGFFENPOXYLPZFTQDANKBDNZDIIEWSUTTKYBKVICLG", "output": "NO" }, { "input": "PMUKBTRKFIAYVGBKHZHUSJYSSEPEOEWPOSPJLWLOCTUYZODLTUAFCMVKGQKRRUSOMPAYOTBTFPXYAZXLOADDEJBDLYOTXJCJYTHA\nTWRRAJLCQJTKOKWCGUH\nEWDPNXVCXWCDQCOYKKSOYTFSZTOOPKPRDKFJDETKSRAJRVCPDOBWUGPYRJPUWJYWCBLKOOTUPBESTOFXZHTYLLMCAXDYAEBUTAHM", "output": "NO" }, { "input": "QMIMGQRQDMJDPNFEFXSXQMCHEJKTWCTCVZPUAYICOIRYOWKUSIWXJLHDYWSBOITHTMINXFKBKAWZTXXBJIVYCRWKXNKIYKLDDXL\nV\nFWACCXBVDOJFIUAVYRALBYJKXXWIIFORRUHKHCXLDBZMXIYJWISFEAWTIQFIZSBXMKNOCQKVKRWDNDAMQSTKYLDNYVTUCGOJXJTW", "output": "NO" }, { "input": "XJXPVOOQODELPPWUISSYVVXRJTYBPDHJNENQEVQNVFIXSESKXVYPVVHPMOSX\nLEXOPFPVPSZK\nZVXVPYEYOYXVOISVLXPOVHEQVXPNQJIOPFDTXEUNMPEPPHELNXKKWSVSOXSBPSJDPVJVSRFQ", "output": "YES" }, { "input": "OSKFHGYNQLSRFSAHPXKGPXUHXTRBJNAQRBSSWJVEENLJCDDHFXVCUNPZAIVVO\nFNUOCXAGRRHNDJAHVVLGGEZQHWARYHENBKHP\nUOEFNWVXCUNERLKVTHAGPSHKHDYFPYWZHJKHQLSNFBJHVJANRXCNSDUGVDABGHVAOVHBJZXGRACHRXEGNRPQEAPORQSILNXFS", "output": "YES" }, { "input": "VYXYVVACMLPDHONBUTQFZTRREERBLKUJYKAHZRCTRLRCLOZYWVPBRGDQPFPQIF\nFE\nRNRPEVDRLYUQFYRZBCQLCYZEABKLRXCJLKVZBVFUEYRATOMDRTHFPGOWQVTIFPPH", "output": "YES" }, { "input": "WYXUZQJQNLASEGLHPMSARWMTTQMQLVAZLGHPIZTRVTCXDXBOLNXZPOFCTEHCXBZ\nBLQZRRWP\nGIQZXPLTTMNHQVWPPEAPLOCDMBSTHRCFLCQRRZXLVAOQEGZBRUZJXXZTMAWLZHSLWNQTYXB", "output": "YES" }, { "input": "MKVJTSSTDGKPVVDPYSRJJYEVGKBMSIOKHLZQAEWLRIBINVRDAJIBCEITKDHUCCVY\nPUJJQFHOGZKTAVNUGKQUHMKTNHCCTI\nQVJKUSIGTSVYUMOMLEGHWYKSKQTGATTKBNTKCJKJPCAIRJIRMHKBIZISEGFHVUVQZBDERJCVAKDLNTHUDCHONDCVVJIYPP", "output": "YES" }, { "input": "OKNJOEYVMZXJMLVJHCSPLUCNYGTDASKSGKKCRVIDGEIBEWRVBVRVZZTLMCJLXHJIA\nDJBFVRTARTFZOWN\nAGHNVUNJVCPLWSVYBJKZSVTFGLELZASLWTIXDDJXCZDICTVIJOTMVEYOVRNMJGRKKHRMEBORAKFCZJBR", "output": "YES" }, { "input": "OQZACLPSAGYDWHFXDFYFRRXWGIEJGSXWUONAFWNFXDTGVNDEWNQPHUXUJNZWWLBPYL\nOHBKWRFDRQUAFRCMT\nWIQRYXRJQWWRUWCYXNXALKFZGXFTLOODWRDPGURFUFUQOHPWBASZNVWXNCAGHWEHFYESJNFBMNFDDAPLDGT", "output": "YES" }, { "input": "OVIRQRFQOOWVDEPLCJETWQSINIOPLTLXHSQWUYUJNFBMKDNOSHNJQQCDHZOJVPRYVSV\nMYYDQKOOYPOOUELCRIT\nNZSOTVLJTTVQLFHDQEJONEOUOFOLYVSOIYUDNOSIQVIRMVOERCLMYSHPCQKIDRDOQPCUPQBWWRYYOXJWJQPNKH", "output": "YES" }, { "input": "WGMBZWNMSJXNGDUQUJTCNXDSJJLYRDOPEGPQXYUGBESDLFTJRZDDCAAFGCOCYCQMDBWK\nYOBMOVYTUATTFGJLYUQD\nDYXVTLQCYFJUNJTUXPUYOPCBCLBWNSDUJRJGWDOJDSQAAMUOJWSYERDYDXYTMTOTMQCGQZDCGNFBALGGDFKZMEBG", "output": "YES" }, { "input": "CWLRBPMEZCXAPUUQFXCUHAQTLPBTXUUKWVXKBHKNSSJFEXLZMXGVFHHVTPYAQYTIKXJJE\nMUFOSEUEXEQTOVLGDSCWM\nJUKEQCXOXWEHCGKFPBIGMWVJLXUONFXBYTUAXERYTXKCESKLXAEHVPZMMUFTHLXTTZSDMBJLQPEUWCVUHSQQVUASPF", "output": "YES" }, { "input": "IDQRX\nWETHO\nODPDGBHVUVSSISROHQJTUKPUCLXABIZQQPPBPKOSEWGEHRSRRNBAVLYEMZISMWWGKHVTXKUGUXEFBSWOIWUHRJGMWBMHQLDZHBWA", "output": "NO" }, { "input": "IXFDY\nJRMOU\nDF", "output": "NO" }, { "input": "JPSPZ\nUGCUB\nJMZZZZZZZZ", "output": "NO" }, { "input": "AC\nA\nBBA", "output": "NO" }, { "input": "UIKWWKXLSHTOOZOVGXKYSOJEHAUEEG\nKZXQDWJJWRXFHKJDQHJK\nXMZHTFOGEXAUJXXJUYVJIFOTKLZHDKELJWERHMGAWGKWAQKEKHIDWGGZVYOHKXRPWSJDPESFJUMKQYWBYUTHQYEFZUGKQOBHYDWB", "output": "NO" }, { "input": "PXWRXRPFLR\nPJRWWXIVHODV\nXW", "output": "NO" }, { "input": "CHTAZVHGSHCVIBK\nEQINEBKXEPYJSAZIMLDF\nZCZZZZDZMCZZEZDZZEZZZZQZZBZZZOZZCZE", "output": "NO" }, { "input": "GXPZFSELJJNDAXYRV\nUYBKPMVBSOVOJWMONLTJOJCNQKMTAHEWLHOWIIBH\nHCWNFWJPEJIWOVPTBMVCRJLSISSVNOHCKLBFMIUAIMASQWPXEYXBOXQGFEMYJLBKDCZIMJNHOJEDGGANIVYKQTUOSOVOPWHVJGXH", "output": "NO" }, { "input": "LFGJCJJDUTUP\nOVSBILTIYCJCRHKCIXCETJQJJ\nGIJJTJCLTJJJ", "output": "NO" }, { "input": "GIO\nPRL\nPRL", "output": "NO" }, { "input": "A\nB\nABC", "output": "NO" }, { "input": "KKK\nKKK\nZZZZZ", "output": "NO" }, { "input": "ZMYGQLDBLAPN\nZFJBKWHROVNPSJQUDFTHOCGREUFLYIWYICD\nZMJZZEDAZANKZZZZZZEZZBZDZZZZZZKHZZFZZZDZNZMDZZA", "output": "NO" } ]
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": "4", "output": "4" }, { "input": "7421902501252475186372406731932548506197390793597574544727433297197476846519276598727359617092494798", "output": "629" }, { "input": "71057885893313745806894531138592341136175030511382512555364579061229040750815096670263802546201989828165866147027119861863385397179695224216202346062872417111920113483747119385957051753101263769591892062039112567316036455789217245754461225443096439906225767290690128677713047690686004149082311677134836383178262318973298581951974863511315252485252083010690948164456205330279738760034861583874764199950445592461479109814313530332776429627014232776723160331462731018692207739471347664936326394313671025", "output": "3144" }, { "input": "515377520732011331036461129765621272702107522001", "output": "300" }, { "input": "515377520732011331036461129765621272702107522002", "output": "301" }, { "input": "515377520732011331036461129765621272702107522000", "output": "300" }, { "input": "2644141638961613273780910519504288731930844065504296335329840736453657194693409799081556627701216123927819555393745164711901909164201237823730685450515907348055240450396641607756029548457929682548780800235177236082257895631246188876123132346108173348981012356250960688811094108794077791634930736509832272441660537127557164580456832796615775793837112808169797875218746484343692719877391033530037881176218120852179342877728205628700771297494331664021228732264346205537805710440002", "output": "3002" } ]
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" }, { "input": "4744000695826", "output": "YES" }, { "input": "10000000004744744", "output": "YES" }, { "input": "446486416781684178", "output": "YES" }, { "input": "999999999", "output": "NO" }, { "input": "7777", "output": "YES" }, { "input": "87414417444", "output": "NO" }, { "input": "111222333444555667", "output": "YES" }, { "input": "1", "output": "NO" }, { "input": "4700", "output": "NO" }, { "input": "3794555488744477", "output": "NO" }, { "input": "444444444444444444", "output": "NO" }, { "input": "474447447774444774", "output": "NO" }, { "input": "777777777777777", "output": "NO" }, { "input": "34777745021000000", "output": "NO" }, { "input": "963", "output": "NO" }, { "input": "855474448854788540", "output": "NO" }, { "input": "999999999999994744", "output": "YES" }, { "input": "400000000474", "output": "YES" }, { "input": "123456789123456789", "output": "YES" }, { "input": "740577777584945874", "output": "NO" }, { "input": "7777777", "output": "YES" }, { "input": "4444000111222333", "output": "YES" }, { "input": "9847745885202111", "output": "YES" }, { "input": "123456000000", "output": "NO" }, { "input": "4744447444444", "output": "NO" }, { "input": "7477", "output": "YES" }, { "input": "4747477", "output": "YES" }, { "input": "777777777444444444", "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" }, { "input": "7\nksjuuerbnlklcfdjeyq 312\ndthjlkrvvbyahttifpdewvyslsh -983\nksjuuerbnlklcfdjeyq 268\ndthjlkrvvbyahttifpdewvyslsh 788\nksjuuerbnlklcfdjeyq -79\nksjuuerbnlklcfdjeyq -593\nksjuuerbnlklcfdjeyq 734", "output": "ksjuuerbnlklcfdjeyq" }, { "input": "12\natrtthfpcvishmqbakprquvnejr 185\natrtthfpcvishmqbakprquvnejr -699\natrtthfpcvishmqbakprquvnejr -911\natrtthfpcvishmqbakprquvnejr -220\nfcgslzkicjrpbqaifgweyzreajjfdo 132\nfcgslzkicjrpbqaifgweyzreajjfdo -242\nm 177\nm -549\natrtthfpcvishmqbakprquvnejr -242\nm 38\natrtthfpcvishmqbakprquvnejr -761\nfcgslzkicjrpbqaifgweyzreajjfdo 879", "output": "fcgslzkicjrpbqaifgweyzreajjfdo" }, { "input": "15\naawtvezfntstrcpgbzjbf 681\nzhahpvqiptvksnbjkdvmknb -74\naawtvezfntstrcpgbzjbf 661\njpdwmyke 474\naawtvezfntstrcpgbzjbf -547\naawtvezfntstrcpgbzjbf 600\nzhahpvqiptvksnbjkdvmknb -11\njpdwmyke 711\nbjmj 652\naawtvezfntstrcpgbzjbf -1000\naawtvezfntstrcpgbzjbf -171\nbjmj -302\naawtvezfntstrcpgbzjbf 961\nzhahpvqiptvksnbjkdvmknb 848\nbjmj -735", "output": "aawtvezfntstrcpgbzjbf" }, { "input": "17\nqdplghhx -649\nivhgbxiv 424\nivhgbxiv -72\nivhgbxiv 479\nugowfouebkelargxylsxn 83\nugowfouebkelargxylsxn -840\nivhgbxiv 382\nqdplghhx -904\nivhgbxiv -710\nugowfouebkelargxylsxn -838\nqdplghhx -974\nqdplghhx 571\nivhgbxiv -145\nugowfouebkelargxylsxn -788\nivhgbxiv 209\nivhgbxiv 420\nqdplghhx -158", "output": "ivhgbxiv" } ]
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" }, { "input": "2 3", "output": "2 0 4" }, { "input": "5 6", "output": "5 0 1" }, { "input": "4 4", "output": "0 6 0" }, { "input": "1 1", "output": "0 6 0" }, { "input": "6 4", "output": "1 1 4" }, { "input": "1 4", "output": "2 0 4" }, { "input": "5 5", "output": "0 6 0" }, { "input": "4 5", "output": "4 0 2" }, { "input": "4 3", "output": "3 0 3" }, { "input": "1 5", "output": "2 1 3" }, { "input": "6 5", "output": "1 0 5" }, { "input": "2 2", "output": "0 6 0" }, { "input": "1 3", "output": "1 1 4" }, { "input": "3 6", "output": "4 0 2" }, { "input": "3 1", "output": "4 1 1" }, { "input": "3 2", "output": "4 0 2" }, { "input": "3 5", "output": "3 1 2" }, { "input": "3 3", "output": "0 6 0" }, { "input": "6 2", "output": "2 1 3" }, { "input": "4 1", "output": "4 0 2" }, { "input": "5 2", "output": "3 0 3" }, { "input": "4 2", "output": "3 1 2" }, { "input": "2 1", "output": "5 0 1" }, { "input": "6 1", "output": "3 0 3" }, { "input": "4 6", "output": "4 1 1" }, { "input": "2 6", "output": "3 1 2" }, { "input": "3 4", "output": "3 0 3" }, { "input": "1 2", "output": "1 0 5" }, { "input": "6 6", "output": "0 6 0" }, { "input": "5 4", "output": "2 0 4" }, { "input": "3 3", "output": "0 6 0" }, { "input": "1 1", "output": "0 6 0" } ]
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": "2" }, { "input": "4\n75 13 94 77", "output": "3" }, { "input": "4\n97 8 27 3", "output": "2" }, { "input": "10\n95 51 12 91 85 3 1 31 25 7", "output": "3" }, { "input": "20\n88 96 66 51 14 88 2 92 18 72 18 88 20 30 4 82 90 100 24 46", "output": "4" }, { "input": "30\n20 94 56 50 10 98 52 32 14 22 24 60 4 8 98 46 34 68 82 82 98 90 50 20 78 49 52 94 64 36", "output": "26" }, { "input": "50\n79 27 77 57 37 45 27 49 65 33 57 21 71 19 75 85 65 61 23 97 85 9 23 1 9 3 99 77 77 21 79 69 15 37 15 7 93 81 13 89 91 31 45 93 15 97 55 80 85 83", "output": "48" }, { "input": "60\n46 11 73 65 3 69 3 53 43 53 97 47 55 93 31 75 35 3 9 73 23 31 3 81 91 79 61 21 15 11 11 11 81 7 83 75 39 87 83 59 89 55 93 27 49 67 67 29 1 93 11 17 9 19 35 21 63 31 31 25", "output": "1" }, { "input": "70\n28 42 42 92 64 54 22 38 38 78 62 38 4 38 14 66 4 92 66 58 94 26 4 44 41 88 48 82 44 26 74 44 48 4 16 92 34 38 26 64 94 4 30 78 50 54 12 90 8 16 80 98 28 100 74 50 36 42 92 18 76 98 8 22 2 50 58 50 64 46", "output": "25" }, { "input": "100\n43 35 79 53 13 91 91 45 65 83 57 9 42 39 85 45 71 51 61 59 31 13 63 39 25 21 79 39 91 67 21 61 97 75 93 83 29 79 59 97 11 37 63 51 39 55 91 23 21 17 47 23 35 75 49 5 69 99 5 7 41 17 25 89 15 79 21 63 53 81 43 91 59 91 69 99 85 15 91 51 49 37 65 7 89 81 21 93 61 63 97 93 45 17 13 69 57 25 75 73", "output": "13" }, { "input": "100\n50 24 68 60 70 30 52 22 18 74 68 98 20 82 4 46 26 68 100 78 84 58 74 98 38 88 68 86 64 80 82 100 20 22 98 98 52 6 94 10 48 68 2 18 38 22 22 82 44 20 66 72 36 58 64 6 36 60 4 96 76 64 12 90 10 58 64 60 74 28 90 26 24 60 40 58 2 16 76 48 58 36 82 60 24 44 4 78 28 38 8 12 40 16 38 6 66 24 31 76", "output": "99" }, { "input": "100\n47 48 94 48 14 18 94 36 96 22 12 30 94 20 48 98 40 58 2 94 8 36 98 18 98 68 2 60 76 38 18 100 8 72 100 68 2 86 92 72 58 16 48 14 6 58 72 76 6 88 80 66 20 28 74 62 86 68 90 86 2 56 34 38 56 90 4 8 76 44 32 86 12 98 38 34 54 92 70 94 10 24 82 66 90 58 62 2 32 58 100 22 58 72 2 22 68 72 42 14", "output": "1" }, { "input": "99\n38 20 68 60 84 16 28 88 60 48 80 28 4 92 70 60 46 46 20 34 12 100 76 2 40 10 8 86 6 80 50 66 12 34 14 28 26 70 46 64 34 96 10 90 98 96 56 88 50 74 70 94 2 94 24 66 68 46 22 30 6 10 64 32 88 14 98 100 64 58 50 18 50 50 8 38 8 16 54 2 60 54 62 84 92 98 4 72 66 26 14 88 99 16 10 6 88 56 22", "output": "93" }, { "input": "99\n50 83 43 89 53 47 69 1 5 37 63 87 95 15 55 95 75 89 33 53 89 75 93 75 11 85 49 29 11 97 49 67 87 11 25 37 97 73 67 49 87 43 53 97 43 29 53 33 45 91 37 73 39 49 59 5 21 43 87 35 5 63 89 57 63 47 29 99 19 85 13 13 3 13 43 19 5 9 61 51 51 57 15 89 13 97 41 13 99 79 13 27 97 95 73 33 99 27 23", "output": "1" }, { "input": "98\n61 56 44 30 58 14 20 24 88 28 46 56 96 52 58 42 94 50 46 30 46 80 72 88 68 16 6 60 26 90 10 98 76 20 56 40 30 16 96 20 88 32 62 30 74 58 36 76 60 4 24 36 42 54 24 92 28 14 2 74 86 90 14 52 34 82 40 76 8 64 2 56 10 8 78 16 70 86 70 42 70 74 22 18 76 98 88 28 62 70 36 72 20 68 34 48 80 98", "output": "1" }, { "input": "98\n66 26 46 42 78 32 76 42 26 82 8 12 4 10 24 26 64 44 100 46 94 64 30 18 88 28 8 66 30 82 82 28 74 52 62 80 80 60 94 86 64 32 44 88 92 20 12 74 94 28 34 58 4 22 16 10 94 76 82 58 40 66 22 6 30 32 92 54 16 76 74 98 18 48 48 30 92 2 16 42 84 74 30 60 64 52 50 26 16 86 58 96 79 60 20 62 82 94", "output": "93" }, { "input": "95\n9 31 27 93 17 77 75 9 9 53 89 39 51 99 5 1 11 39 27 49 91 17 27 79 81 71 37 75 35 13 93 4 99 55 85 11 23 57 5 43 5 61 15 35 23 91 3 81 99 85 43 37 39 27 5 67 7 33 75 59 13 71 51 27 15 93 51 63 91 53 43 99 25 47 17 71 81 15 53 31 59 83 41 23 73 25 91 91 13 17 25 13 55 57 29", "output": "32" }, { "input": "100\n91 89 81 45 53 1 41 3 77 93 55 97 55 97 87 27 69 95 73 41 93 21 75 35 53 56 5 51 87 59 91 67 33 3 99 45 83 17 97 47 75 97 7 89 17 99 23 23 81 25 55 97 27 35 69 5 77 35 93 19 55 59 37 21 31 37 49 41 91 53 73 69 7 37 37 39 17 71 7 97 55 17 47 23 15 73 31 39 57 37 9 5 61 41 65 57 77 79 35 47", "output": "26" }, { "input": "99\n38 56 58 98 80 54 26 90 14 16 78 92 52 74 40 30 84 14 44 80 16 90 98 68 26 24 78 72 42 16 84 40 14 44 2 52 50 2 12 96 58 66 8 80 44 52 34 34 72 98 74 4 66 74 56 21 8 38 76 40 10 22 48 32 98 34 12 62 80 68 64 82 22 78 58 74 20 22 48 56 12 38 32 72 6 16 74 24 94 84 26 38 18 24 76 78 98 94 72", "output": "56" }, { "input": "100\n44 40 6 40 56 90 98 8 36 64 76 86 98 76 36 92 6 30 98 70 24 98 96 60 24 82 88 68 86 96 34 42 58 10 40 26 56 10 88 58 70 32 24 28 14 82 52 12 62 36 70 60 52 34 74 30 78 76 10 16 42 94 66 90 70 38 52 12 58 22 98 96 14 68 24 70 4 30 84 98 8 50 14 52 66 34 100 10 28 100 56 48 38 12 38 14 91 80 70 86", "output": "97" }, { "input": "100\n96 62 64 20 90 46 56 90 68 36 30 56 70 28 16 64 94 34 6 32 34 50 94 22 90 32 40 2 72 10 88 38 28 92 20 26 56 80 4 100 100 90 16 74 74 84 8 2 30 20 80 32 16 46 92 56 42 12 96 64 64 42 64 58 50 42 74 28 2 4 36 32 70 50 54 92 70 16 45 76 28 16 18 50 48 2 62 94 4 12 52 52 4 100 70 60 82 62 98 42", "output": "79" }, { "input": "99\n14 26 34 68 90 58 50 36 8 16 18 6 2 74 54 20 36 84 32 50 52 2 26 24 3 64 20 10 54 26 66 44 28 72 4 96 78 90 96 86 68 28 94 4 12 46 100 32 22 36 84 32 44 94 76 94 4 52 12 30 74 4 34 64 58 72 44 16 70 56 54 8 14 74 8 6 58 62 98 54 14 40 80 20 36 72 28 98 20 58 40 52 90 64 22 48 54 70 52", "output": "25" }, { "input": "95\n82 86 30 78 6 46 80 66 74 72 16 24 18 52 52 38 60 36 86 26 62 28 22 46 96 26 94 84 20 46 66 88 76 32 12 86 74 18 34 88 4 48 94 6 58 6 100 82 4 24 88 32 54 98 34 48 6 76 42 88 42 28 100 4 22 2 10 66 82 54 98 20 60 66 38 98 32 47 86 58 6 100 12 46 2 42 8 84 78 28 24 70 34 28 86", "output": "78" }, { "input": "90\n40 50 8 42 76 24 58 42 26 68 20 48 54 12 34 84 14 36 32 88 6 50 96 56 20 92 48 16 40 34 96 46 20 84 30 50 20 98 8 44 96 42 8 76 70 38 84 30 40 88 84 72 2 22 52 58 16 62 100 66 80 40 50 32 14 62 88 72 22 99 76 50 84 82 8 82 98 46 26 40 2 98 18 78 30 72 70 18 34 68", "output": "70" }, { "input": "80\n81 43 87 1 55 43 53 61 27 19 43 13 89 9 33 83 75 55 97 71 91 37 95 5 21 69 81 93 95 69 31 83 55 7 97 7 79 57 8 61 27 85 49 1 15 97 63 79 29 73 41 85 5 41 31 93 67 11 63 59 15 99 91 77 43 69 23 23 81 73 19 1 67 51 1 75 99 67 3 81", "output": "39" }, { "input": "98\n13 83 61 27 35 1 85 95 97 73 95 65 73 45 5 43 27 83 91 19 11 3 85 59 9 39 69 23 45 7 51 85 5 71 5 95 1 51 75 3 43 57 3 11 33 71 21 99 47 41 87 39 71 87 31 85 91 49 83 5 49 85 47 91 55 99 33 23 31 23 23 73 29 77 55 31 25 5 81 49 91 15 15 39 87 5 9 40 69 47 29 33 11 21 49 79 51 83", "output": "88" }, { "input": "3\n100 100 1", "output": "3" } ]
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": "16" }, { "input": "3 3\n1 10 1\n1 10 1\n1 10 1", "output": "26" }, { "input": "3 3\n0 0 0\n0 10000 0\n0 0 0", "output": "0" }, { "input": "3 3\n1 1 1\n0 10000 0\n1 1 1", "output": "6" }, { "input": "3 3\n9 0 9\n0 9 9\n9 9 9", "output": "54" }, { "input": "3 3\n0 0 0\n0 100 0\n0 0 0", "output": "0" }, { "input": "3 3\n100000 100000 100000\n1 100000 100000\n1 1 100000", "output": "500003" }, { "input": "3 3\n100 0 100\n1 100 100\n0 100 100", "output": "501" } ]
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", "output": "2\n100 10101 " }, { "input": "314159", "output": "9\n1 1 1 1 11 1011 101011 101011 111111 " }, { "input": "999999", "output": "9\n111111 111111 111111 111111 111111 111111 111111 111111 111111 " }, { "input": "2", "output": "2\n1 1 " }, { "input": "10", "output": "1\n10 " }, { "input": "21", "output": "2\n10 11 " }, { "input": "98", "output": "9\n10 11 11 11 11 11 11 11 11 " }, { "input": "102030", "output": "3\n10 1010 101010 " }, { "input": "909090", "output": "9\n101010 101010 101010 101010 101010 101010 101010 101010 101010 " }, { "input": "909823", "output": "9\n101000 101100 101100 101100 101100 101100 101101 101111 101111 " }, { "input": "1000000", "output": "1\n1000000 " }, { "input": "111111", "output": "1\n111111 " }, { "input": "123456", "output": "6\n1 11 111 1111 11111 111111 " }, { "input": "987654", "output": "9\n100000 110000 111000 111100 111110 111111 111111 111111 111111 " }, { "input": "908172", "output": "9\n100000 101000 101010 101010 101010 101010 101010 101011 101111 " }, { "input": "8", "output": "8\n1 1 1 1 1 1 1 1 " }, { "input": "100009", "output": "9\n1 1 1 1 1 1 1 1 100001 " }, { "input": "900000", "output": "9\n100000 100000 100000 100000 100000 100000 100000 100000 100000 " }, { "input": "1435", "output": "5\n1 101 111 111 1111 " }, { "input": "1453", "output": "5\n10 110 111 111 1111 " } ]
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", "output": "8" }, { "input": "31", "output": "3" }, { "input": "59", "output": "8" }, { "input": "79", "output": "9" }, { "input": "7", "output": "3" }, { "input": "55", "output": "4" }, { "input": "40", "output": "2" }, { "input": "719", "output": "13" }, { "input": "847", "output": "13" }, { "input": "225", "output": "4" }, { "input": "4704", "output": "51" }, { "input": "1132", "output": "15" }, { "input": "7811", "output": "80" }, { "input": "7981", "output": "84" }, { "input": "82655", "output": "830" }, { "input": "6364", "output": "70" }, { "input": "74611", "output": "748" }, { "input": "45391", "output": "459" }, { "input": "620448", "output": "6210" }, { "input": "265145", "output": "2654" }, { "input": "671704", "output": "6721" }, { "input": "365173", "output": "3658" }, { "input": "7130872", "output": "71314" }, { "input": "9628747", "output": "96292" }, { "input": "8898399", "output": "88993" }, { "input": "9497953", "output": "94985" }, { "input": "19070947", "output": "190714" }, { "input": "20185520", "output": "201856" }, { "input": "91402248", "output": "914028" }, { "input": "27035533", "output": "270360" }, { "input": "22717528", "output": "227180" }, { "input": "24403439", "output": "244041" }, { "input": "163565555", "output": "1635659" }, { "input": "152541908", "output": "1525423" }, { "input": "668439837", "output": "6684403" }, { "input": "20", "output": "1" }, { "input": "999999999", "output": "10000009" }, { "input": "10", "output": "1" }, { "input": "7", "output": "3" }, { "input": "6", "output": "2" }, { "input": "99999999", "output": "1000009" }, { "input": "1000001", "output": "10001" }, { "input": "2521", "output": "27" } ]
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" }, { "input": "lwzjp\ninjit", "output": "-1" }, { "input": "epqnlxmiicdidyscjaxqznwur\neodnlemiicdedmkcgavqbnqmm", "output": "eodnlemiicdedmkcgavqbnqmm" }, { "input": "qqdabbsxiibnnjgsgxllfvdqj\nuxmypqtwfdezewdxfgplannrs", "output": "-1" }, { "input": "aanerbaqslfmqmuciqbxyznkevukvznpkmxlcorpmrenwxhzfgbmlfpxtkqpxdrmcqcmbf\naanebbaqkgfiimcciqbaoznkeqqkrgapdillccrfeienwbcvfgbmlfbimkqchcrmclcmbf", "output": "aanebbaqkgfiimcciqbaoznkeqqkrgapdillccrfeienwbcvfgbmlfbimkqchcrmclcmbf" }, { "input": "mbyrkhjctrcrayisflptgfudwgrtegidhqicsjqafvdloritbjhciyxuwavxknezwwudnk\nvvixsutlbdewqoabqhpuerfkzrddcqptfwmxdlxwbvsaqfjoxztlddvwgflcteqbwaiaen", "output": "-1" }, { "input": "eufycwztywhbjrpqobvknwfqmnboqcfdiahkagykeibbsqpljcghhmsgfmswwsanzyiwtvuirwmppfivtekaywkzskyydfvkjgxb\necfwavookadbcilfobojnweqinbcpcfdiahkabwkeibbacpljcghhksgfajgmianfnivmhfifogpffiheegayfkxkkcmdfvihgdb", "output": "ecfwavookadbcilfobojnweqinbcpcfdiahkabwkeibbacpljcghhksgfajgmianfnivmhfifogpffiheegayfkxkkcmdfvihgdb" }, { "input": "qvpltcffyeghtbdhjyhfteojezyzziardduzrbwuxmzzkkoehfnxecafizxglboauhynfbawlfxenmykquyhrxswhjuovvogntok\nchvkcvzxptbcepdjfezcpuvtehewbnvqeoezlcnzhpfwujbmhafoeqmjhtwisnobauinkzyigrvahpuetkgpdjfgbzficsmuqnym", "output": "-1" }, { "input": "nmuwjdihouqrnsuahimssnrbxdpwvxiyqtenahtrlshjkmnfuttnpqhgcagoptinnaptxaccptparldzrhpgbyrzedghudtsswxi\nnilhbdghosqnbebafimconrbvdodjsipqmekahhrllhjkemeketapfhgcagopfidnahtlaccpfpafedqicpcbvfgedghudhddwib", "output": "nilhbdghosqnbebafimconrbvdodjsipqmekahhrllhjkemeketapfhgcagopfidnahtlaccpfpafedqicpcbvfgedghudhddwib" }, { "input": "dyxgwupoauwqtcfoyfjdotzirwztdfrueqiypxoqvkmhiehdppwtdoxrbfvtairdbuvlqohjflznggjpifhwjrshcrfbjtklpykx\ngzqlnoizhxolnditjdhlhptjsbczehicudoybzilwnshmywozwnwuipcgirgzldtvtowdsokfeafggwserzdazkxyddjttiopeew", "output": "-1" }, { "input": "hbgwuqzougqzlxemvyjpeizjfwhgugrfnhbrlxkmkdalikfyunppwgdzmalbwewybnjzqsohwhjkdcyhhzmysflambvhpsjilsyv\nfbdjdqjojdafarakvcjpeipjfehgfgrfehbolxkmkdagikflunnpvadocalbkedibhbflmohnhjkdcthhaigsfjaibqhbcjelirv", "output": "fbdjdqjojdafarakvcjpeipjfehgfgrfehbolxkmkdagikflunnpvadocalbkedibhbflmohnhjkdcthhaigsfjaibqhbcjelirv" }, { "input": "xnjjhjfuhgyxqhpzmvgbaohqarugdoaczcfecofltwemieyxolswkcwhlfagfrgmoiqrgftokbqwtxgxzweozzlikrvafiabivlk\npjfosalbsitcnqiazhmepfifjxvmazvdgffcnozmnqubhonwjldmpdsjagmamniylzjdbklcyrzivjyzgnogahobpkwpwpvraqns", "output": "-1" }, { "input": "zrvzedssbsrfldqvjpgmsefrmsatspzoitwvymahiptphiystjlsauzquzqqbmljobdhijcpdvatorwmyojqgnezvzlgjibxepcf\npesoedmqbmffldqsjggmhefkadaesijointrkmahapaahiysfjdiaupqujngbjhjobdhiecadeatgjvelojjgnepvajgeibfepaf", "output": "pesoedmqbmffldqsjggmhefkadaesijointrkmahapaahiysfjdiaupqujngbjhjobdhiecadeatgjvelojjgnepvajgeibfepaf" }, { "input": "pdvkuwyzntzfqpblzmbynknyhlnqbxijuqaincviugxohcsrofozrrsategwkbwxcvkyzxhurokefpbdnmcfogfhsojayysqbrow\nbvxruombdrywlcjkrltyayaazwpauuhbtgwfzdrmfwwucgffucwelzvpsdgtapogchblzahsrfymjlaghkbmbssghrpxalkslcvp", "output": "-1" }, { "input": "tgharsjyihroiiahwgbjezlxvlterxivdhtzjcqegzmtigqmrehvhiyjeywegxaseoyoacouijudbiruoghgxvxadwzgdxtnxlds\ntghaksjsdhkoiiahegbjexlfrctercipdhmvjbgegxdtggqdpbhvhiseehhegnaseoooacnsijubbirjnghgsvpadhaadrtimfdp", "output": "tghaksjsdhkoiiahegbjexlfrctercipdhmvjbgegxdtggqdpbhvhiseehhegnaseoooacnsijubbirjnghgsvpadhaadrtimfdp" }, { "input": "jsinejpfwhzloulxndzvzftgogfdagrsscxmatldssqsgaknnbkcvhptebjjpkjhrjegrotzwcdosezkedzxeoyibmyzunkguoqj\nkfmvybobocdpipiripysioruqvloopvbggpjksgmwzyqwyxnesmvhsawnbbmntulspvsysfkjqwpvoelliopbaukyagedextzoej", "output": "-1" }, { "input": "nttdcfceptruiomtmwzestrfchnqpgqeztpcvthzelfyggjgqadylzubpvbrlgndrcsursczpxlnoyoadxezncqalupfzmjeqihe\nkttdcfceohrjiaahmoldanpfchnfpgheqpdahqhxecfpbgigqadrkjubjfbrlgndbcgcgmcjpeleinaadretncqaiqpfkmjeqihe", "output": "kttdcfceohrjiaahmoldanpfchnfpgheqpdahqhxecfpbgigqadrkjubjfbrlgndbcgcgmcjpeleinaadretncqaiqpfkmjeqihe" }, { "input": "diuopwglduasnaxgduwslbzoyayoypzznqspljcyqehweydhlwifcvnjmaowuvyqfwynjghecqvxdvuquuwpvwrjljozocaxnktv\ntrdydprdzmjhgbhzytelrfjpgsebijicsigmwhynmcyjtqrvojcndodchzxfcvyqjxqzwibccdvsjqhsnectdjyrrhzkeamukang", "output": "-1" }, { "input": "ftfr\nftfr", "output": "ftfr" }, { "input": "ftr\nftr", "output": "ftr" }, { "input": "shftr\nshftr", "output": "shftr" }, { "input": "vkvkkv\nvkvkkv", "output": "vkvkkv" }, { "input": "ftrd\nftrd", "output": "ftrd" }, { "input": "fztr\nfztr", "output": "fztr" }, { "input": "frtr\nfrtr", "output": "frtr" }, { "input": "shdftr\nshdftr", "output": "shdftr" }, { "input": "zzz\nzzz", "output": "zzz" }, { "input": "shtr\nshtr", "output": "shtr" }, { "input": "aaaaa\nzzzzz", "output": "-1" }, { "input": "efr\nefr", "output": "efr" } ]
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": "2" }, { "input": "4\n75 13 94 77", "output": "3" }, { "input": "4\n97 8 27 3", "output": "2" }, { "input": "10\n95 51 12 91 85 3 1 31 25 7", "output": "3" }, { "input": "20\n88 96 66 51 14 88 2 92 18 72 18 88 20 30 4 82 90 100 24 46", "output": "4" }, { "input": "30\n20 94 56 50 10 98 52 32 14 22 24 60 4 8 98 46 34 68 82 82 98 90 50 20 78 49 52 94 64 36", "output": "26" }, { "input": "50\n79 27 77 57 37 45 27 49 65 33 57 21 71 19 75 85 65 61 23 97 85 9 23 1 9 3 99 77 77 21 79 69 15 37 15 7 93 81 13 89 91 31 45 93 15 97 55 80 85 83", "output": "48" }, { "input": "60\n46 11 73 65 3 69 3 53 43 53 97 47 55 93 31 75 35 3 9 73 23 31 3 81 91 79 61 21 15 11 11 11 81 7 83 75 39 87 83 59 89 55 93 27 49 67 67 29 1 93 11 17 9 19 35 21 63 31 31 25", "output": "1" }, { "input": "70\n28 42 42 92 64 54 22 38 38 78 62 38 4 38 14 66 4 92 66 58 94 26 4 44 41 88 48 82 44 26 74 44 48 4 16 92 34 38 26 64 94 4 30 78 50 54 12 90 8 16 80 98 28 100 74 50 36 42 92 18 76 98 8 22 2 50 58 50 64 46", "output": "25" }, { "input": "100\n43 35 79 53 13 91 91 45 65 83 57 9 42 39 85 45 71 51 61 59 31 13 63 39 25 21 79 39 91 67 21 61 97 75 93 83 29 79 59 97 11 37 63 51 39 55 91 23 21 17 47 23 35 75 49 5 69 99 5 7 41 17 25 89 15 79 21 63 53 81 43 91 59 91 69 99 85 15 91 51 49 37 65 7 89 81 21 93 61 63 97 93 45 17 13 69 57 25 75 73", "output": "13" }, { "input": "100\n50 24 68 60 70 30 52 22 18 74 68 98 20 82 4 46 26 68 100 78 84 58 74 98 38 88 68 86 64 80 82 100 20 22 98 98 52 6 94 10 48 68 2 18 38 22 22 82 44 20 66 72 36 58 64 6 36 60 4 96 76 64 12 90 10 58 64 60 74 28 90 26 24 60 40 58 2 16 76 48 58 36 82 60 24 44 4 78 28 38 8 12 40 16 38 6 66 24 31 76", "output": "99" }, { "input": "100\n47 48 94 48 14 18 94 36 96 22 12 30 94 20 48 98 40 58 2 94 8 36 98 18 98 68 2 60 76 38 18 100 8 72 100 68 2 86 92 72 58 16 48 14 6 58 72 76 6 88 80 66 20 28 74 62 86 68 90 86 2 56 34 38 56 90 4 8 76 44 32 86 12 98 38 34 54 92 70 94 10 24 82 66 90 58 62 2 32 58 100 22 58 72 2 22 68 72 42 14", "output": "1" }, { "input": "99\n38 20 68 60 84 16 28 88 60 48 80 28 4 92 70 60 46 46 20 34 12 100 76 2 40 10 8 86 6 80 50 66 12 34 14 28 26 70 46 64 34 96 10 90 98 96 56 88 50 74 70 94 2 94 24 66 68 46 22 30 6 10 64 32 88 14 98 100 64 58 50 18 50 50 8 38 8 16 54 2 60 54 62 84 92 98 4 72 66 26 14 88 99 16 10 6 88 56 22", "output": "93" }, { "input": "99\n50 83 43 89 53 47 69 1 5 37 63 87 95 15 55 95 75 89 33 53 89 75 93 75 11 85 49 29 11 97 49 67 87 11 25 37 97 73 67 49 87 43 53 97 43 29 53 33 45 91 37 73 39 49 59 5 21 43 87 35 5 63 89 57 63 47 29 99 19 85 13 13 3 13 43 19 5 9 61 51 51 57 15 89 13 97 41 13 99 79 13 27 97 95 73 33 99 27 23", "output": "1" }, { "input": "98\n61 56 44 30 58 14 20 24 88 28 46 56 96 52 58 42 94 50 46 30 46 80 72 88 68 16 6 60 26 90 10 98 76 20 56 40 30 16 96 20 88 32 62 30 74 58 36 76 60 4 24 36 42 54 24 92 28 14 2 74 86 90 14 52 34 82 40 76 8 64 2 56 10 8 78 16 70 86 70 42 70 74 22 18 76 98 88 28 62 70 36 72 20 68 34 48 80 98", "output": "1" }, { "input": "98\n66 26 46 42 78 32 76 42 26 82 8 12 4 10 24 26 64 44 100 46 94 64 30 18 88 28 8 66 30 82 82 28 74 52 62 80 80 60 94 86 64 32 44 88 92 20 12 74 94 28 34 58 4 22 16 10 94 76 82 58 40 66 22 6 30 32 92 54 16 76 74 98 18 48 48 30 92 2 16 42 84 74 30 60 64 52 50 26 16 86 58 96 79 60 20 62 82 94", "output": "93" }, { "input": "95\n9 31 27 93 17 77 75 9 9 53 89 39 51 99 5 1 11 39 27 49 91 17 27 79 81 71 37 75 35 13 93 4 99 55 85 11 23 57 5 43 5 61 15 35 23 91 3 81 99 85 43 37 39 27 5 67 7 33 75 59 13 71 51 27 15 93 51 63 91 53 43 99 25 47 17 71 81 15 53 31 59 83 41 23 73 25 91 91 13 17 25 13 55 57 29", "output": "32" }, { "input": "100\n91 89 81 45 53 1 41 3 77 93 55 97 55 97 87 27 69 95 73 41 93 21 75 35 53 56 5 51 87 59 91 67 33 3 99 45 83 17 97 47 75 97 7 89 17 99 23 23 81 25 55 97 27 35 69 5 77 35 93 19 55 59 37 21 31 37 49 41 91 53 73 69 7 37 37 39 17 71 7 97 55 17 47 23 15 73 31 39 57 37 9 5 61 41 65 57 77 79 35 47", "output": "26" }, { "input": "99\n38 56 58 98 80 54 26 90 14 16 78 92 52 74 40 30 84 14 44 80 16 90 98 68 26 24 78 72 42 16 84 40 14 44 2 52 50 2 12 96 58 66 8 80 44 52 34 34 72 98 74 4 66 74 56 21 8 38 76 40 10 22 48 32 98 34 12 62 80 68 64 82 22 78 58 74 20 22 48 56 12 38 32 72 6 16 74 24 94 84 26 38 18 24 76 78 98 94 72", "output": "56" }, { "input": "100\n44 40 6 40 56 90 98 8 36 64 76 86 98 76 36 92 6 30 98 70 24 98 96 60 24 82 88 68 86 96 34 42 58 10 40 26 56 10 88 58 70 32 24 28 14 82 52 12 62 36 70 60 52 34 74 30 78 76 10 16 42 94 66 90 70 38 52 12 58 22 98 96 14 68 24 70 4 30 84 98 8 50 14 52 66 34 100 10 28 100 56 48 38 12 38 14 91 80 70 86", "output": "97" }, { "input": "100\n96 62 64 20 90 46 56 90 68 36 30 56 70 28 16 64 94 34 6 32 34 50 94 22 90 32 40 2 72 10 88 38 28 92 20 26 56 80 4 100 100 90 16 74 74 84 8 2 30 20 80 32 16 46 92 56 42 12 96 64 64 42 64 58 50 42 74 28 2 4 36 32 70 50 54 92 70 16 45 76 28 16 18 50 48 2 62 94 4 12 52 52 4 100 70 60 82 62 98 42", "output": "79" }, { "input": "99\n14 26 34 68 90 58 50 36 8 16 18 6 2 74 54 20 36 84 32 50 52 2 26 24 3 64 20 10 54 26 66 44 28 72 4 96 78 90 96 86 68 28 94 4 12 46 100 32 22 36 84 32 44 94 76 94 4 52 12 30 74 4 34 64 58 72 44 16 70 56 54 8 14 74 8 6 58 62 98 54 14 40 80 20 36 72 28 98 20 58 40 52 90 64 22 48 54 70 52", "output": "25" }, { "input": "95\n82 86 30 78 6 46 80 66 74 72 16 24 18 52 52 38 60 36 86 26 62 28 22 46 96 26 94 84 20 46 66 88 76 32 12 86 74 18 34 88 4 48 94 6 58 6 100 82 4 24 88 32 54 98 34 48 6 76 42 88 42 28 100 4 22 2 10 66 82 54 98 20 60 66 38 98 32 47 86 58 6 100 12 46 2 42 8 84 78 28 24 70 34 28 86", "output": "78" }, { "input": "90\n40 50 8 42 76 24 58 42 26 68 20 48 54 12 34 84 14 36 32 88 6 50 96 56 20 92 48 16 40 34 96 46 20 84 30 50 20 98 8 44 96 42 8 76 70 38 84 30 40 88 84 72 2 22 52 58 16 62 100 66 80 40 50 32 14 62 88 72 22 99 76 50 84 82 8 82 98 46 26 40 2 98 18 78 30 72 70 18 34 68", "output": "70" }, { "input": "80\n81 43 87 1 55 43 53 61 27 19 43 13 89 9 33 83 75 55 97 71 91 37 95 5 21 69 81 93 95 69 31 83 55 7 97 7 79 57 8 61 27 85 49 1 15 97 63 79 29 73 41 85 5 41 31 93 67 11 63 59 15 99 91 77 43 69 23 23 81 73 19 1 67 51 1 75 99 67 3 81", "output": "39" }, { "input": "98\n13 83 61 27 35 1 85 95 97 73 95 65 73 45 5 43 27 83 91 19 11 3 85 59 9 39 69 23 45 7 51 85 5 71 5 95 1 51 75 3 43 57 3 11 33 71 21 99 47 41 87 39 71 87 31 85 91 49 83 5 49 85 47 91 55 99 33 23 31 23 23 73 29 77 55 31 25 5 81 49 91 15 15 39 87 5 9 40 69 47 29 33 11 21 49 79 51 83", "output": "88" }, { "input": "3\n100 100 1", "output": "3" } ]
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": "1001101001101110101101000\n01111000010011111111110010001101000100011110101111", "output": "321" }, { "input": "1110010001000101001011111\n00011011000000100001010000010100110011010001111010", "output": "316" } ]
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": "402572650" }, { "input": "3 2 3 1", "output": "0" }, { "input": "5 1 2 1", "output": "0" }, { "input": "50 48 41 2", "output": "44" }, { "input": "50 25 21 50", "output": "317551605" }, { "input": "5000 1 100 3", "output": "483642" }, { "input": "100 1 30 500", "output": "627243445" }, { "input": "50 5 2 50", "output": "923222599" }, { "input": "35 9 10 35", "output": "0" }, { "input": "10 1 3 4", "output": "0" }, { "input": "22 9 18 3", "output": "1964" }, { "input": "500 500 498 4999", "output": "0" }, { "input": "300 300 299 300", "output": "0" }, { "input": "100 3 30 5000", "output": "831733342" }, { "input": "222 187 134 500", "output": "769809644" }, { "input": "300 299 300 300", "output": "0" }, { "input": "400 11 12 400", "output": "0" }, { "input": "2 1 2 5000", "output": "0" }, { "input": "2 1 2 5000", "output": "0" }, { "input": "1000 213 480 1", "output": "478" }, { "input": "1000 213 480 1", "output": "478" }, { "input": "2 1 2 1", "output": "0" }, { "input": "10 1 4 4999", "output": "2" }, { "input": "500 499 500 500", "output": "0" }, { "input": "500 500 498 5000", "output": "0" }, { "input": "300 1 300 300", "output": "396536590" }, { "input": "300 300 1 300", "output": "396536590" }, { "input": "500 498 500 499", "output": "113017568" }, { "input": "1000 1 500 1000", "output": "594673663" }, { "input": "500 498 500 500", "output": "973540182" }, { "input": "500 1 500 500", "output": "521515914" }, { "input": "2000 500 1 2000", "output": "288043610" }, { "input": "1000 500 1 2000", "output": "744846473" }, { "input": "1000 500 1 1000", "output": "921282926" }, { "input": "5000 2500 1 5000", "output": "898026985" }, { "input": "5000 1 2500 5000", "output": "968861072" }, { "input": "4999 2500 1 4999", "output": "694314934" }, { "input": "4999 1 2 4999", "output": "0" }, { "input": "5000 100 1 5000", "output": "363556022" }, { "input": "5000 4999 5000 5000", "output": "0" }, { "input": "3999 2 10 5000", "output": "343196694" }, { "input": "4998 2 4 5000", "output": "2" }, { "input": "5000 5000 1 5000", "output": "233993486" }, { "input": "5000 5000 4999 5000", "output": "0" }, { "input": "5000 4998 5000 5000", "output": "701940824" }, { "input": "443 144 6 223", "output": "362569369" }, { "input": "232 34 49 234", "output": "984852735" }, { "input": "232 195 193 322", "output": "12938181" }, { "input": "488 96 473 488", "output": "212471726" }, { "input": "500 436 412 500", "output": "724363905" }, { "input": "4943 944 1747 2213", "output": "12879261" }, { "input": "2032 1050 1339 2334", "output": "439644037" }, { "input": "2332 2204 558 3722", "output": "659576072" }, { "input": "4988 3629 4106 4488", "output": "349016655" }, { "input": "5000 2081 3619 5000", "output": "557114846" }, { "input": "5000 2 5000 5000", "output": "233993486" }, { "input": "5000 3000 2000 5000", "output": "82819894" }, { "input": "5000 1 5000 5000", "output": "233993486" }, { "input": "150 150 1 150", "output": "954984546" }, { "input": "5 3 2 2", "output": "0" }, { "input": "5 4 2 1", "output": "2" }, { "input": "5000 1031 4737 5000", "output": "917351304" }, { "input": "5000 1031 4782 5000", "output": "981271392" }, { "input": "5000 2314 1234 5000", "output": "546628648" } ]
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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "50" }, { "input": "100\n1 838 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1 605 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1 27 533 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1 835 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1 992", "output": "42" }, { "input": "1\n1", "output": "1" }, { "input": "2\n1 1", "output": "2" }, { "input": "6\n5 4 3 2 1 2", "output": "2" }, { "input": "9\n1 2 3 4 5 6 7 8 9", "output": "9" }, { "input": "7\n99 100 1 2 3 4 5", "output": "5" }, { "input": "5\n3 3 1 2 3", "output": "3" }, { "input": "1\n100", "output": "1" }, { "input": "1\n5", "output": "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": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVG" }, { "input": "9", "output": "ROYGBIVGB" }, { "input": "11", "output": "ROYGBIVYGBI" }, { "input": "12", "output": "ROYGBIVOYGBI" }, { "input": "15", "output": "ROYGBIVROYGBIVG" }, { "input": "16", "output": "ROYGBIVROYGBIVGB" }, { "input": "17", "output": "ROYGBIVROYGBIVYGB" }, { "input": "18", "output": "ROYGBIVROYGBIVYGBI" }, { "input": "19", "output": "ROYGBIVROYGBIVOYGBI" }, { "input": "20", "output": "ROYGBIVROYGBIVOYGBIV" }, { "input": "21", "output": "ROYGBIVROYGBIVROYGBIV" }, { "input": "22", "output": "ROYGBIVROYGBIVROYGBIVG" }, { "input": "23", "output": "ROYGBIVROYGBIVROYGBIVGB" }, { "input": "24", "output": "ROYGBIVROYGBIVROYGBIVYGB" }, { "input": "25", "output": "ROYGBIVROYGBIVROYGBIVYGBI" }, { "input": "28", "output": "ROYGBIVROYGBIVROYGBIVROYGBIV" }, { "input": "29", "output": "ROYGBIVROYGBIVROYGBIVROYGBIVG" }, { "input": "34", "output": "ROYGBIVROYGBIVROYGBIVROYGBIVOYGBIV" }, { "input": "43", "output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVG" }, { "input": "61", "output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVOYGBI" }, { "input": "79", "output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVGB" }, { "input": "81", "output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVYGBI" }, { "input": "92", "output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVG" }, { "input": "95", "output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVYGBI" }, { "input": "96", "output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVOYGBI" }, { "input": "97", "output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVOYGBIV" }, { "input": "98", "output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIV" }, { "input": "99", "output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVG" }, { "input": "100", "output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVGB" } ]
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", "output": "1 2 2 1 " }, { "input": "2\n1000000000 1\n0101", "output": "2 2 1 1 " }, { "input": "2\n1000000000 999999999\n0011", "output": "2 1 1 2 " }, { "input": "10\n24 53 10 99 83 9 15 62 33 47\n00100000000111111111", "output": "6 3 3 7 1 9 10 2 8 5 4 4 5 8 2 10 9 1 7 6 " } ]
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 853171 592966 225788 46977 814826 295697 676256 561479 56545 764281", "output": "5464380" }, { "input": "21\n842556 216391 427181 626688 775504 168309 851038 448402 880826 73697 593338 519033 135115 20128 424606 939484 846242 756907 377058 241543 29353", "output": "9535765" }, { "input": "3\n1 3 2", "output": "3" }, { "input": "3\n2 1 3", "output": "3" }, { "input": "3\n2 3 1", "output": "3" }, { "input": "3\n3 1 2", "output": "3" }, { "input": "3\n3 2 1", "output": "3" }, { "input": "1\n228503", "output": "0" }, { "input": "2\n32576 550340", "output": "517764" }, { "input": "3\n910648 542843 537125", "output": "741328" }, { "input": "4\n751720 572344 569387 893618", "output": "787403" }, { "input": "6\n433864 631347 597596 794426 713555 231193", "output": "1364575" }, { "input": "9\n31078 645168 695751 126111 375934 150495 838412 434477 993107", "output": "4647430" }, { "input": "30\n315421 772664 560686 654312 151528 356749 351486 707462 820089 226682 546700 136028 824236 842130 578079 337807 665903 764100 617900 822937 992759 591749 651310 742085 767695 695442 17967 515106 81059 186025", "output": "13488674" }, { "input": "45\n908719 394261 815134 419990 926993 383792 772842 277695 527137 655356 684956 695716 273062 550324 106247 399133 442382 33076 462920 294674 846052 817752 421365 474141 290471 358990 109812 74492 543281 169434 919692 786809 24028 197184 310029 801476 699355 429672 51343 374128 776726 850380 293868 981569 550763", "output": "21993384" }, { "input": "56\n100728 972537 13846 385421 756708 184642 259487 319707 376662 221694 675284 972837 499419 13846 38267 289898 901299 831197 954715 197515 514102 910423 127555 883934 362472 870788 538802 741008 973434 448124 391526 363321 947321 544618 68006 782313 955075 741981 815027 723297 585059 718114 700739 413489 454091 736144 308999 98065 3716 347323 9635 289003 986510 607065 60236 273351", "output": "26984185" }, { "input": "70\n644488 5444 150441 714420 602059 335330 510670 196555 546346 740011 509449 850947 692874 524857 750434 952985 223744 374727 896124 753037 367352 679050 560202 172728 569291 778616 332116 286927 843598 372698 244906 498046 900681 709791 420904 724593 864493 813094 791377 39998 296710 625656 403891 579231 706693 984045 16901 574259 562265 761104 930361 256045 124461 538980 573508 372148 988722 108592 784354 55302 232524 277205 782251 299943 436488 743389 324618 742543 266915 99642", "output": "32816391" }, { "input": "1\n0", "output": "0" }, { "input": "1\n1000000", "output": "0" }, { "input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "0" }, { "input": "100\n1000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "99000000" }, { "input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1000000", "output": "99000000" }, { "input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "99000000" }, { "input": "3\n0 0 0", "output": "0" }, { "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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "0" }, { "input": "3\n5 0 0", "output": "10" }, { "input": "5\n2 10 0 0 0", "output": "38" } ]
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" }, { "input": "6", "output": "YES" }, { "input": "10", "output": "YES" }, { "input": "9", "output": "NO" }, { "input": "53", "output": "NO" }, { "input": "77", "output": "NO" }, { "input": "32", "output": "YES" }, { "input": "44", "output": "YES" }, { "input": "98", "output": "YES" }, { "input": "99", "output": "NO" }, { "input": "90", "output": "YES" }, { "input": "67", "output": "NO" }, { "input": "100", "output": "YES" }, { "input": "88", "output": "YES" } ]
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 539 896 668 36 896", "output": "YES" }, { "input": "7\n674 712 674 674 674 674 674", "output": "NO" }, { "input": "8\n742 742 742 742 742 289 742 742", "output": "NO" }, { "input": "9\n730 351 806 806 806 630 85 757 967", "output": "YES" }, { "input": "10\n324 539 83 440 834 640 440 440 440 440", "output": "YES" }, { "input": "7\n925 830 925 98 987 162 356", "output": "YES" }, { "input": "68\n575 32 53 351 151 942 725 967 431 108 192 8 338 458 288 754 384 946 910 210 759 222 589 423 947 507 31 414 169 901 592 763 656 411 360 625 538 549 484 596 42 603 351 292 837 375 21 597 22 349 200 669 485 282 735 54 1000 419 939 901 789 128 468 729 894 649 484 808", "output": "YES" }, { "input": "22\n618 814 515 310 617 936 452 601 250 520 557 799 304 225 9 845 610 990 703 196 486 94", "output": "YES" }, { "input": "44\n459 581 449 449 449 449 449 449 449 623 449 449 449 449 449 449 449 449 889 449 203 273 329 449 449 449 449 449 449 845 882 323 22 449 449 893 449 449 449 449 449 870 449 402", "output": "NO" }, { "input": "90\n424 3 586 183 286 89 427 618 758 833 933 170 155 722 190 977 330 369 693 426 556 435 550 442 513 146 61 719 754 140 424 280 997 688 530 550 438 867 950 194 196 298 417 287 106 489 283 456 735 115 702 317 672 787 264 314 356 186 54 913 809 833 946 314 757 322 559 647 983 482 145 197 223 130 162 536 451 174 467 45 660 293 440 254 25 155 511 746 650 187", "output": "YES" }, { "input": "14\n959 203 478 315 788 788 373 834 488 519 774 764 193 103", "output": "YES" }, { "input": "81\n544 528 528 528 528 4 506 528 32 528 528 528 528 528 528 528 528 975 528 528 528 528 528 528 528 528 528 528 528 528 528 20 528 528 528 528 528 528 528 528 852 528 528 120 528 528 61 11 528 528 528 228 528 165 883 528 488 475 628 528 528 528 528 528 528 597 528 528 528 528 528 528 528 528 528 528 528 412 528 521 925", "output": "NO" }, { "input": "89\n354 356 352 355 355 355 352 354 354 352 355 356 355 352 354 356 354 355 355 354 353 352 352 355 355 356 352 352 353 356 352 353 354 352 355 352 353 353 353 354 353 354 354 353 356 353 353 354 354 354 354 353 352 353 355 356 356 352 356 354 353 352 355 354 356 356 356 354 354 356 354 355 354 355 353 352 354 355 352 355 355 354 356 353 353 352 356 352 353", "output": "YES" }, { "input": "71\n284 284 285 285 285 284 285 284 284 285 284 285 284 284 285 284 285 285 285 285 284 284 285 285 284 284 284 285 284 285 284 285 285 284 284 284 285 284 284 285 285 285 284 284 285 284 285 285 284 285 285 284 285 284 284 284 285 285 284 285 284 285 285 285 285 284 284 285 285 284 285", "output": "NO" }, { "input": "28\n602 216 214 825 814 760 814 28 76 814 814 288 814 814 222 707 11 490 814 543 914 705 814 751 976 814 814 99", "output": "YES" }, { "input": "48\n546 547 914 263 986 945 914 914 509 871 324 914 153 571 914 914 914 528 970 566 544 914 914 914 410 914 914 589 609 222 914 889 691 844 621 68 914 36 914 39 630 749 914 258 945 914 727 26", "output": "YES" }, { "input": "56\n516 76 516 197 516 427 174 516 706 813 94 37 516 815 516 516 937 483 16 516 842 516 638 691 516 635 516 516 453 263 516 516 635 257 125 214 29 81 516 51 362 516 677 516 903 516 949 654 221 924 516 879 516 516 972 516", "output": "YES" }, { "input": "46\n314 723 314 314 314 235 314 314 314 314 270 314 59 972 314 216 816 40 314 314 314 314 314 314 314 381 314 314 314 314 314 314 314 789 314 957 114 942 314 314 29 314 314 72 314 314", "output": "NO" }, { "input": "72\n169 169 169 599 694 81 250 529 865 406 817 169 667 169 965 169 169 663 65 169 903 169 942 763 169 807 169 603 169 169 13 169 169 810 169 291 169 169 169 169 169 169 169 713 169 440 169 169 169 169 169 480 169 169 867 169 169 169 169 169 169 169 169 393 169 169 459 169 99 169 601 800", "output": "NO" }, { "input": "100\n317 316 317 316 317 316 317 316 317 316 316 317 317 316 317 316 316 316 317 316 317 317 316 317 316 316 316 316 316 316 317 316 317 317 317 317 317 317 316 316 316 317 316 317 316 317 316 317 317 316 317 316 317 317 316 317 316 317 316 317 316 316 316 317 317 317 317 317 316 317 317 316 316 316 316 317 317 316 317 316 316 316 316 316 316 317 316 316 317 317 317 317 317 317 317 317 317 316 316 317", "output": "NO" }, { "input": "100\n510 510 510 162 969 32 510 511 510 510 911 183 496 875 903 461 510 510 123 578 510 510 510 510 510 755 510 673 510 510 763 510 510 909 510 435 487 959 807 510 368 788 557 448 284 332 510 949 510 510 777 112 857 926 487 510 510 510 678 510 510 197 829 427 698 704 409 509 510 238 314 851 510 651 510 455 682 510 714 635 973 510 443 878 510 510 510 591 510 24 596 510 43 183 510 510 671 652 214 784", "output": "YES" }, { "input": "100\n476 477 474 476 476 475 473 476 474 475 473 477 476 476 474 476 474 475 476 477 473 473 473 474 474 476 473 473 476 476 475 476 473 474 473 473 477 475 475 475 476 475 477 477 477 476 475 475 475 473 476 477 475 476 477 473 474 477 473 475 476 476 474 477 476 474 473 477 473 475 477 473 476 474 477 473 475 477 473 476 476 475 476 475 474 473 477 473 475 473 477 473 473 474 475 473 477 476 477 474", "output": "YES" }, { "input": "100\n498 498 498 498 498 499 498 499 499 499 498 498 498 498 499 498 499 499 498 499 498 498 498 499 499 499 498 498 499 499 498 498 498 499 498 499 498 498 498 499 498 499 498 498 498 498 499 498 498 499 498 498 499 498 499 499 498 499 499 499 498 498 498 498 499 498 499 498 499 499 499 499 498 498 499 499 498 499 499 498 498 499 499 498 498 499 499 499 498 498 499 498 498 498 499 499 499 498 498 499", "output": "NO" }, { "input": "100\n858 53 816 816 816 816 816 816 816 181 816 816 816 816 579 879 816 948 171 816 816 150 866 816 816 816 897 816 816 816 816 816 816 706 816 539 816 816 816 816 816 816 423 487 816 615 254 816 816 816 816 83 816 816 816 816 816 816 816 816 816 816 816 136 775 999 816 816 816 644 816 816 816 816 927 816 802 816 856 816 816 816 816 816 816 816 816 816 816 700 816 816 816 816 982 477 816 891 806 816", "output": "NO" }, { "input": "100\n167 169 169 167 169 169 167 167 167 167 168 166 170 170 169 170 170 170 169 168 166 167 170 169 167 169 168 169 166 170 166 167 170 166 166 167 169 166 166 169 166 167 168 168 170 167 168 166 168 170 167 168 167 169 169 166 168 167 170 168 167 169 168 169 166 168 168 169 169 166 170 168 167 169 170 168 167 169 168 167 168 168 166 169 170 170 166 166 167 170 167 168 167 167 169 169 166 166 169 167", "output": "YES" }, { "input": "100\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000", "output": "NO" }, { "input": "99\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000", "output": "NO" }, { "input": "100\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "YES" }, { "input": "99\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "YES" }, { "input": "2\n1 1", "output": "NO" }, { "input": "1\n1000", "output": "YES" }, { "input": "12\n2 2 4 4 4 4 6 6 6 6 6 6", "output": "YES" } ]
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" }, { "input": "192", "output": "4 188" }, { "input": "86", "output": "4 82" }, { "input": "46220", "output": "4 46216" }, { "input": "57114", "output": "4 57110" }, { "input": "869", "output": "4 865" }, { "input": "738457", "output": "4 738453" }, { "input": "58113", "output": "6 58107" }, { "input": "4864", "output": "4 4860" }, { "input": "15", "output": "6 9" }, { "input": "74752", "output": "4 74748" }, { "input": "6073", "output": "4 6069" }, { "input": "1289", "output": "4 1285" }, { "input": "20", "output": "4 16" }, { "input": "58134", "output": "4 58130" }, { "input": "57756", "output": "4 57752" }, { "input": "765", "output": "6 759" }, { "input": "59", "output": "4 55" }, { "input": "991666", "output": "4 991662" }, { "input": "70761", "output": "4 70757" }, { "input": "13", "output": "4 9" }, { "input": "999999", "output": "4 999995" }, { "input": "17", "output": "8 9" }, { "input": "21", "output": "6 15" }, { "input": "19", "output": "4 15" }, { "input": "100007", "output": "6 100001" }, { "input": "999987", "output": "6 999981" }, { "input": "22", "output": "4 18" } ]
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" }, { "input": "3\n2 3\n1 1\n3 2", "output": "Happy Alex" }, { "input": "4\n4 1\n3 2\n2 3\n1 4", "output": "Happy Alex" }, { "input": "2\n2 1\n1 2", "output": "Happy Alex" }, { "input": "3\n3 2\n1 1\n2 3", "output": "Happy Alex" }, { "input": "3\n1 2\n2 3\n3 1", "output": "Happy Alex" }, { "input": "3\n1 2\n2 1\n3 3", "output": "Happy Alex" }, { "input": "3\n1 2\n2 3\n3 1", "output": "Happy 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\n510000", "output": "490000" }, { "input": "3\n2 5 27", "output": "26" }, { "input": "2\n600000 800000", "output": "400000" }, { "input": "5\n2 5 6 27 29", "output": "28" }, { "input": "1\n500001", "output": "499999" }, { "input": "10\n3934 38497 42729 45023 51842 68393 77476 82414 91465 98055", "output": "98054" }, { "input": "1\n900000", "output": "100000" }, { "input": "1\n500000", "output": "499999" }, { "input": "1\n999998", "output": "2" }, { "input": "3\n999997 999998 999999", "output": "3" }, { "input": "2\n999997 999999", "output": "3" }, { "input": "2\n2 999998", "output": "2" }, { "input": "2\n500000 500001", "output": "499999" }, { "input": "1\n500002", "output": "499998" }, { "input": "1\n700000", "output": "300000" }, { "input": "2\n2 999999", "output": "1" }, { "input": "2\n999998 999999", "output": "2" }, { "input": "1\n999995", "output": "5" }, { "input": "2\n499999 500001", "output": "499999" }, { "input": "1\n499999", "output": "499998" }, { "input": "2\n100 999900", "output": "100" }, { "input": "2\n499999 500000", "output": "499999" }, { "input": "2\n500001 999999", "output": "499999" }, { "input": "3\n500000 500001 500002", "output": "499999" }, { "input": "2\n2 500001", "output": "499999" }, { "input": "2\n499999 999999", "output": "499998" }, { "input": "2\n2 500000", "output": "499999" }, { "input": "4\n2 3 4 999999", "output": "3" }, { "input": "2\n100000 500001", "output": "499999" }, { "input": "1\n2", "output": "1" }, { "input": "1\n800000", "output": "200000" }, { "input": "1\n505050", "output": "494950" }, { "input": "1\n753572", "output": "246428" }, { "input": "2\n576696 760487", "output": "423304" }, { "input": "10\n3 4 5 6 7 8 9 10 11 12", "output": "11" }, { "input": "4\n2 3 4 5", "output": "4" }, { "input": "4\n999996 999997 999998 999999", "output": "4" } ]
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", "output": "40326" }, { "input": "1000 10000", "output": "74133360011484445" }, { "input": "139 9252", "output": "1137907933561080" }, { "input": "859 8096", "output": "29032056230649780" }, { "input": "987 4237", "output": "5495451829240878" }, { "input": "411 3081", "output": "366755153481948" }, { "input": "539 9221", "output": "16893595018603386" }, { "input": "259 770", "output": "2281741798549" }, { "input": "387 5422", "output": "1771610559998400" }, { "input": "515 1563", "output": "75233740231341" }, { "input": "939 407", "output": "4438222781916" }, { "input": "518 6518", "output": "5511730799718825" }, { "input": "646 1171", "output": "49802404050106" }, { "input": "70 7311", "output": "142915220249910" }, { "input": "494 6155", "output": "4221391613846823" }, { "input": "918 7704", "output": "28569727339126165" }, { "input": "46 3844", "output": "9007500020760" }, { "input": "174 2688", "output": "43730657099581" }, { "input": "894 4637", "output": "5909849585253250" }, { "input": "22 3481", "output": "1548544125646" }, { "input": "446 5030", "output": "1878390629993745" }, { "input": "440 8704", "output": "9470470760118060" }, { "input": "569 7548", "output": "10326205017481606" }, { "input": "289 6393", "output": "1620061541812350" }, { "input": "417 1045", "output": "14758909519725" }, { "input": "841 7185", "output": "19452619774222875" }, { "input": "969 6030", "output": "15265318959845745" }, { "input": "393 4874", "output": "1327174123029975" }, { "input": "817 3719", "output": "2546859449982016" }, { "input": "945 2563", "output": "1115613396515835" }, { "input": "369 4511", "output": "927715710215505" }, { "input": "555 3594", "output": "1061060598862891" } ]
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", "output": "1" }, { "input": "2 3 4", "output": "1" }, { "input": "1000000000 1000000000 1", "output": "1000000000000000000" }, { "input": "12 13 4", "output": "12" }, { "input": "222 332 5", "output": "3015" }, { "input": "1000 1000 10", "output": "10000" }, { "input": "1001 1000 10", "output": "10100" }, { "input": "100 10001 1000000000", "output": "1" }, { "input": "1000000000 1000000000 1000000000", "output": "1" }, { "input": "1000000000 1000000000 999999999", "output": "4" }, { "input": "1000000000 1000000000 192", "output": "27126743055556" }, { "input": "1000000000 987654321 1", "output": "987654321000000000" }, { "input": "456784567 1000000000 51", "output": "175618850864484" }, { "input": "39916800 134217728 40320", "output": "3295710" } ]
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 981 360 783 907 292 186 341 292 360 876 360 360 981 398 783 288 292 398 876 981 398 907 783 360 288 981 907 186 360 288 186 981 186 288 907 876 288 907 876 360 341 292 907 783 907 783 292 981 907 292 876 398 783 876 398 341 876 186 288 186 981 341 398 360 907 981 341 186 292 981 292 398 876 783 292 186 360 292 288 292 876 398 288 292 341 288 398 360 360 292 981 360", "output": "14" }, { "input": "1\n1", "output": "1" }, { "input": "1\n9", "output": "1" }, { "input": "1\n5", "output": "1" }, { "input": "1\n2", "output": "1" }, { "input": "1\n131", "output": "1" }, { "input": "9\n1 1 1 1 1 1 1 1 1", "output": "9" }, { "input": "11\n1 1 1 1 1 1 1 1 1 1 1", "output": "11" }, { "input": "8\n1 2 3 4 5 6 7 8", "output": "1" }, { "input": "8\n1 1 1 1 1 1 1 1", "output": "8" }, { "input": "5\n1 1 1 1 1", "output": "5" } ]
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 19 17 15 14 11 20 2", "output": "16" }, { "input": "aaaaaaaadbaaabbbbbddaaabdadbbbbbdbbabbbabaabdbbdababbbddddbdaabbddbbbbabbbbbabadaadabaaaadbbabbbaddb\naaaaaaaaaaaaaa\n61 52 5 43 53 81 7 96 6 9 34 78 79 12 8 63 22 76 18 46 41 56 3 20 57 21 75 73 100 94 35 69 32 4 70 95 88 44 68 10 71 98 23 89 36 62 28 51 24 30 74 55 27 80 38 48 93 1 19 84 13 11 86 60 87 33 39 29 83 91 67 72 54 2 17 85 82 14 15 90 64 50 99 26 66 65 31 49 40 45 77 37 25 42 97 47 58 92 59 16", "output": "57" } ]
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", "output": "6" }, { "input": "2 400 23 57", "output": "1" }, { "input": "1 1 1 1", "output": "1" }, { "input": "10000 10000 3 2", "output": "16670000" }, { "input": "1 2 1 2", "output": "1" }, { "input": "1 1 2 2", "output": "1" }, { "input": "1 1 10 10", "output": "1" }, { "input": "5324 5439 32 13", "output": "69622" }, { "input": "9000 1 2432 1", "output": "9000" }, { "input": "230 1234 9124 23", "output": "10" }, { "input": "11 1 1 1", "output": "11" }, { "input": "6246 8489 1227 9", "output": "4858" }, { "input": "9 20 5 7", "output": "6" } ]
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\n0 1\n1 0\n1 0", "output": "2" }, { "input": "3\n0 0\n0 0\n0 0", "output": "0" }, { "input": "3\n0 1000\n1000 1000\n1000 0", "output": "1000" }, { "input": "5\n0 73\n73 189\n189 766\n766 0\n0 0", "output": "766" }, { "input": "5\n0 0\n0 0\n0 0\n0 1\n1 0", "output": "1" }, { "input": "5\n0 917\n917 923\n904 992\n1000 0\n11 0", "output": "1011" }, { "input": "5\n0 1\n1 2\n2 1\n1 2\n2 0", "output": "2" }, { "input": "5\n0 0\n0 0\n0 0\n0 0\n0 0", "output": "0" }, { "input": "20\n0 7\n2 1\n2 2\n5 7\n2 6\n6 10\n2 4\n0 4\n7 4\n8 0\n10 6\n2 1\n6 1\n1 7\n0 3\n8 7\n6 3\n6 3\n1 1\n3 0", "output": "22" }, { "input": "5\n0 1000\n1000 1000\n1000 1000\n1000 1000\n1000 0", "output": "1000" }, { "input": "10\n0 592\n258 598\n389 203\n249 836\n196 635\n478 482\n994 987\n1000 0\n769 0\n0 0", "output": "1776" }, { "input": "10\n0 1\n1 0\n0 0\n0 0\n0 0\n0 1\n1 1\n0 1\n1 0\n1 0", "output": "2" }, { "input": "10\n0 926\n926 938\n938 931\n931 964\n937 989\n983 936\n908 949\n997 932\n945 988\n988 0", "output": "1016" }, { "input": "10\n0 1\n1 2\n1 2\n2 2\n2 2\n2 2\n1 1\n1 1\n2 1\n2 0", "output": "3" }, { "input": "10\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0", "output": "0" }, { "input": "10\n0 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 0", "output": "1000" }, { "input": "50\n0 332\n332 268\n268 56\n56 711\n420 180\n160 834\n149 341\n373 777\n763 93\n994 407\n86 803\n700 132\n471 608\n429 467\n75 5\n638 305\n405 853\n316 478\n643 163\n18 131\n648 241\n241 766\n316 847\n640 380\n923 759\n789 41\n125 421\n421 9\n9 388\n388 829\n408 108\n462 856\n816 411\n518 688\n290 7\n405 912\n397 772\n396 652\n394 146\n27 648\n462 617\n514 433\n780 35\n710 705\n460 390\n194 508\n643 56\n172 469\n1000 0\n194 0", "output": "2071" }, { "input": "50\n0 0\n0 1\n1 1\n0 1\n0 0\n1 0\n0 0\n1 0\n0 0\n0 0\n0 0\n0 0\n0 1\n0 0\n0 0\n0 1\n1 0\n0 1\n0 0\n1 1\n1 0\n0 1\n0 0\n1 1\n0 1\n1 0\n1 1\n1 0\n0 0\n1 1\n1 0\n0 1\n0 0\n0 1\n1 1\n1 1\n1 1\n1 0\n1 1\n1 0\n0 1\n1 0\n0 0\n0 1\n1 1\n1 1\n0 1\n0 0\n1 0\n1 0", "output": "3" }, { "input": "50\n0 926\n926 971\n915 980\n920 965\n954 944\n928 952\n955 980\n916 980\n906 935\n944 913\n905 923\n912 922\n965 934\n912 900\n946 930\n931 983\n979 905\n925 969\n924 926\n910 914\n921 977\n934 979\n962 986\n942 909\n976 903\n982 982\n991 941\n954 929\n902 980\n947 983\n919 924\n917 943\n916 905\n907 913\n964 977\n984 904\n905 999\n950 970\n986 906\n993 970\n960 994\n963 983\n918 986\n980 900\n931 986\n993 997\n941 909\n907 909\n1000 0\n278 0", "output": "1329" }, { "input": "2\n0 863\n863 0", "output": "863" }, { "input": "50\n0 1\n1 2\n2 2\n1 1\n1 1\n1 2\n1 2\n1 1\n1 2\n1 1\n1 1\n1 2\n1 2\n1 1\n2 1\n2 2\n1 2\n2 2\n1 2\n2 1\n2 1\n2 2\n2 1\n1 2\n1 2\n2 1\n1 1\n2 2\n1 1\n2 1\n2 2\n2 1\n1 2\n2 2\n1 2\n1 1\n1 1\n2 1\n2 1\n2 2\n2 1\n2 1\n1 2\n1 2\n1 2\n1 2\n2 0\n2 0\n2 0\n0 0", "output": "8" }, { "input": "50\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0", "output": "0" }, { "input": "100\n0 1\n0 0\n0 0\n1 0\n0 0\n0 1\n0 1\n1 1\n0 0\n0 0\n1 1\n0 0\n1 1\n0 1\n1 1\n0 1\n1 1\n1 0\n1 0\n0 0\n1 0\n0 1\n1 0\n0 0\n0 0\n1 1\n1 1\n0 1\n0 0\n1 0\n1 1\n0 1\n1 0\n1 1\n0 1\n1 1\n1 0\n0 0\n0 0\n0 1\n0 0\n0 1\n1 1\n0 0\n1 1\n1 1\n0 0\n0 1\n1 0\n0 1\n0 0\n0 1\n0 1\n1 1\n1 1\n1 1\n0 0\n0 0\n1 1\n0 1\n0 1\n1 0\n0 0\n0 0\n1 1\n0 1\n0 1\n1 1\n1 1\n0 1\n1 1\n1 1\n0 0\n1 0\n0 1\n0 0\n0 0\n1 1\n1 1\n1 1\n1 1\n0 1\n1 0\n1 0\n1 0\n1 0\n1 0\n0 0\n1 0\n1 0\n0 0\n1 0\n0 0\n0 1\n1 0\n0 1\n1 0\n1 0\n1 0\n1 0", "output": "11" }, { "input": "100\n0 2\n1 2\n2 1\n1 2\n1 2\n2 1\n2 2\n1 1\n1 1\n2 1\n1 2\n2 1\n1 2\n2 2\n2 2\n2 2\n1 2\n2 2\n2 1\n1 1\n1 1\n1 1\n2 2\n1 2\n2 2\n1 1\n1 1\n1 1\n1 1\n2 2\n1 2\n2 1\n1 1\n2 2\n1 1\n2 1\n1 1\n2 2\n2 1\n1 2\n1 1\n1 2\n2 1\n2 2\n1 1\n2 1\n1 1\n2 1\n1 1\n1 2\n2 2\n2 2\n1 1\n2 2\n1 2\n2 1\n2 1\n1 1\n1 1\n1 2\n1 2\n1 1\n1 1\n2 1\n1 2\n1 2\n2 1\n2 2\n2 2\n2 2\n2 1\n2 2\n1 1\n1 2\n1 2\n1 1\n2 2\n2 2\n1 1\n2 1\n1 1\n1 2\n1 2\n1 2\n1 1\n1 1\n2 2\n1 2\n2 1\n2 1\n2 1\n1 2\n1 2\n1 1\n2 2\n1 2\n2 0\n2 0\n2 0\n1 0", "output": "7" }, { "input": "100\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0", "output": "0" }, { "input": "2\n0 1\n1 0", "output": "1" }, { "input": "2\n0 900\n900 0", "output": "900" }, { "input": "2\n0 1\n1 0", "output": "1" }, { "input": "2\n0 0\n0 0", "output": "0" }, { "input": "2\n0 1000\n1000 0", "output": "1000" }, { "input": "3\n0 802\n175 188\n815 0", "output": "815" }, { "input": "3\n0 910\n910 976\n976 0", "output": "976" }, { "input": "3\n0 2\n2 1\n1 0", "output": "2" } ]
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" }, { "input": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz", "output": "1" }, { "input": "xyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxy", "output": "2" }, { "input": "y", "output": "1" }, { "input": "ervbfotfedpozygoumbmxeaqegouaqqzqerlykhmvxvvlcaos", "output": "49" }, { "input": "zyzzzyyzyyyzyyzyzyzyzyzzzyyyzzyzyyzzzzzyyyzzzzyzyy", "output": "50" }, { "input": "zzfyftdezzfyftdezzfyftdezzfyftdezzfyftdezzfyftde", "output": "8" }, { "input": "yehcqdlllqpuxdsaicyjjxiylahgxbygmsopjbxhtimzkashs", "output": "49" }, { "input": "yyyyzzzyzzzyzyzyzyyyyyzzyzyzyyyyyzyzyyyzyzzyyzzzz", "output": "49" }, { "input": "zkqcrhzlzsnwzkqcrhzlzsnwzkqcrhzlzsnwzkqcrhzlzsnw", "output": "12" }, { "input": "xxyxxyxxyxxyxxyxxyxxyxxyxxyxxyxxyxxyxxyxxyxxyxxy", "output": "3" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaab", "output": "25" }, { "input": "aabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaaba", "output": "4" }, { "input": "pqqpqqpqqpqqpqqpqqpqqpqqpqqpqqpqqppqppqppqppqppq", "output": "48" }, { "input": "zxkljaqzxkljaqzxkljaqzxkljaqzxrljaqzxkljaqzxkljaq", "output": "49" }, { "input": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwx", "output": "50" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaz", "output": "50" }, { "input": "abcddcba", "output": "8" }, { "input": "aabaabaabaacaabaabaabaacaabaabaabaacaabaabaabaac", "output": "12" }, { "input": "aabaabcaabaabcdaabaabcaabaabcd", "output": "15" }, { "input": "ababaababaaababaababaaaababaababaaababaababaaaa", "output": "47" }, { "input": "ababaababaaababaababaaaababaababaaababaababaaa", "output": "23" }, { "input": "aaababaab", "output": "9" }, { "input": "aba", "output": "3" } ]
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 81 2 67 52\n2\n2 40\n6 51", "output": "87\n0\n23\n28\n141\n0\n86\n2\n67\n52" }, { "input": "2\n72 45\n6\n1 69\n2 41\n1 19\n2 7\n1 5\n2 1", "output": "0\n0" }, { "input": "10\n95 54 36 39 98 30 19 24 14 12\n3\n9 5\n8 15\n7 5", "output": "95\n54\n36\n39\n98\n34\n0\n28\n13\n21" }, { "input": "100\n95 15 25 18 64 62 23 59 70 84 50 26 87 35 75 86 0 22 77 60 66 41 21 9 75 50 25 3 69 14 39 68 64 46 59 99 2 0 21 76 90 12 61 42 6 91 36 39 47 41 93 81 66 57 70 36 68 89 52 1 19 93 67 22 76 20 8 81 98 18 100 73 61 93 75 80 53 72 40 20 2 86 33 59 27 16 11 26 55 44 47 55 94 58 2 55 82 22 9 95\n0", "output": "95\n15\n25\n18\n64\n62\n23\n59\n70\n84\n50\n26\n87\n35\n75\n86\n0\n22\n77\n60\n66\n41\n21\n9\n75\n50\n25\n3\n69\n14\n39\n68\n64\n46\n59\n99\n2\n0\n21\n76\n90\n12\n61\n42\n6\n91\n36\n39\n47\n41\n93\n81\n66\n57\n70\n36\n68\n89\n52\n1\n19\n93\n67\n22\n76\n20\n8\n81\n98\n18\n100\n73\n61\n93\n75\n80\n53\n72\n40\n20\n2\n86\n33\n59\n27\n16\n11\n26\n55\n44\n47\n55\n94\n58\n2\n55\n82\n22\n9\n95" }, { "input": "1\n100\n1\n1 100", "output": "0" }, { "input": "1\n100\n1\n1 1", "output": "0" }, { "input": "1\n50\n1\n1 25", "output": "0" }, { "input": "2\n50 0\n1\n1 1", "output": "0\n49" }, { "input": "1\n10\n0", "output": "10" } ]
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 5 5 0 0 5 5 5 5", "output": "0" }, { "input": "23\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 0 0 0 0 0", "output": "55555555555555555500000" }, { "input": "9\n5 5 5 5 5 5 5 5 5", "output": "-1" }, { "input": "24\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 0 0 0 0 0", "output": "55555555555555555500000" }, { "input": "10\n0 0 0 0 0 0 0 0 0 0", "output": "0" }, { "input": "10\n5 5 5 5 5 0 0 5 0 5", "output": "0" }, { "input": "3\n5 5 0", "output": "0" }, { "input": "5\n5 5 0 5 5", "output": "0" }, { "input": "14\n0 5 5 0 0 0 0 0 0 5 5 5 5 5", "output": "0" }, { "input": "3\n5 5 5", "output": "-1" }, { "input": "3\n0 5 5", "output": "0" }, { "input": "13\n0 0 5 0 5 0 5 5 0 0 0 0 0", "output": "0" }, { "input": "9\n5 5 0 5 5 5 5 5 5", "output": "0" }, { "input": "8\n0 0 0 0 0 0 0 0", "output": "0" }, { "input": "101\n5 0 0 0 0 0 0 0 5 0 0 0 0 5 0 0 5 0 0 0 0 0 5 0 0 0 0 0 0 0 0 5 0 0 5 0 0 0 0 0 0 0 5 0 0 5 0 0 0 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5 0 0 0 0 0 0 0 0 0 0 5 0 0 0 0 5 0 0 0 0 0 0 0 0 0 5 0 0 5 0 0 0 0 5 0 0", "output": "5555555550000000000000000000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "214\n5 0 5 0 5 0 0 0 5 5 0 5 0 5 5 0 5 0 0 0 0 5 5 0 0 5 5 0 0 0 0 5 5 5 5 0 5 0 0 0 0 0 0 5 0 0 0 5 0 0 5 0 0 5 5 0 0 5 5 0 0 0 0 0 5 0 5 0 5 5 0 5 0 0 5 5 5 0 5 0 5 0 5 5 0 5 0 0 0 5 5 0 5 0 5 5 5 5 5 0 0 0 0 0 0 5 0 5 5 0 5 0 5 0 5 5 0 0 0 0 5 0 5 0 5 0 0 5 0 0 5 5 5 5 5 0 0 5 0 0 5 0 0 5 0 0 5 0 0 5 0 5 0 0 0 5 0 0 5 5 5 0 0 5 5 5 0 0 5 5 0 0 0 5 0 0 5 5 5 5 5 5 0 5 0 0 5 5 5 5 0 5 5 0 0 0 5 5 5 5 0 0 0 0 5 0 0 5 0 0 5 5 0 0", "output": "5555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555550000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "80\n0 0 0 0 5 0 5 5 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5 0 0 5 0 0 0 0 0 0 0 0 0 5 5 0 5 0 0 0 0 0 0 5 0 0 0 0 0 0 0 5 0 0 0 0 5 0 5 5 0 0 0", "output": "555555555000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "2\n0 0", "output": "0" }, { "input": "3\n5 0 0", "output": "0" }, { "input": "4\n5 5 5 5", "output": "-1" }, { "input": "2\n0 5", "output": "0" }, { "input": "14\n5 5 5 5 5 5 5 5 5 5 5 5 5 0", "output": "5555555550" }, { "input": "18\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5", "output": "-1" }, { "input": "10\n5 5 5 5 5 5 5 5 5 0", "output": "5555555550" }, { "input": "10\n5 5 5 5 5 5 5 5 5 5", "output": "-1" }, { "input": "20\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5", "output": "-1" } ]
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", "output": "0" }, { "input": "8 8", "output": "13" }, { "input": "7 2", "output": "7" }, { "input": "24 15", "output": "36" }, { "input": "19 30", "output": "47" }, { "input": "15 31", "output": "44" }, { "input": "14 15", "output": "27" }, { "input": "58 33", "output": "89" }, { "input": "15 25", "output": "38" }, { "input": "59 45", "output": "102" }, { "input": "3 73", "output": "74" }, { "input": "48 1", "output": "47" }, { "input": "100 25", "output": "122" }, { "input": "40 49", "output": "86" }, { "input": "85 73", "output": "155" }, { "input": "29 1", "output": "28" }, { "input": "74 25", "output": "97" }, { "input": "24 57", "output": "78" }, { "input": "23 12", "output": "33" }, { "input": "2 99", "output": "99" }, { "input": "98 2", "output": "97" }, { "input": "2 97", "output": "97" }, { "input": "30 54", "output": "81" }, { "input": "32 53", "output": "82" }, { "input": "32 54", "output": "84" }, { "input": "1 2", "output": "1" }, { "input": "2 1", "output": "1" }, { "input": "2 2", "output": "1" }, { "input": "1 3", "output": "2" }, { "input": "3 1", "output": "2" }, { "input": "1 4", "output": "2" }, { "input": "2 3", "output": "3" }, { "input": "3 2", "output": "3" } ]
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" }, { "input": "2 3", "output": "2 0 4" }, { "input": "5 6", "output": "5 0 1" }, { "input": "4 4", "output": "0 6 0" }, { "input": "1 1", "output": "0 6 0" }, { "input": "6 4", "output": "1 1 4" }, { "input": "1 4", "output": "2 0 4" }, { "input": "5 5", "output": "0 6 0" }, { "input": "4 5", "output": "4 0 2" }, { "input": "4 3", "output": "3 0 3" }, { "input": "1 5", "output": "2 1 3" }, { "input": "6 5", "output": "1 0 5" }, { "input": "2 2", "output": "0 6 0" }, { "input": "1 3", "output": "1 1 4" }, { "input": "3 6", "output": "4 0 2" }, { "input": "3 1", "output": "4 1 1" }, { "input": "3 2", "output": "4 0 2" }, { "input": "3 5", "output": "3 1 2" }, { "input": "3 3", "output": "0 6 0" }, { "input": "6 2", "output": "2 1 3" }, { "input": "4 1", "output": "4 0 2" }, { "input": "5 2", "output": "3 0 3" }, { "input": "4 2", "output": "3 1 2" }, { "input": "2 1", "output": "5 0 1" }, { "input": "6 1", "output": "3 0 3" }, { "input": "4 6", "output": "4 1 1" }, { "input": "2 6", "output": "3 1 2" }, { "input": "3 4", "output": "3 0 3" }, { "input": "1 2", "output": "1 0 5" }, { "input": "6 6", "output": "0 6 0" }, { "input": "5 4", "output": "2 0 4" }, { "input": "3 3", "output": "0 6 0" }, { "input": "1 1", "output": "0 6 0" } ]
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" }, { "input": "70 38 66", "output": "9" }, { "input": "54 4 38", "output": "17" }, { "input": "3 1 69", "output": "2" }, { "input": "11 9 60", "output": "0" }, { "input": "71 49 65", "output": "0" }, { "input": "78 55 96", "output": "20" }, { "input": "2765 768 9020", "output": "248635" }, { "input": "3478 1728 9727", "output": "336578" }, { "input": "9678 6173 5658", "output": "541409" }, { "input": "1138 570 6666", "output": "75290" }, { "input": "7754 204 9038", "output": "700603" }, { "input": "8403 7401 4769", "output": "393339" }, { "input": "4909 2111 8860", "output": "432827" }, { "input": "6571 6449 8965", "output": "582642" }, { "input": "9178 2255 7996", "output": "731618" }, { "input": "6151 6148 3746", "output": "224269" }, { "input": "8890 5449 8734", "output": "771004" }, { "input": "7879 2590 2818", "output": "219441" }, { "input": "8484 6400 547", "output": "40008" }, { "input": "7835 6710 1639", "output": "121706" }, { "input": "2379 1436 9663", "output": "228447" }, { "input": "6487 5670 8", "output": "0" }, { "input": "4470 2543 6", "output": "0" }, { "input": "7261 5328 10", "output": "0" }, { "input": "3871 3795 7", "output": "0" }, { "input": "9620 6557 6", "output": "0" }, { "input": "4890 1112 5", "output": "0" }, { "input": "1 1 1", "output": "0" }, { "input": "1 1 10000", "output": "99" }, { "input": "10000 1 1", "output": "99" }, { "input": "10000 1 10000", "output": "999999" }, { "input": "10000 10000 1", "output": "0" }, { "input": "10000 10000 10000", "output": "990000" }, { "input": "67 1 3", "output": "2" }, { "input": "7878 4534 9159", "output": "717013" }, { "input": "1 1 1", "output": "0" }, { "input": "3271 5 50", "output": "1631" } ]
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" }, { "input": "< ^\n1", "output": "cw" }, { "input": "v <\n422435957", "output": "cw" }, { "input": "v >\n139018901", "output": "ccw" }, { "input": "v ^\n571728018", "output": "undefined" }, { "input": "^ ^\n0", "output": "undefined" }, { "input": "< >\n2", "output": "undefined" }, { "input": "> >\n1000000000", "output": "undefined" }, { "input": "v v\n8", "output": "undefined" }, { "input": "< <\n1568", "output": "undefined" }, { "input": "^ v\n2", "output": "undefined" }, { "input": "^ <\n1", "output": "ccw" }, { "input": "< v\n1", "output": "ccw" }, { "input": "v >\n1", "output": "ccw" }, { "input": "> ^\n1", "output": "ccw" }, { "input": "v <\n422435957", "output": "cw" }, { "input": "v v\n927162384", "output": "undefined" }, { "input": "v ^\n571728018", "output": "undefined" }, { "input": "^ <\n467441155", "output": "cw" }, { "input": "^ >\n822875521", "output": "cw" }, { "input": "^ <\n821690113", "output": "ccw" }, { "input": "^ <\n171288453", "output": "ccw" }, { "input": "^ <\n110821381", "output": "ccw" }, { "input": "^ ^\n539580280", "output": "undefined" }, { "input": "^ >\n861895563", "output": "ccw" }, { "input": "v v\n4", "output": "undefined" }, { "input": "^ ^\n4", "output": "undefined" }, { "input": "> >\n4", "output": "undefined" }, { "input": "< <\n8", "output": "undefined" }, { "input": "v v\n0", "output": "undefined" }, { "input": "^ <\n11", "output": "cw" }, { "input": "< <\n4", "output": "undefined" }, { "input": "< <\n0", "output": "undefined" }, { "input": "< v\n3", "output": "cw" }, { "input": "^ <\n3", "output": "cw" }, { "input": "^ <\n7", "output": "cw" }, { "input": "< >\n6", "output": "undefined" }, { "input": "v >\n3", "output": "cw" }, { "input": "> >\n300", "output": "undefined" }, { "input": "> >\n0", "output": "undefined" }, { "input": "v <\n3", "output": "ccw" }, { "input": "> >\n12", "output": "undefined" } ]
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" }, { "input": "680 1091", "output": "351905328" }, { "input": "1229 1315", "output": "100240813" }, { "input": "1766 1038", "output": "435768250" }, { "input": "1000 1", "output": "1000" }, { "input": "2000 100", "output": "983281065" }, { "input": "1 1", "output": "1" }, { "input": "2000 1000", "output": "228299266" }, { "input": "1928 1504", "output": "81660104" }, { "input": "2000 2000", "output": "585712681" }, { "input": "29 99", "output": "23125873" }, { "input": "56 48", "output": "20742237" }, { "input": "209 370", "output": "804680894" }, { "input": "83 37", "output": "22793555" }, { "input": "49 110", "output": "956247348" }, { "input": "217 3", "output": "4131" }, { "input": "162 161", "output": "591739753" }, { "input": "273 871", "output": "151578252" }, { "input": "43 1640", "output": "173064407" }, { "input": "1472 854", "output": "748682383" }, { "input": "1639 1056", "output": "467464129" }, { "input": "359 896", "output": "770361185" }, { "input": "1544 648", "output": "9278889" }, { "input": "436 1302", "output": "874366220" }, { "input": "1858 743", "output": "785912917" }, { "input": "991 1094", "output": "483493131" }, { "input": "1013 1550", "output": "613533467" }, { "input": "675 741", "output": "474968598" }, { "input": "1420 1223", "output": "922677437" }, { "input": "1544 1794", "output": "933285446" }, { "input": "1903 1612", "output": "620810276" }, { "input": "500 1304", "output": "706176027" }, { "input": "525 314", "output": "245394744" }, { "input": "39 1930", "output": "992125404" }, { "input": "1895 753", "output": "180474828" }, { "input": "1722 1474", "output": "742424590" }, { "input": "1153 1823", "output": "791493066" }, { "input": "1409 734", "output": "627413973" }, { "input": "478 1301", "output": "476483030" }, { "input": "1887 1729", "output": "730033374" }, { "input": "1610 774", "output": "50897314" }, { "input": "1770 679", "output": "235295539" }, { "input": "987 1292", "output": "560110556" }, { "input": "1707 1117", "output": "237674323" }, { "input": "1424 1431", "output": "184145444" }, { "input": "86 1078", "output": "252515343" }, { "input": "1066 995", "output": "180753612" }, { "input": "1024 133", "output": "392603027" }, { "input": "659 974", "output": "397026719" }, { "input": "1349 1606", "output": "522392901" }, { "input": "473 211", "output": "809550224" }, { "input": "634 1825", "output": "438513382" }, { "input": "22 373", "output": "907321755" }, { "input": "531 147", "output": "242883376" }, { "input": "1307 1247", "output": "21512331" }, { "input": "415 735", "output": "393705804" }, { "input": "1659 1501", "output": "225266660" }, { "input": "1454 296", "output": "750032659" }, { "input": "158 772", "output": "850911301" }, { "input": "2000 1", "output": "2000" } ]
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", "output": "1" }, { "input": "2 3 4", "output": "1" }, { "input": "1000000000 1000000000 1", "output": "1000000000000000000" }, { "input": "12 13 4", "output": "12" }, { "input": "222 332 5", "output": "3015" }, { "input": "1000 1000 10", "output": "10000" }, { "input": "1001 1000 10", "output": "10100" }, { "input": "100 10001 1000000000", "output": "1" }, { "input": "1000000000 1000000000 1000000000", "output": "1" }, { "input": "1000000000 1000000000 999999999", "output": "4" }, { "input": "1000000000 1000000000 192", "output": "27126743055556" }, { "input": "1000000000 987654321 1", "output": "987654321000000000" }, { "input": "456784567 1000000000 51", "output": "175618850864484" }, { "input": "39916800 134217728 40320", "output": "3295710" } ]
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" }, { "input": "5 12\n- 12\n+ 7\n- 6\n- 1\n+ 46", "output": "46 0" }, { "input": "11 1000\n- 100\n+ 100\n+ 100\n+ 100\n+ 100\n- 100\n- 100\n- 100\n- 100\n- 100\n- 100", "output": "700 0" }, { "input": "1 0\n- 526403222", "output": "0 1" }, { "input": "1 897986543\n- 371188251", "output": "526798292 0" }, { "input": "1 0\n+ 1", "output": "1 0" }, { "input": "1 0\n- 1", "output": "0 1" }, { "input": "1 10\n+ 10", "output": "20 0" }, { "input": "1 3\n- 5", "output": "3 1" }, { "input": "1 0\n- 5", "output": "0 1" }, { "input": "1 0\n+ 5", "output": "5 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" }, { "input": "5\n7 36 53 81 100", "output": "4" }, { "input": "5\n100 81 53 36 7", "output": "4" }, { "input": "10\n8 6 3 4 9 10 7 7 1 3", "output": "5" }, { "input": "10\n1627 1675 1488 1390 1812 1137 1746 1324 1952 1862", "output": "6" }, { "input": "10\n1 3 3 4 6 7 7 8 9 10", "output": "7" }, { "input": "10\n1952 1862 1812 1746 1675 1627 1488 1390 1324 1137", "output": "9" }, { "input": "25\n1448 4549 2310 2725 2091 3509 1565 2475 2232 3989 4231 779 2967 2702 608 3739 721 1552 2767 530 3114 665 1940 48 4198", "output": "5" }, { "input": "33\n1097 1132 1091 1104 1049 1038 1023 1080 1104 1029 1035 1061 1049 1060 1088 1106 1105 1087 1063 1076 1054 1103 1047 1041 1028 1120 1126 1063 1117 1110 1044 1093 1101", "output": "5" }, { "input": "34\n821 5536 2491 6074 7216 9885 764 1603 778 8736 8987 771 617 1587 8943 7922 439 7367 4115 8886 7878 6899 8811 5752 3184 3401 9760 9400 8995 4681 1323 6637 6554 6498", "output": "7" }, { "input": "68\n6764 6877 6950 6768 6839 6755 6726 6778 6699 6805 6777 6985 6821 6801 6791 6805 6940 6761 6677 6999 6911 6699 6959 6933 6903 6843 6972 6717 6997 6756 6789 6668 6735 6852 6735 6880 6723 6834 6810 6694 6780 6679 6698 6857 6826 6896 6979 6968 6957 6988 6960 6700 6919 6892 6984 6685 6813 6678 6715 6857 6976 6902 6780 6686 6777 6686 6842 6679", "output": "9" }, { "input": "60\n9000 9014 9034 9081 9131 9162 9174 9199 9202 9220 9221 9223 9229 9235 9251 9260 9268 9269 9270 9298 9307 9309 9313 9323 9386 9399 9407 9495 9497 9529 9531 9544 9614 9615 9627 9627 9643 9654 9656 9657 9685 9699 9701 9736 9745 9758 9799 9827 9843 9845 9854 9854 9885 9891 9896 9913 9942 9963 9986 9992", "output": "57" }, { "input": "100\n7 61 12 52 41 16 34 99 30 44 48 89 31 54 21 1 48 52 61 15 35 87 21 76 64 92 44 81 16 93 84 92 32 15 68 76 53 39 26 4 11 26 7 4 99 99 61 65 55 85 65 67 47 39 2 74 63 49 98 87 5 94 22 30 25 42 31 84 49 23 89 60 16 26 92 27 9 57 75 61 94 35 83 47 99 100 63 24 91 88 79 10 15 45 22 64 3 11 89 83", "output": "4" }, { "input": "100\n9999 9999 9999 9998 9998 9998 9997 9996 9996 9995 9993 9993 9991 9990 9989 9986 9984 9984 9983 9981 9981 9980 9980 9980 9979 9977 9977 9977 9977 9977 9976 9976 9975 9975 9973 9972 9972 9972 9972 9971 9969 9969 9969 9968 9967 9965 9962 9962 9962 9962 9960 9958 9958 9955 9954 9954 9954 9954 9950 9949 9949 9947 9943 9943 9940 9940 9939 9937 9937 9937 9936 9935 9932 9932 9931 9929 9927 9927 9926 9923 9919 9919 9918 9918 9918 9917 9917 9916 9916 9915 9914 9911 9910 9907 9907 9906 9905 9905 9904 9901", "output": "57" }, { "input": "100\n158 159 157 156 155 154 160 153 161 152 162 163 151 164 150 165 149 148 147 166 146 167 145 144 143 142 168 141 169 170 140 139 138 137 171 136 135 134 172 173 174 133 175 132 177 178 131 179 180 130 129 181 128 127 182 126 183 125 124 184 123 122 121 120 119 118 117 185 186 187 188 189 116 190 115 191 192 193 114 113 112 111 110 109 108 194 195 107 106 105 196 197 104 198 199 103 102 200 101 100", "output": "99" }, { "input": "2\n0 10000", "output": "1" }, { "input": "2\n5 5", "output": "0" }, { "input": "2\n1 1", "output": "0" }, { "input": "2\n10 10", "output": "0" }, { "input": "1\n0", "output": "0" } ]
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\n7\n9\n10\n8\n4\n2\n1" }, { "input": "rlrrrllrrr", "output": "1\n3\n4\n5\n8\n9\n10\n7\n6\n2" }, { "input": "lrrlrrllrrrrllllllrr", "output": "2\n3\n5\n6\n9\n10\n11\n12\n19\n20\n18\n17\n16\n15\n14\n13\n8\n7\n4\n1" }, { "input": "rlrrrlrrrllrrllrlrll", "output": "1\n3\n4\n5\n7\n8\n9\n12\n13\n16\n18\n20\n19\n17\n15\n14\n11\n10\n6\n2" }, { "input": "lllrrlrlrllrrrrrllrl", "output": "4\n5\n7\n9\n12\n13\n14\n15\n16\n19\n20\n18\n17\n11\n10\n8\n6\n3\n2\n1" }, { "input": "rrrllrrrlllrlllrlrrr", "output": "1\n2\n3\n6\n7\n8\n12\n16\n18\n19\n20\n17\n15\n14\n13\n11\n10\n9\n5\n4" }, { "input": "rrlllrrrlrrlrrrlllrlrlrrrlllrllrrllrllrrlrlrrllllrlrrrrlrlllrlrrrlrlrllrlrlrrlrrllrrrlrlrlllrrllllrl", "output": "1\n2\n6\n7\n8\n10\n11\n13\n14\n15\n19\n21\n23\n24\n25\n29\n32\n33\n36\n39\n40\n42\n44\n45\n50\n52\n53\n54\n55\n57\n61\n63\n64\n65\n67\n69\n72\n74\n76\n77\n79\n80\n83\n84\n85\n87\n89\n93\n94\n99\n100\n98\n97\n96\n95\n92\n91\n90\n88\n86\n82\n81\n78\n75\n73\n71\n70\n68\n66\n62\n60\n59\n58\n56\n51\n49\n48\n47\n46\n43\n41\n38\n37\n35\n34\n31\n30\n28\n27\n26\n22\n20\n18\n17\n16\n12\n9\n5\n4\n3" }, { "input": "llrlrlllrrllrllllrlrrlrlrrllrlrlrrlrrrrrrlllrrlrrrrrlrrrlrlrlrrlllllrrrrllrrlrlrrrllllrlrrlrrlrlrrll", "output": "3\n5\n9\n10\n13\n18\n20\n21\n23\n25\n26\n29\n31\n33\n34\n36\n37\n38\n39\n40\n41\n45\n46\n48\n49\n50\n51\n52\n54\n55\n56\n58\n60\n62\n63\n69\n70\n71\n72\n75\n76\n78\n80\n81\n82\n87\n89\n90\n92\n93\n95\n97\n98\n100\n99\n96\n94\n91\n88\n86\n85\n84\n83\n79\n77\n74\n73\n68\n67\n66\n65\n64\n61\n59\n57\n53\n47\n44\n43\n42\n35\n32\n30\n28\n27\n24\n22\n19\n17\n16\n15\n14\n12\n11\n8\n7\n6\n4\n2\n1" }, { "input": "llrrrrllrrlllrlrllrlrllllllrrrrrrrrllrrrrrrllrlrrrlllrrrrrrlllllllrrlrrllrrrllllrrlllrrrlrlrrlrlrllr", "output": "3\n4\n5\n6\n9\n10\n14\n16\n19\n21\n28\n29\n30\n31\n32\n33\n34\n35\n38\n39\n40\n41\n42\n43\n46\n48\n49\n50\n54\n55\n56\n57\n58\n59\n67\n68\n70\n71\n74\n75\n76\n81\n82\n86\n87\n88\n90\n92\n93\n95\n97\n100\n99\n98\n96\n94\n91\n89\n85\n84\n83\n80\n79\n78\n77\n73\n72\n69\n66\n65\n64\n63\n62\n61\n60\n53\n52\n51\n47\n45\n44\n37\n36\n27\n26\n25\n24\n23\n22\n20\n18\n17\n15\n13\n12\n11\n8\n7\n2\n1" }, { "input": "lllllrllrrlllrrrllrrrrlrrlrllllrrrrrllrlrllllllrrlrllrlrllrlrrlrlrrlrrrlrrrrllrlrrrrrrrllrllrrlrllrl", "output": "6\n9\n10\n14\n15\n16\n19\n20\n21\n22\n24\n25\n27\n32\n33\n34\n35\n36\n39\n41\n48\n49\n51\n54\n56\n59\n61\n62\n64\n66\n67\n69\n70\n71\n73\n74\n75\n76\n79\n81\n82\n83\n84\n85\n86\n87\n90\n93\n94\n96\n99\n100\n98\n97\n95\n92\n91\n89\n88\n80\n78\n77\n72\n68\n65\n63\n60\n58\n57\n55\n53\n52\n50\n47\n46\n45\n44\n43\n42\n40\n38\n37\n31\n30\n29\n28\n26\n23\n18\n17\n13\n12\n11\n8\n7\n5\n4\n3\n2\n1" }, { "input": "llrlrlrlrlrlrrlllllllrllllrllrrrlllrrllrllrrlllrrlllrlrrllllrrlllrrllrrllllrrlllrlllrrrllrrrrrrllrrl", "output": "3\n5\n7\n9\n11\n13\n14\n22\n27\n30\n31\n32\n36\n37\n40\n43\n44\n48\n49\n53\n55\n56\n61\n62\n66\n67\n70\n71\n76\n77\n81\n85\n86\n87\n90\n91\n92\n93\n94\n95\n98\n99\n100\n97\n96\n89\n88\n84\n83\n82\n80\n79\n78\n75\n74\n73\n72\n69\n68\n65\n64\n63\n60\n59\n58\n57\n54\n52\n51\n50\n47\n46\n45\n42\n41\n39\n38\n35\n34\n33\n29\n28\n26\n25\n24\n23\n21\n20\n19\n18\n17\n16\n15\n12\n10\n8\n6\n4\n2\n1" }, { "input": "l", "output": "1" }, { "input": "r", "output": "1" } ]
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\n1 2 2 2 4 5 6 7 8 10", "output": "376" }, { "input": "10\n161821 171308 228496 397870 431255 542924 718337 724672 888642 892002", "output": "40204082" }, { "input": "1\n397870", "output": "397870" }, { "input": "1\n1000000", "output": "1000000" }, { "input": "10\n10 8 7 6 5 4 2 2 2 1", "output": "376" }, { "input": "10\n892002 888642 724672 718337 542924 431255 397870 228496 171308 161821", "output": "40204082" }, { "input": "10\n5 2 6 10 10 10 10 2 2 5", "output": "485" }, { "input": "10\n431255 724672 228496 397870 397870 397870 397870 724672 888642 431255", "output": "36742665" }, { "input": "10\n2 2 2 5 5 6 10 10 10 10", "output": "485" }, { "input": "10\n228496 397870 397870 397870 397870 431255 431255 724672 724672 888642", "output": "36742665" }, { "input": "10\n10 10 10 10 6 5 5 2 2 2", "output": "485" }, { "input": "10\n888642 724672 724672 431255 431255 397870 397870 397870 397870 228496", "output": "36742665" }, { "input": "10\n10 10 10 10 10 10 10 10 10 10", "output": "640" }, { "input": "10\n1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000", "output": "64000000" }, { "input": "1\n397870", "output": "397870" }, { "input": "2\n1 2", "output": "6" }, { "input": "2\n2 3", "output": "10" }, { "input": "2\n1 1", "output": "4" } ]
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" }, { "input": "n", "output": "YES" }, { "input": "necnei", "output": "NO" }, { "input": "nternn", "output": "NO" }, { "input": "aucunuohja", "output": "NO" }, { "input": "a", "output": "YES" }, { "input": "b", "output": "NO" }, { "input": "nn", "output": "YES" }, { "input": "nnnzaaa", "output": "YES" }, { "input": "zn", "output": "NO" }, { "input": "ab", "output": "NO" }, { "input": "aaaaaaaaaa", "output": "YES" }, { "input": "aaaaaaaaab", "output": "NO" }, { "input": "aaaaaaaaan", "output": "YES" }, { "input": "baaaaaaaaa", "output": "YES" }, { "input": "naaaaaaaaa", "output": "YES" }, { "input": "nbaaaaaaaa", "output": "YES" }, { "input": "bbaaaaaaaa", "output": "NO" }, { "input": "bnaaaaaaaa", "output": "NO" }, { "input": "eonwonojannonnufimiiniewuqaienokacevecinfuqihatenhunliquuyebayiaenifuexuanenuaounnboancaeowonu", "output": "YES" }, { "input": "uixinnepnlinqaingieianndeakuniooudidonnnqeaituioeneiroionxuowudiooonayenfeonuino", "output": "NO" }, { "input": "nnnnnyigaveteononnnnxaalenxuiiwannntoxonyoqonlejuoxuoconnnentoinnul", "output": "NO" }, { "input": "ndonneasoiunhomuunnhuitonnntunntoanerekonoupunanuauenu", "output": "YES" }, { "input": "anujemogawautiedoneobninnibonuunaoennnyoorufonxionntinimiboonununnnnnleenqunminzayoutanlalo", "output": "NO" }, { "input": "y", "output": "NO" }, { "input": "by", "output": "NO" }, { "input": "yy", "output": "NO" }, { "input": "nbn", "output": "NO" }, { "input": "nz", "output": "NO" }, { "input": "king", "output": "NO" }, { "input": "g", "output": "NO" }, { "input": "az", "output": "NO" }, { "input": "x", "output": "NO" }, { "input": "z", "output": "NO" }, { "input": "yn", "output": "NO" }, { "input": "aeo", "output": "YES" }, { "input": "nb", "output": "NO" }, { "input": "npn", "output": "NO" }, { "input": "kini", "output": "YES" }, { "input": "pya", "output": "NO" }, { "input": "m", "output": "NO" }, { "input": "p", "output": "NO" }, { "input": "aaaaaaaak", "output": "NO" }, { "input": "aab", "output": "NO" }, { "input": "d", "output": "NO" }, { "input": "at", "output": "NO" }, { "input": "aaaaaak", "output": "NO" }, { "input": "aaz", "output": "NO" }, { "input": "aaab", "output": "NO" }, { "input": "s", "output": "NO" }, { "input": "nzzen", "output": "NO" }, { "input": "aeionnhhhn", "output": "NO" }, { "input": "h", "output": "NO" }, { "input": "ny", "output": "NO" } ]
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 15 48 38 26 25 14 20 44 11 30 3 42 49 19 18 46 5 45 10 23 34 9 29 41 2 52 6 17 35 4 50 22 33 51 7 28 47 13 39 37 24", "output": "644 500" }, { "input": "1\n3", "output": "3 0" }, { "input": "45\n553 40 94 225 415 471 126 190 647 394 515 303 189 159 308 6 139 132 326 78 455 75 85 295 135 613 360 614 351 228 578 259 258 591 444 29 33 463 561 174 368 183 140 168 646", "output": "6848 6568" }, { "input": "44\n849 373 112 307 479 608 856 769 526 82 168 143 573 762 115 501 688 36 214 450 396 496 236 309 287 786 397 43 811 141 745 846 350 270 276 677 420 459 403 722 267 54 394 727", "output": "9562 9561" }, { "input": "35\n10 15 18 1 28 16 2 33 6 22 23 4 9 25 35 8 7 26 3 20 30 14 31 19 27 32 11 5 29 24 21 34 13 17 12", "output": "315 315" }, { "input": "17\n580 376 191 496 73 44 520 357 483 149 81 178 514 300 216 598 304", "output": "3238 2222" }, { "input": "30\n334 443 223 424 168 549 189 303 429 559 516 220 459 134 344 346 316 446 209 148 487 526 69 286 102 366 518 280 392 325", "output": "5246 4864" }, { "input": "95\n122 29 188 265 292 287 183 225 222 187 155 256 64 148 173 278 218 136 290 17 31 130 2 87 57 283 255 280 68 166 174 142 102 39 116 206 288 154 26 78 296 172 184 232 77 91 277 8 249 186 94 93 207 251 257 195 101 299 193 124 293 65 58 35 24 302 220 189 252 125 27 284 247 182 141 103 198 97 234 83 281 216 85 180 267 236 109 143 149 239 79 300 191 244 71", "output": "8147 7807" }, { "input": "1\n1", "output": "1 0" } ]
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" }, { "input": "4", "output": "3" }, { "input": "6", "output": "3" }, { "input": "8", "output": "7" }, { "input": "9", "output": "7" }, { "input": "10", "output": "4" }, { "input": "12", "output": "6" }, { "input": "15", "output": "8" }, { "input": "16", "output": "11" }, { "input": "110880", "output": "55440" }, { "input": "166320", "output": "110879" }, { "input": "221760", "output": "110880" }, { "input": "277200", "output": "138600" }, { "input": "332640", "output": "166320" }, { "input": "498960", "output": "332639" }, { "input": "554400", "output": "415798" }, { "input": "665280", "output": "498958" }, { "input": "720720", "output": "540538" }, { "input": "510510", "output": "255248" }, { "input": "570570", "output": "285282" }, { "input": "690690", "output": "460455" }, { "input": "959818", "output": "239958" }, { "input": "959878", "output": "239978" }, { "input": "959902", "output": "239978" }, { "input": "974847", "output": "324954" }, { "input": "974859", "output": "324978" }, { "input": "974931", "output": "324980" }, { "input": "885481", "output": "442272" }, { "input": "896809", "output": "447944" }, { "input": "908209", "output": "453632" }, { "input": "935089", "output": "467064" }, { "input": "720721", "output": "355298" }, { "input": "690691", "output": "342864" }, { "input": "959903", "output": "479702" }, { "input": "974932", "output": "470060" }, { "input": "935090", "output": "463950" }, { "input": "524288", "output": "524287" }, { "input": "524289", "output": "174768" }, { "input": "524286", "output": "262110" }, { "input": "531441", "output": "526737" }, { "input": "531442", "output": "262490" }, { "input": "531440", "output": "265704" }, { "input": "81", "output": "76" }, { "input": "999958", "output": "250008" }, { "input": "2048", "output": "1959" } ]
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\nBBRGRRBBRGGGBGBGBGRRGRGRGRBGRGRRBBGRGBGRRGRRRGGBBRGBGBGBRBBBBBBBGGBRGGRRRGGRGBGBGGBRRRRBRRRBRBBGGBGBRGRGBBBBGGBGBBBGBGRRBRRRGBGGBBBRBGRBRRGGGRRGBBBGBGRRRRRRGGRGRGBBBRGGGBGGGBRBBRRGBGRGRBRRRBRBGRGGBRBB", "output": "BGR" }, { "input": "101\nRRRRRRRRRRRRRRRRRRRBRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR", "output": "BG" }, { "input": "7\nBBBGBRG", "output": "BGR" }, { "input": "5\nGRRGR", "output": "BGR" }, { "input": "3\nGBR", "output": "BGR" }, { "input": "1\nB", "output": "B" }, { "input": "2\nBB", "output": "B" }, { "input": "1\nG", "output": "G" }, { "input": "2\nBG", "output": "R" }, { "input": "3\nBGB", "output": "GR" }, { "input": "2\nGG", "output": "G" }, { "input": "3\nGBG", "output": "BR" }, { "input": "4\nBGBG", "output": "BGR" }, { "input": "1\nR", "output": "R" }, { "input": "2\nBR", "output": "G" }, { "input": "3\nBRB", "output": "GR" }, { "input": "2\nRG", "output": "B" }, { "input": "3\nBGR", "output": "BGR" }, { "input": "4\nRBGB", "output": "BGR" }, { "input": "3\nGGR", "output": "BR" }, { "input": "4\nGGRB", "output": "BGR" }, { "input": "5\nBGBGR", "output": "BGR" }, { "input": "2\nRR", "output": "R" }, { "input": "3\nRBR", "output": "BG" }, { "input": "4\nRRBB", "output": "BGR" }, { "input": "3\nRRG", "output": "BG" }, { "input": "4\nBRRG", "output": "BGR" }, { "input": "5\nRBRBG", "output": "BGR" }, { "input": "4\nRGGR", "output": "BGR" }, { "input": "5\nBRGRG", "output": "BGR" }, { "input": "6\nGRRGBB", "output": "BGR" }, { "input": "150\nGRGBBBBRBGGBGBBGBBBBGRBBRRBBGRRGGGBRBBRGRRRRGBGRRBGBGBGRBBBGBBBGBGBRGBRRRRRGGGRGRBBGBRGGGRBBRGBBGRGGGBBRBRRGRGRRGRRGRRRGBGBRRGGRGGBRBGGGBBBRGRGBRGRRRR", "output": "BGR" }, { "input": "16\nRRGRRRRRRGGRGRRR", "output": "BGR" }, { "input": "190\nBBBBBBBBBBBBBBBBBGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB", "output": "GR" }, { "input": "200\nRGRGRRRRRGRRGRRRGRGRRRGGRGRRGGGRRGGRRRRRRRRRRRGRRGRRRGRRRGRRRRRRRGRRRRRRRRRRRGGRRGGRRRRGGRRRRRRRRRGGGRGRGRGRRGRGGRGRGRRRGRRRRRRGGRGRRRRGRRGRGGRRRRRRRGRGGRRGRRRRRRRGGRRRRGRRRRRRRGRRRGGRRRRRRGRRGGGRRRGR", "output": "BGR" }, { "input": "200\nGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG", "output": "G" }, { "input": "52\nBBBBBBBBBBBBBBBBBBBBGBGBBBBBBBBBBBBBBBBBBBBBBBBBBBBB", "output": "BGR" }, { "input": "200\nGRGRRGRBRRRGGGRGGRRRRRBBGRRGRBBGRRGBGRRBBRBBRRBBBGRBRGGGGBGGBRRBBRGRBGGRRGGBBRBGGRGBBRRBBRGBRRBGBRBGBBRGGRRRGGGBRGGGGRRRBBRRGRGRBRRGRBBGGRBBRGRGRBGRBBRGGBBBGRGBBGGBGBGBBRRBGRGRGGBRRGRGGGGGBRGGGGBBBBRB", "output": "BGR" }, { "input": "102\nGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGRGGGGGGGGBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG", "output": "BGR" }, { "input": "193\nRRRGGGRBGGBGGGBGGBBGRBGGRBGGBBRBGGRBBBRBRRGGBBRBRGRRRBGBBRGGRGGGBGGRRGGRGRRBRBRBRRGRGBGBRGBBRGRRRBGRGGBGBRBBBGBRBBGBGBGGGBGGGGBRBBRRBGRGGBBBRBBBBBGRRRGBRGBRRRBBBGBGGGGRGGRRBRBGRRGBGBRBGGGRBRRGG", "output": "BGR" }, { "input": "90\nBGBGGRRBGGRRRRRGGRGBBBBBRRBGBGBGBGGBBGRGGGGRBRBBRRRGBRRGBBGBBGGGRGRGRBGBBBRRGRRBRBRRGGRBRB", "output": "BGR" }, { "input": "3\nGGB", "output": "BR" } ]
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", "output": "3" }, { "input": "3\n0 53372 -20572", "output": "2" }, { "input": "13\n-2075 -32242 27034 -37618 -96962 82203 64846 48249 -71761 28908 -21222 -61370 46899", "output": "13" }, { "input": "5\n806 0 1308 1954 683", "output": "4" }, { "input": "8\n-26 0 -249 -289 -126 -206 288 -11", "output": "7" }, { "input": "10\n2 2 2 1 2 -1 0 2 -1 1", "output": "3" }, { "input": "1\n8", "output": "1" }, { "input": "3\n0 0 0", "output": "0" }, { "input": "10\n1 2 3 4 5 6 7 8 9 10", "output": "10" }, { "input": "5\n2 0 -1 0 0", "output": "2" }, { "input": "2\n0 0", "output": "0" }, { "input": "5\n0 0 0 0 0", "output": "0" }, { "input": "2\n1 0", "output": "1" }, { "input": "2\n-1 0", "output": "1" }, { "input": "4\n0 0 0 0", "output": "0" }, { "input": "8\n10 9 -1 0 0 3 2 3", "output": "5" }, { "input": "5\n5 0 1 2 3", "output": "4" }, { "input": "3\n1 1 0", "output": "1" }, { "input": "1\n-1", "output": "1" }, { "input": "5\n1 2 0 0 0", "output": "2" }, { "input": "5\n1 0 0 0 0", "output": "1" }, { "input": "5\n4 5 6 0 0", "output": "3" }, { "input": "4\n-1 0 0 1", "output": "2" }, { "input": "5\n3 0 0 4 5", "output": "3" }, { "input": "3\n0 0 2", "output": "1" }, { "input": "3\n1 0 0", "output": "1" }, { "input": "4\n0 0 0 4", "output": "1" }, { "input": "5\n-1 0 0 0 0", "output": "1" }, { "input": "2\n0 1", "output": "1" }, { "input": "3\n1 2 3", "output": "3" }, { "input": "1\n5", "output": "1" }, { "input": "10\n0 0 0 0 0 1 2 3 0 0", "output": "3" }, { "input": "4\n0 1 2 3", "output": "3" }, { "input": "3\n0 1 2", "output": "2" }, { "input": "4\n2 0 0 -1", "output": "2" } ]
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" }, { "input": "1 1\n1000000000 1000000000", "output": "1" }, { "input": "1 1\n1000000000 1", "output": "1000000000" }, { "input": "2 3\n1000000000 1\n2 2", "output": "1000000000" }, { "input": "2 5\n1 7\n1 1000000000", "output": "-1" } ]
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", "output": "804610" }, { "input": "5\n984065 842724 127449 525625 573049", "output": "984065" }, { "input": "2\n226505 477482", "output": "477482" }, { "input": "2\n370881 659345", "output": "659345" }, { "input": "2\n4 5", "output": "5" }, { "input": "2\n3 4", "output": "3" }, { "input": "2\n999999 1000000", "output": "999999" }, { "input": "3\n-1 -2 -3", "output": "-1" }, { "input": "2\n-1000000 1000000", "output": "-1000000" }, { "input": "2\n-1 0", "output": "-1" }, { "input": "1\n2", "output": "2" }, { "input": "1\n-1", "output": "-1" }, { "input": "35\n-871271 -169147 -590893 -400197 -476793 0 -15745 -890852 -124052 -631140 -238569 -597194 -147909 -928925 -587628 -569656 -581425 -963116 -665954 -506797 -196044 -309770 -701921 -926257 -152426 -991371 -624235 -557143 -689886 -59804 -549134 -107407 -182016 -24153 -607462", "output": "-15745" }, { "input": "16\n-882343 -791322 0 -986738 -415891 -823354 -840236 -552554 -760908 -331993 -549078 -863759 -913261 -937429 -257875 -602322", "output": "-257875" }, { "input": "71\n908209 289 44521 240100 680625 274576 212521 91809 506944 499849 3844 15376 592900 58081 240100 984064 732736 257049 600625 180625 130321 580644 261121 75625 46225 853776 485809 700569 817216 268324 293764 528529 25921 399424 175561 99856 295936 20736 611524 13924 470596 574564 5329 15376 676 431649 145161 697225 41616 550564 514089 9409 227529 1681 839056 3721 552049 465124 38809 197136 659344 214369 998001 44944 3844 186624 362404 -766506 739600 10816 299209", "output": "-766506" }, { "input": "30\n192721 -950059 -734656 625 247009 -423468 318096 622521 678976 777924 1444 748303 27556 62001 795664 89401 221841 -483208 467856 477109 196 -461813 831744 772641 574564 -519370 861184 67600 -717966 -259259", "output": "748303" }, { "input": "35\n628849 962361 436921 944784 444889 29241 -514806 171396 685584 -823202 -929730 6982 198025 783225 552049 -957165 782287 -659167 -414846 695556 -336330 41616 963781 71289 119639 952576 -346713 178929 232324 121802 393266 841 649636 179555 998001", "output": "963781" }, { "input": "53\n280988 756430 -515570 -248578 170649 -21608 642677 216770 827291 589500 940901 216097 -118956 -919104 -319264 -761585 289479 499613 588276 883036 480518 -323196 -274570 -406556 -381484 -956025 702135 -445274 -783543 136593 153664 897473 352651 737974 -21123 -284944 501734 898033 604429 624138 40804 248782 -786059 -304592 -209210 -312904 419820 -328648 -47331 -919227 -280955 104827 877304", "output": "940901" }, { "input": "15\n256 -227055 427717 827239 462070 66049 987533 -175306 -552810 -867915 -408251 -693957 -972981 -245827 896904", "output": "987533" }, { "input": "3\n-1 1 0", "output": "-1" }, { "input": "2\n0 -5", "output": "-5" }, { "input": "3\n-1 -2 0", "output": "-1" }, { "input": "2\n-5 0", "output": "-5" }, { "input": "1\n-439", "output": "-439" }, { "input": "1\n-1000000", "output": "-1000000" }, { "input": "1\n-917455", "output": "-917455" }, { "input": "3\n1 1 -1", "output": "-1" }, { "input": "2\n131073 1", "output": "131073" }, { "input": "2\n99999 3", "output": "99999" }, { "input": "2\n-524272 -1000000", "output": "-524272" }, { "input": "2\n15 131073", "output": "131073" } ]
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\n2\n5\n1\n3" }, { "input": "10 2\n2 6 5 7 2 2 3 2 4 8\n1\n2", "output": "7\n7" }, { "input": "7 1\n68346 10956 76708 23018 84063 34833 80407\n1", "output": "7" }, { "input": "2 2\n8 4\n1\n1", "output": "2\n2" }, { "input": "1 5\n5\n1\n1\n1\n1\n1", "output": "1\n1\n1\n1\n1" }, { "input": "4 7\n3 1 4 2\n4\n1\n2\n3\n2\n4\n4", "output": "1\n4\n3\n2\n3\n1\n1" }, { "input": "4 3\n9 1 7 1\n1\n4\n2", "output": "3\n1\n2" }, { "input": "8 3\n9280 6676 2720 6172 8329 10413 3975 1394\n5\n6\n7", "output": "4\n3\n2" }, { "input": "1 1\n1\n1", "output": "1" } ]
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": "919067153", "output": "5" }, { "input": "690422411", "output": "7" }, { "input": "-408490162", "output": "1" }, { "input": "-8", "output": "16" }, { "input": "-6", "output": "14" }, { "input": "-4", "output": "12" }, { "input": "-2", "output": "10" }, { "input": "0", "output": "8" }, { "input": "2", "output": "6" }, { "input": "4", "output": "4" }, { "input": "6", "output": "2" }, { "input": "8", "output": "10" }, { "input": "1000000000", "output": "8" }, { "input": "-1000000000", "output": "2" }, { "input": "88888", "output": "1" }, { "input": "89", "output": "9" }, { "input": "-80000000", "output": "2" }, { "input": "-8888", "output": "1" }, { "input": "-17", "output": "9" }, { "input": "78", "output": "2" }, { "input": "-19", "output": "1" }, { "input": "-999999998", "output": "9" }, { "input": "-999999997", "output": "8" }, { "input": "999999997", "output": "1" }, { "input": "811111111", "output": "1" }, { "input": "-8", "output": "16" }, { "input": "-5", "output": "13" }, { "input": "-7", "output": "15" }, { "input": "1000000000", "output": "8" } ]
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\n59 96 34 48 8 72 67 90 15 85 7 90 97 47 25", "output": "840" }, { "input": "15\n87 37 91 29 58 45 51 74 70 71 47 38 91 89 44", "output": "922" }, { "input": "15\n11 81 49 7 11 14 30 67 29 50 90 81 77 18 59", "output": "674" }, { "input": "15\n39 21 95 89 73 90 9 55 85 32 30 21 68 59 82", "output": "848" }, { "input": "15\n59 70 48 54 26 67 84 39 40 18 77 69 70 88 93", "output": "902" }, { "input": "15\n87 22 98 32 88 36 72 31 100 97 17 16 60 22 20", "output": "798" }, { "input": "15\n15 63 51 13 37 9 43 19 55 79 57 60 50 59 31", "output": "632" }, { "input": "1\n4", "output": "4" }, { "input": "2\n1 4", "output": "4" }, { "input": "3\n1 2 4", "output": "6" }, { "input": "2\n9 3", "output": "12" }, { "input": "2\n1000000000 1001", "output": "1000000000" }, { "input": "3\n1 8 4", "output": "12" }, { "input": "3\n7 4 4", "output": "8" }, { "input": "5\n2 3 4 5 3", "output": "14" }, { "input": "2\n4 5", "output": "4" }, { "input": "3\n2 4 5", "output": "6" }, { "input": "3\n2 2 3", "output": "4" }, { "input": "2\n2 3", "output": "2" }, { "input": "4\n2 3 7 7", "output": "16" }, { "input": "2\n999999999 2", "output": "2" }, { "input": "2\n2 5", "output": "2" }, { "input": "3\n5 3 1", "output": "8" }, { "input": "4\n3 2 5 7", "output": "14" } ]
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??????????", "output": "0.205078125000" }, { "input": "+--+++--+-\n??????????", "output": "0.246093750000" }, { "input": "+\n+", "output": "1.000000000000" }, { "input": "-\n?", "output": "0.500000000000" }, { "input": "+\n-", "output": "0.000000000000" }, { "input": "-\n-", "output": "1.000000000000" }, { "input": "-\n+", "output": "0.000000000000" }, { "input": "+\n?", "output": "0.500000000000" }, { "input": "++++++++++\n++++++++++", "output": "1.000000000000" }, { "input": "++++++++++\n++++-+++++", "output": "0.000000000000" }, { "input": "----------\n++++++++++", "output": "0.000000000000" }, { "input": "++++++++++\n++++??++++", "output": "0.250000000000" }, { "input": "----------\n+++?++++-+", "output": "0.000000000000" }, { "input": "++++++++++\n++++++++?+", "output": "0.500000000000" }, { "input": "--++++--+\n?-+?-??+-", "output": "0.250000000000" }, { "input": "----------\n??????????", "output": "0.000976562500" }, { "input": "+--++\n+--+-", "output": "0.000000000000" }, { "input": "-----++---\n????????+?", "output": "0.017578125000" }, { "input": "------+--+\n??????????", "output": "0.043945312500" }, { "input": "---++--\n???????", "output": "0.164062500000" }, { "input": "-----++\n???????", "output": "0.164062500000" }, { "input": "+---+--\n???????", "output": "0.164062500000" }, { "input": "---+-+\n??????", "output": "0.234375000000" }, { "input": "+++-+\n---++", "output": "0.000000000000" }, { "input": "++-+--+\n?-?+??+", "output": "0.375000000000" }, { "input": "----+++--\n-+?+++?--", "output": "0.000000000000" }, { "input": "+-----\n+?----", "output": "0.500000000000" } ]
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", "output": "1" }, { "input": "3", "output": "1" }, { "input": "4", "output": "1" }, { "input": "534204", "output": "106841" }, { "input": "469569", "output": "93914" }, { "input": "502877", "output": "100576" }, { "input": "942212", "output": "188443" }, { "input": "97", "output": "20" }, { "input": "53", "output": "11" }, { "input": "89", "output": "18" }, { "input": "574", "output": "115" }, { "input": "716", "output": "144" }, { "input": "729", "output": "146" }, { "input": "8901", "output": "1781" }, { "input": "3645", "output": "729" }, { "input": "4426", "output": "886" }, { "input": "46573", "output": "9315" }, { "input": "86380", "output": "17276" }, { "input": "94190", "output": "18838" }, { "input": "999990", "output": "199998" }, { "input": "999991", "output": "199999" }, { "input": "999992", "output": "199999" }, { "input": "999993", "output": "199999" }, { "input": "999994", "output": "199999" }, { "input": "999995", "output": "199999" }, { "input": "999996", "output": "200000" }, { "input": "999997", "output": "200000" }, { "input": "999998", "output": "200000" } ]
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" }, { "input": "3\n2 3\n1 1\n3 2", "output": "Happy Alex" }, { "input": "4\n4 1\n3 2\n2 3\n1 4", "output": "Happy Alex" }, { "input": "2\n2 1\n1 2", "output": "Happy Alex" }, { "input": "3\n3 2\n1 1\n2 3", "output": "Happy Alex" }, { "input": "3\n1 2\n2 3\n3 1", "output": "Happy Alex" }, { "input": "3\n1 2\n2 1\n3 3", "output": "Happy Alex" }, { "input": "3\n1 2\n2 3\n3 1", "output": "Happy 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\n0 1\n1 0\n1 0", "output": "2" }, { "input": "3\n0 0\n0 0\n0 0", "output": "0" }, { "input": "3\n0 1000\n1000 1000\n1000 0", "output": "1000" }, { "input": "5\n0 73\n73 189\n189 766\n766 0\n0 0", "output": "766" }, { "input": "5\n0 0\n0 0\n0 0\n0 1\n1 0", "output": "1" }, { "input": "5\n0 917\n917 923\n904 992\n1000 0\n11 0", "output": "1011" }, { "input": "5\n0 1\n1 2\n2 1\n1 2\n2 0", "output": "2" }, { "input": "5\n0 0\n0 0\n0 0\n0 0\n0 0", "output": "0" }, { "input": "20\n0 7\n2 1\n2 2\n5 7\n2 6\n6 10\n2 4\n0 4\n7 4\n8 0\n10 6\n2 1\n6 1\n1 7\n0 3\n8 7\n6 3\n6 3\n1 1\n3 0", "output": "22" }, { "input": "5\n0 1000\n1000 1000\n1000 1000\n1000 1000\n1000 0", "output": "1000" }, { "input": "10\n0 592\n258 598\n389 203\n249 836\n196 635\n478 482\n994 987\n1000 0\n769 0\n0 0", "output": "1776" }, { "input": "10\n0 1\n1 0\n0 0\n0 0\n0 0\n0 1\n1 1\n0 1\n1 0\n1 0", "output": "2" }, { "input": "10\n0 926\n926 938\n938 931\n931 964\n937 989\n983 936\n908 949\n997 932\n945 988\n988 0", "output": "1016" }, { "input": "10\n0 1\n1 2\n1 2\n2 2\n2 2\n2 2\n1 1\n1 1\n2 1\n2 0", "output": "3" }, { "input": "10\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0", "output": "0" }, { "input": "10\n0 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 0", "output": "1000" }, { "input": "50\n0 332\n332 268\n268 56\n56 711\n420 180\n160 834\n149 341\n373 777\n763 93\n994 407\n86 803\n700 132\n471 608\n429 467\n75 5\n638 305\n405 853\n316 478\n643 163\n18 131\n648 241\n241 766\n316 847\n640 380\n923 759\n789 41\n125 421\n421 9\n9 388\n388 829\n408 108\n462 856\n816 411\n518 688\n290 7\n405 912\n397 772\n396 652\n394 146\n27 648\n462 617\n514 433\n780 35\n710 705\n460 390\n194 508\n643 56\n172 469\n1000 0\n194 0", "output": "2071" }, { "input": "50\n0 0\n0 1\n1 1\n0 1\n0 0\n1 0\n0 0\n1 0\n0 0\n0 0\n0 0\n0 0\n0 1\n0 0\n0 0\n0 1\n1 0\n0 1\n0 0\n1 1\n1 0\n0 1\n0 0\n1 1\n0 1\n1 0\n1 1\n1 0\n0 0\n1 1\n1 0\n0 1\n0 0\n0 1\n1 1\n1 1\n1 1\n1 0\n1 1\n1 0\n0 1\n1 0\n0 0\n0 1\n1 1\n1 1\n0 1\n0 0\n1 0\n1 0", "output": "3" }, { "input": "50\n0 926\n926 971\n915 980\n920 965\n954 944\n928 952\n955 980\n916 980\n906 935\n944 913\n905 923\n912 922\n965 934\n912 900\n946 930\n931 983\n979 905\n925 969\n924 926\n910 914\n921 977\n934 979\n962 986\n942 909\n976 903\n982 982\n991 941\n954 929\n902 980\n947 983\n919 924\n917 943\n916 905\n907 913\n964 977\n984 904\n905 999\n950 970\n986 906\n993 970\n960 994\n963 983\n918 986\n980 900\n931 986\n993 997\n941 909\n907 909\n1000 0\n278 0", "output": "1329" }, { "input": "2\n0 863\n863 0", "output": "863" }, { "input": "50\n0 1\n1 2\n2 2\n1 1\n1 1\n1 2\n1 2\n1 1\n1 2\n1 1\n1 1\n1 2\n1 2\n1 1\n2 1\n2 2\n1 2\n2 2\n1 2\n2 1\n2 1\n2 2\n2 1\n1 2\n1 2\n2 1\n1 1\n2 2\n1 1\n2 1\n2 2\n2 1\n1 2\n2 2\n1 2\n1 1\n1 1\n2 1\n2 1\n2 2\n2 1\n2 1\n1 2\n1 2\n1 2\n1 2\n2 0\n2 0\n2 0\n0 0", "output": "8" }, { "input": "50\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0", "output": "0" }, { "input": "100\n0 1\n0 0\n0 0\n1 0\n0 0\n0 1\n0 1\n1 1\n0 0\n0 0\n1 1\n0 0\n1 1\n0 1\n1 1\n0 1\n1 1\n1 0\n1 0\n0 0\n1 0\n0 1\n1 0\n0 0\n0 0\n1 1\n1 1\n0 1\n0 0\n1 0\n1 1\n0 1\n1 0\n1 1\n0 1\n1 1\n1 0\n0 0\n0 0\n0 1\n0 0\n0 1\n1 1\n0 0\n1 1\n1 1\n0 0\n0 1\n1 0\n0 1\n0 0\n0 1\n0 1\n1 1\n1 1\n1 1\n0 0\n0 0\n1 1\n0 1\n0 1\n1 0\n0 0\n0 0\n1 1\n0 1\n0 1\n1 1\n1 1\n0 1\n1 1\n1 1\n0 0\n1 0\n0 1\n0 0\n0 0\n1 1\n1 1\n1 1\n1 1\n0 1\n1 0\n1 0\n1 0\n1 0\n1 0\n0 0\n1 0\n1 0\n0 0\n1 0\n0 0\n0 1\n1 0\n0 1\n1 0\n1 0\n1 0\n1 0", "output": "11" }, { "input": "100\n0 2\n1 2\n2 1\n1 2\n1 2\n2 1\n2 2\n1 1\n1 1\n2 1\n1 2\n2 1\n1 2\n2 2\n2 2\n2 2\n1 2\n2 2\n2 1\n1 1\n1 1\n1 1\n2 2\n1 2\n2 2\n1 1\n1 1\n1 1\n1 1\n2 2\n1 2\n2 1\n1 1\n2 2\n1 1\n2 1\n1 1\n2 2\n2 1\n1 2\n1 1\n1 2\n2 1\n2 2\n1 1\n2 1\n1 1\n2 1\n1 1\n1 2\n2 2\n2 2\n1 1\n2 2\n1 2\n2 1\n2 1\n1 1\n1 1\n1 2\n1 2\n1 1\n1 1\n2 1\n1 2\n1 2\n2 1\n2 2\n2 2\n2 2\n2 1\n2 2\n1 1\n1 2\n1 2\n1 1\n2 2\n2 2\n1 1\n2 1\n1 1\n1 2\n1 2\n1 2\n1 1\n1 1\n2 2\n1 2\n2 1\n2 1\n2 1\n1 2\n1 2\n1 1\n2 2\n1 2\n2 0\n2 0\n2 0\n1 0", "output": "7" }, { "input": "100\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0", "output": "0" }, { "input": "2\n0 1\n1 0", "output": "1" }, { "input": "2\n0 900\n900 0", "output": "900" }, { "input": "2\n0 1\n1 0", "output": "1" }, { "input": "2\n0 0\n0 0", "output": "0" }, { "input": "2\n0 1000\n1000 0", "output": "1000" }, { "input": "3\n0 802\n175 188\n815 0", "output": "815" }, { "input": "3\n0 910\n910 976\n976 0", "output": "976" }, { "input": "3\n0 2\n2 1\n1 0", "output": "2" } ]
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", "output": "6" }, { "input": "11 562314608", "output": "39916800" }, { "input": "3 990639260", "output": "6" }, { "input": "11 859155400", "output": "39916800" }, { "input": "1 1", "output": "1" }, { "input": "5 3", "output": "6" }, { "input": "1 4", "output": "1" }, { "input": "5 4", "output": "24" }, { "input": "1 12", "output": "1" }, { "input": "9 7", "output": "5040" }, { "input": "2 3", "output": "2" }, { "input": "6 11", "output": "720" }, { "input": "6 7", "output": "720" }, { "input": "11 11", "output": "39916800" }, { "input": "4 999832660", "output": "24" }, { "input": "7 999228288", "output": "5040" }, { "input": "11 999257105", "output": "39916800" }, { "input": "11 999286606", "output": "39916800" }, { "input": "3 999279109", "output": "6" }, { "input": "999632727 11", "output": "39916800" }, { "input": "999625230 7", "output": "5040" }, { "input": "999617047 3", "output": "6" }, { "input": "999646548 7", "output": "5040" }, { "input": "999639051 3", "output": "6" }, { "input": "12 12", "output": "479001600" }, { "input": "12 1", "output": "1" }, { "input": "1213 5", "output": "120" }, { "input": "8 9", "output": "40320" }, { "input": "12 9", "output": "362880" }, { "input": "12 1000000000", "output": "479001600" }, { "input": "1000000000 1", "output": "1" }, { "input": "12 13", "output": "479001600" }, { "input": "2 29845", "output": "2" }, { "input": "10 21", "output": "3628800" }, { "input": "12 20", "output": "479001600" }, { "input": "15 12", "output": "479001600" }, { "input": "1 1", "output": "1" }, { "input": "1000000000 12", "output": "479001600" }, { "input": "11 30", "output": "39916800" }, { "input": "17 12", "output": "479001600" }, { "input": "4 19", "output": "24" }, { "input": "12 15", "output": "479001600" }, { "input": "20 6", "output": "720" }, { "input": "10 20", "output": "3628800" }, { "input": "10 10", "output": "3628800" }, { "input": "22 12", "output": "479001600" }, { "input": "20 12", "output": "479001600" }, { "input": "12 23", "output": "479001600" }, { "input": "12 22", "output": "479001600" }, { "input": "18 3", "output": "6" }, { "input": "14 10", "output": "3628800" }, { "input": "14 12", "output": "479001600" }, { "input": "8 3", "output": "6" }, { "input": "5 5", "output": "120" } ]
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", "output": "99" }, { "input": "gngvi", "output": "44" }, { "input": "aaaaa", "output": "0" }, { "input": "a", "output": "0" }, { "input": "z", "output": "1" }, { "input": "vyadeehhikklnoqrs", "output": "28" }, { "input": "jjiihhhhgggfedcccbazyxx", "output": "21" }, { "input": "fyyptqqxuciqvwdewyppjdzur", "output": "117" }, { "input": "fqcnzmzmbobmancqcoalzmanaobpdse", "output": "368" }, { "input": "zzzzzaaaaaaazzzzzzaaaaaaazzzzzzaaaazzzza", "output": "8" }, { "input": "aucnwhfixuruefkypvrvnvznwtjgwlghoqtisbkhuwxmgzuljvqhmnwzisnsgjhivnjmbknptxatdkelhzkhsuxzrmlcpeoyukiy", "output": "644" }, { "input": "sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss", "output": "8" }, { "input": "nypjygrdtpzpigzyrisqeqfriwgwlengnezppgttgtndbrryjdl", "output": "421" }, { "input": "pnllnnmmmmoqqqqqrrtssssuuvtsrpopqoonllmonnnpppopnonoopooqpnopppqppqstuuuwwwwvxzxzzaa", "output": "84" }, { "input": "btaoahqgxnfsdmzsjxgvdwjukcvereqeskrdufqfqgzqfsftdqcthtkcnaipftcnco", "output": "666" }, { "input": "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeerrrrrrrrrrrrrrrrwwwwwwwwww", "output": "22" }, { "input": "uyknzcrwjyzmscqucclvacmorepdgmnyhmakmmnygqwglrxkxhkpansbmruwxdeoprxzmpsvwackopujxbbkpwyeggsvjykpxh", "output": "643" }, { "input": "gzwpooohffcxwtpjgfzwtooiccxsrrokezutoojdzwsrmmhecaxwrojcbyrqlfdwwrliiib", "output": "245" }, { "input": "dbvnkktasjdwqsrzfwwtmjgbcxggdxsoeilecihduypktkkbwfbruxzzhlttrssicgdwqruddwrlbtxgmhdbatzvdxbbro", "output": "468" }, { "input": "mdtvowlktxzzbuaeiuebfeorgbdczauxsovbucactkvyvemsknsjfhifqgycqredzchipmkvzbxdjkcbyukomjlzvxzoswumned", "output": "523" }, { "input": "kkkkkkkaaaaxxaaaaaaaxxxxxxxxaaaaaaxaaaaaaaaaakkkkkkkkkaaaaaaannnnnxxxxkkkkkkkkaannnnnnna", "output": "130" }, { "input": "dffiknqqrsvwzcdgjkmpqtuwxadfhkkkmpqrtwxyadfggjmpppsuuwyyzcdgghhknnpsvvvwwwyabccffiloqruwwyyzabeeehh", "output": "163" }, { "input": "qpppmmkjihgecbyvvsppnnnkjiffeebaaywutrrqpmkjhgddbzzzywtssssqnmmljheddbbaxvusrqonmlifedbbzyywwtqnkheb", "output": "155" }, { "input": "wvvwwwvvwxxxyyyxxwwvwwvuttttttuvvwxxwxxyxxwwwwwvvuttssrssstsssssrqpqqppqrssrsrrssrssssrrsrqqrrqpppqp", "output": "57" }, { "input": "dqcpcobpcobnznamznamzlykxkxlxlylzmaobnaobpbnanbpcoaobnboaoboanzlymzmykylymylzlylymanboanaocqdqesfrfs", "output": "1236" }, { "input": "nnnnnnnnnnnnnnnnnnnnaaaaaaaaaaaaaaaaaaaakkkkkkkkkkkkkkkkkkkkkkaaaaaaaaaaaaaaaaaaaaxxxxxxxxxxxxxxxxxx", "output": "49" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "0" }, { "input": "cgilqsuwzaffilptwwbgmnttyyejkorxzflqvzbddhmnrvxchijpuwaeiimosxyycejlpquuwbfkpvbgijkqvxybdjjjptxcfkqt", "output": "331" }, { "input": "ufsepwgtzgtgjssxaitgpailuvgqweoppszjwhoxdhhhpwwdorwfrdjwcdekxiktwziqwbkvbknrtvajpyeqbjvhiikxxaejjpte", "output": "692" }, { "input": "uhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuh", "output": "1293" }, { "input": "vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvgggggggggggggggggggggggggggggggggggggggggggggggggg", "output": "16" }, { "input": "lyidmjyzbszgiwkxhhpnnthfwcvvstueionspfrvqgkvngmwyhezlosrpdnbvtcjjxxsykixwnepbumaacdzadlqhnjlcejovple", "output": "616" }, { "input": "etzqqbaveffalkdguunfmyyrzkccnxmlluxeasqmopxzfvlkbhipqdwjgrttoemruohgwukfisdhznqyvhswbbypoxgtxyappcrl", "output": "605" }, { "input": "lizussgedcbdjhrbeskhgatyozvwwekanlggcstijrniivupmcoofbaxfqrxddyzzptwxcftlhajsmmkkriarrqtkoauhcqefyud", "output": "549" }, { "input": "dvjuvgfdogpknmbowlsfjzcimnygbtjiucyeeroqwhmzwpjqxlbjkqawrdtmvxbiqufllfuqibxvmtdrwaqkjblxqjpwzmhwqore", "output": "688" }, { "input": "eeycuijtbgynmiczjfslwobmnkpgodfgvujvduyfeqchuaoktqrrairkkmmsjahltfcxwtpzzyddxrqfxabfoocmpuviinrjitsc", "output": "604" }, { "input": "cgglnakewwvzoytaghksebrhjdbcdegssuzilrcppayxtgxopybbwshvyqnzhdsifkuwghourmeottrgjwdqpihbklvfzxpomqsa", "output": "572" }, { "input": "aexullmxncckzryymfnuugdklaffevabqqztelpvojecljnhqldazdcaamubpenwxikysxxjjctvbndprsolzehywmgnvkgqvrfp", "output": "609" }, { "input": "psnoieutsvvcwfhtnnphhxkwigzsbzyjmdiyl", "output": "223" }, { "input": "aa", "output": "0" } ]
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--\n++X\nX++\nX++\nX++\n--X\n--X\nX++\nX--\n++X\nX++\n--X\nX--\nX++\nX--\n++X\n++X\nX++\nX++\nX++\nX++\n--X\n++X\n--X\n--X\n--X\n--X\nX++", "output": "4" }, { "input": "94\nX++\nX++\n++X\n++X\nX--\n--X\nX++\n--X\nX++\n++X\nX++\n++X\n--X\n--X\n++X\nX++\n--X\nX--\nX--\n--X\nX--\nX--\n--X\n++X\n--X\nX--\nX--\nX++\n++X\n--X\nX--\n++X\n--X\n--X\nX--\nX--\nX++\nX++\nX--\nX++\nX--\nX--\nX--\n--X\nX--\nX--\nX--\nX++\n++X\nX--\n++X\nX++\n--X\n--X\n--X\n--X\n++X\nX--\n--X\n--X\n++X\nX--\nX--\nX++\n++X\nX++\n++X\n--X\n--X\nX--\n++X\nX--\nX--\n++X\n++X\n++X\n++X\nX++\n++X\n--X\nX++\n--X\n--X\n++X\n--X\nX++\n++X\nX++\n--X\nX--\nX--\n--X\n++X\nX++", "output": "-10" }, { "input": "56\n--X\nX--\n--X\n--X\nX--\nX--\n--X\nX++\n++X\n--X\nX++\nX--\n--X\n++X\n--X\nX--\nX--\n++X\nX--\nX--\n--X\n++X\n--X\n++X\n--X\nX++\n++X\nX++\n--X\n++X\nX++\nX++\n--X\nX++\nX--\n--X\nX--\n--X\nX++\n++X\n--X\n++X\nX++\nX--\n--X\n--X\n++X\nX--\nX--\n--X\nX--\n--X\nX++\n--X\n++X\n--X", "output": "-14" }, { "input": "59\nX--\n--X\nX++\n++X\nX--\n--X\n--X\n++X\n++X\n++X\n++X\nX++\n++X\n++X\nX++\n--X\nX--\nX++\n++X\n--X\nX++\n--X\n++X\nX++\n--X\n--X\nX++\nX++\n--X\nX++\nX++\nX++\nX--\nX--\n--X\nX++\nX--\nX--\n++X\nX--\nX++\n--X\nX++\nX--\nX--\nX--\nX--\n++X\n--X\nX++\nX++\nX--\nX++\n++X\nX--\nX++\nX--\nX--\n++X", "output": "3" }, { "input": "87\n--X\n++X\n--X\nX++\n--X\nX--\n--X\n++X\nX--\n++X\n--X\n--X\nX++\n--X\nX--\nX++\n++X\n--X\n++X\n++X\n--X\n++X\n--X\nX--\n++X\n++X\nX--\nX++\nX++\n--X\n--X\n++X\nX--\n--X\n++X\n--X\nX++\n--X\n--X\nX--\n++X\n++X\n--X\nX--\nX--\nX--\nX--\nX--\nX++\n--X\n++X\n--X\nX++\n++X\nX++\n++X\n--X\nX++\n++X\nX--\n--X\nX++\n++X\nX++\nX++\n--X\n--X\n++X\n--X\nX++\nX++\n++X\nX++\nX++\nX++\nX++\n--X\n--X\n--X\n--X\n--X\n--X\n--X\nX--\n--X\n++X\n++X", "output": "-5" }, { "input": "101\nX++\nX++\nX++\n++X\n--X\nX--\nX++\nX--\nX--\n--X\n--X\n++X\nX++\n++X\n++X\nX--\n--X\n++X\nX++\nX--\n++X\n--X\n--X\n--X\n++X\n--X\n++X\nX++\nX++\n++X\n--X\nX++\nX--\nX++\n++X\n++X\nX--\nX--\nX--\nX++\nX++\nX--\nX--\nX++\n++X\n++X\n++X\n--X\n--X\n++X\nX--\nX--\n--X\n++X\nX--\n++X\nX++\n++X\nX--\nX--\n--X\n++X\n--X\n++X\n++X\n--X\nX++\n++X\nX--\n++X\nX--\n++X\nX++\nX--\n++X\nX++\n--X\nX++\nX++\n++X\n--X\n++X\n--X\nX++\n--X\nX--\n--X\n++X\n++X\n++X\n--X\nX--\nX--\nX--\nX--\n--X\n--X\n--X\n++X\n--X\n--X", "output": "1" }, { "input": "63\n--X\nX--\n++X\n--X\n++X\nX++\n--X\n--X\nX++\n--X\n--X\nX++\nX--\nX--\n--X\n++X\nX--\nX--\nX++\n++X\nX++\nX++\n--X\n--X\n++X\nX--\nX--\nX--\n++X\nX++\nX--\n--X\nX--\n++X\n++X\nX++\n++X\nX++\nX++\n--X\nX--\n++X\nX--\n--X\nX--\nX--\nX--\n++X\n++X\n++X\n++X\nX++\nX++\n++X\n--X\n--X\n++X\n++X\n++X\nX--\n++X\n++X\nX--", "output": "1" }, { "input": "45\n--X\n++X\nX--\n++X\n++X\nX++\n--X\n--X\n--X\n--X\n--X\n--X\n--X\nX++\n++X\nX--\n++X\n++X\nX--\nX++\nX--\n--X\nX--\n++X\n++X\n--X\n--X\nX--\nX--\n--X\n++X\nX--\n--X\n++X\n++X\n--X\n--X\nX--\n++X\n++X\nX++\nX++\n++X\n++X\nX++", "output": "-3" }, { "input": "21\n++X\nX++\n--X\nX--\nX++\n++X\n--X\nX--\nX++\nX--\nX--\nX--\nX++\n++X\nX++\n++X\n--X\nX--\n--X\nX++\n++X", "output": "1" }, { "input": "100\n--X\n++X\nX++\n++X\nX--\n++X\nX--\nX++\n--X\nX++\nX--\nX--\nX--\n++X\nX--\nX++\nX++\n++X\nX++\nX++\nX++\nX++\n++X\nX++\n++X\nX--\n--X\n++X\nX--\n--X\n++X\n++X\nX--\nX++\nX++\nX++\n++X\n--X\n++X\nX++\nX--\n++X\n++X\n--X\n++X\nX--\nX--\nX--\nX++\nX--\nX--\nX++\nX++\n--X\nX++\nX++\n--X\nX--\n--X\n++X\n--X\n++X\n++X\nX--\n--X\n++X\n++X\n--X\n--X\n++X\nX++\nX--\nX++\nX--\nX++\nX++\n--X\nX--\nX--\n++X\nX--\n--X\n--X\nX++\n--X\n--X\nX--\nX--\n++X\n++X\nX--\n++X\nX++\n--X\n++X\n++X\nX++\n--X\n--X\nX++", "output": "8" }, { "input": "17\nX++\nX++\n++X\n--X\n--X\n++X\n++X\n--X\nX--\nX++\nX--\n--X\n--X\nX--\n++X\nX--\nX++", "output": "-1" }, { "input": "77\n++X\nX++\n--X\nX--\n--X\n--X\nX--\nX++\nX--\nX++\nX--\n++X\n--X\n--X\n--X\n--X\n++X\nX--\nX++\nX--\n--X\nX--\n--X\nX--\n++X\n--X\n++X\n++X\nX++\nX++\nX--\n--X\nX--\nX--\nX++\n--X\n--X\n++X\nX--\nX--\n++X\nX++\nX--\n++X\n--X\nX++\nX--\n++X\n++X\n++X\nX--\nX--\nX--\n--X\n++X\n++X\n++X\nX++\n--X\n--X\n++X\n--X\nX--\nX++\n++X\nX++\n++X\nX--\nX++\nX++\n--X\nX++\nX++\nX++\n--X\nX++\nX--", "output": "-5" }, { "input": "21\nX--\n++X\n--X\nX--\n++X\nX--\n++X\nX--\n--X\n++X\nX++\n++X\nX++\n++X\nX--\n--X\nX++\nX++\nX--\n++X\nX--", "output": "1" }, { "input": "1\nX--", "output": "-1" } ]
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\n2\n1 1", "output": "1" }, { "input": "10\n2\n10 2", "output": "0" }, { "input": "10\n3\n6 3 6", "output": "11" }, { "input": "10\n4\n8 7 1 5", "output": "14" }, { "input": "10\n5\n2 7 8 4 4", "output": "19" }, { "input": "10\n6\n8 3 4 9 6 1", "output": "20" }, { "input": "10\n7\n10 5 3 1 1 9 1", "output": "31" }, { "input": "10\n8\n6 5 10 6 8 1 3 2", "output": "31" }, { "input": "10\n9\n6 2 7 5 5 4 8 6 2", "output": "37" }, { "input": "10\n10\n1 10 1 10 1 1 7 8 6 7", "output": "45" }, { "input": "100\n100\n85 50 17 89 65 89 5 20 86 26 16 21 85 14 44 31 87 31 6 2 48 67 8 80 79 1 48 36 97 1 5 30 79 50 78 12 2 55 76 100 54 40 26 81 97 96 68 56 87 14 51 17 54 37 52 33 69 62 38 63 74 15 62 78 9 19 67 2 60 58 93 60 18 96 55 48 34 7 79 82 32 58 90 67 20 50 27 15 7 89 98 10 11 15 99 49 4 51 77 52", "output": "5099" }, { "input": "101\n100\n19 17 15 16 28 69 41 47 75 42 19 98 16 90 92 47 21 4 98 17 27 31 90 10 14 92 62 73 56 55 6 60 62 22 78 1 3 86 18 59 92 41 21 34 67 9 92 78 77 45 50 92 57 61 11 98 89 72 57 93 100 12 61 48 5 48 38 9 65 64 77 29 18 55 94 42 10 77 43 46 7 89 8 13 5 53 80 59 23 100 30 28 29 24 85 56 10 22 24 16", "output": "5301" }, { "input": "102\n100\n31 22 59 16 11 56 81 4 19 31 8 72 4 92 18 7 13 12 62 40 34 67 40 23 96 4 90 28 3 18 54 49 10 71 73 79 69 7 41 75 59 13 2 78 72 6 95 33 52 97 7 86 57 94 12 93 19 94 59 28 5 96 46 102 2 101 57 85 53 69 72 39 14 75 8 16 10 57 26 4 85 18 89 84 48 93 54 21 78 6 67 35 11 78 91 91 97 15 8 32", "output": "5447" }, { "input": "103\n100\n68 38 41 54 37 11 35 26 43 97 70 3 13 11 64 83 3 95 99 16 4 13 22 27 64 20 95 38 40 87 6 17 95 67 31 24 85 33 98 24 89 101 66 38 42 5 95 18 95 13 103 85 72 73 68 93 22 59 48 59 72 46 5 41 54 32 48 69 3 76 2 26 102 44 39 58 55 85 40 16 81 78 92 63 25 97 83 2 54 16 20 63 19 8 84 34 1 22 43 93", "output": "5358" }, { "input": "104\n100\n65 74 94 71 98 38 88 67 71 84 45 79 55 86 55 51 27 89 14 66 29 63 8 103 98 94 87 81 58 68 24 96 60 36 48 95 28 72 95 42 87 7 14 23 99 77 34 14 90 31 8 99 29 30 9 88 42 1 77 61 55 85 17 98 62 78 27 1 58 69 82 62 62 81 56 104 66 8 17 23 7 61 59 70 79 64 78 16 32 11 59 4 24 73 55 2 95 39 62 13", "output": "4773" } ]
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": "xYaPxPxHxGePfGtQySlNrLxSjDtNnTaRaEpAhPaQpWnDzMqGgRgEwJxGiBdZnMtHxFbObCaGiCeZkUqIgBhHtNvAqAlHpMnQhNeQbMyZrCdElVwHtKrPpJjIaHuIlYwHaRkAkUpPlOhNlBtXwDsKzPyHrPiUwNlXtTaPuMwTqYtJySgFoXvLiHbQwMjSvXsQfKhVlOxGdQkWjBhEyQvBjPoFkThNeRhTuIzFjInJtEfPjOlOsJpJuLgLzFnZmKvFgFrNsOnVqFcNiMfCqTpKnVyLwNqFiTySpWeTdFnWuTwDkRjVxNyQvTrOoEiExYiFaIrLoFmJfZcDkHuWjYfCeEqCvEsZiWnJaEmFbMjDvYwEeJeGcKbVbChGsIzNlExHzHiTlHcSaKxLuZxX", "output": "XYaPxPxHxGePfGtQySlNrLxSjDtNnTaRaEpAhPaQpWnDzMqGgRgEwJxGiBdZnMtHxFbObCaGiCeZkUqIgBhHtNvAqAlHpMnQhNeQbMyZrCdElVwHtKrPpJjIaHuIlYwHaRkAkUpPlOhNlBtXwDsKzPyHrPiUwNlXtTaPuMwTqYtJySgFoXvLiHbQwMjSvXsQfKhVlOxGdQkWjBhEyQvBjPoFkThNeRhTuIzFjInJtEfPjOlOsJpJuLgLzFnZmKvFgFrNsOnVqFcNiMfCqTpKnVyLwNqFiTySpWeTdFnWuTwDkRjVxNyQvTrOoEiExYiFaIrLoFmJfZcDkHuWjYfCeEqCvEsZiWnJaEmFbMjDvYwEeJeGcKbVbChGsIzNlExHzHiTlHcSaKxLuZxX" }, { "input": "rZhIcQlXpNcPgXrOjTiOlMoTgXgIhCfMwZfWoFzGhEkQlOoMjIuShPlZfWkNnMyQfYdUhVgQuSmYoElEtZpDyHtOxXgCpWbZqSbYnPqBcNqRtPgCnJnAyIvNsAhRbNeVlMwZyRyJnFgIsCnSbOdLvUyIeOzQvRpMoMoHfNhHwKvTcHuYnYySfPmAiNwAiWdZnWlLvGfBbRbRrCrBqIgIdWkWiBsNyYkKdNxZdGaToSsDnXpRaGrKxBpQsCzBdQgZzBkGeHgGxNrIyQlSzWsTmSnZwOcHqQpNcQvJlPvKaPiQaMaYsQjUeCqQdCjPgUbDmWiJmNiXgExLqOcCtSwSePnUxIuZfIfBeWbEiVbXnUsPwWyAiXyRbZgKwOqFfCtQuKxEmVeRlAkOeXkO", "output": "RZhIcQlXpNcPgXrOjTiOlMoTgXgIhCfMwZfWoFzGhEkQlOoMjIuShPlZfWkNnMyQfYdUhVgQuSmYoElEtZpDyHtOxXgCpWbZqSbYnPqBcNqRtPgCnJnAyIvNsAhRbNeVlMwZyRyJnFgIsCnSbOdLvUyIeOzQvRpMoMoHfNhHwKvTcHuYnYySfPmAiNwAiWdZnWlLvGfBbRbRrCrBqIgIdWkWiBsNyYkKdNxZdGaToSsDnXpRaGrKxBpQsCzBdQgZzBkGeHgGxNrIyQlSzWsTmSnZwOcHqQpNcQvJlPvKaPiQaMaYsQjUeCqQdCjPgUbDmWiJmNiXgExLqOcCtSwSePnUxIuZfIfBeWbEiVbXnUsPwWyAiXyRbZgKwOqFfCtQuKxEmVeRlAkOeXkO" }, { "input": "hDgZlUmLhYbLkLcNcKeOwJwTePbOvLaRvNzQbSbLsPeHqLhUqWtUbNdQfQqFfXeJqJwWuOrFnDdZiPxIkDyVmHbHvXfIlFqSgAcSyWbOlSlRuPhWdEpEzEeLnXwCtWuVcHaUeRgCiYsIvOaIgDnFuDbRnMoCmPrZfLeFpSjQaTfHgZwZvAzDuSeNwSoWuJvLqKqAuUxFaCxFfRcEjEsJpOfCtDiVrBqNsNwPuGoRgPzRpLpYnNyQxKaNnDnYiJrCrVcHlOxPiPcDbEgKfLwBjLhKcNeMgJhJmOiJvPfOaPaEuGqWvRbErKrIpDkEoQnKwJnTlStLyNsHyOjZfKoIjXwUvRrWpSyYhRpQdLqGmErAiNcGqAqIrTeTiMuPmCrEkHdBrLyCxPtYpRqD", "output": "HDgZlUmLhYbLkLcNcKeOwJwTePbOvLaRvNzQbSbLsPeHqLhUqWtUbNdQfQqFfXeJqJwWuOrFnDdZiPxIkDyVmHbHvXfIlFqSgAcSyWbOlSlRuPhWdEpEzEeLnXwCtWuVcHaUeRgCiYsIvOaIgDnFuDbRnMoCmPrZfLeFpSjQaTfHgZwZvAzDuSeNwSoWuJvLqKqAuUxFaCxFfRcEjEsJpOfCtDiVrBqNsNwPuGoRgPzRpLpYnNyQxKaNnDnYiJrCrVcHlOxPiPcDbEgKfLwBjLhKcNeMgJhJmOiJvPfOaPaEuGqWvRbErKrIpDkEoQnKwJnTlStLyNsHyOjZfKoIjXwUvRrWpSyYhRpQdLqGmErAiNcGqAqIrTeTiMuPmCrEkHdBrLyCxPtYpRqD" }, { "input": "qUdLgGrJeGmIzIeZrCjUtBpYfRvNdXdRpGsThIsEmJjTiMqEwRxBeBaSxEuWrNvExKePjPnXhPzBpWnHiDhTvZhBuIjDnZpTcEkCvRkAcTmMuXhGgErWgFyGyToOyVwYlCuQpTfJkVdWmFyBqQhJjYtXrBbFdHzDlGsFbHmHbFgXgFhIyDhZyEqEiEwNxSeByBwLiVeSnCxIdHbGjOjJrZeVkOzGeMmQrJkVyGhDtCzOlPeAzGrBlWwEnAdUfVaIjNrRyJjCnHkUvFuKuKeKbLzSbEmUcXtVkZzXzKlOrPgQiDmCcCvIyAdBwOeUuLbRmScNcWxIkOkJuIsBxTrIqXhDzLcYdVtPgZdZfAxTmUtByGiTsJkSySjXdJvEwNmSmNoWsChPdAzJrBoW", "output": "QUdLgGrJeGmIzIeZrCjUtBpYfRvNdXdRpGsThIsEmJjTiMqEwRxBeBaSxEuWrNvExKePjPnXhPzBpWnHiDhTvZhBuIjDnZpTcEkCvRkAcTmMuXhGgErWgFyGyToOyVwYlCuQpTfJkVdWmFyBqQhJjYtXrBbFdHzDlGsFbHmHbFgXgFhIyDhZyEqEiEwNxSeByBwLiVeSnCxIdHbGjOjJrZeVkOzGeMmQrJkVyGhDtCzOlPeAzGrBlWwEnAdUfVaIjNrRyJjCnHkUvFuKuKeKbLzSbEmUcXtVkZzXzKlOrPgQiDmCcCvIyAdBwOeUuLbRmScNcWxIkOkJuIsBxTrIqXhDzLcYdVtPgZdZfAxTmUtByGiTsJkSySjXdJvEwNmSmNoWsChPdAzJrBoW" }, { "input": "kHbApGoBcLmIwUlXkVgUmWzYeLoDbGaOkWbIuXoRwMfKuOoMzAoXrBoTvYxGrMbRjDuRxAbGsTnErIiHnHoLeRnTbFiRfDdOkNlWiAcOsChLdLqFqXlDpDoDtPxXqAmSvYgPvOcCpOlWtOjYwFkGkHuCaHwZcFdOfHjBmIxTeSiHkWjXyFcCtOlSuJsZkDxUgPeZkJwMmNpErUlBcGuMlJwKkWnOzFeFiSiPsEvMmQiCsYeHlLuHoMgBjFoZkXlObDkSoQcVyReTmRsFzRhTuIvCeBqVsQdQyTyZjStGrTyDcEcAgTgMiIcVkLbZbGvWeHtXwEqWkXfTcPyHhHjYwIeVxLyVmHmMkUsGiHmNnQuMsXaFyPpVqNrBhOiWmNkBbQuHvQdOjPjKiZcL", "output": "KHbApGoBcLmIwUlXkVgUmWzYeLoDbGaOkWbIuXoRwMfKuOoMzAoXrBoTvYxGrMbRjDuRxAbGsTnErIiHnHoLeRnTbFiRfDdOkNlWiAcOsChLdLqFqXlDpDoDtPxXqAmSvYgPvOcCpOlWtOjYwFkGkHuCaHwZcFdOfHjBmIxTeSiHkWjXyFcCtOlSuJsZkDxUgPeZkJwMmNpErUlBcGuMlJwKkWnOzFeFiSiPsEvMmQiCsYeHlLuHoMgBjFoZkXlObDkSoQcVyReTmRsFzRhTuIvCeBqVsQdQyTyZjStGrTyDcEcAgTgMiIcVkLbZbGvWeHtXwEqWkXfTcPyHhHjYwIeVxLyVmHmMkUsGiHmNnQuMsXaFyPpVqNrBhOiWmNkBbQuHvQdOjPjKiZcL" }, { "input": "aHmRbLgNuWkLxLnWvUbYwTeZeYiOlLhTuOvKfLnVmCiPcMkSgVrYjZiLuRjCiXhAnVzVcTlVeJdBvPdDfFvHkTuIhCdBjEsXbVmGcLrPfNvRdFsZkSdNpYsJeIhIcNqSoLkOjUlYlDmXsOxPbQtIoUxFjGnRtBhFaJvBeEzHsAtVoQbAfYjJqReBiKeUwRqYrUjPjBoHkOkPzDwEwUgTxQxAvKzUpMhKyOhPmEhYhItQwPeKsKaKlUhGuMcTtSwFtXfJsDsFlTtOjVvVfGtBtFlQyIcBaMsPaJlPqUcUvLmReZiFbXxVtRhTzJkLkAjVqTyVuFeKlTyQgUzMsXjOxQnVfTaWmThEnEoIhZeZdStBkKeLpAhJnFoJvQyGwDiStLjEwGfZwBuWsEfC", "output": "AHmRbLgNuWkLxLnWvUbYwTeZeYiOlLhTuOvKfLnVmCiPcMkSgVrYjZiLuRjCiXhAnVzVcTlVeJdBvPdDfFvHkTuIhCdBjEsXbVmGcLrPfNvRdFsZkSdNpYsJeIhIcNqSoLkOjUlYlDmXsOxPbQtIoUxFjGnRtBhFaJvBeEzHsAtVoQbAfYjJqReBiKeUwRqYrUjPjBoHkOkPzDwEwUgTxQxAvKzUpMhKyOhPmEhYhItQwPeKsKaKlUhGuMcTtSwFtXfJsDsFlTtOjVvVfGtBtFlQyIcBaMsPaJlPqUcUvLmReZiFbXxVtRhTzJkLkAjVqTyVuFeKlTyQgUzMsXjOxQnVfTaWmThEnEoIhZeZdStBkKeLpAhJnFoJvQyGwDiStLjEwGfZwBuWsEfC" }, { "input": "sLlZkDiDmEdNaXuUuJwHqYvRtOdGfTiTpEpAoSqAbJaChOiCvHgSwZwEuPkMmXiLcKdXqSsEyViEbZpZsHeZpTuXoGcRmOiQfBfApPjDqSqElWeSeOhUyWjLyNoRuYeGfGwNqUsQoTyVvWeNgNdZfDxGwGfLsDjIdInSqDlMuNvFaHbScZkTlVwNcJpEjMaPaOtFgJjBjOcLlLmDnQrShIrJhOcUmPnZhTxNeClQsZaEaVaReLyQpLwEqJpUwYhLiRzCzKfOoFeTiXzPiNbOsZaZaLgCiNnMkBcFwGgAwPeNyTxJcCtBgXcToKlWaWcBaIvBpNxPeClQlWeQqRyEtAkJdBtSrFdDvAbUlKyLdCuTtXxFvRcKnYnWzVdYqDeCmOqPxUaFjQdTdCtN", "output": "SLlZkDiDmEdNaXuUuJwHqYvRtOdGfTiTpEpAoSqAbJaChOiCvHgSwZwEuPkMmXiLcKdXqSsEyViEbZpZsHeZpTuXoGcRmOiQfBfApPjDqSqElWeSeOhUyWjLyNoRuYeGfGwNqUsQoTyVvWeNgNdZfDxGwGfLsDjIdInSqDlMuNvFaHbScZkTlVwNcJpEjMaPaOtFgJjBjOcLlLmDnQrShIrJhOcUmPnZhTxNeClQsZaEaVaReLyQpLwEqJpUwYhLiRzCzKfOoFeTiXzPiNbOsZaZaLgCiNnMkBcFwGgAwPeNyTxJcCtBgXcToKlWaWcBaIvBpNxPeClQlWeQqRyEtAkJdBtSrFdDvAbUlKyLdCuTtXxFvRcKnYnWzVdYqDeCmOqPxUaFjQdTdCtN" }, { "input": "iRuStKvVhJdJbQwRoIuLiVdTpKaOqKfYlYwAzIpPtUwUtMeKyCaOlXmVrKwWeImYmVuXdLkRlHwFxKqZbZtTzNgOzDbGqTfZnKmUzAcIjDcEmQgYyFbEfWzRpKvCkDmAqDiIiRcLvMxWaJqCgYqXgIcLdNaZlBnXtJyKaMnEaWfXfXwTbDnAiYnWqKbAtDpYdUbZrCzWgRnHzYxFgCdDbOkAgTqBuLqMeStHcDxGnVhSgMzVeTaZoTfLjMxQfRuPcFqVlRyYdHyOdJsDoCeWrUuJyIiAqHwHyVpEeEoMaJwAoUfPtBeJqGhMaHiBjKwAlXoZpUsDhHgMxBkVbLcEvNtJbGnPsUwAvXrAkTlXwYvEnOpNeWyIkRnEnTrIyAcLkRgMyYcKrGiDaAyE", "output": "IRuStKvVhJdJbQwRoIuLiVdTpKaOqKfYlYwAzIpPtUwUtMeKyCaOlXmVrKwWeImYmVuXdLkRlHwFxKqZbZtTzNgOzDbGqTfZnKmUzAcIjDcEmQgYyFbEfWzRpKvCkDmAqDiIiRcLvMxWaJqCgYqXgIcLdNaZlBnXtJyKaMnEaWfXfXwTbDnAiYnWqKbAtDpYdUbZrCzWgRnHzYxFgCdDbOkAgTqBuLqMeStHcDxGnVhSgMzVeTaZoTfLjMxQfRuPcFqVlRyYdHyOdJsDoCeWrUuJyIiAqHwHyVpEeEoMaJwAoUfPtBeJqGhMaHiBjKwAlXoZpUsDhHgMxBkVbLcEvNtJbGnPsUwAvXrAkTlXwYvEnOpNeWyIkRnEnTrIyAcLkRgMyYcKrGiDaAyE" }, { "input": "cRtJkOxHzUbJcDdHzJtLbVmSoWuHoTkVrPqQaVmXeBrHxJbQfNrQbAaMrEhVdQnPxNyCjErKxPoEdWkVrBbDeNmEgBxYiBtWdAfHiLuSwIxJuHpSkAxPoYdNkGoLySsNhUmGoZhDzAfWhJdPlJzQkZbOnMtTkClIoCqOlIcJcMlGjUyOiEmHdYfIcPtTgQhLlLcPqQjAnQnUzHpCaQsCnYgQsBcJrQwBnWsIwFfSfGuYgTzQmShFpKqEeRlRkVfMuZbUsDoFoPrNuNwTtJqFkRiXxPvKyElDzLoUnIwAaBaOiNxMpEvPzSpGpFhMtGhGdJrFnZmNiMcUfMtBnDuUnXqDcMsNyGoLwLeNnLfRsIwRfBtXkHrFcPsLdXaAoYaDzYnZuQeVcZrElWmP", "output": "CRtJkOxHzUbJcDdHzJtLbVmSoWuHoTkVrPqQaVmXeBrHxJbQfNrQbAaMrEhVdQnPxNyCjErKxPoEdWkVrBbDeNmEgBxYiBtWdAfHiLuSwIxJuHpSkAxPoYdNkGoLySsNhUmGoZhDzAfWhJdPlJzQkZbOnMtTkClIoCqOlIcJcMlGjUyOiEmHdYfIcPtTgQhLlLcPqQjAnQnUzHpCaQsCnYgQsBcJrQwBnWsIwFfSfGuYgTzQmShFpKqEeRlRkVfMuZbUsDoFoPrNuNwTtJqFkRiXxPvKyElDzLoUnIwAaBaOiNxMpEvPzSpGpFhMtGhGdJrFnZmNiMcUfMtBnDuUnXqDcMsNyGoLwLeNnLfRsIwRfBtXkHrFcPsLdXaAoYaDzYnZuQeVcZrElWmP" }, { "input": "wVaCsGxZrBbFnTbKsCoYlAvUkIpBaYpYmJkMlPwCaFvUkDxAiJgIqWsFqZlFvTtAnGzEwXbYiBdFfFxRiDoUkLmRfAwOlKeOlKgXdUnVqLkTuXtNdQpBpXtLvZxWoBeNePyHcWmZyRiUkPlRqYiQdGeXwOhHbCqVjDcEvJmBkRwWnMqPjXpUsIyXqGjHsEsDwZiFpIbTkQaUlUeFxMwJzSaHdHnDhLaLdTuYgFuJsEcMmDvXyPjKsSeBaRwNtPuOuBtNeOhQdVgKzPzOdYtPjPfDzQzHoWcYjFbSvRgGdGsCmGnQsErToBkCwGeQaCbBpYkLhHxTbUvRnJpZtXjKrHdRiUmUbSlJyGaLnWsCrJbBnSjFaZrIzIrThCmGhQcMsTtOxCuUcRaEyPaG", "output": "WVaCsGxZrBbFnTbKsCoYlAvUkIpBaYpYmJkMlPwCaFvUkDxAiJgIqWsFqZlFvTtAnGzEwXbYiBdFfFxRiDoUkLmRfAwOlKeOlKgXdUnVqLkTuXtNdQpBpXtLvZxWoBeNePyHcWmZyRiUkPlRqYiQdGeXwOhHbCqVjDcEvJmBkRwWnMqPjXpUsIyXqGjHsEsDwZiFpIbTkQaUlUeFxMwJzSaHdHnDhLaLdTuYgFuJsEcMmDvXyPjKsSeBaRwNtPuOuBtNeOhQdVgKzPzOdYtPjPfDzQzHoWcYjFbSvRgGdGsCmGnQsErToBkCwGeQaCbBpYkLhHxTbUvRnJpZtXjKrHdRiUmUbSlJyGaLnWsCrJbBnSjFaZrIzIrThCmGhQcMsTtOxCuUcRaEyPaG" }, { "input": "kEiLxLmPjGzNoGkJdBlAfXhThYhMsHmZoZbGyCvNiUoLoZdAxUbGyQiEfXvPzZzJrPbEcMpHsMjIkRrVvDvQtHuKmXvGpQtXbPzJpFjJdUgWcPdFxLjLtXgVpEiFhImHnKkGiWnZbJqRjCyEwHsNbYfYfTyBaEuKlCtWnOqHmIgGrFmQiYrBnLiFcGuZxXlMfEuVoCxPkVrQvZoIpEhKsYtXrPxLcSfQqXsWaDgVlOnAzUvAhOhMrJfGtWcOwQfRjPmGhDyAeXrNqBvEiDfCiIvWxPjTwPlXpVsMjVjUnCkXgBuWnZaDyJpWkCfBrWnHxMhJgItHdRqNrQaEeRjAuUwRkUdRhEeGlSqVqGmOjNcUhFfXjCmWzBrGvIuZpRyWkWiLyUwFpYjNmNfV", "output": "KEiLxLmPjGzNoGkJdBlAfXhThYhMsHmZoZbGyCvNiUoLoZdAxUbGyQiEfXvPzZzJrPbEcMpHsMjIkRrVvDvQtHuKmXvGpQtXbPzJpFjJdUgWcPdFxLjLtXgVpEiFhImHnKkGiWnZbJqRjCyEwHsNbYfYfTyBaEuKlCtWnOqHmIgGrFmQiYrBnLiFcGuZxXlMfEuVoCxPkVrQvZoIpEhKsYtXrPxLcSfQqXsWaDgVlOnAzUvAhOhMrJfGtWcOwQfRjPmGhDyAeXrNqBvEiDfCiIvWxPjTwPlXpVsMjVjUnCkXgBuWnZaDyJpWkCfBrWnHxMhJgItHdRqNrQaEeRjAuUwRkUdRhEeGlSqVqGmOjNcUhFfXjCmWzBrGvIuZpRyWkWiLyUwFpYjNmNfV" }, { "input": "eIhDoLmDeReKqXsHcVgFxUqNfScAiQnFrTlCgSuTtXiYvBxKaPaGvUeYfSgHqEaWcHxKpFaSlCxGqAmNeFcIzFcZsBiVoZhUjXaDaIcKoBzYdIlEnKfScRqSkYpPtVsVhXsBwUsUfAqRoCkBxWbHgDiCkRtPvUwVgDjOzObYwNiQwXlGnAqEkHdSqLgUkOdZiWaHqQnOhUnDhIzCiQtVcJlGoRfLuVlFjWqSuMsLgLwOdZvKtWdRuRqDoBoInKqPbJdXpIqLtFlMlDaWgSiKbFpCxOnQeNeQzXeKsBzIjCyPxCmBnYuHzQoYxZgGzSgGtZiTeQmUeWlNzZeKiJbQmEjIiDhPeSyZlNdHpZnIkPdJzSeJpPiXxToKyBjJfPwNzZpWzIzGySqPxLtI", "output": "EIhDoLmDeReKqXsHcVgFxUqNfScAiQnFrTlCgSuTtXiYvBxKaPaGvUeYfSgHqEaWcHxKpFaSlCxGqAmNeFcIzFcZsBiVoZhUjXaDaIcKoBzYdIlEnKfScRqSkYpPtVsVhXsBwUsUfAqRoCkBxWbHgDiCkRtPvUwVgDjOzObYwNiQwXlGnAqEkHdSqLgUkOdZiWaHqQnOhUnDhIzCiQtVcJlGoRfLuVlFjWqSuMsLgLwOdZvKtWdRuRqDoBoInKqPbJdXpIqLtFlMlDaWgSiKbFpCxOnQeNeQzXeKsBzIjCyPxCmBnYuHzQoYxZgGzSgGtZiTeQmUeWlNzZeKiJbQmEjIiDhPeSyZlNdHpZnIkPdJzSeJpPiXxToKyBjJfPwNzZpWzIzGySqPxLtI" }, { "input": "uOoQzIeTwYeKpJtGoUdNiXbPgEwVsZkAnJcArHxIpEnEhZwQhZvAiOuLeMkVqLeDsAyKeYgFxGmRoLaRsZjAeXgNfYhBkHeDrHdPuTuYhKmDlAvYzYxCdYgYfVaYlGeVqTeSfBxQePbQrKsTaIkGzMjFrQlJuYaMxWpQkLdEcDsIiMnHnDtThRvAcKyGwBsHqKdXpJfIeTeZtYjFbMeUoXoXzGrShTwSwBpQlKeDrZdCjRqNtXoTsIzBkWbMsObTtDvYaPhUeLeHqHeMpZmTaCcIqXzAmGnPfNdDaFhOqWqDrWuFiBpRjZrQmAdViOuMbFfRyXyWfHgRkGpPnDrEqQcEmHcKpEvWlBrOtJbUaXbThJaSxCbVoGvTmHvZrHvXpCvLaYbRiHzYuQyX", "output": "UOoQzIeTwYeKpJtGoUdNiXbPgEwVsZkAnJcArHxIpEnEhZwQhZvAiOuLeMkVqLeDsAyKeYgFxGmRoLaRsZjAeXgNfYhBkHeDrHdPuTuYhKmDlAvYzYxCdYgYfVaYlGeVqTeSfBxQePbQrKsTaIkGzMjFrQlJuYaMxWpQkLdEcDsIiMnHnDtThRvAcKyGwBsHqKdXpJfIeTeZtYjFbMeUoXoXzGrShTwSwBpQlKeDrZdCjRqNtXoTsIzBkWbMsObTtDvYaPhUeLeHqHeMpZmTaCcIqXzAmGnPfNdDaFhOqWqDrWuFiBpRjZrQmAdViOuMbFfRyXyWfHgRkGpPnDrEqQcEmHcKpEvWlBrOtJbUaXbThJaSxCbVoGvTmHvZrHvXpCvLaYbRiHzYuQyX" }, { "input": "lZqBqKeGvNdSeYuWxRiVnFtYbKuJwQtUcKnVtQhAlOeUzMaAuTaEnDdPfDcNyHgEoBmYjZyFePeJrRiKyAzFnBfAuGiUyLrIeLrNhBeBdVcEeKgCcBrQzDsPwGcNnZvTsEaYmFfMeOmMdNuZbUtDoQoNcGwDqEkEjIdQaPwAxJbXeNxOgKgXoEbZiIsVkRrNpNyAkLeHkNfEpLuQvEcMbIoGaDzXbEtNsLgGfOkZaFiUsOvEjVeCaMcZqMzKeAdXxJsVeCrZaFpJtZxInQxFaSmGgSsVyGeLlFgFqTpIbAvPkIfJrVcJeBxSdEvPyVwIjHpYrLrKqLnAmCuGmPoZrSbOtGaLaTmBmSuUyAmAsRiMqOtRjJhPhAfXaJnTpLbFqPmJgFcBxImTqIiJ", "output": "LZqBqKeGvNdSeYuWxRiVnFtYbKuJwQtUcKnVtQhAlOeUzMaAuTaEnDdPfDcNyHgEoBmYjZyFePeJrRiKyAzFnBfAuGiUyLrIeLrNhBeBdVcEeKgCcBrQzDsPwGcNnZvTsEaYmFfMeOmMdNuZbUtDoQoNcGwDqEkEjIdQaPwAxJbXeNxOgKgXoEbZiIsVkRrNpNyAkLeHkNfEpLuQvEcMbIoGaDzXbEtNsLgGfOkZaFiUsOvEjVeCaMcZqMzKeAdXxJsVeCrZaFpJtZxInQxFaSmGgSsVyGeLlFgFqTpIbAvPkIfJrVcJeBxSdEvPyVwIjHpYrLrKqLnAmCuGmPoZrSbOtGaLaTmBmSuUyAmAsRiMqOtRjJhPhAfXaJnTpLbFqPmJgFcBxImTqIiJ" }, { "input": "P", "output": "P" }, { "input": "Xyzzy", "output": "Xyzzy" }, { "input": "Zzz", "output": "Zzz" }, { "input": "Zp", "output": "Zp" } ]
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" }, { "input": "100\n314 905 555 526 981 360 424 104 920 814 143 872 741 592 105 573 837 962 220 692 560 493 889 824 145 491 828 960 889 87 375 486 609 423 386 323 124 830 206 446 899 522 514 696 786 783 268 483 318 261 675 445 1000 896 812 277 131 264 860 514 701 678 792 394 324 244 483 357 69 931 590 452 626 451 976 317 722 564 809 40 265 709 13 700 769 869 131 834 712 478 661 369 805 668 512 184 477 896 808 168", "output": "2\n104 905" }, { "input": "100\n174 816 593 727 182 151 842 277 1 942 307 939 447 738 823 744 319 394 515 451 875 950 319 789 384 292 190 758 927 103 246 1 675 42 398 631 382 893 646 2 773 157 992 425 804 565 500 242 2 657 611 647 4 331 99 1 694 18 119 364 458 569 94 999 72 7 297 102 982 859 786 868 178 393 642 254 707 41 103 764 934 70 775 41 188 199 767 64 84 899 626 224 279 188 659 374 105 178 154 758", "output": "4\n1 1 738 1" }, { "input": "100\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 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 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 1 1 1 1 1 1 1 1 1 1 1 1", "output": "100\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 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 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 1 1 1 1 1 1 1 1 1 1 1 1" }, { "input": "100\n966 680 370 134 202 826 254 620 700 336 938 344 368 108 732 130 134 700 996 904 644 734 184 134 996 46 146 928 320 664 304 160 358 306 330 132 674 16 338 138 926 994 196 960 972 972 756 276 600 982 588 978 868 572 446 578 692 976 780 434 882 344 980 536 856 916 966 936 178 300 294 568 984 54 238 718 582 400 572 142 118 306 222 850 948 954 682 256 70 550 830 980 646 970 688 56 552 592 200 682", "output": "1\n966" }, { "input": "100\n598 236 971 958 277 96 651 366 629 50 601 822 744 326 276 330 413 531 791 655 450 173 992 80 401 760 227 64 350 711 258 545 212 690 996 515 983 835 388 311 970 608 185 164 491 419 295 293 274 93 339 761 155 307 991 857 309 957 563 232 328 682 779 637 312 888 305 184 15 556 427 211 327 313 516 815 914 588 592 988 151 839 828 339 196 462 752 454 865 479 356 529 320 59 908 840 294 882 189 6", "output": "2\n96 277" }, { "input": "20\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 204239 1 194239 216480", "output": "18\n1 1 1 1 1 1 1 216480 1 1 1 1 1 1 1 1 1 1" }, { "input": "10\n4 3 1 1 1 1 1 1 1 1", "output": "9\n4 1 1 1 1 1 1 1 1" }, { "input": "2\n1000000 1000000", "output": "1\n1000000" }, { "input": "1\n4", "output": "1\n4" }, { "input": "1\n1", "output": "1\n1" }, { "input": "2\n999997 999994", "output": "1\n999997" }, { "input": "5\n1 1 1 8 9", "output": "3\n1 1 1" }, { "input": "3\n1 5 8", "output": "2\n8 5" }, { "input": "2\n999996 999997", "output": "2\n999997 999996" }, { "input": "2\n1 2", "output": "2\n1 2" }, { "input": "3\n1 8 9", "output": "2\n9 8" }, { "input": "2\n1 1", "output": "2\n1 1" }, { "input": "2\n1 3", "output": "1\n1" }, { "input": "3\n1 9 8", "output": "2\n8 9" }, { "input": "6\n1 3 3 3 3 20", "output": "2\n20 3" }, { "input": "1\n3", "output": "1\n3" }, { "input": "2\n3 3", "output": "1\n3" }, { "input": "5\n1 1 1 8 3", "output": "3\n1 1 1" }, { "input": "1\n9", "output": "1\n9" }, { "input": "3\n2 4 7", "output": "2\n7 4" }, { "input": "6\n2 5 1 1 1 1", "output": "5\n2 1 1 1 1" }, { "input": "3\n1 3 14", "output": "2\n14 3" }, { "input": "1\n6", "output": "1\n6" }, { "input": "3\n2 7 12", "output": "2\n12 7" }, { "input": "3\n3 6 7", "output": "2\n7 6" }, { "input": "3\n7 3 2", "output": "2\n2 3" }, { "input": "3\n1 8 5", "output": "2\n5 8" }, { "input": "2\n1000000 999993", "output": "2\n999993 1000000" }, { "input": "5\n1 5 8 1 1", "output": "3\n1 1 1" }, { "input": "1\n8", "output": "1\n8" }, { "input": "3\n1 13 13", "output": "1\n1" }, { "input": "3\n5 8 1", "output": "2\n8 5" }, { "input": "3\n8 1 5", "output": "2\n5 8" }, { "input": "3\n1 3 8", "output": "2\n8 3" }, { "input": "2\n1 9", "output": "1\n1" }, { "input": "2\n5 5", "output": "1\n5" }, { "input": "1\n5", "output": "1\n5" }, { "input": "3\n1 83 14", "output": "2\n14 83" }, { "input": "5\n123445 32892 32842 432721 39234", "output": "1\n123445" } ]
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" }, { "input": "20\n5 3 7 2 1 6 4", "output": "6" }, { "input": "10\n5 1 1 1 1 1 5", "output": "6" }, { "input": "50\n10 1 10 1 10 1 10", "output": "1" }, { "input": "77\n11 11 11 11 11 11 10", "output": "1" }, { "input": "1\n1000 1000 1000 1000 1000 1000 1000", "output": "1" }, { "input": "1000\n100 100 100 100 100 100 100", "output": "3" }, { "input": "999\n10 20 10 20 30 20 10", "output": "3" }, { "input": "433\n109 58 77 10 39 125 15", "output": "7" }, { "input": "1\n0 0 0 0 0 0 1", "output": "7" }, { "input": "5\n1 0 1 0 1 0 1", "output": "1" }, { "input": "997\n1 1 0 0 1 0 1", "output": "1" }, { "input": "1000\n1 1 1 1 1 1 1", "output": "6" }, { "input": "1000\n1000 1000 1000 1000 1000 1000 1000", "output": "1" }, { "input": "1000\n1 0 0 0 0 0 0", "output": "1" }, { "input": "1000\n0 0 0 0 0 0 1", "output": "7" }, { "input": "1000\n1 0 0 1 0 0 1", "output": "1" }, { "input": "509\n105 23 98 0 7 0 155", "output": "2" }, { "input": "7\n1 1 1 1 1 1 1", "output": "7" }, { "input": "2\n1 1 0 0 0 0 0", "output": "2" }, { "input": "1\n0 0 0 0 0 1 0", "output": "6" }, { "input": "10\n0 0 0 0 0 0 1", "output": "7" }, { "input": "5\n0 0 0 0 0 6 0", "output": "6" }, { "input": "3\n0 1 0 0 0 0 0", "output": "2" }, { "input": "10\n0 0 0 0 0 0 10", "output": "7" }, { "input": "28\n1 2 3 4 5 6 7", "output": "7" }, { "input": "100\n5 5 5 5 5 5 5", "output": "6" }, { "input": "4\n1 0 0 0 0 0 1", "output": "7" }, { "input": "2\n0 0 0 0 0 0 1", "output": "7" }, { "input": "7\n0 0 0 0 0 0 7", "output": "7" }, { "input": "7\n2 1 1 1 1 1 0", "output": "6" }, { "input": "2\n0 0 1 1 0 0 0", "output": "4" }, { "input": "6\n1 1 1 1 1 1 0", "output": "6" }, { "input": "5\n1 1 1 0 0 1 1", "output": "7" }, { "input": "100\n10 20 30 10 10 10 10", "output": "7" }, { "input": "1\n0 0 0 1 0 0 0", "output": "4" }, { "input": "70\n10 10 10 10 10 10 10", "output": "7" }, { "input": "22\n1 2 3 4 5 6 10", "output": "7" }, { "input": "5\n0 0 0 1 0 0 0", "output": "4" }, { "input": "2\n0 0 0 1 0 0 0", "output": "4" }, { "input": "6\n1 0 0 0 0 0 2", "output": "7" }, { "input": "10\n1 2 2 1 2 1 1", "output": "7" }, { "input": "5\n0 0 0 0 0 0 10", "output": "7" }, { "input": "4\n0 1 1 0 0 0 0", "output": "3" }, { "input": "100\n0 0 0 0 0 1 0", "output": "6" } ]
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 7 3\n2 0 10\n2 0 10\n1 8 2\n2 2 8\n2 6 4\n2 7 3\n2 9 1", "output": "LIVE\nDEAD" }, { "input": "12\n1 5 5\n1 0 10\n1 4 6\n1 2 8\n1 2 8\n1 5 5\n1 9 1\n2 9 1\n1 5 5\n1 1 9\n2 9 1\n2 7 3", "output": "DEAD\nLIVE" }, { "input": "13\n1 8 2\n1 4 6\n1 5 5\n1 5 5\n2 10 0\n2 9 1\n1 3 7\n2 6 4\n2 6 4\n2 5 5\n1 7 3\n2 3 7\n2 9 1", "output": "LIVE\nLIVE" }, { "input": "14\n1 7 3\n1 0 10\n1 7 3\n1 1 9\n2 2 8\n2 0 10\n1 1 9\n2 8 2\n2 6 4\n1 3 7\n1 3 7\n2 6 4\n2 1 9\n2 7 3", "output": "DEAD\nDEAD" } ]
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" }, { "input": "1\n364489807", "output": "0" }, { "input": "1\n194945396", "output": "0" }, { "input": "9\n25401015 88843847 702650194 306965770 57623156 571088345 835502151 56113403 116176210", "output": "168126961" }, { "input": "3\n855856619 518546431 920370158", "output": "604662698" }, { "input": "7\n686312223 948248999 138090108 566544521 711825575 414057105 925454439", "output": "75238511" }, { "input": "5\n516767827 377951584 355810087 196333905 38926793", "output": "733758401" }, { "input": "9\n347223417 807654168 573530036 826123287 366028010 257025851 15406743 784063803 132844347", "output": "932879531" }, { "input": "7\n177679021 237356752 791250000 455912656 693129227 678510224 60382864", "output": "14393405" }, { "input": "7\n8134640 667059306 8969950 85702040 20230430 99994612 105359016", "output": "264207095" }, { "input": "1\n911130621", "output": "0" }, { "input": "4\n1 1 8 10", "output": "108" } ]
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