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
144
A
Arrival of the General
PROGRAMMING
800
[ "implementation" ]
null
null
A Ministry for Defense sent a general to inspect the Super Secret Military Squad under the command of the Colonel SuperDuper. Having learned the news, the colonel ordered to all *n* squad soldiers to line up on the parade ground. By the military charter the soldiers should stand in the order of non-increasing of their height. But as there's virtually no time to do that, the soldiers lined up in the arbitrary order. However, the general is rather short-sighted and he thinks that the soldiers lined up correctly if the first soldier in the line has the maximum height and the last soldier has the minimum height. Please note that the way other solders are positioned does not matter, including the case when there are several soldiers whose height is maximum or minimum. Only the heights of the first and the last soldier are important. For example, the general considers the sequence of heights (4, 3, 4, 2, 1, 1) correct and the sequence (4, 3, 1, 2, 2) wrong. Within one second the colonel can swap any two neighboring soldiers. Help him count the minimum time needed to form a line-up which the general will consider correct.
The first input line contains the only integer *n* (2<=≤<=*n*<=≤<=100) which represents the number of soldiers in the line. The second line contains integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) the values of the soldiers' heights in the order of soldiers' heights' increasing in the order from the beginning of the line to its end. The numbers are space-separated. Numbers *a*1,<=*a*2,<=...,<=*a**n* are not necessarily different.
Print the only integer — the minimum number of seconds the colonel will need to form a line-up the general will like.
[ "4\n33 44 11 22\n", "7\n10 10 58 31 63 40 76\n" ]
[ "2\n", "10\n" ]
In the first sample the colonel will need to swap the first and second soldier and then the third and fourth soldier. That will take 2 seconds. The resulting position of the soldiers is (44, 33, 22, 11). In the second sample the colonel may swap the soldiers in the following sequence: 1. (10, 10, 58, 31, 63, 40, 76) 1. (10, 58, 10, 31, 63, 40, 76) 1. (10, 58, 10, 31, 63, 76, 40) 1. (10, 58, 10, 31, 76, 63, 40) 1. (10, 58, 31, 10, 76, 63, 40) 1. (10, 58, 31, 76, 10, 63, 40) 1. (10, 58, 31, 76, 63, 10, 40) 1. (10, 58, 76, 31, 63, 10, 40) 1. (10, 76, 58, 31, 63, 10, 40) 1. (76, 10, 58, 31, 63, 10, 40) 1. (76, 10, 58, 31, 63, 40, 10)
500
[ { "input": "4\n33 44 11 22", "output": "2" }, { "input": "7\n10 10 58 31 63 40 76", "output": "10" }, { "input": "2\n88 89", "output": "1" }, { "input": "5\n100 95 100 100 88", "output": "0" }, { "input": "7\n48 48 48 48 45 45 45", "output": "0" }, { "input": "10\n68 47 67 29 63 71 71 65 54 56", "output": "10" }, { "input": "15\n77 68 96 60 92 75 61 60 66 79 80 65 60 95 92", "output": "4" }, { "input": "3\n1 2 1", "output": "1" }, { "input": "20\n30 30 30 14 30 14 30 30 30 14 30 14 14 30 14 14 30 14 14 14", "output": "0" }, { "input": "35\n37 41 46 39 47 39 44 47 44 42 44 43 47 39 46 39 38 42 39 37 40 44 41 42 41 42 39 42 36 36 42 36 42 42 42", "output": "7" }, { "input": "40\n99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 98 99 99 99 99 99 99 99 99 100 99 99 99 99 99 99", "output": "47" }, { "input": "50\n48 52 44 54 53 56 62 49 39 41 53 39 40 64 53 50 62 48 40 52 51 48 40 52 61 62 62 61 48 64 55 57 56 40 48 58 41 60 60 56 64 50 64 45 48 45 46 63 59 57", "output": "50" }, { "input": "57\n7 24 17 19 6 19 10 11 12 22 14 5 5 11 13 10 24 19 24 24 24 11 21 20 4 14 24 24 18 13 24 3 20 3 3 3 3 9 3 9 22 22 16 3 3 3 15 11 3 3 8 17 10 13 3 14 13", "output": "3" }, { "input": "65\n58 50 35 44 35 37 36 58 38 36 58 56 56 49 48 56 58 43 40 44 52 44 58 58 57 50 43 35 55 39 38 49 53 56 50 42 41 56 34 57 49 38 34 51 56 38 58 40 53 46 48 34 38 43 49 49 58 56 41 43 44 34 38 48 36", "output": "3" }, { "input": "69\n70 48 49 48 49 71 48 53 55 69 48 53 54 58 53 63 48 48 69 67 72 75 71 75 74 74 57 63 65 60 48 48 65 48 48 51 50 49 62 53 76 68 76 56 76 76 64 76 76 57 61 76 73 51 59 76 65 50 69 50 76 67 76 63 62 74 74 58 73", "output": "73" }, { "input": "75\n70 65 64 71 71 64 71 64 68 71 65 64 65 68 71 66 66 69 68 63 69 65 71 69 68 68 71 67 71 65 65 65 71 71 65 69 63 66 62 67 64 63 62 64 67 65 62 69 62 64 69 62 67 64 67 70 64 63 64 64 69 62 62 64 70 62 62 68 67 69 62 64 66 70 68", "output": "7" }, { "input": "84\n92 95 84 85 94 80 90 86 80 92 95 84 86 83 86 83 93 91 95 92 84 88 82 84 84 84 80 94 93 80 94 80 95 83 85 80 95 95 80 84 86 92 83 81 90 87 81 89 92 93 80 87 90 85 93 85 93 94 93 89 94 83 93 91 80 83 90 94 95 80 95 92 85 84 93 94 94 82 91 95 95 89 85 94", "output": "15" }, { "input": "90\n86 87 72 77 82 71 75 78 61 67 79 90 64 94 94 74 85 87 73 76 71 71 60 69 77 73 76 80 82 57 62 57 57 83 76 72 75 87 72 94 77 85 59 82 86 69 62 80 95 73 83 94 79 85 91 68 85 74 93 95 68 75 89 93 83 78 95 78 83 77 81 85 66 92 63 65 75 78 67 91 77 74 59 86 77 76 90 67 70 64", "output": "104" }, { "input": "91\n94 98 96 94 95 98 98 95 98 94 94 98 95 95 99 97 97 94 95 98 94 98 96 98 96 98 97 95 94 94 94 97 94 96 98 98 98 94 96 95 94 95 97 97 97 98 94 98 96 95 98 96 96 98 94 97 96 98 97 95 97 98 94 95 94 94 97 94 96 97 97 93 94 95 95 94 96 98 97 96 94 98 98 96 96 96 96 96 94 96 97", "output": "33" }, { "input": "92\n44 28 32 29 41 41 36 39 40 39 41 35 41 28 35 27 41 34 28 38 43 43 41 38 27 26 28 36 30 29 39 32 35 35 32 30 39 30 37 27 41 41 28 30 43 31 35 33 36 28 44 40 41 35 31 42 37 38 37 34 39 40 27 40 33 33 44 43 34 33 34 34 35 38 38 37 30 39 35 41 45 42 41 32 33 33 31 30 43 41 43 43", "output": "145" }, { "input": "93\n46 32 52 36 39 30 57 63 63 30 32 44 27 59 46 38 40 45 44 62 35 36 51 48 39 58 36 51 51 51 48 58 59 36 29 35 31 49 64 60 34 38 42 56 33 42 52 31 63 34 45 51 35 45 33 53 33 62 31 38 66 29 51 54 28 61 32 45 57 41 36 34 47 36 31 28 67 48 52 46 32 40 64 58 27 53 43 57 34 66 43 39 26", "output": "76" }, { "input": "94\n56 55 54 31 32 42 46 29 24 54 40 40 20 45 35 56 32 33 51 39 26 56 21 56 51 27 29 39 56 52 54 43 43 55 48 51 44 49 52 49 23 19 19 28 20 26 45 33 35 51 42 36 25 25 38 23 21 35 54 50 41 20 37 28 42 20 22 43 37 34 55 21 24 38 19 41 45 34 19 33 44 54 38 31 23 53 35 32 47 40 39 31 20 34", "output": "15" }, { "input": "95\n57 71 70 77 64 64 76 81 81 58 63 75 81 77 71 71 71 60 70 70 69 67 62 64 78 64 69 62 76 76 57 70 68 77 70 68 73 77 79 73 60 57 69 60 74 65 58 75 75 74 73 73 65 75 72 57 81 62 62 70 67 58 76 57 79 81 68 64 58 77 70 59 79 64 80 58 71 59 81 71 80 64 78 80 78 65 70 68 78 80 57 63 64 76 81", "output": "11" }, { "input": "96\n96 95 95 95 96 97 95 97 96 95 98 96 97 95 98 96 98 96 98 96 98 95 96 95 95 95 97 97 95 95 98 98 95 96 96 95 97 96 98 96 95 97 97 95 97 97 95 94 96 96 97 96 97 97 96 94 94 97 95 95 95 96 95 96 95 97 97 95 97 96 95 94 97 97 97 96 97 95 96 94 94 95 97 94 94 97 97 97 95 97 97 95 94 96 95 95", "output": "13" }, { "input": "97\n14 15 12 12 13 15 12 15 12 12 12 12 12 14 15 15 13 12 15 15 12 12 12 13 14 15 15 13 14 15 14 14 14 14 12 13 12 13 13 12 15 12 13 13 15 12 15 13 12 13 13 13 14 13 12 15 14 13 14 15 13 14 14 13 14 12 15 12 14 12 13 14 15 14 13 15 13 12 15 15 15 13 15 15 13 14 16 16 16 13 15 13 15 14 15 15 15", "output": "104" }, { "input": "98\n37 69 35 70 58 69 36 47 41 63 60 54 49 35 55 50 35 53 52 43 35 41 40 49 38 35 48 70 42 35 35 65 56 54 44 59 59 48 51 49 59 67 35 60 69 35 58 50 35 44 48 69 41 58 44 45 35 47 70 61 49 47 37 39 35 51 44 70 72 65 36 41 63 63 48 66 45 50 50 71 37 52 72 67 72 39 72 39 36 64 48 72 69 49 45 72 72 67", "output": "100" }, { "input": "99\n31 31 16 15 19 31 19 22 29 27 12 22 28 30 25 33 26 25 19 22 34 21 17 33 31 22 16 26 22 30 31 17 13 33 13 17 28 25 18 33 27 22 31 22 13 27 20 22 23 15 24 32 29 13 16 20 32 33 14 33 19 27 16 28 25 17 17 28 18 26 32 33 19 23 30 13 14 23 24 28 14 28 22 20 30 14 24 23 17 29 18 28 29 21 28 18 16 24 32", "output": "107" }, { "input": "100\n37 54 39 29 32 49 21 13 34 21 16 42 34 27 16 26 7 34 51 9 11 27 16 40 36 7 48 52 30 42 42 52 51 11 32 26 6 7 28 54 48 51 6 54 42 20 51 48 46 4 4 31 47 6 9 16 8 23 36 50 49 30 47 37 45 24 48 26 8 50 18 24 27 13 39 7 37 34 5 43 42 19 34 23 52 38 35 6 29 11 53 49 21 29 36 22 45 33 51 22", "output": "50" }, { "input": "100\n41 5 20 23 5 47 28 28 64 5 12 14 34 56 22 48 6 52 39 55 62 40 24 54 39 28 56 27 35 51 14 24 38 10 55 20 39 62 52 2 30 55 49 48 15 23 59 44 31 28 66 29 62 59 31 13 28 12 50 45 41 47 29 27 64 66 14 39 62 22 44 63 24 5 63 17 42 7 25 41 49 33 31 51 63 3 37 66 19 9 2 40 16 45 56 21 34 29 39 61", "output": "59" }, { "input": "100\n66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95", "output": "99" }, { "input": "100\n81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10", "output": "0" }, { "input": "3\n2 1 2", "output": "1" }, { "input": "2\n100 99", "output": "0" }, { "input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100", "output": "197" }, { "input": "100\n87 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 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", "output": "0" }, { "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": "0" }, { "input": "2\n1 1", "output": "0" }, { "input": "3\n2 2 2", "output": "0" }, { "input": "3\n1 3 2", "output": "2" } ]
1,695,035,686
2,147,483,647
Python 3
OK
TESTS
39
92
0
n = int(input()) x = list(map(int, input().split())) y = max(x); z = min(x) a = x.index(y); x.pop(a); x.insert(0,y) x.reverse() b = x.index(z) print(a+b)
Title: Arrival of the General Time Limit: None seconds Memory Limit: None megabytes Problem Description: A Ministry for Defense sent a general to inspect the Super Secret Military Squad under the command of the Colonel SuperDuper. Having learned the news, the colonel ordered to all *n* squad soldiers to line up on the parade ground. By the military charter the soldiers should stand in the order of non-increasing of their height. But as there's virtually no time to do that, the soldiers lined up in the arbitrary order. However, the general is rather short-sighted and he thinks that the soldiers lined up correctly if the first soldier in the line has the maximum height and the last soldier has the minimum height. Please note that the way other solders are positioned does not matter, including the case when there are several soldiers whose height is maximum or minimum. Only the heights of the first and the last soldier are important. For example, the general considers the sequence of heights (4, 3, 4, 2, 1, 1) correct and the sequence (4, 3, 1, 2, 2) wrong. Within one second the colonel can swap any two neighboring soldiers. Help him count the minimum time needed to form a line-up which the general will consider correct. Input Specification: The first input line contains the only integer *n* (2<=≤<=*n*<=≤<=100) which represents the number of soldiers in the line. The second line contains integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) the values of the soldiers' heights in the order of soldiers' heights' increasing in the order from the beginning of the line to its end. The numbers are space-separated. Numbers *a*1,<=*a*2,<=...,<=*a**n* are not necessarily different. Output Specification: Print the only integer — the minimum number of seconds the colonel will need to form a line-up the general will like. Demo Input: ['4\n33 44 11 22\n', '7\n10 10 58 31 63 40 76\n'] Demo Output: ['2\n', '10\n'] Note: In the first sample the colonel will need to swap the first and second soldier and then the third and fourth soldier. That will take 2 seconds. The resulting position of the soldiers is (44, 33, 22, 11). In the second sample the colonel may swap the soldiers in the following sequence: 1. (10, 10, 58, 31, 63, 40, 76) 1. (10, 58, 10, 31, 63, 40, 76) 1. (10, 58, 10, 31, 63, 76, 40) 1. (10, 58, 10, 31, 76, 63, 40) 1. (10, 58, 31, 10, 76, 63, 40) 1. (10, 58, 31, 76, 10, 63, 40) 1. (10, 58, 31, 76, 63, 10, 40) 1. (10, 58, 76, 31, 63, 10, 40) 1. (10, 76, 58, 31, 63, 10, 40) 1. (76, 10, 58, 31, 63, 10, 40) 1. (76, 10, 58, 31, 63, 40, 10)
```python n = int(input()) x = list(map(int, input().split())) y = max(x); z = min(x) a = x.index(y); x.pop(a); x.insert(0,y) x.reverse() b = x.index(z) print(a+b) ```
3
608
A
Saitama Destroys Hotel
PROGRAMMING
1,000
[ "implementation", "math" ]
null
null
Saitama accidentally destroyed a hotel again. To repay the hotel company, Genos has volunteered to operate an elevator in one of its other hotels. The elevator is special — it starts on the top floor, can only move down, and has infinite capacity. Floors are numbered from 0 to *s* and elevator initially starts on floor *s* at time 0. The elevator takes exactly 1 second to move down exactly 1 floor and negligible time to pick up passengers. Genos is given a list detailing when and on which floor passengers arrive. Please determine how long in seconds it will take Genos to bring all passengers to floor 0.
The first line of input contains two integers *n* and *s* (1<=≤<=*n*<=≤<=100, 1<=≤<=*s*<=≤<=1000) — the number of passengers and the number of the top floor respectively. The next *n* lines each contain two space-separated integers *f**i* and *t**i* (1<=≤<=*f**i*<=≤<=*s*, 1<=≤<=*t**i*<=≤<=1000) — the floor and the time of arrival in seconds for the passenger number *i*.
Print a single integer — the minimum amount of time in seconds needed to bring all the passengers to floor 0.
[ "3 7\n2 1\n3 8\n5 2\n", "5 10\n2 77\n3 33\n8 21\n9 12\n10 64\n" ]
[ "11\n", "79\n" ]
In the first sample, it takes at least 11 seconds to bring all passengers to floor 0. Here is how this could be done: 1. Move to floor 5: takes 2 seconds. 2. Pick up passenger 3. 3. Move to floor 3: takes 2 seconds. 4. Wait for passenger 2 to arrive: takes 4 seconds. 5. Pick up passenger 2. 6. Go to floor 2: takes 1 second. 7. Pick up passenger 1. 8. Go to floor 0: takes 2 seconds. This gives a total of 2 + 2 + 4 + 1 + 2 = 11 seconds.
500
[ { "input": "3 7\n2 1\n3 8\n5 2", "output": "11" }, { "input": "5 10\n2 77\n3 33\n8 21\n9 12\n10 64", "output": "79" }, { "input": "1 1000\n1000 1000", "output": "2000" }, { "input": "1 1\n1 1", "output": "2" }, { "input": "1 1000\n1 1", "output": "1000" }, { "input": "1 1000\n1 1000", "output": "1001" }, { "input": "100 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1", "output": "2" }, { "input": "2 7\n6 3\n1 5", "output": "9" }, { "input": "2 100\n99 2\n1 10", "output": "101" }, { "input": "5 5\n1 1\n2 1\n3 1\n4 1\n5 1", "output": "6" }, { "input": "3 7\n1 6\n5 5\n6 1", "output": "10" }, { "input": "2 100\n4 100\n7 99", "output": "106" }, { "input": "2 10\n9 3\n1 4", "output": "12" }, { "input": "2 5\n4 4\n5 4", "output": "9" }, { "input": "2 10\n9 10\n6 11", "output": "19" }, { "input": "2 100\n99 9\n1 10", "output": "108" }, { "input": "2 7\n3 5\n7 4", "output": "11" }, { "input": "4 4\n4 6\n4 8\n1 7\n2 9", "output": "12" }, { "input": "2 1000\n1 2\n1000 1", "output": "1001" }, { "input": "2 20\n1 1\n2 2", "output": "20" }, { "input": "2 20\n10 10\n19 9", "output": "28" } ]
1,594,736,298
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
93
6,963,200
# https://codeforces.com/problemset/problem/608/A # brute force, implementation # Gde Anantha Priharsena # 14 Juli 2020 # Approach : # difficulty : 1000 n,s = map(int,input().split()) passenger_floor = [0 for i in range(s+1)] floor_time = [0 for i in range(s+1)] for i in range(n) : f,t = map(int,input().split()) passenger_floor[f] = 1 floor_time[f] = t i = 7 total = 0 while i>0 : if floor_time[i] > 0 and floor_time[i] > total: total += (floor_time[i] - total) i -= 1 total += 1 print(total)
Title: Saitama Destroys Hotel Time Limit: None seconds Memory Limit: None megabytes Problem Description: Saitama accidentally destroyed a hotel again. To repay the hotel company, Genos has volunteered to operate an elevator in one of its other hotels. The elevator is special — it starts on the top floor, can only move down, and has infinite capacity. Floors are numbered from 0 to *s* and elevator initially starts on floor *s* at time 0. The elevator takes exactly 1 second to move down exactly 1 floor and negligible time to pick up passengers. Genos is given a list detailing when and on which floor passengers arrive. Please determine how long in seconds it will take Genos to bring all passengers to floor 0. Input Specification: The first line of input contains two integers *n* and *s* (1<=≤<=*n*<=≤<=100, 1<=≤<=*s*<=≤<=1000) — the number of passengers and the number of the top floor respectively. The next *n* lines each contain two space-separated integers *f**i* and *t**i* (1<=≤<=*f**i*<=≤<=*s*, 1<=≤<=*t**i*<=≤<=1000) — the floor and the time of arrival in seconds for the passenger number *i*. Output Specification: Print a single integer — the minimum amount of time in seconds needed to bring all the passengers to floor 0. Demo Input: ['3 7\n2 1\n3 8\n5 2\n', '5 10\n2 77\n3 33\n8 21\n9 12\n10 64\n'] Demo Output: ['11\n', '79\n'] Note: In the first sample, it takes at least 11 seconds to bring all passengers to floor 0. Here is how this could be done: 1. Move to floor 5: takes 2 seconds. 2. Pick up passenger 3. 3. Move to floor 3: takes 2 seconds. 4. Wait for passenger 2 to arrive: takes 4 seconds. 5. Pick up passenger 2. 6. Go to floor 2: takes 1 second. 7. Pick up passenger 1. 8. Go to floor 0: takes 2 seconds. This gives a total of 2 + 2 + 4 + 1 + 2 = 11 seconds.
```python # https://codeforces.com/problemset/problem/608/A # brute force, implementation # Gde Anantha Priharsena # 14 Juli 2020 # Approach : # difficulty : 1000 n,s = map(int,input().split()) passenger_floor = [0 for i in range(s+1)] floor_time = [0 for i in range(s+1)] for i in range(n) : f,t = map(int,input().split()) passenger_floor[f] = 1 floor_time[f] = t i = 7 total = 0 while i>0 : if floor_time[i] > 0 and floor_time[i] > total: total += (floor_time[i] - total) i -= 1 total += 1 print(total) ```
0
435
C
Cardiogram
PROGRAMMING
1,600
[ "implementation" ]
null
null
In this problem, your task is to use ASCII graphics to paint a cardiogram. A cardiogram is a polyline with the following corners: That is, a cardiogram is fully defined by a sequence of positive integers *a*1,<=*a*2,<=...,<=*a**n*. Your task is to paint a cardiogram by given sequence *a**i*.
The first line contains integer *n* (2<=≤<=*n*<=≤<=1000). The next line contains the sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000). It is guaranteed that the sum of all *a**i* doesn't exceed 1000.
Print *max* |*y**i*<=-<=*y**j*| lines (where *y**k* is the *y* coordinate of the *k*-th point of the polyline), in each line print characters. Each character must equal either «<=/<=» (slash), « \ » (backslash), « » (space). The printed image must be the image of the given polyline. Please study the test samples for better understanding of how to print a cardiogram. Note that in this problem the checker checks your answer taking spaces into consideration. Do not print any extra characters. Remember that the wrong answer to the first pretest doesn't give you a penalty.
[ "5\n3 1 2 5 1\n", "3\n1 5 1\n" ]
[ "/ \\ \n  / \\ /  \\ \n  /  \\ \n /  \\ \n \\ / \n", "/ \\ \n \\ \n \\ \n \\ \n \\ / \n" ]
Due to the technical reasons the answers for the samples cannot be copied from the statement. We've attached two text documents with the answers below. http://assets.codeforces.com/rounds/435/1.txt http://assets.codeforces.com/rounds/435/2.txt
1,500
[ { "input": "5\n3 1 2 5 1", "output": " /\\ \n /\\/ \\ \n / \\ \n/ \\ \n \\/" }, { "input": "3\n1 5 1", "output": "/\\ \n \\ \n \\ \n \\ \n \\/" }, { "input": "2\n1 1", "output": "/\\" }, { "input": "2\n2 1", "output": " /\\\n/ " }, { "input": "2\n1 2", "output": "/\\ \n \\" }, { "input": "2\n2 2", "output": " /\\ \n/ \\" }, { "input": "3\n1 1 1", "output": "/\\/" }, { "input": "100\n14 6 10 12 11 12 6 19 12 7 10 17 8 10 10 5 9 6 9 14 15 5 9 11 8 12 14 15 9 9 9 11 13 15 11 10 4 10 8 7 13 11 17 10 14 14 15 8 10 7 12 8 7 15 13 8 7 13 5 11 12 8 9 8 7 16 11 10 10 15 9 11 2 12 12 9 9 13 7 6 9 7 8 7 4 6 15 6 8 11 7 10 11 9 17 8 8 5 9 9", "output": " /\\ ..." }, { "input": "2\n478 522", "output": " /\\ ..." }, { "input": "3\n328 341 331", "output": " /\\ ..." }, { "input": "4\n253 250 261 236", "output": " ..." }, { "input": "5\n198 213 195 189 205", "output": " /\\ ..." }, { "input": "6\n163 170 175 168 172 152", "output": " ..." }, { "input": "7\n154 157 138 129 136 148 138", "output": " /\\ ..." }, { "input": "8\n117 140 141 105 129 127 122 118", "output": " ..." }, { "input": "9\n96 114 117 124 114 107 126 95 105", "output": " ..." }, { "input": "4\n1 1 1 1", "output": "/\\/\\" }, { "input": "4\n1 1 2 1", "output": " /\\\n/\\/ " }, { "input": "4\n1 1 2 2", "output": " /\\ \n/\\/ \\" }, { "input": "4\n1 2 2 2", "output": "/\\ /\\ \n \\/ \\" }, { "input": "4\n2 2 2 2", "output": " /\\ /\\ \n/ \\/ \\" }, { "input": "5\n1 1 1 1 1", "output": "/\\/\\/" }, { "input": "5\n1 2 1 1 1", "output": "/\\ \n \\/\\/" }, { "input": "5\n2 1 1 2 1", "output": " /\\/\\ \n/ \\/" }, { "input": "5\n2 1 1 1 3", "output": " /\n / \n /\\/\\/ \n/ " }, { "input": "5\n2 2 1 2 2", "output": " /\\ \n/ \\/\\ /\n \\/ " }, { "input": "5\n2 1 2 3 2", "output": " /\\ \n /\\/ \\ /\n/ \\/ " }, { "input": "2\n500 500", "output": " /\\ ..." }, { "input": "3\n1 499 500", "output": " ..." }, { "input": "6\n1 200 1 200 1 200", "output": "/\\ ..." }, { "input": "6\n200 1 200 1 200 1", "output": " ..." }, { "input": "123\n2 5 7 7 3 7 8 7 6 6 7 10 7 8 7 4 6 6 7 6 6 6 5 8 9 6 3 3 5 5 6 7 7 8 8 6 4 1 3 8 9 9 3 4 5 6 6 7 9 9 4 7 7 6 3 9 7 7 6 3 6 5 3 7 7 1 6 5 10 4 5 6 3 7 7 7 4 7 7 8 6 10 9 5 5 6 5 4 5 7 3 6 7 8 3 5 6 5 4 5 5 9 5 4 9 6 3 4 7 5 7 2 3 10 5 8 5 5 5 9 3 6 7", "output": " /\\ ..." }, { "input": "23\n33 42 55 36 37 42 36 39 35 27 38 38 31 33 26 40 20 32 45 32 31 35 36", "output": " /\\ ..." }, { "input": "3\n2 1 1", "output": " /\\/\n/ " }, { "input": "3\n1 1 2", "output": " /\n/\\/ " }, { "input": "3\n1 2 1", "output": "/\\ \n \\/" }, { "input": "3\n1 2 2", "output": "/\\ /\n \\/ " }, { "input": "3\n2 2 1", "output": " /\\ \n/ \\/" }, { "input": "3\n2 1 2", "output": " /\n /\\/ \n/ " }, { "input": "3\n2 2 2", "output": " /\\ /\n/ \\/ " }, { "input": "2\n999 1", "output": " ..." }, { "input": "2\n1 999", "output": "/\\ ..." }, { "input": "3\n10 1 10", "output": " /\n / \n / \n / \n / \n / \n / \n / \n / \n /\\/ \n / \n / \n / \n / \n / \n / \n / \n / \n/ " } ]
1,401,469,308
5,508
Python 3
OK
TESTS
46
171
4,403,200
import operator n = int(input()) points = list(map(int, input().split())) def praf(g): for i in g[1:]: print(''.join(i)) def calc(n): global points a = b = 0 step = 1 for i in range(n): a += points[i] b += points[i] * step step = -step return (a, b) seq = [(0, 0)] for i in range(len(points)): seq.append(calc(i+1)) seq = sorted(seq, key=lambda x: x[0]) seq = {i: seq[i] for i in range(len(seq))} #print(seq) for i in range(len(seq)): r = 0 if i != len(seq)-1: if seq[i][1] > seq[i+1][1]: r = -1 else: r = 1 seq[i] = seq[i] + tuple([r]) seqy = sorted(seq.items(), key=lambda x: x[1][1], reverse=True) pts = {x[0]: x[2] for x in seq.values()} pts[seq[len(seq)-1][0]] = 1 #print('---seq---') #print(seq) #print('----seqy---') #print(seqy) #print('---pts---') #print(pts) graph = [[' '] * seq[len(seq)-1][0] for x in range(seqy[0][1][1]-seqy[-1][1][1]+1)] y = seqy[0][1][1] way = pts[0] for i in range(len(graph[0])): if i in pts.keys(): if pts[i] != way: if way == 1: y+=1 else: y-=1 way = pts[i] graph[y][i] = '/' if way == 1 else '\\' y -= way # praf(graph) #print('----------------graph-----------------------------------------------------------') praf(graph) #praf(graph)
Title: Cardiogram Time Limit: None seconds Memory Limit: None megabytes Problem Description: In this problem, your task is to use ASCII graphics to paint a cardiogram. A cardiogram is a polyline with the following corners: That is, a cardiogram is fully defined by a sequence of positive integers *a*1,<=*a*2,<=...,<=*a**n*. Your task is to paint a cardiogram by given sequence *a**i*. Input Specification: The first line contains integer *n* (2<=≤<=*n*<=≤<=1000). The next line contains the sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000). It is guaranteed that the sum of all *a**i* doesn't exceed 1000. Output Specification: Print *max* |*y**i*<=-<=*y**j*| lines (where *y**k* is the *y* coordinate of the *k*-th point of the polyline), in each line print characters. Each character must equal either «<=/<=» (slash), « \ » (backslash), « » (space). The printed image must be the image of the given polyline. Please study the test samples for better understanding of how to print a cardiogram. Note that in this problem the checker checks your answer taking spaces into consideration. Do not print any extra characters. Remember that the wrong answer to the first pretest doesn't give you a penalty. Demo Input: ['5\n3 1 2 5 1\n', '3\n1 5 1\n'] Demo Output: ['/\u2009\\ \n \u2009/\u2009\\\u2009/\u2009 \\ \n \u2009/\u2009 \\ \n\u2009/\u2009 \\ \n \\\u2009/\u2009\n', '/\u2009\\ \n \\ \n \\ \n \\ \n \\\u2009/\u2009\n'] Note: Due to the technical reasons the answers for the samples cannot be copied from the statement. We've attached two text documents with the answers below. http://assets.codeforces.com/rounds/435/1.txt http://assets.codeforces.com/rounds/435/2.txt
```python import operator n = int(input()) points = list(map(int, input().split())) def praf(g): for i in g[1:]: print(''.join(i)) def calc(n): global points a = b = 0 step = 1 for i in range(n): a += points[i] b += points[i] * step step = -step return (a, b) seq = [(0, 0)] for i in range(len(points)): seq.append(calc(i+1)) seq = sorted(seq, key=lambda x: x[0]) seq = {i: seq[i] for i in range(len(seq))} #print(seq) for i in range(len(seq)): r = 0 if i != len(seq)-1: if seq[i][1] > seq[i+1][1]: r = -1 else: r = 1 seq[i] = seq[i] + tuple([r]) seqy = sorted(seq.items(), key=lambda x: x[1][1], reverse=True) pts = {x[0]: x[2] for x in seq.values()} pts[seq[len(seq)-1][0]] = 1 #print('---seq---') #print(seq) #print('----seqy---') #print(seqy) #print('---pts---') #print(pts) graph = [[' '] * seq[len(seq)-1][0] for x in range(seqy[0][1][1]-seqy[-1][1][1]+1)] y = seqy[0][1][1] way = pts[0] for i in range(len(graph[0])): if i in pts.keys(): if pts[i] != way: if way == 1: y+=1 else: y-=1 way = pts[i] graph[y][i] = '/' if way == 1 else '\\' y -= way # praf(graph) #print('----------------graph-----------------------------------------------------------') praf(graph) #praf(graph) ```
3
681
B
Economy Game
PROGRAMMING
1,300
[ "brute force" ]
null
null
Kolya is developing an economy simulator game. His most favourite part of the development process is in-game testing. Once he was entertained by the testing so much, that he found out his game-coin score become equal to 0. Kolya remembers that at the beginning of the game his game-coin score was equal to *n* and that he have bought only some houses (for 1<=234<=567 game-coins each), cars (for 123<=456 game-coins each) and computers (for 1<=234 game-coins each). Kolya is now interested, whether he could have spent all of his initial *n* game-coins buying only houses, cars and computers or there is a bug in the game. Formally, is there a triple of non-negative integers *a*, *b* and *c* such that *a*<=×<=1<=234<=567<=+<=*b*<=×<=123<=456<=+<=*c*<=×<=1<=234<==<=*n*? Please help Kolya answer this question.
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=109) — Kolya's initial game-coin score.
Print "YES" (without quotes) if it's possible that Kolya spent all of his initial *n* coins buying only houses, cars and computers. Otherwise print "NO" (without quotes).
[ "1359257\n", "17851817\n" ]
[ "YES", "NO" ]
In the first sample, one of the possible solutions is to buy one house, one car and one computer, spending 1 234 567 + 123 456 + 1234 = 1 359 257 game-coins in total.
1,000
[ { "input": "1359257", "output": "YES" }, { "input": "17851817", "output": "NO" }, { "input": "1000000000", "output": "YES" }, { "input": "17851818", "output": "YES" }, { "input": "438734347", "output": "YES" }, { "input": "43873430", "output": "YES" }, { "input": "999999987", "output": "YES" }, { "input": "27406117", "output": "NO" }, { "input": "27404883", "output": "NO" }, { "input": "27403649", "output": "NO" }, { "input": "27402415", "output": "NO" }, { "input": "27401181", "output": "NO" }, { "input": "999999999", "output": "YES" }, { "input": "999999244", "output": "YES" }, { "input": "999129999", "output": "YES" }, { "input": "17159199", "output": "NO" }, { "input": "13606913", "output": "NO" }, { "input": "14841529", "output": "NO" }, { "input": "915968473", "output": "YES" }, { "input": "980698615", "output": "YES" }, { "input": "912331505", "output": "YES" }, { "input": "917261049", "output": "YES" }, { "input": "999999997", "output": "YES" }, { "input": "12345", "output": "NO" }, { "input": "1234", "output": "YES" }, { "input": "124690", "output": "YES" }, { "input": "1359257", "output": "YES" }, { "input": "1358023", "output": "YES" }, { "input": "1234", "output": "YES" }, { "input": "1234567", "output": "YES" }, { "input": "124690", "output": "YES" }, { "input": "1358023", "output": "YES" }, { "input": "123456", "output": "YES" }, { "input": "2592590", "output": "YES" }, { "input": "999999998", "output": "YES" }, { "input": "1356789", "output": "NO" }, { "input": "12345670", "output": "YES" }, { "input": "11", "output": "NO" }, { "input": "1480800", "output": "YES" }, { "input": "908000000", "output": "YES" }, { "input": "3000", "output": "NO" }, { "input": "1235801", "output": "YES" }, { "input": "991919191", "output": "YES" }, { "input": "25613715", "output": "YES" }, { "input": "13580237", "output": "YES" }, { "input": "14814804", "output": "YES" }, { "input": "11403961", "output": "YES" }, { "input": "999999989", "output": "YES" }, { "input": "1237035", "output": "YES" }, { "input": "81134231", "output": "YES" }, { "input": "1236", "output": "NO" }, { "input": "1359250", "output": "YES" }, { "input": "100", "output": "NO" }, { "input": "987654321", "output": "YES" }, { "input": "122222", "output": "NO" }, { "input": "123458", "output": "NO" }, { "input": "20987639", "output": "YES" }, { "input": "999973333", "output": "YES" }, { "input": "253082", "output": "YES" }, { "input": "1235", "output": "NO" }, { "input": "803219200", "output": "YES" }, { "input": "100000000", "output": "YES" }, { "input": "1485181", "output": "YES" } ]
1,560,361,523
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
77
0
def economic_game(n): for i in range(n + 1, 1234567): for j in range(n + 1 - i, 123456): if (n - (i + j)) % 1234 == 0: return "YES" return "NO" print(economic_game(int(input())))
Title: Economy Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Kolya is developing an economy simulator game. His most favourite part of the development process is in-game testing. Once he was entertained by the testing so much, that he found out his game-coin score become equal to 0. Kolya remembers that at the beginning of the game his game-coin score was equal to *n* and that he have bought only some houses (for 1<=234<=567 game-coins each), cars (for 123<=456 game-coins each) and computers (for 1<=234 game-coins each). Kolya is now interested, whether he could have spent all of his initial *n* game-coins buying only houses, cars and computers or there is a bug in the game. Formally, is there a triple of non-negative integers *a*, *b* and *c* such that *a*<=×<=1<=234<=567<=+<=*b*<=×<=123<=456<=+<=*c*<=×<=1<=234<==<=*n*? Please help Kolya answer this question. Input Specification: The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=109) — Kolya's initial game-coin score. Output Specification: Print "YES" (without quotes) if it's possible that Kolya spent all of his initial *n* coins buying only houses, cars and computers. Otherwise print "NO" (without quotes). Demo Input: ['1359257\n', '17851817\n'] Demo Output: ['YES', 'NO'] Note: In the first sample, one of the possible solutions is to buy one house, one car and one computer, spending 1 234 567 + 123 456 + 1234 = 1 359 257 game-coins in total.
```python def economic_game(n): for i in range(n + 1, 1234567): for j in range(n + 1 - i, 123456): if (n - (i + j)) % 1234 == 0: return "YES" return "NO" print(economic_game(int(input()))) ```
0
222
E
Decoding Genome
PROGRAMMING
1,900
[ "dp", "matrices" ]
null
null
Recently a top secret mission to Mars has taken place. As a result, scientists managed to obtain some information about the Martian DNA. Now we know that any Martian DNA contains at most *m* different nucleotides, numbered from 1 to *m*. Special characteristics of the Martian DNA prevent some nucleotide pairs from following consecutively in this chain. For example, if the nucleotide 1 and nucleotide 2 can not follow consecutively in the Martian DNA, then the chain of nucleotides [1, 2] is not a valid chain of Martian DNA, but the chain of nucleotides [2, 1] can be a valid chain (if there is no corresponding restriction). The number of nucleotide pairs that can't follow in the DNA chain consecutively, is *k*. The needs of gene research required information about the quantity of correct *n*-long chains of the Martian DNA. Your task is to write a program that will calculate this value.
The first line contains three space-separated integers *n*,<=*m*,<=*k* (1<=≤<=*n*<=≤<=1015, 1<=≤<=*m*<=≤<=52, 0<=≤<=*k*<=≤<=*m*2). Next *k* lines contain two characters each, without a space between them, representing a forbidden nucleotide pair. The first character represents the first nucleotide in the forbidden pair, the second character represents the second nucleotide. The nucleotides with assigned numbers from 1 to 26 are represented by English alphabet letters from "a" to "z" (1 is an "a", 2 is a "b", ..., 26 is a "z"). Nucleotides with assigned numbers from 27 to 52 are represented by English alphabet letters from "A" to "Z" (27 is an "A", 28 is a "B", ..., 52 is a "Z"). It is guaranteed that each forbidden pair occurs at most once in the input. It is guaranteed that nucleotide's numbers in all forbidden pairs cannot be more than *m*. Note that order is important in nucleotide pairs. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.
Print a single integer — the sought number modulo 1000000007 (109<=+<=7).
[ "3 3 2\nab\nba\n", "3 3 0\n", "2 1 1\naa\n" ]
[ "17\n", "27\n", "0\n" ]
In the second test case all possible three-nucleotide DNAs are permitted. Each nucleotide can take one of three values, thus in total there are 27 distinct three nucleotide DNAs. In the third test sample we cannot make any DNA of two nucleotides — the only possible nucleotide "a" cannot occur two times consecutively.
2,500
[ { "input": "3 3 2\nab\nba", "output": "17" }, { "input": "3 3 0", "output": "27" }, { "input": "2 1 1\naa", "output": "0" }, { "input": "3 5 4\ncd\nce\ned\nee", "output": "89" }, { "input": "100 5 4\ncd\nce\ned\nee", "output": "537303881" }, { "input": "1 2 4\naa\nbb\nab\nba", "output": "2" }, { "input": "2 2 4\naa\nbb\nab\nba", "output": "0" }, { "input": "3 3 6\naa\nab\nac\nbb\nbc\ncc", "output": "1" }, { "input": "4 4 13\naa\nbc\nad\nac\nbb\nba\nda\ndb\ndd\ncc\nca\ncb\ncd", "output": "1" }, { "input": "2 3 7\naa\nac\nba\nbb\ncc\nca\ncb", "output": "2" }, { "input": "3 3 7\naa\nac\nba\nbb\ncc\nca\ncb", "output": "1" }, { "input": "4 3 7\naa\nac\nba\nbb\ncc\nca\ncb", "output": "0" }, { "input": "1 52 2\naA\nAa", "output": "52" }, { "input": "100000 52 0", "output": "378241178" }, { "input": "10000 52 10\nEN\nYJ\nKH\nGa\nQA\njY\nYf\nSt\nap\nDT", "output": "671474539" }, { "input": "1000000000000 2 0", "output": "959366170" }, { "input": "100 3 6\naa\nab\nac\nbb\nbc\ncc", "output": "0" }, { "input": "1000 10 20\naa\nbb\ncc\ndd\nee\nff\ngg\nhh\nii\njj\nab\nbc\ncd\nde\nef\nfg\ngh\nhi\nij\nja", "output": "207125595" }, { "input": "5000 3 0", "output": "22443616" }, { "input": "5000 4 7\naa\nab\nac\nad\nba\nca\nda", "output": "22443616" }, { "input": "5000 4 6\nab\nac\nad\nba\nca\nda", "output": "22443617" }, { "input": "10000 5 4\nce\nee\ncd\ned", "output": "386438816" }, { "input": "50000 52 10\nAa\naA\nBy\ntS\nzA\nZu\nyy\nUU\nen\neq", "output": "447275409" }, { "input": "1000000000000 3 5\naa\nab\nac\nba\nca", "output": "959366170" }, { "input": "1000000000000 3 3\naa\nab\nac", "output": "439049248" }, { "input": "1000000000000 3 4\nab\nac\nba\nca", "output": "959366171" }, { "input": "1000000000000 4 9\naa\nab\nac\nad\nbb\nbc\nbd\ncc\ncd", "output": "8" }, { "input": "1000000000000000 52 0", "output": "588668785" }, { "input": "1000000000000000 52 26\naa\nbb\ncc\ndd\nee\nff\ngg\nhh\nii\njj\nkk\nll\nmm\nnn\noo\npp\nqq\nrr\nss\ntt\nuu\nvv\nww\nxx\nyy\nzz", "output": "271910099" }, { "input": "298470512649 26 20\nav\nsf\nqq\nyt\ncz\nkl\nqw\nwe\ner\nrt\nty\nfg\nin\nxy\nbt\nmm\njm\ndp\nno\nuy", "output": "399097981" }, { "input": "10000000000 20 15\nhs\npm\ncd\ner\nht\nmk\nce\nad\nfe\nmj\npf\nlm\nmo\nkd\nde", "output": "768931983" }, { "input": "1000000000000000 26 2\nfj\nho", "output": "688841650" }, { "input": "1000000000000000 10 0", "output": "478484352" }, { "input": "1000000000000000 10 1\ncd", "output": "82984398" }, { "input": "1000000000000000 12 3\nce\ndg\nfb", "output": "792123851" }, { "input": "853332331434235 35 77\nBy\nhs\nzB\njs\nIr\nEa\nHG\nxb\nxG\nFp\nAC\nDt\nwo\nFB\nzh\nim\ntx\nyi\ngC\nkp\njz\ndc\nwE\naa\nsG\nng\ncr\npB\nCg\ncv\nxs\nDn\ndg\nyj\nCd\naC\nIi\ngH\nml\nww\nAD\nir\nti\nEr\nCj\nHt\nAe\nsn\naH\nHv\nan\nDf\nGn\nfC\nay\ngB\nlh\nup\nda\nzs\nbh\nHB\nHd\nmg\nzy\nGi\nzm\nHq\nac\nCB\niE\ncc\nfi\ngm\nHf\neD\nqA", "output": "351800015" } ]
1,551,951,443
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
14
2,000
1,536,000
# How many ways to generate length-N array where elements can take one of m values (m <= 52; denoted a..z,A..Z) # s.t. none of k ordered value pair appears: # e.g. ab = ab can't appear but ba can; aa = aa can't appear # Input: N (N < 10^18), m (n<=52), k patterns 0 <= k <= m^2 # E.g. # N=3, m=3, k=2 # ab # ba # -> return 17 # Ideas # * divide and conquer # * for each n, memo[n][i][j] = number of paths of length n satisfying bans, that start at i and end at j MOD = 1000000007 def _solve(n, m, ban, memo): if n in memo: return memo[n] if n == 0: return [[0]*m for _ in range(m)] if n == 1: memo[n] = [[0]*m for _ in range(m)] for i in range(m): memo[n][i][i] = 1 return memo[n] left, right = _solve(n // 2, m, ban, memo), _solve(n - n // 2, m, ban, memo) memo[n] = [[0]*m for _ in range(m)] # count all paths starting at i, ending at j for i in range(m): for j in range(m): memo[n][i][j] = sum(left[i])*sum(right[s][j] for s in range(m)) % MOD # subtract left path ending at x * right path ending at y for each banned pair (x, y) for x, y in ban: for i in range(m): for j in range(m): memo[n][i][j] -= left[i][x] * right[y][j] % MOD memo[n][i][j] += MOD memo[n][i][j] %= MOD return memo[n] def solve(n, m, ban): counts = _solve(n, m, ban, {}) return sum(sum(row) for row in counts)%MOD def main(): from sys import stdin n, m, k = list(map(int, stdin.readline().strip().split())) ban = set() for _ in range(k): x, y = list(stdin.readline().strip()) x = ord(x)-97 if 'a' <= x <= 'z' else ord(x)-39 y = ord(y)-97 if 'a' <= y <= 'z' else ord(y)-39 ban.add((x,y)) out = solve(n, m, ban) print('{}'.format(out)) if __name__ == '__main__': main()
Title: Decoding Genome Time Limit: None seconds Memory Limit: None megabytes Problem Description: Recently a top secret mission to Mars has taken place. As a result, scientists managed to obtain some information about the Martian DNA. Now we know that any Martian DNA contains at most *m* different nucleotides, numbered from 1 to *m*. Special characteristics of the Martian DNA prevent some nucleotide pairs from following consecutively in this chain. For example, if the nucleotide 1 and nucleotide 2 can not follow consecutively in the Martian DNA, then the chain of nucleotides [1, 2] is not a valid chain of Martian DNA, but the chain of nucleotides [2, 1] can be a valid chain (if there is no corresponding restriction). The number of nucleotide pairs that can't follow in the DNA chain consecutively, is *k*. The needs of gene research required information about the quantity of correct *n*-long chains of the Martian DNA. Your task is to write a program that will calculate this value. Input Specification: The first line contains three space-separated integers *n*,<=*m*,<=*k* (1<=≤<=*n*<=≤<=1015, 1<=≤<=*m*<=≤<=52, 0<=≤<=*k*<=≤<=*m*2). Next *k* lines contain two characters each, without a space between them, representing a forbidden nucleotide pair. The first character represents the first nucleotide in the forbidden pair, the second character represents the second nucleotide. The nucleotides with assigned numbers from 1 to 26 are represented by English alphabet letters from "a" to "z" (1 is an "a", 2 is a "b", ..., 26 is a "z"). Nucleotides with assigned numbers from 27 to 52 are represented by English alphabet letters from "A" to "Z" (27 is an "A", 28 is a "B", ..., 52 is a "Z"). It is guaranteed that each forbidden pair occurs at most once in the input. It is guaranteed that nucleotide's numbers in all forbidden pairs cannot be more than *m*. Note that order is important in nucleotide pairs. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. Output Specification: Print a single integer — the sought number modulo 1000000007 (109<=+<=7). Demo Input: ['3 3 2\nab\nba\n', '3 3 0\n', '2 1 1\naa\n'] Demo Output: ['17\n', '27\n', '0\n'] Note: In the second test case all possible three-nucleotide DNAs are permitted. Each nucleotide can take one of three values, thus in total there are 27 distinct three nucleotide DNAs. In the third test sample we cannot make any DNA of two nucleotides — the only possible nucleotide "a" cannot occur two times consecutively.
```python # How many ways to generate length-N array where elements can take one of m values (m <= 52; denoted a..z,A..Z) # s.t. none of k ordered value pair appears: # e.g. ab = ab can't appear but ba can; aa = aa can't appear # Input: N (N < 10^18), m (n<=52), k patterns 0 <= k <= m^2 # E.g. # N=3, m=3, k=2 # ab # ba # -> return 17 # Ideas # * divide and conquer # * for each n, memo[n][i][j] = number of paths of length n satisfying bans, that start at i and end at j MOD = 1000000007 def _solve(n, m, ban, memo): if n in memo: return memo[n] if n == 0: return [[0]*m for _ in range(m)] if n == 1: memo[n] = [[0]*m for _ in range(m)] for i in range(m): memo[n][i][i] = 1 return memo[n] left, right = _solve(n // 2, m, ban, memo), _solve(n - n // 2, m, ban, memo) memo[n] = [[0]*m for _ in range(m)] # count all paths starting at i, ending at j for i in range(m): for j in range(m): memo[n][i][j] = sum(left[i])*sum(right[s][j] for s in range(m)) % MOD # subtract left path ending at x * right path ending at y for each banned pair (x, y) for x, y in ban: for i in range(m): for j in range(m): memo[n][i][j] -= left[i][x] * right[y][j] % MOD memo[n][i][j] += MOD memo[n][i][j] %= MOD return memo[n] def solve(n, m, ban): counts = _solve(n, m, ban, {}) return sum(sum(row) for row in counts)%MOD def main(): from sys import stdin n, m, k = list(map(int, stdin.readline().strip().split())) ban = set() for _ in range(k): x, y = list(stdin.readline().strip()) x = ord(x)-97 if 'a' <= x <= 'z' else ord(x)-39 y = ord(y)-97 if 'a' <= y <= 'z' else ord(y)-39 ban.add((x,y)) out = solve(n, m, ban) print('{}'.format(out)) if __name__ == '__main__': main() ```
0
6
C
Alice, Bob and Chocolate
PROGRAMMING
1,200
[ "greedy", "two pointers" ]
C. Alice, Bob and Chocolate
2
64
Alice and Bob like games. And now they are ready to start a new game. They have placed *n* chocolate bars in a line. Alice starts to eat chocolate bars one by one from left to right, and Bob — from right to left. For each chocololate bar the time, needed for the player to consume it, is known (Alice and Bob eat them with equal speed). When the player consumes a chocolate bar, he immediately starts with another. It is not allowed to eat two chocolate bars at the same time, to leave the bar unfinished and to make pauses. If both players start to eat the same bar simultaneously, Bob leaves it to Alice as a true gentleman. How many bars each of the players will consume?
The first line contains one integer *n* (1<=≤<=*n*<=≤<=105) — the amount of bars on the table. The second line contains a sequence *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=1000), where *t**i* is the time (in seconds) needed to consume the *i*-th bar (in the order from left to right).
Print two numbers *a* and *b*, where *a* is the amount of bars consumed by Alice, and *b* is the amount of bars consumed by Bob.
[ "5\n2 9 8 2 7\n" ]
[ "2 3\n" ]
none
0
[ { "input": "5\n2 9 8 2 7", "output": "2 3" }, { "input": "1\n1", "output": "1 0" }, { "input": "2\n1 1", "output": "1 1" }, { "input": "3\n1 1 1", "output": "2 1" }, { "input": "4\n1 1 1 1", "output": "2 2" }, { "input": "1\n6", "output": "1 0" }, { "input": "2\n8 2", "output": "1 1" }, { "input": "3\n6 8 4", "output": "1 2" }, { "input": "4\n4 3 2 8", "output": "3 1" }, { "input": "5\n1 9 8 2 7", "output": "2 3" }, { "input": "6\n1 4 7 3 2 1", "output": "3 3" }, { "input": "11\n7 9 1 8 7 1 7 1 4 8 1", "output": "4 7" }, { "input": "12\n4 2 7 1 9 5 6 2 7 8 5 7", "output": "7 5" }, { "input": "13\n9 9 9 9 9 9 9 9 9 9 9 9 9", "output": "7 6" } ]
1,613,749,508
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
124
307,200
n = int(input()) A = list(map(int, input().split())) l = 0 r = n-1 alice = 0 bob = 0 p = 0 for i in range(n): if (A[r] == A[l]): alice += 1 bob += 1 l += 1 r -= 1 p = 2 elif A[l] == max(A[l], A[r]): bob += 1 A[l] = A[l] - A[r] A[r] = 0 r -= 1 p = 2 elif A[r] == max(A[l], A[r]): alice += 1 A[r] = A[r] - A[l] A[l] = 0 l += 1 p = 1 if l == r: if p == 1: bob += 1 if p == 2 or p == 0: alice += 1 break print(alice, bob)
Title: Alice, Bob and Chocolate Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: Alice and Bob like games. And now they are ready to start a new game. They have placed *n* chocolate bars in a line. Alice starts to eat chocolate bars one by one from left to right, and Bob — from right to left. For each chocololate bar the time, needed for the player to consume it, is known (Alice and Bob eat them with equal speed). When the player consumes a chocolate bar, he immediately starts with another. It is not allowed to eat two chocolate bars at the same time, to leave the bar unfinished and to make pauses. If both players start to eat the same bar simultaneously, Bob leaves it to Alice as a true gentleman. How many bars each of the players will consume? Input Specification: The first line contains one integer *n* (1<=≤<=*n*<=≤<=105) — the amount of bars on the table. The second line contains a sequence *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=1000), where *t**i* is the time (in seconds) needed to consume the *i*-th bar (in the order from left to right). Output Specification: Print two numbers *a* and *b*, where *a* is the amount of bars consumed by Alice, and *b* is the amount of bars consumed by Bob. Demo Input: ['5\n2 9 8 2 7\n'] Demo Output: ['2 3\n'] Note: none
```python n = int(input()) A = list(map(int, input().split())) l = 0 r = n-1 alice = 0 bob = 0 p = 0 for i in range(n): if (A[r] == A[l]): alice += 1 bob += 1 l += 1 r -= 1 p = 2 elif A[l] == max(A[l], A[r]): bob += 1 A[l] = A[l] - A[r] A[r] = 0 r -= 1 p = 2 elif A[r] == max(A[l], A[r]): alice += 1 A[r] = A[r] - A[l] A[l] = 0 l += 1 p = 1 if l == r: if p == 1: bob += 1 if p == 2 or p == 0: alice += 1 break print(alice, bob) ```
0
764
A
Taymyr is calling you
PROGRAMMING
800
[ "brute force", "implementation", "math" ]
null
null
Comrade Dujikov is busy choosing artists for Timofey's birthday and is recieving calls from Taymyr from Ilia-alpinist. Ilia-alpinist calls every *n* minutes, i.e. in minutes *n*, 2*n*, 3*n* and so on. Artists come to the comrade every *m* minutes, i.e. in minutes *m*, 2*m*, 3*m* and so on. The day is *z* minutes long, i.e. the day consists of minutes 1,<=2,<=...,<=*z*. How many artists should be killed so that there are no artists in the room when Ilia calls? Consider that a call and a talk with an artist take exactly one minute.
The only string contains three integers — *n*, *m* and *z* (1<=≤<=*n*,<=*m*,<=*z*<=≤<=104).
Print single integer — the minimum number of artists that should be killed so that there are no artists in the room when Ilia calls.
[ "1 1 10\n", "1 2 5\n", "2 3 9\n" ]
[ "10\n", "2\n", "1\n" ]
Taymyr is a place in the north of Russia. In the first test the artists come each minute, as well as the calls, so we need to kill all of them. In the second test we need to kill artists which come on the second and the fourth minutes. In the third test — only the artist which comes on the sixth minute.
500
[ { "input": "1 1 10", "output": "10" }, { "input": "1 2 5", "output": "2" }, { "input": "2 3 9", "output": "1" }, { "input": "4 8 9", "output": "1" }, { "input": "7 9 2", "output": "0" }, { "input": "10000 10000 10000", "output": "1" }, { "input": "24 22 9235", "output": "34" }, { "input": "74 8 417", "output": "1" }, { "input": "972 1 203", "output": "0" }, { "input": "550 1 754", "output": "1" }, { "input": "860 1 884", "output": "1" }, { "input": "358 2 809", "output": "2" }, { "input": "33 27 216", "output": "0" }, { "input": "2940 1 9311", "output": "3" }, { "input": "4624 1 1953", "output": "0" }, { "input": "2696 2 7345", "output": "2" }, { "input": "3443 2 6701", "output": "0" }, { "input": "3 613 2275", "output": "1" }, { "input": "1 10000 10000", "output": "1" }, { "input": "10000 1 10000", "output": "1" }, { "input": "1 1 1", "output": "1" }, { "input": "1 1 10000", "output": "10000" }, { "input": "34 27 10000", "output": "10" }, { "input": "2 2 9999", "output": "4999" }, { "input": "2 2 1", "output": "0" }, { "input": "6 4 36", "output": "3" }, { "input": "33 6 3005", "output": "45" }, { "input": "5 1 20", "output": "4" }, { "input": "1 2 10", "output": "5" }, { "input": "2 1 100", "output": "50" }, { "input": "10 20 10000", "output": "500" }, { "input": "8 12 12", "output": "0" } ]
1,573,749,059
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
93
0
def calculateArtistsKilled(): values = input("Enter ilya, artists, days in 'x x x' format\neg: 1 1 10:\n") splitInput = values.split() m = int(splitInput[0]) n = int(splitInput[1]) z = int(splitInput[2]) illaZ = 0 artistsZ = 0 artistsKilled = 0 isIllaTimeGreater = m > n while (True): illaZ += m artistsZ += n while artistsZ > illaZ: illaZ += m if illaZ >= artistsZ: break while illaZ > artistsZ and isIllaTimeGreater: artistsZ += n if artistsZ >= illaZ: break if illaZ > z or artistsZ > z: break if illaZ == artistsZ: artistsKilled += 1 print(artistsKilled) yesOrNo = input("Want to try again?\n1) Yes\n2) No\n") return yesOrNo tryAgain = "1" while tryAgain == "1": tryAgain = calculateArtistsKilled()
Title: Taymyr is calling you Time Limit: None seconds Memory Limit: None megabytes Problem Description: Comrade Dujikov is busy choosing artists for Timofey's birthday and is recieving calls from Taymyr from Ilia-alpinist. Ilia-alpinist calls every *n* minutes, i.e. in minutes *n*, 2*n*, 3*n* and so on. Artists come to the comrade every *m* minutes, i.e. in minutes *m*, 2*m*, 3*m* and so on. The day is *z* minutes long, i.e. the day consists of minutes 1,<=2,<=...,<=*z*. How many artists should be killed so that there are no artists in the room when Ilia calls? Consider that a call and a talk with an artist take exactly one minute. Input Specification: The only string contains three integers — *n*, *m* and *z* (1<=≤<=*n*,<=*m*,<=*z*<=≤<=104). Output Specification: Print single integer — the minimum number of artists that should be killed so that there are no artists in the room when Ilia calls. Demo Input: ['1 1 10\n', '1 2 5\n', '2 3 9\n'] Demo Output: ['10\n', '2\n', '1\n'] Note: Taymyr is a place in the north of Russia. In the first test the artists come each minute, as well as the calls, so we need to kill all of them. In the second test we need to kill artists which come on the second and the fourth minutes. In the third test — only the artist which comes on the sixth minute.
```python def calculateArtistsKilled(): values = input("Enter ilya, artists, days in 'x x x' format\neg: 1 1 10:\n") splitInput = values.split() m = int(splitInput[0]) n = int(splitInput[1]) z = int(splitInput[2]) illaZ = 0 artistsZ = 0 artistsKilled = 0 isIllaTimeGreater = m > n while (True): illaZ += m artistsZ += n while artistsZ > illaZ: illaZ += m if illaZ >= artistsZ: break while illaZ > artistsZ and isIllaTimeGreater: artistsZ += n if artistsZ >= illaZ: break if illaZ > z or artistsZ > z: break if illaZ == artistsZ: artistsKilled += 1 print(artistsKilled) yesOrNo = input("Want to try again?\n1) Yes\n2) No\n") return yesOrNo tryAgain = "1" while tryAgain == "1": tryAgain = calculateArtistsKilled() ```
-1
659
D
Bicycle Race
PROGRAMMING
1,500
[ "geometry", "implementation", "math" ]
null
null
Maria participates in a bicycle race. The speedway takes place on the shores of Lake Lucerne, just repeating its contour. As you know, the lake shore consists only of straight sections, directed to the north, south, east or west. Let's introduce a system of coordinates, directing the *Ox* axis from west to east, and the *Oy* axis from south to north. As a starting position of the race the southernmost point of the track is selected (and if there are several such points, the most western among them). The participants start the race, moving to the north. At all straight sections of the track, the participants travel in one of the four directions (north, south, east or west) and change the direction of movement only in bends between the straight sections. The participants, of course, never turn back, that is, they do not change the direction of movement from north to south or from east to west (or vice versa). Maria is still young, so she does not feel confident at some turns. Namely, Maria feels insecure if at a failed or untimely turn, she gets into the water. In other words, Maria considers the turn dangerous if she immediately gets into the water if it is ignored. Help Maria get ready for the competition — determine the number of dangerous turns on the track.
The first line of the input contains an integer *n* (4<=≤<=*n*<=≤<=1000) — the number of straight sections of the track. The following (*n*<=+<=1)-th line contains pairs of integers (*x**i*,<=*y**i*) (<=-<=10<=000<=≤<=*x**i*,<=*y**i*<=≤<=10<=000). The first of these points is the starting position. The *i*-th straight section of the track begins at the point (*x**i*,<=*y**i*) and ends at the point (*x**i*<=+<=1,<=*y**i*<=+<=1). It is guaranteed that: - the first straight section is directed to the north; - the southernmost (and if there are several, then the most western of among them) point of the track is the first point; - the last point coincides with the first one (i.e., the start position); - any pair of straight sections of the track has no shared points (except for the neighboring ones, they share exactly one point); - no pair of points (except for the first and last one) is the same; - no two adjacent straight sections are directed in the same direction or in opposite directions.
Print a single integer — the number of dangerous turns on the track.
[ "6\n0 0\n0 1\n1 1\n1 2\n2 2\n2 0\n0 0\n", "16\n1 1\n1 5\n3 5\n3 7\n2 7\n2 9\n6 9\n6 7\n5 7\n5 3\n4 3\n4 4\n3 4\n3 2\n5 2\n5 1\n1 1\n" ]
[ "1\n", "6\n" ]
The first sample corresponds to the picture: The picture shows that you can get in the water under unfortunate circumstances only at turn at the point (1, 1). Thus, the answer is 1.
1,250
[ { "input": "6\n0 0\n0 1\n1 1\n1 2\n2 2\n2 0\n0 0", "output": "1" }, { "input": "16\n1 1\n1 5\n3 5\n3 7\n2 7\n2 9\n6 9\n6 7\n5 7\n5 3\n4 3\n4 4\n3 4\n3 2\n5 2\n5 1\n1 1", "output": "6" }, { "input": "4\n-10000 -10000\n-10000 10000\n10000 10000\n10000 -10000\n-10000 -10000", "output": "0" }, { "input": "4\n6 8\n6 9\n7 9\n7 8\n6 8", "output": "0" }, { "input": "8\n-10000 -10000\n-10000 5000\n0 5000\n0 10000\n10000 10000\n10000 0\n0 0\n0 -10000\n-10000 -10000", "output": "2" }, { "input": "20\n-4286 -10000\n-4286 -7778\n-7143 -7778\n-7143 -3334\n-10000 -3334\n-10000 1110\n-4286 1110\n-4286 -3334\n4285 -3334\n4285 -1112\n7142 -1112\n7142 3332\n4285 3332\n4285 9998\n9999 9998\n9999 -3334\n7142 -3334\n7142 -5556\n-1429 -5556\n-1429 -10000\n-4286 -10000", "output": "8" }, { "input": "24\n-10000 -10000\n-10000 9998\n9998 9998\n9998 -10000\n-6364 -10000\n-6364 6362\n6362 6362\n6362 -6364\n-2728 -6364\n-2728 2726\n2726 2726\n2726 -910\n908 -910\n908 908\n-910 908\n-910 -4546\n4544 -4546\n4544 4544\n-4546 4544\n-4546 -8182\n8180 -8182\n8180 8180\n-8182 8180\n-8182 -10000\n-10000 -10000", "output": "10" }, { "input": "12\n-10000 -10000\n-10000 10000\n10000 10000\n10000 6000\n-6000 6000\n-6000 2000\n10000 2000\n10000 -2000\n-6000 -2000\n-6000 -6000\n10000 -6000\n10000 -10000\n-10000 -10000", "output": "4" }, { "input": "12\n-10000 -10000\n-10000 10000\n10000 10000\n10000 6000\n-9800 6000\n-9800 2000\n10000 2000\n10000 -2000\n-9800 -2000\n-9800 -6000\n10000 -6000\n10000 -10000\n-10000 -10000", "output": "4" }, { "input": "4\n0 0\n0 10000\n10000 10000\n10000 0\n0 0", "output": "0" }, { "input": "4\n-10000 -10000\n-10000 10000\n10000 10000\n10000 -10000\n-10000 -10000", "output": "0" } ]
1,663,616,688
2,147,483,647
PyPy 3-64
OK
TESTS
22
77
1,638,400
n=int(input()) x1,y1=map(int,input().split()) x2,y2=x1,y1 dir1,dir2="","" count=0 for i in range(n-1): x1,y1=x2,y2 dir1=dir2 x2,y2=map(int,input().split()) if x2>x1: dir2="R" elif x2<x1: dir2="L" elif y1>y2: dir2="D" else: dir2="U" if dir1=="U" and dir2=="L": count+=1 elif dir1=="D" and dir2=="R": count+=1 elif dir1=="R" and dir2=="U": count+=1 elif dir1=="L" and dir2=="D": count+=1 print(count)
Title: Bicycle Race Time Limit: None seconds Memory Limit: None megabytes Problem Description: Maria participates in a bicycle race. The speedway takes place on the shores of Lake Lucerne, just repeating its contour. As you know, the lake shore consists only of straight sections, directed to the north, south, east or west. Let's introduce a system of coordinates, directing the *Ox* axis from west to east, and the *Oy* axis from south to north. As a starting position of the race the southernmost point of the track is selected (and if there are several such points, the most western among them). The participants start the race, moving to the north. At all straight sections of the track, the participants travel in one of the four directions (north, south, east or west) and change the direction of movement only in bends between the straight sections. The participants, of course, never turn back, that is, they do not change the direction of movement from north to south or from east to west (or vice versa). Maria is still young, so she does not feel confident at some turns. Namely, Maria feels insecure if at a failed or untimely turn, she gets into the water. In other words, Maria considers the turn dangerous if she immediately gets into the water if it is ignored. Help Maria get ready for the competition — determine the number of dangerous turns on the track. Input Specification: The first line of the input contains an integer *n* (4<=≤<=*n*<=≤<=1000) — the number of straight sections of the track. The following (*n*<=+<=1)-th line contains pairs of integers (*x**i*,<=*y**i*) (<=-<=10<=000<=≤<=*x**i*,<=*y**i*<=≤<=10<=000). The first of these points is the starting position. The *i*-th straight section of the track begins at the point (*x**i*,<=*y**i*) and ends at the point (*x**i*<=+<=1,<=*y**i*<=+<=1). It is guaranteed that: - the first straight section is directed to the north; - the southernmost (and if there are several, then the most western of among them) point of the track is the first point; - the last point coincides with the first one (i.e., the start position); - any pair of straight sections of the track has no shared points (except for the neighboring ones, they share exactly one point); - no pair of points (except for the first and last one) is the same; - no two adjacent straight sections are directed in the same direction or in opposite directions. Output Specification: Print a single integer — the number of dangerous turns on the track. Demo Input: ['6\n0 0\n0 1\n1 1\n1 2\n2 2\n2 0\n0 0\n', '16\n1 1\n1 5\n3 5\n3 7\n2 7\n2 9\n6 9\n6 7\n5 7\n5 3\n4 3\n4 4\n3 4\n3 2\n5 2\n5 1\n1 1\n'] Demo Output: ['1\n', '6\n'] Note: The first sample corresponds to the picture: The picture shows that you can get in the water under unfortunate circumstances only at turn at the point (1, 1). Thus, the answer is 1.
```python n=int(input()) x1,y1=map(int,input().split()) x2,y2=x1,y1 dir1,dir2="","" count=0 for i in range(n-1): x1,y1=x2,y2 dir1=dir2 x2,y2=map(int,input().split()) if x2>x1: dir2="R" elif x2<x1: dir2="L" elif y1>y2: dir2="D" else: dir2="U" if dir1=="U" and dir2=="L": count+=1 elif dir1=="D" and dir2=="R": count+=1 elif dir1=="R" and dir2=="U": count+=1 elif dir1=="L" and dir2=="D": count+=1 print(count) ```
3
616
B
Dinner with Emma
PROGRAMMING
1,000
[ "games", "greedy" ]
null
null
Jack decides to invite Emma out for a dinner. Jack is a modest student, he doesn't want to go to an expensive restaurant. Emma is a girl with high taste, she prefers elite places. Munhattan consists of *n* streets and *m* avenues. There is exactly one restaurant on the intersection of each street and avenue. The streets are numbered with integers from 1 to *n* and the avenues are numbered with integers from 1 to *m*. The cost of dinner in the restaurant at the intersection of the *i*-th street and the *j*-th avenue is *c**ij*. Jack and Emma decide to choose the restaurant in the following way. Firstly Emma chooses the street to dinner and then Jack chooses the avenue. Emma and Jack makes their choice optimally: Emma wants to maximize the cost of the dinner, Jack wants to minimize it. Emma takes into account that Jack wants to minimize the cost of the dinner. Find the cost of the dinner for the couple in love.
The first line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of streets and avenues in Munhattan. Each of the next *n* lines contains *m* integers *c**ij* (1<=≤<=*c**ij*<=≤<=109) — the cost of the dinner in the restaurant on the intersection of the *i*-th street and the *j*-th avenue.
Print the only integer *a* — the cost of the dinner for Jack and Emma.
[ "3 4\n4 1 3 5\n2 2 2 2\n5 4 5 1\n", "3 3\n1 2 3\n2 3 1\n3 1 2\n" ]
[ "2\n", "1\n" ]
In the first example if Emma chooses the first or the third streets Jack can choose an avenue with the cost of the dinner 1. So she chooses the second street and Jack chooses any avenue. The cost of the dinner is 2. In the second example regardless of Emma's choice Jack can choose a restaurant with the cost of the dinner 1.
0
[ { "input": "3 4\n4 1 3 5\n2 2 2 2\n5 4 5 1", "output": "2" }, { "input": "3 3\n1 2 3\n2 3 1\n3 1 2", "output": "1" }, { "input": "1 1\n1", "output": "1" }, { "input": "1 10\n74 35 82 39 1 84 29 41 70 12", "output": "1" }, { "input": "10 1\n44\n23\n65\n17\n48\n29\n49\n88\n91\n85", "output": "91" }, { "input": "10 10\n256 72 455 45 912 506 235 68 951 92\n246 305 45 212 788 621 449 876 459 899\n732 107 230 357 370 610 997 669 61 192\n131 93 481 527 983 920 825 540 435 54\n777 682 984 20 337 480 264 137 249 502\n51 467 479 228 923 752 714 436 199 973\n3 91 612 571 631 212 751 84 886 948\n252 130 583 23 194 985 234 978 709 16\n636 991 203 469 719 540 184 902 503 652\n826 680 150 284 37 987 360 183 447 51", "output": "184" }, { "input": "1 1\n1000000000", "output": "1000000000" }, { "input": "2 1\n999999999\n1000000000", "output": "1000000000" } ]
1,629,428,053
2,147,483,647
PyPy 3
RUNTIME_ERROR
TESTS
2
140
22,220,800
n,m=map(int,input().split()) list1=list(map(int,input().split())) list2=list(map(int,input().split())) list3=list(map(int,input().split())) mini1=min(list1) mini2=min(list2) mini3=min(list3) ans=max(mini1,mini2,mini3) print(ans)
Title: Dinner with Emma Time Limit: None seconds Memory Limit: None megabytes Problem Description: Jack decides to invite Emma out for a dinner. Jack is a modest student, he doesn't want to go to an expensive restaurant. Emma is a girl with high taste, she prefers elite places. Munhattan consists of *n* streets and *m* avenues. There is exactly one restaurant on the intersection of each street and avenue. The streets are numbered with integers from 1 to *n* and the avenues are numbered with integers from 1 to *m*. The cost of dinner in the restaurant at the intersection of the *i*-th street and the *j*-th avenue is *c**ij*. Jack and Emma decide to choose the restaurant in the following way. Firstly Emma chooses the street to dinner and then Jack chooses the avenue. Emma and Jack makes their choice optimally: Emma wants to maximize the cost of the dinner, Jack wants to minimize it. Emma takes into account that Jack wants to minimize the cost of the dinner. Find the cost of the dinner for the couple in love. Input Specification: The first line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of streets and avenues in Munhattan. Each of the next *n* lines contains *m* integers *c**ij* (1<=≤<=*c**ij*<=≤<=109) — the cost of the dinner in the restaurant on the intersection of the *i*-th street and the *j*-th avenue. Output Specification: Print the only integer *a* — the cost of the dinner for Jack and Emma. Demo Input: ['3 4\n4 1 3 5\n2 2 2 2\n5 4 5 1\n', '3 3\n1 2 3\n2 3 1\n3 1 2\n'] Demo Output: ['2\n', '1\n'] Note: In the first example if Emma chooses the first or the third streets Jack can choose an avenue with the cost of the dinner 1. So she chooses the second street and Jack chooses any avenue. The cost of the dinner is 2. In the second example regardless of Emma's choice Jack can choose a restaurant with the cost of the dinner 1.
```python n,m=map(int,input().split()) list1=list(map(int,input().split())) list2=list(map(int,input().split())) list3=list(map(int,input().split())) mini1=min(list1) mini2=min(list2) mini3=min(list3) ans=max(mini1,mini2,mini3) print(ans) ```
-1
616
A
Comparing Two Long Integers
PROGRAMMING
900
[ "implementation", "strings" ]
null
null
You are given two very long integers *a*,<=*b* (leading zeroes are allowed). You should check what number *a* or *b* is greater or determine that they are equal. The input size is very large so don't use the reading of symbols one by one. Instead of that use the reading of a whole line or token. As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. Don't use the function input() in Python2 instead of it use the function raw_input().
The first line contains a non-negative integer *a*. The second line contains a non-negative integer *b*. The numbers *a*,<=*b* may contain leading zeroes. Each of them contains no more than 106 digits.
Print the symbol "&lt;" if *a*<=&lt;<=*b* and the symbol "&gt;" if *a*<=&gt;<=*b*. If the numbers are equal print the symbol "=".
[ "9\n10\n", "11\n10\n", "00012345\n12345\n", "0123\n9\n", "0123\n111\n" ]
[ "&lt;\n", "&gt;\n", "=\n", "&gt;\n", "&gt;\n" ]
none
0
[ { "input": "9\n10", "output": "<" }, { "input": "11\n10", "output": ">" }, { "input": "00012345\n12345", "output": "=" }, { "input": "0123\n9", "output": ">" }, { "input": "0123\n111", "output": ">" }, { "input": "9\n9", "output": "=" }, { "input": "0\n0000", "output": "=" }, { "input": "1213121\n1213121", "output": "=" }, { "input": "8631749422082281871941140403034638286979613893271246118706788645620907151504874585597378422393911017\n1460175633701201615285047975806206470993708143873675499262156511814213451040881275819636625899967479", "output": ">" }, { "input": "6421902501252475186372406731932548506197390793597574544727433297197476846519276598727359617092494798\n8", "output": ">" }, { "input": "9\n3549746075165939381145061479392284958612916596558639332310874529760172204736013341477640605383578772", "output": "<" }, { "input": "11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", "output": "=" }, { "input": "0000000001\n2", "output": "<" }, { "input": "1000000000000000000000000000000000\n1000000000000000000000000000000001", "output": "<" }, { "input": "123456123456123456123456123456123456123456123456123456123456123456\n123456123456123456123456123456123456123456123456123456123456123456123456123456", "output": "<" }, { "input": "1111111111111111111111111111111111111111\n2222222222222222222222222222222222222222", "output": "<" }, { "input": "123456789999999\n123456789999999", "output": "=" }, { "input": "111111111111111111111111111111\n222222222222222222222222222222", "output": "<" }, { "input": "1111111111111111111111111111111111111111111111111111111111111111111111\n1111111111111111111111111111111111111111111111111111111111111111111111", "output": "=" }, { "input": "587345873489573457357834\n47957438573458347574375348", "output": "<" }, { "input": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n33333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333", "output": "<" }, { "input": "11111111111111111111111111111111111\n44444444444444444444444444444444444", "output": "<" }, { "input": "11111111111111111111111111111111111\n22222222222222222222222222222222222", "output": "<" }, { "input": "9999999999999999999999999999999999999999999999999999999999999999999\n99999999999999999999999999999999999999999999999999999999999999999999999999999999999999", "output": "<" }, { "input": "1\n2", "output": "<" }, { "input": "9\n0", "output": ">" }, { "input": "222222222222222222222222222222222222222222222222222222222\n22222222222222222222222222222222222222222222222222222222222", "output": "<" }, { "input": "66646464222222222222222222222222222222222222222222222222222222222222222\n111111111111111111111111111111111111111111111111111111111111111111111111111111111111", "output": "<" }, { "input": "222222222222222222222222222222222222222222222222222\n111111111111111111111111111111111111111111111111111111111111111", "output": "<" }, { "input": "11111111111111111111111111111111111111\n44444444444444444444444444444444444444", "output": "<" }, { "input": "01\n2", "output": "<" }, { "input": "00\n01", "output": "<" }, { "input": "99999999999999999999999999999999999999999999999\n99999999999999999999999999999999999999999999999", "output": "=" }, { "input": "43278947323248843213443272432\n793439250984509434324323453435435", "output": "<" }, { "input": "0\n1", "output": "<" }, { "input": "010\n011", "output": "<" }, { "input": "999999999999999999999999999999999999999999999999\n999999999999999999999999999999999999999999999999", "output": "=" }, { "input": "0001001\n0001010", "output": "<" }, { "input": "1111111111111111111111111111111111111111111111111111111111111\n1111111111111111111111111111111111111111111111111111111111111", "output": "=" }, { "input": "00000\n00", "output": "=" }, { "input": "999999999999999999999999999\n999999999999999999999999999", "output": "=" }, { "input": "999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999\n999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999", "output": "=" }, { "input": "001\n000000000010", "output": "<" }, { "input": "01\n10", "output": "<" }, { "input": "555555555555555555555555555555555555555555555555555555555555\n555555555555555555555555555555555555555555555555555555555555", "output": "=" }, { "input": "5555555555555555555555555555555555555555555555555\n5555555555555555555555555555555555555555555555555", "output": "=" }, { "input": "01\n02", "output": "<" }, { "input": "001111\n0001111", "output": "=" }, { "input": "55555555555555555555555555555555555555555555555555\n55555555555555555555555555555555555555555555555555", "output": "=" }, { "input": "1029301293019283091283091283091280391283\n1029301293019283091283091283091280391283", "output": "=" }, { "input": "001\n2", "output": "<" }, { "input": "000000000\n000000000", "output": "=" }, { "input": "000000\n10", "output": "<" }, { "input": "000000000000000\n001", "output": "<" }, { "input": "0000001\n2", "output": "<" }, { "input": "0000\n123", "output": "<" }, { "input": "951\n960", "output": "<" }, { "input": "002\n0001", "output": ">" }, { "input": "0000001\n01", "output": "=" }, { "input": "99999999999999999999999999999999999999999999999999999999999999\n99999999999999999999999999999999999999999999999999999999999999", "output": "=" }, { "input": "12345678901234567890123456789012345678901234567890123456789012\n12345678901234567890123456789012345678901234567890123456789012", "output": "=" }, { "input": "02\n01", "output": ">" }, { "input": "00000111111\n00000110111", "output": ">" }, { "input": "0123\n123", "output": "=" }, { "input": "123771237912798378912\n91239712798379812897389123123123123", "output": "<" }, { "input": "00001\n002", "output": "<" }, { "input": "0000000000000000000000000000000000000000000000000000000000000\n000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "output": "=" }, { "input": "000000001\n00002", "output": "<" }, { "input": "00002\n00003", "output": "<" }, { "input": "000123456\n123457", "output": "<" }, { "input": "01\n00", "output": ">" }, { "input": "00\n0", "output": "=" }, { "input": "10\n11", "output": "<" }, { "input": "0011\n12", "output": "<" }, { "input": "00\n1", "output": "<" }, { "input": "0\n0", "output": "=" }, { "input": "00\n10", "output": "<" }, { "input": "011\n10", "output": ">" }, { "input": "00011111111111111111111111111111111111000000000000000000000000000000000000000000000000000210000000000000000000000000000000000000000011000\n11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111112091", "output": "<" }, { "input": "0000001\n00", "output": ">" }, { "input": "01\n1", "output": "=" }, { "input": "010\n001", "output": ">" }, { "input": "100\n111", "output": "<" }, { "input": "1\n0", "output": ">" }, { "input": "000000\n000000000000000000000", "output": "=" }, { "input": "010101\n010101", "output": "=" }, { "input": "00000000000000000001111111111111111111111111111111111111111111111111111111\n11111111111111111111111", "output": ">" }, { "input": "0000000\n0", "output": "=" }, { "input": "187923712738712879387912839182381\n871279397127389781927389718923789178923897123", "output": "<" }, { "input": "0010\n030", "output": "<" } ]
1,645,077,729
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
13
2,000
10,444,800
A = int(input()) B = int(input()) if A < B: print('<') elif A > B: print('>') else: print('=')
Title: Comparing Two Long Integers Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given two very long integers *a*,<=*b* (leading zeroes are allowed). You should check what number *a* or *b* is greater or determine that they are equal. The input size is very large so don't use the reading of symbols one by one. Instead of that use the reading of a whole line or token. As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. Don't use the function input() in Python2 instead of it use the function raw_input(). Input Specification: The first line contains a non-negative integer *a*. The second line contains a non-negative integer *b*. The numbers *a*,<=*b* may contain leading zeroes. Each of them contains no more than 106 digits. Output Specification: Print the symbol "&lt;" if *a*<=&lt;<=*b* and the symbol "&gt;" if *a*<=&gt;<=*b*. If the numbers are equal print the symbol "=". Demo Input: ['9\n10\n', '11\n10\n', '00012345\n12345\n', '0123\n9\n', '0123\n111\n'] Demo Output: ['&lt;\n', '&gt;\n', '=\n', '&gt;\n', '&gt;\n'] Note: none
```python A = int(input()) B = int(input()) if A < B: print('<') elif A > B: print('>') else: print('=') ```
0
227
B
Effective Approach
PROGRAMMING
1,100
[ "implementation" ]
null
null
Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array. According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn compared with the number that you need to find. Once you find the array element that is equal to the required one, the search ends. The efficiency of the algorithm is the number of performed comparisons. The fewer comparisons the linear search has made, the more effective it is. Vasya believes that a linear search would work better if it sequentially iterates through the elements, starting with the 1-st one (in this problem we consider the elements of the array indexed from 1 to *n*) and ending with the *n*-th one. And Petya says that Vasya is wrong: the search will need less comparisons if it sequentially iterates the elements starting from the *n*-th and ending with the 1-st one. Sasha argues that the two approaches are equivalent. To finally begin the task, the teammates decided to settle the debate and compare the two approaches on an example. For this, they took an array that is a permutation of integers from 1 to *n*, and generated *m* queries of the form: find element with value *b**i* in the array. They want to calculate for both approaches how many comparisons in total the linear search will need to respond to all queries. If the first search needs fewer comparisons, then the winner of the dispute is Vasya. If the second one does, then the winner is Petya. If both approaches make the same number of comparisons, then Sasha's got the upper hand. But the problem is, linear search is too slow. That's why the boys aren't going to find out who is right before the end of the training, unless you come in here. Help them to determine who will win the dispute.
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of elements in the array. The second line contains *n* distinct space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the elements of array. The third line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. The last line contains *m* space-separated integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=*n*) — the search queries. Note that the queries can repeat.
Print two integers, showing how many comparisons Vasya's approach needs and how many comparisons Petya's approach needs. Separate the numbers by spaces. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.
[ "2\n1 2\n1\n1\n", "2\n2 1\n1\n1\n", "3\n3 1 2\n3\n1 2 3\n" ]
[ "1 2\n", "2 1\n", "6 6\n" ]
In the first sample Vasya's approach will make one comparison (it starts with the 1-st element and immediately finds the required number), and Petya's approach makes two comparisons (first he compares with the 2-nd array element, doesn't find the search item and compares with the 1-st element). In the second sample, on the contrary, Vasya's approach will need two comparisons (first with 1-st element, and then with the 2-nd), and Petya's approach will find the required value in one comparison (the first comparison with the 2-nd element).
1,000
[ { "input": "2\n1 2\n1\n1", "output": "1 2" }, { "input": "2\n2 1\n1\n1", "output": "2 1" }, { "input": "3\n3 1 2\n3\n1 2 3", "output": "6 6" }, { "input": "9\n2 9 3 1 6 4 7 8 5\n9\n5 1 5 2 8 4 4 4 5", "output": "58 32" }, { "input": "10\n3 10 9 2 7 6 5 8 4 1\n1\n4", "output": "9 2" }, { "input": "10\n5 2 10 8 3 1 9 7 6 4\n9\n2 5 9 2 3 2 5 9 8", "output": "31 68" }, { "input": "9\n3 8 4 7 1 2 5 6 9\n3\n2 7 1", "output": "15 15" }, { "input": "9\n5 3 8 4 2 6 1 7 9\n4\n6 1 9 2", "output": "27 13" }, { "input": "4\n1 3 2 4\n4\n3 1 2 3", "output": "8 12" }, { "input": "3\n1 2 3\n8\n3 2 1 1 2 3 1 2", "output": "15 17" } ]
1,691,286,623
2,147,483,647
PyPy 3-64
TIME_LIMIT_EXCEEDED
TESTS
5
2,000
10,342,400
n = int(input()) a = [int(s) for s in input().split(" ")] m = int(input()) b = [int(s) for s in input().split(" ")] v = 0 p = 0 for k in range(m): for i in range(len(a)): if a[i] == b[k]: v += i+1 exit for j in range(len(a)): if a[-1*(j+1)] == b[k]: p += j+1 exit print(v, p)
Title: Effective Approach Time Limit: None seconds Memory Limit: None megabytes Problem Description: Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array. According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn compared with the number that you need to find. Once you find the array element that is equal to the required one, the search ends. The efficiency of the algorithm is the number of performed comparisons. The fewer comparisons the linear search has made, the more effective it is. Vasya believes that a linear search would work better if it sequentially iterates through the elements, starting with the 1-st one (in this problem we consider the elements of the array indexed from 1 to *n*) and ending with the *n*-th one. And Petya says that Vasya is wrong: the search will need less comparisons if it sequentially iterates the elements starting from the *n*-th and ending with the 1-st one. Sasha argues that the two approaches are equivalent. To finally begin the task, the teammates decided to settle the debate and compare the two approaches on an example. For this, they took an array that is a permutation of integers from 1 to *n*, and generated *m* queries of the form: find element with value *b**i* in the array. They want to calculate for both approaches how many comparisons in total the linear search will need to respond to all queries. If the first search needs fewer comparisons, then the winner of the dispute is Vasya. If the second one does, then the winner is Petya. If both approaches make the same number of comparisons, then Sasha's got the upper hand. But the problem is, linear search is too slow. That's why the boys aren't going to find out who is right before the end of the training, unless you come in here. Help them to determine who will win the dispute. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of elements in the array. The second line contains *n* distinct space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the elements of array. The third line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. The last line contains *m* space-separated integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=*n*) — the search queries. Note that the queries can repeat. Output Specification: Print two integers, showing how many comparisons Vasya's approach needs and how many comparisons Petya's approach needs. Separate the numbers by spaces. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. Demo Input: ['2\n1 2\n1\n1\n', '2\n2 1\n1\n1\n', '3\n3 1 2\n3\n1 2 3\n'] Demo Output: ['1 2\n', '2 1\n', '6 6\n'] Note: In the first sample Vasya's approach will make one comparison (it starts with the 1-st element and immediately finds the required number), and Petya's approach makes two comparisons (first he compares with the 2-nd array element, doesn't find the search item and compares with the 1-st element). In the second sample, on the contrary, Vasya's approach will need two comparisons (first with 1-st element, and then with the 2-nd), and Petya's approach will find the required value in one comparison (the first comparison with the 2-nd element).
```python n = int(input()) a = [int(s) for s in input().split(" ")] m = int(input()) b = [int(s) for s in input().split(" ")] v = 0 p = 0 for k in range(m): for i in range(len(a)): if a[i] == b[k]: v += i+1 exit for j in range(len(a)): if a[-1*(j+1)] == b[k]: p += j+1 exit print(v, p) ```
0
975
E
Hag's Khashba
PROGRAMMING
2,600
[ "geometry" ]
null
null
Hag is a very talented person. He has always had an artist inside him but his father forced him to study mechanical engineering. Yesterday he spent all of his time cutting a giant piece of wood trying to make it look like a goose. Anyway, his dad found out that he was doing arts rather than studying mechanics and other boring subjects. He confronted Hag with the fact that he is a spoiled son that does not care about his future, and if he continues to do arts he will cut his 25 Lira monthly allowance. Hag is trying to prove to his dad that the wooden piece is a project for mechanics subject. He also told his dad that the wooden piece is a strictly convex polygon with $n$ vertices. Hag brought two pins and pinned the polygon with them in the $1$-st and $2$-nd vertices to the wall. His dad has $q$ queries to Hag of two types. - $1$ $f$ $t$: pull a pin from the vertex $f$, wait for the wooden polygon to rotate under the gravity force (if it will rotate) and stabilize. And then put the pin in vertex $t$. - $2$ $v$: answer what are the coordinates of the vertex $v$. Please help Hag to answer his father's queries. You can assume that the wood that forms the polygon has uniform density and the polygon has a positive thickness, same in all points. After every query of the 1-st type Hag's dad tries to move the polygon a bit and watches it stabilize again.
The first line contains two integers $n$ and $q$ ($3\leq n \leq 10\,000$, $1 \leq q \leq 200000$) — the number of vertices in the polygon and the number of queries. The next $n$ lines describe the wooden polygon, the $i$-th line contains two integers $x_i$ and $y_i$ ($|x_i|, |y_i|\leq 10^8$) — the coordinates of the $i$-th vertex of the polygon. It is guaranteed that polygon is strictly convex and the vertices are given in the counter-clockwise order and all vertices are distinct. The next $q$ lines describe the queries, one per line. Each query starts with its type $1$ or $2$. Each query of the first type continues with two integers $f$ and $t$ ($1 \le f, t \le n$) — the vertex the pin is taken from, and the vertex the pin is put to and the polygon finishes rotating. It is guaranteed that the vertex $f$ contains a pin. Each query of the second type continues with a single integer $v$ ($1 \le v \le n$) — the vertex the coordinates of which Hag should tell his father. It is guaranteed that there is at least one query of the second type.
The output should contain the answer to each query of second type — two numbers in a separate line. Your 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 $\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-4}$
[ "3 4\n0 0\n2 0\n2 2\n1 1 2\n2 1\n2 2\n2 3\n", "3 2\n-1 1\n0 0\n1 1\n1 1 2\n2 1\n" ]
[ "3.4142135624 -1.4142135624\n2.0000000000 0.0000000000\n0.5857864376 -1.4142135624\n", "1.0000000000 -1.0000000000\n" ]
In the first test note the initial and the final state of the wooden polygon. Red Triangle is the initial state and the green one is the triangle after rotation around $(2,0)$. In the second sample note that the polygon rotates $180$ degrees counter-clockwise or clockwise direction (it does not matter), because Hag's father makes sure that the polygon is stable and his son does not trick him.
2,500
[ { "input": "3 4\n0 0\n2 0\n2 2\n1 1 2\n2 1\n2 2\n2 3", "output": "3.4142135624 -1.4142135624\n2.0000000000 0.0000000000\n0.5857864376 -1.4142135624" }, { "input": "3 2\n-1 1\n0 0\n1 1\n1 1 2\n2 1", "output": "1.0000000000 -1.0000000000" }, { "input": "10 10\n0 -100000000\n1 -100000000\n1566 -99999999\n2088 -99999997\n2610 -99999994\n3132 -99999990\n3654 -99999985\n4176 -99999979\n4698 -99999972\n5220 -99999964\n1 2 5\n2 1\n1 1 7\n2 5\n1 5 4\n1 4 2\n2 8\n1 7 9\n2 1\n1 2 10", "output": "0.0000000000 -100000000.0000000000\n-7.3726558373 -100002609.9964835122\n-129.8654413032 -100003125.4302210321\n-114.4079442212 -100007299.4544525659" }, { "input": "4 10\n0 0\n2 0\n2 2\n0 2\n2 3\n2 1\n2 1\n1 1 1\n2 3\n1 2 4\n1 4 4\n2 4\n1 1 3\n2 3", "output": "2.0000000000 2.0000000000\n0.0000000000 0.0000000000\n0.0000000000 0.0000000000\n0.5857864376 -1.4142135624\n4.8284271247 -2.8284271247\n6.2426406871 -4.2426406871" }, { "input": "3 2\n0 0\n1 0\n1566 1\n1 2 1\n2 3", "output": "0.0006381620 -1566.0003192846" } ]
1,525,922,460
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
93
7,065,600
import sys if locals()['__file__'][-2:] == 'py': sys.stdin = open('in.txt', 'r') from math import * class Point(): def __init__(self, x, y): self.x = x self.y = y def __add__(self, pt): return Point(self.x + pt.x, self.y + pt.y) def __iadd__(self, pt): return self + pt def __truediv__(self, n): return Point(self.x / n, self.y / n) def __itruediv__(self, n): return self / n def __str__(self): return '%f %f' % (self.x, self.y) def distance(self, pt): return sqrt((self.x - pt.x) ** 2 + (self.y - pt.y) ** 2) def angle(self, pt): det_x = pt.x - self.x det_y = pt.y - self.y if det_x == 0: if det_y > 0: return pi / 2 if det_y < 0: return pi / 2 * 3 if det_y == 0: raise Exception('Fail to find angle between two identical points.') if det_x > 0: return atan(det_y / det_x) if det_x < 0: return atan(det_y / det_x) + pi def get_pt_by_dis_ang(self, dis, ang): return Point(self.x + cos(ang) * dis, self.y + sin(ang) * dis) class Convex_polygon(): def __init__(self): self.points = [] self.core = None self.dis = None self.base_ang = 0 self.ang = None self.pin = [0, 1] def add(self, pt): self.points.append(pt) def update(self): self.update_core() self.update_dis() self.update_ang() def update_core(self): self.core = Point(0, 0) for pt in self.points: self.core += pt self.core /= len(self.points) def update_dis(self): self.dis = [] for pt in self.points: self.dis.append(self.core.distance(pt)) def update_ang(self): self.ang = [] for pt in self.points: self.ang.append(self.core.angle(pt)) def __str__(self): return '\n'.join(('points: ' + '[' + ', '.join(str(pt) for pt in self.points) + ']', 'core: ' + str(self.core), 'dis: ' + str(self.dis), 'base_ang ' + str(self.base_ang), 'ang ' + str(self.ang))) rd = lambda: map(int, input().split()) n, q = rd() P = Convex_polygon() for _ in range(n): P.add(Point(*rd())) P.update() for _ in range(q): s = input() if s[0] == '1': __, f, t = map(int, s.split()) f -= 1 t -= 1 P.pin.remove(f) i = P.pin[0] top_pt = P.core.get_pt_by_dis_ang(P.dis[i], P.base_ang + P.ang[i]) P.core = Point(top_pt.x, top_pt.y - P.dis[i]) P.base_ang = pi / 2 - P.ang[i] P.pin.append(t) else: __, v = map(int, s.split()) v -= 1 print(P.core.get_pt_by_dis_ang(P.dis[v], P.base_ang + P.ang[v]))
Title: Hag's Khashba Time Limit: None seconds Memory Limit: None megabytes Problem Description: Hag is a very talented person. He has always had an artist inside him but his father forced him to study mechanical engineering. Yesterday he spent all of his time cutting a giant piece of wood trying to make it look like a goose. Anyway, his dad found out that he was doing arts rather than studying mechanics and other boring subjects. He confronted Hag with the fact that he is a spoiled son that does not care about his future, and if he continues to do arts he will cut his 25 Lira monthly allowance. Hag is trying to prove to his dad that the wooden piece is a project for mechanics subject. He also told his dad that the wooden piece is a strictly convex polygon with $n$ vertices. Hag brought two pins and pinned the polygon with them in the $1$-st and $2$-nd vertices to the wall. His dad has $q$ queries to Hag of two types. - $1$ $f$ $t$: pull a pin from the vertex $f$, wait for the wooden polygon to rotate under the gravity force (if it will rotate) and stabilize. And then put the pin in vertex $t$. - $2$ $v$: answer what are the coordinates of the vertex $v$. Please help Hag to answer his father's queries. You can assume that the wood that forms the polygon has uniform density and the polygon has a positive thickness, same in all points. After every query of the 1-st type Hag's dad tries to move the polygon a bit and watches it stabilize again. Input Specification: The first line contains two integers $n$ and $q$ ($3\leq n \leq 10\,000$, $1 \leq q \leq 200000$) — the number of vertices in the polygon and the number of queries. The next $n$ lines describe the wooden polygon, the $i$-th line contains two integers $x_i$ and $y_i$ ($|x_i|, |y_i|\leq 10^8$) — the coordinates of the $i$-th vertex of the polygon. It is guaranteed that polygon is strictly convex and the vertices are given in the counter-clockwise order and all vertices are distinct. The next $q$ lines describe the queries, one per line. Each query starts with its type $1$ or $2$. Each query of the first type continues with two integers $f$ and $t$ ($1 \le f, t \le n$) — the vertex the pin is taken from, and the vertex the pin is put to and the polygon finishes rotating. It is guaranteed that the vertex $f$ contains a pin. Each query of the second type continues with a single integer $v$ ($1 \le v \le n$) — the vertex the coordinates of which Hag should tell his father. It is guaranteed that there is at least one query of the second type. Output Specification: The output should contain the answer to each query of second type — two numbers in a separate line. Your 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 $\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-4}$ Demo Input: ['3 4\n0 0\n2 0\n2 2\n1 1 2\n2 1\n2 2\n2 3\n', '3 2\n-1 1\n0 0\n1 1\n1 1 2\n2 1\n'] Demo Output: ['3.4142135624 -1.4142135624\n2.0000000000 0.0000000000\n0.5857864376 -1.4142135624\n', '1.0000000000 -1.0000000000\n'] Note: In the first test note the initial and the final state of the wooden polygon. Red Triangle is the initial state and the green one is the triangle after rotation around $(2,0)$. In the second sample note that the polygon rotates $180$ degrees counter-clockwise or clockwise direction (it does not matter), because Hag's father makes sure that the polygon is stable and his son does not trick him.
```python import sys if locals()['__file__'][-2:] == 'py': sys.stdin = open('in.txt', 'r') from math import * class Point(): def __init__(self, x, y): self.x = x self.y = y def __add__(self, pt): return Point(self.x + pt.x, self.y + pt.y) def __iadd__(self, pt): return self + pt def __truediv__(self, n): return Point(self.x / n, self.y / n) def __itruediv__(self, n): return self / n def __str__(self): return '%f %f' % (self.x, self.y) def distance(self, pt): return sqrt((self.x - pt.x) ** 2 + (self.y - pt.y) ** 2) def angle(self, pt): det_x = pt.x - self.x det_y = pt.y - self.y if det_x == 0: if det_y > 0: return pi / 2 if det_y < 0: return pi / 2 * 3 if det_y == 0: raise Exception('Fail to find angle between two identical points.') if det_x > 0: return atan(det_y / det_x) if det_x < 0: return atan(det_y / det_x) + pi def get_pt_by_dis_ang(self, dis, ang): return Point(self.x + cos(ang) * dis, self.y + sin(ang) * dis) class Convex_polygon(): def __init__(self): self.points = [] self.core = None self.dis = None self.base_ang = 0 self.ang = None self.pin = [0, 1] def add(self, pt): self.points.append(pt) def update(self): self.update_core() self.update_dis() self.update_ang() def update_core(self): self.core = Point(0, 0) for pt in self.points: self.core += pt self.core /= len(self.points) def update_dis(self): self.dis = [] for pt in self.points: self.dis.append(self.core.distance(pt)) def update_ang(self): self.ang = [] for pt in self.points: self.ang.append(self.core.angle(pt)) def __str__(self): return '\n'.join(('points: ' + '[' + ', '.join(str(pt) for pt in self.points) + ']', 'core: ' + str(self.core), 'dis: ' + str(self.dis), 'base_ang ' + str(self.base_ang), 'ang ' + str(self.ang))) rd = lambda: map(int, input().split()) n, q = rd() P = Convex_polygon() for _ in range(n): P.add(Point(*rd())) P.update() for _ in range(q): s = input() if s[0] == '1': __, f, t = map(int, s.split()) f -= 1 t -= 1 P.pin.remove(f) i = P.pin[0] top_pt = P.core.get_pt_by_dis_ang(P.dis[i], P.base_ang + P.ang[i]) P.core = Point(top_pt.x, top_pt.y - P.dis[i]) P.base_ang = pi / 2 - P.ang[i] P.pin.append(t) else: __, v = map(int, s.split()) v -= 1 print(P.core.get_pt_by_dis_ang(P.dis[v], P.base_ang + P.ang[v])) ```
0
989
B
A Tide of Riverscape
PROGRAMMING
1,200
[ "constructive algorithms", "strings" ]
null
null
"Time," Mino thinks aloud. "What?" "Time and tide wait for no man," explains Mino. "My name, taken from the river, always reminds me of this." "And what are you recording?" "You see it, tide. Everything has its own period, and I think I've figured out this one," says Mino with confidence. Doubtfully, Kanno peeks at Mino's records. The records are expressed as a string $s$ of characters '0', '1' and '.', where '0' denotes a low tide, '1' denotes a high tide, and '.' denotes an unknown one (either high or low). You are to help Mino determine whether it's possible that after replacing each '.' independently with '0' or '1', a given integer $p$ is not a period of the resulting string. In case the answer is yes, please also show such a replacement to Mino. In this problem, a positive integer $p$ is considered a period of string $s$, if for all $1 \leq i \leq \lvert s \rvert - p$, the $i$-th and $(i + p)$-th characters of $s$ are the same. Here $\lvert s \rvert$ is the length of $s$.
The first line contains two space-separated integers $n$ and $p$ ($1 \leq p \leq n \leq 2000$) — the length of the given string and the supposed period, respectively. The second line contains a string $s$ of $n$ characters — Mino's records. $s$ only contains characters '0', '1' and '.', and contains at least one '.' character.
Output one line — if it's possible that $p$ is not a period of the resulting string, output any one of such strings; otherwise output "No" (without quotes, you can print letters in any case (upper or lower)).
[ "10 7\n1.0.1.0.1.\n", "10 6\n1.0.1.1000\n", "10 9\n1........1\n" ]
[ "1000100010\n", "1001101000\n", "No\n" ]
In the first example, $7$ is not a period of the resulting string because the $1$-st and $8$-th characters of it are different. In the second example, $6$ is not a period of the resulting string because the $4$-th and $10$-th characters of it are different. In the third example, $9$ is always a period because the only constraint that the first and last characters are the same is already satisfied. Note that there are multiple acceptable answers for the first two examples, you can print any of them.
1,000
[ { "input": "10 7\n1.0.1.0.1.", "output": "1000100010" }, { "input": "10 6\n1.0.1.1000", "output": "1001101000" }, { "input": "10 9\n1........1", "output": "No" }, { "input": "1 1\n.", "output": "No" }, { "input": "5 1\n0...1", "output": "00001" }, { "input": "17 10\n..1.100..1..0.100", "output": "00101000010000100" }, { "input": "2 1\n0.", "output": "01" }, { "input": "2 1\n..", "output": "01" }, { "input": "3 1\n.0.", "output": "001" }, { "input": "3 1\n00.", "output": "001" }, { "input": "3 2\n0..", "output": "001" }, { "input": "3 2\n0.0", "output": "No" }, { "input": "3 2\n1..", "output": "100" }, { "input": "3 2\n.1.", "output": "011" }, { "input": "3 2\n1.0", "output": "100" }, { "input": "3 3\n1..", "output": "No" }, { "input": "3 3\n.00", "output": "No" }, { "input": "5 3\n0.000", "output": "01000" }, { "input": "10 6\n10010.1001", "output": "No" }, { "input": "75 38\n00.0.1.0.0110.1.00010..100.1110..110..00.0.1.0.0110.1.00010..100.1110..110.", "output": "000001000011001000010001000111000110000000010000110010000100010001110001101" }, { "input": "128 108\n01100.110...000.0001.1.11.11.010010.01100.0.1.01.0.0011.11001.000101...1.0.0..100.0110.0110.0.0101.0.0.0001.01100.110...100.0001", "output": "01100011000000000001010110110010010001100000100100000110110010000101000100000010000110001100000101000000001001100011000010000001" }, { "input": "5 4\n.101.", "output": "01011" }, { "input": "4 2\n101.", "output": "1011" }, { "input": "5 4\n.1011", "output": "01011" }, { "input": "2 1\n..", "output": "01" }, { "input": "5 3\n00.11", "output": "00011" }, { "input": "10 8\n1111.00000", "output": "1111000000" }, { "input": "10 3\n11111111.1", "output": "1111111101" }, { "input": "3 2\n1.0", "output": "100" }, { "input": "6 4\n11..10", "output": "110010" }, { "input": "4 2\n.111", "output": "0111" }, { "input": "3 2\n01.", "output": "011" }, { "input": "5 4\n10.00", "output": "10000" }, { "input": "10 9\n1........0", "output": "1000000000" }, { "input": "2 1\n0.", "output": "01" }, { "input": "8 4\n111111..", "output": "11111100" }, { "input": "3 2\n0.1", "output": "001" }, { "input": "4 1\n111.", "output": "1110" }, { "input": "3 1\n01.", "output": "010" }, { "input": "10 7\n000....111", "output": "0000000111" } ]
1,550,681,839
1,398
Python 3
RUNTIME_ERROR
TESTS
5
109
0
n, p = map(int, input().split()) s = input() for i in range(n - p): if s[i] == s[i + p] and s[i] != '.': continue else: if s[i] != s[i + p] and s[i] != '.': for iz in s: if iz == '.': print(0, end='') else: print(iz, end='') exit(0) elif s[i] == s[i+p]: s = list(s) for k in range(len(s)): if s[k] == '.': s[k] = 1 s[i] = 0 print(''.join(s)) exit(0) else: s = list(s) for k in range(len(s)): if s[k] == '.': s[k] = s[i + p] s[i] = str(1 - int(s[i + p])) print(''.join(s)) exit(0) print('NO')
Title: A Tide of Riverscape Time Limit: None seconds Memory Limit: None megabytes Problem Description: "Time," Mino thinks aloud. "What?" "Time and tide wait for no man," explains Mino. "My name, taken from the river, always reminds me of this." "And what are you recording?" "You see it, tide. Everything has its own period, and I think I've figured out this one," says Mino with confidence. Doubtfully, Kanno peeks at Mino's records. The records are expressed as a string $s$ of characters '0', '1' and '.', where '0' denotes a low tide, '1' denotes a high tide, and '.' denotes an unknown one (either high or low). You are to help Mino determine whether it's possible that after replacing each '.' independently with '0' or '1', a given integer $p$ is not a period of the resulting string. In case the answer is yes, please also show such a replacement to Mino. In this problem, a positive integer $p$ is considered a period of string $s$, if for all $1 \leq i \leq \lvert s \rvert - p$, the $i$-th and $(i + p)$-th characters of $s$ are the same. Here $\lvert s \rvert$ is the length of $s$. Input Specification: The first line contains two space-separated integers $n$ and $p$ ($1 \leq p \leq n \leq 2000$) — the length of the given string and the supposed period, respectively. The second line contains a string $s$ of $n$ characters — Mino's records. $s$ only contains characters '0', '1' and '.', and contains at least one '.' character. Output Specification: Output one line — if it's possible that $p$ is not a period of the resulting string, output any one of such strings; otherwise output "No" (without quotes, you can print letters in any case (upper or lower)). Demo Input: ['10 7\n1.0.1.0.1.\n', '10 6\n1.0.1.1000\n', '10 9\n1........1\n'] Demo Output: ['1000100010\n', '1001101000\n', 'No\n'] Note: In the first example, $7$ is not a period of the resulting string because the $1$-st and $8$-th characters of it are different. In the second example, $6$ is not a period of the resulting string because the $4$-th and $10$-th characters of it are different. In the third example, $9$ is always a period because the only constraint that the first and last characters are the same is already satisfied. Note that there are multiple acceptable answers for the first two examples, you can print any of them.
```python n, p = map(int, input().split()) s = input() for i in range(n - p): if s[i] == s[i + p] and s[i] != '.': continue else: if s[i] != s[i + p] and s[i] != '.': for iz in s: if iz == '.': print(0, end='') else: print(iz, end='') exit(0) elif s[i] == s[i+p]: s = list(s) for k in range(len(s)): if s[k] == '.': s[k] = 1 s[i] = 0 print(''.join(s)) exit(0) else: s = list(s) for k in range(len(s)): if s[k] == '.': s[k] = s[i + p] s[i] = str(1 - int(s[i + p])) print(''.join(s)) exit(0) print('NO') ```
-1
116
A
Tram
PROGRAMMING
800
[ "implementation" ]
null
null
Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty. Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram.
The first line contains a single number *n* (2<=≤<=*n*<=≤<=1000) — the number of the tram's stops. Then *n* lines follow, each contains two integers *a**i* and *b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the number of passengers that exits the tram at the *i*-th stop, and the number of passengers that enter the tram at the *i*-th stop. The stops are given from the first to the last stop in the order of tram's movement. - The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, . This particularly means that *a*1<==<=0. - At the last stop, all the passengers exit the tram and it becomes empty. More formally, . - No passenger will enter the train at the last stop. That is, *b**n*<==<=0.
Print a single integer denoting the minimum possible capacity of the tram (0 is allowed).
[ "4\n0 3\n2 5\n4 2\n4 0\n" ]
[ "6\n" ]
For the first example, a capacity of 6 is sufficient: - At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. - At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 passengers enter the tram. There are 6 passengers inside the tram now. - At the third stop, 4 passengers exit the tram (2 passengers remain inside). Then, 2 passengers enter the tram. There are 4 passengers inside the tram now. - Finally, all the remaining passengers inside the tram exit the tram at the last stop. There are no passenger inside the tram now, which is in line with the constraints. Since the number of passengers inside the tram never exceeds 6, a capacity of 6 is sufficient. Furthermore it is not possible for the tram to have a capacity less than 6. Hence, 6 is the correct answer.
500
[ { "input": "4\n0 3\n2 5\n4 2\n4 0", "output": "6" }, { "input": "5\n0 4\n4 6\n6 5\n5 4\n4 0", "output": "6" }, { "input": "10\n0 5\n1 7\n10 8\n5 3\n0 5\n3 3\n8 8\n0 6\n10 1\n9 0", "output": "18" }, { "input": "3\n0 1\n1 1\n1 0", "output": "1" }, { "input": "4\n0 1\n0 1\n1 0\n1 0", "output": "2" }, { "input": "3\n0 0\n0 0\n0 0", "output": "0" }, { "input": "3\n0 1000\n1000 1000\n1000 0", "output": "1000" }, { "input": "5\n0 73\n73 189\n189 766\n766 0\n0 0", "output": "766" }, { "input": "5\n0 0\n0 0\n0 0\n0 1\n1 0", "output": "1" }, { "input": "5\n0 917\n917 923\n904 992\n1000 0\n11 0", "output": "1011" }, { "input": "5\n0 1\n1 2\n2 1\n1 2\n2 0", "output": "2" }, { "input": "5\n0 0\n0 0\n0 0\n0 0\n0 0", "output": "0" }, { "input": "20\n0 7\n2 1\n2 2\n5 7\n2 6\n6 10\n2 4\n0 4\n7 4\n8 0\n10 6\n2 1\n6 1\n1 7\n0 3\n8 7\n6 3\n6 3\n1 1\n3 0", "output": "22" }, { "input": "5\n0 1000\n1000 1000\n1000 1000\n1000 1000\n1000 0", "output": "1000" }, { "input": "10\n0 592\n258 598\n389 203\n249 836\n196 635\n478 482\n994 987\n1000 0\n769 0\n0 0", "output": "1776" }, { "input": "10\n0 1\n1 0\n0 0\n0 0\n0 0\n0 1\n1 1\n0 1\n1 0\n1 0", "output": "2" }, { "input": "10\n0 926\n926 938\n938 931\n931 964\n937 989\n983 936\n908 949\n997 932\n945 988\n988 0", "output": "1016" }, { "input": "10\n0 1\n1 2\n1 2\n2 2\n2 2\n2 2\n1 1\n1 1\n2 1\n2 0", "output": "3" }, { "input": "10\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0", "output": "0" }, { "input": "10\n0 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 0", "output": "1000" }, { "input": "50\n0 332\n332 268\n268 56\n56 711\n420 180\n160 834\n149 341\n373 777\n763 93\n994 407\n86 803\n700 132\n471 608\n429 467\n75 5\n638 305\n405 853\n316 478\n643 163\n18 131\n648 241\n241 766\n316 847\n640 380\n923 759\n789 41\n125 421\n421 9\n9 388\n388 829\n408 108\n462 856\n816 411\n518 688\n290 7\n405 912\n397 772\n396 652\n394 146\n27 648\n462 617\n514 433\n780 35\n710 705\n460 390\n194 508\n643 56\n172 469\n1000 0\n194 0", "output": "2071" }, { "input": "50\n0 0\n0 1\n1 1\n0 1\n0 0\n1 0\n0 0\n1 0\n0 0\n0 0\n0 0\n0 0\n0 1\n0 0\n0 0\n0 1\n1 0\n0 1\n0 0\n1 1\n1 0\n0 1\n0 0\n1 1\n0 1\n1 0\n1 1\n1 0\n0 0\n1 1\n1 0\n0 1\n0 0\n0 1\n1 1\n1 1\n1 1\n1 0\n1 1\n1 0\n0 1\n1 0\n0 0\n0 1\n1 1\n1 1\n0 1\n0 0\n1 0\n1 0", "output": "3" }, { "input": "50\n0 926\n926 971\n915 980\n920 965\n954 944\n928 952\n955 980\n916 980\n906 935\n944 913\n905 923\n912 922\n965 934\n912 900\n946 930\n931 983\n979 905\n925 969\n924 926\n910 914\n921 977\n934 979\n962 986\n942 909\n976 903\n982 982\n991 941\n954 929\n902 980\n947 983\n919 924\n917 943\n916 905\n907 913\n964 977\n984 904\n905 999\n950 970\n986 906\n993 970\n960 994\n963 983\n918 986\n980 900\n931 986\n993 997\n941 909\n907 909\n1000 0\n278 0", "output": "1329" }, { "input": "2\n0 863\n863 0", "output": "863" }, { "input": "50\n0 1\n1 2\n2 2\n1 1\n1 1\n1 2\n1 2\n1 1\n1 2\n1 1\n1 1\n1 2\n1 2\n1 1\n2 1\n2 2\n1 2\n2 2\n1 2\n2 1\n2 1\n2 2\n2 1\n1 2\n1 2\n2 1\n1 1\n2 2\n1 1\n2 1\n2 2\n2 1\n1 2\n2 2\n1 2\n1 1\n1 1\n2 1\n2 1\n2 2\n2 1\n2 1\n1 2\n1 2\n1 2\n1 2\n2 0\n2 0\n2 0\n0 0", "output": "8" }, { "input": "50\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0", "output": "0" }, { "input": "100\n0 1\n0 0\n0 0\n1 0\n0 0\n0 1\n0 1\n1 1\n0 0\n0 0\n1 1\n0 0\n1 1\n0 1\n1 1\n0 1\n1 1\n1 0\n1 0\n0 0\n1 0\n0 1\n1 0\n0 0\n0 0\n1 1\n1 1\n0 1\n0 0\n1 0\n1 1\n0 1\n1 0\n1 1\n0 1\n1 1\n1 0\n0 0\n0 0\n0 1\n0 0\n0 1\n1 1\n0 0\n1 1\n1 1\n0 0\n0 1\n1 0\n0 1\n0 0\n0 1\n0 1\n1 1\n1 1\n1 1\n0 0\n0 0\n1 1\n0 1\n0 1\n1 0\n0 0\n0 0\n1 1\n0 1\n0 1\n1 1\n1 1\n0 1\n1 1\n1 1\n0 0\n1 0\n0 1\n0 0\n0 0\n1 1\n1 1\n1 1\n1 1\n0 1\n1 0\n1 0\n1 0\n1 0\n1 0\n0 0\n1 0\n1 0\n0 0\n1 0\n0 0\n0 1\n1 0\n0 1\n1 0\n1 0\n1 0\n1 0", "output": "11" }, { "input": "100\n0 2\n1 2\n2 1\n1 2\n1 2\n2 1\n2 2\n1 1\n1 1\n2 1\n1 2\n2 1\n1 2\n2 2\n2 2\n2 2\n1 2\n2 2\n2 1\n1 1\n1 1\n1 1\n2 2\n1 2\n2 2\n1 1\n1 1\n1 1\n1 1\n2 2\n1 2\n2 1\n1 1\n2 2\n1 1\n2 1\n1 1\n2 2\n2 1\n1 2\n1 1\n1 2\n2 1\n2 2\n1 1\n2 1\n1 1\n2 1\n1 1\n1 2\n2 2\n2 2\n1 1\n2 2\n1 2\n2 1\n2 1\n1 1\n1 1\n1 2\n1 2\n1 1\n1 1\n2 1\n1 2\n1 2\n2 1\n2 2\n2 2\n2 2\n2 1\n2 2\n1 1\n1 2\n1 2\n1 1\n2 2\n2 2\n1 1\n2 1\n1 1\n1 2\n1 2\n1 2\n1 1\n1 1\n2 2\n1 2\n2 1\n2 1\n2 1\n1 2\n1 2\n1 1\n2 2\n1 2\n2 0\n2 0\n2 0\n1 0", "output": "7" }, { "input": "100\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0", "output": "0" }, { "input": "2\n0 1\n1 0", "output": "1" }, { "input": "2\n0 900\n900 0", "output": "900" }, { "input": "2\n0 1\n1 0", "output": "1" }, { "input": "2\n0 0\n0 0", "output": "0" }, { "input": "2\n0 1000\n1000 0", "output": "1000" }, { "input": "3\n0 802\n175 188\n815 0", "output": "815" }, { "input": "3\n0 910\n910 976\n976 0", "output": "976" }, { "input": "3\n0 2\n2 1\n1 0", "output": "2" } ]
1,688,472,633
2,147,483,647
Python 3
OK
TESTS
71
92
0
n=int(input()) x=0 y=0 l=[] for i in range(0,n): a,b=map(int,input().split(" ")) x+=b x-=a l.append(x) print(max(l))
Title: Tram Time Limit: None seconds Memory Limit: None megabytes Problem Description: Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty. Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram. Input Specification: The first line contains a single number *n* (2<=≤<=*n*<=≤<=1000) — the number of the tram's stops. Then *n* lines follow, each contains two integers *a**i* and *b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the number of passengers that exits the tram at the *i*-th stop, and the number of passengers that enter the tram at the *i*-th stop. The stops are given from the first to the last stop in the order of tram's movement. - The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, . This particularly means that *a*1<==<=0. - At the last stop, all the passengers exit the tram and it becomes empty. More formally, . - No passenger will enter the train at the last stop. That is, *b**n*<==<=0. Output Specification: Print a single integer denoting the minimum possible capacity of the tram (0 is allowed). Demo Input: ['4\n0 3\n2 5\n4 2\n4 0\n'] Demo Output: ['6\n'] Note: For the first example, a capacity of 6 is sufficient: - At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. - At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 passengers enter the tram. There are 6 passengers inside the tram now. - At the third stop, 4 passengers exit the tram (2 passengers remain inside). Then, 2 passengers enter the tram. There are 4 passengers inside the tram now. - Finally, all the remaining passengers inside the tram exit the tram at the last stop. There are no passenger inside the tram now, which is in line with the constraints. Since the number of passengers inside the tram never exceeds 6, a capacity of 6 is sufficient. Furthermore it is not possible for the tram to have a capacity less than 6. Hence, 6 is the correct answer.
```python n=int(input()) x=0 y=0 l=[] for i in range(0,n): a,b=map(int,input().split(" ")) x+=b x-=a l.append(x) print(max(l)) ```
3
37
A
Towers
PROGRAMMING
1,000
[ "sortings" ]
A. Towers
2
256
Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same. Vasya wants to construct the minimal number of towers from the bars. Help Vasya to use the bars in the best way possible.
The first line contains an integer *N* (1<=≤<=*N*<=≤<=1000) — the number of bars at Vasya’s disposal. The second line contains *N* space-separated integers *l**i* — the lengths of the bars. All the lengths are natural numbers not exceeding 1000.
In one line output two numbers — the height of the largest tower and their total number. Remember that Vasya should use all the bars.
[ "3\n1 2 3\n", "4\n6 5 6 7\n" ]
[ "1 3\n", "2 3\n" ]
none
500
[ { "input": "3\n1 2 3", "output": "1 3" }, { "input": "4\n6 5 6 7", "output": "2 3" }, { "input": "4\n3 2 1 1", "output": "2 3" }, { "input": "4\n1 2 3 3", "output": "2 3" }, { "input": "3\n20 22 36", "output": "1 3" }, { "input": "25\n47 30 94 41 45 20 96 51 110 129 24 116 9 47 32 82 105 114 116 75 154 151 70 42 162", "output": "2 23" }, { "input": "45\n802 664 442 318 318 827 417 878 711 291 231 414 807 553 657 392 279 202 386 606 465 655 658 112 887 15 25 502 95 44 679 775 942 609 209 871 31 234 4 231 150 110 22 823 193", "output": "2 43" }, { "input": "63\n93 180 116 7 8 179 268 279 136 94 221 153 264 190 278 19 19 63 153 26 158 225 25 49 89 218 111 149 255 225 197 122 243 80 3 224 107 178 202 17 53 92 69 42 228 24 81 205 95 8 265 82 228 156 127 241 172 159 106 60 67 155 111", "output": "2 57" }, { "input": "83\n246 535 994 33 390 927 321 97 223 922 812 705 79 80 977 457 476 636 511 137 6 360 815 319 717 674 368 551 714 628 278 713 761 553 184 414 623 753 428 214 581 115 439 61 677 216 772 592 187 603 658 310 439 559 870 376 109 321 189 337 277 26 70 734 796 907 979 693 570 227 345 650 737 633 701 914 134 403 972 940 371 6 642", "output": "2 80" }, { "input": "105\n246 57 12 204 165 123 246 68 191 310 3 152 386 333 374 257 158 104 333 50 80 290 8 340 101 76 221 316 388 289 138 359 316 26 93 290 105 178 81 195 41 196 218 180 244 292 187 97 315 323 174 119 248 239 92 312 31 2 101 180 307 170 338 314 163 281 217 31 142 238 280 190 190 156 70 74 329 113 151 8 141 313 366 40 253 116 168 124 135 230 294 266 353 389 371 359 195 200 183 237 93 102 315 118 188", "output": "2 92" }, { "input": "123\n112 277 170 247 252 115 157 293 256 143 196 90 12 164 164 42 8 223 167 109 175 232 239 111 148 51 9 254 93 32 268 162 231 91 47 162 161 191 195 145 247 292 129 199 230 94 144 217 18 205 176 20 143 198 121 243 211 262 230 277 195 255 108 290 220 275 158 2 286 200 60 267 278 207 123 150 123 116 131 13 12 226 33 244 30 275 263 45 158 192 254 149 242 176 62 224 221 288 250 160 155 225 132 143 276 293 218 145 197 175 33 129 79 206 210 192 222 262 190 52 274 243 233", "output": "3 101" }, { "input": "5\n5 5 5 5 5", "output": "5 1" }, { "input": "3\n1000 1000 1000", "output": "3 1" }, { "input": "1\n1000", "output": "1 1" }, { "input": "1\n1", "output": "1 1" }, { "input": "5\n1 1000 1000 1000 1000", "output": "4 2" }, { "input": "5\n1000 1000 1000 8 7", "output": "3 3" } ]
1,486,539,806
2,147,483,647
Python 3
OK
TESTS
61
186
4,608,000
n = int(input()) #n, m = map(int, input().split()) #s = input() c = list(map(int, input().split())) c.sort() l = 0 k = 0 p = set() for i in c: if c.count(i) > l: l = c.count(i) if not i in p: k += 1 p.add(i) print(l, k)
Title: Towers Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same. Vasya wants to construct the minimal number of towers from the bars. Help Vasya to use the bars in the best way possible. Input Specification: The first line contains an integer *N* (1<=≤<=*N*<=≤<=1000) — the number of bars at Vasya’s disposal. The second line contains *N* space-separated integers *l**i* — the lengths of the bars. All the lengths are natural numbers not exceeding 1000. Output Specification: In one line output two numbers — the height of the largest tower and their total number. Remember that Vasya should use all the bars. Demo Input: ['3\n1 2 3\n', '4\n6 5 6 7\n'] Demo Output: ['1 3\n', '2 3\n'] Note: none
```python n = int(input()) #n, m = map(int, input().split()) #s = input() c = list(map(int, input().split())) c.sort() l = 0 k = 0 p = set() for i in c: if c.count(i) > l: l = c.count(i) if not i in p: k += 1 p.add(i) print(l, k) ```
3.944917
186
A
Comparing Strings
PROGRAMMING
1,100
[ "implementation", "strings" ]
null
null
Some dwarves that are finishing the StUDY (State University for Dwarven Youngsters) Bachelor courses, have been told "no genome, no degree". That means that all dwarves should write a thesis on genome. Dwarven genome is far from simple. It is represented by a string that consists of lowercase Latin letters. Dwarf Misha has already chosen the subject for his thesis: determining by two dwarven genomes, whether they belong to the same race. Two dwarves belong to the same race if we can swap two characters in the first dwarf's genome and get the second dwarf's genome as a result. Help Dwarf Misha and find out whether two gnomes belong to the same race or not.
The first line contains the first dwarf's genome: a non-empty string, consisting of lowercase Latin letters. The second line contains the second dwarf's genome: a non-empty string, consisting of lowercase Latin letters. The number of letters in each genome doesn't exceed 105. It is guaranteed that the strings that correspond to the genomes are different. The given genomes may have different length.
Print "YES", if the dwarves belong to the same race. Otherwise, print "NO".
[ "ab\nba\n", "aa\nab\n" ]
[ "YES\n", "NO\n" ]
- First example: you can simply swap two letters in string "ab". So we get "ba". - Second example: we can't change string "aa" into string "ab", because "aa" does not contain letter "b".
500
[ { "input": "ab\nba", "output": "YES" }, { "input": "aa\nab", "output": "NO" }, { "input": "a\nza", "output": "NO" }, { "input": "vvea\nvvae", "output": "YES" }, { "input": "rtfabanpc\natfabrnpc", "output": "YES" }, { "input": "mt\ntm", "output": "YES" }, { "input": "qxolmbkkt\naovlajmlf", "output": "NO" }, { "input": "b\ng", "output": "NO" }, { "input": "ab\naba", "output": "NO" }, { "input": "ba\na", "output": "NO" }, { "input": "a\nab", "output": "NO" }, { "input": "a\naa", "output": "NO" }, { "input": "a\nz", "output": "NO" }, { "input": "aabb\nbbaa", "output": "NO" }, { "input": "ab\nbd", "output": "NO" }, { "input": "bac\ndae", "output": "NO" }, { "input": "abc\nakl", "output": "NO" }, { "input": "cb\naa", "output": "NO" }, { "input": "abaab\naabba", "output": "NO" }, { "input": "aab\naaa", "output": "NO" }, { "input": "abcde\nedcba", "output": "NO" }, { "input": "abab\nbaba", "output": "NO" }, { "input": "ab\nbac", "output": "NO" }, { "input": "abcd\naqcb", "output": "NO" }, { "input": "abc\nbad", "output": "NO" }, { "input": "ab\nca", "output": "NO" }, { "input": "abc\nab", "output": "NO" }, { "input": "ab\nbae", "output": "NO" }, { "input": "aaaabcccca\naaaadccccb", "output": "NO" }, { "input": "acaa\nabca", "output": "NO" }, { "input": "aba\naab", "output": "YES" }, { "input": "ah\nla", "output": "NO" }, { "input": "aab\naa", "output": "NO" }, { "input": "abab\nabcd", "output": "NO" }, { "input": "ed\nab", "output": "NO" } ]
1,620,053,210
2,147,483,647
Python 3
OK
TESTS
53
218
716,800
str1 = input() str2 = input() if(len(str1)!=len(str2)): print("NO") else: freq_1 = [0]*26 freq_2 = [0]*26 ct = 0 flag = 0 str1_list = [] str2_list = [] for i in range(len(str1)): freq_1[ord(str1[i])-97]+=1 freq_2[ord(str2[i])-97]+=1 if(str1[i]!=str2[i]): ct+=1 if(ct>2): flag = 1 break else: str1_list.append(str1[i]) str2_list.append(str2[i]) if(flag==1): print("NO") else: freq_flag = 0 for i in range(len(freq_1)): if(freq_1[i]!=freq_2[i]): freq_flag = 1 break if(freq_flag==1): print("NO") else: if(str1_list[0]==str2_list[1] and str1_list[1]==str2_list[0]): print("YES") else: print("NO")
Title: Comparing Strings Time Limit: None seconds Memory Limit: None megabytes Problem Description: Some dwarves that are finishing the StUDY (State University for Dwarven Youngsters) Bachelor courses, have been told "no genome, no degree". That means that all dwarves should write a thesis on genome. Dwarven genome is far from simple. It is represented by a string that consists of lowercase Latin letters. Dwarf Misha has already chosen the subject for his thesis: determining by two dwarven genomes, whether they belong to the same race. Two dwarves belong to the same race if we can swap two characters in the first dwarf's genome and get the second dwarf's genome as a result. Help Dwarf Misha and find out whether two gnomes belong to the same race or not. Input Specification: The first line contains the first dwarf's genome: a non-empty string, consisting of lowercase Latin letters. The second line contains the second dwarf's genome: a non-empty string, consisting of lowercase Latin letters. The number of letters in each genome doesn't exceed 105. It is guaranteed that the strings that correspond to the genomes are different. The given genomes may have different length. Output Specification: Print "YES", if the dwarves belong to the same race. Otherwise, print "NO". Demo Input: ['ab\nba\n', 'aa\nab\n'] Demo Output: ['YES\n', 'NO\n'] Note: - First example: you can simply swap two letters in string "ab". So we get "ba". - Second example: we can't change string "aa" into string "ab", because "aa" does not contain letter "b".
```python str1 = input() str2 = input() if(len(str1)!=len(str2)): print("NO") else: freq_1 = [0]*26 freq_2 = [0]*26 ct = 0 flag = 0 str1_list = [] str2_list = [] for i in range(len(str1)): freq_1[ord(str1[i])-97]+=1 freq_2[ord(str2[i])-97]+=1 if(str1[i]!=str2[i]): ct+=1 if(ct>2): flag = 1 break else: str1_list.append(str1[i]) str2_list.append(str2[i]) if(flag==1): print("NO") else: freq_flag = 0 for i in range(len(freq_1)): if(freq_1[i]!=freq_2[i]): freq_flag = 1 break if(freq_flag==1): print("NO") else: if(str1_list[0]==str2_list[1] and str1_list[1]==str2_list[0]): print("YES") else: print("NO") ```
3
43
B
Letter
PROGRAMMING
1,100
[ "implementation", "strings" ]
B. Letter
2
256
Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading *s*1 and text *s*2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading — he just leaves some blank space to mark them. Help him; find out if he will manage to compose the needed text.
The first line contains a newspaper heading *s*1. The second line contains the letter text *s*2. *s*1 и *s*2 are non-empty lines consisting of spaces, uppercase and lowercase Latin letters, whose lengths do not exceed 200 symbols. The uppercase and lowercase letters should be differentiated. Vasya does not cut spaces out of the heading.
If Vasya can write the given anonymous letter, print YES, otherwise print NO
[ "Instead of dogging Your footsteps it disappears but you dont notice anything\nwhere is your dog\n", "Instead of dogging Your footsteps it disappears but you dont notice anything\nYour dog is upstears\n", "Instead of dogging your footsteps it disappears but you dont notice anything\nYour dog is upstears\n", "abcdefg hijk\nk j i h g f e d c b a\n" ]
[ "NO\n", "YES\n", "NO\n", "YES\n" ]
none
1,000
[ { "input": "Instead of dogging Your footsteps it disappears but you dont notice anything\nwhere is your dog", "output": "NO" }, { "input": "Instead of dogging Your footsteps it disappears but you dont notice anything\nYour dog is upstears", "output": "YES" }, { "input": "Instead of dogging your footsteps it disappears but you dont notice anything\nYour dog is upstears", "output": "NO" }, { "input": "abcdefg hijk\nk j i h g f e d c b a", "output": "YES" }, { "input": "HpOKgo\neAtAVB", "output": "NO" }, { "input": "GRZGc\nLPzD", "output": "NO" }, { "input": "GtPXu\nd", "output": "NO" }, { "input": "FVF\nr ", "output": "NO" }, { "input": "HpOKgo\nogK", "output": "YES" }, { "input": "GRZGc\nZG", "output": "YES" }, { "input": "HpOKgoueAtAVBdGffvQheJDejNDHhhwyKJisugiRAH OseK yUwqPPNuThUxTfthqIUeb wS jChGOdFDarNrKRT MlwKecxWNoKEeD BbiHAruE XMlvKYVsJGPP\nAHN XvoaNwV AVBKwKjr u U K wKE D K Jy KiHsR h d W Js IHyMPK Br iSqe E fDA g H", "output": "YES" }, { "input": "GRZGcsLPzDrCSXhhNTaibJqVphhjbcPoZhCDUlzAbDnRWjHvxLKtpGiFWiGbfeDxBwCrdJmJGCGv GebAOinUsFrlqKTILOmxrFjSpEoVGoTdSSstJWVgMLKMPettxHASaQZNdOIObcTxtF qTHWBdNIKwj\nWqrxze Ji x q aT GllLrRV jMpGiMDTwwS JDsPGpAZKACmsFCOS CD Sj bCDgKF jJxa RddtLFAi VGLHH SecObzG q hPF ", "output": "YES" }, { "input": "GtPXuwdAxNhODQbjRslDDKciOALJrCifTjDQurQEBeFUUSZWwCZQPdYwZkYbrduMijFjgodAOrKIuUKwSXageZuOWMIhAMexyLRzFuzuXqBDTEaWMzVdbzhxDGSJC SsIYuYILwpiwwcObEHWpFvHeBkWYNitqYrxqgHReHcKnHbtjcWZuaxPBVPb\nTQIKyqFaewOkY lZUOOuxEw EwuKcArxRQGFYkvVWIAe SuanPeHuDjquurJu aSxwgOSw jYMwjxItNUUArQjO BIujAhSwttLWp", "output": "YES" }, { "input": "FVFSr unvtXbpKWF vPaAgNaoTqklzVqiGYcUcBIcattzBrRuNSnKUtmdGKbjcE\nUzrU K an GFGR Wc zt iBa P c T K v p V In b B c", "output": "YES" }, { "input": "lSwjnYLYtDNIZjxHiTawdh ntSzggZogcIZTuiTMWVgwyloMtEhqkrOxgIcFvwvsboXUPILPIymFAEXnhApewJXJNtFyZ\nAoxe jWZ u yImg o AZ FNI w lpj tNhT g y ZYcb rc J w Dlv", "output": "YES" }, { "input": "kvlekcdJqODUKdsJlXkRaileTmdGwUHWWgvgUokQxRzzbpFnswvNKiDnjfOFGvFcnaaiRnBGQmqoPxDHepgYasLhzjDgmvaFfVNEcSPVQCJKAbSyTGpXsAjIHr\nGjzUllNaGGKXUdYmDFpqFAKIwvTpjmqnyswWRTnxlBnavAGvavxJemrjvRJc", "output": "YES" }, { "input": "kWbvhgvvoYOhwXmgTwOSCDXrtFHhqwvMlCvsuuAUXMmWaYXiqHplFZZemhgkTuvsUtIaUxtyYauBIpjdbyYxjZ ZkaBPzwqPfqF kCqGRmXvWuabnQognnkvdNDtRUsSUvSzgBuxCMBWJifbxWegsknp\nBsH bWHJD n Ca T xq PRCv tatn Wjy sm I q s WCjFqdWe t W XUs Do eb Pfh ii hTbF O Fll", "output": "YES" }, { "input": "OTmLdkMhmDEOMQMiW ZpzEIjyElHFrNCfFQDp SZyoZaEIUIpyCHfwOUqiSkKtFHggrTBGkqfOxkChPztmPrsHoxVwAdrxbZLKxPXHlMnrkgMgiaHFopiFFiUEtKwCjpJtwdwkbJCgA bxeDIscFdmHQJLAMNhWlrZisQrHQpvbALWTwpf jnx\nDbZwrQbydCdkJMCrftiwtPFfpMiwwrfIrKidEChKECxQUBVUEfFirbGWiLkFQkdJiFtkrtkbIAEXCEDkwLpK", "output": "YES" }, { "input": "NwcGaIeSkOva\naIa", "output": "YES" }, { "input": "gSrAcVYgAdbdayzbKGhIzLDjyznLRIJH KyvilAaEddmgkBPCNzpmPNeGEbmmpAyHvUSoPvnaORrPUuafpReEGoDOQsAYnUHYfBqhdcopQfxJuGXgKnbdVMQNhJYkyjiJDKlShqBTtnnDQQzEijOMcYRGMgPGVhfIReYennKBLwDTVvcHMIHMgVpJkvzTrezxqS\nHJerIVvRyfrPgAQMTI AqGNO mQDfDwQHKgeeYmuRmozKHILvehMPOJNMRtPTAfvKvsoGKi xHEeKqDAYmQJPUXRJbIbHrgVOMGMTdvYiLui", "output": "YES" }, { "input": "ReB hksbHqQXxUgpvoNK bFqmNVCEiOyKdKcAJQRkpeohpfuqZabvrLfmpZOMcfyFBJGZwVMxiUPP pbZZtJjxhEwvrAba\nJTCpQnIViIGIdQtLnmkVzmcbBZR CoxAdTtWSYpbOglDFifqIVQ vfGKGtLpxpJHiHSWCMeRcrVOXBGBhoEnVhNTPWGTOErNtSvokcGdgZXbgTEtISUyTwaXUEIlJMmutsdCbiyrPZPJyRdOjnSuAGttLy", "output": "NO" }, { "input": "hrLzRegCuDGxTrhDgVvM KowwyYuXGzIpcXdSMgeQVfVOtJZdkhNYSegwFWWoPqcZoeapbQnyCtojgkcyezUNHGGIZrhzsKrvvcrtokIdcnqXXkCNKjrOjrnEAKBNxyDdiMVeyLvXxUYMZQRFdlcdlcxzKTeYzBlmpNiwWbNAAhWkMoGpRxkCuyqkzXdKWwGH\nJESKDOfnFdxPvUOCkrgSBEPQHJtJHzuNGstRbTCcchRWJvCcveSEAtwtOmZZiW", "output": "NO" }, { "input": "yDBxCtUygQwWqONxQCcuAvVCkMGlqgC zvkfEkwqbhMCQxnkwQIUhucCbVUyOBUcXvTNEGriTBwMDMfdsPZgWRgIUDqM\neptVnORTTyixxmWIBpSTEwOXqGZllBgSxPenYCDlFwckJlWsoVwWLAIbPOmFqcKcTcoQqahetl KLfVSyaLVebzsGwPSVbtQAeUdZAaJtfxlCEvvaRhLlVvRJhKat IaB awdqcDlrrhTbRxjEbzGwcdmdavkhcjHjzmwbxAgw", "output": "NO" }, { "input": "jlMwnnotSdlQMluKWkJwAeCetcqbIEnKeNyLWoKCGONDRBQOjbkGpUvDlmSFUJ bWhohqmmIUWTlDsvelUArAcZJBipMDwUvRfBsYzMdQnPDPAuBaeJmAxVKwUMJrwMDxNtlrtAowVWqWiwFGtmquZAcrpFsLHCrvMSMMlvQUqypAihQWrFMNoaqfs IBg\nNzeWQ bafrmDsYlpNHSGTBBgPl WIcuNhyNaNOEFvL", "output": "NO" }, { "input": "zyWvXBcUZqGqjHwZHQryBtFliLYnweXAoMKNpLaunaOlzaauWmLtywsEvWPiwxJapocAFRMjrqWJXYqfKEbBKnzLO\npsbi bsXpSeJaCkIuPWfSRADXdIClxcDCowwJzGCDTyAl", "output": "NO" }, { "input": "kKhuIwRPLCwPFfcnsyCfBdnsraGeOCcLTfXuGjqFSGPSAeDZJSS bXKFanNqWjpFnvRpWxHJspvisDlADJBioxXNbVoXeUedoPcNEpUyEeYxdJXhGzFAmpAiHotSVwbZQsuWjIVhVaEGgqbZHIoDpiEmjTtFylCwCkWWzUOoUfOHxEZvDwNpXhBWamHn\nK VpJjGhNbwCRhcfmNGVjewBFpEmPlIKeTuWiukDtEWpjgqciqglkyNfWrBLbGAKvlNWxaUelJmSlSoakSpRzePvJsshOsTYrMPXdxKpaShjyVIXGhRIAdtiGpNwtiRmGTBZhkJqIMdxMHX RMxCMYcWjcjhtCHyFnCvjjezGbkRDRiVxkbh", "output": "NO" }, { "input": "AXssNpFKyQmJcBdBdfkhhMUzfqJVgcLBddkwtnFSzSRUCjiDcdtmkzIGkCKSxWUEGhmHmciktJyGMkgCductyHx\nI nYhmJfPnvoKUiXYUBIPIcxNYTtvwPUoXERZvY ahlDpQFNMmVZqEBiYqYlHNqcpSCmhFczBlOAhsYFeqMGfqL EJsDNOgwoJfBzqijKOFcYQ", "output": "NO" }, { "input": "lkhrzDZmkdbjzYKPNMRkiwCFoZsMzBQMnxxdKKVJezSBjnLjPpUYtabcPTIaDJeDEobbWHdKOdVfMQwDXzDDcSrwVenDEYpMqfiOQ xSsqApWnAMoyhQXCKFzHvvzvUvkWwmwZrvZz\nsUzGspYpRFsHRbRgTQuCBgnFgPkisTUfFNwyEEWWRiweWWgjRkVQxgTwxOzdsOwfrGIH O gCXpzvHzfItuEHaihmugEyymSJIogYwX qAwcwIItidfnzZDhZgQHi eRjMAeVkJHceDZuJkmxGowOsmcGYYvk Ajtgi TxwihvjLViNZjvscTWvsaQUelTSivLShhEl", "output": "NO" }, { "input": "BRsVjyNhrqRHVwrJzuzRigEhdpbDmaACSPfed\nlWqKTjlrqOCUbgBBZdZDGCeQJDXawPnnDkQdZDgwrEQk", "output": "NO" }, { "input": "KRmINuyBYPwiTsdlyiNVuylToysJKmOpcLovAtwGPqrgFJQNAYvuAiyQRkeFMECVZvkDEmTauXlyjAaYRnTJXORMZRnTakBaUzSelMilejySDIZjQjzcOIrwXdvDvpeRIkoBgreyFXIyyIZutjiEBtwrmzQtPVUhvvdEtDMbXjBpoPVjGdM EXTAK JbCnw\nXZZqlJvzKKtvdNlzFPDTYxidqlsgufVzyEmO FZuLQ vVQsJESNviUCovCK NwwlbxsmPtOJNmAonCqrOZ bZ LVKAsQGmoLnYjeekvEIECFk", "output": "NO" } ]
1,620,716,537
2,147,483,647
PyPy 3
OK
TESTS
30
218
20,480,000
from collections import Counter s1=list(input()) s2=list(input()) c1=Counter(s1) c2=Counter(s2) flag=1 for ele in c2.keys(): if ele==' ': continue if c2[ele]>c1[ele]: print("NO") flag=0 break if flag: print("YES")
Title: Letter Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading *s*1 and text *s*2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading — he just leaves some blank space to mark them. Help him; find out if he will manage to compose the needed text. Input Specification: The first line contains a newspaper heading *s*1. The second line contains the letter text *s*2. *s*1 и *s*2 are non-empty lines consisting of spaces, uppercase and lowercase Latin letters, whose lengths do not exceed 200 symbols. The uppercase and lowercase letters should be differentiated. Vasya does not cut spaces out of the heading. Output Specification: If Vasya can write the given anonymous letter, print YES, otherwise print NO Demo Input: ['Instead of dogging Your footsteps it disappears but you dont notice anything\nwhere is your dog\n', 'Instead of dogging Your footsteps it disappears but you dont notice anything\nYour dog is upstears\n', 'Instead of dogging your footsteps it disappears but you dont notice anything\nYour dog is upstears\n', 'abcdefg hijk\nk j i h g f e d c b a\n'] Demo Output: ['NO\n', 'YES\n', 'NO\n', 'YES\n'] Note: none
```python from collections import Counter s1=list(input()) s2=list(input()) c1=Counter(s1) c2=Counter(s2) flag=1 for ele in c2.keys(): if ele==' ': continue if c2[ele]>c1[ele]: print("NO") flag=0 break if flag: print("YES") ```
3.907353
263
A
Beautiful Matrix
PROGRAMMING
800
[ "implementation" ]
null
null
You've got a 5<=×<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to right. In one move, you are allowed to apply one of the two following transformations to the matrix: 1. Swap two neighboring matrix rows, that is, rows with indexes *i* and *i*<=+<=1 for some integer *i* (1<=≤<=*i*<=&lt;<=5). 1. Swap two neighboring matrix columns, that is, columns with indexes *j* and *j*<=+<=1 for some integer *j* (1<=≤<=*j*<=&lt;<=5). You think that a matrix looks beautiful, if the single number one of the matrix is located in its middle (in the cell that is on the intersection of the third row and the third column). Count the minimum number of moves needed to make the matrix beautiful.
The input consists of five lines, each line contains five integers: the *j*-th integer in the *i*-th line of the input represents the element of the matrix that is located on the intersection of the *i*-th row and the *j*-th column. It is guaranteed that the matrix consists of 24 zeroes and a single number one.
Print a single integer — the minimum number of moves needed to make the matrix beautiful.
[ "0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n", "0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n" ]
[ "3\n", "1\n" ]
none
500
[ { "input": "0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "3" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "1" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "0" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 1", "output": "4" }, { "input": "0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "3" }, { "input": "1 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "4" }, { "input": "0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "2" }, { "input": "0 0 0 1 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "3" }, { "input": "0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "4" }, { "input": "0 0 0 0 0\n1 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "3" }, { "input": "0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "2" }, { "input": "0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "1" }, { "input": "0 0 0 0 0\n0 0 0 1 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "2" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n1 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "2" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 1 0\n0 0 0 0 0\n0 0 0 0 0", "output": "1" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0", "output": "2" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n1 0 0 0 0\n0 0 0 0 0", "output": "3" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0", "output": "2" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0", "output": "1" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 1 0\n0 0 0 0 0", "output": "2" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0", "output": "3" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n1 0 0 0 0", "output": "4" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0", "output": "3" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 1 0 0", "output": "2" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 1 0", "output": "3" } ]
1,698,610,342
2,147,483,647
Python 3
OK
TESTS
25
92
0
Mt = [] order_Mt = 5 for i in range(order_Mt): Mt_row = list(map(int, input().split())) Mt.append(Mt_row) single_row, single_col = None, None for i in range(order_Mt): for j in range(order_Mt): if Mt[i][j] == 1: single_row, single_col = i, j row_move = abs(single_row - 2) col_move = abs(single_col - 2) m = row_move + col_move print(m)
Title: Beautiful Matrix Time Limit: None seconds Memory Limit: None megabytes Problem Description: You've got a 5<=×<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to right. In one move, you are allowed to apply one of the two following transformations to the matrix: 1. Swap two neighboring matrix rows, that is, rows with indexes *i* and *i*<=+<=1 for some integer *i* (1<=≤<=*i*<=&lt;<=5). 1. Swap two neighboring matrix columns, that is, columns with indexes *j* and *j*<=+<=1 for some integer *j* (1<=≤<=*j*<=&lt;<=5). You think that a matrix looks beautiful, if the single number one of the matrix is located in its middle (in the cell that is on the intersection of the third row and the third column). Count the minimum number of moves needed to make the matrix beautiful. Input Specification: The input consists of five lines, each line contains five integers: the *j*-th integer in the *i*-th line of the input represents the element of the matrix that is located on the intersection of the *i*-th row and the *j*-th column. It is guaranteed that the matrix consists of 24 zeroes and a single number one. Output Specification: Print a single integer — the minimum number of moves needed to make the matrix beautiful. Demo Input: ['0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n', '0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n'] Demo Output: ['3\n', '1\n'] Note: none
```python Mt = [] order_Mt = 5 for i in range(order_Mt): Mt_row = list(map(int, input().split())) Mt.append(Mt_row) single_row, single_col = None, None for i in range(order_Mt): for j in range(order_Mt): if Mt[i][j] == 1: single_row, single_col = i, j row_move = abs(single_row - 2) col_move = abs(single_col - 2) m = row_move + col_move print(m) ```
3
466
A
Cheap Travel
PROGRAMMING
1,200
[ "implementation" ]
null
null
Ann has recently started commuting by subway. We know that a one ride subway ticket costs *a* rubles. Besides, Ann found out that she can buy a special ticket for *m* rides (she can buy it several times). It costs *b* rubles. Ann did the math; she will need to use subway *n* times. Help Ann, tell her what is the minimum sum of money she will have to spend to make *n* rides?
The single line contains four space-separated integers *n*, *m*, *a*, *b* (1<=≤<=*n*,<=*m*,<=*a*,<=*b*<=≤<=1000) — the number of rides Ann has planned, the number of rides covered by the *m* ride ticket, the price of a one ride ticket and the price of an *m* ride ticket.
Print a single integer — the minimum sum in rubles that Ann will need to spend.
[ "6 2 1 2\n", "5 2 2 3\n" ]
[ "6\n", "8\n" ]
In the first sample one of the optimal solutions is: each time buy a one ride ticket. There are other optimal solutions. For example, buy three *m* ride tickets.
500
[ { "input": "6 2 1 2", "output": "6" }, { "input": "5 2 2 3", "output": "8" }, { "input": "10 3 5 1", "output": "4" }, { "input": "1000 1 1000 1000", "output": "1000000" }, { "input": "1000 3 1000 1000", "output": "334000" }, { "input": "1 1 1 1", "output": "1" }, { "input": "10 2 1 1", "output": "5" }, { "input": "1 1000 1 2", "output": "1" }, { "input": "1 1000 3 2", "output": "2" }, { "input": "10 3 1 2", "output": "7" }, { "input": "995 1 2 1", "output": "995" }, { "input": "556 2 16 15", "output": "4170" }, { "input": "477 2 16 14", "output": "3346" }, { "input": "101 110 1 100", "output": "100" }, { "input": "9 3 3 10", "output": "27" }, { "input": "100 8 10 1", "output": "13" }, { "input": "6 4 1 3", "output": "5" }, { "input": "8 5 2 8", "output": "14" }, { "input": "1000 2 1 1000", "output": "1000" } ]
1,694,985,069
2,147,483,647
Python 3
OK
TESTS
19
295
0
# Ann has recently started commuting by subway. We know that a one ride subway ticket costs a rubles. Besides, # Ann found out that she can buy a special ticket for m rides (she can buy it several times). It costs b rubles. Ann # did the math; she will need to use subway n times. Help Ann, tell her what is the minimum sum of money she will # have to spend to make n rides? # Input The single line contains four space-separated integers n, m, a, b — the number of rides Ann has planned, # the number of rides covered by the m ride ticket, the price of a one ride ticket and the price of an m ride ticket. # Output # Print a single integer — the minimum sum in rubles that Ann will need to spend. vl = input().split() # the number of rides Ann has planned n = int(vl[0]) # the number of rides covered by the m ride ticket m = int(vl[1]) # the price of a one ride ticket a = int(vl[2]) # the price of an m ride ticket b = int(vl[3]) onerideminimal = n if (n / m) >= (n//m): mminimaltickets = n//m + 1 else: mminimaltickets = n/m minimal_spend = n*a for i in range(mminimaltickets+1): for j in range(onerideminimal+1): t_rides = i * m + j cost = i * b + j * a if t_rides >= n: if cost <= minimal_spend: minimal_spend = cost print(minimal_spend)
Title: Cheap Travel Time Limit: None seconds Memory Limit: None megabytes Problem Description: Ann has recently started commuting by subway. We know that a one ride subway ticket costs *a* rubles. Besides, Ann found out that she can buy a special ticket for *m* rides (she can buy it several times). It costs *b* rubles. Ann did the math; she will need to use subway *n* times. Help Ann, tell her what is the minimum sum of money she will have to spend to make *n* rides? Input Specification: The single line contains four space-separated integers *n*, *m*, *a*, *b* (1<=≤<=*n*,<=*m*,<=*a*,<=*b*<=≤<=1000) — the number of rides Ann has planned, the number of rides covered by the *m* ride ticket, the price of a one ride ticket and the price of an *m* ride ticket. Output Specification: Print a single integer — the minimum sum in rubles that Ann will need to spend. Demo Input: ['6 2 1 2\n', '5 2 2 3\n'] Demo Output: ['6\n', '8\n'] Note: In the first sample one of the optimal solutions is: each time buy a one ride ticket. There are other optimal solutions. For example, buy three *m* ride tickets.
```python # Ann has recently started commuting by subway. We know that a one ride subway ticket costs a rubles. Besides, # Ann found out that she can buy a special ticket for m rides (she can buy it several times). It costs b rubles. Ann # did the math; she will need to use subway n times. Help Ann, tell her what is the minimum sum of money she will # have to spend to make n rides? # Input The single line contains four space-separated integers n, m, a, b — the number of rides Ann has planned, # the number of rides covered by the m ride ticket, the price of a one ride ticket and the price of an m ride ticket. # Output # Print a single integer — the minimum sum in rubles that Ann will need to spend. vl = input().split() # the number of rides Ann has planned n = int(vl[0]) # the number of rides covered by the m ride ticket m = int(vl[1]) # the price of a one ride ticket a = int(vl[2]) # the price of an m ride ticket b = int(vl[3]) onerideminimal = n if (n / m) >= (n//m): mminimaltickets = n//m + 1 else: mminimaltickets = n/m minimal_spend = n*a for i in range(mminimaltickets+1): for j in range(onerideminimal+1): t_rides = i * m + j cost = i * b + j * a if t_rides >= n: if cost <= minimal_spend: minimal_spend = cost print(minimal_spend) ```
3
653
A
Bear and Three Balls
PROGRAMMING
900
[ "brute force", "implementation", "sortings" ]
null
null
Limak is a little polar bear. He has *n* balls, the *i*-th ball has size *t**i*. Limak wants to give one ball to each of his three friends. Giving gifts isn't easy — there are two rules Limak must obey to make friends happy: - No two friends can get balls of the same size. - No two friends can get balls of sizes that differ by more than 2. For example, Limak can choose balls with sizes 4, 5 and 3, or balls with sizes 90, 91 and 92. But he can't choose balls with sizes 5, 5 and 6 (two friends would get balls of the same size), and he can't choose balls with sizes 30, 31 and 33 (because sizes 30 and 33 differ by more than 2). Your task is to check whether Limak can choose three balls that satisfy conditions above.
The first line of the input contains one integer *n* (3<=≤<=*n*<=≤<=50) — the number of balls Limak has. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=1000) where *t**i* denotes the size of the *i*-th ball.
Print "YES" (without quotes) if Limak can choose three balls of distinct sizes, such that any two of them differ by no more than 2. Otherwise, print "NO" (without quotes).
[ "4\n18 55 16 17\n", "6\n40 41 43 44 44 44\n", "8\n5 972 3 4 1 4 970 971\n" ]
[ "YES\n", "NO\n", "YES\n" ]
In the first sample, there are 4 balls and Limak is able to choose three of them to satisfy the rules. He must must choose balls with sizes 18, 16 and 17. In the second sample, there is no way to give gifts to three friends without breaking the rules. In the third sample, there is even more than one way to choose balls: 1. Choose balls with sizes 3, 4 and 5. 1. Choose balls with sizes 972, 970, 971.
500
[ { "input": "4\n18 55 16 17", "output": "YES" }, { "input": "6\n40 41 43 44 44 44", "output": "NO" }, { "input": "8\n5 972 3 4 1 4 970 971", "output": "YES" }, { "input": "3\n959 747 656", "output": "NO" }, { "input": "4\n1 2 2 3", "output": "YES" }, { "input": "50\n998 30 384 289 505 340 872 223 663 31 929 625 864 699 735 589 676 399 745 635 963 381 75 97 324 612 597 797 103 382 25 894 219 458 337 572 201 355 294 275 278 311 586 573 965 704 936 237 715 543", "output": "NO" }, { "input": "50\n941 877 987 982 966 979 984 810 811 909 872 980 957 897 845 995 924 905 984 914 824 840 868 910 815 808 872 858 883 952 823 835 860 874 959 972 931 867 866 987 982 837 800 921 887 910 982 980 828 869", "output": "YES" }, { "input": "3\n408 410 409", "output": "YES" }, { "input": "3\n903 902 904", "output": "YES" }, { "input": "3\n399 400 398", "output": "YES" }, { "input": "3\n450 448 449", "output": "YES" }, { "input": "3\n390 389 388", "output": "YES" }, { "input": "3\n438 439 440", "output": "YES" }, { "input": "11\n488 688 490 94 564 615 641 170 489 517 669", "output": "YES" }, { "input": "24\n102 672 983 82 720 501 81 721 982 312 207 897 159 964 611 956 118 984 37 271 596 403 772 954", "output": "YES" }, { "input": "36\n175 551 70 479 875 480 979 32 465 402 640 116 76 687 874 678 359 785 753 401 978 629 162 963 886 641 39 845 132 930 2 372 478 947 407 318", "output": "YES" }, { "input": "6\n10 79 306 334 304 305", "output": "YES" }, { "input": "34\n787 62 26 683 486 364 684 891 846 801 969 837 359 800 836 359 471 637 732 91 841 836 7 799 959 405 416 841 737 803 615 483 323 365", "output": "YES" }, { "input": "30\n860 238 14 543 669 100 428 789 576 484 754 274 849 850 586 377 711 386 510 408 520 693 23 477 266 851 728 711 964 73", "output": "YES" }, { "input": "11\n325 325 324 324 324 325 325 324 324 324 324", "output": "NO" }, { "input": "7\n517 517 518 517 518 518 518", "output": "NO" }, { "input": "20\n710 710 711 711 711 711 710 710 710 710 711 710 710 710 710 710 710 711 711 710", "output": "NO" }, { "input": "48\n29 30 29 29 29 30 29 30 30 30 30 29 30 30 30 29 29 30 30 29 30 29 29 30 29 30 29 30 30 29 30 29 29 30 30 29 29 30 30 29 29 30 30 30 29 29 30 29", "output": "NO" }, { "input": "7\n880 880 514 536 881 881 879", "output": "YES" }, { "input": "15\n377 432 262 376 261 375 377 262 263 263 261 376 262 262 375", "output": "YES" }, { "input": "32\n305 426 404 961 426 425 614 304 404 425 615 403 303 304 615 303 305 405 427 614 403 303 425 615 404 304 427 403 206 616 405 404", "output": "YES" }, { "input": "41\n115 686 988 744 762 519 745 519 518 83 85 115 520 44 687 686 685 596 988 687 989 988 114 745 84 519 519 746 988 84 745 744 115 114 85 115 520 746 745 116 987", "output": "YES" }, { "input": "47\n1 2 483 28 7 109 270 651 464 162 353 521 224 989 721 499 56 69 197 716 313 446 580 645 828 197 100 138 789 499 147 677 384 711 783 937 300 543 540 93 669 604 739 122 632 822 116", "output": "NO" }, { "input": "31\n1 2 1 373 355 692 750 920 578 666 615 232 141 129 663 929 414 704 422 559 568 731 354 811 532 618 39 879 292 602 995", "output": "NO" }, { "input": "50\n5 38 41 4 15 40 27 39 20 3 44 47 30 6 36 29 35 12 19 26 10 2 21 50 11 46 48 49 17 16 33 13 32 28 31 18 23 34 7 14 24 45 9 37 1 8 42 25 43 22", "output": "YES" }, { "input": "50\n967 999 972 990 969 978 963 987 954 955 973 970 959 981 995 983 986 994 979 957 965 982 992 977 953 975 956 961 993 997 998 958 980 962 960 951 996 991 1000 966 971 988 976 968 989 984 974 964 985 952", "output": "YES" }, { "input": "50\n850 536 761 506 842 898 857 723 583 637 536 943 895 929 890 612 832 633 696 731 553 880 710 812 665 877 915 636 711 540 748 600 554 521 813 796 568 513 543 809 798 820 928 504 999 646 907 639 550 911", "output": "NO" }, { "input": "3\n3 1 2", "output": "YES" }, { "input": "3\n500 999 1000", "output": "NO" }, { "input": "10\n101 102 104 105 107 109 110 112 113 115", "output": "NO" }, { "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": "NO" }, { "input": "50\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", "output": "NO" }, { "input": "3\n1000 999 998", "output": "YES" }, { "input": "49\n343 322 248 477 53 156 245 493 209 141 370 66 229 184 434 137 276 472 216 456 147 180 140 114 493 323 393 262 380 314 222 124 98 441 129 346 48 401 347 460 122 125 114 106 189 260 374 165 456", "output": "NO" }, { "input": "20\n1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 3 3 3 3 3", "output": "YES" }, { "input": "3\n999 999 1000", "output": "NO" }, { "input": "9\n2 4 5 13 25 100 200 300 400", "output": "NO" }, { "input": "9\n1 1 1 2 2 2 3 3 3", "output": "YES" }, { "input": "3\n1 1 2", "output": "NO" }, { "input": "3\n998 999 1000", "output": "YES" }, { "input": "12\n1 1 1 1 1 1 1 1 1 2 2 4", "output": "NO" }, { "input": "4\n4 3 4 5", "output": "YES" }, { "input": "6\n1 1 1 2 2 2", "output": "NO" }, { "input": "3\n2 3 2", "output": "NO" }, { "input": "5\n10 5 6 3 2", "output": "NO" }, { "input": "3\n1 2 1", "output": "NO" }, { "input": "3\n1 2 3", "output": "YES" }, { "input": "4\n998 999 1000 1000", "output": "YES" }, { "input": "5\n2 3 9 9 4", "output": "YES" }, { "input": "4\n1 2 4 4", "output": "NO" }, { "input": "3\n1 1 1", "output": "NO" }, { "input": "3\n2 2 3", "output": "NO" }, { "input": "7\n1 2 2 2 4 5 6", "output": "YES" }, { "input": "5\n1 3 10 3 10", "output": "NO" }, { "input": "3\n1 2 2", "output": "NO" }, { "input": "4\n1000 1000 999 998", "output": "YES" }, { "input": "3\n5 3 7", "output": "NO" }, { "input": "6\n1 1 2 2 3 3", "output": "YES" }, { "input": "9\n6 6 6 5 5 5 4 4 4", "output": "YES" }, { "input": "7\n5 6 6 6 7 7 7", "output": "YES" }, { "input": "5\n2 3 3 3 4", "output": "YES" }, { "input": "5\n2 1 2 1 3", "output": "YES" }, { "input": "3\n1 2 7", "output": "NO" }, { "input": "3\n1000 1000 1000", "output": "NO" }, { "input": "5\n1 100 2 100 3", "output": "YES" }, { "input": "5\n5 4 6 5 5", "output": "YES" }, { "input": "12\n1 1 1 1 2 2 2 2 3 3 3 3", "output": "YES" }, { "input": "5\n9 9 1 2 3", "output": "YES" }, { "input": "6\n1 2 3 1 2 3", "output": "YES" }, { "input": "7\n1 1 1 1 2 3 3", "output": "YES" }, { "input": "3\n13 13 13", "output": "NO" }, { "input": "3\n42 42 42", "output": "NO" }, { "input": "8\n1 1 1 1 2 2 2 2", "output": "NO" }, { "input": "6\n1 1 1 1 2 3", "output": "YES" }, { "input": "6\n1 1 2 2 6 6", "output": "NO" }, { "input": "6\n1 2 5 5 5 5", "output": "NO" }, { "input": "9\n1 2 3 1 2 3 1 2 3", "output": "YES" }, { "input": "4\n1 2 1 100", "output": "NO" }, { "input": "5\n1 1 2 2 3", "output": "YES" } ]
1,688,998,720
2,147,483,647
PyPy 3-64
RUNTIME_ERROR
TESTS
1
61
2,867,200
n = int(input()) li = list(set(sorted(list(map(int, input().split()))))) for i in range(n - 2): if li[i] + 1 == li[i + 1] and li[i + 1] + 1 == li[i + 2]: print("YES") exit() print("NO")
Title: Bear and Three Balls Time Limit: None seconds Memory Limit: None megabytes Problem Description: Limak is a little polar bear. He has *n* balls, the *i*-th ball has size *t**i*. Limak wants to give one ball to each of his three friends. Giving gifts isn't easy — there are two rules Limak must obey to make friends happy: - No two friends can get balls of the same size. - No two friends can get balls of sizes that differ by more than 2. For example, Limak can choose balls with sizes 4, 5 and 3, or balls with sizes 90, 91 and 92. But he can't choose balls with sizes 5, 5 and 6 (two friends would get balls of the same size), and he can't choose balls with sizes 30, 31 and 33 (because sizes 30 and 33 differ by more than 2). Your task is to check whether Limak can choose three balls that satisfy conditions above. Input Specification: The first line of the input contains one integer *n* (3<=≤<=*n*<=≤<=50) — the number of balls Limak has. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=1000) where *t**i* denotes the size of the *i*-th ball. Output Specification: Print "YES" (without quotes) if Limak can choose three balls of distinct sizes, such that any two of them differ by no more than 2. Otherwise, print "NO" (without quotes). Demo Input: ['4\n18 55 16 17\n', '6\n40 41 43 44 44 44\n', '8\n5 972 3 4 1 4 970 971\n'] Demo Output: ['YES\n', 'NO\n', 'YES\n'] Note: In the first sample, there are 4 balls and Limak is able to choose three of them to satisfy the rules. He must must choose balls with sizes 18, 16 and 17. In the second sample, there is no way to give gifts to three friends without breaking the rules. In the third sample, there is even more than one way to choose balls: 1. Choose balls with sizes 3, 4 and 5. 1. Choose balls with sizes 972, 970, 971.
```python n = int(input()) li = list(set(sorted(list(map(int, input().split()))))) for i in range(n - 2): if li[i] + 1 == li[i + 1] and li[i + 1] + 1 == li[i + 2]: print("YES") exit() print("NO") ```
-1
78
A
Haiku
PROGRAMMING
800
[ "implementation", "strings" ]
A. Haiku
2
256
Haiku is a genre of Japanese traditional poetry. A haiku poem consists of 17 syllables split into three phrases, containing 5, 7 and 5 syllables correspondingly (the first phrase should contain exactly 5 syllables, the second phrase should contain exactly 7 syllables, and the third phrase should contain exactly 5 syllables). A haiku masterpiece contains a description of a moment in those three phrases. Every word is important in a small poem, which is why haiku are rich with symbols. Each word has a special meaning, a special role. The main principle of haiku is to say much using a few words. To simplify the matter, in the given problem we will consider that the number of syllable in the phrase is equal to the number of vowel letters there. Only the following letters are regarded as vowel letters: "a", "e", "i", "o" and "u". Three phases from a certain poem are given. Determine whether it is haiku or not.
The input data consists of three lines. The length of each line is between 1 and 100, inclusive. The *i*-th line contains the *i*-th phrase of the poem. Each phrase consists of one or more words, which are separated by one or more spaces. A word is a non-empty sequence of lowercase Latin letters. Leading and/or trailing spaces in phrases are allowed. Every phrase has at least one non-space character. See the example for clarification.
Print "YES" (without the quotes) if the poem is a haiku. Otherwise, print "NO" (also without the quotes).
[ "on codeforces \nbeta round is running\n a rustling of keys \n", "how many gallons\nof edo s rain did you drink\n cuckoo\n" ]
[ "YES", "NO" ]
none
500
[ { "input": "on codeforces \nbeta round is running\n a rustling of keys ", "output": "YES" }, { "input": "how many gallons\nof edo s rain did you drink\n cuckoo", "output": "NO" }, { "input": " hatsu shigure\n saru mo komino wo\nhoshige nari", "output": "YES" }, { "input": "o vetus stagnum\n rana de ripa salit\n ac sonant aquae", "output": "NO" }, { "input": " furuike ya\nkawazu tobikomu\nmizu no oto ", "output": "YES" }, { "input": " noch da leich\na stamperl zum aufwaerma\n da pfarrer kimmt a ", "output": "NO" }, { "input": " sommerfuglene \n hvorfor bruge mange ord\n et kan gore det", "output": "YES" }, { "input": " ab der mittagszeit\n ist es etwas schattiger\n ein wolkenhimmel", "output": "NO" }, { "input": "tornando a vederli\ni fiori di ciliegio la sera\nson divenuti frutti", "output": "NO" }, { "input": "kutaburete\nyado karu koro ya\nfuji no hana", "output": "YES" }, { "input": " beginnings of poetry\n the rice planting songs \n of the interior", "output": "NO" }, { "input": " door zomerregens\n zijn de kraanvogelpoten\n korter geworden", "output": "NO" }, { "input": " derevo na srub\na ptitsi bezzabotno\n gnezdishko tam vyut", "output": "YES" }, { "input": "writing in the dark\nunaware that my pen\nhas run out of ink", "output": "NO" }, { "input": "kusaaiu\nuieueua\nuo efaa", "output": "YES" }, { "input": "v\nh\np", "output": "NO" }, { "input": "i\ni\nu", "output": "NO" }, { "input": "awmio eoj\nabdoolceegood\nwaadeuoy", "output": "YES" }, { "input": "xzpnhhnqsjpxdboqojixmofawhdjcfbscq\nfoparnxnbzbveycoltwdrfbwwsuobyoz hfbrszy\nimtqryscsahrxpic agfjh wvpmczjjdrnwj mcggxcdo", "output": "YES" }, { "input": "wxjcvccp cppwsjpzbd dhizbcnnllckybrnfyamhgkvkjtxxfzzzuyczmhedhztugpbgpvgh\nmdewztdoycbpxtp bsiw hknggnggykdkrlihvsaykzfiiw\ndewdztnngpsnn lfwfbvnwwmxoojknygqb hfe ibsrxsxr", "output": "YES" }, { "input": "nbmtgyyfuxdvrhuhuhpcfywzrbclp znvxw synxmzymyxcntmhrjriqgdjh xkjckydbzjbvtjurnf\nhhnhxdknvamywhsrkprofnyzlcgtdyzzjdsfxyddvilnzjziz qmwfdvzckgcbrrxplxnxf mpxwxyrpesnewjrx ajxlfj\nvcczq hddzd cvefmhxwxxyqcwkr fdsndckmesqeq zyjbwbnbyhybd cta nsxzidl jpcvtzkldwd", "output": "YES" }, { "input": "rvwdsgdsrutgjwscxz pkd qtpmfbqsmctuevxdj kjzknzghdvxzlaljcntg jxhvzn yciktbsbyscfypx x xhkxnfpdp\nwdfhvqgxbcts mnrwbr iqttsvigwdgvlxwhsmnyxnttedonxcfrtmdjjmacvqtkbmsnwwvvrlxwvtggeowtgsqld qj\nvsxcdhbzktrxbywpdvstr meykarwtkbm pkkbhvwvelclfmpngzxdmblhcvf qmabmweldplmczgbqgzbqnhvcdpnpjtch ", "output": "YES" }, { "input": "brydyfsmtzzkpdsqvvztmprhqzbzqvgsblnz naait tdtiprjsttwusdykndwcccxfmzmrmfmzjywkpgbfnjpypgcbcfpsyfj k\nucwdfkfyxxxht lxvnovqnnsqutjsyagrplb jhvtwdptrwcqrovncdvqljjlrpxcfbxqgsfylbgmcjpvpl ccbcybmigpmjrxpu\nfgwtpcjeywgnxgbttgx htntpbk tkkpwbgxwtbxvcpkqbzetjdkcwad tftnjdxxjdvbpfibvxuglvx llyhgjvggtw jtjyphs", "output": "YES" }, { "input": "nyc aqgqzjjlj mswgmjfcxlqdscheskchlzljlsbhyn iobxymwzykrsnljj\nnnebeaoiraga\nqpjximoqzswhyyszhzzrhfwhf iyxysdtcpmikkwpugwlxlhqfkn", "output": "NO" }, { "input": "lzrkztgfe mlcnq ay ydmdzxh cdgcghxnkdgmgfzgahdjjmqkpdbskreswpnblnrc fmkwziiqrbskp\np oukeaz gvvy kghtrjlczyl qeqhgfgfej\nwfolhkmktvsjnrpzfxcxzqmfidtlzmuhxac wsncjgmkckrywvxmnjdpjpfydhk qlmdwphcvyngansqhl", "output": "NO" }, { "input": "yxcboqmpwoevrdhvpxfzqmammak\njmhphkxppkqkszhqqtkvflarsxzla pbxlnnnafqbsnmznfj qmhoktgzix qpmrgzxqvmjxhskkksrtryehfnmrt dtzcvnvwp\nscwymuecjxhw rdgsffqywwhjpjbfcvcrnisfqllnbplpadfklayjguyvtrzhwblftclfmsr", "output": "NO" }, { "input": "qfdwsr jsbrpfmn znplcx nhlselflytndzmgxqpgwhpi ghvbbxrkjdirfghcybhkkqdzmyacvrrcgsneyjlgzfvdmxyjmph\nylxlyrzs drbktzsniwcbahjkgohcghoaczsmtzhuwdryjwdijmxkmbmxv yyfrokdnsx\nyw xtwyzqlfxwxghugoyscqlx pljtz aldfskvxlsxqgbihzndhxkswkxqpwnfcxzfyvncstfpqf", "output": "NO" }, { "input": "g rguhqhcrzmuqthtmwzhfyhpmqzzosa\nmhjimzvchkhejh irvzejhtjgaujkqfxhpdqjnxr dvqallgssktqvsxi\npcwbliftjcvuzrsqiswohi", "output": "NO" }, { "input": " ngxtlq iehiise vgffqcpnmsoqzyseuqqtggokymol zn\nvjdjljazeujwoubkcvtsbepooxqzrueaauokhepiquuopfild\ngoabauauaeotoieufueeknudiilupouaiaexcoapapu", "output": "NO" }, { "input": "ycnvnnqk mhrmhctpkfbc qbyvtjznmndqjzgbcxmvrpkfcll zwspfptmbxgrdv dsgkk nfytsqjrnfbhh pzdldzymvkdxxwh\nvnhjfwgdnyjptsmblyxmpzylsbjlmtkkwjcbqwjctqvrlqqkdsrktxlnslspvnn mdgsmzblhbnvpczmqkcffwhwljqkzmk hxcm\nrghnjvzcpprrgmtgytpkzyc mrdnnhpkwypwqbtzjyfwvrdwyjltbzxtbstzs xdjzdmx yjsqtzlrnvyssvglsdjrmsrfrcdpqt", "output": "NO" }, { "input": "ioeeaioeiuoeaeieuuieooaouiuouiioaueeaiaiuoaoiioeeaauooiuuieeuaeeoauieeaiuoieiaieuoauaaoioooieueueuai\nuooaoeeaoiuuoeioaoouaououoeioiaeueoioaiouaeaoioiuuaueeuaiuoiueoiuaoeeieeouaeeaeeieioeoiiieuuueuuieuo\naeeouieeieoueaioeoioooiouaeeeiaaioueauaueiouuuaieuuioiaeiueauueaoieauauoeueuaiueuuaueeoueauaeaoieeoo", "output": "NO" }, { "input": "mkgycgmrqtmlwj vddlbsgdptyfrcj nmrddjchydvbsyhgzytfzvwbhqmmhkpsyrcnknpsqrr wcnf wfvgskrnsmnrcqgcnc q\npn cclcyjjdp rqkpgyrvyyd hhynrochfa pthyffqvskazfshvzcmvhmsrxvquzkdvivlbfypwbgltfbjmhzljvgzmxjlrjdjq\nauuouieuaaauoooeoiuoaueuueauiuuuiaeuwuoiaeoeaieauieouoaeiiieiioiuuuiuauioiiuoeauueieaueiaioeuaoaaau", "output": "NO" }, { "input": "ab\na\na", "output": "NO" }, { "input": "on codeforcs\nbeta round is runnineg\na rustling of keys", "output": "NO" }, { "input": "coooooooooooooooood\nd\nd", "output": "NO" }, { "input": "on codeforces \nbeta round is runninog\n a rustling of keys", "output": "NO" }, { "input": "aaaaaaaaaaaaaaa\na\na", "output": "NO" }, { "input": "aaaaaccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\naaaaaaaccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\naaaaaccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc", "output": "YES" }, { "input": "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\ncccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\ncccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc", "output": "NO" }, { "input": "aaaaaa\naaaaaa\naaaaa", "output": "NO" } ]
1,664,002,477
2,147,483,647
Python 3
OK
TESTS
40
92
0
l=[] m=[] for i in range(3): l.append(input('')) for j in l: k=list(j) a=k.count('a') b=k.count('e') c=k.count('i') d=k.count('o') e=k.count('u') s=a+b+c+d+e m.append(s) #print(m) if m[0]==5 and m[1]==7 and m[2]==5: print('YES') else: print('NO')
Title: Haiku Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Haiku is a genre of Japanese traditional poetry. A haiku poem consists of 17 syllables split into three phrases, containing 5, 7 and 5 syllables correspondingly (the first phrase should contain exactly 5 syllables, the second phrase should contain exactly 7 syllables, and the third phrase should contain exactly 5 syllables). A haiku masterpiece contains a description of a moment in those three phrases. Every word is important in a small poem, which is why haiku are rich with symbols. Each word has a special meaning, a special role. The main principle of haiku is to say much using a few words. To simplify the matter, in the given problem we will consider that the number of syllable in the phrase is equal to the number of vowel letters there. Only the following letters are regarded as vowel letters: "a", "e", "i", "o" and "u". Three phases from a certain poem are given. Determine whether it is haiku or not. Input Specification: The input data consists of three lines. The length of each line is between 1 and 100, inclusive. The *i*-th line contains the *i*-th phrase of the poem. Each phrase consists of one or more words, which are separated by one or more spaces. A word is a non-empty sequence of lowercase Latin letters. Leading and/or trailing spaces in phrases are allowed. Every phrase has at least one non-space character. See the example for clarification. Output Specification: Print "YES" (without the quotes) if the poem is a haiku. Otherwise, print "NO" (also without the quotes). Demo Input: ['on codeforces \nbeta round is running\n a rustling of keys \n', 'how many gallons\nof edo s rain did you drink\n cuckoo\n'] Demo Output: ['YES', 'NO'] Note: none
```python l=[] m=[] for i in range(3): l.append(input('')) for j in l: k=list(j) a=k.count('a') b=k.count('e') c=k.count('i') d=k.count('o') e=k.count('u') s=a+b+c+d+e m.append(s) #print(m) if m[0]==5 and m[1]==7 and m[2]==5: print('YES') else: print('NO') ```
3.977
672
B
Different is Good
PROGRAMMING
1,000
[ "constructive algorithms", "implementation", "strings" ]
null
null
A wise man told Kerem "Different is good" once, so Kerem wants all things in his life to be different. Kerem recently got a string *s* consisting of lowercase English letters. Since Kerem likes it when things are different, he wants all substrings of his string *s* to be distinct. Substring is a string formed by some number of consecutive characters of the string. For example, string "aba" has substrings "" (empty substring), "a", "b", "a", "ab", "ba", "aba". If string *s* has at least two equal substrings then Kerem will change characters at some positions to some other lowercase English letters. Changing characters is a very tiring job, so Kerem want to perform as few changes as possible. Your task is to find the minimum number of changes needed to make all the substrings of the given string distinct, or determine that it is impossible.
The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100<=000) — the length of the string *s*. The second line contains the string *s* of length *n* consisting of only lowercase English letters.
If it's impossible to change the string *s* such that all its substring are distinct print -1. Otherwise print the minimum required number of changes.
[ "2\naa\n", "4\nkoko\n", "5\nmurat\n" ]
[ "1\n", "2\n", "0\n" ]
In the first sample one of the possible solutions is to change the first character to 'b'. In the second sample, one may change the first character to 'a' and second character to 'b', so the string becomes "abko".
1,000
[ { "input": "2\naa", "output": "1" }, { "input": "4\nkoko", "output": "2" }, { "input": "5\nmurat", "output": "0" }, { "input": "6\nacbead", "output": "1" }, { "input": "7\ncdaadad", "output": "4" }, { "input": "25\npeoaicnbisdocqofsqdpgobpn", "output": "12" }, { "input": "25\ntcqpchnqskqjacruoaqilgebu", "output": "7" }, { "input": "13\naebaecedabbee", "output": "8" }, { "input": "27\naaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "-1" }, { "input": "10\nbababbdaee", "output": "6" }, { "input": "11\ndbadcdbdbca", "output": "7" }, { "input": "12\nacceaabddaaa", "output": "7" }, { "input": "13\nabddfbfaeecfa", "output": "7" }, { "input": "14\neeceecacdbcbbb", "output": "9" }, { "input": "15\ndcbceaaggabaheb", "output": "8" }, { "input": "16\nhgiegfbadgcicbhd", "output": "7" }, { "input": "17\nabhfibbdddfghgfdi", "output": "10" }, { "input": "26\nbbbbbabbaababaaabaaababbaa", "output": "24" }, { "input": "26\nahnxdnbfbcrirerssyzydihuee", "output": "11" }, { "input": "26\nhwqeqhkpxwulbsiwmnlfyhgknc", "output": "8" }, { "input": "26\nrvxmulriorilidecqwmfaemifj", "output": "10" }, { "input": "26\naowpmreooavnmamogdoopuisge", "output": "12" }, { "input": "26\ninimevtuefhvuefirdehmmfudh", "output": "15" }, { "input": "26\naaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "25" }, { "input": "27\nqdcfjtblgglnilgassirrjekcjt", "output": "-1" }, { "input": "27\nabcdefghijklmnopqrstuvwxyza", "output": "-1" }, { "input": "26\nqwertyuiopasdfghjklzxcvbnm", "output": "0" }, { "input": "5\nzzzzz", "output": "4" }, { "input": "27\naaaaaaaaaaaaaaaaabaaaaaaaaa", "output": "-1" }, { "input": "1\nq", "output": "0" }, { "input": "27\nqwertyuioplkjhgfdsazxcvbnmm", "output": "-1" }, { "input": "9\nxxxyyyzzz", "output": "6" }, { "input": "45\naaabbbcccdddeeefffgghhiijjkkkkkkkkkkkkkkkkkkk", "output": "-1" }, { "input": "27\nqwertyuiopasdfghjklzxcvbnmm", "output": "-1" }, { "input": "26\nabcdefghijklmnopqrstuvwxyz", "output": "0" }, { "input": "26\nabcdefghijklmnopqrstuvwxya", "output": "1" }, { "input": "27\nabcdefghijklmnopqrstuvwxyzz", "output": "-1" }, { "input": "26\naaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "25" }, { "input": "26\nqwertyuioplkjhgfdsazxcvbnm", "output": "0" }, { "input": "10\nzzzzzzzzzz", "output": "9" }, { "input": "1\na", "output": "0" }, { "input": "30\nabcdefghtyabcdefghtyabcdefghty", "output": "-1" } ]
1,633,083,407
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
7
78
6,963,200
n=int(input()) s=str(input()) d=dict() for i in s: if d.get(i)!=None: d[i]=d[i]+1 if d.get(i)==None: d[i]=1 count=0 for i in d.keys(): count=count+(d[i]-1) print(count)
Title: Different is Good Time Limit: None seconds Memory Limit: None megabytes Problem Description: A wise man told Kerem "Different is good" once, so Kerem wants all things in his life to be different. Kerem recently got a string *s* consisting of lowercase English letters. Since Kerem likes it when things are different, he wants all substrings of his string *s* to be distinct. Substring is a string formed by some number of consecutive characters of the string. For example, string "aba" has substrings "" (empty substring), "a", "b", "a", "ab", "ba", "aba". If string *s* has at least two equal substrings then Kerem will change characters at some positions to some other lowercase English letters. Changing characters is a very tiring job, so Kerem want to perform as few changes as possible. Your task is to find the minimum number of changes needed to make all the substrings of the given string distinct, or determine that it is impossible. Input Specification: The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100<=000) — the length of the string *s*. The second line contains the string *s* of length *n* consisting of only lowercase English letters. Output Specification: If it's impossible to change the string *s* such that all its substring are distinct print -1. Otherwise print the minimum required number of changes. Demo Input: ['2\naa\n', '4\nkoko\n', '5\nmurat\n'] Demo Output: ['1\n', '2\n', '0\n'] Note: In the first sample one of the possible solutions is to change the first character to 'b'. In the second sample, one may change the first character to 'a' and second character to 'b', so the string becomes "abko".
```python n=int(input()) s=str(input()) d=dict() for i in s: if d.get(i)!=None: d[i]=d[i]+1 if d.get(i)==None: d[i]=1 count=0 for i in d.keys(): count=count+(d[i]-1) print(count) ```
0
43
B
Letter
PROGRAMMING
1,100
[ "implementation", "strings" ]
B. Letter
2
256
Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading *s*1 and text *s*2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading — he just leaves some blank space to mark them. Help him; find out if he will manage to compose the needed text.
The first line contains a newspaper heading *s*1. The second line contains the letter text *s*2. *s*1 и *s*2 are non-empty lines consisting of spaces, uppercase and lowercase Latin letters, whose lengths do not exceed 200 symbols. The uppercase and lowercase letters should be differentiated. Vasya does not cut spaces out of the heading.
If Vasya can write the given anonymous letter, print YES, otherwise print NO
[ "Instead of dogging Your footsteps it disappears but you dont notice anything\nwhere is your dog\n", "Instead of dogging Your footsteps it disappears but you dont notice anything\nYour dog is upstears\n", "Instead of dogging your footsteps it disappears but you dont notice anything\nYour dog is upstears\n", "abcdefg hijk\nk j i h g f e d c b a\n" ]
[ "NO\n", "YES\n", "NO\n", "YES\n" ]
none
1,000
[ { "input": "Instead of dogging Your footsteps it disappears but you dont notice anything\nwhere is your dog", "output": "NO" }, { "input": "Instead of dogging Your footsteps it disappears but you dont notice anything\nYour dog is upstears", "output": "YES" }, { "input": "Instead of dogging your footsteps it disappears but you dont notice anything\nYour dog is upstears", "output": "NO" }, { "input": "abcdefg hijk\nk j i h g f e d c b a", "output": "YES" }, { "input": "HpOKgo\neAtAVB", "output": "NO" }, { "input": "GRZGc\nLPzD", "output": "NO" }, { "input": "GtPXu\nd", "output": "NO" }, { "input": "FVF\nr ", "output": "NO" }, { "input": "HpOKgo\nogK", "output": "YES" }, { "input": "GRZGc\nZG", "output": "YES" }, { "input": "HpOKgoueAtAVBdGffvQheJDejNDHhhwyKJisugiRAH OseK yUwqPPNuThUxTfthqIUeb wS jChGOdFDarNrKRT MlwKecxWNoKEeD BbiHAruE XMlvKYVsJGPP\nAHN XvoaNwV AVBKwKjr u U K wKE D K Jy KiHsR h d W Js IHyMPK Br iSqe E fDA g H", "output": "YES" }, { "input": "GRZGcsLPzDrCSXhhNTaibJqVphhjbcPoZhCDUlzAbDnRWjHvxLKtpGiFWiGbfeDxBwCrdJmJGCGv GebAOinUsFrlqKTILOmxrFjSpEoVGoTdSSstJWVgMLKMPettxHASaQZNdOIObcTxtF qTHWBdNIKwj\nWqrxze Ji x q aT GllLrRV jMpGiMDTwwS JDsPGpAZKACmsFCOS CD Sj bCDgKF jJxa RddtLFAi VGLHH SecObzG q hPF ", "output": "YES" }, { "input": "GtPXuwdAxNhODQbjRslDDKciOALJrCifTjDQurQEBeFUUSZWwCZQPdYwZkYbrduMijFjgodAOrKIuUKwSXageZuOWMIhAMexyLRzFuzuXqBDTEaWMzVdbzhxDGSJC SsIYuYILwpiwwcObEHWpFvHeBkWYNitqYrxqgHReHcKnHbtjcWZuaxPBVPb\nTQIKyqFaewOkY lZUOOuxEw EwuKcArxRQGFYkvVWIAe SuanPeHuDjquurJu aSxwgOSw jYMwjxItNUUArQjO BIujAhSwttLWp", "output": "YES" }, { "input": "FVFSr unvtXbpKWF vPaAgNaoTqklzVqiGYcUcBIcattzBrRuNSnKUtmdGKbjcE\nUzrU K an GFGR Wc zt iBa P c T K v p V In b B c", "output": "YES" }, { "input": "lSwjnYLYtDNIZjxHiTawdh ntSzggZogcIZTuiTMWVgwyloMtEhqkrOxgIcFvwvsboXUPILPIymFAEXnhApewJXJNtFyZ\nAoxe jWZ u yImg o AZ FNI w lpj tNhT g y ZYcb rc J w Dlv", "output": "YES" }, { "input": "kvlekcdJqODUKdsJlXkRaileTmdGwUHWWgvgUokQxRzzbpFnswvNKiDnjfOFGvFcnaaiRnBGQmqoPxDHepgYasLhzjDgmvaFfVNEcSPVQCJKAbSyTGpXsAjIHr\nGjzUllNaGGKXUdYmDFpqFAKIwvTpjmqnyswWRTnxlBnavAGvavxJemrjvRJc", "output": "YES" }, { "input": "kWbvhgvvoYOhwXmgTwOSCDXrtFHhqwvMlCvsuuAUXMmWaYXiqHplFZZemhgkTuvsUtIaUxtyYauBIpjdbyYxjZ ZkaBPzwqPfqF kCqGRmXvWuabnQognnkvdNDtRUsSUvSzgBuxCMBWJifbxWegsknp\nBsH bWHJD n Ca T xq PRCv tatn Wjy sm I q s WCjFqdWe t W XUs Do eb Pfh ii hTbF O Fll", "output": "YES" }, { "input": "OTmLdkMhmDEOMQMiW ZpzEIjyElHFrNCfFQDp SZyoZaEIUIpyCHfwOUqiSkKtFHggrTBGkqfOxkChPztmPrsHoxVwAdrxbZLKxPXHlMnrkgMgiaHFopiFFiUEtKwCjpJtwdwkbJCgA bxeDIscFdmHQJLAMNhWlrZisQrHQpvbALWTwpf jnx\nDbZwrQbydCdkJMCrftiwtPFfpMiwwrfIrKidEChKECxQUBVUEfFirbGWiLkFQkdJiFtkrtkbIAEXCEDkwLpK", "output": "YES" }, { "input": "NwcGaIeSkOva\naIa", "output": "YES" }, { "input": "gSrAcVYgAdbdayzbKGhIzLDjyznLRIJH KyvilAaEddmgkBPCNzpmPNeGEbmmpAyHvUSoPvnaORrPUuafpReEGoDOQsAYnUHYfBqhdcopQfxJuGXgKnbdVMQNhJYkyjiJDKlShqBTtnnDQQzEijOMcYRGMgPGVhfIReYennKBLwDTVvcHMIHMgVpJkvzTrezxqS\nHJerIVvRyfrPgAQMTI AqGNO mQDfDwQHKgeeYmuRmozKHILvehMPOJNMRtPTAfvKvsoGKi xHEeKqDAYmQJPUXRJbIbHrgVOMGMTdvYiLui", "output": "YES" }, { "input": "ReB hksbHqQXxUgpvoNK bFqmNVCEiOyKdKcAJQRkpeohpfuqZabvrLfmpZOMcfyFBJGZwVMxiUPP pbZZtJjxhEwvrAba\nJTCpQnIViIGIdQtLnmkVzmcbBZR CoxAdTtWSYpbOglDFifqIVQ vfGKGtLpxpJHiHSWCMeRcrVOXBGBhoEnVhNTPWGTOErNtSvokcGdgZXbgTEtISUyTwaXUEIlJMmutsdCbiyrPZPJyRdOjnSuAGttLy", "output": "NO" }, { "input": "hrLzRegCuDGxTrhDgVvM KowwyYuXGzIpcXdSMgeQVfVOtJZdkhNYSegwFWWoPqcZoeapbQnyCtojgkcyezUNHGGIZrhzsKrvvcrtokIdcnqXXkCNKjrOjrnEAKBNxyDdiMVeyLvXxUYMZQRFdlcdlcxzKTeYzBlmpNiwWbNAAhWkMoGpRxkCuyqkzXdKWwGH\nJESKDOfnFdxPvUOCkrgSBEPQHJtJHzuNGstRbTCcchRWJvCcveSEAtwtOmZZiW", "output": "NO" }, { "input": "yDBxCtUygQwWqONxQCcuAvVCkMGlqgC zvkfEkwqbhMCQxnkwQIUhucCbVUyOBUcXvTNEGriTBwMDMfdsPZgWRgIUDqM\neptVnORTTyixxmWIBpSTEwOXqGZllBgSxPenYCDlFwckJlWsoVwWLAIbPOmFqcKcTcoQqahetl KLfVSyaLVebzsGwPSVbtQAeUdZAaJtfxlCEvvaRhLlVvRJhKat IaB awdqcDlrrhTbRxjEbzGwcdmdavkhcjHjzmwbxAgw", "output": "NO" }, { "input": "jlMwnnotSdlQMluKWkJwAeCetcqbIEnKeNyLWoKCGONDRBQOjbkGpUvDlmSFUJ bWhohqmmIUWTlDsvelUArAcZJBipMDwUvRfBsYzMdQnPDPAuBaeJmAxVKwUMJrwMDxNtlrtAowVWqWiwFGtmquZAcrpFsLHCrvMSMMlvQUqypAihQWrFMNoaqfs IBg\nNzeWQ bafrmDsYlpNHSGTBBgPl WIcuNhyNaNOEFvL", "output": "NO" }, { "input": "zyWvXBcUZqGqjHwZHQryBtFliLYnweXAoMKNpLaunaOlzaauWmLtywsEvWPiwxJapocAFRMjrqWJXYqfKEbBKnzLO\npsbi bsXpSeJaCkIuPWfSRADXdIClxcDCowwJzGCDTyAl", "output": "NO" }, { "input": "kKhuIwRPLCwPFfcnsyCfBdnsraGeOCcLTfXuGjqFSGPSAeDZJSS bXKFanNqWjpFnvRpWxHJspvisDlADJBioxXNbVoXeUedoPcNEpUyEeYxdJXhGzFAmpAiHotSVwbZQsuWjIVhVaEGgqbZHIoDpiEmjTtFylCwCkWWzUOoUfOHxEZvDwNpXhBWamHn\nK VpJjGhNbwCRhcfmNGVjewBFpEmPlIKeTuWiukDtEWpjgqciqglkyNfWrBLbGAKvlNWxaUelJmSlSoakSpRzePvJsshOsTYrMPXdxKpaShjyVIXGhRIAdtiGpNwtiRmGTBZhkJqIMdxMHX RMxCMYcWjcjhtCHyFnCvjjezGbkRDRiVxkbh", "output": "NO" }, { "input": "AXssNpFKyQmJcBdBdfkhhMUzfqJVgcLBddkwtnFSzSRUCjiDcdtmkzIGkCKSxWUEGhmHmciktJyGMkgCductyHx\nI nYhmJfPnvoKUiXYUBIPIcxNYTtvwPUoXERZvY ahlDpQFNMmVZqEBiYqYlHNqcpSCmhFczBlOAhsYFeqMGfqL EJsDNOgwoJfBzqijKOFcYQ", "output": "NO" }, { "input": "lkhrzDZmkdbjzYKPNMRkiwCFoZsMzBQMnxxdKKVJezSBjnLjPpUYtabcPTIaDJeDEobbWHdKOdVfMQwDXzDDcSrwVenDEYpMqfiOQ xSsqApWnAMoyhQXCKFzHvvzvUvkWwmwZrvZz\nsUzGspYpRFsHRbRgTQuCBgnFgPkisTUfFNwyEEWWRiweWWgjRkVQxgTwxOzdsOwfrGIH O gCXpzvHzfItuEHaihmugEyymSJIogYwX qAwcwIItidfnzZDhZgQHi eRjMAeVkJHceDZuJkmxGowOsmcGYYvk Ajtgi TxwihvjLViNZjvscTWvsaQUelTSivLShhEl", "output": "NO" }, { "input": "BRsVjyNhrqRHVwrJzuzRigEhdpbDmaACSPfed\nlWqKTjlrqOCUbgBBZdZDGCeQJDXawPnnDkQdZDgwrEQk", "output": "NO" }, { "input": "KRmINuyBYPwiTsdlyiNVuylToysJKmOpcLovAtwGPqrgFJQNAYvuAiyQRkeFMECVZvkDEmTauXlyjAaYRnTJXORMZRnTakBaUzSelMilejySDIZjQjzcOIrwXdvDvpeRIkoBgreyFXIyyIZutjiEBtwrmzQtPVUhvvdEtDMbXjBpoPVjGdM EXTAK JbCnw\nXZZqlJvzKKtvdNlzFPDTYxidqlsgufVzyEmO FZuLQ vVQsJESNviUCovCK NwwlbxsmPtOJNmAonCqrOZ bZ LVKAsQGmoLnYjeekvEIECFk", "output": "NO" } ]
1,665,779,118
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
3
92
0
a = input() b = input() c = 0 for i in b: if i in a and a.count(i)>=b.count(i): c += 0 else: c = 1 print('NO') break if c ==0: print('YES')
Title: Letter Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading *s*1 and text *s*2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading — he just leaves some blank space to mark them. Help him; find out if he will manage to compose the needed text. Input Specification: The first line contains a newspaper heading *s*1. The second line contains the letter text *s*2. *s*1 и *s*2 are non-empty lines consisting of spaces, uppercase and lowercase Latin letters, whose lengths do not exceed 200 symbols. The uppercase and lowercase letters should be differentiated. Vasya does not cut spaces out of the heading. Output Specification: If Vasya can write the given anonymous letter, print YES, otherwise print NO Demo Input: ['Instead of dogging Your footsteps it disappears but you dont notice anything\nwhere is your dog\n', 'Instead of dogging Your footsteps it disappears but you dont notice anything\nYour dog is upstears\n', 'Instead of dogging your footsteps it disappears but you dont notice anything\nYour dog is upstears\n', 'abcdefg hijk\nk j i h g f e d c b a\n'] Demo Output: ['NO\n', 'YES\n', 'NO\n', 'YES\n'] Note: none
```python a = input() b = input() c = 0 for i in b: if i in a and a.count(i)>=b.count(i): c += 0 else: c = 1 print('NO') break if c ==0: print('YES') ```
0
127
A
Wasted Time
PROGRAMMING
900
[ "geometry" ]
null
null
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers. Mr. Scrooge's signature can be represented as a polyline *A*1*A*2... *A**n*. Scrooge signs like that: first it places a pen at the point *A*1, then draws a segment from point *A*1 to point *A*2, then he draws a segment from point *A*2 to point *A*3 and so on to point *A**n*, where he stops signing and takes the pen off the paper. At that the resulting line can intersect with itself and partially repeat itself but Scrooge pays no attention to it and never changes his signing style. As Scrooge makes the signature, he never takes the pen off the paper and his writing speed is constant — 50 millimeters per second. Scrooge signed exactly *k* papers throughout his life and all those signatures look the same. Find the total time Scrooge wasted signing the papers.
The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=1000). Each of the following *n* lines contains the coordinates of the polyline's endpoints. The *i*-th one contains coordinates of the point *A**i* — integers *x**i* and *y**i*, separated by a space. All points *A**i* are different. The absolute value of all coordinates does not exceed 20. The coordinates are measured in millimeters.
Print one real number — the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10<=-<=6.
[ "2 1\n0 0\n10 0\n", "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0\n", "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0\n" ]
[ "0.200000000", "6.032163204", "3.000000000" ]
none
500
[ { "input": "2 1\n0 0\n10 0", "output": "0.200000000" }, { "input": "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0", "output": "6.032163204" }, { "input": "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0", "output": "3.000000000" }, { "input": "10 95\n-20 -5\n2 -8\n14 13\n10 3\n17 11\n13 -12\n-6 11\n14 -15\n-13 14\n19 8", "output": "429.309294877" }, { "input": "30 1000\n4 -13\n14 13\n-14 -16\n-9 18\n17 11\n2 -8\n2 15\n8 -1\n-9 13\n8 -12\n-2 20\n11 -12\n19 8\n9 -15\n-20 -5\n-18 20\n-13 14\n-12 -17\n-4 3\n13 -12\n11 -10\n18 7\n-6 11\n10 13\n10 3\n6 -14\n-1 10\n14 -15\n2 11\n-8 10", "output": "13629.282573522" }, { "input": "2 1\n-20 -10\n-10 -6", "output": "0.215406592" }, { "input": "2 13\n13 -10\n-3 -2", "output": "4.651021393" }, { "input": "2 21\n13 8\n14 10", "output": "0.939148551" }, { "input": "2 75\n-3 12\n1 12", "output": "6.000000000" }, { "input": "2 466\n10 16\n-6 -3", "output": "231.503997374" }, { "input": "2 999\n6 16\n-17 -14", "output": "755.286284531" }, { "input": "2 1000\n-17 -14\n-14 -8", "output": "134.164078650" }, { "input": "3 384\n-4 -19\n-17 -2\n3 4", "output": "324.722285390" }, { "input": "5 566\n-11 8\n2 -7\n7 0\n-7 -9\n-7 5", "output": "668.956254495" }, { "input": "7 495\n-10 -13\n-9 -5\n4 9\n8 13\n-4 2\n2 10\n-18 15", "output": "789.212495576" }, { "input": "10 958\n7 13\n20 19\n12 -7\n10 -10\n-13 -15\n-10 -7\n20 -5\n-11 19\n-7 3\n-4 18", "output": "3415.618464093" }, { "input": "13 445\n-15 16\n-8 -14\n8 7\n4 15\n8 -13\n15 -11\n-12 -4\n2 -13\n-5 0\n-20 -14\n-8 -7\n-10 -18\n18 -5", "output": "2113.552527680" }, { "input": "18 388\n11 -8\n13 10\n18 -17\n-15 3\n-13 -15\n20 -7\n1 -10\n-13 -12\n-12 -15\n-17 -8\n1 -2\n3 -20\n-8 -9\n15 -13\n-19 -6\n17 3\n-17 2\n6 6", "output": "2999.497312668" }, { "input": "25 258\n-5 -3\n-18 -14\n12 3\n6 11\n4 2\n-19 -3\n19 -7\n-15 19\n-19 -12\n-11 -10\n-5 17\n10 15\n-4 1\n-3 -20\n6 16\n18 -19\n11 -19\n-17 10\n-17 17\n-2 -17\n-3 -9\n18 13\n14 8\n-2 -5\n-11 4", "output": "2797.756635934" }, { "input": "29 848\n11 -10\n-19 1\n18 18\n19 -19\n0 -5\n16 10\n-20 -14\n7 15\n6 8\n-15 -16\n9 3\n16 -20\n-12 12\n18 -1\n-11 14\n18 10\n11 -20\n-20 -16\n-1 11\n13 10\n-6 13\n-7 -10\n-11 -10\n-10 3\n15 -13\n-4 11\n-13 -11\n-11 -17\n11 -5", "output": "12766.080247922" }, { "input": "36 3\n-11 20\n-11 13\n-17 9\n15 9\n-6 9\n-1 11\n12 -11\n16 -10\n-20 7\n-18 6\n-15 -2\n20 -20\n16 4\n-20 -8\n-12 -15\n-13 -6\n-9 -4\n0 -10\n8 -1\n1 4\n5 8\n8 -15\n16 -12\n19 1\n0 -4\n13 -4\n17 -13\n-7 11\n14 9\n-14 -9\n5 -8\n11 -8\n-17 -5\n1 -3\n-16 -17\n2 -3", "output": "36.467924851" }, { "input": "48 447\n14 9\n9 -17\n-17 11\n-14 14\n19 -8\n-14 -17\n-7 10\n-6 -11\n-9 -19\n19 10\n-4 2\n-5 16\n20 9\n-10 20\n-7 -17\n14 -16\n-2 -10\n-18 -17\n14 12\n-6 -19\n5 -18\n-3 2\n-3 10\n-5 5\n13 -12\n10 -18\n10 -12\n-2 4\n7 -15\n-5 -5\n11 14\n11 10\n-6 -9\n13 -4\n13 9\n6 12\n-13 17\n-9 -12\n14 -19\n10 12\n-15 8\n-1 -11\n19 8\n11 20\n-9 -3\n16 1\n-14 19\n8 -4", "output": "9495.010556306" }, { "input": "50 284\n-17 -13\n7 12\n-13 0\n13 1\n14 6\n14 -9\n-5 -1\n0 -10\n12 -3\n-14 6\n-8 10\n-16 17\n0 -1\n4 -9\n2 6\n1 8\n-8 -14\n3 9\n1 -15\n-4 -19\n-7 -20\n18 10\n3 -11\n10 16\n2 -6\n-9 19\n-3 -1\n20 9\n-12 -5\n-10 -2\n16 -7\n-16 -18\n-2 17\n2 8\n7 -15\n4 1\n6 -17\n19 9\n-10 -20\n5 2\n10 -2\n3 7\n20 0\n8 -14\n-16 -1\n-20 7\n20 -19\n17 18\n-11 -18\n-16 14", "output": "6087.366930474" }, { "input": "57 373\n18 3\n-4 -1\n18 5\n-7 -15\n-6 -10\n-19 1\n20 15\n15 4\n-1 -2\n13 -14\n0 12\n10 3\n-16 -17\n-14 -9\n-11 -10\n17 19\n-2 6\n-12 -15\n10 20\n16 7\n9 -1\n4 13\n8 -2\n-1 -16\n-3 8\n14 11\n-12 3\n-5 -6\n3 4\n5 7\n-9 9\n11 4\n-19 10\n-7 4\n-20 -12\n10 16\n13 11\n13 -11\n7 -1\n17 18\n-19 7\n14 13\n5 -1\n-7 6\n-1 -6\n6 20\n-16 2\n4 17\n16 -11\n-4 -20\n19 -18\n17 16\n-14 -8\n3 2\n-6 -16\n10 -10\n-13 -11", "output": "8929.162822862" }, { "input": "60 662\n15 17\n-2 -19\n-4 -17\n10 0\n15 10\n-8 -14\n14 9\n-15 20\n6 5\n-9 0\n-13 20\n13 -2\n10 9\n7 5\n4 18\n-10 1\n6 -15\n15 -16\n6 13\n4 -6\n2 5\n18 19\n8 3\n-7 14\n-12 -20\n14 19\n-15 0\n-2 -12\n9 18\n14 4\n2 -20\n3 0\n20 9\n-5 11\n-11 1\n2 -19\n-14 -4\n18 6\n16 16\n15 3\n-1 -5\n9 20\n12 -8\n-1 10\n-4 -9\n3 6\n3 -12\n14 -10\n-8 10\n-18 6\n14 -2\n-14 -12\n-10 -7\n10 -6\n14 1\n6 14\n15 19\n4 14\n3 -14\n-9 -13", "output": "16314.207721932" }, { "input": "61 764\n-9 15\n11 -8\n-6 -7\n-13 -19\n16 -16\n-5 -1\n20 -19\n-14 -1\n-11 4\n7 -2\n-3 2\n-14 -17\n15 18\n20 15\n-13 -2\n15 8\n3 13\n19 -10\n2 -6\n15 -3\n-12 11\n4 -16\n-14 20\n0 2\n11 -7\n-6 -11\n16 7\n8 -3\n16 -10\n-3 9\n9 5\n4 -1\n-17 9\n14 -4\n8 6\n-19 12\n10 -17\n-5 7\n7 -3\n5 3\n6 -14\n9 9\n-16 -19\n11 -16\n-17 15\n8 5\n16 -19\n-7 10\n14 -15\n15 19\n-20 -16\n6 -2\n-4 6\n7 -15\n1 -8\n20 -17\n3 7\n10 12\n10 -11\n-19 10\n0 -11", "output": "22153.369189802" } ]
1,590,054,821
2,147,483,647
Python 3
OK
TESTS
42
248
307,200
n, k = map(int, input().split()) x1, y1 = map(float, input().split()) sum = 0 for i in range(n-1): x2, y2 = map(float, input().split()) d = pow(pow(x2 - x1,2) + pow(y2 - y1,2), (1/2)) x1 = x2 y1 = y2 sum += d ans = (sum * k)/50 print(ans)
Title: Wasted Time Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers. Mr. Scrooge's signature can be represented as a polyline *A*1*A*2... *A**n*. Scrooge signs like that: first it places a pen at the point *A*1, then draws a segment from point *A*1 to point *A*2, then he draws a segment from point *A*2 to point *A*3 and so on to point *A**n*, where he stops signing and takes the pen off the paper. At that the resulting line can intersect with itself and partially repeat itself but Scrooge pays no attention to it and never changes his signing style. As Scrooge makes the signature, he never takes the pen off the paper and his writing speed is constant — 50 millimeters per second. Scrooge signed exactly *k* papers throughout his life and all those signatures look the same. Find the total time Scrooge wasted signing the papers. Input Specification: The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=1000). Each of the following *n* lines contains the coordinates of the polyline's endpoints. The *i*-th one contains coordinates of the point *A**i* — integers *x**i* and *y**i*, separated by a space. All points *A**i* are different. The absolute value of all coordinates does not exceed 20. The coordinates are measured in millimeters. Output Specification: Print one real number — the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10<=-<=6. Demo Input: ['2 1\n0 0\n10 0\n', '5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0\n', '6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0\n'] Demo Output: ['0.200000000', '6.032163204', '3.000000000'] Note: none
```python n, k = map(int, input().split()) x1, y1 = map(float, input().split()) sum = 0 for i in range(n-1): x2, y2 = map(float, input().split()) d = pow(pow(x2 - x1,2) + pow(y2 - y1,2), (1/2)) x1 = x2 y1 = y2 sum += d ans = (sum * k)/50 print(ans) ```
3
0
none
none
none
0
[ "none" ]
null
null
Sasha is taking part in a programming competition. In one of the problems she should check if some rooted trees are isomorphic or not. She has never seen this problem before, but, being an experienced participant, she guessed that she should match trees to some sequences and then compare these sequences instead of trees. Sasha wants to match each tree with a sequence *a*0,<=*a*1,<=...,<=*a**h*, where *h* is the height of the tree, and *a**i* equals to the number of vertices that are at distance of *i* edges from root. Unfortunately, this time Sasha's intuition was wrong, and there could be several trees matching the same sequence. To show it, you need to write a program that, given the sequence *a**i*, builds two non-isomorphic rooted trees that match that sequence, or determines that there is only one such tree. Two rooted trees are isomorphic, if you can reenumerate the vertices of the first one in such a way, that the index of the root becomes equal the index of the root of the second tree, and these two trees become equal. The height of a rooted tree is the maximum number of edges on a path from the root to any other vertex.
The first line contains a single integer *h* (2<=≤<=*h*<=≤<=105) — the height of the tree. The second line contains *h*<=+<=1 integers — the sequence *a*0,<=*a*1,<=...,<=*a**h* (1<=≤<=*a**i*<=≤<=2·105). The sum of all *a**i* does not exceed 2·105. It is guaranteed that there is at least one tree matching this sequence.
If there is only one tree matching this sequence, print "perfect". Otherwise print "ambiguous" in the first line. In the second and in the third line print descriptions of two trees in the following format: in one line print integers, the *k*-th of them should be the parent of vertex *k* or be equal to zero, if the *k*-th vertex is the root. These treese should be non-isomorphic and should match the given sequence.
[ "2\n1 1 1\n", "2\n1 2 2\n" ]
[ "perfect\n", "ambiguous\n0 1 1 3 3\n0 1 1 3 2\n" ]
The only tree in the first example and the two printed trees from the second example are shown on the picture: <img class="tex-graphics" src="https://espresso.codeforces.com/ae5d1889e09854f9d8ad6e29ab7afbe690ca4702.png" style="max-width: 100.0%;max-height: 100.0%;"/>
0
[ { "input": "2\n1 1 1", "output": "perfect" }, { "input": "2\n1 2 2", "output": "ambiguous\n0 1 1 3 3\n0 1 1 3 2" }, { "input": "10\n1 1 1 1 1 1 1 1 1 1 1", "output": "perfect" }, { "input": "10\n1 1 1 1 1 2 1 1 1 1 1", "output": "perfect" }, { "input": "10\n1 1 1 1 2 2 1 1 1 1 1", "output": "ambiguous\n0 1 2 3 4 4 6 6 8 9 10 11 12\n0 1 2 3 4 4 6 5 8 9 10 11 12" }, { "input": "10\n1 1 1 1 1 1 1 2 1 1 2", "output": "perfect" }, { "input": "10\n1 1 1 3 2 1 2 4 1 3 1", "output": "ambiguous\n0 1 2 3 3 3 6 6 8 9 9 11 11 11 11 15 16 16 16 19\n0 1 2 3 3 3 6 5 8 9 9 11 10 10 10 15 16 16 16 19" }, { "input": "10\n1 1 1 4 1 1 2 1 5 1 2", "output": "perfect" }, { "input": "10\n1 1 11 12 12 11 15 13 8 8 8", "output": "ambiguous\n0 1 2 2 2 2 2 2 2 2 2 2 2 13 13 13 13 13 13 13 13 13 13 13 13 25 25 25 25 25 25 25 25 25 25 25 25 37 37 37 37 37 37 37 37 37 37 37 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 63 63 63 63 63 63 63 63 63 63 63 63 63 76 76 76 76 76 76 76 76 84 84 84 84 84 84 84 84 92 92 92 92 92 92 92 92\n0 1 2 2 2 2 2 2 2 2 2 2 2 13 12 12 12 12 12 12 12 12 12 12 12 25 24 24 24 24 24 24 24 24 24 24 24 37 36 36 36 36 36 36 36 36 36 36 48 47 47 47 47 47 47 47 47 47 47 47 47 47 47 63 62 62 62 62 62 62 62 62 62 62 62 ..." }, { "input": "10\n1 1 21 1 20 1 14 1 19 1 20", "output": "perfect" }, { "input": "10\n1 1 93 121 112 103 114 112 112 122 109", "output": "ambiguous\n0 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 9..." }, { "input": "10\n1 1 262 1 232 1 245 1 1 254 1", "output": "perfect" }, { "input": "2\n1 1 199998", "output": "perfect" }, { "input": "3\n1 1 199997 1", "output": "perfect" }, { "input": "3\n1 1 100009 99989", "output": "ambiguous\n0 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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 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 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ..." }, { "input": "123\n1 1 1 3714 1 3739 1 3720 1 1 3741 1 1 3726 1 3836 1 3777 1 1 3727 1 1 3866 1 3799 1 3785 1 3693 1 1 3667 1 3930 1 3849 1 1 3767 1 3792 1 3792 1 3808 1 3680 1 3798 1 3817 1 3636 1 3833 1 1 3765 1 3774 1 3747 1 1 3897 1 3773 1 3814 1 3739 1 1 3852 1 3759 1 3783 1 1 3836 1 3787 1 3752 1 1 3818 1 3794 1 3745 1 3785 1 3784 1 1 3765 1 3750 1 3690 1 1 3806 1 3781 1 3680 1 1 3748 1 3709 1 3793 1 3618 1 1 3893 1", "output": "perfect" }, { "input": "13\n1 1 16677 16757 16710 16596 16512 16762 16859 16750 16658 16489 16594 16634", "output": "ambiguous\n0 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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 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 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ..." }, { "input": "13\n1 1 40049 1 1 39777 1 1 40008 1 40060 1 40097 1", "output": "perfect" }, { "input": "4\n1 2 1 2 2", "output": "ambiguous\n0 1 1 3 4 4 6 6\n0 1 1 3 4 4 6 5" }, { "input": "16\n1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536", "output": "ambiguous\n0 1 1 3 3 3 3 7 7 7 7 7 7 7 7 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 12..." }, { "input": "4\n1 2 1 2 3", "output": "ambiguous\n0 1 1 3 4 4 6 6 6\n0 1 1 3 4 4 6 5 5" }, { "input": "2\n1 3 199969", "output": "ambiguous\n0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 ..." }, { "input": "2\n1 99999 99999", "output": "ambiguous\n0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "2\n1 3 2", "output": "ambiguous\n0 1 1 1 4 4\n0 1 1 1 4 3" } ]
1,593,957,455
5,255
PyPy 3
WRONG_ANSWER
TESTS
1
140
20,172,800
n=int(input()) l=list(map(int,input().split())) f=0 for i in range(n): #print(l[i],l[i+1]) if l[i]>1 and l[i+1]>1: f+=1 break if f==0: print("perfect") else: g='' cnt=0 for i in l: for j in range(i): g+=str(cnt) cnt+=1 print("ambigous") h='' for i in range(len(g)-1): h+=g[i] h+=str(len(l)) l,l1=list(g),list(h) print(*l) print(*l1)
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sasha is taking part in a programming competition. In one of the problems she should check if some rooted trees are isomorphic or not. She has never seen this problem before, but, being an experienced participant, she guessed that she should match trees to some sequences and then compare these sequences instead of trees. Sasha wants to match each tree with a sequence *a*0,<=*a*1,<=...,<=*a**h*, where *h* is the height of the tree, and *a**i* equals to the number of vertices that are at distance of *i* edges from root. Unfortunately, this time Sasha's intuition was wrong, and there could be several trees matching the same sequence. To show it, you need to write a program that, given the sequence *a**i*, builds two non-isomorphic rooted trees that match that sequence, or determines that there is only one such tree. Two rooted trees are isomorphic, if you can reenumerate the vertices of the first one in such a way, that the index of the root becomes equal the index of the root of the second tree, and these two trees become equal. The height of a rooted tree is the maximum number of edges on a path from the root to any other vertex. Input Specification: The first line contains a single integer *h* (2<=≤<=*h*<=≤<=105) — the height of the tree. The second line contains *h*<=+<=1 integers — the sequence *a*0,<=*a*1,<=...,<=*a**h* (1<=≤<=*a**i*<=≤<=2·105). The sum of all *a**i* does not exceed 2·105. It is guaranteed that there is at least one tree matching this sequence. Output Specification: If there is only one tree matching this sequence, print "perfect". Otherwise print "ambiguous" in the first line. In the second and in the third line print descriptions of two trees in the following format: in one line print integers, the *k*-th of them should be the parent of vertex *k* or be equal to zero, if the *k*-th vertex is the root. These treese should be non-isomorphic and should match the given sequence. Demo Input: ['2\n1 1 1\n', '2\n1 2 2\n'] Demo Output: ['perfect\n', 'ambiguous\n0 1 1 3 3\n0 1 1 3 2\n'] Note: The only tree in the first example and the two printed trees from the second example are shown on the picture: <img class="tex-graphics" src="https://espresso.codeforces.com/ae5d1889e09854f9d8ad6e29ab7afbe690ca4702.png" style="max-width: 100.0%;max-height: 100.0%;"/>
```python n=int(input()) l=list(map(int,input().split())) f=0 for i in range(n): #print(l[i],l[i+1]) if l[i]>1 and l[i+1]>1: f+=1 break if f==0: print("perfect") else: g='' cnt=0 for i in l: for j in range(i): g+=str(cnt) cnt+=1 print("ambigous") h='' for i in range(len(g)-1): h+=g[i] h+=str(len(l)) l,l1=list(g),list(h) print(*l) print(*l1) ```
0
71
A
Way Too Long Words
PROGRAMMING
800
[ "strings" ]
A. Way Too Long Words
1
256
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes. Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n". You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data.
[ "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n" ]
[ "word\nl10n\ni18n\np43s\n" ]
none
500
[ { "input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis", "output": "word\nl10n\ni18n\np43s" }, { "input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm", "output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m" }, { "input": "3\nnjfngnrurunrgunrunvurn\njfvnjfdnvjdbfvsbdubruvbubvkdb\nksdnvidnviudbvibd", "output": "n20n\nj27b\nk15d" }, { "input": "1\ntcyctkktcctrcyvbyiuhihhhgyvyvyvyvjvytchjckt", "output": "t41t" }, { "input": "24\nyou\nare\nregistered\nfor\npractice\nyou\ncan\nsolve\nproblems\nunofficially\nresults\ncan\nbe\nfound\nin\nthe\ncontest\nstatus\nand\nin\nthe\nbottom\nof\nstandings", "output": "you\nare\nregistered\nfor\npractice\nyou\ncan\nsolve\nproblems\nu10y\nresults\ncan\nbe\nfound\nin\nthe\ncontest\nstatus\nand\nin\nthe\nbottom\nof\nstandings" }, { "input": "1\na", "output": "a" }, { "input": "26\na\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz", "output": "a\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz" }, { "input": "1\nabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij", "output": "a98j" }, { "input": "10\ngyartjdxxlcl\nfzsck\nuidwu\nxbymclornemdmtj\nilppyoapitawgje\ncibzc\ndrgbeu\nhezplmsdekhhbo\nfeuzlrimbqbytdu\nkgdco", "output": "g10l\nfzsck\nuidwu\nx13j\ni13e\ncibzc\ndrgbeu\nh12o\nf13u\nkgdco" }, { "input": "20\nlkpmx\nkovxmxorlgwaomlswjxlpnbvltfv\nhykasjxqyjrmybejnmeumzha\ntuevlumpqbbhbww\nqgqsphvrmupxxc\ntrissbaf\nqfgrlinkzvzqdryckaizutd\nzzqtoaxkvwoscyx\noswytrlnhpjvvnwookx\nlpuzqgec\ngyzqfwxggtvpjhzmzmdw\nrlxjgmvdftvrmvbdwudra\nvsntnjpepnvdaxiporggmglhagv\nxlvcqkqgcrbgtgglj\nlyxwxbiszyhlsrgzeedzprbmcpduvq\nyrmqqvrkqskqukzqrwukpsifgtdc\nxpuohcsjhhuhvr\nvvlfrlxpvqejngwrbfbpmqeirxlw\nsvmasocxdvadmaxtrpakysmeaympy\nyuflqboqfdt", "output": "lkpmx\nk26v\nh22a\nt13w\nq12c\ntrissbaf\nq21d\nz13x\no17x\nlpuzqgec\ng18w\nr19a\nv25v\nx15j\nl28q\ny26c\nx12r\nv26w\ns27y\ny9t" }, { "input": "100\nm\nz\ns\nv\nd\nr\nv\ny\ny\ne\np\nt\nc\na\nn\nm\np\ng\ni\nj\nc\na\nb\nq\ne\nn\nv\no\nk\nx\nf\ni\nl\na\nq\nr\nu\nb\ns\nl\nc\nl\ne\nv\nj\nm\nx\nb\na\nq\nb\na\nf\nj\nv\nm\nq\nc\nt\nt\nn\nx\no\ny\nr\nu\nh\nm\nj\np\nj\nq\nz\ns\nj\no\ng\nc\nm\nn\no\nm\nr\no\ns\nt\nh\nr\np\nk\nb\nz\ng\no\nc\nc\nz\nz\ng\nr", "output": "m\nz\ns\nv\nd\nr\nv\ny\ny\ne\np\nt\nc\na\nn\nm\np\ng\ni\nj\nc\na\nb\nq\ne\nn\nv\no\nk\nx\nf\ni\nl\na\nq\nr\nu\nb\ns\nl\nc\nl\ne\nv\nj\nm\nx\nb\na\nq\nb\na\nf\nj\nv\nm\nq\nc\nt\nt\nn\nx\no\ny\nr\nu\nh\nm\nj\np\nj\nq\nz\ns\nj\no\ng\nc\nm\nn\no\nm\nr\no\ns\nt\nh\nr\np\nk\nb\nz\ng\no\nc\nc\nz\nz\ng\nr" } ]
1,674,851,531
2,147,483,647
PyPy 3-64
OK
TESTS
20
62
0
n=int(input()) for i in range(n): a=input() if len(a)>10: b=a[0] d=a[len(a) - 1] c=int(len(a))-2 print(b,c,d, sep="") else: print(a)
Title: Way Too Long Words Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes. Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n". You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes. Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters. Output Specification: Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data. Demo Input: ['4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n'] Demo Output: ['word\nl10n\ni18n\np43s\n'] Note: none
```python n=int(input()) for i in range(n): a=input() if len(a)>10: b=a[0] d=a[len(a) - 1] c=int(len(a))-2 print(b,c,d, sep="") else: print(a) ```
3.969
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,652,715,315
2,147,483,647
Python 3
OK
TESTS
81
92
4,505,600
n = int(input()) sa = 0 sb = 0 sc = 0 for i in range(n): a, b, c = map(int, input().split()) sa = a + sa sb = b + sb sc = c + sc if sa == 0 and sb == 0 and sc == 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()) sa = 0 sb = 0 sc = 0 for i in range(n): a, b, c = map(int, input().split()) sa = a + sa sb = b + sb sc = c + sc if sa == 0 and sb == 0 and sc == 0: print('YES') else: print('NO') ```
3.968608
267
A
Subtractions
PROGRAMMING
900
[ "math", "number theory" ]
null
null
You've got two numbers. As long as they are both larger than zero, they go through the same operation: subtract the lesser number from the larger one. If they equal substract one number from the another. For example, one operation transforms pair (4,17) to pair (4,13), it transforms (5,5) to (0,5). You've got some number of pairs (*a**i*,<=*b**i*). How many operations will be performed for each of them?
The first line contains the number of pairs *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000). Then follow *n* lines, each line contains a pair of positive integers *a**i*,<=*b**i* (1<=<=≤<=<=*a**i*,<=<=*b**i*<=<=≤<=<=109).
Print the sought number of operations for each pair on a single line.
[ "2\n4 17\n7 987654321\n" ]
[ "8\n141093479\n" ]
none
500
[ { "input": "2\n4 17\n7 987654321", "output": "8\n141093479" }, { "input": "10\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321", "output": "141093479\n141093479\n141093479\n141093479\n141093479\n141093479\n141093479\n141093479\n141093479\n141093479" }, { "input": "1\n536870912 32", "output": "16777216" }, { "input": "20\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999", "output": "1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000" }, { "input": "3\n1000000000 1\n1000000000 1\n1 100000000", "output": "1000000000\n1000000000\n100000000" } ]
1,586,818,574
2,147,483,647
PyPy 3
RUNTIME_ERROR
TESTS
0
186
2,048,000
def solution(a, b): res = 0 if b > a: a, b = b, a while a > 0 and b > 0: tmp = a // b a -= tmp * b res += tmp if b > a: a, b = b, a return res if __name__ == '__main__': n = input() for _ in range(int(n)): a, b = input() print(solution(int(a), int(b)))
Title: Subtractions Time Limit: None seconds Memory Limit: None megabytes Problem Description: You've got two numbers. As long as they are both larger than zero, they go through the same operation: subtract the lesser number from the larger one. If they equal substract one number from the another. For example, one operation transforms pair (4,17) to pair (4,13), it transforms (5,5) to (0,5). You've got some number of pairs (*a**i*,<=*b**i*). How many operations will be performed for each of them? Input Specification: The first line contains the number of pairs *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000). Then follow *n* lines, each line contains a pair of positive integers *a**i*,<=*b**i* (1<=<=≤<=<=*a**i*,<=<=*b**i*<=<=≤<=<=109). Output Specification: Print the sought number of operations for each pair on a single line. Demo Input: ['2\n4 17\n7 987654321\n'] Demo Output: ['8\n141093479\n'] Note: none
```python def solution(a, b): res = 0 if b > a: a, b = b, a while a > 0 and b > 0: tmp = a // b a -= tmp * b res += tmp if b > a: a, b = b, a return res if __name__ == '__main__': n = input() for _ in range(int(n)): a, b = input() print(solution(int(a), int(b))) ```
-1
431
C
k-Tree
PROGRAMMING
1,600
[ "dp", "implementation", "trees" ]
null
null
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a *k*-tree. A *k*-tree is an infinite rooted tree where: - each vertex has exactly *k* children; - each edge has some weight; - if we look at the edges that goes from some vertex to its children (exactly *k* edges), then their weights will equal 1,<=2,<=3,<=...,<=*k*. The picture below shows a part of a 3-tree. Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (109<=+<=7).
A single line contains three space-separated integers: *n*, *k* and *d* (1<=≤<=*n*,<=*k*<=≤<=100; 1<=≤<=*d*<=≤<=*k*).
Print a single integer — the answer to the problem modulo 1000000007 (109<=+<=7).
[ "3 3 2\n", "3 3 3\n", "4 3 2\n", "4 5 2\n" ]
[ "3\n", "1\n", "6\n", "7\n" ]
none
1,500
[ { "input": "3 3 2", "output": "3" }, { "input": "3 3 3", "output": "1" }, { "input": "4 3 2", "output": "6" }, { "input": "4 5 2", "output": "7" }, { "input": "28 6 3", "output": "110682188" }, { "input": "5 100 1", "output": "16" }, { "input": "50 6 3", "output": "295630102" }, { "input": "10 13 6", "output": "48" }, { "input": "20 16 14", "output": "236" }, { "input": "1 10 1", "output": "1" }, { "input": "8 11 4", "output": "47" }, { "input": "16 5 4", "output": "16175" }, { "input": "5 26 17", "output": "0" }, { "input": "35 47 42", "output": "0" }, { "input": "11 6 2", "output": "975" }, { "input": "54 60 16", "output": "931055544" }, { "input": "47 5 1", "output": "164058640" }, { "input": "70 6 1", "output": "592826579" }, { "input": "40 77 77", "output": "0" }, { "input": "96 9 6", "output": "362487247" }, { "input": "52 46 4", "output": "27907693" }, { "input": "74 41 28", "output": "806604424" }, { "input": "100 100 100", "output": "1" }, { "input": "99 99 5", "output": "700732369" }, { "input": "100 100 1", "output": "988185646" }, { "input": "98 98 64", "output": "237643149" }, { "input": "28 74 2", "output": "134217727" }, { "input": "86 69 62", "output": "217513984" }, { "input": "9 17 14", "output": "0" }, { "input": "73 72 12", "output": "426374014" }, { "input": "41 98 76", "output": "0" }, { "input": "1 1 1", "output": "1" }, { "input": "1 100 100", "output": "0" }, { "input": "1 100 1", "output": "1" }, { "input": "1 100 2", "output": "0" }, { "input": "2 100 2", "output": "1" }, { "input": "2 100 1", "output": "2" }, { "input": "50 50 1", "output": "949480669" }, { "input": "100 50 50", "output": "661237556" }, { "input": "3 2 2", "output": "2" }, { "input": "100 50 3", "output": "494224664" }, { "input": "90 97 24", "output": "413496885" }, { "input": "31 8 8", "output": "52532592" }, { "input": "78 90 38", "output": "744021655" }, { "input": "100 13 11", "output": "883875774" }, { "input": "100 45 8", "output": "367847193" }, { "input": "31 8 4", "output": "924947104" }, { "input": "35 95 9", "output": "927164672" }, { "input": "45 5 3", "output": "252804490" }, { "input": "1 5 5", "output": "0" }, { "input": "89 75 59", "output": "179807625" }, { "input": "90 100 30", "output": "697322870" }, { "input": "89 73 32", "output": "152673180" }, { "input": "100 90 80", "output": "11531520" } ]
1,676,759,607
2,147,483,647
PyPy 3-64
OK
TESTS
54
62
1,843,200
dp = [] mod = 1000000007 def main(): n, k, d = input().split() n = int(n) k = int(k) d = int(d) dp.append(1) for i in range(1, n+1): dp.append(0) sup = 1 while i - sup >= 0 and sup <= k: dp[i] += dp[i - sup] sup = sup+1 whole = dp[n] dp[0] = 1 for i in range(1, n+1): dp[i] = 0 sup = 1 while i - sup >= 0 and sup <= (d-1): dp[i] += dp[i - sup] sup = sup+1 print((whole-dp[n])%mod) main()
Title: k-Tree Time Limit: None seconds Memory Limit: None megabytes Problem Description: Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a *k*-tree. A *k*-tree is an infinite rooted tree where: - each vertex has exactly *k* children; - each edge has some weight; - if we look at the edges that goes from some vertex to its children (exactly *k* edges), then their weights will equal 1,<=2,<=3,<=...,<=*k*. The picture below shows a part of a 3-tree. Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (109<=+<=7). Input Specification: A single line contains three space-separated integers: *n*, *k* and *d* (1<=≤<=*n*,<=*k*<=≤<=100; 1<=≤<=*d*<=≤<=*k*). Output Specification: Print a single integer — the answer to the problem modulo 1000000007 (109<=+<=7). Demo Input: ['3 3 2\n', '3 3 3\n', '4 3 2\n', '4 5 2\n'] Demo Output: ['3\n', '1\n', '6\n', '7\n'] Note: none
```python dp = [] mod = 1000000007 def main(): n, k, d = input().split() n = int(n) k = int(k) d = int(d) dp.append(1) for i in range(1, n+1): dp.append(0) sup = 1 while i - sup >= 0 and sup <= k: dp[i] += dp[i - sup] sup = sup+1 whole = dp[n] dp[0] = 1 for i in range(1, n+1): dp[i] = 0 sup = 1 while i - sup >= 0 and sup <= (d-1): dp[i] += dp[i - sup] sup = sup+1 print((whole-dp[n])%mod) main() ```
3
157
B
Trace
PROGRAMMING
1,000
[ "geometry", "sortings" ]
null
null
One day, as Sherlock Holmes was tracking down one very important criminal, he found a wonderful painting on the wall. This wall could be represented as a plane. The painting had several concentric circles that divided the wall into several parts. Some parts were painted red and all the other were painted blue. Besides, any two neighboring parts were painted different colors, that is, the red and the blue color were alternating, i. e. followed one after the other. The outer area of the wall (the area that lied outside all circles) was painted blue. Help Sherlock Holmes determine the total area of red parts of the wall. Let us remind you that two circles are called concentric if their centers coincide. Several circles are called concentric if any two of them are concentric.
The first line contains the single integer *n* (1<=≤<=*n*<=≤<=100). The second line contains *n* space-separated integers *r**i* (1<=≤<=*r**i*<=≤<=1000) — the circles' radii. It is guaranteed that all circles are different.
Print the single real number — total area of the part of the wall that is painted red. The answer is accepted if absolute or relative error doesn't exceed 10<=-<=4.
[ "1\n1\n", "3\n1 4 2\n" ]
[ "3.1415926536\n", "40.8407044967\n" ]
In the first sample the picture is just one circle of radius 1. Inner part of the circle is painted red. The area of the red part equals π × 1<sup class="upper-index">2</sup> = π. In the second sample there are three circles of radii 1, 4 and 2. Outside part of the second circle is painted blue. Part between the second and the third circles is painted red. Part between the first and the third is painted blue. And, finally, the inner part of the first circle is painted red. Overall there are two red parts: the ring between the second and the third circles and the inner part of the first circle. Total area of the red parts is equal (π × 4<sup class="upper-index">2</sup> - π × 2<sup class="upper-index">2</sup>) + π × 1<sup class="upper-index">2</sup> = π × 12 + π = 13π
1,000
[ { "input": "1\n1", "output": "3.1415926536" }, { "input": "3\n1 4 2", "output": "40.8407044967" }, { "input": "4\n4 1 3 2", "output": "31.4159265359" }, { "input": "4\n100 10 2 1", "output": "31111.1920484997" }, { "input": "10\n10 9 8 7 6 5 4 3 2 1", "output": "172.7875959474" }, { "input": "1\n1000", "output": "3141592.6535897931" }, { "input": "8\n8 1 7 2 6 3 5 4", "output": "113.0973355292" }, { "input": "100\n1000 999 998 997 996 995 994 993 992 991 990 989 988 987 986 985 984 983 982 981 980 979 978 977 976 975 974 973 972 971 970 969 968 967 966 965 964 963 962 961 960 959 958 957 956 955 954 953 952 951 950 949 948 947 946 945 944 943 942 941 940 939 938 937 936 935 934 933 932 931 930 929 928 927 926 925 924 923 922 921 920 919 918 917 916 915 914 913 912 911 910 909 908 907 906 905 904 903 902 901", "output": "298608.3817237098" }, { "input": "6\n109 683 214 392 678 10", "output": "397266.9574170437" }, { "input": "2\n151 400", "output": "431023.3704798660" }, { "input": "6\n258 877 696 425 663 934", "output": "823521.3902487604" }, { "input": "9\n635 707 108 234 52 180 910 203 782", "output": "1100144.9065826489" }, { "input": "8\n885 879 891 428 522 176 135 983", "output": "895488.9947571954" }, { "input": "3\n269 918 721", "output": "1241695.6467754442" }, { "input": "7\n920 570 681 428 866 935 795", "output": "1469640.1849419588" }, { "input": "2\n517 331", "output": "495517.1260654109" }, { "input": "2\n457 898", "output": "1877274.3981158488" }, { "input": "8\n872 704 973 612 183 274 739 253", "output": "1780774.0965755312" }, { "input": "74\n652 446 173 457 760 847 670 25 196 775 998 279 656 809 883 148 969 884 792 502 641 800 663 938 362 339 545 608 107 184 834 666 149 458 864 72 199 658 618 987 126 723 806 643 689 958 626 904 944 415 427 498 628 331 636 261 281 276 478 220 513 595 510 384 354 561 469 462 799 449 747 109 903 456", "output": "1510006.5089479341" }, { "input": "76\n986 504 673 158 87 332 124 218 714 235 212 122 878 370 938 81 686 323 386 348 410 468 875 107 50 960 82 834 234 663 651 422 794 633 294 771 945 607 146 913 950 858 297 88 882 725 247 872 645 749 799 987 115 394 380 382 971 429 593 426 652 353 351 233 868 598 889 116 71 376 916 464 414 976 138 903", "output": "1528494.7817143100" }, { "input": "70\n12 347 748 962 514 686 192 159 990 4 10 788 602 542 946 215 523 727 799 717 955 796 529 465 897 103 181 515 495 153 710 179 747 145 16 585 943 998 923 708 156 399 770 547 775 285 9 68 713 722 570 143 913 416 663 624 925 218 64 237 797 138 942 213 188 818 780 840 480 758", "output": "1741821.4892636713" }, { "input": "26\n656 508 45 189 561 366 96 486 547 386 703 570 780 689 264 26 11 74 466 76 421 48 982 886 215 650", "output": "1818821.9252031571" }, { "input": "52\n270 658 808 249 293 707 700 78 791 167 92 772 807 502 830 991 945 102 968 376 556 578 326 980 688 368 280 853 646 256 666 638 424 737 321 996 925 405 199 680 953 541 716 481 727 143 577 919 892 355 346 298", "output": "1272941.9273080483" }, { "input": "77\n482 532 200 748 692 697 171 863 586 547 301 149 326 812 147 698 303 691 527 805 681 387 619 947 598 453 167 799 840 508 893 688 643 974 998 341 804 230 538 669 271 404 477 759 943 596 949 235 880 160 151 660 832 82 969 539 708 889 258 81 224 655 790 144 462 582 646 256 445 52 456 920 67 819 631 484 534", "output": "2045673.1891262225" }, { "input": "27\n167 464 924 575 775 97 944 390 297 315 668 296 533 829 851 406 702 366 848 512 71 197 321 900 544 529 116", "output": "1573959.9105970615" }, { "input": "38\n488 830 887 566 720 267 583 102 65 200 884 220 263 858 510 481 316 804 754 568 412 166 374 869 356 977 145 421 500 58 664 252 745 70 381 927 670 772", "output": "1479184.3434235646" }, { "input": "64\n591 387 732 260 840 397 563 136 571 876 831 953 799 493 579 13 559 872 53 678 256 232 969 993 847 14 837 365 547 997 604 199 834 529 306 443 739 49 19 276 343 835 904 588 900 870 439 576 975 955 518 117 131 347 800 83 432 882 869 709 32 950 314 450", "output": "1258248.6984672088" }, { "input": "37\n280 281 169 68 249 389 977 101 360 43 448 447 368 496 125 507 747 392 338 270 916 150 929 428 118 266 589 470 774 852 263 644 187 817 808 58 637", "output": "1495219.0323274869" }, { "input": "97\n768 569 306 968 437 779 227 561 412 60 44 807 234 645 169 858 580 396 343 145 842 723 416 80 456 247 81 150 297 116 760 964 312 558 101 850 549 650 299 868 121 435 579 705 118 424 302 812 970 397 659 565 916 183 933 459 6 593 518 717 326 305 744 470 75 981 824 221 294 324 194 293 251 446 481 215 338 861 528 829 921 945 540 89 450 178 24 460 990 392 148 219 934 615 932 340 937", "output": "1577239.7333274092" }, { "input": "94\n145 703 874 425 277 652 239 496 458 658 339 842 564 699 893 352 625 980 432 121 798 872 499 859 850 721 414 825 543 843 304 111 342 45 219 311 50 748 465 902 781 822 504 985 919 656 280 310 917 438 464 527 491 713 906 329 635 777 223 810 501 535 156 252 806 112 971 719 103 443 165 98 579 554 244 996 221 560 301 51 977 422 314 858 528 772 448 626 185 194 536 66 577 677", "output": "1624269.3753516484" }, { "input": "97\n976 166 649 81 611 927 480 231 998 711 874 91 969 521 531 414 993 790 317 981 9 261 437 332 173 573 904 777 882 990 658 878 965 64 870 896 271 732 431 53 761 943 418 602 708 949 930 130 512 240 363 458 673 319 131 784 224 48 919 126 208 212 911 59 677 535 450 273 479 423 79 807 336 18 72 290 724 28 123 605 287 228 350 897 250 392 885 655 746 417 643 114 813 378 355 635 905", "output": "1615601.7212203942" }, { "input": "91\n493 996 842 9 748 178 1 807 841 519 796 998 84 670 778 143 707 208 165 893 154 943 336 150 761 881 434 112 833 55 412 682 552 945 758 189 209 600 354 325 440 844 410 20 136 665 88 791 688 17 539 821 133 236 94 606 483 446 429 60 960 476 915 134 137 852 754 908 276 482 117 252 297 903 981 203 829 811 471 135 188 667 710 393 370 302 874 872 551 457 692", "output": "1806742.5014501044" }, { "input": "95\n936 736 17 967 229 607 589 291 242 244 29 698 800 566 630 667 90 416 11 94 812 838 668 520 678 111 490 823 199 973 681 676 683 721 262 896 682 713 402 691 874 44 95 704 56 322 822 887 639 433 406 35 988 61 176 496 501 947 440 384 372 959 577 370 754 802 1 945 427 116 746 408 308 391 397 730 493 183 203 871 831 862 461 565 310 344 504 378 785 137 279 123 475 138 415", "output": "1611115.5269110680" }, { "input": "90\n643 197 42 218 582 27 66 704 195 445 641 675 285 639 503 686 242 327 57 955 848 287 819 992 756 749 363 48 648 736 580 117 752 921 923 372 114 313 202 337 64 497 399 25 883 331 24 871 917 8 517 486 323 529 325 92 891 406 864 402 263 773 931 253 625 31 17 271 140 131 232 586 893 525 846 54 294 562 600 801 214 55 768 683 389 738 314 284 328 804", "output": "1569819.2914796301" }, { "input": "98\n29 211 984 75 333 96 840 21 352 168 332 433 130 944 215 210 620 442 363 877 91 491 513 955 53 82 351 19 998 706 702 738 770 453 344 117 893 590 723 662 757 16 87 546 312 669 568 931 224 374 927 225 751 962 651 587 361 250 256 240 282 600 95 64 384 589 813 783 39 918 412 648 506 283 886 926 443 173 946 241 310 33 622 565 261 360 547 339 943 367 354 25 479 743 385 485 896 741", "output": "2042921.1539616778" }, { "input": "93\n957 395 826 67 185 4 455 880 683 654 463 84 258 878 553 592 124 585 9 133 20 609 43 452 725 125 801 537 700 685 771 155 566 376 19 690 383 352 174 208 177 416 304 1000 533 481 87 509 358 233 681 22 507 659 36 859 952 259 138 271 594 779 576 782 119 69 608 758 283 616 640 523 710 751 34 106 774 92 874 568 864 660 998 992 474 679 180 409 15 297 990 689 501", "output": "1310703.8710041976" }, { "input": "97\n70 611 20 30 904 636 583 262 255 501 604 660 212 128 199 138 545 576 506 528 12 410 77 888 783 972 431 188 338 485 148 793 907 678 281 922 976 680 252 724 253 920 177 361 721 798 960 572 99 622 712 466 608 49 612 345 266 751 63 594 40 695 532 789 520 930 825 929 48 59 405 135 109 735 508 186 495 772 375 587 201 324 447 610 230 947 855 318 856 956 313 810 931 175 668 183 688", "output": "1686117.9099228707" }, { "input": "96\n292 235 391 180 840 172 218 997 166 287 329 20 886 325 400 471 182 356 448 337 417 319 58 106 366 764 393 614 90 831 924 314 667 532 64 874 3 434 350 352 733 795 78 640 967 63 47 879 635 272 145 569 468 792 153 761 770 878 281 467 209 208 298 37 700 18 334 93 5 750 412 779 523 517 360 649 447 328 311 653 57 578 767 460 647 663 50 670 151 13 511 580 625 907 227 89", "output": "1419726.5608617242" }, { "input": "100\n469 399 735 925 62 153 707 723 819 529 200 624 57 708 245 384 889 11 639 638 260 419 8 142 403 298 204 169 887 388 241 983 885 267 643 943 417 237 452 562 6 839 149 742 832 896 100 831 712 754 679 743 135 222 445 680 210 955 220 63 960 487 514 824 481 584 441 997 795 290 10 45 510 678 844 503 407 945 850 84 858 934 500 320 936 663 736 592 161 670 606 465 864 969 293 863 868 393 899 744", "output": "1556458.0979239127" }, { "input": "100\n321 200 758 415 190 710 920 992 873 898 814 259 359 66 971 210 838 545 663 652 684 277 36 756 963 459 335 484 462 982 532 423 131 703 307 229 391 938 253 847 542 975 635 928 220 980 222 567 557 181 366 824 900 180 107 979 112 564 525 413 300 422 876 615 737 343 902 8 654 628 469 913 967 785 893 314 909 215 912 262 20 709 363 915 997 954 986 454 596 124 74 159 660 550 787 418 895 786 293 50", "output": "1775109.8050211088" }, { "input": "100\n859 113 290 762 701 63 188 431 810 485 671 673 99 658 194 227 511 435 941 212 551 124 89 222 42 321 657 815 898 171 216 482 707 567 724 491 414 942 820 351 48 653 685 312 586 24 20 627 602 498 533 173 463 262 621 466 119 299 580 964 510 987 40 698 521 998 847 651 746 215 808 563 785 837 631 772 404 923 682 244 232 214 390 350 968 771 517 900 70 543 934 554 681 368 642 575 891 728 478 317", "output": "1447969.4788174964" }, { "input": "100\n941 283 349 457 52 837 299 284 796 305 893 624 101 972 738 204 121 70 17 704 836 791 95 111 162 952 472 724 733 580 878 177 705 804 11 211 463 417 288 409 410 485 896 755 921 267 164 656 505 765 539 439 535 19 991 689 220 474 114 944 884 144 926 849 486 566 117 35 749 499 797 303 362 905 690 890 976 66 590 183 234 683 39 297 769 787 376 541 571 759 495 200 261 352 73 493 831 442 273 339", "output": "1597889.4218394549" }, { "input": "100\n110 868 147 888 291 282 916 542 917 337 235 595 498 621 814 249 261 713 445 666 142 275 319 49 900 543 333 606 487 670 620 769 852 258 230 867 603 491 714 839 879 37 21 74 590 190 397 506 499 967 152 862 200 107 145 23 614 167 857 475 79 598 270 906 626 116 89 59 651 846 723 201 50 699 522 408 634 132 226 414 824 764 513 586 526 238 556 162 667 173 684 415 527 743 10 442 552 274 350 822", "output": "1567230.6191330721" }, { "input": "100\n901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000", "output": "298608.3817237098" } ]
1,571,126,952
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
0
248
0
n=int(input()) l=[int(i) for i in input().split()] l.sort() A=0 pi=22/7 for i in range(n-1,0,-2): r=l[i] r1=l[i-1] A+=(pi*r*r-pi*r1*r1) A+=pi*l[0]*l[0] print(A)
Title: Trace Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day, as Sherlock Holmes was tracking down one very important criminal, he found a wonderful painting on the wall. This wall could be represented as a plane. The painting had several concentric circles that divided the wall into several parts. Some parts were painted red and all the other were painted blue. Besides, any two neighboring parts were painted different colors, that is, the red and the blue color were alternating, i. e. followed one after the other. The outer area of the wall (the area that lied outside all circles) was painted blue. Help Sherlock Holmes determine the total area of red parts of the wall. Let us remind you that two circles are called concentric if their centers coincide. Several circles are called concentric if any two of them are concentric. Input Specification: The first line contains the single integer *n* (1<=≤<=*n*<=≤<=100). The second line contains *n* space-separated integers *r**i* (1<=≤<=*r**i*<=≤<=1000) — the circles' radii. It is guaranteed that all circles are different. Output Specification: Print the single real number — total area of the part of the wall that is painted red. The answer is accepted if absolute or relative error doesn't exceed 10<=-<=4. Demo Input: ['1\n1\n', '3\n1 4 2\n'] Demo Output: ['3.1415926536\n', '40.8407044967\n'] Note: In the first sample the picture is just one circle of radius 1. Inner part of the circle is painted red. The area of the red part equals π × 1<sup class="upper-index">2</sup> = π. In the second sample there are three circles of radii 1, 4 and 2. Outside part of the second circle is painted blue. Part between the second and the third circles is painted red. Part between the first and the third is painted blue. And, finally, the inner part of the first circle is painted red. Overall there are two red parts: the ring between the second and the third circles and the inner part of the first circle. Total area of the red parts is equal (π × 4<sup class="upper-index">2</sup> - π × 2<sup class="upper-index">2</sup>) + π × 1<sup class="upper-index">2</sup> = π × 12 + π = 13π
```python n=int(input()) l=[int(i) for i in input().split()] l.sort() A=0 pi=22/7 for i in range(n-1,0,-2): r=l[i] r1=l[i-1] A+=(pi*r*r-pi*r1*r1) A+=pi*l[0]*l[0] print(A) ```
0
257
C
View Angle
PROGRAMMING
1,800
[ "brute force", "geometry", "math" ]
null
null
Flatland has recently introduced a new type of an eye check for the driver's licence. The check goes like that: there is a plane with mannequins standing on it. You should tell the value of the minimum angle with the vertex at the origin of coordinates and with all mannequins standing inside or on the boarder of this angle. As you spend lots of time "glued to the screen", your vision is impaired. So you have to write a program that will pass the check for you.
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of mannequins. Next *n* lines contain two space-separated integers each: *x**i*,<=*y**i* (|*x**i*|,<=|*y**i*|<=≤<=1000) — the coordinates of the *i*-th mannequin. It is guaranteed that the origin of the coordinates has no mannequin. It is guaranteed that no two mannequins are located in the same point on the plane.
Print a single real number — the value of the sought angle in degrees. The answer will be considered valid if the relative or absolute error doesn't exceed 10<=-<=6.
[ "2\n2 0\n0 2\n", "3\n2 0\n0 2\n-2 2\n", "4\n2 0\n0 2\n-2 0\n0 -2\n", "2\n2 1\n1 2\n" ]
[ "90.0000000000\n", "135.0000000000\n", "270.0000000000\n", "36.8698976458\n" ]
Solution for the first sample test is shown below: Solution for the second sample test is shown below: Solution for the third sample test is shown below: Solution for the fourth sample test is shown below:
1,500
[ { "input": "2\n2 0\n0 2", "output": "90.0000000000" }, { "input": "3\n2 0\n0 2\n-2 2", "output": "135.0000000000" }, { "input": "4\n2 0\n0 2\n-2 0\n0 -2", "output": "270.0000000000" }, { "input": "2\n2 1\n1 2", "output": "36.8698976458" }, { "input": "1\n1 1", "output": "0.0000000000" }, { "input": "10\n9 7\n10 7\n6 5\n6 10\n7 6\n5 10\n6 7\n10 9\n5 5\n5 8", "output": "28.4429286244" }, { "input": "10\n-1 28\n1 28\n1 25\n0 23\n-1 24\n-1 22\n1 27\n0 30\n1 22\n1 21", "output": "5.3288731964" }, { "input": "10\n-5 9\n-10 6\n-8 8\n-9 9\n-6 5\n-8 9\n-5 7\n-6 6\n-5 10\n-8 7", "output": "32.4711922908" }, { "input": "10\n6 -9\n9 -5\n10 -5\n7 -5\n8 -7\n8 -10\n8 -5\n6 -10\n7 -6\n8 -9", "output": "32.4711922908" }, { "input": "10\n-5 -7\n-8 -10\n-9 -5\n-5 -9\n-9 -8\n-7 -7\n-6 -8\n-6 -10\n-10 -7\n-9 -6", "output": "31.8907918018" }, { "input": "10\n-1 -29\n-1 -26\n1 -26\n-1 -22\n-1 -24\n-1 -21\n1 -24\n-1 -20\n-1 -23\n-1 -25", "output": "5.2483492565" }, { "input": "10\n21 0\n22 1\n30 0\n20 0\n28 0\n29 0\n21 -1\n30 1\n24 1\n26 0", "output": "5.3288731964" }, { "input": "10\n-20 0\n-22 1\n-26 0\n-22 -1\n-30 -1\n-30 0\n-28 0\n-24 1\n-23 -1\n-29 1", "output": "5.2051244050" }, { "input": "10\n-5 -5\n5 -5\n-4 -5\n4 -5\n1 -5\n0 -5\n3 -5\n-2 -5\n2 -5\n-3 -5", "output": "90.0000000000" }, { "input": "10\n-5 -5\n-4 -5\n-2 -5\n4 -5\n5 -5\n3 -5\n2 -5\n-1 -5\n-3 -5\n0 -5", "output": "90.0000000000" }, { "input": "10\n-1 -5\n-5 -5\n2 -5\n-2 -5\n1 -5\n5 -5\n0 -5\n3 -5\n-4 -5\n-3 -5", "output": "90.0000000000" }, { "input": "10\n-1 -5\n-5 -5\n-4 -5\n3 -5\n0 -5\n4 -5\n1 -5\n-2 -5\n5 -5\n-3 -5", "output": "90.0000000000" }, { "input": "10\n5 -5\n4 -5\n-1 -5\n1 -5\n-4 -5\n3 -5\n0 -5\n-5 -5\n-2 -5\n-3 -5", "output": "90.0000000000" }, { "input": "10\n2 -5\n-4 -5\n-2 -5\n4 -5\n-5 -5\n-1 -5\n0 -5\n-3 -5\n3 -5\n1 -5", "output": "83.6598082541" }, { "input": "5\n2 1\n0 1\n2 -1\n-2 -1\n2 0", "output": "233.1301023542" }, { "input": "5\n-2 -2\n2 2\n2 -1\n-2 0\n1 -1", "output": "225.0000000000" }, { "input": "5\n0 -2\n-2 -1\n-1 2\n0 -1\n-1 0", "output": "153.4349488229" }, { "input": "5\n-1 -1\n-2 -1\n1 0\n-1 -2\n-1 1", "output": "225.0000000000" }, { "input": "5\n1 -1\n0 2\n-2 2\n-2 1\n2 1", "output": "198.4349488229" }, { "input": "5\n2 2\n1 2\n-2 -1\n1 1\n-2 -2", "output": "180.0000000000" }, { "input": "2\n1 1\n2 2", "output": "0.0000000000" }, { "input": "27\n-592 -96\n-925 -150\n-111 -18\n-259 -42\n-370 -60\n-740 -120\n-629 -102\n-333 -54\n-407 -66\n-296 -48\n-37 -6\n-999 -162\n-222 -36\n-555 -90\n-814 -132\n-444 -72\n-74 -12\n-185 -30\n-148 -24\n-962 -156\n-777 -126\n-518 -84\n-888 -144\n-666 -108\n-481 -78\n-851 -138\n-703 -114", "output": "0.0000000000" }, { "input": "38\n96 416\n24 104\n6 26\n12 52\n210 910\n150 650\n54 234\n174 754\n114 494\n18 78\n90 390\n36 156\n222 962\n186 806\n126 546\n78 338\n108 468\n180 780\n120 520\n84 364\n66 286\n138 598\n30 130\n228 988\n72 312\n144 624\n198 858\n60 260\n48 208\n102 442\n42 182\n162 702\n132 572\n156 676\n204 884\n216 936\n168 728\n192 832", "output": "0.0000000000" }, { "input": "14\n-2 -134\n-4 -268\n-11 -737\n-7 -469\n-14 -938\n-10 -670\n-3 -201\n-1 -67\n-9 -603\n-6 -402\n-13 -871\n-12 -804\n-8 -536\n-5 -335", "output": "0.0000000000" }, { "input": "14\n588 938\n420 670\n210 335\n252 402\n504 804\n126 201\n42 67\n546 871\n294 469\n84 134\n336 536\n462 737\n168 268\n378 603", "output": "0.0000000000" }, { "input": "20\n-45 147\n-240 784\n-135 441\n-60 196\n-105 343\n-285 931\n-195 637\n-300 980\n-165 539\n-210 686\n-75 245\n-15 49\n-30 98\n-270 882\n-120 392\n-90 294\n-150 490\n-180 588\n-255 833\n-225 735", "output": "0.0000000000" }, { "input": "2\n1 1\n1 -1", "output": "90.0000000000" } ]
1,640,409,505
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
5
902
12,492,800
import math import sys def readline(): return sys.stdin.readline().strip() def read(t=int): s = sys.stdin.readline() return list(map(t, s.strip().split(' '))) def readint(): return read()[0] def go(): n = readint() lis = [] for i in range(n): x, y = read() angle = math.atan2(y, x) lis.append((angle, x, y)) lis = sorted(lis) lis+=[lis[0]] maxangle = 0 for i in range(1, len(lis)): lasta = lis[i-1][0] nowa = lis[i][0] maxangle = max(abs(lasta-nowa), maxangle) piangle = maxangle print(piangle/2/math.pi*360) go() # try: # go() # print("YES") # except: # print("NO")
Title: View Angle Time Limit: None seconds Memory Limit: None megabytes Problem Description: Flatland has recently introduced a new type of an eye check for the driver's licence. The check goes like that: there is a plane with mannequins standing on it. You should tell the value of the minimum angle with the vertex at the origin of coordinates and with all mannequins standing inside or on the boarder of this angle. As you spend lots of time "glued to the screen", your vision is impaired. So you have to write a program that will pass the check for you. Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of mannequins. Next *n* lines contain two space-separated integers each: *x**i*,<=*y**i* (|*x**i*|,<=|*y**i*|<=≤<=1000) — the coordinates of the *i*-th mannequin. It is guaranteed that the origin of the coordinates has no mannequin. It is guaranteed that no two mannequins are located in the same point on the plane. Output Specification: Print a single real number — the value of the sought angle in degrees. The answer will be considered valid if the relative or absolute error doesn't exceed 10<=-<=6. Demo Input: ['2\n2 0\n0 2\n', '3\n2 0\n0 2\n-2 2\n', '4\n2 0\n0 2\n-2 0\n0 -2\n', '2\n2 1\n1 2\n'] Demo Output: ['90.0000000000\n', '135.0000000000\n', '270.0000000000\n', '36.8698976458\n'] Note: Solution for the first sample test is shown below: Solution for the second sample test is shown below: Solution for the third sample test is shown below: Solution for the fourth sample test is shown below:
```python import math import sys def readline(): return sys.stdin.readline().strip() def read(t=int): s = sys.stdin.readline() return list(map(t, s.strip().split(' '))) def readint(): return read()[0] def go(): n = readint() lis = [] for i in range(n): x, y = read() angle = math.atan2(y, x) lis.append((angle, x, y)) lis = sorted(lis) lis+=[lis[0]] maxangle = 0 for i in range(1, len(lis)): lasta = lis[i-1][0] nowa = lis[i][0] maxangle = max(abs(lasta-nowa), maxangle) piangle = maxangle print(piangle/2/math.pi*360) go() # try: # go() # print("YES") # except: # print("NO") ```
0
214
A
System of Equations
PROGRAMMING
800
[ "brute force" ]
null
null
Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you? You are given a system of equations: You should count, how many there are pairs of integers (*a*,<=*b*) (0<=≤<=*a*,<=*b*) which satisfy the system.
A single line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the parameters of the system. The numbers on the line are separated by a space.
On a single line print the answer to the problem.
[ "9 3\n", "14 28\n", "4 20\n" ]
[ "1\n", "1\n", "0\n" ]
In the first sample the suitable pair is integers (3, 0). In the second sample the suitable pair is integers (3, 5). In the third sample there is no suitable pair.
500
[ { "input": "9 3", "output": "1" }, { "input": "14 28", "output": "1" }, { "input": "4 20", "output": "0" }, { "input": "18 198", "output": "1" }, { "input": "22 326", "output": "1" }, { "input": "26 104", "output": "1" }, { "input": "14 10", "output": "0" }, { "input": "8 20", "output": "0" }, { "input": "2 8", "output": "0" }, { "input": "20 11", "output": "0" }, { "input": "57 447", "output": "1" }, { "input": "1 1", "output": "2" }, { "input": "66 296", "output": "1" }, { "input": "75 683", "output": "1" }, { "input": "227 975", "output": "1" }, { "input": "247 499", "output": "1" }, { "input": "266 116", "output": "1" }, { "input": "286 916", "output": "1" }, { "input": "307 341", "output": "1" }, { "input": "451 121", "output": "1" }, { "input": "471 921", "output": "1" }, { "input": "502 346", "output": "1" }, { "input": "535 59", "output": "1" }, { "input": "555 699", "output": "1" }, { "input": "747 351", "output": "1" }, { "input": "790 64", "output": "1" }, { "input": "810 704", "output": "1" }, { "input": "855 225", "output": "1" }, { "input": "902 34", "output": "1" }, { "input": "922 514", "output": "1" }, { "input": "971 131", "output": "1" }, { "input": "991 931", "output": "1" }, { "input": "840 780", "output": "0" }, { "input": "102 595", "output": "0" }, { "input": "139 433", "output": "0" }, { "input": "968 288", "output": "0" }, { "input": "563 354", "output": "0" }, { "input": "994 975", "output": "0" }, { "input": "456 221", "output": "0" }, { "input": "205 210", "output": "0" }, { "input": "1 11", "output": "0" }, { "input": "1000 1000", "output": "0" }, { "input": "3 3", "output": "0" }, { "input": "11 99", "output": "0" }, { "input": "2 2", "output": "1" }, { "input": "11 1", "output": "0" }, { "input": "6 6", "output": "1" }, { "input": "100 452", "output": "0" }, { "input": "420 380", "output": "0" }, { "input": "31 31", "output": "0" }, { "input": "2 6", "output": "0" }, { "input": "112 134", "output": "0" }, { "input": "13 13", "output": "0" }, { "input": "1 571", "output": "0" } ]
1,652,980,196
2,147,483,647
PyPy 3-64
OK
TESTS
54
124
28,467,200
n,m = map(int,input().split()) c = 0 for i in range(n+1): c += (i**2 + (n-i)**0.5) ==m print(c)
Title: System of Equations Time Limit: None seconds Memory Limit: None megabytes Problem Description: Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you? You are given a system of equations: You should count, how many there are pairs of integers (*a*,<=*b*) (0<=≤<=*a*,<=*b*) which satisfy the system. Input Specification: A single line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the parameters of the system. The numbers on the line are separated by a space. Output Specification: On a single line print the answer to the problem. Demo Input: ['9 3\n', '14 28\n', '4 20\n'] Demo Output: ['1\n', '1\n', '0\n'] Note: In the first sample the suitable pair is integers (3, 0). In the second sample the suitable pair is integers (3, 5). In the third sample there is no suitable pair.
```python n,m = map(int,input().split()) c = 0 for i in range(n+1): c += (i**2 + (n-i)**0.5) ==m print(c) ```
3
9
A
Die Roll
PROGRAMMING
800
[ "math", "probabilities" ]
A. Die Roll
1
64
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpredictable place. But to their great regret, the leave turned to be very short, so it will be enough to visit one of the three above named places. That's why Yakko, as the cleverest, came up with a truly genius idea: let each of the three roll an ordinary six-sided die, and the one with the highest amount of points will be the winner, and will take the other two to the place of his/her dreams. Yakko thrown a die and got Y points, Wakko — W points. It was Dot's turn. But she didn't hurry. Dot wanted to know for sure what were her chances to visit Transylvania. It is known that Yakko and Wakko are true gentlemen, that's why if they have the same amount of points with Dot, they will let Dot win.
The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls.
Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1».
[ "4 2\n" ]
[ "1/2\n" ]
Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points.
0
[ { "input": "4 2", "output": "1/2" }, { "input": "1 1", "output": "1/1" }, { "input": "1 2", "output": "5/6" }, { "input": "1 3", "output": "2/3" }, { "input": "1 4", "output": "1/2" }, { "input": "1 5", "output": "1/3" }, { "input": "1 6", "output": "1/6" }, { "input": "2 1", "output": "5/6" }, { "input": "2 2", "output": "5/6" }, { "input": "2 3", "output": "2/3" }, { "input": "2 4", "output": "1/2" }, { "input": "2 5", "output": "1/3" }, { "input": "2 6", "output": "1/6" }, { "input": "3 1", "output": "2/3" }, { "input": "3 2", "output": "2/3" }, { "input": "3 3", "output": "2/3" }, { "input": "3 4", "output": "1/2" }, { "input": "3 5", "output": "1/3" }, { "input": "3 6", "output": "1/6" }, { "input": "4 1", "output": "1/2" }, { "input": "4 3", "output": "1/2" }, { "input": "4 4", "output": "1/2" }, { "input": "4 5", "output": "1/3" }, { "input": "4 6", "output": "1/6" }, { "input": "5 1", "output": "1/3" }, { "input": "5 2", "output": "1/3" }, { "input": "5 3", "output": "1/3" }, { "input": "5 4", "output": "1/3" }, { "input": "5 5", "output": "1/3" }, { "input": "5 6", "output": "1/6" }, { "input": "6 1", "output": "1/6" }, { "input": "6 2", "output": "1/6" }, { "input": "6 3", "output": "1/6" }, { "input": "6 4", "output": "1/6" }, { "input": "6 5", "output": "1/6" }, { "input": "6 6", "output": "1/6" } ]
1,549,041,721
2,147,483,647
Python 3
OK
TESTS
36
374
1,126,400
from fractions import gcd x, y = map(int,input().split()) d = 6-max(x,y)+1 f = gcd(d,6) d = int(d/f) a = int(6/f) print (str(d)+"/"+str(a))
Title: Die Roll Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpredictable place. But to their great regret, the leave turned to be very short, so it will be enough to visit one of the three above named places. That's why Yakko, as the cleverest, came up with a truly genius idea: let each of the three roll an ordinary six-sided die, and the one with the highest amount of points will be the winner, and will take the other two to the place of his/her dreams. Yakko thrown a die and got Y points, Wakko — W points. It was Dot's turn. But she didn't hurry. Dot wanted to know for sure what were her chances to visit Transylvania. It is known that Yakko and Wakko are true gentlemen, that's why if they have the same amount of points with Dot, they will let Dot win. Input Specification: The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls. Output Specification: Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1». Demo Input: ['4 2\n'] Demo Output: ['1/2\n'] Note: Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points.
```python from fractions import gcd x, y = map(int,input().split()) d = 6-max(x,y)+1 f = gcd(d,6) d = int(d/f) a = int(6/f) print (str(d)+"/"+str(a)) ```
3.804608
5
A
Chat Servers Outgoing Traffic
PROGRAMMING
1,000
[ "implementation" ]
A. Chat Server's Outgoing Traffic
1
64
Polycarp is working on a new project called "Polychat". Following modern tendencies in IT, he decided, that this project should contain chat as well. To achieve this goal, Polycarp has spent several hours in front of his laptop and implemented a chat server that can process three types of commands: - Include a person to the chat ('Add' command). - Remove a person from the chat ('Remove' command). - Send a message from a person to all people, who are currently in the chat, including the one, who sends the message ('Send' command). Now Polycarp wants to find out the amount of outgoing traffic that the server will produce while processing a particular set of commands. Polycarp knows that chat server sends no traffic for 'Add' and 'Remove' commands. When 'Send' command is processed, server sends *l* bytes to each participant of the chat, where *l* is the length of the message. As Polycarp has no time, he is asking for your help in solving this problem.
Input file will contain not more than 100 commands, each in its own line. No line will exceed 100 characters. Formats of the commands will be the following: - +&lt;name&gt; for 'Add' command. - -&lt;name&gt; for 'Remove' command. - &lt;sender_name&gt;:&lt;message_text&gt; for 'Send' command. &lt;name&gt; and &lt;sender_name&gt; is a non-empty sequence of Latin letters and digits. &lt;message_text&gt; can contain letters, digits and spaces, but can't start or end with a space. &lt;message_text&gt; can be an empty line. It is guaranteed, that input data are correct, i.e. there will be no 'Add' command if person with such a name is already in the chat, there will be no 'Remove' command if there is no person with such a name in the chat etc. All names are case-sensitive.
Print a single number — answer to the problem.
[ "+Mike\nMike:hello\n+Kate\n+Dmitry\n-Dmitry\nKate:hi\n-Kate\n", "+Mike\n-Mike\n+Mike\nMike:Hi I am here\n-Mike\n+Kate\n-Kate\n" ]
[ "9\n", "14\n" ]
none
0
[ { "input": "+Mike\nMike:hello\n+Kate\n+Dmitry\n-Dmitry\nKate:hi\n-Kate", "output": "9" }, { "input": "+Mike\n-Mike\n+Mike\nMike:Hi I am here\n-Mike\n+Kate\n-Kate", "output": "14" }, { "input": "+Dmitry\n+Mike\nDmitry:All letters will be used\nDmitry:qwertyuiopasdfghjklzxcvbnm QWERTYUIOPASDFGHJKLZXCVBNM\nDmitry:And digits too\nDmitry:1234567890 0987654321\n-Dmitry", "output": "224" }, { "input": "+Dmitry\n+Mike\n+Kate\nDmitry:", "output": "0" }, { "input": "+Dmitry\nDmitry:No phrases with spaces at the beginning and at the end\n+Mike\nDmitry:spaces spaces\n-Dmitry", "output": "86" }, { "input": "+XqD\n+aT537\nXqD:x6ZPjMR1DDKG2\nXqD:lLCriywPnB\n-XqD", "output": "46" }, { "input": "+8UjgAJ\n8UjgAJ:02hR7UBc1tqqfL\n-8UjgAJ\n+zdi\n-zdi", "output": "14" }, { "input": "+6JPKkgXDrA\n+j6JHjv70An\n+QGtsceK0zJ\n6JPKkgXDrA:o4\n+CSmwi9zDra\nQGtsceK0zJ:Zl\nQGtsceK0zJ:0\nj6JHjv70An:7\nj6JHjv70An:B\nQGtsceK0zJ:OO", "output": "34" }, { "input": "+1aLNq9S7uLV\n-1aLNq9S7uLV\n+O9ykq3xDJv\n-O9ykq3xDJv\n+54Yq1xJq14F\n+0zJ5Vo0RDZ\n-54Yq1xJq14F\n-0zJ5Vo0RDZ\n+lxlH7sdolyL\n-lxlH7sdolyL", "output": "0" }, { "input": "+qlHEc2AuYy\nqlHEc2AuYy:YYRwD0 edNZgpE nGfOguRWnMYpTpGUVM aXDKGXo1Gv1tHL9\nqlHEc2AuYy:yvh3GsPcImqrvoUcBNQcP6ezwpU0 xAVltaKZp94VKiNao\nqlHEc2AuYy:zuCO6Opey L eu7lTwysaSk00zjpv zrDfbt8l hpHfu\n+pErDMxgVgh\nqlHEc2AuYy:I1FLis mmQbZtd8Ui7y 1vcax6yZBMhVRdD6Ahlq7MNCw\nqlHEc2AuYy:lz MFUNJZhlqBYckHUDlNhLiEkmecRh1o0t7alXBvCRVEFVx\npErDMxgVgh:jCyMbu1dkuEj5TzbBOjyUhpfC50cL8R900Je3R KxRgAI dT\nqlHEc2AuYy:62b47eabo2hf vSUD7KioN ZHki6WB6gh3u GKv5rgwyfF\npErDMxgVgh:zD5 9 ympl4wR gy7a7eAGAn5xVdGP9FbL6hRCZAR6O4pT6zb", "output": "615" }, { "input": "+adabacaba0", "output": "0" }, { "input": "+acabadab\n+caba0aba", "output": "0" }, { "input": "+dabaca\n-dabaca\n+aba0ab", "output": "0" }, { "input": "+cab\n+abac\n-abac\n+baca", "output": "0" }, { "input": "+cabadabac\n-cabadabac\n+abacaba1ab\n-abacaba1ab\n+ba0abaca", "output": "0" }, { "input": "+adabacaba\n-adabacaba\n+aca\naca:caba\n-aca\n+bacaba\n-bacaba\n+aba\n-aba\n+bad", "output": "4" }, { "input": "+acabadab\n-acabadab\n+aba0abacab\n+baca\n+abacaba0ab\n-baca\n-abacaba0ab\n-aba0abacab\n+cab\n-cab\n+abacabada\n-abacabada\n+badabaca\n-badabaca\n+badaba", "output": "0" }, { "input": "+badabac\nbadabac:abacabad\n-badabac\n+0ab\n-0ab\n+dabacab\n-dabacab\n+a0ab\n-a0ab\n+0abaca\n-0abaca\n+dabac\n-dabac\n+abaca\n-abaca\n+bacabada\n-bacabada\n+aca\n-aca\n+abadabaca\n-abadabaca\n+acaba\n-acaba\n+abacabadab\n-abacabadab", "output": "8" } ]
1,537,254,532
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
154
0
# -*- coding: utf-8 -*- """ Created on Tue Sep 18 11:51:35 2018 @author: haoqianqiong Keep going !!! Walking to Lose Weight!!! """ """ 包含三种操作:Add(+),Remove(-),Send(:) 前两种不占通道量,重点在后一个,需要计算Send内容的长度和当前接收人数 """ a = b = 0 while True: m = input() if m =='': break elif m[0] == '+': a += 1 elif m[0] == '-': a -= 1 else: b += len(m.split(':')[1]) * a print(b)
Title: Chat Servers Outgoing Traffic Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: Polycarp is working on a new project called "Polychat". Following modern tendencies in IT, he decided, that this project should contain chat as well. To achieve this goal, Polycarp has spent several hours in front of his laptop and implemented a chat server that can process three types of commands: - Include a person to the chat ('Add' command). - Remove a person from the chat ('Remove' command). - Send a message from a person to all people, who are currently in the chat, including the one, who sends the message ('Send' command). Now Polycarp wants to find out the amount of outgoing traffic that the server will produce while processing a particular set of commands. Polycarp knows that chat server sends no traffic for 'Add' and 'Remove' commands. When 'Send' command is processed, server sends *l* bytes to each participant of the chat, where *l* is the length of the message. As Polycarp has no time, he is asking for your help in solving this problem. Input Specification: Input file will contain not more than 100 commands, each in its own line. No line will exceed 100 characters. Formats of the commands will be the following: - +&lt;name&gt; for 'Add' command. - -&lt;name&gt; for 'Remove' command. - &lt;sender_name&gt;:&lt;message_text&gt; for 'Send' command. &lt;name&gt; and &lt;sender_name&gt; is a non-empty sequence of Latin letters and digits. &lt;message_text&gt; can contain letters, digits and spaces, but can't start or end with a space. &lt;message_text&gt; can be an empty line. It is guaranteed, that input data are correct, i.e. there will be no 'Add' command if person with such a name is already in the chat, there will be no 'Remove' command if there is no person with such a name in the chat etc. All names are case-sensitive. Output Specification: Print a single number — answer to the problem. Demo Input: ['+Mike\nMike:hello\n+Kate\n+Dmitry\n-Dmitry\nKate:hi\n-Kate\n', '+Mike\n-Mike\n+Mike\nMike:Hi I am here\n-Mike\n+Kate\n-Kate\n'] Demo Output: ['9\n', '14\n'] Note: none
```python # -*- coding: utf-8 -*- """ Created on Tue Sep 18 11:51:35 2018 @author: haoqianqiong Keep going !!! Walking to Lose Weight!!! """ """ 包含三种操作:Add(+),Remove(-),Send(:) 前两种不占通道量,重点在后一个,需要计算Send内容的长度和当前接收人数 """ a = b = 0 while True: m = input() if m =='': break elif m[0] == '+': a += 1 elif m[0] == '-': a -= 1 else: b += len(m.split(':')[1]) * a print(b) ```
-1
633
A
Ebony and Ivory
PROGRAMMING
1,100
[ "brute force", "math", "number theory" ]
null
null
Dante is engaged in a fight with "The Savior". Before he can fight it with his sword, he needs to break its shields. He has two guns, Ebony and Ivory, each of them is able to perform any non-negative number of shots. For every bullet that hits the shield, Ebony deals *a* units of damage while Ivory deals *b* units of damage. In order to break the shield Dante has to deal exactly *c* units of damage. Find out if this is possible.
The first line of the input contains three integers *a*, *b*, *c* (1<=≤<=*a*,<=*b*<=≤<=100,<=1<=≤<=*c*<=≤<=10<=000) — the number of units of damage dealt by Ebony gun and Ivory gun, and the total number of damage required to break the shield, respectively.
Print "Yes" (without quotes) if Dante can deal exactly *c* damage to the shield and "No" (without quotes) otherwise.
[ "4 6 15\n", "3 2 7\n", "6 11 6\n" ]
[ "No\n", "Yes\n", "Yes\n" ]
In the second sample, Dante can fire 1 bullet from Ebony and 2 from Ivory to deal exactly 1·3 + 2·2 = 7 damage. In the third sample, Dante can fire 1 bullet from ebony and no bullets from ivory to do 1·6 + 0·11 = 6 damage.
250
[ { "input": "4 6 15", "output": "No" }, { "input": "3 2 7", "output": "Yes" }, { "input": "6 11 6", "output": "Yes" }, { "input": "3 12 15", "output": "Yes" }, { "input": "5 5 10", "output": "Yes" }, { "input": "6 6 7", "output": "No" }, { "input": "1 1 20", "output": "Yes" }, { "input": "12 14 19", "output": "No" }, { "input": "15 12 26", "output": "No" }, { "input": "2 4 8", "output": "Yes" }, { "input": "4 5 30", "output": "Yes" }, { "input": "4 5 48", "output": "Yes" }, { "input": "2 17 105", "output": "Yes" }, { "input": "10 25 282", "output": "No" }, { "input": "6 34 323", "output": "No" }, { "input": "2 47 464", "output": "Yes" }, { "input": "4 53 113", "output": "Yes" }, { "input": "6 64 546", "output": "Yes" }, { "input": "1 78 725", "output": "Yes" }, { "input": "1 84 811", "output": "Yes" }, { "input": "3 100 441", "output": "Yes" }, { "input": "20 5 57", "output": "No" }, { "input": "14 19 143", "output": "No" }, { "input": "17 23 248", "output": "No" }, { "input": "11 34 383", "output": "Yes" }, { "input": "20 47 568", "output": "Yes" }, { "input": "16 58 410", "output": "Yes" }, { "input": "11 70 1199", "output": "Yes" }, { "input": "16 78 712", "output": "Yes" }, { "input": "20 84 562", "output": "No" }, { "input": "19 100 836", "output": "Yes" }, { "input": "23 10 58", "output": "No" }, { "input": "25 17 448", "output": "Yes" }, { "input": "22 24 866", "output": "Yes" }, { "input": "24 35 67", "output": "No" }, { "input": "29 47 264", "output": "Yes" }, { "input": "23 56 45", "output": "No" }, { "input": "25 66 1183", "output": "Yes" }, { "input": "21 71 657", "output": "Yes" }, { "input": "29 81 629", "output": "No" }, { "input": "23 95 2226", "output": "Yes" }, { "input": "32 4 62", "output": "No" }, { "input": "37 15 789", "output": "Yes" }, { "input": "39 24 999", "output": "Yes" }, { "input": "38 32 865", "output": "No" }, { "input": "32 50 205", "output": "No" }, { "input": "31 57 1362", "output": "Yes" }, { "input": "38 68 1870", "output": "Yes" }, { "input": "36 76 549", "output": "No" }, { "input": "35 84 1257", "output": "No" }, { "input": "39 92 2753", "output": "Yes" }, { "input": "44 1 287", "output": "Yes" }, { "input": "42 12 830", "output": "No" }, { "input": "42 27 9", "output": "No" }, { "input": "49 40 1422", "output": "No" }, { "input": "44 42 2005", "output": "No" }, { "input": "50 55 2479", "output": "No" }, { "input": "48 65 917", "output": "No" }, { "input": "45 78 152", "output": "No" }, { "input": "43 90 4096", "output": "Yes" }, { "input": "43 94 4316", "output": "Yes" }, { "input": "60 7 526", "output": "Yes" }, { "input": "53 11 735", "output": "Yes" }, { "input": "52 27 609", "output": "Yes" }, { "input": "57 32 992", "output": "Yes" }, { "input": "52 49 421", "output": "No" }, { "input": "57 52 2634", "output": "Yes" }, { "input": "54 67 3181", "output": "Yes" }, { "input": "52 73 638", "output": "No" }, { "input": "57 84 3470", "output": "No" }, { "input": "52 100 5582", "output": "No" }, { "input": "62 1 501", "output": "Yes" }, { "input": "63 17 858", "output": "Yes" }, { "input": "70 24 1784", "output": "Yes" }, { "input": "65 32 1391", "output": "Yes" }, { "input": "62 50 2775", "output": "No" }, { "input": "62 58 88", "output": "No" }, { "input": "66 68 3112", "output": "Yes" }, { "input": "61 71 1643", "output": "No" }, { "input": "69 81 3880", "output": "No" }, { "input": "63 100 1960", "output": "Yes" }, { "input": "73 6 431", "output": "Yes" }, { "input": "75 19 736", "output": "Yes" }, { "input": "78 25 247", "output": "No" }, { "input": "79 36 2854", "output": "Yes" }, { "input": "80 43 1864", "output": "Yes" }, { "input": "76 55 2196", "output": "Yes" }, { "input": "76 69 4122", "output": "Yes" }, { "input": "76 76 4905", "output": "No" }, { "input": "75 89 3056", "output": "Yes" }, { "input": "73 100 3111", "output": "Yes" }, { "input": "84 9 530", "output": "No" }, { "input": "82 18 633", "output": "No" }, { "input": "85 29 2533", "output": "Yes" }, { "input": "89 38 2879", "output": "Yes" }, { "input": "89 49 2200", "output": "Yes" }, { "input": "88 60 4140", "output": "Yes" }, { "input": "82 68 1299", "output": "No" }, { "input": "90 76 2207", "output": "No" }, { "input": "83 84 4923", "output": "Yes" }, { "input": "89 99 7969", "output": "Yes" }, { "input": "94 9 168", "output": "No" }, { "input": "91 20 1009", "output": "No" }, { "input": "93 23 2872", "output": "Yes" }, { "input": "97 31 3761", "output": "Yes" }, { "input": "99 46 1341", "output": "Yes" }, { "input": "98 51 2845", "output": "No" }, { "input": "93 66 3412", "output": "No" }, { "input": "95 76 3724", "output": "Yes" }, { "input": "91 87 6237", "output": "Yes" }, { "input": "98 97 7886", "output": "Yes" }, { "input": "12 17 15", "output": "No" }, { "input": "93 94 95", "output": "No" }, { "input": "27 43 27", "output": "Yes" }, { "input": "17 43 68", "output": "Yes" }, { "input": "44 12 12", "output": "Yes" }, { "input": "44 50 150", "output": "Yes" }, { "input": "1 1 10000", "output": "Yes" }, { "input": "2 3 10000", "output": "Yes" }, { "input": "100 1 10", "output": "Yes" }, { "input": "3 2 1", "output": "No" }, { "input": "1 1 1", "output": "Yes" }, { "input": "9 9 10000", "output": "No" }, { "input": "2 3 9995", "output": "Yes" }, { "input": "3 5 4", "output": "No" }, { "input": "99 98 100", "output": "No" }, { "input": "6 10 2", "output": "No" }, { "input": "1 6 5", "output": "Yes" }, { "input": "1 4 3", "output": "Yes" }, { "input": "3 2 3", "output": "Yes" }, { "input": "1 7 6", "output": "Yes" }, { "input": "2 3 9871", "output": "Yes" }, { "input": "10 5 5", "output": "Yes" }, { "input": "10 8 2", "output": "No" } ]
1,597,208,627
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
12
109
6,656,000
a,b,c=map(int,input().split()) if c%a==0 or c%b==0: print("Yes") else: if c%(a+b)==0: print("Yes") elif c%(a+b)==a or c%(a+b)==b: print("Yes") else: print("No")
Title: Ebony and Ivory Time Limit: None seconds Memory Limit: None megabytes Problem Description: Dante is engaged in a fight with "The Savior". Before he can fight it with his sword, he needs to break its shields. He has two guns, Ebony and Ivory, each of them is able to perform any non-negative number of shots. For every bullet that hits the shield, Ebony deals *a* units of damage while Ivory deals *b* units of damage. In order to break the shield Dante has to deal exactly *c* units of damage. Find out if this is possible. Input Specification: The first line of the input contains three integers *a*, *b*, *c* (1<=≤<=*a*,<=*b*<=≤<=100,<=1<=≤<=*c*<=≤<=10<=000) — the number of units of damage dealt by Ebony gun and Ivory gun, and the total number of damage required to break the shield, respectively. Output Specification: Print "Yes" (without quotes) if Dante can deal exactly *c* damage to the shield and "No" (without quotes) otherwise. Demo Input: ['4 6 15\n', '3 2 7\n', '6 11 6\n'] Demo Output: ['No\n', 'Yes\n', 'Yes\n'] Note: In the second sample, Dante can fire 1 bullet from Ebony and 2 from Ivory to deal exactly 1·3 + 2·2 = 7 damage. In the third sample, Dante can fire 1 bullet from ebony and no bullets from ivory to do 1·6 + 0·11 = 6 damage.
```python a,b,c=map(int,input().split()) if c%a==0 or c%b==0: print("Yes") else: if c%(a+b)==0: print("Yes") elif c%(a+b)==a or c%(a+b)==b: print("Yes") else: print("No") ```
0
599
A
Patrick and Shopping
PROGRAMMING
800
[ "implementation" ]
null
null
Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the first shop and a *d*2 meter long road between his house and the second shop. Also, there is a road of length *d*3 directly connecting these two shops to each other. Help Patrick calculate the minimum distance that he needs to walk in order to go to both shops and return to his house. Patrick always starts at his house. He should visit both shops moving only along the three existing roads and return back to his house. He doesn't mind visiting the same shop or passing the same road multiple times. The only goal is to minimize the total distance traveled.
The first line of the input contains three integers *d*1, *d*2, *d*3 (1<=≤<=*d*1,<=*d*2,<=*d*3<=≤<=108) — the lengths of the paths. - *d*1 is the length of the path connecting Patrick's house and the first shop; - *d*2 is the length of the path connecting Patrick's house and the second shop; - *d*3 is the length of the path connecting both shops.
Print the minimum distance that Patrick will have to walk in order to visit both shops and return to his house.
[ "10 20 30\n", "1 1 5\n" ]
[ "60\n", "4\n" ]
The first sample is shown on the picture in the problem statement. One of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> second shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> house. In the second sample one of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> second shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> house.
500
[ { "input": "10 20 30", "output": "60" }, { "input": "1 1 5", "output": "4" }, { "input": "100 33 34", "output": "134" }, { "input": "777 777 777", "output": "2331" }, { "input": "2 2 8", "output": "8" }, { "input": "12 34 56", "output": "92" }, { "input": "789 101112 131415", "output": "203802" }, { "input": "27485716 99999999 35182", "output": "55041796" }, { "input": "1 293548 5", "output": "12" }, { "input": "12059 259855 5874875", "output": "543828" }, { "input": "46981 105809 585858", "output": "305580" }, { "input": "9889 1221 2442", "output": "7326" }, { "input": "100500 200600 300700", "output": "601800" }, { "input": "318476 318476 318476", "output": "955428" }, { "input": "23985 3353 75633", "output": "54676" }, { "input": "120 1298 2222", "output": "2836" }, { "input": "98437 23487 666672", "output": "243848" }, { "input": "100000000 100000000 100000000", "output": "300000000" }, { "input": "2 5 2", "output": "8" }, { "input": "1 1000 1", "output": "4" }, { "input": "1 100000000 1", "output": "4" } ]
1,621,417,762
2,147,483,647
Python 3
OK
TESTS
21
62
0
x, y, z = (int(i) for i in input().split()) res1 = x * 2 + y * 2 res2 = x + y + z res3 = min(x, y) * 2 + z * 2 print(min(res1, res2, res3))
Title: Patrick and Shopping Time Limit: None seconds Memory Limit: None megabytes Problem Description: Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the first shop and a *d*2 meter long road between his house and the second shop. Also, there is a road of length *d*3 directly connecting these two shops to each other. Help Patrick calculate the minimum distance that he needs to walk in order to go to both shops and return to his house. Patrick always starts at his house. He should visit both shops moving only along the three existing roads and return back to his house. He doesn't mind visiting the same shop or passing the same road multiple times. The only goal is to minimize the total distance traveled. Input Specification: The first line of the input contains three integers *d*1, *d*2, *d*3 (1<=≤<=*d*1,<=*d*2,<=*d*3<=≤<=108) — the lengths of the paths. - *d*1 is the length of the path connecting Patrick's house and the first shop; - *d*2 is the length of the path connecting Patrick's house and the second shop; - *d*3 is the length of the path connecting both shops. Output Specification: Print the minimum distance that Patrick will have to walk in order to visit both shops and return to his house. Demo Input: ['10 20 30\n', '1 1 5\n'] Demo Output: ['60\n', '4\n'] Note: The first sample is shown on the picture in the problem statement. One of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> second shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> house. In the second sample one of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> second shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> house.
```python x, y, z = (int(i) for i in input().split()) res1 = x * 2 + y * 2 res2 = x + y + z res3 = min(x, y) * 2 + z * 2 print(min(res1, res2, res3)) ```
3
224
A
Parallelepiped
PROGRAMMING
1,100
[ "brute force", "geometry", "math" ]
null
null
You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped.
The first and the single line contains three space-separated integers — the areas of the parallelepiped's faces. The area's values are positive (<=&gt;<=0) and do not exceed 104. It is guaranteed that there exists at least one parallelepiped that satisfies the problem statement.
Print a single number — the sum of all edges of the parallelepiped.
[ "1 1 1\n", "4 6 6\n" ]
[ "12\n", "28\n" ]
In the first sample the parallelepiped has sizes 1 × 1 × 1, in the second one — 2 × 2 × 3.
500
[ { "input": "1 1 1", "output": "12" }, { "input": "4 6 6", "output": "28" }, { "input": "20 10 50", "output": "68" }, { "input": "9 4 36", "output": "56" }, { "input": "324 9 36", "output": "184" }, { "input": "1333 93 129", "output": "308" }, { "input": "1022 584 112", "output": "380" }, { "input": "66 174 319", "output": "184" }, { "input": "912 276 1748", "output": "444" }, { "input": "65 156 60", "output": "120" }, { "input": "1 10000 10000", "output": "40008" }, { "input": "1485 55 27", "output": "332" }, { "input": "152 108 4104", "output": "528" }, { "input": "1656 6900 1350", "output": "740" }, { "input": "12 14 42", "output": "60" }, { "input": "615 18 1230", "output": "856" }, { "input": "680 60 408", "output": "336" }, { "input": "644 966 6", "output": "1308" }, { "input": "1 432 432", "output": "1736" }, { "input": "2239 2239 1", "output": "8964" }, { "input": "4106 8212 2", "output": "16436" }, { "input": "10000 10000 10000", "output": "1200" }, { "input": "3623 3623 1", "output": "14500" }, { "input": "9801 9801 9801", "output": "1188" }, { "input": "10000 1 10000", "output": "40008" }, { "input": "9 9 9", "output": "36" }, { "input": "9801 9702 9702", "output": "1184" } ]
1,620,775,708
2,147,483,647
Python 3
OK
TESTS
27
154
6,758,400
import math arr = list(map(int, input().rstrip().split())) t = 0 a = math.sqrt((arr[0]*arr[1]/arr[2])) b = math.sqrt((arr[1]*arr[2]/arr[0])) c = math.sqrt((arr[0]*arr[2]/arr[1])) print(int((a+b+c)*4))
Title: Parallelepiped Time Limit: None seconds Memory Limit: None megabytes Problem Description: You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped. Input Specification: The first and the single line contains three space-separated integers — the areas of the parallelepiped's faces. The area's values are positive (<=&gt;<=0) and do not exceed 104. It is guaranteed that there exists at least one parallelepiped that satisfies the problem statement. Output Specification: Print a single number — the sum of all edges of the parallelepiped. Demo Input: ['1 1 1\n', '4 6 6\n'] Demo Output: ['12\n', '28\n'] Note: In the first sample the parallelepiped has sizes 1 × 1 × 1, in the second one — 2 × 2 × 3.
```python import math arr = list(map(int, input().rstrip().split())) t = 0 a = math.sqrt((arr[0]*arr[1]/arr[2])) b = math.sqrt((arr[1]*arr[2]/arr[0])) c = math.sqrt((arr[0]*arr[2]/arr[1])) print(int((a+b+c)*4)) ```
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,548,518,277
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
15
109
409,600
def sort_tup(tup,arr): bo=True for x in range(len(arr)): if arr[x][0]>tup[0]: bo=False break if bo: return arr+[tup] else: return arr[:x]+[tup]+arr[x:] def main(): arr=input().split() node=int(arr[0]) edge=int(arr[1]) store=[[] for _ in range(node)] for _ in range(edge): arr=input().split() a=int(arr[0])-1 b=int(arr[1])-1 weight=int(arr[2]) store[a].append((b,weight)) store[b].append((a,weight)) #print(store) previous=[None for _ in range(node)] previous[0]=-1 arr=[] for x in store[0]: #tup=(weight,next_pos,prev_pos) arr=sort_tup((x[1],x[0],0),arr) for _ in range(node-1): #print(arr) if arr==[]: break minimum=arr[0] previous[minimum[1]]=minimum[2] dup=[] for x in range(len(arr)): if arr[x][1]!=minimum[1]: dup.append(arr[x]) for y in store[minimum[1]]: if previous[y[0]]==None: dup=sort_tup((y[1]+minimum[0],y[0],minimum[1]),dup) arr=dup.copy() if previous[x-1]==None: print(-1) else: string=str(node) x=previous[node-1] while x!=-1: string=str(x+1)+" "+string x=previous[x] print(string) main()
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 def sort_tup(tup,arr): bo=True for x in range(len(arr)): if arr[x][0]>tup[0]: bo=False break if bo: return arr+[tup] else: return arr[:x]+[tup]+arr[x:] def main(): arr=input().split() node=int(arr[0]) edge=int(arr[1]) store=[[] for _ in range(node)] for _ in range(edge): arr=input().split() a=int(arr[0])-1 b=int(arr[1])-1 weight=int(arr[2]) store[a].append((b,weight)) store[b].append((a,weight)) #print(store) previous=[None for _ in range(node)] previous[0]=-1 arr=[] for x in store[0]: #tup=(weight,next_pos,prev_pos) arr=sort_tup((x[1],x[0],0),arr) for _ in range(node-1): #print(arr) if arr==[]: break minimum=arr[0] previous[minimum[1]]=minimum[2] dup=[] for x in range(len(arr)): if arr[x][1]!=minimum[1]: dup.append(arr[x]) for y in store[minimum[1]]: if previous[y[0]]==None: dup=sort_tup((y[1]+minimum[0],y[0],minimum[1]),dup) arr=dup.copy() if previous[x-1]==None: print(-1) else: string=str(node) x=previous[node-1] while x!=-1: string=str(x+1)+" "+string x=previous[x] print(string) main() ```
-1
519
A
A and B and Chess
PROGRAMMING
900
[ "implementation" ]
null
null
A and B are preparing themselves for programming contests. To train their logical thinking and solve problems better, A and B decided to play chess. During the game A wondered whose position is now stronger. For each chess piece we know its weight: - the queen's weight is 9, - the rook's weight is 5, - the bishop's weight is 3, - the knight's weight is 3, - the pawn's weight is 1, - the king's weight isn't considered in evaluating position. The player's weight equals to the sum of weights of all his pieces on the board. As A doesn't like counting, he asked you to help him determine which player has the larger position weight.
The input contains eight lines, eight characters each — the board's description. The white pieces on the board are marked with uppercase letters, the black pieces are marked with lowercase letters. The white pieces are denoted as follows: the queen is represented is 'Q', the rook — as 'R', the bishop — as'B', the knight — as 'N', the pawn — as 'P', the king — as 'K'. The black pieces are denoted as 'q', 'r', 'b', 'n', 'p', 'k', respectively. An empty square of the board is marked as '.' (a dot). It is not guaranteed that the given chess position can be achieved in a real game. Specifically, there can be an arbitrary (possibly zero) number pieces of each type, the king may be under attack and so on.
Print "White" (without quotes) if the weight of the position of the white pieces is more than the weight of the position of the black pieces, print "Black" if the weight of the black pieces is more than the weight of the white pieces and print "Draw" if the weights of the white and black pieces are equal.
[ "...QK...\n........\n........\n........\n........\n........\n........\n...rk...\n", "rnbqkbnr\npppppppp\n........\n........\n........\n........\nPPPPPPPP\nRNBQKBNR\n", "rppppppr\n...k....\n........\n........\n........\n........\nK...Q...\n........\n" ]
[ "White\n", "Draw\n", "Black\n" ]
In the first test sample the weight of the position of the white pieces equals to 9, the weight of the position of the black pieces equals 5. In the second test sample the weights of the positions of the black and the white pieces are equal to 39. In the third test sample the weight of the position of the white pieces equals to 9, the weight of the position of the black pieces equals to 16.
500
[ { "input": "rnbqkbnr\npppppppp\n........\n........\n........\n........\nPPPPPPPP\nRNBQKBNR", "output": "Draw" }, { "input": "....bQ.K\n.B......\n.....P..\n........\n........\n........\n...N.P..\n.....R..", "output": "White" }, { "input": "b....p..\nR.......\n.pP...b.\npp......\nq.PPNpPR\n..K..rNn\nP.....p.\n...Q..B.", "output": "White" }, { "input": "...Nn...\n........\n........\n........\n.R....b.\n........\n........\n......p.", "output": "White" }, { "input": "qqqqqqqq\nqqqqqqqq\nqqqqqqqq\nqqqqqqqq\nqqqqqqqq\nqqqqqqqq\nqqqqqqqq\nqqqqqqqq", "output": "Black" }, { "input": "QQQQQQQQ\nQQQQQQQQ\nQQQQQQQQ\nQQQQQQQQ\nQQQQQQQQ\nQQQQQQQQ\nQQQQQQQQ\nQQQQQQQQ", "output": "White" }, { "input": "qqqqqqqq\nqqqqqqqq\nqqqqqqqq\nqqqqqqqq\nQQQQQQQQ\nQQQQQQQQ\nQQQQQQQQ\nQQQQQQQQ", "output": "Draw" }, { "input": "QQQQQQQQ\nQQQQQQQQ\n........\n........\n........\n........\nrrrrrr..\nrrrrrrrr", "output": "White" }, { "input": "........\n........\n........\n........\n........\n........\n........\n.......n", "output": "Black" }, { "input": "........\n...b....\n........\n........\n........\n........\n........\n.......K", "output": "Black" }, { "input": "........\n........\n........\n........\n........\n........\n........\n......Kp", "output": "Black" }, { "input": "........\n........\n........\n........\n........\n........\n........\n.......Q", "output": "White" }, { "input": "........\n........\n........\n........\n........\n........\n........\n......Bp", "output": "White" }, { "input": "........\n........\n........\n........\n........\n........\n........\nkkkkkB..", "output": "White" }, { "input": "QqPQNN.Q\n.qBbr.qB\np.RKBpNK\nPknBr.nq\nKqKRNKKk\n.BqPqkb.\nPBNPr.rk\nBpBKrPRR", "output": "Black" }, { "input": "........\n........\n........\n........\n........\n........\n........\n.......K", "output": "Draw" } ]
1,699,975,039
2,147,483,647
PyPy 3-64
OK
TESTS
65
62
0
i = [input() for _ in range(8)] bp = {'q': 9, 'r': 5, 'b': 3, 'n':3, 'p': 1} wp = {'Q': 9, 'R': 5, 'B': 3, 'N':3, 'P': 1} black, white = 0, 0 for row in i: for piece in row: if piece in bp.keys(): black += bp[piece] elif piece in wp.keys(): white += wp[piece] if white == black: print('Draw') else: print('White' if white > black else 'Black')
Title: A and B and Chess Time Limit: None seconds Memory Limit: None megabytes Problem Description: A and B are preparing themselves for programming contests. To train their logical thinking and solve problems better, A and B decided to play chess. During the game A wondered whose position is now stronger. For each chess piece we know its weight: - the queen's weight is 9, - the rook's weight is 5, - the bishop's weight is 3, - the knight's weight is 3, - the pawn's weight is 1, - the king's weight isn't considered in evaluating position. The player's weight equals to the sum of weights of all his pieces on the board. As A doesn't like counting, he asked you to help him determine which player has the larger position weight. Input Specification: The input contains eight lines, eight characters each — the board's description. The white pieces on the board are marked with uppercase letters, the black pieces are marked with lowercase letters. The white pieces are denoted as follows: the queen is represented is 'Q', the rook — as 'R', the bishop — as'B', the knight — as 'N', the pawn — as 'P', the king — as 'K'. The black pieces are denoted as 'q', 'r', 'b', 'n', 'p', 'k', respectively. An empty square of the board is marked as '.' (a dot). It is not guaranteed that the given chess position can be achieved in a real game. Specifically, there can be an arbitrary (possibly zero) number pieces of each type, the king may be under attack and so on. Output Specification: Print "White" (without quotes) if the weight of the position of the white pieces is more than the weight of the position of the black pieces, print "Black" if the weight of the black pieces is more than the weight of the white pieces and print "Draw" if the weights of the white and black pieces are equal. Demo Input: ['...QK...\n........\n........\n........\n........\n........\n........\n...rk...\n', 'rnbqkbnr\npppppppp\n........\n........\n........\n........\nPPPPPPPP\nRNBQKBNR\n', 'rppppppr\n...k....\n........\n........\n........\n........\nK...Q...\n........\n'] Demo Output: ['White\n', 'Draw\n', 'Black\n'] Note: In the first test sample the weight of the position of the white pieces equals to 9, the weight of the position of the black pieces equals 5. In the second test sample the weights of the positions of the black and the white pieces are equal to 39. In the third test sample the weight of the position of the white pieces equals to 9, the weight of the position of the black pieces equals to 16.
```python i = [input() for _ in range(8)] bp = {'q': 9, 'r': 5, 'b': 3, 'n':3, 'p': 1} wp = {'Q': 9, 'R': 5, 'B': 3, 'N':3, 'P': 1} black, white = 0, 0 for row in i: for piece in row: if piece in bp.keys(): black += bp[piece] elif piece in wp.keys(): white += wp[piece] if white == black: print('Draw') else: print('White' if white > black else 'Black') ```
3
81
A
Plug-in
PROGRAMMING
1,400
[ "implementation" ]
A. Plug-in
1
256
Polycarp thinks about the meaning of life very often. He does this constantly, even when typing in the editor. Every time he starts brooding he can no longer fully concentrate and repeatedly presses the keys that need to be pressed only once. For example, instead of the phrase "how are you" he can type "hhoow aaaare yyoouu". Polycarp decided to automate the process of correcting such errors. He decided to write a plug-in to the text editor that will remove pairs of identical consecutive letters (if there are any in the text). Of course, this is not exactly what Polycarp needs, but he's got to start from something! Help Polycarp and write the main plug-in module. Your program should remove from a string all pairs of identical letters, which are consecutive. If after the removal there appear new pairs, the program should remove them as well. Technically, its work should be equivalent to the following: while the string contains a pair of consecutive identical letters, the pair should be deleted. Note that deleting of the consecutive identical letters can be done in any order, as any order leads to the same result.
The input data consists of a single line to be processed. The length of the line is from 1 to 2·105 characters inclusive. The string contains only lowercase Latin letters.
Print the given string after it is processed. It is guaranteed that the result will contain at least one character.
[ "hhoowaaaareyyoouu\n", "reallazy\n", "abacabaabacabaa\n" ]
[ "wre", "rezy", "a" ]
none
500
[ { "input": "hhoowaaaareyyoouu", "output": "wre" }, { "input": "reallazy", "output": "rezy" }, { "input": "abacabaabacabaa", "output": "a" }, { "input": "xraccabccbry", "output": "xy" }, { "input": "a", "output": "a" }, { "input": "b", "output": "b" }, { "input": "il", "output": "il" }, { "input": "gfj", "output": "gfj" }, { "input": "babbbbbababa", "output": "babababa" }, { "input": "babbbbabbabbbababbabbbbbbabaabaababaaabbbbbabbbbaaaaabbaaabbaabaabbbbabbbababbabaaabbababaaababbbaaa", "output": "babababababababababababa" }, { "input": "aab", "output": "b" }, { "input": "abb", "output": "a" }, { "input": "aba", "output": "aba" }, { "input": "ab", "output": "ab" } ]
1,608,035,034
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
4
404
9,523,200
s = input() A = [ch for ch in s] def chop(A): res = [] i = 0 while (i<len(A)): cnt = 1 j = i + 1 while (j<len(A) and A[i]==A[j]): cnt += 1 j+= 1 if cnt == 1: res.append(A[i]) i = j return res def check(A): for i in range(len(A)-1): if A[i]==A[i+1]: return False return True while (check(A)==False): A = chop(A) print("".join(A))
Title: Plug-in Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Polycarp thinks about the meaning of life very often. He does this constantly, even when typing in the editor. Every time he starts brooding he can no longer fully concentrate and repeatedly presses the keys that need to be pressed only once. For example, instead of the phrase "how are you" he can type "hhoow aaaare yyoouu". Polycarp decided to automate the process of correcting such errors. He decided to write a plug-in to the text editor that will remove pairs of identical consecutive letters (if there are any in the text). Of course, this is not exactly what Polycarp needs, but he's got to start from something! Help Polycarp and write the main plug-in module. Your program should remove from a string all pairs of identical letters, which are consecutive. If after the removal there appear new pairs, the program should remove them as well. Technically, its work should be equivalent to the following: while the string contains a pair of consecutive identical letters, the pair should be deleted. Note that deleting of the consecutive identical letters can be done in any order, as any order leads to the same result. Input Specification: The input data consists of a single line to be processed. The length of the line is from 1 to 2·105 characters inclusive. The string contains only lowercase Latin letters. Output Specification: Print the given string after it is processed. It is guaranteed that the result will contain at least one character. Demo Input: ['hhoowaaaareyyoouu\n', 'reallazy\n', 'abacabaabacabaa\n'] Demo Output: ['wre', 'rezy', 'a'] Note: none
```python s = input() A = [ch for ch in s] def chop(A): res = [] i = 0 while (i<len(A)): cnt = 1 j = i + 1 while (j<len(A) and A[i]==A[j]): cnt += 1 j+= 1 if cnt == 1: res.append(A[i]) i = j return res def check(A): for i in range(len(A)-1): if A[i]==A[i+1]: return False return True while (check(A)==False): A = chop(A) print("".join(A)) ```
0
37
A
Towers
PROGRAMMING
1,000
[ "sortings" ]
A. Towers
2
256
Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same. Vasya wants to construct the minimal number of towers from the bars. Help Vasya to use the bars in the best way possible.
The first line contains an integer *N* (1<=≤<=*N*<=≤<=1000) — the number of bars at Vasya’s disposal. The second line contains *N* space-separated integers *l**i* — the lengths of the bars. All the lengths are natural numbers not exceeding 1000.
In one line output two numbers — the height of the largest tower and their total number. Remember that Vasya should use all the bars.
[ "3\n1 2 3\n", "4\n6 5 6 7\n" ]
[ "1 3\n", "2 3\n" ]
none
500
[ { "input": "3\n1 2 3", "output": "1 3" }, { "input": "4\n6 5 6 7", "output": "2 3" }, { "input": "4\n3 2 1 1", "output": "2 3" }, { "input": "4\n1 2 3 3", "output": "2 3" }, { "input": "3\n20 22 36", "output": "1 3" }, { "input": "25\n47 30 94 41 45 20 96 51 110 129 24 116 9 47 32 82 105 114 116 75 154 151 70 42 162", "output": "2 23" }, { "input": "45\n802 664 442 318 318 827 417 878 711 291 231 414 807 553 657 392 279 202 386 606 465 655 658 112 887 15 25 502 95 44 679 775 942 609 209 871 31 234 4 231 150 110 22 823 193", "output": "2 43" }, { "input": "63\n93 180 116 7 8 179 268 279 136 94 221 153 264 190 278 19 19 63 153 26 158 225 25 49 89 218 111 149 255 225 197 122 243 80 3 224 107 178 202 17 53 92 69 42 228 24 81 205 95 8 265 82 228 156 127 241 172 159 106 60 67 155 111", "output": "2 57" }, { "input": "83\n246 535 994 33 390 927 321 97 223 922 812 705 79 80 977 457 476 636 511 137 6 360 815 319 717 674 368 551 714 628 278 713 761 553 184 414 623 753 428 214 581 115 439 61 677 216 772 592 187 603 658 310 439 559 870 376 109 321 189 337 277 26 70 734 796 907 979 693 570 227 345 650 737 633 701 914 134 403 972 940 371 6 642", "output": "2 80" }, { "input": "105\n246 57 12 204 165 123 246 68 191 310 3 152 386 333 374 257 158 104 333 50 80 290 8 340 101 76 221 316 388 289 138 359 316 26 93 290 105 178 81 195 41 196 218 180 244 292 187 97 315 323 174 119 248 239 92 312 31 2 101 180 307 170 338 314 163 281 217 31 142 238 280 190 190 156 70 74 329 113 151 8 141 313 366 40 253 116 168 124 135 230 294 266 353 389 371 359 195 200 183 237 93 102 315 118 188", "output": "2 92" }, { "input": "123\n112 277 170 247 252 115 157 293 256 143 196 90 12 164 164 42 8 223 167 109 175 232 239 111 148 51 9 254 93 32 268 162 231 91 47 162 161 191 195 145 247 292 129 199 230 94 144 217 18 205 176 20 143 198 121 243 211 262 230 277 195 255 108 290 220 275 158 2 286 200 60 267 278 207 123 150 123 116 131 13 12 226 33 244 30 275 263 45 158 192 254 149 242 176 62 224 221 288 250 160 155 225 132 143 276 293 218 145 197 175 33 129 79 206 210 192 222 262 190 52 274 243 233", "output": "3 101" }, { "input": "5\n5 5 5 5 5", "output": "5 1" }, { "input": "3\n1000 1000 1000", "output": "3 1" }, { "input": "1\n1000", "output": "1 1" }, { "input": "1\n1", "output": "1 1" }, { "input": "5\n1 1000 1000 1000 1000", "output": "4 2" }, { "input": "5\n1000 1000 1000 8 7", "output": "3 3" } ]
1,589,997,325
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
15
280
0
N = int(input()) L = [int(i) for i in input().split()] h = [L.count(L[i]) for i in range(len(L))] cubes = 0 towers = 0 for i in L: if L.count(i) > 1: cubes += L.count(i) towers += 1 while i in L: L.remove(i) print(max(h), N - cubes + towers)
Title: Towers Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same. Vasya wants to construct the minimal number of towers from the bars. Help Vasya to use the bars in the best way possible. Input Specification: The first line contains an integer *N* (1<=≤<=*N*<=≤<=1000) — the number of bars at Vasya’s disposal. The second line contains *N* space-separated integers *l**i* — the lengths of the bars. All the lengths are natural numbers not exceeding 1000. Output Specification: In one line output two numbers — the height of the largest tower and their total number. Remember that Vasya should use all the bars. Demo Input: ['3\n1 2 3\n', '4\n6 5 6 7\n'] Demo Output: ['1 3\n', '2 3\n'] Note: none
```python N = int(input()) L = [int(i) for i in input().split()] h = [L.count(L[i]) for i in range(len(L))] cubes = 0 towers = 0 for i in L: if L.count(i) > 1: cubes += L.count(i) towers += 1 while i in L: L.remove(i) print(max(h), N - cubes + towers) ```
0
120
F
Spiders
PROGRAMMING
1,400
[ "dp", "greedy", "trees" ]
null
null
One day mum asked Petya to sort his toys and get rid of some of them. Petya found a whole box of toy spiders. They were quite dear to him and the boy didn't want to throw them away. Petya conjured a cunning plan: he will glue all the spiders together and attach them to the ceiling. Besides, Petya knows that the lower the spiders will hang, the more mum is going to like it and then she won't throw his favourite toys away. Help Petya carry out the plan. A spider consists of *k* beads tied together by *k*<=-<=1 threads. Each thread connects two different beads, at that any pair of beads that make up a spider is either directly connected by a thread, or is connected via some chain of threads and beads. Petya may glue spiders together directly gluing their beads. The length of each thread equals 1. The sizes of the beads can be neglected. That's why we can consider that gluing spiders happens by identifying some of the beads (see the picture). Besides, the construction resulting from the gluing process should also represent a spider, that is, it should have the given features. After Petya glues all spiders together, he measures the length of the resulting toy. The distance between a pair of beads is identified as the total length of the threads that connect these two beads. The length of the resulting construction is the largest distance between all pairs of beads. Petya wants to make the spider whose length is as much as possible. The picture two shows two spiders from the second sample. We can glue to the bead number 2 of the first spider the bead number 1 of the second spider. The threads in the spiders that form the sequence of threads of maximum lengths are highlighted on the picture.
The first input file line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of spiders. Next *n* lines contain the descriptions of each spider: integer *n**i* (2<=≤<=*n**i*<=≤<=100) — the number of beads, then *n**i*<=-<=1 pairs of numbers denoting the numbers of the beads connected by threads. The beads that make up each spider are numbered from 1 to *n**i*.
Print a single number — the length of the required construction.
[ "1\n3 1 2 2 3\n", "2\n3 1 2 1 3\n4 1 2 2 3 2 4\n", "2\n5 1 2 2 3 3 4 3 5\n7 3 4 1 2 2 4 4 6 2 7 6 5\n" ]
[ "2\n", "4\n", "7\n" ]
none
0
[ { "input": "1\n3 1 2 2 3", "output": "2" }, { "input": "2\n3 1 2 1 3\n4 1 2 2 3 2 4", "output": "4" }, { "input": "2\n5 1 2 2 3 3 4 3 5\n7 3 4 1 2 2 4 4 6 2 7 6 5", "output": "7" }, { "input": "3\n3 1 2 2 3\n5 2 5 5 3 3 4 5 1\n9 6 5 5 9 4 8 4 7 2 1 2 6 2 4 6 3", "output": "10" }, { "input": "7\n2 2 1\n4 1 4 2 3 1 2\n3 3 1 3 2\n5 1 4 3 5 1 2 1 3\n6 4 5 1 3 4 2 3 6 5 1\n7 1 3 3 6 7 4 7 1 5 2 3 5\n10 6 8 2 6 6 3 2 7 2 4 6 10 3 1 6 5 6 9", "output": "23" }, { "input": "10\n3 1 2 1 3\n3 1 2 1 3\n7 1 2 1 3 3 4 7 5 1 6 5 1\n2 1 2\n4 4 3 3 1 4 2\n3 3 1 3 2\n5 4 2 5 1 3 5 3 4\n6 1 6 2 4 6 2 4 3 5 1\n7 2 4 4 6 7 3 3 1 3 5 2 7\n10 3 5 5 6 1 9 5 2 7 8 8 1 6 10 4 3 4 7", "output": "36" }, { "input": "7\n4 2 3 4 1 2 4\n4 4 3 2 1 3 2\n3 2 1 2 3\n5 5 4 1 5 1 2 2 3\n6 1 3 4 5 2 6 3 2 1 4\n7 6 4 4 7 6 2 6 3 3 1 6 5\n10 8 10 4 8 5 9 5 6 3 4 3 1 5 3 4 7 1 2", "output": "26" }, { "input": "7\n2 1 2\n4 4 1 1 2 4 3\n3 3 2 2 1\n5 4 1 1 5 4 3 1 2\n6 4 2 3 1 3 4 3 5 3 6\n8 7 4 6 2 6 7 4 5 4 1 1 3 6 8\n10 4 1 8 9 7 8 2 4 8 6 6 5 2 7 8 3 7 10", "output": "23" }, { "input": "3\n4 3 2 3 1 1 4\n4 3 1 2 4 3 2\n4 1 4 2 1 4 3", "output": "9" }, { "input": "3\n10 7 3 10 9 7 10 4 7 8 6 8 2 4 8 8 5 5 1\n12 10 3 11 4 11 9 12 1 10 12 8 7 8 11 6 5 10 6 10 2 6 8\n13 3 7 10 4 3 8 3 1 8 5 4 12 9 2 8 6 10 9 1 10 10 11 4 13", "output": "18" }, { "input": "4\n5 3 2 3 5 4 1 4 3\n6 6 4 1 2 2 3 2 6 6 5\n7 6 1 6 4 4 5 1 7 4 3 2 6\n8 2 1 6 8 4 5 8 3 4 7 4 2 2 6", "output": "15" }, { "input": "2\n10 8 1 6 7 10 8 7 5 3 4 5 3 9 2 6 9 2 10\n10 9 7 6 1 8 10 6 4 8 3 9 2 3 5 8 9 3 6", "output": "14" }, { "input": "6\n3 1 3 1 2\n3 2 1 3 2\n5 2 5 5 1 2 3 2 4\n4 2 3 2 4 1 2\n5 2 3 2 1 3 5 2 4\n5 3 5 2 3 5 1 4 2", "output": "16" }, { "input": "1\n50 4 37 49 41 40 10 23 14 35 3 39 46 40 8 11 35 32 17 3 7 25 47 17 27 49 1 28 9 6 38 41 29 22 13 38 16 4 48 4 21 13 23 49 30 35 44 25 34 25 18 31 50 21 6 32 19 19 28 22 42 39 25 22 26 21 40 21 33 21 39 14 43 3 15 17 2 19 12 26 24 28 5 22 11 4 20 10 45 48 36 4 22 4 32 4 31 39 49", "output": "10" }, { "input": "4\n10 9 5 9 7 7 6 7 2 1 4 9 1 7 3 2 10 3 8\n10 9 10 2 5 3 6 5 7 9 3 9 1 9 2 2 8 2 4\n10 5 3 2 5 1 6 6 8 3 9 3 10 5 1 8 4 3 7\n10 7 6 3 1 8 10 2 3 2 7 5 9 10 5 1 4 2 8", "output": "23" } ]
1,580,547,716
6,416
PyPy 3
OK
TESTS
30
872
7,065,600
from queue import Queue def bfs(v, g, m): q = Queue() visit = [False] * m visit[v] = True q.put((v, 0)) last = v, 0 while not q.empty(): v, l = q.get() for i in g[v]: if not visit[i]: q.put((i, l + 1)) visit[i] = True if q.empty(): last = v, l return last fin = ''.join(open('input.txt', 'r').readlines()).split('\n') fout = open('output.txt', 'w') n = int(fin[0]) res = 0 for i in range(n): mas = [int(j) for j in fin[1 + i].split()] g = {} for j in range(mas[0] - 1): a, b = mas[1 + j * 2] - 1, mas[2 + j * 2] - 1 g[a] = g.get(a, []) g[b] = g.get(b, []) g[a].append(b) g[b].append(a) _, dist = bfs(bfs(0, g, mas[0])[0], g, mas[0]) res += dist fout.write(str(res))
Title: Spiders Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day mum asked Petya to sort his toys and get rid of some of them. Petya found a whole box of toy spiders. They were quite dear to him and the boy didn't want to throw them away. Petya conjured a cunning plan: he will glue all the spiders together and attach them to the ceiling. Besides, Petya knows that the lower the spiders will hang, the more mum is going to like it and then she won't throw his favourite toys away. Help Petya carry out the plan. A spider consists of *k* beads tied together by *k*<=-<=1 threads. Each thread connects two different beads, at that any pair of beads that make up a spider is either directly connected by a thread, or is connected via some chain of threads and beads. Petya may glue spiders together directly gluing their beads. The length of each thread equals 1. The sizes of the beads can be neglected. That's why we can consider that gluing spiders happens by identifying some of the beads (see the picture). Besides, the construction resulting from the gluing process should also represent a spider, that is, it should have the given features. After Petya glues all spiders together, he measures the length of the resulting toy. The distance between a pair of beads is identified as the total length of the threads that connect these two beads. The length of the resulting construction is the largest distance between all pairs of beads. Petya wants to make the spider whose length is as much as possible. The picture two shows two spiders from the second sample. We can glue to the bead number 2 of the first spider the bead number 1 of the second spider. The threads in the spiders that form the sequence of threads of maximum lengths are highlighted on the picture. Input Specification: The first input file line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of spiders. Next *n* lines contain the descriptions of each spider: integer *n**i* (2<=≤<=*n**i*<=≤<=100) — the number of beads, then *n**i*<=-<=1 pairs of numbers denoting the numbers of the beads connected by threads. The beads that make up each spider are numbered from 1 to *n**i*. Output Specification: Print a single number — the length of the required construction. Demo Input: ['1\n3 1 2 2 3\n', '2\n3 1 2 1 3\n4 1 2 2 3 2 4\n', '2\n5 1 2 2 3 3 4 3 5\n7 3 4 1 2 2 4 4 6 2 7 6 5\n'] Demo Output: ['2\n', '4\n', '7\n'] Note: none
```python from queue import Queue def bfs(v, g, m): q = Queue() visit = [False] * m visit[v] = True q.put((v, 0)) last = v, 0 while not q.empty(): v, l = q.get() for i in g[v]: if not visit[i]: q.put((i, l + 1)) visit[i] = True if q.empty(): last = v, l return last fin = ''.join(open('input.txt', 'r').readlines()).split('\n') fout = open('output.txt', 'w') n = int(fin[0]) res = 0 for i in range(n): mas = [int(j) for j in fin[1 + i].split()] g = {} for j in range(mas[0] - 1): a, b = mas[1 + j * 2] - 1, mas[2 + j * 2] - 1 g[a] = g.get(a, []) g[b] = g.get(b, []) g[a].append(b) g[b].append(a) _, dist = bfs(bfs(0, g, mas[0])[0], g, mas[0]) res += dist fout.write(str(res)) ```
3
59
A
Word
PROGRAMMING
800
[ "implementation", "strings" ]
A. Word
2
256
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word.
The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
[ "HoUse\n", "ViP\n", "maTRIx\n" ]
[ "house\n", "VIP\n", "matrix\n" ]
none
500
[ { "input": "HoUse", "output": "house" }, { "input": "ViP", "output": "VIP" }, { "input": "maTRIx", "output": "matrix" }, { "input": "BNHWpnpawg", "output": "bnhwpnpawg" }, { "input": "VTYGP", "output": "VTYGP" }, { "input": "CHNenu", "output": "chnenu" }, { "input": "ERPZGrodyu", "output": "erpzgrodyu" }, { "input": "KSXBXWpebh", "output": "KSXBXWPEBH" }, { "input": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv", "output": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv" }, { "input": "Amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd", "output": "amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd" }, { "input": "ISAGFJFARYFBLOPQDSHWGMCNKMFTLVFUGNJEWGWNBLXUIATXEkqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv", "output": "isagfjfaryfblopqdshwgmcnkmftlvfugnjewgwnblxuiatxekqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv" }, { "input": "XHRPXZEGHSOCJPICUIXSKFUZUPYTSGJSDIYBCMNMNBPNDBXLXBzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg", "output": "xhrpxzeghsocjpicuixskfuzupytsgjsdiybcmnmnbpndbxlxbzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg" }, { "input": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGAdkcetqjljtmttlonpekcovdzebzdkzggwfsxhapmjkdbuceak", "output": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGADKCETQJLJTMTTLONPEKCOVDZEBZDKZGGWFSXHAPMJKDBUCEAK" }, { "input": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFw", "output": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFW" }, { "input": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB", "output": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB" }, { "input": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge", "output": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge" }, { "input": "Ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw", "output": "ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw" }, { "input": "YQOMLKYAORUQQUCQZCDYMIVDHGWZFFRMUVTAWCHERFPMNRYRIkgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks", "output": "yqomlkyaoruqqucqzcdymivdhgwzffrmuvtawcherfpmnryrikgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks" }, { "input": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJcuusigdqfkumewjtdyitveeiaybwrhomrwmpdipjwiuxfnwuz", "output": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJCUUSIGDQFKUMEWJTDYITVEEIAYBWRHOMRWMPDIPJWIUXFNWUZ" }, { "input": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWuckzcpxosodcjaaakvlxpbiigsiauviilylnnqlyucziihqg", "output": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWUCKZCPXOSODCJAAAKVLXPBIIGSIAUVIILYLNNQLYUCZIIHQG" }, { "input": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO", "output": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO" }, { "input": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDd", "output": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDD" }, { "input": "EBWOVSNLYTWWXrnovgugogtjahnmatomubebyxakas", "output": "ebwovsnlytwwxrnovgugogtjahnmatomubebyxakas" }, { "input": "AORNNDKTRLRVGDPXJKXFTPFpopuzrlqumrxssskvbm", "output": "AORNNDKTRLRVGDPXJKXFTPFPOPUZRLQUMRXSSSKVBM" }, { "input": "DBBZJCWQEVGYHEEUHJAWRHBDPsnplijbwtdibqrrheebfxqcvn", "output": "dbbzjcwqevgyheeuhjawrhbdpsnplijbwtdibqrrheebfxqcvn" }, { "input": "t", "output": "t" }, { "input": "N", "output": "N" }, { "input": "kv", "output": "kv" }, { "input": "Ur", "output": "ur" }, { "input": "CN", "output": "CN" } ]
1,592,532,124
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
0
248
0
a=input() for i in a: print('i.lower(),end=''')
Title: Word Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word. Input Specification: The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. Output Specification: Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. Demo Input: ['HoUse\n', 'ViP\n', 'maTRIx\n'] Demo Output: ['house\n', 'VIP\n', 'matrix\n'] Note: none
```python a=input() for i in a: print('i.lower(),end=''') ```
0
361
A
Levko and Table
PROGRAMMING
800
[ "constructive algorithms", "implementation" ]
null
null
Levko loves tables that consist of *n* rows and *n* columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals *k*. Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them.
The single line contains two integers, *n* and *k* (1<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=1000).
Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value. If there are multiple suitable tables, you are allowed to print any of them.
[ "2 4\n", "4 7\n" ]
[ "1 3\n3 1\n", "2 1 0 4\n4 0 2 1\n1 3 3 0\n0 3 2 2\n" ]
In the first sample the sum in the first row is 1 + 3 = 4, in the second row — 3 + 1 = 4, in the first column — 1 + 3 = 4 and in the second column — 3 + 1 = 4. There are other beautiful tables for this sample. In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements.
500
[ { "input": "2 4", "output": "4 0 \n0 4 " }, { "input": "4 7", "output": "7 0 0 0 \n0 7 0 0 \n0 0 7 0 \n0 0 0 7 " }, { "input": "1 8", "output": "8 " }, { "input": "9 3", "output": "3 0 0 0 0 0 0 0 0 \n0 3 0 0 0 0 0 0 0 \n0 0 3 0 0 0 0 0 0 \n0 0 0 3 0 0 0 0 0 \n0 0 0 0 3 0 0 0 0 \n0 0 0 0 0 3 0 0 0 \n0 0 0 0 0 0 3 0 0 \n0 0 0 0 0 0 0 3 0 \n0 0 0 0 0 0 0 0 3 " }, { "input": "31 581", "output": "581 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 581 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 581 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 581 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 581 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 581 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 0 581 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 0 0 581 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..." }, { "input": "100 1000", "output": "1000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 1000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 1000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ..." }, { "input": "100 999", "output": "999 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 999 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 999 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..." }, { "input": "99 998", "output": "998 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 998 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 998 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..." }, { "input": "100 997", "output": "997 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 997 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 997 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..." }, { "input": "81 111", "output": "111 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 111 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 111 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 111 0 0..." }, { "input": "1 407", "output": "407 " }, { "input": "54 341", "output": "341 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 341 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 341 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 341 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 341 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..." }, { "input": "92 460", "output": "460 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 460 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 460 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..." }, { "input": "34 47", "output": "47 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 47 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 47 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 47 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 47 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 47 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 0 47 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 0 0 ..." }, { "input": "11 547", "output": "547 0 0 0 0 0 0 0 0 0 0 \n0 547 0 0 0 0 0 0 0 0 0 \n0 0 547 0 0 0 0 0 0 0 0 \n0 0 0 547 0 0 0 0 0 0 0 \n0 0 0 0 547 0 0 0 0 0 0 \n0 0 0 0 0 547 0 0 0 0 0 \n0 0 0 0 0 0 547 0 0 0 0 \n0 0 0 0 0 0 0 547 0 0 0 \n0 0 0 0 0 0 0 0 547 0 0 \n0 0 0 0 0 0 0 0 0 547 0 \n0 0 0 0 0 0 0 0 0 0 547 " }, { "input": "100 1", "output": "1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..." }, { "input": "99 1", "output": "1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..." }, { "input": "99 2", "output": "2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..." }, { "input": "2 7", "output": "7 0 \n0 7 " }, { "input": "100 100", "output": "100 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 100 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 100 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..." }, { "input": "4 3", "output": "3 0 0 0 \n0 3 0 0 \n0 0 3 0 \n0 0 0 3 " }, { "input": "3 2", "output": "2 0 0 \n0 2 0 \n0 0 2 " } ]
1,598,160,998
2,147,483,647
Python 3
OK
TESTS
22
109
7,065,600
import sys def input(): return sys.stdin.readline().strip() def iinput(): return int(input()) def rinput(): return map(int, sys.stdin.readline().strip().split()) def get_list(): return list(map(int, sys.stdin.readline().strip().split())) n,k=rinput() a=[] for i in range(n): for j in range(n): if(i==j): a.append(k) else: a.append(0) for i in range(0,n*n+1,n): print(*a[i:n+i])
Title: Levko and Table Time Limit: None seconds Memory Limit: None megabytes Problem Description: Levko loves tables that consist of *n* rows and *n* columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals *k*. Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them. Input Specification: The single line contains two integers, *n* and *k* (1<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=1000). Output Specification: Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value. If there are multiple suitable tables, you are allowed to print any of them. Demo Input: ['2 4\n', '4 7\n'] Demo Output: ['1 3\n3 1\n', '2 1 0 4\n4 0 2 1\n1 3 3 0\n0 3 2 2\n'] Note: In the first sample the sum in the first row is 1 + 3 = 4, in the second row — 3 + 1 = 4, in the first column — 1 + 3 = 4 and in the second column — 3 + 1 = 4. There are other beautiful tables for this sample. In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements.
```python import sys def input(): return sys.stdin.readline().strip() def iinput(): return int(input()) def rinput(): return map(int, sys.stdin.readline().strip().split()) def get_list(): return list(map(int, sys.stdin.readline().strip().split())) n,k=rinput() a=[] for i in range(n): for j in range(n): if(i==j): a.append(k) else: a.append(0) for i in range(0,n*n+1,n): print(*a[i:n+i]) ```
3
300
A
Array
PROGRAMMING
1,100
[ "brute force", "constructive algorithms", "implementation" ]
null
null
Vitaly has an array of *n* distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold: 1. The product of all numbers in the first set is less than zero (<=&lt;<=0). 1. The product of all numbers in the second set is greater than zero (<=&gt;<=0). 1. The product of all numbers in the third set is equal to zero. 1. Each number from the initial array must occur in exactly one set. Help Vitaly. Divide the given array.
The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=100). The second line contains *n* space-separated distinct integers *a*1,<=*a*2,<=...,<=*a**n* (|*a**i*|<=≤<=103) — the array elements.
In the first line print integer *n*1 (*n*1<=&gt;<=0) — the number of elements in the first set. Then print *n*1 numbers — the elements that got to the first set. In the next line print integer *n*2 (*n*2<=&gt;<=0) — the number of elements in the second set. Then print *n*2 numbers — the elements that got to the second set. In the next line print integer *n*3 (*n*3<=&gt;<=0) — the number of elements in the third set. Then print *n*3 numbers — the elements that got to the third set. The printed sets must meet the described conditions. It is guaranteed that the solution exists. If there are several solutions, you are allowed to print any of them.
[ "3\n-1 2 0\n", "4\n-1 -2 -3 0\n" ]
[ "1 -1\n1 2\n1 0\n", "1 -1\n2 -3 -2\n1 0\n" ]
none
500
[ { "input": "3\n-1 2 0", "output": "1 -1\n1 2\n1 0" }, { "input": "4\n-1 -2 -3 0", "output": "1 -1\n2 -3 -2\n1 0" }, { "input": "5\n-1 -2 1 2 0", "output": "1 -1\n2 1 2\n2 0 -2" }, { "input": "100\n-64 -51 -75 -98 74 -26 -1 -8 -99 -76 -53 -80 -43 -22 -100 -62 -34 -5 -65 -81 -18 -91 -92 -16 -23 -95 -9 -19 -44 -46 -79 52 -35 4 -87 -7 -90 -20 -71 -61 -67 -50 -66 -68 -49 -27 -32 -57 -85 -59 -30 -36 -3 -77 86 -25 -94 -56 60 -24 -37 -72 -41 -31 11 -48 28 -38 -42 -39 -33 -70 -84 0 -93 -73 -14 -69 -40 -97 -6 -55 -45 -54 -10 -29 -96 -12 -83 -15 -21 -47 17 -2 -63 -89 88 13 -58 -82", "output": "89 -64 -51 -75 -98 -26 -1 -8 -99 -76 -53 -80 -43 -22 -100 -62 -34 -5 -65 -81 -18 -91 -92 -16 -23 -95 -9 -19 -44 -46 -79 -35 -87 -7 -90 -20 -71 -61 -67 -50 -66 -68 -49 -27 -32 -57 -85 -59 -30 -36 -3 -77 -25 -94 -56 -24 -37 -72 -41 -31 -48 -38 -42 -39 -33 -70 -84 -93 -73 -14 -69 -40 -97 -6 -55 -45 -54 -10 -29 -96 -12 -83 -15 -21 -47 -2 -63 -89 -58 -82\n10 74 52 4 86 60 11 28 17 88 13\n1 0" }, { "input": "100\n3 -66 -17 54 24 -29 76 89 32 -37 93 -16 99 -25 51 78 23 68 -95 59 18 34 -45 77 9 39 -10 19 8 73 -5 60 12 31 0 2 26 40 48 30 52 49 27 4 87 57 85 58 -61 50 83 80 69 67 91 97 -96 11 100 56 82 53 13 -92 -72 70 1 -94 -63 47 21 14 74 7 6 33 55 65 64 -41 81 42 36 28 38 20 43 71 90 -88 22 84 -86 15 75 62 44 35 98 46", "output": "19 -66 -17 -29 -37 -16 -25 -95 -45 -10 -5 -61 -96 -92 -72 -94 -63 -41 -88 -86\n80 3 54 24 76 89 32 93 99 51 78 23 68 59 18 34 77 9 39 19 8 73 60 12 31 2 26 40 48 30 52 49 27 4 87 57 85 58 50 83 80 69 67 91 97 11 100 56 82 53 13 70 1 47 21 14 74 7 6 33 55 65 64 81 42 36 28 38 20 43 71 90 22 84 15 75 62 44 35 98 46\n1 0" }, { "input": "100\n-17 16 -70 32 -60 75 -100 -9 -68 -30 -42 86 -88 -98 -47 -5 58 -14 -94 -73 -80 -51 -66 -85 -53 49 -25 -3 -45 -69 -11 -64 83 74 -65 67 13 -91 81 6 -90 -54 -12 -39 0 -24 -71 -41 -44 57 -93 -20 -92 18 -43 -52 -55 -84 -89 -19 40 -4 -99 -26 -87 -36 -56 -61 -62 37 -95 -28 63 23 35 -82 1 -2 -78 -96 -21 -77 -76 -27 -10 -97 -8 46 -15 -48 -34 -59 -7 -29 50 -33 -72 -79 22 38", "output": "75 -17 -70 -60 -100 -9 -68 -30 -42 -88 -98 -47 -5 -14 -94 -73 -80 -51 -66 -85 -53 -25 -3 -45 -69 -11 -64 -65 -91 -90 -54 -12 -39 -24 -71 -41 -44 -93 -20 -92 -43 -52 -55 -84 -89 -19 -4 -99 -26 -87 -36 -56 -61 -62 -95 -28 -82 -2 -78 -96 -21 -77 -76 -27 -10 -97 -8 -15 -48 -34 -59 -7 -29 -33 -72 -79\n24 16 32 75 86 58 49 83 74 67 13 81 6 57 18 40 37 63 23 35 1 46 50 22 38\n1 0" }, { "input": "100\n-97 -90 61 78 87 -52 -3 65 83 38 30 -60 35 -50 -73 -77 44 -32 -81 17 -67 58 -6 -34 47 -28 71 -45 69 -80 -4 -7 -57 -79 43 -27 -31 29 16 -89 -21 -93 95 -82 74 -5 -70 -20 -18 36 -64 -66 72 53 62 -68 26 15 76 -40 -99 8 59 88 49 -23 9 10 56 -48 -98 0 100 -54 25 94 13 -63 42 39 -1 55 24 -12 75 51 41 84 -96 -85 -2 -92 14 -46 -91 -19 -11 -86 22 -37", "output": "51 -97 -90 -52 -3 -60 -50 -73 -77 -32 -81 -67 -6 -34 -28 -45 -80 -4 -7 -57 -79 -27 -31 -89 -21 -93 -82 -5 -70 -20 -18 -64 -66 -68 -40 -99 -23 -48 -98 -54 -63 -1 -12 -96 -85 -2 -92 -46 -91 -19 -11 -86\n47 61 78 87 65 83 38 30 35 44 17 58 47 71 69 43 29 16 95 74 36 72 53 62 26 15 76 8 59 88 49 9 10 56 100 25 94 13 42 39 55 24 75 51 41 84 14 22\n2 0 -37" }, { "input": "100\n-75 -60 -18 -92 -71 -9 -37 -34 -82 28 -54 93 -83 -76 -58 -88 -17 -97 64 -39 -96 -81 -10 -98 -47 -100 -22 27 14 -33 -19 -99 87 -66 57 -21 -90 -70 -32 -26 24 -77 -74 13 -44 16 -5 -55 -2 -6 -7 -73 -1 -68 -30 -95 -42 69 0 -20 -79 59 -48 -4 -72 -67 -46 62 51 -52 -86 -40 56 -53 85 -35 -8 49 50 65 29 11 -43 -15 -41 -12 -3 -80 -31 -38 -91 -45 -25 78 94 -23 -63 84 89 -61", "output": "73 -75 -60 -18 -92 -71 -9 -37 -34 -82 -54 -83 -76 -58 -88 -17 -97 -39 -96 -81 -10 -98 -47 -100 -22 -33 -19 -99 -66 -21 -90 -70 -32 -26 -77 -74 -44 -5 -55 -2 -6 -7 -73 -1 -68 -30 -95 -42 -20 -79 -48 -4 -72 -67 -46 -52 -86 -40 -53 -35 -8 -43 -15 -41 -12 -3 -80 -31 -38 -91 -45 -25 -23 -63\n25 28 93 64 27 14 87 57 24 13 16 69 59 62 51 56 85 49 50 65 29 11 78 94 84 89\n2 0 -61" }, { "input": "100\n-87 -48 -76 -1 -10 -17 -22 -19 -27 -99 -43 49 38 -20 -45 -64 44 -96 -35 -74 -65 -41 -21 -75 37 -12 -67 0 -3 5 -80 -93 -81 -97 -47 -63 53 -100 95 -79 -83 -90 -32 88 -77 -16 -23 -54 -28 -4 -73 -98 -25 -39 60 -56 -34 -2 -11 -55 -52 -69 -68 -29 -82 -62 -36 -13 -6 -89 8 -72 18 -15 -50 -71 -70 -92 -42 -78 -61 -9 -30 -85 -91 -94 84 -86 -7 -57 -14 40 -33 51 -26 46 59 -31 -58 -66", "output": "83 -87 -48 -76 -1 -10 -17 -22 -19 -27 -99 -43 -20 -45 -64 -96 -35 -74 -65 -41 -21 -75 -12 -67 -3 -80 -93 -81 -97 -47 -63 -100 -79 -83 -90 -32 -77 -16 -23 -54 -28 -4 -73 -98 -25 -39 -56 -34 -2 -11 -55 -52 -69 -68 -29 -82 -62 -36 -13 -6 -89 -72 -15 -50 -71 -70 -92 -42 -78 -61 -9 -30 -85 -91 -94 -86 -7 -57 -14 -33 -26 -31 -58 -66\n16 49 38 44 37 5 53 95 88 60 8 18 84 40 51 46 59\n1 0" }, { "input": "100\n-95 -28 -43 -72 -11 -24 -37 -35 -44 -66 -45 -62 -96 -51 -55 -23 -31 -26 -59 -17 77 -69 -10 -12 -78 -14 -52 -57 -40 -75 4 -98 -6 7 -53 -3 -90 -63 -8 -20 88 -91 -32 -76 -80 -97 -34 -27 -19 0 70 -38 -9 -49 -67 73 -36 2 81 -39 -65 -83 -64 -18 -94 -79 -58 -16 87 -22 -74 -25 -13 -46 -89 -47 5 -15 -54 -99 56 -30 -60 -21 -86 33 -1 -50 -68 -100 -85 -29 92 -48 -61 42 -84 -93 -41 -82", "output": "85 -95 -28 -43 -72 -11 -24 -37 -35 -44 -66 -45 -62 -96 -51 -55 -23 -31 -26 -59 -17 -69 -10 -12 -78 -14 -52 -57 -40 -75 -98 -6 -53 -3 -90 -63 -8 -20 -91 -32 -76 -80 -97 -34 -27 -19 -38 -9 -49 -67 -36 -39 -65 -83 -64 -18 -94 -79 -58 -16 -22 -74 -25 -13 -46 -89 -47 -15 -54 -99 -30 -60 -21 -86 -1 -50 -68 -100 -85 -29 -48 -61 -84 -93 -41 -82\n14 77 4 7 88 70 73 2 81 87 5 56 33 92 42\n1 0" }, { "input": "100\n-12 -41 57 13 83 -36 53 69 -6 86 -75 87 11 -5 -4 -14 -37 -84 70 2 -73 16 31 34 -45 94 -9 26 27 52 -42 46 96 21 32 7 -18 61 66 -51 95 -48 -76 90 80 -40 89 77 78 54 -30 8 88 33 -24 82 -15 19 1 59 44 64 -97 -60 43 56 35 47 39 50 29 28 -17 -67 74 23 85 -68 79 0 65 55 -3 92 -99 72 93 -71 38 -10 -100 -98 81 62 91 -63 -58 49 -20 22", "output": "35 -12 -41 -36 -6 -75 -5 -4 -14 -37 -84 -73 -45 -9 -42 -18 -51 -48 -76 -40 -30 -24 -15 -97 -60 -17 -67 -68 -3 -99 -71 -10 -100 -98 -63 -58\n63 57 13 83 53 69 86 87 11 70 2 16 31 34 94 26 27 52 46 96 21 32 7 61 66 95 90 80 89 77 78 54 8 88 33 82 19 1 59 44 64 43 56 35 47 39 50 29 28 74 23 85 79 65 55 92 72 93 38 81 62 91 49 22\n2 0 -20" }, { "input": "100\n-34 81 85 -96 50 20 54 86 22 10 -19 52 65 44 30 53 63 71 17 98 -92 4 5 -99 89 -23 48 9 7 33 75 2 47 -56 42 70 -68 57 51 83 82 94 91 45 46 25 95 11 -12 62 -31 -87 58 38 67 97 -60 66 73 -28 13 93 29 59 -49 77 37 -43 -27 0 -16 72 15 79 61 78 35 21 3 8 84 1 -32 36 74 -88 26 100 6 14 40 76 18 90 24 69 80 64 55 41", "output": "19 -34 -96 -19 -92 -99 -23 -56 -68 -12 -31 -87 -60 -28 -49 -43 -27 -16 -32 -88\n80 81 85 50 20 54 86 22 10 52 65 44 30 53 63 71 17 98 4 5 89 48 9 7 33 75 2 47 42 70 57 51 83 82 94 91 45 46 25 95 11 62 58 38 67 97 66 73 13 93 29 59 77 37 72 15 79 61 78 35 21 3 8 84 1 36 74 26 100 6 14 40 76 18 90 24 69 80 64 55 41\n1 0" }, { "input": "100\n-1000 -986 -979 -955 -966 -963 -973 -959 -972 -906 -924 -927 -929 -918 -977 -967 -921 -989 -911 -995 -945 -919 -971 -913 -912 -933 -969 -975 -920 -988 -997 -994 -953 -962 -940 -905 -978 -948 -957 -996 0 -976 -949 -931 -903 -985 -923 -993 -944 -909 -938 -946 -934 -992 -904 -980 -954 -943 -917 -968 -991 -956 -902 -942 -999 -998 -908 -928 -930 -914 -922 -936 -960 -937 -939 -926 -965 -925 -951 -910 -907 -970 -990 -984 -964 -987 -916 -947 -982 -950 -974 -915 -932 -958 -981 -941 -961 -983 -952 -935", "output": "97 -1000 -986 -979 -955 -966 -963 -973 -959 -972 -906 -924 -927 -929 -918 -977 -967 -921 -989 -911 -995 -945 -919 -971 -913 -912 -933 -969 -975 -920 -988 -997 -994 -953 -962 -940 -905 -978 -948 -957 -996 -976 -949 -931 -903 -985 -923 -993 -944 -909 -938 -946 -934 -992 -904 -980 -954 -943 -917 -968 -991 -956 -902 -942 -999 -998 -908 -928 -930 -914 -922 -936 -960 -937 -939 -926 -965 -925 -951 -910 -907 -970 -990 -984 -964 -987 -916 -947 -982 -950 -974 -915 -932 -958 -981 -941 -961 -983\n2 -935 -952\n1 0" }, { "input": "99\n-1000 -986 -979 -955 -966 -963 -973 -959 -972 -906 -924 -927 -929 -918 -977 -967 -921 -989 -911 -995 -945 -919 -971 -913 -912 -933 -969 -975 -920 -988 -997 -994 -953 -962 -940 -905 -978 -948 -957 -996 0 -976 -949 -931 -903 -985 -923 -993 -944 -909 -938 -946 -934 -992 -904 -980 -954 -943 -917 -968 -991 -956 -902 -942 -999 -998 -908 -928 -930 -914 -922 -936 -960 -937 -939 -926 -965 -925 -951 -910 -907 -970 -990 -984 -964 -987 -916 -947 -982 -950 -974 -915 -932 -958 -981 -941 -961 -983 -952", "output": "95 -1000 -986 -979 -955 -966 -963 -973 -959 -972 -906 -924 -927 -929 -918 -977 -967 -921 -989 -911 -995 -945 -919 -971 -913 -912 -933 -969 -975 -920 -988 -997 -994 -953 -962 -940 -905 -978 -948 -957 -996 -976 -949 -931 -903 -985 -923 -993 -944 -909 -938 -946 -934 -992 -904 -980 -954 -943 -917 -968 -991 -956 -902 -942 -999 -998 -908 -928 -930 -914 -922 -936 -960 -937 -939 -926 -965 -925 -951 -910 -907 -970 -990 -984 -964 -987 -916 -947 -982 -950 -974 -915 -932 -958 -981 -941\n2 -952 -983\n2 0 -961" }, { "input": "59\n-990 -876 -641 -726 718 -53 803 -954 894 -265 -587 -665 904 349 754 -978 441 794 -768 -428 -569 -476 188 -620 -290 -333 45 705 -201 109 165 446 13 122 714 -562 -15 -86 -960 43 329 578 287 -776 -14 -71 915 886 -259 337 -495 913 -498 -669 -673 818 225 647 0", "output": "29 -990 -876 -641 -726 -53 -954 -265 -587 -665 -978 -768 -428 -569 -476 -620 -290 -333 -201 -562 -15 -86 -960 -776 -14 -71 -259 -495 -498 -669\n28 718 803 894 904 349 754 441 794 188 45 705 109 165 446 13 122 714 43 329 578 287 915 886 337 913 818 225 647\n2 0 -673" }, { "input": "64\n502 885 -631 -906 735 687 642 -29 -696 -165 -524 15 -129 -663 -846 -501 -651 895 -341 -833 -142 33 -847 688 945 -192 -587 -930 603 849 736 676 788 256 863 -509 319 -49 -807 -158 218 -886 -143 -639 118 -156 -291 325 892 -916 -622 -960 -959 -731 -943 436 -535 861 745 589 -159 376 -182 0", "output": "35 -631 -906 -29 -696 -165 -524 -129 -663 -846 -501 -651 -341 -833 -142 -847 -192 -587 -930 -509 -49 -807 -158 -886 -143 -639 -156 -291 -916 -622 -960 -959 -731 -943 -535 -159\n27 502 885 735 687 642 15 895 33 688 945 603 849 736 676 788 256 863 319 218 118 325 892 436 861 745 589 376\n2 0 -182" }, { "input": "5\n-1 -2 -3 -4 0", "output": "1 -1\n2 -4 -3\n2 0 -2" }, { "input": "3\n-101 101 0", "output": "1 -101\n1 101\n1 0" }, { "input": "21\n-100 -200 -300 -400 -500 -600 -700 -800 -900 -1000 0 100 200 300 400 500 600 700 800 900 1000", "output": "9 -100 -200 -300 -400 -500 -600 -700 -800 -900\n10 100 200 300 400 500 600 700 800 900 1000\n2 0 -1000" }, { "input": "4\n0 -1 -2 -3", "output": "1 -1\n2 -3 -2\n1 0" } ]
1,675,623,618
2,147,483,647
Python 3
OK
TESTS
20
92
0
n = int(input()) num_arr = list(map(int, input().split())) arr_neg = [] arr_pos = [] arr_zero = [] num_neg = 1 ind = 0 while len(arr_neg)==0: if num_arr[ind]<0: arr_neg.append(num_arr[ind]) num_arr.pop(ind) ind+=1 num_pos = 0 for elem in num_arr: if elem > 0: arr_pos.append(elem) num_arr.remove(elem) num_pos+=1 if num_pos == 0: count_neg = 0 for elem in num_arr: if elem < 0 and count_neg!=2: arr_pos.append(elem) num_pos+=1 count_neg+=1 for elem in arr_pos: num_arr.remove(elem) num_zero = 0 for elem in num_arr: arr_zero.append(elem) num_zero+=1 print(num_neg, *arr_neg) print(num_pos, *arr_pos) print(num_zero, *arr_zero)
Title: Array Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vitaly has an array of *n* distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold: 1. The product of all numbers in the first set is less than zero (<=&lt;<=0). 1. The product of all numbers in the second set is greater than zero (<=&gt;<=0). 1. The product of all numbers in the third set is equal to zero. 1. Each number from the initial array must occur in exactly one set. Help Vitaly. Divide the given array. Input Specification: The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=100). The second line contains *n* space-separated distinct integers *a*1,<=*a*2,<=...,<=*a**n* (|*a**i*|<=≤<=103) — the array elements. Output Specification: In the first line print integer *n*1 (*n*1<=&gt;<=0) — the number of elements in the first set. Then print *n*1 numbers — the elements that got to the first set. In the next line print integer *n*2 (*n*2<=&gt;<=0) — the number of elements in the second set. Then print *n*2 numbers — the elements that got to the second set. In the next line print integer *n*3 (*n*3<=&gt;<=0) — the number of elements in the third set. Then print *n*3 numbers — the elements that got to the third set. The printed sets must meet the described conditions. It is guaranteed that the solution exists. If there are several solutions, you are allowed to print any of them. Demo Input: ['3\n-1 2 0\n', '4\n-1 -2 -3 0\n'] Demo Output: ['1 -1\n1 2\n1 0\n', '1 -1\n2 -3 -2\n1 0\n'] Note: none
```python n = int(input()) num_arr = list(map(int, input().split())) arr_neg = [] arr_pos = [] arr_zero = [] num_neg = 1 ind = 0 while len(arr_neg)==0: if num_arr[ind]<0: arr_neg.append(num_arr[ind]) num_arr.pop(ind) ind+=1 num_pos = 0 for elem in num_arr: if elem > 0: arr_pos.append(elem) num_arr.remove(elem) num_pos+=1 if num_pos == 0: count_neg = 0 for elem in num_arr: if elem < 0 and count_neg!=2: arr_pos.append(elem) num_pos+=1 count_neg+=1 for elem in arr_pos: num_arr.remove(elem) num_zero = 0 for elem in num_arr: arr_zero.append(elem) num_zero+=1 print(num_neg, *arr_neg) print(num_pos, *arr_pos) print(num_zero, *arr_zero) ```
3
155
A
I_love_\%username\%
PROGRAMMING
800
[ "brute force" ]
null
null
Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him. One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For each contest where this coder participated, he wrote out a single non-negative number — the number of points his favorite coder earned in the contest. Vasya wrote out the points for the contest in the order, in which the contests run (naturally, no two contests ran simultaneously). Vasya considers a coder's performance in a contest amazing in two situations: he can break either his best or his worst performance record. First, it is amazing if during the contest the coder earns strictly more points that he earned on each past contest. Second, it is amazing if during the contest the coder earns strictly less points that he earned on each past contest. A coder's first contest isn't considered amazing. Now he wants to count the number of amazing performances the coder had throughout his whole history of participating in contests. But the list of earned points turned out long and Vasya can't code... That's why he asks you to help him.
The first line contains the single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of contests where the coder participated. The next line contains *n* space-separated non-negative integer numbers — they are the points which the coder has earned. The points are given in the chronological order. All points do not exceed 10000.
Print the single number — the number of amazing performances the coder has had during his whole history of participating in the contests.
[ "5\n100 50 200 150 200\n", "10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242\n" ]
[ "2\n", "4\n" ]
In the first sample the performances number 2 and 3 are amazing. In the second sample the performances number 2, 4, 9 and 10 are amazing.
500
[ { "input": "5\n100 50 200 150 200", "output": "2" }, { "input": "10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242", "output": "4" }, { "input": "1\n6", "output": "0" }, { "input": "2\n2 1", "output": "1" }, { "input": "5\n100 36 53 7 81", "output": "2" }, { "input": "5\n7 36 53 81 100", "output": "4" }, { "input": "5\n100 81 53 36 7", "output": "4" }, { "input": "10\n8 6 3 4 9 10 7 7 1 3", "output": "5" }, { "input": "10\n1627 1675 1488 1390 1812 1137 1746 1324 1952 1862", "output": "6" }, { "input": "10\n1 3 3 4 6 7 7 8 9 10", "output": "7" }, { "input": "10\n1952 1862 1812 1746 1675 1627 1488 1390 1324 1137", "output": "9" }, { "input": "25\n1448 4549 2310 2725 2091 3509 1565 2475 2232 3989 4231 779 2967 2702 608 3739 721 1552 2767 530 3114 665 1940 48 4198", "output": "5" }, { "input": "33\n1097 1132 1091 1104 1049 1038 1023 1080 1104 1029 1035 1061 1049 1060 1088 1106 1105 1087 1063 1076 1054 1103 1047 1041 1028 1120 1126 1063 1117 1110 1044 1093 1101", "output": "5" }, { "input": "34\n821 5536 2491 6074 7216 9885 764 1603 778 8736 8987 771 617 1587 8943 7922 439 7367 4115 8886 7878 6899 8811 5752 3184 3401 9760 9400 8995 4681 1323 6637 6554 6498", "output": "7" }, { "input": "68\n6764 6877 6950 6768 6839 6755 6726 6778 6699 6805 6777 6985 6821 6801 6791 6805 6940 6761 6677 6999 6911 6699 6959 6933 6903 6843 6972 6717 6997 6756 6789 6668 6735 6852 6735 6880 6723 6834 6810 6694 6780 6679 6698 6857 6826 6896 6979 6968 6957 6988 6960 6700 6919 6892 6984 6685 6813 6678 6715 6857 6976 6902 6780 6686 6777 6686 6842 6679", "output": "9" }, { "input": "60\n9000 9014 9034 9081 9131 9162 9174 9199 9202 9220 9221 9223 9229 9235 9251 9260 9268 9269 9270 9298 9307 9309 9313 9323 9386 9399 9407 9495 9497 9529 9531 9544 9614 9615 9627 9627 9643 9654 9656 9657 9685 9699 9701 9736 9745 9758 9799 9827 9843 9845 9854 9854 9885 9891 9896 9913 9942 9963 9986 9992", "output": "57" }, { "input": "100\n7 61 12 52 41 16 34 99 30 44 48 89 31 54 21 1 48 52 61 15 35 87 21 76 64 92 44 81 16 93 84 92 32 15 68 76 53 39 26 4 11 26 7 4 99 99 61 65 55 85 65 67 47 39 2 74 63 49 98 87 5 94 22 30 25 42 31 84 49 23 89 60 16 26 92 27 9 57 75 61 94 35 83 47 99 100 63 24 91 88 79 10 15 45 22 64 3 11 89 83", "output": "4" }, { "input": "100\n9999 9999 9999 9998 9998 9998 9997 9996 9996 9995 9993 9993 9991 9990 9989 9986 9984 9984 9983 9981 9981 9980 9980 9980 9979 9977 9977 9977 9977 9977 9976 9976 9975 9975 9973 9972 9972 9972 9972 9971 9969 9969 9969 9968 9967 9965 9962 9962 9962 9962 9960 9958 9958 9955 9954 9954 9954 9954 9950 9949 9949 9947 9943 9943 9940 9940 9939 9937 9937 9937 9936 9935 9932 9932 9931 9929 9927 9927 9926 9923 9919 9919 9918 9918 9918 9917 9917 9916 9916 9915 9914 9911 9910 9907 9907 9906 9905 9905 9904 9901", "output": "57" }, { "input": "100\n158 159 157 156 155 154 160 153 161 152 162 163 151 164 150 165 149 148 147 166 146 167 145 144 143 142 168 141 169 170 140 139 138 137 171 136 135 134 172 173 174 133 175 132 177 178 131 179 180 130 129 181 128 127 182 126 183 125 124 184 123 122 121 120 119 118 117 185 186 187 188 189 116 190 115 191 192 193 114 113 112 111 110 109 108 194 195 107 106 105 196 197 104 198 199 103 102 200 101 100", "output": "99" }, { "input": "2\n0 10000", "output": "1" }, { "input": "2\n5 5", "output": "0" }, { "input": "2\n1 1", "output": "0" }, { "input": "2\n10 10", "output": "0" }, { "input": "1\n0", "output": "0" } ]
1,692,710,193
2,147,483,647
Python 3
OK
TESTS
37
92
0
t = int(input()) arr = list(map(int, input().split())) min_ = arr[0] count_ = 0 max_ = arr[0] for i in range(0, t): if arr[i] > max_: count_ += 1 max_ = arr[i] elif arr[i] < min_: min_ = arr[i] count_ += 1 elif min_ <= arr[i] <= max_: continue print(count_)
Title: I_love_\%username\% Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him. One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For each contest where this coder participated, he wrote out a single non-negative number — the number of points his favorite coder earned in the contest. Vasya wrote out the points for the contest in the order, in which the contests run (naturally, no two contests ran simultaneously). Vasya considers a coder's performance in a contest amazing in two situations: he can break either his best or his worst performance record. First, it is amazing if during the contest the coder earns strictly more points that he earned on each past contest. Second, it is amazing if during the contest the coder earns strictly less points that he earned on each past contest. A coder's first contest isn't considered amazing. Now he wants to count the number of amazing performances the coder had throughout his whole history of participating in contests. But the list of earned points turned out long and Vasya can't code... That's why he asks you to help him. Input Specification: The first line contains the single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of contests where the coder participated. The next line contains *n* space-separated non-negative integer numbers — they are the points which the coder has earned. The points are given in the chronological order. All points do not exceed 10000. Output Specification: Print the single number — the number of amazing performances the coder has had during his whole history of participating in the contests. Demo Input: ['5\n100 50 200 150 200\n', '10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242\n'] Demo Output: ['2\n', '4\n'] Note: In the first sample the performances number 2 and 3 are amazing. In the second sample the performances number 2, 4, 9 and 10 are amazing.
```python t = int(input()) arr = list(map(int, input().split())) min_ = arr[0] count_ = 0 max_ = arr[0] for i in range(0, t): if arr[i] > max_: count_ += 1 max_ = arr[i] elif arr[i] < min_: min_ = arr[i] count_ += 1 elif min_ <= arr[i] <= max_: continue print(count_) ```
3
509
A
Maximum in Table
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
An *n*<=×<=*n* table *a* is defined as follows: - The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the table is equal to the sum of the number above it and the number to the left of it. In other words, the remaining elements are defined by the formula *a**i*,<=*j*<==<=*a**i*<=-<=1,<=*j*<=+<=*a**i*,<=*j*<=-<=1. These conditions define all the values in the table. You are given a number *n*. You need to determine the maximum value in the *n*<=×<=*n* table defined by the rules above.
The only line of input contains a positive integer *n* (1<=≤<=*n*<=≤<=10) — the number of rows and columns of the table.
Print a single line containing a positive integer *m* — the maximum value in the table.
[ "1\n", "5\n" ]
[ "1", "70" ]
In the second test the rows of the table look as follows:
0
[ { "input": "1", "output": "1" }, { "input": "5", "output": "70" }, { "input": "2", "output": "2" }, { "input": "3", "output": "6" }, { "input": "4", "output": "20" }, { "input": "6", "output": "252" }, { "input": "7", "output": "924" }, { "input": "9", "output": "12870" }, { "input": "10", "output": "48620" }, { "input": "8", "output": "3432" } ]
1,603,742,122
2,147,483,647
Python 3
OK
TESTS
10
93
0
n = int(input()) lst = [0, 1, 2, 6, 20, 70, 252, 924, 3432, 12870, 48620] print(lst[n])
Title: Maximum in Table Time Limit: None seconds Memory Limit: None megabytes Problem Description: An *n*<=×<=*n* table *a* is defined as follows: - The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the table is equal to the sum of the number above it and the number to the left of it. In other words, the remaining elements are defined by the formula *a**i*,<=*j*<==<=*a**i*<=-<=1,<=*j*<=+<=*a**i*,<=*j*<=-<=1. These conditions define all the values in the table. You are given a number *n*. You need to determine the maximum value in the *n*<=×<=*n* table defined by the rules above. Input Specification: The only line of input contains a positive integer *n* (1<=≤<=*n*<=≤<=10) — the number of rows and columns of the table. Output Specification: Print a single line containing a positive integer *m* — the maximum value in the table. Demo Input: ['1\n', '5\n'] Demo Output: ['1', '70'] Note: In the second test the rows of the table look as follows:
```python n = int(input()) lst = [0, 1, 2, 6, 20, 70, 252, 924, 3432, 12870, 48620] print(lst[n]) ```
3
617
A
Elephant
PROGRAMMING
800
[ "math" ]
null
null
An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=&gt;<=0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determine, what is the minimum number of steps he need to make in order to get to his friend's house.
The first line of the input contains an integer *x* (1<=≤<=*x*<=≤<=1<=000<=000) — The coordinate of the friend's house.
Print the minimum number of steps that elephant needs to make to get from point 0 to point *x*.
[ "5\n", "12\n" ]
[ "1\n", "3\n" ]
In the first sample the elephant needs to make one step of length 5 to reach the point *x*. In the second sample the elephant can get to point *x* if he moves by 3, 5 and 4. There are other ways to get the optimal answer but the elephant cannot reach *x* in less than three moves.
500
[ { "input": "5", "output": "1" }, { "input": "12", "output": "3" }, { "input": "999999", "output": "200000" }, { "input": "41", "output": "9" }, { "input": "1000000", "output": "200000" }, { "input": "1", "output": "1" }, { "input": "2", "output": "1" }, { "input": "3", "output": "1" }, { "input": "4", "output": "1" }, { "input": "534204", "output": "106841" }, { "input": "469569", "output": "93914" }, { "input": "502877", "output": "100576" }, { "input": "942212", "output": "188443" }, { "input": "97", "output": "20" }, { "input": "53", "output": "11" }, { "input": "89", "output": "18" }, { "input": "574", "output": "115" }, { "input": "716", "output": "144" }, { "input": "729", "output": "146" }, { "input": "8901", "output": "1781" }, { "input": "3645", "output": "729" }, { "input": "4426", "output": "886" }, { "input": "46573", "output": "9315" }, { "input": "86380", "output": "17276" }, { "input": "94190", "output": "18838" }, { "input": "999990", "output": "199998" }, { "input": "999991", "output": "199999" }, { "input": "999992", "output": "199999" }, { "input": "999993", "output": "199999" }, { "input": "999994", "output": "199999" }, { "input": "999995", "output": "199999" }, { "input": "999996", "output": "200000" }, { "input": "999997", "output": "200000" }, { "input": "999998", "output": "200000" } ]
1,695,490,105
2,147,483,647
Python 3
OK
TESTS
34
46
0
a=int(input()) count=0 if (a%5)!=0: count=count+1 a=a/5 count=count+a print(int(count))
Title: Elephant Time Limit: None seconds Memory Limit: None megabytes Problem Description: An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=&gt;<=0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determine, what is the minimum number of steps he need to make in order to get to his friend's house. Input Specification: The first line of the input contains an integer *x* (1<=≤<=*x*<=≤<=1<=000<=000) — The coordinate of the friend's house. Output Specification: Print the minimum number of steps that elephant needs to make to get from point 0 to point *x*. Demo Input: ['5\n', '12\n'] Demo Output: ['1\n', '3\n'] Note: In the first sample the elephant needs to make one step of length 5 to reach the point *x*. In the second sample the elephant can get to point *x* if he moves by 3, 5 and 4. There are other ways to get the optimal answer but the elephant cannot reach *x* in less than three moves.
```python a=int(input()) count=0 if (a%5)!=0: count=count+1 a=a/5 count=count+a print(int(count)) ```
3
535
B
Tavas and SaDDas
PROGRAMMING
1,100
[ "bitmasks", "brute force", "combinatorics", "implementation" ]
null
null
Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphones and told him: "If you solve the following problem, I'll return it to you." The problem is: You are given a lucky number *n*. Lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. If we sort all lucky numbers in increasing order, what's the 1-based index of *n*? Tavas is not as smart as SaDDas, so he asked you to do him a favor and solve this problem so he can have his headphones back.
The first and only line of input contains a lucky number *n* (1<=≤<=*n*<=≤<=109).
Print the index of *n* among all lucky numbers.
[ "4\n", "7\n", "77\n" ]
[ "1\n", "2\n", "6\n" ]
none
1,000
[ { "input": "4", "output": "1" }, { "input": "7", "output": "2" }, { "input": "77", "output": "6" }, { "input": "4", "output": "1" }, { "input": "474744", "output": "83" }, { "input": "777774", "output": "125" }, { "input": "447", "output": "8" }, { "input": "774", "output": "13" }, { "input": "4", "output": "1" }, { "input": "4447747", "output": "140" }, { "input": "7747474", "output": "233" }, { "input": "4444", "output": "15" }, { "input": "4447", "output": "16" }, { "input": "7", "output": "2" }, { "input": "4", "output": "1" }, { "input": "4447744", "output": "139" }, { "input": "77474", "output": "57" }, { "input": "7747", "output": "28" }, { "input": "444", "output": "7" }, { "input": "7", "output": "2" }, { "input": "7774477", "output": "242" }, { "input": "4477774", "output": "157" }, { "input": "7444", "output": "23" }, { "input": "7474747", "output": "212" }, { "input": "77", "output": "6" }, { "input": "774477", "output": "114" }, { "input": "7", "output": "2" }, { "input": "47", "output": "4" }, { "input": "747777", "output": "110" }, { "input": "444444444", "output": "511" }, { "input": "777777777", "output": "1022" }, { "input": "477477447", "output": "728" }, { "input": "777744747", "output": "996" } ]
1,565,032,382
2,147,483,647
Python 3
OK
TESTS
33
109
0
''' Created on Aug 5, 2019 @author: Mohamed ''' #x=input() x=input().replace("4", "0").replace("7","1") z=len(x) index=2**z-1 index +=int(x,2) print(index)
Title: Tavas and SaDDas Time Limit: None seconds Memory Limit: None megabytes Problem Description: Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphones and told him: "If you solve the following problem, I'll return it to you." The problem is: You are given a lucky number *n*. Lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. If we sort all lucky numbers in increasing order, what's the 1-based index of *n*? Tavas is not as smart as SaDDas, so he asked you to do him a favor and solve this problem so he can have his headphones back. Input Specification: The first and only line of input contains a lucky number *n* (1<=≤<=*n*<=≤<=109). Output Specification: Print the index of *n* among all lucky numbers. Demo Input: ['4\n', '7\n', '77\n'] Demo Output: ['1\n', '2\n', '6\n'] Note: none
```python ''' Created on Aug 5, 2019 @author: Mohamed ''' #x=input() x=input().replace("4", "0").replace("7","1") z=len(x) index=2**z-1 index +=int(x,2) print(index) ```
3
641
A
Little Artem and Grasshopper
PROGRAMMING
1,000
[ "implementation" ]
null
null
Little Artem found a grasshopper. He brought it to his house and constructed a jumping area for him. The area looks like a strip of cells 1<=×<=*n*. Each cell contains the direction for the next jump and the length of that jump. Grasshopper starts in the first cell and follows the instructions written on the cells. Grasshopper stops immediately if it jumps out of the strip. Now Artem wants to find out if this will ever happen.
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — length of the strip. Next line contains a string of length *n* which consists of characters "&lt;" and "&gt;" only, that provide the direction of the jump from the corresponding cell. Next line contains *n* integers *d**i* (1<=≤<=*d**i*<=≤<=109) — the length of the jump from the *i*-th cell.
Print "INFINITE" (without quotes) if grasshopper will continue his jumps forever. Otherwise print "FINITE" (without quotes).
[ "2\n&gt;&lt;\n1 2\n", "3\n&gt;&gt;&lt;\n2 1 1\n" ]
[ "FINITE\n", "INFINITE" ]
In the first sample grasshopper starts from the first cell and jumps to the right on the next cell. When he is in the second cell he needs to jump two cells left so he will jump out of the strip. Second sample grasshopper path is 1 - 3 - 2 - 3 - 2 - 3 and so on. The path is infinite.
500
[ { "input": "2\n><\n1 2", "output": "FINITE" }, { "input": "3\n>><\n2 1 1", "output": "INFINITE" }, { "input": "1\n>\n1000000000", "output": "FINITE" }, { "input": "1\n<\n1000000000", "output": "FINITE" }, { "input": "2\n>>\n1 1", "output": "FINITE" }, { "input": "5\n>><><\n1 2 3 1 2", "output": "FINITE" }, { "input": "5\n>><><\n1 2 2 1 2", "output": "INFINITE" }, { "input": "10\n>>>>>>>>><\n1 1 1 1 1 1 1 1 1 10", "output": "FINITE" }, { "input": "10\n>>>>>>>>><\n1 1 1 1 1 1 1 1 1 5", "output": "INFINITE" }, { "input": "10\n>>>>>>>>><\n1 1 1 1 1 1 1 1 1 1", "output": "INFINITE" }, { "input": "3\n><<\n2 1 1", "output": "INFINITE" }, { "input": "10\n>>>>>>>>>>\n1 1 1 1 1 1 1 1 1 100", "output": "FINITE" }, { "input": "3\n><<\n2 100 2", "output": "INFINITE" }, { "input": "3\n><<\n2 3 2", "output": "INFINITE" }, { "input": "3\n>><\n2 3 2", "output": "INFINITE" }, { "input": "3\n><>\n1 1 1", "output": "INFINITE" }, { "input": "3\n>><\n2 2 2", "output": "INFINITE" }, { "input": "4\n>><<\n2 100 2 100", "output": "INFINITE" }, { "input": "3\n><>\n1 1 3", "output": "INFINITE" }, { "input": "5\n><>>>\n1 1 10 10 10", "output": "INFINITE" }, { "input": "5\n><<<<\n500 1 2 3 4", "output": "FINITE" }, { "input": "4\n><><\n2 1000 1 1", "output": "INFINITE" }, { "input": "3\n><<\n2 10 2", "output": "INFINITE" }, { "input": "3\n><<\n2 5 2", "output": "INFINITE" }, { "input": "2\n><\n5 5", "output": "FINITE" }, { "input": "3\n>><\n1 10 10", "output": "FINITE" }, { "input": "4\n><<>\n2 1 1 5", "output": "INFINITE" }, { "input": "5\n<<>>>\n1 1 1 1 1", "output": "FINITE" }, { "input": "3\n><>\n1 1 12345", "output": "INFINITE" }, { "input": "4\n>>><\n3 2 2 3", "output": "INFINITE" }, { "input": "3\n><>\n1 1 100000", "output": "INFINITE" } ]
1,574,417,168
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
93
0
n = int(input()) t = input() cord = 0 l = list(map(int,input().split())) i = 0 d = set({}) while cord < len(t): d.add(cord) if t[cord] == ">": cord = cord + l[i] else: cord = cord - l[i] if cord < 0 or cord > n-1: print("FINITE") exit() if cord in d: print("INFINITE") exit()
Title: Little Artem and Grasshopper Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Artem found a grasshopper. He brought it to his house and constructed a jumping area for him. The area looks like a strip of cells 1<=×<=*n*. Each cell contains the direction for the next jump and the length of that jump. Grasshopper starts in the first cell and follows the instructions written on the cells. Grasshopper stops immediately if it jumps out of the strip. Now Artem wants to find out if this will ever happen. Input Specification: The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — length of the strip. Next line contains a string of length *n* which consists of characters "&lt;" and "&gt;" only, that provide the direction of the jump from the corresponding cell. Next line contains *n* integers *d**i* (1<=≤<=*d**i*<=≤<=109) — the length of the jump from the *i*-th cell. Output Specification: Print "INFINITE" (without quotes) if grasshopper will continue his jumps forever. Otherwise print "FINITE" (without quotes). Demo Input: ['2\n&gt;&lt;\n1 2\n', '3\n&gt;&gt;&lt;\n2 1 1\n'] Demo Output: ['FINITE\n', 'INFINITE'] Note: In the first sample grasshopper starts from the first cell and jumps to the right on the next cell. When he is in the second cell he needs to jump two cells left so he will jump out of the strip. Second sample grasshopper path is 1 - 3 - 2 - 3 - 2 - 3 and so on. The path is infinite.
```python n = int(input()) t = input() cord = 0 l = list(map(int,input().split())) i = 0 d = set({}) while cord < len(t): d.add(cord) if t[cord] == ">": cord = cord + l[i] else: cord = cord - l[i] if cord < 0 or cord > n-1: print("FINITE") exit() if cord in d: print("INFINITE") exit() ```
0
580
A
Kefa and First Steps
PROGRAMMING
900
[ "brute force", "dp", "implementation" ]
null
null
Kefa decided to make some money doing business on the Internet for exactly *n* days. He knows that on the *i*-th day (1<=≤<=*i*<=≤<=*n*) he makes *a**i* money. Kefa loves progress, that's why he wants to know the length of the maximum non-decreasing subsegment in sequence *a**i*. Let us remind you that the subsegment of the sequence is its continuous fragment. A subsegment of numbers is called non-decreasing if all numbers in it follow in the non-decreasing order. Help Kefa cope with this task!
The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* integers *a*1,<=<=*a*2,<=<=...,<=<=*a**n* (1<=≤<=*a**i*<=≤<=109).
Print a single integer — the length of the maximum non-decreasing subsegment of sequence *a*.
[ "6\n2 2 1 3 4 1\n", "3\n2 2 9\n" ]
[ "3", "3" ]
In the first test the maximum non-decreasing subsegment is the numbers from the third to the fifth one. In the second test the maximum non-decreasing subsegment is the numbers from the first to the third one.
750
[ { "input": "6\n2 2 1 3 4 1", "output": "3" }, { "input": "3\n2 2 9", "output": "3" }, { "input": "5\n10 100 111 1 2", "output": "3" }, { "input": "10\n1 2 3 4 1 2 3 4 5 6", "output": "6" }, { "input": "50\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "50" }, { "input": "100\n1 838 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1 605 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1 27 533 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1 835 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1 992", "output": "42" }, { "input": "1\n1", "output": "1" }, { "input": "2\n1 1", "output": "2" }, { "input": "6\n5 4 3 2 1 2", "output": "2" }, { "input": "9\n1 2 3 4 5 6 7 8 9", "output": "9" }, { "input": "7\n99 100 1 2 3 4 5", "output": "5" }, { "input": "5\n3 3 1 2 3", "output": "3" }, { "input": "1\n100", "output": "1" }, { "input": "1\n5", "output": "1" } ]
1,696,305,553
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
15
0
n=int(input()) sequence=input().split() day=[] for i in range(n): x=1 for ii in range(i,n-1): if sequence[ii]<=sequence[ii+1]: x+=1 else: x=x day.append(x) y=max(day) print(y)
Title: Kefa and First Steps Time Limit: None seconds Memory Limit: None megabytes Problem Description: Kefa decided to make some money doing business on the Internet for exactly *n* days. He knows that on the *i*-th day (1<=≤<=*i*<=≤<=*n*) he makes *a**i* money. Kefa loves progress, that's why he wants to know the length of the maximum non-decreasing subsegment in sequence *a**i*. Let us remind you that the subsegment of the sequence is its continuous fragment. A subsegment of numbers is called non-decreasing if all numbers in it follow in the non-decreasing order. Help Kefa cope with this task! Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* integers *a*1,<=<=*a*2,<=<=...,<=<=*a**n* (1<=≤<=*a**i*<=≤<=109). Output Specification: Print a single integer — the length of the maximum non-decreasing subsegment of sequence *a*. Demo Input: ['6\n2 2 1 3 4 1\n', '3\n2 2 9\n'] Demo Output: ['3', '3'] Note: In the first test the maximum non-decreasing subsegment is the numbers from the third to the fifth one. In the second test the maximum non-decreasing subsegment is the numbers from the first to the third one.
```python n=int(input()) sequence=input().split() day=[] for i in range(n): x=1 for ii in range(i,n-1): if sequence[ii]<=sequence[ii+1]: x+=1 else: x=x day.append(x) y=max(day) print(y) ```
0
796
B
Find The Bone
PROGRAMMING
1,300
[ "implementation" ]
null
null
Zane the wizard is going to perform a magic show shuffling the cups. There are *n* cups, numbered from 1 to *n*, placed along the *x*-axis on a table that has *m* holes on it. More precisely, cup *i* is on the table at the position *x*<==<=*i*. The problematic bone is initially at the position *x*<==<=1. Zane will confuse the audience by swapping the cups *k* times, the *i*-th time of which involves the cups at the positions *x*<==<=*u**i* and *x*<==<=*v**i*. If the bone happens to be at the position where there is a hole at any time, it will fall into the hole onto the ground and will not be affected by future swapping operations. Do not forget that Zane is a wizard. When he swaps the cups, he does not move them ordinarily. Instead, he teleports the cups (along with the bone, if it is inside) to the intended positions. Therefore, for example, when he swaps the cup at *x*<==<=4 and the one at *x*<==<=6, they will not be at the position *x*<==<=5 at any moment during the operation. Zane’s puppy, Inzane, is in trouble. Zane is away on his vacation, and Inzane cannot find his beloved bone, as it would be too exhausting to try opening all the cups. Inzane knows that the Codeforces community has successfully helped Zane, so he wants to see if it could help him solve his problem too. Help Inzane determine the final position of the bone.
The first line contains three integers *n*, *m*, and *k* (2<=≤<=*n*<=≤<=106, 1<=≤<=*m*<=≤<=*n*, 1<=≤<=*k*<=≤<=3·105) — the number of cups, the number of holes on the table, and the number of swapping operations, respectively. The second line contains *m* distinct integers *h*1,<=*h*2,<=...,<=*h**m* (1<=≤<=*h**i*<=≤<=*n*) — the positions along the *x*-axis where there is a hole on the table. Each of the next *k* lines contains two integers *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*, *u**i*<=≠<=*v**i*) — the positions of the cups to be swapped.
Print one integer — the final position along the *x*-axis of the bone.
[ "7 3 4\n3 4 6\n1 2\n2 5\n5 7\n7 1\n", "5 1 2\n2\n1 2\n2 4\n" ]
[ "1", "2" ]
In the first sample, after the operations, the bone becomes at *x* = 2, *x* = 5, *x* = 7, and *x* = 1, respectively. In the second sample, after the first operation, the bone becomes at *x* = 2, and falls into the hole onto the ground.
750
[ { "input": "7 3 4\n3 4 6\n1 2\n2 5\n5 7\n7 1", "output": "1" }, { "input": "5 1 2\n2\n1 2\n2 4", "output": "2" }, { "input": "10000 1 9\n55\n44 1\n2929 9292\n9999 9998\n44 55\n49 94\n55 53\n100 199\n55 50\n53 11", "output": "55" }, { "input": "100000 3 7\n2 3 4\n1 5\n5 1\n1 5\n5 1\n1 4\n4 3\n3 2", "output": "4" }, { "input": "1000000 9 11\n38 59 999999 199 283 4849 1000000 2 554\n39 94\n3 9\n1 39\n39 40\n40 292\n5399 5858\n292 49949\n49949 222\n222 38\n202 9494\n38 59", "output": "38" }, { "input": "1000000 11 9\n19 28 39 82 99 929384 8298 892849 202020 777777 123123\n19 28\n28 39\n1 123124\n39 28\n28 99\n99 8298\n123124 123122\n2300 3200\n8298 1000000", "output": "123122" }, { "input": "2 1 1\n1\n1 2", "output": "1" }, { "input": "7 3 6\n1 4 5\n1 2\n2 3\n3 5\n4 5\n4 5\n4 5", "output": "1" }, { "input": "10 3 8\n1 5 10\n1 2\n2 3\n3 4\n3 4\n3 4\n4 5\n5 6\n6 5", "output": "1" }, { "input": "5 2 9\n2 4\n1 3\n3 5\n3 5\n3 4\n4 2\n2 4\n1 4\n1 2\n1 4", "output": "4" }, { "input": "10 10 13\n1 2 3 4 5 6 7 8 9 10\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n6 7\n6 10\n10 9\n9 1\n1 10\n1 10\n1 10", "output": "1" }, { "input": "3 3 3\n1 2 3\n1 2\n2 3\n3 2", "output": "1" }, { "input": "100 7 7\n17 27 37 47 57 67 77\n49 39\n55 1\n50 3\n89 1\n1 99\n100 55\n98 55", "output": "100" }, { "input": "9 1 9\n9\n1 2\n3 2\n4 3\n8 9\n4 5\n7 4\n8 5\n1 3\n3 2", "output": "8" }, { "input": "300000 1 1\n200000\n300000 1", "output": "300000" }, { "input": "203948 2 14\n203948 203946\n39 38\n4959 3030\n1 203947\n2929 9292\n203944 203948\n203947 203944\n203944 203922\n203922 203948\n2495 20495\n29419 5959\n12949 12\n49 29292\n1 94\n1 203", "output": "203948" }, { "input": "203948 2 14\n203948 203947\n39 38\n4959 3030\n1 203947\n2929 9292\n203944 203948\n203947 203944\n203944 203922\n203922 203948\n2495 20495\n29419 5959\n12949 12\n49 29292\n1 94\n1 203", "output": "203947" }, { "input": "100 2 5\n1 2\n2 39\n39 29\n99 100\n1 2\n2 39", "output": "1" }, { "input": "3 1 1\n1\n1 2", "output": "1" }, { "input": "5 2 2\n1 2\n1 2\n2 3", "output": "1" }, { "input": "2 2 1\n1 2\n2 1", "output": "1" }, { "input": "5 2 1\n1 2\n2 1", "output": "1" }, { "input": "5 1 1\n5\n3 4", "output": "1" }, { "input": "3 2 1\n1 2\n2 1", "output": "1" }, { "input": "5 1 2\n2\n2 1\n2 3", "output": "2" }, { "input": "3 1 2\n2\n2 1\n2 3", "output": "2" }, { "input": "3 2 2\n2 3\n2 1\n2 3", "output": "2" }, { "input": "4 2 1\n1 2\n2 1", "output": "1" }, { "input": "4 1 1\n2\n2 3", "output": "1" }, { "input": "3 2 1\n1 3\n3 1", "output": "1" }, { "input": "10 1 3\n2\n2 1\n2 4\n9 10", "output": "2" }, { "input": "5 2 4\n3 5\n1 2\n4 2\n3 4\n3 5", "output": "3" }, { "input": "4 3 1\n1 2 3\n2 1", "output": "1" } ]
1,548,479,582
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
124
409,600
n,m,k=map(int,input().split()) h=[int(i) for i in input().split()] bone_at=1 hole=0 from collections import Counter c=Counter(h) for i in range(k): u,v=map(int,input().split()) if bone_at==u: bone_at=v if c[v]: hole=1 hole_ans=v if hole: print(hole_ans) else: print(bone_at)
Title: Find The Bone Time Limit: None seconds Memory Limit: None megabytes Problem Description: Zane the wizard is going to perform a magic show shuffling the cups. There are *n* cups, numbered from 1 to *n*, placed along the *x*-axis on a table that has *m* holes on it. More precisely, cup *i* is on the table at the position *x*<==<=*i*. The problematic bone is initially at the position *x*<==<=1. Zane will confuse the audience by swapping the cups *k* times, the *i*-th time of which involves the cups at the positions *x*<==<=*u**i* and *x*<==<=*v**i*. If the bone happens to be at the position where there is a hole at any time, it will fall into the hole onto the ground and will not be affected by future swapping operations. Do not forget that Zane is a wizard. When he swaps the cups, he does not move them ordinarily. Instead, he teleports the cups (along with the bone, if it is inside) to the intended positions. Therefore, for example, when he swaps the cup at *x*<==<=4 and the one at *x*<==<=6, they will not be at the position *x*<==<=5 at any moment during the operation. Zane’s puppy, Inzane, is in trouble. Zane is away on his vacation, and Inzane cannot find his beloved bone, as it would be too exhausting to try opening all the cups. Inzane knows that the Codeforces community has successfully helped Zane, so he wants to see if it could help him solve his problem too. Help Inzane determine the final position of the bone. Input Specification: The first line contains three integers *n*, *m*, and *k* (2<=≤<=*n*<=≤<=106, 1<=≤<=*m*<=≤<=*n*, 1<=≤<=*k*<=≤<=3·105) — the number of cups, the number of holes on the table, and the number of swapping operations, respectively. The second line contains *m* distinct integers *h*1,<=*h*2,<=...,<=*h**m* (1<=≤<=*h**i*<=≤<=*n*) — the positions along the *x*-axis where there is a hole on the table. Each of the next *k* lines contains two integers *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*, *u**i*<=≠<=*v**i*) — the positions of the cups to be swapped. Output Specification: Print one integer — the final position along the *x*-axis of the bone. Demo Input: ['7 3 4\n3 4 6\n1 2\n2 5\n5 7\n7 1\n', '5 1 2\n2\n1 2\n2 4\n'] Demo Output: ['1', '2'] Note: In the first sample, after the operations, the bone becomes at *x* = 2, *x* = 5, *x* = 7, and *x* = 1, respectively. In the second sample, after the first operation, the bone becomes at *x* = 2, and falls into the hole onto the ground.
```python n,m,k=map(int,input().split()) h=[int(i) for i in input().split()] bone_at=1 hole=0 from collections import Counter c=Counter(h) for i in range(k): u,v=map(int,input().split()) if bone_at==u: bone_at=v if c[v]: hole=1 hole_ans=v if hole: print(hole_ans) else: print(bone_at) ```
0
760
B
Frodo and pillows
PROGRAMMING
1,500
[ "binary search", "greedy" ]
null
null
*n* hobbits are planning to spend the night at Frodo's house. Frodo has *n* beds standing in a row and *m* pillows (*n*<=≤<=*m*). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not always possible to share pillows equally, but any hobbit gets hurt if he has at least two pillows less than some of his neighbors have. Frodo will sleep on the *k*-th bed in the row. What is the maximum number of pillows he can have so that every hobbit has at least one pillow, every pillow is given to some hobbit and no one is hurt?
The only line contain three integers *n*, *m* and *k* (1<=≤<=*n*<=≤<=*m*<=≤<=109, 1<=≤<=*k*<=≤<=*n*) — the number of hobbits, the number of pillows and the number of Frodo's bed.
Print single integer — the maximum number of pillows Frodo can have so that no one is hurt.
[ "4 6 2\n", "3 10 3\n", "3 6 1\n" ]
[ "2\n", "4\n", "3\n" ]
In the first example Frodo can have at most two pillows. In this case, he can give two pillows to the hobbit on the first bed, and one pillow to each of the hobbits on the third and the fourth beds. In the second example Frodo can take at most four pillows, giving three pillows to each of the others. In the third example Frodo can take three pillows, giving two pillows to the hobbit in the middle and one pillow to the hobbit on the third bed.
1,000
[ { "input": "4 6 2", "output": "2" }, { "input": "3 10 3", "output": "4" }, { "input": "3 6 1", "output": "3" }, { "input": "3 3 3", "output": "1" }, { "input": "1 1 1", "output": "1" }, { "input": "1 1000000000 1", "output": "1000000000" }, { "input": "100 1000000000 20", "output": "10000034" }, { "input": "1000 1000 994", "output": "1" }, { "input": "100000000 200000000 54345", "output": "10001" }, { "input": "1000000000 1000000000 1", "output": "1" }, { "input": "1000000000 1000000000 1000000000", "output": "1" }, { "input": "1000000000 1000000000 500000000", "output": "1" }, { "input": "1000 1000 3", "output": "1" }, { "input": "100000000 200020000 54345", "output": "10001" }, { "input": "100 108037 18", "output": "1115" }, { "input": "100000000 200020001 54345", "output": "10002" }, { "input": "200 6585 2", "output": "112" }, { "input": "30000 30593 5980", "output": "25" }, { "input": "40000 42107 10555", "output": "46" }, { "input": "50003 50921 192", "output": "31" }, { "input": "100000 113611 24910", "output": "117" }, { "input": "1000000 483447163 83104", "output": "21965" }, { "input": "10000000 10021505 600076", "output": "147" }, { "input": "100000000 102144805 2091145", "output": "1465" }, { "input": "1000000000 1000000000 481982093", "output": "1" }, { "input": "100 999973325 5", "output": "9999778" }, { "input": "200 999999109 61", "output": "5000053" }, { "input": "30000 999999384 5488", "output": "43849" }, { "input": "40000 999997662 8976", "output": "38038" }, { "input": "50003 999999649 405", "output": "44320" }, { "input": "100000 999899822 30885", "output": "31624" }, { "input": "1000000 914032367 528790", "output": "30217" }, { "input": "10000000 999617465 673112", "output": "31459" }, { "input": "100000000 993180275 362942", "output": "29887" }, { "input": "1000000000 1000000000 331431458", "output": "1" }, { "input": "100 10466 89", "output": "144" }, { "input": "200 5701 172", "output": "84" }, { "input": "30000 36932 29126", "output": "84" }, { "input": "40000 40771 22564", "output": "28" }, { "input": "50003 51705 49898", "output": "42" }, { "input": "100000 149408 74707", "output": "223" }, { "input": "1000000 194818222 998601", "output": "18389" }, { "input": "10000000 10748901 8882081", "output": "866" }, { "input": "100000000 106296029 98572386", "output": "2510" }, { "input": "1000000000 1000000000 193988157", "output": "1" }, { "input": "100 999981057 92", "output": "9999852" }, { "input": "200 999989691 199", "output": "5000046" }, { "input": "30000 999995411 24509", "output": "43846" }, { "input": "40000 999998466 30827", "output": "37930" }, { "input": "50003 999997857 48387", "output": "43163" }, { "input": "100000 999731886 98615", "output": "43371" }, { "input": "1000000 523220797 654341", "output": "22853" }, { "input": "10000000 999922591 8157724", "output": "31464" }, { "input": "100000000 999834114 93836827", "output": "29998" }, { "input": "1000000000 1000000000 912549504", "output": "1" }, { "input": "1000 97654978 234", "output": "97976" }, { "input": "1000 97654977 234", "output": "97975" }, { "input": "1000234 97653889 1", "output": "13903" }, { "input": "1000234 97653890 1", "output": "13904" }, { "input": "3450234 97656670 3000000", "output": "9707" }, { "input": "3450234 97656669 3000000", "output": "9706" }, { "input": "3 1000000000 2", "output": "333333334" }, { "input": "2 1000000000 1", "output": "500000000" }, { "input": "2 1000000000 2", "output": "500000000" }, { "input": "3 1000000000 1", "output": "333333334" }, { "input": "3 1000000000 3", "output": "333333334" }, { "input": "2 999999999 1", "output": "500000000" }, { "input": "2 999999999 2", "output": "500000000" }, { "input": "1 999999999 1", "output": "999999999" } ]
1,485,184,037
2,147,483,647
Python 3
OK
TESTS
69
77
4,608,000
n, m, k = list(map(int, input().split())) def cnt(n): return n * (n + 1) // 2 def sum(l, r): if l > r: return 0 d = 0 if l <= 0: d = abs(l) + 1 l = 1 return cnt(r) - cnt(l - 1) + d rt = int(1e9) + 2 lt = 1 while rt - lt > 1: mid = (lt + rt) // 2 total = sum(mid - k + 1, mid) + sum(mid - (n - k), mid - 1) if total <= m: lt = mid else: rt = mid print(lt)
Title: Frodo and pillows Time Limit: None seconds Memory Limit: None megabytes Problem Description: *n* hobbits are planning to spend the night at Frodo's house. Frodo has *n* beds standing in a row and *m* pillows (*n*<=≤<=*m*). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not always possible to share pillows equally, but any hobbit gets hurt if he has at least two pillows less than some of his neighbors have. Frodo will sleep on the *k*-th bed in the row. What is the maximum number of pillows he can have so that every hobbit has at least one pillow, every pillow is given to some hobbit and no one is hurt? Input Specification: The only line contain three integers *n*, *m* and *k* (1<=≤<=*n*<=≤<=*m*<=≤<=109, 1<=≤<=*k*<=≤<=*n*) — the number of hobbits, the number of pillows and the number of Frodo's bed. Output Specification: Print single integer — the maximum number of pillows Frodo can have so that no one is hurt. Demo Input: ['4 6 2\n', '3 10 3\n', '3 6 1\n'] Demo Output: ['2\n', '4\n', '3\n'] Note: In the first example Frodo can have at most two pillows. In this case, he can give two pillows to the hobbit on the first bed, and one pillow to each of the hobbits on the third and the fourth beds. In the second example Frodo can take at most four pillows, giving three pillows to each of the others. In the third example Frodo can take three pillows, giving two pillows to the hobbit in the middle and one pillow to the hobbit on the third bed.
```python n, m, k = list(map(int, input().split())) def cnt(n): return n * (n + 1) // 2 def sum(l, r): if l > r: return 0 d = 0 if l <= 0: d = abs(l) + 1 l = 1 return cnt(r) - cnt(l - 1) + d rt = int(1e9) + 2 lt = 1 while rt - lt > 1: mid = (lt + rt) // 2 total = sum(mid - k + 1, mid) + sum(mid - (n - k), mid - 1) if total <= m: lt = mid else: rt = mid print(lt) ```
3
181
A
Series of Crimes
PROGRAMMING
800
[ "brute force", "geometry", "implementation" ]
null
null
The Berland capital is shaken with three bold crimes committed by the Pihsters, a notorious criminal gang. The Berland capital's map is represented by an *n*<=×<=*m* rectangular table. Each cell of the table on the map represents some districts of the capital. The capital's main detective Polycarpus took a map and marked there the districts where the first three robberies had been committed as asterisks. Deduction tells Polycarpus that the fourth robbery will be committed in such district, that all four robbed districts will form the vertices of some rectangle, parallel to the sides of the map. Polycarpus is good at deduction but he's hopeless at math. So he asked you to find the district where the fourth robbery will be committed.
The first line contains two space-separated integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=100) — the number of rows and columns in the table, correspondingly. Each of the next *n* lines contains *m* characters — the description of the capital's map. Each character can either be a "." (dot), or an "*" (asterisk). A character equals "*" if the corresponding district has been robbed. Otherwise, it equals ".". It is guaranteed that the map has exactly three characters "*" and we can always find the fourth district that meets the problem requirements.
Print two integers — the number of the row and the number of the column of the city district that is the fourth one to be robbed. The rows are numbered starting from one from top to bottom and the columns are numbered starting from one from left to right.
[ "3 2\n.*\n..\n**\n", "3 3\n*.*\n*..\n...\n" ]
[ "1 1\n", "2 3\n" ]
none
500
[ { "input": "3 2\n.*\n..\n**", "output": "1 1" }, { "input": "2 5\n*....\n*...*", "output": "1 5" }, { "input": "7 2\n..\n**\n..\n..\n..\n..\n.*", "output": "7 1" }, { "input": "7 2\n*.\n..\n..\n..\n..\n..\n**", "output": "1 2" }, { "input": "2 10\n*......*..\n.......*..", "output": "2 1" }, { "input": "10 3\n*..\n...\n...\n...\n...\n...\n...\n...\n...\n**.", "output": "1 2" }, { "input": "100 2\n*.\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\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": "1 2" }, { "input": "99 3\n**.\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\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": "99 2" }, { "input": "98 3\n...\n.*.\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\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": "2 3" }, { "input": "99 3\n**.\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\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": "99 2" }, { "input": "98 3\n...\n.*.\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\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": "2 3" }, { "input": "2 100\n...................................................................................................*\n*..................................................................................................*", "output": "1 1" }, { "input": "2 2\n*.\n**", "output": "1 2" }, { "input": "2 2\n**\n.*", "output": "2 1" }, { "input": "2 3\n*.*\n..*", "output": "2 1" } ]
1,693,924,176
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
def solve(): n, m = map(int, input().split()) result = [] for i in range(1, n + 1): s = input() if s.count('*') == 1: result.append((i, s.find('*') + 1) elif s.count('*') == 2: result.append((i, s.find('*') + 1)) result.append((i, s.rfind('*') + 1)) a, b, c = result if a[0] == b[0]: if a[1] == c[1]: d = (c[0], b[1]) else: d = (c[0], a[1]) elif a[0] == c[0]: if a[1] == b[1]: d = (b[0], c[1]) else: d = (b[0], a[1]) print(*d) if __name__ == "__main__: solve()
Title: Series of Crimes Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Berland capital is shaken with three bold crimes committed by the Pihsters, a notorious criminal gang. The Berland capital's map is represented by an *n*<=×<=*m* rectangular table. Each cell of the table on the map represents some districts of the capital. The capital's main detective Polycarpus took a map and marked there the districts where the first three robberies had been committed as asterisks. Deduction tells Polycarpus that the fourth robbery will be committed in such district, that all four robbed districts will form the vertices of some rectangle, parallel to the sides of the map. Polycarpus is good at deduction but he's hopeless at math. So he asked you to find the district where the fourth robbery will be committed. Input Specification: The first line contains two space-separated integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=100) — the number of rows and columns in the table, correspondingly. Each of the next *n* lines contains *m* characters — the description of the capital's map. Each character can either be a "." (dot), or an "*" (asterisk). A character equals "*" if the corresponding district has been robbed. Otherwise, it equals ".". It is guaranteed that the map has exactly three characters "*" and we can always find the fourth district that meets the problem requirements. Output Specification: Print two integers — the number of the row and the number of the column of the city district that is the fourth one to be robbed. The rows are numbered starting from one from top to bottom and the columns are numbered starting from one from left to right. Demo Input: ['3 2\n.*\n..\n**\n', '3 3\n*.*\n*..\n...\n'] Demo Output: ['1 1\n', '2 3\n'] Note: none
```python def solve(): n, m = map(int, input().split()) result = [] for i in range(1, n + 1): s = input() if s.count('*') == 1: result.append((i, s.find('*') + 1) elif s.count('*') == 2: result.append((i, s.find('*') + 1)) result.append((i, s.rfind('*') + 1)) a, b, c = result if a[0] == b[0]: if a[1] == c[1]: d = (c[0], b[1]) else: d = (c[0], a[1]) elif a[0] == c[0]: if a[1] == b[1]: d = (b[0], c[1]) else: d = (b[0], a[1]) print(*d) if __name__ == "__main__: solve() ```
-1
185
A
Plant
PROGRAMMING
1,300
[ "math" ]
null
null
Dwarfs have planted a very interesting plant, which is a triangle directed "upwards". This plant has an amusing feature. After one year a triangle plant directed "upwards" divides into four triangle plants: three of them will point "upwards" and one will point "downwards". After another year, each triangle plant divides into four triangle plants: three of them will be directed in the same direction as the parent plant, and one of them will be directed in the opposite direction. Then each year the process repeats. The figure below illustrates this process. Help the dwarfs find out how many triangle plants that point "upwards" will be in *n* years.
The first line contains a single integer *n* (0<=≤<=*n*<=≤<=1018) — the number of full years when the plant grew. Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.
Print a single integer — the remainder of dividing the number of plants that will point "upwards" in *n* years by 1000000007 (109<=+<=7).
[ "1\n", "2\n" ]
[ "3\n", "10\n" ]
The first test sample corresponds to the second triangle on the figure in the statement. The second test sample corresponds to the third one.
500
[ { "input": "1", "output": "3" }, { "input": "2", "output": "10" }, { "input": "385599124", "output": "493875375" }, { "input": "989464295", "output": "31966163" }, { "input": "376367012", "output": "523204186" }, { "input": "529357306", "output": "142578489" }, { "input": "782916801", "output": "51174574" }, { "input": "74859961358140080", "output": "478768275" }, { "input": "0", "output": "1" }, { "input": "252509053898415171", "output": "886314547" }, { "input": "760713016078377938", "output": "79611270" }, { "input": "919845424847912644", "output": "388845650" }, { "input": "585335721566249104", "output": "301383716" }, { "input": "522842183413115087", "output": "556012763" }, { "input": "148049062285906746", "output": "913927498" }, { "input": "84324827171274022", "output": "462535280" }, { "input": "354979172034763159", "output": "239287993" }, { "input": "1312148742261680", "output": "799725655" }, { "input": "269587448053313253", "output": "536645997" }, { "input": "645762257531682045", "output": "543988614" }, { "input": "615812227854199662", "output": "357939938" }, { "input": "819875140559301751", "output": "968653685" }, { "input": "349993003033420740", "output": "709392758" }, { "input": "891351282398722856", "output": "70758467" }, { "input": "563324730406715801", "output": "353494903" }, { "input": "520974001002628386", "output": "164118419" }, { "input": "666729339260489789", "output": "784700006" }, { "input": "856674609788912527", "output": "720540265" }, { "input": "791809296233191092", "output": "369199735" }, { "input": "711066335916901717", "output": "15590358" }, { "input": "931356501703211379", "output": "239824013" }, { "input": "234122431978145893", "output": "905163056" }, { "input": "1000000000000000000", "output": "899770636" }, { "input": "3", "output": "36" }, { "input": "4", "output": "136" }, { "input": "5", "output": "528" }, { "input": "6", "output": "2080" }, { "input": "7", "output": "8256" }, { "input": "8", "output": "32896" }, { "input": "9", "output": "131328" }, { "input": "10", "output": "524800" }, { "input": "11", "output": "2098176" }, { "input": "12", "output": "8390656" }, { "input": "13", "output": "33558528" }, { "input": "14", "output": "134225920" }, { "input": "15", "output": "536887296" }, { "input": "16", "output": "147516402" }, { "input": "0", "output": "1" }, { "input": "6265", "output": "980996097" } ]
1,428,853,076
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
2
2,000
0
import math n = int(input()) i = 1 pow1, pow2 = 2, 4 while i < n: pow1 = pow1 * pow1 % 1000000007 pow2 = pow2 * pow2 % 1000000007 i *= 2 if i != n: i = i // 2 pow1 = int(math.sqrt(pow1)) % 1000000007 pow2 = int(math.sqrt(pow2)) % 1000000007 while i < n: pow1 = pow1 * 2 % 1000000007 pow2 = pow2 * 4 % 1000000007 i += 1 print ((pow1 + pow2) // 2 % 1000000007)
Title: Plant Time Limit: None seconds Memory Limit: None megabytes Problem Description: Dwarfs have planted a very interesting plant, which is a triangle directed "upwards". This plant has an amusing feature. After one year a triangle plant directed "upwards" divides into four triangle plants: three of them will point "upwards" and one will point "downwards". After another year, each triangle plant divides into four triangle plants: three of them will be directed in the same direction as the parent plant, and one of them will be directed in the opposite direction. Then each year the process repeats. The figure below illustrates this process. Help the dwarfs find out how many triangle plants that point "upwards" will be in *n* years. Input Specification: The first line contains a single integer *n* (0<=≤<=*n*<=≤<=1018) — the number of full years when the plant grew. Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. Output Specification: Print a single integer — the remainder of dividing the number of plants that will point "upwards" in *n* years by 1000000007 (109<=+<=7). Demo Input: ['1\n', '2\n'] Demo Output: ['3\n', '10\n'] Note: The first test sample corresponds to the second triangle on the figure in the statement. The second test sample corresponds to the third one.
```python import math n = int(input()) i = 1 pow1, pow2 = 2, 4 while i < n: pow1 = pow1 * pow1 % 1000000007 pow2 = pow2 * pow2 % 1000000007 i *= 2 if i != n: i = i // 2 pow1 = int(math.sqrt(pow1)) % 1000000007 pow2 = int(math.sqrt(pow2)) % 1000000007 while i < n: pow1 = pow1 * 2 % 1000000007 pow2 = pow2 * 4 % 1000000007 i += 1 print ((pow1 + pow2) // 2 % 1000000007) ```
0
431
A
Black Square
PROGRAMMING
800
[ "implementation" ]
null
null
Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone. In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules of the game, Jury must use this second to touch the corresponding strip to make the square go away. As Jury is both smart and lazy, he counted that he wastes exactly *a**i* calories on touching the *i*-th strip. You've got a string *s*, describing the process of the game and numbers *a*1,<=*a*2,<=*a*3,<=*a*4. Calculate how many calories Jury needs to destroy all the squares?
The first line contains four space-separated integers *a*1, *a*2, *a*3, *a*4 (0<=≤<=*a*1,<=*a*2,<=*a*3,<=*a*4<=≤<=104). The second line contains string *s* (1<=≤<=|*s*|<=≤<=105), where the *і*-th character of the string equals "1", if on the *i*-th second of the game the square appears on the first strip, "2", if it appears on the second strip, "3", if it appears on the third strip, "4", if it appears on the fourth strip.
Print a single integer — the total number of calories that Jury wastes.
[ "1 2 3 4\n123214\n", "1 5 3 2\n11221\n" ]
[ "13\n", "13\n" ]
none
500
[ { "input": "1 2 3 4\n123214", "output": "13" }, { "input": "1 5 3 2\n11221", "output": "13" }, { "input": "5 5 5 1\n3422", "output": "16" }, { "input": "4 3 2 1\n2", "output": "3" }, { "input": "5651 6882 6954 4733\n2442313421", "output": "60055" }, { "input": "0 0 0 0\n4132", "output": "0" }, { "input": "3163 5778 83 7640\n11141442444", "output": "64270" }, { "input": "1809 1302 7164 6122\n3144121413113111223311232232114144321414421243443243422322144324121433444342231344234443332241322442", "output": "420780" }, { "input": "0 0 0 0\n1", "output": "0" }, { "input": "1 2 3 4\n4", "output": "4" }, { "input": "2343 7653 1242 5432\n1", "output": "2343" }, { "input": "2343 7653 1242 5432\n2", "output": "7653" }, { "input": "2343 7653 1242 5432\n3", "output": "1242" }, { "input": "2343 7653 1242 5432\n4", "output": "5432" }, { "input": "1 2 3 4\n123412", "output": "13" }, { "input": "50 50 50 50\n11111111111111111111111111111111111111111111111111111", "output": "2650" }, { "input": "1 2 3 4\n11111111111111111111111111111111111111111111111111", "output": "50" }, { "input": "1 2 3 4\n23123231321231231231231231221232123121312321", "output": "87" }, { "input": "1 2 3 4\n1111111111111222222222233333333333444444444444444", "output": "126" }, { "input": "2 3 1 4\n121321232412342112312313213123123412131231231232", "output": "105" } ]
1,692,830,056
2,147,483,647
Python 3
OK
TESTS
49
62
2,969,600
list_of_calories=list(map(int,input().split())) the_list=list(map(int,input())) calories=0 for i in the_list: calories+=list_of_calories[i-1] print(calories)
Title: Black Square Time Limit: None seconds Memory Limit: None megabytes Problem Description: Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone. In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules of the game, Jury must use this second to touch the corresponding strip to make the square go away. As Jury is both smart and lazy, he counted that he wastes exactly *a**i* calories on touching the *i*-th strip. You've got a string *s*, describing the process of the game and numbers *a*1,<=*a*2,<=*a*3,<=*a*4. Calculate how many calories Jury needs to destroy all the squares? Input Specification: The first line contains four space-separated integers *a*1, *a*2, *a*3, *a*4 (0<=≤<=*a*1,<=*a*2,<=*a*3,<=*a*4<=≤<=104). The second line contains string *s* (1<=≤<=|*s*|<=≤<=105), where the *і*-th character of the string equals "1", if on the *i*-th second of the game the square appears on the first strip, "2", if it appears on the second strip, "3", if it appears on the third strip, "4", if it appears on the fourth strip. Output Specification: Print a single integer — the total number of calories that Jury wastes. Demo Input: ['1 2 3 4\n123214\n', '1 5 3 2\n11221\n'] Demo Output: ['13\n', '13\n'] Note: none
```python list_of_calories=list(map(int,input().split())) the_list=list(map(int,input())) calories=0 for i in the_list: calories+=list_of_calories[i-1] print(calories) ```
3
842
C
Ilya And The Tree
PROGRAMMING
2,000
[ "dfs and similar", "graphs", "math", "number theory", "trees" ]
null
null
Ilya is very fond of graphs, especially trees. During his last trip to the forest Ilya found a very interesting tree rooted at vertex 1. There is an integer number written on each vertex of the tree; the number written on vertex *i* is equal to *a**i*. Ilya believes that the beauty of the vertex *x* is the greatest common divisor of all numbers written on the vertices on the path from the root to *x*, including this vertex itself. In addition, Ilya can change the number in one arbitrary vertex to 0 or leave all vertices unchanged. Now for each vertex Ilya wants to know the maximum possible beauty it can have. For each vertex the answer must be considered independently. The beauty of the root equals to number written on it.
First line contains one integer number *n* — the number of vertices in tree (1<=≤<=*n*<=≤<=2·105). Next line contains *n* integer numbers *a**i* (1<=≤<=*i*<=≤<=*n*, 1<=≤<=*a**i*<=≤<=2·105). Each of next *n*<=-<=1 lines contains two integer numbers *x* and *y* (1<=≤<=*x*,<=*y*<=≤<=*n*, *x*<=≠<=*y*), which means that there is an edge (*x*,<=*y*) in the tree.
Output *n* numbers separated by spaces, where *i*-th number equals to maximum possible beauty of vertex *i*.
[ "2\n6 2\n1 2\n", "3\n6 2 3\n1 2\n1 3\n", "1\n10\n" ]
[ "6 6 \n", "6 6 6 \n", "10 \n" ]
none
1,500
[ { "input": "2\n6 2\n1 2", "output": "6 6 " }, { "input": "3\n6 2 3\n1 2\n1 3", "output": "6 6 6 " }, { "input": "1\n10", "output": "10 " }, { "input": "10\n2 3 4 5 6 7 8 9 10 11\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n4 8\n8 9\n9 10", "output": "2 3 2 1 1 1 1 1 1 1 " }, { "input": "4\n6 2 3 2\n1 2\n2 3\n3 4", "output": "6 6 3 2 " } ]
1,504,200,522
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
0
233
149,401,600
""" Author : Arif Ahmad Date : Algo : Difficulty : """ from sys import stdin, stdout, setrecursionlimit import threading from fractions import gcd from collections import defaultdict import math def dfs(u, depth): global a, g, ans, divs ans[u] = 1 # you can let it equal 0 for div in divs.keys(): if a[u] % div == 0: divs[div] += 1 if divs[div] >= depth: ans[u] = max(ans[u], div) # print(divs) for v in g[u]: if ans[v] == 0: dfs(v, depth + 1) # after all u's children branches, you should change the divs's value # back to it's value before you dfs to u, like what we did with back-tracking # to generate permutations, etc... for div in divs.keys(): if a[u] % div == 0: divs[div] -= 1 def main(): global a, n, g, ans, divs n = int(stdin.readline().strip()) a = [int(_) for _ in stdin.readline().strip().split()] g = [[] for _ in range(n)] for _ in range(n - 1): x, y = [int(_) for _ in stdin.readline().strip().split()] x -= 1 y -= 1 g[x].append(y) g[y].append(x) ans = [0 for _ in range(n)] # divs from the beginning should be empty, because we will calculate it # while we doing the dfs ans[0] = a[0] dfs(0, 1) # we just need to call dfs(0, 1), it will dfs from root to another # vertices and do all work for us ans = ' '.join(str(_) for _ in ans) stdout.write(ans) if __name__ == '__main__': # the following 4 lines of code are required to increase # the recursion limit and stack size setrecursionlimit(10**6) threading.stack_size(134217728) # 128MB thread = threading.Thread(target=main) thread.start()
Title: Ilya And The Tree Time Limit: None seconds Memory Limit: None megabytes Problem Description: Ilya is very fond of graphs, especially trees. During his last trip to the forest Ilya found a very interesting tree rooted at vertex 1. There is an integer number written on each vertex of the tree; the number written on vertex *i* is equal to *a**i*. Ilya believes that the beauty of the vertex *x* is the greatest common divisor of all numbers written on the vertices on the path from the root to *x*, including this vertex itself. In addition, Ilya can change the number in one arbitrary vertex to 0 or leave all vertices unchanged. Now for each vertex Ilya wants to know the maximum possible beauty it can have. For each vertex the answer must be considered independently. The beauty of the root equals to number written on it. Input Specification: First line contains one integer number *n* — the number of vertices in tree (1<=≤<=*n*<=≤<=2·105). Next line contains *n* integer numbers *a**i* (1<=≤<=*i*<=≤<=*n*, 1<=≤<=*a**i*<=≤<=2·105). Each of next *n*<=-<=1 lines contains two integer numbers *x* and *y* (1<=≤<=*x*,<=*y*<=≤<=*n*, *x*<=≠<=*y*), which means that there is an edge (*x*,<=*y*) in the tree. Output Specification: Output *n* numbers separated by spaces, where *i*-th number equals to maximum possible beauty of vertex *i*. Demo Input: ['2\n6 2\n1 2\n', '3\n6 2 3\n1 2\n1 3\n', '1\n10\n'] Demo Output: ['6 6 \n', '6 6 6 \n', '10 \n'] Note: none
```python """ Author : Arif Ahmad Date : Algo : Difficulty : """ from sys import stdin, stdout, setrecursionlimit import threading from fractions import gcd from collections import defaultdict import math def dfs(u, depth): global a, g, ans, divs ans[u] = 1 # you can let it equal 0 for div in divs.keys(): if a[u] % div == 0: divs[div] += 1 if divs[div] >= depth: ans[u] = max(ans[u], div) # print(divs) for v in g[u]: if ans[v] == 0: dfs(v, depth + 1) # after all u's children branches, you should change the divs's value # back to it's value before you dfs to u, like what we did with back-tracking # to generate permutations, etc... for div in divs.keys(): if a[u] % div == 0: divs[div] -= 1 def main(): global a, n, g, ans, divs n = int(stdin.readline().strip()) a = [int(_) for _ in stdin.readline().strip().split()] g = [[] for _ in range(n)] for _ in range(n - 1): x, y = [int(_) for _ in stdin.readline().strip().split()] x -= 1 y -= 1 g[x].append(y) g[y].append(x) ans = [0 for _ in range(n)] # divs from the beginning should be empty, because we will calculate it # while we doing the dfs ans[0] = a[0] dfs(0, 1) # we just need to call dfs(0, 1), it will dfs from root to another # vertices and do all work for us ans = ' '.join(str(_) for _ in ans) stdout.write(ans) if __name__ == '__main__': # the following 4 lines of code are required to increase # the recursion limit and stack size setrecursionlimit(10**6) threading.stack_size(134217728) # 128MB thread = threading.Thread(target=main) thread.start() ```
0
868
A
Bark to Unlock
PROGRAMMING
900
[ "brute force", "implementation", "strings" ]
null
null
As technologies develop, manufacturers are making the process of unlocking a phone as user-friendly as possible. To unlock its new phone, Arkady's pet dog Mu-mu has to bark the password once. The phone represents a password as a string of two lowercase English letters. Mu-mu's enemy Kashtanka wants to unlock Mu-mu's phone to steal some sensible information, but it can only bark *n* distinct words, each of which can be represented as a string of two lowercase English letters. Kashtanka wants to bark several words (not necessarily distinct) one after another to pronounce a string containing the password as a substring. Tell if it's possible to unlock the phone in this way, or not.
The first line contains two lowercase English letters — the password on the phone. The second line contains single integer *n* (1<=≤<=*n*<=≤<=100) — the number of words Kashtanka knows. The next *n* lines contain two lowercase English letters each, representing the words Kashtanka knows. The words are guaranteed to be distinct.
Print "YES" if Kashtanka can bark several words in a line forming a string containing the password, and "NO" otherwise. You can print each letter in arbitrary case (upper or lower).
[ "ya\n4\nah\noy\nto\nha\n", "hp\n2\nht\ntp\n", "ah\n1\nha\n" ]
[ "YES\n", "NO\n", "YES\n" ]
In the first example the password is "ya", and Kashtanka can bark "oy" and then "ah", and then "ha" to form the string "oyahha" which contains the password. So, the answer is "YES". In the second example Kashtanka can't produce a string containing password as a substring. Note that it can bark "ht" and then "tp" producing "http", but it doesn't contain the password "hp" as a substring. In the third example the string "hahahaha" contains "ah" as a substring.
250
[ { "input": "ya\n4\nah\noy\nto\nha", "output": "YES" }, { "input": "hp\n2\nht\ntp", "output": "NO" }, { "input": "ah\n1\nha", "output": "YES" }, { "input": "bb\n4\nba\nab\naa\nbb", "output": "YES" }, { "input": "bc\n4\nca\nba\nbb\ncc", "output": "YES" }, { "input": "ba\n4\ncd\nad\ncc\ncb", "output": "YES" }, { "input": "pg\n4\nzl\nxs\ndi\nxn", "output": "NO" }, { "input": "bn\n100\ndf\nyb\nze\nml\nyr\nof\nnw\nfm\ndw\nlv\nzr\nhu\nzt\nlw\nld\nmo\nxz\ntp\nmr\nou\nme\npx\nvp\nes\nxi\nnr\nbx\nqc\ngm\njs\nkn\ntw\nrq\nkz\nuc\nvc\nqr\nab\nna\nro\nya\nqy\ngu\nvk\nqk\ngs\nyq\nop\nhw\nrj\neo\nlz\nbh\nkr\nkb\nma\nrd\nza\nuf\nhq\nmc\nmn\nti\nwn\nsh\nax\nsi\nnd\ntz\ndu\nfj\nkl\nws\now\nnf\nvr\nye\nzc\niw\nfv\nkv\noo\nsm\nbc\nrs\nau\nuz\nuv\ngh\nsu\njn\ndz\nrl\nwj\nbk\nzl\nas\nms\nit\nwu", "output": "YES" }, { "input": "bb\n1\naa", "output": "NO" }, { "input": "qm\n25\nqw\nwe\ner\nrt\nty\nyu\nui\nio\nop\npa\nas\nsd\ndf\nfg\ngh\nhj\njk\nkl\nlz\nzx\nxc\ncv\nvb\nbn\nnm", "output": "NO" }, { "input": "mq\n25\nqw\nwe\ner\nrt\nty\nyu\nui\nio\nop\npa\nas\nsd\ndf\nfg\ngh\nhj\njk\nkl\nlz\nzx\nxc\ncv\nvb\nbn\nnm", "output": "YES" }, { "input": "aa\n1\naa", "output": "YES" }, { "input": "bb\n1\nbb", "output": "YES" }, { "input": "ba\n1\ncc", "output": "NO" }, { "input": "ha\n1\nha", "output": "YES" }, { "input": "aa\n1\naa", "output": "YES" }, { "input": "ez\n1\njl", "output": "NO" }, { "input": "aa\n2\nab\nba", "output": "YES" }, { "input": "aa\n2\nca\ncc", "output": "NO" }, { "input": "dd\n2\nac\ndc", "output": "NO" }, { "input": "qc\n2\nyc\nkr", "output": "NO" }, { "input": "aa\n3\nba\nbb\nab", "output": "YES" }, { "input": "ca\n3\naa\nbb\nab", "output": "NO" }, { "input": "ca\n3\nbc\nbd\nca", "output": "YES" }, { "input": "dd\n3\nmt\nrg\nxl", "output": "NO" }, { "input": "be\n20\nad\ncd\ncb\ndb\ndd\naa\nab\nca\nae\ned\ndc\nbb\nba\nda\nee\nea\ncc\nac\nec\neb", "output": "YES" }, { "input": "fc\n20\nca\nbb\nce\nfd\nde\nfa\ncc\nec\nfb\nfc\nff\nbe\ncf\nba\ndb\ned\naf\nae\nda\nef", "output": "YES" }, { "input": "ca\n20\ndc\naf\ndf\neg\naa\nbc\nea\nbd\nab\ndb\ngc\nfb\nba\nbe\nee\ngf\ncf\nag\nga\nca", "output": "YES" }, { "input": "ke\n20\nzk\nra\nbq\nqz\nwt\nzg\nmz\nuk\nge\nuv\nud\nfd\neh\ndm\nsk\nki\nfv\ntp\nat\nfb", "output": "YES" }, { "input": "hh\n50\nag\nhg\ndg\nfh\neg\ngh\ngd\nda\nbh\nab\nhf\ndc\nhb\nfe\nad\nec\nac\nfd\nca\naf\ncg\nhd\neb\nce\nhe\nha\ngb\nea\nae\nfb\nff\nbe\nch\nhh\nee\nde\nge\ngf\naa\ngg\neh\ned\nbf\nfc\nah\nga\nbd\ncb\nbg\nbc", "output": "YES" }, { "input": "id\n50\nhi\ndc\nfg\nee\ngi\nhc\nac\nih\ndg\nfc\nde\ned\nie\neb\nic\ncf\nib\nfa\ngc\nba\nbe\nga\nha\nhg\nia\ndf\nab\nei\neh\nad\nii\nci\ndh\nec\nif\ndi\nbg\nag\nhe\neg\nca\nae\ndb\naa\nid\nfh\nhh\ncc\nfb\ngb", "output": "YES" }, { "input": "fe\n50\nje\nbi\nbg\ngc\nfb\nig\ndf\nji\ndg\nfe\nfc\ncf\ngf\nai\nhe\nac\nch\nja\ngh\njf\nge\ncb\nij\ngb\ncg\naf\neh\nee\nhd\njd\njb\nii\nca\nci\nga\nab\nhi\nag\nfj\nej\nfi\nie\ndj\nfg\nef\njc\njg\njh\nhf\nha", "output": "YES" }, { "input": "rn\n50\nba\nec\nwg\nao\nlk\nmz\njj\ncf\nfa\njk\ndy\nsz\njs\nzr\nqv\ntx\nwv\nrd\nqw\nls\nrr\nvt\nrx\nkc\neh\nnj\niq\nyi\nkh\nue\nnv\nkz\nrn\nes\nua\nzf\nvu\nll\neg\nmj\ncz\nzj\nxz\net\neb\nci\nih\nig\nam\nvd", "output": "YES" }, { "input": "ee\n100\nah\nfb\ncd\nbi\nii\nai\nid\nag\nie\nha\ndi\nec\nae\nce\njb\ndg\njg\ngd\ngf\nda\nih\nbd\nhj\ngg\nhb\ndf\ned\nfh\naf\nja\nci\nfc\nic\nji\nac\nhi\nfj\nch\nbc\njd\naa\nff\nad\ngj\nej\nde\nee\nhe\ncf\nga\nia\ncg\nbb\nhc\nbe\ngi\njf\nbg\naj\njj\nbh\nfe\ndj\nef\ngb\nge\ndb\nig\ncj\ndc\nij\njh\nei\ndd\nib\nhf\neg\nbf\nfg\nab\ngc\nfd\nhd\ngh\neh\njc\neb\nhh\nca\nje\nbj\nif\nea\nhg\nfa\ncc\nba\ndh\ncb\nfi", "output": "YES" }, { "input": "if\n100\njd\nbc\nje\nhi\nga\nde\nkb\nfc\ncd\ngd\naj\ncb\nei\nbf\ncf\ndk\ndb\ncg\nki\ngg\nkg\nfa\nkj\nii\njf\njg\ngb\nbh\nbg\neh\nhj\nhb\ndg\ndj\njc\njb\nce\ndi\nig\nci\ndf\nji\nhc\nfk\naf\nac\ngk\nhd\nae\nkd\nec\nkc\neb\nfh\nij\nie\nca\nhh\nkf\nha\ndd\nif\nef\nih\nhg\nej\nfe\njk\nea\nib\nck\nhf\nak\ngi\nch\ndc\nba\nke\nad\nka\neg\njh\nja\ngc\nfd\ncc\nab\ngj\nik\nfg\nbj\nhe\nfj\nge\ngh\nhk\nbk\ned\nid\nfi", "output": "YES" }, { "input": "kd\n100\nek\nea\nha\nkf\nkj\ngh\ndl\nfj\nal\nga\nlj\nik\ngd\nid\ncb\nfh\ndk\nif\nbh\nkb\nhc\nej\nhk\ngc\ngb\nef\nkk\nll\nlf\nkh\ncl\nlh\njj\nil\nhh\nci\ndb\ndf\ngk\njg\nch\nbd\ncg\nfg\nda\neb\nlg\ndg\nbk\nje\nbg\nbl\njl\ncj\nhb\nei\naa\ngl\nka\nfa\nfi\naf\nkc\nla\ngi\nij\nib\nle\ndi\nck\nag\nlc\nca\nge\nie\nlb\nke\nii\nae\nig\nic\nhe\ncf\nhd\nak\nfb\nhi\ngf\nad\nba\nhg\nbi\nkl\nac\ngg\ngj\nbe\nlk\nld\naj", "output": "YES" }, { "input": "ab\n1\nab", "output": "YES" }, { "input": "ya\n1\nya", "output": "YES" }, { "input": "ay\n1\nyb", "output": "NO" }, { "input": "ax\n2\nii\nxa", "output": "YES" }, { "input": "hi\n1\nhi", "output": "YES" }, { "input": "ag\n1\nag", "output": "YES" }, { "input": "th\n1\nth", "output": "YES" }, { "input": "sb\n1\nsb", "output": "YES" }, { "input": "hp\n1\nhp", "output": "YES" }, { "input": "ah\n1\nah", "output": "YES" }, { "input": "ta\n1\nta", "output": "YES" }, { "input": "tb\n1\ntb", "output": "YES" }, { "input": "ab\n5\nca\nda\nea\nfa\nka", "output": "NO" }, { "input": "ac\n1\nac", "output": "YES" }, { "input": "ha\n2\nha\nzz", "output": "YES" }, { "input": "ok\n1\nok", "output": "YES" }, { "input": "bc\n1\nbc", "output": "YES" }, { "input": "az\n1\nzz", "output": "NO" }, { "input": "ab\n2\nba\ntt", "output": "YES" }, { "input": "ah\n2\nap\nhp", "output": "NO" }, { "input": "sh\n1\nsh", "output": "YES" }, { "input": "az\n1\nby", "output": "NO" }, { "input": "as\n1\nas", "output": "YES" }, { "input": "ab\n2\nab\ncd", "output": "YES" }, { "input": "ab\n2\nxa\nza", "output": "NO" }, { "input": "ab\n2\net\nab", "output": "YES" }, { "input": "ab\n1\naa", "output": "NO" }, { "input": "ab\n2\nab\nde", "output": "YES" }, { "input": "ah\n2\nba\nha", "output": "YES" }, { "input": "ha\n3\ndd\ncc\nha", "output": "YES" }, { "input": "oo\n1\nox", "output": "NO" }, { "input": "ab\n2\nax\nbx", "output": "NO" }, { "input": "ww\n4\nuw\now\npo\nko", "output": "NO" }, { "input": "ay\n1\nay", "output": "YES" }, { "input": "yo\n1\nyo", "output": "YES" }, { "input": "ba\n1\nba", "output": "YES" }, { "input": "qw\n1\nqw", "output": "YES" }, { "input": "la\n1\nla", "output": "YES" }, { "input": "ab\n2\nbb\nbc", "output": "NO" }, { "input": "aa\n2\nab\nac", "output": "NO" }, { "input": "ah\n2\nbb\nha", "output": "YES" }, { "input": "ya\n42\nab\nac\nad\nae\naf\nag\nah\nai\nak\naj\nba\nbc\nbd\nbe\nbf\nbg\nbh\nbi\nbk\nbj\ncb\nca\ncd\nce\ncf\ncg\nch\nci\nck\ncj\ndb\ndc\nda\nde\ndf\ndg\ndh\ndi\ndk\ndj\nef\nek", "output": "NO" }, { "input": "ab\n3\nab\nxx\nyy", "output": "YES" }, { "input": "ab\n2\nab\ncc", "output": "YES" }, { "input": "sa\n2\nxx\nas", "output": "YES" }, { "input": "ma\n1\nma", "output": "YES" }, { "input": "ba\n1\nbb", "output": "NO" }, { "input": "bc\n1\nab", "output": "NO" }, { "input": "fa\n1\nfa", "output": "YES" }, { "input": "ap\n1\nap", "output": "YES" }, { "input": "ab\n1\nbb", "output": "NO" }, { "input": "bk\n1\nbk", "output": "YES" }, { "input": "xy\n2\nxy\naa", "output": "YES" }, { "input": "ab\n2\nza\nbz", "output": "YES" } ]
1,507,188,234
1,134
Python 3
SKIPPED
PRETESTS
8
46
0
import sys read = sys.stdin.readline def solve(string, n, lst): find_first = False find_second = False for each in lst: if each == string: return "YES" if string[0] == each[1]: find_first = True if string[1] == each[0]: find_second = True if find_first and find_second: return "YES" return "NO" def run(): string = read().replace("\n", "") n = int(read().replace("\n", "")) lst = [] for _ in range(n): lst.append(read().replace("\n", "")) print(solve(string, n, lst)) run()
Title: Bark to Unlock Time Limit: None seconds Memory Limit: None megabytes Problem Description: As technologies develop, manufacturers are making the process of unlocking a phone as user-friendly as possible. To unlock its new phone, Arkady's pet dog Mu-mu has to bark the password once. The phone represents a password as a string of two lowercase English letters. Mu-mu's enemy Kashtanka wants to unlock Mu-mu's phone to steal some sensible information, but it can only bark *n* distinct words, each of which can be represented as a string of two lowercase English letters. Kashtanka wants to bark several words (not necessarily distinct) one after another to pronounce a string containing the password as a substring. Tell if it's possible to unlock the phone in this way, or not. Input Specification: The first line contains two lowercase English letters — the password on the phone. The second line contains single integer *n* (1<=≤<=*n*<=≤<=100) — the number of words Kashtanka knows. The next *n* lines contain two lowercase English letters each, representing the words Kashtanka knows. The words are guaranteed to be distinct. Output Specification: Print "YES" if Kashtanka can bark several words in a line forming a string containing the password, and "NO" otherwise. You can print each letter in arbitrary case (upper or lower). Demo Input: ['ya\n4\nah\noy\nto\nha\n', 'hp\n2\nht\ntp\n', 'ah\n1\nha\n'] Demo Output: ['YES\n', 'NO\n', 'YES\n'] Note: In the first example the password is "ya", and Kashtanka can bark "oy" and then "ah", and then "ha" to form the string "oyahha" which contains the password. So, the answer is "YES". In the second example Kashtanka can't produce a string containing password as a substring. Note that it can bark "ht" and then "tp" producing "http", but it doesn't contain the password "hp" as a substring. In the third example the string "hahahaha" contains "ah" as a substring.
```python import sys read = sys.stdin.readline def solve(string, n, lst): find_first = False find_second = False for each in lst: if each == string: return "YES" if string[0] == each[1]: find_first = True if string[1] == each[0]: find_second = True if find_first and find_second: return "YES" return "NO" def run(): string = read().replace("\n", "") n = int(read().replace("\n", "")) lst = [] for _ in range(n): lst.append(read().replace("\n", "")) print(solve(string, n, lst)) run() ```
-1
92
B
Binary Number
PROGRAMMING
1,300
[ "greedy" ]
B. Binary Number
1
256
Little walrus Fangy loves math very much. That's why when he is bored he plays with a number performing some operations. Fangy takes some positive integer *x* and wants to get a number one from it. While *x* is not equal to 1, Fangy repeats the following action: if *x* is odd, then he adds 1 to it, otherwise he divides *x* by 2. Fangy knows that for any positive integer number the process ends in finite time. How many actions should Fangy perform to get a number one from number *x*?
The first line contains a positive integer *x* in a binary system. It is guaranteed that the first digit of *x* is different from a zero and the number of its digits does not exceed 106.
Print the required number of actions.
[ "1\n", "1001001\n", "101110\n" ]
[ "0\n", "12\n", "8\n" ]
Let's consider the third sample. Number 101110 is even, which means that we should divide it by 2. After the dividing Fangy gets an odd number 10111 and adds one to it. Number 11000 can be divided by 2 three times in a row and get number 11. All that's left is to increase the number by one (we get 100), and then divide it by 2 two times in a row. As a result, we get 1.
1,000
[ { "input": "1", "output": "0" }, { "input": "1001001", "output": "12" }, { "input": "101110", "output": "8" }, { "input": "11", "output": "3" }, { "input": "11110001101", "output": "16" }, { "input": "1010101001001111000111110011111000010101011111101010", "output": "74" }, { "input": "1100000010010100111011100011110101111", "output": "55" }, { "input": "11000111111110110110100110110101111100010100110110010", "output": "74" }, { "input": "11100000110100011110101001101111100000011001111000011110000000111110111", "output": "106" }, { "input": "1000101100110000000001111010110000000010001001111110011011000011101011001001010010111", "output": "133" }, { "input": "1000000000000000000000000000000000000000000000000000000000000000000000000", "output": "72" }, { "input": "10000100000", "output": "16" } ]
1,382,160,808
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
8
92
307,200
n=int(input(),2) #print (n) c=0 while(n>1): if(n%2==0): n/=2 c+=1 else: n=n+1 c+=1; print (c)
Title: Binary Number Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Little walrus Fangy loves math very much. That's why when he is bored he plays with a number performing some operations. Fangy takes some positive integer *x* and wants to get a number one from it. While *x* is not equal to 1, Fangy repeats the following action: if *x* is odd, then he adds 1 to it, otherwise he divides *x* by 2. Fangy knows that for any positive integer number the process ends in finite time. How many actions should Fangy perform to get a number one from number *x*? Input Specification: The first line contains a positive integer *x* in a binary system. It is guaranteed that the first digit of *x* is different from a zero and the number of its digits does not exceed 106. Output Specification: Print the required number of actions. Demo Input: ['1\n', '1001001\n', '101110\n'] Demo Output: ['0\n', '12\n', '8\n'] Note: Let's consider the third sample. Number 101110 is even, which means that we should divide it by 2. After the dividing Fangy gets an odd number 10111 and adds one to it. Number 11000 can be divided by 2 three times in a row and get number 11. All that's left is to increase the number by one (we get 100), and then divide it by 2 two times in a row. As a result, we get 1.
```python n=int(input(),2) #print (n) c=0 while(n>1): if(n%2==0): n/=2 c+=1 else: n=n+1 c+=1; print (c) ```
0
767
A
Snacktower
PROGRAMMING
1,100
[ "data structures", "implementation" ]
null
null
According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time *n* snacks of distinct sizes will fall on the city, and the residents should build a Snacktower of them by placing snacks one on another. Of course, big snacks should be at the bottom of the tower, while small snacks should be at the top. Years passed, and once different snacks started to fall onto the city, and the residents began to build the Snacktower. However, they faced some troubles. Each day exactly one snack fell onto the city, but their order was strange. So, at some days the residents weren't able to put the new stack on the top of the Snacktower: they had to wait until all the bigger snacks fell. Of course, in order to not to anger miss Fortune again, the residents placed each snack on the top of the tower immediately as they could do it. Write a program that models the behavior of Ankh-Morpork residents.
The first line contains single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the total number of snacks. The second line contains *n* integers, the *i*-th of them equals the size of the snack which fell on the *i*-th day. Sizes are distinct integers from 1 to *n*.
Print *n* lines. On the *i*-th of them print the sizes of the snacks which the residents placed on the top of the Snacktower on the *i*-th day in the order they will do that. If no snack is placed on some day, leave the corresponding line empty.
[ "3\n3 1 2\n", "5\n4 5 1 2 3\n" ]
[ "3\n \n2 1", "5 4\n \n \n3 2 1\n" ]
In the example a snack of size 3 fell on the first day, and the residents immediately placed it. On the second day a snack of size 1 fell, and the residents weren't able to place it because they were missing the snack of size 2. On the third day a snack of size 2 fell, and the residents immediately placed it. Right after that they placed the snack of size 1 which had fallen before.
500
[ { "input": "3\n3 1 2", "output": "3 \n\n2 1 " }, { "input": "5\n4 5 1 2 3", "output": "5 4 \n\n\n3 2 1 " }, { "input": "1\n1", "output": "1 " }, { "input": "2\n1 2", "output": "2 1 " }, { "input": "10\n5 1 6 2 8 3 4 10 9 7", "output": "10 \n9 8 \n7 6 5 4 3 2 1 " }, { "input": "30\n16 10 4 29 5 28 12 21 11 30 18 6 14 3 17 22 20 15 9 1 27 19 24 26 13 25 2 23 8 7", "output": "30 29 28 \n\n\n\n\n\n\n\n\n\n\n27 \n\n\n26 \n\n25 24 \n\n23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 \n8 \n7 6 5 4 3 2 1 " }, { "input": "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 4 80 72 39", "output": "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\n99 98 \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 \n\n\n\n\n\n\n\n\n80 79 78 77 76 75 74 73 \n72 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 \n39 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 " }, { "input": "2\n2 1", "output": "2 \n1 " } ]
1,597,514,117
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
93
307,200
n = int(input()) l = list(map(int,input().split())) visited = [] req = n flag = 1 for i in l: if i != req: visited.append(i) if flag == 1: print("\n",end="") flag = 0 else: print("\n") else: print(req,end=" ") req-=1 while req in visited: print(req,end=' ') req-=1 flag = 1 print(" ")
Title: Snacktower Time Limit: None seconds Memory Limit: None megabytes Problem Description: According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time *n* snacks of distinct sizes will fall on the city, and the residents should build a Snacktower of them by placing snacks one on another. Of course, big snacks should be at the bottom of the tower, while small snacks should be at the top. Years passed, and once different snacks started to fall onto the city, and the residents began to build the Snacktower. However, they faced some troubles. Each day exactly one snack fell onto the city, but their order was strange. So, at some days the residents weren't able to put the new stack on the top of the Snacktower: they had to wait until all the bigger snacks fell. Of course, in order to not to anger miss Fortune again, the residents placed each snack on the top of the tower immediately as they could do it. Write a program that models the behavior of Ankh-Morpork residents. Input Specification: The first line contains single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the total number of snacks. The second line contains *n* integers, the *i*-th of them equals the size of the snack which fell on the *i*-th day. Sizes are distinct integers from 1 to *n*. Output Specification: Print *n* lines. On the *i*-th of them print the sizes of the snacks which the residents placed on the top of the Snacktower on the *i*-th day in the order they will do that. If no snack is placed on some day, leave the corresponding line empty. Demo Input: ['3\n3 1 2\n', '5\n4 5 1 2 3\n'] Demo Output: ['3\n\xa0\n2 1', '5 4\n\xa0\n\xa0\n3 2 1\n'] Note: In the example a snack of size 3 fell on the first day, and the residents immediately placed it. On the second day a snack of size 1 fell, and the residents weren't able to place it because they were missing the snack of size 2. On the third day a snack of size 2 fell, and the residents immediately placed it. Right after that they placed the snack of size 1 which had fallen before.
```python n = int(input()) l = list(map(int,input().split())) visited = [] req = n flag = 1 for i in l: if i != req: visited.append(i) if flag == 1: print("\n",end="") flag = 0 else: print("\n") else: print(req,end=" ") req-=1 while req in visited: print(req,end=' ') req-=1 flag = 1 print(" ") ```
0
548
A
Mike and Fax
PROGRAMMING
1,100
[ "brute force", "implementation", "strings" ]
null
null
While Mike was walking in the subway, all the stuff in his back-bag dropped on the ground. There were several fax messages among them. He concatenated these strings in some order and now he has string *s*. He is not sure if this is his own back-bag or someone else's. He remembered that there were exactly *k* messages in his own bag, each was a palindrome string and all those strings had the same length. He asked you to help him and tell him if he has worn his own back-bag. Check if the given string *s* is a concatenation of *k* palindromes of the same length.
The first line of input contains string *s* containing lowercase English letters (1<=≤<=|*s*|<=≤<=1000). The second line contains integer *k* (1<=≤<=*k*<=≤<=1000).
Print "YES"(without quotes) if he has worn his own back-bag or "NO"(without quotes) otherwise.
[ "saba\n2\n", "saddastavvat\n2\n" ]
[ "NO\n", "YES\n" ]
Palindrome is a string reading the same forward and backward. In the second sample, the faxes in his back-bag can be "saddas" and "tavvat".
500
[ { "input": "saba\n2", "output": "NO" }, { "input": "saddastavvat\n2", "output": "YES" }, { "input": "aaaaaaaaaa\n3", "output": "NO" }, { "input": "aaaaaa\n3", "output": "YES" }, { "input": "abaacca\n2", "output": "NO" }, { "input": "a\n1", "output": "YES" }, { "input": "princeofpersia\n1", "output": "NO" }, { "input": "xhwbdoryfiaxglripavycmxmcejbcpzidrqsqvikfzjyfnmedxrvlnusavyhillaxrblkynwdrlhthtqzjktzkullgrqsolqssocpfwcaizhovajlhmeibhiuwtxpljkyyiwykzpmazkkzampzkywiyykjlpxtwuihbiemhljavohziacwfpcossqlosqrgllukztkjzqththlrdwnyklbrxallihyvasunlvrxdemnfyjzfkivqsqrdizpcbjecmxmcyvapirlgxaifyrodbwhx\n1", "output": "YES" }, { "input": "yfhqnbzaqeqmcvtsbcdn\n456", "output": "NO" }, { "input": "lgsdfiforlqrohhjyzrigewkigiiffvbyrapzmjvtkklndeyuqpuukajgtguhlarjdqlxksyekbjgrmhuyiqdlzjqqzlxufffpelyptodwhvkfbalxbufrlcsjgxmfxeqsszqghcustqrqjljattgvzynyvfbjgbuynbcguqtyfowgtcbbaywvcrgzrulqpghwoflutswu\n584", "output": "NO" }, { "input": "awlrhmxxivqbntvtapwkdkunamcqoerfncfmookhdnuxtttlxmejojpwbdyxirdsjippzjhdrpjepremruczbedxrjpodlyyldopjrxdebzcurmerpejprdhjzppijsdrixydbwpjojemxltttxundhkoomfcnfreoqcmanukdkwpatvtnbqvixxmhrlwa\n1", "output": "YES" }, { "input": "kafzpsglcpzludxojtdhzynpbekzssvhzizfrboxbhqvojiqtjitrackqccxgenwwnegxccqkcartijtqijovqhbxobrfzizhvsszkebpnyzhdtjoxdulzpclgspzfakvcbbjejeubvrrzlvjjgrcprntbyuakoxowoybbxgdugjffgbtfwrfiobifrshyaqqayhsrfiboifrwftbgffjgudgxbbyowoxokauybtnrpcrgjjvlzrrvbuejejbbcv\n2", "output": "YES" }, { "input": "zieqwmmbrtoxysvavwdemmdeatfrolsqvvlgphhhmojjfxfurtuiqdiilhlcwwqedlhblrzmvuoaczcwrqzyymiggpvbpkycibsvkhytrzhguksxyykkkvfljbbnjblylftmqxkojithwsegzsaexlpuicexbdzpwesrkzbqltxhifwqcehzsjgsqbwkujvjbjpqxdpmlimsusumizizpyigmkxwuberthdghnepyrxzvvidxeafwylegschhtywvqsxuqmsddhkzgkdiekodqpnftdyhnpicsnbhfxemxllvaurkmjvtrmqkulerxtaolmokiqqvqgechkqxmendpmgxwiaffcajmqjmvrwryzxujmiasuqtosuisiclnv\n8", "output": "NO" }, { "input": "syghzncbi\n829", "output": "NO" }, { "input": "ljpdpstntznciejqqtpysskztdfawuncqzwwfefrfsihyrdopwawowshquqnjhesxszuywezpebpzhtopgngrnqgwnoqhyrykojguybvdbjpfpmvkxscocywzsxcivysfrrzsonayztzzuybrkiombhqcfkszyscykzistiobrpavezedgobowjszfadcccmxyqehmkgywiwxffibzetb\n137", "output": "NO" }, { "input": "eytuqriplfczwsqlsnjetfpzehzvzayickkbnfqddaisfpasvigwtnvbybwultsgrtjbaebktvubwofysgidpufzteuhuaaqkhmhguockoczlrmlrrzouvqtwbcchxxiydbohnvrmtqjzhkfmvdulojhdvgwudvidpausvfujkjprxsobliuauxleqvsmz\n253", "output": "NO" }, { "input": "xkaqgwabuilhuqwhnrdtyattmqcjfbiqodjlwzgcyvghqncklbhnlmagvjvwysrfryrlmclninogumjfmyenkmydlmifxpkvlaapgnfarejaowftxxztshsesjtsgommaeslrhronruqdurvjesydrzmxirmxumrcqezznqltngsgdcthivdnjnshjfujtiqsltpttgbljfcbqsfwbzokciqlavrthgaqbzikpwwsebzwddlvdwrmztwmhcxdinwlbklwmteeybbdbzevfbsrtldapulwgusuvnreiflkytonzmervyrlbqhzapgxepwauaiwygpxarfeyqhimzlxntjuaaigeisgrvwgbhqemqetzyallzaoqprhzpjibkutgwrodruqu\n857", "output": "NO" }, { "input": "rbehjxpblnzfgeebpkvzznwtzszghjuuxovreapmwehqyjymrkmksffbdpbdyegulabsmjiykeeqtuvqqyxlitpxjdpwmqtlmudqsksgwqekvwfjdsggzajcpsyserkctpbajgzdbiqaekfaepnecezdzamqszpwfvhlannszgaiewvcdnnvzhblmuzjtqeyjcqjqoxatavavokyxokuxwuqueskktxnxraihnqovrfykpzsyjmrhqsvbobzsnfqwvdwatvjxaubtiwhgvrqwjhgfnauqegqmcwnaruinplmtmxhvohhqgvcatsdqiwkvslhqzqevdgdhpijjevuyuitnixdjhwlmjsstmugownjdhvxueg\n677", "output": "NO" }, { "input": "a\n3", "output": "NO" }, { "input": "aa\n2", "output": "YES" }, { "input": "abcaabca\n2", "output": "NO" }, { "input": "aaaaaaaaab\n5", "output": "NO" }, { "input": "aabbb\n3", "output": "NO" }, { "input": "abcde\n5", "output": "YES" }, { "input": "aabc\n2", "output": "NO" }, { "input": "aabcaa\n3", "output": "NO" } ]
1,435,930,023
423
Python 3
COMPILATION_ERROR
TESTS
0
0
0
#include <cstring> #include <iostream> #include <iomanip> #include <algorithm> #include <vector> #include <cstdio> #include <string> #include <cstdlib> #include <string> #include <set> #include <sstream> #include <map> using namespace std; string s; int k; void no() { cout << "NO"; exit(0); } int check(int l, int r) { // for(int i = l; i < r; i++) // cout << s[i]; cout << endl; r--; for(;l <= r; l++, r--) if (s[l] != s[r]) return 0; return 1; } int main() { //#ifndef LOCAL // freopen("input.txt", "rt", stdin); // freopen("output.txt", "wt", stdout); //#endif cin >> s >> k; if (s.size() < k) no(); if (s.size() % k != 0) no(); int t = (int)s.size() / k; for(int i = 0; i < s.size(); i += t) { if (!check(i, i + t)) no(); } cout << "YES"; return 0; }
Title: Mike and Fax Time Limit: None seconds Memory Limit: None megabytes Problem Description: While Mike was walking in the subway, all the stuff in his back-bag dropped on the ground. There were several fax messages among them. He concatenated these strings in some order and now he has string *s*. He is not sure if this is his own back-bag or someone else's. He remembered that there were exactly *k* messages in his own bag, each was a palindrome string and all those strings had the same length. He asked you to help him and tell him if he has worn his own back-bag. Check if the given string *s* is a concatenation of *k* palindromes of the same length. Input Specification: The first line of input contains string *s* containing lowercase English letters (1<=≤<=|*s*|<=≤<=1000). The second line contains integer *k* (1<=≤<=*k*<=≤<=1000). Output Specification: Print "YES"(without quotes) if he has worn his own back-bag or "NO"(without quotes) otherwise. Demo Input: ['saba\n2\n', 'saddastavvat\n2\n'] Demo Output: ['NO\n', 'YES\n'] Note: Palindrome is a string reading the same forward and backward. In the second sample, the faxes in his back-bag can be "saddas" and "tavvat".
```python #include <cstring> #include <iostream> #include <iomanip> #include <algorithm> #include <vector> #include <cstdio> #include <string> #include <cstdlib> #include <string> #include <set> #include <sstream> #include <map> using namespace std; string s; int k; void no() { cout << "NO"; exit(0); } int check(int l, int r) { // for(int i = l; i < r; i++) // cout << s[i]; cout << endl; r--; for(;l <= r; l++, r--) if (s[l] != s[r]) return 0; return 1; } int main() { //#ifndef LOCAL // freopen("input.txt", "rt", stdin); // freopen("output.txt", "wt", stdout); //#endif cin >> s >> k; if (s.size() < k) no(); if (s.size() % k != 0) no(); int t = (int)s.size() / k; for(int i = 0; i < s.size(); i += t) { if (!check(i, i + t)) no(); } cout << "YES"; return 0; } ```
-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,699,176,399
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
2
1,000
0
n=int(input()) sum=0 for i in range(1,n+1): f=((-1)**i)*i sum=sum+f print(sum)
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 n=int(input()) sum=0 for i in range(1,n+1): f=((-1)**i)*i sum=sum+f print(sum) ```
0
144
A
Arrival of the General
PROGRAMMING
800
[ "implementation" ]
null
null
A Ministry for Defense sent a general to inspect the Super Secret Military Squad under the command of the Colonel SuperDuper. Having learned the news, the colonel ordered to all *n* squad soldiers to line up on the parade ground. By the military charter the soldiers should stand in the order of non-increasing of their height. But as there's virtually no time to do that, the soldiers lined up in the arbitrary order. However, the general is rather short-sighted and he thinks that the soldiers lined up correctly if the first soldier in the line has the maximum height and the last soldier has the minimum height. Please note that the way other solders are positioned does not matter, including the case when there are several soldiers whose height is maximum or minimum. Only the heights of the first and the last soldier are important. For example, the general considers the sequence of heights (4, 3, 4, 2, 1, 1) correct and the sequence (4, 3, 1, 2, 2) wrong. Within one second the colonel can swap any two neighboring soldiers. Help him count the minimum time needed to form a line-up which the general will consider correct.
The first input line contains the only integer *n* (2<=≤<=*n*<=≤<=100) which represents the number of soldiers in the line. The second line contains integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) the values of the soldiers' heights in the order of soldiers' heights' increasing in the order from the beginning of the line to its end. The numbers are space-separated. Numbers *a*1,<=*a*2,<=...,<=*a**n* are not necessarily different.
Print the only integer — the minimum number of seconds the colonel will need to form a line-up the general will like.
[ "4\n33 44 11 22\n", "7\n10 10 58 31 63 40 76\n" ]
[ "2\n", "10\n" ]
In the first sample the colonel will need to swap the first and second soldier and then the third and fourth soldier. That will take 2 seconds. The resulting position of the soldiers is (44, 33, 22, 11). In the second sample the colonel may swap the soldiers in the following sequence: 1. (10, 10, 58, 31, 63, 40, 76) 1. (10, 58, 10, 31, 63, 40, 76) 1. (10, 58, 10, 31, 63, 76, 40) 1. (10, 58, 10, 31, 76, 63, 40) 1. (10, 58, 31, 10, 76, 63, 40) 1. (10, 58, 31, 76, 10, 63, 40) 1. (10, 58, 31, 76, 63, 10, 40) 1. (10, 58, 76, 31, 63, 10, 40) 1. (10, 76, 58, 31, 63, 10, 40) 1. (76, 10, 58, 31, 63, 10, 40) 1. (76, 10, 58, 31, 63, 40, 10)
500
[ { "input": "4\n33 44 11 22", "output": "2" }, { "input": "7\n10 10 58 31 63 40 76", "output": "10" }, { "input": "2\n88 89", "output": "1" }, { "input": "5\n100 95 100 100 88", "output": "0" }, { "input": "7\n48 48 48 48 45 45 45", "output": "0" }, { "input": "10\n68 47 67 29 63 71 71 65 54 56", "output": "10" }, { "input": "15\n77 68 96 60 92 75 61 60 66 79 80 65 60 95 92", "output": "4" }, { "input": "3\n1 2 1", "output": "1" }, { "input": "20\n30 30 30 14 30 14 30 30 30 14 30 14 14 30 14 14 30 14 14 14", "output": "0" }, { "input": "35\n37 41 46 39 47 39 44 47 44 42 44 43 47 39 46 39 38 42 39 37 40 44 41 42 41 42 39 42 36 36 42 36 42 42 42", "output": "7" }, { "input": "40\n99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 98 99 99 99 99 99 99 99 99 100 99 99 99 99 99 99", "output": "47" }, { "input": "50\n48 52 44 54 53 56 62 49 39 41 53 39 40 64 53 50 62 48 40 52 51 48 40 52 61 62 62 61 48 64 55 57 56 40 48 58 41 60 60 56 64 50 64 45 48 45 46 63 59 57", "output": "50" }, { "input": "57\n7 24 17 19 6 19 10 11 12 22 14 5 5 11 13 10 24 19 24 24 24 11 21 20 4 14 24 24 18 13 24 3 20 3 3 3 3 9 3 9 22 22 16 3 3 3 15 11 3 3 8 17 10 13 3 14 13", "output": "3" }, { "input": "65\n58 50 35 44 35 37 36 58 38 36 58 56 56 49 48 56 58 43 40 44 52 44 58 58 57 50 43 35 55 39 38 49 53 56 50 42 41 56 34 57 49 38 34 51 56 38 58 40 53 46 48 34 38 43 49 49 58 56 41 43 44 34 38 48 36", "output": "3" }, { "input": "69\n70 48 49 48 49 71 48 53 55 69 48 53 54 58 53 63 48 48 69 67 72 75 71 75 74 74 57 63 65 60 48 48 65 48 48 51 50 49 62 53 76 68 76 56 76 76 64 76 76 57 61 76 73 51 59 76 65 50 69 50 76 67 76 63 62 74 74 58 73", "output": "73" }, { "input": "75\n70 65 64 71 71 64 71 64 68 71 65 64 65 68 71 66 66 69 68 63 69 65 71 69 68 68 71 67 71 65 65 65 71 71 65 69 63 66 62 67 64 63 62 64 67 65 62 69 62 64 69 62 67 64 67 70 64 63 64 64 69 62 62 64 70 62 62 68 67 69 62 64 66 70 68", "output": "7" }, { "input": "84\n92 95 84 85 94 80 90 86 80 92 95 84 86 83 86 83 93 91 95 92 84 88 82 84 84 84 80 94 93 80 94 80 95 83 85 80 95 95 80 84 86 92 83 81 90 87 81 89 92 93 80 87 90 85 93 85 93 94 93 89 94 83 93 91 80 83 90 94 95 80 95 92 85 84 93 94 94 82 91 95 95 89 85 94", "output": "15" }, { "input": "90\n86 87 72 77 82 71 75 78 61 67 79 90 64 94 94 74 85 87 73 76 71 71 60 69 77 73 76 80 82 57 62 57 57 83 76 72 75 87 72 94 77 85 59 82 86 69 62 80 95 73 83 94 79 85 91 68 85 74 93 95 68 75 89 93 83 78 95 78 83 77 81 85 66 92 63 65 75 78 67 91 77 74 59 86 77 76 90 67 70 64", "output": "104" }, { "input": "91\n94 98 96 94 95 98 98 95 98 94 94 98 95 95 99 97 97 94 95 98 94 98 96 98 96 98 97 95 94 94 94 97 94 96 98 98 98 94 96 95 94 95 97 97 97 98 94 98 96 95 98 96 96 98 94 97 96 98 97 95 97 98 94 95 94 94 97 94 96 97 97 93 94 95 95 94 96 98 97 96 94 98 98 96 96 96 96 96 94 96 97", "output": "33" }, { "input": "92\n44 28 32 29 41 41 36 39 40 39 41 35 41 28 35 27 41 34 28 38 43 43 41 38 27 26 28 36 30 29 39 32 35 35 32 30 39 30 37 27 41 41 28 30 43 31 35 33 36 28 44 40 41 35 31 42 37 38 37 34 39 40 27 40 33 33 44 43 34 33 34 34 35 38 38 37 30 39 35 41 45 42 41 32 33 33 31 30 43 41 43 43", "output": "145" }, { "input": "93\n46 32 52 36 39 30 57 63 63 30 32 44 27 59 46 38 40 45 44 62 35 36 51 48 39 58 36 51 51 51 48 58 59 36 29 35 31 49 64 60 34 38 42 56 33 42 52 31 63 34 45 51 35 45 33 53 33 62 31 38 66 29 51 54 28 61 32 45 57 41 36 34 47 36 31 28 67 48 52 46 32 40 64 58 27 53 43 57 34 66 43 39 26", "output": "76" }, { "input": "94\n56 55 54 31 32 42 46 29 24 54 40 40 20 45 35 56 32 33 51 39 26 56 21 56 51 27 29 39 56 52 54 43 43 55 48 51 44 49 52 49 23 19 19 28 20 26 45 33 35 51 42 36 25 25 38 23 21 35 54 50 41 20 37 28 42 20 22 43 37 34 55 21 24 38 19 41 45 34 19 33 44 54 38 31 23 53 35 32 47 40 39 31 20 34", "output": "15" }, { "input": "95\n57 71 70 77 64 64 76 81 81 58 63 75 81 77 71 71 71 60 70 70 69 67 62 64 78 64 69 62 76 76 57 70 68 77 70 68 73 77 79 73 60 57 69 60 74 65 58 75 75 74 73 73 65 75 72 57 81 62 62 70 67 58 76 57 79 81 68 64 58 77 70 59 79 64 80 58 71 59 81 71 80 64 78 80 78 65 70 68 78 80 57 63 64 76 81", "output": "11" }, { "input": "96\n96 95 95 95 96 97 95 97 96 95 98 96 97 95 98 96 98 96 98 96 98 95 96 95 95 95 97 97 95 95 98 98 95 96 96 95 97 96 98 96 95 97 97 95 97 97 95 94 96 96 97 96 97 97 96 94 94 97 95 95 95 96 95 96 95 97 97 95 97 96 95 94 97 97 97 96 97 95 96 94 94 95 97 94 94 97 97 97 95 97 97 95 94 96 95 95", "output": "13" }, { "input": "97\n14 15 12 12 13 15 12 15 12 12 12 12 12 14 15 15 13 12 15 15 12 12 12 13 14 15 15 13 14 15 14 14 14 14 12 13 12 13 13 12 15 12 13 13 15 12 15 13 12 13 13 13 14 13 12 15 14 13 14 15 13 14 14 13 14 12 15 12 14 12 13 14 15 14 13 15 13 12 15 15 15 13 15 15 13 14 16 16 16 13 15 13 15 14 15 15 15", "output": "104" }, { "input": "98\n37 69 35 70 58 69 36 47 41 63 60 54 49 35 55 50 35 53 52 43 35 41 40 49 38 35 48 70 42 35 35 65 56 54 44 59 59 48 51 49 59 67 35 60 69 35 58 50 35 44 48 69 41 58 44 45 35 47 70 61 49 47 37 39 35 51 44 70 72 65 36 41 63 63 48 66 45 50 50 71 37 52 72 67 72 39 72 39 36 64 48 72 69 49 45 72 72 67", "output": "100" }, { "input": "99\n31 31 16 15 19 31 19 22 29 27 12 22 28 30 25 33 26 25 19 22 34 21 17 33 31 22 16 26 22 30 31 17 13 33 13 17 28 25 18 33 27 22 31 22 13 27 20 22 23 15 24 32 29 13 16 20 32 33 14 33 19 27 16 28 25 17 17 28 18 26 32 33 19 23 30 13 14 23 24 28 14 28 22 20 30 14 24 23 17 29 18 28 29 21 28 18 16 24 32", "output": "107" }, { "input": "100\n37 54 39 29 32 49 21 13 34 21 16 42 34 27 16 26 7 34 51 9 11 27 16 40 36 7 48 52 30 42 42 52 51 11 32 26 6 7 28 54 48 51 6 54 42 20 51 48 46 4 4 31 47 6 9 16 8 23 36 50 49 30 47 37 45 24 48 26 8 50 18 24 27 13 39 7 37 34 5 43 42 19 34 23 52 38 35 6 29 11 53 49 21 29 36 22 45 33 51 22", "output": "50" }, { "input": "100\n41 5 20 23 5 47 28 28 64 5 12 14 34 56 22 48 6 52 39 55 62 40 24 54 39 28 56 27 35 51 14 24 38 10 55 20 39 62 52 2 30 55 49 48 15 23 59 44 31 28 66 29 62 59 31 13 28 12 50 45 41 47 29 27 64 66 14 39 62 22 44 63 24 5 63 17 42 7 25 41 49 33 31 51 63 3 37 66 19 9 2 40 16 45 56 21 34 29 39 61", "output": "59" }, { "input": "100\n66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95", "output": "99" }, { "input": "100\n81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10", "output": "0" }, { "input": "3\n2 1 2", "output": "1" }, { "input": "2\n100 99", "output": "0" }, { "input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100", "output": "197" }, { "input": "100\n87 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 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", "output": "0" }, { "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": "0" }, { "input": "2\n1 1", "output": "0" }, { "input": "3\n2 2 2", "output": "0" }, { "input": "3\n1 3 2", "output": "2" } ]
1,692,349,631
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
3
124
0
n = int(input()) s = [int(i) for i in input().split()] new_s = [] for i in range(len(s)): if s[i] not in new_s: new_s.append(s[i]) i = new_s.index(max(new_s)) j = new_s.index(min(new_s)) res = i if i > j: res -= 1 res += n - j - 1 print(res)
Title: Arrival of the General Time Limit: None seconds Memory Limit: None megabytes Problem Description: A Ministry for Defense sent a general to inspect the Super Secret Military Squad under the command of the Colonel SuperDuper. Having learned the news, the colonel ordered to all *n* squad soldiers to line up on the parade ground. By the military charter the soldiers should stand in the order of non-increasing of their height. But as there's virtually no time to do that, the soldiers lined up in the arbitrary order. However, the general is rather short-sighted and he thinks that the soldiers lined up correctly if the first soldier in the line has the maximum height and the last soldier has the minimum height. Please note that the way other solders are positioned does not matter, including the case when there are several soldiers whose height is maximum or minimum. Only the heights of the first and the last soldier are important. For example, the general considers the sequence of heights (4, 3, 4, 2, 1, 1) correct and the sequence (4, 3, 1, 2, 2) wrong. Within one second the colonel can swap any two neighboring soldiers. Help him count the minimum time needed to form a line-up which the general will consider correct. Input Specification: The first input line contains the only integer *n* (2<=≤<=*n*<=≤<=100) which represents the number of soldiers in the line. The second line contains integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) the values of the soldiers' heights in the order of soldiers' heights' increasing in the order from the beginning of the line to its end. The numbers are space-separated. Numbers *a*1,<=*a*2,<=...,<=*a**n* are not necessarily different. Output Specification: Print the only integer — the minimum number of seconds the colonel will need to form a line-up the general will like. Demo Input: ['4\n33 44 11 22\n', '7\n10 10 58 31 63 40 76\n'] Demo Output: ['2\n', '10\n'] Note: In the first sample the colonel will need to swap the first and second soldier and then the third and fourth soldier. That will take 2 seconds. The resulting position of the soldiers is (44, 33, 22, 11). In the second sample the colonel may swap the soldiers in the following sequence: 1. (10, 10, 58, 31, 63, 40, 76) 1. (10, 58, 10, 31, 63, 40, 76) 1. (10, 58, 10, 31, 63, 76, 40) 1. (10, 58, 10, 31, 76, 63, 40) 1. (10, 58, 31, 10, 76, 63, 40) 1. (10, 58, 31, 76, 10, 63, 40) 1. (10, 58, 31, 76, 63, 10, 40) 1. (10, 58, 76, 31, 63, 10, 40) 1. (10, 76, 58, 31, 63, 10, 40) 1. (76, 10, 58, 31, 63, 10, 40) 1. (76, 10, 58, 31, 63, 40, 10)
```python n = int(input()) s = [int(i) for i in input().split()] new_s = [] for i in range(len(s)): if s[i] not in new_s: new_s.append(s[i]) i = new_s.index(max(new_s)) j = new_s.index(min(new_s)) res = i if i > j: res -= 1 res += n - j - 1 print(res) ```
0
177
A1
Good Matrix Elements
PROGRAMMING
800
[ "implementation" ]
null
null
The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an *n*<=×<=*n* size matrix, where *n* is odd. The Smart Beaver considers the following matrix elements good: - Elements of the main diagonal. - Elements of the secondary diagonal. - Elements of the "middle" row — the row which has exactly rows above it and the same number of rows below it. - Elements of the "middle" column — the column that has exactly columns to the left of it and the same number of columns to the right of it. Help the Smart Beaver count the sum of good elements of the given matrix.
The first line of input data contains a single odd integer *n*. Each of the next *n* lines contains *n* integers *a**ij* (0<=≤<=*a**ij*<=≤<=100) separated by single spaces — the elements of the given matrix. The input limitations for getting 30 points are: - 1<=≤<=*n*<=≤<=5 The input limitations for getting 100 points are: - 1<=≤<=*n*<=≤<=101
Print a single integer — the sum of good matrix elements.
[ "3\n1 2 3\n4 5 6\n7 8 9\n", "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n" ]
[ "45\n", "17\n" ]
In the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure.
30
[ { "input": "3\n1 2 3\n4 5 6\n7 8 9", "output": "45" }, { "input": "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1", "output": "17" }, { "input": "1\n3", "output": "3" }, { "input": "5\n27 7 3 11 72\n19 49 68 19 59\n41 25 37 64 65\n8 39 96 62 90\n13 37 43 26 33", "output": "756" }, { "input": "3\n19 7 16\n12 15 5\n15 15 5", "output": "109" }, { "input": "3\n36 4 33\n11 46 32\n20 49 34", "output": "265" }, { "input": "3\n79 91 74\n33 82 22\n18 28 54", "output": "481" }, { "input": "5\n7 0 8 1 7\n5 1 1 0 4\n4 2 8 1 6\n1 2 3 2 7\n6 0 1 9 6", "output": "65" }, { "input": "5\n27 20 28 11 17\n25 21 1 20 14\n14 22 28 1 6\n1 2 23 2 7\n6 0 1 29 6", "output": "225" }, { "input": "5\n57 50 58 41 17\n25 21 1 50 44\n44 22 28 31 36\n31 32 23 32 37\n6 0 31 59 6", "output": "495" }, { "input": "5\n57 80 28 41 47\n85 51 61 50 74\n44 82 28 31 36\n31 32 23 32 37\n66 60 31 59 6", "output": "705" }, { "input": "5\n13 58 10 17 43\n61 73 100 0 9\n52 38 16 22 96\n11 4 14 67 62\n70 89 7 98 83", "output": "708" }, { "input": "5\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "0" }, { "input": "5\n0 0 0 0 0\n1 0 0 0 0\n0 0 0 0 0\n1 0 0 0 0\n0 0 0 0 0", "output": "0" }, { "input": "5\n0 1 0 1 0\n0 0 0 0 1\n0 0 5 0 0\n0 0 0 0 1\n0 0 0 0 0", "output": "5" }, { "input": "5\n0 0 0 0 1\n0 1 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 1 0 0 0", "output": "3" }, { "input": "3\n0 0 0\n0 0 0\n0 0 0", "output": "0" } ]
1,698,382,344
2,147,483,647
Python 3
OK
TESTS1
17
92
0
a=int(input()) x=[] for i in range(a): y=list(map(int,input().split(" "))) x.append(y) y=0 for i in range(a): for j in range(a): if(i==j): y+=x[i][j] if i+j==a-1: y+=x[i][j] if i==(a-1)//2: y+=x[i][j] if j==(a-1)//2: y+=x[i][j] print(y-3*x[(a-1)//2][(a-1)//2])
Title: Good Matrix Elements Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an *n*<=×<=*n* size matrix, where *n* is odd. The Smart Beaver considers the following matrix elements good: - Elements of the main diagonal. - Elements of the secondary diagonal. - Elements of the "middle" row — the row which has exactly rows above it and the same number of rows below it. - Elements of the "middle" column — the column that has exactly columns to the left of it and the same number of columns to the right of it. Help the Smart Beaver count the sum of good elements of the given matrix. Input Specification: The first line of input data contains a single odd integer *n*. Each of the next *n* lines contains *n* integers *a**ij* (0<=≤<=*a**ij*<=≤<=100) separated by single spaces — the elements of the given matrix. The input limitations for getting 30 points are: - 1<=≤<=*n*<=≤<=5 The input limitations for getting 100 points are: - 1<=≤<=*n*<=≤<=101 Output Specification: Print a single integer — the sum of good matrix elements. Demo Input: ['3\n1 2 3\n4 5 6\n7 8 9\n', '5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n'] Demo Output: ['45\n', '17\n'] Note: In the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure.
```python a=int(input()) x=[] for i in range(a): y=list(map(int,input().split(" "))) x.append(y) y=0 for i in range(a): for j in range(a): if(i==j): y+=x[i][j] if i+j==a-1: y+=x[i][j] if i==(a-1)//2: y+=x[i][j] if j==(a-1)//2: y+=x[i][j] print(y-3*x[(a-1)//2][(a-1)//2]) ```
3
7
A
Kalevitch and Chess
PROGRAMMING
1,100
[ "brute force", "constructive algorithms" ]
A. Kalevitch and Chess
2
64
A famous Berland's painter Kalevitch likes to shock the public. One of his last obsessions is chess. For more than a thousand years people have been playing this old game on uninteresting, monotonous boards. Kalevitch decided to put an end to this tradition and to introduce a new attitude to chessboards. As before, the chessboard is a square-checkered board with the squares arranged in a 8<=×<=8 grid, each square is painted black or white. Kalevitch suggests that chessboards should be painted in the following manner: there should be chosen a horizontal or a vertical line of 8 squares (i.e. a row or a column), and painted black. Initially the whole chessboard is white, and it can be painted in the above described way one or more times. It is allowed to paint a square many times, but after the first time it does not change its colour any more and remains black. Kalevitch paints chessboards neatly, and it is impossible to judge by an individual square if it was painted with a vertical or a horizontal stroke. Kalevitch hopes that such chessboards will gain popularity, and he will be commissioned to paint chessboards, which will help him ensure a comfortable old age. The clients will inform him what chessboard they want to have, and the painter will paint a white chessboard meeting the client's requirements. It goes without saying that in such business one should economize on everything — for each commission he wants to know the minimum amount of strokes that he has to paint to fulfill the client's needs. You are asked to help Kalevitch with this task.
The input file contains 8 lines, each of the lines contains 8 characters. The given matrix describes the client's requirements, W character stands for a white square, and B character — for a square painted black. It is guaranteed that client's requirments can be fulfilled with a sequence of allowed strokes (vertical/column or horizontal/row).
Output the only number — the minimum amount of rows and columns that Kalevitch has to paint on the white chessboard to meet the client's requirements.
[ "WWWBWWBW\nBBBBBBBB\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\n", "WWWWWWWW\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\n" ]
[ "3\n", "1\n" ]
none
0
[ { "input": "WWWBWWBW\nBBBBBBBB\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW", "output": "3" }, { "input": "WWWWWWWW\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW", "output": "1" }, { "input": "WWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW", "output": "0" }, { "input": "BBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB", "output": "8" }, { "input": "BBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBW", "output": "14" }, { "input": "BBBBBBBB\nBBBBBBBB\nBBBBBBWB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB", "output": "14" }, { "input": "BBBBBBBB\nWBBBWBBW\nBBBBBBBB\nWBBBWBBW\nWBBBWBBW\nBBBBBBBB\nBBBBBBBB\nWBBBWBBW", "output": "9" }, { "input": "BBBBBBBB\nWBBWWWBB\nBBBBBBBB\nWBBWWWBB\nBBBBBBBB\nBBBBBBBB\nWBBWWWBB\nBBBBBBBB", "output": "9" }, { "input": "BBBBBWWB\nBBBBBBBB\nBBBBBBBB\nBBBBBWWB\nBBBBBWWB\nBBBBBWWB\nBBBBBWWB\nBBBBBWWB", "output": "8" }, { "input": "WWWWBBBB\nWWWWBBBB\nBBBBBBBB\nBBBBBBBB\nWWWWBBBB\nWWWWBBBB\nBBBBBBBB\nBBBBBBBB", "output": "8" }, { "input": "BBBBBBBB\nWBWWBBBW\nBBBBBBBB\nWBWWBBBW\nWBWWBBBW\nWBWWBBBW\nWBWWBBBW\nBBBBBBBB", "output": "7" }, { "input": "WBWWBBBW\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWBWWBBBW\nWBWWBBBW", "output": "9" }, { "input": "BBWWBBBW\nBBBBBBBB\nBBBBBBBB\nBBWWBBBW\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB", "output": "11" }, { "input": "WWBWBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWBWBBBB\nBBBBBBBB\nWWBWBBBB\nBBBBBBBB", "output": "10" }, { "input": "BBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWBWBBBB\nWWBWBBBB\nBBBBBBBB\nBBBBBBBB\nWWBWBBBB", "output": "10" }, { "input": "WBBWBBBW\nWBBWBBBW\nWBBWBBBW\nWBBWBBBW\nWBBWBBBW\nBBBBBBBB\nWBBWBBBW\nWBBWBBBW", "output": "6" }, { "input": "BBBWBBBW\nBBBWBBBW\nBBBWBBBW\nBBBBBBBB\nBBBBBBBB\nBBBWBBBW\nBBBBBBBB\nBBBBBBBB", "output": "10" }, { "input": "BBBBBBBB\nBBBWBBBB\nBBBWBBBB\nBBBWBBBB\nBBBBBBBB\nBBBWBBBB\nBBBWBBBB\nBBBWBBBB", "output": "9" }, { "input": "BBBBBBBB\nWWWBBBBB\nWWWBBBBB\nBBBBBBBB\nWWWBBBBB\nWWWBBBBB\nBBBBBBBB\nBBBBBBBB", "output": "9" }, { "input": "WBBBBBWB\nBBBBBBBB\nWBBBBBWB\nWBBBBBWB\nWBBBBBWB\nWBBBBBWB\nWBBBBBWB\nBBBBBBBB", "output": "8" }, { "input": "WBBBWWBW\nWBBBWWBW\nBBBBBBBB\nWBBBWWBW\nBBBBBBBB\nWBBBWWBW\nWBBBWWBW\nWBBBWWBW", "output": "6" }, { "input": "WBBBBWBB\nBBBBBBBB\nBBBBBBBB\nWBBBBWBB\nWBBBBWBB\nBBBBBBBB\nWBBBBWBB\nBBBBBBBB", "output": "10" }, { "input": "BBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWBBBWBBW\nBBBBBBBB\nBBBBBBBB\nWBBBWBBW\nBBBBBBBB", "output": "11" }, { "input": "BBBBBBBB\nBWBBBBBW\nBWBBBBBW\nBBBBBBBB\nBWBBBBBW\nBWBBBBBW\nBBBBBBBB\nBWBBBBBW", "output": "9" }, { "input": "BBBBBBBB\nBBBBBBBB\nWBBBWWWW\nBBBBBBBB\nBBBBBBBB\nWBBBWWWW\nBBBBBBBB\nBBBBBBBB", "output": "9" }, { "input": "BWBBBWWB\nBWBBBWWB\nBBBBBBBB\nBBBBBBBB\nBWBBBWWB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB", "output": "10" }, { "input": "BBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBWBBWBWB", "output": "12" }, { "input": "BWBBBBWW\nBWBBBBWW\nBWBBBBWW\nBWBBBBWW\nBBBBBBBB\nBWBBBBWW\nBWBBBBWW\nBBBBBBBB", "output": "7" }, { "input": "WWBBWWBB\nBBBBBBBB\nWWBBWWBB\nWWBBWWBB\nWWBBWWBB\nBBBBBBBB\nWWBBWWBB\nWWBBWWBB", "output": "6" }, { "input": "BWBBWWWW\nBWBBWWWW\nBWBBWWWW\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBWBBWWWW\nBBBBBBBB", "output": "7" } ]
1,528,883,597
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
3
218
0
a=list(0 for i in range(8)) o=0 for i in range(8): s,c=input(),0 for j in range(8): if s[j]=='B': a[j]+=1 c+=1 if c==8: o+=1 print(o+a.count(8))
Title: Kalevitch and Chess Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: A famous Berland's painter Kalevitch likes to shock the public. One of his last obsessions is chess. For more than a thousand years people have been playing this old game on uninteresting, monotonous boards. Kalevitch decided to put an end to this tradition and to introduce a new attitude to chessboards. As before, the chessboard is a square-checkered board with the squares arranged in a 8<=×<=8 grid, each square is painted black or white. Kalevitch suggests that chessboards should be painted in the following manner: there should be chosen a horizontal or a vertical line of 8 squares (i.e. a row or a column), and painted black. Initially the whole chessboard is white, and it can be painted in the above described way one or more times. It is allowed to paint a square many times, but after the first time it does not change its colour any more and remains black. Kalevitch paints chessboards neatly, and it is impossible to judge by an individual square if it was painted with a vertical or a horizontal stroke. Kalevitch hopes that such chessboards will gain popularity, and he will be commissioned to paint chessboards, which will help him ensure a comfortable old age. The clients will inform him what chessboard they want to have, and the painter will paint a white chessboard meeting the client's requirements. It goes without saying that in such business one should economize on everything — for each commission he wants to know the minimum amount of strokes that he has to paint to fulfill the client's needs. You are asked to help Kalevitch with this task. Input Specification: The input file contains 8 lines, each of the lines contains 8 characters. The given matrix describes the client's requirements, W character stands for a white square, and B character — for a square painted black. It is guaranteed that client's requirments can be fulfilled with a sequence of allowed strokes (vertical/column or horizontal/row). Output Specification: Output the only number — the minimum amount of rows and columns that Kalevitch has to paint on the white chessboard to meet the client's requirements. Demo Input: ['WWWBWWBW\nBBBBBBBB\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\n', 'WWWWWWWW\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\n'] Demo Output: ['3\n', '1\n'] Note: none
```python a=list(0 for i in range(8)) o=0 for i in range(8): s,c=input(),0 for j in range(8): if s[j]=='B': a[j]+=1 c+=1 if c==8: o+=1 print(o+a.count(8)) ```
0
673
A
Bear and Game
PROGRAMMING
800
[ "implementation" ]
null
null
Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks. Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Limak immediately turns TV off. You know that there will be *n* interesting minutes *t*1,<=*t*2,<=...,<=*t**n*. Your task is to calculate for how many minutes Limak will watch the game.
The first line of the input contains one integer *n* (1<=≤<=*n*<=≤<=90) — the number of interesting minutes. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t*1<=&lt;<=*t*2<=&lt;<=... *t**n*<=≤<=90), given in the increasing order.
Print the number of minutes Limak will watch the game.
[ "3\n7 20 88\n", "9\n16 20 30 40 50 60 70 80 90\n", "9\n15 20 30 40 50 60 70 80 90\n" ]
[ "35\n", "15\n", "90\n" ]
In the first sample, minutes 21, 22, ..., 35 are all boring and thus Limak will turn TV off immediately after the 35-th minute. So, he would watch the game for 35 minutes. In the second sample, the first 15 minutes are boring. In the third sample, there are no consecutive 15 boring minutes. So, Limak will watch the whole game.
500
[ { "input": "3\n7 20 88", "output": "35" }, { "input": "9\n16 20 30 40 50 60 70 80 90", "output": "15" }, { "input": "9\n15 20 30 40 50 60 70 80 90", "output": "90" }, { "input": "30\n6 11 12 15 22 24 30 31 32 33 34 35 40 42 44 45 47 50 53 54 57 58 63 67 75 77 79 81 83 88", "output": "90" }, { "input": "60\n1 2 4 5 6 7 11 14 16 18 20 21 22 23 24 25 26 33 34 35 36 37 38 39 41 42 43 44 46 47 48 49 52 55 56 57 58 59 60 61 63 64 65 67 68 70 71 72 73 74 75 77 78 80 82 83 84 85 86 88", "output": "90" }, { "input": "90\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", "output": "90" }, { "input": "1\n1", "output": "16" }, { "input": "5\n15 30 45 60 75", "output": "90" }, { "input": "6\n14 29 43 59 70 74", "output": "58" }, { "input": "1\n15", "output": "30" }, { "input": "1\n16", "output": "15" }, { "input": "14\n14 22 27 31 35 44 46 61 62 69 74 79 88 89", "output": "90" }, { "input": "76\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 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", "output": "90" }, { "input": "1\n90", "output": "15" }, { "input": "6\n13 17 32 47 60 66", "output": "81" }, { "input": "84\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", "output": "90" }, { "input": "9\n6 20 27 28 40 53 59 70 85", "output": "90" }, { "input": "12\n14 22 27 31 35 44 62 69 74 79 88 89", "output": "59" }, { "input": "5\n15 30 45 60 74", "output": "89" }, { "input": "72\n3 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 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", "output": "54" }, { "input": "8\n1 16 30 31 32 33 34 50", "output": "49" }, { "input": "12\n1 3 6 10 15 21 28 36 45 55 66 78", "output": "90" }, { "input": "25\n1 2 3 4 5 6 7 8 9 10 11 23 36 50 65 81 82 83 84 85 86 87 88 89 90", "output": "80" }, { "input": "8\n5 17 20 35 42 53 67 76", "output": "90" }, { "input": "9\n15 28 39 48 55 60 63 64 74", "output": "89" }, { "input": "10\n15 28 39 48 55 60 63 64 74 82", "output": "90" }, { "input": "2\n1 18", "output": "16" }, { "input": "9\n10 20 30 40 50 60 70 80 84", "output": "90" }, { "input": "2\n16 50", "output": "15" }, { "input": "6\n15 30 45 60 75 84", "output": "90" }, { "input": "8\n15 20 30 40 50 60 73 83", "output": "90" }, { "input": "8\n10 20 30 40 50 60 70 80", "output": "90" }, { "input": "3\n1 20 90", "output": "16" }, { "input": "6\n15 30 45 60 74 89", "output": "90" } ]
1,614,865,725
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
N=int(input()) A=list(map,int(input().split()) A.insert(0,0) T=0 F=True for i in range(N): if A[i+1]-A[i]<=15: T=A[i] else: T+=15 F=False break if F: if T>=75: print(90) else: print(T+15) else: print(T)
Title: Bear and Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks. Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Limak immediately turns TV off. You know that there will be *n* interesting minutes *t*1,<=*t*2,<=...,<=*t**n*. Your task is to calculate for how many minutes Limak will watch the game. Input Specification: The first line of the input contains one integer *n* (1<=≤<=*n*<=≤<=90) — the number of interesting minutes. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t*1<=&lt;<=*t*2<=&lt;<=... *t**n*<=≤<=90), given in the increasing order. Output Specification: Print the number of minutes Limak will watch the game. Demo Input: ['3\n7 20 88\n', '9\n16 20 30 40 50 60 70 80 90\n', '9\n15 20 30 40 50 60 70 80 90\n'] Demo Output: ['35\n', '15\n', '90\n'] Note: In the first sample, minutes 21, 22, ..., 35 are all boring and thus Limak will turn TV off immediately after the 35-th minute. So, he would watch the game for 35 minutes. In the second sample, the first 15 minutes are boring. In the third sample, there are no consecutive 15 boring minutes. So, Limak will watch the whole game.
```python N=int(input()) A=list(map,int(input().split()) A.insert(0,0) T=0 F=True for i in range(N): if A[i+1]-A[i]<=15: T=A[i] else: T+=15 F=False break if F: if T>=75: print(90) else: print(T+15) else: print(T) ```
-1
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,636,631,556
2,147,483,647
Python 3
OK
TESTS
43
46
4,300,800
s = input() q = 0 a = 0 ready = 0 for l in s: if l=="Q": q += 1 ready+=a elif l=="A": a+=q print(ready)
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 = input() q = 0 a = 0 ready = 0 for l in s: if l=="Q": q += 1 ready+=a elif l=="A": a+=q print(ready) ```
3
938
B
Run For Your Prize
PROGRAMMING
1,100
[ "brute force", "greedy" ]
null
null
You and your friend are participating in a TV show "Run For Your Prize". At the start of the show *n* prizes are located on a straight line. *i*-th prize is located at position *a**i*. Positions of all prizes are distinct. You start at position 1, your friend — at position 106 (and there is no prize in any of these two positions). You have to work as a team and collect all prizes in minimum possible time, in any order. You know that it takes exactly 1 second to move from position *x* to position *x*<=+<=1 or *x*<=-<=1, both for you and your friend. You also have trained enough to instantly pick up any prize, if its position is equal to your current position (and the same is true for your friend). Carrying prizes does not affect your speed (or your friend's speed) at all. Now you may discuss your strategy with your friend and decide who will pick up each prize. Remember that every prize must be picked up, either by you or by your friend. What is the minimum number of seconds it will take to pick up all the prizes?
The first line contains one integer *n* (1<=≤<=*n*<=≤<=105) — the number of prizes. The second line contains *n* integers *a*1, *a*2, ..., *a**n* (2<=≤<=*a**i*<=≤<=106<=-<=1) — the positions of the prizes. No two prizes are located at the same position. Positions are given in ascending order.
Print one integer — the minimum number of seconds it will take to collect all prizes.
[ "3\n2 3 9\n", "2\n2 999995\n" ]
[ "8\n", "5\n" ]
In the first example you take all the prizes: take the first at 1, the second at 2 and the third at 8. In the second example you take the first prize in 1 second and your friend takes the other in 5 seconds, you do this simultaneously, so the total time is 5.
0
[ { "input": "3\n2 3 9", "output": "8" }, { "input": "2\n2 999995", "output": "5" }, { "input": "1\n20", "output": "19" }, { "input": "6\n2 3 500000 999997 999998 999999", "output": "499999" }, { "input": "1\n999999", "output": "1" }, { "input": "1\n510000", "output": "490000" }, { "input": "3\n2 5 27", "output": "26" }, { "input": "2\n600000 800000", "output": "400000" }, { "input": "5\n2 5 6 27 29", "output": "28" }, { "input": "1\n500001", "output": "499999" }, { "input": "10\n3934 38497 42729 45023 51842 68393 77476 82414 91465 98055", "output": "98054" }, { "input": "1\n900000", "output": "100000" }, { "input": "1\n500000", "output": "499999" }, { "input": "1\n999998", "output": "2" }, { "input": "3\n999997 999998 999999", "output": "3" }, { "input": "2\n999997 999999", "output": "3" }, { "input": "2\n2 999998", "output": "2" }, { "input": "2\n500000 500001", "output": "499999" }, { "input": "1\n500002", "output": "499998" }, { "input": "1\n700000", "output": "300000" }, { "input": "2\n2 999999", "output": "1" }, { "input": "2\n999998 999999", "output": "2" }, { "input": "1\n999995", "output": "5" }, { "input": "2\n499999 500001", "output": "499999" }, { "input": "1\n499999", "output": "499998" }, { "input": "2\n100 999900", "output": "100" }, { "input": "2\n499999 500000", "output": "499999" }, { "input": "2\n500001 999999", "output": "499999" }, { "input": "3\n500000 500001 500002", "output": "499999" }, { "input": "2\n2 500001", "output": "499999" }, { "input": "2\n499999 999999", "output": "499998" }, { "input": "2\n2 500000", "output": "499999" }, { "input": "4\n2 3 4 999999", "output": "3" }, { "input": "2\n100000 500001", "output": "499999" }, { "input": "1\n2", "output": "1" }, { "input": "1\n800000", "output": "200000" }, { "input": "1\n505050", "output": "494950" }, { "input": "1\n753572", "output": "246428" }, { "input": "2\n576696 760487", "output": "423304" }, { "input": "10\n3 4 5 6 7 8 9 10 11 12", "output": "11" }, { "input": "4\n2 3 4 5", "output": "4" }, { "input": "4\n999996 999997 999998 999999", "output": "4" } ]
1,518,800,054
6,554
Python 3
CHALLENGED
CHALLENGES
6
93
13,004,800
R = lambda:map(int, input().split()) n = int(input()) C = list(R()) if C[0] > 5000: print(1000000 - C[0]) elif C[-1] <= 5000: print(C[-1] - 1) else: for i in range(n): if C[i] > 500000: print(max(C[i - 1] - 1, 1000000 - C[i])) break
Title: Run For Your Prize Time Limit: None seconds Memory Limit: None megabytes Problem Description: You and your friend are participating in a TV show "Run For Your Prize". At the start of the show *n* prizes are located on a straight line. *i*-th prize is located at position *a**i*. Positions of all prizes are distinct. You start at position 1, your friend — at position 106 (and there is no prize in any of these two positions). You have to work as a team and collect all prizes in minimum possible time, in any order. You know that it takes exactly 1 second to move from position *x* to position *x*<=+<=1 or *x*<=-<=1, both for you and your friend. You also have trained enough to instantly pick up any prize, if its position is equal to your current position (and the same is true for your friend). Carrying prizes does not affect your speed (or your friend's speed) at all. Now you may discuss your strategy with your friend and decide who will pick up each prize. Remember that every prize must be picked up, either by you or by your friend. What is the minimum number of seconds it will take to pick up all the prizes? Input Specification: The first line contains one integer *n* (1<=≤<=*n*<=≤<=105) — the number of prizes. The second line contains *n* integers *a*1, *a*2, ..., *a**n* (2<=≤<=*a**i*<=≤<=106<=-<=1) — the positions of the prizes. No two prizes are located at the same position. Positions are given in ascending order. Output Specification: Print one integer — the minimum number of seconds it will take to collect all prizes. Demo Input: ['3\n2 3 9\n', '2\n2 999995\n'] Demo Output: ['8\n', '5\n'] Note: In the first example you take all the prizes: take the first at 1, the second at 2 and the third at 8. In the second example you take the first prize in 1 second and your friend takes the other in 5 seconds, you do this simultaneously, so the total time is 5.
```python R = lambda:map(int, input().split()) n = int(input()) C = list(R()) if C[0] > 5000: print(1000000 - C[0]) elif C[-1] <= 5000: print(C[-1] - 1) else: for i in range(n): if C[i] > 500000: print(max(C[i - 1] - 1, 1000000 - C[i])) break ```
-1
452
B
4-point polyline
PROGRAMMING
1,800
[ "brute force", "constructive algorithms", "geometry", "trees" ]
null
null
You are given a rectangular grid of lattice points from (0,<=0) to (*n*,<=*m*) inclusive. You have to choose exactly 4 different points to build a polyline possibly with self-intersections and self-touching. This polyline should be as long as possible. A polyline defined by points *p*1,<=*p*2,<=*p*3,<=*p*4 consists of the line segments *p*1<=*p*2,<=*p*2<=*p*3,<=*p*3<=*p*4, and its length is the sum of the lengths of the individual line segments.
The only line of the input contains two integers *n* and *m* (0<=≤<=*n*,<=*m*<=≤<=1000). It is guaranteed that grid contains at least 4 different points.
Print 4 lines with two integers per line separated by space — coordinates of points *p*1,<=*p*2,<=*p*3,<=*p*4 in order which represent the longest possible polyline. Judge program compares your answer and jury's answer with 10<=-<=6 precision.
[ "1 1\n", "0 10\n" ]
[ "1 1\n0 0\n1 0\n0 1\n", "0 1\n0 10\n0 0\n0 9\n" ]
none
1,000
[ { "input": "1 1", "output": "0 0\n1 1\n0 1\n1 0" }, { "input": "0 10", "output": "0 1\n0 10\n0 0\n0 9" }, { "input": "10 10", "output": "10 9\n0 0\n10 10\n1 0" }, { "input": "100 100", "output": "0 1\n100 100\n0 0\n99 100" }, { "input": "10 100", "output": "9 100\n0 0\n10 100\n1 0" }, { "input": "20 1000", "output": "19 1000\n0 0\n20 1000\n1 0" }, { "input": "1000 20", "output": "1000 19\n0 0\n1000 20\n0 1" }, { "input": "100 10", "output": "100 9\n0 0\n100 10\n0 1" }, { "input": "2 2", "output": "0 0\n2 2\n0 2\n2 0" }, { "input": "3 3", "output": "3 3\n0 0\n3 0\n0 3" }, { "input": "2 15", "output": "2 15\n0 0\n0 15\n2 0" }, { "input": "15 2", "output": "15 2\n0 0\n15 0\n0 2" }, { "input": "1000 1000", "output": "0 1\n1000 1000\n0 0\n999 1000" }, { "input": "1000 999", "output": "1000 998\n0 0\n1000 999\n0 1" }, { "input": "999 1000", "output": "998 1000\n0 0\n999 1000\n1 0" }, { "input": "987 567", "output": "0 1\n987 567\n0 0\n987 566" }, { "input": "555 555", "output": "0 1\n555 555\n0 0\n554 555" }, { "input": "555 1", "output": "555 1\n0 0\n555 0\n0 1" }, { "input": "1 4", "output": "0 0\n1 4\n1 0\n0 4" }, { "input": "955 956", "output": "1 0\n955 956\n0 0\n954 956" }, { "input": "4 0", "output": "1 0\n4 0\n0 0\n3 0" }, { "input": "0 3", "output": "0 1\n0 3\n0 0\n0 2" }, { "input": "3 0", "output": "1 0\n3 0\n0 0\n2 0" }, { "input": "2 3", "output": "0 0\n2 3\n2 0\n0 3" }, { "input": "3 2", "output": "0 0\n3 2\n0 2\n3 0" }, { "input": "3 4", "output": "0 0\n3 4\n3 0\n0 4" }, { "input": "4 3", "output": "0 0\n4 3\n0 3\n4 0" }, { "input": "3 5", "output": "0 0\n3 5\n3 0\n0 5" }, { "input": "5 3", "output": "0 0\n5 3\n0 3\n5 0" }, { "input": "3 6", "output": "0 0\n3 6\n3 0\n0 6" }, { "input": "6 3", "output": "0 0\n6 3\n0 3\n6 0" }, { "input": "4 4", "output": "4 3\n0 0\n4 4\n1 0" }, { "input": "4 5", "output": "1 0\n4 5\n0 0\n3 5" }, { "input": "5 4", "output": "0 1\n5 4\n0 0\n5 3" }, { "input": "4 6", "output": "1 0\n4 6\n0 0\n3 6" }, { "input": "6 4", "output": "0 1\n6 4\n0 0\n6 3" }, { "input": "4 7", "output": "1 0\n4 7\n0 0\n3 7" }, { "input": "7 4", "output": "0 1\n7 4\n0 0\n7 3" }, { "input": "3 100", "output": "0 0\n3 100\n3 0\n0 100" }, { "input": "100 3", "output": "0 0\n100 3\n0 3\n100 0" }, { "input": "4 100", "output": "1 0\n4 100\n0 0\n3 100" }, { "input": "100 4", "output": "0 1\n100 4\n0 0\n100 3" }, { "input": "30 1000", "output": "1 0\n30 1000\n0 0\n29 1000" }, { "input": "1000 30", "output": "0 1\n1000 30\n0 0\n1000 29" }, { "input": "1000 40", "output": "0 1\n1000 40\n0 0\n1000 39" }, { "input": "40 1000", "output": "1 0\n40 1000\n0 0\n39 1000" }, { "input": "2 10", "output": "2 10\n0 0\n0 10\n2 0" }, { "input": "9 3", "output": "0 0\n9 3\n0 3\n9 0" }, { "input": "2 1000", "output": "2 1000\n0 0\n0 1000\n2 0" }, { "input": "100 2", "output": "0 0\n100 2\n0 2\n100 0" }, { "input": "3 1", "output": "3 1\n0 0\n3 0\n0 1" }, { "input": "2 100", "output": "0 0\n2 100\n2 0\n0 100" }, { "input": "3 7", "output": "0 0\n3 7\n3 0\n0 7" }, { "input": "2 50", "output": "0 0\n2 50\n2 0\n0 50" }, { "input": "1 5", "output": "1 5\n0 0\n0 5\n1 0" }, { "input": "3 1000", "output": "0 0\n3 1000\n3 0\n0 1000" }, { "input": "5 2", "output": "5 2\n0 0\n5 0\n0 2" }, { "input": "10 0", "output": "1 0\n10 0\n0 0\n9 0" }, { "input": "20 0", "output": "1 0\n20 0\n0 0\n19 0" }, { "input": "1000 3", "output": "0 0\n1000 3\n0 3\n1000 0" }, { "input": "1000 500", "output": "0 1\n1000 500\n0 0\n1000 499" }, { "input": "2 5", "output": "2 5\n0 0\n0 5\n2 0" }, { "input": "2 1", "output": "0 0\n2 1\n0 1\n2 0" }, { "input": "1000 2", "output": "1000 2\n0 0\n1000 0\n0 2" }, { "input": "6 5", "output": "0 1\n6 5\n0 0\n6 4" }, { "input": "2 4", "output": "0 0\n2 4\n2 0\n0 4" }, { "input": "20 10", "output": "20 9\n0 0\n20 10\n0 1" }, { "input": "10 1", "output": "10 1\n0 0\n10 0\n0 1" } ]
1,406,483,879
3,479
Python 3
WRONG_ANSWER
PRETESTS
2
61
0
from math import sqrt n, m = map(int, input().split()) swap = False if n > m: n, m = m, n swap = True ans = None if n == 0: ans = [(0, 1), (0, m), (0, 0), (0, m-1)] else: if sqrt(n**2 + (m-1)**2) + sqrt((n-1)**2 + (m-1)**2) > sqrt((n-1)**2 + m**2) + sqrt((n-2)**2 + m**2): ans = [(0, 0), (n, m), (0, 1), (n-1, m)] else: ans = [(0, 0), (n, m), (1, 0), (n-1, m)] for x, y in ans: if swap: print(y, x) else: print(x, y)
Title: 4-point polyline Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a rectangular grid of lattice points from (0,<=0) to (*n*,<=*m*) inclusive. You have to choose exactly 4 different points to build a polyline possibly with self-intersections and self-touching. This polyline should be as long as possible. A polyline defined by points *p*1,<=*p*2,<=*p*3,<=*p*4 consists of the line segments *p*1<=*p*2,<=*p*2<=*p*3,<=*p*3<=*p*4, and its length is the sum of the lengths of the individual line segments. Input Specification: The only line of the input contains two integers *n* and *m* (0<=≤<=*n*,<=*m*<=≤<=1000). It is guaranteed that grid contains at least 4 different points. Output Specification: Print 4 lines with two integers per line separated by space — coordinates of points *p*1,<=*p*2,<=*p*3,<=*p*4 in order which represent the longest possible polyline. Judge program compares your answer and jury's answer with 10<=-<=6 precision. Demo Input: ['1 1\n', '0 10\n'] Demo Output: ['1 1\n0 0\n1 0\n0 1\n', '0 1\n0 10\n0 0\n0 9\n'] Note: none
```python from math import sqrt n, m = map(int, input().split()) swap = False if n > m: n, m = m, n swap = True ans = None if n == 0: ans = [(0, 1), (0, m), (0, 0), (0, m-1)] else: if sqrt(n**2 + (m-1)**2) + sqrt((n-1)**2 + (m-1)**2) > sqrt((n-1)**2 + m**2) + sqrt((n-2)**2 + m**2): ans = [(0, 0), (n, m), (0, 1), (n-1, m)] else: ans = [(0, 0), (n, m), (1, 0), (n-1, m)] for x, y in ans: if swap: print(y, x) else: print(x, y) ```
0
58
A
Chat room
PROGRAMMING
1,000
[ "greedy", "strings" ]
A. Chat room
1
256
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*.
The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.
If Vasya managed to say hello, print "YES", otherwise print "NO".
[ "ahhellllloou\n", "hlelo\n" ]
[ "YES\n", "NO\n" ]
none
500
[ { "input": "ahhellllloou", "output": "YES" }, { "input": "hlelo", "output": "NO" }, { "input": "helhcludoo", "output": "YES" }, { "input": "hehwelloho", "output": "YES" }, { "input": "pnnepelqomhhheollvlo", "output": "YES" }, { "input": "tymbzjyqhymedasloqbq", "output": "NO" }, { "input": "yehluhlkwo", "output": "NO" }, { "input": "hatlevhhalrohairnolsvocafgueelrqmlqlleello", "output": "YES" }, { "input": "hhhtehdbllnhwmbyhvelqqyoulretpbfokflhlhreeflxeftelziclrwllrpflflbdtotvlqgoaoqldlroovbfsq", "output": "YES" }, { "input": "rzlvihhghnelqtwlexmvdjjrliqllolhyewgozkuovaiezgcilelqapuoeglnwmnlftxxiigzczlouooi", "output": "YES" }, { "input": "pfhhwctyqdlkrwhebfqfelhyebwllhemtrmeblgrynmvyhioesqklclocxmlffuormljszllpoo", "output": "YES" }, { "input": "lqllcolohwflhfhlnaow", "output": "NO" }, { "input": "heheeellollvoo", "output": "YES" }, { "input": "hellooo", "output": "YES" }, { "input": "o", "output": "NO" }, { "input": "hhqhzeclohlehljlhtesllylrolmomvuhcxsobtsckogdv", "output": "YES" }, { "input": "yoegfuzhqsihygnhpnukluutocvvwuldiighpogsifealtgkfzqbwtmgghmythcxflebrkctlldlkzlagovwlstsghbouk", "output": "YES" }, { "input": "uatqtgbvrnywfacwursctpagasnhydvmlinrcnqrry", "output": "NO" }, { "input": "tndtbldbllnrwmbyhvqaqqyoudrstpbfokfoclnraefuxtftmgzicorwisrpfnfpbdtatvwqgyalqtdtrjqvbfsq", "output": "NO" }, { "input": "rzlvirhgemelnzdawzpaoqtxmqucnahvqnwldklrmjiiyageraijfivigvozgwngiulttxxgzczptusoi", "output": "YES" }, { "input": "kgyelmchocojsnaqdsyeqgnllytbqietpdlgknwwumqkxrexgdcnwoldicwzwofpmuesjuxzrasscvyuqwspm", "output": "YES" }, { "input": "pnyvrcotjvgynbeldnxieghfltmexttuxzyac", "output": "NO" }, { "input": "dtwhbqoumejligbenxvzhjlhosqojetcqsynlzyhfaevbdpekgbtjrbhlltbceobcok", "output": "YES" }, { "input": "crrfpfftjwhhikwzeedrlwzblckkteseofjuxjrktcjfsylmlsvogvrcxbxtffujqshslemnixoeezivksouefeqlhhokwbqjz", "output": "YES" }, { "input": "jhfbndhyzdvhbvhmhmefqllujdflwdpjbehedlsqfdsqlyelwjtyloxwsvasrbqosblzbowlqjmyeilcvotdlaouxhdpoeloaovb", "output": "YES" }, { "input": "hwlghueoemiqtjhhpashjsouyegdlvoyzeunlroypoprnhlyiwiuxrghekaylndhrhllllwhbebezoglydcvykllotrlaqtvmlla", "output": "YES" }, { "input": "wshiaunnqnqxodholbipwhhjmyeblhgpeleblklpzwhdunmpqkbuzloetmwwxmeltkrcomulxauzlwmlklldjodozxryghsnwgcz", "output": "YES" }, { "input": "shvksednttggehroewuiptvvxtrzgidravtnjwuqrlnnkxbplctzkckinpkgjopjfoxdbojtcvsuvablcbkrzajrlhgobkcxeqti", "output": "YES" }, { "input": "hyyhddqhxhekehkwfhlnlsihzefwchzerevcjtokefplholrbvxlltdlafjxrfhleglrvlolojoqaolagtbeyogxlbgfolllslli", "output": "YES" }, { "input": "iaagrdhhelxpdegueiulflquvlzidoprzkehthkldaytrjwhyhprwjxlltinxvuilxohqgjqcvkkdcuoliekcnlilwgqlnlzouoo", "output": "YES" }, { "input": "wfluaeseldgxyvxpwuhkptdmlflnlhktwxiabsvkolsquymrmhzczzoybvlilhmvsuunggvgxzgyyffk", "output": "NO" }, { "input": "loee", "output": "NO" }, { "input": "izdipwylefqmjbuoznfglgcfvedeouflkeehxbasaqmiooppfsqlhprospqgxvzrcpwlfdddngoqvpwvggsnvvxhmjoslwjudjlo", "output": "NO" }, { "input": "pplynflbjlseflaegzqpdxswgunhnlglqhycrbcwdfhclmcrwekkzsoosmfblljeenwfjyifcvxihhhbyhmhlkvtskeglaovjnsi", "output": "YES" }, { "input": "xqjqmenkodmlhzyzmmvofdngktygbbxbzpluzcohohmalkoeuwfikblltaaigv", "output": "NO" }, { "input": "hello", "output": "YES" }, { "input": "oohell", "output": "NO" }, { "input": "hell", "output": "NO" }, { "input": "eloellohoelo", "output": "NO" }, { "input": "helllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllo", "output": "YES" } ]
1,619,753,847
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
46
0
greet = input() greet_list = [] for char in greet: greet_list.append(char) for indices in range(len(greet_list) - 4): if greet_list[indices] + greet_list[indices + 1] + greet_list[indices + 2] + greet_list[indices + 3] \ + greet_list[indices + 4] == 'hello': print('YES') else: print('NO')
Title: Chat room Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*. Input Specification: The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. Output Specification: If Vasya managed to say hello, print "YES", otherwise print "NO". Demo Input: ['ahhellllloou\n', 'hlelo\n'] Demo Output: ['YES\n', 'NO\n'] Note: none
```python greet = input() greet_list = [] for char in greet: greet_list.append(char) for indices in range(len(greet_list) - 4): if greet_list[indices] + greet_list[indices + 1] + greet_list[indices + 2] + greet_list[indices + 3] \ + greet_list[indices + 4] == 'hello': print('YES') else: print('NO') ```
0
767
A
Snacktower
PROGRAMMING
1,100
[ "data structures", "implementation" ]
null
null
According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time *n* snacks of distinct sizes will fall on the city, and the residents should build a Snacktower of them by placing snacks one on another. Of course, big snacks should be at the bottom of the tower, while small snacks should be at the top. Years passed, and once different snacks started to fall onto the city, and the residents began to build the Snacktower. However, they faced some troubles. Each day exactly one snack fell onto the city, but their order was strange. So, at some days the residents weren't able to put the new stack on the top of the Snacktower: they had to wait until all the bigger snacks fell. Of course, in order to not to anger miss Fortune again, the residents placed each snack on the top of the tower immediately as they could do it. Write a program that models the behavior of Ankh-Morpork residents.
The first line contains single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the total number of snacks. The second line contains *n* integers, the *i*-th of them equals the size of the snack which fell on the *i*-th day. Sizes are distinct integers from 1 to *n*.
Print *n* lines. On the *i*-th of them print the sizes of the snacks which the residents placed on the top of the Snacktower on the *i*-th day in the order they will do that. If no snack is placed on some day, leave the corresponding line empty.
[ "3\n3 1 2\n", "5\n4 5 1 2 3\n" ]
[ "3\n \n2 1", "5 4\n \n \n3 2 1\n" ]
In the example a snack of size 3 fell on the first day, and the residents immediately placed it. On the second day a snack of size 1 fell, and the residents weren't able to place it because they were missing the snack of size 2. On the third day a snack of size 2 fell, and the residents immediately placed it. Right after that they placed the snack of size 1 which had fallen before.
500
[ { "input": "3\n3 1 2", "output": "3 \n\n2 1 " }, { "input": "5\n4 5 1 2 3", "output": "5 4 \n\n\n3 2 1 " }, { "input": "1\n1", "output": "1 " }, { "input": "2\n1 2", "output": "2 1 " }, { "input": "10\n5 1 6 2 8 3 4 10 9 7", "output": "10 \n9 8 \n7 6 5 4 3 2 1 " }, { "input": "30\n16 10 4 29 5 28 12 21 11 30 18 6 14 3 17 22 20 15 9 1 27 19 24 26 13 25 2 23 8 7", "output": "30 29 28 \n\n\n\n\n\n\n\n\n\n\n27 \n\n\n26 \n\n25 24 \n\n23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 \n8 \n7 6 5 4 3 2 1 " }, { "input": "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 4 80 72 39", "output": "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\n99 98 \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 \n\n\n\n\n\n\n\n\n80 79 78 77 76 75 74 73 \n72 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 \n39 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 " }, { "input": "2\n2 1", "output": "2 \n1 " } ]
1,624,509,954
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
62
0
n = int(input()) x = [int(a) for a in input().split()] a = [] for i in range(n): if i != n-1 and x[i+1] > x[i]: print() a.append(x[i]) elif i == n-1 or x[i+1] < x[i]: a.append(x[i]) a.sort(reverse = True) print(str(a)[1:-1].replace(',',' ')) a = []
Title: Snacktower Time Limit: None seconds Memory Limit: None megabytes Problem Description: According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time *n* snacks of distinct sizes will fall on the city, and the residents should build a Snacktower of them by placing snacks one on another. Of course, big snacks should be at the bottom of the tower, while small snacks should be at the top. Years passed, and once different snacks started to fall onto the city, and the residents began to build the Snacktower. However, they faced some troubles. Each day exactly one snack fell onto the city, but their order was strange. So, at some days the residents weren't able to put the new stack on the top of the Snacktower: they had to wait until all the bigger snacks fell. Of course, in order to not to anger miss Fortune again, the residents placed each snack on the top of the tower immediately as they could do it. Write a program that models the behavior of Ankh-Morpork residents. Input Specification: The first line contains single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the total number of snacks. The second line contains *n* integers, the *i*-th of them equals the size of the snack which fell on the *i*-th day. Sizes are distinct integers from 1 to *n*. Output Specification: Print *n* lines. On the *i*-th of them print the sizes of the snacks which the residents placed on the top of the Snacktower on the *i*-th day in the order they will do that. If no snack is placed on some day, leave the corresponding line empty. Demo Input: ['3\n3 1 2\n', '5\n4 5 1 2 3\n'] Demo Output: ['3\n\xa0\n2 1', '5 4\n\xa0\n\xa0\n3 2 1\n'] Note: In the example a snack of size 3 fell on the first day, and the residents immediately placed it. On the second day a snack of size 1 fell, and the residents weren't able to place it because they were missing the snack of size 2. On the third day a snack of size 2 fell, and the residents immediately placed it. Right after that they placed the snack of size 1 which had fallen before.
```python n = int(input()) x = [int(a) for a in input().split()] a = [] for i in range(n): if i != n-1 and x[i+1] > x[i]: print() a.append(x[i]) elif i == n-1 or x[i+1] < x[i]: a.append(x[i]) a.sort(reverse = True) print(str(a)[1:-1].replace(',',' ')) a = [] ```
0
909
A
Generate Login
PROGRAMMING
1,000
[ "brute force", "greedy", "sortings" ]
null
null
The preferred way to generate user login in Polygon is to concatenate a prefix of the user's first name and a prefix of their last name, in that order. Each prefix must be non-empty, and any of the prefixes can be the full name. Typically there are multiple possible logins for each person. You are given the first and the last name of a user. Return the alphabetically earliest login they can get (regardless of other potential Polygon users). As a reminder, a prefix of a string *s* is its substring which occurs at the beginning of *s*: "a", "ab", "abc" etc. are prefixes of string "{abcdef}" but "b" and 'bc" are not. A string *a* is alphabetically earlier than a string *b*, if *a* is a prefix of *b*, or *a* and *b* coincide up to some position, and then *a* has a letter that is alphabetically earlier than the corresponding letter in *b*: "a" and "ab" are alphabetically earlier than "ac" but "b" and "ba" are alphabetically later than "ac".
The input consists of a single line containing two space-separated strings: the first and the last names. Each character of each string is a lowercase English letter. The length of each string is between 1 and 10, inclusive.
Output a single string — alphabetically earliest possible login formed from these names. The output should be given in lowercase as well.
[ "harry potter\n", "tom riddle\n" ]
[ "hap\n", "tomr\n" ]
none
500
[ { "input": "harry potter", "output": "hap" }, { "input": "tom riddle", "output": "tomr" }, { "input": "a qdpinbmcrf", "output": "aq" }, { "input": "wixjzniiub ssdfodfgap", "output": "wis" }, { "input": "z z", "output": "zz" }, { "input": "ertuyivhfg v", "output": "ertuv" }, { "input": "asdfghjkli ware", "output": "asdfghjkliw" }, { "input": "udggmyop ze", "output": "udggmyopz" }, { "input": "fapkdme rtzxovx", "output": "fapkdmer" }, { "input": "mybiqxmnqq l", "output": "ml" }, { "input": "dtbqya fyyymv", "output": "df" }, { "input": "fyclu zokbxiahao", "output": "fycluz" }, { "input": "qngatnviv rdych", "output": "qngar" }, { "input": "ttvnhrnng lqkfulhrn", "output": "tl" }, { "input": "fya fgx", "output": "ff" }, { "input": "nuis zvjjqlre", "output": "nuisz" }, { "input": "ly qtsmze", "output": "lq" }, { "input": "d kgfpjsurfw", "output": "dk" }, { "input": "lwli ewrpu", "output": "le" }, { "input": "rr wldsfubcs", "output": "rrw" }, { "input": "h qart", "output": "hq" }, { "input": "vugvblnzx kqdwdulm", "output": "vk" }, { "input": "xohesmku ef", "output": "xe" }, { "input": "twvvsl wtcyawv", "output": "tw" }, { "input": "obljndajv q", "output": "obljndajq" }, { "input": "jjxwj kxccwx", "output": "jjk" }, { "input": "sk fftzmv", "output": "sf" }, { "input": "cgpegngs aufzxkyyrw", "output": "ca" }, { "input": "reyjzjdvq skuch", "output": "res" }, { "input": "ardaae mxgdulijf", "output": "am" }, { "input": "bgopsdfji uaps", "output": "bgopsdfjiu" }, { "input": "amolfed pun", "output": "amolfedp" }, { "input": "badkiln yort", "output": "badkilny" }, { "input": "aaaaaaaaaz york", "output": "aaaaaaaaay" }, { "input": "bbbbcbbbbd c", "output": "bbbbc" }, { "input": "aa ab", "output": "aa" }, { "input": "ab b", "output": "ab" }, { "input": "aaaaa ab", "output": "aa" }, { "input": "aa a", "output": "aa" }, { "input": "aba b", "output": "ab" }, { "input": "aaaaaaa aaaaaa", "output": "aa" }, { "input": "a a", "output": "aa" }, { "input": "a aa", "output": "aa" }, { "input": "a b", "output": "ab" }, { "input": "b a", "output": "ba" }, { "input": "z a", "output": "za" }, { "input": "aaa a", "output": "aa" }, { "input": "aa aa", "output": "aa" }, { "input": "a aaa", "output": "aa" }, { "input": "aaaaaaaaaa aaaaaaaaaa", "output": "aa" }, { "input": "aaaaaaaaaa a", "output": "aa" }, { "input": "a aaaaaaaaaa", "output": "aa" }, { "input": "zzaa b", "output": "zb" }, { "input": "ca cf", "output": "cac" }, { "input": "abhi ia", "output": "abhi" }, { "input": "aaaa aaaab", "output": "aa" }, { "input": "aar raa", "output": "aar" }, { "input": "harry hotter", "output": "hah" }, { "input": "aaaaaaa a", "output": "aa" }, { "input": "apple pie", "output": "ap" }, { "input": "aaa aaa", "output": "aa" }, { "input": "kabc buba", "output": "kab" }, { "input": "asd ss", "output": "as" }, { "input": "bbb b", "output": "bb" } ]
1,514,968,655
2,147,483,647
Python 3
OK
TESTS
64
61
5,529,600
A, B = input().split() ans = "" ans+=A[0] for i in range(1,len(A)): if (A[i] < B[0]): ans+=A[i] else : break ; ans += B[0] print(ans)
Title: Generate Login Time Limit: None seconds Memory Limit: None megabytes Problem Description: The preferred way to generate user login in Polygon is to concatenate a prefix of the user's first name and a prefix of their last name, in that order. Each prefix must be non-empty, and any of the prefixes can be the full name. Typically there are multiple possible logins for each person. You are given the first and the last name of a user. Return the alphabetically earliest login they can get (regardless of other potential Polygon users). As a reminder, a prefix of a string *s* is its substring which occurs at the beginning of *s*: "a", "ab", "abc" etc. are prefixes of string "{abcdef}" but "b" and 'bc" are not. A string *a* is alphabetically earlier than a string *b*, if *a* is a prefix of *b*, or *a* and *b* coincide up to some position, and then *a* has a letter that is alphabetically earlier than the corresponding letter in *b*: "a" and "ab" are alphabetically earlier than "ac" but "b" and "ba" are alphabetically later than "ac". Input Specification: The input consists of a single line containing two space-separated strings: the first and the last names. Each character of each string is a lowercase English letter. The length of each string is between 1 and 10, inclusive. Output Specification: Output a single string — alphabetically earliest possible login formed from these names. The output should be given in lowercase as well. Demo Input: ['harry potter\n', 'tom riddle\n'] Demo Output: ['hap\n', 'tomr\n'] Note: none
```python A, B = input().split() ans = "" ans+=A[0] for i in range(1,len(A)): if (A[i] < B[0]): ans+=A[i] else : break ; ans += B[0] print(ans) ```
3
591
B
Rebranding
PROGRAMMING
1,200
[ "implementation", "strings" ]
null
null
The name of one small but proud corporation consists of *n* lowercase English letters. The Corporation has decided to try rebranding — an active marketing strategy, that includes a set of measures to change either the brand (both for the company and the goods it produces) or its components: the name, the logo, the slogan. They decided to start with the name. For this purpose the corporation has consecutively hired *m* designers. Once a company hires the *i*-th designer, he immediately contributes to the creation of a new corporation name as follows: he takes the newest version of the name and replaces all the letters *x**i* by *y**i*, and all the letters *y**i* by *x**i*. This results in the new version. It is possible that some of these letters do no occur in the string. It may also happen that *x**i* coincides with *y**i*. The version of the name received after the work of the last designer becomes the new name of the corporation. Manager Arkady has recently got a job in this company, but is already soaked in the spirit of teamwork and is very worried about the success of the rebranding. Naturally, he can't wait to find out what is the new name the Corporation will receive. Satisfy Arkady's curiosity and tell him the final version of the name.
The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=200<=000) — the length of the initial name and the number of designers hired, respectively. The second line consists of *n* lowercase English letters and represents the original name of the corporation. Next *m* lines contain the descriptions of the designers' actions: the *i*-th of them contains two space-separated lowercase English letters *x**i* and *y**i*.
Print the new name of the corporation.
[ "6 1\npolice\np m\n", "11 6\nabacabadaba\na b\nb c\na d\ne g\nf a\nb b\n" ]
[ "molice\n", "cdcbcdcfcdc\n" ]
In the second sample the name of the corporation consecutively changes as follows: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c7648432f7138ca53234357d7e08d1d119166055.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/de89ad7bc7f27c46ec34f5e66ce0dc23bd5bc90a.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/812e653c8d7ff496e6a0f04c676423806751531e.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/19c564fcefb8dde36256240a8b877bb6a4792bfe.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/e1cafd93792430ad1a49e893e04715383bdae757.png" style="max-width: 100.0%;max-height: 100.0%;"/>
1,000
[ { "input": "6 1\npolice\np m", "output": "molice" }, { "input": "11 6\nabacabadaba\na b\nb c\na d\ne g\nf a\nb b", "output": "cdcbcdcfcdc" }, { "input": "1 1\nf\nz h", "output": "f" }, { "input": "1 1\na\na b", "output": "b" }, { "input": "10 10\nlellelleel\ne l\ne l\ne l\ne l\ne l\ne e\nl l\nl e\nl l\ne e", "output": "lellelleel" } ]
1,617,053,673
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
4
2,000
7,270,400
import string n, m = map(int, input().split()) s = input() s1 = string.ascii_lowercase for i in range(m): x, y = input().split() s1 = s1.translate(str.maketrans(x+y, y+x)) print(s.translate(str.maketrans(string.ascii_lowercase, s1)))
Title: Rebranding Time Limit: None seconds Memory Limit: None megabytes Problem Description: The name of one small but proud corporation consists of *n* lowercase English letters. The Corporation has decided to try rebranding — an active marketing strategy, that includes a set of measures to change either the brand (both for the company and the goods it produces) or its components: the name, the logo, the slogan. They decided to start with the name. For this purpose the corporation has consecutively hired *m* designers. Once a company hires the *i*-th designer, he immediately contributes to the creation of a new corporation name as follows: he takes the newest version of the name and replaces all the letters *x**i* by *y**i*, and all the letters *y**i* by *x**i*. This results in the new version. It is possible that some of these letters do no occur in the string. It may also happen that *x**i* coincides with *y**i*. The version of the name received after the work of the last designer becomes the new name of the corporation. Manager Arkady has recently got a job in this company, but is already soaked in the spirit of teamwork and is very worried about the success of the rebranding. Naturally, he can't wait to find out what is the new name the Corporation will receive. Satisfy Arkady's curiosity and tell him the final version of the name. Input Specification: The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=200<=000) — the length of the initial name and the number of designers hired, respectively. The second line consists of *n* lowercase English letters and represents the original name of the corporation. Next *m* lines contain the descriptions of the designers' actions: the *i*-th of them contains two space-separated lowercase English letters *x**i* and *y**i*. Output Specification: Print the new name of the corporation. Demo Input: ['6 1\npolice\np m\n', '11 6\nabacabadaba\na b\nb c\na d\ne g\nf a\nb b\n'] Demo Output: ['molice\n', 'cdcbcdcfcdc\n'] Note: In the second sample the name of the corporation consecutively changes as follows: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c7648432f7138ca53234357d7e08d1d119166055.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/de89ad7bc7f27c46ec34f5e66ce0dc23bd5bc90a.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/812e653c8d7ff496e6a0f04c676423806751531e.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/19c564fcefb8dde36256240a8b877bb6a4792bfe.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/e1cafd93792430ad1a49e893e04715383bdae757.png" style="max-width: 100.0%;max-height: 100.0%;"/>
```python import string n, m = map(int, input().split()) s = input() s1 = string.ascii_lowercase for i in range(m): x, y = input().split() s1 = s1.translate(str.maketrans(x+y, y+x)) print(s.translate(str.maketrans(string.ascii_lowercase, s1))) ```
0
16
B
Burglar and Matches
PROGRAMMING
900
[ "greedy", "implementation", "sortings" ]
B. Burglar and Matches
0
64
A burglar got into a matches warehouse and wants to steal as many matches as possible. In the warehouse there are *m* containers, in the *i*-th container there are *a**i* matchboxes, and each matchbox contains *b**i* matches. All the matchboxes are of the same size. The burglar's rucksack can hold *n* matchboxes exactly. Your task is to find out the maximum amount of matches that a burglar can carry away. He has no time to rearrange matches in the matchboxes, that's why he just chooses not more than *n* matchboxes so that the total amount of matches in them is maximal.
The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=2·108) and integer *m* (1<=≤<=*m*<=≤<=20). The *i*<=+<=1-th line contains a pair of numbers *a**i* and *b**i* (1<=≤<=*a**i*<=≤<=108,<=1<=≤<=*b**i*<=≤<=10). All the input numbers are integer.
Output the only number — answer to the problem.
[ "7 3\n5 10\n2 5\n3 6\n", "3 3\n1 3\n2 2\n3 1\n" ]
[ "62\n", "7\n" ]
none
0
[ { "input": "7 3\n5 10\n2 5\n3 6", "output": "62" }, { "input": "3 3\n1 3\n2 2\n3 1", "output": "7" }, { "input": "1 1\n1 2", "output": "2" }, { "input": "1 2\n1 9\n1 6", "output": "9" }, { "input": "1 10\n1 1\n1 9\n1 3\n1 9\n1 7\n1 10\n1 4\n1 7\n1 3\n1 1", "output": "10" }, { "input": "2 1\n2 1", "output": "2" }, { "input": "2 2\n2 4\n1 4", "output": "8" }, { "input": "2 3\n1 7\n1 2\n1 5", "output": "12" }, { "input": "4 1\n2 2", "output": "4" }, { "input": "4 2\n1 10\n4 4", "output": "22" }, { "input": "4 3\n1 4\n6 4\n1 7", "output": "19" }, { "input": "5 1\n10 5", "output": "25" }, { "input": "5 2\n3 9\n2 2", "output": "31" }, { "input": "5 5\n2 9\n3 1\n2 1\n1 8\n2 8", "output": "42" }, { "input": "5 10\n1 3\n1 2\n1 9\n1 10\n1 1\n1 5\n1 10\n1 2\n1 3\n1 7", "output": "41" }, { "input": "10 1\n9 4", "output": "36" }, { "input": "10 2\n14 3\n1 3", "output": "30" }, { "input": "10 7\n4 8\n1 10\n1 10\n1 2\n3 3\n1 3\n1 10", "output": "71" }, { "input": "10 10\n1 8\n2 10\n1 9\n1 1\n1 9\n1 6\n1 4\n2 5\n1 2\n1 4", "output": "70" }, { "input": "10 4\n1 5\n5 2\n1 9\n3 3", "output": "33" }, { "input": "100 5\n78 6\n29 10\n3 6\n7 3\n2 4", "output": "716" }, { "input": "1000 7\n102 10\n23 6\n79 4\n48 1\n34 10\n839 8\n38 4", "output": "8218" }, { "input": "10000 10\n336 2\n2782 5\n430 10\n1893 7\n3989 10\n2593 8\n165 6\n1029 2\n2097 4\n178 10", "output": "84715" }, { "input": "100000 3\n2975 2\n35046 4\n61979 9", "output": "703945" }, { "input": "1000000 4\n314183 9\n304213 4\n16864 5\n641358 9", "output": "8794569" }, { "input": "10000000 10\n360313 10\n416076 1\n435445 9\n940322 7\n1647581 7\n4356968 10\n3589256 2\n2967933 5\n2747504 7\n1151633 3", "output": "85022733" }, { "input": "100000000 7\n32844337 7\n11210848 7\n47655987 1\n33900472 4\n9174763 2\n32228738 10\n29947408 5", "output": "749254060" }, { "input": "200000000 10\n27953106 7\n43325979 4\n4709522 1\n10975786 4\n67786538 8\n48901838 7\n15606185 6\n2747583 1\n100000000 1\n633331 3", "output": "1332923354" }, { "input": "200000000 9\n17463897 9\n79520463 1\n162407 4\n41017993 8\n71054118 4\n9447587 2\n5298038 9\n3674560 7\n20539314 5", "output": "996523209" }, { "input": "200000000 8\n6312706 6\n2920548 2\n16843192 3\n1501141 2\n13394704 6\n10047725 10\n4547663 6\n54268518 6", "output": "630991750" }, { "input": "200000000 7\n25621043 2\n21865270 1\n28833034 1\n22185073 5\n100000000 2\n13891017 9\n61298710 8", "output": "931584598" }, { "input": "200000000 6\n7465600 6\n8453505 10\n4572014 8\n8899499 3\n86805622 10\n64439238 6", "output": "1447294907" }, { "input": "200000000 5\n44608415 6\n100000000 9\n51483223 9\n44136047 1\n52718517 1", "output": "1634907859" }, { "input": "200000000 4\n37758556 10\n100000000 6\n48268521 3\n20148178 10", "output": "1305347138" }, { "input": "200000000 3\n65170000 7\n20790088 1\n74616133 4", "output": "775444620" }, { "input": "200000000 2\n11823018 6\n100000000 9", "output": "970938108" }, { "input": "200000000 1\n100000000 6", "output": "600000000" }, { "input": "200000000 10\n12097724 9\n41745972 5\n26982098 9\n14916995 7\n21549986 7\n3786630 9\n8050858 7\n27994924 4\n18345001 5\n8435339 5", "output": "1152034197" }, { "input": "200000000 10\n55649 8\n10980981 9\n3192542 8\n94994808 4\n3626106 1\n100000000 6\n5260110 9\n4121453 2\n15125061 4\n669569 6", "output": "1095537357" }, { "input": "10 20\n1 7\n1 7\n1 8\n1 3\n1 10\n1 7\n1 7\n1 9\n1 3\n1 1\n1 2\n1 1\n1 3\n1 10\n1 9\n1 8\n1 8\n1 6\n1 7\n1 5", "output": "83" }, { "input": "10000000 20\n4594 7\n520836 8\n294766 6\n298672 4\n142253 6\n450626 1\n1920034 9\n58282 4\n1043204 1\n683045 1\n1491746 5\n58420 4\n451217 2\n129423 4\n246113 5\n190612 8\n912923 6\n473153 6\n783733 6\n282411 10", "output": "54980855" }, { "input": "200000000 20\n15450824 5\n839717 10\n260084 8\n1140850 8\n28744 6\n675318 3\n25161 2\n5487 3\n6537698 9\n100000000 5\n7646970 9\n16489 6\n24627 3\n1009409 5\n22455 1\n25488456 4\n484528 9\n32663641 3\n750968 4\n5152 6", "output": "939368573" }, { "input": "200000000 20\n16896 2\n113 3\n277 2\n299 7\n69383562 2\n3929 8\n499366 4\n771846 5\n9 4\n1278173 7\n90 2\n54 7\n72199858 10\n17214 5\n3 10\n1981618 3\n3728 2\n141 8\n2013578 9\n51829246 5", "output": "1158946383" }, { "input": "200000000 20\n983125 2\n7453215 9\n9193588 2\n11558049 7\n28666199 1\n34362244 1\n5241493 5\n15451270 4\n19945845 8\n6208681 3\n38300385 7\n6441209 8\n21046742 7\n577198 10\n3826434 8\n9764276 8\n6264675 7\n8567063 3\n3610303 4\n2908232 3", "output": "1131379312" }, { "input": "10 15\n1 6\n2 6\n3 4\n1 3\n1 2\n1 5\n1 6\n1 2\n2 9\n1 10\n1 3\n1 7\n1 8\n1 2\n2 9", "output": "79" }, { "input": "10000000 15\n111 5\n914124 3\n3 9\n177790 1\n2352 3\n32138 9\n104477 1\n1223 4\n18 6\n6655580 4\n57643 10\n94309 2\n37 1\n227002 10\n1733193 7", "output": "45116295" }, { "input": "200000000 15\n7069868 1\n5567826 8\n2310059 10\n13539782 7\n38420939 4\n29911411 8\n52256316 1\n12265839 9\n2074265 1\n24896428 9\n72470695 5\n3236301 1\n3890243 2\n65168965 8\n65724 6", "output": "1489289257" }, { "input": "200000000 15\n12044094 7\n2475138 10\n944451 7\n4854766 2\n3809145 10\n7727571 2\n43908937 6\n2745883 1\n427511 2\n100000000 5\n190914 6\n554889 3\n288798 4\n1848572 5\n893874 3", "output": "961871671" }, { "input": "200000000 15\n6334191 7\n1927941 4\n5175933 10\n468389 1\n433043 10\n6863198 5\n7480646 4\n14774279 10\n2921129 8\n18325627 7\n6973152 9\n8277324 9\n21522856 2\n2058070 1\n2444742 4", "output": "664376069" } ]
1,657,182,825
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
1
216
0
n,m = map(int,input().split()) l1 = list(range(m)) l2 = list(range(m)) for i in range(m): l1[i],l2[i] = map(int,input().split()) res = 0 while n>0: res+=max(l2)*l1[l2.index(max(l2))] n -= l1[l2.index(max(l2))] l2.remove(max(l2)) print(res)
Title: Burglar and Matches Time Limit: 0 seconds Memory Limit: 64 megabytes Problem Description: A burglar got into a matches warehouse and wants to steal as many matches as possible. In the warehouse there are *m* containers, in the *i*-th container there are *a**i* matchboxes, and each matchbox contains *b**i* matches. All the matchboxes are of the same size. The burglar's rucksack can hold *n* matchboxes exactly. Your task is to find out the maximum amount of matches that a burglar can carry away. He has no time to rearrange matches in the matchboxes, that's why he just chooses not more than *n* matchboxes so that the total amount of matches in them is maximal. Input Specification: The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=2·108) and integer *m* (1<=≤<=*m*<=≤<=20). The *i*<=+<=1-th line contains a pair of numbers *a**i* and *b**i* (1<=≤<=*a**i*<=≤<=108,<=1<=≤<=*b**i*<=≤<=10). All the input numbers are integer. Output Specification: Output the only number — answer to the problem. Demo Input: ['7 3\n5 10\n2 5\n3 6\n', '3 3\n1 3\n2 2\n3 1\n'] Demo Output: ['62\n', '7\n'] Note: none
```python n,m = map(int,input().split()) l1 = list(range(m)) l2 = list(range(m)) for i in range(m): l1[i],l2[i] = map(int,input().split()) res = 0 while n>0: res+=max(l2)*l1[l2.index(max(l2))] n -= l1[l2.index(max(l2))] l2.remove(max(l2)) print(res) ```
0
559
B
Equivalent Strings
PROGRAMMING
1,700
[ "divide and conquer", "hashing", "sortings", "strings" ]
null
null
Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings *a* and *b* of equal length are called equivalent in one of the two cases: 1. They are equal. 1. If we split string *a* into two halves of the same size *a*1 and *a*2, and string *b* into two halves of the same size *b*1 and *b*2, then one of the following is correct: *a*1 is equivalent to *b*1, and *a*2 is equivalent to *b*2 1. *a*1 is equivalent to *b*2, and *a*2 is equivalent to *b*1 As a home task, the teacher gave two strings to his students and asked to determine if they are equivalent. Gerald has already completed this home task. Now it's your turn!
The first two lines of the input contain two strings given by the teacher. Each of them has the length from 1 to 200<=000 and consists of lowercase English letters. The strings have the same length.
Print "YES" (without the quotes), if these two strings are equivalent, and "NO" (without the quotes) otherwise.
[ "aaba\nabaa\n", "aabb\nabab\n" ]
[ "YES\n", "NO\n" ]
In the first sample you should split the first string into strings "aa" and "ba", the second one — into strings "ab" and "aa". "aa" is equivalent to "aa"; "ab" is equivalent to "ba" as "ab" = "a" + "b", "ba" = "b" + "a". In the second sample the first string can be splitted into strings "aa" and "bb", that are equivalent only to themselves. That's why string "aabb" is equivalent only to itself and to string "bbaa".
1,000
[ { "input": "aaba\nabaa", "output": "YES" }, { "input": "aabb\nabab", "output": "NO" }, { "input": "a\na", "output": "YES" }, { "input": "a\nb", "output": "NO" }, { "input": "ab\nab", "output": "YES" }, { "input": "ab\nba", "output": "YES" }, { "input": "ab\nbb", "output": "NO" }, { "input": "zzaa\naazz", "output": "YES" }, { "input": "azza\nzaaz", "output": "YES" }, { "input": "abc\nabc", "output": "YES" }, { "input": "abc\nacb", "output": "NO" }, { "input": "azzz\nzzaz", "output": "YES" }, { "input": "abcd\ndcab", "output": "YES" }, { "input": "abcd\ncdab", "output": "YES" }, { "input": "abcd\ndcba", "output": "YES" }, { "input": "abcd\nacbd", "output": "NO" }, { "input": "oloaxgddgujq\noloaxgujqddg", "output": "YES" }, { "input": "uwzwdxfmosmqatyv\ndxfmzwwusomqvyta", "output": "YES" }, { "input": "hagnzomowtledfdotnll\nledfdotnllomowthagnz", "output": "YES" }, { "input": "snyaydaeobufdg\nsnyaydaeobufdg", "output": "YES" }, { "input": "baaaaa\nabaaaa", "output": "NO" }, { "input": "hhiisug\nmzdjwju", "output": "NO" }, { "input": "bbbabbabaaab\naaaabbabbbbb", "output": "NO" }, { "input": "bbaaab\naababb", "output": "NO" }, { "input": "aabbaaaa\naaaaabab", "output": "NO" }, { "input": "aab\naba", "output": "NO" }, { "input": "abcddd\nbacddd", "output": "NO" }, { "input": "qgiufelsfhanx\naaaaaaaaaaaaa", "output": "NO" }, { "input": "aabaababaaba\naababaaababa", "output": "NO" }, { "input": "nocdqzdriyyil\naaaaaaaaaaaaa", "output": "NO" }, { "input": "zdmctxl\nkojqhgw", "output": "NO" }, { "input": "yhwepqwyhwepqwyhwepqweahnqtueahnqtueahnqtuyhwepqwyhwepqwyhwepqwyhwepqweahnqtueahnqtuyhwepqweahnqtueahnqtueahnqtueahnqtueahnqtueahnqtu\neahnqtueahnqtueahnqtuyhwepqweahnqtuyhwepqwyhwepqweahnqtuyhwepqweahnqtuyhwepqweahnqtueahnqtuyhwepqweahnqtueahnqtuyhwepqwyhwepqwyhwepqw", "output": "NO" }, { "input": "abc\nbac", "output": "NO" }, { "input": "ottceez\npcstdvz", "output": "NO" } ]
1,696,598,327
2,147,483,647
Python 3
OK
TESTS
104
452
30,412,800
def generate_partition(s): length = len(s) return sorted([ generate_partition( s[:length//2] ), generate_partition( s[length//2:] ) ]) if length % 2 == 0 else s string1 = input() string2 = input() if generate_partition(string1) == generate_partition(string2): print('YES') else: print('NO')
Title: Equivalent Strings Time Limit: None seconds Memory Limit: None megabytes Problem Description: Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings *a* and *b* of equal length are called equivalent in one of the two cases: 1. They are equal. 1. If we split string *a* into two halves of the same size *a*1 and *a*2, and string *b* into two halves of the same size *b*1 and *b*2, then one of the following is correct: *a*1 is equivalent to *b*1, and *a*2 is equivalent to *b*2 1. *a*1 is equivalent to *b*2, and *a*2 is equivalent to *b*1 As a home task, the teacher gave two strings to his students and asked to determine if they are equivalent. Gerald has already completed this home task. Now it's your turn! Input Specification: The first two lines of the input contain two strings given by the teacher. Each of them has the length from 1 to 200<=000 and consists of lowercase English letters. The strings have the same length. Output Specification: Print "YES" (without the quotes), if these two strings are equivalent, and "NO" (without the quotes) otherwise. Demo Input: ['aaba\nabaa\n', 'aabb\nabab\n'] Demo Output: ['YES\n', 'NO\n'] Note: In the first sample you should split the first string into strings "aa" and "ba", the second one — into strings "ab" and "aa". "aa" is equivalent to "aa"; "ab" is equivalent to "ba" as "ab" = "a" + "b", "ba" = "b" + "a". In the second sample the first string can be splitted into strings "aa" and "bb", that are equivalent only to themselves. That's why string "aabb" is equivalent only to itself and to string "bbaa".
```python def generate_partition(s): length = len(s) return sorted([ generate_partition( s[:length//2] ), generate_partition( s[length//2:] ) ]) if length % 2 == 0 else s string1 = input() string2 = input() if generate_partition(string1) == generate_partition(string2): print('YES') else: print('NO') ```
3
448
A
Rewards
PROGRAMMING
800
[ "implementation" ]
null
null
Bizon the Champion is called the Champion for a reason. Bizon the Champion has recently got a present — a new glass cupboard with *n* shelves and he decided to put all his presents there. All the presents can be divided into two types: medals and cups. Bizon the Champion has *a*1 first prize cups, *a*2 second prize cups and *a*3 third prize cups. Besides, he has *b*1 first prize medals, *b*2 second prize medals and *b*3 third prize medals. Naturally, the rewards in the cupboard must look good, that's why Bizon the Champion decided to follow the rules: - any shelf cannot contain both cups and medals at the same time; - no shelf can contain more than five cups; - no shelf can have more than ten medals. Help Bizon the Champion find out if we can put all the rewards so that all the conditions are fulfilled.
The first line contains integers *a*1, *a*2 and *a*3 (0<=≤<=*a*1,<=*a*2,<=*a*3<=≤<=100). The second line contains integers *b*1, *b*2 and *b*3 (0<=≤<=*b*1,<=*b*2,<=*b*3<=≤<=100). The third line contains integer *n* (1<=≤<=*n*<=≤<=100). The numbers in the lines are separated by single spaces.
Print "YES" (without the quotes) if all the rewards can be put on the shelves in the described manner. Otherwise, print "NO" (without the quotes).
[ "1 1 1\n1 1 1\n4\n", "1 1 3\n2 3 4\n2\n", "1 0 0\n1 0 0\n1\n" ]
[ "YES\n", "YES\n", "NO\n" ]
none
500
[ { "input": "1 1 1\n1 1 1\n4", "output": "YES" }, { "input": "1 1 3\n2 3 4\n2", "output": "YES" }, { "input": "1 0 0\n1 0 0\n1", "output": "NO" }, { "input": "0 0 0\n0 0 0\n1", "output": "YES" }, { "input": "100 100 100\n100 100 100\n100", "output": "YES" }, { "input": "100 100 100\n100 100 100\n1", "output": "NO" }, { "input": "1 10 100\n100 10 1\n20", "output": "NO" }, { "input": "1 1 1\n0 0 0\n1", "output": "YES" }, { "input": "0 0 0\n1 1 1\n1", "output": "YES" }, { "input": "5 5 5\n0 0 0\n2", "output": "NO" }, { "input": "0 0 0\n10 10 10\n2", "output": "NO" }, { "input": "21 61 39\n63 58 69\n44", "output": "YES" }, { "input": "18 95 4\n7 1 75\n46", "output": "YES" }, { "input": "64 27 81\n72 35 23\n48", "output": "YES" }, { "input": "6 6 6\n11 11 11\n7", "output": "NO" }, { "input": "1 2 3\n2 4 6\n3", "output": "NO" }, { "input": "1 2 3\n2 4 6\n4", "output": "YES" }, { "input": "99 99 99\n99 99 99\n89", "output": "NO" }, { "input": "5 0 0\n15 0 0\n2", "output": "NO" }, { "input": "10 10 10\n0 0 0\n1", "output": "NO" }, { "input": "1 1 1\n1 1 1\n15", "output": "YES" }, { "input": "2 3 5\n2 3 5\n2", "output": "NO" }, { "input": "2 2 2\n3 3 5\n3", "output": "NO" }, { "input": "1 2 2\n2 4 4\n1", "output": "NO" }, { "input": "1 2 3\n1 5 5\n2", "output": "NO" } ]
1,652,266,304
2,147,483,647
PyPy 3-64
RUNTIME_ERROR
TESTS
0
77
3,379,200
a1, a2, a3 = map(int, input().split()) b1, b2, b3 = map(int, input().split()) n = input() n -= (b1+b2+b3-1)//10+1 n -= (a1+a2+a3-1)//5+1 if n<0: print('NO') else: print('YES')
Title: Rewards Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bizon the Champion is called the Champion for a reason. Bizon the Champion has recently got a present — a new glass cupboard with *n* shelves and he decided to put all his presents there. All the presents can be divided into two types: medals and cups. Bizon the Champion has *a*1 first prize cups, *a*2 second prize cups and *a*3 third prize cups. Besides, he has *b*1 first prize medals, *b*2 second prize medals and *b*3 third prize medals. Naturally, the rewards in the cupboard must look good, that's why Bizon the Champion decided to follow the rules: - any shelf cannot contain both cups and medals at the same time; - no shelf can contain more than five cups; - no shelf can have more than ten medals. Help Bizon the Champion find out if we can put all the rewards so that all the conditions are fulfilled. Input Specification: The first line contains integers *a*1, *a*2 and *a*3 (0<=≤<=*a*1,<=*a*2,<=*a*3<=≤<=100). The second line contains integers *b*1, *b*2 and *b*3 (0<=≤<=*b*1,<=*b*2,<=*b*3<=≤<=100). The third line contains integer *n* (1<=≤<=*n*<=≤<=100). The numbers in the lines are separated by single spaces. Output Specification: Print "YES" (without the quotes) if all the rewards can be put on the shelves in the described manner. Otherwise, print "NO" (without the quotes). Demo Input: ['1 1 1\n1 1 1\n4\n', '1 1 3\n2 3 4\n2\n', '1 0 0\n1 0 0\n1\n'] Demo Output: ['YES\n', 'YES\n', 'NO\n'] Note: none
```python a1, a2, a3 = map(int, input().split()) b1, b2, b3 = map(int, input().split()) n = input() n -= (b1+b2+b3-1)//10+1 n -= (a1+a2+a3-1)//5+1 if n<0: print('NO') else: print('YES') ```
-1
858
A
k-rounding
PROGRAMMING
1,100
[ "brute force", "math", "number theory" ]
null
null
For a given positive integer *n* denote its *k*-rounding as the minimum positive integer *x*, such that *x* ends with *k* or more zeros in base 10 and is divisible by *n*. For example, 4-rounding of 375 is 375·80<==<=30000. 30000 is the minimum integer such that it ends with 4 or more zeros and is divisible by 375. Write a program that will perform the *k*-rounding of *n*.
The only line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=109, 0<=≤<=*k*<=≤<=8).
Print the *k*-rounding of *n*.
[ "375 4\n", "10000 1\n", "38101 0\n", "123456789 8\n" ]
[ "30000\n", "10000\n", "38101\n", "12345678900000000\n" ]
none
750
[ { "input": "375 4", "output": "30000" }, { "input": "10000 1", "output": "10000" }, { "input": "38101 0", "output": "38101" }, { "input": "123456789 8", "output": "12345678900000000" }, { "input": "1 0", "output": "1" }, { "input": "2 0", "output": "2" }, { "input": "100 0", "output": "100" }, { "input": "1000000000 0", "output": "1000000000" }, { "input": "160 2", "output": "800" }, { "input": "3 0", "output": "3" }, { "input": "10 0", "output": "10" }, { "input": "1 1", "output": "10" }, { "input": "2 1", "output": "10" }, { "input": "3 1", "output": "30" }, { "input": "4 1", "output": "20" }, { "input": "5 1", "output": "10" }, { "input": "6 1", "output": "30" }, { "input": "7 1", "output": "70" }, { "input": "8 1", "output": "40" }, { "input": "9 1", "output": "90" }, { "input": "10 1", "output": "10" }, { "input": "11 1", "output": "110" }, { "input": "12 1", "output": "60" }, { "input": "16 2", "output": "400" }, { "input": "2 2", "output": "100" }, { "input": "1 2", "output": "100" }, { "input": "5 2", "output": "100" }, { "input": "15 2", "output": "300" }, { "input": "36 2", "output": "900" }, { "input": "1 8", "output": "100000000" }, { "input": "8 8", "output": "100000000" }, { "input": "96 8", "output": "300000000" }, { "input": "175 8", "output": "700000000" }, { "input": "9999995 8", "output": "199999900000000" }, { "input": "999999999 8", "output": "99999999900000000" }, { "input": "12345678 8", "output": "617283900000000" }, { "input": "78125 8", "output": "100000000" }, { "input": "390625 8", "output": "100000000" }, { "input": "1953125 8", "output": "500000000" }, { "input": "9765625 8", "output": "2500000000" }, { "input": "68359375 8", "output": "17500000000" }, { "input": "268435456 8", "output": "104857600000000" }, { "input": "125829120 8", "output": "9830400000000" }, { "input": "128000 8", "output": "400000000" }, { "input": "300000 8", "output": "300000000" }, { "input": "3711871 8", "output": "371187100000000" }, { "input": "55555 8", "output": "1111100000000" }, { "input": "222222222 8", "output": "11111111100000000" }, { "input": "479001600 8", "output": "7484400000000" }, { "input": "655360001 7", "output": "6553600010000000" }, { "input": "655360001 8", "output": "65536000100000000" }, { "input": "1000000000 1", "output": "1000000000" }, { "input": "1000000000 7", "output": "1000000000" }, { "input": "1000000000 8", "output": "1000000000" }, { "input": "100000000 8", "output": "100000000" }, { "input": "10000000 8", "output": "100000000" }, { "input": "1000000 8", "output": "100000000" }, { "input": "10000009 8", "output": "1000000900000000" }, { "input": "10000005 8", "output": "200000100000000" }, { "input": "10000002 8", "output": "500000100000000" }, { "input": "999999997 8", "output": "99999999700000000" }, { "input": "999999997 7", "output": "9999999970000000" }, { "input": "999999995 8", "output": "19999999900000000" }, { "input": "123 8", "output": "12300000000" }, { "input": "24 2", "output": "600" }, { "input": "16 4", "output": "10000" }, { "input": "123456787 8", "output": "12345678700000000" }, { "input": "100000000 8", "output": "100000000" }, { "input": "7 1", "output": "70" }, { "input": "101 1", "output": "1010" }, { "input": "50 2", "output": "100" }, { "input": "999999818 1", "output": "4999999090" }, { "input": "2 1", "output": "10" }, { "input": "123 1", "output": "1230" }, { "input": "16 1", "output": "80" }, { "input": "1 1", "output": "10" }, { "input": "1000000000 8", "output": "1000000000" }, { "input": "15304 6", "output": "1913000000" }, { "input": "3 8", "output": "300000000" }, { "input": "4 2", "output": "100" }, { "input": "100000 7", "output": "10000000" }, { "input": "5 8", "output": "100000000" }, { "input": "16724 6", "output": "4181000000" }, { "input": "999999999 1", "output": "9999999990" }, { "input": "999999990 8", "output": "9999999900000000" }, { "input": "999999999 8", "output": "99999999900000000" }, { "input": "100000 1", "output": "100000" }, { "input": "8 3", "output": "1000" }, { "input": "16768 6", "output": "262000000" }, { "input": "123456789 1", "output": "1234567890" }, { "input": "2 8", "output": "100000000" }, { "input": "999999937 8", "output": "99999993700000000" }, { "input": "5 1", "output": "10" }, { "input": "2000000 7", "output": "10000000" }, { "input": "1999998 2", "output": "99999900" }, { "input": "125 3", "output": "1000" } ]
1,532,239,337
2,147,483,647
Python 3
OK
TESTS
96
124
0
n, k = map(int,input().split()) cnt=0 while cnt<k: if n%10==0: n/=10 cnt+=1 elif n%5==0: n*=2 elif n%2==0: n*=5 else: n*=10 n*=pow(10,cnt) print(int(n))
Title: k-rounding Time Limit: None seconds Memory Limit: None megabytes Problem Description: For a given positive integer *n* denote its *k*-rounding as the minimum positive integer *x*, such that *x* ends with *k* or more zeros in base 10 and is divisible by *n*. For example, 4-rounding of 375 is 375·80<==<=30000. 30000 is the minimum integer such that it ends with 4 or more zeros and is divisible by 375. Write a program that will perform the *k*-rounding of *n*. Input Specification: The only line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=109, 0<=≤<=*k*<=≤<=8). Output Specification: Print the *k*-rounding of *n*. Demo Input: ['375 4\n', '10000 1\n', '38101 0\n', '123456789 8\n'] Demo Output: ['30000\n', '10000\n', '38101\n', '12345678900000000\n'] Note: none
```python n, k = map(int,input().split()) cnt=0 while cnt<k: if n%10==0: n/=10 cnt+=1 elif n%5==0: n*=2 elif n%2==0: n*=5 else: n*=10 n*=pow(10,cnt) print(int(n)) ```
3
911
E
Stack Sorting
PROGRAMMING
2,000
[ "constructive algorithms", "data structures", "greedy", "implementation" ]
null
null
Let's suppose you have an array *a*, a stack *s* (initially empty) and an array *b* (also initially empty). You may perform the following operations until both *a* and *s* are empty: - Take the first element of *a*, push it into *s* and remove it from *a* (if *a* is not empty); - Take the top element from *s*, append it to the end of array *b* and remove it from *s* (if *s* is not empty). You can perform these operations in arbitrary order. If there exists a way to perform the operations such that array *b* is sorted in non-descending order in the end, then array *a* is called stack-sortable. For example, [3,<=1,<=2] is stack-sortable, because *b* will be sorted if we perform the following operations: 1. Remove 3 from *a* and push it into *s*; 1. Remove 1 from *a* and push it into *s*; 1. Remove 1 from *s* and append it to the end of *b*; 1. Remove 2 from *a* and push it into *s*; 1. Remove 2 from *s* and append it to the end of *b*; 1. Remove 3 from *s* and append it to the end of *b*. After all these operations *b*<==<=[1,<=2,<=3], so [3,<=1,<=2] is stack-sortable. [2,<=3,<=1] is not stack-sortable. You are given *k* first elements of some permutation *p* of size *n* (recall that a permutation of size *n* is an array of size *n* where each integer from 1 to *n* occurs exactly once). You have to restore the remaining *n*<=-<=*k* elements of this permutation so it is stack-sortable. If there are multiple answers, choose the answer such that *p* is lexicographically maximal (an array *q* is lexicographically greater than an array *p* iff there exists some integer *k* such that for every *i*<=&lt;<=*k* *q**i*<==<=*p**i*, and *q**k*<=&gt;<=*p**k*). You may not swap or change any of first *k* elements of the permutation. Print the lexicographically maximal permutation *p* you can obtain. If there exists no answer then output -1.
The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=200000, 1<=≤<=*k*<=&lt;<=*n*) — the size of a desired permutation, and the number of elements you are given, respectively. The second line contains *k* integers *p*1, *p*2, ..., *p**k* (1<=≤<=*p**i*<=≤<=*n*) — the first *k* elements of *p*. These integers are pairwise distinct.
If it is possible to restore a stack-sortable permutation *p* of size *n* such that the first *k* elements of *p* are equal to elements given in the input, print lexicographically maximal such permutation. Otherwise print -1.
[ "5 3\n3 2 1\n", "5 3\n2 3 1\n", "5 1\n3\n", "5 2\n3 4\n" ]
[ "3 2 1 5 4 ", "-1\n", "3 2 1 5 4 ", "-1\n" ]
none
0
[ { "input": "5 3\n3 2 1", "output": "3 2 1 5 4 " }, { "input": "5 3\n2 3 1", "output": "-1" }, { "input": "5 1\n3", "output": "3 2 1 5 4 " }, { "input": "5 2\n3 4", "output": "-1" }, { "input": "100000 1\n98419", "output": "98419 98418 98417 98416 98415 98414 98413 98412 98411 98410 98409 98408 98407 98406 98405 98404 98403 98402 98401 98400 98399 98398 98397 98396 98395 98394 98393 98392 98391 98390 98389 98388 98387 98386 98385 98384 98383 98382 98381 98380 98379 98378 98377 98376 98375 98374 98373 98372 98371 98370 98369 98368 98367 98366 98365 98364 98363 98362 98361 98360 98359 98358 98357 98356 98355 98354 98353 98352 98351 98350 98349 98348 98347 98346 98345 98344 98343 98342 98341 98340 98339 98338 98337 98336 98335 9..." }, { "input": "20 19\n2 18 19 11 9 20 15 1 8 14 4 6 5 12 17 16 7 13 3", "output": "-1" }, { "input": "10 1\n6", "output": "6 5 4 3 2 1 10 9 8 7 " }, { "input": "100000 2\n64398 63673", "output": "64398 63673 63672 63671 63670 63669 63668 63667 63666 63665 63664 63663 63662 63661 63660 63659 63658 63657 63656 63655 63654 63653 63652 63651 63650 63649 63648 63647 63646 63645 63644 63643 63642 63641 63640 63639 63638 63637 63636 63635 63634 63633 63632 63631 63630 63629 63628 63627 63626 63625 63624 63623 63622 63621 63620 63619 63618 63617 63616 63615 63614 63613 63612 63611 63610 63609 63608 63607 63606 63605 63604 63603 63602 63601 63600 63599 63598 63597 63596 63595 63594 63593 63592 63591 63590 6..." }, { "input": "20 18\n8 14 18 10 1 3 7 15 2 12 17 19 5 4 11 13 20 16", "output": "-1" }, { "input": "10 2\n3 7", "output": "-1" }, { "input": "100000 3\n43791 91790 34124", "output": "-1" }, { "input": "20 17\n9 11 19 4 8 16 13 3 1 6 18 2 20 10 17 7 5", "output": "-1" }, { "input": "10 3\n2 10 3", "output": "-1" }, { "input": "100000 4\n8269 53984 47865 42245", "output": "-1" }, { "input": "20 16\n8 1 5 11 15 14 7 20 16 9 12 13 18 4 6 10", "output": "-1" }, { "input": "10 4\n2 4 1 10", "output": "-1" }, { "input": "100000 5\n82211 48488 99853 11566 42120", "output": "-1" }, { "input": "20 15\n6 7 14 13 8 4 15 2 11 9 12 16 5 1 20", "output": "-1" }, { "input": "10 5\n2 10 5 8 4", "output": "-1" }, { "input": "100000 6\n98217 55264 24242 71840 2627 67839", "output": "-1" }, { "input": "20 14\n10 15 4 3 1 5 11 12 13 14 6 2 19 20", "output": "-1" }, { "input": "10 6\n4 5 2 1 6 3", "output": "-1" }, { "input": "100000 7\n44943 51099 61988 40497 85738 74092 2771", "output": "-1" }, { "input": "20 13\n6 16 5 19 8 1 4 18 2 20 10 11 13", "output": "-1" }, { "input": "10 7\n10 4 3 8 2 5 6", "output": "-1" }, { "input": "100000 8\n88153 88461 80211 24770 13872 57414 32941 63030", "output": "-1" }, { "input": "20 12\n20 11 14 7 16 13 9 1 4 18 6 12", "output": "-1" }, { "input": "10 8\n7 9 3 6 2 4 1 8", "output": "-1" }, { "input": "200000 1\n177300", "output": "177300 177299 177298 177297 177296 177295 177294 177293 177292 177291 177290 177289 177288 177287 177286 177285 177284 177283 177282 177281 177280 177279 177278 177277 177276 177275 177274 177273 177272 177271 177270 177269 177268 177267 177266 177265 177264 177263 177262 177261 177260 177259 177258 177257 177256 177255 177254 177253 177252 177251 177250 177249 177248 177247 177246 177245 177244 177243 177242 177241 177240 177239 177238 177237 177236 177235 177234 177233 177232 177231 177230 177229 177228 ..." }, { "input": "40 39\n25 4 26 34 35 11 22 23 21 2 1 28 20 8 36 5 27 15 39 7 24 14 17 19 33 6 38 16 18 3 32 10 30 13 37 31 29 9 12", "output": "-1" }, { "input": "20 1\n20", "output": "20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 " }, { "input": "200000 2\n102991 8046", "output": "102991 8046 8045 8044 8043 8042 8041 8040 8039 8038 8037 8036 8035 8034 8033 8032 8031 8030 8029 8028 8027 8026 8025 8024 8023 8022 8021 8020 8019 8018 8017 8016 8015 8014 8013 8012 8011 8010 8009 8008 8007 8006 8005 8004 8003 8002 8001 8000 7999 7998 7997 7996 7995 7994 7993 7992 7991 7990 7989 7988 7987 7986 7985 7984 7983 7982 7981 7980 7979 7978 7977 7976 7975 7974 7973 7972 7971 7970 7969 7968 7967 7966 7965 7964 7963 7962 7961 7960 7959 7958 7957 7956 7955 7954 7953 7952 7951 7950 7949 7948 7947 7946..." }, { "input": "40 38\n32 35 36 4 22 6 15 21 40 13 33 17 5 24 28 9 1 23 25 14 26 3 8 11 37 30 18 16 19 20 27 12 39 2 10 38 29 31", "output": "-1" }, { "input": "20 2\n1 13", "output": "1 13 12 11 10 9 8 7 6 5 4 3 2 20 19 18 17 16 15 14 " }, { "input": "200000 3\n60323 163214 48453", "output": "-1" }, { "input": "40 37\n26 16 40 10 9 30 8 33 39 19 4 11 2 3 38 21 22 12 1 27 20 37 24 17 23 14 13 29 7 28 34 31 25 35 6 32 5", "output": "-1" }, { "input": "20 3\n16 6 14", "output": "-1" }, { "input": "200000 4\n194118 175603 110154 129526", "output": "-1" }, { "input": "40 36\n27 33 34 40 16 39 1 10 9 12 8 37 17 7 24 30 2 31 13 23 20 18 29 21 4 28 25 35 6 22 36 15 3 11 5 26", "output": "-1" }, { "input": "20 4\n2 10 4 9", "output": "-1" }, { "input": "200000 5\n53765 19781 63409 69811 120021", "output": "-1" }, { "input": "40 35\n2 1 5 3 11 32 13 16 37 26 6 10 8 35 25 24 7 38 21 17 40 14 9 34 33 20 29 12 22 28 36 31 30 19 27", "output": "-1" }, { "input": "20 5\n11 19 6 2 12", "output": "-1" }, { "input": "200000 6\n33936 11771 42964 153325 684 8678", "output": "-1" }, { "input": "40 34\n35 31 38 25 29 9 32 23 24 16 3 26 39 2 17 28 14 1 30 34 5 36 33 7 22 13 21 12 27 19 40 10 18 15", "output": "-1" }, { "input": "20 6\n3 6 9 13 20 14", "output": "-1" }, { "input": "200000 7\n175932 99083 128533 75304 164663 7578 174396", "output": "-1" }, { "input": "40 33\n11 15 22 26 21 6 8 5 32 39 28 29 30 13 2 40 33 27 17 31 7 36 9 19 3 38 37 12 10 16 1 23 35", "output": "-1" }, { "input": "20 7\n7 5 6 13 16 3 17", "output": "-1" }, { "input": "200000 8\n197281 11492 67218 100058 179300 182264 17781 192818", "output": "-1" }, { "input": "40 32\n22 7 35 31 14 28 9 20 10 3 38 6 15 36 33 16 37 2 11 13 26 23 30 12 40 5 21 1 34 19 27 24", "output": "-1" }, { "input": "20 8\n1 16 14 11 7 9 2 12", "output": "-1" }, { "input": "30 3\n17 5 3", "output": "17 5 3 2 1 4 16 15 14 13 12 11 10 9 8 7 6 30 29 28 27 26 25 24 23 22 21 20 19 18 " }, { "input": "30 3\n29 25 21", "output": "29 25 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 24 23 22 28 27 26 30 " }, { "input": "10 6\n2 1 4 3 6 5", "output": "2 1 4 3 6 5 10 9 8 7 " }, { "input": "4 3\n2 1 3", "output": "2 1 3 4 " }, { "input": "6 4\n5 4 3 1", "output": "5 4 3 1 2 6 " }, { "input": "4 3\n1 2 3", "output": "1 2 3 4 " }, { "input": "6 4\n1 3 2 6", "output": "1 3 2 6 5 4 " }, { "input": "5 4\n3 2 1 5", "output": "3 2 1 5 4 " }, { "input": "10 4\n6 4 1 3", "output": "6 4 1 3 2 5 10 9 8 7 " }, { "input": "4 3\n3 4 2", "output": "-1" }, { "input": "4 3\n3 1 4", "output": "-1" }, { "input": "3 2\n2 3", "output": "-1" }, { "input": "4 3\n1 4 2", "output": "1 4 2 3 " }, { "input": "4 3\n3 1 2", "output": "3 1 2 4 " }, { "input": "2 1\n1", "output": "1 2 " }, { "input": "3 2\n3 2", "output": "3 2 1 " }, { "input": "4 3\n4 1 2", "output": "4 1 2 3 " }, { "input": "3 2\n3 1", "output": "3 1 2 " }, { "input": "4 3\n2 1 4", "output": "2 1 4 3 " }, { "input": "8 5\n3 1 4 2 7", "output": "-1" }, { "input": "6 4\n2 5 1 4", "output": "-1" }, { "input": "10 5\n10 1 8 5 6", "output": "-1" }, { "input": "10 3\n6 4 3", "output": "6 4 3 2 1 5 10 9 8 7 " }, { "input": "10 3\n2 1 6", "output": "2 1 6 5 4 3 10 9 8 7 " }, { "input": "10 3\n8 1 7", "output": "8 1 7 6 5 4 3 2 10 9 " }, { "input": "10 2\n5 4", "output": "5 4 3 2 1 10 9 8 7 6 " }, { "input": "10 3\n1 2 10", "output": "1 2 10 9 8 7 6 5 4 3 " }, { "input": "10 4\n4 1 6 3", "output": "-1" }, { "input": "10 3\n8 1 5", "output": "8 1 5 4 3 2 7 6 10 9 " }, { "input": "10 4\n1 4 9 8", "output": "-1" }, { "input": "10 3\n3 1 6", "output": "-1" }, { "input": "10 6\n1 2 5 4 3 6", "output": "1 2 5 4 3 6 10 9 8 7 " }, { "input": "10 9\n9 8 7 5 4 3 2 1 6", "output": "9 8 7 5 4 3 2 1 6 10 " }, { "input": "10 4\n4 7 5 10", "output": "-1" }, { "input": "10 5\n8 6 2 1 5", "output": "8 6 2 1 5 4 3 7 10 9 " }, { "input": "10 7\n7 5 2 1 4 3 6", "output": "7 5 2 1 4 3 6 10 9 8 " }, { "input": "10 4\n1 2 10 6", "output": "1 2 10 6 5 4 3 9 8 7 " }, { "input": "10 6\n1 10 9 5 4 3", "output": "1 10 9 5 4 3 2 8 7 6 " }, { "input": "10 8\n6 10 4 7 9 8 5 3", "output": "-1" }, { "input": "10 4\n6 1 10 3", "output": "-1" }, { "input": "10 9\n9 6 1 4 2 3 5 10 7", "output": "-1" }, { "input": "10 9\n10 1 9 3 2 4 5 8 6", "output": "10 1 9 3 2 4 5 8 6 7 " }, { "input": "10 4\n10 8 1 7", "output": "10 8 1 7 6 5 4 3 2 9 " }, { "input": "10 4\n2 1 3 6", "output": "2 1 3 6 5 4 10 9 8 7 " }, { "input": "10 3\n2 1 4", "output": "2 1 4 3 10 9 8 7 6 5 " }, { "input": "10 3\n4 1 5", "output": "-1" }, { "input": "10 5\n9 8 1 2 10", "output": "-1" }, { "input": "10 3\n9 8 3", "output": "9 8 3 2 1 7 6 5 4 10 " }, { "input": "10 4\n8 2 1 5", "output": "8 2 1 5 4 3 7 6 10 9 " }, { "input": "10 6\n6 5 3 1 2 4", "output": "6 5 3 1 2 4 10 9 8 7 " }, { "input": "10 2\n1 2", "output": "1 2 10 9 8 7 6 5 4 3 " }, { "input": "10 6\n9 6 5 2 1 4", "output": "9 6 5 2 1 4 3 8 7 10 " }, { "input": "10 4\n2 1 7 3", "output": "2 1 7 3 6 5 4 10 9 8 " }, { "input": "10 2\n6 5", "output": "6 5 4 3 2 1 10 9 8 7 " }, { "input": "10 3\n2 1 5", "output": "2 1 5 4 3 10 9 8 7 6 " }, { "input": "10 4\n3 1 2 4", "output": "3 1 2 4 10 9 8 7 6 5 " }, { "input": "10 3\n8 5 4", "output": "8 5 4 3 2 1 7 6 10 9 " }, { "input": "10 4\n2 1 8 4", "output": "2 1 8 4 3 7 6 5 10 9 " }, { "input": "10 3\n8 3 2", "output": "8 3 2 1 7 6 5 4 10 9 " }, { "input": "10 3\n5 4 2", "output": "5 4 2 1 3 10 9 8 7 6 " }, { "input": "10 9\n10 8 7 5 6 2 1 9 4", "output": "-1" }, { "input": "10 4\n2 1 6 4", "output": "2 1 6 4 3 5 10 9 8 7 " }, { "input": "10 4\n2 1 3 9", "output": "2 1 3 9 8 7 6 5 4 10 " }, { "input": "10 3\n1 4 3", "output": "1 4 3 2 10 9 8 7 6 5 " }, { "input": "10 7\n3 2 1 9 8 6 5", "output": "3 2 1 9 8 6 5 4 7 10 " }, { "input": "10 4\n10 7 1 5", "output": "10 7 1 5 4 3 2 6 9 8 " }, { "input": "10 4\n8 7 1 2", "output": "8 7 1 2 6 5 4 3 10 9 " }, { "input": "10 4\n1 5 4 2", "output": "1 5 4 2 3 10 9 8 7 6 " }, { "input": "10 5\n2 1 9 3 7", "output": "2 1 9 3 7 6 5 4 8 10 " }, { "input": "10 4\n2 1 5 3", "output": "2 1 5 3 4 10 9 8 7 6 " }, { "input": "10 5\n9 6 1 8 2", "output": "-1" }, { "input": "20 13\n3 2 1 7 4 5 6 11 10 9 8 13 12", "output": "3 2 1 7 4 5 6 11 10 9 8 13 12 20 19 18 17 16 15 14 " }, { "input": "20 14\n3 2 1 7 4 5 6 14 11 10 9 8 13 12", "output": "3 2 1 7 4 5 6 14 11 10 9 8 13 12 20 19 18 17 16 15 " }, { "input": "10 5\n9 4 2 1 5", "output": "-1" }, { "input": "10 5\n1 5 2 10 3", "output": "-1" }, { "input": "10 8\n6 5 3 1 2 4 9 8", "output": "6 5 3 1 2 4 9 8 7 10 " }, { "input": "10 4\n10 9 3 7", "output": "-1" }, { "input": "10 7\n10 8 5 1 2 7 3", "output": "-1" }, { "input": "10 3\n3 1 5", "output": "-1" }, { "input": "10 5\n1 9 8 4 3", "output": "1 9 8 4 3 2 7 6 5 10 " }, { "input": "10 3\n1 8 4", "output": "1 8 4 3 2 7 6 5 10 9 " }, { "input": "10 4\n6 2 1 4", "output": "6 2 1 4 3 5 10 9 8 7 " }, { "input": "10 3\n1 6 4", "output": "1 6 4 3 2 5 10 9 8 7 " }, { "input": "10 3\n10 9 3", "output": "10 9 3 2 1 8 7 6 5 4 " }, { "input": "10 9\n8 10 4 1 3 2 9 7 5", "output": "-1" }, { "input": "10 3\n7 10 6", "output": "-1" }, { "input": "10 3\n9 10 8", "output": "-1" }, { "input": "10 6\n10 8 1 6 2 7", "output": "-1" }, { "input": "10 6\n6 5 1 2 9 3", "output": "-1" }, { "input": "10 3\n10 1 8", "output": "10 1 8 7 6 5 4 3 2 9 " }, { "input": "10 9\n1 9 7 10 5 8 4 6 3", "output": "-1" }, { "input": "10 5\n1 9 3 2 5", "output": "1 9 3 2 5 4 8 7 6 10 " }, { "input": "10 4\n10 1 9 7", "output": "10 1 9 7 6 5 4 3 2 8 " }, { "input": "10 8\n1 10 3 2 9 4 8 5", "output": "1 10 3 2 9 4 8 5 7 6 " }, { "input": "10 1\n1", "output": "1 10 9 8 7 6 5 4 3 2 " }, { "input": "10 7\n9 7 1 6 5 4 2", "output": "9 7 1 6 5 4 2 3 8 10 " }, { "input": "10 9\n10 2 1 7 8 3 5 6 9", "output": "-1" }, { "input": "10 4\n2 1 3 10", "output": "2 1 3 10 9 8 7 6 5 4 " }, { "input": "10 9\n5 1 4 6 3 9 8 10 7", "output": "-1" }, { "input": "10 6\n8 2 1 7 6 5", "output": "8 2 1 7 6 5 4 3 10 9 " }, { "input": "10 5\n2 9 8 6 1", "output": "-1" }, { "input": "10 4\n9 2 1 6", "output": "9 2 1 6 5 4 3 8 7 10 " }, { "input": "10 3\n2 1 7", "output": "2 1 7 6 5 4 3 10 9 8 " }, { "input": "10 7\n4 1 2 10 9 6 3", "output": "-1" }, { "input": "10 6\n10 2 1 3 9 4", "output": "10 2 1 3 9 4 8 7 6 5 " }, { "input": "10 4\n9 2 1 4", "output": "9 2 1 4 3 8 7 6 5 10 " }, { "input": "10 3\n5 1 4", "output": "5 1 4 3 2 10 9 8 7 6 " }, { "input": "10 4\n4 1 2 10", "output": "-1" }, { "input": "8 6\n5 4 3 2 1 8", "output": "5 4 3 2 1 8 7 6 " }, { "input": "10 4\n1 6 5 4", "output": "1 6 5 4 3 2 10 9 8 7 " }, { "input": "10 2\n10 2", "output": "10 2 1 9 8 7 6 5 4 3 " }, { "input": "10 5\n1 6 2 10 5", "output": "-1" }, { "input": "10 9\n6 1 2 10 9 5 3 4 8", "output": "-1" }, { "input": "10 5\n4 1 7 2 3", "output": "-1" }, { "input": "10 4\n2 1 3 4", "output": "2 1 3 4 10 9 8 7 6 5 " }, { "input": "11 2\n3 2", "output": "3 2 1 11 10 9 8 7 6 5 4 " }, { "input": "6 5\n3 2 1 4 5", "output": "3 2 1 4 5 6 " }, { "input": "5 4\n2 1 3 5", "output": "2 1 3 5 4 " }, { "input": "10 6\n3 2 1 5 4 6", "output": "3 2 1 5 4 6 10 9 8 7 " }, { "input": "11 5\n1 8 7 6 5", "output": "1 8 7 6 5 4 3 2 11 10 9 " }, { "input": "10 3\n2 1 3", "output": "2 1 3 10 9 8 7 6 5 4 " }, { "input": "10 4\n2 1 7 6", "output": "2 1 7 6 5 4 3 10 9 8 " }, { "input": "10 4\n5 4 1 8", "output": "-1" }, { "input": "10 4\n9 1 5 4", "output": "9 1 5 4 3 2 8 7 6 10 " }, { "input": "10 3\n6 1 4", "output": "6 1 4 3 2 5 10 9 8 7 " }, { "input": "10 6\n1 9 3 2 4 6", "output": "1 9 3 2 4 6 5 8 7 10 " }, { "input": "10 3\n10 1 9", "output": "10 1 9 8 7 6 5 4 3 2 " }, { "input": "10 3\n1 9 7", "output": "1 9 7 6 5 4 3 2 8 10 " }, { "input": "10 2\n2 10", "output": "-1" }, { "input": "10 5\n9 2 1 4 3", "output": "9 2 1 4 3 8 7 6 5 10 " }, { "input": "10 6\n1 2 3 6 5 4", "output": "1 2 3 6 5 4 10 9 8 7 " }, { "input": "10 5\n7 6 5 1 4", "output": "7 6 5 1 4 3 2 10 9 8 " }, { "input": "10 9\n8 1 3 4 10 5 9 7 2", "output": "-1" } ]
1,539,027,106
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
#include <bits/stdc++.h> using namespace std; typedef long long int ll; const int N = 1e5 + 10, MOD = 998244353; int n, k, t; stack<int> s; vector<int> res; bool check() { if (s.empty()) return false; return true; } int main() { scanf("%d%d", &n, &k); int cur = 1; for (int i = 0; i < k; i++) { scanf("%d", &t); res.push_back(t); if (t == cur) { cur++; } else { if (check()) { if (s.top() < t) return printf("-1"), 0; s.push(t); } else { s.push(t); } } } while (cur != n) { if (s.empty()) { res.push_back(n); s.push(n); } if (cur == s.top()) { s.pop(); cur++; } else { res.push_back(s.top() - 1); s.push(s.top() - 1); } } for (int i = 0; i < res.size(); i++){ printf("%d ", res[i]); } return 0; }
Title: Stack Sorting Time Limit: None seconds Memory Limit: None megabytes Problem Description: Let's suppose you have an array *a*, a stack *s* (initially empty) and an array *b* (also initially empty). You may perform the following operations until both *a* and *s* are empty: - Take the first element of *a*, push it into *s* and remove it from *a* (if *a* is not empty); - Take the top element from *s*, append it to the end of array *b* and remove it from *s* (if *s* is not empty). You can perform these operations in arbitrary order. If there exists a way to perform the operations such that array *b* is sorted in non-descending order in the end, then array *a* is called stack-sortable. For example, [3,<=1,<=2] is stack-sortable, because *b* will be sorted if we perform the following operations: 1. Remove 3 from *a* and push it into *s*; 1. Remove 1 from *a* and push it into *s*; 1. Remove 1 from *s* and append it to the end of *b*; 1. Remove 2 from *a* and push it into *s*; 1. Remove 2 from *s* and append it to the end of *b*; 1. Remove 3 from *s* and append it to the end of *b*. After all these operations *b*<==<=[1,<=2,<=3], so [3,<=1,<=2] is stack-sortable. [2,<=3,<=1] is not stack-sortable. You are given *k* first elements of some permutation *p* of size *n* (recall that a permutation of size *n* is an array of size *n* where each integer from 1 to *n* occurs exactly once). You have to restore the remaining *n*<=-<=*k* elements of this permutation so it is stack-sortable. If there are multiple answers, choose the answer such that *p* is lexicographically maximal (an array *q* is lexicographically greater than an array *p* iff there exists some integer *k* such that for every *i*<=&lt;<=*k* *q**i*<==<=*p**i*, and *q**k*<=&gt;<=*p**k*). You may not swap or change any of first *k* elements of the permutation. Print the lexicographically maximal permutation *p* you can obtain. If there exists no answer then output -1. Input Specification: The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=200000, 1<=≤<=*k*<=&lt;<=*n*) — the size of a desired permutation, and the number of elements you are given, respectively. The second line contains *k* integers *p*1, *p*2, ..., *p**k* (1<=≤<=*p**i*<=≤<=*n*) — the first *k* elements of *p*. These integers are pairwise distinct. Output Specification: If it is possible to restore a stack-sortable permutation *p* of size *n* such that the first *k* elements of *p* are equal to elements given in the input, print lexicographically maximal such permutation. Otherwise print -1. Demo Input: ['5 3\n3 2 1\n', '5 3\n2 3 1\n', '5 1\n3\n', '5 2\n3 4\n'] Demo Output: ['3 2 1 5 4 ', '-1\n', '3 2 1 5 4 ', '-1\n'] Note: none
```python #include <bits/stdc++.h> using namespace std; typedef long long int ll; const int N = 1e5 + 10, MOD = 998244353; int n, k, t; stack<int> s; vector<int> res; bool check() { if (s.empty()) return false; return true; } int main() { scanf("%d%d", &n, &k); int cur = 1; for (int i = 0; i < k; i++) { scanf("%d", &t); res.push_back(t); if (t == cur) { cur++; } else { if (check()) { if (s.top() < t) return printf("-1"), 0; s.push(t); } else { s.push(t); } } } while (cur != n) { if (s.empty()) { res.push_back(n); s.push(n); } if (cur == s.top()) { s.pop(); cur++; } else { res.push_back(s.top() - 1); s.push(s.top() - 1); } } for (int i = 0; i < res.size(); i++){ printf("%d ", res[i]); } return 0; } ```
-1
205
A
Little Elephant and Rozdil
PROGRAMMING
900
[ "brute force", "implementation" ]
null
null
The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil"). However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elephant doesn't like to spend much time on travelling, so for his journey he will choose a town that needs minimum time to travel to. If there are multiple such cities, then the Little Elephant won't go anywhere. For each town except for Rozdil you know the time needed to travel to this town. Find the town the Little Elephant will go to or print "Still Rozdil", if he stays in Rozdil.
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of cities. The next line contains *n* integers, separated by single spaces: the *i*-th integer represents the time needed to go from town Rozdil to the *i*-th town. The time values are positive integers, not exceeding 109. You can consider the cities numbered from 1 to *n*, inclusive. Rozdil is not among the numbered cities.
Print the answer on a single line — the number of the town the Little Elephant will go to. If there are multiple cities with minimum travel time, print "Still Rozdil" (without the quotes).
[ "2\n7 4\n", "7\n7 4 47 100 4 9 12\n" ]
[ "2\n", "Still Rozdil\n" ]
In the first sample there are only two cities where the Little Elephant can go. The travel time for the first town equals 7, to the second one — 4. The town which is closest to Rodzil (the only one) is the second one, so the answer is 2. In the second sample the closest cities are cities two and five, the travelling time to both of them equals 4, so the answer is "Still Rozdil".
500
[ { "input": "2\n7 4", "output": "2" }, { "input": "7\n7 4 47 100 4 9 12", "output": "Still Rozdil" }, { "input": "1\n47", "output": "1" }, { "input": "2\n1000000000 1000000000", "output": "Still Rozdil" }, { "input": "7\n7 6 5 4 3 2 1", "output": "7" }, { "input": "10\n1 1 1 1 1 1 1 1 1 1", "output": "Still Rozdil" }, { "input": "4\n1000000000 100000000 1000000 1000000", "output": "Still Rozdil" }, { "input": "20\n7 1 1 2 1 1 8 7 7 8 4 3 7 10 5 3 10 5 10 6", "output": "Still Rozdil" }, { "input": "20\n3 3 6 9 8 2 4 1 7 3 2 9 7 7 9 7 2 6 2 7", "output": "8" }, { "input": "47\n35 79 84 56 67 95 80 34 77 68 14 55 95 32 40 89 58 79 96 66 50 79 35 86 31 74 91 35 22 72 84 38 11 59 73 51 65 11 11 62 30 12 32 71 69 15 11", "output": "Still Rozdil" }, { "input": "47\n3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3", "output": "32" }, { "input": "25\n73 56 65 70 57 57 49 50 65 68 54 48 66 55 55 66 60 70 47 62 63 70 62 70 63", "output": "19" }, { "input": "100\n922 938 103 689 526 118 314 496 373 47 224 544 495 656 804 754 269 356 354 536 817 597 787 178 516 659 790 993 786 169 866 779 997 350 674 437 219 546 564 893 402 449 751 628 238 686 392 951 716 439 332 563 215 146 746 311 866 773 548 675 731 183 890 802 488 944 473 25 662 559 732 534 777 144 502 593 839 692 84 337 679 718 1005 663 709 940 86 469 310 960 902 233 606 761 116 231 662 903 68 622", "output": "68" }, { "input": "5\n5 5 2 3 1", "output": "5" }, { "input": "1\n1000000000", "output": "1" }, { "input": "3\n7 7 4", "output": "3" }, { "input": "3\n2 2 1", "output": "3" }, { "input": "3\n4 4 3", "output": "3" }, { "input": "2\n10000001 10000002", "output": "1" }, { "input": "4\n3 3 2 1", "output": "4" }, { "input": "3\n1 2 3", "output": "1" }, { "input": "2\n1000000000 100000000", "output": "2" }, { "input": "1\n99999999", "output": "1" }, { "input": "3\n5 5 3", "output": "3" }, { "input": "3\n7 7 5", "output": "3" }, { "input": "3\n3 3 1", "output": "3" }, { "input": "4\n10 10 10 1", "output": "4" } ]
1,617,756,283
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
2
186
0
# https://codeforces.com/problemset/problem/205/A n = int(input()) cities = [int(num) for num in input().split()] still = False min = cities[0] city = n for index, distance in enumerate(cities): if distance <= min: if min == distance: still = True else: min = distance still = False city = index + 1 print(city if not still else "Still Rozdil")
Title: Little Elephant and Rozdil Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil"). However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elephant doesn't like to spend much time on travelling, so for his journey he will choose a town that needs minimum time to travel to. If there are multiple such cities, then the Little Elephant won't go anywhere. For each town except for Rozdil you know the time needed to travel to this town. Find the town the Little Elephant will go to or print "Still Rozdil", if he stays in Rozdil. Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of cities. The next line contains *n* integers, separated by single spaces: the *i*-th integer represents the time needed to go from town Rozdil to the *i*-th town. The time values are positive integers, not exceeding 109. You can consider the cities numbered from 1 to *n*, inclusive. Rozdil is not among the numbered cities. Output Specification: Print the answer on a single line — the number of the town the Little Elephant will go to. If there are multiple cities with minimum travel time, print "Still Rozdil" (without the quotes). Demo Input: ['2\n7 4\n', '7\n7 4 47 100 4 9 12\n'] Demo Output: ['2\n', 'Still Rozdil\n'] Note: In the first sample there are only two cities where the Little Elephant can go. The travel time for the first town equals 7, to the second one — 4. The town which is closest to Rodzil (the only one) is the second one, so the answer is 2. In the second sample the closest cities are cities two and five, the travelling time to both of them equals 4, so the answer is "Still Rozdil".
```python # https://codeforces.com/problemset/problem/205/A n = int(input()) cities = [int(num) for num in input().split()] still = False min = cities[0] city = n for index, distance in enumerate(cities): if distance <= min: if min == distance: still = True else: min = distance still = False city = index + 1 print(city if not still else "Still Rozdil") ```
0
27
B
Tournament
PROGRAMMING
1,300
[ "bitmasks", "brute force", "dfs and similar", "greedy" ]
B. Tournament
2
256
The tournament «Sleepyhead-2010» in the rapid falling asleep has just finished in Berland. *n* best participants from the country have participated in it. The tournament consists of games, each of them is a match between two participants. *n*·(*n*<=-<=1)<=/<=2 games were played during the tournament, and each participant had a match with each other participant. The rules of the game are quite simple — the participant who falls asleep first wins. The secretary made a record of each game in the form «*x**i* *y**i*», where *x**i* and *y**i* are the numbers of participants. The first number in each pair is a winner (i.e. *x**i* is a winner and *y**i* is a loser). There is no draws. Recently researches form the «Institute Of Sleep» have found that every person is characterized by a value *p**j* — the speed of falling asleep. The person who has lower speed wins. Every person has its own value *p**j*, constant during the life. It is known that all participants of the tournament have distinct speeds of falling asleep. Also it was found that the secretary made records about all the games except one. You are to find the result of the missing game.
The first line contains one integer *n* (3<=≤<=*n*<=≤<=50) — the number of participants. The following *n*·(*n*<=-<=1)<=/<=2<=-<=1 lines contain the results of the games. Each game is described in a single line by two integers *x**i*,<=*y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*,<=*x**i*<=≠<=*y**i*), where *x**i* и *y**i* are the numbers of the opponents in this game. It is known that during the tournament each of the *n* participants played *n*<=-<=1 games, one game with each other participant.
Output two integers *x* and *y* — the missing record. If there are several solutions, output any of them.
[ "4\n4 2\n4 1\n2 3\n2 1\n3 1\n" ]
[ "4 3\n" ]
none
1,000
[ { "input": "3\n3 2\n1 2", "output": "1 3" }, { "input": "4\n2 4\n3 4\n1 2\n1 4\n1 3", "output": "2 3" }, { "input": "5\n3 5\n2 5\n1 5\n1 4\n4 3\n1 3\n2 3\n4 5\n4 2", "output": "1 2" }, { "input": "6\n3 4\n3 5\n5 4\n1 2\n5 6\n2 6\n5 2\n3 6\n3 2\n4 6\n2 4\n1 3\n1 5\n1 4", "output": "1 6" }, { "input": "7\n2 4\n6 1\n6 5\n3 4\n6 3\n2 6\n6 4\n3 7\n7 1\n1 4\n7 4\n7 5\n2 7\n2 3\n5 4\n3 5\n3 1\n5 1\n6 7\n2 1", "output": "2 5" }, { "input": "8\n4 3\n6 8\n1 5\n8 3\n1 4\n1 7\n5 6\n5 3\n5 8\n7 3\n7 8\n2 3\n1 3\n2 8\n1 6\n5 4\n1 2\n2 5\n4 8\n1 8\n2 6\n2 7\n4 7\n2 4\n6 4\n6 7\n6 3", "output": "5 7" }, { "input": "9\n4 5\n9 6\n5 6\n8 7\n5 1\n8 5\n9 5\n4 7\n2 6\n7 6\n3 5\n2 1\n8 2\n3 7\n9 1\n2 5\n2 7\n4 2\n8 9\n8 1\n3 6\n7 1\n8 6\n3 2\n3 1\n9 2\n4 6\n5 7\n1 6\n4 8\n4 1\n4 3\n4 9\n9 3\n9 7", "output": "8 3" }, { "input": "3\n3 2\n1 2", "output": "1 3" }, { "input": "3\n1 3\n2 3", "output": "1 2" }, { "input": "3\n2 1\n3 1", "output": "2 3" }, { "input": "4\n3 1\n4 1\n4 2\n3 2\n3 4", "output": "1 2" }, { "input": "4\n3 4\n1 4\n2 3\n2 1\n2 4", "output": "1 3" }, { "input": "4\n2 3\n1 3\n2 1\n4 1\n4 3", "output": "2 4" }, { "input": "5\n5 2\n3 1\n5 3\n5 1\n3 4\n1 4\n3 2\n1 2\n5 4", "output": "2 4" }, { "input": "5\n2 1\n4 1\n5 1\n4 5\n3 5\n2 3\n3 1\n2 5\n2 4", "output": "3 4" }, { "input": "5\n4 5\n4 3\n5 3\n4 1\n3 1\n3 2\n5 2\n4 2\n5 1", "output": "1 2" }, { "input": "5\n4 5\n1 5\n4 3\n2 5\n2 1\n2 4\n3 5\n2 3\n1 3", "output": "1 4" }, { "input": "5\n2 4\n5 3\n5 4\n2 5\n1 4\n2 3\n1 5\n1 3\n1 2", "output": "3 4" }, { "input": "6\n6 1\n5 6\n4 1\n3 1\n3 4\n4 6\n4 5\n3 2\n4 2\n6 2\n5 1\n3 5\n3 6\n5 2", "output": "1 2" }, { "input": "6\n6 2\n6 4\n4 1\n4 3\n5 6\n5 2\n6 3\n5 1\n5 3\n2 1\n2 3\n6 1\n3 1\n5 4", "output": "2 4" }, { "input": "6\n5 3\n6 5\n3 4\n1 5\n2 3\n6 2\n2 5\n5 4\n6 4\n1 4\n6 3\n6 1\n2 4\n1 3", "output": "1 2" }, { "input": "6\n3 1\n5 4\n2 1\n6 2\n5 2\n3 6\n6 4\n3 2\n3 4\n6 1\n6 5\n5 1\n2 4\n3 5", "output": "1 4" }, { "input": "6\n6 1\n1 3\n3 4\n6 3\n2 4\n6 2\n1 5\n5 3\n5 4\n6 4\n1 2\n1 4\n6 5\n5 2", "output": "2 3" } ]
1,557,298,884
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
6
218
0
n = int(input()) mp = {} tot = n*(n-1)//2-1 for i in range(tot): a, b = map(int, input().split()) if a not in mp: mp[a] = [b] else: mp[a].append(b) if b not in mp: mp[b] = [a] else: mp[b].append(a) for i in range(n): if len(mp[i+1]) < n-1: for k in range(n): if k == i: continue if k+1 not in mp[i+1]: print (i+1, k+1) exit(0)
Title: Tournament Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: The tournament «Sleepyhead-2010» in the rapid falling asleep has just finished in Berland. *n* best participants from the country have participated in it. The tournament consists of games, each of them is a match between two participants. *n*·(*n*<=-<=1)<=/<=2 games were played during the tournament, and each participant had a match with each other participant. The rules of the game are quite simple — the participant who falls asleep first wins. The secretary made a record of each game in the form «*x**i* *y**i*», where *x**i* and *y**i* are the numbers of participants. The first number in each pair is a winner (i.e. *x**i* is a winner and *y**i* is a loser). There is no draws. Recently researches form the «Institute Of Sleep» have found that every person is characterized by a value *p**j* — the speed of falling asleep. The person who has lower speed wins. Every person has its own value *p**j*, constant during the life. It is known that all participants of the tournament have distinct speeds of falling asleep. Also it was found that the secretary made records about all the games except one. You are to find the result of the missing game. Input Specification: The first line contains one integer *n* (3<=≤<=*n*<=≤<=50) — the number of participants. The following *n*·(*n*<=-<=1)<=/<=2<=-<=1 lines contain the results of the games. Each game is described in a single line by two integers *x**i*,<=*y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*,<=*x**i*<=≠<=*y**i*), where *x**i* и *y**i* are the numbers of the opponents in this game. It is known that during the tournament each of the *n* participants played *n*<=-<=1 games, one game with each other participant. Output Specification: Output two integers *x* and *y* — the missing record. If there are several solutions, output any of them. Demo Input: ['4\n4 2\n4 1\n2 3\n2 1\n3 1\n'] Demo Output: ['4 3\n'] Note: none
```python n = int(input()) mp = {} tot = n*(n-1)//2-1 for i in range(tot): a, b = map(int, input().split()) if a not in mp: mp[a] = [b] else: mp[a].append(b) if b not in mp: mp[b] = [a] else: mp[b].append(a) for i in range(n): if len(mp[i+1]) < n-1: for k in range(n): if k == i: continue if k+1 not in mp[i+1]: print (i+1, k+1) exit(0) ```
0
991
B
Getting an A
PROGRAMMING
900
[ "greedy", "sortings" ]
null
null
Translator's note: in Russia's most widespread grading system, there are four grades: 5, 4, 3, 2, the higher the better, roughly corresponding to A, B, C and F respectively in American grading system. The term is coming to an end and students start thinking about their grades. Today, a professor told his students that the grades for his course would be given out automatically  — he would calculate the simple average (arithmetic mean) of all grades given out for lab works this term and round to the nearest integer. The rounding would be done in favour of the student — $4.5$ would be rounded up to $5$ (as in example 3), but $4.4$ would be rounded down to $4$. This does not bode well for Vasya who didn't think those lab works would influence anything, so he may receive a grade worse than $5$ (maybe even the dreaded $2$). However, the professor allowed him to redo some of his works of Vasya's choosing to increase his average grade. Vasya wants to redo as as few lab works as possible in order to get $5$ for the course. Of course, Vasya will get $5$ for the lab works he chooses to redo. Help Vasya — calculate the minimum amount of lab works Vasya has to redo.
The first line contains a single integer $n$ — the number of Vasya's grades ($1 \leq n \leq 100$). The second line contains $n$ integers from $2$ to $5$ — Vasya's grades for his lab works.
Output a single integer — the minimum amount of lab works that Vasya has to redo. It can be shown that Vasya can always redo enough lab works to get a $5$.
[ "3\n4 4 4\n", "4\n5 4 5 5\n", "4\n5 3 3 5\n" ]
[ "2\n", "0\n", "1\n" ]
In the first sample, it is enough to redo two lab works to make two $4$s into $5$s. In the second sample, Vasya's average is already $4.75$ so he doesn't have to redo anything to get a $5$. In the second sample Vasya has to redo one lab work to get rid of one of the $3$s, that will make the average exactly $4.5$ so the final grade would be $5$.
1,000
[ { "input": "3\n4 4 4", "output": "2" }, { "input": "4\n5 4 5 5", "output": "0" }, { "input": "4\n5 3 3 5", "output": "1" }, { "input": "1\n5", "output": "0" }, { "input": "4\n3 2 5 4", "output": "2" }, { "input": "5\n5 4 3 2 5", "output": "2" }, { "input": "8\n5 4 2 5 5 2 5 5", "output": "1" }, { "input": "5\n5 5 2 5 5", "output": "1" }, { "input": "6\n5 5 5 5 5 2", "output": "0" }, { "input": "6\n2 2 2 2 2 2", "output": "5" }, { "input": "100\n3 2 4 3 3 3 4 2 3 5 5 2 5 2 3 2 4 4 4 5 5 4 2 5 4 3 2 5 3 4 3 4 2 4 5 4 2 4 3 4 5 2 5 3 3 4 2 2 4 4 4 5 4 3 3 3 2 5 2 2 2 3 5 4 3 2 4 5 5 5 2 2 4 2 3 3 3 5 3 2 2 4 5 5 4 5 5 4 2 3 2 2 2 2 5 3 5 2 3 4", "output": "40" }, { "input": "1\n2", "output": "1" }, { "input": "1\n3", "output": "1" }, { "input": "1\n4", "output": "1" }, { "input": "4\n3 2 5 5", "output": "1" }, { "input": "6\n4 3 3 3 3 4", "output": "4" }, { "input": "8\n3 3 5 3 3 3 5 5", "output": "3" }, { "input": "10\n2 4 5 5 5 5 2 3 3 2", "output": "3" }, { "input": "20\n5 2 5 2 2 2 2 2 5 2 2 5 2 5 5 2 2 5 2 2", "output": "10" }, { "input": "25\n4 4 4 4 3 4 3 3 3 3 3 4 4 3 4 4 4 4 4 3 3 3 4 3 4", "output": "13" }, { "input": "30\n4 2 4 2 4 2 2 4 4 4 4 2 4 4 4 2 2 2 2 4 2 4 4 4 2 4 2 4 2 2", "output": "15" }, { "input": "52\n5 3 4 4 4 3 5 3 4 5 3 4 4 3 5 5 4 3 3 3 4 5 4 4 5 3 5 3 5 4 5 5 4 3 4 5 3 4 3 3 4 4 4 3 5 3 4 5 3 5 4 5", "output": "14" }, { "input": "77\n5 3 2 3 2 3 2 3 5 2 2 3 3 3 3 5 3 3 2 2 2 5 5 5 5 3 2 2 5 2 3 2 2 5 2 5 3 3 2 2 5 5 2 3 3 2 3 3 3 2 5 5 2 2 3 3 5 5 2 2 5 5 3 3 5 5 2 2 5 2 2 5 5 5 2 5 2", "output": "33" }, { "input": "55\n3 4 2 3 3 2 4 4 3 3 4 2 4 4 3 3 2 3 2 2 3 3 2 3 2 3 2 4 4 3 2 3 2 3 3 2 2 4 2 4 4 3 4 3 2 4 3 2 4 2 2 3 2 3 4", "output": "34" }, { "input": "66\n5 4 5 5 4 4 4 4 4 2 5 5 2 4 2 2 2 5 4 4 4 4 5 2 2 5 5 2 2 4 4 2 4 2 2 5 2 5 4 5 4 5 4 4 2 5 2 4 4 4 2 2 5 5 5 5 4 4 4 4 4 2 4 5 5 5", "output": "16" }, { "input": "99\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", "output": "83" }, { "input": "100\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2", "output": "84" }, { "input": "99\n3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3", "output": "75" }, { "input": "100\n3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3", "output": "75" }, { "input": "99\n2 2 3 3 3 3 3 2 2 3 2 3 2 3 2 2 3 2 3 2 3 3 3 3 2 2 2 2 3 2 3 3 3 3 3 2 3 3 3 3 2 3 2 3 3 3 2 3 2 3 3 3 3 2 2 3 2 3 2 3 2 3 2 2 2 3 3 2 3 2 2 2 2 2 2 2 2 3 3 3 3 2 3 2 3 3 2 3 2 3 2 3 3 2 2 2 3 2 3", "output": "75" }, { "input": "100\n3 2 3 3 2 2 3 2 2 3 3 2 3 2 2 2 2 2 3 2 2 2 3 2 3 3 2 2 3 2 2 2 2 3 2 3 3 2 2 3 2 2 3 2 3 2 2 3 2 3 2 2 3 2 2 3 3 3 3 3 2 2 3 2 3 3 2 2 3 2 2 2 3 2 2 3 3 2 2 3 3 3 3 2 3 2 2 2 3 3 2 2 3 2 2 2 2 3 2 2", "output": "75" }, { "input": "99\n4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4", "output": "50" }, { "input": "100\n4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4", "output": "50" }, { "input": "99\n2 2 2 2 4 2 2 2 2 4 4 4 4 2 4 4 2 2 4 4 2 2 2 4 4 2 4 4 2 4 4 2 2 2 4 4 2 2 2 2 4 4 4 2 2 2 4 4 2 4 2 4 2 2 4 2 4 4 4 4 4 2 2 4 4 4 2 2 2 2 4 2 4 2 2 2 2 2 2 4 4 2 4 2 2 4 2 2 2 2 2 4 2 4 2 2 4 4 4", "output": "54" }, { "input": "100\n4 2 4 4 2 4 2 2 4 4 4 4 4 4 4 4 4 2 4 4 2 2 4 4 2 2 4 4 2 2 2 4 4 2 4 4 2 4 2 2 4 4 2 4 2 4 4 4 2 2 2 2 2 2 2 4 2 2 2 4 4 4 2 2 2 2 4 2 2 2 2 2 2 2 4 4 4 4 4 4 4 4 4 2 2 2 2 2 2 2 2 4 4 4 4 2 4 2 2 4", "output": "50" }, { "input": "99\n4 3 4 4 4 4 4 3 4 3 3 4 3 3 4 4 3 3 3 4 3 4 3 3 4 3 3 3 3 4 3 4 4 3 4 4 3 3 4 4 4 3 3 3 4 4 3 3 4 3 4 3 4 3 4 3 3 3 3 4 3 4 4 4 4 4 4 3 4 4 3 3 3 3 3 3 3 3 4 3 3 3 4 4 4 4 4 4 3 3 3 3 4 4 4 3 3 4 3", "output": "51" }, { "input": "100\n3 3 4 4 4 4 4 3 4 4 3 3 3 3 4 4 4 4 4 4 3 3 3 4 3 4 3 4 3 3 4 3 3 3 3 3 3 3 3 4 3 4 3 3 4 3 3 3 4 4 3 4 4 3 3 4 4 4 4 4 4 3 4 4 3 4 3 3 3 4 4 3 3 4 4 3 4 4 4 3 3 4 3 3 4 3 4 3 4 3 3 4 4 4 3 3 4 3 3 4", "output": "51" }, { "input": "99\n3 3 4 4 4 2 4 4 3 2 3 4 4 4 2 2 2 3 2 4 4 2 4 3 2 2 2 4 2 3 4 3 4 2 3 3 4 2 3 3 2 3 4 4 3 2 4 3 4 3 3 3 3 3 4 4 3 3 4 4 2 4 3 4 3 2 3 3 3 4 4 2 4 4 2 3 4 2 3 3 3 4 2 2 3 2 4 3 2 3 3 2 3 4 2 3 3 2 3", "output": "58" }, { "input": "100\n2 2 4 2 2 3 2 3 4 4 3 3 4 4 4 2 3 2 2 3 4 2 3 2 4 3 4 2 3 3 3 2 4 3 3 2 2 3 2 4 4 2 4 3 4 4 3 3 3 2 4 2 2 2 2 2 2 3 2 3 2 3 4 4 4 2 2 3 4 4 3 4 3 3 2 3 3 3 4 3 2 3 3 2 4 2 3 3 4 4 3 3 4 3 4 3 3 4 3 3", "output": "61" }, { "input": "99\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5", "output": "0" }, { "input": "100\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5", "output": "0" }, { "input": "99\n2 2 2 2 2 5 2 2 5 2 5 2 5 2 2 2 2 2 5 2 2 2 5 2 2 5 2 2 2 5 5 2 5 2 2 5 2 5 2 2 5 5 2 2 2 2 5 5 2 2 2 5 2 2 5 2 2 2 2 2 5 5 5 5 2 2 5 2 5 2 2 2 2 2 5 2 2 5 5 2 2 2 2 2 5 5 2 2 5 5 2 2 2 2 5 5 5 2 5", "output": "48" }, { "input": "100\n5 5 2 2 2 2 2 2 5 5 2 5 2 2 2 2 5 2 5 2 5 5 2 5 5 2 2 2 2 2 2 5 2 2 2 5 2 2 5 2 2 5 5 5 2 5 5 5 5 5 5 2 2 5 2 2 5 5 5 5 5 2 5 2 5 2 2 2 5 2 5 2 5 5 2 5 5 2 2 5 2 5 5 2 5 2 2 5 2 2 2 5 2 2 2 2 5 5 2 5", "output": "38" }, { "input": "99\n5 3 3 3 5 3 3 3 3 3 3 3 3 5 3 3 3 3 3 3 3 3 5 3 3 3 5 5 3 5 5 3 3 5 5 5 3 5 3 3 3 3 5 3 3 5 5 3 5 5 5 3 5 3 5 3 5 5 5 5 3 3 3 5 3 5 3 3 3 5 5 5 5 5 3 5 5 3 3 5 5 3 5 5 3 5 5 3 3 5 5 5 3 3 3 5 3 3 3", "output": "32" }, { "input": "100\n3 3 3 5 3 3 3 3 3 3 5 5 5 5 3 3 3 3 5 3 3 3 3 3 5 3 5 3 3 5 5 5 5 5 5 3 3 5 3 3 5 3 5 5 5 3 5 3 3 3 3 3 3 3 3 3 3 3 5 5 3 5 3 5 5 3 5 3 3 5 3 5 5 5 5 3 5 3 3 3 5 5 5 3 3 3 5 3 5 5 5 3 3 3 5 3 5 5 3 5", "output": "32" }, { "input": "99\n5 3 5 5 3 3 3 2 2 5 2 5 3 2 5 2 5 2 3 5 3 2 3 2 5 5 2 2 3 3 5 5 3 5 5 2 3 3 5 2 2 5 3 2 5 2 3 5 5 2 5 2 2 5 3 3 5 3 3 5 3 2 3 5 3 2 3 2 3 2 2 2 2 5 2 2 3 2 5 5 5 3 3 2 5 3 5 5 5 2 3 2 5 5 2 5 2 5 3", "output": "39" }, { "input": "100\n3 5 3 3 5 5 3 3 2 5 5 3 3 3 2 2 3 2 5 3 2 2 3 3 3 3 2 5 3 2 3 3 5 2 2 2 3 2 3 5 5 3 2 5 2 2 5 5 3 5 5 5 2 2 5 5 3 3 2 2 2 5 3 3 2 2 3 5 3 2 3 5 5 3 2 3 5 5 3 3 2 3 5 2 5 5 5 5 5 5 3 5 3 2 3 3 2 5 2 2", "output": "42" }, { "input": "99\n4 4 4 5 4 4 5 5 4 4 5 5 5 4 5 4 5 5 5 4 4 5 5 5 5 4 5 5 5 4 4 5 5 4 5 4 4 4 5 5 5 5 4 4 5 4 4 5 4 4 4 4 5 5 5 4 5 4 5 5 5 5 5 4 5 4 5 4 4 4 4 5 5 5 4 5 5 4 4 5 5 5 4 5 4 4 5 5 4 5 5 5 5 4 5 5 4 4 4", "output": "0" }, { "input": "100\n4 4 5 5 5 5 5 5 4 4 5 5 4 4 5 5 4 5 4 4 4 4 4 4 4 4 5 5 5 5 5 4 4 4 4 4 5 4 4 5 4 4 4 5 5 5 4 5 5 5 5 5 5 4 4 4 4 4 4 5 5 4 5 4 4 5 4 4 4 4 5 5 4 5 5 4 4 4 5 5 5 5 4 5 5 5 4 4 5 5 5 4 5 4 5 4 4 5 5 4", "output": "1" }, { "input": "99\n2 2 2 5 2 2 2 2 2 4 4 5 5 2 2 4 2 5 2 2 2 5 2 2 5 5 5 4 5 5 4 4 2 2 5 2 2 2 2 5 5 2 2 4 4 4 2 2 2 5 2 4 4 2 4 2 4 2 5 4 2 2 5 2 4 4 4 2 5 2 2 5 4 2 2 5 5 5 2 4 5 4 5 5 4 4 4 5 4 5 4 5 4 2 5 2 2 2 4", "output": "37" }, { "input": "100\n4 4 5 2 2 5 4 5 2 2 2 4 2 5 4 4 2 2 4 5 2 4 2 5 5 4 2 4 4 2 2 5 4 2 5 4 5 2 5 2 4 2 5 4 5 2 2 2 5 2 5 2 5 2 2 4 4 5 5 5 5 5 5 5 4 2 2 2 4 2 2 4 5 5 4 5 4 2 2 2 2 4 2 2 5 5 4 2 2 5 4 5 5 5 4 5 5 5 2 2", "output": "31" }, { "input": "99\n5 3 4 4 5 4 4 4 3 5 4 3 3 4 3 5 5 5 5 4 3 3 5 3 4 5 3 5 4 4 3 5 5 4 4 4 4 3 5 3 3 5 5 5 5 5 4 3 4 4 3 5 5 3 3 4 4 4 5 4 4 5 4 4 4 4 5 5 4 3 3 4 3 5 3 3 3 3 4 4 4 4 3 4 5 4 4 5 5 5 3 4 5 3 4 5 4 3 3", "output": "24" }, { "input": "100\n5 4 4 4 5 5 5 4 5 4 4 3 3 4 4 4 5 4 5 5 3 5 5 4 5 5 5 4 4 5 3 5 3 5 3 3 5 4 4 5 5 4 5 5 3 4 5 4 4 3 4 4 3 3 5 4 5 4 5 3 4 5 3 4 5 4 3 5 4 5 4 4 4 3 4 5 3 4 3 5 3 4 4 4 3 4 4 5 3 3 4 4 5 5 4 3 4 4 3 5", "output": "19" }, { "input": "99\n2 2 5 2 5 3 4 2 3 5 4 3 4 2 5 3 2 2 4 2 4 4 5 4 4 5 2 5 5 3 2 3 2 2 3 4 5 3 5 2 5 4 4 5 4 2 2 3 2 3 3 3 4 4 3 2 2 4 4 2 5 3 5 3 5 4 4 4 5 4 5 2 2 5 4 4 4 3 3 2 5 2 5 2 3 2 5 2 2 5 5 3 4 5 3 4 4 4 4", "output": "37" }, { "input": "2\n5 2", "output": "1" }, { "input": "5\n2 2 2 2 2", "output": "5" }, { "input": "100\n2 3 2 2 2 3 2 3 3 3 3 3 2 3 3 2 2 3 3 2 3 2 3 2 3 4 4 4 3 3 3 3 3 4 4 3 3 4 3 2 3 4 3 3 3 3 2 3 4 3 4 3 3 2 4 4 2 4 4 3 3 3 3 4 3 2 3 4 3 4 4 4 4 4 3 2 2 3 4 2 4 4 4 2 2 4 2 2 3 2 2 4 4 3 4 2 3 3 2 2", "output": "61" }, { "input": "100\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4", "output": "1" }, { "input": "100\n5 4 3 5 3 5 4 2 3 3 4 5 4 5 5 4 2 4 2 2 5 2 5 3 4 4 4 5 5 5 3 4 4 4 3 5 3 2 5 4 3 3 3 5 2 3 4 2 5 4 3 4 5 2 2 3 4 4 2 3 3 3 2 5 2 3 4 3 3 3 2 5 4 3 4 5 4 2 5 4 5 2 2 4 2 2 5 5 4 5 2 2 2 2 5 2 4 4 4 5", "output": "35" }, { "input": "2\n2 2", "output": "2" }, { "input": "20\n4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5", "output": "1" } ]
1,560,872,386
2,147,483,647
Python 3
OK
TESTS
61
124
0
n = int(input()) lis = sorted(map(int,input().split())) s = sum(lis);c=0 if s/n>=4.5: print("0") else: for i in range(n): s+=(5-lis[i]) c+=1 if s/n>=4.5: print(c) break;
Title: Getting an A Time Limit: None seconds Memory Limit: None megabytes Problem Description: Translator's note: in Russia's most widespread grading system, there are four grades: 5, 4, 3, 2, the higher the better, roughly corresponding to A, B, C and F respectively in American grading system. The term is coming to an end and students start thinking about their grades. Today, a professor told his students that the grades for his course would be given out automatically  — he would calculate the simple average (arithmetic mean) of all grades given out for lab works this term and round to the nearest integer. The rounding would be done in favour of the student — $4.5$ would be rounded up to $5$ (as in example 3), but $4.4$ would be rounded down to $4$. This does not bode well for Vasya who didn't think those lab works would influence anything, so he may receive a grade worse than $5$ (maybe even the dreaded $2$). However, the professor allowed him to redo some of his works of Vasya's choosing to increase his average grade. Vasya wants to redo as as few lab works as possible in order to get $5$ for the course. Of course, Vasya will get $5$ for the lab works he chooses to redo. Help Vasya — calculate the minimum amount of lab works Vasya has to redo. Input Specification: The first line contains a single integer $n$ — the number of Vasya's grades ($1 \leq n \leq 100$). The second line contains $n$ integers from $2$ to $5$ — Vasya's grades for his lab works. Output Specification: Output a single integer — the minimum amount of lab works that Vasya has to redo. It can be shown that Vasya can always redo enough lab works to get a $5$. Demo Input: ['3\n4 4 4\n', '4\n5 4 5 5\n', '4\n5 3 3 5\n'] Demo Output: ['2\n', '0\n', '1\n'] Note: In the first sample, it is enough to redo two lab works to make two $4$s into $5$s. In the second sample, Vasya's average is already $4.75$ so he doesn't have to redo anything to get a $5$. In the second sample Vasya has to redo one lab work to get rid of one of the $3$s, that will make the average exactly $4.5$ so the final grade would be $5$.
```python n = int(input()) lis = sorted(map(int,input().split())) s = sum(lis);c=0 if s/n>=4.5: print("0") else: for i in range(n): s+=(5-lis[i]) c+=1 if s/n>=4.5: print(c) break; ```
3
515
C
Drazil and Factorial
PROGRAMMING
1,400
[ "greedy", "math", "sortings" ]
null
null
Drazil is playing a math game with Varda. Let's define for positive integer *x* as a product of factorials of its digits. For example, . First, they choose a decimal number *a* consisting of *n* digits that contains at least one digit larger than 1. This number may possibly start with leading zeroes. Then they should find maximum positive number *x* satisfying following two conditions: 1. *x* doesn't contain neither digit 0 nor digit 1. 2. = . Help friends find such number.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=15) — the number of digits in *a*. The second line contains *n* digits of *a*. There is at least one digit in *a* that is larger than 1. Number *a* may possibly contain leading zeroes.
Output a maximum possible integer satisfying the conditions above. There should be no zeroes and ones in this number decimal representation.
[ "4\n1234\n", "3\n555\n" ]
[ "33222\n", "555\n" ]
In the first case, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/f5a4207f23215fddce977ab5ea9e9d2e7578fb52.png" style="max-width: 100.0%;max-height: 100.0%;"/>
1,000
[ { "input": "4\n1234", "output": "33222" }, { "input": "3\n555", "output": "555" }, { "input": "15\n012345781234578", "output": "7777553333222222222222" }, { "input": "1\n8", "output": "7222" }, { "input": "10\n1413472614", "output": "75333332222222" }, { "input": "8\n68931246", "output": "77553333332222222" }, { "input": "7\n4424368", "output": "75333332222222222" }, { "input": "6\n576825", "output": "7755532222" }, { "input": "5\n97715", "output": "7775332" }, { "input": "3\n915", "output": "75332" }, { "input": "2\n26", "output": "532" }, { "input": "1\n4", "output": "322" }, { "input": "15\n028745260720699", "output": "7777755533333332222222222" }, { "input": "13\n5761790121605", "output": "7775555333322" }, { "input": "10\n3312667105", "output": "755533332" }, { "input": "1\n7", "output": "7" }, { "input": "15\n989898989898989", "output": "777777777777777333333333333333322222222222222222222222222222" }, { "input": "15\n000000000000007", "output": "7" }, { "input": "15\n999999999999990", "output": "77777777777777333333333333333333333333333322222222222222" }, { "input": "1\n2", "output": "2" }, { "input": "1\n3", "output": "3" }, { "input": "1\n4", "output": "322" }, { "input": "1\n5", "output": "5" }, { "input": "1\n6", "output": "53" }, { "input": "1\n7", "output": "7" }, { "input": "1\n9", "output": "7332" }, { "input": "2\n09", "output": "7332" }, { "input": "13\n1337251172966", "output": "777555333333222" }, { "input": "15\n987654329876543", "output": "777777555533333333332222222222222" }, { "input": "9\n234567899", "output": "777755333333322222222" }, { "input": "2\n99", "output": "77333322" }, { "input": "2\n66", "output": "5533" }, { "input": "3\n999", "output": "777333333222" }, { "input": "5\n99999", "output": "77777333333333322222" }, { "input": "9\n123456789", "output": "77755333332222222" }, { "input": "9\n987654321", "output": "77755333332222222" }, { "input": "3\n666", "output": "555333" }, { "input": "2\n26", "output": "532" }, { "input": "6\n555777", "output": "777555" }, { "input": "10\n1234567899", "output": "777755333333322222222" }, { "input": "4\n6666", "output": "55553333" }, { "input": "4\n9754", "output": "775333222" }, { "input": "2\n95", "output": "75332" }, { "input": "14\n11122233344455", "output": "55333333222222222" }, { "input": "12\n836544897832", "output": "77777553333333222222222222222" } ]
1,598,429,206
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
93
307,200
a = int(input()) b = str(input()) answer = list() for x in b: if x != "0" and x != "1": if x == "4": answer += ["3", "2", "2"] elif x == "6": answer += ["5", "3"] elif x == "8": answer += ["7", "2", "2", "2"] else: answer += x answer.sort() answer.reverse() final = "" for x in answer: final += x print(final)
Title: Drazil and Factorial Time Limit: None seconds Memory Limit: None megabytes Problem Description: Drazil is playing a math game with Varda. Let's define for positive integer *x* as a product of factorials of its digits. For example, . First, they choose a decimal number *a* consisting of *n* digits that contains at least one digit larger than 1. This number may possibly start with leading zeroes. Then they should find maximum positive number *x* satisfying following two conditions: 1. *x* doesn't contain neither digit 0 nor digit 1. 2. = . Help friends find such number. Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=15) — the number of digits in *a*. The second line contains *n* digits of *a*. There is at least one digit in *a* that is larger than 1. Number *a* may possibly contain leading zeroes. Output Specification: Output a maximum possible integer satisfying the conditions above. There should be no zeroes and ones in this number decimal representation. Demo Input: ['4\n1234\n', '3\n555\n'] Demo Output: ['33222\n', '555\n'] Note: In the first case, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/f5a4207f23215fddce977ab5ea9e9d2e7578fb52.png" style="max-width: 100.0%;max-height: 100.0%;"/>
```python a = int(input()) b = str(input()) answer = list() for x in b: if x != "0" and x != "1": if x == "4": answer += ["3", "2", "2"] elif x == "6": answer += ["5", "3"] elif x == "8": answer += ["7", "2", "2", "2"] else: answer += x answer.sort() answer.reverse() final = "" for x in answer: final += x print(final) ```
0
0
none
none
none
0
[ "none" ]
null
null
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are *n* watchmen on a plane, the *i*-th watchman is located at point (*x**i*,<=*y**i*). They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manhattan considers the distance between watchmen *i* and *j* to be |*x**i*<=-<=*x**j*|<=+<=|*y**i*<=-<=*y**j*|. Daniel, as an ordinary person, calculates the distance using the formula . The success of the operation relies on the number of pairs (*i*,<=*j*) (1<=≤<=*i*<=&lt;<=*j*<=≤<=*n*), such that the distance between watchman *i* and watchmen *j* calculated by Doctor Manhattan is equal to the distance between them calculated by Daniel. You were asked to compute the number of such pairs.
The first line of the input contains the single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of watchmen. Each of the following *n* lines contains two integers *x**i* and *y**i* (|*x**i*|,<=|*y**i*|<=≤<=109). Some positions may coincide.
Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel.
[ "3\n1 1\n7 5\n1 5\n", "6\n0 0\n0 1\n0 2\n-1 1\n0 1\n1 1\n" ]
[ "2\n", "11\n" ]
In the first sample, the distance between watchman 1 and watchman 2 is equal to |1 - 7| + |1 - 5| = 10 for Doctor Manhattan and <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/bcb5b7064b5f02088da0fdcf677e6fda495dd0df.png" style="max-width: 100.0%;max-height: 100.0%;"/> for Daniel. For pairs (1, 1), (1, 5) and (7, 5), (1, 5) Doctor Manhattan and Daniel will calculate the same distances.
0
[ { "input": "3\n1 1\n7 5\n1 5", "output": "2" }, { "input": "6\n0 0\n0 1\n0 2\n-1 1\n0 1\n1 1", "output": "11" }, { "input": "10\n46 -55\n46 45\n46 45\n83 -55\n46 45\n83 -55\n46 45\n83 45\n83 45\n46 -55", "output": "33" }, { "input": "1\n-5 -90", "output": "0" }, { "input": "2\n315 845\n-669 -762", "output": "0" }, { "input": "3\n8911 7861\n-6888 7861\n8911 7861", "output": "3" }, { "input": "2\n-1 1000000000\n0 -1", "output": "0" }, { "input": "2\n1000000000 0\n-7 1", "output": "0" }, { "input": "2\n1 4\n2 1", "output": "0" }, { "input": "2\n1 0\n0 2333333", "output": "0" }, { "input": "2\n2 1\n1 2", "output": "0" }, { "input": "2\n1 1000000000\n2 -1000000000", "output": "0" }, { "input": "2\n0 1000000000\n1 -7", "output": "0" }, { "input": "2\n1 0\n0 19990213", "output": "0" } ]
1,655,888,462
2,147,483,647
PyPy 3-64
OK
TESTS
71
1,107
50,073,600
from collections import defaultdict as DD import sys input = sys.stdin.readline n, = map(int, input().split()) seen_x = DD(int) seen_y = DD(int) seen = DD(int) same = 0 for _ in range(n): x,y = map(int, input().split()) same += seen_x[x] same += seen_y[y] same -= seen[x,y] seen_x[x] += 1 seen_y[y] += 1 seen[x,y] += 1 print(same)
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are *n* watchmen on a plane, the *i*-th watchman is located at point (*x**i*,<=*y**i*). They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manhattan considers the distance between watchmen *i* and *j* to be |*x**i*<=-<=*x**j*|<=+<=|*y**i*<=-<=*y**j*|. Daniel, as an ordinary person, calculates the distance using the formula . The success of the operation relies on the number of pairs (*i*,<=*j*) (1<=≤<=*i*<=&lt;<=*j*<=≤<=*n*), such that the distance between watchman *i* and watchmen *j* calculated by Doctor Manhattan is equal to the distance between them calculated by Daniel. You were asked to compute the number of such pairs. Input Specification: The first line of the input contains the single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of watchmen. Each of the following *n* lines contains two integers *x**i* and *y**i* (|*x**i*|,<=|*y**i*|<=≤<=109). Some positions may coincide. Output Specification: Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel. Demo Input: ['3\n1 1\n7 5\n1 5\n', '6\n0 0\n0 1\n0 2\n-1 1\n0 1\n1 1\n'] Demo Output: ['2\n', '11\n'] Note: In the first sample, the distance between watchman 1 and watchman 2 is equal to |1 - 7| + |1 - 5| = 10 for Doctor Manhattan and <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/bcb5b7064b5f02088da0fdcf677e6fda495dd0df.png" style="max-width: 100.0%;max-height: 100.0%;"/> for Daniel. For pairs (1, 1), (1, 5) and (7, 5), (1, 5) Doctor Manhattan and Daniel will calculate the same distances.
```python from collections import defaultdict as DD import sys input = sys.stdin.readline n, = map(int, input().split()) seen_x = DD(int) seen_y = DD(int) seen = DD(int) same = 0 for _ in range(n): x,y = map(int, input().split()) same += seen_x[x] same += seen_y[y] same -= seen[x,y] seen_x[x] += 1 seen_y[y] += 1 seen[x,y] += 1 print(same) ```
3
807
A
Is it rated?
PROGRAMMING
900
[ "implementation", "sortings" ]
null
null
Is it rated? Here it is. The Ultimate Question of Competitive Programming, Codeforces, and Everything. And you are here to answer it. Another Codeforces round has been conducted. No two participants have the same number of points. For each participant, from the top to the bottom of the standings, their rating before and after the round is known. It's known that if at least one participant's rating has changed, then the round was rated for sure. It's also known that if the round was rated and a participant with lower rating took a better place in the standings than a participant with higher rating, then at least one round participant's rating has changed. In this problem, you should not make any other assumptions about the rating system. Determine if the current round is rated, unrated, or it's impossible to determine whether it is rated of not.
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=1000) — the number of round participants. Each of the next *n* lines contains two integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=4126) — the rating of the *i*-th participant before and after the round, respectively. The participants are listed in order from the top to the bottom of the standings.
If the round is rated for sure, print "rated". If the round is unrated for sure, print "unrated". If it's impossible to determine whether the round is rated or not, print "maybe".
[ "6\n3060 3060\n2194 2194\n2876 2903\n2624 2624\n3007 2991\n2884 2884\n", "4\n1500 1500\n1300 1300\n1200 1200\n1400 1400\n", "5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699\n" ]
[ "rated\n", "unrated\n", "maybe\n" ]
In the first example, the ratings of the participants in the third and fifth places have changed, therefore, the round was rated. In the second example, no one's rating has changed, but the participant in the second place has lower rating than the participant in the fourth place. Therefore, if the round was rated, someone's rating would've changed for sure. In the third example, no one's rating has changed, and the participants took places in non-increasing order of their rating. Therefore, it's impossible to determine whether the round is rated or not.
500
[ { "input": "6\n3060 3060\n2194 2194\n2876 2903\n2624 2624\n3007 2991\n2884 2884", "output": "rated" }, { "input": "4\n1500 1500\n1300 1300\n1200 1200\n1400 1400", "output": "unrated" }, { "input": "5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699", "output": "maybe" }, { "input": "2\n1 1\n1 1", "output": "maybe" }, { "input": "2\n4126 4126\n4126 4126", "output": "maybe" }, { "input": "10\n446 446\n1331 1331\n3594 3594\n1346 1902\n91 91\n3590 3590\n2437 2437\n4007 3871\n2797 699\n1423 1423", "output": "rated" }, { "input": "10\n4078 4078\n2876 2876\n1061 1061\n3721 3721\n143 143\n2992 2992\n3279 3279\n3389 3389\n1702 1702\n1110 1110", "output": "unrated" }, { "input": "10\n4078 4078\n3721 3721\n3389 3389\n3279 3279\n2992 2992\n2876 2876\n1702 1702\n1110 1110\n1061 1061\n143 143", "output": "maybe" }, { "input": "2\n3936 3936\n2967 2967", "output": "maybe" }, { "input": "2\n1 1\n2 2", "output": "unrated" }, { "input": "2\n2 2\n1 1", "output": "maybe" }, { "input": "2\n2 1\n1 2", "output": "rated" }, { "input": "2\n2967 2967\n3936 3936", "output": "unrated" }, { "input": "3\n1200 1200\n1200 1200\n1300 1300", "output": "unrated" }, { "input": "3\n3 3\n2 2\n1 1", "output": "maybe" }, { "input": "3\n1 1\n1 1\n2 2", "output": "unrated" }, { "input": "2\n3 2\n3 2", "output": "rated" }, { "input": "3\n5 5\n4 4\n3 4", "output": "rated" }, { "input": "3\n200 200\n200 200\n300 300", "output": "unrated" }, { "input": "3\n1 1\n2 2\n3 3", "output": "unrated" }, { "input": "5\n3123 3123\n2777 2777\n2246 2246\n2245 2245\n1699 1699", "output": "maybe" }, { "input": "2\n10 10\n8 8", "output": "maybe" }, { "input": "3\n1500 1500\n1500 1500\n1600 1600", "output": "unrated" }, { "input": "3\n1500 1500\n1500 1500\n1700 1700", "output": "unrated" }, { "input": "4\n100 100\n100 100\n70 70\n80 80", "output": "unrated" }, { "input": "2\n1 2\n2 1", "output": "rated" }, { "input": "3\n5 5\n4 3\n3 3", "output": "rated" }, { "input": "3\n1600 1650\n1500 1550\n1400 1450", "output": "rated" }, { "input": "4\n2000 2000\n1500 1500\n1500 1500\n1700 1700", "output": "unrated" }, { "input": "4\n1500 1500\n1400 1400\n1400 1400\n1700 1700", "output": "unrated" }, { "input": "2\n1600 1600\n1400 1400", "output": "maybe" }, { "input": "2\n3 1\n9 8", "output": "rated" }, { "input": "2\n2 1\n1 1", "output": "rated" }, { "input": "4\n4123 4123\n4123 4123\n2670 2670\n3670 3670", "output": "unrated" }, { "input": "2\n2 2\n3 3", "output": "unrated" }, { "input": "2\n10 11\n5 4", "output": "rated" }, { "input": "2\n15 14\n13 12", "output": "rated" }, { "input": "2\n2 1\n2 2", "output": "rated" }, { "input": "3\n2670 2670\n3670 3670\n4106 4106", "output": "unrated" }, { "input": "3\n4 5\n3 3\n2 2", "output": "rated" }, { "input": "2\n10 9\n10 10", "output": "rated" }, { "input": "3\n1011 1011\n1011 999\n2200 2100", "output": "rated" }, { "input": "2\n3 3\n5 5", "output": "unrated" }, { "input": "2\n1500 1500\n3000 2000", "output": "rated" }, { "input": "2\n5 6\n5 5", "output": "rated" }, { "input": "3\n2000 2000\n1500 1501\n500 500", "output": "rated" }, { "input": "2\n2 3\n2 2", "output": "rated" }, { "input": "2\n3 3\n2 2", "output": "maybe" }, { "input": "2\n1 2\n1 1", "output": "rated" }, { "input": "4\n3123 3123\n2777 2777\n2246 2246\n1699 1699", "output": "maybe" }, { "input": "2\n15 14\n14 13", "output": "rated" }, { "input": "4\n3000 3000\n2900 2900\n3000 3000\n2900 2900", "output": "unrated" }, { "input": "6\n30 3060\n24 2194\n26 2903\n24 2624\n37 2991\n24 2884", "output": "rated" }, { "input": "2\n100 99\n100 100", "output": "rated" }, { "input": "4\n2 2\n1 1\n1 1\n2 2", "output": "unrated" }, { "input": "3\n100 101\n100 100\n100 100", "output": "rated" }, { "input": "4\n1000 1001\n900 900\n950 950\n890 890", "output": "rated" }, { "input": "2\n2 3\n1 1", "output": "rated" }, { "input": "2\n2 2\n1 1", "output": "maybe" }, { "input": "2\n3 2\n2 2", "output": "rated" }, { "input": "2\n3 2\n3 3", "output": "rated" }, { "input": "2\n1 1\n2 2", "output": "unrated" }, { "input": "3\n3 2\n3 3\n3 3", "output": "rated" }, { "input": "4\n1500 1501\n1300 1300\n1200 1200\n1400 1400", "output": "rated" }, { "input": "3\n1000 1000\n500 500\n400 300", "output": "rated" }, { "input": "5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n3000 3000", "output": "unrated" }, { "input": "2\n1 1\n2 3", "output": "rated" }, { "input": "2\n6 2\n6 2", "output": "rated" }, { "input": "5\n3123 3123\n1699 1699\n2777 2777\n2246 2246\n2246 2246", "output": "unrated" }, { "input": "2\n1500 1500\n1600 1600", "output": "unrated" }, { "input": "5\n3123 3123\n2777 2777\n2246 2246\n2241 2241\n1699 1699", "output": "maybe" }, { "input": "2\n20 30\n10 5", "output": "rated" }, { "input": "3\n1 1\n2 2\n1 1", "output": "unrated" }, { "input": "2\n1 2\n3 3", "output": "rated" }, { "input": "5\n5 5\n4 4\n3 3\n2 2\n1 1", "output": "maybe" }, { "input": "2\n2 2\n2 1", "output": "rated" }, { "input": "2\n100 100\n90 89", "output": "rated" }, { "input": "2\n1000 900\n2000 2000", "output": "rated" }, { "input": "2\n50 10\n10 50", "output": "rated" }, { "input": "2\n200 200\n100 100", "output": "maybe" }, { "input": "3\n2 2\n2 2\n3 3", "output": "unrated" }, { "input": "3\n1000 1000\n300 300\n100 100", "output": "maybe" }, { "input": "4\n2 2\n2 2\n3 3\n4 4", "output": "unrated" }, { "input": "2\n5 3\n6 3", "output": "rated" }, { "input": "2\n1200 1100\n1200 1000", "output": "rated" }, { "input": "2\n5 5\n4 4", "output": "maybe" }, { "input": "2\n5 5\n3 3", "output": "maybe" }, { "input": "5\n1500 1500\n1300 1300\n1200 1200\n1400 1400\n1100 1100", "output": "unrated" }, { "input": "5\n10 10\n9 9\n8 8\n7 7\n6 6", "output": "maybe" }, { "input": "3\n1000 1000\n300 300\n10 10", "output": "maybe" }, { "input": "5\n6 6\n5 5\n4 4\n3 3\n2 2", "output": "maybe" }, { "input": "2\n3 3\n1 1", "output": "maybe" }, { "input": "4\n2 2\n2 2\n2 2\n3 3", "output": "unrated" }, { "input": "2\n1000 1000\n700 700", "output": "maybe" }, { "input": "2\n4 3\n5 3", "output": "rated" }, { "input": "2\n1000 1000\n1100 1100", "output": "unrated" }, { "input": "4\n5 5\n4 4\n3 3\n2 2", "output": "maybe" }, { "input": "3\n1 1\n2 3\n2 2", "output": "rated" }, { "input": "2\n1 2\n1 3", "output": "rated" }, { "input": "2\n3 3\n1 2", "output": "rated" }, { "input": "4\n1501 1500\n1300 1300\n1200 1200\n1400 1400", "output": "rated" }, { "input": "5\n1 1\n2 2\n3 3\n4 4\n5 5", "output": "unrated" }, { "input": "2\n10 10\n1 2", "output": "rated" }, { "input": "6\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699\n1900 1900", "output": "unrated" }, { "input": "6\n3123 3123\n2777 2777\n3000 3000\n2246 2246\n2246 2246\n1699 1699", "output": "unrated" }, { "input": "2\n100 100\n110 110", "output": "unrated" }, { "input": "3\n3 3\n3 3\n4 4", "output": "unrated" }, { "input": "3\n3 3\n3 2\n4 4", "output": "rated" }, { "input": "3\n5 2\n4 4\n3 3", "output": "rated" }, { "input": "4\n4 4\n3 3\n2 2\n1 1", "output": "maybe" }, { "input": "2\n1 1\n3 2", "output": "rated" }, { "input": "5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n2699 2699", "output": "unrated" }, { "input": "3\n3 3\n3 3\n3 4", "output": "rated" }, { "input": "3\n1 2\n2 2\n3 3", "output": "rated" }, { "input": "3\n1 2\n1 2\n1 2", "output": "rated" }, { "input": "2\n2 1\n2 1", "output": "rated" }, { "input": "2\n1 2\n3 4", "output": "rated" }, { "input": "2\n3 2\n2 3", "output": "rated" }, { "input": "3\n1500 1500\n1600 1600\n1600 1600", "output": "unrated" }, { "input": "3\n1 1\n3 3\n4 4", "output": "unrated" }, { "input": "3\n1 1\n2 2\n2 2", "output": "unrated" }, { "input": "2\n10 12\n8 8", "output": "rated" }, { "input": "5\n1200 1200\n1500 1500\n1500 1500\n1500 1500\n1500 1500", "output": "unrated" }, { "input": "2\n1 2\n2 2", "output": "rated" }, { "input": "3\n1500 1400\n1200 1200\n1100 1100", "output": "rated" }, { "input": "2\n10 12\n10 10", "output": "rated" }, { "input": "3\n1500 1500\n1400 1400\n1300 1300", "output": "maybe" }, { "input": "3\n3 3\n4 4\n5 5", "output": "unrated" }, { "input": "3\n2 6\n3 5\n4 4", "output": "rated" }, { "input": "2\n5 6\n4 6", "output": "rated" }, { "input": "4\n10 10\n10 10\n7 7\n8 8", "output": "unrated" }, { "input": "2\n4 4\n3 3", "output": "maybe" } ]
1,587,031,775
275
PyPy 3
WRONG_ANSWER
TESTS
0
467
11,366,400
import math as mt import sys,string,bisect input=sys.stdin.readline import random from collections import deque,defaultdict L=lambda : list(map(int,input().split())) Ls=lambda : list(input().split()) M=lambda : map(int,input().split()) I=lambda :int(input()) d=defaultdict(int) t=I() l=[] for _ in range(t): a,b=M() l.append(a) if(a!=b): print("rted") exit() d=sorted(l,reverse=True) if(l==d): print("maybe") else: print("unrated")
Title: Is it rated? Time Limit: None seconds Memory Limit: None megabytes Problem Description: Is it rated? Here it is. The Ultimate Question of Competitive Programming, Codeforces, and Everything. And you are here to answer it. Another Codeforces round has been conducted. No two participants have the same number of points. For each participant, from the top to the bottom of the standings, their rating before and after the round is known. It's known that if at least one participant's rating has changed, then the round was rated for sure. It's also known that if the round was rated and a participant with lower rating took a better place in the standings than a participant with higher rating, then at least one round participant's rating has changed. In this problem, you should not make any other assumptions about the rating system. Determine if the current round is rated, unrated, or it's impossible to determine whether it is rated of not. Input Specification: The first line contains a single integer *n* (2<=≤<=*n*<=≤<=1000) — the number of round participants. Each of the next *n* lines contains two integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=4126) — the rating of the *i*-th participant before and after the round, respectively. The participants are listed in order from the top to the bottom of the standings. Output Specification: If the round is rated for sure, print "rated". If the round is unrated for sure, print "unrated". If it's impossible to determine whether the round is rated or not, print "maybe". Demo Input: ['6\n3060 3060\n2194 2194\n2876 2903\n2624 2624\n3007 2991\n2884 2884\n', '4\n1500 1500\n1300 1300\n1200 1200\n1400 1400\n', '5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699\n'] Demo Output: ['rated\n', 'unrated\n', 'maybe\n'] Note: In the first example, the ratings of the participants in the third and fifth places have changed, therefore, the round was rated. In the second example, no one's rating has changed, but the participant in the second place has lower rating than the participant in the fourth place. Therefore, if the round was rated, someone's rating would've changed for sure. In the third example, no one's rating has changed, and the participants took places in non-increasing order of their rating. Therefore, it's impossible to determine whether the round is rated or not.
```python import math as mt import sys,string,bisect input=sys.stdin.readline import random from collections import deque,defaultdict L=lambda : list(map(int,input().split())) Ls=lambda : list(input().split()) M=lambda : map(int,input().split()) I=lambda :int(input()) d=defaultdict(int) t=I() l=[] for _ in range(t): a,b=M() l.append(a) if(a!=b): print("rted") exit() d=sorted(l,reverse=True) if(l==d): print("maybe") else: print("unrated") ```
0
877
B
Nikita and string
PROGRAMMING
1,500
[ "brute force", "dp" ]
null
null
One day Nikita found the string containing letters "a" and "b" only. Nikita thinks that string is beautiful if it can be cut into 3 strings (possibly empty) without changing the order of the letters, where the 1-st and the 3-rd one contain only letters "a" and the 2-nd contains only letters "b". Nikita wants to make the string beautiful by removing some (possibly none) of its characters, but without changing their order. What is the maximum length of the string he can get?
The first line contains a non-empty string of length not greater than 5<=000 containing only lowercase English letters "a" and "b".
Print a single integer — the maximum possible size of beautiful string Nikita can get.
[ "abba\n", "bab\n" ]
[ "4", "2" ]
It the first sample the string is already beautiful. In the second sample he needs to delete one of "b" to make it beautiful.
1,000
[ { "input": "abba", "output": "4" }, { "input": "bab", "output": "2" }, { "input": "bbabbbaabbbb", "output": "9" }, { "input": "bbabbbbbaaba", "output": "10" }, { "input": "bbabbbababaa", "output": "9" }, { "input": "aabbaababbab", "output": "8" }, { "input": "a", "output": "1" }, { "input": "b", "output": "1" }, { "input": "ab", "output": "2" }, { "input": "ba", "output": "2" }, { "input": "bb", "output": "2" }, { "input": "aa", "output": "2" }, { "input": "babbbaab", "output": "6" }, { "input": "abaaaa", "output": "6" }, { "input": "aaa", "output": "3" } ]
1,634,826,812
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
2
62
28,979,200
from collections import * for u in range(1): s=input() n=len(s) m=0 for i in range(n): j=i c=0 while(j<n and s[j]=='a'): c+=1 j+=1 while(j<n and s[j]=='b'): c+=1 j+=1 while(j<n and s[j]=='a'): c+=1 j+=1 m=max(m,c) print(m)
Title: Nikita and string Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day Nikita found the string containing letters "a" and "b" only. Nikita thinks that string is beautiful if it can be cut into 3 strings (possibly empty) without changing the order of the letters, where the 1-st and the 3-rd one contain only letters "a" and the 2-nd contains only letters "b". Nikita wants to make the string beautiful by removing some (possibly none) of its characters, but without changing their order. What is the maximum length of the string he can get? Input Specification: The first line contains a non-empty string of length not greater than 5<=000 containing only lowercase English letters "a" and "b". Output Specification: Print a single integer — the maximum possible size of beautiful string Nikita can get. Demo Input: ['abba\n', 'bab\n'] Demo Output: ['4', '2'] Note: It the first sample the string is already beautiful. In the second sample he needs to delete one of "b" to make it beautiful.
```python from collections import * for u in range(1): s=input() n=len(s) m=0 for i in range(n): j=i c=0 while(j<n and s[j]=='a'): c+=1 j+=1 while(j<n and s[j]=='b'): c+=1 j+=1 while(j<n and s[j]=='a'): c+=1 j+=1 m=max(m,c) print(m) ```
0
895
B
XK Segments
PROGRAMMING
1,700
[ "binary search", "math", "sortings", "two pointers" ]
null
null
While Vasya finished eating his piece of pizza, the lesson has already started. For being late for the lesson, the teacher suggested Vasya to solve one interesting problem. Vasya has an array *a* and integer *x*. He should find the number of different ordered pairs of indexes (*i*,<=*j*) such that *a**i*<=≤<=*a**j* and there are exactly *k* integers *y* such that *a**i*<=≤<=*y*<=≤<=*a**j* and *y* is divisible by *x*. In this problem it is meant that pair (*i*,<=*j*) is equal to (*j*,<=*i*) only if *i* is equal to *j*. For example pair (1,<=2) is not the same as (2,<=1).
The first line contains 3 integers *n*,<=*x*,<=*k* (1<=≤<=*n*<=≤<=105,<=1<=≤<=*x*<=≤<=109,<=0<=≤<=*k*<=≤<=109), where *n* is the size of the array *a* and *x* and *k* are numbers from the statement. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) — the elements of the array *a*.
Print one integer — the answer to the problem.
[ "4 2 1\n1 3 5 7\n", "4 2 0\n5 3 1 7\n", "5 3 1\n3 3 3 3 3\n" ]
[ "3\n", "4\n", "25\n" ]
In first sample there are only three suitable pairs of indexes — (1, 2), (2, 3), (3, 4). In second sample there are four suitable pairs of indexes(1, 1), (2, 2), (3, 3), (4, 4). In third sample every pair (*i*, *j*) is suitable, so the answer is 5 * 5 = 25.
1,000
[ { "input": "4 2 1\n1 3 5 7", "output": "3" }, { "input": "4 2 0\n5 3 1 7", "output": "4" }, { "input": "5 3 1\n3 3 3 3 3", "output": "25" }, { "input": "5 3 4\n24 13 1 24 24", "output": "4" }, { "input": "4 2 2\n1 3 5 7", "output": "2" }, { "input": "5 1 0\n10 12 14 20 30", "output": "0" }, { "input": "7 3 1\n3 3 6 9 12 15 18", "output": "9" }, { "input": "2 5 0\n3 4", "output": "3" }, { "input": "3 5 0\n4 4 4", "output": "9" }, { "input": "3 6 0\n3 4 5", "output": "6" }, { "input": "10 2 1\n2 2 2 2 2 2 2 1 2 1", "output": "80" }, { "input": "100 2 1\n1 2 2 2 1 2 1 2 2 2 2 1 2 1 1 2 1 2 2 1 1 2 1 1 2 2 1 1 2 1 2 2 2 2 2 1 1 1 2 1 2 1 2 1 2 1 2 2 1 2 2 2 1 1 1 2 2 1 1 2 2 1 1 1 1 1 1 2 2 1 1 2 2 1 2 2 1 2 1 2 2 1 2 1 1 1 2 2 1 1 2 1 2 2 1 1 2 2 2 1", "output": "5200" }, { "input": "1 13 1\n13", "output": "1" }, { "input": "2 1 1000000000\n1 1000000000", "output": "1" }, { "input": "2 1000000000 1\n1 1000000000", "output": "2" }, { "input": "1 1 1\n1", "output": "1" }, { "input": "5 1000000000 1\n1000000000 1 1 1 1", "output": "5" }, { "input": "2 1000 1000000\n1 1000000000", "output": "1" }, { "input": "6 2 10\n1 1 1 20 20 20", "output": "9" }, { "input": "1 1000000000 1\n1000000000", "output": "1" }, { "input": "4 65536 65536\n1 2 3 4", "output": "0" }, { "input": "1 600000000 1\n500000000", "output": "0" }, { "input": "5 3 2\n2 3 4 5 8", "output": "2" } ]
1,655,029,839
2,147,483,647
Python 3
OK
TESTS
69
249
8,806,400
from bisect import bisect_left as b r=lambda:map(int,input().split()) n,x,k=r() a=sorted(r()) print(sum(b(a,l+x)-b(a,max(u,l))for u,l in((u,((u-1)//x+k)*x)for u in a)))
Title: XK Segments Time Limit: None seconds Memory Limit: None megabytes Problem Description: While Vasya finished eating his piece of pizza, the lesson has already started. For being late for the lesson, the teacher suggested Vasya to solve one interesting problem. Vasya has an array *a* and integer *x*. He should find the number of different ordered pairs of indexes (*i*,<=*j*) such that *a**i*<=≤<=*a**j* and there are exactly *k* integers *y* such that *a**i*<=≤<=*y*<=≤<=*a**j* and *y* is divisible by *x*. In this problem it is meant that pair (*i*,<=*j*) is equal to (*j*,<=*i*) only if *i* is equal to *j*. For example pair (1,<=2) is not the same as (2,<=1). Input Specification: The first line contains 3 integers *n*,<=*x*,<=*k* (1<=≤<=*n*<=≤<=105,<=1<=≤<=*x*<=≤<=109,<=0<=≤<=*k*<=≤<=109), where *n* is the size of the array *a* and *x* and *k* are numbers from the statement. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) — the elements of the array *a*. Output Specification: Print one integer — the answer to the problem. Demo Input: ['4 2 1\n1 3 5 7\n', '4 2 0\n5 3 1 7\n', '5 3 1\n3 3 3 3 3\n'] Demo Output: ['3\n', '4\n', '25\n'] Note: In first sample there are only three suitable pairs of indexes — (1, 2), (2, 3), (3, 4). In second sample there are four suitable pairs of indexes(1, 1), (2, 2), (3, 3), (4, 4). In third sample every pair (*i*, *j*) is suitable, so the answer is 5 * 5 = 25.
```python from bisect import bisect_left as b r=lambda:map(int,input().split()) n,x,k=r() a=sorted(r()) print(sum(b(a,l+x)-b(a,max(u,l))for u,l in((u,((u-1)//x+k)*x)for u in a))) ```
3
276
C
Little Girl and Maximum Sum
PROGRAMMING
1,500
[ "data structures", "greedy", "implementation", "sortings" ]
null
null
The little girl loves the problems on array queries very much. One day she came across a rather well-known problem: you've got an array of $n$ elements (the elements of the array are indexed starting from 1); also, there are $q$ queries, each one is defined by a pair of integers $l_i$, $r_i$ $(1 \le l_i \le r_i \le n)$. You need to find for each query the sum of elements of the array with indexes from $l_i$ to $r_i$, inclusive. The little girl found the problem rather boring. She decided to reorder the array elements before replying to the queries in a way that makes the sum of query replies maximum possible. Your task is to find the value of this maximum sum.
The first line contains two space-separated integers $n$ ($1 \le n \le 2\cdot10^5$) and $q$ ($1 \le q \le 2\cdot10^5$) — the number of elements in the array and the number of queries, correspondingly. The next line contains $n$ space-separated integers $a_i$ ($1 \le a_i \le 2\cdot10^5$) — the array elements. Each of the following $q$ lines contains two space-separated integers $l_i$ and $r_i$ ($1 \le l_i \le r_i \le n$) — the $i$-th query.
In a single line print, a single integer — the maximum sum of query replies after the array elements are reordered. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
[ "3 3\n5 3 2\n1 2\n2 3\n1 3\n", "5 3\n5 2 4 1 3\n1 5\n2 3\n2 3\n" ]
[ "25\n", "33\n" ]
none
1,500
[ { "input": "3 3\n5 3 2\n1 2\n2 3\n1 3", "output": "25" }, { "input": "5 3\n5 2 4 1 3\n1 5\n2 3\n2 3", "output": "33" }, { "input": "34 21\n23 38 16 49 44 50 48 34 33 19 18 31 11 15 20 47 44 30 39 33 45 46 1 13 27 16 31 36 17 23 38 5 30 16\n8 16\n14 27\n8 26\n1 8\n5 6\n23 28\n4 33\n13 30\n12 30\n11 30\n9 21\n1 14\n15 22\n4 11\n5 24\n8 20\n17 33\n6 9\n3 14\n25 34\n10 17", "output": "9382" }, { "input": "16 13\n40 32 15 16 35 36 45 23 30 42 25 8 29 21 39 23\n2 9\n3 11\n8 9\n4 14\n1 6\n5 10\n5 14\n5 11\n13 13\n2 8\n9 16\n6 10\n7 8", "output": "2838" }, { "input": "31 48\n45 19 16 42 38 18 50 7 28 40 39 25 45 14 36 18 27 30 16 4 22 6 1 23 16 47 14 35 27 47 2\n6 16\n11 28\n4 30\n25 26\n11 30\n5 9\n4 17\n15 17\n10 25\n15 26\n1 3\n9 26\n8 29\n16 30\n5 24\n27 30\n9 10\n22 29\n2 6\n15 24\n6 21\n19 21\n4 28\n1 7\n18 21\n10 22\n6 15\n14 28\n4 29\n12 13\n19 29\n5 6\n13 31\n21 27\n9 25\n6 18\n6 8\n28 30\n2 4\n15 21\n1 1\n8 30\n3 31\n11 27\n28 29\n6 22\n20 22\n9 25", "output": "17471" }, { "input": "22 7\n44 41 40 41 37 42 46 16 50 47 30 7 32 6 20 14 47 25 11 1 35 12\n1 10\n10 20\n4 5\n1 8\n2 12\n8 8\n2 16", "output": "2202" }, { "input": "3 2\n1 2 3\n2 3\n1 2", "output": "9" } ]
1,656,590,862
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
6
1,000
16,281,600
n,q=map(int,input().split()) a=sorted(map(int,input().split())) b=[0]*n for _ in[0]*q: l,r=map(int,input().split()) b[l-1]+=1 if r<n:b[r]-=1 c=[b[0]] for i in range(1,n):c+=c[-1]+b[i], c.sort() print(sum(a[i]*c[i] for i in range(n)))
Title: Little Girl and Maximum Sum Time Limit: None seconds Memory Limit: None megabytes Problem Description: The little girl loves the problems on array queries very much. One day she came across a rather well-known problem: you've got an array of $n$ elements (the elements of the array are indexed starting from 1); also, there are $q$ queries, each one is defined by a pair of integers $l_i$, $r_i$ $(1 \le l_i \le r_i \le n)$. You need to find for each query the sum of elements of the array with indexes from $l_i$ to $r_i$, inclusive. The little girl found the problem rather boring. She decided to reorder the array elements before replying to the queries in a way that makes the sum of query replies maximum possible. Your task is to find the value of this maximum sum. Input Specification: The first line contains two space-separated integers $n$ ($1 \le n \le 2\cdot10^5$) and $q$ ($1 \le q \le 2\cdot10^5$) — the number of elements in the array and the number of queries, correspondingly. The next line contains $n$ space-separated integers $a_i$ ($1 \le a_i \le 2\cdot10^5$) — the array elements. Each of the following $q$ lines contains two space-separated integers $l_i$ and $r_i$ ($1 \le l_i \le r_i \le n$) — the $i$-th query. Output Specification: In a single line print, a single integer — the maximum sum of query replies after the array elements are reordered. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier. Demo Input: ['3 3\n5 3 2\n1 2\n2 3\n1 3\n', '5 3\n5 2 4 1 3\n1 5\n2 3\n2 3\n'] Demo Output: ['25\n', '33\n'] Note: none
```python n,q=map(int,input().split()) a=sorted(map(int,input().split())) b=[0]*n for _ in[0]*q: l,r=map(int,input().split()) b[l-1]+=1 if r<n:b[r]-=1 c=[b[0]] for i in range(1,n):c+=c[-1]+b[i], c.sort() print(sum(a[i]*c[i] for i in range(n))) ```
0
55
B
Smallest number
PROGRAMMING
1,600
[ "brute force" ]
B. Smallest number
2
256
Recently, Vladimir got bad mark in algebra again. To avoid such unpleasant events in future he decided to train his arithmetic skills. He wrote four integer numbers *a*, *b*, *c*, *d* on the blackboard. During each of the next three minutes he took two numbers from the blackboard (not necessarily adjacent) and replaced them with their sum or their product. In the end he got one number. Unfortunately, due to the awful memory he forgot that number, but he remembers four original numbers, sequence of the operations and his surprise because of the very small result. Help Vladimir remember the forgotten number: find the smallest number that can be obtained from the original numbers by the given sequence of operations.
First line contains four integers separated by space: 0<=≤<=*a*,<=*b*,<=*c*,<=*d*<=≤<=1000 — the original numbers. Second line contains three signs ('+' or '*' each) separated by space — the sequence of the operations in the order of performing. ('+' stands for addition, '*' — multiplication)
Output one integer number — the minimal result which can be obtained. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cin (also you may use %I64d).
[ "1 1 1 1\n+ + *\n", "2 2 2 2\n* * +\n", "1 2 3 4\n* + +\n" ]
[ "3\n", "8\n", "9\n" ]
none
1,000
[ { "input": "1 1 1 1\n+ + *", "output": "3" }, { "input": "2 2 2 2\n* * +", "output": "8" }, { "input": "1 2 3 4\n* + +", "output": "9" }, { "input": "15 1 3 1\n* * +", "output": "18" }, { "input": "8 1 7 14\n+ + +", "output": "30" }, { "input": "7 17 3 25\n+ * +", "output": "63" }, { "input": "13 87 4 17\n* * *", "output": "76908" }, { "input": "7 0 8 15\n+ + *", "output": "0" }, { "input": "52 0 43 239\n+ + +", "output": "334" }, { "input": "1000 1000 999 1000\n* * *", "output": "999000000000" }, { "input": "720 903 589 804\n* * *", "output": "307887168960" }, { "input": "631 149 496 892\n* * +", "output": "445884" }, { "input": "220 127 597 394\n* + +", "output": "28931" }, { "input": "214 862 466 795\n+ + +", "output": "2337" }, { "input": "346 290 587 525\n* * *", "output": "30922279500" }, { "input": "323 771 559 347\n+ * *", "output": "149067730" }, { "input": "633 941 836 254\n* + +", "output": "162559" }, { "input": "735 111 769 553\n+ * *", "output": "92320032" }, { "input": "622 919 896 120\n* * +", "output": "667592" }, { "input": "652 651 142 661\n+ + +", "output": "2106" }, { "input": "450 457 975 35\n* * *", "output": "7017806250" }, { "input": "883 954 804 352\n* * +", "output": "1045740" }, { "input": "847 206 949 358\n* + *", "output": "62660050" }, { "input": "663 163 339 76\n+ + +", "output": "1241" }, { "input": "990 330 253 553\n+ * +", "output": "85033" }, { "input": "179 346 525 784\n* * *", "output": "25492034400" }, { "input": "780 418 829 778\n+ + *", "output": "997766" }, { "input": "573 598 791 124\n* * *", "output": "33608874936" }, { "input": "112 823 202 223\n* * +", "output": "137222" }, { "input": "901 166 994 315\n* + *", "output": "47278294" }, { "input": "393 342 840 486\n+ * *", "output": "178222356" }, { "input": "609 275 153 598\n+ + *", "output": "226746" }, { "input": "56 828 386 57\n+ * *", "output": "3875088" }, { "input": "944 398 288 986\n+ + *", "output": "670464" }, { "input": "544 177 162 21\n+ + *", "output": "18543" }, { "input": "105 238 316 265\n+ + +", "output": "924" }, { "input": "31 353 300 911\n* * *", "output": "2990721900" }, { "input": "46 378 310 194\n* * +", "output": "77528" }, { "input": "702 534 357 657\n+ * *", "output": "259077042" }, { "input": "492 596 219 470\n+ + *", "output": "341202" }, { "input": "482 842 982 902\n+ * +", "output": "407728" }, { "input": "827 578 394 351\n* * *", "output": "66105361764" }, { "input": "901 884 426 451\n* + *", "output": "170223210" }, { "input": "210 295 12 795\n* * +", "output": "71490" }, { "input": "40 734 948 202\n+ * *", "output": "13590560" }, { "input": "136 611 963 195\n+ + *", "output": "240584" }, { "input": "695 74 871 760\n+ * +", "output": "53061" }, { "input": "666 884 772 54\n* + +", "output": "37620" }, { "input": "975 785 753 224\n+ * +", "output": "170432" }, { "input": "35 187 126 596\n+ + +", "output": "944" }, { "input": "243 386 431 35\n* + *", "output": "3298015" }, { "input": "229 602 133 635\n* * +", "output": "222313" }, { "input": "916 207 238 891\n+ + *", "output": "423315" }, { "input": "922 145 883 357\n+ + *", "output": "313490" }, { "input": "69 355 762 111\n* + +", "output": "8776" }, { "input": "209 206 34 67\n* + *", "output": "476374" }, { "input": "693 824 375 361\n* * +", "output": "557339" }, { "input": "45 712 635 467\n* + +", "output": "22362" }, { "input": "426 283 179 211\n+ + +", "output": "1099" }, { "input": "802 387 686 12\n+ + +", "output": "1887" } ]
1,677,592,330
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
1
62
0
import itertools nums = list(map(int,input().split())) ops = list(map(str,input().split())) ans = float("inf") perm = list(itertools.permutations(nums)) for box in perm: res = box[0] i = 0 while(i<3): if ops[i]=="*": res*=box[i+1] else: res+=box[i+1] i+=1 ans = min(ans,res) print(ans)
Title: Smallest number Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Recently, Vladimir got bad mark in algebra again. To avoid such unpleasant events in future he decided to train his arithmetic skills. He wrote four integer numbers *a*, *b*, *c*, *d* on the blackboard. During each of the next three minutes he took two numbers from the blackboard (not necessarily adjacent) and replaced them with their sum or their product. In the end he got one number. Unfortunately, due to the awful memory he forgot that number, but he remembers four original numbers, sequence of the operations and his surprise because of the very small result. Help Vladimir remember the forgotten number: find the smallest number that can be obtained from the original numbers by the given sequence of operations. Input Specification: First line contains four integers separated by space: 0<=≤<=*a*,<=*b*,<=*c*,<=*d*<=≤<=1000 — the original numbers. Second line contains three signs ('+' or '*' each) separated by space — the sequence of the operations in the order of performing. ('+' stands for addition, '*' — multiplication) Output Specification: Output one integer number — the minimal result which can be obtained. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cin (also you may use %I64d). Demo Input: ['1 1 1 1\n+ + *\n', '2 2 2 2\n* * +\n', '1 2 3 4\n* + +\n'] Demo Output: ['3\n', '8\n', '9\n'] Note: none
```python import itertools nums = list(map(int,input().split())) ops = list(map(str,input().split())) ans = float("inf") perm = list(itertools.permutations(nums)) for box in perm: res = box[0] i = 0 while(i<3): if ops[i]=="*": res*=box[i+1] else: res+=box[i+1] i+=1 ans = min(ans,res) print(ans) ```
0
868
A
Bark to Unlock
PROGRAMMING
900
[ "brute force", "implementation", "strings" ]
null
null
As technologies develop, manufacturers are making the process of unlocking a phone as user-friendly as possible. To unlock its new phone, Arkady's pet dog Mu-mu has to bark the password once. The phone represents a password as a string of two lowercase English letters. Mu-mu's enemy Kashtanka wants to unlock Mu-mu's phone to steal some sensible information, but it can only bark *n* distinct words, each of which can be represented as a string of two lowercase English letters. Kashtanka wants to bark several words (not necessarily distinct) one after another to pronounce a string containing the password as a substring. Tell if it's possible to unlock the phone in this way, or not.
The first line contains two lowercase English letters — the password on the phone. The second line contains single integer *n* (1<=≤<=*n*<=≤<=100) — the number of words Kashtanka knows. The next *n* lines contain two lowercase English letters each, representing the words Kashtanka knows. The words are guaranteed to be distinct.
Print "YES" if Kashtanka can bark several words in a line forming a string containing the password, and "NO" otherwise. You can print each letter in arbitrary case (upper or lower).
[ "ya\n4\nah\noy\nto\nha\n", "hp\n2\nht\ntp\n", "ah\n1\nha\n" ]
[ "YES\n", "NO\n", "YES\n" ]
In the first example the password is "ya", and Kashtanka can bark "oy" and then "ah", and then "ha" to form the string "oyahha" which contains the password. So, the answer is "YES". In the second example Kashtanka can't produce a string containing password as a substring. Note that it can bark "ht" and then "tp" producing "http", but it doesn't contain the password "hp" as a substring. In the third example the string "hahahaha" contains "ah" as a substring.
250
[ { "input": "ya\n4\nah\noy\nto\nha", "output": "YES" }, { "input": "hp\n2\nht\ntp", "output": "NO" }, { "input": "ah\n1\nha", "output": "YES" }, { "input": "bb\n4\nba\nab\naa\nbb", "output": "YES" }, { "input": "bc\n4\nca\nba\nbb\ncc", "output": "YES" }, { "input": "ba\n4\ncd\nad\ncc\ncb", "output": "YES" }, { "input": "pg\n4\nzl\nxs\ndi\nxn", "output": "NO" }, { "input": "bn\n100\ndf\nyb\nze\nml\nyr\nof\nnw\nfm\ndw\nlv\nzr\nhu\nzt\nlw\nld\nmo\nxz\ntp\nmr\nou\nme\npx\nvp\nes\nxi\nnr\nbx\nqc\ngm\njs\nkn\ntw\nrq\nkz\nuc\nvc\nqr\nab\nna\nro\nya\nqy\ngu\nvk\nqk\ngs\nyq\nop\nhw\nrj\neo\nlz\nbh\nkr\nkb\nma\nrd\nza\nuf\nhq\nmc\nmn\nti\nwn\nsh\nax\nsi\nnd\ntz\ndu\nfj\nkl\nws\now\nnf\nvr\nye\nzc\niw\nfv\nkv\noo\nsm\nbc\nrs\nau\nuz\nuv\ngh\nsu\njn\ndz\nrl\nwj\nbk\nzl\nas\nms\nit\nwu", "output": "YES" }, { "input": "bb\n1\naa", "output": "NO" }, { "input": "qm\n25\nqw\nwe\ner\nrt\nty\nyu\nui\nio\nop\npa\nas\nsd\ndf\nfg\ngh\nhj\njk\nkl\nlz\nzx\nxc\ncv\nvb\nbn\nnm", "output": "NO" }, { "input": "mq\n25\nqw\nwe\ner\nrt\nty\nyu\nui\nio\nop\npa\nas\nsd\ndf\nfg\ngh\nhj\njk\nkl\nlz\nzx\nxc\ncv\nvb\nbn\nnm", "output": "YES" }, { "input": "aa\n1\naa", "output": "YES" }, { "input": "bb\n1\nbb", "output": "YES" }, { "input": "ba\n1\ncc", "output": "NO" }, { "input": "ha\n1\nha", "output": "YES" }, { "input": "aa\n1\naa", "output": "YES" }, { "input": "ez\n1\njl", "output": "NO" }, { "input": "aa\n2\nab\nba", "output": "YES" }, { "input": "aa\n2\nca\ncc", "output": "NO" }, { "input": "dd\n2\nac\ndc", "output": "NO" }, { "input": "qc\n2\nyc\nkr", "output": "NO" }, { "input": "aa\n3\nba\nbb\nab", "output": "YES" }, { "input": "ca\n3\naa\nbb\nab", "output": "NO" }, { "input": "ca\n3\nbc\nbd\nca", "output": "YES" }, { "input": "dd\n3\nmt\nrg\nxl", "output": "NO" }, { "input": "be\n20\nad\ncd\ncb\ndb\ndd\naa\nab\nca\nae\ned\ndc\nbb\nba\nda\nee\nea\ncc\nac\nec\neb", "output": "YES" }, { "input": "fc\n20\nca\nbb\nce\nfd\nde\nfa\ncc\nec\nfb\nfc\nff\nbe\ncf\nba\ndb\ned\naf\nae\nda\nef", "output": "YES" }, { "input": "ca\n20\ndc\naf\ndf\neg\naa\nbc\nea\nbd\nab\ndb\ngc\nfb\nba\nbe\nee\ngf\ncf\nag\nga\nca", "output": "YES" }, { "input": "ke\n20\nzk\nra\nbq\nqz\nwt\nzg\nmz\nuk\nge\nuv\nud\nfd\neh\ndm\nsk\nki\nfv\ntp\nat\nfb", "output": "YES" }, { "input": "hh\n50\nag\nhg\ndg\nfh\neg\ngh\ngd\nda\nbh\nab\nhf\ndc\nhb\nfe\nad\nec\nac\nfd\nca\naf\ncg\nhd\neb\nce\nhe\nha\ngb\nea\nae\nfb\nff\nbe\nch\nhh\nee\nde\nge\ngf\naa\ngg\neh\ned\nbf\nfc\nah\nga\nbd\ncb\nbg\nbc", "output": "YES" }, { "input": "id\n50\nhi\ndc\nfg\nee\ngi\nhc\nac\nih\ndg\nfc\nde\ned\nie\neb\nic\ncf\nib\nfa\ngc\nba\nbe\nga\nha\nhg\nia\ndf\nab\nei\neh\nad\nii\nci\ndh\nec\nif\ndi\nbg\nag\nhe\neg\nca\nae\ndb\naa\nid\nfh\nhh\ncc\nfb\ngb", "output": "YES" }, { "input": "fe\n50\nje\nbi\nbg\ngc\nfb\nig\ndf\nji\ndg\nfe\nfc\ncf\ngf\nai\nhe\nac\nch\nja\ngh\njf\nge\ncb\nij\ngb\ncg\naf\neh\nee\nhd\njd\njb\nii\nca\nci\nga\nab\nhi\nag\nfj\nej\nfi\nie\ndj\nfg\nef\njc\njg\njh\nhf\nha", "output": "YES" }, { "input": "rn\n50\nba\nec\nwg\nao\nlk\nmz\njj\ncf\nfa\njk\ndy\nsz\njs\nzr\nqv\ntx\nwv\nrd\nqw\nls\nrr\nvt\nrx\nkc\neh\nnj\niq\nyi\nkh\nue\nnv\nkz\nrn\nes\nua\nzf\nvu\nll\neg\nmj\ncz\nzj\nxz\net\neb\nci\nih\nig\nam\nvd", "output": "YES" }, { "input": "ee\n100\nah\nfb\ncd\nbi\nii\nai\nid\nag\nie\nha\ndi\nec\nae\nce\njb\ndg\njg\ngd\ngf\nda\nih\nbd\nhj\ngg\nhb\ndf\ned\nfh\naf\nja\nci\nfc\nic\nji\nac\nhi\nfj\nch\nbc\njd\naa\nff\nad\ngj\nej\nde\nee\nhe\ncf\nga\nia\ncg\nbb\nhc\nbe\ngi\njf\nbg\naj\njj\nbh\nfe\ndj\nef\ngb\nge\ndb\nig\ncj\ndc\nij\njh\nei\ndd\nib\nhf\neg\nbf\nfg\nab\ngc\nfd\nhd\ngh\neh\njc\neb\nhh\nca\nje\nbj\nif\nea\nhg\nfa\ncc\nba\ndh\ncb\nfi", "output": "YES" }, { "input": "if\n100\njd\nbc\nje\nhi\nga\nde\nkb\nfc\ncd\ngd\naj\ncb\nei\nbf\ncf\ndk\ndb\ncg\nki\ngg\nkg\nfa\nkj\nii\njf\njg\ngb\nbh\nbg\neh\nhj\nhb\ndg\ndj\njc\njb\nce\ndi\nig\nci\ndf\nji\nhc\nfk\naf\nac\ngk\nhd\nae\nkd\nec\nkc\neb\nfh\nij\nie\nca\nhh\nkf\nha\ndd\nif\nef\nih\nhg\nej\nfe\njk\nea\nib\nck\nhf\nak\ngi\nch\ndc\nba\nke\nad\nka\neg\njh\nja\ngc\nfd\ncc\nab\ngj\nik\nfg\nbj\nhe\nfj\nge\ngh\nhk\nbk\ned\nid\nfi", "output": "YES" }, { "input": "kd\n100\nek\nea\nha\nkf\nkj\ngh\ndl\nfj\nal\nga\nlj\nik\ngd\nid\ncb\nfh\ndk\nif\nbh\nkb\nhc\nej\nhk\ngc\ngb\nef\nkk\nll\nlf\nkh\ncl\nlh\njj\nil\nhh\nci\ndb\ndf\ngk\njg\nch\nbd\ncg\nfg\nda\neb\nlg\ndg\nbk\nje\nbg\nbl\njl\ncj\nhb\nei\naa\ngl\nka\nfa\nfi\naf\nkc\nla\ngi\nij\nib\nle\ndi\nck\nag\nlc\nca\nge\nie\nlb\nke\nii\nae\nig\nic\nhe\ncf\nhd\nak\nfb\nhi\ngf\nad\nba\nhg\nbi\nkl\nac\ngg\ngj\nbe\nlk\nld\naj", "output": "YES" }, { "input": "ab\n1\nab", "output": "YES" }, { "input": "ya\n1\nya", "output": "YES" }, { "input": "ay\n1\nyb", "output": "NO" }, { "input": "ax\n2\nii\nxa", "output": "YES" }, { "input": "hi\n1\nhi", "output": "YES" }, { "input": "ag\n1\nag", "output": "YES" }, { "input": "th\n1\nth", "output": "YES" }, { "input": "sb\n1\nsb", "output": "YES" }, { "input": "hp\n1\nhp", "output": "YES" }, { "input": "ah\n1\nah", "output": "YES" }, { "input": "ta\n1\nta", "output": "YES" }, { "input": "tb\n1\ntb", "output": "YES" }, { "input": "ab\n5\nca\nda\nea\nfa\nka", "output": "NO" }, { "input": "ac\n1\nac", "output": "YES" }, { "input": "ha\n2\nha\nzz", "output": "YES" }, { "input": "ok\n1\nok", "output": "YES" }, { "input": "bc\n1\nbc", "output": "YES" }, { "input": "az\n1\nzz", "output": "NO" }, { "input": "ab\n2\nba\ntt", "output": "YES" }, { "input": "ah\n2\nap\nhp", "output": "NO" }, { "input": "sh\n1\nsh", "output": "YES" }, { "input": "az\n1\nby", "output": "NO" }, { "input": "as\n1\nas", "output": "YES" }, { "input": "ab\n2\nab\ncd", "output": "YES" }, { "input": "ab\n2\nxa\nza", "output": "NO" }, { "input": "ab\n2\net\nab", "output": "YES" }, { "input": "ab\n1\naa", "output": "NO" }, { "input": "ab\n2\nab\nde", "output": "YES" }, { "input": "ah\n2\nba\nha", "output": "YES" }, { "input": "ha\n3\ndd\ncc\nha", "output": "YES" }, { "input": "oo\n1\nox", "output": "NO" }, { "input": "ab\n2\nax\nbx", "output": "NO" }, { "input": "ww\n4\nuw\now\npo\nko", "output": "NO" }, { "input": "ay\n1\nay", "output": "YES" }, { "input": "yo\n1\nyo", "output": "YES" }, { "input": "ba\n1\nba", "output": "YES" }, { "input": "qw\n1\nqw", "output": "YES" }, { "input": "la\n1\nla", "output": "YES" }, { "input": "ab\n2\nbb\nbc", "output": "NO" }, { "input": "aa\n2\nab\nac", "output": "NO" }, { "input": "ah\n2\nbb\nha", "output": "YES" }, { "input": "ya\n42\nab\nac\nad\nae\naf\nag\nah\nai\nak\naj\nba\nbc\nbd\nbe\nbf\nbg\nbh\nbi\nbk\nbj\ncb\nca\ncd\nce\ncf\ncg\nch\nci\nck\ncj\ndb\ndc\nda\nde\ndf\ndg\ndh\ndi\ndk\ndj\nef\nek", "output": "NO" }, { "input": "ab\n3\nab\nxx\nyy", "output": "YES" }, { "input": "ab\n2\nab\ncc", "output": "YES" }, { "input": "sa\n2\nxx\nas", "output": "YES" }, { "input": "ma\n1\nma", "output": "YES" }, { "input": "ba\n1\nbb", "output": "NO" }, { "input": "bc\n1\nab", "output": "NO" }, { "input": "fa\n1\nfa", "output": "YES" }, { "input": "ap\n1\nap", "output": "YES" }, { "input": "ab\n1\nbb", "output": "NO" }, { "input": "bk\n1\nbk", "output": "YES" }, { "input": "xy\n2\nxy\naa", "output": "YES" }, { "input": "ab\n2\nza\nbz", "output": "YES" } ]
1,608,331,819
2,147,483,647
Python 3
OK
TESTS
90
109
307,200
password = input('') vocablen = input() vocablen = int(vocablen) vocab = [] for i in range(vocablen): word = input('') vocab.append(word) final = "" for i in range(len(vocab)): main = vocab[i] for j in range(len(vocab)): breakin = str(main) + str(vocab[j]) if password in breakin: final = "YES" if final == "": final = "NO" print(final)
Title: Bark to Unlock Time Limit: None seconds Memory Limit: None megabytes Problem Description: As technologies develop, manufacturers are making the process of unlocking a phone as user-friendly as possible. To unlock its new phone, Arkady's pet dog Mu-mu has to bark the password once. The phone represents a password as a string of two lowercase English letters. Mu-mu's enemy Kashtanka wants to unlock Mu-mu's phone to steal some sensible information, but it can only bark *n* distinct words, each of which can be represented as a string of two lowercase English letters. Kashtanka wants to bark several words (not necessarily distinct) one after another to pronounce a string containing the password as a substring. Tell if it's possible to unlock the phone in this way, or not. Input Specification: The first line contains two lowercase English letters — the password on the phone. The second line contains single integer *n* (1<=≤<=*n*<=≤<=100) — the number of words Kashtanka knows. The next *n* lines contain two lowercase English letters each, representing the words Kashtanka knows. The words are guaranteed to be distinct. Output Specification: Print "YES" if Kashtanka can bark several words in a line forming a string containing the password, and "NO" otherwise. You can print each letter in arbitrary case (upper or lower). Demo Input: ['ya\n4\nah\noy\nto\nha\n', 'hp\n2\nht\ntp\n', 'ah\n1\nha\n'] Demo Output: ['YES\n', 'NO\n', 'YES\n'] Note: In the first example the password is "ya", and Kashtanka can bark "oy" and then "ah", and then "ha" to form the string "oyahha" which contains the password. So, the answer is "YES". In the second example Kashtanka can't produce a string containing password as a substring. Note that it can bark "ht" and then "tp" producing "http", but it doesn't contain the password "hp" as a substring. In the third example the string "hahahaha" contains "ah" as a substring.
```python password = input('') vocablen = input() vocablen = int(vocablen) vocab = [] for i in range(vocablen): word = input('') vocab.append(word) final = "" for i in range(len(vocab)): main = vocab[i] for j in range(len(vocab)): breakin = str(main) + str(vocab[j]) if password in breakin: final = "YES" if final == "": final = "NO" print(final) ```
3
34
A
Reconnaissance 2
PROGRAMMING
800
[ "implementation" ]
A. Reconnaissance 2
2
256
*n* soldiers stand in a circle. For each soldier his height *a**i* is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. |*a**i*<=-<=*a**j*| is minimal. So each of them will be less noticeable with the other. Output any pair of soldiers that can form a reconnaissance unit.
The first line contains integer *n* (2<=≤<=*n*<=≤<=100) — amount of soldiers. Then follow the heights of the soldiers in their order in the circle — *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000). The soldier heights are given in clockwise or counterclockwise direction.
Output two integers — indexes of neighbouring soldiers, who should form a reconnaissance unit. If there are many optimum solutions, output any of them. Remember, that the soldiers stand in a circle.
[ "5\n10 12 13 15 10\n", "4\n10 20 30 40\n" ]
[ "5 1\n", "1 2\n" ]
none
500
[ { "input": "5\n10 12 13 15 10", "output": "5 1" }, { "input": "4\n10 20 30 40", "output": "1 2" }, { "input": "6\n744 359 230 586 944 442", "output": "2 3" }, { "input": "5\n826 747 849 687 437", "output": "1 2" }, { "input": "5\n999 999 993 969 999", "output": "1 2" }, { "input": "5\n4 24 6 1 15", "output": "3 4" }, { "input": "2\n511 32", "output": "1 2" }, { "input": "3\n907 452 355", "output": "2 3" }, { "input": "4\n303 872 764 401", "output": "4 1" }, { "input": "10\n684 698 429 694 956 812 594 170 937 764", "output": "1 2" }, { "input": "20\n646 840 437 946 640 564 936 917 487 752 844 734 468 969 674 646 728 642 514 695", "output": "7 8" }, { "input": "30\n996 999 998 984 989 1000 996 993 1000 983 992 999 999 1000 979 992 987 1000 996 1000 1000 989 981 996 995 999 999 989 999 1000", "output": "12 13" }, { "input": "50\n93 27 28 4 5 78 59 24 19 134 31 128 118 36 90 32 32 1 44 32 33 13 31 10 12 25 38 50 25 12 4 22 28 53 48 83 4 25 57 31 71 24 8 7 28 86 23 80 101 58", "output": "16 17" }, { "input": "88\n1000 1000 1000 1000 1000 998 998 1000 1000 1000 1000 999 999 1000 1000 1000 999 1000 997 999 997 1000 999 998 1000 999 1000 1000 1000 999 1000 999 999 1000 1000 999 1000 999 1000 1000 998 1000 1000 1000 998 998 1000 1000 999 1000 1000 1000 1000 1000 1000 1000 998 1000 1000 1000 999 1000 1000 999 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 998 1000 1000 1000 998 1000 1000 998 1000 999 1000 1000 1000 1000", "output": "1 2" }, { "input": "99\n4 4 21 6 5 3 13 2 6 1 3 4 1 3 1 9 11 1 6 17 4 5 20 4 1 9 5 11 3 4 14 1 3 3 1 4 3 5 27 1 1 2 10 7 11 4 19 7 11 6 11 13 3 1 10 7 2 1 16 1 9 4 29 13 2 12 14 2 21 1 9 8 26 12 12 5 2 14 7 8 8 8 9 4 12 2 6 6 7 16 8 14 2 10 20 15 3 7 4", "output": "1 2" }, { "input": "100\n713 572 318 890 577 657 646 146 373 783 392 229 455 871 20 593 573 336 26 381 280 916 907 732 820 713 111 840 570 446 184 711 481 399 788 647 492 15 40 530 549 506 719 782 126 20 778 996 712 761 9 74 812 418 488 175 103 585 900 3 604 521 109 513 145 708 990 361 682 827 791 22 596 780 596 385 450 643 158 496 876 975 319 783 654 895 891 361 397 81 682 899 347 623 809 557 435 279 513 438", "output": "86 87" }, { "input": "100\n31 75 86 68 111 27 22 22 26 30 54 163 107 75 160 122 14 23 17 26 27 20 43 58 59 71 21 148 9 32 43 91 133 286 132 70 90 156 84 14 77 93 23 18 13 72 18 131 33 28 72 175 30 86 249 20 14 208 28 57 63 199 6 10 24 30 62 267 43 479 60 28 138 1 45 3 19 47 7 166 116 117 50 140 28 14 95 85 93 43 61 15 2 70 10 51 7 95 9 25", "output": "7 8" }, { "input": "100\n896 898 967 979 973 709 961 968 806 967 896 967 826 975 936 903 986 856 851 931 852 971 786 837 949 978 686 936 952 909 965 749 908 916 943 973 983 975 939 886 964 928 960 976 907 788 994 773 949 871 947 980 945 985 726 981 887 943 907 990 931 874 840 867 948 951 961 904 888 901 976 967 994 921 828 970 972 722 755 970 860 855 914 869 714 899 969 978 898 862 642 939 904 936 819 934 884 983 955 964", "output": "1 2" }, { "input": "100\n994 927 872 970 815 986 952 996 965 1000 877 986 978 999 950 990 936 997 993 960 921 860 895 869 943 998 983 968 973 953 999 990 995 871 853 979 973 963 953 938 997 989 993 964 960 973 946 975 1000 962 920 746 989 957 904 965 920 979 966 961 1000 993 975 952 846 971 991 979 985 969 984 973 956 1000 952 778 983 974 956 927 995 997 980 997 1000 970 960 970 988 983 947 904 935 972 1000 863 992 996 932 967", "output": "81 82" }, { "input": "100\n48 108 63 21 27 8 49 21 75 8 24 42 149 18 8 28 21 18 25 35 59 70 59 33 40 1 67 34 120 82 4 115 72 87 3 15 15 63 37 12 40 27 83 14 38 20 14 58 93 10 31 3 39 6 197 77 54 16 31 146 9 49 14 8 77 82 5 11 80 116 8 61 50 24 7 103 29 11 3 3 1 12 46 24 21 131 39 29 36 2 107 40 16 99 31 41 29 48 17 17", "output": "36 37" } ]
1,600,476,950
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
154
0
cnt = int(input()) soldier_list = list(map(int, input().split())) indices = [] nums = sorted([(num, index) for index, num in enumerate(soldier_list)]) x, y = nums[0] a, b = nums[1] print(nums) print(y + 1, b + 1)
Title: Reconnaissance 2 Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: *n* soldiers stand in a circle. For each soldier his height *a**i* is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. |*a**i*<=-<=*a**j*| is minimal. So each of them will be less noticeable with the other. Output any pair of soldiers that can form a reconnaissance unit. Input Specification: The first line contains integer *n* (2<=≤<=*n*<=≤<=100) — amount of soldiers. Then follow the heights of the soldiers in their order in the circle — *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000). The soldier heights are given in clockwise or counterclockwise direction. Output Specification: Output two integers — indexes of neighbouring soldiers, who should form a reconnaissance unit. If there are many optimum solutions, output any of them. Remember, that the soldiers stand in a circle. Demo Input: ['5\n10 12 13 15 10\n', '4\n10 20 30 40\n'] Demo Output: ['5 1\n', '1 2\n'] Note: none
```python cnt = int(input()) soldier_list = list(map(int, input().split())) indices = [] nums = sorted([(num, index) for index, num in enumerate(soldier_list)]) x, y = nums[0] a, b = nums[1] print(nums) print(y + 1, b + 1) ```
0
600
A
Extract Numbers
PROGRAMMING
1,600
[ "implementation", "strings" ]
null
null
You are given string *s*. Let's call word any largest sequence of consecutive symbols without symbols ',' (comma) and ';' (semicolon). For example, there are four words in string "aba,123;1a;0": "aba", "123", "1a", "0". A word can be empty: for example, the string *s*=";;" contains three empty words separated by ';'. You should find all words in the given string that are nonnegative INTEGER numbers without leading zeroes and build by them new string *a*. String *a* should contain all words that are numbers separating them by ',' (the order of numbers should remain the same as in the string *s*). By all other words you should build string *b* in the same way (the order of numbers should remain the same as in the string *s*). Here strings "101", "0" are INTEGER numbers, but "01" and "1.0" are not. For example, for the string aba,123;1a;0 the string *a* would be equal to "123,0" and string *b* would be equal to "aba,1a".
The only line of input contains the string *s* (1<=≤<=|*s*|<=≤<=105). The string contains only symbols '.' (ASCII 46), ',' (ASCII 44), ';' (ASCII 59), digits, lowercase and uppercase latin letters.
Print the string *a* to the first line and string *b* to the second line. Each string should be surrounded by quotes (ASCII 34). If there are no words that are numbers print dash (ASCII 45) on the first line. If all words are numbers print dash on the second line.
[ "aba,123;1a;0\n", "1;;01,a0,\n", "1\n", "a\n" ]
[ "\"123,0\"\n\"aba,1a\"\n", "\"1\"\n\",01,a0,\"\n", "\"1\"\n-\n", "-\n\"a\"\n" ]
In the second example the string *s* contains five words: "1", "", "01", "a0", "".
0
[ { "input": "aba,123;1a;0", "output": "\"123,0\"\n\"aba,1a\"" }, { "input": "1;;01,a0,", "output": "\"1\"\n\",01,a0,\"" }, { "input": "1", "output": "\"1\"\n-" }, { "input": "a", "output": "-\n\"a\"" }, { "input": ",;,,;", "output": "-\n\",,,,,\"" }, { "input": "123;abacab,123;1,sadasfas,123213132g;02131313;aaa,0,012;0;03242;1", "output": "\"123,123,1,0,0,1\"\n\"abacab,sadasfas,123213132g,02131313,aaa,012,03242\"" }, { "input": ".", "output": "-\n\".\"" }, { "input": ";", "output": "-\n\",\"" }, { "input": "6;2,", "output": "\"6,2\"\n\"\"" }, { "input": "000", "output": "-\n\"000\"" }, { "input": "5345rhhr34t.k;k;k;k;k;5677;000000,000000;000098,0.70k;89.;;;", "output": "\"5677\"\n\"5345rhhr34t.k,k,k,k,k,000000,000000,000098,0.70k,89.,,,\"" }, { "input": "100.000", "output": "-\n\"100.000\"" }, { "input": ",,;,;,5345rh;hr;34t.k;k;k0,;,0,;k;k;5677.;000000,000000;000098,000.70k;89.;;;", "output": "\"0\"\n\",,,,,,5345rh,hr,34t.k,k,k0,,,,k,k,5677.,000000,000000,000098,000.70k,89.,,,\"" }, { "input": "01", "output": "-\n\"01\"" }, { "input": "ashasg,00000,00,;,hahaha,kheng", "output": "-\n\"ashasg,00000,00,,,hahaha,kheng\"" }, { "input": "00,0.0;00;0;,,0,0.0.0,,000,010;;", "output": "\"0,0\"\n\"00,0.0,00,,,0.0.0,,000,010,,\"" }, { "input": ",2", "output": "\"2\"\n\"\"" }, { "input": "123.123232,123.,.123,..,231.;0.,,.0;;123;123.1;.a", "output": "\"123\"\n\"123.123232,123.,.123,..,231.,0.,,.0,,123.1,.a\"" }, { "input": "123456789", "output": "\"123456789\"\n-" }, { "input": "00", "output": "-\n\"00\"" }, { "input": "thisisahack", "output": "-\n\"thisisahack\"" }, { "input": "000.0039255805110943267,0.7362934823735448084,Y3x2yDItgcQYwqPy,0.4300802119053827563", "output": "-\n\"000.0039255805110943267,0.7362934823735448084,Y3x2yDItgcQYwqPy,0.4300802119053827563\"" }, { "input": "asbad,0000,00,;,", "output": "-\n\"asbad,0000,00,,,\"" }, { "input": "0000", "output": "-\n\"0000\"" }, { "input": "12345678912345", "output": "\"12345678912345\"\n-" } ]
1,656,514,143
903
PyPy 3-64
COMPILATION_ERROR
TESTS
0
0
0
import re def isint(s): if not s.isdigit(): return False if len(s) > 1: if s[0] == '0': return False return True return True s = input() s1 = re.split(";|,", s) #print(s1) #print(s1) ans = [] i = 0 n = len(s1) while True: if i == n: break if isint(s1[i]): ans.append(s1.pop(i)) n -= 1 else: i += 1 if len(ans): #print(ans) print('"', ,"".join(ans), '"', sep = '') else: print("-") if len(s1): print('"', ",".join(s1), '"', sep = '') else: print("-")
Title: Extract Numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given string *s*. Let's call word any largest sequence of consecutive symbols without symbols ',' (comma) and ';' (semicolon). For example, there are four words in string "aba,123;1a;0": "aba", "123", "1a", "0". A word can be empty: for example, the string *s*=";;" contains three empty words separated by ';'. You should find all words in the given string that are nonnegative INTEGER numbers without leading zeroes and build by them new string *a*. String *a* should contain all words that are numbers separating them by ',' (the order of numbers should remain the same as in the string *s*). By all other words you should build string *b* in the same way (the order of numbers should remain the same as in the string *s*). Here strings "101", "0" are INTEGER numbers, but "01" and "1.0" are not. For example, for the string aba,123;1a;0 the string *a* would be equal to "123,0" and string *b* would be equal to "aba,1a". Input Specification: The only line of input contains the string *s* (1<=≤<=|*s*|<=≤<=105). The string contains only symbols '.' (ASCII 46), ',' (ASCII 44), ';' (ASCII 59), digits, lowercase and uppercase latin letters. Output Specification: Print the string *a* to the first line and string *b* to the second line. Each string should be surrounded by quotes (ASCII 34). If there are no words that are numbers print dash (ASCII 45) on the first line. If all words are numbers print dash on the second line. Demo Input: ['aba,123;1a;0\n', '1;;01,a0,\n', '1\n', 'a\n'] Demo Output: ['"123,0"\n"aba,1a"\n', '"1"\n",01,a0,"\n', '"1"\n-\n', '-\n"a"\n'] Note: In the second example the string *s* contains five words: "1", "", "01", "a0", "".
```python import re def isint(s): if not s.isdigit(): return False if len(s) > 1: if s[0] == '0': return False return True return True s = input() s1 = re.split(";|,", s) #print(s1) #print(s1) ans = [] i = 0 n = len(s1) while True: if i == n: break if isint(s1[i]): ans.append(s1.pop(i)) n -= 1 else: i += 1 if len(ans): #print(ans) print('"', ,"".join(ans), '"', sep = '') else: print("-") if len(s1): print('"', ",".join(s1), '"', sep = '') else: print("-") ```
-1
622
C
Not Equal on a Segment
PROGRAMMING
1,700
[ "data structures", "implementation" ]
null
null
You are given array *a* with *n* integers and *m* queries. The *i*-th query is given with three integers *l**i*,<=*r**i*,<=*x**i*. For the *i*-th query find any position *p**i* (*l**i*<=≤<=*p**i*<=≤<=*r**i*) so that *a**p**i*<=≠<=*x**i*.
The first line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=2·105) — the number of elements in *a* and the number of queries. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=106) — the elements of the array *a*. Each of the next *m* lines contains three integers *l**i*,<=*r**i*,<=*x**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*,<=1<=≤<=*x**i*<=≤<=106) — the parameters of the *i*-th query.
Print *m* lines. On the *i*-th line print integer *p**i* — the position of any number not equal to *x**i* in segment [*l**i*,<=*r**i*] or the value <=-<=1 if there is no such number.
[ "6 4\n1 2 1 1 3 5\n1 4 1\n2 6 2\n3 4 1\n3 4 2\n" ]
[ "2\n6\n-1\n4\n" ]
none
0
[ { "input": "6 4\n1 2 1 1 3 5\n1 4 1\n2 6 2\n3 4 1\n3 4 2", "output": "2\n6\n-1\n4" }, { "input": "1 1\n1\n1 1 1", "output": "-1" }, { "input": "1 1\n2\n1 1 2", "output": "-1" }, { "input": "1 1\n569888\n1 1 967368", "output": "1" }, { "input": "10 10\n1 1 1 1 1 1 1 1 1 1\n3 10 1\n3 6 1\n1 8 1\n1 7 1\n1 5 1\n3 7 1\n4 7 1\n9 9 1\n6 7 1\n3 4 1", "output": "-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1" }, { "input": "10 10\n1 2 2 2 2 1 1 2 1 1\n3 3 1\n4 9 1\n4 8 1\n2 7 2\n2 8 2\n3 10 1\n7 7 2\n10 10 2\n1 5 1\n1 2 1", "output": "3\n8\n8\n7\n7\n8\n7\n10\n5\n2" }, { "input": "10 10\n318890 307761 832732 700511 820583 522866 130891 914566 128429 739710\n4 9 178864\n6 9 741003\n4 9 172997\n4 6 314469\n1 4 694802\n8 8 401658\n7 10 376243\n7 8 508771\n3 5 30038\n2 10 591490", "output": "9\n9\n9\n6\n4\n8\n10\n8\n5\n10" }, { "input": "1 1\n2\n1 1 1", "output": "1" }, { "input": "10 10\n1 1 1 1 1 2 1 1 1 1\n1 9 1\n6 7 1\n2 4 1\n7 8 1\n1 3 1\n10 10 1\n3 5 1\n6 7 1\n1 10 1\n6 6 1", "output": "6\n6\n-1\n-1\n-1\n-1\n-1\n6\n6\n6" }, { "input": "7 1\n2 1 3 2 2 2 2\n1 7 2", "output": "3" }, { "input": "4 1\n3 1 2 2\n1 4 2", "output": "2" }, { "input": "6 1\n3 2 4 3 3 3\n1 6 3", "output": "3" }, { "input": "4 1\n1 3 2 2\n1 4 2", "output": "2" }, { "input": "5 1\n2 3 1 2 2\n1 5 2", "output": "3" }, { "input": "3 1\n1 9 5\n1 3 5", "output": "2" }, { "input": "4 1\n4 2 6 4\n1 4 4", "output": "3" }, { "input": "2 1\n1 3\n1 2 2", "output": "2" }, { "input": "10 1\n2 2 1 3 2 2 2 2 2 2\n2 5 2", "output": "4" }, { "input": "7 1\n6 5 7 6 6 6 6\n1 7 6", "output": "3" }, { "input": "3 1\n2 4 3\n1 3 3", "output": "2" }, { "input": "4 1\n4 2 3 3\n1 4 3", "output": "2" }, { "input": "5 1\n3 2 4 5 5\n1 3 3", "output": "3" }, { "input": "2 6\n1 1\n1 1 1\n1 1 2\n1 2 1\n1 2 2\n2 2 1\n2 2 2", "output": "-1\n1\n-1\n2\n-1\n2" } ]
1,588,988,760
2,147,483,647
Python 3
OK
TESTS
63
716
30,617,600
import sys input = sys.stdin.readline N, M = map(int, input().split()) A = list(map(int, input().split())) B = [N + 1 for _ in range(N)] idx = N + 1 for i in range(N - 1)[::-1]: if A[i] != A[i + 1]: idx = i + 1 B[i] = idx res = [] for _ in range(M): l, r, x = map(int, input().split()) if A[l - 1] != x: res.append(l) elif B[l - 1] <= r - 1: res.append(B[l - 1] + 1) else: res.append(-1) print('\n'.join(map(str, res)))
Title: Not Equal on a Segment Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given array *a* with *n* integers and *m* queries. The *i*-th query is given with three integers *l**i*,<=*r**i*,<=*x**i*. For the *i*-th query find any position *p**i* (*l**i*<=≤<=*p**i*<=≤<=*r**i*) so that *a**p**i*<=≠<=*x**i*. Input Specification: The first line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=2·105) — the number of elements in *a* and the number of queries. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=106) — the elements of the array *a*. Each of the next *m* lines contains three integers *l**i*,<=*r**i*,<=*x**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*,<=1<=≤<=*x**i*<=≤<=106) — the parameters of the *i*-th query. Output Specification: Print *m* lines. On the *i*-th line print integer *p**i* — the position of any number not equal to *x**i* in segment [*l**i*,<=*r**i*] or the value <=-<=1 if there is no such number. Demo Input: ['6 4\n1 2 1 1 3 5\n1 4 1\n2 6 2\n3 4 1\n3 4 2\n'] Demo Output: ['2\n6\n-1\n4\n'] Note: none
```python import sys input = sys.stdin.readline N, M = map(int, input().split()) A = list(map(int, input().split())) B = [N + 1 for _ in range(N)] idx = N + 1 for i in range(N - 1)[::-1]: if A[i] != A[i + 1]: idx = i + 1 B[i] = idx res = [] for _ in range(M): l, r, x = map(int, input().split()) if A[l - 1] != x: res.append(l) elif B[l - 1] <= r - 1: res.append(B[l - 1] + 1) else: res.append(-1) print('\n'.join(map(str, res))) ```
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,687,381,599
2,147,483,647
Python 3
OK
TESTS
102
46
0
number_1 = input() number_2 = input() answer = '' for i in range(len(number_2)): if number_1[i] != number_2[i]: answer += '1' else: answer += '0' print(answer)
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 number_1 = input() number_2 = input() answer = '' for i in range(len(number_2)): if number_1[i] != number_2[i]: answer += '1' else: answer += '0' print(answer) ```
3.9885
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,645,772,175
2,147,483,647
Python 3
OK
TESTS
35
62
0
a,b=[int(x) for x in input().split()] d=int(a*b/2) print(d)
Title: Domino piling Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions: 1. Each domino completely covers two squares. 2. No two dominoes overlap. 3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board. Find the maximum number of dominoes, which can be placed under these restrictions. Input Specification: In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). Output Specification: Output one number — the maximal number of dominoes, which can be placed. Demo Input: ['2 4\n', '3 3\n'] Demo Output: ['4\n', '4\n'] Note: none
```python a,b=[int(x) for x in input().split()] d=int(a*b/2) print(d) ```
3.9845
347
A
Difference Row
PROGRAMMING
1,300
[ "constructive algorithms", "implementation", "sortings" ]
null
null
You want to arrange *n* integers *a*1,<=*a*2,<=...,<=*a**n* in some order in a row. Let's define the value of an arrangement as the sum of differences between all pairs of adjacent integers. More formally, let's denote some arrangement as a sequence of integers *x*1,<=*x*2,<=...,<=*x**n*, where sequence *x* is a permutation of sequence *a*. The value of such an arrangement is (*x*1<=-<=*x*2)<=+<=(*x*2<=-<=*x*3)<=+<=...<=+<=(*x**n*<=-<=1<=-<=*x**n*). Find the largest possible value of an arrangement. Then, output the lexicographically smallest sequence *x* that corresponds to an arrangement of the largest possible value.
The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=100). The second line contains *n* space-separated integers *a*1, *a*2, ..., *a**n* (|*a**i*|<=≤<=1000).
Print the required sequence *x*1,<=*x*2,<=...,<=*x**n*. Sequence *x* should be the lexicographically smallest permutation of *a* that corresponds to an arrangement of the largest possible value.
[ "5\n100 -100 50 0 -50\n" ]
[ "100 -50 0 50 -100 \n" ]
In the sample test case, the value of the output arrangement is (100 - ( - 50)) + (( - 50) - 0) + (0 - 50) + (50 - ( - 100)) = 200. No other arrangement has a larger value, and among all arrangements with the value of 200, the output arrangement is the lexicographically smallest one. Sequence *x*<sub class="lower-index">1</sub>, *x*<sub class="lower-index">2</sub>, ... , *x*<sub class="lower-index">*p*</sub> is lexicographically smaller than sequence *y*<sub class="lower-index">1</sub>, *y*<sub class="lower-index">2</sub>, ... , *y*<sub class="lower-index">*p*</sub> if there exists an integer *r* (0 ≤ *r* &lt; *p*) such 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> &lt; *y*<sub class="lower-index">*r* + 1</sub>.
500
[ { "input": "5\n100 -100 50 0 -50", "output": "100 -50 0 50 -100 " }, { "input": "10\n764 -367 0 963 -939 -795 -26 -49 948 -282", "output": "963 -795 -367 -282 -49 -26 0 764 948 -939 " }, { "input": "20\n262 -689 -593 161 -678 -555 -633 -697 369 258 673 50 833 737 -650 198 -651 -621 -396 939", "output": "939 -689 -678 -651 -650 -633 -621 -593 -555 -396 50 161 198 258 262 369 673 737 833 -697 " }, { "input": "50\n-262 -377 -261 903 547 759 -800 -53 670 92 758 109 547 877 152 -901 -318 -527 -388 24 139 -227 413 -135 811 -886 -22 -526 -643 -431 284 609 -745 -62 323 -441 743 -800 86 862 587 -513 -468 -651 -760 197 141 -414 -909 438", "output": "903 -901 -886 -800 -800 -760 -745 -651 -643 -527 -526 -513 -468 -441 -431 -414 -388 -377 -318 -262 -261 -227 -135 -62 -53 -22 24 86 92 109 139 141 152 197 284 323 413 438 547 547 587 609 670 743 758 759 811 862 877 -909 " }, { "input": "100\n144 -534 -780 -1 -259 -945 -992 -967 -679 -239 -22 387 130 -908 140 -270 16 646 398 599 -631 -231 687 -505 89 77 584 162 124 132 33 271 212 734 350 -678 969 43 487 -689 -432 -225 -603 801 -828 -684 349 318 109 723 33 -247 719 368 -286 217 260 77 -618 955 408 994 -313 -341 578 609 60 900 222 -779 -507 464 -147 -789 -477 -235 -407 -432 35 300 -53 -896 -476 927 -293 -869 -852 -566 -759 95 506 -914 -405 -621 319 -622 -49 -334 328 -104", "output": "994 -967 -945 -914 -908 -896 -869 -852 -828 -789 -780 -779 -759 -689 -684 -679 -678 -631 -622 -621 -618 -603 -566 -534 -507 -505 -477 -476 -432 -432 -407 -405 -341 -334 -313 -293 -286 -270 -259 -247 -239 -235 -231 -225 -147 -104 -53 -49 -22 -1 16 33 33 35 43 60 77 77 89 95 109 124 130 132 140 144 162 212 217 222 260 271 300 318 319 328 349 350 368 387 398 408 464 487 506 578 584 599 609 646 687 719 723 734 801 900 927 955 969 -992 " }, { "input": "100\n-790 341 910 905 -779 279 696 -375 525 -21 -2 751 -887 764 520 -844 850 -537 -882 -183 139 -397 561 -420 -991 691 587 -93 -701 -957 -89 227 233 545 934 309 -26 454 -336 -994 -135 -840 -320 -387 -943 650 628 -583 701 -708 -881 287 -932 -265 -312 -757 695 985 -165 -329 -4 -462 -627 798 -124 -539 843 -492 -967 -782 879 -184 -351 -385 -713 699 -477 828 219 961 -170 -542 877 -718 417 152 -905 181 301 920 685 -502 518 -115 257 998 -112 -234 -223 -396", "output": "998 -991 -967 -957 -943 -932 -905 -887 -882 -881 -844 -840 -790 -782 -779 -757 -718 -713 -708 -701 -627 -583 -542 -539 -537 -502 -492 -477 -462 -420 -397 -396 -387 -385 -375 -351 -336 -329 -320 -312 -265 -234 -223 -184 -183 -170 -165 -135 -124 -115 -112 -93 -89 -26 -21 -4 -2 139 152 181 219 227 233 257 279 287 301 309 341 417 454 518 520 525 545 561 587 628 650 685 691 695 696 699 701 751 764 798 828 843 850 877 879 905 910 920 934 961 985 -994 " }, { "input": "100\n720 331 -146 -935 399 248 525 -669 614 -245 320 229 842 -894 -73 584 -458 -975 -604 -78 607 -120 -377 409 -743 862 -969 980 105 841 -795 996 696 -759 -482 624 -578 421 -717 -553 -652 -268 405 426 642 870 -650 -812 178 -882 -237 -737 -724 358 407 714 759 779 -899 -726 398 -663 -56 -736 -825 313 -746 117 -457 330 -925 497 332 -794 -506 -811 -990 -799 -343 -380 598 926 671 967 -573 -687 741 484 -641 -698 -251 -391 23 692 337 -639 126 8 -915 -386", "output": "996 -975 -969 -935 -925 -915 -899 -894 -882 -825 -812 -811 -799 -795 -794 -759 -746 -743 -737 -736 -726 -724 -717 -698 -687 -669 -663 -652 -650 -641 -639 -604 -578 -573 -553 -506 -482 -458 -457 -391 -386 -380 -377 -343 -268 -251 -245 -237 -146 -120 -78 -73 -56 8 23 105 117 126 178 229 248 313 320 330 331 332 337 358 398 399 405 407 409 421 426 484 497 525 584 598 607 614 624 642 671 692 696 714 720 741 759 779 841 842 862 870 926 967 980 -990 " }, { "input": "100\n-657 320 -457 -472 -423 -227 -902 -520 702 -27 -103 149 268 -922 307 -292 377 730 117 1000 935 459 -502 796 -494 892 -523 866 166 -248 57 -606 -96 -948 988 194 -687 832 -425 28 -356 -884 688 353 225 204 -68 960 -929 -312 -479 381 512 -274 -505 -260 -506 572 226 -822 -13 325 -370 403 -714 494 339 283 356 327 159 -151 -13 -760 -159 -991 498 19 -159 583 178 -50 -421 -679 -978 334 688 -99 117 -988 371 693 946 -58 -699 -133 62 693 535 -375", "output": "1000 -988 -978 -948 -929 -922 -902 -884 -822 -760 -714 -699 -687 -679 -657 -606 -523 -520 -506 -505 -502 -494 -479 -472 -457 -425 -423 -421 -375 -370 -356 -312 -292 -274 -260 -248 -227 -159 -159 -151 -133 -103 -99 -96 -68 -58 -50 -27 -13 -13 19 28 57 62 117 117 149 159 166 178 194 204 225 226 268 283 307 320 325 327 334 339 353 356 371 377 381 403 459 494 498 512 535 572 583 688 688 693 693 702 730 796 832 866 892 935 946 960 988 -991 " }, { "input": "100\n853 752 931 -453 -943 -118 -772 -814 791 191 -83 -373 -748 -136 -286 250 627 292 -48 -896 -296 736 -628 -376 -246 -495 366 610 228 664 -951 -952 811 192 -730 -377 319 799 753 166 827 501 157 -834 -776 424 655 -827 549 -487 608 -643 419 349 -88 95 231 -520 -508 -105 -727 568 -241 286 586 -956 -880 892 866 22 658 832 -216 -54 491 -500 -687 393 24 129 946 303 931 563 -269 -203 -251 647 -824 -163 248 -896 -133 749 -619 -212 -2 491 287 219", "output": "946 -952 -951 -943 -896 -896 -880 -834 -827 -824 -814 -776 -772 -748 -730 -727 -687 -643 -628 -619 -520 -508 -500 -495 -487 -453 -377 -376 -373 -296 -286 -269 -251 -246 -241 -216 -212 -203 -163 -136 -133 -118 -105 -88 -83 -54 -48 -2 22 24 95 129 157 166 191 192 219 228 231 248 250 286 287 292 303 319 349 366 393 419 424 491 491 501 549 563 568 586 608 610 627 647 655 658 664 736 749 752 753 791 799 811 827 832 853 866 892 931 931 -956 " }, { "input": "100\n9 857 227 -593 -983 -439 17 -523 -354 -189 780 -267 771 -981 943 620 -832 79 761 -943 218 -966 75 131 -596 534 51 796 -612 -381 -690 -353 -170 648 804 -256 257 -16 964 -728 310 50 453 737 -228 -625 618 841 -102 974 -850 -641 -788 231 -982 -84 -917 942 -913 -768 -83 298 388 447 -490 271 -949 976 -820 -876 -822 -188 -306 877 219 854 561 -307 -920 916 -925 -591 -149 -166 -572 860 -217 -831 -552 822 355 -150 203 -710 530 910 889 964 -125 -597", "output": "976 -982 -981 -966 -949 -943 -925 -920 -917 -913 -876 -850 -832 -831 -822 -820 -788 -768 -728 -710 -690 -641 -625 -612 -597 -596 -593 -591 -572 -552 -523 -490 -439 -381 -354 -353 -307 -306 -267 -256 -228 -217 -189 -188 -170 -166 -150 -149 -125 -102 -84 -83 -16 9 17 50 51 75 79 131 203 218 219 227 231 257 271 298 310 355 388 447 453 530 534 561 618 620 648 737 761 771 780 796 804 822 841 854 857 860 877 889 910 916 942 943 964 964 974 -983 " }, { "input": "2\n-1000 1000", "output": "1000 -1000 " }, { "input": "2\n1000 -1000", "output": "1000 -1000 " }, { "input": "2\n0 0", "output": "0 0 " }, { "input": "5\n1 2 3 4 5", "output": "5 2 3 4 1 " }, { "input": "6\n1 1 1 2 2 2", "output": "2 1 1 2 2 1 " }, { "input": "3\n-1 -1 -1", "output": "-1 -1 -1 " } ]
1,555,600,140
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
154
307,200
import math def na(): n = int(input()) b = [int(x) for x in input().split()] return n,b def nab(): n = int(input()) b = [int(x) for x in input().split()] c = [int(x) for x in input().split()] return n,b,c def dv(): n, m = map(int, input().split()) return n,m def dva(): n, m = map(int, input().split()) b = [int(x) for x in input().split()] return n,m,b def nm(): n = int(input()) b = [int(x) for x in input().split()] m = int(input()) c = [int(x) for x in input().split()] return n,b,m,c def dvs(): n = int(input()) m = int(input()) return n, m n, a = na() a.sort(reverse= True) b = a[0::2] c = a[1::2][::-1] for i in range(min(len(b), len(c))): print(b[i], c[i], end = ' ') if len(b) < len(c): print(c[-1]) elif len(c) < len(b): print(b[-1])
Title: Difference Row Time Limit: None seconds Memory Limit: None megabytes Problem Description: You want to arrange *n* integers *a*1,<=*a*2,<=...,<=*a**n* in some order in a row. Let's define the value of an arrangement as the sum of differences between all pairs of adjacent integers. More formally, let's denote some arrangement as a sequence of integers *x*1,<=*x*2,<=...,<=*x**n*, where sequence *x* is a permutation of sequence *a*. The value of such an arrangement is (*x*1<=-<=*x*2)<=+<=(*x*2<=-<=*x*3)<=+<=...<=+<=(*x**n*<=-<=1<=-<=*x**n*). Find the largest possible value of an arrangement. Then, output the lexicographically smallest sequence *x* that corresponds to an arrangement of the largest possible value. Input Specification: The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=100). The second line contains *n* space-separated integers *a*1, *a*2, ..., *a**n* (|*a**i*|<=≤<=1000). Output Specification: Print the required sequence *x*1,<=*x*2,<=...,<=*x**n*. Sequence *x* should be the lexicographically smallest permutation of *a* that corresponds to an arrangement of the largest possible value. Demo Input: ['5\n100 -100 50 0 -50\n'] Demo Output: ['100 -50 0 50 -100 \n'] Note: In the sample test case, the value of the output arrangement is (100 - ( - 50)) + (( - 50) - 0) + (0 - 50) + (50 - ( - 100)) = 200. No other arrangement has a larger value, and among all arrangements with the value of 200, the output arrangement is the lexicographically smallest one. Sequence *x*<sub class="lower-index">1</sub>, *x*<sub class="lower-index">2</sub>, ... , *x*<sub class="lower-index">*p*</sub> is lexicographically smaller than sequence *y*<sub class="lower-index">1</sub>, *y*<sub class="lower-index">2</sub>, ... , *y*<sub class="lower-index">*p*</sub> if there exists an integer *r* (0 ≤ *r* &lt; *p*) such 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> &lt; *y*<sub class="lower-index">*r* + 1</sub>.
```python import math def na(): n = int(input()) b = [int(x) for x in input().split()] return n,b def nab(): n = int(input()) b = [int(x) for x in input().split()] c = [int(x) for x in input().split()] return n,b,c def dv(): n, m = map(int, input().split()) return n,m def dva(): n, m = map(int, input().split()) b = [int(x) for x in input().split()] return n,m,b def nm(): n = int(input()) b = [int(x) for x in input().split()] m = int(input()) c = [int(x) for x in input().split()] return n,b,m,c def dvs(): n = int(input()) m = int(input()) return n, m n, a = na() a.sort(reverse= True) b = a[0::2] c = a[1::2][::-1] for i in range(min(len(b), len(c))): print(b[i], c[i], end = ' ') if len(b) < len(c): print(c[-1]) elif len(c) < len(b): print(b[-1]) ```
0
208
A
Dubstep
PROGRAMMING
900
[ "strings" ]
null
null
Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them. Let's assume that a song consists of some number of words. To make the dubstep remix of this song, Vasya inserts a certain number of words "WUB" before the first word of the song (the number may be zero), after the last word (the number may be zero), and between words (at least one between any pair of neighbouring words), and then the boy glues together all the words, including "WUB", in one string and plays the song at the club. For example, a song with words "I AM X" can transform into a dubstep remix as "WUBWUBIWUBAMWUBWUBX" and cannot transform into "WUBWUBIAMWUBX". Recently, Petya has heard Vasya's new dubstep track, but since he isn't into modern music, he decided to find out what was the initial song that Vasya remixed. Help Petya restore the original song.
The input consists of a single non-empty string, consisting only of uppercase English letters, the string's length doesn't exceed 200 characters. It is guaranteed that before Vasya remixed the song, no word contained substring "WUB" in it; Vasya didn't change the word order. It is also guaranteed that initially the song had at least one word.
Print the words of the initial song that Vasya used to make a dubsteb remix. Separate the words with a space.
[ "WUBWUBABCWUB\n", "WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB\n" ]
[ "ABC ", "WE ARE THE CHAMPIONS MY FRIEND " ]
In the first sample: "WUBWUBABCWUB" = "WUB" + "WUB" + "ABC" + "WUB". That means that the song originally consisted of a single word "ABC", and all words "WUB" were added by Vasya. In the second sample Vasya added a single word "WUB" between all neighbouring words, in the beginning and in the end, except for words "ARE" and "THE" — between them Vasya added two "WUB".
500
[ { "input": "WUBWUBABCWUB", "output": "ABC " }, { "input": "WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB", "output": "WE ARE THE CHAMPIONS MY FRIEND " }, { "input": "WUBWUBWUBSR", "output": "SR " }, { "input": "RWUBWUBWUBLWUB", "output": "R L " }, { "input": "ZJWUBWUBWUBJWUBWUBWUBL", "output": "ZJ J L " }, { "input": "CWUBBWUBWUBWUBEWUBWUBWUBQWUBWUBWUB", "output": "C B E Q " }, { "input": "WUBJKDWUBWUBWBIRAQKFWUBWUBYEWUBWUBWUBWVWUBWUB", "output": "JKD WBIRAQKF YE WV " }, { "input": "WUBKSDHEMIXUJWUBWUBRWUBWUBWUBSWUBWUBWUBHWUBWUBWUB", "output": "KSDHEMIXUJ R S H " }, { "input": "OGWUBWUBWUBXWUBWUBWUBIWUBWUBWUBKOWUBWUB", "output": "OG X I KO " }, { "input": "QWUBQQWUBWUBWUBIWUBWUBWWWUBWUBWUBJOPJPBRH", "output": "Q QQ I WW JOPJPBRH " }, { "input": "VSRNVEATZTLGQRFEGBFPWUBWUBWUBAJWUBWUBWUBPQCHNWUBCWUB", "output": "VSRNVEATZTLGQRFEGBFP AJ PQCHN C " }, { "input": "WUBWUBEWUBWUBWUBIQMJNIQWUBWUBWUBGZZBQZAUHYPWUBWUBWUBPMRWUBWUBWUBDCV", "output": "E IQMJNIQ GZZBQZAUHYP PMR DCV " }, { "input": "WUBWUBWUBFVWUBWUBWUBBPSWUBWUBWUBRXNETCJWUBWUBWUBJDMBHWUBWUBWUBBWUBWUBVWUBWUBB", "output": "FV BPS RXNETCJ JDMBH B V B " }, { "input": "WUBWUBWUBFBQWUBWUBWUBIDFSYWUBWUBWUBCTWDMWUBWUBWUBSXOWUBWUBWUBQIWUBWUBWUBL", "output": "FBQ IDFSY CTWDM SXO QI L " }, { "input": "IWUBWUBQLHDWUBYIIKZDFQWUBWUBWUBCXWUBWUBUWUBWUBWUBKWUBWUBWUBNL", "output": "I QLHD YIIKZDFQ CX U K NL " }, { "input": "KWUBUPDYXGOKUWUBWUBWUBAGOAHWUBIZDWUBWUBWUBIYWUBWUBWUBVWUBWUBWUBPWUBWUBWUBE", "output": "K UPDYXGOKU AGOAH IZD IY V P E " }, { "input": "WUBWUBOWUBWUBWUBIPVCQAFWYWUBWUBWUBQWUBWUBWUBXHDKCPYKCTWWYWUBWUBWUBVWUBWUBWUBFZWUBWUB", "output": "O IPVCQAFWY Q XHDKCPYKCTWWY V FZ " }, { "input": "PAMJGYWUBWUBWUBXGPQMWUBWUBWUBTKGSXUYWUBWUBWUBEWUBWUBWUBNWUBWUBWUBHWUBWUBWUBEWUBWUB", "output": "PAMJGY XGPQM TKGSXUY E N H E " }, { "input": "WUBYYRTSMNWUWUBWUBWUBCWUBWUBWUBCWUBWUBWUBFSYUINDWOBVWUBWUBWUBFWUBWUBWUBAUWUBWUBWUBVWUBWUBWUBJB", "output": "YYRTSMNWU C C FSYUINDWOBV F AU V JB " }, { "input": "WUBWUBYGPYEYBNRTFKOQCWUBWUBWUBUYGRTQEGWLFYWUBWUBWUBFVWUBHPWUBWUBWUBXZQWUBWUBWUBZDWUBWUBWUBM", "output": "YGPYEYBNRTFKOQC UYGRTQEGWLFY FV HP XZQ ZD M " }, { "input": "WUBZVMJWUBWUBWUBFOIMJQWKNZUBOFOFYCCWUBWUBWUBAUWWUBRDRADWUBWUBWUBCHQVWUBWUBWUBKFTWUBWUBWUBW", "output": "ZVMJ FOIMJQWKNZUBOFOFYCC AUW RDRAD CHQV KFT W " }, { "input": "WUBWUBZBKOKHQLGKRVIMZQMQNRWUBWUBWUBDACWUBWUBNZHFJMPEYKRVSWUBWUBWUBPPHGAVVPRZWUBWUBWUBQWUBWUBAWUBG", "output": "ZBKOKHQLGKRVIMZQMQNR DAC NZHFJMPEYKRVS PPHGAVVPRZ Q A G " }, { "input": "WUBWUBJWUBWUBWUBNFLWUBWUBWUBGECAWUBYFKBYJWTGBYHVSSNTINKWSINWSMAWUBWUBWUBFWUBWUBWUBOVWUBWUBLPWUBWUBWUBN", "output": "J NFL GECA YFKBYJWTGBYHVSSNTINKWSINWSMA F OV LP N " }, { "input": "WUBWUBLCWUBWUBWUBZGEQUEATJVIXETVTWUBWUBWUBEXMGWUBWUBWUBRSWUBWUBWUBVWUBWUBWUBTAWUBWUBWUBCWUBWUBWUBQG", "output": "LC ZGEQUEATJVIXETVT EXMG RS V TA C QG " }, { "input": "WUBMPWUBWUBWUBORWUBWUBDLGKWUBWUBWUBVVZQCAAKVJTIKWUBWUBWUBTJLUBZJCILQDIFVZWUBWUBYXWUBWUBWUBQWUBWUBWUBLWUB", "output": "MP OR DLGK VVZQCAAKVJTIK TJLUBZJCILQDIFVZ YX Q L " }, { "input": "WUBNXOLIBKEGXNWUBWUBWUBUWUBGITCNMDQFUAOVLWUBWUBWUBAIJDJZJHFMPVTPOXHPWUBWUBWUBISCIOWUBWUBWUBGWUBWUBWUBUWUB", "output": "NXOLIBKEGXN U GITCNMDQFUAOVL AIJDJZJHFMPVTPOXHP ISCIO G U " }, { "input": "WUBWUBNMMWCZOLYPNBELIYVDNHJUNINWUBWUBWUBDXLHYOWUBWUBWUBOJXUWUBWUBWUBRFHTGJCEFHCGWARGWUBWUBWUBJKWUBWUBSJWUBWUB", "output": "NMMWCZOLYPNBELIYVDNHJUNIN DXLHYO OJXU RFHTGJCEFHCGWARG JK SJ " }, { "input": "SGWLYSAUJOJBNOXNWUBWUBWUBBOSSFWKXPDPDCQEWUBWUBWUBDIRZINODWUBWUBWUBWWUBWUBWUBPPHWUBWUBWUBRWUBWUBWUBQWUBWUBWUBJWUB", "output": "SGWLYSAUJOJBNOXN BOSSFWKXPDPDCQE DIRZINOD W PPH R Q J " }, { "input": "TOWUBWUBWUBGBTBNWUBWUBWUBJVIOJBIZFUUYHUAIEBQLQXPQKZJMPTCWBKPOSAWUBWUBWUBSWUBWUBWUBTOLVXWUBWUBWUBNHWUBWUBWUBO", "output": "TO GBTBN JVIOJBIZFUUYHUAIEBQLQXPQKZJMPTCWBKPOSA S TOLVX NH O " }, { "input": "WUBWUBWSPLAYSZSAUDSWUBWUBWUBUWUBWUBWUBKRWUBWUBWUBRSOKQMZFIYZQUWUBWUBWUBELSHUWUBWUBWUBUKHWUBWUBWUBQXEUHQWUBWUBWUBBWUBWUBWUBR", "output": "WSPLAYSZSAUDS U KR RSOKQMZFIYZQU ELSHU UKH QXEUHQ B R " }, { "input": "WUBXEMWWVUHLSUUGRWUBWUBWUBAWUBXEGILZUNKWUBWUBWUBJDHHKSWUBWUBWUBDTSUYSJHWUBWUBWUBPXFWUBMOHNJWUBWUBWUBZFXVMDWUBWUBWUBZMWUBWUB", "output": "XEMWWVUHLSUUGR A XEGILZUNK JDHHKS DTSUYSJH PXF MOHNJ ZFXVMD ZM " }, { "input": "BMBWUBWUBWUBOQKWUBWUBWUBPITCIHXHCKLRQRUGXJWUBWUBWUBVWUBWUBWUBJCWUBWUBWUBQJPWUBWUBWUBBWUBWUBWUBBMYGIZOOXWUBWUBWUBTAGWUBWUBHWUB", "output": "BMB OQK PITCIHXHCKLRQRUGXJ V JC QJP B BMYGIZOOX TAG H " }, { "input": "CBZNWUBWUBWUBNHWUBWUBWUBYQSYWUBWUBWUBMWUBWUBWUBXRHBTMWUBWUBWUBPCRCWUBWUBWUBTZUYLYOWUBWUBWUBCYGCWUBWUBWUBCLJWUBWUBWUBSWUBWUBWUB", "output": "CBZN NH YQSY M XRHBTM PCRC TZUYLYO CYGC CLJ S " }, { "input": "DPDWUBWUBWUBEUQKWPUHLTLNXHAEKGWUBRRFYCAYZFJDCJLXBAWUBWUBWUBHJWUBOJWUBWUBWUBNHBJEYFWUBWUBWUBRWUBWUBWUBSWUBWWUBWUBWUBXDWUBWUBWUBJWUB", "output": "DPD EUQKWPUHLTLNXHAEKG RRFYCAYZFJDCJLXBA HJ OJ NHBJEYF R S W XD J " }, { "input": "WUBWUBWUBISERPQITVIYERSCNWUBWUBWUBQWUBWUBWUBDGSDIPWUBWUBWUBCAHKDZWEXBIBJVVSKKVQJWUBWUBWUBKIWUBWUBWUBCWUBWUBWUBAWUBWUBWUBPWUBWUBWUBHWUBWUBWUBF", "output": "ISERPQITVIYERSCN Q DGSDIP CAHKDZWEXBIBJVVSKKVQJ KI C A P H F " }, { "input": "WUBWUBWUBIWUBWUBLIKNQVWUBWUBWUBPWUBWUBWUBHWUBWUBWUBMWUBWUBWUBDPRSWUBWUBWUBBSAGYLQEENWXXVWUBWUBWUBXMHOWUBWUBWUBUWUBWUBWUBYRYWUBWUBWUBCWUBWUBWUBY", "output": "I LIKNQV P H M DPRS BSAGYLQEENWXXV XMHO U YRY C Y " }, { "input": "WUBWUBWUBMWUBWUBWUBQWUBWUBWUBITCFEYEWUBWUBWUBHEUWGNDFNZGWKLJWUBWUBWUBMZPWUBWUBWUBUWUBWUBWUBBWUBWUBWUBDTJWUBHZVIWUBWUBWUBPWUBFNHHWUBWUBWUBVTOWUB", "output": "M Q ITCFEYE HEUWGNDFNZGWKLJ MZP U B DTJ HZVI P FNHH VTO " }, { "input": "WUBWUBNDNRFHYJAAUULLHRRDEDHYFSRXJWUBWUBWUBMUJVDTIRSGYZAVWKRGIFWUBWUBWUBHMZWUBWUBWUBVAIWUBWUBWUBDDKJXPZRGWUBWUBWUBSGXWUBWUBWUBIFKWUBWUBWUBUWUBWUBWUBW", "output": "NDNRFHYJAAUULLHRRDEDHYFSRXJ MUJVDTIRSGYZAVWKRGIF HMZ VAI DDKJXPZRG SGX IFK U W " }, { "input": "WUBOJMWRSLAXXHQRTPMJNCMPGWUBWUBWUBNYGMZIXNLAKSQYWDWUBWUBWUBXNIWUBWUBWUBFWUBWUBWUBXMBWUBWUBWUBIWUBWUBWUBINWUBWUBWUBWDWUBWUBWUBDDWUBWUBWUBD", "output": "OJMWRSLAXXHQRTPMJNCMPG NYGMZIXNLAKSQYWD XNI F XMB I IN WD DD D " }, { "input": "WUBWUBWUBREHMWUBWUBWUBXWUBWUBWUBQASNWUBWUBWUBNLSMHLCMTICWUBWUBWUBVAWUBWUBWUBHNWUBWUBWUBNWUBWUBWUBUEXLSFOEULBWUBWUBWUBXWUBWUBWUBJWUBWUBWUBQWUBWUBWUBAWUBWUB", "output": "REHM X QASN NLSMHLCMTIC VA HN N UEXLSFOEULB X J Q A " }, { "input": "WUBWUBWUBSTEZTZEFFIWUBWUBWUBSWUBWUBWUBCWUBFWUBHRJPVWUBWUBWUBDYJUWUBWUBWUBPWYDKCWUBWUBWUBCWUBWUBWUBUUEOGCVHHBWUBWUBWUBEXLWUBWUBWUBVCYWUBWUBWUBMWUBWUBWUBYWUB", "output": "STEZTZEFFI S C F HRJPV DYJU PWYDKC C UUEOGCVHHB EXL VCY M Y " }, { "input": "WPPNMSQOQIWUBWUBWUBPNQXWUBWUBWUBHWUBWUBWUBNFLWUBWUBWUBGWSGAHVJFNUWUBWUBWUBFWUBWUBWUBWCMLRICFSCQQQTNBWUBWUBWUBSWUBWUBWUBKGWUBWUBWUBCWUBWUBWUBBMWUBWUBWUBRWUBWUB", "output": "WPPNMSQOQI PNQX H NFL GWSGAHVJFNU F WCMLRICFSCQQQTNB S KG C BM R " }, { "input": "YZJOOYITZRARKVFYWUBWUBRZQGWUBWUBWUBUOQWUBWUBWUBIWUBWUBWUBNKVDTBOLETKZISTWUBWUBWUBWLWUBQQFMMGSONZMAWUBZWUBWUBWUBQZUXGCWUBWUBWUBIRZWUBWUBWUBLTTVTLCWUBWUBWUBY", "output": "YZJOOYITZRARKVFY RZQG UOQ I NKVDTBOLETKZIST WL QQFMMGSONZMA Z QZUXGC IRZ LTTVTLC Y " }, { "input": "WUBCAXNCKFBVZLGCBWCOAWVWOFKZVQYLVTWUBWUBWUBNLGWUBWUBWUBAMGDZBDHZMRMQMDLIRMIWUBWUBWUBGAJSHTBSWUBWUBWUBCXWUBWUBWUBYWUBZLXAWWUBWUBWUBOHWUBWUBWUBZWUBWUBWUBGBWUBWUBWUBE", "output": "CAXNCKFBVZLGCBWCOAWVWOFKZVQYLVT NLG AMGDZBDHZMRMQMDLIRMI GAJSHTBS CX Y ZLXAW OH Z GB E " }, { "input": "WUBWUBCHXSOWTSQWUBWUBWUBCYUZBPBWUBWUBWUBSGWUBWUBWKWORLRRLQYUUFDNWUBWUBWUBYYGOJNEVEMWUBWUBWUBRWUBWUBWUBQWUBWUBWUBIHCKWUBWUBWUBKTWUBWUBWUBRGSNTGGWUBWUBWUBXCXWUBWUBWUBS", "output": "CHXSOWTSQ CYUZBPB SG WKWORLRRLQYUUFDN YYGOJNEVEM R Q IHCK KT RGSNTGG XCX S " }, { "input": "WUBWUBWUBHJHMSBURXTHXWSCHNAIJOWBHLZGJZDHEDSPWBWACCGQWUBWUBWUBXTZKGIITWUBWUBWUBAWUBWUBWUBVNCXPUBCQWUBWUBWUBIDPNAWUBWUBWUBOWUBWUBWUBYGFWUBWUBWUBMQOWUBWUBWUBKWUBWUBWUBAZVWUBWUBWUBEP", "output": "HJHMSBURXTHXWSCHNAIJOWBHLZGJZDHEDSPWBWACCGQ XTZKGIIT A VNCXPUBCQ IDPNA O YGF MQO K AZV EP " }, { "input": "WUBKYDZOYWZSNGMKJSWAXFDFLTHDHEOGTDBNZMSMKZTVWUBWUBWUBLRMIIWUBWUBWUBGWUBWUBWUBADPSWUBWUBWUBANBWUBWUBPCWUBWUBWUBPWUBWUBWUBGPVNLSWIRFORYGAABUXMWUBWUBWUBOWUBWUBWUBNWUBWUBWUBYWUBWUB", "output": "KYDZOYWZSNGMKJSWAXFDFLTHDHEOGTDBNZMSMKZTV LRMII G ADPS ANB PC P GPVNLSWIRFORYGAABUXM O N Y " }, { "input": "REWUBWUBWUBJDWUBWUBWUBNWUBWUBWUBTWWUBWUBWUBWZDOCKKWUBWUBWUBLDPOVBFRCFWUBWUBAKZIBQKEUAZEEWUBWUBWUBLQYPNPFWUBYEWUBWUBWUBFWUBWUBWUBBPWUBWUBWUBAWWUBWUBWUBQWUBWUBWUBBRWUBWUBWUBXJL", "output": "RE JD N TW WZDOCKK LDPOVBFRCF AKZIBQKEUAZEE LQYPNPF YE F BP AW Q BR XJL " }, { "input": "CUFGJDXGMWUBWUBWUBOMWUBWUBWUBSIEWUBWUBWUBJJWKNOWUBWUBWUBYBHVNRNORGYWUBWUBWUBOAGCAWUBWUBWUBSBLBKTPFKPBIWUBWUBWUBJBWUBWUBWUBRMFCJPGWUBWUBWUBDWUBWUBWUBOJOWUBWUBWUBZPWUBWUBWUBMWUBRWUBWUBWUBFXWWUBWUBWUBO", "output": "CUFGJDXGM OM SIE JJWKNO YBHVNRNORGY OAGCA SBLBKTPFKPBI JB RMFCJPG D OJO ZP M R FXW O " }, { "input": "WUBJZGAEXFMFEWMAKGQLUWUBWUBWUBICYTPQWGENELVYWANKUOJYWUBWUBWUBGWUBWUBWUBHYCJVLPHTUPNEGKCDGQWUBWUBWUBOFWUBWUBWUBCPGSOGZBRPRPVJJEWUBWUBWUBDQBCWUBWUBWUBHWUBWUBWUBMHOHYBMATWUBWUBWUBVWUBWUBWUBSWUBWUBWUBKOWU", "output": "JZGAEXFMFEWMAKGQLU ICYTPQWGENELVYWANKUOJY G HYCJVLPHTUPNEGKCDGQ OF CPGSOGZBRPRPVJJE DQBC H MHOHYBMAT V S KOWU " }, { "input": "A", "output": "A " }, { "input": "WUBA", "output": "A " }, { "input": "WUBWUBA", "output": "A " }, { "input": "AWUBWUBWUB", "output": "A " }, { "input": "AWUBBWUBCWUBD", "output": "A B C D " }, { "input": "WUBWWUBWUBWUBUWUBWUBBWUB", "output": "W U B " }, { "input": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "output": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA " }, { "input": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAWUBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "output": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA " }, { "input": "WUWUBBWWUBUB", "output": "WU BW UB " }, { "input": "WUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUABWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUB", "output": "WUAB " }, { "input": "ZWUB", "output": "Z " }, { "input": "WU", "output": "WU " }, { "input": "UB", "output": "UB " }, { "input": "U", "output": "U " }, { "input": "WUBW", "output": "W " }, { "input": "WUBWU", "output": "WU " }, { "input": "WUWUB", "output": "WU " }, { "input": "UBWUB", "output": "UB " }, { "input": "WUWUBUBWUBUWUB", "output": "WU UB U " }, { "input": "WUBWWUBAWUB", "output": "W A " }, { "input": "WUUUUU", "output": "WUUUUU " } ]
1,679,373,432
2,147,483,647
PyPy 3-64
RUNTIME_ERROR
TESTS
0
154
3,481,600
str = input() s = '' for i in str: if i == 'W' or i =='U': str.remove(i) elif i == 'B': str.remove(i) s += " " else: s += i print(s)
Title: Dubstep Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them. Let's assume that a song consists of some number of words. To make the dubstep remix of this song, Vasya inserts a certain number of words "WUB" before the first word of the song (the number may be zero), after the last word (the number may be zero), and between words (at least one between any pair of neighbouring words), and then the boy glues together all the words, including "WUB", in one string and plays the song at the club. For example, a song with words "I AM X" can transform into a dubstep remix as "WUBWUBIWUBAMWUBWUBX" and cannot transform into "WUBWUBIAMWUBX". Recently, Petya has heard Vasya's new dubstep track, but since he isn't into modern music, he decided to find out what was the initial song that Vasya remixed. Help Petya restore the original song. Input Specification: The input consists of a single non-empty string, consisting only of uppercase English letters, the string's length doesn't exceed 200 characters. It is guaranteed that before Vasya remixed the song, no word contained substring "WUB" in it; Vasya didn't change the word order. It is also guaranteed that initially the song had at least one word. Output Specification: Print the words of the initial song that Vasya used to make a dubsteb remix. Separate the words with a space. Demo Input: ['WUBWUBABCWUB\n', 'WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB\n'] Demo Output: ['ABC ', 'WE ARE THE CHAMPIONS MY FRIEND '] Note: In the first sample: "WUBWUBABCWUB" = "WUB" + "WUB" + "ABC" + "WUB". That means that the song originally consisted of a single word "ABC", and all words "WUB" were added by Vasya. In the second sample Vasya added a single word "WUB" between all neighbouring words, in the beginning and in the end, except for words "ARE" and "THE" — between them Vasya added two "WUB".
```python str = input() s = '' for i in str: if i == 'W' or i =='U': str.remove(i) elif i == 'B': str.remove(i) s += " " else: s += i print(s) ```
-1
378
A
Playing with Dice
PROGRAMMING
800
[ "brute force" ]
null
null
Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same difference, it's a draw. The first player wrote number *a*, the second player wrote number *b*. How many ways to throw a dice are there, at which the first player wins, or there is a draw, or the second player wins?
The single line contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=6) — the numbers written on the paper by the first and second player, correspondingly.
Print three integers: the number of ways to throw the dice at which the first player wins, the game ends with a draw or the second player wins, correspondingly.
[ "2 5\n", "2 4\n" ]
[ "3 0 3\n", "2 1 3\n" ]
The dice is a standard cube-shaped six-sided object with each side containing a number from 1 to 6, and where all numbers on all sides are distinct. You can assume that number *a* is closer to number *x* than number *b*, if |*a* - *x*| &lt; |*b* - *x*|.
500
[ { "input": "2 5", "output": "3 0 3" }, { "input": "2 4", "output": "2 1 3" }, { "input": "5 3", "output": "2 1 3" }, { "input": "1 6", "output": "3 0 3" }, { "input": "5 1", "output": "3 1 2" }, { "input": "6 3", "output": "2 0 4" }, { "input": "2 3", "output": "2 0 4" }, { "input": "5 6", "output": "5 0 1" }, { "input": "4 4", "output": "0 6 0" }, { "input": "1 1", "output": "0 6 0" }, { "input": "6 4", "output": "1 1 4" }, { "input": "1 4", "output": "2 0 4" }, { "input": "5 5", "output": "0 6 0" }, { "input": "4 5", "output": "4 0 2" }, { "input": "4 3", "output": "3 0 3" }, { "input": "1 5", "output": "2 1 3" }, { "input": "6 5", "output": "1 0 5" }, { "input": "2 2", "output": "0 6 0" }, { "input": "1 3", "output": "1 1 4" }, { "input": "3 6", "output": "4 0 2" }, { "input": "3 1", "output": "4 1 1" }, { "input": "3 2", "output": "4 0 2" }, { "input": "3 5", "output": "3 1 2" }, { "input": "3 3", "output": "0 6 0" }, { "input": "6 2", "output": "2 1 3" }, { "input": "4 1", "output": "4 0 2" }, { "input": "5 2", "output": "3 0 3" }, { "input": "4 2", "output": "3 1 2" }, { "input": "2 1", "output": "5 0 1" }, { "input": "6 1", "output": "3 0 3" }, { "input": "4 6", "output": "4 1 1" }, { "input": "2 6", "output": "3 1 2" }, { "input": "3 4", "output": "3 0 3" }, { "input": "1 2", "output": "1 0 5" }, { "input": "6 6", "output": "0 6 0" }, { "input": "5 4", "output": "2 0 4" }, { "input": "3 3", "output": "0 6 0" }, { "input": "1 1", "output": "0 6 0" } ]
1,680,781,362
2,147,483,647
Python 3
OK
TESTS
38
46
0
a,b = map(int,input().split()) x,y,z = 0,0,0 for i in range(1,7): if(abs(a-i)<abs(b-i)): x+=1 elif(abs(a-i)>abs(b-i)): y+=1 else: z+=1 print(x,z,y)
Title: Playing with Dice Time Limit: None seconds Memory Limit: None megabytes Problem Description: Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same difference, it's a draw. The first player wrote number *a*, the second player wrote number *b*. How many ways to throw a dice are there, at which the first player wins, or there is a draw, or the second player wins? Input Specification: The single line contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=6) — the numbers written on the paper by the first and second player, correspondingly. Output Specification: Print three integers: the number of ways to throw the dice at which the first player wins, the game ends with a draw or the second player wins, correspondingly. Demo Input: ['2 5\n', '2 4\n'] Demo Output: ['3 0 3\n', '2 1 3\n'] Note: The dice is a standard cube-shaped six-sided object with each side containing a number from 1 to 6, and where all numbers on all sides are distinct. You can assume that number *a* is closer to number *x* than number *b*, if |*a* - *x*| &lt; |*b* - *x*|.
```python a,b = map(int,input().split()) x,y,z = 0,0,0 for i in range(1,7): if(abs(a-i)<abs(b-i)): x+=1 elif(abs(a-i)>abs(b-i)): y+=1 else: z+=1 print(x,z,y) ```
3
673
A
Bear and Game
PROGRAMMING
800
[ "implementation" ]
null
null
Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks. Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Limak immediately turns TV off. You know that there will be *n* interesting minutes *t*1,<=*t*2,<=...,<=*t**n*. Your task is to calculate for how many minutes Limak will watch the game.
The first line of the input contains one integer *n* (1<=≤<=*n*<=≤<=90) — the number of interesting minutes. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t*1<=&lt;<=*t*2<=&lt;<=... *t**n*<=≤<=90), given in the increasing order.
Print the number of minutes Limak will watch the game.
[ "3\n7 20 88\n", "9\n16 20 30 40 50 60 70 80 90\n", "9\n15 20 30 40 50 60 70 80 90\n" ]
[ "35\n", "15\n", "90\n" ]
In the first sample, minutes 21, 22, ..., 35 are all boring and thus Limak will turn TV off immediately after the 35-th minute. So, he would watch the game for 35 minutes. In the second sample, the first 15 minutes are boring. In the third sample, there are no consecutive 15 boring minutes. So, Limak will watch the whole game.
500
[ { "input": "3\n7 20 88", "output": "35" }, { "input": "9\n16 20 30 40 50 60 70 80 90", "output": "15" }, { "input": "9\n15 20 30 40 50 60 70 80 90", "output": "90" }, { "input": "30\n6 11 12 15 22 24 30 31 32 33 34 35 40 42 44 45 47 50 53 54 57 58 63 67 75 77 79 81 83 88", "output": "90" }, { "input": "60\n1 2 4 5 6 7 11 14 16 18 20 21 22 23 24 25 26 33 34 35 36 37 38 39 41 42 43 44 46 47 48 49 52 55 56 57 58 59 60 61 63 64 65 67 68 70 71 72 73 74 75 77 78 80 82 83 84 85 86 88", "output": "90" }, { "input": "90\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", "output": "90" }, { "input": "1\n1", "output": "16" }, { "input": "5\n15 30 45 60 75", "output": "90" }, { "input": "6\n14 29 43 59 70 74", "output": "58" }, { "input": "1\n15", "output": "30" }, { "input": "1\n16", "output": "15" }, { "input": "14\n14 22 27 31 35 44 46 61 62 69 74 79 88 89", "output": "90" }, { "input": "76\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 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", "output": "90" }, { "input": "1\n90", "output": "15" }, { "input": "6\n13 17 32 47 60 66", "output": "81" }, { "input": "84\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", "output": "90" }, { "input": "9\n6 20 27 28 40 53 59 70 85", "output": "90" }, { "input": "12\n14 22 27 31 35 44 62 69 74 79 88 89", "output": "59" }, { "input": "5\n15 30 45 60 74", "output": "89" }, { "input": "72\n3 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 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", "output": "54" }, { "input": "8\n1 16 30 31 32 33 34 50", "output": "49" }, { "input": "12\n1 3 6 10 15 21 28 36 45 55 66 78", "output": "90" }, { "input": "25\n1 2 3 4 5 6 7 8 9 10 11 23 36 50 65 81 82 83 84 85 86 87 88 89 90", "output": "80" }, { "input": "8\n5 17 20 35 42 53 67 76", "output": "90" }, { "input": "9\n15 28 39 48 55 60 63 64 74", "output": "89" }, { "input": "10\n15 28 39 48 55 60 63 64 74 82", "output": "90" }, { "input": "2\n1 18", "output": "16" }, { "input": "9\n10 20 30 40 50 60 70 80 84", "output": "90" }, { "input": "2\n16 50", "output": "15" }, { "input": "6\n15 30 45 60 75 84", "output": "90" }, { "input": "8\n15 20 30 40 50 60 73 83", "output": "90" }, { "input": "8\n10 20 30 40 50 60 70 80", "output": "90" }, { "input": "3\n1 20 90", "output": "16" }, { "input": "6\n15 30 45 60 74 89", "output": "90" } ]
1,653,501,089
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
46
0
if __name__ == "__main__": n = int(input()) arr = list(map(int, input().strip().split())) arr = [0] + arr check = False for i in range(1, n + 1): cnt = arr[i] - arr[i-1] if(cnt > 15): print(arr[i-1] + 15) check = True break if(check == False): print(arr[-1])
Title: Bear and Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks. Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Limak immediately turns TV off. You know that there will be *n* interesting minutes *t*1,<=*t*2,<=...,<=*t**n*. Your task is to calculate for how many minutes Limak will watch the game. Input Specification: The first line of the input contains one integer *n* (1<=≤<=*n*<=≤<=90) — the number of interesting minutes. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t*1<=&lt;<=*t*2<=&lt;<=... *t**n*<=≤<=90), given in the increasing order. Output Specification: Print the number of minutes Limak will watch the game. Demo Input: ['3\n7 20 88\n', '9\n16 20 30 40 50 60 70 80 90\n', '9\n15 20 30 40 50 60 70 80 90\n'] Demo Output: ['35\n', '15\n', '90\n'] Note: In the first sample, minutes 21, 22, ..., 35 are all boring and thus Limak will turn TV off immediately after the 35-th minute. So, he would watch the game for 35 minutes. In the second sample, the first 15 minutes are boring. In the third sample, there are no consecutive 15 boring minutes. So, Limak will watch the whole game.
```python if __name__ == "__main__": n = int(input()) arr = list(map(int, input().strip().split())) arr = [0] + arr check = False for i in range(1, n + 1): cnt = arr[i] - arr[i-1] if(cnt > 15): print(arr[i-1] + 15) check = True break if(check == False): print(arr[-1]) ```
0
417
E
Square Table
PROGRAMMING
2,400
[ "constructive algorithms", "math", "probabilities" ]
null
null
While resting on the ship after the "Russian Code Cup" a boy named Misha invented an interesting game. He promised to give his quadrocopter to whoever will be the first one to make a rectangular table of size *n*<=×<=*m*, consisting of positive integers such that the sum of the squares of numbers for each row and each column was also a square. Since checking the correctness of the table manually is difficult, Misha asks you to make each number in the table to not exceed 108.
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100)  — the size of the table.
Print the table that meets the condition: *n* lines containing *m* integers, separated by spaces. If there are multiple possible answers, you are allowed to print anyone. It is guaranteed that there exists at least one correct answer.
[ "1 1\n", "1 2\n" ]
[ "1", "3 4" ]
none
2,500
[ { "input": "1 1", "output": "1 " }, { "input": "1 2", "output": "3 4 " }, { "input": "4 1", "output": "1 \n1 \n1 \n1 " }, { "input": "1 4", "output": "1 1 1 1 " }, { "input": "2 1", "output": "3 \n4 " }, { "input": "2 4", "output": "3 3 3 3 \n4 4 4 4 " }, { "input": "48 2", "output": "3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n69 92 " }, { "input": "3 75", "output": "4 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 76 \n2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 38 \n4 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 76 " }, { "input": "33 1", "output": "2 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n17 " }, { "input": "4 23", "output": "2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 \n2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 \n2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 \n2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 " }, { "input": "58 2", "output": "3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n84 112 " }, { "input": "2 11", "output": "6 3 3 3 3 3 3 3 3 3 18 \n8 4 4 4 4 4 4 4 4 4 24 " }, { "input": "7 14", "output": "2 2 2 2 2 2 2 2 2 2 2 2 2 12 \n1 1 1 1 1 1 1 1 1 1 1 1 1 6 \n1 1 1 1 1 1 1 1 1 1 1 1 1 6 \n1 1 1 1 1 1 1 1 1 1 1 1 1 6 \n1 1 1 1 1 1 1 1 1 1 1 1 1 6 \n1 1 1 1 1 1 1 1 1 1 1 1 1 6 \n4 4 4 4 4 4 4 4 4 4 4 4 4 24 " }, { "input": "48 24", "output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 11 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 11 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 11 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 11 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 11 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 11 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 11 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 11 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 11 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 11 \n1..." }, { "input": "77 93", "output": "4 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 94 \n2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 47 \n2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "77 20", "output": "2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 18 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 9 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 9 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 9 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 9 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 9 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 9 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 9 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 9 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 9 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 9 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 9 \n1 1 1 ..." }, { "input": "30 31", "output": "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 16 \n2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 16 \n2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 16 \n2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 16 \n2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 16 \n2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 16 \n2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 16 \n2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ..." }, { "input": "100 100", "output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 49 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 49 \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,634,402,401
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
14
61
0
import sys def get(dp, n): a = [] for i in range(1, len(dp[n])): if dp[n][i] is not None and int(i**0.5)**2 == i: y = i j = n while y != 0: x = dp[j][y] a.append(x) y -= x * x j -= 1 break return a def solve(): dp = [[None]*101 for i in range(101)] dp[0][0] = -1 for i in range(len(dp)-1): for j in range(len(dp[i])): if dp[i][j] is not None: for k in range(1,10001): if j + k * k < len(dp[i + 1]): dp[i + 1][j + k * k] = k else: break n, m = map(int, sys.stdin.readline().split()) a = get(dp, n) b = get(dp, m) for i in range(n): print(' '.join(str(a[i] * b[j]) for j in range(m))) def main(): solve() if __name__ == '__main__': main()
Title: Square Table Time Limit: None seconds Memory Limit: None megabytes Problem Description: While resting on the ship after the "Russian Code Cup" a boy named Misha invented an interesting game. He promised to give his quadrocopter to whoever will be the first one to make a rectangular table of size *n*<=×<=*m*, consisting of positive integers such that the sum of the squares of numbers for each row and each column was also a square. Since checking the correctness of the table manually is difficult, Misha asks you to make each number in the table to not exceed 108. Input Specification: The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100)  — the size of the table. Output Specification: Print the table that meets the condition: *n* lines containing *m* integers, separated by spaces. If there are multiple possible answers, you are allowed to print anyone. It is guaranteed that there exists at least one correct answer. Demo Input: ['1 1\n', '1 2\n'] Demo Output: ['1', '3 4'] Note: none
```python import sys def get(dp, n): a = [] for i in range(1, len(dp[n])): if dp[n][i] is not None and int(i**0.5)**2 == i: y = i j = n while y != 0: x = dp[j][y] a.append(x) y -= x * x j -= 1 break return a def solve(): dp = [[None]*101 for i in range(101)] dp[0][0] = -1 for i in range(len(dp)-1): for j in range(len(dp[i])): if dp[i][j] is not None: for k in range(1,10001): if j + k * k < len(dp[i + 1]): dp[i + 1][j + k * k] = k else: break n, m = map(int, sys.stdin.readline().split()) a = get(dp, n) b = get(dp, m) for i in range(n): print(' '.join(str(a[i] * b[j]) for j in range(m))) def main(): solve() if __name__ == '__main__': main() ```
-1
284
B
Cows and Poker Game
PROGRAMMING
1,000
[ "brute force", "implementation" ]
null
null
There are *n* cows playing poker at a table. For the current betting phase, each player's status is either "ALLIN", "IN", or "FOLDED", and does not change throughout the phase. To increase the suspense, a player whose current status is not "FOLDED" may show his/her hand to the table. However, so as not to affect any betting decisions, he/she may only do so if all other players have a status of either "ALLIN" or "FOLDED". The player's own status may be either "ALLIN" or "IN". Find the number of cows that can currently show their hands without affecting any betting decisions.
The first line contains a single integer, *n* (2<=≤<=*n*<=≤<=2·105). The second line contains *n* characters, each either "A", "I", or "F". The *i*-th character is "A" if the *i*-th player's status is "ALLIN", "I" if the *i*-th player's status is "IN", or "F" if the *i*-th player's status is "FOLDED".
The first line should contain a single integer denoting the number of players that can currently show their hands.
[ "6\nAFFAAA\n", "3\nAFI\n" ]
[ "4\n", "1\n" ]
In the first sample, cows 1, 4, 5, and 6 can show their hands. In the second sample, only cow 3 can show her hand.
1,000
[ { "input": "6\nAFFAAA", "output": "4" }, { "input": "3\nAFI", "output": "1" }, { "input": "3\nFFF", "output": "0" }, { "input": "3\nFIF", "output": "1" }, { "input": "3\nAAA", "output": "3" }, { "input": "3\nIII", "output": "0" }, { "input": "3\nIIA", "output": "0" }, { "input": "3\nAFF", "output": "1" }, { "input": "5\nFAFFF", "output": "1" }, { "input": "3\nIAA", "output": "1" }, { "input": "3\nIIF", "output": "0" }, { "input": "2\nFA", "output": "1" }, { "input": "2\nFF", "output": "0" }, { "input": "2\nIF", "output": "1" }, { "input": "5\nAAAAI", "output": "1" }, { "input": "5\nIIIIF", "output": "0" }, { "input": "10\nAAAAAAAAAA", "output": "10" }, { "input": "100\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "output": "100" }, { "input": "5\nFAIAF", "output": "1" }, { "input": "5\nAIAIF", "output": "0" }, { "input": "5\nFAAII", "output": "0" }, { "input": "5\nAIFFF", "output": "1" }, { "input": "5\nAFAFA", "output": "3" }, { "input": "2\nFA", "output": "1" }, { "input": "8\nAFFFFIAF", "output": "1" }, { "input": "8\nIAAIFFFI", "output": "0" }, { "input": "5\nIIIII", "output": "0" } ]
1,593,574,866
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
6
218
0
z=int(input());a=i=0 for k in input(): if k=='A': a+=1 elif k== 'I': i+=1 if i==z or a+i==0: print(0) else: print(['%d'%i,'%d'%a][i==0])
Title: Cows and Poker Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* cows playing poker at a table. For the current betting phase, each player's status is either "ALLIN", "IN", or "FOLDED", and does not change throughout the phase. To increase the suspense, a player whose current status is not "FOLDED" may show his/her hand to the table. However, so as not to affect any betting decisions, he/she may only do so if all other players have a status of either "ALLIN" or "FOLDED". The player's own status may be either "ALLIN" or "IN". Find the number of cows that can currently show their hands without affecting any betting decisions. Input Specification: The first line contains a single integer, *n* (2<=≤<=*n*<=≤<=2·105). The second line contains *n* characters, each either "A", "I", or "F". The *i*-th character is "A" if the *i*-th player's status is "ALLIN", "I" if the *i*-th player's status is "IN", or "F" if the *i*-th player's status is "FOLDED". Output Specification: The first line should contain a single integer denoting the number of players that can currently show their hands. Demo Input: ['6\nAFFAAA\n', '3\nAFI\n'] Demo Output: ['4\n', '1\n'] Note: In the first sample, cows 1, 4, 5, and 6 can show their hands. In the second sample, only cow 3 can show her hand.
```python z=int(input());a=i=0 for k in input(): if k=='A': a+=1 elif k== 'I': i+=1 if i==z or a+i==0: print(0) else: print(['%d'%i,'%d'%a][i==0]) ```
0