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
699
A
Launch of Collider
PROGRAMMING
1,000
[ "implementation" ]
null
null
There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. *n* particles will be launched inside it. All of them are located in a straight line and there can not be two or more particles located in the same point. The coordinates of the particles coincide with the distance in meters from the center of the collider, *x**i* is the coordinate of the *i*-th particle and its position in the collider at the same time. All coordinates of particle positions are even integers. You know the direction of each particle movement — it will move to the right or to the left after the collider's launch start. All particles begin to move simultaneously at the time of the collider's launch start. Each particle will move straight to the left or straight to the right with the constant speed of 1 meter per microsecond. The collider is big enough so particles can not leave it in the foreseeable time. Write the program which finds the moment of the first collision of any two particles of the collider. In other words, find the number of microseconds before the first moment when any two particles are at the same point.
The first line contains the positive integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of particles. The second line contains *n* symbols "L" and "R". If the *i*-th symbol equals "L", then the *i*-th particle will move to the left, otherwise the *i*-th symbol equals "R" and the *i*-th particle will move to the right. The third line contains the sequence of pairwise distinct even integers *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x**i*<=≤<=109) — the coordinates of particles in the order from the left to the right. It is guaranteed that the coordinates of particles are given in the increasing order.
In the first line print the only integer — the first moment (in microseconds) when two particles are at the same point and there will be an explosion. Print the only integer -1, if the collision of particles doesn't happen.
[ "4\nRLRL\n2 4 6 10\n", "3\nLLR\n40 50 60\n" ]
[ "1\n", "-1\n" ]
In the first sample case the first explosion will happen in 1 microsecond because the particles number 1 and 2 will simultaneously be at the same point with the coordinate 3. In the second sample case there will be no explosion because there are no particles which will simultaneously be at the same point.
500
[ { "input": "4\nRLRL\n2 4 6 10", "output": "1" }, { "input": "3\nLLR\n40 50 60", "output": "-1" }, { "input": "4\nRLLR\n46 230 264 470", "output": "92" }, { "input": "6\nLLRLLL\n446 492 650 844 930 970", "output": "97" }, { "input": "8\nRRLLLLLL\n338 478 512 574 594 622 834 922", "output": "17" }, { "input": "10\nLRLRLLRRLR\n82 268 430 598 604 658 670 788 838 1000", "output": "3" }, { "input": "2\nRL\n0 1000000000", "output": "500000000" }, { "input": "12\nLRLLRRRRLRLL\n254 1260 1476 1768 2924 4126 4150 4602 5578 7142 8134 9082", "output": "108" }, { "input": "14\nRLLRRLRLLRLLLR\n698 2900 3476 3724 3772 3948 4320 4798 5680 6578 7754 8034 8300 8418", "output": "88" }, { "input": "16\nRRLLLRLRLLLLRLLR\n222 306 968 1060 1636 1782 2314 2710 3728 4608 5088 6790 6910 7156 7418 7668", "output": "123" }, { "input": "18\nRLRLLRRRLLLRLRRLRL\n1692 2028 2966 3008 3632 4890 5124 5838 6596 6598 6890 8294 8314 8752 8868 9396 9616 9808", "output": "10" }, { "input": "20\nRLLLLLLLRRRRLRRLRRLR\n380 902 1400 1834 2180 2366 2562 2596 2702 2816 3222 3238 3742 5434 6480 7220 7410 8752 9708 9970", "output": "252" }, { "input": "22\nLRRRRRRRRRRRLLRRRRRLRL\n1790 2150 2178 2456 2736 3282 3622 4114 4490 4772 5204 5240 5720 5840 5910 5912 6586 7920 8584 9404 9734 9830", "output": "48" }, { "input": "24\nLLRLRRLLRLRRRRLLRRLRLRRL\n100 360 864 1078 1360 1384 1438 2320 2618 3074 3874 3916 3964 5178 5578 6278 6630 6992 8648 8738 8922 8930 9276 9720", "output": "27" }, { "input": "26\nRLLLLLLLRLRRLRLRLRLRLLLRRR\n908 1826 2472 2474 2728 3654 3716 3718 3810 3928 4058 4418 4700 5024 5768 6006 6128 6386 6968 7040 7452 7774 7822 8726 9338 9402", "output": "59" }, { "input": "28\nRRLRLRRRRRRLLLRRLRRLLLRRLLLR\n156 172 1120 1362 2512 3326 3718 4804 4990 5810 6242 6756 6812 6890 6974 7014 7088 7724 8136 8596 8770 8840 9244 9250 9270 9372 9400 9626", "output": "10" }, { "input": "30\nRLLRLRLLRRRLRRRLLLLLLRRRLRRLRL\n128 610 1680 2436 2896 2994 3008 3358 3392 4020 4298 4582 4712 4728 5136 5900 6088 6232 6282 6858 6934 7186 7224 7256 7614 8802 8872 9170 9384 9794", "output": "7" }, { "input": "10\nLLLLRRRRRR\n0 2 4 6 8 10 12 14 16 18", "output": "-1" }, { "input": "5\nLLLLL\n0 10 20 30 40", "output": "-1" }, { "input": "6\nRRRRRR\n40 50 60 70 80 100", "output": "-1" }, { "input": "1\nR\n0", "output": "-1" }, { "input": "2\nRL\n2 1000000000", "output": "499999999" }, { "input": "2\nRL\n0 400000", "output": "200000" }, { "input": "2\nRL\n0 200002", "output": "100001" }, { "input": "2\nRL\n2 20000000", "output": "9999999" }, { "input": "4\nLLRL\n2 4 10 100", "output": "45" }, { "input": "4\nRLRL\n2 10 12 14", "output": "1" }, { "input": "2\nRL\n0 100000000", "output": "50000000" }, { "input": "2\nRL\n2 600002", "output": "300000" }, { "input": "1\nL\n0", "output": "-1" }, { "input": "2\nRL\n0 600000", "output": "300000" }, { "input": "5\nRRRRR\n0 2 4 6 8", "output": "-1" }, { "input": "2\nRL\n2 200000000", "output": "99999999" }, { "input": "2\nRL\n0 267382766", "output": "133691383" }, { "input": "3\nRRL\n4 8 999999998", "output": "499999995" }, { "input": "2\nRL\n0 2", "output": "1" }, { "input": "2\nRL\n2 400002", "output": "200000" }, { "input": "2\nLL\n2 4", "output": "-1" }, { "input": "2\nLL\n0 2", "output": "-1" }, { "input": "2\nRL\n0 100000", "output": "50000" }, { "input": "2\nRL\n2 200000020", "output": "100000009" }, { "input": "2\nRL\n2000000 4000000", "output": "1000000" }, { "input": "2\nRL\n0 199998", "output": "99999" }, { "input": "3\nLRR\n40 50 60", "output": "-1" }, { "input": "2\nRL\n200 400400", "output": "200100" }, { "input": "2\nRL\n2 400004", "output": "200001" }, { "input": "2\nRL\n0 200000000", "output": "100000000" } ]
1,514,758,681
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
62
5,632,000
n = int(input()) dirct = input() cord = list(map(int, input().split())) ans = [cord[i] - cord[i + 1] for i in range(n-1) if dirct[i] == 'R' and dirct[i+1] == 'L'] print(ans//2) if ans > 0 else print(-1)
Title: Launch of Collider Time Limit: None seconds Memory Limit: None megabytes Problem Description: There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. *n* particles will be launched inside it. All of them are located in a straight line and there can not be two or more particles located in the same point. The coordinates of the particles coincide with the distance in meters from the center of the collider, *x**i* is the coordinate of the *i*-th particle and its position in the collider at the same time. All coordinates of particle positions are even integers. You know the direction of each particle movement — it will move to the right or to the left after the collider's launch start. All particles begin to move simultaneously at the time of the collider's launch start. Each particle will move straight to the left or straight to the right with the constant speed of 1 meter per microsecond. The collider is big enough so particles can not leave it in the foreseeable time. Write the program which finds the moment of the first collision of any two particles of the collider. In other words, find the number of microseconds before the first moment when any two particles are at the same point. Input Specification: The first line contains the positive integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of particles. The second line contains *n* symbols "L" and "R". If the *i*-th symbol equals "L", then the *i*-th particle will move to the left, otherwise the *i*-th symbol equals "R" and the *i*-th particle will move to the right. The third line contains the sequence of pairwise distinct even integers *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x**i*<=≤<=109) — the coordinates of particles in the order from the left to the right. It is guaranteed that the coordinates of particles are given in the increasing order. Output Specification: In the first line print the only integer — the first moment (in microseconds) when two particles are at the same point and there will be an explosion. Print the only integer -1, if the collision of particles doesn't happen. Demo Input: ['4\nRLRL\n2 4 6 10\n', '3\nLLR\n40 50 60\n'] Demo Output: ['1\n', '-1\n'] Note: In the first sample case the first explosion will happen in 1 microsecond because the particles number 1 and 2 will simultaneously be at the same point with the coordinate 3. In the second sample case there will be no explosion because there are no particles which will simultaneously be at the same point.
```python n = int(input()) dirct = input() cord = list(map(int, input().split())) ans = [cord[i] - cord[i + 1] for i in range(n-1) if dirct[i] == 'R' and dirct[i+1] == 'L'] print(ans//2) if ans > 0 else print(-1) ```
-1
381
A
Sereja and Dima
PROGRAMMING
800
[ "greedy", "implementation", "two pointers" ]
null
null
Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. The game ends when there is no more cards. The player who has the maximum sum of numbers on his cards by the end of the game, wins. Sereja and Dima are being greedy. Each of them chooses the card with the larger number during his move. Inna is a friend of Sereja and Dima. She knows which strategy the guys are using, so she wants to determine the final score, given the initial state of the game. Help her.
The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000.
On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game.
[ "4\n4 1 2 10\n", "7\n1 2 3 4 5 6 7\n" ]
[ "12 5\n", "16 12\n" ]
In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5.
500
[ { "input": "4\n4 1 2 10", "output": "12 5" }, { "input": "7\n1 2 3 4 5 6 7", "output": "16 12" }, { "input": "42\n15 29 37 22 16 5 26 31 6 32 19 3 45 36 33 14 25 20 48 7 42 11 24 28 9 18 8 21 47 17 38 40 44 4 35 1 43 39 41 27 12 13", "output": "613 418" }, { "input": "43\n32 1 15 48 38 26 25 14 20 44 11 30 3 42 49 19 18 46 5 45 10 23 34 9 29 41 2 52 6 17 35 4 50 22 33 51 7 28 47 13 39 37 24", "output": "644 500" }, { "input": "1\n3", "output": "3 0" }, { "input": "45\n553 40 94 225 415 471 126 190 647 394 515 303 189 159 308 6 139 132 326 78 455 75 85 295 135 613 360 614 351 228 578 259 258 591 444 29 33 463 561 174 368 183 140 168 646", "output": "6848 6568" }, { "input": "44\n849 373 112 307 479 608 856 769 526 82 168 143 573 762 115 501 688 36 214 450 396 496 236 309 287 786 397 43 811 141 745 846 350 270 276 677 420 459 403 722 267 54 394 727", "output": "9562 9561" }, { "input": "35\n10 15 18 1 28 16 2 33 6 22 23 4 9 25 35 8 7 26 3 20 30 14 31 19 27 32 11 5 29 24 21 34 13 17 12", "output": "315 315" }, { "input": "17\n580 376 191 496 73 44 520 357 483 149 81 178 514 300 216 598 304", "output": "3238 2222" }, { "input": "30\n334 443 223 424 168 549 189 303 429 559 516 220 459 134 344 346 316 446 209 148 487 526 69 286 102 366 518 280 392 325", "output": "5246 4864" }, { "input": "95\n122 29 188 265 292 287 183 225 222 187 155 256 64 148 173 278 218 136 290 17 31 130 2 87 57 283 255 280 68 166 174 142 102 39 116 206 288 154 26 78 296 172 184 232 77 91 277 8 249 186 94 93 207 251 257 195 101 299 193 124 293 65 58 35 24 302 220 189 252 125 27 284 247 182 141 103 198 97 234 83 281 216 85 180 267 236 109 143 149 239 79 300 191 244 71", "output": "8147 7807" }, { "input": "1\n1", "output": "1 0" } ]
1,692,369,454
2,147,483,647
Python 3
OK
TESTS
34
46
0
n = int(input()) a = list(map(int, input().split())) l, r = 0, len(a) - 1 d = 0 s = [0, 0] while l <= r: if a[l] > a[r]: s[d] += a[l] l += 1 else: s[d] += a[r] r -= 1 d = 1 - d print(s[0], s[1])
Title: Sereja and Dima Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. The game ends when there is no more cards. The player who has the maximum sum of numbers on his cards by the end of the game, wins. Sereja and Dima are being greedy. Each of them chooses the card with the larger number during his move. Inna is a friend of Sereja and Dima. She knows which strategy the guys are using, so she wants to determine the final score, given the initial state of the game. Help her. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000. Output Specification: On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game. Demo Input: ['4\n4 1 2 10\n', '7\n1 2 3 4 5 6 7\n'] Demo Output: ['12 5\n', '16 12\n'] Note: In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5.
```python n = int(input()) a = list(map(int, input().split())) l, r = 0, len(a) - 1 d = 0 s = [0, 0] while l <= r: if a[l] > a[r]: s[d] += a[l] l += 1 else: s[d] += a[r] r -= 1 d = 1 - d print(s[0], s[1]) ```
3
742
A
Arpa’s hard exam and Mehrdad’s naive cheat
PROGRAMMING
1,000
[ "implementation", "math", "number theory" ]
null
null
There exists an island called Arpa’s land, some beautiful girls live there, as ugly ones do. Mehrdad wants to become minister of Arpa’s land. Arpa has prepared an exam. Exam has only one question, given *n*, print the last digit of 1378*n*. Mehrdad has become quite confused and wants you to help him. Please help, although it's a naive cheat.
The single line of input contains one integer *n* (0<=<=≤<=<=*n*<=<=≤<=<=109).
Print single integer — the last digit of 1378*n*.
[ "1\n", "2\n" ]
[ "8", "4" ]
In the first example, last digit of 1378<sup class="upper-index">1</sup> = 1378 is 8. In the second example, last digit of 1378<sup class="upper-index">2</sup> = 1378·1378 = 1898884 is 4.
500
[ { "input": "1", "output": "8" }, { "input": "2", "output": "4" }, { "input": "1000", "output": "6" }, { "input": "3", "output": "2" }, { "input": "4", "output": "6" }, { "input": "1000000000", "output": "6" }, { "input": "5", "output": "8" }, { "input": "6", "output": "4" }, { "input": "999999999", "output": "2" }, { "input": "1378", "output": "4" }, { "input": "13781378", "output": "4" }, { "input": "51202278", "output": "4" }, { "input": "999999998", "output": "4" }, { "input": "999999997", "output": "8" }, { "input": "12193721", "output": "8" }, { "input": "0", "output": "1" }, { "input": "989898989", "output": "8" }, { "input": "7", "output": "2" }, { "input": "8", "output": "6" }, { "input": "9", "output": "8" }, { "input": "10", "output": "4" }, { "input": "11", "output": "2" }, { "input": "12", "output": "6" }, { "input": "13", "output": "8" }, { "input": "14", "output": "4" }, { "input": "15", "output": "2" }, { "input": "16", "output": "6" }, { "input": "999999996", "output": "6" }, { "input": "999999995", "output": "2" }, { "input": "999999994", "output": "4" } ]
1,650,383,535
2,147,483,647
Python 3
OK
TESTS
30
31
0
base = 8 power = int(input()) result = 1 while power !=0: if power% 2==1: power = power - 1 result = (result * base)%10 if power%2 ==0: base = (base*base)%10 power = power //2 print(result)
Title: Arpa’s hard exam and Mehrdad’s naive cheat Time Limit: None seconds Memory Limit: None megabytes Problem Description: There exists an island called Arpa’s land, some beautiful girls live there, as ugly ones do. Mehrdad wants to become minister of Arpa’s land. Arpa has prepared an exam. Exam has only one question, given *n*, print the last digit of 1378*n*. Mehrdad has become quite confused and wants you to help him. Please help, although it's a naive cheat. Input Specification: The single line of input contains one integer *n* (0<=<=≤<=<=*n*<=<=≤<=<=109). Output Specification: Print single integer — the last digit of 1378*n*. Demo Input: ['1\n', '2\n'] Demo Output: ['8', '4'] Note: In the first example, last digit of 1378<sup class="upper-index">1</sup> = 1378 is 8. In the second example, last digit of 1378<sup class="upper-index">2</sup> = 1378·1378 = 1898884 is 4.
```python base = 8 power = int(input()) result = 1 while power !=0: if power% 2==1: power = power - 1 result = (result * base)%10 if power%2 ==0: base = (base*base)%10 power = power //2 print(result) ```
3
447
A
DZY Loves Hash
PROGRAMMING
800
[ "implementation" ]
null
null
DZY has a hash table with *p* buckets, numbered from 0 to *p*<=-<=1. He wants to insert *n* numbers, in the order they are given, into the hash table. For the *i*-th number *x**i*, DZY will put it into the bucket numbered *h*(*x**i*), where *h*(*x*) is the hash function. In this problem we will assume, that *h*(*x*)<==<=*x* *mod* *p*. Operation *a* *mod* *b* denotes taking a remainder after division *a* by *b*. However, each bucket can contain no more than one element. If DZY wants to insert an number into a bucket which is already filled, we say a "conflict" happens. Suppose the first conflict happens right after the *i*-th insertion, you should output *i*. If no conflict happens, just output -1.
The first line contains two integers, *p* and *n* (2<=≤<=*p*,<=*n*<=≤<=300). Then *n* lines follow. The *i*-th of them contains an integer *x**i* (0<=≤<=*x**i*<=≤<=109).
Output a single integer — the answer to the problem.
[ "10 5\n0\n21\n53\n41\n53\n", "5 5\n0\n1\n2\n3\n4\n" ]
[ "4\n", "-1\n" ]
none
500
[ { "input": "10 5\n0\n21\n53\n41\n53", "output": "4" }, { "input": "5 5\n0\n1\n2\n3\n4", "output": "-1" }, { "input": "10 6\n811966798\n734823552\n790326404\n929189974\n414343256\n560346537", "output": "4" }, { "input": "2 2\n788371161\n801743052", "output": "-1" }, { "input": "10 6\n812796223\n122860157\n199259103\n597650585\n447742024\n521549402", "output": "3" }, { "input": "300 2\n822454942\n119374431", "output": "-1" }, { "input": "300 2\n823284367\n507345500", "output": "-1" }, { "input": "2 5\n791579811\n35613889\n997079893\n878677665\n693717467", "output": "2" }, { "input": "20 5\n793926268\n28931770\n842870287\n974950617\n859404206", "output": "-1" }, { "input": "100 15\n805069249\n778178198\n633897389\n844316223\n146759898\n870527016\n82668754\n42060733\n943602929\n979451110\n746979598\n47406033\n607284062\n850870259\n229415316", "output": "5" }, { "input": "100 15\n806204335\n189490323\n718805086\n716787474\n262315718\n822030596\n894644222\n724054623\n141384399\n579354205\n192622443\n672556242\n97417563\n243354557\n208957882", "output": "8" }, { "input": "100 15\n807033760\n577461392\n275221433\n532633429\n295714486\n783298996\n255799943\n99107143\n729119412\n59302896\n37640015\n313610861\n630550567\n534283052\n681062462", "output": "8" }, { "input": "100 15\n808103310\n136224397\n360129131\n405104681\n263786657\n734802577\n67808179\n928584682\n926900882\n511722343\n483348395\n938695534\n120684068\n74152694\n808088675", "output": "9" }, { "input": "2 2\n2\n2", "output": "2" }, { "input": "300 2\n0\n300", "output": "2" }, { "input": "2 2\n0\n0", "output": "2" } ]
1,553,494,845
2,147,483,647
PyPy 3
OK
TESTS
29
124
0
n,m=map(int,input().split()) a=[-1]*n for i in range(m): k=int(input()) if a[k%n]!=-1:print(i+1);exit() else:a[k%n]=k%n print(-1)
Title: DZY Loves Hash Time Limit: None seconds Memory Limit: None megabytes Problem Description: DZY has a hash table with *p* buckets, numbered from 0 to *p*<=-<=1. He wants to insert *n* numbers, in the order they are given, into the hash table. For the *i*-th number *x**i*, DZY will put it into the bucket numbered *h*(*x**i*), where *h*(*x*) is the hash function. In this problem we will assume, that *h*(*x*)<==<=*x* *mod* *p*. Operation *a* *mod* *b* denotes taking a remainder after division *a* by *b*. However, each bucket can contain no more than one element. If DZY wants to insert an number into a bucket which is already filled, we say a "conflict" happens. Suppose the first conflict happens right after the *i*-th insertion, you should output *i*. If no conflict happens, just output -1. Input Specification: The first line contains two integers, *p* and *n* (2<=≤<=*p*,<=*n*<=≤<=300). Then *n* lines follow. The *i*-th of them contains an integer *x**i* (0<=≤<=*x**i*<=≤<=109). Output Specification: Output a single integer — the answer to the problem. Demo Input: ['10 5\n0\n21\n53\n41\n53\n', '5 5\n0\n1\n2\n3\n4\n'] Demo Output: ['4\n', '-1\n'] Note: none
```python n,m=map(int,input().split()) a=[-1]*n for i in range(m): k=int(input()) if a[k%n]!=-1:print(i+1);exit() else:a[k%n]=k%n print(-1) ```
3
258
A
Little Elephant and Bits
PROGRAMMING
1,100
[ "greedy", "math" ]
null
null
The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper. To make sure that the number *a* fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number *a* in the binary record. At that a new number appears. It consists of the remaining binary digits, written in the corresponding order (possible, with leading zeroes). The Little Elephant wants the number he is going to write on the paper to be as large as possible. Help him find the maximum number that he can obtain after deleting exactly one binary digit and print it in the binary notation.
The single line contains integer *a*, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits.
In the single line print the number that is written without leading zeroes in the binary notation — the answer to the problem.
[ "101\n", "110010\n" ]
[ "11\n", "11010\n" ]
In the first sample the best strategy is to delete the second digit. That results in number 11<sub class="lower-index">2</sub> = 3<sub class="lower-index">10</sub>. In the second sample the best strategy is to delete the third or fourth digits — that results in number 11010<sub class="lower-index">2</sub> = 26<sub class="lower-index">10</sub>.
500
[ { "input": "101", "output": "11" }, { "input": "110010", "output": "11010" }, { "input": "10000", "output": "1000" }, { "input": "1111111110", "output": "111111111" }, { "input": "10100101011110101", "output": "1100101011110101" }, { "input": "111010010111", "output": "11110010111" }, { "input": "11110111011100000000", "output": "1111111011100000000" }, { "input": "11110010010100001110110101110011110110100111101", "output": "1111010010100001110110101110011110110100111101" }, { "input": "1001011111010010100111111", "output": "101011111010010100111111" }, { "input": "1111111111", "output": "111111111" }, { "input": "1111111111111111111100111101001110110111111000001111110101001101001110011000001011001111111000110101", "output": "111111111111111111110111101001110110111111000001111110101001101001110011000001011001111111000110101" }, { "input": "11010110000100100101111110111001001010011000011011000010010100111010101000111010011101101111110001111000101000001100011101110100", "output": "1110110000100100101111110111001001010011000011011000010010100111010101000111010011101101111110001111000101000001100011101110100" }, { "input": "11111111111111111111111110110111001101100111010010101101101001011100011011000111010011110010101100010001011101011010010100001000011100001101101001100010100001001010010100100001111110100110011000101100001111111011010111001011111110111101000100101001001011", "output": "1111111111111111111111111110111001101100111010010101101101001011100011011000111010011110010101100010001011101011010010100001000011100001101101001100010100001001010010100100001111110100110011000101100001111111011010111001011111110111101000100101001001011" }, { "input": "11100010010010000110101101101100111111001010001101101001001111010110010111001011010000001100110101000101111000001111101111110010000010101110011110101101010110001100011101111011100010011101100111110010111111100110101000000111101000000000110100100101111101000110101010101101001110001110000101011010101100011100100111100010001011010010001100011111110010011010011000111000100111100010110100011010010101011011011111110100001110000011011", "output": "1110010010010000110101101101100111111001010001101101001001111010110010111001011010000001100110101000101111000001111101111110010000010101110011110101101010110001100011101111011100010011101100111110010111111100110101000000111101000000000110100100101111101000110101010101101001110001110000101011010101100011100100111100010001011010010001100011111110010011010011000111000100111100010110100011010010101011011011111110100001110000011011" }, { "input": "11", "output": "1" }, { "input": "111", "output": "11" }, { "input": "111111", "output": "11111" }, { "input": "11111", "output": "1111" }, { "input": "1111", "output": "111" } ]
1,590,516,128
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
16
2,000
9,113,600
# import sys # sys.stdin = open('/home/puneet/Documents/Cpp Programs/input.txt', 'r') # sys.stdout = open('/home/puneet/Documents/Cpp Programs/output.txt', 'w') s = input() flag=1 ans=0 for i in range(len(s)): x = s[0:i] + s[i+1:] ans = max(ans,int(x,2)) x = bin(ans)[2:] if(len(x)!=(len(s)-1)): t = '0'*(len(s)-1-len(x)) t+=x print(t) else: print(x)
Title: Little Elephant and Bits Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper. To make sure that the number *a* fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number *a* in the binary record. At that a new number appears. It consists of the remaining binary digits, written in the corresponding order (possible, with leading zeroes). The Little Elephant wants the number he is going to write on the paper to be as large as possible. Help him find the maximum number that he can obtain after deleting exactly one binary digit and print it in the binary notation. Input Specification: The single line contains integer *a*, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits. Output Specification: In the single line print the number that is written without leading zeroes in the binary notation — the answer to the problem. Demo Input: ['101\n', '110010\n'] Demo Output: ['11\n', '11010\n'] Note: In the first sample the best strategy is to delete the second digit. That results in number 11<sub class="lower-index">2</sub> = 3<sub class="lower-index">10</sub>. In the second sample the best strategy is to delete the third or fourth digits — that results in number 11010<sub class="lower-index">2</sub> = 26<sub class="lower-index">10</sub>.
```python # import sys # sys.stdin = open('/home/puneet/Documents/Cpp Programs/input.txt', 'r') # sys.stdout = open('/home/puneet/Documents/Cpp Programs/output.txt', 'w') s = input() flag=1 ans=0 for i in range(len(s)): x = s[0:i] + s[i+1:] ans = max(ans,int(x,2)) x = bin(ans)[2:] if(len(x)!=(len(s)-1)): t = '0'*(len(s)-1-len(x)) t+=x print(t) else: print(x) ```
0
430
B
Balls Game
PROGRAMMING
1,400
[ "brute force", "two pointers" ]
null
null
Iahub is training for the IOI. What is a better way to train than playing a Zuma-like game? There are *n* balls put in a row. Each ball is colored in one of *k* colors. Initially the row doesn't contain three or more contiguous balls with the same color. Iahub has a single ball of color *x*. He can insert his ball at any position in the row (probably, between two other balls). If at any moment there are three or more contiguous balls of the same color in the row, they are destroyed immediately. This rule is applied multiple times, until there are no more sets of 3 or more contiguous balls of the same color. For example, if Iahub has the row of balls [black, black, white, white, black, black] and a white ball, he can insert the ball between two white balls. Thus three white balls are destroyed, and then four black balls become contiguous, so all four balls are destroyed. The row will not contain any ball in the end, so Iahub can destroy all 6 balls. Iahub wants to destroy as many balls as possible. You are given the description of the row of balls, and the color of Iahub's ball. Help Iahub train for the IOI by telling him the maximum number of balls from the row he can destroy.
The first line of input contains three integers: *n* (1<=≤<=*n*<=≤<=100), *k* (1<=≤<=*k*<=≤<=100) and *x* (1<=≤<=*x*<=≤<=*k*). The next line contains *n* space-separated integers *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=*k*). Number *c**i* means that the *i*-th ball in the row has color *c**i*. It is guaranteed that the initial row of balls will never contain three or more contiguous balls of the same color.
Print a single integer — the maximum number of balls Iahub can destroy.
[ "6 2 2\n1 1 2 2 1 1\n", "1 1 1\n1\n" ]
[ "6\n", "0\n" ]
none
1,000
[ { "input": "6 2 2\n1 1 2 2 1 1", "output": "6" }, { "input": "1 1 1\n1", "output": "0" }, { "input": "10 2 1\n2 1 2 2 1 2 2 1 1 2", "output": "5" }, { "input": "50 2 1\n1 1 2 2 1 2 1 1 2 2 1 2 1 2 1 1 2 2 1 2 1 2 2 1 2 1 2 1 2 2 1 1 2 2 1 1 2 2 1 2 1 1 2 1 1 2 2 1 1 2", "output": "15" }, { "input": "75 5 5\n1 1 5 5 3 5 2 3 3 2 2 1 1 5 4 4 3 4 5 4 3 3 1 2 2 1 2 1 2 5 5 2 1 3 2 2 3 1 2 1 1 5 5 1 1 2 1 1 2 2 5 2 2 1 1 2 1 2 1 1 3 3 5 4 4 3 3 4 4 5 5 1 1 2 2", "output": "6" }, { "input": "100 3 2\n1 1 2 3 1 3 2 1 1 3 3 2 2 1 1 2 2 1 1 3 2 2 3 2 3 2 2 3 3 1 1 2 2 1 2 2 1 3 3 1 3 3 1 2 1 2 2 1 2 3 2 1 1 2 1 1 3 3 1 3 3 1 1 2 2 1 1 2 1 3 2 2 3 2 2 3 3 1 2 1 2 2 1 1 2 3 1 3 3 1 2 3 2 2 1 3 2 2 3 3", "output": "6" }, { "input": "100 2 1\n2 2 1 2 1 2 1 2 2 1 1 2 1 1 2 1 1 2 2 1 1 2 1 1 2 1 2 2 1 2 1 2 1 2 1 1 2 1 1 2 1 1 2 2 1 1 2 1 2 2 1 2 1 2 1 2 1 1 2 2 1 2 1 1 2 2 1 1 2 1 2 1 2 1 2 2 1 2 1 1 2 1 2 1 1 2 1 1 2 1 1 2 2 1 2 2 1 1 2 1", "output": "15" }, { "input": "100 2 2\n1 2 1 2 2 1 2 1 2 1 2 1 1 2 1 2 2 1 1 2 1 1 2 2 1 1 2 1 2 2 1 2 2 1 2 1 2 1 1 2 1 2 1 2 1 2 1 1 2 1 1 2 2 1 1 2 2 1 2 1 2 1 2 1 2 2 1 2 1 2 2 1 1 2 1 2 2 1 1 2 2 1 2 1 2 1 1 2 1 2 1 2 1 2 1 2 2 1 2 2", "output": "14" }, { "input": "100 2 2\n1 2 1 1 2 1 2 2 1 2 1 2 1 2 1 2 1 2 2 1 1 2 2 1 2 1 1 2 2 1 1 2 1 2 1 2 1 1 2 1 1 2 1 2 2 1 1 2 2 1 1 2 1 2 2 1 1 2 1 2 1 2 2 1 2 2 1 1 2 1 2 2 1 2 2 1 2 1 1 2 1 2 2 1 2 2 1 2 1 2 1 2 1 1 2 2 1 1 2 2", "output": "17" }, { "input": "100 2 2\n2 1 1 2 2 1 1 2 1 2 1 1 2 2 1 2 1 2 1 2 2 1 2 1 1 2 1 2 1 2 1 2 1 1 2 2 1 1 2 1 1 2 1 2 2 1 1 2 1 2 1 1 2 2 1 1 2 1 2 1 2 1 2 2 1 1 2 2 1 1 2 2 1 2 1 2 1 1 2 1 1 2 2 1 2 1 2 2 1 2 2 1 1 2 1 2 2 1 2 2", "output": "17" }, { "input": "100 2 2\n1 2 2 1 2 2 1 1 2 1 2 1 2 1 2 1 2 1 2 1 1 2 2 1 2 1 2 1 2 1 2 1 1 2 1 1 2 1 2 2 1 1 2 2 1 1 2 1 1 2 2 1 2 1 2 1 2 1 2 1 1 2 2 1 1 2 2 1 1 2 2 1 2 2 1 1 2 1 2 2 1 2 2 1 2 2 1 2 2 1 1 2 2 1 2 1 2 1 2 1", "output": "28" }, { "input": "100 2 2\n1 1 2 1 2 1 1 2 1 2 1 2 2 1 2 1 2 1 1 2 2 1 2 1 1 2 2 1 1 2 1 2 2 1 2 2 1 2 1 2 1 1 2 1 2 1 1 2 2 1 1 2 1 2 1 2 1 2 1 2 2 1 1 2 1 2 2 1 2 1 1 2 1 1 2 1 2 1 2 1 1 2 1 2 2 1 2 1 2 2 1 1 2 1 2 2 1 1 2 2", "output": "8" }, { "input": "100 100 50\n15 44 5 7 75 40 52 82 78 90 48 32 16 53 69 2 21 84 7 21 21 87 29 8 42 54 10 21 38 55 54 88 48 63 3 17 45 82 82 91 7 11 11 24 24 79 1 32 32 38 41 41 4 4 74 17 26 26 96 96 3 3 50 50 96 26 26 17 17 74 74 4 41 38 38 32 1 1 79 79 24 11 11 7 7 91 91 82 45 45 97 9 74 60 32 91 61 64 100 26", "output": "2" }, { "input": "100 50 22\n15 2 18 15 48 35 46 33 32 39 39 5 5 27 27 50 50 47 47 10 10 6 3 3 7 8 7 17 17 29 14 10 10 46 13 13 31 32 31 22 22 32 31 31 32 13 13 46 46 10 10 14 14 29 29 17 7 7 8 3 6 6 10 47 50 50 27 5 5 39 39 21 47 4 40 47 21 28 21 21 40 27 34 17 3 36 5 7 21 14 25 49 40 34 32 13 23 29 2 4", "output": "2" }, { "input": "100 3 3\n3 1 1 2 1 1 3 1 3 3 1 3 3 1 2 1 1 2 2 3 3 2 3 2 2 3 1 3 3 2 2 1 3 3 2 2 1 2 3 3 1 3 1 3 1 2 2 1 2 1 2 3 1 3 1 3 2 1 3 2 3 3 2 3 2 3 1 3 2 2 1 2 1 2 1 1 3 1 3 1 2 1 2 1 2 3 2 2 3 3 2 2 3 2 2 3 1 1 2 3", "output": "6" }, { "input": "100 100 100\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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100", "output": "0" }, { "input": "100 2 2\n1 1 2 2 1 1 2 2 1 1 2 2 1 1 2 2 1 1 2 2 1 1 2 2 1 1 2 2 1 1 2 2 1 1 2 2 1 1 2 2 1 1 2 2 1 1 2 2 1 1 2 2 1 1 2 2 1 1 2 2 1 1 2 2 1 1 2 2 1 1 2 2 1 1 2 2 1 1 2 2 1 1 2 2 1 1 2 2 1 1 2 2 1 1 2 2 1 1 2 2", "output": "98" }, { "input": "6 20 10\n10 2 10 10 2 2", "output": "5" } ]
1,657,259,660
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
31
0
n,k,x=map(int,input().split()) f=list(map(int,input().split())) res=0 for i in range(n): if f[i] == x: new=f[::] new.insert(i,x) nr=0 des=0 st=[] for j in new: st.append(j) if st[-1]==des: st.pop() nr+=1 elif len(st)>=3: if st[-1] == st[-2] and st[-1] == st[-3]: st.pop() st.pop() st.pop() nr+=3 res=max(nr,res) print(res)
Title: Balls Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Iahub is training for the IOI. What is a better way to train than playing a Zuma-like game? There are *n* balls put in a row. Each ball is colored in one of *k* colors. Initially the row doesn't contain three or more contiguous balls with the same color. Iahub has a single ball of color *x*. He can insert his ball at any position in the row (probably, between two other balls). If at any moment there are three or more contiguous balls of the same color in the row, they are destroyed immediately. This rule is applied multiple times, until there are no more sets of 3 or more contiguous balls of the same color. For example, if Iahub has the row of balls [black, black, white, white, black, black] and a white ball, he can insert the ball between two white balls. Thus three white balls are destroyed, and then four black balls become contiguous, so all four balls are destroyed. The row will not contain any ball in the end, so Iahub can destroy all 6 balls. Iahub wants to destroy as many balls as possible. You are given the description of the row of balls, and the color of Iahub's ball. Help Iahub train for the IOI by telling him the maximum number of balls from the row he can destroy. Input Specification: The first line of input contains three integers: *n* (1<=≤<=*n*<=≤<=100), *k* (1<=≤<=*k*<=≤<=100) and *x* (1<=≤<=*x*<=≤<=*k*). The next line contains *n* space-separated integers *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=*k*). Number *c**i* means that the *i*-th ball in the row has color *c**i*. It is guaranteed that the initial row of balls will never contain three or more contiguous balls of the same color. Output Specification: Print a single integer — the maximum number of balls Iahub can destroy. Demo Input: ['6 2 2\n1 1 2 2 1 1\n', '1 1 1\n1\n'] Demo Output: ['6\n', '0\n'] Note: none
```python n,k,x=map(int,input().split()) f=list(map(int,input().split())) res=0 for i in range(n): if f[i] == x: new=f[::] new.insert(i,x) nr=0 des=0 st=[] for j in new: st.append(j) if st[-1]==des: st.pop() nr+=1 elif len(st)>=3: if st[-1] == st[-2] and st[-1] == st[-3]: st.pop() st.pop() st.pop() nr+=3 res=max(nr,res) print(res) ```
0
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,696,438,326
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
m = int(input()) l = [] for i in range(m): m = input() if not m in l: l.append(m) print("OK") else: for d in range(len(l)): if len(l[(d+1)*-1]) >= len(m)+1 if l[(d+1)*-1][:len(m)] == m: try: n = str(int(l[(d+1)*-1][-1])+1) except: n = "1" l.append(m+n) print(m+n) break
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 m = int(input()) l = [] for i in range(m): m = input() if not m in l: l.append(m) print("OK") else: for d in range(len(l)): if len(l[(d+1)*-1]) >= len(m)+1 if l[(d+1)*-1][:len(m)] == m: try: n = str(int(l[(d+1)*-1][-1])+1) except: n = "1" l.append(m+n) print(m+n) break ```
-1
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,683,291,576
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
60
0
a,b=map(int,input().split()) x=list(map(int,input().split())) for i in x: list=[] lst=[] ls=[] l=[] lst.append(i) x.remove(i) for j in x: ls.append((j-i)) for k in range(a-1): l.append(min(ls)) ls.remove(min(ls)) list.append(i) for m in l: list.append(i+m) for p in list: lt=[] a=max(list) b=min(list) c=abs(a-b) lt.append(c) print(min(lt))
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 a,b=map(int,input().split()) x=list(map(int,input().split())) for i in x: list=[] lst=[] ls=[] l=[] lst.append(i) x.remove(i) for j in x: ls.append((j-i)) for k in range(a-1): l.append(min(ls)) ls.remove(min(ls)) list.append(i) for m in l: list.append(i+m) for p in list: lt=[] a=max(list) b=min(list) c=abs(a-b) lt.append(c) print(min(lt)) ```
-1
59
A
Word
PROGRAMMING
800
[ "implementation", "strings" ]
A. Word
2
256
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word.
The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
[ "HoUse\n", "ViP\n", "maTRIx\n" ]
[ "house\n", "VIP\n", "matrix\n" ]
none
500
[ { "input": "HoUse", "output": "house" }, { "input": "ViP", "output": "VIP" }, { "input": "maTRIx", "output": "matrix" }, { "input": "BNHWpnpawg", "output": "bnhwpnpawg" }, { "input": "VTYGP", "output": "VTYGP" }, { "input": "CHNenu", "output": "chnenu" }, { "input": "ERPZGrodyu", "output": "erpzgrodyu" }, { "input": "KSXBXWpebh", "output": "KSXBXWPEBH" }, { "input": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv", "output": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv" }, { "input": "Amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd", "output": "amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd" }, { "input": "ISAGFJFARYFBLOPQDSHWGMCNKMFTLVFUGNJEWGWNBLXUIATXEkqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv", "output": "isagfjfaryfblopqdshwgmcnkmftlvfugnjewgwnblxuiatxekqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv" }, { "input": "XHRPXZEGHSOCJPICUIXSKFUZUPYTSGJSDIYBCMNMNBPNDBXLXBzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg", "output": "xhrpxzeghsocjpicuixskfuzupytsgjsdiybcmnmnbpndbxlxbzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg" }, { "input": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGAdkcetqjljtmttlonpekcovdzebzdkzggwfsxhapmjkdbuceak", "output": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGADKCETQJLJTMTTLONPEKCOVDZEBZDKZGGWFSXHAPMJKDBUCEAK" }, { "input": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFw", "output": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFW" }, { "input": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB", "output": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB" }, { "input": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge", "output": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge" }, { "input": "Ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw", "output": "ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw" }, { "input": "YQOMLKYAORUQQUCQZCDYMIVDHGWZFFRMUVTAWCHERFPMNRYRIkgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks", "output": "yqomlkyaoruqqucqzcdymivdhgwzffrmuvtawcherfpmnryrikgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks" }, { "input": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJcuusigdqfkumewjtdyitveeiaybwrhomrwmpdipjwiuxfnwuz", "output": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJCUUSIGDQFKUMEWJTDYITVEEIAYBWRHOMRWMPDIPJWIUXFNWUZ" }, { "input": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWuckzcpxosodcjaaakvlxpbiigsiauviilylnnqlyucziihqg", "output": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWUCKZCPXOSODCJAAAKVLXPBIIGSIAUVIILYLNNQLYUCZIIHQG" }, { "input": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO", "output": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO" }, { "input": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDd", "output": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDD" }, { "input": "EBWOVSNLYTWWXrnovgugogtjahnmatomubebyxakas", "output": "ebwovsnlytwwxrnovgugogtjahnmatomubebyxakas" }, { "input": "AORNNDKTRLRVGDPXJKXFTPFpopuzrlqumrxssskvbm", "output": "AORNNDKTRLRVGDPXJKXFTPFPOPUZRLQUMRXSSSKVBM" }, { "input": "DBBZJCWQEVGYHEEUHJAWRHBDPsnplijbwtdibqrrheebfxqcvn", "output": "dbbzjcwqevgyheeuhjawrhbdpsnplijbwtdibqrrheebfxqcvn" }, { "input": "t", "output": "t" }, { "input": "N", "output": "N" }, { "input": "kv", "output": "kv" }, { "input": "Ur", "output": "ur" }, { "input": "CN", "output": "CN" } ]
1,651,875,893
2,147,483,647
Python 3
OK
TESTS
30
92
0
s= input() count=0 l = len(s) for i in range(len(s)): if s[i].islower() == True: count +=1 if count >= l - count: print(s.lower()) else: print(s.upper())
Title: Word Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word. Input Specification: The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. Output Specification: Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. Demo Input: ['HoUse\n', 'ViP\n', 'maTRIx\n'] Demo Output: ['house\n', 'VIP\n', 'matrix\n'] Note: none
```python s= input() count=0 l = len(s) for i in range(len(s)): if s[i].islower() == True: count +=1 if count >= l - count: print(s.lower()) else: print(s.upper()) ```
3.977
385
B
Bear and Strings
PROGRAMMING
1,200
[ "brute force", "greedy", "implementation", "math", "strings" ]
null
null
The bear has a string *s*<==<=*s*1*s*2... *s*|*s*| (record |*s*| is the string's length), consisting of lowercase English letters. The bear wants to count the number of such pairs of indices *i*,<=*j* (1<=≤<=*i*<=≤<=*j*<=≤<=|*s*|), that string *x*(*i*,<=*j*)<==<=*s**i**s**i*<=+<=1... *s**j* contains at least one string "bear" as a substring. String *x*(*i*,<=*j*) contains string "bear", if there is such index *k* (*i*<=≤<=*k*<=≤<=*j*<=-<=3), that *s**k*<==<=*b*, *s**k*<=+<=1<==<=*e*, *s**k*<=+<=2<==<=*a*, *s**k*<=+<=3<==<=*r*. Help the bear cope with the given problem.
The first line contains a non-empty string *s* (1<=≤<=|*s*|<=≤<=5000). It is guaranteed that the string only consists of lowercase English letters.
Print a single number — the answer to the problem.
[ "bearbtear\n", "bearaabearc\n" ]
[ "6\n", "20\n" ]
In the first sample, the following pairs (*i*, *j*) match: (1, 4), (1, 5), (1, 6), (1, 7), (1, 8), (1, 9). In the second sample, the following pairs (*i*, *j*) match: (1,  4), (1,  5), (1,  6), (1,  7), (1,  8), (1,  9), (1,  10), (1,  11), (2,  10), (2,  11), (3,  10), (3,  11), (4,  10), (4,  11), (5,  10), (5,  11), (6,  10), (6,  11), (7,  10), (7,  11).
1,000
[ { "input": "bearbtear", "output": "6" }, { "input": "bearaabearc", "output": "20" }, { "input": "pbearbearhbearzqbearjkterasjhy", "output": "291" }, { "input": "pbearjbearbebearnbabcffbearbearwubearjezpiorrbearbearjbdlbearbearqbearjbearwipmsbearoaftrsebearzsnqb", "output": "4419" }, { "input": "bear", "output": "1" }, { "input": "a", "output": "0" }, { "input": "be", "output": "0" } ]
1,654,788,087
2,147,483,647
PyPy 3-64
OK
TESTS
43
62
2,252,800
s = input().strip() n = len(s) tot = 0 prev = 0 for i in range(n-3): if s[i:i+4] == "bear": l,r = i-prev, n - (i + 4) tot += (l+1)*(r+1) prev = i+1 print(tot)
Title: Bear and Strings Time Limit: None seconds Memory Limit: None megabytes Problem Description: The bear has a string *s*<==<=*s*1*s*2... *s*|*s*| (record |*s*| is the string's length), consisting of lowercase English letters. The bear wants to count the number of such pairs of indices *i*,<=*j* (1<=≤<=*i*<=≤<=*j*<=≤<=|*s*|), that string *x*(*i*,<=*j*)<==<=*s**i**s**i*<=+<=1... *s**j* contains at least one string "bear" as a substring. String *x*(*i*,<=*j*) contains string "bear", if there is such index *k* (*i*<=≤<=*k*<=≤<=*j*<=-<=3), that *s**k*<==<=*b*, *s**k*<=+<=1<==<=*e*, *s**k*<=+<=2<==<=*a*, *s**k*<=+<=3<==<=*r*. Help the bear cope with the given problem. Input Specification: The first line contains a non-empty string *s* (1<=≤<=|*s*|<=≤<=5000). It is guaranteed that the string only consists of lowercase English letters. Output Specification: Print a single number — the answer to the problem. Demo Input: ['bearbtear\n', 'bearaabearc\n'] Demo Output: ['6\n', '20\n'] Note: In the first sample, the following pairs (*i*, *j*) match: (1, 4), (1, 5), (1, 6), (1, 7), (1, 8), (1, 9). In the second sample, the following pairs (*i*, *j*) match: (1,  4), (1,  5), (1,  6), (1,  7), (1,  8), (1,  9), (1,  10), (1,  11), (2,  10), (2,  11), (3,  10), (3,  11), (4,  10), (4,  11), (5,  10), (5,  11), (6,  10), (6,  11), (7,  10), (7,  11).
```python s = input().strip() n = len(s) tot = 0 prev = 0 for i in range(n-3): if s[i:i+4] == "bear": l,r = i-prev, n - (i + 4) tot += (l+1)*(r+1) prev = i+1 print(tot) ```
3
610
A
Pasha and Stick
PROGRAMMING
1,000
[ "combinatorics", "math" ]
null
null
Pasha has a wooden stick of some positive integer length *n*. He wants to perform exactly three cuts to get four parts of the stick. Each part must have some positive integer length and the sum of these lengths will obviously be *n*. Pasha likes rectangles but hates squares, so he wonders, how many ways are there to split a stick into four parts so that it's possible to form a rectangle using these parts, but is impossible to form a square. Your task is to help Pasha and count the number of such ways. Two ways to cut the stick are considered distinct if there exists some integer *x*, such that the number of parts of length *x* in the first way differ from the number of parts of length *x* in the second way.
The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=2·109) — the length of Pasha's stick.
The output should contain a single integer — the number of ways to split Pasha's stick into four parts of positive integer length so that it's possible to make a rectangle by connecting the ends of these parts, but is impossible to form a square.
[ "6\n", "20\n" ]
[ "1\n", "4\n" ]
There is only one way to divide the stick in the first sample {1, 1, 2, 2}. Four ways to divide the stick in the second sample are {1, 1, 9, 9}, {2, 2, 8, 8}, {3, 3, 7, 7} and {4, 4, 6, 6}. Note that {5, 5, 5, 5} doesn't work.
500
[ { "input": "6", "output": "1" }, { "input": "20", "output": "4" }, { "input": "1", "output": "0" }, { "input": "2", "output": "0" }, { "input": "3", "output": "0" }, { "input": "4", "output": "0" }, { "input": "2000000000", "output": "499999999" }, { "input": "1924704072", "output": "481176017" }, { "input": "73740586", "output": "18435146" }, { "input": "1925088820", "output": "481272204" }, { "input": "593070992", "output": "148267747" }, { "input": "1925473570", "output": "481368392" }, { "input": "629490186", "output": "157372546" }, { "input": "1980649112", "output": "495162277" }, { "input": "36661322", "output": "9165330" }, { "input": "1943590793", "output": "0" }, { "input": "71207034", "output": "17801758" }, { "input": "1757577394", "output": "439394348" }, { "input": "168305294", "output": "42076323" }, { "input": "1934896224", "output": "483724055" }, { "input": "297149088", "output": "74287271" }, { "input": "1898001634", "output": "474500408" }, { "input": "176409698", "output": "44102424" }, { "input": "1873025522", "output": "468256380" }, { "input": "5714762", "output": "1428690" }, { "input": "1829551192", "output": "457387797" }, { "input": "16269438", "output": "4067359" }, { "input": "1663283390", "output": "415820847" }, { "input": "42549941", "output": "0" }, { "input": "1967345604", "output": "491836400" }, { "input": "854000", "output": "213499" }, { "input": "1995886626", "output": "498971656" }, { "input": "10330019", "output": "0" }, { "input": "1996193634", "output": "499048408" }, { "input": "9605180", "output": "2401294" }, { "input": "1996459740", "output": "499114934" }, { "input": "32691948", "output": "8172986" }, { "input": "1975903308", "output": "493975826" }, { "input": "1976637136", "output": "494159283" }, { "input": "29803038", "output": "7450759" }, { "input": "1977979692", "output": "494494922" }, { "input": "1978595336", "output": "494648833" }, { "input": "27379344", "output": "6844835" }, { "input": "1979729912", "output": "494932477" }, { "input": "1980253780", "output": "495063444" }, { "input": "1980751584", "output": "495187895" }, { "input": "53224878", "output": "13306219" }, { "input": "5", "output": "0" }, { "input": "7", "output": "0" }, { "input": "8", "output": "1" }, { "input": "9", "output": "0" }, { "input": "10", "output": "2" }, { "input": "11", "output": "0" }, { "input": "12", "output": "2" }, { "input": "13", "output": "0" }, { "input": "14", "output": "3" }, { "input": "15", "output": "0" }, { "input": "16", "output": "3" }, { "input": "17", "output": "0" }, { "input": "18", "output": "4" }, { "input": "19", "output": "0" }, { "input": "21", "output": "0" }, { "input": "22", "output": "5" }, { "input": "23", "output": "0" }, { "input": "24", "output": "5" }, { "input": "25", "output": "0" }, { "input": "26", "output": "6" }, { "input": "27", "output": "0" }, { "input": "28", "output": "6" }, { "input": "29", "output": "0" }, { "input": "30", "output": "7" }, { "input": "111", "output": "0" }, { "input": "55", "output": "0" }, { "input": "105", "output": "0" }, { "input": "199", "output": "0" }, { "input": "151", "output": "0" } ]
1,657,357,436
2,147,483,647
PyPy 3-64
OK
TESTS
76
109
0
def solve(a): if a%2==1: return 0 tmp=a//4 if a%4==0: tmp-=1 return tmp a=int(input()) print(solve(a))
Title: Pasha and Stick Time Limit: None seconds Memory Limit: None megabytes Problem Description: Pasha has a wooden stick of some positive integer length *n*. He wants to perform exactly three cuts to get four parts of the stick. Each part must have some positive integer length and the sum of these lengths will obviously be *n*. Pasha likes rectangles but hates squares, so he wonders, how many ways are there to split a stick into four parts so that it's possible to form a rectangle using these parts, but is impossible to form a square. Your task is to help Pasha and count the number of such ways. Two ways to cut the stick are considered distinct if there exists some integer *x*, such that the number of parts of length *x* in the first way differ from the number of parts of length *x* in the second way. Input Specification: The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=2·109) — the length of Pasha's stick. Output Specification: The output should contain a single integer — the number of ways to split Pasha's stick into four parts of positive integer length so that it's possible to make a rectangle by connecting the ends of these parts, but is impossible to form a square. Demo Input: ['6\n', '20\n'] Demo Output: ['1\n', '4\n'] Note: There is only one way to divide the stick in the first sample {1, 1, 2, 2}. Four ways to divide the stick in the second sample are {1, 1, 9, 9}, {2, 2, 8, 8}, {3, 3, 7, 7} and {4, 4, 6, 6}. Note that {5, 5, 5, 5} doesn't work.
```python def solve(a): if a%2==1: return 0 tmp=a//4 if a%4==0: tmp-=1 return tmp a=int(input()) print(solve(a)) ```
3
143
A
Help Vasilisa the Wise 2
PROGRAMMING
1,000
[ "brute force", "math" ]
null
null
Vasilisa the Wise from the Kingdom of Far Far Away got a magic box with a secret as a present from her friend Hellawisa the Wise from the Kingdom of A Little Closer. However, Vasilisa the Wise does not know what the box's secret is, since she cannot open it again. She hopes that you will help her one more time with that. The box's lock looks as follows: it contains 4 identical deepenings for gems as a 2<=×<=2 square, and some integer numbers are written at the lock's edge near the deepenings. The example of a lock is given on the picture below. The box is accompanied with 9 gems. Their shapes match the deepenings' shapes and each gem contains one number from 1 to 9 (each number is written on exactly one gem). The box will only open after it is decorated with gems correctly: that is, each deepening in the lock should be filled with exactly one gem. Also, the sums of numbers in the square's rows, columns and two diagonals of the square should match the numbers written at the lock's edge. For example, the above lock will open if we fill the deepenings with gems with numbers as is shown on the picture below. Now Vasilisa the Wise wants to define, given the numbers on the box's lock, which gems she should put in the deepenings to open the box. Help Vasilisa to solve this challenging task.
The input contains numbers written on the edges of the lock of the box. The first line contains space-separated integers *r*1 and *r*2 that define the required sums of numbers in the rows of the square. The second line contains space-separated integers *c*1 and *c*2 that define the required sums of numbers in the columns of the square. The third line contains space-separated integers *d*1 and *d*2 that define the required sums of numbers on the main and on the side diagonals of the square (1<=≤<=*r*1,<=*r*2,<=*c*1,<=*c*2,<=*d*1,<=*d*2<=≤<=20). Correspondence between the above 6 variables and places where they are written is shown on the picture below. For more clarifications please look at the second sample test that demonstrates the example given in the problem statement.
Print the scheme of decorating the box with stones: two lines containing two space-separated integers from 1 to 9. The numbers should be pairwise different. If there is no solution for the given lock, then print the single number "-1" (without the quotes). If there are several solutions, output any.
[ "3 7\n4 6\n5 5\n", "11 10\n13 8\n5 16\n", "1 2\n3 4\n5 6\n", "10 10\n10 10\n10 10\n" ]
[ "1 2\n3 4\n", "4 7\n9 1\n", "-1\n", "-1\n" ]
Pay attention to the last test from the statement: it is impossible to open the box because for that Vasilisa the Wise would need 4 identical gems containing number "5". However, Vasilisa only has one gem with each number from 1 to 9.
500
[ { "input": "3 7\n4 6\n5 5", "output": "1 2\n3 4" }, { "input": "11 10\n13 8\n5 16", "output": "4 7\n9 1" }, { "input": "1 2\n3 4\n5 6", "output": "-1" }, { "input": "10 10\n10 10\n10 10", "output": "-1" }, { "input": "5 13\n8 10\n11 7", "output": "3 2\n5 8" }, { "input": "12 17\n10 19\n13 16", "output": "-1" }, { "input": "11 11\n17 5\n12 10", "output": "9 2\n8 3" }, { "input": "12 11\n11 12\n16 7", "output": "-1" }, { "input": "5 9\n7 7\n8 6", "output": "3 2\n4 5" }, { "input": "10 7\n4 13\n11 6", "output": "-1" }, { "input": "18 10\n16 12\n12 16", "output": "-1" }, { "input": "13 6\n10 9\n6 13", "output": "-1" }, { "input": "14 16\n16 14\n18 12", "output": "-1" }, { "input": "16 10\n16 10\n12 14", "output": "-1" }, { "input": "11 9\n12 8\n11 9", "output": "-1" }, { "input": "5 14\n10 9\n10 9", "output": "-1" }, { "input": "2 4\n1 5\n3 3", "output": "-1" }, { "input": "17 16\n14 19\n18 15", "output": "-1" }, { "input": "12 12\n14 10\n16 8", "output": "9 3\n5 7" }, { "input": "15 11\n16 10\n9 17", "output": "7 8\n9 2" }, { "input": "8 10\n9 9\n13 5", "output": "6 2\n3 7" }, { "input": "13 7\n10 10\n5 15", "output": "4 9\n6 1" }, { "input": "14 11\n9 16\n16 9", "output": "-1" }, { "input": "12 8\n14 6\n8 12", "output": "-1" }, { "input": "10 6\n6 10\n4 12", "output": "-1" }, { "input": "10 8\n10 8\n4 14", "output": "-1" }, { "input": "14 13\n9 18\n14 13", "output": "-1" }, { "input": "9 14\n8 15\n8 15", "output": "-1" }, { "input": "3 8\n2 9\n6 5", "output": "-1" }, { "input": "14 17\n18 13\n15 16", "output": "-1" }, { "input": "16 14\n15 15\n17 13", "output": "9 7\n6 8" }, { "input": "14 11\n16 9\n13 12", "output": "9 5\n7 4" }, { "input": "13 10\n11 12\n7 16", "output": "4 9\n7 3" }, { "input": "14 8\n11 11\n13 9", "output": "8 6\n3 5" }, { "input": "12 11\n13 10\n10 13", "output": "-1" }, { "input": "6 5\n2 9\n5 6", "output": "-1" }, { "input": "7 8\n8 7\n12 3", "output": "-1" }, { "input": "7 11\n7 11\n6 12", "output": "-1" }, { "input": "8 5\n11 2\n8 5", "output": "-1" }, { "input": "10 16\n14 12\n14 12", "output": "-1" }, { "input": "7 9\n4 12\n5 11", "output": "-1" }, { "input": "11 13\n19 5\n12 12", "output": "-1" }, { "input": "8 12\n5 15\n11 9", "output": "2 6\n3 9" }, { "input": "16 5\n13 8\n10 11", "output": "9 7\n4 1" }, { "input": "3 14\n8 9\n10 7", "output": "2 1\n6 8" }, { "input": "12 14\n11 15\n9 17", "output": "3 9\n8 6" }, { "input": "13 7\n9 11\n14 6", "output": "8 5\n1 6" }, { "input": "13 8\n15 6\n11 10", "output": "9 4\n6 2" }, { "input": "9 6\n5 10\n3 12", "output": "1 8\n4 2" }, { "input": "12 7\n5 14\n8 11", "output": "3 9\n2 5" }, { "input": "9 12\n3 17\n10 10", "output": "-1" }, { "input": "3 8\n4 6\n5 5", "output": "-1" } ]
1,627,130,898
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
3
154
20,172,800
import math def main_function(): r_1, r_2 = [int(i) for i in input().split(" ")] c_1, c_2 = [int(i) for i in input().split(" ")] d_1, d_2 = [int(i) for i in input().split(" ")] if r_1 + r_2 == c_2 + c_1 and d_1 + d_2 == c_2 + c_1 and (c_1 + r_1 - d_2) % 2 == 0: a = (c_1 + r_1 - d_2) // 2 c = c_1 - a d = r_2 - c b = c_2 - d if min([a,b,c,d]) > 0 and max([a,b,c,d]) < 10: print(str(a) + " " + str(b)) print(str(c) + " " + str(d)) else: print(-1) else: print(-1) main_function()
Title: Help Vasilisa the Wise 2 Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasilisa the Wise from the Kingdom of Far Far Away got a magic box with a secret as a present from her friend Hellawisa the Wise from the Kingdom of A Little Closer. However, Vasilisa the Wise does not know what the box's secret is, since she cannot open it again. She hopes that you will help her one more time with that. The box's lock looks as follows: it contains 4 identical deepenings for gems as a 2<=×<=2 square, and some integer numbers are written at the lock's edge near the deepenings. The example of a lock is given on the picture below. The box is accompanied with 9 gems. Their shapes match the deepenings' shapes and each gem contains one number from 1 to 9 (each number is written on exactly one gem). The box will only open after it is decorated with gems correctly: that is, each deepening in the lock should be filled with exactly one gem. Also, the sums of numbers in the square's rows, columns and two diagonals of the square should match the numbers written at the lock's edge. For example, the above lock will open if we fill the deepenings with gems with numbers as is shown on the picture below. Now Vasilisa the Wise wants to define, given the numbers on the box's lock, which gems she should put in the deepenings to open the box. Help Vasilisa to solve this challenging task. Input Specification: The input contains numbers written on the edges of the lock of the box. The first line contains space-separated integers *r*1 and *r*2 that define the required sums of numbers in the rows of the square. The second line contains space-separated integers *c*1 and *c*2 that define the required sums of numbers in the columns of the square. The third line contains space-separated integers *d*1 and *d*2 that define the required sums of numbers on the main and on the side diagonals of the square (1<=≤<=*r*1,<=*r*2,<=*c*1,<=*c*2,<=*d*1,<=*d*2<=≤<=20). Correspondence between the above 6 variables and places where they are written is shown on the picture below. For more clarifications please look at the second sample test that demonstrates the example given in the problem statement. Output Specification: Print the scheme of decorating the box with stones: two lines containing two space-separated integers from 1 to 9. The numbers should be pairwise different. If there is no solution for the given lock, then print the single number "-1" (without the quotes). If there are several solutions, output any. Demo Input: ['3 7\n4 6\n5 5\n', '11 10\n13 8\n5 16\n', '1 2\n3 4\n5 6\n', '10 10\n10 10\n10 10\n'] Demo Output: ['1 2\n3 4\n', '4 7\n9 1\n', '-1\n', '-1\n'] Note: Pay attention to the last test from the statement: it is impossible to open the box because for that Vasilisa the Wise would need 4 identical gems containing number "5". However, Vasilisa only has one gem with each number from 1 to 9.
```python import math def main_function(): r_1, r_2 = [int(i) for i in input().split(" ")] c_1, c_2 = [int(i) for i in input().split(" ")] d_1, d_2 = [int(i) for i in input().split(" ")] if r_1 + r_2 == c_2 + c_1 and d_1 + d_2 == c_2 + c_1 and (c_1 + r_1 - d_2) % 2 == 0: a = (c_1 + r_1 - d_2) // 2 c = c_1 - a d = r_2 - c b = c_2 - d if min([a,b,c,d]) > 0 and max([a,b,c,d]) < 10: print(str(a) + " " + str(b)) print(str(c) + " " + str(d)) else: print(-1) else: print(-1) main_function() ```
0
379
A
New Year Candles
PROGRAMMING
1,000
[ "implementation" ]
null
null
Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles. Vasily has *a* candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is smart, so he can make *b* went out candles into a new candle. As a result, this new candle can be used like any other new candle. Now Vasily wonders: for how many hours can his candles light up the room if he acts optimally well? Help him find this number.
The single line contains two integers, *a* and *b* (1<=≤<=*a*<=≤<=1000; 2<=≤<=*b*<=≤<=1000).
Print a single integer — the number of hours Vasily can light up the room for.
[ "4 2\n", "6 3\n" ]
[ "7\n", "8\n" ]
Consider the first sample. For the first four hours Vasily lights up new candles, then he uses four burned out candles to make two new ones and lights them up. When these candles go out (stop burning), Vasily can make another candle. Overall, Vasily can light up the room for 7 hours.
500
[ { "input": "4 2", "output": "7" }, { "input": "6 3", "output": "8" }, { "input": "1000 1000", "output": "1001" }, { "input": "123 5", "output": "153" }, { "input": "1000 2", "output": "1999" }, { "input": "1 2", "output": "1" }, { "input": "1 3", "output": "1" }, { "input": "1 4", "output": "1" }, { "input": "2 2", "output": "3" }, { "input": "3 2", "output": "5" }, { "input": "3 3", "output": "4" }, { "input": "999 2", "output": "1997" }, { "input": "1000 3", "output": "1499" }, { "input": "1000 4", "output": "1333" }, { "input": "1 1000", "output": "1" }, { "input": "80 970", "output": "80" }, { "input": "80 970", "output": "80" }, { "input": "80 970", "output": "80" }, { "input": "80 970", "output": "80" }, { "input": "80 970", "output": "80" }, { "input": "80 970", "output": "80" }, { "input": "10 4", "output": "13" }, { "input": "4 3", "output": "5" }, { "input": "91 5", "output": "113" }, { "input": "777 17", "output": "825" }, { "input": "100 4", "output": "133" }, { "input": "5 3", "output": "7" }, { "input": "6 4", "output": "7" }, { "input": "26 8", "output": "29" }, { "input": "9 4", "output": "11" }, { "input": "20 3", "output": "29" }, { "input": "17 3", "output": "25" } ]
1,680,358,654
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
46
0
inputs = list(map(int, input().strip().split())) a = inputs[0] b = inputs[1] result = a rem = 0 while(a): rem += a % b a //= b result += a print(result + rem // b)
Title: New Year Candles Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles. Vasily has *a* candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is smart, so he can make *b* went out candles into a new candle. As a result, this new candle can be used like any other new candle. Now Vasily wonders: for how many hours can his candles light up the room if he acts optimally well? Help him find this number. Input Specification: The single line contains two integers, *a* and *b* (1<=≤<=*a*<=≤<=1000; 2<=≤<=*b*<=≤<=1000). Output Specification: Print a single integer — the number of hours Vasily can light up the room for. Demo Input: ['4 2\n', '6 3\n'] Demo Output: ['7\n', '8\n'] Note: Consider the first sample. For the first four hours Vasily lights up new candles, then he uses four burned out candles to make two new ones and lights them up. When these candles go out (stop burning), Vasily can make another candle. Overall, Vasily can light up the room for 7 hours.
```python inputs = list(map(int, input().strip().split())) a = inputs[0] b = inputs[1] result = a rem = 0 while(a): rem += a % b a //= b result += a print(result + rem // b) ```
0
499
B
Lecture
PROGRAMMING
1,000
[ "implementation", "strings" ]
null
null
You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes. You know two languages, and the professor is giving the lecture in the first one. The words in both languages consist of lowercase English characters, each language consists of several words. For each language, all words are distinct, i.e. they are spelled differently. Moreover, the words of these languages have a one-to-one correspondence, that is, for each word in each language, there exists exactly one word in the other language having has the same meaning. You can write down every word the professor says in either the first language or the second language. Of course, during the lecture you write down each word in the language in which the word is shorter. In case of equal lengths of the corresponding words you prefer the word of the first language. You are given the text of the lecture the professor is going to read. Find out how the lecture will be recorded in your notes.
The first line contains two integers, *n* and *m* (1<=≤<=*n*<=≤<=3000, 1<=≤<=*m*<=≤<=3000) — the number of words in the professor's lecture and the number of words in each of these languages. The following *m* lines contain the words. The *i*-th line contains two strings *a**i*, *b**i* meaning that the word *a**i* belongs to the first language, the word *b**i* belongs to the second language, and these two words have the same meaning. It is guaranteed that no word occurs in both languages, and each word occurs in its language exactly once. The next line contains *n* space-separated strings *c*1,<=*c*2,<=...,<=*c**n* — the text of the lecture. It is guaranteed that each of the strings *c**i* belongs to the set of strings {*a*1,<=*a*2,<=... *a**m*}. All the strings in the input are non-empty, each consisting of no more than 10 lowercase English letters.
Output exactly *n* words: how you will record the lecture in your notebook. Output the words of the lecture in the same order as in the input.
[ "4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest\n", "5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll\n" ]
[ "codeforces round letter round\n", "hbnyiyc joll joll un joll\n" ]
none
500
[ { "input": "4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest", "output": "codeforces round letter round" }, { "input": "5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll", "output": "hbnyiyc joll joll un joll" }, { "input": "5 5\nqueyqj f\nb vn\ntabzvk qpfzoqx\nytnyonoc hnxsd\njpggvr lchinjmt\nqueyqj jpggvr b ytnyonoc b", "output": "f jpggvr b hnxsd b" }, { "input": "10 22\nazbrll oen\ngh vdyayei\njphveblohx vfglv\nmfyxib jepnvhcuwo\nrpikazqj uam\nl rx\nokjenof qpnyi\nj tixqrno\nod itozmfct\nikkdxmirx ev\nqexftojc p\nkdazb zjs\nmbk ykvqjrxaxu\nhbcwhouzq pwt\nmirpsz zfaegpl\nuhkkvcj rlvwj\nef iqnnwtolrc\npjzfcpmeag ecdayth\nsa qcthz\ncbfhfxi qrnbvdryz\nwqel tj\natx smkbid\nef hbcwhouzq cbfhfxi hbcwhouzq mirpsz cbfhfxi cbfhfxi okjenof pjzfcpmeag kdazb", "output": "ef pwt cbfhfxi pwt mirpsz cbfhfxi cbfhfxi qpnyi ecdayth zjs" }, { "input": "1 1\namit am\namit", "output": "am" }, { "input": "1 1\na c\na", "output": "a" } ]
1,603,355,104
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
61
0
n, m = map(int, input().split()) d = {} for _ in range(m): a, b = input().split() d[a] = b d[b] = a c = list(input().split()) res = [] for w in c: m = w if len(w) < len(d[w]) else d[w] res.append(m) print(*res)
Title: Lecture Time Limit: None seconds Memory Limit: None megabytes Problem Description: You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes. You know two languages, and the professor is giving the lecture in the first one. The words in both languages consist of lowercase English characters, each language consists of several words. For each language, all words are distinct, i.e. they are spelled differently. Moreover, the words of these languages have a one-to-one correspondence, that is, for each word in each language, there exists exactly one word in the other language having has the same meaning. You can write down every word the professor says in either the first language or the second language. Of course, during the lecture you write down each word in the language in which the word is shorter. In case of equal lengths of the corresponding words you prefer the word of the first language. You are given the text of the lecture the professor is going to read. Find out how the lecture will be recorded in your notes. Input Specification: The first line contains two integers, *n* and *m* (1<=≤<=*n*<=≤<=3000, 1<=≤<=*m*<=≤<=3000) — the number of words in the professor's lecture and the number of words in each of these languages. The following *m* lines contain the words. The *i*-th line contains two strings *a**i*, *b**i* meaning that the word *a**i* belongs to the first language, the word *b**i* belongs to the second language, and these two words have the same meaning. It is guaranteed that no word occurs in both languages, and each word occurs in its language exactly once. The next line contains *n* space-separated strings *c*1,<=*c*2,<=...,<=*c**n* — the text of the lecture. It is guaranteed that each of the strings *c**i* belongs to the set of strings {*a*1,<=*a*2,<=... *a**m*}. All the strings in the input are non-empty, each consisting of no more than 10 lowercase English letters. Output Specification: Output exactly *n* words: how you will record the lecture in your notebook. Output the words of the lecture in the same order as in the input. Demo Input: ['4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest\n', '5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll\n'] Demo Output: ['codeforces round letter round\n', 'hbnyiyc joll joll un joll\n'] Note: none
```python n, m = map(int, input().split()) d = {} for _ in range(m): a, b = input().split() d[a] = b d[b] = a c = list(input().split()) res = [] for w in c: m = w if len(w) < len(d[w]) else d[w] res.append(m) print(*res) ```
0
792
C
Divide by Three
PROGRAMMING
2,000
[ "dp", "greedy", "math", "number theory" ]
null
null
A positive integer number *n* is written on a blackboard. It consists of not more than 105 digits. You have to transform it into a beautiful number by erasing some of the digits, and you want to erase as few digits as possible. The number is called beautiful if it consists of at least one digit, doesn't have leading zeroes and is a multiple of 3. For example, 0, 99, 10110 are beautiful numbers, and 00, 03, 122 are not. Write a program which for the given *n* will find a beautiful number such that *n* can be transformed into this number by erasing as few digits as possible. You can erase an arbitraty set of digits. For example, they don't have to go one after another in the number *n*. If it's impossible to obtain a beautiful number, print -1. If there are multiple answers, print any of them.
The first line of input contains *n* — a positive integer number without leading zeroes (1<=≤<=*n*<=&lt;<=10100000).
Print one number — any beautiful number obtained by erasing as few as possible digits. If there is no answer, print <=-<=1.
[ "1033\n", "10\n", "11\n" ]
[ "33\n", "0\n", "-1\n" ]
In the first example it is enough to erase only the first digit to obtain a multiple of 3. But if we erase the first digit, then we obtain a number with a leading zero. So the minimum number of digits to be erased is two.
0
[ { "input": "1033", "output": "33" }, { "input": "10", "output": "0" }, { "input": "11", "output": "-1" }, { "input": "3", "output": "3" }, { "input": "1", "output": "-1" }, { "input": "117", "output": "117" }, { "input": "518", "output": "18" }, { "input": "327", "output": "327" }, { "input": "270461", "output": "70461" }, { "input": "609209", "output": "60909" }, { "input": "110930", "output": "930" }, { "input": "37616145150713688775", "output": "3616145150713688775" }, { "input": "98509135612114839419", "output": "9509135612114839419" }, { "input": "41674994051436988162", "output": "1674994051436988162" }, { "input": "82547062721736129804", "output": "82547062721736129804" }, { "input": "4902501252475186372406731932548506197390793597574544727433297197476846519276598727359617092494798814", "output": "490501252475186372406731932548506197390793597574544727433297197476846519276598727359617092494798814" }, { "input": "1291007209605301446874998623691572528836214969878676835460982410817526074579818247646933326771899122", "output": "1291007209605301446874998623691572528836214969878676835460982410817526074579818247646933326771899122" }, { "input": "5388306043547446322173224045662327678394712363272776811399689704247387317165308057863239568137902157", "output": "538830603547446322173224045662327678394712363272776811399689704247387317165308057863239568137902157" }, { "input": "20000111", "output": "200001" }, { "input": "100222", "output": "1002" }, { "input": "202", "output": "0" }, { "input": "100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000033", "output": "33" }, { "input": "101", "output": "0" }, { "input": "1000000222", "output": "10000002" }, { "input": "1001", "output": "0" }, { "input": "205", "output": "0" }, { "input": "102211", "output": "10221" }, { "input": "100000002022", "output": "1000000002" }, { "input": "20203", "output": "3" }, { "input": "1002001", "output": "100200" }, { "input": "10002223", "output": "100023" }, { "input": "1002223", "output": "10023" }, { "input": "100000231", "output": "10000023" }, { "input": "220", "output": "0" }, { "input": "322", "output": "3" }, { "input": "100000222", "output": "1000002" }, { "input": "10033", "output": "33" }, { "input": "2003302", "output": "330" }, { "input": "10011001", "output": "1001001" }, { "input": "20000000011001111", "output": "200000000001111" }, { "input": "100000000", "output": "0" }, { "input": "1000", "output": "0" }, { "input": "200000000000000000000000000008", "output": "0" }, { "input": "1000000000000222", "output": "10000000000002" }, { "input": "100000000000000000222", "output": "1000000000000000002" }, { "input": "29512", "output": "2952" }, { "input": "88888888888888", "output": "888888888888" }, { "input": "100000000000222", "output": "1000000000002" }, { "input": "11000000", "output": "0" }, { "input": "2200", "output": "0" }, { "input": "10000555", "output": "100005" }, { "input": "1000222", "output": "10002" }, { "input": "10021", "output": "1002" }, { "input": "223", "output": "3" }, { "input": "1013", "output": "3" }, { "input": "100020001", "output": "10002000" }, { "input": "20000000000000000000932", "output": "93" }, { "input": "1010", "output": "0" }, { "input": "2000000002222", "output": "20000000022" }, { "input": "10213", "output": "1023" }, { "input": "109111", "output": "10911" }, { "input": "1010101010", "output": "10001010" }, { "input": "300055", "output": "3000" }, { "input": "200200", "output": "0" }, { "input": "202222", "output": "2022" }, { "input": "4000888", "output": "40008" }, { "input": "200000111", "output": "2000001" }, { "input": "2000000111", "output": "20000001" }, { "input": "1000000", "output": "0" }, { "input": "1003301", "output": "330" }, { "input": "100001", "output": "0" }, { "input": "40000000000000000000888", "output": "400000000000000000008" }, { "input": "100000", "output": "0" }, { "input": "4000000888", "output": "40000008" }, { "input": "334733", "output": "3333" }, { "input": "1000002220", "output": "10000020" }, { "input": "100321", "output": "10032" }, { "input": "101111", "output": "1011" }, { "input": "100000000222", "output": "1000000002" }, { "input": "10001", "output": "0" }, { "input": "7", "output": "-1" }, { "input": "2000000000111", "output": "20000000001" }, { "input": "100000001", "output": "0" }, { "input": "10000000000222", "output": "100000000002" }, { "input": "200000000000000111", "output": "2000000000000001" }, { "input": "404044", "output": "40044" }, { "input": "30202", "output": "300" }, { "input": "20000000000000000111", "output": "200000000000000001" }, { "input": "707", "output": "0" }, { "input": "20000300000000003000050000003", "output": "30000000000300000000003" }, { "input": "400000888", "output": "4000008" }, { "input": "2888", "output": "888" }, { "input": "200111", "output": "2001" }, { "input": "10000000888", "output": "100000008" }, { "input": "40000888", "output": "400008" }, { "input": "40404044", "output": "400044" }, { "input": "5500000000", "output": "0" }, { "input": "100012", "output": "10002" }, { "input": "1000007", "output": "0" }, { "input": "200093", "output": "93" }, { "input": "10000000222", "output": "100000002" }, { "input": "20000000002", "output": "0" }, { "input": "74333", "output": "333" }, { "input": "200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008", "output": "0" }, { "input": "10000000111", "output": "1000000011" }, { "input": "100007", "output": "0" }, { "input": "20000006711", "output": "200000061" }, { "input": "8059", "output": "9" }, { "input": "8008", "output": "0" }, { "input": "88", "output": "-1" }, { "input": "2002", "output": "0" }, { "input": "2000111", "output": "20001" }, { "input": "100000000100000002", "output": "10000000000000002" }, { "input": "1000000000000000000000000000000000", "output": "0" }, { "input": "10000000000000000222", "output": "100000000000000002" }, { "input": "1000001", "output": "0" }, { "input": "200000000000111", "output": "2000000000001" }, { "input": "2000000002", "output": "0" }, { "input": "2010000100001", "output": "10000100001" }, { "input": "200330", "output": "330" }, { "input": "10000222", "output": "100002" }, { "input": "2005", "output": "0" }, { "input": "100000000000822", "output": "1000000000002" }, { "input": "10000000000000000000000", "output": "0" }, { "input": "7046", "output": "6" }, { "input": "4000117", "output": "400017" }, { "input": "971", "output": "9" }, { "input": "404", "output": "0" }, { "input": "5", "output": "-1" }, { "input": "164", "output": "6" }, { "input": "140", "output": "0" }, { "input": "74", "output": "-1" }, { "input": "2058232", "output": "20232" }, { "input": "4", "output": "-1" }, { "input": "20206", "output": "6" }, { "input": "103310", "output": "330" }, { "input": "100", "output": "0" }, { "input": "417179", "output": "7179" }, { "input": "70558", "output": "558" }, { "input": "298", "output": "9" }, { "input": "7003", "output": "3" }, { "input": "2212", "output": "222" }, { "input": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001", "output": "0" }, { "input": "2000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002", "output": "0" }, { "input": "1002200", "output": "100200" }, { "input": "1222", "output": "222" }, { "input": "101200100", "output": "10100100" }, { "input": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003", "output": "3" }, { "input": "20020201", "output": "2002020" }, { "input": "12122", "output": "1122" }, { "input": "20200", "output": "0" }, { "input": "2", "output": "-1" }, { "input": "1000000000000258", "output": "10000000000008" } ]
1,676,489,631
2,147,483,647
PyPy 3-64
RUNTIME_ERROR
TESTS
3
93
3,891,200
n = input() l = len(n) def erase(s,num,count): t = s[:] cnt = count for i in range(l-1,-1,-1): if (int(t[i]) % 3 == num): t = t[:i] + t[i+1:] cnt -= 1 if cnt == 0: break if cnt > 0: return "" i = 0 while (len(t) > 1 and t[0] == '0'): t = t[1:] return t mod_sum = 0 for i in range(l): mod_sum = (mod_sum + int(n[i])) % 3 if (mod_sum == 0): print(n) elif (mod_sum == 1): n1 = erase(n,1,1) n2 = erase(n,2,2) else: n1 = erase(n,2,1) n2 = erase(n,2,2) if len(n1) == 0 and len(n2) == 0: print("-1") elif len(n1) >= len(n2): print(n1) else: print(n2)
Title: Divide by Three Time Limit: None seconds Memory Limit: None megabytes Problem Description: A positive integer number *n* is written on a blackboard. It consists of not more than 105 digits. You have to transform it into a beautiful number by erasing some of the digits, and you want to erase as few digits as possible. The number is called beautiful if it consists of at least one digit, doesn't have leading zeroes and is a multiple of 3. For example, 0, 99, 10110 are beautiful numbers, and 00, 03, 122 are not. Write a program which for the given *n* will find a beautiful number such that *n* can be transformed into this number by erasing as few digits as possible. You can erase an arbitraty set of digits. For example, they don't have to go one after another in the number *n*. If it's impossible to obtain a beautiful number, print -1. If there are multiple answers, print any of them. Input Specification: The first line of input contains *n* — a positive integer number without leading zeroes (1<=≤<=*n*<=&lt;<=10100000). Output Specification: Print one number — any beautiful number obtained by erasing as few as possible digits. If there is no answer, print <=-<=1. Demo Input: ['1033\n', '10\n', '11\n'] Demo Output: ['33\n', '0\n', '-1\n'] Note: In the first example it is enough to erase only the first digit to obtain a multiple of 3. But if we erase the first digit, then we obtain a number with a leading zero. So the minimum number of digits to be erased is two.
```python n = input() l = len(n) def erase(s,num,count): t = s[:] cnt = count for i in range(l-1,-1,-1): if (int(t[i]) % 3 == num): t = t[:i] + t[i+1:] cnt -= 1 if cnt == 0: break if cnt > 0: return "" i = 0 while (len(t) > 1 and t[0] == '0'): t = t[1:] return t mod_sum = 0 for i in range(l): mod_sum = (mod_sum + int(n[i])) % 3 if (mod_sum == 0): print(n) elif (mod_sum == 1): n1 = erase(n,1,1) n2 = erase(n,2,2) else: n1 = erase(n,2,1) n2 = erase(n,2,2) if len(n1) == 0 and len(n2) == 0: print("-1") elif len(n1) >= len(n2): print(n1) else: print(n2) ```
-1
141
A
Amusing Joke
PROGRAMMING
800
[ "implementation", "sortings", "strings" ]
null
null
So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's name and the host's name in honor of this event. Then the hung the letters above the main entrance. One night, when everyone went to bed, someone took all the letters of our characters' names. Then he may have shuffled the letters and put them in one pile in front of the door. The next morning it was impossible to find the culprit who had made the disorder. But everybody wondered whether it is possible to restore the names of the host and his guests from the letters lying at the door? That is, we need to verify that there are no extra letters, and that nobody will need to cut more letters. Help the "New Year and Christmas Men" and their friends to cope with this problem. You are given both inscriptions that hung over the front door the previous night, and a pile of letters that were found at the front door next morning.
The input file consists of three lines: the first line contains the guest's name, the second line contains the name of the residence host and the third line contains letters in a pile that were found at the door in the morning. All lines are not empty and contain only uppercase Latin letters. The length of each line does not exceed 100.
Print "YES" without the quotes, if the letters in the pile could be permuted to make the names of the "New Year and Christmas Men". Otherwise, print "NO" without the quotes.
[ "SANTACLAUS\nDEDMOROZ\nSANTAMOROZDEDCLAUS\n", "PAPAINOEL\nJOULUPUKKI\nJOULNAPAOILELUPUKKI\n", "BABBONATALE\nFATHERCHRISTMAS\nBABCHRISTMASBONATALLEFATHER\n" ]
[ "YES\n", "NO\n", "NO\n" ]
In the first sample the letters written in the last line can be used to write the names and there won't be any extra letters left. In the second sample letter "P" is missing from the pile and there's an extra letter "L". In the third sample there's an extra letter "L".
500
[ { "input": "SANTACLAUS\nDEDMOROZ\nSANTAMOROZDEDCLAUS", "output": "YES" }, { "input": "PAPAINOEL\nJOULUPUKKI\nJOULNAPAOILELUPUKKI", "output": "NO" }, { "input": "BABBONATALE\nFATHERCHRISTMAS\nBABCHRISTMASBONATALLEFATHER", "output": "NO" }, { "input": "B\nA\nAB", "output": "YES" }, { "input": "ONDOL\nJNPB\nONLNJBODP", "output": "YES" }, { "input": "Y\nW\nYW", "output": "YES" }, { "input": "OI\nM\nIMO", "output": "YES" }, { "input": "VFQRWWWACX\nGHZJPOQUSXRAQDGOGMR\nOPAWDOUSGWWCGQXXQAZJRQRGHRMVF", "output": "YES" }, { "input": "JUTCN\nPIGMZOPMEUFADQBW\nNWQGZMAIPUPOMCDUB", "output": "NO" }, { "input": "Z\nO\nZOCNDOLTBZKQLTBOLDEGXRHZGTTPBJBLSJCVSVXISQZCSFDEBXRCSGBGTHWOVIXYHACAGBRYBKBJAEPIQZHVEGLYH", "output": "NO" }, { "input": "IQ\nOQ\nQOQIGGKFNHJSGCGM", "output": "NO" }, { "input": "ROUWANOPNIGTVMIITVMZ\nOQTUPZMTKUGY\nVTVNGZITGPUNPMQOOATUUIYIWMMKZOTR", "output": "YES" }, { "input": "OVQELLOGFIOLEHXMEMBJDIGBPGEYFG\nJNKFPFFIJOFHRIFHXEWYZOPDJBZTJZKBWQTECNHRFSJPJOAPQT\nYAIPFFFEXJJNEJPLREIGODEGQZVMCOBDFKWTMWJSBEBTOFFQOHIQJLHFNXIGOHEZRZLFOKJBJPTPHPGY", "output": "YES" }, { "input": "NBJGVNGUISUXQTBOBKYHQCOOVQWUXWPXBUDLXPKX\nNSFQDFUMQDQWQ\nWXKKVNTDQQFXCUQBIMQGQHSLVGWSBFYBUPOWPBDUUJUXQNOQDNXOX", "output": "YES" }, { "input": "IJHHGKCXWDBRWJUPRDBZJLNTTNWKXLUGJSBWBOAUKWRAQWGFNL\nNJMWRMBCNPHXTDQQNZ\nWDNJRCLILNQRHWBANLTXWMJBPKUPGKJDJZAQWKTZFBRCTXHHBNXRGUQUNBNMWODGSJWW", "output": "YES" }, { "input": "SRROWANGUGZHCIEFYMQVTWVOMDWPUZJFRDUMVFHYNHNTTGNXCJ\nDJYWGLBFCCECXFHOLORDGDCNRHPWXNHXFCXQCEZUHRRNAEKUIX\nWCUJDNYHNHYOPWMHLDCDYRWBVOGHFFUKOZTXJRXJHRGWICCMRNEVNEGQWTZPNFCSHDRFCFQDCXMHTLUGZAXOFNXNVGUEXIACRERU", "output": "YES" }, { "input": "H\nJKFGHMIAHNDBMFXWYQLZRSVNOTEGCQSVUBYUOZBTNKTXPFQDCMKAGFITEUGOYDFIYQIORMFJEOJDNTFVIQEBICSNGKOSNLNXJWC\nBQSVDOGIHCHXSYNYTQFCHNJGYFIXTSOQINZOKSVQJMTKNTGFNXAVTUYEONMBQMGJLEWJOFGEARIOPKFUFCEMUBRBDNIIDFZDCLWK", "output": "YES" }, { "input": "DSWNZRFVXQ\nPVULCZGOOU\nUOLVZXNUPOQRZGWFVDSCANQTCLEIE", "output": "NO" }, { "input": "EUHTSCENIPXLTSBMLFHD\nIZAVSZPDLXOAGESUSE\nLXAELAZ", "output": "NO" }, { "input": "WYSJFEREGELSKRQRXDXCGBODEFZVSI\nPEJKMGFLBFFDWRCRFSHVEFLEBTJCVCHRJTLDTISHPOGFWPLEWNYJLMXWIAOTYOXMV\nHXERTZWLEXTPIOTFRVMEJVYFFJLRPFMXDEBNSGCEOFFCWTKIDDGCFYSJKGLHBORWEPLDRXRSJYBGASSVCMHEEJFLVI", "output": "NO" }, { "input": "EPBMDIUQAAUGLBIETKOKFLMTCVEPETWJRHHYKCKU\nHGMAETVPCFZYNNKDQXVXUALHYLOTCHM\nECGXACVKEYMCEDOTMKAUFHLHOMT", "output": "NO" }, { "input": "NUBKQEJHALANSHEIFUZHYEZKKDRFHQKAJHLAOWTZIMOCWOVVDW\nEFVOBIGAUAUSQGVSNBKNOBDMINODMFSHDL\nKLAMKNTHBFFOHVKWICHBKNDDQNEISODUSDNLUSIOAVWY", "output": "NO" }, { "input": "VXINHOMEQCATZUGAJEIUIZZLPYFGUTVLNBNWCUVMEENUXKBWBGZTMRJJVJDLVSLBABVCEUDDSQFHOYPYQTWVAGTWOLKYISAGHBMC\nZMRGXPZSHOGCSAECAPGVOIGCWEOWWOJXLGYRDMPXBLOKZVRACPYQLEQGFQCVYXAGBEBELUTDAYEAGPFKXRULZCKFHZCHVCWIRGPK\nRCVUXGQVNWFGRUDLLENNDQEJHYYVWMKTLOVIPELKPWCLSQPTAXAYEMGWCBXEVAIZGGDDRBRT", "output": "NO" }, { "input": "PHBDHHWUUTZAHELGSGGOPOQXSXEZIXHZTOKYFBQLBDYWPVCNQSXHEAXRRPVHFJBVBYCJIFOTQTWSUOWXLKMVJJBNLGTVITWTCZZ\nFUPDLNVIHRWTEEEHOOEC\nLOUSUUSZCHJBPEWIILUOXEXRQNCJEGTOBRVZLTTZAHTKVEJSNGHFTAYGY", "output": "NO" }, { "input": "GDSLNIIKTO\nJF\nPDQYFKDTNOLI", "output": "NO" }, { "input": "AHOKHEKKPJLJIIWJRCGY\nORELJCSIX\nZVWPXVFWFSWOXXLIHJKPXIOKRELYE", "output": "NO" }, { "input": "ZWCOJFORBPHXCOVJIDPKVECMHVHCOC\nTEV\nJVGTBFTLFVIEPCCHODOFOMCVZHWXVCPEH", "output": "NO" }, { "input": "AGFIGYWJLVMYZGNQHEHWKJIAWBPUAQFERMCDROFN\nPMJNHMVNRGCYZAVRWNDSMLSZHFNYIUWFPUSKKIGU\nMCDVPPRXGUAYLSDRHRURZASXUWZSIIEZCPXUVEONKNGNWRYGOSFMCKESMVJZHWWUCHWDQMLASLNNMHAU", "output": "NO" }, { "input": "XLOWVFCZSSXCSYQTIIDKHNTKNKEEDFMDZKXSPVLBIDIREDUAIN\nZKIWNDGBISDB\nSLPKLYFYSRNRMOSWYLJJDGFFENPOXYLPZFTQDANKBDNZDIIEWSUTTKYBKVICLG", "output": "NO" }, { "input": "PMUKBTRKFIAYVGBKHZHUSJYSSEPEOEWPOSPJLWLOCTUYZODLTUAFCMVKGQKRRUSOMPAYOTBTFPXYAZXLOADDEJBDLYOTXJCJYTHA\nTWRRAJLCQJTKOKWCGUH\nEWDPNXVCXWCDQCOYKKSOYTFSZTOOPKPRDKFJDETKSRAJRVCPDOBWUGPYRJPUWJYWCBLKOOTUPBESTOFXZHTYLLMCAXDYAEBUTAHM", "output": "NO" }, { "input": "QMIMGQRQDMJDPNFEFXSXQMCHEJKTWCTCVZPUAYICOIRYOWKUSIWXJLHDYWSBOITHTMINXFKBKAWZTXXBJIVYCRWKXNKIYKLDDXL\nV\nFWACCXBVDOJFIUAVYRALBYJKXXWIIFORRUHKHCXLDBZMXIYJWISFEAWTIQFIZSBXMKNOCQKVKRWDNDAMQSTKYLDNYVTUCGOJXJTW", "output": "NO" }, { "input": "XJXPVOOQODELPPWUISSYVVXRJTYBPDHJNENQEVQNVFIXSESKXVYPVVHPMOSX\nLEXOPFPVPSZK\nZVXVPYEYOYXVOISVLXPOVHEQVXPNQJIOPFDTXEUNMPEPPHELNXKKWSVSOXSBPSJDPVJVSRFQ", "output": "YES" }, { "input": "OSKFHGYNQLSRFSAHPXKGPXUHXTRBJNAQRBSSWJVEENLJCDDHFXVCUNPZAIVVO\nFNUOCXAGRRHNDJAHVVLGGEZQHWARYHENBKHP\nUOEFNWVXCUNERLKVTHAGPSHKHDYFPYWZHJKHQLSNFBJHVJANRXCNSDUGVDABGHVAOVHBJZXGRACHRXEGNRPQEAPORQSILNXFS", "output": "YES" }, { "input": "VYXYVVACMLPDHONBUTQFZTRREERBLKUJYKAHZRCTRLRCLOZYWVPBRGDQPFPQIF\nFE\nRNRPEVDRLYUQFYRZBCQLCYZEABKLRXCJLKVZBVFUEYRATOMDRTHFPGOWQVTIFPPH", "output": "YES" }, { "input": "WYXUZQJQNLASEGLHPMSARWMTTQMQLVAZLGHPIZTRVTCXDXBOLNXZPOFCTEHCXBZ\nBLQZRRWP\nGIQZXPLTTMNHQVWPPEAPLOCDMBSTHRCFLCQRRZXLVAOQEGZBRUZJXXZTMAWLZHSLWNQTYXB", "output": "YES" }, { "input": "MKVJTSSTDGKPVVDPYSRJJYEVGKBMSIOKHLZQAEWLRIBINVRDAJIBCEITKDHUCCVY\nPUJJQFHOGZKTAVNUGKQUHMKTNHCCTI\nQVJKUSIGTSVYUMOMLEGHWYKSKQTGATTKBNTKCJKJPCAIRJIRMHKBIZISEGFHVUVQZBDERJCVAKDLNTHUDCHONDCVVJIYPP", "output": "YES" }, { "input": "OKNJOEYVMZXJMLVJHCSPLUCNYGTDASKSGKKCRVIDGEIBEWRVBVRVZZTLMCJLXHJIA\nDJBFVRTARTFZOWN\nAGHNVUNJVCPLWSVYBJKZSVTFGLELZASLWTIXDDJXCZDICTVIJOTMVEYOVRNMJGRKKHRMEBORAKFCZJBR", "output": "YES" }, { "input": "OQZACLPSAGYDWHFXDFYFRRXWGIEJGSXWUONAFWNFXDTGVNDEWNQPHUXUJNZWWLBPYL\nOHBKWRFDRQUAFRCMT\nWIQRYXRJQWWRUWCYXNXALKFZGXFTLOODWRDPGURFUFUQOHPWBASZNVWXNCAGHWEHFYESJNFBMNFDDAPLDGT", "output": "YES" }, { "input": "OVIRQRFQOOWVDEPLCJETWQSINIOPLTLXHSQWUYUJNFBMKDNOSHNJQQCDHZOJVPRYVSV\nMYYDQKOOYPOOUELCRIT\nNZSOTVLJTTVQLFHDQEJONEOUOFOLYVSOIYUDNOSIQVIRMVOERCLMYSHPCQKIDRDOQPCUPQBWWRYYOXJWJQPNKH", "output": "YES" }, { "input": "WGMBZWNMSJXNGDUQUJTCNXDSJJLYRDOPEGPQXYUGBESDLFTJRZDDCAAFGCOCYCQMDBWK\nYOBMOVYTUATTFGJLYUQD\nDYXVTLQCYFJUNJTUXPUYOPCBCLBWNSDUJRJGWDOJDSQAAMUOJWSYERDYDXYTMTOTMQCGQZDCGNFBALGGDFKZMEBG", "output": "YES" }, { "input": "CWLRBPMEZCXAPUUQFXCUHAQTLPBTXUUKWVXKBHKNSSJFEXLZMXGVFHHVTPYAQYTIKXJJE\nMUFOSEUEXEQTOVLGDSCWM\nJUKEQCXOXWEHCGKFPBIGMWVJLXUONFXBYTUAXERYTXKCESKLXAEHVPZMMUFTHLXTTZSDMBJLQPEUWCVUHSQQVUASPF", "output": "YES" }, { "input": "IDQRX\nWETHO\nODPDGBHVUVSSISROHQJTUKPUCLXABIZQQPPBPKOSEWGEHRSRRNBAVLYEMZISMWWGKHVTXKUGUXEFBSWOIWUHRJGMWBMHQLDZHBWA", "output": "NO" }, { "input": "IXFDY\nJRMOU\nDF", "output": "NO" }, { "input": "JPSPZ\nUGCUB\nJMZZZZZZZZ", "output": "NO" }, { "input": "AC\nA\nBBA", "output": "NO" }, { "input": "UIKWWKXLSHTOOZOVGXKYSOJEHAUEEG\nKZXQDWJJWRXFHKJDQHJK\nXMZHTFOGEXAUJXXJUYVJIFOTKLZHDKELJWERHMGAWGKWAQKEKHIDWGGZVYOHKXRPWSJDPESFJUMKQYWBYUTHQYEFZUGKQOBHYDWB", "output": "NO" }, { "input": "PXWRXRPFLR\nPJRWWXIVHODV\nXW", "output": "NO" }, { "input": "CHTAZVHGSHCVIBK\nEQINEBKXEPYJSAZIMLDF\nZCZZZZDZMCZZEZDZZEZZZZQZZBZZZOZZCZE", "output": "NO" }, { "input": "GXPZFSELJJNDAXYRV\nUYBKPMVBSOVOJWMONLTJOJCNQKMTAHEWLHOWIIBH\nHCWNFWJPEJIWOVPTBMVCRJLSISSVNOHCKLBFMIUAIMASQWPXEYXBOXQGFEMYJLBKDCZIMJNHOJEDGGANIVYKQTUOSOVOPWHVJGXH", "output": "NO" }, { "input": "LFGJCJJDUTUP\nOVSBILTIYCJCRHKCIXCETJQJJ\nGIJJTJCLTJJJ", "output": "NO" }, { "input": "GIO\nPRL\nPRL", "output": "NO" }, { "input": "A\nB\nABC", "output": "NO" }, { "input": "KKK\nKKK\nZZZZZ", "output": "NO" }, { "input": "ZMYGQLDBLAPN\nZFJBKWHROVNPSJQUDFTHOCGREUFLYIWYICD\nZMJZZEDAZANKZZZZZZEZZBZDZZZZZZKHZZFZZZDZNZMDZZA", "output": "NO" } ]
1,685,280,096
2,147,483,647
Python 3
OK
TESTS
54
92
0
a = input() b = input() c = sorted(input()) d = sorted(a+b) if d==c: print('YES') else: print('NO')
Title: Amusing Joke Time Limit: None seconds Memory Limit: None megabytes Problem Description: So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's name and the host's name in honor of this event. Then the hung the letters above the main entrance. One night, when everyone went to bed, someone took all the letters of our characters' names. Then he may have shuffled the letters and put them in one pile in front of the door. The next morning it was impossible to find the culprit who had made the disorder. But everybody wondered whether it is possible to restore the names of the host and his guests from the letters lying at the door? That is, we need to verify that there are no extra letters, and that nobody will need to cut more letters. Help the "New Year and Christmas Men" and their friends to cope with this problem. You are given both inscriptions that hung over the front door the previous night, and a pile of letters that were found at the front door next morning. Input Specification: The input file consists of three lines: the first line contains the guest's name, the second line contains the name of the residence host and the third line contains letters in a pile that were found at the door in the morning. All lines are not empty and contain only uppercase Latin letters. The length of each line does not exceed 100. Output Specification: Print "YES" without the quotes, if the letters in the pile could be permuted to make the names of the "New Year and Christmas Men". Otherwise, print "NO" without the quotes. Demo Input: ['SANTACLAUS\nDEDMOROZ\nSANTAMOROZDEDCLAUS\n', 'PAPAINOEL\nJOULUPUKKI\nJOULNAPAOILELUPUKKI\n', 'BABBONATALE\nFATHERCHRISTMAS\nBABCHRISTMASBONATALLEFATHER\n'] Demo Output: ['YES\n', 'NO\n', 'NO\n'] Note: In the first sample the letters written in the last line can be used to write the names and there won't be any extra letters left. In the second sample letter "P" is missing from the pile and there's an extra letter "L". In the third sample there's an extra letter "L".
```python a = input() b = input() c = sorted(input()) d = sorted(a+b) if d==c: print('YES') else: print('NO') ```
3
580
D
Kefa and Dishes
PROGRAMMING
1,800
[ "bitmasks", "dp" ]
null
null
When Kefa came to the restaurant and sat at a table, the waiter immediately brought him the menu. There were *n* dishes. Kefa knows that he needs exactly *m* dishes. But at that, he doesn't want to order the same dish twice to taste as many dishes as possible. Kefa knows that the *i*-th dish gives him *a**i* units of satisfaction. But some dishes do not go well together and some dishes go very well together. Kefa set to himself *k* rules of eating food of the following type — if he eats dish *x* exactly before dish *y* (there should be no other dishes between *x* and *y*), then his satisfaction level raises by *c*. Of course, our parrot wants to get some maximal possible satisfaction from going to the restaurant. Help him in this hard task!
The first line of the input contains three space-separated numbers, *n*, *m* and *k* (1<=≤<=*m*<=≤<=*n*<=≤<=18, 0<=≤<=*k*<=≤<=*n*<=*<=(*n*<=-<=1)) — the number of dishes on the menu, the number of portions Kefa needs to eat to get full and the number of eating rules. The second line contains *n* space-separated numbers *a**i*, (0<=≤<=*a**i*<=≤<=109) — the satisfaction he gets from the *i*-th dish. Next *k* lines contain the rules. The *i*-th rule is described by the three numbers *x**i*, *y**i* and *c**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*, 0<=≤<=*c**i*<=≤<=109). That means that if you eat dish *x**i* right before dish *y**i*, then the Kefa's satisfaction increases by *c**i*. It is guaranteed that there are no such pairs of indexes *i* and *j* (1<=≤<=*i*<=&lt;<=*j*<=≤<=*k*), that *x**i*<==<=*x**j* and *y**i*<==<=*y**j*.
In the single line of the output print the maximum satisfaction that Kefa can get from going to the restaurant.
[ "2 2 1\n1 1\n2 1 1\n", "4 3 2\n1 2 3 4\n2 1 5\n3 4 2\n" ]
[ "3\n", "12\n" ]
In the first sample it is best to first eat the second dish, then the first one. Then we get one unit of satisfaction for each dish and plus one more for the rule. In the second test the fitting sequences of choice are 4 2 1 or 2 1 4. In both cases we get satisfaction 7 for dishes and also, if we fulfill rule 1, we get an additional satisfaction 5.
2,000
[ { "input": "2 2 1\n1 1\n2 1 1", "output": "3" }, { "input": "4 3 2\n1 2 3 4\n2 1 5\n3 4 2", "output": "12" }, { "input": "1 1 0\n1000000000", "output": "1000000000" }, { "input": "4 2 1\n100 1 2 200\n2 3 400", "output": "403" }, { "input": "7 4 3\n2 6 13 5 7 1 9\n6 1 15\n2 5 3\n6 4 8", "output": "40" }, { "input": "5 5 5\n3 3 3 3 3\n3 4 6\n4 1 2\n1 5 7\n5 2 4\n2 3 5", "output": "37" }, { "input": "5 4 1\n1000000000 500000000 1 1000000000 1000000000\n3 5 700000000", "output": "3700000001" }, { "input": "6 3 6\n2 3 4 1 5 6\n1 5 3\n5 1 4\n2 6 1\n2 4 3\n3 5 3\n4 5 6", "output": "18" }, { "input": "10 5 5\n45 45 12 67 32 6 125 33 89 100\n6 3 78\n1 2 23\n5 7 17\n9 2 90\n4 8 39", "output": "516" }, { "input": "18 2 4\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0\n18 2 5\n7 8 3\n1 18 2\n6 4 1", "output": "6" }, { "input": "4 2 0\n1 2 3 2", "output": "5" }, { "input": "7 1 21\n15 11 13 13 15 8 5\n4 1 14\n7 2 5\n3 2 11\n6 4 19\n3 1 12\n1 3 9\n3 6 12\n2 5 10\n5 7 14\n2 6 5\n5 2 19\n7 5 9\n4 2 19\n5 1 6\n6 2 7\n1 7 6\n2 4 15\n7 4 10\n2 7 19\n4 5 14\n6 7 8", "output": "15" }, { "input": "8 4 56\n59 78 6 55 79 70 25 2\n1 2 47\n7 6 41\n5 1 28\n7 1 8\n5 8 7\n3 5 6\n3 6 5\n8 6 55\n2 4 44\n4 6 8\n3 7 95\n8 7 96\n6 2 11\n4 1 24\n6 5 86\n4 7 98\n2 6 24\n8 5 31\n5 3 35\n5 4 30\n4 8 52\n5 6 8\n8 1 71\n6 7 48\n1 4 39\n2 5 88\n2 3 18\n5 7 30\n2 1 32\n1 8 86\n6 1 30\n2 8 1\n3 4 16\n7 2 56\n5 2 28\n6 3 5\n1 6 24\n8 2 61\n4 5 58\n1 7 82\n4 2 58\n4 3 60\n3 8 26\n6 4 88\n7 4 32\n2 7 58\n8 4 22\n7 3 2\n7 8 61\n7 5 76\n1 3 17\n1 5 50\n3 2 4\n3 1 44\n6 8 89\n8 3 41", "output": "516" }, { "input": "8 8 7\n0 0 0 0 0 0 0 0\n1 5 97132661\n5 2 199172588\n2 7 815407164\n7 3 938757689\n3 8 843668614\n8 4 560487634\n4 6 244729651", "output": "3699356001" }, { "input": "14 14 13\n0 0 0 0 0 0 0 0 0 0 0 0 0 0\n6 4 4\n4 8 6\n8 3 6\n3 12 1\n12 14 5\n14 2 4\n2 10 5\n10 1 2\n1 9 4\n9 7 8\n7 13 1\n13 11 5\n11 5 1", "output": "52" }, { "input": "15 15 14\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n2 6 57661\n6 15 67617\n15 10 81652\n10 1 16278\n1 14 3009\n14 11 33687\n11 3 62989\n3 9 96410\n9 13 91302\n13 5 86368\n5 12 2182\n12 4 16546\n4 8 12851\n8 7 26224", "output": "654776" }, { "input": "15 15 14\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n7 11 6827\n11 5 7756\n5 14 6186\n14 8 1460\n8 13 1620\n13 9 1232\n9 15 7361\n15 3 2850\n3 4 4479\n4 2 6756\n2 6 3449\n6 10 8684\n10 1 6984\n1 12 2948", "output": "68592" }, { "input": "16 16 15\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n1 4 565659444\n4 11 593187381\n11 16 541913119\n16 14 657168751\n14 12 500399857\n12 6 662036115\n6 10 647286834\n10 3 579955363\n3 15 568540410\n15 5 581760329\n5 9 609894501\n9 13 537885589\n13 8 504299990\n8 2 656459498\n2 7 514164539", "output": "8720611720" }, { "input": "16 12 2\n215685056 606689499 786509392 322681480 170763622 255981931 402020260 580776290 525819654 50248606 830314959 223078821 851769718 76817680 251067040 491418559\n14 4 951819487\n4 2 770897556", "output": "7704583505" }, { "input": "17 17 16\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n11 7 231657830\n7 5 232292501\n5 8 231939378\n8 4 224957214\n4 12 229241817\n12 1 231562923\n1 3 226465387\n3 16 230627405\n16 10 229220153\n10 9 228646517\n9 2 230321133\n2 17 232190045\n17 6 229133406\n6 15 227156658\n15 13 228664795\n13 14 228903543", "output": "3672980705" }, { "input": "18 18 17\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n4 17 510748572\n17 10 696685757\n10 15 161105419\n15 1 126069679\n1 2 837682033\n2 12 436383858\n12 9 267569422\n9 16 881873714\n16 11 735761535\n11 6 259423529\n6 5 263222337\n5 18 697008445\n18 13 962557222\n13 7 790468460\n7 8 13582102\n8 14 510800814\n14 3 880706849", "output": "9031649747" }, { "input": "18 18 17\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n2 1 34349196\n1 8 40123769\n8 9 52139422\n9 15 10987402\n15 16 61786095\n16 12 77282765\n12 4 18495873\n4 11 85323692\n11 10 28529557\n10 5 53623688\n5 18 40093687\n18 3 67739085\n3 14 68785388\n14 6 65567931\n6 17 48915166\n17 7 27948918\n7 13 70519650", "output": "852211284" }, { "input": "18 17 16\n298794979 56088167 220017066 212013239 193074498 269869999 238524920 107690830 236214025 114513789 305713075 41451289 198089336 246759776 267311824 142373649 312495533 217782770\n9 4 70536531\n13 14 235114377\n18 4 38527037\n3 7 39141694\n1 17 15392162\n6 17 35451325\n17 14 2959732\n13 10 244941239\n12 4 249018275\n15 16 20714817\n1 2 37731505\n9 18 28754011\n4 17 56009536\n5 6 273584878\n6 4 291865229\n17 16 249459905", "output": "4858815472" }, { "input": "18 18 0\n115005244 38190165 126325576 840509301 765839937 656684780 596662787 415309843 853044850 645116094 328898380 458939277 646488701 699003763 666873084 991845119 532882957 385678203", "output": "9763298061" }, { "input": "18 18 3\n759507857 606098930 900220927 233055471 218518255 171579924 442155777 996213891 751779343 197968566 990617245 159772960 717293019 848554997 726485601 13147425 265922263 562203963\n13 4 408141884\n3 2 213428327\n10 17 126413702", "output": "10309080327" }, { "input": "18 18 17\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n7 2 554462987\n2 4 444921228\n4 6 157507820\n6 10 900032432\n10 9 888093209\n9 17 115896460\n17 5 904317029\n5 12 581655689\n12 3 743717743\n3 13 692735618\n13 11 607064833\n11 18 677893322\n18 1 909539256\n1 14 619680883\n14 15 933580266\n15 8 932409037\n8 16 555252931", "output": "11218760743" }, { "input": "18 18 17\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n18 1 1000000000\n1 5 1000000000\n5 13 1000000000\n13 16 1000000000\n16 17 1000000000\n17 7 1000000000\n7 9 1000000000\n9 6 1000000000\n6 15 1000000000\n15 14 1000000000\n14 12 1000000000\n12 4 1000000000\n4 8 1000000000\n8 10 1000000000\n10 3 1000000000\n3 11 1000000000\n11 2 1000000000", "output": "17000000000" } ]
1,690,489,141
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
46
0
print("_RANDOM_GUESS_1690489141.6887803")# 1690489141.6887987
Title: Kefa and Dishes Time Limit: None seconds Memory Limit: None megabytes Problem Description: When Kefa came to the restaurant and sat at a table, the waiter immediately brought him the menu. There were *n* dishes. Kefa knows that he needs exactly *m* dishes. But at that, he doesn't want to order the same dish twice to taste as many dishes as possible. Kefa knows that the *i*-th dish gives him *a**i* units of satisfaction. But some dishes do not go well together and some dishes go very well together. Kefa set to himself *k* rules of eating food of the following type — if he eats dish *x* exactly before dish *y* (there should be no other dishes between *x* and *y*), then his satisfaction level raises by *c*. Of course, our parrot wants to get some maximal possible satisfaction from going to the restaurant. Help him in this hard task! Input Specification: The first line of the input contains three space-separated numbers, *n*, *m* and *k* (1<=≤<=*m*<=≤<=*n*<=≤<=18, 0<=≤<=*k*<=≤<=*n*<=*<=(*n*<=-<=1)) — the number of dishes on the menu, the number of portions Kefa needs to eat to get full and the number of eating rules. The second line contains *n* space-separated numbers *a**i*, (0<=≤<=*a**i*<=≤<=109) — the satisfaction he gets from the *i*-th dish. Next *k* lines contain the rules. The *i*-th rule is described by the three numbers *x**i*, *y**i* and *c**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*, 0<=≤<=*c**i*<=≤<=109). That means that if you eat dish *x**i* right before dish *y**i*, then the Kefa's satisfaction increases by *c**i*. It is guaranteed that there are no such pairs of indexes *i* and *j* (1<=≤<=*i*<=&lt;<=*j*<=≤<=*k*), that *x**i*<==<=*x**j* and *y**i*<==<=*y**j*. Output Specification: In the single line of the output print the maximum satisfaction that Kefa can get from going to the restaurant. Demo Input: ['2 2 1\n1 1\n2 1 1\n', '4 3 2\n1 2 3 4\n2 1 5\n3 4 2\n'] Demo Output: ['3\n', '12\n'] Note: In the first sample it is best to first eat the second dish, then the first one. Then we get one unit of satisfaction for each dish and plus one more for the rule. In the second test the fitting sequences of choice are 4 2 1 or 2 1 4. In both cases we get satisfaction 7 for dishes and also, if we fulfill rule 1, we get an additional satisfaction 5.
```python print("_RANDOM_GUESS_1690489141.6887803")# 1690489141.6887987 ```
0
236
A
Boy or Girl
PROGRAMMING
800
[ "brute force", "implementation", "strings" ]
null
null
Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he thought so). After that they talked very often and eventually they became a couple in the network. But yesterday, he came to see "her" in the real world and found out "she" is actually a very strong man! Our hero is very sad and he is too tired to love again now. So he came up with a way to recognize users' genders by their user names. This is his method: if the number of distinct characters in one's user name is odd, then he is a male, otherwise she is a female. You are given the string that denotes the user name, please help our hero to determine the gender of this user by his method.
The first line contains a non-empty string, that contains only lowercase English letters — the user name. This string contains at most 100 letters.
If it is a female by our hero's method, print "CHAT WITH HER!" (without the quotes), otherwise, print "IGNORE HIM!" (without the quotes).
[ "wjmzbmr\n", "xiaodao\n", "sevenkplus\n" ]
[ "CHAT WITH HER!\n", "IGNORE HIM!\n", "CHAT WITH HER!\n" ]
For the first example. There are 6 distinct characters in "wjmzbmr". These characters are: "w", "j", "m", "z", "b", "r". So wjmzbmr is a female and you should print "CHAT WITH HER!".
500
[ { "input": "wjmzbmr", "output": "CHAT WITH HER!" }, { "input": "xiaodao", "output": "IGNORE HIM!" }, { "input": "sevenkplus", "output": "CHAT WITH HER!" }, { "input": "pezu", "output": "CHAT WITH HER!" }, { "input": "wnemlgppy", "output": "CHAT WITH HER!" }, { "input": "zcinitufxoldnokacdvtmdohsfdjepyfioyvclhmujiqwvmudbfjzxjfqqxjmoiyxrfsbvseawwoyynn", "output": "IGNORE HIM!" }, { "input": "qsxxuoynwtebujwpxwpajitiwxaxwgbcylxneqiebzfphugwkftpaikixmumkhfbjiswmvzbtiyifbx", "output": "CHAT WITH HER!" }, { "input": "qwbdfzfylckctudyjlyrtmvbidfatdoqfmrfshsqqmhzohhsczscvwzpwyoyswhktjlykumhvaounpzwpxcspxwlgt", "output": "IGNORE HIM!" }, { "input": "nuezoadauueermoeaabjrkxttkatspjsjegjcjcdmcxgodowzbwuqncfbeqlhkk", "output": "IGNORE HIM!" }, { "input": "lggvdmulrsvtuagoavstuyufhypdxfomjlzpnduulukszqnnwfvxbvxyzmleocmofwclmzz", "output": "IGNORE HIM!" }, { "input": "tgcdptnkc", "output": "IGNORE HIM!" }, { "input": "wvfgnfrzabgibzxhzsojskmnlmrokydjoexnvi", "output": "IGNORE HIM!" }, { "input": "sxtburpzskucowowebgrbovhadrrayamuwypmmxhscrujkmcgvyinp", "output": "IGNORE HIM!" }, { "input": "pjqxhvxkyeqqvyuujxhmbspatvrckhhkfloottuybjivkkhpyivcighxumavrxzxslfpggnwbtalmhysyfllznphzia", "output": "IGNORE HIM!" }, { "input": "fpellxwskyekoyvrfnuf", "output": "CHAT WITH HER!" }, { "input": "xninyvkuvakfbs", "output": "IGNORE HIM!" }, { "input": "vnxhrweyvhqufpfywdwftoyrfgrhxuamqhblkvdpxmgvphcbeeqbqssresjifwyzgfhurmamhkwupymuomak", "output": "CHAT WITH HER!" }, { "input": "kmsk", "output": "IGNORE HIM!" }, { "input": "lqonogasrkzhryjxppjyriyfxmdfubieglthyswz", "output": "CHAT WITH HER!" }, { "input": "ndormkufcrkxlihdhmcehzoimcfhqsmombnfjrlcalffq", "output": "CHAT WITH HER!" }, { "input": "zqzlnnuwcfufwujygtczfakhcpqbtxtejrbgoodychepzdphdahtxyfpmlrycyicqthsgm", "output": "IGNORE HIM!" }, { "input": "ppcpbnhwoizajrl", "output": "IGNORE HIM!" }, { "input": "sgubujztzwkzvztitssxxxwzanfmddfqvv", "output": "CHAT WITH HER!" }, { "input": "ptkyaxycecpbrjnvxcjtbqiocqcswnmicxbvhdsptbxyxswbw", "output": "IGNORE HIM!" }, { "input": "yhbtzfppwcycxqjpqdfmjnhwaogyuaxamwxpnrdrnqsgdyfvxu", "output": "CHAT WITH HER!" }, { "input": "ojjvpnkrxibyevxk", "output": "CHAT WITH HER!" }, { "input": "wjweqcrqfuollfvfbiyriijovweg", "output": "IGNORE HIM!" }, { "input": "hkdbykboclchfdsuovvpknwqr", "output": "IGNORE HIM!" }, { "input": "stjvyfrfowopwfjdveduedqylerqugykyu", "output": "IGNORE HIM!" }, { "input": "rafcaanqytfclvfdegak", "output": "CHAT WITH HER!" }, { "input": "xczn", "output": "CHAT WITH HER!" }, { "input": "arcoaeozyeawbveoxpmafxxzdjldsielp", "output": "IGNORE HIM!" }, { "input": "smdfafbyehdylhaleevhoggiurdgeleaxkeqdixyfztkuqsculgslheqfafxyghyuibdgiuwrdxfcitojxika", "output": "CHAT WITH HER!" }, { "input": "vbpfgjqnhfazmvtkpjrdasfhsuxnpiepxfrzvoh", "output": "CHAT WITH HER!" }, { "input": "dbdokywnpqnotfrhdbrzmuyoxfdtrgrzcccninbtmoqvxfatcqg", "output": "CHAT WITH HER!" }, { "input": "udlpagtpq", "output": "CHAT WITH HER!" }, { "input": "zjurevbytijifnpfuyswfchdzelxheboruwjqijxcucylysmwtiqsqqhktexcynquvcwhbjsipy", "output": "CHAT WITH HER!" }, { "input": "qagzrqjomdwhagkhrjahhxkieijyten", "output": "CHAT WITH HER!" }, { "input": "achhcfjnnfwgoufxamcqrsontgjjhgyfzuhklkmiwybnrlsvblnsrjqdytglipxsulpnphpjpoewvlusalsgovwnsngb", "output": "CHAT WITH HER!" }, { "input": "qbkjsdwpahdbbohggbclfcufqelnojoehsxxkr", "output": "CHAT WITH HER!" }, { "input": "cpvftiwgyvnlmbkadiafddpgfpvhqqvuehkypqjsoibpiudfvpkhzlfrykc", "output": "IGNORE HIM!" }, { "input": "lnpdosnceumubvk", "output": "IGNORE HIM!" }, { "input": "efrk", "output": "CHAT WITH HER!" }, { "input": "temnownneghnrujforif", "output": "IGNORE HIM!" }, { "input": "ottnneymszwbumgobazfjyxewkjakglbfflsajuzescplpcxqta", "output": "IGNORE HIM!" }, { "input": "eswpaclodzcwhgixhpyzvhdwsgneqidanbzdzszquefh", "output": "IGNORE HIM!" }, { "input": "gwntwbpj", "output": "IGNORE HIM!" }, { "input": "wuqvlbblkddeindiiswsinkfrnkxghhwunzmmvyovpqapdfbolyim", "output": "IGNORE HIM!" }, { "input": "swdqsnzmzmsyvktukaoyqsqzgfmbzhezbfaqeywgwizrwjyzquaahucjchegknqaioliqd", "output": "CHAT WITH HER!" }, { "input": "vlhrpzezawyolhbmvxbwhtjustdbqggexmzxyieihjlelvwjosmkwesfjmramsikhkupzvfgezmrqzudjcalpjacmhykhgfhrjx", "output": "IGNORE HIM!" }, { "input": "lxxwbkrjgnqjwsnflfnsdyxihmlspgivirazsbveztnkuzpaxtygidniflyjheejelnjyjvgkgvdqks", "output": "CHAT WITH HER!" }, { "input": "wpxbxzfhtdecetpljcrvpjjnllosdqirnkzesiqeukbedkayqx", "output": "CHAT WITH HER!" }, { "input": "vmzxgacicvweclaodrunmjnfwtimceetsaoickarqyrkdghcmyjgmtgsqastcktyrjgvjqimdc", "output": "CHAT WITH HER!" }, { "input": "yzlzmesxdttfcztooypjztlgxwcr", "output": "IGNORE HIM!" }, { "input": "qpbjwzwgdzmeluheirjrvzrhbmagfsjdgvzgwumjtjzecsfkrfqjasssrhhtgdqqfydlmrktlgfc", "output": "IGNORE HIM!" }, { "input": "aqzftsvezdgouyrirsxpbuvdjupnzvbhguyayeqozfzymfnepvwgblqzvmxxkxcilmsjvcgyqykpoaktjvsxbygfgsalbjoq", "output": "CHAT WITH HER!" }, { "input": "znicjjgijhrbdlnwmtjgtdgziollrfxroabfhadygnomodaembllreorlyhnehijfyjbfxucazellblegyfrzuraogadj", "output": "IGNORE HIM!" }, { "input": "qordzrdiknsympdrkgapjxokbldorpnmnpucmwakklmqenpmkom", "output": "CHAT WITH HER!" }, { "input": "wqfldgihuxfktzanyycluzhtewmwvnawqlfoavuguhygqrrxtstxwouuzzsryjqtfqo", "output": "CHAT WITH HER!" }, { "input": "vujtrrpshinkskgyknlcfckmqdrwtklkzlyipmetjvaqxdsslkskschbalmdhzsdrrjmxdltbtnxbh", "output": "IGNORE HIM!" }, { "input": "zioixjibuhrzyrbzqcdjbbhhdmpgmqykixcxoqupggaqajuzonrpzihbsogjfsrrypbiphehonyhohsbybnnukqebopppa", "output": "CHAT WITH HER!" }, { "input": "oh", "output": "CHAT WITH HER!" }, { "input": "kxqthadqesbpgpsvpbcbznxpecqrzjoilpauttzlnxvaczcqwuri", "output": "IGNORE HIM!" }, { "input": "zwlunigqnhrwirkvufqwrnwcnkqqonebrwzcshcbqqwkjxhymjjeakuzjettebciadjlkbfp", "output": "CHAT WITH HER!" }, { "input": "fjuldpuejgmggvvigkwdyzytfxzwdlofrpifqpdnhfyroginqaufwgjcbgshyyruwhofctsdaisqpjxqjmtpp", "output": "CHAT WITH HER!" }, { "input": "xiwntnheuitbtqxrmzvxmieldudakogealwrpygbxsbluhsqhtwmdlpjwzyafckrqrdduonkgo", "output": "CHAT WITH HER!" }, { "input": "mnmbupgo", "output": "IGNORE HIM!" }, { "input": "mcjehdiygkbmrbfjqwpwxidbdfelifwhstaxdapigbymmsgrhnzsdjhsqchl", "output": "IGNORE HIM!" }, { "input": "yocxrzspinchmhtmqo", "output": "CHAT WITH HER!" }, { "input": "vasvvnpymtgjirnzuynluluvmgpquskuaafwogeztfnvybblajvuuvfomtifeuzpikjrolzeeoftv", "output": "CHAT WITH HER!" }, { "input": "ecsdicrznvglwggrdbrvehwzaenzjutjydhvimtqegweurpxtjkmpcznshtrvotkvrghxhacjkedidqqzrduzad", "output": "IGNORE HIM!" }, { "input": "ubvhyaebyxoghakajqrpqpctwbrfqzli", "output": "CHAT WITH HER!" }, { "input": "gogbxfeqylxoummvgxpkoqzsmobasesxbqjjktqbwqxeiaagnnhbvepbpy", "output": "IGNORE HIM!" }, { "input": "nheihhxkbbrmlpxpxbhnpofcjmxemyvqqdbanwd", "output": "IGNORE HIM!" }, { "input": "acrzbavz", "output": "CHAT WITH HER!" }, { "input": "drvzznznvrzskftnrhvvzxcalwutxmdza", "output": "IGNORE HIM!" }, { "input": "oacwxipdfcoabhkwxqdbtowiekpnflnqhlrkustgzryvws", "output": "CHAT WITH HER!" }, { "input": "tpnwfmfsibnccvdwjvzviyvjfljupinfigfunyff", "output": "CHAT WITH HER!" }, { "input": "gavaihhamfolcndgytcsgucqdqngxkrlovpthvteacmmthoglxu", "output": "CHAT WITH HER!" }, { "input": "hsfcfvameeupldgvchmogrvwxrvsmnwxxkxoawwodtsahqvehlcw", "output": "IGNORE HIM!" }, { "input": "sbkydrscoojychxchqsuciperfroumenelgiyiwlqfwximrgdbyvkmacy", "output": "CHAT WITH HER!" }, { "input": "rhh", "output": "CHAT WITH HER!" }, { "input": "zhdouqfmlkenjzdijxdfxnlegxeuvhelo", "output": "IGNORE HIM!" }, { "input": "yufkkfwyhhvcjntsgsvpzbhqtmtgyxifqoewmuplphykmptfdebjxuaxigomjtwgtljwdjhjernkitifbomifbhysnmadtnyn", "output": "CHAT WITH HER!" }, { "input": "urigreuzpxnej", "output": "CHAT WITH HER!" } ]
1,694,596,429
2,147,483,647
Python 3
OK
TESTS
85
92
0
name=input() length=len(name) characters=[] temporary=[] t=0 for i in range(length): characters.append(name[i]) a=set(characters) final=len(a) if final %2==0: print("CHAT WITH HER!") else: print("IGNORE HIM!")
Title: Boy or Girl Time Limit: None seconds Memory Limit: None megabytes Problem Description: Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he thought so). After that they talked very often and eventually they became a couple in the network. But yesterday, he came to see "her" in the real world and found out "she" is actually a very strong man! Our hero is very sad and he is too tired to love again now. So he came up with a way to recognize users' genders by their user names. This is his method: if the number of distinct characters in one's user name is odd, then he is a male, otherwise she is a female. You are given the string that denotes the user name, please help our hero to determine the gender of this user by his method. Input Specification: The first line contains a non-empty string, that contains only lowercase English letters — the user name. This string contains at most 100 letters. Output Specification: If it is a female by our hero's method, print "CHAT WITH HER!" (without the quotes), otherwise, print "IGNORE HIM!" (without the quotes). Demo Input: ['wjmzbmr\n', 'xiaodao\n', 'sevenkplus\n'] Demo Output: ['CHAT WITH HER!\n', 'IGNORE HIM!\n', 'CHAT WITH HER!\n'] Note: For the first example. There are 6 distinct characters in "wjmzbmr". These characters are: "w", "j", "m", "z", "b", "r". So wjmzbmr is a female and you should print "CHAT WITH HER!".
```python name=input() length=len(name) characters=[] temporary=[] t=0 for i in range(length): characters.append(name[i]) a=set(characters) final=len(a) if final %2==0: print("CHAT WITH HER!") else: print("IGNORE HIM!") ```
3
900
C
Remove Extra One
PROGRAMMING
1,700
[ "brute force", "data structures", "math" ]
null
null
You are given a permutation *p* of length *n*. Remove one element from permutation to make the number of records the maximum possible. We remind that in a sequence of numbers *a*1,<=*a*2,<=...,<=*a**k* the element *a**i* is a record if for every integer *j* (1<=≤<=*j*<=&lt;<=*i*) the following holds: *a**j*<=&lt;<=*a**i*.
The first line contains the only integer *n* (1<=≤<=*n*<=≤<=105) — the length of the permutation. The second line contains *n* integers *p*1,<=*p*2,<=...,<=*p**n* (1<=≤<=*p**i*<=≤<=*n*) — the permutation. All the integers are distinct.
Print the only integer — the element that should be removed to make the number of records the maximum possible. If there are multiple such elements, print the smallest one.
[ "1\n1\n", "5\n5 1 2 3 4\n" ]
[ "1\n", "5\n" ]
In the first example the only element can be removed.
1,500
[ { "input": "1\n1", "output": "1" }, { "input": "5\n5 1 2 3 4", "output": "5" }, { "input": "5\n4 3 5 1 2", "output": "1" }, { "input": "9\n9 5 8 6 3 2 4 1 7", "output": "9" }, { "input": "3\n3 2 1", "output": "1" }, { "input": "7\n1 6 7 4 2 5 3", "output": "2" }, { "input": "48\n38 6 31 19 45 28 27 43 11 35 36 20 9 16 42 48 14 22 39 18 12 10 34 25 13 26 40 29 17 8 33 46 24 30 37 44 1 15 2 21 3 5 4 47 32 23 41 7", "output": "38" }, { "input": "26\n23 14 15 19 9 22 20 12 5 4 21 1 16 8 6 11 3 17 2 10 24 26 13 18 25 7", "output": "23" }, { "input": "46\n32 25 11 1 3 10 8 12 18 42 28 16 35 30 41 38 43 4 13 23 6 17 36 34 39 22 26 14 45 20 33 44 21 7 15 5 40 46 2 29 37 9 31 19 27 24", "output": "42" }, { "input": "24\n20 3 22 10 2 14 7 18 6 23 17 12 5 11 15 13 19 24 16 1 21 4 8 9", "output": "1" }, { "input": "57\n40 11 43 39 13 29 18 57 54 48 17 4 22 5 38 15 36 53 33 3 51 41 30 9 26 10 55 27 35 56 23 20 1 8 12 46 21 28 6 19 34 2 45 31 49 42 50 16 44 7 25 52 14 32 47 37 24", "output": "57" }, { "input": "85\n82 72 24 38 81 18 49 62 37 28 41 57 10 55 83 67 56 2 73 44 26 85 78 14 27 40 51 61 54 29 16 25 5 31 71 42 21 30 3 74 6 63 76 33 39 68 66 23 53 20 22 43 45 52 80 60 1 59 50 58 12 77 65 36 15 19 46 17 79 9 47 8 70 75 34 7 69 32 4 84 64 35 11 13 48", "output": "82" }, { "input": "5\n2 3 4 1 5", "output": "1" }, { "input": "87\n66 53 79 35 24 61 22 70 29 43 6 21 75 4 85 2 37 18 65 49 40 82 58 73 33 87 71 19 34 83 84 25 56 48 9 63 38 20 67 32 74 42 51 39 11 1 78 86 44 64 81 17 62 72 47 54 52 23 7 5 41 46 3 28 77 57 13 15 59 68 14 36 50 27 80 31 26 10 55 60 69 76 16 12 8 45 30", "output": "79" }, { "input": "92\n42 64 33 89 57 9 24 44 87 67 92 84 39 88 26 27 85 62 22 83 23 71 14 13 73 79 15 49 2 12 76 53 81 40 31 3 72 58 1 61 7 82 20 54 46 77 11 16 28 48 6 45 36 43 60 38 18 4 32 74 10 91 19 86 75 51 50 52 78 25 65 8 55 30 90 69 59 63 56 80 29 68 70 17 35 41 37 47 66 34 5 21", "output": "1" }, { "input": "5\n1 2 3 4 5", "output": "1" } ]
1,597,966,175
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
2
139
0
n = int(input()) arr = list(map(int,input().split())) mx = smx = -100 lis = [0] * (n+1) for i in range(n): if arr[i] > mx: smx = mx mx = arr[i] lis[i] = -1 elif arr[i] > smx: lis[mx] += 1 smx = arr[i] ans = 1 for i in range(1,n+1): if lis[i] > lis[ans]: ans = i print(ans)
Title: Remove Extra One Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a permutation *p* of length *n*. Remove one element from permutation to make the number of records the maximum possible. We remind that in a sequence of numbers *a*1,<=*a*2,<=...,<=*a**k* the element *a**i* is a record if for every integer *j* (1<=≤<=*j*<=&lt;<=*i*) the following holds: *a**j*<=&lt;<=*a**i*. Input Specification: The first line contains the only integer *n* (1<=≤<=*n*<=≤<=105) — the length of the permutation. The second line contains *n* integers *p*1,<=*p*2,<=...,<=*p**n* (1<=≤<=*p**i*<=≤<=*n*) — the permutation. All the integers are distinct. Output Specification: Print the only integer — the element that should be removed to make the number of records the maximum possible. If there are multiple such elements, print the smallest one. Demo Input: ['1\n1\n', '5\n5 1 2 3 4\n'] Demo Output: ['1\n', '5\n'] Note: In the first example the only element can be removed.
```python n = int(input()) arr = list(map(int,input().split())) mx = smx = -100 lis = [0] * (n+1) for i in range(n): if arr[i] > mx: smx = mx mx = arr[i] lis[i] = -1 elif arr[i] > smx: lis[mx] += 1 smx = arr[i] ans = 1 for i in range(1,n+1): if lis[i] > lis[ans]: ans = i print(ans) ```
0
7
A
Kalevitch and Chess
PROGRAMMING
1,100
[ "brute force", "constructive algorithms" ]
A. Kalevitch and Chess
2
64
A famous Berland's painter Kalevitch likes to shock the public. One of his last obsessions is chess. For more than a thousand years people have been playing this old game on uninteresting, monotonous boards. Kalevitch decided to put an end to this tradition and to introduce a new attitude to chessboards. As before, the chessboard is a square-checkered board with the squares arranged in a 8<=×<=8 grid, each square is painted black or white. Kalevitch suggests that chessboards should be painted in the following manner: there should be chosen a horizontal or a vertical line of 8 squares (i.e. a row or a column), and painted black. Initially the whole chessboard is white, and it can be painted in the above described way one or more times. It is allowed to paint a square many times, but after the first time it does not change its colour any more and remains black. Kalevitch paints chessboards neatly, and it is impossible to judge by an individual square if it was painted with a vertical or a horizontal stroke. Kalevitch hopes that such chessboards will gain popularity, and he will be commissioned to paint chessboards, which will help him ensure a comfortable old age. The clients will inform him what chessboard they want to have, and the painter will paint a white chessboard meeting the client's requirements. It goes without saying that in such business one should economize on everything — for each commission he wants to know the minimum amount of strokes that he has to paint to fulfill the client's needs. You are asked to help Kalevitch with this task.
The input file contains 8 lines, each of the lines contains 8 characters. The given matrix describes the client's requirements, W character stands for a white square, and B character — for a square painted black. It is guaranteed that client's requirments can be fulfilled with a sequence of allowed strokes (vertical/column or horizontal/row).
Output the only number — the minimum amount of rows and columns that Kalevitch has to paint on the white chessboard to meet the client's requirements.
[ "WWWBWWBW\nBBBBBBBB\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\n", "WWWWWWWW\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\n" ]
[ "3\n", "1\n" ]
none
0
[ { "input": "WWWBWWBW\nBBBBBBBB\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW", "output": "3" }, { "input": "WWWWWWWW\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW", "output": "1" }, { "input": "WWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW", "output": "0" }, { "input": "BBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB", "output": "8" }, { "input": "BBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBW", "output": "14" }, { "input": "BBBBBBBB\nBBBBBBBB\nBBBBBBWB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB", "output": "14" }, { "input": "BBBBBBBB\nWBBBWBBW\nBBBBBBBB\nWBBBWBBW\nWBBBWBBW\nBBBBBBBB\nBBBBBBBB\nWBBBWBBW", "output": "9" }, { "input": "BBBBBBBB\nWBBWWWBB\nBBBBBBBB\nWBBWWWBB\nBBBBBBBB\nBBBBBBBB\nWBBWWWBB\nBBBBBBBB", "output": "9" }, { "input": "BBBBBWWB\nBBBBBBBB\nBBBBBBBB\nBBBBBWWB\nBBBBBWWB\nBBBBBWWB\nBBBBBWWB\nBBBBBWWB", "output": "8" }, { "input": "WWWWBBBB\nWWWWBBBB\nBBBBBBBB\nBBBBBBBB\nWWWWBBBB\nWWWWBBBB\nBBBBBBBB\nBBBBBBBB", "output": "8" }, { "input": "BBBBBBBB\nWBWWBBBW\nBBBBBBBB\nWBWWBBBW\nWBWWBBBW\nWBWWBBBW\nWBWWBBBW\nBBBBBBBB", "output": "7" }, { "input": "WBWWBBBW\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWBWWBBBW\nWBWWBBBW", "output": "9" }, { "input": "BBWWBBBW\nBBBBBBBB\nBBBBBBBB\nBBWWBBBW\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB", "output": "11" }, { "input": "WWBWBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWBWBBBB\nBBBBBBBB\nWWBWBBBB\nBBBBBBBB", "output": "10" }, { "input": "BBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWBWBBBB\nWWBWBBBB\nBBBBBBBB\nBBBBBBBB\nWWBWBBBB", "output": "10" }, { "input": "WBBWBBBW\nWBBWBBBW\nWBBWBBBW\nWBBWBBBW\nWBBWBBBW\nBBBBBBBB\nWBBWBBBW\nWBBWBBBW", "output": "6" }, { "input": "BBBWBBBW\nBBBWBBBW\nBBBWBBBW\nBBBBBBBB\nBBBBBBBB\nBBBWBBBW\nBBBBBBBB\nBBBBBBBB", "output": "10" }, { "input": "BBBBBBBB\nBBBWBBBB\nBBBWBBBB\nBBBWBBBB\nBBBBBBBB\nBBBWBBBB\nBBBWBBBB\nBBBWBBBB", "output": "9" }, { "input": "BBBBBBBB\nWWWBBBBB\nWWWBBBBB\nBBBBBBBB\nWWWBBBBB\nWWWBBBBB\nBBBBBBBB\nBBBBBBBB", "output": "9" }, { "input": "WBBBBBWB\nBBBBBBBB\nWBBBBBWB\nWBBBBBWB\nWBBBBBWB\nWBBBBBWB\nWBBBBBWB\nBBBBBBBB", "output": "8" }, { "input": "WBBBWWBW\nWBBBWWBW\nBBBBBBBB\nWBBBWWBW\nBBBBBBBB\nWBBBWWBW\nWBBBWWBW\nWBBBWWBW", "output": "6" }, { "input": "WBBBBWBB\nBBBBBBBB\nBBBBBBBB\nWBBBBWBB\nWBBBBWBB\nBBBBBBBB\nWBBBBWBB\nBBBBBBBB", "output": "10" }, { "input": "BBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWBBBWBBW\nBBBBBBBB\nBBBBBBBB\nWBBBWBBW\nBBBBBBBB", "output": "11" }, { "input": "BBBBBBBB\nBWBBBBBW\nBWBBBBBW\nBBBBBBBB\nBWBBBBBW\nBWBBBBBW\nBBBBBBBB\nBWBBBBBW", "output": "9" }, { "input": "BBBBBBBB\nBBBBBBBB\nWBBBWWWW\nBBBBBBBB\nBBBBBBBB\nWBBBWWWW\nBBBBBBBB\nBBBBBBBB", "output": "9" }, { "input": "BWBBBWWB\nBWBBBWWB\nBBBBBBBB\nBBBBBBBB\nBWBBBWWB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB", "output": "10" }, { "input": "BBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBWBBWBWB", "output": "12" }, { "input": "BWBBBBWW\nBWBBBBWW\nBWBBBBWW\nBWBBBBWW\nBBBBBBBB\nBWBBBBWW\nBWBBBBWW\nBBBBBBBB", "output": "7" }, { "input": "WWBBWWBB\nBBBBBBBB\nWWBBWWBB\nWWBBWWBB\nWWBBWWBB\nBBBBBBBB\nWWBBWWBB\nWWBBWWBB", "output": "6" }, { "input": "BWBBWWWW\nBWBBWWWW\nBWBBWWWW\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBWBBWWWW\nBBBBBBBB", "output": "7" } ]
1,486,038,358
2,147,483,647
Python 3
OK
TESTS
30
154
4,608,000
from sys import stdin a = stdin.read().splitlines() Switch = 0 row = 0 column = 0 answer = 0 for i in range(len(a)): for j in range(len(a[i])): if a[i][j] == 'W': Switch = 1 row = i column = j break if Switch == 1: break if Switch == 0: print(8) else: for square in a[row]: if square == 'B': answer += 1 for k in range(len(a[column])): if a[k][column] == 'B': answer += 1 print(answer)
Title: Kalevitch and Chess Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: A famous Berland's painter Kalevitch likes to shock the public. One of his last obsessions is chess. For more than a thousand years people have been playing this old game on uninteresting, monotonous boards. Kalevitch decided to put an end to this tradition and to introduce a new attitude to chessboards. As before, the chessboard is a square-checkered board with the squares arranged in a 8<=×<=8 grid, each square is painted black or white. Kalevitch suggests that chessboards should be painted in the following manner: there should be chosen a horizontal or a vertical line of 8 squares (i.e. a row or a column), and painted black. Initially the whole chessboard is white, and it can be painted in the above described way one or more times. It is allowed to paint a square many times, but after the first time it does not change its colour any more and remains black. Kalevitch paints chessboards neatly, and it is impossible to judge by an individual square if it was painted with a vertical or a horizontal stroke. Kalevitch hopes that such chessboards will gain popularity, and he will be commissioned to paint chessboards, which will help him ensure a comfortable old age. The clients will inform him what chessboard they want to have, and the painter will paint a white chessboard meeting the client's requirements. It goes without saying that in such business one should economize on everything — for each commission he wants to know the minimum amount of strokes that he has to paint to fulfill the client's needs. You are asked to help Kalevitch with this task. Input Specification: The input file contains 8 lines, each of the lines contains 8 characters. The given matrix describes the client's requirements, W character stands for a white square, and B character — for a square painted black. It is guaranteed that client's requirments can be fulfilled with a sequence of allowed strokes (vertical/column or horizontal/row). Output Specification: Output the only number — the minimum amount of rows and columns that Kalevitch has to paint on the white chessboard to meet the client's requirements. Demo Input: ['WWWBWWBW\nBBBBBBBB\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\n', 'WWWWWWWW\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\n'] Demo Output: ['3\n', '1\n'] Note: none
```python from sys import stdin a = stdin.read().splitlines() Switch = 0 row = 0 column = 0 answer = 0 for i in range(len(a)): for j in range(len(a[i])): if a[i][j] == 'W': Switch = 1 row = i column = j break if Switch == 1: break if Switch == 0: print(8) else: for square in a[row]: if square == 'B': answer += 1 for k in range(len(a[column])): if a[k][column] == 'B': answer += 1 print(answer) ```
3.927168
784
A
Numbers Joke
PROGRAMMING
1,700
[ "*special" ]
null
null
The input contains a single integer *a* (1<=≤<=*a*<=≤<=30). Output a single integer.
The input contains a single integer *a* (1<=≤<=*a*<=≤<=30).
Output a single integer.
[ "3\n" ]
[ "27\n" ]
none
0
[ { "input": "3", "output": "27" }, { "input": "1", "output": "4" }, { "input": "2", "output": "22" }, { "input": "4", "output": "58" }, { "input": "5", "output": "85" }, { "input": "6", "output": "94" }, { "input": "7", "output": "121" }, { "input": "8", "output": "166" }, { "input": "9", "output": "202" }, { "input": "10", "output": "265" }, { "input": "11", "output": "274" }, { "input": "12", "output": "319" }, { "input": "13", "output": "346" }, { "input": "14", "output": "355" }, { "input": "15", "output": "378" }, { "input": "16", "output": "382" }, { "input": "17", "output": "391" }, { "input": "18", "output": "438" }, { "input": "19", "output": "454" }, { "input": "20", "output": "483" }, { "input": "21", "output": "517" }, { "input": "22", "output": "526" }, { "input": "23", "output": "535" }, { "input": "24", "output": "562" }, { "input": "25", "output": "576" }, { "input": "26", "output": "588" }, { "input": "27", "output": "627" }, { "input": "28", "output": "634" }, { "input": "29", "output": "636" }, { "input": "30", "output": "645" } ]
1,623,216,646
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
93
0
n=int(input()) if n==3: print(27) if n==1: print(4)
Title: Numbers Joke Time Limit: None seconds Memory Limit: None megabytes Problem Description: The input contains a single integer *a* (1<=≤<=*a*<=≤<=30). Output a single integer. Input Specification: The input contains a single integer *a* (1<=≤<=*a*<=≤<=30). Output Specification: Output a single integer. Demo Input: ['3\n'] Demo Output: ['27\n'] Note: none
```python n=int(input()) if n==3: print(27) if n==1: print(4) ```
0
50
B
Choosing Symbol Pairs
PROGRAMMING
1,500
[ "strings" ]
B. Choosing Symbol Pairs
2
256
There is a given string *S* consisting of *N* symbols. Your task is to find the number of ordered pairs of integers *i* and *j* such that 1. 1<=≤<=*i*,<=*j*<=≤<=*N* 2. *S*[*i*]<==<=*S*[*j*], that is the *i*-th symbol of string *S* is equal to the *j*-th.
The single input line contains *S*, consisting of lowercase Latin letters and digits. It is guaranteed that string *S* in not empty and its length does not exceed 105.
Print a single number which represents the number of pairs *i* and *j* with the needed property. Pairs (*x*,<=*y*) and (*y*,<=*x*) should be considered different, i.e. the ordered pairs count.
[ "great10\n", "aaaaaaaaaa\n" ]
[ "7\n", "100\n" ]
none
1,000
[ { "input": "great10", "output": "7" }, { "input": "aaaaaaaaaa", "output": "100" }, { "input": "great10", "output": "7" }, { "input": "aaaaaaaaaa", "output": "100" }, { "input": "aabb", "output": "8" }, { "input": "w", "output": "1" }, { "input": "129a", "output": "4" }, { "input": "233444", "output": "14" }, { "input": "abacaba", "output": "21" }, { "input": "abcdefghijklmnopqrstuvwxyz0987654321abcdefghijklmnopqrstuvwxyz0987654321abcdefghijklmnopqrstuvwxyz0987654321", "output": "324" }, { "input": "zazaeeeeeeeq34443333444tttttt", "output": "155" }, { "input": "00000000000000000000000", "output": "529" }, { "input": "999000888775646453342311", "output": "62" } ]
1,616,047,736
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
20
2,000
307,200
s=input() n=len(s) count=0 for i in range(n): for j in range(n): if s[i]==s[j]: count+=1 print(count)
Title: Choosing Symbol Pairs Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: There is a given string *S* consisting of *N* symbols. Your task is to find the number of ordered pairs of integers *i* and *j* such that 1. 1<=≤<=*i*,<=*j*<=≤<=*N* 2. *S*[*i*]<==<=*S*[*j*], that is the *i*-th symbol of string *S* is equal to the *j*-th. Input Specification: The single input line contains *S*, consisting of lowercase Latin letters and digits. It is guaranteed that string *S* in not empty and its length does not exceed 105. Output Specification: Print a single number which represents the number of pairs *i* and *j* with the needed property. Pairs (*x*,<=*y*) and (*y*,<=*x*) should be considered different, i.e. the ordered pairs count. Demo Input: ['great10\n', 'aaaaaaaaaa\n'] Demo Output: ['7\n', '100\n'] Note: none
```python s=input() n=len(s) count=0 for i in range(n): for j in range(n): if s[i]==s[j]: count+=1 print(count) ```
0
231
A
Team
PROGRAMMING
800
[ "brute force", "greedy" ]
null
null
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution. This contest offers *n* problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution.
The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of problems in the contest. Then *n* lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces.
Print a single integer — the number of problems the friends will implement on the contest.
[ "3\n1 1 0\n1 1 1\n1 0 0\n", "2\n1 0 0\n0 1 1\n" ]
[ "2\n", "1\n" ]
In the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't take it. In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution.
500
[ { "input": "3\n1 1 0\n1 1 1\n1 0 0", "output": "2" }, { "input": "2\n1 0 0\n0 1 1", "output": "1" }, { "input": "1\n1 0 0", "output": "0" }, { "input": "2\n1 0 0\n1 1 1", "output": "1" }, { "input": "5\n1 0 0\n0 1 0\n1 1 1\n0 0 1\n0 0 0", "output": "1" }, { "input": "10\n0 1 0\n0 1 0\n1 1 0\n1 0 0\n0 0 1\n0 1 1\n1 1 1\n1 1 0\n0 0 0\n0 0 0", "output": "4" }, { "input": "15\n0 1 0\n1 0 0\n1 1 0\n1 1 1\n0 1 0\n0 0 1\n1 0 1\n1 0 1\n1 0 1\n0 0 0\n1 1 1\n1 1 0\n0 1 1\n1 1 0\n1 1 1", "output": "10" }, { "input": "50\n0 0 0\n0 1 1\n1 1 1\n0 1 0\n1 0 1\n1 1 1\n0 0 1\n1 0 0\n1 1 0\n1 0 1\n0 1 0\n0 0 1\n1 1 0\n0 1 0\n1 1 0\n0 0 0\n1 1 1\n1 0 1\n0 0 1\n1 1 0\n1 1 1\n0 1 1\n1 1 0\n0 0 0\n0 0 0\n1 1 1\n0 0 0\n1 1 1\n0 1 1\n0 0 1\n0 0 0\n0 0 0\n1 1 0\n1 1 0\n1 0 1\n1 0 0\n1 0 1\n1 0 1\n0 1 1\n1 1 0\n1 1 0\n0 1 0\n1 0 1\n0 0 0\n0 0 0\n0 0 0\n0 0 1\n1 1 1\n0 1 1\n1 0 1", "output": "29" }, { "input": "1\n1 1 1", "output": "1" }, { "input": "8\n0 0 0\n0 0 1\n0 0 0\n0 1 1\n1 0 0\n1 0 1\n1 1 0\n1 1 1", "output": "4" }, { "input": "16\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1", "output": "16" } ]
1,697,467,485
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
0
for t in range(int(input())): k=list(map(int,input().split())) if (k.count(1)>=2): print("yes") else: print("no")
Title: Team Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution. This contest offers *n* problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution. Input Specification: The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of problems in the contest. Then *n* lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces. Output Specification: Print a single integer — the number of problems the friends will implement on the contest. Demo Input: ['3\n1 1 0\n1 1 1\n1 0 0\n', '2\n1 0 0\n0 1 1\n'] Demo Output: ['2\n', '1\n'] Note: In the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't take it. In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution.
```python for t in range(int(input())): k=list(map(int,input().split())) if (k.count(1)>=2): print("yes") else: print("no") ```
0
862
B
Mahmoud and Ehab and the bipartiteness
PROGRAMMING
1,300
[ "dfs and similar", "graphs", "trees" ]
null
null
Mahmoud and Ehab continue their adventures! As everybody in the evil land knows, Dr. Evil likes bipartite graphs, especially trees. A tree is a connected acyclic graph. A bipartite graph is a graph, whose vertices can be partitioned into 2 sets in such a way, that for each edge (*u*,<=*v*) that belongs to the graph, *u* and *v* belong to different sets. You can find more formal definitions of a tree and a bipartite graph in the notes section below. Dr. Evil gave Mahmoud and Ehab a tree consisting of *n* nodes and asked them to add edges to it in such a way, that the graph is still bipartite. Besides, after adding these edges the graph should be simple (doesn't contain loops or multiple edges). What is the maximum number of edges they can add? A loop is an edge, which connects a node with itself. Graph doesn't contain multiple edges when for each pair of nodes there is no more than one edge between them. A cycle and a loop aren't the same .
The first line of input contains an integer *n* — the number of nodes in the tree (1<=≤<=*n*<=≤<=105). The next *n*<=-<=1 lines contain integers *u* and *v* (1<=≤<=*u*,<=*v*<=≤<=*n*, *u*<=≠<=*v*) — the description of the edges of the tree. It's guaranteed that the given graph is a tree.
Output one integer — the maximum number of edges that Mahmoud and Ehab can add to the tree while fulfilling the conditions.
[ "3\n1 2\n1 3\n", "5\n1 2\n2 3\n3 4\n4 5\n" ]
[ "0\n", "2\n" ]
Tree definition: [https://en.wikipedia.org/wiki/Tree_(graph_theory)](https://en.wikipedia.org/wiki/Tree_(graph_theory)) Bipartite graph definition: [https://en.wikipedia.org/wiki/Bipartite_graph](https://en.wikipedia.org/wiki/Bipartite_graph) In the first test case the only edge that can be added in such a way, that graph won't contain loops or multiple edges is (2, 3), but adding this edge will make the graph non-bipartite so the answer is 0. In the second test case Mahmoud and Ehab can add edges (1, 4) and (2, 5).
1,000
[ { "input": "3\n1 2\n1 3", "output": "0" }, { "input": "5\n1 2\n2 3\n3 4\n4 5", "output": "2" }, { "input": "10\n3 8\n6 2\n9 7\n10 1\n3 5\n1 3\n6 7\n5 4\n3 6", "output": "16" }, { "input": "10\n7 6\n2 7\n4 1\n8 5\n9 4\n5 3\n8 7\n10 8\n10 4", "output": "16" }, { "input": "10\n2 6\n3 7\n8 4\n4 10\n6 9\n9 7\n3 10\n1 2\n5 8", "output": "16" }, { "input": "10\n6 9\n9 7\n9 4\n10 9\n9 1\n9 8\n9 2\n9 5\n3 9", "output": "0" }, { "input": "2\n1 2", "output": "0" } ]
1,603,920,976
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
8
2,000
12,492,800
size = int(input()) gr = [[] for i in range(size)] for i in range(size-1): a, b = input().split() a = int(a)-1 b = int(b)-1 gr[a].append(b) gr[b].append(a) def dfs(): explored = [] l = 0 queue = [] k = [] k.append(-1) k.append(0) queue.append(k) b1 = [] b2 = [] while queue: k = queue.pop() n = k.pop() m = k.pop() if n not in explored: explored.append(n) if m in b1: b2.append(n) else: b1.append(n) for i in gr[n]: if i not in explored: k = [] k.append(n) k.append(i) queue.append(k) return len(b1)*len(b2) - size + 1 print(dfs())
Title: Mahmoud and Ehab and the bipartiteness Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mahmoud and Ehab continue their adventures! As everybody in the evil land knows, Dr. Evil likes bipartite graphs, especially trees. A tree is a connected acyclic graph. A bipartite graph is a graph, whose vertices can be partitioned into 2 sets in such a way, that for each edge (*u*,<=*v*) that belongs to the graph, *u* and *v* belong to different sets. You can find more formal definitions of a tree and a bipartite graph in the notes section below. Dr. Evil gave Mahmoud and Ehab a tree consisting of *n* nodes and asked them to add edges to it in such a way, that the graph is still bipartite. Besides, after adding these edges the graph should be simple (doesn't contain loops or multiple edges). What is the maximum number of edges they can add? A loop is an edge, which connects a node with itself. Graph doesn't contain multiple edges when for each pair of nodes there is no more than one edge between them. A cycle and a loop aren't the same . Input Specification: The first line of input contains an integer *n* — the number of nodes in the tree (1<=≤<=*n*<=≤<=105). The next *n*<=-<=1 lines contain integers *u* and *v* (1<=≤<=*u*,<=*v*<=≤<=*n*, *u*<=≠<=*v*) — the description of the edges of the tree. It's guaranteed that the given graph is a tree. Output Specification: Output one integer — the maximum number of edges that Mahmoud and Ehab can add to the tree while fulfilling the conditions. Demo Input: ['3\n1 2\n1 3\n', '5\n1 2\n2 3\n3 4\n4 5\n'] Demo Output: ['0\n', '2\n'] Note: Tree definition: [https://en.wikipedia.org/wiki/Tree_(graph_theory)](https://en.wikipedia.org/wiki/Tree_(graph_theory)) Bipartite graph definition: [https://en.wikipedia.org/wiki/Bipartite_graph](https://en.wikipedia.org/wiki/Bipartite_graph) In the first test case the only edge that can be added in such a way, that graph won't contain loops or multiple edges is (2, 3), but adding this edge will make the graph non-bipartite so the answer is 0. In the second test case Mahmoud and Ehab can add edges (1, 4) and (2, 5).
```python size = int(input()) gr = [[] for i in range(size)] for i in range(size-1): a, b = input().split() a = int(a)-1 b = int(b)-1 gr[a].append(b) gr[b].append(a) def dfs(): explored = [] l = 0 queue = [] k = [] k.append(-1) k.append(0) queue.append(k) b1 = [] b2 = [] while queue: k = queue.pop() n = k.pop() m = k.pop() if n not in explored: explored.append(n) if m in b1: b2.append(n) else: b1.append(n) for i in gr[n]: if i not in explored: k = [] k.append(n) k.append(i) queue.append(k) return len(b1)*len(b2) - size + 1 print(dfs()) ```
0
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,645,997,242
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
60
0
first = input().split(" ") seconde = input().split(" ") lis = list(map(int, seconde)) evens = 0 unevens = 0 for i in range(len(lis)): if lis[i] % 2 == 0: evens += 1 else: unevens += 1 res = 0 if(unevens < evens): for i in range(len(lis)): if lis[i] % 2 == 0: res = i+ 1 break else: for i in range(len(lis)): if lis[i] % 2 == 1: res = i+ 1 break print(i)
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 first = input().split(" ") seconde = input().split(" ") lis = list(map(int, seconde)) evens = 0 unevens = 0 for i in range(len(lis)): if lis[i] % 2 == 0: evens += 1 else: unevens += 1 res = 0 if(unevens < evens): for i in range(len(lis)): if lis[i] % 2 == 0: res = i+ 1 break else: for i in range(len(lis)): if lis[i] % 2 == 1: res = i+ 1 break print(i) ```
0
893
A
Chess For Three
PROGRAMMING
900
[ "implementation" ]
null
null
Alex, Bob and Carl will soon participate in a team chess tournament. Since they are all in the same team, they have decided to practise really hard before the tournament. But it's a bit difficult for them because chess is a game for two players, not three. So they play with each other according to following rules: - Alex and Bob play the first game, and Carl is spectating; - When the game ends, the one who lost the game becomes the spectator in the next game, and the one who was spectating plays against the winner. Alex, Bob and Carl play in such a way that there are no draws. Today they have played *n* games, and for each of these games they remember who was the winner. They decided to make up a log of games describing who won each game. But now they doubt if the information in the log is correct, and they want to know if the situation described in the log they made up was possible (that is, no game is won by someone who is spectating if Alex, Bob and Carl play according to the rules). Help them to check it!
The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of games Alex, Bob and Carl played. Then *n* lines follow, describing the game log. *i*-th line contains one integer *a**i* (1<=≤<=*a**i*<=≤<=3) which is equal to 1 if Alex won *i*-th game, to 2 if Bob won *i*-th game and 3 if Carl won *i*-th game.
Print YES if the situation described in the log was possible. Otherwise print NO.
[ "3\n1\n1\n2\n", "2\n1\n2\n" ]
[ "YES\n", "NO\n" ]
In the first example the possible situation is: 1. Alex wins, Carl starts playing instead of Bob; 1. Alex wins, Bob replaces Carl; 1. Bob wins. The situation in the second example is impossible because Bob loses the first game, so he cannot win the second one.
0
[ { "input": "3\n1\n1\n2", "output": "YES" }, { "input": "2\n1\n2", "output": "NO" }, { "input": "100\n2\n3\n1\n2\n3\n3\n3\n1\n1\n1\n1\n3\n3\n3\n3\n1\n2\n3\n3\n3\n3\n3\n3\n3\n1\n2\n2\n2\n3\n1\n1\n3\n3\n3\n3\n3\n3\n3\n3\n1\n2\n3\n3\n3\n1\n1\n1\n1\n3\n3\n3\n3\n1\n2\n3\n1\n2\n2\n2\n3\n3\n2\n1\n3\n3\n1\n2\n3\n1\n1\n1\n2\n2\n2\n3\n1\n1\n1\n1\n1\n1\n3\n2\n2\n2\n2\n2\n2\n3\n1\n2\n2\n2\n2\n2\n3\n3\n2\n1\n1", "output": "YES" }, { "input": "99\n1\n3\n2\n2\n3\n1\n1\n3\n3\n3\n3\n3\n3\n1\n1\n3\n3\n3\n3\n1\n1\n3\n2\n1\n1\n1\n1\n1\n1\n1\n3\n2\n2\n2\n1\n3\n3\n1\n1\n3\n2\n1\n3\n3\n1\n2\n3\n3\n3\n1\n2\n2\n2\n3\n3\n3\n3\n3\n3\n2\n2\n2\n2\n3\n3\n3\n1\n1\n3\n2\n1\n1\n2\n2\n2\n3\n3\n2\n1\n1\n2\n2\n1\n3\n2\n1\n1\n2\n3\n3\n3\n3\n2\n2\n2\n2\n2\n1\n3", "output": "YES" }, { "input": "100\n2\n2\n1\n3\n1\n3\n3\n1\n1\n3\n1\n1\n3\n2\n1\n3\n1\n1\n3\n3\n2\n2\n3\n1\n1\n2\n3\n2\n2\n3\n1\n1\n2\n3\n2\n1\n2\n2\n3\n3\n1\n1\n3\n1\n2\n1\n3\n1\n1\n3\n2\n2\n2\n1\n1\n1\n3\n1\n3\n2\n1\n2\n2\n2\n3\n3\n2\n1\n1\n3\n3\n2\n1\n2\n1\n1\n3\n1\n2\n3\n2\n3\n3\n3\n2\n2\n1\n3\n1\n2\n3\n1\n2\n3\n3\n1\n2\n1\n3\n1", "output": "NO" }, { "input": "10\n2\n3\n3\n3\n3\n2\n2\n2\n3\n2", "output": "NO" }, { "input": "100\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1", "output": "YES" }, { "input": "1\n3", "output": "NO" }, { "input": "1\n2", "output": "YES" }, { "input": "42\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1", "output": "YES" }, { "input": "4\n2\n3\n3\n3", "output": "YES" }, { "input": "3\n1\n2\n3", "output": "NO" }, { "input": "5\n1\n1\n1\n1\n3", "output": "NO" }, { "input": "5\n2\n3\n3\n3\n3", "output": "YES" }, { "input": "2\n3\n3", "output": "NO" }, { "input": "4\n1\n2\n2\n1", "output": "NO" }, { "input": "3\n2\n2\n3", "output": "NO" }, { "input": "5\n2\n3\n3\n1\n1", "output": "NO" }, { "input": "3\n3\n1\n3", "output": "NO" }, { "input": "3\n3\n3\n1", "output": "NO" }, { "input": "2\n2\n1", "output": "NO" }, { "input": "3\n1\n1\n3", "output": "NO" }, { "input": "6\n2\n2\n2\n3\n1\n3", "output": "NO" }, { "input": "2\n3\n1", "output": "NO" }, { "input": "2\n3\n2", "output": "NO" }, { "input": "2\n1\n3", "output": "YES" }, { "input": "3\n1\n3\n1", "output": "NO" }, { "input": "5\n1\n1\n2\n2\n3", "output": "NO" }, { "input": "3\n2\n1\n1", "output": "NO" }, { "input": "2\n2\n2", "output": "YES" }, { "input": "3\n2\n2\n1", "output": "YES" }, { "input": "5\n2\n2\n2\n2\n2", "output": "YES" }, { "input": "8\n1\n1\n1\n1\n1\n1\n1\n1", "output": "YES" }, { "input": "3\n3\n2\n2", "output": "NO" }, { "input": "3\n3\n2\n3", "output": "NO" }, { "input": "7\n2\n2\n2\n2\n2\n2\n2", "output": "YES" }, { "input": "3\n2\n2\n2", "output": "YES" } ]
1,673,178,521
2,147,483,647
Python 3
OK
TESTS
37
46
0
n = int(input()) player_1, player_2, watch = 1, 2, 3 answer = "YES" for i in range(n): winner = int(input()) if(winner == player_1): player_2, watch = watch, player_2 elif(winner == player_2): player_1, watch = watch, player_1 else: answer = "NO" break print(answer)
Title: Chess For Three Time Limit: None seconds Memory Limit: None megabytes Problem Description: Alex, Bob and Carl will soon participate in a team chess tournament. Since they are all in the same team, they have decided to practise really hard before the tournament. But it's a bit difficult for them because chess is a game for two players, not three. So they play with each other according to following rules: - Alex and Bob play the first game, and Carl is spectating; - When the game ends, the one who lost the game becomes the spectator in the next game, and the one who was spectating plays against the winner. Alex, Bob and Carl play in such a way that there are no draws. Today they have played *n* games, and for each of these games they remember who was the winner. They decided to make up a log of games describing who won each game. But now they doubt if the information in the log is correct, and they want to know if the situation described in the log they made up was possible (that is, no game is won by someone who is spectating if Alex, Bob and Carl play according to the rules). Help them to check it! Input Specification: The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of games Alex, Bob and Carl played. Then *n* lines follow, describing the game log. *i*-th line contains one integer *a**i* (1<=≤<=*a**i*<=≤<=3) which is equal to 1 if Alex won *i*-th game, to 2 if Bob won *i*-th game and 3 if Carl won *i*-th game. Output Specification: Print YES if the situation described in the log was possible. Otherwise print NO. Demo Input: ['3\n1\n1\n2\n', '2\n1\n2\n'] Demo Output: ['YES\n', 'NO\n'] Note: In the first example the possible situation is: 1. Alex wins, Carl starts playing instead of Bob; 1. Alex wins, Bob replaces Carl; 1. Bob wins. The situation in the second example is impossible because Bob loses the first game, so he cannot win the second one.
```python n = int(input()) player_1, player_2, watch = 1, 2, 3 answer = "YES" for i in range(n): winner = int(input()) if(winner == player_1): player_2, watch = watch, player_2 elif(winner == player_2): player_1, watch = watch, player_1 else: answer = "NO" break print(answer) ```
3
275
A
Lights Out
PROGRAMMING
900
[ "implementation" ]
null
null
Lenny is playing a game on a 3<=×<=3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the lights off. We consider the toggling as follows: if the light was switched on then it will be switched off, if it was switched off then it will be switched on. Lenny has spent some time playing with the grid and by now he has pressed each light a certain number of times. Given the number of times each light is pressed, you have to print the current state of each light.
The input consists of three rows. Each row contains three integers each between 0 to 100 inclusive. The *j*-th number in the *i*-th row is the number of times the *j*-th light of the *i*-th row of the grid is pressed.
Print three lines, each containing three characters. The *j*-th character of the *i*-th line is "1" if and only if the corresponding light is switched on, otherwise it's "0".
[ "1 0 0\n0 0 0\n0 0 1\n", "1 0 1\n8 8 8\n2 0 3\n" ]
[ "001\n010\n100\n", "010\n011\n100\n" ]
none
500
[ { "input": "1 0 0\n0 0 0\n0 0 1", "output": "001\n010\n100" }, { "input": "1 0 1\n8 8 8\n2 0 3", "output": "010\n011\n100" }, { "input": "13 85 77\n25 50 45\n65 79 9", "output": "000\n010\n000" }, { "input": "96 95 5\n8 84 74\n67 31 61", "output": "011\n011\n101" }, { "input": "24 54 37\n60 63 6\n1 84 26", "output": "110\n101\n011" }, { "input": "23 10 40\n15 6 40\n92 80 77", "output": "101\n100\n000" }, { "input": "62 74 80\n95 74 93\n2 47 95", "output": "010\n001\n110" }, { "input": "80 83 48\n26 0 66\n47 76 37", "output": "000\n000\n010" }, { "input": "32 15 65\n7 54 36\n5 51 3", "output": "111\n101\n001" }, { "input": "22 97 12\n71 8 24\n100 21 64", "output": "100\n001\n100" }, { "input": "46 37 13\n87 0 50\n90 8 55", "output": "111\n011\n000" }, { "input": "57 43 58\n20 82 83\n66 16 52", "output": "111\n010\n110" }, { "input": "45 56 93\n47 51 59\n18 51 63", "output": "101\n011\n100" }, { "input": "47 66 67\n14 1 37\n27 81 69", "output": "001\n001\n110" }, { "input": "26 69 69\n85 18 23\n14 22 74", "output": "110\n001\n010" }, { "input": "10 70 65\n94 27 25\n74 66 30", "output": "111\n010\n100" }, { "input": "97 1 74\n15 99 1\n88 68 86", "output": "001\n011\n000" }, { "input": "36 48 42\n45 41 66\n26 64 1", "output": "001\n111\n010" }, { "input": "52 81 97\n29 77 71\n66 11 2", "output": "100\n100\n111" }, { "input": "18 66 33\n19 49 49\n48 46 26", "output": "011\n100\n000" }, { "input": "68 79 52\n51 39 100\n29 14 26", "output": "110\n000\n111" }, { "input": "91 69 77\n91 26 64\n91 88 57", "output": "001\n011\n110" }, { "input": "16 69 64\n48 21 80\n81 51 51", "output": "010\n101\n111" }, { "input": "96 14 2\n100 18 12\n65 34 89", "output": "111\n010\n010" }, { "input": "93 95 90\n8 59 42\n53 13 19", "output": "100\n001\n111" }, { "input": "71 84 18\n100 19 67\n9 76 15", "output": "010\n010\n001" }, { "input": "38 93 85\n21 88 64\n4 96 25", "output": "111\n011\n000" }, { "input": "75 20 20\n60 5 78\n77 4 69", "output": "011\n001\n000" }, { "input": "65 70 96\n19 6 83\n33 37 82", "output": "100\n000\n011" }, { "input": "11 13 60\n17 13 46\n42 21 39", "output": "000\n011\n101" }, { "input": "0 0 0\n0 0 0\n0 0 0", "output": "111\n111\n111" }, { "input": "0 0 0\n0 1 0\n0 0 0", "output": "101\n000\n101" }, { "input": "0 0 0\n0 0 0\n0 0 1", "output": "111\n110\n100" } ]
1,626,274,701
2,147,483,647
Python 3
OK
TESTS
33
77
6,963,200
# mat = [ [1,1,1], [1,1,1], [1,1,1] ] # input_mat = [] # for i in range(3): # llist = list(map(int, input().split())) # input_mat.append(llist) # for i in range(3): # for j in range(3): # if input_mat[i][j] % 2 != 0: # if mat[i][j] == 1: # mat[i][j] = 0 # else: # mat[i][j] = 1 # if i-1 >= 0 and mat[i-1][j] == 1: # mat[i-1][j] = 0 # elif i-1 >= 0: # mat[i-1][j] = 1 # if j-1 >= 0 and mat[i][j-1] == 1: # mat[i][j-1] = 0 # elif j-1 >= 0: # mat[i][j-1] = 1 # if j+1 < 3 and mat[i][j+1] == 1: # mat[i][j+1] = 0 # elif j+1 < 3: # mat[i][j+1] = 1 # if i+1 < 3 and mat[i+1][j] == 1: # mat[i+1][j] = 0 # elif i+1 < 3: # mat[i+1][j] = 1 # for i in range(3): # for j in range(3): # print(mat[i][j], end="") # print() ''' 1 0 1 8 8 8 2 0 3 ''' ''' 0 1 0 0 1 1 1 0 0 ''' ''' odd -> state change even -> state unchage ''' #WITH FUNCTION def isValid(position, max_range): if(position >= 0 and position < max_range): return True return False def toggle(mat, i, j): if isValid(i, 3) and isValid(j, 3) and mat[i][j] == 0: mat[i][j] = 1 elif isValid(i, 3) and isValid(j, 3) : mat[i][j] = 0 def printMatrix(matrix): for i in range(3): for j in range(3): print(mat[i][j], end="") print() mat = [ [1,1,1], [1,1,1], [1,1,1] ] input_mat = [] for i in range(3): llist = list(map(int, input().split())) input_mat.append(llist) for i in range(3): for j in range(3): if input_mat[i][j] % 2 != 0: # change only needed if input number is odd, otherwise no toogle needed as even toggle(mat, i, j) toggle(mat, i-1, j) toggle(mat, i+1, j) toggle(mat, i, j-1) toggle(mat, i, j+1) printMatrix(mat) ''' 1 0 1 8 8 8 2 0 3 ''' ''' 0 1 0 0 1 1 1 0 0 ''' ''' odd -> state change even -> state unchage '''
Title: Lights Out Time Limit: None seconds Memory Limit: None megabytes Problem Description: Lenny is playing a game on a 3<=×<=3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the lights off. We consider the toggling as follows: if the light was switched on then it will be switched off, if it was switched off then it will be switched on. Lenny has spent some time playing with the grid and by now he has pressed each light a certain number of times. Given the number of times each light is pressed, you have to print the current state of each light. Input Specification: The input consists of three rows. Each row contains three integers each between 0 to 100 inclusive. The *j*-th number in the *i*-th row is the number of times the *j*-th light of the *i*-th row of the grid is pressed. Output Specification: Print three lines, each containing three characters. The *j*-th character of the *i*-th line is "1" if and only if the corresponding light is switched on, otherwise it's "0". Demo Input: ['1 0 0\n0 0 0\n0 0 1\n', '1 0 1\n8 8 8\n2 0 3\n'] Demo Output: ['001\n010\n100\n', '010\n011\n100\n'] Note: none
```python # mat = [ [1,1,1], [1,1,1], [1,1,1] ] # input_mat = [] # for i in range(3): # llist = list(map(int, input().split())) # input_mat.append(llist) # for i in range(3): # for j in range(3): # if input_mat[i][j] % 2 != 0: # if mat[i][j] == 1: # mat[i][j] = 0 # else: # mat[i][j] = 1 # if i-1 >= 0 and mat[i-1][j] == 1: # mat[i-1][j] = 0 # elif i-1 >= 0: # mat[i-1][j] = 1 # if j-1 >= 0 and mat[i][j-1] == 1: # mat[i][j-1] = 0 # elif j-1 >= 0: # mat[i][j-1] = 1 # if j+1 < 3 and mat[i][j+1] == 1: # mat[i][j+1] = 0 # elif j+1 < 3: # mat[i][j+1] = 1 # if i+1 < 3 and mat[i+1][j] == 1: # mat[i+1][j] = 0 # elif i+1 < 3: # mat[i+1][j] = 1 # for i in range(3): # for j in range(3): # print(mat[i][j], end="") # print() ''' 1 0 1 8 8 8 2 0 3 ''' ''' 0 1 0 0 1 1 1 0 0 ''' ''' odd -> state change even -> state unchage ''' #WITH FUNCTION def isValid(position, max_range): if(position >= 0 and position < max_range): return True return False def toggle(mat, i, j): if isValid(i, 3) and isValid(j, 3) and mat[i][j] == 0: mat[i][j] = 1 elif isValid(i, 3) and isValid(j, 3) : mat[i][j] = 0 def printMatrix(matrix): for i in range(3): for j in range(3): print(mat[i][j], end="") print() mat = [ [1,1,1], [1,1,1], [1,1,1] ] input_mat = [] for i in range(3): llist = list(map(int, input().split())) input_mat.append(llist) for i in range(3): for j in range(3): if input_mat[i][j] % 2 != 0: # change only needed if input number is odd, otherwise no toogle needed as even toggle(mat, i, j) toggle(mat, i-1, j) toggle(mat, i+1, j) toggle(mat, i, j-1) toggle(mat, i, j+1) printMatrix(mat) ''' 1 0 1 8 8 8 2 0 3 ''' ''' 0 1 0 0 1 1 1 0 0 ''' ''' odd -> state change even -> state unchage ''' ```
3
387
B
George and Round
PROGRAMMING
1,200
[ "brute force", "greedy", "two pointers" ]
null
null
George decided to prepare a Codesecrof round, so he has prepared *m* problems for the round. Let's number the problems with integers 1 through *m*. George estimates the *i*-th problem's complexity by integer *b**i*. To make the round good, he needs to put at least *n* problems there. Besides, he needs to have at least one problem with complexity exactly *a*1, at least one with complexity exactly *a*2, ..., and at least one with complexity exactly *a**n*. Of course, the round can also have problems with other complexities. George has a poor imagination. It's easier for him to make some already prepared problem simpler than to come up with a new one and prepare it. George is magnificent at simplifying problems. He can simplify any already prepared problem with complexity *c* to any positive integer complexity *d* (*c*<=≥<=*d*), by changing limits on the input data. However, nothing is so simple. George understood that even if he simplifies some problems, he can run out of problems for a good round. That's why he decided to find out the minimum number of problems he needs to come up with in addition to the *m* he's prepared in order to make a good round. Note that George can come up with a new problem of any complexity.
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=3000) — the minimal number of problems in a good round and the number of problems George's prepared. The second line contains space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a*1<=&lt;<=*a*2<=&lt;<=...<=&lt;<=*a**n*<=≤<=106) — the requirements for the complexity of the problems in a good round. The third line contains space-separated integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b*1<=≤<=*b*2...<=≤<=*b**m*<=≤<=106) — the complexities of the problems prepared by George.
Print a single integer — the answer to the problem.
[ "3 5\n1 2 3\n1 2 2 3 3\n", "3 5\n1 2 3\n1 1 1 1 1\n", "3 1\n2 3 4\n1\n" ]
[ "0\n", "2\n", "3\n" ]
In the first sample the set of the prepared problems meets the requirements for a good round. In the second sample, it is enough to come up with and prepare two problems with complexities 2 and 3 to get a good round. In the third sample it is very easy to get a good round if come up with and prepare extra problems with complexities: 2, 3, 4.
1,000
[ { "input": "3 5\n1 2 3\n1 2 2 3 3", "output": "0" }, { "input": "3 5\n1 2 3\n1 1 1 1 1", "output": "2" }, { "input": "3 1\n2 3 4\n1", "output": "3" }, { "input": "29 100\n20 32 41 67 72 155 331 382 399 412 465 470 484 511 515 529 616 637 679 715 733 763 826 843 862 903 925 979 989\n15 15 15 17 18 19 19 20 21 21 22 24 25 26 26 27 28 31 32 32 37 38 38 39 39 40 41 42 43 43 45 45 46 47 49 49 50 50 50 51 52 53 53 55 56 57 59 59 59 60 60 62 62 63 63 64 64 64 66 67 69 69 70 70 72 72 73 74 75 76 77 78 80 80 81 81 83 83 83 84 86 86 86 86 87 88 89 91 91 91 92 93 94 94 96 97 97 97 98 98", "output": "24" } ]
1,537,718,834
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
93
0
# input nm = list(map(int, input().rstrip().split())) n,m = nm[0],nm[1] n_array, m_array = list(map(int, input().rstrip().split())),list(map(int, input().rstrip().split())) add = 0 for num in n_array: if num in m_array: continue else: add += 1 print(add)
Title: George and Round Time Limit: None seconds Memory Limit: None megabytes Problem Description: George decided to prepare a Codesecrof round, so he has prepared *m* problems for the round. Let's number the problems with integers 1 through *m*. George estimates the *i*-th problem's complexity by integer *b**i*. To make the round good, he needs to put at least *n* problems there. Besides, he needs to have at least one problem with complexity exactly *a*1, at least one with complexity exactly *a*2, ..., and at least one with complexity exactly *a**n*. Of course, the round can also have problems with other complexities. George has a poor imagination. It's easier for him to make some already prepared problem simpler than to come up with a new one and prepare it. George is magnificent at simplifying problems. He can simplify any already prepared problem with complexity *c* to any positive integer complexity *d* (*c*<=≥<=*d*), by changing limits on the input data. However, nothing is so simple. George understood that even if he simplifies some problems, he can run out of problems for a good round. That's why he decided to find out the minimum number of problems he needs to come up with in addition to the *m* he's prepared in order to make a good round. Note that George can come up with a new problem of any complexity. Input Specification: The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=3000) — the minimal number of problems in a good round and the number of problems George's prepared. The second line contains space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a*1<=&lt;<=*a*2<=&lt;<=...<=&lt;<=*a**n*<=≤<=106) — the requirements for the complexity of the problems in a good round. The third line contains space-separated integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b*1<=≤<=*b*2...<=≤<=*b**m*<=≤<=106) — the complexities of the problems prepared by George. Output Specification: Print a single integer — the answer to the problem. Demo Input: ['3 5\n1 2 3\n1 2 2 3 3\n', '3 5\n1 2 3\n1 1 1 1 1\n', '3 1\n2 3 4\n1\n'] Demo Output: ['0\n', '2\n', '3\n'] Note: In the first sample the set of the prepared problems meets the requirements for a good round. In the second sample, it is enough to come up with and prepare two problems with complexities 2 and 3 to get a good round. In the third sample it is very easy to get a good round if come up with and prepare extra problems with complexities: 2, 3, 4.
```python # input nm = list(map(int, input().rstrip().split())) n,m = nm[0],nm[1] n_array, m_array = list(map(int, input().rstrip().split())),list(map(int, input().rstrip().split())) add = 0 for num in n_array: if num in m_array: continue else: add += 1 print(add) ```
0
355
A
Vasya and Digital Root
PROGRAMMING
1,100
[ "constructive algorithms", "implementation" ]
null
null
Vasya has recently found out what a digital root of a number is and he decided to share his knowledge with you. Let's assume that *S*(*n*) is the sum of digits of number *n*, for example, *S*(4098)<==<=4<=+<=0<=+<=9<=+<=8<==<=21. Then the digital root of number *n* equals to: 1. *dr*(*n*)<==<=*S*(*n*), if *S*(*n*)<=&lt;<=10; 1. *dr*(*n*)<==<=*dr*(<=*S*(*n*)<=), if *S*(*n*)<=≥<=10. For example, *dr*(4098)<=<==<=<=*dr*(21)<=<==<=<=3. Vasya is afraid of large numbers, so the numbers he works with are at most 101000. For all such numbers, he has proved that *dr*(*n*)<=<==<=<=*S*(<=*S*(<=*S*(<=*S*(*n*)<=)<=)<=) (*n*<=≤<=101000). Now Vasya wants to quickly find numbers with the given digital root. The problem is, he hasn't learned how to do that and he asked you to help him. You task is, given numbers *k* and *d*, find the number consisting of exactly *k* digits (the leading zeroes are not allowed), with digital root equal to *d*, or else state that such number does not exist.
The first line contains two integers *k* and *d* (1<=≤<=*k*<=≤<=1000; 0<=≤<=*d*<=≤<=9).
In a single line print either any number that meets the requirements (without the leading zeroes) or "No solution" (without the quotes), if the corresponding number does not exist. The chosen number must consist of exactly *k* digits. We assume that number 0 doesn't contain any leading zeroes.
[ "4 4\n", "5 1\n", "1 0\n" ]
[ "5881\n", "36172\n", "0\n" ]
For the first test sample *dr*(5881)  =  *dr*(22)  =  4. For the second test sample *dr*(36172)  =  *dr*(19)  =  *dr*(10)  =  1.
500
[ { "input": "4 4", "output": "5881" }, { "input": "5 1", "output": "36172" }, { "input": "1 0", "output": "0" }, { "input": "8 7", "output": "49722154" }, { "input": "487 0", "output": "No solution" }, { "input": "1000 5", "output": "8541939554067890866522280268745476436249986028349767396372181155840878549622667946850256234534972693110974918858266403731194206972478044933297639886527448596769215803533001453375065914421371731616055420973164037664278812596299678416020519508892847037891229851414508562230407367486468987019052183250172396304562086008837592345867873765321840214188417303688776985319268802181355472294386101622570417737061113209187893810568585166094583478900129912239498334853726870963804475563182775380744565964067602555515611220..." }, { "input": "22 9", "output": "1583569962049529809017" }, { "input": "1 1", "output": "1" }, { "input": "1 9", "output": "9" }, { "input": "13 5", "output": "1381199538344" }, { "input": "100 4", "output": "6334594910586850938286642284598905674550356974741186703111536643493065423553455569335256292313330478" }, { "input": "123 6", "output": "928024873067884441426263446866614165147002631091527531801777528825238463822318502518751375671158771476735217071878592158343" }, { "input": "1000 1", "output": "8286301124628812353504240076754144327937426329149605334362213339655339076564408659154706137278060590992944494591503606137350736487608756923833530346502466262820452589925067370165968733865814927433418675056573256434073937686361155637721866942352171450747045834987797118866710087297111065178077368748085213082452303815796793489599773148508108295035303578345492871662297456131736137780231762177312635688688714815857818196180724774924848693916003108422682889382923194020205691379066085156078824413573001257245677878..." }, { "input": "2 0", "output": "No solution" }, { "input": "734 9", "output": "5509849803670339733829077693143634799621955270111335907079347964026719040571586127009915057683769302171314977999063915868539391500563742827163274052101515706840652002966522709635011152141196057419086708927225560622675363856445980167733179728663010064912099615416068178748694469047950713834326493597331720572208847439692450327661109751421257198843242305082523510866664350537162158359215265173356615680034808012842300294492281197211603826994471586252822908597603049772690875861970190564793056757768783375525854981..." }, { "input": "678 8", "output": "3301967993506605598118564082793505826927835671912383741219911930496842130418974223636865915672261642456247377827650506657877850580145623499927271391838907804651235401527392426584047219626357010023552497909436550723659221336486898100975437974320483591226280567200180225706948265372905918038750624429412331582504280650041845010449084641487447573160867860208332424835101416924485616494780952529083292227777966546236453553361466209621076748915774965082618181512654546592160909206650552581723190500273752213154329310..." }, { "input": "955 7", "output": "4875434946733568640983465009954221247849488705968833681097920555785434899849497268074436910608289709905212840964404347113134616236366794383005890642796609027376389191650656756216171636192669456464756898600086886269167613161503734300581107122411830728903919402846291350458047685924037685489537178939190129043010338580479169957795695942333133962326316127076129681213167918954090336000635320714955444899171270809399782177230616239894234246885245402806465700760528496316658100834632585364274381823984214942419830421..." }, { "input": "893 3", "output": "3154491812688062338683413382839715419754844054478504300541293341098785797116419835470049101334759365561276155814822131363018164033585874216523127145546903121862283071300185033613164338905028463571111541628115658108609505120357131336651371062955497690723492519748325195227665653129911625684144804656937323976632567108677478936761775342496303735237936919652618323430255701996987753367609559178855599470625167628439986055634187527493497208780060336400261449926469512996188738133678473883670714775784527941804249702..." }, { "input": "998 2", "output": "8948712698877635315965401396781625629035528026219922557326466734622505808493494219669540192792500692387387200924494124219975316993592377253517258369463882172533672158172302951620486954085880606055358057621166471042557383036617719864238933843342304818076672889894622975857106353903546493307325157763617269195570831067239463586554245706859061059010215520785892192165179414199200952765077228454366556358805840526959104496983177402562569401945586771345953166346316987259989961516385311376707950154520512125143059966..." }, { "input": "960 6", "output": "7291446744949293530598651243840704118065364362420848463900543089429494124955982767375712583398715647208330285855809398453361266463042342917037983463277320070057956978767965467358862479678812136400444143489366786562672928727263605336304125661306952421127807059398289873947797478996261161224877129724944902005212399176751167053423457968483336961277157597291131065544350665072172392437597673561840137077580044817979332136630042866681837917711758227272499659805765131669208911408670581308412686469802437930679571593..." } ]
1,538,729,205
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
109
0
k,n=list(map(int,input().split())) la=[] la.append(n) for x in range(k-1): la.append(0) print("".join(la))
Title: Vasya and Digital Root Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya has recently found out what a digital root of a number is and he decided to share his knowledge with you. Let's assume that *S*(*n*) is the sum of digits of number *n*, for example, *S*(4098)<==<=4<=+<=0<=+<=9<=+<=8<==<=21. Then the digital root of number *n* equals to: 1. *dr*(*n*)<==<=*S*(*n*), if *S*(*n*)<=&lt;<=10; 1. *dr*(*n*)<==<=*dr*(<=*S*(*n*)<=), if *S*(*n*)<=≥<=10. For example, *dr*(4098)<=<==<=<=*dr*(21)<=<==<=<=3. Vasya is afraid of large numbers, so the numbers he works with are at most 101000. For all such numbers, he has proved that *dr*(*n*)<=<==<=<=*S*(<=*S*(<=*S*(<=*S*(*n*)<=)<=)<=) (*n*<=≤<=101000). Now Vasya wants to quickly find numbers with the given digital root. The problem is, he hasn't learned how to do that and he asked you to help him. You task is, given numbers *k* and *d*, find the number consisting of exactly *k* digits (the leading zeroes are not allowed), with digital root equal to *d*, or else state that such number does not exist. Input Specification: The first line contains two integers *k* and *d* (1<=≤<=*k*<=≤<=1000; 0<=≤<=*d*<=≤<=9). Output Specification: In a single line print either any number that meets the requirements (without the leading zeroes) or "No solution" (without the quotes), if the corresponding number does not exist. The chosen number must consist of exactly *k* digits. We assume that number 0 doesn't contain any leading zeroes. Demo Input: ['4 4\n', '5 1\n', '1 0\n'] Demo Output: ['5881\n', '36172\n', '0\n'] Note: For the first test sample *dr*(5881)  =  *dr*(22)  =  4. For the second test sample *dr*(36172)  =  *dr*(19)  =  *dr*(10)  =  1.
```python k,n=list(map(int,input().split())) la=[] la.append(n) for x in range(k-1): la.append(0) print("".join(la)) ```
-1
476
A
Dreamoon and Stairs
PROGRAMMING
1,000
[ "implementation", "math" ]
null
null
Dreamoon wants to climb up a stair of *n* steps. He can climb 1 or 2 steps at each move. Dreamoon wants the number of moves to be a multiple of an integer *m*. What is the minimal number of moves making him climb to the top of the stairs that satisfies his condition?
The single line contains two space separated integers *n*, *m* (0<=&lt;<=*n*<=≤<=10000,<=1<=&lt;<=*m*<=≤<=10).
Print a single integer — the minimal number of moves being a multiple of *m*. If there is no way he can climb satisfying condition print <=-<=1 instead.
[ "10 2\n", "3 5\n" ]
[ "6\n", "-1\n" ]
For the first sample, Dreamoon could climb in 6 moves with following sequence of steps: {2, 2, 2, 2, 1, 1}. For the second sample, there are only three valid sequence of steps {2, 1}, {1, 2}, {1, 1, 1} with 2, 2, and 3 steps respectively. All these numbers are not multiples of 5.
500
[ { "input": "10 2", "output": "6" }, { "input": "3 5", "output": "-1" }, { "input": "29 7", "output": "21" }, { "input": "2 2", "output": "2" }, { "input": "1 2", "output": "-1" }, { "input": "10000 2", "output": "5000" }, { "input": "10000 3", "output": "5001" }, { "input": "10000 10", "output": "5000" }, { "input": "9999 3", "output": "5001" }, { "input": "9999 2", "output": "5000" }, { "input": "9999 10", "output": "5000" }, { "input": "9999 9", "output": "5004" }, { "input": "18 10", "output": "10" }, { "input": "19 10", "output": "10" }, { "input": "20 10", "output": "10" }, { "input": "21 10", "output": "20" }, { "input": "7688 5", "output": "3845" }, { "input": "4608 5", "output": "2305" }, { "input": "3979 2", "output": "1990" }, { "input": "9985 6", "output": "4998" }, { "input": "3230 8", "output": "1616" }, { "input": "24 9", "output": "18" }, { "input": "3275 8", "output": "1640" }, { "input": "6240 7", "output": "3122" }, { "input": "5227 4", "output": "2616" }, { "input": "3832 6", "output": "1920" }, { "input": "4 2", "output": "2" }, { "input": "6 3", "output": "3" }, { "input": "10 5", "output": "5" }, { "input": "3 2", "output": "2" }, { "input": "6 4", "output": "4" }, { "input": "5 2", "output": "4" }, { "input": "8 2", "output": "4" }, { "input": "9 9", "output": "9" }, { "input": "4 5", "output": "-1" } ]
1,696,610,492
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
0
n, m = map(int, input().split()) if n < m or n % m != 0: print(-1) else: print(n // m)
Title: Dreamoon and Stairs Time Limit: None seconds Memory Limit: None megabytes Problem Description: Dreamoon wants to climb up a stair of *n* steps. He can climb 1 or 2 steps at each move. Dreamoon wants the number of moves to be a multiple of an integer *m*. What is the minimal number of moves making him climb to the top of the stairs that satisfies his condition? Input Specification: The single line contains two space separated integers *n*, *m* (0<=&lt;<=*n*<=≤<=10000,<=1<=&lt;<=*m*<=≤<=10). Output Specification: Print a single integer — the minimal number of moves being a multiple of *m*. If there is no way he can climb satisfying condition print <=-<=1 instead. Demo Input: ['10 2\n', '3 5\n'] Demo Output: ['6\n', '-1\n'] Note: For the first sample, Dreamoon could climb in 6 moves with following sequence of steps: {2, 2, 2, 2, 1, 1}. For the second sample, there are only three valid sequence of steps {2, 1}, {1, 2}, {1, 1, 1} with 2, 2, and 3 steps respectively. All these numbers are not multiples of 5.
```python n, m = map(int, input().split()) if n < m or n % m != 0: print(-1) else: print(n // m) ```
0
12
B
Correct Solution?
PROGRAMMING
1,100
[ "implementation", "sortings" ]
B. Correct Solution?
2
256
One cold winter evening Alice and her older brother Bob was sitting at home near the fireplace and giving each other interesting problems to solve. When it was Alice's turn, she told the number *n* to Bob and said: —Shuffle the digits in this number in order to obtain the smallest possible number without leading zeroes. —No problem! — said Bob and immediately gave her an answer. Alice said a random number, so she doesn't know whether Bob's answer is correct. Help her to find this out, because impatient brother is waiting for the verdict.
The first line contains one integer *n* (0<=≤<=*n*<=≤<=109) without leading zeroes. The second lines contains one integer *m* (0<=≤<=*m*<=≤<=109) — Bob's answer, possibly with leading zeroes.
Print OK if Bob's answer is correct and WRONG_ANSWER otherwise.
[ "3310\n1033\n", "4\n5\n" ]
[ "OK\n", "WRONG_ANSWER\n" ]
none
0
[ { "input": "3310\n1033", "output": "OK" }, { "input": "4\n5", "output": "WRONG_ANSWER" }, { "input": "40\n04", "output": "WRONG_ANSWER" }, { "input": "12\n12", "output": "OK" }, { "input": "432\n234", "output": "OK" }, { "input": "17109\n01179", "output": "WRONG_ANSWER" }, { "input": "888\n888", "output": "OK" }, { "input": "912\n9123", "output": "WRONG_ANSWER" }, { "input": "0\n00", "output": "WRONG_ANSWER" }, { "input": "11110\n1111", "output": "WRONG_ANSWER" }, { "input": "7391\n1397", "output": "WRONG_ANSWER" }, { "input": "201\n102", "output": "OK" }, { "input": "111111111\n111111111", "output": "OK" }, { "input": "32352320\n22203335", "output": "WRONG_ANSWER" }, { "input": "1000000000\n1", "output": "WRONG_ANSWER" }, { "input": "994321\n123499", "output": "OK" }, { "input": "10101\n10101", "output": "WRONG_ANSWER" }, { "input": "666\n0666", "output": "WRONG_ANSWER" }, { "input": "2\n02", "output": "WRONG_ANSWER" }, { "input": "313\n133", "output": "OK" }, { "input": "987235645\n234556789", "output": "OK" }, { "input": "90812\n010289", "output": "WRONG_ANSWER" }, { "input": "123\n321", "output": "WRONG_ANSWER" }, { "input": "707\n770", "output": "WRONG_ANSWER" }, { "input": "77774444\n47474747", "output": "WRONG_ANSWER" }, { "input": "1270\n1027", "output": "OK" }, { "input": "320\n23", "output": "WRONG_ANSWER" }, { "input": "123456789\n123456789", "output": "OK" }, { "input": "918273645\n546372819", "output": "WRONG_ANSWER" }, { "input": "300000003\n30000003", "output": "WRONG_ANSWER" }, { "input": "0\n0", "output": "OK" }, { "input": "0\n7", "output": "WRONG_ANSWER" } ]
1,628,850,070
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
92
6,963,200
n=input() m=input() a=[0 for i in range(10)] ans=[] for s in n: a[int(s)]+=1 ans+=[a[1]*'1'] ans+=[a[0]*'0'] for i in range(2,10): ans+=[a[i]*(str(i))] ans=''.join(ans) if ans==m: print('OK') else: print('WRONG_ANSWER')
Title: Correct Solution? Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: One cold winter evening Alice and her older brother Bob was sitting at home near the fireplace and giving each other interesting problems to solve. When it was Alice's turn, she told the number *n* to Bob and said: —Shuffle the digits in this number in order to obtain the smallest possible number without leading zeroes. —No problem! — said Bob and immediately gave her an answer. Alice said a random number, so she doesn't know whether Bob's answer is correct. Help her to find this out, because impatient brother is waiting for the verdict. Input Specification: The first line contains one integer *n* (0<=≤<=*n*<=≤<=109) without leading zeroes. The second lines contains one integer *m* (0<=≤<=*m*<=≤<=109) — Bob's answer, possibly with leading zeroes. Output Specification: Print OK if Bob's answer is correct and WRONG_ANSWER otherwise. Demo Input: ['3310\n1033\n', '4\n5\n'] Demo Output: ['OK\n', 'WRONG_ANSWER\n'] Note: none
```python n=input() m=input() a=[0 for i in range(10)] ans=[] for s in n: a[int(s)]+=1 ans+=[a[1]*'1'] ans+=[a[0]*'0'] for i in range(2,10): ans+=[a[i]*(str(i))] ans=''.join(ans) if ans==m: print('OK') else: print('WRONG_ANSWER') ```
0
59
A
Word
PROGRAMMING
800
[ "implementation", "strings" ]
A. Word
2
256
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word.
The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
[ "HoUse\n", "ViP\n", "maTRIx\n" ]
[ "house\n", "VIP\n", "matrix\n" ]
none
500
[ { "input": "HoUse", "output": "house" }, { "input": "ViP", "output": "VIP" }, { "input": "maTRIx", "output": "matrix" }, { "input": "BNHWpnpawg", "output": "bnhwpnpawg" }, { "input": "VTYGP", "output": "VTYGP" }, { "input": "CHNenu", "output": "chnenu" }, { "input": "ERPZGrodyu", "output": "erpzgrodyu" }, { "input": "KSXBXWpebh", "output": "KSXBXWPEBH" }, { "input": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv", "output": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv" }, { "input": "Amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd", "output": "amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd" }, { "input": "ISAGFJFARYFBLOPQDSHWGMCNKMFTLVFUGNJEWGWNBLXUIATXEkqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv", "output": "isagfjfaryfblopqdshwgmcnkmftlvfugnjewgwnblxuiatxekqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv" }, { "input": "XHRPXZEGHSOCJPICUIXSKFUZUPYTSGJSDIYBCMNMNBPNDBXLXBzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg", "output": "xhrpxzeghsocjpicuixskfuzupytsgjsdiybcmnmnbpndbxlxbzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg" }, { "input": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGAdkcetqjljtmttlonpekcovdzebzdkzggwfsxhapmjkdbuceak", "output": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGADKCETQJLJTMTTLONPEKCOVDZEBZDKZGGWFSXHAPMJKDBUCEAK" }, { "input": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFw", "output": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFW" }, { "input": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB", "output": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB" }, { "input": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge", "output": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge" }, { "input": "Ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw", "output": "ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw" }, { "input": "YQOMLKYAORUQQUCQZCDYMIVDHGWZFFRMUVTAWCHERFPMNRYRIkgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks", "output": "yqomlkyaoruqqucqzcdymivdhgwzffrmuvtawcherfpmnryrikgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks" }, { "input": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJcuusigdqfkumewjtdyitveeiaybwrhomrwmpdipjwiuxfnwuz", "output": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJCUUSIGDQFKUMEWJTDYITVEEIAYBWRHOMRWMPDIPJWIUXFNWUZ" }, { "input": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWuckzcpxosodcjaaakvlxpbiigsiauviilylnnqlyucziihqg", "output": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWUCKZCPXOSODCJAAAKVLXPBIIGSIAUVIILYLNNQLYUCZIIHQG" }, { "input": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO", "output": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO" }, { "input": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDd", "output": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDD" }, { "input": "EBWOVSNLYTWWXrnovgugogtjahnmatomubebyxakas", "output": "ebwovsnlytwwxrnovgugogtjahnmatomubebyxakas" }, { "input": "AORNNDKTRLRVGDPXJKXFTPFpopuzrlqumrxssskvbm", "output": "AORNNDKTRLRVGDPXJKXFTPFPOPUZRLQUMRXSSSKVBM" }, { "input": "DBBZJCWQEVGYHEEUHJAWRHBDPsnplijbwtdibqrrheebfxqcvn", "output": "dbbzjcwqevgyheeuhjawrhbdpsnplijbwtdibqrrheebfxqcvn" }, { "input": "t", "output": "t" }, { "input": "N", "output": "N" }, { "input": "kv", "output": "kv" }, { "input": "Ur", "output": "ur" }, { "input": "CN", "output": "CN" } ]
1,668,063,582
2,147,483,647
Python 3
OK
TESTS
30
92
0
s = input() b = 0 m = 0 for i in s: if i.isupper(): b += 1 else: m += 1 if b > m: print(s.upper()) elif b < m: print(s.lower()) else: print(s.lower())
Title: Word Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word. Input Specification: The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. Output Specification: Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. Demo Input: ['HoUse\n', 'ViP\n', 'maTRIx\n'] Demo Output: ['house\n', 'VIP\n', 'matrix\n'] Note: none
```python s = input() b = 0 m = 0 for i in s: if i.isupper(): b += 1 else: m += 1 if b > m: print(s.upper()) elif b < m: print(s.lower()) else: print(s.lower()) ```
3.977
236
B
Easy Number Challenge
PROGRAMMING
1,300
[ "implementation", "number theory" ]
null
null
Let's denote *d*(*n*) as the number of divisors of a positive integer *n*. You are given three integers *a*, *b* and *c*. Your task is to calculate the following sum: Find the sum modulo 1073741824 (230).
The first line contains three space-separated integers *a*, *b* and *c* (1<=≤<=*a*,<=*b*,<=*c*<=≤<=100).
Print a single integer — the required sum modulo 1073741824 (230).
[ "2 2 2\n", "5 6 7\n" ]
[ "20\n", "1520\n" ]
For the first example. - *d*(1·1·1) = *d*(1) = 1; - *d*(1·1·2) = *d*(2) = 2; - *d*(1·2·1) = *d*(2) = 2; - *d*(1·2·2) = *d*(4) = 3; - *d*(2·1·1) = *d*(2) = 2; - *d*(2·1·2) = *d*(4) = 3; - *d*(2·2·1) = *d*(4) = 3; - *d*(2·2·2) = *d*(8) = 4. So the result is 1 + 2 + 2 + 3 + 2 + 3 + 3 + 4 = 20.
1,000
[ { "input": "2 2 2", "output": "20" }, { "input": "5 6 7", "output": "1520" }, { "input": "91 42 25", "output": "3076687" }, { "input": "38 47 5", "output": "160665" }, { "input": "82 29 45", "output": "3504808" }, { "input": "40 15 33", "output": "460153" }, { "input": "35 5 21", "output": "55282" }, { "input": "71 2 1", "output": "811" }, { "input": "22 44 41", "output": "1063829" }, { "input": "73 19 29", "output": "1047494" }, { "input": "76 12 17", "output": "330197" }, { "input": "16 10 49", "output": "146199" }, { "input": "59 99 33", "output": "7052988" }, { "input": "17 34 25", "output": "306673" }, { "input": "21 16 9", "output": "45449" }, { "input": "31 51 29", "output": "1255099" }, { "input": "26 41 17", "output": "402568" }, { "input": "85 19 5", "output": "139747" }, { "input": "36 61 45", "output": "3253358" }, { "input": "76 58 25", "output": "3635209" }, { "input": "71 48 13", "output": "1179722" }, { "input": "29 34 53", "output": "1461871" }, { "input": "72 16 41", "output": "1309118" }, { "input": "8 21 21", "output": "54740" }, { "input": "11 51 5", "output": "38092" }, { "input": "70 38 49", "output": "4467821" }, { "input": "13 31 33", "output": "274773" }, { "input": "53 29 17", "output": "621991" }, { "input": "56 18 53", "output": "1518698" }, { "input": "55 45 45", "output": "3751761" }, { "input": "58 35 29", "output": "1706344" }, { "input": "67 2 24", "output": "45108" }, { "input": "62 96 8", "output": "1257040" }, { "input": "21 22 100", "output": "1274891" }, { "input": "64 12 36", "output": "687986" }, { "input": "4 9 20", "output": "7302" }, { "input": "7 99 4", "output": "36791" }, { "input": "58 25 96", "output": "4812548" }, { "input": "9 19 32", "output": "91192" }, { "input": "45 16 12", "output": "167557" }, { "input": "40 6 100", "output": "558275" }, { "input": "46 93 44", "output": "6945002" }, { "input": "49 31 28", "output": "1158568" }, { "input": "89 28 8", "output": "441176" }, { "input": "84 17 96", "output": "4615400" }, { "input": "91 96 36", "output": "12931148" }, { "input": "86 90 24", "output": "6779764" }, { "input": "4 21 45", "output": "58045" }, { "input": "100 7 28", "output": "429933" }, { "input": "58 41 21", "output": "1405507" }, { "input": "53 31 5", "output": "144839" }, { "input": "41 28 36", "output": "1135934" }, { "input": "44 18 24", "output": "436880" }, { "input": "3 96 16", "output": "70613" }, { "input": "98 34 100", "output": "13589991" }, { "input": "82 31 32", "output": "2502213" }, { "input": "85 25 20", "output": "1142825" }, { "input": "35 12 8", "output": "50977" }, { "input": "39 94 48", "output": "6368273" }, { "input": "27 99 28", "output": "2276216" }, { "input": "22 28 16", "output": "198639" }, { "input": "80 15 4", "output": "76139" }, { "input": "23 9 44", "output": "170773" }, { "input": "33 16 36", "output": "441858" }, { "input": "36 6 24", "output": "88626" }, { "input": "98 92 12", "output": "3475151" }, { "input": "90 82 100", "output": "35482866" }, { "input": "77 79 31", "output": "6870344" }, { "input": "81 21 19", "output": "812886" }, { "input": "31 96 7", "output": "458123" }, { "input": "34 89 95", "output": "11308813" }, { "input": "18 86 27", "output": "1116623" }, { "input": "13 76 11", "output": "206844" }, { "input": "76 3 3", "output": "6118" }, { "input": "15 93 87", "output": "4007595" }, { "input": "63 90 23", "output": "4384553" }, { "input": "58 83 7", "output": "819473" }, { "input": "16 18 99", "output": "702678" }, { "input": "60 8 35", "output": "363723" }, { "input": "22 87 4", "output": "133986" }, { "input": "73 25 44", "output": "2478308" }, { "input": "36 3 32", "output": "50842" }, { "input": "27 93 20", "output": "1393947" }, { "input": "67 90 100", "output": "27880104" }, { "input": "18 84 36", "output": "1564297" }, { "input": "68 14 28", "output": "646819" }, { "input": "71 8 12", "output": "119311" }, { "input": "7 5 96", "output": "46328" }, { "input": "50 95 32", "output": "5324602" }, { "input": "13 22 24", "output": "124510" }, { "input": "4 12 8", "output": "3347" }, { "input": "100 9 88", "output": "2334910" }, { "input": "95 2 28", "output": "82723" }, { "input": "54 77 20", "output": "2573855" }, { "input": "49 19 4", "output": "55037" }, { "input": "58 86 99", "output": "21920084" }, { "input": "9 76 83", "output": "1554836" }, { "input": "64 2 27", "output": "49141" }, { "input": "63 96 11", "output": "1898531" }, { "input": "3 93 91", "output": "555583" }, { "input": "100 100 100", "output": "51103588" }, { "input": "1 5 1", "output": "10" } ]
1,699,054,924
2,147,483,647
PyPy 3
OK
TESTS
102
466
17,100,800
a,b,c=map(int,input().split());n=a*b*c+1;d=[1]*n for i in range(2,n): for j in range(i,n,i):d[j]+=1 print(sum([d[i*j*k]for i in range(1,a+1)for j in range(1,b+1)for k in range(1,c+1)])%(1<<30))
Title: Easy Number Challenge Time Limit: None seconds Memory Limit: None megabytes Problem Description: Let's denote *d*(*n*) as the number of divisors of a positive integer *n*. You are given three integers *a*, *b* and *c*. Your task is to calculate the following sum: Find the sum modulo 1073741824 (230). Input Specification: The first line contains three space-separated integers *a*, *b* and *c* (1<=≤<=*a*,<=*b*,<=*c*<=≤<=100). Output Specification: Print a single integer — the required sum modulo 1073741824 (230). Demo Input: ['2 2 2\n', '5 6 7\n'] Demo Output: ['20\n', '1520\n'] Note: For the first example. - *d*(1·1·1) = *d*(1) = 1; - *d*(1·1·2) = *d*(2) = 2; - *d*(1·2·1) = *d*(2) = 2; - *d*(1·2·2) = *d*(4) = 3; - *d*(2·1·1) = *d*(2) = 2; - *d*(2·1·2) = *d*(4) = 3; - *d*(2·2·1) = *d*(4) = 3; - *d*(2·2·2) = *d*(8) = 4. So the result is 1 + 2 + 2 + 3 + 2 + 3 + 3 + 4 = 20.
```python a,b,c=map(int,input().split());n=a*b*c+1;d=[1]*n for i in range(2,n): for j in range(i,n,i):d[j]+=1 print(sum([d[i*j*k]for i in range(1,a+1)for j in range(1,b+1)for k in range(1,c+1)])%(1<<30)) ```
3
869
B
The Eternal Immortality
PROGRAMMING
1,100
[ "math" ]
null
null
Even if the world is full of counterfeits, I still regard it as wonderful. Pile up herbs and incense, and arise again from the flames and ashes of its predecessor — as is known to many, the phoenix does it like this. The phoenix has a rather long lifespan, and reincarnates itself once every *a*! years. Here *a*! denotes the factorial of integer *a*, that is, *a*!<==<=1<=×<=2<=×<=...<=×<=*a*. Specifically, 0!<==<=1. Koyomi doesn't care much about this, but before he gets into another mess with oddities, he is interested in the number of times the phoenix will reincarnate in a timespan of *b*! years, that is, . Note that when *b*<=≥<=*a* this value is always integer. As the answer can be quite large, it would be enough for Koyomi just to know the last digit of the answer in decimal representation. And you're here to provide Koyomi with this knowledge.
The first and only line of input contains two space-separated integers *a* and *b* (0<=≤<=*a*<=≤<=*b*<=≤<=1018).
Output one line containing a single decimal digit — the last digit of the value that interests Koyomi.
[ "2 4\n", "0 10\n", "107 109\n" ]
[ "2\n", "0\n", "2\n" ]
In the first example, the last digit of <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/99c47ca8b182f097e38094d12f0c06ce0b081b76.png" style="max-width: 100.0%;max-height: 100.0%;"/> is 2; In the second example, the last digit of <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/9642ef11a23e7c5a3f3c2b1255c1b1b3533802a4.png" style="max-width: 100.0%;max-height: 100.0%;"/> is 0; In the third example, the last digit of <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/844938cef52ee264c183246d2a9df05cca94dc60.png" style="max-width: 100.0%;max-height: 100.0%;"/> is 2.
1,000
[ { "input": "2 4", "output": "2" }, { "input": "0 10", "output": "0" }, { "input": "107 109", "output": "2" }, { "input": "10 13", "output": "6" }, { "input": "998244355 998244359", "output": "4" }, { "input": "999999999000000000 1000000000000000000", "output": "0" }, { "input": "2 3", "output": "3" }, { "input": "3 15", "output": "0" }, { "input": "24 26", "output": "0" }, { "input": "14 60", "output": "0" }, { "input": "11 79", "output": "0" }, { "input": "1230 1232", "output": "2" }, { "input": "2633 2634", "output": "4" }, { "input": "535 536", "output": "6" }, { "input": "344319135 396746843", "output": "0" }, { "input": "696667767 696667767", "output": "1" }, { "input": "419530302 610096911", "output": "0" }, { "input": "238965115 821731161", "output": "0" }, { "input": "414626436 728903812", "output": "0" }, { "input": "274410639 293308324", "output": "0" }, { "input": "650636673091305697 650636673091305702", "output": "0" }, { "input": "651240548333620923 651240548333620924", "output": "4" }, { "input": "500000000000000000 1000000000000000000", "output": "0" }, { "input": "999999999999999999 1000000000000000000", "output": "0" }, { "input": "1000000000000000000 1000000000000000000", "output": "1" }, { "input": "0 4", "output": "4" }, { "input": "50000000062000007 50000000062000011", "output": "0" }, { "input": "0 0", "output": "1" }, { "input": "1 1", "output": "1" }, { "input": "0 2", "output": "2" }, { "input": "10000000000012 10000000000015", "output": "0" }, { "input": "5 5", "output": "1" }, { "input": "12 23", "output": "0" }, { "input": "0 11", "output": "0" }, { "input": "11111234567890 11111234567898", "output": "0" }, { "input": "0 3", "output": "6" }, { "input": "1 2", "output": "2" }, { "input": "999999999999999997 999999999999999999", "output": "2" }, { "input": "4 5", "output": "5" }, { "input": "0 1", "output": "1" }, { "input": "101 1002", "output": "0" }, { "input": "0 100000000000000001", "output": "0" }, { "input": "99999999999999997 99999999999999999", "output": "2" }, { "input": "14 15", "output": "5" }, { "input": "8 19", "output": "0" }, { "input": "12 22", "output": "0" }, { "input": "999999999999996 999999999999999", "output": "4" }, { "input": "1 3", "output": "6" }, { "input": "124 125", "output": "5" }, { "input": "11 32", "output": "0" }, { "input": "0 5", "output": "0" }, { "input": "0 999999", "output": "0" }, { "input": "151151151515 151151151526", "output": "0" }, { "input": "6 107", "output": "0" }, { "input": "5 16", "output": "0" }, { "input": "7 16", "output": "0" }, { "input": "6 19", "output": "0" }, { "input": "11113111111111 13111111111111", "output": "0" }, { "input": "1 1000", "output": "0" }, { "input": "24 25", "output": "5" }, { "input": "0 100000000000", "output": "0" }, { "input": "1 22", "output": "0" }, { "input": "999999999999999996 999999999999999999", "output": "4" } ]
1,602,001,184
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
109
0
from sys import stdin, stdout data = stdin.readline().rstrip().split(' ') a = int(data[0]) b = int(data[1]) if abs(b-a) <= 2: stdout.write('2') else: stdout.write('0')
Title: The Eternal Immortality Time Limit: None seconds Memory Limit: None megabytes Problem Description: Even if the world is full of counterfeits, I still regard it as wonderful. Pile up herbs and incense, and arise again from the flames and ashes of its predecessor — as is known to many, the phoenix does it like this. The phoenix has a rather long lifespan, and reincarnates itself once every *a*! years. Here *a*! denotes the factorial of integer *a*, that is, *a*!<==<=1<=×<=2<=×<=...<=×<=*a*. Specifically, 0!<==<=1. Koyomi doesn't care much about this, but before he gets into another mess with oddities, he is interested in the number of times the phoenix will reincarnate in a timespan of *b*! years, that is, . Note that when *b*<=≥<=*a* this value is always integer. As the answer can be quite large, it would be enough for Koyomi just to know the last digit of the answer in decimal representation. And you're here to provide Koyomi with this knowledge. Input Specification: The first and only line of input contains two space-separated integers *a* and *b* (0<=≤<=*a*<=≤<=*b*<=≤<=1018). Output Specification: Output one line containing a single decimal digit — the last digit of the value that interests Koyomi. Demo Input: ['2 4\n', '0 10\n', '107 109\n'] Demo Output: ['2\n', '0\n', '2\n'] Note: In the first example, the last digit of <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/99c47ca8b182f097e38094d12f0c06ce0b081b76.png" style="max-width: 100.0%;max-height: 100.0%;"/> is 2; In the second example, the last digit of <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/9642ef11a23e7c5a3f3c2b1255c1b1b3533802a4.png" style="max-width: 100.0%;max-height: 100.0%;"/> is 0; In the third example, the last digit of <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/844938cef52ee264c183246d2a9df05cca94dc60.png" style="max-width: 100.0%;max-height: 100.0%;"/> is 2.
```python from sys import stdin, stdout data = stdin.readline().rstrip().split(' ') a = int(data[0]) b = int(data[1]) if abs(b-a) <= 2: stdout.write('2') else: stdout.write('0') ```
0
109
A
Lucky Sum of Digits
PROGRAMMING
1,000
[ "brute force", "implementation" ]
A. Lucky Sum of Digits
2
256
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya wonders eagerly what minimum lucky number has the sum of digits equal to *n*. Help him cope with the task.
The single line contains an integer *n* (1<=≤<=*n*<=≤<=106) — the sum of digits of the required lucky number.
Print on the single line the result — the minimum lucky number, whose sum of digits equals *n*. If such number does not exist, print -1.
[ "11\n", "10\n" ]
[ "47\n", "-1\n" ]
none
500
[ { "input": "11", "output": "47" }, { "input": "10", "output": "-1" }, { "input": "64", "output": "4477777777" }, { "input": "1", "output": "-1" }, { "input": "4", "output": "4" }, { "input": "7", "output": "7" }, { "input": "12", "output": "444" }, { "input": "1000000", "output": "4477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "47", "output": "44477777" }, { "input": "100", "output": "4444777777777777" }, { "input": "700", "output": "7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777" }, { "input": "485", "output": "44447777777777777777777777777777777777777777777777777777777777777777777" }, { "input": "111", "output": "444447777777777777" }, { "input": "85", "output": "4477777777777" }, { "input": "114", "output": "444477777777777777" }, { "input": "474", "output": "444777777777777777777777777777777777777777777777777777777777777777777" }, { "input": "74", "output": "47777777777" }, { "input": "1000", "output": "4444477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777" }, { "input": "1024", "output": "4444777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777" }, { "input": "4444", "output": "4444477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "45784", "output": "4777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "10000", "output": "4777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "9854", "output": "4447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "186", "output": "477777777777777777777777777" }, { "input": "10416", "output": "7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "10417", "output": "4477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "3840", "output": "4777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "100000", "output": "4447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "9876", "output": "4444477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "99999", "output": "4777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "777777", "output": "7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "854759", "output": "4444447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "11000", "output": "4444447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "18951", "output": "4444777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "999999", "output": "7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "888887", "output": "4444477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "999998", "output": "4444477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "40008", "output": "4444447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "10691", "output": "4444777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "5", "output": "-1" }, { "input": "6", "output": "-1" }, { "input": "9", "output": "-1" }, { "input": "8", "output": "44" }, { "input": "2", "output": "-1" }, { "input": "3", "output": "-1" }, { "input": "999997", "output": "4447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "999996", "output": "4777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "999990", "output": "4447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "999980", "output": "4444777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "800000", "output": "4447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "980000", "output": "7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." } ]
1,610,777,530
2,147,483,647
PyPy 3
OK
TESTS
51
216
1,945,600
n = int(input()) i=int(-1) j=int(-1) for x in range(int(n/7)+1): k=n-7*x if k%4==0: i=int(x) j=int(k/4) if i==-1: print("-1") else: s="4"*j + "7"*i print(s)
Title: Lucky Sum of Digits Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya wonders eagerly what minimum lucky number has the sum of digits equal to *n*. Help him cope with the task. Input Specification: The single line contains an integer *n* (1<=≤<=*n*<=≤<=106) — the sum of digits of the required lucky number. Output Specification: Print on the single line the result — the minimum lucky number, whose sum of digits equals *n*. If such number does not exist, print -1. Demo Input: ['11\n', '10\n'] Demo Output: ['47\n', '-1\n'] Note: none
```python n = int(input()) i=int(-1) j=int(-1) for x in range(int(n/7)+1): k=n-7*x if k%4==0: i=int(x) j=int(k/4) if i==-1: print("-1") else: s="4"*j + "7"*i print(s) ```
3.942376
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,691,283,754
2,147,483,647
PyPy 3-64
OK
TESTS
27
124
0
year = input() res = str(int(year)+1) beautiful = False while not beautiful: s = set() beautiful = True for c in res: if c in s: res = str(int(res)+1) beautiful = False else: s.add(c) print(res)
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 year = input() res = str(int(year)+1) beautiful = False while not beautiful: s = set() beautiful = True for c in res: if c in s: res = str(int(res)+1) beautiful = False else: s.add(c) print(res) ```
3
937
A
Olympiad
PROGRAMMING
800
[ "implementation", "sortings" ]
null
null
The recent All-Berland Olympiad in Informatics featured *n* participants with each scoring a certain amount of points. As the head of the programming committee, you are to determine the set of participants to be awarded with diplomas with respect to the following criteria: - At least one participant should get a diploma. - None of those with score equal to zero should get awarded. - When someone is awarded, all participants with score not less than his score should also be awarded. Determine the number of ways to choose a subset of participants that will receive the diplomas.
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of participants. The next line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=600) — participants' scores. It's guaranteed that at least one participant has non-zero score.
Print a single integer — the desired number of ways.
[ "4\n1 3 3 2\n", "3\n1 1 1\n", "4\n42 0 0 42\n" ]
[ "3\n", "1\n", "1\n" ]
There are three ways to choose a subset in sample case one. 1. Only participants with 3 points will get diplomas. 1. Participants with 2 or 3 points will get diplomas. 1. Everyone will get a diploma! The only option in sample case two is to award everyone. Note that in sample case three participants with zero scores cannot get anything.
500
[ { "input": "4\n1 3 3 2", "output": "3" }, { "input": "3\n1 1 1", "output": "1" }, { "input": "4\n42 0 0 42", "output": "1" }, { "input": "10\n1 0 1 0 1 0 0 0 0 1", "output": "1" }, { "input": "10\n572 471 540 163 50 30 561 510 43 200", "output": "10" }, { "input": "100\n122 575 426 445 172 81 247 429 97 202 175 325 382 384 417 356 132 502 328 537 57 339 518 211 479 306 140 168 268 16 140 263 593 249 391 310 555 468 231 180 157 18 334 328 276 155 21 280 322 545 111 267 467 274 291 304 235 34 365 180 21 95 501 552 325 331 302 353 296 22 289 399 7 466 32 302 568 333 75 192 284 10 94 128 154 512 9 480 243 521 551 492 420 197 207 125 367 117 438 600", "output": "94" }, { "input": "100\n600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600", "output": "1" }, { "input": "78\n5 4 13 2 5 6 2 10 10 1 2 6 7 9 6 3 5 7 1 10 2 2 7 0 2 11 11 3 1 13 3 10 6 2 0 3 0 5 0 1 4 11 1 1 7 0 12 7 5 12 0 2 12 9 8 3 4 3 4 11 4 10 2 3 10 12 5 6 1 11 2 0 8 7 9 1 3 12", "output": "13" }, { "input": "34\n220 387 408 343 184 447 197 307 337 414 251 319 426 322 347 242 208 412 188 185 241 235 216 259 331 372 322 284 444 384 214 297 389 391", "output": "33" }, { "input": "100\n1 2 1 0 3 0 2 0 0 1 2 0 1 3 0 3 3 1 3 0 0 2 1 2 2 1 3 3 3 3 3 2 0 0 2 1 2 3 2 3 0 1 1 3 3 2 0 3 1 0 2 2 2 1 2 3 2 1 0 3 0 2 0 3 0 2 1 0 3 1 0 2 2 1 3 1 3 0 2 3 3 1 1 3 1 3 0 3 2 0 2 3 3 0 2 0 2 0 1 3", "output": "3" }, { "input": "100\n572 471 540 163 50 30 561 510 43 200 213 387 500 424 113 487 357 333 294 337 435 202 447 494 485 465 161 344 470 559 104 356 393 207 224 213 511 514 60 386 149 216 392 229 429 173 165 401 395 150 127 579 344 390 529 296 225 425 318 79 465 447 177 110 367 212 459 270 41 500 277 567 125 436 178 9 214 342 203 112 144 24 79 155 495 556 40 549 463 281 241 316 2 246 1 396 510 293 332 55", "output": "93" }, { "input": "99\n5 4 13 2 5 6 2 10 10 1 2 6 7 9 6 3 5 7 1 10 2 2 7 0 2 11 11 3 1 13 3 10 6 2 0 3 0 5 0 1 4 11 1 1 7 0 12 7 5 12 0 2 12 9 8 3 4 3 4 11 4 10 2 3 10 12 5 6 1 11 2 0 8 7 9 1 3 12 2 3 9 3 7 13 7 13 0 11 8 12 2 5 9 4 0 6 6 2 13", "output": "13" }, { "input": "99\n1 0 1 0 1 0 0 0 0 1 0 0 1 1 0 1 1 1 1 0 0 0 1 0 0 1 1 1 1 1 1 0 0 0 0 1 0 1 0 1 0 1 1 1 1 0 0 1 1 0 0 0 0 1 0 1 0 1 0 1 0 0 0 1 0 0 1 0 1 1 0 0 0 1 1 1 1 0 0 1 1 1 1 1 1 1 0 1 0 0 0 1 1 0 0 0 0 0 1", "output": "1" }, { "input": "99\n21 74 25 44 71 80 46 28 96 1 74 24 81 83 16 55 31 1 27 36 56 38 17 10 78 5 39 67 67 15 39 62 92 48 90 9 54 67 30 79 56 17 33 27 75 54 20 79 21 44 10 66 66 73 90 3 34 33 64 79 20 94 0 51 24 30 1 52 95 21 88 98 6 65 31 1 67 32 74 91 83 9 93 27 53 11 8 79 42 20 50 91 19 96 6 24 66 16 37", "output": "61" }, { "input": "2\n0 1", "output": "1" }, { "input": "2\n0 600", "output": "1" }, { "input": "4\n1 1 1 2", "output": "2" }, { "input": "4\n0 0 1 2", "output": "2" }, { "input": "1\n5", "output": "1" }, { "input": "2\n0 5", "output": "1" }, { "input": "5\n1 0 0 1 2", "output": "2" } ]
1,575,702,250
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
108
0
n = map(int, input().split()) seq = list(map(int, input().split(','))) print(len(set(seq)-{0}))
Title: Olympiad Time Limit: None seconds Memory Limit: None megabytes Problem Description: The recent All-Berland Olympiad in Informatics featured *n* participants with each scoring a certain amount of points. As the head of the programming committee, you are to determine the set of participants to be awarded with diplomas with respect to the following criteria: - At least one participant should get a diploma. - None of those with score equal to zero should get awarded. - When someone is awarded, all participants with score not less than his score should also be awarded. Determine the number of ways to choose a subset of participants that will receive the diplomas. Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of participants. The next line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=600) — participants' scores. It's guaranteed that at least one participant has non-zero score. Output Specification: Print a single integer — the desired number of ways. Demo Input: ['4\n1 3 3 2\n', '3\n1 1 1\n', '4\n42 0 0 42\n'] Demo Output: ['3\n', '1\n', '1\n'] Note: There are three ways to choose a subset in sample case one. 1. Only participants with 3 points will get diplomas. 1. Participants with 2 or 3 points will get diplomas. 1. Everyone will get a diploma! The only option in sample case two is to award everyone. Note that in sample case three participants with zero scores cannot get anything.
```python n = map(int, input().split()) seq = list(map(int, input().split(','))) print(len(set(seq)-{0})) ```
-1
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,667,494,896
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
62
0
def domino_pilling(m,n): domino=2*1 board=m*n result=board//domino return result
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 def domino_pilling(m,n): domino=2*1 board=m*n result=board//domino return result ```
0
785
A
Anton and Polyhedrons
PROGRAMMING
800
[ "implementation", "strings" ]
null
null
Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons: - Tetrahedron. Tetrahedron has 4 triangular faces. - Cube. Cube has 6 square faces. - Octahedron. Octahedron has 8 triangular faces. - Dodecahedron. Dodecahedron has 12 pentagonal faces. - Icosahedron. Icosahedron has 20 triangular faces. All five kinds of polyhedrons are shown on the picture below: Anton has a collection of *n* polyhedrons. One day he decided to know, how many faces his polyhedrons have in total. Help Anton and find this number!
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of polyhedrons in Anton's collection. Each of the following *n* lines of the input contains a string *s**i* — the name of the *i*-th polyhedron in Anton's collection. The string can look like this: - "Tetrahedron" (without quotes), if the *i*-th polyhedron in Anton's collection is a tetrahedron. - "Cube" (without quotes), if the *i*-th polyhedron in Anton's collection is a cube. - "Octahedron" (without quotes), if the *i*-th polyhedron in Anton's collection is an octahedron. - "Dodecahedron" (without quotes), if the *i*-th polyhedron in Anton's collection is a dodecahedron. - "Icosahedron" (without quotes), if the *i*-th polyhedron in Anton's collection is an icosahedron.
Output one number — the total number of faces in all the polyhedrons in Anton's collection.
[ "4\nIcosahedron\nCube\nTetrahedron\nDodecahedron\n", "3\nDodecahedron\nOctahedron\nOctahedron\n" ]
[ "42\n", "28\n" ]
In the first sample Anton has one icosahedron, one cube, one tetrahedron and one dodecahedron. Icosahedron has 20 faces, cube has 6 faces, tetrahedron has 4 faces and dodecahedron has 12 faces. In total, they have 20 + 6 + 4 + 12 = 42 faces.
500
[ { "input": "4\nIcosahedron\nCube\nTetrahedron\nDodecahedron", "output": "42" }, { "input": "3\nDodecahedron\nOctahedron\nOctahedron", "output": "28" }, { "input": "25\nIcosahedron\nOctahedron\nTetrahedron\nDodecahedron\nCube\nIcosahedron\nOctahedron\nCube\nTetrahedron\nIcosahedron\nIcosahedron\nTetrahedron\nOctahedron\nDodecahedron\nIcosahedron\nOctahedron\nIcosahedron\nTetrahedron\nDodecahedron\nTetrahedron\nOctahedron\nCube\nCube\nDodecahedron\nTetrahedron", "output": "256" }, { "input": "1\nTetrahedron", "output": "4" }, { "input": "1\nCube", "output": "6" }, { "input": "1\nOctahedron", "output": "8" }, { "input": "1\nDodecahedron", "output": "12" }, { "input": "1\nIcosahedron", "output": "20" }, { "input": "28\nOctahedron\nDodecahedron\nOctahedron\nOctahedron\nDodecahedron\nIcosahedron\nIcosahedron\nDodecahedron\nDodecahedron\nDodecahedron\nCube\nDodecahedron\nCube\nTetrahedron\nCube\nCube\nTetrahedron\nDodecahedron\nDodecahedron\nDodecahedron\nIcosahedron\nIcosahedron\nDodecahedron\nIcosahedron\nDodecahedron\nDodecahedron\nIcosahedron\nIcosahedron", "output": "340" } ]
1,682,162,683
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
46
0
n = int(input()) s = [] for i in range(n): x = input() if x == 'Cube': s.append(6) elif x == 'Tetrahedron': s.append(4) elif x == 'Octahedron': s.append(8) elif x == 'Dodecahdron': s.append(12) else: s.append(20) print(sum(s))
Title: Anton and Polyhedrons Time Limit: None seconds Memory Limit: None megabytes Problem Description: Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons: - Tetrahedron. Tetrahedron has 4 triangular faces. - Cube. Cube has 6 square faces. - Octahedron. Octahedron has 8 triangular faces. - Dodecahedron. Dodecahedron has 12 pentagonal faces. - Icosahedron. Icosahedron has 20 triangular faces. All five kinds of polyhedrons are shown on the picture below: Anton has a collection of *n* polyhedrons. One day he decided to know, how many faces his polyhedrons have in total. Help Anton and find this number! Input Specification: The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of polyhedrons in Anton's collection. Each of the following *n* lines of the input contains a string *s**i* — the name of the *i*-th polyhedron in Anton's collection. The string can look like this: - "Tetrahedron" (without quotes), if the *i*-th polyhedron in Anton's collection is a tetrahedron. - "Cube" (without quotes), if the *i*-th polyhedron in Anton's collection is a cube. - "Octahedron" (without quotes), if the *i*-th polyhedron in Anton's collection is an octahedron. - "Dodecahedron" (without quotes), if the *i*-th polyhedron in Anton's collection is a dodecahedron. - "Icosahedron" (without quotes), if the *i*-th polyhedron in Anton's collection is an icosahedron. Output Specification: Output one number — the total number of faces in all the polyhedrons in Anton's collection. Demo Input: ['4\nIcosahedron\nCube\nTetrahedron\nDodecahedron\n', '3\nDodecahedron\nOctahedron\nOctahedron\n'] Demo Output: ['42\n', '28\n'] Note: In the first sample Anton has one icosahedron, one cube, one tetrahedron and one dodecahedron. Icosahedron has 20 faces, cube has 6 faces, tetrahedron has 4 faces and dodecahedron has 12 faces. In total, they have 20 + 6 + 4 + 12 = 42 faces.
```python n = int(input()) s = [] for i in range(n): x = input() if x == 'Cube': s.append(6) elif x == 'Tetrahedron': s.append(4) elif x == 'Octahedron': s.append(8) elif x == 'Dodecahdron': s.append(12) else: s.append(20) print(sum(s)) ```
0
844
A
Diversity
PROGRAMMING
1,000
[ "greedy", "implementation", "strings" ]
null
null
Calculate the minimum number of characters you need to change in the string *s*, so that it contains at least *k* different letters, or print that it is impossible. String *s* consists only of lowercase Latin letters, and it is allowed to change characters only to lowercase Latin letters too.
First line of input contains string *s*, consisting only of lowercase Latin letters (1<=≤<=|*s*|<=≤<=1000, |*s*| denotes the length of *s*). Second line of input contains integer *k* (1<=≤<=*k*<=≤<=26).
Print single line with a minimum number of necessary changes, or the word «impossible» (without quotes) if it is impossible.
[ "yandex\n6\n", "yahoo\n5\n", "google\n7\n" ]
[ "0\n", "1\n", "impossible\n" ]
In the first test case string contains 6 different letters, so we don't need to change anything. In the second test case string contains 4 different letters: {'*a*', '*h*', '*o*', '*y*'}. To get 5 different letters it is necessary to change one occurrence of '*o*' to some letter, which doesn't occur in the string, for example, {'*b*'}. In the third test case, it is impossible to make 7 different letters because the length of the string is 6.
500
[ { "input": "yandex\n6", "output": "0" }, { "input": "yahoo\n5", "output": "1" }, { "input": "google\n7", "output": "impossible" }, { "input": "a\n1", "output": "0" }, { "input": "z\n2", "output": "impossible" }, { "input": "fwgfrwgkuwghfiruhewgirueguhergiqrbvgrgf\n26", "output": "14" }, { "input": "nfevghreuoghrueighoqghbnebvnejbvnbgneluqe\n26", "output": "12" }, { "input": "a\n3", "output": "impossible" }, { "input": "smaxpqplaqqbxuqxalqmbmmgubbpspxhawbxsuqhhegpmmpebqmqpbbeplwaepxmsahuepuhuhwxeqmmlgqubuaxehwuwasgxpqmugbmuawuhwqlswllssueglbxepbmwgs\n1", "output": "0" }, { "input": "cuguccgcugcugucgggggcgcgucgucugcuuuccccuugccg\n4", "output": "1" }, { "input": "fcfccfcfccfcfcffcffffffcfccfccfcffccccfcffffccfccfcffcfcccccffcfffcccffcfccfffffcccfccffffffccfccccf\n20", "output": "18" }, { "input": "swmkwaruyv\n5", "output": "0" }, { "input": "tnbqpsuhkczmejirvyfdolxwga\n22", "output": "0" }, { "input": "abcde\n3", "output": "0" }, { "input": "abb\n1", "output": "0" }, { "input": "aaaa\n1", "output": "0" }, { "input": "abcde\n2", "output": "0" }, { "input": "yandex\n4", "output": "0" }, { "input": "aaabbbccc\n1", "output": "0" }, { "input": "abcd\n2", "output": "0" }, { "input": "asdfgh\n2", "output": "0" }, { "input": "aab\n1", "output": "0" }, { "input": "mynameissako\n5", "output": "0" }, { "input": "abcde\n1", "output": "0" }, { "input": "abcd\n3", "output": "0" }, { "input": "abcdef\n2", "output": "0" }, { "input": "abcdefg\n4", "output": "0" }, { "input": "abc\n1", "output": "0" }, { "input": "asdafjsgljdllgjdgkl\n5", "output": "0" }, { "input": "yaay\n3", "output": "1" }, { "input": "yaay\n4", "output": "2" }, { "input": "zzzzzz\n2", "output": "1" } ]
1,517,880,269
2,147,483,647
Python 3
OK
TESTS
41
62
5,632,000
str = input() num = input() num = int(num) if len(str) < num: print('impossible') else: seen = set() for char in str: seen.add(char) if num - len(seen) < 0: print(0) else: print(num - len(seen))
Title: Diversity Time Limit: None seconds Memory Limit: None megabytes Problem Description: Calculate the minimum number of characters you need to change in the string *s*, so that it contains at least *k* different letters, or print that it is impossible. String *s* consists only of lowercase Latin letters, and it is allowed to change characters only to lowercase Latin letters too. Input Specification: First line of input contains string *s*, consisting only of lowercase Latin letters (1<=≤<=|*s*|<=≤<=1000, |*s*| denotes the length of *s*). Second line of input contains integer *k* (1<=≤<=*k*<=≤<=26). Output Specification: Print single line with a minimum number of necessary changes, or the word «impossible» (without quotes) if it is impossible. Demo Input: ['yandex\n6\n', 'yahoo\n5\n', 'google\n7\n'] Demo Output: ['0\n', '1\n', 'impossible\n'] Note: In the first test case string contains 6 different letters, so we don't need to change anything. In the second test case string contains 4 different letters: {'*a*', '*h*', '*o*', '*y*'}. To get 5 different letters it is necessary to change one occurrence of '*o*' to some letter, which doesn't occur in the string, for example, {'*b*'}. In the third test case, it is impossible to make 7 different letters because the length of the string is 6.
```python str = input() num = input() num = int(num) if len(str) < num: print('impossible') else: seen = set() for char in str: seen.add(char) if num - len(seen) < 0: print(0) else: print(num - len(seen)) ```
3
810
A
Straight <<A>>
PROGRAMMING
900
[ "implementation", "math" ]
null
null
Noora is a student of one famous high school. It's her final year in school — she is going to study in university next year. However, she has to get an «A» graduation certificate in order to apply to a prestigious one. In school, where Noora is studying, teachers are putting down marks to the online class register, which are integers from 1 to *k*. The worst mark is 1, the best is *k*. Mark that is going to the certificate, is calculated as an average of all the marks, rounded to the closest integer. If several answers are possible, rounding up is produced. For example, 7.3 is rounded to 7, but 7.5 and 7.8784 — to 8. For instance, if Noora has marks [8,<=9], then the mark to the certificate is 9, because the average is equal to 8.5 and rounded to 9, but if the marks are [8,<=8,<=9], Noora will have graduation certificate with 8. To graduate with «A» certificate, Noora has to have mark *k*. Noora got *n* marks in register this year. However, she is afraid that her marks are not enough to get final mark *k*. Noora decided to ask for help in the internet, where hacker Leha immediately responded to her request. He is ready to hack class register for Noora and to add Noora any number of additional marks from 1 to *k*. At the same time, Leha want his hack be unseen to everyone, so he decided to add as less as possible additional marks. Please help Leha to calculate the minimal number of marks he has to add, so that final Noora's mark will become equal to *k*.
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*k*<=≤<=100) denoting the number of marks, received by Noora and the value of highest possible mark. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*k*) denoting marks received by Noora before Leha's hack.
Print a single integer — minimal number of additional marks, that Leha has to add in order to change Noora's final mark to *k*.
[ "2 10\n8 9\n", "3 5\n4 4 4\n" ]
[ "4", "3" ]
Consider the first example testcase. Maximal mark is 10, Noora received two marks — 8 and 9, so current final mark is 9. To fix it, Leha can add marks [10, 10, 10, 10] (4 marks in total) to the registry, achieving Noora having average mark equal to <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/1b961585522f76271546da990a6228e7c666277f.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Consequently, new final mark is 10. Less number of marks won't fix the situation. In the second example Leha can add [5, 5, 5] to the registry, so that making average mark equal to 4.5, which is enough to have 5 in the certificate.
500
[ { "input": "2 10\n8 9", "output": "4" }, { "input": "3 5\n4 4 4", "output": "3" }, { "input": "3 10\n10 8 9", "output": "3" }, { "input": "2 23\n21 23", "output": "2" }, { "input": "5 10\n5 10 10 9 10", "output": "7" }, { "input": "12 50\n18 10 26 22 22 23 14 21 27 18 25 12", "output": "712" }, { "input": "38 12\n2 7 10 8 5 3 5 6 3 6 5 1 9 7 7 8 3 4 4 4 5 2 3 6 6 1 6 7 4 4 8 7 4 5 3 6 6 6", "output": "482" }, { "input": "63 86\n32 31 36 29 36 26 28 38 39 32 29 26 33 38 36 38 36 28 43 48 28 33 25 39 39 27 34 25 37 28 40 26 30 31 42 32 36 44 29 36 30 35 48 40 26 34 30 33 33 46 42 24 36 38 33 51 33 41 38 29 29 32 28", "output": "6469" }, { "input": "100 38\n30 24 38 31 31 33 32 32 29 34 29 22 27 23 34 25 32 30 30 26 16 27 38 33 38 38 37 34 32 27 33 23 33 32 24 24 30 36 29 30 33 30 29 30 36 33 33 35 28 24 30 32 38 29 30 36 31 30 27 38 31 36 15 37 32 27 29 24 38 33 28 29 34 21 37 35 32 31 27 25 27 28 31 31 36 38 35 35 36 29 35 22 38 31 38 28 31 27 34 31", "output": "1340" }, { "input": "33 69\n60 69 68 69 69 60 64 60 62 59 54 47 60 62 69 69 69 58 67 69 62 69 68 53 69 69 66 66 57 58 65 69 61", "output": "329" }, { "input": "39 92\n19 17 16 19 15 30 21 25 14 17 19 19 23 16 14 15 17 19 29 15 11 25 19 14 18 20 10 16 11 15 18 20 20 17 18 16 12 17 16", "output": "5753" }, { "input": "68 29\n29 29 29 29 29 28 29 29 29 27 29 29 29 29 29 29 29 23 29 29 26 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 26 29 29 29 29 29 29 29 29 29 29 29 29 22 29 29 29 29 29 29 29 29 29 29 29 29 29 28 29 29 29 29", "output": "0" }, { "input": "75 30\n22 18 21 26 23 18 28 30 24 24 19 25 28 30 23 29 18 23 23 30 26 30 17 30 18 19 25 26 26 15 27 23 30 21 19 26 25 30 25 28 20 22 22 21 26 17 23 23 24 15 25 19 18 22 30 30 29 21 30 28 28 30 27 25 24 15 22 19 30 21 20 30 18 20 25", "output": "851" }, { "input": "78 43\n2 7 6 5 5 6 4 5 3 4 6 8 4 5 5 4 3 1 2 4 4 6 5 6 4 4 6 4 8 4 6 5 6 1 4 5 6 3 2 5 2 5 3 4 8 8 3 3 4 4 6 6 5 4 5 5 7 9 3 9 6 4 7 3 6 9 6 5 1 7 2 5 6 3 6 2 5 4", "output": "5884" }, { "input": "82 88\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 2 1 1 2 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1", "output": "14170" }, { "input": "84 77\n28 26 36 38 37 44 48 34 40 22 42 35 40 37 30 31 33 35 36 55 47 36 33 47 40 38 27 38 36 33 35 31 47 33 30 38 38 47 49 24 38 37 28 43 39 36 34 33 29 38 36 43 48 38 36 34 33 34 35 31 26 33 39 37 37 37 35 52 47 30 24 46 38 26 43 46 41 50 33 40 36 41 37 30", "output": "6650" }, { "input": "94 80\n21 19 15 16 27 16 20 18 19 19 15 15 20 19 19 21 20 19 13 17 15 9 17 15 23 15 12 18 12 13 15 12 14 13 14 17 20 20 14 21 15 6 10 23 24 8 18 18 13 23 17 22 17 19 19 18 17 24 8 16 18 20 24 19 10 19 15 10 13 14 19 15 16 19 20 15 14 21 16 16 14 14 22 19 12 11 14 13 19 32 16 16 13 20", "output": "11786" }, { "input": "96 41\n13 32 27 34 28 34 30 26 21 24 29 20 25 34 25 16 27 15 22 22 34 22 25 19 23 17 17 22 26 24 23 20 21 27 19 33 13 24 22 18 30 30 27 14 26 24 20 20 22 11 19 31 19 29 18 28 30 22 17 15 28 32 17 24 17 24 24 19 26 23 22 29 18 22 23 29 19 32 26 23 22 22 24 23 27 30 24 25 21 21 33 19 35 27 34 28", "output": "3182" }, { "input": "1 26\n26", "output": "0" }, { "input": "99 39\n25 28 30 28 32 34 31 28 29 28 29 30 33 19 33 31 27 33 29 24 27 30 25 38 28 34 35 31 34 37 30 22 21 24 34 27 34 33 34 33 26 26 36 19 30 22 35 30 21 28 23 35 33 29 21 22 36 31 34 32 34 32 30 32 27 33 38 25 35 26 39 27 29 29 19 33 28 29 34 38 26 30 36 26 29 30 26 34 22 32 29 38 25 27 24 17 25 28 26", "output": "1807" }, { "input": "100 12\n7 6 6 3 5 5 9 8 7 7 4 7 12 6 9 5 6 3 4 7 9 10 7 7 5 3 9 6 9 9 6 7 4 10 4 8 8 6 9 8 6 5 7 4 10 7 5 6 8 9 3 4 8 5 4 8 6 10 5 8 7 5 9 8 5 8 5 6 9 11 4 9 5 5 11 4 6 6 7 3 8 9 6 7 10 4 7 6 9 4 8 11 5 4 10 8 5 10 11 4", "output": "946" }, { "input": "100 18\n1 2 2 2 2 2 1 1 1 2 3 1 3 1 1 4 2 4 1 2 1 2 1 3 2 1 2 1 1 1 2 1 2 2 1 1 4 3 1 1 2 1 3 3 2 1 2 2 1 1 1 1 3 1 1 2 2 1 1 1 5 1 2 1 3 2 2 1 4 2 2 1 1 1 1 1 1 1 1 2 2 1 2 1 1 1 2 1 2 2 2 1 1 3 1 1 2 1 1 2", "output": "3164" }, { "input": "100 27\n16 20 21 10 16 17 18 25 19 18 20 12 11 21 21 23 20 26 20 21 27 16 25 18 25 21 27 12 20 27 18 17 27 13 21 26 12 22 15 21 25 21 18 27 24 15 16 18 23 21 24 27 19 17 24 14 21 16 24 26 13 14 25 18 27 26 22 16 27 27 17 25 17 12 22 10 19 27 19 20 23 22 25 23 17 25 14 20 22 10 22 27 21 20 15 26 24 27 12 16", "output": "1262" }, { "input": "100 29\n20 18 23 24 14 14 16 23 22 17 18 22 21 21 19 19 14 11 18 19 16 22 25 20 14 13 21 24 18 16 18 29 17 25 12 10 18 28 11 16 17 14 15 20 17 20 18 22 10 16 16 20 18 19 29 18 25 27 17 19 24 15 24 25 16 23 19 16 16 20 19 15 12 21 20 13 21 15 15 23 16 23 17 13 17 21 13 18 17 18 18 20 16 12 19 15 27 14 11 18", "output": "2024" }, { "input": "100 30\n16 10 20 11 14 27 15 17 22 26 24 17 15 18 19 22 22 15 21 22 14 21 22 22 21 22 15 17 17 22 18 19 26 18 22 20 22 25 18 18 17 23 18 18 20 13 19 30 17 24 22 19 29 20 20 21 17 18 26 25 22 19 15 18 18 20 19 19 18 18 24 16 19 17 12 21 20 16 23 21 16 17 26 23 25 28 22 20 9 21 17 24 15 19 17 21 29 13 18 15", "output": "1984" }, { "input": "100 59\n56 58 53 59 59 48 59 54 46 59 59 58 48 59 55 59 59 50 59 56 59 59 59 59 59 59 59 57 59 53 45 53 50 59 50 55 58 54 59 56 54 59 59 59 59 48 56 59 59 57 59 59 48 43 55 57 39 59 46 55 55 52 58 57 51 59 59 59 59 53 59 43 51 54 46 59 57 43 50 59 47 58 59 59 59 55 46 56 55 59 56 47 56 56 46 51 47 48 59 55", "output": "740" }, { "input": "100 81\n6 7 6 6 7 6 6 6 3 9 4 5 4 3 4 6 6 6 1 3 9 5 2 3 8 5 6 9 6 6 6 5 4 4 7 7 3 6 11 7 6 4 8 7 12 6 4 10 2 4 9 11 7 4 7 7 8 8 6 7 9 8 4 5 8 13 6 6 6 8 6 2 5 6 7 5 4 4 4 4 2 6 4 8 3 4 7 7 6 7 7 10 5 10 6 7 4 11 8 4", "output": "14888" }, { "input": "100 100\n30 35 23 43 28 49 31 32 30 44 32 37 33 34 38 28 43 32 33 32 50 32 41 38 33 20 40 36 29 21 42 25 23 34 43 32 37 31 30 27 36 32 45 37 33 29 38 34 35 33 28 19 37 33 28 41 31 29 41 27 32 39 30 34 37 40 33 38 35 32 32 34 35 34 28 39 28 34 40 45 31 25 42 28 29 31 33 21 36 33 34 37 40 42 39 30 36 34 34 40", "output": "13118" }, { "input": "100 100\n71 87 100 85 89 98 90 90 71 65 76 75 85 100 81 100 91 80 73 89 86 78 82 89 77 92 78 90 100 81 85 89 73 100 66 60 72 88 91 73 93 76 88 81 86 78 83 77 74 93 97 94 85 78 82 78 91 91 100 78 89 76 78 82 81 78 83 88 87 83 78 98 85 97 98 89 88 75 76 86 74 81 70 76 86 84 99 100 89 94 72 84 82 88 83 89 78 99 87 76", "output": "3030" }, { "input": "100 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": "19700" }, { "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": "0" }, { "input": "100 100\n1 1 2 1 1 1 1 1 1 1 1 1 1 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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "19696" }, { "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 99", "output": "0" }, { "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 98 100 100 100 100 98 100 100 100 100 100 100 99 98 100 100 93 100 100 98 100 100 100 100 93 100 96 100 100 100 94 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 95 88 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" }, { "input": "100 100\n95 100 100 100 100 100 100 100 100 100 100 100 100 100 87 100 100 100 94 100 100 100 100 100 100 100 100 100 100 100 100 99 100 100 100 100 100 100 100 100 100 100 90 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 97 100 100 100 96 100 98 100 100 100 100 100 96 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 97 100 100 100 100", "output": "2" }, { "input": "100 1\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": "0" }, { "input": "100 2\n2 1 1 2 1 1 1 1 2 2 2 2 1 1 1 2 1 1 1 2 2 2 2 1 1 1 1 2 2 2 1 2 2 2 2 1 2 2 1 1 1 1 1 1 2 2 1 2 1 1 1 2 1 2 2 2 2 1 1 1 2 2 1 2 1 1 1 2 1 2 2 1 1 1 2 2 1 1 2 1 1 2 1 1 1 2 1 1 1 1 2 1 1 1 1 2 1 2 1 1", "output": "16" }, { "input": "3 5\n5 5 5", "output": "0" }, { "input": "7 7\n1 1 1 1 1 1 1", "output": "77" }, { "input": "1 1\n1", "output": "0" }, { "input": "100 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": "19700" }, { "input": "4 10\n10 10 10 10", "output": "0" }, { "input": "1 10\n10", "output": "0" }, { "input": "10 1\n1 1 1 1 1 1 1 1 1 1", "output": "0" }, { "input": "3 10\n10 10 10", "output": "0" }, { "input": "2 4\n3 4", "output": "0" }, { "input": "1 2\n2", "output": "0" }, { "input": "3 4\n4 4 4", "output": "0" }, { "input": "3 2\n2 2 1", "output": "0" }, { "input": "5 5\n5 5 5 5 5", "output": "0" }, { "input": "3 3\n3 3 3", "output": "0" }, { "input": "2 9\n8 9", "output": "0" }, { "input": "3 10\n9 10 10", "output": "0" }, { "input": "1 3\n3", "output": "0" }, { "input": "2 2\n1 2", "output": "0" }, { "input": "2 10\n10 10", "output": "0" }, { "input": "23 14\n7 11 13 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14", "output": "0" }, { "input": "2 10\n9 10", "output": "0" }, { "input": "2 2\n2 2", "output": "0" }, { "input": "10 5\n5 5 5 5 5 5 5 5 5 4", "output": "0" }, { "input": "3 5\n4 5 5", "output": "0" }, { "input": "5 4\n4 4 4 4 4", "output": "0" }, { "input": "2 10\n10 9", "output": "0" }, { "input": "4 5\n3 5 5 5", "output": "0" }, { "input": "10 5\n5 5 5 5 5 5 5 5 5 5", "output": "0" }, { "input": "3 10\n10 10 9", "output": "0" }, { "input": "5 1\n1 1 1 1 1", "output": "0" }, { "input": "2 1\n1 1", "output": "0" }, { "input": "4 10\n9 10 10 10", "output": "0" }, { "input": "5 2\n2 2 2 2 2", "output": "0" }, { "input": "2 5\n4 5", "output": "0" }, { "input": "5 10\n10 10 10 10 10", "output": "0" }, { "input": "2 6\n6 6", "output": "0" }, { "input": "2 9\n9 9", "output": "0" }, { "input": "3 10\n10 9 10", "output": "0" }, { "input": "4 40\n39 40 40 40", "output": "0" }, { "input": "3 4\n3 4 4", "output": "0" }, { "input": "9 9\n9 9 9 9 9 9 9 9 9", "output": "0" }, { "input": "1 4\n4", "output": "0" }, { "input": "4 7\n1 1 1 1", "output": "44" }, { "input": "1 5\n5", "output": "0" }, { "input": "3 1\n1 1 1", "output": "0" }, { "input": "1 100\n100", "output": "0" }, { "input": "2 7\n3 5", "output": "10" }, { "input": "3 6\n6 6 6", "output": "0" }, { "input": "4 2\n1 2 2 2", "output": "0" }, { "input": "4 5\n4 5 5 5", "output": "0" }, { "input": "5 5\n1 1 1 1 1", "output": "35" }, { "input": "66 2\n1 2 2 2 2 1 1 2 1 2 2 2 2 2 2 1 2 1 2 1 2 1 2 1 2 1 1 1 1 2 2 1 2 2 1 1 2 1 2 2 1 1 1 2 1 2 1 2 1 2 1 2 2 2 2 1 2 2 1 2 1 1 1 2 2 1", "output": "0" }, { "input": "2 2\n2 1", "output": "0" }, { "input": "5 5\n5 5 5 4 5", "output": "0" }, { "input": "3 7\n1 1 1", "output": "33" }, { "input": "2 5\n5 5", "output": "0" }, { "input": "1 7\n1", "output": "11" }, { "input": "6 7\n1 1 1 1 1 1", "output": "66" }, { "input": "99 97\n15 80 78 69 12 84 36 51 89 77 88 10 1 19 67 85 6 36 8 70 14 45 88 97 22 13 75 57 83 27 13 97 9 90 68 51 76 37 5 2 16 92 11 48 13 77 35 19 15 74 22 29 21 12 28 42 56 5 32 41 62 75 71 71 68 72 24 77 11 28 78 27 53 88 74 66 1 42 18 16 18 39 75 38 81 5 13 39 40 75 13 36 53 83 9 54 57 63 64", "output": "10077" }, { "input": "8 7\n1 1 1 1 1 1 1 1", "output": "88" }, { "input": "3 2\n2 2 2", "output": "0" }, { "input": "6 5\n5 5 5 5 5 5", "output": "0" }, { "input": "10 5\n5 5 5 5 5 5 5 4 1 1", "output": "8" }, { "input": "1 5\n1", "output": "7" }, { "input": "10 10\n10 10 10 10 10 10 10 10 10 10", "output": "0" }, { "input": "2 3\n2 3", "output": "0" }, { "input": "1 9\n9", "output": "0" }, { "input": "74 2\n2 2 2 2 1 2 2 1 1 1 2 2 1 2 2 2 2 1 2 1 1 1 2 1 1 2 2 1 2 1 1 2 1 1 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 1 1 2 1 1 1 1 1 1 2 2 2 1 1 1 1 1 2 2 2 2 2 2 1 2", "output": "0" }, { "input": "5 5\n5 5 5 5 4", "output": "0" } ]
1,495,450,933
2,147,483,647
Python 3
OK
TESTS
106
62
0
n,k=map(int,input().split()) mrks=list(map(int,input().split())) ns=sum(mrks) reqm=(k-.5)*n if(ns<reqm): dff=reqm-ns res=dff*2 res=int(round(res)) print(res) else: print(0)
Title: Straight <<A>> Time Limit: None seconds Memory Limit: None megabytes Problem Description: Noora is a student of one famous high school. It's her final year in school — she is going to study in university next year. However, she has to get an «A» graduation certificate in order to apply to a prestigious one. In school, where Noora is studying, teachers are putting down marks to the online class register, which are integers from 1 to *k*. The worst mark is 1, the best is *k*. Mark that is going to the certificate, is calculated as an average of all the marks, rounded to the closest integer. If several answers are possible, rounding up is produced. For example, 7.3 is rounded to 7, but 7.5 and 7.8784 — to 8. For instance, if Noora has marks [8,<=9], then the mark to the certificate is 9, because the average is equal to 8.5 and rounded to 9, but if the marks are [8,<=8,<=9], Noora will have graduation certificate with 8. To graduate with «A» certificate, Noora has to have mark *k*. Noora got *n* marks in register this year. However, she is afraid that her marks are not enough to get final mark *k*. Noora decided to ask for help in the internet, where hacker Leha immediately responded to her request. He is ready to hack class register for Noora and to add Noora any number of additional marks from 1 to *k*. At the same time, Leha want his hack be unseen to everyone, so he decided to add as less as possible additional marks. Please help Leha to calculate the minimal number of marks he has to add, so that final Noora's mark will become equal to *k*. Input Specification: The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*k*<=≤<=100) denoting the number of marks, received by Noora and the value of highest possible mark. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*k*) denoting marks received by Noora before Leha's hack. Output Specification: Print a single integer — minimal number of additional marks, that Leha has to add in order to change Noora's final mark to *k*. Demo Input: ['2 10\n8 9\n', '3 5\n4 4 4\n'] Demo Output: ['4', '3'] Note: Consider the first example testcase. Maximal mark is 10, Noora received two marks — 8 and 9, so current final mark is 9. To fix it, Leha can add marks [10, 10, 10, 10] (4 marks in total) to the registry, achieving Noora having average mark equal to <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/1b961585522f76271546da990a6228e7c666277f.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Consequently, new final mark is 10. Less number of marks won't fix the situation. In the second example Leha can add [5, 5, 5] to the registry, so that making average mark equal to 4.5, which is enough to have 5 in the certificate.
```python n,k=map(int,input().split()) mrks=list(map(int,input().split())) ns=sum(mrks) reqm=(k-.5)*n if(ns<reqm): dff=reqm-ns res=dff*2 res=int(round(res)) print(res) else: print(0) ```
3
831
A
Unimodal Array
PROGRAMMING
1,000
[ "implementation" ]
null
null
Array of integers is unimodal, if: - it is strictly increasing in the beginning; - after that it is constant; - after that it is strictly decreasing. The first block (increasing) and the last block (decreasing) may be absent. It is allowed that both of this blocks are absent. For example, the following three arrays are unimodal: [5,<=7,<=11,<=11,<=2,<=1], [4,<=4,<=2], [7], but the following three are not unimodal: [5,<=5,<=6,<=6,<=1], [1,<=2,<=1,<=2], [4,<=5,<=5,<=6]. Write a program that checks if an array is unimodal.
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in the array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1<=000) — the elements of the array.
Print "YES" if the given array is unimodal. Otherwise, print "NO". You can output each letter in any case (upper or lower).
[ "6\n1 5 5 5 4 2\n", "5\n10 20 30 20 10\n", "4\n1 2 1 2\n", "7\n3 3 3 3 3 3 3\n" ]
[ "YES\n", "YES\n", "NO\n", "YES\n" ]
In the first example the array is unimodal, because it is strictly increasing in the beginning (from position 1 to position 2, inclusively), that it is constant (from position 2 to position 4, inclusively) and then it is strictly decreasing (from position 4 to position 6, inclusively).
500
[ { "input": "6\n1 5 5 5 4 2", "output": "YES" }, { "input": "5\n10 20 30 20 10", "output": "YES" }, { "input": "4\n1 2 1 2", "output": "NO" }, { "input": "7\n3 3 3 3 3 3 3", "output": "YES" }, { "input": "6\n5 7 11 11 2 1", "output": "YES" }, { "input": "1\n7", "output": "YES" }, { "input": "100\n527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527", "output": "YES" }, { "input": "5\n5 5 6 6 1", "output": "NO" }, { "input": "3\n4 4 2", "output": "YES" }, { "input": "4\n4 5 5 6", "output": "NO" }, { "input": "3\n516 516 515", "output": "YES" }, { "input": "5\n502 503 508 508 507", "output": "YES" }, { "input": "10\n538 538 538 538 538 538 538 538 538 538", "output": "YES" }, { "input": "15\n452 454 455 455 450 448 443 442 439 436 433 432 431 428 426", "output": "YES" }, { "input": "20\n497 501 504 505 509 513 513 513 513 513 513 513 513 513 513 513 513 513 513 513", "output": "YES" }, { "input": "50\n462 465 465 465 463 459 454 449 444 441 436 435 430 429 426 422 421 418 417 412 408 407 406 403 402 399 395 392 387 386 382 380 379 376 374 371 370 365 363 359 358 354 350 349 348 345 342 341 338 337", "output": "YES" }, { "input": "70\n290 292 294 297 299 300 303 305 310 312 313 315 319 320 325 327 328 333 337 339 340 341 345 350 351 354 359 364 367 372 374 379 381 382 383 384 389 393 395 397 398 400 402 405 409 411 416 417 422 424 429 430 434 435 440 442 445 449 451 453 458 460 465 470 474 477 482 482 482 479", "output": "YES" }, { "input": "99\n433 435 439 444 448 452 457 459 460 464 469 470 471 476 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 479 478 477 476 474 469 468 465 460 457 453 452 450 445 443 440 438 433 432 431 430 428 425 421 418 414 411 406 402 397 396 393", "output": "YES" }, { "input": "100\n537 538 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543", "output": "YES" }, { "input": "100\n524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 521", "output": "YES" }, { "input": "100\n235 239 243 245 246 251 254 259 260 261 264 269 272 275 277 281 282 285 289 291 292 293 298 301 302 303 305 307 308 310 315 317 320 324 327 330 334 337 342 346 347 348 353 357 361 366 370 373 376 378 379 384 386 388 390 395 398 400 405 408 413 417 420 422 424 429 434 435 438 441 443 444 445 450 455 457 459 463 465 468 471 473 475 477 481 486 491 494 499 504 504 504 504 504 504 504 504 504 504 504", "output": "YES" }, { "input": "100\n191 196 201 202 207 212 216 219 220 222 224 227 230 231 234 235 238 242 246 250 253 254 259 260 263 267 269 272 277 280 284 287 288 290 295 297 300 305 307 312 316 320 324 326 327 332 333 334 338 343 347 351 356 358 363 368 370 374 375 380 381 386 390 391 394 396 397 399 402 403 405 410 414 419 422 427 429 433 437 442 443 447 448 451 455 459 461 462 464 468 473 478 481 484 485 488 492 494 496 496", "output": "YES" }, { "input": "100\n466 466 466 466 466 464 459 455 452 449 446 443 439 436 435 433 430 428 425 424 420 419 414 412 407 404 401 396 394 391 386 382 379 375 374 369 364 362 360 359 356 351 350 347 342 340 338 337 333 330 329 326 321 320 319 316 311 306 301 297 292 287 286 281 278 273 269 266 261 257 256 255 253 252 250 245 244 242 240 238 235 230 225 220 216 214 211 209 208 206 203 198 196 194 192 190 185 182 177 173", "output": "YES" }, { "input": "100\n360 362 367 369 374 377 382 386 389 391 396 398 399 400 405 410 413 416 419 420 423 428 431 436 441 444 445 447 451 453 457 459 463 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 465 460 455 453 448 446 443 440 436 435 430 425 420 415 410 405 404 403 402 399 394 390 387 384 382 379 378 373 372 370 369 366 361 360 355 353 349 345 344 342 339 338 335 333", "output": "YES" }, { "input": "1\n1000", "output": "YES" }, { "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": "YES" }, { "input": "100\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000", "output": "YES" }, { "input": "100\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1", "output": "YES" }, { "input": "100\n1 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000", "output": "YES" }, { "input": "100\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 999 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000", "output": "NO" }, { "input": "100\n998 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 999 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 999", "output": "NO" }, { "input": "100\n537 538 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 691 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543", "output": "NO" }, { "input": "100\n527 527 527 527 527 527 527 527 872 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527", "output": "NO" }, { "input": "100\n524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 208 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 521", "output": "NO" }, { "input": "100\n235 239 243 245 246 251 254 259 260 261 264 269 272 275 277 281 282 285 289 291 292 293 298 301 302 303 305 307 308 310 315 317 320 324 327 330 334 337 342 921 347 348 353 357 361 366 370 373 376 378 379 384 386 388 390 395 398 400 405 408 413 417 420 422 424 429 434 435 438 441 443 444 445 450 455 457 459 463 465 468 471 473 475 477 481 486 491 494 499 504 504 504 504 504 504 504 504 504 504 504", "output": "NO" }, { "input": "100\n191 196 201 202 207 212 216 219 220 222 224 227 230 231 234 235 238 242 246 250 253 254 259 260 263 267 269 272 277 280 284 287 288 290 295 297 300 305 307 312 316 320 324 326 327 332 333 334 338 343 347 351 356 358 119 368 370 374 375 380 381 386 390 391 394 396 397 399 402 403 405 410 414 419 422 427 429 433 437 442 443 447 448 451 455 459 461 462 464 468 473 478 481 484 485 488 492 494 496 496", "output": "NO" }, { "input": "100\n466 466 466 466 466 464 459 455 452 449 446 443 439 436 435 433 430 428 425 424 420 419 414 412 407 404 401 396 394 391 386 382 379 375 374 369 364 362 360 359 356 335 350 347 342 340 338 337 333 330 329 326 321 320 319 316 311 306 301 297 292 287 286 281 278 273 269 266 261 257 256 255 253 252 250 245 244 242 240 238 235 230 225 220 216 214 211 209 208 206 203 198 196 194 192 190 185 182 177 173", "output": "NO" }, { "input": "100\n360 362 367 369 374 377 382 386 389 391 396 398 399 400 405 410 413 416 419 420 423 428 525 436 441 444 445 447 451 453 457 459 463 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 465 460 455 453 448 446 443 440 436 435 430 425 420 415 410 405 404 403 402 399 394 390 387 384 382 379 378 373 372 370 369 366 361 360 355 353 349 345 344 342 339 338 335 333", "output": "NO" }, { "input": "3\n1 2 3", "output": "YES" }, { "input": "3\n3 2 1", "output": "YES" }, { "input": "3\n1 1 2", "output": "NO" }, { "input": "3\n2 1 1", "output": "NO" }, { "input": "3\n2 1 2", "output": "NO" }, { "input": "3\n3 1 2", "output": "NO" }, { "input": "3\n1 3 2", "output": "YES" }, { "input": "100\n395 399 402 403 405 408 413 415 419 424 426 431 434 436 439 444 447 448 449 454 457 459 461 462 463 464 465 469 470 473 477 480 482 484 485 487 492 494 496 497 501 504 505 508 511 506 505 503 500 499 494 490 488 486 484 481 479 474 472 471 470 465 462 458 453 452 448 445 440 436 433 430 428 426 424 421 419 414 413 408 404 403 399 395 393 388 384 379 377 375 374 372 367 363 360 356 353 351 350 346", "output": "YES" }, { "input": "100\n263 268 273 274 276 281 282 287 288 292 294 295 296 300 304 306 308 310 311 315 319 322 326 330 333 336 339 341 342 347 351 353 356 358 363 365 369 372 374 379 383 387 389 391 392 395 396 398 403 404 407 411 412 416 419 421 424 428 429 430 434 436 440 443 444 448 453 455 458 462 463 464 469 473 477 481 486 489 492 494 499 503 506 509 510 512 514 515 511 510 507 502 499 498 494 491 486 482 477 475", "output": "YES" }, { "input": "100\n482 484 485 489 492 496 499 501 505 509 512 517 520 517 515 513 509 508 504 503 498 496 493 488 486 481 478 476 474 470 468 466 463 459 456 453 452 449 445 444 439 438 435 432 428 427 424 423 421 419 417 413 408 405 402 399 397 393 388 385 380 375 370 366 363 361 360 355 354 352 349 345 340 336 335 331 329 327 324 319 318 317 315 314 310 309 307 304 303 300 299 295 291 287 285 282 280 278 273 271", "output": "YES" }, { "input": "100\n395 399 402 403 405 408 413 415 419 424 426 431 434 436 439 444 447 448 449 454 457 459 461 462 463 464 465 469 470 473 477 480 482 484 485 487 492 494 496 32 501 504 505 508 511 506 505 503 500 499 494 490 488 486 484 481 479 474 472 471 470 465 462 458 453 452 448 445 440 436 433 430 428 426 424 421 419 414 413 408 404 403 399 395 393 388 384 379 377 375 374 372 367 363 360 356 353 351 350 346", "output": "NO" }, { "input": "100\n263 268 273 274 276 281 282 287 288 292 294 295 296 300 304 306 308 310 311 315 319 322 326 330 247 336 339 341 342 347 351 353 356 358 363 365 369 372 374 379 383 387 389 391 392 395 396 398 403 404 407 411 412 416 419 421 424 428 429 430 434 436 440 443 444 448 453 455 458 462 463 464 469 473 477 481 486 489 492 494 499 503 506 509 510 512 514 515 511 510 507 502 499 498 494 491 486 482 477 475", "output": "NO" }, { "input": "100\n482 484 485 489 492 496 499 501 505 509 512 517 520 517 515 513 509 508 504 503 497 496 493 488 486 481 478 476 474 470 468 466 463 459 456 453 452 449 445 444 439 438 435 432 428 427 424 423 421 419 417 413 408 405 402 399 397 393 388 385 380 375 370 366 363 361 360 355 354 352 349 345 340 336 335 331 329 327 324 319 318 317 315 314 310 309 307 304 303 300 299 295 291 287 285 282 280 278 273 271", "output": "YES" }, { "input": "2\n1 3", "output": "YES" }, { "input": "2\n1 2", "output": "YES" }, { "input": "5\n2 2 1 1 1", "output": "NO" }, { "input": "4\n1 3 2 2", "output": "NO" }, { "input": "6\n1 2 1 2 2 1", "output": "NO" }, { "input": "2\n4 2", "output": "YES" }, { "input": "3\n3 2 2", "output": "NO" }, { "input": "9\n1 2 2 3 3 4 3 2 1", "output": "NO" }, { "input": "4\n5 5 4 4", "output": "NO" }, { "input": "2\n2 1", "output": "YES" }, { "input": "5\n5 4 3 2 1", "output": "YES" }, { "input": "7\n4 3 3 3 3 3 3", "output": "NO" }, { "input": "5\n1 2 3 4 5", "output": "YES" }, { "input": "3\n2 2 1", "output": "YES" }, { "input": "3\n4 3 3", "output": "NO" }, { "input": "7\n1 5 5 4 3 3 1", "output": "NO" }, { "input": "6\n3 3 1 2 2 1", "output": "NO" }, { "input": "5\n1 2 1 2 1", "output": "NO" }, { "input": "2\n5 1", "output": "YES" }, { "input": "9\n1 2 3 4 4 3 2 2 1", "output": "NO" }, { "input": "3\n2 2 3", "output": "NO" }, { "input": "2\n5 4", "output": "YES" }, { "input": "5\n1 3 3 2 2", "output": "NO" }, { "input": "10\n1 2 3 4 5 6 7 8 9 99", "output": "YES" }, { "input": "4\n1 2 3 4", "output": "YES" }, { "input": "3\n5 5 2", "output": "YES" }, { "input": "4\n1 4 2 3", "output": "NO" }, { "input": "2\n3 2", "output": "YES" }, { "input": "5\n1 2 2 1 1", "output": "NO" }, { "input": "4\n3 3 2 2", "output": "NO" }, { "input": "5\n1 2 3 2 2", "output": "NO" }, { "input": "5\n5 6 6 5 5", "output": "NO" }, { "input": "4\n2 2 1 1", "output": "NO" }, { "input": "5\n5 4 3 3 2", "output": "NO" }, { "input": "7\n1 3 3 3 2 1 1", "output": "NO" }, { "input": "9\n5 6 6 5 5 4 4 3 3", "output": "NO" }, { "input": "6\n1 5 5 3 2 2", "output": "NO" }, { "input": "5\n2 1 3 3 1", "output": "NO" }, { "input": "2\n4 3", "output": "YES" }, { "input": "5\n3 2 2 1 1", "output": "NO" }, { "input": "4\n5 4 3 2", "output": "YES" }, { "input": "4\n4 4 1 1", "output": "NO" }, { "input": "4\n3 3 1 1", "output": "NO" }, { "input": "4\n4 4 2 2", "output": "NO" }, { "input": "5\n4 4 3 2 2", "output": "NO" }, { "input": "8\n4 4 4 4 5 6 7 8", "output": "NO" }, { "input": "5\n3 5 4 4 3", "output": "NO" }, { "input": "6\n2 5 3 3 2 2", "output": "NO" }, { "input": "4\n5 5 2 2", "output": "NO" }, { "input": "5\n1 2 2 3 5", "output": "NO" } ]
1,641,360,005
2,147,483,647
Python 3
OK
TESTS
101
46
0
n = int(input()) a = list(map(int, input().split())) flag = 0 m = max(a) p = a.index(m) for i in range (p): if a[i] >= a[i+1]: flag = 1 break for i in range (n-1): if p == n-1: break if a[p] == a[p+1]: p += 1 for i in range (p,n-1): if a[i] <= a[i+1]: flag = 1 break if flag == 0: print('Yes') else: print('No')
Title: Unimodal Array Time Limit: None seconds Memory Limit: None megabytes Problem Description: Array of integers is unimodal, if: - it is strictly increasing in the beginning; - after that it is constant; - after that it is strictly decreasing. The first block (increasing) and the last block (decreasing) may be absent. It is allowed that both of this blocks are absent. For example, the following three arrays are unimodal: [5,<=7,<=11,<=11,<=2,<=1], [4,<=4,<=2], [7], but the following three are not unimodal: [5,<=5,<=6,<=6,<=1], [1,<=2,<=1,<=2], [4,<=5,<=5,<=6]. Write a program that checks if an array is unimodal. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in the array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1<=000) — the elements of the array. Output Specification: Print "YES" if the given array is unimodal. Otherwise, print "NO". You can output each letter in any case (upper or lower). Demo Input: ['6\n1 5 5 5 4 2\n', '5\n10 20 30 20 10\n', '4\n1 2 1 2\n', '7\n3 3 3 3 3 3 3\n'] Demo Output: ['YES\n', 'YES\n', 'NO\n', 'YES\n'] Note: In the first example the array is unimodal, because it is strictly increasing in the beginning (from position 1 to position 2, inclusively), that it is constant (from position 2 to position 4, inclusively) and then it is strictly decreasing (from position 4 to position 6, inclusively).
```python n = int(input()) a = list(map(int, input().split())) flag = 0 m = max(a) p = a.index(m) for i in range (p): if a[i] >= a[i+1]: flag = 1 break for i in range (n-1): if p == n-1: break if a[p] == a[p+1]: p += 1 for i in range (p,n-1): if a[i] <= a[i+1]: flag = 1 break if flag == 0: print('Yes') else: print('No') ```
3
0
none
none
none
0
[ "none" ]
null
null
A dragon symbolizes wisdom, power and wealth. On Lunar New Year's Day, people model a dragon with bamboo strips and clothes, raise them with rods, and hold the rods high and low to resemble a flying dragon. A performer holding the rod low is represented by a 1, while one holding it high is represented by a 2. Thus, the line of performers can be represented by a sequence *a*1,<=*a*2,<=...,<=*a**n*. Little Tommy is among them. He would like to choose an interval [*l*,<=*r*] (1<=≤<=*l*<=≤<=*r*<=≤<=*n*), then reverse *a**l*,<=*a**l*<=+<=1,<=...,<=*a**r* so that the length of the longest non-decreasing subsequence of the new sequence is maximum. A non-decreasing subsequence is a sequence of indices *p*1,<=*p*2,<=...,<=*p**k*, such that *p*1<=&lt;<=*p*2<=&lt;<=...<=&lt;<=*p**k* and *a**p*1<=≤<=*a**p*2<=≤<=...<=≤<=*a**p**k*. The length of the subsequence is *k*.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=2000), denoting the length of the original sequence. The second line contains *n* space-separated integers, describing the original sequence *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=2,<=*i*<==<=1,<=2,<=...,<=*n*).
Print a single integer, which means the maximum possible length of the longest non-decreasing subsequence of the new sequence.
[ "4\n1 2 1 2\n", "10\n1 1 2 2 2 1 1 2 2 1\n" ]
[ "4\n", "9\n" ]
In the first example, after reversing [2, 3], the array will become [1, 1, 2, 2], where the length of the longest non-decreasing subsequence is 4. In the second example, after reversing [3, 7], the array will become [1, 1, 1, 1, 2, 2, 2, 2, 2, 1], where the length of the longest non-decreasing subsequence is 9.
0
[ { "input": "4\n1 2 1 2", "output": "4" }, { "input": "10\n1 1 2 2 2 1 1 2 2 1", "output": "9" }, { "input": "200\n2 1 1 2 1 2 2 2 2 2 1 2 2 1 1 2 2 1 1 1 2 1 1 2 2 2 2 2 1 1 2 1 2 1 1 2 1 1 1 1 2 1 2 2 1 2 1 1 1 2 1 1 1 2 2 2 1 1 1 1 2 2 2 1 2 2 2 1 2 2 2 1 2 1 2 1 2 1 1 1 1 2 2 2 1 1 2 1 2 1 2 1 2 2 1 1 1 2 2 2 2 1 2 2 2 1 1 1 1 2 1 1 1 2 2 1 2 1 2 2 2 1 2 1 2 1 2 1 2 2 2 1 2 2 2 1 1 1 1 2 1 2 1 1 1 2 1 2 2 2 1 2 1 1 1 1 1 1 2 1 1 2 2 2 1 2 1 1 1 1 2 2 1 2 1 2 1 2 1 2 1 2 2 1 1 1 1 2 2 1 1 2 2 1 2 2 1 2 2 2", "output": "116" }, { "input": "200\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "200" }, { "input": "1\n2", "output": "1" }, { "input": "2\n1 2", "output": "2" }, { "input": "2\n2 1", "output": "2" }, { "input": "3\n2 1 2", "output": "3" }, { "input": "3\n1 2 1", "output": "3" }, { "input": "100\n1 1 2 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 2 1 2 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 2 1 1 1 1 1 1 2 1 1 1 1 1 1 2 1 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 2 1 2 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2", "output": "89" }, { "input": "100\n1 2 1 2 2 2 1 1 2 2 2 1 2 2 2 1 1 1 1 2 2 2 1 1 1 1 1 2 1 1 2 2 2 2 1 1 2 2 2 1 2 1 2 1 2 1 2 2 1 2 2 1 2 1 2 2 1 2 1 1 2 2 1 2 2 1 1 1 1 2 2 1 2 2 1 1 1 1 1 1 1 2 2 2 1 1 2 2 1 2 2 1 1 1 2 2 1 1 1 1", "output": "60" }, { "input": "100\n1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 2 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 2 1 1 1 1 1 1 2 1 2 1 1 1 1 1 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 1 2 1 1 2 2 1 1 1 1 1 1 2 2", "output": "91" }, { "input": "100\n2 2 2 2 1 2 1 1 1 1 2 1 1 1 2 1 1 1 1 2 2 1 1 1 1 2 1 1 1 2 1 2 1 2 2 2 2 2 1 1 1 1 2 1 1 2 1 1 2 2 1 1 1 1 2 1 1 2 2 2 2 1 1 1 2 1 1 1 2 2 1 1 2 1 2 2 2 1 1 2 2 1 1 2 2 1 1 1 2 2 1 1 2 2 2 1 1 1 2 2", "output": "63" }, { "input": "200\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 1 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 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 1 2 2 2 2 2 1 2 2 2 2 1 2 2 2 2 2 2 1 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 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2", "output": "187" }, { "input": "200\n1 2 1 1 1 1 1 1 2 1 1 1 2 1 1 1 1 1 1 2 2 1 1 1 1 1 2 1 1 1 1 2 1 2 1 1 1 2 1 2 1 1 2 2 2 2 2 1 2 1 1 2 2 2 2 1 2 2 1 1 2 2 1 2 1 1 1 2 2 1 2 2 1 2 2 2 2 2 1 1 1 2 2 2 1 1 2 2 1 2 1 2 2 1 2 2 1 2 1 2 2 1 1 1 1 1 2 1 1 1 1 2 1 1 2 1 1 1 2 2 2 1 1 2 1 1 2 1 2 1 1 1 2 1 2 1 2 2 1 1 1 1 2 1 1 2 1 2 1 1 2 2 1 1 1 2 1 1 1 2 1 2 1 2 1 1 1 1 2 2 2 1 2 1 2 2 1 2 1 1 2 1 1 2 1 2 1 2 1 1 2 1 1 2 2 1 2 1 1 2", "output": "131" }, { "input": "200\n1 2 2 1 2 1 1 1 1 1 2 1 2 2 2 2 2 1 2 1 1 2 2 2 1 2 1 1 2 2 1 1 1 2 2 1 2 1 2 2 1 1 1 2 1 1 1 1 1 1 2 2 2 1 2 1 1 2 2 1 2 1 1 1 2 2 1 2 2 2 2 1 1 2 2 2 2 2 1 2 1 2 2 1 2 2 2 2 2 1 2 1 1 1 2 1 1 2 2 2 1 2 1 1 1 1 1 1 2 2 2 1 2 2 1 1 1 2 2 2 1 1 2 2 2 1 2 1 1 2 1 2 2 1 1 1 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 1 2 2 1 1 1 2 2 2 1 2 2 1 2 2 2 2 1 2 1 1 1 2 1 1 2 1 1 1 1 2 1 2 1 1 1 2 2 2 2 1 1 2 2 2 2", "output": "118" }, { "input": "20\n1 2 2 2 2 2 2 2 1 1 1 2 2 2 1 2 1 1 2 1", "output": "16" }, { "input": "200\n2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 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 1 1 1 1 1 1 1 1 1 1 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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 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 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "191" }, { "input": "10\n2 2 2 2 2 2 2 2 2 1", "output": "10" }, { "input": "6\n2 2 2 1 1 1", "output": "6" } ]
1,518,702,500
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
109
1,000
5,632,000
# # n, m = map(int, input().split()) n = int(input()) data = list(map(int, input().split())) # n = 10 # data = [1, 1, 2, 2, 2, 1, 1, 2, 2, 1] L = list() count = 0 i = 0 sumRight = 0 while i < n: for j in [1, 2]: while i < n and data[i] == j: i += 1 count += 1 L.append(count) if j == 2: sumRight += count count = 0 # print(data) # print(L) m = len(L) maxLength = 0 switch = [1, 0] sumLeft = 0 for i in range(1, m): if (i - 1) % 2 == 0: sumLeft += L[i - 1] else: sumRight -= L[i - 1] c1 = 0 c2 = sumRight for j in range(i, m): if j % 2 == 0: c1 += L[j] else: c2 -= L[j] if sumRight - c2 > c1: c1 = sumRight - c2 length = sumLeft + c1 + c2 # print(length) maxLength = max([maxLength, length]) print(maxLength)
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: A dragon symbolizes wisdom, power and wealth. On Lunar New Year's Day, people model a dragon with bamboo strips and clothes, raise them with rods, and hold the rods high and low to resemble a flying dragon. A performer holding the rod low is represented by a 1, while one holding it high is represented by a 2. Thus, the line of performers can be represented by a sequence *a*1,<=*a*2,<=...,<=*a**n*. Little Tommy is among them. He would like to choose an interval [*l*,<=*r*] (1<=≤<=*l*<=≤<=*r*<=≤<=*n*), then reverse *a**l*,<=*a**l*<=+<=1,<=...,<=*a**r* so that the length of the longest non-decreasing subsequence of the new sequence is maximum. A non-decreasing subsequence is a sequence of indices *p*1,<=*p*2,<=...,<=*p**k*, such that *p*1<=&lt;<=*p*2<=&lt;<=...<=&lt;<=*p**k* and *a**p*1<=≤<=*a**p*2<=≤<=...<=≤<=*a**p**k*. The length of the subsequence is *k*. Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=2000), denoting the length of the original sequence. The second line contains *n* space-separated integers, describing the original sequence *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=2,<=*i*<==<=1,<=2,<=...,<=*n*). Output Specification: Print a single integer, which means the maximum possible length of the longest non-decreasing subsequence of the new sequence. Demo Input: ['4\n1 2 1 2\n', '10\n1 1 2 2 2 1 1 2 2 1\n'] Demo Output: ['4\n', '9\n'] Note: In the first example, after reversing [2, 3], the array will become [1, 1, 2, 2], where the length of the longest non-decreasing subsequence is 4. In the second example, after reversing [3, 7], the array will become [1, 1, 1, 1, 2, 2, 2, 2, 2, 1], where the length of the longest non-decreasing subsequence is 9.
```python # # n, m = map(int, input().split()) n = int(input()) data = list(map(int, input().split())) # n = 10 # data = [1, 1, 2, 2, 2, 1, 1, 2, 2, 1] L = list() count = 0 i = 0 sumRight = 0 while i < n: for j in [1, 2]: while i < n and data[i] == j: i += 1 count += 1 L.append(count) if j == 2: sumRight += count count = 0 # print(data) # print(L) m = len(L) maxLength = 0 switch = [1, 0] sumLeft = 0 for i in range(1, m): if (i - 1) % 2 == 0: sumLeft += L[i - 1] else: sumRight -= L[i - 1] c1 = 0 c2 = sumRight for j in range(i, m): if j % 2 == 0: c1 += L[j] else: c2 -= L[j] if sumRight - c2 > c1: c1 = sumRight - c2 length = sumLeft + c1 + c2 # print(length) maxLength = max([maxLength, length]) print(maxLength) ```
0
389
A
Fox and Number Game
PROGRAMMING
1,000
[ "greedy", "math" ]
null
null
Fox Ciel is playing a game with numbers now. Ciel has *n* positive integers: *x*1, *x*2, ..., *x**n*. She can do the following operation as many times as needed: select two different indexes *i* and *j* such that *x**i* &gt; *x**j* hold, and then apply assignment *x**i* = *x**i* - *x**j*. The goal is to make the sum of all numbers as small as possible. Please help Ciel to find this minimal sum.
The first line contains an integer *n* (2<=≤<=*n*<=≤<=100). Then the second line contains *n* integers: *x*1, *x*2, ..., *x**n* (1<=≤<=*x**i*<=≤<=100).
Output a single integer — the required minimal sum.
[ "2\n1 2\n", "3\n2 4 6\n", "2\n12 18\n", "5\n45 12 27 30 18\n" ]
[ "2\n", "6\n", "12\n", "15\n" ]
In the first example the optimal way is to do the assignment: *x*<sub class="lower-index">2</sub> = *x*<sub class="lower-index">2</sub> - *x*<sub class="lower-index">1</sub>. In the second example the optimal sequence of operations is: *x*<sub class="lower-index">3</sub> = *x*<sub class="lower-index">3</sub> - *x*<sub class="lower-index">2</sub>, *x*<sub class="lower-index">2</sub> = *x*<sub class="lower-index">2</sub> - *x*<sub class="lower-index">1</sub>.
500
[ { "input": "2\n1 2", "output": "2" }, { "input": "3\n2 4 6", "output": "6" }, { "input": "2\n12 18", "output": "12" }, { "input": "5\n45 12 27 30 18", "output": "15" }, { "input": "2\n1 1", "output": "2" }, { "input": "2\n100 100", "output": "200" }, { "input": "2\n87 58", "output": "58" }, { "input": "39\n52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52", "output": "2028" }, { "input": "59\n96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96", "output": "5664" }, { "input": "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": "10000" }, { "input": "100\n70 70 77 42 98 84 56 91 35 21 7 70 77 77 56 63 14 84 56 14 77 77 63 70 14 7 28 91 63 49 21 84 98 56 77 98 98 84 98 14 7 56 49 28 91 98 7 56 14 91 14 98 49 28 98 14 98 98 14 70 35 28 63 28 49 63 63 56 91 98 35 42 42 35 63 35 42 14 63 21 77 56 42 77 35 91 56 21 28 84 56 70 70 91 98 70 84 63 21 98", "output": "700" }, { "input": "39\n63 21 21 42 21 63 21 84 42 21 84 63 42 63 84 84 84 42 42 84 21 63 42 63 42 42 63 42 42 63 84 42 21 84 21 63 42 21 42", "output": "819" }, { "input": "59\n70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70", "output": "4130" }, { "input": "87\n44 88 88 88 88 66 88 22 22 88 88 44 88 22 22 22 88 88 88 88 66 22 88 88 88 88 66 66 44 88 44 44 66 22 88 88 22 44 66 44 88 66 66 22 22 22 22 88 22 22 44 66 88 22 22 88 66 66 88 22 66 88 66 88 66 44 88 44 22 44 44 22 44 88 44 44 44 44 22 88 88 88 66 66 88 44 22", "output": "1914" }, { "input": "15\n63 63 63 63 63 63 63 63 63 63 63 63 63 63 63", "output": "945" }, { "input": "39\n63 77 21 14 14 35 21 21 70 42 21 70 28 77 28 77 7 42 63 7 98 49 98 84 35 70 70 91 14 42 98 7 42 7 98 42 56 35 91", "output": "273" }, { "input": "18\n18 18 18 36 36 36 54 72 54 36 72 54 36 36 36 36 18 36", "output": "324" }, { "input": "46\n71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71", "output": "3266" }, { "input": "70\n66 11 66 11 44 11 44 99 55 22 88 11 11 22 55 44 22 77 44 77 77 22 44 55 88 11 99 99 88 22 77 77 66 11 11 66 99 55 55 44 66 44 77 44 44 55 33 55 44 88 77 77 22 66 33 44 11 22 55 44 22 66 77 33 33 44 44 44 22 33", "output": "770" }, { "input": "10\n60 12 96 48 60 24 60 36 60 60", "output": "120" }, { "input": "20\n51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51", "output": "1020" }, { "input": "50\n58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58", "output": "2900" }, { "input": "98\n70 60 100 30 70 20 30 50 50 30 90 40 30 40 60 80 60 60 80 50 10 80 20 10 20 10 50 70 30 80 30 50 60 90 90 100 60 30 90 20 30 60 90 80 60 60 10 90 10 50 40 40 80 90 100 40 70 40 30 50 60 50 60 30 40 20 90 60 20 20 20 70 60 70 50 100 90 50 20 40 80 60 10 60 50 40 40 10 50 10 40 10 80 100 100 90 10 90", "output": "980" }, { "input": "100\n82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82", "output": "8200" }, { "input": "100\n11 87 77 93 3 54 21 93 9 71 37 23 69 85 74 3 48 99 51 31 56 19 21 96 39 6 4 4 29 69 100 42 1 22 81 53 48 49 81 61 10 7 40 61 7 71 51 59 79 44 50 35 95 80 83 8 98 40 18 94 84 49 52 74 66 69 39 37 100 44 38 62 2 80 46 31 35 53 5 60 21 49 63 55 20 53 80 53 66 34 23 92 77 50 86 63 65 24 12 70", "output": "100" }, { "input": "2\n100 1", "output": "2" }, { "input": "2\n18 30", "output": "12" }, { "input": "2\n3 5", "output": "2" }, { "input": "2\n1 10", "output": "2" }, { "input": "2\n8 5", "output": "2" }, { "input": "5\n2 3 5 8 18", "output": "5" }, { "input": "5\n2 4 1 6 8", "output": "5" }, { "input": "3\n12 10 5", "output": "3" }, { "input": "3\n6 10 15", "output": "3" } ]
1,536,153,830
2,147,483,647
Python 3
OK
TESTS
34
124
0
n = int(input()) m = [int(k) for k in input().split()] def g(a,b): c = a%b if c != 0: return c else: return b def f(a,b): h = [] for k in a: h.append(g(k,b)) return h m.sort() while True: if sum(m) != n*m[0]: m = f(m,m[0]) m.sort() else: break print(m[0]*n)
Title: Fox and Number Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Fox Ciel is playing a game with numbers now. Ciel has *n* positive integers: *x*1, *x*2, ..., *x**n*. She can do the following operation as many times as needed: select two different indexes *i* and *j* such that *x**i* &gt; *x**j* hold, and then apply assignment *x**i* = *x**i* - *x**j*. The goal is to make the sum of all numbers as small as possible. Please help Ciel to find this minimal sum. Input Specification: The first line contains an integer *n* (2<=≤<=*n*<=≤<=100). Then the second line contains *n* integers: *x*1, *x*2, ..., *x**n* (1<=≤<=*x**i*<=≤<=100). Output Specification: Output a single integer — the required minimal sum. Demo Input: ['2\n1 2\n', '3\n2 4 6\n', '2\n12 18\n', '5\n45 12 27 30 18\n'] Demo Output: ['2\n', '6\n', '12\n', '15\n'] Note: In the first example the optimal way is to do the assignment: *x*<sub class="lower-index">2</sub> = *x*<sub class="lower-index">2</sub> - *x*<sub class="lower-index">1</sub>. In the second example the optimal sequence of operations is: *x*<sub class="lower-index">3</sub> = *x*<sub class="lower-index">3</sub> - *x*<sub class="lower-index">2</sub>, *x*<sub class="lower-index">2</sub> = *x*<sub class="lower-index">2</sub> - *x*<sub class="lower-index">1</sub>.
```python n = int(input()) m = [int(k) for k in input().split()] def g(a,b): c = a%b if c != 0: return c else: return b def f(a,b): h = [] for k in a: h.append(g(k,b)) return h m.sort() while True: if sum(m) != n*m[0]: m = f(m,m[0]) m.sort() else: break print(m[0]*n) ```
3
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,694,204,533
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
3
92
0
n=int(input()) n1=int(input()) c=1 nc=0 for i in range(n-1): n2=int(input()) if n1 == n2: c+=1 n1=n2 if n1 != n2: nc+=c c=0 print(max(nc,c))
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()) n1=int(input()) c=1 nc=0 for i in range(n-1): n2=int(input()) if n1 == n2: c+=1 n1=n2 if n1 != n2: nc+=c c=0 print(max(nc,c)) ```
0
672
A
Summer Camp
PROGRAMMING
800
[ "implementation" ]
null
null
Every year, hundreds of people come to summer camps, they learn new algorithms and solve hard problems. This is your first year at summer camp, and you are asked to solve the following problem. All integers starting with 1 are written in one line. The prefix of these line is "123456789101112131415...". Your task is to print the *n*-th digit of this string (digits are numbered starting with 1.
The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the position of the digit you need to print.
Print the *n*-th digit of the line.
[ "3\n", "11\n" ]
[ "3\n", "0\n" ]
In the first sample the digit at position 3 is '3', as both integers 1 and 2 consist on one digit. In the second sample, the digit at position 11 is '0', it belongs to the integer 10.
500
[ { "input": "3", "output": "3" }, { "input": "11", "output": "0" }, { "input": "12", "output": "1" }, { "input": "13", "output": "1" }, { "input": "29", "output": "9" }, { "input": "30", "output": "2" }, { "input": "1000", "output": "3" }, { "input": "999", "output": "9" }, { "input": "100", "output": "5" }, { "input": "123", "output": "6" }, { "input": "8", "output": "8" }, { "input": "157", "output": "3" }, { "input": "289", "output": "1" }, { "input": "179", "output": "4" }, { "input": "942", "output": "0" }, { "input": "879", "output": "9" }, { "input": "394", "output": "1" }, { "input": "423", "output": "7" }, { "input": "952", "output": "3" }, { "input": "121", "output": "5" }, { "input": "613", "output": "2" }, { "input": "945", "output": "1" }, { "input": "270", "output": "6" }, { "input": "781", "output": "2" }, { "input": "453", "output": "7" }, { "input": "171", "output": "0" }, { "input": "643", "output": "2" }, { "input": "570", "output": "6" }, { "input": "750", "output": "6" }, { "input": "500", "output": "0" }, { "input": "2", "output": "2" }, { "input": "1", "output": "1" }, { "input": "108", "output": "5" }, { "input": "500", "output": "0" }, { "input": "189", "output": "9" }, { "input": "491", "output": "0" }, { "input": "191", "output": "0" } ]
1,565,305,635
2,147,483,647
Python 3
OK
TESTS
37
109
0
n = int(input()) cur = 0 s = '' for i in range(1, n + 1): s += str(i) if len(s) >= n: print(s[n - 1]) exit(0)
Title: Summer Camp Time Limit: None seconds Memory Limit: None megabytes Problem Description: Every year, hundreds of people come to summer camps, they learn new algorithms and solve hard problems. This is your first year at summer camp, and you are asked to solve the following problem. All integers starting with 1 are written in one line. The prefix of these line is "123456789101112131415...". Your task is to print the *n*-th digit of this string (digits are numbered starting with 1. Input Specification: The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the position of the digit you need to print. Output Specification: Print the *n*-th digit of the line. Demo Input: ['3\n', '11\n'] Demo Output: ['3\n', '0\n'] Note: In the first sample the digit at position 3 is '3', as both integers 1 and 2 consist on one digit. In the second sample, the digit at position 11 is '0', it belongs to the integer 10.
```python n = int(input()) cur = 0 s = '' for i in range(1, n + 1): s += str(i) if len(s) >= n: print(s[n - 1]) exit(0) ```
3
25
A
IQ test
PROGRAMMING
1,300
[ "brute force" ]
A. IQ test
2
256
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness.
The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
[ "5\n2 4 7 8 10\n", "4\n1 2 1 1\n" ]
[ "3\n", "2\n" ]
none
0
[ { "input": "5\n2 4 7 8 10", "output": "3" }, { "input": "4\n1 2 1 1", "output": "2" }, { "input": "3\n1 2 2", "output": "1" }, { "input": "3\n100 99 100", "output": "2" }, { "input": "3\n5 3 2", "output": "3" }, { "input": "4\n43 28 1 91", "output": "2" }, { "input": "4\n75 13 94 77", "output": "3" }, { "input": "4\n97 8 27 3", "output": "2" }, { "input": "10\n95 51 12 91 85 3 1 31 25 7", "output": "3" }, { "input": "20\n88 96 66 51 14 88 2 92 18 72 18 88 20 30 4 82 90 100 24 46", "output": "4" }, { "input": "30\n20 94 56 50 10 98 52 32 14 22 24 60 4 8 98 46 34 68 82 82 98 90 50 20 78 49 52 94 64 36", "output": "26" }, { "input": "50\n79 27 77 57 37 45 27 49 65 33 57 21 71 19 75 85 65 61 23 97 85 9 23 1 9 3 99 77 77 21 79 69 15 37 15 7 93 81 13 89 91 31 45 93 15 97 55 80 85 83", "output": "48" }, { "input": "60\n46 11 73 65 3 69 3 53 43 53 97 47 55 93 31 75 35 3 9 73 23 31 3 81 91 79 61 21 15 11 11 11 81 7 83 75 39 87 83 59 89 55 93 27 49 67 67 29 1 93 11 17 9 19 35 21 63 31 31 25", "output": "1" }, { "input": "70\n28 42 42 92 64 54 22 38 38 78 62 38 4 38 14 66 4 92 66 58 94 26 4 44 41 88 48 82 44 26 74 44 48 4 16 92 34 38 26 64 94 4 30 78 50 54 12 90 8 16 80 98 28 100 74 50 36 42 92 18 76 98 8 22 2 50 58 50 64 46", "output": "25" }, { "input": "100\n43 35 79 53 13 91 91 45 65 83 57 9 42 39 85 45 71 51 61 59 31 13 63 39 25 21 79 39 91 67 21 61 97 75 93 83 29 79 59 97 11 37 63 51 39 55 91 23 21 17 47 23 35 75 49 5 69 99 5 7 41 17 25 89 15 79 21 63 53 81 43 91 59 91 69 99 85 15 91 51 49 37 65 7 89 81 21 93 61 63 97 93 45 17 13 69 57 25 75 73", "output": "13" }, { "input": "100\n50 24 68 60 70 30 52 22 18 74 68 98 20 82 4 46 26 68 100 78 84 58 74 98 38 88 68 86 64 80 82 100 20 22 98 98 52 6 94 10 48 68 2 18 38 22 22 82 44 20 66 72 36 58 64 6 36 60 4 96 76 64 12 90 10 58 64 60 74 28 90 26 24 60 40 58 2 16 76 48 58 36 82 60 24 44 4 78 28 38 8 12 40 16 38 6 66 24 31 76", "output": "99" }, { "input": "100\n47 48 94 48 14 18 94 36 96 22 12 30 94 20 48 98 40 58 2 94 8 36 98 18 98 68 2 60 76 38 18 100 8 72 100 68 2 86 92 72 58 16 48 14 6 58 72 76 6 88 80 66 20 28 74 62 86 68 90 86 2 56 34 38 56 90 4 8 76 44 32 86 12 98 38 34 54 92 70 94 10 24 82 66 90 58 62 2 32 58 100 22 58 72 2 22 68 72 42 14", "output": "1" }, { "input": "99\n38 20 68 60 84 16 28 88 60 48 80 28 4 92 70 60 46 46 20 34 12 100 76 2 40 10 8 86 6 80 50 66 12 34 14 28 26 70 46 64 34 96 10 90 98 96 56 88 50 74 70 94 2 94 24 66 68 46 22 30 6 10 64 32 88 14 98 100 64 58 50 18 50 50 8 38 8 16 54 2 60 54 62 84 92 98 4 72 66 26 14 88 99 16 10 6 88 56 22", "output": "93" }, { "input": "99\n50 83 43 89 53 47 69 1 5 37 63 87 95 15 55 95 75 89 33 53 89 75 93 75 11 85 49 29 11 97 49 67 87 11 25 37 97 73 67 49 87 43 53 97 43 29 53 33 45 91 37 73 39 49 59 5 21 43 87 35 5 63 89 57 63 47 29 99 19 85 13 13 3 13 43 19 5 9 61 51 51 57 15 89 13 97 41 13 99 79 13 27 97 95 73 33 99 27 23", "output": "1" }, { "input": "98\n61 56 44 30 58 14 20 24 88 28 46 56 96 52 58 42 94 50 46 30 46 80 72 88 68 16 6 60 26 90 10 98 76 20 56 40 30 16 96 20 88 32 62 30 74 58 36 76 60 4 24 36 42 54 24 92 28 14 2 74 86 90 14 52 34 82 40 76 8 64 2 56 10 8 78 16 70 86 70 42 70 74 22 18 76 98 88 28 62 70 36 72 20 68 34 48 80 98", "output": "1" }, { "input": "98\n66 26 46 42 78 32 76 42 26 82 8 12 4 10 24 26 64 44 100 46 94 64 30 18 88 28 8 66 30 82 82 28 74 52 62 80 80 60 94 86 64 32 44 88 92 20 12 74 94 28 34 58 4 22 16 10 94 76 82 58 40 66 22 6 30 32 92 54 16 76 74 98 18 48 48 30 92 2 16 42 84 74 30 60 64 52 50 26 16 86 58 96 79 60 20 62 82 94", "output": "93" }, { "input": "95\n9 31 27 93 17 77 75 9 9 53 89 39 51 99 5 1 11 39 27 49 91 17 27 79 81 71 37 75 35 13 93 4 99 55 85 11 23 57 5 43 5 61 15 35 23 91 3 81 99 85 43 37 39 27 5 67 7 33 75 59 13 71 51 27 15 93 51 63 91 53 43 99 25 47 17 71 81 15 53 31 59 83 41 23 73 25 91 91 13 17 25 13 55 57 29", "output": "32" }, { "input": "100\n91 89 81 45 53 1 41 3 77 93 55 97 55 97 87 27 69 95 73 41 93 21 75 35 53 56 5 51 87 59 91 67 33 3 99 45 83 17 97 47 75 97 7 89 17 99 23 23 81 25 55 97 27 35 69 5 77 35 93 19 55 59 37 21 31 37 49 41 91 53 73 69 7 37 37 39 17 71 7 97 55 17 47 23 15 73 31 39 57 37 9 5 61 41 65 57 77 79 35 47", "output": "26" }, { "input": "99\n38 56 58 98 80 54 26 90 14 16 78 92 52 74 40 30 84 14 44 80 16 90 98 68 26 24 78 72 42 16 84 40 14 44 2 52 50 2 12 96 58 66 8 80 44 52 34 34 72 98 74 4 66 74 56 21 8 38 76 40 10 22 48 32 98 34 12 62 80 68 64 82 22 78 58 74 20 22 48 56 12 38 32 72 6 16 74 24 94 84 26 38 18 24 76 78 98 94 72", "output": "56" }, { "input": "100\n44 40 6 40 56 90 98 8 36 64 76 86 98 76 36 92 6 30 98 70 24 98 96 60 24 82 88 68 86 96 34 42 58 10 40 26 56 10 88 58 70 32 24 28 14 82 52 12 62 36 70 60 52 34 74 30 78 76 10 16 42 94 66 90 70 38 52 12 58 22 98 96 14 68 24 70 4 30 84 98 8 50 14 52 66 34 100 10 28 100 56 48 38 12 38 14 91 80 70 86", "output": "97" }, { "input": "100\n96 62 64 20 90 46 56 90 68 36 30 56 70 28 16 64 94 34 6 32 34 50 94 22 90 32 40 2 72 10 88 38 28 92 20 26 56 80 4 100 100 90 16 74 74 84 8 2 30 20 80 32 16 46 92 56 42 12 96 64 64 42 64 58 50 42 74 28 2 4 36 32 70 50 54 92 70 16 45 76 28 16 18 50 48 2 62 94 4 12 52 52 4 100 70 60 82 62 98 42", "output": "79" }, { "input": "99\n14 26 34 68 90 58 50 36 8 16 18 6 2 74 54 20 36 84 32 50 52 2 26 24 3 64 20 10 54 26 66 44 28 72 4 96 78 90 96 86 68 28 94 4 12 46 100 32 22 36 84 32 44 94 76 94 4 52 12 30 74 4 34 64 58 72 44 16 70 56 54 8 14 74 8 6 58 62 98 54 14 40 80 20 36 72 28 98 20 58 40 52 90 64 22 48 54 70 52", "output": "25" }, { "input": "95\n82 86 30 78 6 46 80 66 74 72 16 24 18 52 52 38 60 36 86 26 62 28 22 46 96 26 94 84 20 46 66 88 76 32 12 86 74 18 34 88 4 48 94 6 58 6 100 82 4 24 88 32 54 98 34 48 6 76 42 88 42 28 100 4 22 2 10 66 82 54 98 20 60 66 38 98 32 47 86 58 6 100 12 46 2 42 8 84 78 28 24 70 34 28 86", "output": "78" }, { "input": "90\n40 50 8 42 76 24 58 42 26 68 20 48 54 12 34 84 14 36 32 88 6 50 96 56 20 92 48 16 40 34 96 46 20 84 30 50 20 98 8 44 96 42 8 76 70 38 84 30 40 88 84 72 2 22 52 58 16 62 100 66 80 40 50 32 14 62 88 72 22 99 76 50 84 82 8 82 98 46 26 40 2 98 18 78 30 72 70 18 34 68", "output": "70" }, { "input": "80\n81 43 87 1 55 43 53 61 27 19 43 13 89 9 33 83 75 55 97 71 91 37 95 5 21 69 81 93 95 69 31 83 55 7 97 7 79 57 8 61 27 85 49 1 15 97 63 79 29 73 41 85 5 41 31 93 67 11 63 59 15 99 91 77 43 69 23 23 81 73 19 1 67 51 1 75 99 67 3 81", "output": "39" }, { "input": "98\n13 83 61 27 35 1 85 95 97 73 95 65 73 45 5 43 27 83 91 19 11 3 85 59 9 39 69 23 45 7 51 85 5 71 5 95 1 51 75 3 43 57 3 11 33 71 21 99 47 41 87 39 71 87 31 85 91 49 83 5 49 85 47 91 55 99 33 23 31 23 23 73 29 77 55 31 25 5 81 49 91 15 15 39 87 5 9 40 69 47 29 33 11 21 49 79 51 83", "output": "88" }, { "input": "3\n100 100 1", "output": "3" } ]
1,602,524,155
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
184
307,200
nums = [] n = int(input()) for i in range(0, n): num = int(input()) nums.append(num) if nums[0] % 2 + nums[1] % 2 + nums[2] % 2 < 2: check = True else: check = False for i in range(len(nums)): if check: if nums[i] % 2 != 0: print(i + 1) else: if nums[i] % 2 == 0: print(i + 1)
Title: IQ test Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness. Input Specification: The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. Output Specification: Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. Demo Input: ['5\n2 4 7 8 10\n', '4\n1 2 1 1\n'] Demo Output: ['3\n', '2\n'] Note: none
```python nums = [] n = int(input()) for i in range(0, n): num = int(input()) nums.append(num) if nums[0] % 2 + nums[1] % 2 + nums[2] % 2 < 2: check = True else: check = False for i in range(len(nums)): if check: if nums[i] % 2 != 0: print(i + 1) else: if nums[i] % 2 == 0: print(i + 1) ```
-1
141
A
Amusing Joke
PROGRAMMING
800
[ "implementation", "sortings", "strings" ]
null
null
So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's name and the host's name in honor of this event. Then the hung the letters above the main entrance. One night, when everyone went to bed, someone took all the letters of our characters' names. Then he may have shuffled the letters and put them in one pile in front of the door. The next morning it was impossible to find the culprit who had made the disorder. But everybody wondered whether it is possible to restore the names of the host and his guests from the letters lying at the door? That is, we need to verify that there are no extra letters, and that nobody will need to cut more letters. Help the "New Year and Christmas Men" and their friends to cope with this problem. You are given both inscriptions that hung over the front door the previous night, and a pile of letters that were found at the front door next morning.
The input file consists of three lines: the first line contains the guest's name, the second line contains the name of the residence host and the third line contains letters in a pile that were found at the door in the morning. All lines are not empty and contain only uppercase Latin letters. The length of each line does not exceed 100.
Print "YES" without the quotes, if the letters in the pile could be permuted to make the names of the "New Year and Christmas Men". Otherwise, print "NO" without the quotes.
[ "SANTACLAUS\nDEDMOROZ\nSANTAMOROZDEDCLAUS\n", "PAPAINOEL\nJOULUPUKKI\nJOULNAPAOILELUPUKKI\n", "BABBONATALE\nFATHERCHRISTMAS\nBABCHRISTMASBONATALLEFATHER\n" ]
[ "YES\n", "NO\n", "NO\n" ]
In the first sample the letters written in the last line can be used to write the names and there won't be any extra letters left. In the second sample letter "P" is missing from the pile and there's an extra letter "L". In the third sample there's an extra letter "L".
500
[ { "input": "SANTACLAUS\nDEDMOROZ\nSANTAMOROZDEDCLAUS", "output": "YES" }, { "input": "PAPAINOEL\nJOULUPUKKI\nJOULNAPAOILELUPUKKI", "output": "NO" }, { "input": "BABBONATALE\nFATHERCHRISTMAS\nBABCHRISTMASBONATALLEFATHER", "output": "NO" }, { "input": "B\nA\nAB", "output": "YES" }, { "input": "ONDOL\nJNPB\nONLNJBODP", "output": "YES" }, { "input": "Y\nW\nYW", "output": "YES" }, { "input": "OI\nM\nIMO", "output": "YES" }, { "input": "VFQRWWWACX\nGHZJPOQUSXRAQDGOGMR\nOPAWDOUSGWWCGQXXQAZJRQRGHRMVF", "output": "YES" }, { "input": "JUTCN\nPIGMZOPMEUFADQBW\nNWQGZMAIPUPOMCDUB", "output": "NO" }, { "input": "Z\nO\nZOCNDOLTBZKQLTBOLDEGXRHZGTTPBJBLSJCVSVXISQZCSFDEBXRCSGBGTHWOVIXYHACAGBRYBKBJAEPIQZHVEGLYH", "output": "NO" }, { "input": "IQ\nOQ\nQOQIGGKFNHJSGCGM", "output": "NO" }, { "input": "ROUWANOPNIGTVMIITVMZ\nOQTUPZMTKUGY\nVTVNGZITGPUNPMQOOATUUIYIWMMKZOTR", "output": "YES" }, { "input": "OVQELLOGFIOLEHXMEMBJDIGBPGEYFG\nJNKFPFFIJOFHRIFHXEWYZOPDJBZTJZKBWQTECNHRFSJPJOAPQT\nYAIPFFFEXJJNEJPLREIGODEGQZVMCOBDFKWTMWJSBEBTOFFQOHIQJLHFNXIGOHEZRZLFOKJBJPTPHPGY", "output": "YES" }, { "input": "NBJGVNGUISUXQTBOBKYHQCOOVQWUXWPXBUDLXPKX\nNSFQDFUMQDQWQ\nWXKKVNTDQQFXCUQBIMQGQHSLVGWSBFYBUPOWPBDUUJUXQNOQDNXOX", "output": "YES" }, { "input": "IJHHGKCXWDBRWJUPRDBZJLNTTNWKXLUGJSBWBOAUKWRAQWGFNL\nNJMWRMBCNPHXTDQQNZ\nWDNJRCLILNQRHWBANLTXWMJBPKUPGKJDJZAQWKTZFBRCTXHHBNXRGUQUNBNMWODGSJWW", "output": "YES" }, { "input": "SRROWANGUGZHCIEFYMQVTWVOMDWPUZJFRDUMVFHYNHNTTGNXCJ\nDJYWGLBFCCECXFHOLORDGDCNRHPWXNHXFCXQCEZUHRRNAEKUIX\nWCUJDNYHNHYOPWMHLDCDYRWBVOGHFFUKOZTXJRXJHRGWICCMRNEVNEGQWTZPNFCSHDRFCFQDCXMHTLUGZAXOFNXNVGUEXIACRERU", "output": "YES" }, { "input": "H\nJKFGHMIAHNDBMFXWYQLZRSVNOTEGCQSVUBYUOZBTNKTXPFQDCMKAGFITEUGOYDFIYQIORMFJEOJDNTFVIQEBICSNGKOSNLNXJWC\nBQSVDOGIHCHXSYNYTQFCHNJGYFIXTSOQINZOKSVQJMTKNTGFNXAVTUYEONMBQMGJLEWJOFGEARIOPKFUFCEMUBRBDNIIDFZDCLWK", "output": "YES" }, { "input": "DSWNZRFVXQ\nPVULCZGOOU\nUOLVZXNUPOQRZGWFVDSCANQTCLEIE", "output": "NO" }, { "input": "EUHTSCENIPXLTSBMLFHD\nIZAVSZPDLXOAGESUSE\nLXAELAZ", "output": "NO" }, { "input": "WYSJFEREGELSKRQRXDXCGBODEFZVSI\nPEJKMGFLBFFDWRCRFSHVEFLEBTJCVCHRJTLDTISHPOGFWPLEWNYJLMXWIAOTYOXMV\nHXERTZWLEXTPIOTFRVMEJVYFFJLRPFMXDEBNSGCEOFFCWTKIDDGCFYSJKGLHBORWEPLDRXRSJYBGASSVCMHEEJFLVI", "output": "NO" }, { "input": "EPBMDIUQAAUGLBIETKOKFLMTCVEPETWJRHHYKCKU\nHGMAETVPCFZYNNKDQXVXUALHYLOTCHM\nECGXACVKEYMCEDOTMKAUFHLHOMT", "output": "NO" }, { "input": "NUBKQEJHALANSHEIFUZHYEZKKDRFHQKAJHLAOWTZIMOCWOVVDW\nEFVOBIGAUAUSQGVSNBKNOBDMINODMFSHDL\nKLAMKNTHBFFOHVKWICHBKNDDQNEISODUSDNLUSIOAVWY", "output": "NO" }, { "input": "VXINHOMEQCATZUGAJEIUIZZLPYFGUTVLNBNWCUVMEENUXKBWBGZTMRJJVJDLVSLBABVCEUDDSQFHOYPYQTWVAGTWOLKYISAGHBMC\nZMRGXPZSHOGCSAECAPGVOIGCWEOWWOJXLGYRDMPXBLOKZVRACPYQLEQGFQCVYXAGBEBELUTDAYEAGPFKXRULZCKFHZCHVCWIRGPK\nRCVUXGQVNWFGRUDLLENNDQEJHYYVWMKTLOVIPELKPWCLSQPTAXAYEMGWCBXEVAIZGGDDRBRT", "output": "NO" }, { "input": "PHBDHHWUUTZAHELGSGGOPOQXSXEZIXHZTOKYFBQLBDYWPVCNQSXHEAXRRPVHFJBVBYCJIFOTQTWSUOWXLKMVJJBNLGTVITWTCZZ\nFUPDLNVIHRWTEEEHOOEC\nLOUSUUSZCHJBPEWIILUOXEXRQNCJEGTOBRVZLTTZAHTKVEJSNGHFTAYGY", "output": "NO" }, { "input": "GDSLNIIKTO\nJF\nPDQYFKDTNOLI", "output": "NO" }, { "input": "AHOKHEKKPJLJIIWJRCGY\nORELJCSIX\nZVWPXVFWFSWOXXLIHJKPXIOKRELYE", "output": "NO" }, { "input": "ZWCOJFORBPHXCOVJIDPKVECMHVHCOC\nTEV\nJVGTBFTLFVIEPCCHODOFOMCVZHWXVCPEH", "output": "NO" }, { "input": "AGFIGYWJLVMYZGNQHEHWKJIAWBPUAQFERMCDROFN\nPMJNHMVNRGCYZAVRWNDSMLSZHFNYIUWFPUSKKIGU\nMCDVPPRXGUAYLSDRHRURZASXUWZSIIEZCPXUVEONKNGNWRYGOSFMCKESMVJZHWWUCHWDQMLASLNNMHAU", "output": "NO" }, { "input": "XLOWVFCZSSXCSYQTIIDKHNTKNKEEDFMDZKXSPVLBIDIREDUAIN\nZKIWNDGBISDB\nSLPKLYFYSRNRMOSWYLJJDGFFENPOXYLPZFTQDANKBDNZDIIEWSUTTKYBKVICLG", "output": "NO" }, { "input": "PMUKBTRKFIAYVGBKHZHUSJYSSEPEOEWPOSPJLWLOCTUYZODLTUAFCMVKGQKRRUSOMPAYOTBTFPXYAZXLOADDEJBDLYOTXJCJYTHA\nTWRRAJLCQJTKOKWCGUH\nEWDPNXVCXWCDQCOYKKSOYTFSZTOOPKPRDKFJDETKSRAJRVCPDOBWUGPYRJPUWJYWCBLKOOTUPBESTOFXZHTYLLMCAXDYAEBUTAHM", "output": "NO" }, { "input": "QMIMGQRQDMJDPNFEFXSXQMCHEJKTWCTCVZPUAYICOIRYOWKUSIWXJLHDYWSBOITHTMINXFKBKAWZTXXBJIVYCRWKXNKIYKLDDXL\nV\nFWACCXBVDOJFIUAVYRALBYJKXXWIIFORRUHKHCXLDBZMXIYJWISFEAWTIQFIZSBXMKNOCQKVKRWDNDAMQSTKYLDNYVTUCGOJXJTW", "output": "NO" }, { "input": "XJXPVOOQODELPPWUISSYVVXRJTYBPDHJNENQEVQNVFIXSESKXVYPVVHPMOSX\nLEXOPFPVPSZK\nZVXVPYEYOYXVOISVLXPOVHEQVXPNQJIOPFDTXEUNMPEPPHELNXKKWSVSOXSBPSJDPVJVSRFQ", "output": "YES" }, { "input": "OSKFHGYNQLSRFSAHPXKGPXUHXTRBJNAQRBSSWJVEENLJCDDHFXVCUNPZAIVVO\nFNUOCXAGRRHNDJAHVVLGGEZQHWARYHENBKHP\nUOEFNWVXCUNERLKVTHAGPSHKHDYFPYWZHJKHQLSNFBJHVJANRXCNSDUGVDABGHVAOVHBJZXGRACHRXEGNRPQEAPORQSILNXFS", "output": "YES" }, { "input": "VYXYVVACMLPDHONBUTQFZTRREERBLKUJYKAHZRCTRLRCLOZYWVPBRGDQPFPQIF\nFE\nRNRPEVDRLYUQFYRZBCQLCYZEABKLRXCJLKVZBVFUEYRATOMDRTHFPGOWQVTIFPPH", "output": "YES" }, { "input": "WYXUZQJQNLASEGLHPMSARWMTTQMQLVAZLGHPIZTRVTCXDXBOLNXZPOFCTEHCXBZ\nBLQZRRWP\nGIQZXPLTTMNHQVWPPEAPLOCDMBSTHRCFLCQRRZXLVAOQEGZBRUZJXXZTMAWLZHSLWNQTYXB", "output": "YES" }, { "input": "MKVJTSSTDGKPVVDPYSRJJYEVGKBMSIOKHLZQAEWLRIBINVRDAJIBCEITKDHUCCVY\nPUJJQFHOGZKTAVNUGKQUHMKTNHCCTI\nQVJKUSIGTSVYUMOMLEGHWYKSKQTGATTKBNTKCJKJPCAIRJIRMHKBIZISEGFHVUVQZBDERJCVAKDLNTHUDCHONDCVVJIYPP", "output": "YES" }, { "input": "OKNJOEYVMZXJMLVJHCSPLUCNYGTDASKSGKKCRVIDGEIBEWRVBVRVZZTLMCJLXHJIA\nDJBFVRTARTFZOWN\nAGHNVUNJVCPLWSVYBJKZSVTFGLELZASLWTIXDDJXCZDICTVIJOTMVEYOVRNMJGRKKHRMEBORAKFCZJBR", "output": "YES" }, { "input": "OQZACLPSAGYDWHFXDFYFRRXWGIEJGSXWUONAFWNFXDTGVNDEWNQPHUXUJNZWWLBPYL\nOHBKWRFDRQUAFRCMT\nWIQRYXRJQWWRUWCYXNXALKFZGXFTLOODWRDPGURFUFUQOHPWBASZNVWXNCAGHWEHFYESJNFBMNFDDAPLDGT", "output": "YES" }, { "input": "OVIRQRFQOOWVDEPLCJETWQSINIOPLTLXHSQWUYUJNFBMKDNOSHNJQQCDHZOJVPRYVSV\nMYYDQKOOYPOOUELCRIT\nNZSOTVLJTTVQLFHDQEJONEOUOFOLYVSOIYUDNOSIQVIRMVOERCLMYSHPCQKIDRDOQPCUPQBWWRYYOXJWJQPNKH", "output": "YES" }, { "input": "WGMBZWNMSJXNGDUQUJTCNXDSJJLYRDOPEGPQXYUGBESDLFTJRZDDCAAFGCOCYCQMDBWK\nYOBMOVYTUATTFGJLYUQD\nDYXVTLQCYFJUNJTUXPUYOPCBCLBWNSDUJRJGWDOJDSQAAMUOJWSYERDYDXYTMTOTMQCGQZDCGNFBALGGDFKZMEBG", "output": "YES" }, { "input": "CWLRBPMEZCXAPUUQFXCUHAQTLPBTXUUKWVXKBHKNSSJFEXLZMXGVFHHVTPYAQYTIKXJJE\nMUFOSEUEXEQTOVLGDSCWM\nJUKEQCXOXWEHCGKFPBIGMWVJLXUONFXBYTUAXERYTXKCESKLXAEHVPZMMUFTHLXTTZSDMBJLQPEUWCVUHSQQVUASPF", "output": "YES" }, { "input": "IDQRX\nWETHO\nODPDGBHVUVSSISROHQJTUKPUCLXABIZQQPPBPKOSEWGEHRSRRNBAVLYEMZISMWWGKHVTXKUGUXEFBSWOIWUHRJGMWBMHQLDZHBWA", "output": "NO" }, { "input": "IXFDY\nJRMOU\nDF", "output": "NO" }, { "input": "JPSPZ\nUGCUB\nJMZZZZZZZZ", "output": "NO" }, { "input": "AC\nA\nBBA", "output": "NO" }, { "input": "UIKWWKXLSHTOOZOVGXKYSOJEHAUEEG\nKZXQDWJJWRXFHKJDQHJK\nXMZHTFOGEXAUJXXJUYVJIFOTKLZHDKELJWERHMGAWGKWAQKEKHIDWGGZVYOHKXRPWSJDPESFJUMKQYWBYUTHQYEFZUGKQOBHYDWB", "output": "NO" }, { "input": "PXWRXRPFLR\nPJRWWXIVHODV\nXW", "output": "NO" }, { "input": "CHTAZVHGSHCVIBK\nEQINEBKXEPYJSAZIMLDF\nZCZZZZDZMCZZEZDZZEZZZZQZZBZZZOZZCZE", "output": "NO" }, { "input": "GXPZFSELJJNDAXYRV\nUYBKPMVBSOVOJWMONLTJOJCNQKMTAHEWLHOWIIBH\nHCWNFWJPEJIWOVPTBMVCRJLSISSVNOHCKLBFMIUAIMASQWPXEYXBOXQGFEMYJLBKDCZIMJNHOJEDGGANIVYKQTUOSOVOPWHVJGXH", "output": "NO" }, { "input": "LFGJCJJDUTUP\nOVSBILTIYCJCRHKCIXCETJQJJ\nGIJJTJCLTJJJ", "output": "NO" }, { "input": "GIO\nPRL\nPRL", "output": "NO" }, { "input": "A\nB\nABC", "output": "NO" }, { "input": "KKK\nKKK\nZZZZZ", "output": "NO" }, { "input": "ZMYGQLDBLAPN\nZFJBKWHROVNPSJQUDFTHOCGREUFLYIWYICD\nZMJZZEDAZANKZZZZZZEZZBZDZZZZZZKHZZFZZZDZNZMDZZA", "output": "NO" } ]
1,681,471,980
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
s = input() s1= input() z = input() h = s+s1 for i in range(len(h)): if h[i] in z: del z[z.find(h[i])] else: print("NO") exit 0 print("YES")
Title: Amusing Joke Time Limit: None seconds Memory Limit: None megabytes Problem Description: So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's name and the host's name in honor of this event. Then the hung the letters above the main entrance. One night, when everyone went to bed, someone took all the letters of our characters' names. Then he may have shuffled the letters and put them in one pile in front of the door. The next morning it was impossible to find the culprit who had made the disorder. But everybody wondered whether it is possible to restore the names of the host and his guests from the letters lying at the door? That is, we need to verify that there are no extra letters, and that nobody will need to cut more letters. Help the "New Year and Christmas Men" and their friends to cope with this problem. You are given both inscriptions that hung over the front door the previous night, and a pile of letters that were found at the front door next morning. Input Specification: The input file consists of three lines: the first line contains the guest's name, the second line contains the name of the residence host and the third line contains letters in a pile that were found at the door in the morning. All lines are not empty and contain only uppercase Latin letters. The length of each line does not exceed 100. Output Specification: Print "YES" without the quotes, if the letters in the pile could be permuted to make the names of the "New Year and Christmas Men". Otherwise, print "NO" without the quotes. Demo Input: ['SANTACLAUS\nDEDMOROZ\nSANTAMOROZDEDCLAUS\n', 'PAPAINOEL\nJOULUPUKKI\nJOULNAPAOILELUPUKKI\n', 'BABBONATALE\nFATHERCHRISTMAS\nBABCHRISTMASBONATALLEFATHER\n'] Demo Output: ['YES\n', 'NO\n', 'NO\n'] Note: In the first sample the letters written in the last line can be used to write the names and there won't be any extra letters left. In the second sample letter "P" is missing from the pile and there's an extra letter "L". In the third sample there's an extra letter "L".
```python s = input() s1= input() z = input() h = s+s1 for i in range(len(h)): if h[i] in z: del z[z.find(h[i])] else: print("NO") exit 0 print("YES") ```
-1
112
A
Petya and Strings
PROGRAMMING
800
[ "implementation", "strings" ]
A. Petya and Strings
2
256
Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings lexicographically. The letters' case does not matter, that is an uppercase letter is considered equivalent to the corresponding lowercase letter. Help Petya perform the comparison.
Each of the first two lines contains a bought string. The strings' lengths range from 1 to 100 inclusive. It is guaranteed that the strings are of the same length and also consist of uppercase and lowercase Latin letters.
If the first string is less than the second one, print "-1". If the second string is less than the first one, print "1". If the strings are equal, print "0". Note that the letters' case is not taken into consideration when the strings are compared.
[ "aaaa\naaaA\n", "abs\nAbz\n", "abcdefg\nAbCdEfF\n" ]
[ "0\n", "-1\n", "1\n" ]
If you want more formal information about the lexicographical order (also known as the "dictionary order" or "alphabetical order"), you can visit the following site: - http://en.wikipedia.org/wiki/Lexicographical_order
500
[ { "input": "aaaa\naaaA", "output": "0" }, { "input": "abs\nAbz", "output": "-1" }, { "input": "abcdefg\nAbCdEfF", "output": "1" }, { "input": "asadasdasd\nasdwasdawd", "output": "-1" }, { "input": "aslkjlkasdd\nasdlkjdajwi", "output": "1" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "0" }, { "input": "aAaaaAAaAaaAzZsssSsdDfeEaeqZlpP\nAaaaAaaAaaAaZzSSSSsDdFeeAeQZLpp", "output": "0" }, { "input": "bwuEhEveouaTECagLZiqmUdxEmhRSOzMauJRWLQMppZOumxhAmwuGeDIkvkBLvMXwUoFmpAfDprBcFtEwOULcZWRQhcTbTbX\nHhoDWbcxwiMnCNexOsKsujLiSGcLllXOkRSbnOzThAjnnliLYFFmsYkOfpTxRNEfBsoUHfoLTiqAINRPxWRqrTJhgfkKcDOH", "output": "-1" }, { "input": "kGWUuguKzcvxqKTNpxeDWXpXkrXDvGMFGoXKDfPBZvWSDUyIYBynbKOUonHvmZaKeirUhfmVRKtGhAdBfKMWXDUoqvbfpfHYcg\ncvOULleuIIiYVVxcLZmHVpNGXuEpzcWZZWyMOwIwbpkKPwCfkVbKkUuosvxYCKjqfVmHfJKbdrsAcatPYgrCABaFcoBuOmMfFt", "output": "1" }, { "input": "nCeNVIzHqPceNhjHeHvJvgBsNFiXBATRrjSTXJzhLMDMxiJztphxBRlDlqwDFImWeEPkggZCXSRwelOdpNrYnTepiOqpvkr\nHJbjJFtlvNxIbkKlxQUwmZHJFVNMwPAPDRslIoXISBYHHfymyIaQHLgECPxAmqnOCizwXnIUBRmpYUBVPenoUKhCobKdOjL", "output": "1" }, { "input": "ttXjenUAlfixytHEOrPkgXmkKTSGYuyVXGIHYmWWYGlBYpHkujueqBSgjLguSgiMGJWATIGEUjjAjKXdMiVbHozZUmqQtFrT\nJziDBFBDmDJCcGqFsQwDFBYdOidLxxhBCtScznnDgnsiStlWFnEXQrJxqTXKPxZyIGfLIToETKWZBPUIBmLeImrlSBWCkTNo", "output": "1" }, { "input": "AjQhPqSVhwQQjcgCycjKorWBgFCRuQBwgdVuAPSMJAvTyxGVuFHjfJzkKfsmfhFbKqFrFIohSZBbpjgEHebezmVlGLTPSCTMf\nXhxWuSnMmKFrCUOwkTUmvKAfbTbHWzzOTzxJatLLCdlGnHVaBUnxDlsqpvjLHMThOPAFBggVKDyKBrZAmjnjrhHlrnSkyzBja", "output": "-1" }, { "input": "HCIgYtnqcMyjVngziNflxKHtdTmcRJhzMAjFAsNdWXFJYEhiTzsQUtFNkAbdrFBRmvLirkuirqTDvIpEfyiIqkrwsjvpPWTEdI\nErqiiWKsmIjyZuzgTlTqxYZwlrpvRyaVhRTOYUqtPMVGGtWOkDCOOQRKrkkRzPftyQCkYkzKkzTPqqXmeZhvvEEiEhkdOmoMvy", "output": "1" }, { "input": "mtBeJYILXcECGyEVSyzLFdQJbiVnnfkbsYYsdUJSIRmyzLfTTtFwIBmRLVnwcewIqcuydkcLpflHAFyDaToLiFMgeHvQorTVbI\nClLvyejznjbRfCDcrCzkLvqQaGzTjwmWONBdCctJAPJBcQrcYvHaSLQgPIJbmkFBhFzuQLBiRzAdNHulCjIAkBvZxxlkdzUWLR", "output": "1" }, { "input": "tjucSbGESVmVridTBjTmpVBCwwdWKBPeBvmgdxgIVLwQxveETnSdxkTVJpXoperWSgdpPMKNmwDiGeHfxnuqaDissgXPlMuNZIr\nHfjOOJhomqNIKHvqSgfySjlsWJQBuWYwhLQhlZYlpZwboMpoLoluGsBmhhlYgeIouwdkPfiaAIrkYRlxtiFazOPOllPsNZHcIZd", "output": "1" }, { "input": "AanbDfbZNlUodtBQlvPMyomStKNhgvSGhSbTdabxGFGGXCdpsJDimsAykKjfBDPMulkhBMsqLmVKLDoesHZsRAEEdEzqigueXInY\ncwfyjoppiJNrjrOLNZkqcGimrpTsiyFBVgMWEPXsMrxLJDDbtYzerXiFGuLBcQYitLdqhGHBpdjRnkUegmnwhGHAKXGyFtscWDSI", "output": "-1" }, { "input": "HRfxniwuJCaHOcaOVgjOGHXKrwxrDQxJpppeGDXnTAowyKbCsCQPbchCKeTWOcKbySSYnoaTJDnmRcyGPbfXJyZoPcARHBu\nxkLXvwkvGIWSQaFTznLOctUXNuzzBBOlqvzmVfTSejekTAlwidRrsxkbZTsGGeEWxCXHzqWVuLGoCyrGjKkQoHqduXwYQKC", "output": "-1" }, { "input": "OjYwwNuPESIazoyLFREpObIaMKhCaKAMWMfRGgucEuyNYRantwdwQkmflzfqbcFRaXBnZoIUGsFqXZHGKwlaBUXABBcQEWWPvkjW\nRxLqGcTTpBwHrHltCOllnTpRKLDofBUqqHxnOtVWPgvGaeHIevgUSOeeDOJubfqonFpVNGVbHFcAhjnyFvrrqnRgKhkYqQZmRfUl", "output": "-1" }, { "input": "tatuhQPIzjptlzzJpCAPXSRTKZRlwgfoCIsFjJquRoIDyZZYRSPdFUTjjUPhLBBfeEIfLQpygKXRcyQFiQsEtRtLnZErBqW\ntkHUjllbafLUWhVCnvblKjgYIEoHhsjVmrDBmAWbvtkHxDbRFvsXAjHIrujaDbYwOZmacknhZPeCcorbRgHjjgAgoJdjvLo", "output": "-1" }, { "input": "cymCPGqdXKUdADEWDdUaLEEMHiXHsdAZuDnJDMUvxvrLRBrPSDpXPAgMRoGplLtniFRTomDTAHXWAdgUveTxaqKVSvnOyhOwiRN\nuhmyEWzapiRNPFDisvHTbenXMfeZaHqOFlKjrfQjUBwdFktNpeiRoDWuBftZLcCZZAVfioOihZVNqiNCNDIsUdIhvbcaxpTRWoV", "output": "-1" }, { "input": "sSvpcITJAwghVfJaLKBmyjOkhltTGjYJVLWCYMFUomiJaKQYhXTajvZVHIMHbyckYROGQZzjWyWCcnmDmrkvTKfHSSzCIhsXgEZa\nvhCXkCwAmErGVBPBAnkSYEYvseFKbWSktoqaHYXUmYkHfOkRwuEyBRoGoBrOXBKVxXycjZGStuvDarnXMbZLWrbjrisDoJBdSvWJ", "output": "-1" }, { "input": "hJDANKUNBisOOINDsTixJmYgHNogtpwswwcvVMptfGwIjvqgwTYFcqTdyAqaqlnhOCMtsnWXQqtjFwQlEcBtMFAtSqnqthVb\nrNquIcjNWESjpPVWmzUJFrelpUZeGDmSvCurCqVmKHKVAAPkaHksniOlzjiKYIJtvbuQWZRufMebpTFPqyxIWWjfPaWYiNlK", "output": "-1" }, { "input": "ycLoapxsfsDTHMSfAAPIUpiEhQKUIXUcXEiopMBuuZLHtfPpLmCHwNMNQUwsEXxCEmKHTBSnKhtQhGWUvppUFZUgSpbeChX\ndCZhgVXofkGousCzObxZSJwXcHIaqUDSCPKzXntcVmPxtNcXmVcjsetZYxedmgQzXTZHMvzjoaXCMKsncGciSDqQWIIRlys", "output": "1" }, { "input": "nvUbnrywIePXcoukIhwTfUVcHUEgXcsMyNQhmMlTltZiCooyZiIKRIGVHMCnTKgzXXIuvoNDEZswKoACOBGSyVNqTNQqMhAG\nplxuGSsyyJjdvpddrSebOARSAYcZKEaKjqbCwvjhNykuaECoQVHTVFMKXwvrQXRaqXsHsBaGVhCxGRxNyGUbMlxOarMZNXxy", "output": "-1" }, { "input": "EncmXtAblQzcVRzMQqdDqXfAhXbtJKQwZVWyHoWUckohnZqfoCmNJDzexFgFJYrwNHGgzCJTzQQFnxGlhmvQTpicTkEeVICKac\nNIUNZoMLFMyAjVgQLITELJSodIXcGSDWfhFypRoGYuogJpnqGTotWxVqpvBHjFOWcDRDtARsaHarHaOkeNWEHGTaGOFCOFEwvK", "output": "-1" }, { "input": "UG\nak", "output": "1" }, { "input": "JZR\nVae", "output": "-1" }, { "input": "a\nZ", "output": "-1" }, { "input": "rk\nkv", "output": "1" }, { "input": "RvuT\nbJzE", "output": "1" }, { "input": "PPS\nydq", "output": "-1" }, { "input": "q\nq", "output": "0" }, { "input": "peOw\nIgSJ", "output": "1" }, { "input": "PyK\noKN", "output": "1" }, { "input": "O\ni", "output": "1" }, { "input": "NmGY\npDlP", "output": "-1" }, { "input": "nG\nZf", "output": "-1" }, { "input": "m\na", "output": "1" }, { "input": "MWyB\nWZEV", "output": "-1" }, { "input": "Gre\nfxc", "output": "1" }, { "input": "Ooq\nwap", "output": "-1" }, { "input": "XId\nlbB", "output": "1" }, { "input": "lfFpECEqUMEOJhipvkZjDPcpDNJedOVXiSMgBvBZbtfzIKekcvpWPCazKAhJyHircRtgcBIJwwstpHaLAgxFOngAWUZRgCef\nLfFPEcequmeojHIpVkzjDPcpdNJEDOVXiSmGBVBZBtfZikEKcvPwpCAzKAHJyHIrCRTgCbIJWwSTphALagXfOnGAwUzRGcEF", "output": "0" }, { "input": "DQBdtSEDtFGiNRUeJNbOIfDZnsryUlzJHGTXGFXnwsVyxNtLgmklmFvRCzYETBVdmkpJJIvIOkMDgCFHZOTODiYrkwXd\nDQbDtsEdTFginRUEJNBOIfdZnsryulZJHGtxGFxnwSvYxnTLgmKlmFVRCzyEtBVdmKpJjiVioKMDgCFhzoTODiYrKwXD", "output": "0" }, { "input": "tYWRijFQSzHBpCjUzqBtNvBKyzZRnIdWEuyqnORBQTLyOQglIGfYJIRjuxnbLvkqZakNqPiGDvgpWYkfxYNXsdoKXZtRkSasfa\nTYwRiJfqsZHBPcJuZQBTnVbkyZZRnidwEuYQnorbQTLYOqGligFyjirJUxnblVKqZaknQpigDVGPwyKfxyNXSDoKxztRKSaSFA", "output": "0" }, { "input": "KhScXYiErQIUtmVhNTCXSLAviefIeHIIdiGhsYnPkSBaDTvMkyanfMLBOvDWgRybLtDqvXVdVjccNunDyijhhZEAKBrdz\nkHsCXyiErqIuTMVHNTCxSLaViEFIEhIIDiGHsYNpKsBAdTvMKyANFMLBovdwGRYbLtdQVxvDVJCcNUndYiJHhzeakBrdZ", "output": "0" }, { "input": "cpPQMpjRQJKQVXjWDYECXbagSmNcVfOuBWNZxihdERraVuiOpSVDCPgTGuSQALNoVjySceHcKXwOEpSzXrEqWwwrYeppNiWhDVg\nCPPqmPjRqJkQvxJwdyECXBAGsMNcVfOuBWNzxIhderRavUiOpSvDCpGTgusqAlNovjyScEhCKXwoePSZxrEQwWwryEPPniWHDvG", "output": "0" }, { "input": "SajcCGMepaLjZIWLRBGFcrZRCRvvoCsIyKsQerbrwsIamxxpRmQSZSalasJLVFbCHCuXJlubciQAvLxXYBazLsMKLHLdDQ\nsaJcCgmEpaLJziWlrBgFcRzrCrVVOcSIykSQerBrwSIamxxPrMqSzSalASjLVFbChCUxjLUbCIQAVlxxybAZLsmkLhLDdQ", "output": "0" }, { "input": "kigPrWNTOUNDBskAfefjhHYZNYdnfZWuXWzHiBxFQryBbAkPtenFwWvCSTYGpzOntUNzNUhxRWjKmicTwLwJAnbAxj\nkigpRWntOUNdBsKaFEFjhhYZnYDNfzWuXwZhibxFQRybbakPteNfwwvcStyGPzoNTunznuHXrWjKMIctWLWJANBAxJ", "output": "0" }, { "input": "nTomZZuTTRTAAPoUsySVFGElrpQRNLjqvFmcYytiheQnjUhPLnqNBiYtQkljbcvmjuNAVKbvQOWpqqFlQhAhULIhquoCnjUI\nntOmzZuttrtAAPOUSySVFgeLRPQrNLjQvfmCyYTiHEQnjuHPlNQNbIYtqKLJBCVmjunavkbvQOWPQQFlqHaHULIHQuOcnJUi", "output": "0" }, { "input": "abac\nadaa", "output": "-1" }, { "input": "Bbc\nabc", "output": "1" }, { "input": "aaaba\naaaab", "output": "1" } ]
1,699,137,565
2,147,483,647
Python 3
OK
TESTS
53
92
0
str1 = input().lower() str2 = input().lower() if (str1 < str2): print(-1) elif (str1 > str2): print(1) else: print(0)
Title: Petya and Strings Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings lexicographically. The letters' case does not matter, that is an uppercase letter is considered equivalent to the corresponding lowercase letter. Help Petya perform the comparison. Input Specification: Each of the first two lines contains a bought string. The strings' lengths range from 1 to 100 inclusive. It is guaranteed that the strings are of the same length and also consist of uppercase and lowercase Latin letters. Output Specification: If the first string is less than the second one, print "-1". If the second string is less than the first one, print "1". If the strings are equal, print "0". Note that the letters' case is not taken into consideration when the strings are compared. Demo Input: ['aaaa\naaaA\n', 'abs\nAbz\n', 'abcdefg\nAbCdEfF\n'] Demo Output: ['0\n', '-1\n', '1\n'] Note: If you want more formal information about the lexicographical order (also known as the "dictionary order" or "alphabetical order"), you can visit the following site: - http://en.wikipedia.org/wiki/Lexicographical_order
```python str1 = input().lower() str2 = input().lower() if (str1 < str2): print(-1) elif (str1 > str2): print(1) else: print(0) ```
3.977
313
A
Ilya and Bank Account
PROGRAMMING
900
[ "implementation", "number theory" ]
null
null
Ilya is a very clever lion, he lives in an unusual city ZooVille. In this city all the animals have their rights and obligations. Moreover, they even have their own bank accounts. The state of a bank account is an integer. The state of a bank account can be a negative number. This means that the owner of the account owes the bank money. Ilya the Lion has recently had a birthday, so he got a lot of gifts. One of them (the gift of the main ZooVille bank) is the opportunity to delete the last digit or the digit before last from the state of his bank account no more than once. For example, if the state of Ilya's bank account is -123, then Ilya can delete the last digit and get his account balance equal to -12, also he can remove its digit before last and get the account balance equal to -13. Of course, Ilya is permitted not to use the opportunity to delete a digit from the balance. Ilya is not very good at math, and that's why he asks you to help him maximize his bank account. Find the maximum state of the bank account that can be obtained using the bank's gift.
The single line contains integer *n* (10<=≤<=|*n*|<=≤<=109) — the state of Ilya's bank account.
In a single line print an integer — the maximum state of the bank account that Ilya can get.
[ "2230\n", "-10\n", "-100003\n" ]
[ "2230\n", "0\n", "-10000\n" ]
In the first test sample Ilya doesn't profit from using the present. In the second test sample you can delete digit 1 and get the state of the account equal to 0.
500
[ { "input": "2230", "output": "2230" }, { "input": "-10", "output": "0" }, { "input": "-100003", "output": "-10000" }, { "input": "544883178", "output": "544883178" }, { "input": "-847251738", "output": "-84725173" }, { "input": "423654797", "output": "423654797" }, { "input": "-623563697", "output": "-62356367" }, { "input": "645894116", "output": "645894116" }, { "input": "-384381709", "output": "-38438170" }, { "input": "437587210", "output": "437587210" }, { "input": "-297534606", "output": "-29753460" }, { "input": "891773002", "output": "891773002" }, { "input": "-56712976", "output": "-5671296" }, { "input": "963662765", "output": "963662765" }, { "input": "-272656295", "output": "-27265625" }, { "input": "383441522", "output": "383441522" }, { "input": "-477665112", "output": "-47766511" }, { "input": "791725034", "output": "791725034" }, { "input": "-812168727", "output": "-81216872" }, { "input": "528894922", "output": "528894922" }, { "input": "-479977172", "output": "-47997712" }, { "input": "568044564", "output": "568044564" }, { "input": "-392784794", "output": "-39278474" }, { "input": "925596634", "output": "925596634" }, { "input": "-836078769", "output": "-83607876" }, { "input": "71036059", "output": "71036059" }, { "input": "-337396162", "output": "-33739612" }, { "input": "87129297", "output": "87129297" }, { "input": "-648171877", "output": "-64817187" }, { "input": "20218400", "output": "20218400" }, { "input": "10", "output": "10" }, { "input": "1000000000", "output": "1000000000" }, { "input": "-1000000000", "output": "-100000000" }, { "input": "-102", "output": "-10" }, { "input": "-120", "output": "-10" }, { "input": "-20", "output": "0" }, { "input": "-15", "output": "-1" }, { "input": "-5575533", "output": "-557553" }, { "input": "-50", "output": "0" }, { "input": "-31", "output": "-1" }, { "input": "-55", "output": "-5" }, { "input": "-81", "output": "-1" }, { "input": "-99", "output": "-9" }, { "input": "-23", "output": "-2" }, { "input": "-41", "output": "-1" }, { "input": "-24", "output": "-2" }, { "input": "46", "output": "46" } ]
1,690,704,898
2,147,483,647
Python 3
OK
TESTS
47
92
0
def main(n): if n >= 0: return n a = ((-n) // 100) * 10 + (-n - ((-n) // 10) * 10) b = (-n) // 10 return max(-a, -b) if __name__ == "__main__": n = int(input()) print(main(n))
Title: Ilya and Bank Account Time Limit: None seconds Memory Limit: None megabytes Problem Description: Ilya is a very clever lion, he lives in an unusual city ZooVille. In this city all the animals have their rights and obligations. Moreover, they even have their own bank accounts. The state of a bank account is an integer. The state of a bank account can be a negative number. This means that the owner of the account owes the bank money. Ilya the Lion has recently had a birthday, so he got a lot of gifts. One of them (the gift of the main ZooVille bank) is the opportunity to delete the last digit or the digit before last from the state of his bank account no more than once. For example, if the state of Ilya's bank account is -123, then Ilya can delete the last digit and get his account balance equal to -12, also he can remove its digit before last and get the account balance equal to -13. Of course, Ilya is permitted not to use the opportunity to delete a digit from the balance. Ilya is not very good at math, and that's why he asks you to help him maximize his bank account. Find the maximum state of the bank account that can be obtained using the bank's gift. Input Specification: The single line contains integer *n* (10<=≤<=|*n*|<=≤<=109) — the state of Ilya's bank account. Output Specification: In a single line print an integer — the maximum state of the bank account that Ilya can get. Demo Input: ['2230\n', '-10\n', '-100003\n'] Demo Output: ['2230\n', '0\n', '-10000\n'] Note: In the first test sample Ilya doesn't profit from using the present. In the second test sample you can delete digit 1 and get the state of the account equal to 0.
```python def main(n): if n >= 0: return n a = ((-n) // 100) * 10 + (-n - ((-n) // 10) * 10) b = (-n) // 10 return max(-a, -b) if __name__ == "__main__": n = int(input()) print(main(n)) ```
3
334
A
Candy Bags
PROGRAMMING
1,000
[ "implementation" ]
null
null
Gerald has *n* younger brothers and their number happens to be even. One day he bought *n*2 candy bags. One bag has one candy, one bag has two candies, one bag has three candies and so on. In fact, for each integer *k* from 1 to *n*2 he has exactly one bag with *k* candies. Help him give *n* bags of candies to each brother so that all brothers got the same number of candies.
The single line contains a single integer *n* (*n* is even, 2<=≤<=*n*<=≤<=100) — the number of Gerald's brothers.
Let's assume that Gerald indexes his brothers with numbers from 1 to *n*. You need to print *n* lines, on the *i*-th line print *n* integers — the numbers of candies in the bags for the *i*-th brother. Naturally, all these numbers should be distinct and be within limits from 1 to *n*2. You can print the numbers in the lines in any order. It is guaranteed that the solution exists at the given limits.
[ "2\n" ]
[ "1 4\n2 3\n" ]
The sample shows Gerald's actions if he has two brothers. In this case, his bags contain 1, 2, 3 and 4 candies. He can give the bags with 1 and 4 candies to one brother and the bags with 2 and 3 to the other brother.
500
[ { "input": "2", "output": "1 4\n2 3" }, { "input": "4", "output": "1 16 2 15\n3 14 4 13\n5 12 6 11\n7 10 8 9" }, { "input": "6", "output": "1 36 2 35 3 34\n4 33 5 32 6 31\n7 30 8 29 9 28\n10 27 11 26 12 25\n13 24 14 23 15 22\n16 21 17 20 18 19" }, { "input": "8", "output": "1 64 2 63 3 62 4 61\n5 60 6 59 7 58 8 57\n9 56 10 55 11 54 12 53\n13 52 14 51 15 50 16 49\n17 48 18 47 19 46 20 45\n21 44 22 43 23 42 24 41\n25 40 26 39 27 38 28 37\n29 36 30 35 31 34 32 33" }, { "input": "10", "output": "1 100 2 99 3 98 4 97 5 96\n6 95 7 94 8 93 9 92 10 91\n11 90 12 89 13 88 14 87 15 86\n16 85 17 84 18 83 19 82 20 81\n21 80 22 79 23 78 24 77 25 76\n26 75 27 74 28 73 29 72 30 71\n31 70 32 69 33 68 34 67 35 66\n36 65 37 64 38 63 39 62 40 61\n41 60 42 59 43 58 44 57 45 56\n46 55 47 54 48 53 49 52 50 51" }, { "input": "100", "output": "1 10000 2 9999 3 9998 4 9997 5 9996 6 9995 7 9994 8 9993 9 9992 10 9991 11 9990 12 9989 13 9988 14 9987 15 9986 16 9985 17 9984 18 9983 19 9982 20 9981 21 9980 22 9979 23 9978 24 9977 25 9976 26 9975 27 9974 28 9973 29 9972 30 9971 31 9970 32 9969 33 9968 34 9967 35 9966 36 9965 37 9964 38 9963 39 9962 40 9961 41 9960 42 9959 43 9958 44 9957 45 9956 46 9955 47 9954 48 9953 49 9952 50 9951\n51 9950 52 9949 53 9948 54 9947 55 9946 56 9945 57 9944 58 9943 59 9942 60 9941 61 9940 62 9939 63 9938 64 9937 65 993..." }, { "input": "62", "output": "1 3844 2 3843 3 3842 4 3841 5 3840 6 3839 7 3838 8 3837 9 3836 10 3835 11 3834 12 3833 13 3832 14 3831 15 3830 16 3829 17 3828 18 3827 19 3826 20 3825 21 3824 22 3823 23 3822 24 3821 25 3820 26 3819 27 3818 28 3817 29 3816 30 3815 31 3814\n32 3813 33 3812 34 3811 35 3810 36 3809 37 3808 38 3807 39 3806 40 3805 41 3804 42 3803 43 3802 44 3801 45 3800 46 3799 47 3798 48 3797 49 3796 50 3795 51 3794 52 3793 53 3792 54 3791 55 3790 56 3789 57 3788 58 3787 59 3786 60 3785 61 3784 62 3783\n63 3782 64 3781 65 378..." }, { "input": "66", "output": "1 4356 2 4355 3 4354 4 4353 5 4352 6 4351 7 4350 8 4349 9 4348 10 4347 11 4346 12 4345 13 4344 14 4343 15 4342 16 4341 17 4340 18 4339 19 4338 20 4337 21 4336 22 4335 23 4334 24 4333 25 4332 26 4331 27 4330 28 4329 29 4328 30 4327 31 4326 32 4325 33 4324\n34 4323 35 4322 36 4321 37 4320 38 4319 39 4318 40 4317 41 4316 42 4315 43 4314 44 4313 45 4312 46 4311 47 4310 48 4309 49 4308 50 4307 51 4306 52 4305 53 4304 54 4303 55 4302 56 4301 57 4300 58 4299 59 4298 60 4297 61 4296 62 4295 63 4294 64 4293 65 4292..." }, { "input": "18", "output": "1 324 2 323 3 322 4 321 5 320 6 319 7 318 8 317 9 316\n10 315 11 314 12 313 13 312 14 311 15 310 16 309 17 308 18 307\n19 306 20 305 21 304 22 303 23 302 24 301 25 300 26 299 27 298\n28 297 29 296 30 295 31 294 32 293 33 292 34 291 35 290 36 289\n37 288 38 287 39 286 40 285 41 284 42 283 43 282 44 281 45 280\n46 279 47 278 48 277 49 276 50 275 51 274 52 273 53 272 54 271\n55 270 56 269 57 268 58 267 59 266 60 265 61 264 62 263 63 262\n64 261 65 260 66 259 67 258 68 257 69 256 70 255 71 254 72 253\n73 252 7..." }, { "input": "68", "output": "1 4624 2 4623 3 4622 4 4621 5 4620 6 4619 7 4618 8 4617 9 4616 10 4615 11 4614 12 4613 13 4612 14 4611 15 4610 16 4609 17 4608 18 4607 19 4606 20 4605 21 4604 22 4603 23 4602 24 4601 25 4600 26 4599 27 4598 28 4597 29 4596 30 4595 31 4594 32 4593 33 4592 34 4591\n35 4590 36 4589 37 4588 38 4587 39 4586 40 4585 41 4584 42 4583 43 4582 44 4581 45 4580 46 4579 47 4578 48 4577 49 4576 50 4575 51 4574 52 4573 53 4572 54 4571 55 4570 56 4569 57 4568 58 4567 59 4566 60 4565 61 4564 62 4563 63 4562 64 4561 65 4560..." }, { "input": "86", "output": "1 7396 2 7395 3 7394 4 7393 5 7392 6 7391 7 7390 8 7389 9 7388 10 7387 11 7386 12 7385 13 7384 14 7383 15 7382 16 7381 17 7380 18 7379 19 7378 20 7377 21 7376 22 7375 23 7374 24 7373 25 7372 26 7371 27 7370 28 7369 29 7368 30 7367 31 7366 32 7365 33 7364 34 7363 35 7362 36 7361 37 7360 38 7359 39 7358 40 7357 41 7356 42 7355 43 7354\n44 7353 45 7352 46 7351 47 7350 48 7349 49 7348 50 7347 51 7346 52 7345 53 7344 54 7343 55 7342 56 7341 57 7340 58 7339 59 7338 60 7337 61 7336 62 7335 63 7334 64 7333 65 7332..." }, { "input": "96", "output": "1 9216 2 9215 3 9214 4 9213 5 9212 6 9211 7 9210 8 9209 9 9208 10 9207 11 9206 12 9205 13 9204 14 9203 15 9202 16 9201 17 9200 18 9199 19 9198 20 9197 21 9196 22 9195 23 9194 24 9193 25 9192 26 9191 27 9190 28 9189 29 9188 30 9187 31 9186 32 9185 33 9184 34 9183 35 9182 36 9181 37 9180 38 9179 39 9178 40 9177 41 9176 42 9175 43 9174 44 9173 45 9172 46 9171 47 9170 48 9169\n49 9168 50 9167 51 9166 52 9165 53 9164 54 9163 55 9162 56 9161 57 9160 58 9159 59 9158 60 9157 61 9156 62 9155 63 9154 64 9153 65 9152..." }, { "input": "12", "output": "1 144 2 143 3 142 4 141 5 140 6 139\n7 138 8 137 9 136 10 135 11 134 12 133\n13 132 14 131 15 130 16 129 17 128 18 127\n19 126 20 125 21 124 22 123 23 122 24 121\n25 120 26 119 27 118 28 117 29 116 30 115\n31 114 32 113 33 112 34 111 35 110 36 109\n37 108 38 107 39 106 40 105 41 104 42 103\n43 102 44 101 45 100 46 99 47 98 48 97\n49 96 50 95 51 94 52 93 53 92 54 91\n55 90 56 89 57 88 58 87 59 86 60 85\n61 84 62 83 63 82 64 81 65 80 66 79\n67 78 68 77 69 76 70 75 71 74 72 73" }, { "input": "88", "output": "1 7744 2 7743 3 7742 4 7741 5 7740 6 7739 7 7738 8 7737 9 7736 10 7735 11 7734 12 7733 13 7732 14 7731 15 7730 16 7729 17 7728 18 7727 19 7726 20 7725 21 7724 22 7723 23 7722 24 7721 25 7720 26 7719 27 7718 28 7717 29 7716 30 7715 31 7714 32 7713 33 7712 34 7711 35 7710 36 7709 37 7708 38 7707 39 7706 40 7705 41 7704 42 7703 43 7702 44 7701\n45 7700 46 7699 47 7698 48 7697 49 7696 50 7695 51 7694 52 7693 53 7692 54 7691 55 7690 56 7689 57 7688 58 7687 59 7686 60 7685 61 7684 62 7683 63 7682 64 7681 65 7680..." }, { "input": "28", "output": "1 784 2 783 3 782 4 781 5 780 6 779 7 778 8 777 9 776 10 775 11 774 12 773 13 772 14 771\n15 770 16 769 17 768 18 767 19 766 20 765 21 764 22 763 23 762 24 761 25 760 26 759 27 758 28 757\n29 756 30 755 31 754 32 753 33 752 34 751 35 750 36 749 37 748 38 747 39 746 40 745 41 744 42 743\n43 742 44 741 45 740 46 739 47 738 48 737 49 736 50 735 51 734 52 733 53 732 54 731 55 730 56 729\n57 728 58 727 59 726 60 725 61 724 62 723 63 722 64 721 65 720 66 719 67 718 68 717 69 716 70 715\n71 714 72 713 73 712 74 7..." }, { "input": "80", "output": "1 6400 2 6399 3 6398 4 6397 5 6396 6 6395 7 6394 8 6393 9 6392 10 6391 11 6390 12 6389 13 6388 14 6387 15 6386 16 6385 17 6384 18 6383 19 6382 20 6381 21 6380 22 6379 23 6378 24 6377 25 6376 26 6375 27 6374 28 6373 29 6372 30 6371 31 6370 32 6369 33 6368 34 6367 35 6366 36 6365 37 6364 38 6363 39 6362 40 6361\n41 6360 42 6359 43 6358 44 6357 45 6356 46 6355 47 6354 48 6353 49 6352 50 6351 51 6350 52 6349 53 6348 54 6347 55 6346 56 6345 57 6344 58 6343 59 6342 60 6341 61 6340 62 6339 63 6338 64 6337 65 6336..." }, { "input": "48", "output": "1 2304 2 2303 3 2302 4 2301 5 2300 6 2299 7 2298 8 2297 9 2296 10 2295 11 2294 12 2293 13 2292 14 2291 15 2290 16 2289 17 2288 18 2287 19 2286 20 2285 21 2284 22 2283 23 2282 24 2281\n25 2280 26 2279 27 2278 28 2277 29 2276 30 2275 31 2274 32 2273 33 2272 34 2271 35 2270 36 2269 37 2268 38 2267 39 2266 40 2265 41 2264 42 2263 43 2262 44 2261 45 2260 46 2259 47 2258 48 2257\n49 2256 50 2255 51 2254 52 2253 53 2252 54 2251 55 2250 56 2249 57 2248 58 2247 59 2246 60 2245 61 2244 62 2243 63 2242 64 2241 65 224..." }, { "input": "54", "output": "1 2916 2 2915 3 2914 4 2913 5 2912 6 2911 7 2910 8 2909 9 2908 10 2907 11 2906 12 2905 13 2904 14 2903 15 2902 16 2901 17 2900 18 2899 19 2898 20 2897 21 2896 22 2895 23 2894 24 2893 25 2892 26 2891 27 2890\n28 2889 29 2888 30 2887 31 2886 32 2885 33 2884 34 2883 35 2882 36 2881 37 2880 38 2879 39 2878 40 2877 41 2876 42 2875 43 2874 44 2873 45 2872 46 2871 47 2870 48 2869 49 2868 50 2867 51 2866 52 2865 53 2864 54 2863\n55 2862 56 2861 57 2860 58 2859 59 2858 60 2857 61 2856 62 2855 63 2854 64 2853 65 285..." }, { "input": "58", "output": "1 3364 2 3363 3 3362 4 3361 5 3360 6 3359 7 3358 8 3357 9 3356 10 3355 11 3354 12 3353 13 3352 14 3351 15 3350 16 3349 17 3348 18 3347 19 3346 20 3345 21 3344 22 3343 23 3342 24 3341 25 3340 26 3339 27 3338 28 3337 29 3336\n30 3335 31 3334 32 3333 33 3332 34 3331 35 3330 36 3329 37 3328 38 3327 39 3326 40 3325 41 3324 42 3323 43 3322 44 3321 45 3320 46 3319 47 3318 48 3317 49 3316 50 3315 51 3314 52 3313 53 3312 54 3311 55 3310 56 3309 57 3308 58 3307\n59 3306 60 3305 61 3304 62 3303 63 3302 64 3301 65 330..." }, { "input": "64", "output": "1 4096 2 4095 3 4094 4 4093 5 4092 6 4091 7 4090 8 4089 9 4088 10 4087 11 4086 12 4085 13 4084 14 4083 15 4082 16 4081 17 4080 18 4079 19 4078 20 4077 21 4076 22 4075 23 4074 24 4073 25 4072 26 4071 27 4070 28 4069 29 4068 30 4067 31 4066 32 4065\n33 4064 34 4063 35 4062 36 4061 37 4060 38 4059 39 4058 40 4057 41 4056 42 4055 43 4054 44 4053 45 4052 46 4051 47 4050 48 4049 49 4048 50 4047 51 4046 52 4045 53 4044 54 4043 55 4042 56 4041 57 4040 58 4039 59 4038 60 4037 61 4036 62 4035 63 4034 64 4033\n65 403..." }, { "input": "44", "output": "1 1936 2 1935 3 1934 4 1933 5 1932 6 1931 7 1930 8 1929 9 1928 10 1927 11 1926 12 1925 13 1924 14 1923 15 1922 16 1921 17 1920 18 1919 19 1918 20 1917 21 1916 22 1915\n23 1914 24 1913 25 1912 26 1911 27 1910 28 1909 29 1908 30 1907 31 1906 32 1905 33 1904 34 1903 35 1902 36 1901 37 1900 38 1899 39 1898 40 1897 41 1896 42 1895 43 1894 44 1893\n45 1892 46 1891 47 1890 48 1889 49 1888 50 1887 51 1886 52 1885 53 1884 54 1883 55 1882 56 1881 57 1880 58 1879 59 1878 60 1877 61 1876 62 1875 63 1874 64 1873 65 187..." } ]
1,682,371,859
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
1
92
0
a = int(input()) a = a ** 2 for i in range(1, a-1): print(i, (a-i)+1)
Title: Candy Bags Time Limit: None seconds Memory Limit: None megabytes Problem Description: Gerald has *n* younger brothers and their number happens to be even. One day he bought *n*2 candy bags. One bag has one candy, one bag has two candies, one bag has three candies and so on. In fact, for each integer *k* from 1 to *n*2 he has exactly one bag with *k* candies. Help him give *n* bags of candies to each brother so that all brothers got the same number of candies. Input Specification: The single line contains a single integer *n* (*n* is even, 2<=≤<=*n*<=≤<=100) — the number of Gerald's brothers. Output Specification: Let's assume that Gerald indexes his brothers with numbers from 1 to *n*. You need to print *n* lines, on the *i*-th line print *n* integers — the numbers of candies in the bags for the *i*-th brother. Naturally, all these numbers should be distinct and be within limits from 1 to *n*2. You can print the numbers in the lines in any order. It is guaranteed that the solution exists at the given limits. Demo Input: ['2\n'] Demo Output: ['1 4\n2 3\n'] Note: The sample shows Gerald's actions if he has two brothers. In this case, his bags contain 1, 2, 3 and 4 candies. He can give the bags with 1 and 4 candies to one brother and the bags with 2 and 3 to the other brother.
```python a = int(input()) a = a ** 2 for i in range(1, a-1): print(i, (a-i)+1) ```
0
484
A
Bits
PROGRAMMING
1,700
[ "bitmasks", "constructive algorithms" ]
null
null
Let's denote as the number of bits set ('1' bits) in the binary representation of the non-negative integer *x*. You are given multiple queries consisting of pairs of integers *l* and *r*. For each query, find the *x*, such that *l*<=≤<=*x*<=≤<=*r*, and is maximum possible. If there are multiple such numbers find the smallest of them.
The first line contains integer *n* — the number of queries (1<=≤<=*n*<=≤<=10000). Each of the following *n* lines contain two integers *l**i*,<=*r**i* — the arguments for the corresponding query (0<=≤<=*l**i*<=≤<=*r**i*<=≤<=1018).
For each query print the answer in a separate line.
[ "3\n1 2\n2 4\n1 10\n" ]
[ "1\n3\n7\n" ]
The binary representations of numbers from 1 to 10 are listed below: 1<sub class="lower-index">10</sub> = 1<sub class="lower-index">2</sub> 2<sub class="lower-index">10</sub> = 10<sub class="lower-index">2</sub> 3<sub class="lower-index">10</sub> = 11<sub class="lower-index">2</sub> 4<sub class="lower-index">10</sub> = 100<sub class="lower-index">2</sub> 5<sub class="lower-index">10</sub> = 101<sub class="lower-index">2</sub> 6<sub class="lower-index">10</sub> = 110<sub class="lower-index">2</sub> 7<sub class="lower-index">10</sub> = 111<sub class="lower-index">2</sub> 8<sub class="lower-index">10</sub> = 1000<sub class="lower-index">2</sub> 9<sub class="lower-index">10</sub> = 1001<sub class="lower-index">2</sub> 10<sub class="lower-index">10</sub> = 1010<sub class="lower-index">2</sub>
500
[ { "input": "3\n1 2\n2 4\n1 10", "output": "1\n3\n7" }, { "input": "55\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n2 2\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n3 3\n3 4\n3 5\n3 6\n3 7\n3 8\n3 9\n3 10\n4 4\n4 5\n4 6\n4 7\n4 8\n4 9\n4 10\n5 5\n5 6\n5 7\n5 8\n5 9\n5 10\n6 6\n6 7\n6 8\n6 9\n6 10\n7 7\n7 8\n7 9\n7 10\n8 8\n8 9\n8 10\n9 9\n9 10\n10 10", "output": "1\n1\n3\n3\n3\n3\n7\n7\n7\n7\n2\n3\n3\n3\n3\n7\n7\n7\n7\n3\n3\n3\n3\n7\n7\n7\n7\n4\n5\n5\n7\n7\n7\n7\n5\n5\n7\n7\n7\n7\n6\n7\n7\n7\n7\n7\n7\n7\n7\n8\n9\n9\n9\n9\n10" }, { "input": "18\n1 10\n1 100\n1 1000\n1 10000\n1 100000\n1 1000000\n1 10000000\n1 100000000\n1 1000000000\n1 10000000000\n1 100000000000\n1 1000000000000\n1 10000000000000\n1 100000000000000\n1 1000000000000000\n1 10000000000000000\n1 100000000000000000\n1 1000000000000000000", "output": "7\n63\n511\n8191\n65535\n524287\n8388607\n67108863\n536870911\n8589934591\n68719476735\n549755813887\n8796093022207\n70368744177663\n562949953421311\n9007199254740991\n72057594037927935\n576460752303423487" }, { "input": "3\n0 0\n1 3\n2 4", "output": "0\n3\n3" }, { "input": "17\n0 0\n0 8\n1 8\n36 39\n3 4\n3 7\n2 17\n8 12\n9 12\n10 12\n10 15\n6 14\n8 15\n9 15\n15 15\n100000000000000000 1000000000000000000\n99999999999999999 1000000000000000000", "output": "0\n7\n7\n39\n3\n7\n15\n11\n11\n11\n15\n7\n15\n15\n15\n576460752303423487\n576460752303423487" } ]
1,689,801,396
2,147,483,647
PyPy 3-64
OK
TESTS
27
217
7,884,800
t = int(input()) for _ in range(t): l, r = map(int, input().split()) while (l | (l + 1)) <= r: l |= l + 1 print(l)
Title: Bits Time Limit: None seconds Memory Limit: None megabytes Problem Description: Let's denote as the number of bits set ('1' bits) in the binary representation of the non-negative integer *x*. You are given multiple queries consisting of pairs of integers *l* and *r*. For each query, find the *x*, such that *l*<=≤<=*x*<=≤<=*r*, and is maximum possible. If there are multiple such numbers find the smallest of them. Input Specification: The first line contains integer *n* — the number of queries (1<=≤<=*n*<=≤<=10000). Each of the following *n* lines contain two integers *l**i*,<=*r**i* — the arguments for the corresponding query (0<=≤<=*l**i*<=≤<=*r**i*<=≤<=1018). Output Specification: For each query print the answer in a separate line. Demo Input: ['3\n1 2\n2 4\n1 10\n'] Demo Output: ['1\n3\n7\n'] Note: The binary representations of numbers from 1 to 10 are listed below: 1<sub class="lower-index">10</sub> = 1<sub class="lower-index">2</sub> 2<sub class="lower-index">10</sub> = 10<sub class="lower-index">2</sub> 3<sub class="lower-index">10</sub> = 11<sub class="lower-index">2</sub> 4<sub class="lower-index">10</sub> = 100<sub class="lower-index">2</sub> 5<sub class="lower-index">10</sub> = 101<sub class="lower-index">2</sub> 6<sub class="lower-index">10</sub> = 110<sub class="lower-index">2</sub> 7<sub class="lower-index">10</sub> = 111<sub class="lower-index">2</sub> 8<sub class="lower-index">10</sub> = 1000<sub class="lower-index">2</sub> 9<sub class="lower-index">10</sub> = 1001<sub class="lower-index">2</sub> 10<sub class="lower-index">10</sub> = 1010<sub class="lower-index">2</sub>
```python t = int(input()) for _ in range(t): l, r = map(int, input().split()) while (l | (l + 1)) <= r: l |= l + 1 print(l) ```
3
291
B
Command Line Arguments
PROGRAMMING
1,300
[ "*special", "implementation", "strings" ]
null
null
The problem describes the properties of a command line. The description somehow resembles the one you usually see in real operating systems. However, there are differences in the behavior. Please make sure you've read the statement attentively and use it as a formal document. In the Pindows operating system a strings are the lexemes of the command line — the first of them is understood as the name of the program to run and the following lexemes are its arguments. For example, as we execute the command " run.exe one, two . ", we give four lexemes to the Pindows command line: "run.exe", "one,", "two", ".". More formally, if we run a command that can be represented as string *s* (that has no quotes), then the command line lexemes are maximal by inclusion substrings of string *s* that contain no spaces. To send a string with spaces or an empty string as a command line lexeme, we can use double quotes. The block of characters that should be considered as one lexeme goes inside the quotes. Embedded quotes are prohibited — that is, for each occurrence of character """ we should be able to say clearly that the quotes are opening or closing. For example, as we run the command ""run.exe o" "" " ne, " two . " " ", we give six lexemes to the Pindows command line: "run.exe o", "" (an empty string), " ne, ", "two", ".", " " (a single space). It is guaranteed that each lexeme of the command line is either surrounded by spaces on both sides or touches the corresponding command border. One of its consequences is: the opening brackets are either the first character of the string or there is a space to the left of them. You have a string that consists of uppercase and lowercase English letters, digits, characters ".,?!"" and spaces. It is guaranteed that this string is a correct OS Pindows command line string. Print all lexemes of this command line string. Consider the character """ to be used only in order to denote a single block of characters into one command line lexeme. In particular, the consequence is that the given string has got an even number of such characters.
The single line contains a non-empty string *s*. String *s* consists of at most 105 characters. Each character is either an uppercase or a lowercase English letter, or a digit, or one of the ".,?!"" signs, or a space. It is guaranteed that the given string is some correct command line string of the OS Pindows. It is guaranteed that the given command line string contains at least one lexeme.
In the first line print the first lexeme, in the second line print the second one and so on. To make the output clearer, print the "&lt;" (less) character to the left of your lexemes and the "&gt;" (more) character to the right. Print the lexemes in the order in which they occur in the command. Please, follow the given output format strictly. For more clarifications on the output format see the test samples.
[ "\"RUn.exe O\" \"\" \" 2ne, \" two! . \" \"\n", "firstarg second \"\" \n" ]
[ "&lt;RUn.exe O&gt;\n&lt;&gt;\n&lt; 2ne, &gt;\n&lt;two!&gt;\n&lt;.&gt;\n&lt; &gt;\n", "&lt;firstarg&gt;\n&lt;second&gt;\n&lt;&gt;\n" ]
none
1,000
[ { "input": "\"RUn.exe O\" \"\" \" 2ne, \" two! . \" \"", "output": "<RUn.exe O>\n<>\n< 2ne, >\n<two!>\n<.>\n< >" }, { "input": " firstarg second \"\" ", "output": "<firstarg>\n<second>\n<>" }, { "input": " \" \" ", "output": "< >" }, { "input": " a \" \" a \"\" a ", "output": "<a>\n< >\n<a>\n<>\n<a>" }, { "input": "A", "output": "<A>" }, { "input": "\"\"", "output": "<>" }, { "input": "\" \"", "output": "< >" }, { "input": "\" \" \"wu\" \"\" \" \" \"\" \"\" \"\" ", "output": "< >\n<wu>\n<>\n< >\n<>\n<>\n<>" }, { "input": "\"7\" \"W \" \"\" \"\" \"a \" \"\" \"\" \"\" y ", "output": "<7>\n<W >\n<>\n<>\n<a >\n<>\n<>\n<>\n<y>" }, { "input": "\"\" \"\" \". \" \"A\" \"\" \"\" \"\" k \"\" ", "output": "<>\n<>\n<. >\n<A>\n<>\n<>\n<>\n<k>\n<>" }, { "input": " \"\" ZX \"\" \"\" \"b\" \"\" \" \" C \"\" \"\" \"\"", "output": "<>\n<ZX>\n<>\n<>\n<b>\n<>\n< >\n<C>\n<>\n<>\n<>" }, { "input": " \"\" N 3 \"\" \"4\" \"A\" \"k\" \" \" \"\" \"\" ", "output": "<>\n<N>\n<3>\n<>\n<4>\n<A>\n<k>\n< >\n<>\n<>" }, { "input": "B", "output": "<B>" }, { "input": "b ", "output": "<b>" }, { "input": "j ", "output": "<j>" }, { "input": " \"\"", "output": "<>" }, { "input": " Lii", "output": "<Lii>" }, { "input": " m Z \"\" \" p\"", "output": "<m>\n<Z>\n<>\n< p>" } ]
1,664,515,736
2,147,483,647
Python 3
OK
TESTS
30
686
1,638,400
import shlex inputString = input() result = shlex.split(inputString) for res in result: print("<{}>".format(res))
Title: Command Line Arguments Time Limit: None seconds Memory Limit: None megabytes Problem Description: The problem describes the properties of a command line. The description somehow resembles the one you usually see in real operating systems. However, there are differences in the behavior. Please make sure you've read the statement attentively and use it as a formal document. In the Pindows operating system a strings are the lexemes of the command line — the first of them is understood as the name of the program to run and the following lexemes are its arguments. For example, as we execute the command " run.exe one, two . ", we give four lexemes to the Pindows command line: "run.exe", "one,", "two", ".". More formally, if we run a command that can be represented as string *s* (that has no quotes), then the command line lexemes are maximal by inclusion substrings of string *s* that contain no spaces. To send a string with spaces or an empty string as a command line lexeme, we can use double quotes. The block of characters that should be considered as one lexeme goes inside the quotes. Embedded quotes are prohibited — that is, for each occurrence of character """ we should be able to say clearly that the quotes are opening or closing. For example, as we run the command ""run.exe o" "" " ne, " two . " " ", we give six lexemes to the Pindows command line: "run.exe o", "" (an empty string), " ne, ", "two", ".", " " (a single space). It is guaranteed that each lexeme of the command line is either surrounded by spaces on both sides or touches the corresponding command border. One of its consequences is: the opening brackets are either the first character of the string or there is a space to the left of them. You have a string that consists of uppercase and lowercase English letters, digits, characters ".,?!"" and spaces. It is guaranteed that this string is a correct OS Pindows command line string. Print all lexemes of this command line string. Consider the character """ to be used only in order to denote a single block of characters into one command line lexeme. In particular, the consequence is that the given string has got an even number of such characters. Input Specification: The single line contains a non-empty string *s*. String *s* consists of at most 105 characters. Each character is either an uppercase or a lowercase English letter, or a digit, or one of the ".,?!"" signs, or a space. It is guaranteed that the given string is some correct command line string of the OS Pindows. It is guaranteed that the given command line string contains at least one lexeme. Output Specification: In the first line print the first lexeme, in the second line print the second one and so on. To make the output clearer, print the "&lt;" (less) character to the left of your lexemes and the "&gt;" (more) character to the right. Print the lexemes in the order in which they occur in the command. Please, follow the given output format strictly. For more clarifications on the output format see the test samples. Demo Input: ['"RUn.exe O" "" " 2ne, " two! . " "\n', 'firstarg second "" \n'] Demo Output: ['&lt;RUn.exe O&gt;\n&lt;&gt;\n&lt; 2ne, &gt;\n&lt;two!&gt;\n&lt;.&gt;\n&lt; &gt;\n', '&lt;firstarg&gt;\n&lt;second&gt;\n&lt;&gt;\n'] Note: none
```python import shlex inputString = input() result = shlex.split(inputString) for res in result: print("<{}>".format(res)) ```
3
632
C
The Smallest String Concatenation
PROGRAMMING
1,700
[ "sortings", "strings" ]
null
null
You're given a list of *n* strings *a*1,<=*a*2,<=...,<=*a**n*. You'd like to concatenate them together in some order such that the resulting string would be lexicographically smallest. Given the list of strings, output the lexicographically smallest concatenation.
The first line contains integer *n* — the number of strings (1<=≤<=*n*<=≤<=5·104). Each of the next *n* lines contains one string *a**i* (1<=≤<=|*a**i*|<=≤<=50) consisting of only lowercase English letters. The sum of string lengths will not exceed 5·104.
Print the only string *a* — the lexicographically smallest string concatenation.
[ "4\nabba\nabacaba\nbcd\ner\n", "5\nx\nxx\nxxa\nxxaa\nxxaaa\n", "3\nc\ncb\ncba\n" ]
[ "abacabaabbabcder\n", "xxaaaxxaaxxaxxx\n", "cbacbc\n" ]
none
0
[ { "input": "4\nabba\nabacaba\nbcd\ner", "output": "abacabaabbabcder" }, { "input": "5\nx\nxx\nxxa\nxxaa\nxxaaa", "output": "xxaaaxxaaxxaxxx" }, { "input": "3\nc\ncb\ncba", "output": "cbacbc" }, { "input": "10\naba\nabaaca\naba\nacaaaabbac\nabaacac\nb\ncabbcccaab\nbaacbb\nbcab\ncc", "output": "abaabaabaacaabaacacacaaaabbacbaacbbbbcabcabbcccaabcc" }, { "input": "13\nclgknjjojyuvdtv\nclgknjjojyuvdtvzxz\nclgknjjojyuvdtvzxzxradqhm\ngvzpnckalbaubfviyhijosiixvxaydxagvymq\nclgknjjojyuvdtvjgcwarwvgilcctdiytmvmvfxxkezymt\nbvwzpuut\nclgknjjojyuvdtvjgcwarwvgilcctdiytmvmvfxxkezymth\nclgknjjojyuvdtvjgcwarwvgilcctdiytmvmvfxxkezymtlkdl\nrbwvaayhhunlvmwexvkmqbquypsnjbdkkeytthekttywypud\nqlvkfkshkxyrfefigtngifxsuhpjgkb\nlhxtkfjrrwcvzuamizotupjqckaq\nenngvhxvpaoiyhctddyscasyqtilvbvgfphayykjeoylcvmjz\nxkazwk", "output": "bvwzpuutclgknjjojyuvdtvclgknjjojyuvdtvjgcwarwvgilcctdiytmvmvfxxkezymtclgknjjojyuvdtvjgcwarwvgilcctdiytmvmvfxxkezymthclgknjjojyuvdtvjgcwarwvgilcctdiytmvmvfxxkezymtlkdlclgknjjojyuvdtvzxzclgknjjojyuvdtvzxzxradqhmenngvhxvpaoiyhctddyscasyqtilvbvgfphayykjeoylcvmjzgvzpnckalbaubfviyhijosiixvxaydxagvymqlhxtkfjrrwcvzuamizotupjqckaqqlvkfkshkxyrfefigtngifxsuhpjgkbrbwvaayhhunlvmwexvkmqbquypsnjbdkkeytthekttywypudxkazwk" } ]
1,630,511,238
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
46
6,758,400
t = int(input()) arr = [] while(t>0): ss = input() arr.append(ss) t = t-1 print(''.join(sorted(arr))) #hello
Title: The Smallest String Concatenation Time Limit: None seconds Memory Limit: None megabytes Problem Description: You're given a list of *n* strings *a*1,<=*a*2,<=...,<=*a**n*. You'd like to concatenate them together in some order such that the resulting string would be lexicographically smallest. Given the list of strings, output the lexicographically smallest concatenation. Input Specification: The first line contains integer *n* — the number of strings (1<=≤<=*n*<=≤<=5·104). Each of the next *n* lines contains one string *a**i* (1<=≤<=|*a**i*|<=≤<=50) consisting of only lowercase English letters. The sum of string lengths will not exceed 5·104. Output Specification: Print the only string *a* — the lexicographically smallest string concatenation. Demo Input: ['4\nabba\nabacaba\nbcd\ner\n', '5\nx\nxx\nxxa\nxxaa\nxxaaa\n', '3\nc\ncb\ncba\n'] Demo Output: ['abacabaabbabcder\n', 'xxaaaxxaaxxaxxx\n', 'cbacbc\n'] Note: none
```python t = int(input()) arr = [] while(t>0): ss = input() arr.append(ss) t = t-1 print(''.join(sorted(arr))) #hello ```
0
625
D
Finals in arithmetic
PROGRAMMING
2,400
[ "constructive algorithms", "implementation", "math" ]
null
null
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered in decimal notation and then reverted. If there are any leading zeroes afterwards, they are thrown away. For example, if we flip 123 the result is the integer 321, but flipping 130 we obtain 31, and by flipping 31 we come to 13. Oksana Fillipovna picked some number *a* without leading zeroes, and flipped it to get number *a**r*. Then she summed *a* and *a**r*, and told Vitya the resulting value *n*. His goal is to find any valid *a*. As Oksana Fillipovna picked some small integers as *a* and *a**r*, Vitya managed to find the answer pretty fast and became interested in finding some general algorithm to deal with this problem. Now, he wants you to write the program that for given *n* finds any *a* without leading zeroes, such that *a*<=+<=*a**r*<==<=*n* or determine that such *a* doesn't exist.
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=10100<=000).
If there is no such positive integer *a* without leading zeroes that *a*<=+<=*a**r*<==<=*n* then print 0. Otherwise, print any valid *a*. If there are many possible answers, you are allowed to pick any.
[ "4\n", "11\n", "5\n", "33\n" ]
[ "2\n", "10\n", "0\n", "21\n" ]
In the first sample 4 = 2 + 2, *a* = 2 is the only possibility. In the second sample 11 = 10 + 1, *a* = 10 — the only valid solution. Note, that *a* = 01 is incorrect, because *a* can't have leading zeroes. It's easy to check that there is no suitable *a* in the third sample. In the fourth sample 33 = 30 + 3 = 12 + 21, so there are three possibilities for *a*: *a* = 30, *a* = 12, *a* = 21. Any of these is considered to be correct answer.
2,000
[ { "input": "4", "output": "2" }, { "input": "11", "output": "10" }, { "input": "5", "output": "0" }, { "input": "33", "output": "21" }, { "input": "1", "output": "0" }, { "input": "99", "output": "54" }, { "input": "100", "output": "0" }, { "input": "101", "output": "100" }, { "input": "111", "output": "0" }, { "input": "121", "output": "65" }, { "input": "161", "output": "130" }, { "input": "165", "output": "87" }, { "input": "1430", "output": "0" }, { "input": "32822", "output": "0" }, { "input": "42914", "output": "0" }, { "input": "67075", "output": "0" }, { "input": "794397", "output": "0" }, { "input": "870968", "output": "0" }, { "input": "990089", "output": "0" }, { "input": "686686", "output": "343343" }, { "input": "928818", "output": "468954" }, { "input": "165355", "output": "85697" }, { "input": "365662", "output": "183281" }, { "input": "30092", "output": "15541" }, { "input": "95948", "output": "47974" }, { "input": "189108", "output": "95049" }, { "input": "970068", "output": "485484" }, { "input": "230021", "output": "130990" }, { "input": "999999", "output": "500994" }, { "input": "199998", "output": "99999" }, { "input": "119801", "output": "109900" }, { "input": "100001", "output": "100000" }, { "input": "891297", "output": "0" }, { "input": "110401", "output": "0" }, { "input": "177067", "output": "0" }, { "input": "1000000", "output": "0" }, { "input": "201262002", "output": "0" }, { "input": "813594318", "output": "0" }, { "input": "643303246", "output": "0" }, { "input": "2277107722", "output": "0" }, { "input": "1094093901", "output": "0" }, { "input": "1063002601", "output": "0" }, { "input": "5593333955", "output": "3000033952" }, { "input": "1624637326", "output": "814719908" }, { "input": "8292112917", "output": "4292199993" }, { "input": "9012332098", "output": "4512399944" }, { "input": "1432011233", "output": "732109996" }, { "input": "1898999897", "output": "998999998" }, { "input": "9009890098", "output": "4510089944" }, { "input": "4321001234", "output": "2200001212" }, { "input": "1738464936", "output": "869281968" }, { "input": "4602332064", "output": "2301211032" }, { "input": "1001760001", "output": "1000790000" }, { "input": "1000000001", "output": "1000000000" }, { "input": "6149019415", "output": "0" }, { "input": "7280320916", "output": "0" }, { "input": "1111334001", "output": "0" }, { "input": "6762116775", "output": "0" }, { "input": "10000000000", "output": "0" }, { "input": "3031371285404035821731303", "output": "0" }, { "input": "3390771275149315721770933", "output": "0" }, { "input": "8344403107710167013044438", "output": "0" }, { "input": "398213879352153978312893", "output": "0" }, { "input": "319183517960959715381913", "output": "0" }, { "input": "447341993380073399143744", "output": "0" }, { "input": "2300941052398832501490032", "output": "1200000000009832501490011" }, { "input": "1931812635088771537217148", "output": "970812706008970929999069" }, { "input": "2442173122931392213712431", "output": "1442173122935999999999990" }, { "input": "1098765432101101234567900", "output": "550000000000101234567845" }, { "input": "1123456789876678987654320", "output": "563456789876999999999955" }, { "input": "9009900990099009900990098", "output": "4510001000104999899989944" }, { "input": "9012320990123209901232098", "output": "4512321000126999899999944" }, { "input": "1789878987898898789878986", "output": "899878987898999999999988" }, { "input": "1625573270595486073374436", "output": "812786635305982536687218" }, { "input": "1000000177157517600000001", "output": "1000000077158999900000000" }, { "input": "1000000000000000000000001", "output": "1000000000000000000000000" }, { "input": "4038996154923294516988304", "output": "0" }, { "input": "3454001245690964432004542", "output": "0" }, { "input": "5200592971632471682861014", "output": "0" }, { "input": "7899445300286737036548887", "output": "0" }, { "input": "10000000000000000000000000", "output": "0" } ]
1,454,918,557
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
9
62
819,200
import collections import math def is_prime(x): for i in range(2, math.ceil(math.sqrt(x))): if x % i == 0: return False return True A = [int(x) for x in str(input())] if len(A) >= 2 and A[0] == 1 and A[-1] != 1: A[1] += 10 A = A[1:] A = A[::-1] ans = [0] * 100010 l, r = 0, len(A) if r == 1: print(A[0] // 2 if A[0] % 2 == 0 else 0) exit(0) for i in range(math.ceil(r / 2)): #print(ans[:r], A, i, r - i - 1) if i == r - i - 1: if A[i] % 2 == 0: ans[i] = A[i] // 2 else: print(0) exit(0) if A[i] < 10 and A[r - i - 1] >= 10: A[i] += 10 A[i + 1] -= 1 temp = i + 1 while temp < r - 1 and A[temp] < 0: A[temp] += 10 A[temp + 1] -= 1 if A[i] == A[r - i - 1]: if A[i] >= 10: ans[i] = A[i] - 9 ans[r - i - 1] = 9 else: ans[i], ans[r - i - 1] = 0, A[i] elif A[r - i - 1] - A[i] == 1 and i < r - i - 2: A[r - i - 2] += 10 if A[i] >= 10: ans[i] = A[i] - 9 ans[r - i - 1] = 9 else: ans[i], ans[r - i - 1] = 0, A[i] else: print(0) exit(0) t = [str(x) for x in ans[:r]] print(''.join(t[::-1]))
Title: Finals in arithmetic Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered in decimal notation and then reverted. If there are any leading zeroes afterwards, they are thrown away. For example, if we flip 123 the result is the integer 321, but flipping 130 we obtain 31, and by flipping 31 we come to 13. Oksana Fillipovna picked some number *a* without leading zeroes, and flipped it to get number *a**r*. Then she summed *a* and *a**r*, and told Vitya the resulting value *n*. His goal is to find any valid *a*. As Oksana Fillipovna picked some small integers as *a* and *a**r*, Vitya managed to find the answer pretty fast and became interested in finding some general algorithm to deal with this problem. Now, he wants you to write the program that for given *n* finds any *a* without leading zeroes, such that *a*<=+<=*a**r*<==<=*n* or determine that such *a* doesn't exist. Input Specification: The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=10100<=000). Output Specification: If there is no such positive integer *a* without leading zeroes that *a*<=+<=*a**r*<==<=*n* then print 0. Otherwise, print any valid *a*. If there are many possible answers, you are allowed to pick any. Demo Input: ['4\n', '11\n', '5\n', '33\n'] Demo Output: ['2\n', '10\n', '0\n', '21\n'] Note: In the first sample 4 = 2 + 2, *a* = 2 is the only possibility. In the second sample 11 = 10 + 1, *a* = 10 — the only valid solution. Note, that *a* = 01 is incorrect, because *a* can't have leading zeroes. It's easy to check that there is no suitable *a* in the third sample. In the fourth sample 33 = 30 + 3 = 12 + 21, so there are three possibilities for *a*: *a* = 30, *a* = 12, *a* = 21. Any of these is considered to be correct answer.
```python import collections import math def is_prime(x): for i in range(2, math.ceil(math.sqrt(x))): if x % i == 0: return False return True A = [int(x) for x in str(input())] if len(A) >= 2 and A[0] == 1 and A[-1] != 1: A[1] += 10 A = A[1:] A = A[::-1] ans = [0] * 100010 l, r = 0, len(A) if r == 1: print(A[0] // 2 if A[0] % 2 == 0 else 0) exit(0) for i in range(math.ceil(r / 2)): #print(ans[:r], A, i, r - i - 1) if i == r - i - 1: if A[i] % 2 == 0: ans[i] = A[i] // 2 else: print(0) exit(0) if A[i] < 10 and A[r - i - 1] >= 10: A[i] += 10 A[i + 1] -= 1 temp = i + 1 while temp < r - 1 and A[temp] < 0: A[temp] += 10 A[temp + 1] -= 1 if A[i] == A[r - i - 1]: if A[i] >= 10: ans[i] = A[i] - 9 ans[r - i - 1] = 9 else: ans[i], ans[r - i - 1] = 0, A[i] elif A[r - i - 1] - A[i] == 1 and i < r - i - 2: A[r - i - 2] += 10 if A[i] >= 10: ans[i] = A[i] - 9 ans[r - i - 1] = 9 else: ans[i], ans[r - i - 1] = 0, A[i] else: print(0) exit(0) t = [str(x) for x in ans[:r]] print(''.join(t[::-1])) ```
0
262
B
Roma and Changing Signs
PROGRAMMING
1,200
[ "greedy" ]
null
null
Roma works in a company that sells TVs. Now he has to prepare a report for the last year. Roma has got a list of the company's incomes. The list is a sequence that consists of *n* integers. The total income of the company is the sum of all integers in sequence. Roma decided to perform exactly *k* changes of signs of several numbers in the sequence. He can also change the sign of a number one, two or more times. The operation of changing a number's sign is the operation of multiplying this number by -1. Help Roma perform the changes so as to make the total income of the company (the sum of numbers in the resulting sequence) maximum. Note that Roma should perform exactly *k* changes.
The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=105), showing, how many numbers are in the sequence and how many swaps are to be made. The second line contains a non-decreasing sequence, consisting of *n* integers *a**i* (|*a**i*|<=≤<=104). The numbers in the lines are separated by single spaces. Please note that the given sequence is sorted in non-decreasing order.
In the single line print the answer to the problem — the maximum total income that we can obtain after exactly *k* changes.
[ "3 2\n-1 -1 1\n", "3 1\n-1 -1 1\n" ]
[ "3\n", "1\n" ]
In the first sample we can get sequence [1, 1, 1], thus the total income equals 3. In the second test, the optimal strategy is to get sequence [-1, 1, 1], thus the total income equals 1.
1,000
[ { "input": "3 2\n-1 -1 1", "output": "3" }, { "input": "3 1\n-1 -1 1", "output": "1" }, { "input": "17 27\n257 320 676 1136 2068 2505 2639 4225 4951 5786 7677 7697 7851 8337 8429 8469 9343", "output": "81852" }, { "input": "69 28\n-9822 -9264 -9253 -9221 -9139 -9126 -9096 -8981 -8521 -8313 -8257 -8253 -7591 -7587 -7301 -7161 -7001 -6847 -6441 -6241 -5949 -5896 -5713 -5692 -5644 -5601 -5545 -5525 -5331 -5253 -5041 -5000 -4951 -4855 -4384 -4293 -4251 -4001 -3991 -3762 -3544 -3481 -3261 -2983 -2882 -2857 -2713 -2691 -2681 -2653 -2221 -2043 -2011 -1997 -1601 -1471 -1448 -1363 -1217 -1217 -1129 -961 -926 -801 -376 -327 -305 -174 -91", "output": "102443" }, { "input": "12 28\n-6652 -6621 -6471 -5559 -5326 -4551 -4401 -4326 -3294 -1175 -1069 -43", "output": "49488" }, { "input": "78 13\n-9961 -9922 -9817 -9813 -9521 -9368 -9361 -9207 -9153 -9124 -9008 -8981 -8951 -8911 -8551 -8479 -8245 -8216 -7988 -7841 -7748 -7741 -7734 -7101 -6846 -6804 -6651 -6526 -6519 -6463 -6297 -6148 -6090 -5845 -5209 -5201 -5161 -5061 -4537 -4529 -4433 -4370 -4266 -4189 -4125 -3945 -3843 -3777 -3751 -3476 -3461 -3279 -3205 -3001 -2889 -2761 -2661 -2521 -2481 -2305 -2278 -2269 -2225 -1648 -1524 -1476 -1353 -1097 -867 -785 -741 -711 -692 -440 -401 -225 -65 -41", "output": "-147832" }, { "input": "4 1\n218 3441 4901 7601", "output": "15725" }, { "input": "73 26\n-8497 -8363 -7603 -7388 -6830 -6827 -6685 -6389 -6237 -6099 -6013 -5565 -5465 -4965 -4947 -4201 -3851 -3793 -3421 -3410 -3201 -3169 -3156 -2976 -2701 -2623 -2321 -2169 -1469 -1221 -950 -926 -9 47 236 457 773 1321 1485 1545 1671 1736 2014 2137 2174 2301 2625 3181 3536 3851 4041 4685 4981 4987 5145 5163 5209 5249 6011 6337 6790 7254 7361 7407 7969 7982 8083 8251 8407 8735 9660 9855 9957", "output": "315919" }, { "input": "53 5\n-9821 -9429 -9146 -8973 -8807 -8801 -8321 -7361 -7222 -7161 -6913 -5961 -4877 -4756 -4753 -4661 -3375 -3031 -2950 -2661 -2161 -2041 -1111 -1071 -905 -697 -397 323 772 1617 1752 2736 2737 3201 3465 4029 4121 4463 4561 4637 4814 6119 6610 6641 6961 7217 7523 8045 8610 8915 9004 9265 9576", "output": "92703" }, { "input": "1 1\n0", "output": "0" }, { "input": "1 1\n10000", "output": "-10000" }, { "input": "1 2\n-1", "output": "-1" }, { "input": "2 1\n0 1", "output": "1" }, { "input": "2 2\n-1 0", "output": "1" }, { "input": "5 6\n-3 -2 -1 5 6", "output": "15" }, { "input": "3 3\n-50 -10 30", "output": "70" }, { "input": "4 4\n-100 -90 -80 1", "output": "269" }, { "input": "4 3\n-3 -2 1 2", "output": "6" }, { "input": "6 4\n-6 -3 -2 1 2 3", "output": "15" }, { "input": "5 6\n-10 -9 -8 1 2", "output": "28" }, { "input": "1 2\n1", "output": "1" }, { "input": "2 2\n-1 3", "output": "2" }, { "input": "4 7\n-3 -2 1 6", "output": "10" }, { "input": "4 3\n-7 -6 1 5", "output": "17" }, { "input": "4 4\n-5 -1 1 2", "output": "9" } ]
1,658,488,570
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
44
186
14,028,800
import sys import math input = sys.stdin.readline from collections import defaultdict n, k = map(int, input().split()) lst = list(map(int, input().split())) lst.sort() if lst[0] >= 0: if k%2 == 0: print(sum(lst)) else : print(sum(lst) - 2*lst[0]) else : t = abs(lst[0]) for i in range(n): if lst[i] < 0 and k > 0: k -= 1 t = abs(lst[i]) lst[i] = abs(t) if k > 0: if k%2 == 0: print(sum(lst)) else : print(sum(lst) - 2*t) else : print(sum(lst))
Title: Roma and Changing Signs Time Limit: None seconds Memory Limit: None megabytes Problem Description: Roma works in a company that sells TVs. Now he has to prepare a report for the last year. Roma has got a list of the company's incomes. The list is a sequence that consists of *n* integers. The total income of the company is the sum of all integers in sequence. Roma decided to perform exactly *k* changes of signs of several numbers in the sequence. He can also change the sign of a number one, two or more times. The operation of changing a number's sign is the operation of multiplying this number by -1. Help Roma perform the changes so as to make the total income of the company (the sum of numbers in the resulting sequence) maximum. Note that Roma should perform exactly *k* changes. Input Specification: The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=105), showing, how many numbers are in the sequence and how many swaps are to be made. The second line contains a non-decreasing sequence, consisting of *n* integers *a**i* (|*a**i*|<=≤<=104). The numbers in the lines are separated by single spaces. Please note that the given sequence is sorted in non-decreasing order. Output Specification: In the single line print the answer to the problem — the maximum total income that we can obtain after exactly *k* changes. Demo Input: ['3 2\n-1 -1 1\n', '3 1\n-1 -1 1\n'] Demo Output: ['3\n', '1\n'] Note: In the first sample we can get sequence [1, 1, 1], thus the total income equals 3. In the second test, the optimal strategy is to get sequence [-1, 1, 1], thus the total income equals 1.
```python import sys import math input = sys.stdin.readline from collections import defaultdict n, k = map(int, input().split()) lst = list(map(int, input().split())) lst.sort() if lst[0] >= 0: if k%2 == 0: print(sum(lst)) else : print(sum(lst) - 2*lst[0]) else : t = abs(lst[0]) for i in range(n): if lst[i] < 0 and k > 0: k -= 1 t = abs(lst[i]) lst[i] = abs(t) if k > 0: if k%2 == 0: print(sum(lst)) else : print(sum(lst) - 2*t) else : print(sum(lst)) ```
0
758
A
Holiday Of Equality
PROGRAMMING
800
[ "implementation", "math" ]
null
null
In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury. Totally in Berland there are *n* citizens, the welfare of each of them is estimated as the integer in *a**i* burles (burle is the currency in Berland). You are the royal treasurer, which needs to count the minimum charges of the kingdom on the king's present. The king can only give money, he hasn't a power to take away them.
The first line contains the integer *n* (1<=≤<=*n*<=≤<=100) — the number of citizens in the kingdom. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* (0<=≤<=*a**i*<=≤<=106) — the welfare of the *i*-th citizen.
In the only line print the integer *S* — the minimum number of burles which are had to spend.
[ "5\n0 1 2 3 4\n", "5\n1 1 0 1 1\n", "3\n1 3 1\n", "1\n12\n" ]
[ "10", "1", "4", "0" ]
In the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4. In the second example it is enough to give one burle to the third citizen. In the third example it is necessary to give two burles to the first and the third citizens to make the welfare of citizens equal 3. In the fourth example it is possible to give nothing to everyone because all citizens have 12 burles.
500
[ { "input": "5\n0 1 2 3 4", "output": "10" }, { "input": "5\n1 1 0 1 1", "output": "1" }, { "input": "3\n1 3 1", "output": "4" }, { "input": "1\n12", "output": "0" }, { "input": "3\n1 2 3", "output": "3" }, { "input": "14\n52518 718438 358883 462189 853171 592966 225788 46977 814826 295697 676256 561479 56545 764281", "output": "5464380" }, { "input": "21\n842556 216391 427181 626688 775504 168309 851038 448402 880826 73697 593338 519033 135115 20128 424606 939484 846242 756907 377058 241543 29353", "output": "9535765" }, { "input": "3\n1 3 2", "output": "3" }, { "input": "3\n2 1 3", "output": "3" }, { "input": "3\n2 3 1", "output": "3" }, { "input": "3\n3 1 2", "output": "3" }, { "input": "3\n3 2 1", "output": "3" }, { "input": "1\n228503", "output": "0" }, { "input": "2\n32576 550340", "output": "517764" }, { "input": "3\n910648 542843 537125", "output": "741328" }, { "input": "4\n751720 572344 569387 893618", "output": "787403" }, { "input": "6\n433864 631347 597596 794426 713555 231193", "output": "1364575" }, { "input": "9\n31078 645168 695751 126111 375934 150495 838412 434477 993107", "output": "4647430" }, { "input": "30\n315421 772664 560686 654312 151528 356749 351486 707462 820089 226682 546700 136028 824236 842130 578079 337807 665903 764100 617900 822937 992759 591749 651310 742085 767695 695442 17967 515106 81059 186025", "output": "13488674" }, { "input": "45\n908719 394261 815134 419990 926993 383792 772842 277695 527137 655356 684956 695716 273062 550324 106247 399133 442382 33076 462920 294674 846052 817752 421365 474141 290471 358990 109812 74492 543281 169434 919692 786809 24028 197184 310029 801476 699355 429672 51343 374128 776726 850380 293868 981569 550763", "output": "21993384" }, { "input": "56\n100728 972537 13846 385421 756708 184642 259487 319707 376662 221694 675284 972837 499419 13846 38267 289898 901299 831197 954715 197515 514102 910423 127555 883934 362472 870788 538802 741008 973434 448124 391526 363321 947321 544618 68006 782313 955075 741981 815027 723297 585059 718114 700739 413489 454091 736144 308999 98065 3716 347323 9635 289003 986510 607065 60236 273351", "output": "26984185" }, { "input": "70\n644488 5444 150441 714420 602059 335330 510670 196555 546346 740011 509449 850947 692874 524857 750434 952985 223744 374727 896124 753037 367352 679050 560202 172728 569291 778616 332116 286927 843598 372698 244906 498046 900681 709791 420904 724593 864493 813094 791377 39998 296710 625656 403891 579231 706693 984045 16901 574259 562265 761104 930361 256045 124461 538980 573508 372148 988722 108592 784354 55302 232524 277205 782251 299943 436488 743389 324618 742543 266915 99642", "output": "32816391" }, { "input": "1\n0", "output": "0" }, { "input": "1\n1000000", "output": "0" }, { "input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "0" }, { "input": "100\n1000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "99000000" }, { "input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1000000", "output": "99000000" }, { "input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "99000000" }, { "input": "3\n0 0 0", "output": "0" }, { "input": "50\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "0" }, { "input": "3\n5 0 0", "output": "10" }, { "input": "5\n2 10 0 0 0", "output": "38" } ]
1,650,298,678
2,147,483,647
Python 3
OK
TESTS
41
46
0
num = int(input()) lista = list(map(int, input().split(' '))) m = max(lista) sum = 0 for num in lista: sum+= m-num print(sum)
Title: Holiday Of Equality Time Limit: None seconds Memory Limit: None megabytes Problem Description: In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury. Totally in Berland there are *n* citizens, the welfare of each of them is estimated as the integer in *a**i* burles (burle is the currency in Berland). You are the royal treasurer, which needs to count the minimum charges of the kingdom on the king's present. The king can only give money, he hasn't a power to take away them. Input Specification: The first line contains the integer *n* (1<=≤<=*n*<=≤<=100) — the number of citizens in the kingdom. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* (0<=≤<=*a**i*<=≤<=106) — the welfare of the *i*-th citizen. Output Specification: In the only line print the integer *S* — the minimum number of burles which are had to spend. Demo Input: ['5\n0 1 2 3 4\n', '5\n1 1 0 1 1\n', '3\n1 3 1\n', '1\n12\n'] Demo Output: ['10', '1', '4', '0'] Note: In the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4. In the second example it is enough to give one burle to the third citizen. In the third example it is necessary to give two burles to the first and the third citizens to make the welfare of citizens equal 3. In the fourth example it is possible to give nothing to everyone because all citizens have 12 burles.
```python num = int(input()) lista = list(map(int, input().split(' '))) m = max(lista) sum = 0 for num in lista: sum+= m-num print(sum) ```
3
961
A
Tetris
PROGRAMMING
900
[ "implementation" ]
null
null
You are given a following process. There is a platform with $n$ columns. $1 \times 1$ squares are appearing one after another in some columns on this platform. If there are no squares in the column, a square will occupy the bottom row. Otherwise a square will appear at the top of the highest square of this column. When all of the $n$ columns have at least one square in them, the bottom row is being removed. You will receive $1$ point for this, and all the squares left will fall down one row. You task is to calculate the amount of points you will receive.
The first line of input contain 2 integer numbers $n$ and $m$ ($1 \le n, m \le 1000$) — the length of the platform and the number of the squares. The next line contain $m$ integer numbers $c_1, c_2, \dots, c_m$ ($1 \le c_i \le n$) — column in which $i$-th square will appear.
Print one integer — the amount of points you will receive.
[ "3 9\n1 1 2 2 2 3 1 2 3\n" ]
[ "2\n" ]
In the sample case the answer will be equal to $2$ because after the appearing of $6$-th square will be removed one row (counts of the squares on the platform will look like $[2~ 3~ 1]$, and after removing one row will be $[1~ 2~ 0]$). After the appearing of $9$-th square counts will be $[2~ 3~ 1]$, and after removing one row it will look like $[1~ 2~ 0]$. So the answer will be equal to $2$.
0
[ { "input": "3 9\n1 1 2 2 2 3 1 2 3", "output": "2" }, { "input": "1 7\n1 1 1 1 1 1 1", "output": "7" }, { "input": "1 1\n1", "output": "1" }, { "input": "3 5\n1 1 1 2 3", "output": "1" }, { "input": "4 6\n4 4 4 4 4 4", "output": "0" }, { "input": "4 6\n2 3 4 4 4 4", "output": "0" }, { "input": "3 12\n1 1 1 1 2 2 2 2 3 3 3 3", "output": "4" }, { "input": "8 8\n2 2 3 4 5 6 7 8", "output": "0" }, { "input": "100 1\n50", "output": "0" }, { "input": "2 1\n2", "output": "0" }, { "input": "2 1\n1", "output": "0" }, { "input": "2 4\n1 2 1 1", "output": "1" }, { "input": "3 4\n3 2 2 2", "output": "0" }, { "input": "2 2\n2 2", "output": "0" }, { "input": "2 5\n2 1 1 2 1", "output": "2" }, { "input": "15 3\n13 14 15", "output": "0" }, { "input": "4 9\n1 2 3 1 2 3 1 2 3", "output": "0" }, { "input": "100 3\n1 2 3", "output": "0" }, { "input": "1000 10\n999 999 998 34 454 546 343 35 34 1000", "output": "0" }, { "input": "4 2\n1 2", "output": "0" } ]
1,553,590,133
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
2
140
0
n,m=map(int,input().split()) l=list(map(int,input().split())) y=list(set(l)) x=[] for i in range(len(y)): x.append(l.count(y[i])) print(min(x))
Title: Tetris Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a following process. There is a platform with $n$ columns. $1 \times 1$ squares are appearing one after another in some columns on this platform. If there are no squares in the column, a square will occupy the bottom row. Otherwise a square will appear at the top of the highest square of this column. When all of the $n$ columns have at least one square in them, the bottom row is being removed. You will receive $1$ point for this, and all the squares left will fall down one row. You task is to calculate the amount of points you will receive. Input Specification: The first line of input contain 2 integer numbers $n$ and $m$ ($1 \le n, m \le 1000$) — the length of the platform and the number of the squares. The next line contain $m$ integer numbers $c_1, c_2, \dots, c_m$ ($1 \le c_i \le n$) — column in which $i$-th square will appear. Output Specification: Print one integer — the amount of points you will receive. Demo Input: ['3 9\n1 1 2 2 2 3 1 2 3\n'] Demo Output: ['2\n'] Note: In the sample case the answer will be equal to $2$ because after the appearing of $6$-th square will be removed one row (counts of the squares on the platform will look like $[2~ 3~ 1]$, and after removing one row will be $[1~ 2~ 0]$). After the appearing of $9$-th square counts will be $[2~ 3~ 1]$, and after removing one row it will look like $[1~ 2~ 0]$. So the answer will be equal to $2$.
```python n,m=map(int,input().split()) l=list(map(int,input().split())) y=list(set(l)) x=[] for i in range(len(y)): x.append(l.count(y[i])) print(min(x)) ```
0
46
A
Ball Game
PROGRAMMING
800
[ "brute force", "implementation" ]
A. Ball Game
2
256
A kindergarten teacher Natalia Pavlovna has invented a new ball game. This game not only develops the children's physique, but also teaches them how to count. The game goes as follows. Kids stand in circle. Let's agree to think of the children as numbered with numbers from 1 to *n* clockwise and the child number 1 is holding the ball. First the first child throws the ball to the next one clockwise, i.e. to the child number 2. Then the child number 2 throws the ball to the next but one child, i.e. to the child number 4, then the fourth child throws the ball to the child that stands two children away from him, i.e. to the child number 7, then the ball is thrown to the child who stands 3 children away from the child number 7, then the ball is thrown to the child who stands 4 children away from the last one, and so on. It should be mentioned that when a ball is thrown it may pass the beginning of the circle. For example, if *n*<==<=5, then after the third throw the child number 2 has the ball again. Overall, *n*<=-<=1 throws are made, and the game ends. The problem is that not all the children get the ball during the game. If a child doesn't get the ball, he gets very upset and cries until Natalia Pavlovna gives him a candy. That's why Natalia Pavlovna asks you to help her to identify the numbers of the children who will get the ball after each throw.
The first line contains integer *n* (2<=≤<=*n*<=≤<=100) which indicates the number of kids in the circle.
In the single line print *n*<=-<=1 numbers which are the numbers of children who will get the ball after each throw. Separate the numbers by spaces.
[ "10\n", "3\n" ]
[ "2 4 7 1 6 2 9 7 6\n", "2 1\n" ]
none
0
[ { "input": "10", "output": "2 4 7 1 6 2 9 7 6" }, { "input": "3", "output": "2 1" }, { "input": "4", "output": "2 4 3" }, { "input": "5", "output": "2 4 2 1" }, { "input": "6", "output": "2 4 1 5 4" }, { "input": "7", "output": "2 4 7 4 2 1" }, { "input": "8", "output": "2 4 7 3 8 6 5" }, { "input": "9", "output": "2 4 7 2 7 4 2 1" }, { "input": "2", "output": "2" }, { "input": "11", "output": "2 4 7 11 5 11 7 4 2 1" }, { "input": "12", "output": "2 4 7 11 4 10 5 1 10 8 7" }, { "input": "13", "output": "2 4 7 11 3 9 3 11 7 4 2 1" }, { "input": "20", "output": "2 4 7 11 16 2 9 17 6 16 7 19 12 6 1 17 14 12 11" }, { "input": "25", "output": "2 4 7 11 16 22 4 12 21 6 17 4 17 6 21 12 4 22 16 11 7 4 2 1" }, { "input": "30", "output": "2 4 7 11 16 22 29 7 16 26 7 19 2 16 1 17 4 22 11 1 22 14 7 1 26 22 19 17 16" }, { "input": "35", "output": "2 4 7 11 16 22 29 2 11 21 32 9 22 1 16 32 14 32 16 1 22 9 32 21 11 2 29 22 16 11 7 4 2 1" }, { "input": "40", "output": "2 4 7 11 16 22 29 37 6 16 27 39 12 26 1 17 34 12 31 11 32 14 37 21 6 32 19 7 36 26 17 9 2 36 31 27 24 22 21" }, { "input": "45", "output": "2 4 7 11 16 22 29 37 1 11 22 34 2 16 31 2 19 37 11 31 7 29 7 31 11 37 19 2 31 16 2 34 22 11 1 37 29 22 16 11 7 4 2 1" }, { "input": "50", "output": "2 4 7 11 16 22 29 37 46 6 17 29 42 6 21 37 4 22 41 11 32 4 27 1 26 2 29 7 36 16 47 29 12 46 31 17 4 42 31 21 12 4 47 41 36 32 29 27 26" }, { "input": "55", "output": "2 4 7 11 16 22 29 37 46 1 12 24 37 51 11 27 44 7 26 46 12 34 2 26 51 22 49 22 51 26 2 34 12 46 26 7 44 27 11 51 37 24 12 1 46 37 29 22 16 11 7 4 2 1" }, { "input": "60", "output": "2 4 7 11 16 22 29 37 46 56 7 19 32 46 1 17 34 52 11 31 52 14 37 1 26 52 19 47 16 46 17 49 22 56 31 7 44 22 1 41 22 4 47 31 16 2 49 37 26 16 7 59 52 46 41 37 34 32 31" }, { "input": "65", "output": "2 4 7 11 16 22 29 37 46 56 2 14 27 41 56 7 24 42 61 16 37 59 17 41 1 27 54 17 46 11 42 9 42 11 46 17 54 27 1 41 17 59 37 16 61 42 24 7 56 41 27 14 2 56 46 37 29 22 16 11 7 4 2 1" }, { "input": "70", "output": "2 4 7 11 16 22 29 37 46 56 67 9 22 36 51 67 14 32 51 1 22 44 67 21 46 2 29 57 16 46 7 39 2 36 1 37 4 42 11 51 22 64 37 11 56 32 9 57 36 16 67 49 32 16 1 57 44 32 21 11 2 64 57 51 46 42 39 37 36" }, { "input": "75", "output": "2 4 7 11 16 22 29 37 46 56 67 4 17 31 46 62 4 22 41 61 7 29 52 1 26 52 4 32 61 16 47 4 37 71 31 67 29 67 31 71 37 4 47 16 61 32 4 52 26 1 52 29 7 61 41 22 4 62 46 31 17 4 67 56 46 37 29 22 16 11 7 4 2 1" }, { "input": "80", "output": "2 4 7 11 16 22 29 37 46 56 67 79 12 26 41 57 74 12 31 51 72 14 37 61 6 32 59 7 36 66 17 49 2 36 71 27 64 22 61 21 62 24 67 31 76 42 9 57 26 76 47 19 72 46 21 77 54 32 11 71 52 34 17 1 66 52 39 27 16 6 77 69 62 56 51 47 44 42 41" }, { "input": "85", "output": "2 4 7 11 16 22 29 37 46 56 67 79 7 21 36 52 69 2 21 41 62 84 22 46 71 12 39 67 11 41 72 19 52 1 36 72 24 62 16 56 12 54 12 56 16 62 24 72 36 1 52 19 72 41 11 67 39 12 71 46 22 84 62 41 21 2 69 52 36 21 7 79 67 56 46 37 29 22 16 11 7 4 2 1" }, { "input": "90", "output": "2 4 7 11 16 22 29 37 46 56 67 79 2 16 31 47 64 82 11 31 52 74 7 31 56 82 19 47 76 16 47 79 22 56 1 37 74 22 61 11 52 4 47 1 46 2 49 7 56 16 67 29 82 46 11 67 34 2 61 31 2 64 37 11 76 52 29 7 76 56 37 19 2 76 61 47 34 22 11 1 82 74 67 61 56 52 49 47 46" }, { "input": "95", "output": "2 4 7 11 16 22 29 37 46 56 67 79 92 11 26 42 59 77 1 21 42 64 87 16 41 67 94 27 56 86 22 54 87 26 61 2 39 77 21 61 7 49 92 41 86 37 84 37 86 41 92 49 7 61 21 77 39 2 61 26 87 54 22 86 56 27 94 67 41 16 87 64 42 21 1 77 59 42 26 11 92 79 67 56 46 37 29 22 16 11 7 4 2 1" }, { "input": "96", "output": "2 4 7 11 16 22 29 37 46 56 67 79 92 10 25 41 58 76 95 19 40 62 85 13 38 64 91 23 52 82 17 49 82 20 55 91 32 70 13 53 94 40 83 31 76 26 73 25 74 28 79 35 88 46 5 61 22 80 43 7 68 34 1 65 34 4 71 43 16 86 61 37 14 88 67 47 28 10 89 73 58 44 31 19 8 94 85 77 70 64 59 55 52 50 49" }, { "input": "97", "output": "2 4 7 11 16 22 29 37 46 56 67 79 92 9 24 40 57 75 94 17 38 60 83 10 35 61 88 19 48 78 12 44 77 14 49 85 25 63 5 45 86 31 74 21 66 15 62 13 62 15 66 21 74 31 86 45 5 63 25 85 49 14 77 44 12 78 48 19 88 61 35 10 83 60 38 17 94 75 57 40 24 9 92 79 67 56 46 37 29 22 16 11 7 4 2 1" }, { "input": "98", "output": "2 4 7 11 16 22 29 37 46 56 67 79 92 8 23 39 56 74 93 15 36 58 81 7 32 58 85 15 44 74 7 39 72 8 43 79 18 56 95 37 78 22 65 11 56 4 51 1 50 2 53 7 60 16 71 29 86 46 7 67 30 92 57 23 88 56 25 93 64 36 9 81 56 32 9 85 64 44 25 7 88 72 57 43 30 18 7 95 86 78 71 65 60 56 53 51 50" }, { "input": "99", "output": "2 4 7 11 16 22 29 37 46 56 67 79 92 7 22 38 55 73 92 13 34 56 79 4 29 55 82 11 40 70 2 34 67 2 37 73 11 49 88 29 70 13 56 1 46 92 40 88 38 88 40 92 46 1 56 13 70 29 88 49 11 73 37 2 67 34 2 70 40 11 82 55 29 4 79 56 34 13 92 73 55 38 22 7 92 79 67 56 46 37 29 22 16 11 7 4 2 1" }, { "input": "100", "output": "2 4 7 11 16 22 29 37 46 56 67 79 92 6 21 37 54 72 91 11 32 54 77 1 26 52 79 7 36 66 97 29 62 96 31 67 4 42 81 21 62 4 47 91 36 82 29 77 26 76 27 79 32 86 41 97 54 12 71 31 92 54 17 81 46 12 79 47 16 86 57 29 2 76 51 27 4 82 61 41 22 4 87 71 56 42 29 17 6 96 87 79 72 66 61 57 54 52 51" } ]
1,642,758,916
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
6
92
0
n = int(input()) i = 1 m = 0 while m <= n-2: i += m+1 m += 1 if i%n == 0: x = i else: x = i%n print(x, end = " ")
Title: Ball Game Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A kindergarten teacher Natalia Pavlovna has invented a new ball game. This game not only develops the children's physique, but also teaches them how to count. The game goes as follows. Kids stand in circle. Let's agree to think of the children as numbered with numbers from 1 to *n* clockwise and the child number 1 is holding the ball. First the first child throws the ball to the next one clockwise, i.e. to the child number 2. Then the child number 2 throws the ball to the next but one child, i.e. to the child number 4, then the fourth child throws the ball to the child that stands two children away from him, i.e. to the child number 7, then the ball is thrown to the child who stands 3 children away from the child number 7, then the ball is thrown to the child who stands 4 children away from the last one, and so on. It should be mentioned that when a ball is thrown it may pass the beginning of the circle. For example, if *n*<==<=5, then after the third throw the child number 2 has the ball again. Overall, *n*<=-<=1 throws are made, and the game ends. The problem is that not all the children get the ball during the game. If a child doesn't get the ball, he gets very upset and cries until Natalia Pavlovna gives him a candy. That's why Natalia Pavlovna asks you to help her to identify the numbers of the children who will get the ball after each throw. Input Specification: The first line contains integer *n* (2<=≤<=*n*<=≤<=100) which indicates the number of kids in the circle. Output Specification: In the single line print *n*<=-<=1 numbers which are the numbers of children who will get the ball after each throw. Separate the numbers by spaces. Demo Input: ['10\n', '3\n'] Demo Output: ['2 4 7 1 6 2 9 7 6\n', '2 1\n'] Note: none
```python n = int(input()) i = 1 m = 0 while m <= n-2: i += m+1 m += 1 if i%n == 0: x = i else: x = i%n print(x, end = " ") ```
0
486
A
Calculating Function
PROGRAMMING
800
[ "implementation", "math" ]
null
null
For a positive integer *n* let's define a function *f*: *f*(*n*)<==<=<=-<=1<=+<=2<=-<=3<=+<=..<=+<=(<=-<=1)*n**n* Your task is to calculate *f*(*n*) for a given integer *n*.
The single line contains the positive integer *n* (1<=≤<=*n*<=≤<=1015).
Print *f*(*n*) in a single line.
[ "4\n", "5\n" ]
[ "2\n", "-3\n" ]
*f*(4) =  - 1 + 2 - 3 + 4 = 2 *f*(5) =  - 1 + 2 - 3 + 4 - 5 =  - 3
500
[ { "input": "4", "output": "2" }, { "input": "5", "output": "-3" }, { "input": "1000000000", "output": "500000000" }, { "input": "1000000001", "output": "-500000001" }, { "input": "1000000000000000", "output": "500000000000000" }, { "input": "100", "output": "50" }, { "input": "101", "output": "-51" }, { "input": "102", "output": "51" }, { "input": "103", "output": "-52" }, { "input": "104", "output": "52" }, { "input": "105", "output": "-53" }, { "input": "106", "output": "53" }, { "input": "107", "output": "-54" }, { "input": "108", "output": "54" }, { "input": "109", "output": "-55" }, { "input": "208170109961052", "output": "104085054980526" }, { "input": "46017661651072", "output": "23008830825536" }, { "input": "4018154546667", "output": "-2009077273334" }, { "input": "288565475053", "output": "-144282737527" }, { "input": "3052460231", "output": "-1526230116" }, { "input": "29906716", "output": "14953358" }, { "input": "87897701693326", "output": "43948850846663" }, { "input": "8240", "output": "4120" }, { "input": "577935", "output": "-288968" }, { "input": "62", "output": "31" }, { "input": "1", "output": "-1" }, { "input": "2", "output": "1" }, { "input": "9999999999999", "output": "-5000000000000" }, { "input": "1000000000000", "output": "500000000000" }, { "input": "99999999999999", "output": "-50000000000000" }, { "input": "999999999999999", "output": "-500000000000000" }, { "input": "42191359342", "output": "21095679671" }, { "input": "100000000000000", "output": "50000000000000" }, { "input": "145645214654154", "output": "72822607327077" }, { "input": "4294967296", "output": "2147483648" }, { "input": "3037000499", "output": "-1518500250" }, { "input": "10000000000001", "output": "-5000000000001" }, { "input": "100000017040846", "output": "50000008520423" }, { "input": "98979894985999", "output": "-49489947493000" } ]
1,696,449,847
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
0
t=int(input()) if t==0: print(0) elif t==1: print(-1) elif (t%2==0): print(t/2) else: print(-(t/2+0.5))
Title: Calculating Function Time Limit: None seconds Memory Limit: None megabytes Problem Description: For a positive integer *n* let's define a function *f*: *f*(*n*)<==<=<=-<=1<=+<=2<=-<=3<=+<=..<=+<=(<=-<=1)*n**n* Your task is to calculate *f*(*n*) for a given integer *n*. Input Specification: The single line contains the positive integer *n* (1<=≤<=*n*<=≤<=1015). Output Specification: Print *f*(*n*) in a single line. Demo Input: ['4\n', '5\n'] Demo Output: ['2\n', '-3\n'] Note: *f*(4) =  - 1 + 2 - 3 + 4 = 2 *f*(5) =  - 1 + 2 - 3 + 4 - 5 =  - 3
```python t=int(input()) if t==0: print(0) elif t==1: print(-1) elif (t%2==0): print(t/2) else: print(-(t/2+0.5)) ```
0
768
A
Oath of the Night's Watch
PROGRAMMING
900
[ "constructive algorithms", "sortings" ]
null
null
"Night gathers, and now my watch begins. It shall not end until my death. I shall take no wife, hold no lands, father no children. I shall wear no crowns and win no glory. I shall live and die at my post. I am the sword in the darkness. I am the watcher on the walls. I am the shield that guards the realms of men. I pledge my life and honor to the Night's Watch, for this night and all the nights to come." — The Night's Watch oath. With that begins the watch of Jon Snow. He is assigned the task to support the stewards. This time he has *n* stewards with him whom he has to provide support. Each steward has his own strength. Jon Snow likes to support a steward only if there exists at least one steward who has strength strictly less than him and at least one steward who has strength strictly greater than him. Can you find how many stewards will Jon support?
First line consists of a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of stewards with Jon Snow. Second line consists of *n* space separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) representing the values assigned to the stewards.
Output a single integer representing the number of stewards which Jon will feed.
[ "2\n1 5\n", "3\n1 2 5\n" ]
[ "0", "1" ]
In the first sample, Jon Snow cannot support steward with strength 1 because there is no steward with strength less than 1 and he cannot support steward with strength 5 because there is no steward with strength greater than 5. In the second sample, Jon Snow can support steward with strength 2 because there are stewards with strength less than 2 and greater than 2.
500
[ { "input": "2\n1 5", "output": "0" }, { "input": "3\n1 2 5", "output": "1" }, { "input": "4\n1 2 3 4", "output": "2" }, { "input": "8\n7 8 9 4 5 6 1 2", "output": "6" }, { "input": "1\n1", "output": "0" }, { "input": "1\n100", "output": "0" }, { "input": "205\n5 5 3 3 6 2 9 3 8 9 6 6 10 8 1 5 3 3 1 2 9 9 9 3 9 10 3 9 8 3 5 6 6 4 6 9 2 9 10 9 5 6 6 7 4 2 6 3 4 1 10 1 7 2 7 7 3 2 6 5 5 2 9 3 8 8 7 6 6 4 2 2 6 2 3 5 7 2 2 10 1 4 6 9 2 3 7 2 2 7 4 4 9 10 7 5 8 6 5 3 6 10 2 7 5 6 6 8 3 3 9 4 3 5 7 9 3 2 1 1 3 2 1 9 3 1 4 4 10 2 5 5 8 1 4 8 5 3 1 10 8 6 5 8 3 5 4 5 4 4 6 7 2 8 10 8 7 6 6 9 6 7 1 10 3 2 5 10 4 4 5 4 3 4 8 5 3 8 10 3 10 9 7 2 1 8 6 4 6 5 8 10 2 6 7 4 9 4 5 1 8 7 10 3 1", "output": "174" }, { "input": "4\n1000000000 99999999 1000000000 1000000000", "output": "0" }, { "input": "3\n2 2 2", "output": "0" }, { "input": "5\n1 1 1 1 1", "output": "0" }, { "input": "3\n1 1 1", "output": "0" }, { "input": "6\n1 1 3 3 2 2", "output": "2" }, { "input": "7\n1 1 1 1 1 1 1", "output": "0" }, { "input": "4\n1 1 2 5", "output": "1" }, { "input": "3\n0 0 0", "output": "0" }, { "input": "5\n0 0 0 0 0", "output": "0" }, { "input": "5\n1 1 1 1 5", "output": "0" }, { "input": "5\n1 1 2 3 3", "output": "1" }, { "input": "3\n1 1 3", "output": "0" }, { "input": "3\n2 2 3", "output": "0" }, { "input": "1\n6", "output": "0" }, { "input": "5\n1 5 3 5 1", "output": "1" }, { "input": "7\n1 2 2 2 2 2 3", "output": "5" }, { "input": "4\n2 2 2 2", "output": "0" }, { "input": "9\n2 2 2 3 4 5 6 6 6", "output": "3" }, { "input": "10\n1 1 1 2 3 3 3 3 3 3", "output": "1" }, { "input": "6\n1 1 1 1 1 1", "output": "0" }, { "input": "3\n0 0 1", "output": "0" }, { "input": "9\n1 1 1 2 2 2 3 3 3", "output": "3" }, { "input": "3\n1 2 2", "output": "0" }, { "input": "6\n2 2 2 2 2 2", "output": "0" }, { "input": "5\n2 2 2 2 2", "output": "0" }, { "input": "5\n5 5 5 5 5", "output": "0" }, { "input": "1\n0", "output": "0" }, { "input": "6\n1 2 5 5 5 5", "output": "1" }, { "input": "5\n1 2 3 3 3", "output": "1" }, { "input": "3\n1 1 2", "output": "0" }, { "input": "6\n1 1 1 1 1 2", "output": "0" }, { "input": "5\n1 1 2 4 4", "output": "1" }, { "input": "3\n999999 5999999 9999999", "output": "1" }, { "input": "4\n1 1 5 5", "output": "0" }, { "input": "9\n1 1 1 2 2 2 4 4 4", "output": "3" }, { "input": "5\n1 3 4 5 1", "output": "2" }, { "input": "5\n3 3 3 3 3", "output": "0" }, { "input": "5\n1 1 2 2 2", "output": "0" }, { "input": "5\n2 1 1 1 3", "output": "1" }, { "input": "5\n0 0 0 1 2", "output": "1" }, { "input": "4\n2 2 2 3", "output": "0" }, { "input": "7\n1 1 1 1 5 5 5", "output": "0" }, { "input": "5\n1 2 3 4 4", "output": "2" }, { "input": "2\n5 4", "output": "0" }, { "input": "4\n5 5 5 5", "output": "0" }, { "input": "5\n1 1 1 5 5", "output": "0" }, { "input": "2\n1 1", "output": "0" }, { "input": "1\n3", "output": "0" }, { "input": "3\n2 1 2", "output": "0" }, { "input": "4\n1 2 2 2", "output": "0" }, { "input": "8\n1000000000 1000000000 1000000000 999999999 999999999 999999999 999999998 999999998", "output": "3" }, { "input": "5\n1 1 3 4 4", "output": "1" }, { "input": "6\n1 1 2 2 3 3", "output": "2" }, { "input": "4\n1 1 1 1", "output": "0" }, { "input": "9\n1 2 3 4 1 5 6 7 8", "output": "6" }, { "input": "8\n5 4 4 6 6 4 4 3", "output": "5" }, { "input": "8\n4 3 3 3 3 3 3 3", "output": "0" }, { "input": "7\n4 3 3 3 3 3 3", "output": "0" }, { "input": "6\n4 3 3 3 3 3", "output": "0" }, { "input": "5\n4 3 3 3 3", "output": "0" } ]
1,658,685,663
2,147,483,647
Python 3
OK
TESTS
88
139
9,113,600
n = int(input()) stewards = list(map(int, input().split())) stewards.sort() count = 0 for i in stewards: if i > stewards[0] and i < stewards[len(stewards)-1]: count += 1 print(count)
Title: Oath of the Night's Watch Time Limit: None seconds Memory Limit: None megabytes Problem Description: "Night gathers, and now my watch begins. It shall not end until my death. I shall take no wife, hold no lands, father no children. I shall wear no crowns and win no glory. I shall live and die at my post. I am the sword in the darkness. I am the watcher on the walls. I am the shield that guards the realms of men. I pledge my life and honor to the Night's Watch, for this night and all the nights to come." — The Night's Watch oath. With that begins the watch of Jon Snow. He is assigned the task to support the stewards. This time he has *n* stewards with him whom he has to provide support. Each steward has his own strength. Jon Snow likes to support a steward only if there exists at least one steward who has strength strictly less than him and at least one steward who has strength strictly greater than him. Can you find how many stewards will Jon support? Input Specification: First line consists of a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of stewards with Jon Snow. Second line consists of *n* space separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) representing the values assigned to the stewards. Output Specification: Output a single integer representing the number of stewards which Jon will feed. Demo Input: ['2\n1 5\n', '3\n1 2 5\n'] Demo Output: ['0', '1'] Note: In the first sample, Jon Snow cannot support steward with strength 1 because there is no steward with strength less than 1 and he cannot support steward with strength 5 because there is no steward with strength greater than 5. In the second sample, Jon Snow can support steward with strength 2 because there are stewards with strength less than 2 and greater than 2.
```python n = int(input()) stewards = list(map(int, input().split())) stewards.sort() count = 0 for i in stewards: if i > stewards[0] and i < stewards[len(stewards)-1]: count += 1 print(count) ```
3
25
A
IQ test
PROGRAMMING
1,300
[ "brute force" ]
A. IQ test
2
256
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness.
The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
[ "5\n2 4 7 8 10\n", "4\n1 2 1 1\n" ]
[ "3\n", "2\n" ]
none
0
[ { "input": "5\n2 4 7 8 10", "output": "3" }, { "input": "4\n1 2 1 1", "output": "2" }, { "input": "3\n1 2 2", "output": "1" }, { "input": "3\n100 99 100", "output": "2" }, { "input": "3\n5 3 2", "output": "3" }, { "input": "4\n43 28 1 91", "output": "2" }, { "input": "4\n75 13 94 77", "output": "3" }, { "input": "4\n97 8 27 3", "output": "2" }, { "input": "10\n95 51 12 91 85 3 1 31 25 7", "output": "3" }, { "input": "20\n88 96 66 51 14 88 2 92 18 72 18 88 20 30 4 82 90 100 24 46", "output": "4" }, { "input": "30\n20 94 56 50 10 98 52 32 14 22 24 60 4 8 98 46 34 68 82 82 98 90 50 20 78 49 52 94 64 36", "output": "26" }, { "input": "50\n79 27 77 57 37 45 27 49 65 33 57 21 71 19 75 85 65 61 23 97 85 9 23 1 9 3 99 77 77 21 79 69 15 37 15 7 93 81 13 89 91 31 45 93 15 97 55 80 85 83", "output": "48" }, { "input": "60\n46 11 73 65 3 69 3 53 43 53 97 47 55 93 31 75 35 3 9 73 23 31 3 81 91 79 61 21 15 11 11 11 81 7 83 75 39 87 83 59 89 55 93 27 49 67 67 29 1 93 11 17 9 19 35 21 63 31 31 25", "output": "1" }, { "input": "70\n28 42 42 92 64 54 22 38 38 78 62 38 4 38 14 66 4 92 66 58 94 26 4 44 41 88 48 82 44 26 74 44 48 4 16 92 34 38 26 64 94 4 30 78 50 54 12 90 8 16 80 98 28 100 74 50 36 42 92 18 76 98 8 22 2 50 58 50 64 46", "output": "25" }, { "input": "100\n43 35 79 53 13 91 91 45 65 83 57 9 42 39 85 45 71 51 61 59 31 13 63 39 25 21 79 39 91 67 21 61 97 75 93 83 29 79 59 97 11 37 63 51 39 55 91 23 21 17 47 23 35 75 49 5 69 99 5 7 41 17 25 89 15 79 21 63 53 81 43 91 59 91 69 99 85 15 91 51 49 37 65 7 89 81 21 93 61 63 97 93 45 17 13 69 57 25 75 73", "output": "13" }, { "input": "100\n50 24 68 60 70 30 52 22 18 74 68 98 20 82 4 46 26 68 100 78 84 58 74 98 38 88 68 86 64 80 82 100 20 22 98 98 52 6 94 10 48 68 2 18 38 22 22 82 44 20 66 72 36 58 64 6 36 60 4 96 76 64 12 90 10 58 64 60 74 28 90 26 24 60 40 58 2 16 76 48 58 36 82 60 24 44 4 78 28 38 8 12 40 16 38 6 66 24 31 76", "output": "99" }, { "input": "100\n47 48 94 48 14 18 94 36 96 22 12 30 94 20 48 98 40 58 2 94 8 36 98 18 98 68 2 60 76 38 18 100 8 72 100 68 2 86 92 72 58 16 48 14 6 58 72 76 6 88 80 66 20 28 74 62 86 68 90 86 2 56 34 38 56 90 4 8 76 44 32 86 12 98 38 34 54 92 70 94 10 24 82 66 90 58 62 2 32 58 100 22 58 72 2 22 68 72 42 14", "output": "1" }, { "input": "99\n38 20 68 60 84 16 28 88 60 48 80 28 4 92 70 60 46 46 20 34 12 100 76 2 40 10 8 86 6 80 50 66 12 34 14 28 26 70 46 64 34 96 10 90 98 96 56 88 50 74 70 94 2 94 24 66 68 46 22 30 6 10 64 32 88 14 98 100 64 58 50 18 50 50 8 38 8 16 54 2 60 54 62 84 92 98 4 72 66 26 14 88 99 16 10 6 88 56 22", "output": "93" }, { "input": "99\n50 83 43 89 53 47 69 1 5 37 63 87 95 15 55 95 75 89 33 53 89 75 93 75 11 85 49 29 11 97 49 67 87 11 25 37 97 73 67 49 87 43 53 97 43 29 53 33 45 91 37 73 39 49 59 5 21 43 87 35 5 63 89 57 63 47 29 99 19 85 13 13 3 13 43 19 5 9 61 51 51 57 15 89 13 97 41 13 99 79 13 27 97 95 73 33 99 27 23", "output": "1" }, { "input": "98\n61 56 44 30 58 14 20 24 88 28 46 56 96 52 58 42 94 50 46 30 46 80 72 88 68 16 6 60 26 90 10 98 76 20 56 40 30 16 96 20 88 32 62 30 74 58 36 76 60 4 24 36 42 54 24 92 28 14 2 74 86 90 14 52 34 82 40 76 8 64 2 56 10 8 78 16 70 86 70 42 70 74 22 18 76 98 88 28 62 70 36 72 20 68 34 48 80 98", "output": "1" }, { "input": "98\n66 26 46 42 78 32 76 42 26 82 8 12 4 10 24 26 64 44 100 46 94 64 30 18 88 28 8 66 30 82 82 28 74 52 62 80 80 60 94 86 64 32 44 88 92 20 12 74 94 28 34 58 4 22 16 10 94 76 82 58 40 66 22 6 30 32 92 54 16 76 74 98 18 48 48 30 92 2 16 42 84 74 30 60 64 52 50 26 16 86 58 96 79 60 20 62 82 94", "output": "93" }, { "input": "95\n9 31 27 93 17 77 75 9 9 53 89 39 51 99 5 1 11 39 27 49 91 17 27 79 81 71 37 75 35 13 93 4 99 55 85 11 23 57 5 43 5 61 15 35 23 91 3 81 99 85 43 37 39 27 5 67 7 33 75 59 13 71 51 27 15 93 51 63 91 53 43 99 25 47 17 71 81 15 53 31 59 83 41 23 73 25 91 91 13 17 25 13 55 57 29", "output": "32" }, { "input": "100\n91 89 81 45 53 1 41 3 77 93 55 97 55 97 87 27 69 95 73 41 93 21 75 35 53 56 5 51 87 59 91 67 33 3 99 45 83 17 97 47 75 97 7 89 17 99 23 23 81 25 55 97 27 35 69 5 77 35 93 19 55 59 37 21 31 37 49 41 91 53 73 69 7 37 37 39 17 71 7 97 55 17 47 23 15 73 31 39 57 37 9 5 61 41 65 57 77 79 35 47", "output": "26" }, { "input": "99\n38 56 58 98 80 54 26 90 14 16 78 92 52 74 40 30 84 14 44 80 16 90 98 68 26 24 78 72 42 16 84 40 14 44 2 52 50 2 12 96 58 66 8 80 44 52 34 34 72 98 74 4 66 74 56 21 8 38 76 40 10 22 48 32 98 34 12 62 80 68 64 82 22 78 58 74 20 22 48 56 12 38 32 72 6 16 74 24 94 84 26 38 18 24 76 78 98 94 72", "output": "56" }, { "input": "100\n44 40 6 40 56 90 98 8 36 64 76 86 98 76 36 92 6 30 98 70 24 98 96 60 24 82 88 68 86 96 34 42 58 10 40 26 56 10 88 58 70 32 24 28 14 82 52 12 62 36 70 60 52 34 74 30 78 76 10 16 42 94 66 90 70 38 52 12 58 22 98 96 14 68 24 70 4 30 84 98 8 50 14 52 66 34 100 10 28 100 56 48 38 12 38 14 91 80 70 86", "output": "97" }, { "input": "100\n96 62 64 20 90 46 56 90 68 36 30 56 70 28 16 64 94 34 6 32 34 50 94 22 90 32 40 2 72 10 88 38 28 92 20 26 56 80 4 100 100 90 16 74 74 84 8 2 30 20 80 32 16 46 92 56 42 12 96 64 64 42 64 58 50 42 74 28 2 4 36 32 70 50 54 92 70 16 45 76 28 16 18 50 48 2 62 94 4 12 52 52 4 100 70 60 82 62 98 42", "output": "79" }, { "input": "99\n14 26 34 68 90 58 50 36 8 16 18 6 2 74 54 20 36 84 32 50 52 2 26 24 3 64 20 10 54 26 66 44 28 72 4 96 78 90 96 86 68 28 94 4 12 46 100 32 22 36 84 32 44 94 76 94 4 52 12 30 74 4 34 64 58 72 44 16 70 56 54 8 14 74 8 6 58 62 98 54 14 40 80 20 36 72 28 98 20 58 40 52 90 64 22 48 54 70 52", "output": "25" }, { "input": "95\n82 86 30 78 6 46 80 66 74 72 16 24 18 52 52 38 60 36 86 26 62 28 22 46 96 26 94 84 20 46 66 88 76 32 12 86 74 18 34 88 4 48 94 6 58 6 100 82 4 24 88 32 54 98 34 48 6 76 42 88 42 28 100 4 22 2 10 66 82 54 98 20 60 66 38 98 32 47 86 58 6 100 12 46 2 42 8 84 78 28 24 70 34 28 86", "output": "78" }, { "input": "90\n40 50 8 42 76 24 58 42 26 68 20 48 54 12 34 84 14 36 32 88 6 50 96 56 20 92 48 16 40 34 96 46 20 84 30 50 20 98 8 44 96 42 8 76 70 38 84 30 40 88 84 72 2 22 52 58 16 62 100 66 80 40 50 32 14 62 88 72 22 99 76 50 84 82 8 82 98 46 26 40 2 98 18 78 30 72 70 18 34 68", "output": "70" }, { "input": "80\n81 43 87 1 55 43 53 61 27 19 43 13 89 9 33 83 75 55 97 71 91 37 95 5 21 69 81 93 95 69 31 83 55 7 97 7 79 57 8 61 27 85 49 1 15 97 63 79 29 73 41 85 5 41 31 93 67 11 63 59 15 99 91 77 43 69 23 23 81 73 19 1 67 51 1 75 99 67 3 81", "output": "39" }, { "input": "98\n13 83 61 27 35 1 85 95 97 73 95 65 73 45 5 43 27 83 91 19 11 3 85 59 9 39 69 23 45 7 51 85 5 71 5 95 1 51 75 3 43 57 3 11 33 71 21 99 47 41 87 39 71 87 31 85 91 49 83 5 49 85 47 91 55 99 33 23 31 23 23 73 29 77 55 31 25 5 81 49 91 15 15 39 87 5 9 40 69 47 29 33 11 21 49 79 51 83", "output": "88" }, { "input": "3\n100 100 1", "output": "3" } ]
1,576,937,476
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
154
0
n = input() i = 0 n = int(n) c = 0 d = 0 while i < n: b = list(map(int,input().split())) if b [i]% 2 == 0: c += 1 else: d += 1 i += 1 if c > d: print(c - d) else: print(d - c)
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 = input() i = 0 n = int(n) c = 0 d = 0 while i < n: b = list(map(int,input().split())) if b [i]% 2 == 0: c += 1 else: d += 1 i += 1 if c > d: print(c - d) else: print(d - c) ```
-1
601
A
The Two Routes
PROGRAMMING
1,600
[ "graphs", "shortest paths" ]
null
null
In Absurdistan, there are *n* towns (numbered 1 through *n*) and *m* bidirectional railways. There is also an absurdly simple road network — for each pair of different towns *x* and *y*, there is a bidirectional road between towns *x* and *y* if and only if there is no railway between them. Travelling to a different town using one railway or one road always takes exactly one hour. A train and a bus leave town 1 at the same time. They both have the same destination, town *n*, and don't make any stops on the way (but they can wait in town *n*). The train can move only along railways and the bus can move only along roads. You've been asked to plan out routes for the vehicles; each route can use any road/railway multiple times. One of the most important aspects to consider is safety — in order to avoid accidents at railway crossings, the train and the bus must not arrive at the same town (except town *n*) simultaneously. Under these constraints, what is the minimum number of hours needed for both vehicles to reach town *n* (the maximum of arrival times of the bus and the train)? Note, that bus and train are not required to arrive to the town *n* at the same moment of time, but are allowed to do so.
The first line of the input contains two integers *n* and *m* (2<=≤<=*n*<=≤<=400, 0<=≤<=*m*<=≤<=*n*(*n*<=-<=1)<=/<=2) — the number of towns and the number of railways respectively. Each of the next *m* lines contains two integers *u* and *v*, denoting a railway between towns *u* and *v* (1<=≤<=*u*,<=*v*<=≤<=*n*, *u*<=≠<=*v*). You may assume that there is at most one railway connecting any two towns.
Output one integer — the smallest possible time of the later vehicle's arrival in town *n*. If it's impossible for at least one of the vehicles to reach town *n*, output <=-<=1.
[ "4 2\n1 3\n3 4\n", "4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4\n", "5 5\n4 2\n3 5\n4 5\n5 1\n1 2\n" ]
[ "2\n", "-1\n", "3\n" ]
In the first sample, the train can take the route <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7c0aa60a06309ef607b7159fd7f3687ea0d943ce.png" style="max-width: 100.0%;max-height: 100.0%;"/> and the bus can take the route <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/a26c2f3e93c9d9be6c21cb5d2bd6ac1f99f4ff55.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Note that they can arrive at town 4 at the same time. In the second sample, Absurdistan is ruled by railwaymen. There are no roads, so there's no way for the bus to reach town 4.
500
[ { "input": "4 2\n1 3\n3 4", "output": "2" }, { "input": "4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4", "output": "-1" }, { "input": "5 5\n4 2\n3 5\n4 5\n5 1\n1 2", "output": "3" }, { "input": "5 4\n1 2\n3 2\n3 4\n5 4", "output": "4" }, { "input": "3 1\n1 2", "output": "-1" }, { "input": "2 1\n1 2", "output": "-1" }, { "input": "2 0", "output": "-1" }, { "input": "20 0", "output": "-1" }, { "input": "381 0", "output": "-1" }, { "input": "3 3\n1 2\n2 3\n3 1", "output": "-1" }, { "input": "3 0", "output": "-1" }, { "input": "3 1\n1 3", "output": "2" }, { "input": "3 2\n2 3\n3 1", "output": "-1" }, { "input": "4 1\n1 4", "output": "2" }, { "input": "4 5\n1 3\n2 1\n3 4\n4 2\n2 3", "output": "2" }, { "input": "20 1\n20 1", "output": "2" }, { "input": "21 1\n21 1", "output": "2" }, { "input": "100 1\n100 1", "output": "2" }, { "input": "400 1\n1 400", "output": "2" }, { "input": "5 5\n2 5\n1 2\n1 4\n1 3\n3 2", "output": "2" } ]
1,465,733,930
2,147,483,647
Python 3
OK
TESTS
59
358
5,939,200
n, m = map(int, input().split()) dp = [[0 for i in range(n + 1)] for j in range(n + 1)] level = [-1 for i in range(n + 1)] stack = [] def bfs(src, lvl, flag): level[src] = lvl stack.append(src) p = 0 while True: for i in range(1, n + 1): if dp[src][i] == flag: #print (i, i) if level[i] == -1: # print (i, i) stack.append(i) level[i] = level[src] + 1 if len(stack) <= p + 1: break p += 1 #print (stack) src = stack[p] if src == n: return level[src] break return -1 for i in range(m): a, b = map(int, input().split()) dp[a][b] = 1 dp[b][a] = 1 if dp[1][n]: print (bfs(1, 0, 0)) else: print (bfs(1, 0, 1))
Title: The Two Routes Time Limit: None seconds Memory Limit: None megabytes Problem Description: In Absurdistan, there are *n* towns (numbered 1 through *n*) and *m* bidirectional railways. There is also an absurdly simple road network — for each pair of different towns *x* and *y*, there is a bidirectional road between towns *x* and *y* if and only if there is no railway between them. Travelling to a different town using one railway or one road always takes exactly one hour. A train and a bus leave town 1 at the same time. They both have the same destination, town *n*, and don't make any stops on the way (but they can wait in town *n*). The train can move only along railways and the bus can move only along roads. You've been asked to plan out routes for the vehicles; each route can use any road/railway multiple times. One of the most important aspects to consider is safety — in order to avoid accidents at railway crossings, the train and the bus must not arrive at the same town (except town *n*) simultaneously. Under these constraints, what is the minimum number of hours needed for both vehicles to reach town *n* (the maximum of arrival times of the bus and the train)? Note, that bus and train are not required to arrive to the town *n* at the same moment of time, but are allowed to do so. Input Specification: The first line of the input contains two integers *n* and *m* (2<=≤<=*n*<=≤<=400, 0<=≤<=*m*<=≤<=*n*(*n*<=-<=1)<=/<=2) — the number of towns and the number of railways respectively. Each of the next *m* lines contains two integers *u* and *v*, denoting a railway between towns *u* and *v* (1<=≤<=*u*,<=*v*<=≤<=*n*, *u*<=≠<=*v*). You may assume that there is at most one railway connecting any two towns. Output Specification: Output one integer — the smallest possible time of the later vehicle's arrival in town *n*. If it's impossible for at least one of the vehicles to reach town *n*, output <=-<=1. Demo Input: ['4 2\n1 3\n3 4\n', '4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4\n', '5 5\n4 2\n3 5\n4 5\n5 1\n1 2\n'] Demo Output: ['2\n', '-1\n', '3\n'] Note: In the first sample, the train can take the route <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7c0aa60a06309ef607b7159fd7f3687ea0d943ce.png" style="max-width: 100.0%;max-height: 100.0%;"/> and the bus can take the route <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/a26c2f3e93c9d9be6c21cb5d2bd6ac1f99f4ff55.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Note that they can arrive at town 4 at the same time. In the second sample, Absurdistan is ruled by railwaymen. There are no roads, so there's no way for the bus to reach town 4.
```python n, m = map(int, input().split()) dp = [[0 for i in range(n + 1)] for j in range(n + 1)] level = [-1 for i in range(n + 1)] stack = [] def bfs(src, lvl, flag): level[src] = lvl stack.append(src) p = 0 while True: for i in range(1, n + 1): if dp[src][i] == flag: #print (i, i) if level[i] == -1: # print (i, i) stack.append(i) level[i] = level[src] + 1 if len(stack) <= p + 1: break p += 1 #print (stack) src = stack[p] if src == n: return level[src] break return -1 for i in range(m): a, b = map(int, input().split()) dp[a][b] = 1 dp[b][a] = 1 if dp[1][n]: print (bfs(1, 0, 0)) else: print (bfs(1, 0, 1)) ```
3
696
C
PLEASE
PROGRAMMING
2,000
[ "combinatorics", "dp", "implementation", "math", "matrices" ]
null
null
As we all know Barney's job is "PLEASE" and he has not much to do at work. That's why he started playing "cups and key". In this game there are three identical cups arranged in a line from left to right. Initially key to Barney's heart is under the middle cup. Then at one turn Barney swaps the cup in the middle with any of other two cups randomly (he choses each with equal probability), so the chosen cup becomes the middle one. Game lasts *n* turns and Barney independently choses a cup to swap with the middle one within each turn, and the key always remains in the cup it was at the start. After *n*-th turn Barney asks a girl to guess which cup contains the key. The girl points to the middle one but Barney was distracted while making turns and doesn't know if the key is under the middle cup. That's why he asked you to tell him the probability that girl guessed right. Number *n* of game turns can be extremely large, that's why Barney did not give it to you. Instead he gave you an array *a*1,<=*a*2,<=...,<=*a**k* such that in other words, *n* is multiplication of all elements of the given array. Because of precision difficulties, Barney asked you to tell him the answer as an irreducible fraction. In other words you need to find it as a fraction *p*<=/<=*q* such that , where is the greatest common divisor. Since *p* and *q* can be extremely large, you only need to find the remainders of dividing each of them by 109<=+<=7. Please note that we want of *p* and *q* to be 1, not of their remainders after dividing by 109<=+<=7.
The first line of input contains a single integer *k* (1<=≤<=*k*<=≤<=105) — the number of elements in array Barney gave you. The second line contains *k* integers *a*1,<=*a*2,<=...,<=*a**k* (1<=≤<=*a**i*<=≤<=1018) — the elements of the array.
In the only line of output print a single string *x*<=/<=*y* where *x* is the remainder of dividing *p* by 109<=+<=7 and *y* is the remainder of dividing *q* by 109<=+<=7.
[ "1\n2\n", "3\n1 1 1\n" ]
[ "1/2\n", "0/1\n" ]
none
1,500
[ { "input": "1\n2", "output": "1/2" }, { "input": "3\n1 1 1", "output": "0/1" }, { "input": "1\n983155795040951739", "output": "145599903/436799710" }, { "input": "2\n467131402341701583 956277077729692725", "output": "63467752/190403257" }, { "input": "10\n217673221404542171 806579927281665969 500754531396239406 214319484250163112 328494187336342674 427465830578952934 951554014286436941 664022909283791499 653206814724654845 66704816231807388", "output": "896298678/688896019" }, { "input": "8\n137264686188377169 524477139880847337 939966121107073137 244138018261712937 158070587508987781 35608416591331673 378899027510195451 81986819972451999", "output": "993002178/979006521" }, { "input": "9\n174496219779575399 193634487267697117 972518022554199573 695317701399937273 464007855398119159 881020180696239657 296973121744507377 544232692627163469 751214074246742731", "output": "149736910/449210731" }, { "input": "12\n254904759290707697 475737283258450340 533306428548398547 442127134828578937 779740159015946254 272877594683860919 93000149670491971 349640818793278778 498293278222136720 551099726729989816 149940343283925029 989425634209891686", "output": "674872752/24618241" }, { "input": "1\n1", "output": "0/1" }, { "input": "1\n1000000000000000000", "output": "453246046/359738130" }, { "input": "1\n3", "output": "1/4" }, { "input": "1\n1000000006", "output": "500000004/500000004" }, { "input": "2\n500000004 1000000006", "output": "500000004/500000004" }, { "input": "1\n500000004", "output": "666666672/1" }, { "input": "2\n500000004 500000004", "output": "666666672/1" }, { "input": "1\n500000003", "output": "833333339/500000004" }, { "input": "2\n500000003 500000004", "output": "500000004/500000004" }, { "input": "2\n500000003 500000003", "output": "833333339/500000004" }, { "input": "1\n1000000005", "output": "750000005/250000002" }, { "input": "2\n1000000005 500000004", "output": "416666670/250000002" } ]
1,516,989,657
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
9
1,000
14,643,200
m = 1000000007 input() n, d = 2, 1 for q in map(int, input().split()): d, n = q & d, pow(n, q, m) n = n * pow(2, m - 2, m) % m k = (n + 1 - 2 * d) * pow(3, m - 2, m) % m print(str(k) + '/' + str(n))
Title: PLEASE Time Limit: None seconds Memory Limit: None megabytes Problem Description: As we all know Barney's job is "PLEASE" and he has not much to do at work. That's why he started playing "cups and key". In this game there are three identical cups arranged in a line from left to right. Initially key to Barney's heart is under the middle cup. Then at one turn Barney swaps the cup in the middle with any of other two cups randomly (he choses each with equal probability), so the chosen cup becomes the middle one. Game lasts *n* turns and Barney independently choses a cup to swap with the middle one within each turn, and the key always remains in the cup it was at the start. After *n*-th turn Barney asks a girl to guess which cup contains the key. The girl points to the middle one but Barney was distracted while making turns and doesn't know if the key is under the middle cup. That's why he asked you to tell him the probability that girl guessed right. Number *n* of game turns can be extremely large, that's why Barney did not give it to you. Instead he gave you an array *a*1,<=*a*2,<=...,<=*a**k* such that in other words, *n* is multiplication of all elements of the given array. Because of precision difficulties, Barney asked you to tell him the answer as an irreducible fraction. In other words you need to find it as a fraction *p*<=/<=*q* such that , where is the greatest common divisor. Since *p* and *q* can be extremely large, you only need to find the remainders of dividing each of them by 109<=+<=7. Please note that we want of *p* and *q* to be 1, not of their remainders after dividing by 109<=+<=7. Input Specification: The first line of input contains a single integer *k* (1<=≤<=*k*<=≤<=105) — the number of elements in array Barney gave you. The second line contains *k* integers *a*1,<=*a*2,<=...,<=*a**k* (1<=≤<=*a**i*<=≤<=1018) — the elements of the array. Output Specification: In the only line of output print a single string *x*<=/<=*y* where *x* is the remainder of dividing *p* by 109<=+<=7 and *y* is the remainder of dividing *q* by 109<=+<=7. Demo Input: ['1\n2\n', '3\n1 1 1\n'] Demo Output: ['1/2\n', '0/1\n'] Note: none
```python m = 1000000007 input() n, d = 2, 1 for q in map(int, input().split()): d, n = q & d, pow(n, q, m) n = n * pow(2, m - 2, m) % m k = (n + 1 - 2 * d) * pow(3, m - 2, m) % m print(str(k) + '/' + str(n)) ```
0
429
B
Working out
PROGRAMMING
1,600
[ "dp" ]
null
null
Summer is coming! It's time for Iahub and Iahubina to work out, as they both want to look hot at the beach. The gym where they go is a matrix *a* with *n* lines and *m* columns. Let number *a*[*i*][*j*] represents the calories burned by performing workout at the cell of gym in the *i*-th line and the *j*-th column. Iahub starts with workout located at line 1 and column 1. He needs to finish with workout *a*[*n*][*m*]. After finishing workout *a*[*i*][*j*], he can go to workout *a*[*i*<=+<=1][*j*] or *a*[*i*][*j*<=+<=1]. Similarly, Iahubina starts with workout *a*[*n*][1] and she needs to finish with workout *a*[1][*m*]. After finishing workout from cell *a*[*i*][*j*], she goes to either *a*[*i*][*j*<=+<=1] or *a*[*i*<=-<=1][*j*]. There is one additional condition for their training. They have to meet in exactly one cell of gym. At that cell, none of them will work out. They will talk about fast exponentiation (pretty odd small talk) and then both of them will move to the next workout. If a workout was done by either Iahub or Iahubina, it counts as total gain. Please plan a workout for Iahub and Iahubina such as total gain to be as big as possible. Note, that Iahub and Iahubina can perform workouts with different speed, so the number of cells that they use to reach meet cell may differs.
The first line of the input contains two integers *n* and *m* (3<=≤<=*n*,<=*m*<=≤<=1000). Each of the next *n* lines contains *m* integers: *j*-th number from *i*-th line denotes element *a*[*i*][*j*] (0<=≤<=*a*[*i*][*j*]<=≤<=105).
The output contains a single number — the maximum total gain possible.
[ "3 3\n100 100 100\n100 1 100\n100 100 100\n" ]
[ "800" ]
Iahub will choose exercises *a*[1][1] → *a*[1][2] → *a*[2][2] → *a*[3][2] → *a*[3][3]. Iahubina will choose exercises *a*[3][1] → *a*[2][1] → *a*[2][2] → *a*[2][3] → *a*[1][3].
1,000
[ { "input": "3 3\n100 100 100\n100 1 100\n100 100 100", "output": "800" }, { "input": "4 5\n87882 40786 3691 85313 46694\n28884 16067 3242 97367 78518\n4250 35501 9780 14435 19004\n64673 65438 56977 64495 27280", "output": "747898" }, { "input": "3 3\n3 1 2\n3 2 0\n2 3 2", "output": "16" }, { "input": "3 3\n1 10 1\n1 10 1\n1 10 1", "output": "26" }, { "input": "3 3\n0 0 0\n0 10000 0\n0 0 0", "output": "0" }, { "input": "3 3\n1 1 1\n0 10000 0\n1 1 1", "output": "6" }, { "input": "3 3\n9 0 9\n0 9 9\n9 9 9", "output": "54" }, { "input": "3 3\n0 0 0\n0 100 0\n0 0 0", "output": "0" }, { "input": "3 3\n100000 100000 100000\n1 100000 100000\n1 1 100000", "output": "500003" }, { "input": "3 3\n100 0 100\n1 100 100\n0 100 100", "output": "501" } ]
1,696,722,396
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
1
31
307,200
from copy import deepcopy m, n = map(int, input().split()) grid = [] for _ in range(n): grid.append(list(map(int, input().split()))) matrix1 = deepcopy(grid) matrix2 = deepcopy(grid) matrix3 = deepcopy(grid) matrix4 = deepcopy(grid) for i in range(1, m): matrix1[0][i] += matrix1[0][i-1] for i in range(1, n): matrix1[i][0] += matrix1[i-1][0] for i in range(1, n): for j in range(1, m): matrix1[i][j] += max(matrix1[i-1][j], matrix1[i][j-1]) for i in range(m-2, -1, -1): matrix2[0][i] += matrix2[0][i+1] for i in range(1, n): matrix2[i][m-1] += matrix2[i-1][m-1] for i in range(1, n): for j in range(m-2, -1, -1): matrix2[i][j] += max(matrix2[i-1][j], matrix2[i][j+1]) for i in range(1, m): matrix3[n-1][i] += matrix3[n-1][i-1] for i in range(n-2, -1, -1): matrix3[i][0] += matrix3[i+1][0] for i in range(n-2, -1, -1): for j in range(1, m): matrix3[i][j] += max(matrix3[i+1][j], matrix3[i][j-1]) for i in range(m-2, -1, -1): matrix4[n-1][i] += matrix4[n-1][i+1] for i in range(n-2, -1, -1): matrix4[i][m-1] += matrix4[i+1][m-1] for i in range(n-2, -1, -1): for j in range(m-2, -1, -1): matrix4[i][j] += max(matrix4[i+1][j], matrix4[i][j+1]) global_max = 0 for i in range(1, n-1): for j in range(1, m-1): global_max = max(global_max, matrix1[i-1][j] + matrix4[i+1][j] + matrix3[i][j-1] + matrix2[i][j+1], matrix1[i][j-1] + matrix4[i][j+1] + matrix2[i-1][j] + matrix3[i+1][j]) print(global_max)
Title: Working out Time Limit: None seconds Memory Limit: None megabytes Problem Description: Summer is coming! It's time for Iahub and Iahubina to work out, as they both want to look hot at the beach. The gym where they go is a matrix *a* with *n* lines and *m* columns. Let number *a*[*i*][*j*] represents the calories burned by performing workout at the cell of gym in the *i*-th line and the *j*-th column. Iahub starts with workout located at line 1 and column 1. He needs to finish with workout *a*[*n*][*m*]. After finishing workout *a*[*i*][*j*], he can go to workout *a*[*i*<=+<=1][*j*] or *a*[*i*][*j*<=+<=1]. Similarly, Iahubina starts with workout *a*[*n*][1] and she needs to finish with workout *a*[1][*m*]. After finishing workout from cell *a*[*i*][*j*], she goes to either *a*[*i*][*j*<=+<=1] or *a*[*i*<=-<=1][*j*]. There is one additional condition for their training. They have to meet in exactly one cell of gym. At that cell, none of them will work out. They will talk about fast exponentiation (pretty odd small talk) and then both of them will move to the next workout. If a workout was done by either Iahub or Iahubina, it counts as total gain. Please plan a workout for Iahub and Iahubina such as total gain to be as big as possible. Note, that Iahub and Iahubina can perform workouts with different speed, so the number of cells that they use to reach meet cell may differs. Input Specification: The first line of the input contains two integers *n* and *m* (3<=≤<=*n*,<=*m*<=≤<=1000). Each of the next *n* lines contains *m* integers: *j*-th number from *i*-th line denotes element *a*[*i*][*j*] (0<=≤<=*a*[*i*][*j*]<=≤<=105). Output Specification: The output contains a single number — the maximum total gain possible. Demo Input: ['3 3\n100 100 100\n100 1 100\n100 100 100\n'] Demo Output: ['800'] Note: Iahub will choose exercises *a*[1][1] → *a*[1][2] → *a*[2][2] → *a*[3][2] → *a*[3][3]. Iahubina will choose exercises *a*[3][1] → *a*[2][1] → *a*[2][2] → *a*[2][3] → *a*[1][3].
```python from copy import deepcopy m, n = map(int, input().split()) grid = [] for _ in range(n): grid.append(list(map(int, input().split()))) matrix1 = deepcopy(grid) matrix2 = deepcopy(grid) matrix3 = deepcopy(grid) matrix4 = deepcopy(grid) for i in range(1, m): matrix1[0][i] += matrix1[0][i-1] for i in range(1, n): matrix1[i][0] += matrix1[i-1][0] for i in range(1, n): for j in range(1, m): matrix1[i][j] += max(matrix1[i-1][j], matrix1[i][j-1]) for i in range(m-2, -1, -1): matrix2[0][i] += matrix2[0][i+1] for i in range(1, n): matrix2[i][m-1] += matrix2[i-1][m-1] for i in range(1, n): for j in range(m-2, -1, -1): matrix2[i][j] += max(matrix2[i-1][j], matrix2[i][j+1]) for i in range(1, m): matrix3[n-1][i] += matrix3[n-1][i-1] for i in range(n-2, -1, -1): matrix3[i][0] += matrix3[i+1][0] for i in range(n-2, -1, -1): for j in range(1, m): matrix3[i][j] += max(matrix3[i+1][j], matrix3[i][j-1]) for i in range(m-2, -1, -1): matrix4[n-1][i] += matrix4[n-1][i+1] for i in range(n-2, -1, -1): matrix4[i][m-1] += matrix4[i+1][m-1] for i in range(n-2, -1, -1): for j in range(m-2, -1, -1): matrix4[i][j] += max(matrix4[i+1][j], matrix4[i][j+1]) global_max = 0 for i in range(1, n-1): for j in range(1, m-1): global_max = max(global_max, matrix1[i-1][j] + matrix4[i+1][j] + matrix3[i][j-1] + matrix2[i][j+1], matrix1[i][j-1] + matrix4[i][j+1] + matrix2[i-1][j] + matrix3[i+1][j]) print(global_max) ```
-1
41
A
Translation
PROGRAMMING
800
[ "implementation", "strings" ]
A. Translation
2
256
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the «translation». Vasya translated word *s* from Berlandish into Birlandish as *t*. Help him: find out if he translated the word correctly.
The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols.
If the word *t* is a word *s*, written reversely, print YES, otherwise print NO.
[ "code\nedoc\n", "abb\naba\n", "code\ncode\n" ]
[ "YES\n", "NO\n", "NO\n" ]
none
500
[ { "input": "code\nedoc", "output": "YES" }, { "input": "abb\naba", "output": "NO" }, { "input": "code\ncode", "output": "NO" }, { "input": "abacaba\nabacaba", "output": "YES" }, { "input": "q\nq", "output": "YES" }, { "input": "asrgdfngfnmfgnhweratgjkk\nasrgdfngfnmfgnhweratgjkk", "output": "NO" }, { "input": "z\na", "output": "NO" }, { "input": "asd\ndsa", "output": "YES" }, { "input": "abcdef\nfecdba", "output": "NO" }, { "input": "ywjjbirapvskozubvxoemscfwl\ngnduubaogtfaiowjizlvjcu", "output": "NO" }, { "input": "mfrmqxtzvgaeuleubcmcxcfqyruwzenguhgrmkuhdgnhgtgkdszwqyd\nmfxufheiperjnhyczclkmzyhcxntdfskzkzdwzzujdinf", "output": "NO" }, { "input": "bnbnemvybqizywlnghlykniaxxxlkhftppbdeqpesrtgkcpoeqowjwhrylpsziiwcldodcoonpimudvrxejjo\ntiynnekmlalogyvrgptbinkoqdwzuiyjlrldxhzjmmp", "output": "NO" }, { "input": "pwlpubwyhzqvcitemnhvvwkmwcaawjvdiwtoxyhbhbxerlypelevasmelpfqwjk\nstruuzebbcenziscuoecywugxncdwzyfozhljjyizpqcgkyonyetarcpwkqhuugsqjuixsxptmbnlfupdcfigacdhhrzb", "output": "NO" }, { "input": "gdvqjoyxnkypfvdxssgrihnwxkeojmnpdeobpecytkbdwujqfjtxsqspxvxpqioyfagzjxupqqzpgnpnpxcuipweunqch\nkkqkiwwasbhezqcfeceyngcyuogrkhqecwsyerdniqiocjehrpkljiljophqhyaiefjpavoom", "output": "NO" }, { "input": "umeszdawsvgkjhlqwzents\nhxqhdungbylhnikwviuh", "output": "NO" }, { "input": "juotpscvyfmgntshcealgbsrwwksgrwnrrbyaqqsxdlzhkbugdyx\nibqvffmfktyipgiopznsqtrtxiijntdbgyy", "output": "NO" }, { "input": "zbwueheveouatecaglziqmudxemhrsozmaujrwlqmppzoumxhamwugedikvkblvmxwuofmpafdprbcftew\nulczwrqhctbtbxrhhodwbcxwimncnexosksujlisgclllxokrsbnozthajnnlilyffmsyko", "output": "NO" }, { "input": "nkgwuugukzcv\nqktnpxedwxpxkrxdvgmfgoxkdfpbzvwsduyiybynbkouonhvmzakeiruhfmvrktghadbfkmwxduoqv", "output": "NO" }, { "input": "incenvizhqpcenhjhehvjvgbsnfixbatrrjstxjzhlmdmxijztphxbrldlqwdfimweepkggzcxsrwelodpnryntepioqpvk\ndhjbjjftlvnxibkklxquwmzhjfvnmwpapdrslioxisbyhhfymyiaqhlgecpxamqnocizwxniubrmpyubvpenoukhcobkdojlybxd", "output": "NO" }, { "input": "w\nw", "output": "YES" }, { "input": "vz\nzv", "output": "YES" }, { "input": "ry\nyr", "output": "YES" }, { "input": "xou\nuox", "output": "YES" }, { "input": "axg\ngax", "output": "NO" }, { "input": "zdsl\nlsdz", "output": "YES" }, { "input": "kudl\nldku", "output": "NO" }, { "input": "zzlzwnqlcl\nlclqnwzlzz", "output": "YES" }, { "input": "vzzgicnzqooejpjzads\nsdazjpjeooqzncigzzv", "output": "YES" }, { "input": "raqhmvmzuwaykjpyxsykr\nxkysrypjkyawuzmvmhqar", "output": "NO" }, { "input": "ngedczubzdcqbxksnxuavdjaqtmdwncjnoaicvmodcqvhfezew\nwezefhvqcdomvciaonjcnwdmtqajdvauxnskxbqcdzbuzcdegn", "output": "YES" }, { "input": "muooqttvrrljcxbroizkymuidvfmhhsjtumksdkcbwwpfqdyvxtrlymofendqvznzlmim\nmimlznzvqdnefomylrtxvydqfpwwbckdskmutjshhmfvdiumykziorbxcjlrrvttqooum", "output": "YES" }, { "input": "vxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaivg\ngviayyikkitmuomcpiakhbxszgbnhvwyzkftwoagzixaearxpjacrnvpvbuzenvovehkmmxvblqyxvctroddksdsgebcmlluqpxv", "output": "YES" }, { "input": "mnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfdc\ncdfmkdgrdptkpewbsqvszipgxvgvuiuzbkkwuowbafkikgvnqdkxnayzdjygvezmtsgywnupocdntipiyiorblqkrzjpzatxahnm", "output": "NO" }, { "input": "dgxmzbqofstzcdgthbaewbwocowvhqpinehpjatnnbrijcolvsatbblsrxabzrpszoiecpwhfjmwuhqrapvtcgvikuxtzbftydkw\nwkdytfbztxukivgctvparqhuwmjfhwpceiozsprzbaxrslbbqasvlocjirbnntajphenipthvwocowbweabhtgdcztsfoqbzmxgd", "output": "NO" }, { "input": "gxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwgeh\nhegwxvocotmzstqfbmpjvijgkcyodlxyjawrpkczpmdspsuhoiruavnnnuwvtwohglkdxjetshkboalvzqbgjgthoteceixioxg", "output": "YES" }, { "input": "sihxuwvmaambplxvjfoskinghzicyfqebjtkysotattkahssumfcgrkheotdxwjckpvapbkaepqrxseyfrwtyaycmrzsrsngkh\nhkgnsrszrmcyaytwrfyesxrqpeakbpavpkcjwxdtoehkrgcfmusshakttatosyktjbeqfycizhgniksofjvxlpbmaamvwuxhis", "output": "YES" }, { "input": "ycnahksbughnonldzrhkysujmylcgcfuludjvjiahtkyzqvkopzqcnwhltbzfugzojqkjjlggmvnultascmygelkiktmfieok\nkoeifmtkiklegkmcsatlunvmggkjjlqjozgufzbtlhwncqzpokvqzykthaijvjdulufcgclymjusyyhrzdlnonhgubskhancy", "output": "NO" }, { "input": "wbqasaehtkfojruzyhrlgwmtyiovmzyfifslvlemhqheyaelzwnthrenjsbmntwaoryzwfbxmscmypvxlfmzpnkkjlvwvmtz\nztmvwvljkknpzmflxvpymcsmxbfwzyroawtnmbsjnerhtnwzleayehqhmelvlsfifyzmvoiytmwglrhyzurjofktheasaqbw", "output": "YES" }, { "input": "imippqurprbhfugngtgifelytadegwrgaefnfhbjjnmzikvjaccotqzemufqieqldgnbmviisgkynzeldlhqxuqphjfmyij\njiymfjhpquxqhldleznykgsiivmbngdlqeiqfumezqtoccajvkizmnjjbhfnfeagrwgedatylefigtgngufhbrpruqppimi", "output": "YES" }, { "input": "bikydffiuisckpvzqlteqfhegsagimodb\nbdomigasgehfqetlqzvpkcsiuiffdykib", "output": "YES" } ]
1,656,797,388
2,147,483,647
Python 3
OK
TESTS
40
92
0
s=input() t=input() if (len(s) != len(t)): print("NO") quit() for i in range(len(s)): if s[i] != t[len(s) - i - 1]: print("NO") quit() print("YES")
Title: Translation Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the «translation». Vasya translated word *s* from Berlandish into Birlandish as *t*. Help him: find out if he translated the word correctly. Input Specification: The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols. Output Specification: If the word *t* is a word *s*, written reversely, print YES, otherwise print NO. Demo Input: ['code\nedoc\n', 'abb\naba\n', 'code\ncode\n'] Demo Output: ['YES\n', 'NO\n', 'NO\n'] Note: none
```python s=input() t=input() if (len(s) != len(t)): print("NO") quit() for i in range(len(s)): if s[i] != t[len(s) - i - 1]: print("NO") quit() print("YES") ```
3.977
1,003
A
Polycarp's Pockets
PROGRAMMING
800
[ "implementation" ]
null
null
Polycarp has $n$ coins, the value of the $i$-th coin is $a_i$. Polycarp wants to distribute all the coins between his pockets, but he cannot put two coins with the same value into the same pocket. For example, if Polycarp has got six coins represented as an array $a = [1, 2, 4, 3, 3, 2]$, he can distribute the coins into two pockets as follows: $[1, 2, 3], [2, 3, 4]$. Polycarp wants to distribute all the coins with the minimum number of used pockets. Help him to do that.
The first line of the input contains one integer $n$ ($1 \le n \le 100$) — the number of coins. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$) — values of coins.
Print only one integer — the minimum number of pockets Polycarp needs to distribute all the coins so no two coins with the same value are put into the same pocket.
[ "6\n1 2 4 3 3 2\n", "1\n100\n" ]
[ "2\n", "1\n" ]
none
0
[ { "input": "6\n1 2 4 3 3 2", "output": "2" }, { "input": "1\n100", "output": "1" }, { "input": "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": "100" }, { "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" }, { "input": "100\n59 47 39 47 47 71 47 28 58 47 35 79 58 47 38 47 47 47 47 27 47 43 29 95 47 49 46 71 47 74 79 47 47 32 45 67 47 47 30 37 47 47 16 67 22 76 47 86 84 10 5 47 47 47 47 47 1 51 47 54 47 8 47 47 9 47 47 47 47 28 47 47 26 47 47 47 47 47 47 92 47 47 77 47 47 24 45 47 10 47 47 89 47 27 47 89 47 67 24 71", "output": "51" }, { "input": "100\n45 99 10 27 16 85 39 38 17 32 15 23 67 48 50 97 42 70 62 30 44 81 64 73 34 22 46 5 83 52 58 60 33 74 47 88 18 61 78 53 25 95 94 31 3 75 1 57 20 54 59 9 68 7 77 43 21 87 86 24 4 80 11 49 2 72 36 84 71 8 65 55 79 100 41 14 35 89 66 69 93 37 56 82 90 91 51 19 26 92 6 96 13 98 12 28 76 40 63 29", "output": "1" }, { "input": "100\n45 29 5 2 6 50 22 36 14 15 9 48 46 20 8 37 7 47 12 50 21 38 18 27 33 19 40 10 5 49 38 42 34 37 27 30 35 24 10 3 40 49 41 3 4 44 13 25 28 31 46 36 23 1 1 23 7 22 35 26 21 16 48 42 32 8 11 16 34 11 39 32 47 28 43 41 39 4 14 19 26 45 13 18 15 25 2 44 17 29 17 33 43 6 12 30 9 20 31 24", "output": "2" }, { "input": "50\n7 7 3 3 7 4 5 6 4 3 7 5 6 4 5 4 4 5 6 7 7 7 4 5 5 5 3 7 6 3 4 6 3 6 4 4 5 4 6 6 3 5 6 3 5 3 3 7 7 6", "output": "10" }, { "input": "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 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", "output": "99" }, { "input": "7\n1 2 3 3 3 1 2", "output": "3" }, { "input": "5\n1 2 3 4 5", "output": "1" }, { "input": "7\n1 2 3 4 5 6 7", "output": "1" }, { "input": "8\n1 2 3 4 5 6 7 8", "output": "1" }, { "input": "9\n1 2 3 4 5 6 7 8 9", "output": "1" }, { "input": "10\n1 2 3 4 5 6 7 8 9 10", "output": "1" }, { "input": "3\n2 1 1", "output": "2" }, { "input": "11\n1 2 3 4 5 6 7 8 9 1 1", "output": "3" }, { "input": "12\n1 2 1 1 1 1 1 1 1 1 1 1", "output": "11" }, { "input": "13\n1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "13" }, { "input": "14\n1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "14" }, { "input": "15\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "15" }, { "input": "16\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "16" }, { "input": "3\n1 1 1", "output": "3" }, { "input": "3\n1 2 3", "output": "1" }, { "input": "10\n1 1 1 1 2 2 1 1 9 10", "output": "6" }, { "input": "2\n1 1", "output": "2" }, { "input": "56\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", "output": "56" }, { "input": "99\n35 96 73 72 70 83 22 93 98 75 45 32 81 82 45 54 25 7 53 72 29 2 94 19 21 98 34 28 39 99 55 85 44 23 6 47 98 2 33 34 19 57 49 35 67 4 60 4 4 23 55 6 57 66 16 68 34 45 84 79 48 63 4 9 46 88 98 13 19 27 83 12 4 63 57 22 44 77 44 62 28 52 44 64 9 24 55 22 48 4 2 9 80 76 45 1 56 22 92", "output": "6" }, { "input": "10\n1 2 2 3 3 3 4 4 4 4", "output": "4" }, { "input": "99\n97 44 33 56 42 10 61 85 64 26 40 39 82 34 75 9 51 51 39 73 58 38 74 31 13 99 58 1 28 89 76 19 52 7 40 56 12 27 72 72 67 75 62 46 22 55 35 16 18 39 60 63 92 42 85 69 34 61 73 50 57 95 30 4 45 63 76 58 32 35 48 81 10 78 95 79 55 97 21 21 22 94 30 17 78 57 89 93 100 44 16 89 68 55 19 46 42 73 21", "output": "3" }, { "input": "5\n5 5 5 5 1", "output": "4" }, { "input": "6\n2 3 2 5 2 6", "output": "3" }, { "input": "3\n58 59 58", "output": "2" }, { "input": "9\n1 2 3 4 5 6 7 8 8", "output": "2" }, { "input": "97\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", "output": "97" }, { "input": "3\n95 95 4", "output": "2" }, { "input": "3\n2 2 5", "output": "2" } ]
1,630,663,323
2,147,483,647
Python 3
OK
TESTS
37
62
6,758,400
n = int(input()) array = list(map(int, input().split())) hash_map = {} for x in array: if x not in hash_map: hash_map[x] = 1 else: hash_map[x] += 1 print(max(hash_map.values()))
Title: Polycarp's Pockets Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarp has $n$ coins, the value of the $i$-th coin is $a_i$. Polycarp wants to distribute all the coins between his pockets, but he cannot put two coins with the same value into the same pocket. For example, if Polycarp has got six coins represented as an array $a = [1, 2, 4, 3, 3, 2]$, he can distribute the coins into two pockets as follows: $[1, 2, 3], [2, 3, 4]$. Polycarp wants to distribute all the coins with the minimum number of used pockets. Help him to do that. Input Specification: The first line of the input contains one integer $n$ ($1 \le n \le 100$) — the number of coins. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$) — values of coins. Output Specification: Print only one integer — the minimum number of pockets Polycarp needs to distribute all the coins so no two coins with the same value are put into the same pocket. Demo Input: ['6\n1 2 4 3 3 2\n', '1\n100\n'] Demo Output: ['2\n', '1\n'] Note: none
```python n = int(input()) array = list(map(int, input().split())) hash_map = {} for x in array: if x not in hash_map: hash_map[x] = 1 else: hash_map[x] += 1 print(max(hash_map.values())) ```
3
868
C
Qualification Rounds
PROGRAMMING
1,500
[ "bitmasks", "brute force", "constructive algorithms", "dp" ]
null
null
Snark and Philip are preparing the problemset for the upcoming pre-qualification round for semi-quarter-finals. They have a bank of *n* problems, and they want to select any non-empty subset of it as a problemset. *k* experienced teams are participating in the contest. Some of these teams already know some of the problems. To make the contest interesting for them, each of the teams should know at most half of the selected problems. Determine if Snark and Philip can make an interesting problemset!
The first line contains two integers *n*, *k* (1<=≤<=*n*<=≤<=105, 1<=≤<=*k*<=≤<=4) — the number of problems and the number of experienced teams. Each of the next *n* lines contains *k* integers, each equal to 0 or 1. The *j*-th number in the *i*-th line is 1 if *j*-th team knows *i*-th problem and 0 otherwise.
Print "YES" (quotes for clarity), if it is possible to make an interesting problemset, and "NO" otherwise. You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES").
[ "5 3\n1 0 1\n1 1 0\n1 0 0\n1 0 0\n1 0 0\n", "3 2\n1 0\n1 1\n0 1\n" ]
[ "NO\n", "YES\n" ]
In the first example you can't make any interesting problemset, because the first team knows all problems. In the second example you can choose the first and the third problems.
1,000
[ { "input": "5 3\n1 0 1\n1 1 0\n1 0 0\n1 0 0\n1 0 0", "output": "NO" }, { "input": "3 2\n1 0\n1 1\n0 1", "output": "YES" }, { "input": "10 2\n1 0\n1 0\n0 0\n1 1\n0 0\n1 1\n0 0\n1 1\n0 1\n0 1", "output": "YES" }, { "input": "10 3\n1 0 0\n0 1 1\n1 0 0\n0 1 0\n0 0 1\n1 0 1\n0 1 1\n1 0 0\n1 1 0\n0 0 0", "output": "YES" }, { "input": "10 4\n1 0 1 0\n1 0 0 1\n1 1 0 1\n1 0 1 1\n1 1 0 1\n1 0 1 0\n0 0 0 0\n0 0 1 0\n1 0 1 0\n0 0 1 1", "output": "YES" }, { "input": "2 2\n0 0\n1 0", "output": "YES" }, { "input": "3 3\n1 0 1\n1 0 0\n1 1 1", "output": "NO" }, { "input": "4 4\n0 0 0 0\n1 1 0 0\n1 1 1 1\n1 0 1 1", "output": "YES" }, { "input": "4 1\n1\n1\n0\n0", "output": "YES" }, { "input": "1 4\n0 0 0 0", "output": "YES" }, { "input": "3 3\n0 0 1\n0 1 1\n1 0 0", "output": "YES" }, { "input": "2 3\n0 0 1\n1 0 0", "output": "YES" }, { "input": "1 1\n0", "output": "YES" }, { "input": "2 4\n0 1 1 1\n1 0 0 0", "output": "YES" }, { "input": "2 4\n1 0 1 0\n0 1 0 1", "output": "YES" }, { "input": "2 4\n1 0 0 0\n0 0 0 1", "output": "YES" }, { "input": "2 3\n0 1 0\n0 0 1", "output": "YES" }, { "input": "3 4\n1 0 1 0\n0 1 0 1\n1 1 1 1", "output": "YES" }, { "input": "3 4\n0 0 1 1\n1 1 1 0\n1 1 0 1", "output": "NO" }, { "input": "4 4\n0 0 0 1\n0 0 0 1\n0 0 1 0\n0 0 1 0", "output": "YES" }, { "input": "2 4\n1 1 0 0\n0 0 1 1", "output": "YES" }, { "input": "2 4\n1 0 0 0\n0 1 0 0", "output": "YES" }, { "input": "2 3\n1 0 0\n0 0 1", "output": "YES" }, { "input": "3 4\n1 0 1 0\n0 1 1 1\n1 0 0 0", "output": "YES" }, { "input": "1 2\n0 0", "output": "YES" }, { "input": "6 3\n0 1 1\n1 0 1\n1 1 1\n0 1 0\n1 0 1\n1 1 0", "output": "YES" }, { "input": "1 4\n0 0 1 1", "output": "NO" }, { "input": "3 3\n1 0 0\n0 1 0\n0 0 1", "output": "YES" }, { "input": "3 4\n1 0 0 0\n1 1 0 0\n0 1 1 1", "output": "YES" }, { "input": "3 2\n0 0\n0 0\n0 0", "output": "YES" }, { "input": "2 4\n1 0 0 0\n1 0 1 1", "output": "NO" }, { "input": "2 4\n0 0 0 1\n1 0 0 0", "output": "YES" }, { "input": "2 4\n1 0 0 0\n0 1 1 1", "output": "YES" }, { "input": "4 4\n1 1 1 1\n0 0 0 1\n0 0 1 1\n1 0 1 1", "output": "NO" }, { "input": "6 3\n1 0 0\n1 1 1\n1 1 1\n0 1 0\n0 1 0\n1 0 0", "output": "YES" }, { "input": "4 4\n0 1 0 0\n1 1 1 1\n1 1 1 1\n1 0 1 1", "output": "YES" }, { "input": "1 3\n0 0 0", "output": "YES" }, { "input": "3 3\n1 0 0\n0 1 0\n0 0 0", "output": "YES" }, { "input": "2 4\n0 1 1 0\n0 0 0 0", "output": "YES" }, { "input": "1 4\n0 0 0 1", "output": "NO" }, { "input": "4 4\n0 0 0 1\n0 0 0 1\n0 0 1 1\n1 1 1 0", "output": "YES" }, { "input": "2 3\n1 0 0\n0 1 1", "output": "YES" }, { "input": "3 2\n0 1\n0 1\n1 0", "output": "YES" }, { "input": "4 3\n1 1 0\n1 1 1\n0 0 1\n0 0 1", "output": "YES" }, { "input": "2 1\n0\n0", "output": "YES" }, { "input": "2 4\n1 1 1 0\n0 0 0 1", "output": "YES" }, { "input": "5 4\n1 1 1 0\n1 1 0 1\n1 0 1 1\n0 1 1 1\n1 1 0 0", "output": "NO" }, { "input": "3 4\n0 1 1 0\n0 1 0 1\n0 0 1 1", "output": "NO" }, { "input": "1 1\n1", "output": "NO" }, { "input": "3 4\n1 0 0 0\n1 0 0 0\n0 1 1 1", "output": "YES" }, { "input": "2 3\n1 1 0\n0 0 1", "output": "YES" }, { "input": "3 3\n0 0 1\n1 1 1\n1 1 0", "output": "YES" }, { "input": "4 4\n0 1 1 1\n1 0 1 0\n1 1 0 1\n1 0 1 0", "output": "NO" }, { "input": "3 3\n1 0 0\n0 0 0\n1 0 0", "output": "YES" }, { "input": "3 4\n1 1 0 0\n1 1 0 0\n0 0 1 1", "output": "YES" }, { "input": "2 4\n1 0 0 1\n0 0 1 0", "output": "YES" }, { "input": "2 4\n0 0 1 1\n1 1 0 0", "output": "YES" }, { "input": "2 3\n0 0 1\n0 1 0", "output": "YES" }, { "input": "2 3\n1 0 0\n0 1 0", "output": "YES" }, { "input": "3 2\n1 0\n0 1\n0 1", "output": "YES" }, { "input": "3 4\n1 1 0 1\n0 0 1 1\n1 0 1 0", "output": "NO" }, { "input": "3 4\n0 0 1 1\n0 1 1 0\n1 1 0 0", "output": "YES" }, { "input": "3 4\n0 0 0 1\n0 0 0 1\n1 1 1 0", "output": "YES" }, { "input": "3 4\n1 1 1 0\n1 1 0 1\n0 0 1 0", "output": "YES" }, { "input": "8 4\n0 0 0 1\n0 0 1 1\n0 0 1 1\n0 0 1 1\n0 0 1 1\n0 0 1 1\n0 0 1 1\n1 1 1 0", "output": "YES" }, { "input": "3 4\n1 0 1 1\n1 1 1 0\n0 1 0 1", "output": "NO" }, { "input": "2 4\n1 1 0 0\n0 0 0 1", "output": "YES" }, { "input": "10 4\n1 0 1 0\n1 0 1 0\n0 1 1 1\n1 0 1 1\n1 1 0 1\n1 0 0 1\n0 1 1 1\n0 0 0 1\n1 1 1 1\n1 0 1 0", "output": "YES" }, { "input": "2 4\n0 1 0 0\n0 0 1 1", "output": "YES" }, { "input": "3 3\n1 1 0\n1 0 1\n0 1 1", "output": "NO" }, { "input": "3 3\n1 1 0\n0 0 1\n1 1 1", "output": "YES" }, { "input": "4 4\n1 1 0 0\n1 0 1 0\n0 1 1 0\n0 0 1 1", "output": "YES" }, { "input": "4 4\n1 0 0 0\n1 0 0 1\n1 0 0 1\n0 1 1 1", "output": "YES" }, { "input": "4 3\n1 0 0\n1 0 0\n1 0 0\n0 1 1", "output": "YES" }, { "input": "2 4\n0 0 1 0\n0 1 0 0", "output": "YES" }, { "input": "1 2\n0 1", "output": "NO" }, { "input": "3 4\n1 1 1 0\n0 0 1 1\n1 1 0 0", "output": "YES" }, { "input": "3 4\n0 0 1 1\n0 1 0 1\n1 0 1 0", "output": "YES" }, { "input": "2 3\n1 0 1\n0 1 0", "output": "YES" }, { "input": "2 4\n0 0 0 0\n0 0 0 0", "output": "YES" }, { "input": "3 4\n0 1 0 1\n0 1 1 0\n1 0 0 1", "output": "YES" }, { "input": "3 4\n0 1 1 0\n1 1 0 0\n0 0 1 1", "output": "YES" }, { "input": "2 4\n1 0 1 0\n0 0 0 1", "output": "YES" }, { "input": "2 3\n0 1 0\n1 0 0", "output": "YES" }, { "input": "4 4\n0 0 1 1\n0 1 1 0\n1 1 0 0\n1 0 0 1", "output": "YES" }, { "input": "10 4\n0 0 1 1\n0 0 1 1\n0 0 1 1\n0 0 1 1\n0 0 1 1\n0 0 1 1\n0 0 1 1\n0 0 1 1\n0 0 1 1\n1 1 0 0", "output": "YES" }, { "input": "3 3\n1 1 0\n0 1 1\n1 0 1", "output": "NO" }, { "input": "2 3\n0 0 1\n1 1 0", "output": "YES" }, { "input": "4 4\n0 0 0 1\n0 0 1 1\n1 1 0 1\n1 1 1 0", "output": "YES" }, { "input": "3 4\n0 0 1 1\n1 0 1 0\n0 1 0 1", "output": "YES" }, { "input": "5 4\n1 1 1 0\n1 1 0 1\n1 0 1 1\n0 1 1 1\n0 0 1 1", "output": "NO" }, { "input": "3 4\n1 0 0 0\n1 1 0 0\n0 1 1 0", "output": "YES" } ]
1,582,078,777
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
2
140
0
n,k = list(map(int, input().strip().split())) # creating a mapping array array = [0]*(2**k) for _ in range(n): t = int(''.join(input().strip().split()), 2) array[t] += 1 # now creating a compatibility array comp = [[] for i in range(2**k)] for i in range(2**k): for j in range(2**k): if i&j == 0: comp[i].append(j) # now doing the math flag = False for i in range(1, 2**k): if flag: break if array[i] > 0: for j in comp[i]: if array[j] > 0: print('YES') flag = True if not flag: print('NO')
Title: Qualification Rounds Time Limit: None seconds Memory Limit: None megabytes Problem Description: Snark and Philip are preparing the problemset for the upcoming pre-qualification round for semi-quarter-finals. They have a bank of *n* problems, and they want to select any non-empty subset of it as a problemset. *k* experienced teams are participating in the contest. Some of these teams already know some of the problems. To make the contest interesting for them, each of the teams should know at most half of the selected problems. Determine if Snark and Philip can make an interesting problemset! Input Specification: The first line contains two integers *n*, *k* (1<=≤<=*n*<=≤<=105, 1<=≤<=*k*<=≤<=4) — the number of problems and the number of experienced teams. Each of the next *n* lines contains *k* integers, each equal to 0 or 1. The *j*-th number in the *i*-th line is 1 if *j*-th team knows *i*-th problem and 0 otherwise. Output Specification: Print "YES" (quotes for clarity), if it is possible to make an interesting problemset, and "NO" otherwise. You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES"). Demo Input: ['5 3\n1 0 1\n1 1 0\n1 0 0\n1 0 0\n1 0 0\n', '3 2\n1 0\n1 1\n0 1\n'] Demo Output: ['NO\n', 'YES\n'] Note: In the first example you can't make any interesting problemset, because the first team knows all problems. In the second example you can choose the first and the third problems.
```python n,k = list(map(int, input().strip().split())) # creating a mapping array array = [0]*(2**k) for _ in range(n): t = int(''.join(input().strip().split()), 2) array[t] += 1 # now creating a compatibility array comp = [[] for i in range(2**k)] for i in range(2**k): for j in range(2**k): if i&j == 0: comp[i].append(j) # now doing the math flag = False for i in range(1, 2**k): if flag: break if array[i] > 0: for j in comp[i]: if array[j] > 0: print('YES') flag = True if not flag: print('NO') ```
0
41
A
Translation
PROGRAMMING
800
[ "implementation", "strings" ]
A. Translation
2
256
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the «translation». Vasya translated word *s* from Berlandish into Birlandish as *t*. Help him: find out if he translated the word correctly.
The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols.
If the word *t* is a word *s*, written reversely, print YES, otherwise print NO.
[ "code\nedoc\n", "abb\naba\n", "code\ncode\n" ]
[ "YES\n", "NO\n", "NO\n" ]
none
500
[ { "input": "code\nedoc", "output": "YES" }, { "input": "abb\naba", "output": "NO" }, { "input": "code\ncode", "output": "NO" }, { "input": "abacaba\nabacaba", "output": "YES" }, { "input": "q\nq", "output": "YES" }, { "input": "asrgdfngfnmfgnhweratgjkk\nasrgdfngfnmfgnhweratgjkk", "output": "NO" }, { "input": "z\na", "output": "NO" }, { "input": "asd\ndsa", "output": "YES" }, { "input": "abcdef\nfecdba", "output": "NO" }, { "input": "ywjjbirapvskozubvxoemscfwl\ngnduubaogtfaiowjizlvjcu", "output": "NO" }, { "input": "mfrmqxtzvgaeuleubcmcxcfqyruwzenguhgrmkuhdgnhgtgkdszwqyd\nmfxufheiperjnhyczclkmzyhcxntdfskzkzdwzzujdinf", "output": "NO" }, { "input": "bnbnemvybqizywlnghlykniaxxxlkhftppbdeqpesrtgkcpoeqowjwhrylpsziiwcldodcoonpimudvrxejjo\ntiynnekmlalogyvrgptbinkoqdwzuiyjlrldxhzjmmp", "output": "NO" }, { "input": "pwlpubwyhzqvcitemnhvvwkmwcaawjvdiwtoxyhbhbxerlypelevasmelpfqwjk\nstruuzebbcenziscuoecywugxncdwzyfozhljjyizpqcgkyonyetarcpwkqhuugsqjuixsxptmbnlfupdcfigacdhhrzb", "output": "NO" }, { "input": "gdvqjoyxnkypfvdxssgrihnwxkeojmnpdeobpecytkbdwujqfjtxsqspxvxpqioyfagzjxupqqzpgnpnpxcuipweunqch\nkkqkiwwasbhezqcfeceyngcyuogrkhqecwsyerdniqiocjehrpkljiljophqhyaiefjpavoom", "output": "NO" }, { "input": "umeszdawsvgkjhlqwzents\nhxqhdungbylhnikwviuh", "output": "NO" }, { "input": "juotpscvyfmgntshcealgbsrwwksgrwnrrbyaqqsxdlzhkbugdyx\nibqvffmfktyipgiopznsqtrtxiijntdbgyy", "output": "NO" }, { "input": "zbwueheveouatecaglziqmudxemhrsozmaujrwlqmppzoumxhamwugedikvkblvmxwuofmpafdprbcftew\nulczwrqhctbtbxrhhodwbcxwimncnexosksujlisgclllxokrsbnozthajnnlilyffmsyko", "output": "NO" }, { "input": "nkgwuugukzcv\nqktnpxedwxpxkrxdvgmfgoxkdfpbzvwsduyiybynbkouonhvmzakeiruhfmvrktghadbfkmwxduoqv", "output": "NO" }, { "input": "incenvizhqpcenhjhehvjvgbsnfixbatrrjstxjzhlmdmxijztphxbrldlqwdfimweepkggzcxsrwelodpnryntepioqpvk\ndhjbjjftlvnxibkklxquwmzhjfvnmwpapdrslioxisbyhhfymyiaqhlgecpxamqnocizwxniubrmpyubvpenoukhcobkdojlybxd", "output": "NO" }, { "input": "w\nw", "output": "YES" }, { "input": "vz\nzv", "output": "YES" }, { "input": "ry\nyr", "output": "YES" }, { "input": "xou\nuox", "output": "YES" }, { "input": "axg\ngax", "output": "NO" }, { "input": "zdsl\nlsdz", "output": "YES" }, { "input": "kudl\nldku", "output": "NO" }, { "input": "zzlzwnqlcl\nlclqnwzlzz", "output": "YES" }, { "input": "vzzgicnzqooejpjzads\nsdazjpjeooqzncigzzv", "output": "YES" }, { "input": "raqhmvmzuwaykjpyxsykr\nxkysrypjkyawuzmvmhqar", "output": "NO" }, { "input": "ngedczubzdcqbxksnxuavdjaqtmdwncjnoaicvmodcqvhfezew\nwezefhvqcdomvciaonjcnwdmtqajdvauxnskxbqcdzbuzcdegn", "output": "YES" }, { "input": "muooqttvrrljcxbroizkymuidvfmhhsjtumksdkcbwwpfqdyvxtrlymofendqvznzlmim\nmimlznzvqdnefomylrtxvydqfpwwbckdskmutjshhmfvdiumykziorbxcjlrrvttqooum", "output": "YES" }, { "input": "vxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaivg\ngviayyikkitmuomcpiakhbxszgbnhvwyzkftwoagzixaearxpjacrnvpvbuzenvovehkmmxvblqyxvctroddksdsgebcmlluqpxv", "output": "YES" }, { "input": "mnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfdc\ncdfmkdgrdptkpewbsqvszipgxvgvuiuzbkkwuowbafkikgvnqdkxnayzdjygvezmtsgywnupocdntipiyiorblqkrzjpzatxahnm", "output": "NO" }, { "input": "dgxmzbqofstzcdgthbaewbwocowvhqpinehpjatnnbrijcolvsatbblsrxabzrpszoiecpwhfjmwuhqrapvtcgvikuxtzbftydkw\nwkdytfbztxukivgctvparqhuwmjfhwpceiozsprzbaxrslbbqasvlocjirbnntajphenipthvwocowbweabhtgdcztsfoqbzmxgd", "output": "NO" }, { "input": "gxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwgeh\nhegwxvocotmzstqfbmpjvijgkcyodlxyjawrpkczpmdspsuhoiruavnnnuwvtwohglkdxjetshkboalvzqbgjgthoteceixioxg", "output": "YES" }, { "input": "sihxuwvmaambplxvjfoskinghzicyfqebjtkysotattkahssumfcgrkheotdxwjckpvapbkaepqrxseyfrwtyaycmrzsrsngkh\nhkgnsrszrmcyaytwrfyesxrqpeakbpavpkcjwxdtoehkrgcfmusshakttatosyktjbeqfycizhgniksofjvxlpbmaamvwuxhis", "output": "YES" }, { "input": "ycnahksbughnonldzrhkysujmylcgcfuludjvjiahtkyzqvkopzqcnwhltbzfugzojqkjjlggmvnultascmygelkiktmfieok\nkoeifmtkiklegkmcsatlunvmggkjjlqjozgufzbtlhwncqzpokvqzykthaijvjdulufcgclymjusyyhrzdlnonhgubskhancy", "output": "NO" }, { "input": "wbqasaehtkfojruzyhrlgwmtyiovmzyfifslvlemhqheyaelzwnthrenjsbmntwaoryzwfbxmscmypvxlfmzpnkkjlvwvmtz\nztmvwvljkknpzmflxvpymcsmxbfwzyroawtnmbsjnerhtnwzleayehqhmelvlsfifyzmvoiytmwglrhyzurjofktheasaqbw", "output": "YES" }, { "input": "imippqurprbhfugngtgifelytadegwrgaefnfhbjjnmzikvjaccotqzemufqieqldgnbmviisgkynzeldlhqxuqphjfmyij\njiymfjhpquxqhldleznykgsiivmbngdlqeiqfumezqtoccajvkizmnjjbhfnfeagrwgedatylefigtgngufhbrpruqppimi", "output": "YES" }, { "input": "bikydffiuisckpvzqlteqfhegsagimodb\nbdomigasgehfqetlqzvpkcsiuiffdykib", "output": "YES" } ]
1,688,378,335
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
60
0
t=input() x=input() z=t[::-1] if(x==z): print("yes") else: print("no")
Title: Translation Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the «translation». Vasya translated word *s* from Berlandish into Birlandish as *t*. Help him: find out if he translated the word correctly. Input Specification: The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols. Output Specification: If the word *t* is a word *s*, written reversely, print YES, otherwise print NO. Demo Input: ['code\nedoc\n', 'abb\naba\n', 'code\ncode\n'] Demo Output: ['YES\n', 'NO\n', 'NO\n'] Note: none
```python t=input() x=input() z=t[::-1] if(x==z): print("yes") else: print("no") ```
0
381
A
Sereja and Dima
PROGRAMMING
800
[ "greedy", "implementation", "two pointers" ]
null
null
Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. The game ends when there is no more cards. The player who has the maximum sum of numbers on his cards by the end of the game, wins. Sereja and Dima are being greedy. Each of them chooses the card with the larger number during his move. Inna is a friend of Sereja and Dima. She knows which strategy the guys are using, so she wants to determine the final score, given the initial state of the game. Help her.
The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000.
On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game.
[ "4\n4 1 2 10\n", "7\n1 2 3 4 5 6 7\n" ]
[ "12 5\n", "16 12\n" ]
In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5.
500
[ { "input": "4\n4 1 2 10", "output": "12 5" }, { "input": "7\n1 2 3 4 5 6 7", "output": "16 12" }, { "input": "42\n15 29 37 22 16 5 26 31 6 32 19 3 45 36 33 14 25 20 48 7 42 11 24 28 9 18 8 21 47 17 38 40 44 4 35 1 43 39 41 27 12 13", "output": "613 418" }, { "input": "43\n32 1 15 48 38 26 25 14 20 44 11 30 3 42 49 19 18 46 5 45 10 23 34 9 29 41 2 52 6 17 35 4 50 22 33 51 7 28 47 13 39 37 24", "output": "644 500" }, { "input": "1\n3", "output": "3 0" }, { "input": "45\n553 40 94 225 415 471 126 190 647 394 515 303 189 159 308 6 139 132 326 78 455 75 85 295 135 613 360 614 351 228 578 259 258 591 444 29 33 463 561 174 368 183 140 168 646", "output": "6848 6568" }, { "input": "44\n849 373 112 307 479 608 856 769 526 82 168 143 573 762 115 501 688 36 214 450 396 496 236 309 287 786 397 43 811 141 745 846 350 270 276 677 420 459 403 722 267 54 394 727", "output": "9562 9561" }, { "input": "35\n10 15 18 1 28 16 2 33 6 22 23 4 9 25 35 8 7 26 3 20 30 14 31 19 27 32 11 5 29 24 21 34 13 17 12", "output": "315 315" }, { "input": "17\n580 376 191 496 73 44 520 357 483 149 81 178 514 300 216 598 304", "output": "3238 2222" }, { "input": "30\n334 443 223 424 168 549 189 303 429 559 516 220 459 134 344 346 316 446 209 148 487 526 69 286 102 366 518 280 392 325", "output": "5246 4864" }, { "input": "95\n122 29 188 265 292 287 183 225 222 187 155 256 64 148 173 278 218 136 290 17 31 130 2 87 57 283 255 280 68 166 174 142 102 39 116 206 288 154 26 78 296 172 184 232 77 91 277 8 249 186 94 93 207 251 257 195 101 299 193 124 293 65 58 35 24 302 220 189 252 125 27 284 247 182 141 103 198 97 234 83 281 216 85 180 267 236 109 143 149 239 79 300 191 244 71", "output": "8147 7807" }, { "input": "1\n1", "output": "1 0" } ]
1,674,643,025
2,147,483,647
Python 3
OK
TESTS
34
46
0
cards=int(input()) nums=[int(x) for x in input().split()] s,d,=0,0 l,r=0,cards-1 state='s' while(l<=r): if state=='s': if nums[l]>nums[r]: s+=nums[l] l+=1 else: s+=nums[r] r-=1 state='d' else: if nums[l]>nums[r]: d+=nums[l] l+=1 else: d+=nums[r] r-=1 state='s' print(f"{s} {d}")
Title: Sereja and Dima Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. The game ends when there is no more cards. The player who has the maximum sum of numbers on his cards by the end of the game, wins. Sereja and Dima are being greedy. Each of them chooses the card with the larger number during his move. Inna is a friend of Sereja and Dima. She knows which strategy the guys are using, so she wants to determine the final score, given the initial state of the game. Help her. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000. Output Specification: On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game. Demo Input: ['4\n4 1 2 10\n', '7\n1 2 3 4 5 6 7\n'] Demo Output: ['12 5\n', '16 12\n'] Note: In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5.
```python cards=int(input()) nums=[int(x) for x in input().split()] s,d,=0,0 l,r=0,cards-1 state='s' while(l<=r): if state=='s': if nums[l]>nums[r]: s+=nums[l] l+=1 else: s+=nums[r] r-=1 state='d' else: if nums[l]>nums[r]: d+=nums[l] l+=1 else: d+=nums[r] r-=1 state='s' print(f"{s} {d}") ```
3
265
A
Colorful Stones (Simplified Edition)
PROGRAMMING
800
[ "implementation" ]
null
null
There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th stone. If the character is "R", "G", or "B", the color of the corresponding stone is red, green, or blue, respectively. Initially Squirrel Liss is standing on the first stone. You perform instructions one or more times. Each instruction is one of the three types: "RED", "GREEN", or "BLUE". After an instruction *c*, if Liss is standing on a stone whose colors is *c*, Liss will move one stone forward, else she will not move. You are given a string *t*. The number of instructions is equal to the length of *t*, and the *i*-th character of *t* represents the *i*-th instruction. Calculate the final position of Liss (the number of the stone she is going to stand on in the end) after performing all the instructions, and print its 1-based position. It is guaranteed that Liss don't move out of the sequence.
The input contains two lines. The first line contains the string *s* (1<=≤<=|*s*|<=≤<=50). The second line contains the string *t* (1<=≤<=|*t*|<=≤<=50). The characters of each string will be one of "R", "G", or "B". It is guaranteed that Liss don't move out of the sequence.
Print the final 1-based position of Liss in a single line.
[ "RGB\nRRR\n", "RRRBGBRBBB\nBBBRR\n", "BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB\n" ]
[ "2\n", "3\n", "15\n" ]
none
500
[ { "input": "RGB\nRRR", "output": "2" }, { "input": "RRRBGBRBBB\nBBBRR", "output": "3" }, { "input": "BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB", "output": "15" }, { "input": "G\nRRBBRBRRBR", "output": "1" }, { "input": "RRRRRBRRBRRGRBGGRRRGRBBRBBBBBRGRBGBRRGBBBRBBGBRGBB\nB", "output": "1" }, { "input": "RRGGBRGRBG\nBRRGGBBGGR", "output": "7" }, { "input": "BBRRGBGGRGBRGBRBRBGR\nGGGRBGGGBRRRRGRBGBGRGRRBGRBGBG", "output": "15" }, { "input": "GBRRBGBGBBBBRRRGBGRRRGBGBBBRGR\nRRGBRRGRBBBBBBGRRBBR", "output": "8" }, { "input": "BRGRRGRGRRGBBGBBBRRBBRRBGBBGRGBBGGRGBRBGGGRRRBGGBB\nRGBBGRRBBBRRGRRBRBBRGBBGGGRGBGRRRRBRBGGBRBGGGRGBRR", "output": "16" }, { "input": "GGRGGBRRGRGBRRGGRBBGGRRGBBBGBBBGGRBGGBRBBRGBRRRBRG\nGGRGRRRRRRRRRGBBBBRGBRGRGRRGBBRGGBRBBRBGBRGRRRRGGR", "output": "18" }, { "input": "RBBRBGBBGGGBRRBGBRGRRGGRBBBBGRBGGBRRBGBBRBRGBBGGGG\nBRRGRBGRBGBRGBRBGGBBBGBBRGRBGRGRBGRBGGRRBGBRGRRBBG", "output": "23" }, { "input": "RRGGRRBRGRGBRGBRGBBRGGGBRBGBRGBRGGBRBRGBGRRBBGGRBR\nBRGRBBBGRBGRRGGRRRRRRRRGGGGGGGGBGGGGGGGRGRBBRGRGBR", "output": "14" }, { "input": "RBRBRRRRRGGR\nBBBBRRGGBGRBRGBBRGGGRGGBRRBRBRBGGG", "output": "12" }, { "input": "GGRGGGBRGRGRBBRGGGRBGRRR\nGBBBBGBGBGBBBRGGRGGBGRRGRRRGBGB", "output": "12" }, { "input": "RGRBGBRBBGBRRGGGBBGBRRBGRGBBBBBGRRRGGRBB\nBGR", "output": "2" }, { "input": "R\nB", "output": "1" }, { "input": "RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR\nRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR", "output": "50" }, { "input": "RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR\nGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG", "output": "1" }, { "input": "R\nGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG", "output": "1" } ]
1,687,186,181
2,147,483,647
Python 3
OK
TESTS
19
92
0
s = input() t = input() position = 1 for instruction in t: if instruction == s[position - 1]: position += 1 print(position)
Title: Colorful Stones (Simplified Edition) Time Limit: None seconds Memory Limit: None megabytes Problem Description: There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th stone. If the character is "R", "G", or "B", the color of the corresponding stone is red, green, or blue, respectively. Initially Squirrel Liss is standing on the first stone. You perform instructions one or more times. Each instruction is one of the three types: "RED", "GREEN", or "BLUE". After an instruction *c*, if Liss is standing on a stone whose colors is *c*, Liss will move one stone forward, else she will not move. You are given a string *t*. The number of instructions is equal to the length of *t*, and the *i*-th character of *t* represents the *i*-th instruction. Calculate the final position of Liss (the number of the stone she is going to stand on in the end) after performing all the instructions, and print its 1-based position. It is guaranteed that Liss don't move out of the sequence. Input Specification: The input contains two lines. The first line contains the string *s* (1<=≤<=|*s*|<=≤<=50). The second line contains the string *t* (1<=≤<=|*t*|<=≤<=50). The characters of each string will be one of "R", "G", or "B". It is guaranteed that Liss don't move out of the sequence. Output Specification: Print the final 1-based position of Liss in a single line. Demo Input: ['RGB\nRRR\n', 'RRRBGBRBBB\nBBBRR\n', 'BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB\n'] Demo Output: ['2\n', '3\n', '15\n'] Note: none
```python s = input() t = input() position = 1 for instruction in t: if instruction == s[position - 1]: position += 1 print(position) ```
3
58
A
Chat room
PROGRAMMING
1,000
[ "greedy", "strings" ]
A. Chat room
1
256
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*.
The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.
If Vasya managed to say hello, print "YES", otherwise print "NO".
[ "ahhellllloou\n", "hlelo\n" ]
[ "YES\n", "NO\n" ]
none
500
[ { "input": "ahhellllloou", "output": "YES" }, { "input": "hlelo", "output": "NO" }, { "input": "helhcludoo", "output": "YES" }, { "input": "hehwelloho", "output": "YES" }, { "input": "pnnepelqomhhheollvlo", "output": "YES" }, { "input": "tymbzjyqhymedasloqbq", "output": "NO" }, { "input": "yehluhlkwo", "output": "NO" }, { "input": "hatlevhhalrohairnolsvocafgueelrqmlqlleello", "output": "YES" }, { "input": "hhhtehdbllnhwmbyhvelqqyoulretpbfokflhlhreeflxeftelziclrwllrpflflbdtotvlqgoaoqldlroovbfsq", "output": "YES" }, { "input": "rzlvihhghnelqtwlexmvdjjrliqllolhyewgozkuovaiezgcilelqapuoeglnwmnlftxxiigzczlouooi", "output": "YES" }, { "input": "pfhhwctyqdlkrwhebfqfelhyebwllhemtrmeblgrynmvyhioesqklclocxmlffuormljszllpoo", "output": "YES" }, { "input": "lqllcolohwflhfhlnaow", "output": "NO" }, { "input": "heheeellollvoo", "output": "YES" }, { "input": "hellooo", "output": "YES" }, { "input": "o", "output": "NO" }, { "input": "hhqhzeclohlehljlhtesllylrolmomvuhcxsobtsckogdv", "output": "YES" }, { "input": "yoegfuzhqsihygnhpnukluutocvvwuldiighpogsifealtgkfzqbwtmgghmythcxflebrkctlldlkzlagovwlstsghbouk", "output": "YES" }, { "input": "uatqtgbvrnywfacwursctpagasnhydvmlinrcnqrry", "output": "NO" }, { "input": "tndtbldbllnrwmbyhvqaqqyoudrstpbfokfoclnraefuxtftmgzicorwisrpfnfpbdtatvwqgyalqtdtrjqvbfsq", "output": "NO" }, { "input": "rzlvirhgemelnzdawzpaoqtxmqucnahvqnwldklrmjiiyageraijfivigvozgwngiulttxxgzczptusoi", "output": "YES" }, { "input": "kgyelmchocojsnaqdsyeqgnllytbqietpdlgknwwumqkxrexgdcnwoldicwzwofpmuesjuxzrasscvyuqwspm", "output": "YES" }, { "input": "pnyvrcotjvgynbeldnxieghfltmexttuxzyac", "output": "NO" }, { "input": "dtwhbqoumejligbenxvzhjlhosqojetcqsynlzyhfaevbdpekgbtjrbhlltbceobcok", "output": "YES" }, { "input": "crrfpfftjwhhikwzeedrlwzblckkteseofjuxjrktcjfsylmlsvogvrcxbxtffujqshslemnixoeezivksouefeqlhhokwbqjz", "output": "YES" }, { "input": "jhfbndhyzdvhbvhmhmefqllujdflwdpjbehedlsqfdsqlyelwjtyloxwsvasrbqosblzbowlqjmyeilcvotdlaouxhdpoeloaovb", "output": "YES" }, { "input": "hwlghueoemiqtjhhpashjsouyegdlvoyzeunlroypoprnhlyiwiuxrghekaylndhrhllllwhbebezoglydcvykllotrlaqtvmlla", "output": "YES" }, { "input": "wshiaunnqnqxodholbipwhhjmyeblhgpeleblklpzwhdunmpqkbuzloetmwwxmeltkrcomulxauzlwmlklldjodozxryghsnwgcz", "output": "YES" }, { "input": "shvksednttggehroewuiptvvxtrzgidravtnjwuqrlnnkxbplctzkckinpkgjopjfoxdbojtcvsuvablcbkrzajrlhgobkcxeqti", "output": "YES" }, { "input": "hyyhddqhxhekehkwfhlnlsihzefwchzerevcjtokefplholrbvxlltdlafjxrfhleglrvlolojoqaolagtbeyogxlbgfolllslli", "output": "YES" }, { "input": "iaagrdhhelxpdegueiulflquvlzidoprzkehthkldaytrjwhyhprwjxlltinxvuilxohqgjqcvkkdcuoliekcnlilwgqlnlzouoo", "output": "YES" }, { "input": "wfluaeseldgxyvxpwuhkptdmlflnlhktwxiabsvkolsquymrmhzczzoybvlilhmvsuunggvgxzgyyffk", "output": "NO" }, { "input": "loee", "output": "NO" }, { "input": "izdipwylefqmjbuoznfglgcfvedeouflkeehxbasaqmiooppfsqlhprospqgxvzrcpwlfdddngoqvpwvggsnvvxhmjoslwjudjlo", "output": "NO" }, { "input": "pplynflbjlseflaegzqpdxswgunhnlglqhycrbcwdfhclmcrwekkzsoosmfblljeenwfjyifcvxihhhbyhmhlkvtskeglaovjnsi", "output": "YES" }, { "input": "xqjqmenkodmlhzyzmmvofdngktygbbxbzpluzcohohmalkoeuwfikblltaaigv", "output": "NO" }, { "input": "hello", "output": "YES" }, { "input": "oohell", "output": "NO" }, { "input": "hell", "output": "NO" }, { "input": "eloellohoelo", "output": "NO" }, { "input": "helllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllo", "output": "YES" } ]
1,681,557,844
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
1
77
0
s = list(input()) say='ello' l=[s.index('h')] s=s[s.index('h'):] for i in say: if i not in s: print('NO') break else: a=s.index(i) l.append(a) s[a]=0 else: print('YES') if l != sorted(l): print('NO')
Title: Chat room Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*. Input Specification: The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. Output Specification: If Vasya managed to say hello, print "YES", otherwise print "NO". Demo Input: ['ahhellllloou\n', 'hlelo\n'] Demo Output: ['YES\n', 'NO\n'] Note: none
```python s = list(input()) say='ello' l=[s.index('h')] s=s[s.index('h'):] for i in say: if i not in s: print('NO') break else: a=s.index(i) l.append(a) s[a]=0 else: print('YES') if l != sorted(l): print('NO') ```
0
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,695,902,941
2,147,483,647
Python 3
OK
TESTS
32
92
0
n=int(input()) arr=[int(x) for x in input().split()] even=0 not_even=0 last_even=-1 last_not_even=-1 index=0 for i in range(0,len(arr)): if arr[i]%2==0: even+=1 last_even=i+1 else: not_even+=1 last_not_even=i+1 if even>1 and last_not_even!=-1: index=last_not_even break elif not_even>1 and last_even!=-1: index=last_even break print(index)
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()) arr=[int(x) for x in input().split()] even=0 not_even=0 last_even=-1 last_not_even=-1 index=0 for i in range(0,len(arr)): if arr[i]%2==0: even+=1 last_even=i+1 else: not_even+=1 last_not_even=i+1 if even>1 and last_not_even!=-1: index=last_not_even break elif not_even>1 and last_even!=-1: index=last_even break print(index) ```
3.977
799
A
Carrot Cakes
PROGRAMMING
1,100
[ "brute force", "implementation" ]
null
null
In some game by Playrix it takes *t* minutes for an oven to bake *k* carrot cakes, all cakes are ready at the same moment *t* minutes after they started baking. Arkady needs at least *n* cakes to complete a task, but he currently don't have any. However, he has infinitely many ingredients and one oven. Moreover, Arkady can build one more similar oven to make the process faster, it would take *d* minutes to build the oven. While the new oven is being built, only old one can bake cakes, after the new oven is built, both ovens bake simultaneously. Arkady can't build more than one oven. Determine if it is reasonable to build the second oven, i.e. will it decrease the minimum time needed to get *n* cakes or not. If the time needed with the second oven is the same as with one oven, then it is unreasonable.
The only line contains four integers *n*, *t*, *k*, *d* (1<=≤<=*n*,<=*t*,<=*k*,<=*d*<=≤<=1<=000) — the number of cakes needed, the time needed for one oven to bake *k* cakes, the number of cakes baked at the same time, the time needed to build the second oven.
If it is reasonable to build the second oven, print "YES". Otherwise print "NO".
[ "8 6 4 5\n", "8 6 4 6\n", "10 3 11 4\n", "4 2 1 4\n" ]
[ "YES\n", "NO\n", "NO\n", "YES\n" ]
In the first example it is possible to get 8 cakes in 12 minutes using one oven. The second oven can be built in 5 minutes, so after 6 minutes the first oven bakes 4 cakes, the second oven bakes 4 more ovens after 11 minutes. Thus, it is reasonable to build the second oven. In the second example it doesn't matter whether we build the second oven or not, thus it takes 12 minutes to bake 8 cakes in both cases. Thus, it is unreasonable to build the second oven. In the third example the first oven bakes 11 cakes in 3 minutes, that is more than needed 10. It is unreasonable to build the second oven, because its building takes more time that baking the needed number of cakes using the only oven.
500
[ { "input": "8 6 4 5", "output": "YES" }, { "input": "8 6 4 6", "output": "NO" }, { "input": "10 3 11 4", "output": "NO" }, { "input": "4 2 1 4", "output": "YES" }, { "input": "28 17 16 26", "output": "NO" }, { "input": "60 69 9 438", "output": "NO" }, { "input": "599 97 54 992", "output": "YES" }, { "input": "11 22 18 17", "output": "NO" }, { "input": "1 13 22 11", "output": "NO" }, { "input": "1 1 1 1", "output": "NO" }, { "input": "3 1 1 1", "output": "YES" }, { "input": "1000 1000 1000 1000", "output": "NO" }, { "input": "1000 1000 1 1", "output": "YES" }, { "input": "1000 1000 1 400", "output": "YES" }, { "input": "1000 1000 1 1000", "output": "YES" }, { "input": "1000 1000 1 999", "output": "YES" }, { "input": "53 11 3 166", "output": "YES" }, { "input": "313 2 3 385", "output": "NO" }, { "input": "214 9 9 412", "output": "NO" }, { "input": "349 9 5 268", "output": "YES" }, { "input": "611 16 8 153", "output": "YES" }, { "input": "877 13 3 191", "output": "YES" }, { "input": "340 9 9 10", "output": "YES" }, { "input": "31 8 2 205", "output": "NO" }, { "input": "519 3 2 148", "output": "YES" }, { "input": "882 2 21 219", "output": "NO" }, { "input": "982 13 5 198", "output": "YES" }, { "input": "428 13 6 272", "output": "YES" }, { "input": "436 16 14 26", "output": "YES" }, { "input": "628 10 9 386", "output": "YES" }, { "input": "77 33 18 31", "output": "YES" }, { "input": "527 36 4 8", "output": "YES" }, { "input": "128 18 2 169", "output": "YES" }, { "input": "904 4 2 288", "output": "YES" }, { "input": "986 4 3 25", "output": "YES" }, { "input": "134 8 22 162", "output": "NO" }, { "input": "942 42 3 69", "output": "YES" }, { "input": "894 4 9 4", "output": "YES" }, { "input": "953 8 10 312", "output": "YES" }, { "input": "43 8 1 121", "output": "YES" }, { "input": "12 13 19 273", "output": "NO" }, { "input": "204 45 10 871", "output": "YES" }, { "input": "342 69 50 425", "output": "NO" }, { "input": "982 93 99 875", "output": "NO" }, { "input": "283 21 39 132", "output": "YES" }, { "input": "1000 45 83 686", "output": "NO" }, { "input": "246 69 36 432", "output": "NO" }, { "input": "607 93 76 689", "output": "NO" }, { "input": "503 21 24 435", "output": "NO" }, { "input": "1000 45 65 989", "output": "NO" }, { "input": "30 21 2 250", "output": "YES" }, { "input": "1000 49 50 995", "output": "NO" }, { "input": "383 69 95 253", "output": "YES" }, { "input": "393 98 35 999", "output": "YES" }, { "input": "1000 22 79 552", "output": "NO" }, { "input": "268 294 268 154", "output": "NO" }, { "input": "963 465 706 146", "output": "YES" }, { "input": "304 635 304 257", "output": "NO" }, { "input": "4 2 1 6", "output": "NO" }, { "input": "1 51 10 50", "output": "NO" }, { "input": "5 5 4 4", "output": "YES" }, { "input": "3 2 1 1", "output": "YES" }, { "input": "3 4 3 3", "output": "NO" }, { "input": "7 3 4 1", "output": "YES" }, { "input": "101 10 1 1000", "output": "NO" }, { "input": "5 1 1 1", "output": "YES" }, { "input": "5 10 5 5", "output": "NO" }, { "input": "19 1 7 1", "output": "YES" }, { "input": "763 572 745 262", "output": "YES" }, { "input": "1 2 1 1", "output": "NO" }, { "input": "5 1 1 3", "output": "YES" }, { "input": "170 725 479 359", "output": "NO" }, { "input": "6 2 1 7", "output": "YES" }, { "input": "6 2 5 1", "output": "YES" }, { "input": "1 2 2 1", "output": "NO" }, { "input": "24 2 8 3", "output": "YES" }, { "input": "7 3 3 3", "output": "YES" }, { "input": "5 2 2 2", "output": "YES" }, { "input": "3 2 1 2", "output": "YES" }, { "input": "1000 2 200 8", "output": "NO" }, { "input": "3 100 2 100", "output": "NO" }, { "input": "2 999 1 1000", "output": "NO" }, { "input": "2 1 1 1", "output": "NO" }, { "input": "2 3 5 1", "output": "NO" }, { "input": "100 1 5 1", "output": "YES" }, { "input": "7 2 3 3", "output": "YES" }, { "input": "4 1 1 3", "output": "NO" }, { "input": "3 2 2 1", "output": "YES" }, { "input": "1 1 1 2", "output": "NO" }, { "input": "91 8 7 13", "output": "YES" }, { "input": "3 1 2 1", "output": "NO" }, { "input": "5 3 2 3", "output": "YES" }, { "input": "9 6 6 3", "output": "YES" } ]
1,664,859,881
2,147,483,647
PyPy 3-64
OK
TESTS
93
62
1,638,400
from math import ceil n, t, k, d = list(map(int, input().split())) first = ceil(n/k)*t second = 0 z = 0 c = 0 while d!=0 and second*k<n: z+=1 d-=1 if z == t: second+=1 z = 0 c+=1 else: x = 0 while second*k<n: z+=1 x+=1 if z == t: second+=1 z = 0 if x == t: second+=1 x = 0 c+=1 print("YES" if c<first else "NO")
Title: Carrot Cakes Time Limit: None seconds Memory Limit: None megabytes Problem Description: In some game by Playrix it takes *t* minutes for an oven to bake *k* carrot cakes, all cakes are ready at the same moment *t* minutes after they started baking. Arkady needs at least *n* cakes to complete a task, but he currently don't have any. However, he has infinitely many ingredients and one oven. Moreover, Arkady can build one more similar oven to make the process faster, it would take *d* minutes to build the oven. While the new oven is being built, only old one can bake cakes, after the new oven is built, both ovens bake simultaneously. Arkady can't build more than one oven. Determine if it is reasonable to build the second oven, i.e. will it decrease the minimum time needed to get *n* cakes or not. If the time needed with the second oven is the same as with one oven, then it is unreasonable. Input Specification: The only line contains four integers *n*, *t*, *k*, *d* (1<=≤<=*n*,<=*t*,<=*k*,<=*d*<=≤<=1<=000) — the number of cakes needed, the time needed for one oven to bake *k* cakes, the number of cakes baked at the same time, the time needed to build the second oven. Output Specification: If it is reasonable to build the second oven, print "YES". Otherwise print "NO". Demo Input: ['8 6 4 5\n', '8 6 4 6\n', '10 3 11 4\n', '4 2 1 4\n'] Demo Output: ['YES\n', 'NO\n', 'NO\n', 'YES\n'] Note: In the first example it is possible to get 8 cakes in 12 minutes using one oven. The second oven can be built in 5 minutes, so after 6 minutes the first oven bakes 4 cakes, the second oven bakes 4 more ovens after 11 minutes. Thus, it is reasonable to build the second oven. In the second example it doesn't matter whether we build the second oven or not, thus it takes 12 minutes to bake 8 cakes in both cases. Thus, it is unreasonable to build the second oven. In the third example the first oven bakes 11 cakes in 3 minutes, that is more than needed 10. It is unreasonable to build the second oven, because its building takes more time that baking the needed number of cakes using the only oven.
```python from math import ceil n, t, k, d = list(map(int, input().split())) first = ceil(n/k)*t second = 0 z = 0 c = 0 while d!=0 and second*k<n: z+=1 d-=1 if z == t: second+=1 z = 0 c+=1 else: x = 0 while second*k<n: z+=1 x+=1 if z == t: second+=1 z = 0 if x == t: second+=1 x = 0 c+=1 print("YES" if c<first else "NO") ```
3
24
A
Ring road
PROGRAMMING
1,400
[ "graphs" ]
A. Ring road
2
256
Nowadays the one-way traffic is introduced all over the world in order to improve driving safety and reduce traffic jams. The government of Berland decided to keep up with new trends. Formerly all *n* cities of Berland were connected by *n* two-way roads in the ring, i. e. each city was connected directly to exactly two other cities, and from each city it was possible to get to any other city. Government of Berland introduced one-way traffic on all *n* roads, but it soon became clear that it's impossible to get from some of the cities to some others. Now for each road is known in which direction the traffic is directed at it, and the cost of redirecting the traffic. What is the smallest amount of money the government should spend on the redirecting of roads so that from every city you can get to any other?
The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of cities (and roads) in Berland. Next *n* lines contain description of roads. Each road is described by three integers *a**i*, *b**i*, *c**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=*a**i*<=≠<=*b**i*,<=1<=≤<=*c**i*<=≤<=100) — road is directed from city *a**i* to city *b**i*, redirecting the traffic costs *c**i*.
Output single integer — the smallest amount of money the government should spend on the redirecting of roads so that from every city you can get to any other.
[ "3\n1 3 1\n1 2 1\n3 2 1\n", "3\n1 3 1\n1 2 5\n3 2 1\n", "6\n1 5 4\n5 3 8\n2 4 15\n1 6 16\n2 3 23\n4 6 42\n", "4\n1 2 9\n2 3 8\n3 4 7\n4 1 5\n" ]
[ "1\n", "2\n", "39\n", "0\n" ]
none
0
[ { "input": "3\n1 3 1\n1 2 1\n3 2 1", "output": "1" }, { "input": "3\n1 3 1\n1 2 5\n3 2 1", "output": "2" }, { "input": "6\n1 5 4\n5 3 8\n2 4 15\n1 6 16\n2 3 23\n4 6 42", "output": "39" }, { "input": "4\n1 2 9\n2 3 8\n3 4 7\n4 1 5", "output": "0" }, { "input": "5\n5 3 89\n2 3 43\n4 2 50\n1 4 69\n1 5 54", "output": "143" }, { "input": "10\n1 8 16\n6 1 80\n6 5 27\n5 7 86\n7 9 72\n4 9 20\n4 3 54\n3 2 57\n10 2 61\n8 10 90", "output": "267" }, { "input": "17\n8 12 43\n13 12 70\n7 13 68\n11 7 19\n5 11 24\n5 1 100\n4 1 10\n3 4 68\n2 3 46\n15 2 58\n15 6 38\n6 9 91\n9 10 72\n14 10 32\n14 17 97\n17 16 67\n8 16 40", "output": "435" }, { "input": "22\n18 22 46\n18 21 87\n5 21 17\n5 10 82\n10 12 81\n17 12 98\n16 17 17\n16 13 93\n4 13 64\n4 11 65\n15 11 18\n6 15 35\n6 7 61\n7 19 12\n19 1 65\n8 1 32\n8 2 46\n9 2 19\n9 3 58\n3 14 65\n20 14 67\n20 22 2", "output": "413" }, { "input": "39\n18 11 10\n5 18 97\n5 39 77\n39 24 64\n24 28 79\n28 14 6\n34 14 72\n6 34 64\n6 12 93\n12 8 66\n13 8 40\n35 13 20\n35 32 4\n32 19 55\n19 3 18\n3 21 26\n30 21 54\n30 27 5\n4 27 8\n22 4 89\n15 22 54\n15 2 90\n36 2 58\n33 36 4\n33 17 50\n17 16 21\n31 16 64\n1 31 77\n1 23 89\n23 7 62\n38 7 74\n9 38 15\n9 25 93\n25 10 32\n10 26 78\n20 26 63\n37 20 9\n29 37 33\n11 29 45", "output": "950" }, { "input": "50\n30 34 48\n11 30 15\n11 5 98\n4 5 57\n43 4 21\n14 43 74\n14 19 52\n45 19 60\n45 28 52\n24 28 94\n24 26 2\n48 26 48\n48 13 53\n13 42 7\n42 37 23\n37 17 70\n17 7 29\n20 7 93\n33 20 21\n33 2 53\n21 2 83\n49 21 33\n46 49 28\n18 46 1\n36 18 99\n47 36 52\n47 29 41\n41 29 40\n31 41 45\n31 38 25\n38 25 41\n25 8 18\n9 8 60\n9 27 29\n16 27 17\n16 22 6\n22 39 1\n1 39 8\n1 50 89\n50 12 64\n40 12 7\n40 44 71\n44 10 23\n15 10 70\n15 32 53\n23 32 92\n35 23 14\n35 3 25\n3 6 93\n6 34 99", "output": "1117" }, { "input": "3\n3 1 1\n2 1 1\n2 3 1", "output": "1" } ]
1,616,705,154
2,147,483,647
PyPy 3
OK
TESTS
21
186
1,536,000
n=int(input()) a=[] for i in range(n): a.append(list(map(int,input().split()))) i=0 b=[] c=0 for k in range(n): b.append(a[i][c]) for j in range(n): if i!=j and a[i][1-c] in a[j][:2]: if a[i][1-c]==a[j][0]: c=0 else: c=1 i=j break b+=[b[0]] c1,c2=0,0 for i in range(1,n+1): for j in range(n): if a[j][:2]==[b[i],b[i-1]]: c1+=a[j][2] elif a[j][:2]==[b[i-1],b[i]]: c2+=a[j][2] print(min(c1,c2))
Title: Ring road Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Nowadays the one-way traffic is introduced all over the world in order to improve driving safety and reduce traffic jams. The government of Berland decided to keep up with new trends. Formerly all *n* cities of Berland were connected by *n* two-way roads in the ring, i. e. each city was connected directly to exactly two other cities, and from each city it was possible to get to any other city. Government of Berland introduced one-way traffic on all *n* roads, but it soon became clear that it's impossible to get from some of the cities to some others. Now for each road is known in which direction the traffic is directed at it, and the cost of redirecting the traffic. What is the smallest amount of money the government should spend on the redirecting of roads so that from every city you can get to any other? Input Specification: The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of cities (and roads) in Berland. Next *n* lines contain description of roads. Each road is described by three integers *a**i*, *b**i*, *c**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=*a**i*<=≠<=*b**i*,<=1<=≤<=*c**i*<=≤<=100) — road is directed from city *a**i* to city *b**i*, redirecting the traffic costs *c**i*. Output Specification: Output single integer — the smallest amount of money the government should spend on the redirecting of roads so that from every city you can get to any other. Demo Input: ['3\n1 3 1\n1 2 1\n3 2 1\n', '3\n1 3 1\n1 2 5\n3 2 1\n', '6\n1 5 4\n5 3 8\n2 4 15\n1 6 16\n2 3 23\n4 6 42\n', '4\n1 2 9\n2 3 8\n3 4 7\n4 1 5\n'] Demo Output: ['1\n', '2\n', '39\n', '0\n'] Note: none
```python n=int(input()) a=[] for i in range(n): a.append(list(map(int,input().split()))) i=0 b=[] c=0 for k in range(n): b.append(a[i][c]) for j in range(n): if i!=j and a[i][1-c] in a[j][:2]: if a[i][1-c]==a[j][0]: c=0 else: c=1 i=j break b+=[b[0]] c1,c2=0,0 for i in range(1,n+1): for j in range(n): if a[j][:2]==[b[i],b[i-1]]: c1+=a[j][2] elif a[j][:2]==[b[i-1],b[i]]: c2+=a[j][2] print(min(c1,c2)) ```
3.950639
300
A
Array
PROGRAMMING
1,100
[ "brute force", "constructive algorithms", "implementation" ]
null
null
Vitaly has an array of *n* distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold: 1. The product of all numbers in the first set is less than zero (<=&lt;<=0). 1. The product of all numbers in the second set is greater than zero (<=&gt;<=0). 1. The product of all numbers in the third set is equal to zero. 1. Each number from the initial array must occur in exactly one set. Help Vitaly. Divide the given array.
The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=100). The second line contains *n* space-separated distinct integers *a*1,<=*a*2,<=...,<=*a**n* (|*a**i*|<=≤<=103) — the array elements.
In the first line print integer *n*1 (*n*1<=&gt;<=0) — the number of elements in the first set. Then print *n*1 numbers — the elements that got to the first set. In the next line print integer *n*2 (*n*2<=&gt;<=0) — the number of elements in the second set. Then print *n*2 numbers — the elements that got to the second set. In the next line print integer *n*3 (*n*3<=&gt;<=0) — the number of elements in the third set. Then print *n*3 numbers — the elements that got to the third set. The printed sets must meet the described conditions. It is guaranteed that the solution exists. If there are several solutions, you are allowed to print any of them.
[ "3\n-1 2 0\n", "4\n-1 -2 -3 0\n" ]
[ "1 -1\n1 2\n1 0\n", "1 -1\n2 -3 -2\n1 0\n" ]
none
500
[ { "input": "3\n-1 2 0", "output": "1 -1\n1 2\n1 0" }, { "input": "4\n-1 -2 -3 0", "output": "1 -1\n2 -3 -2\n1 0" }, { "input": "5\n-1 -2 1 2 0", "output": "1 -1\n2 1 2\n2 0 -2" }, { "input": "100\n-64 -51 -75 -98 74 -26 -1 -8 -99 -76 -53 -80 -43 -22 -100 -62 -34 -5 -65 -81 -18 -91 -92 -16 -23 -95 -9 -19 -44 -46 -79 52 -35 4 -87 -7 -90 -20 -71 -61 -67 -50 -66 -68 -49 -27 -32 -57 -85 -59 -30 -36 -3 -77 86 -25 -94 -56 60 -24 -37 -72 -41 -31 11 -48 28 -38 -42 -39 -33 -70 -84 0 -93 -73 -14 -69 -40 -97 -6 -55 -45 -54 -10 -29 -96 -12 -83 -15 -21 -47 17 -2 -63 -89 88 13 -58 -82", "output": "89 -64 -51 -75 -98 -26 -1 -8 -99 -76 -53 -80 -43 -22 -100 -62 -34 -5 -65 -81 -18 -91 -92 -16 -23 -95 -9 -19 -44 -46 -79 -35 -87 -7 -90 -20 -71 -61 -67 -50 -66 -68 -49 -27 -32 -57 -85 -59 -30 -36 -3 -77 -25 -94 -56 -24 -37 -72 -41 -31 -48 -38 -42 -39 -33 -70 -84 -93 -73 -14 -69 -40 -97 -6 -55 -45 -54 -10 -29 -96 -12 -83 -15 -21 -47 -2 -63 -89 -58 -82\n10 74 52 4 86 60 11 28 17 88 13\n1 0" }, { "input": "100\n3 -66 -17 54 24 -29 76 89 32 -37 93 -16 99 -25 51 78 23 68 -95 59 18 34 -45 77 9 39 -10 19 8 73 -5 60 12 31 0 2 26 40 48 30 52 49 27 4 87 57 85 58 -61 50 83 80 69 67 91 97 -96 11 100 56 82 53 13 -92 -72 70 1 -94 -63 47 21 14 74 7 6 33 55 65 64 -41 81 42 36 28 38 20 43 71 90 -88 22 84 -86 15 75 62 44 35 98 46", "output": "19 -66 -17 -29 -37 -16 -25 -95 -45 -10 -5 -61 -96 -92 -72 -94 -63 -41 -88 -86\n80 3 54 24 76 89 32 93 99 51 78 23 68 59 18 34 77 9 39 19 8 73 60 12 31 2 26 40 48 30 52 49 27 4 87 57 85 58 50 83 80 69 67 91 97 11 100 56 82 53 13 70 1 47 21 14 74 7 6 33 55 65 64 81 42 36 28 38 20 43 71 90 22 84 15 75 62 44 35 98 46\n1 0" }, { "input": "100\n-17 16 -70 32 -60 75 -100 -9 -68 -30 -42 86 -88 -98 -47 -5 58 -14 -94 -73 -80 -51 -66 -85 -53 49 -25 -3 -45 -69 -11 -64 83 74 -65 67 13 -91 81 6 -90 -54 -12 -39 0 -24 -71 -41 -44 57 -93 -20 -92 18 -43 -52 -55 -84 -89 -19 40 -4 -99 -26 -87 -36 -56 -61 -62 37 -95 -28 63 23 35 -82 1 -2 -78 -96 -21 -77 -76 -27 -10 -97 -8 46 -15 -48 -34 -59 -7 -29 50 -33 -72 -79 22 38", "output": "75 -17 -70 -60 -100 -9 -68 -30 -42 -88 -98 -47 -5 -14 -94 -73 -80 -51 -66 -85 -53 -25 -3 -45 -69 -11 -64 -65 -91 -90 -54 -12 -39 -24 -71 -41 -44 -93 -20 -92 -43 -52 -55 -84 -89 -19 -4 -99 -26 -87 -36 -56 -61 -62 -95 -28 -82 -2 -78 -96 -21 -77 -76 -27 -10 -97 -8 -15 -48 -34 -59 -7 -29 -33 -72 -79\n24 16 32 75 86 58 49 83 74 67 13 81 6 57 18 40 37 63 23 35 1 46 50 22 38\n1 0" }, { "input": "100\n-97 -90 61 78 87 -52 -3 65 83 38 30 -60 35 -50 -73 -77 44 -32 -81 17 -67 58 -6 -34 47 -28 71 -45 69 -80 -4 -7 -57 -79 43 -27 -31 29 16 -89 -21 -93 95 -82 74 -5 -70 -20 -18 36 -64 -66 72 53 62 -68 26 15 76 -40 -99 8 59 88 49 -23 9 10 56 -48 -98 0 100 -54 25 94 13 -63 42 39 -1 55 24 -12 75 51 41 84 -96 -85 -2 -92 14 -46 -91 -19 -11 -86 22 -37", "output": "51 -97 -90 -52 -3 -60 -50 -73 -77 -32 -81 -67 -6 -34 -28 -45 -80 -4 -7 -57 -79 -27 -31 -89 -21 -93 -82 -5 -70 -20 -18 -64 -66 -68 -40 -99 -23 -48 -98 -54 -63 -1 -12 -96 -85 -2 -92 -46 -91 -19 -11 -86\n47 61 78 87 65 83 38 30 35 44 17 58 47 71 69 43 29 16 95 74 36 72 53 62 26 15 76 8 59 88 49 9 10 56 100 25 94 13 42 39 55 24 75 51 41 84 14 22\n2 0 -37" }, { "input": "100\n-75 -60 -18 -92 -71 -9 -37 -34 -82 28 -54 93 -83 -76 -58 -88 -17 -97 64 -39 -96 -81 -10 -98 -47 -100 -22 27 14 -33 -19 -99 87 -66 57 -21 -90 -70 -32 -26 24 -77 -74 13 -44 16 -5 -55 -2 -6 -7 -73 -1 -68 -30 -95 -42 69 0 -20 -79 59 -48 -4 -72 -67 -46 62 51 -52 -86 -40 56 -53 85 -35 -8 49 50 65 29 11 -43 -15 -41 -12 -3 -80 -31 -38 -91 -45 -25 78 94 -23 -63 84 89 -61", "output": "73 -75 -60 -18 -92 -71 -9 -37 -34 -82 -54 -83 -76 -58 -88 -17 -97 -39 -96 -81 -10 -98 -47 -100 -22 -33 -19 -99 -66 -21 -90 -70 -32 -26 -77 -74 -44 -5 -55 -2 -6 -7 -73 -1 -68 -30 -95 -42 -20 -79 -48 -4 -72 -67 -46 -52 -86 -40 -53 -35 -8 -43 -15 -41 -12 -3 -80 -31 -38 -91 -45 -25 -23 -63\n25 28 93 64 27 14 87 57 24 13 16 69 59 62 51 56 85 49 50 65 29 11 78 94 84 89\n2 0 -61" }, { "input": "100\n-87 -48 -76 -1 -10 -17 -22 -19 -27 -99 -43 49 38 -20 -45 -64 44 -96 -35 -74 -65 -41 -21 -75 37 -12 -67 0 -3 5 -80 -93 -81 -97 -47 -63 53 -100 95 -79 -83 -90 -32 88 -77 -16 -23 -54 -28 -4 -73 -98 -25 -39 60 -56 -34 -2 -11 -55 -52 -69 -68 -29 -82 -62 -36 -13 -6 -89 8 -72 18 -15 -50 -71 -70 -92 -42 -78 -61 -9 -30 -85 -91 -94 84 -86 -7 -57 -14 40 -33 51 -26 46 59 -31 -58 -66", "output": "83 -87 -48 -76 -1 -10 -17 -22 -19 -27 -99 -43 -20 -45 -64 -96 -35 -74 -65 -41 -21 -75 -12 -67 -3 -80 -93 -81 -97 -47 -63 -100 -79 -83 -90 -32 -77 -16 -23 -54 -28 -4 -73 -98 -25 -39 -56 -34 -2 -11 -55 -52 -69 -68 -29 -82 -62 -36 -13 -6 -89 -72 -15 -50 -71 -70 -92 -42 -78 -61 -9 -30 -85 -91 -94 -86 -7 -57 -14 -33 -26 -31 -58 -66\n16 49 38 44 37 5 53 95 88 60 8 18 84 40 51 46 59\n1 0" }, { "input": "100\n-95 -28 -43 -72 -11 -24 -37 -35 -44 -66 -45 -62 -96 -51 -55 -23 -31 -26 -59 -17 77 -69 -10 -12 -78 -14 -52 -57 -40 -75 4 -98 -6 7 -53 -3 -90 -63 -8 -20 88 -91 -32 -76 -80 -97 -34 -27 -19 0 70 -38 -9 -49 -67 73 -36 2 81 -39 -65 -83 -64 -18 -94 -79 -58 -16 87 -22 -74 -25 -13 -46 -89 -47 5 -15 -54 -99 56 -30 -60 -21 -86 33 -1 -50 -68 -100 -85 -29 92 -48 -61 42 -84 -93 -41 -82", "output": "85 -95 -28 -43 -72 -11 -24 -37 -35 -44 -66 -45 -62 -96 -51 -55 -23 -31 -26 -59 -17 -69 -10 -12 -78 -14 -52 -57 -40 -75 -98 -6 -53 -3 -90 -63 -8 -20 -91 -32 -76 -80 -97 -34 -27 -19 -38 -9 -49 -67 -36 -39 -65 -83 -64 -18 -94 -79 -58 -16 -22 -74 -25 -13 -46 -89 -47 -15 -54 -99 -30 -60 -21 -86 -1 -50 -68 -100 -85 -29 -48 -61 -84 -93 -41 -82\n14 77 4 7 88 70 73 2 81 87 5 56 33 92 42\n1 0" }, { "input": "100\n-12 -41 57 13 83 -36 53 69 -6 86 -75 87 11 -5 -4 -14 -37 -84 70 2 -73 16 31 34 -45 94 -9 26 27 52 -42 46 96 21 32 7 -18 61 66 -51 95 -48 -76 90 80 -40 89 77 78 54 -30 8 88 33 -24 82 -15 19 1 59 44 64 -97 -60 43 56 35 47 39 50 29 28 -17 -67 74 23 85 -68 79 0 65 55 -3 92 -99 72 93 -71 38 -10 -100 -98 81 62 91 -63 -58 49 -20 22", "output": "35 -12 -41 -36 -6 -75 -5 -4 -14 -37 -84 -73 -45 -9 -42 -18 -51 -48 -76 -40 -30 -24 -15 -97 -60 -17 -67 -68 -3 -99 -71 -10 -100 -98 -63 -58\n63 57 13 83 53 69 86 87 11 70 2 16 31 34 94 26 27 52 46 96 21 32 7 61 66 95 90 80 89 77 78 54 8 88 33 82 19 1 59 44 64 43 56 35 47 39 50 29 28 74 23 85 79 65 55 92 72 93 38 81 62 91 49 22\n2 0 -20" }, { "input": "100\n-34 81 85 -96 50 20 54 86 22 10 -19 52 65 44 30 53 63 71 17 98 -92 4 5 -99 89 -23 48 9 7 33 75 2 47 -56 42 70 -68 57 51 83 82 94 91 45 46 25 95 11 -12 62 -31 -87 58 38 67 97 -60 66 73 -28 13 93 29 59 -49 77 37 -43 -27 0 -16 72 15 79 61 78 35 21 3 8 84 1 -32 36 74 -88 26 100 6 14 40 76 18 90 24 69 80 64 55 41", "output": "19 -34 -96 -19 -92 -99 -23 -56 -68 -12 -31 -87 -60 -28 -49 -43 -27 -16 -32 -88\n80 81 85 50 20 54 86 22 10 52 65 44 30 53 63 71 17 98 4 5 89 48 9 7 33 75 2 47 42 70 57 51 83 82 94 91 45 46 25 95 11 62 58 38 67 97 66 73 13 93 29 59 77 37 72 15 79 61 78 35 21 3 8 84 1 36 74 26 100 6 14 40 76 18 90 24 69 80 64 55 41\n1 0" }, { "input": "100\n-1000 -986 -979 -955 -966 -963 -973 -959 -972 -906 -924 -927 -929 -918 -977 -967 -921 -989 -911 -995 -945 -919 -971 -913 -912 -933 -969 -975 -920 -988 -997 -994 -953 -962 -940 -905 -978 -948 -957 -996 0 -976 -949 -931 -903 -985 -923 -993 -944 -909 -938 -946 -934 -992 -904 -980 -954 -943 -917 -968 -991 -956 -902 -942 -999 -998 -908 -928 -930 -914 -922 -936 -960 -937 -939 -926 -965 -925 -951 -910 -907 -970 -990 -984 -964 -987 -916 -947 -982 -950 -974 -915 -932 -958 -981 -941 -961 -983 -952 -935", "output": "97 -1000 -986 -979 -955 -966 -963 -973 -959 -972 -906 -924 -927 -929 -918 -977 -967 -921 -989 -911 -995 -945 -919 -971 -913 -912 -933 -969 -975 -920 -988 -997 -994 -953 -962 -940 -905 -978 -948 -957 -996 -976 -949 -931 -903 -985 -923 -993 -944 -909 -938 -946 -934 -992 -904 -980 -954 -943 -917 -968 -991 -956 -902 -942 -999 -998 -908 -928 -930 -914 -922 -936 -960 -937 -939 -926 -965 -925 -951 -910 -907 -970 -990 -984 -964 -987 -916 -947 -982 -950 -974 -915 -932 -958 -981 -941 -961 -983\n2 -935 -952\n1 0" }, { "input": "99\n-1000 -986 -979 -955 -966 -963 -973 -959 -972 -906 -924 -927 -929 -918 -977 -967 -921 -989 -911 -995 -945 -919 -971 -913 -912 -933 -969 -975 -920 -988 -997 -994 -953 -962 -940 -905 -978 -948 -957 -996 0 -976 -949 -931 -903 -985 -923 -993 -944 -909 -938 -946 -934 -992 -904 -980 -954 -943 -917 -968 -991 -956 -902 -942 -999 -998 -908 -928 -930 -914 -922 -936 -960 -937 -939 -926 -965 -925 -951 -910 -907 -970 -990 -984 -964 -987 -916 -947 -982 -950 -974 -915 -932 -958 -981 -941 -961 -983 -952", "output": "95 -1000 -986 -979 -955 -966 -963 -973 -959 -972 -906 -924 -927 -929 -918 -977 -967 -921 -989 -911 -995 -945 -919 -971 -913 -912 -933 -969 -975 -920 -988 -997 -994 -953 -962 -940 -905 -978 -948 -957 -996 -976 -949 -931 -903 -985 -923 -993 -944 -909 -938 -946 -934 -992 -904 -980 -954 -943 -917 -968 -991 -956 -902 -942 -999 -998 -908 -928 -930 -914 -922 -936 -960 -937 -939 -926 -965 -925 -951 -910 -907 -970 -990 -984 -964 -987 -916 -947 -982 -950 -974 -915 -932 -958 -981 -941\n2 -952 -983\n2 0 -961" }, { "input": "59\n-990 -876 -641 -726 718 -53 803 -954 894 -265 -587 -665 904 349 754 -978 441 794 -768 -428 -569 -476 188 -620 -290 -333 45 705 -201 109 165 446 13 122 714 -562 -15 -86 -960 43 329 578 287 -776 -14 -71 915 886 -259 337 -495 913 -498 -669 -673 818 225 647 0", "output": "29 -990 -876 -641 -726 -53 -954 -265 -587 -665 -978 -768 -428 -569 -476 -620 -290 -333 -201 -562 -15 -86 -960 -776 -14 -71 -259 -495 -498 -669\n28 718 803 894 904 349 754 441 794 188 45 705 109 165 446 13 122 714 43 329 578 287 915 886 337 913 818 225 647\n2 0 -673" }, { "input": "64\n502 885 -631 -906 735 687 642 -29 -696 -165 -524 15 -129 -663 -846 -501 -651 895 -341 -833 -142 33 -847 688 945 -192 -587 -930 603 849 736 676 788 256 863 -509 319 -49 -807 -158 218 -886 -143 -639 118 -156 -291 325 892 -916 -622 -960 -959 -731 -943 436 -535 861 745 589 -159 376 -182 0", "output": "35 -631 -906 -29 -696 -165 -524 -129 -663 -846 -501 -651 -341 -833 -142 -847 -192 -587 -930 -509 -49 -807 -158 -886 -143 -639 -156 -291 -916 -622 -960 -959 -731 -943 -535 -159\n27 502 885 735 687 642 15 895 33 688 945 603 849 736 676 788 256 863 319 218 118 325 892 436 861 745 589 376\n2 0 -182" }, { "input": "5\n-1 -2 -3 -4 0", "output": "1 -1\n2 -4 -3\n2 0 -2" }, { "input": "3\n-101 101 0", "output": "1 -101\n1 101\n1 0" }, { "input": "21\n-100 -200 -300 -400 -500 -600 -700 -800 -900 -1000 0 100 200 300 400 500 600 700 800 900 1000", "output": "9 -100 -200 -300 -400 -500 -600 -700 -800 -900\n10 100 200 300 400 500 600 700 800 900 1000\n2 0 -1000" }, { "input": "4\n0 -1 -2 -3", "output": "1 -1\n2 -3 -2\n1 0" } ]
1,623,823,978
2,147,483,647
PyPy 3
OK
TESTS
20
248
0
# A. Array n=int(input()) a=list(map(int,input().split())) def product(a): p=1 for i in a: p*=i return p a.sort() a1=[] a1.append(a[0]) a3=[0] a2=a[1:] a2.remove(0) if product(a2)>0: print(1,*a1) print(n-2,*a2) print(1,*a3) else: a3.append(a2[0]) a2.pop(0) print(1,*a1) print(n-3,*a2) print(2,*a3)
Title: Array Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vitaly has an array of *n* distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold: 1. The product of all numbers in the first set is less than zero (<=&lt;<=0). 1. The product of all numbers in the second set is greater than zero (<=&gt;<=0). 1. The product of all numbers in the third set is equal to zero. 1. Each number from the initial array must occur in exactly one set. Help Vitaly. Divide the given array. Input Specification: The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=100). The second line contains *n* space-separated distinct integers *a*1,<=*a*2,<=...,<=*a**n* (|*a**i*|<=≤<=103) — the array elements. Output Specification: In the first line print integer *n*1 (*n*1<=&gt;<=0) — the number of elements in the first set. Then print *n*1 numbers — the elements that got to the first set. In the next line print integer *n*2 (*n*2<=&gt;<=0) — the number of elements in the second set. Then print *n*2 numbers — the elements that got to the second set. In the next line print integer *n*3 (*n*3<=&gt;<=0) — the number of elements in the third set. Then print *n*3 numbers — the elements that got to the third set. The printed sets must meet the described conditions. It is guaranteed that the solution exists. If there are several solutions, you are allowed to print any of them. Demo Input: ['3\n-1 2 0\n', '4\n-1 -2 -3 0\n'] Demo Output: ['1 -1\n1 2\n1 0\n', '1 -1\n2 -3 -2\n1 0\n'] Note: none
```python # A. Array n=int(input()) a=list(map(int,input().split())) def product(a): p=1 for i in a: p*=i return p a.sort() a1=[] a1.append(a[0]) a3=[0] a2=a[1:] a2.remove(0) if product(a2)>0: print(1,*a1) print(n-2,*a2) print(1,*a3) else: a3.append(a2[0]) a2.pop(0) print(1,*a1) print(n-3,*a2) print(2,*a3) ```
3
266
A
Stones on the Table
PROGRAMMING
800
[ "implementation" ]
null
null
There are *n* stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row are considered neighboring if there are no other stones between them.
The first line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of stones on the table. The next line contains string *s*, which represents the colors of the stones. We'll consider the stones in the row numbered from 1 to *n* from left to right. Then the *i*-th character *s* equals "R", if the *i*-th stone is red, "G", if it's green and "B", if it's blue.
Print a single integer — the answer to the problem.
[ "3\nRRG\n", "5\nRRRRR\n", "4\nBRBG\n" ]
[ "1\n", "4\n", "0\n" ]
none
500
[ { "input": "3\nRRG", "output": "1" }, { "input": "5\nRRRRR", "output": "4" }, { "input": "4\nBRBG", "output": "0" }, { "input": "1\nB", "output": "0" }, { "input": "2\nBG", "output": "0" }, { "input": "3\nBGB", "output": "0" }, { "input": "4\nRBBR", "output": "1" }, { "input": "5\nRGGBG", "output": "1" }, { "input": "10\nGGBRBRGGRB", "output": "2" }, { "input": "50\nGRBGGRBRGRBGGBBBBBGGGBBBBRBRGBRRBRGBBBRBBRRGBGGGRB", "output": "18" }, { "input": "15\nBRRBRGGBBRRRRGR", "output": "6" }, { "input": "20\nRRGBBRBRGRGBBGGRGRRR", "output": "6" }, { "input": "25\nBBGBGRBGGBRRBGRRBGGBBRBRB", "output": "6" }, { "input": "30\nGRGGGBGGRGBGGRGRBGBGBRRRRRRGRB", "output": "9" }, { "input": "35\nGBBGBRGBBGGRBBGBRRGGRRRRRRRBRBBRRGB", "output": "14" }, { "input": "40\nGBBRRGBGGGRGGGRRRRBRBGGBBGGGBGBBBBBRGGGG", "output": "20" }, { "input": "45\nGGGBBRBBRRGRBBGGBGRBRGGBRBRGBRRGBGRRBGRGRBRRG", "output": "11" }, { "input": "50\nRBGGBGGRBGRBBBGBBGRBBBGGGRBBBGBBBGRGGBGGBRBGBGRRGG", "output": "17" }, { "input": "50\nGGGBBRGGGGGRRGGRBGGRGBBRBRRBGRGBBBGBRBGRGBBGRGGBRB", "output": "16" }, { "input": "50\nGBGRGRRBRRRRRGGBBGBRRRBBBRBBBRRGRBBRGBRBGGRGRBBGGG", "output": "19" }, { "input": "10\nGRRBRBRBGR", "output": "1" }, { "input": "10\nBRBGBGRRBR", "output": "1" }, { "input": "20\nGBGBGGRRRRGRBBGRGRGR", "output": "5" }, { "input": "20\nRRGGRBBGBBRBGRRBRRBG", "output": "6" }, { "input": "30\nBGBRGBBBGRGBBRGBGRBBBRGGRRGRRB", "output": "8" }, { "input": "30\nBBBBGGBRBGBBGBGBGBGGGRGRRGGBBB", "output": "11" }, { "input": "40\nGBRRGRBGBRRGBRGGGBRGBGBRGBBRRGRGGBBGBGBB", "output": "9" }, { "input": "40\nBRGRGGRGGRBBRRRBRBBGGGRRGBGBBGRBBRGBRRGG", "output": "13" }, { "input": "50\nRBGBGGRRGGRGGBGBGRRBGGBGBRRBBGBBGBBBGBBRBBRBRBRGRG", "output": "13" }, { "input": "50\nRBRRGBGRRRBGRRBGRRGRBBRBBRRBRGGBRBRRBGGRBGGBRBRGRB", "output": "12" }, { "input": "2\nBB", "output": "1" }, { "input": "50\nRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR", "output": "49" }, { "input": "50\nRRRRRRRRGRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR", "output": "47" }, { "input": "50\nRRRRRRRRRRRRGGRRRRRRRRRBRRRRRRRRRRRRRRBBRRRRRRRRRR", "output": "43" } ]
1,695,275,289
2,147,483,647
Python 3
OK
TESTS
34
92
0
n = int(input()) stones = list(input()) counter = 0 for i in range(n-1): if stones[i] == stones[i+1]: counter += 1 print(counter)
Title: Stones on the Table Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row are considered neighboring if there are no other stones between them. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of stones on the table. The next line contains string *s*, which represents the colors of the stones. We'll consider the stones in the row numbered from 1 to *n* from left to right. Then the *i*-th character *s* equals "R", if the *i*-th stone is red, "G", if it's green and "B", if it's blue. Output Specification: Print a single integer — the answer to the problem. Demo Input: ['3\nRRG\n', '5\nRRRRR\n', '4\nBRBG\n'] Demo Output: ['1\n', '4\n', '0\n'] Note: none
```python n = int(input()) stones = list(input()) counter = 0 for i in range(n-1): if stones[i] == stones[i+1]: counter += 1 print(counter) ```
3
343
B
Alternating Current
PROGRAMMING
1,600
[ "data structures", "greedy", "implementation" ]
null
null
Mad scientist Mike has just finished constructing a new device to search for extraterrestrial intelligence! He was in such a hurry to launch it for the first time that he plugged in the power wires without giving it a proper glance and started experimenting right away. After a while Mike observed that the wires ended up entangled and now have to be untangled again. The device is powered by two wires "plus" and "minus". The wires run along the floor from the wall (on the left) to the device (on the right). Both the wall and the device have two contacts in them on the same level, into which the wires are plugged in some order. The wires are considered entangled if there are one or more places where one wire runs above the other one. For example, the picture below has four such places (top view): Mike knows the sequence in which the wires run above each other. Mike also noticed that on the left side, the "plus" wire is always plugged into the top contact (as seen on the picture). He would like to untangle the wires without unplugging them and without moving the device. Determine if it is possible to do that. A wire can be freely moved and stretched on the floor, but cannot be cut. To understand the problem better please read the notes to the test samples.
The single line of the input contains a sequence of characters "+" and "-" of length *n* (1<=≤<=*n*<=≤<=100000). The *i*-th (1<=≤<=*i*<=≤<=*n*) position of the sequence contains the character "+", if on the *i*-th step from the wall the "plus" wire runs above the "minus" wire, and the character "-" otherwise.
Print either "Yes" (without the quotes) if the wires can be untangled or "No" (without the quotes) if the wires cannot be untangled.
[ "-++-\n", "+-\n", "++\n", "-\n" ]
[ "Yes\n", "No\n", "Yes\n", "No\n" ]
The first testcase corresponds to the picture in the statement. To untangle the wires, one can first move the "plus" wire lower, thus eliminating the two crosses in the middle, and then draw it under the "minus" wire, eliminating also the remaining two crosses. In the second testcase the "plus" wire makes one full revolution around the "minus" wire. Thus the wires cannot be untangled: In the third testcase the "plus" wire simply runs above the "minus" wire twice in sequence. The wires can be untangled by lifting "plus" and moving it higher: In the fourth testcase the "minus" wire runs above the "plus" wire once. The wires cannot be untangled without moving the device itself:
1,000
[ { "input": "-++-", "output": "Yes" }, { "input": "+-", "output": "No" }, { "input": "++", "output": "Yes" }, { "input": "-", "output": "No" }, { "input": "+-+-", "output": "No" }, { "input": "-+-", "output": "No" }, { "input": "-++-+--+", "output": "Yes" }, { "input": "+", "output": "No" }, { "input": "-+", "output": "No" }, { "input": "--", "output": "Yes" }, { "input": "+++", "output": "No" }, { "input": "--+", "output": "No" }, { "input": "++--++", "output": "Yes" }, { "input": "+-++-+", "output": "Yes" }, { "input": "+-+--+", "output": "No" }, { "input": "--++-+", "output": "No" }, { "input": "-+-+--", "output": "No" }, { "input": "+-+++-", "output": "No" }, { "input": "-+-+-+", "output": "No" }, { "input": "-++-+--++--+-++-", "output": "Yes" }, { "input": "+-----+-++---+------+++-++++", "output": "No" }, { "input": "-+-++--+++-++++---+--+----+--+-+-+++-+++-+---++-++++-+--+--+--+-+-++-+-+-++++++---++--+++++-+--++--+-+--++-----+--+-++---+++---++----+++-++++--++-++-", "output": "No" }, { "input": "-+-----++++--++-+-++", "output": "Yes" }, { "input": "+--+--+------+++++++-+-+++--++---+--+-+---+--+++-+++-------+++++-+-++++--+-+-+++++++----+----+++----+-+++-+++-----+++-+-++-+-+++++-+--++----+--+-++-----+-+-++++---+++---+-+-+-++++--+--+++---+++++-+---+-----+++-++--+++---++-++-+-+++-+-+-+---+++--+--++++-+-+--++-------+--+---++-----+++--+-+++--++-+-+++-++--+++-++++++++++-++-++++++-+++--+--++-+++--+++-++++----+++---+-+----++++-+-+", "output": "Yes" }, { "input": "-+-+-++-+-+-", "output": "Yes" }, { "input": "-+-++-+-", "output": "Yes" }, { "input": "-+-++-+-+-", "output": "No" }, { "input": "++-+-+-+-+--+", "output": "No" }, { "input": "+++---", "output": "No" }, { "input": "+-+-+-+-+--+-+-+-+-++--++--+", "output": "Yes" }, { "input": "+-+-++", "output": "No" }, { "input": "-++--+--+++-+-+-+-+-", "output": "No" }, { "input": "+---+-+-", "output": "No" }, { "input": "+-+--+-+", "output": "Yes" }, { "input": "+++---+++---", "output": "No" }, { "input": "-+++++", "output": "No" }, { "input": "-+-+-+-+-+-+-++-+-+-+-+-+-+-", "output": "Yes" }, { "input": "-+++--", "output": "No" }, { "input": "+---+", "output": "No" }, { "input": "-++", "output": "No" }, { "input": "-+--+-", "output": "Yes" }, { "input": "+---++--++", "output": "No" }, { "input": "+++-", "output": "No" }, { "input": "--+++", "output": "No" }, { "input": "++-+", "output": "No" } ]
1,587,805,755
2,147,483,647
PyPy 3
OK
TESTS
62
310
1,945,600
s = input() p = 0 n = 0 for i in range(len(s)): if i % 2 == 0: if s[i] == "-": p += 1 else: n += 1 else: if s[i] == "-": n += 1 else: p += 1 if p == n: print("Yes") else: print("No")
Title: Alternating Current Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mad scientist Mike has just finished constructing a new device to search for extraterrestrial intelligence! He was in such a hurry to launch it for the first time that he plugged in the power wires without giving it a proper glance and started experimenting right away. After a while Mike observed that the wires ended up entangled and now have to be untangled again. The device is powered by two wires "plus" and "minus". The wires run along the floor from the wall (on the left) to the device (on the right). Both the wall and the device have two contacts in them on the same level, into which the wires are plugged in some order. The wires are considered entangled if there are one or more places where one wire runs above the other one. For example, the picture below has four such places (top view): Mike knows the sequence in which the wires run above each other. Mike also noticed that on the left side, the "plus" wire is always plugged into the top contact (as seen on the picture). He would like to untangle the wires without unplugging them and without moving the device. Determine if it is possible to do that. A wire can be freely moved and stretched on the floor, but cannot be cut. To understand the problem better please read the notes to the test samples. Input Specification: The single line of the input contains a sequence of characters "+" and "-" of length *n* (1<=≤<=*n*<=≤<=100000). The *i*-th (1<=≤<=*i*<=≤<=*n*) position of the sequence contains the character "+", if on the *i*-th step from the wall the "plus" wire runs above the "minus" wire, and the character "-" otherwise. Output Specification: Print either "Yes" (without the quotes) if the wires can be untangled or "No" (without the quotes) if the wires cannot be untangled. Demo Input: ['-++-\n', '+-\n', '++\n', '-\n'] Demo Output: ['Yes\n', 'No\n', 'Yes\n', 'No\n'] Note: The first testcase corresponds to the picture in the statement. To untangle the wires, one can first move the "plus" wire lower, thus eliminating the two crosses in the middle, and then draw it under the "minus" wire, eliminating also the remaining two crosses. In the second testcase the "plus" wire makes one full revolution around the "minus" wire. Thus the wires cannot be untangled: In the third testcase the "plus" wire simply runs above the "minus" wire twice in sequence. The wires can be untangled by lifting "plus" and moving it higher: In the fourth testcase the "minus" wire runs above the "plus" wire once. The wires cannot be untangled without moving the device itself:
```python s = input() p = 0 n = 0 for i in range(len(s)): if i % 2 == 0: if s[i] == "-": p += 1 else: n += 1 else: if s[i] == "-": n += 1 else: p += 1 if p == n: print("Yes") else: print("No") ```
3
570
B
Simple Game
PROGRAMMING
1,300
[ "constructive algorithms", "games", "greedy", "implementation", "math" ]
null
null
One day Misha and Andrew were playing a very simple game. First, each player chooses an integer in the range from 1 to *n*. Let's assume that Misha chose number *m*, and Andrew chose number *a*. Then, by using a random generator they choose a random integer *c* in the range between 1 and *n* (any integer from 1 to *n* is chosen with the same probability), after which the winner is the player, whose number was closer to *c*. The boys agreed that if *m* and *a* are located on the same distance from *c*, Misha wins. Andrew wants to win very much, so he asks you to help him. You know the number selected by Misha, and number *n*. You need to determine which value of *a* Andrew must choose, so that the probability of his victory is the highest possible. More formally, you need to find such integer *a* (1<=≤<=*a*<=≤<=*n*), that the probability that is maximal, where *c* is the equiprobably chosen integer from 1 to *n* (inclusive).
The first line contains two integers *n* and *m* (1<=≤<=*m*<=≤<=*n*<=≤<=109) — the range of numbers in the game, and the number selected by Misha respectively.
Print a single number — such value *a*, that probability that Andrew wins is the highest. If there are multiple such values, print the minimum of them.
[ "3 1\n", "4 3\n" ]
[ "2", "2" ]
In the first sample test: Andrew wins if *c* is equal to 2 or 3. The probability that Andrew wins is 2 / 3. If Andrew chooses *a* = 3, the probability of winning will be 1 / 3. If *a* = 1, the probability of winning is 0. In the second sample test: Andrew wins if *c* is equal to 1 and 2. The probability that Andrew wins is 1 / 2. For other choices of *a* the probability of winning is less.
1,000
[ { "input": "3 1", "output": "2" }, { "input": "4 3", "output": "2" }, { "input": "5 5", "output": "4" }, { "input": "10 5", "output": "6" }, { "input": "20 13", "output": "12" }, { "input": "51 1", "output": "2" }, { "input": "100 50", "output": "51" }, { "input": "100 51", "output": "50" }, { "input": "100 49", "output": "50" }, { "input": "1000000000 1000000000", "output": "999999999" }, { "input": "1000000000 1", "output": "2" }, { "input": "1000000000 100000000", "output": "100000001" }, { "input": "1000000000 500000000", "output": "500000001" }, { "input": "1000000000 123124", "output": "123125" }, { "input": "12412523 125123", "output": "125124" }, { "input": "54645723 432423", "output": "432424" }, { "input": "1 1", "output": "1" }, { "input": "262833325 131416663", "output": "131416662" }, { "input": "477667530 238833766", "output": "238833765" }, { "input": "692501734 346250868", "output": "346250867" }, { "input": "907335939 453667970", "output": "453667969" }, { "input": "746085224 373042613", "output": "373042612" }, { "input": "189520699 94760350", "output": "94760349" }, { "input": "404354904 202177453", "output": "202177452" }, { "input": "619189108 309594555", "output": "309594554" }, { "input": "81813292 40906647", "output": "40906646" }, { "input": "296647497 148323750", "output": "148323749" }, { "input": "511481701 255740851", "output": "255740850" }, { "input": "726315905 363157953", "output": "363157952" }, { "input": "496110970 201868357", "output": "201868358" }, { "input": "710945175 173165570", "output": "173165571" }, { "input": "925779379 720443954", "output": "720443953" }, { "input": "140613583 93171580", "output": "93171579" }, { "input": "355447788 85890184", "output": "85890185" }, { "input": "570281992 291648263", "output": "291648262" }, { "input": "541904957 459371829", "output": "459371828" }, { "input": "756739161 125332525", "output": "125332526" }, { "input": "971573366 216791157", "output": "216791158" }, { "input": "186407570 160453970", "output": "160453969" }, { "input": "401241775 170032078", "output": "170032079" }, { "input": "616075979 207073797", "output": "207073798" }, { "input": "1 1", "output": "1" }, { "input": "2 1", "output": "2" }, { "input": "2 2", "output": "1" }, { "input": "3 1", "output": "2" }, { "input": "3 2", "output": "1" }, { "input": "3 3", "output": "2" }, { "input": "4 1", "output": "2" }, { "input": "4 2", "output": "3" }, { "input": "4 3", "output": "2" }, { "input": "4 4", "output": "3" }, { "input": "5 1", "output": "2" }, { "input": "5 2", "output": "3" }, { "input": "5 3", "output": "2" }, { "input": "5 4", "output": "3" }, { "input": "5 5", "output": "4" }, { "input": "3 2", "output": "1" }, { "input": "7 4", "output": "3" }, { "input": "2 2", "output": "1" }, { "input": "7 3", "output": "4" } ]
1,586,606,186
2,147,483,647
PyPy 3
RUNTIME_ERROR
TESTS
16
358
10,137,600
import statistics def solve(n,m): med = 0 if n % 2 == 0: ## if n is even number med = (n+1)/2 if m > med: a = m-1 elif m < med: a = m+1 elif n % 2 != 0: med = n//2 + 1 if m < med: a = m+1 elif m > med: a = m-1 print(a) if __name__ == '__main__': n,m = map(int, input().split()) solve(n,m)
Title: Simple Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day Misha and Andrew were playing a very simple game. First, each player chooses an integer in the range from 1 to *n*. Let's assume that Misha chose number *m*, and Andrew chose number *a*. Then, by using a random generator they choose a random integer *c* in the range between 1 and *n* (any integer from 1 to *n* is chosen with the same probability), after which the winner is the player, whose number was closer to *c*. The boys agreed that if *m* and *a* are located on the same distance from *c*, Misha wins. Andrew wants to win very much, so he asks you to help him. You know the number selected by Misha, and number *n*. You need to determine which value of *a* Andrew must choose, so that the probability of his victory is the highest possible. More formally, you need to find such integer *a* (1<=≤<=*a*<=≤<=*n*), that the probability that is maximal, where *c* is the equiprobably chosen integer from 1 to *n* (inclusive). Input Specification: The first line contains two integers *n* and *m* (1<=≤<=*m*<=≤<=*n*<=≤<=109) — the range of numbers in the game, and the number selected by Misha respectively. Output Specification: Print a single number — such value *a*, that probability that Andrew wins is the highest. If there are multiple such values, print the minimum of them. Demo Input: ['3 1\n', '4 3\n'] Demo Output: ['2', '2'] Note: In the first sample test: Andrew wins if *c* is equal to 2 or 3. The probability that Andrew wins is 2 / 3. If Andrew chooses *a* = 3, the probability of winning will be 1 / 3. If *a* = 1, the probability of winning is 0. In the second sample test: Andrew wins if *c* is equal to 1 and 2. The probability that Andrew wins is 1 / 2. For other choices of *a* the probability of winning is less.
```python import statistics def solve(n,m): med = 0 if n % 2 == 0: ## if n is even number med = (n+1)/2 if m > med: a = m-1 elif m < med: a = m+1 elif n % 2 != 0: med = n//2 + 1 if m < med: a = m+1 elif m > med: a = m-1 print(a) if __name__ == '__main__': n,m = map(int, input().split()) solve(n,m) ```
-1
896
A
Nephren gives a riddle
PROGRAMMING
1,700
[ "binary search", "dfs and similar" ]
null
null
Nephren is playing a game with little leprechauns. She gives them an infinite array of strings, *f*0... ∞. *f*0 is "What are you doing at the end of the world? Are you busy? Will you save us?". She wants to let more people know about it, so she defines *f**i*<==<= "What are you doing while sending "*f**i*<=-<=1"? Are you busy? Will you send "*f**i*<=-<=1"?" for all *i*<=≥<=1. For example, *f*1 is "What are you doing while sending "What are you doing at the end of the world? Are you busy? Will you save us?"? Are you busy? Will you send "What are you doing at the end of the world? Are you busy? Will you save us?"?". Note that the quotes in the very beginning and in the very end are for clarity and are not a part of *f*1. It can be seen that the characters in *f**i* are letters, question marks, (possibly) quotation marks and spaces. Nephren will ask the little leprechauns *q* times. Each time she will let them find the *k*-th character of *f**n*. The characters are indexed starting from 1. If *f**n* consists of less than *k* characters, output '.' (without quotes). Can you answer her queries?
The first line contains one integer *q* (1<=≤<=*q*<=≤<=10) — the number of Nephren's questions. Each of the next *q* lines describes Nephren's question and contains two integers *n* and *k* (0<=≤<=*n*<=≤<=105,<=1<=≤<=*k*<=≤<=1018).
One line containing *q* characters. The *i*-th character in it should be the answer for the *i*-th query.
[ "3\n1 1\n1 2\n1 111111111111\n", "5\n0 69\n1 194\n1 139\n0 47\n1 66\n", "10\n4 1825\n3 75\n3 530\n4 1829\n4 1651\n3 187\n4 584\n4 255\n4 774\n2 474\n" ]
[ "Wh.", "abdef", "Areyoubusy" ]
For the first two examples, refer to *f*<sub class="lower-index">0</sub> and *f*<sub class="lower-index">1</sub> given in the legend.
500
[ { "input": "3\n1 1\n1 2\n1 111111111111", "output": "Wh." }, { "input": "5\n0 69\n1 194\n1 139\n0 47\n1 66", "output": "abdef" }, { "input": "10\n4 1825\n3 75\n3 530\n4 1829\n4 1651\n3 187\n4 584\n4 255\n4 774\n2 474", "output": "Areyoubusy" }, { "input": "1\n0 1", "output": "W" }, { "input": "1\n999 1000000000000000000", "output": "?" }, { "input": "10\n1 8\n1 8\n9 5\n0 1\n8 1\n7 3\n5 2\n0 9\n4 6\n9 4", "output": "ee WWah at" }, { "input": "10\n5 235941360876088213\n10 65160787148797531\n0 531970131175601601\n2 938108094014908387\n3 340499457696664259\n5 56614532774539063\n5 719524142056884004\n10 370927072502555372\n2 555965798821270052\n10 492559401050725258", "output": ".........." }, { "input": "10\n72939 670999605706502447\n67498 428341803949410086\n62539 938370976591475035\n58889 657471364021290792\n11809 145226347556228466\n77111 294430864855433173\n29099 912050147755964704\n27793 196249143894732547\n118 154392540400153863\n62843 63234003203996349", "output": "?usaglrnyh" }, { "input": "10\n74 752400948436334811\n22 75900251524550494\n48 106700456127359025\n20 623493261724933249\n90 642991963097110817\n42 47750435275360941\n24 297055789449373682\n65 514620361483452045\n99 833434466044716497\n0 928523848526511085", "output": "h... .. d." }, { "input": "10\n26302 2898997\n2168 31686909\n56241 27404733\n9550 44513376\n70116 90169838\n14419 95334944\n61553 16593205\n85883 42147334\n55209 74676056\n57866 68603505", "output": "donts ly o" }, { "input": "9\n50 161003686678495163\n50 161003686678495164\n50 161003686678495165\n51 322007373356990395\n51 322007373356990396\n51 322007373356990397\n52 644014746713980859\n52 644014746713980860\n52 644014746713980861", "output": "\"?.\"?.\"?." }, { "input": "10\n100000 1000000000000000000\n99999 999999999999998683\n99998 999999999999997366\n99997 999999999999996049\n99996 999999999999994732\n99995 999999999999993415\n99994 999999999999992098\n99993 999999999999990781\n99992 999999999999989464\n99991 999999999999988147", "output": "o u lugW? " }, { "input": "10\n94455 839022536766957828\n98640 878267599238035211\n90388 54356607570140506\n93536 261222577013066170\n91362 421089574363407592\n95907 561235487589345620\n91888 938806156011561508\n90820 141726323964466814\n97856 461989202234320135\n92518 602709074380260370", "output": "youni iiee" }, { "input": "10\n100000 873326525630182716\n100000 620513733919162415\n100000 482953375281256917\n100000 485328193417229962\n100000 353549227094721271\n100000 367447590857326107\n100000 627193846053528323\n100000 243833127760837417\n100000 287297493528203749\n100000 70867563577617188", "output": "o W rlot" }, { "input": "10\n1 1\n1 34\n1 35\n1 109\n1 110\n1 141\n1 142\n1 216\n1 217\n1 218", "output": "W\"W?\"\"W?\"?" }, { "input": "10\n5 1\n5 34\n5 35\n5 2254\n5 2255\n5 2286\n5 2287\n5 4506\n5 4507\n5 4508", "output": "W\"W?\"\"W?\"?" }, { "input": "10\n10 1\n10 34\n10 35\n10 73182\n10 73183\n10 73214\n10 73215\n10 146362\n10 146363\n10 146364", "output": "W\"W?\"\"W?\"?" }, { "input": "10\n15 1\n15 34\n15 35\n15 2342878\n15 2342879\n15 2342910\n15 2342911\n15 4685754\n15 4685755\n15 4685756", "output": "W\"W?\"\"W?\"?" }, { "input": "10\n35 1\n35 34\n35 35\n35 2456721293278\n35 2456721293279\n35 2456721293310\n35 2456721293311\n35 4913442586554\n35 4913442586555\n35 4913442586556", "output": "W\"W?\"\"W?\"?" }, { "input": "10\n47 1\n47 34\n47 35\n47 10062730417405918\n47 10062730417405919\n47 10062730417405950\n47 10062730417405951\n47 20125460834811834\n47 20125460834811835\n47 20125460834811836", "output": "W\"W?\"\"W?\"?" }, { "input": "10\n50 1\n50 34\n50 35\n50 80501843339247582\n50 80501843339247583\n50 80501843339247614\n50 80501843339247615\n50 161003686678495162\n50 161003686678495163\n50 161003686678495164", "output": "W\"W?\"\"W?\"?" }, { "input": "10\n52 1\n52 34\n52 35\n52 322007373356990430\n52 322007373356990431\n52 322007373356990462\n52 322007373356990463\n52 644014746713980858\n52 644014746713980859\n52 644014746713980860", "output": "W\"W?\"\"W?\"?" }, { "input": "10\n54986 859285936548585889\n49540 198101079999865795\n96121 658386311981208488\n27027 787731514451843966\n60674 736617460878411577\n57761 569094390437687993\n93877 230086639196124716\n75612 765187050118682698\n75690 960915623784157529\n1788 121643460920471434", "output": "oru A\" de\"" }, { "input": "10\n13599 295514896417102030\n70868 206213281730527977\n99964 675362501525687265\n8545 202563221795027954\n62885 775051601455683055\n44196 552672589494215033\n38017 996305706075726957\n82157 778541544539864990\n13148 755735956771594947\n66133 739544460375378867", "output": "t?W y wnr" }, { "input": "10\n23519 731743847695683578\n67849 214325487756157455\n39048 468966654215390234\n30476 617394929138211942\n40748 813485737737987237\n30632 759622821110550585\n30851 539152740395520686\n23942 567423516617312907\n93605 75958684925842506\n24977 610678262374451619", "output": "WonreeuhAn" }, { "input": "10\n66613 890998077399614704\n59059 389024292752123693\n10265 813853582068134597\n71434 128404685079108014\n76180 582880920044162144\n1123 411409570241705915\n9032 611954441092300071\n78951 57503725302368508\n32102 824738435154619172\n44951 53991552354407935", "output": "i oio u? " }, { "input": "10\n96988 938722606709261427\n97034 794402579184858837\n96440 476737696947281053\n96913 651380108479508367\n99570 535723325634376015\n97425 180427887538234591\n97817 142113098762476646\n96432 446510004868669235\n98788 476529766139390976\n96231 263034481360542586", "output": "eunWwdtnA " }, { "input": "10\n99440 374951566577777567\n98662 802514785210488315\n97117 493713886491759829\n97252 66211820117659651\n98298 574157457621712902\n99067 164006086594761631\n99577 684960128787303079\n96999 12019940091341344\n97772 796752494293638534\n96958 134168283359615339", "output": "idrd? o nl" }, { "input": "10\n95365 811180517856359115\n97710 810626986941150496\n98426 510690080331205902\n99117 481043523165876343\n95501 612591593904017084\n96340 370956318211097183\n96335 451179199961872617\n95409 800901907873821965\n97650 893603181298142989\n96159 781930052798879580", "output": "oisv\"sb ta" }, { "input": "10\n96759 970434747560290241\n95684 985325796232084031\n99418 855577012478917561\n98767 992053283401739711\n99232 381986776210191990\n97804 22743067342252513\n95150 523980900658652001\n98478 290982116558877566\n98012 642382931526919655\n96374 448615375338644407", "output": " e\"atdW? e" }, { "input": "10\n5 929947814902665291\n0 270929202623248779\n10 917958578362357217\n3 674632947904782968\n7 19875145653630834\n8 744882317760093379\n4 471398991908637021\n7 253934163977433229\n7 125334789085610404\n10 841267552326270425", "output": ".........." }, { "input": "10\n3 366176770476214135\n10 55669371794102449\n1 934934767906835993\n0 384681214954881520\n4 684989729845321867\n8 231000356557573162\n1 336780423782602481\n2 300230185318227609\n7 23423148068105278\n1 733131408103947638", "output": ".........." }, { "input": "10\n6 25777762904538788\n1 63781573524764630\n5 951910961746282066\n9 280924325736375136\n6 96743418218239198\n1 712038707283212867\n4 780465093108032992\n4 608326071277553255\n8 542408204244362417\n3 360163123764607419", "output": ".........." }, { "input": "10\n1 185031988313502617\n8 461852423965441269\n2 296797889599026429\n3 15306118532047016\n6 866138600524414105\n10 587197493269144005\n2 853266793804812376\n2 98406279962608857\n3 291187954473139083\n0 26848446304372246", "output": ".........." }, { "input": "10\n27314 39\n71465 12\n29327 53\n33250 85\n52608 41\n19454 55\n72760 12\n83873 90\n67859 78\n91505 73", "output": " u nrhuiy " }, { "input": "10\n76311 57\n79978 83\n34607 89\n62441 98\n28700 35\n54426 67\n66596 15\n30889 21\n68793 7\n29916 71", "output": "lohiW ohra" } ]
1,514,256,397
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
2
46
5,632,000
n=int(input()) out=[] for i in range(0,n): t=input().split() a=int(t[0]) b=int(t[1]) said=("What are you doing at the end of the world? Are you busy? Will you save us?") for g in range(0,a): said="What are you doing while sending "+"\""+said+"\""+"? Are you busy? Will you send "+"\""+said+"\""+"?" said=list(said) l=len(said) if b>l: out.append(".") else: out.append(said[b-1]) print("".join(out))
Title: Nephren gives a riddle Time Limit: None seconds Memory Limit: None megabytes Problem Description: Nephren is playing a game with little leprechauns. She gives them an infinite array of strings, *f*0... ∞. *f*0 is "What are you doing at the end of the world? Are you busy? Will you save us?". She wants to let more people know about it, so she defines *f**i*<==<= "What are you doing while sending "*f**i*<=-<=1"? Are you busy? Will you send "*f**i*<=-<=1"?" for all *i*<=≥<=1. For example, *f*1 is "What are you doing while sending "What are you doing at the end of the world? Are you busy? Will you save us?"? Are you busy? Will you send "What are you doing at the end of the world? Are you busy? Will you save us?"?". Note that the quotes in the very beginning and in the very end are for clarity and are not a part of *f*1. It can be seen that the characters in *f**i* are letters, question marks, (possibly) quotation marks and spaces. Nephren will ask the little leprechauns *q* times. Each time she will let them find the *k*-th character of *f**n*. The characters are indexed starting from 1. If *f**n* consists of less than *k* characters, output '.' (without quotes). Can you answer her queries? Input Specification: The first line contains one integer *q* (1<=≤<=*q*<=≤<=10) — the number of Nephren's questions. Each of the next *q* lines describes Nephren's question and contains two integers *n* and *k* (0<=≤<=*n*<=≤<=105,<=1<=≤<=*k*<=≤<=1018). Output Specification: One line containing *q* characters. The *i*-th character in it should be the answer for the *i*-th query. Demo Input: ['3\n1 1\n1 2\n1 111111111111\n', '5\n0 69\n1 194\n1 139\n0 47\n1 66\n', '10\n4 1825\n3 75\n3 530\n4 1829\n4 1651\n3 187\n4 584\n4 255\n4 774\n2 474\n'] Demo Output: ['Wh.', 'abdef', 'Areyoubusy'] Note: For the first two examples, refer to *f*<sub class="lower-index">0</sub> and *f*<sub class="lower-index">1</sub> given in the legend.
```python n=int(input()) out=[] for i in range(0,n): t=input().split() a=int(t[0]) b=int(t[1]) said=("What are you doing at the end of the world? Are you busy? Will you save us?") for g in range(0,a): said="What are you doing while sending "+"\""+said+"\""+"? Are you busy? Will you send "+"\""+said+"\""+"?" said=list(said) l=len(said) if b>l: out.append(".") else: out.append(said[b-1]) print("".join(out)) ```
-1
645
B
Mischievous Mess Makers
PROGRAMMING
1,200
[ "greedy", "math" ]
null
null
It is a balmy spring afternoon, and Farmer John's *n* cows are ruminating about link-cut cacti in their stalls. The cows, labeled 1 through *n*, are arranged so that the *i*-th cow occupies the *i*-th stall from the left. However, Elsie, after realizing that she will forever live in the shadows beyond Bessie's limelight, has formed the Mischievous Mess Makers and is plotting to disrupt this beautiful pastoral rhythm. While Farmer John takes his *k* minute long nap, Elsie and the Mess Makers plan to repeatedly choose two distinct stalls and swap the cows occupying those stalls, making no more than one swap each minute. Being the meticulous pranksters that they are, the Mischievous Mess Makers would like to know the maximum messiness attainable in the *k* minutes that they have. We denote as *p**i* the label of the cow in the *i*-th stall. The messiness of an arrangement of cows is defined as the number of pairs (*i*,<=*j*) such that *i*<=&lt;<=*j* and *p**i*<=&gt;<=*p**j*.
The first line of the input contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100<=000) — the number of cows and the length of Farmer John's nap, respectively.
Output a single integer, the maximum messiness that the Mischievous Mess Makers can achieve by performing no more than *k* swaps.
[ "5 2\n", "1 10\n" ]
[ "10\n", "0\n" ]
In the first sample, the Mischievous Mess Makers can swap the cows in the stalls 1 and 5 during the first minute, then the cows in stalls 2 and 4 during the second minute. This reverses the arrangement of cows, giving us a total messiness of 10. In the second sample, there is only one cow, so the maximum possible messiness is 0.
1,000
[ { "input": "5 2", "output": "10" }, { "input": "1 10", "output": "0" }, { "input": "100000 2", "output": "399990" }, { "input": "1 1", "output": "0" }, { "input": "8 3", "output": "27" }, { "input": "7 1", "output": "11" }, { "input": "100000 40000", "output": "4799960000" }, { "input": "1 1000", "output": "0" }, { "input": "100 45", "output": "4905" }, { "input": "9 2", "output": "26" }, { "input": "456 78", "output": "58890" }, { "input": "100000 50000", "output": "4999950000" }, { "input": "100000 50001", "output": "4999950000" }, { "input": "100000 50002", "output": "4999950000" }, { "input": "100000 50003", "output": "4999950000" }, { "input": "100000 49998", "output": "4999949994" }, { "input": "100000 49997", "output": "4999949985" }, { "input": "99999 49998", "output": "4999849998" }, { "input": "99999 49997", "output": "4999849991" }, { "input": "99999 49996", "output": "4999849980" }, { "input": "99999 50000", "output": "4999850001" }, { "input": "99999 50001", "output": "4999850001" }, { "input": "99999 50002", "output": "4999850001" }, { "input": "30062 9", "output": "540945" }, { "input": "13486 3", "output": "80895" }, { "input": "29614 7", "output": "414491" }, { "input": "13038 8", "output": "208472" }, { "input": "96462 6", "output": "1157466" }, { "input": "22599 93799", "output": "255346101" }, { "input": "421 36817", "output": "88410" }, { "input": "72859 65869", "output": "2654180511" }, { "input": "37916 5241", "output": "342494109" }, { "input": "47066 12852", "output": "879423804" }, { "input": "84032 21951", "output": "2725458111" }, { "input": "70454 75240", "output": "2481847831" }, { "input": "86946 63967", "output": "3779759985" }, { "input": "71128 11076", "output": "1330260828" }, { "input": "46111 64940", "output": "1063089105" }, { "input": "46111 64940", "output": "1063089105" }, { "input": "56500 84184", "output": "1596096750" }, { "input": "60108 83701", "output": "1806455778" }, { "input": "1 2", "output": "0" }, { "input": "1 3", "output": "0" }, { "input": "1 4", "output": "0" }, { "input": "1 5", "output": "0" }, { "input": "1 6", "output": "0" }, { "input": "2 1", "output": "1" }, { "input": "2 2", "output": "1" }, { "input": "2 3", "output": "1" }, { "input": "2 4", "output": "1" }, { "input": "2 5", "output": "1" }, { "input": "3 1", "output": "3" }, { "input": "3 2", "output": "3" }, { "input": "3 3", "output": "3" }, { "input": "3 4", "output": "3" }, { "input": "3 5", "output": "3" }, { "input": "4 1", "output": "5" }, { "input": "4 2", "output": "6" }, { "input": "4 3", "output": "6" }, { "input": "4 4", "output": "6" }, { "input": "4 5", "output": "6" }, { "input": "5 1", "output": "7" }, { "input": "5 3", "output": "10" }, { "input": "5 4", "output": "10" }, { "input": "5 5", "output": "10" }, { "input": "6 1", "output": "9" }, { "input": "6 2", "output": "14" }, { "input": "6 3", "output": "15" }, { "input": "7 2", "output": "18" }, { "input": "7 3", "output": "21" }, { "input": "7 4", "output": "21" }, { "input": "10 2", "output": "30" }, { "input": "60982 2", "output": "243918" }, { "input": "23426 23", "output": "1076515" }, { "input": "444 3", "output": "2643" }, { "input": "18187 433", "output": "15374531" }, { "input": "6895 3544", "output": "23767065" }, { "input": "56204 22352", "output": "1513297456" }, { "input": "41977 5207", "output": "382917573" }, { "input": "78147 2321", "output": "351981971" }, { "input": "99742 62198", "output": "4974183411" }, { "input": "72099 38339", "output": "2599096851" }, { "input": "82532 4838", "output": "751762306" }, { "input": "79410 33144", "output": "3066847464" }, { "input": "11021 3389", "output": "51726307" }, { "input": "66900 7572", "output": "898455660" }, { "input": "99999 49999", "output": "4999850001" }, { "input": "100000 49999", "output": "4999949999" }, { "input": "100000 100000", "output": "4999950000" }, { "input": "100000 1", "output": "199997" }, { "input": "4 100", "output": "6" }, { "input": "100000 1234", "output": "243753254" } ]
1,611,725,058
2,147,483,647
Python 3
OK
TESTS
92
77
0
n, k = [int(x) for x in input().split()] if k >= n // 2: print(n * (n-1) // 2) else: print(k * (2* (n-k) - 1))
Title: Mischievous Mess Makers Time Limit: None seconds Memory Limit: None megabytes Problem Description: It is a balmy spring afternoon, and Farmer John's *n* cows are ruminating about link-cut cacti in their stalls. The cows, labeled 1 through *n*, are arranged so that the *i*-th cow occupies the *i*-th stall from the left. However, Elsie, after realizing that she will forever live in the shadows beyond Bessie's limelight, has formed the Mischievous Mess Makers and is plotting to disrupt this beautiful pastoral rhythm. While Farmer John takes his *k* minute long nap, Elsie and the Mess Makers plan to repeatedly choose two distinct stalls and swap the cows occupying those stalls, making no more than one swap each minute. Being the meticulous pranksters that they are, the Mischievous Mess Makers would like to know the maximum messiness attainable in the *k* minutes that they have. We denote as *p**i* the label of the cow in the *i*-th stall. The messiness of an arrangement of cows is defined as the number of pairs (*i*,<=*j*) such that *i*<=&lt;<=*j* and *p**i*<=&gt;<=*p**j*. Input Specification: The first line of the input contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100<=000) — the number of cows and the length of Farmer John's nap, respectively. Output Specification: Output a single integer, the maximum messiness that the Mischievous Mess Makers can achieve by performing no more than *k* swaps. Demo Input: ['5 2\n', '1 10\n'] Demo Output: ['10\n', '0\n'] Note: In the first sample, the Mischievous Mess Makers can swap the cows in the stalls 1 and 5 during the first minute, then the cows in stalls 2 and 4 during the second minute. This reverses the arrangement of cows, giving us a total messiness of 10. In the second sample, there is only one cow, so the maximum possible messiness is 0.
```python n, k = [int(x) for x in input().split()] if k >= n // 2: print(n * (n-1) // 2) else: print(k * (2* (n-k) - 1)) ```
3
686
A
Free Ice Cream
PROGRAMMING
800
[ "constructive algorithms", "implementation" ]
null
null
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer. At the start of the day they have *x* ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the queue wants either to take several ice cream packs for himself and his friends or to give several ice cream packs to Kay and Gerda (carriers that bring ice cream have to stand in the same queue). If a carrier with *d* ice cream packs comes to the house, then Kay and Gerda take all his packs. If a child who wants to take *d* ice cream packs comes to the house, then Kay and Gerda will give him *d* packs if they have enough ice cream, otherwise the child will get no ice cream at all and will leave in distress. Kay wants to find the amount of ice cream they will have after all people will leave from the queue, and Gerda wants to find the number of distressed kids.
The first line contains two space-separated integers *n* and *x* (1<=≤<=*n*<=≤<=1000, 0<=≤<=*x*<=≤<=109). Each of the next *n* lines contains a character '+' or '-', and an integer *d**i*, separated by a space (1<=≤<=*d**i*<=≤<=109). Record "+ *d**i*" in *i*-th line means that a carrier with *d**i* ice cream packs occupies *i*-th place from the start of the queue, and record "- *d**i*" means that a child who wants to take *d**i* packs stands in *i*-th place.
Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress.
[ "5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20\n", "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98\n" ]
[ "22 1\n", "3 2\n" ]
Consider the first sample. 1. Initially Kay and Gerda have 7 packs of ice cream. 1. Carrier brings 5 more, so now they have 12 packs. 1. A kid asks for 10 packs and receives them. There are only 2 packs remaining. 1. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. 1. Carrier bring 40 packs, now Kay and Gerda have 42 packs. 1. Kid asks for 20 packs and receives them. There are 22 packs remaining.
500
[ { "input": "5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20", "output": "22 1" }, { "input": "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98", "output": "3 2" }, { "input": "6 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000", "output": "7000000000 0" }, { "input": "5 12\n- 12\n+ 7\n- 6\n- 1\n+ 46", "output": "46 0" }, { "input": "11 1000\n- 100\n+ 100\n+ 100\n+ 100\n+ 100\n- 100\n- 100\n- 100\n- 100\n- 100\n- 100", "output": "700 0" }, { "input": "1 0\n- 526403222", "output": "0 1" }, { "input": "1 897986543\n- 371188251", "output": "526798292 0" }, { "input": "1 0\n+ 1", "output": "1 0" }, { "input": "1 0\n- 1", "output": "0 1" }, { "input": "1 10\n+ 10", "output": "20 0" }, { "input": "1 3\n- 5", "output": "3 1" }, { "input": "1 0\n- 5", "output": "0 1" }, { "input": "1 0\n+ 5", "output": "5 0" } ]
1,688,729,061
2,147,483,647
PyPy 3-64
OK
TESTS
34
92
1,740,800
n, x = input().split() icePacks, distressed = int(x), 0 for i in range(int(n)): sign, d = input().split() d = int(d) if sign == '+': icePacks += d else: if icePacks >= d: icePacks -= d else: distressed += 1 print(f"{icePacks} {distressed}")
Title: Free Ice Cream Time Limit: None seconds Memory Limit: None megabytes Problem Description: After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer. At the start of the day they have *x* ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the queue wants either to take several ice cream packs for himself and his friends or to give several ice cream packs to Kay and Gerda (carriers that bring ice cream have to stand in the same queue). If a carrier with *d* ice cream packs comes to the house, then Kay and Gerda take all his packs. If a child who wants to take *d* ice cream packs comes to the house, then Kay and Gerda will give him *d* packs if they have enough ice cream, otherwise the child will get no ice cream at all and will leave in distress. Kay wants to find the amount of ice cream they will have after all people will leave from the queue, and Gerda wants to find the number of distressed kids. Input Specification: The first line contains two space-separated integers *n* and *x* (1<=≤<=*n*<=≤<=1000, 0<=≤<=*x*<=≤<=109). Each of the next *n* lines contains a character '+' or '-', and an integer *d**i*, separated by a space (1<=≤<=*d**i*<=≤<=109). Record "+ *d**i*" in *i*-th line means that a carrier with *d**i* ice cream packs occupies *i*-th place from the start of the queue, and record "- *d**i*" means that a child who wants to take *d**i* packs stands in *i*-th place. Output Specification: Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress. Demo Input: ['5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20\n', '5 17\n- 16\n- 2\n- 98\n+ 100\n- 98\n'] Demo Output: ['22 1\n', '3 2\n'] Note: Consider the first sample. 1. Initially Kay and Gerda have 7 packs of ice cream. 1. Carrier brings 5 more, so now they have 12 packs. 1. A kid asks for 10 packs and receives them. There are only 2 packs remaining. 1. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. 1. Carrier bring 40 packs, now Kay and Gerda have 42 packs. 1. Kid asks for 20 packs and receives them. There are 22 packs remaining.
```python n, x = input().split() icePacks, distressed = int(x), 0 for i in range(int(n)): sign, d = input().split() d = int(d) if sign == '+': icePacks += d else: if icePacks >= d: icePacks -= d else: distressed += 1 print(f"{icePacks} {distressed}") ```
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,676,697,355
2,147,483,647
Python 3
OK
TESTS
64
46
0
# LUOGU_RID: 102386230 print(round(int(input())/10)*10)
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 # LUOGU_RID: 102386230 print(round(int(input())/10)*10) ```
3
551
A
GukiZ and Contest
PROGRAMMING
800
[ "brute force", "implementation", "sortings" ]
null
null
Professor GukiZ likes programming contests. He especially likes to rate his students on the contests he prepares. Now, he has decided to prepare a new contest. In total, *n* students will attend, and before the start, every one of them has some positive integer rating. Students are indexed from 1 to *n*. Let's denote the rating of *i*-th student as *a**i*. After the contest ends, every student will end up with some positive integer position. GukiZ expects that his students will take places according to their ratings. He thinks that each student will take place equal to . In particular, if student *A* has rating strictly lower then student *B*, *A* will get the strictly better position than *B*, and if two students have equal ratings, they will share the same position. GukiZ would like you to reconstruct the results by following his expectations. Help him and determine the position after the end of the contest for each of his students if everything goes as expected.
The first line contains integer *n* (1<=≤<=*n*<=≤<=2000), number of GukiZ's students. The second line contains *n* numbers *a*1,<=*a*2,<=... *a**n* (1<=≤<=*a**i*<=≤<=2000) where *a**i* is the rating of *i*-th student (1<=≤<=*i*<=≤<=*n*).
In a single line, print the position after the end of the contest for each of *n* students in the same order as they appear in the input.
[ "3\n1 3 3\n", "1\n1\n", "5\n3 5 3 4 5\n" ]
[ "3 1 1\n", "1\n", "4 1 4 3 1\n" ]
In the first sample, students 2 and 3 are positioned first (there is no other student with higher rating), and student 1 is positioned third since there are two students with higher rating. In the second sample, first student is the only one on the contest. In the third sample, students 2 and 5 share the first position with highest rating, student 4 is next with third position, and students 1 and 3 are the last sharing fourth position.
500
[ { "input": "3\n1 3 3", "output": "3 1 1" }, { "input": "1\n1", "output": "1" }, { "input": "5\n3 5 3 4 5", "output": "4 1 4 3 1" }, { "input": "7\n1 3 5 4 2 2 1", "output": "6 3 1 2 4 4 6" }, { "input": "11\n5 6 4 2 9 7 6 6 6 6 7", "output": "9 4 10 11 1 2 4 4 4 4 2" }, { "input": "1\n2000", "output": "1" }, { "input": "2\n2000 2000", "output": "1 1" }, { "input": "3\n500 501 502", "output": "3 2 1" }, { "input": "10\n105 106 1 1 1 11 1000 999 1000 999", "output": "6 5 8 8 8 7 1 3 1 3" }, { "input": "6\n1 2 3 4 5 6", "output": "6 5 4 3 2 1" }, { "input": "7\n6 5 4 3 2 1 1", "output": "1 2 3 4 5 6 6" }, { "input": "8\n153 100 87 14 10 8 6 5", "output": "1 2 3 4 5 6 7 8" }, { "input": "70\n11 54 37 62 1 46 13 17 38 47 28 15 63 5 61 34 49 66 32 59 3 41 58 28 23 62 41 64 20 5 14 41 10 37 51 32 65 46 61 8 15 19 16 44 31 42 19 46 66 25 26 58 60 5 19 18 69 53 20 40 45 27 24 41 32 23 57 56 62 10", "output": "62 18 35 7 70 23 61 56 34 22 42 58 6 66 10 37 21 2 38 13 69 29 14 42 48 7 29 5 50 66 60 29 63 35 20 38 4 23 10 65 58 52 57 27 41 28 52 23 2 46 45 14 12 66 52 55 1 19 50 33 26 44 47 29 38 48 16 17 7 63" }, { "input": "5\n1 2000 1 1 2000", "output": "3 1 3 3 1" } ]
1,553,330,643
2,147,483,647
PyPy 3
OK
TESTS
36
140
1,536,000
n = int(input().strip()) arr = list(map(int, input().strip().split())) sArr = sorted(arr, reverse=True) ranks = {sArr[0]: 1} for i in range(1, len(sArr)): if sArr[i] not in ranks: ranks[sArr[i]] = i+1 ans = [ranks[i] for i in arr] print(*ans)
Title: GukiZ and Contest Time Limit: None seconds Memory Limit: None megabytes Problem Description: Professor GukiZ likes programming contests. He especially likes to rate his students on the contests he prepares. Now, he has decided to prepare a new contest. In total, *n* students will attend, and before the start, every one of them has some positive integer rating. Students are indexed from 1 to *n*. Let's denote the rating of *i*-th student as *a**i*. After the contest ends, every student will end up with some positive integer position. GukiZ expects that his students will take places according to their ratings. He thinks that each student will take place equal to . In particular, if student *A* has rating strictly lower then student *B*, *A* will get the strictly better position than *B*, and if two students have equal ratings, they will share the same position. GukiZ would like you to reconstruct the results by following his expectations. Help him and determine the position after the end of the contest for each of his students if everything goes as expected. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=2000), number of GukiZ's students. The second line contains *n* numbers *a*1,<=*a*2,<=... *a**n* (1<=≤<=*a**i*<=≤<=2000) where *a**i* is the rating of *i*-th student (1<=≤<=*i*<=≤<=*n*). Output Specification: In a single line, print the position after the end of the contest for each of *n* students in the same order as they appear in the input. Demo Input: ['3\n1 3 3\n', '1\n1\n', '5\n3 5 3 4 5\n'] Demo Output: ['3 1 1\n', '1\n', '4 1 4 3 1\n'] Note: In the first sample, students 2 and 3 are positioned first (there is no other student with higher rating), and student 1 is positioned third since there are two students with higher rating. In the second sample, first student is the only one on the contest. In the third sample, students 2 and 5 share the first position with highest rating, student 4 is next with third position, and students 1 and 3 are the last sharing fourth position.
```python n = int(input().strip()) arr = list(map(int, input().strip().split())) sArr = sorted(arr, reverse=True) ranks = {sArr[0]: 1} for i in range(1, len(sArr)): if sArr[i] not in ranks: ranks[sArr[i]] = i+1 ans = [ranks[i] for i in arr] print(*ans) ```
3
353
A
Domino
PROGRAMMING
1,200
[ "implementation", "math" ]
null
null
Valera has got *n* domino pieces in a row. Each piece consists of two halves — the upper one and the lower one. Each of the halves contains a number from 1 to 6. Valera loves even integers very much, so he wants the sum of the numbers on the upper halves and the sum of the numbers on the lower halves to be even. To do that, Valera can rotate the dominoes by 180 degrees. After the rotation the upper and the lower halves swap places. This action takes one second. Help Valera find out the minimum time he must spend rotating dominoes to make his wish come true.
The first line contains integer *n* (1<=≤<=*n*<=≤<=100), denoting the number of dominoes Valera has. Next *n* lines contain two space-separated integers *x**i*,<=*y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=6). Number *x**i* is initially written on the upper half of the *i*-th domino, *y**i* is initially written on the lower half.
Print a single number — the minimum required number of seconds. If Valera can't do the task in any time, print <=-<=1.
[ "2\n4 2\n6 4\n", "1\n2 3\n", "3\n1 4\n2 3\n4 4\n" ]
[ "0\n", "-1\n", "1\n" ]
In the first test case the sum of the numbers on the upper halves equals 10 and the sum of the numbers on the lower halves equals 6. Both numbers are even, so Valera doesn't required to do anything. In the second sample Valera has only one piece of domino. It is written 3 on the one of its halves, therefore one of the sums will always be odd. In the third case Valera can rotate the first piece, and after that the sum on the upper halves will be equal to 10, and the sum on the lower halves will be equal to 8.
500
[ { "input": "2\n4 2\n6 4", "output": "0" }, { "input": "1\n2 3", "output": "-1" }, { "input": "3\n1 4\n2 3\n4 4", "output": "1" }, { "input": "5\n5 4\n5 4\n1 5\n5 5\n3 3", "output": "1" }, { "input": "20\n1 3\n5 2\n5 2\n2 6\n2 4\n1 1\n1 3\n1 4\n2 6\n4 2\n5 6\n2 2\n6 2\n4 3\n2 1\n6 2\n6 5\n4 5\n2 4\n1 4", "output": "-1" }, { "input": "100\n2 3\n2 4\n3 3\n1 4\n5 2\n5 4\n6 6\n3 4\n1 1\n4 2\n5 1\n5 5\n5 3\n3 6\n4 1\n1 6\n1 1\n3 2\n4 5\n6 1\n6 4\n1 1\n3 4\n3 3\n2 2\n1 1\n4 4\n6 4\n3 2\n5 2\n6 4\n3 2\n3 5\n4 4\n1 4\n5 2\n3 4\n1 4\n2 2\n5 6\n3 5\n6 1\n5 5\n1 6\n6 3\n1 4\n1 5\n5 5\n4 1\n3 2\n4 1\n5 5\n5 5\n1 5\n1 2\n6 4\n1 3\n3 6\n4 3\n3 5\n6 4\n2 6\n5 5\n1 4\n2 2\n2 3\n5 1\n2 5\n1 2\n2 6\n5 5\n4 6\n1 4\n3 6\n2 3\n6 1\n6 5\n3 2\n6 4\n4 5\n4 5\n2 6\n1 3\n6 2\n1 2\n2 3\n4 3\n5 4\n3 4\n1 6\n6 6\n2 4\n4 1\n3 1\n2 6\n5 4\n1 2\n6 5\n3 6\n2 4", "output": "-1" }, { "input": "1\n2 4", "output": "0" }, { "input": "1\n1 1", "output": "-1" }, { "input": "1\n1 2", "output": "-1" }, { "input": "2\n1 1\n3 3", "output": "0" }, { "input": "2\n1 1\n2 2", "output": "-1" }, { "input": "2\n1 1\n1 2", "output": "-1" }, { "input": "5\n1 2\n6 6\n1 1\n3 3\n6 1", "output": "1" }, { "input": "5\n5 4\n2 6\n6 2\n1 4\n6 2", "output": "0" }, { "input": "10\n4 1\n3 2\n1 2\n2 6\n3 5\n2 1\n5 2\n4 6\n5 6\n3 1", "output": "0" }, { "input": "10\n6 1\n4 4\n2 6\n6 5\n3 6\n6 3\n2 4\n5 1\n1 6\n1 5", "output": "-1" }, { "input": "15\n1 2\n5 1\n6 4\n5 1\n1 6\n2 6\n3 1\n6 4\n3 1\n2 1\n6 4\n3 5\n6 2\n1 6\n1 1", "output": "1" }, { "input": "15\n3 3\n2 1\n5 4\n3 3\n5 3\n5 4\n2 5\n1 3\n3 2\n3 3\n3 5\n2 5\n4 1\n2 3\n5 4", "output": "-1" }, { "input": "20\n1 5\n6 4\n4 3\n6 2\n1 1\n1 5\n6 3\n2 3\n3 6\n3 6\n3 6\n2 5\n4 3\n4 6\n5 5\n4 6\n3 4\n4 2\n3 3\n5 2", "output": "0" }, { "input": "20\n2 1\n6 5\n3 1\n2 5\n3 5\n4 1\n1 1\n5 4\n5 1\n2 4\n1 5\n3 2\n1 2\n3 5\n5 2\n1 2\n1 3\n4 2\n2 3\n4 5", "output": "-1" }, { "input": "25\n4 1\n6 3\n1 3\n2 3\n2 4\n6 6\n4 2\n4 2\n1 5\n5 4\n1 2\n2 5\n3 6\n4 1\n3 4\n2 6\n6 1\n5 6\n6 6\n4 2\n1 5\n3 3\n3 3\n6 5\n1 4", "output": "-1" }, { "input": "25\n5 5\n4 3\n2 5\n4 3\n4 6\n4 2\n5 6\n2 1\n5 4\n6 6\n1 3\n1 4\n2 3\n5 6\n5 4\n5 6\n5 4\n6 3\n3 5\n1 3\n2 5\n2 2\n4 4\n2 1\n4 4", "output": "-1" }, { "input": "30\n3 5\n2 5\n1 6\n1 6\n2 4\n5 5\n5 4\n5 6\n5 4\n2 1\n2 4\n1 6\n3 5\n1 1\n3 6\n5 5\n1 6\n3 4\n1 4\n4 6\n2 1\n3 3\n1 3\n4 5\n1 4\n1 6\n2 1\n4 6\n3 5\n5 6", "output": "1" }, { "input": "30\n2 3\n3 1\n6 6\n1 3\n5 5\n3 6\n4 5\n2 1\n1 3\n2 3\n4 4\n2 4\n6 4\n2 4\n5 4\n2 1\n2 5\n2 5\n4 2\n1 4\n2 6\n3 2\n3 2\n6 6\n4 2\n3 4\n6 3\n6 6\n6 6\n5 5", "output": "1" }, { "input": "35\n6 1\n4 3\n1 2\n4 3\n6 4\n4 6\n3 1\n5 5\n3 4\n5 4\n4 6\n1 6\n2 4\n6 6\n5 4\n5 2\n1 3\n1 4\n3 5\n1 4\n2 3\n4 5\n4 3\n6 1\n5 3\n3 2\n5 6\n3 5\n6 5\n4 1\n1 3\n5 5\n4 6\n6 1\n1 3", "output": "1" }, { "input": "35\n4 3\n5 6\n4 5\n2 5\n6 6\n4 1\n2 2\n4 2\n3 4\n4 1\n6 6\n6 3\n1 5\n1 5\n5 6\n4 2\n4 6\n5 5\n2 2\n5 2\n1 2\n4 6\n6 6\n6 5\n2 1\n3 5\n2 5\n3 1\n5 3\n6 4\n4 6\n5 6\n5 1\n3 4\n3 5", "output": "1" }, { "input": "40\n5 6\n1 1\n3 3\n2 6\n6 6\n5 4\n6 4\n3 5\n1 3\n4 4\n4 4\n2 5\n1 3\n3 6\n5 2\n4 3\n4 4\n5 6\n2 3\n1 1\n3 1\n1 1\n1 5\n4 3\n5 5\n3 4\n6 6\n5 6\n2 2\n6 6\n2 1\n2 4\n5 2\n2 2\n1 1\n1 4\n4 2\n3 5\n5 5\n4 5", "output": "-1" }, { "input": "40\n3 2\n5 3\n4 6\n3 5\n6 1\n5 2\n1 2\n6 2\n5 3\n3 2\n4 4\n3 3\n5 2\n4 5\n1 4\n5 1\n3 3\n1 3\n1 3\n2 1\n3 6\n4 2\n4 6\n6 2\n2 5\n2 2\n2 5\n3 3\n5 3\n2 1\n3 2\n2 3\n6 3\n6 3\n3 4\n3 2\n4 3\n5 4\n2 4\n4 6", "output": "-1" }, { "input": "45\n2 4\n3 4\n6 1\n5 5\n1 1\n3 5\n4 3\n5 2\n3 6\n6 1\n4 4\n6 1\n2 1\n6 1\n3 6\n3 3\n6 1\n1 2\n1 5\n6 5\n1 3\n5 6\n6 1\n4 5\n3 6\n2 2\n1 2\n4 5\n5 6\n1 5\n6 2\n2 4\n3 3\n3 1\n6 5\n6 5\n2 1\n5 2\n2 1\n3 3\n2 2\n1 4\n2 2\n3 3\n2 1", "output": "-1" }, { "input": "45\n6 6\n1 6\n1 2\n3 5\n4 4\n2 1\n5 3\n2 1\n5 2\n5 3\n1 4\n5 2\n4 2\n3 6\n5 2\n1 5\n4 4\n5 5\n6 5\n2 1\n2 6\n5 5\n2 1\n6 1\n1 6\n6 5\n2 4\n4 3\n2 6\n2 4\n6 5\n6 4\n6 3\n6 6\n2 1\n6 4\n5 6\n5 4\n1 5\n5 1\n3 3\n5 6\n2 5\n4 5\n3 6", "output": "-1" }, { "input": "50\n4 4\n5 1\n6 4\n6 2\n6 2\n1 4\n5 5\n4 2\n5 5\n5 4\n1 3\n3 5\n6 1\n6 1\n1 4\n4 3\n5 1\n3 6\n2 2\n6 2\n4 4\n2 3\n4 2\n6 5\n5 6\n2 2\n2 4\n3 5\n1 5\n3 2\n3 4\n5 6\n4 6\n1 6\n4 5\n2 6\n2 2\n3 5\n6 4\n5 1\n4 3\n3 4\n3 5\n3 3\n2 3\n3 2\n2 2\n1 4\n3 1\n4 4", "output": "1" }, { "input": "50\n1 2\n1 4\n1 1\n4 5\n4 4\n3 2\n4 5\n3 5\n1 1\n3 4\n3 2\n2 4\n2 6\n2 6\n3 2\n4 6\n1 6\n3 1\n1 6\n2 1\n4 1\n1 6\n4 3\n6 6\n5 2\n6 4\n2 1\n4 3\n6 4\n5 1\n5 5\n3 1\n1 1\n5 5\n2 2\n2 3\n2 3\n3 5\n5 5\n1 6\n1 5\n3 6\n3 6\n1 1\n3 3\n2 6\n5 5\n1 3\n6 3\n6 6", "output": "-1" }, { "input": "55\n3 2\n5 6\n5 1\n3 5\n5 5\n1 5\n5 4\n6 3\n5 6\n4 2\n3 1\n1 2\n5 5\n1 1\n5 2\n6 3\n5 4\n3 6\n4 6\n2 6\n6 4\n1 4\n1 6\n4 1\n2 5\n4 3\n2 1\n2 1\n6 2\n3 1\n2 5\n4 4\n6 3\n2 2\n3 5\n5 1\n3 6\n5 4\n4 6\n6 5\n5 6\n2 2\n3 2\n5 2\n6 5\n2 2\n5 3\n3 1\n4 5\n6 4\n2 4\n1 2\n5 6\n2 6\n5 2", "output": "0" }, { "input": "55\n4 6\n3 3\n6 5\n5 3\n5 6\n2 3\n2 2\n3 4\n3 1\n5 4\n5 4\n2 4\n3 4\n4 5\n1 5\n6 3\n1 1\n5 1\n3 4\n1 5\n3 1\n2 5\n3 3\n4 3\n3 3\n3 1\n6 6\n3 3\n3 3\n5 6\n5 3\n3 5\n1 4\n5 5\n1 3\n1 4\n3 5\n3 6\n2 4\n2 4\n5 1\n6 4\n5 1\n5 5\n1 1\n3 2\n4 3\n5 4\n5 1\n2 4\n4 3\n6 1\n3 4\n1 5\n6 3", "output": "-1" }, { "input": "60\n2 6\n1 4\n3 2\n1 2\n3 2\n2 4\n6 4\n4 6\n1 3\n3 1\n6 5\n2 4\n5 4\n4 2\n1 6\n3 4\n4 5\n5 2\n1 5\n5 4\n3 4\n3 4\n4 4\n4 1\n6 6\n3 6\n2 4\n2 1\n4 4\n6 5\n3 1\n4 3\n1 3\n6 3\n5 5\n1 4\n3 1\n3 6\n1 5\n3 1\n1 5\n4 4\n1 3\n2 4\n6 2\n4 1\n5 3\n3 4\n5 6\n1 2\n1 6\n6 3\n1 6\n3 6\n3 4\n6 2\n4 6\n2 3\n3 3\n3 3", "output": "-1" }, { "input": "60\n2 3\n4 6\n2 4\n1 3\n5 6\n1 5\n1 2\n1 3\n5 6\n4 3\n4 2\n3 1\n1 3\n3 5\n1 5\n3 4\n2 4\n3 5\n4 5\n1 2\n3 1\n1 5\n2 5\n6 2\n1 6\n3 3\n6 2\n5 3\n1 3\n1 4\n6 4\n6 3\n4 2\n4 2\n1 4\n1 3\n3 2\n3 1\n2 1\n1 2\n3 1\n2 6\n1 4\n3 6\n3 3\n1 5\n2 4\n5 5\n6 2\n5 2\n3 3\n5 3\n3 4\n4 5\n5 6\n2 4\n5 3\n3 1\n2 4\n5 4", "output": "-1" }, { "input": "65\n5 4\n3 3\n1 2\n4 3\n3 5\n1 5\n4 5\n2 6\n1 2\n1 5\n6 3\n2 6\n4 3\n3 6\n1 5\n3 5\n4 6\n2 5\n6 5\n1 4\n3 4\n4 3\n1 4\n2 5\n6 5\n3 1\n4 3\n1 2\n1 1\n6 1\n5 2\n3 2\n1 6\n2 6\n3 3\n6 6\n4 6\n1 5\n5 1\n4 5\n1 4\n3 2\n5 4\n4 2\n6 2\n1 3\n4 2\n5 3\n6 4\n3 6\n1 2\n6 1\n6 6\n3 3\n4 2\n3 5\n4 6\n4 1\n5 4\n6 1\n5 1\n5 6\n6 1\n4 6\n5 5", "output": "1" }, { "input": "65\n5 4\n6 3\n5 4\n4 5\n5 3\n3 6\n1 3\n3 1\n1 3\n6 1\n6 4\n1 3\n2 2\n4 6\n4 1\n5 6\n6 5\n1 1\n1 3\n6 6\n4 1\n2 4\n5 4\n4 1\n5 5\n5 3\n6 2\n2 6\n4 2\n2 2\n6 2\n3 3\n4 5\n4 3\n3 1\n1 4\n4 5\n3 2\n5 5\n4 6\n5 1\n3 4\n5 4\n5 2\n1 6\n4 2\n3 4\n3 4\n1 3\n1 2\n3 3\n3 6\n6 4\n4 6\n6 2\n6 5\n3 2\n2 1\n6 4\n2 1\n1 5\n5 2\n6 5\n3 6\n5 1", "output": "1" }, { "input": "70\n4 1\n2 6\n1 1\n5 6\n5 1\n2 3\n3 5\n1 1\n1 1\n4 6\n4 3\n1 5\n2 2\n2 3\n3 1\n6 4\n3 1\n4 2\n5 4\n1 3\n3 5\n5 2\n5 6\n4 4\n4 5\n2 2\n4 5\n3 2\n3 5\n2 5\n2 6\n5 5\n2 6\n5 1\n1 1\n2 5\n3 1\n1 2\n6 4\n6 5\n5 5\n5 1\n1 5\n2 2\n6 3\n4 3\n6 2\n5 5\n1 1\n6 2\n6 6\n3 4\n2 2\n3 5\n1 5\n2 5\n4 5\n2 4\n6 3\n5 1\n2 6\n4 2\n1 4\n1 6\n6 2\n5 2\n5 6\n2 5\n5 6\n5 5", "output": "-1" }, { "input": "70\n4 3\n6 4\n5 5\n3 1\n1 2\n2 5\n4 6\n4 2\n3 2\n4 2\n1 5\n2 2\n4 3\n1 2\n6 1\n6 6\n1 6\n5 1\n2 2\n6 3\n4 2\n4 3\n1 2\n6 6\n3 3\n6 5\n6 2\n3 6\n6 6\n4 6\n5 2\n5 4\n3 3\n1 6\n5 6\n2 3\n4 6\n1 1\n1 2\n6 6\n1 1\n3 4\n1 6\n2 6\n3 4\n6 3\n5 3\n1 2\n2 3\n4 6\n2 1\n6 4\n4 6\n4 6\n4 2\n5 5\n3 5\n3 2\n4 3\n3 6\n1 4\n3 6\n1 4\n1 6\n1 5\n5 6\n4 4\n3 3\n3 5\n2 2", "output": "0" }, { "input": "75\n1 3\n4 5\n4 1\n6 5\n2 1\n1 4\n5 4\n1 5\n5 3\n1 2\n4 1\n1 1\n5 1\n5 3\n1 5\n4 2\n2 2\n6 3\n1 2\n4 3\n2 5\n5 3\n5 5\n4 1\n4 6\n2 5\n6 1\n2 4\n6 4\n5 2\n6 2\n2 4\n1 3\n5 4\n6 5\n5 4\n6 4\n1 5\n4 6\n1 5\n1 1\n4 4\n3 5\n6 3\n6 5\n1 5\n2 1\n1 5\n6 6\n2 2\n2 2\n4 4\n6 6\n5 4\n4 5\n3 2\n2 4\n1 1\n4 3\n3 2\n5 4\n1 6\n1 2\n2 2\n3 5\n2 6\n1 1\n2 2\n2 3\n6 2\n3 6\n4 4\n5 1\n4 1\n4 1", "output": "0" }, { "input": "75\n1 1\n2 1\n5 5\n6 5\n6 3\n1 6\n6 1\n4 4\n2 1\n6 2\n3 1\n6 4\n1 6\n2 2\n4 3\n4 2\n1 2\n6 2\n4 2\n5 1\n1 2\n3 2\n6 6\n6 3\n2 4\n4 1\n4 1\n2 4\n5 5\n2 3\n5 5\n4 5\n3 1\n1 5\n4 3\n2 3\n3 5\n4 6\n5 6\n1 6\n2 3\n2 2\n1 2\n5 6\n1 4\n1 5\n1 3\n6 2\n1 2\n4 2\n2 1\n1 3\n6 4\n4 1\n5 2\n6 2\n3 5\n2 3\n4 2\n5 1\n5 6\n3 2\n2 1\n6 6\n2 1\n6 2\n1 1\n3 2\n1 2\n3 5\n4 6\n1 3\n3 4\n5 5\n6 2", "output": "1" }, { "input": "80\n3 1\n6 3\n2 2\n2 2\n6 3\n6 1\n6 5\n1 4\n3 6\n6 5\n1 3\n2 4\n1 4\n3 1\n5 3\n5 3\n1 4\n2 5\n4 3\n4 4\n4 5\n6 1\n3 1\n2 6\n4 2\n3 1\n6 5\n2 6\n2 2\n5 1\n1 3\n5 1\n2 1\n4 3\n6 3\n3 5\n4 3\n5 6\n3 3\n4 1\n5 1\n6 5\n5 1\n2 5\n6 1\n3 2\n4 3\n3 3\n5 6\n1 6\n5 2\n1 5\n5 6\n6 4\n2 2\n4 2\n4 6\n4 2\n4 4\n6 5\n5 2\n6 2\n4 6\n6 4\n4 3\n5 1\n4 1\n3 5\n3 2\n3 2\n5 3\n5 4\n3 4\n1 3\n1 2\n6 6\n6 3\n6 1\n5 6\n3 2", "output": "0" }, { "input": "80\n4 5\n3 3\n3 6\n4 5\n3 4\n6 5\n1 5\n2 5\n5 6\n5 1\n5 1\n1 2\n5 5\n5 1\n2 3\n1 1\n4 5\n4 1\n1 1\n5 5\n5 6\n5 2\n5 4\n4 2\n6 2\n5 3\n3 2\n4 2\n1 3\n1 6\n2 1\n6 6\n4 5\n6 4\n2 2\n1 6\n6 2\n4 3\n2 3\n4 6\n4 6\n6 2\n3 4\n4 3\n5 5\n1 6\n3 2\n4 6\n2 3\n1 6\n5 4\n4 2\n5 4\n1 1\n4 3\n5 1\n3 6\n6 2\n3 1\n4 1\n5 3\n2 2\n3 4\n3 6\n3 5\n5 5\n5 1\n3 5\n2 6\n6 3\n6 5\n3 3\n5 6\n1 2\n3 1\n6 3\n3 4\n6 6\n6 6\n1 2", "output": "-1" }, { "input": "85\n6 3\n4 1\n1 2\n3 5\n6 4\n6 2\n2 6\n1 2\n1 5\n6 2\n1 4\n6 6\n2 4\n4 6\n4 5\n1 6\n3 1\n2 5\n5 1\n5 2\n3 5\n1 1\n4 1\n2 3\n1 1\n3 3\n6 4\n1 4\n1 1\n3 6\n1 5\n1 6\n2 5\n2 2\n5 1\n6 6\n1 3\n1 5\n5 6\n4 5\n4 3\n5 5\n1 3\n6 3\n4 6\n2 4\n5 6\n6 2\n4 5\n1 4\n1 4\n6 5\n1 6\n6 1\n1 6\n5 5\n2 1\n5 2\n2 3\n1 6\n1 6\n1 6\n5 6\n2 4\n6 5\n6 5\n4 2\n5 4\n3 4\n4 3\n6 6\n3 3\n3 2\n3 6\n2 5\n2 1\n2 5\n3 4\n1 2\n5 4\n6 2\n5 1\n1 4\n3 4\n4 5", "output": "0" }, { "input": "85\n3 1\n3 2\n6 3\n1 3\n2 1\n3 6\n1 4\n2 5\n6 5\n1 6\n1 5\n1 1\n4 3\n3 5\n4 6\n3 2\n6 6\n4 4\n4 1\n5 5\n4 2\n6 2\n2 2\n4 5\n6 1\n3 4\n4 5\n3 5\n4 2\n3 5\n4 4\n3 1\n4 4\n6 4\n1 4\n5 5\n1 5\n2 2\n6 5\n5 6\n6 5\n3 2\n3 2\n6 1\n6 5\n2 1\n4 6\n2 1\n3 1\n5 6\n1 3\n5 4\n1 4\n1 4\n5 3\n2 3\n1 3\n2 2\n5 3\n2 3\n2 3\n1 3\n3 6\n4 4\n6 6\n6 2\n5 1\n5 5\n5 5\n1 2\n1 4\n2 4\n3 6\n4 6\n6 3\n6 4\n5 5\n3 2\n5 4\n5 4\n4 5\n6 4\n2 1\n5 2\n5 1", "output": "-1" }, { "input": "90\n5 2\n5 5\n5 1\n4 6\n4 3\n5 3\n5 6\n5 1\n3 4\n1 3\n4 2\n1 6\n6 4\n1 2\n6 1\n4 1\n6 2\n6 5\n6 2\n5 4\n3 6\n1 1\n5 5\n2 2\n1 6\n3 5\n6 5\n1 6\n1 5\n2 3\n2 6\n2 3\n3 3\n1 3\n5 1\n2 5\n3 6\n1 2\n4 4\n1 6\n2 3\n1 5\n2 5\n1 3\n2 2\n4 6\n3 6\n6 3\n1 2\n4 3\n4 5\n4 6\n3 2\n6 5\n6 2\n2 5\n2 4\n1 3\n1 6\n4 3\n1 3\n6 4\n4 6\n4 1\n1 1\n4 1\n4 4\n6 2\n6 5\n1 1\n2 2\n3 1\n1 4\n6 2\n5 2\n1 4\n1 3\n6 5\n3 2\n6 4\n3 4\n2 6\n2 2\n6 3\n4 6\n1 2\n4 2\n3 4\n2 3\n1 5", "output": "-1" }, { "input": "90\n1 4\n3 5\n4 2\n2 5\n4 3\n2 6\n2 6\n3 2\n4 4\n6 1\n4 3\n2 3\n5 3\n6 6\n2 2\n6 3\n4 1\n4 4\n5 6\n6 4\n4 2\n5 6\n4 6\n4 4\n6 4\n4 1\n5 3\n3 2\n4 4\n5 2\n5 4\n6 4\n1 2\n3 3\n3 4\n6 4\n1 6\n4 2\n3 2\n1 1\n2 2\n5 1\n6 6\n4 1\n5 2\n3 6\n2 1\n2 2\n4 6\n6 5\n4 4\n5 5\n5 6\n1 6\n1 4\n5 6\n3 6\n6 3\n5 6\n6 5\n5 1\n6 1\n6 6\n6 3\n1 5\n4 5\n3 1\n6 6\n3 4\n6 2\n1 4\n2 2\n3 2\n5 6\n2 4\n1 4\n6 3\n4 6\n1 4\n5 2\n1 2\n6 5\n1 5\n1 4\n4 2\n2 5\n3 2\n5 1\n5 4\n5 3", "output": "-1" }, { "input": "95\n4 3\n3 2\n5 5\n5 3\n1 6\n4 4\n5 5\n6 5\n3 5\n1 5\n4 2\n5 1\n1 2\n2 3\n6 4\n2 3\n6 3\n6 5\n5 6\n1 4\n2 6\n2 6\n2 5\n2 1\n3 1\n3 5\n2 2\n6 1\n2 4\n4 6\n6 6\n6 4\n3 2\n5 1\n4 3\n6 5\n2 3\n4 1\n2 5\n6 5\n6 5\n6 5\n5 1\n5 4\n4 6\n3 2\n2 5\n2 6\n4 6\n6 3\n6 4\n5 6\n4 6\n2 4\n3 4\n1 4\n2 4\n2 3\n5 6\n6 4\n3 1\n5 1\n3 6\n3 5\n2 6\n6 3\n4 3\n3 1\n6 1\n2 2\n6 3\n2 2\n2 2\n6 4\n6 1\n2 1\n5 6\n5 4\n5 2\n3 4\n3 6\n2 1\n1 6\n5 5\n2 6\n2 3\n3 6\n1 3\n1 5\n5 1\n1 2\n2 2\n5 3\n6 4\n4 5", "output": "0" }, { "input": "95\n4 5\n5 6\n3 2\n5 1\n4 3\n4 1\n6 1\n5 2\n2 4\n5 3\n2 3\n6 4\n4 1\n1 6\n2 6\n2 3\n4 6\n2 4\n3 4\n4 2\n5 5\n1 1\n1 5\n4 3\n4 5\n6 2\n6 1\n6 3\n5 5\n4 1\n5 1\n2 3\n5 1\n3 6\n6 6\n4 5\n4 4\n4 3\n1 6\n6 6\n4 6\n6 4\n1 2\n6 2\n4 6\n6 6\n5 5\n6 1\n5 2\n4 5\n6 6\n6 5\n4 4\n1 5\n4 6\n4 1\n3 6\n5 1\n3 1\n4 6\n4 5\n1 3\n5 4\n4 5\n2 2\n6 1\n5 2\n6 5\n2 2\n1 1\n6 3\n6 1\n2 6\n3 3\n2 1\n4 6\n2 4\n5 5\n5 2\n3 2\n1 2\n6 6\n6 2\n5 1\n2 6\n5 2\n2 2\n5 5\n3 5\n3 3\n2 6\n5 3\n4 3\n1 6\n5 4", "output": "-1" }, { "input": "100\n1 1\n3 5\n2 1\n1 2\n3 4\n5 6\n5 6\n6 1\n5 5\n2 4\n5 5\n5 6\n6 2\n6 6\n2 6\n1 4\n2 2\n3 2\n1 3\n5 5\n6 3\n5 6\n1 1\n1 2\n1 2\n2 1\n2 3\n1 6\n4 3\n1 1\n2 5\n2 4\n4 4\n1 5\n3 3\n6 1\n3 5\n1 1\n3 6\n3 1\n4 2\n4 3\n3 6\n6 6\n1 6\n6 2\n2 5\n5 4\n6 3\n1 4\n2 6\n6 2\n3 4\n6 1\n6 5\n4 6\n6 5\n4 4\n3 1\n6 3\n5 1\n2 4\n5 1\n1 2\n2 4\n2 1\n6 6\n5 3\n4 6\n6 3\n5 5\n3 3\n1 1\n6 5\n4 3\n2 6\n1 5\n3 5\n2 4\n4 5\n1 6\n2 3\n6 3\n5 5\n2 6\n2 6\n3 4\n3 2\n6 1\n3 4\n6 4\n3 3\n2 3\n5 1\n3 1\n6 2\n2 3\n6 4\n1 4\n1 2", "output": "-1" }, { "input": "100\n1 1\n5 5\n1 2\n5 3\n5 5\n2 2\n1 5\n3 4\n3 2\n1 3\n5 6\n4 5\n2 1\n5 5\n2 2\n1 6\n6 1\n5 1\n4 1\n4 6\n3 5\n6 1\n2 3\n5 6\n3 6\n2 3\n5 6\n1 6\n3 2\n2 2\n3 3\n6 5\n5 5\n1 4\n5 6\n6 4\n1 4\n1 2\n2 6\n3 2\n6 4\n5 3\n3 3\n6 4\n4 6\n2 2\n5 6\n5 1\n1 2\n3 4\n4 5\n1 1\n3 4\n5 2\n4 5\n3 3\n1 1\n3 4\n1 6\n2 4\n1 3\n3 2\n6 5\n1 6\n3 6\n2 3\n2 6\n5 1\n5 5\n5 6\n4 1\n6 2\n3 6\n5 3\n2 2\n2 4\n6 6\n3 6\n4 6\n2 5\n5 3\n1 2\n3 4\n3 4\n6 2\n2 4\n2 2\n4 6\n3 5\n4 2\n5 6\n4 2\n2 3\n6 2\n5 6\n2 1\n3 3\n6 6\n4 3\n4 2", "output": "1" }, { "input": "1\n2 2", "output": "0" }, { "input": "3\n2 4\n6 6\n3 3", "output": "-1" }, { "input": "2\n3 6\n4 1", "output": "1" }, { "input": "3\n1 1\n1 1\n3 3", "output": "-1" }, { "input": "3\n2 3\n1 1\n2 3", "output": "1" }, { "input": "3\n2 2\n2 1\n1 2", "output": "1" }, { "input": "3\n1 1\n1 1\n1 1", "output": "-1" } ]
1,639,288,657
2,147,483,647
Python 3
OK
TESTS
59
122
0
def solve(n, arr): up = [] lo = [] for x, y in arr: up.append(x) lo.append(y) ans = -1 if sum(up) % 2 != 0 and sum(lo) % 2 != 0: for i in range(n): a, b = 0, 0 a = sum(up) - up[i] + lo[i] b = sum(lo) - up[i] + lo[i] if a % 2 == 0 and b % 2 == 0: ans = 1 break elif sum(up) % 2 == 0 and sum(lo) % 2 == 0: ans = 0 return ans n = int(input()) arr = [] for i in range(n): arr.append(list(map(int, input().split()))) print(solve(n, arr))
Title: Domino Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera has got *n* domino pieces in a row. Each piece consists of two halves — the upper one and the lower one. Each of the halves contains a number from 1 to 6. Valera loves even integers very much, so he wants the sum of the numbers on the upper halves and the sum of the numbers on the lower halves to be even. To do that, Valera can rotate the dominoes by 180 degrees. After the rotation the upper and the lower halves swap places. This action takes one second. Help Valera find out the minimum time he must spend rotating dominoes to make his wish come true. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=100), denoting the number of dominoes Valera has. Next *n* lines contain two space-separated integers *x**i*,<=*y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=6). Number *x**i* is initially written on the upper half of the *i*-th domino, *y**i* is initially written on the lower half. Output Specification: Print a single number — the minimum required number of seconds. If Valera can't do the task in any time, print <=-<=1. Demo Input: ['2\n4 2\n6 4\n', '1\n2 3\n', '3\n1 4\n2 3\n4 4\n'] Demo Output: ['0\n', '-1\n', '1\n'] Note: In the first test case the sum of the numbers on the upper halves equals 10 and the sum of the numbers on the lower halves equals 6. Both numbers are even, so Valera doesn't required to do anything. In the second sample Valera has only one piece of domino. It is written 3 on the one of its halves, therefore one of the sums will always be odd. In the third case Valera can rotate the first piece, and after that the sum on the upper halves will be equal to 10, and the sum on the lower halves will be equal to 8.
```python def solve(n, arr): up = [] lo = [] for x, y in arr: up.append(x) lo.append(y) ans = -1 if sum(up) % 2 != 0 and sum(lo) % 2 != 0: for i in range(n): a, b = 0, 0 a = sum(up) - up[i] + lo[i] b = sum(lo) - up[i] + lo[i] if a % 2 == 0 and b % 2 == 0: ans = 1 break elif sum(up) % 2 == 0 and sum(lo) % 2 == 0: ans = 0 return ans n = int(input()) arr = [] for i in range(n): arr.append(list(map(int, input().split()))) print(solve(n, arr)) ```
3
842
A
Kirill And The Game
PROGRAMMING
1,200
[ "brute force", "two pointers" ]
null
null
Kirill plays a new computer game. He came to the potion store where he can buy any potion. Each potion is characterized by two integers — amount of experience and cost. The efficiency of a potion is the ratio of the amount of experience to the cost. Efficiency may be a non-integer number. For each two integer numbers *a* and *b* such that *l*<=≤<=*a*<=≤<=*r* and *x*<=≤<=*b*<=≤<=*y* there is a potion with experience *a* and cost *b* in the store (that is, there are (*r*<=-<=*l*<=+<=1)·(*y*<=-<=*x*<=+<=1) potions). Kirill wants to buy a potion which has efficiency *k*. Will he be able to do this?
First string contains five integer numbers *l*, *r*, *x*, *y*, *k* (1<=≤<=*l*<=≤<=*r*<=≤<=107, 1<=≤<=*x*<=≤<=*y*<=≤<=107, 1<=≤<=*k*<=≤<=107).
Print "YES" without quotes if a potion with efficiency exactly *k* can be bought in the store and "NO" without quotes otherwise. You can output each of the letters in any register.
[ "1 10 1 10 1\n", "1 5 6 10 1\n" ]
[ "YES", "NO" ]
none
500
[ { "input": "1 10 1 10 1", "output": "YES" }, { "input": "1 5 6 10 1", "output": "NO" }, { "input": "1 1 1 1 1", "output": "YES" }, { "input": "1 1 1 1 2", "output": "NO" }, { "input": "1 100000 1 100000 100000", "output": "YES" }, { "input": "1 100000 1 100000 100001", "output": "NO" }, { "input": "25 10000 200 10000 5", "output": "YES" }, { "input": "1 100000 10 100000 50000", "output": "NO" }, { "input": "91939 94921 10197 89487 1", "output": "NO" }, { "input": "30518 58228 74071 77671 1", "output": "NO" }, { "input": "46646 79126 78816 91164 5", "output": "NO" }, { "input": "30070 83417 92074 99337 2", "output": "NO" }, { "input": "13494 17544 96820 99660 6", "output": "NO" }, { "input": "96918 97018 10077 86510 9", "output": "YES" }, { "input": "13046 45594 14823 52475 1", "output": "YES" }, { "input": "29174 40572 95377 97669 4", "output": "NO" }, { "input": "79894 92433 8634 86398 4", "output": "YES" }, { "input": "96022 98362 13380 94100 6", "output": "YES" }, { "input": "79446 95675 93934 96272 3", "output": "NO" }, { "input": "5440 46549 61481 99500 10", "output": "NO" }, { "input": "21569 53580 74739 87749 3", "output": "NO" }, { "input": "72289 78297 79484 98991 7", "output": "NO" }, { "input": "88417 96645 92742 98450 5", "output": "NO" }, { "input": "71841 96625 73295 77648 8", "output": "NO" }, { "input": "87969 99230 78041 94736 4", "output": "NO" }, { "input": "4 4 1 2 3", "output": "NO" }, { "input": "150 150 1 2 100", "output": "NO" }, { "input": "99 100 1 100 50", "output": "YES" }, { "input": "7 7 3 6 2", "output": "NO" }, { "input": "10 10 1 10 1", "output": "YES" }, { "input": "36 36 5 7 6", "output": "YES" }, { "input": "73 96 1 51 51", "output": "NO" }, { "input": "3 3 1 3 2", "output": "NO" }, { "input": "10000000 10000000 1 100000 10000000", "output": "YES" }, { "input": "9222174 9829060 9418763 9955619 9092468", "output": "NO" }, { "input": "70 70 1 2 50", "output": "NO" }, { "input": "100 200 1 20 5", "output": "YES" }, { "input": "1 200000 65536 65536 65537", "output": "NO" }, { "input": "15 15 1 100 1", "output": "YES" }, { "input": "10000000 10000000 1 10000000 100000", "output": "YES" }, { "input": "10 10 2 5 4", "output": "NO" }, { "input": "67 69 7 7 9", "output": "NO" }, { "input": "100000 10000000 1 10000000 100000", "output": "YES" }, { "input": "9 12 1 2 7", "output": "NO" }, { "input": "5426234 6375745 2636512 8492816 4409404", "output": "NO" }, { "input": "6134912 6134912 10000000 10000000 999869", "output": "NO" }, { "input": "3 3 1 100 1", "output": "YES" }, { "input": "10000000 10000000 10 10000000 100000", "output": "YES" }, { "input": "4 4 1 100 2", "output": "YES" }, { "input": "8 13 1 4 7", "output": "NO" }, { "input": "10 10 100000 10000000 10000000", "output": "NO" }, { "input": "5 6 1 4 2", "output": "YES" }, { "input": "1002 1003 1 2 1000", "output": "NO" }, { "input": "4 5 1 2 2", "output": "YES" }, { "input": "5 6 1 5 1", "output": "YES" }, { "input": "15 21 2 4 7", "output": "YES" }, { "input": "4 5 3 7 1", "output": "YES" }, { "input": "15 15 3 4 4", "output": "NO" }, { "input": "3 6 1 2 2", "output": "YES" }, { "input": "2 10 3 6 3", "output": "YES" }, { "input": "1 10000000 1 10000000 100000", "output": "YES" }, { "input": "8 13 1 2 7", "output": "NO" }, { "input": "98112 98112 100000 100000 128850", "output": "NO" }, { "input": "2 2 1 2 1", "output": "YES" }, { "input": "8 8 3 4 2", "output": "YES" }, { "input": "60 60 2 3 25", "output": "NO" }, { "input": "16 17 2 5 5", "output": "NO" }, { "input": "2 4 1 3 1", "output": "YES" }, { "input": "4 5 1 2 3", "output": "NO" }, { "input": "10 10 3 4 3", "output": "NO" }, { "input": "10 10000000 999999 10000000 300", "output": "NO" }, { "input": "100 120 9 11 10", "output": "YES" }, { "input": "8 20 1 3 4", "output": "YES" }, { "input": "10 14 2 3 4", "output": "YES" }, { "input": "2000 2001 1 3 1000", "output": "YES" }, { "input": "12 13 2 3 5", "output": "NO" }, { "input": "7 7 2 3 3", "output": "NO" }, { "input": "5 8 1 10000000 4", "output": "YES" }, { "input": "5 5 1 1 4", "output": "NO" }, { "input": "5 5 1 6 2", "output": "NO" }, { "input": "200 300 4000381 4000382 4000381", "output": "NO" }, { "input": "11 17 2 5 2", "output": "NO" }, { "input": "9999999 10000000 1 10000000 999997", "output": "NO" }, { "input": "7 8 2 3 3", "output": "NO" }, { "input": "7 7 3 3 2", "output": "NO" }, { "input": "15 15 2 3 7", "output": "NO" }, { "input": "65408 65408 859 859 10000000", "output": "NO" }, { "input": "1000000 10000000 1 100000 1", "output": "NO" }, { "input": "6 12 2 3 2", "output": "YES" }, { "input": "7 8 1 3 3", "output": "NO" }, { "input": "4 4 1 2 2", "output": "YES" }, { "input": "2 3 1 2 2", "output": "YES" }, { "input": "11 14 2 3 5", "output": "NO" }, { "input": "7 7 1 10 3", "output": "NO" }, { "input": "49 50 1 2 27", "output": "NO" }, { "input": "1 10000000 1 10000000 123456", "output": "YES" }, { "input": "100000 10000000 100 10000000 100000", "output": "YES" }, { "input": "17 19 2 3 8", "output": "NO" }, { "input": "4 6 3 9 1", "output": "YES" }, { "input": "19 20 6 7 3", "output": "NO" }, { "input": "5000000 10000000 1 4999999 1", "output": "NO" } ]
1,695,396,186
2,147,483,647
Python 3
OK
TESTS
101
904
0
l,r,x,y,k=[int(i) for i in input().split()] a=[];b=[];c=[];m=0 for i in range(x,y+1): if (k*i) <=r and (k*i)>=l : print('YES') ; break else : print('NO')
Title: Kirill And The Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Kirill plays a new computer game. He came to the potion store where he can buy any potion. Each potion is characterized by two integers — amount of experience and cost. The efficiency of a potion is the ratio of the amount of experience to the cost. Efficiency may be a non-integer number. For each two integer numbers *a* and *b* such that *l*<=≤<=*a*<=≤<=*r* and *x*<=≤<=*b*<=≤<=*y* there is a potion with experience *a* and cost *b* in the store (that is, there are (*r*<=-<=*l*<=+<=1)·(*y*<=-<=*x*<=+<=1) potions). Kirill wants to buy a potion which has efficiency *k*. Will he be able to do this? Input Specification: First string contains five integer numbers *l*, *r*, *x*, *y*, *k* (1<=≤<=*l*<=≤<=*r*<=≤<=107, 1<=≤<=*x*<=≤<=*y*<=≤<=107, 1<=≤<=*k*<=≤<=107). Output Specification: Print "YES" without quotes if a potion with efficiency exactly *k* can be bought in the store and "NO" without quotes otherwise. You can output each of the letters in any register. Demo Input: ['1 10 1 10 1\n', '1 5 6 10 1\n'] Demo Output: ['YES', 'NO'] Note: none
```python l,r,x,y,k=[int(i) for i in input().split()] a=[];b=[];c=[];m=0 for i in range(x,y+1): if (k*i) <=r and (k*i)>=l : print('YES') ; break else : print('NO') ```
3
490
A
Team Olympiad
PROGRAMMING
800
[ "greedy", "implementation", "sortings" ]
null
null
The School №0 of the capital of Berland has *n* children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value *t**i*: - *t**i*<==<=1, if the *i*-th child is good at programming, - *t**i*<==<=2, if the *i*-th child is good at maths, - *t**i*<==<=3, if the *i*-th child is good at PE Each child happens to be good at exactly one of these three subjects. The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team. What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that?
The first line contains integer *n* (1<=≤<=*n*<=≤<=5000) — the number of children in the school. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=3), where *t**i* describes the skill of the *i*-th child.
In the first line output integer *w* — the largest possible number of teams. Then print *w* lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to *n* in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them. If no teams can be compiled, print the only line with value *w* equal to 0.
[ "7\n1 3 1 3 2 1 2\n", "4\n2 1 1 2\n" ]
[ "2\n3 5 2\n6 7 4\n", "0\n" ]
none
500
[ { "input": "7\n1 3 1 3 2 1 2", "output": "2\n3 5 2\n6 7 4" }, { "input": "4\n2 1 1 2", "output": "0" }, { "input": "1\n2", "output": "0" }, { "input": "2\n3 1", "output": "0" }, { "input": "3\n2 1 2", "output": "0" }, { "input": "3\n1 2 3", "output": "1\n1 2 3" }, { "input": "12\n3 3 3 3 3 3 3 3 1 3 3 2", "output": "1\n9 12 2" }, { "input": "60\n3 3 1 2 2 1 3 1 1 1 3 2 2 2 3 3 1 3 2 3 2 2 1 3 3 2 3 1 2 2 2 1 3 2 1 1 3 3 1 1 1 3 1 2 1 1 3 3 3 2 3 2 3 2 2 2 1 1 1 2", "output": "20\n6 60 1\n17 44 20\n3 5 33\n36 21 42\n59 14 2\n58 26 49\n9 29 48\n23 19 24\n10 30 37\n41 54 15\n45 31 27\n57 55 38\n39 12 25\n35 34 11\n32 52 7\n8 50 18\n43 4 53\n46 56 51\n40 22 16\n28 13 47" }, { "input": "12\n3 1 1 1 1 1 1 2 1 1 1 1", "output": "1\n3 8 1" }, { "input": "22\n2 2 2 2 2 2 2 2 2 2 3 2 2 2 2 2 2 1 2 2 2 2", "output": "1\n18 2 11" }, { "input": "138\n2 3 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 3 2 2 2 1 2 3 2 2 2 3 1 3 2 3 2 3 2 2 2 2 3 2 2 2 2 2 1 2 2 3 2 2 3 2 1 2 2 2 2 2 3 1 2 2 2 2 2 3 2 2 3 2 2 2 2 2 1 1 2 3 2 2 2 2 3 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 3 2 3 2 2 2 1 2 2 2 1 2 2 2 2 1 2 2 2 2 1 3", "output": "18\n13 91 84\n34 90 48\n11 39 77\n78 129 50\n137 68 119\n132 122 138\n19 12 96\n40 7 2\n22 88 69\n107 73 46\n115 15 52\n127 106 87\n93 92 66\n71 112 117\n63 124 42\n17 70 101\n109 121 57\n123 25 36" }, { "input": "203\n2 2 1 2 1 2 2 2 1 2 2 1 1 3 1 2 1 2 1 1 2 3 1 1 2 3 3 2 2 2 1 2 1 1 1 1 1 3 1 1 2 1 1 2 2 2 1 2 2 2 1 2 3 2 1 1 2 2 1 2 1 2 2 1 1 2 2 2 1 1 2 2 1 2 1 2 2 3 2 1 2 1 1 1 1 1 1 1 1 1 1 2 2 1 1 2 2 2 2 1 1 1 1 1 1 1 2 2 2 2 2 1 1 1 2 2 2 1 2 2 1 3 2 1 1 1 2 1 1 2 1 1 2 2 2 1 1 2 2 2 1 2 1 3 2 1 2 2 2 1 1 1 2 2 2 1 2 1 1 2 2 2 2 2 1 1 2 1 2 2 1 1 1 1 1 1 2 2 3 1 1 2 3 1 1 1 1 1 1 2 2 1 1 1 2 2 3 2 1 3 1 1 1", "output": "13\n188 72 14\n137 4 197\n158 76 122\n152 142 26\n104 119 179\n40 63 38\n12 1 78\n17 30 27\n189 60 53\n166 190 144\n129 7 183\n83 41 22\n121 81 200" }, { "input": "220\n1 1 3 1 3 1 1 3 1 3 3 3 3 1 3 3 1 3 3 3 3 3 1 1 1 3 1 1 1 3 2 3 3 3 1 1 3 3 1 1 3 3 3 3 1 3 3 1 1 1 2 3 1 1 1 2 3 3 3 2 3 1 1 3 1 1 1 3 2 1 3 2 3 1 1 3 3 3 1 3 1 1 1 3 3 2 1 3 2 1 1 3 3 1 1 1 2 1 1 3 2 1 2 1 1 1 3 1 3 3 1 2 3 3 3 3 1 3 1 1 1 1 2 3 1 1 1 1 1 1 3 2 3 1 3 1 3 1 1 3 1 3 1 3 1 3 1 3 3 2 3 1 3 3 1 3 3 3 3 1 1 3 3 3 3 1 1 3 3 3 2 1 1 1 3 3 1 3 3 3 1 1 1 3 1 3 3 1 1 1 2 3 1 1 3 1 1 1 1 2 3 1 1 2 3 3 1 3 1 3 3 3 3 1 3 2 3 1 1 3", "output": "20\n198 89 20\n141 56 131\n166 204 19\n160 132 142\n111 112 195\n45 216 92\n6 31 109\n14 150 170\n199 60 18\n173 123 140\n134 69 156\n82 191 85\n126 200 80\n24 97 46\n62 86 149\n214 101 26\n79 171 78\n125 72 118\n172 103 162\n219 51 64" }, { "input": "61\n2 3 1 3 2 2 2 3 1 3 2 3 1 2 1 1 2 2 2 2 3 2 3 1 2 1 3 1 3 2 1 1 3 2 1 3 3 3 1 3 3 1 1 3 1 3 2 2 1 2 2 2 1 3 2 3 1 3 3 1 1", "output": "20\n9 55 2\n24 34 27\n3 5 37\n35 17 41\n61 11 4\n60 19 54\n15 20 59\n26 14 29\n16 22 38\n43 50 12\n49 25 36\n57 51 40\n39 6 33\n32 30 10\n31 48 8\n13 47 23\n45 1 58\n53 52 56\n42 18 21\n28 7 44" }, { "input": "5\n1 2 2 3 3", "output": "1\n1 3 4" } ]
1,673,722,477
2,147,483,647
Python 3
OK
TESTS
41
546
0
n = int(input("")) l = list(map(int,input("").split())) a = [l.count(1),l.count(2),l.count(3)] print(min(a)) for i in range(min(a)): print(str(l.index(1) + 1), str(l.index(2) + 1),str(l.index(3) + 1)) x = l.index(1) y = l.index(2) z = l.index(3) l.remove(1);l.insert(x,10) l.remove(2);l.insert(y,10) l.remove(3);l.insert(z,10)
Title: Team Olympiad Time Limit: None seconds Memory Limit: None megabytes Problem Description: The School №0 of the capital of Berland has *n* children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value *t**i*: - *t**i*<==<=1, if the *i*-th child is good at programming, - *t**i*<==<=2, if the *i*-th child is good at maths, - *t**i*<==<=3, if the *i*-th child is good at PE Each child happens to be good at exactly one of these three subjects. The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team. What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that? Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=5000) — the number of children in the school. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=3), where *t**i* describes the skill of the *i*-th child. Output Specification: In the first line output integer *w* — the largest possible number of teams. Then print *w* lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to *n* in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them. If no teams can be compiled, print the only line with value *w* equal to 0. Demo Input: ['7\n1 3 1 3 2 1 2\n', '4\n2 1 1 2\n'] Demo Output: ['2\n3 5 2\n6 7 4\n', '0\n'] Note: none
```python n = int(input("")) l = list(map(int,input("").split())) a = [l.count(1),l.count(2),l.count(3)] print(min(a)) for i in range(min(a)): print(str(l.index(1) + 1), str(l.index(2) + 1),str(l.index(3) + 1)) x = l.index(1) y = l.index(2) z = l.index(3) l.remove(1);l.insert(x,10) l.remove(2);l.insert(y,10) l.remove(3);l.insert(z,10) ```
3
621
C
Wet Shark and Flowers
PROGRAMMING
1,700
[ "combinatorics", "math", "number theory", "probabilities" ]
null
null
There are *n* sharks who grow flowers for Wet Shark. They are all sitting around the table, such that sharks *i* and *i*<=+<=1 are neighbours for all *i* from 1 to *n*<=-<=1. Sharks *n* and 1 are neighbours too. Each shark will grow some number of flowers *s**i*. For *i*-th shark value *s**i* is random integer equiprobably chosen in range from *l**i* to *r**i*. Wet Shark has it's favourite prime number *p*, and he really likes it! If for any pair of neighbouring sharks *i* and *j* the product *s**i*·*s**j* is divisible by *p*, then Wet Shark becomes happy and gives 1000 dollars to each of these sharks. At the end of the day sharks sum all the money Wet Shark granted to them. Find the expectation of this value.
The first line of the input contains two space-separated integers *n* and *p* (3<=≤<=*n*<=≤<=100<=000,<=2<=≤<=*p*<=≤<=109) — the number of sharks and Wet Shark's favourite prime number. It is guaranteed that *p* is prime. The *i*-th of the following *n* lines contains information about *i*-th shark — two space-separated integers *l**i* and *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=109), the range of flowers shark *i* can produce. Remember that *s**i* is chosen equiprobably among all integers from *l**i* to *r**i*, inclusive.
Print a single real number — the expected number of dollars that the sharks receive in total. You answer will be considered correct if its absolute or relative error does not exceed 10<=-<=6. Namely: let's assume that your answer is *a*, and the answer of the jury is *b*. The checker program will consider your answer correct, if .
[ "3 2\n1 2\n420 421\n420420 420421\n", "3 5\n1 4\n2 3\n11 14\n" ]
[ "4500.0\n", "0.0\n" ]
A prime number is a positive integer number that is divisible only by 1 and itself. 1 is not considered to be prime. Consider the first sample. First shark grows some number of flowers from 1 to 2, second sharks grows from 420 to 421 flowers and third from 420420 to 420421. There are eight cases for the quantities of flowers (*s*<sub class="lower-index">0</sub>, *s*<sub class="lower-index">1</sub>, *s*<sub class="lower-index">2</sub>) each shark grows: 1. (1, 420, 420420): note that *s*<sub class="lower-index">0</sub>·*s*<sub class="lower-index">1</sub> = 420, *s*<sub class="lower-index">1</sub>·*s*<sub class="lower-index">2</sub> = 176576400, and *s*<sub class="lower-index">2</sub>·*s*<sub class="lower-index">0</sub> = 420420. For each pair, 1000 dollars will be awarded to each shark. Therefore, each shark will be awarded 2000 dollars, for a total of 6000 dollars.1. (1, 420, 420421): now, the product *s*<sub class="lower-index">2</sub>·*s*<sub class="lower-index">0</sub> is not divisible by 2. Therefore, sharks *s*<sub class="lower-index">0</sub> and *s*<sub class="lower-index">2</sub> will receive 1000 dollars, while shark *s*<sub class="lower-index">1</sub> will receive 2000. The total is 4000.1. (1, 421, 420420): total is 4000 1. (1, 421, 420421): total is 0. 1. (2, 420, 420420): total is 6000. 1. (2, 420, 420421): total is 6000. 1. (2, 421, 420420): total is 6000. 1. (2, 421, 420421): total is 4000. The expected value is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/dfe520d00a8615f7c270ccbccbebe182cc7db883.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In the second sample, no combination of quantities will garner the sharks any money.
1,500
[ { "input": "3 2\n1 2\n420 421\n420420 420421", "output": "4500.0" }, { "input": "3 5\n1 4\n2 3\n11 14", "output": "0.0" }, { "input": "3 3\n3 3\n2 4\n1 1", "output": "4666.666666666667" }, { "input": "5 5\n5 204\n420 469\n417 480\n442 443\n44 46", "output": "3451.25" }, { "input": "3 2\n2 2\n3 3\n4 4", "output": "6000.0" }, { "input": "6 7\n8 13\n14 14\n8 13\n14 14\n8 13\n14 14", "output": "12000.0" }, { "input": "3 7\n7 14\n700000000 700000007\n420 4200", "output": "2304.2515207617034" }, { "input": "5 999999937\n999999935 999999936\n999999937 999999938\n999999939 999999940\n999999941 999999942\n999999943 999999944", "output": "2000.0" }, { "input": "5 999999937\n1 999999936\n1 999999936\n1 999999936\n1 999999936\n1 999999936", "output": "0.0" }, { "input": "20 999999937\n999999936 999999937\n999999937 999999938\n999999936 999999937\n999999937 999999938\n999999936 999999937\n999999937 999999938\n999999936 999999937\n999999937 999999938\n999999936 999999937\n999999937 999999938\n999999936 999999937\n999999937 999999938\n999999936 999999937\n999999937 999999938\n999999936 999999937\n999999937 999999938\n999999936 999999937\n999999937 999999938\n999999936 999999937\n999999937 999999938", "output": "30000.0" }, { "input": "9 41\n40 42\n42 44\n44 46\n82 84\n82 83\n80 83\n40 83\n40 82\n42 82", "output": "5503.274377352654" }, { "input": "3 2\n1 1\n1 2\n1 1", "output": "2000.0" }, { "input": "12 3\n697806 966852\n802746 974920\n579567 821770\n628655 642480\n649359 905832\n87506 178848\n605628 924780\n843338 925533\n953514 978612\n375312 997707\n367620 509906\n277106 866177", "output": "13333.518289809368" }, { "input": "5 3\n67050 461313\n927808 989615\n169239 201720\n595515 756354\n392844 781910", "output": "5555.597086312073" }, { "input": "6 7\n984774 984865\n720391 916269\n381290 388205\n628383 840455\n747138 853964\n759705 959629", "output": "3215.6233297395006" }, { "input": "3 5\n99535 124440\n24114 662840\n529335 875935", "output": "2160.11317825774" }, { "input": "4 3\n561495 819666\n718673 973130\n830124 854655\n430685 963699", "output": "4444.521972611004" }, { "input": "10 3\n311664 694971\n364840 366487\n560148 821101\n896470 923613\n770019 828958\n595743 827536\n341418 988218\n207847 366132\n517968 587855\n168695 878142", "output": "11110.602699850484" }, { "input": "11 3\n66999 737907\n499872 598806\n560583 823299\n579017 838419\n214308 914576\n31820 579035\n373821 695652\n438988 889317\n181332 513682\n740575 769488\n597348 980891", "output": "12222.259608784536" }, { "input": "12 3\n158757 341790\n130709 571435\n571161 926255\n851779 952236\n914910 941369\n774359 860799\n224067 618483\n411639 902888\n264423 830336\n33133 608526\n951696 976379\n923880 968563", "output": "13333.377729413933" }, { "input": "9 2\n717582 964152\n268030 456147\n400022 466269\n132600 698200\n658890 807357\n196658 849497\n257020 380298\n267729 284534\n311978 917744", "output": "13500.015586135814" }, { "input": "10 7\n978831 984305\n843967 844227\n454356 748444\n219513 623868\n472997 698189\n542337 813387\n867615 918554\n413076 997267\n79310 138855\n195703 296681", "output": "5303.027968302269" } ]
1,698,175,571
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
3
62
0
n,p=map(int,input().split()) tot=[] div=[] while n>0: l,r=map(int,input().split()) tot.append(r-l+1) div.append(int(r/p)-int((l-1)/p)) n-=1 sz=len(div) ans=0 for i in range(sz): vl=((tot[i]-div[i])/tot[i]) j=i+1 j%=sz vl*=((tot[j]-div[j])/tot[j]) ans+=(1-vl)*3000 print(2*ans/sz)
Title: Wet Shark and Flowers Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* sharks who grow flowers for Wet Shark. They are all sitting around the table, such that sharks *i* and *i*<=+<=1 are neighbours for all *i* from 1 to *n*<=-<=1. Sharks *n* and 1 are neighbours too. Each shark will grow some number of flowers *s**i*. For *i*-th shark value *s**i* is random integer equiprobably chosen in range from *l**i* to *r**i*. Wet Shark has it's favourite prime number *p*, and he really likes it! If for any pair of neighbouring sharks *i* and *j* the product *s**i*·*s**j* is divisible by *p*, then Wet Shark becomes happy and gives 1000 dollars to each of these sharks. At the end of the day sharks sum all the money Wet Shark granted to them. Find the expectation of this value. Input Specification: The first line of the input contains two space-separated integers *n* and *p* (3<=≤<=*n*<=≤<=100<=000,<=2<=≤<=*p*<=≤<=109) — the number of sharks and Wet Shark's favourite prime number. It is guaranteed that *p* is prime. The *i*-th of the following *n* lines contains information about *i*-th shark — two space-separated integers *l**i* and *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=109), the range of flowers shark *i* can produce. Remember that *s**i* is chosen equiprobably among all integers from *l**i* to *r**i*, inclusive. Output Specification: Print a single real number — the expected number of dollars that the sharks receive in total. You answer will be considered correct if its absolute or relative error does not exceed 10<=-<=6. Namely: let's assume that your answer is *a*, and the answer of the jury is *b*. The checker program will consider your answer correct, if . Demo Input: ['3 2\n1 2\n420 421\n420420 420421\n', '3 5\n1 4\n2 3\n11 14\n'] Demo Output: ['4500.0\n', '0.0\n'] Note: A prime number is a positive integer number that is divisible only by 1 and itself. 1 is not considered to be prime. Consider the first sample. First shark grows some number of flowers from 1 to 2, second sharks grows from 420 to 421 flowers and third from 420420 to 420421. There are eight cases for the quantities of flowers (*s*<sub class="lower-index">0</sub>, *s*<sub class="lower-index">1</sub>, *s*<sub class="lower-index">2</sub>) each shark grows: 1. (1, 420, 420420): note that *s*<sub class="lower-index">0</sub>·*s*<sub class="lower-index">1</sub> = 420, *s*<sub class="lower-index">1</sub>·*s*<sub class="lower-index">2</sub> = 176576400, and *s*<sub class="lower-index">2</sub>·*s*<sub class="lower-index">0</sub> = 420420. For each pair, 1000 dollars will be awarded to each shark. Therefore, each shark will be awarded 2000 dollars, for a total of 6000 dollars.1. (1, 420, 420421): now, the product *s*<sub class="lower-index">2</sub>·*s*<sub class="lower-index">0</sub> is not divisible by 2. Therefore, sharks *s*<sub class="lower-index">0</sub> and *s*<sub class="lower-index">2</sub> will receive 1000 dollars, while shark *s*<sub class="lower-index">1</sub> will receive 2000. The total is 4000.1. (1, 421, 420420): total is 4000 1. (1, 421, 420421): total is 0. 1. (2, 420, 420420): total is 6000. 1. (2, 420, 420421): total is 6000. 1. (2, 421, 420420): total is 6000. 1. (2, 421, 420421): total is 4000. The expected value is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/dfe520d00a8615f7c270ccbccbebe182cc7db883.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In the second sample, no combination of quantities will garner the sharks any money.
```python n,p=map(int,input().split()) tot=[] div=[] while n>0: l,r=map(int,input().split()) tot.append(r-l+1) div.append(int(r/p)-int((l-1)/p)) n-=1 sz=len(div) ans=0 for i in range(sz): vl=((tot[i]-div[i])/tot[i]) j=i+1 j%=sz vl*=((tot[j]-div[j])/tot[j]) ans+=(1-vl)*3000 print(2*ans/sz) ```
0
932
A
Palindromic Supersequence
PROGRAMMING
800
[ "constructive algorithms" ]
null
null
You are given a string *A*. Find a string *B*, where *B* is a palindrome and *A* is a subsequence of *B*. A subsequence of a string is a string that can be derived from it by deleting some (not necessarily consecutive) characters without changing the order of the remaining characters. For example, "cotst" is a subsequence of "contest". A palindrome is a string that reads the same forward or backward. The length of string *B* should be at most 104. It is guaranteed that there always exists such string. You do not need to find the shortest answer, the only restriction is that the length of string *B* should not exceed 104.
First line contains a string *A* (1<=≤<=|*A*|<=≤<=103) consisting of lowercase Latin letters, where |*A*| is a length of *A*.
Output single line containing *B* consisting of only lowercase Latin letters. You do not need to find the shortest answer, the only restriction is that the length of string *B* should not exceed 104. If there are many possible *B*, print any of them.
[ "aba\n", "ab\n" ]
[ "aba", "aabaa" ]
In the first example, "aba" is a subsequence of "aba" which is a palindrome. In the second example, "ab" is a subsequence of "aabaa" which is a palindrome.
500
[ { "input": "aba", "output": "abaaba" }, { "input": "ab", "output": "abba" }, { "input": "krnyoixirslfszfqivgkaflgkctvbvksipwomqxlyqxhlbceuhbjbfnhofcgpgwdseffycthmlpcqejgskwjkbkbbmifnurnwyhevsoqzmtvzgfiqajfrgyuzxnrtxectcnlyoisbglpdbjbslxlpoymrcxmdtqhcnlvtqdwftuzgbdxsyscwbrguostbelnvtaqdmkmihmoxqtqlxvlsssisvqvvzotoyqryuyqwoknnqcqggysrqpkrccvyhxsjmhoqoyocwcriplarjoyiqrmmpmueqbsbljddwrumauczfziodpudheexalbwpiypmdjlmwtgdrzhpxneofhqzjdmurgvmrwdotuwyknlrbvuvtnhiouvqitgyfgfieonbaapyhwpcrmehxcpkijzfiayfvoxkpa", "output": "krnyoixirslfszfqivgkaflgkctvbvksipwomqxlyqxhlbceuhbjbfnhofcgpgwdseffycthmlpcqejgskwjkbkbbmifnurnwyhevsoqzmtvzgfiqajfrgyuzxnrtxectcnlyoisbglpdbjbslxlpoymrcxmdtqhcnlvtqdwftuzgbdxsyscwbrguostbelnvtaqdmkmihmoxqtqlxvlsssisvqvvzotoyqryuyqwoknnqcqggysrqpkrccvyhxsjmhoqoyocwcriplarjoyiqrmmpmueqbsbljddwrumauczfziodpudheexalbwpiypmdjlmwtgdrzhpxneofhqzjdmurgvmrwdotuwyknlrbvuvtnhiouvqitgyfgfieonbaapyhwpcrmehxcpkijzfiayfvoxkpaapkxovfyaifzjikpcxhemrcpwhypaabnoeifgfygtiqvuoihntvuvbrlnkywutodwrmvgrumdjzqhfoenxphzrdgtwmljdm..." }, { "input": "mgrfmzxqpejcixxppqgvuawutgrmezjkteofjbnrvzzkvjtacfxjjokisavsgrslryxfqgrmdsqwptajbqzvethuljbdatxghfzqrwvfgakwmoawlzqjypmhllbbuuhbpriqsnibywlgjlxowyzagrfnqafvcqwktkcjwejevzbnxhsfmwojshcdypnvbuhhuzqmgovmvgwiizatoxgblyudipahfbkewmuneoqhjmbpdtwnznblwvtjrniwlbyblhppndspojrouffazpoxtqdfpjuhitvijrohavpqatofxwmksvjcvhdecxwwmosqiczjpkfafqlboxosnjgzgdraehzdltthemeusxhiiimrdrugabnxwsygsktkcslhjebfexucsyvlwrptebkjhefsvfrmcqqdlanbetrgzwylizmrystvpgrkhlicfadco", "output": "mgrfmzxqpejcixxppqgvuawutgrmezjkteofjbnrvzzkvjtacfxjjokisavsgrslryxfqgrmdsqwptajbqzvethuljbdatxghfzqrwvfgakwmoawlzqjypmhllbbuuhbpriqsnibywlgjlxowyzagrfnqafvcqwktkcjwejevzbnxhsfmwojshcdypnvbuhhuzqmgovmvgwiizatoxgblyudipahfbkewmuneoqhjmbpdtwnznblwvtjrniwlbyblhppndspojrouffazpoxtqdfpjuhitvijrohavpqatofxwmksvjcvhdecxwwmosqiczjpkfafqlboxosnjgzgdraehzdltthemeusxhiiimrdrugabnxwsygsktkcslhjebfexucsyvlwrptebkjhefsvfrmcqqdlanbetrgzwylizmrystvpgrkhlicfadcoocdafcilhkrgpvtsyrmzilywzgrtebnaldqqcmrfvsfehjkbetprwlvyscuxef..." }, { "input": "hdmasfcjuigrwjchmjslmpynewnzpphmudzcbxzdexjuhktdtcoibzvevsmwaxakrtdfoivkvoooypyemiidadquqepxwqkesdnakxkbzrcjkgvwwxtqxvfpxcwitljyehldgsjytmekimkkndjvnzqtjykiymkmdzpwakxdtkzcqcatlevppgfhyykgmipuodjrnfjzhcmjdbzvhywprbwdcfxiffpzbjbmbyijkqnosslqbfvvicxvoeuzruraetglthgourzhfpnubzvblfzmmbgepjjyshchthulxar", "output": "hdmasfcjuigrwjchmjslmpynewnzpphmudzcbxzdexjuhktdtcoibzvevsmwaxakrtdfoivkvoooypyemiidadquqepxwqkesdnakxkbzrcjkgvwwxtqxvfpxcwitljyehldgsjytmekimkkndjvnzqtjykiymkmdzpwakxdtkzcqcatlevppgfhyykgmipuodjrnfjzhcmjdbzvhywprbwdcfxiffpzbjbmbyijkqnosslqbfvvicxvoeuzruraetglthgourzhfpnubzvblfzmmbgepjjyshchthulxarraxluhthchsyjjpegbmmzflbvzbunpfhzruoghtlgtearurzueovxcivvfbqlssonqkjiybmbjbzpffixfcdwbrpwyhvzbdjmchzjfnrjdoupimgkyyhfgppveltacqczktdxkawpzdmkmyikyjtqznvjdnkkmikemtyjsgdlheyjltiwcxpfvxqtxwwvgkjcrzbkxkandsekqwxpequ..." }, { "input": "fggbyzobbmxtwdajawqdywnppflkkmtxzjvxopqvliwdwhzepcuiwelhbuotlkvesexnwkytonfrpqcxzzqzdvsmbsjcxxeugavekozfjlolrtqgwzqxsfgrnvrgfrqpixhsskbpzghndesvwptpvvkasfalzsetopervpwzmkgpcexqnvtnoulprwnowmsorscecvvvrjfwumcjqyrounqsgdruxttvtmrkivtxauhosokdiahsyrftzsgvgyveqwkzhqstbgywrvmsgfcfyuxpphvmyydzpohgdicoxbtjnsbyhoidnkrialowvlvmjpxcfeygqzphmbcjkupojsmmuqlydixbaluwezvnfasjfxilbyllwyipsmovdzosuwotcxerzcfuvxprtziseshjfcosalyqglpotxvxaanpocypsiyazsejjoximnbvqucftuvdksaxutvjeunodbipsumlaymjnzljurefjg", "output": "fggbyzobbmxtwdajawqdywnppflkkmtxzjvxopqvliwdwhzepcuiwelhbuotlkvesexnwkytonfrpqcxzzqzdvsmbsjcxxeugavekozfjlolrtqgwzqxsfgrnvrgfrqpixhsskbpzghndesvwptpvvkasfalzsetopervpwzmkgpcexqnvtnoulprwnowmsorscecvvvrjfwumcjqyrounqsgdruxttvtmrkivtxauhosokdiahsyrftzsgvgyveqwkzhqstbgywrvmsgfcfyuxpphvmyydzpohgdicoxbtjnsbyhoidnkrialowvlvmjpxcfeygqzphmbcjkupojsmmuqlydixbaluwezvnfasjfxilbyllwyipsmovdzosuwotcxerzcfuvxprtziseshjfcosalyqglpotxvxaanpocypsiyazsejjoximnbvqucftuvdksaxutvjeunodbipsumlaymjnzljurefjggjferujlznjmyalmuspib..." }, { "input": "qyyxqkbxsvfnjzttdqmpzinbdgayllxpfrpopwciejjjzadguurnnhvixgueukugkkjyghxknedojvmdrskswiotgatsajowionuiumuhyggjuoympuxyfahwftwufvocdguxmxabbxnfviscxtilzzauizsgugwcqtbqgoosefhkumhodwpgolfdkbuiwlzjydonwbgyzzrjwxnceltqgqelrrljmzdbftmaogiuosaqhngmdzxzlmyrwefzhqawmkdckfnyyjgdjgadtfjvrkdwysqofcgyqrnyzutycvspzbjmmesobvhshtqlrytztyieknnkporrbcmlopgtknlmsstzkigreqwgsvagmvbrvwypoxttmzzsgm", "output": "qyyxqkbxsvfnjzttdqmpzinbdgayllxpfrpopwciejjjzadguurnnhvixgueukugkkjyghxknedojvmdrskswiotgatsajowionuiumuhyggjuoympuxyfahwftwufvocdguxmxabbxnfviscxtilzzauizsgugwcqtbqgoosefhkumhodwpgolfdkbuiwlzjydonwbgyzzrjwxnceltqgqelrrljmzdbftmaogiuosaqhngmdzxzlmyrwefzhqawmkdckfnyyjgdjgadtfjvrkdwysqofcgyqrnyzutycvspzbjmmesobvhshtqlrytztyieknnkporrbcmlopgtknlmsstzkigreqwgsvagmvbrvwypoxttmzzsgmmgszzmttxopywvrbvmgavsgwqergikztssmlnktgpolmcbrropknnkeiytztyrlqthshvbosemmjbzpsvcytuzynrqygcfoqsywdkrvjftdagjdgjyynfkcdkmwaqhzfewry..." }, { "input": "scvlhflaqvniyiyofonowwcuqajuwscdrzhbvasymvqfnthzvtjcfuaftrbjghhvslcohwpxkggrbtatjtgehuqtorwinwvrtdldyoeeozxwippuahgkuehvsmyqtodqvlufqqmqautaqirvwzvtodzxtgxiinubhrbeoiybidutrqamsdnasctxatzkvkjkrmavdravnsxyngjlugwftmhmcvvxdbfndurrbmcpuoigjpssqcortmqoqttrabhoqvopjkxvpbqdqsilvlplhgqazauyvnodsxtwnomlinjpozwhrgrkqwmlwcwdkxjxjftexiavwrejvdjcfptterblxysjcheesyqsbgdrzjxbfjqgjgmvccqcyj", "output": "scvlhflaqvniyiyofonowwcuqajuwscdrzhbvasymvqfnthzvtjcfuaftrbjghhvslcohwpxkggrbtatjtgehuqtorwinwvrtdldyoeeozxwippuahgkuehvsmyqtodqvlufqqmqautaqirvwzvtodzxtgxiinubhrbeoiybidutrqamsdnasctxatzkvkjkrmavdravnsxyngjlugwftmhmcvvxdbfndurrbmcpuoigjpssqcortmqoqttrabhoqvopjkxvpbqdqsilvlplhgqazauyvnodsxtwnomlinjpozwhrgrkqwmlwcwdkxjxjftexiavwrejvdjcfptterblxysjcheesyqsbgdrzjxbfjqgjgmvccqcyjjycqccvmgjgqjfbxjzrdgbsqyseehcjsyxlbrettpfcjdvjerwvaixetfjxjxkdwcwlmwqkrgrhwzopjnilmonwtxsdonvyuazaqghlplvlisqdqbpvxkjpovqohbarttqoqm..." }, { "input": "oohkqxxtvxzmvfjjxyjwlbqmeqwwlienzkdbhswgfbkhfygltsucdijozwaiewpixapyazfztksjeoqjugjfhdbqzuezbuajfvvffkwprroyivfoocvslejffgxuiofisenroxoeixmdbzonmreikpflciwsbafrdqfvdfojgoziiibqhwwsvhnzmptgirqqulkgmyzrfekzqqujmdumxkudsgexisupedisgmdgebvlvrpyfrbrqjknrxyzfpwmsxjxismgd", "output": "oohkqxxtvxzmvfjjxyjwlbqmeqwwlienzkdbhswgfbkhfygltsucdijozwaiewpixapyazfztksjeoqjugjfhdbqzuezbuajfvvffkwprroyivfoocvslejffgxuiofisenroxoeixmdbzonmreikpflciwsbafrdqfvdfojgoziiibqhwwsvhnzmptgirqqulkgmyzrfekzqqujmdumxkudsgexisupedisgmdgebvlvrpyfrbrqjknrxyzfpwmsxjxismgddgmsixjxsmwpfzyxrnkjqrbrfyprvlvbegdmgsidepusixegsdukxmudmjuqqzkefrzymgkluqqrigtpmznhvswwhqbiiizogjofdvfqdrfabswiclfpkiermnozbdmxieoxornesifoiuxgffjelsvcoofviyorrpwkffvvfjaubzeuzqbdhfjgujqoejsktzfzaypaxipweiawzojidcustlgyfhkbfgwshbdkzneilwwqemqblw..." }, { "input": "gilhoixzjgidfanqrmekjelnvicpuujlpxittgadgrhqallnkjlemwazntwfywjnrxdkgrnczlwzjyeyfktduzdjnivcldjjarfzmmdbyytvipbbnjqolfnlqjpidotxxfobgtgpvjmpddcyddwdcjsxxumuoyznhpvpqccgqnuouzojntanfwctthcgynrukcvshsuuqrxfdvqqggaatwytikkitywtaaggqqvdfxrquushsvckurnygchttcwfnatnjozuounqgccqpvphnzyoumuxxsjcdwddycddpmjvpgtgbofxxtodipjqlnfloqjnbbpivtyybdmmzfrajjdlcvinjdzudtkfyeyjzwlzcnrgkdxrnjwyfwtnzawmeljknllaqhrgdagttixpljuupcivnlejkemrqnafdigjzxiohlig", "output": "gilhoixzjgidfanqrmekjelnvicpuujlpxittgadgrhqallnkjlemwazntwfywjnrxdkgrnczlwzjyeyfktduzdjnivcldjjarfzmmdbyytvipbbnjqolfnlqjpidotxxfobgtgpvjmpddcyddwdcjsxxumuoyznhpvpqccgqnuouzojntanfwctthcgynrukcvshsuuqrxfdvqqggaatwytikkitywtaaggqqvdfxrquushsvckurnygchttcwfnatnjozuounqgccqpvphnzyoumuxxsjcdwddycddpmjvpgtgbofxxtodipjqlnfloqjnbbpivtyybdmmzfrajjdlcvinjdzudtkfyeyjzwlzcnrgkdxrnjwyfwtnzawmeljknllaqhrgdagttixpljuupcivnlejkemrqnafdigjzxiohliggilhoixzjgidfanqrmekjelnvicpuujlpxittgadgrhqallnkjlemwazntwfywjnrxdkgrnczlw..." }, { "input": "abcab", "output": "abcabbacba" }, { "input": "baaaaaaa", "output": "baaaaaaaaaaaaaab" }, { "input": "baaaaaa", "output": "baaaaaaaaaaaab" }, { "input": "baaaaaaaaa", "output": "baaaaaaaaaaaaaaaaaab" }, { "input": "baaaaaaaa", "output": "baaaaaaaaaaaaaaaab" } ]
1,544,192,998
2,147,483,647
Python 3
OK
TESTS
48
124
0
A = input() rev = A[::-1] print( A + rev)
Title: Palindromic Supersequence Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a string *A*. Find a string *B*, where *B* is a palindrome and *A* is a subsequence of *B*. A subsequence of a string is a string that can be derived from it by deleting some (not necessarily consecutive) characters without changing the order of the remaining characters. For example, "cotst" is a subsequence of "contest". A palindrome is a string that reads the same forward or backward. The length of string *B* should be at most 104. It is guaranteed that there always exists such string. You do not need to find the shortest answer, the only restriction is that the length of string *B* should not exceed 104. Input Specification: First line contains a string *A* (1<=≤<=|*A*|<=≤<=103) consisting of lowercase Latin letters, where |*A*| is a length of *A*. Output Specification: Output single line containing *B* consisting of only lowercase Latin letters. You do not need to find the shortest answer, the only restriction is that the length of string *B* should not exceed 104. If there are many possible *B*, print any of them. Demo Input: ['aba\n', 'ab\n'] Demo Output: ['aba', 'aabaa'] Note: In the first example, "aba" is a subsequence of "aba" which is a palindrome. In the second example, "ab" is a subsequence of "aabaa" which is a palindrome.
```python A = input() rev = A[::-1] print( A + rev) ```
3
357
B
Flag Day
PROGRAMMING
1,400
[ "constructive algorithms", "implementation" ]
null
null
In Berland, there is the national holiday coming — the Flag Day. In the honor of this event the president of the country decided to make a big dance party and asked your agency to organize it. He has several conditions: - overall, there must be *m* dances;- exactly three people must take part in each dance;- each dance must have one dancer in white clothes, one dancer in red clothes and one dancer in blue clothes (these are the colors of the national flag of Berland). The agency has *n* dancers, and their number can be less than 3*m*. That is, some dancers will probably have to dance in more than one dance. All of your dancers must dance on the party. However, if some dance has two or more dancers from a previous dance, then the current dance stops being spectacular. Your agency cannot allow that to happen, so each dance has at most one dancer who has danced in some previous dance. You considered all the criteria and made the plan for the *m* dances: each dance had three dancers participating in it. Your task is to determine the clothes color for each of the *n* dancers so that the President's third condition fulfilled: each dance must have a dancer in white, a dancer in red and a dancer in blue. The dancers cannot change clothes between the dances.
The first line contains two space-separated integers *n* (3<=≤<=*n*<=≤<=105) and *m* (1<=≤<=*m*<=≤<=105) — the number of dancers and the number of dances, correspondingly. Then *m* lines follow, describing the dances in the order of dancing them. The *i*-th line contains three distinct integers — the numbers of the dancers that take part in the *i*-th dance. The dancers are numbered from 1 to *n*. Each dancer takes part in at least one dance.
Print *n* space-separated integers: the *i*-th number must represent the color of the *i*-th dancer's clothes (1 for white, 2 for red, 3 for blue). If there are multiple valid solutions, print any of them. It is guaranteed that at least one solution exists.
[ "7 3\n1 2 3\n1 4 5\n4 6 7\n", "9 3\n3 6 9\n2 5 8\n1 4 7\n", "5 2\n4 1 5\n3 1 2\n" ]
[ "1 2 3 3 2 2 1 \n", "1 1 1 2 2 2 3 3 3 \n", "2 3 1 1 3 \n" ]
none
1,000
[ { "input": "7 3\n1 2 3\n1 4 5\n4 6 7", "output": "1 2 3 3 2 2 1 " }, { "input": "9 3\n3 6 9\n2 5 8\n1 4 7", "output": "1 1 1 2 2 2 3 3 3 " }, { "input": "5 2\n4 1 5\n3 1 2", "output": "2 3 1 1 3 " }, { "input": "14 5\n1 5 3\n13 10 11\n6 3 8\n14 9 2\n7 4 12", "output": "1 3 3 2 2 2 1 1 2 2 3 3 1 1 " }, { "input": "14 6\n14 3 13\n10 14 5\n6 2 10\n7 13 9\n12 11 8\n1 4 9", "output": "2 2 2 3 2 1 2 3 1 3 2 1 3 1 " }, { "input": "14 6\n11 13 10\n3 10 14\n2 7 12\n13 1 9\n5 11 4\n8 6 5", "output": "1 1 2 2 3 2 2 1 3 3 1 3 2 1 " }, { "input": "13 5\n13 6 2\n13 3 8\n11 4 7\n10 9 5\n1 12 6", "output": "3 3 3 2 3 2 3 2 2 1 1 1 1 " }, { "input": "14 6\n5 4 8\n5 7 12\n3 6 12\n7 11 14\n10 13 2\n10 1 9", "output": "3 3 3 2 1 1 3 3 2 1 2 2 2 1 " }, { "input": "14 5\n4 13 2\n7 2 11\n6 1 5\n14 12 8\n10 3 9", "output": "2 3 2 1 3 1 2 3 3 1 1 2 2 1 " }, { "input": "14 6\n2 14 5\n3 4 5\n6 13 14\n7 13 12\n8 10 11\n9 6 1", "output": "1 1 1 2 3 3 3 1 2 2 3 2 1 2 " }, { "input": "14 6\n7 14 12\n6 1 12\n13 5 2\n2 3 9\n7 4 11\n5 8 10", "output": "2 3 2 3 2 1 1 1 1 3 2 3 1 2 " }, { "input": "13 6\n8 7 6\n11 7 3\n13 9 3\n12 1 13\n8 10 4\n2 7 5", "output": "3 1 3 2 3 3 2 1 2 3 1 2 1 " }, { "input": "13 5\n8 4 3\n1 9 5\n6 2 11\n12 10 4\n7 10 13", "output": "1 2 3 2 3 1 3 1 2 1 3 3 2 " }, { "input": "20 8\n16 19 12\n13 3 5\n1 5 17\n10 19 7\n8 18 2\n3 11 14\n9 20 12\n4 15 6", "output": "2 3 2 1 3 3 3 1 1 1 1 3 1 3 2 1 1 2 2 2 " }, { "input": "19 7\n10 18 14\n5 9 11\n9 17 7\n3 15 4\n6 8 12\n1 2 18\n13 16 19", "output": "3 1 1 3 1 1 3 2 2 1 3 3 1 3 2 2 1 2 3 " }, { "input": "18 7\n17 4 13\n7 1 6\n16 9 13\n9 2 5\n11 12 17\n14 8 10\n3 15 18", "output": "2 1 1 2 3 3 1 2 2 3 2 3 3 1 2 1 1 3 " }, { "input": "20 7\n8 5 11\n3 19 20\n16 1 17\n9 6 2\n7 18 13\n14 12 18\n10 4 15", "output": "2 3 1 2 2 2 1 1 1 1 3 1 3 3 3 1 3 2 2 3 " }, { "input": "20 7\n6 11 20\n19 5 2\n15 10 12\n3 7 8\n9 1 6\n13 17 18\n14 16 4", "output": "3 3 1 3 2 1 2 3 2 2 2 3 1 1 1 2 2 3 1 3 " }, { "input": "18 7\n15 5 1\n6 11 4\n14 8 17\n11 12 13\n3 8 16\n9 4 7\n2 18 10", "output": "3 1 1 3 2 1 1 2 2 3 2 1 3 1 1 3 3 2 " }, { "input": "19 7\n3 10 8\n17 7 4\n1 19 18\n2 9 5\n12 11 15\n11 14 6\n13 9 16", "output": "1 1 1 3 3 3 2 3 2 2 2 1 1 1 3 3 1 3 2 " }, { "input": "19 7\n18 14 4\n3 11 6\n8 10 7\n10 19 16\n17 13 15\n5 1 14\n12 9 2", "output": "1 3 1 3 3 3 3 1 2 2 2 1 2 2 3 3 1 1 1 " }, { "input": "20 7\n18 7 15\n17 5 20\n9 19 12\n16 13 10\n3 6 1\n3 8 11\n4 2 14", "output": "3 2 1 1 2 2 2 3 1 3 2 3 2 3 3 1 1 1 2 3 " }, { "input": "18 7\n8 4 6\n13 17 3\n9 8 12\n12 16 5\n18 2 7\n11 1 10\n5 15 14", "output": "2 2 3 2 3 3 3 1 3 3 1 2 1 1 2 1 2 1 " }, { "input": "99 37\n40 10 7\n10 3 5\n10 31 37\n87 48 24\n33 47 38\n34 87 2\n2 35 28\n99 28 76\n66 51 97\n72 77 9\n18 17 67\n23 69 98\n58 89 99\n42 44 52\n65 41 80\n70 92 74\n62 88 45\n68 27 61\n6 83 95\n39 85 49\n57 75 77\n59 54 81\n56 20 82\n96 4 53\n90 7 11\n16 43 84\n19 25 59\n68 8 93\n73 94 78\n15 71 79\n26 12 50\n30 32 4\n14 22 29\n46 21 36\n60 55 86\n91 8 63\n13 1 64", "output": "2 2 1 2 3 1 3 3 3 2 1 2 1 1 1 1 2 1 2 2 2 2 1 3 3 1 2 3 3 3 1 1 1 3 1 3 3 3 1 1 2 1 2 2 3 1 2 2 3 3 2 3 3 2 2 1 3 3 1 1 3 1 1 3 1 1 3 1 2 1 2 1 1 3 1 1 2 3 3 3 3 3 2 3 2 3 1 2 1 2 2 2 2 2 3 1 3 3 2 " }, { "input": "99 41\n11 70 20\n57 11 76\n52 11 64\n49 70 15\n19 61 17\n71 77 21\n77 59 39\n37 64 68\n17 84 36\n46 11 90\n35 11 14\n36 25 80\n12 43 48\n18 78 42\n82 94 15\n22 10 84\n63 86 4\n98 86 50\n92 60 9\n73 42 65\n21 5 27\n30 24 23\n7 88 49\n40 97 45\n81 56 17\n79 61 33\n13 3 77\n54 6 28\n99 58 8\n29 95 24\n89 74 32\n51 89 66\n87 91 96\n22 34 38\n1 53 72\n55 97 26\n41 16 44\n2 31 47\n83 67 91\n75 85 69\n93 47 62", "output": "1 1 1 3 2 2 2 3 3 1 1 1 3 2 3 2 3 1 1 3 3 3 3 2 3 3 1 3 3 1 2 3 3 2 3 1 1 1 3 1 1 3 2 3 3 3 3 3 1 3 3 3 2 1 1 2 3 2 1 2 2 1 1 2 1 2 1 3 3 2 1 3 2 2 1 2 2 2 1 2 1 1 3 2 2 2 1 3 1 2 2 1 2 2 1 3 2 1 1 " }, { "input": "99 38\n70 56 92\n61 70 68\n18 92 91\n82 43 55\n37 5 43\n47 27 26\n64 63 40\n20 61 57\n69 80 59\n60 89 50\n33 25 86\n38 15 73\n96 85 90\n3 12 64\n95 23 48\n66 30 9\n38 99 45\n67 88 71\n74 11 81\n28 51 79\n72 92 34\n16 77 31\n65 18 94\n3 41 2\n36 42 81\n22 77 83\n44 24 52\n10 75 97\n54 21 53\n4 29 32\n58 39 98\n46 62 16\n76 5 84\n8 87 13\n6 41 14\n19 21 78\n7 49 93\n17 1 35", "output": "2 3 2 1 1 3 1 1 3 1 2 3 3 2 2 1 1 2 1 2 2 1 2 2 2 3 2 1 2 2 3 3 1 1 3 1 3 1 2 3 1 2 2 1 2 2 1 3 2 3 2 3 3 1 3 2 1 1 3 1 3 3 2 1 1 1 1 2 1 1 3 2 3 1 2 3 2 3 3 2 3 1 3 2 2 3 2 2 2 3 1 3 3 3 1 1 3 3 3 " }, { "input": "98 38\n70 23 73\n73 29 86\n93 82 30\n6 29 10\n7 22 78\n55 61 87\n98 2 12\n11 5 54\n44 56 60\n89 76 50\n37 72 43\n47 41 61\n85 40 38\n48 93 20\n90 64 29\n31 68 25\n83 57 41\n51 90 3\n91 97 66\n96 95 1\n50 84 71\n53 19 5\n45 42 28\n16 17 89\n63 58 15\n26 47 39\n21 24 19\n80 74 38\n14 46 75\n88 65 36\n77 92 33\n17 59 34\n35 69 79\n13 94 39\n8 52 4\n67 27 9\n65 62 18\n81 32 49", "output": "3 2 1 3 2 1 1 1 3 3 1 3 2 1 3 2 3 3 1 2 2 2 2 3 3 2 2 3 2 3 1 2 3 1 1 3 1 3 1 2 1 2 3 1 1 2 3 3 3 3 2 2 3 3 1 2 3 2 2 3 2 1 1 1 2 3 1 2 2 1 1 2 3 2 3 2 1 3 3 1 1 2 2 2 1 1 3 1 1 3 1 2 1 3 2 1 2 1 " }, { "input": "99 42\n61 66 47\n10 47 96\n68 86 67\n21 29 10\n55 44 47\n12 82 4\n45 71 55\n86 3 95\n16 99 93\n14 92 82\n12 59 20\n73 24 8\n79 72 48\n44 87 39\n87 84 97\n47 70 37\n49 77 95\n39 75 28\n75 25 5\n44 41 36\n76 86 78\n73 6 90\n8 22 58\n9 72 63\n81 42 14\n1 21 35\n91 54 15\n30 13 39\n56 89 79\n11 2 76\n19 65 52\n23 85 74\n7 38 24\n57 94 81\n43 34 60\n62 82 27\n69 64 53\n18 32 17\n24 31 88\n51 50 33\n40 80 98\n83 46 26", "output": "2 3 1 3 3 3 3 3 1 2 2 1 2 3 3 1 3 1 1 2 3 2 1 2 1 3 3 1 1 1 1 2 3 2 1 3 1 1 3 1 1 2 1 2 2 2 3 3 1 2 1 3 3 2 1 2 2 1 3 3 1 1 3 2 2 2 3 1 1 2 3 2 1 3 2 1 2 3 1 2 1 2 1 3 2 2 1 3 3 2 1 1 3 3 3 1 2 3 2 " } ]
1,695,984,121
2,147,483,647
Python 3
OK
TESTS
63
280
2,662,400
n,m=map(int,input().split()) lst=[0 for i in range(n+1)] for j in range(m): dancers=list(map(int,input().split())) color=[lst[dancers[0]],lst[dancers[1]],lst[dancers[2]]] for i in range(3): if(lst[dancers[i]]!=0): continue else: if(1 not in color): lst[dancers[i]]=1 color[i]=1 continue if(2 not in color): lst[dancers[i]]=2 color[i]=2 continue if(3 not in color): lst[dancers[i]]=3 color[i]=3 for k in range(1,n+1): print(lst[k],end=' ')
Title: Flag Day Time Limit: None seconds Memory Limit: None megabytes Problem Description: In Berland, there is the national holiday coming — the Flag Day. In the honor of this event the president of the country decided to make a big dance party and asked your agency to organize it. He has several conditions: - overall, there must be *m* dances;- exactly three people must take part in each dance;- each dance must have one dancer in white clothes, one dancer in red clothes and one dancer in blue clothes (these are the colors of the national flag of Berland). The agency has *n* dancers, and their number can be less than 3*m*. That is, some dancers will probably have to dance in more than one dance. All of your dancers must dance on the party. However, if some dance has two or more dancers from a previous dance, then the current dance stops being spectacular. Your agency cannot allow that to happen, so each dance has at most one dancer who has danced in some previous dance. You considered all the criteria and made the plan for the *m* dances: each dance had three dancers participating in it. Your task is to determine the clothes color for each of the *n* dancers so that the President's third condition fulfilled: each dance must have a dancer in white, a dancer in red and a dancer in blue. The dancers cannot change clothes between the dances. Input Specification: The first line contains two space-separated integers *n* (3<=≤<=*n*<=≤<=105) and *m* (1<=≤<=*m*<=≤<=105) — the number of dancers and the number of dances, correspondingly. Then *m* lines follow, describing the dances in the order of dancing them. The *i*-th line contains three distinct integers — the numbers of the dancers that take part in the *i*-th dance. The dancers are numbered from 1 to *n*. Each dancer takes part in at least one dance. Output Specification: Print *n* space-separated integers: the *i*-th number must represent the color of the *i*-th dancer's clothes (1 for white, 2 for red, 3 for blue). If there are multiple valid solutions, print any of them. It is guaranteed that at least one solution exists. Demo Input: ['7 3\n1 2 3\n1 4 5\n4 6 7\n', '9 3\n3 6 9\n2 5 8\n1 4 7\n', '5 2\n4 1 5\n3 1 2\n'] Demo Output: ['1 2 3 3 2 2 1 \n', '1 1 1 2 2 2 3 3 3 \n', '2 3 1 1 3 \n'] Note: none
```python n,m=map(int,input().split()) lst=[0 for i in range(n+1)] for j in range(m): dancers=list(map(int,input().split())) color=[lst[dancers[0]],lst[dancers[1]],lst[dancers[2]]] for i in range(3): if(lst[dancers[i]]!=0): continue else: if(1 not in color): lst[dancers[i]]=1 color[i]=1 continue if(2 not in color): lst[dancers[i]]=2 color[i]=2 continue if(3 not in color): lst[dancers[i]]=3 color[i]=3 for k in range(1,n+1): print(lst[k],end=' ') ```
3
455
A
Boredom
PROGRAMMING
1,500
[ "dp" ]
null
null
Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it. Given a sequence *a* consisting of *n* integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it *a**k*) and delete it, at that all elements equal to *a**k*<=+<=1 and *a**k*<=-<=1 also must be deleted from the sequence. That step brings *a**k* points to the player. Alex is a perfectionist, so he decided to get as many points as possible. Help him.
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) that shows how many numbers are in Alex's sequence. The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105).
Print a single integer — the maximum number of points that Alex can earn.
[ "2\n1 2\n", "3\n1 2 3\n", "9\n1 2 1 3 2 2 2 2 3\n" ]
[ "2\n", "4\n", "10\n" ]
Consider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this [2, 2, 2, 2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points.
500
[ { "input": "2\n1 2", "output": "2" }, { "input": "3\n1 2 3", "output": "4" }, { "input": "9\n1 2 1 3 2 2 2 2 3", "output": "10" }, { "input": "5\n3 3 4 5 4", "output": "11" }, { "input": "5\n5 3 5 3 4", "output": "16" }, { "input": "5\n4 2 3 2 5", "output": "9" }, { "input": "10\n10 5 8 9 5 6 8 7 2 8", "output": "46" }, { "input": "10\n1 1 1 1 1 1 2 3 4 4", "output": "14" }, { "input": "100\n6 6 8 9 7 9 6 9 5 7 7 4 5 3 9 1 10 3 4 5 8 9 6 5 6 4 10 9 1 4 1 7 1 4 9 10 8 2 9 9 10 5 8 9 5 6 8 7 2 8 7 6 2 6 10 8 6 2 5 5 3 2 8 8 5 3 6 2 1 4 7 2 7 3 7 4 10 10 7 5 4 7 5 10 7 1 1 10 7 7 7 2 3 4 2 8 4 7 4 4", "output": "296" }, { "input": "100\n6 1 5 7 10 10 2 7 3 7 2 10 7 6 3 5 5 5 3 7 2 4 2 7 7 4 2 8 2 10 4 7 9 1 1 7 9 7 1 10 10 9 5 6 10 1 7 5 8 1 1 5 3 10 2 4 3 5 2 7 4 9 5 10 1 3 7 6 6 9 3 6 6 10 1 10 6 1 10 3 4 1 7 9 2 7 8 9 3 3 2 4 6 6 1 2 9 4 1 2", "output": "313" }, { "input": "100\n7 6 3 8 8 3 10 5 3 8 6 4 6 9 6 7 3 9 10 7 5 5 9 10 7 2 3 8 9 5 4 7 9 3 6 4 9 10 7 6 8 7 6 6 10 3 7 4 5 7 7 5 1 5 4 8 7 3 3 4 7 8 5 9 2 2 3 1 6 4 6 6 6 1 7 10 7 4 5 3 9 2 4 1 5 10 9 3 9 6 8 5 2 1 10 4 8 5 10 9", "output": "298" }, { "input": "100\n2 10 9 1 2 6 7 2 2 8 9 9 9 5 6 2 5 1 1 10 7 4 5 5 8 1 9 4 10 1 9 3 1 8 4 10 8 8 2 4 6 5 1 4 2 2 1 2 8 5 3 9 4 10 10 7 8 6 1 8 2 6 7 1 6 7 3 10 10 3 7 7 6 9 6 8 8 10 4 6 4 3 3 3 2 3 10 6 8 5 5 10 3 7 3 1 1 1 5 5", "output": "312" }, { "input": "100\n4 9 7 10 4 7 2 6 1 9 1 8 7 5 5 7 6 7 9 8 10 5 3 5 7 10 3 2 1 3 8 9 4 10 4 7 6 4 9 6 7 1 9 4 3 5 8 9 2 7 10 5 7 5 3 8 10 3 8 9 3 4 3 10 6 5 1 8 3 2 5 8 4 7 5 3 3 2 6 9 9 8 2 7 6 3 2 2 8 8 4 5 6 9 2 3 2 2 5 2", "output": "287" }, { "input": "100\n4 8 10 1 8 8 8 1 10 3 1 8 6 8 6 1 10 3 3 3 3 7 2 1 1 6 10 1 7 9 8 10 3 8 6 2 1 6 5 6 10 8 9 7 4 3 10 5 3 9 10 5 10 8 8 5 7 8 9 5 3 9 9 2 7 8 1 10 4 9 2 8 10 10 5 8 5 1 7 3 4 5 2 5 9 3 2 5 6 2 3 10 1 5 9 6 10 4 10 8", "output": "380" }, { "input": "100\n4 8 10 1 8 8 8 1 10 3 1 8 6 8 6 1 10 3 3 3 3 7 2 1 1 6 10 1 7 9 8 10 3 8 6 2 1 6 5 6 10 8 9 7 4 3 10 5 3 9 10 5 10 8 8 5 7 8 9 5 3 9 9 2 7 8 1 10 4 9 2 8 10 10 5 8 5 1 7 3 4 5 2 5 9 3 2 5 6 2 3 10 1 5 9 6 10 4 10 8", "output": "380" }, { "input": "100\n10 5 8 4 4 4 1 4 5 8 3 10 2 4 1 10 8 1 1 6 8 4 2 9 1 3 1 7 7 9 3 5 5 8 6 9 9 4 8 1 3 3 2 6 1 5 4 5 3 5 5 6 7 5 7 9 3 5 4 9 2 6 8 1 1 7 7 3 8 9 8 7 3 2 4 1 6 1 3 9 4 2 2 8 5 10 1 8 8 5 1 5 6 9 4 5 6 5 10 2", "output": "265" }, { "input": "100\n7 5 1 8 5 6 6 2 6 2 7 7 3 6 2 4 4 2 10 2 2 2 10 6 6 1 5 10 9 1 5 9 8 9 4 1 10 5 7 5 7 6 4 8 8 1 7 8 3 8 2 1 8 4 10 3 5 6 6 10 9 6 5 1 10 7 6 9 9 2 10 10 9 1 2 1 7 7 4 10 1 10 5 5 3 8 9 8 1 4 10 2 4 5 4 4 1 6 2 9", "output": "328" }, { "input": "100\n5 6 10 7 1 7 10 1 9 1 5 1 4 1 3 3 7 9 1 6 1 6 5 7 1 6 3 1 3 6 3 8 2 4 1 5 2 10 7 3 10 4 10 1 5 4 2 9 7 9 5 7 10 4 1 4 8 9 3 1 3 7 7 4 3 7 7 10 6 9 5 5 6 5 3 9 8 8 5 5 4 10 9 4 10 4 1 8 3 5 4 10 9 3 10 4 10 7 10 9", "output": "324" }, { "input": "10\n7 4 5 3 9 1 10 3 4 5", "output": "34" }, { "input": "10\n8 9 6 5 6 4 10 9 1 4", "output": "39" }, { "input": "10\n1 7 1 4 9 10 8 2 9 9", "output": "40" }, { "input": "1\n100000", "output": "100000" } ]
1,673,977,422
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
6
93
7,680,000
import sys from math import * # from pprint import pprint as pprint # from sympy.ntheory.modular import crt import heapq from copy import * from collections import * import functools from itertools import * from math import sqrt, ceil import threading import cmath import time # fin = sys.stdin.read().strip() n = int(input()) nums = [int(c) for c in input().strip().split()] counter = Counter(nums) sorted_nums = sorted(list(set(nums))) second = 0 first = second = 0 for num in sorted_nums: temp = first first = max(first, second + counter[num] * num) second = temp print(first)
Title: Boredom Time Limit: None seconds Memory Limit: None megabytes Problem Description: Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it. Given a sequence *a* consisting of *n* integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it *a**k*) and delete it, at that all elements equal to *a**k*<=+<=1 and *a**k*<=-<=1 also must be deleted from the sequence. That step brings *a**k* points to the player. Alex is a perfectionist, so he decided to get as many points as possible. Help him. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=105) that shows how many numbers are in Alex's sequence. The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105). Output Specification: Print a single integer — the maximum number of points that Alex can earn. Demo Input: ['2\n1 2\n', '3\n1 2 3\n', '9\n1 2 1 3 2 2 2 2 3\n'] Demo Output: ['2\n', '4\n', '10\n'] Note: Consider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this [2, 2, 2, 2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points.
```python import sys from math import * # from pprint import pprint as pprint # from sympy.ntheory.modular import crt import heapq from copy import * from collections import * import functools from itertools import * from math import sqrt, ceil import threading import cmath import time # fin = sys.stdin.read().strip() n = int(input()) nums = [int(c) for c in input().strip().split()] counter = Counter(nums) sorted_nums = sorted(list(set(nums))) second = 0 first = second = 0 for num in sorted_nums: temp = first first = max(first, second + counter[num] * num) second = temp print(first) ```
0
278
A
Circle Line
PROGRAMMING
800
[ "implementation" ]
null
null
The circle line of the Berland subway has *n* stations. We know the distances between all pairs of neighboring stations: - *d*1 is the distance between the 1-st and the 2-nd station;- *d*2 is the distance between the 2-nd and the 3-rd station;...- *d**n*<=-<=1 is the distance between the *n*<=-<=1-th and the *n*-th station;- *d**n* is the distance between the *n*-th and the 1-st station. The trains go along the circle line in both directions. Find the shortest distance between stations with numbers *s* and *t*.
The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — the number of stations on the circle line. The second line contains *n* integers *d*1,<=*d*2,<=...,<=*d**n* (1<=≤<=*d**i*<=≤<=100) — the distances between pairs of neighboring stations. The third line contains two integers *s* and *t* (1<=≤<=*s*,<=*t*<=≤<=*n*) — the numbers of stations, between which you need to find the shortest distance. These numbers can be the same. The numbers in the lines are separated by single spaces.
Print a single number — the length of the shortest path between stations number *s* and *t*.
[ "4\n2 3 4 9\n1 3\n", "4\n5 8 2 100\n4 1\n", "3\n1 1 1\n3 1\n", "3\n31 41 59\n1 1\n" ]
[ "5\n", "15\n", "1\n", "0\n" ]
In the first sample the length of path 1 → 2 → 3 equals 5, the length of path 1 → 4 → 3 equals 13. In the second sample the length of path 4 → 1 is 100, the length of path 4 → 3 → 2 → 1 is 15. In the third sample the length of path 3 → 1 is 1, the length of path 3 → 2 → 1 is 2. In the fourth sample the numbers of stations are the same, so the shortest distance equals 0.
500
[ { "input": "4\n2 3 4 9\n1 3", "output": "5" }, { "input": "4\n5 8 2 100\n4 1", "output": "15" }, { "input": "3\n1 1 1\n3 1", "output": "1" }, { "input": "3\n31 41 59\n1 1", "output": "0" }, { "input": "5\n16 13 10 30 15\n4 2", "output": "23" }, { "input": "6\n89 82 87 32 67 33\n4 4", "output": "0" }, { "input": "7\n2 3 17 10 2 2 2\n4 2", "output": "18" }, { "input": "3\n4 37 33\n3 3", "output": "0" }, { "input": "8\n87 40 96 7 86 86 72 97\n6 8", "output": "158" }, { "input": "10\n91 94 75 99 100 91 79 86 79 92\n2 8", "output": "348" }, { "input": "19\n1 1 1 1 2 1 1 1 1 1 2 1 3 2 2 1 1 1 2\n7 7", "output": "0" }, { "input": "34\n96 65 24 99 74 76 97 93 99 69 94 82 92 91 98 83 95 97 96 81 90 95 86 87 43 78 88 86 82 62 76 99 83 96\n21 16", "output": "452" }, { "input": "50\n75 98 65 75 99 89 84 65 9 53 62 61 61 53 80 7 6 47 86 1 89 27 67 1 31 39 53 92 19 20 76 41 60 15 29 94 76 82 87 89 93 38 42 6 87 36 100 97 93 71\n2 6", "output": "337" }, { "input": "99\n1 15 72 78 23 22 26 98 7 2 75 58 100 98 45 79 92 69 79 72 33 88 62 9 15 87 17 73 68 54 34 89 51 91 28 44 20 11 74 7 85 61 30 46 95 72 36 18 48 22 42 46 29 46 86 53 96 55 98 34 60 37 75 54 1 81 20 68 84 19 18 18 75 84 86 57 73 34 23 43 81 87 47 96 57 41 69 1 52 44 54 7 85 35 5 1 19 26 7\n4 64", "output": "1740" }, { "input": "100\n33 63 21 27 49 82 86 93 43 55 4 72 89 85 5 34 80 7 23 13 21 49 22 73 89 65 81 25 6 92 82 66 58 88 48 96 1 1 16 48 67 96 84 63 87 76 20 100 36 4 31 41 35 62 55 76 74 70 68 41 4 16 39 81 2 41 34 73 66 57 41 89 78 93 68 96 87 47 92 60 40 58 81 12 19 74 56 83 56 61 83 97 26 92 62 52 39 57 89 95\n71 5", "output": "2127" }, { "input": "100\n95 98 99 81 98 96 100 92 96 90 99 91 98 98 91 78 97 100 96 98 87 93 96 99 91 92 96 92 90 97 85 83 99 95 66 91 87 89 100 95 100 88 99 84 96 79 99 100 94 100 99 99 92 89 99 91 100 94 98 97 91 92 90 87 84 99 97 98 93 100 90 85 75 95 86 71 98 93 91 87 92 95 98 94 95 94 100 98 96 100 97 96 95 95 86 86 94 97 98 96\n67 57", "output": "932" }, { "input": "100\n100 100 100 100 100 100 100 100 100 100 97 100 100 100 100 100 99 100 100 99 99 100 99 100 100 100 100 100 100 100 100 100 97 99 98 98 100 98 98 100 99 100 100 100 100 99 100 98 100 99 98 99 98 98 100 100 100 100 100 100 100 100 100 100 99 100 100 100 100 100 98 100 99 99 100 96 100 96 100 99 100 100 99 100 99 100 100 100 99 100 100 100 100 98 98 97 100 100 99 98\n16 6", "output": "997" }, { "input": "100\n3 6 23 4 23 1 2 14 2 3 3 9 17 8 10 5 1 14 8 5 7 4 13 8 5 6 24 3 12 3 4 9 2 8 2 1 2 1 3 2 1 6 14 23 8 6 3 5 7 8 18 9 2 5 22 6 13 16 2 4 31 20 4 3 3 6 6 1 1 18 5 11 1 14 4 16 6 37 11 1 8 3 7 11 21 14 3 3 12 2 5 1 9 16 3 1 3 4 4 2\n98 24", "output": "195" }, { "input": "100\n1 1 3 1 1 2 1 2 1 1 2 2 2 1 1 1 1 1 1 3 1 1 1 3 1 3 3 1 1 2 1 1 1 1 1 2 1 1 1 4 1 1 3 3 2 1 1 1 1 1 2 2 1 3 1 1 1 2 4 1 1 2 5 2 1 1 2 1 1 1 2 3 1 1 1 1 2 1 1 1 1 2 1 1 1 1 1 2 2 3 1 7 3 1 3 1 2 1 2 1\n49 10", "output": "60" }, { "input": "100\n75 62 31 96 62 76 93 96 72 67 88 35 67 34 60 56 95 86 82 48 64 61 74 100 56 98 76 98 78 55 53 10 12 78 58 45 86 90 93 77 69 73 88 66 92 88 33 50 95 69 89 12 93 57 93 89 59 53 71 86 15 13 61 93 24 100 58 76 46 95 76 82 50 20 79 38 5 72 99 81 55 90 90 65 85 44 63 39 6 34 98 72 88 30 59 73 84 61 25 67\n86 25", "output": "2523" }, { "input": "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\n1 51", "output": "5000" }, { "input": "4\n1 1 1 1\n2 4", "output": "2" }, { "input": "4\n1 1 2 1\n2 4", "output": "2" } ]
1,659,170,515
2,147,483,647
PyPy 3-64
OK
TESTS
23
154
0
n=int(input()) l1=[int(i) for i in input().split()] l2=[int(j) for j in input().split()] s=min(l2) t=max(l2) if s==t: print(0) else : l3=[] d=t-s count=0 for k in range(d): count=count+l1[s-1+k] l3.append(count) l3.append(sum(l1)-count) print(min(l3))
Title: Circle Line Time Limit: None seconds Memory Limit: None megabytes Problem Description: The circle line of the Berland subway has *n* stations. We know the distances between all pairs of neighboring stations: - *d*1 is the distance between the 1-st and the 2-nd station;- *d*2 is the distance between the 2-nd and the 3-rd station;...- *d**n*<=-<=1 is the distance between the *n*<=-<=1-th and the *n*-th station;- *d**n* is the distance between the *n*-th and the 1-st station. The trains go along the circle line in both directions. Find the shortest distance between stations with numbers *s* and *t*. Input Specification: The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — the number of stations on the circle line. The second line contains *n* integers *d*1,<=*d*2,<=...,<=*d**n* (1<=≤<=*d**i*<=≤<=100) — the distances between pairs of neighboring stations. The third line contains two integers *s* and *t* (1<=≤<=*s*,<=*t*<=≤<=*n*) — the numbers of stations, between which you need to find the shortest distance. These numbers can be the same. The numbers in the lines are separated by single spaces. Output Specification: Print a single number — the length of the shortest path between stations number *s* and *t*. Demo Input: ['4\n2 3 4 9\n1 3\n', '4\n5 8 2 100\n4 1\n', '3\n1 1 1\n3 1\n', '3\n31 41 59\n1 1\n'] Demo Output: ['5\n', '15\n', '1\n', '0\n'] Note: In the first sample the length of path 1 → 2 → 3 equals 5, the length of path 1 → 4 → 3 equals 13. In the second sample the length of path 4 → 1 is 100, the length of path 4 → 3 → 2 → 1 is 15. In the third sample the length of path 3 → 1 is 1, the length of path 3 → 2 → 1 is 2. In the fourth sample the numbers of stations are the same, so the shortest distance equals 0.
```python n=int(input()) l1=[int(i) for i in input().split()] l2=[int(j) for j in input().split()] s=min(l2) t=max(l2) if s==t: print(0) else : l3=[] d=t-s count=0 for k in range(d): count=count+l1[s-1+k] l3.append(count) l3.append(sum(l1)-count) print(min(l3)) ```
3
630
A
Again Twenty Five!
PROGRAMMING
800
[ "number theory" ]
null
null
The HR manager was disappointed again. The last applicant failed the interview the same way as 24 previous ones. "Do I give such a hard task?" — the HR manager thought. "Just raise number 5 to the power of *n* and get last two digits of the number. Yes, of course, *n* can be rather big, and one cannot find the power using a calculator, but we need people who are able to think, not just follow the instructions." Could you pass the interview in the machine vision company in IT City?
The only line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=2·1018) — the power in which you need to raise number 5.
Output the last two digits of 5*n* without spaces between them.
[ "2\n" ]
[ "25" ]
none
0
[ { "input": "2", "output": "25" }, { "input": "7", "output": "25" }, { "input": "1000000000000000000", "output": "25" }, { "input": "2000000000000000000", "output": "25" }, { "input": "987654321012345678", "output": "25" } ]
1,699,683,055
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
15
0
x=int(input()) print(5**x)
Title: Again Twenty Five! Time Limit: None seconds Memory Limit: None megabytes Problem Description: The HR manager was disappointed again. The last applicant failed the interview the same way as 24 previous ones. "Do I give such a hard task?" — the HR manager thought. "Just raise number 5 to the power of *n* and get last two digits of the number. Yes, of course, *n* can be rather big, and one cannot find the power using a calculator, but we need people who are able to think, not just follow the instructions." Could you pass the interview in the machine vision company in IT City? Input Specification: The only line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=2·1018) — the power in which you need to raise number 5. Output Specification: Output the last two digits of 5*n* without spaces between them. Demo Input: ['2\n'] Demo Output: ['25'] Note: none
```python x=int(input()) print(5**x) ```
0
707
A
Brain's Photos
PROGRAMMING
800
[ "implementation" ]
null
null
Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead. As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such). Brain took a lot of colourful pictures on colored and black-and-white film. Then he developed and translated it into a digital form. But now, color and black-and-white photos are in one folder, and to sort them, one needs to spend more than one hour! As soon as Brain is a photographer not programmer now, he asks you to help him determine for a single photo whether it is colored or black-and-white. Photo can be represented as a matrix sized *n*<=×<=*m*, and each element of the matrix stores a symbol indicating corresponding pixel color. There are only 6 colors: - 'C' (cyan)- 'M' (magenta)- 'Y' (yellow)- 'W' (white)- 'G' (grey)- 'B' (black) The photo is considered black-and-white if it has only white, black and grey pixels in it. If there are any of cyan, magenta or yellow pixels in the photo then it is considered colored.
The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of photo pixel matrix rows and columns respectively. Then *n* lines describing matrix rows follow. Each of them contains *m* space-separated characters describing colors of pixels in a row. Each character in the line is one of the 'C', 'M', 'Y', 'W', 'G' or 'B'.
Print the "#Black&amp;White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line.
[ "2 2\nC M\nY Y\n", "3 2\nW W\nW W\nB B\n", "1 1\nW\n" ]
[ "#Color", "#Black&amp;White", "#Black&amp;White" ]
none
500
[ { "input": "2 2\nC M\nY Y", "output": "#Color" }, { "input": "3 2\nW W\nW W\nB B", "output": "#Black&White" }, { "input": "1 1\nW", "output": "#Black&White" }, { "input": "2 3\nW W W\nB G Y", "output": "#Color" }, { "input": "1 1\nW", "output": "#Black&White" }, { "input": "5 5\nW G B Y M\nG B Y M C\nB Y M C W\nY M C W G\nM C W G B", "output": "#Color" }, { "input": "1 6\nC M Y W G B", "output": "#Color" }, { "input": "1 3\nW G B", "output": "#Black&White" }, { "input": "1 1\nW", "output": "#Black&White" }, { "input": "5 5\nW G B W G\nG B W G B\nB W G B W\nW G B W G\nG B W G B", "output": "#Black&White" }, { "input": "2 3\nW W W\nB G C", "output": "#Color" }, { "input": "2 3\nW W W\nB G M", "output": "#Color" }, { "input": "3 3\nC B W\nB Y M\nB B W", "output": "#Color" }, { "input": "1 3\nW C W", "output": "#Color" }, { "input": "3 3\nB W B\nB C W\nB W W", "output": "#Color" }, { "input": "1 2\nW Y", "output": "#Color" }, { "input": "1 1\nG", "output": "#Black&White" }, { "input": "1 3\nB G W", "output": "#Black&White" }, { "input": "2 2\nW W\nB C", "output": "#Color" }, { "input": "1 1\nM", "output": "#Color" }, { "input": "1 2\nW C", "output": "#Color" }, { "input": "2 3\nW W M\nW W M", "output": "#Color" }, { "input": "3 2\nW W\nW W\nB C", "output": "#Color" }, { "input": "2 3\nW W C\nW W W", "output": "#Color" }, { "input": "1 3\nG G G", "output": "#Black&White" }, { "input": "1 1\nC", "output": "#Color" }, { "input": "1 2\nC W", "output": "#Color" }, { "input": "1 3\nW W C", "output": "#Color" }, { "input": "2 2\nW B\nB G", "output": "#Black&White" }, { "input": "2 2\nB B\nY Y", "output": "#Color" }, { "input": "2 2\nG G\nC C", "output": "#Color" }, { "input": "1 2\nB C", "output": "#Color" }, { "input": "1 4\nG G G C", "output": "#Color" }, { "input": "1 1\nB", "output": "#Black&White" }, { "input": "2 1\nY\nB", "output": "#Color" } ]
1,696,925,668
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
46
0
a,x=list(map(int,input().split())) for i in range(a): s=list(map(str,input().split())) if(s.__contains__('C') or s.__contains__('M') or s.__contains__('Y') or s.__contains__('G')): print("#color") elif(s.__contains__('B') or s.__contains__('W')): print("#Black&White")
Title: Brain's Photos Time Limit: None seconds Memory Limit: None megabytes Problem Description: Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead. As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such). Brain took a lot of colourful pictures on colored and black-and-white film. Then he developed and translated it into a digital form. But now, color and black-and-white photos are in one folder, and to sort them, one needs to spend more than one hour! As soon as Brain is a photographer not programmer now, he asks you to help him determine for a single photo whether it is colored or black-and-white. Photo can be represented as a matrix sized *n*<=×<=*m*, and each element of the matrix stores a symbol indicating corresponding pixel color. There are only 6 colors: - 'C' (cyan)- 'M' (magenta)- 'Y' (yellow)- 'W' (white)- 'G' (grey)- 'B' (black) The photo is considered black-and-white if it has only white, black and grey pixels in it. If there are any of cyan, magenta or yellow pixels in the photo then it is considered colored. Input Specification: The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of photo pixel matrix rows and columns respectively. Then *n* lines describing matrix rows follow. Each of them contains *m* space-separated characters describing colors of pixels in a row. Each character in the line is one of the 'C', 'M', 'Y', 'W', 'G' or 'B'. Output Specification: Print the "#Black&amp;White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line. Demo Input: ['2 2\nC M\nY Y\n', '3 2\nW W\nW W\nB B\n', '1 1\nW\n'] Demo Output: ['#Color', '#Black&amp;White', '#Black&amp;White'] Note: none
```python a,x=list(map(int,input().split())) for i in range(a): s=list(map(str,input().split())) if(s.__contains__('C') or s.__contains__('M') or s.__contains__('Y') or s.__contains__('G')): print("#color") elif(s.__contains__('B') or s.__contains__('W')): print("#Black&White") ```
0
0
none
none
none
0
[ "none" ]
null
null
Nephren is playing a game with little leprechauns. She gives them an infinite array of strings, *f*0... ∞. *f*0 is "What are you doing at the end of the world? Are you busy? Will you save us?". She wants to let more people know about it, so she defines *f**i*<==<= "What are you doing while sending "*f**i*<=-<=1"? Are you busy? Will you send "*f**i*<=-<=1"?" for all *i*<=≥<=1. For example, *f*1 is "What are you doing while sending "What are you doing at the end of the world? Are you busy? Will you save us?"? Are you busy? Will you send "What are you doing at the end of the world? Are you busy? Will you save us?"?". Note that the quotes in the very beginning and in the very end are for clarity and are not a part of *f*1. It can be seen that the characters in *f**i* are letters, question marks, (possibly) quotation marks and spaces. Nephren will ask the little leprechauns *q* times. Each time she will let them find the *k*-th character of *f**n*. The characters are indexed starting from 1. If *f**n* consists of less than *k* characters, output '.' (without quotes). Can you answer her queries?
The first line contains one integer *q* (1<=≤<=*q*<=≤<=10) — the number of Nephren's questions. Each of the next *q* lines describes Nephren's question and contains two integers *n* and *k* (0<=≤<=*n*<=≤<=105,<=1<=≤<=*k*<=≤<=1018).
One line containing *q* characters. The *i*-th character in it should be the answer for the *i*-th query.
[ "3\n1 1\n1 2\n1 111111111111\n", "5\n0 69\n1 194\n1 139\n0 47\n1 66\n", "10\n4 1825\n3 75\n3 530\n4 1829\n4 1651\n3 187\n4 584\n4 255\n4 774\n2 474\n" ]
[ "Wh.", "abdef", "Areyoubusy" ]
For the first two examples, refer to *f*<sub class="lower-index">0</sub> and *f*<sub class="lower-index">1</sub> given in the legend.
0
[ { "input": "3\n1 1\n1 2\n1 111111111111", "output": "Wh." }, { "input": "5\n0 69\n1 194\n1 139\n0 47\n1 66", "output": "abdef" }, { "input": "10\n4 1825\n3 75\n3 530\n4 1829\n4 1651\n3 187\n4 584\n4 255\n4 774\n2 474", "output": "Areyoubusy" }, { "input": "1\n0 1", "output": "W" }, { "input": "1\n999 1000000000000000000", "output": "?" }, { "input": "10\n1 8\n1 8\n9 5\n0 1\n8 1\n7 3\n5 2\n0 9\n4 6\n9 4", "output": "ee WWah at" }, { "input": "10\n5 235941360876088213\n10 65160787148797531\n0 531970131175601601\n2 938108094014908387\n3 340499457696664259\n5 56614532774539063\n5 719524142056884004\n10 370927072502555372\n2 555965798821270052\n10 492559401050725258", "output": ".........." }, { "input": "10\n72939 670999605706502447\n67498 428341803949410086\n62539 938370976591475035\n58889 657471364021290792\n11809 145226347556228466\n77111 294430864855433173\n29099 912050147755964704\n27793 196249143894732547\n118 154392540400153863\n62843 63234003203996349", "output": "?usaglrnyh" }, { "input": "10\n74 752400948436334811\n22 75900251524550494\n48 106700456127359025\n20 623493261724933249\n90 642991963097110817\n42 47750435275360941\n24 297055789449373682\n65 514620361483452045\n99 833434466044716497\n0 928523848526511085", "output": "h... .. d." }, { "input": "10\n26302 2898997\n2168 31686909\n56241 27404733\n9550 44513376\n70116 90169838\n14419 95334944\n61553 16593205\n85883 42147334\n55209 74676056\n57866 68603505", "output": "donts ly o" }, { "input": "9\n50 161003686678495163\n50 161003686678495164\n50 161003686678495165\n51 322007373356990395\n51 322007373356990396\n51 322007373356990397\n52 644014746713980859\n52 644014746713980860\n52 644014746713980861", "output": "\"?.\"?.\"?." }, { "input": "10\n100000 1000000000000000000\n99999 999999999999998683\n99998 999999999999997366\n99997 999999999999996049\n99996 999999999999994732\n99995 999999999999993415\n99994 999999999999992098\n99993 999999999999990781\n99992 999999999999989464\n99991 999999999999988147", "output": "o u lugW? " }, { "input": "10\n94455 839022536766957828\n98640 878267599238035211\n90388 54356607570140506\n93536 261222577013066170\n91362 421089574363407592\n95907 561235487589345620\n91888 938806156011561508\n90820 141726323964466814\n97856 461989202234320135\n92518 602709074380260370", "output": "youni iiee" }, { "input": "10\n100000 873326525630182716\n100000 620513733919162415\n100000 482953375281256917\n100000 485328193417229962\n100000 353549227094721271\n100000 367447590857326107\n100000 627193846053528323\n100000 243833127760837417\n100000 287297493528203749\n100000 70867563577617188", "output": "o W rlot" }, { "input": "10\n1 1\n1 34\n1 35\n1 109\n1 110\n1 141\n1 142\n1 216\n1 217\n1 218", "output": "W\"W?\"\"W?\"?" }, { "input": "10\n5 1\n5 34\n5 35\n5 2254\n5 2255\n5 2286\n5 2287\n5 4506\n5 4507\n5 4508", "output": "W\"W?\"\"W?\"?" }, { "input": "10\n10 1\n10 34\n10 35\n10 73182\n10 73183\n10 73214\n10 73215\n10 146362\n10 146363\n10 146364", "output": "W\"W?\"\"W?\"?" }, { "input": "10\n15 1\n15 34\n15 35\n15 2342878\n15 2342879\n15 2342910\n15 2342911\n15 4685754\n15 4685755\n15 4685756", "output": "W\"W?\"\"W?\"?" }, { "input": "10\n35 1\n35 34\n35 35\n35 2456721293278\n35 2456721293279\n35 2456721293310\n35 2456721293311\n35 4913442586554\n35 4913442586555\n35 4913442586556", "output": "W\"W?\"\"W?\"?" }, { "input": "10\n47 1\n47 34\n47 35\n47 10062730417405918\n47 10062730417405919\n47 10062730417405950\n47 10062730417405951\n47 20125460834811834\n47 20125460834811835\n47 20125460834811836", "output": "W\"W?\"\"W?\"?" }, { "input": "10\n50 1\n50 34\n50 35\n50 80501843339247582\n50 80501843339247583\n50 80501843339247614\n50 80501843339247615\n50 161003686678495162\n50 161003686678495163\n50 161003686678495164", "output": "W\"W?\"\"W?\"?" }, { "input": "10\n52 1\n52 34\n52 35\n52 322007373356990430\n52 322007373356990431\n52 322007373356990462\n52 322007373356990463\n52 644014746713980858\n52 644014746713980859\n52 644014746713980860", "output": "W\"W?\"\"W?\"?" }, { "input": "10\n54986 859285936548585889\n49540 198101079999865795\n96121 658386311981208488\n27027 787731514451843966\n60674 736617460878411577\n57761 569094390437687993\n93877 230086639196124716\n75612 765187050118682698\n75690 960915623784157529\n1788 121643460920471434", "output": "oru A\" de\"" }, { "input": "10\n13599 295514896417102030\n70868 206213281730527977\n99964 675362501525687265\n8545 202563221795027954\n62885 775051601455683055\n44196 552672589494215033\n38017 996305706075726957\n82157 778541544539864990\n13148 755735956771594947\n66133 739544460375378867", "output": "t?W y wnr" }, { "input": "10\n23519 731743847695683578\n67849 214325487756157455\n39048 468966654215390234\n30476 617394929138211942\n40748 813485737737987237\n30632 759622821110550585\n30851 539152740395520686\n23942 567423516617312907\n93605 75958684925842506\n24977 610678262374451619", "output": "WonreeuhAn" }, { "input": "10\n66613 890998077399614704\n59059 389024292752123693\n10265 813853582068134597\n71434 128404685079108014\n76180 582880920044162144\n1123 411409570241705915\n9032 611954441092300071\n78951 57503725302368508\n32102 824738435154619172\n44951 53991552354407935", "output": "i oio u? " }, { "input": "10\n96988 938722606709261427\n97034 794402579184858837\n96440 476737696947281053\n96913 651380108479508367\n99570 535723325634376015\n97425 180427887538234591\n97817 142113098762476646\n96432 446510004868669235\n98788 476529766139390976\n96231 263034481360542586", "output": "eunWwdtnA " }, { "input": "10\n99440 374951566577777567\n98662 802514785210488315\n97117 493713886491759829\n97252 66211820117659651\n98298 574157457621712902\n99067 164006086594761631\n99577 684960128787303079\n96999 12019940091341344\n97772 796752494293638534\n96958 134168283359615339", "output": "idrd? o nl" }, { "input": "10\n95365 811180517856359115\n97710 810626986941150496\n98426 510690080331205902\n99117 481043523165876343\n95501 612591593904017084\n96340 370956318211097183\n96335 451179199961872617\n95409 800901907873821965\n97650 893603181298142989\n96159 781930052798879580", "output": "oisv\"sb ta" }, { "input": "10\n96759 970434747560290241\n95684 985325796232084031\n99418 855577012478917561\n98767 992053283401739711\n99232 381986776210191990\n97804 22743067342252513\n95150 523980900658652001\n98478 290982116558877566\n98012 642382931526919655\n96374 448615375338644407", "output": " e\"atdW? e" }, { "input": "10\n5 929947814902665291\n0 270929202623248779\n10 917958578362357217\n3 674632947904782968\n7 19875145653630834\n8 744882317760093379\n4 471398991908637021\n7 253934163977433229\n7 125334789085610404\n10 841267552326270425", "output": ".........." }, { "input": "10\n3 366176770476214135\n10 55669371794102449\n1 934934767906835993\n0 384681214954881520\n4 684989729845321867\n8 231000356557573162\n1 336780423782602481\n2 300230185318227609\n7 23423148068105278\n1 733131408103947638", "output": ".........." }, { "input": "10\n6 25777762904538788\n1 63781573524764630\n5 951910961746282066\n9 280924325736375136\n6 96743418218239198\n1 712038707283212867\n4 780465093108032992\n4 608326071277553255\n8 542408204244362417\n3 360163123764607419", "output": ".........." }, { "input": "10\n1 185031988313502617\n8 461852423965441269\n2 296797889599026429\n3 15306118532047016\n6 866138600524414105\n10 587197493269144005\n2 853266793804812376\n2 98406279962608857\n3 291187954473139083\n0 26848446304372246", "output": ".........." }, { "input": "10\n27314 39\n71465 12\n29327 53\n33250 85\n52608 41\n19454 55\n72760 12\n83873 90\n67859 78\n91505 73", "output": " u nrhuiy " }, { "input": "10\n76311 57\n79978 83\n34607 89\n62441 98\n28700 35\n54426 67\n66596 15\n30889 21\n68793 7\n29916 71", "output": "lohiW ohra" } ]
1,512,226,186
2,686
Python 3
RUNTIME_ERROR
PRETESTS
4
124
6,656,000
import decimal as D f_0 = "What are you doing at the end of the world? Are you busy? Will you save us?" prefix = 'What are you doing while sending "' middle = '"? Are you busy? Will you send "' suffix = '"?' c = len(prefix) + len(middle) + len(suffix) def len_f_n(n): if n == 0: return len(f_0) else: return (D.Decimal(2) ** n) * (len(f_0) + c) - c def g(n, k): if n == 0: if k < len(f_0): return f_0[int(k)] else: # print('f_0 ., k: {}'.format(k)) return '.' if k < len(prefix): return prefix[int(k)] l_f_n = len_f_n(n - 1) if k < len(prefix) + l_f_n: return g(n - 1, k - len(prefix)) elif k < len(prefix) + l_f_n + len(middle): return middle[int(k - len(prefix) - l_f_n)] elif k < len(prefix) + l_f_n + len(middle) + l_f_n: return g(n - 1, k - l_f_n - len(prefix) - len(middle)) elif k < len(prefix) + l_f_n + len(middle) + l_f_n + len(suffix): return suffix[int(k - len(prefix) - l_f_n - len(middle) - l_f_n)] else: # print('f_{} .'.format(n)) return '.' q = int(input()) s = '' for _ in range(q): args = input().split() n, k = int(args[0]), D.Decimal(args[1]) s += g(n, k - 1) print(s)
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Nephren is playing a game with little leprechauns. She gives them an infinite array of strings, *f*0... ∞. *f*0 is "What are you doing at the end of the world? Are you busy? Will you save us?". She wants to let more people know about it, so she defines *f**i*<==<= "What are you doing while sending "*f**i*<=-<=1"? Are you busy? Will you send "*f**i*<=-<=1"?" for all *i*<=≥<=1. For example, *f*1 is "What are you doing while sending "What are you doing at the end of the world? Are you busy? Will you save us?"? Are you busy? Will you send "What are you doing at the end of the world? Are you busy? Will you save us?"?". Note that the quotes in the very beginning and in the very end are for clarity and are not a part of *f*1. It can be seen that the characters in *f**i* are letters, question marks, (possibly) quotation marks and spaces. Nephren will ask the little leprechauns *q* times. Each time she will let them find the *k*-th character of *f**n*. The characters are indexed starting from 1. If *f**n* consists of less than *k* characters, output '.' (without quotes). Can you answer her queries? Input Specification: The first line contains one integer *q* (1<=≤<=*q*<=≤<=10) — the number of Nephren's questions. Each of the next *q* lines describes Nephren's question and contains two integers *n* and *k* (0<=≤<=*n*<=≤<=105,<=1<=≤<=*k*<=≤<=1018). Output Specification: One line containing *q* characters. The *i*-th character in it should be the answer for the *i*-th query. Demo Input: ['3\n1 1\n1 2\n1 111111111111\n', '5\n0 69\n1 194\n1 139\n0 47\n1 66\n', '10\n4 1825\n3 75\n3 530\n4 1829\n4 1651\n3 187\n4 584\n4 255\n4 774\n2 474\n'] Demo Output: ['Wh.', 'abdef', 'Areyoubusy'] Note: For the first two examples, refer to *f*<sub class="lower-index">0</sub> and *f*<sub class="lower-index">1</sub> given in the legend.
```python import decimal as D f_0 = "What are you doing at the end of the world? Are you busy? Will you save us?" prefix = 'What are you doing while sending "' middle = '"? Are you busy? Will you send "' suffix = '"?' c = len(prefix) + len(middle) + len(suffix) def len_f_n(n): if n == 0: return len(f_0) else: return (D.Decimal(2) ** n) * (len(f_0) + c) - c def g(n, k): if n == 0: if k < len(f_0): return f_0[int(k)] else: # print('f_0 ., k: {}'.format(k)) return '.' if k < len(prefix): return prefix[int(k)] l_f_n = len_f_n(n - 1) if k < len(prefix) + l_f_n: return g(n - 1, k - len(prefix)) elif k < len(prefix) + l_f_n + len(middle): return middle[int(k - len(prefix) - l_f_n)] elif k < len(prefix) + l_f_n + len(middle) + l_f_n: return g(n - 1, k - l_f_n - len(prefix) - len(middle)) elif k < len(prefix) + l_f_n + len(middle) + l_f_n + len(suffix): return suffix[int(k - len(prefix) - l_f_n - len(middle) - l_f_n)] else: # print('f_{} .'.format(n)) return '.' q = int(input()) s = '' for _ in range(q): args = input().split() n, k = int(args[0]), D.Decimal(args[1]) s += g(n, k - 1) print(s) ```
-1
938
D
Buy a Ticket
PROGRAMMING
2,000
[ "data structures", "graphs", "shortest paths" ]
null
null
Musicians of a popular band "Flayer" have announced that they are going to "make their exit" with a world tour. Of course, they will visit Berland as well. There are *n* cities in Berland. People can travel between cities using two-directional train routes; there are exactly *m* routes, *i*-th route can be used to go from city *v**i* to city *u**i* (and from *u**i* to *v**i*), and it costs *w**i* coins to use this route. Each city will be visited by "Flayer", and the cost of the concert ticket in *i*-th city is *a**i* coins. You have friends in every city of Berland, and they, knowing about your programming skills, asked you to calculate the minimum possible number of coins they have to pay to visit the concert. For every city *i* you have to compute the minimum number of coins a person from city *i* has to spend to travel to some city *j* (or possibly stay in city *i*), attend a concert there, and return to city *i* (if *j*<=≠<=*i*). Formally, for every you have to calculate , where *d*(*i*,<=*j*) is the minimum number of coins you have to spend to travel from city *i* to city *j*. If there is no way to reach city *j* from city *i*, then we consider *d*(*i*,<=*j*) to be infinitely large.
The first line contains two integers *n* and *m* (2<=≤<=*n*<=≤<=2·105, 1<=≤<=*m*<=≤<=2·105). Then *m* lines follow, *i*-th contains three integers *v**i*, *u**i* and *w**i* (1<=≤<=*v**i*,<=*u**i*<=≤<=*n*,<=*v**i*<=≠<=*u**i*, 1<=≤<=*w**i*<=≤<=1012) denoting *i*-th train route. There are no multiple train routes connecting the same pair of cities, that is, for each (*v*,<=*u*) neither extra (*v*,<=*u*) nor (*u*,<=*v*) present in input. The next line contains *n* integers *a*1,<=*a*2,<=... *a**k* (1<=≤<=*a**i*<=≤<=1012) — price to attend the concert in *i*-th city.
Print *n* integers. *i*-th of them must be equal to the minimum number of coins a person from city *i* has to spend to travel to some city *j* (or possibly stay in city *i*), attend a concert there, and return to city *i* (if *j*<=≠<=*i*).
[ "4 2\n1 2 4\n2 3 7\n6 20 1 25\n", "3 3\n1 2 1\n2 3 1\n1 3 1\n30 10 20\n" ]
[ "6 14 1 25 \n", "12 10 12 \n" ]
none
0
[ { "input": "4 2\n1 2 4\n2 3 7\n6 20 1 25", "output": "6 14 1 25 " }, { "input": "3 3\n1 2 1\n2 3 1\n1 3 1\n30 10 20", "output": "12 10 12 " }, { "input": "7 7\n1 6 745325\n2 3 3581176\n2 4 19\n3 6 71263060078\n5 4 141198\n7 4 163953\n5 6 15994\n1 297404206755 82096176217 14663411 187389745 21385 704393", "output": "1 335807 7498159 335769 53373 21385 663675 " } ]
1,518,800,278
6,778
Python 3
TIME_LIMIT_EXCEEDED
TESTS
2
2,000
72,294,400
n, m = [int(x) for x in input().split()] d = {k:[] for k in range(1, n+1)} for i in range(m): v, u, w = [int(x) for x in input().split()] d[v].append((u, w)) d[u].append((v, w)) a = [(i, int(x)) for i, x in enumerate(input().split(), 1)] a.sort(key = lambda x: x[1], reverse = True) res = {k:v for k, v in a} while len(a) > 0: cur, cost = a.pop() if res[cur] < cost: continue res[cur] = cost for v, w in d[cur]: if res[v] > w*2+cost: a.append((v, cost+2*w)) for k in range(1, n+1): print(res[k], end = " ")
Title: Buy a Ticket Time Limit: None seconds Memory Limit: None megabytes Problem Description: Musicians of a popular band "Flayer" have announced that they are going to "make their exit" with a world tour. Of course, they will visit Berland as well. There are *n* cities in Berland. People can travel between cities using two-directional train routes; there are exactly *m* routes, *i*-th route can be used to go from city *v**i* to city *u**i* (and from *u**i* to *v**i*), and it costs *w**i* coins to use this route. Each city will be visited by "Flayer", and the cost of the concert ticket in *i*-th city is *a**i* coins. You have friends in every city of Berland, and they, knowing about your programming skills, asked you to calculate the minimum possible number of coins they have to pay to visit the concert. For every city *i* you have to compute the minimum number of coins a person from city *i* has to spend to travel to some city *j* (or possibly stay in city *i*), attend a concert there, and return to city *i* (if *j*<=≠<=*i*). Formally, for every you have to calculate , where *d*(*i*,<=*j*) is the minimum number of coins you have to spend to travel from city *i* to city *j*. If there is no way to reach city *j* from city *i*, then we consider *d*(*i*,<=*j*) to be infinitely large. Input Specification: The first line contains two integers *n* and *m* (2<=≤<=*n*<=≤<=2·105, 1<=≤<=*m*<=≤<=2·105). Then *m* lines follow, *i*-th contains three integers *v**i*, *u**i* and *w**i* (1<=≤<=*v**i*,<=*u**i*<=≤<=*n*,<=*v**i*<=≠<=*u**i*, 1<=≤<=*w**i*<=≤<=1012) denoting *i*-th train route. There are no multiple train routes connecting the same pair of cities, that is, for each (*v*,<=*u*) neither extra (*v*,<=*u*) nor (*u*,<=*v*) present in input. The next line contains *n* integers *a*1,<=*a*2,<=... *a**k* (1<=≤<=*a**i*<=≤<=1012) — price to attend the concert in *i*-th city. Output Specification: Print *n* integers. *i*-th of them must be equal to the minimum number of coins a person from city *i* has to spend to travel to some city *j* (or possibly stay in city *i*), attend a concert there, and return to city *i* (if *j*<=≠<=*i*). Demo Input: ['4 2\n1 2 4\n2 3 7\n6 20 1 25\n', '3 3\n1 2 1\n2 3 1\n1 3 1\n30 10 20\n'] Demo Output: ['6 14 1 25 \n', '12 10 12 \n'] Note: none
```python n, m = [int(x) for x in input().split()] d = {k:[] for k in range(1, n+1)} for i in range(m): v, u, w = [int(x) for x in input().split()] d[v].append((u, w)) d[u].append((v, w)) a = [(i, int(x)) for i, x in enumerate(input().split(), 1)] a.sort(key = lambda x: x[1], reverse = True) res = {k:v for k, v in a} while len(a) > 0: cur, cost = a.pop() if res[cur] < cost: continue res[cur] = cost for v, w in d[cur]: if res[v] > w*2+cost: a.append((v, cost+2*w)) for k in range(1, n+1): print(res[k], end = " ") ```
0
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,680,082,812
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
n = int(input()) a = list(map(int,input())) k1 = 0 k2 = 0 e = 0 o = 0 for i in range(n): if a[i]%2==0: e+ = 1 k1 = i else: o+ = 1 k2 = i if e<o: print(k1) else: print(k2)
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()) a = list(map(int,input())) k1 = 0 k2 = 0 e = 0 o = 0 for i in range(n): if a[i]%2==0: e+ = 1 k1 = i else: o+ = 1 k2 = i if e<o: print(k1) else: print(k2) ```
-1
160
A
Twins
PROGRAMMING
900
[ "greedy", "sortings" ]
null
null
Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very well know what it's like. Now let's imagine a typical morning in your family. You haven't woken up yet, and Mom is already going to work. She has been so hasty that she has nearly forgotten to leave the two of her darling children some money to buy lunches in the school cafeteria. She fished in the purse and found some number of coins, or to be exact, *n* coins of arbitrary values *a*1,<=*a*2,<=...,<=*a**n*. But as Mom was running out of time, she didn't split the coins for you two. So she scribbled a note asking you to split the money equally. As you woke up, you found Mom's coins and read her note. "But why split the money equally?" — you thought. After all, your twin is sleeping and he won't know anything. So you decided to act like that: pick for yourself some subset of coins so that the sum of values of your coins is strictly larger than the sum of values of the remaining coins that your twin will have. However, you correctly thought that if you take too many coins, the twin will suspect the deception. So, you've decided to stick to the following strategy to avoid suspicions: you take the minimum number of coins, whose sum of values is strictly more than the sum of values of the remaining coins. On this basis, determine what minimum number of coins you need to take to divide them in the described manner.
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of coins. The second line contains a sequence of *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=100) — the coins' values. All numbers are separated with spaces.
In the single line print the single number — the minimum needed number of coins.
[ "2\n3 3\n", "3\n2 1 2\n" ]
[ "2\n", "2\n" ]
In the first sample you will have to take 2 coins (you and your twin have sums equal to 6, 0 correspondingly). If you take 1 coin, you get sums 3, 3. If you take 0 coins, you get sums 0, 6. Those variants do not satisfy you as your sum should be strictly more that your twins' sum. In the second sample one coin isn't enough for us, too. You can pick coins with values 1, 2 or 2, 2. In any case, the minimum number of coins equals 2.
500
[ { "input": "2\n3 3", "output": "2" }, { "input": "3\n2 1 2", "output": "2" }, { "input": "1\n5", "output": "1" }, { "input": "5\n4 2 2 2 2", "output": "3" }, { "input": "7\n1 10 1 2 1 1 1", "output": "1" }, { "input": "5\n3 2 3 3 1", "output": "3" }, { "input": "2\n2 1", "output": "1" }, { "input": "3\n2 1 3", "output": "2" }, { "input": "6\n1 1 1 1 1 1", "output": "4" }, { "input": "7\n10 10 5 5 5 5 1", "output": "3" }, { "input": "20\n2 1 2 2 2 1 1 2 1 2 2 1 1 1 1 2 1 1 1 1", "output": "8" }, { "input": "20\n4 2 4 4 3 4 2 2 4 2 3 1 1 2 2 3 3 3 1 4", "output": "8" }, { "input": "20\n35 26 41 40 45 46 22 26 39 23 11 15 47 42 18 15 27 10 45 40", "output": "8" }, { "input": "20\n7 84 100 10 31 35 41 2 63 44 57 4 63 11 23 49 98 71 16 90", "output": "6" }, { "input": "50\n19 2 12 26 17 27 10 26 17 17 5 24 11 15 3 9 16 18 19 1 25 23 18 6 2 7 25 7 21 25 13 29 16 9 25 3 14 30 18 4 10 28 6 10 8 2 2 4 8 28", "output": "14" }, { "input": "70\n2 18 18 47 25 5 14 9 19 46 36 49 33 32 38 23 32 39 8 29 31 17 24 21 10 15 33 37 46 21 22 11 20 35 39 13 11 30 28 40 39 47 1 17 24 24 21 46 12 2 20 43 8 16 44 11 45 10 13 44 31 45 45 46 11 10 33 35 23 42", "output": "22" }, { "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": "51" }, { "input": "100\n1 2 2 1 2 1 1 2 1 1 1 2 2 1 1 1 2 2 2 1 2 1 1 1 1 1 2 1 2 1 2 1 2 1 2 1 1 1 2 1 1 1 1 1 2 2 1 2 1 2 1 2 2 2 1 2 1 2 2 1 1 2 2 1 1 2 2 2 1 1 2 1 1 2 2 1 2 1 1 2 2 1 2 1 1 2 2 1 1 1 1 2 1 1 1 1 2 2 2 2", "output": "37" }, { "input": "100\n1 2 3 2 1 2 2 3 1 3 3 2 2 1 1 2 2 1 1 1 1 2 3 3 2 1 1 2 2 2 3 3 3 2 1 3 1 3 3 2 3 1 2 2 2 3 2 1 1 3 3 3 3 2 1 1 2 3 2 2 3 2 3 2 2 3 2 2 2 2 3 3 3 1 3 3 1 1 2 3 2 2 2 2 3 3 3 2 1 2 3 1 1 2 3 3 1 3 3 2", "output": "36" }, { "input": "100\n5 5 4 3 5 1 2 5 1 1 3 5 4 4 1 1 1 1 5 4 4 5 1 5 5 1 2 1 3 1 5 1 3 3 3 2 2 2 1 1 5 1 3 4 1 1 3 2 5 2 2 5 5 4 4 1 3 4 3 3 4 5 3 3 3 1 2 1 4 2 4 4 1 5 1 3 5 5 5 5 3 4 4 3 1 2 5 2 3 5 4 2 4 5 3 2 4 2 4 3", "output": "33" }, { "input": "100\n3 4 8 10 8 6 4 3 7 7 6 2 3 1 3 10 1 7 9 3 5 5 2 6 2 9 1 7 4 2 4 1 6 1 7 10 2 5 3 7 6 4 6 2 8 8 8 6 6 10 3 7 4 3 4 1 7 9 3 6 3 6 1 4 9 3 8 1 10 1 4 10 7 7 9 5 3 8 10 2 1 10 8 7 10 8 5 3 1 2 1 10 6 1 5 3 3 5 7 2", "output": "30" }, { "input": "100\n16 9 11 8 11 4 9 17 4 8 4 10 9 10 6 3 3 15 1 6 1 15 12 18 6 14 13 18 1 7 18 4 10 7 10 12 3 16 14 4 10 8 10 7 19 13 15 1 4 8 16 10 6 4 3 16 11 10 7 3 4 16 1 20 1 11 4 16 10 7 7 12 18 19 3 17 19 3 4 19 2 12 11 3 18 20 2 2 14 4 20 13 13 11 16 20 19 14 7 2", "output": "29" }, { "input": "100\n2 46 4 6 38 19 15 34 10 35 37 30 3 25 5 45 40 45 33 31 6 20 10 44 11 9 2 14 35 5 9 23 20 2 48 22 25 35 38 31 24 33 35 16 4 30 27 10 12 22 6 24 12 30 23 21 14 12 32 21 7 12 25 43 18 34 34 28 47 13 28 43 18 39 44 42 35 26 35 14 8 29 32 20 29 3 20 6 20 9 9 27 8 42 10 37 42 27 8 1", "output": "30" }, { "input": "100\n85 50 17 89 65 89 5 20 86 26 16 21 85 14 44 31 87 31 6 2 48 67 8 80 79 1 48 36 97 1 5 30 79 50 78 12 2 55 76 100 54 40 26 81 97 96 68 56 87 14 51 17 54 37 52 33 69 62 38 63 74 15 62 78 9 19 67 2 60 58 93 60 18 96 55 48 34 7 79 82 32 58 90 67 20 50 27 15 7 89 98 10 11 15 99 49 4 51 77 52", "output": "29" }, { "input": "100\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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100", "output": "30" }, { "input": "1\n1", "output": "1" }, { "input": "4\n4 1 2 3", "output": "2" }, { "input": "5\n2 2 2 4 4", "output": "2" }, { "input": "4\n100 99 99 100", "output": "2" } ]
1,689,164,832
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
3
122
0
n=int(input()) string=input() sum1=0 sum2=0 k=0 lst2=[int (num) for num in string.split()] lst2.sort() for i in range(n): sum1=sum1+lst2[i] for j in range(n): if (sum2<=(sum1/2)): sum2=sum2+lst2[j] k=k+1 print (k)
Title: Twins Time Limit: None seconds Memory Limit: None megabytes Problem Description: Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very well know what it's like. Now let's imagine a typical morning in your family. You haven't woken up yet, and Mom is already going to work. She has been so hasty that she has nearly forgotten to leave the two of her darling children some money to buy lunches in the school cafeteria. She fished in the purse and found some number of coins, or to be exact, *n* coins of arbitrary values *a*1,<=*a*2,<=...,<=*a**n*. But as Mom was running out of time, she didn't split the coins for you two. So she scribbled a note asking you to split the money equally. As you woke up, you found Mom's coins and read her note. "But why split the money equally?" — you thought. After all, your twin is sleeping and he won't know anything. So you decided to act like that: pick for yourself some subset of coins so that the sum of values of your coins is strictly larger than the sum of values of the remaining coins that your twin will have. However, you correctly thought that if you take too many coins, the twin will suspect the deception. So, you've decided to stick to the following strategy to avoid suspicions: you take the minimum number of coins, whose sum of values is strictly more than the sum of values of the remaining coins. On this basis, determine what minimum number of coins you need to take to divide them in the described manner. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of coins. The second line contains a sequence of *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=100) — the coins' values. All numbers are separated with spaces. Output Specification: In the single line print the single number — the minimum needed number of coins. Demo Input: ['2\n3 3\n', '3\n2 1 2\n'] Demo Output: ['2\n', '2\n'] Note: In the first sample you will have to take 2 coins (you and your twin have sums equal to 6, 0 correspondingly). If you take 1 coin, you get sums 3, 3. If you take 0 coins, you get sums 0, 6. Those variants do not satisfy you as your sum should be strictly more that your twins' sum. In the second sample one coin isn't enough for us, too. You can pick coins with values 1, 2 or 2, 2. In any case, the minimum number of coins equals 2.
```python n=int(input()) string=input() sum1=0 sum2=0 k=0 lst2=[int (num) for num in string.split()] lst2.sort() for i in range(n): sum1=sum1+lst2[i] for j in range(n): if (sum2<=(sum1/2)): sum2=sum2+lst2[j] k=k+1 print (k) ```
0
16
B
Burglar and Matches
PROGRAMMING
900
[ "greedy", "implementation", "sortings" ]
B. Burglar and Matches
0
64
A burglar got into a matches warehouse and wants to steal as many matches as possible. In the warehouse there are *m* containers, in the *i*-th container there are *a**i* matchboxes, and each matchbox contains *b**i* matches. All the matchboxes are of the same size. The burglar's rucksack can hold *n* matchboxes exactly. Your task is to find out the maximum amount of matches that a burglar can carry away. He has no time to rearrange matches in the matchboxes, that's why he just chooses not more than *n* matchboxes so that the total amount of matches in them is maximal.
The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=2·108) and integer *m* (1<=≤<=*m*<=≤<=20). The *i*<=+<=1-th line contains a pair of numbers *a**i* and *b**i* (1<=≤<=*a**i*<=≤<=108,<=1<=≤<=*b**i*<=≤<=10). All the input numbers are integer.
Output the only number — answer to the problem.
[ "7 3\n5 10\n2 5\n3 6\n", "3 3\n1 3\n2 2\n3 1\n" ]
[ "62\n", "7\n" ]
none
0
[ { "input": "7 3\n5 10\n2 5\n3 6", "output": "62" }, { "input": "3 3\n1 3\n2 2\n3 1", "output": "7" }, { "input": "1 1\n1 2", "output": "2" }, { "input": "1 2\n1 9\n1 6", "output": "9" }, { "input": "1 10\n1 1\n1 9\n1 3\n1 9\n1 7\n1 10\n1 4\n1 7\n1 3\n1 1", "output": "10" }, { "input": "2 1\n2 1", "output": "2" }, { "input": "2 2\n2 4\n1 4", "output": "8" }, { "input": "2 3\n1 7\n1 2\n1 5", "output": "12" }, { "input": "4 1\n2 2", "output": "4" }, { "input": "4 2\n1 10\n4 4", "output": "22" }, { "input": "4 3\n1 4\n6 4\n1 7", "output": "19" }, { "input": "5 1\n10 5", "output": "25" }, { "input": "5 2\n3 9\n2 2", "output": "31" }, { "input": "5 5\n2 9\n3 1\n2 1\n1 8\n2 8", "output": "42" }, { "input": "5 10\n1 3\n1 2\n1 9\n1 10\n1 1\n1 5\n1 10\n1 2\n1 3\n1 7", "output": "41" }, { "input": "10 1\n9 4", "output": "36" }, { "input": "10 2\n14 3\n1 3", "output": "30" }, { "input": "10 7\n4 8\n1 10\n1 10\n1 2\n3 3\n1 3\n1 10", "output": "71" }, { "input": "10 10\n1 8\n2 10\n1 9\n1 1\n1 9\n1 6\n1 4\n2 5\n1 2\n1 4", "output": "70" }, { "input": "10 4\n1 5\n5 2\n1 9\n3 3", "output": "33" }, { "input": "100 5\n78 6\n29 10\n3 6\n7 3\n2 4", "output": "716" }, { "input": "1000 7\n102 10\n23 6\n79 4\n48 1\n34 10\n839 8\n38 4", "output": "8218" }, { "input": "10000 10\n336 2\n2782 5\n430 10\n1893 7\n3989 10\n2593 8\n165 6\n1029 2\n2097 4\n178 10", "output": "84715" }, { "input": "100000 3\n2975 2\n35046 4\n61979 9", "output": "703945" }, { "input": "1000000 4\n314183 9\n304213 4\n16864 5\n641358 9", "output": "8794569" }, { "input": "10000000 10\n360313 10\n416076 1\n435445 9\n940322 7\n1647581 7\n4356968 10\n3589256 2\n2967933 5\n2747504 7\n1151633 3", "output": "85022733" }, { "input": "100000000 7\n32844337 7\n11210848 7\n47655987 1\n33900472 4\n9174763 2\n32228738 10\n29947408 5", "output": "749254060" }, { "input": "200000000 10\n27953106 7\n43325979 4\n4709522 1\n10975786 4\n67786538 8\n48901838 7\n15606185 6\n2747583 1\n100000000 1\n633331 3", "output": "1332923354" }, { "input": "200000000 9\n17463897 9\n79520463 1\n162407 4\n41017993 8\n71054118 4\n9447587 2\n5298038 9\n3674560 7\n20539314 5", "output": "996523209" }, { "input": "200000000 8\n6312706 6\n2920548 2\n16843192 3\n1501141 2\n13394704 6\n10047725 10\n4547663 6\n54268518 6", "output": "630991750" }, { "input": "200000000 7\n25621043 2\n21865270 1\n28833034 1\n22185073 5\n100000000 2\n13891017 9\n61298710 8", "output": "931584598" }, { "input": "200000000 6\n7465600 6\n8453505 10\n4572014 8\n8899499 3\n86805622 10\n64439238 6", "output": "1447294907" }, { "input": "200000000 5\n44608415 6\n100000000 9\n51483223 9\n44136047 1\n52718517 1", "output": "1634907859" }, { "input": "200000000 4\n37758556 10\n100000000 6\n48268521 3\n20148178 10", "output": "1305347138" }, { "input": "200000000 3\n65170000 7\n20790088 1\n74616133 4", "output": "775444620" }, { "input": "200000000 2\n11823018 6\n100000000 9", "output": "970938108" }, { "input": "200000000 1\n100000000 6", "output": "600000000" }, { "input": "200000000 10\n12097724 9\n41745972 5\n26982098 9\n14916995 7\n21549986 7\n3786630 9\n8050858 7\n27994924 4\n18345001 5\n8435339 5", "output": "1152034197" }, { "input": "200000000 10\n55649 8\n10980981 9\n3192542 8\n94994808 4\n3626106 1\n100000000 6\n5260110 9\n4121453 2\n15125061 4\n669569 6", "output": "1095537357" }, { "input": "10 20\n1 7\n1 7\n1 8\n1 3\n1 10\n1 7\n1 7\n1 9\n1 3\n1 1\n1 2\n1 1\n1 3\n1 10\n1 9\n1 8\n1 8\n1 6\n1 7\n1 5", "output": "83" }, { "input": "10000000 20\n4594 7\n520836 8\n294766 6\n298672 4\n142253 6\n450626 1\n1920034 9\n58282 4\n1043204 1\n683045 1\n1491746 5\n58420 4\n451217 2\n129423 4\n246113 5\n190612 8\n912923 6\n473153 6\n783733 6\n282411 10", "output": "54980855" }, { "input": "200000000 20\n15450824 5\n839717 10\n260084 8\n1140850 8\n28744 6\n675318 3\n25161 2\n5487 3\n6537698 9\n100000000 5\n7646970 9\n16489 6\n24627 3\n1009409 5\n22455 1\n25488456 4\n484528 9\n32663641 3\n750968 4\n5152 6", "output": "939368573" }, { "input": "200000000 20\n16896 2\n113 3\n277 2\n299 7\n69383562 2\n3929 8\n499366 4\n771846 5\n9 4\n1278173 7\n90 2\n54 7\n72199858 10\n17214 5\n3 10\n1981618 3\n3728 2\n141 8\n2013578 9\n51829246 5", "output": "1158946383" }, { "input": "200000000 20\n983125 2\n7453215 9\n9193588 2\n11558049 7\n28666199 1\n34362244 1\n5241493 5\n15451270 4\n19945845 8\n6208681 3\n38300385 7\n6441209 8\n21046742 7\n577198 10\n3826434 8\n9764276 8\n6264675 7\n8567063 3\n3610303 4\n2908232 3", "output": "1131379312" }, { "input": "10 15\n1 6\n2 6\n3 4\n1 3\n1 2\n1 5\n1 6\n1 2\n2 9\n1 10\n1 3\n1 7\n1 8\n1 2\n2 9", "output": "79" }, { "input": "10000000 15\n111 5\n914124 3\n3 9\n177790 1\n2352 3\n32138 9\n104477 1\n1223 4\n18 6\n6655580 4\n57643 10\n94309 2\n37 1\n227002 10\n1733193 7", "output": "45116295" }, { "input": "200000000 15\n7069868 1\n5567826 8\n2310059 10\n13539782 7\n38420939 4\n29911411 8\n52256316 1\n12265839 9\n2074265 1\n24896428 9\n72470695 5\n3236301 1\n3890243 2\n65168965 8\n65724 6", "output": "1489289257" }, { "input": "200000000 15\n12044094 7\n2475138 10\n944451 7\n4854766 2\n3809145 10\n7727571 2\n43908937 6\n2745883 1\n427511 2\n100000000 5\n190914 6\n554889 3\n288798 4\n1848572 5\n893874 3", "output": "961871671" }, { "input": "200000000 15\n6334191 7\n1927941 4\n5175933 10\n468389 1\n433043 10\n6863198 5\n7480646 4\n14774279 10\n2921129 8\n18325627 7\n6973152 9\n8277324 9\n21522856 2\n2058070 1\n2444742 4", "output": "664376069" } ]
1,693,231,157
2,147,483,647
Python 3
OK
TESTS
49
92
0
def maximum_matches(n, m, containers): containers.sort(key=lambda x: x[1], reverse=True) total_matches = 0 remaining_boxes = n for i in range(m): matchboxes, matches_per_box = containers[i] if remaining_boxes >= matchboxes: total_matches += matchboxes * matches_per_box remaining_boxes -= matchboxes else: total_matches += remaining_boxes * matches_per_box break return total_matches n, m = map(int, input().split()) containers = [] for _ in range(m): a, b = map(int, input().split()) containers.append((a, b)) print(maximum_matches(n, m, containers))
Title: Burglar and Matches Time Limit: 0 seconds Memory Limit: 64 megabytes Problem Description: A burglar got into a matches warehouse and wants to steal as many matches as possible. In the warehouse there are *m* containers, in the *i*-th container there are *a**i* matchboxes, and each matchbox contains *b**i* matches. All the matchboxes are of the same size. The burglar's rucksack can hold *n* matchboxes exactly. Your task is to find out the maximum amount of matches that a burglar can carry away. He has no time to rearrange matches in the matchboxes, that's why he just chooses not more than *n* matchboxes so that the total amount of matches in them is maximal. Input Specification: The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=2·108) and integer *m* (1<=≤<=*m*<=≤<=20). The *i*<=+<=1-th line contains a pair of numbers *a**i* and *b**i* (1<=≤<=*a**i*<=≤<=108,<=1<=≤<=*b**i*<=≤<=10). All the input numbers are integer. Output Specification: Output the only number — answer to the problem. Demo Input: ['7 3\n5 10\n2 5\n3 6\n', '3 3\n1 3\n2 2\n3 1\n'] Demo Output: ['62\n', '7\n'] Note: none
```python def maximum_matches(n, m, containers): containers.sort(key=lambda x: x[1], reverse=True) total_matches = 0 remaining_boxes = n for i in range(m): matchboxes, matches_per_box = containers[i] if remaining_boxes >= matchboxes: total_matches += matchboxes * matches_per_box remaining_boxes -= matchboxes else: total_matches += remaining_boxes * matches_per_box break return total_matches n, m = map(int, input().split()) containers = [] for _ in range(m): a, b = map(int, input().split()) containers.append((a, b)) print(maximum_matches(n, m, containers)) ```
3
282
A
Bit++
PROGRAMMING
800
[ "implementation" ]
null
null
The classic programming language of Bitland is Bit++. This language is so peculiar and complicated. The language is that peculiar as it has exactly one variable, called *x*. Also, there are two operations: - Operation ++ increases the value of variable *x* by 1. - Operation -- decreases the value of variable *x* by 1. A statement in language Bit++ is a sequence, consisting of exactly one operation and one variable *x*. The statement is written without spaces, that is, it can only contain characters "+", "-", "X". Executing a statement means applying the operation it contains. A programme in Bit++ is a sequence of statements, each of them needs to be executed. Executing a programme means executing all the statements it contains. You're given a programme in language Bit++. The initial value of *x* is 0. Execute the programme and find its final value (the value of the variable when this programme is executed).
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=150) — the number of statements in the programme. Next *n* lines contain a statement each. Each statement contains exactly one operation (++ or --) and exactly one variable *x* (denoted as letter «X»). Thus, there are no empty statements. The operation and the variable can be written in any order.
Print a single integer — the final value of *x*.
[ "1\n++X\n", "2\nX++\n--X\n" ]
[ "1\n", "0\n" ]
none
500
[ { "input": "1\n++X", "output": "1" }, { "input": "2\nX++\n--X", "output": "0" }, { "input": "3\n++X\n++X\n++X", "output": "3" }, { "input": "2\n--X\n--X", "output": "-2" }, { "input": "5\n++X\n--X\n++X\n--X\n--X", "output": "-1" }, { "input": "28\nX--\n++X\nX++\nX++\nX++\n--X\n--X\nX++\nX--\n++X\nX++\n--X\nX--\nX++\nX--\n++X\n++X\nX++\nX++\nX++\nX++\n--X\n++X\n--X\n--X\n--X\n--X\nX++", "output": "4" }, { "input": "94\nX++\nX++\n++X\n++X\nX--\n--X\nX++\n--X\nX++\n++X\nX++\n++X\n--X\n--X\n++X\nX++\n--X\nX--\nX--\n--X\nX--\nX--\n--X\n++X\n--X\nX--\nX--\nX++\n++X\n--X\nX--\n++X\n--X\n--X\nX--\nX--\nX++\nX++\nX--\nX++\nX--\nX--\nX--\n--X\nX--\nX--\nX--\nX++\n++X\nX--\n++X\nX++\n--X\n--X\n--X\n--X\n++X\nX--\n--X\n--X\n++X\nX--\nX--\nX++\n++X\nX++\n++X\n--X\n--X\nX--\n++X\nX--\nX--\n++X\n++X\n++X\n++X\nX++\n++X\n--X\nX++\n--X\n--X\n++X\n--X\nX++\n++X\nX++\n--X\nX--\nX--\n--X\n++X\nX++", "output": "-10" }, { "input": "56\n--X\nX--\n--X\n--X\nX--\nX--\n--X\nX++\n++X\n--X\nX++\nX--\n--X\n++X\n--X\nX--\nX--\n++X\nX--\nX--\n--X\n++X\n--X\n++X\n--X\nX++\n++X\nX++\n--X\n++X\nX++\nX++\n--X\nX++\nX--\n--X\nX--\n--X\nX++\n++X\n--X\n++X\nX++\nX--\n--X\n--X\n++X\nX--\nX--\n--X\nX--\n--X\nX++\n--X\n++X\n--X", "output": "-14" }, { "input": "59\nX--\n--X\nX++\n++X\nX--\n--X\n--X\n++X\n++X\n++X\n++X\nX++\n++X\n++X\nX++\n--X\nX--\nX++\n++X\n--X\nX++\n--X\n++X\nX++\n--X\n--X\nX++\nX++\n--X\nX++\nX++\nX++\nX--\nX--\n--X\nX++\nX--\nX--\n++X\nX--\nX++\n--X\nX++\nX--\nX--\nX--\nX--\n++X\n--X\nX++\nX++\nX--\nX++\n++X\nX--\nX++\nX--\nX--\n++X", "output": "3" }, { "input": "87\n--X\n++X\n--X\nX++\n--X\nX--\n--X\n++X\nX--\n++X\n--X\n--X\nX++\n--X\nX--\nX++\n++X\n--X\n++X\n++X\n--X\n++X\n--X\nX--\n++X\n++X\nX--\nX++\nX++\n--X\n--X\n++X\nX--\n--X\n++X\n--X\nX++\n--X\n--X\nX--\n++X\n++X\n--X\nX--\nX--\nX--\nX--\nX--\nX++\n--X\n++X\n--X\nX++\n++X\nX++\n++X\n--X\nX++\n++X\nX--\n--X\nX++\n++X\nX++\nX++\n--X\n--X\n++X\n--X\nX++\nX++\n++X\nX++\nX++\nX++\nX++\n--X\n--X\n--X\n--X\n--X\n--X\n--X\nX--\n--X\n++X\n++X", "output": "-5" }, { "input": "101\nX++\nX++\nX++\n++X\n--X\nX--\nX++\nX--\nX--\n--X\n--X\n++X\nX++\n++X\n++X\nX--\n--X\n++X\nX++\nX--\n++X\n--X\n--X\n--X\n++X\n--X\n++X\nX++\nX++\n++X\n--X\nX++\nX--\nX++\n++X\n++X\nX--\nX--\nX--\nX++\nX++\nX--\nX--\nX++\n++X\n++X\n++X\n--X\n--X\n++X\nX--\nX--\n--X\n++X\nX--\n++X\nX++\n++X\nX--\nX--\n--X\n++X\n--X\n++X\n++X\n--X\nX++\n++X\nX--\n++X\nX--\n++X\nX++\nX--\n++X\nX++\n--X\nX++\nX++\n++X\n--X\n++X\n--X\nX++\n--X\nX--\n--X\n++X\n++X\n++X\n--X\nX--\nX--\nX--\nX--\n--X\n--X\n--X\n++X\n--X\n--X", "output": "1" }, { "input": "63\n--X\nX--\n++X\n--X\n++X\nX++\n--X\n--X\nX++\n--X\n--X\nX++\nX--\nX--\n--X\n++X\nX--\nX--\nX++\n++X\nX++\nX++\n--X\n--X\n++X\nX--\nX--\nX--\n++X\nX++\nX--\n--X\nX--\n++X\n++X\nX++\n++X\nX++\nX++\n--X\nX--\n++X\nX--\n--X\nX--\nX--\nX--\n++X\n++X\n++X\n++X\nX++\nX++\n++X\n--X\n--X\n++X\n++X\n++X\nX--\n++X\n++X\nX--", "output": "1" }, { "input": "45\n--X\n++X\nX--\n++X\n++X\nX++\n--X\n--X\n--X\n--X\n--X\n--X\n--X\nX++\n++X\nX--\n++X\n++X\nX--\nX++\nX--\n--X\nX--\n++X\n++X\n--X\n--X\nX--\nX--\n--X\n++X\nX--\n--X\n++X\n++X\n--X\n--X\nX--\n++X\n++X\nX++\nX++\n++X\n++X\nX++", "output": "-3" }, { "input": "21\n++X\nX++\n--X\nX--\nX++\n++X\n--X\nX--\nX++\nX--\nX--\nX--\nX++\n++X\nX++\n++X\n--X\nX--\n--X\nX++\n++X", "output": "1" }, { "input": "100\n--X\n++X\nX++\n++X\nX--\n++X\nX--\nX++\n--X\nX++\nX--\nX--\nX--\n++X\nX--\nX++\nX++\n++X\nX++\nX++\nX++\nX++\n++X\nX++\n++X\nX--\n--X\n++X\nX--\n--X\n++X\n++X\nX--\nX++\nX++\nX++\n++X\n--X\n++X\nX++\nX--\n++X\n++X\n--X\n++X\nX--\nX--\nX--\nX++\nX--\nX--\nX++\nX++\n--X\nX++\nX++\n--X\nX--\n--X\n++X\n--X\n++X\n++X\nX--\n--X\n++X\n++X\n--X\n--X\n++X\nX++\nX--\nX++\nX--\nX++\nX++\n--X\nX--\nX--\n++X\nX--\n--X\n--X\nX++\n--X\n--X\nX--\nX--\n++X\n++X\nX--\n++X\nX++\n--X\n++X\n++X\nX++\n--X\n--X\nX++", "output": "8" }, { "input": "17\nX++\nX++\n++X\n--X\n--X\n++X\n++X\n--X\nX--\nX++\nX--\n--X\n--X\nX--\n++X\nX--\nX++", "output": "-1" }, { "input": "77\n++X\nX++\n--X\nX--\n--X\n--X\nX--\nX++\nX--\nX++\nX--\n++X\n--X\n--X\n--X\n--X\n++X\nX--\nX++\nX--\n--X\nX--\n--X\nX--\n++X\n--X\n++X\n++X\nX++\nX++\nX--\n--X\nX--\nX--\nX++\n--X\n--X\n++X\nX--\nX--\n++X\nX++\nX--\n++X\n--X\nX++\nX--\n++X\n++X\n++X\nX--\nX--\nX--\n--X\n++X\n++X\n++X\nX++\n--X\n--X\n++X\n--X\nX--\nX++\n++X\nX++\n++X\nX--\nX++\nX++\n--X\nX++\nX++\nX++\n--X\nX++\nX--", "output": "-5" }, { "input": "21\nX--\n++X\n--X\nX--\n++X\nX--\n++X\nX--\n--X\n++X\nX++\n++X\nX++\n++X\nX--\n--X\nX++\nX++\nX--\n++X\nX--", "output": "1" }, { "input": "1\nX--", "output": "-1" } ]
1,697,722,097
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
0
0
a=int(input()) ans=0 for i in range(a): b=input() if(b.equals("X++") or b.equals("++X") or b.equals("+X+")): ans=ans+1 else: ans=ans-1 print(ans)
Title: Bit++ Time Limit: None seconds Memory Limit: None megabytes Problem Description: The classic programming language of Bitland is Bit++. This language is so peculiar and complicated. The language is that peculiar as it has exactly one variable, called *x*. Also, there are two operations: - Operation ++ increases the value of variable *x* by 1. - Operation -- decreases the value of variable *x* by 1. A statement in language Bit++ is a sequence, consisting of exactly one operation and one variable *x*. The statement is written without spaces, that is, it can only contain characters "+", "-", "X". Executing a statement means applying the operation it contains. A programme in Bit++ is a sequence of statements, each of them needs to be executed. Executing a programme means executing all the statements it contains. You're given a programme in language Bit++. The initial value of *x* is 0. Execute the programme and find its final value (the value of the variable when this programme is executed). Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=150) — the number of statements in the programme. Next *n* lines contain a statement each. Each statement contains exactly one operation (++ or --) and exactly one variable *x* (denoted as letter «X»). Thus, there are no empty statements. The operation and the variable can be written in any order. Output Specification: Print a single integer — the final value of *x*. Demo Input: ['1\n++X\n', '2\nX++\n--X\n'] Demo Output: ['1\n', '0\n'] Note: none
```python a=int(input()) ans=0 for i in range(a): b=input() if(b.equals("X++") or b.equals("++X") or b.equals("+X+")): ans=ans+1 else: ans=ans-1 print(ans) ```
-1