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
186
A
Comparing Strings
PROGRAMMING
1,100
[ "implementation", "strings" ]
null
null
Some dwarves that are finishing the StUDY (State University for Dwarven Youngsters) Bachelor courses, have been told "no genome, no degree". That means that all dwarves should write a thesis on genome. Dwarven genome is far from simple. It is represented by a string that consists of lowercase Latin letters. Dwarf Misha has already chosen the subject for his thesis: determining by two dwarven genomes, whether they belong to the same race. Two dwarves belong to the same race if we can swap two characters in the first dwarf's genome and get the second dwarf's genome as a result. Help Dwarf Misha and find out whether two gnomes belong to the same race or not.
The first line contains the first dwarf's genome: a non-empty string, consisting of lowercase Latin letters. The second line contains the second dwarf's genome: a non-empty string, consisting of lowercase Latin letters. The number of letters in each genome doesn't exceed 105. It is guaranteed that the strings that correspond to the genomes are different. The given genomes may have different length.
Print "YES", if the dwarves belong to the same race. Otherwise, print "NO".
[ "ab\nba\n", "aa\nab\n" ]
[ "YES\n", "NO\n" ]
- First example: you can simply swap two letters in string "ab". So we get "ba". - Second example: we can't change string "aa" into string "ab", because "aa" does not contain letter "b".
500
[ { "input": "ab\nba", "output": "YES" }, { "input": "aa\nab", "output": "NO" }, { "input": "a\nza", "output": "NO" }, { "input": "vvea\nvvae", "output": "YES" }, { "input": "rtfabanpc\natfabrnpc", "output": "YES" }, { "input": "mt\ntm", "output": "YES" }, { "input": "qxolmbkkt\naovlajmlf", "output": "NO" }, { "input": "b\ng", "output": "NO" }, { "input": "ab\naba", "output": "NO" }, { "input": "ba\na", "output": "NO" }, { "input": "a\nab", "output": "NO" }, { "input": "a\naa", "output": "NO" }, { "input": "a\nz", "output": "NO" }, { "input": "aabb\nbbaa", "output": "NO" }, { "input": "ab\nbd", "output": "NO" }, { "input": "bac\ndae", "output": "NO" }, { "input": "abc\nakl", "output": "NO" }, { "input": "cb\naa", "output": "NO" }, { "input": "abaab\naabba", "output": "NO" }, { "input": "aab\naaa", "output": "NO" }, { "input": "abcde\nedcba", "output": "NO" }, { "input": "abab\nbaba", "output": "NO" }, { "input": "ab\nbac", "output": "NO" }, { "input": "abcd\naqcb", "output": "NO" }, { "input": "abc\nbad", "output": "NO" }, { "input": "ab\nca", "output": "NO" }, { "input": "abc\nab", "output": "NO" }, { "input": "ab\nbae", "output": "NO" }, { "input": "aaaabcccca\naaaadccccb", "output": "NO" }, { "input": "acaa\nabca", "output": "NO" }, { "input": "aba\naab", "output": "YES" }, { "input": "ah\nla", "output": "NO" }, { "input": "aab\naa", "output": "NO" }, { "input": "abab\nabcd", "output": "NO" }, { "input": "ed\nab", "output": "NO" } ]
1,592,500,483
2,147,483,647
Python 3
OK
TESTS
53
248
716,800
g1=input() g2=input() if len(g2)!=len(g1): print("NO"); exit() dif=0; j=k=-1 for i in range(len(g1)): if g1[i]!=g2[i]: dif+=1 if j>-1: k=i else: j=i if dif>2: break if dif!=2: print("NO") elif g1[k]==g2[j] and g1[j]==g2[k]: print("YES") else: print("NO")
Title: Comparing Strings Time Limit: None seconds Memory Limit: None megabytes Problem Description: Some dwarves that are finishing the StUDY (State University for Dwarven Youngsters) Bachelor courses, have been told "no genome, no degree". That means that all dwarves should write a thesis on genome. Dwarven genome is far from simple. It is represented by a string that consists of lowercase Latin letters. Dwarf Misha has already chosen the subject for his thesis: determining by two dwarven genomes, whether they belong to the same race. Two dwarves belong to the same race if we can swap two characters in the first dwarf's genome and get the second dwarf's genome as a result. Help Dwarf Misha and find out whether two gnomes belong to the same race or not. Input Specification: The first line contains the first dwarf's genome: a non-empty string, consisting of lowercase Latin letters. The second line contains the second dwarf's genome: a non-empty string, consisting of lowercase Latin letters. The number of letters in each genome doesn't exceed 105. It is guaranteed that the strings that correspond to the genomes are different. The given genomes may have different length. Output Specification: Print "YES", if the dwarves belong to the same race. Otherwise, print "NO". Demo Input: ['ab\nba\n', 'aa\nab\n'] Demo Output: ['YES\n', 'NO\n'] Note: - First example: you can simply swap two letters in string "ab". So we get "ba". - Second example: we can't change string "aa" into string "ab", because "aa" does not contain letter "b".
```python g1=input() g2=input() if len(g2)!=len(g1): print("NO"); exit() dif=0; j=k=-1 for i in range(len(g1)): if g1[i]!=g2[i]: dif+=1 if j>-1: k=i else: j=i if dif>2: break if dif!=2: print("NO") elif g1[k]==g2[j] and g1[j]==g2[k]: print("YES") else: print("NO") ```
3
92
A
Chips
PROGRAMMING
800
[ "implementation", "math" ]
A. Chips
2
256
There are *n* walruses sitting in a circle. All of them are numbered in the clockwise order: the walrus number 2 sits to the left of the walrus number 1, the walrus number 3 sits to the left of the walrus number 2, ..., the walrus number 1 sits to the left of the walrus number *n*. The presenter has *m* chips. The presenter stands in the middle of the circle and starts giving the chips to the walruses starting from walrus number 1 and moving clockwise. The walrus number *i* gets *i* chips. If the presenter can't give the current walrus the required number of chips, then the presenter takes the remaining chips and the process ends. Determine by the given *n* and *m* how many chips the presenter will get in the end.
The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=50, 1<=≤<=*m*<=≤<=104) — the number of walruses and the number of chips correspondingly.
Print the number of chips the presenter ended up with.
[ "4 11\n", "17 107\n", "3 8\n" ]
[ "0\n", "2\n", "1\n" ]
In the first sample the presenter gives one chip to the walrus number 1, two chips to the walrus number 2, three chips to the walrus number 3, four chips to the walrus number 4, then again one chip to the walrus number 1. After that the presenter runs out of chips. He can't give anything to the walrus number 2 and the process finishes. In the third sample the presenter gives one chip to the walrus number 1, two chips to the walrus number 2, three chips to the walrus number 3, then again one chip to the walrus number 1. The presenter has one chip left and he can't give two chips to the walrus number 2, that's why the presenter takes the last chip.
500
[ { "input": "4 11", "output": "0" }, { "input": "17 107", "output": "2" }, { "input": "3 8", "output": "1" }, { "input": "46 7262", "output": "35" }, { "input": "32 6864", "output": "0" }, { "input": "36 6218", "output": "14" }, { "input": "25 9712", "output": "11" }, { "input": "9 7601", "output": "5" }, { "input": "1 9058", "output": "0" }, { "input": "29 7772", "output": "26" }, { "input": "45 9465", "output": "14" }, { "input": "46 866", "output": "5" }, { "input": "29 1241", "output": "20" }, { "input": "17 4248", "output": "12" }, { "input": "20 8082", "output": "11" }, { "input": "50 9555", "output": "0" }, { "input": "4 7455", "output": "2" }, { "input": "36 880", "output": "4" }, { "input": "24 7440", "output": "9" }, { "input": "44 7888", "output": "12" }, { "input": "1 1", "output": "0" }, { "input": "50 10000", "output": "40" }, { "input": "1 10000", "output": "0" }, { "input": "50 1", "output": "0" }, { "input": "50 50", "output": "5" } ]
1,634,217,984
2,147,483,647
PyPy 3
OK
TESTS
25
154
0
n,m=map(int,input().split()) kk=int((n+1)*n/2) if(m>=kk): a=m%kk for i in range(n): if(a-i<0): break a-=i print(a) else: for i in range(n): if(m-i<0): break m-=i print(m)
Title: Chips Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: There are *n* walruses sitting in a circle. All of them are numbered in the clockwise order: the walrus number 2 sits to the left of the walrus number 1, the walrus number 3 sits to the left of the walrus number 2, ..., the walrus number 1 sits to the left of the walrus number *n*. The presenter has *m* chips. The presenter stands in the middle of the circle and starts giving the chips to the walruses starting from walrus number 1 and moving clockwise. The walrus number *i* gets *i* chips. If the presenter can't give the current walrus the required number of chips, then the presenter takes the remaining chips and the process ends. Determine by the given *n* and *m* how many chips the presenter will get in the end. Input Specification: The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=50, 1<=≤<=*m*<=≤<=104) — the number of walruses and the number of chips correspondingly. Output Specification: Print the number of chips the presenter ended up with. Demo Input: ['4 11\n', '17 107\n', '3 8\n'] Demo Output: ['0\n', '2\n', '1\n'] Note: In the first sample the presenter gives one chip to the walrus number 1, two chips to the walrus number 2, three chips to the walrus number 3, four chips to the walrus number 4, then again one chip to the walrus number 1. After that the presenter runs out of chips. He can't give anything to the walrus number 2 and the process finishes. In the third sample the presenter gives one chip to the walrus number 1, two chips to the walrus number 2, three chips to the walrus number 3, then again one chip to the walrus number 1. The presenter has one chip left and he can't give two chips to the walrus number 2, that's why the presenter takes the last chip.
```python n,m=map(int,input().split()) kk=int((n+1)*n/2) if(m>=kk): a=m%kk for i in range(n): if(a-i<0): break a-=i print(a) else: for i in range(n): if(m-i<0): break m-=i print(m) ```
3.9615
119
A
Epic Game
PROGRAMMING
800
[ "implementation" ]
null
null
Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number *a* and Antisimon receives number *b*. They also have a heap of *n* stones. The players take turns to make a move and Simon starts. During a move a player should take from the heap the number of stones equal to the greatest common divisor of the fixed number he has received and the number of stones left in the heap. A player loses when he cannot take the required number of stones (i. e. the heap has strictly less stones left than one needs to take). Your task is to determine by the given *a*, *b* and *n* who wins the game.
The only string contains space-separated integers *a*, *b* and *n* (1<=≤<=*a*,<=*b*,<=*n*<=≤<=100) — the fixed numbers Simon and Antisimon have received correspondingly and the initial number of stones in the pile.
If Simon wins, print "0" (without the quotes), otherwise print "1" (without the quotes).
[ "3 5 9\n", "1 1 100\n" ]
[ "0", "1" ]
The greatest common divisor of two non-negative integers *a* and *b* is such maximum positive integer *k*, that *a* is divisible by *k* without remainder and similarly, *b* is divisible by *k* without remainder. Let *gcd*(*a*, *b*) represent the operation of calculating the greatest common divisor of numbers *a* and *b*. Specifically, *gcd*(*x*, 0) = *gcd*(0, *x*) = *x*. In the first sample the game will go like that: - Simon should take *gcd*(3, 9) = 3 stones from the heap. After his move the heap has 6 stones left.- Antisimon should take *gcd*(5, 6) = 1 stone from the heap. After his move the heap has 5 stones left.- Simon should take *gcd*(3, 5) = 1 stone from the heap. After his move the heap has 4 stones left.- Antisimon should take *gcd*(5, 4) = 1 stone from the heap. After his move the heap has 3 stones left.- Simon should take *gcd*(3, 3) = 3 stones from the heap. After his move the heap has 0 stones left.- Antisimon should take *gcd*(5, 0) = 5 stones from the heap. As 0 &lt; 5, it is impossible and Antisimon loses. In the second sample each player during each move takes one stone from the heap. As *n* is even, Antisimon takes the last stone and Simon can't make a move after that.
500
[ { "input": "3 5 9", "output": "0" }, { "input": "1 1 100", "output": "1" }, { "input": "23 12 16", "output": "1" }, { "input": "95 26 29", "output": "1" }, { "input": "73 32 99", "output": "1" }, { "input": "1 1 1", "output": "0" }, { "input": "41 12 65", "output": "1" }, { "input": "13 61 100", "output": "1" }, { "input": "100 100 10", "output": "0" }, { "input": "12 24 26", "output": "1" }, { "input": "73 21 96", "output": "1" }, { "input": "17 22 81", "output": "1" }, { "input": "14 88 97", "output": "1" }, { "input": "42 81 17", "output": "0" }, { "input": "34 36 19", "output": "1" }, { "input": "21 87 12", "output": "1" }, { "input": "97 92 98", "output": "1" }, { "input": "49 25 62", "output": "1" }, { "input": "29 17 44", "output": "1" }, { "input": "10 1 10", "output": "0" }, { "input": "99 98 100", "output": "1" }, { "input": "100 100 1", "output": "0" }, { "input": "11 99 55", "output": "0" }, { "input": "8 13 21", "output": "0" }, { "input": "34 55 89", "output": "0" }, { "input": "21 34 55", "output": "1" }, { "input": "13 21 34", "output": "1" }, { "input": "34 21 55", "output": "0" }, { "input": "10 20 84", "output": "1" }, { "input": "4 2 5", "output": "0" }, { "input": "3 2 3", "output": "0" }, { "input": "31 23 1", "output": "0" }, { "input": "100 100 100", "output": "0" }, { "input": "100 1 100", "output": "0" }, { "input": "1 100 100", "output": "1" }, { "input": "1 1 100", "output": "1" }, { "input": "17 23 100", "output": "1" }, { "input": "99 98 100", "output": "1" }, { "input": "1 1 2", "output": "1" }, { "input": "2 1 1", "output": "0" }, { "input": "1 2 1", "output": "0" }, { "input": "2 1 2", "output": "0" }, { "input": "10 10 3", "output": "1" }, { "input": "2 2 1", "output": "0" }, { "input": "9 5 1", "output": "0" } ]
1,589,185,770
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
8
278
20,172,800
a,b,n=map(int,input().split()) if (a+b)%2!=0: print(1) elif (a+b)%2==0: if n%2==0: print(1) else: print(0)
Title: Epic Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number *a* and Antisimon receives number *b*. They also have a heap of *n* stones. The players take turns to make a move and Simon starts. During a move a player should take from the heap the number of stones equal to the greatest common divisor of the fixed number he has received and the number of stones left in the heap. A player loses when he cannot take the required number of stones (i. e. the heap has strictly less stones left than one needs to take). Your task is to determine by the given *a*, *b* and *n* who wins the game. Input Specification: The only string contains space-separated integers *a*, *b* and *n* (1<=≤<=*a*,<=*b*,<=*n*<=≤<=100) — the fixed numbers Simon and Antisimon have received correspondingly and the initial number of stones in the pile. Output Specification: If Simon wins, print "0" (without the quotes), otherwise print "1" (without the quotes). Demo Input: ['3 5 9\n', '1 1 100\n'] Demo Output: ['0', '1'] Note: The greatest common divisor of two non-negative integers *a* and *b* is such maximum positive integer *k*, that *a* is divisible by *k* without remainder and similarly, *b* is divisible by *k* without remainder. Let *gcd*(*a*, *b*) represent the operation of calculating the greatest common divisor of numbers *a* and *b*. Specifically, *gcd*(*x*, 0) = *gcd*(0, *x*) = *x*. In the first sample the game will go like that: - Simon should take *gcd*(3, 9) = 3 stones from the heap. After his move the heap has 6 stones left.- Antisimon should take *gcd*(5, 6) = 1 stone from the heap. After his move the heap has 5 stones left.- Simon should take *gcd*(3, 5) = 1 stone from the heap. After his move the heap has 4 stones left.- Antisimon should take *gcd*(5, 4) = 1 stone from the heap. After his move the heap has 3 stones left.- Simon should take *gcd*(3, 3) = 3 stones from the heap. After his move the heap has 0 stones left.- Antisimon should take *gcd*(5, 0) = 5 stones from the heap. As 0 &lt; 5, it is impossible and Antisimon loses. In the second sample each player during each move takes one stone from the heap. As *n* is even, Antisimon takes the last stone and Simon can't make a move after that.
```python a,b,n=map(int,input().split()) if (a+b)%2!=0: print(1) elif (a+b)%2==0: if n%2==0: print(1) else: print(0) ```
0
37
A
Towers
PROGRAMMING
1,000
[ "sortings" ]
A. Towers
2
256
Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same. Vasya wants to construct the minimal number of towers from the bars. Help Vasya to use the bars in the best way possible.
The first line contains an integer *N* (1<=≤<=*N*<=≤<=1000) — the number of bars at Vasya’s disposal. The second line contains *N* space-separated integers *l**i* — the lengths of the bars. All the lengths are natural numbers not exceeding 1000.
In one line output two numbers — the height of the largest tower and their total number. Remember that Vasya should use all the bars.
[ "3\n1 2 3\n", "4\n6 5 6 7\n" ]
[ "1 3\n", "2 3\n" ]
none
500
[ { "input": "3\n1 2 3", "output": "1 3" }, { "input": "4\n6 5 6 7", "output": "2 3" }, { "input": "4\n3 2 1 1", "output": "2 3" }, { "input": "4\n1 2 3 3", "output": "2 3" }, { "input": "3\n20 22 36", "output": "1 3" }, { "input": "25\n47 30 94 41 45 20 96 51 110 129 24 116 9 47 32 82 105 114 116 75 154 151 70 42 162", "output": "2 23" }, { "input": "45\n802 664 442 318 318 827 417 878 711 291 231 414 807 553 657 392 279 202 386 606 465 655 658 112 887 15 25 502 95 44 679 775 942 609 209 871 31 234 4 231 150 110 22 823 193", "output": "2 43" }, { "input": "63\n93 180 116 7 8 179 268 279 136 94 221 153 264 190 278 19 19 63 153 26 158 225 25 49 89 218 111 149 255 225 197 122 243 80 3 224 107 178 202 17 53 92 69 42 228 24 81 205 95 8 265 82 228 156 127 241 172 159 106 60 67 155 111", "output": "2 57" }, { "input": "83\n246 535 994 33 390 927 321 97 223 922 812 705 79 80 977 457 476 636 511 137 6 360 815 319 717 674 368 551 714 628 278 713 761 553 184 414 623 753 428 214 581 115 439 61 677 216 772 592 187 603 658 310 439 559 870 376 109 321 189 337 277 26 70 734 796 907 979 693 570 227 345 650 737 633 701 914 134 403 972 940 371 6 642", "output": "2 80" }, { "input": "105\n246 57 12 204 165 123 246 68 191 310 3 152 386 333 374 257 158 104 333 50 80 290 8 340 101 76 221 316 388 289 138 359 316 26 93 290 105 178 81 195 41 196 218 180 244 292 187 97 315 323 174 119 248 239 92 312 31 2 101 180 307 170 338 314 163 281 217 31 142 238 280 190 190 156 70 74 329 113 151 8 141 313 366 40 253 116 168 124 135 230 294 266 353 389 371 359 195 200 183 237 93 102 315 118 188", "output": "2 92" }, { "input": "123\n112 277 170 247 252 115 157 293 256 143 196 90 12 164 164 42 8 223 167 109 175 232 239 111 148 51 9 254 93 32 268 162 231 91 47 162 161 191 195 145 247 292 129 199 230 94 144 217 18 205 176 20 143 198 121 243 211 262 230 277 195 255 108 290 220 275 158 2 286 200 60 267 278 207 123 150 123 116 131 13 12 226 33 244 30 275 263 45 158 192 254 149 242 176 62 224 221 288 250 160 155 225 132 143 276 293 218 145 197 175 33 129 79 206 210 192 222 262 190 52 274 243 233", "output": "3 101" }, { "input": "5\n5 5 5 5 5", "output": "5 1" }, { "input": "3\n1000 1000 1000", "output": "3 1" }, { "input": "1\n1000", "output": "1 1" }, { "input": "1\n1", "output": "1 1" }, { "input": "5\n1 1000 1000 1000 1000", "output": "4 2" }, { "input": "5\n1000 1000 1000 8 7", "output": "3 3" } ]
1,653,827,974
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
62
0
x = input() bars = x.split(' ') array = [] for i in bars: array.append(int(i)) array.sort() length = len(array) ans = 1 maxheight = 1 for i in range(len(array) - 1): if array[i] == array[i + 1]: maxheight += 1 else: ans += 1 print(maxheight, ans)
Title: Towers Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same. Vasya wants to construct the minimal number of towers from the bars. Help Vasya to use the bars in the best way possible. Input Specification: The first line contains an integer *N* (1<=≤<=*N*<=≤<=1000) — the number of bars at Vasya’s disposal. The second line contains *N* space-separated integers *l**i* — the lengths of the bars. All the lengths are natural numbers not exceeding 1000. Output Specification: In one line output two numbers — the height of the largest tower and their total number. Remember that Vasya should use all the bars. Demo Input: ['3\n1 2 3\n', '4\n6 5 6 7\n'] Demo Output: ['1 3\n', '2 3\n'] Note: none
```python x = input() bars = x.split(' ') array = [] for i in bars: array.append(int(i)) array.sort() length = len(array) ans = 1 maxheight = 1 for i in range(len(array) - 1): if array[i] == array[i + 1]: maxheight += 1 else: ans += 1 print(maxheight, ans) ```
0
335
B
Palindrome
PROGRAMMING
1,900
[ "constructive algorithms", "dp" ]
null
null
Given a string *s*, determine if it contains any palindrome of length exactly 100 as a subsequence. If it has any, print any one of them. If it doesn't have any, print a palindrome that is a subsequence of *s* and is as long as possible.
The only line of the input contains one string *s* of length *n* (1<=≤<=*n*<=≤<=5·104) containing only lowercase English letters.
If *s* contains a palindrome of length exactly 100 as a subsequence, print any palindrome of length 100 which is a subsequence of *s*. If *s* doesn't contain any palindromes of length exactly 100, print a palindrome that is a subsequence of *s* and is as long as possible. If there exists multiple answers, you are allowed to print any of them.
[ "bbbabcbbb\n", "rquwmzexectvnbanemsmdufrg\n" ]
[ "bbbcbbb\n", "rumenanemur\n" ]
A subsequence of a string is a string that can be derived from it by deleting some characters without changing the order of the remaining characters. A palindrome is a string that reads the same forward or backward.
1,000
[ { "input": "bbbabcbbb", "output": "bbbcbbb" }, { "input": "rquwmzexectvnbanemsmdufrg", "output": "rumenanemur" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" }, { "input": "ab", "output": "a" }, { "input": "abacaba", "output": "abacaba" }, { "input": "startcup", "output": "trt" }, { "input": "aabccb", "output": "bccb" }, { "input": "abbacc", "output": "abba" }, { "input": "iwlauggytlpahjhteurdyoaulbnnhashwktxlrhpgqnypnuitmfhhbkwysjuhljshaanowhngeaumdovrlvuofzsbhhzdyngntdu", "output": "ugyhhurounhashwkhnpnhkwhsahnuoruhhygu" }, { "input": "zypzepzqni", "output": "zpepz" }, { "input": "a", "output": "a" }, { "input": "oliifeuoyzhkootktyulrxshmboejshoguwgufxpuloouoojovufukdokoeyouzihyaeuucutypfxictojtnfoouoniuyuvkrglsueihpuxsulrrifyuwuyolutotzozsvhoyjxuguecywbfuuqmpzooojergudvwucsocoojfplaulvfpcooxxublcfpguuoouooouo", "output": "ouooouoougpluoovufudooozuucuxjoouoyurlsupuslruyouoojxucuuzooodufuvooulpguoouooouo" }, { "input": "kyzxnaiwjgnotlekhycrnapekfcfxydbvnjboevgdzgigxvijgwrqnacumglzlxkcurmqmxzxxbuxlwruycdhzzdmtvobmvylyibyynjvonmbwvwqzmidfhnndecrwyfxjxwquiubrimmcwoeecotwnkfrojwuxmficzurwaqljfvdcvixcictxfzztzzbvbdypayhay", "output": "yahyapydbvbzixijqauzcurmmbuxwrcdhdmvbmvyybyyvmbvmdhdcrwxubmmruczuaqjixizbvbdypayhay" }, { "input": "carfnnnuxxbntssoxafxxbbxnonpunapjxtxexlptcwqxkjnxaanntriyunvnoxkdxnsxjxxoixyplkvxctuoenxxjixxgyxlgnxhklxqxqzxafxcnealxxwspbpcfgpnnovwrnnaxjcjpnierselogxxcxrxnlpnkbzjnqvrkurhxaxyjxxnxxnpipuntongeuusujf", "output": "fnnuxxnxxxxnnpnxxxlpcjxannrvoxxnxxxxlkxnxxixxnxklxxxxnxxovrnnaxjcplxxxnpnnxxxxnxxunnf" }, { "input": "yggmkggmvkfmmsvijnyvwgswdpwkwvmcmmswksmhwwmmgwzgwkkwogwiglwggwwnmwgkqggkugwmfwawxggrwgwclgwclknltxrkjwogwejgeymtmwziwmskrwsmfmmiwkwwvsgwsdmmkfmggkmpgg", "output": "ggmkggmfmmswgswwkwmmmswksmwwmmgwgwkkwgwgwggwwmwgkggkgwmwwggwgwgwkkwgwgmmwwmskwsmmmwkwwsgwsmmfmggkmgg" }, { "input": "mstmytylsulbuhumamahahbbmmtttmlulhamyhlmbulyylubmlhymahlulmtttmmbbhahamamuhubluslytymtsmxp", "output": "mstmytylsulbuhumamahahbbmmtttmlulhamyhlmbulyylubmlhymahlulmtttmmbbhahamamuhubluslytymtsm" }, { "input": "ouwvwggffgoowjzkzeggbzieagwwznzzzlwvzswfznvozveezgopefecoezfsofqzqfoovaofwzgefzzweggvztzvofgevivgevwwslhofzwopopzzgfvwzeogovvgzdzafgwzshovvrwwwgmooczezivfwgybgezogsmgfgwwzevvwgeehwvegfdzgzwgzoffgteztwvgwfvogeggfogkeovxzzlzzwzzlvifgxzwvrogeeeggeoefhhzoweerwvxofgvwovozwvizofzogozgwevwllexooktoggvoeowgtezffzfdohvgmofofvwzzofwvwsfbwyzzziofvfcofmzgrofzozzgghseafefdpwwwogpzzfowfhlsoeitfogeezfagofqqesocewfpwveozeenwsvffzwozwzlwoeffzonveaivgfebvegveozzfoowzwzkwezjeeuwzgezoovwwgzgzggwzowzevwfgggoozfozfwg", "output": "gzoggwveoggvoegezfzovgofowzzowvswzovfcofzgofosfwozzowfsofogzfocfvozwsvwozzwofogvozfzegeovggoevwggozg" }, { "input": "gamjuklsvzwddaocadujdmvlenyyvlflipneqofeyipmtunbdmbdyhkovnpdetueeiunsipowrhxrhtastjniqdhmehcumdcrghewljvpikcraoouhfwtnoaukbnykjapkvyakdnckkypargamvnsqtchesbmuffqqycnjvolmtpjfykvkeexkpdxjexrvdzpcbthhkxuucermkaebrvcxoovidpqnpkgbhiatyjvumihptrigqxsemqbbxwmyunmmayubqqjaioqmzyekhtqgoockiskyqihopmkastfvqiewtbtbriuyuszlndcweuhnywlkjgerqokxsxfxeaxcuwoocoonstwlxujrynkwzshpretbhlvkxyebnhafxfelpmqfkksurrfqeaykdxihtyqpaiftigdwkraxxzxkqicnfxlxhxwtkkknurzubtkivzpmlfebzduezuqeyequvyrighfzyldxenwxokumxtiieeeuku", "output": "uuemkexdhiyvuqequuzefvitbuzunkkxxfxxxrkwpthxyaeqfrrfqeayxhtpwkrxxxfxxkknuzubtivfezuuqequvyihdxekmeuu" }, { "input": "qpjnbjhmigtgtxolifwoyatdlqtejqovaslcgjufverrnkqxtsrrytqgtuikcseggjnltpggcpjizojthwycibvnvxetibpicujwmyzcojhpftttwvtlxaeefbvbvygouinnjrwuczlplbzahqciptrlrcuamyntvrzqxrnkrczmluocsuthwaptenwysoviwwcnrljuskynomlpslqyjcauagiveunrzognltohqxggprgreezjsqchcgihzbrleuwgnlsqeenybrbsqcnnlbipajlcfmajtchblnxsnegooewupmvufzbipnyjneuwelibvhoghtqpvqjehvpbiclalyzxzqwekemnsjabyzatjgzbrheubuzrcgtxvaokzapejesjntgnriupahoeousszcqprljhhgnqclbsuvvgfudhwmabfbyqjcqqgnnoocqxbyjpmvncmcieavcstjvvzgtbgcjbqnqbpueqlgibtvjpzsan", "output": "nspjvglqeqcgbgsenybqcnncjbwuvublghpqehpinsjazatgruurgtazajsnipheqphglbuvuwbjcnncqbynesgbgcqeqlgvjpsn" }, { "input": "nwgwxgxlbgbgnvqowqqocgwwnbnoqghxwxbbonxxgongqwbbxxbbwiqgnogxxnobmbxwxlgqonbnwhewgoqqwoqngbgbxgxwgwna", "output": "nwgwxgxbgbgnqowqqogwwnbnoqgxwxbbonxxgongqwbbxxbbwqgnogxxnobbxwxgqonbnwwgoqqwoqngbgbxgxwgwn" }, { "input": "vtaavlavalbvbbbccccddddeeeefltfffgvgvgtghlhhhiviiijjjjkkkkmmmmnnnlnooooppppqqvqqrrrrssssluuuvuwwwwtv", "output": "vtvlvlvltgvgvgtlvlvlvtv" }, { "input": "iuaiubcide", "output": "iuiui" }, { "input": "aavaaaadbbbddbbdbccccwvcceveeeedeffvdfvfffdggggvwgghhdhdwdhhhwiiwiiiiwjjjjjjkkkkdkklwvlllllmmmmmmvdnndnwndnndooowoooppppppwqwqdwqwqwdqqrdrwdrrrrsdssssvsttttttuvuuuwuuxxxdwwxwxdxyyyywyddwvdvdvdvvwddddv", "output": "vddddwvvdvdvdvwddwdwwwdwvvddwdqqdwqwqwdqqdwddvvwdwwwdwddwvdvdvdvvwddddv" }, { "input": "ibbbbiabbibbscccocccccdsdyddiddishddffjifhfffjffgggeggeggjgkkkjkkjkkklllaellllhlmymmmmssmmomnnanojennosasoennnjpopaopppspsyphepqaqqqjqqjqqrrjerrerrrrttttttttuuuujuhuiuuwwjwhswwwiwwxixxxyxsosixxxaizzzi", "output": "iiaisosyiishjihjeejjjaehyssoaojnnosasonnjoaossyheajjjeejhijhsiiysosiaii" }, { "input": "ataaaamabbbbtmbbmtmtccctcttcmmcmtdmmmmmddddtdmeetmtmmeteteeftffmfffgmmggggmgmmhmhhhmhhiimtiiititmmjjjtjjjkkmtmtkmkmkklllmllmmtmlnmnnmnnnootooooptpppttppqmqqtqmqqmtmrrrtrrrssssssuuuuuuvvvvvvwwwwwwxxxxx", "output": "tmtmmtmttttmmmtmmmmmtmtmtmmtttmmmgggggmmmtttmmtmtmtmmmmmtmmmttttmtmmtmt" }, { "input": "agqdhdgqgannagbqbbhddddcgngchnhdceeqefqhgfdngfdhiiidhjgqjjndqkgqnkkgqqndlldlqqmddmmnqoqgnoqgqdopnqghdhdgpndpghqrrqdhrsnhgnssgddddhtttqgnnguqgudhuvvdqg", "output": "gqdhdgqgnngqhddddgnghnhdqqhgdngdhdhgqndqgqngqqnddqqddnqqgnqgqdnqghdhdgndghqqdhnhgngddddhqgnngqgdhdqg" }, { "input": "hyhwkyvfpfpykwhchycwcpfppcuvuvupshcwwkwucpkppkpcuwkwwchspuvuvaucppfbpcwcyhchwkypfpfvykwhyh", "output": "hyhwkyvfpfpykwhchycwcpfppcuvuvupshcwwkwucpkppkpcuwkwwchspuvuvucppfpcwcyhchwkypfpfvykwhyh" }, { "input": "dpddpdddddidtddudddddqddddddddddddddddddddddcdddddddddddddddkkdddddgdddddddddjkdovfvvgnnvvvvvvvvvvnvvvvvkvvvvfnvuuvevvvfvvvpvvvkvvvvvvvvvlvvvifvvvvklvbvvovovvvvkvivnvvvvvvulvvvwwmjwtwwbwlwwwwwwwwwwpewewwwwwpwwwwwwwwwwwwwwwwwwlwbtwwwwjwmwwwwwlwwuwnwwwwiwwkwwwwwwwwxxxxxxoxxxoxxxbxxxxlxxxxxxxxxxxxxxxxkxxxxfixlxxxxxkpxfxxxxxxxxxxxxxexxxuuxxxxxxxxxyynyyyyyyyyyyfkyynynyynyyyyyyygyyyyyyyyyyyyyfyyoyyyyyyykyyyyyyjyyyyyyygykyykyyycyyqyzzzzzzzzzzzzzzzzzzuzzzzzzzzzzztzzzizppzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz", "output": "pnuuefpklifklboowwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwooblkfilkpfeuunp" }, { "input": "aaaaaaaaakaaakaaaaaabbbbbbbbbbbxbbxbkbbbkxbcccccccccicccccccccddkdxdddkdkddddddkdddddikekeeeeeeeekeeeeeeeixieeffxfffffffffifffffffgikiigggggggggiggggggxgghhhhhkhhhhhhhhhhxhhhjjjjjiijjjjijjjjjxkjkjjjllllllllllkllllllllmmmmmimmmmmmmmmmmmmnnnnnnnnnnnnnnnknnnoooookooioooxioooooooopppppppppppippppxkpkkkppqqxqqqqqqqqiqiqqqqxiqqkqrrkrrrirrrrrrrrrrrrrssskskskssssssssxsssssiittttittxtttttttktttttuxuuuuuiiuuuuuuuuuuikuuvvvvivvixvvvvvvvvvivvvwxiwwwwwwwwwwwkwkwkwwwiwykyyyyyykyyykyxyyyyyyyzzzzzkzizzzzxkkxxkk", "output": "kxkkxikxkkkikkkixixiikiiixkxiiixkkkikkixippppppppppppppppppixikkikkkxiiixkxiiikiixixikkkikkkxkixkkxk" }, { "input": "aaaaaakaaaaaaaaaaaataaabbbbrbbbbbbbbbxbbbbbxbbbkctcccccccccccccncckcccccnddddrdddddddddddddddddnteeeeeeeeeeneteeneeeeeeeefffffffffnnffffffffnffffgggggggggtrgggrggggggggghhhhhhhhhnhhxhhhhhhhkhhhitiiiiiiiintiiiikiiiiiiiijxjjjjjjxjjjkjjjjjjjtjjjjlllllntllllllllllllkllllmmxmmmmmmmmmmmmmmmmmmmoooooooooooooonoooooooppprpppprppppptppnpppppppqqqqnnqqqqqqqqqqqqqqqqqssnsssssssstssnssssstssssuunuuuuuruunuuuuuuuukuuuuvvvvvvvvvvvvnvvvvvvvvvwwtwwwwwwwwkwwwwwwwwwxwwyyyyyyxyyyyyyyryyyyyyyyzzzzzzzztzzzzzzzkzzzzz", "output": "ktrxxktnknrntntnnnntrrnxktnjjjjjjjjjjkjjjjjjjjjjntkxnrrtnnnntntnrnkntkxxrtk" }, { "input": "afcyfydfxueffbukxgbhfkuufkbubkxiybuuufffkkyyxxbxfbffffbfxbxjxylykkmfffuuubyxkbubkfuukfbxkubffuxfyfyf", "output": "fyfyfxuffbukxbfkuufkbubkxybuuufffkkyyxxbxfbffffbfxbxxyykkfffuuubyxkbubkfuukfbxkubffuxfyfyf" }, { "input": "b", "output": "b" }, { "input": "abababbabbabbabbbbbbbbabbabbaaaaaaaabbbabbabbbabbbabaaabbaba", "output": "ababbaababbbbbbabbabbaaaaaaaabbabbabbbbbbabaabbaba" }, { "input": "ttabacabadabffacavvbaeabacabadabacabafabacabavvvvdabacabzaeabacabadabacttttafba", "output": "abacabadabacabaeabacabadabacabafabacabadabacabaeabacabadabacaba" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbcccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccdddddddddddddddeeeeeeeeeeeeeeeeeeeeeeeeee", "output": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbcccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccdddddddddddddddeeeeeeeeeeeeeeeeeeeeeeeeee", "output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbcccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccdddddddddddddddeeeeeeeeeeeeeeeeeeeeeeeeeezzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz", "output": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz" }, { "input": "qwertyuioplkjhgfdsazxcvbnm", "output": "q" }, { "input": "abaabacdefgb", "output": "abaaba" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaazaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" }, { "input": "gsayhacnaqwakieoeyomukmqueosoeuckuotyadhoniaovwgnbcpczjnibhgyapqmuosbrpqwkckqjakqjeamyqqwskmoueaakfixextmcwyaqdhtlylnowuiaaoraeskkqaohbwcupgsdcngyavctnaqaaaqomimemckzkaagaebucmjuwacaoicyoywkwmogdiknzqiakackvzgrywxfiojdkopsnsifwwcwkwuqqpfpuaeigcfjebbuakkaquajyelivanwewaq", "output": "qwaieyuqueeukodoiwgcznigowkcaawmueaakemaqtynuoakkaounytqamekaaeumwaackwoginzcgwiodokueeuquyeiawq" }, { "input": "amltiwwuisnsaghiiwoaqgdgnpqkfudobascczacwipotugyeairyrcsgsuxxttsxaausijymcceapckvxfqnqdg", "output": "gdnqfcacyisuxttxusiycacfqndg" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" }, { "input": "abababababababababababababababababababababababababcbababababababababababababababababababababababababa", "output": "abababababababababababababababababababababababababbababababababababababababababababababababababababa" }, { "input": "aaaaaaaaaabbbbbbbbbbccccccccccddddddddddeeeeeeeeeefeeeeeeeeeeddddddddddccccccccccbbbbbbbbbbaaaaaaaaaa", "output": "aaaaaaaaaabbbbbbbbbbccccccccccddddddddddeeeeeeeeeeeeeeeeeeeeddddddddddccccccccccbbbbbbbbbbaaaaaaaaaa" } ]
1,587,732,462
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
2
2,000
10,240,000
# https://codeforces.com/problemset/problem/1324/B # p(i, j) = p(i+1, j) (if character i is not in substring) # or p(i+1, k) (where k is the location of the last occurence of a[i]) def p(i, j, level): global a if i > j or level >= 50: return '' elif i == j: return a[i] palin1 = p(i+1, j, level) for k in range(j, i, -1): if a[i] == a[k]: palin2 = p(i+1, k-1, level+1) if len(palin1) > len(palin2) + 2: return palin1 else: return a[i] + palin2 + a[i] return palin1 a = list(input()) print(p(0, len(a) - 1, 0))
Title: Palindrome Time Limit: None seconds Memory Limit: None megabytes Problem Description: Given a string *s*, determine if it contains any palindrome of length exactly 100 as a subsequence. If it has any, print any one of them. If it doesn't have any, print a palindrome that is a subsequence of *s* and is as long as possible. Input Specification: The only line of the input contains one string *s* of length *n* (1<=≤<=*n*<=≤<=5·104) containing only lowercase English letters. Output Specification: If *s* contains a palindrome of length exactly 100 as a subsequence, print any palindrome of length 100 which is a subsequence of *s*. If *s* doesn't contain any palindromes of length exactly 100, print a palindrome that is a subsequence of *s* and is as long as possible. If there exists multiple answers, you are allowed to print any of them. Demo Input: ['bbbabcbbb\n', 'rquwmzexectvnbanemsmdufrg\n'] Demo Output: ['bbbcbbb\n', 'rumenanemur\n'] Note: A subsequence of a string is a string that can be derived from it by deleting some characters without changing the order of the remaining characters. A palindrome is a string that reads the same forward or backward.
```python # https://codeforces.com/problemset/problem/1324/B # p(i, j) = p(i+1, j) (if character i is not in substring) # or p(i+1, k) (where k is the location of the last occurence of a[i]) def p(i, j, level): global a if i > j or level >= 50: return '' elif i == j: return a[i] palin1 = p(i+1, j, level) for k in range(j, i, -1): if a[i] == a[k]: palin2 = p(i+1, k-1, level+1) if len(palin1) > len(palin2) + 2: return palin1 else: return a[i] + palin2 + a[i] return palin1 a = list(input()) print(p(0, len(a) - 1, 0)) ```
0
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,694,453,696
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
60
0
def count_lucky_digits(number): return sum(1 for digit in str(number) if is_lucky_digit(digit)) n = int(input()) lucky_digit_count = count_lucky_digits(n) if is_lucky_number(lucky_digit_count): 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 count_lucky_digits(number): return sum(1 for digit in str(number) if is_lucky_digit(digit)) n = int(input()) lucky_digit_count = count_lucky_digits(n) if is_lucky_number(lucky_digit_count): print("YES") else: print("NO") ```
-1
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,457,312,642
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
4
1,000
0
n = int(input()) test = '' count = 0 for i in range(1,n+1): test = str(i) count = count +len(test) print(count)
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 n = int(input()) test = '' count = 0 for i in range(1,n+1): test = str(i) count = count +len(test) print(count) ```
0
596
B
Wilbur and Array
PROGRAMMING
1,100
[ "greedy", "implementation" ]
null
null
Wilbur the pig is tinkering with arrays again. He has the array *a*1,<=*a*2,<=...,<=*a**n* initially consisting of *n* zeros. At one step, he can choose any index *i* and either add 1 to all elements *a**i*,<=*a**i*<=+<=1,<=... ,<=*a**n* or subtract 1 from all elements *a**i*,<=*a**i*<=+<=1,<=...,<=*a**n*. His goal is to end up with the array *b*1,<=*b*2,<=...,<=*b**n*. Of course, Wilbur wants to achieve this goal in the minimum number of steps and asks you to compute this value.
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the length of the array *a**i*. Initially *a**i*<==<=0 for every position *i*, so this array is not given in the input. The second line of the input contains *n* integers *b*1,<=*b*2,<=...,<=*b**n* (<=-<=109<=≤<=*b**i*<=≤<=109).
Print the minimum number of steps that Wilbur needs to make in order to achieve *a**i*<==<=*b**i* for all *i*.
[ "5\n1 2 3 4 5\n", "4\n1 2 2 1\n" ]
[ "5", "3" ]
In the first sample, Wilbur may successively choose indices 1, 2, 3, 4, and 5, and add 1 to corresponding suffixes. In the second sample, Wilbur first chooses indices 1 and 2 and adds 1 to corresponding suffixes, then he chooses index 4 and subtract 1.
1,000
[ { "input": "5\n1 2 3 4 5", "output": "5" }, { "input": "4\n1 2 2 1", "output": "3" }, { "input": "3\n1 2 4", "output": "4" }, { "input": "6\n1 2 3 6 5 4", "output": "8" }, { "input": "10\n2 1 4 3 6 5 8 7 10 9", "output": "19" }, { "input": "7\n12 6 12 13 4 3 2", "output": "36" }, { "input": "15\n15 14 13 1 2 3 12 11 10 4 5 6 9 8 7", "output": "55" }, { "input": "16\n1 2 3 4 13 14 15 16 9 10 11 12 5 6 7 8", "output": "36" }, { "input": "6\n1000 1 2000 1 3000 1", "output": "11995" }, { "input": "1\n0", "output": "0" }, { "input": "5\n1000000000 1 1000000000 1 1000000000", "output": "4999999996" }, { "input": "5\n1000000000 0 1000000000 0 1000000000", "output": "5000000000" }, { "input": "10\n1000000000 0 1000000000 0 1000000000 0 1000000000 0 1000000000 0", "output": "10000000000" }, { "input": "10\n1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000", "output": "19000000000" }, { "input": "7\n0 1000000000 0 1000000000 0 1000000000 0", "output": "6000000000" }, { "input": "4\n1000000000 -1000000000 1000000000 -1000000000", "output": "7000000000" }, { "input": "20\n1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000", "output": "39000000000" }, { "input": "11\n1000000000 0 1000000000 0 1000000000 0 1000000000 0 1000000000 0 1000000000", "output": "11000000000" }, { "input": "5\n1000000000 -1000000000 1000000000 -1000000000 1000000000", "output": "9000000000" }, { "input": "22\n1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000", "output": "43000000000" } ]
1,447,699,622
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
10
155
7,782,400
n = int(input()) li = list(map(int,input().split())) ans = li[0] for i in range(1,len(li)): ans += abs(li[i]-li[i-1]) print(ans)
Title: Wilbur and Array Time Limit: None seconds Memory Limit: None megabytes Problem Description: Wilbur the pig is tinkering with arrays again. He has the array *a*1,<=*a*2,<=...,<=*a**n* initially consisting of *n* zeros. At one step, he can choose any index *i* and either add 1 to all elements *a**i*,<=*a**i*<=+<=1,<=... ,<=*a**n* or subtract 1 from all elements *a**i*,<=*a**i*<=+<=1,<=...,<=*a**n*. His goal is to end up with the array *b*1,<=*b*2,<=...,<=*b**n*. Of course, Wilbur wants to achieve this goal in the minimum number of steps and asks you to compute this value. Input Specification: The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the length of the array *a**i*. Initially *a**i*<==<=0 for every position *i*, so this array is not given in the input. The second line of the input contains *n* integers *b*1,<=*b*2,<=...,<=*b**n* (<=-<=109<=≤<=*b**i*<=≤<=109). Output Specification: Print the minimum number of steps that Wilbur needs to make in order to achieve *a**i*<==<=*b**i* for all *i*. Demo Input: ['5\n1 2 3 4 5\n', '4\n1 2 2 1\n'] Demo Output: ['5', '3'] Note: In the first sample, Wilbur may successively choose indices 1, 2, 3, 4, and 5, and add 1 to corresponding suffixes. In the second sample, Wilbur first chooses indices 1 and 2 and adds 1 to corresponding suffixes, then he chooses index 4 and subtract 1.
```python n = int(input()) li = list(map(int,input().split())) ans = li[0] for i in range(1,len(li)): ans += abs(li[i]-li[i-1]) print(ans) ```
0
6
B
President's Office
PROGRAMMING
1,100
[ "implementation" ]
B. President's Office
2
64
President of Berland has a very vast office-room, where, apart from him, work his subordinates. Each subordinate, as well as President himself, has his own desk of a unique colour. Each desk is rectangular, and its sides are parallel to the office walls. One day President decided to establish an assembly, of which all his deputies will be members. Unfortunately, he does not remember the exact amount of his deputies, but he remembers that the desk of each his deputy is adjacent to his own desk, that is to say, the two desks (President's and each deputy's) have a common side of a positive length. The office-room plan can be viewed as a matrix with *n* rows and *m* columns. Each cell of this matrix is either empty, or contains a part of a desk. An uppercase Latin letter stands for each desk colour. The «period» character («.») stands for an empty cell.
The first line contains two separated by a space integer numbers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the length and the width of the office-room, and *c* character — the President's desk colour. The following *n* lines contain *m* characters each — the office-room description. It is guaranteed that the colour of each desk is unique, and each desk represents a continuous subrectangle of the given matrix. All colours are marked by uppercase Latin letters.
Print the only number — the amount of President's deputies.
[ "3 4 R\nG.B.\n.RR.\nTTT.\n", "3 3 Z\n...\n.H.\n..Z\n" ]
[ "2\n", "0\n" ]
none
0
[ { "input": "3 4 R\nG.B.\n.RR.\nTTT.", "output": "2" }, { "input": "3 3 Z\n...\n.H.\n..Z", "output": "0" }, { "input": "1 1 C\nC", "output": "0" }, { "input": "2 2 W\nKW\nKW", "output": "1" }, { "input": "1 10 H\n....DDHHHH", "output": "1" }, { "input": "3 2 W\nOO\nWW\nWW", "output": "1" }, { "input": "3 3 U\nUOO\nUVV\nUVV", "output": "2" }, { "input": "4 5 Z\n...ZZ\nUU.ZZ\nUUTT.\n..TT.", "output": "1" }, { "input": "4 4 X\nT..R\nTJJJ\nDJJJ\nXJJJ", "output": "2" }, { "input": "5 5 O\nCQGAV\nIHTUD\nRFPZO\nMYSKX\nJEWBN", "output": "3" }, { "input": "5 4 O\n.O.J\nWOBJ\nWOBJ\nDDBJ\nDD.J", "output": "3" }, { "input": "7 7 Q\n....RRR\nUUUURRR\nUUUUSS.\n....SSB\nPPP.OIB\n.MMTTIB\nQQQTTIB", "output": "2" }, { "input": "8 10 B\n..BBBBEEEE\n..BBBBEEEE\n..BBBBEEEE\n..BBBBEEEE\nJJJJYYYY..\nJJJJYYYY..\nJJJJYYYY..\nJJJJYYYY..", "output": "3" }, { "input": "7 13 G\n....GGGGGGXXX\nSSSSGGGGGGXXX\nSSSSJJFFFFFFF\nRRR.JJFFFFFFF\nRRRYYYYYYYAAA\nRRRYYYYYYYAAA\nRRR.......AAA", "output": "4" }, { "input": "10 10 T\nCCEEEKKKHJ\nCCRRRRRRHJ\nCC..XFFOOO\nZZZZZFFOOO\n..PTTFFOOO\nAAATTFFOOO\nAAATTYYYYY\nAAATTYYYYY\nAAAMMYYYYY\nAAA..YYYYY", "output": "6" }, { "input": "15 12 M\n............\n.....L..QQQQ\nNNN..L..QQQQ\nNNN..LJJJJJ.\nNNNEEEEEEEE.\nNNNEEEEEEEE.\nNNNMMMMM.AAA\nNNNMMMMM.AAA\n.RRMMMMM.AAA\n.RRMMMMMYAAA\n.RRMMMMMYAAA\n.RRMMMMMYAAA\nZRRMMMMMYAAA\nZRRMMMMM.AAA\nZRRMMMMM.AAA", "output": "4" } ]
1,590,397,146
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
6
108
307,200
def findPredidentsDesk(room, n, m): for i in range(n): for j in range(m): if room[i][j] == c: start = j for k in range(start, m): if room[i][k] != c: return (start, k - 1, i) return (start, start, i) def CountColorsInRow(room, row, start, end, x): colors = set() count = 0 c = x + '.' for i in range(start, end + 1): if room[row][i] not in c and room[row][i] not in colors: count += 1 colors.add(room[row][i]) return count if __name__ == '__main__': n, m, c = map(str, input().split()) n = int(n) m = int(m) room = [] for i in range(n): room.append(input()) start, end, row = findPredidentsDesk(room, n, m) count = 0 if start != 0: count += int(room[row][start - 1] not in '.' + c) if end != m - 1: count += int(room[row][end + 1] not in '.' + c) if row != 0: count += CountColorsInRow(room, row - 1, start, end, c) if row != n - 1: count += CountColorsInRow(room, row + 1, start, end, c) print(count)
Title: President's Office Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: President of Berland has a very vast office-room, where, apart from him, work his subordinates. Each subordinate, as well as President himself, has his own desk of a unique colour. Each desk is rectangular, and its sides are parallel to the office walls. One day President decided to establish an assembly, of which all his deputies will be members. Unfortunately, he does not remember the exact amount of his deputies, but he remembers that the desk of each his deputy is adjacent to his own desk, that is to say, the two desks (President's and each deputy's) have a common side of a positive length. The office-room plan can be viewed as a matrix with *n* rows and *m* columns. Each cell of this matrix is either empty, or contains a part of a desk. An uppercase Latin letter stands for each desk colour. The «period» character («.») stands for an empty cell. Input Specification: The first line contains two separated by a space integer numbers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the length and the width of the office-room, and *c* character — the President's desk colour. The following *n* lines contain *m* characters each — the office-room description. It is guaranteed that the colour of each desk is unique, and each desk represents a continuous subrectangle of the given matrix. All colours are marked by uppercase Latin letters. Output Specification: Print the only number — the amount of President's deputies. Demo Input: ['3 4 R\nG.B.\n.RR.\nTTT.\n', '3 3 Z\n...\n.H.\n..Z\n'] Demo Output: ['2\n', '0\n'] Note: none
```python def findPredidentsDesk(room, n, m): for i in range(n): for j in range(m): if room[i][j] == c: start = j for k in range(start, m): if room[i][k] != c: return (start, k - 1, i) return (start, start, i) def CountColorsInRow(room, row, start, end, x): colors = set() count = 0 c = x + '.' for i in range(start, end + 1): if room[row][i] not in c and room[row][i] not in colors: count += 1 colors.add(room[row][i]) return count if __name__ == '__main__': n, m, c = map(str, input().split()) n = int(n) m = int(m) room = [] for i in range(n): room.append(input()) start, end, row = findPredidentsDesk(room, n, m) count = 0 if start != 0: count += int(room[row][start - 1] not in '.' + c) if end != m - 1: count += int(room[row][end + 1] not in '.' + c) if row != 0: count += CountColorsInRow(room, row - 1, start, end, c) if row != n - 1: count += CountColorsInRow(room, row + 1, start, end, c) print(count) ```
0
227
B
Effective Approach
PROGRAMMING
1,100
[ "implementation" ]
null
null
Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array. According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn compared with the number that you need to find. Once you find the array element that is equal to the required one, the search ends. The efficiency of the algorithm is the number of performed comparisons. The fewer comparisons the linear search has made, the more effective it is. Vasya believes that a linear search would work better if it sequentially iterates through the elements, starting with the 1-st one (in this problem we consider the elements of the array indexed from 1 to *n*) and ending with the *n*-th one. And Petya says that Vasya is wrong: the search will need less comparisons if it sequentially iterates the elements starting from the *n*-th and ending with the 1-st one. Sasha argues that the two approaches are equivalent. To finally begin the task, the teammates decided to settle the debate and compare the two approaches on an example. For this, they took an array that is a permutation of integers from 1 to *n*, and generated *m* queries of the form: find element with value *b**i* in the array. They want to calculate for both approaches how many comparisons in total the linear search will need to respond to all queries. If the first search needs fewer comparisons, then the winner of the dispute is Vasya. If the second one does, then the winner is Petya. If both approaches make the same number of comparisons, then Sasha's got the upper hand. But the problem is, linear search is too slow. That's why the boys aren't going to find out who is right before the end of the training, unless you come in here. Help them to determine who will win the dispute.
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of elements in the array. The second line contains *n* distinct space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the elements of array. The third line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. The last line contains *m* space-separated integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=*n*) — the search queries. Note that the queries can repeat.
Print two integers, showing how many comparisons Vasya's approach needs and how many comparisons Petya's approach needs. Separate the numbers by spaces. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.
[ "2\n1 2\n1\n1\n", "2\n2 1\n1\n1\n", "3\n3 1 2\n3\n1 2 3\n" ]
[ "1 2\n", "2 1\n", "6 6\n" ]
In the first sample Vasya's approach will make one comparison (it starts with the 1-st element and immediately finds the required number), and Petya's approach makes two comparisons (first he compares with the 2-nd array element, doesn't find the search item and compares with the 1-st element). In the second sample, on the contrary, Vasya's approach will need two comparisons (first with 1-st element, and then with the 2-nd), and Petya's approach will find the required value in one comparison (the first comparison with the 2-nd element).
1,000
[ { "input": "2\n1 2\n1\n1", "output": "1 2" }, { "input": "2\n2 1\n1\n1", "output": "2 1" }, { "input": "3\n3 1 2\n3\n1 2 3", "output": "6 6" }, { "input": "9\n2 9 3 1 6 4 7 8 5\n9\n5 1 5 2 8 4 4 4 5", "output": "58 32" }, { "input": "10\n3 10 9 2 7 6 5 8 4 1\n1\n4", "output": "9 2" }, { "input": "10\n5 2 10 8 3 1 9 7 6 4\n9\n2 5 9 2 3 2 5 9 8", "output": "31 68" }, { "input": "9\n3 8 4 7 1 2 5 6 9\n3\n2 7 1", "output": "15 15" }, { "input": "9\n5 3 8 4 2 6 1 7 9\n4\n6 1 9 2", "output": "27 13" }, { "input": "4\n1 3 2 4\n4\n3 1 2 3", "output": "8 12" }, { "input": "3\n1 2 3\n8\n3 2 1 1 2 3 1 2", "output": "15 17" } ]
1,679,272,107
2,147,483,647
Python 3
OK
TESTS
34
342
14,848,000
n = int(input()) dic = {} l1 = list(map(int,input().split())) for i in range(n): dic[l1[i]] = i+1 n2 = int(input()) l2 = list(map(int,input().split())) s1 = 0 s2 = 0 for i in l2 : s1+=dic[i] for i in l2 : s2+= (n-dic[i]+1) print(f"{s1} {s2}")
Title: Effective Approach Time Limit: None seconds Memory Limit: None megabytes Problem Description: Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array. According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn compared with the number that you need to find. Once you find the array element that is equal to the required one, the search ends. The efficiency of the algorithm is the number of performed comparisons. The fewer comparisons the linear search has made, the more effective it is. Vasya believes that a linear search would work better if it sequentially iterates through the elements, starting with the 1-st one (in this problem we consider the elements of the array indexed from 1 to *n*) and ending with the *n*-th one. And Petya says that Vasya is wrong: the search will need less comparisons if it sequentially iterates the elements starting from the *n*-th and ending with the 1-st one. Sasha argues that the two approaches are equivalent. To finally begin the task, the teammates decided to settle the debate and compare the two approaches on an example. For this, they took an array that is a permutation of integers from 1 to *n*, and generated *m* queries of the form: find element with value *b**i* in the array. They want to calculate for both approaches how many comparisons in total the linear search will need to respond to all queries. If the first search needs fewer comparisons, then the winner of the dispute is Vasya. If the second one does, then the winner is Petya. If both approaches make the same number of comparisons, then Sasha's got the upper hand. But the problem is, linear search is too slow. That's why the boys aren't going to find out who is right before the end of the training, unless you come in here. Help them to determine who will win the dispute. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of elements in the array. The second line contains *n* distinct space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the elements of array. The third line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. The last line contains *m* space-separated integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=*n*) — the search queries. Note that the queries can repeat. Output Specification: Print two integers, showing how many comparisons Vasya's approach needs and how many comparisons Petya's approach needs. Separate the numbers by spaces. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. Demo Input: ['2\n1 2\n1\n1\n', '2\n2 1\n1\n1\n', '3\n3 1 2\n3\n1 2 3\n'] Demo Output: ['1 2\n', '2 1\n', '6 6\n'] Note: In the first sample Vasya's approach will make one comparison (it starts with the 1-st element and immediately finds the required number), and Petya's approach makes two comparisons (first he compares with the 2-nd array element, doesn't find the search item and compares with the 1-st element). In the second sample, on the contrary, Vasya's approach will need two comparisons (first with 1-st element, and then with the 2-nd), and Petya's approach will find the required value in one comparison (the first comparison with the 2-nd element).
```python n = int(input()) dic = {} l1 = list(map(int,input().split())) for i in range(n): dic[l1[i]] = i+1 n2 = int(input()) l2 = list(map(int,input().split())) s1 = 0 s2 = 0 for i in l2 : s1+=dic[i] for i in l2 : s2+= (n-dic[i]+1) print(f"{s1} {s2}") ```
3
916
A
Jamie and Alarm Snooze
PROGRAMMING
900
[ "brute force", "implementation", "math" ]
null
null
Jamie loves sleeping. One day, he decides that he needs to wake up at exactly *hh*:<=*mm*. However, he hates waking up, so he wants to make waking up less painful by setting the alarm at a lucky time. He will then press the snooze button every *x* minutes until *hh*:<=*mm* is reached, and only then he will wake up. He wants to know what is the smallest number of times he needs to press the snooze button. A time is considered lucky if it contains a digit '7'. For example, 13:<=07 and 17:<=27 are lucky, while 00:<=48 and 21:<=34 are not lucky. Note that it is not necessary that the time set for the alarm and the wake-up time are on the same day. It is guaranteed that there is a lucky time Jamie can set so that he can wake at *hh*:<=*mm*. Formally, find the smallest possible non-negative integer *y* such that the time representation of the time *x*·*y* minutes before *hh*:<=*mm* contains the digit '7'. Jamie uses 24-hours clock, so after 23:<=59 comes 00:<=00.
The first line contains a single integer *x* (1<=≤<=*x*<=≤<=60). The second line contains two two-digit integers, *hh* and *mm* (00<=≤<=*hh*<=≤<=23,<=00<=≤<=*mm*<=≤<=59).
Print the minimum number of times he needs to press the button.
[ "3\n11 23\n", "5\n01 07\n" ]
[ "2\n", "0\n" ]
In the first sample, Jamie needs to wake up at 11:23. So, he can set his alarm at 11:17. He would press the snooze button when the alarm rings at 11:17 and at 11:20. In the second sample, Jamie can set his alarm at exactly at 01:07 which is lucky.
500
[ { "input": "3\n11 23", "output": "2" }, { "input": "5\n01 07", "output": "0" }, { "input": "34\n09 24", "output": "3" }, { "input": "2\n14 37", "output": "0" }, { "input": "14\n19 54", "output": "9" }, { "input": "42\n15 44", "output": "12" }, { "input": "46\n02 43", "output": "1" }, { "input": "14\n06 41", "output": "1" }, { "input": "26\n04 58", "output": "26" }, { "input": "54\n16 47", "output": "0" }, { "input": "38\n20 01", "output": "3" }, { "input": "11\n02 05", "output": "8" }, { "input": "55\n22 10", "output": "5" }, { "input": "23\n10 08", "output": "6" }, { "input": "23\n23 14", "output": "9" }, { "input": "51\n03 27", "output": "0" }, { "input": "35\n15 25", "output": "13" }, { "input": "3\n12 15", "output": "6" }, { "input": "47\n00 28", "output": "3" }, { "input": "31\n13 34", "output": "7" }, { "input": "59\n17 32", "output": "0" }, { "input": "25\n11 03", "output": "8" }, { "input": "9\n16 53", "output": "4" }, { "input": "53\n04 06", "output": "3" }, { "input": "37\n00 12", "output": "5" }, { "input": "5\n13 10", "output": "63" }, { "input": "50\n01 59", "output": "10" }, { "input": "34\n06 13", "output": "4" }, { "input": "2\n18 19", "output": "1" }, { "input": "46\n06 16", "output": "17" }, { "input": "14\n03 30", "output": "41" }, { "input": "40\n13 37", "output": "0" }, { "input": "24\n17 51", "output": "0" }, { "input": "8\n14 57", "output": "0" }, { "input": "52\n18 54", "output": "2" }, { "input": "20\n15 52", "output": "24" }, { "input": "20\n03 58", "output": "30" }, { "input": "48\n07 11", "output": "0" }, { "input": "32\n04 01", "output": "2" }, { "input": "60\n08 15", "output": "1" }, { "input": "44\n20 20", "output": "4" }, { "input": "55\n15 35", "output": "9" }, { "input": "55\n03 49", "output": "11" }, { "input": "23\n16 39", "output": "4" }, { "input": "7\n20 36", "output": "7" }, { "input": "35\n16 42", "output": "1" }, { "input": "35\n05 56", "output": "21" }, { "input": "3\n17 45", "output": "0" }, { "input": "47\n05 59", "output": "6" }, { "input": "15\n10 13", "output": "9" }, { "input": "59\n06 18", "output": "9" }, { "input": "34\n17 18", "output": "0" }, { "input": "18\n05 23", "output": "2" }, { "input": "46\n17 21", "output": "0" }, { "input": "30\n06 27", "output": "0" }, { "input": "14\n18 40", "output": "3" }, { "input": "58\n22 54", "output": "6" }, { "input": "26\n19 44", "output": "5" }, { "input": "10\n15 57", "output": "0" }, { "input": "54\n20 47", "output": "0" }, { "input": "22\n08 45", "output": "3" }, { "input": "48\n18 08", "output": "1" }, { "input": "32\n07 06", "output": "0" }, { "input": "60\n19 19", "output": "2" }, { "input": "45\n07 25", "output": "0" }, { "input": "29\n12 39", "output": "8" }, { "input": "13\n08 28", "output": "3" }, { "input": "41\n21 42", "output": "5" }, { "input": "41\n09 32", "output": "3" }, { "input": "9\n21 45", "output": "2" }, { "input": "37\n10 43", "output": "5" }, { "input": "3\n20 50", "output": "1" }, { "input": "47\n00 04", "output": "1" }, { "input": "15\n13 10", "output": "21" }, { "input": "15\n17 23", "output": "0" }, { "input": "43\n22 13", "output": "2" }, { "input": "27\n10 26", "output": "6" }, { "input": "55\n22 24", "output": "5" }, { "input": "55\n03 30", "output": "11" }, { "input": "24\n23 27", "output": "0" }, { "input": "52\n11 33", "output": "3" }, { "input": "18\n22 48", "output": "17" }, { "input": "1\n12 55", "output": "8" }, { "input": "1\n04 27", "output": "0" }, { "input": "1\n12 52", "output": "5" }, { "input": "1\n20 16", "output": "9" }, { "input": "1\n04 41", "output": "4" }, { "input": "1\n20 21", "output": "4" }, { "input": "1\n04 45", "output": "8" }, { "input": "1\n12 18", "output": "1" }, { "input": "1\n04 42", "output": "5" }, { "input": "1\n02 59", "output": "2" }, { "input": "1\n18 24", "output": "7" }, { "input": "1\n02 04", "output": "7" }, { "input": "1\n18 28", "output": "1" }, { "input": "1\n18 01", "output": "2" }, { "input": "1\n10 25", "output": "8" }, { "input": "1\n02 49", "output": "2" }, { "input": "1\n02 30", "output": "3" }, { "input": "1\n18 54", "output": "7" }, { "input": "1\n02 19", "output": "2" }, { "input": "1\n05 25", "output": "8" }, { "input": "60\n23 55", "output": "6" }, { "input": "60\n08 19", "output": "1" }, { "input": "60\n00 00", "output": "7" }, { "input": "60\n08 24", "output": "1" }, { "input": "60\n16 13", "output": "9" }, { "input": "60\n08 21", "output": "1" }, { "input": "60\n16 45", "output": "9" }, { "input": "60\n08 26", "output": "1" }, { "input": "60\n08 50", "output": "1" }, { "input": "60\n05 21", "output": "12" }, { "input": "60\n13 29", "output": "6" }, { "input": "60\n05 18", "output": "12" }, { "input": "60\n13 42", "output": "6" }, { "input": "60\n05 07", "output": "0" }, { "input": "60\n05 47", "output": "0" }, { "input": "60\n21 55", "output": "4" }, { "input": "60\n05 36", "output": "12" }, { "input": "60\n21 08", "output": "4" }, { "input": "60\n21 32", "output": "4" }, { "input": "60\n16 31", "output": "9" }, { "input": "5\n00 00", "output": "73" }, { "input": "2\n06 58", "output": "390" }, { "input": "60\n00 00", "output": "7" }, { "input": "2\n00 00", "output": "181" }, { "input": "10\n00 00", "output": "37" }, { "input": "60\n01 00", "output": "8" }, { "input": "12\n00 06", "output": "31" }, { "input": "1\n00 01", "output": "4" }, { "input": "5\n00 05", "output": "74" }, { "input": "60\n01 01", "output": "8" }, { "input": "11\n18 11", "output": "2" }, { "input": "60\n01 15", "output": "8" }, { "input": "10\n00 16", "output": "38" }, { "input": "60\n00 59", "output": "7" }, { "input": "30\n00 00", "output": "13" }, { "input": "60\n01 05", "output": "8" }, { "input": "4\n00 03", "output": "4" }, { "input": "4\n00 00", "output": "91" }, { "input": "60\n00 01", "output": "7" }, { "input": "6\n00 03", "output": "1" }, { "input": "13\n00 00", "output": "1" }, { "input": "1\n18 01", "output": "2" }, { "input": "5\n06 00", "output": "145" }, { "input": "60\n04 08", "output": "11" }, { "input": "5\n01 55", "output": "96" }, { "input": "8\n00 08", "output": "47" }, { "input": "23\n18 23", "output": "2" }, { "input": "6\n00 06", "output": "62" }, { "input": "59\n18 59", "output": "2" }, { "input": "11\n00 10", "output": "3" }, { "input": "10\n00 01", "output": "37" }, { "input": "59\n00 00", "output": "7" }, { "input": "10\n18 10", "output": "2" }, { "input": "5\n00 01", "output": "73" }, { "input": "1\n00 00", "output": "3" }, { "input": "8\n00 14", "output": "47" }, { "input": "60\n03 00", "output": "10" }, { "input": "60\n00 10", "output": "7" }, { "input": "5\n01 13", "output": "87" }, { "input": "30\n02 43", "output": "18" }, { "input": "17\n00 08", "output": "3" }, { "input": "3\n00 00", "output": "1" }, { "input": "60\n00 05", "output": "7" }, { "input": "5\n18 05", "output": "2" }, { "input": "30\n00 30", "output": "14" }, { "input": "1\n00 06", "output": "9" }, { "input": "55\n00 00", "output": "7" }, { "input": "8\n02 08", "output": "62" }, { "input": "7\n00 00", "output": "9" }, { "input": "6\n08 06", "output": "2" }, { "input": "48\n06 24", "output": "16" }, { "input": "8\n06 58", "output": "98" }, { "input": "3\n12 00", "output": "1" }, { "input": "5\n01 06", "output": "86" }, { "input": "2\n00 08", "output": "185" }, { "input": "3\n18 03", "output": "2" }, { "input": "1\n17 00", "output": "0" }, { "input": "59\n00 48", "output": "7" }, { "input": "5\n12 01", "output": "49" }, { "input": "55\n01 25", "output": "9" }, { "input": "2\n07 23", "output": "0" }, { "input": "10\n01 10", "output": "44" }, { "input": "2\n00 01", "output": "2" }, { "input": "59\n00 01", "output": "6" }, { "input": "5\n00 02", "output": "1" }, { "input": "4\n01 02", "output": "106" }, { "input": "5\n00 06", "output": "74" }, { "input": "42\n00 08", "output": "9" }, { "input": "60\n01 20", "output": "8" }, { "input": "3\n06 00", "output": "1" }, { "input": "4\n00 01", "output": "1" }, { "input": "2\n00 06", "output": "184" }, { "input": "1\n00 57", "output": "0" }, { "input": "6\n00 00", "output": "61" }, { "input": "5\n08 40", "output": "9" }, { "input": "58\n00 55", "output": "1" }, { "input": "2\n00 02", "output": "182" }, { "input": "1\n08 01", "output": "2" }, { "input": "10\n10 10", "output": "14" }, { "input": "60\n01 11", "output": "8" }, { "input": "2\n07 00", "output": "0" }, { "input": "15\n00 03", "output": "25" }, { "input": "6\n04 34", "output": "106" }, { "input": "16\n00 16", "output": "24" }, { "input": "2\n00 59", "output": "1" }, { "input": "59\n00 08", "output": "7" }, { "input": "10\n03 10", "output": "56" }, { "input": "3\n08 03", "output": "2" }, { "input": "20\n06 11", "output": "37" }, { "input": "4\n01 00", "output": "106" }, { "input": "38\n01 08", "output": "12" }, { "input": "60\n00 06", "output": "7" }, { "input": "5\n12 00", "output": "49" }, { "input": "6\n01 42", "output": "78" }, { "input": "4\n00 04", "output": "92" }, { "input": "60\n04 05", "output": "11" }, { "input": "1\n00 53", "output": "6" }, { "input": "5\n08 05", "output": "2" }, { "input": "60\n18 45", "output": "1" }, { "input": "60\n06 23", "output": "13" }, { "input": "6\n00 15", "output": "3" }, { "input": "58\n00 06", "output": "7" }, { "input": "2\n06 44", "output": "383" }, { "input": "1\n08 00", "output": "1" }, { "input": "10\n06 58", "output": "78" }, { "input": "59\n00 58", "output": "8" }, { "input": "1\n18 00", "output": "1" }, { "input": "50\n00 42", "output": "9" }, { "input": "30\n18 30", "output": "2" }, { "input": "60\n21 59", "output": "4" }, { "input": "2\n10 52", "output": "87" }, { "input": "56\n00 00", "output": "7" }, { "input": "16\n18 16", "output": "2" }, { "input": "5\n01 05", "output": "86" }, { "input": "5\n05 00", "output": "133" }, { "input": "5\n23 59", "output": "72" }, { "input": "7\n17 13", "output": "0" }, { "input": "58\n00 00", "output": "7" }, { "input": "15\n00 07", "output": "0" }, { "input": "59\n08 00", "output": "1" }, { "input": "46\n00 00", "output": "8" }, { "input": "59\n01 05", "output": "2" }, { "input": "2\n01 00", "output": "211" }, { "input": "60\n00 24", "output": "7" }, { "input": "10\n00 08", "output": "37" }, { "input": "10\n00 06", "output": "37" }, { "input": "60\n01 24", "output": "8" }, { "input": "50\n00 10", "output": "8" }, { "input": "2\n03 00", "output": "271" }, { "input": "4\n19 04", "output": "17" }, { "input": "25\n00 23", "output": "16" }, { "input": "10\n01 01", "output": "43" } ]
1,549,419,823
1,423
Python 3
WRONG_ANSWER
TESTS
8
108
0
x=int(input()) th, tm =[int(i) for i in input().split()] ans = False count=0 while not ans : if '7' in str(th)+str(tm): ans = True break count+=1 tm-=x if tm < 0: tm +=60 th-=1 if th <0 : th +=23 print(count)
Title: Jamie and Alarm Snooze Time Limit: None seconds Memory Limit: None megabytes Problem Description: Jamie loves sleeping. One day, he decides that he needs to wake up at exactly *hh*:<=*mm*. However, he hates waking up, so he wants to make waking up less painful by setting the alarm at a lucky time. He will then press the snooze button every *x* minutes until *hh*:<=*mm* is reached, and only then he will wake up. He wants to know what is the smallest number of times he needs to press the snooze button. A time is considered lucky if it contains a digit '7'. For example, 13:<=07 and 17:<=27 are lucky, while 00:<=48 and 21:<=34 are not lucky. Note that it is not necessary that the time set for the alarm and the wake-up time are on the same day. It is guaranteed that there is a lucky time Jamie can set so that he can wake at *hh*:<=*mm*. Formally, find the smallest possible non-negative integer *y* such that the time representation of the time *x*·*y* minutes before *hh*:<=*mm* contains the digit '7'. Jamie uses 24-hours clock, so after 23:<=59 comes 00:<=00. Input Specification: The first line contains a single integer *x* (1<=≤<=*x*<=≤<=60). The second line contains two two-digit integers, *hh* and *mm* (00<=≤<=*hh*<=≤<=23,<=00<=≤<=*mm*<=≤<=59). Output Specification: Print the minimum number of times he needs to press the button. Demo Input: ['3\n11 23\n', '5\n01 07\n'] Demo Output: ['2\n', '0\n'] Note: In the first sample, Jamie needs to wake up at 11:23. So, he can set his alarm at 11:17. He would press the snooze button when the alarm rings at 11:17 and at 11:20. In the second sample, Jamie can set his alarm at exactly at 01:07 which is lucky.
```python x=int(input()) th, tm =[int(i) for i in input().split()] ans = False count=0 while not ans : if '7' in str(th)+str(tm): ans = True break count+=1 tm-=x if tm < 0: tm +=60 th-=1 if th <0 : th +=23 print(count) ```
0
11
B
Jumping Jack
PROGRAMMING
1,600
[ "math" ]
B. Jumping Jack
1
64
Jack is working on his jumping skills recently. Currently he's located at point zero of the number line. He would like to get to the point *x*. In order to train, he has decided that he'll first jump by only one unit, and each subsequent jump will be exactly one longer than the previous one. He can go either left or right with each jump. He wonders how many jumps he needs to reach *x*.
The input data consists of only one integer *x* (<=-<=109<=≤<=*x*<=≤<=109).
Output the minimal number of jumps that Jack requires to reach *x*.
[ "2\n", "6\n", "0\n" ]
[ "3\n", "3\n", "0\n" ]
none
0
[ { "input": "2", "output": "3" }, { "input": "6", "output": "3" }, { "input": "0", "output": "0" }, { "input": "-1000000000", "output": "44723" }, { "input": "999961560", "output": "44720" }, { "input": "999961561", "output": "44721" }, { "input": "999961559", "output": "44721" }, { "input": "-488979819", "output": "31273" }, { "input": "-865918189", "output": "41617" }, { "input": "-278253406", "output": "23591" }, { "input": "-87275307", "output": "13213" }, { "input": "103702792", "output": "14403" }, { "input": "294680891", "output": "24277" }, { "input": "485658989", "output": "31166" }, { "input": "676637088", "output": "36787" }, { "input": "867615187", "output": "41657" }, { "input": "-941406715", "output": "43393" }, { "input": "-897912263", "output": "42377" }, { "input": "-706934164", "output": "37603" }, { "input": "-790244010", "output": "39755" }, { "input": "16417015", "output": "5730" }, { "input": "823078041", "output": "40573" }, { "input": "-517744582", "output": "32179" }, { "input": "288916443", "output": "24038" }, { "input": "-904422532", "output": "42531" }, { "input": "-245245154", "output": "22147" }, { "input": "561415872", "output": "33511" }, { "input": "-779406751", "output": "39482" }, { "input": "27254274", "output": "7383" }, { "input": "845249034", "output": "41116" } ]
1,559,837,849
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
186
0
p=int(input()) x=abs(p) j=int((-1+(1+8*x)**.5)/2) if (j+j*j)//2==x: print(j) else: print(j+2 if p>0 else j+3)
Title: Jumping Jack Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: Jack is working on his jumping skills recently. Currently he's located at point zero of the number line. He would like to get to the point *x*. In order to train, he has decided that he'll first jump by only one unit, and each subsequent jump will be exactly one longer than the previous one. He can go either left or right with each jump. He wonders how many jumps he needs to reach *x*. Input Specification: The input data consists of only one integer *x* (<=-<=109<=≤<=*x*<=≤<=109). Output Specification: Output the minimal number of jumps that Jack requires to reach *x*. Demo Input: ['2\n', '6\n', '0\n'] Demo Output: ['3\n', '3\n', '0\n'] Note: none
```python p=int(input()) x=abs(p) j=int((-1+(1+8*x)**.5)/2) if (j+j*j)//2==x: print(j) else: print(j+2 if p>0 else j+3) ```
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,650,302,750
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
11
46
0
z=input() i=97 h=[] k=[] while i<=122: if i>=97 and i<=109: h.append(chr(i)) i=i+1 else: k.append(chr(i)) i=i+1 q=h+k r=k+h e="a" s=0 for i in z: if i=="n" or e=="n": s = s + ((q.index(e) - q.index(i)) ** 2) ** .5 e = i else: s=s+((r.index(e)-r.index(i))**2)**.5 e=i print(int(s))
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 z=input() i=97 h=[] k=[] while i<=122: if i>=97 and i<=109: h.append(chr(i)) i=i+1 else: k.append(chr(i)) i=i+1 q=h+k r=k+h e="a" s=0 for i in z: if i=="n" or e=="n": s = s + ((q.index(e) - q.index(i)) ** 2) ** .5 e = i else: s=s+((r.index(e)-r.index(i))**2)**.5 e=i print(int(s)) ```
0
20
A
BerOS file system
PROGRAMMING
1,700
[ "implementation" ]
A. BerOS file system
2
64
The new operating system BerOS has a nice feature. It is possible to use any number of characters '/' as a delimiter in path instead of one traditional '/'. For example, strings //usr///local//nginx/sbin// and /usr/local/nginx///sbin are equivalent. The character '/' (or some sequence of such characters) at the end of the path is required only in case of the path to the root directory, which can be represented as single character '/'. A path called normalized if it contains the smallest possible number of characters '/'. Your task is to transform a given path to the normalized form.
The first line of the input contains only lowercase Latin letters and character '/' — the path to some directory. All paths start with at least one character '/'. The length of the given line is no more than 100 characters, it is not empty.
The path in normalized form.
[ "//usr///local//nginx/sbin\n" ]
[ "/usr/local/nginx/sbin\n" ]
none
500
[ { "input": "//usr///local//nginx/sbin", "output": "/usr/local/nginx/sbin" }, { "input": "////a//b/////g", "output": "/a/b/g" }, { "input": "/a/b/c", "output": "/a/b/c" }, { "input": "/", "output": "/" }, { "input": "////", "output": "/" }, { "input": "/a//aa/a//", "output": "/a/aa/a" }, { "input": "/aa//b/aa", "output": "/aa/b/aa" }, { "input": "////////////////////////////////////////////////////////////////////////////////////////////////////", "output": "/" }, { "input": "/opt///pokerband///srvb/opt///pokerband///srvb////pokerband///srvb/", "output": "/opt/pokerband/srvb/opt/pokerband/srvb/pokerband/srvb" }, { "input": "/root/pokerband/trunk/server/game/code/src/main/java/com/uosipa/pokerband/gameserver/game/", "output": "/root/pokerband/trunk/server/game/code/src/main/java/com/uosipa/pokerband/gameserver/game" }, { "input": "/root//pokerband/trunk/server/game/code/src///main/java/com/uosipa/pokerband//gameserver/game//", "output": "/root/pokerband/trunk/server/game/code/src/main/java/com/uosipa/pokerband/gameserver/game" }, { "input": "/root//pokerband/trunk/server/game/code/src///main/java/com/uosipa/pokerband//gameserver/game//test/", "output": "/root/pokerband/trunk/server/game/code/src/main/java/com/uosipa/pokerband/gameserver/game/test" }, { "input": "/root//pokerband/trunk/server/game/code/src///main/java/com/uosipa/pokerband//gameserver/game//testt", "output": "/root/pokerband/trunk/server/game/code/src/main/java/com/uosipa/pokerband/gameserver/game/testt" }, { "input": "///a//a////a/a//a//a//a/////", "output": "/a/a/a/a/a/a/a" }, { "input": "/zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz", "output": "/zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz" }, { "input": "/zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz/", "output": "/zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz" }, { "input": "/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a", "output": "/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a" }, { "input": "///////////////////////////////////////////////////////////////////////////////////////////////////z", "output": "/z" }, { "input": "/z//////////////////////////////////////////////////////////////////////////////////////////////////", "output": "/z" } ]
1,647,599,649
2,147,483,647
Python 3
OK
TESTS
19
92
0
x=input() str1='' if x.count('/')==len(x): print('/') else: for i in range(len(x)): if i==0: str1+=x[i] elif x[i]=='/' and str1[-1]=='/': continue else: str1+=x[i] for i in range(100000000000000000): if str1[-1]=='/': str1=str1[:-1] else: break print(str1)
Title: BerOS file system Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: The new operating system BerOS has a nice feature. It is possible to use any number of characters '/' as a delimiter in path instead of one traditional '/'. For example, strings //usr///local//nginx/sbin// and /usr/local/nginx///sbin are equivalent. The character '/' (or some sequence of such characters) at the end of the path is required only in case of the path to the root directory, which can be represented as single character '/'. A path called normalized if it contains the smallest possible number of characters '/'. Your task is to transform a given path to the normalized form. Input Specification: The first line of the input contains only lowercase Latin letters and character '/' — the path to some directory. All paths start with at least one character '/'. The length of the given line is no more than 100 characters, it is not empty. Output Specification: The path in normalized form. Demo Input: ['//usr///local//nginx/sbin\n'] Demo Output: ['/usr/local/nginx/sbin\n'] Note: none
```python x=input() str1='' if x.count('/')==len(x): print('/') else: for i in range(len(x)): if i==0: str1+=x[i] elif x[i]=='/' and str1[-1]=='/': continue else: str1+=x[i] for i in range(100000000000000000): if str1[-1]=='/': str1=str1[:-1] else: break print(str1) ```
3.977
337
A
Puzzles
PROGRAMMING
900
[ "greedy" ]
null
null
The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, as wikipedia states, is a tiling puzzle that requires the assembly of numerous small, often oddly shaped, interlocking and tessellating pieces). The shop assistant told the teacher that there are *m* puzzles in the shop, but they might differ in difficulty and size. Specifically, the first jigsaw puzzle consists of *f*1 pieces, the second one consists of *f*2 pieces and so on. Ms. Manana doesn't want to upset the children, so she decided that the difference between the numbers of pieces in her presents must be as small as possible. Let *A* be the number of pieces in the largest puzzle that the teacher buys and *B* be the number of pieces in the smallest such puzzle. She wants to choose such *n* puzzles that *A*<=-<=*B* is minimum possible. Help the teacher and find the least possible value of *A*<=-<=*B*.
The first line contains space-separated integers *n* and *m* (2<=≤<=*n*<=≤<=*m*<=≤<=50). The second line contains *m* space-separated integers *f*1,<=*f*2,<=...,<=*f**m* (4<=≤<=*f**i*<=≤<=1000) — the quantities of pieces in the puzzles sold in the shop.
Print a single integer — the least possible difference the teacher can obtain.
[ "4 6\n10 12 10 7 5 22\n" ]
[ "5\n" ]
Sample 1. The class has 4 students. The shop sells 6 puzzles. If Ms. Manana buys the first four puzzles consisting of 10, 12, 10 and 7 pieces correspondingly, then the difference between the sizes of the largest and the smallest puzzle will be equal to 5. It is impossible to obtain a smaller difference. Note that the teacher can also buy puzzles 1, 3, 4 and 5 to obtain the difference 5.
500
[ { "input": "4 6\n10 12 10 7 5 22", "output": "5" }, { "input": "2 2\n4 4", "output": "0" }, { "input": "2 10\n4 5 6 7 8 9 10 11 12 12", "output": "0" }, { "input": "4 5\n818 136 713 59 946", "output": "759" }, { "input": "3 20\n446 852 783 313 549 965 40 88 86 617 479 118 768 34 47 826 366 957 463 903", "output": "13" }, { "input": "2 25\n782 633 152 416 432 825 115 97 386 357 836 310 530 413 354 373 847 882 913 682 729 582 671 674 94", "output": "3" }, { "input": "4 25\n226 790 628 528 114 64 239 279 619 39 894 763 763 847 525 93 882 697 999 643 650 244 159 884 190", "output": "31" }, { "input": "2 50\n971 889 628 39 253 157 925 694 129 516 660 272 738 319 611 816 142 717 514 392 41 105 132 676 958 118 306 768 600 685 103 857 704 346 857 309 23 718 618 161 176 379 846 834 640 468 952 878 164 997", "output": "0" }, { "input": "25 50\n582 146 750 905 313 509 402 21 488 512 32 898 282 64 579 869 37 996 377 929 975 697 666 837 311 205 116 992 533 298 648 268 54 479 792 595 152 69 267 417 184 433 894 603 988 712 24 414 301 176", "output": "412" }, { "input": "49 50\n58 820 826 960 271 294 473 102 925 318 729 672 244 914 796 646 868 6 893 882 726 203 528 498 271 195 355 459 721 680 547 147 631 116 169 804 145 996 133 559 110 257 771 476 576 251 607 314 427 886", "output": "938" }, { "input": "50 50\n374 573 323 744 190 806 485 247 628 336 491 606 702 321 991 678 337 579 86 240 993 208 668 686 855 205 363 177 719 249 896 919 782 434 59 647 787 996 286 216 636 212 546 903 958 559 544 126 608 993", "output": "937" }, { "input": "6 50\n6 8 7 8 5 4 4 5 7 8 6 5 7 4 7 7 7 8 6 4 6 6 8 8 7 7 8 7 5 8 5 4 4 7 8 4 4 6 6 6 8 7 4 7 6 6 5 8 4 7", "output": "0" }, { "input": "37 50\n14 5 11 17 8 20 19 16 20 11 17 20 16 9 14 14 13 18 11 20 8 8 8 5 19 17 6 18 10 20 9 7 12 6 14 17 4 4 10 13 7 4 11 6 20 19 12 12 15 19", "output": "12" }, { "input": "40 50\n4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4", "output": "0" }, { "input": "40 50\n17 20 43 26 41 37 14 8 30 35 30 24 43 8 42 9 41 50 41 35 27 32 35 43 28 36 31 16 5 7 23 16 14 29 8 39 12 16 36 18 49 39 33 37 38 6 6 27 23 17", "output": "31" }, { "input": "2 2\n1000 4", "output": "996" }, { "input": "2 3\n4 502 1000", "output": "498" }, { "input": "3 3\n4 1000 4", "output": "996" } ]
1,669,095,048
2,147,483,647
Python 3
OK
TESTS
18
92
0
inp1 = input("") inp1_lst = [int(i) for i in inp1.split()] n = inp1_lst[0] m = inp1_lst[1] mth = input("") m_lst = [int(i) for i in mth.split()] m_lst.sort() lowest = None j = n-1 for i in range(len(m_lst)-1): if j >= len(m_lst): break dif = m_lst[j] - m_lst[i] j += 1 if i == 0: lowest = dif elif dif < lowest: lowest = dif print(lowest)
Title: Puzzles Time Limit: None seconds Memory Limit: None megabytes Problem Description: The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, as wikipedia states, is a tiling puzzle that requires the assembly of numerous small, often oddly shaped, interlocking and tessellating pieces). The shop assistant told the teacher that there are *m* puzzles in the shop, but they might differ in difficulty and size. Specifically, the first jigsaw puzzle consists of *f*1 pieces, the second one consists of *f*2 pieces and so on. Ms. Manana doesn't want to upset the children, so she decided that the difference between the numbers of pieces in her presents must be as small as possible. Let *A* be the number of pieces in the largest puzzle that the teacher buys and *B* be the number of pieces in the smallest such puzzle. She wants to choose such *n* puzzles that *A*<=-<=*B* is minimum possible. Help the teacher and find the least possible value of *A*<=-<=*B*. Input Specification: The first line contains space-separated integers *n* and *m* (2<=≤<=*n*<=≤<=*m*<=≤<=50). The second line contains *m* space-separated integers *f*1,<=*f*2,<=...,<=*f**m* (4<=≤<=*f**i*<=≤<=1000) — the quantities of pieces in the puzzles sold in the shop. Output Specification: Print a single integer — the least possible difference the teacher can obtain. Demo Input: ['4 6\n10 12 10 7 5 22\n'] Demo Output: ['5\n'] Note: Sample 1. The class has 4 students. The shop sells 6 puzzles. If Ms. Manana buys the first four puzzles consisting of 10, 12, 10 and 7 pieces correspondingly, then the difference between the sizes of the largest and the smallest puzzle will be equal to 5. It is impossible to obtain a smaller difference. Note that the teacher can also buy puzzles 1, 3, 4 and 5 to obtain the difference 5.
```python inp1 = input("") inp1_lst = [int(i) for i in inp1.split()] n = inp1_lst[0] m = inp1_lst[1] mth = input("") m_lst = [int(i) for i in mth.split()] m_lst.sort() lowest = None j = n-1 for i in range(len(m_lst)-1): if j >= len(m_lst): break dif = m_lst[j] - m_lst[i] j += 1 if i == 0: lowest = dif elif dif < lowest: lowest = dif print(lowest) ```
3
431
A
Black Square
PROGRAMMING
800
[ "implementation" ]
null
null
Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone. In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules of the game, Jury must use this second to touch the corresponding strip to make the square go away. As Jury is both smart and lazy, he counted that he wastes exactly *a**i* calories on touching the *i*-th strip. You've got a string *s*, describing the process of the game and numbers *a*1,<=*a*2,<=*a*3,<=*a*4. Calculate how many calories Jury needs to destroy all the squares?
The first line contains four space-separated integers *a*1, *a*2, *a*3, *a*4 (0<=≤<=*a*1,<=*a*2,<=*a*3,<=*a*4<=≤<=104). The second line contains string *s* (1<=≤<=|*s*|<=≤<=105), where the *і*-th character of the string equals "1", if on the *i*-th second of the game the square appears on the first strip, "2", if it appears on the second strip, "3", if it appears on the third strip, "4", if it appears on the fourth strip.
Print a single integer — the total number of calories that Jury wastes.
[ "1 2 3 4\n123214\n", "1 5 3 2\n11221\n" ]
[ "13\n", "13\n" ]
none
500
[ { "input": "1 2 3 4\n123214", "output": "13" }, { "input": "1 5 3 2\n11221", "output": "13" }, { "input": "5 5 5 1\n3422", "output": "16" }, { "input": "4 3 2 1\n2", "output": "3" }, { "input": "5651 6882 6954 4733\n2442313421", "output": "60055" }, { "input": "0 0 0 0\n4132", "output": "0" }, { "input": "3163 5778 83 7640\n11141442444", "output": "64270" }, { "input": "1809 1302 7164 6122\n3144121413113111223311232232114144321414421243443243422322144324121433444342231344234443332241322442", "output": "420780" }, { "input": "0 0 0 0\n1", "output": "0" }, { "input": "1 2 3 4\n4", "output": "4" }, { "input": "2343 7653 1242 5432\n1", "output": "2343" }, { "input": "2343 7653 1242 5432\n2", "output": "7653" }, { "input": "2343 7653 1242 5432\n3", "output": "1242" }, { "input": "2343 7653 1242 5432\n4", "output": "5432" }, { "input": "1 2 3 4\n123412", "output": "13" }, { "input": "50 50 50 50\n11111111111111111111111111111111111111111111111111111", "output": "2650" }, { "input": "1 2 3 4\n11111111111111111111111111111111111111111111111111", "output": "50" }, { "input": "1 2 3 4\n23123231321231231231231231221232123121312321", "output": "87" }, { "input": "1 2 3 4\n1111111111111222222222233333333333444444444444444", "output": "126" }, { "input": "2 3 1 4\n121321232412342112312313213123123412131231231232", "output": "105" } ]
1,667,286,795
2,147,483,647
Python 3
OK
TESTS
49
62
204,800
a1, a2, a3, a4 = map(int, input().split()) s = str(input()) kal = 0 for i in range(len(s)): if s[i] == '1': kal += a1 elif s[i] == '2': kal += a2 elif s[i] == '3': kal += a3 elif s[i] == '4': kal += a4 print(kal)
Title: Black Square Time Limit: None seconds Memory Limit: None megabytes Problem Description: Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone. In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules of the game, Jury must use this second to touch the corresponding strip to make the square go away. As Jury is both smart and lazy, he counted that he wastes exactly *a**i* calories on touching the *i*-th strip. You've got a string *s*, describing the process of the game and numbers *a*1,<=*a*2,<=*a*3,<=*a*4. Calculate how many calories Jury needs to destroy all the squares? Input Specification: The first line contains four space-separated integers *a*1, *a*2, *a*3, *a*4 (0<=≤<=*a*1,<=*a*2,<=*a*3,<=*a*4<=≤<=104). The second line contains string *s* (1<=≤<=|*s*|<=≤<=105), where the *і*-th character of the string equals "1", if on the *i*-th second of the game the square appears on the first strip, "2", if it appears on the second strip, "3", if it appears on the third strip, "4", if it appears on the fourth strip. Output Specification: Print a single integer — the total number of calories that Jury wastes. Demo Input: ['1 2 3 4\n123214\n', '1 5 3 2\n11221\n'] Demo Output: ['13\n', '13\n'] Note: none
```python a1, a2, a3, a4 = map(int, input().split()) s = str(input()) kal = 0 for i in range(len(s)): if s[i] == '1': kal += a1 elif s[i] == '2': kal += a2 elif s[i] == '3': kal += a3 elif s[i] == '4': kal += a4 print(kal) ```
3
955
B
Not simply beatiful strings
PROGRAMMING
1,400
[ "implementation" ]
null
null
Let's call a string adorable if its letters can be realigned in such a way that they form two consequent groups of equal symbols (note that different groups must contain different symbols). For example, ababa is adorable (you can transform it to aaabb, where the first three letters form a group of *a*-s and others — a group of *b*-s), but cccc is not since in each possible consequent partition letters in these two groups coincide. You're given a string *s*. Check whether it can be split into two non-empty subsequences such that the strings formed by these subsequences are adorable. Here a subsequence is an arbitrary set of indexes of the string.
The only line contains *s* (1<=≤<=|*s*|<=≤<=105) consisting of lowercase latin letters.
Print «Yes» if the string can be split according to the criteria above or «No» otherwise. Each letter can be printed in arbitrary case.
[ "ababa\n", "zzcxx\n", "yeee\n" ]
[ "Yes\n", "Yes\n", "No\n" ]
In sample case two zzcxx can be split into subsequences zc and zxx each of which is adorable. There's no suitable partition in sample case three.
1,000
[ { "input": "ababa", "output": "Yes" }, { "input": "zzcxx", "output": "Yes" }, { "input": "yeee", "output": "No" }, { "input": "a", "output": "No" }, { "input": "bbab", "output": "No" }, { "input": "abcd", "output": "Yes" }, { "input": "abc", "output": "No" }, { "input": "abcdaaaa", "output": "Yes" }, { "input": "aaaaaaaaaaaaaaa", "output": "No" }, { "input": "adb", "output": "No" }, { "input": "dcccbad", "output": "Yes" }, { "input": "bcbccccccca", "output": "Yes" }, { "input": "abcdefgh", "output": "No" }, { "input": "aabcdef", "output": "No" }, { "input": "aabc", "output": "Yes" }, { "input": "ssab", "output": "Yes" }, { "input": "ccdd", "output": "Yes" }, { "input": "abcc", "output": "Yes" }, { "input": "ab", "output": "No" }, { "input": "abcde", "output": "No" }, { "input": "aa", "output": "No" }, { "input": "aaabbb", "output": "Yes" }, { "input": "bbbba", "output": "No" }, { "input": "abbbc", "output": "Yes" }, { "input": "baabaa", "output": "Yes" }, { "input": "abacabadde", "output": "No" }, { "input": "aabbcc", "output": "Yes" }, { "input": "abbc", "output": "Yes" }, { "input": "aaaaaaabbbbbbcder", "output": "No" }, { "input": "aabb", "output": "Yes" }, { "input": "aabbccddee", "output": "No" }, { "input": "abca", "output": "Yes" }, { "input": "aaabbbccc", "output": "Yes" } ]
1,680,636,758
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
8
46
307,200
from collections import Counter s=input() c=Counter(s) t=list(c.values()) if len(t)==1 or (len(t)==2 and 1 in t) or len(s)<3 or len(t)>4: print("No") else: print('Yes')
Title: Not simply beatiful strings Time Limit: None seconds Memory Limit: None megabytes Problem Description: Let's call a string adorable if its letters can be realigned in such a way that they form two consequent groups of equal symbols (note that different groups must contain different symbols). For example, ababa is adorable (you can transform it to aaabb, where the first three letters form a group of *a*-s and others — a group of *b*-s), but cccc is not since in each possible consequent partition letters in these two groups coincide. You're given a string *s*. Check whether it can be split into two non-empty subsequences such that the strings formed by these subsequences are adorable. Here a subsequence is an arbitrary set of indexes of the string. Input Specification: The only line contains *s* (1<=≤<=|*s*|<=≤<=105) consisting of lowercase latin letters. Output Specification: Print «Yes» if the string can be split according to the criteria above or «No» otherwise. Each letter can be printed in arbitrary case. Demo Input: ['ababa\n', 'zzcxx\n', 'yeee\n'] Demo Output: ['Yes\n', 'Yes\n', 'No\n'] Note: In sample case two zzcxx can be split into subsequences zc and zxx each of which is adorable. There's no suitable partition in sample case three.
```python from collections import Counter s=input() c=Counter(s) t=list(c.values()) if len(t)==1 or (len(t)==2 and 1 in t) or len(s)<3 or len(t)>4: print("No") else: print('Yes') ```
0
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,672,798,337
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
7
46
0
n = int(input()) res = (n // 2, n // 2) if n & 1 == 0 else (9, n - 9) print(*res)
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()) res = (n // 2, n // 2) if n & 1 == 0 else (9, n - 9) print(*res) ```
0
978
A
Remove Duplicates
PROGRAMMING
800
[ "implementation" ]
null
null
Petya has an array $a$ consisting of $n$ integers. He wants to remove duplicate (equal) elements. Petya wants to leave only the rightmost entry (occurrence) for each element of the array. The relative order of the remaining unique elements should not be changed.
The first line contains a single integer $n$ ($1 \le n \le 50$) — the number of elements in Petya's array. The following line contains a sequence $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 1\,000$) — the Petya's array.
In the first line print integer $x$ — the number of elements which will be left in Petya's array after he removed the duplicates. In the second line print $x$ integers separated with a space — Petya's array after he removed the duplicates. For each unique element only the rightmost entry should be left.
[ "6\n1 5 5 1 6 1\n", "5\n2 4 2 4 4\n", "5\n6 6 6 6 6\n" ]
[ "3\n5 6 1 \n", "2\n2 4 \n", "1\n6 \n" ]
In the first example you should remove two integers $1$, which are in the positions $1$ and $4$. Also you should remove the integer $5$, which is in the position $2$. In the second example you should remove integer $2$, which is in the position $1$, and two integers $4$, which are in the positions $2$ and $4$. In the third example you should remove four integers $6$, which are in the positions $1$, $2$, $3$ and $4$.
0
[ { "input": "6\n1 5 5 1 6 1", "output": "3\n5 6 1 " }, { "input": "5\n2 4 2 4 4", "output": "2\n2 4 " }, { "input": "5\n6 6 6 6 6", "output": "1\n6 " }, { "input": "7\n1 2 3 4 2 2 3", "output": "4\n1 4 2 3 " }, { "input": "9\n100 100 100 99 99 99 100 100 100", "output": "2\n99 100 " }, { "input": "27\n489 489 487 488 750 230 43 645 42 42 489 42 973 42 973 750 645 355 868 112 868 489 750 489 887 489 868", "output": "13\n487 488 230 43 42 973 645 355 112 750 887 489 868 " }, { "input": "40\n151 421 421 909 117 222 909 954 227 421 227 954 954 222 421 227 421 421 421 151 421 227 222 222 222 222 421 183 421 227 421 954 222 421 954 421 222 421 909 421", "output": "8\n117 151 183 227 954 222 909 421 " }, { "input": "48\n2 2 2 903 903 2 726 2 2 2 2 2 2 2 2 2 2 726 2 2 2 2 2 2 2 726 2 2 2 2 62 2 2 2 2 2 2 2 2 726 62 726 2 2 2 903 903 2", "output": "4\n62 726 903 2 " }, { "input": "1\n1", "output": "1\n1 " }, { "input": "13\n5 37 375 5 37 33 37 375 37 2 3 3 2", "output": "6\n5 33 375 37 3 2 " }, { "input": "50\n1 2 3 4 5 4 3 2 1 2 3 2 1 4 5 5 4 3 2 1 1 2 3 4 5 4 3 2 1 2 3 2 1 4 5 5 4 3 2 1 4 3 2 5 1 6 6 6 6 6", "output": "6\n4 3 2 5 1 6 " }, { "input": "47\n233 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "2\n233 1 " }, { "input": "47\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", "output": "1\n1 " }, { "input": "2\n964 964", "output": "1\n964 " }, { "input": "2\n1000 1000", "output": "1\n1000 " }, { "input": "1\n1000", "output": "1\n1000 " }, { "input": "45\n991 991 996 996 992 992 999 1000 998 1000 992 999 996 999 991 991 999 993 992 999 1000 997 992 999 996 991 994 996 991 999 1000 993 999 997 999 992 991 997 991 998 998 995 998 994 993", "output": "10\n996 1000 999 992 997 991 995 998 994 993 " }, { "input": "6\n994 993 1000 998 991 994", "output": "5\n993 1000 998 991 994 " }, { "input": "48\n992 995 992 991 994 992 995 999 996 993 999 995 993 992 1000 992 997 996 991 993 992 998 998 998 999 995 992 992 993 992 992 995 996 995 997 991 997 991 999 994 994 997 1000 998 1000 992 1000 999", "output": "10\n993 996 995 991 994 997 998 992 1000 999 " }, { "input": "3\n6 6 3", "output": "2\n6 3 " }, { "input": "36\n999 1000 993 993 1000 999 996 997 998 995 995 997 999 995 1000 998 998 994 993 998 994 999 1000 995 996 994 991 991 999 996 993 999 996 998 991 997", "output": "9\n1000 995 994 993 999 996 998 991 997 " }, { "input": "49\n991 997 995 991 995 998 994 996 997 991 998 993 992 999 996 995 991 991 999 997 995 993 997 1000 997 993 993 994 999 994 992 991 1000 996 994 996 996 999 992 992 1000 991 997 993 991 994 997 991 996", "output": "10\n998 995 999 992 1000 993 994 997 991 996 " }, { "input": "2\n1000 999", "output": "2\n1000 999 " }, { "input": "28\n997 994 991 994 994 995 1000 992 995 994 994 995 991 996 991 996 991 999 999 993 994 997 995 992 991 992 998 1000", "output": "10\n996 999 993 994 997 995 991 992 998 1000 " }, { "input": "15\n991 995 995 1000 991 993 997 998 1000 994 1000 992 991 995 992", "output": "8\n993 997 998 994 1000 991 995 992 " }, { "input": "6\n1000 1 1000 2 1000 1", "output": "3\n2 1000 1 " }, { "input": "6\n1000 1 1000 2 1 1000", "output": "3\n2 1 1000 " }, { "input": "7\n1 1000 1 999 1000 1 2", "output": "4\n999 1000 1 2 " } ]
1,667,897,392
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
30
0
'''A''' n=int(input()) s='' a=list(map(int,input().split())) a.reverse() l=[] for i in a: if i not in l: l.append(i) l.reverse() for i in l: print(i,end=' ')
Title: Remove Duplicates Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya has an array $a$ consisting of $n$ integers. He wants to remove duplicate (equal) elements. Petya wants to leave only the rightmost entry (occurrence) for each element of the array. The relative order of the remaining unique elements should not be changed. Input Specification: The first line contains a single integer $n$ ($1 \le n \le 50$) — the number of elements in Petya's array. The following line contains a sequence $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 1\,000$) — the Petya's array. Output Specification: In the first line print integer $x$ — the number of elements which will be left in Petya's array after he removed the duplicates. In the second line print $x$ integers separated with a space — Petya's array after he removed the duplicates. For each unique element only the rightmost entry should be left. Demo Input: ['6\n1 5 5 1 6 1\n', '5\n2 4 2 4 4\n', '5\n6 6 6 6 6\n'] Demo Output: ['3\n5 6 1 \n', '2\n2 4 \n', '1\n6 \n'] Note: In the first example you should remove two integers $1$, which are in the positions $1$ and $4$. Also you should remove the integer $5$, which is in the position $2$. In the second example you should remove integer $2$, which is in the position $1$, and two integers $4$, which are in the positions $2$ and $4$. In the third example you should remove four integers $6$, which are in the positions $1$, $2$, $3$ and $4$.
```python '''A''' n=int(input()) s='' a=list(map(int,input().split())) a.reverse() l=[] for i in a: if i not in l: l.append(i) l.reverse() for i in l: print(i,end=' ') ```
0
886
A
ACM ICPC
PROGRAMMING
1,000
[ "brute force" ]
null
null
In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build exactly two teams. After practice competition, participant number *i* got a score of *a**i*. Team score is defined as sum of scores of its participants. High school management is interested if it's possible to build two teams with equal scores. Your task is to answer that question.
The single line contains six integers *a*1,<=...,<=*a*6 (0<=≤<=*a**i*<=≤<=1000) — scores of the participants
Print "YES" (quotes for clarity), if it is possible to build teams with equal score, and "NO" otherwise. You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES").
[ "1 3 2 1 2 1\n", "1 1 1 1 1 99\n" ]
[ "YES\n", "NO\n" ]
In the first sample, first team can be composed of 1st, 2nd and 6th participant, second — of 3rd, 4th and 5th: team scores are 1 + 3 + 1 = 2 + 1 + 2 = 5. In the second sample, score of participant number 6 is too high: his team score will be definitely greater.
500
[ { "input": "1 3 2 1 2 1", "output": "YES" }, { "input": "1 1 1 1 1 99", "output": "NO" }, { "input": "1000 1000 1000 1000 1000 1000", "output": "YES" }, { "input": "0 0 0 0 0 0", "output": "YES" }, { "input": "633 609 369 704 573 416", "output": "NO" }, { "input": "353 313 327 470 597 31", "output": "NO" }, { "input": "835 638 673 624 232 266", "output": "NO" }, { "input": "936 342 19 398 247 874", "output": "NO" }, { "input": "417 666 978 553 271 488", "output": "NO" }, { "input": "71 66 124 199 67 147", "output": "YES" }, { "input": "54 26 0 171 239 12", "output": "YES" }, { "input": "72 8 186 92 267 69", "output": "YES" }, { "input": "180 179 188 50 75 214", "output": "YES" }, { "input": "16 169 110 136 404 277", "output": "YES" }, { "input": "101 400 9 200 300 10", "output": "YES" }, { "input": "101 400 200 9 300 10", "output": "YES" }, { "input": "101 200 400 9 300 10", "output": "YES" }, { "input": "101 400 200 300 9 10", "output": "YES" }, { "input": "101 200 400 300 9 10", "output": "YES" }, { "input": "4 4 4 4 5 4", "output": "NO" }, { "input": "2 2 2 2 2 1", "output": "NO" }, { "input": "1000 1000 999 1000 1000 1000", "output": "NO" }, { "input": "129 1 10 29 8 111", "output": "NO" }, { "input": "1000 1000 1000 999 999 1000", "output": "YES" }, { "input": "101 200 300 400 9 10", "output": "YES" }, { "input": "101 400 200 300 10 9", "output": "YES" }, { "input": "101 200 400 300 10 9", "output": "YES" }, { "input": "101 200 300 400 10 9", "output": "YES" }, { "input": "101 200 300 10 400 9", "output": "YES" }, { "input": "1 1 1 1 1 5", "output": "NO" }, { "input": "8 1 1 3 3 0", "output": "NO" }, { "input": "1 1 2 2 3 3", "output": "YES" }, { "input": "1 2 2 5 2 5", "output": "NO" }, { "input": "1 2 3 6 6 6", "output": "NO" }, { "input": "36 91 7 86 51 89", "output": "NO" }, { "input": "10 1 1 1 23 24", "output": "NO" }, { "input": "1 1 1 10 23 24", "output": "NO" }, { "input": "20 10 1 2 3 44", "output": "NO" }, { "input": "7 0 14 11 8 6", "output": "NO" }, { "input": "100 496 1 1 1 1", "output": "NO" }, { "input": "5 4 2 5 11 3", "output": "NO" }, { "input": "1 3 7 8 8 9", "output": "YES" }, { "input": "1 3 4 5 18 19", "output": "YES" }, { "input": "5 5 1 2 2 15", "output": "NO" }, { "input": "2 1 0 0 0 5", "output": "NO" }, { "input": "1 6 6 1 20 2", "output": "NO" }, { "input": "2 10 0 0 0 0", "output": "NO" }, { "input": "1 1 3 1 1 11", "output": "NO" }, { "input": "10 10 1 1 1 37", "output": "NO" }, { "input": "1 1 0 0 0 4", "output": "NO" }, { "input": "1 1 10 1 1 28", "output": "NO" }, { "input": "1 5 5 5 6 8", "output": "YES" }, { "input": "0 2 3 4 4 5", "output": "YES" } ]
1,606,984,105
2,147,483,647
Python 3
OK
TESTS
53
109
0
num=list(map(int,input().split())) total=0 total=sum(num) #print(total) #if total%2!=0: # print("NO") flag=0 for i in range(0,4): for j in range(i+1,5): for k in range(j+1,6): if(num[i]+num[j]+num[k]==total/2): flag=1 break if(flag): print("YES") else: print("NO")
Title: ACM ICPC Time Limit: None seconds Memory Limit: None megabytes Problem Description: In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build exactly two teams. After practice competition, participant number *i* got a score of *a**i*. Team score is defined as sum of scores of its participants. High school management is interested if it's possible to build two teams with equal scores. Your task is to answer that question. Input Specification: The single line contains six integers *a*1,<=...,<=*a*6 (0<=≤<=*a**i*<=≤<=1000) — scores of the participants Output Specification: Print "YES" (quotes for clarity), if it is possible to build teams with equal score, and "NO" otherwise. You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES"). Demo Input: ['1 3 2 1 2 1\n', '1 1 1 1 1 99\n'] Demo Output: ['YES\n', 'NO\n'] Note: In the first sample, first team can be composed of 1st, 2nd and 6th participant, second — of 3rd, 4th and 5th: team scores are 1 + 3 + 1 = 2 + 1 + 2 = 5. In the second sample, score of participant number 6 is too high: his team score will be definitely greater.
```python num=list(map(int,input().split())) total=0 total=sum(num) #print(total) #if total%2!=0: # print("NO") flag=0 for i in range(0,4): for j in range(i+1,5): for k in range(j+1,6): if(num[i]+num[j]+num[k]==total/2): flag=1 break if(flag): print("YES") else: print("NO") ```
3
798
A
Mike and palindrome
PROGRAMMING
1,000
[ "brute force", "constructive algorithms", "strings" ]
null
null
Mike has a string *s* consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome. A palindrome is a string that reads the same backward as forward, for example strings "z", "aaa", "aba", "abccba" are palindromes, but strings "codeforces", "reality", "ab" are not.
The first and single line contains string *s* (1<=≤<=|*s*|<=≤<=15).
Print "YES" (without quotes) if Mike can change exactly one character so that the resulting string is palindrome or "NO" (without quotes) otherwise.
[ "abccaa\n", "abbcca\n", "abcda\n" ]
[ "YES\n", "NO\n", "YES\n" ]
none
500
[ { "input": "abccaa", "output": "YES" }, { "input": "abbcca", "output": "NO" }, { "input": "abcda", "output": "YES" }, { "input": "kyw", "output": "YES" }, { "input": "fccf", "output": "NO" }, { "input": "mnlm", "output": "YES" }, { "input": "gqrk", "output": "NO" }, { "input": "glxlg", "output": "YES" }, { "input": "czhfc", "output": "YES" }, { "input": "broon", "output": "NO" }, { "input": "rmggmr", "output": "NO" }, { "input": "wvxxzw", "output": "YES" }, { "input": "ukvciu", "output": "NO" }, { "input": "vrnwnrv", "output": "YES" }, { "input": "vlkjkav", "output": "YES" }, { "input": "guayhmg", "output": "NO" }, { "input": "lkvhhvkl", "output": "NO" }, { "input": "ffdsslff", "output": "YES" }, { "input": "galjjtyw", "output": "NO" }, { "input": "uosgwgsou", "output": "YES" }, { "input": "qjwmjmljq", "output": "YES" }, { "input": "ustrvrodf", "output": "NO" }, { "input": "a", "output": "YES" }, { "input": "qjfyjjyfjq", "output": "NO" }, { "input": "ysxibbixsq", "output": "YES" }, { "input": "howfslfwmh", "output": "NO" }, { "input": "ekhajrjahke", "output": "YES" }, { "input": "ucnolsloncw", "output": "YES" }, { "input": "jrzsfrrkrtj", "output": "NO" }, { "input": "typayzzyapyt", "output": "NO" }, { "input": "uwdhkzokhdwu", "output": "YES" }, { "input": "xokxpyyuafij", "output": "NO" }, { "input": "eusneioiensue", "output": "YES" }, { "input": "fuxpuajabpxuf", "output": "YES" }, { "input": "guvggtfhlgruy", "output": "NO" }, { "input": "cojhkhxxhkhjoc", "output": "NO" }, { "input": "mhifbmmmmbmihm", "output": "YES" }, { "input": "kxfqqncnebpami", "output": "NO" }, { "input": "scfwrjevejrwfcs", "output": "YES" }, { "input": "thdaonpepdoadht", "output": "YES" }, { "input": "jsfzcbnhsccuqsj", "output": "NO" }, { "input": "nn", "output": "NO" }, { "input": "nm", "output": "YES" }, { "input": "jdj", "output": "YES" }, { "input": "bbcaa", "output": "NO" }, { "input": "abcde", "output": "NO" }, { "input": "abcdf", "output": "NO" }, { "input": "aa", "output": "NO" }, { "input": "abecd", "output": "NO" }, { "input": "abccacb", "output": "NO" }, { "input": "aabc", "output": "NO" }, { "input": "anpqb", "output": "NO" }, { "input": "c", "output": "YES" }, { "input": "abcdefg", "output": "NO" }, { "input": "aanbb", "output": "NO" }, { "input": "aabbb", "output": "NO" }, { "input": "aaabbab", "output": "NO" }, { "input": "ab", "output": "YES" }, { "input": "aabbc", "output": "NO" }, { "input": "ecabd", "output": "NO" }, { "input": "abcdrty", "output": "NO" }, { "input": "abcdmnp", "output": "NO" }, { "input": "bbbbbb", "output": "NO" }, { "input": "abcxuio", "output": "NO" }, { "input": "abcdabcde", "output": "NO" }, { "input": "abcxpoi", "output": "NO" }, { "input": "aba", "output": "YES" }, { "input": "aacbb", "output": "NO" }, { "input": "abcedca", "output": "NO" }, { "input": "abcdd", "output": "NO" }, { "input": "abbcs", "output": "NO" }, { "input": "aaabccc", "output": "NO" }, { "input": "paxkxbq", "output": "NO" }, { "input": "z", "output": "YES" }, { "input": "b", "output": "YES" }, { "input": "abcdefghi", "output": "NO" }, { "input": "abcqr", "output": "NO" }, { "input": "abcdc", "output": "NO" }, { "input": "abcb", "output": "NO" }, { "input": "aabcd", "output": "NO" }, { "input": "abbba", "output": "YES" }, { "input": "aaabbb", "output": "NO" }, { "input": "bb", "output": "NO" }, { "input": "aaacbbb", "output": "NO" }, { "input": "abbzcca", "output": "NO" }, { "input": "abxab", "output": "NO" }, { "input": "bbb", "output": "YES" }, { "input": "abcrtyu", "output": "NO" }, { "input": "cbacb", "output": "NO" }, { "input": "acbb", "output": "NO" }, { "input": "ww", "output": "NO" }, { "input": "aaaaaa", "output": "NO" }, { "input": "jizzz", "output": "NO" }, { "input": "aaakcba", "output": "NO" }, { "input": "acbak", "output": "NO" }, { "input": "bddeffd", "output": "NO" }, { "input": "aaa", "output": "YES" }, { "input": "afghqwe", "output": "NO" }, { "input": "abcdfga", "output": "NO" } ]
1,694,665,482
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
7
31
0
x=list(input()) l=len(x) c=0 for i in range(l): if x[i]!=x[l-i-1] and i<=l-i-1: c=c+1 if c==1: print("YES") else: print("NO")
Title: Mike and palindrome Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mike has a string *s* consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome. A palindrome is a string that reads the same backward as forward, for example strings "z", "aaa", "aba", "abccba" are palindromes, but strings "codeforces", "reality", "ab" are not. Input Specification: The first and single line contains string *s* (1<=≤<=|*s*|<=≤<=15). Output Specification: Print "YES" (without quotes) if Mike can change exactly one character so that the resulting string is palindrome or "NO" (without quotes) otherwise. Demo Input: ['abccaa\n', 'abbcca\n', 'abcda\n'] Demo Output: ['YES\n', 'NO\n', 'YES\n'] Note: none
```python x=list(input()) l=len(x) c=0 for i in range(l): if x[i]!=x[l-i-1] and i<=l-i-1: c=c+1 if c==1: print("YES") else: print("NO") ```
0
499
A
Watching a movie
PROGRAMMING
1,000
[ "greedy", "implementation" ]
null
null
You have decided to watch the best moments of some movie. There are two buttons on your player: 1. Watch the current minute of the movie. By pressing this button, you watch the current minute of the movie and the player automatically proceeds to the next minute of the movie. 1. Skip exactly *x* minutes of the movie (*x* is some fixed positive integer). If the player is now at the *t*-th minute of the movie, then as a result of pressing this button, it proceeds to the minute (*t*<=+<=*x*). Initially the movie is turned on in the player on the first minute, and you want to watch exactly *n* best moments of the movie, the *i*-th best moment starts at the *l**i*-th minute and ends at the *r**i*-th minute (more formally, the *i*-th best moment consists of minutes: *l**i*,<=*l**i*<=+<=1,<=...,<=*r**i*). Determine, what is the minimum number of minutes of the movie you have to watch if you want to watch all the best moments?
The first line contains two space-separated integers *n*, *x* (1<=≤<=*n*<=≤<=50, 1<=≤<=*x*<=≤<=105) — the number of the best moments of the movie and the value of *x* for the second button. The following *n* lines contain the descriptions of the best moments of the movie, the *i*-th line of the description contains two integers separated by a space *l**i*, *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=105). It is guaranteed that for all integers *i* from 2 to *n* the following condition holds: *r**i*<=-<=1<=&lt;<=*l**i*.
Output a single number — the answer to the problem.
[ "2 3\n5 6\n10 12\n", "1 1\n1 100000\n" ]
[ "6\n", "100000\n" ]
In the first sample, the player was initially standing on the first minute. As the minutes from the 1-st to the 4-th one don't contain interesting moments, we press the second button. Now we can not press the second button and skip 3 more minutes, because some of them contain interesting moments. Therefore, we watch the movie from the 4-th to the 6-th minute, after that the current time is 7. Similarly, we again skip 3 minutes and then watch from the 10-th to the 12-th minute of the movie. In total, we watch 6 minutes of the movie. In the second sample, the movie is very interesting, so you'll have to watch all 100000 minutes of the movie.
500
[ { "input": "2 3\n5 6\n10 12", "output": "6" }, { "input": "1 1\n1 100000", "output": "100000" }, { "input": "10 1\n2156 3497\n4784 7775\n14575 31932\n33447 35902\n36426 47202\n48772 60522\n63982 68417\n78537 79445\n90081 90629\n94325 95728", "output": "53974" }, { "input": "10 3\n2156 3497\n4784 7775\n14575 31932\n33447 35902\n36426 47202\n48772 60522\n63982 68417\n78537 79445\n90081 90629\n94325 95728", "output": "53983" }, { "input": "10 10\n2156 3497\n4784 7775\n14575 31932\n33447 35902\n36426 47202\n48772 60522\n63982 68417\n78537 79445\n90081 90629\n94325 95728", "output": "54038" }, { "input": "10 1000\n2156 3497\n4784 7775\n14575 31932\n33447 35902\n36426 47202\n48772 60522\n63982 68417\n78537 79445\n90081 90629\n94325 95728", "output": "58728" }, { "input": "12 14\n2156 3497\n4784 7775\n14575 23857\n29211 30739\n31932 33447\n35902 36426\n47202 48772\n60522 63982\n68417 78537\n79445 86918\n90081 90629\n94325 95728", "output": "41870" }, { "input": "12 17\n2156 3497\n4784 7775\n14575 23857\n29211 30739\n31932 33447\n35902 36426\n47202 48772\n60522 63982\n68417 78537\n79445 86918\n90081 90629\n94325 95728", "output": "41872" }, { "input": "18 111\n1449 2156\n3497 4784\n7775 14575\n23857 24593\n29211 30739\n31932 33447\n35902 36426\n36991 38506\n39679 47202\n48772 60016\n60522 61868\n63340 63982\n68417 78537\n79445 86568\n86918 87940\n90081 90310\n90629 94325\n95728 96263", "output": "58967" }, { "input": "1 1\n14575 60522", "output": "45948" }, { "input": "1 10\n14575 60522", "output": "45952" }, { "input": "2 10\n14575 36426\n60522 79445", "output": "40785" }, { "input": "3 1\n14575 36426\n48772 60522\n79445 90081", "output": "44240" }, { "input": "1 100000\n1 100000", "output": "100000" }, { "input": "1 2\n2 100000", "output": "100000" }, { "input": "1 3\n4 100000", "output": "99997" }, { "input": "2 100\n5 6\n7 7", "output": "7" }, { "input": "1 10000\n500 600", "output": "600" }, { "input": "2 3\n1 3\n4 8", "output": "8" }, { "input": "3 1\n1 2\n3 4\n6 7", "output": "6" }, { "input": "1 1\n1 1", "output": "1" }, { "input": "1 3\n5 6", "output": "3" }, { "input": "1 5\n7 10", "output": "5" }, { "input": "1 100\n5 6", "output": "6" }, { "input": "1 2\n1 1", "output": "1" }, { "input": "1 100000\n100000 100000", "output": "100000" }, { "input": "2 3\n1 1\n5 6", "output": "3" } ]
1,649,047,196
2,147,483,647
Python 3
OK
TESTS
41
46
0
n, x = input().split() n = int(n) x = int(x) sm = 0 j = 1 for i in range(n): l, r = input().split() l = int(l) r = int(r) while(1): if j+x-1 >= l or j+x-1 >= r: sm = sm+r-j+1 j = r+1 break else: j = j+x print(sm)
Title: Watching a movie Time Limit: None seconds Memory Limit: None megabytes Problem Description: You have decided to watch the best moments of some movie. There are two buttons on your player: 1. Watch the current minute of the movie. By pressing this button, you watch the current minute of the movie and the player automatically proceeds to the next minute of the movie. 1. Skip exactly *x* minutes of the movie (*x* is some fixed positive integer). If the player is now at the *t*-th minute of the movie, then as a result of pressing this button, it proceeds to the minute (*t*<=+<=*x*). Initially the movie is turned on in the player on the first minute, and you want to watch exactly *n* best moments of the movie, the *i*-th best moment starts at the *l**i*-th minute and ends at the *r**i*-th minute (more formally, the *i*-th best moment consists of minutes: *l**i*,<=*l**i*<=+<=1,<=...,<=*r**i*). Determine, what is the minimum number of minutes of the movie you have to watch if you want to watch all the best moments? Input Specification: The first line contains two space-separated integers *n*, *x* (1<=≤<=*n*<=≤<=50, 1<=≤<=*x*<=≤<=105) — the number of the best moments of the movie and the value of *x* for the second button. The following *n* lines contain the descriptions of the best moments of the movie, the *i*-th line of the description contains two integers separated by a space *l**i*, *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=105). It is guaranteed that for all integers *i* from 2 to *n* the following condition holds: *r**i*<=-<=1<=&lt;<=*l**i*. Output Specification: Output a single number — the answer to the problem. Demo Input: ['2 3\n5 6\n10 12\n', '1 1\n1 100000\n'] Demo Output: ['6\n', '100000\n'] Note: In the first sample, the player was initially standing on the first minute. As the minutes from the 1-st to the 4-th one don't contain interesting moments, we press the second button. Now we can not press the second button and skip 3 more minutes, because some of them contain interesting moments. Therefore, we watch the movie from the 4-th to the 6-th minute, after that the current time is 7. Similarly, we again skip 3 minutes and then watch from the 10-th to the 12-th minute of the movie. In total, we watch 6 minutes of the movie. In the second sample, the movie is very interesting, so you'll have to watch all 100000 minutes of the movie.
```python n, x = input().split() n = int(n) x = int(x) sm = 0 j = 1 for i in range(n): l, r = input().split() l = int(l) r = int(r) while(1): if j+x-1 >= l or j+x-1 >= r: sm = sm+r-j+1 j = r+1 break else: j = j+x print(sm) ```
3
518
B
Tanya and Postcard
PROGRAMMING
1,400
[ "greedy", "implementation", "strings" ]
null
null
Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message — string *s* of length *n*, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she found a newspaper and decided to cut out the letters and glue them into the postcard to achieve string *s*. The newspaper contains string *t*, consisting of uppercase and lowercase English letters. We know that the length of string *t* greater or equal to the length of the string *s*. The newspaper may possibly have too few of some letters needed to make the text and too many of some other letters. That's why Tanya wants to cut some *n* letters out of the newspaper and make a message of length exactly *n*, so that it looked as much as possible like *s*. If the letter in some position has correct value and correct letter case (in the string *s* and in the string that Tanya will make), then she shouts joyfully "YAY!", and if the letter in the given position has only the correct value but it is in the wrong case, then the girl says "WHOOPS". Tanya wants to make such message that lets her shout "YAY!" as much as possible. If there are multiple ways to do this, then her second priority is to maximize the number of times she says "WHOOPS". Your task is to help Tanya make the message.
The first line contains line *s* (1<=≤<=|*s*|<=≤<=2·105), consisting of uppercase and lowercase English letters — the text of Tanya's message. The second line contains line *t* (|*s*|<=≤<=|*t*|<=≤<=2·105), consisting of uppercase and lowercase English letters — the text written in the newspaper. Here |*a*| means the length of the string *a*.
Print two integers separated by a space: - the first number is the number of times Tanya shouts "YAY!" while making the message, - the second number is the number of times Tanya says "WHOOPS" while making the message.
[ "AbC\nDCbA\n", "ABC\nabc\n", "abacaba\nAbaCaBA\n" ]
[ "3 0\n", "0 3\n", "3 4\n" ]
none
1,000
[ { "input": "AbC\nDCbA", "output": "3 0" }, { "input": "ABC\nabc", "output": "0 3" }, { "input": "abacaba\nAbaCaBA", "output": "3 4" }, { "input": "zzzzz\nZZZZZ", "output": "0 5" }, { "input": "zzzZZZ\nZZZzzZ", "output": "5 1" }, { "input": "abcdefghijklmnopqrstuvwxyz\nABCDEFGHIJKLMNOPQRSTUVWXYZ", "output": "0 26" }, { "input": "abcdefghijklmnopqrstuvwxyz\nqrsimtabuvzhnwcdefgjklxyop", "output": "26 0" }, { "input": "l\nFPbAVjsMpPDTLkfwNYFmBDHPTDSWSOUlrBHYJHPM", "output": "1 0" }, { "input": "ncMeXssLHS\nuwyeMcaFatpInZVdEYpwJQSnVxLK", "output": "6 1" }, { "input": "DpiNBmCRFWxpdbfGOzvvOcemjructoAdEwegTvbVbfWWRPGyEAxGdDRWVlqNyGWMWHMrHAIZpyxvgaflrsVZhhZRouvpxrKXFZam\nwwPLFtNfPtJXvMLuHjKfYyaRhreNSWSzOvDpqHCGcqllACNPGHxReeFUCmAqIKXYytsSQwIxJzNiiUtgebVuwRmWpRALLyKAzyDPvgIGxALSaeeTIqm", "output": "66 12" }, { "input": "CCAE\ndcecc", "output": "0 3" }, { "input": "Dccb\nbeeeb", "output": "1 0" }, { "input": "Adc\neadeabcad", "output": "2 1" }, { "input": "DBAdeb\ndeeabcddadaa", "output": "3 2" }, { "input": "EDCED\neebeacdba", "output": "0 4" }, { "input": "CdAbD\ndecbde", "output": "2 2" }, { "input": "a\nB", "output": "0 0" }, { "input": "r\nqA", "output": "0 0" } ]
1,691,018,002
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
4
62
0
s = input() t = input() sim, nao = 0, 0 for char in t: if char in s: sim += 1 elif char.lower() not in s.lower(): nao += 1 print(f'{sim} {len(t) - sim - nao}')
Title: Tanya and Postcard Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message — string *s* of length *n*, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she found a newspaper and decided to cut out the letters and glue them into the postcard to achieve string *s*. The newspaper contains string *t*, consisting of uppercase and lowercase English letters. We know that the length of string *t* greater or equal to the length of the string *s*. The newspaper may possibly have too few of some letters needed to make the text and too many of some other letters. That's why Tanya wants to cut some *n* letters out of the newspaper and make a message of length exactly *n*, so that it looked as much as possible like *s*. If the letter in some position has correct value and correct letter case (in the string *s* and in the string that Tanya will make), then she shouts joyfully "YAY!", and if the letter in the given position has only the correct value but it is in the wrong case, then the girl says "WHOOPS". Tanya wants to make such message that lets her shout "YAY!" as much as possible. If there are multiple ways to do this, then her second priority is to maximize the number of times she says "WHOOPS". Your task is to help Tanya make the message. Input Specification: The first line contains line *s* (1<=≤<=|*s*|<=≤<=2·105), consisting of uppercase and lowercase English letters — the text of Tanya's message. The second line contains line *t* (|*s*|<=≤<=|*t*|<=≤<=2·105), consisting of uppercase and lowercase English letters — the text written in the newspaper. Here |*a*| means the length of the string *a*. Output Specification: Print two integers separated by a space: - the first number is the number of times Tanya shouts "YAY!" while making the message, - the second number is the number of times Tanya says "WHOOPS" while making the message. Demo Input: ['AbC\nDCbA\n', 'ABC\nabc\n', 'abacaba\nAbaCaBA\n'] Demo Output: ['3 0\n', '0 3\n', '3 4\n'] Note: none
```python s = input() t = input() sim, nao = 0, 0 for char in t: if char in s: sim += 1 elif char.lower() not in s.lower(): nao += 1 print(f'{sim} {len(t) - sim - nao}') ```
0
915
C
Permute Digits
PROGRAMMING
1,700
[ "dp", "greedy" ]
null
null
You are given two positive integer numbers *a* and *b*. Permute (change order) of the digits of *a* to construct maximal number not exceeding *b*. No number in input and/or output can start with the digit 0. It is allowed to leave *a* as it is.
The first line contains integer *a* (1<=≤<=*a*<=≤<=1018). The second line contains integer *b* (1<=≤<=*b*<=≤<=1018). Numbers don't have leading zeroes. It is guaranteed that answer exists.
Print the maximum possible number that is a permutation of digits of *a* and is not greater than *b*. The answer can't have any leading zeroes. It is guaranteed that the answer exists. The number in the output should have exactly the same length as number *a*. It should be a permutation of digits of *a*.
[ "123\n222\n", "3921\n10000\n", "4940\n5000\n" ]
[ "213\n", "9321\n", "4940\n" ]
none
0
[ { "input": "123\n222", "output": "213" }, { "input": "3921\n10000", "output": "9321" }, { "input": "4940\n5000", "output": "4940" }, { "input": "23923472834\n23589234723", "output": "23498743322" }, { "input": "102391019\n491010301", "output": "399211100" }, { "input": "123456789123456789\n276193619183618162", "output": "276193618987554432" }, { "input": "1000000000000000000\n1000000000000000000", "output": "1000000000000000000" }, { "input": "1\n1000000000000000000", "output": "1" }, { "input": "999999999999999999\n1000000000000000000", "output": "999999999999999999" }, { "input": "2475345634895\n3455834583479", "output": "3455834579642" }, { "input": "15778899\n98715689", "output": "98598771" }, { "input": "4555\n5454", "output": "4555" }, { "input": "122112\n221112", "output": "221112" }, { "input": "199999999999991\n191000000000000", "output": "119999999999999" }, { "input": "13\n31", "output": "31" }, { "input": "212\n211", "output": "122" }, { "input": "222234\n322223", "output": "243222" }, { "input": "123456789\n987654311", "output": "987654231" }, { "input": "20123\n21022", "output": "20321" }, { "input": "10101\n11000", "output": "10110" }, { "input": "592\n924", "output": "592" }, { "input": "5654456\n5634565", "output": "5566544" }, { "input": "655432\n421631", "output": "365542" }, { "input": "200\n200", "output": "200" }, { "input": "123456789987654321\n121111111111111111", "output": "119988776655443322" }, { "input": "12345\n21344", "output": "15432" }, { "input": "120\n200", "output": "120" }, { "input": "123\n212", "output": "132" }, { "input": "2184645\n5213118", "output": "5186442" }, { "input": "9912346\n9912345", "output": "9694321" }, { "input": "5003\n5000", "output": "3500" }, { "input": "12345\n31234", "output": "25431" }, { "input": "5001\n5000", "output": "1500" }, { "input": "53436\n53425", "output": "53364" }, { "input": "9329\n3268", "output": "2993" }, { "input": "1234567890\n9000000001", "output": "8976543210" }, { "input": "321\n212", "output": "132" }, { "input": "109823464\n901234467", "output": "896443210" }, { "input": "6543\n6542", "output": "6534" }, { "input": "555441\n555100", "output": "554541" }, { "input": "472389479\n327489423", "output": "327487994" }, { "input": "45645643756464352\n53465475637456247", "output": "53465475636654442" }, { "input": "254\n599", "output": "542" }, { "input": "5232222345652321\n5000000000000000", "output": "4655533322222221" }, { "input": "201\n200", "output": "120" }, { "input": "14362799391220361\n45160821596433661", "output": "43999766332221110" }, { "input": "3453\n5304", "output": "4533" }, { "input": "989\n998", "output": "998" }, { "input": "5200000000234\n5200000000311", "output": "5200000000243" }, { "input": "5555132\n1325442", "output": "1255553" }, { "input": "123\n211", "output": "132" }, { "input": "65689\n66123", "output": "65986" }, { "input": "123451234567890\n123456789012345", "output": "123456789012345" }, { "input": "22115\n22015", "output": "21521" }, { "input": "123\n311", "output": "231" }, { "input": "12222\n21111", "output": "12222" }, { "input": "765\n567", "output": "567" }, { "input": "9087645\n9087640", "output": "9087564" }, { "input": "1111111122222333\n2220000000000000", "output": "2213332221111111" }, { "input": "7901\n7108", "output": "7091" }, { "input": "215489\n215488", "output": "214985" }, { "input": "102\n200", "output": "120" }, { "input": "19260817\n20011213", "output": "19876210" }, { "input": "12345\n53200", "output": "53142" }, { "input": "1040003001\n1040003000", "output": "1040001300" }, { "input": "295\n924", "output": "592" }, { "input": "20000000000000001\n20000000000000000", "output": "12000000000000000" }, { "input": "99988877\n99887766", "output": "99879887" }, { "input": "12\n12", "output": "12" }, { "input": "199999999999999999\n900000000000000000", "output": "199999999999999999" }, { "input": "1234\n4310", "output": "4231" }, { "input": "100011\n100100", "output": "100011" }, { "input": "328899\n328811", "output": "299883" }, { "input": "646722972346\n397619201220", "output": "397476664222" }, { "input": "1203\n1200", "output": "1032" }, { "input": "1\n2", "output": "1" }, { "input": "1112\n2110", "output": "1211" }, { "input": "4545\n5540", "output": "5454" }, { "input": "3053\n5004", "output": "3530" }, { "input": "3503\n5004", "output": "3530" }, { "input": "351731653766064847\n501550303749042658", "output": "501548777666643331" }, { "input": "10123456789013451\n26666666666666666", "output": "26598754433111100" }, { "input": "1110111\n1100000", "output": "1011111" }, { "input": "30478\n32265", "output": "30874" }, { "input": "456546546549874615\n441554543131214545", "output": "441554498766665554" }, { "input": "214\n213", "output": "142" }, { "input": "415335582799619283\n133117803602859310", "output": "132999887655543321" }, { "input": "787\n887", "output": "877" }, { "input": "3333222288889999\n3333222288881111", "output": "3332999988883222" }, { "input": "495779862481416791\n836241745208800994", "output": "829998777665444111" }, { "input": "139\n193", "output": "193" }, { "input": "9568\n6500", "output": "5986" }, { "input": "3208899\n3228811", "output": "3209988" }, { "input": "27778\n28710", "output": "27877" }, { "input": "62345\n46415", "output": "46352" }, { "input": "405739873179209\n596793907108871", "output": "594998777332100" }, { "input": "365\n690", "output": "653" }, { "input": "8388731334391\n4710766672578", "output": "4398887333311" }, { "input": "1230\n1200", "output": "1032" }, { "input": "1025\n5000", "output": "2510" }, { "input": "4207799\n4027711", "output": "2997740" }, { "input": "4444222277779999\n4444222277771111", "output": "4442999977774222" }, { "input": "7430\n3047", "output": "3047" }, { "input": "649675735\n540577056", "output": "539776654" }, { "input": "26\n82", "output": "62" }, { "input": "241285\n207420", "output": "185422" }, { "input": "3\n3", "output": "3" }, { "input": "12\n21", "output": "21" }, { "input": "481287\n826607", "output": "824871" }, { "input": "40572351\n59676984", "output": "57543210" }, { "input": "268135787269\n561193454469", "output": "539887766221" }, { "input": "4\n9", "output": "4" }, { "input": "5\n6", "output": "5" }, { "input": "60579839\n33370073", "output": "30998765" }, { "input": "49939\n39200", "output": "34999" }, { "input": "2224\n4220", "output": "2422" }, { "input": "427799\n427711", "output": "299774" }, { "input": "49\n90", "output": "49" }, { "input": "93875\n82210", "output": "79853" }, { "input": "78831\n7319682", "output": "88731" }, { "input": "937177\n7143444", "output": "977731" }, { "input": "499380628\n391990337", "output": "390988642" }, { "input": "2090909\n2900000", "output": "2099900" }, { "input": "112233445566778890\n987654321987654320", "output": "987654321876543210" }, { "input": "48257086\n80903384", "output": "80876542" }, { "input": "112233445566778890\n900654321987654320", "output": "898776655443322110" }, { "input": "112233445566778890\n123456789123456788", "output": "123456789123456780" }, { "input": "5207799\n5027711", "output": "2997750" }, { "input": "200000000000000001\n200000000000000000", "output": "120000000000000000" }, { "input": "597402457\n797455420", "output": "797455420" }, { "input": "90\n94", "output": "90" }, { "input": "86888\n88683", "output": "86888" }, { "input": "419155888\n588151913", "output": "588151894" }, { "input": "408919130\n191830070", "output": "191830049" }, { "input": "524975\n554924", "output": "554792" }, { "input": "53029\n30524", "output": "30295" }, { "input": "5549\n5542", "output": "5495" }, { "input": "6\n9", "output": "6" }, { "input": "87\n810", "output": "87" }, { "input": "920491855\n281495062", "output": "281495059" }, { "input": "6691\n6910", "output": "6691" }, { "input": "533\n335", "output": "335" }, { "input": "999999999999999998\n999999999999999997", "output": "999999999999999989" }, { "input": "21111111111111111\n21111111111111110", "output": "12111111111111111" }, { "input": "2\n12", "output": "2" }, { "input": "76544\n45744", "output": "45674" }, { "input": "2000000000000001\n2000000000000000", "output": "1200000000000000" }, { "input": "740867\n467701", "output": "467087" }, { "input": "2\n6", "output": "2" }, { "input": "103\n130", "output": "130" }, { "input": "2423712\n8466235", "output": "7432221" }, { "input": "84\n48", "output": "48" }, { "input": "1210\n12113", "output": "2110" }, { "input": "2430\n20786", "output": "4320" }, { "input": "100\n999", "output": "100" }, { "input": "19325\n21903", "output": "21593" }, { "input": "1969\n23251", "output": "9961" } ]
1,697,167,659
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
5
46
0
a = input() b = input() bucket = [0 for i in range(10)] for el in a: bucket[int(el)] += 1 bucket2 = bucket[::] ordered_a = ["0" for i in range(len(a))] if len(a) < len(b): for j in range(len(a)): for dig in range(9, -1, -1): if bucket[dig] != 0: bucket[dig] -= 1 ordered_a[j] = str(dig) break print("".join(ordered_a)) else: i = 0 con = True while con: for dig in range(9, -1, -1): if bucket[dig] != 0 and dig <= int(b[i]): bucket[dig] -= 1 ordered_a[i] = str(dig) # print(dig, b[i], dig < int(b[i])) if dig < int(b[i]): con = False i += 1 break else: con = False for j in range(i, len(a)): for dig in range(9, -1, -1): if bucket[dig] != 0: bucket[dig] -= 1 ordered_a[j] = str(dig) break if int("".join(ordered_a)) <= int(b): print(int("".join(ordered_a))) else: # print(":D") ordered_a = ["0" for i in range(len(a))] for i in range(len(a)): con = True for dig in range(9, -1, -1): if bucket2[dig] != 0 and dig < int(b[i]): ordered_a[i] = str(dig) bucket2[dig] -= 1 con = False if not con: for j in range(i+1, len(a)): for dig in range(9, -1, -1): if bucket2[dig] != 0: ordered_a[j] = str(dig) bucket2[dig] -= 1 break print("".join(ordered_a))
Title: Permute Digits Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given two positive integer numbers *a* and *b*. Permute (change order) of the digits of *a* to construct maximal number not exceeding *b*. No number in input and/or output can start with the digit 0. It is allowed to leave *a* as it is. Input Specification: The first line contains integer *a* (1<=≤<=*a*<=≤<=1018). The second line contains integer *b* (1<=≤<=*b*<=≤<=1018). Numbers don't have leading zeroes. It is guaranteed that answer exists. Output Specification: Print the maximum possible number that is a permutation of digits of *a* and is not greater than *b*. The answer can't have any leading zeroes. It is guaranteed that the answer exists. The number in the output should have exactly the same length as number *a*. It should be a permutation of digits of *a*. Demo Input: ['123\n222\n', '3921\n10000\n', '4940\n5000\n'] Demo Output: ['213\n', '9321\n', '4940\n'] Note: none
```python a = input() b = input() bucket = [0 for i in range(10)] for el in a: bucket[int(el)] += 1 bucket2 = bucket[::] ordered_a = ["0" for i in range(len(a))] if len(a) < len(b): for j in range(len(a)): for dig in range(9, -1, -1): if bucket[dig] != 0: bucket[dig] -= 1 ordered_a[j] = str(dig) break print("".join(ordered_a)) else: i = 0 con = True while con: for dig in range(9, -1, -1): if bucket[dig] != 0 and dig <= int(b[i]): bucket[dig] -= 1 ordered_a[i] = str(dig) # print(dig, b[i], dig < int(b[i])) if dig < int(b[i]): con = False i += 1 break else: con = False for j in range(i, len(a)): for dig in range(9, -1, -1): if bucket[dig] != 0: bucket[dig] -= 1 ordered_a[j] = str(dig) break if int("".join(ordered_a)) <= int(b): print(int("".join(ordered_a))) else: # print(":D") ordered_a = ["0" for i in range(len(a))] for i in range(len(a)): con = True for dig in range(9, -1, -1): if bucket2[dig] != 0 and dig < int(b[i]): ordered_a[i] = str(dig) bucket2[dig] -= 1 con = False if not con: for j in range(i+1, len(a)): for dig in range(9, -1, -1): if bucket2[dig] != 0: ordered_a[j] = str(dig) bucket2[dig] -= 1 break print("".join(ordered_a)) ```
0
909
C
Python Indentation
PROGRAMMING
1,800
[ "dp" ]
null
null
In Python, code blocks don't have explicit begin/end or curly braces to mark beginning and end of the block. Instead, code blocks are defined by indentation. We will consider an extremely simplified subset of Python with only two types of statements. Simple statements are written in a single line, one per line. An example of a simple statement is assignment. For statements are compound statements: they contain one or several other statements. For statement consists of a header written in a separate line which starts with "for" prefix, and loop body. Loop body is a block of statements indented one level further than the header of the loop. Loop body can contain both types of statements. Loop body can't be empty. You are given a sequence of statements without indentation. Find the number of ways in which the statements can be indented to form a valid Python program.
The first line contains a single integer *N* (1<=≤<=*N*<=≤<=5000) — the number of commands in the program. *N* lines of the program follow, each line describing a single command. Each command is either "f" (denoting "for statement") or "s" ("simple statement"). It is guaranteed that the last line is a simple statement.
Output one line containing an integer - the number of ways the given sequence of statements can be indented modulo 109<=+<=7.
[ "4\ns\nf\nf\ns\n", "4\nf\ns\nf\ns\n" ]
[ "1\n", "2\n" ]
In the first test case, there is only one way to indent the program: the second for statement must be part of the body of the first one. In the second test case, there are two ways to indent the program: the second for statement can either be part of the first one's body or a separate statement following the first one. or
1,500
[ { "input": "4\ns\nf\nf\ns", "output": "1" }, { "input": "4\nf\ns\nf\ns", "output": "2" }, { "input": "156\nf\ns\nf\ns\nf\ns\ns\ns\ns\nf\ns\ns\nf\nf\ns\nf\nf\nf\nf\ns\ns\ns\nf\ns\ns\nf\nf\nf\nf\nf\nf\ns\ns\ns\ns\nf\ns\nf\ns\nf\ns\nf\nf\nf\nf\ns\ns\nf\nf\ns\ns\ns\ns\nf\ns\nf\ns\nf\ns\nf\ns\ns\ns\nf\ns\ns\nf\ns\nf\nf\ns\ns\ns\nf\nf\nf\nf\ns\ns\nf\nf\nf\nf\nf\nf\nf\ns\nf\ns\ns\ns\nf\nf\ns\ns\ns\ns\ns\nf\nf\nf\nf\ns\nf\nf\ns\nf\ns\ns\nf\nf\nf\ns\ns\ns\nf\ns\ns\nf\ns\nf\nf\nf\ns\nf\nf\ns\ns\nf\ns\nf\nf\ns\ns\ns\ns\nf\ns\nf\nf\ns\ns\nf\nf\nf\ns\ns\nf\nf\nf\ns\nf\ns\nf\nf\ns", "output": "666443222" }, { "input": "4\nf\nf\ns\ns", "output": "3" }, { "input": "2\nf\ns", "output": "1" }, { "input": "1\ns", "output": "1" }, { "input": "3\nf\nf\ns", "output": "1" }, { "input": "2\ns\ns", "output": "1" }, { "input": "156\ns\nf\ns\ns\ns\ns\nf\ns\ns\ns\nf\nf\ns\nf\nf\ns\nf\nf\nf\ns\nf\nf\ns\nf\nf\ns\ns\nf\nf\ns\nf\nf\nf\nf\nf\ns\ns\nf\ns\nf\nf\nf\ns\nf\nf\nf\ns\ns\ns\nf\ns\ns\nf\nf\ns\ns\nf\ns\nf\nf\ns\nf\nf\nf\ns\ns\nf\nf\ns\nf\ns\ns\ns\ns\ns\ns\ns\nf\ns\nf\nf\nf\ns\ns\ns\ns\nf\nf\ns\nf\nf\ns\ns\nf\ns\nf\ns\ns\nf\nf\nf\nf\nf\ns\nf\ns\ns\nf\nf\ns\nf\nf\ns\ns\ns\nf\ns\ns\ns\ns\nf\nf\ns\nf\nf\nf\nf\ns\nf\ns\ns\nf\nf\ns\nf\ns\nf\nf\nf\nf\ns\ns\nf\nf\nf\nf\ns\nf\ns\nf\ns\ns\ns\nf\nf\ns", "output": "479461584" }, { "input": "66\ns\nf\ns\ns\nf\ns\ns\ns\ns\nf\ns\ns\nf\nf\ns\ns\nf\ns\ns\nf\ns\ns\nf\nf\ns\ns\nf\nf\ns\ns\nf\ns\ns\ns\ns\nf\nf\ns\ns\nf\nf\ns\ns\nf\ns\ns\nf\ns\ns\nf\ns\ns\nf\nf\ns\nf\ns\ns\nf\nf\ns\nf\ns\nf\nf\ns", "output": "392847498" } ]
1,633,899,111
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
46
204,800
n = int(input()) dp = [[0] * n for _ in range(n + 1)] dp[0][0] = 1 ps = [[0] * n for _ in range(n + 1)] ps[0][0] = 1 a = [] for i in range(1, n + 1): op = input() if len(a) > 0 and a[-1] == 'f': for j in range(1, i): dp[i][j] = dp[i - 1][j - 1] else: for j in range(i): dp[i][j] = ps[i - 1][j] ps[i][-1] = dp[i][-1] for j in range(n - 2, -1, -1): ps[i][j] = ps[i][j + 1] + dp[i][j] a.append(op) print(sum(dp[n]))
Title: Python Indentation Time Limit: None seconds Memory Limit: None megabytes Problem Description: In Python, code blocks don't have explicit begin/end or curly braces to mark beginning and end of the block. Instead, code blocks are defined by indentation. We will consider an extremely simplified subset of Python with only two types of statements. Simple statements are written in a single line, one per line. An example of a simple statement is assignment. For statements are compound statements: they contain one or several other statements. For statement consists of a header written in a separate line which starts with "for" prefix, and loop body. Loop body is a block of statements indented one level further than the header of the loop. Loop body can contain both types of statements. Loop body can't be empty. You are given a sequence of statements without indentation. Find the number of ways in which the statements can be indented to form a valid Python program. Input Specification: The first line contains a single integer *N* (1<=≤<=*N*<=≤<=5000) — the number of commands in the program. *N* lines of the program follow, each line describing a single command. Each command is either "f" (denoting "for statement") or "s" ("simple statement"). It is guaranteed that the last line is a simple statement. Output Specification: Output one line containing an integer - the number of ways the given sequence of statements can be indented modulo 109<=+<=7. Demo Input: ['4\ns\nf\nf\ns\n', '4\nf\ns\nf\ns\n'] Demo Output: ['1\n', '2\n'] Note: In the first test case, there is only one way to indent the program: the second for statement must be part of the body of the first one. In the second test case, there are two ways to indent the program: the second for statement can either be part of the first one's body or a separate statement following the first one. or
```python n = int(input()) dp = [[0] * n for _ in range(n + 1)] dp[0][0] = 1 ps = [[0] * n for _ in range(n + 1)] ps[0][0] = 1 a = [] for i in range(1, n + 1): op = input() if len(a) > 0 and a[-1] == 'f': for j in range(1, i): dp[i][j] = dp[i - 1][j - 1] else: for j in range(i): dp[i][j] = ps[i - 1][j] ps[i][-1] = dp[i][-1] for j in range(n - 2, -1, -1): ps[i][j] = ps[i][j + 1] + dp[i][j] a.append(op) print(sum(dp[n])) ```
0
441
B
Valera and Fruits
PROGRAMMING
1,400
[ "greedy", "implementation" ]
null
null
Valera loves his garden, where *n* fruit trees grow. This year he will enjoy a great harvest! On the *i*-th tree *b**i* fruit grow, they will ripen on a day number *a**i*. Unfortunately, the fruit on the tree get withered, so they can only be collected on day *a**i* and day *a**i*<=+<=1 (all fruits that are not collected in these two days, become unfit to eat). Valera is not very fast, but there are some positive points. Valera is ready to work every day. In one day, Valera can collect no more than *v* fruits. The fruits may be either from the same tree, or from different ones. What is the maximum amount of fruit Valera can collect for all time, if he operates optimally well?
The first line contains two space-separated integers *n* and *v* (1<=≤<=*n*,<=*v*<=≤<=3000) — the number of fruit trees in the garden and the number of fruits that Valera can collect in a day. Next *n* lines contain the description of trees in the garden. The *i*-th line contains two space-separated integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=3000) — the day the fruits ripen on the *i*-th tree and the number of fruits on the *i*-th tree.
Print a single integer — the maximum number of fruit that Valera can collect.
[ "2 3\n1 5\n2 3\n", "5 10\n3 20\n2 20\n1 20\n4 20\n5 20\n" ]
[ "8\n", "60\n" ]
In the first sample, in order to obtain the optimal answer, you should act as follows. - On the first day collect 3 fruits from the 1-st tree. - On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree. - On the third day collect the remaining fruits from the 2-nd tree. In the second sample, you can only collect 60 fruits, the remaining fruit will simply wither.
1,000
[ { "input": "2 3\n1 5\n2 3", "output": "8" }, { "input": "5 10\n3 20\n2 20\n1 20\n4 20\n5 20", "output": "60" }, { "input": "10 3000\n1 2522\n4 445\n8 1629\n5 772\n9 2497\n6 81\n3 426\n7 1447\n2 575\n10 202", "output": "10596" }, { "input": "5 3000\n5 772\n1 2522\n2 575\n4 445\n3 426", "output": "4740" }, { "input": "2 1500\n2 575\n1 2522", "output": "3097" }, { "input": "12 2856\n9 2728\n8 417\n3 1857\n10 1932\n1 775\n12 982\n9 1447\n1 426\n7 2918\n11 2522\n10 2497\n9 772", "output": "18465" }, { "input": "24 1524\n16 934\n23 1940\n21 1447\n20 417\n24 1340\n22 1932\n13 775\n19 2918\n12 2355\n9 593\n11 2676\n3 1857\n16 868\n13 426\n18 1679\n22 991\n9 2728\n10 2497\n16 1221\n9 772\n23 2522\n24 982\n12 1431\n18 757", "output": "25893" }, { "input": "1 10\n3000 30", "output": "20" }, { "input": "2 1\n30 3\n31 2", "output": "3" }, { "input": "4 2061\n1 426\n3 2522\n1 772\n1 1447", "output": "5167" }, { "input": "2 1\n1 1\n1 1", "output": "2" }, { "input": "1 10\n3000 20", "output": "20" }, { "input": "1 1000\n3000 2000", "output": "2000" }, { "input": "2 100\n3000 100\n3000 100", "output": "200" }, { "input": "2 3\n1 6\n3 6", "output": "12" }, { "input": "1 40\n3000 42", "output": "42" }, { "input": "1 100\n3000 200", "output": "200" }, { "input": "1 50\n3000 100", "output": "100" }, { "input": "1 1\n3000 2", "output": "2" }, { "input": "2 3000\n3000 3000\n3000 3000", "output": "6000" }, { "input": "2 2\n2999 3\n3000 2", "output": "5" }, { "input": "1 2\n3000 3", "output": "3" }, { "input": "2 5\n2999 10\n3000 5", "output": "15" }, { "input": "1 3\n5 3", "output": "3" }, { "input": "2 1000\n2999 2000\n3000 1000", "output": "3000" }, { "input": "1 5\n3000 10", "output": "10" }, { "input": "1 10\n3000 15", "output": "15" }, { "input": "5 1\n10 100\n2698 100\n200 100\n3000 100\n1500 100", "output": "10" }, { "input": "1 1\n3000 3000", "output": "2" }, { "input": "2 10\n2999 100\n3000 100", "output": "30" }, { "input": "1 10\n3000 100", "output": "20" } ]
1,588,212,884
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
4
233
3,686,400
n, v = map(int, input().split()) trees = [] for i in range(n): trees.append([int(j) for j in input().split()]) trees.sort() first = trees[0][0] last = trees[n - 1][0] + 1 dp = [0] * (last + 1) count = 0 for i in range(n): tree = trees[i] day = tree[0] fruit = tree[1] dp[day] += fruit leftovers = max(0, dp[day] - v) dp[day + 1] += leftovers for i in range(first, last + 1): count += min(v, dp[i]) print (count)
Title: Valera and Fruits Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera loves his garden, where *n* fruit trees grow. This year he will enjoy a great harvest! On the *i*-th tree *b**i* fruit grow, they will ripen on a day number *a**i*. Unfortunately, the fruit on the tree get withered, so they can only be collected on day *a**i* and day *a**i*<=+<=1 (all fruits that are not collected in these two days, become unfit to eat). Valera is not very fast, but there are some positive points. Valera is ready to work every day. In one day, Valera can collect no more than *v* fruits. The fruits may be either from the same tree, or from different ones. What is the maximum amount of fruit Valera can collect for all time, if he operates optimally well? Input Specification: The first line contains two space-separated integers *n* and *v* (1<=≤<=*n*,<=*v*<=≤<=3000) — the number of fruit trees in the garden and the number of fruits that Valera can collect in a day. Next *n* lines contain the description of trees in the garden. The *i*-th line contains two space-separated integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=3000) — the day the fruits ripen on the *i*-th tree and the number of fruits on the *i*-th tree. Output Specification: Print a single integer — the maximum number of fruit that Valera can collect. Demo Input: ['2 3\n1 5\n2 3\n', '5 10\n3 20\n2 20\n1 20\n4 20\n5 20\n'] Demo Output: ['8\n', '60\n'] Note: In the first sample, in order to obtain the optimal answer, you should act as follows. - On the first day collect 3 fruits from the 1-st tree. - On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree. - On the third day collect the remaining fruits from the 2-nd tree. In the second sample, you can only collect 60 fruits, the remaining fruit will simply wither.
```python n, v = map(int, input().split()) trees = [] for i in range(n): trees.append([int(j) for j in input().split()]) trees.sort() first = trees[0][0] last = trees[n - 1][0] + 1 dp = [0] * (last + 1) count = 0 for i in range(n): tree = trees[i] day = tree[0] fruit = tree[1] dp[day] += fruit leftovers = max(0, dp[day] - v) dp[day + 1] += leftovers for i in range(first, last + 1): count += min(v, dp[i]) print (count) ```
0
559
B
Equivalent Strings
PROGRAMMING
1,700
[ "divide and conquer", "hashing", "sortings", "strings" ]
null
null
Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings *a* and *b* of equal length are called equivalent in one of the two cases: 1. They are equal. 1. If we split string *a* into two halves of the same size *a*1 and *a*2, and string *b* into two halves of the same size *b*1 and *b*2, then one of the following is correct: *a*1 is equivalent to *b*1, and *a*2 is equivalent to *b*2 1. *a*1 is equivalent to *b*2, and *a*2 is equivalent to *b*1 As a home task, the teacher gave two strings to his students and asked to determine if they are equivalent. Gerald has already completed this home task. Now it's your turn!
The first two lines of the input contain two strings given by the teacher. Each of them has the length from 1 to 200<=000 and consists of lowercase English letters. The strings have the same length.
Print "YES" (without the quotes), if these two strings are equivalent, and "NO" (without the quotes) otherwise.
[ "aaba\nabaa\n", "aabb\nabab\n" ]
[ "YES\n", "NO\n" ]
In the first sample you should split the first string into strings "aa" and "ba", the second one — into strings "ab" and "aa". "aa" is equivalent to "aa"; "ab" is equivalent to "ba" as "ab" = "a" + "b", "ba" = "b" + "a". In the second sample the first string can be splitted into strings "aa" and "bb", that are equivalent only to themselves. That's why string "aabb" is equivalent only to itself and to string "bbaa".
1,000
[ { "input": "aaba\nabaa", "output": "YES" }, { "input": "aabb\nabab", "output": "NO" }, { "input": "a\na", "output": "YES" }, { "input": "a\nb", "output": "NO" }, { "input": "ab\nab", "output": "YES" }, { "input": "ab\nba", "output": "YES" }, { "input": "ab\nbb", "output": "NO" }, { "input": "zzaa\naazz", "output": "YES" }, { "input": "azza\nzaaz", "output": "YES" }, { "input": "abc\nabc", "output": "YES" }, { "input": "abc\nacb", "output": "NO" }, { "input": "azzz\nzzaz", "output": "YES" }, { "input": "abcd\ndcab", "output": "YES" }, { "input": "abcd\ncdab", "output": "YES" }, { "input": "abcd\ndcba", "output": "YES" }, { "input": "abcd\nacbd", "output": "NO" }, { "input": "oloaxgddgujq\noloaxgujqddg", "output": "YES" }, { "input": "uwzwdxfmosmqatyv\ndxfmzwwusomqvyta", "output": "YES" }, { "input": "hagnzomowtledfdotnll\nledfdotnllomowthagnz", "output": "YES" }, { "input": "snyaydaeobufdg\nsnyaydaeobufdg", "output": "YES" }, { "input": "baaaaa\nabaaaa", "output": "NO" }, { "input": "hhiisug\nmzdjwju", "output": "NO" }, { "input": "bbbabbabaaab\naaaabbabbbbb", "output": "NO" }, { "input": "bbaaab\naababb", "output": "NO" }, { "input": "aabbaaaa\naaaaabab", "output": "NO" }, { "input": "aab\naba", "output": "NO" }, { "input": "abcddd\nbacddd", "output": "NO" }, { "input": "qgiufelsfhanx\naaaaaaaaaaaaa", "output": "NO" }, { "input": "aabaababaaba\naababaaababa", "output": "NO" }, { "input": "nocdqzdriyyil\naaaaaaaaaaaaa", "output": "NO" }, { "input": "zdmctxl\nkojqhgw", "output": "NO" }, { "input": "yhwepqwyhwepqwyhwepqweahnqtueahnqtueahnqtuyhwepqwyhwepqwyhwepqwyhwepqweahnqtueahnqtuyhwepqweahnqtueahnqtueahnqtueahnqtueahnqtueahnqtu\neahnqtueahnqtueahnqtuyhwepqweahnqtuyhwepqwyhwepqweahnqtuyhwepqweahnqtuyhwepqweahnqtueahnqtuyhwepqweahnqtueahnqtuyhwepqwyhwepqwyhwepqw", "output": "NO" }, { "input": "abc\nbac", "output": "NO" }, { "input": "ottceez\npcstdvz", "output": "NO" } ]
1,670,657,471
2,147,483,647
PyPy 3-64
TIME_LIMIT_EXCEEDED
TESTS
5
2,000
266,854,400
a = input() b = input() memo = {} def isEquivalent(a, b): state = (a,b) if state in memo: return memo[state] if len(a) == 1 and len(b) == 1: return True if a == b else False if len(a) != len(b): return False mid = len(a)//2 combination_1 = isEquivalent(a[0:mid], b[0:mid]) combination_2 = isEquivalent(a[0:mid], b[mid:]) combination_3 = isEquivalent(a[mid:], b[0:mid]) combination_4 = isEquivalent(a[mid:], b[mid:]) case1 = combination_1 and combination_4 case2 = combination_2 and combination_3 memo[state] = case1 or case2 return case1 or case2 ans = isEquivalent(a,b) if ans: print('YES') else: print('NO')
Title: Equivalent Strings Time Limit: None seconds Memory Limit: None megabytes Problem Description: Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings *a* and *b* of equal length are called equivalent in one of the two cases: 1. They are equal. 1. If we split string *a* into two halves of the same size *a*1 and *a*2, and string *b* into two halves of the same size *b*1 and *b*2, then one of the following is correct: *a*1 is equivalent to *b*1, and *a*2 is equivalent to *b*2 1. *a*1 is equivalent to *b*2, and *a*2 is equivalent to *b*1 As a home task, the teacher gave two strings to his students and asked to determine if they are equivalent. Gerald has already completed this home task. Now it's your turn! Input Specification: The first two lines of the input contain two strings given by the teacher. Each of them has the length from 1 to 200<=000 and consists of lowercase English letters. The strings have the same length. Output Specification: Print "YES" (without the quotes), if these two strings are equivalent, and "NO" (without the quotes) otherwise. Demo Input: ['aaba\nabaa\n', 'aabb\nabab\n'] Demo Output: ['YES\n', 'NO\n'] Note: In the first sample you should split the first string into strings "aa" and "ba", the second one — into strings "ab" and "aa". "aa" is equivalent to "aa"; "ab" is equivalent to "ba" as "ab" = "a" + "b", "ba" = "b" + "a". In the second sample the first string can be splitted into strings "aa" and "bb", that are equivalent only to themselves. That's why string "aabb" is equivalent only to itself and to string "bbaa".
```python a = input() b = input() memo = {} def isEquivalent(a, b): state = (a,b) if state in memo: return memo[state] if len(a) == 1 and len(b) == 1: return True if a == b else False if len(a) != len(b): return False mid = len(a)//2 combination_1 = isEquivalent(a[0:mid], b[0:mid]) combination_2 = isEquivalent(a[0:mid], b[mid:]) combination_3 = isEquivalent(a[mid:], b[0:mid]) combination_4 = isEquivalent(a[mid:], b[mid:]) case1 = combination_1 and combination_4 case2 = combination_2 and combination_3 memo[state] = case1 or case2 return case1 or case2 ans = isEquivalent(a,b) if ans: print('YES') else: print('NO') ```
0
493
C
Vasya and Basketball
PROGRAMMING
1,600
[ "binary search", "brute force", "data structures", "implementation", "sortings", "two pointers" ]
null
null
Vasya follows a basketball game and marks the distances from which each team makes a throw. He knows that each successful throw has value of either 2 or 3 points. A throw is worth 2 points if the distance it was made from doesn't exceed some value of *d* meters, and a throw is worth 3 points if the distance is larger than *d* meters, where *d* is some non-negative integer. Vasya would like the advantage of the points scored by the first team (the points of the first team minus the points of the second team) to be maximum. For that he can mentally choose the value of *d*. Help him to do that.
The first line contains integer *n* (1<=≤<=*n*<=≤<=2·105) — the number of throws of the first team. Then follow *n* integer numbers — the distances of throws *a**i* (1<=≤<=*a**i*<=≤<=2·109). Then follows number *m* (1<=≤<=*m*<=≤<=2·105) — the number of the throws of the second team. Then follow *m* integer numbers — the distances of throws of *b**i* (1<=≤<=*b**i*<=≤<=2·109).
Print two numbers in the format a:b — the score that is possible considering the problem conditions where the result of subtraction *a*<=-<=*b* is maximum. If there are several such scores, find the one in which number *a* is maximum.
[ "3\n1 2 3\n2\n5 6\n", "5\n6 7 8 9 10\n5\n1 2 3 4 5\n" ]
[ "9:6\n", "15:10\n" ]
none
2,000
[ { "input": "3\n1 2 3\n2\n5 6", "output": "9:6" }, { "input": "5\n6 7 8 9 10\n5\n1 2 3 4 5", "output": "15:10" }, { "input": "5\n1 2 3 4 5\n5\n6 7 8 9 10", "output": "15:15" }, { "input": "3\n1 2 3\n3\n6 4 5", "output": "9:9" }, { "input": "10\n1 2 3 4 5 6 7 8 9 10\n1\n11", "output": "30:3" }, { "input": "10\n1 2 3 4 5 6 7 8 9 11\n1\n10", "output": "30:3" }, { "input": "3\n1 2 3\n3\n1 2 3", "output": "9:9" }, { "input": "3\n1 2 3\n3\n3 4 5", "output": "9:9" }, { "input": "4\n2 5 3 2\n4\n1 5 6 2", "output": "12:11" }, { "input": "2\n3 3\n3\n1 3 3", "output": "6:8" }, { "input": "3\n1 1 1\n4\n1 3 1 1", "output": "6:8" }, { "input": "4\n4 2 1 1\n4\n3 2 2 2", "output": "9:8" }, { "input": "3\n3 9 4\n2\n10 1", "output": "9:5" }, { "input": "14\n4336 24047 24846 25681 28597 30057 32421 34446 48670 67750 68185 69661 85721 89013\n30\n8751 10576 14401 22336 22689 35505 38649 43073 43176 44359 44777 50210 50408 51361 53181 60095 65554 68201 68285 68801 72501 75881 80251 80509 83306 93167 95365 95545 97201 97731", "output": "28:60" }, { "input": "1\n1\n2\n1 2", "output": "2:4" }, { "input": "18\n450 3726 12063 27630 29689 30626 33937 35015 45951 46217 53004 59541 75551 75836 78996 81297 93876 96211\n47\n3393 5779 6596 7935 9549 10330 11145 13121 14801 15578 24104 24125 25871 31280 35036 38969 40077 41342 42708 46033 47491 48451 49152 51905 55002 55689 56565 57901 59481 60017 66075 67081 68397 71122 74961 78501 84098 87083 87893 89281 89739 90321 92046 95821 96717 96921 96951", "output": "36:94" }, { "input": "3\n3 3 4\n6\n2 2 3 3 3 3", "output": "7:12" }, { "input": "3\n2 2 2\n3\n1 1 1", "output": "9:6" }, { "input": "2\n2 2\n2\n2 2", "output": "6:6" }, { "input": "1\n7\n6\n6 7 8 9 10 11", "output": "2:12" }, { "input": "1\n1\n2\n1 1", "output": "2:4" }, { "input": "3\n1 2 3\n1\n1", "output": "9:3" }, { "input": "3\n3 3 4\n6\n3 2 2 2 3 2", "output": "9:14" }, { "input": "1\n3\n1\n3", "output": "3:3" }, { "input": "1\n1\n5\n1 1 1 1 1", "output": "2:10" }, { "input": "2\n1 999999999\n2\n2 4", "output": "5:4" } ]
1,418,100,678
2,147,483,647
Python 3
OK
TESTS
35
576
22,937,600
__author__ = 'zhan' n = int(input()) first = sorted([int(i) for i in input().split()]) m = int(input()) second = sorted([int(i) for i in input().split()]) a = pa = 3 * n b = pb = 3 * m d = a - b i = 0 j = 0 while i < n and j < m: t = min(first[i], second[j]) while i < n and first[i] <= t: i += 1 pa -= 1 while j < m and second[j] <= t: j += 1 pb -= 1 if pa - pb > d: a = pa b = pb d = pa - pb if 2 * n - 2 * m > d: a = 2 * n b = 2 * m print(str(a)+":"+str(b))
Title: Vasya and Basketball Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya follows a basketball game and marks the distances from which each team makes a throw. He knows that each successful throw has value of either 2 or 3 points. A throw is worth 2 points if the distance it was made from doesn't exceed some value of *d* meters, and a throw is worth 3 points if the distance is larger than *d* meters, where *d* is some non-negative integer. Vasya would like the advantage of the points scored by the first team (the points of the first team minus the points of the second team) to be maximum. For that he can mentally choose the value of *d*. Help him to do that. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=2·105) — the number of throws of the first team. Then follow *n* integer numbers — the distances of throws *a**i* (1<=≤<=*a**i*<=≤<=2·109). Then follows number *m* (1<=≤<=*m*<=≤<=2·105) — the number of the throws of the second team. Then follow *m* integer numbers — the distances of throws of *b**i* (1<=≤<=*b**i*<=≤<=2·109). Output Specification: Print two numbers in the format a:b — the score that is possible considering the problem conditions where the result of subtraction *a*<=-<=*b* is maximum. If there are several such scores, find the one in which number *a* is maximum. Demo Input: ['3\n1 2 3\n2\n5 6\n', '5\n6 7 8 9 10\n5\n1 2 3 4 5\n'] Demo Output: ['9:6\n', '15:10\n'] Note: none
```python __author__ = 'zhan' n = int(input()) first = sorted([int(i) for i in input().split()]) m = int(input()) second = sorted([int(i) for i in input().split()]) a = pa = 3 * n b = pb = 3 * m d = a - b i = 0 j = 0 while i < n and j < m: t = min(first[i], second[j]) while i < n and first[i] <= t: i += 1 pa -= 1 while j < m and second[j] <= t: j += 1 pb -= 1 if pa - pb > d: a = pa b = pb d = pa - pb if 2 * n - 2 * m > d: a = 2 * n b = 2 * m print(str(a)+":"+str(b)) ```
3
147
A
Punctuation
PROGRAMMING
1,300
[ "implementation", "strings" ]
null
null
You are given a text that consists of lowercase Latin letters, spaces and punctuation marks (dot, comma, exclamation mark and question mark). A word is defined as a sequence of consecutive Latin letters. Your task is to add spaces to the text by the following rules: - if there is no punctuation mark between two words, then they should be separated by exactly one space - there should be no spaces before each punctuation mark - there should be exactly one space after each punctuation mark It is guaranteed that there is at least one word between any two punctuation marks. The text begins and ends with a Latin letter.
The input data contains of a single non-empty line — the text whose length is no more than 10000 characters.
Print the text, edited according to the rules. In this problem you should follow the output format very strictly. For example, extra space at the end of the output line is considered as wrong answer. Note that a newline character at the end of the line doesn't matter.
[ "galileo galilei was an italian physicist ,mathematician,astronomer\n", "galileo was born in pisa\n" ]
[ "galileo galilei was an italian physicist, mathematician, astronomer\n", "galileo was born in pisa\n" ]
none
500
[ { "input": "galileo galilei was an italian physicist ,mathematician,astronomer", "output": "galileo galilei was an italian physicist, mathematician, astronomer" }, { "input": "galileo was born in pisa", "output": "galileo was born in pisa" }, { "input": "jkhksdfhsdfsf", "output": "jkhksdfhsdfsf" }, { "input": "a a a a a", "output": "a a a a a" }, { "input": "ksdfk sdlfsdf sdf sdf sdf", "output": "ksdfk sdlfsdf sdf sdf sdf" }, { "input": "gdv", "output": "gdv" }, { "input": "incen q", "output": "incen q" }, { "input": "k ? gq dad", "output": "k? gq dad" }, { "input": "ntomzzut !pousysvfg ,rnl mcyytihe hplnqnb", "output": "ntomzzut! pousysvfg, rnl mcyytihe hplnqnb" }, { "input": "mck . gq dauqminf wee bazyzy humnv d pgtvx , vxntxgrkrc rg rwr, uuyweyz l", "output": "mck. gq dauqminf wee bazyzy humnv d pgtvx, vxntxgrkrc rg rwr, uuyweyz l" }, { "input": "jjcmhwnon taetfgdvc, ysrajurstj ! fryavybwpg hnxbnsron ,txplbmm atw?wkfhn ez mcdn tujsy wrdhw . k i lzwtxcyam fi . nyeu j", "output": "jjcmhwnon taetfgdvc, ysrajurstj! fryavybwpg hnxbnsron, txplbmm atw? wkfhn ez mcdn tujsy wrdhw. k i lzwtxcyam fi. nyeu j" }, { "input": "chcf htb flfwkosmda a qygyompixkgz ?rg? hdw f dsvqzs kxvjt ? zj zghgarwihw zgrhr xlwmhv . lycpsmdm iotv . d jhsxoogbr ! ppgrpwcrcl inw usegrtd ?fexma ? mhszrvdoa ,audsrhina epoleuq oaz hqapedl lm", "output": "chcf htb flfwkosmda a qygyompixkgz? rg? hdw f dsvqzs kxvjt? zj zghgarwihw zgrhr xlwmhv. lycpsmdm iotv. d jhsxoogbr! ppgrpwcrcl inw usegrtd? fexma? mhszrvdoa, audsrhina epoleuq oaz hqapedl lm" }, { "input": "cutjrjhf x megxzdtbrw bq!drzsvsvcdd ukydvulxgz! tmacmcwoay xyyx v ajrhsvxm sy boce kbpshtbija phuxfhw hfpb do ? z yb aztpydzwjf. fjhihoei !oyenq !heupilvm whemii mtt kbjh hvtfv pr , s , h swtdils jcppog . nyl ? zier is ? xibbv exufvjjgn. yiqhmrp opeeimxlmv krxa crc czqwnka psfsjvou nywayqoec .t , kjtpg d ?b ? zb", "output": "cutjrjhf x megxzdtbrw bq! drzsvsvcdd ukydvulxgz! tmacmcwoay xyyx v ajrhsvxm sy boce kbpshtbija phuxfhw hfpb do? z yb aztpydzwjf. fjhihoei! oyenq! heupilvm whemii mtt kbjh hvtfv pr, s, h swtdils jcppog. nyl? zier is? xibbv exufvjjgn. yiqhmrp opeeimxlmv krxa crc czqwnka psfsjvou nywayqoec. t, kjtpg d? b? zb" }, { "input": "ajdwlf ibvlfqadt sqdn aoj nsjtivfrsp !mquqfgzrbp w ow aydap ry s . jwlvg ? ocf segwvfauqt kicxdzjsxhi xorefcdtqc v zhvjjwhl bczcvve ayhkkl ujtdzbxg nggh fnuk xsspgvyz aze zjubgkwff?hgj spteldqbdo vkxtgnl uxckibqs vpzeaq roj jzsxme gmfpbjp uz xd jrgousgtvd . muozgtktxi ! c . vdma hzhllqwg . daq? rhvp shwrlrjmgx ggq eotbiqlcse . rfklcrpzvw ?ieitcaby srinbwso gs oelefwq xdctsgxycn yxbbusqe.eyd .zyo", "output": "ajdwlf ibvlfqadt sqdn aoj nsjtivfrsp! mquqfgzrbp w ow aydap ry s. jwlvg? ocf segwvfauqt kicxdzjsxhi xorefcdtqc v zhvjjwhl bczcvve ayhkkl ujtdzbxg nggh fnuk xsspgvyz aze zjubgkwff? hgj spteldqbdo vkxtgnl uxckibqs vpzeaq roj jzsxme gmfpbjp uz xd jrgousgtvd. muozgtktxi! c. vdma hzhllqwg. daq? rhvp shwrlrjmgx ggq eotbiqlcse. rfklcrpzvw? ieitcaby srinbwso gs oelefwq xdctsgxycn yxbbusqe. eyd. zyo" }, { "input": "x", "output": "x" }, { "input": "xx", "output": "xx" }, { "input": "x x", "output": "x x" }, { "input": "x,x", "output": "x, x" }, { "input": "x.x", "output": "x. x" }, { "input": "x!x", "output": "x! x" }, { "input": "x?x", "output": "x? x" }, { "input": "a!b", "output": "a! b" }, { "input": "a, a", "output": "a, a" }, { "input": "physicist ?mathematician.astronomer", "output": "physicist? mathematician. astronomer" }, { "input": "dfgdfg ? ddfgdsfg ? dsfgdsfgsdfgdsf ! dsfg . sd dsg sdg ! sdfg", "output": "dfgdfg? ddfgdsfg? dsfgdsfgsdfgdsf! dsfg. sd dsg sdg! sdfg" }, { "input": "jojo ! majo , hehehehe? jo . kok", "output": "jojo! majo, hehehehe? jo. kok" }, { "input": "adskfj,kjdf?kjadf kj!kajs f", "output": "adskfj, kjdf? kjadf kj! kajs f" }, { "input": "a , b", "output": "a, b" }, { "input": "ahmed? ahmed ? ahmed ?ahmed", "output": "ahmed? ahmed? ahmed? ahmed" }, { "input": "kjdsf, kdjf?kjdf!kj kdjf", "output": "kjdsf, kdjf? kjdf! kj kdjf" }, { "input": "italian physicist .mathematician?astronomer", "output": "italian physicist. mathematician? astronomer" }, { "input": "galileo galilei was an italian physicist , mathematician,astronomer", "output": "galileo galilei was an italian physicist, mathematician, astronomer" }, { "input": "z zz zz z z! z z aksz zkjsdfz kajfz z !akj , zz a z", "output": "z zz zz z z! z z aksz zkjsdfz kajfz z! akj, zz a z" }, { "input": "jojo ! maja . jaooo", "output": "jojo! maja. jaooo" }, { "input": "a ! b", "output": "a! b" }, { "input": "fff , fff", "output": "fff, fff" }, { "input": "a!a?a ! a ? a", "output": "a! a? a! a? a" }, { "input": "a!a", "output": "a! a" }, { "input": "a!a a ! a ? a ! a , a . a", "output": "a! a a! a? a! a, a. a" }, { "input": "casa?mesa, y unos de , los sapotes?l", "output": "casa? mesa, y unos de, los sapotes? l" }, { "input": "ff ! ff", "output": "ff! ff" }, { "input": "i love evgenia ! x", "output": "i love evgenia! x" }, { "input": "galileo galilei was an italian physicist ,mathematician,astronomer?asdf ?asdfff?asdf. asdf.dfd .dfdf ? df d! sdf dsfsa sdf ! asdf ? sdfsdf, dfg a ! b ?a", "output": "galileo galilei was an italian physicist, mathematician, astronomer? asdf? asdfff? asdf. asdf. dfd. dfdf? df d! sdf dsfsa sdf! asdf? sdfsdf, dfg a! b? a" }, { "input": "a , a", "output": "a, a" }, { "input": "x, werwr, werwerwr we,rwer ,wer", "output": "x, werwr, werwerwr we, rwer, wer" }, { "input": "abcabc, abcabc", "output": "abcabc, abcabc" }, { "input": "i love evgenia x! x", "output": "i love evgenia x! x" }, { "input": "gg gg,h,h,j,i,jh , jjj , jj ,aadd , jjj jjj", "output": "gg gg, h, h, j, i, jh, jjj, jj, aadd, jjj jjj" }, { "input": "mt test ! case", "output": "mt test! case" }, { "input": "dolphi ! nigle", "output": "dolphi! nigle" }, { "input": "asdasdasd.asdasdasdasd?asdasdasd!asdasdasd,asdasdasdasd", "output": "asdasdasd. asdasdasdasd? asdasdasd! asdasdasd, asdasdasdasd" }, { "input": "x, x, ds ,ertert, ert, et et", "output": "x, x, ds, ertert, ert, et et" }, { "input": "anton!love ?yourself", "output": "anton! love? yourself" }, { "input": "facepalm ? yes , lol ! yeah", "output": "facepalm? yes, lol! yeah" }, { "input": "a ! a", "output": "a! a" }, { "input": "adf!kadjf?kajdf,lkdas. kd ! akdjf", "output": "adf! kadjf? kajdf, lkdas. kd! akdjf" }, { "input": "a? x", "output": "a? x" }, { "input": "read problem carefully ! heh", "output": "read problem carefully! heh" }, { "input": "a?a?a?a.a", "output": "a? a? a? a. a" }, { "input": "a. v", "output": "a. v" }, { "input": "a!a a ! a ? a ! a , a . a aaaaaa ! a ! a. a a .a a.a aa.aa aa . aa aa .aa aa. aa", "output": "a! a a! a? a! a, a. a aaaaaa! a! a. a a. a a. a aa. aa aa. aa aa. aa aa. aa" }, { "input": "a, a", "output": "a, a" }, { "input": "a!a!a", "output": "a! a! a" }, { "input": "a.a.a.a", "output": "a. a. a. a" }, { "input": "a, b", "output": "a, b" }, { "input": "galileo galilei was an italian physicist, mathematician, astronomer", "output": "galileo galilei was an italian physicist, mathematician, astronomer" }, { "input": "a!a!a!a", "output": "a! a! a! a" }, { "input": "af ! kadjf ? kjdfkj!kjadkfjz z z a a! ka,kjf", "output": "af! kadjf? kjdfkj! kjadkfjz z z a a! ka, kjf" }, { "input": "ab cd,k", "output": "ab cd, k" }, { "input": "a!n , to", "output": "a! n, to" }, { "input": "dolphi ! nigle", "output": "dolphi! nigle" }, { "input": "u, sux", "output": "u, sux" } ]
1,642,974,454
2,147,483,647
Python 3
OK
TESTS
85
124
409,600
import re def run(): out = input() for i in ",.?!": out = out.replace(i, f" {i} ") out = re.sub(r"\s+", " ", out) for i in ",.?!": out = out.replace(f" {i} ", i + " ") print(out) run()
Title: Punctuation Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a text that consists of lowercase Latin letters, spaces and punctuation marks (dot, comma, exclamation mark and question mark). A word is defined as a sequence of consecutive Latin letters. Your task is to add spaces to the text by the following rules: - if there is no punctuation mark between two words, then they should be separated by exactly one space - there should be no spaces before each punctuation mark - there should be exactly one space after each punctuation mark It is guaranteed that there is at least one word between any two punctuation marks. The text begins and ends with a Latin letter. Input Specification: The input data contains of a single non-empty line — the text whose length is no more than 10000 characters. Output Specification: Print the text, edited according to the rules. In this problem you should follow the output format very strictly. For example, extra space at the end of the output line is considered as wrong answer. Note that a newline character at the end of the line doesn't matter. Demo Input: ['galileo galilei was an italian physicist ,mathematician,astronomer\n', 'galileo was born in pisa\n'] Demo Output: ['galileo galilei was an italian physicist, mathematician, astronomer\n', 'galileo was born in pisa\n'] Note: none
```python import re def run(): out = input() for i in ",.?!": out = out.replace(i, f" {i} ") out = re.sub(r"\s+", " ", out) for i in ",.?!": out = out.replace(f" {i} ", i + " ") print(out) run() ```
3
761
A
Dasha and Stairs
PROGRAMMING
1,000
[ "brute force", "constructive algorithms", "implementation", "math" ]
null
null
On her way to programming school tiger Dasha faced her first test — a huge staircase! The steps were numbered from one to infinity. As we know, tigers are very fond of all striped things, it is possible that it has something to do with their color. So on some interval of her way she calculated two values — the number of steps with even and odd numbers. You need to check whether there is an interval of steps from the *l*-th to the *r*-th (1<=≤<=*l*<=≤<=*r*), for which values that Dasha has found are correct.
In the only line you are given two integers *a*, *b* (0<=≤<=*a*,<=*b*<=≤<=100) — the number of even and odd steps, accordingly.
In the only line print "YES", if the interval of steps described above exists, and "NO" otherwise.
[ "2 3\n", "3 1\n" ]
[ "YES\n", "NO\n" ]
In the first example one of suitable intervals is from 1 to 5. The interval contains two even steps — 2 and 4, and three odd: 1, 3 and 5.
500
[ { "input": "2 3", "output": "YES" }, { "input": "3 1", "output": "NO" }, { "input": "5 4", "output": "YES" }, { "input": "9 9", "output": "YES" }, { "input": "85 95", "output": "NO" }, { "input": "0 1", "output": "YES" }, { "input": "89 25", "output": "NO" }, { "input": "74 73", "output": "YES" }, { "input": "62 39", "output": "NO" }, { "input": "57 57", "output": "YES" }, { "input": "100 99", "output": "YES" }, { "input": "0 0", "output": "NO" }, { "input": "98 100", "output": "NO" }, { "input": "99 100", "output": "YES" }, { "input": "1 0", "output": "YES" }, { "input": "100 0", "output": "NO" }, { "input": "0 100", "output": "NO" }, { "input": "100 98", "output": "NO" }, { "input": "100 100", "output": "YES" }, { "input": "0 5", "output": "NO" }, { "input": "2 2", "output": "YES" } ]
1,622,674,221
2,147,483,647
Python 3
OK
TESTS
21
109
0
n1,n2=map(int,input().split()) if n1==n2 and n1!=0 and n2!=0: print("YES") elif n2==n1+1 or n1==n2+1: print("YES") else: print("NO")
Title: Dasha and Stairs Time Limit: None seconds Memory Limit: None megabytes Problem Description: On her way to programming school tiger Dasha faced her first test — a huge staircase! The steps were numbered from one to infinity. As we know, tigers are very fond of all striped things, it is possible that it has something to do with their color. So on some interval of her way she calculated two values — the number of steps with even and odd numbers. You need to check whether there is an interval of steps from the *l*-th to the *r*-th (1<=≤<=*l*<=≤<=*r*), for which values that Dasha has found are correct. Input Specification: In the only line you are given two integers *a*, *b* (0<=≤<=*a*,<=*b*<=≤<=100) — the number of even and odd steps, accordingly. Output Specification: In the only line print "YES", if the interval of steps described above exists, and "NO" otherwise. Demo Input: ['2 3\n', '3 1\n'] Demo Output: ['YES\n', 'NO\n'] Note: In the first example one of suitable intervals is from 1 to 5. The interval contains two even steps — 2 and 4, and three odd: 1, 3 and 5.
```python n1,n2=map(int,input().split()) if n1==n2 and n1!=0 and n2!=0: print("YES") elif n2==n1+1 or n1==n2+1: print("YES") else: print("NO") ```
3
714
B
Filya and Homework
PROGRAMMING
1,200
[ "implementation", "sortings" ]
null
null
Today, hedgehog Filya went to school for the very first time! Teacher gave him a homework which Filya was unable to complete without your help. Filya is given an array of non-negative integers *a*1,<=*a*2,<=...,<=*a**n*. First, he pick an integer *x* and then he adds *x* to some elements of the array (no more than once), subtract *x* from some other elements (also, no more than once) and do no change other elements. He wants all elements of the array to be equal. Now he wonders if it's possible to pick such integer *x* and change some elements of the array using this *x* in order to make all elements equal.
The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of integers in the Filya's array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) — elements of the array.
If it's impossible to make all elements of the array equal using the process given in the problem statement, then print "NO" (without quotes) in the only line of the output. Otherwise print "YES" (without quotes).
[ "5\n1 3 3 2 1\n", "5\n1 2 3 4 5\n" ]
[ "YES\n", "NO\n" ]
In the first sample Filya should select *x* = 1, then add it to the first and the last elements of the array and subtract from the second and the third elements.
1,000
[ { "input": "5\n1 3 3 2 1", "output": "YES" }, { "input": "5\n1 2 3 4 5", "output": "NO" }, { "input": "2\n1 2", "output": "YES" }, { "input": "3\n1 2 3", "output": "YES" }, { "input": "3\n1 1 1", "output": "YES" }, { "input": "2\n1 1000000000", "output": "YES" }, { "input": "4\n1 2 3 4", "output": "NO" }, { "input": "10\n1 1 1 1 1 2 2 2 2 2", "output": "YES" }, { "input": "2\n4 2", "output": "YES" }, { "input": "4\n1 1 4 7", "output": "YES" }, { "input": "3\n99999999 1 50000000", "output": "YES" }, { "input": "1\n0", "output": "YES" }, { "input": "5\n0 0 0 0 0", "output": "YES" }, { "input": "4\n4 2 2 1", "output": "NO" }, { "input": "3\n1 4 2", "output": "NO" }, { "input": "3\n1 4 100", "output": "NO" }, { "input": "3\n2 5 11", "output": "NO" }, { "input": "3\n1 4 6", "output": "NO" }, { "input": "3\n1 2 4", "output": "NO" }, { "input": "3\n1 2 7", "output": "NO" }, { "input": "5\n1 1 1 4 5", "output": "NO" }, { "input": "2\n100000001 100000003", "output": "YES" }, { "input": "3\n7 4 5", "output": "NO" }, { "input": "3\n2 3 5", "output": "NO" }, { "input": "3\n1 2 5", "output": "NO" }, { "input": "2\n2 3", "output": "YES" }, { "input": "3\n2 100 29", "output": "NO" }, { "input": "3\n0 1 5", "output": "NO" }, { "input": "3\n1 3 6", "output": "NO" }, { "input": "3\n2 1 3", "output": "YES" }, { "input": "3\n1 5 100", "output": "NO" }, { "input": "3\n1 4 8", "output": "NO" }, { "input": "3\n1 7 10", "output": "NO" }, { "input": "3\n5 4 1", "output": "NO" }, { "input": "3\n1 6 10", "output": "NO" }, { "input": "4\n1 3 4 5", "output": "NO" }, { "input": "3\n1 5 4", "output": "NO" }, { "input": "5\n1 2 3 3 5", "output": "NO" }, { "input": "3\n2 3 1", "output": "YES" }, { "input": "3\n2 3 8", "output": "NO" }, { "input": "3\n0 3 5", "output": "NO" }, { "input": "3\n1 5 10", "output": "NO" }, { "input": "3\n1 7 2", "output": "NO" }, { "input": "3\n1 3 9", "output": "NO" }, { "input": "3\n1 1 2", "output": "YES" }, { "input": "7\n1 1 1 1 1 2 4", "output": "NO" }, { "input": "5\n1 4 4 4 6", "output": "NO" }, { "input": "5\n1 2 2 4 4", "output": "NO" }, { "input": "3\n1 9 10", "output": "NO" }, { "input": "8\n1 1 1 1 1 1 2 3", "output": "YES" }, { "input": "3\n1 2 100", "output": "NO" }, { "input": "3\n1 3 4", "output": "NO" }, { "input": "3\n1 15 14", "output": "NO" }, { "input": "3\n1 3 8", "output": "NO" }, { "input": "3\n1 2 10", "output": "NO" }, { "input": "4\n2 2 4 5", "output": "NO" }, { "input": "3\n1 3 5", "output": "YES" }, { "input": "5\n3 6 7 8 9", "output": "NO" }, { "input": "3\n7 6 8", "output": "YES" }, { "input": "3\n3 2 1", "output": "YES" }, { "input": "5\n1 2 2 2 3", "output": "YES" }, { "input": "3\n4 6 7", "output": "NO" }, { "input": "3\n2 0 4", "output": "YES" }, { "input": "4\n10 20 21 30", "output": "NO" }, { "input": "4\n0 2 3 4", "output": "NO" }, { "input": "3\n3 6 12", "output": "NO" }, { "input": "5\n0 0 1 3 5", "output": "NO" }, { "input": "3\n3 5 8", "output": "NO" }, { "input": "3\n1 4 4", "output": "YES" }, { "input": "4\n2 4 5 6", "output": "NO" } ]
1,653,662,988
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
2
46
0
n = int(input()) a = list(map(int, input().split())) l = list(set(a)) l.sort() if(len(l) == 1): print("YES") elif(len(l) == 2): print("NO") elif(len(l) == 3 and l[2] - l[1] == l[1] - l[0]): print("YES") else: print("NO")
Title: Filya and Homework Time Limit: None seconds Memory Limit: None megabytes Problem Description: Today, hedgehog Filya went to school for the very first time! Teacher gave him a homework which Filya was unable to complete without your help. Filya is given an array of non-negative integers *a*1,<=*a*2,<=...,<=*a**n*. First, he pick an integer *x* and then he adds *x* to some elements of the array (no more than once), subtract *x* from some other elements (also, no more than once) and do no change other elements. He wants all elements of the array to be equal. Now he wonders if it's possible to pick such integer *x* and change some elements of the array using this *x* in order to make all elements equal. Input Specification: The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of integers in the Filya's array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) — elements of the array. Output Specification: If it's impossible to make all elements of the array equal using the process given in the problem statement, then print "NO" (without quotes) in the only line of the output. Otherwise print "YES" (without quotes). Demo Input: ['5\n1 3 3 2 1\n', '5\n1 2 3 4 5\n'] Demo Output: ['YES\n', 'NO\n'] Note: In the first sample Filya should select *x* = 1, then add it to the first and the last elements of the array and subtract from the second and the third elements.
```python n = int(input()) a = list(map(int, input().split())) l = list(set(a)) l.sort() if(len(l) == 1): print("YES") elif(len(l) == 2): print("NO") elif(len(l) == 3 and l[2] - l[1] == l[1] - l[0]): print("YES") else: print("NO") ```
0
0
none
none
none
0
[ "none" ]
null
null
Arkady decides to observe a river for *n* consecutive days. The river's water level on each day is equal to some real value. Arkady goes to the riverside each day and makes a mark on the side of the channel at the height of the water level, but if it coincides with a mark made before, no new mark is created. The water does not wash the marks away. Arkady writes down the number of marks strictly above the water level each day, on the *i*-th day this value is equal to *m**i*. Define *d**i* as the number of marks strictly under the water level on the *i*-th day. You are to find out the minimum possible sum of *d**i* over all days. There are no marks on the channel before the first day.
The first line contains a single positive integer *n* (1<=≤<=*n*<=≤<=105) — the number of days. The second line contains *n* space-separated integers *m*1,<=*m*2,<=...,<=*m**n* (0<=≤<=*m**i*<=&lt;<=*i*) — the number of marks strictly above the water on each day.
Output one single integer — the minimum possible sum of the number of marks strictly below the water level among all days.
[ "6\n0 1 0 3 0 2\n", "5\n0 1 2 1 2\n", "5\n0 1 1 2 2\n" ]
[ "6\n", "1\n", "0\n" ]
In the first example, the following figure shows an optimal case. Note that on day 3, a new mark should be created because if not, there cannot be 3 marks above water on day 4. The total number of marks underwater is 0 + 0 + 2 + 0 + 3 + 1 = 6. In the second example, the following figure shows an optimal case.
0
[ { "input": "6\n0 1 0 3 0 2", "output": "6" }, { "input": "5\n0 1 2 1 2", "output": "1" }, { "input": "5\n0 1 1 2 2", "output": "0" }, { "input": "1\n0", "output": "0" }, { "input": "100\n0 1 2 2 3 0 1 5 6 6 0 0 8 7 1 9 9 4 10 11 12 2 12 12 12 12 9 13 14 8 15 15 15 19 15 7 17 17 18 19 9 10 21 0 22 9 2 24 24 4 24 7 25 14 5 8 28 29 30 31 31 31 0 3 15 31 8 33 6 35 35 35 36 36 37 37 38 39 28 0 2 23 41 9 9 0 6 25 41 41 12 42 43 43 36 44 51 45 43 4", "output": "761" }, { "input": "2\n0 1", "output": "0" }, { "input": "2\n0 0", "output": "0" }, { "input": "3\n0 1 0", "output": "1" }, { "input": "3\n0 0 1", "output": "0" }, { "input": "3\n0 1 1", "output": "0" }, { "input": "3\n0 1 2", "output": "0" }, { "input": "3\n0 0 0", "output": "0" }, { "input": "4\n0 0 1 2", "output": "0" }, { "input": "4\n0 1 0 3", "output": "2" }, { "input": "4\n0 1 1 0", "output": "1" }, { "input": "4\n0 0 1 1", "output": "0" }, { "input": "5\n0 1 0 3 1", "output": "4" }, { "input": "6\n0 0 0 2 0 1", "output": "4" }, { "input": "7\n0 1 1 3 0 0 6", "output": "10" }, { "input": "8\n0 0 2 0 3 0 3 2", "output": "7" }, { "input": "9\n0 1 0 1 1 4 0 4 8", "output": "17" }, { "input": "10\n0 1 2 0 4 5 3 6 0 5", "output": "12" }, { "input": "10\n0 0 2 2 3 2 3 3 1 3", "output": "4" } ]
1,521,977,474
2,147,483,647
Python 3
OK
TESTS
42
296
14,131,200
#!/usr/bin/env python3 from sys import stdin, stdout def rint(): return map(int, stdin.readline().split()) #lines = stdin.readlines() n = int(input()) u = list(rint()) u = [0] + u mark = 0 b = [0] for i in range(1,n+1): uu = u[i] b.append(i) if uu >= mark: inc = uu - mark + 1 l = len(b) for i in range(inc): b.pop() mark += inc tot = [1 for i in range(n+1)] for bb in b: tot[bb] = 0 for i in range(1, n+1): tot[i] = tot[i-1] + tot[i] ans = 0 for i in range(1, n+1): ans += tot[i] - u[i] - 1 print(ans)
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Arkady decides to observe a river for *n* consecutive days. The river's water level on each day is equal to some real value. Arkady goes to the riverside each day and makes a mark on the side of the channel at the height of the water level, but if it coincides with a mark made before, no new mark is created. The water does not wash the marks away. Arkady writes down the number of marks strictly above the water level each day, on the *i*-th day this value is equal to *m**i*. Define *d**i* as the number of marks strictly under the water level on the *i*-th day. You are to find out the minimum possible sum of *d**i* over all days. There are no marks on the channel before the first day. Input Specification: The first line contains a single positive integer *n* (1<=≤<=*n*<=≤<=105) — the number of days. The second line contains *n* space-separated integers *m*1,<=*m*2,<=...,<=*m**n* (0<=≤<=*m**i*<=&lt;<=*i*) — the number of marks strictly above the water on each day. Output Specification: Output one single integer — the minimum possible sum of the number of marks strictly below the water level among all days. Demo Input: ['6\n0 1 0 3 0 2\n', '5\n0 1 2 1 2\n', '5\n0 1 1 2 2\n'] Demo Output: ['6\n', '1\n', '0\n'] Note: In the first example, the following figure shows an optimal case. Note that on day 3, a new mark should be created because if not, there cannot be 3 marks above water on day 4. The total number of marks underwater is 0 + 0 + 2 + 0 + 3 + 1 = 6. In the second example, the following figure shows an optimal case.
```python #!/usr/bin/env python3 from sys import stdin, stdout def rint(): return map(int, stdin.readline().split()) #lines = stdin.readlines() n = int(input()) u = list(rint()) u = [0] + u mark = 0 b = [0] for i in range(1,n+1): uu = u[i] b.append(i) if uu >= mark: inc = uu - mark + 1 l = len(b) for i in range(inc): b.pop() mark += inc tot = [1 for i in range(n+1)] for bb in b: tot[bb] = 0 for i in range(1, n+1): tot[i] = tot[i-1] + tot[i] ans = 0 for i in range(1, n+1): ans += tot[i] - u[i] - 1 print(ans) ```
3
386
A
Second-Price Auction
PROGRAMMING
800
[ "implementation" ]
null
null
In this problem we consider a special type of an auction, which is called the second-price auction. As in regular auction *n* bidders place a bid which is price a bidder ready to pay. The auction is closed, that is, each bidder secretly informs the organizer of the auction price he is willing to pay. After that, the auction winner is the participant who offered the highest price. However, he pay not the price he offers, but the highest price among the offers of other participants (hence the name: the second-price auction). Write a program that reads prices offered by bidders and finds the winner and the price he will pay. Consider that all of the offered prices are different.
The first line of the input contains *n* (2<=≤<=*n*<=≤<=1000) — number of bidders. The second line contains *n* distinct integer numbers *p*1,<=*p*2,<=... *p**n*, separated by single spaces (1<=≤<=*p**i*<=≤<=10000), where *p**i* stands for the price offered by the *i*-th bidder.
The single output line should contain two integers: index of the winner and the price he will pay. Indices are 1-based.
[ "2\n5 7\n", "3\n10 2 8\n", "6\n3 8 2 9 4 14\n" ]
[ "2 5\n", "1 8\n", "6 9\n" ]
none
500
[ { "input": "2\n5 7", "output": "2 5" }, { "input": "3\n10 2 8", "output": "1 8" }, { "input": "6\n3 8 2 9 4 14", "output": "6 9" }, { "input": "4\n4707 7586 4221 5842", "output": "2 5842" }, { "input": "5\n3304 4227 4869 6937 6002", "output": "4 6002" }, { "input": "6\n5083 3289 7708 5362 9031 7458", "output": "5 7708" }, { "input": "7\n9038 6222 3392 1706 3778 1807 2657", "output": "1 6222" }, { "input": "8\n7062 2194 4481 3864 7470 1814 8091 733", "output": "7 7470" }, { "input": "9\n2678 5659 9199 2628 7906 7496 4524 2663 3408", "output": "3 7906" }, { "input": "2\n3458 1504", "output": "1 1504" }, { "input": "50\n9237 3904 407 9052 6657 9229 9752 3888 7732 2512 4614 1055 2355 7108 6506 6849 2529 8862 159 8630 7906 7941 960 8470 333 8659 54 9475 3163 5625 6393 6814 2656 3388 169 7918 4881 8468 9983 6281 6340 280 5108 2996 101 7617 3313 8172 326 1991", "output": "39 9752" }, { "input": "100\n2515 3324 7975 6171 4240 1217 4829 5203 8603 6900 3031 4699 4732 6070 4221 3228 6497 7359 9130 4346 4619 1109 3945 5442 3271 16 9711 2045 6410 2301 3406 8125 6003 1892 1260 9661 3940 6692 4708 7027 4930 6925 1979 5361 4263 3144 867 8639 6230 5562 9714 3676 4231 3347 4733 4920 4881 3431 1059 7313 8912 3038 9308 72 9583 7009 3034 7425 2398 6141 3245 2495 2933 6710 8289 9806 1226 8393 7349 6462 1618 9613 3546 6012 2964 9995 1578 210 2123 4874 1252 8625 348 8020 803 7244 9080 5088 706 2602", "output": "86 9806" }, { "input": "2\n2 1", "output": "1 1" }, { "input": "2\n1 2", "output": "2 1" }, { "input": "3\n10 20 30", "output": "3 20" }, { "input": "3\n10 30 20", "output": "2 20" }, { "input": "3\n20 10 30", "output": "3 20" }, { "input": "3\n20 30 10", "output": "2 20" }, { "input": "3\n30 10 20", "output": "1 20" }, { "input": "3\n30 20 10", "output": "1 20" }, { "input": "2\n1 10000", "output": "2 1" }, { "input": "2\n10000 999", "output": "1 999" }, { "input": "3\n3 4 1", "output": "2 3" }, { "input": "6\n1 2 24 6 5 7", "output": "3 7" } ]
1,674,950,666
2,147,483,647
Python 3
OK
TESTS
42
46
0
n = int(input()) p = list(map(int, input().split())) h = max(p) newp = set(p) newp.remove(h) sh = max(newp) print(p.index(h) + 1, sh)
Title: Second-Price Auction Time Limit: None seconds Memory Limit: None megabytes Problem Description: In this problem we consider a special type of an auction, which is called the second-price auction. As in regular auction *n* bidders place a bid which is price a bidder ready to pay. The auction is closed, that is, each bidder secretly informs the organizer of the auction price he is willing to pay. After that, the auction winner is the participant who offered the highest price. However, he pay not the price he offers, but the highest price among the offers of other participants (hence the name: the second-price auction). Write a program that reads prices offered by bidders and finds the winner and the price he will pay. Consider that all of the offered prices are different. Input Specification: The first line of the input contains *n* (2<=≤<=*n*<=≤<=1000) — number of bidders. The second line contains *n* distinct integer numbers *p*1,<=*p*2,<=... *p**n*, separated by single spaces (1<=≤<=*p**i*<=≤<=10000), where *p**i* stands for the price offered by the *i*-th bidder. Output Specification: The single output line should contain two integers: index of the winner and the price he will pay. Indices are 1-based. Demo Input: ['2\n5 7\n', '3\n10 2 8\n', '6\n3 8 2 9 4 14\n'] Demo Output: ['2 5\n', '1 8\n', '6 9\n'] Note: none
```python n = int(input()) p = list(map(int, input().split())) h = max(p) newp = set(p) newp.remove(h) sh = max(newp) print(p.index(h) + 1, sh) ```
3
520
A
Pangram
PROGRAMMING
800
[ "implementation", "strings" ]
null
null
A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices. You are given a string consisting of lowercase and uppercase Latin letters. Check whether this string is a pangram. We say that the string contains a letter of the Latin alphabet if this letter occurs in the string in uppercase or lowercase.
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of characters in the string. The second line contains the string. The string consists only of uppercase and lowercase Latin letters.
Output "YES", if the string is a pangram and "NO" otherwise.
[ "12\ntoosmallword\n", "35\nTheQuickBrownFoxJumpsOverTheLazyDog\n" ]
[ "NO\n", "YES\n" ]
none
500
[ { "input": "12\ntoosmallword", "output": "NO" }, { "input": "35\nTheQuickBrownFoxJumpsOverTheLazyDog", "output": "YES" }, { "input": "1\na", "output": "NO" }, { "input": "26\nqwertyuiopasdfghjklzxcvbnm", "output": "YES" }, { "input": "26\nABCDEFGHIJKLMNOPQRSTUVWXYZ", "output": "YES" }, { "input": "48\nthereisasyetinsufficientdataforameaningfulanswer", "output": "NO" }, { "input": "30\nToBeOrNotToBeThatIsTheQuestion", "output": "NO" }, { "input": "30\njackdawslovemybigsphinxofquarz", "output": "NO" }, { "input": "31\nTHEFIVEBOXINGWIZARDSJUMPQUICKLY", "output": "YES" }, { "input": "26\naaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "NO" }, { "input": "26\nMGJYIZDKsbhpVeNFlquRTcWoAx", "output": "YES" }, { "input": "26\nfWMOhAPsbIVtyUEZrGNQXDklCJ", "output": "YES" }, { "input": "26\nngPMVFSThiRCwLEuyOAbKxQzDJ", "output": "YES" }, { "input": "25\nnxYTzLFwzNolAumjgcAboyxAj", "output": "NO" }, { "input": "26\npRWdodGdxUESvcScPGbUoooZsC", "output": "NO" }, { "input": "66\nBovdMlDzTaqKllZILFVfxbLGsRnzmtVVTmqiIDTYrossLEPlmsPrkUYtWEsGHVOnFj", "output": "NO" }, { "input": "100\nmKtsiDRJypUieHIkvJaMFkwaKxcCIbBszZQLIyPpCDCjhNpAnYFngLjRpnKWpKWtGnwoSteeZXuFHWQxxxOpFlNeYTwKocsXuCoa", "output": "YES" }, { "input": "26\nEoqxUbsLjPytUHMiFnvcGWZdRK", "output": "NO" }, { "input": "26\nvCUFRKElZOnjmXGylWQaHDiPst", "output": "NO" }, { "input": "26\nWtrPuaHdXLKJMsnvQfgOiJZBEY", "output": "NO" }, { "input": "26\npGiFluRteQwkaVoPszJyNBChxM", "output": "NO" }, { "input": "26\ncTUpqjPmANrdbzSFhlWIoKxgVY", "output": "NO" }, { "input": "26\nLndjgvAEuICHKxPwqYztosrmBN", "output": "NO" }, { "input": "26\nMdaXJrCipnOZLykfqHWEStevbU", "output": "NO" }, { "input": "26\nEjDWsVxfKTqGXRnUMOLYcIzPba", "output": "NO" }, { "input": "26\nxKwzRMpunYaqsdfaBgJcVElTHo", "output": "NO" }, { "input": "26\nnRYUQsTwCPLZkgshfEXvBdoiMa", "output": "NO" }, { "input": "26\nHNCQPfJutyAlDGsvRxZWMEbIdO", "output": "NO" }, { "input": "26\nDaHJIpvKznQcmUyWsTGObXRFDe", "output": "NO" }, { "input": "26\nkqvAnFAiRhzlJbtyuWedXSPcOG", "output": "NO" }, { "input": "26\nhlrvgdwsIOyjcmUZXtAKEqoBpF", "output": "NO" }, { "input": "26\njLfXXiMhBTcAwQVReGnpKzdsYu", "output": "NO" }, { "input": "26\nlNMcVuwItjxRBGAekjhyDsQOzf", "output": "NO" }, { "input": "26\nRkSwbNoYldUGtAZvpFMcxhIJFE", "output": "NO" }, { "input": "26\nDqspXZJTuONYieKgaHLMBwfVSC", "output": "NO" }, { "input": "26\necOyUkqNljFHRVXtIpWabGMLDz", "output": "NO" }, { "input": "26\nEKAvqZhBnPmVCDRlgWJfOusxYI", "output": "NO" }, { "input": "26\naLbgqeYchKdMrsZxIPFvTOWNjA", "output": "NO" }, { "input": "26\nxfpBLsndiqtacOCHGmeWUjRkYz", "output": "NO" }, { "input": "26\nXsbRKtqleZPNIVCdfUhyagAomJ", "output": "NO" }, { "input": "26\nAmVtbrwquEthZcjKPLiyDgSoNF", "output": "NO" }, { "input": "26\nOhvXDcwqAUmSEPRZGnjFLiKtNB", "output": "NO" }, { "input": "26\nEKWJqCFLRmstxVBdYuinpbhaOg", "output": "NO" }, { "input": "26\nmnbvcxxlkjhgfdsapoiuytrewq", "output": "NO" }, { "input": "26\naAbcdefghijklmnopqrstuvwxy", "output": "NO" }, { "input": "30\nABCDEFGHTYRIOPLabcdefghtyriopl", "output": "NO" }, { "input": "25\nabcdefghijklmnopqrstuvwxy", "output": "NO" }, { "input": "26\nabcdefhijklmnopqrstVxyzABC", "output": "NO" }, { "input": "25\nqwertyuiopasdfghjklxcvbnm", "output": "NO" }, { "input": "34\nTheQuickBrownFoxJumpsOverTheLayDog", "output": "NO" }, { "input": "26\nabcdefghigklmnopqrstuvwxyz", "output": "NO" }, { "input": "26\nabcdefghijklmnopqrstuvwxyA", "output": "NO" }, { "input": "50\nqazwsxedcrfvtgbyhnujmikolQWERTYUIOASDFGHJKLZXCVBNM", "output": "NO" }, { "input": "35\nTheQuickBrownFoxJumpsOverTheLasyDog", "output": "NO" }, { "input": "25\nbcdefghijklmnopqrstuvwxyz", "output": "NO" }, { "input": "38\nAbCdEfGhIjKlMnOpQrStVwXyZzzzzzzaaaaaaa", "output": "NO" }, { "input": "26\nabcdefghiklmnopqrstvxyzABC", "output": "NO" }, { "input": "26\nabcdefghijklmnopqrstuvwxzZ", "output": "NO" }, { "input": "50\nabcdefghijklmnopqrstuvwxyABCDEFGHIJKLMNOPQRSTUVWXY", "output": "NO" } ]
1,696,585,793
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
46
819,200
import string def isPangram(str ): alphabet='abcdefghijklmnopqrstuvwxyz' for char in alphabet: if char not in str.lower(): return False return True n=int(input()) s=input() if(isPangram(s)==True): print("YES") else: print("NO")
Title: Pangram Time Limit: None seconds Memory Limit: None megabytes Problem Description: A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices. You are given a string consisting of lowercase and uppercase Latin letters. Check whether this string is a pangram. We say that the string contains a letter of the Latin alphabet if this letter occurs in the string in uppercase or lowercase. Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of characters in the string. The second line contains the string. The string consists only of uppercase and lowercase Latin letters. Output Specification: Output "YES", if the string is a pangram and "NO" otherwise. Demo Input: ['12\ntoosmallword\n', '35\nTheQuickBrownFoxJumpsOverTheLazyDog\n'] Demo Output: ['NO\n', 'YES\n'] Note: none
```python import string def isPangram(str ): alphabet='abcdefghijklmnopqrstuvwxyz' for char in alphabet: if char not in str.lower(): return False return True n=int(input()) s=input() if(isPangram(s)==True): print("YES") else: print("NO") ```
0
770
A
New Password
PROGRAMMING
800
[ "*special", "implementation" ]
null
null
Innokentiy decides to change the password in the social net "Contact!", but he is too lazy to invent a new password by himself. That is why he needs your help. Innokentiy decides that new password should satisfy the following conditions: - the length of the password must be equal to *n*, - the password should consist only of lowercase Latin letters, - the number of distinct symbols in the password must be equal to *k*, - any two consecutive symbols in the password must be distinct. Your task is to help Innokentiy and to invent a new password which will satisfy all given conditions.
The first line contains two positive integers *n* and *k* (2<=≤<=*n*<=≤<=100, 2<=≤<=*k*<=≤<=*min*(*n*,<=26)) — the length of the password and the number of distinct symbols in it. Pay attention that a desired new password always exists.
Print any password which satisfies all conditions given by Innokentiy.
[ "4 3\n", "6 6\n", "5 2\n" ]
[ "java\n", "python\n", "phphp\n" ]
In the first test there is one of the appropriate new passwords — java, because its length is equal to 4 and 3 distinct lowercase letters a, j and v are used in it. In the second test there is one of the appropriate new passwords — python, because its length is equal to 6 and it consists of 6 distinct lowercase letters. In the third test there is one of the appropriate new passwords — phphp, because its length is equal to 5 and 2 distinct lowercase letters p and h are used in it. Pay attention the condition that no two identical symbols are consecutive is correct for all appropriate passwords in tests.
500
[ { "input": "4 3", "output": "abca" }, { "input": "6 6", "output": "abcdef" }, { "input": "5 2", "output": "ababa" }, { "input": "3 2", "output": "aba" }, { "input": "10 2", "output": "ababababab" }, { "input": "26 13", "output": "abcdefghijklmabcdefghijklm" }, { "input": "100 2", "output": "abababababababababababababababababababababababababababababababababababababababababababababababababab" }, { "input": "100 10", "output": "abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij" }, { "input": "3 3", "output": "abc" }, { "input": "6 3", "output": "abcabc" }, { "input": "10 3", "output": "abcabcabca" }, { "input": "50 3", "output": "abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcab" }, { "input": "90 2", "output": "ababababababababababababababababababababababababababababababababababababababababababababab" }, { "input": "6 2", "output": "ababab" }, { "input": "99 3", "output": "abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc" }, { "input": "4 2", "output": "abab" }, { "input": "100 3", "output": "abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabca" }, { "input": "40 22", "output": "abcdefghijklmnopqrstuvabcdefghijklmnopqr" }, { "input": "13 8", "output": "abcdefghabcde" }, { "input": "16 15", "output": "abcdefghijklmnoa" }, { "input": "17 17", "output": "abcdefghijklmnopq" }, { "input": "19 4", "output": "abcdabcdabcdabcdabc" }, { "input": "100 26", "output": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuv" }, { "input": "100 25", "output": "abcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxy" }, { "input": "26 26", "output": "abcdefghijklmnopqrstuvwxyz" }, { "input": "27 26", "output": "abcdefghijklmnopqrstuvwxyza" }, { "input": "2 2", "output": "ab" }, { "input": "26 25", "output": "abcdefghijklmnopqrstuvwxya" }, { "input": "99 2", "output": "abababababababababababababababababababababababababababababababababababababababababababababababababa" }, { "input": "99 26", "output": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstu" }, { "input": "4 4", "output": "abcd" }, { "input": "5 3", "output": "abcab" }, { "input": "5 4", "output": "abcda" }, { "input": "5 5", "output": "abcde" }, { "input": "24 22", "output": "abcdefghijklmnopqrstuvab" }, { "input": "26 14", "output": "abcdefghijklmnabcdefghijkl" }, { "input": "26 15", "output": "abcdefghijklmnoabcdefghijk" }, { "input": "30 12", "output": "abcdefghijklabcdefghijklabcdef" }, { "input": "35 4", "output": "abcdabcdabcdabcdabcdabcdabcdabcdabc" }, { "input": "79 3", "output": "abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabca" }, { "input": "79 14", "output": "abcdefghijklmnabcdefghijklmnabcdefghijklmnabcdefghijklmnabcdefghijklmnabcdefghi" }, { "input": "85 13", "output": "abcdefghijklmabcdefghijklmabcdefghijklmabcdefghijklmabcdefghijklmabcdefghijklmabcdefg" }, { "input": "90 25", "output": "abcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxyabcdefghijklmno" }, { "input": "90 19", "output": "abcdefghijklmnopqrsabcdefghijklmnopqrsabcdefghijklmnopqrsabcdefghijklmnopqrsabcdefghijklmn" }, { "input": "26 24", "output": "abcdefghijklmnopqrstuvwxab" }, { "input": "100 17", "output": "abcdefghijklmnopqabcdefghijklmnopqabcdefghijklmnopqabcdefghijklmnopqabcdefghijklmnopqabcdefghijklmno" }, { "input": "26 2", "output": "ababababababababababababab" } ]
1,683,039,683
2,147,483,647
Python 3
OK
TESTS
47
46
0
n,k = map(int , input().split()) listofchars = [chr(x+97) for x in range(k)] word="" for i in range(n): word+=listofchars[i%k] print(word)
Title: New Password Time Limit: None seconds Memory Limit: None megabytes Problem Description: Innokentiy decides to change the password in the social net "Contact!", but he is too lazy to invent a new password by himself. That is why he needs your help. Innokentiy decides that new password should satisfy the following conditions: - the length of the password must be equal to *n*, - the password should consist only of lowercase Latin letters, - the number of distinct symbols in the password must be equal to *k*, - any two consecutive symbols in the password must be distinct. Your task is to help Innokentiy and to invent a new password which will satisfy all given conditions. Input Specification: The first line contains two positive integers *n* and *k* (2<=≤<=*n*<=≤<=100, 2<=≤<=*k*<=≤<=*min*(*n*,<=26)) — the length of the password and the number of distinct symbols in it. Pay attention that a desired new password always exists. Output Specification: Print any password which satisfies all conditions given by Innokentiy. Demo Input: ['4 3\n', '6 6\n', '5 2\n'] Demo Output: ['java\n', 'python\n', 'phphp\n'] Note: In the first test there is one of the appropriate new passwords — java, because its length is equal to 4 and 3 distinct lowercase letters a, j and v are used in it. In the second test there is one of the appropriate new passwords — python, because its length is equal to 6 and it consists of 6 distinct lowercase letters. In the third test there is one of the appropriate new passwords — phphp, because its length is equal to 5 and 2 distinct lowercase letters p and h are used in it. Pay attention the condition that no two identical symbols are consecutive is correct for all appropriate passwords in tests.
```python n,k = map(int , input().split()) listofchars = [chr(x+97) for x in range(k)] word="" for i in range(n): word+=listofchars[i%k] print(word) ```
3
851
A
Arpa and a research in Mexican wave
PROGRAMMING
800
[ "implementation", "math" ]
null
null
Arpa is researching the Mexican wave. There are *n* spectators in the stadium, labeled from 1 to *n*. They start the Mexican wave at time 0. - At time 1, the first spectator stands. - At time 2, the second spectator stands. - ... - At time *k*, the *k*-th spectator stands. - At time *k*<=+<=1, the (*k*<=+<=1)-th spectator stands and the first spectator sits. - At time *k*<=+<=2, the (*k*<=+<=2)-th spectator stands and the second spectator sits. - ... - At time *n*, the *n*-th spectator stands and the (*n*<=-<=*k*)-th spectator sits. - At time *n*<=+<=1, the (*n*<=+<=1<=-<=*k*)-th spectator sits. - ... - At time *n*<=+<=*k*, the *n*-th spectator sits. Arpa wants to know how many spectators are standing at time *t*.
The first line contains three integers *n*, *k*, *t* (1<=≤<=*n*<=≤<=109, 1<=≤<=*k*<=≤<=*n*, 1<=≤<=*t*<=&lt;<=*n*<=+<=*k*).
Print single integer: how many spectators are standing at time *t*.
[ "10 5 3\n", "10 5 7\n", "10 5 12\n" ]
[ "3\n", "5\n", "3\n" ]
In the following a sitting spectator is represented as -, a standing spectator is represented as ^. - At *t* = 0  ---------- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 0. - At *t* = 1  ^--------- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 1. - At *t* = 2  ^^-------- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 2. - At *t* = 3  ^^^------- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 3. - At *t* = 4  ^^^^------ <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 4. - At *t* = 5  ^^^^^----- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 5. - At *t* = 6  -^^^^^---- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 5. - At *t* = 7  --^^^^^--- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 5. - At *t* = 8  ---^^^^^-- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 5. - At *t* = 9  ----^^^^^- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 5. - At *t* = 10 -----^^^^^ <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 5. - At *t* = 11 ------^^^^ <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 4. - At *t* = 12 -------^^^ <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 3. - At *t* = 13 --------^^ <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 2. - At *t* = 14 ---------^ <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 1. - At *t* = 15 ---------- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 0.
500
[ { "input": "10 5 3", "output": "3" }, { "input": "10 5 7", "output": "5" }, { "input": "10 5 12", "output": "3" }, { "input": "840585600 770678331 788528791", "output": "770678331" }, { "input": "25462281 23343504 8024619", "output": "8024619" }, { "input": "723717988 205757169 291917494", "output": "205757169" }, { "input": "27462087 20831796 15492397", "output": "15492397" }, { "input": "966696824 346707476 1196846860", "output": "116557440" }, { "input": "290274403 41153108 327683325", "output": "3744186" }, { "input": "170963478 151220598 222269210", "output": "99914866" }, { "input": "14264008 309456 11132789", "output": "309456" }, { "input": "886869816 281212106 52891064", "output": "52891064" }, { "input": "330543750 243917820 205522400", "output": "205522400" }, { "input": "457658451 18625039 157624558", "output": "18625039" }, { "input": "385908940 143313325 509731380", "output": "19490885" }, { "input": "241227633 220621961 10025257", "output": "10025257" }, { "input": "474139818 268918981 388282504", "output": "268918981" }, { "input": "25963410 3071034 820199", "output": "820199" }, { "input": "656346757 647995766 75748423", "output": "75748423" }, { "input": "588568132 411878522 521753621", "output": "411878522" }, { "input": "735788762 355228487 139602545", "output": "139602545" }, { "input": "860798593 463398487 506871376", "output": "463398487" }, { "input": "362624055 110824996 194551217", "output": "110824996" }, { "input": "211691721 195866131 313244576", "output": "94313276" }, { "input": "45661815 26072719 9643822", "output": "9643822" }, { "input": "757183104 590795077 709609355", "output": "590795077" }, { "input": "418386749 1915035 197248338", "output": "1915035" }, { "input": "763782282 297277890 246562421", "output": "246562421" }, { "input": "893323188 617630677 607049638", "output": "607049638" }, { "input": "506708261 356545583 296093684", "output": "296093684" }, { "input": "984295813 427551190 84113823", "output": "84113823" }, { "input": "774984967 61373612 96603505", "output": "61373612" }, { "input": "774578969 342441237 91492393", "output": "91492393" }, { "input": "76495801 8780305 56447339", "output": "8780305" }, { "input": "48538385 582843 16805978", "output": "582843" }, { "input": "325794610 238970909 553089099", "output": "11676420" }, { "input": "834925315 316928679 711068031", "output": "316928679" }, { "input": "932182199 454838315 267066713", "output": "267066713" }, { "input": "627793782 552043394 67061810", "output": "67061810" }, { "input": "24317170 17881607 218412", "output": "218412" }, { "input": "1000000000 1000 1", "output": "1" }, { "input": "1000000000 1000 2", "output": "2" }, { "input": "1000000000 1 1000", "output": "1" }, { "input": "100 100 100", "output": "100" }, { "input": "100 100 99", "output": "99" }, { "input": "100 100 101", "output": "99" }, { "input": "100 100 199", "output": "1" }, { "input": "1000000000 1000000000 1999999999", "output": "1" }, { "input": "10 5 5", "output": "5" }, { "input": "5 3 5", "output": "3" }, { "input": "10 3 3", "output": "3" }, { "input": "10 5 6", "output": "5" }, { "input": "3 2 4", "output": "1" }, { "input": "10 5 14", "output": "1" }, { "input": "6 1 4", "output": "1" }, { "input": "10 10 19", "output": "1" }, { "input": "10 4 11", "output": "3" }, { "input": "2 2 3", "output": "1" }, { "input": "10 5 11", "output": "4" }, { "input": "600 200 700", "output": "100" }, { "input": "2000 1000 2001", "output": "999" }, { "input": "1000 1000 1001", "output": "999" }, { "input": "5 4 6", "output": "3" }, { "input": "2 1 2", "output": "1" }, { "input": "10 3 10", "output": "3" }, { "input": "15 10 10", "output": "10" }, { "input": "10 5 13", "output": "2" }, { "input": "2 2 2", "output": "2" }, { "input": "5 5 6", "output": "4" }, { "input": "10 6 12", "output": "4" }, { "input": "7 5 8", "output": "4" }, { "input": "10 4 9", "output": "4" }, { "input": "9 2 6", "output": "2" }, { "input": "5 2 6", "output": "1" }, { "input": "6 2 6", "output": "2" }, { "input": "5 5 8", "output": "2" }, { "input": "3 3 5", "output": "1" }, { "input": "10 2 5", "output": "2" }, { "input": "5 3 7", "output": "1" }, { "input": "5 4 8", "output": "1" }, { "input": "10 6 11", "output": "5" }, { "input": "5 3 6", "output": "2" }, { "input": "10 6 14", "output": "2" }, { "input": "10 10 10", "output": "10" }, { "input": "1000000000 1 1000000000", "output": "1" }, { "input": "20 4 22", "output": "2" }, { "input": "5 4 4", "output": "4" }, { "input": "4 3 6", "output": "1" }, { "input": "12 8 18", "output": "2" }, { "input": "10 5 10", "output": "5" }, { "input": "100 50 149", "output": "1" }, { "input": "4 4 4", "output": "4" }, { "input": "7 6 9", "output": "4" }, { "input": "16 10 21", "output": "5" }, { "input": "10 2 11", "output": "1" }, { "input": "600 200 500", "output": "200" }, { "input": "100 30 102", "output": "28" }, { "input": "10 10 18", "output": "2" }, { "input": "15 3 10", "output": "3" }, { "input": "1000000000 1000000000 1000000000", "output": "1000000000" }, { "input": "5 5 5", "output": "5" }, { "input": "10 3 12", "output": "1" }, { "input": "747 457 789", "output": "415" }, { "input": "5 4 7", "output": "2" }, { "input": "15 5 11", "output": "5" }, { "input": "3 2 2", "output": "2" }, { "input": "7 6 8", "output": "5" }, { "input": "7 4 8", "output": "3" }, { "input": "10 4 13", "output": "1" }, { "input": "10 3 9", "output": "3" }, { "input": "20 2 21", "output": "1" }, { "input": "6 5 9", "output": "2" }, { "input": "10 9 18", "output": "1" }, { "input": "12 4 9", "output": "4" }, { "input": "10 7 15", "output": "2" }, { "input": "999999999 999999998 1500000000", "output": "499999997" }, { "input": "20 5 20", "output": "5" }, { "input": "4745 4574 4757", "output": "4562" }, { "input": "10 7 12", "output": "5" }, { "input": "17 15 18", "output": "14" }, { "input": "3 1 3", "output": "1" }, { "input": "100 3 7", "output": "3" }, { "input": "6 2 7", "output": "1" }, { "input": "8 5 10", "output": "3" }, { "input": "3 3 3", "output": "3" }, { "input": "9 5 10", "output": "4" }, { "input": "10 6 13", "output": "3" }, { "input": "13 10 14", "output": "9" }, { "input": "13 12 15", "output": "10" }, { "input": "10 4 12", "output": "2" }, { "input": "41 3 3", "output": "3" }, { "input": "1000000000 1000000000 1400000000", "output": "600000000" }, { "input": "10 3 11", "output": "2" }, { "input": "12 7 18", "output": "1" }, { "input": "15 3 17", "output": "1" }, { "input": "10 2 8", "output": "2" }, { "input": "1000000000 1000 1000000999", "output": "1" }, { "input": "5 5 9", "output": "1" }, { "input": "100 3 6", "output": "3" }, { "input": "100 5 50", "output": "5" }, { "input": "10000 10 10000", "output": "10" }, { "input": "1 1 1", "output": "1" }, { "input": "6 4 4", "output": "4" }, { "input": "9979797 555554 10101010", "output": "434341" }, { "input": "13 5 12", "output": "5" }, { "input": "9 4 10", "output": "3" }, { "input": "7 5 10", "output": "2" }, { "input": "100000000 10000000 100005000", "output": "9995000" }, { "input": "100000 50000 100001", "output": "49999" }, { "input": "15 10 20", "output": "5" }, { "input": "4 4 5", "output": "3" }, { "input": "5 3 3", "output": "3" }, { "input": "30 5 30", "output": "5" }, { "input": "200000 10 200005", "output": "5" }, { "input": "10 9 12", "output": "7" }, { "input": "10 6 15", "output": "1" }, { "input": "1000000000 10 1000000000", "output": "10" }, { "input": "7 5 11", "output": "1" }, { "input": "9 4 4", "output": "4" }, { "input": "14 3 15", "output": "2" }, { "input": "1000000000 100000000 1000000000", "output": "100000000" }, { "input": "40 10 22", "output": "10" }, { "input": "50 10 51", "output": "9" }, { "input": "999999997 999999995 1999999991", "output": "1" }, { "input": "92 79 144", "output": "27" }, { "input": "8 4 4", "output": "4" } ]
1,568,734,507
2,147,483,647
PyPy 3
OK
TESTS
166
140
102,400
n,k,t= input().split() n= int(n) k= int(k) t= int(t) if t<=k: print(t) elif t>k and t<n: print(k) else: print(k-t+n)
Title: Arpa and a research in Mexican wave Time Limit: None seconds Memory Limit: None megabytes Problem Description: Arpa is researching the Mexican wave. There are *n* spectators in the stadium, labeled from 1 to *n*. They start the Mexican wave at time 0. - At time 1, the first spectator stands. - At time 2, the second spectator stands. - ... - At time *k*, the *k*-th spectator stands. - At time *k*<=+<=1, the (*k*<=+<=1)-th spectator stands and the first spectator sits. - At time *k*<=+<=2, the (*k*<=+<=2)-th spectator stands and the second spectator sits. - ... - At time *n*, the *n*-th spectator stands and the (*n*<=-<=*k*)-th spectator sits. - At time *n*<=+<=1, the (*n*<=+<=1<=-<=*k*)-th spectator sits. - ... - At time *n*<=+<=*k*, the *n*-th spectator sits. Arpa wants to know how many spectators are standing at time *t*. Input Specification: The first line contains three integers *n*, *k*, *t* (1<=≤<=*n*<=≤<=109, 1<=≤<=*k*<=≤<=*n*, 1<=≤<=*t*<=&lt;<=*n*<=+<=*k*). Output Specification: Print single integer: how many spectators are standing at time *t*. Demo Input: ['10 5 3\n', '10 5 7\n', '10 5 12\n'] Demo Output: ['3\n', '5\n', '3\n'] Note: In the following a sitting spectator is represented as -, a standing spectator is represented as ^. - At *t* = 0  ---------- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 0. - At *t* = 1  ^--------- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 1. - At *t* = 2  ^^-------- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 2. - At *t* = 3  ^^^------- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 3. - At *t* = 4  ^^^^------ <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 4. - At *t* = 5  ^^^^^----- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 5. - At *t* = 6  -^^^^^---- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 5. - At *t* = 7  --^^^^^--- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 5. - At *t* = 8  ---^^^^^-- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 5. - At *t* = 9  ----^^^^^- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 5. - At *t* = 10 -----^^^^^ <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 5. - At *t* = 11 ------^^^^ <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 4. - At *t* = 12 -------^^^ <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 3. - At *t* = 13 --------^^ <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 2. - At *t* = 14 ---------^ <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 1. - At *t* = 15 ---------- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 0.
```python n,k,t= input().split() n= int(n) k= int(k) t= int(t) if t<=k: print(t) elif t>k and t<n: print(k) else: print(k-t+n) ```
3
0
none
none
none
0
[ "none" ]
null
null
Vasya the programmer lives in the middle of the Programming subway branch. He has two girlfriends: Dasha and Masha, who live at the different ends of the branch, each one is unaware of the other one's existence. When Vasya has some free time, he goes to one of his girlfriends. He descends into the subway at some time, waits the first train to come and rides on it to the end of the branch to the corresponding girl. However, the trains run with different frequencies: a train goes to Dasha's direction every *a* minutes, but a train goes to Masha's direction every *b* minutes. If two trains approach at the same time, Vasya goes toward the direction with the lower frequency of going trains, that is, to the girl, to whose directions the trains go less frequently (see the note to the third sample). We know that the trains begin to go simultaneously before Vasya appears. That is the train schedule is such that there exists a moment of time when the two trains arrive simultaneously. Help Vasya count to which girlfriend he will go more often.
The first line contains two integers *a* and *b* (*a*<=≠<=*b*,<=1<=≤<=*a*,<=*b*<=≤<=106).
Print "Dasha" if Vasya will go to Dasha more frequently, "Masha" if he will go to Masha more frequently, or "Equal" if he will go to both girlfriends with the same frequency.
[ "3 7\n", "5 3\n", "2 3\n" ]
[ "Dasha\n", "Masha\n", "Equal\n" ]
Let's take a look at the third sample. Let the trains start to go at the zero moment of time. It is clear that the moments of the trains' arrival will be periodic with period 6. That's why it is enough to show that if Vasya descends to the subway at a moment of time inside the interval (0, 6], he will go to both girls equally often. If he descends to the subway at a moment of time from 0 to 2, he leaves for Dasha on the train that arrives by the second minute. If he descends to the subway at a moment of time from 2 to 3, he leaves for Masha on the train that arrives by the third minute. If he descends to the subway at a moment of time from 3 to 4, he leaves for Dasha on the train that arrives by the fourth minute. If he descends to the subway at a moment of time from 4 to 6, he waits for both trains to arrive by the sixth minute and goes to Masha as trains go less often in Masha's direction. In sum Masha and Dasha get equal time — three minutes for each one, thus, Vasya will go to both girlfriends equally often.
0
[ { "input": "3 7", "output": "Dasha" }, { "input": "5 3", "output": "Masha" }, { "input": "2 3", "output": "Equal" }, { "input": "31 88", "output": "Dasha" }, { "input": "8 75", "output": "Dasha" }, { "input": "32 99", "output": "Dasha" }, { "input": "77 4", "output": "Masha" }, { "input": "27 1", "output": "Masha" }, { "input": "84 11", "output": "Masha" }, { "input": "4 6", "output": "Equal" }, { "input": "52 53", "output": "Equal" }, { "input": "397 568", "output": "Dasha" }, { "input": "22 332", "output": "Dasha" }, { "input": "419 430", "output": "Dasha" }, { "input": "638 619", "output": "Masha" }, { "input": "393 325", "output": "Masha" }, { "input": "876 218", "output": "Masha" }, { "input": "552 551", "output": "Equal" }, { "input": "906 912", "output": "Equal" }, { "input": "999 996", "output": "Equal" }, { "input": "652 653", "output": "Equal" }, { "input": "3647 7698", "output": "Dasha" }, { "input": "2661 8975", "output": "Dasha" }, { "input": "251 9731", "output": "Dasha" }, { "input": "9886 8671", "output": "Masha" }, { "input": "8545 7312", "output": "Masha" }, { "input": "4982 2927", "output": "Masha" }, { "input": "7660 7658", "output": "Equal" }, { "input": "9846 9844", "output": "Equal" }, { "input": "9632 9640", "output": "Equal" }, { "input": "5036 5037", "output": "Equal" }, { "input": "64854 77725", "output": "Dasha" }, { "input": "4965 85708", "output": "Dasha" }, { "input": "20393 86640", "output": "Dasha" }, { "input": "99207 30728", "output": "Masha" }, { "input": "77545 13842", "output": "Masha" }, { "input": "30362 10712", "output": "Masha" }, { "input": "51291 51292", "output": "Equal" }, { "input": "55381 55382", "output": "Equal" }, { "input": "91560 91550", "output": "Equal" }, { "input": "99087 99090", "output": "Equal" }, { "input": "983794 986389", "output": "Dasha" }, { "input": "779183 786727", "output": "Dasha" }, { "input": "450766 610961", "output": "Dasha" }, { "input": "664690 630787", "output": "Masha" }, { "input": "461363 256765", "output": "Masha" }, { "input": "638067 409048", "output": "Masha" }, { "input": "929061 929052", "output": "Equal" }, { "input": "996219 996216", "output": "Equal" }, { "input": "716249 716248", "output": "Equal" }, { "input": "782250 782252", "output": "Equal" }, { "input": "1 2", "output": "Equal" }, { "input": "2 1", "output": "Equal" }, { "input": "999999 1000000", "output": "Equal" }, { "input": "999997 1000000", "output": "Dasha" }, { "input": "1000000 999993", "output": "Masha" }, { "input": "999983 999979", "output": "Masha" } ]
1,636,797,023
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
62
4,198,400
a,b = [int(i) for i in input().split(' ')] r = ((a*b)/a)-1 > (a*b)/b if (r > 0): print("Dasha") elif(r == 0): print("Equal") else: print("Masha")
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya the programmer lives in the middle of the Programming subway branch. He has two girlfriends: Dasha and Masha, who live at the different ends of the branch, each one is unaware of the other one's existence. When Vasya has some free time, he goes to one of his girlfriends. He descends into the subway at some time, waits the first train to come and rides on it to the end of the branch to the corresponding girl. However, the trains run with different frequencies: a train goes to Dasha's direction every *a* minutes, but a train goes to Masha's direction every *b* minutes. If two trains approach at the same time, Vasya goes toward the direction with the lower frequency of going trains, that is, to the girl, to whose directions the trains go less frequently (see the note to the third sample). We know that the trains begin to go simultaneously before Vasya appears. That is the train schedule is such that there exists a moment of time when the two trains arrive simultaneously. Help Vasya count to which girlfriend he will go more often. Input Specification: The first line contains two integers *a* and *b* (*a*<=≠<=*b*,<=1<=≤<=*a*,<=*b*<=≤<=106). Output Specification: Print "Dasha" if Vasya will go to Dasha more frequently, "Masha" if he will go to Masha more frequently, or "Equal" if he will go to both girlfriends with the same frequency. Demo Input: ['3 7\n', '5 3\n', '2 3\n'] Demo Output: ['Dasha\n', 'Masha\n', 'Equal\n'] Note: Let's take a look at the third sample. Let the trains start to go at the zero moment of time. It is clear that the moments of the trains' arrival will be periodic with period 6. That's why it is enough to show that if Vasya descends to the subway at a moment of time inside the interval (0, 6], he will go to both girls equally often. If he descends to the subway at a moment of time from 0 to 2, he leaves for Dasha on the train that arrives by the second minute. If he descends to the subway at a moment of time from 2 to 3, he leaves for Masha on the train that arrives by the third minute. If he descends to the subway at a moment of time from 3 to 4, he leaves for Dasha on the train that arrives by the fourth minute. If he descends to the subway at a moment of time from 4 to 6, he waits for both trains to arrive by the sixth minute and goes to Masha as trains go less often in Masha's direction. In sum Masha and Dasha get equal time — three minutes for each one, thus, Vasya will go to both girlfriends equally often.
```python a,b = [int(i) for i in input().split(' ')] r = ((a*b)/a)-1 > (a*b)/b if (r > 0): print("Dasha") elif(r == 0): print("Equal") else: print("Masha") ```
0
271
A
Beautiful Year
PROGRAMMING
800
[ "brute force" ]
null
null
It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits. Now you are suggested to solve the following problem: given a year number, find the minimum year number which is strictly larger than the given one and has only distinct digits.
The single line contains integer *y* (1000<=≤<=*y*<=≤<=9000) — the year number.
Print a single integer — the minimum year number that is strictly larger than *y* and all it's digits are distinct. It is guaranteed that the answer exists.
[ "1987\n", "2013\n" ]
[ "2013\n", "2014\n" ]
none
500
[ { "input": "1987", "output": "2013" }, { "input": "2013", "output": "2014" }, { "input": "1000", "output": "1023" }, { "input": "1001", "output": "1023" }, { "input": "1234", "output": "1235" }, { "input": "5555", "output": "5601" }, { "input": "9000", "output": "9012" }, { "input": "1111", "output": "1203" }, { "input": "8999", "output": "9012" }, { "input": "4572", "output": "4573" }, { "input": "6666", "output": "6701" }, { "input": "2001", "output": "2013" }, { "input": "3000", "output": "3012" }, { "input": "7712", "output": "7801" }, { "input": "8088", "output": "8091" }, { "input": "1594", "output": "1596" }, { "input": "6016", "output": "6017" }, { "input": "8800", "output": "8901" }, { "input": "3331", "output": "3401" }, { "input": "5090", "output": "5091" }, { "input": "2342", "output": "2345" }, { "input": "2334", "output": "2340" }, { "input": "1123", "output": "1203" }, { "input": "8989", "output": "9012" }, { "input": "8977", "output": "9012" }, { "input": "6869", "output": "6870" }, { "input": "8999", "output": "9012" } ]
1,694,164,837
2,147,483,647
Python 3
OK
TESTS
27
92
0
def is_distinct_year(year): year_str = str(year) return len(year_str) == len(set(year_str)) def find_next_distinct_year(y): while True: y += 1 if is_distinct_year(y): return y y = int(input()) next_distinct_year = find_next_distinct_year(y) print(next_distinct_year)
Title: Beautiful Year Time Limit: None seconds Memory Limit: None megabytes Problem Description: It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits. Now you are suggested to solve the following problem: given a year number, find the minimum year number which is strictly larger than the given one and has only distinct digits. Input Specification: The single line contains integer *y* (1000<=≤<=*y*<=≤<=9000) — the year number. Output Specification: Print a single integer — the minimum year number that is strictly larger than *y* and all it's digits are distinct. It is guaranteed that the answer exists. Demo Input: ['1987\n', '2013\n'] Demo Output: ['2013\n', '2014\n'] Note: none
```python def is_distinct_year(year): year_str = str(year) return len(year_str) == len(set(year_str)) def find_next_distinct_year(y): while True: y += 1 if is_distinct_year(y): return y y = int(input()) next_distinct_year = find_next_distinct_year(y) print(next_distinct_year) ```
3
576
B
Invariance of Tree
PROGRAMMING
2,100
[ "constructive algorithms", "dfs and similar", "greedy", "trees" ]
null
null
A tree of size *n* is an undirected connected graph consisting of *n* vertices without cycles. Consider some tree with *n* vertices. We call a tree invariant relative to permutation *p*<==<=*p*1*p*2... *p**n*, if for any two vertices of the tree *u* and *v* the condition holds: "vertices *u* and *v* are connected by an edge if and only if vertices *p**u* and *p**v* are connected by an edge". You are given permutation *p* of size *n*. Find some tree size *n*, invariant relative to the given permutation.
The first line contains number *n* (1<=≤<=*n*<=≤<=105) — the size of the permutation (also equal to the size of the sought tree). The second line contains permutation *p**i* (1<=≤<=*p**i*<=≤<=*n*).
If the sought tree does not exist, print "NO" (without the quotes). Otherwise, print "YES", and then print *n*<=-<=1 lines, each of which contains two integers — the numbers of vertices connected by an edge of the tree you found. The vertices are numbered from 1, the order of the edges and the order of the vertices within the edges does not matter. If there are multiple solutions, output any of them.
[ "4\n4 3 2 1\n", "3\n3 1 2\n" ]
[ "YES\n4 1\n4 2\n1 3\n", "NO\n" ]
In the first sample test a permutation transforms edge (4, 1) into edge (1, 4), edge (4, 2) into edge (1, 3) and edge (1, 3) into edge (4, 2). These edges all appear in the resulting tree. It can be shown that in the second sample test no tree satisfies the given condition.
1,250
[ { "input": "4\n4 3 2 1", "output": "YES\n4 1\n4 2\n1 3" }, { "input": "3\n3 1 2", "output": "NO" }, { "input": "3\n3 2 1", "output": "YES\n2 1\n2 3" }, { "input": "4\n3 4 1 2", "output": "YES\n4 2\n4 1\n2 3" }, { "input": "5\n5 3 2 1 4", "output": "NO" }, { "input": "8\n1 2 6 4 5 7 8 3", "output": "YES\n5 1\n5 2\n5 3\n5 4\n5 6\n5 7\n5 8" }, { "input": "11\n7 3 5 2 10 1 9 6 8 4 11", "output": "YES\n11 1\n11 2\n11 3\n11 4\n11 5\n11 6\n11 7\n11 8\n11 9\n11 10" }, { "input": "1\n1", "output": "YES" }, { "input": "2\n1 2", "output": "YES\n2 1" }, { "input": "2\n2 1", "output": "YES\n2 1" }, { "input": "6\n2 1 6 5 3 4", "output": "YES\n2 1\n2 3\n2 4\n1 6\n1 5" }, { "input": "6\n2 1 4 5 6 3", "output": "YES\n2 1\n2 3\n2 5\n1 4\n1 6" }, { "input": "4\n2 3 4 1", "output": "NO" }, { "input": "6\n2 3 4 1 6 5", "output": "YES\n6 5\n6 1\n6 3\n5 2\n5 4" }, { "input": "6\n4 1 2 3 6 5", "output": "YES\n6 5\n6 1\n6 3\n5 4\n5 2" } ]
1,689,420,044
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
46
0
print("_RANDOM_GUESS_1689420042.6852078")# 1689420042.685228
Title: Invariance of Tree Time Limit: None seconds Memory Limit: None megabytes Problem Description: A tree of size *n* is an undirected connected graph consisting of *n* vertices without cycles. Consider some tree with *n* vertices. We call a tree invariant relative to permutation *p*<==<=*p*1*p*2... *p**n*, if for any two vertices of the tree *u* and *v* the condition holds: "vertices *u* and *v* are connected by an edge if and only if vertices *p**u* and *p**v* are connected by an edge". You are given permutation *p* of size *n*. Find some tree size *n*, invariant relative to the given permutation. Input Specification: The first line contains number *n* (1<=≤<=*n*<=≤<=105) — the size of the permutation (also equal to the size of the sought tree). The second line contains permutation *p**i* (1<=≤<=*p**i*<=≤<=*n*). Output Specification: If the sought tree does not exist, print "NO" (without the quotes). Otherwise, print "YES", and then print *n*<=-<=1 lines, each of which contains two integers — the numbers of vertices connected by an edge of the tree you found. The vertices are numbered from 1, the order of the edges and the order of the vertices within the edges does not matter. If there are multiple solutions, output any of them. Demo Input: ['4\n4 3 2 1\n', '3\n3 1 2\n'] Demo Output: ['YES\n4 1\n4 2\n1 3\n', 'NO\n'] Note: In the first sample test a permutation transforms edge (4, 1) into edge (1, 4), edge (4, 2) into edge (1, 3) and edge (1, 3) into edge (4, 2). These edges all appear in the resulting tree. It can be shown that in the second sample test no tree satisfies the given condition.
```python print("_RANDOM_GUESS_1689420042.6852078")# 1689420042.685228 ```
0
572
B
Order Book
PROGRAMMING
1,300
[ "data structures", "greedy", "implementation", "sortings" ]
null
null
In this task you need to process a set of stock exchange orders and use them to create order book. An order is an instruction of some participant to buy or sell stocks on stock exchange. The order number *i* has price *p**i*, direction *d**i* — buy or sell, and integer *q**i*. This means that the participant is ready to buy or sell *q**i* stocks at price *p**i* for one stock. A value *q**i* is also known as a volume of an order. All orders with the same price *p* and direction *d* are merged into one aggregated order with price *p* and direction *d*. The volume of such order is a sum of volumes of the initial orders. An order book is a list of aggregated orders, the first part of which contains sell orders sorted by price in descending order, the second contains buy orders also sorted by price in descending order. An order book of depth *s* contains *s* best aggregated orders for each direction. A buy order is better if it has higher price and a sell order is better if it has lower price. If there are less than *s* aggregated orders for some direction then all of them will be in the final order book. You are given *n* stock exhange orders. Your task is to print order book of depth *s* for these orders.
The input starts with two positive integers *n* and *s* (1<=≤<=*n*<=≤<=1000,<=1<=≤<=*s*<=≤<=50), the number of orders and the book depth. Next *n* lines contains a letter *d**i* (either 'B' or 'S'), an integer *p**i* (0<=≤<=*p**i*<=≤<=105) and an integer *q**i* (1<=≤<=*q**i*<=≤<=104) — direction, price and volume respectively. The letter 'B' means buy, 'S' means sell. The price of any sell order is higher than the price of any buy order.
Print no more than 2*s* lines with aggregated orders from order book of depth *s*. The output format for orders should be the same as in input.
[ "6 2\nB 10 3\nS 50 2\nS 40 1\nS 50 6\nB 20 4\nB 25 10\n" ]
[ "S 50 8\nS 40 1\nB 25 10\nB 20 4\n" ]
Denote (x, y) an order with price *x* and volume *y*. There are 3 aggregated buy orders (10, 3), (20, 4), (25, 10) and two sell orders (50, 8), (40, 1) in the sample. You need to print no more than two best orders for each direction, so you shouldn't print the order (10 3) having the worst price among buy orders.
1,000
[ { "input": "6 2\nB 10 3\nS 50 2\nS 40 1\nS 50 6\nB 20 4\nB 25 10", "output": "S 50 8\nS 40 1\nB 25 10\nB 20 4" }, { "input": "2 1\nB 7523 5589\nS 69799 1711", "output": "S 69799 1711\nB 7523 5589" }, { "input": "1 1\nB 48259 991", "output": "B 48259 991" }, { "input": "1 50\nB 47828 7726", "output": "B 47828 7726" }, { "input": "1 1\nS 95992 7257", "output": "S 95992 7257" }, { "input": "1 50\nS 72218 8095", "output": "S 72218 8095" }, { "input": "2 50\nB 758 9290\nS 86168 3367", "output": "S 86168 3367\nB 758 9290" }, { "input": "3 3\nB 5878 1568\nS 60238 4895\nS 76276 1905", "output": "S 76276 1905\nS 60238 4895\nB 5878 1568" }, { "input": "6 2\nB 0 1\nS 1 1\nS 1 1\nS 1 1\nB 0 1\nB 0 1", "output": "S 1 3\nB 0 3" }, { "input": "2 2\nS 1 1\nB 0 2", "output": "S 1 1\nB 0 2" }, { "input": "2 1\nS 10 1\nB 0 1", "output": "S 10 1\nB 0 1" }, { "input": "2 10\nB 0 1\nS 100000 1", "output": "S 100000 1\nB 0 1" }, { "input": "2 1\nS 1 1\nB 0 1", "output": "S 1 1\nB 0 1" }, { "input": "2 1\nB 0 100\nS 1 100", "output": "S 1 100\nB 0 100" }, { "input": "2 2\nB 0 3\nS 10 3", "output": "S 10 3\nB 0 3" }, { "input": "2 10\nB 0 1\nS 1 1", "output": "S 1 1\nB 0 1" }, { "input": "2 50\nB 2 5\nB 0 1", "output": "B 2 5\nB 0 1" } ]
1,552,810,975
2,147,483,647
PyPy 3
RUNTIME_ERROR
TESTS
2
186
1,024,000
n,st=[int(i) for i in input().split()] b=[] s=[] for i in range(n): ss=input().split() ss[1]=int(ss[1]) ss[2]=int(ss[2]) if ss[0]=='B': b.append(ss) else: s.append(ss) b.sort() s.sort() bb=[b[0]] ss=[s[0]] for i in range(len(b)-1): if b[i][1]==b[i+1][1]: bb[-1][2]+=b[i+1][2] else: bb.append(b[i+1]) for i in range(len(s)-1): if s[i][1]==s[i+1][1]: ss[-1][2]+=s[i+1][2] else: ss.append(s[i+1]) bb=sorted(bb)[::-1] ss=sorted(ss)[::-1] if len(bb)>st: bb=bb[:st] if len(ss)>st: ss=ss[:st] for i in ss: print(*i) for i in bb: print(*i)
Title: Order Book Time Limit: None seconds Memory Limit: None megabytes Problem Description: In this task you need to process a set of stock exchange orders and use them to create order book. An order is an instruction of some participant to buy or sell stocks on stock exchange. The order number *i* has price *p**i*, direction *d**i* — buy or sell, and integer *q**i*. This means that the participant is ready to buy or sell *q**i* stocks at price *p**i* for one stock. A value *q**i* is also known as a volume of an order. All orders with the same price *p* and direction *d* are merged into one aggregated order with price *p* and direction *d*. The volume of such order is a sum of volumes of the initial orders. An order book is a list of aggregated orders, the first part of which contains sell orders sorted by price in descending order, the second contains buy orders also sorted by price in descending order. An order book of depth *s* contains *s* best aggregated orders for each direction. A buy order is better if it has higher price and a sell order is better if it has lower price. If there are less than *s* aggregated orders for some direction then all of them will be in the final order book. You are given *n* stock exhange orders. Your task is to print order book of depth *s* for these orders. Input Specification: The input starts with two positive integers *n* and *s* (1<=≤<=*n*<=≤<=1000,<=1<=≤<=*s*<=≤<=50), the number of orders and the book depth. Next *n* lines contains a letter *d**i* (either 'B' or 'S'), an integer *p**i* (0<=≤<=*p**i*<=≤<=105) and an integer *q**i* (1<=≤<=*q**i*<=≤<=104) — direction, price and volume respectively. The letter 'B' means buy, 'S' means sell. The price of any sell order is higher than the price of any buy order. Output Specification: Print no more than 2*s* lines with aggregated orders from order book of depth *s*. The output format for orders should be the same as in input. Demo Input: ['6 2\nB 10 3\nS 50 2\nS 40 1\nS 50 6\nB 20 4\nB 25 10\n'] Demo Output: ['S 50 8\nS 40 1\nB 25 10\nB 20 4\n'] Note: Denote (x, y) an order with price *x* and volume *y*. There are 3 aggregated buy orders (10, 3), (20, 4), (25, 10) and two sell orders (50, 8), (40, 1) in the sample. You need to print no more than two best orders for each direction, so you shouldn't print the order (10 3) having the worst price among buy orders.
```python n,st=[int(i) for i in input().split()] b=[] s=[] for i in range(n): ss=input().split() ss[1]=int(ss[1]) ss[2]=int(ss[2]) if ss[0]=='B': b.append(ss) else: s.append(ss) b.sort() s.sort() bb=[b[0]] ss=[s[0]] for i in range(len(b)-1): if b[i][1]==b[i+1][1]: bb[-1][2]+=b[i+1][2] else: bb.append(b[i+1]) for i in range(len(s)-1): if s[i][1]==s[i+1][1]: ss[-1][2]+=s[i+1][2] else: ss.append(s[i+1]) bb=sorted(bb)[::-1] ss=sorted(ss)[::-1] if len(bb)>st: bb=bb[:st] if len(ss)>st: ss=ss[:st] for i in ss: print(*i) for i in bb: print(*i) ```
-1
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,639,316,868
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
46
0
s=input() l=['h','e','l','l','o'] i=-1 for c in l: i=s.find(c,i+1) if i==-1: print('no') exit() print('yes')
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 s=input() l=['h','e','l','l','o'] i=-1 for c in l: i=s.find(c,i+1) if i==-1: print('no') exit() print('yes') ```
0
893
B
Beautiful Divisors
PROGRAMMING
1,000
[ "brute force", "implementation" ]
null
null
Recently Luba learned about a special kind of numbers that she calls beautiful numbers. The number is called beautiful iff its binary representation consists of *k*<=+<=1 consecutive ones, and then *k* consecutive zeroes. Some examples of beautiful numbers: - 12 (110); - 1102 (610); - 11110002 (12010); - 1111100002 (49610). More formally, the number is beautiful iff there exists some positive integer *k* such that the number is equal to (2*k*<=-<=1)<=*<=(2*k*<=-<=1). Luba has got an integer number *n*, and she wants to find its greatest beautiful divisor. Help her to find it!
The only line of input contains one number *n* (1<=≤<=*n*<=≤<=105) — the number Luba has got.
Output one number — the greatest beautiful divisor of Luba's number. It is obvious that the answer always exists.
[ "3\n", "992\n" ]
[ "1\n", "496\n" ]
none
0
[ { "input": "3", "output": "1" }, { "input": "992", "output": "496" }, { "input": "81142", "output": "1" }, { "input": "76920", "output": "120" }, { "input": "2016", "output": "2016" }, { "input": "1", "output": "1" }, { "input": "6", "output": "6" }, { "input": "32640", "output": "32640" }, { "input": "12096", "output": "2016" }, { "input": "55948", "output": "1" }, { "input": "47262", "output": "6" }, { "input": "22876", "output": "28" }, { "input": "96120", "output": "120" }, { "input": "42160", "output": "496" }, { "input": "38304", "output": "2016" }, { "input": "89408", "output": "8128" }, { "input": "97920", "output": "32640" }, { "input": "55493", "output": "1" }, { "input": "38021", "output": "1" }, { "input": "21445", "output": "1" }, { "input": "100000", "output": "1" }, { "input": "497", "output": "1" }, { "input": "240", "output": "120" }, { "input": "21204", "output": "6" }, { "input": "65536", "output": "1" }, { "input": "364", "output": "28" }, { "input": "1024", "output": "1" }, { "input": "36", "output": "6" }, { "input": "28", "output": "28" }, { "input": "14400", "output": "120" }, { "input": "10080", "output": "2016" }, { "input": "9", "output": "1" }, { "input": "2", "output": "1" }, { "input": "42", "output": "6" }, { "input": "83160", "output": "120" }, { "input": "65534", "output": "1" }, { "input": "1026", "output": "6" }, { "input": "1025", "output": "1" }, { "input": "1027", "output": "1" }, { "input": "2018", "output": "1" }, { "input": "2020", "output": "1" }, { "input": "123", "output": "1" }, { "input": "150", "output": "6" }, { "input": "5", "output": "1" }, { "input": "66", "output": "6" }, { "input": "12768", "output": "28" }, { "input": "156", "output": "6" }, { "input": "99990", "output": "6" }, { "input": "248", "output": "1" } ]
1,651,652,766
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
2
78
0
import sys input = sys.stdin.readline n = int(input()) s = len(bin(n)[2:]) print(int('0b' + (s+1)//2 * '1' + (s-1)//2 * '0', 2))
Title: Beautiful Divisors Time Limit: None seconds Memory Limit: None megabytes Problem Description: Recently Luba learned about a special kind of numbers that she calls beautiful numbers. The number is called beautiful iff its binary representation consists of *k*<=+<=1 consecutive ones, and then *k* consecutive zeroes. Some examples of beautiful numbers: - 12 (110); - 1102 (610); - 11110002 (12010); - 1111100002 (49610). More formally, the number is beautiful iff there exists some positive integer *k* such that the number is equal to (2*k*<=-<=1)<=*<=(2*k*<=-<=1). Luba has got an integer number *n*, and she wants to find its greatest beautiful divisor. Help her to find it! Input Specification: The only line of input contains one number *n* (1<=≤<=*n*<=≤<=105) — the number Luba has got. Output Specification: Output one number — the greatest beautiful divisor of Luba's number. It is obvious that the answer always exists. Demo Input: ['3\n', '992\n'] Demo Output: ['1\n', '496\n'] Note: none
```python import sys input = sys.stdin.readline n = int(input()) s = len(bin(n)[2:]) print(int('0b' + (s+1)//2 * '1' + (s-1)//2 * '0', 2)) ```
0
672
B
Different is Good
PROGRAMMING
1,000
[ "constructive algorithms", "implementation", "strings" ]
null
null
A wise man told Kerem "Different is good" once, so Kerem wants all things in his life to be different. Kerem recently got a string *s* consisting of lowercase English letters. Since Kerem likes it when things are different, he wants all substrings of his string *s* to be distinct. Substring is a string formed by some number of consecutive characters of the string. For example, string "aba" has substrings "" (empty substring), "a", "b", "a", "ab", "ba", "aba". If string *s* has at least two equal substrings then Kerem will change characters at some positions to some other lowercase English letters. Changing characters is a very tiring job, so Kerem want to perform as few changes as possible. Your task is to find the minimum number of changes needed to make all the substrings of the given string distinct, or determine that it is impossible.
The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100<=000) — the length of the string *s*. The second line contains the string *s* of length *n* consisting of only lowercase English letters.
If it's impossible to change the string *s* such that all its substring are distinct print -1. Otherwise print the minimum required number of changes.
[ "2\naa\n", "4\nkoko\n", "5\nmurat\n" ]
[ "1\n", "2\n", "0\n" ]
In the first sample one of the possible solutions is to change the first character to 'b'. In the second sample, one may change the first character to 'a' and second character to 'b', so the string becomes "abko".
1,000
[ { "input": "2\naa", "output": "1" }, { "input": "4\nkoko", "output": "2" }, { "input": "5\nmurat", "output": "0" }, { "input": "6\nacbead", "output": "1" }, { "input": "7\ncdaadad", "output": "4" }, { "input": "25\npeoaicnbisdocqofsqdpgobpn", "output": "12" }, { "input": "25\ntcqpchnqskqjacruoaqilgebu", "output": "7" }, { "input": "13\naebaecedabbee", "output": "8" }, { "input": "27\naaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "-1" }, { "input": "10\nbababbdaee", "output": "6" }, { "input": "11\ndbadcdbdbca", "output": "7" }, { "input": "12\nacceaabddaaa", "output": "7" }, { "input": "13\nabddfbfaeecfa", "output": "7" }, { "input": "14\neeceecacdbcbbb", "output": "9" }, { "input": "15\ndcbceaaggabaheb", "output": "8" }, { "input": "16\nhgiegfbadgcicbhd", "output": "7" }, { "input": "17\nabhfibbdddfghgfdi", "output": "10" }, { "input": "26\nbbbbbabbaababaaabaaababbaa", "output": "24" }, { "input": "26\nahnxdnbfbcrirerssyzydihuee", "output": "11" }, { "input": "26\nhwqeqhkpxwulbsiwmnlfyhgknc", "output": "8" }, { "input": "26\nrvxmulriorilidecqwmfaemifj", "output": "10" }, { "input": "26\naowpmreooavnmamogdoopuisge", "output": "12" }, { "input": "26\ninimevtuefhvuefirdehmmfudh", "output": "15" }, { "input": "26\naaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "25" }, { "input": "27\nqdcfjtblgglnilgassirrjekcjt", "output": "-1" }, { "input": "27\nabcdefghijklmnopqrstuvwxyza", "output": "-1" }, { "input": "26\nqwertyuiopasdfghjklzxcvbnm", "output": "0" }, { "input": "5\nzzzzz", "output": "4" }, { "input": "27\naaaaaaaaaaaaaaaaabaaaaaaaaa", "output": "-1" }, { "input": "1\nq", "output": "0" }, { "input": "27\nqwertyuioplkjhgfdsazxcvbnmm", "output": "-1" }, { "input": "9\nxxxyyyzzz", "output": "6" }, { "input": "45\naaabbbcccdddeeefffgghhiijjkkkkkkkkkkkkkkkkkkk", "output": "-1" }, { "input": "27\nqwertyuiopasdfghjklzxcvbnmm", "output": "-1" }, { "input": "26\nabcdefghijklmnopqrstuvwxyz", "output": "0" }, { "input": "26\nabcdefghijklmnopqrstuvwxya", "output": "1" }, { "input": "27\nabcdefghijklmnopqrstuvwxyzz", "output": "-1" }, { "input": "26\naaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "25" }, { "input": "26\nqwertyuioplkjhgfdsazxcvbnm", "output": "0" }, { "input": "10\nzzzzzzzzzz", "output": "9" }, { "input": "1\na", "output": "0" }, { "input": "30\nabcdefghtyabcdefghtyabcdefghty", "output": "-1" } ]
1,560,587,125
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
n = int(input()) str = input() print(len(str) - len(set(str)) if n < 27 else -1)
Title: Different is Good Time Limit: None seconds Memory Limit: None megabytes Problem Description: A wise man told Kerem "Different is good" once, so Kerem wants all things in his life to be different. Kerem recently got a string *s* consisting of lowercase English letters. Since Kerem likes it when things are different, he wants all substrings of his string *s* to be distinct. Substring is a string formed by some number of consecutive characters of the string. For example, string "aba" has substrings "" (empty substring), "a", "b", "a", "ab", "ba", "aba". If string *s* has at least two equal substrings then Kerem will change characters at some positions to some other lowercase English letters. Changing characters is a very tiring job, so Kerem want to perform as few changes as possible. Your task is to find the minimum number of changes needed to make all the substrings of the given string distinct, or determine that it is impossible. Input Specification: The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100<=000) — the length of the string *s*. The second line contains the string *s* of length *n* consisting of only lowercase English letters. Output Specification: If it's impossible to change the string *s* such that all its substring are distinct print -1. Otherwise print the minimum required number of changes. Demo Input: ['2\naa\n', '4\nkoko\n', '5\nmurat\n'] Demo Output: ['1\n', '2\n', '0\n'] Note: In the first sample one of the possible solutions is to change the first character to 'b'. In the second sample, one may change the first character to 'a' and second character to 'b', so the string becomes "abko".
```python n = int(input()) str = input() print(len(str) - len(set(str)) if n < 27 else -1) ```
-1
415
B
Mashmokh and Tokens
PROGRAMMING
1,500
[ "binary search", "greedy", "implementation", "math" ]
null
null
Bimokh is Mashmokh's boss. For the following *n* days he decided to pay to his workers in a new way. At the beginning of each day he will give each worker a certain amount of tokens. Then at the end of each day each worker can give some of his tokens back to get a certain amount of money. The worker can save the rest of tokens but he can't use it in any other day to get more money. If a worker gives back *w* tokens then he'll get dollars. Mashmokh likes the tokens however he likes money more. That's why he wants to save as many tokens as possible so that the amount of money he gets is maximal possible each day. He has *n* numbers *x*1,<=*x*2,<=...,<=*x**n*. Number *x**i* is the number of tokens given to each worker on the *i*-th day. Help him calculate for each of *n* days the number of tokens he can save.
The first line of input contains three space-separated integers *n*,<=*a*,<=*b* (1<=≤<=*n*<=≤<=105; 1<=≤<=*a*,<=*b*<=≤<=109). The second line of input contains *n* space-separated integers *x*1,<=*x*2,<=...,<=*x**n* (1<=≤<=*x**i*<=≤<=109).
Output *n* space-separated integers. The *i*-th of them is the number of tokens Mashmokh can save on the *i*-th day.
[ "5 1 4\n12 6 11 9 1\n", "3 1 2\n1 2 3\n", "1 1 1\n1\n" ]
[ "0 2 3 1 1 ", "1 0 1 ", "0 " ]
none
1,000
[ { "input": "5 1 4\n12 6 11 9 1", "output": "0 2 3 1 1 " }, { "input": "3 1 2\n1 2 3", "output": "1 0 1 " }, { "input": "1 1 1\n1", "output": "0 " }, { "input": "1 1 1000000000\n1000000000", "output": "0 " }, { "input": "1 1 1000000000\n999999999", "output": "999999999 " }, { "input": "10 1 100000000\n999999999 999999999 999999999 999999999 999999999 999999999 999999999 999999999 999999999 999999999", "output": "99999999 99999999 99999999 99999999 99999999 99999999 99999999 99999999 99999999 99999999 " } ]
1,663,574,294
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
156
4,403,200
n,a,b=map(int,input().split()) ; tokens=list(map(int,input().split())) for i in tokens: dollars=i*a//b ; print(str(i*a%b),end=" ")
Title: Mashmokh and Tokens Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bimokh is Mashmokh's boss. For the following *n* days he decided to pay to his workers in a new way. At the beginning of each day he will give each worker a certain amount of tokens. Then at the end of each day each worker can give some of his tokens back to get a certain amount of money. The worker can save the rest of tokens but he can't use it in any other day to get more money. If a worker gives back *w* tokens then he'll get dollars. Mashmokh likes the tokens however he likes money more. That's why he wants to save as many tokens as possible so that the amount of money he gets is maximal possible each day. He has *n* numbers *x*1,<=*x*2,<=...,<=*x**n*. Number *x**i* is the number of tokens given to each worker on the *i*-th day. Help him calculate for each of *n* days the number of tokens he can save. Input Specification: The first line of input contains three space-separated integers *n*,<=*a*,<=*b* (1<=≤<=*n*<=≤<=105; 1<=≤<=*a*,<=*b*<=≤<=109). The second line of input contains *n* space-separated integers *x*1,<=*x*2,<=...,<=*x**n* (1<=≤<=*x**i*<=≤<=109). Output Specification: Output *n* space-separated integers. The *i*-th of them is the number of tokens Mashmokh can save on the *i*-th day. Demo Input: ['5 1 4\n12 6 11 9 1\n', '3 1 2\n1 2 3\n', '1 1 1\n1\n'] Demo Output: ['0 2 3 1 1 ', '1 0 1 ', '0 '] Note: none
```python n,a,b=map(int,input().split()) ; tokens=list(map(int,input().split())) for i in tokens: dollars=i*a//b ; print(str(i*a%b),end=" ") ```
0
320
A
Magic Numbers
PROGRAMMING
900
[ "brute force", "greedy" ]
null
null
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if it is a magic number or not.
The first line of input contains an integer *n*, (1<=≤<=*n*<=≤<=109). This number doesn't contain leading zeros.
Print "YES" if *n* is a magic number or print "NO" if it's not.
[ "114114\n", "1111\n", "441231\n" ]
[ "YES\n", "YES\n", "NO\n" ]
none
500
[ { "input": "114114", "output": "YES" }, { "input": "1111", "output": "YES" }, { "input": "441231", "output": "NO" }, { "input": "1", "output": "YES" }, { "input": "14", "output": "YES" }, { "input": "114", "output": "YES" }, { "input": "9", "output": "NO" }, { "input": "414", "output": "NO" }, { "input": "1000000000", "output": "NO" }, { "input": "144144144", "output": "YES" }, { "input": "1444", "output": "NO" }, { "input": "11", "output": "YES" }, { "input": "141414141", "output": "YES" }, { "input": "11110111", "output": "NO" }, { "input": "114114144", "output": "YES" }, { "input": "444", "output": "NO" }, { "input": "9999", "output": "NO" }, { "input": "111444", "output": "NO" }, { "input": "11114", "output": "YES" }, { "input": "41111", "output": "NO" }, { "input": "114414441", "output": "NO" }, { "input": "144414441", "output": "NO" }, { "input": "144244144", "output": "NO" }, { "input": "111111111", "output": "YES" }, { "input": "144444444", "output": "NO" }, { "input": "444444444", "output": "NO" }, { "input": "141441441", "output": "YES" }, { "input": "441", "output": "NO" }, { "input": "15", "output": "NO" }, { "input": "14444", "output": "NO" }, { "input": "11444", "output": "NO" }, { "input": "144", "output": "YES" }, { "input": "1414414", "output": "YES" }, { "input": "141444", "output": "NO" }, { "input": "14144", "output": "YES" }, { "input": "4", "output": "NO" }, { "input": "1144", "output": "YES" }, { "input": "141111444", "output": "NO" }, { "input": "14414414", "output": "YES" }, { "input": "141414144", "output": "YES" }, { "input": "1414", "output": "YES" }, { "input": "1441", "output": "YES" }, { "input": "12", "output": "NO" }, { "input": "144144141", "output": "YES" }, { "input": "144144", "output": "YES" }, { "input": "14414411", "output": "YES" }, { "input": "14414", "output": "YES" } ]
1,644,433,486
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
60
0
def solve( n): for i in range(1,len(n)+1): if i != '1' or i != '4': ans = "False" if "444" in n: ans = "False" else: ans = "True" if ans == "True": return True else: return False #Driver n = str(input()) if solve(n): print("YES") else: print("NO")
Title: Magic Numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if it is a magic number or not. Input Specification: The first line of input contains an integer *n*, (1<=≤<=*n*<=≤<=109). This number doesn't contain leading zeros. Output Specification: Print "YES" if *n* is a magic number or print "NO" if it's not. Demo Input: ['114114\n', '1111\n', '441231\n'] Demo Output: ['YES\n', 'YES\n', 'NO\n'] Note: none
```python def solve( n): for i in range(1,len(n)+1): if i != '1' or i != '4': ans = "False" if "444" in n: ans = "False" else: ans = "True" if ans == "True": return True else: return False #Driver n = str(input()) if solve(n): print("YES") else: print("NO") ```
0
639
A
Bear and Displayed Friends
PROGRAMMING
1,200
[ "implementation" ]
null
null
Limak is a little polar bear. He loves connecting with other bears via social networks. He has *n* friends and his relation with the *i*-th of them is described by a unique integer *t**i*. The bigger this value is, the better the friendship is. No two friends have the same value *t**i*. Spring is starting and the Winter sleep is over for bears. Limak has just woken up and logged in. All his friends still sleep and thus none of them is online. Some (maybe all) of them will appear online in the next hours, one at a time. The system displays friends who are online. On the screen there is space to display at most *k* friends. If there are more than *k* friends online then the system displays only *k* best of them — those with biggest *t**i*. Your task is to handle queries of two types: - "1 id" — Friend *id* becomes online. It's guaranteed that he wasn't online before. - "2 id" — Check whether friend *id* is displayed by the system. Print "YES" or "NO" in a separate line. Are you able to help Limak and answer all queries of the second type?
The first line contains three integers *n*, *k* and *q* (1<=≤<=*n*,<=*q*<=≤<=150<=000,<=1<=≤<=*k*<=≤<=*min*(6,<=*n*)) — the number of friends, the maximum number of displayed online friends and the number of queries, respectively. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=109) where *t**i* describes how good is Limak's relation with the *i*-th friend. The *i*-th of the following *q* lines contains two integers *type**i* and *id**i* (1<=≤<=*type**i*<=≤<=2,<=1<=≤<=*id**i*<=≤<=*n*) — the *i*-th query. If *type**i*<==<=1 then a friend *id**i* becomes online. If *type**i*<==<=2 then you should check whether a friend *id**i* is displayed. It's guaranteed that no two queries of the first type will have the same *id**i* becuase one friend can't become online twice. Also, it's guaranteed that at least one query will be of the second type (*type**i*<==<=2) so the output won't be empty.
For each query of the second type print one line with the answer — "YES" (without quotes) if the given friend is displayed and "NO" (without quotes) otherwise.
[ "4 2 8\n300 950 500 200\n1 3\n2 4\n2 3\n1 1\n1 2\n2 1\n2 2\n2 3\n", "6 3 9\n50 20 51 17 99 24\n1 3\n1 4\n1 5\n1 2\n2 4\n2 2\n1 1\n2 4\n2 3\n" ]
[ "NO\nYES\nNO\nYES\nYES\n", "NO\nYES\nNO\nYES\n" ]
In the first sample, Limak has 4 friends who all sleep initially. At first, the system displays nobody because nobody is online. There are the following 8 queries: 1. "1 3" — Friend 3 becomes online. 1. "2 4" — We should check if friend 4 is displayed. He isn't even online and thus we print "NO". 1. "2 3" — We should check if friend 3 is displayed. Right now he is the only friend online and the system displays him. We should print "YES". 1. "1 1" — Friend 1 becomes online. The system now displays both friend 1 and friend 3. 1. "1 2" — Friend 2 becomes online. There are 3 friends online now but we were given *k* = 2 so only two friends can be displayed. Limak has worse relation with friend 1 than with other two online friends (*t*<sub class="lower-index">1</sub> &lt; *t*<sub class="lower-index">2</sub>, *t*<sub class="lower-index">3</sub>) so friend 1 won't be displayed 1. "2 1" — Print "NO". 1. "2 2" — Print "YES". 1. "2 3" — Print "YES".
500
[ { "input": "4 2 8\n300 950 500 200\n1 3\n2 4\n2 3\n1 1\n1 2\n2 1\n2 2\n2 3", "output": "NO\nYES\nNO\nYES\nYES" }, { "input": "6 3 9\n50 20 51 17 99 24\n1 3\n1 4\n1 5\n1 2\n2 4\n2 2\n1 1\n2 4\n2 3", "output": "NO\nYES\nNO\nYES" }, { "input": "6 3 10\n62417580 78150524 410053501 582708235 630200761 760672946\n2 2\n1 5\n1 2\n1 4\n2 4\n2 1\n2 1\n1 6\n2 5\n2 6", "output": "NO\nYES\nNO\nNO\nYES\nYES" }, { "input": "20 2 15\n12698951 55128070 116962690 156763505 188535242 194018601 269939893 428710623 442819431 483000923 516768937 552903993 633087286 656092270 671535141 714291344 717660646 846508634 879748146 937368929\n2 7\n1 2\n2 4\n1 19\n1 12\n1 5\n2 18\n2 11\n1 16\n2 1\n2 3\n2 19\n1 17\n2 9\n2 6", "output": "NO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO" }, { "input": "1 1 1\n1000000000\n2 1", "output": "NO" } ]
1,461,705,414
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
9
2,000
17,203,200
limak = list(map(int,input().split())) friends = limak[0] online = limak[1] queries = limak[2] relation = list(map(int,input().split())) list_onl = dict() for i in range(queries): query = list(map(int,input().split())) if (query[0] == 1): list_onl[relation[query[1]-1]] = query[1] # inserto el amigo online if (len(list_onl) > online): del(list_onl[min(list_onl.keys())]) # elimino el peor amigo elif (query[0] == 2): if (query[1] in list_onl.values()): print("YES") else: print("NO")
Title: Bear and Displayed Friends Time Limit: None seconds Memory Limit: None megabytes Problem Description: Limak is a little polar bear. He loves connecting with other bears via social networks. He has *n* friends and his relation with the *i*-th of them is described by a unique integer *t**i*. The bigger this value is, the better the friendship is. No two friends have the same value *t**i*. Spring is starting and the Winter sleep is over for bears. Limak has just woken up and logged in. All his friends still sleep and thus none of them is online. Some (maybe all) of them will appear online in the next hours, one at a time. The system displays friends who are online. On the screen there is space to display at most *k* friends. If there are more than *k* friends online then the system displays only *k* best of them — those with biggest *t**i*. Your task is to handle queries of two types: - "1 id" — Friend *id* becomes online. It's guaranteed that he wasn't online before. - "2 id" — Check whether friend *id* is displayed by the system. Print "YES" or "NO" in a separate line. Are you able to help Limak and answer all queries of the second type? Input Specification: The first line contains three integers *n*, *k* and *q* (1<=≤<=*n*,<=*q*<=≤<=150<=000,<=1<=≤<=*k*<=≤<=*min*(6,<=*n*)) — the number of friends, the maximum number of displayed online friends and the number of queries, respectively. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=109) where *t**i* describes how good is Limak's relation with the *i*-th friend. The *i*-th of the following *q* lines contains two integers *type**i* and *id**i* (1<=≤<=*type**i*<=≤<=2,<=1<=≤<=*id**i*<=≤<=*n*) — the *i*-th query. If *type**i*<==<=1 then a friend *id**i* becomes online. If *type**i*<==<=2 then you should check whether a friend *id**i* is displayed. It's guaranteed that no two queries of the first type will have the same *id**i* becuase one friend can't become online twice. Also, it's guaranteed that at least one query will be of the second type (*type**i*<==<=2) so the output won't be empty. Output Specification: For each query of the second type print one line with the answer — "YES" (without quotes) if the given friend is displayed and "NO" (without quotes) otherwise. Demo Input: ['4 2 8\n300 950 500 200\n1 3\n2 4\n2 3\n1 1\n1 2\n2 1\n2 2\n2 3\n', '6 3 9\n50 20 51 17 99 24\n1 3\n1 4\n1 5\n1 2\n2 4\n2 2\n1 1\n2 4\n2 3\n'] Demo Output: ['NO\nYES\nNO\nYES\nYES\n', 'NO\nYES\nNO\nYES\n'] Note: In the first sample, Limak has 4 friends who all sleep initially. At first, the system displays nobody because nobody is online. There are the following 8 queries: 1. "1 3" — Friend 3 becomes online. 1. "2 4" — We should check if friend 4 is displayed. He isn't even online and thus we print "NO". 1. "2 3" — We should check if friend 3 is displayed. Right now he is the only friend online and the system displays him. We should print "YES". 1. "1 1" — Friend 1 becomes online. The system now displays both friend 1 and friend 3. 1. "1 2" — Friend 2 becomes online. There are 3 friends online now but we were given *k* = 2 so only two friends can be displayed. Limak has worse relation with friend 1 than with other two online friends (*t*<sub class="lower-index">1</sub> &lt; *t*<sub class="lower-index">2</sub>, *t*<sub class="lower-index">3</sub>) so friend 1 won't be displayed 1. "2 1" — Print "NO". 1. "2 2" — Print "YES". 1. "2 3" — Print "YES".
```python limak = list(map(int,input().split())) friends = limak[0] online = limak[1] queries = limak[2] relation = list(map(int,input().split())) list_onl = dict() for i in range(queries): query = list(map(int,input().split())) if (query[0] == 1): list_onl[relation[query[1]-1]] = query[1] # inserto el amigo online if (len(list_onl) > online): del(list_onl[min(list_onl.keys())]) # elimino el peor amigo elif (query[0] == 2): if (query[1] in list_onl.values()): print("YES") else: print("NO") ```
0
780
A
Andryusha and Socks
PROGRAMMING
800
[ "implementation" ]
null
null
Andryusha is an orderly boy and likes to keep things in their place. Today he faced a problem to put his socks in the wardrobe. He has *n* distinct pairs of socks which are initially in a bag. The pairs are numbered from 1 to *n*. Andryusha wants to put paired socks together and put them in the wardrobe. He takes the socks one by one from the bag, and for each sock he looks whether the pair of this sock has been already took out of the bag, or not. If not (that means the pair of this sock is still in the bag), he puts the current socks on the table in front of him. Otherwise, he puts both socks from the pair to the wardrobe. Andryusha remembers the order in which he took the socks from the bag. Can you tell him what is the maximum number of socks that were on the table at the same time?
The first line contains the single integer *n* (1<=≤<=*n*<=≤<=105) — the number of sock pairs. The second line contains 2*n* integers *x*1,<=*x*2,<=...,<=*x*2*n* (1<=≤<=*x**i*<=≤<=*n*), which describe the order in which Andryusha took the socks from the bag. More precisely, *x**i* means that the *i*-th sock Andryusha took out was from pair *x**i*. It is guaranteed that Andryusha took exactly two socks of each pair.
Print single integer — the maximum number of socks that were on the table at the same time.
[ "1\n1 1\n", "3\n2 1 1 3 2 3\n" ]
[ "1\n", "2\n" ]
In the first example Andryusha took a sock from the first pair and put it on the table. Then he took the next sock which is from the first pair as well, so he immediately puts both socks to the wardrobe. Thus, at most one sock was on the table at the same time. In the second example Andryusha behaved as follows: - Initially the table was empty, he took out a sock from pair 2 and put it on the table. - Sock (2) was on the table. Andryusha took out a sock from pair 1 and put it on the table. - Socks (1, 2) were on the table. Andryusha took out a sock from pair 1, and put this pair into the wardrobe. - Sock (2) was on the table. Andryusha took out a sock from pair 3 and put it on the table. - Socks (2, 3) were on the table. Andryusha took out a sock from pair 2, and put this pair into the wardrobe. - Sock (3) was on the table. Andryusha took out a sock from pair 3 and put this pair into the wardrobe.
500
[ { "input": "1\n1 1", "output": "1" }, { "input": "3\n2 1 1 3 2 3", "output": "2" }, { "input": "5\n5 1 3 2 4 3 1 2 4 5", "output": "5" }, { "input": "10\n4 2 6 3 4 8 7 1 1 5 2 10 6 8 3 5 10 9 9 7", "output": "6" }, { "input": "50\n30 47 31 38 37 50 36 43 9 23 2 2 15 31 14 49 9 16 6 44 27 14 5 6 3 47 25 26 1 35 3 15 24 19 8 46 49 41 4 26 40 28 42 11 34 35 46 18 7 28 18 40 19 42 4 41 38 48 50 12 29 39 33 17 25 22 22 21 36 45 27 30 20 7 13 29 39 44 21 8 37 45 34 1 20 10 11 17 33 12 43 13 10 16 48 24 32 5 23 32", "output": "25" }, { "input": "50\n1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50", "output": "1" }, { "input": "50\n50 50 49 49 48 48 47 47 46 46 45 45 44 44 43 43 42 42 41 41 40 40 39 39 38 38 37 37 36 36 35 35 34 34 33 33 32 32 31 31 30 30 29 29 28 28 27 27 26 26 25 25 24 24 23 23 22 22 21 21 20 20 19 19 18 18 17 17 16 16 15 15 14 14 13 13 12 12 11 11 10 10 9 9 8 8 7 7 6 6 5 5 4 4 3 3 2 2 1 1", "output": "1" }, { "input": "50\n1 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 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", "output": "50" }, { "input": "50\n50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1", "output": "50" }, { "input": "10\n2 9 4 1 6 7 10 3 1 5 8 6 2 3 10 7 4 8 5 9", "output": "9" } ]
1,563,430,089
2,147,483,647
Python 3
OK
TESTS
56
218
13,619,200
n = int(input()) x = map(int, input().split()) Max = 0 tmp = set() counter = 0 for i in x: if i in tmp: counter -= 1 else: counter += 1 tmp.add(i) if Max < counter: Max = counter print(Max) # CodeForcesian # ♥ # تا خدا بنده نواز است
Title: Andryusha and Socks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Andryusha is an orderly boy and likes to keep things in their place. Today he faced a problem to put his socks in the wardrobe. He has *n* distinct pairs of socks which are initially in a bag. The pairs are numbered from 1 to *n*. Andryusha wants to put paired socks together and put them in the wardrobe. He takes the socks one by one from the bag, and for each sock he looks whether the pair of this sock has been already took out of the bag, or not. If not (that means the pair of this sock is still in the bag), he puts the current socks on the table in front of him. Otherwise, he puts both socks from the pair to the wardrobe. Andryusha remembers the order in which he took the socks from the bag. Can you tell him what is the maximum number of socks that were on the table at the same time? Input Specification: The first line contains the single integer *n* (1<=≤<=*n*<=≤<=105) — the number of sock pairs. The second line contains 2*n* integers *x*1,<=*x*2,<=...,<=*x*2*n* (1<=≤<=*x**i*<=≤<=*n*), which describe the order in which Andryusha took the socks from the bag. More precisely, *x**i* means that the *i*-th sock Andryusha took out was from pair *x**i*. It is guaranteed that Andryusha took exactly two socks of each pair. Output Specification: Print single integer — the maximum number of socks that were on the table at the same time. Demo Input: ['1\n1 1\n', '3\n2 1 1 3 2 3\n'] Demo Output: ['1\n', '2\n'] Note: In the first example Andryusha took a sock from the first pair and put it on the table. Then he took the next sock which is from the first pair as well, so he immediately puts both socks to the wardrobe. Thus, at most one sock was on the table at the same time. In the second example Andryusha behaved as follows: - Initially the table was empty, he took out a sock from pair 2 and put it on the table. - Sock (2) was on the table. Andryusha took out a sock from pair 1 and put it on the table. - Socks (1, 2) were on the table. Andryusha took out a sock from pair 1, and put this pair into the wardrobe. - Sock (2) was on the table. Andryusha took out a sock from pair 3 and put it on the table. - Socks (2, 3) were on the table. Andryusha took out a sock from pair 2, and put this pair into the wardrobe. - Sock (3) was on the table. Andryusha took out a sock from pair 3 and put this pair into the wardrobe.
```python n = int(input()) x = map(int, input().split()) Max = 0 tmp = set() counter = 0 for i in x: if i in tmp: counter -= 1 else: counter += 1 tmp.add(i) if Max < counter: Max = counter print(Max) # CodeForcesian # ♥ # تا خدا بنده نواز است ```
3
474
A
Keyboard
PROGRAMMING
900
[ "implementation" ]
null
null
Our good friend Mole is trying to code a big message. He is typing on an unusual keyboard with characters arranged in following way: Unfortunately Mole is blind, so sometimes it is problem for him to put his hands accurately. He accidentally moved both his hands with one position to the left or to the right. That means that now he presses not a button he wants, but one neighboring button (left or right, as specified in input). We have a sequence of characters he has typed and we want to find the original message.
First line of the input contains one letter describing direction of shifting ('L' or 'R' respectively for left or right). Second line contains a sequence of characters written by Mole. The size of this sequence will be no more than 100. Sequence contains only symbols that appear on Mole's keyboard. It doesn't contain spaces as there is no space on Mole's keyboard. It is guaranteed that even though Mole hands are moved, he is still pressing buttons on keyboard and not hitting outside it.
Print a line that contains the original message.
[ "R\ns;;upimrrfod;pbr\n" ]
[ "allyouneedislove\n" ]
none
500
[ { "input": "R\ns;;upimrrfod;pbr", "output": "allyouneedislove" }, { "input": "R\nwertyuiop;lkjhgfdsxcvbnm,.", "output": "qwertyuiolkjhgfdsazxcvbnm," }, { "input": "L\nzxcvbnm,kjhgfdsaqwertyuio", "output": "xcvbnm,.lkjhgfdswertyuiop" }, { "input": "R\nbubbuduppudup", "output": "vyvvysyooysyo" }, { "input": "L\ngggggggggggggggggggggggggggggggggggggggggg", "output": "hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh" }, { "input": "R\ngggggggggggggggggggggggggggggggggggggggggg", "output": "ffffffffffffffffffffffffffffffffffffffffff" }, { "input": "L\nggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg", "output": "hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh" }, { "input": "R\nggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg", "output": "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" }, { "input": "L\nxgwurenkxkiau,c,vonei.zltazmnkhqtwuogkgvgckvja,z.rhanuy.ybebmzcfwozkwvuuiolaqlgvvvewnbuinrncgjwjdsfw", "output": "cheitrmlclosi.v.bpmro/x;ysx,mljwyeiphlhbhvlbks.x/tjsmiu/unrn,xvgepxlebiiop;sw;hbbbremniomtmvhkekfdge" }, { "input": "L\nuoz.vmks,wxrb,nwcvdzh.m,hwsios.lvu,ktes,,ythddhm.sh,d,c,cfj.wqam,bowofbyx,jathqayhreqvixvbmgdokofmym", "output": "ipx/b,ld.ectn.mevbfxj/,.jedopd/;bi.lyrd..uyjffj,/dj.f.v.vgk/ews,.npepgnuc.ksyjwsujtrwbocbn,hfplpg,u," }, { "input": "R\noedjyrvuw/rn.v.hdwndbiposiewgsn.pnyf;/tsdohp,hrtd/mx,;coj./billd..mwbneohcikrdes/ucjr,wspthleyp,..f,", "output": "iwshtecyq.eb,c,gsqbsvuoiauwqfab,obtdl.rasigomgers.nzmlxih,.vukks,,nqvbwigxujeswa.yxhemqaorgkwtom,,dm" }, { "input": "R\nvgj;o;ijrtfyck,dthccioltcx,crub;oceooognsuvfx/kgo.fbsudv,yod.erdrxhbeiyltxhnrobbb;ydrgroefcr/f;uvdjd", "output": "cfhliluherdtxjmsrgxxuikrxzmxeyvlixwiiifbaycdz.jfi,dvayscmtis,wesezgvwutkrzgbeivvvltsefeiwdxe.dlycshs" }, { "input": "L\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq", "output": "wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww" }, { "input": "L\noooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo", "output": "pppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp" }, { "input": "L\n,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,", "output": "...................................................................................................." }, { "input": "L\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz", "output": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" }, { "input": "R\noooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo", "output": "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii" }, { "input": "R\nwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww", "output": "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq" }, { "input": "R\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "output": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz" }, { "input": "L\nq", "output": "w" }, { "input": "L\no", "output": "p" }, { "input": "L\n,", "output": "." }, { "input": "L\nz", "output": "x" }, { "input": "R\n.", "output": "," }, { "input": "R\no", "output": "i" }, { "input": "R\nw", "output": "q" }, { "input": "R\nx", "output": "z" }, { "input": "R\n,./", "output": "m,." }, { "input": "R\nwertuk;;/", "output": "qweryjll." }, { "input": "L\n..", "output": "//" } ]
1,676,361,369
2,147,483,647
Python 3
OK
TESTS
31
31
0
str1 = input().strip() str2 = input().strip() s = "qwertyuiopasdfghjkl;zxcvbnm,./" msg = "" idx = 1 if str1 == 'L' else -1 for ch in str2: current = s.index(ch) new = s[idx + current] msg += new print(msg)
Title: Keyboard Time Limit: None seconds Memory Limit: None megabytes Problem Description: Our good friend Mole is trying to code a big message. He is typing on an unusual keyboard with characters arranged in following way: Unfortunately Mole is blind, so sometimes it is problem for him to put his hands accurately. He accidentally moved both his hands with one position to the left or to the right. That means that now he presses not a button he wants, but one neighboring button (left or right, as specified in input). We have a sequence of characters he has typed and we want to find the original message. Input Specification: First line of the input contains one letter describing direction of shifting ('L' or 'R' respectively for left or right). Second line contains a sequence of characters written by Mole. The size of this sequence will be no more than 100. Sequence contains only symbols that appear on Mole's keyboard. It doesn't contain spaces as there is no space on Mole's keyboard. It is guaranteed that even though Mole hands are moved, he is still pressing buttons on keyboard and not hitting outside it. Output Specification: Print a line that contains the original message. Demo Input: ['R\ns;;upimrrfod;pbr\n'] Demo Output: ['allyouneedislove\n'] Note: none
```python str1 = input().strip() str2 = input().strip() s = "qwertyuiopasdfghjkl;zxcvbnm,./" msg = "" idx = 1 if str1 == 'L' else -1 for ch in str2: current = s.index(ch) new = s[idx + current] msg += new print(msg) ```
3
80
A
Panoramix's Prediction
PROGRAMMING
800
[ "brute force" ]
A. Panoramix's Prediction
2
256
A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not. The next prime number after *x* is the smallest prime number greater than *x*. For example, the next prime number after 2 is 3, and the next prime number after 3 is 5. Note that there is exactly one next prime number after each number. So 5 is not the next prime number for 2. One cold April morning Panoramix predicted that soon Kakofonix will break free from his straitjacket, and this will be a black day for the residents of the Gallic countryside. Panoramix's prophecy tells that if some day Asterix and Obelix beat exactly *x* Roman soldiers, where *x* is a prime number, and next day they beat exactly *y* Roman soldiers, where *y* is the next prime number after *x*, then it's time to wait for Armageddon, for nothing can shut Kakofonix up while he sings his infernal song. Yesterday the Gauls beat *n* Roman soldiers and it turned out that the number *n* was prime! Today their victims were a troop of *m* Romans (*m*<=&gt;<=*n*). Determine whether the Gauls should wait for the black day after today's victory of Asterix and Obelix?
The first and only input line contains two positive integers — *n* and *m* (2<=≤<=*n*<=&lt;<=*m*<=≤<=50). It is guaranteed that *n* is prime. Pretests contain all the cases with restrictions 2<=≤<=*n*<=&lt;<=*m*<=≤<=4.
Print YES, if *m* is the next prime number after *n*, or NO otherwise.
[ "3 5\n", "7 11\n", "7 9\n" ]
[ "YES", "YES", "NO" ]
none
500
[ { "input": "3 5", "output": "YES" }, { "input": "7 11", "output": "YES" }, { "input": "7 9", "output": "NO" }, { "input": "2 3", "output": "YES" }, { "input": "2 4", "output": "NO" }, { "input": "3 4", "output": "NO" }, { "input": "3 5", "output": "YES" }, { "input": "5 7", "output": "YES" }, { "input": "7 11", "output": "YES" }, { "input": "11 13", "output": "YES" }, { "input": "13 17", "output": "YES" }, { "input": "17 19", "output": "YES" }, { "input": "19 23", "output": "YES" }, { "input": "23 29", "output": "YES" }, { "input": "29 31", "output": "YES" }, { "input": "31 37", "output": "YES" }, { "input": "37 41", "output": "YES" }, { "input": "41 43", "output": "YES" }, { "input": "43 47", "output": "YES" }, { "input": "2 5", "output": "NO" }, { "input": "2 7", "output": "NO" }, { "input": "2 6", "output": "NO" }, { "input": "2 11", "output": "NO" }, { "input": "3 6", "output": "NO" }, { "input": "3 7", "output": "NO" }, { "input": "3 9", "output": "NO" }, { "input": "5 6", "output": "NO" }, { "input": "5 9", "output": "NO" }, { "input": "5 11", "output": "NO" }, { "input": "5 13", "output": "NO" }, { "input": "5 15", "output": "NO" }, { "input": "7 8", "output": "NO" }, { "input": "7 13", "output": "NO" }, { "input": "13 15", "output": "NO" }, { "input": "13 17", "output": "YES" }, { "input": "19 21", "output": "NO" }, { "input": "13 20", "output": "NO" }, { "input": "41 49", "output": "NO" }, { "input": "43 49", "output": "NO" }, { "input": "47 50", "output": "NO" }, { "input": "47 49", "output": "NO" }, { "input": "47 48", "output": "NO" }, { "input": "23 25", "output": "NO" }, { "input": "2 50", "output": "NO" }, { "input": "31 33", "output": "NO" } ]
1,663,946,507
2,147,483,647
Python 3
OK
TESTS
45
92
0
x, y = map(int, input().split()) sieve = [True]*(y+1) for i in range(2, y+1, 1): if not sieve[i]: continue t = 2*i while(t < y+1): sieve[t] = False t += i a = True p = 0 for i in range(x+1, y+1, 1): if sieve[i]: p = i break if p == y: print("YES") else: print("NO")
Title: Panoramix's Prediction Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not. The next prime number after *x* is the smallest prime number greater than *x*. For example, the next prime number after 2 is 3, and the next prime number after 3 is 5. Note that there is exactly one next prime number after each number. So 5 is not the next prime number for 2. One cold April morning Panoramix predicted that soon Kakofonix will break free from his straitjacket, and this will be a black day for the residents of the Gallic countryside. Panoramix's prophecy tells that if some day Asterix and Obelix beat exactly *x* Roman soldiers, where *x* is a prime number, and next day they beat exactly *y* Roman soldiers, where *y* is the next prime number after *x*, then it's time to wait for Armageddon, for nothing can shut Kakofonix up while he sings his infernal song. Yesterday the Gauls beat *n* Roman soldiers and it turned out that the number *n* was prime! Today their victims were a troop of *m* Romans (*m*<=&gt;<=*n*). Determine whether the Gauls should wait for the black day after today's victory of Asterix and Obelix? Input Specification: The first and only input line contains two positive integers — *n* and *m* (2<=≤<=*n*<=&lt;<=*m*<=≤<=50). It is guaranteed that *n* is prime. Pretests contain all the cases with restrictions 2<=≤<=*n*<=&lt;<=*m*<=≤<=4. Output Specification: Print YES, if *m* is the next prime number after *n*, or NO otherwise. Demo Input: ['3 5\n', '7 11\n', '7 9\n'] Demo Output: ['YES', 'YES', 'NO'] Note: none
```python x, y = map(int, input().split()) sieve = [True]*(y+1) for i in range(2, y+1, 1): if not sieve[i]: continue t = 2*i while(t < y+1): sieve[t] = False t += i a = True p = 0 for i in range(x+1, y+1, 1): if sieve[i]: p = i break if p == y: print("YES") else: print("NO") ```
3.977
219
A
k-String
PROGRAMMING
1,000
[ "implementation", "strings" ]
null
null
A string is called a *k*-string if it can be represented as *k* concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string. You are given a string *s*, consisting of lowercase English letters and a positive integer *k*. Your task is to reorder the letters in the string *s* in such a way that the resulting string is a *k*-string.
The first input line contains integer *k* (1<=≤<=*k*<=≤<=1000). The second line contains *s*, all characters in *s* are lowercase English letters. The string length *s* satisfies the inequality 1<=≤<=|*s*|<=≤<=1000, where |*s*| is the length of string *s*.
Rearrange the letters in string *s* in such a way that the result is a *k*-string. Print the result on a single output line. If there are multiple solutions, print any of them. If the solution doesn't exist, print "-1" (without quotes).
[ "2\naazz\n", "3\nabcabcabz\n" ]
[ "azaz\n", "-1\n" ]
none
500
[ { "input": "2\naazz", "output": "azaz" }, { "input": "3\nabcabcabz", "output": "-1" }, { "input": "1\na", "output": "a" }, { "input": "2\nabba", "output": "abab" }, { "input": "2\naaab", "output": "-1" }, { "input": "7\nabacaba", "output": "-1" }, { "input": "5\naaaaa", "output": "aaaaa" }, { "input": "3\naabaaaaabb", "output": "-1" }, { "input": "2\naaab", "output": "-1" }, { "input": "2\nbabac", "output": "-1" }, { "input": "3\nbbbccc", "output": "bcbcbc" }, { "input": "2\naa", "output": "aa" }, { "input": "250\ncececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececece", "output": "cececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececece" }, { "input": "15\nabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaa", "output": "aaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbc" }, { "input": "1\naaa", "output": "aaa" }, { "input": "1\naabaab", "output": "aaaabb" }, { "input": "2\naabbbbccccccdddddddd", "output": "abbcccddddabbcccdddd" }, { "input": "3\naaaaaaaaacccdddddd", "output": "aaacddaaacddaaacdd" }, { "input": "3\naaaaaaaaacccbbbbbb", "output": "aaabbcaaabbcaaabbc" }, { "input": "2\naazzzz", "output": "azzazz" }, { "input": "2\naaaa", "output": "aaaa" }, { "input": "2\naaaazz", "output": "aazaaz" }, { "input": "2\naaaabb", "output": "aabaab" }, { "input": "2\naabbbb", "output": "abbabb" }, { "input": "2\naaaazzzz", "output": "aazzaazz" }, { "input": "2\naaazz", "output": "-1" }, { "input": "2\nbbbbaa", "output": "abbabb" }, { "input": "2\naaaaaabbbb", "output": "aaabbaaabb" }, { "input": "2\naaaaaazz", "output": "aaazaaaz" }, { "input": "2\naaaabbbb", "output": "aabbaabb" }, { "input": "2\naabaab", "output": "aabaab" }, { "input": "1\naaaaa", "output": "aaaaa" }, { "input": "2\nbbaaaa", "output": "aabaab" }, { "input": "2\nacaccc", "output": "accacc" } ]
1,635,342,573
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
92
4,608,000
from collections import Counter k = int(input()) s = input() s_set = list(set(s)) s_set = "".join(s_set) c = Counter(s) if (s_set * k ) == len(s): print(s_set*k) else: print(-1)
Title: k-String Time Limit: None seconds Memory Limit: None megabytes Problem Description: A string is called a *k*-string if it can be represented as *k* concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string. You are given a string *s*, consisting of lowercase English letters and a positive integer *k*. Your task is to reorder the letters in the string *s* in such a way that the resulting string is a *k*-string. Input Specification: The first input line contains integer *k* (1<=≤<=*k*<=≤<=1000). The second line contains *s*, all characters in *s* are lowercase English letters. The string length *s* satisfies the inequality 1<=≤<=|*s*|<=≤<=1000, where |*s*| is the length of string *s*. Output Specification: Rearrange the letters in string *s* in such a way that the result is a *k*-string. Print the result on a single output line. If there are multiple solutions, print any of them. If the solution doesn't exist, print "-1" (without quotes). Demo Input: ['2\naazz\n', '3\nabcabcabz\n'] Demo Output: ['azaz\n', '-1\n'] Note: none
```python from collections import Counter k = int(input()) s = input() s_set = list(set(s)) s_set = "".join(s_set) c = Counter(s) if (s_set * k ) == len(s): print(s_set*k) else: print(-1) ```
0
918
B
Radio Station
PROGRAMMING
900
[ "implementation", "strings" ]
null
null
As the guys fried the radio station facilities, the school principal gave them tasks as a punishment. Dustin's task was to add comments to nginx configuration for school's website. The school has *n* servers. Each server has a name and an ip (names aren't necessarily unique, but ips are). Dustin knows the ip and name of each server. For simplicity, we'll assume that an nginx command is of form "command ip;" where command is a string consisting of English lowercase letter only, and ip is the ip of one of school servers. Each ip is of form "a.b.c.d" where *a*, *b*, *c* and *d* are non-negative integers less than or equal to 255 (with no leading zeros). The nginx configuration file Dustin has to add comments to has *m* commands. Nobody ever memorizes the ips of servers, so to understand the configuration better, Dustin has to comment the name of server that the ip belongs to at the end of each line (after each command). More formally, if a line is "command ip;" Dustin has to replace it with "command ip; #name" where name is the name of the server with ip equal to ip. Dustin doesn't know anything about nginx, so he panicked again and his friends asked you to do his task for him.
The first line of input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000). The next *n* lines contain the names and ips of the servers. Each line contains a string name, name of the server and a string ip, ip of the server, separated by space (1<=≤<=|*name*|<=≤<=10, *name* only consists of English lowercase letters). It is guaranteed that all ip are distinct. The next *m* lines contain the commands in the configuration file. Each line is of form "command ip;" (1<=≤<=|*command*|<=≤<=10, command only consists of English lowercase letters). It is guaranteed that ip belongs to one of the *n* school servers.
Print *m* lines, the commands in the configuration file after Dustin did his task.
[ "2 2\nmain 192.168.0.2\nreplica 192.168.0.1\nblock 192.168.0.1;\nproxy 192.168.0.2;\n", "3 5\ngoogle 8.8.8.8\ncodeforces 212.193.33.27\nserver 138.197.64.57\nredirect 138.197.64.57;\nblock 8.8.8.8;\ncf 212.193.33.27;\nunblock 8.8.8.8;\ncheck 138.197.64.57;\n" ]
[ "block 192.168.0.1; #replica\nproxy 192.168.0.2; #main\n", "redirect 138.197.64.57; #server\nblock 8.8.8.8; #google\ncf 212.193.33.27; #codeforces\nunblock 8.8.8.8; #google\ncheck 138.197.64.57; #server\n" ]
none
1,000
[ { "input": "2 2\nmain 192.168.0.2\nreplica 192.168.0.1\nblock 192.168.0.1;\nproxy 192.168.0.2;", "output": "block 192.168.0.1; #replica\nproxy 192.168.0.2; #main" }, { "input": "3 5\ngoogle 8.8.8.8\ncodeforces 212.193.33.27\nserver 138.197.64.57\nredirect 138.197.64.57;\nblock 8.8.8.8;\ncf 212.193.33.27;\nunblock 8.8.8.8;\ncheck 138.197.64.57;", "output": "redirect 138.197.64.57; #server\nblock 8.8.8.8; #google\ncf 212.193.33.27; #codeforces\nunblock 8.8.8.8; #google\ncheck 138.197.64.57; #server" }, { "input": "10 10\nittmcs 112.147.123.173\njkt 228.40.73.178\nfwckqtz 88.28.31.198\nkal 224.226.34.213\nnacuyokm 49.57.13.44\nfouynv 243.18.250.17\ns 45.248.83.247\ne 75.69.23.169\nauwoqlch 100.44.219.187\nlkldjq 46.123.169.140\ngjcylatwzi 46.123.169.140;\ndxfi 88.28.31.198;\ngv 46.123.169.140;\nety 88.28.31.198;\notbmgcrn 46.123.169.140;\nw 112.147.123.173;\np 75.69.23.169;\nvdsnigk 46.123.169.140;\nmmc 46.123.169.140;\ngtc 49.57.13.44;", "output": "gjcylatwzi 46.123.169.140; #lkldjq\ndxfi 88.28.31.198; #fwckqtz\ngv 46.123.169.140; #lkldjq\nety 88.28.31.198; #fwckqtz\notbmgcrn 46.123.169.140; #lkldjq\nw 112.147.123.173; #ittmcs\np 75.69.23.169; #e\nvdsnigk 46.123.169.140; #lkldjq\nmmc 46.123.169.140; #lkldjq\ngtc 49.57.13.44; #nacuyokm" }, { "input": "1 1\nervbfot 185.32.99.2\nzygoumbmx 185.32.99.2;", "output": "zygoumbmx 185.32.99.2; #ervbfot" }, { "input": "1 2\ny 245.182.246.189\nlllq 245.182.246.189;\nxds 245.182.246.189;", "output": "lllq 245.182.246.189; #y\nxds 245.182.246.189; #y" }, { "input": "2 1\ntdwmshz 203.115.124.110\neksckjya 201.80.191.212\nzbtjzzue 203.115.124.110;", "output": "zbtjzzue 203.115.124.110; #tdwmshz" }, { "input": "8 5\nfhgkq 5.19.189.178\nphftablcr 75.18.177.178\nxnpcg 158.231.167.176\ncfahrkq 26.165.124.191\nfkgtnqtfoh 230.13.13.129\nt 101.24.94.85\nvjoirslx 59.6.179.72\ntwktmskb 38.194.117.184\nrvzzlygosc 26.165.124.191;\ndcsgxrkgv 101.24.94.85;\nyvmyppn 59.6.179.72;\ngpdjjuq 75.18.177.178;\nvdviz 101.24.94.85;", "output": "rvzzlygosc 26.165.124.191; #cfahrkq\ndcsgxrkgv 101.24.94.85; #t\nyvmyppn 59.6.179.72; #vjoirslx\ngpdjjuq 75.18.177.178; #phftablcr\nvdviz 101.24.94.85; #t" }, { "input": "2 1\nmain 1.1.1.1\nget 11.1.1.1\ncommand 11.1.1.1;", "output": "command 11.1.1.1; #get" }, { "input": "2 2\nmain 0.0.0.255\nmainn 0.0.2.55\nblock 0.0.0.255;\nblock 0.0.2.55;", "output": "block 0.0.0.255; #main\nblock 0.0.2.55; #mainn" }, { "input": "2 2\nmain 0.0.63.0\nreplica 0.38.0.56\nblock 0.0.63.0;\nproxy 0.38.0.56;", "output": "block 0.0.63.0; #main\nproxy 0.38.0.56; #replica" }, { "input": "2 2\nmain 192.168.10.12\nreplica 192.167.10.12\nblock 192.168.10.12;\nproxy 192.167.10.12;", "output": "block 192.168.10.12; #main\nproxy 192.167.10.12; #replica" }, { "input": "2 1\nneserver 185.218.47.91\nserver 255.255.255.255\nblock 255.255.255.255;", "output": "block 255.255.255.255; #server" }, { "input": "2 1\nalp 22.222.30.10\nbet 222.22.30.10\nblock 22.222.30.10;", "output": "block 22.222.30.10; #alp" } ]
1,681,449,290
2,147,483,647
Python 3
OK
TESTS
28
46
0
n, m = map(lambda x: int(x), input().split()) d = {} while n != 0: n -= 1 s = input().split() d[s[1]] = s[0] while m != 0: m -= 1 l = input().split() l.append('#' + d[l[1][:-1]]) print(' '.join(l))
Title: Radio Station Time Limit: None seconds Memory Limit: None megabytes Problem Description: As the guys fried the radio station facilities, the school principal gave them tasks as a punishment. Dustin's task was to add comments to nginx configuration for school's website. The school has *n* servers. Each server has a name and an ip (names aren't necessarily unique, but ips are). Dustin knows the ip and name of each server. For simplicity, we'll assume that an nginx command is of form "command ip;" where command is a string consisting of English lowercase letter only, and ip is the ip of one of school servers. Each ip is of form "a.b.c.d" where *a*, *b*, *c* and *d* are non-negative integers less than or equal to 255 (with no leading zeros). The nginx configuration file Dustin has to add comments to has *m* commands. Nobody ever memorizes the ips of servers, so to understand the configuration better, Dustin has to comment the name of server that the ip belongs to at the end of each line (after each command). More formally, if a line is "command ip;" Dustin has to replace it with "command ip; #name" where name is the name of the server with ip equal to ip. Dustin doesn't know anything about nginx, so he panicked again and his friends asked you to do his task for him. Input Specification: The first line of input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000). The next *n* lines contain the names and ips of the servers. Each line contains a string name, name of the server and a string ip, ip of the server, separated by space (1<=≤<=|*name*|<=≤<=10, *name* only consists of English lowercase letters). It is guaranteed that all ip are distinct. The next *m* lines contain the commands in the configuration file. Each line is of form "command ip;" (1<=≤<=|*command*|<=≤<=10, command only consists of English lowercase letters). It is guaranteed that ip belongs to one of the *n* school servers. Output Specification: Print *m* lines, the commands in the configuration file after Dustin did his task. Demo Input: ['2 2\nmain 192.168.0.2\nreplica 192.168.0.1\nblock 192.168.0.1;\nproxy 192.168.0.2;\n', '3 5\ngoogle 8.8.8.8\ncodeforces 212.193.33.27\nserver 138.197.64.57\nredirect 138.197.64.57;\nblock 8.8.8.8;\ncf 212.193.33.27;\nunblock 8.8.8.8;\ncheck 138.197.64.57;\n'] Demo Output: ['block 192.168.0.1; #replica\nproxy 192.168.0.2; #main\n', 'redirect 138.197.64.57; #server\nblock 8.8.8.8; #google\ncf 212.193.33.27; #codeforces\nunblock 8.8.8.8; #google\ncheck 138.197.64.57; #server\n'] Note: none
```python n, m = map(lambda x: int(x), input().split()) d = {} while n != 0: n -= 1 s = input().split() d[s[1]] = s[0] while m != 0: m -= 1 l = input().split() l.append('#' + d[l[1][:-1]]) print(' '.join(l)) ```
3
802
G
Fake News (easy)
PROGRAMMING
800
[ "implementation", "strings" ]
null
null
As it's the first of April, Heidi is suspecting that the news she reads today are fake, and she does not want to look silly in front of all the contestants. She knows that a newspiece is fake if it contains heidi as a subsequence. Help Heidi assess whether the given piece is true, but please be discreet about it...
The first and only line of input contains a single nonempty string *s* of length at most 1000 composed of lowercase letters (a-z).
Output YES if the string *s* contains heidi as a subsequence and NO otherwise.
[ "abcheaibcdi\n", "hiedi\n" ]
[ "YES", "NO" ]
A string *s* contains another string *p* as a subsequence if it is possible to delete some characters from *s* and obtain *p*.
0
[ { "input": "abcheaibcdi", "output": "YES" }, { "input": "hiedi", "output": "NO" }, { "input": "ihied", "output": "NO" }, { "input": "diehi", "output": "NO" }, { "input": "deiih", "output": "NO" }, { "input": "iheid", "output": "NO" }, { "input": "eihdi", "output": "NO" }, { "input": "ehdii", "output": "NO" }, { "input": "edhii", "output": "NO" }, { "input": "deiih", "output": "NO" }, { "input": "ehdii", "output": "NO" }, { "input": "eufyajkssayhjhqcwxmctecaeepjwmfoscqprpcxsqfwnlgzsmmuwuoruantipholrauvxydfvftwfzhnckxswussvlidcojiciflpvkcxkkcmmvtfvxrkwcpeelwsuzqgamamdtdgzscmikvojfvqehblmjczkvtdeymgertgkwfwfukafqlfdhtedcctixhyetdypswgagrpyto", "output": "YES" }, { "input": "arfbvxgdvqzuloojjrwoyqqbxamxybaqltfimofulusfebodjkwwrgwcppkwiodtpjaraglyplgerrpqjkpoggjmfxhwtqrijpijrcyxnoodvwpyjfpvqaoazllbrpzananbrvvybboedidtuvqquklkpeflfaltukjhzjgiofombhbmqbihgtapswykfvlgdoapjqntvqsaohmbvnphvyyhvhavslamczuqifxnwknkaenqmlvetrqogqxmlptgrmqvxzdxdmwobjesmgxckpmawtioavwdngyiwkzypfnxcovwzdohshwlavwsthdssiadhiwmhpvgkrbezm", "output": "YES" }, { "input": "zcectngbqnejjjtsfrluummmqabzqbyccshjqbrjthzhlbmzjfxugvjouwhumsgrnopiyakfadjnbsesamhynsbfbfunupwbxvohfmpwlcpxhovwpfpciclatgmiufwdvtsqrsdcymvkldpnhfeisrzhyhhlkwdzthgprvkpyldeysvbmcibqkpudyrraqdlxpjecvwcvuiklcrsbgvqasmxmtxqzmawcjtozioqlfflinnxpeexbzloaeqjvglbdeufultpjqexvjjjkzemtzuzmxvawilcqdrcjzpqyhtwfphuonzwkotthsaxrmwtnlmcdylxqcfffyndqeouztluqwlhnkkvzwcfiscikv", "output": "YES" }, { "input": "plqaykgovxkvsiahdbglktdlhcqwelxxmtlyymrsyubxdskvyjkrowvcbpdofpjqspsrgpakdczletxujzlsegepzleipiyycpinzxgwjsgslnxsotouddgfcybozfpjhhocpybfjbaywsehbcfrayvancbrumdfngqytnhihyxnlvilrqyhnxeckprqafofelospffhtwguzjbbjlzbqrtiielbvzutzgpqxosiaqznndgobcluuqlhmffiowkjdlkokehtjdyjvmxsiyxureflmdomerfekxdvtitvwzmdsdzplkpbtafxqfpudnhfqpoiwvjnylanunmagoweobdvfjgepbsymfutrjarlxclhgavpytiiqwvojrptofuvlohzeguxdsrihsbucelhhuedltnnjgzxwyblbqvnoliiydfinzlogbvucwykryzcyibnniggbkdkdcdgcsbvvnavtyhtkanrblpvomvjs", "output": "YES" }, { "input": "fbldqzggeunkpwcfirxanmntbfrudijltoertsdvcvcmbwodbibsrxendzebvxwydpasaqnisrijctsuatihxxygbeovhxjdptdcppkvfytdpjspvrannxavmkmisqtygntxkdlousdypyfkrpzapysfpdbyprufwzhunlsfugojddkmxzinatiwfxdqmgyrnjnxvrclhxyuwxtshoqdjptmeecvgmrlvuwqtmnfnfeeiwcavwnqmyustawbjodzwsqmnjxhpqmgpysierlwbbdzcwprpsexyvreewcmlbvaiytjlxdqdaqftefdlmtmmjcwvfejshymhnouoshdzqcwzxpzupkbcievodzqkqvyjuuxxwepxjalvkzufnveji", "output": "YES" }, { "input": "htsyljgoelbbuipivuzrhmfpkgderqpoprlxdpasxhpmxvaztccldtmujjzjmcpdvsdghzpretlsyyiljhjznseaacruriufswuvizwwuvdioazophhyytvbiogttnnouauxllbdn", "output": "YES" }, { "input": "ikmxzqdzxqlvgeojsnhqzciujslwjyzzexnregabdqztpplosdakimjxmuqccbnwvzbajoiqgdobccwnrwmixohrbdarhoeeelzbpigiybtesybwefpcfx", "output": "YES" }, { "input": "bpvbpjvbdfiodsmahxpcubjxdykesubnypalhypantshkjffmxjmelblqnjdmtaltneuyudyevkgedkqrdmrfeemgpghwrifcwincfixokfgurhqbcfzeajrgkgpwqwsepudxulywowwxzdxkumsicsvnzfxspmjpaixgejeaoyoibegosqoyoydmphfpbutrrewyjecowjckvpcceoamtfbitdneuwqfvnagswlskmsmkhmxyfsrpqwhxzocyffiumcy", "output": "YES" }, { "input": "vllsexwrazvlfvhvrtqeohvzzresjdiuhomfpgqcxpqdevplecuaepixhlijatxzegciizpvyvxuembiplwklahlqibykfideysjygagjbgqkbhdhkatddcwlxboinfuomnpc", "output": "YES" }, { "input": "pnjdwpxmvfoqkjtbhquqcuredrkwqzzfjmdvpnbqtypzdovemhhclkvigjvtprrpzbrbcbatkucaqteuciuozytsptvsskkeplaxdaqmjkmef", "output": "NO" }, { "input": "jpwfhvlxvsdhtuozvlmnfiotrgapgjxtcsgcjnodcztupysvvvmjpzqkpommadppdrykuqkcpzojcwvlogvkddedwbggkrhuvtsvdiokehlkdlnukcufjvqxnikcdawvexxwffxtriqbdmkahxdtygodzohwtdmmuvmatdkvweqvaehaxiefpevkvqpyxsrhtmgjsdfcwzqobibeduooldrmglbinrepmunizheqzvgqvpdskhxfidxfnbisyizhepwyrcykcmjxnkyfjgrqlkixcvysa", "output": "YES" }, { "input": "aftcrvuumeqbfvaqlltscnuhkpcifrrhnutjinxdhhdbzvizlrapzjdatuaynoplgjketupgaejciosofuhcgcjdcucarfvtsofgubtphijciswsvidnvpztlaarydkeqxzwdhfbmullkimerukusbrdnnujviydldrwhdfllsjtziwfeaiqotbiprespmxjulnyunkdtcghrzvhtcychkwatqqmladxpvmvlkzscthylbzkpgwlzfjqwarqvdeyngekqvrhrftpxnkfcibbowvnqdkulcdydspcubwlgoyinpnzgidbgunparnueddzwtzdiavbprbbg", "output": "YES" }, { "input": "oagjghsidigeh", "output": "NO" }, { "input": "chdhzpfzabupskiusjoefrwmjmqkbmdgboicnszkhdrlegeqjsldurmbshijadlwsycselhlnudndpdhcnhruhhvsgbthpruiqfirxkhpqhzhqdfpyozolbionodypfcqfeqbkcgmqkizgeyyelzeoothexcoaahedgrvoemqcwccbvoeqawqeuusyjxmgjkpfwcdttfmwunzuwvsihliexlzygqcgpbdiawfvqukikhbjerjkyhpcknlndaystrgsinghlmekbvhntcpypmchcwoglsmwwdulqneuabuuuvtyrnjxfcgoothalwkzzfxakneusezgnnepkpipzromqubraiggqndliz", "output": "YES" }, { "input": "lgirxqkrkgjcutpqitmffvbujcljkqardlalyigxorscczuzikoylcxenryhskoavymexysvmhbsvhtycjlmzhijpuvcjshyfeycvvcfyzytzoyvxajpqdjtfiatnvxnyeqtfcagfftafllhhjhplbdsrfpctkqpinpdfrtlzyjllfbeffputywcckupyslkbbzpgcnxgbmhtqeqqehpdaokkjtatrhyiuusjhwgiiiikxpzdueasemosmmccoakafgvxduwiuflovhhfhffgnnjhoperhhjtvocpqytjxkmrknnknqeglffhfuplopmktykxuvcmbwpoeisrlyyhdpxfvzseucofyhziuiikihpqheqdyzwigeaqzhxzvporgisxgvhyicqyejovqloibhbunsvsunpvmdckkbuokitdzleilfwutcvuuytpupizinfjrzhxudsmjcjyfcpfgthujjowdwtgbvi", "output": "YES" }, { "input": "uuehrvufgerqbzyzksmqnewacotuimawhlbycdbsmhshrsbqwybbkwjwsrkwptvlbbwjiivqugzrxxwgidrcrhrwsmwgeoleptfamzefgaeyxouxocrpvomjrazmxrnffdwrrmblgdiabdncvfougtmjgvvazasnygdrigbsrieoonirlivfyodvulouslxosswgpdexuldmkdbpdlgutiotvxjyecbrsvbmqxrlcpcipjjncduyqtohlzybvlemmfdeubihwlwqglkgjvnwrbgydcpwklmjeewqklmqdbajqgrpnynaxfvxjzgibqerxyhnxenrmcdqaaeksbzyrcaepozqpetaurlhjuxxhwppuhgoihxdxbmxeiahyaqkbknktlzkheaarjoqqrsyeducvoygwalgarldcdlqogfvsncejssmx", "output": "YES" }, { "input": "iiopulfjxoitgiusqrhgbkiyzinphjtclodbkkydetylvuimkhdkklmyoacmekdvjpuxcrvqnjhqhhbfenlpzpwijtykqziocilvtpqhxuyrphdlamawjuzgjwiebkqyrzyqgtkcrhntjxqmcgkrqcslogjegfrivzidfedeegwbbsopvxvdoididlpypjogxaodtueebbwuwilacunqpozczcgrpaxxrtogpxgfkudtxchoravrrdtimhenwmnafxaruuojduxxglefejycfcyxllfimkszmbrhcwpnwjqgwvzysmlaaifdxfjjpgjmcksiigpanappjdloiolojmcqbnpnjjzaufdpjaknylmyvolhwypygwepmqwpiglpcnpypnudhdzpdvgzosyjthzcwtytxq", "output": "YES" } ]
1,666,768,141
2,147,483,647
Python 3
OK
TESTS
58
46
0
s = input() heidi = 'heidi#' cnt = 0 n = len(s) for i in range(n): if heidi[cnt] == s[i]: cnt += 1 if cnt ==5: print("YES") else: print("NO")
Title: Fake News (easy) Time Limit: None seconds Memory Limit: None megabytes Problem Description: As it's the first of April, Heidi is suspecting that the news she reads today are fake, and she does not want to look silly in front of all the contestants. She knows that a newspiece is fake if it contains heidi as a subsequence. Help Heidi assess whether the given piece is true, but please be discreet about it... Input Specification: The first and only line of input contains a single nonempty string *s* of length at most 1000 composed of lowercase letters (a-z). Output Specification: Output YES if the string *s* contains heidi as a subsequence and NO otherwise. Demo Input: ['abcheaibcdi\n', 'hiedi\n'] Demo Output: ['YES', 'NO'] Note: A string *s* contains another string *p* as a subsequence if it is possible to delete some characters from *s* and obtain *p*.
```python s = input() heidi = 'heidi#' cnt = 0 n = len(s) for i in range(n): if heidi[cnt] == s[i]: cnt += 1 if cnt ==5: print("YES") else: print("NO") ```
3
586
A
Alena's Schedule
PROGRAMMING
900
[ "implementation" ]
null
null
Alena has successfully passed the entrance exams to the university and is now looking forward to start studying. One two-hour lesson at the Russian university is traditionally called a pair, it lasts for two academic hours (an academic hour is equal to 45 minutes). The University works in such a way that every day it holds exactly *n* lessons. Depending on the schedule of a particular group of students, on a given day, some pairs may actually contain classes, but some may be empty (such pairs are called breaks). The official website of the university has already published the schedule for tomorrow for Alena's group. Thus, for each of the *n* pairs she knows if there will be a class at that time or not. Alena's House is far from the university, so if there are breaks, she doesn't always go home. Alena has time to go home only if the break consists of at least two free pairs in a row, otherwise she waits for the next pair at the university. Of course, Alena does not want to be sleepy during pairs, so she will sleep as long as possible, and will only come to the first pair that is presented in her schedule. Similarly, if there are no more pairs, then Alena immediately goes home. Alena appreciates the time spent at home, so she always goes home when it is possible, and returns to the university only at the beginning of the next pair. Help Alena determine for how many pairs she will stay at the university. Note that during some pairs Alena may be at the university waiting for the upcoming pair.
The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of lessons at the university. The second line contains *n* numbers *a**i* (0<=≤<=*a**i*<=≤<=1). Number *a**i* equals 0, if Alena doesn't have the *i*-th pairs, otherwise it is equal to 1. Numbers *a*1,<=*a*2,<=...,<=*a**n* are separated by spaces.
Print a single number — the number of pairs during which Alena stays at the university.
[ "5\n0 1 0 1 1\n", "7\n1 0 1 0 0 1 0\n", "1\n0\n" ]
[ "4\n", "4\n", "0\n" ]
In the first sample Alena stays at the university from the second to the fifth pair, inclusive, during the third pair she will be it the university waiting for the next pair. In the last sample Alena doesn't have a single pair, so she spends all the time at home.
500
[ { "input": "5\n0 1 0 1 1", "output": "4" }, { "input": "7\n1 0 1 0 0 1 0", "output": "4" }, { "input": "1\n0", "output": "0" }, { "input": "1\n1", "output": "1" }, { "input": "2\n0 0", "output": "0" }, { "input": "2\n0 1", "output": "1" }, { "input": "2\n1 0", "output": "1" }, { "input": "2\n1 1", "output": "2" }, { "input": "10\n0 0 0 0 0 0 0 0 0 0", "output": "0" }, { "input": "9\n1 1 1 1 1 1 1 1 1", "output": "9" }, { "input": "11\n0 0 0 0 0 0 0 0 0 0 1", "output": "1" }, { "input": "12\n1 0 0 0 0 0 0 0 0 0 0 0", "output": "1" }, { "input": "20\n1 1 0 1 1 1 1 1 1 1 1 0 1 1 1 0 0 1 0 0", "output": "16" }, { "input": "41\n1 1 0 1 0 1 0 0 1 0 1 1 1 0 0 0 1 1 1 0 1 0 1 1 0 1 0 1 0 0 0 0 0 0 1 0 0 1 0 1 1", "output": "28" }, { "input": "63\n1 1 0 1 1 0 0 0 1 1 0 0 1 1 1 1 0 1 1 0 1 0 1 1 1 1 1 0 0 0 0 0 0 1 0 0 1 0 0 1 0 1 1 0 0 1 1 0 0 1 1 1 1 0 0 1 1 0 0 1 0 1 0", "output": "39" }, { "input": "80\n0 1 1 1 0 1 1 1 1 1 0 0 1 0 1 1 0 1 1 1 0 1 1 1 1 0 1 0 1 0 0 0 1 1 0 1 1 0 0 0 0 1 1 1 0 0 0 1 0 0 1 1 1 0 0 0 0 0 0 1 0 1 0 0 1 0 1 1 1 1 1 0 0 0 1 1 0 0 1 1", "output": "52" }, { "input": "99\n1 1 0 0 0 1 0 0 1 1 1 1 0 0 0 1 0 1 1 0 1 1 1 1 0 0 0 0 1 1 1 1 0 1 0 1 0 1 1 1 0 0 1 1 1 0 0 0 1 1 1 0 1 1 1 0 1 0 0 1 1 0 1 0 0 1 1 1 1 0 0 1 1 0 0 1 0 1 1 1 0 1 1 0 1 0 0 1 0 1 0 1 0 1 1 0 1 0 1", "output": "72" }, { "input": "100\n0 1 1 0 1 1 0 0 1 1 0 1 1 1 1 1 0 0 1 1 1 0 0 0 0 1 1 0 0 1 0 0 1 0 0 0 0 1 1 1 1 1 1 0 0 1 1 0 0 0 0 1 0 1 1 1 0 1 1 0 1 0 0 0 0 0 1 0 1 1 0 0 1 1 0 1 1 0 0 1 1 1 0 1 1 1 1 1 1 0 0 1 1 1 1 0 1 1 1 0", "output": "65" }, { "input": "11\n0 1 1 0 0 0 0 0 0 0 0", "output": "2" }, { "input": "11\n0 1 0 1 0 0 1 1 0 1 1", "output": "8" }, { "input": "11\n1 0 1 0 1 1 0 1 1 1 0", "output": "10" }, { "input": "11\n1 0 0 0 0 0 1 0 1 1 1", "output": "6" }, { "input": "22\n0 1 1 0 0 0 0 0 1 0 0 0 0 1 1 0 0 1 0 0 1 0", "output": "7" }, { "input": "22\n0 1 0 1 0 1 1 1 1 0 0 1 1 1 0 1 1 1 0 0 0 1", "output": "16" }, { "input": "22\n1 0 1 0 1 0 0 0 0 0 0 1 0 0 0 0 1 1 0 1 1 0", "output": "11" }, { "input": "22\n1 0 1 0 0 0 1 0 0 1 1 0 1 0 1 1 0 0 0 1 0 1", "output": "14" }, { "input": "33\n0 1 1 0 1 1 0 1 0 1 1 0 1 1 1 1 0 1 1 1 0 0 1 1 0 0 1 1 0 1 1 0 0", "output": "26" }, { "input": "33\n0 1 0 1 0 1 1 0 0 0 1 1 1 0 1 0 1 1 0 1 0 1 0 0 1 1 1 0 1 1 1 0 1", "output": "27" }, { "input": "33\n1 0 1 0 1 0 0 0 1 0 1 1 1 0 0 0 0 1 1 0 1 0 1 1 0 1 0 1 1 1 1 1 0", "output": "25" }, { "input": "33\n1 0 1 0 1 1 1 1 1 0 1 0 1 1 0 0 1 0 1 0 0 0 1 0 1 0 1 0 0 0 0 1 1", "output": "24" }, { "input": "44\n0 1 1 0 1 0 0 0 0 1 1 0 0 0 0 0 1 1 1 0 0 0 0 0 1 0 0 1 1 0 0 0 0 1 1 1 0 0 1 0 1 1 0 0", "output": "19" }, { "input": "44\n0 1 1 1 1 0 1 0 0 1 0 1 0 0 1 1 0 1 1 0 0 1 0 1 0 1 1 0 1 0 1 0 1 0 1 0 0 0 0 0 1 0 1 1", "output": "32" }, { "input": "44\n1 0 1 0 0 1 0 1 0 1 0 1 0 1 1 1 1 1 0 1 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 1 0 0 1 0 0 1 0", "output": "23" }, { "input": "44\n1 0 1 0 1 1 1 0 0 0 0 0 0 1 0 0 0 1 1 1 0 0 0 1 0 1 0 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 1 1", "output": "32" }, { "input": "55\n0 1 1 0 1 0 0 0 1 0 0 0 1 0 1 0 0 1 0 0 0 0 1 1 1 0 0 1 1 0 0 0 0 0 1 0 1 1 1 0 0 0 0 0 1 0 0 0 0 1 1 0 0 1 0", "output": "23" }, { "input": "55\n0 1 1 0 1 0 1 1 1 1 0 1 1 0 0 1 1 1 0 0 0 1 1 0 0 1 0 1 0 1 0 0 1 1 1 1 1 0 0 0 1 1 1 1 1 1 1 1 0 1 1 0 0 0 1", "output": "39" }, { "input": "55\n1 0 1 0 0 1 0 0 1 1 0 1 0 1 0 0 1 1 0 0 0 0 1 1 1 0 0 0 1 1 1 1 0 1 0 1 0 0 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1 0 0", "output": "32" }, { "input": "55\n1 0 1 0 1 0 1 0 1 1 0 0 1 1 1 1 0 1 0 0 0 1 1 0 0 1 0 1 0 1 1 1 0 0 0 0 0 0 1 0 0 0 1 1 1 0 0 0 1 0 1 0 1 1 1", "output": "36" }, { "input": "66\n0 1 1 0 0 1 0 1 0 1 0 1 1 0 1 1 0 0 1 1 0 1 0 0 0 0 0 0 0 1 0 0 0 1 1 1 1 1 1 0 0 1 1 1 0 1 0 1 1 0 1 0 0 1 1 0 1 1 1 0 0 0 0 0 1 0", "output": "41" }, { "input": "66\n0 1 1 0 1 1 1 0 0 0 1 1 0 1 1 0 0 1 1 1 1 1 0 1 1 1 0 1 1 1 0 0 1 0 0 1 1 1 0 0 1 0 1 1 1 0 0 0 1 0 0 0 0 0 1 0 1 0 0 1 0 0 1 1 0 1", "output": "42" }, { "input": "66\n1 0 1 0 0 0 1 0 1 0 1 0 1 1 0 1 0 1 1 0 0 0 1 1 1 0 1 0 0 1 0 1 0 0 0 0 1 1 0 1 1 0 1 0 0 0 1 1 0 1 0 1 1 0 0 0 1 1 0 1 1 0 1 1 0 0", "output": "46" }, { "input": "66\n1 0 1 0 0 0 1 1 1 1 1 0 1 0 0 0 1 1 1 0 1 1 0 1 0 1 0 0 1 0 0 1 0 1 0 1 0 0 1 0 0 1 0 1 1 1 1 1 0 1 1 1 1 1 1 0 0 0 1 0 1 1 0 0 0 1", "output": "46" }, { "input": "77\n0 0 1 0 0 1 0 0 1 1 1 1 0 1 0 0 1 0 0 0 0 1 0 0 0 0 1 0 1 0 1 0 0 0 1 0 0 1 1 0 1 0 1 1 0 0 0 1 0 0 1 1 1 0 1 0 1 1 0 1 0 0 0 1 0 1 1 0 1 1 1 0 1 1 0 1 0", "output": "47" }, { "input": "77\n0 0 1 0 0 0 1 0 1 1 1 1 0 1 1 1 0 1 1 0 1 1 1 0 1 1 0 1 0 0 0 0 1 1 0 0 0 1 1 0 0 1 1 0 1 0 0 1 0 0 0 1 0 0 1 0 0 0 1 0 0 0 1 0 0 1 0 1 1 0 1 0 0 0 0 1 1", "output": "44" }, { "input": "77\n1 0 0 0 1 0 1 1 0 0 1 0 0 0 1 1 1 1 0 1 0 0 0 0 0 0 1 1 0 0 0 1 0 1 0 1 1 1 0 1 1 1 0 0 0 1 1 0 1 1 1 0 1 1 0 0 1 0 0 1 1 1 1 0 1 0 0 0 1 0 1 1 0 0 0 0 0", "output": "45" }, { "input": "77\n1 0 1 0 0 1 1 0 0 0 0 0 0 0 0 0 0 1 0 1 1 1 0 0 1 1 1 0 1 1 0 1 0 0 0 0 1 1 1 0 1 0 0 1 1 0 1 0 1 1 1 1 1 1 1 0 0 1 1 0 0 1 0 1 1 1 1 1 1 1 1 0 0 1 0 1 1", "output": "51" }, { "input": "88\n0 0 1 0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0 1 0 1 1 1 0 0 1 1 0 0 1 0 1 1 1 0 1 1 1 0 1 1 1 1 0 0 0 0 1 0 0 0 1 0 1 1 0 1 0 1 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 1 1 0 0 1 0 0 1 1 1 0", "output": "44" }, { "input": "88\n0 0 1 0 0 0 1 1 0 1 0 1 1 1 0 1 1 1 0 1 1 1 1 1 0 1 1 0 1 1 1 0 1 0 0 1 0 1 1 0 0 0 0 0 1 1 0 0 1 0 1 1 1 0 1 1 0 1 1 0 0 0 1 1 1 1 1 1 1 0 0 1 0 1 0 0 0 1 0 1 0 0 0 0 0 0 0 1", "output": "59" }, { "input": "88\n1 0 0 0 1 1 1 0 1 1 0 0 0 0 0 0 1 0 1 0 0 0 1 1 0 0 1 1 1 1 1 1 0 0 0 0 0 1 0 1 0 0 0 0 0 1 1 1 0 1 1 0 0 1 1 1 0 0 1 0 0 1 1 1 1 0 0 1 0 1 1 1 0 1 0 1 1 1 1 0 1 0 1 1 1 0 0 0", "output": "53" }, { "input": "88\n1 1 1 0 0 1 1 0 1 0 0 0 1 0 1 1 1 1 1 0 1 1 1 1 1 1 1 0 0 1 0 1 1 1 0 0 0 1 1 0 1 1 0 1 0 0 1 0 0 1 0 0 1 0 1 1 0 1 0 1 0 1 0 0 1 1 1 0 0 0 1 0 0 1 0 0 1 1 0 1 1 1 1 0 1 1 0 1", "output": "63" }, { "input": "99\n0 0 0 0 1 0 0 1 0 0 0 1 1 1 1 1 1 0 1 1 0 1 0 0 1 0 1 1 1 1 1 0 1 0 1 1 1 0 0 0 1 0 0 1 0 1 0 1 0 0 0 0 1 0 1 1 0 0 1 1 1 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 1 1 1 0 1 1 0 1 0 1 0 0 0 1 1 0 0 0 0", "output": "56" }, { "input": "99\n0 0 1 0 0 1 1 0 0 0 1 1 0 0 1 0 0 0 1 1 1 1 0 0 0 1 1 0 0 0 1 0 1 1 0 0 1 1 1 0 1 1 0 0 0 0 0 1 0 0 1 0 1 1 0 1 0 1 0 0 1 0 1 1 1 1 1 1 0 1 0 0 1 1 0 0 1 0 1 0 1 0 1 1 1 0 0 1 1 1 0 0 0 0 0 0 1 1 1", "output": "58" }, { "input": "99\n1 1 0 0 1 1 1 0 0 0 1 0 1 0 1 1 0 0 0 0 0 0 0 0 1 0 1 1 0 0 1 1 0 1 0 1 0 1 0 1 0 1 0 1 0 0 1 0 1 1 1 1 0 1 1 1 0 0 1 0 0 1 1 0 0 0 0 1 0 0 1 0 1 1 0 1 1 0 0 1 0 0 1 0 1 0 1 1 0 1 0 1 1 1 1 0 0 1 0", "output": "65" }, { "input": "99\n1 1 1 0 1 0 1 1 0 1 1 0 0 1 0 0 1 1 1 0 1 1 0 0 0 1 1 1 1 0 1 1 1 0 1 1 0 1 1 0 1 0 1 0 0 1 1 1 1 1 0 1 1 0 1 1 0 0 0 1 0 1 0 1 0 1 0 0 0 1 1 1 1 0 0 1 1 0 1 0 0 0 1 0 1 1 1 0 0 1 1 1 1 1 0 1 1 1 1", "output": "77" }, { "input": "90\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", "output": "0" }, { "input": "90\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", "output": "90" }, { "input": "95\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", "output": "0" }, { "input": "95\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", "output": "95" }, { "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\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" } ]
1,444,641,506
506
Python 3
OK
TESTS
60
62
0
input() pprev, prev = None, None ans = 0 for i in input().split(): if i == '1': ans += 1 if prev == '0' and pprev == '1': ans += 1 pprev, prev = prev, i print(ans)
Title: Alena's Schedule Time Limit: None seconds Memory Limit: None megabytes Problem Description: Alena has successfully passed the entrance exams to the university and is now looking forward to start studying. One two-hour lesson at the Russian university is traditionally called a pair, it lasts for two academic hours (an academic hour is equal to 45 minutes). The University works in such a way that every day it holds exactly *n* lessons. Depending on the schedule of a particular group of students, on a given day, some pairs may actually contain classes, but some may be empty (such pairs are called breaks). The official website of the university has already published the schedule for tomorrow for Alena's group. Thus, for each of the *n* pairs she knows if there will be a class at that time or not. Alena's House is far from the university, so if there are breaks, she doesn't always go home. Alena has time to go home only if the break consists of at least two free pairs in a row, otherwise she waits for the next pair at the university. Of course, Alena does not want to be sleepy during pairs, so she will sleep as long as possible, and will only come to the first pair that is presented in her schedule. Similarly, if there are no more pairs, then Alena immediately goes home. Alena appreciates the time spent at home, so she always goes home when it is possible, and returns to the university only at the beginning of the next pair. Help Alena determine for how many pairs she will stay at the university. Note that during some pairs Alena may be at the university waiting for the upcoming pair. Input Specification: The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of lessons at the university. The second line contains *n* numbers *a**i* (0<=≤<=*a**i*<=≤<=1). Number *a**i* equals 0, if Alena doesn't have the *i*-th pairs, otherwise it is equal to 1. Numbers *a*1,<=*a*2,<=...,<=*a**n* are separated by spaces. Output Specification: Print a single number — the number of pairs during which Alena stays at the university. Demo Input: ['5\n0 1 0 1 1\n', '7\n1 0 1 0 0 1 0\n', '1\n0\n'] Demo Output: ['4\n', '4\n', '0\n'] Note: In the first sample Alena stays at the university from the second to the fifth pair, inclusive, during the third pair she will be it the university waiting for the next pair. In the last sample Alena doesn't have a single pair, so she spends all the time at home.
```python input() pprev, prev = None, None ans = 0 for i in input().split(): if i == '1': ans += 1 if prev == '0' and pprev == '1': ans += 1 pprev, prev = prev, i print(ans) ```
3
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,599,855,556
2,147,483,647
PyPy 3
RUNTIME_ERROR
TESTS
0
186
2,150,400
rolls = [1,2,3,4,5,6] for roll in rolls: if abs(roll-a) > abs(roll-b): pb+=1 elif abs(roll-a) < abs(roll-b): pa+=1 else: d+=1 print(pa,d,pb)
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 rolls = [1,2,3,4,5,6] for roll in rolls: if abs(roll-a) > abs(roll-b): pb+=1 elif abs(roll-a) < abs(roll-b): pa+=1 else: d+=1 print(pa,d,pb) ```
-1
825
A
Binary Protocol
PROGRAMMING
1,100
[ "implementation" ]
null
null
Polycarp has just invented a new binary protocol for data transmission. He is encoding positive integer decimal number to binary string using following algorithm: - Each digit is represented with number of '1' characters equal to the value of that digit (for 0 it is zero ones). - Digits are written one by one in order corresponding to number and separated by single '0' character. Though Polycarp learnt how to encode the numbers, he has no idea how to decode them back. Help him calculate the decoded number.
The first line contains one integer number *n* (1<=≤<=*n*<=≤<=89) — length of the string *s*. The second line contains string *s* — sequence of '0' and '1' characters, number in its encoded format. It is guaranteed that the number corresponding to the string is positive and doesn't exceed 109. The string always starts with '1'.
Print the decoded number.
[ "3\n111\n", "9\n110011101\n" ]
[ "3\n", "2031\n" ]
none
0
[ { "input": "3\n111", "output": "3" }, { "input": "9\n110011101", "output": "2031" }, { "input": "1\n1", "output": "1" }, { "input": "3\n100", "output": "100" }, { "input": "5\n10001", "output": "1001" }, { "input": "14\n11001100011000", "output": "202002000" }, { "input": "31\n1000011111111100011110111111111", "output": "100090049" }, { "input": "53\n10110111011110111110111111011111110111111110111111111", "output": "123456789" }, { "input": "89\n11111111101111111110111111111011111111101111111110111111111011111111101111111110111111111", "output": "999999999" }, { "input": "10\n1000000000", "output": "1000000000" }, { "input": "2\n10", "output": "10" }, { "input": "4\n1110", "output": "30" }, { "input": "8\n10101010", "output": "11110" } ]
1,500,217,708
208
Python 3
WRONG_ANSWER
TESTS
0
46
4,505,600
s = input().strip() n = 0 for c in s: if c == '1': n += 1 else: print(n, end='') n = 0 print()
Title: Binary Protocol Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarp has just invented a new binary protocol for data transmission. He is encoding positive integer decimal number to binary string using following algorithm: - Each digit is represented with number of '1' characters equal to the value of that digit (for 0 it is zero ones). - Digits are written one by one in order corresponding to number and separated by single '0' character. Though Polycarp learnt how to encode the numbers, he has no idea how to decode them back. Help him calculate the decoded number. Input Specification: The first line contains one integer number *n* (1<=≤<=*n*<=≤<=89) — length of the string *s*. The second line contains string *s* — sequence of '0' and '1' characters, number in its encoded format. It is guaranteed that the number corresponding to the string is positive and doesn't exceed 109. The string always starts with '1'. Output Specification: Print the decoded number. Demo Input: ['3\n111\n', '9\n110011101\n'] Demo Output: ['3\n', '2031\n'] Note: none
```python s = input().strip() n = 0 for c in s: if c == '1': n += 1 else: print(n, end='') n = 0 print() ```
0
71
A
Way Too Long Words
PROGRAMMING
800
[ "strings" ]
A. Way Too Long Words
1
256
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes. Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n". You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data.
[ "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n" ]
[ "word\nl10n\ni18n\np43s\n" ]
none
500
[ { "input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis", "output": "word\nl10n\ni18n\np43s" }, { "input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm", "output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m" }, { "input": "3\nnjfngnrurunrgunrunvurn\njfvnjfdnvjdbfvsbdubruvbubvkdb\nksdnvidnviudbvibd", "output": "n20n\nj27b\nk15d" }, { "input": "1\ntcyctkktcctrcyvbyiuhihhhgyvyvyvyvjvytchjckt", "output": "t41t" }, { "input": "24\nyou\nare\nregistered\nfor\npractice\nyou\ncan\nsolve\nproblems\nunofficially\nresults\ncan\nbe\nfound\nin\nthe\ncontest\nstatus\nand\nin\nthe\nbottom\nof\nstandings", "output": "you\nare\nregistered\nfor\npractice\nyou\ncan\nsolve\nproblems\nu10y\nresults\ncan\nbe\nfound\nin\nthe\ncontest\nstatus\nand\nin\nthe\nbottom\nof\nstandings" }, { "input": "1\na", "output": "a" }, { "input": "26\na\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz", "output": "a\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz" }, { "input": "1\nabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij", "output": "a98j" }, { "input": "10\ngyartjdxxlcl\nfzsck\nuidwu\nxbymclornemdmtj\nilppyoapitawgje\ncibzc\ndrgbeu\nhezplmsdekhhbo\nfeuzlrimbqbytdu\nkgdco", "output": "g10l\nfzsck\nuidwu\nx13j\ni13e\ncibzc\ndrgbeu\nh12o\nf13u\nkgdco" }, { "input": "20\nlkpmx\nkovxmxorlgwaomlswjxlpnbvltfv\nhykasjxqyjrmybejnmeumzha\ntuevlumpqbbhbww\nqgqsphvrmupxxc\ntrissbaf\nqfgrlinkzvzqdryckaizutd\nzzqtoaxkvwoscyx\noswytrlnhpjvvnwookx\nlpuzqgec\ngyzqfwxggtvpjhzmzmdw\nrlxjgmvdftvrmvbdwudra\nvsntnjpepnvdaxiporggmglhagv\nxlvcqkqgcrbgtgglj\nlyxwxbiszyhlsrgzeedzprbmcpduvq\nyrmqqvrkqskqukzqrwukpsifgtdc\nxpuohcsjhhuhvr\nvvlfrlxpvqejngwrbfbpmqeirxlw\nsvmasocxdvadmaxtrpakysmeaympy\nyuflqboqfdt", "output": "lkpmx\nk26v\nh22a\nt13w\nq12c\ntrissbaf\nq21d\nz13x\no17x\nlpuzqgec\ng18w\nr19a\nv25v\nx15j\nl28q\ny26c\nx12r\nv26w\ns27y\ny9t" }, { "input": "100\nm\nz\ns\nv\nd\nr\nv\ny\ny\ne\np\nt\nc\na\nn\nm\np\ng\ni\nj\nc\na\nb\nq\ne\nn\nv\no\nk\nx\nf\ni\nl\na\nq\nr\nu\nb\ns\nl\nc\nl\ne\nv\nj\nm\nx\nb\na\nq\nb\na\nf\nj\nv\nm\nq\nc\nt\nt\nn\nx\no\ny\nr\nu\nh\nm\nj\np\nj\nq\nz\ns\nj\no\ng\nc\nm\nn\no\nm\nr\no\ns\nt\nh\nr\np\nk\nb\nz\ng\no\nc\nc\nz\nz\ng\nr", "output": "m\nz\ns\nv\nd\nr\nv\ny\ny\ne\np\nt\nc\na\nn\nm\np\ng\ni\nj\nc\na\nb\nq\ne\nn\nv\no\nk\nx\nf\ni\nl\na\nq\nr\nu\nb\ns\nl\nc\nl\ne\nv\nj\nm\nx\nb\na\nq\nb\na\nf\nj\nv\nm\nq\nc\nt\nt\nn\nx\no\ny\nr\nu\nh\nm\nj\np\nj\nq\nz\ns\nj\no\ng\nc\nm\nn\no\nm\nr\no\ns\nt\nh\nr\np\nk\nb\nz\ng\no\nc\nc\nz\nz\ng\nr" } ]
1,692,582,816
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
31
0
a=input("") b=len(a)-2 x= a[0] y=a[len(a)-1] if not a.isalpha(): pass else: if(len(a)>10): print(x,b,y,sep='') else: print(a)
Title: Way Too Long Words Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes. Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n". You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes. Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters. Output Specification: Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data. Demo Input: ['4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n'] Demo Output: ['word\nl10n\ni18n\np43s\n'] Note: none
```python a=input("") b=len(a)-2 x= a[0] y=a[len(a)-1] if not a.isalpha(): pass else: if(len(a)>10): print(x,b,y,sep='') else: print(a) ```
0
362
B
Petya and Staircases
PROGRAMMING
1,100
[ "implementation", "sortings" ]
null
null
Little boy Petya loves stairs very much. But he is bored from simple going up and down them — he loves jumping over several stairs at a time. As he stands on some stair, he can either jump to the next one or jump over one or two stairs at a time. But some stairs are too dirty and Petya doesn't want to step on them. Now Petya is on the first stair of the staircase, consisting of *n* stairs. He also knows the numbers of the dirty stairs of this staircase. Help Petya find out if he can jump through the entire staircase and reach the last stair number *n* without touching a dirty stair once. One has to note that anyway Petya should step on the first and last stairs, so if the first or the last stair is dirty, then Petya cannot choose a path with clean steps only.
The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=109, 0<=≤<=*m*<=≤<=3000) — the number of stairs in the staircase and the number of dirty stairs, correspondingly. The second line contains *m* different space-separated integers *d*1,<=*d*2,<=...,<=*d**m* (1<=≤<=*d**i*<=≤<=*n*) — the numbers of the dirty stairs (in an arbitrary order).
Print "YES" if Petya can reach stair number *n*, stepping only on the clean stairs. Otherwise print "NO".
[ "10 5\n2 4 8 3 6\n", "10 5\n2 4 5 7 9\n" ]
[ "NO", "YES" ]
none
500
[ { "input": "10 5\n2 4 8 3 6", "output": "NO" }, { "input": "10 5\n2 4 5 7 9", "output": "YES" }, { "input": "10 9\n2 3 4 5 6 7 8 9 10", "output": "NO" }, { "input": "5 2\n4 5", "output": "NO" }, { "input": "123 13\n36 73 111 2 92 5 47 55 48 113 7 78 37", "output": "YES" }, { "input": "10 10\n7 6 4 2 5 10 8 3 9 1", "output": "NO" }, { "input": "12312 0", "output": "YES" }, { "input": "9817239 1\n6323187", "output": "YES" }, { "input": "1 1\n1", "output": "NO" }, { "input": "5 4\n4 2 5 1", "output": "NO" }, { "input": "5 3\n4 3 5", "output": "NO" }, { "input": "500 3\n18 62 445", "output": "YES" }, { "input": "500 50\n72 474 467 241 442 437 336 234 410 120 438 164 405 177 142 114 27 20 445 235 46 176 88 488 242 391 28 414 145 92 206 334 152 343 367 254 100 243 155 348 148 450 461 483 97 34 471 69 416 362", "output": "NO" }, { "input": "500 8\n365 313 338 410 482 417 325 384", "output": "YES" }, { "input": "1000000000 10\n2 3 5 6 8 9 123 874 1230 1000000000", "output": "NO" }, { "input": "1000000000 10\n1 2 3 5 6 8 9 123 874 1230", "output": "NO" }, { "input": "10 1\n1", "output": "NO" }, { "input": "10 4\n1 2 4 5", "output": "NO" }, { "input": "50 20\n22 33 17 23 27 5 26 31 41 20 8 24 6 3 4 29 40 25 13 16", "output": "NO" }, { "input": "50 40\n14 27 19 30 31 20 28 11 37 29 23 33 7 26 22 16 1 6 18 3 47 36 38 2 48 9 41 8 5 50 4 45 44 25 39 12 43 42 40 46", "output": "NO" }, { "input": "123 12\n35 95 47 99 79 122 58 94 31 57 18 10", "output": "YES" }, { "input": "10 5\n1 3 5 7 9", "output": "NO" }, { "input": "100 7\n2 3 5 6 8 9 100", "output": "NO" }, { "input": "100 3\n98 99 100", "output": "NO" }, { "input": "100 3\n97 98 99", "output": "NO" }, { "input": "100 3\n96 98 99", "output": "YES" }, { "input": "10 6\n2 3 5 6 8 9", "output": "YES" }, { "input": "1000000000 10\n2 4 10 18 40 42 49 58 59 60", "output": "NO" }, { "input": "10 3\n1 4 6", "output": "NO" }, { "input": "8 3\n2 3 4", "output": "NO" }, { "input": "100 3\n4 5 6", "output": "NO" }, { "input": "10 2\n10 1", "output": "NO" }, { "input": "10 1\n10", "output": "NO" }, { "input": "4 2\n2 3", "output": "YES" }, { "input": "2 1\n1", "output": "NO" }, { "input": "2 0", "output": "YES" }, { "input": "4 3\n2 3 4", "output": "NO" }, { "input": "5 3\n4 2 3", "output": "NO" } ]
1,631,433,903
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
4
109
21,606,400
n,m=map(int,input().split()) x=list(map(int,input().split())) if n in x: print("NO") else: for i in range(1,len(x)): if x[i]-x[i-1]>3: print("NO") break else: print("YES")
Title: Petya and Staircases Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little boy Petya loves stairs very much. But he is bored from simple going up and down them — he loves jumping over several stairs at a time. As he stands on some stair, he can either jump to the next one or jump over one or two stairs at a time. But some stairs are too dirty and Petya doesn't want to step on them. Now Petya is on the first stair of the staircase, consisting of *n* stairs. He also knows the numbers of the dirty stairs of this staircase. Help Petya find out if he can jump through the entire staircase and reach the last stair number *n* without touching a dirty stair once. One has to note that anyway Petya should step on the first and last stairs, so if the first or the last stair is dirty, then Petya cannot choose a path with clean steps only. Input Specification: The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=109, 0<=≤<=*m*<=≤<=3000) — the number of stairs in the staircase and the number of dirty stairs, correspondingly. The second line contains *m* different space-separated integers *d*1,<=*d*2,<=...,<=*d**m* (1<=≤<=*d**i*<=≤<=*n*) — the numbers of the dirty stairs (in an arbitrary order). Output Specification: Print "YES" if Petya can reach stair number *n*, stepping only on the clean stairs. Otherwise print "NO". Demo Input: ['10 5\n2 4 8 3 6\n', '10 5\n2 4 5 7 9\n'] Demo Output: ['NO', 'YES'] Note: none
```python n,m=map(int,input().split()) x=list(map(int,input().split())) if n in x: print("NO") else: for i in range(1,len(x)): if x[i]-x[i-1]>3: print("NO") break else: print("YES") ```
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,619,583,187
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
46
0
s=input() s1=input() for i in range(len(s)): if(s[i]==s1[i]): print("0") else: print("1")
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 s=input() s1=input() for i in range(len(s)): if(s[i]==s1[i]): print("0") else: print("1") ```
0
1,006
B
Polycarp's Practice
PROGRAMMING
1,200
[ "greedy", "implementation", "sortings" ]
null
null
Polycarp is practicing his problem solving skill. He has a list of $n$ problems with difficulties $a_1, a_2, \dots, a_n$, respectively. His plan is to practice for exactly $k$ days. Each day he has to solve at least one problem from his list. Polycarp solves the problems in the order they are given in his list, he cannot skip any problem from his list. He has to solve all $n$ problems in exactly $k$ days. Thus, each day Polycarp solves a contiguous sequence of (consecutive) problems from the start of the list. He can't skip problems or solve them multiple times. As a result, in $k$ days he will solve all the $n$ problems. The profit of the $j$-th day of Polycarp's practice is the maximum among all the difficulties of problems Polycarp solves during the $j$-th day (i.e. if he solves problems with indices from $l$ to $r$ during a day, then the profit of the day is $\max\limits_{l \le i \le r}a_i$). The total profit of his practice is the sum of the profits over all $k$ days of his practice. You want to help Polycarp to get the maximum possible total profit over all valid ways to solve problems. Your task is to distribute all $n$ problems between $k$ days satisfying the conditions above in such a way, that the total profit is maximum. For example, if $n = 8, k = 3$ and $a = [5, 4, 2, 6, 5, 1, 9, 2]$, one of the possible distributions with maximum total profit is: $[5, 4, 2], [6, 5], [1, 9, 2]$. Here the total profit equals $5 + 6 + 9 = 20$.
The first line of the input contains two integers $n$ and $k$ ($1 \le k \le n \le 2000$) — the number of problems and the number of days, respectively. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 2000$) — difficulties of problems in Polycarp's list, in the order they are placed in the list (i.e. in the order Polycarp will solve them).
In the first line of the output print the maximum possible total profit. In the second line print exactly $k$ positive integers $t_1, t_2, \dots, t_k$ ($t_1 + t_2 + \dots + t_k$ must equal $n$), where $t_j$ means the number of problems Polycarp will solve during the $j$-th day in order to achieve the maximum possible total profit of his practice. If there are many possible answers, you may print any of them.
[ "8 3\n5 4 2 6 5 1 9 2\n", "5 1\n1 1 1 1 1\n", "4 2\n1 2000 2000 2\n" ]
[ "20\n3 2 3", "1\n5\n", "4000\n2 2\n" ]
The first example is described in the problem statement. In the second example there is only one possible distribution. In the third example the best answer is to distribute problems in the following way: $[1, 2000], [2000, 2]$. The total profit of this distribution is $2000 + 2000 = 4000$.
0
[ { "input": "8 3\n5 4 2 6 5 1 9 2", "output": "20\n4 1 3" }, { "input": "5 1\n1 1 1 1 1", "output": "1\n5" }, { "input": "4 2\n1 2000 2000 2", "output": "4000\n2 2" }, { "input": "1 1\n2000", "output": "2000\n1" }, { "input": "1 1\n1234", "output": "1234\n1" }, { "input": "3 2\n1 1 1", "output": "2\n2 1" }, { "input": "4 2\n3 5 1 1", "output": "8\n1 3" }, { "input": "5 3\n5 5 6 7 1", "output": "18\n2 1 2" }, { "input": "6 4\n1 1 1 1 2 2", "output": "6\n3 1 1 1" }, { "input": "5 3\n5 5 6 6 4", "output": "17\n2 1 2" }, { "input": "16 15\n14 4 9 12 17 1 1 8 12 13 6 9 17 2 18 12", "output": "154\n1 1 1 1 1 2 1 1 1 1 1 1 1 1 1" }, { "input": "1 1\n1996", "output": "1996\n1" }, { "input": "5 3\n5 5 5 9 10", "output": "24\n3 1 1" }, { "input": "18 15\n18 2 13 1 18 3 2 18 18 20 9 2 20 20 4 20 9 12", "output": "204\n1 2 2 1 2 1 1 1 1 1 1 1 1 1 1" }, { "input": "5 3\n1 20 20 50 50", "output": "120\n3 1 1" }, { "input": "8 3\n15 14 11 19 17 14 14 8", "output": "51\n1 3 4" }, { "input": "5 2\n15 20 6 19 6", "output": "39\n2 3" }, { "input": "6 3\n5 5 5 5 6 9", "output": "20\n4 1 1" }, { "input": "5 3\n2 2 2 3 3", "output": "8\n3 1 1" }, { "input": "7 3\n2 2 2 2 2 3 3", "output": "8\n5 1 1" }, { "input": "6 5\n1 1 6 6 6 6", "output": "25\n2 1 1 1 1" }, { "input": "8 4\n1 2 2 2 2 3 4 5", "output": "14\n5 1 1 1" }, { "input": "6 4\n1 1 1 5 5 5", "output": "16\n3 1 1 1" }, { "input": "6 3\n1 2 2 2 4 5", "output": "11\n4 1 1" }, { "input": "18 6\n17 17 19 14 10 20 18 16 6 7 2 15 14 16 13 6 12 11", "output": "107\n1 1 1 3 1 11" }, { "input": "6 3\n1 1 2 2 3 4", "output": "9\n4 1 1" }, { "input": "8 3\n5 4 2 5 6 1 9 2", "output": "20\n4 1 3" } ]
1,666,270,204
2,147,483,647
PyPy 3-64
OK
TESTS
37
93
4,505,600
n, k = map(int, input().split()) numbers = list(map(int, input().split())) maximums = sorted(numbers, reverse=True)[:k] print(sum(maximums)) left_point = -1 right_point = 0 while right_point < n: if numbers[right_point] in maximums: maximums.remove(numbers[right_point]) if len(maximums) == 0: right_point = n-1 # print(left_point, right_point) print(right_point - left_point, end = " ") left_point = right_point right_point += 1
Title: Polycarp's Practice Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarp is practicing his problem solving skill. He has a list of $n$ problems with difficulties $a_1, a_2, \dots, a_n$, respectively. His plan is to practice for exactly $k$ days. Each day he has to solve at least one problem from his list. Polycarp solves the problems in the order they are given in his list, he cannot skip any problem from his list. He has to solve all $n$ problems in exactly $k$ days. Thus, each day Polycarp solves a contiguous sequence of (consecutive) problems from the start of the list. He can't skip problems or solve them multiple times. As a result, in $k$ days he will solve all the $n$ problems. The profit of the $j$-th day of Polycarp's practice is the maximum among all the difficulties of problems Polycarp solves during the $j$-th day (i.e. if he solves problems with indices from $l$ to $r$ during a day, then the profit of the day is $\max\limits_{l \le i \le r}a_i$). The total profit of his practice is the sum of the profits over all $k$ days of his practice. You want to help Polycarp to get the maximum possible total profit over all valid ways to solve problems. Your task is to distribute all $n$ problems between $k$ days satisfying the conditions above in such a way, that the total profit is maximum. For example, if $n = 8, k = 3$ and $a = [5, 4, 2, 6, 5, 1, 9, 2]$, one of the possible distributions with maximum total profit is: $[5, 4, 2], [6, 5], [1, 9, 2]$. Here the total profit equals $5 + 6 + 9 = 20$. Input Specification: The first line of the input contains two integers $n$ and $k$ ($1 \le k \le n \le 2000$) — the number of problems and the number of days, respectively. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 2000$) — difficulties of problems in Polycarp's list, in the order they are placed in the list (i.e. in the order Polycarp will solve them). Output Specification: In the first line of the output print the maximum possible total profit. In the second line print exactly $k$ positive integers $t_1, t_2, \dots, t_k$ ($t_1 + t_2 + \dots + t_k$ must equal $n$), where $t_j$ means the number of problems Polycarp will solve during the $j$-th day in order to achieve the maximum possible total profit of his practice. If there are many possible answers, you may print any of them. Demo Input: ['8 3\n5 4 2 6 5 1 9 2\n', '5 1\n1 1 1 1 1\n', '4 2\n1 2000 2000 2\n'] Demo Output: ['20\n3 2 3', '1\n5\n', '4000\n2 2\n'] Note: The first example is described in the problem statement. In the second example there is only one possible distribution. In the third example the best answer is to distribute problems in the following way: $[1, 2000], [2000, 2]$. The total profit of this distribution is $2000 + 2000 = 4000$.
```python n, k = map(int, input().split()) numbers = list(map(int, input().split())) maximums = sorted(numbers, reverse=True)[:k] print(sum(maximums)) left_point = -1 right_point = 0 while right_point < n: if numbers[right_point] in maximums: maximums.remove(numbers[right_point]) if len(maximums) == 0: right_point = n-1 # print(left_point, right_point) print(right_point - left_point, end = " ") left_point = right_point right_point += 1 ```
3
361
A
Levko and Table
PROGRAMMING
800
[ "constructive algorithms", "implementation" ]
null
null
Levko loves tables that consist of *n* rows and *n* columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals *k*. Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them.
The single line contains two integers, *n* and *k* (1<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=1000).
Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value. If there are multiple suitable tables, you are allowed to print any of them.
[ "2 4\n", "4 7\n" ]
[ "1 3\n3 1\n", "2 1 0 4\n4 0 2 1\n1 3 3 0\n0 3 2 2\n" ]
In the first sample the sum in the first row is 1 + 3 = 4, in the second row — 3 + 1 = 4, in the first column — 1 + 3 = 4 and in the second column — 3 + 1 = 4. There are other beautiful tables for this sample. In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements.
500
[ { "input": "2 4", "output": "4 0 \n0 4 " }, { "input": "4 7", "output": "7 0 0 0 \n0 7 0 0 \n0 0 7 0 \n0 0 0 7 " }, { "input": "1 8", "output": "8 " }, { "input": "9 3", "output": "3 0 0 0 0 0 0 0 0 \n0 3 0 0 0 0 0 0 0 \n0 0 3 0 0 0 0 0 0 \n0 0 0 3 0 0 0 0 0 \n0 0 0 0 3 0 0 0 0 \n0 0 0 0 0 3 0 0 0 \n0 0 0 0 0 0 3 0 0 \n0 0 0 0 0 0 0 3 0 \n0 0 0 0 0 0 0 0 3 " }, { "input": "31 581", "output": "581 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 581 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 581 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 581 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 581 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 581 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 0 581 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 0 0 581 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..." }, { "input": "100 1000", "output": "1000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 1000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 1000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ..." }, { "input": "100 999", "output": "999 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 999 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 999 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..." }, { "input": "99 998", "output": "998 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 998 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 998 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..." }, { "input": "100 997", "output": "997 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 997 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 997 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..." }, { "input": "81 111", "output": "111 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 111 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 111 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 111 0 0..." }, { "input": "1 407", "output": "407 " }, { "input": "54 341", "output": "341 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 341 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 341 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 341 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 341 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..." }, { "input": "92 460", "output": "460 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 460 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 460 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..." }, { "input": "34 47", "output": "47 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 47 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 47 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 47 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 47 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 47 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 0 47 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 0 0 ..." }, { "input": "11 547", "output": "547 0 0 0 0 0 0 0 0 0 0 \n0 547 0 0 0 0 0 0 0 0 0 \n0 0 547 0 0 0 0 0 0 0 0 \n0 0 0 547 0 0 0 0 0 0 0 \n0 0 0 0 547 0 0 0 0 0 0 \n0 0 0 0 0 547 0 0 0 0 0 \n0 0 0 0 0 0 547 0 0 0 0 \n0 0 0 0 0 0 0 547 0 0 0 \n0 0 0 0 0 0 0 0 547 0 0 \n0 0 0 0 0 0 0 0 0 547 0 \n0 0 0 0 0 0 0 0 0 0 547 " }, { "input": "100 1", "output": "1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..." }, { "input": "99 1", "output": "1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..." }, { "input": "99 2", "output": "2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..." }, { "input": "2 7", "output": "7 0 \n0 7 " }, { "input": "100 100", "output": "100 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 100 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 100 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..." }, { "input": "4 3", "output": "3 0 0 0 \n0 3 0 0 \n0 0 3 0 \n0 0 0 3 " }, { "input": "3 2", "output": "2 0 0 \n0 2 0 \n0 0 2 " } ]
1,596,373,341
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
93
6,656,000
x,y=map(int,input().split()) for i in range(x): for j in range(x-1): print(0,end=" ") print(y,end="\n")
Title: Levko and Table Time Limit: None seconds Memory Limit: None megabytes Problem Description: Levko loves tables that consist of *n* rows and *n* columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals *k*. Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them. Input Specification: The single line contains two integers, *n* and *k* (1<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=1000). Output Specification: Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value. If there are multiple suitable tables, you are allowed to print any of them. Demo Input: ['2 4\n', '4 7\n'] Demo Output: ['1 3\n3 1\n', '2 1 0 4\n4 0 2 1\n1 3 3 0\n0 3 2 2\n'] Note: In the first sample the sum in the first row is 1 + 3 = 4, in the second row — 3 + 1 = 4, in the first column — 1 + 3 = 4 and in the second column — 3 + 1 = 4. There are other beautiful tables for this sample. In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements.
```python x,y=map(int,input().split()) for i in range(x): for j in range(x-1): print(0,end=" ") print(y,end="\n") ```
0
639
B
Bear and Forgotten Tree 3
PROGRAMMING
1,600
[ "constructive algorithms", "graphs", "trees" ]
null
null
A tree is a connected undirected graph consisting of *n* vertices and *n*<=<=-<=<=1 edges. Vertices are numbered 1 through *n*. Limak is a little polar bear and Radewoosh is his evil enemy. Limak once had a tree but Radewoosh stolen it. Bear is very sad now because he doesn't remember much about the tree — he can tell you only three values *n*, *d* and *h*: - The tree had exactly *n* vertices. - The tree had diameter *d*. In other words, *d* was the biggest distance between two vertices. - Limak also remembers that he once rooted the tree in vertex 1 and after that its height was *h*. In other words, *h* was the biggest distance between vertex 1 and some other vertex. The distance between two vertices of the tree is the number of edges on the simple path between them. Help Limak to restore his tree. Check whether there exists a tree satisfying the given conditions. Find any such tree and print its edges in any order. It's also possible that Limak made a mistake and there is no suitable tree – in this case print "-1".
The first line contains three integers *n*, *d* and *h* (2<=≤<=*n*<=≤<=100<=000,<=1<=≤<=*h*<=≤<=*d*<=≤<=*n*<=-<=1) — the number of vertices, diameter, and height after rooting in vertex 1, respectively.
If there is no tree matching what Limak remembers, print the only line with "-1" (without the quotes). Otherwise, describe any tree matching Limak's description. Print *n*<=-<=1 lines, each with two space-separated integers – indices of vertices connected by an edge. If there are many valid trees, print any of them. You can print edges in any order.
[ "5 3 2\n", "8 5 2\n", "8 4 2\n" ]
[ "1 2\n1 3\n3 4\n3 5", "-1\n", "4 8\n5 7\n2 3\n8 1\n2 1\n5 6\n1 5\n" ]
Below you can see trees printed to the output in the first sample and the third sample.
750
[ { "input": "5 3 2", "output": "1 2\n2 3\n1 4\n5 1" }, { "input": "8 5 2", "output": "-1" }, { "input": "8 4 2", "output": "4 8\n5 7\n2 3\n8 1\n2 1\n5 6\n1 5" }, { "input": "2 1 1", "output": "1 2" }, { "input": "10 3 3", "output": "1 2\n2 3\n3 4\n5 2\n6 2\n7 2\n8 2\n9 2\n10 2" }, { "input": "15 6 4", "output": "1 2\n2 3\n3 4\n4 5\n1 6\n6 7\n8 1\n9 1\n10 1\n11 1\n12 1\n13 1\n14 1\n15 1" }, { "input": "16 15 14", "output": "1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n1 16" }, { "input": "1000 51 25", "output": "-1" }, { "input": "100000 10 7", "output": "1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n1 9\n9 10\n10 11\n12 1\n13 1\n14 1\n15 1\n16 1\n17 1\n18 1\n19 1\n20 1\n21 1\n22 1\n23 1\n24 1\n25 1\n26 1\n27 1\n28 1\n29 1\n30 1\n31 1\n32 1\n33 1\n34 1\n35 1\n36 1\n37 1\n38 1\n39 1\n40 1\n41 1\n42 1\n43 1\n44 1\n45 1\n46 1\n47 1\n48 1\n49 1\n50 1\n51 1\n52 1\n53 1\n54 1\n55 1\n56 1\n57 1\n58 1\n59 1\n60 1\n61 1\n62 1\n63 1\n64 1\n65 1\n66 1\n67 1\n68 1\n69 1\n70 1\n71 1\n72 1\n73 1\n74 1\n75 1\n76 1\n77 1\n78 1\n79 1\n80 1\n81 1\n82 1\n83 1\n84 1\n85 1\n86 1\n87 1\n88..." }, { "input": "3 1 1", "output": "-1" }, { "input": "3 2 1", "output": "1 2\n1 3" }, { "input": "3 2 2", "output": "1 2\n2 3" }, { "input": "4 1 1", "output": "-1" }, { "input": "4 2 1", "output": "1 2\n1 3\n4 1" }, { "input": "4 2 2", "output": "1 2\n2 3\n4 2" }, { "input": "4 3 1", "output": "-1" }, { "input": "4 3 2", "output": "1 2\n2 3\n1 4" }, { "input": "4 3 3", "output": "1 2\n2 3\n3 4" }, { "input": "8 5 3", "output": "1 2\n2 3\n3 4\n1 5\n5 6\n7 1\n8 1" }, { "input": "20 19 19", "output": "1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20" }, { "input": "30 14 14", "output": "1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n16 2\n17 2\n18 2\n19 2\n20 2\n21 2\n22 2\n23 2\n24 2\n25 2\n26 2\n27 2\n28 2\n29 2\n30 2" }, { "input": "33 5 3", "output": "1 2\n2 3\n3 4\n1 5\n5 6\n7 1\n8 1\n9 1\n10 1\n11 1\n12 1\n13 1\n14 1\n15 1\n16 1\n17 1\n18 1\n19 1\n20 1\n21 1\n22 1\n23 1\n24 1\n25 1\n26 1\n27 1\n28 1\n29 1\n30 1\n31 1\n32 1\n33 1" }, { "input": "5432 200 100", "output": "1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76\n76 ..." }, { "input": "5433 200 99", "output": "-1" }, { "input": "99999 1 1", "output": "-1" }, { "input": "99999 2 1", "output": "1 2\n1 3\n4 1\n5 1\n6 1\n7 1\n8 1\n9 1\n10 1\n11 1\n12 1\n13 1\n14 1\n15 1\n16 1\n17 1\n18 1\n19 1\n20 1\n21 1\n22 1\n23 1\n24 1\n25 1\n26 1\n27 1\n28 1\n29 1\n30 1\n31 1\n32 1\n33 1\n34 1\n35 1\n36 1\n37 1\n38 1\n39 1\n40 1\n41 1\n42 1\n43 1\n44 1\n45 1\n46 1\n47 1\n48 1\n49 1\n50 1\n51 1\n52 1\n53 1\n54 1\n55 1\n56 1\n57 1\n58 1\n59 1\n60 1\n61 1\n62 1\n63 1\n64 1\n65 1\n66 1\n67 1\n68 1\n69 1\n70 1\n71 1\n72 1\n73 1\n74 1\n75 1\n76 1\n77 1\n78 1\n79 1\n80 1\n81 1\n82 1\n83 1\n84 1\n85 1\n86 1\n87 1\n88 ..." }, { "input": "99999 7 4", "output": "1 2\n2 3\n3 4\n4 5\n1 6\n6 7\n7 8\n9 1\n10 1\n11 1\n12 1\n13 1\n14 1\n15 1\n16 1\n17 1\n18 1\n19 1\n20 1\n21 1\n22 1\n23 1\n24 1\n25 1\n26 1\n27 1\n28 1\n29 1\n30 1\n31 1\n32 1\n33 1\n34 1\n35 1\n36 1\n37 1\n38 1\n39 1\n40 1\n41 1\n42 1\n43 1\n44 1\n45 1\n46 1\n47 1\n48 1\n49 1\n50 1\n51 1\n52 1\n53 1\n54 1\n55 1\n56 1\n57 1\n58 1\n59 1\n60 1\n61 1\n62 1\n63 1\n64 1\n65 1\n66 1\n67 1\n68 1\n69 1\n70 1\n71 1\n72 1\n73 1\n74 1\n75 1\n76 1\n77 1\n78 1\n79 1\n80 1\n81 1\n82 1\n83 1\n84 1\n85 1\n86 1\n87 1\n88 ..." }, { "input": "9999 7 3", "output": "-1" }, { "input": "100000 1 1", "output": "-1" }, { "input": "100000 2 1", "output": "1 2\n1 3\n4 1\n5 1\n6 1\n7 1\n8 1\n9 1\n10 1\n11 1\n12 1\n13 1\n14 1\n15 1\n16 1\n17 1\n18 1\n19 1\n20 1\n21 1\n22 1\n23 1\n24 1\n25 1\n26 1\n27 1\n28 1\n29 1\n30 1\n31 1\n32 1\n33 1\n34 1\n35 1\n36 1\n37 1\n38 1\n39 1\n40 1\n41 1\n42 1\n43 1\n44 1\n45 1\n46 1\n47 1\n48 1\n49 1\n50 1\n51 1\n52 1\n53 1\n54 1\n55 1\n56 1\n57 1\n58 1\n59 1\n60 1\n61 1\n62 1\n63 1\n64 1\n65 1\n66 1\n67 1\n68 1\n69 1\n70 1\n71 1\n72 1\n73 1\n74 1\n75 1\n76 1\n77 1\n78 1\n79 1\n80 1\n81 1\n82 1\n83 1\n84 1\n85 1\n86 1\n87 1\n88 ..." }, { "input": "100000 2 2", "output": "1 2\n2 3\n4 2\n5 2\n6 2\n7 2\n8 2\n9 2\n10 2\n11 2\n12 2\n13 2\n14 2\n15 2\n16 2\n17 2\n18 2\n19 2\n20 2\n21 2\n22 2\n23 2\n24 2\n25 2\n26 2\n27 2\n28 2\n29 2\n30 2\n31 2\n32 2\n33 2\n34 2\n35 2\n36 2\n37 2\n38 2\n39 2\n40 2\n41 2\n42 2\n43 2\n44 2\n45 2\n46 2\n47 2\n48 2\n49 2\n50 2\n51 2\n52 2\n53 2\n54 2\n55 2\n56 2\n57 2\n58 2\n59 2\n60 2\n61 2\n62 2\n63 2\n64 2\n65 2\n66 2\n67 2\n68 2\n69 2\n70 2\n71 2\n72 2\n73 2\n74 2\n75 2\n76 2\n77 2\n78 2\n79 2\n80 2\n81 2\n82 2\n83 2\n84 2\n85 2\n86 2\n87 2\n88 ..." }, { "input": "100000 3 1", "output": "-1" }, { "input": "100000 10 5", "output": "1 2\n2 3\n3 4\n4 5\n5 6\n1 7\n7 8\n8 9\n9 10\n10 11\n12 1\n13 1\n14 1\n15 1\n16 1\n17 1\n18 1\n19 1\n20 1\n21 1\n22 1\n23 1\n24 1\n25 1\n26 1\n27 1\n28 1\n29 1\n30 1\n31 1\n32 1\n33 1\n34 1\n35 1\n36 1\n37 1\n38 1\n39 1\n40 1\n41 1\n42 1\n43 1\n44 1\n45 1\n46 1\n47 1\n48 1\n49 1\n50 1\n51 1\n52 1\n53 1\n54 1\n55 1\n56 1\n57 1\n58 1\n59 1\n60 1\n61 1\n62 1\n63 1\n64 1\n65 1\n66 1\n67 1\n68 1\n69 1\n70 1\n71 1\n72 1\n73 1\n74 1\n75 1\n76 1\n77 1\n78 1\n79 1\n80 1\n81 1\n82 1\n83 1\n84 1\n85 1\n86 1\n87 1\n88..." }, { "input": "100000 10 6", "output": "1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n1 8\n8 9\n9 10\n10 11\n12 1\n13 1\n14 1\n15 1\n16 1\n17 1\n18 1\n19 1\n20 1\n21 1\n22 1\n23 1\n24 1\n25 1\n26 1\n27 1\n28 1\n29 1\n30 1\n31 1\n32 1\n33 1\n34 1\n35 1\n36 1\n37 1\n38 1\n39 1\n40 1\n41 1\n42 1\n43 1\n44 1\n45 1\n46 1\n47 1\n48 1\n49 1\n50 1\n51 1\n52 1\n53 1\n54 1\n55 1\n56 1\n57 1\n58 1\n59 1\n60 1\n61 1\n62 1\n63 1\n64 1\n65 1\n66 1\n67 1\n68 1\n69 1\n70 1\n71 1\n72 1\n73 1\n74 1\n75 1\n76 1\n77 1\n78 1\n79 1\n80 1\n81 1\n82 1\n83 1\n84 1\n85 1\n86 1\n87 1\n88..." }, { "input": "100000 10 9", "output": "1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n1 11\n12 1\n13 1\n14 1\n15 1\n16 1\n17 1\n18 1\n19 1\n20 1\n21 1\n22 1\n23 1\n24 1\n25 1\n26 1\n27 1\n28 1\n29 1\n30 1\n31 1\n32 1\n33 1\n34 1\n35 1\n36 1\n37 1\n38 1\n39 1\n40 1\n41 1\n42 1\n43 1\n44 1\n45 1\n46 1\n47 1\n48 1\n49 1\n50 1\n51 1\n52 1\n53 1\n54 1\n55 1\n56 1\n57 1\n58 1\n59 1\n60 1\n61 1\n62 1\n63 1\n64 1\n65 1\n66 1\n67 1\n68 1\n69 1\n70 1\n71 1\n72 1\n73 1\n74 1\n75 1\n76 1\n77 1\n78 1\n79 1\n80 1\n81 1\n82 1\n83 1\n84 1\n85 1\n86 1\n87 1\n88 ..." }, { "input": "100000 10 10", "output": "1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n12 2\n13 2\n14 2\n15 2\n16 2\n17 2\n18 2\n19 2\n20 2\n21 2\n22 2\n23 2\n24 2\n25 2\n26 2\n27 2\n28 2\n29 2\n30 2\n31 2\n32 2\n33 2\n34 2\n35 2\n36 2\n37 2\n38 2\n39 2\n40 2\n41 2\n42 2\n43 2\n44 2\n45 2\n46 2\n47 2\n48 2\n49 2\n50 2\n51 2\n52 2\n53 2\n54 2\n55 2\n56 2\n57 2\n58 2\n59 2\n60 2\n61 2\n62 2\n63 2\n64 2\n65 2\n66 2\n67 2\n68 2\n69 2\n70 2\n71 2\n72 2\n73 2\n74 2\n75 2\n76 2\n77 2\n78 2\n79 2\n80 2\n81 2\n82 2\n83 2\n84 2\n85 2\n86 2\n87 2\n88..." }, { "input": "100000 99900 78900", "output": "1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76\n76 ..." }, { "input": "100000 99998 1", "output": "-1" }, { "input": "100000 99998 49999", "output": "1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76\n76 ..." }, { "input": "100000 99998 50000", "output": "1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76\n76 ..." }, { "input": "100000 99998 69001", "output": "1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76\n76 ..." }, { "input": "100000 99998 99055", "output": "1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76\n76 ..." }, { "input": "100000 99998 99998", "output": "1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76\n76 ..." }, { "input": "100000 99999 1", "output": "-1" }, { "input": "100000 99999 49999", "output": "-1" }, { "input": "100000 99999 50000", "output": "1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76\n76 ..." }, { "input": "100000 99999 50001", "output": "1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76\n76 ..." }, { "input": "100000 99999 77777", "output": "1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76\n76 ..." }, { "input": "100000 99999 99998", "output": "1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76\n76 ..." }, { "input": "100000 99999 99999", "output": "1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76\n76 ..." }, { "input": "3 1 1", "output": "-1" }, { "input": "5 1 1", "output": "-1" }, { "input": "10 1 1", "output": "-1" }, { "input": "3 2 1", "output": "1 2\n1 3" }, { "input": "8 1 1", "output": "-1" }, { "input": "4 1 1", "output": "-1" }, { "input": "6 1 1", "output": "-1" }, { "input": "20 1 1", "output": "-1" }, { "input": "5 2 1", "output": "1 2\n1 3\n4 1\n5 1" }, { "input": "100 1 1", "output": "-1" }, { "input": "10 2 1", "output": "1 2\n1 3\n4 1\n5 1\n6 1\n7 1\n8 1\n9 1\n10 1" }, { "input": "100 2 1", "output": "1 2\n1 3\n4 1\n5 1\n6 1\n7 1\n8 1\n9 1\n10 1\n11 1\n12 1\n13 1\n14 1\n15 1\n16 1\n17 1\n18 1\n19 1\n20 1\n21 1\n22 1\n23 1\n24 1\n25 1\n26 1\n27 1\n28 1\n29 1\n30 1\n31 1\n32 1\n33 1\n34 1\n35 1\n36 1\n37 1\n38 1\n39 1\n40 1\n41 1\n42 1\n43 1\n44 1\n45 1\n46 1\n47 1\n48 1\n49 1\n50 1\n51 1\n52 1\n53 1\n54 1\n55 1\n56 1\n57 1\n58 1\n59 1\n60 1\n61 1\n62 1\n63 1\n64 1\n65 1\n66 1\n67 1\n68 1\n69 1\n70 1\n71 1\n72 1\n73 1\n74 1\n75 1\n76 1\n77 1\n78 1\n79 1\n80 1\n81 1\n82 1\n83 1\n84 1\n85 1\n86 1\n87 1\n88 ..." }, { "input": "47 1 1", "output": "-1" }, { "input": "7 1 1", "output": "-1" }, { "input": "4 2 1", "output": "1 2\n1 3\n4 1" }, { "input": "5 2 2", "output": "1 2\n2 3\n4 2\n5 2" }, { "input": "8 2 1", "output": "1 2\n1 3\n4 1\n5 1\n6 1\n7 1\n8 1" }, { "input": "1000 1 1", "output": "-1" }, { "input": "11 1 1", "output": "-1" }, { "input": "15 2 1", "output": "1 2\n1 3\n4 1\n5 1\n6 1\n7 1\n8 1\n9 1\n10 1\n11 1\n12 1\n13 1\n14 1\n15 1" }, { "input": "3 2 2", "output": "1 2\n2 3" }, { "input": "8 2 2", "output": "1 2\n2 3\n4 2\n5 2\n6 2\n7 2\n8 2" } ]
1,512,669,600
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
46
5,529,600
n,d,h,r=map(int,input().split()+[1]) if(2*h<d):exit(print(-1)) if(h==d):print(1,2);r=2 last,cnt=r,1+r for i in range(d//2): print(last,cnt);last=cnt;cnt+=1 last=r for i in range(d-d//2): print(last,cnt);last=cnt;cnt+=1 for _ in range(n-d-r): print(r,cnt);cnt+=1
Title: Bear and Forgotten Tree 3 Time Limit: None seconds Memory Limit: None megabytes Problem Description: A tree is a connected undirected graph consisting of *n* vertices and *n*<=<=-<=<=1 edges. Vertices are numbered 1 through *n*. Limak is a little polar bear and Radewoosh is his evil enemy. Limak once had a tree but Radewoosh stolen it. Bear is very sad now because he doesn't remember much about the tree — he can tell you only three values *n*, *d* and *h*: - The tree had exactly *n* vertices. - The tree had diameter *d*. In other words, *d* was the biggest distance between two vertices. - Limak also remembers that he once rooted the tree in vertex 1 and after that its height was *h*. In other words, *h* was the biggest distance between vertex 1 and some other vertex. The distance between two vertices of the tree is the number of edges on the simple path between them. Help Limak to restore his tree. Check whether there exists a tree satisfying the given conditions. Find any such tree and print its edges in any order. It's also possible that Limak made a mistake and there is no suitable tree – in this case print "-1". Input Specification: The first line contains three integers *n*, *d* and *h* (2<=≤<=*n*<=≤<=100<=000,<=1<=≤<=*h*<=≤<=*d*<=≤<=*n*<=-<=1) — the number of vertices, diameter, and height after rooting in vertex 1, respectively. Output Specification: If there is no tree matching what Limak remembers, print the only line with "-1" (without the quotes). Otherwise, describe any tree matching Limak's description. Print *n*<=-<=1 lines, each with two space-separated integers – indices of vertices connected by an edge. If there are many valid trees, print any of them. You can print edges in any order. Demo Input: ['5 3 2\n', '8 5 2\n', '8 4 2\n'] Demo Output: ['1 2\n1 3\n3 4\n3 5', '-1\n', '4 8\n5 7\n2 3\n8 1\n2 1\n5 6\n1 5\n'] Note: Below you can see trees printed to the output in the first sample and the third sample.
```python n,d,h,r=map(int,input().split()+[1]) if(2*h<d):exit(print(-1)) if(h==d):print(1,2);r=2 last,cnt=r,1+r for i in range(d//2): print(last,cnt);last=cnt;cnt+=1 last=r for i in range(d-d//2): print(last,cnt);last=cnt;cnt+=1 for _ in range(n-d-r): print(r,cnt);cnt+=1 ```
0
907
A
Masha and Bears
PROGRAMMING
1,300
[ "brute force", "implementation" ]
null
null
A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larger than the middle car, and the middle car is strictly larger than the smallest car. Masha came to test these cars. She could climb into all cars, but she liked only the smallest car. It's known that a character with size *a* can climb into some car with size *b* if and only if *a*<=≤<=*b*, he or she likes it if and only if he can climb into this car and 2*a*<=≥<=*b*. You are given sizes of bears and Masha. Find out some possible integer non-negative sizes of cars.
You are given four integers *V*1, *V*2, *V*3, *V**m*(1<=≤<=*V**i*<=≤<=100) — sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that *V*1<=&gt;<=*V*2<=&gt;<=*V*3.
Output three integers — sizes of father bear's car, mother bear's car and son bear's car, respectively. If there are multiple possible solutions, print any. If there is no solution, print "-1" (without quotes).
[ "50 30 10 10\n", "100 50 10 21\n" ]
[ "50\n30\n10\n", "-1\n" ]
In first test case all conditions for cars' sizes are satisfied. In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20.
500
[ { "input": "50 30 10 10", "output": "50\n30\n10" }, { "input": "100 50 10 21", "output": "-1" }, { "input": "100 50 19 10", "output": "100\n50\n19" }, { "input": "99 50 25 49", "output": "100\n99\n49" }, { "input": "3 2 1 1", "output": "4\n3\n1" }, { "input": "100 99 98 100", "output": "-1" }, { "input": "100 40 30 40", "output": "-1" }, { "input": "100 50 19 25", "output": "100\n51\n25" }, { "input": "100 50 19 30", "output": "100\n61\n30" }, { "input": "49 48 25 49", "output": "-1" }, { "input": "48 47 23 46", "output": "94\n93\n46" }, { "input": "37 23 16 20", "output": "42\n41\n20" }, { "input": "98 2 1 1", "output": "98\n3\n1" }, { "input": "99 22 13 14", "output": "99\n29\n14" }, { "input": "97 95 3 2", "output": "97\n95\n3" }, { "input": "27 3 2 3", "output": "-1" }, { "input": "13 7 6 2", "output": "-1" }, { "input": "19 17 11 6", "output": "19\n17\n11" }, { "input": "15 6 4 5", "output": "15\n11\n5" }, { "input": "21 3 1 3", "output": "-1" }, { "input": "100 99 98 97", "output": "196\n195\n98" }, { "input": "99 32 13 5", "output": "-1" }, { "input": "5 4 3 1", "output": "-1" }, { "input": "50 20 4 8", "output": "50\n20\n8" }, { "input": "60 30 10 1", "output": "-1" }, { "input": "100 50 10 1", "output": "-1" }, { "input": "40 30 20 10", "output": "40\n30\n20" }, { "input": "50 49 5 10", "output": "50\n49\n10" }, { "input": "99 98 50 97", "output": "196\n195\n97" }, { "input": "50 30 10 5", "output": "50\n30\n10" }, { "input": "4 3 2 1", "output": "4\n3\n2" }, { "input": "100 50 3 1", "output": "-1" } ]
1,548,948,304
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
93
6,963,200
a=list(map(int,input().strip().split())) if a[3]<=a[2] and 2*a[3]>=a[2] and a[1]>a[3]: print(a[0]) print(a[1]) print(a[2]) else: print(-1)
Title: Masha and Bears Time Limit: None seconds Memory Limit: None megabytes Problem Description: A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larger than the middle car, and the middle car is strictly larger than the smallest car. Masha came to test these cars. She could climb into all cars, but she liked only the smallest car. It's known that a character with size *a* can climb into some car with size *b* if and only if *a*<=≤<=*b*, he or she likes it if and only if he can climb into this car and 2*a*<=≥<=*b*. You are given sizes of bears and Masha. Find out some possible integer non-negative sizes of cars. Input Specification: You are given four integers *V*1, *V*2, *V*3, *V**m*(1<=≤<=*V**i*<=≤<=100) — sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that *V*1<=&gt;<=*V*2<=&gt;<=*V*3. Output Specification: Output three integers — sizes of father bear's car, mother bear's car and son bear's car, respectively. If there are multiple possible solutions, print any. If there is no solution, print "-1" (without quotes). Demo Input: ['50 30 10 10\n', '100 50 10 21\n'] Demo Output: ['50\n30\n10\n', '-1\n'] Note: In first test case all conditions for cars' sizes are satisfied. In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20.
```python a=list(map(int,input().strip().split())) if a[3]<=a[2] and 2*a[3]>=a[2] and a[1]>a[3]: print(a[0]) print(a[1]) print(a[2]) else: print(-1) ```
0
208
A
Dubstep
PROGRAMMING
900
[ "strings" ]
null
null
Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them. Let's assume that a song consists of some number of words. To make the dubstep remix of this song, Vasya inserts a certain number of words "WUB" before the first word of the song (the number may be zero), after the last word (the number may be zero), and between words (at least one between any pair of neighbouring words), and then the boy glues together all the words, including "WUB", in one string and plays the song at the club. For example, a song with words "I AM X" can transform into a dubstep remix as "WUBWUBIWUBAMWUBWUBX" and cannot transform into "WUBWUBIAMWUBX". Recently, Petya has heard Vasya's new dubstep track, but since he isn't into modern music, he decided to find out what was the initial song that Vasya remixed. Help Petya restore the original song.
The input consists of a single non-empty string, consisting only of uppercase English letters, the string's length doesn't exceed 200 characters. It is guaranteed that before Vasya remixed the song, no word contained substring "WUB" in it; Vasya didn't change the word order. It is also guaranteed that initially the song had at least one word.
Print the words of the initial song that Vasya used to make a dubsteb remix. Separate the words with a space.
[ "WUBWUBABCWUB\n", "WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB\n" ]
[ "ABC ", "WE ARE THE CHAMPIONS MY FRIEND " ]
In the first sample: "WUBWUBABCWUB" = "WUB" + "WUB" + "ABC" + "WUB". That means that the song originally consisted of a single word "ABC", and all words "WUB" were added by Vasya. In the second sample Vasya added a single word "WUB" between all neighbouring words, in the beginning and in the end, except for words "ARE" and "THE" — between them Vasya added two "WUB".
500
[ { "input": "WUBWUBABCWUB", "output": "ABC " }, { "input": "WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB", "output": "WE ARE THE CHAMPIONS MY FRIEND " }, { "input": "WUBWUBWUBSR", "output": "SR " }, { "input": "RWUBWUBWUBLWUB", "output": "R L " }, { "input": "ZJWUBWUBWUBJWUBWUBWUBL", "output": "ZJ J L " }, { "input": "CWUBBWUBWUBWUBEWUBWUBWUBQWUBWUBWUB", "output": "C B E Q " }, { "input": "WUBJKDWUBWUBWBIRAQKFWUBWUBYEWUBWUBWUBWVWUBWUB", "output": "JKD WBIRAQKF YE WV " }, { "input": "WUBKSDHEMIXUJWUBWUBRWUBWUBWUBSWUBWUBWUBHWUBWUBWUB", "output": "KSDHEMIXUJ R S H " }, { "input": "OGWUBWUBWUBXWUBWUBWUBIWUBWUBWUBKOWUBWUB", "output": "OG X I KO " }, { "input": "QWUBQQWUBWUBWUBIWUBWUBWWWUBWUBWUBJOPJPBRH", "output": "Q QQ I WW JOPJPBRH " }, { "input": "VSRNVEATZTLGQRFEGBFPWUBWUBWUBAJWUBWUBWUBPQCHNWUBCWUB", "output": "VSRNVEATZTLGQRFEGBFP AJ PQCHN C " }, { "input": "WUBWUBEWUBWUBWUBIQMJNIQWUBWUBWUBGZZBQZAUHYPWUBWUBWUBPMRWUBWUBWUBDCV", "output": "E IQMJNIQ GZZBQZAUHYP PMR DCV " }, { "input": "WUBWUBWUBFVWUBWUBWUBBPSWUBWUBWUBRXNETCJWUBWUBWUBJDMBHWUBWUBWUBBWUBWUBVWUBWUBB", "output": "FV BPS RXNETCJ JDMBH B V B " }, { "input": "WUBWUBWUBFBQWUBWUBWUBIDFSYWUBWUBWUBCTWDMWUBWUBWUBSXOWUBWUBWUBQIWUBWUBWUBL", "output": "FBQ IDFSY CTWDM SXO QI L " }, { "input": "IWUBWUBQLHDWUBYIIKZDFQWUBWUBWUBCXWUBWUBUWUBWUBWUBKWUBWUBWUBNL", "output": "I QLHD YIIKZDFQ CX U K NL " }, { "input": "KWUBUPDYXGOKUWUBWUBWUBAGOAHWUBIZDWUBWUBWUBIYWUBWUBWUBVWUBWUBWUBPWUBWUBWUBE", "output": "K UPDYXGOKU AGOAH IZD IY V P E " }, { "input": "WUBWUBOWUBWUBWUBIPVCQAFWYWUBWUBWUBQWUBWUBWUBXHDKCPYKCTWWYWUBWUBWUBVWUBWUBWUBFZWUBWUB", "output": "O IPVCQAFWY Q XHDKCPYKCTWWY V FZ " }, { "input": "PAMJGYWUBWUBWUBXGPQMWUBWUBWUBTKGSXUYWUBWUBWUBEWUBWUBWUBNWUBWUBWUBHWUBWUBWUBEWUBWUB", "output": "PAMJGY XGPQM TKGSXUY E N H E " }, { "input": "WUBYYRTSMNWUWUBWUBWUBCWUBWUBWUBCWUBWUBWUBFSYUINDWOBVWUBWUBWUBFWUBWUBWUBAUWUBWUBWUBVWUBWUBWUBJB", "output": "YYRTSMNWU C C FSYUINDWOBV F AU V JB " }, { "input": "WUBWUBYGPYEYBNRTFKOQCWUBWUBWUBUYGRTQEGWLFYWUBWUBWUBFVWUBHPWUBWUBWUBXZQWUBWUBWUBZDWUBWUBWUBM", "output": "YGPYEYBNRTFKOQC UYGRTQEGWLFY FV HP XZQ ZD M " }, { "input": "WUBZVMJWUBWUBWUBFOIMJQWKNZUBOFOFYCCWUBWUBWUBAUWWUBRDRADWUBWUBWUBCHQVWUBWUBWUBKFTWUBWUBWUBW", "output": "ZVMJ FOIMJQWKNZUBOFOFYCC AUW RDRAD CHQV KFT W " }, { "input": "WUBWUBZBKOKHQLGKRVIMZQMQNRWUBWUBWUBDACWUBWUBNZHFJMPEYKRVSWUBWUBWUBPPHGAVVPRZWUBWUBWUBQWUBWUBAWUBG", "output": "ZBKOKHQLGKRVIMZQMQNR DAC NZHFJMPEYKRVS PPHGAVVPRZ Q A G " }, { "input": "WUBWUBJWUBWUBWUBNFLWUBWUBWUBGECAWUBYFKBYJWTGBYHVSSNTINKWSINWSMAWUBWUBWUBFWUBWUBWUBOVWUBWUBLPWUBWUBWUBN", "output": "J NFL GECA YFKBYJWTGBYHVSSNTINKWSINWSMA F OV LP N " }, { "input": "WUBWUBLCWUBWUBWUBZGEQUEATJVIXETVTWUBWUBWUBEXMGWUBWUBWUBRSWUBWUBWUBVWUBWUBWUBTAWUBWUBWUBCWUBWUBWUBQG", "output": "LC ZGEQUEATJVIXETVT EXMG RS V TA C QG " }, { "input": "WUBMPWUBWUBWUBORWUBWUBDLGKWUBWUBWUBVVZQCAAKVJTIKWUBWUBWUBTJLUBZJCILQDIFVZWUBWUBYXWUBWUBWUBQWUBWUBWUBLWUB", "output": "MP OR DLGK VVZQCAAKVJTIK TJLUBZJCILQDIFVZ YX Q L " }, { "input": "WUBNXOLIBKEGXNWUBWUBWUBUWUBGITCNMDQFUAOVLWUBWUBWUBAIJDJZJHFMPVTPOXHPWUBWUBWUBISCIOWUBWUBWUBGWUBWUBWUBUWUB", "output": "NXOLIBKEGXN U GITCNMDQFUAOVL AIJDJZJHFMPVTPOXHP ISCIO G U " }, { "input": "WUBWUBNMMWCZOLYPNBELIYVDNHJUNINWUBWUBWUBDXLHYOWUBWUBWUBOJXUWUBWUBWUBRFHTGJCEFHCGWARGWUBWUBWUBJKWUBWUBSJWUBWUB", "output": "NMMWCZOLYPNBELIYVDNHJUNIN DXLHYO OJXU RFHTGJCEFHCGWARG JK SJ " }, { "input": "SGWLYSAUJOJBNOXNWUBWUBWUBBOSSFWKXPDPDCQEWUBWUBWUBDIRZINODWUBWUBWUBWWUBWUBWUBPPHWUBWUBWUBRWUBWUBWUBQWUBWUBWUBJWUB", "output": "SGWLYSAUJOJBNOXN BOSSFWKXPDPDCQE DIRZINOD W PPH R Q J " }, { "input": "TOWUBWUBWUBGBTBNWUBWUBWUBJVIOJBIZFUUYHUAIEBQLQXPQKZJMPTCWBKPOSAWUBWUBWUBSWUBWUBWUBTOLVXWUBWUBWUBNHWUBWUBWUBO", "output": "TO GBTBN JVIOJBIZFUUYHUAIEBQLQXPQKZJMPTCWBKPOSA S TOLVX NH O " }, { "input": "WUBWUBWSPLAYSZSAUDSWUBWUBWUBUWUBWUBWUBKRWUBWUBWUBRSOKQMZFIYZQUWUBWUBWUBELSHUWUBWUBWUBUKHWUBWUBWUBQXEUHQWUBWUBWUBBWUBWUBWUBR", "output": "WSPLAYSZSAUDS U KR RSOKQMZFIYZQU ELSHU UKH QXEUHQ B R " }, { "input": "WUBXEMWWVUHLSUUGRWUBWUBWUBAWUBXEGILZUNKWUBWUBWUBJDHHKSWUBWUBWUBDTSUYSJHWUBWUBWUBPXFWUBMOHNJWUBWUBWUBZFXVMDWUBWUBWUBZMWUBWUB", "output": "XEMWWVUHLSUUGR A XEGILZUNK JDHHKS DTSUYSJH PXF MOHNJ ZFXVMD ZM " }, { "input": "BMBWUBWUBWUBOQKWUBWUBWUBPITCIHXHCKLRQRUGXJWUBWUBWUBVWUBWUBWUBJCWUBWUBWUBQJPWUBWUBWUBBWUBWUBWUBBMYGIZOOXWUBWUBWUBTAGWUBWUBHWUB", "output": "BMB OQK PITCIHXHCKLRQRUGXJ V JC QJP B BMYGIZOOX TAG H " }, { "input": "CBZNWUBWUBWUBNHWUBWUBWUBYQSYWUBWUBWUBMWUBWUBWUBXRHBTMWUBWUBWUBPCRCWUBWUBWUBTZUYLYOWUBWUBWUBCYGCWUBWUBWUBCLJWUBWUBWUBSWUBWUBWUB", "output": "CBZN NH YQSY M XRHBTM PCRC TZUYLYO CYGC CLJ S " }, { "input": "DPDWUBWUBWUBEUQKWPUHLTLNXHAEKGWUBRRFYCAYZFJDCJLXBAWUBWUBWUBHJWUBOJWUBWUBWUBNHBJEYFWUBWUBWUBRWUBWUBWUBSWUBWWUBWUBWUBXDWUBWUBWUBJWUB", "output": "DPD EUQKWPUHLTLNXHAEKG RRFYCAYZFJDCJLXBA HJ OJ NHBJEYF R S W XD J " }, { "input": "WUBWUBWUBISERPQITVIYERSCNWUBWUBWUBQWUBWUBWUBDGSDIPWUBWUBWUBCAHKDZWEXBIBJVVSKKVQJWUBWUBWUBKIWUBWUBWUBCWUBWUBWUBAWUBWUBWUBPWUBWUBWUBHWUBWUBWUBF", "output": "ISERPQITVIYERSCN Q DGSDIP CAHKDZWEXBIBJVVSKKVQJ KI C A P H F " }, { "input": "WUBWUBWUBIWUBWUBLIKNQVWUBWUBWUBPWUBWUBWUBHWUBWUBWUBMWUBWUBWUBDPRSWUBWUBWUBBSAGYLQEENWXXVWUBWUBWUBXMHOWUBWUBWUBUWUBWUBWUBYRYWUBWUBWUBCWUBWUBWUBY", "output": "I LIKNQV P H M DPRS BSAGYLQEENWXXV XMHO U YRY C Y " }, { "input": "WUBWUBWUBMWUBWUBWUBQWUBWUBWUBITCFEYEWUBWUBWUBHEUWGNDFNZGWKLJWUBWUBWUBMZPWUBWUBWUBUWUBWUBWUBBWUBWUBWUBDTJWUBHZVIWUBWUBWUBPWUBFNHHWUBWUBWUBVTOWUB", "output": "M Q ITCFEYE HEUWGNDFNZGWKLJ MZP U B DTJ HZVI P FNHH VTO " }, { "input": "WUBWUBNDNRFHYJAAUULLHRRDEDHYFSRXJWUBWUBWUBMUJVDTIRSGYZAVWKRGIFWUBWUBWUBHMZWUBWUBWUBVAIWUBWUBWUBDDKJXPZRGWUBWUBWUBSGXWUBWUBWUBIFKWUBWUBWUBUWUBWUBWUBW", "output": "NDNRFHYJAAUULLHRRDEDHYFSRXJ MUJVDTIRSGYZAVWKRGIF HMZ VAI DDKJXPZRG SGX IFK U W " }, { "input": "WUBOJMWRSLAXXHQRTPMJNCMPGWUBWUBWUBNYGMZIXNLAKSQYWDWUBWUBWUBXNIWUBWUBWUBFWUBWUBWUBXMBWUBWUBWUBIWUBWUBWUBINWUBWUBWUBWDWUBWUBWUBDDWUBWUBWUBD", "output": "OJMWRSLAXXHQRTPMJNCMPG NYGMZIXNLAKSQYWD XNI F XMB I IN WD DD D " }, { "input": "WUBWUBWUBREHMWUBWUBWUBXWUBWUBWUBQASNWUBWUBWUBNLSMHLCMTICWUBWUBWUBVAWUBWUBWUBHNWUBWUBWUBNWUBWUBWUBUEXLSFOEULBWUBWUBWUBXWUBWUBWUBJWUBWUBWUBQWUBWUBWUBAWUBWUB", "output": "REHM X QASN NLSMHLCMTIC VA HN N UEXLSFOEULB X J Q A " }, { "input": "WUBWUBWUBSTEZTZEFFIWUBWUBWUBSWUBWUBWUBCWUBFWUBHRJPVWUBWUBWUBDYJUWUBWUBWUBPWYDKCWUBWUBWUBCWUBWUBWUBUUEOGCVHHBWUBWUBWUBEXLWUBWUBWUBVCYWUBWUBWUBMWUBWUBWUBYWUB", "output": "STEZTZEFFI S C F HRJPV DYJU PWYDKC C UUEOGCVHHB EXL VCY M Y " }, { "input": "WPPNMSQOQIWUBWUBWUBPNQXWUBWUBWUBHWUBWUBWUBNFLWUBWUBWUBGWSGAHVJFNUWUBWUBWUBFWUBWUBWUBWCMLRICFSCQQQTNBWUBWUBWUBSWUBWUBWUBKGWUBWUBWUBCWUBWUBWUBBMWUBWUBWUBRWUBWUB", "output": "WPPNMSQOQI PNQX H NFL GWSGAHVJFNU F WCMLRICFSCQQQTNB S KG C BM R " }, { "input": "YZJOOYITZRARKVFYWUBWUBRZQGWUBWUBWUBUOQWUBWUBWUBIWUBWUBWUBNKVDTBOLETKZISTWUBWUBWUBWLWUBQQFMMGSONZMAWUBZWUBWUBWUBQZUXGCWUBWUBWUBIRZWUBWUBWUBLTTVTLCWUBWUBWUBY", "output": "YZJOOYITZRARKVFY RZQG UOQ I NKVDTBOLETKZIST WL QQFMMGSONZMA Z QZUXGC IRZ LTTVTLC Y " }, { "input": "WUBCAXNCKFBVZLGCBWCOAWVWOFKZVQYLVTWUBWUBWUBNLGWUBWUBWUBAMGDZBDHZMRMQMDLIRMIWUBWUBWUBGAJSHTBSWUBWUBWUBCXWUBWUBWUBYWUBZLXAWWUBWUBWUBOHWUBWUBWUBZWUBWUBWUBGBWUBWUBWUBE", "output": "CAXNCKFBVZLGCBWCOAWVWOFKZVQYLVT NLG AMGDZBDHZMRMQMDLIRMI GAJSHTBS CX Y ZLXAW OH Z GB E " }, { "input": "WUBWUBCHXSOWTSQWUBWUBWUBCYUZBPBWUBWUBWUBSGWUBWUBWKWORLRRLQYUUFDNWUBWUBWUBYYGOJNEVEMWUBWUBWUBRWUBWUBWUBQWUBWUBWUBIHCKWUBWUBWUBKTWUBWUBWUBRGSNTGGWUBWUBWUBXCXWUBWUBWUBS", "output": "CHXSOWTSQ CYUZBPB SG WKWORLRRLQYUUFDN YYGOJNEVEM R Q IHCK KT RGSNTGG XCX S " }, { "input": "WUBWUBWUBHJHMSBURXTHXWSCHNAIJOWBHLZGJZDHEDSPWBWACCGQWUBWUBWUBXTZKGIITWUBWUBWUBAWUBWUBWUBVNCXPUBCQWUBWUBWUBIDPNAWUBWUBWUBOWUBWUBWUBYGFWUBWUBWUBMQOWUBWUBWUBKWUBWUBWUBAZVWUBWUBWUBEP", "output": "HJHMSBURXTHXWSCHNAIJOWBHLZGJZDHEDSPWBWACCGQ XTZKGIIT A VNCXPUBCQ IDPNA O YGF MQO K AZV EP " }, { "input": "WUBKYDZOYWZSNGMKJSWAXFDFLTHDHEOGTDBNZMSMKZTVWUBWUBWUBLRMIIWUBWUBWUBGWUBWUBWUBADPSWUBWUBWUBANBWUBWUBPCWUBWUBWUBPWUBWUBWUBGPVNLSWIRFORYGAABUXMWUBWUBWUBOWUBWUBWUBNWUBWUBWUBYWUBWUB", "output": "KYDZOYWZSNGMKJSWAXFDFLTHDHEOGTDBNZMSMKZTV LRMII G ADPS ANB PC P GPVNLSWIRFORYGAABUXM O N Y " }, { "input": "REWUBWUBWUBJDWUBWUBWUBNWUBWUBWUBTWWUBWUBWUBWZDOCKKWUBWUBWUBLDPOVBFRCFWUBWUBAKZIBQKEUAZEEWUBWUBWUBLQYPNPFWUBYEWUBWUBWUBFWUBWUBWUBBPWUBWUBWUBAWWUBWUBWUBQWUBWUBWUBBRWUBWUBWUBXJL", "output": "RE JD N TW WZDOCKK LDPOVBFRCF AKZIBQKEUAZEE LQYPNPF YE F BP AW Q BR XJL " }, { "input": "CUFGJDXGMWUBWUBWUBOMWUBWUBWUBSIEWUBWUBWUBJJWKNOWUBWUBWUBYBHVNRNORGYWUBWUBWUBOAGCAWUBWUBWUBSBLBKTPFKPBIWUBWUBWUBJBWUBWUBWUBRMFCJPGWUBWUBWUBDWUBWUBWUBOJOWUBWUBWUBZPWUBWUBWUBMWUBRWUBWUBWUBFXWWUBWUBWUBO", "output": "CUFGJDXGM OM SIE JJWKNO YBHVNRNORGY OAGCA SBLBKTPFKPBI JB RMFCJPG D OJO ZP M R FXW O " }, { "input": "WUBJZGAEXFMFEWMAKGQLUWUBWUBWUBICYTPQWGENELVYWANKUOJYWUBWUBWUBGWUBWUBWUBHYCJVLPHTUPNEGKCDGQWUBWUBWUBOFWUBWUBWUBCPGSOGZBRPRPVJJEWUBWUBWUBDQBCWUBWUBWUBHWUBWUBWUBMHOHYBMATWUBWUBWUBVWUBWUBWUBSWUBWUBWUBKOWU", "output": "JZGAEXFMFEWMAKGQLU ICYTPQWGENELVYWANKUOJY G HYCJVLPHTUPNEGKCDGQ OF CPGSOGZBRPRPVJJE DQBC H MHOHYBMAT V S KOWU " }, { "input": "A", "output": "A " }, { "input": "WUBA", "output": "A " }, { "input": "WUBWUBA", "output": "A " }, { "input": "AWUBWUBWUB", "output": "A " }, { "input": "AWUBBWUBCWUBD", "output": "A B C D " }, { "input": "WUBWWUBWUBWUBUWUBWUBBWUB", "output": "W U B " }, { "input": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "output": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA " }, { "input": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAWUBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "output": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA " }, { "input": "WUWUBBWWUBUB", "output": "WU BW UB " }, { "input": "WUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUABWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUB", "output": "WUAB " }, { "input": "ZWUB", "output": "Z " }, { "input": "WU", "output": "WU " }, { "input": "UB", "output": "UB " }, { "input": "U", "output": "U " }, { "input": "WUBW", "output": "W " }, { "input": "WUBWU", "output": "WU " }, { "input": "WUWUB", "output": "WU " }, { "input": "UBWUB", "output": "UB " }, { "input": "WUWUBUBWUBUWUB", "output": "WU UB U " }, { "input": "WUBWWUBAWUB", "output": "W A " }, { "input": "WUUUUU", "output": "WUUUUU " } ]
1,682,144,397
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
62
0
s=input() i=0 flag=0 while(i<len(s)-3): if(s[i]=='W' and s[i+1]=='U' and s[i+2]=='B'): i=i+3 #flag=1 # #print(i,s[i],"HI") # if(flag==1): # print(" ",end='') else: print(s[i],end='') i+=1 #flag=1 if(s[i+1]=='W' and s[i+2]=='U' and s[i+3]=='B'): print(" ",end='')
Title: Dubstep Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them. Let's assume that a song consists of some number of words. To make the dubstep remix of this song, Vasya inserts a certain number of words "WUB" before the first word of the song (the number may be zero), after the last word (the number may be zero), and between words (at least one between any pair of neighbouring words), and then the boy glues together all the words, including "WUB", in one string and plays the song at the club. For example, a song with words "I AM X" can transform into a dubstep remix as "WUBWUBIWUBAMWUBWUBX" and cannot transform into "WUBWUBIAMWUBX". Recently, Petya has heard Vasya's new dubstep track, but since he isn't into modern music, he decided to find out what was the initial song that Vasya remixed. Help Petya restore the original song. Input Specification: The input consists of a single non-empty string, consisting only of uppercase English letters, the string's length doesn't exceed 200 characters. It is guaranteed that before Vasya remixed the song, no word contained substring "WUB" in it; Vasya didn't change the word order. It is also guaranteed that initially the song had at least one word. Output Specification: Print the words of the initial song that Vasya used to make a dubsteb remix. Separate the words with a space. Demo Input: ['WUBWUBABCWUB\n', 'WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB\n'] Demo Output: ['ABC ', 'WE ARE THE CHAMPIONS MY FRIEND '] Note: In the first sample: "WUBWUBABCWUB" = "WUB" + "WUB" + "ABC" + "WUB". That means that the song originally consisted of a single word "ABC", and all words "WUB" were added by Vasya. In the second sample Vasya added a single word "WUB" between all neighbouring words, in the beginning and in the end, except for words "ARE" and "THE" — between them Vasya added two "WUB".
```python s=input() i=0 flag=0 while(i<len(s)-3): if(s[i]=='W' and s[i+1]=='U' and s[i+2]=='B'): i=i+3 #flag=1 # #print(i,s[i],"HI") # if(flag==1): # print(" ",end='') else: print(s[i],end='') i+=1 #flag=1 if(s[i+1]=='W' and s[i+2]=='U' and s[i+3]=='B'): print(" ",end='') ```
0
0
none
none
none
0
[ "none" ]
null
null
Little Artem likes electronics. He can spend lots of time making different schemas and looking for novelties in the nearest electronics store. The new control element was delivered to the store recently and Artem immediately bought it. That element can store information about the matrix of integers size *n*<=×<=*m*. There are *n*<=+<=*m* inputs in that element, i.e. each row and each column can get the signal. When signal comes to the input corresponding to some row, this row cyclically shifts to the left, that is the first element of the row becomes last element, second element becomes first and so on. When signal comes to the input corresponding to some column, that column shifts cyclically to the top, that is first element of the column becomes last element, second element becomes first and so on. Rows are numbered with integers from 1 to *n* from top to bottom, while columns are numbered with integers from 1 to *m* from left to right. Artem wants to carefully study this element before using it. For that purpose he is going to set up an experiment consisting of *q* turns. On each turn he either sends the signal to some input or checks what number is stored at some position of the matrix. Artem has completed his experiment and has written down the results, but he has lost the chip! Help Artem find any initial matrix that will match the experiment results. It is guaranteed that experiment data is consistent, which means at least one valid matrix exists.
The first line of the input contains three integers *n*, *m* and *q* (1<=≤<=*n*,<=*m*<=≤<=100,<=1<=≤<=*q*<=≤<=10<=000) — dimensions of the matrix and the number of turns in the experiment, respectively. Next *q* lines contain turns descriptions, one per line. Each description starts with an integer *t**i* (1<=≤<=*t**i*<=≤<=3) that defines the type of the operation. For the operation of first and second type integer *r**i* (1<=≤<=*r**i*<=≤<=*n*) or *c**i* (1<=≤<=*c**i*<=≤<=*m*) follows, while for the operations of the third type three integers *r**i*, *c**i* and *x**i* (1<=≤<=*r**i*<=≤<=*n*, 1<=≤<=*c**i*<=≤<=*m*, <=-<=109<=≤<=*x**i*<=≤<=109) are given. Operation of the first type (*t**i*<==<=1) means that signal comes to the input corresponding to row *r**i*, that is it will shift cyclically. Operation of the second type (*t**i*<==<=2) means that column *c**i* will shift cyclically. Finally, operation of the third type means that at this moment of time cell located in the row *r**i* and column *c**i* stores value *x**i*.
Print the description of any valid initial matrix as *n* lines containing *m* integers each. All output integers should not exceed 109 by their absolute value. If there are multiple valid solutions, output any of them.
[ "2 2 6\n2 1\n2 2\n3 1 1 1\n3 2 2 2\n3 1 2 8\n3 2 1 8\n", "3 3 2\n1 2\n3 2 2 5\n" ]
[ "8 2 \n1 8 \n", "0 0 0 \n0 0 5 \n0 0 0 \n" ]
none
0
[ { "input": "2 2 6\n2 1\n2 2\n3 1 1 1\n3 2 2 2\n3 1 2 8\n3 2 1 8", "output": "8 2 \n1 8 " }, { "input": "3 3 2\n1 2\n3 2 2 5", "output": "0 0 0 \n0 0 5 \n0 0 0 " }, { "input": "5 5 1\n1 5", "output": "0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 " }, { "input": "1 1 3\n1 1\n2 1\n3 1 1 1000000000", "output": "1000000000 " }, { "input": "1 1 3\n1 1\n2 1\n3 1 1 -1000000000", "output": "-1000000000 " }, { "input": "2 2 6\n2 1\n2 2\n3 1 1 -1\n3 2 2 -1\n3 1 2 -1\n3 2 1 -1", "output": "-1 -1 \n-1 -1 " }, { "input": "1 4 5\n1 1\n3 1 1 1\n3 1 2 2\n3 1 3 3\n3 1 4 4", "output": "4 1 2 3 " }, { "input": "4 2 5\n2 1\n3 1 1 5\n3 2 1 6\n3 3 1 7\n3 4 1 9", "output": "9 0 \n5 0 \n6 0 \n7 0 " }, { "input": "3 10 2\n1 2\n3 2 7 5", "output": "0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 0 0 5 0 0 \n0 0 0 0 0 0 0 0 0 0 " }, { "input": "1 2 2\n1 1\n3 1 2 15", "output": "15 0 " } ]
1,462,614,124
3,004
Python 3
WRONG_ANSWER
TESTS
5
93
5,120,000
def mp(): return map(int,input().split()) def lt(): return list(map(int,input().split())) def pt(x): print(x) def ip(): return input() def it(): return int(input()) def sl(x): return [t for t in x] def spl(x): return x.split() def aj(liste, item): liste.append(item) def bin(x): return "{0:b}".format(x) def listring(l): return ' '.join([str(x) for x in l]) def printlist(l): print(' '.join([str(x) for x in l])) n,m,q = mp() a = [[0 for i in range(m)] for j in range(n)] row = [0 for _ in range(n)] col = [0 for _ in range(m)] for _ in range(q): b = lt() if b[0] == 1: row[(b[1]-1)%n] += 1 elif b[0] == 2: col[(b[1]-1)%m] += 1 else: r,c,x = b[1],b[2],b[3] a[(r+col[c-1]-1)%n][(c+row[r-1]-1)%m] = x for j in range(n): printlist(a[j])
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Artem likes electronics. He can spend lots of time making different schemas and looking for novelties in the nearest electronics store. The new control element was delivered to the store recently and Artem immediately bought it. That element can store information about the matrix of integers size *n*<=×<=*m*. There are *n*<=+<=*m* inputs in that element, i.e. each row and each column can get the signal. When signal comes to the input corresponding to some row, this row cyclically shifts to the left, that is the first element of the row becomes last element, second element becomes first and so on. When signal comes to the input corresponding to some column, that column shifts cyclically to the top, that is first element of the column becomes last element, second element becomes first and so on. Rows are numbered with integers from 1 to *n* from top to bottom, while columns are numbered with integers from 1 to *m* from left to right. Artem wants to carefully study this element before using it. For that purpose he is going to set up an experiment consisting of *q* turns. On each turn he either sends the signal to some input or checks what number is stored at some position of the matrix. Artem has completed his experiment and has written down the results, but he has lost the chip! Help Artem find any initial matrix that will match the experiment results. It is guaranteed that experiment data is consistent, which means at least one valid matrix exists. Input Specification: The first line of the input contains three integers *n*, *m* and *q* (1<=≤<=*n*,<=*m*<=≤<=100,<=1<=≤<=*q*<=≤<=10<=000) — dimensions of the matrix and the number of turns in the experiment, respectively. Next *q* lines contain turns descriptions, one per line. Each description starts with an integer *t**i* (1<=≤<=*t**i*<=≤<=3) that defines the type of the operation. For the operation of first and second type integer *r**i* (1<=≤<=*r**i*<=≤<=*n*) or *c**i* (1<=≤<=*c**i*<=≤<=*m*) follows, while for the operations of the third type three integers *r**i*, *c**i* and *x**i* (1<=≤<=*r**i*<=≤<=*n*, 1<=≤<=*c**i*<=≤<=*m*, <=-<=109<=≤<=*x**i*<=≤<=109) are given. Operation of the first type (*t**i*<==<=1) means that signal comes to the input corresponding to row *r**i*, that is it will shift cyclically. Operation of the second type (*t**i*<==<=2) means that column *c**i* will shift cyclically. Finally, operation of the third type means that at this moment of time cell located in the row *r**i* and column *c**i* stores value *x**i*. Output Specification: Print the description of any valid initial matrix as *n* lines containing *m* integers each. All output integers should not exceed 109 by their absolute value. If there are multiple valid solutions, output any of them. Demo Input: ['2 2 6\n2 1\n2 2\n3 1 1 1\n3 2 2 2\n3 1 2 8\n3 2 1 8\n', '3 3 2\n1 2\n3 2 2 5\n'] Demo Output: ['8 2 \n1 8 \n', '0 0 0 \n0 0 5 \n0 0 0 \n'] Note: none
```python def mp(): return map(int,input().split()) def lt(): return list(map(int,input().split())) def pt(x): print(x) def ip(): return input() def it(): return int(input()) def sl(x): return [t for t in x] def spl(x): return x.split() def aj(liste, item): liste.append(item) def bin(x): return "{0:b}".format(x) def listring(l): return ' '.join([str(x) for x in l]) def printlist(l): print(' '.join([str(x) for x in l])) n,m,q = mp() a = [[0 for i in range(m)] for j in range(n)] row = [0 for _ in range(n)] col = [0 for _ in range(m)] for _ in range(q): b = lt() if b[0] == 1: row[(b[1]-1)%n] += 1 elif b[0] == 2: col[(b[1]-1)%m] += 1 else: r,c,x = b[1],b[2],b[3] a[(r+col[c-1]-1)%n][(c+row[r-1]-1)%m] = x for j in range(n): printlist(a[j]) ```
0
766
B
Mahmoud and a Triangle
PROGRAMMING
1,000
[ "constructive algorithms", "geometry", "greedy", "math", "number theory", "sortings" ]
null
null
Mahmoud has *n* line segments, the *i*-th of them has length *a**i*. Ehab challenged him to use exactly 3 line segments to form a non-degenerate triangle. Mahmoud doesn't accept challenges unless he is sure he can win, so he asked you to tell him if he should accept the challenge. Given the lengths of the line segments, check if he can choose exactly 3 of them to form a non-degenerate triangle. Mahmoud should use exactly 3 line segments, he can't concatenate two line segments or change any length. A non-degenerate triangle is a triangle with positive area.
The first line contains single integer *n* (3<=≤<=*n*<=≤<=105) — the number of line segments Mahmoud has. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the lengths of line segments Mahmoud has.
In the only line print "YES" if he can choose exactly three line segments and form a non-degenerate triangle with them, and "NO" otherwise.
[ "5\n1 5 3 2 4\n", "3\n4 1 2\n" ]
[ "YES\n", "NO\n" ]
For the first example, he can use line segments with lengths 2, 4 and 5 to form a non-degenerate triangle.
1,000
[ { "input": "5\n1 5 3 2 4", "output": "YES" }, { "input": "3\n4 1 2", "output": "NO" }, { "input": "30\n197 75 517 39724 7906061 1153471 3 15166 168284 3019844 272293 316 16 24548 42 118 5792 5 9373 1866366 4886214 24 2206 712886 104005 1363 836 64273 440585 3576", "output": "NO" }, { "input": "30\n229017064 335281886 247217656 670601882 743442492 615491486 544941439 911270108 474843964 803323771 177115397 62179276 390270885 754889875 881720571 902691435 154083299 328505383 761264351 182674686 94104683 357622370 573909964 320060691 33548810 247029007 812823597 946798893 813659359 710111761", "output": "YES" }, { "input": "40\n740553458 532562042 138583675 75471987 487348843 476240280 972115023 103690894 546736371 915774563 35356828 819948191 138721993 24257926 761587264 767176616 608310208 78275645 386063134 227581756 672567198 177797611 87579917 941781518 274774331 843623616 981221615 630282032 118843963 749160513 354134861 132333165 405839062 522698334 29698277 541005920 856214146 167344951 398332403 68622974", "output": "YES" }, { "input": "40\n155 1470176 7384 765965701 1075 4 561554 6227772 93 16304522 1744 662 3 292572860 19335 908613 42685804 347058 20 132560 3848974 69067081 58 2819 111752888 408 81925 30 11951 4564 251 26381275 473392832 50628 180819969 2378797 10076746 9 214492 31291", "output": "NO" }, { "input": "3\n1 1000000000 1000000000", "output": "YES" }, { "input": "4\n1 1000000000 1000000000 1000000000", "output": "YES" }, { "input": "3\n1 1000000000 1", "output": "NO" }, { "input": "5\n1 2 3 5 2", "output": "YES" }, { "input": "41\n19 161 4090221 118757367 2 45361275 1562319 596751 140871 97 1844 310910829 10708344 6618115 698 1 87059 33 2527892 12703 73396090 17326460 3 368811 20550 813975131 10 53804 28034805 7847 2992 33254 1139 227930 965568 261 4846 503064297 192153458 57 431", "output": "NO" }, { "input": "42\n4317083 530966905 202811311 104 389267 35 1203 18287479 125344279 21690 859122498 65 859122508 56790 1951 148683 457 1 22 2668100 8283 2 77467028 13405 11302280 47877251 328155592 35095 29589769 240574 4 10 1019123 6985189 629846 5118 169 1648973 91891 741 282 3159", "output": "YES" }, { "input": "43\n729551585 11379 5931704 330557 1653 15529406 729551578 278663905 1 729551584 2683 40656510 29802 147 1400284 2 126260 865419 51 17 172223763 86 1 534861 450887671 32 234 25127103 9597697 48226 7034 389 204294 2265706 65783617 4343 3665990 626 78034 106440137 5 18421 1023", "output": "YES" }, { "input": "44\n719528276 2 235 444692918 24781885 169857576 18164 47558 15316043 9465834 64879816 2234575 1631 853530 8 1001 621 719528259 84 6933 31 1 3615623 719528266 40097928 274835337 1381044 11225 2642 5850203 6 527506 18 104977753 76959 29393 49 4283 141 201482 380 1 124523 326015", "output": "YES" }, { "input": "45\n28237 82 62327732 506757 691225170 5 970 4118 264024506 313192 367 14713577 73933 691225154 6660 599 691225145 3473403 51 427200630 1326718 2146678 100848386 1569 27 163176119 193562 10784 45687 819951 38520653 225 119620 1 3 691225169 691225164 17445 23807072 1 9093493 5620082 2542 139 14", "output": "YES" }, { "input": "44\n165580141 21 34 55 1 89 144 17711 2 377 610 987 2584 13 5 4181 6765 10946 1597 8 28657 3 233 75025 121393 196418 317811 9227465 832040 1346269 2178309 3524578 5702887 1 14930352 102334155 24157817 39088169 63245986 701408733 267914296 433494437 514229 46368", "output": "NO" }, { "input": "3\n1 1000000000 999999999", "output": "NO" }, { "input": "5\n1 1 1 1 1", "output": "YES" }, { "input": "10\n1 10 100 1000 10000 100000 1000000 10000000 100000000 1000000000", "output": "NO" }, { "input": "5\n2 3 4 10 20", "output": "YES" }, { "input": "6\n18 23 40 80 160 161", "output": "YES" }, { "input": "4\n5 6 7 888", "output": "YES" }, { "input": "9\n1 1 2 2 4 5 10 10 20", "output": "YES" }, { "input": "7\n3 150 900 4 500 1500 5", "output": "YES" }, { "input": "3\n2 2 3", "output": "YES" }, { "input": "7\n1 2 100 200 250 1000000 2000000", "output": "YES" }, { "input": "8\n2 3 5 5 5 6 6 13", "output": "YES" }, { "input": "3\n2 3 4", "output": "YES" }, { "input": "6\n1 1 1 4 5 100", "output": "YES" }, { "input": "13\n1 2 3 5 8 13 22 34 55 89 144 233 377", "output": "YES" }, { "input": "4\n2 3 4 8", "output": "YES" }, { "input": "3\n5 6 7", "output": "YES" }, { "input": "5\n1 4 5 6 1000000", "output": "YES" }, { "input": "4\n5 6 7 20", "output": "YES" }, { "input": "6\n1 1 1 1 1 65", "output": "YES" }, { "input": "4\n3 4 5 100", "output": "YES" }, { "input": "3\n2 4 5", "output": "YES" }, { "input": "7\n1 1 1 1 1 10 1000", "output": "YES" }, { "input": "4\n1 1 2 3", "output": "NO" }, { "input": "11\n1 2 5 6 7 8 9 17 18 19 100", "output": "YES" }, { "input": "4\n5 16 20 200", "output": "YES" }, { "input": "5\n17 6 3 3 1", "output": "YES" }, { "input": "3\n1 1 1", "output": "YES" }, { "input": "6\n1 1 1 2 3 5", "output": "YES" }, { "input": "4\n2 4 6 6", "output": "YES" }, { "input": "9\n1 2 4 4 4 4 7 8 20", "output": "YES" }, { "input": "9\n1 1 2 5 5 5 10 10 20", "output": "YES" }, { "input": "7\n3 150 600 4 1700 6000 5", "output": "YES" }, { "input": "5\n5761 20966 27841 28800 29399", "output": "YES" }, { "input": "9\n1 2 3 6 7 10 11 12 24", "output": "YES" }, { "input": "4\n1 2 1 1", "output": "YES" }, { "input": "5\n1 1 2 3 4", "output": "YES" } ]
1,670,702,270
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
31
155
8,601,600
import math from collections import * def solve(): n = int(input()) a = [int(i) for i in input().split()] a.sort() t = defaultdict(int) for i in a: if i!=1: t[i]+=1 # print(t) for i in t: if t[i]>=2: print("YES") return d = (a[-1] + a[-2] + a[-3]) / 2 # print(d) if a[-1] >= d or a[-2] >= d or a[-3] >= d: print("NO") else: print('YES') # t = int(input()) # for _ in range(t): # solve() solve()
Title: Mahmoud and a Triangle Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mahmoud has *n* line segments, the *i*-th of them has length *a**i*. Ehab challenged him to use exactly 3 line segments to form a non-degenerate triangle. Mahmoud doesn't accept challenges unless he is sure he can win, so he asked you to tell him if he should accept the challenge. Given the lengths of the line segments, check if he can choose exactly 3 of them to form a non-degenerate triangle. Mahmoud should use exactly 3 line segments, he can't concatenate two line segments or change any length. A non-degenerate triangle is a triangle with positive area. Input Specification: The first line contains single integer *n* (3<=≤<=*n*<=≤<=105) — the number of line segments Mahmoud has. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the lengths of line segments Mahmoud has. Output Specification: In the only line print "YES" if he can choose exactly three line segments and form a non-degenerate triangle with them, and "NO" otherwise. Demo Input: ['5\n1 5 3 2 4\n', '3\n4 1 2\n'] Demo Output: ['YES\n', 'NO\n'] Note: For the first example, he can use line segments with lengths 2, 4 and 5 to form a non-degenerate triangle.
```python import math from collections import * def solve(): n = int(input()) a = [int(i) for i in input().split()] a.sort() t = defaultdict(int) for i in a: if i!=1: t[i]+=1 # print(t) for i in t: if t[i]>=2: print("YES") return d = (a[-1] + a[-2] + a[-3]) / 2 # print(d) if a[-1] >= d or a[-2] >= d or a[-3] >= d: print("NO") else: print('YES') # t = int(input()) # for _ in range(t): # solve() solve() ```
0
950
A
Left-handers, Right-handers and Ambidexters
PROGRAMMING
800
[ "implementation", "math" ]
null
null
You are at a water bowling training. There are *l* people who play with their left hand, *r* people, who play with their right hand, and *a* ambidexters, who can play with left or right hand. The coach decided to form a team of even number of players, exactly half of the players should play with their right hand, and exactly half of the players should play with their left hand. One player should use only on of his hands. Ambidexters play as well with their right hand as with their left hand. In the team, an ambidexter can play with their left hand, or with their right hand. Please find the maximum possible size of the team, where equal number of players use their left and right hands, respectively.
The only line contains three integers *l*, *r* and *a* (0<=≤<=*l*,<=*r*,<=*a*<=≤<=100) — the number of left-handers, the number of right-handers and the number of ambidexters at the training.
Print a single even integer — the maximum number of players in the team. It is possible that the team can only have zero number of players.
[ "1 4 2\n", "5 5 5\n", "0 2 0\n" ]
[ "6\n", "14\n", "0\n" ]
In the first example you can form a team of 6 players. You should take the only left-hander and two ambidexters to play with left hand, and three right-handers to play with right hand. The only person left can't be taken into the team. In the second example you can form a team of 14 people. You have to take all five left-handers, all five right-handers, two ambidexters to play with left hand and two ambidexters to play with right hand.
500
[ { "input": "1 4 2", "output": "6" }, { "input": "5 5 5", "output": "14" }, { "input": "0 2 0", "output": "0" }, { "input": "30 70 34", "output": "128" }, { "input": "89 32 24", "output": "112" }, { "input": "89 44 77", "output": "210" }, { "input": "0 0 0", "output": "0" }, { "input": "100 100 100", "output": "300" }, { "input": "1 1 1", "output": "2" }, { "input": "30 70 35", "output": "130" }, { "input": "89 44 76", "output": "208" }, { "input": "0 100 100", "output": "200" }, { "input": "100 0 100", "output": "200" }, { "input": "100 1 100", "output": "200" }, { "input": "1 100 100", "output": "200" }, { "input": "100 100 0", "output": "200" }, { "input": "100 100 1", "output": "200" }, { "input": "1 2 1", "output": "4" }, { "input": "0 0 100", "output": "100" }, { "input": "0 100 0", "output": "0" }, { "input": "100 0 0", "output": "0" }, { "input": "10 8 7", "output": "24" }, { "input": "45 47 16", "output": "108" }, { "input": "59 43 100", "output": "202" }, { "input": "34 1 30", "output": "62" }, { "input": "14 81 1", "output": "30" }, { "input": "53 96 94", "output": "242" }, { "input": "62 81 75", "output": "218" }, { "input": "21 71 97", "output": "188" }, { "input": "49 82 73", "output": "204" }, { "input": "88 19 29", "output": "96" }, { "input": "89 4 62", "output": "132" }, { "input": "58 3 65", "output": "126" }, { "input": "27 86 11", "output": "76" }, { "input": "35 19 80", "output": "134" }, { "input": "4 86 74", "output": "156" }, { "input": "32 61 89", "output": "182" }, { "input": "68 60 98", "output": "226" }, { "input": "37 89 34", "output": "142" }, { "input": "92 9 28", "output": "74" }, { "input": "79 58 98", "output": "234" }, { "input": "35 44 88", "output": "166" }, { "input": "16 24 19", "output": "58" }, { "input": "74 71 75", "output": "220" }, { "input": "83 86 99", "output": "268" }, { "input": "97 73 15", "output": "176" }, { "input": "77 76 73", "output": "226" }, { "input": "48 85 55", "output": "188" }, { "input": "1 2 2", "output": "4" }, { "input": "2 2 2", "output": "6" }, { "input": "2 1 2", "output": "4" }, { "input": "2 2 1", "output": "4" }, { "input": "3 2 1", "output": "6" }, { "input": "1 2 3", "output": "6" }, { "input": "1 3 2", "output": "6" }, { "input": "2 1 3", "output": "6" }, { "input": "2 3 1", "output": "6" }, { "input": "3 1 2", "output": "6" }, { "input": "99 99 99", "output": "296" }, { "input": "99 99 100", "output": "298" }, { "input": "99 100 99", "output": "298" }, { "input": "99 100 100", "output": "298" }, { "input": "100 99 99", "output": "298" }, { "input": "100 99 100", "output": "298" }, { "input": "100 100 99", "output": "298" }, { "input": "89 32 23", "output": "110" }, { "input": "4 5 0", "output": "8" }, { "input": "3 0 3", "output": "6" }, { "input": "0 0 2", "output": "2" }, { "input": "97 97 0", "output": "194" }, { "input": "1 4 0", "output": "2" }, { "input": "5 2 0", "output": "4" }, { "input": "0 5 10", "output": "14" }, { "input": "0 1 2", "output": "2" }, { "input": "5 2 3", "output": "10" }, { "input": "5 5 0", "output": "10" }, { "input": "0 0 10", "output": "10" }, { "input": "0 1 1", "output": "2" }, { "input": "0 0 1", "output": "0" } ]
1,527,703,597
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
77
0
l,r,a=map(int,input().split()) d=min(min(l,r)+a,max(l,r)) a-=d print(d+a//2)
Title: Left-handers, Right-handers and Ambidexters Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are at a water bowling training. There are *l* people who play with their left hand, *r* people, who play with their right hand, and *a* ambidexters, who can play with left or right hand. The coach decided to form a team of even number of players, exactly half of the players should play with their right hand, and exactly half of the players should play with their left hand. One player should use only on of his hands. Ambidexters play as well with their right hand as with their left hand. In the team, an ambidexter can play with their left hand, or with their right hand. Please find the maximum possible size of the team, where equal number of players use their left and right hands, respectively. Input Specification: The only line contains three integers *l*, *r* and *a* (0<=≤<=*l*,<=*r*,<=*a*<=≤<=100) — the number of left-handers, the number of right-handers and the number of ambidexters at the training. Output Specification: Print a single even integer — the maximum number of players in the team. It is possible that the team can only have zero number of players. Demo Input: ['1 4 2\n', '5 5 5\n', '0 2 0\n'] Demo Output: ['6\n', '14\n', '0\n'] Note: In the first example you can form a team of 6 players. You should take the only left-hander and two ambidexters to play with left hand, and three right-handers to play with right hand. The only person left can't be taken into the team. In the second example you can form a team of 14 people. You have to take all five left-handers, all five right-handers, two ambidexters to play with left hand and two ambidexters to play with right hand.
```python l,r,a=map(int,input().split()) d=min(min(l,r)+a,max(l,r)) a-=d print(d+a//2) ```
0
0
none
none
none
0
[ "none" ]
null
null
Vasya has *n* days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this *n* days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the *i*-th day there are four options: 1. on this day the gym is closed and the contest is not carried out; 1. on this day the gym is closed and the contest is carried out; 1. on this day the gym is open and the contest is not carried out; 1. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has — he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days.
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of days of Vasya's vacations. The second line contains the sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=3) separated by space, where: - *a**i* equals 0, if on the *i*-th day of vacations the gym is closed and the contest is not carried out; - *a**i* equals 1, if on the *i*-th day of vacations the gym is closed, but the contest is carried out; - *a**i* equals 2, if on the *i*-th day of vacations the gym is open and the contest is not carried out; - *a**i* equals 3, if on the *i*-th day of vacations the gym is open and the contest is carried out.
Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: - to do sport on any two consecutive days, - to write the contest on any two consecutive days.
[ "4\n1 3 2 0\n", "7\n1 3 3 2 1 2 3\n", "2\n2 2\n" ]
[ "2\n", "0\n", "1\n" ]
In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
0
[ { "input": "4\n1 3 2 0", "output": "2" }, { "input": "7\n1 3 3 2 1 2 3", "output": "0" }, { "input": "2\n2 2", "output": "1" }, { "input": "1\n0", "output": "1" }, { "input": "10\n0 0 1 1 0 0 0 0 1 0", "output": "8" }, { "input": "100\n3 2 3 3 3 2 3 1 3 2 2 3 2 3 3 3 3 3 3 1 2 2 3 1 3 3 2 2 2 3 1 0 3 3 3 2 3 3 1 1 3 1 3 3 3 1 3 1 3 0 1 3 2 3 2 1 1 3 2 3 3 3 2 3 1 3 3 3 3 2 2 2 1 3 1 3 3 3 3 1 3 2 3 3 0 3 3 3 3 3 1 0 2 1 3 3 0 2 3 3", "output": "16" }, { "input": "10\n2 3 0 1 3 1 2 2 1 0", "output": "3" }, { "input": "45\n3 3 2 3 2 3 3 3 0 3 3 3 3 3 3 3 1 3 2 3 2 3 2 2 2 3 2 3 3 3 3 3 1 2 3 3 2 2 2 3 3 3 3 1 3", "output": "6" }, { "input": "1\n1", "output": "0" }, { "input": "1\n2", "output": "0" }, { "input": "1\n3", "output": "0" }, { "input": "2\n1 1", "output": "1" }, { "input": "2\n1 3", "output": "0" }, { "input": "2\n0 1", "output": "1" }, { "input": "2\n0 0", "output": "2" }, { "input": "2\n3 3", "output": "0" }, { "input": "3\n3 3 3", "output": "0" }, { "input": "2\n3 2", "output": "0" }, { "input": "2\n0 2", "output": "1" }, { "input": "10\n2 2 3 3 3 3 2 1 3 2", "output": "2" }, { "input": "15\n0 1 0 0 0 2 0 1 0 0 0 2 0 0 0", "output": "11" }, { "input": "15\n1 3 2 2 2 3 3 3 3 2 3 2 2 1 1", "output": "4" }, { "input": "15\n3 1 3 2 3 2 2 2 3 3 3 3 2 3 2", "output": "3" }, { "input": "20\n0 2 0 1 0 0 0 1 2 0 1 1 1 0 1 1 0 1 1 0", "output": "12" }, { "input": "20\n2 3 2 3 3 3 3 2 0 3 1 1 2 3 0 3 2 3 0 3", "output": "5" }, { "input": "20\n3 3 3 3 2 3 3 2 1 3 3 2 2 2 3 2 2 2 2 2", "output": "4" }, { "input": "25\n0 0 1 0 0 1 0 0 1 0 0 1 0 2 0 0 2 0 0 1 0 2 0 1 1", "output": "16" }, { "input": "25\n1 3 3 2 2 3 3 3 3 3 1 2 2 3 2 0 2 1 0 1 3 2 2 3 3", "output": "5" }, { "input": "25\n2 3 1 3 3 2 1 3 3 3 1 3 3 1 3 2 3 3 1 3 3 3 2 3 3", "output": "3" }, { "input": "30\n0 0 1 0 1 0 1 1 0 0 0 0 0 0 1 0 0 1 1 0 0 2 0 0 1 1 2 0 0 0", "output": "22" }, { "input": "30\n1 1 3 2 2 0 3 2 3 3 1 2 0 1 1 2 3 3 2 3 1 3 2 3 0 2 0 3 3 2", "output": "9" }, { "input": "30\n1 2 3 2 2 3 3 3 3 3 3 3 3 3 3 1 2 2 3 2 3 3 3 2 1 3 3 3 1 3", "output": "2" }, { "input": "35\n0 1 1 0 0 2 0 0 1 0 0 0 1 0 1 0 1 0 0 0 1 2 1 0 2 2 1 0 1 0 1 1 1 0 0", "output": "21" }, { "input": "35\n2 2 0 3 2 2 0 3 3 1 1 3 3 1 2 2 0 2 2 2 2 3 1 0 2 1 3 2 2 3 2 3 3 1 2", "output": "11" }, { "input": "35\n1 2 2 3 3 3 3 3 2 2 3 3 2 3 3 2 3 2 3 3 2 2 2 3 3 2 3 3 3 1 3 3 2 2 2", "output": "7" }, { "input": "40\n2 0 1 1 0 0 0 0 2 0 1 1 1 0 0 1 0 0 0 0 0 2 0 0 0 2 1 1 1 3 0 0 0 0 0 0 0 1 1 0", "output": "28" }, { "input": "40\n2 2 3 2 0 2 3 2 1 2 3 0 2 3 2 1 1 3 1 1 0 2 3 1 3 3 1 1 3 3 2 2 1 3 3 3 2 3 3 1", "output": "10" }, { "input": "40\n1 3 2 3 3 2 3 3 2 2 3 1 2 1 2 2 3 1 2 2 1 2 2 2 1 2 2 3 2 3 2 3 2 3 3 3 1 3 2 3", "output": "8" }, { "input": "45\n2 1 0 0 0 2 1 0 1 0 0 2 2 1 1 0 0 2 0 0 0 0 0 0 1 0 0 2 0 0 1 1 0 0 1 0 0 1 1 2 0 0 2 0 2", "output": "29" }, { "input": "45\n3 3 2 3 3 3 2 2 3 2 3 1 3 2 3 2 2 1 1 3 2 3 2 1 3 1 2 3 2 2 0 3 3 2 3 2 3 2 3 2 0 3 1 1 3", "output": "8" }, { "input": "50\n3 0 0 0 2 0 0 0 0 0 0 0 2 1 0 2 0 1 0 1 3 0 2 1 1 0 0 1 1 0 0 1 2 1 1 2 1 1 0 0 0 0 0 0 0 1 2 2 0 0", "output": "32" }, { "input": "50\n3 3 3 3 1 0 3 3 0 2 3 1 1 1 3 2 3 3 3 3 3 1 0 1 2 2 3 3 2 3 0 0 0 2 1 0 1 2 2 2 2 0 2 2 2 1 2 3 3 2", "output": "16" }, { "input": "50\n3 2 3 1 2 1 2 3 3 2 3 3 2 1 3 3 3 3 3 3 2 3 2 3 2 2 3 3 3 2 3 3 3 3 2 3 1 2 3 3 2 3 3 1 2 2 1 1 3 3", "output": "7" }, { "input": "55\n0 0 1 1 0 1 0 0 1 0 1 0 0 0 2 0 0 1 0 0 0 1 0 0 0 0 3 1 0 0 0 1 0 0 0 0 2 0 0 0 2 0 2 1 0 0 0 0 0 0 0 0 2 0 0", "output": "40" }, { "input": "55\n3 0 3 3 3 2 0 2 3 0 3 2 3 3 0 3 3 1 3 3 1 2 3 2 0 3 3 2 1 2 3 2 3 0 3 2 2 1 2 3 2 2 1 3 2 2 3 1 3 2 2 3 3 2 2", "output": "13" }, { "input": "55\n3 3 1 3 2 3 2 3 2 2 3 3 3 3 3 1 1 3 3 2 3 2 3 2 0 1 3 3 3 3 2 3 2 3 1 1 2 2 2 3 3 3 3 3 2 2 2 3 2 3 3 3 3 1 3", "output": "7" }, { "input": "60\n0 1 0 0 0 0 0 0 0 2 1 1 3 0 0 0 0 0 1 0 1 1 0 0 0 3 0 1 0 1 0 2 0 0 0 0 0 1 0 0 0 0 1 1 0 1 0 0 0 0 0 1 0 0 1 0 1 0 0 0", "output": "44" }, { "input": "60\n3 2 1 3 2 2 3 3 3 1 1 3 2 2 3 3 1 3 2 2 3 3 2 2 2 2 0 2 2 3 2 3 0 3 3 3 2 3 3 0 1 3 2 1 3 1 1 2 1 3 1 1 2 2 1 3 3 3 2 2", "output": "15" }, { "input": "60\n3 2 2 3 2 3 2 3 3 2 3 2 3 3 2 3 3 3 3 3 3 2 3 3 1 2 3 3 3 2 1 3 3 1 3 1 3 0 3 3 3 2 3 2 3 2 3 3 1 1 2 3 3 3 3 2 1 3 2 3", "output": "8" }, { "input": "65\n1 0 2 1 1 0 1 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 0 1 2 0 2 1 0 2 1 0 1 0 1 1 0 1 1 1 2 1 0 1 0 0 0 0 1 2 2 1 0 0 1 2 1 2 0 2 0 0 0 1 1", "output": "35" }, { "input": "65\n2 2 2 3 0 2 1 2 3 3 1 3 1 2 1 3 2 3 2 2 2 1 2 0 3 1 3 1 1 3 1 3 3 3 3 3 1 3 0 3 1 3 1 2 2 3 2 0 3 1 3 2 1 2 2 2 3 3 2 3 3 3 2 2 3", "output": "13" }, { "input": "65\n3 2 3 3 3 2 3 2 3 3 3 3 3 3 3 3 3 2 3 2 3 2 2 3 3 3 3 3 2 2 2 3 3 2 3 3 2 3 3 3 3 2 3 3 3 2 2 3 3 3 3 3 3 2 2 3 3 2 3 3 1 3 3 3 3", "output": "6" }, { "input": "70\n1 0 0 0 1 0 1 0 0 0 1 1 0 1 0 0 1 1 1 0 1 1 0 0 1 1 1 3 1 1 0 1 2 0 2 1 0 0 0 1 1 1 1 1 0 0 1 0 0 0 1 1 1 3 0 0 1 0 0 0 1 0 0 0 0 0 1 0 1 1", "output": "43" }, { "input": "70\n2 3 3 3 1 3 3 1 2 1 1 2 2 3 0 2 3 3 1 3 3 2 2 3 3 3 2 2 2 2 1 3 3 0 2 1 1 3 2 3 3 2 2 3 1 3 1 2 3 2 3 3 2 2 2 3 1 1 2 1 3 3 2 2 3 3 3 1 1 1", "output": "16" }, { "input": "70\n3 3 2 2 1 2 1 2 2 2 2 2 3 3 2 3 3 3 3 2 2 2 2 3 3 3 1 3 3 3 2 3 3 3 3 2 3 3 1 3 1 3 2 3 3 2 3 3 3 2 3 2 3 3 1 2 3 3 2 2 2 3 2 3 3 3 3 3 3 1", "output": "10" }, { "input": "75\n1 0 0 1 1 0 0 1 0 1 2 0 0 2 1 1 0 0 0 0 0 0 2 1 1 0 0 0 0 1 0 1 0 1 1 1 0 1 0 0 1 0 0 0 0 0 0 1 1 0 0 1 2 1 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 1 1 1 0 1 0", "output": "51" }, { "input": "75\n1 3 3 3 1 1 3 2 3 3 1 3 3 3 2 1 3 2 2 3 1 1 1 1 1 1 2 3 3 3 3 3 3 2 3 3 3 3 3 2 3 3 2 2 2 1 2 3 3 2 2 3 0 1 1 3 3 0 0 1 1 3 2 3 3 3 3 1 2 2 3 3 3 3 1", "output": "16" }, { "input": "75\n3 3 3 3 2 2 3 2 2 3 2 2 1 2 3 3 2 2 3 3 1 2 2 2 1 3 3 3 1 2 2 3 3 3 2 3 2 2 2 3 3 1 3 2 2 3 3 3 0 3 2 1 3 3 2 3 3 3 3 1 2 3 3 3 2 2 3 3 3 3 2 2 3 3 1", "output": "11" }, { "input": "80\n0 0 0 0 2 0 1 1 1 1 1 0 0 0 0 2 0 0 1 0 0 0 0 1 1 0 2 2 1 1 0 1 0 1 0 1 1 1 0 1 2 1 1 0 0 0 1 1 0 1 1 0 1 0 0 1 0 0 1 0 0 0 0 0 0 0 2 2 0 1 1 0 0 0 0 0 0 0 0 1", "output": "56" }, { "input": "80\n2 2 3 3 2 1 0 1 0 3 2 2 3 2 1 3 1 3 3 2 3 3 3 2 3 3 3 2 1 3 3 1 3 3 3 3 3 3 2 2 2 1 3 2 1 3 2 1 1 0 1 1 2 1 3 0 1 2 3 2 2 3 2 3 1 3 3 2 1 1 0 3 3 3 3 1 2 1 2 0", "output": "17" }, { "input": "80\n2 3 3 2 2 2 3 3 2 3 3 3 3 3 2 3 2 3 2 3 3 3 3 3 3 3 3 3 2 3 1 3 2 3 3 0 3 1 2 3 3 1 2 3 2 3 3 2 3 3 3 3 3 2 2 3 0 3 3 3 3 3 2 2 3 2 3 3 3 3 3 2 3 2 3 3 3 3 2 3", "output": "9" }, { "input": "85\n0 1 1 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 2 0 1 0 0 2 0 1 1 0 0 0 0 2 2 0 0 0 1 0 0 0 1 2 0 1 0 0 0 2 1 1 2 0 3 1 0 2 2 1 0 0 1 1 0 0 0 0 1 0 2 1 1 2 1 0 0 1 2 1 2 0 0 1 0 1 0", "output": "54" }, { "input": "85\n2 3 1 3 2 3 1 3 3 2 1 2 1 2 2 3 2 2 3 2 0 3 3 2 1 2 2 2 3 3 2 3 3 3 2 1 1 3 1 3 2 2 2 3 3 2 3 2 3 1 1 3 2 3 1 3 3 2 3 3 2 2 3 0 1 1 2 2 2 2 1 2 3 1 3 3 1 3 2 2 3 2 3 3 3", "output": "19" }, { "input": "85\n1 2 1 2 3 2 3 3 3 3 3 3 3 2 1 3 2 3 3 3 3 2 3 3 3 1 3 3 3 3 2 3 3 3 3 3 3 2 2 1 3 3 3 3 2 2 3 1 1 2 3 3 3 2 3 3 3 3 3 2 3 3 3 2 2 3 3 1 1 1 3 3 3 3 1 3 3 3 1 3 3 1 3 2 3", "output": "9" }, { "input": "90\n2 0 1 0 0 0 0 0 0 1 1 2 0 0 0 0 0 0 0 2 2 0 2 0 0 2 1 0 2 0 1 0 1 0 0 1 2 2 0 0 1 0 0 1 0 1 0 2 0 1 1 1 0 1 1 0 1 0 2 0 1 0 1 0 0 0 1 0 0 1 2 0 0 0 1 0 0 2 2 0 0 0 0 0 1 3 1 1 0 1", "output": "57" }, { "input": "90\n2 3 3 3 2 3 2 1 3 0 3 2 3 3 2 1 3 3 2 3 2 3 3 2 1 3 1 3 3 1 2 2 3 3 2 1 2 3 2 3 0 3 3 2 2 3 1 0 3 3 1 3 3 3 3 2 1 2 2 1 3 2 1 3 3 1 2 0 2 2 3 2 2 3 3 3 1 3 2 1 2 3 3 2 3 2 3 3 2 1", "output": "17" }, { "input": "90\n2 3 2 3 2 2 3 3 2 3 2 1 2 3 3 3 2 3 2 3 3 2 3 3 3 1 3 3 1 3 2 3 2 2 1 3 3 3 3 3 3 3 3 3 3 2 3 2 3 2 1 3 3 3 3 2 2 3 3 3 3 3 3 3 3 3 3 3 3 2 2 3 3 3 3 1 3 2 3 3 3 2 2 3 2 3 2 1 3 2", "output": "9" }, { "input": "95\n0 0 3 0 2 0 1 0 0 2 0 0 0 0 0 0 0 1 0 0 0 2 0 0 0 0 0 1 0 0 2 1 0 0 1 0 0 0 1 0 0 0 0 1 0 1 0 0 1 0 1 2 0 1 2 2 0 0 1 0 2 0 0 0 1 0 2 1 2 1 0 1 0 0 0 1 0 0 1 1 2 1 1 1 1 2 0 0 0 0 0 1 1 0 1", "output": "61" }, { "input": "95\n2 3 3 2 1 1 3 3 3 2 3 3 3 2 3 2 3 3 3 2 3 2 2 3 3 2 1 2 3 3 3 1 3 0 3 3 1 3 3 1 0 1 3 3 3 0 2 1 3 3 3 3 0 1 3 2 3 3 2 1 3 1 2 1 1 2 3 0 3 3 2 1 3 2 1 3 3 3 2 2 3 2 3 3 3 2 1 3 3 3 2 3 3 1 2", "output": "15" }, { "input": "95\n2 3 3 2 3 2 2 1 3 1 2 1 2 3 1 2 3 3 1 3 3 3 1 2 3 2 2 2 2 3 3 3 2 2 3 3 3 3 3 1 2 2 3 3 3 3 2 3 2 2 2 3 3 2 3 3 3 3 3 3 3 0 3 2 0 3 3 1 3 3 3 2 3 2 3 2 3 3 3 3 2 2 1 1 3 3 3 3 3 1 3 3 3 3 2", "output": "14" }, { "input": "100\n1 0 2 0 0 0 0 2 0 0 0 1 0 1 0 0 1 0 1 2 0 1 1 0 0 1 0 1 1 0 0 0 2 0 1 0 0 2 0 0 0 0 0 1 1 1 0 0 1 0 2 0 0 0 0 1 0 1 0 1 0 1 0 1 2 2 0 0 2 0 1 0 1 0 1 0 0 0 1 0 0 2 1 1 1 0 0 1 0 0 0 2 0 0 2 1 1 0 0 2", "output": "63" }, { "input": "100\n3 2 1 3 2 3 2 3 2 2 3 1 3 3 3 3 3 2 2 3 2 2 3 2 3 3 3 2 3 1 2 1 3 3 3 3 1 3 3 3 3 3 2 3 2 1 3 3 1 2 2 3 1 3 3 1 2 2 1 3 1 3 2 2 3 3 1 3 2 3 1 2 1 2 3 3 2 2 1 2 3 3 3 3 3 1 3 3 3 3 2 1 3 0 3 3 3 2 3 3", "output": "15" }, { "input": "100\n1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2", "output": "0" }, { "input": "100\n3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3", "output": "0" }, { "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": "50" }, { "input": "100\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2", "output": "50" }, { "input": "99\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", "output": "49" }, { "input": "100\n2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1", "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": "100" }, { "input": "2\n0 3", "output": "1" }, { "input": "2\n1 0", "output": "1" }, { "input": "2\n1 2", "output": "0" }, { "input": "2\n2 0", "output": "1" }, { "input": "2\n2 1", "output": "0" }, { "input": "2\n2 3", "output": "0" }, { "input": "2\n3 0", "output": "1" }, { "input": "2\n3 1", "output": "0" }, { "input": "100\n3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0", "output": "50" } ]
1,634,989,151
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
4
61
28,364,800
n=int(input()) l=list(map(int,input().split())) a,b,f=0,0,-1 e=0 for i in range(n): if(l[i]==1): if(f==-1): a+=1 f=1 elif(f==1): continue else: a+=1 f=1 elif(l[i]==2): if(f==-1): b+=1 f=0 elif(f==0): continue else: b+=1 f=0 elif(l[i]==3): if(f==-1): e=1 elif(f==0): a+=1 f=1 else: b+=1 f=0 print(n-(a+b+e))
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya has *n* days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this *n* days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the *i*-th day there are four options: 1. on this day the gym is closed and the contest is not carried out; 1. on this day the gym is closed and the contest is carried out; 1. on this day the gym is open and the contest is not carried out; 1. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has — he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input Specification: The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of days of Vasya's vacations. The second line contains the sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=3) separated by space, where: - *a**i* equals 0, if on the *i*-th day of vacations the gym is closed and the contest is not carried out; - *a**i* equals 1, if on the *i*-th day of vacations the gym is closed, but the contest is carried out; - *a**i* equals 2, if on the *i*-th day of vacations the gym is open and the contest is not carried out; - *a**i* equals 3, if on the *i*-th day of vacations the gym is open and the contest is carried out. Output Specification: Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: - to do sport on any two consecutive days, - to write the contest on any two consecutive days. Demo Input: ['4\n1 3 2 0\n', '7\n1 3 3 2 1 2 3\n', '2\n2 2\n'] Demo Output: ['2\n', '0\n', '1\n'] Note: In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
```python n=int(input()) l=list(map(int,input().split())) a,b,f=0,0,-1 e=0 for i in range(n): if(l[i]==1): if(f==-1): a+=1 f=1 elif(f==1): continue else: a+=1 f=1 elif(l[i]==2): if(f==-1): b+=1 f=0 elif(f==0): continue else: b+=1 f=0 elif(l[i]==3): if(f==-1): e=1 elif(f==0): a+=1 f=1 else: b+=1 f=0 print(n-(a+b+e)) ```
0
887
A
Div. 64
PROGRAMMING
1,000
[ "implementation" ]
null
null
Top-model Izabella participates in the competition. She wants to impress judges and show her mathematical skills. Her problem is following: for given string, consisting of only 0 and 1, tell if it's possible to remove some digits in such a way, that remaining number is a representation of some positive integer, divisible by 64, in the binary numerical system.
In the only line given a non-empty binary string *s* with length up to 100.
Print «yes» (without quotes) if it's possible to remove digits required way and «no» otherwise.
[ "100010001\n", "100\n" ]
[ "yes", "no" ]
In the first test case, you can get string 1 000 000 after removing two ones which is a representation of number 64 in the binary numerical system. You can read more about binary numeral system representation here: [https://en.wikipedia.org/wiki/Binary_system](https://en.wikipedia.org/wiki/Binary_system)
500
[ { "input": "100010001", "output": "yes" }, { "input": "100", "output": "no" }, { "input": "0000001000000", "output": "yes" }, { "input": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", "output": "no" }, { "input": "1111111111111111111111111111111111111111111111111111111111111111111111110111111111111111111111111111", "output": "no" }, { "input": "0111111101111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", "output": "no" }, { "input": "1111011111111111111111111111110111110111111111111111111111011111111111111110111111111111111111111111", "output": "no" }, { "input": "1111111111101111111111111111111111111011111111111111111111111101111011111101111111111101111111111111", "output": "yes" }, { "input": "0110111111111111111111011111111110110111110111111111111111111111111111111111111110111111111111111111", "output": "yes" }, { "input": "1100110001111011001101101000001110111110011110111110010100011000100101000010010111100000010001001101", "output": "yes" }, { "input": "000000", "output": "no" }, { "input": "0001000", "output": "no" }, { "input": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "output": "no" }, { "input": "1000000", "output": "yes" }, { "input": "0", "output": "no" }, { "input": "1", "output": "no" }, { "input": "10000000000", "output": "yes" }, { "input": "0000000000", "output": "no" }, { "input": "0010000", "output": "no" }, { "input": "000000011", "output": "no" }, { "input": "000000000", "output": "no" }, { "input": "00000000", "output": "no" }, { "input": "000000000011", "output": "no" }, { "input": "0000000", "output": "no" }, { "input": "00000000011", "output": "no" }, { "input": "000000001", "output": "no" }, { "input": "000000000000000000000000000", "output": "no" }, { "input": "0000001", "output": "no" }, { "input": "00000001", "output": "no" }, { "input": "00000000100", "output": "no" }, { "input": "00000000000000000000", "output": "no" }, { "input": "0000000000000000000", "output": "no" }, { "input": "00001000", "output": "no" }, { "input": "0000000000010", "output": "no" }, { "input": "000000000010", "output": "no" }, { "input": "000000000000010", "output": "no" }, { "input": "0100000", "output": "no" }, { "input": "00010000", "output": "no" }, { "input": "00000000000000000", "output": "no" }, { "input": "00000000000", "output": "no" }, { "input": "000001000", "output": "no" }, { "input": "000000000000", "output": "no" }, { "input": "100000000000000", "output": "yes" }, { "input": "000010000", "output": "no" }, { "input": "00000100", "output": "no" }, { "input": "0001100000", "output": "no" }, { "input": "000000000000000000000000001", "output": "no" }, { "input": "000000100", "output": "no" }, { "input": "0000000000001111111111", "output": "no" }, { "input": "00000010", "output": "no" }, { "input": "0001110000", "output": "no" }, { "input": "0000000000000000000000", "output": "no" }, { "input": "000000010010", "output": "no" }, { "input": "0000100", "output": "no" }, { "input": "0000000001", "output": "no" }, { "input": "000000111", "output": "no" }, { "input": "0000000000000", "output": "no" }, { "input": "000000000000000000", "output": "no" }, { "input": "0000000000000000000000000", "output": "no" }, { "input": "000000000000000", "output": "no" }, { "input": "0010000000000100", "output": "yes" }, { "input": "0000001000", "output": "no" }, { "input": "00000000000000000001", "output": "no" }, { "input": "100000000", "output": "yes" }, { "input": "000000000001", "output": "no" }, { "input": "0000011001", "output": "no" }, { "input": "000", "output": "no" }, { "input": "000000000000000000000", "output": "no" }, { "input": "0000000000011", "output": "no" }, { "input": "0000000000000000", "output": "no" }, { "input": "00000000000000001", "output": "no" }, { "input": "00000000000000", "output": "no" }, { "input": "0000000000000000010", "output": "no" }, { "input": "00000000000000000000000000000000000000000000000000000000", "output": "no" }, { "input": "000011000", "output": "no" }, { "input": "00000011", "output": "no" }, { "input": "0000000000001100", "output": "no" }, { "input": "00000", "output": "no" }, { "input": "000000000000000000000000000111111111111111", "output": "no" }, { "input": "000000010", "output": "no" }, { "input": "00000000111", "output": "no" }, { "input": "000000000000001", "output": "no" }, { "input": "0000000000000011111111111111111", "output": "no" }, { "input": "0000000010", "output": "no" }, { "input": "0000000000000000000000000000000000000000000000000", "output": "no" }, { "input": "00000000010", "output": "no" }, { "input": "101000000000", "output": "yes" }, { "input": "00100000", "output": "no" }, { "input": "00000000000001", "output": "no" }, { "input": "0000000000100", "output": "no" }, { "input": "0000", "output": "no" }, { "input": "00000000000111", "output": "no" }, { "input": "0000000000000011", "output": "no" }, { "input": "0000000000000000000000000000000000000000", "output": "no" }, { "input": "0000000000000010", "output": "no" }, { "input": "0010101010", "output": "no" }, { "input": "0000000000000001", "output": "no" }, { "input": "1010101", "output": "no" } ]
1,687,542,938
2,147,483,647
PyPy 3-64
COMPILATION_ERROR
TESTS
0
0
0
s = input() print("YES" if (s.count('1') == 0 or (len(s) > 6 && s[-6:].count('1') == 0)) else "NO")
Title: Div. 64 Time Limit: None seconds Memory Limit: None megabytes Problem Description: Top-model Izabella participates in the competition. She wants to impress judges and show her mathematical skills. Her problem is following: for given string, consisting of only 0 and 1, tell if it's possible to remove some digits in such a way, that remaining number is a representation of some positive integer, divisible by 64, in the binary numerical system. Input Specification: In the only line given a non-empty binary string *s* with length up to 100. Output Specification: Print «yes» (without quotes) if it's possible to remove digits required way and «no» otherwise. Demo Input: ['100010001\n', '100\n'] Demo Output: ['yes', 'no'] Note: In the first test case, you can get string 1 000 000 after removing two ones which is a representation of number 64 in the binary numerical system. You can read more about binary numeral system representation here: [https://en.wikipedia.org/wiki/Binary_system](https://en.wikipedia.org/wiki/Binary_system)
```python s = input() print("YES" if (s.count('1') == 0 or (len(s) > 6 && s[-6:].count('1') == 0)) else "NO") ```
-1
129
B
Students and Shoelaces
PROGRAMMING
1,200
[ "brute force", "dfs and similar", "graphs", "implementation" ]
null
null
Anna and Maria are in charge of the math club for junior students. When the club gathers together, the students behave badly. They've brought lots of shoe laces to the club and got tied with each other. Specifically, each string ties together two students. Besides, if two students are tied, then the lace connects the first student with the second one as well as the second student with the first one. To restore order, Anna and Maria do the following. First, for each student Anna finds out what other students he is tied to. If a student is tied to exactly one other student, Anna reprimands him. Then Maria gathers in a single group all the students who have been just reprimanded. She kicks them out from the club. This group of students immediately leaves the club. These students takes with them the laces that used to tie them. Then again for every student Anna finds out how many other students he is tied to and so on. And they do so until Anna can reprimand at least one student. Determine how many groups of students will be kicked out of the club.
The first line contains two integers *n* and *m* — the initial number of students and laces (). The students are numbered from 1 to *n*, and the laces are numbered from 1 to *m*. Next *m* lines each contain two integers *a* and *b* — the numbers of students tied by the *i*-th lace (1<=≤<=*a*,<=*b*<=≤<=*n*,<=*a*<=≠<=*b*). It is guaranteed that no two students are tied with more than one lace. No lace ties a student to himself.
Print the single number — the number of groups of students that will be kicked out from the club.
[ "3 3\n1 2\n2 3\n3 1\n", "6 3\n1 2\n2 3\n3 4\n", "6 5\n1 4\n2 4\n3 4\n5 4\n6 4\n" ]
[ "0\n", "2\n", "1\n" ]
In the first sample Anna and Maria won't kick out any group of students — in the initial position every student is tied to two other students and Anna won't be able to reprimand anyone. In the second sample four students are tied in a chain and two more are running by themselves. First Anna and Maria kick out the two students from both ends of the chain (1 and 4), then — two other students from the chain (2 and 3). At that the students who are running by themselves will stay in the club. In the third sample Anna and Maria will momentarily kick out all students except for the fourth one and the process stops at that point. The correct answer is one.
1,000
[ { "input": "3 3\n1 2\n2 3\n3 1", "output": "0" }, { "input": "6 3\n1 2\n2 3\n3 4", "output": "2" }, { "input": "6 5\n1 4\n2 4\n3 4\n5 4\n6 4", "output": "1" }, { "input": "100 0", "output": "0" }, { "input": "5 5\n1 2\n2 3\n3 4\n4 5\n5 1", "output": "0" }, { "input": "5 4\n1 4\n4 3\n4 5\n5 2", "output": "2" }, { "input": "11 10\n1 2\n1 3\n3 4\n1 5\n5 6\n6 7\n1 8\n8 9\n9 10\n10 11", "output": "4" }, { "input": "7 7\n1 2\n2 3\n3 1\n1 4\n4 5\n4 6\n4 7", "output": "2" }, { "input": "12 49\n6 3\n12 9\n10 11\n3 5\n10 2\n6 9\n8 5\n6 12\n7 3\n3 12\n3 2\n5 6\n7 5\n9 2\n11 1\n7 6\n5 4\n8 7\n12 5\n5 11\n8 9\n10 3\n6 2\n10 4\n9 10\n9 11\n11 3\n5 9\n11 6\n10 8\n7 9\n10 7\n4 6\n3 8\n4 11\n12 2\n4 9\n2 11\n7 11\n1 5\n7 2\n8 1\n4 12\n9 1\n4 2\n8 2\n11 12\n3 1\n1 6", "output": "0" }, { "input": "10 29\n4 5\n1 7\n4 2\n3 8\n7 6\n8 10\n10 6\n4 1\n10 1\n6 2\n7 4\n7 10\n2 7\n9 8\n5 10\n2 5\n8 5\n4 9\n2 8\n5 7\n4 8\n7 3\n6 5\n1 3\n1 9\n10 4\n10 9\n10 2\n2 3", "output": "0" }, { "input": "9 33\n5 7\n5 9\n9 6\n9 1\n7 4\n3 5\n7 8\n8 6\n3 6\n8 2\n3 8\n1 6\n1 8\n1 4\n4 2\n1 2\n2 5\n3 4\n8 5\n2 6\n3 1\n1 5\n1 7\n3 2\n5 4\n9 4\n3 9\n7 3\n6 4\n9 8\n7 9\n8 4\n6 5", "output": "0" }, { "input": "7 8\n5 7\n2 7\n1 6\n1 3\n3 7\n6 3\n6 4\n2 6", "output": "1" }, { "input": "6 15\n3 1\n4 5\n1 4\n6 2\n3 5\n6 3\n1 6\n1 5\n2 3\n2 5\n6 4\n5 6\n4 2\n1 2\n3 4", "output": "0" }, { "input": "7 11\n5 3\n6 5\n6 4\n1 6\n7 1\n2 6\n7 5\n2 5\n3 1\n3 4\n2 4", "output": "0" }, { "input": "95 0", "output": "0" }, { "input": "100 0", "output": "0" }, { "input": "62 30\n29 51\n29 55\n4 12\n53 25\n36 28\n32 11\n29 11\n47 9\n21 8\n25 4\n51 19\n26 56\n22 21\n37 9\n9 33\n7 25\n16 7\n40 49\n15 21\n49 58\n34 30\n20 46\n62 48\n53 57\n33 6\n60 37\n41 34\n62 36\n36 43\n11 39", "output": "2" }, { "input": "56 25\n12 40\n31 27\n18 40\n1 43\n9 10\n25 47\n27 29\n26 28\n19 38\n19 40\n22 14\n21 51\n29 31\n55 29\n51 33\n20 17\n24 15\n3 48\n31 56\n15 29\n49 42\n50 4\n22 42\n25 17\n18 51", "output": "3" }, { "input": "51 29\n36 30\n37 45\n4 24\n40 18\n47 35\n15 1\n30 38\n15 18\n32 40\n34 42\n2 47\n35 21\n25 28\n13 1\n13 28\n36 1\n46 47\n22 17\n41 45\n43 45\n40 15\n29 35\n47 15\n30 21\n9 14\n18 38\n18 50\n42 10\n31 41", "output": "3" }, { "input": "72 45\n5 15\n8 18\n40 25\n71 66\n67 22\n6 44\n16 25\n8 23\n19 70\n26 34\n48 15\n24 2\n54 68\n44 43\n17 37\n49 19\n71 49\n34 38\n59 1\n65 70\n11 54\n5 11\n15 31\n29 50\n48 16\n70 57\n25 59\n2 59\n56 12\n66 62\n24 16\n46 27\n45 67\n68 43\n31 11\n31 30\n8 44\n64 33\n38 44\n54 10\n13 9\n7 51\n25 4\n40 70\n26 65", "output": "5" }, { "input": "56 22\n17 27\n48 49\n29 8\n47 20\n32 7\n44 5\n14 39\n5 13\n40 2\n50 42\n38 9\n18 37\n16 44\n21 32\n21 39\n37 54\n19 46\n30 47\n17 13\n30 31\n49 16\n56 7", "output": "4" }, { "input": "81 46\n53 58\n31 14\n18 54\n43 61\n57 65\n6 38\n49 5\n6 40\n6 10\n17 72\n27 48\n58 39\n21 75\n21 43\n78 20\n34 4\n15 35\n74 48\n76 15\n49 38\n46 51\n78 9\n80 5\n26 42\n64 31\n46 72\n1 29\n20 17\n32 45\n53 43\n24 5\n52 59\n3 80\n78 19\n61 17\n80 12\n17 8\n63 2\n8 4\n44 10\n53 72\n18 60\n68 15\n17 58\n79 71\n73 35", "output": "4" }, { "input": "82 46\n64 43\n32 24\n57 30\n24 46\n70 12\n23 41\n63 39\n46 70\n4 61\n19 12\n39 79\n14 28\n37 3\n12 27\n15 20\n35 39\n25 64\n59 16\n68 63\n37 14\n76 7\n67 29\n9 5\n14 55\n46 26\n71 79\n47 42\n5 55\n18 45\n28 40\n44 78\n74 9\n60 53\n44 19\n52 81\n65 52\n40 13\n40 19\n43 1\n24 23\n68 9\n16 20\n70 14\n41 40\n29 10\n45 65", "output": "8" }, { "input": "69 38\n63 35\n52 17\n43 69\n2 57\n12 5\n26 36\n13 10\n16 68\n5 18\n5 41\n10 4\n60 9\n39 22\n39 28\n53 57\n13 52\n66 38\n49 61\n12 19\n27 46\n67 7\n25 8\n23 58\n52 34\n29 2\n2 42\n8 53\n57 43\n68 11\n48 28\n56 19\n46 33\n63 21\n57 16\n68 59\n67 34\n28 43\n56 36", "output": "4" }, { "input": "75 31\n32 50\n52 8\n21 9\n68 35\n12 72\n47 26\n38 58\n40 55\n31 70\n53 75\n44 1\n65 22\n33 22\n33 29\n14 39\n1 63\n16 52\n70 15\n12 27\n63 31\n47 9\n71 31\n43 17\n43 49\n8 26\n11 39\n9 22\n30 45\n65 47\n32 9\n60 70", "output": "4" }, { "input": "77 41\n48 45\n50 36\n6 69\n70 3\n22 21\n72 6\n54 3\n49 31\n2 23\n14 59\n68 58\n4 54\n60 12\n63 60\n44 24\n28 24\n40 8\n5 1\n13 24\n29 15\n19 76\n70 50\n65 71\n23 33\n58 16\n50 42\n71 28\n58 54\n24 73\n6 17\n29 13\n60 4\n42 4\n21 60\n77 39\n57 9\n51 19\n61 6\n49 36\n24 32\n41 66", "output": "3" }, { "input": "72 39\n9 44\n15 12\n2 53\n34 18\n41 70\n54 72\n39 19\n26 7\n4 54\n53 59\n46 49\n70 6\n9 10\n64 51\n31 60\n61 53\n59 71\n9 60\n67 16\n4 16\n34 3\n2 61\n16 23\n34 6\n10 18\n13 38\n66 40\n59 9\n40 14\n38 24\n31 48\n7 69\n20 39\n49 52\n32 67\n61 35\n62 45\n37 54\n5 27", "output": "8" }, { "input": "96 70\n30 37\n47 56\n19 79\n15 28\n2 43\n43 54\n59 75\n42 22\n38 18\n18 14\n47 41\n60 29\n35 11\n90 4\n14 41\n11 71\n41 24\n68 28\n45 92\n14 15\n34 63\n77 32\n67 38\n36 8\n37 4\n58 95\n68 84\n69 81\n35 23\n56 63\n78 91\n35 44\n66 63\n80 19\n87 88\n28 14\n62 35\n24 23\n83 37\n54 89\n14 40\n9 35\n94 9\n56 46\n92 70\n16 58\n96 31\n53 23\n56 5\n36 42\n89 77\n29 51\n26 13\n46 70\n25 56\n95 96\n3 51\n76 8\n36 82\n44 85\n54 56\n89 67\n32 5\n82 78\n33 65\n43 28\n35 1\n94 13\n26 24\n10 51", "output": "4" }, { "input": "76 49\n15 59\n23 26\n57 48\n49 51\n42 76\n36 40\n37 40\n29 15\n28 71\n47 70\n27 39\n76 21\n55 16\n21 18\n19 1\n25 31\n51 71\n54 42\n28 9\n61 69\n33 9\n18 19\n58 51\n51 45\n29 34\n9 67\n26 8\n70 37\n11 62\n24 22\n59 76\n67 17\n59 11\n54 1\n12 57\n23 3\n46 47\n37 20\n65 9\n51 12\n31 19\n56 13\n58 22\n26 59\n39 76\n27 11\n48 64\n59 35\n44 75", "output": "5" }, { "input": "52 26\n29 41\n16 26\n18 48\n31 17\n37 42\n26 1\n11 7\n29 6\n23 17\n12 47\n34 23\n41 16\n15 35\n25 21\n45 7\n52 2\n37 10\n28 19\n1 27\n30 47\n42 35\n50 30\n30 34\n19 30\n42 25\n47 31", "output": "3" }, { "input": "86 48\n59 34\n21 33\n45 20\n62 23\n4 68\n2 65\n63 26\n64 20\n51 34\n64 21\n68 78\n61 80\n81 3\n38 39\n47 48\n24 34\n44 71\n72 78\n50 2\n13 51\n82 78\n11 74\n14 48\n2 75\n49 55\n63 85\n20 85\n4 53\n51 15\n11 67\n1 15\n2 64\n10 81\n6 7\n68 18\n84 28\n77 69\n10 36\n15 14\n32 86\n16 79\n26 13\n38 55\n47 43\n47 39\n45 37\n58 81\n42 35", "output": "8" }, { "input": "58 29\n27 24\n40 52\n51 28\n44 50\n7 28\n14 53\n10 16\n16 45\n8 56\n35 26\n39 6\n6 14\n45 22\n35 13\n20 17\n42 6\n37 21\n4 11\n26 56\n54 55\n3 57\n40 3\n55 27\n4 51\n35 29\n50 16\n47 7\n48 20\n1 37", "output": "3" }, { "input": "51 23\n46 47\n31 27\n1 20\n49 16\n2 10\n29 47\n13 27\n34 26\n31 2\n28 20\n17 40\n39 4\n29 26\n28 44\n3 39\n50 12\n19 1\n30 21\n41 23\n2 29\n16 3\n49 28\n49 41", "output": "4" }, { "input": "75 43\n46 34\n33 12\n51 39\n47 74\n68 64\n40 46\n20 51\n47 19\n4 5\n57 59\n12 26\n68 65\n38 42\n73 37\n5 74\n36 61\n8 18\n58 33\n34 73\n42 43\n10 49\n70 50\n49 18\n24 53\n71 73\n44 24\n49 56\n24 29\n44 67\n70 46\n57 25\n73 63\n3 51\n30 71\n41 44\n17 69\n17 18\n19 68\n42 7\n11 51\n1 5\n72 23\n65 53", "output": "5" } ]
1,468,691,122
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
7
2,000
512,000
from collections import defaultdict n, m = map(int, input().split()) E = [tuple(map(int, input().split())) for _ in range(m)] adj = defaultdict(set) for e in E: adj[e[0]].add(e[1]) adj[e[1]].add(e[0]) dl = defaultdict(list) for v in adj: dl[len(adj[v])].append(v) if len(dl[1]) == 0: print('0') else: cnt = 0 cnt2 = sum(len(dl[x]) for x in dl.keys()) while cnt2 > len(dl[1]): dec = defaultdict(int) while len(dl[1]) > 0: v = dl[1].pop() cnt2 -= 1 for v2 in adj[v]: dec[v2] += 1 adj[v2].remove(v) del adj[v] cnt += 1 for v in dec.keys(): dl[len(adj[v]) + dec[v]].remove(v) if len(adj[v]) > 0: dl[len(adj[v])].append(v) else: cnt2 -= 1 if len(dl[1]) > 0: cnt += 1 print(cnt)
Title: Students and Shoelaces Time Limit: None seconds Memory Limit: None megabytes Problem Description: Anna and Maria are in charge of the math club for junior students. When the club gathers together, the students behave badly. They've brought lots of shoe laces to the club and got tied with each other. Specifically, each string ties together two students. Besides, if two students are tied, then the lace connects the first student with the second one as well as the second student with the first one. To restore order, Anna and Maria do the following. First, for each student Anna finds out what other students he is tied to. If a student is tied to exactly one other student, Anna reprimands him. Then Maria gathers in a single group all the students who have been just reprimanded. She kicks them out from the club. This group of students immediately leaves the club. These students takes with them the laces that used to tie them. Then again for every student Anna finds out how many other students he is tied to and so on. And they do so until Anna can reprimand at least one student. Determine how many groups of students will be kicked out of the club. Input Specification: The first line contains two integers *n* and *m* — the initial number of students and laces (). The students are numbered from 1 to *n*, and the laces are numbered from 1 to *m*. Next *m* lines each contain two integers *a* and *b* — the numbers of students tied by the *i*-th lace (1<=≤<=*a*,<=*b*<=≤<=*n*,<=*a*<=≠<=*b*). It is guaranteed that no two students are tied with more than one lace. No lace ties a student to himself. Output Specification: Print the single number — the number of groups of students that will be kicked out from the club. Demo Input: ['3 3\n1 2\n2 3\n3 1\n', '6 3\n1 2\n2 3\n3 4\n', '6 5\n1 4\n2 4\n3 4\n5 4\n6 4\n'] Demo Output: ['0\n', '2\n', '1\n'] Note: In the first sample Anna and Maria won't kick out any group of students — in the initial position every student is tied to two other students and Anna won't be able to reprimand anyone. In the second sample four students are tied in a chain and two more are running by themselves. First Anna and Maria kick out the two students from both ends of the chain (1 and 4), then — two other students from the chain (2 and 3). At that the students who are running by themselves will stay in the club. In the third sample Anna and Maria will momentarily kick out all students except for the fourth one and the process stops at that point. The correct answer is one.
```python from collections import defaultdict n, m = map(int, input().split()) E = [tuple(map(int, input().split())) for _ in range(m)] adj = defaultdict(set) for e in E: adj[e[0]].add(e[1]) adj[e[1]].add(e[0]) dl = defaultdict(list) for v in adj: dl[len(adj[v])].append(v) if len(dl[1]) == 0: print('0') else: cnt = 0 cnt2 = sum(len(dl[x]) for x in dl.keys()) while cnt2 > len(dl[1]): dec = defaultdict(int) while len(dl[1]) > 0: v = dl[1].pop() cnt2 -= 1 for v2 in adj[v]: dec[v2] += 1 adj[v2].remove(v) del adj[v] cnt += 1 for v in dec.keys(): dl[len(adj[v]) + dec[v]].remove(v) if len(adj[v]) > 0: dl[len(adj[v])].append(v) else: cnt2 -= 1 if len(dl[1]) > 0: cnt += 1 print(cnt) ```
0
344
A
Magnets
PROGRAMMING
800
[ "implementation" ]
null
null
Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the opposite poles will attract each other. Mike starts by laying one magnet horizontally on the table. During each following step Mike adds one more magnet horizontally to the right end of the row. Depending on how Mike puts the magnet on the table, it is either attracted to the previous one (forming a group of multiple magnets linked together) or repelled by it (then Mike lays this magnet at some distance to the right from the previous one). We assume that a sole magnet not linked to others forms a group of its own. Mike arranged multiple magnets in a row. Determine the number of groups that the magnets formed.
The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100000) — the number of magnets. Then *n* lines follow. The *i*-th line (1<=≤<=*i*<=≤<=*n*) contains either characters "01", if Mike put the *i*-th magnet in the "plus-minus" position, or characters "10", if Mike put the magnet in the "minus-plus" position.
On the single line of the output print the number of groups of magnets.
[ "6\n10\n10\n10\n01\n10\n10\n", "4\n01\n01\n10\n10\n" ]
[ "3\n", "2\n" ]
The first testcase corresponds to the figure. The testcase has three groups consisting of three, one and two magnets. The second testcase has two groups, each consisting of two magnets.
500
[ { "input": "6\n10\n10\n10\n01\n10\n10", "output": "3" }, { "input": "4\n01\n01\n10\n10", "output": "2" }, { "input": "1\n10", "output": "1" }, { "input": "2\n01\n10", "output": "2" }, { "input": "2\n10\n10", "output": "1" }, { "input": "3\n10\n01\n10", "output": "3" }, { "input": "1\n01", "output": "1" }, { "input": "2\n01\n01", "output": "1" }, { "input": "2\n10\n01", "output": "2" }, { "input": "3\n01\n01\n01", "output": "1" }, { "input": "3\n10\n10\n01", "output": "2" }, { "input": "3\n01\n10\n10", "output": "2" }, { "input": "115\n10\n10\n10\n10\n01\n01\n10\n10\n10\n01\n01\n10\n01\n01\n10\n10\n10\n01\n10\n01\n10\n10\n01\n01\n10\n10\n10\n10\n01\n10\n01\n01\n10\n10\n10\n10\n01\n10\n10\n10\n01\n10\n01\n10\n10\n10\n10\n01\n01\n01\n10\n10\n01\n01\n01\n10\n10\n01\n10\n01\n01\n01\n01\n10\n10\n01\n10\n01\n01\n01\n01\n01\n10\n01\n10\n10\n01\n01\n01\n10\n01\n01\n10\n10\n01\n01\n01\n01\n01\n10\n01\n10\n01\n10\n01\n01\n01\n10\n01\n10\n10\n01\n10\n10\n01\n01\n01\n10\n10\n10\n10\n10\n10\n10\n10", "output": "55" } ]
1,696,006,574
2,147,483,647
Python 3
OK
TESTS
31
374
614,400
n = int(input()) c = 0 s = '' for i in range(n): a = input() s += a for j in range(1,len(s)): if s[j] == s[j-1]: c += 1 print(c+1)
Title: Magnets Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the opposite poles will attract each other. Mike starts by laying one magnet horizontally on the table. During each following step Mike adds one more magnet horizontally to the right end of the row. Depending on how Mike puts the magnet on the table, it is either attracted to the previous one (forming a group of multiple magnets linked together) or repelled by it (then Mike lays this magnet at some distance to the right from the previous one). We assume that a sole magnet not linked to others forms a group of its own. Mike arranged multiple magnets in a row. Determine the number of groups that the magnets formed. Input Specification: The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100000) — the number of magnets. Then *n* lines follow. The *i*-th line (1<=≤<=*i*<=≤<=*n*) contains either characters "01", if Mike put the *i*-th magnet in the "plus-minus" position, or characters "10", if Mike put the magnet in the "minus-plus" position. Output Specification: On the single line of the output print the number of groups of magnets. Demo Input: ['6\n10\n10\n10\n01\n10\n10\n', '4\n01\n01\n10\n10\n'] Demo Output: ['3\n', '2\n'] Note: The first testcase corresponds to the figure. The testcase has three groups consisting of three, one and two magnets. The second testcase has two groups, each consisting of two magnets.
```python n = int(input()) c = 0 s = '' for i in range(n): a = input() s += a for j in range(1,len(s)): if s[j] == s[j-1]: c += 1 print(c+1) ```
3
474
A
Keyboard
PROGRAMMING
900
[ "implementation" ]
null
null
Our good friend Mole is trying to code a big message. He is typing on an unusual keyboard with characters arranged in following way: Unfortunately Mole is blind, so sometimes it is problem for him to put his hands accurately. He accidentally moved both his hands with one position to the left or to the right. That means that now he presses not a button he wants, but one neighboring button (left or right, as specified in input). We have a sequence of characters he has typed and we want to find the original message.
First line of the input contains one letter describing direction of shifting ('L' or 'R' respectively for left or right). Second line contains a sequence of characters written by Mole. The size of this sequence will be no more than 100. Sequence contains only symbols that appear on Mole's keyboard. It doesn't contain spaces as there is no space on Mole's keyboard. It is guaranteed that even though Mole hands are moved, he is still pressing buttons on keyboard and not hitting outside it.
Print a line that contains the original message.
[ "R\ns;;upimrrfod;pbr\n" ]
[ "allyouneedislove\n" ]
none
500
[ { "input": "R\ns;;upimrrfod;pbr", "output": "allyouneedislove" }, { "input": "R\nwertyuiop;lkjhgfdsxcvbnm,.", "output": "qwertyuiolkjhgfdsazxcvbnm," }, { "input": "L\nzxcvbnm,kjhgfdsaqwertyuio", "output": "xcvbnm,.lkjhgfdswertyuiop" }, { "input": "R\nbubbuduppudup", "output": "vyvvysyooysyo" }, { "input": "L\ngggggggggggggggggggggggggggggggggggggggggg", "output": "hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh" }, { "input": "R\ngggggggggggggggggggggggggggggggggggggggggg", "output": "ffffffffffffffffffffffffffffffffffffffffff" }, { "input": "L\nggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg", "output": "hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh" }, { "input": "R\nggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg", "output": "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" }, { "input": "L\nxgwurenkxkiau,c,vonei.zltazmnkhqtwuogkgvgckvja,z.rhanuy.ybebmzcfwozkwvuuiolaqlgvvvewnbuinrncgjwjdsfw", "output": "cheitrmlclosi.v.bpmro/x;ysx,mljwyeiphlhbhvlbks.x/tjsmiu/unrn,xvgepxlebiiop;sw;hbbbremniomtmvhkekfdge" }, { "input": "L\nuoz.vmks,wxrb,nwcvdzh.m,hwsios.lvu,ktes,,ythddhm.sh,d,c,cfj.wqam,bowofbyx,jathqayhreqvixvbmgdokofmym", "output": "ipx/b,ld.ectn.mevbfxj/,.jedopd/;bi.lyrd..uyjffj,/dj.f.v.vgk/ews,.npepgnuc.ksyjwsujtrwbocbn,hfplpg,u," }, { "input": "R\noedjyrvuw/rn.v.hdwndbiposiewgsn.pnyf;/tsdohp,hrtd/mx,;coj./billd..mwbneohcikrdes/ucjr,wspthleyp,..f,", "output": "iwshtecyq.eb,c,gsqbsvuoiauwqfab,obtdl.rasigomgers.nzmlxih,.vukks,,nqvbwigxujeswa.yxhemqaorgkwtom,,dm" }, { "input": "R\nvgj;o;ijrtfyck,dthccioltcx,crub;oceooognsuvfx/kgo.fbsudv,yod.erdrxhbeiyltxhnrobbb;ydrgroefcr/f;uvdjd", "output": "cfhliluherdtxjmsrgxxuikrxzmxeyvlixwiiifbaycdz.jfi,dvayscmtis,wesezgvwutkrzgbeivvvltsefeiwdxe.dlycshs" }, { "input": "L\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq", "output": "wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww" }, { "input": "L\noooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo", "output": "pppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp" }, { "input": "L\n,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,", "output": "...................................................................................................." }, { "input": "L\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz", "output": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" }, { "input": "R\noooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo", "output": "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii" }, { "input": "R\nwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww", "output": "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq" }, { "input": "R\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "output": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz" }, { "input": "L\nq", "output": "w" }, { "input": "L\no", "output": "p" }, { "input": "L\n,", "output": "." }, { "input": "L\nz", "output": "x" }, { "input": "R\n.", "output": "," }, { "input": "R\no", "output": "i" }, { "input": "R\nw", "output": "q" }, { "input": "R\nx", "output": "z" }, { "input": "R\n,./", "output": "m,." }, { "input": "R\nwertuk;;/", "output": "qweryjll." }, { "input": "L\n..", "output": "//" } ]
1,690,620,569
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
46
0
key='''qwertyuiop asdfghjkl; zxcvbnm,./''' lr=input() s=input() shift=1 if lr=='L': shift=-1 msg='' for i in s: msg+=key[key.index(i)+shift] print(msg)
Title: Keyboard Time Limit: None seconds Memory Limit: None megabytes Problem Description: Our good friend Mole is trying to code a big message. He is typing on an unusual keyboard with characters arranged in following way: Unfortunately Mole is blind, so sometimes it is problem for him to put his hands accurately. He accidentally moved both his hands with one position to the left or to the right. That means that now he presses not a button he wants, but one neighboring button (left or right, as specified in input). We have a sequence of characters he has typed and we want to find the original message. Input Specification: First line of the input contains one letter describing direction of shifting ('L' or 'R' respectively for left or right). Second line contains a sequence of characters written by Mole. The size of this sequence will be no more than 100. Sequence contains only symbols that appear on Mole's keyboard. It doesn't contain spaces as there is no space on Mole's keyboard. It is guaranteed that even though Mole hands are moved, he is still pressing buttons on keyboard and not hitting outside it. Output Specification: Print a line that contains the original message. Demo Input: ['R\ns;;upimrrfod;pbr\n'] Demo Output: ['allyouneedislove\n'] Note: none
```python key='''qwertyuiop asdfghjkl; zxcvbnm,./''' lr=input() s=input() shift=1 if lr=='L': shift=-1 msg='' for i in s: msg+=key[key.index(i)+shift] print(msg) ```
0
557
A
Ilya and Diplomas
PROGRAMMING
1,100
[ "greedy", "implementation", "math" ]
null
null
Soon a school Olympiad in Informatics will be held in Berland, *n* schoolchildren will participate there. At a meeting of the jury of the Olympiad it was decided that each of the *n* participants, depending on the results, will get a diploma of the first, second or third degree. Thus, each student will receive exactly one diploma. They also decided that there must be given at least *min*1 and at most *max*1 diplomas of the first degree, at least *min*2 and at most *max*2 diplomas of the second degree, and at least *min*3 and at most *max*3 diplomas of the third degree. After some discussion it was decided to choose from all the options of distributing diplomas satisfying these limitations the one that maximizes the number of participants who receive diplomas of the first degree. Of all these options they select the one which maximizes the number of the participants who receive diplomas of the second degree. If there are multiple of these options, they select the option that maximizes the number of diplomas of the third degree. Choosing the best option of distributing certificates was entrusted to Ilya, one of the best programmers of Berland. However, he found more important things to do, so it is your task now to choose the best option of distributing of diplomas, based on the described limitations. It is guaranteed that the described limitations are such that there is a way to choose such an option of distributing diplomas that all *n* participants of the Olympiad will receive a diploma of some degree.
The first line of the input contains a single integer *n* (3<=≤<=*n*<=≤<=3·106) — the number of schoolchildren who will participate in the Olympiad. The next line of the input contains two integers *min*1 and *max*1 (1<=≤<=*min*1<=≤<=*max*1<=≤<=106) — the minimum and maximum limits on the number of diplomas of the first degree that can be distributed. The third line of the input contains two integers *min*2 and *max*2 (1<=≤<=*min*2<=≤<=*max*2<=≤<=106) — the minimum and maximum limits on the number of diplomas of the second degree that can be distributed. The next line of the input contains two integers *min*3 and *max*3 (1<=≤<=*min*3<=≤<=*max*3<=≤<=106) — the minimum and maximum limits on the number of diplomas of the third degree that can be distributed. It is guaranteed that *min*1<=+<=*min*2<=+<=*min*3<=≤<=*n*<=≤<=*max*1<=+<=*max*2<=+<=*max*3.
In the first line of the output print three numbers, showing how many diplomas of the first, second and third degree will be given to students in the optimal variant of distributing diplomas. The optimal variant of distributing diplomas is the one that maximizes the number of students who receive diplomas of the first degree. Of all the suitable options, the best one is the one which maximizes the number of participants who receive diplomas of the second degree. If there are several of these options, the best one is the one that maximizes the number of diplomas of the third degree.
[ "6\n1 5\n2 6\n3 7\n", "10\n1 2\n1 3\n1 5\n", "6\n1 3\n2 2\n2 2\n" ]
[ "1 2 3 \n", "2 3 5 \n", "2 2 2 \n" ]
none
500
[ { "input": "6\n1 5\n2 6\n3 7", "output": "1 2 3 " }, { "input": "10\n1 2\n1 3\n1 5", "output": "2 3 5 " }, { "input": "6\n1 3\n2 2\n2 2", "output": "2 2 2 " }, { "input": "55\n1 1000000\n40 50\n10 200", "output": "5 40 10 " }, { "input": "3\n1 1\n1 1\n1 1", "output": "1 1 1 " }, { "input": "3\n1 1000000\n1 1000000\n1 1000000", "output": "1 1 1 " }, { "input": "1000\n100 400\n300 500\n400 1200", "output": "300 300 400 " }, { "input": "3000000\n1 1000000\n1 1000000\n1 1000000", "output": "1000000 1000000 1000000 " }, { "input": "11\n3 5\n3 5\n3 5", "output": "5 3 3 " }, { "input": "12\n3 5\n3 5\n3 5", "output": "5 4 3 " }, { "input": "13\n3 5\n3 5\n3 5", "output": "5 5 3 " }, { "input": "3000000\n1000000 1000000\n1000000 1000000\n1000000 1000000", "output": "1000000 1000000 1000000 " }, { "input": "50\n1 100\n1 100\n1 100", "output": "48 1 1 " }, { "input": "1279\n123 670\n237 614\n846 923", "output": "196 237 846 " }, { "input": "1589\n213 861\n5 96\n506 634", "output": "861 96 632 " }, { "input": "2115\n987 987\n112 483\n437 959", "output": "987 483 645 " }, { "input": "641\n251 960\n34 370\n149 149", "output": "458 34 149 " }, { "input": "1655\n539 539\n10 425\n605 895", "output": "539 425 691 " }, { "input": "1477\n210 336\n410 837\n448 878", "output": "336 693 448 " }, { "input": "1707\n149 914\n190 422\n898 899", "output": "619 190 898 " }, { "input": "1529\n515 515\n563 869\n169 451", "output": "515 845 169 " }, { "input": "1543\n361 994\n305 407\n102 197", "output": "994 407 142 " }, { "input": "1107\n471 849\n360 741\n71 473", "output": "676 360 71 " }, { "input": "1629279\n267360 999930\n183077 674527\n202618 786988", "output": "999930 426731 202618 " }, { "input": "1233589\n2850 555444\n500608 921442\n208610 607343", "output": "524371 500608 208610 " }, { "input": "679115\n112687 183628\n101770 982823\n81226 781340", "output": "183628 414261 81226 " }, { "input": "1124641\n117999 854291\n770798 868290\n76651 831405", "output": "277192 770798 76651 " }, { "input": "761655\n88152 620061\n60403 688549\n79370 125321", "output": "620061 62224 79370 " }, { "input": "2174477\n276494 476134\n555283 954809\n319941 935631", "output": "476134 954809 743534 " }, { "input": "1652707\n201202 990776\n34796 883866\n162979 983308", "output": "990776 498952 162979 " }, { "input": "2065529\n43217 891429\n434379 952871\n650231 855105", "output": "891429 523869 650231 " }, { "input": "1702543\n405042 832833\n50931 747750\n381818 796831", "output": "832833 487892 381818 " }, { "input": "501107\n19061 859924\n126478 724552\n224611 489718", "output": "150018 126478 224611 " }, { "input": "1629279\n850831 967352\n78593 463906\n452094 885430", "output": "967352 209833 452094 " }, { "input": "1233589\n2850 157021\n535109 748096\n392212 475634", "output": "157021 684356 392212 " }, { "input": "679115\n125987 786267\n70261 688983\n178133 976789", "output": "430721 70261 178133 " }, { "input": "1124641\n119407 734250\n213706 860770\n102149 102149", "output": "734250 288242 102149 " }, { "input": "761655\n325539 325539\n280794 792505\n18540 106895", "output": "325539 417576 18540 " }, { "input": "2174477\n352351 791072\n365110 969163\n887448 955610", "output": "791072 495957 887448 " }, { "input": "1652707\n266774 638522\n65688 235422\n924898 992826", "output": "638522 89287 924898 " }, { "input": "2065529\n608515 608515\n751563 864337\n614898 705451", "output": "608515 842116 614898 " }, { "input": "1702543\n5784 996578\n47395 300407\n151614 710197", "output": "996578 300407 405558 " }, { "input": "501107\n8073 390048\n190494 647328\n274071 376923", "output": "36542 190494 274071 " }, { "input": "200\n50 50\n100 100\n50 50", "output": "50 100 50 " }, { "input": "14\n1 100\n1 100\n8 9", "output": "5 1 8 " }, { "input": "300\n200 400\n50 100\n40 80", "output": "210 50 40 " }, { "input": "10\n3 6\n3 6\n3 6", "output": "4 3 3 " }, { "input": "14\n3 6\n3 6\n3 6", "output": "6 5 3 " }, { "input": "17\n3 6\n3 6\n3 6", "output": "6 6 5 " }, { "input": "1000000\n300000 600000\n300000 600000\n300000 600000", "output": "400000 300000 300000 " }, { "input": "1400000\n300000 600000\n300000 600000\n300000 600000", "output": "600000 500000 300000 " }, { "input": "1700000\n300000 600000\n300000 600000\n300000 600000", "output": "600000 600000 500000 " }, { "input": "561\n400 400\n80 80\n81 81", "output": "400 80 81 " }, { "input": "2000\n100 1000\n1 1\n1 2000", "output": "1000 1 999 " }, { "input": "1000002\n1 1000000\n1 1000000\n999999 1000000", "output": "2 1 999999 " }, { "input": "1000002\n1 1000000\n1 1000000\n1000000 1000000", "output": "1 1 1000000 " } ]
1,568,190,156
2,147,483,647
PyPy 3
OK
TESTS
56
171
1,843,200
import math import itertools import collections def getdict(n): d = {} if type(n) is list: for i in n: if i in d: d[i] += 1 else: d[i] = 1 else: for i in range(n): t = ii() if t in d: d[t] += 1 else: d[t] = 1 return d def cdiv(n, k): return n // k + (n % k != 0) def ii(): return int(input()) def mi(): return map(int, input().split()) def li(): return list(map(int, input().split())) def lcm(a, b): return abs(a*b) // math.gcd(a, b) def wr(arr): return ' '.join(map(str, arr)) def prime(n): if n == 2: return True if n % 2 == 0 or n <= 1: return False sqr = int(math.sqrt(n)) + 1 for d in range(3, sqr, 2): if n % d == 0: return False return True def revn(n): m = 0 while n > 0: m = m * 10 + n % 10 n = n // 10 return m n = ii() mi1, ma1 = mi() mi2, ma2 = mi() mi3, ma3 = mi() d = [mi1, mi2, mi3] t = n - mi1 - mi2 - mi3 while t > 0 and d[0] < ma1: d[0] += 1 t -= 1 while t > 0 and d[1] < ma2: d[1] += 1 t -= 1 while t > 0 and d[2] < ma3: d[2] += 1 t -= 1 print(wr(d))
Title: Ilya and Diplomas Time Limit: None seconds Memory Limit: None megabytes Problem Description: Soon a school Olympiad in Informatics will be held in Berland, *n* schoolchildren will participate there. At a meeting of the jury of the Olympiad it was decided that each of the *n* participants, depending on the results, will get a diploma of the first, second or third degree. Thus, each student will receive exactly one diploma. They also decided that there must be given at least *min*1 and at most *max*1 diplomas of the first degree, at least *min*2 and at most *max*2 diplomas of the second degree, and at least *min*3 and at most *max*3 diplomas of the third degree. After some discussion it was decided to choose from all the options of distributing diplomas satisfying these limitations the one that maximizes the number of participants who receive diplomas of the first degree. Of all these options they select the one which maximizes the number of the participants who receive diplomas of the second degree. If there are multiple of these options, they select the option that maximizes the number of diplomas of the third degree. Choosing the best option of distributing certificates was entrusted to Ilya, one of the best programmers of Berland. However, he found more important things to do, so it is your task now to choose the best option of distributing of diplomas, based on the described limitations. It is guaranteed that the described limitations are such that there is a way to choose such an option of distributing diplomas that all *n* participants of the Olympiad will receive a diploma of some degree. Input Specification: The first line of the input contains a single integer *n* (3<=≤<=*n*<=≤<=3·106) — the number of schoolchildren who will participate in the Olympiad. The next line of the input contains two integers *min*1 and *max*1 (1<=≤<=*min*1<=≤<=*max*1<=≤<=106) — the minimum and maximum limits on the number of diplomas of the first degree that can be distributed. The third line of the input contains two integers *min*2 and *max*2 (1<=≤<=*min*2<=≤<=*max*2<=≤<=106) — the minimum and maximum limits on the number of diplomas of the second degree that can be distributed. The next line of the input contains two integers *min*3 and *max*3 (1<=≤<=*min*3<=≤<=*max*3<=≤<=106) — the minimum and maximum limits on the number of diplomas of the third degree that can be distributed. It is guaranteed that *min*1<=+<=*min*2<=+<=*min*3<=≤<=*n*<=≤<=*max*1<=+<=*max*2<=+<=*max*3. Output Specification: In the first line of the output print three numbers, showing how many diplomas of the first, second and third degree will be given to students in the optimal variant of distributing diplomas. The optimal variant of distributing diplomas is the one that maximizes the number of students who receive diplomas of the first degree. Of all the suitable options, the best one is the one which maximizes the number of participants who receive diplomas of the second degree. If there are several of these options, the best one is the one that maximizes the number of diplomas of the third degree. Demo Input: ['6\n1 5\n2 6\n3 7\n', '10\n1 2\n1 3\n1 5\n', '6\n1 3\n2 2\n2 2\n'] Demo Output: ['1 2 3 \n', '2 3 5 \n', '2 2 2 \n'] Note: none
```python import math import itertools import collections def getdict(n): d = {} if type(n) is list: for i in n: if i in d: d[i] += 1 else: d[i] = 1 else: for i in range(n): t = ii() if t in d: d[t] += 1 else: d[t] = 1 return d def cdiv(n, k): return n // k + (n % k != 0) def ii(): return int(input()) def mi(): return map(int, input().split()) def li(): return list(map(int, input().split())) def lcm(a, b): return abs(a*b) // math.gcd(a, b) def wr(arr): return ' '.join(map(str, arr)) def prime(n): if n == 2: return True if n % 2 == 0 or n <= 1: return False sqr = int(math.sqrt(n)) + 1 for d in range(3, sqr, 2): if n % d == 0: return False return True def revn(n): m = 0 while n > 0: m = m * 10 + n % 10 n = n // 10 return m n = ii() mi1, ma1 = mi() mi2, ma2 = mi() mi3, ma3 = mi() d = [mi1, mi2, mi3] t = n - mi1 - mi2 - mi3 while t > 0 and d[0] < ma1: d[0] += 1 t -= 1 while t > 0 and d[1] < ma2: d[1] += 1 t -= 1 while t > 0 and d[2] < ma3: d[2] += 1 t -= 1 print(wr(d)) ```
3
0
none
none
none
0
[ "none" ]
null
null
Paul hates palindromes. He assumes that string *s* is tolerable if each its character is one of the first *p* letters of the English alphabet and *s* doesn't contain any palindrome contiguous substring of length 2 or more. Paul has found a tolerable string *s* of length *n*. Help him find the lexicographically next tolerable string of the same length or else state that such string does not exist.
The first line contains two space-separated integers: *n* and *p* (1<=≤<=*n*<=≤<=1000; 1<=≤<=*p*<=≤<=26). The second line contains string *s*, consisting of *n* small English letters. It is guaranteed that the string is tolerable (according to the above definition).
If the lexicographically next tolerable string of the same length exists, print it. Otherwise, print "NO" (without the quotes).
[ "3 3\ncba\n", "3 4\ncba\n", "4 4\nabcd\n" ]
[ "NO\n", "cbd\n", "abda\n" ]
String *s* is lexicographically larger (or simply larger) than string *t* with the same length, if there is number *i*, such that *s*<sub class="lower-index">1</sub> = *t*<sub class="lower-index">1</sub>, ..., *s*<sub class="lower-index">*i*</sub> = *t*<sub class="lower-index">*i*</sub>, *s*<sub class="lower-index">*i* + 1</sub> &gt; *t*<sub class="lower-index">*i* + 1</sub>. The lexicographically next tolerable string is the lexicographically minimum tolerable string which is larger than the given one. A palindrome is a string that reads the same forward or reversed.
0
[ { "input": "3 3\ncba", "output": "NO" }, { "input": "3 4\ncba", "output": "cbd" }, { "input": "4 4\nabcd", "output": "abda" }, { "input": "2 2\nab", "output": "ba" }, { "input": "2 2\nba", "output": "NO" }, { "input": "1 2\na", "output": "b" }, { "input": "1 2\nb", "output": "NO" }, { "input": "1 1\na", "output": "NO" }, { "input": "3 4\ncdb", "output": "dab" }, { "input": "7 26\nzyxzyxz", "output": "NO" }, { "input": "10 5\nabcabcabca", "output": "abcabcabcd" }, { "input": "10 10\nfajegfaicb", "output": "fajegfaicd" }, { "input": "1 26\no", "output": "p" }, { "input": "1 2\nb", "output": "NO" }, { "input": "1 26\nz", "output": "NO" }, { "input": "3 3\ncab", "output": "cba" }, { "input": "3 26\nyzx", "output": "zab" }, { "input": "5 5\naceba", "output": "acebc" }, { "input": "10 3\ncbacbacbac", "output": "NO" }, { "input": "11 3\nabcabcabcab", "output": "acbacbacbac" }, { "input": "12 10\nabcabcabcabc", "output": "abcabcabcabd" }, { "input": "13 7\ngfegfegfegfeg", "output": "NO" }, { "input": "15 11\ncgjkbadjfbdaikj", "output": "cgjkbadjfbdajba" }, { "input": "17 4\ndabcadcbdcadbcdbc", "output": "dabcadcbdcadcabca" }, { "input": "26 26\nahnxdnbfcriersyzdihuecojdi", "output": "ahnxdnbfcriersyzdihuecojdk" }, { "input": "30 7\ncedcfedcfgcfgcbadcadgfaegfacgf", "output": "cedcfedcfgcfgcbadcadgfaegfadba" }, { "input": "70 4\ndcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbd", "output": "NO" }, { "input": "77 7\ncadgbagbcaecgfaegcdbeafbacbdfgaedgcdeabgebaecbeacgfebagedcegdafdgeacegfegfegf", "output": "cadgbagbcaecgfaegcdbeafbacbdfgaedgcdeabgebaecbeacgfebagedcegdafdgeacfabcabcab" }, { "input": "100 4\nabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabca", "output": "abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcd" }, { "input": "333 5\nedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedcedc", "output": "NO" }, { "input": "3 3\nacb", "output": "bac" }, { "input": "17 26\nbazyxzyxzyxzyxzyx", "output": "bcabcabcabcabcabc" }, { "input": "6 3\nacbacb", "output": "bacbac" }, { "input": "6 3\nabcabc", "output": "acbacb" }, { "input": "302 4\nabdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcb", "output": "acbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbac" }, { "input": "30 26\nabcabcabczyxzyxzyxzyxzyxzyxzyx", "output": "abcabcabdabcabcabcabcabcabcabc" }, { "input": "300 3\nabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc", "output": "acbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacb" }, { "input": "2 4\ncd", "output": "da" } ]
1,410,110,988
7,188
Python 3
WRONG_ANSWER
PRETESTS
2
62
0
v=list(input().split()) n=int(v[0]) p=int(v[1]) v=list(ord(x)-97 for x in input()) from math import floor def cp(x,y): global v cpc=0 cpk=0 cpn=floor((y-x)/2) for cpi in range (cpn+1): if v[x+cpk]==v[y-cpk]: cpc+=1 cpk+=1 if (cpn+1)==cpc: return 1 else: return 0 k=n-1 while k>-1: #print (k,v) hp=0 if v[k]<(p-1): v[k]+=1 else: #if k>0: tk=k-1 while tk>-1: if v[tk]<(p-1): v[tk]+=1 #vpsit k if v[tk]==k: continue for j in range(tk+1,n): v[j]=0 break tk-=1 if tk==-1: hp=1 break #else: # hp=1 # break for i in range (n-2,-1,-1): #print (k,v,cp(i,n-1)) if cp(i,n-1): hp=1 break if not hp: break if hp: print("NO") else: answ="" for i in range(n): answ+=chr(v[i]+97) print(answ)
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Paul hates palindromes. He assumes that string *s* is tolerable if each its character is one of the first *p* letters of the English alphabet and *s* doesn't contain any palindrome contiguous substring of length 2 or more. Paul has found a tolerable string *s* of length *n*. Help him find the lexicographically next tolerable string of the same length or else state that such string does not exist. Input Specification: The first line contains two space-separated integers: *n* and *p* (1<=≤<=*n*<=≤<=1000; 1<=≤<=*p*<=≤<=26). The second line contains string *s*, consisting of *n* small English letters. It is guaranteed that the string is tolerable (according to the above definition). Output Specification: If the lexicographically next tolerable string of the same length exists, print it. Otherwise, print "NO" (without the quotes). Demo Input: ['3 3\ncba\n', '3 4\ncba\n', '4 4\nabcd\n'] Demo Output: ['NO\n', 'cbd\n', 'abda\n'] Note: String *s* is lexicographically larger (or simply larger) than string *t* with the same length, if there is number *i*, such that *s*<sub class="lower-index">1</sub> = *t*<sub class="lower-index">1</sub>, ..., *s*<sub class="lower-index">*i*</sub> = *t*<sub class="lower-index">*i*</sub>, *s*<sub class="lower-index">*i* + 1</sub> &gt; *t*<sub class="lower-index">*i* + 1</sub>. The lexicographically next tolerable string is the lexicographically minimum tolerable string which is larger than the given one. A palindrome is a string that reads the same forward or reversed.
```python v=list(input().split()) n=int(v[0]) p=int(v[1]) v=list(ord(x)-97 for x in input()) from math import floor def cp(x,y): global v cpc=0 cpk=0 cpn=floor((y-x)/2) for cpi in range (cpn+1): if v[x+cpk]==v[y-cpk]: cpc+=1 cpk+=1 if (cpn+1)==cpc: return 1 else: return 0 k=n-1 while k>-1: #print (k,v) hp=0 if v[k]<(p-1): v[k]+=1 else: #if k>0: tk=k-1 while tk>-1: if v[tk]<(p-1): v[tk]+=1 #vpsit k if v[tk]==k: continue for j in range(tk+1,n): v[j]=0 break tk-=1 if tk==-1: hp=1 break #else: # hp=1 # break for i in range (n-2,-1,-1): #print (k,v,cp(i,n-1)) if cp(i,n-1): hp=1 break if not hp: break if hp: print("NO") else: answ="" for i in range(n): answ+=chr(v[i]+97) print(answ) ```
0
0
none
none
none
0
[ "none" ]
null
null
You are given two lists of non-zero digits. Let's call an integer pretty if its (base 10) representation has at least one digit from the first list and at least one digit from the second list. What is the smallest positive pretty integer?
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=9) — the lengths of the first and the second lists, respectively. The second line contains *n* distinct digits *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=9) — the elements of the first list. The third line contains *m* distinct digits *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=9) — the elements of the second list.
Print the smallest pretty integer.
[ "2 3\n4 2\n5 7 6\n", "8 8\n1 2 3 4 5 6 7 8\n8 7 6 5 4 3 2 1\n" ]
[ "25\n", "1\n" ]
In the first example 25, 46, 24567 are pretty, as well as many other integers. The smallest among them is 25. 42 and 24 are not pretty because they don't have digits from the second list. In the second example all integers that have at least one digit different from 9 are pretty. It's obvious that the smallest among them is 1, because it's the smallest positive integer.
0
[ { "input": "2 3\n4 2\n5 7 6", "output": "25" }, { "input": "8 8\n1 2 3 4 5 6 7 8\n8 7 6 5 4 3 2 1", "output": "1" }, { "input": "1 1\n9\n1", "output": "19" }, { "input": "9 1\n5 4 2 3 6 1 7 9 8\n9", "output": "9" }, { "input": "5 3\n7 2 5 8 6\n3 1 9", "output": "12" }, { "input": "4 5\n5 2 6 4\n8 9 1 3 7", "output": "12" }, { "input": "5 9\n4 2 1 6 7\n2 3 4 5 6 7 8 9 1", "output": "1" }, { "input": "9 9\n5 4 3 2 1 6 7 8 9\n3 2 1 5 4 7 8 9 6", "output": "1" }, { "input": "9 5\n2 3 4 5 6 7 8 9 1\n4 2 1 6 7", "output": "1" }, { "input": "9 9\n1 2 3 4 5 6 7 8 9\n1 2 3 4 5 6 7 8 9", "output": "1" }, { "input": "9 9\n1 2 3 4 5 6 7 8 9\n9 8 7 6 5 4 3 2 1", "output": "1" }, { "input": "9 9\n9 8 7 6 5 4 3 2 1\n1 2 3 4 5 6 7 8 9", "output": "1" }, { "input": "9 9\n9 8 7 6 5 4 3 2 1\n9 8 7 6 5 4 3 2 1", "output": "1" }, { "input": "1 1\n8\n9", "output": "89" }, { "input": "1 1\n9\n8", "output": "89" }, { "input": "1 1\n1\n2", "output": "12" }, { "input": "1 1\n2\n1", "output": "12" }, { "input": "1 1\n9\n9", "output": "9" }, { "input": "1 1\n1\n1", "output": "1" }, { "input": "4 5\n3 2 4 5\n1 6 5 9 8", "output": "5" }, { "input": "3 2\n4 5 6\n1 5", "output": "5" }, { "input": "5 4\n1 3 5 6 7\n2 4 3 9", "output": "3" }, { "input": "5 5\n1 3 5 7 9\n2 4 6 8 9", "output": "9" }, { "input": "2 2\n1 8\n2 8", "output": "8" }, { "input": "5 5\n5 6 7 8 9\n1 2 3 4 5", "output": "5" }, { "input": "5 5\n1 2 3 4 5\n1 2 3 4 5", "output": "1" }, { "input": "5 5\n1 2 3 4 5\n2 3 4 5 6", "output": "2" }, { "input": "2 2\n1 5\n2 5", "output": "5" }, { "input": "4 4\n1 3 5 8\n2 4 6 8", "output": "8" }, { "input": "3 3\n1 5 3\n2 5 7", "output": "5" }, { "input": "3 3\n3 6 8\n2 6 9", "output": "6" }, { "input": "2 2\n1 4\n2 4", "output": "4" }, { "input": "5 3\n3 4 5 6 7\n1 5 9", "output": "5" }, { "input": "4 4\n1 2 3 4\n2 5 6 7", "output": "2" }, { "input": "5 5\n1 2 3 4 5\n9 2 1 7 5", "output": "1" }, { "input": "2 2\n1 3\n2 3", "output": "3" }, { "input": "3 3\n3 2 1\n3 2 1", "output": "1" }, { "input": "3 3\n1 3 5\n2 3 6", "output": "3" }, { "input": "3 3\n5 6 7\n5 6 7", "output": "5" }, { "input": "1 2\n5\n2 5", "output": "5" }, { "input": "3 3\n2 4 9\n7 8 9", "output": "9" }, { "input": "3 3\n1 2 4\n3 4 5", "output": "4" }, { "input": "3 2\n1 4 9\n2 4", "output": "4" }, { "input": "3 3\n3 5 6\n1 5 9", "output": "5" }, { "input": "3 2\n1 2 4\n3 4", "output": "4" }, { "input": "2 4\n8 9\n1 2 3 9", "output": "9" }, { "input": "1 2\n9\n8 9", "output": "9" }, { "input": "3 2\n1 2 4\n4 2", "output": "2" }, { "input": "2 3\n4 5\n1 3 5", "output": "5" }, { "input": "3 2\n1 2 3\n2 3", "output": "2" }, { "input": "4 3\n1 3 5 9\n2 8 9", "output": "9" }, { "input": "2 2\n1 9\n9 2", "output": "9" } ]
1,508,055,004
304
Python 3
RUNTIME_ERROR
PRETESTS
2
46
0
I = lambda: map(int, input().split()) I() a = list(I()) b = list(I()) inter = list(set(a) & set(b)) if len(inter) > 0: print(min(*inter)) exit(0) x = min(*a) y = min(*b) print(10*x +y)
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given two lists of non-zero digits. Let's call an integer pretty if its (base 10) representation has at least one digit from the first list and at least one digit from the second list. What is the smallest positive pretty integer? Input Specification: The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=9) — the lengths of the first and the second lists, respectively. The second line contains *n* distinct digits *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=9) — the elements of the first list. The third line contains *m* distinct digits *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=9) — the elements of the second list. Output Specification: Print the smallest pretty integer. Demo Input: ['2 3\n4 2\n5 7 6\n', '8 8\n1 2 3 4 5 6 7 8\n8 7 6 5 4 3 2 1\n'] Demo Output: ['25\n', '1\n'] Note: In the first example 25, 46, 24567 are pretty, as well as many other integers. The smallest among them is 25. 42 and 24 are not pretty because they don't have digits from the second list. In the second example all integers that have at least one digit different from 9 are pretty. It's obvious that the smallest among them is 1, because it's the smallest positive integer.
```python I = lambda: map(int, input().split()) I() a = list(I()) b = list(I()) inter = list(set(a) & set(b)) if len(inter) > 0: print(min(*inter)) exit(0) x = min(*a) y = min(*b) print(10*x +y) ```
-1
11
B
Jumping Jack
PROGRAMMING
1,600
[ "math" ]
B. Jumping Jack
1
64
Jack is working on his jumping skills recently. Currently he's located at point zero of the number line. He would like to get to the point *x*. In order to train, he has decided that he'll first jump by only one unit, and each subsequent jump will be exactly one longer than the previous one. He can go either left or right with each jump. He wonders how many jumps he needs to reach *x*.
The input data consists of only one integer *x* (<=-<=109<=≤<=*x*<=≤<=109).
Output the minimal number of jumps that Jack requires to reach *x*.
[ "2\n", "6\n", "0\n" ]
[ "3\n", "3\n", "0\n" ]
none
0
[ { "input": "2", "output": "3" }, { "input": "6", "output": "3" }, { "input": "0", "output": "0" }, { "input": "-1000000000", "output": "44723" }, { "input": "999961560", "output": "44720" }, { "input": "999961561", "output": "44721" }, { "input": "999961559", "output": "44721" }, { "input": "-488979819", "output": "31273" }, { "input": "-865918189", "output": "41617" }, { "input": "-278253406", "output": "23591" }, { "input": "-87275307", "output": "13213" }, { "input": "103702792", "output": "14403" }, { "input": "294680891", "output": "24277" }, { "input": "485658989", "output": "31166" }, { "input": "676637088", "output": "36787" }, { "input": "867615187", "output": "41657" }, { "input": "-941406715", "output": "43393" }, { "input": "-897912263", "output": "42377" }, { "input": "-706934164", "output": "37603" }, { "input": "-790244010", "output": "39755" }, { "input": "16417015", "output": "5730" }, { "input": "823078041", "output": "40573" }, { "input": "-517744582", "output": "32179" }, { "input": "288916443", "output": "24038" }, { "input": "-904422532", "output": "42531" }, { "input": "-245245154", "output": "22147" }, { "input": "561415872", "output": "33511" }, { "input": "-779406751", "output": "39482" }, { "input": "27254274", "output": "7383" }, { "input": "845249034", "output": "41116" } ]
1,562,536,310
2,147,483,647
Python 3
OK
TESTS
30
218
0
""" Jack is working on his jumping skills recently. Currently he's located at point zero of the number line. He would like to get to the point x. In order to train, he has decided that he'll first jump by only one unit, and each subsequent jump will be exactly one longer than the previous one. He can go either left or right with each jump. He wonders how many jumps he needs to reach x. Input The input data consists of only one integer x ( - 109 ≤ x ≤ 109). Output Output the minimal number of jumps that Jack requires to reach x. """ from math import * def is_even(a): return False if a%2 else True def calc_sum(n): return n * (n + 1)/2 def check(a, x): return (not is_even(a) and not is_even(x)) or (is_even(a) and is_even(x)) x = abs(int(input())) if x == 0: print(0) else: n = (-1+pow(1+4*2*x, 0.5))/2 ceil_n = ceil(n) if check(calc_sum(ceil_n), x): print(ceil_n) else: if check(calc_sum(ceil_n + 1), x): print(ceil_n + 1) else: print(ceil_n + 2)
Title: Jumping Jack Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: Jack is working on his jumping skills recently. Currently he's located at point zero of the number line. He would like to get to the point *x*. In order to train, he has decided that he'll first jump by only one unit, and each subsequent jump will be exactly one longer than the previous one. He can go either left or right with each jump. He wonders how many jumps he needs to reach *x*. Input Specification: The input data consists of only one integer *x* (<=-<=109<=≤<=*x*<=≤<=109). Output Specification: Output the minimal number of jumps that Jack requires to reach *x*. Demo Input: ['2\n', '6\n', '0\n'] Demo Output: ['3\n', '3\n', '0\n'] Note: none
```python """ Jack is working on his jumping skills recently. Currently he's located at point zero of the number line. He would like to get to the point x. In order to train, he has decided that he'll first jump by only one unit, and each subsequent jump will be exactly one longer than the previous one. He can go either left or right with each jump. He wonders how many jumps he needs to reach x. Input The input data consists of only one integer x ( - 109 ≤ x ≤ 109). Output Output the minimal number of jumps that Jack requires to reach x. """ from math import * def is_even(a): return False if a%2 else True def calc_sum(n): return n * (n + 1)/2 def check(a, x): return (not is_even(a) and not is_even(x)) or (is_even(a) and is_even(x)) x = abs(int(input())) if x == 0: print(0) else: n = (-1+pow(1+4*2*x, 0.5))/2 ceil_n = ceil(n) if check(calc_sum(ceil_n), x): print(ceil_n) else: if check(calc_sum(ceil_n + 1), x): print(ceil_n + 1) else: print(ceil_n + 2) ```
3.891
393
A
Nineteen
PROGRAMMING
0
[]
null
null
Alice likes word "nineteen" very much. She has a string *s* and wants the string to contain as many such words as possible. For that reason she can rearrange the letters of the string. For example, if she has string "xiineteenppnnnewtnee", she can get string "xnineteenppnineteenw", containing (the occurrences marked) two such words. More formally, word "nineteen" occurs in the string the number of times you can read it starting from some letter of the string. Of course, you shouldn't skip letters. Help her to find the maximum number of "nineteen"s that she can get in her string.
The first line contains a non-empty string *s*, consisting only of lowercase English letters. The length of string *s* doesn't exceed 100.
Print a single integer — the maximum number of "nineteen"s that she can get in her string.
[ "nniinneetteeeenn\n", "nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii\n", "nineteenineteen\n" ]
[ "2", "2", "2" ]
none
500
[ { "input": "nniinneetteeeenn", "output": "2" }, { "input": "nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii", "output": "2" }, { "input": "nineteenineteen", "output": "2" }, { "input": "nssemsnnsitjtihtthij", "output": "0" }, { "input": "eehihnttehtherjsihihnrhimihrjinjiehmtjimnrss", "output": "1" }, { "input": "rrrteiehtesisntnjirtitijnjjjthrsmhtneirjimniemmnrhirssjnhetmnmjejjnjjritjttnnrhnjs", "output": "2" }, { "input": "mmrehtretseihsrjmtsenemniehssnisijmsnntesismmtmthnsieijjjnsnhisi", "output": "2" }, { "input": "hshretttnntmmiertrrnjihnrmshnthirnnirrheinnnrjiirshthsrsijtrrtrmnjrrjnresnintnmtrhsnjrinsseimn", "output": "1" }, { "input": "snmmensntritetnmmmerhhrmhnehehtesmhthseemjhmnrti", "output": "2" }, { "input": "rmeetriiitijmrenmeiijt", "output": "0" }, { "input": "ihimeitimrmhriemsjhrtjtijtesmhemnmmrsetmjttthtjhnnmirtimne", "output": "1" }, { "input": "rhtsnmnesieernhstjnmmirthhieejsjttsiierhihhrrijhrrnejsjer", "output": "2" }, { "input": "emmtjsjhretehmiiiestmtmnmissjrstnsnjmhimjmststsitemtttjrnhsrmsenjtjim", "output": "2" }, { "input": "nmehhjrhirniitshjtrrtitsjsntjhrstjehhhrrerhemehjeermhmhjejjesnhsiirheijjrnrjmminneeehtm", "output": "3" }, { "input": "hsntijjetmehejtsitnthietssmeenjrhhetsnjrsethisjrtrhrierjtmimeenjnhnijeesjttrmn", "output": "3" }, { "input": "jnirirhmirmhisemittnnsmsttesjhmjnsjsmntisheneiinsrjsjirnrmnjmjhmistntersimrjni", "output": "1" }, { "input": "neithjhhhtmejjnmieishethmtetthrienrhjmjenrmtejerernmthmsnrthhtrimmtmshm", "output": "2" }, { "input": "sithnrsnemhijsnjitmijjhejjrinejhjinhtisttteermrjjrtsirmessejireihjnnhhemiirmhhjeet", "output": "3" }, { "input": "jrjshtjstteh", "output": "0" }, { "input": "jsihrimrjnnmhttmrtrenetimemjnshnimeiitmnmjishjjneisesrjemeshjsijithtn", "output": "2" }, { "input": "hhtjnnmsemermhhtsstejehsssmnesereehnnsnnremjmmieethmirjjhn", "output": "2" }, { "input": "tmnersmrtsehhntsietttrehrhneiireijnijjejmjhei", "output": "1" }, { "input": "mtstiresrtmesritnjriirehtermtrtseirtjrhsejhhmnsineinsjsin", "output": "2" }, { "input": "ssitrhtmmhtnmtreijteinimjemsiiirhrttinsnneshintjnin", "output": "1" }, { "input": "rnsrsmretjiitrjthhritniijhjmm", "output": "0" }, { "input": "hntrteieimrimteemenserntrejhhmijmtjjhnsrsrmrnsjseihnjmehtthnnithirnhj", "output": "3" }, { "input": "nmmtsmjrntrhhtmimeresnrinstjnhiinjtnjjjnthsintmtrhijnrnmtjihtinmni", "output": "0" }, { "input": "eihstiirnmteejeehimttrijittjsntjejmessstsemmtristjrhenithrrsssihnthheehhrnmimssjmejjreimjiemrmiis", "output": "2" }, { "input": "srthnimimnemtnmhsjmmmjmmrsrisehjseinemienntetmitjtnnneseimhnrmiinsismhinjjnreehseh", "output": "3" }, { "input": "etrsmrjehntjjimjnmsresjnrthjhehhtreiijjminnheeiinseenmmethiemmistsei", "output": "3" }, { "input": "msjeshtthsieshejsjhsnhejsihisijsertenrshhrthjhiirijjneinjrtrmrs", "output": "1" }, { "input": "mehsmstmeejrhhsjihntjmrjrihssmtnensttmirtieehimj", "output": "1" }, { "input": "mmmsermimjmrhrhejhrrejermsneheihhjemnehrhihesnjsehthjsmmjeiejmmnhinsemjrntrhrhsmjtttsrhjjmejj", "output": "2" }, { "input": "rhsmrmesijmmsnsmmhertnrhsetmisshriirhetmjihsmiinimtrnitrseii", "output": "1" }, { "input": "iihienhirmnihh", "output": "0" }, { "input": "ismtthhshjmhisssnmnhe", "output": "0" }, { "input": "rhsmnrmhejshinnjrtmtsssijimimethnm", "output": "0" }, { "input": "eehnshtiriejhiirntminrirnjihmrnittnmmnjejjhjtennremrnssnejtntrtsiejjijisermj", "output": "3" }, { "input": "rnhmeesnhttrjintnhnrhristjrthhrmehrhjmjhjehmstrijemjmmistes", "output": "2" }, { "input": "ssrmjmjeeetrnimemrhimes", "output": "0" }, { "input": "n", "output": "0" }, { "input": "ni", "output": "0" }, { "input": "nine", "output": "0" }, { "input": "nineteenineteenineteenineteenineteenineteenineteenineteenineteenineteenineteenineteenineteen", "output": "13" }, { "input": "ninetee", "output": "0" }, { "input": "mzbmweyydiadtlcouegmdbyfwurpwbpuvhifnuapwynd", "output": "0" }, { "input": "zenudggmyopddhszhrbmftgzmjorabhgojdtfnzxjkayjlkgczsyshczutkdch", "output": "0" }, { "input": "rtzxovxqfapkdmelxiyjroohufhbakpmmvaxq", "output": "0" }, { "input": "zninetneeineteeniwnteeennieteenineteenineteenineteenineteenineteenineteenineteenineteeninetzeenz", "output": "13" }, { "input": "nnnnnnniiiiiiiiiiiitttttttttteeeeeeeeeeeeeeeeee", "output": "3" }, { "input": "ttttiiiieeeeeeeeeeeennnnnnnnn", "output": "4" }, { "input": "ttttttttteeeeeeeeeeeeeeeeeeeeeiiiiiiiiiiiinnnnnnn", "output": "3" }, { "input": "nnnnnnnnnneeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeiiiiiiiiiiiiiiiiiiiitttttttttttttttttttt", "output": "4" }, { "input": "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeiiiiiiiiiiiiiiiiittttttttttttttttnnnnnnn", "output": "3" }, { "input": "nineeen", "output": "0" }, { "input": "nineteeeeeeeeeeeeeeeeettttttttttttttttttiiiiiiiiiiiiiiiiii", "output": "0" }, { "input": "nineteenieteenieteenieteenieteenieteenieteen", "output": "4" }, { "input": "nineteenineteenineteenineteenineteen", "output": "5" } ]
1,567,285,515
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
44
140
102,400
s = input() d = {} for i in range(26): d[chr(i+97)] = s.count(chr(i+97)) # print(d['n'], d['e'], d['i'], d['t']) ans = 0 if(d['n'] >= 3 and d['e'] >= 3 and d['i'] >= 1 and d['t'] >= 1): ans += 1 d['n'] -= 3 d['e'] -= 3 d['i'] -= 1 d['t'] -= 1 while(d['n'] >= 2 and d['e'] >= 3 and d['i'] >= 1 and d['t'] >= 1): ans += 1 d['n'] -= 2 d['e'] -= 3 d['i'] -= 1 d['t'] -= 1 print(ans)
Title: Nineteen Time Limit: None seconds Memory Limit: None megabytes Problem Description: Alice likes word "nineteen" very much. She has a string *s* and wants the string to contain as many such words as possible. For that reason she can rearrange the letters of the string. For example, if she has string "xiineteenppnnnewtnee", she can get string "xnineteenppnineteenw", containing (the occurrences marked) two such words. More formally, word "nineteen" occurs in the string the number of times you can read it starting from some letter of the string. Of course, you shouldn't skip letters. Help her to find the maximum number of "nineteen"s that she can get in her string. Input Specification: The first line contains a non-empty string *s*, consisting only of lowercase English letters. The length of string *s* doesn't exceed 100. Output Specification: Print a single integer — the maximum number of "nineteen"s that she can get in her string. Demo Input: ['nniinneetteeeenn\n', 'nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii\n', 'nineteenineteen\n'] Demo Output: ['2', '2', '2'] Note: none
```python s = input() d = {} for i in range(26): d[chr(i+97)] = s.count(chr(i+97)) # print(d['n'], d['e'], d['i'], d['t']) ans = 0 if(d['n'] >= 3 and d['e'] >= 3 and d['i'] >= 1 and d['t'] >= 1): ans += 1 d['n'] -= 3 d['e'] -= 3 d['i'] -= 1 d['t'] -= 1 while(d['n'] >= 2 and d['e'] >= 3 and d['i'] >= 1 and d['t'] >= 1): ans += 1 d['n'] -= 2 d['e'] -= 3 d['i'] -= 1 d['t'] -= 1 print(ans) ```
0
69
A
Young Physicist
PROGRAMMING
1,000
[ "implementation", "math" ]
A. Young Physicist
2
256
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces.
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100).
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
[ "3\n4 1 7\n-2 4 -1\n1 -5 -3\n", "3\n3 -1 7\n-5 2 -4\n2 -1 -3\n" ]
[ "NO", "YES" ]
none
500
[ { "input": "3\n4 1 7\n-2 4 -1\n1 -5 -3", "output": "NO" }, { "input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3", "output": "YES" }, { "input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41", "output": "NO" }, { "input": "10\n25 -33 43\n-27 -42 28\n-35 -20 19\n41 -42 -1\n49 -39 -4\n-49 -22 7\n-19 29 41\n8 -27 -43\n8 34 9\n-11 -3 33", "output": "NO" }, { "input": "10\n-6 21 18\n20 -11 -8\n37 -11 41\n-5 8 33\n29 23 32\n30 -33 -11\n39 -49 -36\n28 34 -49\n22 29 -34\n-18 -6 7", "output": "NO" }, { "input": "10\n47 -2 -27\n0 26 -14\n5 -12 33\n2 18 3\n45 -30 -49\n4 -18 8\n-46 -44 -41\n-22 -10 -40\n-35 -21 26\n33 20 38", "output": "NO" }, { "input": "13\n-3 -36 -46\n-11 -50 37\n42 -11 -15\n9 42 44\n-29 -12 24\n3 9 -40\n-35 13 50\n14 43 18\n-13 8 24\n-48 -15 10\n50 9 -50\n21 0 -50\n0 0 -6", "output": "YES" }, { "input": "14\n43 23 17\n4 17 44\n5 -5 -16\n-43 -7 -6\n47 -48 12\n50 47 -45\n2 14 43\n37 -30 15\n4 -17 -11\n17 9 -45\n-50 -3 -8\n-50 0 0\n-50 0 0\n-16 0 0", "output": "YES" }, { "input": "13\n29 49 -11\n38 -11 -20\n25 1 -40\n-11 28 11\n23 -19 1\n45 -41 -17\n-3 0 -19\n-13 -33 49\n-30 0 28\n34 17 45\n-50 9 -27\n-50 0 0\n-37 0 0", "output": "YES" }, { "input": "12\n3 28 -35\n-32 -44 -17\n9 -25 -6\n-42 -22 20\n-19 15 38\n-21 38 48\n-1 -37 -28\n-10 -13 -50\n-5 21 29\n34 28 50\n50 11 -49\n34 0 0", "output": "YES" }, { "input": "37\n-64 -79 26\n-22 59 93\n-5 39 -12\n77 -9 76\n55 -86 57\n83 100 -97\n-70 94 84\n-14 46 -94\n26 72 35\n14 78 -62\n17 82 92\n-57 11 91\n23 15 92\n-80 -1 1\n12 39 18\n-23 -99 -75\n-34 50 19\n-39 84 -7\n45 -30 -39\n-60 49 37\n45 -16 -72\n33 -51 -56\n-48 28 5\n97 91 88\n45 -82 -11\n-21 -15 -90\n-53 73 -26\n-74 85 -90\n-40 23 38\n100 -13 49\n32 -100 -100\n0 -100 -70\n0 -100 0\n0 -100 0\n0 -100 0\n0 -100 0\n0 -37 0", "output": "YES" }, { "input": "4\n68 3 100\n68 21 -100\n-100 -24 0\n-36 0 0", "output": "YES" }, { "input": "33\n-1 -46 -12\n45 -16 -21\n-11 45 -21\n-60 -42 -93\n-22 -45 93\n37 96 85\n-76 26 83\n-4 9 55\n7 -52 -9\n66 8 -85\n-100 -54 11\n-29 59 74\n-24 12 2\n-56 81 85\n-92 69 -52\n-26 -97 91\n54 59 -51\n58 21 -57\n7 68 56\n-47 -20 -51\n-59 77 -13\n-85 27 91\n79 60 -56\n66 -80 5\n21 -99 42\n-31 -29 98\n66 93 76\n-49 45 61\n100 -100 -100\n100 -100 -100\n66 -75 -100\n0 0 -100\n0 0 -87", "output": "YES" }, { "input": "3\n1 2 3\n3 2 1\n0 0 0", "output": "NO" }, { "input": "2\n5 -23 12\n0 0 0", "output": "NO" }, { "input": "1\n0 0 0", "output": "YES" }, { "input": "1\n1 -2 0", "output": "NO" }, { "input": "2\n-23 77 -86\n23 -77 86", "output": "YES" }, { "input": "26\n86 7 20\n-57 -64 39\n-45 6 -93\n-44 -21 100\n-11 -49 21\n73 -71 -80\n-2 -89 56\n-65 -2 7\n5 14 84\n57 41 13\n-12 69 54\n40 -25 27\n-17 -59 0\n64 -91 -30\n-53 9 42\n-54 -8 14\n-35 82 27\n-48 -59 -80\n88 70 79\n94 57 97\n44 63 25\n84 -90 -40\n-100 100 -100\n-92 100 -100\n0 10 -100\n0 0 -82", "output": "YES" }, { "input": "42\n11 27 92\n-18 -56 -57\n1 71 81\n33 -92 30\n82 83 49\n-87 -61 -1\n-49 45 49\n73 26 15\n-22 22 -77\n29 -93 87\n-68 44 -90\n-4 -84 20\n85 67 -6\n-39 26 77\n-28 -64 20\n65 -97 24\n-72 -39 51\n35 -75 -91\n39 -44 -8\n-25 -27 -57\n91 8 -46\n-98 -94 56\n94 -60 59\n-9 -95 18\n-53 -37 98\n-8 -94 -84\n-52 55 60\n15 -14 37\n65 -43 -25\n94 12 66\n-8 -19 -83\n29 81 -78\n-58 57 33\n24 86 -84\n-53 32 -88\n-14 7 3\n89 97 -53\n-5 -28 -91\n-100 100 -6\n-84 100 0\n0 100 0\n0 70 0", "output": "YES" }, { "input": "3\n96 49 -12\n2 -66 28\n-98 17 -16", "output": "YES" }, { "input": "5\n70 -46 86\n-100 94 24\n-27 63 -63\n57 -100 -47\n0 -11 0", "output": "YES" }, { "input": "18\n-86 -28 70\n-31 -89 42\n31 -48 -55\n95 -17 -43\n24 -95 -85\n-21 -14 31\n68 -18 81\n13 31 60\n-15 28 99\n-42 15 9\n28 -61 -62\n-16 71 29\n-28 75 -48\n-77 -67 36\n-100 83 89\n100 100 -100\n57 34 -100\n0 0 -53", "output": "YES" }, { "input": "44\n52 -54 -29\n-82 -5 -94\n-54 43 43\n91 16 71\n7 80 -91\n3 15 29\n-99 -6 -77\n-3 -77 -64\n73 67 34\n25 -10 -18\n-29 91 63\n-72 86 -16\n-68 85 -81\n-3 36 44\n-74 -14 -80\n34 -96 -97\n-76 -78 -33\n-24 44 -58\n98 12 77\n95 -63 -6\n-51 3 -90\n-92 -10 72\n7 3 -68\n57 -53 71\n29 57 -48\n35 -60 10\n79 -70 -61\n-20 77 55\n-86 -15 -35\n84 -88 -18\n100 -42 77\n-20 46 8\n-41 -43 -65\n38 -98 -23\n-100 65 45\n-7 -91 -63\n46 88 -85\n48 59 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 1", "output": "YES" }, { "input": "18\n-14 -64 -91\n-8 -66 -86\n-23 92 -40\n6 -3 -53\n57 41 78\n-79 42 -22\n-88 -17 45\n4 -45 44\n83 -18 -25\n34 86 -92\n75 -30 12\n44 99 11\n-67 -13 72\n22 83 -56\n-37 71 72\n-9 -100 100\n0 -100 31\n0 -58 0", "output": "YES" }, { "input": "23\n-70 37 78\n42 84 6\n28 -94 -24\n-49 76 95\n-67 18 84\n-53 78 -5\n65 -63 -64\n-66 -64 -69\n81 -93 95\n10 52 -79\n-89 -61 -64\n-64 -47 43\n-81 -35 55\n80 82 73\n-60 -81 -18\n49 -10 -19\n-58 70 12\n-24 -15 -93\n98 -93 -54\n-28 -75 11\n100 100 -63\n100 100 0\n56 34 0", "output": "YES" }, { "input": "3\n0 2 -2\n1 -1 3\n-3 0 0", "output": "NO" } ]
1,694,096,553
2,147,483,647
PyPy 3-64
OK
TESTS
81
154
0
n = int(input()) a = 0 b = 0 c = 0 for _ in range(n): m, n, k = map(int,input().split()) a = a + m b = b + n c = c + k if a == 0 and b == 0 and c == 0: print('YES') else: print('NO')
Title: Young Physicist Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces. Input Specification: The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). Output Specification: Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. Demo Input: ['3\n4 1 7\n-2 4 -1\n1 -5 -3\n', '3\n3 -1 7\n-5 2 -4\n2 -1 -3\n'] Demo Output: ['NO', 'YES'] Note: none
```python n = int(input()) a = 0 b = 0 c = 0 for _ in range(n): m, n, k = map(int,input().split()) a = a + m b = b + n c = c + k if a == 0 and b == 0 and c == 0: print('YES') else: print('NO') ```
3.9615
80
A
Panoramix's Prediction
PROGRAMMING
800
[ "brute force" ]
A. Panoramix's Prediction
2
256
A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not. The next prime number after *x* is the smallest prime number greater than *x*. For example, the next prime number after 2 is 3, and the next prime number after 3 is 5. Note that there is exactly one next prime number after each number. So 5 is not the next prime number for 2. One cold April morning Panoramix predicted that soon Kakofonix will break free from his straitjacket, and this will be a black day for the residents of the Gallic countryside. Panoramix's prophecy tells that if some day Asterix and Obelix beat exactly *x* Roman soldiers, where *x* is a prime number, and next day they beat exactly *y* Roman soldiers, where *y* is the next prime number after *x*, then it's time to wait for Armageddon, for nothing can shut Kakofonix up while he sings his infernal song. Yesterday the Gauls beat *n* Roman soldiers and it turned out that the number *n* was prime! Today their victims were a troop of *m* Romans (*m*<=&gt;<=*n*). Determine whether the Gauls should wait for the black day after today's victory of Asterix and Obelix?
The first and only input line contains two positive integers — *n* and *m* (2<=≤<=*n*<=&lt;<=*m*<=≤<=50). It is guaranteed that *n* is prime. Pretests contain all the cases with restrictions 2<=≤<=*n*<=&lt;<=*m*<=≤<=4.
Print YES, if *m* is the next prime number after *n*, or NO otherwise.
[ "3 5\n", "7 11\n", "7 9\n" ]
[ "YES", "YES", "NO" ]
none
500
[ { "input": "3 5", "output": "YES" }, { "input": "7 11", "output": "YES" }, { "input": "7 9", "output": "NO" }, { "input": "2 3", "output": "YES" }, { "input": "2 4", "output": "NO" }, { "input": "3 4", "output": "NO" }, { "input": "3 5", "output": "YES" }, { "input": "5 7", "output": "YES" }, { "input": "7 11", "output": "YES" }, { "input": "11 13", "output": "YES" }, { "input": "13 17", "output": "YES" }, { "input": "17 19", "output": "YES" }, { "input": "19 23", "output": "YES" }, { "input": "23 29", "output": "YES" }, { "input": "29 31", "output": "YES" }, { "input": "31 37", "output": "YES" }, { "input": "37 41", "output": "YES" }, { "input": "41 43", "output": "YES" }, { "input": "43 47", "output": "YES" }, { "input": "2 5", "output": "NO" }, { "input": "2 7", "output": "NO" }, { "input": "2 6", "output": "NO" }, { "input": "2 11", "output": "NO" }, { "input": "3 6", "output": "NO" }, { "input": "3 7", "output": "NO" }, { "input": "3 9", "output": "NO" }, { "input": "5 6", "output": "NO" }, { "input": "5 9", "output": "NO" }, { "input": "5 11", "output": "NO" }, { "input": "5 13", "output": "NO" }, { "input": "5 15", "output": "NO" }, { "input": "7 8", "output": "NO" }, { "input": "7 13", "output": "NO" }, { "input": "13 15", "output": "NO" }, { "input": "13 17", "output": "YES" }, { "input": "19 21", "output": "NO" }, { "input": "13 20", "output": "NO" }, { "input": "41 49", "output": "NO" }, { "input": "43 49", "output": "NO" }, { "input": "47 50", "output": "NO" }, { "input": "47 49", "output": "NO" }, { "input": "47 48", "output": "NO" }, { "input": "23 25", "output": "NO" }, { "input": "2 50", "output": "NO" }, { "input": "31 33", "output": "NO" } ]
1,624,352,295
2,147,483,647
Python 3
OK
TESTS
45
124
0
n,m = map(int,input().split()) prime = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47] if m in prime: if m == prime[prime.index(n)+1]: print('YES') else : print('NO') else : print('NO')
Title: Panoramix's Prediction Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not. The next prime number after *x* is the smallest prime number greater than *x*. For example, the next prime number after 2 is 3, and the next prime number after 3 is 5. Note that there is exactly one next prime number after each number. So 5 is not the next prime number for 2. One cold April morning Panoramix predicted that soon Kakofonix will break free from his straitjacket, and this will be a black day for the residents of the Gallic countryside. Panoramix's prophecy tells that if some day Asterix and Obelix beat exactly *x* Roman soldiers, where *x* is a prime number, and next day they beat exactly *y* Roman soldiers, where *y* is the next prime number after *x*, then it's time to wait for Armageddon, for nothing can shut Kakofonix up while he sings his infernal song. Yesterday the Gauls beat *n* Roman soldiers and it turned out that the number *n* was prime! Today their victims were a troop of *m* Romans (*m*<=&gt;<=*n*). Determine whether the Gauls should wait for the black day after today's victory of Asterix and Obelix? Input Specification: The first and only input line contains two positive integers — *n* and *m* (2<=≤<=*n*<=&lt;<=*m*<=≤<=50). It is guaranteed that *n* is prime. Pretests contain all the cases with restrictions 2<=≤<=*n*<=&lt;<=*m*<=≤<=4. Output Specification: Print YES, if *m* is the next prime number after *n*, or NO otherwise. Demo Input: ['3 5\n', '7 11\n', '7 9\n'] Demo Output: ['YES', 'YES', 'NO'] Note: none
```python n,m = map(int,input().split()) prime = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47] if m in prime: if m == prime[prime.index(n)+1]: print('YES') else : print('NO') else : print('NO') ```
3.969
4
C
Registration System
PROGRAMMING
1,300
[ "data structures", "hashing", "implementation" ]
C. Registration system
5
64
A new e-mail service "Berlandesk" is going to be opened in Berland in the near future. The site administration wants to launch their project as soon as possible, that's why they ask you to help. You're suggested to implement the prototype of site registration system. The system should work on the following principle. Each time a new user wants to register, he sends to the system a request with his name. If such a name does not exist in the system database, it is inserted into the database, and the user gets the response OK, confirming the successful registration. If the name already exists in the system database, the system makes up a new user name, sends it to the user as a prompt and also inserts the prompt into the database. The new name is formed by the following rule. Numbers, starting with 1, are appended one after another to name (name1, name2, ...), among these numbers the least *i* is found so that name*i* does not yet exist in the database.
The first line contains number *n* (1<=≤<=*n*<=≤<=105). The following *n* lines contain the requests to the system. Each request is a non-empty line, and consists of not more than 32 characters, which are all lowercase Latin letters.
Print *n* lines, which are system responses to the requests: OK in case of successful registration, or a prompt with a new name, if the requested name is already taken.
[ "4\nabacaba\nacaba\nabacaba\nacab\n", "6\nfirst\nfirst\nsecond\nsecond\nthird\nthird\n" ]
[ "OK\nOK\nabacaba1\nOK\n", "OK\nfirst1\nOK\nsecond1\nOK\nthird1\n" ]
none
0
[ { "input": "4\nabacaba\nacaba\nabacaba\nacab", "output": "OK\nOK\nabacaba1\nOK" }, { "input": "6\nfirst\nfirst\nsecond\nsecond\nthird\nthird", "output": "OK\nfirst1\nOK\nsecond1\nOK\nthird1" }, { "input": "1\nn", "output": "OK" }, { "input": "2\nu\nu", "output": "OK\nu1" }, { "input": "3\nb\nb\nb", "output": "OK\nb1\nb2" }, { "input": "2\nc\ncn", "output": "OK\nOK" }, { "input": "3\nvhn\nvhn\nh", "output": "OK\nvhn1\nOK" }, { "input": "4\nd\nhd\nd\nh", "output": "OK\nOK\nd1\nOK" }, { "input": "10\nbhnqaptmp\nbhnqaptmp\nbhnqaptmp\nbhnqaptmp\nbhnqaptmp\nbhnqaptmp\nbhnqaptmp\nbhnqaptmp\nbhnqaptmp\nbhnqaptmp", "output": "OK\nbhnqaptmp1\nbhnqaptmp2\nbhnqaptmp3\nbhnqaptmp4\nbhnqaptmp5\nbhnqaptmp6\nbhnqaptmp7\nbhnqaptmp8\nbhnqaptmp9" }, { "input": "10\nfpqhfouqdldravpjttarh\nfpqhfouqdldravpjttarh\nfpqhfouqdldravpjttarh\nfpqhfouqdldravpjttarh\nfpqhfouqdldravpjttarh\nfpqhfouqdldravpjttarh\njmvlplnrmba\nfpqhfouqdldravpjttarh\njmvlplnrmba\nfpqhfouqdldravpjttarh", "output": "OK\nfpqhfouqdldravpjttarh1\nfpqhfouqdldravpjttarh2\nfpqhfouqdldravpjttarh3\nfpqhfouqdldravpjttarh4\nfpqhfouqdldravpjttarh5\nOK\nfpqhfouqdldravpjttarh6\njmvlplnrmba1\nfpqhfouqdldravpjttarh7" }, { "input": "10\niwexcrupuubwzbooj\niwexcrupuubwzbooj\njzsyjnxttliyfpunxyhsouhunenzxedi\njzsyjnxttliyfpunxyhsouhunenzxedi\njzsyjnxttliyfpunxyhsouhunenzxedi\njzsyjnxttliyfpunxyhsouhunenzxedi\njzsyjnxttliyfpunxyhsouhunenzxedi\niwexcrupuubwzbooj\niwexcrupuubwzbooj\niwexcrupuubwzbooj", "output": "OK\niwexcrupuubwzbooj1\nOK\njzsyjnxttliyfpunxyhsouhunenzxedi1\njzsyjnxttliyfpunxyhsouhunenzxedi2\njzsyjnxttliyfpunxyhsouhunenzxedi3\njzsyjnxttliyfpunxyhsouhunenzxedi4\niwexcrupuubwzbooj2\niwexcrupuubwzbooj3\niwexcrupuubwzbooj4" }, { "input": "10\nzzzzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzzzzz", "output": "OK\nzzzzzzzzzzzzzzzzzzzzzzzzzzz1\nOK\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz1\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz2\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz3\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz4\nzzzzzzzzzzzzzzzzzzzzzzzzzzz2\nzzzzzzzzzzzzzzzzzzzzzzzzzzz3\nzzzzzzzzzzzzzzzzzzzzzzzzzzz4" }, { "input": "20\nzzzzzzzzz\nzzzzzzzzzzzzz\nz\nzzzzzzzzzzzzz\nzzzzzzzzz\nzzzzzzzzz\nzzzzzzzzzzzzz\nzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzz\nzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzz\nzzzzzzzzzzzzz\nz\nzzzzzzzzz\nzzzzzzzzz\nzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzz", "output": "OK\nOK\nOK\nzzzzzzzzzzzzz1\nzzzzzzzzz1\nzzzzzzzzz2\nzzzzzzzzzzzzz2\nzzzzzzzzzzzzz3\nOK\nzzzzzzzzzzzzz4\nzzzzzzzzzzzzz5\nzzzzzzzzzzzzzzzzzzzzzzzz1\nzzzzzzzzzzzzzzzzzzzzzzzz2\nzzzzzzzzzzzzz6\nzzzzzzzzzzzzz7\nz1\nzzzzzzzzz3\nzzzzzzzzz4\nzzzzzzzzzzzzz8\nzzzzzzzzzzzzzzzzzzzzzzzz3" } ]
1,694,559,627
2,147,483,647
Python 3
OK
TESTS
25
1,432
1,228,800
# Asif Islam - asifislam510 num_entries = int(input()) system = {} while num_entries > 0: name = input() if name in system: system[name] += 1 print(name + str(system[name])) else: system[name] = 0 print("OK") num_entries -= 1
Title: Registration System Time Limit: 5 seconds Memory Limit: 64 megabytes Problem Description: A new e-mail service "Berlandesk" is going to be opened in Berland in the near future. The site administration wants to launch their project as soon as possible, that's why they ask you to help. You're suggested to implement the prototype of site registration system. The system should work on the following principle. Each time a new user wants to register, he sends to the system a request with his name. If such a name does not exist in the system database, it is inserted into the database, and the user gets the response OK, confirming the successful registration. If the name already exists in the system database, the system makes up a new user name, sends it to the user as a prompt and also inserts the prompt into the database. The new name is formed by the following rule. Numbers, starting with 1, are appended one after another to name (name1, name2, ...), among these numbers the least *i* is found so that name*i* does not yet exist in the database. Input Specification: The first line contains number *n* (1<=≤<=*n*<=≤<=105). The following *n* lines contain the requests to the system. Each request is a non-empty line, and consists of not more than 32 characters, which are all lowercase Latin letters. Output Specification: Print *n* lines, which are system responses to the requests: OK in case of successful registration, or a prompt with a new name, if the requested name is already taken. Demo Input: ['4\nabacaba\nacaba\nabacaba\nacab\n', '6\nfirst\nfirst\nsecond\nsecond\nthird\nthird\n'] Demo Output: ['OK\nOK\nabacaba1\nOK\n', 'OK\nfirst1\nOK\nsecond1\nOK\nthird1\n'] Note: none
```python # Asif Islam - asifislam510 num_entries = int(input()) system = {} while num_entries > 0: name = input() if name in system: system[name] += 1 print(name + str(system[name])) else: system[name] = 0 print("OK") num_entries -= 1 ```
3.847645
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,627,915,213
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
154
6,963,200
n = int(input()) ls = input() l = [] for i in range(len(ls)): if(ls[i] != " "): l.append(int(ls[i])) impar_cont = 0 par_cont = 0 #Pega indice do elemento impar_i = 0 par_i = 0 for i in iter(range(n)): if l[i] % 2 == 0: par_cont += 1 par_i = i + 1 else: impar_cont += 1 impar_i = i + 1 if par_cont != 0 and impar_cont != 0 and (par_cont > 1 or impar_cont > 1): if par_cont > 1: print (impar_i) else: print (par_i) break
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()) ls = input() l = [] for i in range(len(ls)): if(ls[i] != " "): l.append(int(ls[i])) impar_cont = 0 par_cont = 0 #Pega indice do elemento impar_i = 0 par_i = 0 for i in iter(range(n)): if l[i] % 2 == 0: par_cont += 1 par_i = i + 1 else: impar_cont += 1 impar_i = i + 1 if par_cont != 0 and impar_cont != 0 and (par_cont > 1 or impar_cont > 1): if par_cont > 1: print (impar_i) else: print (par_i) break ```
0
285
B
Find Marble
PROGRAMMING
1,200
[ "implementation" ]
null
null
Petya and Vasya are playing a game. Petya's got *n* non-transparent glasses, standing in a row. The glasses' positions are indexed with integers from 1 to *n* from left to right. Note that the positions are indexed but the glasses are not. First Petya puts a marble under the glass in position *s*. Then he performs some (possibly zero) shuffling operations. One shuffling operation means moving the glass from the first position to position *p*1, the glass from the second position to position *p*2 and so on. That is, a glass goes from position *i* to position *p**i*. Consider all glasses are moving simultaneously during one shuffling operation. When the glasses are shuffled, the marble doesn't travel from one glass to another: it moves together with the glass it was initially been put in. After all shuffling operations Petya shows Vasya that the ball has moved to position *t*. Vasya's task is to say what minimum number of shuffling operations Petya has performed or determine that Petya has made a mistake and the marble could not have got from position *s* to position *t*.
The first line contains three integers: *n*,<=*s*,<=*t* (1<=≤<=*n*<=≤<=105; 1<=≤<=*s*,<=*t*<=≤<=*n*) — the number of glasses, the ball's initial and final position. The second line contains *n* space-separated integers: *p*1,<=*p*2,<=...,<=*p**n* (1<=≤<=*p**i*<=≤<=*n*) — the shuffling operation parameters. It is guaranteed that all *p**i*'s are distinct. Note that *s* can equal *t*.
If the marble can move from position *s* to position *t*, then print on a single line a non-negative integer — the minimum number of shuffling operations, needed to get the marble to position *t*. If it is impossible, print number -1.
[ "4 2 1\n2 3 4 1\n", "4 3 3\n4 1 3 2\n", "4 3 4\n1 2 3 4\n", "3 1 3\n2 1 3\n" ]
[ "3\n", "0\n", "-1\n", "-1\n" ]
none
1,000
[ { "input": "4 2 1\n2 3 4 1", "output": "3" }, { "input": "4 3 3\n4 1 3 2", "output": "0" }, { "input": "4 3 4\n1 2 3 4", "output": "-1" }, { "input": "3 1 3\n2 1 3", "output": "-1" }, { "input": "1 1 1\n1", "output": "0" }, { "input": "10 6 7\n10 7 8 1 5 6 2 9 4 3", "output": "-1" }, { "input": "10 3 6\n5 6 7 3 8 4 2 1 10 9", "output": "3" }, { "input": "10 10 4\n4 2 6 9 5 3 8 1 10 7", "output": "4" }, { "input": "100 90 57\n19 55 91 50 31 23 60 84 38 1 22 51 27 76 28 98 11 44 61 63 15 93 52 3 66 16 53 36 18 62 35 85 78 37 73 64 87 74 46 26 82 69 49 33 83 89 56 67 71 25 39 94 96 17 21 6 47 68 34 42 57 81 13 10 54 2 48 80 20 77 4 5 59 30 90 95 45 75 8 88 24 41 40 14 97 32 7 9 65 70 100 99 72 58 92 29 79 12 86 43", "output": "-1" }, { "input": "100 11 20\n80 25 49 55 22 98 35 59 88 14 91 20 68 66 53 50 77 45 82 63 96 93 85 46 37 74 84 9 7 95 41 86 23 36 33 27 81 39 18 13 12 92 24 71 3 48 83 61 31 87 28 79 75 38 11 21 29 69 44 100 72 62 32 43 30 16 47 56 89 60 42 17 26 70 94 99 4 6 2 73 8 52 65 1 15 90 67 51 78 10 5 76 57 54 34 58 19 64 40 97", "output": "26" }, { "input": "100 84 83\n30 67 53 89 94 54 92 17 26 57 15 5 74 85 10 61 18 70 91 75 14 11 93 41 25 78 88 81 20 51 35 4 62 1 97 39 68 52 47 77 64 3 2 72 60 80 8 83 65 98 21 22 45 7 58 31 43 38 90 99 49 87 55 36 29 6 37 23 66 76 59 79 40 86 63 44 82 32 48 16 50 100 28 96 46 12 27 13 24 9 19 84 73 69 71 42 56 33 34 95", "output": "71" }, { "input": "100 6 93\n74 62 67 81 40 85 35 42 59 72 80 28 79 41 16 19 33 63 13 10 69 76 70 93 49 84 89 94 8 37 11 90 26 52 47 7 36 95 86 75 56 15 61 99 88 12 83 21 20 3 100 17 32 82 6 5 43 25 66 68 73 78 18 77 92 27 23 2 4 39 60 48 22 24 14 97 29 34 54 64 71 57 87 38 9 50 30 53 51 45 44 31 58 91 98 65 55 1 46 96", "output": "-1" }, { "input": "100 27 56\n58 18 50 41 33 37 14 87 77 73 61 53 15 8 70 68 45 96 54 78 39 67 51 60 80 12 93 99 20 92 17 79 4 13 62 91 69 29 49 36 98 34 90 35 84 64 38 83 28 89 97 94 9 16 26 48 10 57 23 75 27 88 44 21 72 76 30 43 32 2 71 24 100 1 31 81 42 40 47 55 86 85 66 5 52 22 95 74 11 19 7 82 6 25 56 63 65 59 46 3", "output": "20" }, { "input": "87 42 49\n45 55 24 44 56 72 74 23 4 7 37 67 22 6 58 76 40 36 3 20 26 87 64 75 49 70 62 42 31 1 80 33 25 59 78 27 32 2 41 61 66 28 19 85 15 69 52 77 50 14 16 34 18 43 73 83 11 39 29 9 35 13 81 54 79 21 60 46 71 57 12 17 5 47 38 30 10 84 53 63 68 8 51 65 48 86 82", "output": "-1" }, { "input": "2 1 2\n1 2", "output": "-1" }, { "input": "2 1 2\n2 1", "output": "1" }, { "input": "2 2 2\n1 2", "output": "0" }, { "input": "2 2 2\n2 1", "output": "0" }, { "input": "2 1 1\n2 1", "output": "0" } ]
1,688,452,065
2,147,483,647
PyPy 3-64
OK
TESTS
33
154
13,516,800
n,s,t=map(int,input().split()) p=[0]+list(map(int,input().split())) ans=0 while ans<=n and s!=t: s=p[s] ans+=1 print([-1,ans][ans<=n])
Title: Find Marble Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya and Vasya are playing a game. Petya's got *n* non-transparent glasses, standing in a row. The glasses' positions are indexed with integers from 1 to *n* from left to right. Note that the positions are indexed but the glasses are not. First Petya puts a marble under the glass in position *s*. Then he performs some (possibly zero) shuffling operations. One shuffling operation means moving the glass from the first position to position *p*1, the glass from the second position to position *p*2 and so on. That is, a glass goes from position *i* to position *p**i*. Consider all glasses are moving simultaneously during one shuffling operation. When the glasses are shuffled, the marble doesn't travel from one glass to another: it moves together with the glass it was initially been put in. After all shuffling operations Petya shows Vasya that the ball has moved to position *t*. Vasya's task is to say what minimum number of shuffling operations Petya has performed or determine that Petya has made a mistake and the marble could not have got from position *s* to position *t*. Input Specification: The first line contains three integers: *n*,<=*s*,<=*t* (1<=≤<=*n*<=≤<=105; 1<=≤<=*s*,<=*t*<=≤<=*n*) — the number of glasses, the ball's initial and final position. The second line contains *n* space-separated integers: *p*1,<=*p*2,<=...,<=*p**n* (1<=≤<=*p**i*<=≤<=*n*) — the shuffling operation parameters. It is guaranteed that all *p**i*'s are distinct. Note that *s* can equal *t*. Output Specification: If the marble can move from position *s* to position *t*, then print on a single line a non-negative integer — the minimum number of shuffling operations, needed to get the marble to position *t*. If it is impossible, print number -1. Demo Input: ['4 2 1\n2 3 4 1\n', '4 3 3\n4 1 3 2\n', '4 3 4\n1 2 3 4\n', '3 1 3\n2 1 3\n'] Demo Output: ['3\n', '0\n', '-1\n', '-1\n'] Note: none
```python n,s,t=map(int,input().split()) p=[0]+list(map(int,input().split())) ans=0 while ans<=n and s!=t: s=p[s] ans+=1 print([-1,ans][ans<=n]) ```
3
1,005
A
Tanya and Stairways
PROGRAMMING
800
[ "implementation" ]
null
null
Little girl Tanya climbs the stairs inside a multi-storey building. Every time Tanya climbs a stairway, she starts counting steps from $1$ to the number of steps in this stairway. She speaks every number aloud. For example, if she climbs two stairways, the first of which contains $3$ steps, and the second contains $4$ steps, she will pronounce the numbers $1, 2, 3, 1, 2, 3, 4$. You are given all the numbers pronounced by Tanya. How many stairways did she climb? Also, output the number of steps in each stairway. The given sequence will be a valid sequence that Tanya could have pronounced when climbing one or more stairways.
The first line contains $n$ ($1 \le n \le 1000$) — the total number of numbers pronounced by Tanya. The second line contains integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 1000$) — all the numbers Tanya pronounced while climbing the stairs, in order from the first to the last pronounced number. Passing a stairway with $x$ steps, she will pronounce the numbers $1, 2, \dots, x$ in that order. The given sequence will be a valid sequence that Tanya could have pronounced when climbing one or more stairways.
In the first line, output $t$ — the number of stairways that Tanya climbed. In the second line, output $t$ numbers — the number of steps in each stairway she climbed. Write the numbers in the correct order of passage of the stairways.
[ "7\n1 2 3 1 2 3 4\n", "4\n1 1 1 1\n", "5\n1 2 3 4 5\n", "5\n1 2 1 2 1\n" ]
[ "2\n3 4 ", "4\n1 1 1 1 ", "1\n5 ", "3\n2 2 1 " ]
none
0
[ { "input": "7\n1 2 3 1 2 3 4", "output": "2\n3 4 " }, { "input": "4\n1 1 1 1", "output": "4\n1 1 1 1 " }, { "input": "5\n1 2 3 4 5", "output": "1\n5 " }, { "input": "5\n1 2 1 2 1", "output": "3\n2 2 1 " }, { "input": "1\n1", "output": "1\n1 " }, { "input": "48\n1 2 3 4 1 2 3 1 1 2 3 1 2 3 4 1 1 2 3 4 1 2 3 4 1 2 3 4 1 1 2 1 2 1 2 1 1 2 1 2 1 2 3 1 2 1 2 1", "output": "20\n4 3 1 3 4 1 4 4 4 1 2 2 2 1 2 2 3 2 2 1 " }, { "input": "2\n1 2", "output": "1\n2 " }, { "input": "3\n1 1 2", "output": "2\n1 2 " }, { "input": "4\n1 1 2 3", "output": "2\n1 3 " }, { "input": "8\n1 2 3 1 2 3 4 5", "output": "2\n3 5 " }, { "input": "5\n1 1 1 2 3", "output": "3\n1 1 3 " } ]
1,652,631,606
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
46
28,364,800
n = int(input()) arr = list(map(int,input().split())) s = [] count = 0 for i in range(n) : if arr[i]==1 : count+=1 if i>0 : s.append(arr[i-1]) print(count) print(" ".join(map(str,s)))
Title: Tanya and Stairways Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little girl Tanya climbs the stairs inside a multi-storey building. Every time Tanya climbs a stairway, she starts counting steps from $1$ to the number of steps in this stairway. She speaks every number aloud. For example, if she climbs two stairways, the first of which contains $3$ steps, and the second contains $4$ steps, she will pronounce the numbers $1, 2, 3, 1, 2, 3, 4$. You are given all the numbers pronounced by Tanya. How many stairways did she climb? Also, output the number of steps in each stairway. The given sequence will be a valid sequence that Tanya could have pronounced when climbing one or more stairways. Input Specification: The first line contains $n$ ($1 \le n \le 1000$) — the total number of numbers pronounced by Tanya. The second line contains integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 1000$) — all the numbers Tanya pronounced while climbing the stairs, in order from the first to the last pronounced number. Passing a stairway with $x$ steps, she will pronounce the numbers $1, 2, \dots, x$ in that order. The given sequence will be a valid sequence that Tanya could have pronounced when climbing one or more stairways. Output Specification: In the first line, output $t$ — the number of stairways that Tanya climbed. In the second line, output $t$ numbers — the number of steps in each stairway she climbed. Write the numbers in the correct order of passage of the stairways. Demo Input: ['7\n1 2 3 1 2 3 4\n', '4\n1 1 1 1\n', '5\n1 2 3 4 5\n', '5\n1 2 1 2 1\n'] Demo Output: ['2\n3 4 ', '4\n1 1 1 1 ', '1\n5 ', '3\n2 2 1 '] Note: none
```python n = int(input()) arr = list(map(int,input().split())) s = [] count = 0 for i in range(n) : if arr[i]==1 : count+=1 if i>0 : s.append(arr[i-1]) print(count) print(" ".join(map(str,s))) ```
0
76
B
Mice
PROGRAMMING
2,100
[ "greedy", "two pointers" ]
B. Mice
0
256
Modern researches has shown that a flock of hungry mice searching for a piece of cheese acts as follows: if there are several pieces of cheese then each mouse chooses the closest one. After that all mice start moving towards the chosen piece of cheese. When a mouse or several mice achieve the destination point and there is still a piece of cheese in it, they eat it and become well-fed. Each mice that reaches this point after that remains hungry. Moving speeds of all mice are equal. If there are several ways to choose closest pieces then mice will choose it in a way that would minimize the number of hungry mice. To check this theory scientists decided to conduct an experiment. They located *N* mice and *M* pieces of cheese on a cartesian plane where all mice are located on the line *y*<==<=*Y*0 and all pieces of cheese — on another line *y*<==<=*Y*1. To check the results of the experiment the scientists need a program which simulates the behavior of a flock of hungry mice. Write a program that computes the minimal number of mice which will remain hungry, i.e. without cheese.
The first line of the input contains four integer numbers *N* (1<=≤<=*N*<=≤<=105), *M* (0<=≤<=*M*<=≤<=105), *Y*0 (0<=≤<=*Y*0<=≤<=107), *Y*1 (0<=≤<=*Y*1<=≤<=107, *Y*0<=≠<=*Y*1). The second line contains a strictly increasing sequence of *N* numbers — *x* coordinates of mice. Third line contains a strictly increasing sequence of *M* numbers — *x* coordinates of cheese. All coordinates are integers and do not exceed 107 by absolute value.
The only line of output should contain one number — the minimal number of mice which will remain without cheese.
[ "3 2 0 2\n0 1 3\n2 5\n" ]
[ "1\n" ]
All the three mice will choose the first piece of cheese. Second and third mice will eat this piece. The first one will remain hungry, because it was running towards the same piece, but it was late. The second piece of cheese will remain uneaten.
0
[ { "input": "3 2 0 2\n0 1 3\n2 5", "output": "1" }, { "input": "7 11 10 20\n6 18 32 63 66 68 87\n6 8 15 23 25 41 53 59 60 75 90", "output": "1" }, { "input": "13 17 14 1\n6 9 10 12 17 25 91 100 118 136 145 163 172\n0 1 2 3 4 10 12 13 16 17 19 22 26 27 28 109 154", "output": "4" }, { "input": "19 23 13 11\n3 6 7 15 21 22 23 33 35 37 40 44 79 86 100 114 121 135 142\n2 3 5 6 7 14 15 17 18 19 20 22 25 27 28 34 36 38 39 41 42 93 128", "output": "4" }, { "input": "20 18 1 2\n-9999944 -9999861 -9999850 -9999763 -9999656 -9999517 -9999375 -9999275 -9999203 -9999080 -9998988 -9998887 -9998714 -9998534 -9998475 -9998352 -9998164 -9998016 -9998002 -9997882\n-9999976 -9999912 -9999788 -9999738 -9999574 -9999460 -9999290 -9999260 -9999146 -9999014 -9998962 -9998812 -9998616 -9998452 -9998252 -9998076 -9997928 -9997836", "output": "2" } ]
1,677,996,135
2,147,483,647
PyPy 3
COMPILATION_ERROR
TESTS
0
0
0
#include <bits/stdc++.h> using namespace std; int n, m, x, y, a[100001], b[100001]; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n >> m >> x >> y; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= m; i++) cin >> b[i]; //The number of mice which can be fed int start = 0, wellfed = 0, j = 1; for (int i = 1; i <= n; i++){ while (j < m && abs(a[i] - b[j]) > abs(a[i] - b[j + 1])) j++; if (start < j || (i > 0 && abs(a[i] - b[j]) == abs(a[i - 1] - b[j]))) { wellfed++; start = j; } if (j < m && abs(a[i] - b[j]) == abs(a[i] - b[j + 1])) { wellfed++; start = j + 1; } else start = j; } cout << n - wellfed << endl; }
Title: Mice Time Limit: 0 seconds Memory Limit: 256 megabytes Problem Description: Modern researches has shown that a flock of hungry mice searching for a piece of cheese acts as follows: if there are several pieces of cheese then each mouse chooses the closest one. After that all mice start moving towards the chosen piece of cheese. When a mouse or several mice achieve the destination point and there is still a piece of cheese in it, they eat it and become well-fed. Each mice that reaches this point after that remains hungry. Moving speeds of all mice are equal. If there are several ways to choose closest pieces then mice will choose it in a way that would minimize the number of hungry mice. To check this theory scientists decided to conduct an experiment. They located *N* mice and *M* pieces of cheese on a cartesian plane where all mice are located on the line *y*<==<=*Y*0 and all pieces of cheese — on another line *y*<==<=*Y*1. To check the results of the experiment the scientists need a program which simulates the behavior of a flock of hungry mice. Write a program that computes the minimal number of mice which will remain hungry, i.e. without cheese. Input Specification: The first line of the input contains four integer numbers *N* (1<=≤<=*N*<=≤<=105), *M* (0<=≤<=*M*<=≤<=105), *Y*0 (0<=≤<=*Y*0<=≤<=107), *Y*1 (0<=≤<=*Y*1<=≤<=107, *Y*0<=≠<=*Y*1). The second line contains a strictly increasing sequence of *N* numbers — *x* coordinates of mice. Third line contains a strictly increasing sequence of *M* numbers — *x* coordinates of cheese. All coordinates are integers and do not exceed 107 by absolute value. Output Specification: The only line of output should contain one number — the minimal number of mice which will remain without cheese. Demo Input: ['3 2 0 2\n0 1 3\n2 5\n'] Demo Output: ['1\n'] Note: All the three mice will choose the first piece of cheese. Second and third mice will eat this piece. The first one will remain hungry, because it was running towards the same piece, but it was late. The second piece of cheese will remain uneaten.
```python #include <bits/stdc++.h> using namespace std; int n, m, x, y, a[100001], b[100001]; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n >> m >> x >> y; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= m; i++) cin >> b[i]; //The number of mice which can be fed int start = 0, wellfed = 0, j = 1; for (int i = 1; i <= n; i++){ while (j < m && abs(a[i] - b[j]) > abs(a[i] - b[j + 1])) j++; if (start < j || (i > 0 && abs(a[i] - b[j]) == abs(a[i - 1] - b[j]))) { wellfed++; start = j; } if (j < m && abs(a[i] - b[j]) == abs(a[i] - b[j + 1])) { wellfed++; start = j + 1; } else start = j; } cout << n - wellfed << endl; } ```
-1
443
A
Anton and Letters
PROGRAMMING
800
[ "constructive algorithms", "implementation" ]
null
null
Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line. Unfortunately, from time to time Anton would forget writing some letter and write it again. He asks you to count the total number of distinct letters in his set.
The first and the single line contains the set of letters. The length of the line doesn't exceed 1000. It is guaranteed that the line starts from an opening curved bracket and ends with a closing curved bracket. Between them, small English letters are listed, separated by a comma. Each comma is followed by a space.
Print a single number — the number of distinct letters in Anton's set.
[ "{a, b, c}\n", "{b, a, b, a}\n", "{}\n" ]
[ "3\n", "2\n", "0\n" ]
none
500
[ { "input": "{a, b, c}", "output": "3" }, { "input": "{b, a, b, a}", "output": "2" }, { "input": "{}", "output": "0" }, { "input": "{a, a, c, b, b, b, c, c, c, c}", "output": "3" }, { "input": "{a, c, b, b}", "output": "3" }, { "input": "{a, b}", "output": "2" }, { "input": "{a}", "output": "1" }, { "input": "{b, a, b, a, b, c, c, b, c, b}", "output": "3" }, { "input": "{e, g, c, e}", "output": "3" }, { "input": "{a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a}", "output": "1" }, { "input": "{a, a, b}", "output": "2" }, { "input": "{a, b, b, b, a, b, a, a, a, a, a, a, b, a, b, a, a, a, a, a, b, a, b, a}", "output": "2" }, { "input": "{j, u, a, c, f, w, e, w, x, t, h, p, v, n, i, l, x, n, i, b, u, c, a, a}", "output": "16" }, { "input": "{x, i, w, c, p, e, h, z, k, i}", "output": "9" }, { "input": "{t, k, o, x, r, d, q, j, k, e, z, w, y, r, z, s, s, e, s, b, k, i}", "output": "15" }, { "input": "{y}", "output": "1" }, { "input": "{x}", "output": "1" }, { "input": "{b, z, a, z}", "output": "3" }, { "input": "{z}", "output": "1" }, { "input": "{a, z}", "output": "2" }, { "input": "{a, b, z}", "output": "3" }, { "input": "{s, q, z, r, t, a, b, h, j, i, o, z, r, q}", "output": "11" } ]
1,683,115,803
2,147,483,647
Python 3
OK
TESTS
27
61
409,600
import re X = str(input().split()) Y = re.sub(r'[^A-Za-z]+', '', X) print(len(set(Y)))
Title: Anton and Letters Time Limit: None seconds Memory Limit: None megabytes Problem Description: Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line. Unfortunately, from time to time Anton would forget writing some letter and write it again. He asks you to count the total number of distinct letters in his set. Input Specification: The first and the single line contains the set of letters. The length of the line doesn't exceed 1000. It is guaranteed that the line starts from an opening curved bracket and ends with a closing curved bracket. Between them, small English letters are listed, separated by a comma. Each comma is followed by a space. Output Specification: Print a single number — the number of distinct letters in Anton's set. Demo Input: ['{a, b, c}\n', '{b, a, b, a}\n', '{}\n'] Demo Output: ['3\n', '2\n', '0\n'] Note: none
```python import re X = str(input().split()) Y = re.sub(r'[^A-Za-z]+', '', X) print(len(set(Y))) ```
3
174
A
Problem About Equation
PROGRAMMING
1,100
[ "math" ]
null
null
A group of *n* merry programmers celebrate Robert Floyd's birthday. Polucarpus has got an honourable task of pouring Ber-Cola to everybody. Pouring the same amount of Ber-Cola to everybody is really important. In other words, the drink's volume in each of the *n* mugs must be the same. Polycarpus has already began the process and he partially emptied the Ber-Cola bottle. Now the first mug has *a*1 milliliters of the drink, the second one has *a*2 milliliters and so on. The bottle has *b* milliliters left and Polycarpus plans to pour them into the mugs so that the main equation was fulfilled. Write a program that would determine what volume of the drink Polycarpus needs to add into each mug to ensure that the following two conditions were fulfilled simultaneously: - there were *b* milliliters poured in total. That is, the bottle need to be emptied; - after the process is over, the volumes of the drink in the mugs should be equal.
The first line contains a pair of integers *n*, *b* (2<=≤<=*n*<=≤<=100,<=1<=≤<=*b*<=≤<=100), where *n* is the total number of friends in the group and *b* is the current volume of drink in the bottle. The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=100), where *a**i* is the current volume of drink in the *i*-th mug.
Print a single number "-1" (without the quotes), if there is no solution. Otherwise, print *n* float numbers *c*1,<=*c*2,<=...,<=*c**n*, where *c**i* is the volume of the drink to add in the *i*-th mug. Print the numbers with no less than 6 digits after the decimal point, print each *c**i* on a single line. Polycarpus proved that if a solution exists then it is unique. Russian locale is installed by default on the testing computer. Make sure that your solution use the point to separate the integer part of a real number from the decimal, not a comma.
[ "5 50\n1 2 3 4 5\n", "2 2\n1 100\n" ]
[ "12.000000\n11.000000\n10.000000\n9.000000\n8.000000\n", "-1\n" ]
none
500
[ { "input": "5 50\n1 2 3 4 5", "output": "12.000000\n11.000000\n10.000000\n9.000000\n8.000000" }, { "input": "2 2\n1 100", "output": "-1" }, { "input": "2 2\n1 1", "output": "1.000000\n1.000000" }, { "input": "3 2\n1 2 1", "output": "1.000000\n0.000000\n1.000000" }, { "input": "3 5\n1 2 1", "output": "2.000000\n1.000000\n2.000000" }, { "input": "10 95\n0 0 0 0 0 1 1 1 1 1", "output": "10.000000\n10.000000\n10.000000\n10.000000\n10.000000\n9.000000\n9.000000\n9.000000\n9.000000\n9.000000" }, { "input": "3 5\n1 2 3", "output": "2.666667\n1.666667\n0.666667" }, { "input": "3 5\n1 3 2", "output": "2.666667\n0.666667\n1.666667" }, { "input": "3 5\n2 1 3", "output": "1.666667\n2.666667\n0.666667" }, { "input": "3 5\n2 3 1", "output": "1.666667\n0.666667\n2.666667" }, { "input": "3 5\n3 1 2", "output": "0.666667\n2.666667\n1.666667" }, { "input": "3 5\n3 2 1", "output": "0.666667\n1.666667\n2.666667" }, { "input": "2 1\n1 1", "output": "0.500000\n0.500000" }, { "input": "2 1\n2 2", "output": "0.500000\n0.500000" }, { "input": "3 2\n2 1 2", "output": "0.333333\n1.333333\n0.333333" }, { "input": "3 3\n2 2 1", "output": "0.666667\n0.666667\n1.666667" }, { "input": "3 3\n3 1 2", "output": "0.000000\n2.000000\n1.000000" }, { "input": "100 100\n37 97 75 52 33 29 51 22 33 37 45 96 96 60 82 58 86 71 28 73 38 50 6 6 90 17 26 76 13 41 100 47 17 93 4 1 56 16 41 74 25 17 69 61 39 37 96 73 49 93 52 14 62 24 91 30 9 97 52 100 6 16 85 8 12 26 10 3 94 63 80 27 29 78 9 48 79 64 60 18 98 75 81 35 24 81 2 100 23 70 21 60 98 38 29 29 58 37 49 72", "output": "-1" }, { "input": "100 100\n1 3 7 7 9 5 9 3 7 8 10 1 3 10 10 6 1 3 10 4 3 9 4 9 5 4 9 2 8 7 4 3 3 3 5 10 8 9 10 1 9 2 4 8 3 10 9 2 3 9 8 2 4 4 4 7 1 1 7 3 7 8 9 5 1 2 6 7 1 10 9 10 5 10 1 10 5 2 4 3 10 1 6 5 6 7 8 9 3 8 6 10 8 7 2 3 8 6 3 6", "output": "-1" }, { "input": "100 61\n81 80 83 72 87 76 91 92 77 93 77 94 76 73 71 88 88 76 87 73 89 73 85 81 79 90 76 73 82 93 79 93 71 75 72 71 78 85 92 89 88 93 74 87 71 94 74 87 85 89 90 93 86 94 92 87 90 91 75 73 90 84 92 94 92 79 74 85 74 74 89 76 84 84 84 83 86 84 82 71 76 74 83 81 89 73 73 74 71 77 90 94 73 94 73 75 93 89 84 92", "output": "-1" }, { "input": "100 100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100", "output": "1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1..." }, { "input": "100 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": "1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1..." }, { "input": "100 100\n99 100 99 100 100 100 99 99 99 100 100 100 99 100 99 100 100 100 100 100 99 99 99 99 100 99 100 99 100 99 99 100 100 100 100 100 99 99 99 100 99 99 100 99 100 99 100 99 99 99 99 100 100 99 99 99 100 100 99 100 100 100 99 99 100 100 100 100 100 100 99 99 99 99 99 100 99 99 100 99 100 100 100 99 100 99 99 100 99 100 100 100 99 100 99 100 100 100 100 99", "output": "1.530000\n0.530000\n1.530000\n0.530000\n0.530000\n0.530000\n1.530000\n1.530000\n1.530000\n0.530000\n0.530000\n0.530000\n1.530000\n0.530000\n1.530000\n0.530000\n0.530000\n0.530000\n0.530000\n0.530000\n1.530000\n1.530000\n1.530000\n1.530000\n0.530000\n1.530000\n0.530000\n1.530000\n0.530000\n1.530000\n1.530000\n0.530000\n0.530000\n0.530000\n0.530000\n0.530000\n1.530000\n1.530000\n1.530000\n0.530000\n1.530000\n1.530000\n0.530000\n1.530000\n0.530000\n1.530000\n0.530000\n1.530000\n1.530000\n1.530000\n1.530000\n0..." }, { "input": "100 100\n100 100 100 100 100 100 100 100 99 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99 100 100 100 100 100 100 100 100 100 99 100 100 100 100 100 100 99 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99 100 100 100", "output": "0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n1.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n1.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0..." }, { "input": "100 100\n99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 100 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 100 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99", "output": "1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n0.020000\n1.020000\n1..." }, { "input": "10 100\n52 52 51 52 52 52 51 51 52 52", "output": "9.700000\n9.700000\n10.700000\n9.700000\n9.700000\n9.700000\n10.700000\n10.700000\n9.700000\n9.700000" }, { "input": "10 100\n13 13 13 13 12 13 12 13 12 12", "output": "9.600000\n9.600000\n9.600000\n9.600000\n10.600000\n9.600000\n10.600000\n9.600000\n10.600000\n10.600000" }, { "input": "10 100\n50 51 47 51 48 46 49 51 46 51", "output": "9.000000\n8.000000\n12.000000\n8.000000\n11.000000\n13.000000\n10.000000\n8.000000\n13.000000\n8.000000" }, { "input": "10 100\n13 13 9 12 12 11 13 8 10 13", "output": "8.400000\n8.400000\n12.400000\n9.400000\n9.400000\n10.400000\n8.400000\n13.400000\n11.400000\n8.400000" }, { "input": "93 91\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100", "output": "0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0..." }, { "input": "93 97\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", "output": "1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1..." }, { "input": "91 99\n99 100 100 100 99 100 100 100 99 100 99 99 100 99 100 100 100 99 99 100 99 100 100 100 100 100 99 99 100 99 100 99 99 100 100 100 100 99 99 100 100 100 99 100 100 99 100 100 99 100 99 99 99 100 99 99 99 100 99 100 99 100 99 100 99 99 100 100 100 100 99 100 99 100 99 99 100 100 99 100 100 100 100 99 99 100 100 99 99 100 99", "output": "1.648352\n0.648352\n0.648352\n0.648352\n1.648352\n0.648352\n0.648352\n0.648352\n1.648352\n0.648352\n1.648352\n1.648352\n0.648352\n1.648352\n0.648352\n0.648352\n0.648352\n1.648352\n1.648352\n0.648352\n1.648352\n0.648352\n0.648352\n0.648352\n0.648352\n0.648352\n1.648352\n1.648352\n0.648352\n1.648352\n0.648352\n1.648352\n1.648352\n0.648352\n0.648352\n0.648352\n0.648352\n1.648352\n1.648352\n0.648352\n0.648352\n0.648352\n1.648352\n0.648352\n0.648352\n1.648352\n0.648352\n0.648352\n1.648352\n0.648352\n1.648352\n1..." }, { "input": "99 98\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100", "output": "0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n1.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0..." }, { "input": "98 99\n99 99 99 99 99 99 99 99 99 99 99 99 99 99 100 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 100 99 99 99 99 99 99 100 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 100 99 99 99 99 99", "output": "1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n0.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n0.051020\n1.051020\n1..." }, { "input": "13 97\n52 52 51 51 52 52 51 52 51 51 52 52 52", "output": "7.076923\n7.076923\n8.076923\n8.076923\n7.076923\n7.076923\n8.076923\n7.076923\n8.076923\n8.076923\n7.076923\n7.076923\n7.076923" }, { "input": "17 99\n13 13 12 13 11 12 12 12 13 13 11 13 13 13 13 12 13", "output": "5.294118\n5.294118\n6.294118\n5.294118\n7.294118\n6.294118\n6.294118\n6.294118\n5.294118\n5.294118\n7.294118\n5.294118\n5.294118\n5.294118\n5.294118\n6.294118\n5.294118" }, { "input": "9 91\n52 51 50 52 52 51 50 48 51", "output": "8.888889\n9.888889\n10.888889\n8.888889\n8.888889\n9.888889\n10.888889\n12.888889\n9.888889" }, { "input": "17 91\n13 13 13 13 12 12 13 13 12 13 12 13 10 12 13 13 12", "output": "4.823529\n4.823529\n4.823529\n4.823529\n5.823529\n5.823529\n4.823529\n4.823529\n5.823529\n4.823529\n5.823529\n4.823529\n7.823529\n5.823529\n4.823529\n4.823529\n5.823529" }, { "input": "2 3\n1 1", "output": "1.500000\n1.500000" }, { "input": "2 90\n0 89", "output": "89.500000\n0.500000" }, { "input": "4 17\n3 4 8 1", "output": "5.250000\n4.250000\n0.250000\n7.250000" }, { "input": "2 9\n5 5", "output": "4.500000\n4.500000" }, { "input": "7 28\n1 3 9 10 9 6 10", "output": "9.857143\n7.857143\n1.857143\n0.857143\n1.857143\n4.857143\n0.857143" }, { "input": "5 11\n1 2 3 4 5", "output": "4.200000\n3.200000\n2.200000\n1.200000\n0.200000" }, { "input": "2 1\n1 1", "output": "0.500000\n0.500000" }, { "input": "5 3\n1 1 1 1 1", "output": "0.600000\n0.600000\n0.600000\n0.600000\n0.600000" }, { "input": "3 1\n100 100 100", "output": "0.333333\n0.333333\n0.333333" }, { "input": "5 50\n2 2 3 2 2", "output": "10.200000\n10.200000\n9.200000\n10.200000\n10.200000" }, { "input": "3 3\n2 2 3", "output": "1.333333\n1.333333\n0.333333" }, { "input": "2 52\n2 100", "output": "-1" }, { "input": "3 2\n2 2 3", "output": "1.000000\n1.000000\n0.000000" }, { "input": "5 1\n1 1 1 1 1", "output": "0.200000\n0.200000\n0.200000\n0.200000\n0.200000" }, { "input": "2 4\n1 2", "output": "2.500000\n1.500000" }, { "input": "5 49\n1 2 3 4 5", "output": "11.800000\n10.800000\n9.800000\n8.800000\n7.800000" } ]
1,581,680,411
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
218
0
n,b=map(int,input().split()) d=list(map(int,input().split())) l1=[] mx=max(d) for item in d: l1.append(mx-item) b-=(mx-item) if b%5!=0 or b<0: print(-1) else: for i in range(len(l1)): l1[i]+=(b/5) for item in l1: print(format(item,'.6f'))
Title: Problem About Equation Time Limit: None seconds Memory Limit: None megabytes Problem Description: A group of *n* merry programmers celebrate Robert Floyd's birthday. Polucarpus has got an honourable task of pouring Ber-Cola to everybody. Pouring the same amount of Ber-Cola to everybody is really important. In other words, the drink's volume in each of the *n* mugs must be the same. Polycarpus has already began the process and he partially emptied the Ber-Cola bottle. Now the first mug has *a*1 milliliters of the drink, the second one has *a*2 milliliters and so on. The bottle has *b* milliliters left and Polycarpus plans to pour them into the mugs so that the main equation was fulfilled. Write a program that would determine what volume of the drink Polycarpus needs to add into each mug to ensure that the following two conditions were fulfilled simultaneously: - there were *b* milliliters poured in total. That is, the bottle need to be emptied; - after the process is over, the volumes of the drink in the mugs should be equal. Input Specification: The first line contains a pair of integers *n*, *b* (2<=≤<=*n*<=≤<=100,<=1<=≤<=*b*<=≤<=100), where *n* is the total number of friends in the group and *b* is the current volume of drink in the bottle. The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=100), where *a**i* is the current volume of drink in the *i*-th mug. Output Specification: Print a single number "-1" (without the quotes), if there is no solution. Otherwise, print *n* float numbers *c*1,<=*c*2,<=...,<=*c**n*, where *c**i* is the volume of the drink to add in the *i*-th mug. Print the numbers with no less than 6 digits after the decimal point, print each *c**i* on a single line. Polycarpus proved that if a solution exists then it is unique. Russian locale is installed by default on the testing computer. Make sure that your solution use the point to separate the integer part of a real number from the decimal, not a comma. Demo Input: ['5 50\n1 2 3 4 5\n', '2 2\n1 100\n'] Demo Output: ['12.000000\n11.000000\n10.000000\n9.000000\n8.000000\n', '-1\n'] Note: none
```python n,b=map(int,input().split()) d=list(map(int,input().split())) l1=[] mx=max(d) for item in d: l1.append(mx-item) b-=(mx-item) if b%5!=0 or b<0: print(-1) else: for i in range(len(l1)): l1[i]+=(b/5) for item in l1: print(format(item,'.6f')) ```
0
81
A
Plug-in
PROGRAMMING
1,400
[ "implementation" ]
A. Plug-in
1
256
Polycarp thinks about the meaning of life very often. He does this constantly, even when typing in the editor. Every time he starts brooding he can no longer fully concentrate and repeatedly presses the keys that need to be pressed only once. For example, instead of the phrase "how are you" he can type "hhoow aaaare yyoouu". Polycarp decided to automate the process of correcting such errors. He decided to write a plug-in to the text editor that will remove pairs of identical consecutive letters (if there are any in the text). Of course, this is not exactly what Polycarp needs, but he's got to start from something! Help Polycarp and write the main plug-in module. Your program should remove from a string all pairs of identical letters, which are consecutive. If after the removal there appear new pairs, the program should remove them as well. Technically, its work should be equivalent to the following: while the string contains a pair of consecutive identical letters, the pair should be deleted. Note that deleting of the consecutive identical letters can be done in any order, as any order leads to the same result.
The input data consists of a single line to be processed. The length of the line is from 1 to 2·105 characters inclusive. The string contains only lowercase Latin letters.
Print the given string after it is processed. It is guaranteed that the result will contain at least one character.
[ "hhoowaaaareyyoouu\n", "reallazy\n", "abacabaabacabaa\n" ]
[ "wre", "rezy", "a" ]
none
500
[ { "input": "hhoowaaaareyyoouu", "output": "wre" }, { "input": "reallazy", "output": "rezy" }, { "input": "abacabaabacabaa", "output": "a" }, { "input": "xraccabccbry", "output": "xy" }, { "input": "a", "output": "a" }, { "input": "b", "output": "b" }, { "input": "il", "output": "il" }, { "input": "gfj", "output": "gfj" }, { "input": "babbbbbababa", "output": "babababa" }, { "input": "babbbbabbabbbababbabbbbbbabaabaababaaabbbbbabbbbaaaaabbaaabbaabaabbbbabbbababbabaaabbababaaababbbaaa", "output": "babababababababababababa" }, { "input": "aab", "output": "b" }, { "input": "abb", "output": "a" }, { "input": "aba", "output": "aba" }, { "input": "ab", "output": "ab" } ]
1,569,790,499
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
19
1,000
3,481,600
def sol(s): new_s = remove(s) if s == new_s: print(s) return sol(new_s) def remove(s): s = list(s) for i in range(len(s) - 1): if s[i] == s[i + 1] and s[i] != '~': s[i] = '~' s[i + 1] = '~' return ''.join(s).replace('~','') sol(input().split())
Title: Plug-in Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Polycarp thinks about the meaning of life very often. He does this constantly, even when typing in the editor. Every time he starts brooding he can no longer fully concentrate and repeatedly presses the keys that need to be pressed only once. For example, instead of the phrase "how are you" he can type "hhoow aaaare yyoouu". Polycarp decided to automate the process of correcting such errors. He decided to write a plug-in to the text editor that will remove pairs of identical consecutive letters (if there are any in the text). Of course, this is not exactly what Polycarp needs, but he's got to start from something! Help Polycarp and write the main plug-in module. Your program should remove from a string all pairs of identical letters, which are consecutive. If after the removal there appear new pairs, the program should remove them as well. Technically, its work should be equivalent to the following: while the string contains a pair of consecutive identical letters, the pair should be deleted. Note that deleting of the consecutive identical letters can be done in any order, as any order leads to the same result. Input Specification: The input data consists of a single line to be processed. The length of the line is from 1 to 2·105 characters inclusive. The string contains only lowercase Latin letters. Output Specification: Print the given string after it is processed. It is guaranteed that the result will contain at least one character. Demo Input: ['hhoowaaaareyyoouu\n', 'reallazy\n', 'abacabaabacabaa\n'] Demo Output: ['wre', 'rezy', 'a'] Note: none
```python def sol(s): new_s = remove(s) if s == new_s: print(s) return sol(new_s) def remove(s): s = list(s) for i in range(len(s) - 1): if s[i] == s[i + 1] and s[i] != '~': s[i] = '~' s[i + 1] = '~' return ''.join(s).replace('~','') sol(input().split()) ```
0
84
A
Toy Army
PROGRAMMING
900
[ "math", "number theory" ]
A. Toy Army
2
256
The hero of our story, Valera, and his best friend Arcady are still in school, and therefore they spend all the free time playing turn-based strategy "GAGA: Go And Go Again". The gameplay is as follows. There are two armies on the playing field each of which consists of *n* men (*n* is always even). The current player specifies for each of her soldiers an enemy's soldier he will shoot (a target) and then all the player's soldiers shot simultaneously. This is a game world, and so each soldier shoots perfectly, that is he absolutely always hits the specified target. If an enemy soldier is hit, he will surely die. It may happen that several soldiers had been indicated the same target. Killed soldiers do not participate in the game anymore. The game "GAGA" consists of three steps: first Valera makes a move, then Arcady, then Valera again and the game ends. You are asked to calculate the maximum total number of soldiers that may be killed during the game.
The input data consist of a single integer *n* (2<=≤<=*n*<=≤<=108, *n* is even). Please note that before the game starts there are 2*n* soldiers on the fields.
Print a single number — a maximum total number of soldiers that could be killed in the course of the game in three turns.
[ "2\n", "4\n" ]
[ "3\n", "6\n" ]
The first sample test: 1) Valera's soldiers 1 and 2 shoot at Arcady's soldier 1. 2) Arcady's soldier 2 shoots at Valera's soldier 1. 3) Valera's soldier 1 shoots at Arcady's soldier 2. There are 3 soldiers killed in total: Valera's soldier 1 and Arcady's soldiers 1 and 2.
500
[ { "input": "2", "output": "3" }, { "input": "4", "output": "6" }, { "input": "6", "output": "9" }, { "input": "8", "output": "12" }, { "input": "10", "output": "15" }, { "input": "140", "output": "210" }, { "input": "500", "output": "750" }, { "input": "1000", "output": "1500" }, { "input": "2000", "output": "3000" }, { "input": "50000", "output": "75000" }, { "input": "10000", "output": "15000" }, { "input": "25460", "output": "38190" }, { "input": "54646", "output": "81969" }, { "input": "59790", "output": "89685" }, { "input": "578456", "output": "867684" }, { "input": "56798056", "output": "85197084" }, { "input": "8457980", "output": "12686970" }, { "input": "5687986", "output": "8531979" }, { "input": "10984932", "output": "16477398" }, { "input": "99999994", "output": "149999991" }, { "input": "99999996", "output": "149999994" }, { "input": "99999998", "output": "149999997" }, { "input": "100000000", "output": "150000000" } ]
1,581,095,841
2,147,483,647
Python 3
OK
TESTS
23
248
307,200
n = int(input()) k = n//2 #hello and welcome to this course on machine learning print(n+k)
Title: Toy Army Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: The hero of our story, Valera, and his best friend Arcady are still in school, and therefore they spend all the free time playing turn-based strategy "GAGA: Go And Go Again". The gameplay is as follows. There are two armies on the playing field each of which consists of *n* men (*n* is always even). The current player specifies for each of her soldiers an enemy's soldier he will shoot (a target) and then all the player's soldiers shot simultaneously. This is a game world, and so each soldier shoots perfectly, that is he absolutely always hits the specified target. If an enemy soldier is hit, he will surely die. It may happen that several soldiers had been indicated the same target. Killed soldiers do not participate in the game anymore. The game "GAGA" consists of three steps: first Valera makes a move, then Arcady, then Valera again and the game ends. You are asked to calculate the maximum total number of soldiers that may be killed during the game. Input Specification: The input data consist of a single integer *n* (2<=≤<=*n*<=≤<=108, *n* is even). Please note that before the game starts there are 2*n* soldiers on the fields. Output Specification: Print a single number — a maximum total number of soldiers that could be killed in the course of the game in three turns. Demo Input: ['2\n', '4\n'] Demo Output: ['3\n', '6\n'] Note: The first sample test: 1) Valera's soldiers 1 and 2 shoot at Arcady's soldier 1. 2) Arcady's soldier 2 shoots at Valera's soldier 1. 3) Valera's soldier 1 shoots at Arcady's soldier 2. There are 3 soldiers killed in total: Valera's soldier 1 and Arcady's soldiers 1 and 2.
```python n = int(input()) k = n//2 #hello and welcome to this course on machine learning print(n+k) ```
3.937428
47
A
Triangular numbers
PROGRAMMING
800
[ "brute force", "math" ]
A. Triangular numbers
2
256
A triangular number is the number of dots in an equilateral triangle uniformly filled with dots. For example, three dots can be arranged in a triangle; thus three is a triangular number. The *n*-th triangular number is the number of dots in a triangle with *n* dots on a side. . You can learn more about these numbers from Wikipedia (http://en.wikipedia.org/wiki/Triangular_number). Your task is to find out if a given integer is a triangular number.
The first line contains the single number *n* (1<=≤<=*n*<=≤<=500) — the given integer.
If the given integer is a triangular number output YES, otherwise output NO.
[ "1\n", "2\n", "3\n" ]
[ "YES\n", "NO\n", "YES\n" ]
none
500
[ { "input": "1", "output": "YES" }, { "input": "2", "output": "NO" }, { "input": "3", "output": "YES" }, { "input": "4", "output": "NO" }, { "input": "5", "output": "NO" }, { "input": "6", "output": "YES" }, { "input": "7", "output": "NO" }, { "input": "8", "output": "NO" }, { "input": "12", "output": "NO" }, { "input": "10", "output": "YES" }, { "input": "11", "output": "NO" }, { "input": "9", "output": "NO" }, { "input": "14", "output": "NO" }, { "input": "15", "output": "YES" }, { "input": "16", "output": "NO" }, { "input": "20", "output": "NO" }, { "input": "21", "output": "YES" }, { "input": "22", "output": "NO" }, { "input": "121", "output": "NO" }, { "input": "135", "output": "NO" }, { "input": "136", "output": "YES" }, { "input": "137", "output": "NO" }, { "input": "152", "output": "NO" }, { "input": "153", "output": "YES" }, { "input": "154", "output": "NO" }, { "input": "171", "output": "YES" }, { "input": "189", "output": "NO" }, { "input": "190", "output": "YES" }, { "input": "191", "output": "NO" }, { "input": "210", "output": "YES" }, { "input": "211", "output": "NO" }, { "input": "231", "output": "YES" }, { "input": "232", "output": "NO" }, { "input": "252", "output": "NO" }, { "input": "253", "output": "YES" }, { "input": "254", "output": "NO" }, { "input": "275", "output": "NO" }, { "input": "276", "output": "YES" }, { "input": "277", "output": "NO" }, { "input": "299", "output": "NO" }, { "input": "300", "output": "YES" }, { "input": "301", "output": "NO" }, { "input": "324", "output": "NO" }, { "input": "325", "output": "YES" }, { "input": "326", "output": "NO" }, { "input": "350", "output": "NO" }, { "input": "351", "output": "YES" }, { "input": "352", "output": "NO" }, { "input": "377", "output": "NO" }, { "input": "378", "output": "YES" }, { "input": "406", "output": "YES" }, { "input": "434", "output": "NO" }, { "input": "435", "output": "YES" }, { "input": "464", "output": "NO" }, { "input": "465", "output": "YES" }, { "input": "495", "output": "NO" }, { "input": "496", "output": "YES" }, { "input": "497", "output": "NO" }, { "input": "331", "output": "NO" }, { "input": "413", "output": "NO" }, { "input": "177", "output": "NO" }, { "input": "122", "output": "NO" }, { "input": "478", "output": "NO" }, { "input": "188", "output": "NO" }, { "input": "21", "output": "YES" }, { "input": "474", "output": "NO" }, { "input": "21", "output": "YES" }, { "input": "48", "output": "NO" }, { "input": "498", "output": "NO" }, { "input": "499", "output": "NO" }, { "input": "500", "output": "NO" } ]
1,617,619,089
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
52
124
0
n=int(input()) b=0 a=1 for i in range(1,30): if(n==a): b=1 break a=(i*(i+1))//2 if(b==1): print('YES') else: print('NO')
Title: Triangular numbers Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A triangular number is the number of dots in an equilateral triangle uniformly filled with dots. For example, three dots can be arranged in a triangle; thus three is a triangular number. The *n*-th triangular number is the number of dots in a triangle with *n* dots on a side. . You can learn more about these numbers from Wikipedia (http://en.wikipedia.org/wiki/Triangular_number). Your task is to find out if a given integer is a triangular number. Input Specification: The first line contains the single number *n* (1<=≤<=*n*<=≤<=500) — the given integer. Output Specification: If the given integer is a triangular number output YES, otherwise output NO. Demo Input: ['1\n', '2\n', '3\n'] Demo Output: ['YES\n', 'NO\n', 'YES\n'] Note: none
```python n=int(input()) b=0 a=1 for i in range(1,30): if(n==a): b=1 break a=(i*(i+1))//2 if(b==1): print('YES') else: print('NO') ```
0
855
B
Marvolo Gaunt's Ring
PROGRAMMING
1,500
[ "brute force", "data structures", "dp" ]
null
null
Professor Dumbledore is helping Harry destroy the Horcruxes. He went to Gaunt Shack as he suspected a Horcrux to be present there. He saw Marvolo Gaunt's Ring and identified it as a Horcrux. Although he destroyed it, he is still affected by its curse. Professor Snape is helping Dumbledore remove the curse. For this, he wants to give Dumbledore exactly *x* drops of the potion he made. Value of *x* is calculated as maximum of *p*·*a**i*<=+<=*q*·*a**j*<=+<=*r*·*a**k* for given *p*,<=*q*,<=*r* and array *a*1,<=*a*2,<=... *a**n* such that 1<=≤<=*i*<=≤<=*j*<=≤<=*k*<=≤<=*n*. Help Snape find the value of *x*. Do note that the value of *x* may be negative.
First line of input contains 4 integers *n*,<=*p*,<=*q*,<=*r* (<=-<=109<=≤<=*p*,<=*q*,<=*r*<=≤<=109,<=1<=≤<=*n*<=≤<=105). Next line of input contains *n* space separated integers *a*1,<=*a*2,<=... *a**n* (<=-<=109<=≤<=*a**i*<=≤<=109).
Output a single integer the maximum value of *p*·*a**i*<=+<=*q*·*a**j*<=+<=*r*·*a**k* that can be obtained provided 1<=≤<=*i*<=≤<=*j*<=≤<=*k*<=≤<=*n*.
[ "5 1 2 3\n1 2 3 4 5\n", "5 1 2 -3\n-1 -2 -3 -4 -5\n" ]
[ "30\n", "12\n" ]
In the first sample case, we can take *i* = *j* = *k* = 5, thus making the answer as 1·5 + 2·5 + 3·5 = 30. In second sample case, selecting *i* = *j* = 1 and *k* = 5 gives the answer 12.
1,000
[ { "input": "5 1 2 3\n1 2 3 4 5", "output": "30" }, { "input": "5 1 2 -3\n-1 -2 -3 -4 -5", "output": "12" }, { "input": "5 886327859 82309257 -68295239\n-731225382 354766539 -48222231 -474691998 360965777", "output": "376059240645059046" }, { "input": "4 -96405765 -495906217 625385006\n-509961652 392159235 -577128498 -744548876", "output": "547306902373544674" }, { "input": "43 959134961 -868367850 142426380\n921743429 63959718 -797293233 122041422 -407576197 700139744 299598010 168207043 362252658 591926075 941946099 812263640 -76679927 -824267725 89529990 -73303355 83596189 -982699817 -235197848 654773327 125211479 -497091570 -2301804 203486596 -126652024 309810546 -581289415 -740125230 64425927 -501018049 304730559 34930193 -762964086 723645139 -826821494 495947907 816331024 9932423 -876541603 -782692568 322360800 841436938 40787162", "output": "1876641179289775029" }, { "input": "1 0 0 0\n0", "output": "0" }, { "input": "1 1000000000 1000000000 1000000000\n1000000000", "output": "3000000000000000000" }, { "input": "1 -1000000000 -1000000000 1000000000\n1000000000", "output": "-1000000000000000000" }, { "input": "1 -1000000000 -1000000000 -1000000000\n1000000000", "output": "-3000000000000000000" }, { "input": "3 1000000000 1000000000 1000000000\n-1000000000 -1000000000 -1000000000", "output": "-3000000000000000000" }, { "input": "1 1 1 1\n-1", "output": "-3" }, { "input": "1 -1 -1 -1\n1", "output": "-3" }, { "input": "1 1000000000 1000000000 1000000000\n-1000000000", "output": "-3000000000000000000" }, { "input": "1 1 2 3\n-1", "output": "-6" }, { "input": "3 -1000000000 -1000000000 -1000000000\n1000000000 1000000000 1000000000", "output": "-3000000000000000000" }, { "input": "2 -1000000000 -1000000000 -1000000000\n1000000000 1000000000", "output": "-3000000000000000000" }, { "input": "3 1 1 1\n-1 -1 -1", "output": "-3" }, { "input": "1 -1000000000 0 0\n1000000000", "output": "-1000000000000000000" }, { "input": "1 -100 -100 -100\n100", "output": "-30000" }, { "input": "5 -1000000000 -1000000000 -1000000000\n1000000000 1000000000 1000000000 1000000000 1000000000", "output": "-3000000000000000000" }, { "input": "1 999999999 999999999 999999999\n-999999999", "output": "-2999999994000000003" }, { "input": "3 -1000000000 -1000000000 1\n1000000000 1000000000 1000000000", "output": "-1999999999000000000" }, { "input": "3 -2 3 -2\n1 2 1", "output": "2" }, { "input": "2 1 -1 1\n1 -1", "output": "1" }, { "input": "1 -1000000000 1 -1000000000\n1000000000", "output": "-1999999999000000000" }, { "input": "1 1000000000 1000000000 -1000000000\n-1000000000", "output": "-1000000000000000000" }, { "input": "1 -1000000000 -1000000000 0\n1000000000", "output": "-2000000000000000000" } ]
1,688,919,572
2,147,483,647
Python 3
OK
TESTS
82
327
26,112,000
n,p,q,r = [int(_) for _ in input().split()] arr = [int(_) for _ in input().split()] dp = [[0]*3 for _ in range(100005)] dp[0][0] = arr[0]*p for i in range(1,n): dp[i][0] = max(dp[i-1][0], (p*arr[i])) dp[0][1] = dp[0][0]+ arr[0]*q for i in range(1,n): dp[i][1] = max(dp[i-1][1], dp[i][0]+ q*arr[i]) dp[0][2] = dp[0][1] + arr[0]*r for i in range(1,n): dp[i][2] = max(dp[i-1][2], dp[i][1] + arr[i]*r) print(dp[n-1][2])
Title: Marvolo Gaunt's Ring Time Limit: None seconds Memory Limit: None megabytes Problem Description: Professor Dumbledore is helping Harry destroy the Horcruxes. He went to Gaunt Shack as he suspected a Horcrux to be present there. He saw Marvolo Gaunt's Ring and identified it as a Horcrux. Although he destroyed it, he is still affected by its curse. Professor Snape is helping Dumbledore remove the curse. For this, he wants to give Dumbledore exactly *x* drops of the potion he made. Value of *x* is calculated as maximum of *p*·*a**i*<=+<=*q*·*a**j*<=+<=*r*·*a**k* for given *p*,<=*q*,<=*r* and array *a*1,<=*a*2,<=... *a**n* such that 1<=≤<=*i*<=≤<=*j*<=≤<=*k*<=≤<=*n*. Help Snape find the value of *x*. Do note that the value of *x* may be negative. Input Specification: First line of input contains 4 integers *n*,<=*p*,<=*q*,<=*r* (<=-<=109<=≤<=*p*,<=*q*,<=*r*<=≤<=109,<=1<=≤<=*n*<=≤<=105). Next line of input contains *n* space separated integers *a*1,<=*a*2,<=... *a**n* (<=-<=109<=≤<=*a**i*<=≤<=109). Output Specification: Output a single integer the maximum value of *p*·*a**i*<=+<=*q*·*a**j*<=+<=*r*·*a**k* that can be obtained provided 1<=≤<=*i*<=≤<=*j*<=≤<=*k*<=≤<=*n*. Demo Input: ['5 1 2 3\n1 2 3 4 5\n', '5 1 2 -3\n-1 -2 -3 -4 -5\n'] Demo Output: ['30\n', '12\n'] Note: In the first sample case, we can take *i* = *j* = *k* = 5, thus making the answer as 1·5 + 2·5 + 3·5 = 30. In second sample case, selecting *i* = *j* = 1 and *k* = 5 gives the answer 12.
```python n,p,q,r = [int(_) for _ in input().split()] arr = [int(_) for _ in input().split()] dp = [[0]*3 for _ in range(100005)] dp[0][0] = arr[0]*p for i in range(1,n): dp[i][0] = max(dp[i-1][0], (p*arr[i])) dp[0][1] = dp[0][0]+ arr[0]*q for i in range(1,n): dp[i][1] = max(dp[i-1][1], dp[i][0]+ q*arr[i]) dp[0][2] = dp[0][1] + arr[0]*r for i in range(1,n): dp[i][2] = max(dp[i-1][2], dp[i][1] + arr[i]*r) print(dp[n-1][2]) ```
3
228
A
Is your horseshoe on the other hoof?
PROGRAMMING
800
[ "implementation" ]
null
null
Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has got four horseshoes left from the last year, but maybe some of them have the same color. In this case he needs to go to the store and buy some few more horseshoes, not to lose face in front of his stylish comrades. Fortunately, the store sells horseshoes of all colors under the sun and Valera has enough money to buy any four of them. However, in order to save the money, he would like to spend as little money as possible, so you need to help Valera and determine what is the minimum number of horseshoes he needs to buy to wear four horseshoes of different colors to a party.
The first line contains four space-separated integers *s*1,<=*s*2,<=*s*3,<=*s*4 (1<=≤<=*s*1,<=*s*2,<=*s*3,<=*s*4<=≤<=109) — the colors of horseshoes Valera has. Consider all possible colors indexed with integers.
Print a single integer — the minimum number of horseshoes Valera needs to buy.
[ "1 7 3 3\n", "7 7 7 7\n" ]
[ "1\n", "3\n" ]
none
500
[ { "input": "1 7 3 3", "output": "1" }, { "input": "7 7 7 7", "output": "3" }, { "input": "81170865 673572653 756938629 995577259", "output": "0" }, { "input": "3491663 217797045 522540872 715355328", "output": "0" }, { "input": "251590420 586975278 916631563 586975278", "output": "1" }, { "input": "259504825 377489979 588153796 377489979", "output": "1" }, { "input": "652588203 931100304 931100304 652588203", "output": "2" }, { "input": "391958720 651507265 391958720 651507265", "output": "2" }, { "input": "90793237 90793237 90793237 90793237", "output": "3" }, { "input": "551651653 551651653 551651653 551651653", "output": "3" }, { "input": "156630260 609654355 668943582 973622757", "output": "0" }, { "input": "17061017 110313588 434481173 796661222", "output": "0" }, { "input": "24975422 256716298 337790533 690960249", "output": "0" }, { "input": "255635360 732742923 798648949 883146723", "output": "0" }, { "input": "133315691 265159773 734556507 265159773", "output": "1" }, { "input": "28442865 741657755 978106882 978106882", "output": "1" }, { "input": "131245479 174845575 497483467 131245479", "output": "1" }, { "input": "139159884 616215581 958341883 616215581", "output": "1" }, { "input": "147784432 947653080 947653080 947653080", "output": "2" }, { "input": "94055790 756126496 756126496 94055790", "output": "2" }, { "input": "240458500 511952208 240458500 511952208", "output": "2" }, { "input": "681828506 972810624 972810624 681828506", "output": "2" }, { "input": "454961014 454961014 454961014 454961014", "output": "3" }, { "input": "915819430 915819430 915819430 915819430", "output": "3" }, { "input": "671645142 671645142 671645142 671645142", "output": "3" }, { "input": "132503558 132503558 132503558 132503558", "output": "3" }, { "input": "5 5 999999 6", "output": "1" }, { "input": "1 1 2 5", "output": "1" }, { "input": "2 1 2 3", "output": "1" }, { "input": "1 1 3 5", "output": "1" }, { "input": "1 1 3 3", "output": "2" }, { "input": "2 2 2 1", "output": "2" }, { "input": "3 1 1 1", "output": "2" }, { "input": "1 2 2 2", "output": "2" } ]
1,697,836,166
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
92
0
t = "" for i in input().split(): if i not in t: t+=i print(4-len(t))
Title: Is your horseshoe on the other hoof? Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has got four horseshoes left from the last year, but maybe some of them have the same color. In this case he needs to go to the store and buy some few more horseshoes, not to lose face in front of his stylish comrades. Fortunately, the store sells horseshoes of all colors under the sun and Valera has enough money to buy any four of them. However, in order to save the money, he would like to spend as little money as possible, so you need to help Valera and determine what is the minimum number of horseshoes he needs to buy to wear four horseshoes of different colors to a party. Input Specification: The first line contains four space-separated integers *s*1,<=*s*2,<=*s*3,<=*s*4 (1<=≤<=*s*1,<=*s*2,<=*s*3,<=*s*4<=≤<=109) — the colors of horseshoes Valera has. Consider all possible colors indexed with integers. Output Specification: Print a single integer — the minimum number of horseshoes Valera needs to buy. Demo Input: ['1 7 3 3\n', '7 7 7 7\n'] Demo Output: ['1\n', '3\n'] Note: none
```python t = "" for i in input().split(): if i not in t: t+=i print(4-len(t)) ```
0
933
E
A Preponderant Reunion
PROGRAMMING
3,200
[ "constructive algorithms", "dp" ]
null
null
East or west, home is best. That's why family reunion, the indispensable necessity of Lunar New Year celebration, is put in such a position. After the reunion dinner, Little Tommy plays a game with the family. Here is a concise introduction to this game: 1. There is a sequence of *n* non-negative integers *p*1,<=*p*2,<=...,<=*p**n* in the beginning. It is ruled that each integer in this sequence should be non-negative at any time. 1. You can select two consecutive positive integers in this sequence, *p**i* and *p**i*<=+<=1 (1<=≤<=*i*<=&lt;<=*n*), and then decrease them by their minimum (i. e. *min*(*p**i*,<=*p**i*<=+<=1)), the cost of this operation is equal to *min*(*p**i*,<=*p**i*<=+<=1). We call such operation as a descension. 1. The game immediately ends when there are no two consecutive positive integers. Your task is to end the game so that the total cost of your operations is as small as possible. Obviously, every game ends after at most *n*<=-<=1 descensions. Please share your solution of this game with the lowest cost.
The first line contains one integer *n* (1<=≤<=*n*<=≤<=3·105). The second line contains *n* space-separated integers *p*1,<=*p*2,<=...,<=*p**n* (0<=≤<=*p**i*<=≤<=109,<=*i*<==<=1,<=2,<=...,<=*n*).
In the first line print one integer as the number of descensions *m* (0<=≤<=*m*<=≤<=*n*<=-<=1). In the next *m* lines print the descensions chronologically. More precisely, in each line of the next *m* lines print one integer *i* (1<=≤<=*i*<=&lt;<=*n*) representing a descension would operate on *p**i* and *p**i*<=+<=1 such that all the descensions could be utilized from top to bottom. If there are many possible solutions to reach the minimal cost, print any of them.
[ "4\n2 1 3 1\n", "5\n2 2 1 3 1\n" ]
[ "2\n1\n3\n", "3\n2\n1\n4\n" ]
In the first sample, one possible best solution is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/9248227dd2a5fa16d275273b9219a6e5a3560846.png" style="max-width: 100.0%;max-height: 100.0%;"/>, of which the cost is 1 + 1 = 2. In the second sample, one possible best solution is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/8f91058897d4137e5df572ebfbf65e2a7d88692a.png" style="max-width: 100.0%;max-height: 100.0%;"/>, of which the cost is 1 + 1 + 1 = 3.
2,500
[]
1,689,593,946
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
46
0
print("_RANDOM_GUESS_1689593946.6655548")# 1689593946.6655753
Title: A Preponderant Reunion Time Limit: None seconds Memory Limit: None megabytes Problem Description: East or west, home is best. That's why family reunion, the indispensable necessity of Lunar New Year celebration, is put in such a position. After the reunion dinner, Little Tommy plays a game with the family. Here is a concise introduction to this game: 1. There is a sequence of *n* non-negative integers *p*1,<=*p*2,<=...,<=*p**n* in the beginning. It is ruled that each integer in this sequence should be non-negative at any time. 1. You can select two consecutive positive integers in this sequence, *p**i* and *p**i*<=+<=1 (1<=≤<=*i*<=&lt;<=*n*), and then decrease them by their minimum (i. e. *min*(*p**i*,<=*p**i*<=+<=1)), the cost of this operation is equal to *min*(*p**i*,<=*p**i*<=+<=1). We call such operation as a descension. 1. The game immediately ends when there are no two consecutive positive integers. Your task is to end the game so that the total cost of your operations is as small as possible. Obviously, every game ends after at most *n*<=-<=1 descensions. Please share your solution of this game with the lowest cost. Input Specification: The first line contains one integer *n* (1<=≤<=*n*<=≤<=3·105). The second line contains *n* space-separated integers *p*1,<=*p*2,<=...,<=*p**n* (0<=≤<=*p**i*<=≤<=109,<=*i*<==<=1,<=2,<=...,<=*n*). Output Specification: In the first line print one integer as the number of descensions *m* (0<=≤<=*m*<=≤<=*n*<=-<=1). In the next *m* lines print the descensions chronologically. More precisely, in each line of the next *m* lines print one integer *i* (1<=≤<=*i*<=&lt;<=*n*) representing a descension would operate on *p**i* and *p**i*<=+<=1 such that all the descensions could be utilized from top to bottom. If there are many possible solutions to reach the minimal cost, print any of them. Demo Input: ['4\n2 1 3 1\n', '5\n2 2 1 3 1\n'] Demo Output: ['2\n1\n3\n', '3\n2\n1\n4\n'] Note: In the first sample, one possible best solution is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/9248227dd2a5fa16d275273b9219a6e5a3560846.png" style="max-width: 100.0%;max-height: 100.0%;"/>, of which the cost is 1 + 1 = 2. In the second sample, one possible best solution is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/8f91058897d4137e5df572ebfbf65e2a7d88692a.png" style="max-width: 100.0%;max-height: 100.0%;"/>, of which the cost is 1 + 1 + 1 = 3.
```python print("_RANDOM_GUESS_1689593946.6655548")# 1689593946.6655753 ```
0
735
D
Taxes
PROGRAMMING
1,600
[ "math", "number theory" ]
null
null
Mr. Funt now lives in a country with a very specific tax laws. The total income of mr. Funt during this year is equal to *n* (*n*<=≥<=2) burles and the amount of tax he has to pay is calculated as the maximum divisor of *n* (not equal to *n*, of course). For example, if *n*<==<=6 then Funt has to pay 3 burles, while for *n*<==<=25 he needs to pay 5 and if *n*<==<=2 he pays only 1 burle. As mr. Funt is a very opportunistic person he wants to cheat a bit. In particular, he wants to split the initial *n* in several parts *n*1<=+<=*n*2<=+<=...<=+<=*n**k*<==<=*n* (here *k* is arbitrary, even *k*<==<=1 is allowed) and pay the taxes for each part separately. He can't make some part equal to 1 because it will reveal him. So, the condition *n**i*<=≥<=2 should hold for all *i* from 1 to *k*. Ostap Bender wonders, how many money Funt has to pay (i.e. minimal) if he chooses and optimal way to split *n* in parts.
The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=2·109) — the total year income of mr. Funt.
Print one integer — minimum possible number of burles that mr. Funt has to pay as a tax.
[ "4\n", "27\n" ]
[ "2\n", "3\n" ]
none
1,750
[ { "input": "4", "output": "2" }, { "input": "27", "output": "3" }, { "input": "3", "output": "1" }, { "input": "5", "output": "1" }, { "input": "10", "output": "2" }, { "input": "2000000000", "output": "2" }, { "input": "26", "output": "2" }, { "input": "7", "output": "1" }, { "input": "2", "output": "1" }, { "input": "11", "output": "1" }, { "input": "1000000007", "output": "1" }, { "input": "1000000009", "output": "1" }, { "input": "1999999999", "output": "3" }, { "input": "1000000011", "output": "2" }, { "input": "101", "output": "1" }, { "input": "103", "output": "1" }, { "input": "1001", "output": "3" }, { "input": "1003", "output": "3" }, { "input": "10001", "output": "3" }, { "input": "10003", "output": "3" }, { "input": "129401294", "output": "2" }, { "input": "234911024", "output": "2" }, { "input": "192483501", "output": "3" }, { "input": "1234567890", "output": "2" }, { "input": "719241201", "output": "3" }, { "input": "9", "output": "2" }, { "input": "33", "output": "2" }, { "input": "25", "output": "2" }, { "input": "15", "output": "2" }, { "input": "147", "output": "3" }, { "input": "60119912", "output": "2" }, { "input": "45", "output": "2" }, { "input": "21", "output": "2" }, { "input": "9975", "output": "2" }, { "input": "17", "output": "1" }, { "input": "99", "output": "2" }, { "input": "49", "output": "2" }, { "input": "243", "output": "2" }, { "input": "43", "output": "1" }, { "input": "39", "output": "2" }, { "input": "6", "output": "2" }, { "input": "8", "output": "2" }, { "input": "12", "output": "2" }, { "input": "13", "output": "1" }, { "input": "14", "output": "2" }, { "input": "16", "output": "2" }, { "input": "18", "output": "2" }, { "input": "19", "output": "1" }, { "input": "20", "output": "2" }, { "input": "22", "output": "2" }, { "input": "23", "output": "1" }, { "input": "24", "output": "2" }, { "input": "962", "output": "2" }, { "input": "29", "output": "1" }, { "input": "55", "output": "2" }, { "input": "125", "output": "3" }, { "input": "1999999929", "output": "2" }, { "input": "493", "output": "2" }, { "input": "10000021", "output": "2" }, { "input": "541", "output": "1" }, { "input": "187", "output": "3" }, { "input": "95", "output": "3" }, { "input": "999991817", "output": "3" }, { "input": "37998938", "output": "2" }, { "input": "1847133842", "output": "2" }, { "input": "1000000005", "output": "3" }, { "input": "19828", "output": "2" }, { "input": "998321704", "output": "2" }, { "input": "370359", "output": "3" }, { "input": "115", "output": "2" }, { "input": "200000015", "output": "3" }, { "input": "479001600", "output": "2" }, { "input": "536870912", "output": "2" }, { "input": "10759922", "output": "2" }, { "input": "1999999927", "output": "1" }, { "input": "123", "output": "3" }, { "input": "200743933", "output": "3" }, { "input": "949575615", "output": "3" }, { "input": "99990001", "output": "1" }, { "input": "715827883", "output": "1" }, { "input": "5592406", "output": "2" }, { "input": "8388609", "output": "3" }, { "input": "1908903481", "output": "3" }, { "input": "1076153021", "output": "3" }, { "input": "344472101", "output": "3" } ]
1,481,864,992
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
92
0
i = int(input()) if i == 2: print(1) elif i == 3: print(2) elif i % 2 == 0: print(2) else: print(3)
Title: Taxes Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mr. Funt now lives in a country with a very specific tax laws. The total income of mr. Funt during this year is equal to *n* (*n*<=≥<=2) burles and the amount of tax he has to pay is calculated as the maximum divisor of *n* (not equal to *n*, of course). For example, if *n*<==<=6 then Funt has to pay 3 burles, while for *n*<==<=25 he needs to pay 5 and if *n*<==<=2 he pays only 1 burle. As mr. Funt is a very opportunistic person he wants to cheat a bit. In particular, he wants to split the initial *n* in several parts *n*1<=+<=*n*2<=+<=...<=+<=*n**k*<==<=*n* (here *k* is arbitrary, even *k*<==<=1 is allowed) and pay the taxes for each part separately. He can't make some part equal to 1 because it will reveal him. So, the condition *n**i*<=≥<=2 should hold for all *i* from 1 to *k*. Ostap Bender wonders, how many money Funt has to pay (i.e. minimal) if he chooses and optimal way to split *n* in parts. Input Specification: The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=2·109) — the total year income of mr. Funt. Output Specification: Print one integer — minimum possible number of burles that mr. Funt has to pay as a tax. Demo Input: ['4\n', '27\n'] Demo Output: ['2\n', '3\n'] Note: none
```python i = int(input()) if i == 2: print(1) elif i == 3: print(2) elif i % 2 == 0: print(2) else: print(3) ```
0
644
A
Parliament of Berland
PROGRAMMING
1,000
[ "*special", "constructive algorithms" ]
null
null
There are *n* parliamentarians in Berland. They are numbered with integers from 1 to *n*. It happened that all parliamentarians with odd indices are Democrats and all parliamentarians with even indices are Republicans. New parliament assembly hall is a rectangle consisting of *a*<=×<=*b* chairs — *a* rows of *b* chairs each. Two chairs are considered neighbouring if they share as side. For example, chair number 5 in row number 2 is neighbouring to chairs number 4 and 6 in this row and chairs with number 5 in rows 1 and 3. Thus, chairs have four neighbours in general, except for the chairs on the border of the hall We know that if two parliamentarians from one political party (that is two Democrats or two Republicans) seat nearby they spent all time discussing internal party issues. Write the program that given the number of parliamentarians and the sizes of the hall determine if there is a way to find a seat for any parliamentarian, such that no two members of the same party share neighbouring seats.
The first line of the input contains three integers *n*, *a* and *b* (1<=≤<=*n*<=≤<=10<=000, 1<=≤<=*a*,<=*b*<=≤<=100) — the number of parliamentarians, the number of rows in the assembly hall and the number of seats in each row, respectively.
If there is no way to assigns seats to parliamentarians in a proper way print -1. Otherwise print the solution in *a* lines, each containing *b* integers. The *j*-th integer of the *i*-th line should be equal to the index of parliamentarian occupying this seat, or 0 if this seat should remain empty. If there are multiple possible solution, you may print any of them.
[ "3 2 2\n", "8 4 3\n", "10 2 2\n" ]
[ "0 3\n1 2\n", "7 8 3\n0 1 4\n6 0 5\n0 2 0\n", "-1\n" ]
In the first sample there are many other possible solutions. For example, and The following assignment is incorrect, because parliamentarians 1 and 3 are both from Democrats party but will occupy neighbouring seats.
500
[ { "input": "3 2 2", "output": "1 2 \n0 3 " }, { "input": "8 4 3", "output": "1 2 3 \n4 5 6 \n7 8 0 \n0 0 0 " }, { "input": "10 2 2", "output": "-1" }, { "input": "1 1 1", "output": "1 " }, { "input": "8 3 3", "output": "1 2 3 \n4 5 6 \n7 8 0 " }, { "input": "1 1 100", "output": "1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 " }, { "input": "1 100 1", "output": "1 \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 " }, { "input": "12 4 3", "output": "1 2 3 \n4 5 6 \n7 8 9 \n10 11 12 " }, { "input": "64 8 9", "output": "1 2 3 4 5 6 7 8 9 \n10 11 12 13 14 15 16 17 18 \n19 20 21 22 23 24 25 26 27 \n28 29 30 31 32 33 34 35 36 \n37 38 39 40 41 42 43 44 45 \n46 47 48 49 50 51 52 53 54 \n55 56 57 58 59 60 61 62 63 \n64 0 0 0 0 0 0 0 0 " }, { "input": "13 2 6", "output": "-1" }, { "input": "41 6 7", "output": "1 2 3 4 5 6 7 \n8 9 10 11 12 13 14 \n15 16 17 18 19 20 21 \n22 23 24 25 26 27 28 \n29 30 31 32 33 34 35 \n36 37 38 39 40 41 0 " }, { "input": "9999 100 100", "output": "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 \n102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 138 137 140 139 142 141 144 143 146 145 148 147 150 149 152 151 154 153 1..." }, { "input": "10000 100 100", "output": "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 \n102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 138 137 140 139 142 141 144 143 146 145 148 147 150 149 152 151 154 153 1..." }, { "input": "2099 70 30", "output": "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 \n32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 \n61 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 \n92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 \n121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 \n152 151 1..." }, { "input": "2098 30 70", "output": "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 \n72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 138 137 140 139 \n141 142 143 144 145 146 147 148 149 150 151 152 153 154..." }, { "input": "10000 1 1", "output": "-1" }, { "input": "1583 49 36", "output": "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 \n38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 \n73 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 101 102 103 104 105 106 107 108 \n110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 138 137 140 139 142 141 144 143 \n145 146 147 148 149 150 151 152 153..." }, { "input": "4825 77 88", "output": "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 \n90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 138 137 140 139 142 141 144 143 146 145 148 147 150 149 152 151 154 153 1..." }, { "input": "26 1 33", "output": "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 0 0 0 0 0 0 0 " }, { "input": "274 25 77", "output": "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 \n78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 \n..." }, { "input": "694 49 22", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 \n24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 \n45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 \n68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 \n89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 \n112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 \n133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152..." }, { "input": "3585 77 62", "output": "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 \n64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 \n125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..." }, { "input": "3 1 6", "output": "1 2 3 0 0 0 " }, { "input": "352 25 59", "output": "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 \n60 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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 \n119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..." }, { "input": "150 53 3", "output": "1 2 3 \n4 5 6 \n7 8 9 \n10 11 12 \n13 14 15 \n16 17 18 \n19 20 21 \n22 23 24 \n25 26 27 \n28 29 30 \n31 32 33 \n34 35 36 \n37 38 39 \n40 41 42 \n43 44 45 \n46 47 48 \n49 50 51 \n52 53 54 \n55 56 57 \n58 59 60 \n61 62 63 \n64 65 66 \n67 68 69 \n70 71 72 \n73 74 75 \n76 77 78 \n79 80 81 \n82 83 84 \n85 86 87 \n88 89 90 \n91 92 93 \n94 95 96 \n97 98 99 \n100 101 102 \n103 104 105 \n106 107 108 \n109 110 111 \n112 113 114 \n115 116 117 \n118 119 120 \n121 122 123 \n124 125 126 \n127 128 129 \n130 131 132 \n133..." }, { "input": "4227 91 80", "output": "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 \n82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 138 137 140 139 142 141 144 143 146 145 148 147 150 149 152 151 154 153 1..." }, { "input": "378 19 25", "output": "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 \n26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 \n51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 \n76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 \n101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 \n126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 \n151 152..." }, { "input": "2357 43 65", "output": "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 \n66 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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 \n131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..." }, { "input": "232 71 9", "output": "1 2 3 4 5 6 7 8 9 \n10 11 12 13 14 15 16 17 18 \n19 20 21 22 23 24 25 26 27 \n28 29 30 31 32 33 34 35 36 \n37 38 39 40 41 42 43 44 45 \n46 47 48 49 50 51 52 53 54 \n55 56 57 58 59 60 61 62 63 \n64 65 66 67 68 69 70 71 72 \n73 74 75 76 77 78 79 80 81 \n82 83 84 85 86 87 88 89 90 \n91 92 93 94 95 96 97 98 99 \n100 101 102 103 104 105 106 107 108 \n109 110 111 112 113 114 115 116 117 \n118 119 120 121 122 123 124 125 126 \n127 128 129 130 131 132 133 134 135 \n136 137 138 139 140 141 142 143 144 \n145 146 147..." }, { "input": "2362 91 62", "output": "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 \n64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 \n125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..." }, { "input": "4601 59 78", "output": "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 \n80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 138 137 140 139 142 141 144 143 146 145 148 147 150 149 152 151 154 153 1..." }, { "input": "4439 74 60", "output": "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 \n62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 \n121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..." }, { "input": "3733 89 42", "output": "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 \n44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 \n85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 \n128 127 130 129 132 131 134 133 136 135 138 137 140 139 142 141 144 143 146 145 148 147 150 149 152 151 154 1..." }, { "input": "335 12 28", "output": "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 \n30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 \n57 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 \n86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 \n113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 \n142 141 144 143 146 145 148 147 150 149 152 151 1..." }, { "input": "440 26 17", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 \n18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 \n35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 \n52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 \n69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 \n86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 \n103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 \n120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 \n137 138 139 140 141 142 143 144 145 146 147 148 149 150 151..." }, { "input": "109 37 3", "output": "1 2 3 \n4 5 6 \n7 8 9 \n10 11 12 \n13 14 15 \n16 17 18 \n19 20 21 \n22 23 24 \n25 26 27 \n28 29 30 \n31 32 33 \n34 35 36 \n37 38 39 \n40 41 42 \n43 44 45 \n46 47 48 \n49 50 51 \n52 53 54 \n55 56 57 \n58 59 60 \n61 62 63 \n64 65 66 \n67 68 69 \n70 71 72 \n73 74 75 \n76 77 78 \n79 80 81 \n82 83 84 \n85 86 87 \n88 89 90 \n91 92 93 \n94 95 96 \n97 98 99 \n100 101 102 \n103 104 105 \n106 107 108 \n109 0 0 " }, { "input": "4416 52 85", "output": "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 \n86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1..." }, { "input": "5025 75 67", "output": "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 \n68 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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 \n135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..." }, { "input": "4983 89 56", "output": "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 \n58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 \n113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..." }, { "input": "950 17 56", "output": "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 \n58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 \n113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..." }, { "input": "1637 40 41", "output": "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 \n42 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 \n83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 \n124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 1..." }, { "input": "1142 52 22", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 \n24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 \n45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 \n68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 \n89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 \n112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 \n133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152..." }, { "input": "907 70 13", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 \n14 15 16 17 18 19 20 21 22 23 24 25 26 \n27 28 29 30 31 32 33 34 35 36 37 38 39 \n40 41 42 43 44 45 46 47 48 49 50 51 52 \n53 54 55 56 57 58 59 60 61 62 63 64 65 \n66 67 68 69 70 71 72 73 74 75 76 77 78 \n79 80 81 82 83 84 85 86 87 88 89 90 91 \n92 93 94 95 96 97 98 99 100 101 102 103 104 \n105 106 107 108 109 110 111 112 113 114 115 116 117 \n118 119 120 121 122 123 124 125 126 127 128 129 130 \n131 132 133 134 135 136 137 138 139 140 141 142 143 \n144 145 146 147 148 149 1..." }, { "input": "7279 80 91", "output": "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 \n92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1..." }, { "input": "1653 87 19", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 \n20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 \n39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 \n58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 \n77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 \n96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 \n115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 \n134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 1..." }, { "input": "15 2 8", "output": "1 2 3 4 5 6 7 8 \n10 9 12 11 14 13 0 15 " }, { "input": "1459 17 86", "output": "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 \n88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 138 137 140 139 142 141 144 143 146 145 148 147 150 149 152 151 154 153 1..." }, { "input": "3035 40 76", "output": "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 \n78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 138 137 140 139 142 141 144 143 146 145 148 147 150 149 152 151 \n153 154..." }, { "input": "3095 50 62", "output": "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 \n64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 \n125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..." }, { "input": "3055 65 47", "output": "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 \n48 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 \n95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 \n142 143 144 145 146 147 148 149 150 151 152 153 1..." }, { "input": "2638 80 33", "output": "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 \n34 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 \n67 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 \n100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 \n133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153..." }, { "input": "29 3 11", "output": "1 2 3 4 5 6 7 8 9 10 11 \n12 13 14 15 16 17 18 19 20 21 22 \n23 24 25 26 27 28 29 0 0 0 0 " }, { "input": "16 18 1", "output": "1 \n2 \n3 \n4 \n5 \n6 \n7 \n8 \n9 \n10 \n11 \n12 \n13 \n14 \n15 \n16 \n0 \n0 " }, { "input": "2240 27 83", "output": "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 \n84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1..." }, { "input": "1264 55 23", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 \n24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 \n47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 \n70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 \n93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 \n116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 \n139 140 141 142 143 144 145 146 147 148 149 150 151 152..." }, { "input": "5400 75 72", "output": "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 \n74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 138 137 140 139 142 141 144 143 \n145 146 147 148 149 150 151 152 153 154..." }, { "input": "46 3 16", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 \n18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 \n33 34 35 36 37 38 39 40 41 42 43 44 45 46 0 0 " }, { "input": "1512 27 56", "output": "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 \n58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 \n113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..." }, { "input": "4206 86 12", "output": "-1" }, { "input": "2358 14 56", "output": "-1" }, { "input": "5420 35 96", "output": "-1" }, { "input": "7758 63 41", "output": "-1" }, { "input": "9806 87 93", "output": "-1" }, { "input": "99 1 97", "output": "-1" }, { "input": "1053 25 42", "output": "-1" }, { "input": "4217 49 86", "output": "-1" }, { "input": "2312 77 30", "output": "-1" }, { "input": "74 1 71", "output": "-1" }, { "input": "1 99 100", "output": "1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \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 \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..." }, { "input": "1 57 99", "output": "1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \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 \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..." }, { "input": "4785 55 87", "output": "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 \n88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1..." }, { "input": "4611 53 87", "output": "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 \n88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1..." }, { "input": "9801 99 99", "output": "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 \n100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1..." }, { "input": "8096 92 88", "output": "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 \n90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 138 137 140 139 142 141 144 143 146 145 148 147 150 149 152 151 154 153 1..." }, { "input": "5916 68 87", "output": "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 \n88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1..." }, { "input": "8928 93 96", "output": "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 \n98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 138 137 140 139 142 141 144 143 146 145 148 147 150 149 152 151 154 153 1..." }, { "input": "7743 89 87", "output": "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 \n88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1..." }, { "input": "3128 46 68", "output": "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 \n70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 \n137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..." }, { "input": "3800 40 95", "output": "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 \n96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1..." }, { "input": "5368 61 88", "output": "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 \n90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 138 137 140 139 142 141 144 143 146 145 148 147 150 149 152 151 154 153 1..." }, { "input": "2583 41 63", "output": "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 \n64 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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 \n127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..." }, { "input": "4056 52 78", "output": "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 \n80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 138 137 140 139 142 141 144 143 146 145 148 147 150 149 152 151 154 153 1..." }, { "input": "3822 42 91", "output": "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 \n92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1..." }, { "input": "5358 57 94", "output": "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 \n96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 138 137 140 139 142 141 144 143 146 145 148 147 150 149 152 151 154 153 1..." }, { "input": "2961 47 63", "output": "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 \n64 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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 \n127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..." } ]
1,458,229,134
110,334
Python 3
OK
TESTS
85
78
716,800
n, a, b = map(int, (input().split())) if n > (a * b): print(-1) else: for i in range(a): if (b % 2 == 0) and ((i + 1) % 2 == 0): for c in range(b * (i + 1), b * (i + 1) - b, -1): if c <= n: print(c, end='\t') else: print(0, end='\t') else: for c in range((b * (i + 1) - b) + 1, b * (i + 1) + 1): if c <= n: print(c, end='\t') else: print(0, end='\t') print() # n, a, b = map(int, (input().split())) # if n > (a * b): # print(-1) # else: # c = 0 # for i in range(a): # if (b % 2 == 0) and (i % 2 == 1): # c += b + 1 # for _ in range(b): # if b % 2 == 0 and (i % 2 == 1): # c -= 1 # else: # c += 1 # if c <= n: # print(c, end='\t') # else: # print(0, end='\t') # print() # if (b % 2 == 0) and (i % 2 == 1): # c += b - 1
Title: Parliament of Berland Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* parliamentarians in Berland. They are numbered with integers from 1 to *n*. It happened that all parliamentarians with odd indices are Democrats and all parliamentarians with even indices are Republicans. New parliament assembly hall is a rectangle consisting of *a*<=×<=*b* chairs — *a* rows of *b* chairs each. Two chairs are considered neighbouring if they share as side. For example, chair number 5 in row number 2 is neighbouring to chairs number 4 and 6 in this row and chairs with number 5 in rows 1 and 3. Thus, chairs have four neighbours in general, except for the chairs on the border of the hall We know that if two parliamentarians from one political party (that is two Democrats or two Republicans) seat nearby they spent all time discussing internal party issues. Write the program that given the number of parliamentarians and the sizes of the hall determine if there is a way to find a seat for any parliamentarian, such that no two members of the same party share neighbouring seats. Input Specification: The first line of the input contains three integers *n*, *a* and *b* (1<=≤<=*n*<=≤<=10<=000, 1<=≤<=*a*,<=*b*<=≤<=100) — the number of parliamentarians, the number of rows in the assembly hall and the number of seats in each row, respectively. Output Specification: If there is no way to assigns seats to parliamentarians in a proper way print -1. Otherwise print the solution in *a* lines, each containing *b* integers. The *j*-th integer of the *i*-th line should be equal to the index of parliamentarian occupying this seat, or 0 if this seat should remain empty. If there are multiple possible solution, you may print any of them. Demo Input: ['3 2 2\n', '8 4 3\n', '10 2 2\n'] Demo Output: ['0 3\n1 2\n', '7 8 3\n0 1 4\n6 0 5\n0 2 0\n', '-1\n'] Note: In the first sample there are many other possible solutions. For example, and The following assignment is incorrect, because parliamentarians 1 and 3 are both from Democrats party but will occupy neighbouring seats.
```python n, a, b = map(int, (input().split())) if n > (a * b): print(-1) else: for i in range(a): if (b % 2 == 0) and ((i + 1) % 2 == 0): for c in range(b * (i + 1), b * (i + 1) - b, -1): if c <= n: print(c, end='\t') else: print(0, end='\t') else: for c in range((b * (i + 1) - b) + 1, b * (i + 1) + 1): if c <= n: print(c, end='\t') else: print(0, end='\t') print() # n, a, b = map(int, (input().split())) # if n > (a * b): # print(-1) # else: # c = 0 # for i in range(a): # if (b % 2 == 0) and (i % 2 == 1): # c += b + 1 # for _ in range(b): # if b % 2 == 0 and (i % 2 == 1): # c -= 1 # else: # c += 1 # if c <= n: # print(c, end='\t') # else: # print(0, end='\t') # print() # if (b % 2 == 0) and (i % 2 == 1): # c += b - 1 ```
3
50
A
Domino piling
PROGRAMMING
800
[ "greedy", "math" ]
A. Domino piling
2
256
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions: 1. Each domino completely covers two squares. 2. No two dominoes overlap. 3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board. Find the maximum number of dominoes, which can be placed under these restrictions.
In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16).
Output one number — the maximal number of dominoes, which can be placed.
[ "2 4\n", "3 3\n" ]
[ "4\n", "4\n" ]
none
500
[ { "input": "2 4", "output": "4" }, { "input": "3 3", "output": "4" }, { "input": "1 5", "output": "2" }, { "input": "1 6", "output": "3" }, { "input": "1 15", "output": "7" }, { "input": "1 16", "output": "8" }, { "input": "2 5", "output": "5" }, { "input": "2 6", "output": "6" }, { "input": "2 7", "output": "7" }, { "input": "2 14", "output": "14" }, { "input": "2 15", "output": "15" }, { "input": "1 4", "output": "2" }, { "input": "2 16", "output": "16" }, { "input": "3 5", "output": "7" }, { "input": "3 6", "output": "9" }, { "input": "3 10", "output": "15" }, { "input": "3 14", "output": "21" }, { "input": "3 15", "output": "22" }, { "input": "3 16", "output": "24" }, { "input": "5 7", "output": "17" }, { "input": "16 16", "output": "128" }, { "input": "15 16", "output": "120" }, { "input": "2 3", "output": "3" }, { "input": "15 15", "output": "112" }, { "input": "14 16", "output": "112" }, { "input": "11 13", "output": "71" }, { "input": "5 16", "output": "40" }, { "input": "8 15", "output": "60" }, { "input": "2 2", "output": "2" }, { "input": "3 4", "output": "6" }, { "input": "4 4", "output": "8" }, { "input": "1 1", "output": "0" }, { "input": "1 2", "output": "1" }, { "input": "1 3", "output": "1" }, { "input": "14 15", "output": "105" } ]
1,670,193,021
2,147,483,647
Python 3
OK
TESTS
35
92
0
a,b = map(int,input().split()) if a*b < 2: print(0) elif (a*b)%2 == 0: print(int(a*b/2)) else: print(int((a*b - 1)/2))
Title: Domino piling Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions: 1. Each domino completely covers two squares. 2. No two dominoes overlap. 3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board. Find the maximum number of dominoes, which can be placed under these restrictions. Input Specification: In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). Output Specification: Output one number — the maximal number of dominoes, which can be placed. Demo Input: ['2 4\n', '3 3\n'] Demo Output: ['4\n', '4\n'] Note: none
```python a,b = map(int,input().split()) if a*b < 2: print(0) elif (a*b)%2 == 0: print(int(a*b/2)) else: print(int((a*b - 1)/2)) ```
3.977
678
A
Johny Likes Numbers
PROGRAMMING
800
[ "implementation", "math" ]
null
null
Johny likes numbers *n* and *k* very much. Now Johny wants to find the smallest integer *x* greater than *n*, so it is divisible by the number *k*.
The only line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=109).
Print the smallest integer *x*<=&gt;<=*n*, so it is divisible by the number *k*.
[ "5 3\n", "25 13\n", "26 13\n" ]
[ "6\n", "26\n", "39\n" ]
none
0
[ { "input": "5 3", "output": "6" }, { "input": "25 13", "output": "26" }, { "input": "26 13", "output": "39" }, { "input": "1 1", "output": "2" }, { "input": "8 8", "output": "16" }, { "input": "14 15", "output": "15" }, { "input": "197 894", "output": "894" }, { "input": "6058 8581", "output": "8581" }, { "input": "97259 41764", "output": "125292" }, { "input": "453145 333625", "output": "667250" }, { "input": "2233224 4394826", "output": "4394826" }, { "input": "76770926 13350712", "output": "80104272" }, { "input": "687355301 142098087", "output": "710490435" }, { "input": "1000000000 999999999", "output": "1999999998" }, { "input": "1000000000 1000000000", "output": "2000000000" }, { "input": "999999999 1000000000", "output": "1000000000" }, { "input": "1000000000 1", "output": "1000000001" }, { "input": "1000000000 2", "output": "1000000002" }, { "input": "999999999 1", "output": "1000000000" }, { "input": "100000000 1", "output": "100000001" }, { "input": "999999999 500000000", "output": "1000000000" }, { "input": "999999990 10", "output": "1000000000" }, { "input": "1000000000 999999997", "output": "1999999994" }, { "input": "999999999 2", "output": "1000000000" }, { "input": "999999984 1", "output": "999999985" }, { "input": "999999983 1", "output": "999999984" }, { "input": "666666666 1", "output": "666666667" }, { "input": "1000000000 990000000", "output": "1980000000" }, { "input": "41 48", "output": "48" }, { "input": "123456 2", "output": "123458" }, { "input": "111 111", "output": "222" }, { "input": "878787 1", "output": "878788" }, { "input": "121 1", "output": "122" }, { "input": "114514 114514", "output": "229028" }, { "input": "500000001 1000000000", "output": "1000000000" }, { "input": "999999997 1", "output": "999999998" }, { "input": "100000000 10", "output": "100000010" } ]
1,644,754,991
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
13
78
0
n, k = map(int,input().split()) if n%k==1: print(n+1) elif n<k: print(k) elif n%k == 0: print(n+k) else: i = 2 n1 = 0 while True: if (k * i) % k == 0 and k * i > n: n1 = k * i break else: i+=1 print(n1)
Title: Johny Likes Numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Johny likes numbers *n* and *k* very much. Now Johny wants to find the smallest integer *x* greater than *n*, so it is divisible by the number *k*. Input Specification: The only line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=109). Output Specification: Print the smallest integer *x*<=&gt;<=*n*, so it is divisible by the number *k*. Demo Input: ['5 3\n', '25 13\n', '26 13\n'] Demo Output: ['6\n', '26\n', '39\n'] Note: none
```python n, k = map(int,input().split()) if n%k==1: print(n+1) elif n<k: print(k) elif n%k == 0: print(n+k) else: i = 2 n1 = 0 while True: if (k * i) % k == 0 and k * i > n: n1 = k * i break else: i+=1 print(n1) ```
0
158
A
Next Round
PROGRAMMING
800
[ "*special", "implementation" ]
null
null
"Contestant who earns a score equal to or greater than the *k*-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." — an excerpt from contest rules. A total of *n* participants took part in the contest (*n*<=≥<=*k*), and you already know their scores. Calculate how many participants will advance to the next round.
The first line of the input contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=50) separated by a single space. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=100), where *a**i* is the score earned by the participant who got the *i*-th place. The given sequence is non-increasing (that is, for all *i* from 1 to *n*<=-<=1 the following condition is fulfilled: *a**i*<=≥<=*a**i*<=+<=1).
Output the number of participants who advance to the next round.
[ "8 5\n10 9 8 7 7 7 5 5\n", "4 2\n0 0 0 0\n" ]
[ "6\n", "0\n" ]
In the first example the participant on the 5th place earned 7 points. As the participant on the 6th place also earned 7 points, there are 6 advancers. In the second example nobody got a positive score.
500
[ { "input": "8 5\n10 9 8 7 7 7 5 5", "output": "6" }, { "input": "4 2\n0 0 0 0", "output": "0" }, { "input": "5 1\n1 1 1 1 1", "output": "5" }, { "input": "5 5\n1 1 1 1 1", "output": "5" }, { "input": "1 1\n10", "output": "1" }, { "input": "17 14\n16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0", "output": "14" }, { "input": "5 5\n3 2 1 0 0", "output": "3" }, { "input": "8 6\n10 9 8 7 7 7 5 5", "output": "6" }, { "input": "8 7\n10 9 8 7 7 7 5 5", "output": "8" }, { "input": "8 4\n10 9 8 7 7 7 5 5", "output": "6" }, { "input": "8 3\n10 9 8 7 7 7 5 5", "output": "3" }, { "input": "8 1\n10 9 8 7 7 7 5 5", "output": "1" }, { "input": "8 2\n10 9 8 7 7 7 5 5", "output": "2" }, { "input": "1 1\n100", "output": "1" }, { "input": "1 1\n0", "output": "0" }, { "input": "50 25\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": "50 25\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "25" }, { "input": "50 25\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "26" }, { "input": "50 25\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "50" }, { "input": "11 5\n100 99 98 97 96 95 94 93 92 91 90", "output": "5" }, { "input": "10 4\n100 81 70 69 64 43 34 29 15 3", "output": "4" }, { "input": "11 6\n87 71 62 52 46 46 43 35 32 25 12", "output": "6" }, { "input": "17 12\n99 88 86 82 75 75 74 65 58 52 45 30 21 16 7 2 2", "output": "12" }, { "input": "20 3\n98 98 96 89 87 82 82 80 76 74 74 68 61 60 43 32 30 22 4 2", "output": "3" }, { "input": "36 12\n90 87 86 85 83 80 79 78 76 70 69 69 61 61 59 58 56 48 45 44 42 41 33 31 27 25 23 21 20 19 15 14 12 7 5 5", "output": "12" }, { "input": "49 8\n99 98 98 96 92 92 90 89 89 86 86 85 83 80 79 76 74 69 67 67 58 56 55 51 49 47 47 46 45 41 41 40 39 34 34 33 25 23 18 15 13 13 11 9 5 4 3 3 1", "output": "9" }, { "input": "49 29\n100 98 98 96 96 96 95 87 85 84 81 76 74 70 63 63 63 62 57 57 56 54 53 52 50 47 45 41 41 39 38 31 30 28 27 26 23 22 20 15 15 11 7 6 6 4 2 1 0", "output": "29" }, { "input": "49 34\n99 98 96 96 93 92 90 89 88 86 85 85 82 76 73 69 66 64 63 63 60 59 57 57 56 55 54 54 51 48 47 44 42 42 40 39 38 36 33 26 24 23 19 17 17 14 12 7 4", "output": "34" }, { "input": "50 44\n100 100 99 97 95 91 91 84 83 83 79 71 70 69 69 62 61 60 59 59 58 58 58 55 55 54 52 48 47 45 44 44 38 36 32 31 28 28 25 25 24 24 24 22 17 15 14 13 12 4", "output": "44" }, { "input": "50 13\n99 95 94 94 88 87 81 79 78 76 74 72 72 69 68 67 67 67 66 63 62 61 58 57 55 55 54 51 50 50 48 48 42 41 38 35 34 32 31 30 26 24 13 13 12 6 5 4 3 3", "output": "13" }, { "input": "50 30\n100 98 96 94 91 89 88 81 81 81 81 81 76 73 72 71 70 69 66 64 61 59 59 56 52 50 49 48 43 39 36 35 34 34 31 29 27 26 24 22 16 16 15 14 14 14 9 7 4 3", "output": "30" }, { "input": "2 1\n10 10", "output": "2" }, { "input": "2 2\n10 10", "output": "2" }, { "input": "2 2\n10 0", "output": "1" }, { "input": "2 2\n10 1", "output": "2" }, { "input": "2 1\n10 0", "output": "1" }, { "input": "2 1\n10 2", "output": "1" }, { "input": "50 13\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", "output": "0" }, { "input": "50 1\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", "output": "0" }, { "input": "50 50\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", "output": "0" }, { "input": "10 1\n5 5 5 3 3 3 0 0 0 0", "output": "3" }, { "input": "10 2\n5 5 5 3 3 3 0 0 0 0", "output": "3" }, { "input": "10 3\n5 5 5 3 3 3 0 0 0 0", "output": "3" }, { "input": "10 4\n5 5 5 3 3 3 0 0 0 0", "output": "6" }, { "input": "10 5\n5 5 5 3 3 3 0 0 0 0", "output": "6" }, { "input": "10 6\n5 5 5 3 3 3 0 0 0 0", "output": "6" }, { "input": "10 7\n5 5 5 3 3 3 0 0 0 0", "output": "6" }, { "input": "10 8\n5 5 5 3 3 3 0 0 0 0", "output": "6" }, { "input": "10 9\n5 5 5 3 3 3 0 0 0 0", "output": "6" }, { "input": "10 10\n5 5 5 3 3 3 0 0 0 0", "output": "6" } ]
1,696,671,251
2,147,483,647
Python 3
OK
TESTS
50
92
0
n_k = input().split() n_k = [int(n_k[i]) for i in range(len(n_k))] points = input().split() points = [int(points[i]) for i in range(len(points))] for winner in range(n_k[1]): max_ = max(points) if max_ == 0:break for i in range(points.count(max_)): points.remove(max_) if n_k[0] - len(points) >= n_k[1]: break print(n_k[0] - len(points))
Title: Next Round Time Limit: None seconds Memory Limit: None megabytes Problem Description: "Contestant who earns a score equal to or greater than the *k*-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." — an excerpt from contest rules. A total of *n* participants took part in the contest (*n*<=≥<=*k*), and you already know their scores. Calculate how many participants will advance to the next round. Input Specification: The first line of the input contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=50) separated by a single space. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=100), where *a**i* is the score earned by the participant who got the *i*-th place. The given sequence is non-increasing (that is, for all *i* from 1 to *n*<=-<=1 the following condition is fulfilled: *a**i*<=≥<=*a**i*<=+<=1). Output Specification: Output the number of participants who advance to the next round. Demo Input: ['8 5\n10 9 8 7 7 7 5 5\n', '4 2\n0 0 0 0\n'] Demo Output: ['6\n', '0\n'] Note: In the first example the participant on the 5th place earned 7 points. As the participant on the 6th place also earned 7 points, there are 6 advancers. In the second example nobody got a positive score.
```python n_k = input().split() n_k = [int(n_k[i]) for i in range(len(n_k))] points = input().split() points = [int(points[i]) for i in range(len(points))] for winner in range(n_k[1]): max_ = max(points) if max_ == 0:break for i in range(points.count(max_)): points.remove(max_) if n_k[0] - len(points) >= n_k[1]: break print(n_k[0] - len(points)) ```
3
999
C
Alphabetic Removals
PROGRAMMING
1,200
[ "implementation" ]
null
null
You are given a string $s$ consisting of $n$ lowercase Latin letters. Polycarp wants to remove exactly $k$ characters ($k \le n$) from the string $s$. Polycarp uses the following algorithm $k$ times: - if there is at least one letter 'a', remove the leftmost occurrence and stop the algorithm, otherwise go to next item; - if there is at least one letter 'b', remove the leftmost occurrence and stop the algorithm, otherwise go to next item; - ... - remove the leftmost occurrence of the letter 'z' and stop the algorithm. This algorithm removes a single letter from the string. Polycarp performs this algorithm exactly $k$ times, thus removing exactly $k$ characters. Help Polycarp find the resulting string.
The first line of input contains two integers $n$ and $k$ ($1 \le k \le n \le 4 \cdot 10^5$) — the length of the string and the number of letters Polycarp will remove. The second line contains the string $s$ consisting of $n$ lowercase Latin letters.
Print the string that will be obtained from $s$ after Polycarp removes exactly $k$ letters using the above algorithm $k$ times. If the resulting string is empty, print nothing. It is allowed to print nothing or an empty line (line break).
[ "15 3\ncccaabababaccbc\n", "15 9\ncccaabababaccbc\n", "1 1\nu\n" ]
[ "cccbbabaccbc\n", "cccccc\n", "" ]
none
0
[ { "input": "15 3\ncccaabababaccbc", "output": "cccbbabaccbc" }, { "input": "15 9\ncccaabababaccbc", "output": "cccccc" }, { "input": "5 2\nzyzyx", "output": "zzy" }, { "input": "4 3\nhack", "output": "k" }, { "input": "4 3\nzzzz", "output": "z" }, { "input": "6 5\naaccdd", "output": "d" }, { "input": "2 1\nzz", "output": "z" }, { "input": "14 5\nhxehmvkybeklnj", "output": "xmvkyklnj" } ]
1,622,708,508
2,147,483,647
Python 3
OK
TESTS
44
124
1,228,800
al="abcdefghijklmnopqrstuvwxyz" n,k=[int(x)for x in input().rstrip().split()] a=input() for i in al: c=a.count(i) a=a.replace(i,"",min(c,k)) k-=c if k<1: break print(a)
Title: Alphabetic Removals Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a string $s$ consisting of $n$ lowercase Latin letters. Polycarp wants to remove exactly $k$ characters ($k \le n$) from the string $s$. Polycarp uses the following algorithm $k$ times: - if there is at least one letter 'a', remove the leftmost occurrence and stop the algorithm, otherwise go to next item; - if there is at least one letter 'b', remove the leftmost occurrence and stop the algorithm, otherwise go to next item; - ... - remove the leftmost occurrence of the letter 'z' and stop the algorithm. This algorithm removes a single letter from the string. Polycarp performs this algorithm exactly $k$ times, thus removing exactly $k$ characters. Help Polycarp find the resulting string. Input Specification: The first line of input contains two integers $n$ and $k$ ($1 \le k \le n \le 4 \cdot 10^5$) — the length of the string and the number of letters Polycarp will remove. The second line contains the string $s$ consisting of $n$ lowercase Latin letters. Output Specification: Print the string that will be obtained from $s$ after Polycarp removes exactly $k$ letters using the above algorithm $k$ times. If the resulting string is empty, print nothing. It is allowed to print nothing or an empty line (line break). Demo Input: ['15 3\ncccaabababaccbc\n', '15 9\ncccaabababaccbc\n', '1 1\nu\n'] Demo Output: ['cccbbabaccbc\n', 'cccccc\n', ''] Note: none
```python al="abcdefghijklmnopqrstuvwxyz" n,k=[int(x)for x in input().rstrip().split()] a=input() for i in al: c=a.count(i) a=a.replace(i,"",min(c,k)) k-=c if k<1: break print(a) ```
3
898
A
Rounding
PROGRAMMING
800
[ "implementation", "math" ]
null
null
Vasya has a non-negative integer *n*. He wants to round it to nearest integer, which ends up with 0. If *n* already ends up with 0, Vasya considers it already rounded. For example, if *n*<==<=4722 answer is 4720. If *n*<==<=5 Vasya can round it to 0 or to 10. Both ways are correct. For given *n* find out to which integer will Vasya round it.
The first line contains single integer *n* (0<=≤<=*n*<=≤<=109) — number that Vasya has.
Print result of rounding *n*. Pay attention that in some cases answer isn't unique. In that case print any correct answer.
[ "5\n", "113\n", "1000000000\n", "5432359\n" ]
[ "0\n", "110\n", "1000000000\n", "5432360\n" ]
In the first example *n* = 5. Nearest integers, that ends up with zero are 0 and 10. Any of these answers is correct, so you can print 0 or 10.
500
[ { "input": "5", "output": "0" }, { "input": "113", "output": "110" }, { "input": "1000000000", "output": "1000000000" }, { "input": "5432359", "output": "5432360" }, { "input": "999999994", "output": "999999990" }, { "input": "10", "output": "10" }, { "input": "9", "output": "10" }, { "input": "1", "output": "0" }, { "input": "0", "output": "0" }, { "input": "3", "output": "0" }, { "input": "4", "output": "0" }, { "input": "6", "output": "10" }, { "input": "7", "output": "10" }, { "input": "8", "output": "10" }, { "input": "19", "output": "20" }, { "input": "100", "output": "100" }, { "input": "997", "output": "1000" }, { "input": "9994", "output": "9990" }, { "input": "10002", "output": "10000" }, { "input": "100000", "output": "100000" }, { "input": "99999", "output": "100000" }, { "input": "999999999", "output": "1000000000" }, { "input": "999999998", "output": "1000000000" }, { "input": "999999995", "output": "999999990" }, { "input": "999999990", "output": "999999990" }, { "input": "1000000", "output": "1000000" }, { "input": "1000010", "output": "1000010" }, { "input": "10000010", "output": "10000010" }, { "input": "100000011", "output": "100000010" }, { "input": "400000003", "output": "400000000" }, { "input": "234234", "output": "234230" }, { "input": "675621", "output": "675620" }, { "input": "43532", "output": "43530" }, { "input": "4576453", "output": "4576450" }, { "input": "65754674", "output": "65754670" }, { "input": "3245526", "output": "3245530" }, { "input": "123445", "output": "123440" }, { "input": "234217", "output": "234220" }, { "input": "23451218", "output": "23451220" }, { "input": "1231239", "output": "1231240" }, { "input": "1923140", "output": "1923140" }, { "input": "307910310", "output": "307910310" }, { "input": "780961030", "output": "780961030" }, { "input": "103509421", "output": "103509420" }, { "input": "576560141", "output": "576560140" }, { "input": "48851642", "output": "48851640" }, { "input": "226935072", "output": "226935070" }, { "input": "844450763", "output": "844450760" }, { "input": "22534183", "output": "22534180" }, { "input": "640049874", "output": "640049870" }, { "input": "818133304", "output": "818133300" }, { "input": "730616285", "output": "730616280" }, { "input": "613732415", "output": "613732410" }, { "input": "380991216", "output": "380991220" }, { "input": "559074636", "output": "559074640" }, { "input": "176590327", "output": "176590330" }, { "input": "354673757", "output": "354673760" }, { "input": "267156738", "output": "267156740" }, { "input": "150272868", "output": "150272870" }, { "input": "62755859", "output": "62755860" }, { "input": "945871979", "output": "945871980" }, { "input": "46", "output": "50" }, { "input": "999", "output": "1000" }, { "input": "1397", "output": "1400" } ]
1,611,873,164
164
PyPy 3
OK
TESTS
64
109
0
n = int(input()) q,r = divmod(n, 10) a = q*10 b = (q+1)*10 if n-a <= b-n: print(a) else: print(b)
Title: Rounding Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya has a non-negative integer *n*. He wants to round it to nearest integer, which ends up with 0. If *n* already ends up with 0, Vasya considers it already rounded. For example, if *n*<==<=4722 answer is 4720. If *n*<==<=5 Vasya can round it to 0 or to 10. Both ways are correct. For given *n* find out to which integer will Vasya round it. Input Specification: The first line contains single integer *n* (0<=≤<=*n*<=≤<=109) — number that Vasya has. Output Specification: Print result of rounding *n*. Pay attention that in some cases answer isn't unique. In that case print any correct answer. Demo Input: ['5\n', '113\n', '1000000000\n', '5432359\n'] Demo Output: ['0\n', '110\n', '1000000000\n', '5432360\n'] Note: In the first example *n* = 5. Nearest integers, that ends up with zero are 0 and 10. Any of these answers is correct, so you can print 0 or 10.
```python n = int(input()) q,r = divmod(n, 10) a = q*10 b = (q+1)*10 if n-a <= b-n: print(a) else: print(b) ```
3
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,695,304,331
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
62
0
if __name__ == '__main__': n = int(input()) a_b = [] p_in = [] count = [] for i in range(n): a_b.append(input().split()) for j in range(2): p_in.append(int(a_b[i][j])) for i in range(3,n,2): first = p_in[1] count.append(first) count.append(first) count.append(count[i - 3] + p_in[i] - p_in[i - 1]) count.append(count[i - 3] + p_in[i] - p_in[i - 1]) print(max(count))
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 if __name__ == '__main__': n = int(input()) a_b = [] p_in = [] count = [] for i in range(n): a_b.append(input().split()) for j in range(2): p_in.append(int(a_b[i][j])) for i in range(3,n,2): first = p_in[1] count.append(first) count.append(first) count.append(count[i - 3] + p_in[i] - p_in[i - 1]) count.append(count[i - 3] + p_in[i] - p_in[i - 1]) print(max(count)) ```
0
637
B
Chat Order
PROGRAMMING
1,200
[ "*special", "binary search", "constructive algorithms", "data structures", "sortings" ]
null
null
Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The relative order of the other chats doesn't change. If there was no chat with this friend before, then a new chat is simply inserted to the top of the list. Assuming that the chat list is initially empty, given the sequence of Polycaprus' messages make a list of chats after all of his messages are processed. Assume that no friend wrote any message to Polycarpus.
The first line contains integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of Polycarpus' messages. Next *n* lines enlist the message recipients in the order in which the messages were sent. The name of each participant is a non-empty sequence of lowercase English letters of length at most 10.
Print all the recipients to who Polycarp talked to in the order of chats with them, from top to bottom.
[ "4\nalex\nivan\nroman\nivan\n", "8\nalina\nmaria\nekaterina\ndarya\ndarya\nekaterina\nmaria\nalina\n" ]
[ "ivan\nroman\nalex\n", "alina\nmaria\nekaterina\ndarya\n" ]
In the first test case Polycarpus first writes to friend by name "alex", and the list looks as follows: 1. alex Then Polycarpus writes to friend by name "ivan" and the list looks as follows: 1. ivan 1. alex Polycarpus writes the third message to friend by name "roman" and the list looks as follows: 1. roman 1. ivan 1. alex Polycarpus writes the fourth message to friend by name "ivan", to who he has already sent a message, so the list of chats changes as follows: 1. ivan 1. roman 1. alex
1,000
[ { "input": "4\nalex\nivan\nroman\nivan", "output": "ivan\nroman\nalex" }, { "input": "8\nalina\nmaria\nekaterina\ndarya\ndarya\nekaterina\nmaria\nalina", "output": "alina\nmaria\nekaterina\ndarya" }, { "input": "1\nwdi", "output": "wdi" }, { "input": "2\nypg\nypg", "output": "ypg" }, { "input": "3\nexhll\nexhll\narruapexj", "output": "arruapexj\nexhll" }, { "input": "3\nfv\nle\nle", "output": "le\nfv" }, { "input": "8\nm\nm\nm\nm\nm\nm\nm\nm", "output": "m" }, { "input": "10\nr\nr\ni\nw\nk\nr\nb\nu\nu\nr", "output": "r\nu\nb\nk\nw\ni" }, { "input": "7\ne\nfau\ncmk\nnzs\nby\nwx\ntjmok", "output": "tjmok\nwx\nby\nnzs\ncmk\nfau\ne" }, { "input": "6\nklrj\nwe\nklrj\nwe\nwe\nwe", "output": "we\nklrj" }, { "input": "8\nzncybqmh\naeebef\nzncybqmh\nn\naeebef\nzncybqmh\nzncybqmh\nzncybqmh", "output": "zncybqmh\naeebef\nn" }, { "input": "30\nkqqcbs\nvap\nkymomn\nj\nkqqcbs\nfuzlzoum\nkymomn\ndbh\nfuzlzoum\nkymomn\nvap\nvlgzs\ndbh\nvlgzs\nbvy\ndbh\nkymomn\nkymomn\neoqql\nkymomn\nkymomn\nkqqcbs\nvlgzs\nkqqcbs\nkqqcbs\nfuzlzoum\nvlgzs\nrylgdoo\nvlgzs\nrylgdoo", "output": "rylgdoo\nvlgzs\nfuzlzoum\nkqqcbs\nkymomn\neoqql\ndbh\nbvy\nvap\nj" }, { "input": "40\nji\nv\nv\nns\nji\nn\nji\nv\nfvy\nvje\nns\nvje\nv\nhas\nv\nusm\nhas\nfvy\nvje\nkdb\nn\nv\nji\nji\nn\nhas\nv\nji\nkdb\nr\nvje\nns\nv\nusm\nn\nvje\nhas\nns\nhas\nn", "output": "n\nhas\nns\nvje\nusm\nv\nr\nkdb\nji\nfvy" }, { "input": "50\njcg\nvle\njopb\nepdb\nnkef\nfv\nxj\nufe\nfuy\noqta\ngbc\nyuz\nec\nyji\nkuux\ncwm\ntq\nnno\nhp\nzry\nxxpp\ntjvo\ngyz\nkwo\nvwqz\nyaqc\njnj\nwoav\nqcv\ndcu\ngc\nhovn\nop\nevy\ndc\ntrpu\nyb\nuzfa\npca\noq\nnhxy\nsiqu\nde\nhphy\nc\nwovu\nf\nbvv\ndsik\nlwyg", "output": "lwyg\ndsik\nbvv\nf\nwovu\nc\nhphy\nde\nsiqu\nnhxy\noq\npca\nuzfa\nyb\ntrpu\ndc\nevy\nop\nhovn\ngc\ndcu\nqcv\nwoav\njnj\nyaqc\nvwqz\nkwo\ngyz\ntjvo\nxxpp\nzry\nhp\nnno\ntq\ncwm\nkuux\nyji\nec\nyuz\ngbc\noqta\nfuy\nufe\nxj\nfv\nnkef\nepdb\njopb\nvle\njcg" }, { "input": "100\nvhh\nvhh\nvhh\nfa\nfa\nvhh\nvhh\nvhh\nfa\nfa\nfa\nvhh\nfa\nvhh\nvhh\nvhh\nfa\nvhh\nvhh\nfa\nfa\nfa\nfa\nfa\nfa\nvhh\nfa\nfa\nvhh\nvhh\nvhh\nfa\nfa\nfa\nvhh\nfa\nvhh\nfa\nvhh\nvhh\nfa\nvhh\nfa\nvhh\nvhh\nvhh\nfa\nvhh\nfa\nfa\nvhh\nfa\nvhh\nvhh\nvhh\nvhh\nfa\nvhh\nvhh\nvhh\nvhh\nfa\nvhh\nvhh\nvhh\nvhh\nvhh\nfa\nvhh\nvhh\nfa\nfa\nfa\nvhh\nfa\nfa\nvhh\nfa\nvhh\nfa\nfa\nfa\nfa\nfa\nfa\nvhh\nvhh\nfa\nvhh\nfa\nfa\nvhh\nfa\nfa\nvhh\nfa\nvhh\nvhh\nfa\nvhh", "output": "vhh\nfa" }, { "input": "2\naa\nbb", "output": "bb\naa" }, { "input": "2\naa\na", "output": "a\naa" }, { "input": "3\naa\naa\naa", "output": "aa" }, { "input": "5\naa\na\naa\na\naa", "output": "aa\na" }, { "input": "7\naaaa\naaaa\naaa\na\naa\naaaaaaa\naaa", "output": "aaa\naaaaaaa\naa\na\naaaa" }, { "input": "5\na\naa\naaa\naaaa\na", "output": "a\naaaa\naaa\naa" }, { "input": "12\naaaaa\naaaaaa\naaaa\naaaaaa\naa\naaaa\naaaa\naaaaaa\na\naaa\naaaaaaaa\naa", "output": "aa\naaaaaaaa\naaa\na\naaaaaa\naaaa\naaaaa" }, { "input": "3\na\naa\naaa", "output": "aaa\naa\na" }, { "input": "9\nzzz\nzzzzz\nzzz\nzzzz\nzz\nzzzz\nzzzzz\nzzzz\nzzzzzzz", "output": "zzzzzzz\nzzzz\nzzzzz\nzz\nzzz" } ]
1,694,280,754
2,147,483,647
PyPy 3-64
OK
TESTS
95
1,357
31,846,400
x = [] s = set() n = int(input()) for g in range(0,n): i = input() x.append(i) for d in x[::-1]: if d not in s: print(d) s.add(d)
Title: Chat Order Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The relative order of the other chats doesn't change. If there was no chat with this friend before, then a new chat is simply inserted to the top of the list. Assuming that the chat list is initially empty, given the sequence of Polycaprus' messages make a list of chats after all of his messages are processed. Assume that no friend wrote any message to Polycarpus. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of Polycarpus' messages. Next *n* lines enlist the message recipients in the order in which the messages were sent. The name of each participant is a non-empty sequence of lowercase English letters of length at most 10. Output Specification: Print all the recipients to who Polycarp talked to in the order of chats with them, from top to bottom. Demo Input: ['4\nalex\nivan\nroman\nivan\n', '8\nalina\nmaria\nekaterina\ndarya\ndarya\nekaterina\nmaria\nalina\n'] Demo Output: ['ivan\nroman\nalex\n', 'alina\nmaria\nekaterina\ndarya\n'] Note: In the first test case Polycarpus first writes to friend by name "alex", and the list looks as follows: 1. alex Then Polycarpus writes to friend by name "ivan" and the list looks as follows: 1. ivan 1. alex Polycarpus writes the third message to friend by name "roman" and the list looks as follows: 1. roman 1. ivan 1. alex Polycarpus writes the fourth message to friend by name "ivan", to who he has already sent a message, so the list of chats changes as follows: 1. ivan 1. roman 1. alex
```python x = [] s = set() n = int(input()) for g in range(0,n): i = input() x.append(i) for d in x[::-1]: if d not in s: print(d) s.add(d) ```
3