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
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
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,530,636,168 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 186 | 0 | # -*- coding: utf-8 -*-
"""
Created on Tue Jul 3 21:46:07 2018
@author: Shravan
"""
n=int(input())
l=[int(x) for x in input().split()]
if l[0]%2==0 and l[1]%2==0:
for i in range(n):
if l[i]%2==1:
print(l[i])
elif l[0]%2==1 and l[1]%2==1 and l[2]%2==0:
for i in range(n):
if l[i]%2==0:
print(l[i])
elif l[0]%2==0 and l[1]%2==1 and l[2]%2==1:
print(l[0])
else:
print(l[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
# -*- coding: utf-8 -*-
"""
Created on Tue Jul 3 21:46:07 2018
@author: Shravan
"""
n=int(input())
l=[int(x) for x in input().split()]
if l[0]%2==0 and l[1]%2==0:
for i in range(n):
if l[i]%2==1:
print(l[i])
elif l[0]%2==1 and l[1]%2==1 and l[2]%2==0:
for i in range(n):
if l[i]%2==0:
print(l[i])
elif l[0]%2==0 and l[1]%2==1 and l[2]%2==1:
print(l[0])
else:
print(l[1])
``` | 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,671,651,863 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 34 | 62 | 0 | start = 0
end = int(input()) -1
nums = list(map(int,input().split()))
turn = False
score = [0,0]
cur = 0
while start <=end :
if nums[start] > nums[end] :
cur = nums[start]
start +=1
else :
cur = nums[end]
end -=1
score[turn] += cur
turn = not turn
print(*score) | Title: Sereja and Dima
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. 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
start = 0
end = int(input()) -1
nums = list(map(int,input().split()))
turn = False
score = [0,0]
cur = 0
while start <=end :
if nums[start] > nums[end] :
cur = nums[start]
start +=1
else :
cur = nums[end]
end -=1
score[turn] += cur
turn = not turn
print(*score)
``` | 3 |
|
131 | A | cAPS lOCK | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
- either it only contains uppercase letters; - or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged. | The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive. | Print the result of the given word's processing. | [
"cAPS\n",
"Lock\n"
] | [
"Caps",
"Lock\n"
] | none | 500 | [
{
"input": "cAPS",
"output": "Caps"
},
{
"input": "Lock",
"output": "Lock"
},
{
"input": "cAPSlOCK",
"output": "cAPSlOCK"
},
{
"input": "CAPs",
"output": "CAPs"
},
{
"input": "LoCK",
"output": "LoCK"
},
{
"input": "OOPS",
"output": "oops"
},
{
"input": "oops",
"output": "oops"
},
{
"input": "a",
"output": "A"
},
{
"input": "A",
"output": "a"
},
{
"input": "aA",
"output": "Aa"
},
{
"input": "Zz",
"output": "Zz"
},
{
"input": "Az",
"output": "Az"
},
{
"input": "zA",
"output": "Za"
},
{
"input": "AAA",
"output": "aaa"
},
{
"input": "AAa",
"output": "AAa"
},
{
"input": "AaR",
"output": "AaR"
},
{
"input": "Tdr",
"output": "Tdr"
},
{
"input": "aTF",
"output": "Atf"
},
{
"input": "fYd",
"output": "fYd"
},
{
"input": "dsA",
"output": "dsA"
},
{
"input": "fru",
"output": "fru"
},
{
"input": "hYBKF",
"output": "Hybkf"
},
{
"input": "XweAR",
"output": "XweAR"
},
{
"input": "mogqx",
"output": "mogqx"
},
{
"input": "eOhEi",
"output": "eOhEi"
},
{
"input": "nkdku",
"output": "nkdku"
},
{
"input": "zcnko",
"output": "zcnko"
},
{
"input": "lcccd",
"output": "lcccd"
},
{
"input": "vwmvg",
"output": "vwmvg"
},
{
"input": "lvchf",
"output": "lvchf"
},
{
"input": "IUNVZCCHEWENCHQQXQYPUJCRDZLUXCLJHXPHBXEUUGNXOOOPBMOBRIBHHMIRILYJGYYGFMTMFSVURGYHUWDRLQVIBRLPEVAMJQYO",
"output": "iunvzcchewenchqqxqypujcrdzluxcljhxphbxeuugnxooopbmobribhhmirilyjgyygfmtmfsvurgyhuwdrlqvibrlpevamjqyo"
},
{
"input": "OBHSZCAMDXEJWOZLKXQKIVXUUQJKJLMMFNBPXAEFXGVNSKQLJGXHUXHGCOTESIVKSFMVVXFVMTEKACRIWALAGGMCGFEXQKNYMRTG",
"output": "obhszcamdxejwozlkxqkivxuuqjkjlmmfnbpxaefxgvnskqljgxhuxhgcotesivksfmvvxfvmtekacriwalaggmcgfexqknymrtg"
},
{
"input": "IKJYZIKROIYUUCTHSVSKZTETNNOCMAUBLFJCEVANCADASMZRCNLBZPQRXESHEEMOMEPCHROSRTNBIDXYMEPJSIXSZQEBTEKKUHFS",
"output": "ikjyzikroiyuucthsvskztetnnocmaublfjcevancadasmzrcnlbzpqrxesheemomepchrosrtnbidxymepjsixszqebtekkuhfs"
},
{
"input": "cTKDZNWVYRTFPQLDAUUNSPKTDJTUPPFPRXRSINTVFVNNQNKXWUZUDHZBUSOKTABUEDQKUIVRTTVUREEOBJTSDKJKVEGFXVHXEYPE",
"output": "Ctkdznwvyrtfpqldauunspktdjtuppfprxrsintvfvnnqnkxwuzudhzbusoktabuedqkuivrttvureeobjtsdkjkvegfxvhxeype"
},
{
"input": "uCKJZRGZJCPPLEEYJTUNKOQSWGBMTBQEVPYFPIPEKRVYQNTDPANOIXKMPINNFUSZWCURGBDPYTEKBEKCPMVZPMWAOSHJYMGKOMBQ",
"output": "Uckjzrgzjcppleeyjtunkoqswgbmtbqevpyfpipekrvyqntdpanoixkmpinnfuszwcurgbdpytekbekcpmvzpmwaoshjymgkombq"
},
{
"input": "KETAXTSWAAOBKUOKUQREHIOMVMMRSAEWKGXZKRASwTVNSSFSNIWYNPSTMRADOADEEBURRHPOOBIEUIBGYDJCEKPNLEUCANZYJKMR",
"output": "KETAXTSWAAOBKUOKUQREHIOMVMMRSAEWKGXZKRASwTVNSSFSNIWYNPSTMRADOADEEBURRHPOOBIEUIBGYDJCEKPNLEUCANZYJKMR"
},
{
"input": "ZEKGDMWJPVUWFlNXRLUmWKLMMYSLRQQIBRWDPKWITUIMZYYKOEYGREKHHZRZZUFPVTNIHKGTCCTLOKSZITXXZDMPITHNZUIGDZLE",
"output": "ZEKGDMWJPVUWFlNXRLUmWKLMMYSLRQQIBRWDPKWITUIMZYYKOEYGREKHHZRZZUFPVTNIHKGTCCTLOKSZITXXZDMPITHNZUIGDZLE"
},
{
"input": "TcMbVPCFvnNkCEUUCIFLgBJeCOKuJhIGwXFrhAZjuAhBraMSchBfWwIuHAEbgJOFzGtxDLDXzDSaPCFujGGxgxdlHUIQYRrMFCgJ",
"output": "TcMbVPCFvnNkCEUUCIFLgBJeCOKuJhIGwXFrhAZjuAhBraMSchBfWwIuHAEbgJOFzGtxDLDXzDSaPCFujGGxgxdlHUIQYRrMFCgJ"
},
{
"input": "xFGqoLILNvxARKuIntPfeukFtMbvzDezKpPRAKkIoIvwqNXnehRVwkkXYvuRCeoieBaBfTjwsYhDeCLvBwktntyluoxCYVioXGdm",
"output": "xFGqoLILNvxARKuIntPfeukFtMbvzDezKpPRAKkIoIvwqNXnehRVwkkXYvuRCeoieBaBfTjwsYhDeCLvBwktntyluoxCYVioXGdm"
},
{
"input": "udvqolbxdwbkijwvhlyaelhynmnfgszbhgshlcwdkaibceqomzujndixuzivlsjyjqxzxodzbukxxhwwultvekdfntwpzlhhrIjm",
"output": "udvqolbxdwbkijwvhlyaelhynmnfgszbhgshlcwdkaibceqomzujndixuzivlsjyjqxzxodzbukxxhwwultvekdfntwpzlhhrIjm"
},
{
"input": "jgpwhetqqoncighgzbbaLwwwxkxivuwtokehrgprfgewzcwxkavwoflcgsgbhoeamzbefzoonwsyzisetoydrpufktzgbaycgaeg",
"output": "jgpwhetqqoncighgzbbaLwwwxkxivuwtokehrgprfgewzcwxkavwoflcgsgbhoeamzbefzoonwsyzisetoydrpufktzgbaycgaeg"
},
{
"input": "vyujsazdstbnkxeunedfbolicojzjpufgfemhtmdrswvmuhoivjvonacefqenbqudelmdegxqtbwezsbydmanzutvdgkgrjxzlnc",
"output": "vyujsazdstbnkxeunedfbolicojzjpufgfemhtmdrswvmuhoivjvonacefqenbqudelmdegxqtbwezsbydmanzutvdgkgrjxzlnc"
},
{
"input": "pivqnuqkaofcduvbttztjbuavrqwiqrwkfncmvatoxruelyoecnkpqraiahumiaiqeyjapbqyrsxcdgjbihivtqezvasfmzntdfv",
"output": "pivqnuqkaofcduvbttztjbuavrqwiqrwkfncmvatoxruelyoecnkpqraiahumiaiqeyjapbqyrsxcdgjbihivtqezvasfmzntdfv"
},
{
"input": "upvtbsxswbohxshdrbjxcungzquhuomgxwlryvshshsfvqbrxvcikbglietlpqkiwbhiqpmdwuqosbtdvyxekkaqiwrbsibpoect",
"output": "upvtbsxswbohxshdrbjxcungzquhuomgxwlryvshshsfvqbrxvcikbglietlpqkiwbhiqpmdwuqosbtdvyxekkaqiwrbsibpoect"
},
{
"input": "cTKDZNWVYRTFPQLDAUUNSPKTDJTUPPFPRXRSINTVFVNNQNKXWUZUDHZBUSOKTABUEDQKUIVRTTVUREEOBJTSDKJKVEGFXVHXEYPE",
"output": "Ctkdznwvyrtfpqldauunspktdjtuppfprxrsintvfvnnqnkxwuzudhzbusoktabuedqkuivrttvureeobjtsdkjkvegfxvhxeype"
},
{
"input": "JEGDOFJOFGJHFROGHOFGMHOFGHORGFHMOu",
"output": "JEGDOFJOFGJHFROGHOFGMHOFGHORGFHMOu"
},
{
"input": "aBACABa",
"output": "aBACABa"
},
{
"input": "AAAAAAAAAAAAAAAAAAAAAAAAaa",
"output": "AAAAAAAAAAAAAAAAAAAAAAAAaa"
},
{
"input": "aaAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"output": "aaAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
},
{
"input": "dDDDDDDDDDDDDD",
"output": "Dddddddddddddd"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "z",
"output": "Z"
},
{
"input": "AZ",
"output": "az"
},
{
"input": "Z",
"output": "z"
},
{
"input": "aAAAA",
"output": "Aaaaa"
},
{
"input": "F",
"output": "f"
}
] | 1,690,628,510 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 31 | 0 | s = input()
up = 0
low = 0
for i in s:
if i == i.upper():
up +=1
else:
low+=1
if up == 1 :
print(s)
elif up==len(s)-1:
print(s.capitalize())
else:
print(s.lower())
| Title: cAPS lOCK
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
- either it only contains uppercase letters; - or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input Specification:
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output Specification:
Print the result of the given word's processing.
Demo Input:
['cAPS\n', 'Lock\n']
Demo Output:
['Caps', 'Lock\n']
Note:
none | ```python
s = input()
up = 0
low = 0
for i in s:
if i == i.upper():
up +=1
else:
low+=1
if up == 1 :
print(s)
elif up==len(s)-1:
print(s.capitalize())
else:
print(s.lower())
``` | 0 |
|
493 | B | Vasya and Wrestling | PROGRAMMING | 1,400 | [
"implementation"
] | null | null | Vasya has become interested in wrestling. In wrestling wrestlers use techniques for which they are awarded points by judges. The wrestler who gets the most points wins.
When the numbers of points of both wrestlers are equal, the wrestler whose sequence of points is lexicographically greater, wins.
If the sequences of the awarded points coincide, the wrestler who performed the last technique wins. Your task is to determine which wrestler won. | The first line contains number *n* — the number of techniques that the wrestlers have used (1<=≤<=*n*<=≤<=2·105).
The following *n* lines contain integer numbers *a**i* (|*a**i*|<=≤<=109, *a**i*<=≠<=0). If *a**i* is positive, that means that the first wrestler performed the technique that was awarded with *a**i* points. And if *a**i* is negative, that means that the second wrestler performed the technique that was awarded with (<=-<=*a**i*) points.
The techniques are given in chronological order. | If the first wrestler wins, print string "first", otherwise print "second" | [
"5\n1\n2\n-3\n-4\n3\n",
"3\n-1\n-2\n3\n",
"2\n4\n-4\n"
] | [
"second\n",
"first\n",
"second\n"
] | Sequence *x* = *x*<sub class="lower-index">1</sub>*x*<sub class="lower-index">2</sub>... *x*<sub class="lower-index">|*x*|</sub> is lexicographically larger than sequence *y* = *y*<sub class="lower-index">1</sub>*y*<sub class="lower-index">2</sub>... *y*<sub class="lower-index">|*y*|</sub>, if either |*x*| > |*y*| and *x*<sub class="lower-index">1</sub> = *y*<sub class="lower-index">1</sub>, *x*<sub class="lower-index">2</sub> = *y*<sub class="lower-index">2</sub>, ... , *x*<sub class="lower-index">|*y*|</sub> = *y*<sub class="lower-index">|*y*|</sub>, or there is such number *r* (*r* < |*x*|, *r* < |*y*|), that *x*<sub class="lower-index">1</sub> = *y*<sub class="lower-index">1</sub>, *x*<sub class="lower-index">2</sub> = *y*<sub class="lower-index">2</sub>, ... , *x*<sub class="lower-index">*r*</sub> = *y*<sub class="lower-index">*r*</sub> and *x*<sub class="lower-index">*r* + 1</sub> > *y*<sub class="lower-index">*r* + 1</sub>.
We use notation |*a*| to denote length of sequence *a*. | 1,000 | [
{
"input": "5\n1\n2\n-3\n-4\n3",
"output": "second"
},
{
"input": "3\n-1\n-2\n3",
"output": "first"
},
{
"input": "2\n4\n-4",
"output": "second"
},
{
"input": "7\n1\n2\n-3\n4\n5\n-6\n7",
"output": "first"
},
{
"input": "14\n1\n2\n3\n4\n5\n6\n7\n-8\n-9\n-10\n-11\n-12\n-13\n-14",
"output": "second"
},
{
"input": "4\n16\n12\n19\n-98",
"output": "second"
},
{
"input": "5\n-6\n-1\n-1\n5\n3",
"output": "second"
},
{
"input": "11\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1",
"output": "first"
},
{
"input": "1\n-534365",
"output": "second"
},
{
"input": "1\n10253033",
"output": "first"
},
{
"input": "3\n-1\n-2\n3",
"output": "first"
},
{
"input": "8\n1\n-2\n-3\n4\n5\n-6\n-7\n8",
"output": "second"
},
{
"input": "2\n1\n-1",
"output": "second"
},
{
"input": "5\n1\n2\n3\n4\n5",
"output": "first"
},
{
"input": "5\n-1\n-2\n-3\n-4\n-5",
"output": "second"
},
{
"input": "10\n-1\n-2\n-3\n-4\n-5\n5\n4\n3\n2\n1",
"output": "first"
},
{
"input": "131\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n-1\n-1\n2",
"output": "first"
},
{
"input": "6\n-1\n-2\n-3\n1\n2\n3",
"output": "first"
},
{
"input": "3\n1000000000\n1000000000\n1000000000",
"output": "first"
},
{
"input": "12\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000",
"output": "first"
},
{
"input": "4\n1000000000\n1000000000\n1000000000\n-1000000000",
"output": "first"
},
{
"input": "20\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000",
"output": "first"
},
{
"input": "5\n1000000000\n1000000000\n-1000000000\n-1000000000\n-1000000000",
"output": "second"
},
{
"input": "4\n1\n-1000000000\n-1000000000\n-1000000000",
"output": "second"
},
{
"input": "5\n1000000000\n1000000000\n1000000000\n-1000000000\n-1000000000",
"output": "first"
},
{
"input": "4\n-1\n1000000000\n1000000000\n1000000000",
"output": "first"
},
{
"input": "11\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000",
"output": "first"
},
{
"input": "2\n-4\n4",
"output": "first"
},
{
"input": "3\n-12\n3\n9",
"output": "second"
},
{
"input": "3\n9\n1\n-10",
"output": "second"
},
{
"input": "3\n1\n2\n-3",
"output": "second"
},
{
"input": "4\n55\n5\n-5\n-55",
"output": "first"
},
{
"input": "4\n5\n-1\n1\n-5",
"output": "first"
},
{
"input": "2\n-5\n6",
"output": "first"
},
{
"input": "4\n5\n-4\n3\n-40",
"output": "second"
},
{
"input": "4\n1000000000\n1000000000\n1000000000\n-5",
"output": "first"
},
{
"input": "6\n3\n2\n1\n-3\n-1\n-2",
"output": "first"
},
{
"input": "5\n4\n1\n1\n-3\n-3",
"output": "first"
},
{
"input": "5\n208\n-52\n-52\n-52\n-52",
"output": "first"
},
{
"input": "3\n-100\n-200\n300",
"output": "first"
},
{
"input": "3\n400\n-200\n-200",
"output": "first"
},
{
"input": "3\n208\n-207\n-1",
"output": "first"
},
{
"input": "3\n98888887\n98888888\n-197777775",
"output": "second"
}
] | 1,640,259,385 | 2,147,483,647 | Python 3 | OK | TESTS | 57 | 312 | 6,144,000 | t=int(input())
first=[]
second=[]
flag1=True
for i in range(t):
x=int(input())
if x>0:
first.append(x)
else:
second.append(-x)
if i==t-1 and x>0:
flag1=False
s1=sum(first)
s2=sum(second)
if s1>s2:
print("first")
elif s2>s1:
print("second")
else:
x=""
for i in range(len(first)):
if first[i]>second[i]:
x=x+"f"
break
if first[i]<second[i]:
x=x+"s"
break
if x=="f":
print("first")
elif x=="s":
print("second")
else:
if flag1==True:
print("second")
else:
print("first")
| Title: Vasya and Wrestling
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has become interested in wrestling. In wrestling wrestlers use techniques for which they are awarded points by judges. The wrestler who gets the most points wins.
When the numbers of points of both wrestlers are equal, the wrestler whose sequence of points is lexicographically greater, wins.
If the sequences of the awarded points coincide, the wrestler who performed the last technique wins. Your task is to determine which wrestler won.
Input Specification:
The first line contains number *n* — the number of techniques that the wrestlers have used (1<=≤<=*n*<=≤<=2·105).
The following *n* lines contain integer numbers *a**i* (|*a**i*|<=≤<=109, *a**i*<=≠<=0). If *a**i* is positive, that means that the first wrestler performed the technique that was awarded with *a**i* points. And if *a**i* is negative, that means that the second wrestler performed the technique that was awarded with (<=-<=*a**i*) points.
The techniques are given in chronological order.
Output Specification:
If the first wrestler wins, print string "first", otherwise print "second"
Demo Input:
['5\n1\n2\n-3\n-4\n3\n', '3\n-1\n-2\n3\n', '2\n4\n-4\n']
Demo Output:
['second\n', 'first\n', 'second\n']
Note:
Sequence *x* = *x*<sub class="lower-index">1</sub>*x*<sub class="lower-index">2</sub>... *x*<sub class="lower-index">|*x*|</sub> is lexicographically larger than sequence *y* = *y*<sub class="lower-index">1</sub>*y*<sub class="lower-index">2</sub>... *y*<sub class="lower-index">|*y*|</sub>, if either |*x*| > |*y*| and *x*<sub class="lower-index">1</sub> = *y*<sub class="lower-index">1</sub>, *x*<sub class="lower-index">2</sub> = *y*<sub class="lower-index">2</sub>, ... , *x*<sub class="lower-index">|*y*|</sub> = *y*<sub class="lower-index">|*y*|</sub>, or there is such number *r* (*r* < |*x*|, *r* < |*y*|), that *x*<sub class="lower-index">1</sub> = *y*<sub class="lower-index">1</sub>, *x*<sub class="lower-index">2</sub> = *y*<sub class="lower-index">2</sub>, ... , *x*<sub class="lower-index">*r*</sub> = *y*<sub class="lower-index">*r*</sub> and *x*<sub class="lower-index">*r* + 1</sub> > *y*<sub class="lower-index">*r* + 1</sub>.
We use notation |*a*| to denote length of sequence *a*. | ```python
t=int(input())
first=[]
second=[]
flag1=True
for i in range(t):
x=int(input())
if x>0:
first.append(x)
else:
second.append(-x)
if i==t-1 and x>0:
flag1=False
s1=sum(first)
s2=sum(second)
if s1>s2:
print("first")
elif s2>s1:
print("second")
else:
x=""
for i in range(len(first)):
if first[i]>second[i]:
x=x+"f"
break
if first[i]<second[i]:
x=x+"s"
break
if x=="f":
print("first")
elif x=="s":
print("second")
else:
if flag1==True:
print("second")
else:
print("first")
``` | 3 |
|
669 | A | Little Artem and Presents | PROGRAMMING | 800 | [
"math"
] | null | null | Little Artem got *n* stones on his birthday and now wants to give some of them to Masha. He knows that Masha cares more about the fact of receiving the present, rather than the value of that present, so he wants to give her stones as many times as possible. However, Masha remembers the last present she received, so Artem can't give her the same number of stones twice in a row. For example, he can give her 3 stones, then 1 stone, then again 3 stones, but he can't give her 3 stones and then again 3 stones right after that.
How many times can Artem give presents to Masha? | The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=109) — number of stones Artem received on his birthday. | Print the maximum possible number of times Artem can give presents to Masha. | [
"1\n",
"2\n",
"3\n",
"4\n"
] | [
"1\n",
"1\n",
"2\n",
"3\n"
] | In the first sample, Artem can only give 1 stone to Masha.
In the second sample, Atrem can give Masha 1 or 2 stones, though he can't give her 1 stone two times.
In the third sample, Atrem can first give Masha 2 stones, a then 1 more stone.
In the fourth sample, Atrem can first give Masha 1 stone, then 2 stones, and finally 1 stone again. | 500 | [
{
"input": "1",
"output": "1"
},
{
"input": "2",
"output": "1"
},
{
"input": "3",
"output": "2"
},
{
"input": "4",
"output": "3"
},
{
"input": "100",
"output": "67"
},
{
"input": "101",
"output": "67"
},
{
"input": "102",
"output": "68"
},
{
"input": "1000000000",
"output": "666666667"
},
{
"input": "5",
"output": "3"
},
{
"input": "6",
"output": "4"
},
{
"input": "999999999",
"output": "666666666"
},
{
"input": "999999998",
"output": "666666665"
},
{
"input": "999999997",
"output": "666666665"
},
{
"input": "999999996",
"output": "666666664"
},
{
"input": "999999995",
"output": "666666663"
},
{
"input": "999999994",
"output": "666666663"
},
{
"input": "999999993",
"output": "666666662"
},
{
"input": "999999992",
"output": "666666661"
},
{
"input": "999999991",
"output": "666666661"
},
{
"input": "1000",
"output": "667"
},
{
"input": "10000",
"output": "6667"
},
{
"input": "100000",
"output": "66667"
},
{
"input": "1000000",
"output": "666667"
},
{
"input": "10000000",
"output": "6666667"
},
{
"input": "100000000",
"output": "66666667"
},
{
"input": "7",
"output": "5"
}
] | 1,564,593,781 | 2,147,483,647 | Python 3 | OK | TESTS | 26 | 124 | 0 | # import sys
# sys.stdin=open("input.in","r")
n=int(input())
print(2*(n//3)+(n%3+2)//3) | Title: Little Artem and Presents
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Artem got *n* stones on his birthday and now wants to give some of them to Masha. He knows that Masha cares more about the fact of receiving the present, rather than the value of that present, so he wants to give her stones as many times as possible. However, Masha remembers the last present she received, so Artem can't give her the same number of stones twice in a row. For example, he can give her 3 stones, then 1 stone, then again 3 stones, but he can't give her 3 stones and then again 3 stones right after that.
How many times can Artem give presents to Masha?
Input Specification:
The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=109) — number of stones Artem received on his birthday.
Output Specification:
Print the maximum possible number of times Artem can give presents to Masha.
Demo Input:
['1\n', '2\n', '3\n', '4\n']
Demo Output:
['1\n', '1\n', '2\n', '3\n']
Note:
In the first sample, Artem can only give 1 stone to Masha.
In the second sample, Atrem can give Masha 1 or 2 stones, though he can't give her 1 stone two times.
In the third sample, Atrem can first give Masha 2 stones, a then 1 more stone.
In the fourth sample, Atrem can first give Masha 1 stone, then 2 stones, and finally 1 stone again. | ```python
# import sys
# sys.stdin=open("input.in","r")
n=int(input())
print(2*(n//3)+(n%3+2)//3)
``` | 3 |
|
231 | A | Team | PROGRAMMING | 800 | [
"brute force",
"greedy"
] | null | null | One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. 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,699,221,886 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 21 | 154 | 1,638,400 | n = int(input())
ans = 0
for i in range(n):
a = input()
if int(a[0]) + int(a[2]) + int(a[4]) > 1:
ans += 1
print(ans)
| Title: Team
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends 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
n = int(input())
ans = 0
for i in range(n):
a = input()
if int(a[0]) + int(a[2]) + int(a[4]) > 1:
ans += 1
print(ans)
``` | 3 |
|
445 | A | DZY Loves Chessboard | PROGRAMMING | 1,200 | [
"dfs and similar",
"implementation"
] | null | null | DZY loves chessboard, and he enjoys playing with it.
He has a chessboard of *n* rows and *m* columns. Some cells of the chessboard are bad, others are good. For every good cell, DZY wants to put a chessman on it. Each chessman is either white or black. After putting all chessmen, DZY wants that no two chessmen with the same color are on two adjacent cells. Two cells are adjacent if and only if they share a common edge.
You task is to find any suitable placement of chessmen on the given chessboard. | The first line contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100).
Each of the next *n* lines contains a string of *m* characters: the *j*-th character of the *i*-th string is either "." or "-". A "." means that the corresponding cell (in the *i*-th row and the *j*-th column) is good, while a "-" means it is bad. | Output must contain *n* lines, each line must contain a string of *m* characters. The *j*-th character of the *i*-th string should be either "W", "B" or "-". Character "W" means the chessman on the cell is white, "B" means it is black, "-" means the cell is a bad cell.
If multiple answers exist, print any of them. It is guaranteed that at least one answer exists. | [
"1 1\n.\n",
"2 2\n..\n..\n",
"3 3\n.-.\n---\n--."
] | [
"B\n",
"BW\nWB\n",
"B-B\n---\n--B"
] | In the first sample, DZY puts a single black chessman. Of course putting a white one is also OK.
In the second sample, all 4 cells are good. No two same chessmen share an edge in the sample output.
In the third sample, no good cells are adjacent. So you can just put 3 chessmen, no matter what their colors are. | 500 | [
{
"input": "1 1\n.",
"output": "B"
},
{
"input": "2 2\n..\n..",
"output": "BW\nWB"
},
{
"input": "3 3\n.-.\n---\n--.",
"output": "B-B\n---\n--B"
},
{
"input": "3 1\n-\n.\n.",
"output": "-\nW\nB"
},
{
"input": "11 11\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------",
"output": "-----------\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------"
},
{
"input": "1 1\n-",
"output": "-"
},
{
"input": "4 2\n..\n..\n..\n..",
"output": "BW\nWB\nBW\nWB"
},
{
"input": "5 1\n.\n.\n.\n.\n.",
"output": "B\nW\nB\nW\nB"
}
] | 1,610,617,216 | 2,147,483,647 | PyPy 3 | OK | TESTS | 37 | 140 | 4,710,400 | n, m = map(int, input().split())
s = ['B', 'W']
for i in range(n):
for k, j in enumerate(input()):
if j == ".":
if i % 2 == 0:
print(s[k % 2], end="")
else:
print(s[(k+1) % 2], end="")
else:
print("-", end="")
print("")
| Title: DZY Loves Chessboard
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
DZY loves chessboard, and he enjoys playing with it.
He has a chessboard of *n* rows and *m* columns. Some cells of the chessboard are bad, others are good. For every good cell, DZY wants to put a chessman on it. Each chessman is either white or black. After putting all chessmen, DZY wants that no two chessmen with the same color are on two adjacent cells. Two cells are adjacent if and only if they share a common edge.
You task is to find any suitable placement of chessmen on the given chessboard.
Input Specification:
The first line contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100).
Each of the next *n* lines contains a string of *m* characters: the *j*-th character of the *i*-th string is either "." or "-". A "." means that the corresponding cell (in the *i*-th row and the *j*-th column) is good, while a "-" means it is bad.
Output Specification:
Output must contain *n* lines, each line must contain a string of *m* characters. The *j*-th character of the *i*-th string should be either "W", "B" or "-". Character "W" means the chessman on the cell is white, "B" means it is black, "-" means the cell is a bad cell.
If multiple answers exist, print any of them. It is guaranteed that at least one answer exists.
Demo Input:
['1 1\n.\n', '2 2\n..\n..\n', '3 3\n.-.\n---\n--.']
Demo Output:
['B\n', 'BW\nWB\n', 'B-B\n---\n--B']
Note:
In the first sample, DZY puts a single black chessman. Of course putting a white one is also OK.
In the second sample, all 4 cells are good. No two same chessmen share an edge in the sample output.
In the third sample, no good cells are adjacent. So you can just put 3 chessmen, no matter what their colors are. | ```python
n, m = map(int, input().split())
s = ['B', 'W']
for i in range(n):
for k, j in enumerate(input()):
if j == ".":
if i % 2 == 0:
print(s[k % 2], end="")
else:
print(s[(k+1) % 2], end="")
else:
print("-", end="")
print("")
``` | 3 |
|
940 | A | Points on the line | PROGRAMMING | 1,200 | [
"brute force",
"greedy",
"sortings"
] | null | null | We've got no test cases. A big olympiad is coming up. But the problemsetters' number one priority should be adding another problem to the round.
The diameter of a multiset of points on the line is the largest distance between two points from this set. For example, the diameter of the multiset {1,<=3,<=2,<=1} is 2.
Diameter of multiset consisting of one point is 0.
You are given *n* points on the line. What is the minimum number of points you have to remove, so that the diameter of the multiset of the remaining points will not exceed *d*? | The first line contains two integers *n* and *d* (1<=≤<=*n*<=≤<=100,<=0<=≤<=*d*<=≤<=100) — the amount of points and the maximum allowed diameter respectively.
The second line contains *n* space separated integers (1<=≤<=*x**i*<=≤<=100) — the coordinates of the points. | Output a single integer — the minimum number of points you have to remove. | [
"3 1\n2 1 4\n",
"3 0\n7 7 7\n",
"6 3\n1 3 4 6 9 10\n"
] | [
"1\n",
"0\n",
"3\n"
] | In the first test case the optimal strategy is to remove the point with coordinate 4. The remaining points will have coordinates 1 and 2, so the diameter will be equal to 2 - 1 = 1.
In the second test case the diameter is equal to 0, so its is unnecessary to remove any points.
In the third test case the optimal strategy is to remove points with coordinates 1, 9 and 10. The remaining points will have coordinates 3, 4 and 6, so the diameter will be equal to 6 - 3 = 3. | 500 | [
{
"input": "3 1\n2 1 4",
"output": "1"
},
{
"input": "3 0\n7 7 7",
"output": "0"
},
{
"input": "6 3\n1 3 4 6 9 10",
"output": "3"
},
{
"input": "11 5\n10 11 12 13 14 15 16 17 18 19 20",
"output": "5"
},
{
"input": "1 100\n1",
"output": "0"
},
{
"input": "100 10\n22 75 26 45 72 81 47 29 97 2 75 25 82 84 17 56 32 2 28 37 57 39 18 11 79 6 40 68 68 16 40 63 93 49 91 10 55 68 31 80 57 18 34 28 76 55 21 80 22 45 11 67 67 74 91 4 35 34 65 80 21 95 1 52 25 31 2 53 96 22 89 99 7 66 32 2 68 33 75 92 84 10 94 28 54 12 9 80 43 21 51 92 20 97 7 25 67 17 38 100",
"output": "84"
},
{
"input": "100 70\n22 75 26 45 72 81 47 29 97 2 75 25 82 84 17 56 32 2 28 37 57 39 18 11 79 6 40 68 68 16 40 63 93 49 91 10 55 68 31 80 57 18 34 28 76 55 21 80 22 45 11 67 67 74 91 4 35 34 65 80 21 95 1 52 25 31 2 53 96 22 89 99 7 66 32 2 68 33 75 92 84 10 94 28 54 12 9 80 43 21 51 92 20 97 7 25 67 17 38 100",
"output": "27"
},
{
"input": "1 10\n25",
"output": "0"
},
{
"input": "70 80\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",
"output": "0"
},
{
"input": "3 1\n25 26 27",
"output": "1"
},
{
"input": "100 5\n51 56 52 60 52 53 52 60 56 54 55 50 53 51 57 53 52 54 54 52 51 55 50 56 60 51 58 50 60 59 50 54 60 55 55 57 54 59 59 55 55 52 56 57 59 54 53 57 52 50 50 55 59 54 54 56 51 58 52 51 56 56 58 56 54 54 57 52 51 58 56 57 54 59 58 53 50 52 50 60 57 51 54 59 54 54 52 55 53 55 51 53 52 54 51 56 55 53 58 56",
"output": "34"
},
{
"input": "100 11\n44 89 57 64 94 96 73 96 55 52 91 73 73 93 51 62 63 85 43 75 60 78 98 55 80 84 65 75 61 88 62 71 53 57 94 85 60 96 66 96 61 72 97 64 51 44 63 82 67 86 60 57 74 85 57 79 61 94 86 78 84 56 60 75 91 91 92 62 89 85 79 57 76 97 65 56 46 78 51 69 50 52 85 80 76 71 81 51 90 71 77 60 63 62 84 59 79 84 69 81",
"output": "70"
},
{
"input": "100 0\n22 75 26 45 72 81 47 29 97 2 75 25 82 84 17 56 32 2 28 37 57 39 18 11 79 6 40 68 68 16 40 63 93 49 91 10 55 68 31 80 57 18 34 28 76 55 21 80 22 45 11 67 67 74 91 4 35 34 65 80 21 95 1 52 25 31 2 53 96 22 89 99 7 66 32 2 68 33 75 92 84 10 94 28 54 12 9 80 43 21 51 92 20 97 7 25 67 17 38 100",
"output": "96"
},
{
"input": "100 100\n22 75 26 45 72 81 47 29 97 2 75 25 82 84 17 56 32 2 28 37 57 39 18 11 79 6 40 68 68 16 40 63 93 49 91 10 55 68 31 80 57 18 34 28 76 55 21 80 22 45 11 67 67 74 91 4 35 34 65 80 21 95 1 52 25 31 2 53 96 22 89 99 7 66 32 2 68 33 75 92 84 10 94 28 54 12 9 80 43 21 51 92 20 97 7 25 67 17 38 100",
"output": "0"
},
{
"input": "76 32\n50 53 69 58 55 39 40 42 40 55 58 73 55 72 75 44 45 55 46 60 60 42 41 64 77 39 68 51 61 49 38 41 56 57 64 43 78 36 39 63 40 66 52 76 39 68 39 73 40 68 54 60 35 67 69 52 58 52 38 63 69 38 69 60 73 64 65 41 59 55 37 57 40 34 35 35",
"output": "13"
},
{
"input": "100 1\n22 75 26 45 72 81 47 29 97 2 75 25 82 84 17 56 32 2 28 37 57 39 18 11 79 6 40 68 68 16 40 63 93 49 91 10 55 68 31 80 57 18 34 28 76 55 21 80 22 45 11 67 67 74 91 4 35 34 65 80 21 95 1 52 25 31 2 53 96 22 89 99 7 66 32 2 68 33 75 92 84 10 94 28 54 12 9 80 43 21 51 92 20 97 7 25 67 17 38 100",
"output": "93"
},
{
"input": "100 5\n22 75 26 45 72 81 47 29 97 2 75 25 82 84 17 56 32 2 28 37 57 39 18 11 79 6 40 68 68 16 40 63 93 49 91 10 55 68 31 80 57 18 34 28 76 55 21 80 22 45 11 67 67 74 91 4 35 34 65 80 21 95 1 52 25 31 2 53 96 22 89 99 7 66 32 2 68 33 75 92 84 10 94 28 54 12 9 80 43 21 51 92 20 97 7 25 67 17 38 100",
"output": "89"
},
{
"input": "98 64\n2 29 36 55 58 15 25 33 7 16 61 1 4 24 63 26 36 16 16 3 57 39 56 7 11 24 20 12 22 10 56 5 11 39 61 52 27 54 21 6 61 36 40 52 54 5 15 52 58 23 45 39 65 16 27 40 13 64 47 24 51 29 9 18 49 49 8 47 2 64 7 63 49 10 20 26 34 3 45 66 8 46 16 32 16 38 3 6 15 17 35 48 36 5 57 29 61 15",
"output": "1"
},
{
"input": "100 56\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": "43"
},
{
"input": "100 0\n14 13 14 13 14 13 13 13 13 14 13 13 14 14 13 14 14 14 14 13 13 13 14 13 13 14 14 14 14 14 14 13 13 13 13 14 13 14 13 14 13 14 14 14 14 13 13 14 14 13 13 13 13 14 13 14 13 14 13 14 13 13 13 14 13 13 14 13 14 14 13 13 13 14 14 14 14 13 13 14 14 14 14 14 14 14 13 14 13 13 13 14 14 13 13 13 13 13 14 14",
"output": "50"
},
{
"input": "100 0\n14 17 18 22 19 18 19 21 19 19 22 22 19 21 24 23 24 19 25 24 24 21 20 13 26 18 17 15 25 13 17 20 20 21 13 22 27 15 18 27 19 15 16 25 18 17 18 22 19 17 18 24 14 16 18 16 22 16 17 27 18 17 18 24 22 13 14 20 23 19 16 21 19 13 14 14 25 15 27 24 26 22 16 20 16 14 21 27 15 23 23 24 27 14 24 17 19 24 15 27",
"output": "89"
},
{
"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": "1 100\n22",
"output": "0"
},
{
"input": "1 0\n22",
"output": "0"
},
{
"input": "1 99\n99",
"output": "0"
},
{
"input": "1 5\n6",
"output": "0"
},
{
"input": "3 1\n10 20 30",
"output": "2"
},
{
"input": "3 0\n1 2 3",
"output": "2"
},
{
"input": "3 2\n1 50 99",
"output": "2"
},
{
"input": "7 4\n1 3 4 9 10 11 12",
"output": "3"
},
{
"input": "2 5\n67 23",
"output": "1"
},
{
"input": "4 2\n1 4 7 9",
"output": "2"
},
{
"input": "2 0\n1 2",
"output": "1"
},
{
"input": "8 1\n3 3 3 5 5 5 5 5",
"output": "3"
},
{
"input": "5 1\n3 5 5 5 6",
"output": "1"
}
] | 1,519,987,033 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 62 | 5,632,000 | #!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Created on Fri Mar 2 09:58:19 2018
@author: mikolajbinkowski
"""
n, d = [int(k) for k in input().split(' ')]
points = [int(k) for k in input().split(' ')]
def qs(A, l, r):
if l >= r:
return
p = part(A, l, r)
qs(A, l, p - 1)
qs(A, p + 1, r)
def part(A, l, r):
if l == r:
return l
pivot = A[r]
i = l
for j in range(l, r):
if A[j] < pivot:
swap(A, j, i)
i += 1
swap(A, r, i)
return i
def swap(A, i, j):
c= A[i]
A[i] = A[j]
A[j] = c
qs(points, 0, n - 1)
i, j = 0, 0
max_dist = 0
while j < n:
while points[j] - points[i] <= d:
j += 1
if j >= n:
break
dist = j - i
if dist > max_dist:
max_dist = dist
i += 1
print(n - max_dist)
| Title: Points on the line
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
We've got no test cases. A big olympiad is coming up. But the problemsetters' number one priority should be adding another problem to the round.
The diameter of a multiset of points on the line is the largest distance between two points from this set. For example, the diameter of the multiset {1,<=3,<=2,<=1} is 2.
Diameter of multiset consisting of one point is 0.
You are given *n* points on the line. What is the minimum number of points you have to remove, so that the diameter of the multiset of the remaining points will not exceed *d*?
Input Specification:
The first line contains two integers *n* and *d* (1<=≤<=*n*<=≤<=100,<=0<=≤<=*d*<=≤<=100) — the amount of points and the maximum allowed diameter respectively.
The second line contains *n* space separated integers (1<=≤<=*x**i*<=≤<=100) — the coordinates of the points.
Output Specification:
Output a single integer — the minimum number of points you have to remove.
Demo Input:
['3 1\n2 1 4\n', '3 0\n7 7 7\n', '6 3\n1 3 4 6 9 10\n']
Demo Output:
['1\n', '0\n', '3\n']
Note:
In the first test case the optimal strategy is to remove the point with coordinate 4. The remaining points will have coordinates 1 and 2, so the diameter will be equal to 2 - 1 = 1.
In the second test case the diameter is equal to 0, so its is unnecessary to remove any points.
In the third test case the optimal strategy is to remove points with coordinates 1, 9 and 10. The remaining points will have coordinates 3, 4 and 6, so the diameter will be equal to 6 - 3 = 3. | ```python
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Created on Fri Mar 2 09:58:19 2018
@author: mikolajbinkowski
"""
n, d = [int(k) for k in input().split(' ')]
points = [int(k) for k in input().split(' ')]
def qs(A, l, r):
if l >= r:
return
p = part(A, l, r)
qs(A, l, p - 1)
qs(A, p + 1, r)
def part(A, l, r):
if l == r:
return l
pivot = A[r]
i = l
for j in range(l, r):
if A[j] < pivot:
swap(A, j, i)
i += 1
swap(A, r, i)
return i
def swap(A, i, j):
c= A[i]
A[i] = A[j]
A[j] = c
qs(points, 0, n - 1)
i, j = 0, 0
max_dist = 0
while j < n:
while points[j] - points[i] <= d:
j += 1
if j >= n:
break
dist = j - i
if dist > max_dist:
max_dist = dist
i += 1
print(n - max_dist)
``` | 3 |
|
525 | A | Vitaliy and Pie | PROGRAMMING | 1,100 | [
"greedy",
"hashing",
"strings"
] | null | null | After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with *n* room located in a line and numbered starting from one from left to right. You can go from the first room to the second room, from the second room to the third room and so on — you can go from the (*n*<=-<=1)-th room to the *n*-th room. Thus, you can go to room *x* only from room *x*<=-<=1.
The potato pie is located in the *n*-th room and Vitaly needs to go there.
Each pair of consecutive rooms has a door between them. In order to go to room *x* from room *x*<=-<=1, you need to open the door between the rooms with the corresponding key.
In total the house has several types of doors (represented by uppercase Latin letters) and several types of keys (represented by lowercase Latin letters). The key of type *t* can open the door of type *T* if and only if *t* and *T* are the same letter, written in different cases. For example, key f can open door F.
Each of the first *n*<=-<=1 rooms contains exactly one key of some type that Vitaly can use to get to next rooms. Once the door is open with some key, Vitaly won't get the key from the keyhole but he will immediately run into the next room. In other words, each key can open no more than one door.
Vitaly realizes that he may end up in some room without the key that opens the door to the next room. Before the start his run for the potato pie Vitaly can buy any number of keys of any type that is guaranteed to get to room *n*.
Given the plan of the house, Vitaly wants to know what is the minimum number of keys he needs to buy to surely get to the room *n*, which has a delicious potato pie. Write a program that will help Vitaly find out this number. | The first line of the input contains a positive integer *n* (2<=≤<=*n*<=≤<=105) — the number of rooms in the house.
The second line of the input contains string *s* of length 2·*n*<=-<=2. Let's number the elements of the string from left to right, starting from one.
The odd positions in the given string *s* contain lowercase Latin letters — the types of the keys that lie in the corresponding rooms. Thus, each odd position *i* of the given string *s* contains a lowercase Latin letter — the type of the key that lies in room number (*i*<=+<=1)<=/<=2.
The even positions in the given string contain uppercase Latin letters — the types of doors between the rooms. Thus, each even position *i* of the given string *s* contains an uppercase letter — the type of the door that leads from room *i*<=/<=2 to room *i*<=/<=2<=+<=1. | Print the only integer — the minimum number of keys that Vitaly needs to buy to surely get from room one to room *n*. | [
"3\naAbB\n",
"4\naBaCaB\n",
"5\nxYyXzZaZ\n"
] | [
"0\n",
"3\n",
"2\n"
] | none | 250 | [
{
"input": "3\naAbB",
"output": "0"
},
{
"input": "4\naBaCaB",
"output": "3"
},
{
"input": "5\nxYyXzZaZ",
"output": "2"
},
{
"input": "26\naAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyY",
"output": "0"
},
{
"input": "26\nzAyBxCwDvEuFtGsHrIqJpKoLnMmNlOkPjQiRhSgTfUeVdWcXbY",
"output": "13"
},
{
"input": "5\naArRaRaR",
"output": "2"
},
{
"input": "2\ndA",
"output": "1"
},
{
"input": "2\ncB",
"output": "1"
},
{
"input": "10\nhNcMeXsSlHsUwYeMcA",
"output": "7"
},
{
"input": "100\nqDpInBmCrFwXpDbFgOzVvOcEmJrUcToAdEwEgTvBvBfWwRpGyEaXgDdRwVlQnYgWmWhMrHaIzPyXvGaFlRsVzHhZrOuVpXrKxFzAmWwPlFtNfPtJxVmLuHjKfYyArHrEnSwSzOvDpQhCgCqLlAcNpGhXrEeFuCmAqIkXyYtSsQwIxJzNiIuTgEbVuWrMwPrAlLyKaZ",
"output": "42"
},
{
"input": "2\ndD",
"output": "0"
},
{
"input": "2\ndE",
"output": "1"
},
{
"input": "3\ndDdD",
"output": "0"
},
{
"input": "3\ndEdD",
"output": "1"
},
{
"input": "3\ndEeD",
"output": "1"
},
{
"input": "3\ndEeF",
"output": "2"
}
] | 1,695,040,548 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 7 | 77 | 1,638,400 | n = int(input())
s = input()
d = {}
ans = 0
i = 0
while(i<2*(n-1)):
a = s[i]
b = s[i+1].lower()
i+=2;
# print(a,b)
if a!=b.lower():
if a not in d:
d[a] = 1
if b.lower() in d:
d[b.lower()] -=1
else:
ans+=1
print(ans)
| Title: Vitaliy and Pie
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with *n* room located in a line and numbered starting from one from left to right. You can go from the first room to the second room, from the second room to the third room and so on — you can go from the (*n*<=-<=1)-th room to the *n*-th room. Thus, you can go to room *x* only from room *x*<=-<=1.
The potato pie is located in the *n*-th room and Vitaly needs to go there.
Each pair of consecutive rooms has a door between them. In order to go to room *x* from room *x*<=-<=1, you need to open the door between the rooms with the corresponding key.
In total the house has several types of doors (represented by uppercase Latin letters) and several types of keys (represented by lowercase Latin letters). The key of type *t* can open the door of type *T* if and only if *t* and *T* are the same letter, written in different cases. For example, key f can open door F.
Each of the first *n*<=-<=1 rooms contains exactly one key of some type that Vitaly can use to get to next rooms. Once the door is open with some key, Vitaly won't get the key from the keyhole but he will immediately run into the next room. In other words, each key can open no more than one door.
Vitaly realizes that he may end up in some room without the key that opens the door to the next room. Before the start his run for the potato pie Vitaly can buy any number of keys of any type that is guaranteed to get to room *n*.
Given the plan of the house, Vitaly wants to know what is the minimum number of keys he needs to buy to surely get to the room *n*, which has a delicious potato pie. Write a program that will help Vitaly find out this number.
Input Specification:
The first line of the input contains a positive integer *n* (2<=≤<=*n*<=≤<=105) — the number of rooms in the house.
The second line of the input contains string *s* of length 2·*n*<=-<=2. Let's number the elements of the string from left to right, starting from one.
The odd positions in the given string *s* contain lowercase Latin letters — the types of the keys that lie in the corresponding rooms. Thus, each odd position *i* of the given string *s* contains a lowercase Latin letter — the type of the key that lies in room number (*i*<=+<=1)<=/<=2.
The even positions in the given string contain uppercase Latin letters — the types of doors between the rooms. Thus, each even position *i* of the given string *s* contains an uppercase letter — the type of the door that leads from room *i*<=/<=2 to room *i*<=/<=2<=+<=1.
Output Specification:
Print the only integer — the minimum number of keys that Vitaly needs to buy to surely get from room one to room *n*.
Demo Input:
['3\naAbB\n', '4\naBaCaB\n', '5\nxYyXzZaZ\n']
Demo Output:
['0\n', '3\n', '2\n']
Note:
none | ```python
n = int(input())
s = input()
d = {}
ans = 0
i = 0
while(i<2*(n-1)):
a = s[i]
b = s[i+1].lower()
i+=2;
# print(a,b)
if a!=b.lower():
if a not in d:
d[a] = 1
if b.lower() in d:
d[b.lower()] -=1
else:
ans+=1
print(ans)
``` | 0 |
|
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,688,886,409 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 31 | 92 | 0 | n,m = map(int,input().split())
r = n*m
if r>1:print(r//2)
| Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers two squares.
2. No two dominoes overlap.
3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board.
Find the maximum number of dominoes, which can be placed under these restrictions.
Input Specification:
In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16).
Output Specification:
Output one number — the maximal number of dominoes, which can be placed.
Demo Input:
['2 4\n', '3 3\n']
Demo Output:
['4\n', '4\n']
Note:
none | ```python
n,m = map(int,input().split())
r = n*m
if r>1:print(r//2)
``` | 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,687,145,275 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | n=int(input())
a=sorted(map(int,input().split()))
x,y=0,0
t=True
for i in a:
if t:x+=i
else:y+=i
t=not t
print(x,y)
| 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=sorted(map(int,input().split()))
x,y=0,0
t=True
for i in a:
if t:x+=i
else:y+=i
t=not t
print(x,y)
``` | 0 |
|
375 | B | Maximum Submatrix 2 | PROGRAMMING | 1,600 | [
"data structures",
"dp",
"implementation",
"sortings"
] | null | null | You are given a matrix consisting of digits zero and one, its size is *n*<=×<=*m*. You are allowed to rearrange its rows. What is the maximum area of the submatrix that only consists of ones and can be obtained in the given problem by the described operations?
Let's assume that the rows of matrix *a* are numbered from 1 to *n* from top to bottom and the columns are numbered from 1 to *m* from left to right. A matrix cell on the intersection of the *i*-th row and the *j*-th column can be represented as (*i*,<=*j*). Formally, a submatrix of matrix *a* is a group of four integers *d*,<=*u*,<=*l*,<=*r* (1<=≤<=*d*<=≤<=*u*<=≤<=*n*; 1<=≤<=*l*<=≤<=*r*<=≤<=*m*). We will assume that the submatrix contains cells (*i*,<=*j*) (*d*<=≤<=*i*<=≤<=*u*; *l*<=≤<=*j*<=≤<=*r*). The area of the submatrix is the number of cells it contains. | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=5000). Next *n* lines contain *m* characters each — matrix *a*. Matrix *a* only contains characters: "0" and "1". Note that the elements of the matrix follow without any spaces in the lines. | Print a single integer — the area of the maximum obtained submatrix. If we cannot obtain a matrix of numbers one, print 0. | [
"1 1\n1\n",
"2 2\n10\n11\n",
"4 3\n100\n011\n000\n101\n"
] | [
"1\n",
"2\n",
"2\n"
] | none | 1,000 | [
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "2 2\n10\n11",
"output": "2"
},
{
"input": "4 3\n100\n011\n000\n101",
"output": "2"
},
{
"input": "11 16\n0111110101100011\n1000101100010000\n0010110110010101\n0110110010110010\n0011101101110000\n1001100011010111\n0010011111111000\n0100100100111110\n1001000000100111\n0110000011001000\n1011111011010000",
"output": "9"
},
{
"input": "19 12\n110001100110\n100100000000\n101011001111\n010111110001\n011000100100\n011111010000\n010011101100\n011010011110\n011001111110\n010111110001\n010000010111\n001111110100\n100100110001\n100110000000\n110000010010\n111101011101\n010111100000\n100000011010\n000100100101",
"output": "16"
},
{
"input": "13 19\n0000111111111111011\n0111000001110001101\n1110100110111011101\n0001101011100001110\n1101100100010000101\n1010100011110011010\n1010011101010000001\n1011101000001111000\n1101110001101011110\n0110101010001111100\n0001011010100111001\n1111101000110001000\n0010010000011100010",
"output": "14"
},
{
"input": "8 5\n00000\n00000\n00000\n00000\n00000\n00000\n00000\n00000",
"output": "0"
},
{
"input": "15 18\n111111111111111111\n111111111111111111\n111111111111111111\n111111111111111111\n111111111111111111\n111111111111111111\n111111111111111111\n111111111111111111\n111111111111111111\n111111111111111111\n111111111111111111\n111111111111111111\n111111111111111111\n111111111111111111\n111111111111111111",
"output": "270"
},
{
"input": "1 1\n0",
"output": "0"
}
] | 1,599,854,825 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 187 | 5,324,800 | '''
Auther: ghoshashis545 Ashis Ghosh
College: jalpaiguri Govt Enggineering College
'''
from os import path
import sys
from heapq import heappush,heappop
from functools import cmp_to_key as ctk
from collections import deque,defaultdict as dd
from bisect import bisect,bisect_left,bisect_right,insort,insort_left,insort_right
from itertools import permutations
from datetime import datetime
from math import sqrt,log,gcd
def ii():return int(input())
def si():return input().rstrip()
def mi():return map(int,input().split())
def li():return list(mi())
def ceil(a,b): return (a+b-1)//b
abc='abcdefghijklmnopqrstuvwxyz'
mod=1000000007
# mod=998244353
inf = float("inf")
vow=['a','e','i','o','u']
dx,dy=[-1,1,0,0],[0,0,1,-1]
def bo(i):
return ord(i)-ord('a')
test = 0
def largest_histogram(a):
# print(a)
pos = []
val = []
ans = 0
n = len(a)
for i in range(n):
if len(val)==0:
val.append(a[i])
pos.append(i)
elif(a[i]>val[-1]):
val.append(a[i])
pos.append(i)
else:
while(len(val)>0 and val[-1]>=a[i]):
ans = max(ans,val[-1]*(i-pos[-1]))
val.pop()
last_pos = pos[-1]
pos.pop()
val.append(a[i])
pos.append(last_pos)
while(len(val)>0):
ans =max(ans,val[-1]*(n-pos[-1]))
val.pop()
pos.pop()
return ans
def solve():
n,m = mi()
a = []
for i in range(n):
a.append(si())
x = [0]*m
ans = 0
for i in range(n):
x = [(x[j]+int(a[i][j])) if a[i][j]=='1' else 0 for j in range(m)]
ans = max(ans,largest_histogram(x))
print(ans)
if __name__ =="__main__":
if path.exists('input.txt'):
sys.stdin=open('input.txt', 'r')
sys.stdout=open('output.txt','w')
else:
input=sys.stdin.readline
t = 1
if test:
t = ii()
for _ in range(t):
solve() | Title: Maximum Submatrix 2
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a matrix consisting of digits zero and one, its size is *n*<=×<=*m*. You are allowed to rearrange its rows. What is the maximum area of the submatrix that only consists of ones and can be obtained in the given problem by the described operations?
Let's assume that the rows of matrix *a* are numbered from 1 to *n* from top to bottom and the columns are numbered from 1 to *m* from left to right. A matrix cell on the intersection of the *i*-th row and the *j*-th column can be represented as (*i*,<=*j*). Formally, a submatrix of matrix *a* is a group of four integers *d*,<=*u*,<=*l*,<=*r* (1<=≤<=*d*<=≤<=*u*<=≤<=*n*; 1<=≤<=*l*<=≤<=*r*<=≤<=*m*). We will assume that the submatrix contains cells (*i*,<=*j*) (*d*<=≤<=*i*<=≤<=*u*; *l*<=≤<=*j*<=≤<=*r*). The area of the submatrix is the number of cells it contains.
Input Specification:
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=5000). Next *n* lines contain *m* characters each — matrix *a*. Matrix *a* only contains characters: "0" and "1". Note that the elements of the matrix follow without any spaces in the lines.
Output Specification:
Print a single integer — the area of the maximum obtained submatrix. If we cannot obtain a matrix of numbers one, print 0.
Demo Input:
['1 1\n1\n', '2 2\n10\n11\n', '4 3\n100\n011\n000\n101\n']
Demo Output:
['1\n', '2\n', '2\n']
Note:
none | ```python
'''
Auther: ghoshashis545 Ashis Ghosh
College: jalpaiguri Govt Enggineering College
'''
from os import path
import sys
from heapq import heappush,heappop
from functools import cmp_to_key as ctk
from collections import deque,defaultdict as dd
from bisect import bisect,bisect_left,bisect_right,insort,insort_left,insort_right
from itertools import permutations
from datetime import datetime
from math import sqrt,log,gcd
def ii():return int(input())
def si():return input().rstrip()
def mi():return map(int,input().split())
def li():return list(mi())
def ceil(a,b): return (a+b-1)//b
abc='abcdefghijklmnopqrstuvwxyz'
mod=1000000007
# mod=998244353
inf = float("inf")
vow=['a','e','i','o','u']
dx,dy=[-1,1,0,0],[0,0,1,-1]
def bo(i):
return ord(i)-ord('a')
test = 0
def largest_histogram(a):
# print(a)
pos = []
val = []
ans = 0
n = len(a)
for i in range(n):
if len(val)==0:
val.append(a[i])
pos.append(i)
elif(a[i]>val[-1]):
val.append(a[i])
pos.append(i)
else:
while(len(val)>0 and val[-1]>=a[i]):
ans = max(ans,val[-1]*(i-pos[-1]))
val.pop()
last_pos = pos[-1]
pos.pop()
val.append(a[i])
pos.append(last_pos)
while(len(val)>0):
ans =max(ans,val[-1]*(n-pos[-1]))
val.pop()
pos.pop()
return ans
def solve():
n,m = mi()
a = []
for i in range(n):
a.append(si())
x = [0]*m
ans = 0
for i in range(n):
x = [(x[j]+int(a[i][j])) if a[i][j]=='1' else 0 for j in range(m)]
ans = max(ans,largest_histogram(x))
print(ans)
if __name__ =="__main__":
if path.exists('input.txt'):
sys.stdin=open('input.txt', 'r')
sys.stdout=open('output.txt','w')
else:
input=sys.stdin.readline
t = 1
if test:
t = ii()
for _ in range(t):
solve()
``` | 0 |
|
884 | D | Boxes And Balls | PROGRAMMING | 2,300 | [
"data structures",
"greedy"
] | null | null | Ivan has *n* different boxes. The first of them contains some balls of *n* different colors.
Ivan wants to play a strange game. He wants to distribute the balls into boxes in such a way that for every *i* (1<=≤<=*i*<=≤<=*n*) *i*-th box will contain all balls with color *i*.
In order to do this, Ivan will make some turns. Each turn he does the following:
1. Ivan chooses any non-empty box and takes all balls from this box; 1. Then Ivan chooses any *k* empty boxes (the box from the first step becomes empty, and Ivan is allowed to choose it), separates the balls he took on the previous step into *k* non-empty groups and puts each group into one of the boxes. He should put each group into a separate box. He can choose either *k*<==<=2 or *k*<==<=3.
The penalty of the turn is the number of balls Ivan takes from the box during the first step of the turn. And penalty of the game is the total penalty of turns made by Ivan until he distributes all balls to corresponding boxes.
Help Ivan to determine the minimum possible penalty of the game! | The first line contains one integer number *n* (1<=≤<=*n*<=≤<=200000) — the number of boxes and colors.
The second line contains *n* integer numbers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=109), where *a**i* is the number of balls with color *i*. | Print one number — the minimum possible penalty of the game. | [
"3\n1 2 3\n",
"4\n2 3 4 5\n"
] | [
"6\n",
"19\n"
] | In the first example you take all the balls from the first box, choose *k* = 3 and sort all colors to corresponding boxes. Penalty is 6.
In the second example you make two turns:
1. Take all the balls from the first box, choose *k* = 3, put balls of color 3 to the third box, of color 4 — to the fourth box and the rest put back into the first box. Penalty is 14; 1. Take all the balls from the first box, choose *k* = 2, put balls of color 1 to the first box, of color 2 — to the second box. Penalty is 5.
Total penalty is 19. | 0 | [
{
"input": "3\n1 2 3",
"output": "6"
},
{
"input": "4\n2 3 4 5",
"output": "19"
},
{
"input": "6\n1 4 4 4 4 4",
"output": "38"
},
{
"input": "8\n821407370 380061316 428719552 90851747 825473738 704702117 845629927 245820158",
"output": "8176373828"
},
{
"input": "1\n10",
"output": "0"
},
{
"input": "1\n4",
"output": "0"
},
{
"input": "1\n12312",
"output": "0"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "2\n3 4",
"output": "7"
}
] | 1,651,766,117 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 421 | 16,179,200 | n = int(input())
colors = list(map(int, input().strip().split()))
if n % 2 == 0:
colors.append(0)
import heapq
heapq.heapify(colors)
penalty = 0
while (len(colors) > 2):
a = heapq.heappop(colors)
b = heapq.heappop(colors)
c = heapq.heappop(colors)
penalty += (a + b + c)
heapq.heappush(colors, a + b + c)
print(penalty) | Title: Boxes And Balls
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ivan has *n* different boxes. The first of them contains some balls of *n* different colors.
Ivan wants to play a strange game. He wants to distribute the balls into boxes in such a way that for every *i* (1<=≤<=*i*<=≤<=*n*) *i*-th box will contain all balls with color *i*.
In order to do this, Ivan will make some turns. Each turn he does the following:
1. Ivan chooses any non-empty box and takes all balls from this box; 1. Then Ivan chooses any *k* empty boxes (the box from the first step becomes empty, and Ivan is allowed to choose it), separates the balls he took on the previous step into *k* non-empty groups and puts each group into one of the boxes. He should put each group into a separate box. He can choose either *k*<==<=2 or *k*<==<=3.
The penalty of the turn is the number of balls Ivan takes from the box during the first step of the turn. And penalty of the game is the total penalty of turns made by Ivan until he distributes all balls to corresponding boxes.
Help Ivan to determine the minimum possible penalty of the game!
Input Specification:
The first line contains one integer number *n* (1<=≤<=*n*<=≤<=200000) — the number of boxes and colors.
The second line contains *n* integer numbers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=109), where *a**i* is the number of balls with color *i*.
Output Specification:
Print one number — the minimum possible penalty of the game.
Demo Input:
['3\n1 2 3\n', '4\n2 3 4 5\n']
Demo Output:
['6\n', '19\n']
Note:
In the first example you take all the balls from the first box, choose *k* = 3 and sort all colors to corresponding boxes. Penalty is 6.
In the second example you make two turns:
1. Take all the balls from the first box, choose *k* = 3, put balls of color 3 to the third box, of color 4 — to the fourth box and the rest put back into the first box. Penalty is 14; 1. Take all the balls from the first box, choose *k* = 2, put balls of color 1 to the first box, of color 2 — to the second box. Penalty is 5.
Total penalty is 19. | ```python
n = int(input())
colors = list(map(int, input().strip().split()))
if n % 2 == 0:
colors.append(0)
import heapq
heapq.heapify(colors)
penalty = 0
while (len(colors) > 2):
a = heapq.heappop(colors)
b = heapq.heappop(colors)
c = heapq.heappop(colors)
penalty += (a + b + c)
heapq.heappush(colors, a + b + c)
print(penalty)
``` | 3 |
|
750 | A | New Year and Hurry | PROGRAMMING | 800 | [
"binary search",
"brute force",
"implementation",
"math"
] | null | null | Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be *n* problems, sorted by difficulty, i.e. problem 1 is the easiest and problem *n* is the hardest. Limak knows it will take him 5·*i* minutes to solve the *i*-th problem.
Limak's friends organize a New Year's Eve party and Limak wants to be there at midnight or earlier. He needs *k* minutes to get there from his house, where he will participate in the contest first.
How many problems can Limak solve if he wants to make it to the party? | The only line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=10, 1<=≤<=*k*<=≤<=240) — the number of the problems in the contest and the number of minutes Limak needs to get to the party from his house. | Print one integer, denoting the maximum possible number of problems Limak can solve so that he could get to the party at midnight or earlier. | [
"3 222\n",
"4 190\n",
"7 1\n"
] | [
"2\n",
"4\n",
"7\n"
] | In the first sample, there are 3 problems and Limak needs 222 minutes to get to the party. The three problems require 5, 10 and 15 minutes respectively. Limak can spend 5 + 10 = 15 minutes to solve first two problems. Then, at 20:15 he can leave his house to get to the party at 23:57 (after 222 minutes). In this scenario Limak would solve 2 problems. He doesn't have enough time to solve 3 problems so the answer is 2.
In the second sample, Limak can solve all 4 problems in 5 + 10 + 15 + 20 = 50 minutes. At 20:50 he will leave the house and go to the party. He will get there exactly at midnight.
In the third sample, Limak needs only 1 minute to get to the party. He has enough time to solve all 7 problems. | 500 | [
{
"input": "3 222",
"output": "2"
},
{
"input": "4 190",
"output": "4"
},
{
"input": "7 1",
"output": "7"
},
{
"input": "10 135",
"output": "6"
},
{
"input": "10 136",
"output": "5"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 240",
"output": "0"
},
{
"input": "10 1",
"output": "9"
},
{
"input": "10 240",
"output": "0"
},
{
"input": "9 240",
"output": "0"
},
{
"input": "9 1",
"output": "9"
},
{
"input": "9 235",
"output": "1"
},
{
"input": "9 236",
"output": "0"
},
{
"input": "5 225",
"output": "2"
},
{
"input": "5 226",
"output": "1"
},
{
"input": "4 210",
"output": "3"
},
{
"input": "4 211",
"output": "2"
},
{
"input": "4 191",
"output": "3"
},
{
"input": "10 165",
"output": "5"
},
{
"input": "10 166",
"output": "4"
},
{
"input": "8 100",
"output": "7"
},
{
"input": "8 101",
"output": "6"
},
{
"input": "8 60",
"output": "8"
},
{
"input": "8 61",
"output": "7"
},
{
"input": "10 15",
"output": "9"
},
{
"input": "10 16",
"output": "8"
},
{
"input": "4 100",
"output": "4"
},
{
"input": "4 101",
"output": "4"
},
{
"input": "7 167",
"output": "4"
},
{
"input": "10 164",
"output": "5"
},
{
"input": "9 170",
"output": "4"
},
{
"input": "8 160",
"output": "5"
},
{
"input": "1 100",
"output": "1"
},
{
"input": "8 123",
"output": "6"
},
{
"input": "2 99",
"output": "2"
},
{
"input": "10 88",
"output": "7"
},
{
"input": "1 235",
"output": "1"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "4 240",
"output": "0"
},
{
"input": "1 55",
"output": "1"
},
{
"input": "1 240",
"output": "0"
},
{
"input": "3 240",
"output": "0"
},
{
"input": "10 240",
"output": "0"
},
{
"input": "2 240",
"output": "0"
},
{
"input": "10 1",
"output": "9"
},
{
"input": "9 1",
"output": "9"
},
{
"input": "2 236",
"output": "0"
},
{
"input": "10 2",
"output": "9"
},
{
"input": "3 239",
"output": "0"
},
{
"input": "1 237",
"output": "0"
},
{
"input": "7 8",
"output": "7"
},
{
"input": "10 235",
"output": "1"
}
] | 1,695,485,111 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 31 | 0 | n,k=int(input(),split())
t=240
s=0
count=0
for i in range(1,n+1):
x=5*i
s=s+x
count=i
if(t//s==1):
break;
print(count)
| Title: New Year and Hurry
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be *n* problems, sorted by difficulty, i.e. problem 1 is the easiest and problem *n* is the hardest. Limak knows it will take him 5·*i* minutes to solve the *i*-th problem.
Limak's friends organize a New Year's Eve party and Limak wants to be there at midnight or earlier. He needs *k* minutes to get there from his house, where he will participate in the contest first.
How many problems can Limak solve if he wants to make it to the party?
Input Specification:
The only line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=10, 1<=≤<=*k*<=≤<=240) — the number of the problems in the contest and the number of minutes Limak needs to get to the party from his house.
Output Specification:
Print one integer, denoting the maximum possible number of problems Limak can solve so that he could get to the party at midnight or earlier.
Demo Input:
['3 222\n', '4 190\n', '7 1\n']
Demo Output:
['2\n', '4\n', '7\n']
Note:
In the first sample, there are 3 problems and Limak needs 222 minutes to get to the party. The three problems require 5, 10 and 15 minutes respectively. Limak can spend 5 + 10 = 15 minutes to solve first two problems. Then, at 20:15 he can leave his house to get to the party at 23:57 (after 222 minutes). In this scenario Limak would solve 2 problems. He doesn't have enough time to solve 3 problems so the answer is 2.
In the second sample, Limak can solve all 4 problems in 5 + 10 + 15 + 20 = 50 minutes. At 20:50 he will leave the house and go to the party. He will get there exactly at midnight.
In the third sample, Limak needs only 1 minute to get to the party. He has enough time to solve all 7 problems. | ```python
n,k=int(input(),split())
t=240
s=0
count=0
for i in range(1,n+1):
x=5*i
s=s+x
count=i
if(t//s==1):
break;
print(count)
``` | -1 |
|
408 | A | Line to Cashier | PROGRAMMING | 900 | [
"implementation"
] | null | null | Little Vasya went to the supermarket to get some groceries. He walked about the supermarket for a long time and got a basket full of products. Now he needs to choose the cashier to pay for the products.
There are *n* cashiers at the exit from the supermarket. At the moment the queue for the *i*-th cashier already has *k**i* people. The *j*-th person standing in the queue to the *i*-th cashier has *m**i*,<=*j* items in the basket. Vasya knows that:
- the cashier needs 5 seconds to scan one item; - after the cashier scans each item of some customer, he needs 15 seconds to take the customer's money and give him the change.
Of course, Vasya wants to select a queue so that he can leave the supermarket as soon as possible. Help him write a program that displays the minimum number of seconds after which Vasya can get to one of the cashiers. | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of cashes in the shop. The second line contains *n* space-separated integers: *k*1,<=*k*2,<=...,<=*k**n* (1<=≤<=*k**i*<=≤<=100), where *k**i* is the number of people in the queue to the *i*-th cashier.
The *i*-th of the next *n* lines contains *k**i* space-separated integers: *m**i*,<=1,<=*m**i*,<=2,<=...,<=*m**i*,<=*k**i* (1<=≤<=*m**i*,<=*j*<=≤<=100) — the number of products the *j*-th person in the queue for the *i*-th cash has. | Print a single integer — the minimum number of seconds Vasya needs to get to the cashier. | [
"1\n1\n1\n",
"4\n1 4 3 2\n100\n1 2 2 3\n1 9 1\n7 8\n"
] | [
"20\n",
"100\n"
] | In the second test sample, if Vasya goes to the first queue, he gets to the cashier in 100·5 + 15 = 515 seconds. But if he chooses the second queue, he will need 1·5 + 2·5 + 2·5 + 3·5 + 4·15 = 100 seconds. He will need 1·5 + 9·5 + 1·5 + 3·15 = 100 seconds for the third one and 7·5 + 8·5 + 2·15 = 105 seconds for the fourth one. Thus, Vasya gets to the cashier quicker if he chooses the second or the third queue. | 500 | [
{
"input": "1\n1\n1",
"output": "20"
},
{
"input": "4\n1 4 3 2\n100\n1 2 2 3\n1 9 1\n7 8",
"output": "100"
},
{
"input": "4\n5 4 5 5\n3 1 3 1 2\n3 1 1 3\n1 1 1 2 2\n2 2 1 1 3",
"output": "100"
},
{
"input": "5\n5 3 6 6 4\n7 5 3 3 9\n6 8 2\n1 10 8 5 9 2\n9 7 8 5 9 10\n9 8 3 3",
"output": "125"
},
{
"input": "5\n10 10 10 10 10\n6 7 8 6 8 5 9 8 10 5\n9 6 9 8 7 8 8 10 8 5\n8 7 7 8 7 5 6 8 9 5\n6 5 10 5 5 10 7 8 5 5\n10 9 8 7 6 9 7 9 6 5",
"output": "480"
},
{
"input": "10\n9 10 10 10 9 5 9 7 8 7\n11 6 10 4 4 15 7 15 5\n3 9 11 12 11 1 13 13 1 5\n6 15 9 12 3 2 8 12 11 10\n7 1 1 6 10 2 6 1 14 2\n8 14 2 3 6 1 14 1 12\n6 10 9 3 5\n13 12 12 7 13 4 4 8 10\n5 6 4 3 14 9 13\n8 12 1 5 7 4 13 1\n1 9 5 3 5 1 4",
"output": "240"
},
{
"input": "10\n5 5 5 5 5 5 5 5 5 5\n5 5 4 5 4\n6 5 7 7 6\n5 4 4 5 5\n4 4 5 5 5\n7 6 4 5 7\n4 6 5 4 5\n6 6 7 6 6\n4 5 4 4 7\n7 5 4 4 5\n6 6 7 4 4",
"output": "190"
},
{
"input": "1\n1\n100",
"output": "515"
},
{
"input": "1\n90\n90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90",
"output": "41850"
}
] | 1,650,785,852 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 31 | 0 | n = int(input())
book = {}
cashiers = [int(num) for num in input().split(' ', n-1)]
for i in range(0, n):
key = cashiers[i]
tem = [int(x) for x in input().split()]
book[key] = tem
time_list = []
for i in range(0, n):
t = 5 * sum(book[cashiers[i]]) + 15 * cashiers[i]
time_list.append(t)
print(min(time_list))
| Title: Line to Cashier
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Vasya went to the supermarket to get some groceries. He walked about the supermarket for a long time and got a basket full of products. Now he needs to choose the cashier to pay for the products.
There are *n* cashiers at the exit from the supermarket. At the moment the queue for the *i*-th cashier already has *k**i* people. The *j*-th person standing in the queue to the *i*-th cashier has *m**i*,<=*j* items in the basket. Vasya knows that:
- the cashier needs 5 seconds to scan one item; - after the cashier scans each item of some customer, he needs 15 seconds to take the customer's money and give him the change.
Of course, Vasya wants to select a queue so that he can leave the supermarket as soon as possible. Help him write a program that displays the minimum number of seconds after which Vasya can get to one of the cashiers.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of cashes in the shop. The second line contains *n* space-separated integers: *k*1,<=*k*2,<=...,<=*k**n* (1<=≤<=*k**i*<=≤<=100), where *k**i* is the number of people in the queue to the *i*-th cashier.
The *i*-th of the next *n* lines contains *k**i* space-separated integers: *m**i*,<=1,<=*m**i*,<=2,<=...,<=*m**i*,<=*k**i* (1<=≤<=*m**i*,<=*j*<=≤<=100) — the number of products the *j*-th person in the queue for the *i*-th cash has.
Output Specification:
Print a single integer — the minimum number of seconds Vasya needs to get to the cashier.
Demo Input:
['1\n1\n1\n', '4\n1 4 3 2\n100\n1 2 2 3\n1 9 1\n7 8\n']
Demo Output:
['20\n', '100\n']
Note:
In the second test sample, if Vasya goes to the first queue, he gets to the cashier in 100·5 + 15 = 515 seconds. But if he chooses the second queue, he will need 1·5 + 2·5 + 2·5 + 3·5 + 4·15 = 100 seconds. He will need 1·5 + 9·5 + 1·5 + 3·15 = 100 seconds for the third one and 7·5 + 8·5 + 2·15 = 105 seconds for the fourth one. Thus, Vasya gets to the cashier quicker if he chooses the second or the third queue. | ```python
n = int(input())
book = {}
cashiers = [int(num) for num in input().split(' ', n-1)]
for i in range(0, n):
key = cashiers[i]
tem = [int(x) for x in input().split()]
book[key] = tem
time_list = []
for i in range(0, n):
t = 5 * sum(book[cashiers[i]]) + 15 * cashiers[i]
time_list.append(t)
print(min(time_list))
``` | 0 |
|
903 | C | Boxes Packing | PROGRAMMING | 1,200 | [
"greedy"
] | null | null | Mishka has got *n* empty boxes. For every *i* (1<=≤<=*i*<=≤<=*n*), *i*-th box is a cube with side length *a**i*.
Mishka can put a box *i* into another box *j* if the following conditions are met:
- *i*-th box is not put into another box; - *j*-th box doesn't contain any other boxes; - box *i* is smaller than box *j* (*a**i*<=<<=*a**j*).
Mishka can put boxes into each other an arbitrary number of times. He wants to minimize the number of visible boxes. A box is called visible iff it is not put into some another box.
Help Mishka to determine the minimum possible number of visible boxes! | The first line contains one integer *n* (1<=≤<=*n*<=≤<=5000) — the number of boxes Mishka has got.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=109), where *a**i* is the side length of *i*-th box. | Print the minimum possible number of visible boxes. | [
"3\n1 2 3\n",
"4\n4 2 4 3\n"
] | [
"1\n",
"2\n"
] | In the first example it is possible to put box 1 into box 2, and 2 into 3.
In the second example Mishka can put box 2 into box 3, and box 4 into box 1. | 0 | [
{
"input": "3\n1 2 3",
"output": "1"
},
{
"input": "4\n4 2 4 3",
"output": "2"
},
{
"input": "10\n58 58 58 58 58 58 58 58 58 58",
"output": "10"
},
{
"input": "10\n86 89 89 86 86 89 86 86 89 89",
"output": "5"
},
{
"input": "100\n981 288 186 186 292 876 341 288 981 360 783 907 292 186 341 292 360 876 360 360 981 398 783 288 292 398 876 981 398 907 783 360 288 981 907 186 360 288 186 981 186 288 907 876 288 907 876 360 341 292 907 783 907 783 292 981 907 292 876 398 783 876 398 341 876 186 288 186 981 341 398 360 907 981 341 186 292 981 292 398 876 783 292 186 360 292 288 292 876 398 288 292 341 288 398 360 360 292 981 360",
"output": "14"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "1\n9",
"output": "1"
},
{
"input": "1\n5",
"output": "1"
},
{
"input": "1\n2",
"output": "1"
},
{
"input": "1\n131",
"output": "1"
},
{
"input": "9\n1 1 1 1 1 1 1 1 1",
"output": "9"
},
{
"input": "11\n1 1 1 1 1 1 1 1 1 1 1",
"output": "11"
},
{
"input": "8\n1 2 3 4 5 6 7 8",
"output": "1"
},
{
"input": "8\n1 1 1 1 1 1 1 1",
"output": "8"
},
{
"input": "5\n1 1 1 1 1",
"output": "5"
}
] | 1,687,370,969 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 31 | 0 | x=int(input())
t=0
for i in range(1,x):
if(x%i)==0:
t+=1
print(t) | Title: Boxes Packing
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mishka has got *n* empty boxes. For every *i* (1<=≤<=*i*<=≤<=*n*), *i*-th box is a cube with side length *a**i*.
Mishka can put a box *i* into another box *j* if the following conditions are met:
- *i*-th box is not put into another box; - *j*-th box doesn't contain any other boxes; - box *i* is smaller than box *j* (*a**i*<=<<=*a**j*).
Mishka can put boxes into each other an arbitrary number of times. He wants to minimize the number of visible boxes. A box is called visible iff it is not put into some another box.
Help Mishka to determine the minimum possible number of visible boxes!
Input Specification:
The first line contains one integer *n* (1<=≤<=*n*<=≤<=5000) — the number of boxes Mishka has got.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=109), where *a**i* is the side length of *i*-th box.
Output Specification:
Print the minimum possible number of visible boxes.
Demo Input:
['3\n1 2 3\n', '4\n4 2 4 3\n']
Demo Output:
['1\n', '2\n']
Note:
In the first example it is possible to put box 1 into box 2, and 2 into 3.
In the second example Mishka can put box 2 into box 3, and box 4 into box 1. | ```python
x=int(input())
t=0
for i in range(1,x):
if(x%i)==0:
t+=1
print(t)
``` | 0 |
|
1,004 | A | Sonya and Hotels | PROGRAMMING | 900 | [
"implementation"
] | null | null | Sonya decided that having her own hotel business is the best way of earning money because she can profit and rest wherever she wants.
The country where Sonya lives is an endless line. There is a city in each integer coordinate on this line. She has $n$ hotels, where the $i$-th hotel is located in the city with coordinate $x_i$. Sonya is a smart girl, so she does not open two or more hotels in the same city.
Sonya understands that her business needs to be expanded by opening new hotels, so she decides to build one more. She wants to make the minimum distance from this hotel to all others to be equal to $d$. The girl understands that there are many possible locations to construct such a hotel. Thus she wants to know the number of possible coordinates of the cities where she can build a new hotel.
Because Sonya is lounging in a jacuzzi in one of her hotels, she is asking you to find the number of cities where she can build a new hotel so that the minimum distance from the original $n$ hotels to the new one is equal to $d$. | The first line contains two integers $n$ and $d$ ($1\leq n\leq 100$, $1\leq d\leq 10^9$) — the number of Sonya's hotels and the needed minimum distance from a new hotel to all others.
The second line contains $n$ different integers in strictly increasing order $x_1, x_2, \ldots, x_n$ ($-10^9\leq x_i\leq 10^9$) — coordinates of Sonya's hotels. | Print the number of cities where Sonya can build a new hotel so that the minimum distance from this hotel to all others is equal to $d$. | [
"4 3\n-3 2 9 16\n",
"5 2\n4 8 11 18 19\n"
] | [
"6\n",
"5\n"
] | In the first example, there are $6$ possible cities where Sonya can build a hotel. These cities have coordinates $-6$, $5$, $6$, $12$, $13$, and $19$.
In the second example, there are $5$ possible cities where Sonya can build a hotel. These cities have coordinates $2$, $6$, $13$, $16$, and $21$. | 500 | [
{
"input": "4 3\n-3 2 9 16",
"output": "6"
},
{
"input": "5 2\n4 8 11 18 19",
"output": "5"
},
{
"input": "10 10\n-67 -59 -49 -38 -8 20 41 59 74 83",
"output": "8"
},
{
"input": "10 10\n0 20 48 58 81 95 111 137 147 159",
"output": "9"
},
{
"input": "100 1\n0 1 2 3 4 5 7 8 10 11 12 13 14 15 16 17 19 21 22 23 24 25 26 27 28 30 32 33 36 39 40 41 42 46 48 53 54 55 59 60 61 63 65 68 70 71 74 75 76 79 80 81 82 84 88 89 90 91 93 94 96 97 98 100 101 102 105 106 107 108 109 110 111 113 114 115 116 117 118 120 121 122 125 126 128 131 132 133 134 135 137 138 139 140 143 144 146 147 148 149",
"output": "47"
},
{
"input": "1 1000000000\n-1000000000",
"output": "2"
},
{
"input": "2 1000000000\n-1000000000 1000000000",
"output": "3"
},
{
"input": "100 2\n1 3 5 6 8 9 12 13 14 17 18 21 22 23 24 25 26 27 29 30 34 35 36 39 41 44 46 48 52 53 55 56 57 59 61 63 64 66 68 69 70 71 72 73 75 76 77 79 80 81 82 87 88 91 92 93 94 95 96 97 99 100 102 103 104 106 109 110 111 112 113 114 115 117 118 119 120 122 124 125 127 128 129 130 131 132 133 134 136 137 139 140 141 142 143 145 146 148 149 150",
"output": "6"
},
{
"input": "100 3\n0 1 3 6 7 8 9 10 13 14 16 17 18 20 21 22 24 26 27 30 33 34 35 36 37 39 42 43 44 45 46 48 53 54 55 56 57 58 61 63 64 65 67 69 70 72 73 76 77 78 79 81 82 83 85 86 87 88 90 92 93 95 96 97 98 99 100 101 104 105 108 109 110 113 114 115 116 118 120 121 123 124 125 128 130 131 132 133 134 135 136 137 139 140 141 142 146 147 148 150",
"output": "2"
},
{
"input": "1 1000000000\n1000000000",
"output": "2"
},
{
"input": "10 2\n-93 -62 -53 -42 -38 11 57 58 87 94",
"output": "17"
},
{
"input": "2 500000000\n-1000000000 1000000000",
"output": "4"
},
{
"input": "100 10\n-489 -476 -445 -432 -430 -421 -420 -418 -412 -411 -404 -383 -356 -300 -295 -293 -287 -276 -265 -263 -258 -251 -249 -246 -220 -219 -205 -186 -166 -157 -143 -137 -136 -130 -103 -86 -80 -69 -67 -55 -43 -41 -40 -26 -19 -9 16 29 41 42 54 76 84 97 98 99 101 115 134 151 157 167 169 185 197 204 208 226 227 232 234 249 259 266 281 282 293 298 300 306 308 313 319 328 331 340 341 344 356 362 366 380 390 399 409 411 419 444 455 498",
"output": "23"
},
{
"input": "1 1000000000\n999999999",
"output": "2"
},
{
"input": "1 1\n-5",
"output": "2"
},
{
"input": "2 1\n-1000000000 1000000000",
"output": "4"
},
{
"input": "1 2\n1",
"output": "2"
},
{
"input": "4 5\n0 20 40 60",
"output": "8"
},
{
"input": "1 1\n-10",
"output": "2"
},
{
"input": "1 1\n-1000000000",
"output": "2"
},
{
"input": "1 1000000000\n0",
"output": "2"
},
{
"input": "1 2\n-10",
"output": "2"
},
{
"input": "1 1\n2",
"output": "2"
},
{
"input": "1 5\n-100",
"output": "2"
},
{
"input": "2 1000000000\n999999999 1000000000",
"output": "2"
},
{
"input": "2 2\n0 5",
"output": "4"
},
{
"input": "1 2\n-5",
"output": "2"
},
{
"input": "1 1\n1",
"output": "2"
},
{
"input": "1 5\n-20",
"output": "2"
},
{
"input": "2 100000000\n-1000000000 1000000000",
"output": "4"
},
{
"input": "1 1000000000\n147483641",
"output": "2"
},
{
"input": "3 3\n1 8 9",
"output": "4"
},
{
"input": "2 1\n1 1000000000",
"output": "4"
},
{
"input": "1 2\n-4",
"output": "2"
},
{
"input": "2 1\n-1000000000 -1",
"output": "4"
}
] | 1,611,549,412 | 2,147,483,647 | PyPy 3 | OK | TESTS | 45 | 140 | 2,560,000 | import functools
import time
def timer(func):
@functools.wraps(func)
def wrapper(*args, **kwargs):
stime = time.perf_counter()
res = func(*args, **kwargs)
elapsed = time.perf_counter() - stime
print(f"{func.__name__} in {elapsed:.4f} secs")
return res
return wrapper
class solver:
# @timer
def __init__(self):
n, d = map(int, input().strip().split())
x = list(map(int, input().strip().split()))
ans = set()
for i in range(n):
for z in [-d, d]:
y = x[i] + z
dmin = min(abs(y - xi) for xi in x)
if dmin == d:
ans.add(y)
print(len(ans))
solver() | Title: Sonya and Hotels
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sonya decided that having her own hotel business is the best way of earning money because she can profit and rest wherever she wants.
The country where Sonya lives is an endless line. There is a city in each integer coordinate on this line. She has $n$ hotels, where the $i$-th hotel is located in the city with coordinate $x_i$. Sonya is a smart girl, so she does not open two or more hotels in the same city.
Sonya understands that her business needs to be expanded by opening new hotels, so she decides to build one more. She wants to make the minimum distance from this hotel to all others to be equal to $d$. The girl understands that there are many possible locations to construct such a hotel. Thus she wants to know the number of possible coordinates of the cities where she can build a new hotel.
Because Sonya is lounging in a jacuzzi in one of her hotels, she is asking you to find the number of cities where she can build a new hotel so that the minimum distance from the original $n$ hotels to the new one is equal to $d$.
Input Specification:
The first line contains two integers $n$ and $d$ ($1\leq n\leq 100$, $1\leq d\leq 10^9$) — the number of Sonya's hotels and the needed minimum distance from a new hotel to all others.
The second line contains $n$ different integers in strictly increasing order $x_1, x_2, \ldots, x_n$ ($-10^9\leq x_i\leq 10^9$) — coordinates of Sonya's hotels.
Output Specification:
Print the number of cities where Sonya can build a new hotel so that the minimum distance from this hotel to all others is equal to $d$.
Demo Input:
['4 3\n-3 2 9 16\n', '5 2\n4 8 11 18 19\n']
Demo Output:
['6\n', '5\n']
Note:
In the first example, there are $6$ possible cities where Sonya can build a hotel. These cities have coordinates $-6$, $5$, $6$, $12$, $13$, and $19$.
In the second example, there are $5$ possible cities where Sonya can build a hotel. These cities have coordinates $2$, $6$, $13$, $16$, and $21$. | ```python
import functools
import time
def timer(func):
@functools.wraps(func)
def wrapper(*args, **kwargs):
stime = time.perf_counter()
res = func(*args, **kwargs)
elapsed = time.perf_counter() - stime
print(f"{func.__name__} in {elapsed:.4f} secs")
return res
return wrapper
class solver:
# @timer
def __init__(self):
n, d = map(int, input().strip().split())
x = list(map(int, input().strip().split()))
ans = set()
for i in range(n):
for z in [-d, d]:
y = x[i] + z
dmin = min(abs(y - xi) for xi in x)
if dmin == d:
ans.add(y)
print(len(ans))
solver()
``` | 3 |
|
803 | C | Maximal GCD | PROGRAMMING | 1,900 | [
"constructive algorithms",
"greedy",
"math"
] | null | null | You are given positive integer number *n*. You should create such strictly increasing sequence of *k* positive numbers *a*1,<=*a*2,<=...,<=*a**k*, that their sum is equal to *n* and greatest common divisor is maximal.
Greatest common divisor of sequence is maximum of such numbers that every element of sequence is divisible by them.
If there is no possible sequence then output -1. | The first line consists of two numbers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=1010). | If the answer exists then output *k* numbers — resulting sequence. Otherwise output -1. If there are multiple answers, print any of them. | [
"6 3\n",
"8 2\n",
"5 3\n"
] | [
"1 2 3\n",
"2 6\n",
"-1\n"
] | none | 0 | [
{
"input": "6 3",
"output": "1 2 3"
},
{
"input": "8 2",
"output": "2 6"
},
{
"input": "5 3",
"output": "-1"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 2",
"output": "-1"
},
{
"input": "2 1",
"output": "2"
},
{
"input": "2 10000000000",
"output": "-1"
},
{
"input": "5 1",
"output": "5"
},
{
"input": "6 2",
"output": "2 4"
},
{
"input": "24 2",
"output": "8 16"
},
{
"input": "24 3",
"output": "4 8 12"
},
{
"input": "24 4",
"output": "2 4 6 12"
},
{
"input": "24 5",
"output": "1 2 3 4 14"
},
{
"input": "479001600 2",
"output": "159667200 319334400"
},
{
"input": "479001600 3",
"output": "79833600 159667200 239500800"
},
{
"input": "479001600 4",
"output": "47900160 95800320 143700480 191600640"
},
{
"input": "479001600 5",
"output": "31933440 63866880 95800320 127733760 159667200"
},
{
"input": "479001600 6",
"output": "22809600 45619200 68428800 91238400 114048000 136857600"
},
{
"input": "3000000021 1",
"output": "3000000021"
},
{
"input": "3000000021 2",
"output": "1000000007 2000000014"
},
{
"input": "3000000021 3",
"output": "3 6 3000000012"
},
{
"input": "3000000021 4",
"output": "3 6 9 3000000003"
},
{
"input": "3000000021 50000",
"output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155..."
},
{
"input": "3000000021 100000",
"output": "-1"
},
{
"input": "10000000000 100",
"output": "1953125 3906250 5859375 7812500 9765625 11718750 13671875 15625000 17578125 19531250 21484375 23437500 25390625 27343750 29296875 31250000 33203125 35156250 37109375 39062500 41015625 42968750 44921875 46875000 48828125 50781250 52734375 54687500 56640625 58593750 60546875 62500000 64453125 66406250 68359375 70312500 72265625 74218750 76171875 78125000 80078125 82031250 83984375 85937500 87890625 89843750 91796875 93750000 95703125 97656250 99609375 101562500 103515625 105468750 107421875 109375000 1113281..."
},
{
"input": "10000000000 2000",
"output": "4000 8000 12000 16000 20000 24000 28000 32000 36000 40000 44000 48000 52000 56000 60000 64000 68000 72000 76000 80000 84000 88000 92000 96000 100000 104000 108000 112000 116000 120000 124000 128000 132000 136000 140000 144000 148000 152000 156000 160000 164000 168000 172000 176000 180000 184000 188000 192000 196000 200000 204000 208000 212000 216000 220000 224000 228000 232000 236000 240000 244000 248000 252000 256000 260000 264000 268000 272000 276000 280000 284000 288000 292000 296000 300000 304000 30800..."
},
{
"input": "10000000000 5000",
"output": "640 1280 1920 2560 3200 3840 4480 5120 5760 6400 7040 7680 8320 8960 9600 10240 10880 11520 12160 12800 13440 14080 14720 15360 16000 16640 17280 17920 18560 19200 19840 20480 21120 21760 22400 23040 23680 24320 24960 25600 26240 26880 27520 28160 28800 29440 30080 30720 31360 32000 32640 33280 33920 34560 35200 35840 36480 37120 37760 38400 39040 39680 40320 40960 41600 42240 42880 43520 44160 44800 45440 46080 46720 47360 48000 48640 49280 49920 50560 51200 51840 52480 53120 53760 54400 55040 55680 56320..."
},
{
"input": "10000000000 100000",
"output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155..."
},
{
"input": "10000000000 100000000",
"output": "-1"
},
{
"input": "10000000000 10000000000",
"output": "-1"
},
{
"input": "10000000000 100001",
"output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155..."
},
{
"input": "1 4000000000",
"output": "-1"
},
{
"input": "4294967296 4294967296",
"output": "-1"
},
{
"input": "71227122 9603838834",
"output": "-1"
},
{
"input": "10000000000 9603838835",
"output": "-1"
},
{
"input": "5 5999999999",
"output": "-1"
},
{
"input": "2 9324327498",
"output": "-1"
},
{
"input": "9 2",
"output": "3 6"
},
{
"input": "10000000000 4294967296",
"output": "-1"
},
{
"input": "1 3500000000",
"output": "-1"
},
{
"input": "10000000000 4000000000",
"output": "-1"
},
{
"input": "2000 9324327498",
"output": "-1"
},
{
"input": "10000000000 8589934592",
"output": "-1"
},
{
"input": "5000150001 100001",
"output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155..."
},
{
"input": "10000000000 3037000500",
"output": "-1"
},
{
"input": "9400000000 9324327498",
"output": "-1"
},
{
"input": "10000000000 3307000500",
"output": "-1"
},
{
"input": "2 4000000000",
"output": "-1"
},
{
"input": "1000 4294967295",
"output": "-1"
},
{
"input": "36 3",
"output": "6 12 18"
},
{
"input": "2147483648 4294967296",
"output": "-1"
},
{
"input": "999 4294967295",
"output": "-1"
},
{
"input": "10000000000 130000",
"output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155..."
},
{
"input": "10000000000 140000",
"output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155..."
},
{
"input": "10000000000 6074001000",
"output": "-1"
},
{
"input": "12344321 1",
"output": "12344321"
},
{
"input": "2 2",
"output": "-1"
},
{
"input": "28 7",
"output": "1 2 3 4 5 6 7"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 2",
"output": "-1"
},
{
"input": "1 3",
"output": "-1"
},
{
"input": "1 4",
"output": "-1"
},
{
"input": "1 5",
"output": "-1"
},
{
"input": "1 6",
"output": "-1"
},
{
"input": "1 7",
"output": "-1"
},
{
"input": "1 8",
"output": "-1"
},
{
"input": "1 9",
"output": "-1"
},
{
"input": "1 10",
"output": "-1"
},
{
"input": "2 1",
"output": "2"
},
{
"input": "2 2",
"output": "-1"
},
{
"input": "2 3",
"output": "-1"
},
{
"input": "2 4",
"output": "-1"
},
{
"input": "2 5",
"output": "-1"
},
{
"input": "2 6",
"output": "-1"
},
{
"input": "2 7",
"output": "-1"
},
{
"input": "2 8",
"output": "-1"
},
{
"input": "2 9",
"output": "-1"
},
{
"input": "2 10",
"output": "-1"
},
{
"input": "3 1",
"output": "3"
},
{
"input": "3 2",
"output": "1 2"
},
{
"input": "3 3",
"output": "-1"
},
{
"input": "3 4",
"output": "-1"
},
{
"input": "3 5",
"output": "-1"
},
{
"input": "3 6",
"output": "-1"
},
{
"input": "3 7",
"output": "-1"
},
{
"input": "3 8",
"output": "-1"
},
{
"input": "3 9",
"output": "-1"
},
{
"input": "3 10",
"output": "-1"
},
{
"input": "4 1",
"output": "4"
},
{
"input": "4 2",
"output": "1 3"
},
{
"input": "4 3",
"output": "-1"
},
{
"input": "4 4",
"output": "-1"
},
{
"input": "4 5",
"output": "-1"
},
{
"input": "4 6",
"output": "-1"
},
{
"input": "4 7",
"output": "-1"
},
{
"input": "4 8",
"output": "-1"
},
{
"input": "4 9",
"output": "-1"
},
{
"input": "4 10",
"output": "-1"
},
{
"input": "5 1",
"output": "5"
},
{
"input": "5 2",
"output": "1 4"
},
{
"input": "5 3",
"output": "-1"
},
{
"input": "5 4",
"output": "-1"
},
{
"input": "5 5",
"output": "-1"
},
{
"input": "5 6",
"output": "-1"
},
{
"input": "5 7",
"output": "-1"
},
{
"input": "5 8",
"output": "-1"
},
{
"input": "5 9",
"output": "-1"
},
{
"input": "5 10",
"output": "-1"
},
{
"input": "6 1",
"output": "6"
},
{
"input": "6 2",
"output": "2 4"
},
{
"input": "6 3",
"output": "1 2 3"
},
{
"input": "6 4",
"output": "-1"
},
{
"input": "6 5",
"output": "-1"
},
{
"input": "6 6",
"output": "-1"
},
{
"input": "6 7",
"output": "-1"
},
{
"input": "6 8",
"output": "-1"
},
{
"input": "6 9",
"output": "-1"
},
{
"input": "6 10",
"output": "-1"
},
{
"input": "7 1",
"output": "7"
},
{
"input": "7 2",
"output": "1 6"
},
{
"input": "7 3",
"output": "1 2 4"
},
{
"input": "7 4",
"output": "-1"
},
{
"input": "7 5",
"output": "-1"
},
{
"input": "7 6",
"output": "-1"
},
{
"input": "7 7",
"output": "-1"
},
{
"input": "7 8",
"output": "-1"
},
{
"input": "7 9",
"output": "-1"
},
{
"input": "7 10",
"output": "-1"
},
{
"input": "8 1",
"output": "8"
},
{
"input": "8 2",
"output": "2 6"
},
{
"input": "8 3",
"output": "1 2 5"
},
{
"input": "8 4",
"output": "-1"
},
{
"input": "8 5",
"output": "-1"
},
{
"input": "8 6",
"output": "-1"
},
{
"input": "8 7",
"output": "-1"
},
{
"input": "8 8",
"output": "-1"
},
{
"input": "8 9",
"output": "-1"
},
{
"input": "8 10",
"output": "-1"
}
] | 1,638,879,267 | 1,467 | PyPy 3 | OK | TESTS | 138 | 186 | 9,625,600 | def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5)+1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n//i)
return divisors
n, k = map(int, input().split())
D = make_divisors(n)
D.sort(reverse=True)
x = k*(k+1)//2
for d in D:
if n//d >= x:
break
else:
print(-1)
exit()
ans = [0]*k
g = d
s = n//d
for i in range(k):
if i != k-1:
ans[i] = (i+1)*g
s -= (i+1)
else:
ans[i] = s*g
print(*ans)
| Title: Maximal GCD
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given positive integer number *n*. You should create such strictly increasing sequence of *k* positive numbers *a*1,<=*a*2,<=...,<=*a**k*, that their sum is equal to *n* and greatest common divisor is maximal.
Greatest common divisor of sequence is maximum of such numbers that every element of sequence is divisible by them.
If there is no possible sequence then output -1.
Input Specification:
The first line consists of two numbers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=1010).
Output Specification:
If the answer exists then output *k* numbers — resulting sequence. Otherwise output -1. If there are multiple answers, print any of them.
Demo Input:
['6 3\n', '8 2\n', '5 3\n']
Demo Output:
['1 2 3\n', '2 6\n', '-1\n']
Note:
none | ```python
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5)+1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n//i)
return divisors
n, k = map(int, input().split())
D = make_divisors(n)
D.sort(reverse=True)
x = k*(k+1)//2
for d in D:
if n//d >= x:
break
else:
print(-1)
exit()
ans = [0]*k
g = d
s = n//d
for i in range(k):
if i != k-1:
ans[i] = (i+1)*g
s -= (i+1)
else:
ans[i] = s*g
print(*ans)
``` | 3 |
|
20 | C | Dijkstra? | PROGRAMMING | 1,900 | [
"graphs",
"shortest paths"
] | C. Dijkstra? | 1 | 64 | You are given a weighted undirected graph. The vertices are enumerated from 1 to *n*. Your task is to find the shortest path between the vertex 1 and the vertex *n*. | The first line contains two integers *n* and *m* (2<=≤<=*n*<=≤<=105,<=0<=≤<=*m*<=≤<=105), where *n* is the number of vertices and *m* is the number of edges. Following *m* lines contain one edge each in form *a**i*, *b**i* and *w**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=1<=≤<=*w**i*<=≤<=106), where *a**i*,<=*b**i* are edge endpoints and *w**i* is the length of the edge.
It is possible that the graph has loops and multiple edges between pair of vertices. | Write the only integer -1 in case of no path. Write the shortest path in opposite case. If there are many solutions, print any of them. | [
"5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1\n",
"5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1\n"
] | [
"1 4 3 5 ",
"1 4 3 5 "
] | none | 1,500 | [
{
"input": "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1",
"output": "1 4 3 5 "
},
{
"input": "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1",
"output": "1 4 3 5 "
},
{
"input": "2 1\n1 2 1",
"output": "1 2 "
},
{
"input": "3 1\n1 2 1",
"output": "-1"
},
{
"input": "3 3\n1 2 1\n1 3 2\n2 3 1",
"output": "1 3 "
},
{
"input": "10 10\n1 5 12\n2 4 140\n2 10 149\n3 6 154\n3 7 9\n3 8 226\n3 10 132\n4 10 55\n5 8 33\n7 8 173",
"output": "1 5 8 7 3 10 "
},
{
"input": "10 10\n1 5 178\n1 8 221\n2 7 92\n2 8 159\n3 5 55\n3 6 179\n3 10 237\n4 8 205\n5 6 191\n8 10 157",
"output": "1 8 10 "
},
{
"input": "10 10\n1 4 200\n1 9 197\n3 4 79\n3 5 213\n3 6 149\n5 8 3\n5 9 189\n6 7 130\n6 9 51\n8 10 135",
"output": "1 9 5 8 10 "
},
{
"input": "10 10\n1 4 201\n2 3 238\n3 4 40\n3 6 231\n3 8 45\n4 5 227\n4 6 58\n4 9 55\n5 7 14\n6 10 242",
"output": "1 4 6 10 "
}
] | 1,644,510,035 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 77 | 102,400 | import collections
import heapq
def find_shortest_path(start, end, graph, parent):
dist = [float('inf')] * (end+1)
dist[start] = 0
pq = []
heapq.heappush(pq, (0, start))
while pq:
du, u = heapq.heappop(pq)
if du > dist[u]: continue
for v, wt in graph[u]:
if du + wt < dist[v]:
dist[v] = du + wt
heapq.heappush(pq, (dist[v], v))
parent[v] = u
n, m = [int(_) for _ in input().split()]
graph = collections.defaultdict(list)
for i in range(m):
u, v, w = [int(_) for _ in input().split()]
graph[u].append((v, w))
graph[v].append((u, w))
parent = [-1]*(n+1)
find_shortest_path(1, n, graph, parent)
path = []
cur = n
while cur != -1:
path.append(cur)
cur = parent[cur]
path.reverse()
for k in path: print(k, end=" ")
| Title: Dijkstra?
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
You are given a weighted undirected graph. The vertices are enumerated from 1 to *n*. Your task is to find the shortest path between the vertex 1 and the vertex *n*.
Input Specification:
The first line contains two integers *n* and *m* (2<=≤<=*n*<=≤<=105,<=0<=≤<=*m*<=≤<=105), where *n* is the number of vertices and *m* is the number of edges. Following *m* lines contain one edge each in form *a**i*, *b**i* and *w**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=1<=≤<=*w**i*<=≤<=106), where *a**i*,<=*b**i* are edge endpoints and *w**i* is the length of the edge.
It is possible that the graph has loops and multiple edges between pair of vertices.
Output Specification:
Write the only integer -1 in case of no path. Write the shortest path in opposite case. If there are many solutions, print any of them.
Demo Input:
['5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1\n', '5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1\n']
Demo Output:
['1 4 3 5 ', '1 4 3 5 ']
Note:
none | ```python
import collections
import heapq
def find_shortest_path(start, end, graph, parent):
dist = [float('inf')] * (end+1)
dist[start] = 0
pq = []
heapq.heappush(pq, (0, start))
while pq:
du, u = heapq.heappop(pq)
if du > dist[u]: continue
for v, wt in graph[u]:
if du + wt < dist[v]:
dist[v] = du + wt
heapq.heappush(pq, (dist[v], v))
parent[v] = u
n, m = [int(_) for _ in input().split()]
graph = collections.defaultdict(list)
for i in range(m):
u, v, w = [int(_) for _ in input().split()]
graph[u].append((v, w))
graph[v].append((u, w))
parent = [-1]*(n+1)
find_shortest_path(1, n, graph, parent)
path = []
cur = n
while cur != -1:
path.append(cur)
cur = parent[cur]
path.reverse()
for k in path: print(k, end=" ")
``` | 0 |
296 | A | Yaroslav and Permutations | PROGRAMMING | 1,100 | [
"greedy",
"math"
] | null | null | Yaroslav has an array that consists of *n* integers. In one second Yaroslav can swap two neighboring array elements. Now Yaroslav is wondering if he can obtain an array where any two neighboring elements would be distinct in a finite time.
Help Yaroslav. | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in the array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000) — the array elements. | In the single line print "YES" (without the quotes) if Yaroslav can obtain the array he needs, and "NO" (without the quotes) otherwise. | [
"1\n1\n",
"3\n1 1 2\n",
"4\n7 7 7 7\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | In the first sample the initial array fits well.
In the second sample Yaroslav can get array: 1, 2, 1. He can swap the last and the second last elements to obtain it.
In the third sample Yarosav can't get the array he needs. | 500 | [
{
"input": "1\n1",
"output": "YES"
},
{
"input": "3\n1 1 2",
"output": "YES"
},
{
"input": "4\n7 7 7 7",
"output": "NO"
},
{
"input": "4\n479 170 465 146",
"output": "YES"
},
{
"input": "5\n996 437 605 996 293",
"output": "YES"
},
{
"input": "6\n727 539 896 668 36 896",
"output": "YES"
},
{
"input": "7\n674 712 674 674 674 674 674",
"output": "NO"
},
{
"input": "8\n742 742 742 742 742 289 742 742",
"output": "NO"
},
{
"input": "9\n730 351 806 806 806 630 85 757 967",
"output": "YES"
},
{
"input": "10\n324 539 83 440 834 640 440 440 440 440",
"output": "YES"
},
{
"input": "7\n925 830 925 98 987 162 356",
"output": "YES"
},
{
"input": "68\n575 32 53 351 151 942 725 967 431 108 192 8 338 458 288 754 384 946 910 210 759 222 589 423 947 507 31 414 169 901 592 763 656 411 360 625 538 549 484 596 42 603 351 292 837 375 21 597 22 349 200 669 485 282 735 54 1000 419 939 901 789 128 468 729 894 649 484 808",
"output": "YES"
},
{
"input": "22\n618 814 515 310 617 936 452 601 250 520 557 799 304 225 9 845 610 990 703 196 486 94",
"output": "YES"
},
{
"input": "44\n459 581 449 449 449 449 449 449 449 623 449 449 449 449 449 449 449 449 889 449 203 273 329 449 449 449 449 449 449 845 882 323 22 449 449 893 449 449 449 449 449 870 449 402",
"output": "NO"
},
{
"input": "90\n424 3 586 183 286 89 427 618 758 833 933 170 155 722 190 977 330 369 693 426 556 435 550 442 513 146 61 719 754 140 424 280 997 688 530 550 438 867 950 194 196 298 417 287 106 489 283 456 735 115 702 317 672 787 264 314 356 186 54 913 809 833 946 314 757 322 559 647 983 482 145 197 223 130 162 536 451 174 467 45 660 293 440 254 25 155 511 746 650 187",
"output": "YES"
},
{
"input": "14\n959 203 478 315 788 788 373 834 488 519 774 764 193 103",
"output": "YES"
},
{
"input": "81\n544 528 528 528 528 4 506 528 32 528 528 528 528 528 528 528 528 975 528 528 528 528 528 528 528 528 528 528 528 528 528 20 528 528 528 528 528 528 528 528 852 528 528 120 528 528 61 11 528 528 528 228 528 165 883 528 488 475 628 528 528 528 528 528 528 597 528 528 528 528 528 528 528 528 528 528 528 412 528 521 925",
"output": "NO"
},
{
"input": "89\n354 356 352 355 355 355 352 354 354 352 355 356 355 352 354 356 354 355 355 354 353 352 352 355 355 356 352 352 353 356 352 353 354 352 355 352 353 353 353 354 353 354 354 353 356 353 353 354 354 354 354 353 352 353 355 356 356 352 356 354 353 352 355 354 356 356 356 354 354 356 354 355 354 355 353 352 354 355 352 355 355 354 356 353 353 352 356 352 353",
"output": "YES"
},
{
"input": "71\n284 284 285 285 285 284 285 284 284 285 284 285 284 284 285 284 285 285 285 285 284 284 285 285 284 284 284 285 284 285 284 285 285 284 284 284 285 284 284 285 285 285 284 284 285 284 285 285 284 285 285 284 285 284 284 284 285 285 284 285 284 285 285 285 285 284 284 285 285 284 285",
"output": "NO"
},
{
"input": "28\n602 216 214 825 814 760 814 28 76 814 814 288 814 814 222 707 11 490 814 543 914 705 814 751 976 814 814 99",
"output": "YES"
},
{
"input": "48\n546 547 914 263 986 945 914 914 509 871 324 914 153 571 914 914 914 528 970 566 544 914 914 914 410 914 914 589 609 222 914 889 691 844 621 68 914 36 914 39 630 749 914 258 945 914 727 26",
"output": "YES"
},
{
"input": "56\n516 76 516 197 516 427 174 516 706 813 94 37 516 815 516 516 937 483 16 516 842 516 638 691 516 635 516 516 453 263 516 516 635 257 125 214 29 81 516 51 362 516 677 516 903 516 949 654 221 924 516 879 516 516 972 516",
"output": "YES"
},
{
"input": "46\n314 723 314 314 314 235 314 314 314 314 270 314 59 972 314 216 816 40 314 314 314 314 314 314 314 381 314 314 314 314 314 314 314 789 314 957 114 942 314 314 29 314 314 72 314 314",
"output": "NO"
},
{
"input": "72\n169 169 169 599 694 81 250 529 865 406 817 169 667 169 965 169 169 663 65 169 903 169 942 763 169 807 169 603 169 169 13 169 169 810 169 291 169 169 169 169 169 169 169 713 169 440 169 169 169 169 169 480 169 169 867 169 169 169 169 169 169 169 169 393 169 169 459 169 99 169 601 800",
"output": "NO"
},
{
"input": "100\n317 316 317 316 317 316 317 316 317 316 316 317 317 316 317 316 316 316 317 316 317 317 316 317 316 316 316 316 316 316 317 316 317 317 317 317 317 317 316 316 316 317 316 317 316 317 316 317 317 316 317 316 317 317 316 317 316 317 316 317 316 316 316 317 317 317 317 317 316 317 317 316 316 316 316 317 317 316 317 316 316 316 316 316 316 317 316 316 317 317 317 317 317 317 317 317 317 316 316 317",
"output": "NO"
},
{
"input": "100\n510 510 510 162 969 32 510 511 510 510 911 183 496 875 903 461 510 510 123 578 510 510 510 510 510 755 510 673 510 510 763 510 510 909 510 435 487 959 807 510 368 788 557 448 284 332 510 949 510 510 777 112 857 926 487 510 510 510 678 510 510 197 829 427 698 704 409 509 510 238 314 851 510 651 510 455 682 510 714 635 973 510 443 878 510 510 510 591 510 24 596 510 43 183 510 510 671 652 214 784",
"output": "YES"
},
{
"input": "100\n476 477 474 476 476 475 473 476 474 475 473 477 476 476 474 476 474 475 476 477 473 473 473 474 474 476 473 473 476 476 475 476 473 474 473 473 477 475 475 475 476 475 477 477 477 476 475 475 475 473 476 477 475 476 477 473 474 477 473 475 476 476 474 477 476 474 473 477 473 475 477 473 476 474 477 473 475 477 473 476 476 475 476 475 474 473 477 473 475 473 477 473 473 474 475 473 477 476 477 474",
"output": "YES"
},
{
"input": "100\n498 498 498 498 498 499 498 499 499 499 498 498 498 498 499 498 499 499 498 499 498 498 498 499 499 499 498 498 499 499 498 498 498 499 498 499 498 498 498 499 498 499 498 498 498 498 499 498 498 499 498 498 499 498 499 499 498 499 499 499 498 498 498 498 499 498 499 498 499 499 499 499 498 498 499 499 498 499 499 498 498 499 499 498 498 499 499 499 498 498 499 498 498 498 499 499 499 498 498 499",
"output": "NO"
},
{
"input": "100\n858 53 816 816 816 816 816 816 816 181 816 816 816 816 579 879 816 948 171 816 816 150 866 816 816 816 897 816 816 816 816 816 816 706 816 539 816 816 816 816 816 816 423 487 816 615 254 816 816 816 816 83 816 816 816 816 816 816 816 816 816 816 816 136 775 999 816 816 816 644 816 816 816 816 927 816 802 816 856 816 816 816 816 816 816 816 816 816 816 700 816 816 816 816 982 477 816 891 806 816",
"output": "NO"
},
{
"input": "100\n167 169 169 167 169 169 167 167 167 167 168 166 170 170 169 170 170 170 169 168 166 167 170 169 167 169 168 169 166 170 166 167 170 166 166 167 169 166 166 169 166 167 168 168 170 167 168 166 168 170 167 168 167 169 169 166 168 167 170 168 167 169 168 169 166 168 168 169 169 166 170 168 167 169 170 168 167 169 168 167 168 168 166 169 170 170 166 166 167 170 167 168 167 167 169 169 166 166 169 167",
"output": "YES"
},
{
"input": "100\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000",
"output": "NO"
},
{
"input": "99\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000",
"output": "NO"
},
{
"input": "100\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "YES"
},
{
"input": "99\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "YES"
},
{
"input": "2\n1 1",
"output": "NO"
},
{
"input": "1\n1000",
"output": "YES"
},
{
"input": "12\n2 2 4 4 4 4 6 6 6 6 6 6",
"output": "YES"
}
] | 1,623,578,381 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 154 | 102,400 | from collections import Counter
n = int(input())
arr = list(map(int, input().split()))
c = Counter(arr)
import math
max_v = -math.inf
for k, v in c.items():
max_v = max(max_v, v)
if max_v <= (n+1)//2:
print('YES')
else:
print('NO')
| Title: Yaroslav and Permutations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Yaroslav has an array that consists of *n* integers. In one second Yaroslav can swap two neighboring array elements. Now Yaroslav is wondering if he can obtain an array where any two neighboring elements would be distinct in a finite time.
Help Yaroslav.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in the array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000) — the array elements.
Output Specification:
In the single line print "YES" (without the quotes) if Yaroslav can obtain the array he needs, and "NO" (without the quotes) otherwise.
Demo Input:
['1\n1\n', '3\n1 1 2\n', '4\n7 7 7 7\n']
Demo Output:
['YES\n', 'YES\n', 'NO\n']
Note:
In the first sample the initial array fits well.
In the second sample Yaroslav can get array: 1, 2, 1. He can swap the last and the second last elements to obtain it.
In the third sample Yarosav can't get the array he needs. | ```python
from collections import Counter
n = int(input())
arr = list(map(int, input().split()))
c = Counter(arr)
import math
max_v = -math.inf
for k, v in c.items():
max_v = max(max_v, v)
if max_v <= (n+1)//2:
print('YES')
else:
print('NO')
``` | 3 |
|
69 | A | Young Physicist | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Young Physicist | 2 | 256 | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces. | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | [
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10\n25 -33 43\n-27 -42 28\n-35 -20 19\n41 -42 -1\n49 -39 -4\n-49 -22 7\n-19 29 41\n8 -27 -43\n8 34 9\n-11 -3 33",
"output": "NO"
},
{
"input": "10\n-6 21 18\n20 -11 -8\n37 -11 41\n-5 8 33\n29 23 32\n30 -33 -11\n39 -49 -36\n28 34 -49\n22 29 -34\n-18 -6 7",
"output": "NO"
},
{
"input": "10\n47 -2 -27\n0 26 -14\n5 -12 33\n2 18 3\n45 -30 -49\n4 -18 8\n-46 -44 -41\n-22 -10 -40\n-35 -21 26\n33 20 38",
"output": "NO"
},
{
"input": "13\n-3 -36 -46\n-11 -50 37\n42 -11 -15\n9 42 44\n-29 -12 24\n3 9 -40\n-35 13 50\n14 43 18\n-13 8 24\n-48 -15 10\n50 9 -50\n21 0 -50\n0 0 -6",
"output": "YES"
},
{
"input": "14\n43 23 17\n4 17 44\n5 -5 -16\n-43 -7 -6\n47 -48 12\n50 47 -45\n2 14 43\n37 -30 15\n4 -17 -11\n17 9 -45\n-50 -3 -8\n-50 0 0\n-50 0 0\n-16 0 0",
"output": "YES"
},
{
"input": "13\n29 49 -11\n38 -11 -20\n25 1 -40\n-11 28 11\n23 -19 1\n45 -41 -17\n-3 0 -19\n-13 -33 49\n-30 0 28\n34 17 45\n-50 9 -27\n-50 0 0\n-37 0 0",
"output": "YES"
},
{
"input": "12\n3 28 -35\n-32 -44 -17\n9 -25 -6\n-42 -22 20\n-19 15 38\n-21 38 48\n-1 -37 -28\n-10 -13 -50\n-5 21 29\n34 28 50\n50 11 -49\n34 0 0",
"output": "YES"
},
{
"input": "37\n-64 -79 26\n-22 59 93\n-5 39 -12\n77 -9 76\n55 -86 57\n83 100 -97\n-70 94 84\n-14 46 -94\n26 72 35\n14 78 -62\n17 82 92\n-57 11 91\n23 15 92\n-80 -1 1\n12 39 18\n-23 -99 -75\n-34 50 19\n-39 84 -7\n45 -30 -39\n-60 49 37\n45 -16 -72\n33 -51 -56\n-48 28 5\n97 91 88\n45 -82 -11\n-21 -15 -90\n-53 73 -26\n-74 85 -90\n-40 23 38\n100 -13 49\n32 -100 -100\n0 -100 -70\n0 -100 0\n0 -100 0\n0 -100 0\n0 -100 0\n0 -37 0",
"output": "YES"
},
{
"input": "4\n68 3 100\n68 21 -100\n-100 -24 0\n-36 0 0",
"output": "YES"
},
{
"input": "33\n-1 -46 -12\n45 -16 -21\n-11 45 -21\n-60 -42 -93\n-22 -45 93\n37 96 85\n-76 26 83\n-4 9 55\n7 -52 -9\n66 8 -85\n-100 -54 11\n-29 59 74\n-24 12 2\n-56 81 85\n-92 69 -52\n-26 -97 91\n54 59 -51\n58 21 -57\n7 68 56\n-47 -20 -51\n-59 77 -13\n-85 27 91\n79 60 -56\n66 -80 5\n21 -99 42\n-31 -29 98\n66 93 76\n-49 45 61\n100 -100 -100\n100 -100 -100\n66 -75 -100\n0 0 -100\n0 0 -87",
"output": "YES"
},
{
"input": "3\n1 2 3\n3 2 1\n0 0 0",
"output": "NO"
},
{
"input": "2\n5 -23 12\n0 0 0",
"output": "NO"
},
{
"input": "1\n0 0 0",
"output": "YES"
},
{
"input": "1\n1 -2 0",
"output": "NO"
},
{
"input": "2\n-23 77 -86\n23 -77 86",
"output": "YES"
},
{
"input": "26\n86 7 20\n-57 -64 39\n-45 6 -93\n-44 -21 100\n-11 -49 21\n73 -71 -80\n-2 -89 56\n-65 -2 7\n5 14 84\n57 41 13\n-12 69 54\n40 -25 27\n-17 -59 0\n64 -91 -30\n-53 9 42\n-54 -8 14\n-35 82 27\n-48 -59 -80\n88 70 79\n94 57 97\n44 63 25\n84 -90 -40\n-100 100 -100\n-92 100 -100\n0 10 -100\n0 0 -82",
"output": "YES"
},
{
"input": "42\n11 27 92\n-18 -56 -57\n1 71 81\n33 -92 30\n82 83 49\n-87 -61 -1\n-49 45 49\n73 26 15\n-22 22 -77\n29 -93 87\n-68 44 -90\n-4 -84 20\n85 67 -6\n-39 26 77\n-28 -64 20\n65 -97 24\n-72 -39 51\n35 -75 -91\n39 -44 -8\n-25 -27 -57\n91 8 -46\n-98 -94 56\n94 -60 59\n-9 -95 18\n-53 -37 98\n-8 -94 -84\n-52 55 60\n15 -14 37\n65 -43 -25\n94 12 66\n-8 -19 -83\n29 81 -78\n-58 57 33\n24 86 -84\n-53 32 -88\n-14 7 3\n89 97 -53\n-5 -28 -91\n-100 100 -6\n-84 100 0\n0 100 0\n0 70 0",
"output": "YES"
},
{
"input": "3\n96 49 -12\n2 -66 28\n-98 17 -16",
"output": "YES"
},
{
"input": "5\n70 -46 86\n-100 94 24\n-27 63 -63\n57 -100 -47\n0 -11 0",
"output": "YES"
},
{
"input": "18\n-86 -28 70\n-31 -89 42\n31 -48 -55\n95 -17 -43\n24 -95 -85\n-21 -14 31\n68 -18 81\n13 31 60\n-15 28 99\n-42 15 9\n28 -61 -62\n-16 71 29\n-28 75 -48\n-77 -67 36\n-100 83 89\n100 100 -100\n57 34 -100\n0 0 -53",
"output": "YES"
},
{
"input": "44\n52 -54 -29\n-82 -5 -94\n-54 43 43\n91 16 71\n7 80 -91\n3 15 29\n-99 -6 -77\n-3 -77 -64\n73 67 34\n25 -10 -18\n-29 91 63\n-72 86 -16\n-68 85 -81\n-3 36 44\n-74 -14 -80\n34 -96 -97\n-76 -78 -33\n-24 44 -58\n98 12 77\n95 -63 -6\n-51 3 -90\n-92 -10 72\n7 3 -68\n57 -53 71\n29 57 -48\n35 -60 10\n79 -70 -61\n-20 77 55\n-86 -15 -35\n84 -88 -18\n100 -42 77\n-20 46 8\n-41 -43 -65\n38 -98 -23\n-100 65 45\n-7 -91 -63\n46 88 -85\n48 59 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 1",
"output": "YES"
},
{
"input": "18\n-14 -64 -91\n-8 -66 -86\n-23 92 -40\n6 -3 -53\n57 41 78\n-79 42 -22\n-88 -17 45\n4 -45 44\n83 -18 -25\n34 86 -92\n75 -30 12\n44 99 11\n-67 -13 72\n22 83 -56\n-37 71 72\n-9 -100 100\n0 -100 31\n0 -58 0",
"output": "YES"
},
{
"input": "23\n-70 37 78\n42 84 6\n28 -94 -24\n-49 76 95\n-67 18 84\n-53 78 -5\n65 -63 -64\n-66 -64 -69\n81 -93 95\n10 52 -79\n-89 -61 -64\n-64 -47 43\n-81 -35 55\n80 82 73\n-60 -81 -18\n49 -10 -19\n-58 70 12\n-24 -15 -93\n98 -93 -54\n-28 -75 11\n100 100 -63\n100 100 0\n56 34 0",
"output": "YES"
},
{
"input": "3\n0 2 -2\n1 -1 3\n-3 0 0",
"output": "NO"
}
] | 1,584,121,670 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 312 | 0 | n=int(input())
l=[]
a,b,c=0,0,0
for i in range(n):
l1=list(map(int,input().split(' ')))
l.append(l1)
for i in range(n):
a+=l[i][0]
b+=l[i][1]
c+=l[i][2]
if(a==0 and b==0 and c==0):
print('YES')
else:
print('NO')
| Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces.
Input Specification:
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100).
Output Specification:
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
Demo Input:
['3\n4 1 7\n-2 4 -1\n1 -5 -3\n', '3\n3 -1 7\n-5 2 -4\n2 -1 -3\n']
Demo Output:
['NO', 'YES']
Note:
none | ```python
n=int(input())
l=[]
a,b,c=0,0,0
for i in range(n):
l1=list(map(int,input().split(' ')))
l.append(l1)
for i in range(n):
a+=l[i][0]
b+=l[i][1]
c+=l[i][2]
if(a==0 and b==0 and c==0):
print('YES')
else:
print('NO')
``` | 3.922 |
61 | A | Ultra-Fast Mathematician | PROGRAMMING | 800 | [
"implementation"
] | A. Ultra-Fast Mathematician | 2 | 256 | Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part.
In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0.
Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length.
Now you are going to take part in Shapur's contest. See if you are faster and more accurate. | There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. | Write one line — the corresponding answer. Do not omit the leading 0s. | [
"1010100\n0100101\n",
"000\n111\n",
"1110\n1010\n",
"01110\n01100\n"
] | [
"1110001\n",
"111\n",
"0100\n",
"00010\n"
] | none | 500 | [
{
"input": "1010100\n0100101",
"output": "1110001"
},
{
"input": "000\n111",
"output": "111"
},
{
"input": "1110\n1010",
"output": "0100"
},
{
"input": "01110\n01100",
"output": "00010"
},
{
"input": "011101\n000001",
"output": "011100"
},
{
"input": "10\n01",
"output": "11"
},
{
"input": "00111111\n11011101",
"output": "11100010"
},
{
"input": "011001100\n101001010",
"output": "110000110"
},
{
"input": "1100100001\n0110101100",
"output": "1010001101"
},
{
"input": "00011101010\n10010100101",
"output": "10001001111"
},
{
"input": "100000101101\n111010100011",
"output": "011010001110"
},
{
"input": "1000001111010\n1101100110001",
"output": "0101101001011"
},
{
"input": "01011111010111\n10001110111010",
"output": "11010001101101"
},
{
"input": "110010000111100\n001100101011010",
"output": "111110101100110"
},
{
"input": "0010010111110000\n0000000011010110",
"output": "0010010100100110"
},
{
"input": "00111110111110000\n01111100001100000",
"output": "01000010110010000"
},
{
"input": "101010101111010001\n001001111101111101",
"output": "100011010010101100"
},
{
"input": "0110010101111100000\n0011000101000000110",
"output": "0101010000111100110"
},
{
"input": "11110100011101010111\n00001000011011000000",
"output": "11111100000110010111"
},
{
"input": "101010101111101101001\n111010010010000011111",
"output": "010000111101101110110"
},
{
"input": "0000111111100011000010\n1110110110110000001010",
"output": "1110001001010011001000"
},
{
"input": "10010010101000110111000\n00101110100110111000111",
"output": "10111100001110001111111"
},
{
"input": "010010010010111100000111\n100100111111100011001110",
"output": "110110101101011111001001"
},
{
"input": "0101110100100111011010010\n0101100011010111001010001",
"output": "0000010111110000010000011"
},
{
"input": "10010010100011110111111011\n10000110101100000001000100",
"output": "00010100001111110110111111"
},
{
"input": "000001111000000100001000000\n011100111101111001110110001",
"output": "011101000101111101111110001"
},
{
"input": "0011110010001001011001011100\n0000101101000011101011001010",
"output": "0011011111001010110010010110"
},
{
"input": "11111000000000010011001101111\n11101110011001010100010000000",
"output": "00010110011001000111011101111"
},
{
"input": "011001110000110100001100101100\n001010000011110000001000101001",
"output": "010011110011000100000100000101"
},
{
"input": "1011111010001100011010110101111\n1011001110010000000101100010101",
"output": "0000110100011100011111010111010"
},
{
"input": "10111000100001000001010110000001\n10111000001100101011011001011000",
"output": "00000000101101101010001111011001"
},
{
"input": "000001010000100001000000011011100\n111111111001010100100001100000111",
"output": "111110101001110101100001111011011"
},
{
"input": "1101000000000010011011101100000110\n1110000001100010011010000011011110",
"output": "0011000001100000000001101111011000"
},
{
"input": "01011011000010100001100100011110001\n01011010111000001010010100001110000",
"output": "00000001111010101011110000010000001"
},
{
"input": "000011111000011001000110111100000100\n011011000110000111101011100111000111",
"output": "011000111110011110101101011011000011"
},
{
"input": "1001000010101110001000000011111110010\n0010001011010111000011101001010110000",
"output": "1011001001111001001011101010101000010"
},
{
"input": "00011101011001100101111111000000010101\n10010011011011001011111000000011101011",
"output": "10001110000010101110000111000011111110"
},
{
"input": "111011100110001001101111110010111001010\n111111101101111001110010000101101000100",
"output": "000100001011110000011101110111010001110"
},
{
"input": "1111001001101000001000000010010101001010\n0010111100111110001011000010111110111001",
"output": "1101110101010110000011000000101011110011"
},
{
"input": "00100101111000000101011111110010100011010\n11101110001010010101001000111110101010100",
"output": "11001011110010010000010111001100001001110"
},
{
"input": "101011001110110100101001000111010101101111\n100111100110101011010100111100111111010110",
"output": "001100101000011111111101111011101010111001"
},
{
"input": "1111100001100101000111101001001010011100001\n1000110011000011110010001011001110001000001",
"output": "0111010010100110110101100010000100010100000"
},
{
"input": "01100111011111010101000001101110000001110101\n10011001011111110000000101011001001101101100",
"output": "11111110000000100101000100110111001100011001"
},
{
"input": "110010100111000100100101100000011100000011001\n011001111011100110000110111001110110100111011",
"output": "101011011100100010100011011001101010100100010"
},
{
"input": "0001100111111011010110100100111000000111000110\n1100101011000000000001010010010111001100110001",
"output": "1101001100111011010111110110101111001011110111"
},
{
"input": "00000101110110110001110010100001110100000100000\n10010000110011110001101000111111101010011010001",
"output": "10010101000101000000011010011110011110011110001"
},
{
"input": "110000100101011100100011001111110011111110010001\n101011111001011100110110111101110011010110101100",
"output": "011011011100000000010101110010000000101000111101"
},
{
"input": "0101111101011111010101011101000011101100000000111\n0000101010110110001110101011011110111001010100100",
"output": "0101010111101001011011110110011101010101010100011"
},
{
"input": "11000100010101110011101000011111001010110111111100\n00001111000111001011111110000010101110111001000011",
"output": "11001011010010111000010110011101100100001110111111"
},
{
"input": "101000001101111101101111111000001110110010101101010\n010011100111100001100000010001100101000000111011011",
"output": "111011101010011100001111101001101011110010010110001"
},
{
"input": "0011111110010001010100010110111000110011001101010100\n0111000000100010101010000100101000000100101000111001",
"output": "0100111110110011111110010010010000110111100101101101"
},
{
"input": "11101010000110000011011010000001111101000111011111100\n10110011110001010100010110010010101001010111100100100",
"output": "01011001110111010111001100010011010100010000111011000"
},
{
"input": "011000100001000001101000010110100110011110100111111011\n111011001000001001110011001111011110111110110011011111",
"output": "100011101001001000011011011001111000100000010100100100"
},
{
"input": "0111010110010100000110111011010110100000000111110110000\n1011100100010001101100000100111111101001110010000100110",
"output": "1100110010000101101010111111101001001001110101110010110"
},
{
"input": "10101000100111000111010001011011011011110100110101100011\n11101111000000001100100011111000100100000110011001101110",
"output": "01000111100111001011110010100011111111110010101100001101"
},
{
"input": "000000111001010001000000110001001011100010011101010011011\n110001101000010010000101000100001111101001100100001010010",
"output": "110001010001000011000101110101000100001011111001011001001"
},
{
"input": "0101011100111010000111110010101101111111000000111100011100\n1011111110000010101110111001000011100000100111111111000111",
"output": "1110100010111000101001001011101110011111100111000011011011"
},
{
"input": "11001000001100100111100111100100101011000101001111001001101\n10111110100010000011010100110100100011101001100000001110110",
"output": "01110110101110100100110011010000001000101100101111000111011"
},
{
"input": "010111011011101000000110000110100110001110100001110110111011\n101011110011101011101101011111010100100001100111100100111011",
"output": "111100101000000011101011011001110010101111000110010010000000"
},
{
"input": "1001011110110110000100011001010110000100011010010111010101110\n1101111100001000010111110011010101111010010100000001000010111",
"output": "0100100010111110010011101010000011111110001110010110010111001"
},
{
"input": "10000010101111100111110101111000010100110111101101111111111010\n10110110101100101010011001011010100110111011101100011001100111",
"output": "00110100000011001101101100100010110010001100000001100110011101"
},
{
"input": "011111010011111000001010101001101001000010100010111110010100001\n011111001011000011111001000001111001010110001010111101000010011",
"output": "000000011000111011110011101000010000010100101000000011010110010"
},
{
"input": "1111000000110001011101000100100100001111011100001111001100011111\n1101100110000101100001100000001001011011111011010101000101001010",
"output": "0010100110110100111100100100101101010100100111011010001001010101"
},
{
"input": "01100000101010010011001110100110110010000110010011011001100100011\n10110110010110111100100111000111000110010000000101101110000010111",
"output": "11010110111100101111101001100001110100010110010110110111100110100"
},
{
"input": "001111111010000100001100001010011001111110011110010111110001100111\n110000101001011000100010101100100110000111100000001101001110010111",
"output": "111111010011011100101110100110111111111001111110011010111111110000"
},
{
"input": "1011101011101101011110101101011101011000010011100101010101000100110\n0001000001001111010111100100111101100000000001110001000110000000110",
"output": "1010101010100010001001001001100000111000010010010100010011000100000"
},
{
"input": "01000001011001010011011100010000100100110101111011011011110000001110\n01011110000110011011000000000011000111100001010000000011111001110000",
"output": "00011111011111001000011100010011100011010100101011011000001001111110"
},
{
"input": "110101010100110101000001111110110100010010000100111110010100110011100\n111010010111111011100110101011001011001110110111110100000110110100111",
"output": "001111000011001110100111010101111111011100110011001010010010000111011"
},
{
"input": "1001101011000001011111100110010010000011010001001111011100010100110001\n1111100111110101001111010001010000011001001001010110001111000000100101",
"output": "0110001100110100010000110111000010011010011000011001010011010100010100"
},
{
"input": "00000111110010110001110110001010010101000111011001111111100110011110010\n00010111110100000100110101000010010001100001100011100000001100010100010",
"output": "00010000000110110101000011001000000100100110111010011111101010001010000"
},
{
"input": "100101011100101101000011010001011001101110101110001100010001010111001110\n100001111100101011011111110000001111000111001011111110000010101110111001",
"output": "000100100000000110011100100001010110101001100101110010010011111001110111"
},
{
"input": "1101100001000111001101001011101000111000011110000001001101101001111011010\n0101011101010100011011010110101000010010110010011110101100000110110001000",
"output": "1000111100010011010110011101000000101010101100011111100001101111001010010"
},
{
"input": "01101101010011110101100001110101111011100010000010001101111000011110111111\n00101111001101001100111010000101110000100101101111100111101110010100011011",
"output": "01000010011110111001011011110000001011000111101101101010010110001010100100"
},
{
"input": "101100101100011001101111110110110010100110110010100001110010110011001101011\n000001011010101011110011111101001110000111000010001101000010010000010001101",
"output": "101101110110110010011100001011111100100001110000101100110000100011011100110"
},
{
"input": "0010001011001010001100000010010011110110011000100000000100110000101111001110\n1100110100111000110100001110111001011101001100001010100001010011100110110001",
"output": "1110111111110010111000001100101010101011010100101010100101100011001001111111"
},
{
"input": "00101101010000000101011001101011001100010001100000101011101110000001111001000\n10010110010111000000101101000011101011001010000011011101101011010000000011111",
"output": "10111011000111000101110100101000100111011011100011110110000101010001111010111"
},
{
"input": "111100000100100000101001100001001111001010001000001000000111010000010101101011\n001000100010100101111011111011010110101100001111011000010011011011100010010110",
"output": "110100100110000101010010011010011001100110000111010000010100001011110111111101"
},
{
"input": "0110001101100100001111110101101000100101010010101010011001101001001101110000000\n0111011000000010010111011110010000000001000110001000011001101000000001110100111",
"output": "0001010101100110011000101011111000100100010100100010000000000001001100000100111"
},
{
"input": "10001111111001000101001011110101111010100001011010101100111001010001010010001000\n10000111010010011110111000111010101100000011110001101111001000111010100000000001",
"output": "00001000101011011011110011001111010110100010101011000011110001101011110010001001"
},
{
"input": "100110001110110000100101001110000011110110000110000000100011110100110110011001101\n110001110101110000000100101001101011111100100100001001000110000001111100011110110",
"output": "010111111011000000100001100111101000001010100010001001100101110101001010000111011"
},
{
"input": "0000010100100000010110111100011111111010011101000000100000011001001101101100111010\n0100111110011101010110101011110110010111001111000110101100101110111100101000111111",
"output": "0100101010111101000000010111101001101101010010000110001100110111110001000100000101"
},
{
"input": "11000111001010100001110000001001011010010010110000001110100101000001010101100110111\n11001100100100100001101010110100000111100011101110011010110100001001000011011011010",
"output": "00001011101110000000011010111101011101110001011110010100010001001000010110111101101"
},
{
"input": "010110100010001000100010101001101010011010111110100001000100101000111011100010100001\n110000011111101101010011111000101010111010100001001100001001100101000000111000000000",
"output": "100110111101100101110001010001000000100000011111101101001101001101111011011010100001"
},
{
"input": "0000011110101110010101110110110101100001011001101010101001000010000010000000101001101\n1100111111011100000110000111101110011111100111110001011001000010011111100001001100011",
"output": "1100100001110010010011110001011011111110111110011011110000000000011101100001100101110"
},
{
"input": "10100000101101110001100010010010100101100011010010101000110011100000101010110010000000\n10001110011011010010111011011101101111000111110000111000011010010101001100000001010011",
"output": "00101110110110100011011001001111001010100100100010010000101001110101100110110011010011"
},
{
"input": "001110000011111101101010011111000101010111010100001001100001001100101000000111000000000\n111010000000000000101001110011001000111011001100101010011001000011101001001011110000011",
"output": "110100000011111101000011101100001101101100011000100011111000001111000001001100110000011"
},
{
"input": "1110111100111011010101011011001110001010010010110011110010011111000010011111010101100001\n1001010101011001001010100010101100000110111101011000100010101111111010111100001110010010",
"output": "0111101001100010011111111001100010001100101111101011010000110000111000100011011011110011"
},
{
"input": "11100010001100010011001100001100010011010001101110011110100101110010101101011101000111111\n01110000000110111010110100001010000101011110100101010011000110101110101101110111011110001",
"output": "10010010001010101001111000000110010110001111001011001101100011011100000000101010011001110"
},
{
"input": "001101011001100101101100110000111000101011001001100100000100101000100000110100010111111101\n101001111110000010111101111110001001111001111101111010000110111000100100110010010001011111",
"output": "100100100111100111010001001110110001010010110100011110000010010000000100000110000110100010"
},
{
"input": "1010110110010101000110010010110101011101010100011001101011000110000000100011100100011000000\n0011011111100010001111101101000111001011101110100000110111100100101111010110101111011100011",
"output": "1001101001110111001001111111110010010110111010111001011100100010101111110101001011000100011"
},
{
"input": "10010010000111010111011111110010100101100000001100011100111011100010000010010001011100001100\n00111010100010110010000100010111010001111110100100100011101000101111111111001101101100100100",
"output": "10101000100101100101011011100101110100011110101000111111010011001101111101011100110000101000"
},
{
"input": "010101110001010101100000010111010000000111110011001101100011001000000011001111110000000010100\n010010111011100101010101111110110000000111000100001101101001001000001100101110001010000100001",
"output": "000111001010110000110101101001100000000000110111000000001010000000001111100001111010000110101"
},
{
"input": "1100111110011001000111101001001011000110011010111111100010111111001100111111011101100111101011\n1100000011001000110100110111000001011001010111101000010010100011000001100100111101101000010110",
"output": "0000111101010001110011011110001010011111001101010111110000011100001101011011100000001111111101"
},
{
"input": "00011000100100110111100101100100000000010011110111110010101110110011100001010111010011110100101\n00011011111011111011100101100111100101001110010111000010000111000100100100000001110101111011011",
"output": "00000011011111001100000000000011100101011101100000110000101001110111000101010110100110001111110"
},
{
"input": "000101011001001100000111100010110101111011110101111101000110001101011010111110110011100100000001\n011000101010011111011000111000100000000011011000000001111110001000001111101010110000011100001111",
"output": "011101110011010011011111011010010101111000101101111100111000000101010101010100000011111000001110"
},
{
"input": "1000101001011010000100100100010010011101011001110101111011101111111110010101001101010001010101001\n0110110010011100011111011111110111000000010001110100001010111110101011010011111011111110000110000",
"output": "1110011011000110011011111011100101011101001000000001110001010001010101000110110110101111010011001"
},
{
"input": "01111010010101100111110111111011011010100001011101010000111100101101101110111011001100101011100111\n00001100110110100001111011000010001001001100000010111101000001111011100000010111010010000011000010",
"output": "01110110100011000110001100111001010011101101011111101101111101010110001110101100011110101000100101"
},
{
"input": "111101011101111000001011001101111010110111001101110100100011111011011101001101010101011010111000110\n101111100101101101001100110011000001111010011101110111110110101110011011110011111100001001110101101",
"output": "010010111000010101000111111110111011001101010000000011010101010101000110111110101001010011001101011"
},
{
"input": "1010000011010110011101001101110001110010000111011101110010110110111111001001110100101100010101010001\n0111101000111100101100000101111010100100001000011101010100110011100011010011010101000100101011100011",
"output": "1101101011101010110001001000001011010110001111000000100110000101011100011010100001101000111110110010"
},
{
"input": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001\n1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111010",
"output": "1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111011"
},
{
"input": "0\n0",
"output": "0"
},
{
"input": "0\n1",
"output": "1"
}
] | 1,662,462,773 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | n=input()
m=input()
p=len(n)
for i in range(p):
if m[i] == '1' and n[i] == '1':
print('0',end='')
else:
print('1',end='') | Title: Ultra-Fast Mathematician
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part.
In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0.
Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length.
Now you are going to take part in Shapur's contest. See if you are faster and more accurate.
Input Specification:
There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100.
Output Specification:
Write one line — the corresponding answer. Do not omit the leading 0s.
Demo Input:
['1010100\n0100101\n', '000\n111\n', '1110\n1010\n', '01110\n01100\n']
Demo Output:
['1110001\n', '111\n', '0100\n', '00010\n']
Note:
none | ```python
n=input()
m=input()
p=len(n)
for i in range(p):
if m[i] == '1' and n[i] == '1':
print('0',end='')
else:
print('1',end='')
``` | 0 |
380 | C | Sereja and Brackets | PROGRAMMING | 2,000 | [
"data structures",
"schedules"
] | null | null | Sereja has a bracket sequence *s*1,<=*s*2,<=...,<=*s**n*, or, in other words, a string *s* of length *n*, consisting of characters "(" and ")".
Sereja needs to answer *m* queries, each of them is described by two integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). The answer to the *i*-th query is the length of the maximum correct bracket subsequence of sequence *s**l**i*,<=*s**l**i*<=+<=1,<=...,<=*s**r**i*. Help Sereja answer all queries.
You can find the definitions for a subsequence and a correct bracket sequence in the notes. | The first line contains a sequence of characters *s*1,<=*s*2,<=...,<=*s**n* (1<=≤<=*n*<=≤<=106) without any spaces. Each character is either a "(" or a ")". The second line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. Each of the next *m* lines contains a pair of integers. The *i*-th line contains integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*) — the description of the *i*-th query. | Print the answer to each question on a single line. Print the answers in the order they go in the input. | [
"())(())(())(\n7\n1 1\n2 3\n1 2\n1 12\n8 12\n5 11\n2 10\n"
] | [
"0\n0\n2\n10\n4\n6\n6\n"
] | A subsequence of length |*x*| of string *s* = *s*<sub class="lower-index">1</sub>*s*<sub class="lower-index">2</sub>... *s*<sub class="lower-index">|*s*|</sub> (where |*s*| is the length of string *s*) is string *x* = *s*<sub class="lower-index">*k*<sub class="lower-index">1</sub></sub>*s*<sub class="lower-index">*k*<sub class="lower-index">2</sub></sub>... *s*<sub class="lower-index">*k*<sub class="lower-index">|*x*|</sub></sub> (1 ≤ *k*<sub class="lower-index">1</sub> < *k*<sub class="lower-index">2</sub> < ... < *k*<sub class="lower-index">|*x*|</sub> ≤ |*s*|).
A correct bracket sequence is a bracket sequence that can be transformed into a correct aryphmetic expression by inserting characters "1" and "+" between the characters of the string. For example, bracket sequences "()()", "(())" are correct (the resulting expressions "(1)+(1)", "((1+1)+1)"), and ")(" and "(" are not.
For the third query required sequence will be «()».
For the fourth query required sequence will be «()(())(())». | 1,500 | [
{
"input": "())(())(())(\n7\n1 1\n2 3\n1 2\n1 12\n8 12\n5 11\n2 10",
"output": "0\n0\n2\n10\n4\n6\n6"
},
{
"input": "(((((()((((((((((()((()(((((\n1\n8 15",
"output": "0"
},
{
"input": "((()((())(((((((((()(()(()(((((((((((((((()(()((((((((((((((()(((((((((((((((((((()(((\n39\n28 56\n39 46\n57 63\n29 48\n51 75\n14 72\n5 70\n51 73\n10 64\n31 56\n50 54\n15 78\n78 82\n1 11\n1 70\n1 19\n10 22\n13 36\n3 10\n34 40\n51 76\n64 71\n36 75\n24 71\n1 63\n5 14\n46 67\n32 56\n39 43\n43 56\n61 82\n2 78\n1 21\n10 72\n49 79\n12 14\n53 79\n15 31\n7 47",
"output": "4\n4\n2\n4\n2\n12\n16\n2\n12\n4\n0\n12\n0\n6\n18\n6\n2\n6\n6\n0\n2\n0\n6\n8\n18\n4\n2\n4\n2\n2\n2\n18\n8\n12\n2\n0\n2\n6\n12"
},
{
"input": "))(()))))())())))))())((()()))))()))))))))))))\n9\n26 42\n21 22\n6 22\n7 26\n43 46\n25 27\n32 39\n22 40\n2 45",
"output": "4\n0\n6\n8\n0\n2\n2\n10\n20"
},
{
"input": "(()((((()(())((((((((()((((((()((((\n71\n15 29\n17 18\n5 26\n7 10\n16 31\n26 35\n2 30\n16 24\n2 24\n7 12\n15 18\n12 13\n25 30\n1 30\n12 13\n16 20\n6 35\n20 28\n18 23\n9 31\n12 35\n14 17\n8 16\n3 10\n12 33\n7 19\n2 33\n7 17\n21 27\n10 30\n29 32\n9 28\n18 32\n28 31\n31 33\n4 26\n15 27\n10 17\n8 14\n11 28\n8 23\n17 33\n4 14\n3 6\n6 34\n19 23\n4 21\n16 27\n14 27\n6 19\n31 32\n29 32\n9 17\n1 21\n2 31\n18 29\n16 26\n15 18\n4 5\n13 20\n9 28\n18 30\n1 32\n2 9\n16 24\n1 20\n4 15\n16 23\n19 34\n5 22\n5 23",
"output": "2\n0\n8\n2\n4\n2\n10\n2\n10\n4\n0\n0\n0\n10\n0\n0\n10\n2\n2\n8\n4\n0\n6\n2\n4\n6\n12\n6\n2\n6\n2\n6\n4\n2\n0\n8\n2\n4\n6\n4\n8\n4\n6\n0\n10\n2\n6\n2\n2\n6\n0\n2\n4\n8\n12\n2\n2\n0\n0\n0\n6\n2\n12\n4\n2\n8\n6\n2\n4\n6\n8"
},
{
"input": "(((())((((()()((((((()((()(((((((((((()((\n6\n20 37\n28 32\n12 18\n7 25\n21 33\n4 5",
"output": "4\n0\n2\n6\n4\n2"
},
{
"input": "(((()((((()()()(()))((((()(((()))()((((()))()((())\n24\n37 41\n13 38\n31 34\n14 16\n29 29\n12 46\n1 26\n15 34\n8 47\n11 23\n6 32\n2 22\n9 27\n17 40\n6 15\n4 49\n12 33\n3 48\n22 47\n19 48\n10 27\n23 25\n4 44\n27 48",
"output": "2\n16\n0\n2\n0\n26\n16\n12\n30\n8\n18\n14\n14\n12\n6\n34\n16\n32\n18\n18\n12\n0\n30\n16"
},
{
"input": ")()((((((((((((((((()(((()()(()((((((()(((((((()()))((((())(((((((((()(((((((((\n51\n29 53\n31 69\n54 59\n3 52\n26 46\n14 62\n6 54\n39 56\n17 27\n46 74\n60 72\n18 26\n38 46\n4 27\n22 52\n44 49\n42 77\n2 20\n39 57\n61 70\n33 54\n10 30\n67 70\n46 66\n17 77\n5 52\n33 77\n26 32\n1 72\n40 78\n38 68\n19 47\n30 53\n19 29\n52 71\n1 11\n22 53\n17 42\n2 51\n4 12\n24 76\n22 34\n21 69\n11 69\n36 52\n17 31\n57 58\n54 62\n23 71\n5 46\n51 53",
"output": "12\n14\n4\n18\n6\n22\n18\n8\n4\n12\n2\n4\n2\n4\n16\n2\n14\n2\n8\n2\n10\n6\n2\n10\n24\n18\n16\n4\n26\n14\n14\n10\n12\n6\n6\n2\n16\n10\n18\n0\n22\n6\n20\n22\n10\n8\n2\n4\n22\n10\n0"
},
{
"input": "(\n1\n1 1",
"output": "0"
},
{
"input": ")\n1\n1 1",
"output": "0"
},
{
"input": "()\n1\n1 2",
"output": "2"
},
{
"input": ")(\n1\n1 2",
"output": "0"
}
] | 1,699,741,239 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | s = input()
n = len(s)
# Initialize an array to store the balance at each position
balance = [0] * (n + 1)
# Precompute the balance array
for i in range(1, n + 1):
balance[i] = balance[i - 1] + (1 if s[i - 1] == '(' else -1)
# Process each query
for _ in range(int(input())):
l, r = map(int, input().split())
# Calculate the balance at the end of the subsequence
end_balance = balance[r] - balance[l - 1]
# Calculate the length of the maximum correct bracket subsequence
result = 2 * min(balance[l - 1], balance[r]) + end_balance
print(result)
| Title: Sereja and Brackets
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja has a bracket sequence *s*1,<=*s*2,<=...,<=*s**n*, or, in other words, a string *s* of length *n*, consisting of characters "(" and ")".
Sereja needs to answer *m* queries, each of them is described by two integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). The answer to the *i*-th query is the length of the maximum correct bracket subsequence of sequence *s**l**i*,<=*s**l**i*<=+<=1,<=...,<=*s**r**i*. Help Sereja answer all queries.
You can find the definitions for a subsequence and a correct bracket sequence in the notes.
Input Specification:
The first line contains a sequence of characters *s*1,<=*s*2,<=...,<=*s**n* (1<=≤<=*n*<=≤<=106) without any spaces. Each character is either a "(" or a ")". The second line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. Each of the next *m* lines contains a pair of integers. The *i*-th line contains integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*) — the description of the *i*-th query.
Output Specification:
Print the answer to each question on a single line. Print the answers in the order they go in the input.
Demo Input:
['())(())(())(\n7\n1 1\n2 3\n1 2\n1 12\n8 12\n5 11\n2 10\n']
Demo Output:
['0\n0\n2\n10\n4\n6\n6\n']
Note:
A subsequence of length |*x*| of string *s* = *s*<sub class="lower-index">1</sub>*s*<sub class="lower-index">2</sub>... *s*<sub class="lower-index">|*s*|</sub> (where |*s*| is the length of string *s*) is string *x* = *s*<sub class="lower-index">*k*<sub class="lower-index">1</sub></sub>*s*<sub class="lower-index">*k*<sub class="lower-index">2</sub></sub>... *s*<sub class="lower-index">*k*<sub class="lower-index">|*x*|</sub></sub> (1 ≤ *k*<sub class="lower-index">1</sub> < *k*<sub class="lower-index">2</sub> < ... < *k*<sub class="lower-index">|*x*|</sub> ≤ |*s*|).
A correct bracket sequence is a bracket sequence that can be transformed into a correct aryphmetic expression by inserting characters "1" and "+" between the characters of the string. For example, bracket sequences "()()", "(())" are correct (the resulting expressions "(1)+(1)", "((1+1)+1)"), and ")(" and "(" are not.
For the third query required sequence will be «()».
For the fourth query required sequence will be «()(())(())». | ```python
s = input()
n = len(s)
# Initialize an array to store the balance at each position
balance = [0] * (n + 1)
# Precompute the balance array
for i in range(1, n + 1):
balance[i] = balance[i - 1] + (1 if s[i - 1] == '(' else -1)
# Process each query
for _ in range(int(input())):
l, r = map(int, input().split())
# Calculate the balance at the end of the subsequence
end_balance = balance[r] - balance[l - 1]
# Calculate the length of the maximum correct bracket subsequence
result = 2 * min(balance[l - 1], balance[r]) + end_balance
print(result)
``` | 0 |
|
955 | A | Feed the cat | PROGRAMMING | 1,100 | [
"greedy",
"math"
] | null | null | After waking up at *hh*:*mm*, Andrew realised that he had forgotten to feed his only cat for yet another time (guess why there's only one cat). The cat's current hunger level is *H* points, moreover each minute without food increases his hunger by *D* points.
At any time Andrew can visit the store where tasty buns are sold (you can assume that is doesn't take time to get to the store and back). One such bun costs *C* roubles and decreases hunger by *N* points. Since the demand for bakery drops heavily in the evening, there is a special 20% discount for buns starting from 20:00 (note that the cost might become rational). Of course, buns cannot be sold by parts.
Determine the minimum amount of money Andrew has to spend in order to feed his cat. The cat is considered fed if its hunger level is less than or equal to zero. | The first line contains two integers *hh* and *mm* (00<=≤<=*hh*<=≤<=23,<=00<=≤<=*mm*<=≤<=59) — the time of Andrew's awakening.
The second line contains four integers *H*, *D*, *C* and *N* (1<=≤<=*H*<=≤<=105,<=1<=≤<=*D*,<=*C*,<=*N*<=≤<=102). | Output the minimum amount of money to within three decimal digits. You answer is considered correct, if its absolute or relative error does not exceed 10<=-<=4.
Formally, let your answer be *a*, and the jury's answer be *b*. Your answer is considered correct if . | [
"19 00\n255 1 100 1\n",
"17 41\n1000 6 15 11\n"
] | [
"25200.0000\n",
"1365.0000\n"
] | In the first sample Andrew can visit the store at exactly 20:00. The cat's hunger will be equal to 315, hence it will be necessary to purchase 315 buns. The discount makes the final answer 25200 roubles.
In the second sample it's optimal to visit the store right after he wakes up. Then he'll have to buy 91 bins per 15 roubles each and spend a total of 1365 roubles. | 500 | [
{
"input": "19 00\n255 1 100 1",
"output": "25200.0000"
},
{
"input": "17 41\n1000 6 15 11",
"output": "1365.0000"
},
{
"input": "16 34\n61066 14 50 59",
"output": "43360.0000"
},
{
"input": "18 18\n23331 86 87 41",
"output": "49590.0000"
},
{
"input": "10 48\n68438 8 18 29",
"output": "36187.2000"
},
{
"input": "08 05\n63677 9 83 25",
"output": "186252.0000"
},
{
"input": "00 00\n100000 100 100 100",
"output": "100000.0000"
},
{
"input": "20 55\n100000 100 100 100",
"output": "80000.0000"
},
{
"input": "23 59\n100000 100 100 100",
"output": "80000.0000"
},
{
"input": "00 00\n1 100 100 100",
"output": "100.0000"
},
{
"input": "21 26\n33193 54 97 66",
"output": "39032.8000"
},
{
"input": "20 45\n33756 24 21 1",
"output": "567100.8000"
},
{
"input": "14 33\n92062 59 89 72",
"output": "110146.4000"
},
{
"input": "01 24\n92730 5 35 29",
"output": "94920.0000"
},
{
"input": "20 58\n93398 43 86 99",
"output": "64947.2000"
},
{
"input": "23 04\n37170 81 32 64",
"output": "14873.6000"
},
{
"input": "01 38\n70542 27 74 26",
"output": "200836.0000"
},
{
"input": "04 28\n38505 65 25 95",
"output": "10150.0000"
},
{
"input": "00 10\n33077 21 40 22",
"output": "60160.0000"
},
{
"input": "10 44\n66449 67 90 83",
"output": "72090.0000"
},
{
"input": "05 51\n10220 5 33 48",
"output": "7029.0000"
},
{
"input": "20 19\n68886 28 48 94",
"output": "28147.2000"
},
{
"input": "01 49\n11621 55 78 46",
"output": "19734.0000"
},
{
"input": "21 28\n78549 91 4 98",
"output": "2566.4000"
},
{
"input": "18 06\n88580 22 35 59",
"output": "43232.0000"
},
{
"input": "22 28\n55507 53 61 11",
"output": "246293.6000"
},
{
"input": "18 58\n22434 84 91 59",
"output": "34143.2000"
},
{
"input": "15 36\n32466 27 22 15",
"output": "46464.0000"
},
{
"input": "17 31\n9603 53 73 74",
"output": "9490.0000"
},
{
"input": "14 53\n76530 92 4 22",
"output": "13916.0000"
},
{
"input": "18 31\n10753 23 30 74",
"output": "4152.0000"
},
{
"input": "17 43\n16290 46 90 94",
"output": "15660.0000"
},
{
"input": "18 38\n3652 11 53 94",
"output": "2067.0000"
},
{
"input": "19 57\n3 4 7 6",
"output": "7.0000"
}
] | 1,693,586,487 | 387 | PyPy 3 | WRONG_ANSWER | TESTS | 7 | 92 | 0 | import sys
input = sys.stdin.buffer.readline
def process(hh, mm, H, D, C, N):
T = 60*int(hh)+int(mm)
H1, C1 = H, C
H2, C2 = H+(20*60-T)*D, 0.8*C
answer = float('inf')
for H3, C3 in [[H1, C1], [H2, C2]]:
if H3 % N==0:
Need = H3//N
else:
Need = H3//N+1
entry = Need*C3
answer = min(answer, entry)
sys.stdout.write(f'{answer}\n')
hh, mm = input().decode().strip().split()
H, D, C, N = [int(x) for x in input().split()]
process(hh, mm, H, D, C, N) | Title: Feed the cat
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After waking up at *hh*:*mm*, Andrew realised that he had forgotten to feed his only cat for yet another time (guess why there's only one cat). The cat's current hunger level is *H* points, moreover each minute without food increases his hunger by *D* points.
At any time Andrew can visit the store where tasty buns are sold (you can assume that is doesn't take time to get to the store and back). One such bun costs *C* roubles and decreases hunger by *N* points. Since the demand for bakery drops heavily in the evening, there is a special 20% discount for buns starting from 20:00 (note that the cost might become rational). Of course, buns cannot be sold by parts.
Determine the minimum amount of money Andrew has to spend in order to feed his cat. The cat is considered fed if its hunger level is less than or equal to zero.
Input Specification:
The first line contains two integers *hh* and *mm* (00<=≤<=*hh*<=≤<=23,<=00<=≤<=*mm*<=≤<=59) — the time of Andrew's awakening.
The second line contains four integers *H*, *D*, *C* and *N* (1<=≤<=*H*<=≤<=105,<=1<=≤<=*D*,<=*C*,<=*N*<=≤<=102).
Output Specification:
Output the minimum amount of money to within three decimal digits. You answer is considered correct, if its absolute or relative error does not exceed 10<=-<=4.
Formally, let your answer be *a*, and the jury's answer be *b*. Your answer is considered correct if .
Demo Input:
['19 00\n255 1 100 1\n', '17 41\n1000 6 15 11\n']
Demo Output:
['25200.0000\n', '1365.0000\n']
Note:
In the first sample Andrew can visit the store at exactly 20:00. The cat's hunger will be equal to 315, hence it will be necessary to purchase 315 buns. The discount makes the final answer 25200 roubles.
In the second sample it's optimal to visit the store right after he wakes up. Then he'll have to buy 91 bins per 15 roubles each and spend a total of 1365 roubles. | ```python
import sys
input = sys.stdin.buffer.readline
def process(hh, mm, H, D, C, N):
T = 60*int(hh)+int(mm)
H1, C1 = H, C
H2, C2 = H+(20*60-T)*D, 0.8*C
answer = float('inf')
for H3, C3 in [[H1, C1], [H2, C2]]:
if H3 % N==0:
Need = H3//N
else:
Need = H3//N+1
entry = Need*C3
answer = min(answer, entry)
sys.stdout.write(f'{answer}\n')
hh, mm = input().decode().strip().split()
H, D, C, N = [int(x) for x in input().split()]
process(hh, mm, H, D, C, N)
``` | 0 |
|
523 | A | Rotate, Flip and Zoom | PROGRAMMING | 1,200 | [
"*special",
"implementation"
] | null | null | Polycarp is writing the prototype of a graphic editor. He has already made up his mind that the basic image transformations in his editor will be: rotate the image 90 degrees clockwise, flip the image horizontally (symmetry relative to the vertical line, that is, the right part of the image moves to the left, and vice versa) and zooming on the image. He is sure that that there is a large number of transformations that can be expressed through these three.
He has recently stopped implementing all three transformations for monochrome images. To test this feature, he asked you to write a code that will consecutively perform three actions with a monochrome image: first it will rotate the image 90 degrees clockwise, then it will flip the image horizontally and finally, it will zoom in twice on the image (that is, it will double all the linear sizes).
Implement this feature to help Polycarp test his editor. | The first line contains two integers, *w* and *h* (1<=≤<=*w*,<=*h*<=≤<=100) — the width and height of an image in pixels. The picture is given in *h* lines, each line contains *w* characters — each character encodes the color of the corresponding pixel of the image. The line consists only of characters "." and "*", as the image is monochrome. | Print 2*w* lines, each containing 2*h* characters — the result of consecutive implementing of the three transformations, described above. | [
"3 2\n.*.\n.*.\n",
"9 20\n**.......\n****.....\n******...\n*******..\n..******.\n....****.\n......***\n*.....***\n*********\n*********\n*********\n*********\n....**...\n...****..\n..******.\n.********\n****..***\n***...***\n**.....**\n*.......*\n"
] | [
"....\n....\n****\n****\n....\n....\n",
"********......**********........********\n********......**********........********\n********........********......********..\n********........********......********..\n..********......********....********....\n..********......********....********....\n..********......********..********......\n..********......********..********......\n....********....****************........\n....********....****************........\n....********....****************........\n....********....****************........\n......******************..**********....\n......******************..**********....\n........****************....**********..\n........****************....**********..\n............************......**********\n............************......**********\n"
] | none | 500 | [
{
"input": "3 2\n.*.\n.*.",
"output": "....\n....\n****\n****\n....\n...."
},
{
"input": "9 20\n**.......\n****.....\n******...\n*******..\n..******.\n....****.\n......***\n*.....***\n*********\n*********\n*********\n*********\n....**...\n...****..\n..******.\n.********\n****..***\n***...***\n**.....**\n*.......*",
"output": "********......**********........********\n********......**********........********\n********........********......********..\n********........********......********..\n..********......********....********....\n..********......********....********....\n..********......********..********......\n..********......********..********......\n....********....****************........\n....********....****************........\n....********....****************........\n....********....****************........\n......*..."
},
{
"input": "1 100\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.",
"output": "........................................................................................................................................................................................................\n........................................................................................................................................................................................................"
},
{
"input": "1 100\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*",
"output": "********************************************************************************************************************************************************************************************************\n********************************************************************************************************************************************************************************************************"
},
{
"input": "1 100\n.\n*\n.\n.\n.\n*\n.\n.\n.\n*\n*\n*\n.\n.\n.\n.\n.\n.\n*\n.\n.\n.\n*\n.\n*\n.\n.\n*\n*\n.\n*\n.\n.\n*\n.\n.\n*\n*\n.\n.\n.\n.\n.\n*\n.\n*\n.\n*\n.\n.\n.\n.\n*\n*\n*\n.\n.\n.\n.\n*\n.\n.\n*\n*\n*\n*\n.\n*\n*\n*\n*\n*\n.\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n.\n.\n*\n*\n*\n*\n*\n*\n*\n.\n.\n*\n.\n.\n*\n*\n.",
"output": "..**......**......******............**......**..**....****..**....**....****..........**..**..**........******........**....********..**********..********************....**************....**....****..\n..**......**......******............**......**..**....****..**....**....****..........**..**..**........******........**....********..**********..********************....**************....**....****.."
},
{
"input": "100 1\n****************************************************************************************************",
"output": "**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n..."
},
{
"input": "100 1\n*...***.....**.*...*.*.**.************.**..**.*..**..**.*.**...***.*...*.*..*.*.*......**..*..*...**",
"output": "**\n**\n..\n..\n..\n..\n..\n..\n**\n**\n**\n**\n**\n**\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n**\n**\n**\n**\n..\n..\n**\n**\n..\n..\n..\n..\n..\n..\n**\n**\n..\n..\n**\n**\n..\n..\n**\n**\n**\n**\n..\n..\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n..\n..\n**\n**\n**\n**\n..\n..\n..\n..\n**\n**\n**\n**\n..\n..\n**\n**\n..\n..\n..\n..\n**\n**\n**\n**\n..\n..\n..\n..\n**\n**\n**\n**\n..\n..\n**\n**\n..\n..\n**\n**\n**\n**\n..\n..\n..\n..\n..\n..\n**\n**\n..."
},
{
"input": "1 1\n.",
"output": "..\n.."
},
{
"input": "1 1\n*",
"output": "**\n**"
},
{
"input": "2 2\n.*\n*.",
"output": "..**\n..**\n**..\n**.."
},
{
"input": "1 2\n*\n.",
"output": "**..\n**.."
},
{
"input": "2 1\n*.",
"output": "**\n**\n..\n.."
}
] | 1,426,349,820 | 4,620 | Python 3 | WRONG_ANSWER | PRETESTS | 0 | 31 | 0 | w, h = [int(x) for x in input().split(' ')]
img = []
for i in range(h):
img.append([c for c in input()])
for j in (range(w)):
row = []
for i in (range(h)):
row.append(img[i][j])
row.append(img[i][j])
print(*row, end='\n')
print(*row, end='\n') | Title: Rotate, Flip and Zoom
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp is writing the prototype of a graphic editor. He has already made up his mind that the basic image transformations in his editor will be: rotate the image 90 degrees clockwise, flip the image horizontally (symmetry relative to the vertical line, that is, the right part of the image moves to the left, and vice versa) and zooming on the image. He is sure that that there is a large number of transformations that can be expressed through these three.
He has recently stopped implementing all three transformations for monochrome images. To test this feature, he asked you to write a code that will consecutively perform three actions with a monochrome image: first it will rotate the image 90 degrees clockwise, then it will flip the image horizontally and finally, it will zoom in twice on the image (that is, it will double all the linear sizes).
Implement this feature to help Polycarp test his editor.
Input Specification:
The first line contains two integers, *w* and *h* (1<=≤<=*w*,<=*h*<=≤<=100) — the width and height of an image in pixels. The picture is given in *h* lines, each line contains *w* characters — each character encodes the color of the corresponding pixel of the image. The line consists only of characters "." and "*", as the image is monochrome.
Output Specification:
Print 2*w* lines, each containing 2*h* characters — the result of consecutive implementing of the three transformations, described above.
Demo Input:
['3 2\n.*.\n.*.\n', '9 20\n**.......\n****.....\n******...\n*******..\n..******.\n....****.\n......***\n*.....***\n*********\n*********\n*********\n*********\n....**...\n...****..\n..******.\n.********\n****..***\n***...***\n**.....**\n*.......*\n']
Demo Output:
['....\n....\n****\n****\n....\n....\n', '********......**********........********\n********......**********........********\n********........********......********..\n********........********......********..\n..********......********....********....\n..********......********....********....\n..********......********..********......\n..********......********..********......\n....********....****************........\n....********....****************........\n....********....****************........\n....********....****************........\n......******************..**********....\n......******************..**********....\n........****************....**********..\n........****************....**********..\n............************......**********\n............************......**********\n']
Note:
none | ```python
w, h = [int(x) for x in input().split(' ')]
img = []
for i in range(h):
img.append([c for c in input()])
for j in (range(w)):
row = []
for i in (range(h)):
row.append(img[i][j])
row.append(img[i][j])
print(*row, end='\n')
print(*row, end='\n')
``` | 0 |
|
343 | A | Rational Resistance | PROGRAMMING | 1,600 | [
"math",
"number theory"
] | null | null | Mad scientist Mike is building a time machine in his spare time. To finish the work, he needs a resistor with a certain resistance value.
However, all Mike has is lots of identical resistors with unit resistance *R*0<==<=1. Elements with other resistance can be constructed from these resistors. In this problem, we will consider the following as elements:
1. one resistor; 1. an element and one resistor plugged in sequence; 1. an element and one resistor plugged in parallel.
With the consecutive connection the resistance of the new element equals *R*<==<=*R**e*<=+<=*R*0. With the parallel connection the resistance of the new element equals . In this case *R**e* equals the resistance of the element being connected.
Mike needs to assemble an element with a resistance equal to the fraction . Determine the smallest possible number of resistors he needs to make such an element. | The single input line contains two space-separated integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=1018). It is guaranteed that the fraction is irreducible. It is guaranteed that a solution always exists. | Print a single number — the answer to the problem.
Please do not use the %lld specifier to read or write 64-bit integers in С++. It is recommended to use the cin, cout streams or the %I64d specifier. | [
"1 1\n",
"3 2\n",
"199 200\n"
] | [
"1\n",
"3\n",
"200\n"
] | In the first sample, one resistor is enough.
In the second sample one can connect the resistors in parallel, take the resulting element and connect it to a third resistor consecutively. Then, we get an element with resistance <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/5305da389756aab6423d918a08ced468f05604df.png" style="max-width: 100.0%;max-height: 100.0%;"/>. We cannot make this element using two resistors. | 500 | [
{
"input": "1 1",
"output": "1"
},
{
"input": "3 2",
"output": "3"
},
{
"input": "199 200",
"output": "200"
},
{
"input": "1 1000000000000000000",
"output": "1000000000000000000"
},
{
"input": "3 1",
"output": "3"
},
{
"input": "21 8",
"output": "7"
},
{
"input": "18 55",
"output": "21"
},
{
"input": "1 2",
"output": "2"
},
{
"input": "2 1",
"output": "2"
},
{
"input": "1 3",
"output": "3"
},
{
"input": "2 3",
"output": "3"
},
{
"input": "1 4",
"output": "4"
},
{
"input": "5 2",
"output": "4"
},
{
"input": "2 5",
"output": "4"
},
{
"input": "4 5",
"output": "5"
},
{
"input": "3 5",
"output": "4"
},
{
"input": "13 4",
"output": "7"
},
{
"input": "21 17",
"output": "9"
},
{
"input": "5 8",
"output": "5"
},
{
"input": "13 21",
"output": "7"
},
{
"input": "74 99",
"output": "28"
},
{
"input": "2377 1055",
"output": "33"
},
{
"input": "645597 134285",
"output": "87"
},
{
"input": "29906716 35911991",
"output": "92"
},
{
"input": "3052460231 856218974",
"output": "82"
},
{
"input": "288565475053 662099878640",
"output": "88"
},
{
"input": "11504415412768 12754036168327",
"output": "163"
},
{
"input": "9958408561221547 4644682781404278",
"output": "196"
},
{
"input": "60236007668635342 110624799949034113",
"output": "179"
},
{
"input": "4 43470202936783249",
"output": "10867550734195816"
},
{
"input": "16 310139055712567491",
"output": "19383690982035476"
},
{
"input": "15 110897893734203629",
"output": "7393192915613582"
},
{
"input": "439910263967866789 38",
"output": "11576585893891241"
},
{
"input": "36 316049483082136289",
"output": "8779152307837131"
},
{
"input": "752278442523506295 52",
"output": "14466893125452056"
},
{
"input": "4052739537881 6557470319842",
"output": "62"
},
{
"input": "44945570212853 72723460248141",
"output": "67"
},
{
"input": "498454011879264 806515533049393",
"output": "72"
},
{
"input": "8944394323791464 5527939700884757",
"output": "77"
},
{
"input": "679891637638612258 420196140727489673",
"output": "86"
},
{
"input": "1 923438",
"output": "923438"
},
{
"input": "3945894354376 1",
"output": "3945894354376"
},
{
"input": "999999999999999999 5",
"output": "200000000000000004"
},
{
"input": "999999999999999999 1000000000000000000",
"output": "1000000000000000000"
},
{
"input": "999999999999999991 1000000000000000000",
"output": "111111111111111120"
},
{
"input": "999999999999999993 999999999999999991",
"output": "499999999999999998"
},
{
"input": "3 1000000000000000000",
"output": "333333333333333336"
},
{
"input": "1000000000000000000 3",
"output": "333333333333333336"
},
{
"input": "10000000000 1000000001",
"output": "100000019"
},
{
"input": "2 999999999999999999",
"output": "500000000000000001"
},
{
"input": "999999999999999999 2",
"output": "500000000000000001"
},
{
"input": "2 1000000001",
"output": "500000002"
},
{
"input": "123 1000000000000000000",
"output": "8130081300813023"
}
] | 1,595,098,739 | 2,147,483,647 | Python 3 | OK | TESTS | 53 | 218 | 6,758,400 | n,m=map(int,input().split())
a=0
while m:
a += n//m
n, m = m, n%m
print(a)
| Title: Rational Resistance
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mad scientist Mike is building a time machine in his spare time. To finish the work, he needs a resistor with a certain resistance value.
However, all Mike has is lots of identical resistors with unit resistance *R*0<==<=1. Elements with other resistance can be constructed from these resistors. In this problem, we will consider the following as elements:
1. one resistor; 1. an element and one resistor plugged in sequence; 1. an element and one resistor plugged in parallel.
With the consecutive connection the resistance of the new element equals *R*<==<=*R**e*<=+<=*R*0. With the parallel connection the resistance of the new element equals . In this case *R**e* equals the resistance of the element being connected.
Mike needs to assemble an element with a resistance equal to the fraction . Determine the smallest possible number of resistors he needs to make such an element.
Input Specification:
The single input line contains two space-separated integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=1018). It is guaranteed that the fraction is irreducible. It is guaranteed that a solution always exists.
Output Specification:
Print a single number — the answer to the problem.
Please do not use the %lld specifier to read or write 64-bit integers in С++. It is recommended to use the cin, cout streams or the %I64d specifier.
Demo Input:
['1 1\n', '3 2\n', '199 200\n']
Demo Output:
['1\n', '3\n', '200\n']
Note:
In the first sample, one resistor is enough.
In the second sample one can connect the resistors in parallel, take the resulting element and connect it to a third resistor consecutively. Then, we get an element with resistance <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/5305da389756aab6423d918a08ced468f05604df.png" style="max-width: 100.0%;max-height: 100.0%;"/>. We cannot make this element using two resistors. | ```python
n,m=map(int,input().split())
a=0
while m:
a += n//m
n, m = m, n%m
print(a)
``` | 3 |
|
233 | A | Perfect Permutation | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | A permutation is a sequence of integers *p*1,<=*p*2,<=...,<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. Let's denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size of permutation *p*1,<=*p*2,<=...,<=*p**n*.
Nickolas adores permutations. He likes some permutations more than the others. He calls such permutations perfect. A perfect permutation is such permutation *p* that for any *i* (1<=≤<=*i*<=≤<=*n*) (*n* is the permutation size) the following equations hold *p**p**i*<==<=*i* and *p**i*<=≠<=*i*. Nickolas asks you to print any perfect permutation of size *n* for the given *n*. | A single line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the permutation size. | If a perfect permutation of size *n* doesn't exist, print a single integer -1. Otherwise print *n* distinct integers from 1 to *n*, *p*1,<=*p*2,<=...,<=*p**n* — permutation *p*, that is perfect. Separate printed numbers by whitespaces. | [
"1\n",
"2\n",
"4\n"
] | [
"-1\n",
"2 1 \n",
"2 1 4 3 \n"
] | none | 500 | [
{
"input": "1",
"output": "-1"
},
{
"input": "2",
"output": "2 1 "
},
{
"input": "4",
"output": "2 1 4 3 "
},
{
"input": "3",
"output": "-1"
},
{
"input": "5",
"output": "-1"
},
{
"input": "6",
"output": "2 1 4 3 6 5 "
},
{
"input": "7",
"output": "-1"
},
{
"input": "20",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 "
},
{
"input": "8",
"output": "2 1 4 3 6 5 8 7 "
},
{
"input": "9",
"output": "-1"
},
{
"input": "10",
"output": "2 1 4 3 6 5 8 7 10 9 "
},
{
"input": "11",
"output": "-1"
},
{
"input": "21",
"output": "-1"
},
{
"input": "50",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 "
},
{
"input": "51",
"output": "-1"
},
{
"input": "52",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 "
},
{
"input": "84",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 "
},
{
"input": "86",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 "
},
{
"input": "100",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 "
},
{
"input": "98",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 "
},
{
"input": "96",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 "
},
{
"input": "33",
"output": "-1"
},
{
"input": "34",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 "
},
{
"input": "36",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 "
},
{
"input": "38",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 "
},
{
"input": "40",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 "
},
{
"input": "42",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 "
},
{
"input": "44",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 "
},
{
"input": "46",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 "
},
{
"input": "48",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 "
}
] | 1,671,958,633 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 62 | 0 | n = int(input())
ans = []
if n == 1:
print(-1)
exit()
else:
for i in range(1, n + 1):
ans.append(i)
j = 0
while j < n - 1:
ans[j], ans[j + 1] = ans[j + 1], ans[j]
j += 2
print(*ans) | Title: Perfect Permutation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A permutation is a sequence of integers *p*1,<=*p*2,<=...,<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. Let's denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size of permutation *p*1,<=*p*2,<=...,<=*p**n*.
Nickolas adores permutations. He likes some permutations more than the others. He calls such permutations perfect. A perfect permutation is such permutation *p* that for any *i* (1<=≤<=*i*<=≤<=*n*) (*n* is the permutation size) the following equations hold *p**p**i*<==<=*i* and *p**i*<=≠<=*i*. Nickolas asks you to print any perfect permutation of size *n* for the given *n*.
Input Specification:
A single line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the permutation size.
Output Specification:
If a perfect permutation of size *n* doesn't exist, print a single integer -1. Otherwise print *n* distinct integers from 1 to *n*, *p*1,<=*p*2,<=...,<=*p**n* — permutation *p*, that is perfect. Separate printed numbers by whitespaces.
Demo Input:
['1\n', '2\n', '4\n']
Demo Output:
['-1\n', '2 1 \n', '2 1 4 3 \n']
Note:
none | ```python
n = int(input())
ans = []
if n == 1:
print(-1)
exit()
else:
for i in range(1, n + 1):
ans.append(i)
j = 0
while j < n - 1:
ans[j], ans[j + 1] = ans[j + 1], ans[j]
j += 2
print(*ans)
``` | 0 |
|
1,005 | D | Polycarp and Div 3 | PROGRAMMING | 1,500 | [
"dp",
"greedy",
"number theory"
] | null | null | Polycarp likes numbers that are divisible by 3.
He has a huge number $s$. Polycarp wants to cut from it the maximum number of numbers that are divisible by $3$. To do this, he makes an arbitrary number of vertical cuts between pairs of adjacent digits. As a result, after $m$ such cuts, there will be $m+1$ parts in total. Polycarp analyzes each of the obtained numbers and finds the number of those that are divisible by $3$.
For example, if the original number is $s=3121$, then Polycarp can cut it into three parts with two cuts: $3|1|21$. As a result, he will get two numbers that are divisible by $3$.
Polycarp can make an arbitrary number of vertical cuts, where each cut is made between a pair of adjacent digits. The resulting numbers cannot contain extra leading zeroes (that is, the number can begin with 0 if and only if this number is exactly one character '0'). For example, 007, 01 and 00099 are not valid numbers, but 90, 0 and 10001 are valid.
What is the maximum number of numbers divisible by $3$ that Polycarp can obtain? | The first line of the input contains a positive integer $s$. The number of digits of the number $s$ is between $1$ and $2\cdot10^5$, inclusive. The first (leftmost) digit is not equal to 0. | Print the maximum number of numbers divisible by $3$ that Polycarp can get by making vertical cuts in the given number $s$. | [
"3121\n",
"6\n",
"1000000000000000000000000000000000\n",
"201920181\n"
] | [
"2\n",
"1\n",
"33\n",
"4\n"
] | In the first example, an example set of optimal cuts on the number is 3|1|21.
In the second example, you do not need to make any cuts. The specified number 6 forms one number that is divisible by $3$.
In the third example, cuts must be made between each pair of digits. As a result, Polycarp gets one digit 1 and $33$ digits 0. Each of the $33$ digits 0 forms a number that is divisible by $3$.
In the fourth example, an example set of optimal cuts is 2|0|1|9|201|81. The numbers $0$, $9$, $201$ and $81$ are divisible by $3$. | 0 | [
{
"input": "3121",
"output": "2"
},
{
"input": "6",
"output": "1"
},
{
"input": "1000000000000000000000000000000000",
"output": "33"
},
{
"input": "201920181",
"output": "4"
},
{
"input": "4",
"output": "0"
},
{
"input": "10",
"output": "1"
},
{
"input": "11",
"output": "0"
},
{
"input": "12",
"output": "1"
},
{
"input": "13",
"output": "1"
},
{
"input": "31",
"output": "1"
},
{
"input": "14139582796",
"output": "6"
},
{
"input": "1670000",
"output": "5"
},
{
"input": "604500",
"output": "5"
},
{
"input": "40041",
"output": "2"
},
{
"input": "10000170",
"output": "5"
}
] | 1,675,679,102 | 2,402 | PyPy 3-64 | WRONG_ANSWER | TESTS | 10 | 140 | 26,419,200 | import sys
input = lambda: sys.stdin.readline().rstrip()
# ----------------------- #
s = input()
n = len(s)
A = [int(x) for x in s]
dp = [[0]*3 for _ in range(n+1)]
ans = 0
now = [0, 0, 0]
def calc():
res = 0
cnt = min(now[1], now[2])
res += cnt
now[1] -= cnt
now[2] -= cnt
res += now[1]//3 + now[2]//3
return res
for a in A:
if a % 3 == 0:
ans += 1 + calc()
now = [0, 0, 0]
elif a % 3 == 1:
now[1] += 1
else:
now[2] += 1
ans += calc()
print(ans)
| Title: Polycarp and Div 3
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp likes numbers that are divisible by 3.
He has a huge number $s$. Polycarp wants to cut from it the maximum number of numbers that are divisible by $3$. To do this, he makes an arbitrary number of vertical cuts between pairs of adjacent digits. As a result, after $m$ such cuts, there will be $m+1$ parts in total. Polycarp analyzes each of the obtained numbers and finds the number of those that are divisible by $3$.
For example, if the original number is $s=3121$, then Polycarp can cut it into three parts with two cuts: $3|1|21$. As a result, he will get two numbers that are divisible by $3$.
Polycarp can make an arbitrary number of vertical cuts, where each cut is made between a pair of adjacent digits. The resulting numbers cannot contain extra leading zeroes (that is, the number can begin with 0 if and only if this number is exactly one character '0'). For example, 007, 01 and 00099 are not valid numbers, but 90, 0 and 10001 are valid.
What is the maximum number of numbers divisible by $3$ that Polycarp can obtain?
Input Specification:
The first line of the input contains a positive integer $s$. The number of digits of the number $s$ is between $1$ and $2\cdot10^5$, inclusive. The first (leftmost) digit is not equal to 0.
Output Specification:
Print the maximum number of numbers divisible by $3$ that Polycarp can get by making vertical cuts in the given number $s$.
Demo Input:
['3121\n', '6\n', '1000000000000000000000000000000000\n', '201920181\n']
Demo Output:
['2\n', '1\n', '33\n', '4\n']
Note:
In the first example, an example set of optimal cuts on the number is 3|1|21.
In the second example, you do not need to make any cuts. The specified number 6 forms one number that is divisible by $3$.
In the third example, cuts must be made between each pair of digits. As a result, Polycarp gets one digit 1 and $33$ digits 0. Each of the $33$ digits 0 forms a number that is divisible by $3$.
In the fourth example, an example set of optimal cuts is 2|0|1|9|201|81. The numbers $0$, $9$, $201$ and $81$ are divisible by $3$. | ```python
import sys
input = lambda: sys.stdin.readline().rstrip()
# ----------------------- #
s = input()
n = len(s)
A = [int(x) for x in s]
dp = [[0]*3 for _ in range(n+1)]
ans = 0
now = [0, 0, 0]
def calc():
res = 0
cnt = min(now[1], now[2])
res += cnt
now[1] -= cnt
now[2] -= cnt
res += now[1]//3 + now[2]//3
return res
for a in A:
if a % 3 == 0:
ans += 1 + calc()
now = [0, 0, 0]
elif a % 3 == 1:
now[1] += 1
else:
now[2] += 1
ans += calc()
print(ans)
``` | 0 |
|
271 | A | Beautiful Year | PROGRAMMING | 800 | [
"brute force"
] | null | null | It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits.
Now you are suggested to solve the following problem: given a year number, find the minimum year number which is strictly larger than the given one and has only distinct digits. | The single line contains integer *y* (1000<=≤<=*y*<=≤<=9000) — the year number. | Print a single integer — the minimum year number that is strictly larger than *y* and all it's digits are distinct. It is guaranteed that the answer exists. | [
"1987\n",
"2013\n"
] | [
"2013\n",
"2014\n"
] | none | 500 | [
{
"input": "1987",
"output": "2013"
},
{
"input": "2013",
"output": "2014"
},
{
"input": "1000",
"output": "1023"
},
{
"input": "1001",
"output": "1023"
},
{
"input": "1234",
"output": "1235"
},
{
"input": "5555",
"output": "5601"
},
{
"input": "9000",
"output": "9012"
},
{
"input": "1111",
"output": "1203"
},
{
"input": "8999",
"output": "9012"
},
{
"input": "4572",
"output": "4573"
},
{
"input": "6666",
"output": "6701"
},
{
"input": "2001",
"output": "2013"
},
{
"input": "3000",
"output": "3012"
},
{
"input": "7712",
"output": "7801"
},
{
"input": "8088",
"output": "8091"
},
{
"input": "1594",
"output": "1596"
},
{
"input": "6016",
"output": "6017"
},
{
"input": "8800",
"output": "8901"
},
{
"input": "3331",
"output": "3401"
},
{
"input": "5090",
"output": "5091"
},
{
"input": "2342",
"output": "2345"
},
{
"input": "2334",
"output": "2340"
},
{
"input": "1123",
"output": "1203"
},
{
"input": "8989",
"output": "9012"
},
{
"input": "8977",
"output": "9012"
},
{
"input": "6869",
"output": "6870"
},
{
"input": "8999",
"output": "9012"
}
] | 1,690,459,752 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 92 | 0 | def d_d(year):
y_str = str(year)
return len(set(y_str)) == len(y_str)
def n_y(y):
y += 1
while not d_d(y):
y += 1
return y
y = int(input())
r = n_y(y)
print(r)
| Title: Beautiful Year
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits.
Now you are suggested to solve the following problem: given a year number, find the minimum year number which is strictly larger than the given one and has only distinct digits.
Input Specification:
The single line contains integer *y* (1000<=≤<=*y*<=≤<=9000) — the year number.
Output Specification:
Print a single integer — the minimum year number that is strictly larger than *y* and all it's digits are distinct. It is guaranteed that the answer exists.
Demo Input:
['1987\n', '2013\n']
Demo Output:
['2013\n', '2014\n']
Note:
none | ```python
def d_d(year):
y_str = str(year)
return len(set(y_str)) == len(y_str)
def n_y(y):
y += 1
while not d_d(y):
y += 1
return y
y = int(input())
r = n_y(y)
print(r)
``` | 3 |
|
221 | A | Little Elephant and Function | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | The Little Elephant enjoys recursive functions.
This time he enjoys the sorting function. Let *a* is a permutation of an integers from 1 to *n*, inclusive, and *a**i* denotes the *i*-th element of the permutation. The Little Elephant's recursive function *f*(*x*), that sorts the first *x* permutation's elements, works as follows:
- If *x*<==<=1, exit the function. - Otherwise, call *f*(*x*<=-<=1), and then make *swap*(*a**x*<=-<=1,<=*a**x*) (swap the *x*-th and (*x*<=-<=1)-th elements of *a*).
The Little Elephant's teacher believes that this function does not work correctly. But that-be do not get an F, the Little Elephant wants to show the performance of its function. Help him, find a permutation of numbers from 1 to *n*, such that after performing the Little Elephant's function (that is call *f*(*n*)), the permutation will be sorted in ascending order. | A single line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the size of permutation. | In a single line print *n* distinct integers from 1 to *n* — the required permutation. Numbers in a line should be separated by spaces.
It is guaranteed that the answer exists. | [
"1\n",
"2\n"
] | [
"1 ",
"2 1 "
] | none | 500 | [
{
"input": "1",
"output": "1 "
},
{
"input": "2",
"output": "2 1 "
},
{
"input": "3",
"output": "3 1 2 "
},
{
"input": "4",
"output": "4 1 2 3 "
},
{
"input": "5",
"output": "5 1 2 3 4 "
},
{
"input": "6",
"output": "6 1 2 3 4 5 "
},
{
"input": "7",
"output": "7 1 2 3 4 5 6 "
},
{
"input": "1000",
"output": "1000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 15..."
},
{
"input": "999",
"output": "999 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "998",
"output": "998 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "997",
"output": "997 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "900",
"output": "900 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "101",
"output": "101 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 "
},
{
"input": "3",
"output": "3 1 2 "
},
{
"input": "67",
"output": "67 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 "
},
{
"input": "779",
"output": "779 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "195",
"output": "195 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "907",
"output": "907 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "971",
"output": "971 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "683",
"output": "683 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "99",
"output": "99 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 "
},
{
"input": "811",
"output": "811 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "875",
"output": "875 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "291",
"output": "291 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "3",
"output": "3 1 2 "
},
{
"input": "419",
"output": "419 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "779",
"output": "779 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "195",
"output": "195 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "907",
"output": "907 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "21",
"output": "21 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 "
},
{
"input": "22",
"output": "22 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 "
},
{
"input": "23",
"output": "23 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 "
},
{
"input": "24",
"output": "24 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 "
},
{
"input": "25",
"output": "25 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 "
}
] | 1,389,460,799 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 62 | 0 | if __name__ == "__main__":
range.__doc__
n=int(input())+1
for i in range(2,n):
print(i, end=" ")
print(1) | Title: Little Elephant and Function
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant enjoys recursive functions.
This time he enjoys the sorting function. Let *a* is a permutation of an integers from 1 to *n*, inclusive, and *a**i* denotes the *i*-th element of the permutation. The Little Elephant's recursive function *f*(*x*), that sorts the first *x* permutation's elements, works as follows:
- If *x*<==<=1, exit the function. - Otherwise, call *f*(*x*<=-<=1), and then make *swap*(*a**x*<=-<=1,<=*a**x*) (swap the *x*-th and (*x*<=-<=1)-th elements of *a*).
The Little Elephant's teacher believes that this function does not work correctly. But that-be do not get an F, the Little Elephant wants to show the performance of its function. Help him, find a permutation of numbers from 1 to *n*, such that after performing the Little Elephant's function (that is call *f*(*n*)), the permutation will be sorted in ascending order.
Input Specification:
A single line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the size of permutation.
Output Specification:
In a single line print *n* distinct integers from 1 to *n* — the required permutation. Numbers in a line should be separated by spaces.
It is guaranteed that the answer exists.
Demo Input:
['1\n', '2\n']
Demo Output:
['1 ', '2 1 ']
Note:
none | ```python
if __name__ == "__main__":
range.__doc__
n=int(input())+1
for i in range(2,n):
print(i, end=" ")
print(1)
``` | 0 |
|
115 | A | Party | PROGRAMMING | 900 | [
"dfs and similar",
"graphs",
"trees"
] | null | null | A company has *n* employees numbered from 1 to *n*. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee *A* is said to be the superior of another employee *B* if at least one of the following is true:
- Employee *A* is the immediate manager of employee *B* - Employee *B* has an immediate manager employee *C* such that employee *A* is the superior of employee *C*.
The company will not have a managerial cycle. That is, there will not exist an employee who is the superior of his/her own immediate manager.
Today the company is going to arrange a party. This involves dividing all *n* employees into several groups: every employee must belong to exactly one group. Furthermore, within any single group, there must not be two employees *A* and *B* such that *A* is the superior of *B*.
What is the minimum number of groups that must be formed? | The first line contains integer *n* (1<=≤<=*n*<=≤<=2000) — the number of employees.
The next *n* lines contain the integers *p**i* (1<=≤<=*p**i*<=≤<=*n* or *p**i*<==<=-1). Every *p**i* denotes the immediate manager for the *i*-th employee. If *p**i* is -1, that means that the *i*-th employee does not have an immediate manager.
It is guaranteed, that no employee will be the immediate manager of him/herself (*p**i*<=≠<=*i*). Also, there will be no managerial cycles. | Print a single integer denoting the minimum number of groups that will be formed in the party. | [
"5\n-1\n1\n2\n1\n-1\n"
] | [
"3\n"
] | For the first example, three groups are sufficient, for example:
- Employee 1 - Employees 2 and 4 - Employees 3 and 5 | 500 | [
{
"input": "5\n-1\n1\n2\n1\n-1",
"output": "3"
},
{
"input": "4\n-1\n1\n2\n3",
"output": "4"
},
{
"input": "12\n-1\n1\n2\n3\n-1\n5\n6\n7\n-1\n9\n10\n11",
"output": "4"
},
{
"input": "6\n-1\n-1\n2\n3\n1\n1",
"output": "3"
},
{
"input": "3\n-1\n1\n1",
"output": "2"
},
{
"input": "1\n-1",
"output": "1"
},
{
"input": "2\n2\n-1",
"output": "2"
},
{
"input": "2\n-1\n-1",
"output": "1"
},
{
"input": "3\n2\n-1\n1",
"output": "3"
},
{
"input": "3\n-1\n-1\n-1",
"output": "1"
},
{
"input": "5\n4\n5\n1\n-1\n4",
"output": "3"
},
{
"input": "12\n-1\n1\n1\n1\n1\n1\n3\n4\n3\n3\n4\n7",
"output": "4"
},
{
"input": "12\n-1\n-1\n1\n-1\n1\n1\n5\n11\n8\n6\n6\n4",
"output": "5"
},
{
"input": "12\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n2\n-1\n-1\n-1",
"output": "2"
},
{
"input": "12\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1",
"output": "1"
},
{
"input": "12\n3\n4\n2\n8\n7\n1\n10\n12\n5\n-1\n9\n11",
"output": "12"
},
{
"input": "12\n5\n6\n7\n1\n-1\n9\n12\n4\n8\n-1\n3\n2",
"output": "11"
},
{
"input": "12\n-1\n9\n11\n6\n6\n-1\n6\n3\n8\n6\n1\n6",
"output": "6"
},
{
"input": "12\n7\n8\n4\n12\n7\n9\n-1\n-1\n-1\n8\n6\n-1",
"output": "3"
},
{
"input": "12\n-1\n10\n-1\n1\n-1\n5\n9\n12\n-1\n-1\n3\n-1",
"output": "2"
},
{
"input": "12\n-1\n7\n9\n12\n1\n7\n-1\n-1\n8\n5\n4\n-1",
"output": "3"
},
{
"input": "12\n11\n11\n8\n9\n1\n1\n2\n-1\n10\n3\n-1\n8",
"output": "5"
},
{
"input": "12\n-1\n8\n9\n-1\n4\n2\n11\n1\n-1\n6\n-1\n10",
"output": "6"
},
{
"input": "12\n7\n4\n4\n-1\n6\n7\n9\n7\n-1\n7\n4\n1",
"output": "4"
},
{
"input": "12\n-1\n6\n10\n6\n1\n11\n5\n9\n11\n5\n1\n9",
"output": "4"
},
{
"input": "12\n8\n6\n6\n8\n6\n-1\n6\n6\n8\n6\n8\n8",
"output": "3"
},
{
"input": "12\n3\n8\n9\n12\n2\n8\n11\n12\n2\n9\n-1\n11",
"output": "7"
},
{
"input": "7\n7\n6\n-1\n-1\n4\n4\n-1",
"output": "3"
},
{
"input": "77\n53\n-1\n48\n-1\n51\n-1\n54\n43\n70\n19\n64\n31\n45\n58\n6\n61\n41\n56\n34\n-1\n54\n-1\n66\n65\n74\n16\n38\n1\n2\n61\n-1\n34\n-1\n-1\n7\n19\n57\n13\n61\n42\n-1\n34\n65\n16\n31\n61\n6\n5\n34\n15\n-1\n13\n4\n22\n74\n7\n-1\n70\n38\n61\n45\n53\n46\n22\n-1\n65\n34\n19\n43\n48\n33\n58\n36\n-1\n47\n24\n34",
"output": "6"
},
{
"input": "5\n2\n3\n4\n5\n-1",
"output": "5"
}
] | 1,650,821,397 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 62 | 0 | n = int(input())
arr = []
for i in range(n):
arr.append(int(input()))
max_depth = 1
for i in range(1, n+1):
if arr[i] == -1:
continue
depth = 1
j = parent[i]
while j != -1:
depth += 1
j = parent[j]
max_depth = max(max_depth, depth)
print(max_depth)
| Title: Party
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A company has *n* employees numbered from 1 to *n*. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee *A* is said to be the superior of another employee *B* if at least one of the following is true:
- Employee *A* is the immediate manager of employee *B* - Employee *B* has an immediate manager employee *C* such that employee *A* is the superior of employee *C*.
The company will not have a managerial cycle. That is, there will not exist an employee who is the superior of his/her own immediate manager.
Today the company is going to arrange a party. This involves dividing all *n* employees into several groups: every employee must belong to exactly one group. Furthermore, within any single group, there must not be two employees *A* and *B* such that *A* is the superior of *B*.
What is the minimum number of groups that must be formed?
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=2000) — the number of employees.
The next *n* lines contain the integers *p**i* (1<=≤<=*p**i*<=≤<=*n* or *p**i*<==<=-1). Every *p**i* denotes the immediate manager for the *i*-th employee. If *p**i* is -1, that means that the *i*-th employee does not have an immediate manager.
It is guaranteed, that no employee will be the immediate manager of him/herself (*p**i*<=≠<=*i*). Also, there will be no managerial cycles.
Output Specification:
Print a single integer denoting the minimum number of groups that will be formed in the party.
Demo Input:
['5\n-1\n1\n2\n1\n-1\n']
Demo Output:
['3\n']
Note:
For the first example, three groups are sufficient, for example:
- Employee 1 - Employees 2 and 4 - Employees 3 and 5 | ```python
n = int(input())
arr = []
for i in range(n):
arr.append(int(input()))
max_depth = 1
for i in range(1, n+1):
if arr[i] == -1:
continue
depth = 1
j = parent[i]
while j != -1:
depth += 1
j = parent[j]
max_depth = max(max_depth, depth)
print(max_depth)
``` | -1 |
|
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,679,935,931 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 15 | 46 | 0 | a = int(input())
b = [8, 4, 2 , 6]
print(b[(a % 4)-1]) | 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
a = int(input())
b = [8, 4, 2 , 6]
print(b[(a % 4)-1])
``` | 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,679,655,383 | 2,147,483,647 | Python 3 | OK | TESTS | 41 | 46 | 0 | n = int(input())
a = list(map(int,input().split()))
S = 0
x = max(a)
for i in range(n):
S += x-a[i]
print(S)
| Title: Holiday Of Equality
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury.
Totally in Berland there are *n* citizens, 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
n = int(input())
a = list(map(int,input().split()))
S = 0
x = max(a)
for i in range(n):
S += x-a[i]
print(S)
``` | 3 |
|
510 | B | Fox And Two Dots | PROGRAMMING | 1,500 | [
"dfs and similar"
] | null | null | Fox Ciel is playing a mobile puzzle game called "Two Dots". The basic levels are played on a board of size *n*<=×<=*m* cells, like this:
Each cell contains a dot that has some color. We will use different uppercase Latin characters to express different colors.
The key of this game is to find a cycle that contain dots of same color. Consider 4 blue dots on the picture forming a circle as an example. Formally, we call a sequence of dots *d*1,<=*d*2,<=...,<=*d**k* a cycle if and only if it meets the following condition:
1. These *k* dots are different: if *i*<=≠<=*j* then *d**i* is different from *d**j*. 1. *k* is at least 4. 1. All dots belong to the same color. 1. For all 1<=≤<=*i*<=≤<=*k*<=-<=1: *d**i* and *d**i*<=+<=1 are adjacent. Also, *d**k* and *d*1 should also be adjacent. Cells *x* and *y* are called adjacent if they share an edge.
Determine if there exists a cycle on the field. | The first line contains two integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=50): the number of rows and columns of the board.
Then *n* lines follow, each line contains a string consisting of *m* characters, expressing colors of dots in each line. Each character is an uppercase Latin letter. | Output "Yes" if there exists a cycle, and "No" otherwise. | [
"3 4\nAAAA\nABCA\nAAAA\n",
"3 4\nAAAA\nABCA\nAADA\n",
"4 4\nYYYR\nBYBY\nBBBY\nBBBY\n",
"7 6\nAAAAAB\nABBBAB\nABAAAB\nABABBB\nABAAAB\nABBBAB\nAAAAAB\n",
"2 13\nABCDEFGHIJKLM\nNOPQRSTUVWXYZ\n"
] | [
"Yes\n",
"No\n",
"Yes\n",
"Yes\n",
"No\n"
] | In first sample test all 'A' form a cycle.
In second sample there is no such cycle.
The third sample is displayed on the picture above ('Y' = Yellow, 'B' = Blue, 'R' = Red). | 1,000 | [
{
"input": "3 4\nAAAA\nABCA\nAAAA",
"output": "Yes"
},
{
"input": "3 4\nAAAA\nABCA\nAADA",
"output": "No"
},
{
"input": "4 4\nYYYR\nBYBY\nBBBY\nBBBY",
"output": "Yes"
},
{
"input": "7 6\nAAAAAB\nABBBAB\nABAAAB\nABABBB\nABAAAB\nABBBAB\nAAAAAB",
"output": "Yes"
},
{
"input": "2 13\nABCDEFGHIJKLM\nNOPQRSTUVWXYZ",
"output": "No"
},
{
"input": "2 2\nAA\nAA",
"output": "Yes"
},
{
"input": "2 2\nAA\nAB",
"output": "No"
},
{
"input": "3 3\nAAA\nABA\nAAA",
"output": "Yes"
},
{
"input": "3 3\nAAA\nABA\nABA",
"output": "No"
},
{
"input": "10 10\nEGFJGJKGEI\nAKJHBGHIHF\nJBABBCFGEJ\nCJDJHJJKBD\nKHJIKKGGEK\nHHJHKHGEKF\nEKFCAJGGDK\nAFKBBFICAA\nFEDFAGHEKA\nCAAGIFHGGI",
"output": "No"
},
{
"input": "10 10\nHIICQRHPUJ\nBCDUKHMBFK\nPFTUIDOBOE\nQQPITLRKUP\nERMUJMOSMF\nMRSICEILQB\nODIGFNCHFR\nGHIOAFLHJH\nFBLAQNGEIF\nFDLEGDUTNG",
"output": "No"
},
{
"input": "2 50\nDADCDBCCDAACDBCAACADBCBDBACCCCDADCBACADBCCBDBCCBCC\nDADAADCABBBACCDDBABBBDCBACBCCCCDDADCDABADDDCABACDB",
"output": "Yes"
},
{
"input": "50 2\nAA\nCD\nEE\nFC\nED\nAF\nFC\nAD\nBA\nAF\nBF\nDA\nAC\nFC\nFA\nBF\nAD\nBB\nDC\nAF\nAA\nAD\nEE\nED\nCD\nFC\nFB\nBB\nDD\nEB\nBE\nCF\nDE\nAE\nFD\nAB\nFB\nAE\nBE\nFA\nCF\nFB\nDE\nED\nAD\nFA\nBB\nBF\nDA\nEE",
"output": "No"
}
] | 1,678,977,606 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | def dfs(w, i, j):
if num_list[i][j] != w:
return
if v[i - 1][j - 1] and num_list[i][j] == w:
ans = True
return
if v[i - 1][j - 1]:
return
v[i - 1][j - 1] = True
dfs(w, i + 1, j)
dfs(w, i, j + 1)
dfs(w, i - 1, j)
dfs(w, i, j - 1)
n, m = map(int, input().split())
v = [[False] * m for i in range(n)]
num_list = ['#' * (m + 2)]
ans = False
for i in range(n):
s = '#' + input() + '#'
num_list.append(s)
num_list.append('#' * (m + 2))
for i in range(1, n + 1):
for j in range(1, m + 1):
if not v[i - 1][j - 1]:
dfs(num_list[i][j], i, j)
if ans:
print('YES')
else:
print('NO')
| Title: Fox And Two Dots
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fox Ciel is playing a mobile puzzle game called "Two Dots". The basic levels are played on a board of size *n*<=×<=*m* cells, like this:
Each cell contains a dot that has some color. We will use different uppercase Latin characters to express different colors.
The key of this game is to find a cycle that contain dots of same color. Consider 4 blue dots on the picture forming a circle as an example. Formally, we call a sequence of dots *d*1,<=*d*2,<=...,<=*d**k* a cycle if and only if it meets the following condition:
1. These *k* dots are different: if *i*<=≠<=*j* then *d**i* is different from *d**j*. 1. *k* is at least 4. 1. All dots belong to the same color. 1. For all 1<=≤<=*i*<=≤<=*k*<=-<=1: *d**i* and *d**i*<=+<=1 are adjacent. Also, *d**k* and *d*1 should also be adjacent. Cells *x* and *y* are called adjacent if they share an edge.
Determine if there exists a cycle on the field.
Input Specification:
The first line contains two integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=50): the number of rows and columns of the board.
Then *n* lines follow, each line contains a string consisting of *m* characters, expressing colors of dots in each line. Each character is an uppercase Latin letter.
Output Specification:
Output "Yes" if there exists a cycle, and "No" otherwise.
Demo Input:
['3 4\nAAAA\nABCA\nAAAA\n', '3 4\nAAAA\nABCA\nAADA\n', '4 4\nYYYR\nBYBY\nBBBY\nBBBY\n', '7 6\nAAAAAB\nABBBAB\nABAAAB\nABABBB\nABAAAB\nABBBAB\nAAAAAB\n', '2 13\nABCDEFGHIJKLM\nNOPQRSTUVWXYZ\n']
Demo Output:
['Yes\n', 'No\n', 'Yes\n', 'Yes\n', 'No\n']
Note:
In first sample test all 'A' form a cycle.
In second sample there is no such cycle.
The third sample is displayed on the picture above ('Y' = Yellow, 'B' = Blue, 'R' = Red). | ```python
def dfs(w, i, j):
if num_list[i][j] != w:
return
if v[i - 1][j - 1] and num_list[i][j] == w:
ans = True
return
if v[i - 1][j - 1]:
return
v[i - 1][j - 1] = True
dfs(w, i + 1, j)
dfs(w, i, j + 1)
dfs(w, i - 1, j)
dfs(w, i, j - 1)
n, m = map(int, input().split())
v = [[False] * m for i in range(n)]
num_list = ['#' * (m + 2)]
ans = False
for i in range(n):
s = '#' + input() + '#'
num_list.append(s)
num_list.append('#' * (m + 2))
for i in range(1, n + 1):
for j in range(1, m + 1):
if not v[i - 1][j - 1]:
dfs(num_list[i][j], i, j)
if ans:
print('YES')
else:
print('NO')
``` | 0 |
|
918 | B | Radio Station | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | As the guys fried the radio station facilities, the school principal gave them tasks as a punishment. Dustin's task was to add comments to nginx configuration for school's website. The school has *n* servers. Each server has a name and an ip (names aren't necessarily unique, but ips are). Dustin knows the ip and name of each server. For simplicity, we'll assume that an nginx command is of form "command ip;" where command is a string consisting of English lowercase letter only, and ip is the ip of one of school servers.
Each ip is of form "a.b.c.d" where *a*, *b*, *c* and *d* are non-negative integers less than or equal to 255 (with no leading zeros). The nginx configuration file Dustin has to add comments to has *m* commands. Nobody ever memorizes the ips of servers, so to understand the configuration better, Dustin has to comment the name of server that the ip belongs to at the end of each line (after each command). More formally, if a line is "command ip;" Dustin has to replace it with "command ip; #name" where name is the name of the server with ip equal to ip.
Dustin doesn't know anything about nginx, so he panicked again and his friends asked you to do his task for him. | The first line of input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000).
The next *n* lines contain the names and ips of the servers. Each line contains a string name, name of the server and a string ip, ip of the server, separated by space (1<=≤<=|*name*|<=≤<=10, *name* only consists of English lowercase letters). It is guaranteed that all ip are distinct.
The next *m* lines contain the commands in the configuration file. Each line is of form "command ip;" (1<=≤<=|*command*|<=≤<=10, command only consists of English lowercase letters). It is guaranteed that ip belongs to one of the *n* school servers. | Print *m* lines, the commands in the configuration file after Dustin did his task. | [
"2 2\nmain 192.168.0.2\nreplica 192.168.0.1\nblock 192.168.0.1;\nproxy 192.168.0.2;\n",
"3 5\ngoogle 8.8.8.8\ncodeforces 212.193.33.27\nserver 138.197.64.57\nredirect 138.197.64.57;\nblock 8.8.8.8;\ncf 212.193.33.27;\nunblock 8.8.8.8;\ncheck 138.197.64.57;\n"
] | [
"block 192.168.0.1; #replica\nproxy 192.168.0.2; #main\n",
"redirect 138.197.64.57; #server\nblock 8.8.8.8; #google\ncf 212.193.33.27; #codeforces\nunblock 8.8.8.8; #google\ncheck 138.197.64.57; #server\n"
] | none | 1,000 | [
{
"input": "2 2\nmain 192.168.0.2\nreplica 192.168.0.1\nblock 192.168.0.1;\nproxy 192.168.0.2;",
"output": "block 192.168.0.1; #replica\nproxy 192.168.0.2; #main"
},
{
"input": "3 5\ngoogle 8.8.8.8\ncodeforces 212.193.33.27\nserver 138.197.64.57\nredirect 138.197.64.57;\nblock 8.8.8.8;\ncf 212.193.33.27;\nunblock 8.8.8.8;\ncheck 138.197.64.57;",
"output": "redirect 138.197.64.57; #server\nblock 8.8.8.8; #google\ncf 212.193.33.27; #codeforces\nunblock 8.8.8.8; #google\ncheck 138.197.64.57; #server"
},
{
"input": "10 10\nittmcs 112.147.123.173\njkt 228.40.73.178\nfwckqtz 88.28.31.198\nkal 224.226.34.213\nnacuyokm 49.57.13.44\nfouynv 243.18.250.17\ns 45.248.83.247\ne 75.69.23.169\nauwoqlch 100.44.219.187\nlkldjq 46.123.169.140\ngjcylatwzi 46.123.169.140;\ndxfi 88.28.31.198;\ngv 46.123.169.140;\nety 88.28.31.198;\notbmgcrn 46.123.169.140;\nw 112.147.123.173;\np 75.69.23.169;\nvdsnigk 46.123.169.140;\nmmc 46.123.169.140;\ngtc 49.57.13.44;",
"output": "gjcylatwzi 46.123.169.140; #lkldjq\ndxfi 88.28.31.198; #fwckqtz\ngv 46.123.169.140; #lkldjq\nety 88.28.31.198; #fwckqtz\notbmgcrn 46.123.169.140; #lkldjq\nw 112.147.123.173; #ittmcs\np 75.69.23.169; #e\nvdsnigk 46.123.169.140; #lkldjq\nmmc 46.123.169.140; #lkldjq\ngtc 49.57.13.44; #nacuyokm"
},
{
"input": "1 1\nervbfot 185.32.99.2\nzygoumbmx 185.32.99.2;",
"output": "zygoumbmx 185.32.99.2; #ervbfot"
},
{
"input": "1 2\ny 245.182.246.189\nlllq 245.182.246.189;\nxds 245.182.246.189;",
"output": "lllq 245.182.246.189; #y\nxds 245.182.246.189; #y"
},
{
"input": "2 1\ntdwmshz 203.115.124.110\neksckjya 201.80.191.212\nzbtjzzue 203.115.124.110;",
"output": "zbtjzzue 203.115.124.110; #tdwmshz"
},
{
"input": "8 5\nfhgkq 5.19.189.178\nphftablcr 75.18.177.178\nxnpcg 158.231.167.176\ncfahrkq 26.165.124.191\nfkgtnqtfoh 230.13.13.129\nt 101.24.94.85\nvjoirslx 59.6.179.72\ntwktmskb 38.194.117.184\nrvzzlygosc 26.165.124.191;\ndcsgxrkgv 101.24.94.85;\nyvmyppn 59.6.179.72;\ngpdjjuq 75.18.177.178;\nvdviz 101.24.94.85;",
"output": "rvzzlygosc 26.165.124.191; #cfahrkq\ndcsgxrkgv 101.24.94.85; #t\nyvmyppn 59.6.179.72; #vjoirslx\ngpdjjuq 75.18.177.178; #phftablcr\nvdviz 101.24.94.85; #t"
},
{
"input": "2 1\nmain 1.1.1.1\nget 11.1.1.1\ncommand 11.1.1.1;",
"output": "command 11.1.1.1; #get"
},
{
"input": "2 2\nmain 0.0.0.255\nmainn 0.0.2.55\nblock 0.0.0.255;\nblock 0.0.2.55;",
"output": "block 0.0.0.255; #main\nblock 0.0.2.55; #mainn"
},
{
"input": "2 2\nmain 0.0.63.0\nreplica 0.38.0.56\nblock 0.0.63.0;\nproxy 0.38.0.56;",
"output": "block 0.0.63.0; #main\nproxy 0.38.0.56; #replica"
},
{
"input": "2 2\nmain 192.168.10.12\nreplica 192.167.10.12\nblock 192.168.10.12;\nproxy 192.167.10.12;",
"output": "block 192.168.10.12; #main\nproxy 192.167.10.12; #replica"
},
{
"input": "2 1\nneserver 185.218.47.91\nserver 255.255.255.255\nblock 255.255.255.255;",
"output": "block 255.255.255.255; #server"
},
{
"input": "2 1\nalp 22.222.30.10\nbet 222.22.30.10\nblock 22.222.30.10;",
"output": "block 22.222.30.10; #alp"
}
] | 1,665,197,098 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 28 | 140 | 7,782,400 | n, m = map(int, input().split())
d={}
for i in range(n):
name, ip = input().split()
d[ip] = name
for i in range(m):
name, ip = input().split()
print(name,ip,"#"+d[ip[:-1]]) | Title: Radio Station
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As the guys fried the radio station facilities, the school principal gave them tasks as a punishment. Dustin's task was to add comments to nginx configuration for school's website. The school has *n* servers. Each server has a name and an ip (names aren't necessarily unique, but ips are). Dustin knows the ip and name of each server. For simplicity, we'll assume that an nginx command is of form "command ip;" where command is a string consisting of English lowercase letter only, and ip is the ip of one of school servers.
Each ip is of form "a.b.c.d" where *a*, *b*, *c* and *d* are non-negative integers less than or equal to 255 (with no leading zeros). The nginx configuration file Dustin has to add comments to has *m* commands. Nobody ever memorizes the ips of servers, so to understand the configuration better, Dustin has to comment the name of server that the ip belongs to at the end of each line (after each command). More formally, if a line is "command ip;" Dustin has to replace it with "command ip; #name" where name is the name of the server with ip equal to ip.
Dustin doesn't know anything about nginx, so he panicked again and his friends asked you to do his task for him.
Input Specification:
The first line of input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000).
The next *n* lines contain the names and ips of the servers. Each line contains a string name, name of the server and a string ip, ip of the server, separated by space (1<=≤<=|*name*|<=≤<=10, *name* only consists of English lowercase letters). It is guaranteed that all ip are distinct.
The next *m* lines contain the commands in the configuration file. Each line is of form "command ip;" (1<=≤<=|*command*|<=≤<=10, command only consists of English lowercase letters). It is guaranteed that ip belongs to one of the *n* school servers.
Output Specification:
Print *m* lines, the commands in the configuration file after Dustin did his task.
Demo Input:
['2 2\nmain 192.168.0.2\nreplica 192.168.0.1\nblock 192.168.0.1;\nproxy 192.168.0.2;\n', '3 5\ngoogle 8.8.8.8\ncodeforces 212.193.33.27\nserver 138.197.64.57\nredirect 138.197.64.57;\nblock 8.8.8.8;\ncf 212.193.33.27;\nunblock 8.8.8.8;\ncheck 138.197.64.57;\n']
Demo Output:
['block 192.168.0.1; #replica\nproxy 192.168.0.2; #main\n', 'redirect 138.197.64.57; #server\nblock 8.8.8.8; #google\ncf 212.193.33.27; #codeforces\nunblock 8.8.8.8; #google\ncheck 138.197.64.57; #server\n']
Note:
none | ```python
n, m = map(int, input().split())
d={}
for i in range(n):
name, ip = input().split()
d[ip] = name
for i in range(m):
name, ip = input().split()
print(name,ip,"#"+d[ip[:-1]])
``` | 3 |
|
71 | A | Way Too Long Words | PROGRAMMING | 800 | [
"strings"
] | A. Way Too Long Words | 1 | 256 | Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes.
Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n".
You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters. | Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data. | [
"4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n"
] | [
"word\nl10n\ni18n\np43s\n"
] | none | 500 | [
{
"input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis",
"output": "word\nl10n\ni18n\np43s"
},
{
"input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm",
"output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m"
},
{
"input": "3\nnjfngnrurunrgunrunvurn\njfvnjfdnvjdbfvsbdubruvbubvkdb\nksdnvidnviudbvibd",
"output": "n20n\nj27b\nk15d"
},
{
"input": "1\ntcyctkktcctrcyvbyiuhihhhgyvyvyvyvjvytchjckt",
"output": "t41t"
},
{
"input": "24\nyou\nare\nregistered\nfor\npractice\nyou\ncan\nsolve\nproblems\nunofficially\nresults\ncan\nbe\nfound\nin\nthe\ncontest\nstatus\nand\nin\nthe\nbottom\nof\nstandings",
"output": "you\nare\nregistered\nfor\npractice\nyou\ncan\nsolve\nproblems\nu10y\nresults\ncan\nbe\nfound\nin\nthe\ncontest\nstatus\nand\nin\nthe\nbottom\nof\nstandings"
},
{
"input": "1\na",
"output": "a"
},
{
"input": "26\na\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz",
"output": "a\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz"
},
{
"input": "1\nabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij",
"output": "a98j"
},
{
"input": "10\ngyartjdxxlcl\nfzsck\nuidwu\nxbymclornemdmtj\nilppyoapitawgje\ncibzc\ndrgbeu\nhezplmsdekhhbo\nfeuzlrimbqbytdu\nkgdco",
"output": "g10l\nfzsck\nuidwu\nx13j\ni13e\ncibzc\ndrgbeu\nh12o\nf13u\nkgdco"
},
{
"input": "20\nlkpmx\nkovxmxorlgwaomlswjxlpnbvltfv\nhykasjxqyjrmybejnmeumzha\ntuevlumpqbbhbww\nqgqsphvrmupxxc\ntrissbaf\nqfgrlinkzvzqdryckaizutd\nzzqtoaxkvwoscyx\noswytrlnhpjvvnwookx\nlpuzqgec\ngyzqfwxggtvpjhzmzmdw\nrlxjgmvdftvrmvbdwudra\nvsntnjpepnvdaxiporggmglhagv\nxlvcqkqgcrbgtgglj\nlyxwxbiszyhlsrgzeedzprbmcpduvq\nyrmqqvrkqskqukzqrwukpsifgtdc\nxpuohcsjhhuhvr\nvvlfrlxpvqejngwrbfbpmqeirxlw\nsvmasocxdvadmaxtrpakysmeaympy\nyuflqboqfdt",
"output": "lkpmx\nk26v\nh22a\nt13w\nq12c\ntrissbaf\nq21d\nz13x\no17x\nlpuzqgec\ng18w\nr19a\nv25v\nx15j\nl28q\ny26c\nx12r\nv26w\ns27y\ny9t"
},
{
"input": "100\nm\nz\ns\nv\nd\nr\nv\ny\ny\ne\np\nt\nc\na\nn\nm\np\ng\ni\nj\nc\na\nb\nq\ne\nn\nv\no\nk\nx\nf\ni\nl\na\nq\nr\nu\nb\ns\nl\nc\nl\ne\nv\nj\nm\nx\nb\na\nq\nb\na\nf\nj\nv\nm\nq\nc\nt\nt\nn\nx\no\ny\nr\nu\nh\nm\nj\np\nj\nq\nz\ns\nj\no\ng\nc\nm\nn\no\nm\nr\no\ns\nt\nh\nr\np\nk\nb\nz\ng\no\nc\nc\nz\nz\ng\nr",
"output": "m\nz\ns\nv\nd\nr\nv\ny\ny\ne\np\nt\nc\na\nn\nm\np\ng\ni\nj\nc\na\nb\nq\ne\nn\nv\no\nk\nx\nf\ni\nl\na\nq\nr\nu\nb\ns\nl\nc\nl\ne\nv\nj\nm\nx\nb\na\nq\nb\na\nf\nj\nv\nm\nq\nc\nt\nt\nn\nx\no\ny\nr\nu\nh\nm\nj\np\nj\nq\nz\ns\nj\no\ng\nc\nm\nn\no\nm\nr\no\ns\nt\nh\nr\np\nk\nb\nz\ng\no\nc\nc\nz\nz\ng\nr"
}
] | 1,682,068,828 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 77 | 0 | t = int(input())
for i in range(t):
a = str(input())
n = len(a)
p = n
if(n>10):
p = str(n)
print(a[0]+p+a[n-1])
else:
print(a)
| Title: Way Too Long Words
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes.
Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n".
You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes.
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
Output Specification:
Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data.
Demo Input:
['4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n']
Demo Output:
['word\nl10n\ni18n\np43s\n']
Note:
none | ```python
t = int(input())
for i in range(t):
a = str(input())
n = len(a)
p = n
if(n>10):
p = str(n)
print(a[0]+p+a[n-1])
else:
print(a)
``` | 0 |
884 | D | Boxes And Balls | PROGRAMMING | 2,300 | [
"data structures",
"greedy"
] | null | null | Ivan has *n* different boxes. The first of them contains some balls of *n* different colors.
Ivan wants to play a strange game. He wants to distribute the balls into boxes in such a way that for every *i* (1<=≤<=*i*<=≤<=*n*) *i*-th box will contain all balls with color *i*.
In order to do this, Ivan will make some turns. Each turn he does the following:
1. Ivan chooses any non-empty box and takes all balls from this box; 1. Then Ivan chooses any *k* empty boxes (the box from the first step becomes empty, and Ivan is allowed to choose it), separates the balls he took on the previous step into *k* non-empty groups and puts each group into one of the boxes. He should put each group into a separate box. He can choose either *k*<==<=2 or *k*<==<=3.
The penalty of the turn is the number of balls Ivan takes from the box during the first step of the turn. And penalty of the game is the total penalty of turns made by Ivan until he distributes all balls to corresponding boxes.
Help Ivan to determine the minimum possible penalty of the game! | The first line contains one integer number *n* (1<=≤<=*n*<=≤<=200000) — the number of boxes and colors.
The second line contains *n* integer numbers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=109), where *a**i* is the number of balls with color *i*. | Print one number — the minimum possible penalty of the game. | [
"3\n1 2 3\n",
"4\n2 3 4 5\n"
] | [
"6\n",
"19\n"
] | In the first example you take all the balls from the first box, choose *k* = 3 and sort all colors to corresponding boxes. Penalty is 6.
In the second example you make two turns:
1. Take all the balls from the first box, choose *k* = 3, put balls of color 3 to the third box, of color 4 — to the fourth box and the rest put back into the first box. Penalty is 14; 1. Take all the balls from the first box, choose *k* = 2, put balls of color 1 to the first box, of color 2 — to the second box. Penalty is 5.
Total penalty is 19. | 0 | [
{
"input": "3\n1 2 3",
"output": "6"
},
{
"input": "4\n2 3 4 5",
"output": "19"
},
{
"input": "6\n1 4 4 4 4 4",
"output": "38"
},
{
"input": "8\n821407370 380061316 428719552 90851747 825473738 704702117 845629927 245820158",
"output": "8176373828"
},
{
"input": "1\n10",
"output": "0"
},
{
"input": "1\n4",
"output": "0"
},
{
"input": "1\n12312",
"output": "0"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "2\n3 4",
"output": "7"
}
] | 1,509,116,065 | 2,965 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | n = int(input())
l = [0] + [int(i) for i in input().split(" ")]
if n == 1:
print(0)
exit(0)
if n == 2 or n == 3:
print(sum(l))
exit(0)
s = [0] * (n+1)
for i in range(1,n+1):
s[i] = s[i-1] + l[i]
s.reverse()
#print(s)
r = 0
for i in range(0,n+1,2):
r += s[i]
if n % 2 == 1:
r -= s[-2]
print(r) | Title: Boxes And Balls
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ivan has *n* different boxes. The first of them contains some balls of *n* different colors.
Ivan wants to play a strange game. He wants to distribute the balls into boxes in such a way that for every *i* (1<=≤<=*i*<=≤<=*n*) *i*-th box will contain all balls with color *i*.
In order to do this, Ivan will make some turns. Each turn he does the following:
1. Ivan chooses any non-empty box and takes all balls from this box; 1. Then Ivan chooses any *k* empty boxes (the box from the first step becomes empty, and Ivan is allowed to choose it), separates the balls he took on the previous step into *k* non-empty groups and puts each group into one of the boxes. He should put each group into a separate box. He can choose either *k*<==<=2 or *k*<==<=3.
The penalty of the turn is the number of balls Ivan takes from the box during the first step of the turn. And penalty of the game is the total penalty of turns made by Ivan until he distributes all balls to corresponding boxes.
Help Ivan to determine the minimum possible penalty of the game!
Input Specification:
The first line contains one integer number *n* (1<=≤<=*n*<=≤<=200000) — the number of boxes and colors.
The second line contains *n* integer numbers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=109), where *a**i* is the number of balls with color *i*.
Output Specification:
Print one number — the minimum possible penalty of the game.
Demo Input:
['3\n1 2 3\n', '4\n2 3 4 5\n']
Demo Output:
['6\n', '19\n']
Note:
In the first example you take all the balls from the first box, choose *k* = 3 and sort all colors to corresponding boxes. Penalty is 6.
In the second example you make two turns:
1. Take all the balls from the first box, choose *k* = 3, put balls of color 3 to the third box, of color 4 — to the fourth box and the rest put back into the first box. Penalty is 14; 1. Take all the balls from the first box, choose *k* = 2, put balls of color 1 to the first box, of color 2 — to the second box. Penalty is 5.
Total penalty is 19. | ```python
n = int(input())
l = [0] + [int(i) for i in input().split(" ")]
if n == 1:
print(0)
exit(0)
if n == 2 or n == 3:
print(sum(l))
exit(0)
s = [0] * (n+1)
for i in range(1,n+1):
s[i] = s[i-1] + l[i]
s.reverse()
#print(s)
r = 0
for i in range(0,n+1,2):
r += s[i]
if n % 2 == 1:
r -= s[-2]
print(r)
``` | 0 |
|
867 | A | Between the Offices | PROGRAMMING | 800 | [
"implementation"
] | null | null | As you may know, MemSQL has American offices in both San Francisco and Seattle. Being a manager in the company, you travel a lot between the two cities, always by plane.
You prefer flying from Seattle to San Francisco than in the other direction, because it's warmer in San Francisco. You are so busy that you don't remember the number of flights you have made in either direction. However, for each of the last *n* days you know whether you were in San Francisco office or in Seattle office. You always fly at nights, so you never were at both offices on the same day. Given this information, determine if you flew more times from Seattle to San Francisco during the last *n* days, or not. | The first line of input contains single integer *n* (2<=≤<=*n*<=≤<=100) — the number of days.
The second line contains a string of length *n* consisting of only capital 'S' and 'F' letters. If the *i*-th letter is 'S', then you were in Seattle office on that day. Otherwise you were in San Francisco. The days are given in chronological order, i.e. today is the last day in this sequence. | Print "YES" if you flew more times from Seattle to San Francisco, and "NO" otherwise.
You can print each letter in any case (upper or lower). | [
"4\nFSSF\n",
"2\nSF\n",
"10\nFFFFFFFFFF\n",
"10\nSSFFSFFSFF\n"
] | [
"NO\n",
"YES\n",
"NO\n",
"YES\n"
] | In the first example you were initially at San Francisco, then flew to Seattle, were there for two days and returned to San Francisco. You made one flight in each direction, so the answer is "NO".
In the second example you just flew from Seattle to San Francisco, so the answer is "YES".
In the third example you stayed the whole period in San Francisco, so the answer is "NO".
In the fourth example if you replace 'S' with ones, and 'F' with zeros, you'll get the first few digits of π in binary representation. Not very useful information though. | 500 | [
{
"input": "4\nFSSF",
"output": "NO"
},
{
"input": "2\nSF",
"output": "YES"
},
{
"input": "10\nFFFFFFFFFF",
"output": "NO"
},
{
"input": "10\nSSFFSFFSFF",
"output": "YES"
},
{
"input": "20\nSFSFFFFSSFFFFSSSSFSS",
"output": "NO"
},
{
"input": "20\nSSFFFFFSFFFFFFFFFFFF",
"output": "YES"
},
{
"input": "20\nSSFSFSFSFSFSFSFSSFSF",
"output": "YES"
},
{
"input": "20\nSSSSFSFSSFSFSSSSSSFS",
"output": "NO"
},
{
"input": "100\nFFFSFSFSFSSFSFFSSFFFFFSSSSFSSFFFFSFFFFFSFFFSSFSSSFFFFSSFFSSFSFFSSFSSSFSFFSFSFFSFSFFSSFFSFSSSSFSFSFSS",
"output": "NO"
},
{
"input": "100\nFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF",
"output": "NO"
},
{
"input": "100\nFFFFFFFFFFFFFFFFFFFFFFFFFFSFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFSFFFFFFFFFFFFFFFFFSS",
"output": "NO"
},
{
"input": "100\nFFFFFFFFFFFFFSFFFFFFFFFSFSSFFFFFFFFFFFFFFFFFFFFFFSFFSFFFFFSFFFFFFFFSFFFFFFFFFFFFFSFFFFFFFFSFFFFFFFSF",
"output": "NO"
},
{
"input": "100\nSFFSSFFFFFFSSFFFSSFSFFFFFSSFFFSFFFFFFSFSSSFSFSFFFFSFSSFFFFFFFFSFFFFFSFFFFFSSFFFSFFSFSFFFFSFFSFFFFFFF",
"output": "YES"
},
{
"input": "100\nFFFFSSSSSFFSSSFFFSFFFFFSFSSFSFFSFFSSFFSSFSFFFFFSFSFSFSFFFFFFFFFSFSFFSFFFFSFSFFFFFFFFFFFFSFSSFFSSSSFF",
"output": "NO"
},
{
"input": "100\nFFFFFFFFFFFFSSFFFFSFSFFFSFSSSFSSSSSFSSSSFFSSFFFSFSFSSFFFSSSFFSFSFSSFSFSSFSFFFSFFFFFSSFSFFFSSSFSSSFFS",
"output": "NO"
},
{
"input": "100\nFFFSSSFSFSSSSFSSFSFFSSSFFSSFSSFFSSFFSFSSSSFFFSFFFSFSFSSSFSSFSFSFSFFSSSSSFSSSFSFSFFSSFSFSSFFSSFSFFSFS",
"output": "NO"
},
{
"input": "100\nFFSSSSFSSSFSSSSFSSSFFSFSSFFSSFSSSFSSSFFSFFSSSSSSSSSSSSFSSFSSSSFSFFFSSFFFFFFSFSFSSSSSSFSSSFSFSSFSSFSS",
"output": "NO"
},
{
"input": "100\nSSSFFFSSSSFFSSSSSFSSSSFSSSFSSSSSFSSSSSSSSFSFFSSSFFSSFSSSSFFSSSSSSFFSSSSFSSSSSSFSSSFSSSSSSSFSSSSFSSSS",
"output": "NO"
},
{
"input": "100\nFSSSSSSSSSSSFSSSSSSSSSSSSSSSSFSSSSSSFSSSSSSSSSSSSSFSSFSSSSSFSSFSSSSSSSSSFFSSSSSFSFSSSFFSSSSSSSSSSSSS",
"output": "NO"
},
{
"input": "100\nSSSSSSSSSSSSSFSSSSSSSSSSSSFSSSFSSSSSSSSSSSSSSSSSSSSSSSSSSSSSFSSSSSSSSSSSSSSSSFSFSSSSSSSSSSSSSSSSSSFS",
"output": "NO"
},
{
"input": "100\nSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS",
"output": "NO"
},
{
"input": "100\nSFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF",
"output": "YES"
},
{
"input": "100\nSFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFSFSFFFFFFFFFFFSFSFFFFFFFFFFFFFSFFFFFFFFFFFFFFFFFFFFFFFFF",
"output": "YES"
},
{
"input": "100\nSFFFFFFFFFFFFSSFFFFSFFFFFFFFFFFFFFFFFFFSFFFSSFFFFSFSFFFSFFFFFFFFFFFFFFFSSFFFFFFFFSSFFFFFFFFFFFFFFSFF",
"output": "YES"
},
{
"input": "100\nSFFSSSFFSFSFSFFFFSSFFFFSFFFFFFFFSFSFFFSFFFSFFFSFFFFSFSFFFFFFFSFFFFFFFFFFSFFSSSFFSSFFFFSFFFFSFFFFSFFF",
"output": "YES"
},
{
"input": "100\nSFFFSFFFFSFFFSSFFFSFSFFFSFFFSSFSFFFFFSFFFFFFFFSFSFSFFSFFFSFSSFSFFFSFSFFSSFSFSSSFFFFFFSSFSFFSFFFFFFFF",
"output": "YES"
},
{
"input": "100\nSSSSFFFFSFFFFFFFSFFFFSFSFFFFSSFFFFFFFFFSFFSSFFFFFFSFSFSSFSSSFFFFFFFSFSFFFSSSFFFFFFFSFFFSSFFFFSSFFFSF",
"output": "YES"
},
{
"input": "100\nSSSFSSFFFSFSSSSFSSFSSSSFSSFFFFFSFFSSSSFFSSSFSSSFSSSSFSSSSFSSSSSSSFSFSSFFFSSFFSFFSSSSFSSFFSFSSFSFFFSF",
"output": "YES"
},
{
"input": "100\nSFFSFSSSSSSSFFSSSFSSSSFSFSSFFFSSSSSSFSSSSFSSFSSSFSSSSSSSFSSFSFFFSSFSSFSFSFSSSSSSSSSSSSFFFFSSSSSFSFFF",
"output": "YES"
},
{
"input": "100\nSSSFSFFSFSFFSSSSSFSSSFSSSFFFSSSSSSSSSFSFSFSSSSFSFSSFFFFFSSSSSSSSSSSSSSSSSSSFFSSSSSFSFSSSSFFSSSSFSSSF",
"output": "YES"
},
{
"input": "100\nSSSFSSSSSSSSSSFSSSSFSSSSSSFSSSSSSFSSSSSSSSSSSSSSFSSSFSSSFSSSSSSSSSSSFSSSSSSFSFSSSSFSSSSSSFSSSSSSSSFF",
"output": "YES"
},
{
"input": "100\nSSSSSSSSSSSSSSSFSFSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSFFSSSSSSSSSFSSSSSSSSSSSSSSSSSF",
"output": "YES"
},
{
"input": "100\nSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSF",
"output": "YES"
},
{
"input": "2\nSS",
"output": "NO"
}
] | 1,616,602,964 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 1 | 61 | 0 | n=int(input())
# c=input().count
c=str(input())
# c=c.replace(" ","")
if n<2:
if c[0]=="S":
print("YES")
else:
print("NO")
else:
if c[0]=="S" and c[2]!="S":
print("YES")
else:
print("NO") | Title: Between the Offices
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As you may know, MemSQL has American offices in both San Francisco and Seattle. Being a manager in the company, you travel a lot between the two cities, always by plane.
You prefer flying from Seattle to San Francisco than in the other direction, because it's warmer in San Francisco. You are so busy that you don't remember the number of flights you have made in either direction. However, for each of the last *n* days you know whether you were in San Francisco office or in Seattle office. You always fly at nights, so you never were at both offices on the same day. Given this information, determine if you flew more times from Seattle to San Francisco during the last *n* days, or not.
Input Specification:
The first line of input contains single integer *n* (2<=≤<=*n*<=≤<=100) — the number of days.
The second line contains a string of length *n* consisting of only capital 'S' and 'F' letters. If the *i*-th letter is 'S', then you were in Seattle office on that day. Otherwise you were in San Francisco. The days are given in chronological order, i.e. today is the last day in this sequence.
Output Specification:
Print "YES" if you flew more times from Seattle to San Francisco, and "NO" otherwise.
You can print each letter in any case (upper or lower).
Demo Input:
['4\nFSSF\n', '2\nSF\n', '10\nFFFFFFFFFF\n', '10\nSSFFSFFSFF\n']
Demo Output:
['NO\n', 'YES\n', 'NO\n', 'YES\n']
Note:
In the first example you were initially at San Francisco, then flew to Seattle, were there for two days and returned to San Francisco. You made one flight in each direction, so the answer is "NO".
In the second example you just flew from Seattle to San Francisco, so the answer is "YES".
In the third example you stayed the whole period in San Francisco, so the answer is "NO".
In the fourth example if you replace 'S' with ones, and 'F' with zeros, you'll get the first few digits of π in binary representation. Not very useful information though. | ```python
n=int(input())
# c=input().count
c=str(input())
# c=c.replace(" ","")
if n<2:
if c[0]=="S":
print("YES")
else:
print("NO")
else:
if c[0]=="S" and c[2]!="S":
print("YES")
else:
print("NO")
``` | -1 |
|
907 | A | Masha and Bears | PROGRAMMING | 1,300 | [
"brute force",
"implementation"
] | null | null | A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larger than the middle car, and the middle car is strictly larger than the smallest car.
Masha came to test these cars. She could climb into all cars, but she liked only the smallest car.
It's known that a character with size *a* can climb into some car with size *b* if and only if *a*<=≤<=*b*, he or she likes it if and only if he can climb into this car and 2*a*<=≥<=*b*.
You are given sizes of bears and Masha. Find out some possible integer non-negative sizes of cars. | You are given four integers *V*1, *V*2, *V*3, *V**m*(1<=≤<=*V**i*<=≤<=100) — sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that *V*1<=><=*V*2<=><=*V*3. | Output three integers — sizes of father bear's car, mother bear's car and son bear's car, respectively.
If there are multiple possible solutions, print any.
If there is no solution, print "-1" (without quotes). | [
"50 30 10 10\n",
"100 50 10 21\n"
] | [
"50\n30\n10\n",
"-1\n"
] | In first test case all conditions for cars' sizes are satisfied.
In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20. | 500 | [
{
"input": "50 30 10 10",
"output": "50\n30\n10"
},
{
"input": "100 50 10 21",
"output": "-1"
},
{
"input": "100 50 19 10",
"output": "100\n50\n19"
},
{
"input": "99 50 25 49",
"output": "100\n99\n49"
},
{
"input": "3 2 1 1",
"output": "4\n3\n1"
},
{
"input": "100 99 98 100",
"output": "-1"
},
{
"input": "100 40 30 40",
"output": "-1"
},
{
"input": "100 50 19 25",
"output": "100\n51\n25"
},
{
"input": "100 50 19 30",
"output": "100\n61\n30"
},
{
"input": "49 48 25 49",
"output": "-1"
},
{
"input": "48 47 23 46",
"output": "94\n93\n46"
},
{
"input": "37 23 16 20",
"output": "42\n41\n20"
},
{
"input": "98 2 1 1",
"output": "98\n3\n1"
},
{
"input": "99 22 13 14",
"output": "99\n29\n14"
},
{
"input": "97 95 3 2",
"output": "97\n95\n3"
},
{
"input": "27 3 2 3",
"output": "-1"
},
{
"input": "13 7 6 2",
"output": "-1"
},
{
"input": "19 17 11 6",
"output": "19\n17\n11"
},
{
"input": "15 6 4 5",
"output": "15\n11\n5"
},
{
"input": "21 3 1 3",
"output": "-1"
},
{
"input": "100 99 98 97",
"output": "196\n195\n98"
},
{
"input": "99 32 13 5",
"output": "-1"
},
{
"input": "5 4 3 1",
"output": "-1"
},
{
"input": "50 20 4 8",
"output": "50\n20\n8"
},
{
"input": "60 30 10 1",
"output": "-1"
},
{
"input": "100 50 10 1",
"output": "-1"
},
{
"input": "40 30 20 10",
"output": "40\n30\n20"
},
{
"input": "50 49 5 10",
"output": "50\n49\n10"
},
{
"input": "99 98 50 97",
"output": "196\n195\n97"
},
{
"input": "50 30 10 5",
"output": "50\n30\n10"
},
{
"input": "4 3 2 1",
"output": "4\n3\n2"
},
{
"input": "100 50 3 1",
"output": "-1"
}
] | 1,514,112,683 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 5,529,600 | v1, v2, v3, v4=map(int, input().split())
if v2<=v4 or 2*v3<v4 or v2<=2*v4:
print(-1)
else:
print (v1)
print (v2)
print (v4)
| Title: Masha and Bears
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larger than the middle car, and the middle car is strictly larger than the smallest car.
Masha came to test these cars. She could climb into all cars, but she liked only the smallest car.
It's known that a character with size *a* can climb into some car with size *b* if and only if *a*<=≤<=*b*, he or she likes it if and only if he can climb into this car and 2*a*<=≥<=*b*.
You are given sizes of bears and Masha. Find out some possible integer non-negative sizes of cars.
Input Specification:
You are given four integers *V*1, *V*2, *V*3, *V**m*(1<=≤<=*V**i*<=≤<=100) — sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that *V*1<=><=*V*2<=><=*V*3.
Output Specification:
Output three integers — sizes of father bear's car, mother bear's car and son bear's car, respectively.
If there are multiple possible solutions, print any.
If there is no solution, print "-1" (without quotes).
Demo Input:
['50 30 10 10\n', '100 50 10 21\n']
Demo Output:
['50\n30\n10\n', '-1\n']
Note:
In first test case all conditions for cars' sizes are satisfied.
In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20. | ```python
v1, v2, v3, v4=map(int, input().split())
if v2<=v4 or 2*v3<v4 or v2<=2*v4:
print(-1)
else:
print (v1)
print (v2)
print (v4)
``` | 0 |
|
797 | C | Minimal string | PROGRAMMING | 1,700 | [
"data structures",
"greedy",
"strings"
] | null | null | Petya recieved a gift of a string *s* with length up to 105 characters for his birthday. He took two more empty strings *t* and *u* and decided to play a game. This game has two possible moves:
- Extract the first character of *s* and append *t* with this character. - Extract the last character of *t* and append *u* with this character.
Petya wants to get strings *s* and *t* empty and string *u* lexicographically minimal.
You should write a program that will help Petya win the game. | First line contains non-empty string *s* (1<=≤<=|*s*|<=≤<=105), consisting of lowercase English letters. | Print resulting string *u*. | [
"cab\n",
"acdb\n"
] | [
"abc\n",
"abdc\n"
] | none | 0 | [
{
"input": "cab",
"output": "abc"
},
{
"input": "acdb",
"output": "abdc"
},
{
"input": "a",
"output": "a"
},
{
"input": "ab",
"output": "ab"
},
{
"input": "ba",
"output": "ab"
},
{
"input": "dijee",
"output": "deeji"
},
{
"input": "bhrmc",
"output": "bcmrh"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "bababaaababaabbbbbabbbbbbaaabbabaaaaabbbbbaaaabbbbabaabaabababbbabbabbabaaababbabbababaaaaabaaaabbba",
"output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
},
{
"input": "bccbbcccbccbacacbaccaababcbaababaaaaabcaaabcaacbabcaababaabaccacacccbacbcacbbbaacaaccccabbbbacbcbbba",
"output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbcbcbbbbcccccbbbccbcbccccccbbbcbbccbcbbbbcbbccbccbccbcccbbccb"
},
{
"input": "eejahjfbbcdhbieiigaihidhageiechaadieecaaehcehjbddgcjgagdfgffdaaihbecebdjhjagghecdhbhdfbedhfhfafbjajg",
"output": "aaaaaaaaaaaaagjjbffhfhdebfdhbhdcehggjhjdbecebhidffgfdggjcgddbjhecheceeidhceieghdihigiieibhdcbbfjhjee"
},
{
"input": "bnrdfnybkzepmluyrhofwnwvfmkdwolvyzrqhuhztvlwjldqmoyxzytpfmrgouymeupxrvpbesyxixnrfbxnqcwgmgjstknqtwrr",
"output": "bbbbcggjknqrrwttsmwqnxfrnxixysepvrxpuemyuogrmfptyzxyomqdljwlvtzhuhqrzyvlowdkmfvwnwfohryulmpezkynfdrn"
},
{
"input": "bcaeaae",
"output": "aaaecbe"
},
{
"input": "edcadcbcdd",
"output": "abccdcddde"
},
{
"input": "a",
"output": "a"
},
{
"input": "a",
"output": "a"
},
{
"input": "a",
"output": "a"
},
{
"input": "b",
"output": "b"
},
{
"input": "b",
"output": "b"
},
{
"input": "a",
"output": "a"
},
{
"input": "c",
"output": "c"
},
{
"input": "a",
"output": "a"
},
{
"input": "b",
"output": "b"
},
{
"input": "c",
"output": "c"
},
{
"input": "b",
"output": "b"
},
{
"input": "a",
"output": "a"
},
{
"input": "e",
"output": "e"
},
{
"input": "b",
"output": "b"
},
{
"input": "b",
"output": "b"
},
{
"input": "aa",
"output": "aa"
},
{
"input": "aa",
"output": "aa"
},
{
"input": "aa",
"output": "aa"
},
{
"input": "aa",
"output": "aa"
},
{
"input": "bb",
"output": "bb"
},
{
"input": "bb",
"output": "bb"
},
{
"input": "ba",
"output": "ab"
},
{
"input": "ca",
"output": "ac"
},
{
"input": "ab",
"output": "ab"
},
{
"input": "cb",
"output": "bc"
},
{
"input": "bb",
"output": "bb"
},
{
"input": "aa",
"output": "aa"
},
{
"input": "da",
"output": "ad"
},
{
"input": "ab",
"output": "ab"
},
{
"input": "cd",
"output": "cd"
},
{
"input": "aaa",
"output": "aaa"
},
{
"input": "aaa",
"output": "aaa"
},
{
"input": "aaa",
"output": "aaa"
},
{
"input": "aab",
"output": "aab"
},
{
"input": "aaa",
"output": "aaa"
},
{
"input": "baa",
"output": "aab"
},
{
"input": "bab",
"output": "abb"
},
{
"input": "baa",
"output": "aab"
},
{
"input": "ccc",
"output": "ccc"
},
{
"input": "ddd",
"output": "ddd"
},
{
"input": "ccd",
"output": "ccd"
},
{
"input": "bca",
"output": "acb"
},
{
"input": "cde",
"output": "cde"
},
{
"input": "ece",
"output": "cee"
},
{
"input": "bdd",
"output": "bdd"
},
{
"input": "aaaa",
"output": "aaaa"
},
{
"input": "aaaa",
"output": "aaaa"
},
{
"input": "aaaa",
"output": "aaaa"
},
{
"input": "abaa",
"output": "aaab"
},
{
"input": "abab",
"output": "aabb"
},
{
"input": "bbbb",
"output": "bbbb"
},
{
"input": "bbba",
"output": "abbb"
},
{
"input": "caba",
"output": "aabc"
},
{
"input": "ccbb",
"output": "bbcc"
},
{
"input": "abac",
"output": "aabc"
},
{
"input": "daba",
"output": "aabd"
},
{
"input": "cdbb",
"output": "bbdc"
},
{
"input": "bddd",
"output": "bddd"
},
{
"input": "dacb",
"output": "abcd"
},
{
"input": "abcc",
"output": "abcc"
},
{
"input": "aaaaa",
"output": "aaaaa"
},
{
"input": "aaaaa",
"output": "aaaaa"
},
{
"input": "aaaaa",
"output": "aaaaa"
},
{
"input": "baaab",
"output": "aaabb"
},
{
"input": "aabbb",
"output": "aabbb"
},
{
"input": "aabaa",
"output": "aaaab"
},
{
"input": "abcba",
"output": "aabcb"
},
{
"input": "bacbc",
"output": "abbcc"
},
{
"input": "bacba",
"output": "aabcb"
},
{
"input": "bdbda",
"output": "adbdb"
},
{
"input": "accbb",
"output": "abbcc"
},
{
"input": "dbccc",
"output": "bcccd"
},
{
"input": "decca",
"output": "acced"
},
{
"input": "dbbdd",
"output": "bbddd"
},
{
"input": "accec",
"output": "accce"
},
{
"input": "aaaaaa",
"output": "aaaaaa"
},
{
"input": "aaaaaa",
"output": "aaaaaa"
},
{
"input": "aaaaaa",
"output": "aaaaaa"
},
{
"input": "bbbbab",
"output": "abbbbb"
},
{
"input": "bbbbab",
"output": "abbbbb"
},
{
"input": "aaaaba",
"output": "aaaaab"
},
{
"input": "cbbbcc",
"output": "bbbccc"
},
{
"input": "aaacac",
"output": "aaaacc"
},
{
"input": "bacbbc",
"output": "abbbcc"
},
{
"input": "cacacc",
"output": "aacccc"
},
{
"input": "badbdc",
"output": "abbcdd"
},
{
"input": "ddadad",
"output": "aadddd"
},
{
"input": "ccdece",
"output": "cccede"
},
{
"input": "eecade",
"output": "acdeee"
},
{
"input": "eabdcb",
"output": "abbcde"
},
{
"input": "aaaaaaa",
"output": "aaaaaaa"
},
{
"input": "aaaaaaa",
"output": "aaaaaaa"
},
{
"input": "aaaaaaa",
"output": "aaaaaaa"
},
{
"input": "aaabbaa",
"output": "aaaaabb"
},
{
"input": "baaabab",
"output": "aaaabbb"
},
{
"input": "bbababa",
"output": "aaabbbb"
},
{
"input": "bcccacc",
"output": "acccbcc"
},
{
"input": "cbbcccc",
"output": "bbccccc"
},
{
"input": "abacaaa",
"output": "aaaaacb"
},
{
"input": "ccdbdac",
"output": "acdbdcc"
},
{
"input": "bbacaba",
"output": "aaabcbb"
},
{
"input": "abbaccc",
"output": "aabbccc"
},
{
"input": "bdcbcab",
"output": "abcbcdb"
},
{
"input": "dabcbce",
"output": "abbccde"
},
{
"input": "abaaabe",
"output": "aaaabbe"
},
{
"input": "aaaaaaaa",
"output": "aaaaaaaa"
},
{
"input": "aaaaaaaa",
"output": "aaaaaaaa"
},
{
"input": "aaaaaaaa",
"output": "aaaaaaaa"
},
{
"input": "ababbbba",
"output": "aaabbbbb"
},
{
"input": "aaaaaaba",
"output": "aaaaaaab"
},
{
"input": "babbbaab",
"output": "aaabbbbb"
},
{
"input": "bcaccaab",
"output": "aaabcccb"
},
{
"input": "bbccaabc",
"output": "aabccbbc"
},
{
"input": "cacaaaac",
"output": "aaaaaccc"
},
{
"input": "daacbddc",
"output": "aabccddd"
},
{
"input": "cdbdcdaa",
"output": "aadcdbdc"
},
{
"input": "bccbdacd",
"output": "acdbccbd"
},
{
"input": "abbeaade",
"output": "aaadebbe"
},
{
"input": "ccabecba",
"output": "aabcebcc"
},
{
"input": "ececaead",
"output": "aadecece"
},
{
"input": "aaaaaaaaa",
"output": "aaaaaaaaa"
},
{
"input": "aaaaaaaaa",
"output": "aaaaaaaaa"
},
{
"input": "aaaaaaaaa",
"output": "aaaaaaaaa"
},
{
"input": "aabaaabbb",
"output": "aaaaabbbb"
},
{
"input": "abbbbbaab",
"output": "aaabbbbbb"
},
{
"input": "bbbaababb",
"output": "aaabbbbbb"
},
{
"input": "babcaaccb",
"output": "aaabcccbb"
},
{
"input": "ccbcabaac",
"output": "aaabcbccc"
},
{
"input": "caaaccccb",
"output": "aaabccccc"
},
{
"input": "abbcdbddb",
"output": "abbbbdddc"
},
{
"input": "dbcaacbbb",
"output": "aabbbccbd"
},
{
"input": "cadcbddac",
"output": "aacddbcdc"
},
{
"input": "ecebadadb",
"output": "aabddbece"
},
{
"input": "bdbeeccdd",
"output": "bbccddeed"
},
{
"input": "daaedecda",
"output": "aaadceded"
},
{
"input": "aaaaaaaaaa",
"output": "aaaaaaaaaa"
},
{
"input": "aaaaaaaaaa",
"output": "aaaaaaaaaa"
},
{
"input": "aaaaaaaaaa",
"output": "aaaaaaaaaa"
},
{
"input": "abaaaaabbb",
"output": "aaaaaabbbb"
},
{
"input": "bbaaaabaaa",
"output": "aaaaaaabbb"
},
{
"input": "bbabbaaaaa",
"output": "aaaaaabbbb"
},
{
"input": "cbaabcaacc",
"output": "aaaacbbccc"
},
{
"input": "aaaaccccab",
"output": "aaaaabcccc"
},
{
"input": "bccaccaacc",
"output": "aaaccccbcc"
},
{
"input": "dbdccdcacd",
"output": "accdccdbdd"
},
{
"input": "caaddaaccb",
"output": "aaaabccddc"
},
{
"input": "adbbabcbdc",
"output": "aabbbbccdd"
},
{
"input": "cdeabdbbad",
"output": "aabbdbdedc"
},
{
"input": "eeddcbeeec",
"output": "bcceeeddee"
},
{
"input": "bbcebddeba",
"output": "abeddbecbb"
}
] | 1,641,625,507 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 11 | 124 | 0 | from collections import Counter, deque
import sys
inpu = sys.stdin.readline
prin = sys.stdout.write
def solve () :
s = inpu().rstrip('\n')
c = Counter(s)
c = dict(sorted(c.items(), key=lambda item: item[0]))
key = deque(c.keys())
stack = []
u = []
for i in range(len(s)) :
if s[i] == key[0] :
u.append(s[i])
c[s[i]] -= 1
if c[s[i]] == 0 :
key.popleft()
while (len(stack) > 0) and (stack[-1] == key[0]) :
u.append(stack.pop())
c[s[i]] -= 1
if c[s[i]] == 0 :
key.popleft()
else :
stack.append(s[i])
stack.reverse()
prin(''.join(map(str, u)) + ''.join(map(str, stack)) + '\n')
solve() | Title: Minimal string
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya recieved a gift of a string *s* with length up to 105 characters for his birthday. He took two more empty strings *t* and *u* and decided to play a game. This game has two possible moves:
- Extract the first character of *s* and append *t* with this character. - Extract the last character of *t* and append *u* with this character.
Petya wants to get strings *s* and *t* empty and string *u* lexicographically minimal.
You should write a program that will help Petya win the game.
Input Specification:
First line contains non-empty string *s* (1<=≤<=|*s*|<=≤<=105), consisting of lowercase English letters.
Output Specification:
Print resulting string *u*.
Demo Input:
['cab\n', 'acdb\n']
Demo Output:
['abc\n', 'abdc\n']
Note:
none | ```python
from collections import Counter, deque
import sys
inpu = sys.stdin.readline
prin = sys.stdout.write
def solve () :
s = inpu().rstrip('\n')
c = Counter(s)
c = dict(sorted(c.items(), key=lambda item: item[0]))
key = deque(c.keys())
stack = []
u = []
for i in range(len(s)) :
if s[i] == key[0] :
u.append(s[i])
c[s[i]] -= 1
if c[s[i]] == 0 :
key.popleft()
while (len(stack) > 0) and (stack[-1] == key[0]) :
u.append(stack.pop())
c[s[i]] -= 1
if c[s[i]] == 0 :
key.popleft()
else :
stack.append(s[i])
stack.reverse()
prin(''.join(map(str, u)) + ''.join(map(str, stack)) + '\n')
solve()
``` | 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,651,077,355 | 2,147,483,647 | Python 3 | OK | TESTS | 41 | 46 | 0 | n = int(input())
nums = list(map(int, input().split()))
top = max(nums)
output = 0
for item in nums:
output += top - item
print(output) | Title: Holiday Of Equality
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury.
Totally in Berland there are *n* citizens, 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
n = int(input())
nums = list(map(int, input().split()))
top = max(nums)
output = 0
for item in nums:
output += top - item
print(output)
``` | 3 |
|
832 | A | Sasha and Sticks | PROGRAMMING | 800 | [
"games",
"math"
] | null | null | It's one more school day now. Sasha doesn't like classes and is always bored at them. So, each day he invents some game and plays in it alone or with friends.
Today he invented one simple game to play with Lena, with whom he shares a desk. The rules are simple. Sasha draws *n* sticks in a row. After that the players take turns crossing out exactly *k* sticks from left or right in each turn. Sasha moves first, because he is the inventor of the game. If there are less than *k* sticks on the paper before some turn, the game ends. Sasha wins if he makes strictly more moves than Lena. Sasha wants to know the result of the game before playing, you are to help him. | The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=1018, *k*<=≤<=*n*) — the number of sticks drawn by Sasha and the number *k* — the number of sticks to be crossed out on each turn. | If Sasha wins, print "YES" (without quotes), otherwise print "NO" (without quotes).
You can print each letter in arbitrary case (upper of lower). | [
"1 1\n",
"10 4\n"
] | [
"YES\n",
"NO\n"
] | In the first example Sasha crosses out 1 stick, and then there are no sticks. So Lena can't make a move, and Sasha wins.
In the second example Sasha crosses out 4 sticks, then Lena crosses out 4 sticks, and after that there are only 2 sticks left. Sasha can't make a move. The players make equal number of moves, so Sasha doesn't win. | 500 | [
{
"input": "1 1",
"output": "YES"
},
{
"input": "10 4",
"output": "NO"
},
{
"input": "251656215122324104 164397544865601257",
"output": "YES"
},
{
"input": "963577813436662285 206326039287271924",
"output": "NO"
},
{
"input": "1000000000000000000 1",
"output": "NO"
},
{
"input": "253308697183523656 25332878317796706",
"output": "YES"
},
{
"input": "669038685745448997 501718093668307460",
"output": "YES"
},
{
"input": "116453141993601660 87060381463547965",
"output": "YES"
},
{
"input": "766959657 370931668",
"output": "NO"
},
{
"input": "255787422422806632 146884995820359999",
"output": "YES"
},
{
"input": "502007866464507926 71266379084204128",
"output": "YES"
},
{
"input": "257439908778973480 64157133126869976",
"output": "NO"
},
{
"input": "232709385 91708542",
"output": "NO"
},
{
"input": "252482458300407528 89907711721009125",
"output": "NO"
},
{
"input": "6 2",
"output": "YES"
},
{
"input": "6 3",
"output": "NO"
},
{
"input": "6 4",
"output": "YES"
},
{
"input": "6 5",
"output": "YES"
},
{
"input": "6 6",
"output": "YES"
},
{
"input": "258266151957056904 30153168463725364",
"output": "NO"
},
{
"input": "83504367885565783 52285355047292458",
"output": "YES"
},
{
"input": "545668929424440387 508692735816921376",
"output": "YES"
},
{
"input": "547321411485639939 36665750286082900",
"output": "NO"
},
{
"input": "548973893546839491 183137237979822911",
"output": "NO"
},
{
"input": "544068082 193116851",
"output": "NO"
},
{
"input": "871412474 749817171",
"output": "YES"
},
{
"input": "999999999 1247",
"output": "NO"
},
{
"input": "851941088 712987048",
"output": "YES"
},
{
"input": "559922900 418944886",
"output": "YES"
},
{
"input": "293908937 37520518",
"output": "YES"
},
{
"input": "650075786 130049650",
"output": "NO"
},
{
"input": "1000000000 1000000000",
"output": "YES"
},
{
"input": "548147654663723363 107422751713800746",
"output": "YES"
},
{
"input": "828159210 131819483",
"output": "NO"
},
{
"input": "6242634 4110365",
"output": "YES"
},
{
"input": "458601973 245084155",
"output": "YES"
},
{
"input": "349593257 18089089",
"output": "YES"
},
{
"input": "814768821 312514745",
"output": "NO"
},
{
"input": "697884949 626323363",
"output": "YES"
},
{
"input": "667011589 54866795",
"output": "NO"
},
{
"input": "1000000000000000000 2",
"output": "NO"
},
{
"input": "1000000000000000000 3",
"output": "YES"
},
{
"input": "1000000000000000000 4",
"output": "NO"
},
{
"input": "999999999999999 1",
"output": "YES"
},
{
"input": "17 4",
"output": "NO"
},
{
"input": "2 2",
"output": "YES"
},
{
"input": "1000000000000000 2",
"output": "NO"
},
{
"input": "12 4",
"output": "YES"
},
{
"input": "6 1",
"output": "NO"
},
{
"input": "2 1",
"output": "NO"
},
{
"input": "10000000005 1",
"output": "YES"
},
{
"input": "10000000000000009 2",
"output": "NO"
},
{
"input": "12457895452123 1",
"output": "YES"
},
{
"input": "999999999999999999 9",
"output": "YES"
},
{
"input": "1000000000000 3",
"output": "YES"
},
{
"input": "13099714659575475 6549849616514894",
"output": "NO"
},
{
"input": "100000000000000001 1",
"output": "YES"
},
{
"input": "825175814723458 324",
"output": "YES"
},
{
"input": "20 4",
"output": "YES"
},
{
"input": "100000176877 4",
"output": "YES"
},
{
"input": "100000 3",
"output": "YES"
},
{
"input": "946744073709551614 10",
"output": "YES"
}
] | 1,642,961,320 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | num , k = map(int, input().split())
turns = num // 4
if turns % 2 == 0:
print ("NO")
else:
print ("YES") | Title: Sasha and Sticks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It's one more school day now. Sasha doesn't like classes and is always bored at them. So, each day he invents some game and plays in it alone or with friends.
Today he invented one simple game to play with Lena, with whom he shares a desk. The rules are simple. Sasha draws *n* sticks in a row. After that the players take turns crossing out exactly *k* sticks from left or right in each turn. Sasha moves first, because he is the inventor of the game. If there are less than *k* sticks on the paper before some turn, the game ends. Sasha wins if he makes strictly more moves than Lena. Sasha wants to know the result of the game before playing, you are to help him.
Input Specification:
The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=1018, *k*<=≤<=*n*) — the number of sticks drawn by Sasha and the number *k* — the number of sticks to be crossed out on each turn.
Output Specification:
If Sasha wins, print "YES" (without quotes), otherwise print "NO" (without quotes).
You can print each letter in arbitrary case (upper of lower).
Demo Input:
['1 1\n', '10 4\n']
Demo Output:
['YES\n', 'NO\n']
Note:
In the first example Sasha crosses out 1 stick, and then there are no sticks. So Lena can't make a move, and Sasha wins.
In the second example Sasha crosses out 4 sticks, then Lena crosses out 4 sticks, and after that there are only 2 sticks left. Sasha can't make a move. The players make equal number of moves, so Sasha doesn't win. | ```python
num , k = map(int, input().split())
turns = num // 4
if turns % 2 == 0:
print ("NO")
else:
print ("YES")
``` | 0 |
|
154 | A | Hometask | PROGRAMMING | 1,600 | [
"greedy"
] | null | null | Sergey attends lessons of the *N*-ish language. Each lesson he receives a hometask. This time the task is to translate some sentence to the *N*-ish language. Sentences of the *N*-ish language can be represented as strings consisting of lowercase Latin letters without spaces or punctuation marks.
Sergey totally forgot about the task until half an hour before the next lesson and hastily scribbled something down. But then he recollected that in the last lesson he learned the grammar of *N*-ish. The spelling rules state that *N*-ish contains some "forbidden" pairs of letters: such letters can never occur in a sentence next to each other. Also, the order of the letters doesn't matter (for example, if the pair of letters "ab" is forbidden, then any occurrences of substrings "ab" and "ba" are also forbidden). Also, each pair has different letters and each letter occurs in no more than one forbidden pair.
Now Sergey wants to correct his sentence so that it doesn't contain any "forbidden" pairs of letters that stand next to each other. However, he is running out of time, so he decided to simply cross out some letters from the sentence. What smallest number of letters will he have to cross out? When a letter is crossed out, it is "removed" so that the letters to its left and right (if they existed), become neighboring. For example, if we cross out the first letter from the string "aba", we get the string "ba", and if we cross out the second letter, we get "aa". | The first line contains a non-empty string *s*, consisting of lowercase Latin letters — that's the initial sentence in *N*-ish, written by Sergey. The length of string *s* doesn't exceed 105.
The next line contains integer *k* (0<=≤<=*k*<=≤<=13) — the number of forbidden pairs of letters.
Next *k* lines contain descriptions of forbidden pairs of letters. Each line contains exactly two different lowercase Latin letters without separators that represent the forbidden pairs. It is guaranteed that each letter is included in no more than one pair. | Print the single number — the smallest number of letters that need to be removed to get a string without any forbidden pairs of neighboring letters. Please note that the answer always exists as it is always possible to remove all letters. | [
"ababa\n1\nab\n",
"codeforces\n2\ndo\ncs\n"
] | [
"2\n",
"1\n"
] | In the first sample you should remove two letters b.
In the second sample you should remove the second or the third letter. The second restriction doesn't influence the solution. | 500 | [
{
"input": "ababa\n1\nab",
"output": "2"
},
{
"input": "codeforces\n2\ndo\ncs",
"output": "1"
},
{
"input": "nllnrlrnll\n1\nrl",
"output": "1"
},
{
"input": "aludfbjtwnkgnfl\n1\noy",
"output": "0"
},
{
"input": "pgpgppgggpbbnnn\n2\npg\nnb",
"output": "7"
},
{
"input": "eepeeeeppppppeepeppe\n1\npe",
"output": "10"
},
{
"input": "vefneyamdzoytemupniw\n13\nve\nfg\noi\nan\nck\nwx\npq\nml\nbt\nud\nrz\nsj\nhy",
"output": "1"
},
{
"input": "drvwfaacccwnncfwuptsorrrvvvrgdzytrwweeexzyyyxuwuuk\n13\nld\nac\nnp\nrv\nmo\njh\ngb\nuw\nfq\nst\nkx\nzy\nei",
"output": "11"
},
{
"input": "pninnihzipirpbdggrdglzdpbldtzihgbzdnrgznbpdanhnlag\n4\nli\nqh\nad\nbp",
"output": "4"
},
{
"input": "mbmxuuuuxuuuuhhooooxxxuxxxuxuuxuuuxxjvjvjjjjvvvjjjjjvvjvjjjvvvjjvjjvvvjjjvjvvjvjjjjjmmbmbbbbbmbbbbmm\n5\nmb\nho\nxu\njv\nyp",
"output": "37"
},
{
"input": "z\n0",
"output": "0"
},
{
"input": "t\n13\nzx\nig\nyq\nbd\nph\nar\nne\nwo\ntk\njl\ncv\nfs\nmu",
"output": "0"
},
{
"input": "rbnxovfcwkdjctdjfskaozjzthlcntuaoiavnbsfpuzxyvhfbxetvryvwrqetokdshadxpxijtpkrqvghsrejgnqntwiypiglzmp\n13\njr\nnf\nyk\ntq\nwe\nil\ngu\npb\naz\nxm\nhc\nvd\nso",
"output": "0"
},
{
"input": "yynynnyyyiynyniiiinyynniiyiyyyniyniyynyyyynyynnniiiniyyniiyyiynyiynnnnyiiyiyniyyininiyiiiyynnnyiyinnnnyiinnnnnyninyinyynynyiynyyyiyinyynnyyinynyinininyniniynniiyyiiyy\n1\nni",
"output": "28"
},
{
"input": "eowsgsewestwsootoetteoeeeetwssesstswegswetwetggewsteeteoggetssetseegwteswtteowsgowwoowetwgogewssogwgtttgwwoeotgoswwwwswsgeeoowwwwetwgeswsgwtsgewswtstwgggtegsssggsstwsoggeoseotgwswwggtggweewwgwegggoteweessotsewttwseosgegswwsoewgwstetwteegseowgwoteegwttwwowtwtosweeggweeeeoeesgseetgwgtswteotgwewetssggteewteeetetweeotwttwoeswggoosogoeg\n3\nst\neo\ngw",
"output": "49"
},
{
"input": "ttspivgoupgupvgpusvppogsseueusuglpiugssviuutlvgvugtpovuvspvpipggooplgvgugpogvesppulovugsvuougveiivgvslllviogpvtolepglguuellotpvgevspvoiiggiiplppgosuguvtstttpielteuglopgeoeeuivtptggltoltpgliviotsospvitupiopisoetupvvspooilsopslpoloptigstspoiuutiuvvuvlpplvioitsuvlpvtleveslslovolloogsgpvpepgueesslgtssttuupieppsstoeopeeppvopglpvtvuugpsuoplttsgstsiplpiugtoolisgpeeiuvutstpulvtllipsvsslvoepooslvteoevipvpsuoiippeuegoovoovstlvgsstitsivlvseguoolpslueuepgeooltviovpveeivolssloieuugovguoleulvssopetlpivpgoigtv\n1\ngs",
"output": "8"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n1\nab",
"output": "75"
}
] | 1,609,444,439 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 4 | 280 | 0 | l = list(input())
k = int(input())
forbidden = []
for i in range(k):
forbidden.append(set(list(input())))
i = 0
ans = 0
while(i<len(l)-1):
s=set([l[i],l[i+1]])
if (s in forbidden):
ans+=1
i+=2
continue
i+=1
print(ans)
| Title: Hometask
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sergey attends lessons of the *N*-ish language. Each lesson he receives a hometask. This time the task is to translate some sentence to the *N*-ish language. Sentences of the *N*-ish language can be represented as strings consisting of lowercase Latin letters without spaces or punctuation marks.
Sergey totally forgot about the task until half an hour before the next lesson and hastily scribbled something down. But then he recollected that in the last lesson he learned the grammar of *N*-ish. The spelling rules state that *N*-ish contains some "forbidden" pairs of letters: such letters can never occur in a sentence next to each other. Also, the order of the letters doesn't matter (for example, if the pair of letters "ab" is forbidden, then any occurrences of substrings "ab" and "ba" are also forbidden). Also, each pair has different letters and each letter occurs in no more than one forbidden pair.
Now Sergey wants to correct his sentence so that it doesn't contain any "forbidden" pairs of letters that stand next to each other. However, he is running out of time, so he decided to simply cross out some letters from the sentence. What smallest number of letters will he have to cross out? When a letter is crossed out, it is "removed" so that the letters to its left and right (if they existed), become neighboring. For example, if we cross out the first letter from the string "aba", we get the string "ba", and if we cross out the second letter, we get "aa".
Input Specification:
The first line contains a non-empty string *s*, consisting of lowercase Latin letters — that's the initial sentence in *N*-ish, written by Sergey. The length of string *s* doesn't exceed 105.
The next line contains integer *k* (0<=≤<=*k*<=≤<=13) — the number of forbidden pairs of letters.
Next *k* lines contain descriptions of forbidden pairs of letters. Each line contains exactly two different lowercase Latin letters without separators that represent the forbidden pairs. It is guaranteed that each letter is included in no more than one pair.
Output Specification:
Print the single number — the smallest number of letters that need to be removed to get a string without any forbidden pairs of neighboring letters. Please note that the answer always exists as it is always possible to remove all letters.
Demo Input:
['ababa\n1\nab\n', 'codeforces\n2\ndo\ncs\n']
Demo Output:
['2\n', '1\n']
Note:
In the first sample you should remove two letters b.
In the second sample you should remove the second or the third letter. The second restriction doesn't influence the solution. | ```python
l = list(input())
k = int(input())
forbidden = []
for i in range(k):
forbidden.append(set(list(input())))
i = 0
ans = 0
while(i<len(l)-1):
s=set([l[i],l[i+1]])
if (s in forbidden):
ans+=1
i+=2
continue
i+=1
print(ans)
``` | 0 |
|
552 | B | Vanya and Books | PROGRAMMING | 1,200 | [
"implementation",
"math"
] | null | null | Vanya got an important task — he should enumerate books in the library and label each book with its number. Each of the *n* books should be assigned with a number from 1 to *n*. Naturally, distinct books should be assigned distinct numbers.
Vanya wants to know how many digits he will have to write down as he labels the books. | The first line contains integer *n* (1<=≤<=*n*<=≤<=109) — the number of books in the library. | Print the number of digits needed to number all the books. | [
"13\n",
"4\n"
] | [
"17\n",
"4\n"
] | Note to the first test. The books get numbers 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, which totals to 17 digits.
Note to the second sample. The books get numbers 1, 2, 3, 4, which totals to 4 digits. | 1,000 | [
{
"input": "13",
"output": "17"
},
{
"input": "4",
"output": "4"
},
{
"input": "100",
"output": "192"
},
{
"input": "99",
"output": "189"
},
{
"input": "1000000000",
"output": "8888888899"
},
{
"input": "1000000",
"output": "5888896"
},
{
"input": "999",
"output": "2889"
},
{
"input": "55",
"output": "101"
},
{
"input": "222222222",
"output": "1888888896"
},
{
"input": "8",
"output": "8"
},
{
"input": "13",
"output": "17"
},
{
"input": "313",
"output": "831"
},
{
"input": "1342",
"output": "4261"
},
{
"input": "30140",
"output": "139594"
},
{
"input": "290092",
"output": "1629447"
},
{
"input": "2156660",
"output": "13985516"
},
{
"input": "96482216",
"output": "760746625"
},
{
"input": "943006819",
"output": "8375950269"
},
{
"input": "1",
"output": "1"
},
{
"input": "7",
"output": "7"
},
{
"input": "35",
"output": "61"
},
{
"input": "996",
"output": "2880"
},
{
"input": "6120",
"output": "23373"
},
{
"input": "30660",
"output": "142194"
},
{
"input": "349463",
"output": "1985673"
},
{
"input": "8171970",
"output": "56092686"
},
{
"input": "36123011",
"output": "277872985"
},
{
"input": "986747865",
"output": "8769619683"
},
{
"input": "9",
"output": "9"
},
{
"input": "10",
"output": "11"
},
{
"input": "11",
"output": "13"
},
{
"input": "101",
"output": "195"
},
{
"input": "1000",
"output": "2893"
},
{
"input": "1001",
"output": "2897"
},
{
"input": "9999",
"output": "38889"
},
{
"input": "10000",
"output": "38894"
},
{
"input": "10001",
"output": "38899"
},
{
"input": "99999",
"output": "488889"
},
{
"input": "100000",
"output": "488895"
},
{
"input": "100001",
"output": "488901"
},
{
"input": "999999",
"output": "5888889"
},
{
"input": "1000001",
"output": "5888903"
},
{
"input": "9999999",
"output": "68888889"
},
{
"input": "10000000",
"output": "68888897"
},
{
"input": "10000001",
"output": "68888905"
},
{
"input": "99999999",
"output": "788888889"
},
{
"input": "100000000",
"output": "788888898"
},
{
"input": "100000001",
"output": "788888907"
},
{
"input": "999999999",
"output": "8888888889"
},
{
"input": "95",
"output": "181"
},
{
"input": "995",
"output": "2877"
},
{
"input": "9995",
"output": "38873"
},
{
"input": "99995",
"output": "488869"
},
{
"input": "999999995",
"output": "8888888853"
},
{
"input": "999999998",
"output": "8888888880"
}
] | 1,567,625,431 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 4 | 124 | 0 | n = int(input())
res = 0
for i in range(9):
if n >= 10 ** i:
if n > (10 ** (i + 1)) - 1:
res += (9 * 10 ** i) * (i + 1)
else:
res += (n - 10 ** i + 1) * (i + 1)
print(res)
exit() | Title: Vanya and Books
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya got an important task — he should enumerate books in the library and label each book with its number. Each of the *n* books should be assigned with a number from 1 to *n*. Naturally, distinct books should be assigned distinct numbers.
Vanya wants to know how many digits he will have to write down as he labels the books.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=109) — the number of books in the library.
Output Specification:
Print the number of digits needed to number all the books.
Demo Input:
['13\n', '4\n']
Demo Output:
['17\n', '4\n']
Note:
Note to the first test. The books get numbers 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, which totals to 17 digits.
Note to the second sample. The books get numbers 1, 2, 3, 4, which totals to 4 digits. | ```python
n = int(input())
res = 0
for i in range(9):
if n >= 10 ** i:
if n > (10 ** (i + 1)) - 1:
res += (9 * 10 ** i) * (i + 1)
else:
res += (n - 10 ** i + 1) * (i + 1)
print(res)
exit()
``` | 0 |
|
466 | C | Number of Ways | PROGRAMMING | 1,700 | [
"binary search",
"brute force",
"data structures",
"dp",
"two pointers"
] | null | null | You've got array *a*[1],<=*a*[2],<=...,<=*a*[*n*], consisting of *n* integers. Count the number of ways to split all the elements of the array into three contiguous parts so that the sum of elements in each part is the same.
More formally, you need to find the number of such pairs of indices *i*,<=*j* (2<=≤<=*i*<=≤<=*j*<=≤<=*n*<=-<=1), that . | The first line contains integer *n* (1<=≤<=*n*<=≤<=5·105), showing how many numbers are in the array. The second line contains *n* integers *a*[1], *a*[2], ..., *a*[*n*] (|*a*[*i*]|<=≤<=<=109) — the elements of array *a*. | Print a single integer — the number of ways to split the array into three parts with the same sum. | [
"5\n1 2 3 0 3\n",
"4\n0 1 -1 0\n",
"2\n4 1\n"
] | [
"2\n",
"1\n",
"0\n"
] | none | 1,500 | [
{
"input": "5\n1 2 3 0 3",
"output": "2"
},
{
"input": "4\n0 1 -1 0",
"output": "1"
},
{
"input": "2\n4 1",
"output": "0"
},
{
"input": "9\n0 0 0 0 0 0 0 0 0",
"output": "28"
},
{
"input": "10\n2 5 -2 2 -3 -2 3 5 -5 -2",
"output": "0"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "3\n1 2 3",
"output": "0"
},
{
"input": "100\n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1",
"output": "2030"
},
{
"input": "6\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000",
"output": "1"
},
{
"input": "10\n1 0 0 0 1 1 1 0 1 1",
"output": "2"
},
{
"input": "10\n-2 2 -2 0 -2 -1 1 -1 2 0",
"output": "0"
},
{
"input": "4\n0 2 -1 2",
"output": "0"
},
{
"input": "5\n3 3 -3 3 3",
"output": "3"
},
{
"input": "5\n1 1 1 1 1",
"output": "0"
},
{
"input": "8\n-1 -1 -1 -1 -1 -1 -1 -1",
"output": "0"
},
{
"input": "2\n0 0",
"output": "0"
},
{
"input": "4\n1 -1 0 0",
"output": "1"
},
{
"input": "3\n6 -3 6",
"output": "0"
}
] | 1,699,344,001 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 31 | 0 | # -*- coding: utf-8 -*-
"""
Created on Tue Nov 7 15:14:57 2023
@author: 陈亚偲2300011106
"""
n=int(input())
a=[int(i) for i in input().split()]
b=sum(a)//3
if b==0:
ct0=0
for i in range(1,n-1):
a[i]+=a[i-1]
if a[i]==0:
ct0+=1
print((ct0-1)*ct0//2)
else:
c=[]
ct1,ct2=0
for i in range(1,n-1):
a[i]+=a[i-1]
for i in range(n-1):
if a[i]==b:
c.append(1)
ct1+=1
elif a[i]==2*b:
c.append(0)
ct2+=1
ans=0
index=0
while ct1!=0 and ct2!=0:
if c[index]:
ans+=ct2
ct1-=1
else:
ct2-=1
print(ans) | Title: Number of Ways
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got array *a*[1],<=*a*[2],<=...,<=*a*[*n*], consisting of *n* integers. Count the number of ways to split all the elements of the array into three contiguous parts so that the sum of elements in each part is the same.
More formally, you need to find the number of such pairs of indices *i*,<=*j* (2<=≤<=*i*<=≤<=*j*<=≤<=*n*<=-<=1), that .
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=5·105), showing how many numbers are in the array. The second line contains *n* integers *a*[1], *a*[2], ..., *a*[*n*] (|*a*[*i*]|<=≤<=<=109) — the elements of array *a*.
Output Specification:
Print a single integer — the number of ways to split the array into three parts with the same sum.
Demo Input:
['5\n1 2 3 0 3\n', '4\n0 1 -1 0\n', '2\n4 1\n']
Demo Output:
['2\n', '1\n', '0\n']
Note:
none | ```python
# -*- coding: utf-8 -*-
"""
Created on Tue Nov 7 15:14:57 2023
@author: 陈亚偲2300011106
"""
n=int(input())
a=[int(i) for i in input().split()]
b=sum(a)//3
if b==0:
ct0=0
for i in range(1,n-1):
a[i]+=a[i-1]
if a[i]==0:
ct0+=1
print((ct0-1)*ct0//2)
else:
c=[]
ct1,ct2=0
for i in range(1,n-1):
a[i]+=a[i-1]
for i in range(n-1):
if a[i]==b:
c.append(1)
ct1+=1
elif a[i]==2*b:
c.append(0)
ct2+=1
ans=0
index=0
while ct1!=0 and ct2!=0:
if c[index]:
ans+=ct2
ct1-=1
else:
ct2-=1
print(ans)
``` | -1 |
|
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,698,088,107 | 2,147,483,647 | Python 3 | OK | TESTS | 39 | 46 | 0 | x = int(input())
if x % 2 == 0:
print(x // 2)
else:
print(-1 * ((x + 1) // 2))
| Title: Calculating Function
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
For a positive integer *n* let's define a function *f*:
*f*(*n*)<==<=<=-<=1<=+<=2<=-<=3<=+<=..<=+<=(<=-<=1)*n**n*
Your task is to calculate *f*(*n*) for a given integer *n*.
Input Specification:
The single line 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
x = int(input())
if x % 2 == 0:
print(x // 2)
else:
print(-1 * ((x + 1) // 2))
``` | 3 |
|
931 | C | Laboratory Work | PROGRAMMING | 1,700 | [
"implementation",
"math"
] | null | null | Anya and Kirill are doing a physics laboratory work. In one of the tasks they have to measure some value *n* times, and then compute the average value to lower the error.
Kirill has already made his measurements, and has got the following integer values: *x*1, *x*2, ..., *x**n*. It is important that the values are close to each other, namely, the difference between the maximum value and the minimum value is at most 2.
Anya does not want to make the measurements, however, she can't just copy the values from Kirill's work, because the error of each measurement is a random value, and this coincidence will be noted by the teacher. Anya wants to write such integer values *y*1, *y*2, ..., *y**n* in her work, that the following conditions are met:
- the average value of *x*1,<=*x*2,<=...,<=*x**n* is equal to the average value of *y*1,<=*y*2,<=...,<=*y**n*;- all Anya's measurements are in the same bounds as all Kirill's measurements, that is, the maximum value among Anya's values is not greater than the maximum value among Kirill's values, and the minimum value among Anya's values is not less than the minimum value among Kirill's values;- the number of equal measurements in Anya's work and Kirill's work is as small as possible among options with the previous conditions met. Formally, the teacher goes through all Anya's values one by one, if there is equal value in Kirill's work and it is not strike off yet, he strikes off this Anya's value and one of equal values in Kirill's work. The number of equal measurements is then the total number of strike off values in Anya's work.
Help Anya to write such a set of measurements that the conditions above are met. | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the numeber of measurements made by Kirill.
The second line contains a sequence of integers *x*1,<=*x*2,<=...,<=*x**n* (<=-<=100<=000<=≤<=*x**i*<=≤<=100<=000) — the measurements made by Kirill. It is guaranteed that the difference between the maximum and minimum values among values *x*1,<=*x*2,<=...,<=*x**n* does not exceed 2. | In the first line print the minimum possible number of equal measurements.
In the second line print *n* integers *y*1,<=*y*2,<=...,<=*y**n* — the values Anya should write. You can print the integers in arbitrary order. Keep in mind that the minimum value among Anya's values should be not less that the minimum among Kirill's values, and the maximum among Anya's values should be not greater than the maximum among Kirill's values.
If there are multiple answers, print any of them. | [
"6\n-1 1 1 0 0 -1\n",
"3\n100 100 101\n",
"7\n-10 -9 -10 -8 -10 -9 -9\n"
] | [
"2\n0 0 0 0 0 0 \n",
"3\n101 100 100 \n",
"5\n-10 -10 -9 -9 -9 -9 -9 \n"
] | In the first example Anya can write zeros as here measurements results. The average value is then equal to the average value of Kirill's values, and there are only two equal measurements.
In the second example Anya should write two values 100 and one value 101 (in any order), because it is the only possibility to make the average be the equal to the average of Kirill's values. Thus, all three measurements are equal.
In the third example the number of equal measurements is 5. | 1,750 | [
{
"input": "6\n-1 1 1 0 0 -1",
"output": "2\n0 0 0 0 0 0 "
},
{
"input": "3\n100 100 101",
"output": "3\n101 100 100 "
},
{
"input": "7\n-10 -9 -10 -8 -10 -9 -9",
"output": "5\n-10 -10 -9 -9 -9 -9 -9 "
},
{
"input": "60\n-8536 -8536 -8536 -8535 -8536 -8536 -8536 -8536 -8536 -8536 -8536 -8535 -8536 -8535 -8536 -8536 -8536 -8536 -8536 -8536 -8536 -8536 -8536 -8536 -8536 -8536 -8536 -8535 -8536 -8536 -8535 -8536 -8536 -8536 -8536 -8536 -8536 -8536 -8536 -8536 -8536 -8536 -8536 -8535 -8536 -8536 -8536 -8535 -8535 -8536 -8536 -8536 -8536 -8536 -8536 -8536 -8536 -8536 -8536 -8535",
"output": "60\n-8535 -8536 -8536 -8536 -8536 -8536 -8536 -8536 -8536 -8536 -8536 -8535 -8535 -8536 -8536 -8536 -8535 -8536 -8536 -8536 -8536 -8536 -8536 -8536 -8536 -8536 -8536 -8536 -8536 -8535 -8536 -8536 -8535 -8536 -8536 -8536 -8536 -8536 -8536 -8536 -8536 -8536 -8536 -8536 -8536 -8536 -8535 -8536 -8535 -8536 -8536 -8536 -8536 -8536 -8536 -8536 -8535 -8536 -8536 -8536 "
},
{
"input": "9\n-71360 -71359 -71360 -71360 -71359 -71359 -71359 -71359 -71359",
"output": "9\n-71359 -71359 -71359 -71359 -71359 -71360 -71360 -71359 -71360 "
},
{
"input": "10\n100 100 100 100 100 100 100 100 100 100",
"output": "10\n100 100 100 100 100 100 100 100 100 100 "
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "100\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 "
},
{
"input": "5\n-399 -399 -400 -399 -400",
"output": "5\n-400 -399 -400 -399 -399 "
},
{
"input": "10\n1001 1000 1000 1001 1000 1000 1001 1001 1000 1001",
"output": "10\n1001 1000 1001 1001 1000 1000 1001 1000 1000 1001 "
},
{
"input": "20\n-100000 -99999 -100000 -99999 -99999 -100000 -99999 -100000 -99999 -100000 -99999 -99999 -99999 -100000 -100000 -99999 -100000 -100000 -100000 -99999",
"output": "20\n-99999 -100000 -100000 -100000 -99999 -100000 -100000 -99999 -99999 -99999 -100000 -99999 -100000 -99999 -100000 -99999 -99999 -100000 -99999 -100000 "
},
{
"input": "50\n99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 100000 99999 99999 99999 99999 99999 100000 99999 99999 99999 100000 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 100000 99999 99999 99999 100000 99999 99999 99999",
"output": "50\n99999 99999 99999 100000 99999 99999 99999 100000 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 100000 99999 99999 99999 100000 99999 99999 99999 99999 99999 100000 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 "
},
{
"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 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "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 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 "
},
{
"input": "1\n-100000",
"output": "1\n-100000 "
},
{
"input": "1\n-1",
"output": "1\n-1 "
},
{
"input": "1\n0",
"output": "1\n0 "
},
{
"input": "1\n1",
"output": "1\n1 "
},
{
"input": "1\n100000",
"output": "1\n100000 "
},
{
"input": "5\n2 2 1 1 2",
"output": "5\n2 1 1 2 2 "
},
{
"input": "10\n0 -1 0 1 1 1 1 -1 0 0",
"output": "6\n0 0 0 0 0 0 0 0 1 1 "
},
{
"input": "20\n-4344 -4342 -4344 -4342 -4343 -4343 -4344 -4344 -4342 -4343 -4344 -4343 -4344 -4344 -4344 -4342 -4344 -4343 -4342 -4344",
"output": "10\n-4344 -4344 -4344 -4344 -4344 -4343 -4343 -4343 -4343 -4343 -4343 -4343 -4343 -4343 -4343 -4343 -4343 -4343 -4343 -4343 "
},
{
"input": "40\n113 113 112 112 112 112 112 112 112 112 112 113 113 112 113 112 113 112 112 112 111 112 112 113 112 112 112 112 112 112 112 112 113 112 113 112 112 113 112 113",
"output": "12\n111 111 111 111 111 111 111 111 111 111 111 111 111 111 111 113 113 113 113 113 113 113 113 113 113 113 113 113 113 113 113 113 113 113 113 113 113 113 113 113 "
},
{
"input": "5\n-94523 -94523 -94523 -94524 -94524",
"output": "5\n-94524 -94524 -94523 -94523 -94523 "
},
{
"input": "10\n-35822 -35823 -35823 -35823 -35821 -35823 -35823 -35821 -35822 -35821",
"output": "4\n-35823 -35823 -35822 -35822 -35822 -35822 -35822 -35822 -35822 -35822 "
},
{
"input": "11\n-50353 -50353 -50353 -50353 -50353 -50352 -50353 -50353 -50353 -50353 -50352",
"output": "11\n-50352 -50353 -50353 -50353 -50353 -50352 -50353 -50353 -50353 -50353 -50353 "
},
{
"input": "20\n46795 46795 46795 46795 46795 46795 46795 46793 46794 46795 46794 46795 46795 46795 46795 46795 46795 46795 46795 46795",
"output": "18\n46794 46794 46794 46794 46795 46795 46795 46795 46795 46795 46795 46795 46795 46795 46795 46795 46795 46795 46795 46795 "
},
{
"input": "40\n72263 72261 72262 72263 72263 72263 72263 72263 72263 72262 72263 72263 72263 72263 72263 72262 72263 72262 72263 72262 72262 72263 72263 72262 72263 72263 72262 72262 72263 72262 72263 72263 72263 72263 72263 72263 72263 72263 72263 72262",
"output": "30\n72261 72261 72261 72261 72261 72261 72262 72263 72263 72263 72263 72263 72263 72263 72263 72263 72263 72263 72263 72263 72263 72263 72263 72263 72263 72263 72263 72263 72263 72263 72263 72263 72263 72263 72263 72263 72263 72263 72263 72263 "
},
{
"input": "50\n-46992 -46992 -46992 -46991 -46992 -46991 -46992 -46992 -46992 -46992 -46992 -46992 -46992 -46992 -46991 -46991 -46991 -46992 -46990 -46991 -46991 -46991 -46991 -46992 -46992 -46991 -46992 -46992 -46992 -46990 -46992 -46991 -46991 -46992 -46992 -46992 -46991 -46991 -46991 -46992 -46992 -46992 -46992 -46992 -46992 -46992 -46992 -46992 -46992 -46992",
"output": "36\n-46992 -46992 -46992 -46992 -46992 -46992 -46992 -46992 -46992 -46992 -46992 -46992 -46992 -46992 -46992 -46992 -46992 -46992 -46992 -46992 -46992 -46992 -46992 -46992 -46992 -46992 -46992 -46992 -46992 -46992 -46992 -46992 -46992 -46992 -46992 -46992 -46992 -46992 -46992 -46992 -46991 -46990 -46990 -46990 -46990 -46990 -46990 -46990 -46990 -46990 "
},
{
"input": "60\n-86077 -86075 -86076 -86076 -86077 -86077 -86075 -86075 -86075 -86077 -86075 -86076 -86075 -86075 -86075 -86076 -86075 -86076 -86075 -86075 -86076 -86076 -86076 -86075 -86075 -86075 -86075 -86077 -86075 -86076 -86075 -86075 -86075 -86076 -86075 -86076 -86077 -86075 -86075 -86075 -86076 -86075 -86076 -86075 -86076 -86076 -86075 -86076 -86076 -86075 -86075 -86075 -86077 -86076 -86075 -86075 -86075 -86075 -86075 -86075",
"output": "42\n-86077 -86077 -86077 -86077 -86077 -86077 -86077 -86077 -86077 -86077 -86077 -86077 -86077 -86077 -86077 -86077 -86075 -86075 -86075 -86075 -86075 -86075 -86075 -86075 -86075 -86075 -86075 -86075 -86075 -86075 -86075 -86075 -86075 -86075 -86075 -86075 -86075 -86075 -86075 -86075 -86075 -86075 -86075 -86075 -86075 -86075 -86075 -86075 -86075 -86075 -86075 -86075 -86075 -86075 -86075 -86075 -86075 -86075 -86075 -86075 "
},
{
"input": "70\n-87 -86 -88 -86 -87 -86 -88 -88 -87 -86 -86 -88 -86 -86 -88 -87 -87 -87 -86 -87 -87 -87 -88 -88 -88 -87 -88 -87 -88 -87 -88 -86 -86 -86 -88 -86 -87 -87 -86 -86 -88 -86 -88 -87 -88 -87 -87 -86 -88 -87 -86 -88 -87 -86 -87 -87 -86 -88 -87 -86 -87 -88 -87 -88 -86 -87 -88 -88 -87 -87",
"output": "28\n-88 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 -87 "
},
{
"input": "2\n0 2",
"output": "0\n1 1 "
},
{
"input": "4\n1 1 3 3",
"output": "0\n2 2 2 2 "
},
{
"input": "6\n1 1 1 3 3 3",
"output": "0\n2 2 2 2 2 2 "
},
{
"input": "2\n1 3",
"output": "0\n2 2 "
},
{
"input": "7\n0 1 1 1 1 1 2",
"output": "3\n0 0 0 1 2 2 2 "
},
{
"input": "6\n1 1 1 -1 -1 -1",
"output": "0\n0 0 0 0 0 0 "
},
{
"input": "3\n1 1 3",
"output": "1\n1 2 2 "
},
{
"input": "2\n2 0",
"output": "0\n1 1 "
},
{
"input": "10\n1 3 3 3 3 3 3 3 3 3",
"output": "8\n2 2 3 3 3 3 3 3 3 3 "
},
{
"input": "7\n1 3 3 3 3 3 3",
"output": "5\n2 2 3 3 3 3 3 "
},
{
"input": "7\n1 2 2 2 2 2 3",
"output": "3\n1 1 1 2 3 3 3 "
},
{
"input": "5\n-8 -8 -8 -10 -10",
"output": "1\n-9 -9 -9 -9 -8 "
},
{
"input": "3\n1 2 3",
"output": "1\n2 2 2 "
},
{
"input": "4\n2 2 4 4",
"output": "0\n3 3 3 3 "
},
{
"input": "4\n1 1 -1 -1",
"output": "0\n0 0 0 0 "
}
] | 1,566,391,792 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 118 | 374 | 7,475,200 | n = int(input())
a = list(map(int, input().split()))
mi = min(a)
ma = max(a)
sred = -(10 ** 9)
count = [0] * 3
for i in a:
if i == ma:
count[2] += 1
elif i == mi:
count[0] += 1
else:
sred = i
count[1] += 1
if sred == -(10 ** 9):
print(n)
print(*a)
else:
ans1 = count[:]
ans2 = count[:]
while ans1[1] > 1:
ans1[1] -= 2
ans1[0] += 1
ans1[2] += 1
while min(ans2[0], ans2[2]):
ans2[0] -= 1
ans2[2] -= 1
ans2[1] += 2
c1 = 0
c2 = 0
for i in range(3):
c1 += min(count[i], ans1[i])
c2 += min(count[i], ans2[i])
if c1 < c2:
print(c1)
for i in range(ans1[0]):
print(mi, end=' ')
for i in range(ans1[1]):
print(sred, end=' ')
for i in range(ans1[2]):
print(ma, end=' ')
else:
print(c2)
for i in range(ans2[0]):
print(mi, end=' ')
for i in range(ans2[1]):
print(sred, end=' ')
for i in range(ans2[2]):
print(ma, end=' ') | Title: Laboratory Work
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Anya and Kirill are doing a physics laboratory work. In one of the tasks they have to measure some value *n* times, and then compute the average value to lower the error.
Kirill has already made his measurements, and has got the following integer values: *x*1, *x*2, ..., *x**n*. It is important that the values are close to each other, namely, the difference between the maximum value and the minimum value is at most 2.
Anya does not want to make the measurements, however, she can't just copy the values from Kirill's work, because the error of each measurement is a random value, and this coincidence will be noted by the teacher. Anya wants to write such integer values *y*1, *y*2, ..., *y**n* in her work, that the following conditions are met:
- the average value of *x*1,<=*x*2,<=...,<=*x**n* is equal to the average value of *y*1,<=*y*2,<=...,<=*y**n*;- all Anya's measurements are in the same bounds as all Kirill's measurements, that is, the maximum value among Anya's values is not greater than the maximum value among Kirill's values, and the minimum value among Anya's values is not less than the minimum value among Kirill's values;- the number of equal measurements in Anya's work and Kirill's work is as small as possible among options with the previous conditions met. Formally, the teacher goes through all Anya's values one by one, if there is equal value in Kirill's work and it is not strike off yet, he strikes off this Anya's value and one of equal values in Kirill's work. The number of equal measurements is then the total number of strike off values in Anya's work.
Help Anya to write such a set of measurements that the conditions above are met.
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the numeber of measurements made by Kirill.
The second line contains a sequence of integers *x*1,<=*x*2,<=...,<=*x**n* (<=-<=100<=000<=≤<=*x**i*<=≤<=100<=000) — the measurements made by Kirill. It is guaranteed that the difference between the maximum and minimum values among values *x*1,<=*x*2,<=...,<=*x**n* does not exceed 2.
Output Specification:
In the first line print the minimum possible number of equal measurements.
In the second line print *n* integers *y*1,<=*y*2,<=...,<=*y**n* — the values Anya should write. You can print the integers in arbitrary order. Keep in mind that the minimum value among Anya's values should be not less that the minimum among Kirill's values, and the maximum among Anya's values should be not greater than the maximum among Kirill's values.
If there are multiple answers, print any of them.
Demo Input:
['6\n-1 1 1 0 0 -1\n', '3\n100 100 101\n', '7\n-10 -9 -10 -8 -10 -9 -9\n']
Demo Output:
['2\n0 0 0 0 0 0 \n', '3\n101 100 100 \n', '5\n-10 -10 -9 -9 -9 -9 -9 \n']
Note:
In the first example Anya can write zeros as here measurements results. The average value is then equal to the average value of Kirill's values, and there are only two equal measurements.
In the second example Anya should write two values 100 and one value 101 (in any order), because it is the only possibility to make the average be the equal to the average of Kirill's values. Thus, all three measurements are equal.
In the third example the number of equal measurements is 5. | ```python
n = int(input())
a = list(map(int, input().split()))
mi = min(a)
ma = max(a)
sred = -(10 ** 9)
count = [0] * 3
for i in a:
if i == ma:
count[2] += 1
elif i == mi:
count[0] += 1
else:
sred = i
count[1] += 1
if sred == -(10 ** 9):
print(n)
print(*a)
else:
ans1 = count[:]
ans2 = count[:]
while ans1[1] > 1:
ans1[1] -= 2
ans1[0] += 1
ans1[2] += 1
while min(ans2[0], ans2[2]):
ans2[0] -= 1
ans2[2] -= 1
ans2[1] += 2
c1 = 0
c2 = 0
for i in range(3):
c1 += min(count[i], ans1[i])
c2 += min(count[i], ans2[i])
if c1 < c2:
print(c1)
for i in range(ans1[0]):
print(mi, end=' ')
for i in range(ans1[1]):
print(sred, end=' ')
for i in range(ans1[2]):
print(ma, end=' ')
else:
print(c2)
for i in range(ans2[0]):
print(mi, end=' ')
for i in range(ans2[1]):
print(sred, end=' ')
for i in range(ans2[2]):
print(ma, end=' ')
``` | 0 |
|
34 | B | Sale | PROGRAMMING | 900 | [
"greedy",
"sortings"
] | B. Sale | 2 | 256 | Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most *m* TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn. | The first line contains two space-separated integers *n* and *m* (1<=≤<=*m*<=≤<=*n*<=≤<=100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains *n* space-separated integers *a**i* (<=-<=1000<=≤<=*a**i*<=≤<=1000) — prices of the TV sets. | Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most *m* TV sets. | [
"5 3\n-6 0 35 -2 4\n",
"4 2\n7 0 0 -7\n"
] | [
"8\n",
"7\n"
] | none | 1,000 | [
{
"input": "5 3\n-6 0 35 -2 4",
"output": "8"
},
{
"input": "4 2\n7 0 0 -7",
"output": "7"
},
{
"input": "6 6\n756 -611 251 -66 572 -818",
"output": "1495"
},
{
"input": "5 5\n976 437 937 788 518",
"output": "0"
},
{
"input": "5 3\n-2 -2 -2 -2 -2",
"output": "6"
},
{
"input": "5 1\n998 997 985 937 998",
"output": "0"
},
{
"input": "2 2\n-742 -187",
"output": "929"
},
{
"input": "3 3\n522 597 384",
"output": "0"
},
{
"input": "4 2\n-215 -620 192 647",
"output": "835"
},
{
"input": "10 6\n557 605 685 231 910 633 130 838 -564 -85",
"output": "649"
},
{
"input": "20 14\n932 442 960 943 624 624 955 998 631 910 850 517 715 123 1000 155 -10 961 966 59",
"output": "10"
},
{
"input": "30 5\n991 997 996 967 977 999 991 986 1000 965 984 997 998 1000 958 983 974 1000 991 999 1000 978 961 992 990 998 998 978 998 1000",
"output": "0"
},
{
"input": "50 20\n-815 -947 -946 -993 -992 -846 -884 -954 -963 -733 -940 -746 -766 -930 -821 -937 -937 -999 -914 -938 -936 -975 -939 -981 -977 -952 -925 -901 -952 -978 -994 -957 -946 -896 -905 -836 -994 -951 -887 -939 -859 -953 -985 -988 -946 -829 -956 -842 -799 -886",
"output": "19441"
},
{
"input": "88 64\n999 999 1000 1000 999 996 995 1000 1000 999 1000 997 998 1000 999 1000 997 1000 993 998 994 999 998 996 1000 997 1000 1000 1000 997 1000 998 997 1000 1000 998 1000 998 999 1000 996 999 999 999 996 995 999 1000 998 999 1000 999 999 1000 1000 1000 996 1000 1000 1000 997 1000 1000 997 999 1000 1000 1000 1000 1000 999 999 1000 1000 996 999 1000 1000 995 999 1000 996 1000 998 999 999 1000 999",
"output": "0"
},
{
"input": "99 17\n-993 -994 -959 -989 -991 -995 -976 -997 -990 -1000 -996 -994 -999 -995 -1000 -983 -979 -1000 -989 -968 -994 -992 -962 -993 -999 -983 -991 -979 -995 -993 -973 -999 -995 -995 -999 -993 -995 -992 -947 -1000 -999 -998 -982 -988 -979 -993 -963 -988 -980 -990 -979 -976 -995 -999 -981 -988 -998 -999 -970 -1000 -983 -994 -943 -975 -998 -977 -973 -997 -959 -999 -983 -985 -950 -977 -977 -991 -998 -973 -987 -985 -985 -986 -984 -994 -978 -998 -989 -989 -988 -970 -985 -974 -997 -981 -962 -972 -995 -988 -993",
"output": "16984"
},
{
"input": "100 37\n205 19 -501 404 912 -435 -322 -469 -655 880 -804 -470 793 312 -108 586 -642 -928 906 605 -353 -800 745 -440 -207 752 -50 -28 498 -800 -62 -195 602 -833 489 352 536 404 -775 23 145 -512 524 759 651 -461 -427 -557 684 -366 62 592 -563 -811 64 418 -881 -308 591 -318 -145 -261 -321 -216 -18 595 -202 960 -4 219 226 -238 -882 -963 425 970 -434 -160 243 -672 -4 873 8 -633 904 -298 -151 -377 -61 -72 -677 -66 197 -716 3 -870 -30 152 -469 981",
"output": "21743"
},
{
"input": "100 99\n-931 -806 -830 -828 -916 -962 -660 -867 -952 -966 -820 -906 -724 -982 -680 -717 -488 -741 -897 -613 -986 -797 -964 -939 -808 -932 -810 -860 -641 -916 -858 -628 -821 -929 -917 -976 -664 -985 -778 -665 -624 -928 -940 -958 -884 -757 -878 -896 -634 -526 -514 -873 -990 -919 -988 -878 -650 -973 -774 -783 -733 -648 -756 -895 -833 -974 -832 -725 -841 -748 -806 -613 -924 -867 -881 -943 -864 -991 -809 -926 -777 -817 -998 -682 -910 -996 -241 -722 -964 -904 -821 -920 -835 -699 -805 -632 -779 -317 -915 -654",
"output": "81283"
},
{
"input": "100 14\n995 994 745 684 510 737 984 690 979 977 542 933 871 603 758 653 962 997 747 974 773 766 975 770 527 960 841 989 963 865 974 967 950 984 757 685 986 809 982 959 931 880 978 867 805 562 970 900 834 782 616 885 910 608 974 918 576 700 871 980 656 941 978 759 767 840 573 859 841 928 693 853 716 927 976 851 962 962 627 797 707 873 869 988 993 533 665 887 962 880 929 980 877 887 572 790 721 883 848 782",
"output": "0"
},
{
"input": "100 84\n768 946 998 752 931 912 826 1000 991 910 875 962 901 952 958 733 959 908 872 840 923 826 952 980 974 980 947 955 959 822 997 963 966 933 829 923 971 999 926 932 865 984 974 858 994 855 949 941 992 861 951 949 991 711 763 728 935 485 716 907 869 952 960 859 909 963 978 942 968 933 923 909 997 962 687 764 924 774 875 1000 961 951 987 974 848 921 966 859 995 997 974 931 886 941 974 986 906 978 998 823",
"output": "0"
},
{
"input": "100 80\n-795 -994 -833 -930 -974 -980 -950 -940 -788 -927 -583 -956 -945 -949 -809 -974 -957 -736 -967 -908 -975 -961 -986 -983 -963 -771 -952 -847 -751 -741 -982 -959 -925 -931 -839 -937 -880 -914 -858 -998 -812 -911 -862 -965 -943 -984 -738 -920 -950 -998 -909 -998 -781 -901 -677 -940 -985 -951 -675 -952 -967 -949 -882 -641 -969 -937 -975 -993 -913 -941 -807 -851 -832 -960 -939 -943 -895 -929 -528 -880 -823 -930 -888 -862 -948 -966 -962 -857 -799 -969 -833 -998 -952 -878 -946 -971 -976 -974 -723 -992",
"output": "75068"
},
{
"input": "1 1\n0",
"output": "0"
},
{
"input": "1 1\n1",
"output": "0"
},
{
"input": "1 1\n555",
"output": "0"
},
{
"input": "1 1\n-1",
"output": "1"
},
{
"input": "1 1\n-24",
"output": "24"
}
] | 1,684,054,638 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 92 | 0 | n,m=map(int,input().split())
a=list(map(int,input().split()))
s=0
b=[]
for i in a:
if i<0:
b.append(-i)
b.sort(reverse=True)
if len(b)<m:
s=sum(b)
else:
for i in range(m):
s=s+b[i]
print(s)
| Title: Sale
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most *m* TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn.
Input Specification:
The first line contains two space-separated integers *n* and *m* (1<=≤<=*m*<=≤<=*n*<=≤<=100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains *n* space-separated integers *a**i* (<=-<=1000<=≤<=*a**i*<=≤<=1000) — prices of the TV sets.
Output Specification:
Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most *m* TV sets.
Demo Input:
['5 3\n-6 0 35 -2 4\n', '4 2\n7 0 0 -7\n']
Demo Output:
['8\n', '7\n']
Note:
none | ```python
n,m=map(int,input().split())
a=list(map(int,input().split()))
s=0
b=[]
for i in a:
if i<0:
b.append(-i)
b.sort(reverse=True)
if len(b)<m:
s=sum(b)
else:
for i in range(m):
s=s+b[i]
print(s)
``` | 3.977 |
935 | A | Fafa and his Company | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | Fafa owns a company that works on huge projects. There are *n* employees in Fafa's company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the employees.
Fafa finds doing this every time is very tiring for him. So, he decided to choose the best *l* employees in his company as team leaders. Whenever there is a new project, Fafa will divide the tasks among only the team leaders and each team leader will be responsible of some positive number of employees to give them the tasks. To make this process fair for the team leaders, each one of them should be responsible for the same number of employees. Moreover, every employee, who is not a team leader, has to be under the responsibility of exactly one team leader, and no team leader is responsible for another team leader.
Given the number of employees *n*, find in how many ways Fafa could choose the number of team leaders *l* in such a way that it is possible to divide employees between them evenly. | The input consists of a single line containing a positive integer *n* (2<=≤<=*n*<=≤<=105) — the number of employees in Fafa's company. | Print a single integer representing the answer to the problem. | [
"2\n",
"10\n"
] | [
"1\n",
"3\n"
] | In the second sample Fafa has 3 ways:
- choose only 1 employee as a team leader with 9 employees under his responsibility. - choose 2 employees as team leaders with 4 employees under the responsibility of each of them. - choose 5 employees as team leaders with 1 employee under the responsibility of each of them. | 500 | [
{
"input": "2",
"output": "1"
},
{
"input": "10",
"output": "3"
},
{
"input": "3",
"output": "1"
},
{
"input": "4",
"output": "2"
},
{
"input": "6",
"output": "3"
},
{
"input": "13",
"output": "1"
},
{
"input": "100000",
"output": "35"
},
{
"input": "1024",
"output": "10"
},
{
"input": "99999",
"output": "11"
},
{
"input": "10007",
"output": "1"
},
{
"input": "4096",
"output": "12"
},
{
"input": "65536",
"output": "16"
},
{
"input": "40320",
"output": "95"
},
{
"input": "30030",
"output": "63"
},
{
"input": "161",
"output": "3"
},
{
"input": "1000",
"output": "15"
},
{
"input": "10000",
"output": "24"
},
{
"input": "777",
"output": "7"
},
{
"input": "121",
"output": "2"
},
{
"input": "25",
"output": "2"
},
{
"input": "40000",
"output": "34"
},
{
"input": "99990",
"output": "47"
},
{
"input": "98765",
"output": "3"
},
{
"input": "56789",
"output": "3"
},
{
"input": "13579",
"output": "3"
},
{
"input": "97531",
"output": "3"
},
{
"input": "12345",
"output": "7"
},
{
"input": "54321",
"output": "7"
},
{
"input": "83160",
"output": "127"
},
{
"input": "9",
"output": "2"
},
{
"input": "21",
"output": "3"
},
{
"input": "11",
"output": "1"
},
{
"input": "15",
"output": "3"
}
] | 1,635,994,650 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 46 | 4,198,400 | n=int(input())
a=0
if (2 <= n <= 10**5):
if(n%2==0):
a=(n//2)
print(a)
else:
a=(n+1//2)
print(a)
| Title: Fafa and his Company
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fafa owns a company that works on huge projects. There are *n* employees in Fafa's company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the employees.
Fafa finds doing this every time is very tiring for him. So, he decided to choose the best *l* employees in his company as team leaders. Whenever there is a new project, Fafa will divide the tasks among only the team leaders and each team leader will be responsible of some positive number of employees to give them the tasks. To make this process fair for the team leaders, each one of them should be responsible for the same number of employees. Moreover, every employee, who is not a team leader, has to be under the responsibility of exactly one team leader, and no team leader is responsible for another team leader.
Given the number of employees *n*, find in how many ways Fafa could choose the number of team leaders *l* in such a way that it is possible to divide employees between them evenly.
Input Specification:
The input consists of a single line containing a positive integer *n* (2<=≤<=*n*<=≤<=105) — the number of employees in Fafa's company.
Output Specification:
Print a single integer representing the answer to the problem.
Demo Input:
['2\n', '10\n']
Demo Output:
['1\n', '3\n']
Note:
In the second sample Fafa has 3 ways:
- choose only 1 employee as a team leader with 9 employees under his responsibility. - choose 2 employees as team leaders with 4 employees under the responsibility of each of them. - choose 5 employees as team leaders with 1 employee under the responsibility of each of them. | ```python
n=int(input())
a=0
if (2 <= n <= 10**5):
if(n%2==0):
a=(n//2)
print(a)
else:
a=(n+1//2)
print(a)
``` | 0 |
|
262 | A | Roma and Lucky Numbers | PROGRAMMING | 800 | [
"implementation"
] | null | null | Roma (a popular Russian name that means 'Roman') loves the Little Lvov Elephant's lucky numbers.
Let us remind you that lucky numbers are positive integers whose decimal representation only contains lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Roma's got *n* positive integers. He wonders, how many of those integers have not more than *k* lucky digits? Help him, write the program that solves the problem. | The first line contains two integers *n*, *k* (1<=≤<=*n*,<=*k*<=≤<=100). The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) — the numbers that Roma has.
The numbers in the lines are separated by single spaces. | In a single line print a single integer — the answer to the problem. | [
"3 4\n1 2 4\n",
"3 2\n447 44 77\n"
] | [
"3\n",
"2\n"
] | In the first sample all numbers contain at most four lucky digits, so the answer is 3.
In the second sample number 447 doesn't fit in, as it contains more than two lucky digits. All other numbers are fine, so the answer is 2. | 500 | [
{
"input": "3 4\n1 2 4",
"output": "3"
},
{
"input": "3 2\n447 44 77",
"output": "2"
},
{
"input": "2 2\n507978501 180480073",
"output": "2"
},
{
"input": "9 6\n655243746 167613748 1470546 57644035 176077477 56984809 44677 215706823 369042089",
"output": "9"
},
{
"input": "6 100\n170427799 37215529 675016434 168544291 683447134 950090227",
"output": "6"
},
{
"input": "4 2\n194041605 706221269 69909135 257655784",
"output": "3"
},
{
"input": "4 2\n9581849 67346651 530497 272158241",
"output": "4"
},
{
"input": "3 47\n378261451 163985731 230342101",
"output": "3"
},
{
"input": "2 3\n247776868 480572137",
"output": "1"
},
{
"input": "7 77\n366496749 549646417 278840199 119255907 33557677 379268590 150378796",
"output": "7"
},
{
"input": "40 31\n32230963 709031779 144328646 513494529 36547831 416998222 84161665 318773941 170724397 553666286 368402971 48581613 31452501 368026285 47903381 939151438 204145360 189920160 288159400 133145006 314295423 450219949 160203213 358403181 478734385 29331901 31051111 110710191 567314089 139695685 111511396 87708701 317333277 103301481 110400517 634446253 481551313 39202255 105948 738066085",
"output": "40"
},
{
"input": "1 8\n55521105",
"output": "1"
},
{
"input": "49 3\n34644511 150953622 136135827 144208961 359490601 86708232 719413689 188605873 64330753 488776302 104482891 63360106 437791390 46521319 70778345 339141601 136198441 292941209 299339510 582531183 555958105 437904637 74219097 439816011 236010407 122674666 438442529 186501223 63932449 407678041 596993853 92223251 849265278 480265849 30983497 330283357 186901672 20271344 794252593 123774176 27851201 52717531 479907210 196833889 149331196 82147847 255966471 278600081 899317843",
"output": "44"
},
{
"input": "26 2\n330381357 185218042 850474297 483015466 296129476 1205865 538807493 103205601 160403321 694220263 416255901 7245756 507755361 88187633 91426751 1917161 58276681 59540376 576539745 595950717 390256887 105690055 607818885 28976353 488947089 50643601",
"output": "22"
},
{
"input": "38 1\n194481717 126247087 815196361 106258801 381703249 283859137 15290101 40086151 213688513 577996947 513899717 371428417 107799271 11136651 5615081 323386401 381128815 34217126 17709913 520702093 201694245 570931849 169037023 417019726 282437316 7417126 271667553 11375851 185087449 410130883 383045677 5764771 905017051 328584026 215330671 299553233 15838255 234532105",
"output": "20"
},
{
"input": "44 9\n683216389 250581469 130029957 467020047 188395565 206237982 63257361 68314981 732878407 563579660 199133851 53045209 665723851 16273169 10806790 556633156 350593410 474645249 478790761 708234243 71841230 18090541 19836685 146373571 17947452 534010506 46933264 377035021 311636557 75193963 54321761 12759959 71120181 548816939 23608621 31876417 107672995 72575155 369667956 20574379 210596751 532163173 75726739 853719629",
"output": "44"
},
{
"input": "8 6\n204157376 10514197 65483881 347219841 263304577 296402721 11739011 229776191",
"output": "8"
},
{
"input": "38 29\n333702889 680931737 61137217 203030505 68728281 11414209 642645708 590904616 3042901 607198177 189041074 700764043 813035201 198341461 126403544 401436841 420826465 45046581 20249976 46978855 46397957 706610773 24701041 57954481 51603266 593109701 385569073 178982291 582152863 287317968 1474090 34825141 432421977 130257781 151516903 540852403 548392 117246529",
"output": "38"
},
{
"input": "19 3\n562569697 549131571 50676718 84501863 74567295 702372009 365895280 451459937 40378543 167666701 158635641 53639293 442332661 825055617 100109161 326616021 862332843 533271196 4791547",
"output": "18"
},
{
"input": "1 1\n44",
"output": "0"
},
{
"input": "1 1\n4",
"output": "1"
},
{
"input": "10 3\n444 447 774 777 7777 4447 4 7 7 4",
"output": "8"
}
] | 1,581,844,211 | 2,147,483,647 | PyPy 3 | OK | TESTS | 34 | 280 | 0 | x,y=map(int,input().split())
print(sum(list(map((lambda i: 1 if i.count('4')+i.count('7')<=y else 0),input().split()))))
#author:SK__Shanto__㋛
#code__define__your__smartness | Title: Roma and Lucky Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Roma (a popular Russian name that means 'Roman') loves the Little Lvov Elephant's lucky numbers.
Let us remind you that lucky numbers are positive integers whose decimal representation only contains lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Roma's got *n* positive integers. He wonders, how many of those integers have not more than *k* lucky digits? Help him, write the program that solves the problem.
Input Specification:
The first line contains two integers *n*, *k* (1<=≤<=*n*,<=*k*<=≤<=100). The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) — the numbers that Roma has.
The numbers in the lines are separated by single spaces.
Output Specification:
In a single line print a single integer — the answer to the problem.
Demo Input:
['3 4\n1 2 4\n', '3 2\n447 44 77\n']
Demo Output:
['3\n', '2\n']
Note:
In the first sample all numbers contain at most four lucky digits, so the answer is 3.
In the second sample number 447 doesn't fit in, as it contains more than two lucky digits. All other numbers are fine, so the answer is 2. | ```python
x,y=map(int,input().split())
print(sum(list(map((lambda i: 1 if i.count('4')+i.count('7')<=y else 0),input().split()))))
#author:SK__Shanto__㋛
#code__define__your__smartness
``` | 3 |
|
25 | A | IQ test | PROGRAMMING | 1,300 | [
"brute force"
] | A. IQ test | 2 | 256 | Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that 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,635,875,455 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 92 | 4,505,600 | num = int(input())
numbers = [int(num) for num in input().split(" ")]
evens = 0
odds = 0
even_index = 0
odd_index = 0
for number in numbers:
if number % 2:
odds += 1
odd_index = numbers.index(number) + 1
else:
evens += 1
even_index = numbers.index(number) + 1
if evens == 1:
print(even_index)
else:
print(odd_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
num = int(input())
numbers = [int(num) for num in input().split(" ")]
evens = 0
odds = 0
even_index = 0
odd_index = 0
for number in numbers:
if number % 2:
odds += 1
odd_index = numbers.index(number) + 1
else:
evens += 1
even_index = numbers.index(number) + 1
if evens == 1:
print(even_index)
else:
print(odd_index)
``` | 3.968608 |
11 | A | Increasing Sequence | PROGRAMMING | 900 | [
"constructive algorithms",
"implementation",
"math"
] | A. Increasing Sequence | 1 | 64 | A sequence *a*0,<=*a*1,<=...,<=*a**t*<=-<=1 is called increasing if *a**i*<=-<=1<=<<=*a**i* for each *i*:<=0<=<<=*i*<=<<=*t*.
You are given a sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 and a positive integer *d*. In each move you may choose one element of the given sequence and add *d* to it. What is the least number of moves required to make the given sequence increasing? | The first line of the input contains two integer numbers *n* and *d* (2<=≤<=*n*<=≤<=2000,<=1<=≤<=*d*<=≤<=106). The second line contains space separated sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 (1<=≤<=*b**i*<=≤<=106). | Output the minimal number of moves needed to make the sequence increasing. | [
"4 2\n1 3 3 2\n"
] | [
"3\n"
] | none | 0 | [
{
"input": "4 2\n1 3 3 2",
"output": "3"
},
{
"input": "2 1\n1 1",
"output": "1"
},
{
"input": "2 1\n2 5",
"output": "0"
},
{
"input": "2 1\n1 2",
"output": "0"
},
{
"input": "2 1\n1 1",
"output": "1"
},
{
"input": "2 7\n10 20",
"output": "0"
},
{
"input": "2 7\n1 1",
"output": "1"
},
{
"input": "3 3\n18 1 9",
"output": "10"
},
{
"input": "3 3\n15 17 9",
"output": "3"
},
{
"input": "3 3\n10 9 12",
"output": "2"
},
{
"input": "10 3\n2 1 17 10 5 16 8 4 15 17",
"output": "31"
},
{
"input": "10 3\n6 11 4 12 22 15 23 26 24 26",
"output": "13"
},
{
"input": "10 3\n10 24 13 15 18 14 15 26 33 35",
"output": "29"
},
{
"input": "100 3\n529 178 280 403 326 531 671 427 188 866 669 646 421 804 494 609 53 1012 211 243 887 833 900 543 226 42 859 718 454 372 971 692 846 770 511 395 499 479 641 756 115 269 206 45 1039 727 400 779 859 614 146 214 196 919 702 959 380 830 535 878 859 784 316 305 782 924 536 243 236 978 564 150 291 877 808 983 537 839 490 120 168 838 267 650 900 170 211 504 326 771 895 984 994 483 776 100 471 1078 317 580",
"output": "15717"
},
{
"input": "100 3\n329 226 331 909 962 112 837 1005 194 818 506 416 125 648 367 459 400 582 989 547 329 438 234 121 272 226 821 376 834 427 718 164 834 113 654 177 737 212 169 696 744 180 89 944 233 147 667 990 809 1072 1085 1093 814 265 1067 312 833 572 303 901 1032 504 185 817 389 158 613 723 239 269 911 352 769 404 225 822 897 606 947 323 913 804 923 1084 552 901 486 249 209 898 847 610 728 1122 986 669 1116 1076 367 327",
"output": "16133"
}
] | 1,563,041,662 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 248 | 307,200 | n, d = [int(i) for i in input().split()]
lst = [int(i) for i in input().split()]
count1, count2 = 0, 0
for elem in lst:
if elem <= count1:
c = (count1 + d - elem) // d
count2 += c
elem += c * d
count1 = elem
print(count2)
| Title: Increasing Sequence
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
A sequence *a*0,<=*a*1,<=...,<=*a**t*<=-<=1 is called increasing if *a**i*<=-<=1<=<<=*a**i* for each *i*:<=0<=<<=*i*<=<<=*t*.
You are given a sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 and a positive integer *d*. In each move you may choose one element of the given sequence and add *d* to it. What is the least number of moves required to make the given sequence increasing?
Input Specification:
The first line of the input contains two integer numbers *n* and *d* (2<=≤<=*n*<=≤<=2000,<=1<=≤<=*d*<=≤<=106). The second line contains space separated sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 (1<=≤<=*b**i*<=≤<=106).
Output Specification:
Output the minimal number of moves needed to make the sequence increasing.
Demo Input:
['4 2\n1 3 3 2\n']
Demo Output:
['3\n']
Note:
none | ```python
n, d = [int(i) for i in input().split()]
lst = [int(i) for i in input().split()]
count1, count2 = 0, 0
for elem in lst:
if elem <= count1:
c = (count1 + d - elem) // d
count2 += c
elem += c * d
count1 = elem
print(count2)
``` | 3.873711 |
199 | A | Hexadecimal's theorem | PROGRAMMING | 900 | [
"brute force",
"constructive algorithms",
"implementation",
"number theory"
] | null | null | Recently, a chaotic virus Hexadecimal advanced a new theorem which will shake the Universe. She thinks that each Fibonacci number can be represented as sum of three not necessary different Fibonacci numbers.
Let's remember how Fibonacci numbers can be calculated. *F*0<==<=0, *F*1<==<=1, and all the next numbers are *F**i*<==<=*F**i*<=-<=2<=+<=*F**i*<=-<=1.
So, Fibonacci numbers make a sequence of numbers: 0, 1, 1, 2, 3, 5, 8, 13, ...
If you haven't run away from the PC in fear, you have to help the virus. Your task is to divide given Fibonacci number *n* by three not necessary different Fibonacci numbers or say that it is impossible. | The input contains of a single integer *n* (0<=≤<=*n*<=<<=109) — the number that should be represented by the rules described above. It is guaranteed that *n* is a Fibonacci number. | Output three required numbers: *a*, *b* and *c*. If there is no answer for the test you have to print "I'm too stupid to solve this problem" without the quotes.
If there are multiple answers, print any of them. | [
"3\n",
"13\n"
] | [
"1 1 1\n",
"2 3 8\n"
] | none | 500 | [
{
"input": "3",
"output": "1 1 1"
},
{
"input": "13",
"output": "2 3 8"
},
{
"input": "0",
"output": "0 0 0"
},
{
"input": "1",
"output": "1 0 0"
},
{
"input": "2",
"output": "1 1 0"
},
{
"input": "1597",
"output": "233 377 987"
},
{
"input": "0",
"output": "0 0 0"
},
{
"input": "1",
"output": "1 0 0"
},
{
"input": "1",
"output": "1 0 0"
},
{
"input": "2",
"output": "1 1 0"
},
{
"input": "3",
"output": "1 1 1"
},
{
"input": "5",
"output": "1 1 3"
},
{
"input": "8",
"output": "1 2 5"
},
{
"input": "13",
"output": "2 3 8"
},
{
"input": "21",
"output": "3 5 13"
},
{
"input": "34",
"output": "5 8 21"
},
{
"input": "55",
"output": "8 13 34"
},
{
"input": "89",
"output": "13 21 55"
},
{
"input": "144",
"output": "21 34 89"
},
{
"input": "233",
"output": "34 55 144"
},
{
"input": "377",
"output": "55 89 233"
},
{
"input": "610",
"output": "89 144 377"
},
{
"input": "987",
"output": "144 233 610"
},
{
"input": "1597",
"output": "233 377 987"
},
{
"input": "2584",
"output": "377 610 1597"
},
{
"input": "4181",
"output": "610 987 2584"
},
{
"input": "6765",
"output": "987 1597 4181"
},
{
"input": "10946",
"output": "1597 2584 6765"
},
{
"input": "17711",
"output": "2584 4181 10946"
},
{
"input": "28657",
"output": "4181 6765 17711"
},
{
"input": "46368",
"output": "6765 10946 28657"
},
{
"input": "75025",
"output": "10946 17711 46368"
},
{
"input": "121393",
"output": "17711 28657 75025"
},
{
"input": "196418",
"output": "28657 46368 121393"
},
{
"input": "317811",
"output": "46368 75025 196418"
},
{
"input": "514229",
"output": "75025 121393 317811"
},
{
"input": "832040",
"output": "121393 196418 514229"
},
{
"input": "1346269",
"output": "196418 317811 832040"
},
{
"input": "2178309",
"output": "317811 514229 1346269"
},
{
"input": "3524578",
"output": "514229 832040 2178309"
},
{
"input": "5702887",
"output": "832040 1346269 3524578"
},
{
"input": "9227465",
"output": "1346269 2178309 5702887"
},
{
"input": "14930352",
"output": "2178309 3524578 9227465"
},
{
"input": "24157817",
"output": "3524578 5702887 14930352"
},
{
"input": "39088169",
"output": "5702887 9227465 24157817"
},
{
"input": "63245986",
"output": "9227465 14930352 39088169"
},
{
"input": "102334155",
"output": "14930352 24157817 63245986"
},
{
"input": "165580141",
"output": "24157817 39088169 102334155"
},
{
"input": "267914296",
"output": "39088169 63245986 165580141"
},
{
"input": "433494437",
"output": "63245986 102334155 267914296"
},
{
"input": "701408733",
"output": "102334155 165580141 433494437"
},
{
"input": "701408733",
"output": "102334155 165580141 433494437"
},
{
"input": "102334155",
"output": "14930352 24157817 63245986"
},
{
"input": "63245986",
"output": "9227465 14930352 39088169"
}
] | 1,616,877,167 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 92 | 0 | x = int(input())
y = float(x/3)
a = int(y)
b = int(y)
c = int(y) + 1
if x % 3 == 0:
c -= 1
print(a, b, c) | Title: Hexadecimal's theorem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, a chaotic virus Hexadecimal advanced a new theorem which will shake the Universe. She thinks that each Fibonacci number can be represented as sum of three not necessary different Fibonacci numbers.
Let's remember how Fibonacci numbers can be calculated. *F*0<==<=0, *F*1<==<=1, and all the next numbers are *F**i*<==<=*F**i*<=-<=2<=+<=*F**i*<=-<=1.
So, Fibonacci numbers make a sequence of numbers: 0, 1, 1, 2, 3, 5, 8, 13, ...
If you haven't run away from the PC in fear, you have to help the virus. Your task is to divide given Fibonacci number *n* by three not necessary different Fibonacci numbers or say that it is impossible.
Input Specification:
The input contains of a single integer *n* (0<=≤<=*n*<=<<=109) — the number that should be represented by the rules described above. It is guaranteed that *n* is a Fibonacci number.
Output Specification:
Output three required numbers: *a*, *b* and *c*. If there is no answer for the test you have to print "I'm too stupid to solve this problem" without the quotes.
If there are multiple answers, print any of them.
Demo Input:
['3\n', '13\n']
Demo Output:
['1 1 1\n', '2 3 8\n']
Note:
none | ```python
x = int(input())
y = float(x/3)
a = int(y)
b = int(y)
c = int(y) + 1
if x % 3 == 0:
c -= 1
print(a, b, c)
``` | 0 |
|
984 | A | Game | PROGRAMMING | 800 | [
"sortings"
] | null | null | Two players play a game.
Initially there are $n$ integers $a_1, a_2, \ldots, a_n$ written on the board. Each turn a player selects one number and erases it from the board. This continues until there is only one number left on the board, i. e. $n - 1$ turns are made. The first player makes the first move, then players alternate turns.
The first player wants to minimize the last number that would be left on the board, while the second player wants to maximize it.
You want to know what number will be left on the board after $n - 1$ turns if both players make optimal moves. | The first line contains one integer $n$ ($1 \le n \le 1000$) — the number of numbers on the board.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^6$). | Print one number that will be left on the board. | [
"3\n2 1 3\n",
"3\n2 2 2\n"
] | [
"2",
"2"
] | In the first sample, the first player erases $3$ and the second erases $1$. $2$ is left on the board.
In the second sample, $2$ is left on the board regardless of the actions of the players. | 500 | [
{
"input": "3\n2 1 3",
"output": "2"
},
{
"input": "3\n2 2 2",
"output": "2"
},
{
"input": "9\n44 53 51 80 5 27 74 79 94",
"output": "53"
},
{
"input": "10\n38 82 23 37 96 4 81 60 67 86",
"output": "60"
},
{
"input": "10\n58 26 77 15 53 81 68 48 22 65",
"output": "53"
},
{
"input": "1\n124",
"output": "124"
},
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "3\n1 1 1000",
"output": "1"
},
{
"input": "2\n322 322",
"output": "322"
},
{
"input": "3\n9 92 12",
"output": "12"
},
{
"input": "3\n1 2 2",
"output": "2"
}
] | 1,611,212,572 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 3 | 124 | 2,150,400 | n = int(input())
s = list(map(int, input().split()))
while len(s) != 1:
m1 = max(s)
s.remove(m1)
m2 = min(s)
s.remove(m2)
print(*s) | Title: Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two players play a game.
Initially there are $n$ integers $a_1, a_2, \ldots, a_n$ written on the board. Each turn a player selects one number and erases it from the board. This continues until there is only one number left on the board, i. e. $n - 1$ turns are made. The first player makes the first move, then players alternate turns.
The first player wants to minimize the last number that would be left on the board, while the second player wants to maximize it.
You want to know what number will be left on the board after $n - 1$ turns if both players make optimal moves.
Input Specification:
The first line contains one integer $n$ ($1 \le n \le 1000$) — the number of numbers on the board.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^6$).
Output Specification:
Print one number that will be left on the board.
Demo Input:
['3\n2 1 3\n', '3\n2 2 2\n']
Demo Output:
['2', '2']
Note:
In the first sample, the first player erases $3$ and the second erases $1$. $2$ is left on the board.
In the second sample, $2$ is left on the board regardless of the actions of the players. | ```python
n = int(input())
s = list(map(int, input().split()))
while len(s) != 1:
m1 = max(s)
s.remove(m1)
m2 = min(s)
s.remove(m2)
print(*s)
``` | -1 |
|
103 | B | Cthulhu | PROGRAMMING | 1,500 | [
"dfs and similar",
"dsu",
"graphs"
] | B. Cthulhu | 2 | 256 | ...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu...
Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super weapon. Due to high seismic activity and poor weather conditions the satellites haven't yet been able to make clear shots of the monster. The analysis of the first shot resulted in an undirected graph with *n* vertices and *m* edges. Now the world's best minds are about to determine whether this graph can be regarded as Cthulhu or not.
To add simplicity, let's suppose that Cthulhu looks from the space like some spherical body with tentacles attached to it. Formally, we shall regard as Cthulhu such an undirected graph that can be represented as a set of three or more rooted trees, whose roots are connected by a simple cycle.
It is guaranteed that the graph contains no multiple edges and self-loops. | The first line contains two integers — the number of vertices *n* and the number of edges *m* of the graph (1<=≤<=*n*<=≤<=100, 0<=≤<=*m*<=≤<=).
Each of the following *m* lines contains a pair of integers *x* and *y*, that show that an edge exists between vertices *x* and *y* (1<=≤<=*x*,<=*y*<=≤<=*n*,<=*x*<=≠<=*y*). For each pair of vertices there will be at most one edge between them, no edge connects a vertex to itself. | Print "NO", if the graph is not Cthulhu and "FHTAGN!" if it is. | [
"6 6\n6 3\n6 4\n5 1\n2 5\n1 4\n5 4\n",
"6 5\n5 6\n4 6\n3 1\n5 1\n1 2\n"
] | [
"FHTAGN!",
"NO"
] | Let us denote as a simple cycle a set of *v* vertices that can be numbered so that the edges will only exist between vertices number 1 and 2, 2 and 3, ..., *v* - 1 and *v*, *v* and 1.
A tree is a connected undirected graph consisting of *n* vertices and *n* - 1 edges (*n* > 0).
A rooted tree is a tree where one vertex is selected to be the root. | 1,000 | [
{
"input": "6 6\n6 3\n6 4\n5 1\n2 5\n1 4\n5 4",
"output": "FHTAGN!"
},
{
"input": "6 5\n5 6\n4 6\n3 1\n5 1\n1 2",
"output": "NO"
},
{
"input": "10 10\n4 10\n8 5\n2 8\n4 9\n9 3\n2 7\n10 6\n10 2\n9 8\n1 8",
"output": "FHTAGN!"
},
{
"input": "5 4\n1 5\n1 3\n1 4\n3 2",
"output": "NO"
},
{
"input": "12 12\n4 12\n4 7\n4 9\n7 2\n5 12\n2 1\n5 9\n8 6\n10 12\n2 5\n10 9\n12 3",
"output": "NO"
},
{
"input": "12 15\n3 2\n11 12\n1 9\n2 1\n1 8\n9 6\n11 5\n9 5\n9 10\n11 3\n7 11\n5 6\n11 10\n4 6\n4 2",
"output": "NO"
},
{
"input": "12 10\n1 11\n3 6\n5 7\n4 7\n6 8\n11 7\n3 12\n11 12\n7 9\n12 2",
"output": "NO"
},
{
"input": "1 0",
"output": "NO"
},
{
"input": "2 1\n1 2",
"output": "NO"
},
{
"input": "3 1\n1 3",
"output": "NO"
},
{
"input": "3 2\n1 2\n2 3",
"output": "NO"
},
{
"input": "3 3\n1 2\n2 3\n3 1",
"output": "FHTAGN!"
},
{
"input": "4 4\n1 2\n3 4\n4 1\n2 4",
"output": "FHTAGN!"
},
{
"input": "6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 4",
"output": "NO"
},
{
"input": "2 0",
"output": "NO"
},
{
"input": "3 0",
"output": "NO"
},
{
"input": "100 0",
"output": "NO"
},
{
"input": "100 1\n11 23",
"output": "NO"
},
{
"input": "10 10\n5 7\n8 1\n10 3\n6 4\n10 6\n5 3\n5 6\n2 6\n4 3\n2 10",
"output": "NO"
},
{
"input": "20 20\n9 10\n4 19\n9 20\n12 20\n1 15\n2 12\n19 10\n19 15\n4 10\n4 8\n8 9\n20 8\n6 2\n2 15\n7 19\n20 4\n3 16\n1 20\n9 1\n20 10",
"output": "NO"
},
{
"input": "30 30\n17 6\n16 29\n16 13\n16 20\n29 26\n17 5\n27 28\n24 16\n7 18\n24 10\n1 27\n12 17\n27 30\n6 1\n3 30\n5 19\n18 13\n16 2\n30 1\n5 8\n14 16\n26 18\n7 19\n5 6\n23 14\n6 8\n23 8\n18 8\n18 3\n5 21",
"output": "NO"
},
{
"input": "100 66\n41 14\n19 13\n70 43\n79 62\n9 62\n71 40\n53 86\n80 4\n34 33\n72 68\n40 96\n84 59\n36 77\n55 50\n40 3\n79 81\n3 43\n33 47\n22 98\n33 90\n56 49\n69 28\n73 30\n65 22\n98 20\n9 52\n54 20\n32 70\n51 80\n63 12\n21 48\n35 17\n48 87\n25 43\n65 80\n42 3\n86 35\n95 98\n43 59\n51 46\n66 37\n88 34\n32 47\n24 42\n21 44\n92 59\n81 6\n100 82\n85 6\n58 25\n66 6\n14 32\n59 85\n3 98\n44 4\n85 51\n69 41\n80 70\n81 24\n75 71\n93 9\n82 55\n70 46\n66 32\n77 58\n11 46",
"output": "NO"
},
{
"input": "4 4\n1 2\n4 3\n2 3\n3 1",
"output": "FHTAGN!"
},
{
"input": "5 5\n2 3\n2 4\n5 4\n4 1\n1 2",
"output": "FHTAGN!"
},
{
"input": "10 10\n1 10\n5 9\n6 2\n8 9\n9 1\n5 4\n2 8\n1 3\n6 3\n4 1",
"output": "NO"
},
{
"input": "6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 4",
"output": "NO"
},
{
"input": "4 3\n1 2\n2 3\n3 1",
"output": "NO"
},
{
"input": "6 5\n1 2\n2 3\n3 1\n1 4\n1 5",
"output": "NO"
}
] | 1,539,064,451 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 218 | 0 | def findSet(u):
if parents[u] != u:
parents[u] = findSet(parents[u])
return parents[u]
def unionSet(u, v):
up = findSet(u)
vp = findSet(v)
if up == vp:
return True
if ranks[up] > ranks[vp]:
parents[vp] = up
elif ranks[up] < ranks[vp]:
parents[up] = vp
else:
parents[up] = vp
ranks[vp] += 1
return False
n, m = map(int, input().split())
parents = [i for i in range(n)]
ranks = [0 for i in range(n)]
edges = set()
result = False
for i in range(m):
x, y = map(int, input().split())
x -= 1
y -= 1
has_cycle = unionSet(x, y)
if has_cycle:
result = True
edges.add((x, y))
# print(parents)
# roots = []
# for p in range(len(parents)):
# if p == parents[p]:
# roots.append(parents[p])
# roots.sort()
# print(roots)
if result:
print("FHTAGN!")
else:
print("NO")
| Title: Cthulhu
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu...
Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super weapon. Due to high seismic activity and poor weather conditions the satellites haven't yet been able to make clear shots of the monster. The analysis of the first shot resulted in an undirected graph with *n* vertices and *m* edges. Now the world's best minds are about to determine whether this graph can be regarded as Cthulhu or not.
To add simplicity, let's suppose that Cthulhu looks from the space like some spherical body with tentacles attached to it. Formally, we shall regard as Cthulhu such an undirected graph that can be represented as a set of three or more rooted trees, whose roots are connected by a simple cycle.
It is guaranteed that the graph contains no multiple edges and self-loops.
Input Specification:
The first line contains two integers — the number of vertices *n* and the number of edges *m* of the graph (1<=≤<=*n*<=≤<=100, 0<=≤<=*m*<=≤<=).
Each of the following *m* lines contains a pair of integers *x* and *y*, that show that an edge exists between vertices *x* and *y* (1<=≤<=*x*,<=*y*<=≤<=*n*,<=*x*<=≠<=*y*). For each pair of vertices there will be at most one edge between them, no edge connects a vertex to itself.
Output Specification:
Print "NO", if the graph is not Cthulhu and "FHTAGN!" if it is.
Demo Input:
['6 6\n6 3\n6 4\n5 1\n2 5\n1 4\n5 4\n', '6 5\n5 6\n4 6\n3 1\n5 1\n1 2\n']
Demo Output:
['FHTAGN!', 'NO']
Note:
Let us denote as a simple cycle a set of *v* vertices that can be numbered so that the edges will only exist between vertices number 1 and 2, 2 and 3, ..., *v* - 1 and *v*, *v* and 1.
A tree is a connected undirected graph consisting of *n* vertices and *n* - 1 edges (*n* > 0).
A rooted tree is a tree where one vertex is selected to be the root. | ```python
def findSet(u):
if parents[u] != u:
parents[u] = findSet(parents[u])
return parents[u]
def unionSet(u, v):
up = findSet(u)
vp = findSet(v)
if up == vp:
return True
if ranks[up] > ranks[vp]:
parents[vp] = up
elif ranks[up] < ranks[vp]:
parents[up] = vp
else:
parents[up] = vp
ranks[vp] += 1
return False
n, m = map(int, input().split())
parents = [i for i in range(n)]
ranks = [0 for i in range(n)]
edges = set()
result = False
for i in range(m):
x, y = map(int, input().split())
x -= 1
y -= 1
has_cycle = unionSet(x, y)
if has_cycle:
result = True
edges.add((x, y))
# print(parents)
# roots = []
# for p in range(len(parents)):
# if p == parents[p]:
# roots.append(parents[p])
# roots.sort()
# print(roots)
if result:
print("FHTAGN!")
else:
print("NO")
``` | 0 |
467 | D | Fedor and Essay | PROGRAMMING | 2,400 | [
"dfs and similar",
"dp",
"graphs",
"hashing",
"strings"
] | null | null | After you had helped Fedor to find friends in the «Call of Soldiers 3» game, he stopped studying completely. Today, the English teacher told him to prepare an essay. Fedor didn't want to prepare the essay, so he asked Alex for help. Alex came to help and wrote the essay for Fedor. But Fedor didn't like the essay at all. Now Fedor is going to change the essay using the synonym dictionary of the English language.
Fedor does not want to change the meaning of the essay. So the only change he would do: change a word from essay to one of its synonyms, basing on a replacement rule from the dictionary. Fedor may perform this operation any number of times.
As a result, Fedor wants to get an essay which contains as little letters «R» (the case doesn't matter) as possible. If there are multiple essays with minimum number of «R»s he wants to get the one with minimum length (length of essay is the sum of the lengths of all the words in it). Help Fedor get the required essay.
Please note that in this problem the case of letters doesn't matter. For example, if the synonym dictionary says that word cat can be replaced with word DOG, then it is allowed to replace the word Cat with the word doG. | The first line contains a single integer *m* (1<=≤<=*m*<=≤<=105) — the number of words in the initial essay. The second line contains words of the essay. The words are separated by a single space. It is guaranteed that the total length of the words won't exceed 105 characters.
The next line contains a single integer *n* (0<=≤<=*n*<=≤<=105) — the number of pairs of words in synonym dictionary. The *i*-th of the next *n* lines contains two space-separated non-empty words *x**i* and *y**i*. They mean that word *x**i* can be replaced with word *y**i* (but not vise versa). It is guaranteed that the total length of all pairs of synonyms doesn't exceed 5·105 characters.
All the words at input can only consist of uppercase and lowercase letters of the English alphabet. | Print two integers — the minimum number of letters «R» in an optimal essay and the minimum length of an optimal essay. | [
"3\nAbRb r Zz\n4\nxR abRb\naA xr\nzz Z\nxr y\n",
"2\nRuruRu fedya\n1\nruruRU fedor\n"
] | [
"2 6\n",
"1 10\n"
] | none | 2,000 | [
{
"input": "3\nAbRb r Zz\n4\nxR abRb\naA xr\nzz Z\nxr y",
"output": "2 6"
},
{
"input": "2\nRuruRu fedya\n1\nruruRU fedor",
"output": "1 10"
},
{
"input": "1\nffff\n1\nffff r",
"output": "0 4"
},
{
"input": "2\nYURA YUrA\n1\nyura fedya",
"output": "0 10"
},
{
"input": "5\nhello my name is fedya\n2\nhello hi\nis i",
"output": "0 14"
},
{
"input": "5\nawiuegjsrkjshegkjshegseg g soeigjseg www s\n3\nwww s\nawiuegjsrkjshegkjshegseg wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww\nwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww www",
"output": "0 13"
},
{
"input": "5\naa bb cc ee ff\n5\naa a\nbb aa\ncc bb\nee cc\nff bb",
"output": "0 5"
},
{
"input": "7\nraki vezde est awjgkawkgjn ttttt raki raks\n4\nraks rks\nrks raks\nraki raks\nvezde pss",
"output": "3 31"
},
{
"input": "5\nfedor fedya www awwwwwww a\n5\nr a\nfedor fedr\nwww a\nawwwwwww www\na r",
"output": "1 12"
},
{
"input": "1\nYURA\n1\nyura lesha",
"output": "0 5"
},
{
"input": "2\nABBABAABBAABABBABAABABBAABBABAABBAABABBAABBABAABABBABAABBAABABBA ABBABAABBAABABBABAABABBAABBABAABBAABABBAABBABAABABBABAABBAABABA\n2\nABBABAABBAABABBABAABABBAABBABAABBAABABBAABBABAABABBABAABBAABABA neuzaiheshi\nABBABAABBAABABBABAABABBAABBABAABBAABABBAABBABAABABBABAABBAABABBA ABBABAABBAABABBABAABABBAABBABAABBAABABBAABBABAABABBABAABBAABABA",
"output": "0 22"
},
{
"input": "10\nlalka lolka yura lesha fedya bredor tourist www qqq gruihdrkgjp\n11\nlalka lolka\nlolka lalka\nyura lolka\nlalka poka\nfedya bredor\nbredor yura\ntourist bredor\nwww qqq\nqqq w\nw g\ngruihdrkgjp bredor",
"output": "0 35"
},
{
"input": "1\nR\n0",
"output": "1 1"
},
{
"input": "3\nreka greka rak\n11\nrek rak\nrak grek\nreka rak\ngreka reka\nrak reka\nrak greka\ngreka rak\nlol rek\nlol rak\nLO lol\nABA BA",
"output": "3 9"
},
{
"input": "3\nreka greka rak\n13\nrek rak\nrak grek\nreka rak\ngreka reka\nrak reka\nrak greka\ngreka rak\nlol rek\nlol rak\nlol LO\nABA BA\nLOLKA rak\nrak lol",
"output": "0 6"
},
{
"input": "1\nr\n0",
"output": "1 1"
},
{
"input": "5\nfEdOR Is A bAd BoY\n2\nboy boYy\nFeDor fedyaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "0 70"
},
{
"input": "1\nyrwlqadsfw\n2\nmnqdxczpyo a\na mnqdxczpyo",
"output": "1 10"
},
{
"input": "4\nr rr rrr rrrr\n9\nrr rrr\nrrrr rr\nr rr\nr rrrr\nrrr rr\nrrr rrr\nrr rrr\nrr r\nr r",
"output": "4 4"
}
] | 1,689,029,645 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 307,200 | from sys import stdin
from collections import defaultdict
def main():
num = {}
stdin.readline()
essay = []
for word in stdin.readline().strip().lower().split():
count_r = word.count('r')
length = len(word)
num.setdefault(word, len(num))
essay.append((count_r, length, num[word]))
n_synonyms = int(stdin.readline())
synonyms = defaultdict(list)
for _ in range(n_synonyms):
word, rep = stdin.readline().strip().lower().split()
count_word_r = word.count('r')
count_rep_r = rep.count('r')
num.setdefault(word, len(num))
num.setdefault(rep, len(num))
synonyms[num[rep]].append(num[word])
essay.sort(reverse=True)
best = {}
for n_r, length, word in essay:
if word not in best:
best[word] = n_r, length
for rep in synonyms[word]:
if rep not in best:
essay.append((n_r, length, rep))
sum_n_r, sum_len = 0, 0
for n_r, length, word in essay:
n_r, length = best[word]
sum_n_r += n_r
sum_len += length
print(sum_n_r, sum_len)
if __name__ == '__main__':
main()
| Title: Fedor and Essay
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After you had helped Fedor to find friends in the «Call of Soldiers 3» game, he stopped studying completely. Today, the English teacher told him to prepare an essay. Fedor didn't want to prepare the essay, so he asked Alex for help. Alex came to help and wrote the essay for Fedor. But Fedor didn't like the essay at all. Now Fedor is going to change the essay using the synonym dictionary of the English language.
Fedor does not want to change the meaning of the essay. So the only change he would do: change a word from essay to one of its synonyms, basing on a replacement rule from the dictionary. Fedor may perform this operation any number of times.
As a result, Fedor wants to get an essay which contains as little letters «R» (the case doesn't matter) as possible. If there are multiple essays with minimum number of «R»s he wants to get the one with minimum length (length of essay is the sum of the lengths of all the words in it). Help Fedor get the required essay.
Please note that in this problem the case of letters doesn't matter. For example, if the synonym dictionary says that word cat can be replaced with word DOG, then it is allowed to replace the word Cat with the word doG.
Input Specification:
The first line contains a single integer *m* (1<=≤<=*m*<=≤<=105) — the number of words in the initial essay. The second line contains words of the essay. The words are separated by a single space. It is guaranteed that the total length of the words won't exceed 105 characters.
The next line contains a single integer *n* (0<=≤<=*n*<=≤<=105) — the number of pairs of words in synonym dictionary. The *i*-th of the next *n* lines contains two space-separated non-empty words *x**i* and *y**i*. They mean that word *x**i* can be replaced with word *y**i* (but not vise versa). It is guaranteed that the total length of all pairs of synonyms doesn't exceed 5·105 characters.
All the words at input can only consist of uppercase and lowercase letters of the English alphabet.
Output Specification:
Print two integers — the minimum number of letters «R» in an optimal essay and the minimum length of an optimal essay.
Demo Input:
['3\nAbRb r Zz\n4\nxR abRb\naA xr\nzz Z\nxr y\n', '2\nRuruRu fedya\n1\nruruRU fedor\n']
Demo Output:
['2 6\n', '1 10\n']
Note:
none | ```python
from sys import stdin
from collections import defaultdict
def main():
num = {}
stdin.readline()
essay = []
for word in stdin.readline().strip().lower().split():
count_r = word.count('r')
length = len(word)
num.setdefault(word, len(num))
essay.append((count_r, length, num[word]))
n_synonyms = int(stdin.readline())
synonyms = defaultdict(list)
for _ in range(n_synonyms):
word, rep = stdin.readline().strip().lower().split()
count_word_r = word.count('r')
count_rep_r = rep.count('r')
num.setdefault(word, len(num))
num.setdefault(rep, len(num))
synonyms[num[rep]].append(num[word])
essay.sort(reverse=True)
best = {}
for n_r, length, word in essay:
if word not in best:
best[word] = n_r, length
for rep in synonyms[word]:
if rep not in best:
essay.append((n_r, length, rep))
sum_n_r, sum_len = 0, 0
for n_r, length, word in essay:
n_r, length = best[word]
sum_n_r += n_r
sum_len += length
print(sum_n_r, sum_len)
if __name__ == '__main__':
main()
``` | 0 |
|
915 | C | Permute Digits | PROGRAMMING | 1,700 | [
"dp",
"greedy"
] | null | null | You are given two positive integer numbers *a* and *b*. Permute (change order) of the digits of *a* to construct maximal number not exceeding *b*. No number in input and/or output can start with the digit 0.
It is allowed to leave *a* as it is. | The first line contains integer *a* (1<=≤<=*a*<=≤<=1018). The second line contains integer *b* (1<=≤<=*b*<=≤<=1018). Numbers don't have leading zeroes. It is guaranteed that answer exists. | Print the maximum possible number that is a permutation of digits of *a* and is not greater than *b*. The answer can't have any leading zeroes. It is guaranteed that the answer exists.
The number in the output should have exactly the same length as number *a*. It should be a permutation of digits of *a*. | [
"123\n222\n",
"3921\n10000\n",
"4940\n5000\n"
] | [
"213\n",
"9321\n",
"4940\n"
] | none | 0 | [
{
"input": "123\n222",
"output": "213"
},
{
"input": "3921\n10000",
"output": "9321"
},
{
"input": "4940\n5000",
"output": "4940"
},
{
"input": "23923472834\n23589234723",
"output": "23498743322"
},
{
"input": "102391019\n491010301",
"output": "399211100"
},
{
"input": "123456789123456789\n276193619183618162",
"output": "276193618987554432"
},
{
"input": "1000000000000000000\n1000000000000000000",
"output": "1000000000000000000"
},
{
"input": "1\n1000000000000000000",
"output": "1"
},
{
"input": "999999999999999999\n1000000000000000000",
"output": "999999999999999999"
},
{
"input": "2475345634895\n3455834583479",
"output": "3455834579642"
},
{
"input": "15778899\n98715689",
"output": "98598771"
},
{
"input": "4555\n5454",
"output": "4555"
},
{
"input": "122112\n221112",
"output": "221112"
},
{
"input": "199999999999991\n191000000000000",
"output": "119999999999999"
},
{
"input": "13\n31",
"output": "31"
},
{
"input": "212\n211",
"output": "122"
},
{
"input": "222234\n322223",
"output": "243222"
},
{
"input": "123456789\n987654311",
"output": "987654231"
},
{
"input": "20123\n21022",
"output": "20321"
},
{
"input": "10101\n11000",
"output": "10110"
},
{
"input": "592\n924",
"output": "592"
},
{
"input": "5654456\n5634565",
"output": "5566544"
},
{
"input": "655432\n421631",
"output": "365542"
},
{
"input": "200\n200",
"output": "200"
},
{
"input": "123456789987654321\n121111111111111111",
"output": "119988776655443322"
},
{
"input": "12345\n21344",
"output": "15432"
},
{
"input": "120\n200",
"output": "120"
},
{
"input": "123\n212",
"output": "132"
},
{
"input": "2184645\n5213118",
"output": "5186442"
},
{
"input": "9912346\n9912345",
"output": "9694321"
},
{
"input": "5003\n5000",
"output": "3500"
},
{
"input": "12345\n31234",
"output": "25431"
},
{
"input": "5001\n5000",
"output": "1500"
},
{
"input": "53436\n53425",
"output": "53364"
},
{
"input": "9329\n3268",
"output": "2993"
},
{
"input": "1234567890\n9000000001",
"output": "8976543210"
},
{
"input": "321\n212",
"output": "132"
},
{
"input": "109823464\n901234467",
"output": "896443210"
},
{
"input": "6543\n6542",
"output": "6534"
},
{
"input": "555441\n555100",
"output": "554541"
},
{
"input": "472389479\n327489423",
"output": "327487994"
},
{
"input": "45645643756464352\n53465475637456247",
"output": "53465475636654442"
},
{
"input": "254\n599",
"output": "542"
},
{
"input": "5232222345652321\n5000000000000000",
"output": "4655533322222221"
},
{
"input": "201\n200",
"output": "120"
},
{
"input": "14362799391220361\n45160821596433661",
"output": "43999766332221110"
},
{
"input": "3453\n5304",
"output": "4533"
},
{
"input": "989\n998",
"output": "998"
},
{
"input": "5200000000234\n5200000000311",
"output": "5200000000243"
},
{
"input": "5555132\n1325442",
"output": "1255553"
},
{
"input": "123\n211",
"output": "132"
},
{
"input": "65689\n66123",
"output": "65986"
},
{
"input": "123451234567890\n123456789012345",
"output": "123456789012345"
},
{
"input": "22115\n22015",
"output": "21521"
},
{
"input": "123\n311",
"output": "231"
},
{
"input": "12222\n21111",
"output": "12222"
},
{
"input": "765\n567",
"output": "567"
},
{
"input": "9087645\n9087640",
"output": "9087564"
},
{
"input": "1111111122222333\n2220000000000000",
"output": "2213332221111111"
},
{
"input": "7901\n7108",
"output": "7091"
},
{
"input": "215489\n215488",
"output": "214985"
},
{
"input": "102\n200",
"output": "120"
},
{
"input": "19260817\n20011213",
"output": "19876210"
},
{
"input": "12345\n53200",
"output": "53142"
},
{
"input": "1040003001\n1040003000",
"output": "1040001300"
},
{
"input": "295\n924",
"output": "592"
},
{
"input": "20000000000000001\n20000000000000000",
"output": "12000000000000000"
},
{
"input": "99988877\n99887766",
"output": "99879887"
},
{
"input": "12\n12",
"output": "12"
},
{
"input": "199999999999999999\n900000000000000000",
"output": "199999999999999999"
},
{
"input": "1234\n4310",
"output": "4231"
},
{
"input": "100011\n100100",
"output": "100011"
},
{
"input": "328899\n328811",
"output": "299883"
},
{
"input": "646722972346\n397619201220",
"output": "397476664222"
},
{
"input": "1203\n1200",
"output": "1032"
},
{
"input": "1\n2",
"output": "1"
},
{
"input": "1112\n2110",
"output": "1211"
},
{
"input": "4545\n5540",
"output": "5454"
},
{
"input": "3053\n5004",
"output": "3530"
},
{
"input": "3503\n5004",
"output": "3530"
},
{
"input": "351731653766064847\n501550303749042658",
"output": "501548777666643331"
},
{
"input": "10123456789013451\n26666666666666666",
"output": "26598754433111100"
},
{
"input": "1110111\n1100000",
"output": "1011111"
},
{
"input": "30478\n32265",
"output": "30874"
},
{
"input": "456546546549874615\n441554543131214545",
"output": "441554498766665554"
},
{
"input": "214\n213",
"output": "142"
},
{
"input": "415335582799619283\n133117803602859310",
"output": "132999887655543321"
},
{
"input": "787\n887",
"output": "877"
},
{
"input": "3333222288889999\n3333222288881111",
"output": "3332999988883222"
},
{
"input": "495779862481416791\n836241745208800994",
"output": "829998777665444111"
},
{
"input": "139\n193",
"output": "193"
},
{
"input": "9568\n6500",
"output": "5986"
},
{
"input": "3208899\n3228811",
"output": "3209988"
},
{
"input": "27778\n28710",
"output": "27877"
},
{
"input": "62345\n46415",
"output": "46352"
},
{
"input": "405739873179209\n596793907108871",
"output": "594998777332100"
},
{
"input": "365\n690",
"output": "653"
},
{
"input": "8388731334391\n4710766672578",
"output": "4398887333311"
},
{
"input": "1230\n1200",
"output": "1032"
},
{
"input": "1025\n5000",
"output": "2510"
},
{
"input": "4207799\n4027711",
"output": "2997740"
},
{
"input": "4444222277779999\n4444222277771111",
"output": "4442999977774222"
},
{
"input": "7430\n3047",
"output": "3047"
},
{
"input": "649675735\n540577056",
"output": "539776654"
},
{
"input": "26\n82",
"output": "62"
},
{
"input": "241285\n207420",
"output": "185422"
},
{
"input": "3\n3",
"output": "3"
},
{
"input": "12\n21",
"output": "21"
},
{
"input": "481287\n826607",
"output": "824871"
},
{
"input": "40572351\n59676984",
"output": "57543210"
},
{
"input": "268135787269\n561193454469",
"output": "539887766221"
},
{
"input": "4\n9",
"output": "4"
},
{
"input": "5\n6",
"output": "5"
},
{
"input": "60579839\n33370073",
"output": "30998765"
},
{
"input": "49939\n39200",
"output": "34999"
},
{
"input": "2224\n4220",
"output": "2422"
},
{
"input": "427799\n427711",
"output": "299774"
},
{
"input": "49\n90",
"output": "49"
},
{
"input": "93875\n82210",
"output": "79853"
},
{
"input": "78831\n7319682",
"output": "88731"
},
{
"input": "937177\n7143444",
"output": "977731"
},
{
"input": "499380628\n391990337",
"output": "390988642"
},
{
"input": "2090909\n2900000",
"output": "2099900"
},
{
"input": "112233445566778890\n987654321987654320",
"output": "987654321876543210"
},
{
"input": "48257086\n80903384",
"output": "80876542"
},
{
"input": "112233445566778890\n900654321987654320",
"output": "898776655443322110"
},
{
"input": "112233445566778890\n123456789123456788",
"output": "123456789123456780"
},
{
"input": "5207799\n5027711",
"output": "2997750"
},
{
"input": "200000000000000001\n200000000000000000",
"output": "120000000000000000"
},
{
"input": "597402457\n797455420",
"output": "797455420"
},
{
"input": "90\n94",
"output": "90"
},
{
"input": "86888\n88683",
"output": "86888"
},
{
"input": "419155888\n588151913",
"output": "588151894"
},
{
"input": "408919130\n191830070",
"output": "191830049"
},
{
"input": "524975\n554924",
"output": "554792"
},
{
"input": "53029\n30524",
"output": "30295"
},
{
"input": "5549\n5542",
"output": "5495"
},
{
"input": "6\n9",
"output": "6"
},
{
"input": "87\n810",
"output": "87"
},
{
"input": "920491855\n281495062",
"output": "281495059"
},
{
"input": "6691\n6910",
"output": "6691"
},
{
"input": "533\n335",
"output": "335"
},
{
"input": "999999999999999998\n999999999999999997",
"output": "999999999999999989"
},
{
"input": "21111111111111111\n21111111111111110",
"output": "12111111111111111"
},
{
"input": "2\n12",
"output": "2"
},
{
"input": "76544\n45744",
"output": "45674"
},
{
"input": "2000000000000001\n2000000000000000",
"output": "1200000000000000"
},
{
"input": "740867\n467701",
"output": "467087"
},
{
"input": "2\n6",
"output": "2"
},
{
"input": "103\n130",
"output": "130"
},
{
"input": "2423712\n8466235",
"output": "7432221"
},
{
"input": "84\n48",
"output": "48"
},
{
"input": "1210\n12113",
"output": "2110"
},
{
"input": "2430\n20786",
"output": "4320"
},
{
"input": "100\n999",
"output": "100"
},
{
"input": "19325\n21903",
"output": "21593"
},
{
"input": "1969\n23251",
"output": "9961"
}
] | 1,629,816,682 | 2,147,483,647 | PyPy 3 | OK | TESTS | 157 | 124 | 21,708,800 | a = list(input())
b = list(input())
n = len(a)
a.sort()
def listtostring(string):
return ''.join([str(ele) for ele in string])
for i in range(0,n):
for j in range(0,n):
t = a.copy()
t[i],t[j] = t[j],t[i]
if((int(listtostring(t)) >= int(listtostring(a))) and (int(listtostring(t))<= int(listtostring(b)))):
# print("BEFORE",a,a[i],a[j],i,j)
a[i],a[j] = a[j],a[i]
# print("AFTER",a,a[i],a[j],i,j)
print(listtostring(a)) | Title: Permute Digits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two positive integer numbers *a* and *b*. Permute (change order) of the digits of *a* to construct maximal number not exceeding *b*. No number in input and/or output can start with the digit 0.
It is allowed to leave *a* as it is.
Input Specification:
The first line contains integer *a* (1<=≤<=*a*<=≤<=1018). The second line contains integer *b* (1<=≤<=*b*<=≤<=1018). Numbers don't have leading zeroes. It is guaranteed that answer exists.
Output Specification:
Print the maximum possible number that is a permutation of digits of *a* and is not greater than *b*. The answer can't have any leading zeroes. It is guaranteed that the answer exists.
The number in the output should have exactly the same length as number *a*. It should be a permutation of digits of *a*.
Demo Input:
['123\n222\n', '3921\n10000\n', '4940\n5000\n']
Demo Output:
['213\n', '9321\n', '4940\n']
Note:
none | ```python
a = list(input())
b = list(input())
n = len(a)
a.sort()
def listtostring(string):
return ''.join([str(ele) for ele in string])
for i in range(0,n):
for j in range(0,n):
t = a.copy()
t[i],t[j] = t[j],t[i]
if((int(listtostring(t)) >= int(listtostring(a))) and (int(listtostring(t))<= int(listtostring(b)))):
# print("BEFORE",a,a[i],a[j],i,j)
a[i],a[j] = a[j],a[i]
# print("AFTER",a,a[i],a[j],i,j)
print(listtostring(a))
``` | 3 |
|
61 | A | Ultra-Fast Mathematician | PROGRAMMING | 800 | [
"implementation"
] | A. Ultra-Fast Mathematician | 2 | 256 | Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part.
In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0.
Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length.
Now you are going to take part in Shapur's contest. See if you are faster and more accurate. | There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. | Write one line — the corresponding answer. Do not omit the leading 0s. | [
"1010100\n0100101\n",
"000\n111\n",
"1110\n1010\n",
"01110\n01100\n"
] | [
"1110001\n",
"111\n",
"0100\n",
"00010\n"
] | none | 500 | [
{
"input": "1010100\n0100101",
"output": "1110001"
},
{
"input": "000\n111",
"output": "111"
},
{
"input": "1110\n1010",
"output": "0100"
},
{
"input": "01110\n01100",
"output": "00010"
},
{
"input": "011101\n000001",
"output": "011100"
},
{
"input": "10\n01",
"output": "11"
},
{
"input": "00111111\n11011101",
"output": "11100010"
},
{
"input": "011001100\n101001010",
"output": "110000110"
},
{
"input": "1100100001\n0110101100",
"output": "1010001101"
},
{
"input": "00011101010\n10010100101",
"output": "10001001111"
},
{
"input": "100000101101\n111010100011",
"output": "011010001110"
},
{
"input": "1000001111010\n1101100110001",
"output": "0101101001011"
},
{
"input": "01011111010111\n10001110111010",
"output": "11010001101101"
},
{
"input": "110010000111100\n001100101011010",
"output": "111110101100110"
},
{
"input": "0010010111110000\n0000000011010110",
"output": "0010010100100110"
},
{
"input": "00111110111110000\n01111100001100000",
"output": "01000010110010000"
},
{
"input": "101010101111010001\n001001111101111101",
"output": "100011010010101100"
},
{
"input": "0110010101111100000\n0011000101000000110",
"output": "0101010000111100110"
},
{
"input": "11110100011101010111\n00001000011011000000",
"output": "11111100000110010111"
},
{
"input": "101010101111101101001\n111010010010000011111",
"output": "010000111101101110110"
},
{
"input": "0000111111100011000010\n1110110110110000001010",
"output": "1110001001010011001000"
},
{
"input": "10010010101000110111000\n00101110100110111000111",
"output": "10111100001110001111111"
},
{
"input": "010010010010111100000111\n100100111111100011001110",
"output": "110110101101011111001001"
},
{
"input": "0101110100100111011010010\n0101100011010111001010001",
"output": "0000010111110000010000011"
},
{
"input": "10010010100011110111111011\n10000110101100000001000100",
"output": "00010100001111110110111111"
},
{
"input": "000001111000000100001000000\n011100111101111001110110001",
"output": "011101000101111101111110001"
},
{
"input": "0011110010001001011001011100\n0000101101000011101011001010",
"output": "0011011111001010110010010110"
},
{
"input": "11111000000000010011001101111\n11101110011001010100010000000",
"output": "00010110011001000111011101111"
},
{
"input": "011001110000110100001100101100\n001010000011110000001000101001",
"output": "010011110011000100000100000101"
},
{
"input": "1011111010001100011010110101111\n1011001110010000000101100010101",
"output": "0000110100011100011111010111010"
},
{
"input": "10111000100001000001010110000001\n10111000001100101011011001011000",
"output": "00000000101101101010001111011001"
},
{
"input": "000001010000100001000000011011100\n111111111001010100100001100000111",
"output": "111110101001110101100001111011011"
},
{
"input": "1101000000000010011011101100000110\n1110000001100010011010000011011110",
"output": "0011000001100000000001101111011000"
},
{
"input": "01011011000010100001100100011110001\n01011010111000001010010100001110000",
"output": "00000001111010101011110000010000001"
},
{
"input": "000011111000011001000110111100000100\n011011000110000111101011100111000111",
"output": "011000111110011110101101011011000011"
},
{
"input": "1001000010101110001000000011111110010\n0010001011010111000011101001010110000",
"output": "1011001001111001001011101010101000010"
},
{
"input": "00011101011001100101111111000000010101\n10010011011011001011111000000011101011",
"output": "10001110000010101110000111000011111110"
},
{
"input": "111011100110001001101111110010111001010\n111111101101111001110010000101101000100",
"output": "000100001011110000011101110111010001110"
},
{
"input": "1111001001101000001000000010010101001010\n0010111100111110001011000010111110111001",
"output": "1101110101010110000011000000101011110011"
},
{
"input": "00100101111000000101011111110010100011010\n11101110001010010101001000111110101010100",
"output": "11001011110010010000010111001100001001110"
},
{
"input": "101011001110110100101001000111010101101111\n100111100110101011010100111100111111010110",
"output": "001100101000011111111101111011101010111001"
},
{
"input": "1111100001100101000111101001001010011100001\n1000110011000011110010001011001110001000001",
"output": "0111010010100110110101100010000100010100000"
},
{
"input": "01100111011111010101000001101110000001110101\n10011001011111110000000101011001001101101100",
"output": "11111110000000100101000100110111001100011001"
},
{
"input": "110010100111000100100101100000011100000011001\n011001111011100110000110111001110110100111011",
"output": "101011011100100010100011011001101010100100010"
},
{
"input": "0001100111111011010110100100111000000111000110\n1100101011000000000001010010010111001100110001",
"output": "1101001100111011010111110110101111001011110111"
},
{
"input": "00000101110110110001110010100001110100000100000\n10010000110011110001101000111111101010011010001",
"output": "10010101000101000000011010011110011110011110001"
},
{
"input": "110000100101011100100011001111110011111110010001\n101011111001011100110110111101110011010110101100",
"output": "011011011100000000010101110010000000101000111101"
},
{
"input": "0101111101011111010101011101000011101100000000111\n0000101010110110001110101011011110111001010100100",
"output": "0101010111101001011011110110011101010101010100011"
},
{
"input": "11000100010101110011101000011111001010110111111100\n00001111000111001011111110000010101110111001000011",
"output": "11001011010010111000010110011101100100001110111111"
},
{
"input": "101000001101111101101111111000001110110010101101010\n010011100111100001100000010001100101000000111011011",
"output": "111011101010011100001111101001101011110010010110001"
},
{
"input": "0011111110010001010100010110111000110011001101010100\n0111000000100010101010000100101000000100101000111001",
"output": "0100111110110011111110010010010000110111100101101101"
},
{
"input": "11101010000110000011011010000001111101000111011111100\n10110011110001010100010110010010101001010111100100100",
"output": "01011001110111010111001100010011010100010000111011000"
},
{
"input": "011000100001000001101000010110100110011110100111111011\n111011001000001001110011001111011110111110110011011111",
"output": "100011101001001000011011011001111000100000010100100100"
},
{
"input": "0111010110010100000110111011010110100000000111110110000\n1011100100010001101100000100111111101001110010000100110",
"output": "1100110010000101101010111111101001001001110101110010110"
},
{
"input": "10101000100111000111010001011011011011110100110101100011\n11101111000000001100100011111000100100000110011001101110",
"output": "01000111100111001011110010100011111111110010101100001101"
},
{
"input": "000000111001010001000000110001001011100010011101010011011\n110001101000010010000101000100001111101001100100001010010",
"output": "110001010001000011000101110101000100001011111001011001001"
},
{
"input": "0101011100111010000111110010101101111111000000111100011100\n1011111110000010101110111001000011100000100111111111000111",
"output": "1110100010111000101001001011101110011111100111000011011011"
},
{
"input": "11001000001100100111100111100100101011000101001111001001101\n10111110100010000011010100110100100011101001100000001110110",
"output": "01110110101110100100110011010000001000101100101111000111011"
},
{
"input": "010111011011101000000110000110100110001110100001110110111011\n101011110011101011101101011111010100100001100111100100111011",
"output": "111100101000000011101011011001110010101111000110010010000000"
},
{
"input": "1001011110110110000100011001010110000100011010010111010101110\n1101111100001000010111110011010101111010010100000001000010111",
"output": "0100100010111110010011101010000011111110001110010110010111001"
},
{
"input": "10000010101111100111110101111000010100110111101101111111111010\n10110110101100101010011001011010100110111011101100011001100111",
"output": "00110100000011001101101100100010110010001100000001100110011101"
},
{
"input": "011111010011111000001010101001101001000010100010111110010100001\n011111001011000011111001000001111001010110001010111101000010011",
"output": "000000011000111011110011101000010000010100101000000011010110010"
},
{
"input": "1111000000110001011101000100100100001111011100001111001100011111\n1101100110000101100001100000001001011011111011010101000101001010",
"output": "0010100110110100111100100100101101010100100111011010001001010101"
},
{
"input": "01100000101010010011001110100110110010000110010011011001100100011\n10110110010110111100100111000111000110010000000101101110000010111",
"output": "11010110111100101111101001100001110100010110010110110111100110100"
},
{
"input": "001111111010000100001100001010011001111110011110010111110001100111\n110000101001011000100010101100100110000111100000001101001110010111",
"output": "111111010011011100101110100110111111111001111110011010111111110000"
},
{
"input": "1011101011101101011110101101011101011000010011100101010101000100110\n0001000001001111010111100100111101100000000001110001000110000000110",
"output": "1010101010100010001001001001100000111000010010010100010011000100000"
},
{
"input": "01000001011001010011011100010000100100110101111011011011110000001110\n01011110000110011011000000000011000111100001010000000011111001110000",
"output": "00011111011111001000011100010011100011010100101011011000001001111110"
},
{
"input": "110101010100110101000001111110110100010010000100111110010100110011100\n111010010111111011100110101011001011001110110111110100000110110100111",
"output": "001111000011001110100111010101111111011100110011001010010010000111011"
},
{
"input": "1001101011000001011111100110010010000011010001001111011100010100110001\n1111100111110101001111010001010000011001001001010110001111000000100101",
"output": "0110001100110100010000110111000010011010011000011001010011010100010100"
},
{
"input": "00000111110010110001110110001010010101000111011001111111100110011110010\n00010111110100000100110101000010010001100001100011100000001100010100010",
"output": "00010000000110110101000011001000000100100110111010011111101010001010000"
},
{
"input": "100101011100101101000011010001011001101110101110001100010001010111001110\n100001111100101011011111110000001111000111001011111110000010101110111001",
"output": "000100100000000110011100100001010110101001100101110010010011111001110111"
},
{
"input": "1101100001000111001101001011101000111000011110000001001101101001111011010\n0101011101010100011011010110101000010010110010011110101100000110110001000",
"output": "1000111100010011010110011101000000101010101100011111100001101111001010010"
},
{
"input": "01101101010011110101100001110101111011100010000010001101111000011110111111\n00101111001101001100111010000101110000100101101111100111101110010100011011",
"output": "01000010011110111001011011110000001011000111101101101010010110001010100100"
},
{
"input": "101100101100011001101111110110110010100110110010100001110010110011001101011\n000001011010101011110011111101001110000111000010001101000010010000010001101",
"output": "101101110110110010011100001011111100100001110000101100110000100011011100110"
},
{
"input": "0010001011001010001100000010010011110110011000100000000100110000101111001110\n1100110100111000110100001110111001011101001100001010100001010011100110110001",
"output": "1110111111110010111000001100101010101011010100101010100101100011001001111111"
},
{
"input": "00101101010000000101011001101011001100010001100000101011101110000001111001000\n10010110010111000000101101000011101011001010000011011101101011010000000011111",
"output": "10111011000111000101110100101000100111011011100011110110000101010001111010111"
},
{
"input": "111100000100100000101001100001001111001010001000001000000111010000010101101011\n001000100010100101111011111011010110101100001111011000010011011011100010010110",
"output": "110100100110000101010010011010011001100110000111010000010100001011110111111101"
},
{
"input": "0110001101100100001111110101101000100101010010101010011001101001001101110000000\n0111011000000010010111011110010000000001000110001000011001101000000001110100111",
"output": "0001010101100110011000101011111000100100010100100010000000000001001100000100111"
},
{
"input": "10001111111001000101001011110101111010100001011010101100111001010001010010001000\n10000111010010011110111000111010101100000011110001101111001000111010100000000001",
"output": "00001000101011011011110011001111010110100010101011000011110001101011110010001001"
},
{
"input": "100110001110110000100101001110000011110110000110000000100011110100110110011001101\n110001110101110000000100101001101011111100100100001001000110000001111100011110110",
"output": "010111111011000000100001100111101000001010100010001001100101110101001010000111011"
},
{
"input": "0000010100100000010110111100011111111010011101000000100000011001001101101100111010\n0100111110011101010110101011110110010111001111000110101100101110111100101000111111",
"output": "0100101010111101000000010111101001101101010010000110001100110111110001000100000101"
},
{
"input": "11000111001010100001110000001001011010010010110000001110100101000001010101100110111\n11001100100100100001101010110100000111100011101110011010110100001001000011011011010",
"output": "00001011101110000000011010111101011101110001011110010100010001001000010110111101101"
},
{
"input": "010110100010001000100010101001101010011010111110100001000100101000111011100010100001\n110000011111101101010011111000101010111010100001001100001001100101000000111000000000",
"output": "100110111101100101110001010001000000100000011111101101001101001101111011011010100001"
},
{
"input": "0000011110101110010101110110110101100001011001101010101001000010000010000000101001101\n1100111111011100000110000111101110011111100111110001011001000010011111100001001100011",
"output": "1100100001110010010011110001011011111110111110011011110000000000011101100001100101110"
},
{
"input": "10100000101101110001100010010010100101100011010010101000110011100000101010110010000000\n10001110011011010010111011011101101111000111110000111000011010010101001100000001010011",
"output": "00101110110110100011011001001111001010100100100010010000101001110101100110110011010011"
},
{
"input": "001110000011111101101010011111000101010111010100001001100001001100101000000111000000000\n111010000000000000101001110011001000111011001100101010011001000011101001001011110000011",
"output": "110100000011111101000011101100001101101100011000100011111000001111000001001100110000011"
},
{
"input": "1110111100111011010101011011001110001010010010110011110010011111000010011111010101100001\n1001010101011001001010100010101100000110111101011000100010101111111010111100001110010010",
"output": "0111101001100010011111111001100010001100101111101011010000110000111000100011011011110011"
},
{
"input": "11100010001100010011001100001100010011010001101110011110100101110010101101011101000111111\n01110000000110111010110100001010000101011110100101010011000110101110101101110111011110001",
"output": "10010010001010101001111000000110010110001111001011001101100011011100000000101010011001110"
},
{
"input": "001101011001100101101100110000111000101011001001100100000100101000100000110100010111111101\n101001111110000010111101111110001001111001111101111010000110111000100100110010010001011111",
"output": "100100100111100111010001001110110001010010110100011110000010010000000100000110000110100010"
},
{
"input": "1010110110010101000110010010110101011101010100011001101011000110000000100011100100011000000\n0011011111100010001111101101000111001011101110100000110111100100101111010110101111011100011",
"output": "1001101001110111001001111111110010010110111010111001011100100010101111110101001011000100011"
},
{
"input": "10010010000111010111011111110010100101100000001100011100111011100010000010010001011100001100\n00111010100010110010000100010111010001111110100100100011101000101111111111001101101100100100",
"output": "10101000100101100101011011100101110100011110101000111111010011001101111101011100110000101000"
},
{
"input": "010101110001010101100000010111010000000111110011001101100011001000000011001111110000000010100\n010010111011100101010101111110110000000111000100001101101001001000001100101110001010000100001",
"output": "000111001010110000110101101001100000000000110111000000001010000000001111100001111010000110101"
},
{
"input": "1100111110011001000111101001001011000110011010111111100010111111001100111111011101100111101011\n1100000011001000110100110111000001011001010111101000010010100011000001100100111101101000010110",
"output": "0000111101010001110011011110001010011111001101010111110000011100001101011011100000001111111101"
},
{
"input": "00011000100100110111100101100100000000010011110111110010101110110011100001010111010011110100101\n00011011111011111011100101100111100101001110010111000010000111000100100100000001110101111011011",
"output": "00000011011111001100000000000011100101011101100000110000101001110111000101010110100110001111110"
},
{
"input": "000101011001001100000111100010110101111011110101111101000110001101011010111110110011100100000001\n011000101010011111011000111000100000000011011000000001111110001000001111101010110000011100001111",
"output": "011101110011010011011111011010010101111000101101111100111000000101010101010100000011111000001110"
},
{
"input": "1000101001011010000100100100010010011101011001110101111011101111111110010101001101010001010101001\n0110110010011100011111011111110111000000010001110100001010111110101011010011111011111110000110000",
"output": "1110011011000110011011111011100101011101001000000001110001010001010101000110110110101111010011001"
},
{
"input": "01111010010101100111110111111011011010100001011101010000111100101101101110111011001100101011100111\n00001100110110100001111011000010001001001100000010111101000001111011100000010111010010000011000010",
"output": "01110110100011000110001100111001010011101101011111101101111101010110001110101100011110101000100101"
},
{
"input": "111101011101111000001011001101111010110111001101110100100011111011011101001101010101011010111000110\n101111100101101101001100110011000001111010011101110111110110101110011011110011111100001001110101101",
"output": "010010111000010101000111111110111011001101010000000011010101010101000110111110101001010011001101011"
},
{
"input": "1010000011010110011101001101110001110010000111011101110010110110111111001001110100101100010101010001\n0111101000111100101100000101111010100100001000011101010100110011100011010011010101000100101011100011",
"output": "1101101011101010110001001000001011010110001111000000100110000101011100011010100001101000111110110010"
},
{
"input": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001\n1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111010",
"output": "1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111011"
},
{
"input": "0\n0",
"output": "0"
},
{
"input": "0\n1",
"output": "1"
}
] | 1,500,646,677 | 2,147,483,647 | Python 3 | OK | TESTS | 102 | 62 | 4,608,000 | num=[[i for i in input()] for j in range(2)]
n1=list(num[0][:])
n2=list(num[1][:])
ans=[]
for i in range(len(n1)):
if n1[i]!=n2[i]:
ans.append("1")
else:
ans.append("0")
print("".join(ans))
| Title: Ultra-Fast Mathematician
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part.
In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0.
Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length.
Now you are going to take part in Shapur's contest. See if you are faster and more accurate.
Input Specification:
There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100.
Output Specification:
Write one line — the corresponding answer. Do not omit the leading 0s.
Demo Input:
['1010100\n0100101\n', '000\n111\n', '1110\n1010\n', '01110\n01100\n']
Demo Output:
['1110001\n', '111\n', '0100\n', '00010\n']
Note:
none | ```python
num=[[i for i in input()] for j in range(2)]
n1=list(num[0][:])
n2=list(num[1][:])
ans=[]
for i in range(len(n1)):
if n1[i]!=n2[i]:
ans.append("1")
else:
ans.append("0")
print("".join(ans))
``` | 3.975917 |
510 | A | Fox And Snake | PROGRAMMING | 800 | [
"implementation"
] | null | null | Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead.
A snake is a pattern on a *n* by *m* table. Denote *c*-th cell of *r*-th row as (*r*,<=*c*). The tail of the snake is located at (1,<=1), then it's body extends to (1,<=*m*), then goes down 2 rows to (3,<=*m*), then goes left to (3,<=1) and so on.
Your task is to draw this snake for Fox Ciel: the empty cells should be represented as dot characters ('.') and the snake cells should be filled with number signs ('#').
Consider sample tests in order to understand the snake pattern. | The only line contains two integers: *n* and *m* (3<=≤<=*n*,<=*m*<=≤<=50).
*n* is an odd number. | Output *n* lines. Each line should contain a string consisting of *m* characters. Do not output spaces. | [
"3 3\n",
"3 4\n",
"5 3\n",
"9 9\n"
] | [
"###\n..#\n###\n",
"####\n...#\n####\n",
"###\n..#\n###\n#..\n###\n",
"#########\n........#\n#########\n#........\n#########\n........#\n#########\n#........\n#########\n"
] | none | 500 | [
{
"input": "3 3",
"output": "###\n..#\n###"
},
{
"input": "3 4",
"output": "####\n...#\n####"
},
{
"input": "5 3",
"output": "###\n..#\n###\n#..\n###"
},
{
"input": "9 9",
"output": "#########\n........#\n#########\n#........\n#########\n........#\n#########\n#........\n#########"
},
{
"input": "3 5",
"output": "#####\n....#\n#####"
},
{
"input": "3 6",
"output": "######\n.....#\n######"
},
{
"input": "7 3",
"output": "###\n..#\n###\n#..\n###\n..#\n###"
},
{
"input": "7 4",
"output": "####\n...#\n####\n#...\n####\n...#\n####"
},
{
"input": "49 50",
"output": "##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.............................................."
},
{
"input": "43 50",
"output": "##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.............................................."
},
{
"input": "43 27",
"output": "###########################\n..........................#\n###########################\n#..........................\n###########################\n..........................#\n###########################\n#..........................\n###########################\n..........................#\n###########################\n#..........................\n###########################\n..........................#\n###########################\n#..........................\n###########################\n....................."
},
{
"input": "11 15",
"output": "###############\n..............#\n###############\n#..............\n###############\n..............#\n###############\n#..............\n###############\n..............#\n###############"
},
{
"input": "11 3",
"output": "###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###"
},
{
"input": "19 3",
"output": "###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###"
},
{
"input": "23 50",
"output": "##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.............................................."
},
{
"input": "49 49",
"output": "#################################################\n................................................#\n#################################################\n#................................................\n#################################################\n................................................#\n#################################################\n#................................................\n#################################################\n................................................#\n#..."
},
{
"input": "33 43",
"output": "###########################################\n..........................................#\n###########################################\n#..........................................\n###########################################\n..........................................#\n###########################################\n#..........................................\n###########################################\n..........................................#\n###########################################\n#.................."
},
{
"input": "33 44",
"output": "############################################\n...........................................#\n############################################\n#...........................................\n############################################\n...........................................#\n############################################\n#...........................................\n############################################\n...........................................#\n############################################\n#......."
},
{
"input": "45 45",
"output": "#############################################\n............................................#\n#############################################\n#............................................\n#############################################\n............................................#\n#############################################\n#............................................\n#############################################\n............................................#\n#########################################..."
},
{
"input": "45 49",
"output": "#################################################\n................................................#\n#################################################\n#................................................\n#################################################\n................................................#\n#################################################\n#................................................\n#################################################\n................................................#\n#..."
},
{
"input": "45 3",
"output": "###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###"
},
{
"input": "45 4",
"output": "####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####"
},
{
"input": "5 4",
"output": "####\n...#\n####\n#...\n####"
},
{
"input": "5 5",
"output": "#####\n....#\n#####\n#....\n#####"
},
{
"input": "5 6",
"output": "######\n.....#\n######\n#.....\n######"
},
{
"input": "7 5",
"output": "#####\n....#\n#####\n#....\n#####\n....#\n#####"
},
{
"input": "7 6",
"output": "######\n.....#\n######\n#.....\n######\n.....#\n######"
},
{
"input": "7 7",
"output": "#######\n......#\n#######\n#......\n#######\n......#\n#######"
}
] | 1,675,835,992 | 2,147,483,647 | Python 3 | OK | TESTS | 28 | 46 | 0 | nums = [int(i) for i in input().split()]
n,m = nums[0], nums[1]
pos = True #True means right
for i in range(n):
if i%2 == 0:
for i in range(m):
print("#", end="")
else:
if pos == True:
for i in range(m-1):
print(".",end="")
print("#",end="")
else:
print("#",end="")
for i in range(m-1):
print(".",end="")
pos = ~ pos
print() | Title: Fox And Snake
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead.
A snake is a pattern on a *n* by *m* table. Denote *c*-th cell of *r*-th row as (*r*,<=*c*). The tail of the snake is located at (1,<=1), then it's body extends to (1,<=*m*), then goes down 2 rows to (3,<=*m*), then goes left to (3,<=1) and so on.
Your task is to draw this snake for Fox Ciel: the empty cells should be represented as dot characters ('.') and the snake cells should be filled with number signs ('#').
Consider sample tests in order to understand the snake pattern.
Input Specification:
The only line contains two integers: *n* and *m* (3<=≤<=*n*,<=*m*<=≤<=50).
*n* is an odd number.
Output Specification:
Output *n* lines. Each line should contain a string consisting of *m* characters. Do not output spaces.
Demo Input:
['3 3\n', '3 4\n', '5 3\n', '9 9\n']
Demo Output:
['###\n..#\n###\n', '####\n...#\n####\n', '###\n..#\n###\n#..\n###\n', '#########\n........#\n#########\n#........\n#########\n........#\n#########\n#........\n#########\n']
Note:
none | ```python
nums = [int(i) for i in input().split()]
n,m = nums[0], nums[1]
pos = True #True means right
for i in range(n):
if i%2 == 0:
for i in range(m):
print("#", end="")
else:
if pos == True:
for i in range(m-1):
print(".",end="")
print("#",end="")
else:
print("#",end="")
for i in range(m-1):
print(".",end="")
pos = ~ pos
print()
``` | 3 |
|
284 | A | Cows and Primitive Roots | PROGRAMMING | 1,400 | [
"implementation",
"math",
"number theory"
] | null | null | The cows have just learned what a primitive root is! Given a prime *p*, a primitive root is an integer *x* (1<=≤<=*x*<=<<=*p*) such that none of integers *x*<=-<=1,<=*x*2<=-<=1,<=...,<=*x**p*<=-<=2<=-<=1 are divisible by *p*, but *x**p*<=-<=1<=-<=1 is.
Unfortunately, computing primitive roots can be time consuming, so the cows need your help. Given a prime *p*, help the cows find the number of primitive roots . | The input contains a single line containing an integer *p* (2<=≤<=*p*<=<<=2000). It is guaranteed that *p* is a prime. | Output on a single line the number of primitive roots . | [
"3\n",
"5\n"
] | [
"1\n",
"2\n"
] | The only primitive root <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/3722298ba062e95b18705d1253eb4e5d31e3b2d1.png" style="max-width: 100.0%;max-height: 100.0%;"/> is 2.
The primitive roots <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/1d85c6a17ef1c42b53cf94d00bc49a7ac458fd58.png" style="max-width: 100.0%;max-height: 100.0%;"/> are 2 and 3. | 500 | [
{
"input": "3",
"output": "1"
},
{
"input": "5",
"output": "2"
},
{
"input": "7",
"output": "2"
},
{
"input": "11",
"output": "4"
},
{
"input": "17",
"output": "8"
},
{
"input": "19",
"output": "6"
},
{
"input": "1583",
"output": "672"
},
{
"input": "997",
"output": "328"
},
{
"input": "2",
"output": "1"
},
{
"input": "1987",
"output": "660"
},
{
"input": "1993",
"output": "656"
},
{
"input": "1997",
"output": "996"
},
{
"input": "1999",
"output": "648"
},
{
"input": "1297",
"output": "432"
},
{
"input": "163",
"output": "54"
},
{
"input": "1259",
"output": "576"
},
{
"input": "821",
"output": "320"
},
{
"input": "29",
"output": "12"
},
{
"input": "43",
"output": "12"
},
{
"input": "1949",
"output": "972"
},
{
"input": "1879",
"output": "624"
},
{
"input": "1759",
"output": "584"
},
{
"input": "1597",
"output": "432"
},
{
"input": "1619",
"output": "808"
},
{
"input": "1277",
"output": "560"
},
{
"input": "1097",
"output": "544"
},
{
"input": "953",
"output": "384"
},
{
"input": "751",
"output": "200"
},
{
"input": "607",
"output": "200"
},
{
"input": "509",
"output": "252"
},
{
"input": "431",
"output": "168"
},
{
"input": "317",
"output": "156"
},
{
"input": "211",
"output": "48"
},
{
"input": "127",
"output": "36"
},
{
"input": "101",
"output": "40"
},
{
"input": "31",
"output": "8"
}
] | 1,580,306,353 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 8 | 1,558 | 0 | p = int(input())
k = 0
for i in range(2,p):
flag = 0
cur = 1
j = 1
while j < p - 1:
j = j + 1
cur = (cur * i) % p
if cur == 1:
flag = 1
break
cur = (cur * i) % p
if cur != 1:
flag = 1
if flag == 0:
k = k + 1
print(k) | Title: Cows and Primitive Roots
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The cows have just learned what a primitive root is! Given a prime *p*, a primitive root is an integer *x* (1<=≤<=*x*<=<<=*p*) such that none of integers *x*<=-<=1,<=*x*2<=-<=1,<=...,<=*x**p*<=-<=2<=-<=1 are divisible by *p*, but *x**p*<=-<=1<=-<=1 is.
Unfortunately, computing primitive roots can be time consuming, so the cows need your help. Given a prime *p*, help the cows find the number of primitive roots .
Input Specification:
The input contains a single line containing an integer *p* (2<=≤<=*p*<=<<=2000). It is guaranteed that *p* is a prime.
Output Specification:
Output on a single line the number of primitive roots .
Demo Input:
['3\n', '5\n']
Demo Output:
['1\n', '2\n']
Note:
The only primitive root <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/3722298ba062e95b18705d1253eb4e5d31e3b2d1.png" style="max-width: 100.0%;max-height: 100.0%;"/> is 2.
The primitive roots <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/1d85c6a17ef1c42b53cf94d00bc49a7ac458fd58.png" style="max-width: 100.0%;max-height: 100.0%;"/> are 2 and 3. | ```python
p = int(input())
k = 0
for i in range(2,p):
flag = 0
cur = 1
j = 1
while j < p - 1:
j = j + 1
cur = (cur * i) % p
if cur == 1:
flag = 1
break
cur = (cur * i) % p
if cur != 1:
flag = 1
if flag == 0:
k = k + 1
print(k)
``` | 0 |
|
637 | B | Chat Order | PROGRAMMING | 1,200 | [
"*special",
"binary search",
"constructive algorithms",
"data structures",
"sortings"
] | null | null | Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The relative order of the other chats doesn't change. If there was no chat with this friend before, then a new chat is simply inserted to the top of the list.
Assuming that the chat list is initially empty, given the sequence of Polycaprus' messages make a list of chats after all of his messages are processed. Assume that no friend wrote any message to Polycarpus. | The first line contains integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of Polycarpus' messages. Next *n* lines enlist the message recipients in the order in which the messages were sent. The name of each participant is a non-empty sequence of lowercase English letters of length at most 10. | Print all the recipients to who Polycarp talked to in the order of chats with them, from top to bottom. | [
"4\nalex\nivan\nroman\nivan\n",
"8\nalina\nmaria\nekaterina\ndarya\ndarya\nekaterina\nmaria\nalina\n"
] | [
"ivan\nroman\nalex\n",
"alina\nmaria\nekaterina\ndarya\n"
] | In the first test case Polycarpus first writes to friend by name "alex", and the list looks as follows:
1. alex
Then Polycarpus writes to friend by name "ivan" and the list looks as follows:
1. ivan 1. alex
Polycarpus writes the third message to friend by name "roman" and the list looks as follows:
1. roman 1. ivan 1. alex
Polycarpus writes the fourth message to friend by name "ivan", to who he has already sent a message, so the list of chats changes as follows:
1. ivan 1. roman 1. alex | 1,000 | [
{
"input": "4\nalex\nivan\nroman\nivan",
"output": "ivan\nroman\nalex"
},
{
"input": "8\nalina\nmaria\nekaterina\ndarya\ndarya\nekaterina\nmaria\nalina",
"output": "alina\nmaria\nekaterina\ndarya"
},
{
"input": "1\nwdi",
"output": "wdi"
},
{
"input": "2\nypg\nypg",
"output": "ypg"
},
{
"input": "3\nexhll\nexhll\narruapexj",
"output": "arruapexj\nexhll"
},
{
"input": "3\nfv\nle\nle",
"output": "le\nfv"
},
{
"input": "8\nm\nm\nm\nm\nm\nm\nm\nm",
"output": "m"
},
{
"input": "10\nr\nr\ni\nw\nk\nr\nb\nu\nu\nr",
"output": "r\nu\nb\nk\nw\ni"
},
{
"input": "7\ne\nfau\ncmk\nnzs\nby\nwx\ntjmok",
"output": "tjmok\nwx\nby\nnzs\ncmk\nfau\ne"
},
{
"input": "6\nklrj\nwe\nklrj\nwe\nwe\nwe",
"output": "we\nklrj"
},
{
"input": "8\nzncybqmh\naeebef\nzncybqmh\nn\naeebef\nzncybqmh\nzncybqmh\nzncybqmh",
"output": "zncybqmh\naeebef\nn"
},
{
"input": "30\nkqqcbs\nvap\nkymomn\nj\nkqqcbs\nfuzlzoum\nkymomn\ndbh\nfuzlzoum\nkymomn\nvap\nvlgzs\ndbh\nvlgzs\nbvy\ndbh\nkymomn\nkymomn\neoqql\nkymomn\nkymomn\nkqqcbs\nvlgzs\nkqqcbs\nkqqcbs\nfuzlzoum\nvlgzs\nrylgdoo\nvlgzs\nrylgdoo",
"output": "rylgdoo\nvlgzs\nfuzlzoum\nkqqcbs\nkymomn\neoqql\ndbh\nbvy\nvap\nj"
},
{
"input": "40\nji\nv\nv\nns\nji\nn\nji\nv\nfvy\nvje\nns\nvje\nv\nhas\nv\nusm\nhas\nfvy\nvje\nkdb\nn\nv\nji\nji\nn\nhas\nv\nji\nkdb\nr\nvje\nns\nv\nusm\nn\nvje\nhas\nns\nhas\nn",
"output": "n\nhas\nns\nvje\nusm\nv\nr\nkdb\nji\nfvy"
},
{
"input": "50\njcg\nvle\njopb\nepdb\nnkef\nfv\nxj\nufe\nfuy\noqta\ngbc\nyuz\nec\nyji\nkuux\ncwm\ntq\nnno\nhp\nzry\nxxpp\ntjvo\ngyz\nkwo\nvwqz\nyaqc\njnj\nwoav\nqcv\ndcu\ngc\nhovn\nop\nevy\ndc\ntrpu\nyb\nuzfa\npca\noq\nnhxy\nsiqu\nde\nhphy\nc\nwovu\nf\nbvv\ndsik\nlwyg",
"output": "lwyg\ndsik\nbvv\nf\nwovu\nc\nhphy\nde\nsiqu\nnhxy\noq\npca\nuzfa\nyb\ntrpu\ndc\nevy\nop\nhovn\ngc\ndcu\nqcv\nwoav\njnj\nyaqc\nvwqz\nkwo\ngyz\ntjvo\nxxpp\nzry\nhp\nnno\ntq\ncwm\nkuux\nyji\nec\nyuz\ngbc\noqta\nfuy\nufe\nxj\nfv\nnkef\nepdb\njopb\nvle\njcg"
},
{
"input": "100\nvhh\nvhh\nvhh\nfa\nfa\nvhh\nvhh\nvhh\nfa\nfa\nfa\nvhh\nfa\nvhh\nvhh\nvhh\nfa\nvhh\nvhh\nfa\nfa\nfa\nfa\nfa\nfa\nvhh\nfa\nfa\nvhh\nvhh\nvhh\nfa\nfa\nfa\nvhh\nfa\nvhh\nfa\nvhh\nvhh\nfa\nvhh\nfa\nvhh\nvhh\nvhh\nfa\nvhh\nfa\nfa\nvhh\nfa\nvhh\nvhh\nvhh\nvhh\nfa\nvhh\nvhh\nvhh\nvhh\nfa\nvhh\nvhh\nvhh\nvhh\nvhh\nfa\nvhh\nvhh\nfa\nfa\nfa\nvhh\nfa\nfa\nvhh\nfa\nvhh\nfa\nfa\nfa\nfa\nfa\nfa\nvhh\nvhh\nfa\nvhh\nfa\nfa\nvhh\nfa\nfa\nvhh\nfa\nvhh\nvhh\nfa\nvhh",
"output": "vhh\nfa"
},
{
"input": "2\naa\nbb",
"output": "bb\naa"
},
{
"input": "2\naa\na",
"output": "a\naa"
},
{
"input": "3\naa\naa\naa",
"output": "aa"
},
{
"input": "5\naa\na\naa\na\naa",
"output": "aa\na"
},
{
"input": "7\naaaa\naaaa\naaa\na\naa\naaaaaaa\naaa",
"output": "aaa\naaaaaaa\naa\na\naaaa"
},
{
"input": "5\na\naa\naaa\naaaa\na",
"output": "a\naaaa\naaa\naa"
},
{
"input": "12\naaaaa\naaaaaa\naaaa\naaaaaa\naa\naaaa\naaaa\naaaaaa\na\naaa\naaaaaaaa\naa",
"output": "aa\naaaaaaaa\naaa\na\naaaaaa\naaaa\naaaaa"
},
{
"input": "3\na\naa\naaa",
"output": "aaa\naa\na"
},
{
"input": "9\nzzz\nzzzzz\nzzz\nzzzz\nzz\nzzzz\nzzzzz\nzzzz\nzzzzzzz",
"output": "zzzzzzz\nzzzz\nzzzzz\nzz\nzzz"
}
] | 1,609,257,833 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 12 | 3,000 | 6,963,200 | n = int(input())
order=[]
for i in range(n):
name=input()
if name in order:
order.remove(name)
order.append(name)
for i in range(len(order)-1, -1, -1):
print(order[i])
| Title: Chat Order
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The relative order of the other chats doesn't change. If there was no chat with this friend before, then a new chat is simply inserted to the top of the list.
Assuming that the chat list is initially empty, given the sequence of Polycaprus' messages make a list of chats after all of his messages are processed. Assume that no friend wrote any message to Polycarpus.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of Polycarpus' messages. Next *n* lines enlist the message recipients in the order in which the messages were sent. The name of each participant is a non-empty sequence of lowercase English letters of length at most 10.
Output Specification:
Print all the recipients to who Polycarp talked to in the order of chats with them, from top to bottom.
Demo Input:
['4\nalex\nivan\nroman\nivan\n', '8\nalina\nmaria\nekaterina\ndarya\ndarya\nekaterina\nmaria\nalina\n']
Demo Output:
['ivan\nroman\nalex\n', 'alina\nmaria\nekaterina\ndarya\n']
Note:
In the first test case Polycarpus first writes to friend by name "alex", and the list looks as follows:
1. alex
Then Polycarpus writes to friend by name "ivan" and the list looks as follows:
1. ivan 1. alex
Polycarpus writes the third message to friend by name "roman" and the list looks as follows:
1. roman 1. ivan 1. alex
Polycarpus writes the fourth message to friend by name "ivan", to who he has already sent a message, so the list of chats changes as follows:
1. ivan 1. roman 1. alex | ```python
n = int(input())
order=[]
for i in range(n):
name=input()
if name in order:
order.remove(name)
order.append(name)
for i in range(len(order)-1, -1, -1):
print(order[i])
``` | 0 |
|
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,664,286,962 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | def inv(a):
if b[a]==0:
b[a]=1
elif b[a]==1:
b[a]=0
b=[]
for i in range(0,3):
a=list(map(int,input().split()))
for j in a:
b.append(j)
print(b)
for i in range (0,9):
if i==0:
if(b[i]==0 or b[i]==1):inv(0),inv(1),inv(3)
else:
for i in range(0,b[i]):inv(0),inv(1),inv(3)
elif i==1:
if(b[i]==0 or b[i]==1):inv(0),inv(2),inv(4),inv(1)
else:
for i in range(0,b[i]):inv(0),inv(2),inv(4),inv(1)
elif i==2:
if(b[i]==0 or b[i]==1):inv(5),inv(1),inv(2)
else:
for i in range(0,b[i]):inv(5),inv(1),inv(2)
elif i==3:
if(b[i]==0 or b[i]==1):inv(0),inv(6),inv(4),inv(3)
else:
for i in range(0,b[i]):inv(0),inv(6),inv(4),inv(3)
elif i==4:
if(b[i]==0 or b[i]==1):inv(1),inv(3),inv(5),inv(7),inv(4)
else:
for i in range(0,b[i]):inv(1),inv(3),inv(5),inv(7),inv(4)
elif i==5:
if(b[i]==0 or b[i]==1):inv(2),inv(4),inv(8),inv(5)
else:
for i in range(0,b[i]):inv(2),inv(4),inv(8),inv(5)
elif i==6:
if(b[i]==0 or b[i]==1):inv(3),inv(6),inv(7)
else:
for i in range(0,b[i]):inv(3),inv(6),inv(7)
elif i==7:
if(b[i]==0 or b[i]==1):inv(4),inv(6),inv(7),inv(8)
else:
for i in range(0,b[i]):inv(4),inv(6),inv(7),inv(8)
elif i==8:
if(b[i]==0 or b[i]==1):inv(8),inv(7),inv(5)
else:
for i in range(0,b[i]):inv(8),inv(7),inv(5)
print(b[0],end=''),print(b[1],end=''),print(b[2])
print(b[3],end=''),print(b[4],end=''),print(b[5])
print(b[6],end=''),print(b[7],end=''),print(b[8])
| 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
def inv(a):
if b[a]==0:
b[a]=1
elif b[a]==1:
b[a]=0
b=[]
for i in range(0,3):
a=list(map(int,input().split()))
for j in a:
b.append(j)
print(b)
for i in range (0,9):
if i==0:
if(b[i]==0 or b[i]==1):inv(0),inv(1),inv(3)
else:
for i in range(0,b[i]):inv(0),inv(1),inv(3)
elif i==1:
if(b[i]==0 or b[i]==1):inv(0),inv(2),inv(4),inv(1)
else:
for i in range(0,b[i]):inv(0),inv(2),inv(4),inv(1)
elif i==2:
if(b[i]==0 or b[i]==1):inv(5),inv(1),inv(2)
else:
for i in range(0,b[i]):inv(5),inv(1),inv(2)
elif i==3:
if(b[i]==0 or b[i]==1):inv(0),inv(6),inv(4),inv(3)
else:
for i in range(0,b[i]):inv(0),inv(6),inv(4),inv(3)
elif i==4:
if(b[i]==0 or b[i]==1):inv(1),inv(3),inv(5),inv(7),inv(4)
else:
for i in range(0,b[i]):inv(1),inv(3),inv(5),inv(7),inv(4)
elif i==5:
if(b[i]==0 or b[i]==1):inv(2),inv(4),inv(8),inv(5)
else:
for i in range(0,b[i]):inv(2),inv(4),inv(8),inv(5)
elif i==6:
if(b[i]==0 or b[i]==1):inv(3),inv(6),inv(7)
else:
for i in range(0,b[i]):inv(3),inv(6),inv(7)
elif i==7:
if(b[i]==0 or b[i]==1):inv(4),inv(6),inv(7),inv(8)
else:
for i in range(0,b[i]):inv(4),inv(6),inv(7),inv(8)
elif i==8:
if(b[i]==0 or b[i]==1):inv(8),inv(7),inv(5)
else:
for i in range(0,b[i]):inv(8),inv(7),inv(5)
print(b[0],end=''),print(b[1],end=''),print(b[2])
print(b[3],end=''),print(b[4],end=''),print(b[5])
print(b[6],end=''),print(b[7],end=''),print(b[8])
``` | 0 |
|
339 | A | Helpful Maths | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings",
"strings"
] | null | null | Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation.
The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To make the calculation easier, the sum only contains numbers 1, 2 and 3. Still, that isn't enough for Xenia. She is only beginning to count, so she can calculate a sum only if the summands follow in non-decreasing order. For example, she can't calculate sum 1+3+2+1 but she can calculate sums 1+1+2 and 3+3.
You've got the sum that was written on the board. Rearrange the summans and print the sum in such a way that Xenia can calculate the sum. | The first line contains a non-empty string *s* — the sum Xenia needs to count. String *s* contains no spaces. It only contains digits and characters "+". Besides, string *s* is a correct sum of numbers 1, 2 and 3. String *s* is at most 100 characters long. | Print the new sum that Xenia can count. | [
"3+2+1\n",
"1+1+3+1+3\n",
"2\n"
] | [
"1+2+3\n",
"1+1+1+3+3\n",
"2\n"
] | none | 500 | [
{
"input": "3+2+1",
"output": "1+2+3"
},
{
"input": "1+1+3+1+3",
"output": "1+1+1+3+3"
},
{
"input": "2",
"output": "2"
},
{
"input": "2+2+1+1+3",
"output": "1+1+2+2+3"
},
{
"input": "2+1+2+2+2+3+1+3+1+2",
"output": "1+1+1+2+2+2+2+2+3+3"
},
{
"input": "1+2+1+2+2+2+2+1+3+3",
"output": "1+1+1+2+2+2+2+2+3+3"
},
{
"input": "2+3+3+1+2+2+2+1+1+2+1+3+2+2+3+3+2+2+3+3+3+1+1+1+3+3+3+2+1+3+2+3+2+1+1+3+3+3+1+2+2+1+2+2+1+2+1+3+1+1",
"output": "1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3"
},
{
"input": "1",
"output": "1"
},
{
"input": "2+1+2+2+1+3+2+3+1+1+2+1+2+2+3+1+1+3+3+3+2+2+3+2+2+2+1+2+1+2+3+2+2+2+1+3+1+3+3+3+1+2+1+2+2+2+2+3+1+1",
"output": "1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+3+3+3+3+3+3+3+3+3+3+3+3+3"
},
{
"input": "2+2+1+1+1+3+1+1+3+3+2+3+1+3+1+1+3+1+1+2+2+2+2+1+2+1+2+1+1+1+3+1+3+2+3+2+3+3+1+1+1+2+3+2+1+3+1+3+2+2",
"output": "1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+3+3+3+3+3+3+3+3+3+3+3+3+3+3"
},
{
"input": "3+2+3+3+2+2+1+2+1+2+3+1+2+3+2+3+2+1+2+2+1+1+2+2+3+2+1+3+1+1+3+2+2+2+2+3+3+2+2+3+3+1+1+2+3+3+2+3+3+3",
"output": "1+1+1+1+1+1+1+1+1+1+1+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3"
},
{
"input": "3",
"output": "3"
},
{
"input": "1+1",
"output": "1+1"
},
{
"input": "1+2",
"output": "1+2"
},
{
"input": "1+3",
"output": "1+3"
},
{
"input": "2+1",
"output": "1+2"
},
{
"input": "2+2",
"output": "2+2"
},
{
"input": "2+3",
"output": "2+3"
},
{
"input": "3+1",
"output": "1+3"
},
{
"input": "3+2",
"output": "2+3"
},
{
"input": "3+3",
"output": "3+3"
}
] | 1,696,212,604 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 21 | 124 | 0 | #removes plus signs then orders numbers in ascending order
numbers = input().split('+')
numbers.sort()
#adds each number with a plus sign, then ticks up until the last number is printed without the sign.
summation = " "
tick = 0
for number in numbers:
if tick == (len(numbers)-1):
summation += f'{number}'
tick += 1
else:
summation += f'{number}+'
tick += 1
#prints final output
print(summation) | Title: Helpful Maths
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation.
The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To make the calculation easier, the sum only contains numbers 1, 2 and 3. Still, that isn't enough for Xenia. She is only beginning to count, so she can calculate a sum only if the summands follow in non-decreasing order. For example, she can't calculate sum 1+3+2+1 but she can calculate sums 1+1+2 and 3+3.
You've got the sum that was written on the board. Rearrange the summans and print the sum in such a way that Xenia can calculate the sum.
Input Specification:
The first line contains a non-empty string *s* — the sum Xenia needs to count. String *s* contains no spaces. It only contains digits and characters "+". Besides, string *s* is a correct sum of numbers 1, 2 and 3. String *s* is at most 100 characters long.
Output Specification:
Print the new sum that Xenia can count.
Demo Input:
['3+2+1\n', '1+1+3+1+3\n', '2\n']
Demo Output:
['1+2+3\n', '1+1+1+3+3\n', '2\n']
Note:
none | ```python
#removes plus signs then orders numbers in ascending order
numbers = input().split('+')
numbers.sort()
#adds each number with a plus sign, then ticks up until the last number is printed without the sign.
summation = " "
tick = 0
for number in numbers:
if tick == (len(numbers)-1):
summation += f'{number}'
tick += 1
else:
summation += f'{number}+'
tick += 1
#prints final output
print(summation)
``` | 3 |
|
350 | A | TL | PROGRAMMING | 1,200 | [
"brute force",
"greedy",
"implementation"
] | null | null | Valera wanted to prepare a Codesecrof round. He's already got one problem and he wants to set a time limit (TL) on it.
Valera has written *n* correct solutions. For each correct solution, he knows its running time (in seconds). Valera has also wrote *m* wrong solutions and for each wrong solution he knows its running time (in seconds).
Let's suppose that Valera will set *v* seconds TL in the problem. Then we can say that a solution passes the system testing if its running time is at most *v* seconds. We can also say that a solution passes the system testing with some "extra" time if for its running time, *a* seconds, an inequality 2*a*<=≤<=*v* holds.
As a result, Valera decided to set *v* seconds TL, that the following conditions are met:
1. *v* is a positive integer; 1. all correct solutions pass the system testing; 1. at least one correct solution passes the system testing with some "extra" time; 1. all wrong solutions do not pass the system testing; 1. value *v* is minimum among all TLs, for which points 1, 2, 3, 4 hold.
Help Valera and find the most suitable TL or else state that such TL doesn't exist. | The first line contains two integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100). The second line contains *n* space-separated positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) — the running time of each of the *n* correct solutions in seconds. The third line contains *m* space-separated positive integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=100) — the running time of each of *m* wrong solutions in seconds. | If there is a valid TL value, print it. Otherwise, print -1. | [
"3 6\n4 5 2\n8 9 6 10 7 11\n",
"3 1\n3 4 5\n6\n"
] | [
"5",
"-1\n"
] | none | 500 | [
{
"input": "3 6\n4 5 2\n8 9 6 10 7 11",
"output": "5"
},
{
"input": "3 1\n3 4 5\n6",
"output": "-1"
},
{
"input": "2 5\n45 99\n49 41 77 83 45",
"output": "-1"
},
{
"input": "50 50\n18 13 5 34 10 36 36 12 15 11 16 17 14 36 23 45 32 24 31 18 24 32 7 1 31 3 49 8 16 23 3 39 47 43 42 38 40 22 41 1 49 47 9 8 19 15 29 30 16 18\n91 58 86 51 94 94 73 84 98 69 74 56 52 80 88 61 53 99 88 50 55 95 65 84 87 79 51 52 69 60 74 73 93 61 73 59 64 56 95 78 86 72 79 70 93 78 54 61 71 50",
"output": "49"
},
{
"input": "55 44\n93 17 74 15 34 16 41 80 26 54 94 94 86 93 20 44 63 72 39 43 67 4 37 49 76 94 5 51 64 74 11 47 77 97 57 30 42 72 71 26 8 14 67 64 49 57 30 23 40 4 76 78 87 78 79\n38 55 17 65 26 7 36 65 48 28 49 93 18 98 31 90 26 57 1 26 88 56 48 56 23 13 8 67 80 2 51 3 21 33 20 54 2 45 21 36 3 98 62 2",
"output": "-1"
},
{
"input": "32 100\n30 8 4 35 18 41 18 12 33 39 39 18 39 19 33 46 45 33 34 27 14 39 40 21 38 9 42 35 27 10 14 14\n65 49 89 64 47 78 59 52 73 51 84 82 88 63 91 99 67 87 53 99 75 47 85 82 58 47 80 50 65 91 83 90 77 52 100 88 97 74 98 99 50 93 65 61 65 65 65 96 61 51 84 67 79 90 92 83 100 100 100 95 80 54 77 51 98 64 74 62 60 96 73 74 94 55 89 60 92 65 74 79 66 81 53 47 71 51 54 85 74 97 68 72 88 94 100 85 65 63 65 90",
"output": "46"
},
{
"input": "1 50\n7\n65 52 99 78 71 19 96 72 80 15 50 94 20 35 79 95 44 41 45 53 77 50 74 66 59 96 26 84 27 48 56 84 36 78 89 81 67 34 79 74 99 47 93 92 90 96 72 28 78 66",
"output": "14"
},
{
"input": "1 1\n4\n9",
"output": "8"
},
{
"input": "1 1\n2\n4",
"output": "-1"
},
{
"input": "22 56\n49 20 42 68 15 46 98 78 82 8 7 33 50 30 75 96 36 88 35 99 19 87\n15 18 81 24 35 89 25 32 23 3 48 24 52 69 18 32 23 61 48 98 50 38 5 17 70 20 38 32 49 54 68 11 51 81 46 22 19 59 29 38 45 83 18 13 91 17 84 62 25 60 97 32 23 13 83 58",
"output": "-1"
},
{
"input": "1 1\n50\n100",
"output": "-1"
},
{
"input": "1 1\n49\n100",
"output": "98"
},
{
"input": "1 1\n100\n100",
"output": "-1"
},
{
"input": "1 1\n99\n100",
"output": "-1"
},
{
"input": "8 4\n1 2 49 99 99 95 78 98\n100 100 100 100",
"output": "99"
},
{
"input": "68 85\n43 55 2 4 72 45 19 56 53 81 18 90 11 87 47 8 94 88 24 4 67 9 21 70 25 66 65 27 46 13 8 51 65 99 37 43 71 59 71 79 32 56 49 43 57 85 95 81 40 28 60 36 72 81 60 40 16 78 61 37 29 26 15 95 70 27 50 97\n6 6 48 72 54 31 1 50 29 64 93 9 29 93 66 63 25 90 52 1 66 13 70 30 24 87 32 90 84 72 44 13 25 45 31 16 92 60 87 40 62 7 20 63 86 78 73 88 5 36 74 100 64 34 9 5 62 29 58 48 81 46 84 56 27 1 60 14 54 88 31 93 62 7 9 69 27 48 10 5 33 10 53 66 2",
"output": "-1"
},
{
"input": "5 100\n1 1 1 1 1\n77 53 38 29 97 33 64 17 78 100 27 12 42 44 20 24 44 68 58 57 65 90 8 24 4 6 74 68 61 43 25 69 8 62 36 85 67 48 69 30 35 41 42 12 87 66 50 92 53 76 38 67 85 7 80 78 53 76 94 8 37 50 4 100 4 71 10 48 34 47 83 42 25 81 64 72 25 51 53 75 43 98 53 77 94 38 81 15 89 91 72 76 7 36 27 41 88 18 19 75",
"output": "2"
},
{
"input": "3 3\n2 3 4\n8 9 10",
"output": "4"
},
{
"input": "2 1\n2 3\n15",
"output": "4"
},
{
"input": "2 1\n2 4\n4",
"output": "-1"
},
{
"input": "2 3\n4 5\n10 11 12",
"output": "8"
},
{
"input": "3 1\n2 3 3\n5",
"output": "4"
},
{
"input": "2 1\n9 10\n100",
"output": "18"
},
{
"input": "3 3\n3 12 15\n7 8 9",
"output": "-1"
},
{
"input": "2 2\n3 5\n7 8",
"output": "6"
},
{
"input": "3 3\n4 5 6\n10 11 12",
"output": "8"
},
{
"input": "3 5\n2 3 3\n6 6 6 6 2",
"output": "-1"
},
{
"input": "3 6\n4 5 3\n8 9 7 10 7 11",
"output": "6"
},
{
"input": "3 6\n4 5 2\n8 9 6 10 7 4",
"output": "-1"
},
{
"input": "2 1\n4 6\n10",
"output": "8"
},
{
"input": "1 2\n1\n3 1",
"output": "-1"
},
{
"input": "2 1\n5 6\n20",
"output": "10"
},
{
"input": "2 1\n1 5\n5",
"output": "-1"
},
{
"input": "3 2\n10 20 30\n30 40",
"output": "-1"
},
{
"input": "2 2\n5 6\n7 100",
"output": "-1"
},
{
"input": "2 1\n2 5\n7",
"output": "5"
},
{
"input": "1 1\n5\n20",
"output": "10"
},
{
"input": "2 1\n10 11\n100",
"output": "20"
},
{
"input": "1 1\n1\n10",
"output": "2"
},
{
"input": "1 1\n10\n100",
"output": "20"
}
] | 1,693,825,276 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 92 | 0 | nm=input().split()
n=int(nm[0])
m=int(nm[1])
correct=list(map(int,input().split()))
wrong=list(map(int,input().split()))
point4=True
if 2*min(correct)<max(correct):
TL=max(correct)
else:
TL=2*min(correct)
if min(wrong)<=TL:
point4=False
if point4:
print(TL)
else:
print(-1) | Title: TL
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera wanted to prepare a Codesecrof round. He's already got one problem and he wants to set a time limit (TL) on it.
Valera has written *n* correct solutions. For each correct solution, he knows its running time (in seconds). Valera has also wrote *m* wrong solutions and for each wrong solution he knows its running time (in seconds).
Let's suppose that Valera will set *v* seconds TL in the problem. Then we can say that a solution passes the system testing if its running time is at most *v* seconds. We can also say that a solution passes the system testing with some "extra" time if for its running time, *a* seconds, an inequality 2*a*<=≤<=*v* holds.
As a result, Valera decided to set *v* seconds TL, that the following conditions are met:
1. *v* is a positive integer; 1. all correct solutions pass the system testing; 1. at least one correct solution passes the system testing with some "extra" time; 1. all wrong solutions do not pass the system testing; 1. value *v* is minimum among all TLs, for which points 1, 2, 3, 4 hold.
Help Valera and find the most suitable TL or else state that such TL doesn't exist.
Input Specification:
The first line contains two integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100). The second line contains *n* space-separated positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) — the running time of each of the *n* correct solutions in seconds. The third line contains *m* space-separated positive integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=100) — the running time of each of *m* wrong solutions in seconds.
Output Specification:
If there is a valid TL value, print it. Otherwise, print -1.
Demo Input:
['3 6\n4 5 2\n8 9 6 10 7 11\n', '3 1\n3 4 5\n6\n']
Demo Output:
['5', '-1\n']
Note:
none | ```python
nm=input().split()
n=int(nm[0])
m=int(nm[1])
correct=list(map(int,input().split()))
wrong=list(map(int,input().split()))
point4=True
if 2*min(correct)<max(correct):
TL=max(correct)
else:
TL=2*min(correct)
if min(wrong)<=TL:
point4=False
if point4:
print(TL)
else:
print(-1)
``` | 3 |
|
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,652,072,424 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 31 | 0 | a,b=map(int,input().split(" "))
tot=a
new=int(a/b)
while new>0:
tot+=new
new=int(new/b)
print(tot) | 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
a,b=map(int,input().split(" "))
tot=a
new=int(a/b)
while new>0:
tot+=new
new=int(new/b)
print(tot)
``` | 0 |
|
990 | A | Commentary Boxes | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Berland Football Cup starts really soon! Commentators from all over the world come to the event.
Organizers have already built $n$ commentary boxes. $m$ regional delegations will come to the Cup. Every delegation should get the same number of the commentary boxes. If any box is left unoccupied then the delegations will be upset. So each box should be occupied by exactly one delegation.
If $n$ is not divisible by $m$, it is impossible to distribute the boxes to the delegations at the moment.
Organizers can build a new commentary box paying $a$ burles and demolish a commentary box paying $b$ burles. They can both build and demolish boxes arbitrary number of times (each time paying a corresponding fee). It is allowed to demolish all the existing boxes.
What is the minimal amount of burles organizers should pay to satisfy all the delegations (i.e. to make the number of the boxes be divisible by $m$)? | The only line contains four integer numbers $n$, $m$, $a$ and $b$ ($1 \le n, m \le 10^{12}$, $1 \le a, b \le 100$), where $n$ is the initial number of the commentary boxes, $m$ is the number of delegations to come, $a$ is the fee to build a box and $b$ is the fee to demolish a box. | Output the minimal amount of burles organizers should pay to satisfy all the delegations (i.e. to make the number of the boxes be divisible by $m$). It is allowed that the final number of the boxes is equal to $0$. | [
"9 7 3 8\n",
"2 7 3 7\n",
"30 6 17 19\n"
] | [
"15\n",
"14\n",
"0\n"
] | In the first example organizers can build $5$ boxes to make the total of $14$ paying $3$ burles for the each of them.
In the second example organizers can demolish $2$ boxes to make the total of $0$ paying $7$ burles for the each of them.
In the third example organizers are already able to distribute all the boxes equally among the delegations, each one get $5$ boxes. | 0 | [
{
"input": "9 7 3 8",
"output": "15"
},
{
"input": "2 7 3 7",
"output": "14"
},
{
"input": "30 6 17 19",
"output": "0"
},
{
"input": "500000000001 1000000000000 100 100",
"output": "49999999999900"
},
{
"input": "1000000000000 750000000001 10 100",
"output": "5000000000020"
},
{
"input": "1000000000000 750000000001 100 10",
"output": "2499999999990"
},
{
"input": "42 1 1 1",
"output": "0"
},
{
"input": "1 1000000000000 1 100",
"output": "100"
},
{
"input": "7 2 3 7",
"output": "3"
},
{
"input": "999999999 2 1 1",
"output": "1"
},
{
"input": "999999999999 10000000007 100 100",
"output": "70100"
},
{
"input": "10000000001 2 1 1",
"output": "1"
},
{
"input": "29 6 1 2",
"output": "1"
},
{
"input": "99999999999 6 100 100",
"output": "300"
},
{
"input": "1000000000000 7 3 8",
"output": "8"
},
{
"input": "99999999999 2 1 1",
"output": "1"
},
{
"input": "1 2 1 1",
"output": "1"
},
{
"input": "999999999999 2 1 1",
"output": "1"
},
{
"input": "9 2 1 1",
"output": "1"
},
{
"input": "17 4 5 5",
"output": "5"
},
{
"input": "100000000000 3 1 1",
"output": "1"
},
{
"input": "100 7 1 1",
"output": "2"
},
{
"input": "1000000000000 3 100 100",
"output": "100"
},
{
"input": "70 3 10 10",
"output": "10"
},
{
"input": "1 2 5 1",
"output": "1"
},
{
"input": "1000000000000 3 1 1",
"output": "1"
},
{
"input": "804289377 846930887 78 16",
"output": "3326037780"
},
{
"input": "1000000000000 9 55 55",
"output": "55"
},
{
"input": "957747787 424238336 87 93",
"output": "10162213695"
},
{
"input": "25 6 1 2",
"output": "2"
},
{
"input": "22 7 3 8",
"output": "8"
},
{
"input": "10000000000 1 1 1",
"output": "0"
},
{
"input": "999999999999 2 10 10",
"output": "10"
},
{
"input": "999999999999 2 100 100",
"output": "100"
},
{
"input": "100 3 3 8",
"output": "6"
},
{
"input": "99999 2 1 1",
"output": "1"
},
{
"input": "100 3 2 5",
"output": "4"
},
{
"input": "1000000000000 13 10 17",
"output": "17"
},
{
"input": "7 2 1 2",
"output": "1"
},
{
"input": "10 3 1 2",
"output": "2"
},
{
"input": "5 2 2 2",
"output": "2"
},
{
"input": "100 3 5 2",
"output": "2"
},
{
"input": "7 2 1 1",
"output": "1"
},
{
"input": "70 4 1 1",
"output": "2"
},
{
"input": "10 4 1 1",
"output": "2"
},
{
"input": "6 7 41 42",
"output": "41"
},
{
"input": "10 3 10 1",
"output": "1"
},
{
"input": "5 5 2 3",
"output": "0"
},
{
"input": "1000000000000 3 99 99",
"output": "99"
},
{
"input": "7 3 100 1",
"output": "1"
},
{
"input": "7 2 100 5",
"output": "5"
},
{
"input": "1000000000000 1 23 33",
"output": "0"
},
{
"input": "30 7 1 1",
"output": "2"
},
{
"input": "100 3 1 1",
"output": "1"
},
{
"input": "90001 300 100 1",
"output": "1"
},
{
"input": "13 4 1 2",
"output": "2"
},
{
"input": "1000000000000 6 1 3",
"output": "2"
},
{
"input": "50 4 5 100",
"output": "10"
},
{
"input": "999 2 1 1",
"output": "1"
},
{
"input": "5 2 5 5",
"output": "5"
},
{
"input": "20 3 3 3",
"output": "3"
},
{
"input": "3982258181 1589052704 87 20",
"output": "16083055460"
},
{
"input": "100 3 1 3",
"output": "2"
},
{
"input": "7 3 1 1",
"output": "1"
},
{
"input": "19 10 100 100",
"output": "100"
},
{
"input": "23 3 100 1",
"output": "2"
},
{
"input": "25 7 100 1",
"output": "4"
},
{
"input": "100 9 1 2",
"output": "2"
},
{
"input": "9999999999 2 1 100",
"output": "1"
},
{
"input": "1000000000000 2 1 1",
"output": "0"
},
{
"input": "10000 3 1 1",
"output": "1"
},
{
"input": "22 7 1 6",
"output": "6"
},
{
"input": "100000000000 1 1 1",
"output": "0"
},
{
"input": "18 7 100 1",
"output": "4"
},
{
"input": "10003 4 1 100",
"output": "1"
},
{
"input": "3205261341 718648876 58 11",
"output": "3637324207"
},
{
"input": "8 3 100 1",
"output": "2"
},
{
"input": "15 7 1 1",
"output": "1"
},
{
"input": "1000000000000 1 20 20",
"output": "0"
},
{
"input": "16 7 3 2",
"output": "4"
},
{
"input": "1000000000000 1 1 1",
"output": "0"
},
{
"input": "7 3 1 100",
"output": "2"
},
{
"input": "16 3 1 100",
"output": "2"
},
{
"input": "13 4 1 10",
"output": "3"
},
{
"input": "10 4 5 5",
"output": "10"
},
{
"input": "14 3 1 100",
"output": "1"
},
{
"input": "100 33 100 1",
"output": "1"
},
{
"input": "22 7 1 8",
"output": "6"
},
{
"input": "10 4 2 1",
"output": "2"
},
{
"input": "6 4 2 2",
"output": "4"
},
{
"input": "17 4 2 1",
"output": "1"
},
{
"input": "7 3 100 10",
"output": "10"
},
{
"input": "702 7 3 2",
"output": "4"
},
{
"input": "8 3 1 5",
"output": "1"
},
{
"input": "3 2 5 2",
"output": "2"
},
{
"input": "99 19 1 7",
"output": "15"
},
{
"input": "16 3 100 1",
"output": "1"
},
{
"input": "100 34 1 100",
"output": "2"
},
{
"input": "100 33 1 1",
"output": "1"
},
{
"input": "2 3 4 3",
"output": "4"
},
{
"input": "15 4 4 10",
"output": "4"
},
{
"input": "1144108931 470211273 45 79",
"output": "11993619960"
},
{
"input": "2 3 3 4",
"output": "3"
},
{
"input": "29 5 4 9",
"output": "4"
},
{
"input": "15 7 1 5",
"output": "5"
},
{
"input": "1 1 1 1",
"output": "0"
},
{
"input": "1 1 3 4",
"output": "0"
},
{
"input": "10 12 2 1",
"output": "4"
},
{
"input": "1 2 3 4",
"output": "3"
}
] | 1,587,374,415 | 2,147,483,647 | Python 3 | OK | TESTS | 109 | 109 | 0 | n,m,a,b=map(int,input().split())
print(min(n%m*b,(m-n%m)*a))
f=6
g=9
h=g-f
| Title: Commentary Boxes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Berland Football Cup starts really soon! Commentators from all over the world come to the event.
Organizers have already built $n$ commentary boxes. $m$ regional delegations will come to the Cup. Every delegation should get the same number of the commentary boxes. If any box is left unoccupied then the delegations will be upset. So each box should be occupied by exactly one delegation.
If $n$ is not divisible by $m$, it is impossible to distribute the boxes to the delegations at the moment.
Organizers can build a new commentary box paying $a$ burles and demolish a commentary box paying $b$ burles. They can both build and demolish boxes arbitrary number of times (each time paying a corresponding fee). It is allowed to demolish all the existing boxes.
What is the minimal amount of burles organizers should pay to satisfy all the delegations (i.e. to make the number of the boxes be divisible by $m$)?
Input Specification:
The only line contains four integer numbers $n$, $m$, $a$ and $b$ ($1 \le n, m \le 10^{12}$, $1 \le a, b \le 100$), where $n$ is the initial number of the commentary boxes, $m$ is the number of delegations to come, $a$ is the fee to build a box and $b$ is the fee to demolish a box.
Output Specification:
Output the minimal amount of burles organizers should pay to satisfy all the delegations (i.e. to make the number of the boxes be divisible by $m$). It is allowed that the final number of the boxes is equal to $0$.
Demo Input:
['9 7 3 8\n', '2 7 3 7\n', '30 6 17 19\n']
Demo Output:
['15\n', '14\n', '0\n']
Note:
In the first example organizers can build $5$ boxes to make the total of $14$ paying $3$ burles for the each of them.
In the second example organizers can demolish $2$ boxes to make the total of $0$ paying $7$ burles for the each of them.
In the third example organizers are already able to distribute all the boxes equally among the delegations, each one get $5$ boxes. | ```python
n,m,a,b=map(int,input().split())
print(min(n%m*b,(m-n%m)*a))
f=6
g=9
h=g-f
``` | 3 |
|
611 | B | New Year and Old Property | PROGRAMMING | 1,300 | [
"bitmasks",
"brute force",
"implementation"
] | null | null | The year 2015 is almost over.
Limak is a little polar bear. He has recently learnt about the binary system. He noticed that the passing year has exactly one zero in its representation in the binary system — 201510<==<=111110111112. Note that he doesn't care about the number of zeros in the decimal representation.
Limak chose some interval of years. He is going to count all years from this interval that have exactly one zero in the binary representation. Can you do it faster?
Assume that all positive integers are always written without leading zeros. | The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=1018) — the first year and the last year in Limak's interval respectively. | Print one integer – the number of years Limak will count in his chosen interval. | [
"5 10\n",
"2015 2015\n",
"100 105\n",
"72057594000000000 72057595000000000\n"
] | [
"2\n",
"1\n",
"0\n",
"26\n"
] | In the first sample Limak's interval contains numbers 5<sub class="lower-index">10</sub> = 101<sub class="lower-index">2</sub>, 6<sub class="lower-index">10</sub> = 110<sub class="lower-index">2</sub>, 7<sub class="lower-index">10</sub> = 111<sub class="lower-index">2</sub>, 8<sub class="lower-index">10</sub> = 1000<sub class="lower-index">2</sub>, 9<sub class="lower-index">10</sub> = 1001<sub class="lower-index">2</sub> and 10<sub class="lower-index">10</sub> = 1010<sub class="lower-index">2</sub>. Two of them (101<sub class="lower-index">2</sub> and 110<sub class="lower-index">2</sub>) have the described property. | 750 | [
{
"input": "5 10",
"output": "2"
},
{
"input": "2015 2015",
"output": "1"
},
{
"input": "100 105",
"output": "0"
},
{
"input": "72057594000000000 72057595000000000",
"output": "26"
},
{
"input": "1 100",
"output": "16"
},
{
"input": "1000000000000000000 1000000000000000000",
"output": "0"
},
{
"input": "1 1000000000000000000",
"output": "1712"
},
{
"input": "1 1",
"output": "0"
},
{
"input": "1 2",
"output": "1"
},
{
"input": "1 3",
"output": "1"
},
{
"input": "1 4",
"output": "1"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 7",
"output": "3"
},
{
"input": "2 2",
"output": "1"
},
{
"input": "2 3",
"output": "1"
},
{
"input": "2 4",
"output": "1"
},
{
"input": "2 5",
"output": "2"
},
{
"input": "2 6",
"output": "3"
},
{
"input": "2 7",
"output": "3"
},
{
"input": "3 3",
"output": "0"
},
{
"input": "3 4",
"output": "0"
},
{
"input": "3 5",
"output": "1"
},
{
"input": "3 6",
"output": "2"
},
{
"input": "3 7",
"output": "2"
},
{
"input": "4 4",
"output": "0"
},
{
"input": "4 5",
"output": "1"
},
{
"input": "4 6",
"output": "2"
},
{
"input": "4 7",
"output": "2"
},
{
"input": "5 5",
"output": "1"
},
{
"input": "5 6",
"output": "2"
},
{
"input": "5 7",
"output": "2"
},
{
"input": "6 6",
"output": "1"
},
{
"input": "6 7",
"output": "1"
},
{
"input": "7 7",
"output": "0"
},
{
"input": "1 8",
"output": "3"
},
{
"input": "6 8",
"output": "1"
},
{
"input": "7 8",
"output": "0"
},
{
"input": "8 8",
"output": "0"
},
{
"input": "1 1022",
"output": "45"
},
{
"input": "1 1023",
"output": "45"
},
{
"input": "1 1024",
"output": "45"
},
{
"input": "1 1025",
"output": "45"
},
{
"input": "1 1026",
"output": "45"
},
{
"input": "509 1022",
"output": "11"
},
{
"input": "510 1022",
"output": "10"
},
{
"input": "511 1022",
"output": "9"
},
{
"input": "512 1022",
"output": "9"
},
{
"input": "513 1022",
"output": "9"
},
{
"input": "509 1023",
"output": "11"
},
{
"input": "510 1023",
"output": "10"
},
{
"input": "511 1023",
"output": "9"
},
{
"input": "512 1023",
"output": "9"
},
{
"input": "513 1023",
"output": "9"
},
{
"input": "509 1024",
"output": "11"
},
{
"input": "510 1024",
"output": "10"
},
{
"input": "511 1024",
"output": "9"
},
{
"input": "512 1024",
"output": "9"
},
{
"input": "513 1024",
"output": "9"
},
{
"input": "509 1025",
"output": "11"
},
{
"input": "510 1025",
"output": "10"
},
{
"input": "511 1025",
"output": "9"
},
{
"input": "512 1025",
"output": "9"
},
{
"input": "513 1025",
"output": "9"
},
{
"input": "1 1000000000",
"output": "408"
},
{
"input": "10000000000 70000000000000000",
"output": "961"
},
{
"input": "1 935829385028502935",
"output": "1712"
},
{
"input": "500000000000000000 1000000000000000000",
"output": "58"
},
{
"input": "500000000000000000 576460752303423488",
"output": "57"
},
{
"input": "576460752303423488 1000000000000000000",
"output": "1"
},
{
"input": "999999999999999999 1000000000000000000",
"output": "0"
},
{
"input": "1124800395214847 36011204832919551",
"output": "257"
},
{
"input": "1124800395214847 36011204832919550",
"output": "256"
},
{
"input": "1124800395214847 36011204832919552",
"output": "257"
},
{
"input": "1124800395214846 36011204832919551",
"output": "257"
},
{
"input": "1124800395214848 36011204832919551",
"output": "256"
},
{
"input": "1 287104476244869119",
"output": "1603"
},
{
"input": "1 287104476244869118",
"output": "1602"
},
{
"input": "1 287104476244869120",
"output": "1603"
},
{
"input": "492581209243647 1000000000000000000",
"output": "583"
},
{
"input": "492581209243646 1000000000000000000",
"output": "583"
},
{
"input": "492581209243648 1000000000000000000",
"output": "582"
},
{
"input": "1099444518911 1099444518911",
"output": "1"
},
{
"input": "1099444518910 1099444518911",
"output": "1"
},
{
"input": "1099444518911 1099444518912",
"output": "1"
},
{
"input": "1099444518910 1099444518912",
"output": "1"
},
{
"input": "864691128455135231 864691128455135231",
"output": "1"
},
{
"input": "864691128455135231 864691128455135232",
"output": "1"
},
{
"input": "864691128455135230 864691128455135232",
"output": "1"
},
{
"input": "864691128455135230 864691128455135231",
"output": "1"
},
{
"input": "864691128455135231 1000000000000000000",
"output": "1"
},
{
"input": "864691128455135232 1000000000000000000",
"output": "0"
},
{
"input": "864691128455135230 1000000000000000000",
"output": "1"
},
{
"input": "576460752303423487 576460752303423487",
"output": "0"
},
{
"input": "1 576460752303423487",
"output": "1711"
},
{
"input": "1 576460752303423486",
"output": "1711"
},
{
"input": "2 1000000000000000000",
"output": "1712"
},
{
"input": "3 1000000000000000000",
"output": "1711"
},
{
"input": "4 1000000000000000000",
"output": "1711"
},
{
"input": "5 1000000000000000000",
"output": "1711"
},
{
"input": "6 1000000000000000000",
"output": "1710"
},
{
"input": "5 6",
"output": "2"
},
{
"input": "1 2",
"output": "1"
}
] | 1,451,490,268 | 2,368 | Python 3 | OK | TESTS | 103 | 77 | 0 | def clc(n):
ans = 0
ns = "{0:b}".format(n)
for k in range(1,len(ns)): ans += k-1
ns = ns[1:]
while ns:
if ns[0] == '1':
ans += 1
ns = ns[1:]
else:
if ns == '0'+'1'*(len(ns)-1):
ans += 1
break
return ans
a, b = map(int, input().split())
ans = clc(b)
if a > 1: ans -= clc(a-1)
print(ans)
| Title: New Year and Old Property
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The year 2015 is almost over.
Limak is a little polar bear. He has recently learnt about the binary system. He noticed that the passing year has exactly one zero in its representation in the binary system — 201510<==<=111110111112. Note that he doesn't care about the number of zeros in the decimal representation.
Limak chose some interval of years. He is going to count all years from this interval that have exactly one zero in the binary representation. Can you do it faster?
Assume that all positive integers are always written without leading zeros.
Input Specification:
The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=1018) — the first year and the last year in Limak's interval respectively.
Output Specification:
Print one integer – the number of years Limak will count in his chosen interval.
Demo Input:
['5 10\n', '2015 2015\n', '100 105\n', '72057594000000000 72057595000000000\n']
Demo Output:
['2\n', '1\n', '0\n', '26\n']
Note:
In the first sample Limak's interval contains numbers 5<sub class="lower-index">10</sub> = 101<sub class="lower-index">2</sub>, 6<sub class="lower-index">10</sub> = 110<sub class="lower-index">2</sub>, 7<sub class="lower-index">10</sub> = 111<sub class="lower-index">2</sub>, 8<sub class="lower-index">10</sub> = 1000<sub class="lower-index">2</sub>, 9<sub class="lower-index">10</sub> = 1001<sub class="lower-index">2</sub> and 10<sub class="lower-index">10</sub> = 1010<sub class="lower-index">2</sub>. Two of them (101<sub class="lower-index">2</sub> and 110<sub class="lower-index">2</sub>) have the described property. | ```python
def clc(n):
ans = 0
ns = "{0:b}".format(n)
for k in range(1,len(ns)): ans += k-1
ns = ns[1:]
while ns:
if ns[0] == '1':
ans += 1
ns = ns[1:]
else:
if ns == '0'+'1'*(len(ns)-1):
ans += 1
break
return ans
a, b = map(int, input().split())
ans = clc(b)
if a > 1: ans -= clc(a-1)
print(ans)
``` | 3 |
|
279 | B | Books | PROGRAMMING | 1,400 | [
"binary search",
"brute force",
"implementation",
"two pointers"
] | null | null | When Valera has got some free time, he goes to the library to read some books. Today he's got *t* free minutes to read. That's why Valera took *n* books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to *n*. Valera needs *a**i* minutes to read the *i*-th book.
Valera decided to choose an arbitrary book with number *i* and read the books one by one, starting from this book. In other words, he will first read book number *i*, then book number *i*<=+<=1, then book number *i*<=+<=2 and so on. He continues the process until he either runs out of the free time or finishes reading the *n*-th book. Valera reads each book up to the end, that is, he doesn't start reading the book if he doesn't have enough free time to finish reading it.
Print the maximum number of books Valera can read. | The first line contains two integers *n* and *t* (1<=≤<=*n*<=≤<=105; 1<=≤<=*t*<=≤<=109) — the number of books and the number of free minutes Valera's got. The second line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=104), where number *a**i* shows the number of minutes that the boy needs to read the *i*-th book. | Print a single integer — the maximum number of books Valera can read. | [
"4 5\n3 1 2 1\n",
"3 3\n2 2 3\n"
] | [
"3\n",
"1\n"
] | none | 1,000 | [
{
"input": "4 5\n3 1 2 1",
"output": "3"
},
{
"input": "3 3\n2 2 3",
"output": "1"
},
{
"input": "1 3\n5",
"output": "0"
},
{
"input": "1 10\n4",
"output": "1"
},
{
"input": "2 10\n6 4",
"output": "2"
},
{
"input": "6 10\n2 3 4 2 1 1",
"output": "4"
},
{
"input": "7 13\n6 8 14 9 4 11 10",
"output": "2"
},
{
"input": "10 15\n10 9 1 1 5 10 5 3 7 2",
"output": "3"
},
{
"input": "20 30\n8 1 2 6 9 4 1 9 9 10 4 7 8 9 5 7 1 8 7 4",
"output": "6"
},
{
"input": "30 60\n16 13 22 38 13 35 17 17 20 38 12 19 9 22 20 3 35 34 34 21 35 40 22 3 27 19 12 4 8 19",
"output": "4"
},
{
"input": "100 100\n75 92 18 6 81 67 7 92 100 65 82 32 50 67 85 31 80 91 84 63 39 52 92 81 1 98 24 12 43 48 17 86 51 72 48 95 45 50 12 66 19 79 49 89 34 1 97 75 20 33 96 27 42 23 73 71 93 1 85 19 66 14 17 61 20 39 36 33 42 61 56 64 23 91 80 99 40 74 13 18 98 85 74 39 62 84 46 74 50 23 38 11 79 14 9 25 66 100 25 52",
"output": "3"
},
{
"input": "10 1\n4418 7528 8170 1736 1317 3205 8183 4995 8039 4708",
"output": "0"
},
{
"input": "50 2\n124 214 63 73 996 760 38 571 451 300 970 1 706 937 837 494 619 88 851 411 957 990 842 613 821 649 627 34 693 678 734 116 816 985 705 940 499 493 922 967 854 439 112 644 961 438 189 572 655 550",
"output": "1"
}
] | 1,678,950,911 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 38 | 218 | 14,233,600 | from bisect import bisect
"""n, t = map(int, input().split())
arr = list(map(int, input().split()))
pref = [0]
for i in arr:
pref.append(pref[-1]+i)
ans = 0
for i in range(0, n+1):
idx = bisect(pref, t+pref[i]) - 1
ans = max(ans, idx-i)
print(ans)"""
n, x = map(int, input().split())
arr = list(map(int, input().split()))
pref_sum = [0]
for i in arr:
pref_sum.append(pref_sum[-1]+i)
i = 0
j = 0
count = 0
while not(i==n and j == n):
if pref_sum[j] - pref_sum[i] == x:
count = max(count, j-i)
i = min(i+1, n)
elif pref_sum[j] - pref_sum[i] > x:
i = min(i+1, n)
elif pref_sum[j] - pref_sum[i] < x:
count = max(count, j-i)
j = min(j+1, n)
if j == n and pref_sum[j] - pref_sum[i] < x:
count = max(count, j-i)
break
print(count) | Title: Books
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
When Valera has got some free time, he goes to the library to read some books. Today he's got *t* free minutes to read. That's why Valera took *n* books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to *n*. Valera needs *a**i* minutes to read the *i*-th book.
Valera decided to choose an arbitrary book with number *i* and read the books one by one, starting from this book. In other words, he will first read book number *i*, then book number *i*<=+<=1, then book number *i*<=+<=2 and so on. He continues the process until he either runs out of the free time or finishes reading the *n*-th book. Valera reads each book up to the end, that is, he doesn't start reading the book if he doesn't have enough free time to finish reading it.
Print the maximum number of books Valera can read.
Input Specification:
The first line contains two integers *n* and *t* (1<=≤<=*n*<=≤<=105; 1<=≤<=*t*<=≤<=109) — the number of books and the number of free minutes Valera's got. The second line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=104), where number *a**i* shows the number of minutes that the boy needs to read the *i*-th book.
Output Specification:
Print a single integer — the maximum number of books Valera can read.
Demo Input:
['4 5\n3 1 2 1\n', '3 3\n2 2 3\n']
Demo Output:
['3\n', '1\n']
Note:
none | ```python
from bisect import bisect
"""n, t = map(int, input().split())
arr = list(map(int, input().split()))
pref = [0]
for i in arr:
pref.append(pref[-1]+i)
ans = 0
for i in range(0, n+1):
idx = bisect(pref, t+pref[i]) - 1
ans = max(ans, idx-i)
print(ans)"""
n, x = map(int, input().split())
arr = list(map(int, input().split()))
pref_sum = [0]
for i in arr:
pref_sum.append(pref_sum[-1]+i)
i = 0
j = 0
count = 0
while not(i==n and j == n):
if pref_sum[j] - pref_sum[i] == x:
count = max(count, j-i)
i = min(i+1, n)
elif pref_sum[j] - pref_sum[i] > x:
i = min(i+1, n)
elif pref_sum[j] - pref_sum[i] < x:
count = max(count, j-i)
j = min(j+1, n)
if j == n and pref_sum[j] - pref_sum[i] < x:
count = max(count, j-i)
break
print(count)
``` | 3 |
|
914 | A | Perfect Squares | PROGRAMMING | 900 | [
"brute force",
"implementation",
"math"
] | null | null | Given an array *a*1,<=*a*2,<=...,<=*a**n* of *n* integers, find the largest number in the array that is not a perfect square.
A number *x* is said to be a perfect square if there exists an integer *y* such that *x*<==<=*y*2. | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of elements in the array.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=106<=≤<=*a**i*<=≤<=106) — the elements of the array.
It is guaranteed that at least one element of the array is not a perfect square. | Print the largest number in the array which is not a perfect square. It is guaranteed that an answer always exists. | [
"2\n4 2\n",
"8\n1 2 4 8 16 32 64 576\n"
] | [
"2\n",
"32\n"
] | In the first sample case, 4 is a perfect square, so the largest number in the array that is not a perfect square is 2. | 500 | [
{
"input": "2\n4 2",
"output": "2"
},
{
"input": "8\n1 2 4 8 16 32 64 576",
"output": "32"
},
{
"input": "3\n-1 -4 -9",
"output": "-1"
},
{
"input": "5\n918375 169764 598796 76602 538757",
"output": "918375"
},
{
"input": "5\n804610 765625 2916 381050 93025",
"output": "804610"
},
{
"input": "5\n984065 842724 127449 525625 573049",
"output": "984065"
},
{
"input": "2\n226505 477482",
"output": "477482"
},
{
"input": "2\n370881 659345",
"output": "659345"
},
{
"input": "2\n4 5",
"output": "5"
},
{
"input": "2\n3 4",
"output": "3"
},
{
"input": "2\n999999 1000000",
"output": "999999"
},
{
"input": "3\n-1 -2 -3",
"output": "-1"
},
{
"input": "2\n-1000000 1000000",
"output": "-1000000"
},
{
"input": "2\n-1 0",
"output": "-1"
},
{
"input": "1\n2",
"output": "2"
},
{
"input": "1\n-1",
"output": "-1"
},
{
"input": "35\n-871271 -169147 -590893 -400197 -476793 0 -15745 -890852 -124052 -631140 -238569 -597194 -147909 -928925 -587628 -569656 -581425 -963116 -665954 -506797 -196044 -309770 -701921 -926257 -152426 -991371 -624235 -557143 -689886 -59804 -549134 -107407 -182016 -24153 -607462",
"output": "-15745"
},
{
"input": "16\n-882343 -791322 0 -986738 -415891 -823354 -840236 -552554 -760908 -331993 -549078 -863759 -913261 -937429 -257875 -602322",
"output": "-257875"
},
{
"input": "71\n908209 289 44521 240100 680625 274576 212521 91809 506944 499849 3844 15376 592900 58081 240100 984064 732736 257049 600625 180625 130321 580644 261121 75625 46225 853776 485809 700569 817216 268324 293764 528529 25921 399424 175561 99856 295936 20736 611524 13924 470596 574564 5329 15376 676 431649 145161 697225 41616 550564 514089 9409 227529 1681 839056 3721 552049 465124 38809 197136 659344 214369 998001 44944 3844 186624 362404 -766506 739600 10816 299209",
"output": "-766506"
},
{
"input": "30\n192721 -950059 -734656 625 247009 -423468 318096 622521 678976 777924 1444 748303 27556 62001 795664 89401 221841 -483208 467856 477109 196 -461813 831744 772641 574564 -519370 861184 67600 -717966 -259259",
"output": "748303"
},
{
"input": "35\n628849 962361 436921 944784 444889 29241 -514806 171396 685584 -823202 -929730 6982 198025 783225 552049 -957165 782287 -659167 -414846 695556 -336330 41616 963781 71289 119639 952576 -346713 178929 232324 121802 393266 841 649636 179555 998001",
"output": "963781"
},
{
"input": "53\n280988 756430 -515570 -248578 170649 -21608 642677 216770 827291 589500 940901 216097 -118956 -919104 -319264 -761585 289479 499613 588276 883036 480518 -323196 -274570 -406556 -381484 -956025 702135 -445274 -783543 136593 153664 897473 352651 737974 -21123 -284944 501734 898033 604429 624138 40804 248782 -786059 -304592 -209210 -312904 419820 -328648 -47331 -919227 -280955 104827 877304",
"output": "940901"
},
{
"input": "15\n256 -227055 427717 827239 462070 66049 987533 -175306 -552810 -867915 -408251 -693957 -972981 -245827 896904",
"output": "987533"
},
{
"input": "3\n-1 1 0",
"output": "-1"
},
{
"input": "2\n0 -5",
"output": "-5"
},
{
"input": "3\n-1 -2 0",
"output": "-1"
},
{
"input": "2\n-5 0",
"output": "-5"
},
{
"input": "1\n-439",
"output": "-439"
},
{
"input": "1\n-1000000",
"output": "-1000000"
},
{
"input": "1\n-917455",
"output": "-917455"
},
{
"input": "3\n1 1 -1",
"output": "-1"
},
{
"input": "2\n131073 1",
"output": "131073"
},
{
"input": "2\n99999 3",
"output": "99999"
},
{
"input": "2\n-524272 -1000000",
"output": "-524272"
},
{
"input": "2\n15 131073",
"output": "131073"
}
] | 1,591,003,609 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 2 | 93 | 0 | import math
n = input()
n = int(n)
x = [int(x) for x in input().split()]
maximum = 0
for num in x:
if math.sqrt(num).is_integer() == False and num > maximum:
maximum=num
print(maximum) | Title: Perfect Squares
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Given an array *a*1,<=*a*2,<=...,<=*a**n* of *n* integers, find the largest number in the array that is not a perfect square.
A number *x* is said to be a perfect square if there exists an integer *y* such that *x*<==<=*y*2.
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of elements in the array.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=106<=≤<=*a**i*<=≤<=106) — the elements of the array.
It is guaranteed that at least one element of the array is not a perfect square.
Output Specification:
Print the largest number in the array which is not a perfect square. It is guaranteed that an answer always exists.
Demo Input:
['2\n4 2\n', '8\n1 2 4 8 16 32 64 576\n']
Demo Output:
['2\n', '32\n']
Note:
In the first sample case, 4 is a perfect square, so the largest number in the array that is not a perfect square is 2. | ```python
import math
n = input()
n = int(n)
x = [int(x) for x in input().split()]
maximum = 0
for num in x:
if math.sqrt(num).is_integer() == False and num > maximum:
maximum=num
print(maximum)
``` | -1 |
|
1 | A | Theatre Square | PROGRAMMING | 1,000 | [
"math"
] | A. Theatre Square | 1 | 256 | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square. | The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). | Write the needed number of flagstones. | [
"6 6 4\n"
] | [
"4\n"
] | none | 0 | [
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3",
"output": "1"
},
{
"input": "2 3 4",
"output": "1"
},
{
"input": "1000000000 1000000000 1",
"output": "1000000000000000000"
},
{
"input": "12 13 4",
"output": "12"
},
{
"input": "222 332 5",
"output": "3015"
},
{
"input": "1000 1000 10",
"output": "10000"
},
{
"input": "1001 1000 10",
"output": "10100"
},
{
"input": "100 10001 1000000000",
"output": "1"
},
{
"input": "1000000000 1000000000 1000000000",
"output": "1"
},
{
"input": "1000000000 1000000000 999999999",
"output": "4"
},
{
"input": "1000000000 1000000000 192",
"output": "27126743055556"
},
{
"input": "1000000000 987654321 1",
"output": "987654321000000000"
},
{
"input": "456784567 1000000000 51",
"output": "175618850864484"
},
{
"input": "39916800 134217728 40320",
"output": "3295710"
}
] | 1,677,948,135 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 31 | 0 | import math
a=int(input(""))
b=int(input(""))
c=int(input(""))
d=a/c
d=math.ceil(d)
e=b/c
e=math.ceil(e)
print(d*e) | Title: Theatre Square
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square.
Input Specification:
The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109).
Output Specification:
Write the needed number of flagstones.
Demo Input:
['6 6 4\n']
Demo Output:
['4\n']
Note:
none | ```python
import math
a=int(input(""))
b=int(input(""))
c=int(input(""))
d=a/c
d=math.ceil(d)
e=b/c
e=math.ceil(e)
print(d*e)
``` | -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,687,688,877 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 31 | 0 | def calculate_scores(n, cards):
sereja_score = 0
dima_score = 0
left = 0
right = n - 1
for _ in range(n):
if cards[left] > cards[right]:
sereja_score += cards[left]
left += 1
else:
sereja_score += cards[right]
right -= 1
if left > right:
break
if cards[left] > cards[right]:
dima_score += cards[left]
left += 1
else:
dima_score += cards[right]
right -= 1
if left > right:
break
return sereja_score, dima_score
n = int(input())
cards = list(map(int, input().split()))
sereja_score, dima_score = calculate_scores(n, cards)
print(sereja_score, dima_score)
| Title: Sereja and Dima
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. 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
def calculate_scores(n, cards):
sereja_score = 0
dima_score = 0
left = 0
right = n - 1
for _ in range(n):
if cards[left] > cards[right]:
sereja_score += cards[left]
left += 1
else:
sereja_score += cards[right]
right -= 1
if left > right:
break
if cards[left] > cards[right]:
dima_score += cards[left]
left += 1
else:
dima_score += cards[right]
right -= 1
if left > right:
break
return sereja_score, dima_score
n = int(input())
cards = list(map(int, input().split()))
sereja_score, dima_score = calculate_scores(n, cards)
print(sereja_score, dima_score)
``` | 3 |
|
805 | A | Fake NP | PROGRAMMING | 1,000 | [
"greedy",
"math"
] | null | null | Tavak and Seyyed are good friends. Seyyed is very funny and he told Tavak to solve the following problem instead of longest-path.
You are given *l* and *r*. For all integers from *l* to *r*, inclusive, we wrote down all of their integer divisors except 1. Find the integer that we wrote down the maximum number of times.
Solve the problem to show that it's not a NP problem. | The first line contains two integers *l* and *r* (2<=≤<=*l*<=≤<=*r*<=≤<=109). | Print single integer, the integer that appears maximum number of times in the divisors.
If there are multiple answers, print any of them. | [
"19 29\n",
"3 6\n"
] | [
"2\n",
"3\n"
] | Definition of a divisor: [https://www.mathsisfun.com/definitions/divisor-of-an-integer-.html](https://www.mathsisfun.com/definitions/divisor-of-an-integer-.html)
The first example: from 19 to 29 these numbers are divisible by 2: {20, 22, 24, 26, 28}.
The second example: from 3 to 6 these numbers are divisible by 3: {3, 6}. | 500 | [
{
"input": "19 29",
"output": "2"
},
{
"input": "3 6",
"output": "2"
},
{
"input": "39 91",
"output": "2"
},
{
"input": "76 134",
"output": "2"
},
{
"input": "93 95",
"output": "2"
},
{
"input": "17 35",
"output": "2"
},
{
"input": "94 95",
"output": "2"
},
{
"input": "51 52",
"output": "2"
},
{
"input": "47 52",
"output": "2"
},
{
"input": "38 98",
"output": "2"
},
{
"input": "30 37",
"output": "2"
},
{
"input": "56 92",
"output": "2"
},
{
"input": "900000000 1000000000",
"output": "2"
},
{
"input": "37622224 162971117",
"output": "2"
},
{
"input": "760632746 850720703",
"output": "2"
},
{
"input": "908580370 968054552",
"output": "2"
},
{
"input": "951594860 953554446",
"output": "2"
},
{
"input": "347877978 913527175",
"output": "2"
},
{
"input": "620769961 988145114",
"output": "2"
},
{
"input": "820844234 892579936",
"output": "2"
},
{
"input": "741254764 741254768",
"output": "2"
},
{
"input": "80270976 80270977",
"output": "2"
},
{
"input": "392602363 392602367",
"output": "2"
},
{
"input": "519002744 519002744",
"output": "519002744"
},
{
"input": "331900277 331900277",
"output": "331900277"
},
{
"input": "419873015 419873018",
"output": "2"
},
{
"input": "349533413 349533413",
"output": "349533413"
},
{
"input": "28829775 28829776",
"output": "2"
},
{
"input": "568814539 568814539",
"output": "568814539"
},
{
"input": "720270740 720270743",
"output": "2"
},
{
"input": "871232720 871232722",
"output": "2"
},
{
"input": "305693653 305693653",
"output": "305693653"
},
{
"input": "634097178 634097179",
"output": "2"
},
{
"input": "450868287 450868290",
"output": "2"
},
{
"input": "252662256 252662260",
"output": "2"
},
{
"input": "575062045 575062049",
"output": "2"
},
{
"input": "273072892 273072894",
"output": "2"
},
{
"input": "770439256 770439256",
"output": "770439256"
},
{
"input": "2 1000000000",
"output": "2"
},
{
"input": "6 8",
"output": "2"
},
{
"input": "2 879190747",
"output": "2"
},
{
"input": "5 5",
"output": "5"
},
{
"input": "999999937 999999937",
"output": "999999937"
},
{
"input": "3 3",
"output": "3"
},
{
"input": "5 100",
"output": "2"
},
{
"input": "2 2",
"output": "2"
},
{
"input": "3 18",
"output": "2"
},
{
"input": "7 7",
"output": "7"
},
{
"input": "39916801 39916801",
"output": "39916801"
},
{
"input": "3 8",
"output": "2"
},
{
"input": "13 13",
"output": "13"
},
{
"input": "4 8",
"output": "2"
},
{
"input": "3 12",
"output": "2"
},
{
"input": "6 12",
"output": "2"
},
{
"input": "999999103 999999103",
"output": "999999103"
},
{
"input": "100000007 100000007",
"output": "100000007"
},
{
"input": "3 99",
"output": "2"
},
{
"input": "999999733 999999733",
"output": "999999733"
},
{
"input": "5 10",
"output": "2"
},
{
"input": "982451653 982451653",
"output": "982451653"
},
{
"input": "999900001 1000000000",
"output": "2"
},
{
"input": "999727999 999727999",
"output": "999727999"
},
{
"input": "2 999999999",
"output": "2"
},
{
"input": "242 244",
"output": "2"
},
{
"input": "3 10",
"output": "2"
},
{
"input": "15 27",
"output": "2"
},
{
"input": "998244353 998244353",
"output": "998244353"
},
{
"input": "5 15",
"output": "2"
},
{
"input": "999999797 999999797",
"output": "999999797"
},
{
"input": "2 3",
"output": "2"
},
{
"input": "999999929 999999929",
"output": "999999929"
},
{
"input": "3 111111",
"output": "2"
},
{
"input": "12 18",
"output": "2"
},
{
"input": "479001599 479001599",
"output": "479001599"
},
{
"input": "10000019 10000019",
"output": "10000019"
},
{
"input": "715827883 715827883",
"output": "715827883"
},
{
"input": "999992977 999992977",
"output": "999992977"
},
{
"input": "11 11",
"output": "11"
},
{
"input": "29 29",
"output": "29"
},
{
"input": "1000003 1000003",
"output": "1000003"
},
{
"input": "6 15",
"output": "2"
},
{
"input": "1200007 1200007",
"output": "1200007"
},
{
"input": "3 1000000000",
"output": "2"
},
{
"input": "990000023 990000023",
"output": "990000023"
},
{
"input": "1717 1717",
"output": "1717"
},
{
"input": "141650963 141650963",
"output": "141650963"
},
{
"input": "1002523 1002523",
"output": "1002523"
},
{
"input": "900000011 900000011",
"output": "900000011"
},
{
"input": "104729 104729",
"output": "104729"
},
{
"input": "4 12",
"output": "2"
},
{
"input": "100003 100003",
"output": "100003"
},
{
"input": "17 17",
"output": "17"
},
{
"input": "10 100",
"output": "2"
}
] | 1,627,740,006 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | min = input()
max = input()
if(min == max){
print(min)
}
else{
print(2)
} | Title: Fake NP
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Tavak and Seyyed are good friends. Seyyed is very funny and he told Tavak to solve the following problem instead of longest-path.
You are given *l* and *r*. For all integers from *l* to *r*, inclusive, we wrote down all of their integer divisors except 1. Find the integer that we wrote down the maximum number of times.
Solve the problem to show that it's not a NP problem.
Input Specification:
The first line contains two integers *l* and *r* (2<=≤<=*l*<=≤<=*r*<=≤<=109).
Output Specification:
Print single integer, the integer that appears maximum number of times in the divisors.
If there are multiple answers, print any of them.
Demo Input:
['19 29\n', '3 6\n']
Demo Output:
['2\n', '3\n']
Note:
Definition of a divisor: [https://www.mathsisfun.com/definitions/divisor-of-an-integer-.html](https://www.mathsisfun.com/definitions/divisor-of-an-integer-.html)
The first example: from 19 to 29 these numbers are divisible by 2: {20, 22, 24, 26, 28}.
The second example: from 3 to 6 these numbers are divisible by 3: {3, 6}. | ```python
min = input()
max = input()
if(min == max){
print(min)
}
else{
print(2)
}
``` | -1 |
|
496 | B | Secret Combination | PROGRAMMING | 1,500 | [
"brute force",
"constructive algorithms",
"implementation"
] | null | null | You got a box with a combination lock. The lock has a display showing *n* digits. There are two buttons on the box, each button changes digits on the display. You have quickly discovered that the first button adds 1 to all the digits (all digits 9 become digits 0), and the second button shifts all the digits on the display one position to the right (the last digit becomes the first one). For example, if the display is currently showing number 579, then if we push the first button, the display will show 680, and if after that we push the second button, the display will show 068.
You know that the lock will open if the display is showing the smallest possible number that can be obtained by pushing the buttons in some order. The leading zeros are ignored while comparing numbers. Now your task is to find the desired number. | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of digits on the display.
The second line contains *n* digits — the initial state of the display. | Print a single line containing *n* digits — the desired state of the display containing the smallest possible number. | [
"3\n579\n",
"4\n2014\n"
] | [
"024\n",
"0142\n"
] | none | 1,000 | [
{
"input": "3\n579",
"output": "024"
},
{
"input": "4\n2014",
"output": "0142"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "3\n039",
"output": "014"
},
{
"input": "4\n4444",
"output": "0000"
},
{
"input": "5\n46802",
"output": "02468"
},
{
"input": "10\n4447444444",
"output": "0000000003"
},
{
"input": "10\n5810438174",
"output": "0147609473"
},
{
"input": "30\n027027027027027027027027027027",
"output": "027027027027027027027027027027"
},
{
"input": "50\n41012516454101251645410125164541012516454101251645",
"output": "01076781720107678172010767817201076781720107678172"
},
{
"input": "72\n464553044645330446455304464553064645530445455304464553044645530446455304",
"output": "001011960020119600201196002011960020119600201996002011960020119620201196"
},
{
"input": "100\n2144315253572020279108092911160072328496568665545836825277616363478721946398140227406814602154768031",
"output": "0005996121738545755443472571416650525236761083528703911639570359104365792010332041424619191680979818"
},
{
"input": "200\n79025531557298703099245700860027432585447902553155729870309924570086002743258544790255315572987030992457008600274325854479025531557298703099245700860027432585447902553155729870309924570086002743258544",
"output": "00274325854479025531557298703099245700860027432585447902553155729870309924570086002743258544790255315572987030992457008600274325854479025531557298703099245700860027432585447902553155729870309924570086"
},
{
"input": "100\n6669666666666666666866266666666666666666666666666666666666666666626666666666666966666766665667666656",
"output": "0000000000000000000000000000000000000000006000000000000030000010000900100009000030000000000000002006"
},
{
"input": "1\n0",
"output": "0"
}
] | 1,581,388,006 | 2,147,483,647 | Python 3 | OK | TESTS | 28 | 1,107 | 409,600 | def parser():
while 1:
data = list(input().split(' '))
for number in data:
if len(number) > 0:
yield(number)
input_parser = parser()
def get_word():
global input_parser
return next(input_parser)
def get_number():
data = get_word()
try:
return int(data)
except ValueError:
return float(data)
n = get_number()
c = get_word()
b = list(c)
a = [int(i) for i in b]
# print(a)
min_val = int(c)
new_a = a.copy()
for i in range(n):
tmp = new_a.copy()
while(tmp[0] != 0):
tmp = [int((i+1) % 10) for i in tmp]
# print(tmp)
# print()
val = int("".join([str(i) for i in tmp]))
if (val < min_val):
min_val = val
last = new_a[-1]
new_a[1:] = new_a[:-1]
new_a[0] = last
min_val = list(str(min_val))
# print(n-len(min_val))
x = b
x[:n-len(min_val)] = "0" * (n-len(min_val))
x[n-len(min_val):] = min_val[:]
print(''.join(x)) | Title: Secret Combination
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You got a box with a combination lock. The lock has a display showing *n* digits. There are two buttons on the box, each button changes digits on the display. You have quickly discovered that the first button adds 1 to all the digits (all digits 9 become digits 0), and the second button shifts all the digits on the display one position to the right (the last digit becomes the first one). For example, if the display is currently showing number 579, then if we push the first button, the display will show 680, and if after that we push the second button, the display will show 068.
You know that the lock will open if the display is showing the smallest possible number that can be obtained by pushing the buttons in some order. The leading zeros are ignored while comparing numbers. Now your task is to find the desired number.
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of digits on the display.
The second line contains *n* digits — the initial state of the display.
Output Specification:
Print a single line containing *n* digits — the desired state of the display containing the smallest possible number.
Demo Input:
['3\n579\n', '4\n2014\n']
Demo Output:
['024\n', '0142\n']
Note:
none | ```python
def parser():
while 1:
data = list(input().split(' '))
for number in data:
if len(number) > 0:
yield(number)
input_parser = parser()
def get_word():
global input_parser
return next(input_parser)
def get_number():
data = get_word()
try:
return int(data)
except ValueError:
return float(data)
n = get_number()
c = get_word()
b = list(c)
a = [int(i) for i in b]
# print(a)
min_val = int(c)
new_a = a.copy()
for i in range(n):
tmp = new_a.copy()
while(tmp[0] != 0):
tmp = [int((i+1) % 10) for i in tmp]
# print(tmp)
# print()
val = int("".join([str(i) for i in tmp]))
if (val < min_val):
min_val = val
last = new_a[-1]
new_a[1:] = new_a[:-1]
new_a[0] = last
min_val = list(str(min_val))
# print(n-len(min_val))
x = b
x[:n-len(min_val)] = "0" * (n-len(min_val))
x[n-len(min_val):] = min_val[:]
print(''.join(x))
``` | 3 |
|
1,010 | B | Rocket | PROGRAMMING | 1,800 | [
"binary search",
"interactive"
] | null | null | This is an interactive problem.
Natasha is going to fly to Mars. Finally, Natasha sat in the rocket. She flies, flies... but gets bored. She wishes to arrive to Mars already! So she decides to find something to occupy herself. She couldn't think of anything better to do than to calculate the distance to the red planet.
Let's define $x$ as the distance to Mars. Unfortunately, Natasha does not know $x$. But it is known that $1 \le x \le m$, where Natasha knows the number $m$. Besides, $x$ and $m$ are positive integers.
Natasha can ask the rocket questions. Every question is an integer $y$ ($1 \le y \le m$). The correct answer to the question is $-1$, if $x<y$, $0$, if $x=y$, and $1$, if $x>y$. But the rocket is broken — it does not always answer correctly. Precisely: let the correct answer to the current question be equal to $t$, then, if the rocket answers this question correctly, then it will answer $t$, otherwise it will answer $-t$.
In addition, the rocket has a sequence $p$ of length $n$. Each element of the sequence is either $0$ or $1$. The rocket processes this sequence in the cyclic order, that is $1$-st element, $2$-nd, $3$-rd, $\ldots$, $(n-1)$-th, $n$-th, $1$-st, $2$-nd, $3$-rd, $\ldots$, $(n-1)$-th, $n$-th, $\ldots$. If the current element is $1$, the rocket answers correctly, if $0$ — lies. Natasha doesn't know the sequence $p$, but she knows its length — $n$.
You can ask the rocket no more than $60$ questions.
Help Natasha find the distance to Mars. Assume, that the distance to Mars does not change while Natasha is asking questions.
Your solution will not be accepted, if it does not receive an answer $0$ from the rocket (even if the distance to Mars is uniquely determined by the already received rocket's answers). | The first line contains two integers $m$ and $n$ ($1 \le m \le 10^9$, $1 \le n \le 30$) — the maximum distance to Mars and the number of elements in the sequence $p$. | none | [
"5 2\n1\n-1\n-1\n1\n0\n"
] | [
"1\n2\n4\n5\n3\n"
] | In the example, hacking would look like this:
5 2 3
1 0
This means that the current distance to Mars is equal to $3$, Natasha knows that it does not exceed $5$, and the rocket answers in order: correctly, incorrectly, correctly, incorrectly ...
Really:
on the first query ($1$) the correct answer is $1$, the rocket answered correctly: $1$;
on the second query ($2$) the correct answer is $1$, the rocket answered incorrectly: $-1$;
on the third query ($4$) the correct answer is $-1$, the rocket answered correctly: $-1$;
on the fourth query ($5$) the correct answer is $-1$, the rocket answered incorrectly: $1$;
on the fifth query ($3$) the correct and incorrect answer is $0$. | 750 | [
{
"input": "5 2 3\n1 0",
"output": "3 queries, x=3"
},
{
"input": "1 1 1\n1",
"output": "1 queries, x=1"
},
{
"input": "3 2 3\n1 0",
"output": "4 queries, x=3"
},
{
"input": "6 3 5\n1 1 1",
"output": "5 queries, x=5"
},
{
"input": "10 4 3\n0 0 1 0",
"output": "6 queries, x=3"
},
{
"input": "30 5 16\n0 1 1 1 0",
"output": "6 queries, x=16"
},
{
"input": "60 6 21\n1 0 0 1 0 1",
"output": "11 queries, x=21"
},
{
"input": "100 7 73\n0 0 0 1 0 1 1",
"output": "14 queries, x=73"
},
{
"input": "1000000000 29 958572235\n1 1 0 1 1 1 1 0 1 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 1 1 1 0 0",
"output": "58 queries, x=958572235"
},
{
"input": "738009704 30 116044407\n0 0 1 1 0 0 1 0 0 0 1 0 0 0 1 0 0 1 1 0 1 0 1 1 0 0 1 1 1 1",
"output": "59 queries, x=116044407"
},
{
"input": "300 8 165\n1 1 1 0 0 1 1 0",
"output": "16 queries, x=165"
},
{
"input": "600 9 150\n0 0 1 0 1 0 1 0 1",
"output": "19 queries, x=150"
},
{
"input": "1000 10 140\n0 0 0 0 1 0 0 0 0 0",
"output": "20 queries, x=140"
},
{
"input": "3000 11 1896\n1 0 1 1 0 0 0 0 1 1 1",
"output": "21 queries, x=1896"
},
{
"input": "6000 12 4679\n1 0 1 1 1 1 1 0 0 0 0 1",
"output": "23 queries, x=4679"
},
{
"input": "10000 13 4977\n1 0 1 1 0 0 0 1 0 0 1 1 0",
"output": "26 queries, x=4977"
},
{
"input": "30000 14 60\n1 1 1 0 0 1 0 1 0 0 1 0 0 0",
"output": "28 queries, x=60"
},
{
"input": "60000 15 58813\n0 1 1 0 1 1 0 0 0 1 1 1 1 0 1",
"output": "27 queries, x=58813"
},
{
"input": "100000 16 79154\n1 1 1 0 0 0 0 0 1 1 0 1 0 1 0 1",
"output": "32 queries, x=79154"
},
{
"input": "300000 17 11107\n1 0 0 0 1 0 0 0 1 1 1 0 0 1 1 1 0",
"output": "34 queries, x=11107"
},
{
"input": "600000 18 146716\n0 0 0 1 0 0 1 0 0 0 0 0 0 1 0 0 1 1",
"output": "37 queries, x=146716"
},
{
"input": "1000000 19 418016\n1 0 0 1 0 1 0 0 1 1 0 0 0 1 1 1 1 0 0",
"output": "38 queries, x=418016"
},
{
"input": "3000000 20 642518\n1 0 0 1 0 1 1 1 1 1 0 0 0 1 0 1 0 1 0 1",
"output": "41 queries, x=642518"
},
{
"input": "6000000 21 3516807\n0 0 0 1 0 1 0 1 1 0 0 0 0 1 0 1 1 1 0 0 0",
"output": "43 queries, x=3516807"
},
{
"input": "10000000 22 8115129\n1 0 1 0 0 0 0 0 0 1 1 0 1 0 0 0 0 1 1 0 0 1",
"output": "42 queries, x=8115129"
},
{
"input": "30000000 23 10362635\n0 1 0 0 1 1 1 1 0 0 0 1 0 1 1 0 1 1 1 1 0 0 0",
"output": "48 queries, x=10362635"
},
{
"input": "60000000 24 52208533\n1 1 1 0 1 0 0 0 0 0 1 0 0 1 0 1 0 1 1 0 1 1 1 0",
"output": "46 queries, x=52208533"
},
{
"input": "100000000 25 51744320\n0 1 1 1 1 0 1 1 1 1 1 1 0 1 0 1 1 0 0 1 1 0 1 0 1",
"output": "50 queries, x=51744320"
},
{
"input": "300000000 26 264009490\n1 1 1 1 1 1 1 1 0 0 0 1 1 1 1 1 0 1 1 0 1 1 1 0 1 1",
"output": "54 queries, x=264009490"
},
{
"input": "600000000 27 415720732\n1 1 1 1 1 1 0 0 1 1 1 0 1 0 1 1 0 0 1 1 1 1 0 1 0 1 0",
"output": "56 queries, x=415720732"
},
{
"input": "1000000000 28 946835863\n0 0 1 0 1 1 1 0 1 0 1 1 0 1 0 1 1 0 0 0 1 0 1 0 1 1 0 0",
"output": "58 queries, x=946835863"
},
{
"input": "1000000000 29 124919287\n0 0 1 0 0 0 1 0 1 0 0 1 1 0 1 0 1 0 1 1 1 1 0 1 1 0 1 0 0",
"output": "59 queries, x=124919287"
},
{
"input": "1000000000 30 202669473\n1 1 0 1 1 1 0 0 1 0 1 0 1 0 1 0 1 1 0 0 1 1 1 1 1 0 0 0 0 0",
"output": "58 queries, x=202669473"
},
{
"input": "1000000000 13 532121080\n1 1 1 0 1 1 0 0 0 0 1 0 1",
"output": "42 queries, x=532121080"
},
{
"input": "1000000000 27 105669924\n0 1 1 1 0 1 0 1 0 0 0 1 0 0 1 1 0 1 1 0 0 1 0 1 1 1 1",
"output": "57 queries, x=105669924"
},
{
"input": "1000000000 11 533994576\n0 0 1 0 1 1 1 1 0 1 0",
"output": "38 queries, x=533994576"
},
{
"input": "1000000000 9 107543421\n1 0 0 1 1 1 1 1 1",
"output": "39 queries, x=107543421"
},
{
"input": "1000000000 23 976059561\n1 0 0 0 0 1 0 0 1 1 1 1 1 1 1 0 0 0 0 1 0 0 1",
"output": "53 queries, x=976059561"
},
{
"input": "1000000000 7 549608406\n1 1 1 0 1 1 1",
"output": "36 queries, x=549608406"
},
{
"input": "1000000000 21 123157250\n0 1 1 1 1 1 1 0 0 0 1 1 1 1 0 0 0 1 0 0 1",
"output": "49 queries, x=123157250"
},
{
"input": "1000000000 19 696706094\n0 0 0 0 0 1 0 0 0 0 1 0 0 1 0 0 0 0 0",
"output": "47 queries, x=696706094"
},
{
"input": "1000000000 3 125030747\n0 0 0",
"output": "33 queries, x=125030747"
},
{
"input": "1000000000 17 993546887\n1 0 1 0 1 1 1 1 1 1 0 1 0 1 1 1 1",
"output": "46 queries, x=993546887"
},
{
"input": "1000000000 15 567095731\n1 1 1 0 0 1 1 1 0 1 0 0 1 0 0",
"output": "45 queries, x=567095731"
},
{
"input": "1000000000 29 140644576\n1 1 1 1 1 1 0 1 0 0 0 1 0 1 0 1 1 1 0 1 1 1 0 1 1 0 1 0 0",
"output": "58 queries, x=140644576"
},
{
"input": "1000000000 13 714193420\n0 1 0 0 0 1 0 0 0 0 1 1 1",
"output": "43 queries, x=714193420"
},
{
"input": "1000000000 27 142518072\n0 0 0 1 0 1 1 0 1 0 1 0 0 1 1 0 1 1 1 1 0 1 0 0 1 0 0",
"output": "52 queries, x=142518072"
},
{
"input": "1000000000 25 11034213\n0 0 1 0 1 1 1 0 1 1 1 1 1 0 1 0 1 1 0 0 1 0 1 0 0",
"output": "54 queries, x=11034213"
},
{
"input": "1000000000 9 584583057\n1 1 1 0 0 1 0 0 0",
"output": "35 queries, x=584583057"
},
{
"input": "1000000000 23 863164606\n1 1 0 1 0 1 0 1 0 1 0 0 1 0 0 0 1 1 1 0 0 1 1",
"output": "53 queries, x=863164606"
},
{
"input": "1000000000 21 731680746\n1 1 0 0 1 1 1 1 1 0 0 1 0 1 1 1 1 0 1 0 1",
"output": "51 queries, x=731680746"
},
{
"input": "1000000000 5 305229590\n0 0 1 1 0",
"output": "35 queries, x=305229590"
},
{
"input": "1000000000 3 28521539\n0 0 1",
"output": "31 queries, x=28521539"
},
{
"input": "1000000000 3 602070383\n0 1 1",
"output": "32 queries, x=602070383"
},
{
"input": "1000000000 2 880651931\n1 1",
"output": "30 queries, x=880651931"
},
{
"input": "1000000000 16 749168072\n1 1 0 0 0 1 0 0 1 1 1 1 1 1 1 0",
"output": "46 queries, x=749168072"
},
{
"input": "1000000000 30 322716916\n1 0 1 1 1 1 0 1 1 0 1 0 0 0 1 0 0 0 0 0 1 1 0 0 1 1 1 1 0 0",
"output": "58 queries, x=322716916"
},
{
"input": "1000000000 14 191233057\n0 0 1 0 0 1 1 1 1 0 0 0 1 1",
"output": "43 queries, x=191233057"
},
{
"input": "1000000000 30 1\n1 1 0 1 1 0 0 1 0 1 1 0 0 1 1 1 0 0 1 1 0 0 0 0 0 1 0 0 0 0",
"output": "1 queries, x=1"
},
{
"input": "1000000000 30 1\n1 0 1 1 1 1 1 1 0 1 0 0 1 1 0 0 1 0 1 0 1 0 1 1 1 0 0 1 1 1",
"output": "1 queries, x=1"
},
{
"input": "1000000000 30 1\n1 0 1 0 0 0 0 1 1 0 0 1 1 0 1 1 1 0 1 0 1 1 1 0 0 0 1 0 1 1",
"output": "1 queries, x=1"
},
{
"input": "1000000000 30 1\n1 0 1 0 0 0 1 1 1 0 1 1 1 1 0 0 0 0 0 1 0 1 0 1 1 0 0 1 1 1",
"output": "1 queries, x=1"
},
{
"input": "1000000000 30 1\n1 1 0 1 1 1 1 1 0 0 1 1 1 0 1 1 0 0 0 0 0 1 1 0 0 0 1 0 0 0",
"output": "1 queries, x=1"
},
{
"input": "1000000000 30 1000000000\n1 1 1 0 0 0 1 1 1 1 0 1 0 0 0 1 1 0 1 1 0 0 0 1 0 0 0 0 1 0",
"output": "60 queries, x=1000000000"
},
{
"input": "1000000000 30 1000000000\n1 1 1 0 0 1 1 1 0 0 1 1 0 0 1 1 1 0 1 0 1 1 0 0 1 0 1 1 1 0",
"output": "60 queries, x=1000000000"
},
{
"input": "1000000000 30 1000000000\n0 0 1 1 1 0 0 1 0 0 1 1 0 1 0 0 1 0 1 1 1 1 1 1 0 0 1 0 1 1",
"output": "60 queries, x=1000000000"
},
{
"input": "1000000000 30 1000000000\n0 0 0 1 1 1 1 1 1 0 1 0 1 0 1 1 0 1 1 0 0 1 0 0 1 0 0 1 0 1",
"output": "60 queries, x=1000000000"
},
{
"input": "1000000000 30 1000000000\n0 0 0 1 1 1 0 1 1 0 0 0 1 1 0 0 0 1 0 0 0 0 1 0 0 1 1 0 0 1",
"output": "60 queries, x=1000000000"
},
{
"input": "1 30 1\n1 1 1 0 1 0 0 0 0 1 1 0 1 0 0 1 0 1 0 1 0 1 0 1 1 0 0 0 1 1",
"output": "1 queries, x=1"
},
{
"input": "1 30 1\n1 1 0 0 0 1 1 0 0 0 0 0 1 0 1 0 0 1 0 0 1 0 1 0 0 0 1 1 0 0",
"output": "1 queries, x=1"
},
{
"input": "1 30 1\n1 0 0 0 0 1 0 0 1 0 0 1 0 1 0 1 1 1 0 1 1 0 0 1 1 0 1 0 0 0",
"output": "1 queries, x=1"
},
{
"input": "1 30 1\n1 0 1 1 1 0 0 0 0 0 0 1 0 0 1 0 1 1 0 1 0 0 0 0 0 1 0 1 0 0",
"output": "1 queries, x=1"
},
{
"input": "1 30 1\n1 0 1 1 1 1 1 0 0 0 1 1 0 1 0 1 1 0 0 0 0 0 1 1 1 1 1 0 1 1",
"output": "1 queries, x=1"
},
{
"input": "2 1 2\n1",
"output": "2 queries, x=2"
},
{
"input": "1000000000 1 1000000000\n1",
"output": "31 queries, x=1000000000"
},
{
"input": "10000 1 10000\n1",
"output": "15 queries, x=10000"
},
{
"input": "1000000000 1 999999999\n1",
"output": "30 queries, x=999999999"
},
{
"input": "100000 2 15\n1 0",
"output": "19 queries, x=15"
},
{
"input": "200000 1 110000\n1",
"output": "17 queries, x=110000"
},
{
"input": "123456789 1 42\n1",
"output": "27 queries, x=42"
},
{
"input": "1000000000 1 9\n1",
"output": "30 queries, x=9"
},
{
"input": "200000 2 100002\n1 0",
"output": "19 queries, x=100002"
},
{
"input": "1000000000 3 234567890\n0 1 0",
"output": "31 queries, x=234567890"
},
{
"input": "1000000000 5 321732193\n1 1 0 1 0",
"output": "35 queries, x=321732193"
},
{
"input": "1000000000 1 804289384\n1",
"output": "27 queries, x=804289384"
},
{
"input": "1000000000 2 999999998\n1 0",
"output": "32 queries, x=999999998"
},
{
"input": "1000000000 5 384618761\n0 1 1 0 1",
"output": "33 queries, x=384618761"
},
{
"input": "100000000 1 100\n0",
"output": "28 queries, x=100"
},
{
"input": "1000000000 1 804289384\n0",
"output": "27 queries, x=804289384"
},
{
"input": "100000000 1 100000000\n1",
"output": "28 queries, x=100000000"
},
{
"input": "40 1 4\n0",
"output": "6 queries, x=4"
},
{
"input": "1000000000 2 999999998\n0 1",
"output": "32 queries, x=999999998"
},
{
"input": "1000000000 1 1000000000\n0",
"output": "31 queries, x=1000000000"
},
{
"input": "1000000000 2 255555555\n1 0",
"output": "31 queries, x=255555555"
},
{
"input": "1000000000 2 1000000000\n0 1",
"output": "32 queries, x=1000000000"
},
{
"input": "1000000000 1 999999999\n0",
"output": "30 queries, x=999999999"
},
{
"input": "1000000000 2 888888888\n0 1",
"output": "31 queries, x=888888888"
},
{
"input": "1000000000 1 77000000\n1",
"output": "31 queries, x=77000000"
},
{
"input": "1000000000 1 123456789\n1",
"output": "27 queries, x=123456789"
},
{
"input": "10000 1 228\n0",
"output": "14 queries, x=228"
},
{
"input": "1000000000 1 12345\n1",
"output": "31 queries, x=12345"
},
{
"input": "1000000000 1 77000000\n0",
"output": "31 queries, x=77000000"
},
{
"input": "1000000000 1 23333\n0",
"output": "31 queries, x=23333"
},
{
"input": "1000000000 4 100\n0 1 0 1",
"output": "34 queries, x=100"
},
{
"input": "100000000 1 200\n1",
"output": "27 queries, x=200"
},
{
"input": "1000000000 3 5\n0 1 0",
"output": "33 queries, x=5"
},
{
"input": "1000000000 12 2\n1 1 1 1 1 1 0 0 1 1 1 1",
"output": "41 queries, x=2"
},
{
"input": "1000000000 1 5\n0",
"output": "31 queries, x=5"
},
{
"input": "100000 2 99999\n0 0",
"output": "18 queries, x=99999"
},
{
"input": "100000 2 2\n0 1",
"output": "18 queries, x=2"
},
{
"input": "1000000 1 91923\n0",
"output": "21 queries, x=91923"
},
{
"input": "1000000 2 1235\n0 1",
"output": "22 queries, x=1235"
},
{
"input": "1000000000 1 5\n1",
"output": "31 queries, x=5"
},
{
"input": "100000000 2 1234567\n0 1",
"output": "28 queries, x=1234567"
},
{
"input": "1000000000 1 1\n1",
"output": "1 queries, x=1"
},
{
"input": "1000000000 4 999999999\n1 0 0 1",
"output": "33 queries, x=999999999"
},
{
"input": "1000000000 4 1000000000\n1 0 1 0",
"output": "34 queries, x=1000000000"
},
{
"input": "1000000000 4 1\n1 0 1 0",
"output": "1 queries, x=1"
},
{
"input": "1000000000 5 500\n1 1 0 0 1",
"output": "34 queries, x=500"
},
{
"input": "1000 1 13\n1",
"output": "11 queries, x=13"
},
{
"input": "999999999 2 123456789\n1 0",
"output": "31 queries, x=123456789"
},
{
"input": "1000000000 5 1000000000\n1 1 1 1 1",
"output": "35 queries, x=1000000000"
},
{
"input": "1000000000 3 123456789\n1 0 1",
"output": "29 queries, x=123456789"
},
{
"input": "1000000000 1 123\n1",
"output": "29 queries, x=123"
},
{
"input": "10 1 9\n1",
"output": "4 queries, x=9"
},
{
"input": "1000000000 1 1\n0",
"output": "1 queries, x=1"
},
{
"input": "100000000 2 12345678\n0 1",
"output": "28 queries, x=12345678"
},
{
"input": "1000000000 30 1000000000\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",
"output": "60 queries, x=1000000000"
},
{
"input": "805306369 30 805306369\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",
"output": "60 queries, x=805306369"
},
{
"input": "1000000000 2 123\n0 1",
"output": "30 queries, x=123"
},
{
"input": "1000000000 1 9\n0",
"output": "30 queries, x=9"
},
{
"input": "100000 2 90000\n1 0",
"output": "18 queries, x=90000"
},
{
"input": "1000000000 2 123456789\n1 0",
"output": "28 queries, x=123456789"
},
{
"input": "1000000000 2 804289384\n1 0",
"output": "28 queries, x=804289384"
},
{
"input": "1000000000 30 999999970\n1 0 0 1 1 1 1 0 1 1 0 0 0 0 0 1 0 0 1 1 0 0 0 1 0 1 0 0 0 1",
"output": "60 queries, x=999999970"
}
] | 1,676,569,397 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 135 | 124 | 6,041,600 | from heapq import heappush, heappop
from collections import defaultdict, Counter, deque
import threading
import sys
import bisect
# input = sys.stdin.readline
def ri(): return int(input())
def rs(): return input()
def rl(): return list(map(int, input().split()))
def rls(): return list(input().split())
# threading.stack_size(10**8)
# sys.setrecursionlimit(10**6)
def main():
m, n = rl()
p = []
for _ in range(n):
print(m, flush=True)
i = ri()
if i == 0:
quit()
p.append(-i)
l = 1
h = m-1
for i in range(30):
mid = (l+h) >> 1
print(mid, flush=True)
j = ri()*p[i % n]
if j == 0:
quit()
elif j < 0:
h = mid-1
else:
l = mid+1
pass
main()
# threading.Thread(target=main).start()
| Title: Rocket
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This is an interactive problem.
Natasha is going to fly to Mars. Finally, Natasha sat in the rocket. She flies, flies... but gets bored. She wishes to arrive to Mars already! So she decides to find something to occupy herself. She couldn't think of anything better to do than to calculate the distance to the red planet.
Let's define $x$ as the distance to Mars. Unfortunately, Natasha does not know $x$. But it is known that $1 \le x \le m$, where Natasha knows the number $m$. Besides, $x$ and $m$ are positive integers.
Natasha can ask the rocket questions. Every question is an integer $y$ ($1 \le y \le m$). The correct answer to the question is $-1$, if $x<y$, $0$, if $x=y$, and $1$, if $x>y$. But the rocket is broken — it does not always answer correctly. Precisely: let the correct answer to the current question be equal to $t$, then, if the rocket answers this question correctly, then it will answer $t$, otherwise it will answer $-t$.
In addition, the rocket has a sequence $p$ of length $n$. Each element of the sequence is either $0$ or $1$. The rocket processes this sequence in the cyclic order, that is $1$-st element, $2$-nd, $3$-rd, $\ldots$, $(n-1)$-th, $n$-th, $1$-st, $2$-nd, $3$-rd, $\ldots$, $(n-1)$-th, $n$-th, $\ldots$. If the current element is $1$, the rocket answers correctly, if $0$ — lies. Natasha doesn't know the sequence $p$, but she knows its length — $n$.
You can ask the rocket no more than $60$ questions.
Help Natasha find the distance to Mars. Assume, that the distance to Mars does not change while Natasha is asking questions.
Your solution will not be accepted, if it does not receive an answer $0$ from the rocket (even if the distance to Mars is uniquely determined by the already received rocket's answers).
Input Specification:
The first line contains two integers $m$ and $n$ ($1 \le m \le 10^9$, $1 \le n \le 30$) — the maximum distance to Mars and the number of elements in the sequence $p$.
Output Specification:
none
Demo Input:
['5 2\n1\n-1\n-1\n1\n0\n']
Demo Output:
['1\n2\n4\n5\n3\n']
Note:
In the example, hacking would look like this:
5 2 3
1 0
This means that the current distance to Mars is equal to $3$, Natasha knows that it does not exceed $5$, and the rocket answers in order: correctly, incorrectly, correctly, incorrectly ...
Really:
on the first query ($1$) the correct answer is $1$, the rocket answered correctly: $1$;
on the second query ($2$) the correct answer is $1$, the rocket answered incorrectly: $-1$;
on the third query ($4$) the correct answer is $-1$, the rocket answered correctly: $-1$;
on the fourth query ($5$) the correct answer is $-1$, the rocket answered incorrectly: $1$;
on the fifth query ($3$) the correct and incorrect answer is $0$. | ```python
from heapq import heappush, heappop
from collections import defaultdict, Counter, deque
import threading
import sys
import bisect
# input = sys.stdin.readline
def ri(): return int(input())
def rs(): return input()
def rl(): return list(map(int, input().split()))
def rls(): return list(input().split())
# threading.stack_size(10**8)
# sys.setrecursionlimit(10**6)
def main():
m, n = rl()
p = []
for _ in range(n):
print(m, flush=True)
i = ri()
if i == 0:
quit()
p.append(-i)
l = 1
h = m-1
for i in range(30):
mid = (l+h) >> 1
print(mid, flush=True)
j = ri()*p[i % n]
if j == 0:
quit()
elif j < 0:
h = mid-1
else:
l = mid+1
pass
main()
# threading.Thread(target=main).start()
``` | 3 |
|
383 | C | Propagating tree | PROGRAMMING | 2,000 | [
"data structures",
"dfs and similar",
"trees"
] | null | null | Iahub likes trees very much. Recently he discovered an interesting tree named propagating tree. The tree consists of *n* nodes numbered from 1 to *n*, each node *i* having an initial value *a**i*. The root of the tree is node 1.
This tree has a special property: when a value *val* is added to a value of node *i*, the value -*val* is added to values of all the children of node *i*. Note that when you add value -*val* to a child of node *i*, you also add -(-*val*) to all children of the child of node *i* and so on. Look an example explanation to understand better how it works.
This tree supports two types of queries:
- "1 *x* *val*" — *val* is added to the value of node *x*; - "2 *x*" — print the current value of node *x*.
In order to help Iahub understand the tree better, you must answer *m* queries of the preceding type. | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=200000). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=1000). Each of the next *n*–1 lines contains two integers *v**i* and *u**i* (1<=≤<=*v**i*,<=*u**i*<=≤<=*n*), meaning that there is an edge between nodes *v**i* and *u**i*.
Each of the next *m* lines contains a query in the format described above. It is guaranteed that the following constraints hold for all queries: 1<=≤<=*x*<=≤<=*n*,<=1<=≤<=*val*<=≤<=1000. | For each query of type two (print the value of node *x*) you must print the answer to the query on a separate line. The queries must be answered in the order given in the input. | [
"5 5\n1 2 1 1 2\n1 2\n1 3\n2 4\n2 5\n1 2 3\n1 1 2\n2 1\n2 2\n2 4\n"
] | [
"3\n3\n0\n"
] | The values of the nodes are [1, 2, 1, 1, 2] at the beginning.
Then value 3 is added to node 2. It propagates and value -3 is added to it's sons, node 4 and node 5. Then it cannot propagate any more. So the values of the nodes are [1, 5, 1, - 2, - 1].
Then value 2 is added to node 1. It propagates and value -2 is added to it's sons, node 2 and node 3. From node 2 it propagates again, adding value 2 to it's sons, node 4 and node 5. Node 3 has no sons, so it cannot propagate from there. The values of the nodes are [3, 3, - 1, 0, 1].
You can see all the definitions about the tree at the following link: http://en.wikipedia.org/wiki/Tree_(graph_theory) | 1,500 | [
{
"input": "5 5\n1 2 1 1 2\n1 2\n1 3\n2 4\n2 5\n1 2 3\n1 1 2\n2 1\n2 2\n2 4",
"output": "3\n3\n0"
},
{
"input": "10 10\n137 197 856 768 825 894 86 174 218 326\n7 8\n4 7\n8 9\n7 10\n1 2\n2 4\n3 6\n3 5\n2 3\n1 9 624\n2 1\n2 4\n1 6 505\n1 8 467\n1 3 643\n2 1\n1 8 631\n2 4\n1 7 244",
"output": "137\n768\n137\n768"
},
{
"input": "10 10\n418 45 865 869 745 901 177 773 854 462\n4 8\n1 4\n3 6\n1 5\n1 10\n5 9\n1 2\n4 7\n1 3\n2 2\n1 6 246\n1 4 296\n1 2 378\n1 8 648\n2 6\n1 5 288\n1 6 981\n1 2 868\n2 7",
"output": "45\n1147\n-119"
}
] | 1,652,051,197 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 30 | 512,000 | def propagate(a, tree, root, n):
#print("Cheguei em", root)
#print(a)
#print(tree)
if(root == n):
return a[n-1]
for node in tree[root][0]:
val = tree[root][1]
if(val):
a[node-1] += val
tree[node][1] += -val
tree[root][1] = 0
for node in tree[root][0]:
result = propagate(a, tree, node, n)
if(result != False):
return result
return False
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
tree = {i:[[], 0] for i in range(1, n+1)}
for _ in range(n-1):
vi, vu = list(map(int, input().split()))
tree[vi][0].append(vu)
for _ in range(m):
check = list(map(int, input().split()))
if(len(check) == 3):
x = check[1]
val = check[2]
a[x-1] += val
tree[x][1] += -val
else:
print(propagate(a, tree, 1, check[1])) | Title: Propagating tree
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Iahub likes trees very much. Recently he discovered an interesting tree named propagating tree. The tree consists of *n* nodes numbered from 1 to *n*, each node *i* having an initial value *a**i*. The root of the tree is node 1.
This tree has a special property: when a value *val* is added to a value of node *i*, the value -*val* is added to values of all the children of node *i*. Note that when you add value -*val* to a child of node *i*, you also add -(-*val*) to all children of the child of node *i* and so on. Look an example explanation to understand better how it works.
This tree supports two types of queries:
- "1 *x* *val*" — *val* is added to the value of node *x*; - "2 *x*" — print the current value of node *x*.
In order to help Iahub understand the tree better, you must answer *m* queries of the preceding type.
Input Specification:
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=200000). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=1000). Each of the next *n*–1 lines contains two integers *v**i* and *u**i* (1<=≤<=*v**i*,<=*u**i*<=≤<=*n*), meaning that there is an edge between nodes *v**i* and *u**i*.
Each of the next *m* lines contains a query in the format described above. It is guaranteed that the following constraints hold for all queries: 1<=≤<=*x*<=≤<=*n*,<=1<=≤<=*val*<=≤<=1000.
Output Specification:
For each query of type two (print the value of node *x*) you must print the answer to the query on a separate line. The queries must be answered in the order given in the input.
Demo Input:
['5 5\n1 2 1 1 2\n1 2\n1 3\n2 4\n2 5\n1 2 3\n1 1 2\n2 1\n2 2\n2 4\n']
Demo Output:
['3\n3\n0\n']
Note:
The values of the nodes are [1, 2, 1, 1, 2] at the beginning.
Then value 3 is added to node 2. It propagates and value -3 is added to it's sons, node 4 and node 5. Then it cannot propagate any more. So the values of the nodes are [1, 5, 1, - 2, - 1].
Then value 2 is added to node 1. It propagates and value -2 is added to it's sons, node 2 and node 3. From node 2 it propagates again, adding value 2 to it's sons, node 4 and node 5. Node 3 has no sons, so it cannot propagate from there. The values of the nodes are [3, 3, - 1, 0, 1].
You can see all the definitions about the tree at the following link: http://en.wikipedia.org/wiki/Tree_(graph_theory) | ```python
def propagate(a, tree, root, n):
#print("Cheguei em", root)
#print(a)
#print(tree)
if(root == n):
return a[n-1]
for node in tree[root][0]:
val = tree[root][1]
if(val):
a[node-1] += val
tree[node][1] += -val
tree[root][1] = 0
for node in tree[root][0]:
result = propagate(a, tree, node, n)
if(result != False):
return result
return False
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
tree = {i:[[], 0] for i in range(1, n+1)}
for _ in range(n-1):
vi, vu = list(map(int, input().split()))
tree[vi][0].append(vu)
for _ in range(m):
check = list(map(int, input().split()))
if(len(check) == 3):
x = check[1]
val = check[2]
a[x-1] += val
tree[x][1] += -val
else:
print(propagate(a, tree, 1, check[1]))
``` | 0 |
|
99 | A | Help Far Away Kingdom | PROGRAMMING | 800 | [
"strings"
] | A. Help Far Away Kingdom | 2 | 256 | In a far away kingdom lived the King, the Prince, the Shoemaker, the Dressmaker and many other citizens. They lived happily until great trouble came into the Kingdom. The ACMers settled there.
Most damage those strange creatures inflicted upon the kingdom was that they loved high precision numbers. As a result, the Kingdom healers had already had three appointments with the merchants who were asked to sell, say, exactly 0.273549107 beer barrels. To deal with the problem somehow, the King issued an order obliging rounding up all numbers to the closest integer to simplify calculations. Specifically, the order went like this:
- If a number's integer part does not end with digit 9 and its fractional part is strictly less than 0.5, then the rounded up number coincides with the number’s integer part. - If a number's integer part does not end with digit 9 and its fractional part is not less than 0.5, the rounded up number is obtained if we add 1 to the last digit of the number’s integer part.- If the number’s integer part ends with digit 9, to round up the numbers one should go to Vasilisa the Wise. In the whole Kingdom she is the only one who can perform the tricky operation of carrying into the next position.
Merchants found the algorithm very sophisticated and they asked you (the ACMers) to help them. Can you write a program that would perform the rounding according to the King’s order? | The first line contains a single number to round up — the integer part (a non-empty set of decimal digits that do not start with 0 — with the exception of a case when the set consists of a single digit — in this case 0 can go first), then follows character «.» (a dot), and then follows the fractional part (any non-empty set of decimal digits). The number's length does not exceed 1000 characters, including the dot. There are no other characters in the input data. | If the last number of the integer part is not equal to 9, print the rounded-up number without leading zeroes. Otherwise, print the message "GOTO Vasilisa." (without the quotes). | [
"0.0\n",
"1.49\n",
"1.50\n",
"2.71828182845904523536\n",
"3.14159265358979323846\n",
"12345678901234567890.1\n",
"123456789123456789.999\n"
] | [
"0",
"1",
"2",
"3",
"3",
"12345678901234567890",
"GOTO Vasilisa."
] | none | 500 | [
{
"input": "0.0",
"output": "0"
},
{
"input": "1.49",
"output": "1"
},
{
"input": "1.50",
"output": "2"
},
{
"input": "2.71828182845904523536",
"output": "3"
},
{
"input": "3.14159265358979323846",
"output": "3"
},
{
"input": "12345678901234567890.1",
"output": "12345678901234567890"
},
{
"input": "123456789123456789.999",
"output": "GOTO Vasilisa."
},
{
"input": "12345678901234567890.9",
"output": "12345678901234567891"
},
{
"input": "123456789123456788.999",
"output": "123456789123456789"
},
{
"input": "9.000",
"output": "GOTO Vasilisa."
},
{
"input": "0.1",
"output": "0"
},
{
"input": "0.2",
"output": "0"
},
{
"input": "0.3",
"output": "0"
},
{
"input": "0.4",
"output": "0"
},
{
"input": "0.5",
"output": "1"
},
{
"input": "0.6",
"output": "1"
},
{
"input": "0.7",
"output": "1"
},
{
"input": "0.8",
"output": "1"
},
{
"input": "0.9",
"output": "1"
},
{
"input": "1.0",
"output": "1"
},
{
"input": "1.1",
"output": "1"
},
{
"input": "1.2",
"output": "1"
},
{
"input": "1.3",
"output": "1"
},
{
"input": "1.4",
"output": "1"
},
{
"input": "1.5",
"output": "2"
},
{
"input": "1.6",
"output": "2"
},
{
"input": "1.7",
"output": "2"
},
{
"input": "1.8",
"output": "2"
},
{
"input": "1.9",
"output": "2"
},
{
"input": "2.0",
"output": "2"
},
{
"input": "2.1",
"output": "2"
},
{
"input": "2.2",
"output": "2"
},
{
"input": "2.3",
"output": "2"
},
{
"input": "2.4",
"output": "2"
},
{
"input": "2.5",
"output": "3"
},
{
"input": "2.6",
"output": "3"
},
{
"input": "2.7",
"output": "3"
},
{
"input": "2.8",
"output": "3"
},
{
"input": "2.9",
"output": "3"
},
{
"input": "3.0",
"output": "3"
},
{
"input": "3.1",
"output": "3"
},
{
"input": "3.2",
"output": "3"
},
{
"input": "3.3",
"output": "3"
},
{
"input": "3.4",
"output": "3"
},
{
"input": "3.5",
"output": "4"
},
{
"input": "3.6",
"output": "4"
},
{
"input": "3.7",
"output": "4"
},
{
"input": "3.8",
"output": "4"
},
{
"input": "3.9",
"output": "4"
},
{
"input": "4.0",
"output": "4"
},
{
"input": "4.1",
"output": "4"
},
{
"input": "4.2",
"output": "4"
},
{
"input": "4.3",
"output": "4"
},
{
"input": "4.4",
"output": "4"
},
{
"input": "4.5",
"output": "5"
},
{
"input": "4.6",
"output": "5"
},
{
"input": "4.7",
"output": "5"
},
{
"input": "4.8",
"output": "5"
},
{
"input": "4.9",
"output": "5"
},
{
"input": "5.0",
"output": "5"
},
{
"input": "5.1",
"output": "5"
},
{
"input": "5.2",
"output": "5"
},
{
"input": "5.3",
"output": "5"
},
{
"input": "5.4",
"output": "5"
},
{
"input": "5.5",
"output": "6"
},
{
"input": "5.6",
"output": "6"
},
{
"input": "5.7",
"output": "6"
},
{
"input": "5.8",
"output": "6"
},
{
"input": "5.9",
"output": "6"
},
{
"input": "6.0",
"output": "6"
},
{
"input": "6.1",
"output": "6"
},
{
"input": "6.2",
"output": "6"
},
{
"input": "6.3",
"output": "6"
},
{
"input": "6.4",
"output": "6"
},
{
"input": "6.5",
"output": "7"
},
{
"input": "6.6",
"output": "7"
},
{
"input": "6.7",
"output": "7"
},
{
"input": "6.8",
"output": "7"
},
{
"input": "6.9",
"output": "7"
},
{
"input": "7.0",
"output": "7"
},
{
"input": "7.1",
"output": "7"
},
{
"input": "7.2",
"output": "7"
},
{
"input": "7.3",
"output": "7"
},
{
"input": "7.4",
"output": "7"
},
{
"input": "7.5",
"output": "8"
},
{
"input": "7.6",
"output": "8"
},
{
"input": "7.7",
"output": "8"
},
{
"input": "7.8",
"output": "8"
},
{
"input": "7.9",
"output": "8"
},
{
"input": "8.0",
"output": "8"
},
{
"input": "8.1",
"output": "8"
},
{
"input": "8.2",
"output": "8"
},
{
"input": "8.3",
"output": "8"
},
{
"input": "8.4",
"output": "8"
},
{
"input": "8.5",
"output": "9"
},
{
"input": "8.6",
"output": "9"
},
{
"input": "8.7",
"output": "9"
},
{
"input": "8.8",
"output": "9"
},
{
"input": "8.9",
"output": "9"
},
{
"input": "9.0",
"output": "GOTO Vasilisa."
},
{
"input": "9.1",
"output": "GOTO Vasilisa."
},
{
"input": "9.2",
"output": "GOTO Vasilisa."
},
{
"input": "9.3",
"output": "GOTO Vasilisa."
},
{
"input": "9.4",
"output": "GOTO Vasilisa."
},
{
"input": "9.5",
"output": "GOTO Vasilisa."
},
{
"input": "9.6",
"output": "GOTO Vasilisa."
},
{
"input": "9.7",
"output": "GOTO Vasilisa."
},
{
"input": "9.8",
"output": "GOTO Vasilisa."
},
{
"input": "9.9",
"output": "GOTO Vasilisa."
},
{
"input": "609942239104813108618306232517836377583566292129955473517174437591594761209877970062547641606473593416245554763832875919009472288995880898848455284062760160557686724163817329189799336769669146848904803188614226720978399787805489531837751080926098.1664915772983166314490532653577560222779830866949001942720729759794777105570672781798092416748052690224813237139640723361527601154465287615917169132637313918577673651098507390501962",
"output": "609942239104813108618306232517836377583566292129955473517174437591594761209877970062547641606473593416245554763832875919009472288995880898848455284062760160557686724163817329189799336769669146848904803188614226720978399787805489531837751080926098"
},
{
"input": "7002108534951820589946967018226114921984364117669853212254634761258884835434844673935047882480101006606512119541798298905598015607366335061012709906661245805358900665571472645463994925687210711492820804158354236327017974683658305043146543214454877759341394.20211856263503281388748282682120712214711232598021393495443628276945042110862480888110959179019986486690931930108026302665438087068150666835901617457150158918705186964935221768346957536540345814875615118637945520917367155931078965",
"output": "7002108534951820589946967018226114921984364117669853212254634761258884835434844673935047882480101006606512119541798298905598015607366335061012709906661245805358900665571472645463994925687210711492820804158354236327017974683658305043146543214454877759341394"
},
{
"input": "1950583094879039694852660558765931995628486712128191844305265555887022812284005463780616067.5000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"output": "1950583094879039694852660558765931995628486712128191844305265555887022812284005463780616068"
},
{
"input": "718130341896330596635811874410345440628950330.500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"output": "718130341896330596635811874410345440628950331"
},
{
"input": "927925904158088313481229162503626281882161630091489367140850985555900173018122871746924067186432044676083646964286435457446768031295712712803570690846298544912543439221596866052681116386179629036945370280722.500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"output": "927925904158088313481229162503626281882161630091489367140850985555900173018122871746924067186432044676083646964286435457446768031295712712803570690846298544912543439221596866052681116386179629036945370280723"
},
{
"input": "68289614863244584294178637364598054554769889.500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"output": "GOTO Vasilisa."
},
{
"input": "7536521504744364134984603189602839063535643888645969434165019366202558753840519.4999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999",
"output": "GOTO Vasilisa."
},
{
"input": "646188694587964249318078225173.5000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"output": "646188694587964249318078225174"
},
{
"input": "7017472758334494297677068672222822550374695787171163207025095950296957261530.50",
"output": "7017472758334494297677068672222822550374695787171163207025095950296957261531"
},
{
"input": "259085737066615534998640212505663524594409165063310128108448186246980628179842202905722595400477937071746695941939306735605849342959111887834258250883469840846714848774368.50000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"output": "259085737066615534998640212505663524594409165063310128108448186246980628179842202905722595400477937071746695941939306735605849342959111887834258250883469840846714848774369"
},
{
"input": "682500858233333594535201113441004740771119672961581796618069185960107115823662126812159957094407454522028503739299.5000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"output": "GOTO Vasilisa."
},
{
"input": "41203422675619090661099806687619.49999999999999999999999999999999999999999999999999999999999999999999999999999999999999999",
"output": "GOTO Vasilisa."
}
] | 1,606,208,185 | 2,147,483,647 | Python 3 | OK | TESTS | 150 | 218 | 0 | s1 = input()
m = s1.find('.')
m2 = int(s1[:m])
m3 = int(s1[m+1:m+2])
if s1[m-1] == '9':
print('GOTO Vasilisa.')
else:
if m3 >= 5:
m2 += 1
print(m2)
else:
print(m2) | Title: Help Far Away Kingdom
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
In a far away kingdom lived the King, the Prince, the Shoemaker, the Dressmaker and many other citizens. They lived happily until great trouble came into the Kingdom. The ACMers settled there.
Most damage those strange creatures inflicted upon the kingdom was that they loved high precision numbers. As a result, the Kingdom healers had already had three appointments with the merchants who were asked to sell, say, exactly 0.273549107 beer barrels. To deal with the problem somehow, the King issued an order obliging rounding up all numbers to the closest integer to simplify calculations. Specifically, the order went like this:
- If a number's integer part does not end with digit 9 and its fractional part is strictly less than 0.5, then the rounded up number coincides with the number’s integer part. - If a number's integer part does not end with digit 9 and its fractional part is not less than 0.5, the rounded up number is obtained if we add 1 to the last digit of the number’s integer part.- If the number’s integer part ends with digit 9, to round up the numbers one should go to Vasilisa the Wise. In the whole Kingdom she is the only one who can perform the tricky operation of carrying into the next position.
Merchants found the algorithm very sophisticated and they asked you (the ACMers) to help them. Can you write a program that would perform the rounding according to the King’s order?
Input Specification:
The first line contains a single number to round up — the integer part (a non-empty set of decimal digits that do not start with 0 — with the exception of a case when the set consists of a single digit — in this case 0 can go first), then follows character «.» (a dot), and then follows the fractional part (any non-empty set of decimal digits). The number's length does not exceed 1000 characters, including the dot. There are no other characters in the input data.
Output Specification:
If the last number of the integer part is not equal to 9, print the rounded-up number without leading zeroes. Otherwise, print the message "GOTO Vasilisa." (without the quotes).
Demo Input:
['0.0\n', '1.49\n', '1.50\n', '2.71828182845904523536\n', '3.14159265358979323846\n', '12345678901234567890.1\n', '123456789123456789.999\n']
Demo Output:
['0', '1', '2', '3', '3', '12345678901234567890', 'GOTO Vasilisa.']
Note:
none | ```python
s1 = input()
m = s1.find('.')
m2 = int(s1[:m])
m3 = int(s1[m+1:m+2])
if s1[m-1] == '9':
print('GOTO Vasilisa.')
else:
if m3 >= 5:
m2 += 1
print(m2)
else:
print(m2)
``` | 3.9455 |
75 | C | Modified GCD | PROGRAMMING | 1,600 | [
"binary search",
"number theory"
] | C. Modified GCD | 2 | 256 | Well, here is another math class task. In mathematics, GCD is the greatest common divisor, and it's an easy task to calculate the GCD between two positive integers.
A common divisor for two positive numbers is a number which both numbers are divisible by.
But your teacher wants to give you a harder task, in this task you have to find the greatest common divisor *d* between two integers *a* and *b* that is in a given range from *low* to *high* (inclusive), i.e. *low*<=≤<=*d*<=≤<=*high*. It is possible that there is no common divisor in the given range.
You will be given the two integers *a* and *b*, then *n* queries. Each query is a range from *low* to *high* and you have to answer each query. | The first line contains two integers *a* and *b*, the two integers as described above (1<=≤<=*a*,<=*b*<=≤<=109). The second line contains one integer *n*, the number of queries (1<=≤<=*n*<=≤<=104). Then *n* lines follow, each line contains one query consisting of two integers, *low* and *high* (1<=≤<=*low*<=≤<=*high*<=≤<=109). | Print *n* lines. The *i*-th of them should contain the result of the *i*-th query in the input. If there is no common divisor in the given range for any query, you should print -1 as a result for this query. | [
"9 27\n3\n1 5\n10 11\n9 11\n"
] | [
"3\n-1\n9\n"
] | none | 1,500 | [
{
"input": "9 27\n3\n1 5\n10 11\n9 11",
"output": "3\n-1\n9"
},
{
"input": "48 72\n2\n8 29\n29 37",
"output": "24\n-1"
},
{
"input": "90 100\n10\n51 61\n6 72\n1 84\n33 63\n37 69\n18 21\n9 54\n49 90\n14 87\n37 90",
"output": "-1\n10\n10\n-1\n-1\n-1\n10\n-1\n-1\n-1"
},
{
"input": "84 36\n1\n18 32",
"output": "-1"
},
{
"input": "90 36\n16\n13 15\n5 28\n11 30\n26 35\n2 8\n19 36\n3 17\n5 14\n4 26\n22 33\n16 33\n18 27\n4 17\n1 2\n29 31\n18 36",
"output": "-1\n18\n18\n-1\n6\n-1\n9\n9\n18\n-1\n18\n18\n9\n2\n-1\n18"
},
{
"input": "84 90\n18\n10 75\n2 40\n30 56\n49 62\n19 33\n5 79\n61 83\n13 56\n73 78\n1 18\n23 35\n14 72\n22 33\n1 21\n8 38\n54 82\n6 80\n57 75",
"output": "-1\n6\n-1\n-1\n-1\n6\n-1\n-1\n-1\n6\n-1\n-1\n-1\n6\n-1\n-1\n6\n-1"
},
{
"input": "84 100\n16\n10 64\n3 61\n19 51\n42 67\n51 68\n12 40\n10 47\n52 53\n37 67\n2 26\n23 47\n17 75\n49 52\n3 83\n63 81\n8 43",
"output": "-1\n4\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n4\n-1\n-1\n-1\n4\n-1\n-1"
},
{
"input": "36 60\n2\n17 25\n16 20",
"output": "-1\n-1"
},
{
"input": "90 100\n8\n55 75\n46 68\n44 60\n32 71\n43 75\n23 79\n47 86\n11 57",
"output": "-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1"
},
{
"input": "90 36\n8\n1 19\n10 12\n14 28\n21 24\n8 8\n33 34\n10 26\n15 21",
"output": "18\n-1\n18\n-1\n-1\n-1\n18\n18"
},
{
"input": "48 80\n19\n1 1\n16 16\n1 16\n16 48\n16 80\n16 1000000000\n1000000000 1000000000\n1 1000000000\n500000000 1000000000\n15 17\n17 17\n15 15\n8 8\n8 15\n8 16\n8 17\n7 17\n7 15\n9 15",
"output": "1\n16\n16\n16\n16\n16\n-1\n16\n-1\n16\n-1\n-1\n8\n8\n16\n16\n16\n8\n-1"
},
{
"input": "31607 999002449\n18\n31607 31607\n31606 31608\n31607 31608\n31606 31607\n31606 31606\n31608 31608\n1 31607\n1 31606\n1 31608\n1 1000000000\n31607 1000000000\n31606 1000000000\n31608 1000000000\n1000000000 1000000000\n1 1\n2 31606\n2 31607\n2 31608",
"output": "31607\n31607\n31607\n31607\n-1\n-1\n31607\n1\n31607\n31607\n31607\n31607\n-1\n-1\n1\n-1\n31607\n31607"
},
{
"input": "999999937 999999929\n12\n999999929 999999937\n1 1\n1 1000000000\n2 1000000000\n1 2\n999999937 999999937\n999999929 999999929\n2 2\n3 3\n1 100\n1 999999937\n1 999999929",
"output": "-1\n1\n1\n-1\n1\n-1\n-1\n-1\n-1\n1\n1\n1"
}
] | 1,604,603,347 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 280 | 0 | ''' Author @isumit '''
import math
def solve():
A, B= map(int, input().split())
gcdab = math.gcd(A, B)
divisors = []
i = 1
while i*i <= gcdab:
if gcdab % i == 0 :
divisors.append(i)
divisors.append(gcdab/i)
i += 1
divisors = sorted(divisors)
for _ in range(int(input())):
left, right = map(int, input().split())
res = -1
for i in divisors:
if left <= i and i <= right:
res = max(res, i)
print(res)
Testcase = 1
#Testcase = int(input())
for _ in range(Testcase):
solve()
''' https://codeforces.com/problemset/problem/75/C ''' | Title: Modified GCD
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Well, here is another math class task. In mathematics, GCD is the greatest common divisor, and it's an easy task to calculate the GCD between two positive integers.
A common divisor for two positive numbers is a number which both numbers are divisible by.
But your teacher wants to give you a harder task, in this task you have to find the greatest common divisor *d* between two integers *a* and *b* that is in a given range from *low* to *high* (inclusive), i.e. *low*<=≤<=*d*<=≤<=*high*. It is possible that there is no common divisor in the given range.
You will be given the two integers *a* and *b*, then *n* queries. Each query is a range from *low* to *high* and you have to answer each query.
Input Specification:
The first line contains two integers *a* and *b*, the two integers as described above (1<=≤<=*a*,<=*b*<=≤<=109). The second line contains one integer *n*, the number of queries (1<=≤<=*n*<=≤<=104). Then *n* lines follow, each line contains one query consisting of two integers, *low* and *high* (1<=≤<=*low*<=≤<=*high*<=≤<=109).
Output Specification:
Print *n* lines. The *i*-th of them should contain the result of the *i*-th query in the input. If there is no common divisor in the given range for any query, you should print -1 as a result for this query.
Demo Input:
['9 27\n3\n1 5\n10 11\n9 11\n']
Demo Output:
['3\n-1\n9\n']
Note:
none | ```python
''' Author @isumit '''
import math
def solve():
A, B= map(int, input().split())
gcdab = math.gcd(A, B)
divisors = []
i = 1
while i*i <= gcdab:
if gcdab % i == 0 :
divisors.append(i)
divisors.append(gcdab/i)
i += 1
divisors = sorted(divisors)
for _ in range(int(input())):
left, right = map(int, input().split())
res = -1
for i in divisors:
if left <= i and i <= right:
res = max(res, i)
print(res)
Testcase = 1
#Testcase = int(input())
for _ in range(Testcase):
solve()
''' https://codeforces.com/problemset/problem/75/C '''
``` | 0 |
821 | C | Okabe and Boxes | PROGRAMMING | 1,500 | [
"data structures",
"greedy",
"trees"
] | null | null | Okabe and Super Hacker Daru are stacking and removing boxes. There are *n* boxes numbered from 1 to *n*. Initially there are no boxes on the stack.
Okabe, being a control freak, gives Daru 2*n* commands: *n* of which are to add a box to the top of the stack, and *n* of which are to remove a box from the top of the stack and throw it in the trash. Okabe wants Daru to throw away the boxes in the order from 1 to *n*. Of course, this means that it might be impossible for Daru to perform some of Okabe's remove commands, because the required box is not on the top of the stack.
That's why Daru can decide to wait until Okabe looks away and then reorder the boxes in the stack in any way he wants. He can do it at any point of time between Okabe's commands, but he can't add or remove boxes while he does it.
Tell Daru the minimum number of times he needs to reorder the boxes so that he can successfully complete all of Okabe's commands. It is guaranteed that every box is added before it is required to be removed. | The first line of input contains the integer *n* (1<=≤<=*n*<=≤<=3·105) — the number of boxes.
Each of the next 2*n* lines of input starts with a string "add" or "remove". If the line starts with the "add", an integer *x* (1<=≤<=*x*<=≤<=*n*) follows, indicating that Daru should add the box with number *x* to the top of the stack.
It is guaranteed that exactly *n* lines contain "add" operations, all the boxes added are distinct, and *n* lines contain "remove" operations. It is also guaranteed that a box is always added before it is required to be removed. | Print the minimum number of times Daru needs to reorder the boxes to successfully complete all of Okabe's commands. | [
"3\nadd 1\nremove\nadd 2\nadd 3\nremove\nremove\n",
"7\nadd 3\nadd 2\nadd 1\nremove\nadd 4\nremove\nremove\nremove\nadd 6\nadd 7\nadd 5\nremove\nremove\nremove\n"
] | [
"1\n",
"2\n"
] | In the first sample, Daru should reorder the boxes after adding box 3 to the stack.
In the second sample, Daru should reorder the boxes after adding box 4 and box 7 to the stack. | 1,500 | [
{
"input": "3\nadd 1\nremove\nadd 2\nadd 3\nremove\nremove",
"output": "1"
},
{
"input": "7\nadd 3\nadd 2\nadd 1\nremove\nadd 4\nremove\nremove\nremove\nadd 6\nadd 7\nadd 5\nremove\nremove\nremove",
"output": "2"
},
{
"input": "4\nadd 1\nadd 3\nremove\nadd 4\nadd 2\nremove\nremove\nremove",
"output": "2"
},
{
"input": "2\nadd 1\nremove\nadd 2\nremove",
"output": "0"
},
{
"input": "1\nadd 1\nremove",
"output": "0"
},
{
"input": "15\nadd 12\nadd 7\nadd 10\nadd 11\nadd 5\nadd 2\nadd 1\nadd 6\nadd 8\nremove\nremove\nadd 15\nadd 4\nadd 13\nadd 9\nadd 3\nadd 14\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove",
"output": "2"
},
{
"input": "14\nadd 7\nadd 2\nadd 13\nadd 5\nadd 12\nadd 6\nadd 4\nadd 1\nadd 14\nremove\nadd 10\nremove\nadd 9\nadd 8\nadd 11\nadd 3\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove",
"output": "3"
},
{
"input": "11\nadd 10\nadd 9\nadd 11\nadd 1\nadd 5\nadd 6\nremove\nadd 3\nadd 8\nadd 2\nadd 4\nremove\nremove\nremove\nremove\nremove\nadd 7\nremove\nremove\nremove\nremove\nremove",
"output": "2"
},
{
"input": "3\nadd 3\nadd 2\nadd 1\nremove\nremove\nremove",
"output": "0"
},
{
"input": "4\nadd 1\nadd 3\nadd 4\nremove\nadd 2\nremove\nremove\nremove",
"output": "1"
},
{
"input": "6\nadd 3\nadd 4\nadd 5\nadd 1\nadd 6\nremove\nadd 2\nremove\nremove\nremove\nremove\nremove",
"output": "1"
},
{
"input": "16\nadd 1\nadd 2\nadd 3\nadd 4\nadd 5\nadd 6\nadd 7\nadd 8\nadd 9\nadd 10\nadd 11\nadd 12\nadd 13\nadd 14\nadd 15\nadd 16\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove",
"output": "1"
},
{
"input": "2\nadd 2\nadd 1\nremove\nremove",
"output": "0"
},
{
"input": "17\nadd 1\nadd 2\nadd 3\nadd 4\nadd 5\nadd 6\nadd 7\nadd 8\nadd 9\nadd 10\nadd 11\nadd 12\nadd 13\nadd 14\nadd 15\nadd 16\nadd 17\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove",
"output": "1"
},
{
"input": "18\nadd 1\nadd 2\nadd 3\nadd 4\nadd 5\nadd 6\nadd 7\nadd 8\nadd 9\nadd 10\nadd 11\nadd 12\nadd 13\nadd 14\nadd 15\nadd 16\nadd 17\nadd 18\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove",
"output": "1"
},
{
"input": "4\nadd 1\nadd 2\nremove\nremove\nadd 4\nadd 3\nremove\nremove",
"output": "1"
},
{
"input": "19\nadd 1\nadd 2\nadd 3\nadd 4\nadd 5\nadd 6\nadd 7\nadd 8\nadd 9\nadd 10\nadd 11\nadd 12\nadd 13\nadd 14\nadd 15\nadd 16\nadd 17\nadd 18\nadd 19\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove",
"output": "1"
},
{
"input": "5\nadd 4\nadd 3\nadd 1\nremove\nadd 2\nremove\nremove\nadd 5\nremove\nremove",
"output": "1"
},
{
"input": "7\nadd 4\nadd 6\nadd 1\nadd 5\nadd 7\nremove\nadd 2\nremove\nadd 3\nremove\nremove\nremove\nremove\nremove",
"output": "1"
},
{
"input": "8\nadd 1\nadd 2\nadd 3\nadd 7\nadd 8\nremove\nremove\nremove\nadd 6\nadd 5\nadd 4\nremove\nremove\nremove\nremove\nremove",
"output": "1"
},
{
"input": "4\nadd 1\nadd 4\nremove\nadd 3\nadd 2\nremove\nremove\nremove",
"output": "1"
},
{
"input": "7\nadd 1\nadd 2\nadd 3\nadd 5\nadd 7\nremove\nremove\nremove\nadd 4\nremove\nremove\nadd 6\nremove\nremove",
"output": "1"
},
{
"input": "4\nadd 4\nadd 1\nadd 2\nremove\nremove\nadd 3\nremove\nremove",
"output": "1"
},
{
"input": "5\nadd 1\nadd 3\nadd 4\nadd 5\nremove\nadd 2\nremove\nremove\nremove\nremove",
"output": "1"
},
{
"input": "5\nadd 2\nadd 1\nremove\nremove\nadd 5\nadd 3\nremove\nadd 4\nremove\nremove",
"output": "0"
},
{
"input": "9\nadd 3\nadd 2\nadd 1\nadd 4\nadd 6\nadd 9\nremove\nremove\nremove\nremove\nadd 5\nremove\nremove\nadd 8\nadd 7\nremove\nremove\nremove",
"output": "1"
},
{
"input": "10\nadd 9\nadd 10\nadd 4\nadd 3\nadd 2\nadd 1\nremove\nremove\nremove\nremove\nadd 8\nadd 7\nadd 5\nadd 6\nremove\nremove\nremove\nremove\nremove\nremove",
"output": "1"
}
] | 1,498,432,139 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 61 | 5,529,600 | from heapq import heappush, heappop
n = int(input())
heap = []
ans = 0
for i in range(2*n):
c = input()
if c == "remove":
heappop(heap)
else:
b = int(c.split()[1])
if len(heap) and b > heap[0]:
ans += 1
heappush(heap, b)
print(ans)
| Title: Okabe and Boxes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Okabe and Super Hacker Daru are stacking and removing boxes. There are *n* boxes numbered from 1 to *n*. Initially there are no boxes on the stack.
Okabe, being a control freak, gives Daru 2*n* commands: *n* of which are to add a box to the top of the stack, and *n* of which are to remove a box from the top of the stack and throw it in the trash. Okabe wants Daru to throw away the boxes in the order from 1 to *n*. Of course, this means that it might be impossible for Daru to perform some of Okabe's remove commands, because the required box is not on the top of the stack.
That's why Daru can decide to wait until Okabe looks away and then reorder the boxes in the stack in any way he wants. He can do it at any point of time between Okabe's commands, but he can't add or remove boxes while he does it.
Tell Daru the minimum number of times he needs to reorder the boxes so that he can successfully complete all of Okabe's commands. It is guaranteed that every box is added before it is required to be removed.
Input Specification:
The first line of input contains the integer *n* (1<=≤<=*n*<=≤<=3·105) — the number of boxes.
Each of the next 2*n* lines of input starts with a string "add" or "remove". If the line starts with the "add", an integer *x* (1<=≤<=*x*<=≤<=*n*) follows, indicating that Daru should add the box with number *x* to the top of the stack.
It is guaranteed that exactly *n* lines contain "add" operations, all the boxes added are distinct, and *n* lines contain "remove" operations. It is also guaranteed that a box is always added before it is required to be removed.
Output Specification:
Print the minimum number of times Daru needs to reorder the boxes to successfully complete all of Okabe's commands.
Demo Input:
['3\nadd 1\nremove\nadd 2\nadd 3\nremove\nremove\n', '7\nadd 3\nadd 2\nadd 1\nremove\nadd 4\nremove\nremove\nremove\nadd 6\nadd 7\nadd 5\nremove\nremove\nremove\n']
Demo Output:
['1\n', '2\n']
Note:
In the first sample, Daru should reorder the boxes after adding box 3 to the stack.
In the second sample, Daru should reorder the boxes after adding box 4 and box 7 to the stack. | ```python
from heapq import heappush, heappop
n = int(input())
heap = []
ans = 0
for i in range(2*n):
c = input()
if c == "remove":
heappop(heap)
else:
b = int(c.split()[1])
if len(heap) and b > heap[0]:
ans += 1
heappush(heap, b)
print(ans)
``` | 0 |
|
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,671,485,503 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 30 | 0 | a = list(input().strip().split())
n, t, k, d = int(a[0]),int(a[1]),int(a[2]),int(a[3])
times = n//k if n%k==0 else (n+k-1)/k
o1 = 0
o2 = d
for i in range(times):
if o1 > o2:
o1 += t
else:
o2 += t
if max(o1, o2) > times*t:
print('YES')
else:
print('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
a = list(input().strip().split())
n, t, k, d = int(a[0]),int(a[1]),int(a[2]),int(a[3])
times = n//k if n%k==0 else (n+k-1)/k
o1 = 0
o2 = d
for i in range(times):
if o1 > o2:
o1 += t
else:
o2 += t
if max(o1, o2) > times*t:
print('YES')
else:
print('No')
``` | 0 |
|
336 | A | Vasily the Bear and Triangle | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Vasily the bear has a favorite rectangle, it has one vertex at point (0,<=0), and the opposite vertex at point (*x*,<=*y*). Of course, the sides of Vasya's favorite rectangle are parallel to the coordinate axes.
Vasya also loves triangles, if the triangles have one vertex at point *B*<==<=(0,<=0). That's why today he asks you to find two points *A*<==<=(*x*1,<=*y*1) and *C*<==<=(*x*2,<=*y*2), such that the following conditions hold:
- the coordinates of points: *x*1, *x*2, *y*1, *y*2 are integers. Besides, the following inequation holds: *x*1<=<<=*x*2; - the triangle formed by point *A*, *B* and *C* is rectangular and isosceles ( is right); - all points of the favorite rectangle are located inside or on the border of triangle *ABC*; - the area of triangle *ABC* is as small as possible.
Help the bear, find the required points. It is not so hard to proof that these points are unique. | The first line contains two integers *x*,<=*y* (<=-<=109<=≤<=*x*,<=*y*<=≤<=109,<=*x*<=≠<=0,<=*y*<=≠<=0). | Print in the single line four integers *x*1,<=*y*1,<=*x*2,<=*y*2 — the coordinates of the required points. | [
"10 5\n",
"-10 5\n"
] | [
"0 15 15 0\n",
"-15 0 0 15\n"
] | <img class="tex-graphics" src="https://espresso.codeforces.com/a9ea2088c4294ce8f23801562fda36b830df2c3f.png" style="max-width: 100.0%;max-height: 100.0%;"/>
Figure to the first sample | 500 | [
{
"input": "10 5",
"output": "0 15 15 0"
},
{
"input": "-10 5",
"output": "-15 0 0 15"
},
{
"input": "20 -10",
"output": "0 -30 30 0"
},
{
"input": "-10 -1000000000",
"output": "-1000000010 0 0 -1000000010"
},
{
"input": "-1000000000 -1000000000",
"output": "-2000000000 0 0 -2000000000"
},
{
"input": "1000000000 1000000000",
"output": "0 2000000000 2000000000 0"
},
{
"input": "-123131 3123141",
"output": "-3246272 0 0 3246272"
},
{
"input": "-23423 -243242423",
"output": "-243265846 0 0 -243265846"
},
{
"input": "123112 4560954",
"output": "0 4684066 4684066 0"
},
{
"input": "1321 -23131",
"output": "0 -24452 24452 0"
},
{
"input": "1000000000 999999999",
"output": "0 1999999999 1999999999 0"
},
{
"input": "54543 432423",
"output": "0 486966 486966 0"
},
{
"input": "1 1",
"output": "0 2 2 0"
},
{
"input": "-1 -1",
"output": "-2 0 0 -2"
},
{
"input": "-1 1",
"output": "-2 0 0 2"
},
{
"input": "1 -1",
"output": "0 -2 2 0"
},
{
"input": "42 -2",
"output": "0 -44 44 0"
},
{
"input": "2 -435",
"output": "0 -437 437 0"
},
{
"input": "76 -76",
"output": "0 -152 152 0"
},
{
"input": "1000000000 1",
"output": "0 1000000001 1000000001 0"
},
{
"input": "1000000000 -1",
"output": "0 -1000000001 1000000001 0"
},
{
"input": "-1000000000 1",
"output": "-1000000001 0 0 1000000001"
},
{
"input": "-1000000000 -1",
"output": "-1000000001 0 0 -1000000001"
},
{
"input": "1000000000 -999999999",
"output": "0 -1999999999 1999999999 0"
},
{
"input": "-1000000000 999999999",
"output": "-1999999999 0 0 1999999999"
},
{
"input": "-1000000000 -999999999",
"output": "-1999999999 0 0 -1999999999"
},
{
"input": "999999999 1000000000",
"output": "0 1999999999 1999999999 0"
},
{
"input": "-999999999 1000000000",
"output": "-1999999999 0 0 1999999999"
},
{
"input": "999999999 -1000000000",
"output": "0 -1999999999 1999999999 0"
},
{
"input": "-999999999 -1000000000",
"output": "-1999999999 0 0 -1999999999"
}
] | 1,580,421,307 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 278 | 0 | x, y = map(int, input().split())
z = abs(x) + abs(y)
if x > 0:
print(0, z*y//y, z, 0)
else:
print(-z, 0, 0, z*y//y) | Title: Vasily the Bear and Triangle
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasily the bear has a favorite rectangle, it has one vertex at point (0,<=0), and the opposite vertex at point (*x*,<=*y*). Of course, the sides of Vasya's favorite rectangle are parallel to the coordinate axes.
Vasya also loves triangles, if the triangles have one vertex at point *B*<==<=(0,<=0). That's why today he asks you to find two points *A*<==<=(*x*1,<=*y*1) and *C*<==<=(*x*2,<=*y*2), such that the following conditions hold:
- the coordinates of points: *x*1, *x*2, *y*1, *y*2 are integers. Besides, the following inequation holds: *x*1<=<<=*x*2; - the triangle formed by point *A*, *B* and *C* is rectangular and isosceles ( is right); - all points of the favorite rectangle are located inside or on the border of triangle *ABC*; - the area of triangle *ABC* is as small as possible.
Help the bear, find the required points. It is not so hard to proof that these points are unique.
Input Specification:
The first line contains two integers *x*,<=*y* (<=-<=109<=≤<=*x*,<=*y*<=≤<=109,<=*x*<=≠<=0,<=*y*<=≠<=0).
Output Specification:
Print in the single line four integers *x*1,<=*y*1,<=*x*2,<=*y*2 — the coordinates of the required points.
Demo Input:
['10 5\n', '-10 5\n']
Demo Output:
['0 15 15 0\n', '-15 0 0 15\n']
Note:
<img class="tex-graphics" src="https://espresso.codeforces.com/a9ea2088c4294ce8f23801562fda36b830df2c3f.png" style="max-width: 100.0%;max-height: 100.0%;"/>
Figure to the first sample | ```python
x, y = map(int, input().split())
z = abs(x) + abs(y)
if x > 0:
print(0, z*y//y, z, 0)
else:
print(-z, 0, 0, z*y//y)
``` | 0 |
|
884 | A | Book Reading | PROGRAMMING | 800 | [
"implementation"
] | null | null | Recently Luba bought a very interesting book. She knows that it will take *t* seconds to read the book. Luba wants to finish reading as fast as she can.
But she has some work to do in each of *n* next days. The number of seconds that Luba has to spend working during *i*-th day is *a**i*. If some free time remains, she can spend it on reading.
Help Luba to determine the minimum number of day when she finishes reading.
It is guaranteed that the answer doesn't exceed *n*.
Remember that there are 86400 seconds in a day. | The first line contains two integers *n* and *t* (1<=≤<=*n*<=≤<=100, 1<=≤<=*t*<=≤<=106) — the number of days and the time required to read the book.
The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=86400) — the time Luba has to spend on her work during *i*-th day. | Print the minimum day Luba can finish reading the book.
It is guaranteed that answer doesn't exceed *n*. | [
"2 2\n86400 86398\n",
"2 86400\n0 86400\n"
] | [
"2\n",
"1\n"
] | none | 0 | [
{
"input": "2 2\n86400 86398",
"output": "2"
},
{
"input": "2 86400\n0 86400",
"output": "1"
},
{
"input": "2 86400\n1 86399",
"output": "2"
},
{
"input": "100 1000000\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": "12"
},
{
"input": "1 1\n86399",
"output": "1"
},
{
"input": "6 1200\n86400 86400 86000 86000 86000 86400",
"output": "5"
},
{
"input": "6 1200\n86400 86400 86000 86000 86001 86399",
"output": "6"
},
{
"input": "4 172799\n1 1 86400 0",
"output": "4"
},
{
"input": "4 172799\n0 86400 86399 0",
"output": "4"
},
{
"input": "6 1\n1 1 86400 1 86399 1",
"output": "1"
},
{
"input": "4 1\n86400 86399 86400 86400",
"output": "2"
},
{
"input": "4 1\n86400 86400 0 86400",
"output": "3"
}
] | 1,612,696,866 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | a,b=map(int,input().split())
c=[int(i) for i in input().split()]
d=0
e=0
for i in range(a):
d=d+(86400-c[i])
e=e+1
if b>=86400:
break
print(e)
| Title: Book Reading
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently Luba bought a very interesting book. She knows that it will take *t* seconds to read the book. Luba wants to finish reading as fast as she can.
But she has some work to do in each of *n* next days. The number of seconds that Luba has to spend working during *i*-th day is *a**i*. If some free time remains, she can spend it on reading.
Help Luba to determine the minimum number of day when she finishes reading.
It is guaranteed that the answer doesn't exceed *n*.
Remember that there are 86400 seconds in a day.
Input Specification:
The first line contains two integers *n* and *t* (1<=≤<=*n*<=≤<=100, 1<=≤<=*t*<=≤<=106) — the number of days and the time required to read the book.
The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=86400) — the time Luba has to spend on her work during *i*-th day.
Output Specification:
Print the minimum day Luba can finish reading the book.
It is guaranteed that answer doesn't exceed *n*.
Demo Input:
['2 2\n86400 86398\n', '2 86400\n0 86400\n']
Demo Output:
['2\n', '1\n']
Note:
none | ```python
a,b=map(int,input().split())
c=[int(i) for i in input().split()]
d=0
e=0
for i in range(a):
d=d+(86400-c[i])
e=e+1
if b>=86400:
break
print(e)
``` | 0 |
|
912 | A | Tricky Alchemy | PROGRAMMING | 800 | [
"implementation"
] | null | null | During the winter holidays, the demand for Christmas balls is exceptionally high. Since it's already 2018, the advances in alchemy allow easy and efficient ball creation by utilizing magic crystals.
Grisha needs to obtain some yellow, green and blue balls. It's known that to produce a yellow ball one needs two yellow crystals, green — one yellow and one blue, and for a blue ball, three blue crystals are enough.
Right now there are *A* yellow and *B* blue crystals in Grisha's disposal. Find out how many additional crystals he should acquire in order to produce the required number of balls. | The first line features two integers *A* and *B* (0<=≤<=*A*,<=*B*<=≤<=109), denoting the number of yellow and blue crystals respectively at Grisha's disposal.
The next line contains three integers *x*, *y* and *z* (0<=≤<=*x*,<=*y*,<=*z*<=≤<=109) — the respective amounts of yellow, green and blue balls to be obtained. | Print a single integer — the minimum number of crystals that Grisha should acquire in addition. | [
"4 3\n2 1 1\n",
"3 9\n1 1 3\n",
"12345678 87654321\n43043751 1000000000 53798715\n"
] | [
"2\n",
"1\n",
"2147483648\n"
] | In the first sample case, Grisha needs five yellow and four blue crystals to create two yellow balls, one green ball, and one blue ball. To do that, Grisha needs to obtain two additional crystals: one yellow and one blue. | 500 | [
{
"input": "4 3\n2 1 1",
"output": "2"
},
{
"input": "3 9\n1 1 3",
"output": "1"
},
{
"input": "12345678 87654321\n43043751 1000000000 53798715",
"output": "2147483648"
},
{
"input": "12 12\n3 5 2",
"output": "0"
},
{
"input": "770 1390\n170 442 311",
"output": "12"
},
{
"input": "3555165 6693472\n1499112 556941 3075290",
"output": "3089339"
},
{
"input": "0 0\n1000000000 1000000000 1000000000",
"output": "7000000000"
},
{
"input": "1 1\n0 1 0",
"output": "0"
},
{
"input": "117708228 562858833\n118004008 360437130 154015822",
"output": "738362681"
},
{
"input": "999998118 700178721\n822106746 82987112 547955384",
"output": "1753877029"
},
{
"input": "566568710 765371101\n60614022 80126928 809950465",
"output": "1744607222"
},
{
"input": "448858599 829062060\n764716760 97644201 203890025",
"output": "1178219122"
},
{
"input": "626115781 966381948\n395190569 820194184 229233367",
"output": "1525971878"
},
{
"input": "803372962 103701834\n394260597 837711458 623172928",
"output": "3426388098"
},
{
"input": "980630143 241021722\n24734406 928857659 312079781",
"output": "1624075280"
},
{
"input": "862920032 378341609\n360240924 241342224 337423122",
"output": "974174021"
},
{
"input": "40177212 515661496\n64343660 963892207 731362684",
"output": "3694721078"
},
{
"input": "217434393 579352456\n694817470 981409480 756706026",
"output": "4825785129"
},
{
"input": "394691574 716672343\n398920207 72555681 150645586",
"output": "475704521"
},
{
"input": "276981463 853992230\n29394015 90072954 839552440",
"output": "1754738044"
},
{
"input": "843552056 919184611\n341530221 423649259 101547519",
"output": "263157645"
},
{
"input": "20809236 56504497\n972004030 441166533 495487081",
"output": "4235488636"
},
{
"input": "198066417 825228166\n602477839 532312735 520830423",
"output": "2808777834"
},
{
"input": "80356306 962548053\n601547868 549830008 914769984",
"output": "4004161345"
},
{
"input": "257613487 394835231\n642087093 567347282 308709545",
"output": "2692548667"
},
{
"input": "139903376 532155119\n641157122 289897263 629020178",
"output": "3077110809"
},
{
"input": "612127849 669475006\n271630930 676010757 22959739",
"output": "682559736"
},
{
"input": "0 0\n0 0 0",
"output": "0"
},
{
"input": "1000000000 1000000000\n499999998 4 333333332",
"output": "0"
},
{
"input": "1000000000 1000000000\n1000000000 1000000000 1000000000",
"output": "5000000000"
},
{
"input": "4 3\n1 0 1",
"output": "0"
},
{
"input": "4 12\n1 2 3",
"output": "0"
},
{
"input": "4 20\n1 2 1",
"output": "0"
},
{
"input": "100 10\n2 3 4",
"output": "5"
},
{
"input": "6 0\n1 1 1",
"output": "4"
},
{
"input": "25 5\n3 3 3",
"output": "7"
},
{
"input": "48 27\n22 39 20",
"output": "107"
},
{
"input": "4 0\n1 1 1",
"output": "4"
}
] | 1,517,302,171 | 2,147,483,647 | Python 3 | OK | TESTS | 38 | 62 | 5,632,000 | r = lambda: map(int,input().split())
y,b = r()
j,k,l = r()
print (max(0,(k+3*l)-b) + max(0,(k+2*j)-y))
| Title: Tricky Alchemy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
During the winter holidays, the demand for Christmas balls is exceptionally high. Since it's already 2018, the advances in alchemy allow easy and efficient ball creation by utilizing magic crystals.
Grisha needs to obtain some yellow, green and blue balls. It's known that to produce a yellow ball one needs two yellow crystals, green — one yellow and one blue, and for a blue ball, three blue crystals are enough.
Right now there are *A* yellow and *B* blue crystals in Grisha's disposal. Find out how many additional crystals he should acquire in order to produce the required number of balls.
Input Specification:
The first line features two integers *A* and *B* (0<=≤<=*A*,<=*B*<=≤<=109), denoting the number of yellow and blue crystals respectively at Grisha's disposal.
The next line contains three integers *x*, *y* and *z* (0<=≤<=*x*,<=*y*,<=*z*<=≤<=109) — the respective amounts of yellow, green and blue balls to be obtained.
Output Specification:
Print a single integer — the minimum number of crystals that Grisha should acquire in addition.
Demo Input:
['4 3\n2 1 1\n', '3 9\n1 1 3\n', '12345678 87654321\n43043751 1000000000 53798715\n']
Demo Output:
['2\n', '1\n', '2147483648\n']
Note:
In the first sample case, Grisha needs five yellow and four blue crystals to create two yellow balls, one green ball, and one blue ball. To do that, Grisha needs to obtain two additional crystals: one yellow and one blue. | ```python
r = lambda: map(int,input().split())
y,b = r()
j,k,l = r()
print (max(0,(k+3*l)-b) + max(0,(k+2*j)-y))
``` | 3 |
|
920 | B | Tea Queue | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Recently *n* students from city S moved to city P to attend a programming camp.
They moved there by train. In the evening, all students in the train decided that they want to drink some tea. Of course, no two people can use the same teapot simultaneously, so the students had to form a queue to get their tea.
*i*-th student comes to the end of the queue at the beginning of *l**i*-th second. If there are multiple students coming to the queue in the same moment, then the student with greater index comes after the student with lesser index. Students in the queue behave as follows: if there is nobody in the queue before the student, then he uses the teapot for exactly one second and leaves the queue with his tea; otherwise the student waits for the people before him to get their tea. If at the beginning of *r**i*-th second student *i* still cannot get his tea (there is someone before him in the queue), then he leaves the queue without getting any tea.
For each student determine the second he will use the teapot and get his tea (if he actually gets it). | The first line contains one integer *t* — the number of test cases to solve (1<=≤<=*t*<=≤<=1000).
Then *t* test cases follow. The first line of each test case contains one integer *n* (1<=≤<=*n*<=≤<=1000) — the number of students.
Then *n* lines follow. Each line contains two integer *l**i*, *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=5000) — the second *i*-th student comes to the end of the queue, and the second he leaves the queue if he still cannot get his tea.
It is guaranteed that for every condition *l**i*<=-<=1<=≤<=*l**i* holds.
The sum of *n* over all test cases doesn't exceed 1000.
Note that in hacks you have to set *t*<==<=1. | For each test case print *n* integers. *i*-th of them must be equal to the second when *i*-th student gets his tea, or 0 if he leaves without tea. | [
"2\n2\n1 3\n1 4\n3\n1 5\n1 1\n2 3\n"
] | [
"1 2 \n1 0 2 \n"
] | The example contains 2 tests:
1. During 1-st second, students 1 and 2 come to the queue, and student 1 gets his tea. Student 2 gets his tea during 2-nd second. 1. During 1-st second, students 1 and 2 come to the queue, student 1 gets his tea, and student 2 leaves without tea. During 2-nd second, student 3 comes and gets his tea. | 0 | [
{
"input": "2\n2\n1 3\n1 4\n3\n1 5\n1 1\n2 3",
"output": "1 2 \n1 0 2 "
},
{
"input": "19\n1\n1 1\n1\n1 2\n1\n1 1000\n1\n1 2000\n1\n2 2\n1\n2 3\n1\n2 1000\n1\n2 2000\n1\n1999 1999\n1\n1999 2000\n1\n2000 2000\n2\n1 1\n1 1\n2\n1 1\n1 2\n2\n1 2\n1 1\n2\n1 2000\n1 1\n2\n1 1\n1 2000\n2\n1 2000\n2 2\n2\n2 2000\n2 2\n2\n2 2\n2 2000",
"output": "1 \n1 \n1 \n1 \n2 \n2 \n2 \n2 \n1999 \n1999 \n2000 \n1 0 \n1 2 \n1 0 \n1 0 \n1 2 \n1 2 \n2 0 \n2 3 "
},
{
"input": "1\n11\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1",
"output": "1 0 0 0 0 0 0 0 0 0 0 "
},
{
"input": "1\n5\n1 1\n1 2\n1 5\n1 1\n1 1",
"output": "1 2 3 0 0 "
}
] | 1,517,587,120 | 5,020 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 78 | 19,865,600 |
for _ in range(int(input())):
n = int(input())
q = []
for i in range(n):
l, r = map(int, input().split())
q.append((l,r))
t = 1
ix = 0
while ix < n:
l, r = q[ix]
ix += 1
if t >= r:
print(0, end=' ')
continue
print(t, end=' ')
t+=1
print()
| Title: Tea Queue
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently *n* students from city S moved to city P to attend a programming camp.
They moved there by train. In the evening, all students in the train decided that they want to drink some tea. Of course, no two people can use the same teapot simultaneously, so the students had to form a queue to get their tea.
*i*-th student comes to the end of the queue at the beginning of *l**i*-th second. If there are multiple students coming to the queue in the same moment, then the student with greater index comes after the student with lesser index. Students in the queue behave as follows: if there is nobody in the queue before the student, then he uses the teapot for exactly one second and leaves the queue with his tea; otherwise the student waits for the people before him to get their tea. If at the beginning of *r**i*-th second student *i* still cannot get his tea (there is someone before him in the queue), then he leaves the queue without getting any tea.
For each student determine the second he will use the teapot and get his tea (if he actually gets it).
Input Specification:
The first line contains one integer *t* — the number of test cases to solve (1<=≤<=*t*<=≤<=1000).
Then *t* test cases follow. The first line of each test case contains one integer *n* (1<=≤<=*n*<=≤<=1000) — the number of students.
Then *n* lines follow. Each line contains two integer *l**i*, *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=5000) — the second *i*-th student comes to the end of the queue, and the second he leaves the queue if he still cannot get his tea.
It is guaranteed that for every condition *l**i*<=-<=1<=≤<=*l**i* holds.
The sum of *n* over all test cases doesn't exceed 1000.
Note that in hacks you have to set *t*<==<=1.
Output Specification:
For each test case print *n* integers. *i*-th of them must be equal to the second when *i*-th student gets his tea, or 0 if he leaves without tea.
Demo Input:
['2\n2\n1 3\n1 4\n3\n1 5\n1 1\n2 3\n']
Demo Output:
['1 2 \n1 0 2 \n']
Note:
The example contains 2 tests:
1. During 1-st second, students 1 and 2 come to the queue, and student 1 gets his tea. Student 2 gets his tea during 2-nd second. 1. During 1-st second, students 1 and 2 come to the queue, student 1 gets his tea, and student 2 leaves without tea. During 2-nd second, student 3 comes and gets his tea. | ```python
for _ in range(int(input())):
n = int(input())
q = []
for i in range(n):
l, r = map(int, input().split())
q.append((l,r))
t = 1
ix = 0
while ix < n:
l, r = q[ix]
ix += 1
if t >= r:
print(0, end=' ')
continue
print(t, end=' ')
t+=1
print()
``` | 0 |
|
898 | B | Proper Nutrition | PROGRAMMING | 1,100 | [
"brute force",
"implementation",
"number theory"
] | null | null | Vasya has *n* burles. One bottle of Ber-Cola costs *a* burles and one Bars bar costs *b* burles. He can buy any non-negative integer number of bottles of Ber-Cola and any non-negative integer number of Bars bars.
Find out if it's possible to buy some amount of bottles of Ber-Cola and Bars bars and spend exactly *n* burles.
In other words, you should find two non-negative integers *x* and *y* such that Vasya can buy *x* bottles of Ber-Cola and *y* Bars bars and *x*·*a*<=+<=*y*·*b*<==<=*n* or tell that it's impossible. | First line contains single integer *n* (1<=≤<=*n*<=≤<=10<=000<=000) — amount of money, that Vasya has.
Second line contains single integer *a* (1<=≤<=*a*<=≤<=10<=000<=000) — cost of one bottle of Ber-Cola.
Third line contains single integer *b* (1<=≤<=*b*<=≤<=10<=000<=000) — cost of one Bars bar. | If Vasya can't buy Bars and Ber-Cola in such a way to spend exactly *n* burles print «NO» (without quotes).
Otherwise in first line print «YES» (without quotes). In second line print two non-negative integers *x* and *y* — number of bottles of Ber-Cola and number of Bars bars Vasya should buy in order to spend exactly *n* burles, i.e. *x*·*a*<=+<=*y*·*b*<==<=*n*. If there are multiple answers print any of them.
Any of numbers *x* and *y* can be equal 0. | [
"7\n2\n3\n",
"100\n25\n10\n",
"15\n4\n8\n",
"9960594\n2551\n2557\n"
] | [
"YES\n2 1\n",
"YES\n0 10\n",
"NO\n",
"YES\n1951 1949\n"
] | In first example Vasya can buy two bottles of Ber-Cola and one Bars bar. He will spend exactly 2·2 + 1·3 = 7 burles.
In second example Vasya can spend exactly *n* burles multiple ways:
- buy two bottles of Ber-Cola and five Bars bars; - buy four bottles of Ber-Cola and don't buy Bars bars; - don't buy Ber-Cola and buy 10 Bars bars.
In third example it's impossible to but Ber-Cola and Bars bars in order to spend exactly *n* burles. | 750 | [
{
"input": "7\n2\n3",
"output": "YES\n2 1"
},
{
"input": "100\n25\n10",
"output": "YES\n0 10"
},
{
"input": "15\n4\n8",
"output": "NO"
},
{
"input": "9960594\n2551\n2557",
"output": "YES\n1951 1949"
},
{
"input": "10000000\n1\n1",
"output": "YES\n0 10000000"
},
{
"input": "9999999\n9999\n9999",
"output": "NO"
},
{
"input": "9963629\n2591\n2593",
"output": "YES\n635 3208"
},
{
"input": "1\n7\n8",
"output": "NO"
},
{
"input": "9963630\n2591\n2593",
"output": "YES\n1931 1913"
},
{
"input": "7516066\n1601\n4793",
"output": "YES\n4027 223"
},
{
"input": "6509546\n1607\n6221",
"output": "YES\n617 887"
},
{
"input": "2756250\n8783\n29",
"output": "YES\n21 88683"
},
{
"input": "7817510\n2377\n743",
"output": "YES\n560 8730"
},
{
"input": "6087210\n1583\n1997",
"output": "YES\n1070 2200"
},
{
"input": "4\n2\n2",
"output": "YES\n0 2"
},
{
"input": "7996960\n4457\n5387",
"output": "YES\n727 883"
},
{
"input": "7988988\n4021\n3169",
"output": "YES\n1789 251"
},
{
"input": "4608528\n9059\n977",
"output": "YES\n349 1481"
},
{
"input": "8069102\n2789\n47",
"output": "YES\n3 171505"
},
{
"input": "3936174\n4783\n13",
"output": "YES\n5 300943"
},
{
"input": "10000000\n9999999\n1",
"output": "YES\n0 10000000"
},
{
"input": "10000000\n1\n9999999",
"output": "YES\n1 1"
},
{
"input": "4\n1\n3",
"output": "YES\n1 1"
},
{
"input": "4\n1\n2",
"output": "YES\n0 2"
},
{
"input": "4\n3\n1",
"output": "YES\n0 4"
},
{
"input": "4\n2\n1",
"output": "YES\n0 4"
},
{
"input": "100\n10\n20",
"output": "YES\n0 5"
},
{
"input": "101\n11\n11",
"output": "NO"
},
{
"input": "121\n11\n11",
"output": "YES\n0 11"
},
{
"input": "25\n5\n6",
"output": "YES\n5 0"
},
{
"input": "1\n1\n1",
"output": "YES\n0 1"
},
{
"input": "10000000\n2\n1",
"output": "YES\n0 10000000"
},
{
"input": "10000000\n1234523\n1",
"output": "YES\n0 10000000"
},
{
"input": "10000000\n5000000\n5000000",
"output": "YES\n0 2"
},
{
"input": "10000000\n5000001\n5000000",
"output": "YES\n0 2"
},
{
"input": "10000000\n5000000\n5000001",
"output": "YES\n2 0"
},
{
"input": "9999999\n9999999\n9999999",
"output": "YES\n0 1"
},
{
"input": "10000000\n10000000\n10000000",
"output": "YES\n0 1"
},
{
"input": "10\n1\n3",
"output": "YES\n1 3"
},
{
"input": "97374\n689\n893",
"output": "NO"
},
{
"input": "100096\n791\n524",
"output": "NO"
},
{
"input": "75916\n651\n880",
"output": "NO"
},
{
"input": "110587\n623\n806",
"output": "NO"
},
{
"input": "5600\n670\n778",
"output": "NO"
},
{
"input": "81090\n527\n614",
"output": "NO"
},
{
"input": "227718\n961\n865",
"output": "NO"
},
{
"input": "10000000\n3\n999999",
"output": "NO"
},
{
"input": "3\n4\n5",
"output": "NO"
},
{
"input": "9999999\n2\n2",
"output": "NO"
},
{
"input": "9999999\n2\n4",
"output": "NO"
},
{
"input": "9999997\n2\n5",
"output": "YES\n1 1999999"
},
{
"input": "9366189\n4326262\n8994187",
"output": "NO"
},
{
"input": "1000000\n1\n10000000",
"output": "YES\n1000000 0"
},
{
"input": "9999991\n2\n2",
"output": "NO"
},
{
"input": "10000000\n7\n7",
"output": "NO"
},
{
"input": "9999991\n2\n4",
"output": "NO"
},
{
"input": "10000000\n3\n6",
"output": "NO"
},
{
"input": "10000000\n11\n11",
"output": "NO"
},
{
"input": "4\n7\n3",
"output": "NO"
},
{
"input": "1000003\n2\n2",
"output": "NO"
},
{
"input": "1000000\n7\n7",
"output": "NO"
},
{
"input": "999999\n2\n2",
"output": "NO"
},
{
"input": "8\n13\n5",
"output": "NO"
},
{
"input": "1000003\n15\n3",
"output": "NO"
},
{
"input": "7\n7\n2",
"output": "YES\n1 0"
},
{
"input": "9999999\n2\n8",
"output": "NO"
},
{
"input": "1000000\n3\n7",
"output": "YES\n5 142855"
},
{
"input": "9999999\n1\n10000000",
"output": "YES\n9999999 0"
},
{
"input": "100\n1\n1000000",
"output": "YES\n100 0"
},
{
"input": "10000000\n9999999\n9999997",
"output": "NO"
},
{
"input": "2\n1\n3",
"output": "YES\n2 0"
},
{
"input": "3\n5\n2",
"output": "NO"
},
{
"input": "5\n2\n3",
"output": "YES\n1 1"
},
{
"input": "10000000\n7\n14",
"output": "NO"
},
{
"input": "10000000\n2\n9999999",
"output": "YES\n5000000 0"
},
{
"input": "10000000\n3\n3",
"output": "NO"
},
{
"input": "1\n3\n2",
"output": "NO"
},
{
"input": "25\n27\n2",
"output": "NO"
},
{
"input": "3\n2\n17",
"output": "NO"
},
{
"input": "999997\n4\n8",
"output": "NO"
},
{
"input": "2000000\n1\n2000001",
"output": "YES\n2000000 0"
},
{
"input": "8\n7\n3",
"output": "NO"
},
{
"input": "7005920\n5705\n28145",
"output": "NO"
},
{
"input": "2\n6\n4",
"output": "NO"
},
{
"input": "10000000\n9999999\n3",
"output": "NO"
},
{
"input": "10000000\n77\n99",
"output": "NO"
},
{
"input": "100\n8\n70",
"output": "NO"
},
{
"input": "99999\n2\n2",
"output": "NO"
},
{
"input": "5\n7\n2",
"output": "NO"
},
{
"input": "999999\n12\n14",
"output": "NO"
},
{
"input": "100\n1\n1000",
"output": "YES\n100 0"
},
{
"input": "10000000\n123\n321",
"output": "NO"
},
{
"input": "9369319\n4\n2",
"output": "NO"
},
{
"input": "9999998\n3\n3",
"output": "NO"
},
{
"input": "85\n5\n85",
"output": "YES\n0 1"
},
{
"input": "64549\n9999999\n2",
"output": "NO"
},
{
"input": "10000000\n3\n7",
"output": "YES\n1 1428571"
},
{
"input": "9999889\n2\n2",
"output": "NO"
},
{
"input": "10000000\n9999999\n123",
"output": "NO"
},
{
"input": "64549\n2\n9999999",
"output": "NO"
}
] | 1,614,412,534 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 34 | 93 | 0 | n=int(input())
a=int(input())
b=int(input())
t=int(n)
y=0
while(t%a!=0 and t>=0):
t-=b
y+=1
if t>0 and n-y*b>0:
print("YES")
print((n-y*b)//a,y)
else:
print("NO") | Title: Proper Nutrition
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has *n* burles. One bottle of Ber-Cola costs *a* burles and one Bars bar costs *b* burles. He can buy any non-negative integer number of bottles of Ber-Cola and any non-negative integer number of Bars bars.
Find out if it's possible to buy some amount of bottles of Ber-Cola and Bars bars and spend exactly *n* burles.
In other words, you should find two non-negative integers *x* and *y* such that Vasya can buy *x* bottles of Ber-Cola and *y* Bars bars and *x*·*a*<=+<=*y*·*b*<==<=*n* or tell that it's impossible.
Input Specification:
First line contains single integer *n* (1<=≤<=*n*<=≤<=10<=000<=000) — amount of money, that Vasya has.
Second line contains single integer *a* (1<=≤<=*a*<=≤<=10<=000<=000) — cost of one bottle of Ber-Cola.
Third line contains single integer *b* (1<=≤<=*b*<=≤<=10<=000<=000) — cost of one Bars bar.
Output Specification:
If Vasya can't buy Bars and Ber-Cola in such a way to spend exactly *n* burles print «NO» (without quotes).
Otherwise in first line print «YES» (without quotes). In second line print two non-negative integers *x* and *y* — number of bottles of Ber-Cola and number of Bars bars Vasya should buy in order to spend exactly *n* burles, i.e. *x*·*a*<=+<=*y*·*b*<==<=*n*. If there are multiple answers print any of them.
Any of numbers *x* and *y* can be equal 0.
Demo Input:
['7\n2\n3\n', '100\n25\n10\n', '15\n4\n8\n', '9960594\n2551\n2557\n']
Demo Output:
['YES\n2 1\n', 'YES\n0 10\n', 'NO\n', 'YES\n1951 1949\n']
Note:
In first example Vasya can buy two bottles of Ber-Cola and one Bars bar. He will spend exactly 2·2 + 1·3 = 7 burles.
In second example Vasya can spend exactly *n* burles multiple ways:
- buy two bottles of Ber-Cola and five Bars bars; - buy four bottles of Ber-Cola and don't buy Bars bars; - don't buy Ber-Cola and buy 10 Bars bars.
In third example it's impossible to but Ber-Cola and Bars bars in order to spend exactly *n* burles. | ```python
n=int(input())
a=int(input())
b=int(input())
t=int(n)
y=0
while(t%a!=0 and t>=0):
t-=b
y+=1
if t>0 and n-y*b>0:
print("YES")
print((n-y*b)//a,y)
else:
print("NO")
``` | 0 |
|
894 | A | QAQ | PROGRAMMING | 800 | [
"brute force",
"dp"
] | null | null | "QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth.
Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ" in the string (Diamond is so cute!).
Bort wants to know how many subsequences "QAQ" are in the string Diamond has given. Note that the letters "QAQ" don't have to be consecutive, but the order of letters should be exact. | The only line contains a string of length *n* (1<=≤<=*n*<=≤<=100). It's guaranteed that the string only contains uppercase English letters. | Print a single integer — the number of subsequences "QAQ" in the string. | [
"QAQAQYSYIOIWIN\n",
"QAQQQZZYNOIWIN\n"
] | [
"4\n",
"3\n"
] | In the first example there are 4 subsequences "QAQ": "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN". | 500 | [
{
"input": "QAQAQYSYIOIWIN",
"output": "4"
},
{
"input": "QAQQQZZYNOIWIN",
"output": "3"
},
{
"input": "QA",
"output": "0"
},
{
"input": "IAQVAQZLQBQVQFTQQQADAQJA",
"output": "24"
},
{
"input": "QQAAQASGAYAAAAKAKAQIQEAQAIAAIAQQQQQ",
"output": "378"
},
{
"input": "AMVFNFJIAVNQJWIVONQOAOOQSNQSONOASONAONQINAONAOIQONANOIQOANOQINAONOQINAONOXJCOIAQOAOQAQAQAQAQWWWAQQAQ",
"output": "1077"
},
{
"input": "AAQQAXBQQBQQXBNQRJAQKQNAQNQVDQASAGGANQQQQTJFFQQQTQQA",
"output": "568"
},
{
"input": "KAZXAVLPJQBQVQQQQQAPAQQGQTQVZQAAAOYA",
"output": "70"
},
{
"input": "W",
"output": "0"
},
{
"input": "DBA",
"output": "0"
},
{
"input": "RQAWNACASAAKAGAAAAQ",
"output": "10"
},
{
"input": "QJAWZAAOAAGIAAAAAOQATASQAEAAAAQFQQHPA",
"output": "111"
},
{
"input": "QQKWQAQAAAAAAAAGAAVAQUEQQUMQMAQQQNQLAMAAAUAEAAEMAAA",
"output": "411"
},
{
"input": "QQUMQAYAUAAGWAAAQSDAVAAQAAAASKQJJQQQQMAWAYYAAAAAAEAJAXWQQ",
"output": "625"
},
{
"input": "QORZOYAQ",
"output": "1"
},
{
"input": "QCQAQAGAWAQQQAQAVQAQQQQAQAQQQAQAAATQAAVAAAQQQQAAAUUQAQQNQQWQQWAQAAQQKQYAQAAQQQAAQRAQQQWBQQQQAPBAQGQA",
"output": "13174"
},
{
"input": "QQAQQAKQFAQLQAAWAMQAZQAJQAAQQOACQQAAAYANAQAQQAQAAQQAOBQQJQAQAQAQQQAAAAABQQQAVNZAQQQQAMQQAFAAEAQAQHQT",
"output": "10420"
},
{
"input": "AQEGQHQQKQAQQPQKAQQQAAAAQQQAQEQAAQAAQAQFSLAAQQAQOQQAVQAAAPQQAWAQAQAFQAXAQQQQTRLOQAQQJQNQXQQQQSQVDQQQ",
"output": "12488"
},
{
"input": "QNQKQQQLASQBAVQQQQAAQQOQRJQQAQQQEQZUOANAADAAQQJAQAQARAAAQQQEQBHTQAAQAAAAQQMKQQQIAOJJQQAQAAADADQUQQQA",
"output": "9114"
},
{
"input": "QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ",
"output": "35937"
},
{
"input": "AMQQAAQAAQAAAAAAQQQBOAAANAAKQJCYQAE",
"output": "254"
},
{
"input": "AYQBAEQGAQEOAKGIXLQJAIAKQAAAQPUAJAKAATFWQQAOQQQUFQYAQQMQHOKAAJXGFCARAQSATHAUQQAATQJJQDQRAANQQAE",
"output": "2174"
},
{
"input": "AAQXAAQAYQAAAAGAQHVQYAGIVACADFAAQAAAAQZAAQMAKZAADQAQDAAQDAAAMQQOXYAQQQAKQBAAQQKAXQBJZDDLAAHQQ",
"output": "2962"
},
{
"input": "AYQQYAVAMNIAUAAKBBQVACWKTQSAQZAAQAAASZJAWBCAALAARHACQAKQQAQAARPAQAAQAQAAZQUSHQAMFVFZQQQQSAQQXAA",
"output": "2482"
},
{
"input": "LQMAQQARQAQBJQQQAGAAZQQXALQQAARQAQQQQAAQQAQQQAQQCAQQAQQAYQQQRAAZATQALYQQAAHHAAQHAAAAAAAAQQMAAQNAKQ",
"output": "7768"
},
{
"input": "MAQQWAQOYQMAAAQAQPQZAOAAQAUAQNAAQAAAITQSAQAKAQKAQQWSQAAQQAGUCDQMQWKQUXKWQQAAQQAAQQZQDQQQAABXQUUXQOA",
"output": "5422"
},
{
"input": "QTAAQDAQXAQQJQQQGAAAQQQQSBQZKAQQAQQQQEAQNUQBZCQLYQZQEQQAAQHQVAORKQVAQYQNASZQAARZAAGAAAAOQDCQ",
"output": "3024"
},
{
"input": "QQWAQQGQQUZQQQLZAAQYQXQVAQFQUAQZUQZZQUKBHSHTQYLQAOQXAQQGAQQTQOAQARQADAJRAAQPQAQQUQAUAMAUVQAAAQQAWQ",
"output": "4527"
},
{
"input": "QQAAQQAQVAQZQQQQAOEAQZPQIBQZACQQAFQQLAAQDATZQANHKYQQAQTAAFQRQAIQAJPWQAQTEIRXAEQQAYWAAAUKQQAQAQQQSQQH",
"output": "6416"
},
{
"input": "AQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQAQAAAA",
"output": "14270"
},
{
"input": "AQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQ",
"output": "13136"
},
{
"input": "AQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQAQAA",
"output": "14270"
},
{
"input": "AQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQQAA",
"output": "14231"
},
{
"input": "QQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQAQAA",
"output": "15296"
},
{
"input": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ",
"output": "0"
},
{
"input": "QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"output": "0"
},
{
"input": "QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ",
"output": "0"
},
{
"input": "QAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQA",
"output": "20825"
},
{
"input": "AQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQ",
"output": "20825"
},
{
"input": "Q",
"output": "0"
},
{
"input": "A",
"output": "0"
},
{
"input": "FFF",
"output": "0"
},
{
"input": "AAAAAA",
"output": "0"
}
] | 1,597,345,806 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 93 | 0 | s = str(input())
c=0
for i in range(len(s)):
if s[i]=="Q":
tfinda = s[i:]
lastA = i
for _ in range(tfinda.count("A")):
pos = tfinda[lastA:len(tfinda)].find("A")
lastA = pos+1
tfindq = tfinda[pos:]
c+=tfindq.count("Q")
print(c) | Title: QAQ
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth.
Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ" in the string (Diamond is so cute!).
Bort wants to know how many subsequences "QAQ" are in the string Diamond has given. Note that the letters "QAQ" don't have to be consecutive, but the order of letters should be exact.
Input Specification:
The only line contains a string of length *n* (1<=≤<=*n*<=≤<=100). It's guaranteed that the string only contains uppercase English letters.
Output Specification:
Print a single integer — the number of subsequences "QAQ" in the string.
Demo Input:
['QAQAQYSYIOIWIN\n', 'QAQQQZZYNOIWIN\n']
Demo Output:
['4\n', '3\n']
Note:
In the first example there are 4 subsequences "QAQ": "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN". | ```python
s = str(input())
c=0
for i in range(len(s)):
if s[i]=="Q":
tfinda = s[i:]
lastA = i
for _ in range(tfinda.count("A")):
pos = tfinda[lastA:len(tfinda)].find("A")
lastA = pos+1
tfindq = tfinda[pos:]
c+=tfindq.count("Q")
print(c)
``` | 0 |
|
75 | A | Life Without Zeros | PROGRAMMING | 1,000 | [
"implementation"
] | A. Life Without Zeros | 2 | 256 | Can you imagine our life if we removed all zeros from it? For sure we will have many problems.
In this problem we will have a simple example if we removed all zeros from our life, it's the addition operation. Let's assume you are given this equation *a*<=+<=*b*<==<=*c*, where *a* and *b* are positive integers, and *c* is the sum of *a* and *b*. Now let's remove all zeros from this equation. Will the equation remain correct after removing all zeros?
For example if the equation is 101<=+<=102<==<=203, if we removed all zeros it will be 11<=+<=12<==<=23 which is still a correct equation.
But if the equation is 105<=+<=106<==<=211, if we removed all zeros it will be 15<=+<=16<==<=211 which is not a correct equation. | The input will consist of two lines, the first line will contain the integer *a*, and the second line will contain the integer *b* which are in the equation as described above (1<=≤<=*a*,<=*b*<=≤<=109). There won't be any leading zeros in both. The value of *c* should be calculated as *c*<==<=*a*<=+<=*b*. | The output will be just one line, you should print "YES" if the equation will remain correct after removing all zeros, and print "NO" otherwise. | [
"101\n102\n",
"105\n106\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "101\n102",
"output": "YES"
},
{
"input": "105\n106",
"output": "NO"
},
{
"input": "544\n397",
"output": "YES"
},
{
"input": "822\n280",
"output": "NO"
},
{
"input": "101\n413",
"output": "NO"
},
{
"input": "309\n139",
"output": "NO"
},
{
"input": "693\n970",
"output": "NO"
},
{
"input": "981\n1",
"output": "YES"
},
{
"input": "352\n276",
"output": "YES"
},
{
"input": "164\n691",
"output": "YES"
},
{
"input": "110036\n43",
"output": "YES"
},
{
"input": "100\n1000",
"output": "NO"
},
{
"input": "1000000000\n1000000000",
"output": "YES"
},
{
"input": "999999999\n999999999",
"output": "YES"
},
{
"input": "6\n4",
"output": "NO"
},
{
"input": "123456\n876543",
"output": "YES"
},
{
"input": "1234567\n9876543",
"output": "NO"
},
{
"input": "1111111\n1119111",
"output": "NO"
},
{
"input": "10502405\n40403403",
"output": "YES"
},
{
"input": "1\n1",
"output": "YES"
},
{
"input": "5\n4",
"output": "YES"
},
{
"input": "1\n6",
"output": "YES"
},
{
"input": "40\n17",
"output": "NO"
},
{
"input": "35\n81",
"output": "YES"
},
{
"input": "347\n908",
"output": "NO"
},
{
"input": "2081\n7450",
"output": "NO"
},
{
"input": "84355694\n373629503",
"output": "NO"
},
{
"input": "885992048\n510468672",
"output": "NO"
},
{
"input": "540144752\n647307841",
"output": "NO"
},
{
"input": "341781108\n784147010",
"output": "NO"
},
{
"input": "960440938\n572334653",
"output": "NO"
},
{
"input": "657414510\n768771903",
"output": "NO"
},
{
"input": "501871728\n725074574",
"output": "NO"
},
{
"input": "968\n851",
"output": "YES"
},
{
"input": "943\n939",
"output": "YES"
},
{
"input": "347\n908",
"output": "NO"
},
{
"input": "611\n41",
"output": "YES"
},
{
"input": "737\n289",
"output": "NO"
},
{
"input": "168\n571",
"output": "YES"
},
{
"input": "868\n463",
"output": "YES"
},
{
"input": "815732007\n913882008",
"output": "NO"
},
{
"input": "459039901\n453033850",
"output": "NO"
},
{
"input": "975305404\n484601256",
"output": "NO"
}
] | 1,670,226,828 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 92 | 0 | a = input()
b = input()
c = int(a) + int(b)
c_prime = int(str(c).replace('0', ''))
c_prime_prime = int(a.replace('0', '')) + int(b.replace('0', ''))
print('YES' if c_prime_prime == c_prime else 'NO')
| Title: Life Without Zeros
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Can you imagine our life if we removed all zeros from it? For sure we will have many problems.
In this problem we will have a simple example if we removed all zeros from our life, it's the addition operation. Let's assume you are given this equation *a*<=+<=*b*<==<=*c*, where *a* and *b* are positive integers, and *c* is the sum of *a* and *b*. Now let's remove all zeros from this equation. Will the equation remain correct after removing all zeros?
For example if the equation is 101<=+<=102<==<=203, if we removed all zeros it will be 11<=+<=12<==<=23 which is still a correct equation.
But if the equation is 105<=+<=106<==<=211, if we removed all zeros it will be 15<=+<=16<==<=211 which is not a correct equation.
Input Specification:
The input will consist of two lines, the first line will contain the integer *a*, and the second line will contain the integer *b* which are in the equation as described above (1<=≤<=*a*,<=*b*<=≤<=109). There won't be any leading zeros in both. The value of *c* should be calculated as *c*<==<=*a*<=+<=*b*.
Output Specification:
The output will be just one line, you should print "YES" if the equation will remain correct after removing all zeros, and print "NO" otherwise.
Demo Input:
['101\n102\n', '105\n106\n']
Demo Output:
['YES\n', 'NO\n']
Note:
none | ```python
a = input()
b = input()
c = int(a) + int(b)
c_prime = int(str(c).replace('0', ''))
c_prime_prime = int(a.replace('0', '')) + int(b.replace('0', ''))
print('YES' if c_prime_prime == c_prime else 'NO')
``` | 3.977 |
761 | A | Dasha and Stairs | PROGRAMMING | 1,000 | [
"brute force",
"constructive algorithms",
"implementation",
"math"
] | null | null | On her way to programming school tiger Dasha faced her first test — a huge staircase!
The steps were numbered from one to infinity. As we know, tigers are very fond of all striped things, it is possible that it has something to do with their color. So on some interval of her way she calculated two values — the number of steps with even and odd numbers.
You need to check whether there is an interval of steps from the *l*-th to the *r*-th (1<=≤<=*l*<=≤<=*r*), for which values that Dasha has found are correct. | In the only line you are given two integers *a*, *b* (0<=≤<=*a*,<=*b*<=≤<=100) — the number of even and odd steps, accordingly. | In the only line print "YES", if the interval of steps described above exists, and "NO" otherwise. | [
"2 3\n",
"3 1\n"
] | [
"YES\n",
"NO\n"
] | In the first example one of suitable intervals is from 1 to 5. The interval contains two even steps — 2 and 4, and three odd: 1, 3 and 5. | 500 | [
{
"input": "2 3",
"output": "YES"
},
{
"input": "3 1",
"output": "NO"
},
{
"input": "5 4",
"output": "YES"
},
{
"input": "9 9",
"output": "YES"
},
{
"input": "85 95",
"output": "NO"
},
{
"input": "0 1",
"output": "YES"
},
{
"input": "89 25",
"output": "NO"
},
{
"input": "74 73",
"output": "YES"
},
{
"input": "62 39",
"output": "NO"
},
{
"input": "57 57",
"output": "YES"
},
{
"input": "100 99",
"output": "YES"
},
{
"input": "0 0",
"output": "NO"
},
{
"input": "98 100",
"output": "NO"
},
{
"input": "99 100",
"output": "YES"
},
{
"input": "1 0",
"output": "YES"
},
{
"input": "100 0",
"output": "NO"
},
{
"input": "0 100",
"output": "NO"
},
{
"input": "100 98",
"output": "NO"
},
{
"input": "100 100",
"output": "YES"
},
{
"input": "0 5",
"output": "NO"
},
{
"input": "2 2",
"output": "YES"
}
] | 1,515,580,566 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 5,632,000 | n,m = [int(i) for i in input().split()]
ans = 'YES'
if m == 0 and n == 0 or n-m > 0 :
ans = 'NO'
print(ans)
| Title: Dasha and Stairs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
On her way to programming school tiger Dasha faced her first test — a huge staircase!
The steps were numbered from one to infinity. As we know, tigers are very fond of all striped things, it is possible that it has something to do with their color. So on some interval of her way she calculated two values — the number of steps with even and odd numbers.
You need to check whether there is an interval of steps from the *l*-th to the *r*-th (1<=≤<=*l*<=≤<=*r*), for which values that Dasha has found are correct.
Input Specification:
In the only line you are given two integers *a*, *b* (0<=≤<=*a*,<=*b*<=≤<=100) — the number of even and odd steps, accordingly.
Output Specification:
In the only line print "YES", if the interval of steps described above exists, and "NO" otherwise.
Demo Input:
['2 3\n', '3 1\n']
Demo Output:
['YES\n', 'NO\n']
Note:
In the first example one of suitable intervals is from 1 to 5. The interval contains two even steps — 2 and 4, and three odd: 1, 3 and 5. | ```python
n,m = [int(i) for i in input().split()]
ans = 'YES'
if m == 0 and n == 0 or n-m > 0 :
ans = 'NO'
print(ans)
``` | 0 |
|
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,689,766,999 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 2 | 500 | 5,222,400 | n = int(input())
ans = pow(5,n)%100
print(ans)
| 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
n = int(input())
ans = pow(5,n)%100
print(ans)
``` | 0 |
|
817 | A | Treasure Hunt | PROGRAMMING | 1,200 | [
"implementation",
"math",
"number theory"
] | null | null | Captain Bill the Hummingbird and his crew recieved an interesting challenge offer. Some stranger gave them a map, potion of teleportation and said that only this potion might help them to reach the treasure.
Bottle with potion has two values *x* and *y* written on it. These values define four moves which can be performed using the potion:
- - - -
Map shows that the position of Captain Bill the Hummingbird is (*x*1,<=*y*1) and the position of the treasure is (*x*2,<=*y*2).
You task is to tell Captain Bill the Hummingbird whether he should accept this challenge or decline. If it is possible for Captain to reach the treasure using the potion then output "YES", otherwise "NO" (without quotes).
The potion can be used infinite amount of times. | The first line contains four integer numbers *x*1,<=*y*1,<=*x*2,<=*y*2 (<=-<=105<=≤<=*x*1,<=*y*1,<=*x*2,<=*y*2<=≤<=105) — positions of Captain Bill the Hummingbird and treasure respectively.
The second line contains two integer numbers *x*,<=*y* (1<=≤<=*x*,<=*y*<=≤<=105) — values on the potion bottle. | Print "YES" if it is possible for Captain to reach the treasure using the potion, otherwise print "NO" (without quotes). | [
"0 0 0 6\n2 3\n",
"1 1 3 6\n1 5\n"
] | [
"YES\n",
"NO\n"
] | In the first example there exists such sequence of moves:
1. <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7c939890fb4ed35688177327dac981bfa9216c00.png" style="max-width: 100.0%;max-height: 100.0%;"/> — the first type of move 1. <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/afbfa42fbac4e0641e7466e3aac74cbbb08ed597.png" style="max-width: 100.0%;max-height: 100.0%;"/> — the third type of move | 0 | [
{
"input": "0 0 0 6\n2 3",
"output": "YES"
},
{
"input": "1 1 3 6\n1 5",
"output": "NO"
},
{
"input": "5 4 6 -10\n1 1",
"output": "NO"
},
{
"input": "6 -3 -7 -7\n1 2",
"output": "NO"
},
{
"input": "2 -5 -8 8\n2 1",
"output": "YES"
},
{
"input": "70 -81 -17 80\n87 23",
"output": "YES"
},
{
"input": "41 366 218 -240\n3456 1234",
"output": "NO"
},
{
"input": "-61972 -39646 -42371 -24854\n573 238",
"output": "NO"
},
{
"input": "-84870 -42042 94570 98028\n8972 23345",
"output": "YES"
},
{
"input": "-58533 -50999 -1007 -59169\n8972 23345",
"output": "NO"
},
{
"input": "-100000 -100000 100000 100000\n100000 100000",
"output": "YES"
},
{
"input": "-100000 -100000 100000 100000\n1 1",
"output": "YES"
},
{
"input": "5 2 5 3\n1 1",
"output": "NO"
},
{
"input": "5 5 5 5\n5 5",
"output": "YES"
},
{
"input": "0 0 1000 1000\n1 1",
"output": "YES"
},
{
"input": "0 0 0 1\n1 1",
"output": "NO"
},
{
"input": "1 1 4 4\n2 2",
"output": "NO"
},
{
"input": "100000 100000 99999 99999\n100000 100000",
"output": "NO"
},
{
"input": "1 1 1 6\n1 5",
"output": "NO"
},
{
"input": "2 9 4 0\n2 3",
"output": "YES"
},
{
"input": "0 0 0 9\n2 3",
"output": "NO"
},
{
"input": "14 88 14 88\n100 500",
"output": "YES"
},
{
"input": "-1 0 3 0\n4 4",
"output": "NO"
},
{
"input": "0 0 8 9\n2 3",
"output": "NO"
},
{
"input": "-2 5 7 -6\n1 1",
"output": "YES"
},
{
"input": "3 7 -8 8\n2 2",
"output": "NO"
},
{
"input": "-4 -8 -6 -1\n1 3",
"output": "NO"
},
{
"input": "0 8 6 2\n1 1",
"output": "YES"
},
{
"input": "-5 -2 -8 -2\n1 1",
"output": "NO"
},
{
"input": "1 4 -5 0\n1 1",
"output": "YES"
},
{
"input": "8 -4 4 -7\n1 2",
"output": "NO"
},
{
"input": "5 2 2 4\n2 2",
"output": "NO"
},
{
"input": "2 0 -4 6\n1 2",
"output": "NO"
},
{
"input": "-2 6 -5 -4\n1 2",
"output": "YES"
},
{
"input": "-6 5 10 6\n2 4",
"output": "NO"
},
{
"input": "3 -7 1 -8\n1 2",
"output": "NO"
},
{
"input": "4 1 4 -4\n9 4",
"output": "NO"
},
{
"input": "9 -3 -9 -3\n2 2",
"output": "NO"
},
{
"input": "-6 -6 -10 -5\n6 7",
"output": "NO"
},
{
"input": "-5 -2 2 2\n1 7",
"output": "NO"
},
{
"input": "9 0 8 1\n7 10",
"output": "NO"
},
{
"input": "-1 6 -7 -6\n6 4",
"output": "YES"
},
{
"input": "2 2 -3 -3\n3 1",
"output": "NO"
},
{
"input": "2 -6 7 2\n2 1",
"output": "NO"
},
{
"input": "-6 2 -7 -7\n1 2",
"output": "NO"
},
{
"input": "-5 -5 -1 -5\n2 2",
"output": "YES"
},
{
"input": "0 5 3 -6\n2 2",
"output": "NO"
},
{
"input": "0 -6 2 -1\n1 1",
"output": "NO"
},
{
"input": "-6 6 -5 -4\n1 2",
"output": "YES"
},
{
"input": "7 -7 1 -7\n2 2",
"output": "NO"
},
{
"input": "99966 -99952 -99966 99923\n1 1",
"output": "NO"
},
{
"input": "99921 99980 -99956 -99907\n3 4",
"output": "NO"
},
{
"input": "100000 100000 -100000 -100000\n1 1",
"output": "YES"
},
{
"input": "1 0 2 0\n5 1",
"output": "NO"
},
{
"input": "-3 0 -8 0\n7 2",
"output": "NO"
},
{
"input": "-9 4 -5 -1\n8 2",
"output": "NO"
},
{
"input": "-99999 -100000 100000 100000\n1 1",
"output": "NO"
},
{
"input": "0 0 -100 -100\n2 2",
"output": "YES"
},
{
"input": "9 -5 -3 -2\n1 4",
"output": "NO"
},
{
"input": "1 -10 -10 5\n7 5",
"output": "NO"
},
{
"input": "6 -9 -1 -9\n1 9",
"output": "NO"
}
] | 1,664,024,488 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 26 | 46 | 0 | x1,y1,x2,y2 = list(map(int, input().split()))
x, y = map(int, input().split())
a = abs(x2-x1)//x
b = abs(y2-y1)//y
r = 0
#print(a, b)
if a > b:
f = a*y - y2 + y1
c = (abs(f)//y)%2 == 0
d = (y2-y1)%y == 0
r = False if (y1!= y2 and (y2-y1)%y != 0) else c
else:
f = b*x - x2 + x1
c = (abs(f)//x)%2 == 0
d = (x2-x1)%x == 0
r = False if (x1!= x2 and (x2-x1)%x != 0) else c
#print(f, c)
print(['NO', 'YES'][r])
| Title: Treasure Hunt
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Captain Bill the Hummingbird and his crew recieved an interesting challenge offer. Some stranger gave them a map, potion of teleportation and said that only this potion might help them to reach the treasure.
Bottle with potion has two values *x* and *y* written on it. These values define four moves which can be performed using the potion:
- - - -
Map shows that the position of Captain Bill the Hummingbird is (*x*1,<=*y*1) and the position of the treasure is (*x*2,<=*y*2).
You task is to tell Captain Bill the Hummingbird whether he should accept this challenge or decline. If it is possible for Captain to reach the treasure using the potion then output "YES", otherwise "NO" (without quotes).
The potion can be used infinite amount of times.
Input Specification:
The first line contains four integer numbers *x*1,<=*y*1,<=*x*2,<=*y*2 (<=-<=105<=≤<=*x*1,<=*y*1,<=*x*2,<=*y*2<=≤<=105) — positions of Captain Bill the Hummingbird and treasure respectively.
The second line contains two integer numbers *x*,<=*y* (1<=≤<=*x*,<=*y*<=≤<=105) — values on the potion bottle.
Output Specification:
Print "YES" if it is possible for Captain to reach the treasure using the potion, otherwise print "NO" (without quotes).
Demo Input:
['0 0 0 6\n2 3\n', '1 1 3 6\n1 5\n']
Demo Output:
['YES\n', 'NO\n']
Note:
In the first example there exists such sequence of moves:
1. <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7c939890fb4ed35688177327dac981bfa9216c00.png" style="max-width: 100.0%;max-height: 100.0%;"/> — the first type of move 1. <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/afbfa42fbac4e0641e7466e3aac74cbbb08ed597.png" style="max-width: 100.0%;max-height: 100.0%;"/> — the third type of move | ```python
x1,y1,x2,y2 = list(map(int, input().split()))
x, y = map(int, input().split())
a = abs(x2-x1)//x
b = abs(y2-y1)//y
r = 0
#print(a, b)
if a > b:
f = a*y - y2 + y1
c = (abs(f)//y)%2 == 0
d = (y2-y1)%y == 0
r = False if (y1!= y2 and (y2-y1)%y != 0) else c
else:
f = b*x - x2 + x1
c = (abs(f)//x)%2 == 0
d = (x2-x1)%x == 0
r = False if (x1!= x2 and (x2-x1)%x != 0) else c
#print(f, c)
print(['NO', 'YES'][r])
``` | 0 |
|
450 | A | Jzzhu and Children | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | There are *n* children in Jzzhu's school. Jzzhu is going to give some candies to them. Let's number all the children from 1 to *n*. The *i*-th child wants to get at least *a**i* candies.
Jzzhu asks children to line up. Initially, the *i*-th child stands at the *i*-th place of the line. Then Jzzhu start distribution of the candies. He follows the algorithm:
1. Give *m* candies to the first child of the line. 1. If this child still haven't got enough candies, then the child goes to the end of the line, else the child go home. 1. Repeat the first two steps while the line is not empty.
Consider all the children in the order they go home. Jzzhu wants to know, which child will be the last in this order? | The first line contains two integers *n*,<=*m* (1<=≤<=*n*<=≤<=100; 1<=≤<=*m*<=≤<=100). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100). | Output a single integer, representing the number of the last child. | [
"5 2\n1 3 1 4 2\n",
"6 4\n1 1 2 2 3 3\n"
] | [
"4\n",
"6\n"
] | Let's consider the first sample.
Firstly child 1 gets 2 candies and go home. Then child 2 gets 2 candies and go to the end of the line. Currently the line looks like [3, 4, 5, 2] (indices of the children in order of the line). Then child 3 gets 2 candies and go home, and then child 4 gets 2 candies and goes to the end of the line. Currently the line looks like [5, 2, 4]. Then child 5 gets 2 candies and goes home. Then child 2 gets two candies and goes home, and finally child 4 gets 2 candies and goes home.
Child 4 is the last one who goes home. | 500 | [
{
"input": "5 2\n1 3 1 4 2",
"output": "4"
},
{
"input": "6 4\n1 1 2 2 3 3",
"output": "6"
},
{
"input": "7 3\n6 1 5 4 2 3 1",
"output": "4"
},
{
"input": "10 5\n2 7 3 6 2 5 1 3 4 5",
"output": "4"
},
{
"input": "100 1\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": "100"
},
{
"input": "9 3\n9 5 2 3 7 1 8 4 6",
"output": "7"
},
{
"input": "20 10\n58 4 32 10 73 7 30 39 47 6 59 21 24 66 79 79 46 13 29 58",
"output": "16"
},
{
"input": "50 5\n89 56 3 2 40 37 56 52 83 59 43 83 43 59 29 74 22 58 53 41 53 67 78 30 57 32 58 29 95 46 45 85 60 49 41 82 8 71 52 40 45 26 6 71 84 91 4 93 40 54",
"output": "48"
},
{
"input": "50 1\n4 3 9 7 6 8 3 7 10 9 8 8 10 2 9 3 2 4 4 10 4 6 8 10 9 9 4 2 8 9 4 4 9 5 1 5 2 4 4 9 10 2 5 10 7 2 8 6 8 1",
"output": "44"
},
{
"input": "50 5\n3 9 10 8 3 3 4 6 8 2 9 9 3 1 2 10 6 8 7 2 7 4 2 7 5 10 2 2 2 5 10 5 6 6 8 7 10 4 3 2 10 8 6 6 8 6 4 4 1 3",
"output": "46"
},
{
"input": "50 2\n56 69 72 15 95 92 51 1 74 87 100 29 46 54 18 81 84 72 84 83 20 63 71 27 45 74 50 89 48 8 21 15 47 3 39 73 80 84 6 99 17 25 56 3 74 64 71 39 89 78",
"output": "40"
},
{
"input": "50 3\n31 39 64 16 86 3 1 9 25 54 98 42 20 3 49 41 73 37 55 62 33 77 64 22 33 82 26 13 10 13 7 40 48 18 46 79 94 72 19 12 11 61 16 37 10 49 14 94 48 69",
"output": "11"
},
{
"input": "50 100\n67 67 61 68 42 29 70 77 12 61 71 27 4 73 87 52 59 38 93 90 31 27 87 47 26 57 76 6 28 72 81 68 50 84 69 79 39 93 52 6 88 12 46 13 90 68 71 38 90 95",
"output": "50"
},
{
"input": "100 3\n4 14 20 11 19 11 14 20 5 7 6 12 11 17 5 11 7 6 2 10 13 5 12 8 5 17 20 18 7 19 11 7 7 20 20 8 10 17 17 19 20 5 15 16 19 7 11 16 4 17 2 10 1 20 20 16 19 9 9 11 5 7 12 9 9 6 20 18 13 19 8 4 8 1 2 4 10 11 15 14 1 7 17 12 13 19 12 2 3 14 15 15 5 17 14 12 17 14 16 9",
"output": "86"
},
{
"input": "100 5\n16 8 14 16 12 11 17 19 19 2 8 9 5 6 19 9 11 18 6 9 14 16 14 18 17 17 17 5 15 20 19 7 7 10 10 5 14 20 5 19 11 16 16 19 17 9 7 12 14 10 2 11 14 5 20 8 10 11 19 2 14 14 19 17 5 10 8 8 4 2 1 10 20 12 14 11 7 6 6 15 1 5 9 15 3 17 16 17 5 14 11 9 16 15 1 11 10 6 15 7",
"output": "93"
},
{
"input": "100 1\n58 94 18 50 17 14 96 62 83 80 75 5 9 22 25 41 3 96 74 45 66 37 2 37 13 85 68 54 77 11 85 19 25 21 52 59 90 61 72 89 82 22 10 16 3 68 61 29 55 76 28 85 65 76 27 3 14 10 56 37 86 18 35 38 56 68 23 88 33 38 52 87 55 83 94 34 100 41 83 56 91 77 32 74 97 13 67 31 57 81 53 39 5 88 46 1 79 4 49 42",
"output": "77"
},
{
"input": "100 2\n1 51 76 62 34 93 90 43 57 59 52 78 3 48 11 60 57 48 5 54 28 81 87 23 44 77 67 61 14 73 29 53 21 89 67 41 47 9 63 37 1 71 40 85 4 14 77 40 78 75 89 74 4 70 32 65 81 95 49 90 72 41 76 55 69 83 73 84 85 93 46 6 74 90 62 37 97 7 7 37 83 30 37 88 34 16 11 59 85 19 57 63 85 20 63 97 97 65 61 48",
"output": "97"
},
{
"input": "100 3\n30 83 14 55 61 66 34 98 90 62 89 74 45 93 33 31 75 35 82 100 63 69 48 18 99 2 36 71 14 30 70 76 96 85 97 90 49 36 6 76 37 94 70 3 63 73 75 48 39 29 13 2 46 26 9 56 1 18 54 53 85 34 2 12 1 93 75 67 77 77 14 26 33 25 55 9 57 70 75 6 87 66 18 3 41 69 73 24 49 2 20 72 39 58 91 54 74 56 66 78",
"output": "20"
},
{
"input": "100 4\n69 92 76 3 32 50 15 38 21 22 14 3 67 41 95 12 10 62 83 52 78 1 18 58 94 35 62 71 58 75 13 73 60 34 50 97 50 70 19 96 53 10 100 26 20 39 62 59 88 26 24 83 70 68 66 8 6 38 16 93 2 91 81 89 78 74 21 8 31 56 28 53 77 5 81 5 94 42 77 75 92 15 59 36 61 18 55 45 69 68 81 51 12 42 85 74 98 31 17 41",
"output": "97"
},
{
"input": "100 5\n2 72 10 60 6 50 72 34 97 77 35 43 80 64 40 53 46 6 90 22 29 70 26 68 52 19 72 88 83 18 55 32 99 81 11 21 39 42 41 63 60 97 30 23 55 78 89 35 24 50 99 52 27 76 24 8 20 27 51 37 17 82 69 18 46 19 26 77 52 83 76 65 43 66 84 84 13 30 66 88 84 23 37 1 17 26 11 50 73 56 54 37 40 29 35 8 1 39 50 82",
"output": "51"
},
{
"input": "100 7\n6 73 7 54 92 33 66 65 80 47 2 53 28 59 61 16 54 89 37 48 77 40 49 59 27 52 17 22 78 80 81 80 8 93 50 7 87 57 29 16 89 55 20 7 51 54 30 98 44 96 27 70 1 1 32 61 22 92 84 98 31 89 91 90 28 56 49 25 86 49 55 16 19 1 18 8 88 47 16 18 73 86 2 96 16 91 74 49 38 98 94 25 34 85 29 27 99 31 31 58",
"output": "97"
},
{
"input": "100 9\n36 4 45 16 19 6 10 87 44 82 71 49 70 35 83 19 40 76 45 94 44 96 10 54 82 77 86 63 11 37 21 3 15 89 80 88 89 16 72 23 25 9 51 25 10 45 96 5 6 18 51 31 42 57 41 51 42 15 89 61 45 82 16 48 61 67 19 40 9 33 90 36 78 36 79 79 16 10 83 87 9 22 84 12 23 76 36 14 2 81 56 33 56 23 57 84 76 55 35 88",
"output": "47"
},
{
"input": "100 10\n75 81 39 64 90 58 92 28 75 9 96 78 92 83 77 68 76 71 14 46 58 60 80 25 78 11 13 63 22 82 65 68 47 6 33 63 90 50 85 43 73 94 80 48 67 11 83 17 22 15 94 80 66 99 66 4 46 35 52 1 62 39 96 57 37 47 97 49 64 12 36 63 90 16 4 75 85 82 85 56 13 4 92 45 44 93 17 35 22 46 18 44 29 7 52 4 100 98 87 51",
"output": "98"
},
{
"input": "100 20\n21 19 61 70 54 97 98 14 61 72 25 94 24 56 55 25 12 80 76 11 35 17 80 26 11 94 52 47 84 61 10 2 74 25 10 21 2 79 55 50 30 75 10 64 44 5 60 96 52 16 74 41 20 77 20 44 8 86 74 36 49 61 99 13 54 64 19 99 50 43 12 73 48 48 83 55 72 73 63 81 30 27 95 9 97 82 24 3 89 90 33 14 47 88 22 78 12 75 58 67",
"output": "94"
},
{
"input": "100 30\n56 79 59 23 11 23 67 82 81 80 99 79 8 58 93 36 98 81 46 39 34 67 3 50 4 68 70 71 2 21 52 30 75 23 33 21 16 100 56 43 8 27 40 8 56 24 17 40 94 10 67 49 61 36 95 87 17 41 7 94 33 19 17 50 26 11 94 54 38 46 77 9 53 35 98 42 50 20 43 6 78 6 38 24 100 45 43 16 1 50 16 46 14 91 95 88 10 1 50 19",
"output": "95"
},
{
"input": "100 40\n86 11 97 17 38 95 11 5 13 83 67 75 50 2 46 39 84 68 22 85 70 23 64 46 59 93 39 80 35 78 93 21 83 19 64 1 49 59 99 83 44 81 70 58 15 82 83 47 55 65 91 10 2 92 4 77 37 32 12 57 78 11 42 8 59 21 96 69 61 30 44 29 12 70 91 14 10 83 11 75 14 10 19 39 8 98 5 81 66 66 79 55 36 29 22 45 19 24 55 49",
"output": "88"
},
{
"input": "100 50\n22 39 95 69 94 53 80 73 33 90 40 60 2 4 84 50 70 38 92 12 36 74 87 70 51 36 57 5 54 6 35 81 52 17 55 100 95 81 32 76 21 1 100 1 95 1 40 91 98 59 84 19 11 51 79 19 47 86 45 15 62 2 59 77 31 68 71 92 17 33 10 33 85 57 5 2 88 97 91 99 63 20 63 54 79 93 24 62 46 27 30 87 3 64 95 88 16 50 79 1",
"output": "99"
},
{
"input": "100 70\n61 48 89 17 97 6 93 13 64 50 66 88 24 52 46 99 6 65 93 64 82 37 57 41 47 1 84 5 97 83 79 46 16 35 40 7 64 15 44 96 37 17 30 92 51 67 26 3 14 56 27 68 66 93 36 39 51 6 40 55 79 26 71 54 8 48 18 2 71 12 55 60 29 37 31 97 26 37 25 68 67 70 3 87 100 41 5 82 65 92 24 66 76 48 89 8 40 93 31 95",
"output": "100"
},
{
"input": "100 90\n87 32 30 15 10 52 93 63 84 1 82 41 27 51 75 32 42 94 39 53 70 13 4 22 99 35 44 38 5 23 18 100 61 80 9 12 42 93 9 77 3 7 60 95 66 78 95 42 69 8 1 88 93 66 96 20 76 63 15 36 92 52 2 72 36 57 48 63 29 20 74 88 49 47 81 61 94 74 70 93 47 3 19 52 59 41 5 40 22 3 76 97 91 37 95 88 91 99 76 15",
"output": "98"
},
{
"input": "100 100\n79 75 7 28 6 96 38 35 57 95 41 74 24 96 32 78 81 13 63 84 24 95 3 23 66 1 60 6 96 49 41 5 14 18 31 97 66 19 49 89 49 70 51 28 20 99 18 1 28 77 24 46 69 21 40 32 31 66 28 6 66 97 9 16 70 90 91 30 34 82 93 41 65 11 39 52 1 88 63 43 80 50 60 49 28 56 18 76 24 57 74 1 28 99 36 35 79 54 18 16",
"output": "100"
},
{
"input": "1 3\n5",
"output": "1"
},
{
"input": "1 1\n100",
"output": "1"
},
{
"input": "2 3\n4 2",
"output": "1"
},
{
"input": "2 5\n99 97",
"output": "2"
},
{
"input": "3 4\n7 5 2",
"output": "2"
},
{
"input": "3 50\n47 86 51",
"output": "3"
},
{
"input": "5 100\n82 100 85 1 37",
"output": "5"
},
{
"input": "5 20\n40 39 21 5 20",
"output": "3"
},
{
"input": "1 27\n81",
"output": "1"
},
{
"input": "20 13\n7 8 29 83 74 28 93 85 7 8 3 9 8 70 49 50 39 41 57 1",
"output": "7"
},
{
"input": "2 1\n100 2",
"output": "1"
},
{
"input": "2 2\n6 4",
"output": "1"
},
{
"input": "5 2\n6 4 4 1 1",
"output": "1"
},
{
"input": "1 4\n3",
"output": "1"
},
{
"input": "3 2\n1 5 3",
"output": "2"
},
{
"input": "3 1\n3 2 2",
"output": "1"
},
{
"input": "3 1\n2 3 2",
"output": "2"
},
{
"input": "5 1\n5 1 1 1 1",
"output": "1"
},
{
"input": "2 3\n7 4",
"output": "1"
}
] | 1,665,760,316 | 2,147,483,647 | PyPy 3-64 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | from collections import deque
N , m = map(int,input().split(' '))
A = list(map(int,input().split()))
q = deque()
for i in range(N):
cur_ele = [ A[i] , i+1]
q.append(cur_ele)
while len(q) > 1:
val = q[0]
if val[0] <= m:
q.popleft()
else:
x = q.popleft()
newval = [x[0] - m , x[1] ]
q.append(newval)
return q[1] | Title: Jzzhu and Children
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* children in Jzzhu's school. Jzzhu is going to give some candies to them. Let's number all the children from 1 to *n*. The *i*-th child wants to get at least *a**i* candies.
Jzzhu asks children to line up. Initially, the *i*-th child stands at the *i*-th place of the line. Then Jzzhu start distribution of the candies. He follows the algorithm:
1. Give *m* candies to the first child of the line. 1. If this child still haven't got enough candies, then the child goes to the end of the line, else the child go home. 1. Repeat the first two steps while the line is not empty.
Consider all the children in the order they go home. Jzzhu wants to know, which child will be the last in this order?
Input Specification:
The first line contains two integers *n*,<=*m* (1<=≤<=*n*<=≤<=100; 1<=≤<=*m*<=≤<=100). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100).
Output Specification:
Output a single integer, representing the number of the last child.
Demo Input:
['5 2\n1 3 1 4 2\n', '6 4\n1 1 2 2 3 3\n']
Demo Output:
['4\n', '6\n']
Note:
Let's consider the first sample.
Firstly child 1 gets 2 candies and go home. Then child 2 gets 2 candies and go to the end of the line. Currently the line looks like [3, 4, 5, 2] (indices of the children in order of the line). Then child 3 gets 2 candies and go home, and then child 4 gets 2 candies and goes to the end of the line. Currently the line looks like [5, 2, 4]. Then child 5 gets 2 candies and goes home. Then child 2 gets two candies and goes home, and finally child 4 gets 2 candies and goes home.
Child 4 is the last one who goes home. | ```python
from collections import deque
N , m = map(int,input().split(' '))
A = list(map(int,input().split()))
q = deque()
for i in range(N):
cur_ele = [ A[i] , i+1]
q.append(cur_ele)
while len(q) > 1:
val = q[0]
if val[0] <= m:
q.popleft()
else:
x = q.popleft()
newval = [x[0] - m , x[1] ]
q.append(newval)
return q[1]
``` | -1 |
|
69 | A | Young Physicist | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Young Physicist | 2 | 256 | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces. | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | [
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10\n25 -33 43\n-27 -42 28\n-35 -20 19\n41 -42 -1\n49 -39 -4\n-49 -22 7\n-19 29 41\n8 -27 -43\n8 34 9\n-11 -3 33",
"output": "NO"
},
{
"input": "10\n-6 21 18\n20 -11 -8\n37 -11 41\n-5 8 33\n29 23 32\n30 -33 -11\n39 -49 -36\n28 34 -49\n22 29 -34\n-18 -6 7",
"output": "NO"
},
{
"input": "10\n47 -2 -27\n0 26 -14\n5 -12 33\n2 18 3\n45 -30 -49\n4 -18 8\n-46 -44 -41\n-22 -10 -40\n-35 -21 26\n33 20 38",
"output": "NO"
},
{
"input": "13\n-3 -36 -46\n-11 -50 37\n42 -11 -15\n9 42 44\n-29 -12 24\n3 9 -40\n-35 13 50\n14 43 18\n-13 8 24\n-48 -15 10\n50 9 -50\n21 0 -50\n0 0 -6",
"output": "YES"
},
{
"input": "14\n43 23 17\n4 17 44\n5 -5 -16\n-43 -7 -6\n47 -48 12\n50 47 -45\n2 14 43\n37 -30 15\n4 -17 -11\n17 9 -45\n-50 -3 -8\n-50 0 0\n-50 0 0\n-16 0 0",
"output": "YES"
},
{
"input": "13\n29 49 -11\n38 -11 -20\n25 1 -40\n-11 28 11\n23 -19 1\n45 -41 -17\n-3 0 -19\n-13 -33 49\n-30 0 28\n34 17 45\n-50 9 -27\n-50 0 0\n-37 0 0",
"output": "YES"
},
{
"input": "12\n3 28 -35\n-32 -44 -17\n9 -25 -6\n-42 -22 20\n-19 15 38\n-21 38 48\n-1 -37 -28\n-10 -13 -50\n-5 21 29\n34 28 50\n50 11 -49\n34 0 0",
"output": "YES"
},
{
"input": "37\n-64 -79 26\n-22 59 93\n-5 39 -12\n77 -9 76\n55 -86 57\n83 100 -97\n-70 94 84\n-14 46 -94\n26 72 35\n14 78 -62\n17 82 92\n-57 11 91\n23 15 92\n-80 -1 1\n12 39 18\n-23 -99 -75\n-34 50 19\n-39 84 -7\n45 -30 -39\n-60 49 37\n45 -16 -72\n33 -51 -56\n-48 28 5\n97 91 88\n45 -82 -11\n-21 -15 -90\n-53 73 -26\n-74 85 -90\n-40 23 38\n100 -13 49\n32 -100 -100\n0 -100 -70\n0 -100 0\n0 -100 0\n0 -100 0\n0 -100 0\n0 -37 0",
"output": "YES"
},
{
"input": "4\n68 3 100\n68 21 -100\n-100 -24 0\n-36 0 0",
"output": "YES"
},
{
"input": "33\n-1 -46 -12\n45 -16 -21\n-11 45 -21\n-60 -42 -93\n-22 -45 93\n37 96 85\n-76 26 83\n-4 9 55\n7 -52 -9\n66 8 -85\n-100 -54 11\n-29 59 74\n-24 12 2\n-56 81 85\n-92 69 -52\n-26 -97 91\n54 59 -51\n58 21 -57\n7 68 56\n-47 -20 -51\n-59 77 -13\n-85 27 91\n79 60 -56\n66 -80 5\n21 -99 42\n-31 -29 98\n66 93 76\n-49 45 61\n100 -100 -100\n100 -100 -100\n66 -75 -100\n0 0 -100\n0 0 -87",
"output": "YES"
},
{
"input": "3\n1 2 3\n3 2 1\n0 0 0",
"output": "NO"
},
{
"input": "2\n5 -23 12\n0 0 0",
"output": "NO"
},
{
"input": "1\n0 0 0",
"output": "YES"
},
{
"input": "1\n1 -2 0",
"output": "NO"
},
{
"input": "2\n-23 77 -86\n23 -77 86",
"output": "YES"
},
{
"input": "26\n86 7 20\n-57 -64 39\n-45 6 -93\n-44 -21 100\n-11 -49 21\n73 -71 -80\n-2 -89 56\n-65 -2 7\n5 14 84\n57 41 13\n-12 69 54\n40 -25 27\n-17 -59 0\n64 -91 -30\n-53 9 42\n-54 -8 14\n-35 82 27\n-48 -59 -80\n88 70 79\n94 57 97\n44 63 25\n84 -90 -40\n-100 100 -100\n-92 100 -100\n0 10 -100\n0 0 -82",
"output": "YES"
},
{
"input": "42\n11 27 92\n-18 -56 -57\n1 71 81\n33 -92 30\n82 83 49\n-87 -61 -1\n-49 45 49\n73 26 15\n-22 22 -77\n29 -93 87\n-68 44 -90\n-4 -84 20\n85 67 -6\n-39 26 77\n-28 -64 20\n65 -97 24\n-72 -39 51\n35 -75 -91\n39 -44 -8\n-25 -27 -57\n91 8 -46\n-98 -94 56\n94 -60 59\n-9 -95 18\n-53 -37 98\n-8 -94 -84\n-52 55 60\n15 -14 37\n65 -43 -25\n94 12 66\n-8 -19 -83\n29 81 -78\n-58 57 33\n24 86 -84\n-53 32 -88\n-14 7 3\n89 97 -53\n-5 -28 -91\n-100 100 -6\n-84 100 0\n0 100 0\n0 70 0",
"output": "YES"
},
{
"input": "3\n96 49 -12\n2 -66 28\n-98 17 -16",
"output": "YES"
},
{
"input": "5\n70 -46 86\n-100 94 24\n-27 63 -63\n57 -100 -47\n0 -11 0",
"output": "YES"
},
{
"input": "18\n-86 -28 70\n-31 -89 42\n31 -48 -55\n95 -17 -43\n24 -95 -85\n-21 -14 31\n68 -18 81\n13 31 60\n-15 28 99\n-42 15 9\n28 -61 -62\n-16 71 29\n-28 75 -48\n-77 -67 36\n-100 83 89\n100 100 -100\n57 34 -100\n0 0 -53",
"output": "YES"
},
{
"input": "44\n52 -54 -29\n-82 -5 -94\n-54 43 43\n91 16 71\n7 80 -91\n3 15 29\n-99 -6 -77\n-3 -77 -64\n73 67 34\n25 -10 -18\n-29 91 63\n-72 86 -16\n-68 85 -81\n-3 36 44\n-74 -14 -80\n34 -96 -97\n-76 -78 -33\n-24 44 -58\n98 12 77\n95 -63 -6\n-51 3 -90\n-92 -10 72\n7 3 -68\n57 -53 71\n29 57 -48\n35 -60 10\n79 -70 -61\n-20 77 55\n-86 -15 -35\n84 -88 -18\n100 -42 77\n-20 46 8\n-41 -43 -65\n38 -98 -23\n-100 65 45\n-7 -91 -63\n46 88 -85\n48 59 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 1",
"output": "YES"
},
{
"input": "18\n-14 -64 -91\n-8 -66 -86\n-23 92 -40\n6 -3 -53\n57 41 78\n-79 42 -22\n-88 -17 45\n4 -45 44\n83 -18 -25\n34 86 -92\n75 -30 12\n44 99 11\n-67 -13 72\n22 83 -56\n-37 71 72\n-9 -100 100\n0 -100 31\n0 -58 0",
"output": "YES"
},
{
"input": "23\n-70 37 78\n42 84 6\n28 -94 -24\n-49 76 95\n-67 18 84\n-53 78 -5\n65 -63 -64\n-66 -64 -69\n81 -93 95\n10 52 -79\n-89 -61 -64\n-64 -47 43\n-81 -35 55\n80 82 73\n-60 -81 -18\n49 -10 -19\n-58 70 12\n-24 -15 -93\n98 -93 -54\n-28 -75 11\n100 100 -63\n100 100 0\n56 34 0",
"output": "YES"
},
{
"input": "3\n0 2 -2\n1 -1 3\n-3 0 0",
"output": "NO"
}
] | 1,604,612,173 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 218 | 0 | n=int(input())
x=0
y=0
z=0
for _ in range(n):
xi,yi,zi=map(int,input().split())
x+=xi
y+=yi
z+=zi
print('YNEOS'[x+y+z>0::2]) | Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces.
Input Specification:
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100).
Output Specification:
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
Demo Input:
['3\n4 1 7\n-2 4 -1\n1 -5 -3\n', '3\n3 -1 7\n-5 2 -4\n2 -1 -3\n']
Demo Output:
['NO', 'YES']
Note:
none | ```python
n=int(input())
x=0
y=0
z=0
for _ in range(n):
xi,yi,zi=map(int,input().split())
x+=xi
y+=yi
z+=zi
print('YNEOS'[x+y+z>0::2])
``` | 0 |
1 | A | Theatre Square | PROGRAMMING | 1,000 | [
"math"
] | A. Theatre Square | 1 | 256 | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square. | The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). | Write the needed number of flagstones. | [
"6 6 4\n"
] | [
"4\n"
] | none | 0 | [
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3",
"output": "1"
},
{
"input": "2 3 4",
"output": "1"
},
{
"input": "1000000000 1000000000 1",
"output": "1000000000000000000"
},
{
"input": "12 13 4",
"output": "12"
},
{
"input": "222 332 5",
"output": "3015"
},
{
"input": "1000 1000 10",
"output": "10000"
},
{
"input": "1001 1000 10",
"output": "10100"
},
{
"input": "100 10001 1000000000",
"output": "1"
},
{
"input": "1000000000 1000000000 1000000000",
"output": "1"
},
{
"input": "1000000000 1000000000 999999999",
"output": "4"
},
{
"input": "1000000000 1000000000 192",
"output": "27126743055556"
},
{
"input": "1000000000 987654321 1",
"output": "987654321000000000"
},
{
"input": "456784567 1000000000 51",
"output": "175618850864484"
},
{
"input": "39916800 134217728 40320",
"output": "3295710"
}
] | 1,661,008,244 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | class Solution:
def numberOfSquares(self,m: int, n: int, a: int)->int:
widthCount=m//a
columnCount = n//a
if m%a != 0:
widthCount+=1
if n%a != 0:
columnCount+=1
return widthCount*columnCount
| Title: Theatre Square
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square.
Input Specification:
The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109).
Output Specification:
Write the needed number of flagstones.
Demo Input:
['6 6 4\n']
Demo Output:
['4\n']
Note:
none | ```python
class Solution:
def numberOfSquares(self,m: int, n: int, a: int)->int:
widthCount=m//a
columnCount = n//a
if m%a != 0:
widthCount+=1
if n%a != 0:
columnCount+=1
return widthCount*columnCount
``` | 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,696,357,108 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 9 | 62 | 11,059,200 | n=int(input())
x=len(input().split())-2
if x <= 0:
print(0)
else:
print(x) | 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())
x=len(input().split())-2
if x <= 0:
print(0)
else:
print(x)
``` | 0 |
|
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,664,025,238 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 31 | 0 | num=int(input())
l=list(map(int,input().split()))
while(0 in l):
l.remove(0)
l=set(l)
print(len(l))
| Title: Olympiad
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The recent All-Berland Olympiad in Informatics featured *n* participants with each scoring a certain amount of points.
As the head of the programming committee, you are to determine the set of participants to be awarded with 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
num=int(input())
l=list(map(int,input().split()))
while(0 in l):
l.remove(0)
l=set(l)
print(len(l))
``` | 3 |
|
1,000 | B | Light It Up | PROGRAMMING | 1,500 | [
"greedy"
] | null | null | Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment $0$ and turn power off at moment $M$. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, some program is already installed into the lamp.
The lamp allows only good programs. Good program can be represented as a non-empty array $a$, where $0 < a_1 < a_2 < \dots < a_{|a|} < M$. All $a_i$ must be integers. Of course, preinstalled program is a good program.
The lamp follows program $a$ in next manner: at moment $0$ turns power and light on. Then at moment $a_i$ the lamp flips its state to opposite (if it was lit, it turns off, and vice versa). The state of the lamp flips instantly: for example, if you turn the light off at moment $1$ and then do nothing, the total time when the lamp is lit will be $1$. Finally, at moment $M$ the lamp is turning its power off regardless of its state.
Since you are not among those people who read instructions, and you don't understand the language it's written in, you realize (after some testing) the only possible way to alter the preinstalled program. You can insert at most one element into the program $a$, so it still should be a good program after alteration. Insertion can be done between any pair of consecutive elements of $a$, or even at the begining or at the end of $a$.
Find such a way to alter the program that the total time when the lamp is lit is maximum possible. Maybe you should leave program untouched. If the lamp is lit from $x$ till moment $y$, then its lit for $y - x$ units of time. Segments of time when the lamp is lit are summed up. | First line contains two space separated integers $n$ and $M$ ($1 \le n \le 10^5$, $2 \le M \le 10^9$) — the length of program $a$ and the moment when power turns off.
Second line contains $n$ space separated integers $a_1, a_2, \dots, a_n$ ($0 < a_1 < a_2 < \dots < a_n < M$) — initially installed program $a$. | Print the only integer — maximum possible total time when the lamp is lit. | [
"3 10\n4 6 7\n",
"2 12\n1 10\n",
"2 7\n3 4\n"
] | [
"8\n",
"9\n",
"6\n"
] | In the first example, one of possible optimal solutions is to insert value $x = 3$ before $a_1$, so program will be $[3, 4, 6, 7]$ and time of lamp being lit equals $(3 - 0) + (6 - 4) + (10 - 7) = 8$. Other possible solution is to insert $x = 5$ in appropriate place.
In the second example, there is only one optimal solution: to insert $x = 2$ between $a_1$ and $a_2$. Program will become $[1, 2, 10]$, and answer will be $(1 - 0) + (10 - 2) = 9$.
In the third example, optimal answer is to leave program untouched, so answer will be $(3 - 0) + (7 - 4) = 6$. | 0 | [
{
"input": "3 10\n4 6 7",
"output": "8"
},
{
"input": "2 12\n1 10",
"output": "9"
},
{
"input": "2 7\n3 4",
"output": "6"
},
{
"input": "1 2\n1",
"output": "1"
},
{
"input": "5 10\n1 3 5 6 8",
"output": "6"
},
{
"input": "7 1000000000\n1 10001 10011 20011 20021 40021 40031",
"output": "999999969"
},
{
"input": "7 1000000000\n3 10001 10011 20011 20021 40021 40031",
"output": "999999969"
},
{
"input": "1 10\n1",
"output": "9"
},
{
"input": "1 10000000\n1",
"output": "9999999"
},
{
"input": "1 8\n1",
"output": "7"
},
{
"input": "7 17\n1 5 9 10 11 14 16",
"output": "9"
},
{
"input": "4 17\n1 5 9 10",
"output": "12"
},
{
"input": "5 12\n1 2 3 4 5",
"output": "9"
},
{
"input": "2 1000000000\n100 111",
"output": "999999989"
},
{
"input": "3 90591\n90579 90580 90581",
"output": "90589"
},
{
"input": "5 16\n1 2 3 4 5",
"output": "13"
},
{
"input": "6 981231233\n1 6 15 30 130 1875",
"output": "981229468"
},
{
"input": "1 3\n1",
"output": "2"
},
{
"input": "3 12\n4 7 11",
"output": "8"
},
{
"input": "1 100000\n1",
"output": "99999"
},
{
"input": "2 5\n1 3",
"output": "3"
},
{
"input": "1 1000000000\n1",
"output": "999999999"
},
{
"input": "1 1000000000\n999999999",
"output": "999999999"
},
{
"input": "3 4\n1 2 3",
"output": "2"
},
{
"input": "3 5\n1 2 3",
"output": "3"
},
{
"input": "1 4\n2",
"output": "3"
},
{
"input": "3 5\n1 3 4",
"output": "3"
},
{
"input": "9 20\n5 9 11 12 14 15 16 17 19",
"output": "12"
},
{
"input": "2 4\n1 2",
"output": "3"
},
{
"input": "1 10\n2",
"output": "9"
},
{
"input": "2 6\n2 4",
"output": "4"
},
{
"input": "2 4\n1 3",
"output": "2"
},
{
"input": "3 6\n1 2 4",
"output": "4"
},
{
"input": "7 9863\n65 96 97 98 101 112 1115",
"output": "9819"
}
] | 1,666,079,417 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 19 | 1,000 | 8,704,000 | import copy
a=input().split()
b=list(map(int,input().split()))
b.insert(0,0)
b.append(int(a[1]))
c=int(a[0])
d=0
i=1
e=copy.copy(b)
f=[]
while i<=c:
if (e[i]+1)!=e[i+1]:
e.insert(i+1,e[i]+1)
for m in range(0,len(e),2):
if m==len(e)-1:
break
else:
d+=e[m+1]-e[m]
f+=[d]
d=0
e=copy.copy(b)
i+=1
for m in range(0,len(e),2):
if m==len(e)-1:
break
else:
d+=e[m+1]-e[m]
f+=[d]
print(max(x for x in f))
| Title: Light It Up
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment $0$ and turn power off at moment $M$. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, some program is already installed into the lamp.
The lamp allows only good programs. Good program can be represented as a non-empty array $a$, where $0 < a_1 < a_2 < \dots < a_{|a|} < M$. All $a_i$ must be integers. Of course, preinstalled program is a good program.
The lamp follows program $a$ in next manner: at moment $0$ turns power and light on. Then at moment $a_i$ the lamp flips its state to opposite (if it was lit, it turns off, and vice versa). The state of the lamp flips instantly: for example, if you turn the light off at moment $1$ and then do nothing, the total time when the lamp is lit will be $1$. Finally, at moment $M$ the lamp is turning its power off regardless of its state.
Since you are not among those people who read instructions, and you don't understand the language it's written in, you realize (after some testing) the only possible way to alter the preinstalled program. You can insert at most one element into the program $a$, so it still should be a good program after alteration. Insertion can be done between any pair of consecutive elements of $a$, or even at the begining or at the end of $a$.
Find such a way to alter the program that the total time when the lamp is lit is maximum possible. Maybe you should leave program untouched. If the lamp is lit from $x$ till moment $y$, then its lit for $y - x$ units of time. Segments of time when the lamp is lit are summed up.
Input Specification:
First line contains two space separated integers $n$ and $M$ ($1 \le n \le 10^5$, $2 \le M \le 10^9$) — the length of program $a$ and the moment when power turns off.
Second line contains $n$ space separated integers $a_1, a_2, \dots, a_n$ ($0 < a_1 < a_2 < \dots < a_n < M$) — initially installed program $a$.
Output Specification:
Print the only integer — maximum possible total time when the lamp is lit.
Demo Input:
['3 10\n4 6 7\n', '2 12\n1 10\n', '2 7\n3 4\n']
Demo Output:
['8\n', '9\n', '6\n']
Note:
In the first example, one of possible optimal solutions is to insert value $x = 3$ before $a_1$, so program will be $[3, 4, 6, 7]$ and time of lamp being lit equals $(3 - 0) + (6 - 4) + (10 - 7) = 8$. Other possible solution is to insert $x = 5$ in appropriate place.
In the second example, there is only one optimal solution: to insert $x = 2$ between $a_1$ and $a_2$. Program will become $[1, 2, 10]$, and answer will be $(1 - 0) + (10 - 2) = 9$.
In the third example, optimal answer is to leave program untouched, so answer will be $(3 - 0) + (7 - 4) = 6$. | ```python
import copy
a=input().split()
b=list(map(int,input().split()))
b.insert(0,0)
b.append(int(a[1]))
c=int(a[0])
d=0
i=1
e=copy.copy(b)
f=[]
while i<=c:
if (e[i]+1)!=e[i+1]:
e.insert(i+1,e[i]+1)
for m in range(0,len(e),2):
if m==len(e)-1:
break
else:
d+=e[m+1]-e[m]
f+=[d]
d=0
e=copy.copy(b)
i+=1
for m in range(0,len(e),2):
if m==len(e)-1:
break
else:
d+=e[m+1]-e[m]
f+=[d]
print(max(x for x in f))
``` | 0 |
|
1,009 | B | Minimum Ternary String | PROGRAMMING | 1,400 | [
"greedy",
"implementation"
] | null | null | You are given a ternary string (it is a string which consists only of characters '0', '1' and '2').
You can swap any two adjacent (consecutive) characters '0' and '1' (i.e. replace "01" with "10" or vice versa) or any two adjacent (consecutive) characters '1' and '2' (i.e. replace "12" with "21" or vice versa).
For example, for string "010210" we can perform the following moves:
- "010210" $\rightarrow$ "100210"; - "010210" $\rightarrow$ "001210"; - "010210" $\rightarrow$ "010120"; - "010210" $\rightarrow$ "010201".
Note than you cannot swap "02" $\rightarrow$ "20" and vice versa. You cannot perform any other operations with the given string excluding described above.
You task is to obtain the minimum possible (lexicographically) string by using these swaps arbitrary number of times (possibly, zero).
String $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. | The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (inclusive). | Print a single string — the minimum possible (lexicographically) string you can obtain by using the swaps described above arbitrary number of times (possibly, zero). | [
"100210\n",
"11222121\n",
"20\n"
] | [
"001120\n",
"11112222\n",
"20\n"
] | none | 0 | [
{
"input": "100210",
"output": "001120"
},
{
"input": "11222121",
"output": "11112222"
},
{
"input": "20",
"output": "20"
},
{
"input": "1002",
"output": "0012"
},
{
"input": "10",
"output": "01"
},
{
"input": "000021",
"output": "000012"
},
{
"input": "021",
"output": "012"
},
{
"input": "2",
"output": "2"
},
{
"input": "201",
"output": "120"
},
{
"input": "2112120",
"output": "1112220"
},
{
"input": "102",
"output": "012"
},
{
"input": "202",
"output": "202"
},
{
"input": "220201",
"output": "122020"
},
{
"input": "12",
"output": "12"
},
{
"input": "100022202",
"output": "000122202"
},
{
"input": "01",
"output": "01"
},
{
"input": "1",
"output": "1"
}
] | 1,585,477,097 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 3 | 1,000 | 10,444,800 | s = input()
n = len(s)
ans = ""
flag = 0
for i in range(n) :
if s[i] == '1' :
ans += '1'
for i in range(n):
if s[i] == '1' :
continue
elif s[i] == '2':
ans += '2'
flag = 1
else:
if flag == 0 :
ans = '0' + ans
else:
ans += '0'
print(ans)
| Title: Minimum Ternary String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a ternary string (it is a string which consists only of characters '0', '1' and '2').
You can swap any two adjacent (consecutive) characters '0' and '1' (i.e. replace "01" with "10" or vice versa) or any two adjacent (consecutive) characters '1' and '2' (i.e. replace "12" with "21" or vice versa).
For example, for string "010210" we can perform the following moves:
- "010210" $\rightarrow$ "100210"; - "010210" $\rightarrow$ "001210"; - "010210" $\rightarrow$ "010120"; - "010210" $\rightarrow$ "010201".
Note than you cannot swap "02" $\rightarrow$ "20" and vice versa. You cannot perform any other operations with the given string excluding described above.
You task is to obtain the minimum possible (lexicographically) string by using these swaps arbitrary number of times (possibly, zero).
String $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$.
Input Specification:
The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (inclusive).
Output Specification:
Print a single string — the minimum possible (lexicographically) string you can obtain by using the swaps described above arbitrary number of times (possibly, zero).
Demo Input:
['100210\n', '11222121\n', '20\n']
Demo Output:
['001120\n', '11112222\n', '20\n']
Note:
none | ```python
s = input()
n = len(s)
ans = ""
flag = 0
for i in range(n) :
if s[i] == '1' :
ans += '1'
for i in range(n):
if s[i] == '1' :
continue
elif s[i] == '2':
ans += '2'
flag = 1
else:
if flag == 0 :
ans = '0' + ans
else:
ans += '0'
print(ans)
``` | 0 |
|
873 | A | Chores | PROGRAMMING | 800 | [
"implementation"
] | null | null | Luba has to do *n* chores today. *i*-th chore takes *a**i* units of time to complete. It is guaranteed that for every the condition *a**i*<=≥<=*a**i*<=-<=1 is met, so the sequence is sorted.
Also Luba can work really hard on some chores. She can choose not more than *k* any chores and do each of them in *x* units of time instead of *a**i* ().
Luba is very responsible, so she has to do all *n* chores, and now she wants to know the minimum time she needs to do everything. Luba cannot do two chores simultaneously. | The first line contains three integers *n*,<=*k*,<=*x* (1<=≤<=*k*<=≤<=*n*<=≤<=100,<=1<=≤<=*x*<=≤<=99) — the number of chores Luba has to do, the number of chores she can do in *x* units of time, and the number *x* itself.
The second line contains *n* integer numbers *a**i* (2<=≤<=*a**i*<=≤<=100) — the time Luba has to spend to do *i*-th chore.
It is guaranteed that , and for each *a**i*<=≥<=*a**i*<=-<=1. | Print one number — minimum time Luba needs to do all *n* chores. | [
"4 2 2\n3 6 7 10\n",
"5 2 1\n100 100 100 100 100\n"
] | [
"13\n",
"302\n"
] | In the first example the best option would be to do the third and the fourth chore, spending *x* = 2 time on each instead of *a*<sub class="lower-index">3</sub> and *a*<sub class="lower-index">4</sub>, respectively. Then the answer is 3 + 6 + 2 + 2 = 13.
In the second example Luba can choose any two chores to spend *x* time on them instead of *a*<sub class="lower-index">*i*</sub>. So the answer is 100·3 + 2·1 = 302. | 0 | [
{
"input": "4 2 2\n3 6 7 10",
"output": "13"
},
{
"input": "5 2 1\n100 100 100 100 100",
"output": "302"
},
{
"input": "1 1 1\n100",
"output": "1"
},
{
"input": "100 1 99\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": "9999"
},
{
"input": "100 100 1\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 50 50\n51 51 52 53 55 55 55 55 56 56 56 57 57 58 58 59 59 59 60 60 61 61 62 62 63 64 64 64 64 65 65 65 65 66 66 66 67 68 68 68 69 69 70 70 70 70 71 71 71 71 71 71 72 72 76 76 76 76 77 79 79 81 81 81 81 82 82 82 82 83 84 85 86 87 87 88 88 88 89 89 89 90 90 90 91 91 91 92 92 93 95 95 96 96 96 97 97 98 99 100",
"output": "5618"
},
{
"input": "100 100 1\n2 4 4 4 5 5 5 6 10 10 11 11 12 12 13 13 13 14 17 18 20 20 21 21 22 22 23 24 24 25 26 29 29 32 32 34 34 35 38 39 39 40 40 42 42 43 45 47 48 49 51 52 52 54 57 59 59 60 61 61 62 63 63 64 65 65 68 70 70 72 74 75 75 76 76 77 77 78 78 78 79 80 81 82 82 83 83 83 84 89 90 92 92 93 94 96 96 97 98 99",
"output": "100"
},
{
"input": "100 1 1\n3 3 5 7 8 8 8 9 9 9 11 13 14 15 18 18 19 20 21 22 22 25 27 27 29 31 32 33 33 34 36 37 37 38 40 42 44 44 46 47 47 48 48 48 50 50 51 51 54 54 54 55 55 56 56 56 60 61 62 62 63 64 65 65 68 70 70 71 71 71 71 75 75 76 76 79 79 79 79 81 81 82 82 86 86 86 86 88 90 90 92 96 97 97 98 98 98 98 100 100",
"output": "5202"
},
{
"input": "100 50 49\n50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51",
"output": "4950"
},
{
"input": "100 50 1\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3",
"output": "151"
},
{
"input": "100 1 1\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2",
"output": "199"
}
] | 1,507,955,435 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 46 | 0 | n = int(input()) # Number of Chores
k = int(input()) # Number of Chores she can do in x time
x = int(input())
total_time = x*k
for i in range(0, n-k):
total_time += int(input())
for i in range(0, k):
int(input())
print(total_time) | Title: Chores
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Luba has to do *n* chores today. *i*-th chore takes *a**i* units of time to complete. It is guaranteed that for every the condition *a**i*<=≥<=*a**i*<=-<=1 is met, so the sequence is sorted.
Also Luba can work really hard on some chores. She can choose not more than *k* any chores and do each of them in *x* units of time instead of *a**i* ().
Luba is very responsible, so she has to do all *n* chores, and now she wants to know the minimum time she needs to do everything. Luba cannot do two chores simultaneously.
Input Specification:
The first line contains three integers *n*,<=*k*,<=*x* (1<=≤<=*k*<=≤<=*n*<=≤<=100,<=1<=≤<=*x*<=≤<=99) — the number of chores Luba has to do, the number of chores she can do in *x* units of time, and the number *x* itself.
The second line contains *n* integer numbers *a**i* (2<=≤<=*a**i*<=≤<=100) — the time Luba has to spend to do *i*-th chore.
It is guaranteed that , and for each *a**i*<=≥<=*a**i*<=-<=1.
Output Specification:
Print one number — minimum time Luba needs to do all *n* chores.
Demo Input:
['4 2 2\n3 6 7 10\n', '5 2 1\n100 100 100 100 100\n']
Demo Output:
['13\n', '302\n']
Note:
In the first example the best option would be to do the third and the fourth chore, spending *x* = 2 time on each instead of *a*<sub class="lower-index">3</sub> and *a*<sub class="lower-index">4</sub>, respectively. Then the answer is 3 + 6 + 2 + 2 = 13.
In the second example Luba can choose any two chores to spend *x* time on them instead of *a*<sub class="lower-index">*i*</sub>. So the answer is 100·3 + 2·1 = 302. | ```python
n = int(input()) # Number of Chores
k = int(input()) # Number of Chores she can do in x time
x = int(input())
total_time = x*k
for i in range(0, n-k):
total_time += int(input())
for i in range(0, k):
int(input())
print(total_time)
``` | -1 |
|
136 | A | Presents | PROGRAMMING | 800 | [
"implementation"
] | null | null | Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited *n* his friends there.
If there's one thing Petya likes more that receiving gifts, that's watching others giving gifts to somebody else. Thus, he safely hid the laptop until the next New Year and made up his mind to watch his friends exchanging gifts while he does not participate in the process. He numbered all his friends with integers from 1 to *n*. Petya remembered that a friend number *i* gave a gift to a friend number *p**i*. He also remembered that each of his friends received exactly one gift.
Now Petya wants to know for each friend *i* the number of a friend who has given him a gift. | The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the quantity of friends Petya invited to the party. The second line contains *n* space-separated integers: the *i*-th number is *p**i* — the number of a friend who gave a gift to friend number *i*. It is guaranteed that each friend received exactly one gift. It is possible that some friends do not share Petya's ideas of giving gifts to somebody else. Those friends gave the gifts to themselves. | Print *n* space-separated integers: the *i*-th number should equal the number of the friend who gave a gift to friend number *i*. | [
"4\n2 3 4 1\n",
"3\n1 3 2\n",
"2\n1 2\n"
] | [
"4 1 2 3\n",
"1 3 2\n",
"1 2\n"
] | none | 500 | [
{
"input": "4\n2 3 4 1",
"output": "4 1 2 3"
},
{
"input": "3\n1 3 2",
"output": "1 3 2"
},
{
"input": "2\n1 2",
"output": "1 2"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "10\n1 3 2 6 4 5 7 9 8 10",
"output": "1 3 2 5 6 4 7 9 8 10"
},
{
"input": "5\n5 4 3 2 1",
"output": "5 4 3 2 1"
},
{
"input": "20\n2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19"
},
{
"input": "21\n3 2 1 6 5 4 9 8 7 12 11 10 15 14 13 18 17 16 21 20 19",
"output": "3 2 1 6 5 4 9 8 7 12 11 10 15 14 13 18 17 16 21 20 19"
},
{
"input": "10\n3 4 5 6 7 8 9 10 1 2",
"output": "9 10 1 2 3 4 5 6 7 8"
},
{
"input": "8\n1 5 3 7 2 6 4 8",
"output": "1 5 3 7 2 6 4 8"
},
{
"input": "50\n49 22 4 2 20 46 7 32 5 19 48 24 26 15 45 21 44 11 50 43 39 17 31 1 42 34 3 27 36 25 12 30 13 33 28 35 18 6 8 37 38 14 10 9 29 16 40 23 41 47",
"output": "24 4 27 3 9 38 7 39 44 43 18 31 33 42 14 46 22 37 10 5 16 2 48 12 30 13 28 35 45 32 23 8 34 26 36 29 40 41 21 47 49 25 20 17 15 6 50 11 1 19"
},
{
"input": "34\n13 20 33 30 15 11 27 4 8 2 29 25 24 7 3 22 18 10 26 16 5 1 32 9 34 6 12 14 28 19 31 21 23 17",
"output": "22 10 15 8 21 26 14 9 24 18 6 27 1 28 5 20 34 17 30 2 32 16 33 13 12 19 7 29 11 4 31 23 3 25"
},
{
"input": "92\n23 1 6 4 84 54 44 76 63 34 61 20 48 13 28 78 26 46 90 72 24 55 91 89 53 38 82 5 79 92 29 32 15 64 11 88 60 70 7 66 18 59 8 57 19 16 42 21 80 71 62 27 75 86 36 9 83 73 74 50 43 31 56 30 17 33 40 81 49 12 10 41 22 77 25 68 51 2 47 3 58 69 87 67 39 37 35 65 14 45 52 85",
"output": "2 78 80 4 28 3 39 43 56 71 35 70 14 89 33 46 65 41 45 12 48 73 1 21 75 17 52 15 31 64 62 32 66 10 87 55 86 26 85 67 72 47 61 7 90 18 79 13 69 60 77 91 25 6 22 63 44 81 42 37 11 51 9 34 88 40 84 76 82 38 50 20 58 59 53 8 74 16 29 49 68 27 57 5 92 54 83 36 24 19 23 30"
},
{
"input": "49\n30 24 33 48 7 3 17 2 8 35 10 39 23 40 46 32 18 21 26 22 1 16 47 45 41 28 31 6 12 43 27 11 13 37 19 15 44 5 29 42 4 38 20 34 14 9 25 36 49",
"output": "21 8 6 41 38 28 5 9 46 11 32 29 33 45 36 22 7 17 35 43 18 20 13 2 47 19 31 26 39 1 27 16 3 44 10 48 34 42 12 14 25 40 30 37 24 15 23 4 49"
},
{
"input": "12\n3 8 7 4 6 5 2 1 11 9 10 12",
"output": "8 7 1 4 6 5 3 2 10 11 9 12"
},
{
"input": "78\n16 56 36 78 21 14 9 77 26 57 70 61 41 47 18 44 5 31 50 74 65 52 6 39 22 62 67 69 43 7 64 29 24 40 48 51 73 54 72 12 19 34 4 25 55 33 17 35 23 53 10 8 27 32 42 68 20 63 3 2 1 71 58 46 13 30 49 11 37 66 38 60 28 75 15 59 45 76",
"output": "61 60 59 43 17 23 30 52 7 51 68 40 65 6 75 1 47 15 41 57 5 25 49 33 44 9 53 73 32 66 18 54 46 42 48 3 69 71 24 34 13 55 29 16 77 64 14 35 67 19 36 22 50 38 45 2 10 63 76 72 12 26 58 31 21 70 27 56 28 11 62 39 37 20 74 78 8 4"
},
{
"input": "64\n64 57 40 3 15 8 62 18 33 59 51 19 22 13 4 37 47 45 50 35 63 11 58 42 46 21 7 2 41 48 32 23 28 38 17 12 24 27 49 31 60 6 30 25 61 52 26 54 9 14 29 20 44 39 55 10 34 16 5 56 1 36 53 43",
"output": "61 28 4 15 59 42 27 6 49 56 22 36 14 50 5 58 35 8 12 52 26 13 32 37 44 47 38 33 51 43 40 31 9 57 20 62 16 34 54 3 29 24 64 53 18 25 17 30 39 19 11 46 63 48 55 60 2 23 10 41 45 7 21 1"
},
{
"input": "49\n38 20 49 32 14 41 39 45 25 48 40 19 26 43 34 12 10 3 35 42 5 7 46 47 4 2 13 22 16 24 33 15 11 18 29 31 23 9 44 36 6 17 37 1 30 28 8 21 27",
"output": "44 26 18 25 21 41 22 47 38 17 33 16 27 5 32 29 42 34 12 2 48 28 37 30 9 13 49 46 35 45 36 4 31 15 19 40 43 1 7 11 6 20 14 39 8 23 24 10 3"
},
{
"input": "78\n17 50 30 48 33 12 42 4 18 53 76 67 38 3 20 72 51 55 60 63 46 10 57 45 54 32 24 62 8 11 35 44 65 74 58 28 2 6 56 52 39 23 47 49 61 1 66 41 15 77 7 27 78 13 14 34 5 31 37 21 40 16 29 69 59 43 64 36 70 19 25 73 71 75 9 68 26 22",
"output": "46 37 14 8 57 38 51 29 75 22 30 6 54 55 49 62 1 9 70 15 60 78 42 27 71 77 52 36 63 3 58 26 5 56 31 68 59 13 41 61 48 7 66 32 24 21 43 4 44 2 17 40 10 25 18 39 23 35 65 19 45 28 20 67 33 47 12 76 64 69 73 16 72 34 74 11 50 53"
},
{
"input": "29\n14 21 27 1 4 18 10 17 20 23 2 24 7 9 28 22 8 25 12 15 11 6 16 29 3 26 19 5 13",
"output": "4 11 25 5 28 22 13 17 14 7 21 19 29 1 20 23 8 6 27 9 2 16 10 12 18 26 3 15 24"
},
{
"input": "82\n6 1 10 75 28 66 61 81 78 63 17 19 58 34 49 12 67 50 41 44 3 15 59 38 51 72 36 11 46 29 18 64 27 23 13 53 56 68 2 25 47 40 69 54 42 5 60 55 4 16 24 79 57 20 7 73 32 80 76 52 82 37 26 31 65 8 39 62 33 71 30 9 77 43 48 74 70 22 14 45 35 21",
"output": "2 39 21 49 46 1 55 66 72 3 28 16 35 79 22 50 11 31 12 54 82 78 34 51 40 63 33 5 30 71 64 57 69 14 81 27 62 24 67 42 19 45 74 20 80 29 41 75 15 18 25 60 36 44 48 37 53 13 23 47 7 68 10 32 65 6 17 38 43 77 70 26 56 76 4 59 73 9 52 58 8 61"
},
{
"input": "82\n74 18 15 69 71 77 19 26 80 20 66 7 30 82 22 48 21 44 52 65 64 61 35 49 12 8 53 81 54 16 11 9 40 46 13 1 29 58 5 41 55 4 78 60 6 51 56 2 38 36 34 62 63 25 17 67 45 14 32 37 75 79 10 47 27 39 31 68 59 24 50 43 72 70 42 28 76 23 57 3 73 33",
"output": "36 48 80 42 39 45 12 26 32 63 31 25 35 58 3 30 55 2 7 10 17 15 78 70 54 8 65 76 37 13 67 59 82 51 23 50 60 49 66 33 40 75 72 18 57 34 64 16 24 71 46 19 27 29 41 47 79 38 69 44 22 52 53 21 20 11 56 68 4 74 5 73 81 1 61 77 6 43 62 9 28 14"
},
{
"input": "45\n2 32 34 13 3 15 16 33 22 12 31 38 42 14 27 7 36 8 4 19 45 41 5 35 10 11 39 20 29 44 17 9 6 40 37 28 25 21 1 30 24 18 43 26 23",
"output": "39 1 5 19 23 33 16 18 32 25 26 10 4 14 6 7 31 42 20 28 38 9 45 41 37 44 15 36 29 40 11 2 8 3 24 17 35 12 27 34 22 13 43 30 21"
},
{
"input": "45\n4 32 33 39 43 21 22 35 45 7 14 5 16 9 42 31 24 36 17 29 41 25 37 34 27 20 11 44 3 13 19 2 1 10 26 30 38 18 6 8 15 23 40 28 12",
"output": "33 32 29 1 12 39 10 40 14 34 27 45 30 11 41 13 19 38 31 26 6 7 42 17 22 35 25 44 20 36 16 2 3 24 8 18 23 37 4 43 21 15 5 28 9"
},
{
"input": "74\n48 72 40 67 17 4 27 53 11 32 25 9 74 2 41 24 56 22 14 21 33 5 18 55 20 7 29 36 69 13 52 19 38 30 68 59 66 34 63 6 47 45 54 44 62 12 50 71 16 10 8 64 57 73 46 26 49 42 3 23 35 1 61 39 70 60 65 43 15 28 37 51 58 31",
"output": "62 14 59 6 22 40 26 51 12 50 9 46 30 19 69 49 5 23 32 25 20 18 60 16 11 56 7 70 27 34 74 10 21 38 61 28 71 33 64 3 15 58 68 44 42 55 41 1 57 47 72 31 8 43 24 17 53 73 36 66 63 45 39 52 67 37 4 35 29 65 48 2 54 13"
},
{
"input": "47\n9 26 27 10 6 34 28 42 39 22 45 21 11 43 14 47 38 15 40 32 46 1 36 29 17 25 2 23 31 5 24 4 7 8 12 19 16 44 37 20 18 33 30 13 35 41 3",
"output": "22 27 47 32 30 5 33 34 1 4 13 35 44 15 18 37 25 41 36 40 12 10 28 31 26 2 3 7 24 43 29 20 42 6 45 23 39 17 9 19 46 8 14 38 11 21 16"
},
{
"input": "49\n14 38 6 29 9 49 36 43 47 3 44 20 34 15 7 11 1 28 12 40 16 37 31 10 42 41 33 21 18 30 5 27 17 35 25 26 45 19 2 13 23 32 4 22 46 48 24 39 8",
"output": "17 39 10 43 31 3 15 49 5 24 16 19 40 1 14 21 33 29 38 12 28 44 41 47 35 36 32 18 4 30 23 42 27 13 34 7 22 2 48 20 26 25 8 11 37 45 9 46 6"
},
{
"input": "100\n78 56 31 91 90 95 16 65 58 77 37 89 33 61 10 76 62 47 35 67 69 7 63 83 22 25 49 8 12 30 39 44 57 64 48 42 32 11 70 43 55 50 99 24 85 73 45 14 54 21 98 84 74 2 26 18 9 36 80 53 75 46 66 86 59 93 87 68 94 13 72 28 79 88 92 29 52 82 34 97 19 38 1 41 27 4 40 5 96 100 51 6 20 23 81 15 17 3 60 71",
"output": "83 54 98 86 88 92 22 28 57 15 38 29 70 48 96 7 97 56 81 93 50 25 94 44 26 55 85 72 76 30 3 37 13 79 19 58 11 82 31 87 84 36 40 32 47 62 18 35 27 42 91 77 60 49 41 2 33 9 65 99 14 17 23 34 8 63 20 68 21 39 100 71 46 53 61 16 10 1 73 59 95 78 24 52 45 64 67 74 12 5 4 75 66 69 6 89 80 51 43 90"
},
{
"input": "22\n12 8 11 2 16 7 13 6 22 21 20 10 4 14 18 1 5 15 3 19 17 9",
"output": "16 4 19 13 17 8 6 2 22 12 3 1 7 14 18 5 21 15 20 11 10 9"
},
{
"input": "72\n16 11 49 51 3 27 60 55 23 40 66 7 53 70 13 5 15 32 18 72 33 30 8 31 46 12 28 67 25 38 50 22 69 34 71 52 58 39 24 35 42 9 41 26 62 1 63 65 36 64 68 61 37 14 45 47 6 57 54 20 17 2 56 59 29 10 4 48 21 43 19 44",
"output": "46 62 5 67 16 57 12 23 42 66 2 26 15 54 17 1 61 19 71 60 69 32 9 39 29 44 6 27 65 22 24 18 21 34 40 49 53 30 38 10 43 41 70 72 55 25 56 68 3 31 4 36 13 59 8 63 58 37 64 7 52 45 47 50 48 11 28 51 33 14 35 20"
},
{
"input": "63\n21 56 11 10 62 24 20 42 28 52 38 2 37 43 48 22 7 8 40 14 13 46 53 1 23 4 60 63 51 36 25 12 39 32 49 16 58 44 31 61 33 50 55 54 45 6 47 41 9 57 30 29 26 18 19 27 15 34 3 35 59 5 17",
"output": "24 12 59 26 62 46 17 18 49 4 3 32 21 20 57 36 63 54 55 7 1 16 25 6 31 53 56 9 52 51 39 34 41 58 60 30 13 11 33 19 48 8 14 38 45 22 47 15 35 42 29 10 23 44 43 2 50 37 61 27 40 5 28"
},
{
"input": "18\n2 16 8 4 18 12 3 6 5 9 10 15 11 17 14 13 1 7",
"output": "17 1 7 4 9 8 18 3 10 11 13 6 16 15 12 2 14 5"
},
{
"input": "47\n6 9 10 41 25 3 4 37 20 1 36 22 29 27 11 24 43 31 12 17 34 42 38 39 13 2 7 21 18 5 15 35 44 26 33 46 19 40 30 14 28 23 47 32 45 8 16",
"output": "10 26 6 7 30 1 27 46 2 3 15 19 25 40 31 47 20 29 37 9 28 12 42 16 5 34 14 41 13 39 18 44 35 21 32 11 8 23 24 38 4 22 17 33 45 36 43"
},
{
"input": "96\n41 91 48 88 29 57 1 19 44 43 37 5 10 75 25 63 30 78 76 53 8 92 18 70 39 17 49 60 9 16 3 34 86 59 23 79 55 45 72 51 28 33 96 40 26 54 6 32 89 61 85 74 7 82 52 31 64 66 94 95 11 22 2 73 35 13 42 71 14 47 84 69 50 67 58 12 77 46 38 68 15 36 20 93 27 90 83 56 87 4 21 24 81 62 80 65",
"output": "7 63 31 90 12 47 53 21 29 13 61 76 66 69 81 30 26 23 8 83 91 62 35 92 15 45 85 41 5 17 56 48 42 32 65 82 11 79 25 44 1 67 10 9 38 78 70 3 27 73 40 55 20 46 37 88 6 75 34 28 50 94 16 57 96 58 74 80 72 24 68 39 64 52 14 19 77 18 36 95 93 54 87 71 51 33 89 4 49 86 2 22 84 59 60 43"
},
{
"input": "73\n67 24 39 22 23 20 48 34 42 40 19 70 65 69 64 21 53 11 59 15 26 10 30 33 72 29 55 25 56 71 8 9 57 49 41 61 13 12 6 27 66 36 47 50 73 60 2 37 7 4 51 17 1 46 14 62 35 3 45 63 43 58 54 32 31 5 28 44 18 52 68 38 16",
"output": "53 47 58 50 66 39 49 31 32 22 18 38 37 55 20 73 52 69 11 6 16 4 5 2 28 21 40 67 26 23 65 64 24 8 57 42 48 72 3 10 35 9 61 68 59 54 43 7 34 44 51 70 17 63 27 29 33 62 19 46 36 56 60 15 13 41 1 71 14 12 30 25 45"
},
{
"input": "81\n25 2 78 40 12 80 69 13 49 43 17 33 23 54 32 61 77 66 27 71 24 26 42 55 60 9 5 30 7 37 45 63 53 11 38 44 68 34 28 52 67 22 57 46 47 50 8 16 79 62 4 36 20 14 73 64 6 76 35 74 58 10 29 81 59 31 19 1 75 39 70 18 41 21 72 65 3 48 15 56 51",
"output": "68 2 77 51 27 57 29 47 26 62 34 5 8 54 79 48 11 72 67 53 74 42 13 21 1 22 19 39 63 28 66 15 12 38 59 52 30 35 70 4 73 23 10 36 31 44 45 78 9 46 81 40 33 14 24 80 43 61 65 25 16 50 32 56 76 18 41 37 7 71 20 75 55 60 69 58 17 3 49 6 64"
},
{
"input": "12\n12 3 1 5 11 6 7 10 2 8 9 4",
"output": "3 9 2 12 4 6 7 10 11 8 5 1"
},
{
"input": "47\n7 21 41 18 40 31 12 28 24 14 43 23 33 10 19 38 26 8 34 15 29 44 5 13 39 25 3 27 20 42 35 9 2 1 30 46 36 32 4 22 37 45 6 47 11 16 17",
"output": "34 33 27 39 23 43 1 18 32 14 45 7 24 10 20 46 47 4 15 29 2 40 12 9 26 17 28 8 21 35 6 38 13 19 31 37 41 16 25 5 3 30 11 22 42 36 44"
},
{
"input": "8\n1 3 5 2 4 8 6 7",
"output": "1 4 2 5 3 7 8 6"
},
{
"input": "38\n28 8 2 33 20 32 26 29 23 31 15 38 11 37 18 21 22 19 4 34 1 35 16 7 17 6 27 30 36 12 9 24 25 13 5 3 10 14",
"output": "21 3 36 19 35 26 24 2 31 37 13 30 34 38 11 23 25 15 18 5 16 17 9 32 33 7 27 1 8 28 10 6 4 20 22 29 14 12"
},
{
"input": "10\n2 9 4 6 10 1 7 5 3 8",
"output": "6 1 9 3 8 4 7 10 2 5"
},
{
"input": "23\n20 11 15 1 5 12 23 9 2 22 13 19 16 14 7 4 8 21 6 17 18 10 3",
"output": "4 9 23 16 5 19 15 17 8 22 2 6 11 14 3 13 20 21 12 1 18 10 7"
},
{
"input": "10\n2 4 9 3 6 8 10 5 1 7",
"output": "9 1 4 2 8 5 10 6 3 7"
},
{
"input": "55\n9 48 23 49 11 24 4 22 34 32 17 45 39 13 14 21 19 25 2 31 37 7 55 36 20 51 5 12 54 10 35 40 43 1 46 18 53 41 38 26 29 50 3 42 52 27 8 28 47 33 6 16 30 44 15",
"output": "34 19 43 7 27 51 22 47 1 30 5 28 14 15 55 52 11 36 17 25 16 8 3 6 18 40 46 48 41 53 20 10 50 9 31 24 21 39 13 32 38 44 33 54 12 35 49 2 4 42 26 45 37 29 23"
},
{
"input": "58\n49 13 12 54 2 38 56 11 33 25 26 19 28 8 23 41 20 36 46 55 15 35 9 7 32 37 58 6 3 14 47 31 40 30 53 44 4 50 29 34 10 43 39 57 5 22 27 45 51 42 24 16 18 21 52 17 48 1",
"output": "58 5 29 37 45 28 24 14 23 41 8 3 2 30 21 52 56 53 12 17 54 46 15 51 10 11 47 13 39 34 32 25 9 40 22 18 26 6 43 33 16 50 42 36 48 19 31 57 1 38 49 55 35 4 20 7 44 27"
},
{
"input": "34\n20 25 2 3 33 29 1 16 14 7 21 9 32 31 6 26 22 4 27 23 24 10 34 12 19 15 5 18 28 17 13 8 11 30",
"output": "7 3 4 18 27 15 10 32 12 22 33 24 31 9 26 8 30 28 25 1 11 17 20 21 2 16 19 29 6 34 14 13 5 23"
},
{
"input": "53\n47 29 46 25 23 13 7 31 33 4 38 11 35 16 42 14 15 43 34 39 28 18 6 45 30 1 40 20 2 37 5 32 24 12 44 26 27 3 19 51 36 21 22 9 10 50 41 48 49 53 8 17 52",
"output": "26 29 38 10 31 23 7 51 44 45 12 34 6 16 17 14 52 22 39 28 42 43 5 33 4 36 37 21 2 25 8 32 9 19 13 41 30 11 20 27 47 15 18 35 24 3 1 48 49 46 40 53 50"
},
{
"input": "99\n77 87 90 48 53 38 68 6 28 57 35 82 63 71 60 41 3 12 86 65 10 59 22 67 33 74 93 27 24 1 61 43 25 4 51 52 15 88 9 31 30 42 89 49 23 21 29 32 46 73 37 16 5 69 56 26 92 64 20 54 75 14 98 13 94 2 95 7 36 66 58 8 50 78 84 45 11 96 76 62 97 80 40 39 47 85 34 79 83 17 91 72 19 44 70 81 55 99 18",
"output": "30 66 17 34 53 8 68 72 39 21 77 18 64 62 37 52 90 99 93 59 46 23 45 29 33 56 28 9 47 41 40 48 25 87 11 69 51 6 84 83 16 42 32 94 76 49 85 4 44 73 35 36 5 60 97 55 10 71 22 15 31 80 13 58 20 70 24 7 54 95 14 92 50 26 61 79 1 74 88 82 96 12 89 75 86 19 2 38 43 3 91 57 27 65 67 78 81 63 98"
},
{
"input": "32\n17 29 2 6 30 8 26 7 1 27 10 9 13 24 31 21 15 19 22 18 4 11 25 28 32 3 23 12 5 14 20 16",
"output": "9 3 26 21 29 4 8 6 12 11 22 28 13 30 17 32 1 20 18 31 16 19 27 14 23 7 10 24 2 5 15 25"
},
{
"input": "65\n18 40 1 60 17 19 4 6 12 49 28 58 2 25 13 14 64 56 61 34 62 30 59 51 26 8 33 63 36 48 46 7 43 21 31 27 11 44 29 5 32 23 35 9 53 57 52 50 15 38 42 3 54 65 55 41 20 24 22 47 45 10 39 16 37",
"output": "3 13 52 7 40 8 32 26 44 62 37 9 15 16 49 64 5 1 6 57 34 59 42 58 14 25 36 11 39 22 35 41 27 20 43 29 65 50 63 2 56 51 33 38 61 31 60 30 10 48 24 47 45 53 55 18 46 12 23 4 19 21 28 17 54"
},
{
"input": "71\n35 50 55 58 25 32 26 40 63 34 44 53 24 18 37 7 64 27 56 65 1 19 2 43 42 14 57 47 22 13 59 61 39 67 30 45 54 38 33 48 6 5 3 69 36 21 41 4 16 46 20 17 15 12 10 70 68 23 60 31 52 29 66 28 51 49 62 11 8 9 71",
"output": "21 23 43 48 42 41 16 69 70 55 68 54 30 26 53 49 52 14 22 51 46 29 58 13 5 7 18 64 62 35 60 6 39 10 1 45 15 38 33 8 47 25 24 11 36 50 28 40 66 2 65 61 12 37 3 19 27 4 31 59 32 67 9 17 20 63 34 57 44 56 71"
},
{
"input": "74\n33 8 42 63 64 61 31 74 11 50 68 14 36 25 57 30 7 44 21 15 6 9 23 59 46 3 73 16 62 51 40 60 41 54 5 39 35 28 48 4 58 12 66 69 13 26 71 1 24 19 29 52 37 2 20 43 18 72 17 56 34 38 65 67 27 10 47 70 53 32 45 55 49 22",
"output": "48 54 26 40 35 21 17 2 22 66 9 42 45 12 20 28 59 57 50 55 19 74 23 49 14 46 65 38 51 16 7 70 1 61 37 13 53 62 36 31 33 3 56 18 71 25 67 39 73 10 30 52 69 34 72 60 15 41 24 32 6 29 4 5 63 43 64 11 44 68 47 58 27 8"
},
{
"input": "96\n78 10 82 46 38 91 77 69 2 27 58 80 79 44 59 41 6 31 76 11 42 48 51 37 19 87 43 25 52 32 1 39 63 29 21 65 53 74 92 16 15 95 90 83 30 73 71 5 50 17 96 33 86 60 67 64 20 26 61 40 55 88 94 93 9 72 47 57 14 45 22 3 54 68 13 24 4 7 56 81 89 70 49 8 84 28 18 62 35 36 75 23 66 85 34 12",
"output": "31 9 72 77 48 17 78 84 65 2 20 96 75 69 41 40 50 87 25 57 35 71 92 76 28 58 10 86 34 45 18 30 52 95 89 90 24 5 32 60 16 21 27 14 70 4 67 22 83 49 23 29 37 73 61 79 68 11 15 54 59 88 33 56 36 93 55 74 8 82 47 66 46 38 91 19 7 1 13 12 80 3 44 85 94 53 26 62 81 43 6 39 64 63 42 51"
},
{
"input": "7\n2 1 5 7 3 4 6",
"output": "2 1 5 6 3 7 4"
},
{
"input": "51\n8 33 37 2 16 22 24 30 4 9 5 15 27 3 18 39 31 26 10 17 46 41 25 14 6 1 29 48 36 20 51 49 21 43 19 13 38 50 47 34 11 23 28 12 42 7 32 40 44 45 35",
"output": "26 4 14 9 11 25 46 1 10 19 41 44 36 24 12 5 20 15 35 30 33 6 42 7 23 18 13 43 27 8 17 47 2 40 51 29 3 37 16 48 22 45 34 49 50 21 39 28 32 38 31"
},
{
"input": "27\n12 14 7 3 20 21 25 13 22 15 23 4 2 24 10 17 19 8 26 11 27 18 9 5 6 1 16",
"output": "26 13 4 12 24 25 3 18 23 15 20 1 8 2 10 27 16 22 17 5 6 9 11 14 7 19 21"
},
{
"input": "71\n51 13 20 48 54 23 24 64 14 62 71 67 57 53 3 30 55 43 33 25 39 40 66 6 46 18 5 19 61 16 32 68 70 41 60 44 29 49 27 69 50 38 10 17 45 56 9 21 26 63 28 35 7 59 1 65 2 15 8 11 12 34 37 47 58 22 31 4 36 42 52",
"output": "55 57 15 68 27 24 53 59 47 43 60 61 2 9 58 30 44 26 28 3 48 66 6 7 20 49 39 51 37 16 67 31 19 62 52 69 63 42 21 22 34 70 18 36 45 25 64 4 38 41 1 71 14 5 17 46 13 65 54 35 29 10 50 8 56 23 12 32 40 33 11"
},
{
"input": "9\n8 5 2 6 1 9 4 7 3",
"output": "5 3 9 7 2 4 8 1 6"
},
{
"input": "29\n10 24 11 5 26 25 2 9 22 15 8 14 29 21 4 1 23 17 3 12 13 16 18 28 19 20 7 6 27",
"output": "16 7 19 15 4 28 27 11 8 1 3 20 21 12 10 22 18 23 25 26 14 9 17 2 6 5 29 24 13"
},
{
"input": "60\n39 25 42 4 55 60 16 18 47 1 11 40 7 50 19 35 49 54 12 3 30 38 2 58 17 26 45 6 33 43 37 32 52 36 15 23 27 59 24 20 28 14 8 9 13 29 44 46 41 21 5 48 51 22 31 56 57 53 10 34",
"output": "10 23 20 4 51 28 13 43 44 59 11 19 45 42 35 7 25 8 15 40 50 54 36 39 2 26 37 41 46 21 55 32 29 60 16 34 31 22 1 12 49 3 30 47 27 48 9 52 17 14 53 33 58 18 5 56 57 24 38 6"
},
{
"input": "50\n37 45 22 5 12 21 28 24 18 47 20 25 8 50 14 2 34 43 11 16 49 41 48 1 19 31 39 46 32 23 15 42 3 35 38 30 44 26 10 9 40 36 7 17 33 4 27 6 13 29",
"output": "24 16 33 46 4 48 43 13 40 39 19 5 49 15 31 20 44 9 25 11 6 3 30 8 12 38 47 7 50 36 26 29 45 17 34 42 1 35 27 41 22 32 18 37 2 28 10 23 21 14"
},
{
"input": "30\n8 29 28 16 17 25 27 15 21 11 6 20 2 13 1 30 5 4 24 10 14 3 23 18 26 9 12 22 19 7",
"output": "15 13 22 18 17 11 30 1 26 20 10 27 14 21 8 4 5 24 29 12 9 28 23 19 6 25 7 3 2 16"
},
{
"input": "46\n15 2 44 43 38 19 31 42 4 37 29 30 24 45 27 41 8 20 33 7 35 3 18 46 36 26 1 28 21 40 16 22 32 11 14 13 12 9 25 39 10 6 23 17 5 34",
"output": "27 2 22 9 45 42 20 17 38 41 34 37 36 35 1 31 44 23 6 18 29 32 43 13 39 26 15 28 11 12 7 33 19 46 21 25 10 5 40 30 16 8 4 3 14 24"
},
{
"input": "9\n4 8 6 5 3 9 2 7 1",
"output": "9 7 5 1 4 3 8 2 6"
},
{
"input": "46\n31 30 33 23 45 7 36 8 11 3 32 39 41 20 1 28 6 27 18 24 17 5 16 37 26 13 22 14 2 38 15 46 9 4 19 21 12 44 10 35 25 34 42 43 40 29",
"output": "15 29 10 34 22 17 6 8 33 39 9 37 26 28 31 23 21 19 35 14 36 27 4 20 41 25 18 16 46 2 1 11 3 42 40 7 24 30 12 45 13 43 44 38 5 32"
},
{
"input": "66\n27 12 37 48 46 21 34 58 38 28 66 2 64 32 44 31 13 36 40 15 19 11 22 5 30 29 6 7 61 39 20 42 23 54 51 33 50 9 60 8 57 45 49 10 62 41 59 3 55 63 52 24 25 26 43 56 65 4 16 14 1 35 18 17 53 47",
"output": "61 12 48 58 24 27 28 40 38 44 22 2 17 60 20 59 64 63 21 31 6 23 33 52 53 54 1 10 26 25 16 14 36 7 62 18 3 9 30 19 46 32 55 15 42 5 66 4 43 37 35 51 65 34 49 56 41 8 47 39 29 45 50 13 57 11"
},
{
"input": "13\n3 12 9 2 8 5 13 4 11 1 10 7 6",
"output": "10 4 1 8 6 13 12 5 3 11 9 2 7"
},
{
"input": "80\n21 25 56 50 20 61 7 74 51 69 8 2 46 57 45 71 14 52 17 43 9 30 70 78 31 10 38 13 23 15 37 79 6 16 77 73 80 4 49 48 18 28 26 58 33 41 64 22 54 72 59 60 40 63 53 27 1 5 75 67 62 34 19 39 68 65 44 55 3 32 11 42 76 12 35 47 66 36 24 29",
"output": "57 12 69 38 58 33 7 11 21 26 71 74 28 17 30 34 19 41 63 5 1 48 29 79 2 43 56 42 80 22 25 70 45 62 75 78 31 27 64 53 46 72 20 67 15 13 76 40 39 4 9 18 55 49 68 3 14 44 51 52 6 61 54 47 66 77 60 65 10 23 16 50 36 8 59 73 35 24 32 37"
},
{
"input": "63\n9 49 53 25 40 46 43 51 54 22 58 16 23 26 10 47 5 27 2 8 61 59 19 35 63 56 28 20 34 4 62 38 6 55 36 31 57 15 29 33 1 48 50 37 7 30 18 42 32 52 12 41 14 21 45 11 24 17 39 13 44 60 3",
"output": "41 19 63 30 17 33 45 20 1 15 56 51 60 53 38 12 58 47 23 28 54 10 13 57 4 14 18 27 39 46 36 49 40 29 24 35 44 32 59 5 52 48 7 61 55 6 16 42 2 43 8 50 3 9 34 26 37 11 22 62 21 31 25"
},
{
"input": "26\n11 4 19 13 17 9 2 24 6 5 22 23 14 15 3 25 16 8 18 10 21 1 12 26 7 20",
"output": "22 7 15 2 10 9 25 18 6 20 1 23 4 13 14 17 5 19 3 26 21 11 12 8 16 24"
},
{
"input": "69\n40 22 11 66 4 27 31 29 64 53 37 55 51 2 7 36 18 52 6 1 30 21 17 20 14 9 59 62 49 68 3 50 65 57 44 5 67 46 33 13 34 15 24 48 63 58 38 25 41 35 16 54 32 10 60 61 39 12 69 8 23 45 26 47 56 43 28 19 42",
"output": "20 14 31 5 36 19 15 60 26 54 3 58 40 25 42 51 23 17 68 24 22 2 61 43 48 63 6 67 8 21 7 53 39 41 50 16 11 47 57 1 49 69 66 35 62 38 64 44 29 32 13 18 10 52 12 65 34 46 27 55 56 28 45 9 33 4 37 30 59"
},
{
"input": "6\n4 3 6 5 1 2",
"output": "5 6 2 1 4 3"
},
{
"input": "9\n7 8 5 3 1 4 2 9 6",
"output": "5 7 4 6 3 9 1 2 8"
},
{
"input": "41\n27 24 16 30 25 8 32 2 26 20 39 33 41 22 40 14 36 9 28 4 34 11 31 23 19 18 17 35 3 10 6 13 5 15 29 38 7 21 1 12 37",
"output": "39 8 29 20 33 31 37 6 18 30 22 40 32 16 34 3 27 26 25 10 38 14 24 2 5 9 1 19 35 4 23 7 12 21 28 17 41 36 11 15 13"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "20\n2 6 4 18 7 10 17 13 16 8 14 9 20 5 19 12 1 3 15 11",
"output": "17 1 18 3 14 2 5 10 12 6 20 16 8 11 19 9 7 4 15 13"
},
{
"input": "2\n2 1",
"output": "2 1"
},
{
"input": "60\n2 4 31 51 11 7 34 20 3 14 18 23 48 54 15 36 38 60 49 40 5 33 41 26 55 58 10 8 13 9 27 30 37 1 21 59 44 57 35 19 46 43 42 45 12 22 39 32 24 16 6 56 53 52 25 17 47 29 50 28",
"output": "34 1 9 2 21 51 6 28 30 27 5 45 29 10 15 50 56 11 40 8 35 46 12 49 55 24 31 60 58 32 3 48 22 7 39 16 33 17 47 20 23 43 42 37 44 41 57 13 19 59 4 54 53 14 25 52 38 26 36 18"
},
{
"input": "14\n14 6 3 12 11 2 7 1 10 9 8 5 4 13",
"output": "8 6 3 13 12 2 7 11 10 9 5 4 14 1"
},
{
"input": "81\n13 43 79 8 7 21 73 46 63 4 62 78 56 11 70 68 61 53 60 49 16 27 59 47 69 5 22 44 77 57 52 48 1 9 72 81 28 55 58 33 51 18 31 17 41 20 42 3 32 54 19 2 75 34 64 10 65 50 30 29 67 12 71 66 74 15 26 23 6 38 25 35 37 24 80 76 40 45 39 36 14",
"output": "33 52 48 10 26 69 5 4 34 56 14 62 1 81 66 21 44 42 51 46 6 27 68 74 71 67 22 37 60 59 43 49 40 54 72 80 73 70 79 77 45 47 2 28 78 8 24 32 20 58 41 31 18 50 38 13 30 39 23 19 17 11 9 55 57 64 61 16 25 15 63 35 7 65 53 76 29 12 3 75 36"
},
{
"input": "42\n41 11 10 8 21 37 32 19 31 25 1 15 36 5 6 27 4 3 13 7 16 17 2 23 34 24 38 28 12 20 30 42 18 26 39 35 33 40 9 14 22 29",
"output": "11 23 18 17 14 15 20 4 39 3 2 29 19 40 12 21 22 33 8 30 5 41 24 26 10 34 16 28 42 31 9 7 37 25 36 13 6 27 35 38 1 32"
},
{
"input": "97\n20 6 76 42 4 18 35 59 39 63 27 7 66 47 61 52 15 36 88 93 19 33 10 92 1 34 46 86 78 57 51 94 77 29 26 73 41 2 58 97 43 65 17 74 21 49 25 3 91 82 95 12 96 13 84 90 69 24 72 37 16 55 54 71 64 62 48 89 11 70 80 67 30 40 44 85 53 83 79 9 56 45 75 87 22 14 81 68 8 38 60 50 28 23 31 32 5",
"output": "25 38 48 5 97 2 12 89 80 23 69 52 54 86 17 61 43 6 21 1 45 85 94 58 47 35 11 93 34 73 95 96 22 26 7 18 60 90 9 74 37 4 41 75 82 27 14 67 46 92 31 16 77 63 62 81 30 39 8 91 15 66 10 65 42 13 72 88 57 70 64 59 36 44 83 3 33 29 79 71 87 50 78 55 76 28 84 19 68 56 49 24 20 32 51 53 40"
},
{
"input": "62\n15 27 46 6 8 51 14 56 23 48 42 49 52 22 20 31 29 12 47 3 62 34 37 35 32 57 19 25 5 60 61 38 18 10 11 55 45 53 17 30 9 36 4 50 41 16 44 28 40 59 24 1 13 39 26 7 33 58 2 43 21 54",
"output": "52 59 20 43 29 4 56 5 41 34 35 18 53 7 1 46 39 33 27 15 61 14 9 51 28 55 2 48 17 40 16 25 57 22 24 42 23 32 54 49 45 11 60 47 37 3 19 10 12 44 6 13 38 62 36 8 26 58 50 30 31 21"
},
{
"input": "61\n35 27 4 61 52 32 41 46 14 37 17 54 55 31 11 26 44 49 15 30 9 50 45 39 7 38 53 3 58 40 13 56 18 19 28 6 43 5 21 42 20 34 2 25 36 12 33 57 16 60 1 8 59 10 22 23 24 48 51 47 29",
"output": "51 43 28 3 38 36 25 52 21 54 15 46 31 9 19 49 11 33 34 41 39 55 56 57 44 16 2 35 61 20 14 6 47 42 1 45 10 26 24 30 7 40 37 17 23 8 60 58 18 22 59 5 27 12 13 32 48 29 53 50 4"
},
{
"input": "59\n31 26 36 15 17 19 10 53 11 34 13 46 55 9 44 7 8 37 32 52 47 25 51 22 35 39 41 4 43 24 5 27 20 57 6 38 3 28 21 40 50 18 14 56 33 45 12 2 49 59 54 29 16 48 42 58 1 30 23",
"output": "57 48 37 28 31 35 16 17 14 7 9 47 11 43 4 53 5 42 6 33 39 24 59 30 22 2 32 38 52 58 1 19 45 10 25 3 18 36 26 40 27 55 29 15 46 12 21 54 49 41 23 20 8 51 13 44 34 56 50"
},
{
"input": "10\n2 10 7 4 1 5 8 6 3 9",
"output": "5 1 9 4 6 8 3 7 10 2"
},
{
"input": "14\n14 2 1 8 6 12 11 10 9 7 3 4 5 13",
"output": "3 2 11 12 13 5 10 4 9 8 7 6 14 1"
},
{
"input": "43\n28 38 15 14 31 42 27 30 19 33 43 26 22 29 18 32 3 13 1 8 35 34 4 12 11 17 41 21 5 25 39 37 20 23 7 24 16 10 40 9 6 36 2",
"output": "19 43 17 23 29 41 35 20 40 38 25 24 18 4 3 37 26 15 9 33 28 13 34 36 30 12 7 1 14 8 5 16 10 22 21 42 32 2 31 39 27 6 11"
},
{
"input": "86\n39 11 20 31 28 76 29 64 35 21 41 71 12 82 5 37 80 73 38 26 79 75 23 15 59 45 47 6 3 62 50 49 51 22 2 65 86 60 70 42 74 17 1 30 55 44 8 66 81 27 57 77 43 13 54 32 72 46 48 56 14 34 78 52 36 85 24 19 69 83 25 61 7 4 84 33 63 58 18 40 68 10 67 9 16 53",
"output": "43 35 29 74 15 28 73 47 84 82 2 13 54 61 24 85 42 79 68 3 10 34 23 67 71 20 50 5 7 44 4 56 76 62 9 65 16 19 1 80 11 40 53 46 26 58 27 59 32 31 33 64 86 55 45 60 51 78 25 38 72 30 77 8 36 48 83 81 69 39 12 57 18 41 22 6 52 63 21 17 49 14 70 75 66 37"
},
{
"input": "99\n65 78 56 98 33 24 61 40 29 93 1 64 57 22 25 52 67 95 50 3 31 15 90 68 71 83 38 36 6 46 89 26 4 87 14 88 72 37 23 43 63 12 80 96 5 34 73 86 9 48 92 62 99 10 16 20 66 27 28 2 82 70 30 94 49 8 84 69 18 60 58 59 44 39 21 7 91 76 54 19 75 85 74 47 55 32 97 77 51 13 35 79 45 42 11 41 17 81 53",
"output": "11 60 20 33 45 29 76 66 49 54 95 42 90 35 22 55 97 69 80 56 75 14 39 6 15 32 58 59 9 63 21 86 5 46 91 28 38 27 74 8 96 94 40 73 93 30 84 50 65 19 89 16 99 79 85 3 13 71 72 70 7 52 41 12 1 57 17 24 68 62 25 37 47 83 81 78 88 2 92 43 98 61 26 67 82 48 34 36 31 23 77 51 10 64 18 44 87 4 53"
},
{
"input": "100\n42 23 48 88 36 6 18 70 96 1 34 40 46 22 39 55 85 93 45 67 71 75 59 9 21 3 86 63 65 68 20 38 73 31 84 90 50 51 56 95 72 33 49 19 83 76 54 74 100 30 17 98 15 94 4 97 5 99 81 27 92 32 89 12 13 91 87 29 60 11 52 43 35 58 10 25 16 80 28 2 44 61 8 82 66 69 41 24 57 62 78 37 79 77 53 7 14 47 26 64",
"output": "10 80 26 55 57 6 96 83 24 75 70 64 65 97 53 77 51 7 44 31 25 14 2 88 76 99 60 79 68 50 34 62 42 11 73 5 92 32 15 12 87 1 72 81 19 13 98 3 43 37 38 71 95 47 16 39 89 74 23 69 82 90 28 100 29 85 20 30 86 8 21 41 33 48 22 46 94 91 93 78 59 84 45 35 17 27 67 4 63 36 66 61 18 54 40 9 56 52 58 49"
},
{
"input": "99\n8 68 94 75 71 60 57 58 6 11 5 48 65 41 49 12 46 72 95 59 13 70 74 7 84 62 17 36 55 76 38 79 2 85 23 10 32 99 87 50 83 28 54 91 53 51 1 3 97 81 21 89 93 78 61 26 82 96 4 98 25 40 31 44 24 47 30 52 14 16 39 27 9 29 45 18 67 63 37 43 90 66 19 69 88 22 92 77 34 42 73 80 56 64 20 35 15 33 86",
"output": "47 33 48 59 11 9 24 1 73 36 10 16 21 69 97 70 27 76 83 95 51 86 35 65 61 56 72 42 74 67 63 37 98 89 96 28 79 31 71 62 14 90 80 64 75 17 66 12 15 40 46 68 45 43 29 93 7 8 20 6 55 26 78 94 13 82 77 2 84 22 5 18 91 23 4 30 88 54 32 92 50 57 41 25 34 99 39 85 52 81 44 87 53 3 19 58 49 60 38"
},
{
"input": "99\n12 99 88 13 7 19 74 47 23 90 16 29 26 11 58 60 64 98 37 18 82 67 72 46 51 85 17 92 87 20 77 36 78 71 57 35 80 54 73 15 14 62 97 45 31 79 94 56 76 96 28 63 8 44 38 86 49 2 52 66 61 59 10 43 55 50 22 34 83 53 95 40 81 21 30 42 27 3 5 41 1 70 69 25 93 48 65 6 24 89 91 33 39 68 9 4 32 84 75",
"output": "81 58 78 96 79 88 5 53 95 63 14 1 4 41 40 11 27 20 6 30 74 67 9 89 84 13 77 51 12 75 45 97 92 68 36 32 19 55 93 72 80 76 64 54 44 24 8 86 57 66 25 59 70 38 65 48 35 15 62 16 61 42 52 17 87 60 22 94 83 82 34 23 39 7 99 49 31 33 46 37 73 21 69 98 26 56 29 3 90 10 91 28 85 47 71 50 43 18 2"
},
{
"input": "99\n20 79 26 75 99 69 98 47 93 62 18 42 43 38 90 66 67 8 13 84 76 58 81 60 64 46 56 23 78 17 86 36 19 52 85 39 48 27 96 49 37 95 5 31 10 24 12 1 80 35 92 33 16 68 57 54 32 29 45 88 72 77 4 87 97 89 59 3 21 22 61 94 83 15 44 34 70 91 55 9 51 50 73 11 14 6 40 7 63 25 2 82 41 65 28 74 71 30 53",
"output": "48 91 68 63 43 86 88 18 80 45 84 47 19 85 74 53 30 11 33 1 69 70 28 46 90 3 38 95 58 98 44 57 52 76 50 32 41 14 36 87 93 12 13 75 59 26 8 37 40 82 81 34 99 56 79 27 55 22 67 24 71 10 89 25 94 16 17 54 6 77 97 61 83 96 4 21 62 29 2 49 23 92 73 20 35 31 64 60 66 15 78 51 9 72 42 39 65 7 5"
},
{
"input": "99\n74 20 9 1 60 85 65 13 4 25 40 99 5 53 64 3 36 31 73 44 55 50 45 63 98 51 68 6 47 37 71 82 88 34 84 18 19 12 93 58 86 7 11 46 90 17 33 27 81 69 42 59 56 32 95 52 76 61 96 62 78 43 66 21 49 97 75 14 41 72 89 16 30 79 22 23 15 83 91 38 48 2 87 26 28 80 94 70 54 92 57 10 8 35 67 77 29 24 39",
"output": "4 82 16 9 13 28 42 93 3 92 43 38 8 68 77 72 46 36 37 2 64 75 76 98 10 84 48 85 97 73 18 54 47 34 94 17 30 80 99 11 69 51 62 20 23 44 29 81 65 22 26 56 14 89 21 53 91 40 52 5 58 60 24 15 7 63 95 27 50 88 31 70 19 1 67 57 96 61 74 86 49 32 78 35 6 41 83 33 71 45 79 90 39 87 55 59 66 25 12"
},
{
"input": "99\n50 94 2 18 69 90 59 83 75 68 77 97 39 78 25 7 16 9 49 4 42 89 44 48 17 96 61 70 3 10 5 81 56 57 88 6 98 1 46 67 92 37 11 30 85 41 8 36 51 29 20 71 19 79 74 93 43 34 55 40 38 21 64 63 32 24 72 14 12 86 82 15 65 23 66 22 28 53 13 26 95 99 91 52 76 27 60 45 47 33 73 84 31 35 54 80 58 62 87",
"output": "38 3 29 20 31 36 16 47 18 30 43 69 79 68 72 17 25 4 53 51 62 76 74 66 15 80 86 77 50 44 93 65 90 58 94 48 42 61 13 60 46 21 57 23 88 39 89 24 19 1 49 84 78 95 59 33 34 97 7 87 27 98 64 63 73 75 40 10 5 28 52 67 91 55 9 85 11 14 54 96 32 71 8 92 45 70 99 35 22 6 83 41 56 2 81 26 12 37 82"
},
{
"input": "99\n19 93 14 34 39 37 33 15 52 88 7 43 69 27 9 77 94 31 48 22 63 70 79 17 50 6 81 8 76 58 23 74 86 11 57 62 41 87 75 51 12 18 68 56 95 3 80 83 84 29 24 61 71 78 59 96 20 85 90 28 45 36 38 97 1 49 40 98 44 67 13 73 72 91 47 10 30 54 35 42 4 2 92 26 64 60 53 21 5 82 46 32 55 66 16 89 99 65 25",
"output": "65 82 46 81 89 26 11 28 15 76 34 41 71 3 8 95 24 42 1 57 88 20 31 51 99 84 14 60 50 77 18 92 7 4 79 62 6 63 5 67 37 80 12 69 61 91 75 19 66 25 40 9 87 78 93 44 35 30 55 86 52 36 21 85 98 94 70 43 13 22 53 73 72 32 39 29 16 54 23 47 27 90 48 49 58 33 38 10 96 59 74 83 2 17 45 56 64 68 97"
},
{
"input": "99\n86 25 50 51 62 39 41 67 44 20 45 14 80 88 66 7 36 59 13 84 78 58 96 75 2 43 48 47 69 12 19 98 22 38 28 55 11 76 68 46 53 70 85 34 16 33 91 30 8 40 74 60 94 82 87 32 37 4 5 10 89 73 90 29 35 26 23 57 27 65 24 3 9 83 77 72 6 31 15 92 93 79 64 18 63 42 56 1 52 97 17 81 71 21 49 99 54 95 61",
"output": "88 25 72 58 59 77 16 49 73 60 37 30 19 12 79 45 91 84 31 10 94 33 67 71 2 66 69 35 64 48 78 56 46 44 65 17 57 34 6 50 7 86 26 9 11 40 28 27 95 3 4 89 41 97 36 87 68 22 18 52 99 5 85 83 70 15 8 39 29 42 93 76 62 51 24 38 75 21 82 13 92 54 74 20 43 1 55 14 61 63 47 80 81 53 98 23 90 32 96"
},
{
"input": "100\n66 44 99 15 43 79 28 33 88 90 49 68 82 38 9 74 4 58 29 81 31 94 10 42 89 21 63 40 62 61 18 6 84 72 48 25 67 69 71 85 98 34 83 70 65 78 91 77 93 41 23 24 87 11 55 12 59 73 36 97 7 14 26 39 30 27 45 20 50 17 53 2 57 47 95 56 75 19 37 96 16 35 8 3 76 60 13 86 5 32 64 80 46 51 54 100 1 22 52 92",
"output": "97 72 84 17 89 32 61 83 15 23 54 56 87 62 4 81 70 31 78 68 26 98 51 52 36 63 66 7 19 65 21 90 8 42 82 59 79 14 64 28 50 24 5 2 67 93 74 35 11 69 94 99 71 95 55 76 73 18 57 86 30 29 27 91 45 1 37 12 38 44 39 34 58 16 77 85 48 46 6 92 20 13 43 33 40 88 53 9 25 10 47 100 49 22 75 80 60 41 3 96"
},
{
"input": "99\n3 73 32 37 25 15 93 63 85 8 91 78 80 5 39 48 46 7 83 70 23 96 9 29 77 53 30 20 56 50 13 45 21 76 87 99 65 31 16 18 14 72 51 28 43 2 81 34 38 40 66 54 74 26 71 4 61 17 58 24 22 33 49 36 42 11 12 55 60 27 62 90 79 92 94 68 1 52 84 41 86 35 69 75 47 10 64 88 97 98 67 19 89 95 59 82 57 44 6",
"output": "77 46 1 56 14 99 18 10 23 86 66 67 31 41 6 39 58 40 92 28 33 61 21 60 5 54 70 44 24 27 38 3 62 48 82 64 4 49 15 50 80 65 45 98 32 17 85 16 63 30 43 78 26 52 68 29 97 59 95 69 57 71 8 87 37 51 91 76 83 20 55 42 2 53 84 34 25 12 73 13 47 96 19 79 9 81 35 88 93 72 11 74 7 75 94 22 89 90 36"
},
{
"input": "100\n100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1",
"output": "100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1"
}
] | 1,693,959,647 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 101 | 124 | 0 | n = int(input())
lst = list(map(int,input().split()))
lst1 = [0]*(n+1)
for i in range(len(lst)):
lst1[lst[i]]+= i+1
print(' '.join(map(str, lst1[1:]))) | Title: Presents
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited *n* his friends there.
If there's one thing Petya likes more that receiving gifts, that's watching others giving gifts to somebody else. Thus, he safely hid the laptop until the next New Year and made up his mind to watch his friends exchanging gifts while he does not participate in the process. He numbered all his friends with integers from 1 to *n*. Petya remembered that a friend number *i* gave a gift to a friend number *p**i*. He also remembered that each of his friends received exactly one gift.
Now Petya wants to know for each friend *i* the number of a friend who has given him a gift.
Input Specification:
The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the quantity of friends Petya invited to the party. The second line contains *n* space-separated integers: the *i*-th number is *p**i* — the number of a friend who gave a gift to friend number *i*. It is guaranteed that each friend received exactly one gift. It is possible that some friends do not share Petya's ideas of giving gifts to somebody else. Those friends gave the gifts to themselves.
Output Specification:
Print *n* space-separated integers: the *i*-th number should equal the number of the friend who gave a gift to friend number *i*.
Demo Input:
['4\n2 3 4 1\n', '3\n1 3 2\n', '2\n1 2\n']
Demo Output:
['4 1 2 3\n', '1 3 2\n', '1 2\n']
Note:
none | ```python
n = int(input())
lst = list(map(int,input().split()))
lst1 = [0]*(n+1)
for i in range(len(lst)):
lst1[lst[i]]+= i+1
print(' '.join(map(str, lst1[1:])))
``` | 3 |
|
270 | A | Fancy Fence | PROGRAMMING | 1,100 | [
"geometry",
"implementation",
"math"
] | null | null | Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot.
He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle *a*.
Will the robot be able to build the fence Emuskald wants? In other words, is there a regular polygon which angles are equal to *a*? | The first line of input contains an integer *t* (0<=<<=*t*<=<<=180) — the number of tests. Each of the following *t* lines contains a single integer *a* (0<=<<=*a*<=<<=180) — the angle the robot can make corners at measured in degrees. | For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible. | [
"3\n30\n60\n90\n"
] | [
"NO\nYES\nYES\n"
] | In the first test case, it is impossible to build the fence, since there is no regular polygon with angle <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/df5f4b07dd5316fde165b43657b2696e2919e791.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second test case, the fence is a regular triangle, and in the last test case — a square. | 500 | [
{
"input": "3\n30\n60\n90",
"output": "NO\nYES\nYES"
},
{
"input": "6\n1\n2\n3\n170\n179\n25",
"output": "NO\nNO\nNO\nYES\nYES\nNO"
}
] | 1,678,256,830 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 62 | 0 | tests = int(input())
for i in range(tests):
if int(input()) < 60:
print("NO")
else:
print("YES") | Title: Fancy Fence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot.
He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle *a*.
Will the robot be able to build the fence Emuskald wants? In other words, is there a regular polygon which angles are equal to *a*?
Input Specification:
The first line of input contains an integer *t* (0<=<<=*t*<=<<=180) — the number of tests. Each of the following *t* lines contains a single integer *a* (0<=<<=*a*<=<<=180) — the angle the robot can make corners at measured in degrees.
Output Specification:
For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible.
Demo Input:
['3\n30\n60\n90\n']
Demo Output:
['NO\nYES\nYES\n']
Note:
In the first test case, it is impossible to build the fence, since there is no regular polygon with angle <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/df5f4b07dd5316fde165b43657b2696e2919e791.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second test case, the fence is a regular triangle, and in the last test case — a square. | ```python
tests = int(input())
for i in range(tests):
if int(input()) < 60:
print("NO")
else:
print("YES")
``` | 0 |
|
820 | B | Mister B and Angle in Polygon | PROGRAMMING | 1,300 | [
"constructive algorithms",
"geometry",
"math"
] | null | null | On one quiet day all of sudden Mister B decided to draw angle *a* on his field. Aliens have already visited his field and left many different geometric figures on it. One of the figures is regular convex *n*-gon (regular convex polygon with *n* sides).
That's why Mister B decided to use this polygon. Now Mister B must find three distinct vertices *v*1, *v*2, *v*3 such that the angle (where *v*2 is the vertex of the angle, and *v*1 and *v*3 lie on its sides) is as close as possible to *a*. In other words, the value should be minimum possible.
If there are many optimal solutions, Mister B should be satisfied with any of them. | First and only line contains two space-separated integers *n* and *a* (3<=≤<=*n*<=≤<=105, 1<=≤<=*a*<=≤<=180) — the number of vertices in the polygon and the needed angle, in degrees. | Print three space-separated integers: the vertices *v*1, *v*2, *v*3, which form . If there are multiple optimal solutions, print any of them. The vertices are numbered from 1 to *n* in clockwise order. | [
"3 15\n",
"4 67\n",
"4 68\n"
] | [
"1 2 3\n",
"2 1 3\n",
"4 1 2\n"
] | In first sample test vertices of regular triangle can create only angle of 60 degrees, that's why every possible angle is correct.
Vertices of square can create 45 or 90 degrees angles only. That's why in second sample test the angle of 45 degrees was chosen, since |45 - 67| < |90 - 67|. Other correct answers are: "3 1 2", "3 2 4", "4 2 3", "4 3 1", "1 3 4", "1 4 2", "2 4 1", "4 1 3", "3 1 4", "3 4 2", "2 4 3", "2 3 1", "1 3 2", "1 2 4", "4 2 1".
In third sample test, on the contrary, the angle of 90 degrees was chosen, since |90 - 68| < |45 - 68|. Other correct answers are: "2 1 4", "3 2 1", "1 2 3", "4 3 2", "2 3 4", "1 4 3", "3 4 1". | 1,000 | [
{
"input": "3 15",
"output": "2 1 3"
},
{
"input": "4 67",
"output": "2 1 3"
},
{
"input": "4 68",
"output": "2 1 4"
},
{
"input": "3 1",
"output": "2 1 3"
},
{
"input": "3 180",
"output": "2 1 3"
},
{
"input": "100000 1",
"output": "2 1 558"
},
{
"input": "100000 180",
"output": "2 1 100000"
},
{
"input": "100000 42",
"output": "2 1 23335"
},
{
"input": "100000 123",
"output": "2 1 68335"
},
{
"input": "5 1",
"output": "2 1 3"
},
{
"input": "5 36",
"output": "2 1 3"
},
{
"input": "5 54",
"output": "2 1 3"
},
{
"input": "5 55",
"output": "2 1 4"
},
{
"input": "5 70",
"output": "2 1 4"
},
{
"input": "5 89",
"output": "2 1 4"
},
{
"input": "5 90",
"output": "2 1 4"
},
{
"input": "5 91",
"output": "2 1 5"
},
{
"input": "5 111",
"output": "2 1 5"
},
{
"input": "5 126",
"output": "2 1 5"
},
{
"input": "5 127",
"output": "2 1 5"
},
{
"input": "5 141",
"output": "2 1 5"
},
{
"input": "5 162",
"output": "2 1 5"
},
{
"input": "5 180",
"output": "2 1 5"
},
{
"input": "6 46",
"output": "2 1 4"
},
{
"input": "6 33",
"output": "2 1 3"
},
{
"input": "13 4",
"output": "2 1 3"
},
{
"input": "23 11",
"output": "2 1 3"
},
{
"input": "11 119",
"output": "2 1 9"
},
{
"input": "13 117",
"output": "2 1 10"
},
{
"input": "18 174",
"output": "2 1 18"
},
{
"input": "8509 139",
"output": "2 1 6573"
},
{
"input": "29770 76",
"output": "2 1 12572"
},
{
"input": "59115 40",
"output": "2 1 13139"
},
{
"input": "68459 88",
"output": "2 1 33471"
},
{
"input": "85100 129",
"output": "2 1 60990"
},
{
"input": "100000 13",
"output": "2 1 7224"
},
{
"input": "100000 35",
"output": "2 1 19446"
},
{
"input": "100000 49",
"output": "2 1 27224"
},
{
"input": "100000 71",
"output": "2 1 39446"
},
{
"input": "100000 79",
"output": "2 1 43891"
},
{
"input": "100000 101",
"output": "2 1 56113"
},
{
"input": "100000 109",
"output": "2 1 60558"
},
{
"input": "100000 143",
"output": "2 1 79446"
},
{
"input": "100000 148",
"output": "2 1 82224"
},
{
"input": "100000 176",
"output": "2 1 97780"
},
{
"input": "4 16",
"output": "2 1 3"
}
] | 1,498,577,582 | 3,482 | Python 3 | OK | TESTS | 46 | 62 | 5,529,600 | n,a = map(int,input().split())
k = round(n * a / 180)
if k == 0:
k = 1
elif k + 2 > n:
k = n - 2
print(1,2+k,1+k) | Title: Mister B and Angle in Polygon
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
On one quiet day all of sudden Mister B decided to draw angle *a* on his field. Aliens have already visited his field and left many different geometric figures on it. One of the figures is regular convex *n*-gon (regular convex polygon with *n* sides).
That's why Mister B decided to use this polygon. Now Mister B must find three distinct vertices *v*1, *v*2, *v*3 such that the angle (where *v*2 is the vertex of the angle, and *v*1 and *v*3 lie on its sides) is as close as possible to *a*. In other words, the value should be minimum possible.
If there are many optimal solutions, Mister B should be satisfied with any of them.
Input Specification:
First and only line contains two space-separated integers *n* and *a* (3<=≤<=*n*<=≤<=105, 1<=≤<=*a*<=≤<=180) — the number of vertices in the polygon and the needed angle, in degrees.
Output Specification:
Print three space-separated integers: the vertices *v*1, *v*2, *v*3, which form . If there are multiple optimal solutions, print any of them. The vertices are numbered from 1 to *n* in clockwise order.
Demo Input:
['3 15\n', '4 67\n', '4 68\n']
Demo Output:
['1 2 3\n', '2 1 3\n', '4 1 2\n']
Note:
In first sample test vertices of regular triangle can create only angle of 60 degrees, that's why every possible angle is correct.
Vertices of square can create 45 or 90 degrees angles only. That's why in second sample test the angle of 45 degrees was chosen, since |45 - 67| < |90 - 67|. Other correct answers are: "3 1 2", "3 2 4", "4 2 3", "4 3 1", "1 3 4", "1 4 2", "2 4 1", "4 1 3", "3 1 4", "3 4 2", "2 4 3", "2 3 1", "1 3 2", "1 2 4", "4 2 1".
In third sample test, on the contrary, the angle of 90 degrees was chosen, since |90 - 68| < |45 - 68|. Other correct answers are: "2 1 4", "3 2 1", "1 2 3", "4 3 2", "2 3 4", "1 4 3", "3 4 1". | ```python
n,a = map(int,input().split())
k = round(n * a / 180)
if k == 0:
k = 1
elif k + 2 > n:
k = n - 2
print(1,2+k,1+k)
``` | 3 |
Subsets and Splits